summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore11
-rw-r--r--.gitmodules9
-rw-r--r--AUTHORS1
-rw-r--r--ChangeLog12
-rw-r--r--README96
-rwxr-xr-xbootstrap24
-rw-r--r--configure.ac214
-rw-r--r--contrib/.gitignore3
-rw-r--r--contrib/Makefile.am70
-rw-r--r--contrib/Makefile.am.in68
-rw-r--r--contrib/auditor-report.tex.j2157
-rw-r--r--contrib/ci/Containerfile68
-rwxr-xr-xcontrib/ci/ci.sh33
-rw-r--r--contrib/ci/jobs/0-codespell/config.ini6
-rw-r--r--contrib/ci/jobs/0-codespell/dictionary.txt47
-rwxr-xr-xcontrib/ci/jobs/0-codespell/job.sh100
-rwxr-xr-xcontrib/ci/jobs/1-build/build.sh14
-rwxr-xr-xcontrib/ci/jobs/1-build/job.sh6
-rw-r--r--contrib/ci/jobs/2-test/config.ini6
-rwxr-xr-xcontrib/ci/jobs/2-test/job.sh6
-rwxr-xr-xcontrib/ci/jobs/2-test/test.sh51
-rw-r--r--contrib/ci/jobs/3-docs/config.ini6
-rwxr-xr-xcontrib/ci/jobs/3-docs/docs.sh11
-rwxr-xr-xcontrib/ci/jobs/3-docs/job.sh6
-rw-r--r--contrib/ci/jobs/4-deb-package/install-fix.patch13
-rwxr-xr-xcontrib/ci/jobs/4-deb-package/job.sh23
-rwxr-xr-xcontrib/ci/jobs/4-deb-package/version.sh17
-rw-r--r--contrib/ci/jobs/5-deploy-package/config.ini5
-rwxr-xr-xcontrib/ci/jobs/5-deploy-package/job.sh14
-rw-r--r--contrib/exchange-pp-v0.rst (renamed from contrib/pp/pp.rst)12
-rw-r--r--contrib/exchange-tos-bfh-v0.rst (renamed from contrib/tos/bfh.rst)0
-rw-r--r--contrib/exchange-tos-netzbon-v0.rst108
-rw-r--r--contrib/exchange-tos-tops-v0.rst959
-rw-r--r--contrib/exchange-tos-v0.rst (renamed from contrib/tos/tos.rst)103
m---------contrib/gana0
-rwxr-xr-xcontrib/gana-generate.sh (renamed from contrib/gana-update.sh)2
-rwxr-xr-xcontrib/gana-latest.sh (renamed from contrib/gana.sh)2
-rw-r--r--contrib/gnunet.tag20
-rw-r--r--contrib/kyc-proof-already-done.en.must9
-rw-r--r--contrib/kyc-proof-bad-request.en.must15
-rw-r--r--contrib/kyc-proof-endpoint-unknown.en.must15
-rw-r--r--contrib/kyc-proof-internal-error.en.must16
-rw-r--r--contrib/kyc-proof-target-unknown.en.must15
-rw-r--r--contrib/kycaid-invalid-request.en.must12
-rw-r--r--contrib/locale/de/LC_MESSAGES/exchange-tos-v0.po403
-rw-r--r--contrib/microhttpd.tag12
-rw-r--r--contrib/oauth2-authentication-failure.en.must16
-rw-r--r--contrib/oauth2-authorization-failure-malformed.en.must13
-rw-r--r--contrib/oauth2-authorization-failure.en.must12
-rw-r--r--contrib/oauth2-bad-request.en.must15
-rw-r--r--contrib/oauth2-conversion-failure.en.must28
-rw-r--r--contrib/oauth2-provider-failure.en.must22
-rw-r--r--contrib/packages/fedora/etc-libtalerexchange/taler/overrides.conf1
-rw-r--r--contrib/packages/fedora/etc-libtalerexchange/taler/taler.conf49
-rw-r--r--contrib/packages/fedora/etc-taler-auditor/apache2/sites-available/taler-auditor.conf4
-rw-r--r--contrib/packages/fedora/etc-taler-auditor/nginx/sites-available/taler-auditor18
-rw-r--r--contrib/packages/fedora/etc-taler-auditor/taler/conf.d/auditor-system.conf12
-rw-r--r--contrib/packages/fedora/etc-taler-auditor/taler/secrets/auditor-db.secret.conf10
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/apache2/sites-available/taler-exchange.conf4
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/nginx/sites-available/taler-exchange17
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-business.conf50
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-coins.conf33
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-system.conf13
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf (renamed from debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials.secret.conf)0
-rw-r--r--contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-db.secret.conf10
-rw-r--r--contrib/packages/fedora/taler-auditor.taler-auditor-httpd.service12
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-aggregator.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-aggregator@.service17
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-closer.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-expire.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-httpd.service33
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-httpd@.service27
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-secmod-cs.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-secmod-eddsa.service19
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-secmod-rsa.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-transfer.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch.service18
-rw-r--r--contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch@.service18
-rw-r--r--contrib/persona-exchange-unauthorized.en.must13
-rw-r--r--contrib/persona-exchange-unpaid.en.must13
-rw-r--r--contrib/persona-invalid-response.en.must13
-rw-r--r--contrib/persona-kyc-failed.en.must20
-rw-r--r--contrib/persona-load-failure.en.must13
-rw-r--r--contrib/persona-logic-failure.en.must13
-rw-r--r--contrib/persona-network-timeout.en.must13
-rw-r--r--contrib/persona-provider-failure.en.must13
-rw-r--r--contrib/pp/.gitignore3
-rw-r--r--contrib/pp/Makefile109
-rw-r--r--contrib/pp/README58
-rw-r--r--contrib/pp/conf.py282
-rw-r--r--contrib/pp/en/0.epubbin14983 -> 0 bytes
-rw-r--r--contrib/pp/en/0.html211
-rw-r--r--contrib/pp/en/0.pdfbin77445 -> 0 bytes
-rw-r--r--contrib/pp/en/0.txt237
-rw-r--r--contrib/pp/en/0.xml214
-rw-r--r--contrib/pp/locale/de/LC_MESSAGES/pp.po221
-rw-r--r--contrib/samples/wire-auditor.json6
-rw-r--r--contrib/sigp/h.header5
-rwxr-xr-xcontrib/taler-auditor-dbconfig132
-rwxr-xr-xcontrib/taler-bank-manage-testing27
-rwxr-xr-xcontrib/taler-exchange-dbconfig186
-rwxr-xr-xcontrib/taler-nexus-prepare128
-rwxr-xr-xcontrib/taler-terms-generator295
-rw-r--r--contrib/tos/.gitignore3
-rw-r--r--contrib/tos/Makefile109
-rw-r--r--contrib/tos/README58
-rw-r--r--contrib/tos/conf.py282
-rw-r--r--contrib/tos/en/0.epubbin24290 -> 0 bytes
-rw-r--r--contrib/tos/en/0.html316
-rw-r--r--contrib/tos/en/0.pdfbin83662 -> 0 bytes
-rw-r--r--contrib/tos/en/0.txt349
-rw-r--r--contrib/tos/en/0.xml323
-rw-r--r--contrib/tos/locale/de/LC_MESSAGES/tos.po241
-rwxr-xr-xcontrib/uncrustify_precommit5
-rwxr-xr-xcontrib/update-pp.sh14
-rwxr-xr-xcontrib/update-tos.sh15
m---------contrib/wallet-core0
-rw-r--r--debian/changelog142
-rw-r--r--debian/control80
-rw-r--r--debian/etc-libtalerexchange/taler/taler.conf12
-rw-r--r--debian/etc-taler-auditor/nginx/sites-available/taler-auditor23
-rw-r--r--debian/etc-taler-auditor/taler/secrets/auditor-db.secret.conf2
-rw-r--r--debian/etc-taler-exchange/nginx/sites-available/taler-exchange7
-rw-r--r--debian/etc-taler-exchange/taler/conf.d/exchange-business.conf25
-rw-r--r--debian/etc-taler-exchange/taler/conf.d/exchange-system.conf3
-rw-r--r--debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf17
-rw-r--r--debian/etc-taler-exchange/taler/secrets/exchange-db.secret.conf2
-rw-r--r--debian/libtalerexchange-dev.install18
-rw-r--r--debian/libtalerexchange.install2
-rw-r--r--debian/libtalerexchange.postinst28
-rwxr-xr-xdebian/rules26
-rw-r--r--debian/taler-auditor.install6
-rw-r--r--debian/taler-auditor.postinst5
-rw-r--r--debian/taler-auditor.postrm9
-rw-r--r--debian/taler-auditor.taler-auditor-httpd.service3
-rw-r--r--debian/taler-auditor.taler-helper-auditor-deposits.service15
-rw-r--r--debian/taler-exchange-database.install2
-rw-r--r--debian/taler-exchange-offline.postinst13
-rw-r--r--debian/taler-exchange-offline.taler-exchange-offline.service23
-rw-r--r--debian/taler-exchange-offline.taler-exchange-offline.timer20
-rw-r--r--debian/taler-exchange.install22
-rw-r--r--debian/taler-exchange.postinst14
-rw-r--r--debian/taler-exchange.postrm26
-rw-r--r--debian/taler-exchange.taler-exchange-aggregator.service9
-rw-r--r--debian/taler-exchange.taler-exchange-aggregator@.service24
-rw-r--r--debian/taler-exchange.taler-exchange-closer.service9
-rw-r--r--debian/taler-exchange.taler-exchange-expire.service9
-rw-r--r--debian/taler-exchange.taler-exchange-httpd.service19
-rw-r--r--debian/taler-exchange.taler-exchange-httpd@.service11
-rw-r--r--debian/taler-exchange.taler-exchange-secmod-cs.service5
-rw-r--r--debian/taler-exchange.taler-exchange-secmod-eddsa.service5
-rw-r--r--debian/taler-exchange.taler-exchange-secmod-rsa.service5
-rw-r--r--debian/taler-exchange.taler-exchange-transfer.service10
-rw-r--r--debian/taler-exchange.taler-exchange-wirewatch.service10
-rw-r--r--debian/taler-exchange.taler-exchange-wirewatch@.service13
-rw-r--r--debian/taler-exchange.taler-exchange.slice7
-rw-r--r--debian/taler-exchange.tmpfiles3
-rw-r--r--debian/taler-terms-generator.install8
-rw-r--r--doc/Makefile.am43
-rw-r--r--doc/cs/content/4_2_specification.tex2
-rw-r--r--doc/doxygen/taler.doxy2551
-rw-r--r--doc/flows/.gitignore1
-rw-r--r--doc/flows/Makefile3
-rw-r--r--doc/flows/fees-coins.tex39
-rw-r--r--doc/flows/fees-wire.tex30
-rw-r--r--doc/flows/int-deposit.tex52
-rw-r--r--doc/flows/int-pay.tex60
-rw-r--r--doc/flows/int-pull.tex56
-rw-r--r--doc/flows/int-push.tex48
-rw-r--r--doc/flows/int-refund.tex39
-rw-r--r--doc/flows/int-shutdown.tex48
-rw-r--r--doc/flows/int-withdraw.tex49
-rw-r--r--doc/flows/kyc-balance.tex58
-rw-r--r--doc/flows/kyc-deposit.tex85
-rw-r--r--doc/flows/kyc-pull.tex92
-rw-r--r--doc/flows/kyc-push.tex90
-rw-r--r--doc/flows/kyc-withdraw.tex58
-rw-r--r--doc/flows/main.de.tex239
-rw-r--r--doc/flows/main.tex206
-rw-r--r--doc/flows/proc-aml.tex47
-rw-r--r--doc/flows/proc-domestic.tex66
-rw-r--r--doc/flows/proc-kyb.tex98
-rw-r--r--doc/flows/proc-kyc.tex88
m---------doc/prebuilt0
-rw-r--r--doc/system/taler/implementation.tex2
-rw-r--r--m4/libgnurl.m4266
-rw-r--r--src/Makefile.am3
-rw-r--r--src/auditor/.gitignore7
-rw-r--r--src/auditor/Makefile.am73
-rw-r--r--src/auditor/auditor-basedb.age1
-rw-r--r--src/auditor/auditor-basedb.conf183
-rw-r--r--src/auditor/auditor-basedb.feesbin800 -> 0 bytes
-rw-r--r--src/auditor/auditor-basedb.mpub1
-rw-r--r--src/auditor/auditor-basedb.sql16991
-rw-r--r--src/auditor/auditor.conf6
-rw-r--r--src/auditor/batch.conf2
-rwxr-xr-xsrc/auditor/batch.sh22
-rw-r--r--src/auditor/generate-auditor-basedb-template.conf1
-rw-r--r--src/auditor/generate-auditor-basedb.conf202
-rwxr-xr-xsrc/auditor/generate-auditor-basedb.sh308
-rw-r--r--src/auditor/generate-kyc-basedb.conf4
-rwxr-xr-xsrc/auditor/generate-revoke-basedb.sh376
-rw-r--r--src/auditor/generate_auditordb_home/.local/share/taler/exchange-offline/master.priv1
-rw-r--r--src/auditor/report-lib.c70
-rw-r--r--src/auditor/report-lib.h48
-rw-r--r--src/auditor/revoke-basedb.age1
-rw-r--r--src/auditor/revoke-basedb.conf12
-rw-r--r--src/auditor/revoke-basedb.feesbin800 -> 0 bytes
-rw-r--r--src/auditor/revoke-basedb.mpub1
-rw-r--r--src/auditor/revoke-basedb.sql17003
-rwxr-xr-xsrc/auditor/setup.sh93
-rw-r--r--src/auditor/taler-auditor-dbinit.c4
-rw-r--r--src/auditor/taler-auditor-exchange.c224
-rw-r--r--src/auditor/taler-auditor-httpd.c76
-rw-r--r--src/auditor/taler-auditor-httpd.h6
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation-get.c166
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation-get.h70
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation.c148
-rw-r--r--src/auditor/taler-auditor-httpd_deposit-confirmation.h1
-rw-r--r--src/auditor/taler-auditor-httpd_exchanges.c116
-rw-r--r--src/auditor/taler-auditor-sync.c22
-rw-r--r--src/auditor/taler-auditor.in7
-rw-r--r--src/auditor/taler-helper-auditor-aggregation.c370
-rw-r--r--src/auditor/taler-helper-auditor-coins.c728
-rw-r--r--src/auditor/taler-helper-auditor-deposits.c239
-rw-r--r--src/auditor/taler-helper-auditor-purses.c1451
-rw-r--r--src/auditor/taler-helper-auditor-render.py12
-rw-r--r--src/auditor/taler-helper-auditor-reserves.c1447
-rw-r--r--src/auditor/taler-helper-auditor-wire.c1308
-rwxr-xr-xsrc/auditor/test-auditor.sh2627
-rwxr-xr-xsrc/auditor/test-kyc.sh751
-rwxr-xr-xsrc/auditor/test-revocation.sh888
-rwxr-xr-xsrc/auditor/test-sync.sh184
-rw-r--r--src/auditordb/.gitignore4
-rw-r--r--src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_bad_sig_losses.sql26
-rw-r--r--src/auditordb/0002-auditor_balances.sql30
-rw-r--r--src/auditordb/0002-auditor_closure_lags.sql27
-rw-r--r--src/auditordb/0002-auditor_coin_inconsistency.sql28
-rw-r--r--src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_denomination_pending.sql34
-rw-r--r--src/auditordb/0002-auditor_denominations_without_sigs.sql27
-rw-r--r--src/auditordb/0002-auditor_deposit_confirmations.sql58
-rw-r--r--src/auditordb/0002-auditor_emergency.sql29
-rw-r--r--src/auditordb/0002-auditor_emergency_by_count.sql30
-rw-r--r--src/auditordb/0002-auditor_exchange_signkeys.sql35
-rw-r--r--src/auditordb/0002-auditor_fee_time_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_historic_denomination_revenue.sql32
-rw-r--r--src/auditordb/0002-auditor_historic_reserve_summary.sql30
-rw-r--r--src/auditordb/0002-auditor_misattribution_in_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_progress.sql26
-rw-r--r--src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql26
-rw-r--r--src/auditordb/0002-auditor_purses.sql25
-rw-r--r--src/auditordb/0002-auditor_refreshes_hanging.sql25
-rw-r--r--src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_reserve_in_inconsistency.sql29
-rw-r--r--src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql27
-rw-r--r--src/auditordb/0002-auditor_reserves.sql31
-rw-r--r--src/auditordb/0002-auditor_row_inconsistency.sql25
-rw-r--r--src/auditordb/0002-auditor_row_minor_inconsistencies.sql25
-rw-r--r--src/auditordb/0002-auditor_wire_format_inconsistency.sql26
-rw-r--r--src/auditordb/0002-auditor_wire_out_inconsistency.sql26
-rw-r--r--src/auditordb/9999.sql53
-rw-r--r--src/auditordb/Makefile.am90
-rw-r--r--src/auditordb/auditor-0000.sql293
-rw-r--r--src/auditordb/auditor-0001.sql516
-rw-r--r--src/auditordb/auditor-0002.sql.in46
-rw-r--r--src/auditordb/auditor_do_get_auditor_progress.sql38
-rw-r--r--src/auditordb/auditor_do_get_balance.sql47
-rw-r--r--src/auditordb/drop.sql31
-rw-r--r--src/auditordb/drop0001.sql50
-rw-r--r--src/auditordb/hdr.h0
-rw-r--r--src/auditordb/pg_del_denomination_balance.c47
-rw-r--r--src/auditordb/pg_del_denomination_balance.h40
-rw-r--r--src/auditordb/pg_del_reserve_info.c47
-rw-r--r--src/auditordb/pg_del_reserve_info.h41
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.c47
-rw-r--r--src/auditordb/pg_delete_deposit_confirmations.h41
-rw-r--r--src/auditordb/pg_delete_pending_deposit.c48
-rw-r--r--src/auditordb/pg_delete_pending_deposit.h44
-rw-r--r--src/auditordb/pg_delete_purse_info.c47
-rw-r--r--src/auditordb/pg_delete_purse_info.h42
-rw-r--r--src/auditordb/pg_get_auditor_progress.c178
-rw-r--r--src/auditordb/pg_get_auditor_progress.h44
-rw-r--r--src/auditordb/pg_get_balance.c183
-rw-r--r--src/auditordb/pg_get_balance.h44
-rw-r--r--src/auditordb/pg_get_denomination_balance.c68
-rw-r--r--src/auditordb/pg_get_denomination_balance.h43
-rw-r--r--src/auditordb/pg_get_deposit_confirmations.c199
-rw-r--r--src/auditordb/pg_get_deposit_confirmations.h48
-rw-r--r--src/auditordb/pg_get_purse_info.c62
-rw-r--r--src/auditordb/pg_get_purse_info.h47
-rw-r--r--src/auditordb/pg_get_reserve_info.c88
-rw-r--r--src/auditordb/pg_get_reserve_info.h49
-rw-r--r--src/auditordb/pg_get_wire_fee_summary.c59
-rw-r--r--src/auditordb/pg_get_wire_fee_summary.h41
-rw-r--r--src/auditordb/pg_helper.h119
-rw-r--r--src/auditordb/pg_insert_auditor_progress.c97
-rw-r--r--src/auditordb/pg_insert_auditor_progress.h46
-rw-r--r--src/auditordb/pg_insert_balance.c97
-rw-r--r--src/auditordb/pg_insert_balance.h45
-rw-r--r--src/auditordb/pg_insert_denomination_balance.c65
-rw-r--r--src/auditordb/pg_insert_denomination_balance.h45
-rw-r--r--src/auditordb/pg_insert_deposit_confirmation.c77
-rw-r--r--src/auditordb/pg_insert_deposit_confirmation.h42
-rw-r--r--src/auditordb/pg_insert_exchange_signkey.c56
-rw-r--r--src/auditordb/pg_insert_exchange_signkey.h41
-rw-r--r--src/auditordb/pg_insert_historic_denom_revenue.c59
-rw-r--r--src/auditordb/pg_insert_historic_denom_revenue.h50
-rw-r--r--src/auditordb/pg_insert_historic_reserve_revenue.c54
-rw-r--r--src/auditordb/pg_insert_historic_reserve_revenue.h45
-rw-r--r--src/auditordb/pg_insert_pending_deposit.c58
-rw-r--r--src/auditordb/pg_insert_pending_deposit.h48
-rw-r--r--src/auditordb/pg_insert_purse_info.c55
-rw-r--r--src/auditordb/pg_insert_purse_info.h45
-rw-r--r--src/auditordb/pg_insert_reserve_info.c79
-rw-r--r--src/auditordb/pg_insert_reserve_info.h48
-rw-r--r--src/auditordb/pg_select_historic_denom_revenue.c146
-rw-r--r--src/auditordb/pg_select_historic_denom_revenue.h43
-rw-r--r--src/auditordb/pg_select_historic_reserve_revenue.c140
-rw-r--r--src/auditordb/pg_select_historic_reserve_revenue.h43
-rw-r--r--src/auditordb/pg_select_pending_deposits.c149
-rw-r--r--src/auditordb/pg_select_pending_deposits.h46
-rw-r--r--src/auditordb/pg_select_purse_expired.c146
-rw-r--r--src/auditordb/pg_select_purse_expired.h43
-rw-r--r--src/auditordb/pg_template.c26
-rw-r--r--src/auditordb/pg_template.h29
-rwxr-xr-xsrc/auditordb/pg_template.sh21
-rw-r--r--src/auditordb/pg_update_auditor_progress.c99
-rw-r--r--src/auditordb/pg_update_auditor_progress.h46
-rw-r--r--src/auditordb/pg_update_balance.c100
-rw-r--r--src/auditordb/pg_update_balance.h47
-rw-r--r--src/auditordb/pg_update_denomination_balance.c62
-rw-r--r--src/auditordb/pg_update_denomination_balance.h45
-rw-r--r--src/auditordb/pg_update_purse_info.c52
-rw-r--r--src/auditordb/pg_update_purse_info.h45
-rw-r--r--src/auditordb/pg_update_reserve_info.c69
-rw-r--r--src/auditordb/pg_update_reserve_info.h46
-rw-r--r--src/auditordb/pg_update_wire_fee_summary.c48
-rw-r--r--src/auditordb/pg_update_wire_fee_summary.h42
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c2941
-rw-r--r--src/auditordb/procedures.sql.in (renamed from src/exchangedb/drop0001-shard-part.sql)11
-rw-r--r--src/auditordb/restart.sql (renamed from src/auditordb/restart0001.sql)20
-rw-r--r--src/auditordb/test_auditordb.c748
-rw-r--r--src/auditordb/test_auditordb_checkpoints.c386
-rw-r--r--src/auditordb/versioning.sql (renamed from src/exchangedb/exchange-0000.sql)3
-rw-r--r--src/bank-lib/Makefile.am34
-rw-r--r--src/bank-lib/bank_api_admin.c52
-rw-r--r--src/bank-lib/bank_api_common.h2
-rw-r--r--src/bank-lib/bank_api_credit.c149
-rw-r--r--src/bank-lib/bank_api_debit.c144
-rw-r--r--src/bank-lib/bank_api_transfer.c49
-rw-r--r--src/bank-lib/fakebank.c2633
-rw-r--r--src/bank-lib/fakebank.h691
-rw-r--r--src/bank-lib/fakebank_api_check.c238
-rw-r--r--src/bank-lib/fakebank_bank.c524
-rw-r--r--src/bank-lib/fakebank_bank.h54
-rw-r--r--src/bank-lib/fakebank_bank_accounts_withdrawals.c101
-rw-r--r--src/bank-lib/fakebank_bank_accounts_withdrawals.h50
-rw-r--r--src/bank-lib/fakebank_bank_get_accounts.c80
-rw-r--r--src/bank-lib/fakebank_bank_get_accounts.h48
-rw-r--r--src/bank-lib/fakebank_bank_get_root.c58
-rw-r--r--src/bank-lib/fakebank_bank_get_root.h44
-rw-r--r--src/bank-lib/fakebank_bank_get_withdrawals.c87
-rw-r--r--src/bank-lib/fakebank_bank_get_withdrawals.h51
-rw-r--r--src/bank-lib/fakebank_bank_post_accounts_withdrawals.c196
-rw-r--r--src/bank-lib/fakebank_bank_post_accounts_withdrawals.h54
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_abort.c74
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_abort.h48
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_confirm.c107
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_confirm.h48
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_id_op.c241
-rw-r--r--src/bank-lib/fakebank_bank_post_withdrawals_id_op.h58
-rw-r--r--src/bank-lib/fakebank_bank_testing_register.c128
-rw-r--r--src/bank-lib/fakebank_bank_testing_register.h53
-rw-r--r--src/bank-lib/fakebank_common_lookup.c103
-rw-r--r--src/bank-lib/fakebank_common_lookup.h62
-rw-r--r--src/bank-lib/fakebank_common_lp.c344
-rw-r--r--src/bank-lib/fakebank_common_lp.h100
-rw-r--r--src/bank-lib/fakebank_common_make_admin_transfer.c117
-rw-r--r--src/bank-lib/fakebank_common_make_admin_transfer.h56
-rw-r--r--src/bank-lib/fakebank_common_parser.c138
-rw-r--r--src/bank-lib/fakebank_common_parser.h50
-rw-r--r--src/bank-lib/fakebank_common_transact.c261
-rw-r--r--src/bank-lib/fakebank_common_transact.h76
-rw-r--r--src/bank-lib/fakebank_stop.c192
-rw-r--r--src/bank-lib/fakebank_tbi.c167
-rw-r--r--src/bank-lib/fakebank_tbi.h54
-rw-r--r--src/bank-lib/fakebank_tbi_get_withdrawal_operation.c141
-rw-r--r--src/bank-lib/fakebank_tbi_get_withdrawal_operation.h51
-rw-r--r--src/bank-lib/fakebank_tbi_post_withdrawal_operation.c231
-rw-r--r--src/bank-lib/fakebank_tbi_post_withdrawal_operation.h53
-rw-r--r--src/bank-lib/fakebank_tbr.c94
-rw-r--r--src/bank-lib/fakebank_tbr.h58
-rw-r--r--src/bank-lib/fakebank_tbr_get_history.c312
-rw-r--r--src/bank-lib/fakebank_tbr_get_history.h52
-rw-r--r--src/bank-lib/fakebank_tbr_get_root.c50
-rw-r--r--src/bank-lib/fakebank_tbr_get_root.h45
-rw-r--r--src/bank-lib/fakebank_twg.c124
-rw-r--r--src/bank-lib/fakebank_twg.h56
-rw-r--r--src/bank-lib/fakebank_twg_admin_add_incoming.c160
-rw-r--r--src/bank-lib/fakebank_twg_admin_add_incoming.h52
-rw-r--r--src/bank-lib/fakebank_twg_get_root.c58
-rw-r--r--src/bank-lib/fakebank_twg_get_root.h46
-rw-r--r--src/bank-lib/fakebank_twg_history.c537
-rw-r--r--src/bank-lib/fakebank_twg_history.h67
-rw-r--r--src/bank-lib/fakebank_twg_transfer.c178
-rw-r--r--src/bank-lib/fakebank_twg_transfer.h55
-rw-r--r--src/bank-lib/taler-exchange-wire-gateway-client.c282
-rw-r--r--src/bank-lib/taler-fakebank-run.c56
-rwxr-xr-xsrc/bank-lib/test_bank.sh42
-rw-r--r--src/benchmark/.gitignore1
-rw-r--r--src/benchmark/Makefile.am7
-rw-r--r--src/benchmark/bank-benchmark-cs.conf127
-rw-r--r--src/benchmark/bank-benchmark-rsa.conf132
-rw-r--r--src/benchmark/benchmark-common.conf106
-rw-r--r--src/benchmark/benchmark-cs.conf116
-rw-r--r--src/benchmark/benchmark-rsa.conf121
-rw-r--r--src/benchmark/coins-cs.conf58
-rw-r--r--src/benchmark/coins-rsa.conf63
-rw-r--r--src/benchmark/exchange_benchmark_home/.local/share/taler/exchange/offline-keys/master.priv1
-rw-r--r--src/benchmark/taler-aggregator-benchmark.c95
-rw-r--r--src/benchmark/taler-bank-benchmark.c649
-rw-r--r--src/benchmark/taler-exchange-benchmark.c929
-rw-r--r--src/curl/Makefile.am2
-rw-r--r--src/curl/curl.c82
-rw-r--r--src/exchange-tools/Makefile.am16
-rw-r--r--src/exchange-tools/exchange-offline.conf4
-rw-r--r--src/exchange-tools/taler-auditor-offline.c451
-rw-r--r--src/exchange-tools/taler-crypto-worker.c461
-rw-r--r--src/exchange-tools/taler-exchange-dbinit.c122
-rw-r--r--src/exchange-tools/taler-exchange-offline.c1741
-rw-r--r--src/exchange/Makefile.am45
-rw-r--r--src/exchange/exchange.conf80
-rw-r--r--src/exchange/taler-exchange-aggregator.c967
-rw-r--r--src/exchange/taler-exchange-closer.c127
-rw-r--r--src/exchange/taler-exchange-drain.c431
-rw-r--r--src/exchange/taler-exchange-expire.c32
-rw-r--r--src/exchange/taler-exchange-httpd.c1321
-rw-r--r--src/exchange/taler-exchange-httpd.h199
-rw-r--r--src/exchange/taler-exchange-httpd_age-withdraw.c1019
-rw-r--r--src/exchange/taler-exchange-httpd_age-withdraw.h (renamed from src/exchange/taler-exchange-httpd_withdraw.h)32
-rw-r--r--src/exchange/taler-exchange-httpd_age-withdraw_reveal.c610
-rw-r--r--src/exchange/taler-exchange-httpd_age-withdraw_reveal.h56
-rw-r--r--src/exchange/taler-exchange-httpd_aml-decision-get.c233
-rw-r--r--src/exchange/taler-exchange-httpd_aml-decision.c358
-rw-r--r--src/exchange/taler-exchange-httpd_aml-decision.h79
-rw-r--r--src/exchange/taler-exchange-httpd_aml-decisions-get.c215
-rw-r--r--src/exchange/taler-exchange-httpd_batch-deposit.c648
-rw-r--r--src/exchange/taler-exchange-httpd_batch-withdraw.c638
-rw-r--r--src/exchange/taler-exchange-httpd_coins_get.c709
-rw-r--r--src/exchange/taler-exchange-httpd_coins_get.h (renamed from src/exchange/taler-exchange-httpd_deposit.h)40
-rw-r--r--src/exchange/taler-exchange-httpd_common_deposit.c71
-rw-r--r--src/exchange/taler-exchange-httpd_common_kyc.c302
-rw-r--r--src/exchange/taler-exchange-httpd_common_kyc.h117
-rw-r--r--src/exchange/taler-exchange-httpd_config.c84
-rw-r--r--src/exchange/taler-exchange-httpd_config.h58
-rw-r--r--src/exchange/taler-exchange-httpd_csr.c124
-rw-r--r--src/exchange/taler-exchange-httpd_db.c61
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c497
-rw-r--r--src/exchange/taler-exchange-httpd_deposits_get.c350
-rw-r--r--src/exchange/taler-exchange-httpd_deposits_get.h7
-rw-r--r--src/exchange/taler-exchange-httpd_extensions.c313
-rw-r--r--src/exchange/taler-exchange-httpd_extensions.h15
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c1874
-rw-r--r--src/exchange/taler-exchange-httpd_keys.h160
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-check.c474
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-check.h2
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-proof.c828
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-proof.h4
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-wallet.c136
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-webhook.c420
-rw-r--r--src/exchange/taler-exchange-httpd_kyc-webhook.h64
-rw-r--r--src/exchange/taler-exchange-httpd_link.c25
-rw-r--r--src/exchange/taler-exchange-httpd_link.h4
-rw-r--r--src/exchange/taler-exchange-httpd_management.h39
-rw-r--r--src/exchange/taler-exchange-httpd_management_aml-officers.c142
-rw-r--r--src/exchange/taler-exchange-httpd_management_auditors.c2
-rw-r--r--src/exchange/taler-exchange-httpd_management_drain.c195
-rw-r--r--src/exchange/taler-exchange-httpd_management_extensions.c70
-rw-r--r--src/exchange/taler-exchange-httpd_management_global_fees.c9
-rw-r--r--src/exchange/taler-exchange-httpd_management_partners.c132
-rw-r--r--src/exchange/taler-exchange-httpd_management_post_keys.c321
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_disable.c16
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_enable.c95
-rw-r--r--src/exchange/taler-exchange-httpd_management_wire_fees.c5
-rw-r--r--src/exchange/taler-exchange-httpd_melt.c8
-rw-r--r--src/exchange/taler-exchange-httpd_metrics.h35
-rw-r--r--src/exchange/taler-exchange-httpd_purses_create.c160
-rw-r--r--src/exchange/taler-exchange-httpd_purses_delete.c141
-rw-r--r--src/exchange/taler-exchange-httpd_purses_delete.h (renamed from src/auditor/taler-auditor-httpd_exchanges.h)32
-rw-r--r--src/exchange/taler-exchange-httpd_purses_deposit.c48
-rw-r--r--src/exchange/taler-exchange-httpd_purses_get.c128
-rw-r--r--src/exchange/taler-exchange-httpd_purses_merge.c240
-rw-r--r--src/exchange/taler-exchange-httpd_recoup-refresh.c33
-rw-r--r--src/exchange/taler-exchange-httpd_recoup.c45
-rw-r--r--src/exchange/taler-exchange-httpd_refreshes_reveal.c181
-rw-r--r--src/exchange/taler-exchange-httpd_refund.c1
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_attest.c385
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_attest.h41
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_close.c448
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_close.h (renamed from src/exchange/taler-exchange-httpd_reserves_status.h)20
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get.c285
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get.h9
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get_attest.c232
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_get_attest.h44
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_history.c656
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_history.h12
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_open.c471
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_open.h41
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_purse.c292
-rw-r--r--src/exchange/taler-exchange-httpd_reserves_status.c239
-rw-r--r--src/exchange/taler-exchange-httpd_responses.c939
-rw-r--r--src/exchange/taler-exchange-httpd_responses.h196
-rw-r--r--src/exchange/taler-exchange-httpd_spa.c362
-rw-r--r--src/exchange/taler-exchange-httpd_spa.h49
-rw-r--r--src/exchange/taler-exchange-httpd_transfers_get.c147
-rw-r--r--src/exchange/taler-exchange-httpd_wire.c650
-rw-r--r--src/exchange/taler-exchange-httpd_wire.h84
-rw-r--r--src/exchange/taler-exchange-httpd_withdraw.c466
-rwxr-xr-xsrc/exchange/taler-exchange-kyc-aml-pep-trigger.sh7
-rw-r--r--src/exchange/taler-exchange-router.c4
-rw-r--r--src/exchange/taler-exchange-transfer.c41
-rw-r--r--src/exchange/taler-exchange-wirewatch.c1044
-rw-r--r--src/exchange/test_taler_exchange_httpd.conf4
-rwxr-xr-xsrc/exchange/test_taler_exchange_httpd.sh6
-rw-r--r--src/exchangedb/.gitignore24
-rw-r--r--src/exchangedb/0002-account_merges.sql139
-rw-r--r--src/exchangedb/0002-age_withdraw.sql157
-rw-r--r--src/exchangedb/0002-aggregation_tracking.sql118
-rw-r--r--src/exchangedb/0002-aggregation_transient.sql71
-rw-r--r--src/exchangedb/0002-aml_history.sql147
-rw-r--r--src/exchangedb/0002-aml_staff.sql40
-rw-r--r--src/exchangedb/0002-aml_status.sql101
-rw-r--r--src/exchangedb/0002-auditor_denom_sigs.sql32
-rw-r--r--src/exchangedb/0002-auditors.sql35
-rw-r--r--src/exchangedb/0002-batch_deposits.sql172
-rw-r--r--src/exchangedb/0002-close_requests.sql178
-rw-r--r--src/exchangedb/0002-coin_deposits.sql157
-rw-r--r--src/exchangedb/0002-coin_history.sql138
-rw-r--r--src/exchangedb/0002-contracts.sql109
-rw-r--r--src/exchangedb/0002-cs_nonce_locks.sql97
-rw-r--r--src/exchangedb/0002-denomination_revocations.sql23
-rw-r--r--src/exchangedb/0002-denominations.sql45
-rw-r--r--src/exchangedb/0002-exchange_sign_keys.sql36
-rw-r--r--src/exchangedb/0002-extensions.sql27
-rw-r--r--src/exchangedb/0002-global_fee.sql37
-rw-r--r--src/exchangedb/0002-history_requests.sql159
-rw-r--r--src/exchangedb/0002-known_coins.sql136
-rw-r--r--src/exchangedb/0002-kyc_alerts.sql27
-rw-r--r--src/exchangedb/0002-kyc_attributes.sql162
-rw-r--r--src/exchangedb/0002-legitimization_processes.sql149
-rw-r--r--src/exchangedb/0002-legitimization_requirements.sql104
-rw-r--r--src/exchangedb/0002-partner_accounts.sql33
-rw-r--r--src/exchangedb/0002-partners.sql49
-rw-r--r--src/exchangedb/0002-policy_details.sql175
-rw-r--r--src/exchangedb/0002-policy_fulfillments.sql101
-rw-r--r--src/exchangedb/0002-prewire.sql116
-rw-r--r--src/exchangedb/0002-profit_drains.sql42
-rw-r--r--src/exchangedb/0002-purse_actions.sql121
-rw-r--r--src/exchangedb/0002-purse_decision.sql143
-rw-r--r--src/exchangedb/0002-purse_deletion.sql110
-rw-r--r--src/exchangedb/0002-purse_deposits.sql176
-rw-r--r--src/exchangedb/0002-purse_merges.sql140
-rw-r--r--src/exchangedb/0002-purse_requests.sql163
-rw-r--r--src/exchangedb/0002-recoup.sql267
-rw-r--r--src/exchangedb/0002-recoup_refresh.sql203
-rw-r--r--src/exchangedb/0002-refresh_commitments.sql166
-rw-r--r--src/exchangedb/0002-refresh_revealed_coins.sql169
-rw-r--r--src/exchangedb/0002-refresh_transfer_keys.sql127
-rw-r--r--src/exchangedb/0002-refunds.sql162
-rw-r--r--src/exchangedb/0002-reserve_history.sql138
-rw-r--r--src/exchangedb/0002-reserves.sql152
-rw-r--r--src/exchangedb/0002-reserves_close.sql151
-rw-r--r--src/exchangedb/0002-reserves_in.sql175
-rw-r--r--src/exchangedb/0002-reserves_open_deposits.sql135
-rw-r--r--src/exchangedb/0002-reserves_open_requests.sql150
-rw-r--r--src/exchangedb/0002-reserves_out.sql173
-rw-r--r--src/exchangedb/0002-revolving_work_shards.sql46
-rw-r--r--src/exchangedb/0002-signkey_revocations.sql23
-rw-r--r--src/exchangedb/0002-wad_in_entries.sql175
-rw-r--r--src/exchangedb/0002-wad_out_entries.sql179
-rw-r--r--src/exchangedb/0002-wads_in.sql107
-rw-r--r--src/exchangedb/0002-wads_out.sql128
-rw-r--r--src/exchangedb/0002-wire_accounts.sql45
-rw-r--r--src/exchangedb/0002-wire_fee.sql34
-rw-r--r--src/exchangedb/0002-wire_out.sql130
-rw-r--r--src/exchangedb/0002-wire_targets.sql89
-rw-r--r--src/exchangedb/0002-work_shards.sql56
-rw-r--r--src/exchangedb/0003-purse_deletion.sql52
-rw-r--r--src/exchangedb/0003-wire_accounts.sql25
-rw-r--r--src/exchangedb/0004-refunds.sql35
-rw-r--r--src/exchangedb/Makefile.am345
-rw-r--r--src/exchangedb/auditor-triggers-0001.sql41
-rw-r--r--src/exchangedb/bench-db-postgres.conf4
-rw-r--r--src/exchangedb/bench_db.c30
-rw-r--r--src/exchangedb/common-0001.sql2747
-rw-r--r--src/exchangedb/drop-common.sql97
-rw-r--r--src/exchangedb/drop.sql39
-rw-r--r--src/exchangedb/drop0001-exchange-part.sql108
-rw-r--r--src/exchangedb/exchange-0001-part.sql3664
-rw-r--r--src/exchangedb/exchange-0001.sql296
-rw-r--r--src/exchangedb/exchange-0002.sql.in118
-rw-r--r--src/exchangedb/exchange-0003.sql.in25
-rw-r--r--src/exchangedb/exchange-0004.sql.in24
-rw-r--r--src/exchangedb/exchange_do_account_merge.sql15
-rw-r--r--src/exchangedb/exchange_do_age_withdraw.sql165
-rw-r--r--src/exchangedb/exchange_do_amount_specific.sql92
-rw-r--r--src/exchangedb/exchange_do_batch_coin_known.sql469
-rw-r--r--src/exchangedb/exchange_do_batch_reserves_update.sql72
-rw-r--r--src/exchangedb/exchange_do_batch_withdraw.sql126
-rw-r--r--src/exchangedb/exchange_do_batch_withdraw_insert.sql120
-rw-r--r--src/exchangedb/exchange_do_deposit.sql206
-rw-r--r--src/exchangedb/exchange_do_expire_purse.sql98
-rw-r--r--src/exchangedb/exchange_do_gc.sql140
-rw-r--r--src/exchangedb/exchange_do_get_link_data.sql59
-rw-r--r--src/exchangedb/exchange_do_insert_aml_decision.sql127
-rw-r--r--src/exchangedb/exchange_do_insert_aml_officer.sql74
-rw-r--r--src/exchangedb/exchange_do_insert_kyc_attributes.sql114
-rw-r--r--src/exchangedb/exchange_do_insert_or_update_policy_details.sql114
-rw-r--r--src/exchangedb/exchange_do_melt.sql182
-rw-r--r--src/exchangedb/exchange_do_purse_delete.sql118
-rw-r--r--src/exchangedb/exchange_do_purse_deposit.sql267
-rw-r--r--src/exchangedb/exchange_do_purse_merge.sql237
-rw-r--r--src/exchangedb/exchange_do_recoup_by_reserve.sql87
-rw-r--r--src/exchangedb/exchange_do_recoup_to_coin.sql135
-rw-r--r--src/exchangedb/exchange_do_recoup_to_reserve.sql150
-rw-r--r--src/exchangedb/exchange_do_refund.sql205
-rw-r--r--src/exchangedb/exchange_do_reserve_open.sql194
-rw-r--r--src/exchangedb/exchange_do_reserve_open_deposit.sql84
-rw-r--r--src/exchangedb/exchange_do_reserve_purse.sql162
-rw-r--r--src/exchangedb/exchange_do_reserves_in_insert.sql122
-rw-r--r--src/exchangedb/exchange_do_select_deposits_missing_wire.sql73
-rw-r--r--src/exchangedb/exchange_do_select_justification_for_missing_wire.sql102
-rw-r--r--src/exchangedb/exchangedb-postgres.conf7
-rw-r--r--src/exchangedb/exchangedb.conf4
-rw-r--r--src/exchangedb/exchangedb_accounts.c1
-rw-r--r--src/exchangedb/exchangedb_transactions.c31
-rw-r--r--src/exchangedb/irbt_callbacks.c1134
-rwxr-xr-xsrc/exchangedb/perf-exchangedb-reserves-in-insert-postgres210
-rw-r--r--src/exchangedb/perf_deposits_get_ready.c565
-rw-r--r--src/exchangedb/perf_get_link_data.c543
-rw-r--r--src/exchangedb/perf_reserves_in_insert.c232
-rw-r--r--src/exchangedb/perf_select_refunds_by_coin.c619
-rw-r--r--src/exchangedb/pg_abort_shard.c53
-rw-r--r--src/exchangedb/pg_abort_shard.h43
-rw-r--r--src/exchangedb/pg_activate_signing_key.c58
-rw-r--r--src/exchangedb/pg_activate_signing_key.h44
-rw-r--r--src/exchangedb/pg_add_denomination_key.c86
-rw-r--r--src/exchangedb/pg_add_denomination_key.h46
-rw-r--r--src/exchangedb/pg_add_policy_fulfillment_proof.c159
-rw-r--r--src/exchangedb/pg_add_policy_fulfillment_proof.h39
-rw-r--r--src/exchangedb/pg_aggregate.c205
-rw-r--r--src/exchangedb/pg_aggregate.h46
-rw-r--r--src/exchangedb/pg_batch_ensure_coin_known.c462
-rw-r--r--src/exchangedb/pg_batch_ensure_coin_known.h47
-rw-r--r--src/exchangedb/pg_begin_revolving_shard.c263
-rw-r--r--src/exchangedb/pg_begin_revolving_shard.h49
-rw-r--r--src/exchangedb/pg_begin_shard.c266
-rw-r--r--src/exchangedb/pg_begin_shard.h47
-rw-r--r--src/exchangedb/pg_commit.c58
-rw-r--r--src/exchangedb/pg_commit.h37
-rw-r--r--src/exchangedb/pg_complete_shard.c56
-rw-r--r--src/exchangedb/pg_complete_shard.h43
-rw-r--r--src/exchangedb/pg_compute_shard.c49
-rw-r--r--src/exchangedb/pg_compute_shard.h39
-rw-r--r--src/exchangedb/pg_count_known_coins.c63
-rw-r--r--src/exchangedb/pg_count_known_coins.h39
-rw-r--r--src/exchangedb/pg_create_aggregation_transient.c64
-rw-r--r--src/exchangedb/pg_create_aggregation_transient.h49
-rw-r--r--src/exchangedb/pg_create_tables.c72
-rw-r--r--src/exchangedb/pg_create_tables.h44
-rw-r--r--src/exchangedb/pg_delete_aggregation_transient.c50
-rw-r--r--src/exchangedb/pg_delete_aggregation_transient.h43
-rw-r--r--src/exchangedb/pg_delete_shard_locks.c41
-rw-r--r--src/exchangedb/pg_delete_shard_locks.h38
-rw-r--r--src/exchangedb/pg_do_age_withdraw.c108
-rw-r--r--src/exchangedb/pg_do_age_withdraw.h57
-rw-r--r--src/exchangedb/pg_do_batch_withdraw.c89
-rw-r--r--src/exchangedb/pg_do_batch_withdraw.h59
-rw-r--r--src/exchangedb/pg_do_batch_withdraw_insert.c77
-rw-r--r--src/exchangedb/pg_do_batch_withdraw_insert.h52
-rw-r--r--src/exchangedb/pg_do_deposit.c119
-rw-r--r--src/exchangedb/pg_do_deposit.h51
-rw-r--r--src/exchangedb/pg_do_melt.c82
-rw-r--r--src/exchangedb/pg_do_melt.h49
-rw-r--r--src/exchangedb/pg_do_purse_delete.c64
-rw-r--r--src/exchangedb/pg_do_purse_delete.h49
-rw-r--r--src/exchangedb/pg_do_purse_deposit.c90
-rw-r--r--src/exchangedb/pg_do_purse_deposit.h63
-rw-r--r--src/exchangedb/pg_do_purse_merge.c91
-rw-r--r--src/exchangedb/pg_do_purse_merge.h57
-rw-r--r--src/exchangedb/pg_do_recoup.c85
-rw-r--r--src/exchangedb/pg_do_recoup.h56
-rw-r--r--src/exchangedb/pg_do_recoup_refresh.c79
-rw-r--r--src/exchangedb/pg_do_recoup_refresh.h57
-rw-r--r--src/exchangedb/pg_do_refund.c93
-rw-r--r--src/exchangedb/pg_do_refund.h52
-rw-r--r--src/exchangedb/pg_do_reserve_open.c101
-rw-r--r--src/exchangedb/pg_do_reserve_open.h64
-rw-r--r--src/exchangedb/pg_do_reserve_purse.c121
-rw-r--r--src/exchangedb/pg_do_reserve_purse.h57
-rw-r--r--src/exchangedb/pg_drain_kyc_alert.c59
-rw-r--r--src/exchangedb/pg_drain_kyc_alert.h40
-rw-r--r--src/exchangedb/pg_drop_tables.c58
-rw-r--r--src/exchangedb/pg_drop_tables.h38
-rw-r--r--src/exchangedb/pg_ensure_coin_known.c169
-rw-r--r--src/exchangedb/pg_ensure_coin_known.h45
-rw-r--r--src/exchangedb/pg_event_listen.c53
-rw-r--r--src/exchangedb/pg_event_listen.h45
-rw-r--r--src/exchangedb/pg_event_listen_cancel.c36
-rw-r--r--src/exchangedb/pg_event_listen_cancel.h38
-rw-r--r--src/exchangedb/pg_event_notify.c41
-rw-r--r--src/exchangedb/pg_event_notify.h42
-rw-r--r--src/exchangedb/pg_expire_purse.c69
-rw-r--r--src/exchangedb/pg_expire_purse.h41
-rw-r--r--src/exchangedb/pg_find_aggregation_transient.c150
-rw-r--r--src/exchangedb/pg_find_aggregation_transient.h43
-rw-r--r--src/exchangedb/pg_gc.c80
-rw-r--r--src/exchangedb/pg_gc.h39
-rw-r--r--src/exchangedb/pg_get_age_withdraw.c119
-rw-r--r--src/exchangedb/pg_get_age_withdraw.h45
-rw-r--r--src/exchangedb/pg_get_coin_denomination.c69
-rw-r--r--src/exchangedb/pg_get_coin_denomination.h43
-rw-r--r--src/exchangedb/pg_get_coin_transactions.c1144
-rw-r--r--src/exchangedb/pg_get_coin_transactions.h61
-rw-r--r--src/exchangedb/pg_get_denomination_info.c91
-rw-r--r--src/exchangedb/pg_get_denomination_info.h41
-rw-r--r--src/exchangedb/pg_get_denomination_revocation.c63
-rw-r--r--src/exchangedb/pg_get_denomination_revocation.h45
-rw-r--r--src/exchangedb/pg_get_drain_profit.c76
-rw-r--r--src/exchangedb/pg_get_drain_profit.h52
-rw-r--r--src/exchangedb/pg_get_expired_reserves.c174
-rw-r--r--src/exchangedb/pg_get_expired_reserves.h45
-rw-r--r--src/exchangedb/pg_get_extension_manifest.c67
-rw-r--r--src/exchangedb/pg_get_extension_manifest.h42
-rw-r--r--src/exchangedb/pg_get_global_fee.c86
-rw-r--r--src/exchangedb/pg_get_global_fee.h52
-rw-r--r--src/exchangedb/pg_get_global_fees.c165
-rw-r--r--src/exchangedb/pg_get_global_fees.h41
-rw-r--r--src/exchangedb/pg_get_known_coin.c67
-rw-r--r--src/exchangedb/pg_get_known_coin.h40
-rw-r--r--src/exchangedb/pg_get_link_data.c367
-rw-r--r--src/exchangedb/pg_get_link_data.h45
-rw-r--r--src/exchangedb/pg_get_melt.c124
-rw-r--r--src/exchangedb/pg_get_melt.h44
-rw-r--r--src/exchangedb/pg_get_old_coin_by_h_blind.c64
-rw-r--r--src/exchangedb/pg_get_old_coin_by_h_blind.h45
-rw-r--r--src/exchangedb/pg_get_pending_kyc_requirement_process.c66
-rw-r--r--src/exchangedb/pg_get_pending_kyc_requirement_process.h45
-rw-r--r--src/exchangedb/pg_get_policy_details.c64
-rw-r--r--src/exchangedb/pg_get_policy_details.h40
-rw-r--r--src/exchangedb/pg_get_purse_deposit.c84
-rw-r--r--src/exchangedb/pg_get_purse_deposit.h53
-rw-r--r--src/exchangedb/pg_get_purse_request.c79
-rw-r--r--src/exchangedb/pg_get_purse_request.h57
-rw-r--r--src/exchangedb/pg_get_ready_deposit.c74
-rw-r--r--src/exchangedb/pg_get_ready_deposit.h46
-rw-r--r--src/exchangedb/pg_get_refresh_reveal.c213
-rw-r--r--src/exchangedb/pg_get_refresh_reveal.h44
-rw-r--r--src/exchangedb/pg_get_reserve_balance.c55
-rw-r--r--src/exchangedb/pg_get_reserve_balance.h40
-rw-r--r--src/exchangedb/pg_get_reserve_by_h_blind.c63
-rw-r--r--src/exchangedb/pg_get_reserve_by_h_blind.h44
-rw-r--r--src/exchangedb/pg_get_reserve_history.c936
-rw-r--r--src/exchangedb/pg_get_reserve_history.h57
-rw-r--r--src/exchangedb/pg_get_signature_for_known_coin.c63
-rw-r--r--src/exchangedb/pg_get_signature_for_known_coin.h43
-rw-r--r--src/exchangedb/pg_get_unfinished_close_requests.c166
-rw-r--r--src/exchangedb/pg_get_unfinished_close_requests.h46
-rw-r--r--src/exchangedb/pg_get_wire_accounts.c169
-rw-r--r--src/exchangedb/pg_get_wire_accounts.h42
-rw-r--r--src/exchangedb/pg_get_wire_fee.c73
-rw-r--r--src/exchangedb/pg_get_wire_fee.h49
-rw-r--r--src/exchangedb/pg_get_wire_fees.c147
-rw-r--r--src/exchangedb/pg_get_wire_fees.h44
-rw-r--r--src/exchangedb/pg_get_wire_hash_for_contract.c81
-rw-r--r--src/exchangedb/pg_get_wire_hash_for_contract.h46
-rw-r--r--src/exchangedb/pg_get_withdraw_info.c79
-rw-r--r--src/exchangedb/pg_get_withdraw_info.h43
-rw-r--r--src/exchangedb/pg_have_deposit2.c117
-rw-r--r--src/exchangedb/pg_have_deposit2.h53
-rw-r--r--src/exchangedb/pg_helper.h149
-rw-r--r--src/exchangedb/pg_inject_auditor_triggers.c57
-rw-r--r--src/exchangedb/pg_inject_auditor_triggers.h41
-rw-r--r--src/exchangedb/pg_insert_aml_decision.c97
-rw-r--r--src/exchangedb/pg_insert_aml_decision.h64
-rw-r--r--src/exchangedb/pg_insert_aml_officer.c66
-rw-r--r--src/exchangedb/pg_insert_aml_officer.h56
-rw-r--r--src/exchangedb/pg_insert_auditor.c58
-rw-r--r--src/exchangedb/pg_insert_auditor.h45
-rw-r--r--src/exchangedb/pg_insert_auditor_denom_sig.c61
-rw-r--r--src/exchangedb/pg_insert_auditor_denom_sig.h43
-rw-r--r--src/exchangedb/pg_insert_close_request.c68
-rw-r--r--src/exchangedb/pg_insert_close_request.h52
-rw-r--r--src/exchangedb/pg_insert_contract.c93
-rw-r--r--src/exchangedb/pg_insert_contract.h47
-rw-r--r--src/exchangedb/pg_insert_denomination_info.c101
-rw-r--r--src/exchangedb/pg_insert_denomination_info.h42
-rw-r--r--src/exchangedb/pg_insert_denomination_revocation.c54
-rw-r--r--src/exchangedb/pg_insert_denomination_revocation.h42
-rw-r--r--src/exchangedb/pg_insert_drain_profit.c63
-rw-r--r--src/exchangedb/pg_insert_drain_profit.h50
-rw-r--r--src/exchangedb/pg_insert_global_fee.c137
-rw-r--r--src/exchangedb/pg_insert_global_fee.h50
-rw-r--r--src/exchangedb/pg_insert_kyc_attributes.c110
-rw-r--r--src/exchangedb/pg_insert_kyc_attributes.h69
-rw-r--r--src/exchangedb/pg_insert_kyc_failure.c82
-rw-r--r--src/exchangedb/pg_insert_kyc_failure.h50
-rw-r--r--src/exchangedb/pg_insert_kyc_requirement_for_account.c67
-rw-r--r--src/exchangedb/pg_insert_kyc_requirement_for_account.h47
-rw-r--r--src/exchangedb/pg_insert_kyc_requirement_process.c75
-rw-r--r--src/exchangedb/pg_insert_kyc_requirement_process.h49
-rw-r--r--src/exchangedb/pg_insert_partner.c69
-rw-r--r--src/exchangedb/pg_insert_partner.h51
-rw-r--r--src/exchangedb/pg_insert_purse_request.c126
-rw-r--r--src/exchangedb/pg_insert_purse_request.h61
-rw-r--r--src/exchangedb/pg_insert_records_by_table.c2334
-rw-r--r--src/exchangedb/pg_insert_records_by_table.h43
-rw-r--r--src/exchangedb/pg_insert_refresh_reveal.c109
-rw-r--r--src/exchangedb/pg_insert_refresh_reveal.h51
-rw-r--r--src/exchangedb/pg_insert_refund.c65
-rw-r--r--src/exchangedb/pg_insert_refund.h38
-rw-r--r--src/exchangedb/pg_insert_reserve_closed.c113
-rw-r--r--src/exchangedb/pg_insert_reserve_closed.h51
-rw-r--r--src/exchangedb/pg_insert_reserve_open_deposit.c67
-rw-r--r--src/exchangedb/pg_insert_reserve_open_deposit.h54
-rw-r--r--src/exchangedb/pg_insert_signkey_revocation.c53
-rw-r--r--src/exchangedb/pg_insert_signkey_revocation.h41
-rw-r--r--src/exchangedb/pg_insert_wire.c74
-rw-r--r--src/exchangedb/pg_insert_wire.h55
-rw-r--r--src/exchangedb/pg_insert_wire_fee.c108
-rw-r--r--src/exchangedb/pg_insert_wire_fee.h46
-rw-r--r--src/exchangedb/pg_iterate_active_auditors.c123
-rw-r--r--src/exchangedb/pg_iterate_active_auditors.h42
-rw-r--r--src/exchangedb/pg_iterate_active_signkeys.c144
-rw-r--r--src/exchangedb/pg_iterate_active_signkeys.h43
-rw-r--r--src/exchangedb/pg_iterate_auditor_denominations.c121
-rw-r--r--src/exchangedb/pg_iterate_auditor_denominations.h45
-rw-r--r--src/exchangedb/pg_iterate_denomination_info.c180
-rw-r--r--src/exchangedb/pg_iterate_denomination_info.h41
-rw-r--r--src/exchangedb/pg_iterate_denominations.c172
-rw-r--r--src/exchangedb/pg_iterate_denominations.h44
-rw-r--r--src/exchangedb/pg_iterate_kyc_reference.c129
-rw-r--r--src/exchangedb/pg_iterate_kyc_reference.h46
-rw-r--r--src/exchangedb/pg_iterate_reserve_close_info.c128
-rw-r--r--src/exchangedb/pg_iterate_reserve_close_info.h49
-rw-r--r--src/exchangedb/pg_kyc_provider_account_lookup.c64
-rw-r--r--src/exchangedb/pg_kyc_provider_account_lookup.h48
-rw-r--r--src/exchangedb/pg_lookup_aml_officer.c71
-rw-r--r--src/exchangedb/pg_lookup_aml_officer.h51
-rw-r--r--src/exchangedb/pg_lookup_auditor_status.c61
-rw-r--r--src/exchangedb/pg_lookup_auditor_status.h44
-rw-r--r--src/exchangedb/pg_lookup_auditor_timestamp.c57
-rw-r--r--src/exchangedb/pg_lookup_auditor_timestamp.h41
-rw-r--r--src/exchangedb/pg_lookup_denomination_key.c82
-rw-r--r--src/exchangedb/pg_lookup_denomination_key.h41
-rw-r--r--src/exchangedb/pg_lookup_global_fee_by_time.c182
-rw-r--r--src/exchangedb/pg_lookup_global_fee_by_time.h52
-rw-r--r--src/exchangedb/pg_lookup_kyc_process_by_account.c83
-rw-r--r--src/exchangedb/pg_lookup_kyc_process_by_account.h51
-rw-r--r--src/exchangedb/pg_lookup_kyc_requirement_by_row.c71
-rw-r--r--src/exchangedb/pg_lookup_kyc_requirement_by_row.h47
-rw-r--r--src/exchangedb/pg_lookup_records_by_table.c (renamed from src/exchangedb/lrbt_callbacks.c)1646
-rw-r--r--src/exchangedb/pg_lookup_records_by_table.h49
-rw-r--r--src/exchangedb/pg_lookup_serial_by_table.c459
-rw-r--r--src/exchangedb/pg_lookup_serial_by_table.h45
-rw-r--r--src/exchangedb/pg_lookup_signing_key.c64
-rw-r--r--src/exchangedb/pg_lookup_signing_key.h42
-rw-r--r--src/exchangedb/pg_lookup_signkey_revocation.c59
-rw-r--r--src/exchangedb/pg_lookup_signkey_revocation.h42
-rw-r--r--src/exchangedb/pg_lookup_transfer_by_deposit.c239
-rw-r--r--src/exchangedb/pg_lookup_transfer_by_deposit.h63
-rw-r--r--src/exchangedb/pg_lookup_wire_fee_by_time.c156
-rw-r--r--src/exchangedb/pg_lookup_wire_fee_by_time.h76
-rw-r--r--src/exchangedb/pg_lookup_wire_timestamp.c56
-rw-r--r--src/exchangedb/pg_lookup_wire_timestamp.h40
-rw-r--r--src/exchangedb/pg_lookup_wire_transfer.c188
-rw-r--r--src/exchangedb/pg_lookup_wire_transfer.h45
-rw-r--r--src/exchangedb/pg_persist_policy_details.c78
-rw-r--r--src/exchangedb/pg_persist_policy_details.h47
-rw-r--r--src/exchangedb/pg_preflight.c69
-rw-r--r--src/exchangedb/pg_preflight.h44
-rw-r--r--src/exchangedb/pg_profit_drains_get_pending.c78
-rw-r--r--src/exchangedb/pg_profit_drains_get_pending.h52
-rw-r--r--src/exchangedb/pg_profit_drains_set_finished.c49
-rw-r--r--src/exchangedb/pg_profit_drains_set_finished.h40
-rw-r--r--src/exchangedb/pg_release_revolving_shard.c59
-rw-r--r--src/exchangedb/pg_release_revolving_shard.h44
-rw-r--r--src/exchangedb/pg_reserves_get.c61
-rw-r--r--src/exchangedb/pg_reserves_get.h40
-rw-r--r--src/exchangedb/pg_reserves_get_origin.c57
-rw-r--r--src/exchangedb/pg_reserves_get_origin.h41
-rw-r--r--src/exchangedb/pg_reserves_in_insert.c373
-rw-r--r--src/exchangedb/pg_reserves_in_insert.h47
-rw-r--r--src/exchangedb/pg_reserves_update.c53
-rw-r--r--src/exchangedb/pg_reserves_update.h40
-rw-r--r--src/exchangedb/pg_rollback.c50
-rw-r--r--src/exchangedb/pg_rollback.h36
-rw-r--r--src/exchangedb/pg_select_account_merges_above_serial_id.c192
-rw-r--r--src/exchangedb/pg_select_account_merges_above_serial_id.h46
-rw-r--r--src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c154
-rw-r--r--src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.h48
-rw-r--r--src/exchangedb/pg_select_aggregation_transient.c66
-rw-r--r--src/exchangedb/pg_select_aggregation_transient.h47
-rw-r--r--src/exchangedb/pg_select_aggregations_above_serial.c137
-rw-r--r--src/exchangedb/pg_select_aggregations_above_serial.h47
-rw-r--r--src/exchangedb/pg_select_all_purse_decisions_above_serial_id.c146
-rw-r--r--src/exchangedb/pg_select_all_purse_decisions_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_aml_history.c157
-rw-r--r--src/exchangedb/pg_select_aml_history.h46
-rw-r--r--src/exchangedb/pg_select_aml_process.c170
-rw-r--r--src/exchangedb/pg_select_aml_process.h52
-rw-r--r--src/exchangedb/pg_select_aml_threshold.c70
-rw-r--r--src/exchangedb/pg_select_aml_threshold.h48
-rw-r--r--src/exchangedb/pg_select_auditor_denom_sig.c66
-rw-r--r--src/exchangedb/pg_select_auditor_denom_sig.h43
-rw-r--r--src/exchangedb/pg_select_batch_deposits_missing_wire.c144
-rw-r--r--src/exchangedb/pg_select_batch_deposits_missing_wire.h44
-rw-r--r--src/exchangedb/pg_select_coin_deposits_above_serial_id.c204
-rw-r--r--src/exchangedb/pg_select_coin_deposits_above_serial_id.h44
-rw-r--r--src/exchangedb/pg_select_contract.c66
-rw-r--r--src/exchangedb/pg_select_contract.h47
-rw-r--r--src/exchangedb/pg_select_contract_by_purse.c63
-rw-r--r--src/exchangedb/pg_select_contract_by_purse.h42
-rw-r--r--src/exchangedb/pg_select_justification_for_missing_wire.c89
-rw-r--r--src/exchangedb/pg_select_justification_for_missing_wire.h49
-rw-r--r--src/exchangedb/pg_select_kyc_attributes.c156
-rw-r--r--src/exchangedb/pg_select_kyc_attributes.h45
-rw-r--r--src/exchangedb/pg_select_merge_amounts_for_kyc_check.c157
-rw-r--r--src/exchangedb/pg_select_merge_amounts_for_kyc_check.h47
-rw-r--r--src/exchangedb/pg_select_purse.c94
-rw-r--r--src/exchangedb/pg_select_purse.h57
-rw-r--r--src/exchangedb/pg_select_purse_by_merge_pub.c79
-rw-r--r--src/exchangedb/pg_select_purse_by_merge_pub.h54
-rw-r--r--src/exchangedb/pg_select_purse_decisions_above_serial_id.c162
-rw-r--r--src/exchangedb/pg_select_purse_decisions_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_purse_deposits_above_serial_id.c201
-rw-r--r--src/exchangedb/pg_select_purse_deposits_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_purse_deposits_by_purse.c153
-rw-r--r--src/exchangedb/pg_select_purse_deposits_by_purse.h44
-rw-r--r--src/exchangedb/pg_select_purse_merge.c80
-rw-r--r--src/exchangedb/pg_select_purse_merge.h51
-rw-r--r--src/exchangedb/pg_select_purse_merges_above_serial_id.c190
-rw-r--r--src/exchangedb/pg_select_purse_merges_above_serial_id.h46
-rw-r--r--src/exchangedb/pg_select_purse_requests_above_serial_id.c178
-rw-r--r--src/exchangedb/pg_select_purse_requests_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_recoup_above_serial_id.c194
-rw-r--r--src/exchangedb/pg_select_recoup_above_serial_id.h44
-rw-r--r--src/exchangedb/pg_select_recoup_refresh_above_serial_id.c203
-rw-r--r--src/exchangedb/pg_select_recoup_refresh_above_serial_id.h45
-rw-r--r--src/exchangedb/pg_select_refreshes_above_serial_id.c179
-rw-r--r--src/exchangedb/pg_select_refreshes_above_serial_id.h45
-rw-r--r--src/exchangedb/pg_select_refunds_above_serial_id.c223
-rw-r--r--src/exchangedb/pg_select_refunds_above_serial_id.h45
-rw-r--r--src/exchangedb/pg_select_refunds_by_coin.c143
-rw-r--r--src/exchangedb/pg_select_refunds_by_coin.h48
-rw-r--r--src/exchangedb/pg_select_reserve_close_info.c63
-rw-r--r--src/exchangedb/pg_select_reserve_close_info.h49
-rw-r--r--src/exchangedb/pg_select_reserve_closed_above_serial_id.c178
-rw-r--r--src/exchangedb/pg_select_reserve_closed_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_reserve_open_above_serial_id.c168
-rw-r--r--src/exchangedb/pg_select_reserve_open_above_serial_id.h47
-rw-r--r--src/exchangedb/pg_select_reserves_in_above_serial_id.c164
-rw-r--r--src/exchangedb/pg_select_reserves_in_above_serial_id.h44
-rw-r--r--src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c168
-rw-r--r--src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.h46
-rw-r--r--src/exchangedb/pg_select_satisfied_kyc_processes.c141
-rw-r--r--src/exchangedb/pg_select_satisfied_kyc_processes.h47
-rw-r--r--src/exchangedb/pg_select_similar_kyc_attributes.c154
-rw-r--r--src/exchangedb/pg_select_similar_kyc_attributes.h45
-rw-r--r--src/exchangedb/pg_select_wire_out_above_serial_id.c157
-rw-r--r--src/exchangedb/pg_select_wire_out_above_serial_id.h45
-rw-r--r--src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c161
-rw-r--r--src/exchangedb/pg_select_wire_out_above_serial_id_by_account.h47
-rw-r--r--src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c158
-rw-r--r--src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.h48
-rw-r--r--src/exchangedb/pg_select_withdrawals_above_serial_id.c170
-rw-r--r--src/exchangedb/pg_select_withdrawals_above_serial_id.h45
-rw-r--r--src/exchangedb/pg_set_extension_manifest.c56
-rw-r--r--src/exchangedb/pg_set_extension_manifest.h43
-rw-r--r--src/exchangedb/pg_set_purse_balance.c52
-rw-r--r--src/exchangedb/pg_set_purse_balance.h43
-rw-r--r--src/exchangedb/pg_setup_wire_target.c54
-rw-r--r--src/exchangedb/pg_setup_wire_target.h43
-rw-r--r--src/exchangedb/pg_start.c56
-rw-r--r--src/exchangedb/pg_start.h40
-rw-r--r--src/exchangedb/pg_start_deferred_wire_out.c59
-rw-r--r--src/exchangedb/pg_start_deferred_wire_out.h39
-rw-r--r--src/exchangedb/pg_start_read_committed.c56
-rw-r--r--src/exchangedb/pg_start_read_committed.h39
-rw-r--r--src/exchangedb/pg_start_read_only.c57
-rw-r--r--src/exchangedb/pg_start_read_only.h40
-rw-r--r--src/exchangedb/pg_store_wire_transfer_out.c61
-rw-r--r--src/exchangedb/pg_store_wire_transfer_out.h48
-rw-r--r--src/exchangedb/pg_template.c26
-rw-r--r--src/exchangedb/pg_template.h29
-rwxr-xr-xsrc/exchangedb/pg_template.sh21
-rw-r--r--src/exchangedb/pg_test_aml_officer.c48
-rw-r--r--src/exchangedb/pg_test_aml_officer.h43
-rw-r--r--src/exchangedb/pg_trigger_aml_process.c58
-rw-r--r--src/exchangedb/pg_trigger_aml_process.h45
-rw-r--r--src/exchangedb/pg_update_aggregation_transient.c57
-rw-r--r--src/exchangedb/pg_update_aggregation_transient.h46
-rw-r--r--src/exchangedb/pg_update_auditor.c59
-rw-r--r--src/exchangedb/pg_update_auditor.h47
-rw-r--r--src/exchangedb/pg_update_kyc_process_by_row.c122
-rw-r--r--src/exchangedb/pg_update_kyc_process_by_row.h53
-rw-r--r--src/exchangedb/pg_update_wire.c81
-rw-r--r--src/exchangedb/pg_update_wire.h57
-rw-r--r--src/exchangedb/pg_wire_prepare_data_get.c140
-rw-r--r--src/exchangedb/pg_wire_prepare_data_get.h46
-rw-r--r--src/exchangedb/pg_wire_prepare_data_insert.c54
-rw-r--r--src/exchangedb/pg_wire_prepare_data_insert.h43
-rw-r--r--src/exchangedb/pg_wire_prepare_data_mark_failed.c48
-rw-r--r--src/exchangedb/pg_wire_prepare_data_mark_failed.h40
-rw-r--r--src/exchangedb/pg_wire_prepare_data_mark_finished.c47
-rw-r--r--src/exchangedb/pg_wire_prepare_data_mark_finished.h40
-rw-r--r--src/exchangedb/plugin_exchangedb_common.c61
-rw-r--r--src/exchangedb/plugin_exchangedb_common.h51
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c16600
-rw-r--r--src/exchangedb/procedures.sql.in49
-rw-r--r--src/exchangedb/shard-0001-part.sql273
-rw-r--r--src/exchangedb/spi/Makefile9
-rw-r--r--src/exchangedb/spi/README.md37
-rw-r--r--src/exchangedb/spi/own_test.c873
-rw-r--r--src/exchangedb/spi/own_test.control4
-rw-r--r--src/exchangedb/spi/own_test.sql201
-rw-r--r--src/exchangedb/spi/perf_own_test.c25
-rw-r--r--src/exchangedb/spi/pg_aggregate.c411
-rw-r--r--src/exchangedb/test-exchange-db-postgres.conf5
-rwxr-xr-xsrc/exchangedb/test-exchangedb-batch-reserves-in-insert-postgres210
-rwxr-xr-xsrc/exchangedb/test-exchangedb-by-j-postgres210
-rwxr-xr-xsrc/exchangedb/test-exchangedb-populate-link-data-postgres210
-rwxr-xr-xsrc/exchangedb/test-exchangedb-populate-ready-deposit-postgres210
-rwxr-xr-xsrc/exchangedb/test-exchangedb-populate-select-refunds-by-coin-postgres210
-rw-r--r--src/exchangedb/test_exchangedb.c572
-rw-r--r--src/exchangedb/test_exchangedb_by_j.c232
-rwxr-xr-xsrc/exchangedb/test_idempotency.sh12
-rw-r--r--src/exchangedb/versioning.sql (renamed from src/exchangedb/benchmark-0000.sql)3
-rw-r--r--src/extensions/Makefile.am5
-rw-r--r--src/extensions/age_restriction/Makefile.am32
-rw-r--r--src/extensions/age_restriction/age_restriction.c256
-rw-r--r--src/extensions/age_restriction_helper.c73
-rw-r--r--src/extensions/extension_age_restriction.c411
-rw-r--r--src/extensions/extensions.c272
-rw-r--r--src/include/Makefile.am5
-rw-r--r--src/include/platform.h219
-rw-r--r--src/include/taler_amount_lib.h16
-rw-r--r--src/include/taler_attributes.h129
-rw-r--r--src/include/taler_auditor_service.h210
-rw-r--r--src/include/taler_auditordb_plugin.h1124
-rw-r--r--src/include/taler_bank_service.h294
-rw-r--r--src/include/taler_crypto_lib.h1612
-rw-r--r--src/include/taler_curl_lib.h18
-rw-r--r--src/include/taler_exchange_service.h4121
-rw-r--r--src/include/taler_exchangedb_lib.h7
-rw-r--r--src/include/taler_exchangedb_plugin.h2678
-rw-r--r--src/include/taler_extensions.h368
-rw-r--r--src/include/taler_extensions_policy.h205
-rw-r--r--src/include/taler_fakebank_lib.h29
-rw-r--r--src/include/taler_json_lib.h272
-rw-r--r--src/include/taler_kyclogic_lib.h374
-rw-r--r--src/include/taler_kyclogic_plugin.h384
-rw-r--r--src/include/taler_mhd_lib.h390
-rw-r--r--src/include/taler_pq_lib.h229
-rw-r--r--src/include/taler_templating_lib.h130
-rw-r--r--src/include/taler_testing_lib.h1484
-rw-r--r--src/include/taler_util.h342
-rw-r--r--src/json/Makefile.am18
-rw-r--r--src/json/json.c234
-rw-r--r--src/json/json_helper.c805
-rw-r--r--src/json/json_pack.c148
-rw-r--r--src/json/json_wire.c74
-rw-r--r--src/json/test_json.c3
-rw-r--r--src/json/test_json_wire.c80
-rw-r--r--src/kyclogic/Makefile.am144
-rw-r--r--src/kyclogic/kyclogic-kycaid.conf26
-rw-r--r--src/kyclogic/kyclogic-oauth2.conf35
-rw-r--r--src/kyclogic/kyclogic-persona.conf44
-rw-r--r--src/kyclogic/kyclogic.conf15
-rw-r--r--src/kyclogic/kyclogic_api.c1512
-rw-r--r--src/kyclogic/plugin_kyclogic_kycaid.c1480
-rw-r--r--src/kyclogic/plugin_kyclogic_oauth2.c1780
-rw-r--r--src/kyclogic/plugin_kyclogic_persona.c2268
-rw-r--r--src/kyclogic/plugin_kyclogic_template.c468
-rw-r--r--src/kyclogic/sample.conf33
-rwxr-xr-xsrc/kyclogic/taler-exchange-kyc-kycaid-converter.sh90
-rwxr-xr-xsrc/kyclogic/taler-exchange-kyc-oauth2-challenger.sh27
-rwxr-xr-xsrc/kyclogic/taler-exchange-kyc-oauth2-nda.sh30
-rwxr-xr-xsrc/kyclogic/taler-exchange-kyc-oauth2-test-converter.sh31
-rwxr-xr-xsrc/kyclogic/taler-exchange-kyc-persona-converter.sh57
-rw-r--r--src/kyclogic/taler-exchange-kyc-tester.c1646
-rw-r--r--src/lib/.gitignore1
-rw-r--r--src/lib/Makefile.am51
-rw-r--r--src/lib/auditor_api_curl_defaults.c14
-rw-r--r--src/lib/auditor_api_deposit_confirmation.c180
-rw-r--r--src/lib/auditor_api_exchanges.c253
-rw-r--r--src/lib/auditor_api_get_config.c278
-rw-r--r--src/lib/auditor_api_handle.c449
-rw-r--r--src/lib/auditor_api_handle.h59
-rw-r--r--src/lib/exchange_api_add_aml_decision.c246
-rw-r--r--src/lib/exchange_api_age_withdraw.c1125
-rw-r--r--src/lib/exchange_api_age_withdraw_reveal.c477
-rw-r--r--src/lib/exchange_api_auditor_add_denomination.c34
-rw-r--r--src/lib/exchange_api_batch_deposit.c467
-rw-r--r--src/lib/exchange_api_batch_withdraw.c192
-rw-r--r--src/lib/exchange_api_batch_withdraw2.c272
-rw-r--r--src/lib/exchange_api_coins_history.c1230
-rw-r--r--src/lib/exchange_api_common.c1874
-rw-r--r--src/lib/exchange_api_common.h53
-rw-r--r--src/lib/exchange_api_contracts_get.c32
-rw-r--r--src/lib/exchange_api_csr_melt.c39
-rw-r--r--src/lib/exchange_api_csr_withdraw.c41
-rw-r--r--src/lib/exchange_api_curl_defaults.c15
-rw-r--r--src/lib/exchange_api_curl_defaults.h1
-rw-r--r--src/lib/exchange_api_deposit.c557
-rw-r--r--src/lib/exchange_api_deposits_get.c170
-rw-r--r--src/lib/exchange_api_handle.c2686
-rw-r--r--src/lib/exchange_api_handle.h221
-rw-r--r--src/lib/exchange_api_kyc_check.c104
-rw-r--r--src/lib/exchange_api_kyc_proof.c46
-rw-r--r--src/lib/exchange_api_kyc_wallet.c63
-rw-r--r--src/lib/exchange_api_link.c122
-rw-r--r--src/lib/exchange_api_lookup_aml_decision.c417
-rw-r--r--src/lib/exchange_api_lookup_aml_decisions.c376
-rw-r--r--src/lib/exchange_api_management_add_partner.c218
-rw-r--r--src/lib/exchange_api_management_auditor_disable.c26
-rw-r--r--src/lib/exchange_api_management_auditor_enable.c37
-rw-r--r--src/lib/exchange_api_management_drain_profits.c213
-rw-r--r--src/lib/exchange_api_management_get_keys.c131
-rw-r--r--src/lib/exchange_api_management_post_extensions.c39
-rw-r--r--src/lib/exchange_api_management_post_keys.c26
-rw-r--r--src/lib/exchange_api_management_revoke_denomination_key.c25
-rw-r--r--src/lib/exchange_api_management_revoke_signing_key.c23
-rw-r--r--src/lib/exchange_api_management_set_global_fee.c47
-rw-r--r--src/lib/exchange_api_management_set_wire_fee.c44
-rw-r--r--src/lib/exchange_api_management_update_aml_officer.c230
-rw-r--r--src/lib/exchange_api_management_wire_disable.c44
-rw-r--r--src/lib/exchange_api_management_wire_enable.c61
-rw-r--r--src/lib/exchange_api_melt.c132
-rw-r--r--src/lib/exchange_api_purse_create_with_deposit.c166
-rw-r--r--src/lib/exchange_api_purse_create_with_merge.c78
-rw-r--r--src/lib/exchange_api_purse_delete.c243
-rw-r--r--src/lib/exchange_api_purse_deposit.c164
-rw-r--r--src/lib/exchange_api_purse_merge.c67
-rw-r--r--src/lib/exchange_api_purses_get.c76
-rw-r--r--src/lib/exchange_api_recoup.c161
-rw-r--r--src/lib/exchange_api_recoup_refresh.c160
-rw-r--r--src/lib/exchange_api_refresh_common.c66
-rw-r--r--src/lib/exchange_api_refresh_common.h7
-rw-r--r--src/lib/exchange_api_refreshes_reveal.c132
-rw-r--r--src/lib/exchange_api_refund.c435
-rw-r--r--src/lib/exchange_api_reserves_attest.c (renamed from src/lib/exchange_api_reserves_status.c)198
-rw-r--r--src/lib/exchange_api_reserves_close.c373
-rw-r--r--src/lib/exchange_api_reserves_get.c49
-rw-r--r--src/lib/exchange_api_reserves_get_attestable.c276
-rw-r--r--src/lib/exchange_api_reserves_history.c946
-rw-r--r--src/lib/exchange_api_reserves_open.c567
-rw-r--r--src/lib/exchange_api_stefan.c328
-rw-r--r--src/lib/exchange_api_transfers_get.c169
-rw-r--r--src/lib/exchange_api_wire.c489
-rw-r--r--src/lib/exchange_api_withdraw.c342
-rw-r--r--src/lib/exchange_api_withdraw2.c504
-rw-r--r--src/lib/test_stefan.c206
-rw-r--r--src/mhd/Makefile.am4
-rw-r--r--src/mhd/mhd_config.c2
-rw-r--r--src/mhd/mhd_legal.c81
-rw-r--r--src/mhd/mhd_parsing.c336
-rw-r--r--src/mhd/mhd_run.c4
-rw-r--r--src/pq/Makefile.am2
-rw-r--r--src/pq/pq_common.c68
-rw-r--r--src/pq/pq_common.h148
-rw-r--r--src/pq/pq_query_helper.c971
-rw-r--r--src/pq/pq_result_helper.c1057
-rw-r--r--src/pq/test_pq.c215
-rw-r--r--src/sq/sq_query_helper.c2
-rw-r--r--src/sq/sq_result_helper.c2
-rw-r--r--src/sq/test_sq.c8
-rw-r--r--src/templating/.gitignore3
-rw-r--r--src/templating/AUTHORS38
-rw-r--r--src/templating/CHANGELOG.md161
-rw-r--r--src/templating/LICENSE.txt14
-rw-r--r--src/templating/Makefile.am132
-rw-r--r--src/templating/ORIGIN11
-rw-r--r--src/templating/README.md320
-rwxr-xr-xsrc/templating/dotest.sh26
-rw-r--r--src/templating/meson.build12
-rw-r--r--src/templating/mustach-cjson.c258
-rw-r--r--src/templating/mustach-cjson.h96
-rw-r--r--src/templating/mustach-jansson.c271
-rw-r--r--src/templating/mustach-jansson.h96
-rw-r--r--src/templating/mustach-json-c.c284
-rw-r--r--src/templating/mustach-json-c.h160
-rw-r--r--src/templating/mustach-original-Makefile305
-rw-r--r--src/templating/mustach-tool.c258
-rw-r--r--src/templating/mustach-wrap.c482
-rw-r--r--src/templating/mustach-wrap.h235
-rw-r--r--src/templating/mustach.1.gzbin0 -> 742 bytes
-rw-r--r--src/templating/mustach.1.scd60
-rw-r--r--src/templating/mustach.c561
-rw-r--r--src/templating/mustach.h319
-rw-r--r--src/templating/pkgcfgs35
-rwxr-xr-xsrc/templating/run-original-tests.sh19
-rw-r--r--src/templating/templating_api.c524
-rw-r--r--src/templating/test-specs/test-specs-cjson.ref425
-rw-r--r--src/templating/test-specs/test-specs-jansson.ref429
-rw-r--r--src/templating/test-specs/test-specs-json-c.ref425
-rw-r--r--src/templating/test-specs/test-specs.c520
-rw-r--r--src/templating/test1/.gitignore2
-rw-r--r--src/templating/test1/Makefile8
-rw-r--r--src/templating/test1/json23
-rw-r--r--src/templating/test1/must49
-rw-r--r--src/templating/test1/resu.ref41
-rw-r--r--src/templating/test1/vg.ref14
-rw-r--r--src/templating/test2/.gitignore2
-rw-r--r--src/templating/test2/Makefile8
-rw-r--r--src/templating/test2/json9
-rw-r--r--src/templating/test2/must17
-rw-r--r--src/templating/test2/resu.ref7
-rw-r--r--src/templating/test2/vg.ref14
-rw-r--r--src/templating/test3/.gitignore2
-rw-r--r--src/templating/test3/Makefile8
-rw-r--r--src/templating/test3/json7
-rw-r--r--src/templating/test3/must15
-rw-r--r--src/templating/test3/resu.ref13
-rw-r--r--src/templating/test3/vg.ref14
-rw-r--r--src/templating/test4/.gitignore2
-rw-r--r--src/templating/test4/Makefile8
-rw-r--r--src/templating/test4/json13
-rw-r--r--src/templating/test4/must58
-rw-r--r--src/templating/test4/resu.ref50
-rw-r--r--src/templating/test4/vg.ref14
-rw-r--r--src/templating/test5/.gitignore2
-rw-r--r--src/templating/test5/Makefile8
-rw-r--r--src/templating/test5/json23
-rw-r--r--src/templating/test5/must23
-rw-r--r--src/templating/test5/must214
-rw-r--r--src/templating/test5/must2.mustache1
-rw-r--r--src/templating/test5/must3.mustache17
-rw-r--r--src/templating/test5/resu.ref38
-rw-r--r--src/templating/test5/vg.ref14
-rw-r--r--src/templating/test6/.gitignore3
-rw-r--r--src/templating/test6/Makefile12
-rw-r--r--src/templating/test6/json23
-rw-r--r--src/templating/test6/must43
-rw-r--r--src/templating/test6/resu.ref93
-rw-r--r--src/templating/test6/test-custom-write.c149
-rw-r--r--src/templating/test6/vg.ref14
-rw-r--r--src/templating/test7/Makefile8
-rw-r--r--src/templating/test7/base.mustache2
-rw-r--r--src/templating/test7/json8
-rw-r--r--src/templating/test7/node.mustache4
-rw-r--r--src/templating/test7/resu.ref7
-rw-r--r--src/templating/test7/vg.ref14
-rw-r--r--src/templating/test8/.gitignore2
-rw-r--r--src/templating/test8/Makefile8
-rw-r--r--src/templating/test8/json8
-rw-r--r--src/templating/test8/must6
-rw-r--r--src/templating/test8/resu.ref6
-rw-r--r--src/templating/test8/vg.ref14
-rw-r--r--src/templating/test_mustach_jansson.c125
-rw-r--r--src/testing/.gitignore14
-rw-r--r--src/testing/Makefile.am176
-rw-r--r--src/testing/coins-cs.conf118
-rw-r--r--src/testing/coins-rsa.conf128
-rwxr-xr-xsrc/testing/taler-unified-setup.sh934
-rw-r--r--src/testing/test-taler-exchange-aggregator-postgres.conf47
-rw-r--r--src/testing/test-taler-exchange-wirewatch-postgres.conf49
-rw-r--r--src/testing/test_auditor_api-cs.conf140
-rw-r--r--src/testing/test_auditor_api-rsa.conf146
-rw-r--r--src/testing/test_auditor_api.c236
-rw-r--r--src/testing/test_auditor_api_version.c45
-rw-r--r--src/testing/test_bank_api.c248
-rw-r--r--src/testing/test_bank_api.conf23
-rw-r--r--src/testing/test_bank_api_fakebank.conf22
-rw-r--r--src/testing/test_bank_api_fakebank_twisted.conf24
-rw-r--r--src/testing/test_bank_api_nexus.conf38
-rw-r--r--src/testing/test_bank_api_twisted.c220
-rw-r--r--src/testing/test_exchange_api-cs.conf209
-rw-r--r--src/testing/test_exchange_api-rsa.conf220
-rw-r--r--src/testing/test_exchange_api-twisted.conf29
-rw-r--r--src/testing/test_exchange_api.c364
-rw-r--r--src/testing/test_exchange_api.conf118
-rw-r--r--src/testing/test_exchange_api_age_restriction-cs.conf4
-rw-r--r--src/testing/test_exchange_api_age_restriction-rsa.conf4
-rw-r--r--src/testing/test_exchange_api_age_restriction.c370
-rw-r--r--src/testing/test_exchange_api_age_restriction.conf119
-rw-r--r--src/testing/test_exchange_api_conflicts-cs.conf4
-rw-r--r--src/testing/test_exchange_api_conflicts-rsa.conf4
-rw-r--r--src/testing/test_exchange_api_conflicts.c312
-rw-r--r--src/testing/test_exchange_api_conflicts.conf81
-rw-r--r--src/testing/test_exchange_api_home/.config/taler/account-2.json4
-rw-r--r--src/testing/test_exchange_api_home/.local/share/taler/auditor/offline-keys/auditor.privbin0 -> 32 bytes
-rw-r--r--src/testing/test_exchange_api_home/.local/share/taler/exchange-offline/master.privbin32 -> 32 bytes
-rw-r--r--src/testing/test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv1
-rw-r--r--src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv1
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking-cs.conf82
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking-rsa.conf82
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking.c117
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking.conf58
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking_home/.config/taler/x-taler-bank.json4
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange-offline/master.priv1
-rw-r--r--src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange/offline-keys/master.priv1
-rw-r--r--src/testing/test_exchange_api_overlapping_keys_bug.c100
-rw-r--r--src/testing/test_exchange_api_revocation.c119
-rw-r--r--src/testing/test_exchange_api_twisted-cs.conf150
-rw-r--r--src/testing/test_exchange_api_twisted-rsa.conf156
-rw-r--r--src/testing/test_exchange_api_twisted.c266
-rw-r--r--src/testing/test_exchange_management_api.c116
-rw-r--r--src/testing/test_exchange_p2p.c311
-rw-r--r--src/testing/test_kyc_api.c507
-rw-r--r--src/testing/test_kyc_api.conf250
-rw-r--r--src/testing/test_taler_exchange_aggregator.c258
-rw-r--r--src/testing/test_taler_exchange_httpd_home/.config/taler/account-1.json4
-rw-r--r--src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange-offline/master.priv1
-rw-r--r--src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv1
-rw-r--r--src/testing/test_taler_exchange_wirewatch.c135
-rw-r--r--src/testing/testing_api_cmd_age_withdraw.c756
-rw-r--r--src/testing/testing_api_cmd_auditor_add.c81
-rw-r--r--src/testing/testing_api_cmd_auditor_add_denom_sig.c81
-rw-r--r--src/testing/testing_api_cmd_auditor_del.c69
-rw-r--r--src/testing/testing_api_cmd_auditor_deposit_confirmation.c151
-rw-r--r--src/testing/testing_api_cmd_auditor_exchanges.c380
-rw-r--r--src/testing/testing_api_cmd_bank_admin_add_incoming.c101
-rw-r--r--src/testing/testing_api_cmd_bank_admin_check.c29
-rw-r--r--src/testing/testing_api_cmd_bank_check.c59
-rw-r--r--src/testing/testing_api_cmd_bank_check_empty.c26
-rw-r--r--src/testing/testing_api_cmd_bank_history_credit.c533
-rw-r--r--src/testing/testing_api_cmd_bank_history_debit.c530
-rw-r--r--src/testing/testing_api_cmd_bank_transfer.c55
-rw-r--r--src/testing/testing_api_cmd_batch.c49
-rw-r--r--src/testing/testing_api_cmd_batch_deposit.c134
-rw-r--r--src/testing/testing_api_cmd_batch_withdraw.c218
-rw-r--r--src/testing/testing_api_cmd_change_auth.c153
-rw-r--r--src/testing/testing_api_cmd_check_aml_decision.c270
-rw-r--r--src/testing/testing_api_cmd_check_aml_decisions.c204
-rw-r--r--src/testing/testing_api_cmd_check_keys.c251
-rw-r--r--src/testing/testing_api_cmd_coin_history.c609
-rw-r--r--src/testing/testing_api_cmd_common.c111
-rw-r--r--src/testing/testing_api_cmd_contract_get.c40
-rw-r--r--src/testing/testing_api_cmd_deposit.c268
-rw-r--r--src/testing/testing_api_cmd_deposits_get.c74
-rw-r--r--src/testing/testing_api_cmd_exec_aggregator.c1
-rw-r--r--src/testing/testing_api_cmd_exec_closer.c11
-rw-r--r--src/testing/testing_api_cmd_exec_transfer.c1
-rw-r--r--src/testing/testing_api_cmd_exec_wget.c158
-rw-r--r--src/testing/testing_api_cmd_exec_wirewatch.c29
-rw-r--r--src/testing/testing_api_cmd_get_auditor.c286
-rw-r--r--src/testing/testing_api_cmd_get_exchange.c411
-rw-r--r--src/testing/testing_api_cmd_insert_deposit.c144
-rw-r--r--src/testing/testing_api_cmd_kyc_check_get.c68
-rw-r--r--src/testing/testing_api_cmd_kyc_proof.c93
-rw-r--r--src/testing/testing_api_cmd_kyc_wallet_get.c82
-rw-r--r--src/testing/testing_api_cmd_oauth.c45
-rw-r--r--src/testing/testing_api_cmd_offline_sign_global_fees.c22
-rw-r--r--src/testing/testing_api_cmd_offline_sign_wire_fees.c10
-rw-r--r--src/testing/testing_api_cmd_purse_create_deposit.c107
-rw-r--r--src/testing/testing_api_cmd_purse_delete.c189
-rw-r--r--src/testing/testing_api_cmd_purse_deposit.c118
-rw-r--r--src/testing/testing_api_cmd_purse_get.c34
-rw-r--r--src/testing/testing_api_cmd_purse_merge.c68
-rw-r--r--src/testing/testing_api_cmd_recoup.c79
-rw-r--r--src/testing/testing_api_cmd_recoup_refresh.c146
-rw-r--r--src/testing/testing_api_cmd_refresh.c361
-rw-r--r--src/testing/testing_api_cmd_refund.c164
-rw-r--r--src/testing/testing_api_cmd_reserve_attest.c263
-rw-r--r--src/testing/testing_api_cmd_reserve_close.c260
-rw-r--r--src/testing/testing_api_cmd_reserve_get.c32
-rw-r--r--src/testing/testing_api_cmd_reserve_get_attestable.c242
-rw-r--r--src/testing/testing_api_cmd_reserve_history.c356
-rw-r--r--src/testing/testing_api_cmd_reserve_open.c349
-rw-r--r--src/testing/testing_api_cmd_reserve_purse.c77
-rw-r--r--src/testing/testing_api_cmd_reserve_status.c369
-rw-r--r--src/testing/testing_api_cmd_revoke.c2
-rw-r--r--src/testing/testing_api_cmd_revoke_denom_key.c54
-rw-r--r--src/testing/testing_api_cmd_revoke_sign_key.c56
-rw-r--r--src/testing/testing_api_cmd_rewind.c197
-rw-r--r--src/testing/testing_api_cmd_run_fakebank.c214
-rw-r--r--src/testing/testing_api_cmd_serialize_keys.c275
-rw-r--r--src/testing/testing_api_cmd_set_officer.c301
-rw-r--r--src/testing/testing_api_cmd_set_wire_fee.c70
-rw-r--r--src/testing/testing_api_cmd_stat.c64
-rw-r--r--src/testing/testing_api_cmd_system_start.c395
-rw-r--r--src/testing/testing_api_cmd_take_aml_decision.c321
-rw-r--r--src/testing/testing_api_cmd_transfer_get.c264
-rw-r--r--src/testing/testing_api_cmd_twister_exec_client.c2
-rw-r--r--src/testing/testing_api_cmd_wire.c117
-rw-r--r--src/testing/testing_api_cmd_wire_add.c81
-rw-r--r--src/testing/testing_api_cmd_wire_del.c63
-rw-r--r--src/testing/testing_api_cmd_withdraw.c178
-rw-r--r--src/testing/testing_api_helpers_auditor.c231
-rw-r--r--src/testing/testing_api_helpers_bank.c687
-rw-r--r--src/testing/testing_api_helpers_exchange.c983
-rw-r--r--src/testing/testing_api_loop.c884
-rw-r--r--src/testing/testing_api_misc.c394
-rw-r--r--src/testing/testing_api_traits.c57
-rw-r--r--src/testing/testing_api_twister_helpers.c16
-rw-r--r--src/testing/valgrind.h7165
-rw-r--r--src/util/.gitignore1
-rw-r--r--src/util/Makefile.am20
-rw-r--r--src/util/age_restriction.c531
-rw-r--r--src/util/aml_signatures.c201
-rw-r--r--src/util/amount.c69
-rw-r--r--src/util/bench_age_restriction.c208
-rw-r--r--src/util/config.c346
-rw-r--r--src/util/conversion.c405
-rw-r--r--src/util/crypto.c137
-rw-r--r--src/util/crypto_confirmation.c293
-rw-r--r--src/util/crypto_contract.c239
-rw-r--r--src/util/crypto_helper_cs.c645
-rw-r--r--src/util/crypto_helper_esign.c21
-rw-r--r--src/util/crypto_helper_rsa.c313
-rw-r--r--src/util/currencies.conf89
-rw-r--r--src/util/denom.c667
-rwxr-xr-xsrc/util/do_bench_age_restriction8
-rw-r--r--src/util/exchange_signatures.c394
-rw-r--r--src/util/iban.c6
-rw-r--r--src/util/merchant_signatures.c4
-rw-r--r--src/util/offline_signatures.c302
-rw-r--r--src/util/paths.conf6
-rw-r--r--src/util/payto.c442
-rw-r--r--src/util/taler-config.in4
-rw-r--r--src/util/taler-exchange-secmod-cs.c1097
-rw-r--r--src/util/taler-exchange-secmod-cs.conf8
-rw-r--r--src/util/taler-exchange-secmod-cs.h87
-rw-r--r--src/util/taler-exchange-secmod-eddsa.c69
-rw-r--r--src/util/taler-exchange-secmod-eddsa.conf8
-rw-r--r--src/util/taler-exchange-secmod-rsa.c160
-rw-r--r--src/util/taler-exchange-secmod-rsa.conf13
-rw-r--r--src/util/taler-exchange-secmod-rsa.h6
-rw-r--r--src/util/test_age_restriction.c230
-rw-r--r--src/util/test_amount.c17
-rw-r--r--src/util/test_conversion.c149
-rwxr-xr-xsrc/util/test_conversion.sh5
-rw-r--r--src/util/test_crypto.c186
-rw-r--r--src/util/test_helper_cs.c436
-rw-r--r--src/util/test_helper_eddsa.c2
-rw-r--r--src/util/test_helper_rsa.c327
-rw-r--r--src/util/test_payto.c64
-rw-r--r--src/util/tv_age_restriction.c8
-rw-r--r--src/util/url.c85
-rw-r--r--src/util/util.c260
-rw-r--r--src/util/wallet_signatures.c700
1445 files changed, 173406 insertions, 108396 deletions
diff --git a/.gitignore b/.gitignore
index c19d3c4da..bda987c5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,6 +35,7 @@ GPATH
GRTAGS
GTAGS
*.swp
+.DS_Store
src/include/taler_error_codes.h
src/testing/test_exchange_api_rsa
src/testing/test_exchange_api_cs
@@ -162,3 +163,13 @@ po/taler-exchange.pot
po/remove-potcdate.sed
src/include/taler_dbevents.h
src/bank-lib/taler-exchange-wire-gateway-client
+src/exchange/taler-exchange-drain
+src/kyclogic/taler-exchange-kyc-tester
+src/auditor/exchange-httpd-drain.err
+src/templating/libmustach.a
+contrib/tos/conf.py
+contrib/pp/conf.py
+src/auditordb/test_auditordb_checkpoints-postgres
+src/auditordb/test_auditordb_checkpoints_postgres
+/.cache
+/compile_commands.json
diff --git a/.gitmodules b/.gitmodules
index 416977559..01c07d992 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,10 +1,11 @@
-[submodule "doc/api"]
- path = doc/api
- url = git@git.taler.net:api
[submodule "doc/prebuilt"]
path = doc/prebuilt
url = https://git.taler.net/docs.git
branch = prebuilt
[submodule "contrib/gana"]
path = contrib/gana
- url = https://git.gnunet.org/git/gana.git
+ url = https://git.gnunet.org/gana.git
+[submodule "contrib/wallet-core"]
+ path = contrib/wallet-core
+ url = https://git.taler.net/wallet-core.git
+ branch = prebuilt
diff --git a/AUTHORS b/AUTHORS
index d85fa5cad..425379868 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -2,4 +2,5 @@ Sree Harsha Totakura <sreeharsha@totakura.in>
Florian Dold <dold@taler.net>
Marcello Stanisci <stanisci@taler.net>
Christian Grothoff <grothoff@taler.net>
+Özgür Kesim <oec-taler@kesim.org>
Benedikt Mueller
diff --git a/ChangeLog b/ChangeLog
index 690686a02..f2232f498 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Fri Apr 12 10:43:41 AM CEST 2024
+ Releasing GNU Taler Exchange 0.10.2. -CG
+
+Wed Nov 29 09:06:49 AM JST 2023
+ Creating bugfix release for taler-exchange 0.9.3a. -CG
+
+Sat Nov 5 11:32:45 AM CET 2022
+ Added support for P2P payments.
+ Added support for explicit reserve lifetime control.
+ Added support for age restrictions.
+ Releasing GNU Taler Exchange 0.9.0. -CG
+
Fri 03 Sep 2021 07:02:05 PM CEST
Add experimental aggregator sharding logic. -CG
diff --git a/README b/README
index 1a8ad5c25..7b092e0f1 100644
--- a/README
+++ b/README
@@ -13,15 +13,14 @@ spend their digital coins. Naturally, each Merchant is different, but
Taler includes code examples to help Merchants integrate Taler as a
payment system.
-Taler is currently developed by a worldwide group of independent free
-software developers and the DECENTRALISE team at Inria Rennes. Taler
-is free software and a GNU package (https://www.gnu.org/).
+Taler is currently developed by a worldwide group of independent free software
+developers and Taler Systems SA. Taler is free software and an official GNU
+package (https://www.gnu.org/).
-This is an alpha release with a few known bugs, lacking a few
-important features, documentation, testing, performance tuning and an
-external security audit. However, you can run the code and it largely
-works fine. that does not work yet. This package also only includes
-the Taler exchange, not the other components of the system.
+This is an alpha release with a few known bugs, lacking a few important
+features, documentation, testing, performance tuning and an external security
+audit. However, you can run the code and it largely works fine. This package
+also only includes the Taler exchange, not the other components of the system.
Documentation about Taler can be found at https://taler.net/.
Our bug tracker is at https://bugs.taler.net/.
@@ -43,9 +42,9 @@ Dependencies:
These are the direct dependencies for running a Taler exchange:
-- GNUnet >= 0.16.0
+- GNUnet >= 0.21.1
- GNU libmicrohttpd >= 0.9.71
-- PostgreSQL >= 13.0
+- PostgreSQL >= 15.0
@@ -63,7 +62,7 @@ src/pq/
-- Postgres-specific utility functions
src/exchangedb/
- -- Exchange database backend (with DB-specific plugins)
+ -- Exchange database backend (with database-specific plugins)
src/exchange/
-- taler exchange server
@@ -71,71 +70,50 @@ src/exchange/
src/exchange-tools/
-- taler exchange helper programs
-src/exchange-lib/
+src/lib/
-- libtalerexchange: C API to issue HTTP requests to exchange
src/auditor/
-- tools to generate reports about financial performance and
to validate that the exchange has been operating correctly
+src/auditordb/
+ -- database logic for the auditor component (with database-specific
+ plugins)
+
src/benchmark/
-- tool to run performance measurements
+src/templating/
+ -- logic to generate HTML pages from templates at runtime
+src/kyclogic/
+ -- core logic and plugins to trigger and manage KYC processes
+ as required by banking regulation
-Getting Started
-===============
-
-The following steps illustrate how to set up a exchange HTTP server.
-They take as a stub for configuring the exchange the content of 'contrib/exchange-template/config/'.
-
-1) Create a 'test/' directory and copy the stubs in it:
-
-mkdir -p test/config/
-cp exchange/contrib/exchange-template/config/* test/config/
-cd test/
-
-2) Create the exchange's master with the tool 'gnunet-ecc':
+src/bank-lib/
+ -- bank REST client logic and implementation of an in-memory
+ RTGS emulator ("fakebank") for testing.
-gnunet-ecc -g1 master.priv
+src/extensions/
+ -- extensions to the core logic of an exchange
-3) Edit config/exchange-common.conf by replacing the right value on the line with the
-MASTER_PUBLIC_KEY entry with the fresh generated (ASCII version of) master.priv.
-This ASCII version is obtained by issuing:
+src/json/
+ -- helper functions for generating and parsing JSON
-gnunet-ecc -p master.priv
+src/mhd/
+ -- helper functions for interacting with GNU libmicrohttpd
-4) Generate other exchange related keys ('denomination' and 'signing' keys), by issuing:
+src/curl/
+ -- helper functions for interacting with libcurl
-taler-exchange-keyup -m master.priv -o auditor.in
-5) A exchange needs a database to operate, so the following instructions relate to
-how to set up PostgreSQL. On debian, the two packages needed are:
-
-* postgresql
-* postgresql-client
-
-For other operating systems, please refer to the relevant documentation.
-
-In this settlement, the exchange will use a database called 'talercheck' and will
-run under the username through which 'taler-exchange-httpd' is launched. Thus assuming
-that this user is 'demo', we need to create a 'demo' role for postgresql and make
-him the owner of 'talercheck' database.
-
-To perform these administrative tasks we have to impersonate the 'postgres' (by default,
-postgres installation assigns privileges to such a user) user, then connect to the running DBMS.
-Issue the following:
-
-su # give your root password
-su - postgres
-psql # this is the command-line client to the DMBS
-# the following lines are SQL
-CREATE USER demo;
-CREATE DATABASE talercheck OWNER demo;
-# quit with CTRL-D
+Getting Started
+===============
-7) If any previous step has been successful, it is now possbile to start up the
-exchange web server (by default it will listen on port 4241); issue:
+Please follow the exchange manual you can view after
+installing using
+$ info taler-exchange
-taler-exchange-httpd -d `pwd` # assuming we did not move outside of the 'test' directory
+or by visiting https://docs.taler.net/.
diff --git a/bootstrap b/bootstrap
index 65b71c7d8..a2d0c3b5d 100755
--- a/bootstrap
+++ b/bootstrap
@@ -1,4 +1,5 @@
#!/bin/sh
+# This file is in the public domain.
set -eu
@@ -7,11 +8,17 @@ if ! git --version >/dev/null; then
exit 1
fi
+if ! pandoc --version >/dev/null; then
+ echo "pandoc not installed"
+ exit 1
+fi
+
echo "$0: Updating submodules"
-echo | git submodule update --init
+echo | git submodule update --init --force --remote
-./contrib/gana.sh
+# Generate based on pinned submodule
+./contrib/gana-generate.sh
# This is more portable than `which' but comes with
# the caveat of not(?) properly working on busybox's ash:
@@ -31,4 +38,17 @@ else
echo "Uncrustify not detected, hook not installed. Please install uncrustify if you plan on doing development"
fi
+
+# Generate Makefile.am in contrib/
+cd contrib
+rm -f Makefile.am
+find wallet-core/aml-backoffice/ -type f -printf ' %p \\\n' | sort > Makefile.am.ext
+# Remove extra '\' at the end of the file
+truncate -s -2 Makefile.am.ext
+cat Makefile.am.in Makefile.am.ext >> Makefile.am
+# Prevent accidental editing of the generated Makefile.am
+chmod -w Makefile.am
+cd ..
+
+echo "$0: Running autoreconf"
autoreconf -fi
diff --git a/configure.ac b/configure.ac
index f91973fe3..3f8238b42 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
#
# This file is part of TALER
-# Copyright (C) 2014-2021 Taler Systems SA
+# Copyright (C) 2014-2024 Taler Systems SA
#
# TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
@@ -17,7 +17,7 @@
#
#
AC_PREREQ([2.69])
-AC_INIT([taler-exchange],[0.8.5],[taler-bug@gnunet.org])
+AC_INIT([taler-exchange],[0.10.2],[taler-bug@gnunet.org])
AC_CONFIG_AUX_DIR([build-aux])
AC_CONFIG_SRCDIR([src/util/util.c])
AC_CONFIG_HEADERS([taler_config.h])
@@ -63,6 +63,13 @@ AS_IF([test "x$doc_only" != xyes],[
# Force some CFLAGS
CFLAGS="-Wall -Wno-address-of-packed-member $CFLAGS"
+TALER_LIB_LDFLAGS="-export-dynamic -no-undefined"
+TALER_PLUGIN_LDFLAGS="-export-dynamic -avoid-version -module -no-undefined"
+
+AC_SUBST(TALER_LIB_LDFLAGS)
+AC_SUBST(TALER_PLUGIN_LDFLAGS)
+
+
# Checks for header files.
AC_CHECK_HEADERS([stdint.h stdlib.h string.h unistd.h sys/socket.h sys/un.h netinet/in.h netinet/ip.h])
@@ -76,6 +83,7 @@ AC_DEFINE_UNQUOTED([NEED_LIBGCRYPT_VERSION], ["$need_libgcrypt_version"],
AM_PATH_LIBGCRYPT([$need_libgcrypt_version])
+
# should expensive tests be run?
AC_MSG_CHECKING(whether to run expensive tests)
AC_ARG_ENABLE([expensivetests],
@@ -120,6 +128,42 @@ fd = epoll_create1(EPOLL_CLOEXEC);]])],
AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 function.])]))
+# check for libmicrohttpd
+AC_MSG_CHECKING([for microhttpd])
+AC_ARG_WITH([microhttpd],
+ [AS_HELP_STRING([--with-microhttpd=PFX], [base of microhttpd installation])],
+ [AC_MSG_RESULT([given as $with_microhttpd])],
+ [AC_MSG_RESULT([not given])
+ with_microhttpd=yes])
+AS_CASE([$with_microhttpd],
+ [yes], [],
+ [no], [AC_MSG_ERROR([--with-microhttpd is required])],
+ [LDFLAGS="-L$with_microhttpd/lib $LDFLAGS"
+ CPPFLAGS="-I$with_microhttpd/include $CPPFLAGS"])
+MHD_VERSION_AT_LEAST([0.9.71])
+
+# check for libjansson (Jansson JSON library)
+jansson=0
+AC_MSG_CHECKING([for jansson])
+AC_ARG_WITH([jansson],
+ [AS_HELP_STRING([--with-jansson=PFX], [base of jansson installation])],
+ [AC_MSG_RESULT([given as $with_jansson])],
+ [AC_MSG_RESULT([not given])
+ with_jansson=yes])
+AS_CASE([$with_jansson],
+ [yes], [],
+ [no], [AC_MSG_ERROR([--with-jansson is required])],
+ [LDFLAGS="-L$with_jansson/lib $LDFLAGS"
+ CPPFLAGS="-I$with_jansson/include $CPPFLAGS"])
+AC_CHECK_LIB(jansson,json_dumpb,
+ [AC_CHECK_HEADER([jansson.h],[jansson=1])])
+AS_IF([test $jansson = 0],
+ [AC_MSG_ERROR([[
+***
+*** You need libjansson >= 2.10 to build this program.
+*** ]])])
+
+
# Check for GNUnet's libgnunetutil.
libgnunetutil=0
AC_MSG_CHECKING([for libgnunetutil])
@@ -133,20 +177,12 @@ AS_CASE([$with_gnunet],
[no], [AC_MSG_ERROR([--with-gnunet is required])],
[LDFLAGS="-L$with_gnunet/lib $LDFLAGS"
CPPFLAGS="-I$with_gnunet/include $CPPFLAGS"])
-AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_util_lib.h],
- [AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run], libgnunetutil=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif
- #include <gnunet/gnunet_common.h>
- #if GNUNET_UTIL_VERSION < 0x00A0104
- #fail libgnunetutil is too old
- #endif])
+AC_CHECK_HEADERS([gnunet/gnunet_util_lib.h],
+ [AC_CHECK_LIB([gnunetutil], [GNUNET_SCHEDULER_run], libgnunetutil=1)])
AS_IF([test $libgnunetutil != 1],
[AC_MSG_ERROR([[
***
-*** You need libgnunetutil > 0.14.0 to build this program.
-*** (Yes, ">", libgnunetutil 0.14.0 is NOT enough.)
+*** You need libgnunetutil >= 0.21.1 to build this program.
*** This library is part of GNUnet, available at
*** https://gnunet.org
*** ]])])
@@ -165,11 +201,8 @@ AS_CASE([$with_gnunet],
[no], [AC_MSG_ERROR([--with-gnunet is required])],
[LDFLAGS="-L$with_gnunet/lib $LDFLAGS"
CPPFLAGS="-I$with_gnunet/include $CPPFLAGS"])
-AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_json_lib.h],
- [AC_CHECK_LIB([gnunetjson], [GNUNET_JSON_parse], libgnunetjson=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif])
+AC_CHECK_HEADERS([gnunet/gnunet_json_lib.h],
+ [AC_CHECK_LIB([gnunetjson], [GNUNET_JSON_parse], libgnunetjson=1)])
AS_IF([test $libgnunetjson != 1],
[AC_MSG_ERROR([[
***
@@ -183,14 +216,12 @@ AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION([0.19.8])
-# Save before checking libgnurl/libcurl
+# Save before checking libcurl
CFLAGS_SAVE=$CFLAGS
LDFLAGS_SAVE=$LDFLAGS
LIBS_SAVE=$LIBS
-# check for libgnurl
-# libgnurl
-LIBGNURL_CHECK_CONFIG(,7.34.0,gnurl=1,gnurl=0)
+# check for libcurl
LIBCURL_CHECK_CONFIG(,7.34.0,[curl=1],[curl=0])
# cURL must support CURLINFO_TLS_SESSION, version >= 7.34
@@ -201,22 +232,14 @@ AS_IF([test "x$curl" = x1],[
])
-# libcurl and libgnurl should be mutually exclusive
-AS_IF([test "$gnurl" = 1],
- [AM_CONDITIONAL(HAVE_LIBGNURL, true)
- AC_DEFINE([HAVE_LIBGNURL],[1],[Have libgnurl])
- AM_CONDITIONAL(HAVE_LIBCURL, false)
- AC_DEFINE([HAVE_LIBCURL],[0],[Lacking libcurl])
- [LIBGNURLCURL_LIBS="-lgnurl"]],
- [AS_IF([test "$curl" = 1],
- [AM_CONDITIONAL(HAVE_LIBGNURL, false)
- AC_DEFINE([HAVE_LIBGNURL],[0],[Lacking libgnurl])
- AM_CONDITIONAL(HAVE_LIBCURL, true)
- AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl])
- [LIBGNURLCURL_LIBS="-lcurl"]],
- [AC_MSG_ERROR([FATAL: No libgnurl/libcurl])])])
+# libcurl should be mutually exclusive
+AS_IF([test "$curl" = 1],
+ AM_CONDITIONAL(HAVE_LIBCURL, true)
+ AC_DEFINE([HAVE_LIBCURL],[1],[Have libcurl])
+ [LIBCURL_LIBS="-lcurl"],
+ [AC_MSG_ERROR([FATAL: No libcurl])])
-AC_SUBST([LIBGNURLCURL_LIBS])
+AC_SUBST([LIBCURL_LIBS])
# Check for GNUnet's libgnunetcurl.
libgnunetcurl=0
@@ -231,25 +254,37 @@ AS_CASE([$with_gnunet],
[no], [AC_MSG_ERROR([--with-gnunet is required])],
[LDFLAGS="-L$with_gnunet/lib $LDFLAGS"
CPPFLAGS="-I$with_gnunet/include $CPPFLAGS"])
-AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_curl_lib.h],
- [AC_CHECK_LIB([gnunetcurl], [GNUNET_CURL_get_select_info], libgnunetcurl=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif])
+AC_CHECK_HEADERS([gnunet/gnunet_curl_lib.h],
+ [AC_CHECK_LIB([gnunetcurl], [GNUNET_CURL_get_select_info], libgnunetcurl=1)])
AS_IF([test $libgnunetcurl != 1],
[AC_MSG_ERROR([[
***
*** You need libgnunetcurl to build this program.
-*** Make sure you have libcurl or libgnurl installed while
+*** Make sure you have libcurl installed while
*** building GNUnet.
*** ]])])
-# Restore after gnurl/curl checks messed up these values
+# Restore after curl checks messed up these values
CFLAGS=$CFLAGS_SAVE
LDFLAGS=$LDFLAGS_SAVE
LIBS=$LIBS_SAVE
+# test for postgres
+AX_LIB_POSTGRESQL([15.0])
+AS_IF([test "x$found_postgresql" = "xyes"],
+ [SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$POSTGRES_CPPFLAGS $CPPFLAGS"
+ AC_CHECK_HEADERS([libpq-fe.h], [postgres=1], [postgres=0])])
+AS_IF([test "x$postgres" != "x1"],
+ [AC_MSG_ERROR([[
+***
+*** You need libpq(-dev) >= 15.0 to build this program.
+*** ]])])
+AM_CONDITIONAL([HAVE_POSTGRESQL], [test "x$postgres" = "x1"])
+AC_DEFINE_UNQUOTED([HAVE_POSTGRESQL], [$postgres],
+ [Define to 1 if Postgres is available])
+
# Check for GNUnet's libgnunetpq.
libgnunetpq=0
AC_MSG_CHECKING([for libgnunetpq])
@@ -262,84 +297,29 @@ AS_CASE([$with_gnunet],
[yes], [],
[no], [AC_MSG_ERROR([--with-gnunet is required])],
[LDFLAGS="-L$with_gnunet/lib $LDFLAGS"
- CPPFLAGS="-I$with_gnunet/include $CPPFLAGS"])
-AC_CHECK_HEADERS([gnunet/platform.h gnunet/gnunet_pq_lib.h],
- [AC_CHECK_LIB([gnunetpq], [GNUNET_PQ_result_spec_string], libgnunetpq=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif])
+ CPPFLAGS="-I$with_gnunet/include ${CPPFLAGS}"])
+CPPFLAGS="${CPPFLAGS} ${POSTGRESQL_CPPFLAGS}"
+AC_CHECK_HEADERS([gnunet/gnunet_pq_lib.h],
+ [AC_CHECK_LIB([gnunetpq], [GNUNET_PQ_query_param_int64], libgnunetpq=1)])
AS_IF([test $libgnunetpq != 1],
[AC_MSG_ERROR([[
***
-*** You need libgnunetpq to build this program.
+*** You need libgnunetpq version >= 6:0:1 to build this program.
*** Make sure you have Postgres installed while
-*** building GNUnet (and that your GNUnet version
-*** is recent!)
+*** building GNUnet (and that your GNUnet version is recent!)
*** ]])])
+CFLAGS_SAVE=$CFLAGS
+LDFLAGS_SAVE=$LDFLAGS
+LIBS_SAVE="$LIBS"
# Check for GNUnet's libgnunetsq
libgnunetsq=0
AC_MSG_CHECKING([for libgnunetsq])
AC_CHECK_HEADERS([gnunet/gnunet_sq_lib.h],
- [AC_CHECK_LIB([gnunetsq], [GNUNET_SQ_result_spec_string], libgnunetsq=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif])
+ [AC_CHECK_LIB([gnunetsq], [GNUNET_SQ_result_spec_string], libgnunetsq=1)])
-# check for libmicrohttpd
-AC_MSG_CHECKING([for microhttpd])
-AC_ARG_WITH([microhttpd],
- [AS_HELP_STRING([--with-microhttpd=PFX], [base of microhttpd installation])],
- [AC_MSG_RESULT([given as $with_microhttpd])],
- [AC_MSG_RESULT([not given])
- with_microhttpd=yes])
-AS_CASE([$with_microhttpd],
- [yes], [],
- [no], [AC_MSG_ERROR([--with-microhttpd is required])],
- [LDFLAGS="-L$with_microhttpd/lib $LDFLAGS"
- CPPFLAGS="-I$with_microhttpd/include $CPPFLAGS"])
-MHD_VERSION_AT_LEAST([0.9.71])
-
-# check for libjansson (Jansson JSON library)
-jansson=0
-AC_MSG_CHECKING([for jansson])
-AC_ARG_WITH([jansson],
- [AS_HELP_STRING([--with-jansson=PFX], [base of jansson installation])],
- [AC_MSG_RESULT([given as $with_jansson])],
- [AC_MSG_RESULT([not given])
- with_jansson=yes])
-AS_CASE([$with_jansson],
- [yes], [],
- [no], [AC_MSG_ERROR([--with-jansson is required])],
- [LDFLAGS="-L$with_jansson/lib $LDFLAGS"
- CPPFLAGS="-I$with_jansson/include $CPPFLAGS"])
-AC_CHECK_LIB(jansson,json_dumpb,
- [AC_CHECK_HEADER([jansson.h],[jansson=1])])
-AS_IF([test $jansson = 0],
- [AC_MSG_ERROR([[
-***
-*** You need libjansson >= 2.10 to build this program.
-*** ]])])
-
-
-# test for postgres
-AX_LIB_POSTGRESQL([13.0])
-AS_IF([test "x$found_postgresql" = "xyes"],[postgres=true])
-
-TALER_LIB_LDFLAGS="-export-dynamic -no-undefined"
-TALER_PLUGIN_LDFLAGS="-export-dynamic -avoid-version -module -no-undefined"
-
-AC_SUBST(TALER_LIB_LDFLAGS)
-AC_SUBST(TALER_PLUGIN_LDFLAGS)
-
-CFLAGS_SAVE=$CFLAGS
-LDFLAGS_SAVE=$LDFLAGS
-LIBS_SAVE="$LIBS"
-
-
-AM_CONDITIONAL(HAVE_POSTGRESQL, test x$postgres = xtrue)
CFLAGS=$CFLAGS_SAVE
LDFLAGS=$LDFLAGS_SAVE
@@ -389,10 +369,7 @@ AS_CASE([$with_twister],
CPPFLAGS="-I$with_twister/include $CPPFLAGS"])
AC_CHECK_HEADERS([taler/taler_twister_service.h],
- [AC_CHECK_LIB([talertwister], [TALER_TWISTER_connect], talertwister=1)],
- [], [#ifdef HAVE_GNUNET_PLATFORM_H
- #include <gnunet/platform.h>
- #endif])
+ [AC_CHECK_LIB([talertwister], [TALER_TWISTER_connect], talertwister=1)])
AM_CONDITIONAL(HAVE_TWISTER, test x$talertwister = x1)
# should developer logic be compiled (not-for-production code)?
@@ -409,6 +386,11 @@ AS_IF([test "x$enableval" = "xno"], [enable_dev=0])
AC_CHECK_DECL([MHD_OPTION_NOTIFY_CONNECTION],,[enable_dev=0],[[#include <microhttpd.h>]])
AC_DEFINE_UNQUOTED([HAVE_DEVELOPER],[$enable_dev],[1 if developer logic is enabled, 0 otherwise])
+AC_PATH_PROG([JQ], [jq], [no])
+if test "$JQ" = "no"; then
+ AC_MSG_ERROR([jq is required but not found. Please install jq.])
+fi
+
# Adam shostack suggests the following for Windows:
@@ -462,7 +444,7 @@ AC_MSG_CHECKING(for source being under a VCS)
git_version=
AS_IF([test ! "X$gitcommand" = "X"],
[
- git_version=$(cd $srcdir ; git rev-list --full-history --all --abbrev-commit | head -n 1 2>/dev/null)
+ git_version=$(cd $srcdir ; git rev-list -n 1 --abbrev-commit HEAD 2>/dev/null)
])
AS_IF([test "X$git_version" = "X"],
[
@@ -509,7 +491,6 @@ AM_CONDITIONAL([MHD_HAVE_EPOLL], [false])
AM_CONDITIONAL([HAVE_POSTGRESQL], [false])
AM_CONDITIONAL([HAVE_SQLITE], [false])
AM_CONDITIONAL([HAVE_LIBCURL], [false])
-AM_CONDITIONAL([HAVE_LIBGNURL], [false])
AM_CONDITIONAL([HAVE_DEVELOPER], [false])
AM_CONDITIONAL([USE_COVERAGE], [false])
AM_CONDITIONAL([ENABLE_DOC], [true])
@@ -532,7 +513,9 @@ AC_CONFIG_FILES([Makefile
src/exchangedb/Makefile
src/exchange-tools/Makefile
src/extensions/Makefile
+ src/extensions/age_restriction/Makefile
src/lib/Makefile
+ src/kyclogic/Makefile
src/testing/Makefile
src/benchmark/Makefile
src/include/Makefile
@@ -540,6 +523,7 @@ AC_CONFIG_FILES([Makefile
src/mhd/Makefile
src/pq/Makefile
src/sq/Makefile
+ src/templating/Makefile
src/util/Makefile
])
AC_OUTPUT
diff --git a/contrib/.gitignore b/contrib/.gitignore
new file mode 100644
index 000000000..1e74d37e2
--- /dev/null
+++ b/contrib/.gitignore
@@ -0,0 +1,3 @@
+locale/**/*.pot
+Makefile.am
+Makefile.am.ext
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
deleted file mode 100644
index 0d42e1df8..000000000
--- a/contrib/Makefile.am
+++ /dev/null
@@ -1,70 +0,0 @@
-SUBDIRS = .
-
-# English (en)
-tosendir=$(datadir)/taler/exchange/tos/en
-
-# English (en)
-ppendir=$(datadir)/taler/exchange/pp/en
-
-rdatadir=$(datadir)/taler/exchange
-
-tosen_DATA = \
- tos/en/0.txt \
- tos/en/0.pdf \
- tos/en/0.epub \
- tos/en/0.xml \
- tos/en/0.html
-
-ppen_DATA = \
- pp/en/0.txt \
- pp/en/0.pdf \
- pp/en/0.epub \
- pp/en/0.xml \
- pp/en/0.html
-
-rdata_DATA = \
- auditor-report.tex.j2
-
-bin_SCRIPTS = \
- taler-bank-manage-testing \
- taler-nexus-prepare
-
-EXTRA_DIST = \
- $(bin_SCRIPTS) \
- $(tosen_DATA) \
- $(ppen_DATA) \
- update-tos.sh \
- update-pp.sh \
- gana-update.sh \
- gana/gnu-taler-error-codes/registry.rec \
- gana/gnu-taler-error-codes/Makefile \
- tos/Makefile \
- tos/README \
- tos/tos.rst \
- tos/conf.py \
- tos/locale/de/LC_MESSAGES/tos.po \
- pp/Makefile \
- pp/README \
- pp/pp.rst \
- pp/conf.py \
- pp/locale/de/LC_MESSAGES/pp.po \
- $(rdata_DATA) \
- coverage.sh \
- gnunet.tag \
- microhttpd.tag
-
-# Change the set of supported languages here. You should
-# also update tos'XX'data and EXTRA_DIST accordingly.
-TOS_LANGUAGES="en de"
-PP_LANGUAGES="en de"
-
-# Change the terms-of-service version (Etag) to generate here!
-# This value should be incremented whenever there is a substantive
-# change in the original text (but not for the translations).
-TOS_VERSION=0
-PP_VERSION=0
-
-update-tos:
- VERSION=$(TOS_VERSION) ./update-tos.sh $(TOS_LANGUAGES)
-update-pp:
- VERSION=$(PP_VERSION) ./update-pp.sh $(PP_LANGUAGES)
diff --git a/contrib/Makefile.am.in b/contrib/Makefile.am.in
new file mode 100644
index 000000000..e278fad2f
--- /dev/null
+++ b/contrib/Makefile.am.in
@@ -0,0 +1,68 @@
+# This file is in the public domain.
+
+SUBDIRS = .
+
+tmplpkgdatadir = $(datadir)/taler/exchange/templates/
+dist_tmplpkgdata_DATA = \
+ kycaid-invalid-request.en.must \
+ kyc-proof-already-done.en.must \
+ kyc-proof-bad-request.en.must \
+ kyc-proof-endpoint-unknown.en.must \
+ kyc-proof-internal-error.en.must \
+ kyc-proof-target-unknown.en.must \
+ oauth2-authentication-failure.en.must \
+ oauth2-authorization-failure.en.must \
+ oauth2-authorization-failure-malformed.en.must \
+ oauth2-bad-request.en.must \
+ oauth2-conversion-failure.en.must \
+ oauth2-provider-failure.en.must \
+ persona-exchange-unauthorized.en.must \
+ persona-load-failure.en.must \
+ persona-exchange-unpaid.en.must \
+ persona-logic-failure.en.must \
+ persona-invalid-response.en.must \
+ persona-network-timeout.en.must \
+ persona-kyc-failed.en.must \
+ persona-provider-failure.en.must
+
+termsdir=$(datadir)/taler/terms/
+terms_DATA = \
+ exchange-tos-v0.rst \
+ exchange-tos-bfh-v0.rst \
+ exchange-pp-v0.rst
+
+install-exec-local:
+ find locale/ -name "*.po"
+ mkdir -p $(DESTDIR)$(datadir)
+ cp --parents -r $$(find locale/ -name "*.po") $(DESTDIR)$(datadir)
+
+rdatadir=$(datadir)/taler/exchange
+rdata_DATA = \
+ auditor-report.tex.j2
+
+bin_SCRIPTS = \
+ taler-auditor-dbconfig \
+ taler-exchange-dbconfig \
+ taler-terms-generator
+
+
+EXTRA_DIST = \
+ locale/de/LC_MESSAGES/exchange-tos-v0.po \
+ $(bin_SCRIPTS) \
+ gana-generate.sh \
+ gana/gnu-taler-error-codes/registry.rec \
+ gana/gnu-taler-error-codes/Makefile \
+ $(terms_DATA) \
+ $(rdata_DATA) \
+ coverage.sh \
+ gnunet.tag \
+ microhttpd.tag \
+ packages
+
+spapkgdatadir = $(prefix)/share/taler/exchange/spa/
+
+# This is for the single-page-app imported from the wallet-core.git
+# prebuilt branch. This MUST be the last line in the
+# Makefile.am.in, as it will be combined with the
+# actual SPA data by 'bootstrap'!
+dist_spapkgdata_DATA = \
diff --git a/contrib/auditor-report.tex.j2 b/contrib/auditor-report.tex.j2
index 38f44d4e9..bb645520f 100644
--- a/contrib/auditor-report.tex.j2
+++ b/contrib/auditor-report.tex.j2
@@ -1,5 +1,5 @@
% This file is part of TALER
-% Copyright (C) 2016--2019 Taler Systems SA
+% Copyright (C) 2016--2023 Taler Systems SA
%
% TALER is free software; you can redistribute it and/or modify it under the
% terms of the GNU Affero General Public License as published by the Free Software
@@ -88,12 +88,18 @@ In that time, the auditors processed the following table ranges:
& {{ reserves.end_ppr_reserve_in_serial_id }} \\ \hline
Reserves Out (withdraw) & {{ reserves.start_ppr_reserve_out_serial_id }}
& {{ reserves.end_ppr_reserve_out_serial_id }} \\ \hline
- Reserves Recoup & {{ reserves.start_ppr_reserve_recoup_serial_id }}
+ Reserves Recoup & {{ reserves.start_ppr_reserve_recoup_serial_id }}
& {{ reserves.end_ppr_reserve_recoup_serial_id }} \\ \hline
Reserves Close & {{ reserves.start_ppr_reserve_close_serial_id }}
& {{ reserves.end_ppr_reserve_close_serial_id }} \\ \hline
Aggregation & {{ aggregation.start_ppa_wire_out_serial_id }}
& {{ aggregation.end_ppa_wire_out_serial_id }} \\ \hline
+ Aggregation (wire) & {{ wire.start_pp_last_aggregation_serial_id }}
+ & {{ wire.end_pp_last_aggregation_serial_id }} \\ \hline
+ Deposits (wire) & {{ wire.start_pp_last_batch_deposit_id }}
+ & {{ wire.end_pp_last_batch_deposit_id }} \\ \hline
+ Reserves Close (wire) & {{ wire.start_pp_reserve_close_id }}
+ & {{ wire.end_pp_reserve_close_id }} \\ \hline
Coin withdraw & {{ coins.start_ppc_withdraw_serial_id }}
& {{ coins.end_ppc_withdraw_serial_id }} \\ \hline
Coin deposit & {{ coins.start_ppc_deposit_serial_id }}
@@ -102,9 +108,9 @@ In that time, the auditors processed the following table ranges:
& {{ coins.end_ppc_melt_serial_id }} \\ \hline
Coin refund & {{ coins.start_ppc_refund_serial_id }}
& {{ coins.end_ppc_refund_serial_id }} \\ \hline
- Coin recoup & {{ coins.start_ppc_recoup_serial_id }}
+ Coin recoup & {{ coins.start_ppc_recoup_serial_id }}
& {{ coins.end_ppc_recoup_serial_id }} \\ \hline
- Coin recoup refresh & {{ coins.start_ppc_recoup_refresh_serial_id }}
+ Coin recoup refresh & {{ coins.start_ppc_recoup_refresh_serial_id }}
& {{ coins.end_ppc_recoup_refresh_serial_id }} \\
\end{tabular}
\end{center}
@@ -139,6 +145,10 @@ In that time, the wire auditor processed the following table ranges:
{% endif %}
\end{center}
+The total credits to the exchange processed in
+this audit run was {\bf {{ wire.total_wire_in }}}.
+The total debits initiated by the exchange processed in
+this audit run was {\bf {{ wire.total_wire_out }}}.
\section{Operations}
@@ -147,6 +157,16 @@ be {\bf {{ coins.total_escrow_balance }}} (coins)
plus {\bf {{ reserves.total_escrow_balance }}} (reserves).
\noindent
+This should match the final balance computed from
+ingoing and outgoing wire transfers, which is
+{\bf {{ wire.final_balance}} }.
+
+\noindent
+A total of {\bf {{ wire.total_drained}} } in profits
+were transferred (over the lifetime of the exchange)
+to non-escrowed accounts.
+
+\noindent
The active operational risk stands at
{\bf {{ coins.total_active_risk }}}.
@@ -155,9 +175,8 @@ Loss (actualized risk from recoups) is
{\bf {{ coins.total_recoup_loss }}}.
\noindent
-Recoups of non-revoked coins are at
-{\bf {{ coins.total_irregular_recoups }}} (coins)
-plus {\bf {{ reserves.total_irregular_recoups }}} (reserves).
+Losses from irregular reserve operations are at
+{\bf {{ reserves.total_irregular_loss }}} (reserves).
\section{Income}
@@ -193,51 +212,101 @@ load. Small amounts of lag can occur in normal operation.
The total amount the exchange currently lags behind in deposits is
{\bf {{ wire.total_amount_lag }}}.
-Note that some lag is perfectly normal, as tiny amounts that are too small to be wired
-are deferred beyond the due date, hoping that additional transfers will push them above
-the tiny threshold. Below, we report {\em non-tiny} wire transfers that are lagging behind.
+Note that some lag is perfectly normal, as tiny amounts that are too small to
+be wired are deferred beyond the due date, hoping that additional transfers
+will push them above the tiny threshold. Below, we report {\em non-tiny} wire
+transfers that are lagging behind.
% Table generation tested by testcase #1 in test-auditor.sh
{% if wire.lag_details|length() == 0 %}
{\bf No non-tiny wire transfers that are lagging behind detected.}
{% else %}
- \begin{longtable}{l|r|r|c}
- {\bf Deadline} & {\bf Amount} & {\bf Row} & {\bf Claimed done} \\
- \multicolumn{4}{l}{\bf Coin} \\
- \multicolumn{4}{l}{\bf Target account} \\ \hline \hline
+ \begin{longtable}{l|r|r}
+ {\bf Deadline} & {\bf Amount} & {\bf Target account} \\ \hline \hline
\endfirsthead
- {\bf Deadline} & {\bf Amount} & {\bf Row} & {\bf Claimed done} \\
- \multicolumn{4}{l}{\bf Coin} \\
- \multicolumn{4}{l}{\bf Target account} \\ \hline \hline
+ {\bf Deadline} & {\bf Amount} & {\bf Target account} \\ \hline \hline
\endhead
\hline \hline
- {\bf Deadline} & {\bf Amount} & {\bf Row} & {\bf Claimed done} \\
- \multicolumn{4}{l}{\bf Coin} \\
- \multicolumn{4}{l}{\bf Target account} \\
+ {\bf Deadline} & {\bf Amount} & {\bf Target account} \\
\endfoot
\hline \hline
- {\bf Deadline} & {\bf Amount} & {\bf Row} & {\bf Claimed done} \\
- \multicolumn{4}{l}{\bf Coin} \\
- \multicolumn{4}{l}{\bf Target account} \\
+ {\bf Deadline} & {\bf Amount} & {\bf Target account} \\
\caption{Lagging non-tiny transactions.}
\label{table:lag}
\endlastfoot
{% for item in wire.lag_details %}
{{ item.deadline }} &
+ {{ item.total_amount }} &
+ {\tt
+ {% if 'account' in item %}
+ {{ item.account }}
+ {% endif %}
+ } \\ \hline
+{% endfor %}
+ \end{longtable}
+{% endif %}
+
+
+
+{% if wire.lag_kyc_details|length() == 0 %}
+ {\bf No KYC-blocked non-tiny wire transfers that are lagging behind detected.}
+{% else %}
+ \begin{longtable}{l|r|c|r}
+ {\bf Deadline} & {\bf Amount} & {\bf Requirement} & {\bf Target account} \\ \hline \hline
+\endfirsthead
+ {\bf Deadline} & {\bf Amount} & {\bf Requirement} & {\bf Target account} \\ \hline \hline
+\endhead
+ \hline \hline
+ {\bf Deadline} & {\bf Amount} & {\bf Requirement} & {\bf Target account} \\
+\endfoot
+ \hline \hline
+ {\bf Deadline} & {\bf Amount} & {\bf Requirement} & {\bf Target account} \\
+ \caption{Lagging non-tiny transactions due to missing KYC data.}
+ \label{table:lag}
+\endlastfoot
+{% for item in wire.lag_kyc_details %}
+ {{ item.deadline }} &
{{ item.amount }} &
- {{ item.row }} &
-{% if 'claimed_done' in item %}
- {{ item.claimed_done }}
+ {{ item.kyc_pending }} &
+ {\tt
+ {% if 'account' in item %}
+ {{ item.account }}
+ {% endif %}
+ } \\ \hline
+{% endfor %}
+ \end{longtable}
+{% endif %}
+
+
+{% if wire.lag_aml_details|length() == 0 %}
+ {\bf No non-tiny wire transfers that are lagging behind due to AML detected.}
{% else %}
- N/A
-{% endif %} \\
-\nopagebreak
- \multicolumn{4}{l}{ {\tt \small {{ item.coin_pub }} } } \\
+ \begin{longtable}{l|r|r}
+ {\bf Deadline} & {\bf Amount}/{\bf Limit} & {\bf AML status} \\
+ \multicolumn{3}{l}{\bf Target account} \\ \hline \hline
+\endfirsthead
+ {\bf Deadline} & {\bf Amount}/{\bf Limit} & {\bf AML status} \\
+ \multicolumn{4}{l}{\bf Target account} \\ \hline \hline
+\endhead
+ \hline \hline
+ {\bf Deadline} & {\bf Amount}/{\bf Limit} & {\bf AML status} \\
+ \multicolumn{4}{l}{\bf Target account} \\
+\endfoot
+ \hline \hline
+ {\bf Deadline} & {\bf Amount}/{\bf Limit} & {\bf AML status} \\
+ \multicolumn{4}{l}{\bf Target account} \\
+ \caption{Lagging non-tiny transactions due to AML decisions.}
+ \label{table:lag}
+\endlastfoot
+{% for item in wire.lag_aml_details %}
+ {{ item.deadline }} &
+ {{ item.amount }}/{{ item.aml_limit }} &
+ {{ item.aml_status }} &
\nopagebreak
\multicolumn{4}{l}{ {\tt
- {% if 'payto_uri' in item.account %}
- {{ item.account.payto_uri }}
+ {% if 'account' in item %}
+ {{ item.account }}
{% endif %}
} } \\ \hline
{% endfor %}
@@ -304,8 +373,8 @@ confirmations to the auditor directly, so if the exchange is slow at
synchronizing its database with the auditor, some deposit
confirmations may be known at the auditor only directly. However, any
delta not accounted for by database synchronization delays is an
-indicator of a malicious exchange (or online singing key compromise)
-and should be answered by revoking the exchange's online siging keys.
+indicator of a malicious exchange (or online signing key compromise)
+and should be answered by revoking the exchange's online signing keys.
% TODO: maybe reference PhD thesis on this?
The total amount the exchange currently lags behind is
@@ -599,7 +668,7 @@ compromise resulting in proportional financial losses to the exchange.
\endfoot
\hline
{\bf Total loss} &
- {{ reserves.total_loss_balance_insufficient }} \\
+ {{ reserves.total_irregular_loss }} \\
\caption{Reserves with withdrawals higher than reserve funding.}
\label{table:reserve:balance_insufficient}
\endlastfoot
@@ -768,7 +837,7 @@ invalid and the amount involved should be considered lost.
\endfoot
\hline
\multicolumn{2}{l}{ {\bf Total losses} } &
- {\bf {{ coins.total_bad_sig_loss}} } \\
+ {\bf {{ coins.irregular_loss}} } \\
\caption{Losses from operations performed on coins without proper signatures.}
\label{table:bad_signature_losses}
\endlastfoot
@@ -887,7 +956,7 @@ actually received in some reserves.
{% endif %}
-\subsection{Missattributed incoming wire transfers}
+\subsection{Misattributed incoming wire transfers}
This section lists cases where the sender account record of an
incoming wire transfer differs between the exchange and the bank.
@@ -897,7 +966,7 @@ account.
% Table generation tested by testcase #9 in test-auditor.sh
-{% if wire.missattribution_in_inconsistencies|length() == 0 %}
+{% if wire.misattribution_in_inconsistencies|length() == 0 %}
{\bf All incoming wire transfer sender accounts matched up.}
{% else %}
\begin{longtable}{p{8.5cm}|r}
@@ -912,11 +981,11 @@ account.
\endfoot
\hline
{\bf Total amount} &
- {{ wire.total_missattribution_in}} \\
+ {{ wire.total_misattribution_in}} \\
\caption{Incoming wire transfer sender accounts not matching up.}
\label{table:wire_in:sender_account_inconsistencies}
\endlastfoot
-{% for item in wire.missattribution_in_inconsistencies %}
+{% for item in wire.misattribution_in_inconsistencies %}
{\tt \small \truncate{8.3cm}{ {{ item.reserve_pub }} } } &
{{ item.amount }} \\ \hline
{% endfor %}
@@ -928,7 +997,7 @@ account.
\subsection{Actual outgoing wire transfers} \label{sec:wire_check_out}
-This section highlights cases where the exchange missbehaved
+This section highlights cases where the exchange misbehaved
with respect to outgoing wire transfers.
% Table generation tested by testcase #11 in test-auditor.sh
@@ -974,10 +1043,10 @@ with respect to outgoing wire transfers.
\subsection{Denominations without auditor signature}
This section highlights denomination keys that lack a proper
-signature from the {\t taler-auditor-offline} tool. This may be
+signature from the {\tt taler-auditor-offline} tool. This may be
legitimate, say in case where the auditor's involvement in the
exchange business is ending and a new auditor is responsible for
-future denomnations. So this must be read with a keen eye on the
+future denominations. So this must be read with a keen eye on the
business situation.
@@ -1093,7 +1162,7 @@ have a clear financial impact.
{{ item.row }} &
{{ item.diagnostic }} \\
\nopagebreak
- \multicolumn{3}{l}{ {\tiny {\tt \truncate{\textwidth}{ {{ item.wire_offset_hash }} } } } } \\ \hline
+ \multicolumn{3}{l}{ {\tiny {\tt \truncate{\textwidth}{ {{ item.id }} } } } } \\ \hline
{% endfor %}
\end{longtable}
{% endif %}
diff --git a/contrib/ci/Containerfile b/contrib/ci/Containerfile
new file mode 100644
index 000000000..ac31c7ade
--- /dev/null
+++ b/contrib/ci/Containerfile
@@ -0,0 +1,68 @@
+FROM docker.io/library/debian:bookworm
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update -yqq && \
+ apt-get install -yqq \
+ autoconf \
+ autopoint \
+ curl \
+ bash \
+ coreutils \
+ git \
+ libcurl4-gnutls-dev \
+ libgcrypt-dev \
+ libidn11-dev \
+ libjansson-dev \
+ libmicrohttpd-dev \
+ libpq-dev \
+ libqrencode-dev \
+ libsodium-dev \
+ libtool \
+ libunistring-dev \
+ make \
+ pkg-config \
+ python3-pip \
+ python3-sphinx \
+ python3-sphinx-rtd-theme \
+ recutils \
+ texinfo \
+ zlib1g-dev \
+ # For mustach testing (optional) \
+ libjson-c-dev \
+ # Debian packaging tools \
+ po-debconf \
+ build-essential \
+ debhelper-compat \
+ devscripts \
+ git-buildpackage \
+ # Documentation dependencies \
+ doxygen \
+ graphviz \
+ pandoc \
+ # Test suite dependencies \
+ jq \
+ postgresql \
+ sudo \
+ wget
+
+# Install Taler (and friends) packages
+RUN curl -sS https://deb.taler.net/apt-nightly/taler-bookworm-ci.sources \
+ | tee /etc/apt/sources.list.d/taler-bookworm-ci.sources
+
+RUN echo '\
+Package: * \n\
+Pin: origin "deb.taler.net" \n\
+Pin-Priority: 999' > /etc/apt/preferences.d/taler
+
+RUN cat /etc/apt/preferences.d/taler && \
+ apt-get update -y && \
+ apt-get install -y \
+ libgnunet-dev \
+ libgnunet \
+ gnunet \
+ && rm -rf /var/lib/apt/lists/*
+
+WORKDIR /workdir
+
+CMD ["bash", "/workdir/ci/ci.sh"]
diff --git a/contrib/ci/ci.sh b/contrib/ci/ci.sh
new file mode 100755
index 000000000..f0be84242
--- /dev/null
+++ b/contrib/ci/ci.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+set -exvuo pipefail
+
+# Use podman, fails if it isn't found in PATH
+OCI_RUNTIME=$(which podman)
+REPO_NAME=$(basename "${PWD}")
+JOB_NAME="${1}"
+JOB_CONTAINER=$((grep CONTAINER_NAME contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "localhost/${REPO_NAME}")
+JOB_ARCH=$((grep CONTAINER_ARCH contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "${2:-amd64}")
+CONTAINER_BUILD=$((grep CONTAINER_BUILD contrib/ci/jobs/${JOB_NAME}/config.ini | cut -d' ' -f 3) || echo "True")
+
+echo "${JOB_CONTAINER}"
+
+if [ "${CONTAINER_BUILD}" = "True" ] ; then
+ "${OCI_RUNTIME}" build \
+ --arch "${JOB_ARCH}" \
+ -t "${JOB_CONTAINER}" \
+ -f contrib/ci/Containerfile .
+fi
+
+"${OCI_RUNTIME}" run \
+ --rm \
+ -ti \
+ --arch "${JOB_ARCH}" \
+ --env CI_COMMIT_REF="$(git rev-parse HEAD)" \
+ --volume "${PWD}":/workdir \
+ --workdir /workdir \
+ "${JOB_CONTAINER}" \
+ contrib/ci/jobs/"${JOB_NAME}"/job.sh
+
+top_dir=$(dirname "${BASH_SOURCE[0]}")
+
+#"${top_dir}"/build.sh
diff --git a/contrib/ci/jobs/0-codespell/config.ini b/contrib/ci/jobs/0-codespell/config.ini
new file mode 100644
index 000000000..bd7d73860
--- /dev/null
+++ b/contrib/ci/jobs/0-codespell/config.ini
@@ -0,0 +1,6 @@
+[build]
+HALT_ON_FAILURE = False
+WARN_ON_FAILURE = True
+CONTAINER_BUILD = False
+CONTAINER_NAME = nixery.dev/shell/codespell
+CONTAINER_ARCH = amd64
diff --git a/contrib/ci/jobs/0-codespell/dictionary.txt b/contrib/ci/jobs/0-codespell/dictionary.txt
new file mode 100644
index 000000000..f4ffa7945
--- /dev/null
+++ b/contrib/ci/jobs/0-codespell/dictionary.txt
@@ -0,0 +1,47 @@
+# List of "words" that codespell should ignore in our sources.
+#
+# Note: The word sensitivity depends on how the to-be-ignored word is
+# spelled in codespell_lib/data/dictionary.txt. F.e. if there is a word
+# 'foo' and you add 'Foo' _here_, codespell will continue to complain
+# about 'Foo'.
+#
+BRE
+ND
+Nd
+TE
+TEH
+UPDATEing
+WAN
+aci
+acn
+ba
+bre
+cant
+clen
+complet
+doas
+ect
+ehr
+fo
+ges
+hel
+ifset
+ist
+keypair
+nam
+nd
+onl
+openin
+ot
+ser
+sie
+som
+sover
+te
+te
+teh
+tha
+ths
+updateing
+wan
+wih
diff --git a/contrib/ci/jobs/0-codespell/job.sh b/contrib/ci/jobs/0-codespell/job.sh
new file mode 100755
index 000000000..64c0e779c
--- /dev/null
+++ b/contrib/ci/jobs/0-codespell/job.sh
@@ -0,0 +1,100 @@
+#!/bin/bash
+set -exuo pipefail
+
+job_dir=$(dirname "${BASH_SOURCE[0]}")
+
+skip=$(cat <<EOF
+ABOUT-NLS
+*/afl-tests/*
+**/auditor/*.sql
+**/templating/test-specs/*
+*.bbl
+*.bib
+*build-aux*
+*.bst
+*.cache/*
+*/cbdc-es.tex
+*/cbdc-it.tex
+*.cls
+configure*
+config.status
+*/contrib/*
+*/contrib/hellos/**
+*.dat
+*.deflate
+*.doc
+*/doc/*
+**/doc/flows/main.de.tex
+*/doc/texinfo.tex
+*.docx
+*.ecc
+*.eot
+*.epgz
+*.eps
+*.epub
+**/ExchangeSelection/example.ts
+*.fee
+*.fees
+*.file
+**/fonts/**
+*.gif
+*/.git/**
+*.gz
+*/i18n/strings.ts
+*.info
+*.jpeg
+*.jpg
+*.??.json
+*.json
+*/keys/*
+*key
+*.latexmkrc
+*libtool*
+*.log
+*/m4/*
+*.m4
+**/*.map
+*.min.js
+*.mp4
+*.odg
+*.ods
+*.odt
+*.pack.js
+*.pdf
+*.png
+*.PNG
+**/pnpm-lock.yaml
+*.po
+*.pptx
+*.priv
+**/rfc.bib
+*.rpath
+**/signing-key.asc
+*.sqlite
+*/src/anastasis-data.ts
+**/*.svg
+*.svg
+*.tag
+**/templating/mustach**
+*/templating/test?/**
+*/testcurl/test_tricky.c
+*/debian/tmp/**
+*/debian/taler-exchange/**
+*/debian/.debhelper/**
+*.tgz
+*.ttf
+*.ttf
+**/valgrind.h
+*/vpn/tests/**
+*.wav
+*.woff
+*.woff2
+*.xcf
+*.xlsx
+*.zkey
+EOF
+);
+
+echo Current directory: `pwd`
+
+codespell -I "${job_dir}"/dictionary.txt -S ${skip//$'\n'/,}
diff --git a/contrib/ci/jobs/1-build/build.sh b/contrib/ci/jobs/1-build/build.sh
new file mode 100755
index 000000000..d3fcfab85
--- /dev/null
+++ b/contrib/ci/jobs/1-build/build.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -exuo pipefail
+
+apt-get update
+apt-get upgrade -yqq
+
+./bootstrap
+./configure CFLAGS="-ggdb -O0" \
+ --enable-logging=verbose \
+ --disable-doc
+
+nump=$(grep processor /proc/cpuinfo | wc -l)
+make -j$(( $nump / 2 ))
+make
diff --git a/contrib/ci/jobs/1-build/job.sh b/contrib/ci/jobs/1-build/job.sh
new file mode 100755
index 000000000..8d79902c5
--- /dev/null
+++ b/contrib/ci/jobs/1-build/job.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+set -exuo pipefail
+
+job_dir=$(dirname "${BASH_SOURCE[0]}")
+
+"${job_dir}"/build.sh
diff --git a/contrib/ci/jobs/2-test/config.ini b/contrib/ci/jobs/2-test/config.ini
new file mode 100644
index 000000000..49cc8ea8a
--- /dev/null
+++ b/contrib/ci/jobs/2-test/config.ini
@@ -0,0 +1,6 @@
+[build]
+HALT_ON_FAILURE = False
+WARN_ON_FAILURE = True
+CONTAINER_BUILD = True
+CONTAINER_NAME = localhost/exchange
+CONTAINER_ARCH = amd64
diff --git a/contrib/ci/jobs/2-test/job.sh b/contrib/ci/jobs/2-test/job.sh
new file mode 100755
index 000000000..bfb24e335
--- /dev/null
+++ b/contrib/ci/jobs/2-test/job.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+set -exuo pipefail
+
+job_dir=$(dirname "${BASH_SOURCE[0]}")
+
+"${job_dir}"/test.sh
diff --git a/contrib/ci/jobs/2-test/test.sh b/contrib/ci/jobs/2-test/test.sh
new file mode 100755
index 000000000..a0002f226
--- /dev/null
+++ b/contrib/ci/jobs/2-test/test.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+set -evux
+
+apt-get update
+apt-get upgrade -yqq
+
+./bootstrap
+./configure CFLAGS="-ggdb -O0" \
+ --enable-logging=verbose \
+ --disable-doc
+
+nump=$(grep processor /proc/cpuinfo | wc -l)
+make clean
+make -j$(( $nump / 2 ))
+cd src/templating/
+./run-original-tests.sh
+make clean
+cd -
+make -j$(( $nump / 2 ))
+make install
+
+sudo -u postgres /usr/lib/postgresql/15/bin/postgres -D /etc/postgresql/15/main -h localhost -p 5432 &
+sleep 10
+sudo -u postgres createuser -p 5432 root
+sudo -u postgres createdb -p 5432 -O root talercheck
+
+check_command()
+{
+ # Set LD_LIBRARY_PATH so tests can find the installed libs
+ LD_LIBRARY_PATH=/usr/local/lib PGPORT=5432 make check
+}
+
+print_logs()
+{
+ set +e
+ for i in src/*/test-suite.log
+ do
+ echo "Printing ${i}"
+ cat "$i"
+ for FAILURE in $(grep '^FAIL:' ${i} | cut -d' ' -f2)
+ do
+ echo "Printing $(dirname $i)/${FAILURE}.log"
+ cat "$(dirname $i)/${FAILURE}.log"
+ done
+ done
+}
+
+if ! check_command ; then
+ print_logs
+ exit 1
+fi
diff --git a/contrib/ci/jobs/3-docs/config.ini b/contrib/ci/jobs/3-docs/config.ini
new file mode 100644
index 000000000..49cc8ea8a
--- /dev/null
+++ b/contrib/ci/jobs/3-docs/config.ini
@@ -0,0 +1,6 @@
+[build]
+HALT_ON_FAILURE = False
+WARN_ON_FAILURE = True
+CONTAINER_BUILD = True
+CONTAINER_NAME = localhost/exchange
+CONTAINER_ARCH = amd64
diff --git a/contrib/ci/jobs/3-docs/docs.sh b/contrib/ci/jobs/3-docs/docs.sh
new file mode 100755
index 000000000..fe2b96873
--- /dev/null
+++ b/contrib/ci/jobs/3-docs/docs.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+set -exuo pipefail
+
+./bootstrap
+./configure --enable-only-doc
+
+pushd ./doc/doxygen/
+
+make full
+
+popd
diff --git a/contrib/ci/jobs/3-docs/job.sh b/contrib/ci/jobs/3-docs/job.sh
new file mode 100755
index 000000000..a72bca4ba
--- /dev/null
+++ b/contrib/ci/jobs/3-docs/job.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+set -exuo pipefail
+
+job_dir=$(dirname "${BASH_SOURCE[0]}")
+
+"${job_dir}"/docs.sh
diff --git a/contrib/ci/jobs/4-deb-package/install-fix.patch b/contrib/ci/jobs/4-deb-package/install-fix.patch
new file mode 100644
index 000000000..8334c5a7a
--- /dev/null
+++ b/contrib/ci/jobs/4-deb-package/install-fix.patch
@@ -0,0 +1,13 @@
+diff --git a/debian/taler-exchange.install b/debian/taler-exchange.install
+index 631c270b..072c6231 100644
+--- a/debian/taler-exchange.install
++++ b/debian/taler-exchange.install
+@@ -36,6 +36,6 @@ usr/share/taler/exchange/templates/*.must
+ debian/etc-taler-exchange/* etc/
+
+ # Terms of service / privacy policy templates
+-usr/share/taler/exchange/*.rst
++#usr/share/taler/exchange/terms/*.rst
+ # Translations of ToS/PP
+-usr/share/taler/exchange/locale/*/LC_MESSAGES/*.po
++#usr/share/taler/exchange/terms/locale/*/LC_MESSAGES/*.po
diff --git a/contrib/ci/jobs/4-deb-package/job.sh b/contrib/ci/jobs/4-deb-package/job.sh
new file mode 100755
index 000000000..922f8bf63
--- /dev/null
+++ b/contrib/ci/jobs/4-deb-package/job.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+set -exuo pipefail
+# This file is in the public domain.
+# Helper script to build the latest DEB packages in the container.
+
+
+unset LD_LIBRARY_PATH
+
+# Install build-time dependencies.
+# Update apt cache first
+apt-get update
+apt-get upgrade -y
+mk-build-deps --install --tool='apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --yes' debian/control
+
+export VERSION="$(./contrib/ci/jobs/4-deb-package/version.sh)"
+echo "Building package version ${VERSION}"
+EMAIL=none gbp dch --dch-opt=-b --ignore-branch --debian-tag="%(version)s" --git-author --new-version="${VERSION}"
+./bootstrap
+dpkg-buildpackage -rfakeroot -b -uc -us
+
+ls -alh ../*.deb
+mkdir -p /artifacts/exchange/${CI_COMMIT_REF} # Variable comes from CI environment
+mv ../*.deb /artifacts/exchange/${CI_COMMIT_REF}/
diff --git a/contrib/ci/jobs/4-deb-package/version.sh b/contrib/ci/jobs/4-deb-package/version.sh
new file mode 100755
index 000000000..52031b23a
--- /dev/null
+++ b/contrib/ci/jobs/4-deb-package/version.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+set -ex
+
+BRANCH=$(git name-rev --name-only HEAD)
+if [ -z "${BRANCH}" ]; then
+ exit 1
+else
+ # "Unshallow" our checkout, but only our current branch, and exclude the submodules.
+ git fetch --no-recurse-submodules --tags --depth=1000 origin "${BRANCH}"
+ RECENT_VERSION_TAG=$(git describe --tags --match 'v*.*.*' --exclude '*-dev*' --always --abbrev=0 HEAD || exit 1)
+ commits="$(git rev-list ${RECENT_VERSION_TAG}..HEAD --count)"
+ if [ "${commits}" = "0" ]; then
+ git describe --tag HEAD | sed -r 's/^v//' || exit 1
+ else
+ echo $(echo ${RECENT_VERSION_TAG} | sed -r 's/^v//')-${commits}-$(git rev-parse --short=8 HEAD)
+ fi
+fi
diff --git a/contrib/ci/jobs/5-deploy-package/config.ini b/contrib/ci/jobs/5-deploy-package/config.ini
new file mode 100644
index 000000000..8d6409a6e
--- /dev/null
+++ b/contrib/ci/jobs/5-deploy-package/config.ini
@@ -0,0 +1,5 @@
+[build]
+HALT_ON_FAILURE = True
+WARN_ON_FAILURE = True
+CONTAINER_BUILD = False
+CONTAINER_NAME = nixery.dev/shell/rsync
diff --git a/contrib/ci/jobs/5-deploy-package/job.sh b/contrib/ci/jobs/5-deploy-package/job.sh
new file mode 100755
index 000000000..d39cf9987
--- /dev/null
+++ b/contrib/ci/jobs/5-deploy-package/job.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+set -exuo pipefail
+
+ARTIFACT_PATH="/artifacts/exchange/${CI_COMMIT_REF}/*.deb"
+
+RSYNC_HOST="taler.host.internal"
+RSYNC_PORT=424242
+RSYNC_PATH="incoming_packages/bookworm-taler-ci/"
+RSYNC_DEST="rsync://${RSYNC_HOST}/${RSYNC_PATH}"
+
+
+rsync -vP \
+ --port ${RSYNC_PORT} \
+ ${ARTIFACT_PATH} ${RSYNC_DEST}
diff --git a/contrib/pp/pp.rst b/contrib/exchange-pp-v0.rst
index e6d003d88..4800bd4e4 100644
--- a/contrib/pp/pp.rst
+++ b/contrib/exchange-pp-v0.rst
@@ -48,11 +48,11 @@ to our services without at least clear implied consent, and we only process
and retain information with a strict business need. That being said, when
using our Services, we inherently have to collect the following information:
- * Bank account details necessary when receiving funds from you to top-up your wallet or to transfer funds to you when you are being paid via Taler. At the current experimental stage, only the pseudonym and password you entered in the bank demonstrator is stored.
+* Bank account details necessary when receiving funds from you to top-up your wallet or to transfer funds to you when you are being paid via Taler. At the current experimental stage, only the pseudonym and password you entered in the bank demonstrator is stored.
- * The amounts being withdrawn or deposited, with associated unique transaction identifiers and cryptographic signatures authorizing the transaction. Note that for purchases, we cannot identify the buyer from the collected data, so when you spend money, we only receive non-personal information.
+* The amounts being withdrawn or deposited, with associated unique transaction identifiers and cryptographic signatures authorizing the transaction. Note that for purchases, we cannot identify the buyer from the collected data, so when you spend money, we only receive non-personal information.
- * When you contact us. We may collect certain information if you choose to contact us, for example to report a bug or other error with the Taler Wallet. This may include contact information such as your name, email address or phone number depending on the method you choose to contact us.
+* When you contact us. We may collect certain information if you choose to contact us, for example to report a bug or other error with the Taler Wallet. This may include contact information such as your name, email address or phone number depending on the method you choose to contact us.
How we collect and process information
@@ -60,9 +60,9 @@ How we collect and process information
We may process your information for the following reasons:
- * to transfer money as specified by our users (Taler transactions);
- * to assist government entities in linking income to the underlying contract as required by law and local regulations
- * to support you using the Taler Wallet or to improve our Services
+* to transfer money as specified by our users (Taler transactions);
+* to assist government entities in linking income to the underlying contract as required by law and local regulations
+* to support you using the Taler Wallet or to improve our Services
How we share and use the information we gather
diff --git a/contrib/tos/bfh.rst b/contrib/exchange-tos-bfh-v0.rst
index 85f041c33..85f041c33 100644
--- a/contrib/tos/bfh.rst
+++ b/contrib/exchange-tos-bfh-v0.rst
diff --git a/contrib/exchange-tos-netzbon-v0.rst b/contrib/exchange-tos-netzbon-v0.rst
new file mode 100644
index 000000000..ee10121b4
--- /dev/null
+++ b/contrib/exchange-tos-netzbon-v0.rst
@@ -0,0 +1,108 @@
+Allgemeine Geschäftsbedingungen für eNetzBon
+============================================
+
+Version vom 26.2.2024
+---------------------
+
+Diese Allgemeinen Geschäftsbedingungen gelten für alle Nutzer und Händler, die das Taler-Bezahlsystem für eNetzBon verwenden.
+
+1. Vertragspartner
+------------------
+
+Diese Allgemeinen Geschäftsbedingungen (AGB) regeln die Nutzung des Taler-Bezahlsystems (nachfolgend "Taler") zwischen Ihnen (nachfolgend "Nutzer") und Taler Operations AG ("wir", "uns").
+
+2. Produktbeschreibung
+----------------------
+
+* Um die angebotenen Dienste wahrnehmen zu können, müssen Nutzer ein Taler-Wallet (elektronische Geldbörse) als Taler-App auf ihrem Smartphone oder als Erweiterung in einem Browser auf dem PC installieren.
+* Es werden keine Daten von zahlenden Nutzern benötigt und es erfolgt auch keine Registrierung oder Kontenanlage der Nutzer. Sie können ihre Waren ohne Preisgabe ihrer Identität erwerben.
+* Die Nutzer zahlen entweder in bar an den Verein Soziale Ökonomie oder an seine Mitglieder (Händler, Verkäufer) oder überweisen von ihrem bestehenden Girokonto bei einer Schweizer Bank an das Bankkonto des Vereins Soziale Ökonomie in der Währung Schweizer Franken (CHF), um dann wertbasierte elektronische Münzen in ihre Taler-Wallets abzuheben. Sie beziehen damit digitale Wertmarken, die fachsprachlich auch Token oder elektronischen Münzen genannt werden.
+* Die elektronischen Münzen werden in der Denomination eNetzBon im Taler-Wallet angezeigt und stellen Repräsentanten der Geldwerte auf dem Verrechnungskonto des Vereins Soziale Ökonomie dar.
+
+3. Digitale Erweiterung des NetzBon mit eNetzBon
+------------------------------------------------
+
+Der Verein Soziale Ökonomie arbeitet an der Digitalisierung des NetzBon mit GNU Taler, einem digitalen Bezahlsystem, das komplett auf Freier Software und quelloffener Software (FLOSS, Free Libre and Open-Source Software) basiert und den Grundsätzen der Sozialen Ökonomie folgt.
+
+Die Taler Operations AG stellt dieses Bezahlsystem dem Verein Soziale Ökonomie zur Verfügung. Die Erweiterung von NetzBon mit eNetzBon soll die Effizienz und Wirtschaftlichkeit des NetzBon verbessern, ohne jedoch die physische Form des NetzBon in naher Zukunft abzuschaffen.
+
+4. Registrierung und Konten
+---------------------------
+
+Es werden keine Daten von zahlenden Nutzern benötigt und auch nicht erfasst. Es erfolgt auch keine Registrierung oder Kontenanlage der Nutzer.
+
+Am eNetzBon-System teilnehmende Betriebe (Händler, Verkäufer) halten beim Verein Soziale Ökonomie interne eNetzBon-Konten, auf welche sie die ihnen übergebenen Bareinzahlungen von Nutzern (Kunden, Käufern) übertragen, damit die Nutzer dann eNetzBon in ihre persönlichen Wallets abheben können.
+
+5. Käufe und Zahlungsbedingungen
+--------------------------------
+
+* Die Nutzer können eNetzBon durch zwei Verfahren erwerben bzw. das Guthaben auf ihrem Wallet erhöhen:
+
+ * a. Per Bareinzahlung durch Nutzung der "Taler Cashier-App" in der Markthalle und in der Buchhandlung, wo ein Nutzer den abzuhebenden Betrag in CHF an das Personal bar übergeben kann und dann durch das Wallet der Betrag in CHF abgehoben und im Wallet in eNetzBon umgetauscht wird.
+ * b. Per Banküberweisung an das PostFinanz-Konto des Vereins Soziale Ökonomie. Das Wallet hilft dabei den Nutzern, den Abhebevorgang einzuleiten und gibt dazu einen Verwendungszweck an, d.h. eine mehrstellige Kombination aus Nummer und Buchstaben, die im Kontoauszug des persönlichen Girokontos des jeweiligen Nutzers als Buchungstext angezeigt wird. Mit diesem Verwendungszweck kann das Wallet den Betrag zuerst in CHF abheben und dann im Wallet in eNetzBon umtauschen.
+
+* Der Preis eines eNetzBon beträgt 1 CHF. Bitte beachten Sie, dass NetzBon nicht rückerstattbar sind, daher müssen sie ausgegeben werden.
+* In der Phase der Markteinführung von eNetzBon werden keine Transaktionskosten von Nutzern erhoben. Bei der Bezahlung mit eNetzBon fallen daher vorerst keine Transaktionsgebühren an. Diese Allgemeinen Geschäftsbedingungen erlauben jedoch die Möglichkeit zukünftiger Änderungen der Gebührenordnung.
+
+6. Nutzung der Taler-App
+------------------------
+
+Die Taler-App ermöglicht keine direkten Interaktionen, sondern dient ausschliesslich dem Bezug und der Verwendung von eNetzBon bei teilnehmenden Geschäften. Spenden sind möglich. Die Nutzer verpflichten sich, die Taler-App gemäss den geltenden Gesetzen und Vorschriften zu verwenden.
+
+Dem Nutzer ist es nur möglich, mit öffentlichen Shops zu interagieren. Mit anderen Privatpersonen kann ein Nutzer nicht interagieren.
+
+7. Verpflichtende Sicherungsmassnahmen der Nutzer
+-------------------------------------------------
+
+Die Nutzer müssen sich darüber im klaren sein, elektronisches Geld wie Bargeld zu behandeln und ebenso zu sichern, d.h. ein Backup der Wallet-Daten anzulegen.
+
+Die Nutzer der Taler-App sind daher verpflichtet, den Zugang zum digitalen Endgerät zu sichern und vor unbefugtem Zugriff zu bewahren. Sie müssen die Wallet-Daten mit einer Sicherungskopie auf einem anderen Gerät speichern. Die Exportfunktion des Wallet hilft dabei, ein Backup der Wallet-Daten anzulegen und zu speichern.
+
+Ein verlorenes Nutzergerät mit einem Wallet darauf ohne Backup der eNetzBon auf einem anderen Gerät oder Datenträger bedeutet einen Totalverlust des Gegenwerts des NetzBon-Guthabens.
+
+8. Datenschutz
+--------------
+
+Die Datenschutzrichtlinien sind in einem separaten Dokument festgelegt, das die Nutzer auch in der Taler-App finden. Der Schutz der persönlichen Daten und finanziellen Informationen hat für uns höchste Priorität.
+
+Daten der Nutzer werden nicht erhoben. Beim Bezahlen mit eNetzBon werden nur Ort, Uhrzeit und der die eNetzBon empfangende Betrieb (Händler, Verkäufer) erhoben.
+
+Die anonymisierten Daten des Kaufs und der Überweisung von NetzBon an den Betrieb werden im Falle einer Untersuchung der Finma erhoben. Dies betrifft jedoch nicht Nutzer, die mit eNetzBon zahlen, sondern die Transaktionen in NetzBon zwischen dem Verein Soziale Ökonomie und den teilnehmenden Betrieben.
+
+9. Streitbeilegung
+------------------
+
+Bei etwaigen Streitigkeiten oder Unstimmigkeiten, die aus der Nutzung von Taler, der Taler-App und eNetzBon entstehen, verpflichten sich die Parteien, zunächst eine gütliche Einigung anzustreben.
+
+Wenn keine Einigung erzielt werden kann, unterliegt die Streitbeilegung den geltenden schweizerischen Gesetzen und der Gerichtsbarkeit von Biel.
+
+10. Haftungsausschluss
+----------------------
+
+UNSER TEXTVORSCHLAG ZU DIESEM PUNKT MUSS NOCH DISKUTIERT WERDEN: Die Taler Operations AG haftet bei der Erfüllung ihrer Verpflichtungen für jedes Verschulden ihrer Mitarbeiter und der Personen, die sie zur Erfüllung ihrer Verpflichtungen hinzuzieht. Soweit die Sonderbedingungen für einzelne Geschäftsbeziehungen oder sonstige Vereinbarungen etwas Abweichendes regeln, gehen diese Regelungen vor.
+
+Hat ein Nutzer des Taler-Bezahlsystems durch schuldhaftes Verhalten - zum Beispiel durch Verletzung von Mitwirkungspflichten wie regelmässige Sicherungen und Vorsichtsmassnahmen - zur Entstehung eines Schadens beigetragen, bestimmt sich nach den Grundsätzen des Mitverschuldens, in welchem Umfang Taler Operations AG und Nutzer den Schaden zu tragen haben.
+
+11. Allgemeine Bestimmungen
+---------------------------
+
+DER TEXTVORSCHLAG VOM VEREIN SOZIALE ÖKONOMIE ZU DIESEM PUNKT MUSS NOCH DISKUTIERT WERDEN: Der Verein Soziale Ökonomie behält sich vor, bei Verletzung von Regeln oder Missbrauch, gewisse Händler-Konten zu löschen.
+
+12. Änderungen der AGB
+----------------------
+
+Die Taler Operations AG behält sich das Recht vor, diese Allgemeinen Geschäftsbedingungen (AGB) ändern zu können. Die Nutzer werden über Änderungen in der Taler-App benachrichtigt.
+
+Die fortgesetzte Nutzung der Taler-App nach Änderungen der AGB gilt als Zustimmung zu den geänderten Bedingungen.
+
+13. Datenschutzbeauftragte
+--------------------------
+
+Den Datenschutzbeauftragten des Vereins Soziale Ökonomie erreichen Sie beim Sitz des Vereins in der Klybeckstrasse 95, 4057 Basel, und per E-Mail an kontakt@sozialeoekonomie.org.
+
+Den Datenschutzbeauftragten der Taler Operations AG erreichen Sie per Post an Taler Operations AG, Höheweg 80, 2502 Biel, und über die unten genannten Kontaktmöglichkeiten.
+
+14. Kontakt
+-----------
+
+Bei Fragen oder Anliegen bezüglich dieser AGB oder der Taler-App erreichen Sie uns per Post an Taler Operations AG, Höheweg 80, 2502 Biel, und über die unten genannten Kontaktmöglichkeiten.
diff --git a/contrib/exchange-tos-tops-v0.rst b/contrib/exchange-tos-tops-v0.rst
new file mode 100644
index 000000000..2217f781c
--- /dev/null
+++ b/contrib/exchange-tos-tops-v0.rst
@@ -0,0 +1,959 @@
+Allgemeine Geschäftsbedingungen für die Nutzung von TALER
+=========================================================
+
+1. Allgemeines
+--------------
+
+1.1. Dienstleistung / Geltungsbereich
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Die Taler Operations AG (nachfolgend "**TALER AG**") ist eine Schweizer Aktiengesellschaft
+mit Sitz in Zürich.
+Die TALER bietet Privatkundinnen und -kunden (nachfolgend "**Kundin und/oder Kunde**")
+unter dem Namen "TALER” eine eigenes Bezahlungssystem an (nachfolgend "TALER”).
+Diese Allgemeinen Geschäftsbedingungen (nachfolgend "**AGB**") regeln die Benutzung von
+TALER App und die von der TALER AG über die TALER erbrachten Dienstleistungen.
+Diese AGB gelten als akzeptiert, sobald die Kundin bzw. der Kunde in der TALER App das
+Einverständnis erklärt hat.
+
+[KOMMENTAR SK]
+1. Wenn es wirklich nötig ist, für "Taler Operations AG" eine Abkürzung zu verwenden, dann
+würde "TALER AG" aus Sicht der GNU-Community den Namen von GNU Taler sehr vereinnahmen.
+Mein Vorschlag wäre noch kürzer als TALER AG und birgt keine Verwechslungsgefahr,
+Vereinnahmung oder Anmaßung: TOPS AG
+
+CG: Warum nicht einfach "TOPS" statt "TOPS AG"? AG ist auch nicht relevant.
+
+2. Bitte lasst uns Gendersprache vermeiden und statt "**Kundin und Kunde**" lieber
+"**Nutzer**" verwenden und möglichst im Plural schreiben.
+
+CG: Absolut, Gendersprache ist auslaenderfeindlich weil fuer nicht-Muttersprachler
+ deutlich schwerer. Aber besser *Kunden* statt *Nutzer* weil vmtl. Kunde ein Rechtsbegriff ist.
+
+3. **Zahlungsdienst** wäre IMHO rechtlich und sprachlich besser als "Bezahlungssystem".
+Dieser Begriff entspricht dem englischen 'payment service provider' auch nach ISO 220022.
+
+CG: OK.
+
+4. Ich würde dem Zahlungsdienst keinen "Namen" geben - vor allem nicht TALER, weil das
+sofort mit einer Währung assoziiert wird. Taler ist jedoch keine Währung, sondern ein
+Bezahlsystem, das in unserem Fall in CHF denominiertes e-Geld emittiert, genauer
+gesagt TOPS-CHF. Wenn wir dafür eine Kurzbezeichnung dafür brauchen, dann wäre
+mein Vorschlag **eCHF**.
+
+Ja, bin auch gegen die Benennung, vor allem weil es eben kein *eigenes* System ist,
+nur weil ich einen Web-Server betreibe, besitze ich ja nicht das Web ;-).
+
+5. Weitere Begriffsbestimmungen wären hier sinnvoll:
+- **Zahlungsdienst** bezeichnet die Dienstleistung der Taler Operations AG mit Sitz in
+Biel (Höheweg 80, 2502 Biel, Mitglied in der anerkannten Selbstregulierungsorganisation
+gemäss Art. 24 GwG, dem VQF - Verein zur Qualitätssicherung von Finanzdienstleistungen).
+
+CG: Nein, zu komplex. Weglassen.
+
+- **Selbstregulierung** bezeichnet die Eigenschaft der Taler Operations AG als Mitglied
+einer Selbstregulierungsorganisation wie dem VQF und Betreiberin einer
+Sandbox-Dienstleistung nach Art. 6 Abs. 2 BankV ohne gewerbsmäßige Bankeneigenschaft
+(Nichtbank).
+
+CG: Auch nicht gut. "TOPS ist Mitglied im VQF, einer FINMA-akkreditierten
+Selbstregulierungsorganisation. TOPS wird daher nicht direkt von der FINMA
+beaufsichtigt, sondern betreibt eine Finanzdienstleisung nach Art. 6 Abs. 2
+BankV ohne gewerbsmäßige Bankeneigenschaft (Nichtbank) und somit ohne
+Kundeneinlagensicherung."
+
+- **Taler-Wallet** bezeichnet eine von Taler Operations AG bereitgestellte Software, die
+digitales Bargeld (e-Geld) verwaltet, welches der Zahlungsdienst emittiert und zur
+Zahlung an Begünstigte wieder einlöst.
+- **Nutzer** bezeichnet Inhaber von Taler-Wallets und damit Zahlende bzw. potenziell
+Zahlende.
+
+CG: "Kunden sind Inhaber von durch TOPS signierten und in CHF denominierten Wertmarken
+welche in Taler-Wallets in Eigenverantwortung gespeichert werden und mit denen Kunden
+bezahlen koennen."
+
+- **Begünstigte** bezeichnet Händler, Betriebe, Verkäufer und sonstige Empfänger von
+Überweisungen des Zahlungsdiensts.
+- **Überweisungen von Nutzern** bezeichnet die Überweisungen an den hier angebotenen
+Zahlungsdienst mit dem Ziel des Abhebens von e-Geld in ein persönliches Wallet.
+
+CG: Rest weg-kuerzen:
+
+"", die als
+Publikumseinlagen bei Nichtbanken gelten. Taler Operations AG unterliegt nicht der
+Einlagensicherung und als Nichtbank auch nicht der Bankenaufsicht. Die entgegengenommen
+Gelder werden auf einem Sammelkonto aufbewahrt, um Zahlungen zwischen den Nutzern bzw.
+zwischen Zahlenden (Käufern) und Begünstigen (Verkäufern) auszuführen."" (alles streichen)
+
+- **Überweisungen an Begünstigte** bezeichnet die Überweisungen des Zahlungsdiensts an
+Händler, Betriebe, Verkäufer und sonstige Empfänger, die IBAN-Konten an Finanzinstituten in
+der Schweiz führen müssen, um die Zahlungen ihrer Kunden über den Zahlungsdienst empfangen
+zu können.
+- **Geschäftsbeziehung** bezeichnet die Beziehung zwischen Taler Operations AG und den
+Begünstigten (Händler, Betriebe, Verkäufer und sonstige Empfänger). Sollten für über 12
+Monate keine Transaktionen an die Begünstigen erfolgen, gilt die Geschäftsbeziehung als
+beendet.
+
+CG: Taler Operations AG => TOPS (ueberall!).
+
+[KOMMENTAR SK]
+
+1.2. Zugang zu den TALER Dienstleistungen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+TALER ist ein System, das bargeldlose Zahlungen über das TALER Zahlungssystem ermöglicht.
+TALER kann von Kundinnen und Kunden verwendet werden, um Zahlungen zwischen TALER Nutzern
+durchzuführen ("**P2P-Zahlung**") und als Zahlungsmittel im stationären Handel, an
+Automaten, online und in Apps bei autorisierten Händlern oder Dienstleistungsanbietern, die
+TALER als Zahlungsmittel akzeptieren (nachfolgend "**Händler**"), eingesetzt werden
+("**P2M-Zahlung**").
+
+CG: nein, nicht noch Haendler einfuehren, einfach bei **Beguenstigten** bleiben!
+
+Die TALER AG kann sodann die Verwendung der TALER App auch im Ausland bei Händlern zulassen,
+die an einem mit dem TALER Zahlungssystem kooperierenden ausländischen Zahlungssystem
+angeschlossen sind. Solche Transaktionen werden vom ausländischen Zahlungssystem an das
+TALER Zahlungssystem weitergeleitet (nachfolgend "**internationale Zahlung**").
+Darüber hinaus bietet die TALER AG verschiedene Mehrwertleistungen an, namentlich die
+Hinterlegung oder Aktivierung von Sichtkarten und Dienstleistungen im Bereich des
+Mobile-Marketing. Diese Mehrwertleistungen erlauben Kundinnen und Kunden u.a., Coupons,
+Stempelkarten und weitere Kampagnen in der TALER App zu erhalten und zu verwalten, Stempel
+zu sammeln und Treuegeschenke, Rabatte und Gutschriften über die TALER App einzulösen.
+
+CG: obiger Paragraph ist kompletter Unsinn, einfach komplett Streichen. Wir machen
+KEINE internationalen Zahlungen, und auch keine "Mehrwertleistungen". Einfach killen!
+
+[NETZBON-NEU]
+Der Verein Soziale Ökonomie arbeitet an der Digitalisierung des NetzBon mit GNU Taler,
+einem digitalen Bezahlsystem, das komplett auf Freier Software und quelloffener Software
+(FLOSS, Free Libre and Open-Source Software) basiert und den Grundsätzen der Sozialen
+Ökonomie folgt. Die Taler Operations AG stellt dieses Bezahlsystem dem Verein Soziale
+Ökonomie zur Verfügung. Die Erweiterung von NetzBon mit eNetzBon soll die Effizienz und
+Wirtschaftlichkeit des NetzBon verbessern, ohne jedoch die physische Form des NetzBon in
+naher Zukunft abzuschaffen.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Treffender als "P2M-Zahlung" wäre m.E. "C2M-Zahlung" (Customer-to-Merchant), weil die
+Zahlenden im Normalfall keine "Peers" sind, sondern einfach nur deren Kunden. P2P-Zahlungen
+liegen hingegen definitionsgemäß auch vor, wenn Zahlende von ihrem Wallet auf das Wallet
+eines Händlers Coins übertragen (Wallet-Exchange-Wallet).
+- Müssen wir "P2M" als Begriff in den AGB unbedingt verwenden? Bitte diskutieren.
+[KOMMENTAR SK]
+
+CG: Ich sehe gar nicht, das wir ueberhaupt P2P vs. P2M/C2M-Zahlungen in den AGBs unterscheiden muessen/sollten.
+
+
+1.3. Technische Voraussetzungen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+TALER kann "_____________________". Benötigt wird "__________________________".
+Die Nutzung der Zahlungsfunktion und der Mehrwertleistungen erfordert eine aktive
+Internetverbindung.
+
+[NETZBON-NEU]
+Um die angebotenen Dienste wahrnehmen zu können, müssen Nutzer ein Taler-Wallet
+(elektronische Geldbörse) als Taler-App auf ihrem Smartphone oder als Erweiterung in einem
+Browser auf dem PC installieren.
+[NETZBON-NEU]
+
+CG: Nutzer => Kunden
+
+[KOMMENTAR SK]
+- Mir ist nicht klar, was in die Leerzeilen kommen soll.
+
+CG: Ditto.
+
+- Der Satz darunter ist korrekt, aber "Mehrwertleistungen" ein TWINT-Begriff, den wir
+streichen sollten.
+
+CG: JA!
+
+- Ich empfehle, den Satz von NETZBON zu übernehmen, denn er erwähnt auch die
+Browser-Erweiterungen und spricht allumfassend von "Diensten".
+
+CG: Ja. Bitte noch hinzufuegen: "Kunden sind frei in der Wahl ihrer Taler-Wallet
+ Anwendung. Beguenstigte sind ebenfalls frei in der Wahl ihrer Taler-Wallet
+ Anwendung bzw. ihres Taler-Backends. Verschiedene Loesungen werden von
+ diversen Anbietern bereitgestellt.
+ TOPS macht hier keine Einschraenkungen, und uebernimmt keine Gewaehrleistung.
+ Kunden sind eigenverantwortlich fuer die Sicherheit ihrer Taler-Wallets bzw.
+ Taler-Backends und der darin gespeicherten Wertmarken bzw. Transaktionsdaten."
+[KOMMENTAR SK]
+
+1.4. Registrierung und Identifizierung
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Zur Nutzung von TALER sind die Kundinnen und Kunden verpflichtet, sich in bei TALER zu
+registrieren und die verlangten Informationen zur Verfügung zu stellen. Die TALER AG behält
+sich vor, zur Erfüllung regulatorischer Vorgaben jederzeit weitere Informationen zu
+verlangen. Die registrierte Telefonnummer wird aus Sicherheitsgründen per SMS verifiziert.
+Mit der Registration bestätigt die Kundin bzw. der Kunde, die rechtmässige Nutzerin bzw.
+Nutzer der Telefonnummer und des Smartphones zu sein.
+Bei einer Änderung der bei der Registrierung angegebenen Daten müssen diese unverzüglich in
+TALER aktualisiert werden.
+Die TALER AG behält sich vor, Registrierungsgesuche ohne Angabe von Gründen abzulehnen bzw.
+bereits erfolgte Registrationen wieder rückgängig zu machen.
+
+[NETZBON-NEU]
+Es werden keine Daten von zahlenden Nutzern benötigt und es erfolgt auch keine
+Registrierung oder Kontenanlage der Nutzer. Sie können ihre Waren ohne Preisgabe ihrer
+Identität erwerben.
+
+Am eNetzBon-System teilnehmende Betriebe (Händler, Verkäufer) halten beim Verein Soziale
+Ökonomie interne eNetzBon-Konten, auf welche sie die ihnen übergebenen Bareinzahlungen von
+Nutzern (Kunden, Käufern) übertragen, damit die Nutzer dann eNetzBon in ihre persönlichen
+Wallets abheben können. Sie benötigen diese internen eNetzBon-Konten ebenfalls für den
+Empfang von Zahlungen der Nutzer für Güter (Waren und Dienstleistungen) der Betriebe.
+
+Die Nutzer leisten Ihre Einzahlung an das Bezahlsystem entweder in bar an den Verein
+Soziale Ökonomie oder an seine Mitglieder (Händler, Verkäufer) oder überweisen von ihrem
+bestehenden Girokonto bei einer Schweizer Bank an das Bankkonto des Vereins Soziale Ökonomie
+in der Währung Schweizer Franken (CHF), um dann wertbasierte elektronische Münzen in ihre
+Taler-Wallets abzuheben. Sie beziehen damit digitale Wertmarken, die wie ein
+Gutschein oder Prepaid-Guthaben zu betrachten sind. Sie werden auch als Token
+oder Coins bezeichnet. Die elektronischen Münzen werden in der Komplementärwährung
+"eNetzBon" im Taler-Wallet angezeigt und stellen Repräsentanten der Geldwerte auf dem
+Verrechnungskonto des Vereins Soziale Ökonomie in "NetzBon" dar.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+Statt des ersten Absatzes von 1.4.:
+Zur Nutzung des Zahlungsdiensts bei Überweisungen an **Begünstige** von über 15.000
+CHF/Jahr sind diese verpflichtet, sich in bei Taler Operations AG zu registrieren und die
+dabei verlangten Informationen zur Verfügung zu stellen. Die Taler Operations AG behält
+sich vor, zur Erfüllung regulatorischer Vorgaben jederzeit weitere Informationen zu
+verlangen.
+
+Taler Operations AG benötigt zur Registrierung der Händler deren IBAN, Adresse und
+Telefonnummer (AMLA-Akte) oder es gelten die Empfangslimiten für Händler. Zur
+Nutzung des Zahlungsdiensts gehen die Begünstigten eine Geschäftsbeziehung mit Taler
+Operations AG ein. Ab einer bestimmten Umsatzhöhe sind sie verpflichtet, sich zu
+registrieren und die verlangten Informationen zur Verfügung zu stellen.
+
+Es erfolgt keine Registrierung oder Kontenanlage der **Nutzer** bei Taler Operations AG
+oder dem Bezahlsystem bzw. Zahlungsdienst. Es werden jedoch die IBAN-Konten erfasst, von
+denen die eingehenden Überweisungen erfolgen. Die Nutzer brauchen für das Abheben in
+Taler-Wallets eine Schweizer Telefonnummer zum Empfang von TANs, die der Zahlungsdienst
+versendet. Es gelten Höchstabhebegrenzen von 5.000 CHF pro Monat bzw. 15.000 CHF pro Jahr
+für die Nutzer. Bei Zahlungen an andere Nutzer (P2P-Zahlungen) bestehen für Nutzer mit
+Wohnsitz in der Schweiz Limiten von CHF 1.000 pro Monat und CHF 5.000 pro Kalenderjahr für
+das Senden und das Empfangen von e-Geld.
+[KOMMENTAR SK]
+
+CG: Bitte allgemeiner halten, die Grenzwerte CHF sollten gar nicht explizit in
+den AGBs auftauchen! Stattdessen: "Zur Nutzung des Zahlungsdienstes sind
+Kunden und Beguenstigte verpflichtet TOPS bei der Erfuellung regulatorischer
+Vorgaben zu unterstuetzen. Insbesondere kann TOPS Auskunft verlangen ueber die
+Identitaet von wirtschaftlich Beguenstigten. TOPS hat das Recht und die
+Pflicht ggf. Kunden und Beguenstigte von der Nutzung des Systems
+auszuschliessen sollten diese die notwendigen Auskuenfte verweigern oder
+inkorrekte Angaben machen."
+
+
+
+1.5. Geheimhaltung
+~~~~~~~~~~~~~~~~~~
+
+Der Umstand der Geschäftsbeziehung und daraus resultierende Daten (z.B. Name, Wohnort,
+Transaktionsdaten) werden grundsätzlich vertraulich behandelt. Sie können zur Erbringung von
+Dienstleistungen soweit notwendig an den Zahlungsempfänger sowie an weitere Dritte bekannt
+gegeben werden. Die Vertraulichkeit ist sodann zur Wahrung berechtigter Interessen der TALER
+AG, aber insbesondere in folgenden Fällen, aufgehoben:
+* Wahrnehmung gesetzlicher Auskunftspflichten und Erfüllung regulatorischer Vorgaben
+* Inkasso von Forderungen der TALER AG?
+* Gerichtliche Auseinandersetzungen.
+
+[NETZBON-NEU]
+Es werden keine Daten von zahlenden Nutzern benötigt und auch nicht erfasst. Es erfolgt auch
+keine Registrierung oder Kontenanlage der Nutzer.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Satz 1: Geschäftsbeziehung **mit Begünstigten**
+- Ergänzen: Satz aus NETZBON-NEU
+[KOMMENTAR SK]
+
+CG: "Personenbezogene Daten werden von TOPS nur im Rahmen der zur Erfuellung
+gesetzlicher Verpflichtungen notwendigen Umfang erhoben, verarbeitet,
+aufbewahrt oder weitergegeben. Beim Bezahlvorgang mit e-Geld werden keine
+Daten zur Identitaet vom zahlenden Nutzer erfasst."
+
+
+
+1.6. Support
+~~~~~~~~~~~~
+
+Die TALER AG stellt den Kundinnen und Kunden im Sinne eines technischen Supports über die
+TALER eine Hilfefunktion zur Verfügung. Für die Erbringung dieses Supports können von der
+TALER AG auch Dritte beigezogen werden, an welche hierfür Zugriff auf relevante Daten
+gegeben werden kann.
+
+[KOMMENTAR SK]
+Ich würde hier die Haftung für die Aktionen der Dritten einschränken. Zugriff auf relevante
+Daten hätten dritte Parteien wie z.B. Auditoren oder Behörden übrigens auch nur bei Händlern
+in Bezug auf deren Daten und Umsätze. Bitte diskutieren.
+[KOMMENTAR SK]
+
+CG: Ich wuerde nur das Deutsch korrigieren wollen:
+"TOPS stellt den Nutzern auf Anfrage technischen Support zur Verfügung. An
+der Erbringung dieses Supports können Dritte beteiligt sein. Diese erhalten
+hierfür Zugriff auf notwendige personenbezogene Daten zur Kommunikation mit
+den Nutzern."
+
+
+1.7. Sorgfalts- und andere Pflichten der Kundinnen und Kunden
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Beim Umgang mit TALER sind insbesondere folgende Sorgfaltspflichten durch die Kundinnen und
+Kunden einzuhalten:
+* Das Smartphone, PC, Notebook etc. ist vor unbefugter Benutzung oder Manipulation zu
+schützen (z.B. mittels Geräte- bzw. Displaysperre).
+* Der Code für die Nutzung von TALER ist geheim zu halten, darf keinesfalls an andere
+Personen weitergegeben, oder zusammen mit dem Smartphone aufbewahrt werden.
+* Der gewählte Code darf nicht aus leicht ermittelbaren Kombinationen (Mobile-Nummer,
+Geburtsdatum usw.) bestehen.
+* Im Schadenfall haben die Kundinnen und Kunden nach bestem Wissen zur Aufklärung des
+Falls und zur Schadensminderung beizutragen. Bei strafbaren Handlungen ist Anzeige bei der
+Polizei zu erstatten.
+* Vor jeder Ausführung einer Zahlung sind die Angaben zum Zahlungsempfänger zu
+überprüfen, um Fehltransaktionen zu verhindern.
+* Es ist dafür zu sorgen, dass der Kontakt zur TALER AG nicht abbricht. Kommt es zu
+einem Kontaktabbruch, so kann die TALER AG die ihr entstehenden Kosten für
+Adressnachforschungen, wie auch die besondere Behandlung und Überwachung von
+nachrichtenlosen Vermögenswerten, den Kundinnen und Kunden weiterbelasten. Das Vorgehen bei
+nachrichtenlosen Vermögen und die jeweils geltende Gebührentabelle lässt sich hier einsehen.
+Kontaktlose Geschäftsbeziehungen mit einem Schuldsaldo werden von der TALER AG aufgelöst.
+Die Kundinnen und Kunden sind für die Verwendung (Nutzung) ihres Smartphones verantwortlich
+und tragen sämtliche Folgen, die sich aus der Verwendung der TALER App auf dem Smartphone
+ergeben. Insbesondere werden Handlungen, die eine Drittperson unberechtigt mit der TALER App
+auf dem Smartphone einer Kundin bzw. Kunden vornimmt, der Kundin bzw. dem Kunden
+zugerechnet.
+
+[NETZBON-NEU]
+Die Nutzer müssen sich darüber im klaren sein, elektronisches Geld wie Bargeld zu
+behandeln und ebenso zu sichern, d.h. ein Backup der Wallet-Daten anzulegen. Die Nutzer der
+Taler-App sind daher verpflichtet, den Zugang zum digitalen Endgerät zu sichern und vor
+unbefugtem Zugriff zu bewahren. Sie müssen die Wallet-Daten mit einer Sicherungskopie auf
+einem anderen Gerät speichern. Die Exportfunktion des Wallet hilft dabei, ein Backup der
+Wallet-Daten anzulegen und zu speichern. Ein verlorenes Nutzergerät mit einem Wallet darauf
+ohne Backup der eNetzBon auf einem anderen Gerät oder Datenträger bedeutet einen
+Totalverlust des Gegenwerts des NetzBon-Guthabens.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Streichen: * Der Code für die Nutzung von TALER ist geheim zu halten...
+- Streichen: * Der gewählte Code darf nicht...
+CG: 2x Ja.
+
+- Streichen: * Es ist dafür zu sorgen, dass... (ist wohl ein TWINT-Rest)
+
+CG: Besser: ummuenzen auf **Beguenstigte**. D.h. wenn wir einem Haendler Geld schulden
+aber z.B. KYC brauchen, liegt es erst einmal beim Haendler dies zu merken (im Backend!)
+und uns zu kontaktieren! Wenn wir nachforschen muessen, wer hinter einer IBAN steckt
+um dann KYC zu bekommen, soll dies ruhig kosten. Der Text zu Schuldsalden muss natuerlich
+raus, Schulden gibt es ja bei uns nicht!
+
+- Stattdessen den Text aus NETZBON-NEU verwenden und ergänzen mit:
+* Es ist dafür zu sorgen, dass sich das Endgerät mit einem darauf installierten Taler-Wallet
+innerhalb eines Jahres nach der letzten Transaktion mit dem Zahlungsdienst über das Internet
+verbindet, ansonsten kann das Guthaben im Wallet verloren werden. Ein Erneuern des Guthabens
+erfolgt regulär einen Monat vor dem Ende der Gültigkeit des elektronischen Bargelds, das ein
+Jahr beträgt.
+
+CG: "das zum Abhebezeitpunkt ca. ein Jahr betraegt" (ca. ist wichtig, wir runden...!).
+[KOMMENTAR SK]
+
+1.8. Nutzung; Missbräuche
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Weicht die Nutzung von TALER erheblich vom üblichen Gebrauch ab oder bestehen Anzeichen
+eines rechts- oder vertragswidrigen Verhaltens, kann die TALER AG die Kundinnen und Kunden
+zur rechts- und vertragskonformen Benutzung anhalten, die Leistungserbringung ohne
+Vorankündigung entschädigungslos ändern, einschränken oder einstellen, den Vertrag frist-
+und entschädigungslos auflösen und gegebenenfalls Schadenersatz sowie die Freistellung von
+Ansprüchen Dritter verlangen. Dasselbe gilt im Falle von unzutreffenden oder unvollständigen
+Angaben der Kunden bei der Registrierung.
+
+[NETZBON-NEU]
+Die Taler-App ermöglicht keine direkten Interaktionen, sondern dient ausschliesslich dem
+Bezug und der Verwendung von eNetzBon bei teilnehmenden Geschäften. Spenden sind möglich.
+Die Nutzer verpflichten sich, die Taler-App gemäss den geltenden Gesetzen und Vorschriften
+zu verwenden. Dem Nutzer ist es nur möglich, mit öffentlichen Shops zu interagieren. Mit
+anderen Privatpersonen kann ein Nutzer nicht interagieren.
+
+Der Verein Soziale Ökonomie behält sich vor, bei Verletzung von Regeln oder Missbrauch
+gewisse Konten zu löschen.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Satz 1: die Kundinnen und Kunden --> die **Nutzer**
+- Satz 2: Dasselbe gilt im Falle von unzutreffenden oder unvollständigen Angaben der
+**Begünstigten (Händler, Verkäufer)** bei der Registrierung.
+
+CG: Satz 2: bei P2P brauchen wir ggf. auch angaben von Nutzern, wuerde ich bei **Nutzern** lassen.
+
+- In NETZBON-NEU streichen: Mit anderen Privatpersonen kann ein Nutzer nicht interagieren.
+
+CG: Genau, ist auch bei Netzbon *falsch*.
+
+- Ändern: Der Verein Soziale Ökonomie behält sich vor, bei Verletzung von Regeln oder
+Missbrauch Konten **(von Händlern, Betrieben, Verkäufern) zu sperren bzw.** zu löschen.
+[KOMMENTAR SK]
+
+1.9. Haftung
+~~~~~~~~~~~~
+
+Die TALER AG haftet nicht für den Kundinnen und Kunden entstandene Verluste oder Schäden
+aufgrund der Verwendung von TALER, insbesondere nicht für Verluste oder Schäden:
+* aufgrund von Übermittlungsfehlern, technischen Störungen oder Defekten, Ausfällen und
+unberechtigten Zugriffen oder Eingriffen auf das Smartphone;
+* die ganz oder teilweise auf einen Verstoss der Kundinnen und Kunden gegen diese AGB
+oder anwendbare Gesetze zurückzuführen sind;
+* aufgrund einer Störung oder Fehlers von TALER oder der verwendeten Hardware;
+* aufgrund von Störungen, Unterbrechungen (inkl. für Systemwartungsarbeiten) oder
+Überlastungen der relevanten Informatiksysteme bzw. Netze;
+* aufgrund von Zahlungen, die nicht oder verzögert verarbeitet werden;
+* in Bezug auf Mehrwertleistungen;
+
+CG: streichen? Mehrwertleistungen machen wir doch gar nicht?
+
+* die auf Handlungen oder Unterlassungen von Dritten (inkl. Hilfspersonen der TALER AG)
+zurückzuführen sind,
+es sei denn, diese Verluste oder Schäden sind auf grobe Fahrlässigkeit oder vorsätzliches
+Verschulden der TALER AG zurückzuführen. Die TALER AG ersetzt Sach- und Vermögensschäden je
+Schadenereignis bis höchstens CHF 1’000.
+Die Haftung der TALER AG für Folgeschäden, entgangenem Gewinn, Datenverluste ist – soweit
+gesetzlich zulässig – in jedem Fall ausgeschlossen.
+Die Kundin bzw. der Kunde hält die TALER AG schadlos für Schäden oder Verluste, die der
+TALER AG aufgrund der Nichteinhaltung dieser AGB oder gesetzlichen Vorgaben, aufgrund
+fehlerhafter oder unvollständiger Angaben der Kundin bzw. des Kunden oder der Ausführung von
+Anweisungen entstehen.
+
+[KOMMENTAR SK]
+- Vorschlag zur Ergänzung des obigen Absatzes:
+Die Taler Operations AG haftet bei der Erfüllung ihrer Verpflichtungen für jedes Verschulden
+ihrer Mitarbeiter und der Personen, die sie zur Erfüllung ihrer Verpflichtungen hinzuzieht.
+Soweit die Sonderbedingungen für einzelne Geschäftsbeziehungen oder sonstige Vereinbarungen
+etwas Abweichendes regeln, gehen diese Regelungen vor.
+
+Hat ein Nutzer des Taler-Bezahlsystems durch schuldhaftes Verhalten - zum Beispiel durch
+Verletzung von Mitwirkungspflichten wie regelmässige Sicherungen und Vorsichtsmassnahmen -
+zur Entstehung eines Schadens beigetragen, bestimmt sich nach den Grundsätzen des
+Mitverschuldens, in welchem Umfang Taler Operations AG und Nutzer den Schaden zu tragen
+haben.
+
+CG: Nein, weglassen. Hilft uns nicht, nur mehr Text. AGB steht eh nicht ueber Recht und Gesetz.
+
+- Streichen: * in Bezug auf Mehrwertleistungen;
+
+CG: genau.
+[KOMMENTAR SK]
+
+1.10. Kommunikation
+~~~~~~~~~~~~~~~~~~~
+
+Die Kommunikation zwischen der TALER AG und den Kundinnen und Kunden erfolgt grundsätzlich
+über die TALER. Bei Bedarf kann die TALER AG die Kundinnen und Kunden auch ausserhalb der
+TALER App kontaktieren. Eine solche Kommunikation ist nicht zwingend vertraulich oder
+sicher.
+
+[KOMMENTAR SK]
+- Satz 1: Die Kommunikation zwischen der TALER AG und den Begünstigten erfolgt grundsätzlich
+über die TALER AG.
+
+- Satz 2: Bei Bedarf kann die TALER AG die registrierten Begünstigten (Händler, Betriebe,
+Verkäufer) kontaktieren.
+- Ergänzen: Falls eine Kommunikation zwischen der TALER AG und den Nutzern notwendig werden
+sollte, kann diese über ein Finanzinstitut (Bank des überweisenden Girokontos der Nutzer)
+oder/und über die Taler-Apps erfolgen, sofern dies technisch möglich ist.
+[KOMMENTAR SK]
+
+CG: alles falsch. Die Kommunikation von TOPS zu Nutzern erfolgt grundsätzlich
+über Benachrichtigungen im GNU Taler Protokoll. Nutzer sind dafuer verantwortlich auf
+entsprechende Benachrichtigungen zu reagieren. TOPS hat das Recht, Transaktionen
+nicht auszufuehren bis Nutzer auf diesem Weg angeforderte rechtlich notwendige Daten
+bereitstellen.
+
+
+
+1.11. Änderung AGB
+~~~~~~~~~~~~~~~~~~
+
+Die TALER AG kann die AGB jederzeit ändern. Änderungen werden auf geeignete Weise bekannt
+gegeben. Ist die Kundin bzw. der Kunde mit den Änderungen nicht einverstanden, so kann die
+Kundin bzw. der Kunde die TALER App nicht mehr verwenden.
+
+[KOMMENTAR SK]
+Vorschlag statt des obigen Absatzes:
+Die Taler Operations AG behält sich das Recht vor, diese Allgemeinen Geschäftsbedingungen
+(AGB) ändern zu können. Die Nutzer werden über Änderungen in der Taler-App benachrichtigt.
+Die fortgesetzte Nutzung der Taler-App nach Änderungen der AGB gilt als Zustimmung zu den
+geänderten Bedingungen.
+
+Der Zahlungsdienst sendet automatisch Änderungen in den AGB und Datenschutzbestimmungen
+an die Taler-Wallets mit der Notwendigkeit der Bestätigung durch die Nutzer, nach der sie
+die Taler-App weiterverwenden können.
+[KOMMENTAR SK]
+
+CG: "TOPS kann die AGB jederzeit ändern. Änderungen haben nur Wirkung auf nach der
+Änderung bezogene Wertmarken. Korrekte Wallets informieren Nutzer über Änderungen
+vor dem Bezug von neuen Wertmarken. Der Bezug von Wertmarken der TOPS nach
+Änderungen der AGB gilt als Zustimmung zu den geänderten Bedingungen."
+
+weil: du kannt den Leuten nicht verbieten, eine GPL-Wallet nicht zu benutzen wenn sie
+TOPS AGBs nicht zustimmen! Das waere GPL-widrig!
+
+
+1.12. Vorbehalt gesetzlicher Regelungen und Beschränkung der Dienstleistungen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Allfällige Gesetzesbestimmungen, die den Betrieb und die Benutzung von Smartphones,
+Zahlungssystemen, des Internets und sonstiger dedizierter Infrastruktur regeln, bleiben
+vorbehalten und gelten ab ihrer Inkraftsetzung auch für die vorliegenden Dienstleistungen.
+Die Benutzung der Dienstleistungen aus dem Ausland kann lokalen rechtlichen Restriktionen
+unterliegen oder unter Umständen Regeln des ausländischen Rechts verletzen. Die
+Zahlungsfunktion ist grundsätzlich auf das Hoheitsgebiet der Schweiz beschränkt und darf im
+Ausland nicht in Anspruch genommen werden. Zulässig sind aber internationale Zahlungen über
+ein mit dem TALER Zahlungssystem kooperierendes ausländisches Zahlungssystem.
+
+CG: Letzten Satz hier streichen. Nix international.
+
+Die TALER AG behält sich vor, das Angebot von TALER jederzeit und ohne vorherige Ankündigung
+zu ändern, zu beschränken oder vollständig einzustellen, insbesondere aufgrund rechtlicher
+Anforderungen, technischen Problemen, zwecks Verhinderung von Missbräuchen, auf behördliche
+Anordnung oder aus Sicherheitsgründen.
+Die TALER AG kann nach eigenem Ermessen und ohne vorherige Ankündigung die Nutzung von TALER
+für einzelne Kundinnen und Kunden einschränken oder unterbinden, Zahlungen nicht oder nur
+verzögert verarbeiten, eingehende Zahlungen zurückweisen und das Auf- und Entladen
+beschränken, insbesondere wo dies nach Auffassung der TALER AG aus rechtlichen Gründen oder
+solchen, die die Reputation betreffen, angezeigt ist, bei IT-gestützten Angriffen, bei
+Missbrauch oder bei Betrugsverdacht. Im Verlaufe der Dauer der Geschäftsbeziehung können
+Umstände eintreten, die die TALER AG verpflichten, Vermögenswerte zu sperren, die
+Geschäftsbeziehung einer zuständigen Behörde zu melden oder abzubrechen.
+Die Kundinnen und Kunden sind verpflichtet, der TALER AG auf Verlangen Auskünfte zu
+erteilen, die die TALER AG benötigt, um den gesetzlichen oder internen Abklärungs- oder
+Meldepflichten nachzukommen.
+
+CG: scheint mir vieles vorher gesagtes zu duplizieren. Ggf. oben Text streichen?
+
+1.13. Geistiges Eigentum
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Für die Dauer des Vertrages erhalten die Kundinnen und Kunden das unübertragbare, nicht
+ausschliessliche Recht zur Nutzung von TALER. Inhalt und Umfang dieses Rechts ergeben sich
+aus den vorliegenden AGB. Alle Immaterialgüterrechte verbleiben bei der TALER AG oder den
+berechtigten Dritten.
+
+[KOMMENTAR SK]
+Satz 1: Für die Dauer der **Nutzung** erhalten die Nutzer das unübertragbare, nicht
+ausschliessliche Recht zur Verwendung des Bezahlsystems. Die Vertragspartner (Händler,
+Betriebe, Verkäufer) als Begünstigte erhalten im Fall der Nutzung der P2P- oder
+P2M-Funktion des Bezahlsystems dieses Recht wie alle anderen Nutzer eingeräumt.
+[KOMMENTAR SK]
+
+CG: Wuerde ich alles streichen. IP-Unsinn. Besser:
+
+1.13: Trademark
+~~~~~~~~~~~~~~~
+
+Beguenstigte haben das nicht ausschliessliche Recht das Taler-Logo zu
+nutzen um zu signalisieren, dass sie Zahlungen mit Taler akzeptieren.
+
+
+
+1.14 Datenschutz
+~~~~~~~~~~~~~~~~
+
+Die TALER AG verpflichtet sich hinsichtlich der Beschaffung, Bearbeitung und
+Nutzung der personenbezogenen Daten der Kundinnen und Kunden die Bestimmungen der
+schweizerischen Datenschutzgesetzgebung (insbesondere Bundesgesetz über den Datenschutz,
+DSG, und Verordnung über den Datenschutz, VDSG) einzuhalten.
+
+Alle Systemdaten werden ausschliesslich in der Schweiz gehostet.
+
+CG: ausschliesslich => primaer
+
+Der KYC Prozess wird durch
+einen Dienstleister übernommen, welcher verpflichtet wird, die Daten ebenfalls nach Recht
+und Gesetz von der Schweiz zu sichern.
+
+CG: KYC Prozesse werden ggf. durch Dienstleister gesteuert. Diese sind ebenfalls verpflichtet
+die Daten ebenfalls nach Recht und Gesetz der Schweiz zu sichern.
+
+Die eigentichen Daten des Kernsystems werden auf
+verschlüsselten Festplatten redundant (d.h. mit Backup) gespeichert und sind nur
+autorisiertem Personal zugänglich. Autorisiertes Personal wird von TALER AG einer
+Sicherheitsprüfung unterzogen. Das gesamte Design wurde strikt nach den Grundsätzen
+"Privacy-by-Design” und "Privacy-by-Default” umgesetzt.
+
+>>>
+Taler nutzt blinde Signaturen, damit
+TALER AG nicht lernen kann, welcher legitimierte Nutzer bei welchem Verkäufer einkauft.
+Weitere nicht-blinde digitale Signaturen werden eingesetzt, um alle Transaktionsschritte
+gegenseitig zu bestätigen und auch extern z.B. gegenüber Auditoren überprüfbar zu machen.
+Gleichzeitig werden Hashfunktionen eingesetzt, um Details, die dritte Parteien nicht lernen
+sollen, auch nicht zu exponieren. Von den Käufern werden nur so viele Daten verwendet, wie
+zum Abheben in eine virtuelle Geldbörse (Wallet) notwendig sind. Die dabei bezogenen
+Bankkonten haben bereits bankenseitig eine KYC-Prüfung der Käufer durchgeführt und kennen
+deren Namen und Adressen in Verbindung mit der Bankkontennummer (IBAN). Von den Verkäufern
+sind ebenfalls IBAN-Kontennummern bekannt. Diese können bei Bedarf zuständigen Behörden und
+Auditoren offengelegt werden
+<<<
+CG: obigen >>>Paragraph<<< bitte komplett streichen. Nicht falsch, aber viel zu viele Details.
+
+Weitere Informationen zu den Datenbearbeitungen finden sich in der Datenschutzerklärung auf
+der Webseite der TALER AG (www.TALER.ch).
+
+[NETZBON-NEU]
+Die Datenschutzrichtlinien sind in einem separaten Dokument festgelegt, das die Nutzer auch
+in der Taler-App finden. Der Schutz der persönlichen Daten und finanziellen Informationen
+hat für uns höchste Priorität. Daten der Nutzer werden nicht erhoben. Beim Bezahlen mit
+eNetzBon werden nur Ort, Uhrzeit und der die eNetzBon empfangende Betrieb (Händler,
+Verkäufer) erhoben. Die anonymisierten Daten des Kaufs und der Überweisung von NetzBon an
+den Betrieb werden im Falle einer Untersuchung der Finma erhoben. Dies betrifft jedoch nicht
+Nutzer, die mit eNetzBon zahlen, sondern die Transaktionen in NetzBon zwischen dem Verein
+Soziale Ökonomie und den teilnehmenden Betrieben.
+
+Den Datenschutzbeauftragten des Vereins Soziale Ökonomie erreichen Sie beim Sitz des Vereins
+in der Klybeckstrasse 95, 4057 Basel, und per E-Mail an kontakt@sozialeoekonomie.org.
+
+Den Datenschutzbeauftragten der Taler Operations AG erreichen Sie per Post an Taler
+Operations AG, Höheweg 80, 2502 Biel, und über die unten genannten Kontaktmöglichkeiten.
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Satz 1 von 1.14.: Kundinnen und Kunden --> Begünstigte
+
+CG: Besser: "Nutzer" (weil: beides, Kunden + Beguenstigte)
+
+- Beide Texte können ansonsten nach Korrektur orthografischer Fehler so bleiben und sollten
+auch in den AGB so angezeigt werden. Bitte diskutieren und eventuell kürzen.
+
+CG: Ja, definitiv viel kuerzen (siehe oben).
+[KOMMENTAR SK]
+
+1.15. Dauer und Kündigung
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Die Geschäftsbeziehung zwischen der Kundin bzw. dem Kunden und der TALER AG wird für
+unbestimmte Dauer abgeschlossen.
+Die Kundinnen und Kunden können ihr TALER Guthaben auf TALER jederzeit saldieren und
+schliessen, was als Kündigung gilt. Die TALER AG kann ihrerseits die Geschäftsbeziehung
+jederzeit mit sofortiger Wirkung kündigen. Eine schriftliche Kündigung der TALER AG erfolgt
+an die zuletzt bekanntgegebene (E-Mail-) Adresse der Kundin bzw. des Kunden.
+
+CG: Das ist Unsin, wir haben keine E-mail addressen von Kunden!
+
+Erfolgt während 4 Jahren keine Transaktion, gilt die Geschäftsbeziehung als durch die Kundin
+bzw. den Kunden gekündigt.
+
+[KOMMENTAR SK]
+- Satz 1: Die Geschäftsbeziehung zwischen den Begünstigten (Händler, Betriebe, Verkäufer
+und sonstige Empfänger von Überweisungen des Zahlungsdienst an die begünstigten
+IBAN-Konten) und dem Zahlungsdienstleister wird auf eine unbestimmte Dauer abgeschlossen.
+
+CG: Ja.
+
+- Satz 2: Die Nutzer von Taler-Wallets können das Guthaben jederzeit an die Bankkonten
+zurücküberweisen lassen, von denen die Überweisung der Nutzer an den Zahlungsdienst
+erfolgte, und so das Guthaben auf Null setzen.
+
+CG: Auch OK, wobei "saldieren" ggf. besser ist.
+
+- Satz 3: Die TALER AG kann die Geschäftsbeziehung mit den Begünstigten jederzeit -
+insbesondere in Missbrauchsfällen mit sofortiger Wirkung - kündigen.
+- Satz 4: Eine schriftliche Kündigung der TALER AG erfolgt an eine der zuletzt
+bekanntgegebenen Adressen der Geschäftspartner (z.B. per E-Mail oder Brief).
+- Satz 5: Streichen
+
+CG: Ja, wir brauchen ggf. noch etwas das TOPS bei Betriebsaufgabe die Nutzer ueber
+ das Taler-Protokoll informiert und die Wallets in diesem Fall die Kunden
+ auffordern werden, bestehende Restguthaben zu saldieren. Kunden die dies
+ unterlassen, verlieren dann nach 3 Monaten den Anspruch auf das Restguthaben.
+
+[KOMMENTAR SK]
+
+1.16. Übertragung
+~~~~~~~~~~~~~~~~~
+
+Die TALER AG kann die Vertragsbeziehung mit der Kundin bzw. dem Kunden
+(inkl. einem allfälligen Guthaben) jederzeit und ohne vorgängige Information auf eine andere
+Gesellschaft der TALER Gruppe übertragen.
+
+[KOMMENTAR SK]
+Änderungsvorschlag:
+Die Taler Operations AG kann eine vertraglich geregelte Geschäftsbeziehung jederzeit an
+eine andere Firma ihrer Muttergesellschaft übertragen.
+[KOMMENTAR SK]
+
+CG: Nein, einfach "auf eine andere Gesellschaft uebertragen".
+Gar keine Einschraenkung auf Gruppe/Mutter, bitte!
+
+
+1.17. Anwendbares Recht und Gerichtsstand
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Soweit gesetzlich zulässig, unterstehen alle Rechtsbeziehungen zwischen den Kundinnen und
+Kunden und der TALER AG (inkl. internationalen Zahlungen) ausschliesslich dem materiellen
+schweizerischen Recht, unter Ausschluss von Kollisionsrecht und unter Ausschluss von
+Staatsverträgen.
+Unter dem Vorbehalt von entgegenstehenden, zwingenden gesetzlichen Bestimmungen ist Zürich
+ausschliesslicher Gerichtsstand und Erfüllungsort. Für Kundinnen und Kunden mit Wohnsitz
+ausserhalb der Schweiz ist Zürich sodann auch Betreibungsort.
+
+[NETZBON-NEU]
+Bei etwaigen Streitigkeiten oder Unstimmigkeiten, die aus der Nutzung von Taler, der
+Taler-App und eNetzBon entstehen, verpflichten sich die Parteien, zunächst eine gütliche
+Einigung anzustreben. Wenn keine Einigung erzielt werden kann, unterliegt die
+Streitbeilegung den geltenden schweizerischen Gesetzen und der Gerichtsbarkeit von Biel.
+
+CG: Netzbon is Biel!? Nicht Basel?
+[NETZBON-NEU]
+
+[KOMMENTAR SK]
+- Satz 1: Kundinnen und Kunden --> Nutzern
+
+CG: immer ;-)
+
+- Satz 2: Zürich --> Biel
+
+CG: TOPS: Ich denke Bern, nicht Biel (so was ist doch bestimmt Kantonal!?)
+
+- Satz aus NETZBON-NEU ebenfalls verwenden
+
+CG: OK.
+[KOMMENTAR SK]
+
+2. Zahlungsfunktionen
+---------------------
+
+2.1. Limiten
+~~~~~~~~~~~~
+
+Die Kundinnen und Kunden können bis CHF "___________________".
+Bei Zahlungen an andere TALER Nutzer (P2P-Zahlung) bestehen für Kundinnen und Kunden mit
+Wohnsitz in der Schweiz Limiten von CHF 1‘000 pro Monat und CHF 5‘000 pro Kalenderjahr für
+das Senden und das Empfangen von Geld
+
+CG: 1000/5000 fuer das Abheben von e-Geld von einem Girokonto bzw. fuer den Empfang von
+ P2P Zahlungen zwischen Taler-Wallets mit bestaetigter Schweizer Mobilfunknummer.
+
+Die TALER AG behält sich vor, diese Limite jederzeit zu senken oder zu erhöhen bzw.
+zusätzliche Limite einzuführen, insbesondere aus regulatorischen sowie Sicherheitsgründen.
+
+[KOMMENTAR SK]
+Änderungsvorschlag für Satz 3:
+Die TALER AG behält sich insbesondere aus regulatorischen Gründen vor, die Limite jederzeit
+zu senken oder zu erhöhen. Die Änderung wird in aktualisierten AGB angezeigt, welche die
+Nutzer vor der weiteren Nutzung des Zahlungsdiensts zu bestätigen haben.
+[KOMMENTAR SK]
+
+CG: Das wir die AGB aendern koennen haben wir bereits gesagt, wuerde ich nicht doppeln.
+
+2.2. Aufbuchen
+~~~~~~~~~~~~~~
+
+Das TALER Wallet wird von den Kundinnen und Kunden über die hierfür "_________"vorgesehenen
+Optionen aufgeladen. Es stehen folgende Möglichkeiten zur Verfügung:
+* Zum Aufbuchen der gewünschten Währung und der Geldmenge wählt man in der
+Wallet-Anwendung den von TALER AG betriebenen Exchange, an den man die Gelder vom Girokonto
+überweist und von dem schließlich das Wallet die elektronischen Repräsentanten der
+gewünschten Geldmenge abhebt (sog. Coins)
+Die TALER AG kann weitere Aufladeoptionen einführen oder bestehende Optionen nicht mehr
+anbieten.
+Allfällige mit der Ladung verbundenen Transaktions- oder sonstigen Gebühren sind durch die
+Kundinnen und Kunden zu tragen.
+Das TALER Guthaben wird nicht verzinst. Die Kundinnen und Kunden nehmen zur Kenntnis, dass
+das Guthaben nicht von der Einlagensicherung gedeckt ist.
+Der Verarbeitungsprozess für das Aufladen bzw. Entladen des TALER Guthabens kann je nach
+Ladeoption mehrere Tage Zeit in Anspruch nehmen.
+Die Kundin bzw. der Kunde erteilt für den Fall der Einrichtung der LSV-Anbindung der TALER
+AG die Ermächtigung, einzelne Daten zwecks Bonitätsprüfung an Dritte weitergeben zu können.
+
+CG: Den letzten Satz streichen.
+
+[NETZBON-KOMMENTAR]
+Die Nutzer können eNetzBon durch zwei Verfahren erwerben bzw. das Guthaben auf ihrem Wallet
+erhöhen:
+
+a. Per Bareinzahlung durch Nutzung der "Taler Cashier-App" in der
+Markthalle und in der Buchhandlung, wo ein Nutzer den abzuhebenden Betrag in CHF an das
+Personal bar übergeben kann und dann durch das Wallet der Betrag in CHF abgehoben und im
+Wallet in eNetzBon umgetauscht wird.
+
+b. Per Banküberweisung an das PostFinanz-Konto des Vereins Soziale Ökonomie. Das Wallet
+hilft dabei den Nutzern, den Abhebevorgang einzuleiten und gibt dazu einen Verwendungszweck
+an, d.h. eine mehrstellige Kombination aus Nummer und Buchstaben, die im Kontoauszug des
+persönlichhen Girokontos des jeweiligen Nutzers als Buchungstext angezeigt wird. Mit diesem
+Verwendungszweck kann das Wallet den Betrag zuerst in CHF abheben und dann im Wallet in
+eNetzBon umtauschen.
+
+Der Preis eines eNetzBon beträgt 1 CHF. Bitte beachten Sie, dass NetzBon nicht
+rückerstattbar sind, daher müssen sie ausgegeben werden.
+
+In der Phase der Markteinführung von eNetzBon werden keine Transaktionskosten von Nutzern
+erhoben. Bei der Bezahlung mit eNetzBon fallen daher vorerst keine Transaktionsgebühren an.
+Diese Allgemeinen Geschäftsbedingungen erlauben jedoch die Möglichkeit zukünftiger
+Änderungen der Gebührenordnung.
+[NETZBON-KOMMENTAR]
+
+[KOMMENTAR SK]
+- Satz 3 in 2.2.: Streichen: (sog. Coins)
+- Satz 5: durch die Kundinnen und Kunden --> durch die Nutzer
+- Satz 6: Das TALER Guthaben --> Guthaben der Nutzer in Wallets
+- Satz 7: Kundinnen und Kunden --> Nutzer
+- Satz 8: Aufladen bzw. Entladen des TALER Guthabens --> Erhöhen und Verringern des
+Guthabens im Wallet
+
+CG: alle OK.
+
+- Satz 9: Diesen Satz kann ich nicht interpretieren (was ist LSV-Anbindung?); Kundin bzw.
+der Kunde --> Nutzer
+
+CG: LSV Lastschriftverfahren. Streichen, machen wir *nie*.
+[KOMMENTAR SK]
+
+2.3. Abbuchen
+~~~~~~~~~~~~~
+
+Das Entladen muss "_____________________________________________".
+
+[KOMMENTAR SK]
+Was soll in den Platzhalter kommen?
+[KOMMENTAR SK]
+
+CG: ... auf ein Schweizer Bankkonto erfolgen. Internationale Zahlungen sind nicht erlaubt.
+
+
+2.4. Zahlen mit TALER
+~~~~~~~~~~~~~~~~~~~~~
+
+Die Kundinnen und Kunden können mit dem Smartphone und dem damit verbundenen TALER Wallet an
+entsprechend ausgerüsteten Ladenkassen im Inland, Automaten, im Internet, in anderen Apps,
+durch Hinterlegung als TALER Zahlungsart bei ausgewählten Händlern, bei Mehrwertleistungen
+und an andere TALER Nutzer im Rahmen der geltenden Limiten bezahlen.
+Bei einer Bezahlung wird der entsprechende Betrag direkt vom TALER Wallet abgebucht. Es muss
+mindestes im TALER Wallet in Höhe des Transaktionsbetrags verfügbar sein.
+
+CG: Mehrwertleistungen streichen.
+
+[KOMMENTAR SK]
+Änderungsvorschlag für Satz 1: Die Nutzer können mit dem im Smartphone oder Webbrowser
+installierten Taler-Wallet innerhalb der geltenden Limiten bezahlen bei natürlichen und
+juristischen Personen, die diese Bezahloption akzeptieren und ein Schweizer Bankkonto zum
+Geldempfang führen (z.B. Ladengeschäfte, Webshops, Apps und sonstige Begünstigte).
+[KOMMENTAR SK]
+
+CG: Scheint mir aequivalent, ist mir egal ;-).
+
+
+2.5. Belastung der Bezahlungen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Die Kundinnen und Kunden anerkennen sämtliche getätigten P2M- und P2P-Zahlungen, welche mit
+dem TALER Wallet von ihrem Smartphone aus erfolgt sind, selbst wenn diese Zahlungen ohne
+ihre Zustimmung erfolgt sind.
+
+[KOMMENTAR SK]
+Es handelt sich bei dem Guthaben auf den Wallets der Nutzer um digitales Bargeld, dessen
+Eigentümerschaft technisch nicht ermittelbar ist. Jeder Teil des Guthabens erscheint in
+Form einer Datei mit alphanumerischen Zeichenfolgen und wird beim Abheben ins Wallet blind
+signiert, wodurch der Signatar keinen Rückschluss auf den Eigentümer des eingelösten
+Guthabens ziehen kann. Ist ein Guthaben eingelöst worden, kann dieses nicht noch ein
+weiteres Mal eingelöst werden. Wer das Guthaben zuerst einlöst, hat den Wert des Guthabens
+zur Zahlung verwendet.
+[KOMMENTAR SK]
+
+CG: Smartphone ist zu einschraenkend (kann ja auch ein Browser oder CLI-wallet sein!)
+CG: KOMMENTAR SK ist zu lang. Eher was von oben zum Thema Eigenverantwortung/Eigenverwahrung
+ runterziehen?
+
+
+2.6. Preise und Drittvergütungen
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Die Installation von TALER und die Nutzung der damit verbundenen Dienstleistungen sind
+grundsätzlich kostenlos.
+
+CG: Streichen. TOPS hat *nichts* mit der Installation zu tun. Die machen ggf. Dritte,
+ und da haben wir auch nichts zu zu sagen, was da die Kosten sind!
+
+Internationale Zahlungen in Fremdwährungen werden automatisch zu einem von einem Dritten
+gestellten Wechselkurs in Schweizer Franken umgerechnet. Die TALER AG kann diesen
+Wechselkurs erhöhen (sog. Mark-up) sowie eine zusätzliche Gebühr für die
+Fremdwährungstransaktion verlangen. Der Mark-up und die Gebühren fliessen alleine der TALER
+AG zu.
+
+CG: Streichen, wir machen keine Konvertierung.
+
+Den Kundinnen und Kunden wird in jedem Fall der finale Betrag in Schweizer Franken
+zur Bestätigung angezeigt. Kommt es zu einer Rückabwicklung einer internationalen Zahlung,
+so wird diese zum dannzumal gestellten Wechselkurs durchgeführt. Die Kundinnen und Kunden
+tragen das entsprechende Wechselkursrisiko.
+
+CG: Streichen, wir machen keine Konvertierung.
+
+TALER kann für die Nutzung von Aufladeoptionen Gebühren erheben. Die Kundinnen und Kunden
+werden in diesem Fall vor der Nutzung der
+kostenpflichtigen Aufladeoption in der TALER App über die zu bezahlenden Gebühren
+informiert.
+
+CG: Archivieren, nur wenn wir das wirklich machen in die AGB aufnehmen!
+
+Änderungen von Preisen und die Einführung neuer Preise werden grundsätzlich in der TALER App
+bekanntgegeben. Eine Anpassung gilt als genehmigt, wenn die Kundin bzw. der Kunde nicht vor
+Inkrafttreten der Änderung den Vertrag kündigt (Ziffer 1.15). Änderungen von Preisen für
+internationale Zahlungen müssen nicht separat bekanntgegeben werden.
+
+CG: Streichen, wir machen keine internationalen Zahlungen.
+
+Den Kundinnen und
+Kunden wird aber immer der Endbetrag in Schweizer Franken inkl. allen Gebühren angezeigt,
+
+
+bevor eine internationale Zahlung bestätigt wird.
+
+CG: Streichen, wir machen keine internationalen Zahlungen.
+
+
+Bei P2M-Zahlungen und der Inanspruchnahme von Mehrwertleistungen erhält die TALER AG unter
+Umständen gewisse Vergütungen von Dritten. Diese Drittvergütungen sind hier detailliert
+beschrieben.
+
+CG: Streichen, wir machen keine Mehrwertleistungen.
+
+Sie erlauben der TALER AG, die Benutzung der TALER App grundsätzlich kostenlos
+anzubieten. **Die Kundin bzw. der Kunde verzichtet auf die Erstattung sämtlicher
+Drittvergütungen, die die TALER AG in der Vergangenheit erhalten hat und in Zukunft erhalten
+könnte.**
+
+CG: Archivieren: wir bekommen keine Drittverguetungen, und *TOPS* bietet die Taler App gar nicht an!
+
+
+[KOMMENTAR SK]
+- Satz 1: --> Die Installation von Taler-Wallets ...
+- Satz 2: Internationale **eingehende** Zahlungen in Fremdwährungen werden automatisch zu
+einem von **der Schweizerischen Nationalbank** festgestellten Wechselkurs in Schweizer
+Franken umgerechnet.
+- Satz 6: Bei Rückbuchungen aus dem Guthaben in Taler-Wallets auf Nutzeranweisung oder bei
+erfolglosem Abheben ins Wallet erfolgen diese in derselben internationalen Fremdwährung wie
+die Eingangszahlung und verringert um anfallende Gebühren für Rücküberweisungen und
+Fremdwährungstransaktionen.
+- Satz 7 streichen
+- Satz 8: TALER --> Taler Operations AG
+- Satz 11: Eine Anpassung gilt als genehmigt, wenn die **Nutzer** die aktualisierten AGB in
+der App akzeptieren. Eine Anpassung gilt als genehmigt, wenn die Begünstigten (Händler,
+Betriebe, Verkäufer) nicht vor Inkrafttreten der Änderung den Vertrag kündigen.
+- Sätze 14 bis Ende: Bitte streichen, denn "Mehrwertleistungen" umfassen bei TWINT z.B.
+“Mobile-Marketing-Kampagnen”, Rabatt- und Kundenbindungsprogramme und die "Später
+zahlen"-Funktion. Diese Funktionen sind jedoch für das Taler-Bezahlsystem abträglich und
+dürften sowieso eher von der Seite der Händler angeboten werden.
+
+CG: Genau.
+
+Dankeschön, dass alle Kommentare bis hierhin durchgelesen wurden! Der AGB-Text muss ggf.
+stilistisch noch umformuliert werden, denn er ist zu weiten Teilen identisch mit TWINT-AGB.
+[KOMMENTAR SK]
+
+CG: Stilistische Gleichheit ist IMO kein Problem. Nur muss eben richtig sein ;-).
diff --git a/contrib/tos/tos.rst b/contrib/exchange-tos-v0.rst
index 2509b87b1..ea3ab297d 100644
--- a/contrib/tos/tos.rst
+++ b/contrib/exchange-tos-v0.rst
@@ -1,7 +1,8 @@
-Terms Of Service
+Terms of Service
================
-Last Updated: 12.4.2019
+Last update: 22.2.2024
+----------------------
Welcome! Taler Systems SA (“we,” “our,” or “us”) provides a payment service
through our Internet presence (collectively the “Services”). Before using our
@@ -20,27 +21,17 @@ to interact with our Services, you are agreeing to our Terms, so please read
carefully.
Highlights:
-~~~~~~~~~~~
-
- • You are responsible for keeping the data in your Taler Wallet at all times
- under your control. Any losses arising from you not being in control of
- your private information are your problem.
- • We will try to transfer funds we hold in escrow for our users to any legal
- recipient to the best of our ability within the limitations of the law and
- our implementation. However, the Services offered today are highly
- experimental and the set of recipients of funds is severely restricted.
- • For our Services, we may charge transaction fees. The specific fee structure
- is provided based on the Taler protocol and should be shown to you when you
- withdraw electronic coins using a Taler Wallet. You agree and understand
- that the Taler protocol allows for the fee structure to change.
- • You agree to not intentionally overwhelm our systems with requests and
- follow responsible disclosure if you find security issues in our services.
- • We cannot be held accountable for our Services not being available due to
- circumstances beyond our control. If we modify or terminate our services,
- we will try to give you the opportunity to recover your funds. However,
- given the experimental state of the Services today, this may not be
- possible. You are strongly advised to limit your use of the Service
- to small-scale experiments expecting total loss of all funds.
+-----------
+
+* You are responsible for keeping the data in your Taler Wallet at all times under your control. Any losses arising from you not being in control of your private information are your problem.
+
+* We will try to transfer funds we hold in escrow for our users to any legal recipient to the best of our ability within the limitations of the law and our implementation. However, the Services offered today are highly experimental and the set of recipients of funds is severely restricted.
+
+* For our Services, we may charge transaction fees. The specific fee structure is provided based on the Taler protocol and should be shown to you when you withdraw electronic coins using a Taler Wallet. You agree and understand that the Taler protocol allows for the fee structure to change.
+
+* You agree to not intentionally overwhelm our systems with requests and follow responsible disclosure if you find security issues in our services.
+
+* We cannot be held accountable for our Services not being available due to circumstances beyond our control. If we modify or terminate our services, we will try to give you the opportunity to recover your funds. However, given the experimental state of the Services today, this may not be possible. You are strongly advised to limit your use of the Service to small-scale experiments expecting total loss of all funds.
These terms outline approved uses of our Services. The Services and these
Terms are still at an experimental stage. If you have any questions or
@@ -69,12 +60,12 @@ Services
We will try to transfer funds that we hold in escrow for our users to any
legal recipient to the best of our ability and within the limitations of the
law and our implementation. However, the Services offered today are highly
-experimental and the set of recipients of funds is severely restricted. The
+experimental and the set of recipients of funds is severely restricted. The
Taler Wallet can be loaded by exchanging fiat currencies against electronic
coins. We are providing this exchange service. Once your Taler Wallet is
loaded with electronic coins they can be spent for purchases if the seller is
accepting Taler as a means of payment. We are not guaranteeing that any seller
-is accepting Taler at all or a particular seller. The seller or recipient of
+is accepting Taler at all or a particular seller. The seller or recipient of
deposits of electronic coins must specify the target account, as per the
design of the Taler protocol. They are responsible for following the protocol
and specifying the correct bank account, and are solely liable for any losses
@@ -96,7 +87,6 @@ months, and that we will not prosecute anyone reporting security issues if
they did not exploit the issue beyond a proof-of-concept, and followed the
above responsible disclosure practice.
-
Fees
----
@@ -107,7 +97,7 @@ for any electronic coin at the time of withdrawal and fixed throughout the
validity period of the respective electronic coin. Your wallet should obtain
and display applicable fees when withdrawing funds. Fees for coins obtained as
change may differ from the fees applicable to the original coin. Wire transfer
-fees that are independent from electronic coins may change annually. You
+fees that are independent from electronic coins may change annually. You
authorize us to charge or deduct applicable fees owed in connection with
deposits, exchanges and withdrawals following the rules of the Taler protocol.
We reserve the right to provide different types of rewards to users either in
@@ -137,13 +127,12 @@ The Taler Wallet is released under the terms of the GNU General Public License
modified or unmodified form. However, the GPL is a strong copyleft license,
which means that any derivative works must be distributed under the same
license terms as the original software. If you have any questions, you should
-review the GNU GPL’s full terms and conditions at
-https://www.gnu.org/licenses/gpl-3.0.en.html. “Taler” itself is a trademark
+review the GNU GPL’s full terms and conditions on the GNU GPL Licenses page
+(https://www.gnu.org/licenses/gpl-3.0.en.html/). “Taler” itself is a trademark
of Taler Systems SA. You are welcome to use the name in relation to processing
-payments using the Taler protocol, assuming your use is compatible with an
+payments based on the Taler protocol, assuming your use is compatible with an
official release from the GNU Project that is not older than two years.
-
Limitation of liability & disclaimer of warranties
--------------------------------------------------
@@ -154,22 +143,20 @@ software, and Internet connections; The risk of malicious software being
introduced or found in the software underlying the Taler Wallet; The risk that
third parties may obtain unauthorized access to information stored within your
Taler Wallet, including, but not limited to your Taler Wallet coins or backup
-encryption keys. You release us from all liability related to any losses,
+encryption keys. You release us from all liability related to any losses,
damages, or claims arising from:
-(a) user error such as forgotten passwords, incorrectly constructed
- transactions;
-(b) server failure or data loss;
-(c) unauthorized access to the Taler Wallet application;
-(d) bugs or other errors in the Taler Wallet software; and
-(e) any unauthorized third party activities, including, but not limited to,
- the use of viruses, phishing, brute forcing, or other means of attack
- against the Taler Wallet. We make no representations concerning any
- Third Party Content contained in or accessed through our Services.
+1) user error such as forgotten passwords, incorrectly constructed transactions;
+2) server failure or data loss;
+3) unauthorized access to the Taler Wallet application;
+4) bugs or other errors in the Taler Wallet software; and
+5) any unauthorized third party activities, including, but not limited to,
+the use of viruses, phishing, brute forcing, or other means of attack
+against the Taler Wallet. We make no representations concerning any
+Third Party Content contained in or accessed through our Services.
Any other terms, conditions, warranties, or representations associated with
-such content, are solely between you and such organizations and/or
-individuals.
+such content, are solely between you and such organizations and/or individuals.
To the fullest extent permitted by applicable law, in no event will we or any
of our officers, directors, representatives, agents, servants, counsel,
@@ -178,19 +165,16 @@ acting, or purporting to act on our behalf (collectively the “Taler Parties”
be liable to you under contract, tort, strict liability, negligence, or any
other legal or equitable theory, for:
-(a) any lost profits, data loss, cost of procurement of substitute goods or
- services, or direct, indirect, incidental, special, punitive, compensatory,
- or consequential damages of any kind whatsoever resulting from:
+1) any lost profits, data loss, cost of procurement of substitute goods or services,
+or direct, indirect, incidental, special, punitive, compensatory,
+or consequential damages of any kind whatsoever resulting from:
- (i) your use of, or conduct in connection with, our services;
- (ii) any unauthorized use of your wallet and/or private key due to your
- failure to maintain the confidentiality of your wallet;
- (iii) any interruption or cessation of transmission to or from the services; or
- (iv) any bugs, viruses, trojan horses, or the like that are found in the Taler
- Wallet software or that may be transmitted to or through our services by
- any third party (regardless of the source of origination), or
+* your use of, or conduct in connection with, our services;
+* any unauthorized use of your wallet and/or private key due to your failure to maintain the confidentiality of your wallet;
+* any interruption or cessation of transmission to or from the services; or
+* any bugs, viruses, trojan horses, or the like that are found in the Taler Wallet software or that may be transmitted to or through our services by any third party (regardless of the source of origination), or
-(b) any direct damages.
+2) any direct damages.
These limitations apply regardless of legal theory, whether based on tort,
strict liability, breach of contract, breach of warranty, or any other legal
@@ -221,10 +205,11 @@ Indemnity and Time limitation on claims and Termination
To the extent permitted by applicable law, you agree to defend, indemnify, and
hold harmless the Taler Parties from and against any and all claims, damages,
obligations, losses, liabilities, costs or debt, and expenses (including, but
-not limited to, attorney’s fees) arising from: (a) your use of and access to
-the Services; (b) any feedback or submissions you provide to us concerning the
-Taler Wallet; (c) your violation of any term of this Agreement; or (d) your
-violation of any law, rule, or regulation, or the rights of any third party.
+not limited to, attorney’s fees) arising from:
+(a) your use of and access to the Services;
+(b) any feedback or submissions you provide to us concerning the Taler Wallet;
+(c) your violation of any term of this Agreement; or
+(d) your violation of any law, rule, or regulation, or the rights of any third party.
You agree that any claim you may have arising out of or related to your
relationship with us must be filed within one year after such claim arises,
@@ -257,7 +242,6 @@ services, failure of equipment and/or software, other catastrophe, or any
other occurrence which is beyond our reasonable control and shall not affect
the validity and enforceability of any remaining provisions.
-
Governing law, Waivers, Severability and Assignment
---------------------------------------------------
@@ -288,7 +272,6 @@ prior versions of this Agreement) and every nature between us. Except as
provided for above, any modification to this Agreement must be in writing and
must be signed by both parties.
-
Questions or comments
---------------------
diff --git a/contrib/gana b/contrib/gana
-Subproject cf9e9f70ae04da02be8d11fde5668e2ef72adc5
+Subproject 41a6b138a8b62766749a34449ac18bf7cedf963
diff --git a/contrib/gana-update.sh b/contrib/gana-generate.sh
index b20bbaa1d..4679e2003 100755
--- a/contrib/gana-update.sh
+++ b/contrib/gana-generate.sh
@@ -1,4 +1,6 @@
#!/bin/sh
+# This file is in the public domain.
+#
# Helper script to recompute error codes based on submodule
# Run from exchange/ main directory.
set -eu
diff --git a/contrib/gana.sh b/contrib/gana-latest.sh
index 30dc7994e..e92761acc 100755
--- a/contrib/gana.sh
+++ b/contrib/gana-latest.sh
@@ -7,4 +7,4 @@ cd contrib/gana
git pull origin master
cd ../..
-exec ./contrib/gana-update.sh
+exec ./contrib/gana-generate.sh
diff --git a/contrib/gnunet.tag b/contrib/gnunet.tag
index f270ba5ea..4cfdbff9c 100644
--- a/contrib/gnunet.tag
+++ b/contrib/gnunet.tag
@@ -18,6 +18,18 @@
</member>
<member kind="define">
<type>#define</type>
+ <name>GNUNET_CRYPTO_BSA_RSA</name>
+ <anchorfile>gnunet_crypto_lib.h</anchorfile>
+ <arglist></arglist>
+ </member>
+ <member kind="define">
+ <type>#define</type>
+ <name>GNUNET_CRYPTO_BSA_CS</name>
+ <anchorfile>gnunet_crypto_lib.h</anchorfile>
+ <arglist></arglist>
+ </member>
+ <member kind="define">
+ <type>#define</type>
<name>GNUNET_NO</name>
<anchorfile>gnunet_util_lib.h</anchorfile>
<arglist></arglist>
@@ -31,7 +43,13 @@
<member kind="define">
<type>#define</type>
<name>GNUNET_TIME_UNIT_FOREVER_ABS</name>
- <anchorfile>gnunet_util_lib.h</anchorfile>
+ <anchorfile>gnunet_time_lib.h</anchorfile>
+ <arglist></arglist>
+ </member>
+ <member kind="define">
+ <type>#define</type>
+ <name>GNUNET_TIME_UNIT_ZERO_ABS</name>
+ <anchorfile>gnunet_time_lib.h</anchorfile>
<arglist></arglist>
</member>
</compound>
diff --git a/contrib/kyc-proof-already-done.en.must b/contrib/kyc-proof-already-done.en.must
new file mode 100644
index 000000000..c676aa931
--- /dev/null
+++ b/contrib/kyc-proof-already-done.en.must
@@ -0,0 +1,9 @@
+<html>
+<head>
+<title>200: KYC already completed</title>
+</head>
+<body>
+ The KYC process is already completed.
+ There is nothing left to do here.
+</body>
+</html>
diff --git a/contrib/kyc-proof-bad-request.en.must b/contrib/kyc-proof-bad-request.en.must
new file mode 100644
index 000000000..f55516873
--- /dev/null
+++ b/contrib/kyc-proof-bad-request.en.must
@@ -0,0 +1,15 @@
+<html>
+<head>
+<title>400: Malformed client request</title>
+</head>
+<body>
+The client's request was malformed.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA EC hint --> {{ hint }}
+</pre>
+<p>
+<!-- optional human-readable message --> {{ message }}
+</p>
+</body>
+</html>
diff --git a/contrib/kyc-proof-endpoint-unknown.en.must b/contrib/kyc-proof-endpoint-unknown.en.must
new file mode 100644
index 000000000..275f42380
--- /dev/null
+++ b/contrib/kyc-proof-endpoint-unknown.en.must
@@ -0,0 +1,15 @@
+<html>
+<head>
+<title>404: Endpoint unknown</title>
+</head>
+<body>
+The given URL does not match any supported endpoint.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA EC hint --> {{ hint }}
+</pre>
+<p>
+<!-- optional human-readable message --> {{ message }}
+</p>
+</body>
+</html>
diff --git a/contrib/kyc-proof-internal-error.en.must b/contrib/kyc-proof-internal-error.en.must
new file mode 100644
index 000000000..ab7845e0d
--- /dev/null
+++ b/contrib/kyc-proof-internal-error.en.must
@@ -0,0 +1,16 @@
+<html>
+<head>
+<title>500: Internal server error</title>
+</head>
+<body>
+ The server experienced an internal error handling
+ the request.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA EC hint --> {{ hint }}
+</pre>
+<p>
+<!-- optional human-readable message --> {{ message }}
+</p>
+</body>
+</html>
diff --git a/contrib/kyc-proof-target-unknown.en.must b/contrib/kyc-proof-target-unknown.en.must
new file mode 100644
index 000000000..1a698506f
--- /dev/null
+++ b/contrib/kyc-proof-target-unknown.en.must
@@ -0,0 +1,15 @@
+<html>
+<head>
+<title>404: KYC request target unknown</title>
+</head>
+<body>
+We could not identify the KYC operation requested.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA EC hint --> {{ hint }}
+</pre>
+<p>
+<!-- optional human-readable message --> {{ message }}
+</p>
+</body>
+</html>
diff --git a/contrib/kycaid-invalid-request.en.must b/contrib/kycaid-invalid-request.en.must
new file mode 100644
index 000000000..c33e3883f
--- /dev/null
+++ b/contrib/kycaid-invalid-request.en.must
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>400: Invalid endpoint for KYCaid</title>
+</head>
+<body>
+This endpoint is not defined for the KYCaid plugin.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA string for EC --> {{ hint }}
+</pre>
+</body>
+</html>
diff --git a/contrib/locale/de/LC_MESSAGES/exchange-tos-v0.po b/contrib/locale/de/LC_MESSAGES/exchange-tos-v0.po
new file mode 100644
index 000000000..6cd899442
--- /dev/null
+++ b/contrib/locale/de/LC_MESSAGES/exchange-tos-v0.po
@@ -0,0 +1,403 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) 2014-2023 Taler Systems SA (GPLv3+ or GFDL 1.3+)
+# This file is distributed under the same license as the tos-v0 package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: tos-v0 tos-v0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2023-07-20 15:38+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: de\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "Terms of Service"
+msgstr "Allgemeine Geschäftsbedingungen"
+
+msgid "Last Updated: 27.11.2023"
+msgstr ""
+
+msgid ""
+"Welcome! Taler Systems SA (“we,” “our,” or “us”) provides a payment service "
+"through our Internet presence (collectively the “Services”). Before using "
+"our Services, please read the Terms of Service (the “Terms” or the "
+"“Agreement”) carefully."
+msgstr ""
+
+msgid "Overview"
+msgstr ""
+
+msgid ""
+"This section provides a brief summary of the highlights of this Agreement. "
+"Please note that when you accept this Agreement, you are accepting all of "
+"the terms and conditions and not just this section. We and possibly other "
+"third parties provide Internet services which interact with the Taler "
+"Wallet’s self-hosted personal payment application. When using the Taler "
+"Wallet to interact with our Services, you are agreeing to our Terms, so "
+"please read carefully."
+msgstr ""
+
+msgid "Highlights:"
+msgstr ""
+
+msgid ""
+"You are responsible for keeping the data in your Taler Wallet at all times "
+"under your control. Any losses arising from you not being in control of your "
+"private information are your problem."
+msgstr ""
+
+msgid ""
+"We will try to transfer funds we hold in escrow for our users to any legal "
+"recipient to the best of our ability within the limitations of the law and "
+"our implementation. However, the Services offered today are highly "
+"experimental and the set of recipients of funds is severely restricted."
+msgstr ""
+
+msgid ""
+"For our Services, we may charge transaction fees. The specific fee structure "
+"is provided based on the Taler protocol and should be shown to you when you "
+"withdraw electronic coins using a Taler Wallet. You agree and understand "
+"that the Taler protocol allows for the fee structure to change."
+msgstr ""
+
+msgid ""
+"You agree to not intentionally overwhelm our systems with requests and "
+"follow responsible disclosure if you find security issues in our services."
+msgstr ""
+
+msgid ""
+"We cannot be held accountable for our Services not being available due to "
+"circumstances beyond our control. If we modify or terminate our services, we "
+"will try to give you the opportunity to recover your funds. However, given "
+"the experimental state of the Services today, this may not be possible. You "
+"are strongly advised to limit your use of the Service to small-scale "
+"experiments expecting total loss of all funds."
+msgstr ""
+
+msgid ""
+"These terms outline approved uses of our Services. The Services and these "
+"Terms are still at an experimental stage. If you have any questions or "
+"comments related to this Agreement, please send us a message to legal@taler-"
+"systems.com. If you do not agree to this Agreement, you must not use our "
+"Services."
+msgstr ""
+
+msgid "How you accept this policy"
+msgstr ""
+
+msgid ""
+"By sending funds to us (to top-up your Taler Wallet), you acknowledge that "
+"you have read, understood, and agreed to these Terms. We reserve the right "
+"to change these Terms at any time. If you disagree with the change, we may "
+"in the future offer you with an easy option to recover your unspent funds. "
+"However, in the current experimental period you acknowledge that this "
+"feature is not yet available, resulting in your funds being lost unless you "
+"accept the new Terms. If you continue to use our Services other than to "
+"recover your unspent funds, your continued use of our Services following any "
+"such change will signify your acceptance to be bound by the then current "
+"Terms. Please check the effective date above to determine if there have been "
+"any changes since you have last reviewed these Terms."
+msgstr ""
+
+msgid "Services"
+msgstr ""
+
+msgid ""
+"We will try to transfer funds that we hold in escrow for our users to any "
+"legal recipient to the best of our ability and within the limitations of the "
+"law and our implementation. However, the Services offered today are highly "
+"experimental and the set of recipients of funds is severely restricted. The "
+"Taler Wallet can be loaded by exchanging fiat currencies against electronic "
+"coins. We are providing this exchange service. Once your Taler Wallet is "
+"loaded with electronic coins they can be spent for purchases if the seller "
+"is accepting Taler as a means of payment. We are not guaranteeing that any "
+"seller is accepting Taler at all or a particular seller. The seller or "
+"recipient of deposits of electronic coins must specify the target account, "
+"as per the design of the Taler protocol. They are responsible for following "
+"the protocol and specifying the correct bank account, and are solely liable "
+"for any losses that may arise from specifying the wrong account. We will "
+"allow the government to link wire transfers to the underlying contract hash. "
+"It is the responsibility of recipients to preserve the full contracts and to "
+"pay whatever taxes and charges may be applicable. Technical issues may lead "
+"to situations where we are unable to make transfers at all or lead to "
+"incorrect transfers that cannot be reversed. We will only refuse to execute "
+"transfers if the transfers are prohibited by a competent legal authority and "
+"we are ordered to do so."
+msgstr ""
+
+msgid ""
+"When using our Services, you agree to not take any action that intentionally "
+"imposes an unreasonable load on our infrastructure. If you find security "
+"problems in our Services, you agree to first report them to security@taler-"
+"systems.com and grant us the right to publish your report. We warrant that "
+"we will ourselves publicly disclose any issues reported within 3 months, and "
+"that we will not prosecute anyone reporting security issues if they did not "
+"exploit the issue beyond a proof-of-concept, and followed the above "
+"responsible disclosure practice."
+msgstr ""
+
+msgid "Fees"
+msgstr ""
+
+msgid ""
+"You agree to pay the fees for exchanges and withdrawals completed via the "
+"Taler Wallet (\"Fees\") as defined by us, which we may change from time to "
+"time. With the exception of wire transfer fees, Taler transaction fees are "
+"set for any electronic coin at the time of withdrawal and fixed throughout "
+"the validity period of the respective electronic coin. Your wallet should "
+"obtain and display applicable fees when withdrawing funds. Fees for coins "
+"obtained as change may differ from the fees applicable to the original coin. "
+"Wire transfer fees that are independent from electronic coins may change "
+"annually. You authorize us to charge or deduct applicable fees owed in "
+"connection with deposits, exchanges and withdrawals following the rules of "
+"the Taler protocol. We reserve the right to provide different types of "
+"rewards to users either in the form of discount for our Services or in any "
+"other form at our discretion and without prior notice to you."
+msgstr ""
+
+msgid "Eligibility and Financial self-responsibility"
+msgstr ""
+
+msgid ""
+"To be eligible to use our Services, you must be able to form legally binding "
+"contracts or have the permission of your legal guardian. By using our "
+"Services, you represent and warrant that you meet all eligibility "
+"requirements that we outline in these Terms."
+msgstr ""
+
+msgid ""
+"You will be responsible for maintaining the availability, integrity and "
+"confidentiality of the data stored in your wallet. When you setup a Taler "
+"Wallet, you are strongly advised to follow the precautionary measures "
+"offered by the software to minimize the chances to losse access to or "
+"control over your Wallet data. We will not be liable for any loss or damage "
+"arising from your failure to comply with this paragraph."
+msgstr ""
+
+msgid "Copyrights and trademarks"
+msgstr ""
+
+msgid ""
+"The Taler Wallet is released under the terms of the GNU General Public "
+"License (GNU GPL). You have the right to access, use, and share the Taler "
+"Wallet, in modified or unmodified form. However, the GPL is a strong "
+"copyleft license, which means that any derivative works must be distributed "
+"under the same license terms as the original software. If you have any "
+"questions, you should review the GNU GPL’s full terms and conditions at "
+"https://www.gnu.org/licenses/gpl-3.0.en.html. “Taler” itself is a trademark "
+"of Taler Systems SA. You are welcome to use the name in relation to "
+"processing payments using the Taler protocol, assuming your use is "
+"compatible with an official release from the GNU Project that is not older "
+"than two years."
+msgstr ""
+
+msgid "Limitation of liability & disclaimer of warranties"
+msgstr ""
+
+msgid ""
+"You understand and agree that we have no control over, and no duty to take "
+"any action regarding: Failures, disruptions, errors, or delays in processing "
+"that you may experience while using our Services; The risk of failure of "
+"hardware, software, and Internet connections; The risk of malicious software "
+"being introduced or found in the software underlying the Taler Wallet; The "
+"risk that third parties may obtain unauthorized access to information stored "
+"within your Taler Wallet, including, but not limited to your Taler Wallet "
+"coins or backup encryption keys. You release us from all liability related "
+"to any losses, damages, or claims arising from:"
+msgstr ""
+
+msgid ""
+"user error such as forgotten passwords, incorrectly constructed transactions;"
+msgstr ""
+
+msgid "server failure or data loss;"
+msgstr ""
+
+msgid "unauthorized access to the Taler Wallet application;"
+msgstr ""
+
+msgid "bugs or other errors in the Taler Wallet software; and"
+msgstr ""
+
+msgid ""
+"any unauthorized third party activities, including, but not limited to, the "
+"use of viruses, phishing, brute forcing, or other means of attack against "
+"the Taler Wallet. We make no representations concerning any Third Party "
+"Content contained in or accessed through our Services."
+msgstr ""
+
+msgid ""
+"Any other terms, conditions, warranties, or representations associated with "
+"such content, are solely between you and such organizations and/or "
+"individuals."
+msgstr ""
+
+msgid ""
+"To the fullest extent permitted by applicable law, in no event will we or "
+"any of our officers, directors, representatives, agents, servants, counsel, "
+"employees, consultants, lawyers, and other personnel authorized to act, "
+"acting, or purporting to act on our behalf (collectively the “Taler "
+"Parties”) be liable to you under contract, tort, strict liability, "
+"negligence, or any other legal or equitable theory, for:"
+msgstr ""
+
+msgid ""
+"any lost profits, data loss, cost of procurement of substitute goods or "
+"services, or direct, indirect, incidental, special, punitive, compensatory, "
+"or consequential damages of any kind whatsoever resulting from:"
+msgstr ""
+
+msgid "your use of, or conduct in connection with, our services;"
+msgstr ""
+
+msgid ""
+"any unauthorized use of your wallet and/or private key due to your failure "
+"to maintain the confidentiality of your wallet;"
+msgstr ""
+
+msgid ""
+"any interruption or cessation of transmission to or from the services; or"
+msgstr ""
+
+msgid ""
+"any bugs, viruses, trojan horses, or the like that are found in the Taler "
+"Wallet software or that may be transmitted to or through our services by any "
+"third party (regardless of the source of origination), or"
+msgstr ""
+
+msgid "any direct damages."
+msgstr ""
+
+msgid ""
+"These limitations apply regardless of legal theory, whether based on tort, "
+"strict liability, breach of contract, breach of warranty, or any other legal "
+"theory, and whether or not we were advised of the possibility of such "
+"damages. Some jurisdictions do not allow the exclusion or limitation of "
+"liability for consequential or incidental damages, so the above limitation "
+"may not apply to you."
+msgstr ""
+
+msgid ""
+"Our services are provided \"as is\" and without warranty of any kind. To the "
+"maximum extent permitted by law, we disclaim all representations and "
+"warranties, express or implied, relating to the services and underlying "
+"software or any content on the services, whether provided or owned by us or "
+"by any third party, including without limitation, warranties of "
+"merchantability, fitness for a particular purpose, title, non-infringement, "
+"freedom from computer virus, and any implied warranties arising from course "
+"of dealing, course of performance, or usage in trade, all of which are "
+"expressly disclaimed. In addition, we do not represent or warrant that the "
+"content accessible via the services is accurate, complete, available, "
+"current, free of viruses or other harmful components, or that the results of "
+"using the services will meet your requirements. Some states do not allow the "
+"disclaimer of implied warranties, so the foregoing disclaimers may not apply "
+"to you. This paragraph gives you specific legal rights and you may also have "
+"other legal rights that vary from state to state."
+msgstr ""
+
+msgid "Indemnity and Time limitation on claims and Termination"
+msgstr ""
+
+msgid ""
+"To the extent permitted by applicable law, you agree to defend, indemnify, "
+"and hold harmless the Taler Parties from and against any and all claims, "
+"damages, obligations, losses, liabilities, costs or debt, and expenses "
+"(including, but not limited to, attorney’s fees) arising from: (a) your use "
+"of and access to the Services; (b) any feedback or submissions you provide "
+"to us concerning the Taler Wallet; (c) your violation of any term of this "
+"Agreement; or (d) your violation of any law, rule, or regulation, or the "
+"rights of any third party."
+msgstr ""
+
+msgid ""
+"You agree that any claim you may have arising out of or related to your "
+"relationship with us must be filed within one year after such claim arises, "
+"otherwise, your claim in permanently barred."
+msgstr ""
+
+msgid ""
+"In the event of termination concerning your use of our Services, your "
+"obligations under this Agreement will still continue."
+msgstr ""
+
+msgid "Discontinuance of services and Force majeure"
+msgstr ""
+
+msgid ""
+"We may, in our sole discretion and without cost to you, with or without "
+"prior notice, and at any time, modify or discontinue, temporarily or "
+"permanently, any portion of our Services. We will use the Taler protocol’s "
+"provisions to notify Wallets if our Services are to be discontinued. It is "
+"your responsibility to ensure that the Taler Wallet is online at least once "
+"every three months to observe these notifications. We shall not be held "
+"responsible or liable for any loss of funds in the event that we discontinue "
+"or depreciate the Services and your Taler Wallet fails to transfer out the "
+"coins within a three months notification period."
+msgstr ""
+
+msgid ""
+"We shall not be held liable for any delays, failure in performance, or "
+"interruptions of service which result directly or indirectly from any cause "
+"or condition beyond our reasonable control, including but not limited to: "
+"any delay or failure due to any act of God, act of civil or military "
+"authorities, act of terrorism, civil disturbance, war, strike or other labor "
+"dispute, fire, interruption in telecommunications or Internet services or "
+"network provider services, failure of equipment and/or software, other "
+"catastrophe, or any other occurrence which is beyond our reasonable control "
+"and shall not affect the validity and enforceability of any remaining "
+"provisions."
+msgstr ""
+
+msgid "Governing law, Waivers, Severability and Assignment"
+msgstr ""
+
+msgid ""
+"No matter where you’re located, the laws of Switzerland will govern these "
+"Terms. If any provisions of these Terms are inconsistent with any applicable "
+"law, those provisions will be superseded or modified only to the extent such "
+"provisions are inconsistent. The parties agree to submit to the ordinary "
+"courts in Zurich, Switzerland for exclusive jurisdiction of any dispute "
+"arising out of or related to your use of the Services or your breach of "
+"these Terms."
+msgstr ""
+
+msgid ""
+"Our failure to exercise or delay in exercising any right, power, or "
+"privilege under this Agreement shall not operate as a waiver; nor shall any "
+"single or partial exercise of any right, power, or privilege preclude any "
+"other or further exercise thereof."
+msgstr ""
+
+msgid ""
+"You agree that we may assign any of our rights and/or transfer, sub-"
+"contract, or delegate any of our obligations under these Terms."
+msgstr ""
+
+msgid ""
+"If it turns out that any part of this Agreement is invalid, void, or for any "
+"reason unenforceable, that term will be deemed severable and limited or "
+"eliminated to the minimum extent necessary."
+msgstr ""
+
+msgid ""
+"This Agreement sets forth the entire understanding and agreement as to the "
+"subject matter hereof and supersedes any and all prior discussions, "
+"agreements, and understandings of any kind (including, without limitation, "
+"any prior versions of this Agreement) and every nature between us. Except as "
+"provided for above, any modification to this Agreement must be in writing "
+"and must be signed by both parties."
+msgstr ""
+
+msgid "Questions or comments"
+msgstr ""
+
+msgid ""
+"We welcome comments, questions, concerns, or suggestions. Please send us a "
+"message on our contact page at legal@taler-systems.com."
+msgstr ""
diff --git a/contrib/microhttpd.tag b/contrib/microhttpd.tag
index 4780028dd..5156a1a3a 100644
--- a/contrib/microhttpd.tag
+++ b/contrib/microhttpd.tag
@@ -48,6 +48,12 @@
</member>
<member kind="define">
<type>#define</type>
+ <name>MHD_HTTP_CONTENT_TOO_LARGE</name>
+ <anchorfile>microhttpd.h</anchorfile>
+ <arglist></arglist>
+ </member>
+ <member kind="define">
+ <type>#define</type>
<name>MHD_HTTP_REQUEST_TIMEOUT</name>
<anchorfile>microhttpd.h</anchorfile>
<arglist></arglist>
@@ -72,6 +78,12 @@
</member>
<member kind="define">
<type>#define</type>
+ <name>MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED</name>
+ <anchorfile>microhttpd.h</anchorfile>
+ <arglist></arglist>
+ </member>
+ <member kind="define">
+ <type>#define</type>
<name>MHD_HTTP_GONE</name>
<anchorfile>microhttpd.h</anchorfile>
<arglist></arglist>
diff --git a/contrib/oauth2-authentication-failure.en.must b/contrib/oauth2-authentication-failure.en.must
new file mode 100644
index 000000000..537423269
--- /dev/null
+++ b/contrib/oauth2-authentication-failure.en.must
@@ -0,0 +1,16 @@
+<html>
+<head>
+<title>403: Authentication by KYC server failed</title>
+</head>
+<body>
+ You failed the authentication check.
+ The transaction remains blocked.
+ Please obtain proper credentials and try again to proceed.
+<pre>
+<!-- as provided by OAuth2.0 server --> {{ error }}:
+<!-- optional, as provided by OAuth2.0 server --> {{ error_description }}
+
+<!-- optional link (render as link if present!), as provided by OAuth2.0 server --> {{ error_uri }}
+</pre>
+</body>
+</html>
diff --git a/contrib/oauth2-authorization-failure-malformed.en.must b/contrib/oauth2-authorization-failure-malformed.en.must
new file mode 100644
index 000000000..6f7552eae
--- /dev/null
+++ b/contrib/oauth2-authorization-failure-malformed.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>502: OAuth 2.0 service returned malformed response</title>
+</head>
+<body>
+ The KYC backend returned an authorization failure,
+ but additionally provided a malformed error response.
+ <pre>
+<!-- Should we output potentially sensitive data? --> {{ debug }}
+<!-- Optional: server response --> {{ server_response }}
+</pre>
+</body>
+</html>
diff --git a/contrib/oauth2-authorization-failure.en.must b/contrib/oauth2-authorization-failure.en.must
new file mode 100644
index 000000000..c184d10d8
--- /dev/null
+++ b/contrib/oauth2-authorization-failure.en.must
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>403: KYC server refused access</title>
+</head>
+<body>
+The KYC backend refused the authorization code used by the exchange operator. Please inform the exchange operator about this failure.
+<pre>
+<!-- as provided by OAuth2.0 server --> {{ error }}:
+<!-- as provided by OAuth2.0 server --> {{ error_description }}
+</pre>
+</body>
+</html>
diff --git a/contrib/oauth2-bad-request.en.must b/contrib/oauth2-bad-request.en.must
new file mode 100644
index 000000000..f55516873
--- /dev/null
+++ b/contrib/oauth2-bad-request.en.must
@@ -0,0 +1,15 @@
+<html>
+<head>
+<title>400: Malformed client request</title>
+</head>
+<body>
+The client's request was malformed.
+<pre>
+<!-- Taler error code --> {{ code }}:
+<!-- GANA EC hint --> {{ hint }}
+</pre>
+<p>
+<!-- optional human-readable message --> {{ message }}
+</p>
+</body>
+</html>
diff --git a/contrib/oauth2-conversion-failure.en.must b/contrib/oauth2-conversion-failure.en.must
new file mode 100644
index 000000000..e117f5de6
--- /dev/null
+++ b/contrib/oauth2-conversion-failure.en.must
@@ -0,0 +1,28 @@
+<html>
+<head>
+<title>502: Failed to convert KYC data into internal format</title>
+</head>
+<body>
+ The KYC backend returned a response which we then failed
+ to convert into our internal format.
+<pre>
+<!-- Taler Error code --> {{ code }}:
+<!-- Taler EC hint --> {{ hint }}
+</pre>
+<p>
+ <!-- human-readable message --> {{ message}}
+</p>
+<p>
+ Converter command used was: &quot;{{ converter }}&quot;
+</p>
+<p>
+ Converter JSON output:
+<pre>
+ <!-- true if we are in debug mode --> {{ debug }}
+ <!-- optional: attributes returned by script
+ (note: may contain user's private information) --> {{ attributes }}
+</pre>
+</p>
+</pre>
+</body>
+</html>
diff --git a/contrib/oauth2-provider-failure.en.must b/contrib/oauth2-provider-failure.en.must
new file mode 100644
index 000000000..d4c3585bf
--- /dev/null
+++ b/contrib/oauth2-provider-failure.en.must
@@ -0,0 +1,22 @@
+<html>
+<head>
+<title>502: KYC provider had an internal error</title>
+</head>
+<body>
+The KYC OAuth2 backend had an internal error.
+<pre>
+<!-- taler error code --> {{ code }}:
+<!-- GANA hint for EC --> {{ hint }}
+</pre>
+<p>
+ <!-- human readable message with more specifics -->
+ {{ message }}
+</p>
+<pre>
+ <!-- true if we are in debug mode --> {{ debug }}
+ <!-- optional: full response from OAuth provider;
+ may contain private information! -->
+ {{ server_response }}
+</p>
+</body>
+</html>
diff --git a/contrib/packages/fedora/etc-libtalerexchange/taler/overrides.conf b/contrib/packages/fedora/etc-libtalerexchange/taler/overrides.conf
new file mode 100644
index 000000000..60296ead4
--- /dev/null
+++ b/contrib/packages/fedora/etc-libtalerexchange/taler/overrides.conf
@@ -0,0 +1 @@
+# This configuration will be changed by tooling. Do not touch it manually.
diff --git a/contrib/packages/fedora/etc-libtalerexchange/taler/taler.conf b/contrib/packages/fedora/etc-libtalerexchange/taler/taler.conf
new file mode 100644
index 000000000..1c86ccc36
--- /dev/null
+++ b/contrib/packages/fedora/etc-libtalerexchange/taler/taler.conf
@@ -0,0 +1,49 @@
+# Main entry point for the GNU Taler configuration.
+#
+# Structure:
+# - taler.conf is the main configuration entry point
+# used by all Taler components (the file you are currently
+# looking at.
+# - overrides.conf contains configuration overrides that are
+# set by some tools that help with the configuration,
+# and should not be edited by humans. Comments in this file
+# are not preserved.
+# - conf.d/ contains configuration files for
+# Taler components, which can be read by all
+# users of the system and are included by the main
+# configuration.
+# - secrets/ contains configuration snippets
+# with secrets for particular services.
+# These files should have restrictive permissions
+# so that only users of the relevant services
+# can read it. All files in it should end with
+# ".secret.conf".
+
+[taler]
+
+# Currency of the Taler deployment. This setting applies to all Taler
+# components that only support a single currency.
+#currency = KUDOS
+
+# Smallest currency unit handled by the underlying bank system. Taler payments
+# can make payments smaller than this units, but interactions with external
+# systems is always rounded to this unit.
+#currency_round_unit = KUDOS:0.01
+
+# Monthly amount that mandatorily triggers an AML check
+#AML_THRESHOLD = KUDOS:10000000
+
+[paths]
+
+TALER_HOME = /var/lib/taler
+TALER_RUNTIME_DIR = /run/taler
+TALER_CACHE_HOME = /var/cache/taler
+TALER_CONFIG_HOME = /etc/taler
+TALER_DATA_HOME = /var/lib/taler
+
+
+# Inline configurations from all Taler components.
+@inline-matching@ conf.d/*.conf
+
+# Overrides from tools that help with configuration.
+@inline@ overrides.conf
diff --git a/contrib/packages/fedora/etc-taler-auditor/apache2/sites-available/taler-auditor.conf b/contrib/packages/fedora/etc-taler-auditor/apache2/sites-available/taler-auditor.conf
new file mode 100644
index 000000000..f68c59558
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-auditor/apache2/sites-available/taler-auditor.conf
@@ -0,0 +1,4 @@
+<Location "/taler-auditor/">
+ProxyPass "unix:/var/lib/taler-auditor/auditor.sock|http://example.com/"
+RequestHeader add "X-Forwarded-Proto" "https"
+</Location>
diff --git a/contrib/packages/fedora/etc-taler-auditor/nginx/sites-available/taler-auditor b/contrib/packages/fedora/etc-taler-auditor/nginx/sites-available/taler-auditor
new file mode 100644
index 000000000..f74035d53
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-auditor/nginx/sites-available/taler-auditor
@@ -0,0 +1,18 @@
+server {
+
+ listen 80;
+ listen [::]:80;
+
+ server_name localhost;
+
+ access_log /var/log/nginx/auditor.log;
+ error_log /var/log/nginx/auditor.err;
+
+ location /taler-auditor/ {
+ proxy_pass http://unix:/var/lib/taler-auditor/auditor.sock;
+ proxy_redirect off;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-Host "localhost";
+ #proxy_set_header X-Forwarded-Proto "https";
+ }
+} \ No newline at end of file
diff --git a/contrib/packages/fedora/etc-taler-auditor/taler/conf.d/auditor-system.conf b/contrib/packages/fedora/etc-taler-auditor/taler/conf.d/auditor-system.conf
new file mode 100644
index 000000000..3d3aef33a
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-auditor/taler/conf.d/auditor-system.conf
@@ -0,0 +1,12 @@
+# Read secret sections into configuration, but only
+# if we have permission to do so.
+@inline-secret@ auditordb-postgres ../secrets/auditor-db.secret.conf
+
+[auditor]
+# Debian package is configured to use a reverse proxy with a UNIX
+# domain socket. See nginx/apache configuration files.
+SERVE = UNIX
+UNIXPATH = /var/lib/taler-auditor/auditor.sock
+
+# Only supported database is Postgres right now.
+DATABASE = postgres
diff --git a/contrib/packages/fedora/etc-taler-auditor/taler/secrets/auditor-db.secret.conf b/contrib/packages/fedora/etc-taler-auditor/taler/secrets/auditor-db.secret.conf
new file mode 100644
index 000000000..b81bb817f
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-auditor/taler/secrets/auditor-db.secret.conf
@@ -0,0 +1,10 @@
+# Database configuration for the Taler auditor.
+
+[auditordb-postgres]
+
+# Typically, there should only be a single line here, of the form:
+
+CONFIG=postgres:///DATABASE
+
+# The details of the URI depend on where the database lives and how
+# access control was configured.
diff --git a/contrib/packages/fedora/etc-taler-exchange/apache2/sites-available/taler-exchange.conf b/contrib/packages/fedora/etc-taler-exchange/apache2/sites-available/taler-exchange.conf
new file mode 100644
index 000000000..3ec14feb2
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/apache2/sites-available/taler-exchange.conf
@@ -0,0 +1,4 @@
+<Location "/taler-exchange/">
+ProxyPass "unix:/run/taler/exchange-httpd/exchange-http.sock|http://example.com/"
+RequestHeader add "X-Forwarded-Proto" "https"
+</Location>
diff --git a/contrib/packages/fedora/etc-taler-exchange/nginx/sites-available/taler-exchange b/contrib/packages/fedora/etc-taler-exchange/nginx/sites-available/taler-exchange
new file mode 100644
index 000000000..9b61a32df
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/nginx/sites-available/taler-exchange
@@ -0,0 +1,17 @@
+server {
+ listen 80;
+ listen [::]:80;
+
+ server_name localhost;
+
+ access_log /var/log/nginx/exchange.log;
+ error_log /var/log/nginx/exchange.err;
+
+ location /taler-exchange/ {
+ proxy_pass http://unix:/run/taler/exchange-httpd/exchange-http.sock:/;
+ proxy_redirect off;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-Host "localhost";
+ #proxy_set_header X-Forwarded-Proto "https";
+ }
+}
diff --git a/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-business.conf b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-business.conf
new file mode 100644
index 000000000..d5938f2b1
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-business.conf
@@ -0,0 +1,50 @@
+# Configuration for business-level aspects of the exchange.
+
+[exchange]
+
+# Here you MUST add the master public key of the offline system
+# which you can get using `taler-exchange-offline setup`.
+# This is just an example, your key will be different!
+# MASTER_PUBLIC_KEY = YE6Q6TR1EDB7FD0S68TGDZGF1P0GHJD2S0XVV8R2S62MYJ6HJ4ZG
+# MASTER_PUBLIC_KEY =
+
+# Publicly visible base URL of the exchange.
+# BASE_URL = https://example.com/
+# BASE_URL =
+
+# Here you MUST configure the amount above which transactions are
+# always subject to manual AML review.
+# AML_THRESHOLD =
+
+# Attribute encryption key for storing attributes encrypted
+# in the database. Should be a high-entropy nonce.
+ATTRIBUTE_ENCRYPTION_KEY = SET_ME_PLEASE
+
+# For your terms of service and privacy policy, you should specify
+# an Etag that must be updated whenever there are significant
+# changes to either document. The format is up to you, what matters
+# is that the value is updated and never re-used. See the HTTP
+# specification on Etags.
+# TERMS_ETAG =
+# PRIVACY_ETAG =
+
+SERVE = unix
+UNIXPATH_MODE = 666
+
+# Bank accounts used by the exchange should be specified here:
+[exchange-account-1]
+
+ENABLE_CREDIT = NO
+ENABLE_DEBIT = NO
+
+# Account identifier in the form of an RFC-8905 payto:// URI.
+# For SEPA, looks like payto://sepa/$IBAN?receiver-name=$NAME
+# Make sure to URL-encode spaces in $NAME!
+PAYTO_URI =
+
+# Credentials to access the account are in a separate
+# config file with restricted permissions.
+@inline-secret@ exchange-accountcredentials-1 ../secrets/exchange-accountcredentials-1.secret.conf
+
+
+
diff --git a/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-coins.conf b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-coins.conf
new file mode 100644
index 000000000..8294525cb
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-coins.conf
@@ -0,0 +1,33 @@
+#
+# This configuration file specifies the various denominations offered by your
+# exchange.
+#
+# Each denomination must be specified in a sections starting with
+# "coin_".
+#
+# What follows is an example.
+#
+
+# [coin_FOO]
+## Actual value of the coin
+#VALUE = KUDOS:1
+
+## How long will one key be used for withdrawals?
+#DURATION_WITHDRAW = 7 days
+
+## How long do users have to spend their coins?
+#DURATION_SPEND = 2 years
+
+## How long does the exchange keep the proofs around for legal disputes?
+#DURATION_LEGAL = 6 years
+
+## Fees charged. Note that for the lowest denomination, the
+## fee must precisely be the lowest denomination, or zero.
+#FEE_WITHDRAW = KUDOS:0
+#FEE_DEPOSIT = KUDOS:0
+#FEE_REFRESH = KUDOS:0
+#FEE_REFUND = KUDOS:0
+
+## How long should the RSA keys be. Do not change unless you really know
+## what you are doing (consult your local cryptographer first!).
+#RSA_KEYSIZE = 2048
diff --git a/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-system.conf b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-system.conf
new file mode 100644
index 000000000..4ad7e06f6
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/taler/conf.d/exchange-system.conf
@@ -0,0 +1,13 @@
+# Configuration settings for system parameters of the exchange.
+
+# Read secret sections into configuration, but only
+# if we have permission to do so.
+@inline-secret@ exchangedb-postgres ../secrets/exchange-db.secret.conf
+
+[exchange]
+
+# Only supported database is Postgres right now.
+DATABASE = postgres
+
+
+
diff --git a/debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials.secret.conf b/contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf
index 8c8d14320..8c8d14320 100644
--- a/debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials.secret.conf
+++ b/contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf
diff --git a/contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-db.secret.conf b/contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-db.secret.conf
new file mode 100644
index 000000000..a7a727b62
--- /dev/null
+++ b/contrib/packages/fedora/etc-taler-exchange/taler/secrets/exchange-db.secret.conf
@@ -0,0 +1,10 @@
+# Database configuration for the Taler exchange.
+
+[exchangedb-postgres]
+
+# Typically, there should only be a single line here, of the form:
+
+# CONFIG=postgres:///DATABASE
+
+# The details of the URI depend on where the database lives and how
+# access control was configured.
diff --git a/contrib/packages/fedora/taler-auditor.taler-auditor-httpd.service b/contrib/packages/fedora/taler-auditor.taler-auditor-httpd.service
new file mode 100644
index 000000000..9aefab641
--- /dev/null
+++ b/contrib/packages/fedora/taler-auditor.taler-auditor-httpd.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=GNU Taler payment system auditor REST API
+After=postgres.service network.target
+
+[Service]
+User=taler-auditor-httpd
+Type=simple
+Restart=on-failure
+ExecStart=/usr/bin/taler-auditor-httpd -c /etc/taler/taler.conf
+
+[Install]
+WantedBy=multi-user.target
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator.service b/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator.service
new file mode 100644
index 000000000..246cad5c1
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange aggregator service
+PartOf=taler-exchange.target
+After=postgres.service
+
+[Service]
+User=taler-exchange-aggregator
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator@.service b/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator@.service
new file mode 100644
index 000000000..bfc44a9a9
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-aggregator@.service
@@ -0,0 +1,17 @@
+[Unit]
+Description=GNU Taler payment system exchange aggregator service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-aggregator
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-closer.service b/contrib/packages/fedora/taler-exchange.taler-exchange-closer.service
new file mode 100644
index 000000000..97a385c13
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-closer.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange closer service
+PartOf=taler-exchange.target
+After=network.target postgres.service
+
+[Service]
+User=taler-exchange-closer
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-closer -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-expire.service b/contrib/packages/fedora/taler-exchange.taler-exchange-expire.service
new file mode 100644
index 000000000..250f210fe
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-expire.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange expire service
+PartOf=taler-exchange.target
+After=postgres.service
+
+[Service]
+User=taler-exchange-expire
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-expire -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-httpd.service b/contrib/packages/fedora/taler-exchange.taler-exchange-httpd.service
new file mode 100644
index 000000000..3671bdc7d
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-httpd.service
@@ -0,0 +1,33 @@
+[Unit]
+Description=GNU Taler payment system exchange REST API
+AssertPathExists=/run/taler/exchange-httpd
+Requires=taler-exchange-httpd.socket taler-exchange-secmod-cs.service taler-exchange-secmod-rsa.service taler-exchange-secmod-eddsa.service
+After=postgres.service network.target taler-exchange-secmod-cs.service taler-exchange-secmod-rsa.service taler-exchange-secmod-eddsa.service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-httpd
+Type=simple
+
+# Depending on the configuration, the service process kills itself and then
+# needs to be restarted. Thus no significant delay on restarts.
+Restart=always
+RestartSec=1ms
+
+# Disable the service if more than 5 restarts are encountered within 5s.
+# These are usually the systemd defaults, but can be overwritten, thus we set
+# them here explicitly, as the exchange code assumes StartLimitInterval
+# to be >=5s.
+StartLimitBurst=5
+StartLimitInterval=5s
+
+ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=no
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+
+[Install]
+WantedBy=multi-user.target
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-httpd@.service b/contrib/packages/fedora/taler-exchange.taler-exchange-httpd@.service
new file mode 100644
index 000000000..e0246899c
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-httpd@.service
@@ -0,0 +1,27 @@
+% This is a systemd service template.
+[Unit]
+Description=GNU Taler payment system exchange REST API at %I
+AssertPathExists=/run/taler/exchange-httpd
+Requires=taler-exchange-httpd@%i.socket taler-exchange-secmod-rsa.service taler-exchange-secmod-eddsa.service
+After=postgres.service network.target taler-exchange-secmod-rsa.service taler-exchange-secmod-eddsa.service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-httpd
+Type=simple
+# Depending on the configuration, the service suicides and then
+# needs to be restarted.
+Restart=always
+# Do not dally on restarts.
+RestartSec=1ms
+EnvironmentFile=/etc/environment
+ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=no
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+
+[Install]
+WantedBy=multi-user.target
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-cs.service b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-cs.service
new file mode 100644
index 000000000..3b5e0745d
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-cs.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange CS security module
+AssertPathExists=/run/taler/exchange-secmod-cs
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-secmod-cs
+Type=simple
+Restart=always
+RestartSec=100ms
+ExecStart=/usr/bin/taler-exchange-secmod-cs -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=no
+PrivateDevices=yes
+ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-eddsa.service b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-eddsa.service
new file mode 100644
index 000000000..e8fba1736
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-eddsa.service
@@ -0,0 +1,19 @@
+[Unit]
+Description=GNU Taler payment system exchange EdDSA security module
+AssertPathExists=/run/taler/exchange-secmod-eddsa
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-secmod-eddsa
+Type=simple
+Restart=always
+RestartSec=100ms
+ExecStart=/usr/bin/taler-exchange-secmod-eddsa -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=no
+PrivateDevices=yes
+ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
+
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-rsa.service b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-rsa.service
new file mode 100644
index 000000000..10a9585a7
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-secmod-rsa.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange RSA security module
+AssertPathExists=/run/taler/exchange-secmod-rsa
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-secmod-rsa
+Type=simple
+Restart=always
+RestartSec=100ms
+ExecStart=/usr/bin/taler-exchange-secmod-rsa -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=no
+PrivateDevices=yes
+ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-transfer.service b/contrib/packages/fedora/taler-exchange.taler-exchange-transfer.service
new file mode 100644
index 000000000..e26af20d0
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-transfer.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=Taler Exchange Transfer Service
+After=network.target postgres.service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-wire
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-transfer -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch.service b/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch.service
new file mode 100644
index 000000000..7b74737b7
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange wirewatch service
+After=network.target postgres.service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-wire
+Type=simple
+Restart=always
+RestartSec=1s
+RuntimeMaxSec=3600s
+ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
diff --git a/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch@.service b/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch@.service
new file mode 100644
index 000000000..85bb9268b
--- /dev/null
+++ b/contrib/packages/fedora/taler-exchange.taler-exchange-wirewatch@.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=GNU Taler payment system exchange wirewatch service
+After=network.target
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-wire
+Type=simple
+Restart=always
+RestartSec=1s
+ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/contrib/persona-exchange-unauthorized.en.must b/contrib/persona-exchange-unauthorized.en.must
new file mode 100644
index 000000000..9b4858178
--- /dev/null
+++ b/contrib/persona-exchange-unauthorized.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC server refused access</title>
+</head>
+<body>
+The KYC backend refused the authorization code used by the exchange operator. Please inform the exchange operator about this failure.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-exchange-unpaid.en.must b/contrib/persona-exchange-unpaid.en.must
new file mode 100644
index 000000000..65fa4f9b7
--- /dev/null
+++ b/contrib/persona-exchange-unpaid.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC credit exhausted</title>
+</head>
+<body>
+The KYC backend refused the process as the exchange operator's credit balance at the KYC provider is insufficient. Please inform the exchange operator about this failure.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-invalid-response.en.must b/contrib/persona-invalid-response.en.must
new file mode 100644
index 000000000..a288ae074
--- /dev/null
+++ b/contrib/persona-invalid-response.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC provider returned unexpected response</title>
+</head>
+<body>
+The KYC backend returned an unexpected response.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-kyc-failed.en.must b/contrib/persona-kyc-failed.en.must
new file mode 100644
index 000000000..c1e27a821
--- /dev/null
+++ b/contrib/persona-kyc-failed.en.must
@@ -0,0 +1,20 @@
+<html>
+<head>
+<title>KYC authentication failed</title>
+</head>
+<body>
+You failed the KYC check. See below for details.
+<!-- {{kyc_logic}} indicates the type of KYC provider
+ which generated the reply; for now, only
+ "kycaid" is possible. Switch on the
+ {{kyc_logic}} to render results in a provider-specific
+ way. (or introduce new templates per provider?) -->
+<!-- TODO: figure out exactly what the
+ format of 'verifications' is here
+ based on KYCAID documentation and parse
+ that here. -->
+<pre>
+{{ verifications }}
+</pre>
+</body>
+</html> \ No newline at end of file
diff --git a/contrib/persona-load-failure.en.must b/contrib/persona-load-failure.en.must
new file mode 100644
index 000000000..77917c0b3
--- /dev/null
+++ b/contrib/persona-load-failure.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC provider rate limit reached</title>
+</head>
+<body>
+The KYC backend interaction ran into a rate limit.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-logic-failure.en.must b/contrib/persona-logic-failure.en.must
new file mode 100644
index 000000000..504cd09c9
--- /dev/null
+++ b/contrib/persona-logic-failure.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC server interaction failed</title>
+</head>
+<body>
+The KYC backend returned a response indicating a problem with the exchange logic. Please inform the exchange operator about this failure.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-network-timeout.en.must b/contrib/persona-network-timeout.en.must
new file mode 100644
index 000000000..c1ad79b34
--- /dev/null
+++ b/contrib/persona-network-timeout.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC provider timeout</title>
+</head>
+<body>
+The KYC backend interaction ran into a timeout.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/persona-provider-failure.en.must b/contrib/persona-provider-failure.en.must
new file mode 100644
index 000000000..37d1e0f3a
--- /dev/null
+++ b/contrib/persona-provider-failure.en.must
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>KYC provider had an internal error</title>
+</head>
+<body>
+The KYC backend had an internal error.
+<pre>
+{{ kyc_http_status }}
+{{ kyc_logic }}
+{{ kyc_server_reply }}
+</pre>
+</body>
+</html>
diff --git a/contrib/pp/.gitignore b/contrib/pp/.gitignore
deleted file mode 100644
index fb83616eb..000000000
--- a/contrib/pp/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-sphinx.err
-sphinx.log
-_build/
diff --git a/contrib/pp/Makefile b/contrib/pp/Makefile
deleted file mode 100644
index ab29543cb..000000000
--- a/contrib/pp/Makefile
+++ /dev/null
@@ -1,109 +0,0 @@
-# Makefile for Sphinx documentation
-#
-# You can set these variables from the command line.
-SPHINXOPTS =
-SPHINXBUILD = sphinx-build
-PAPER =
-BUILDDIR = _build
-
-# User-friendly check for sphinx-build
-ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
-$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
-endif
-
-# Internal variables.
-PAPEROPT_a4 = -D latex_paper_size=a4
-PAPEROPT_letter = -D latex_paper_size=letter
-ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
-# the i18n builder cannot share the environment and doctrees with the others
-I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
-
-.PHONY: help clean html json epub latex latexpdf text man doctest gettext
-
-help:
- @echo "Please use \`make <target>' where <target> is one of"
- @echo " html to make a single large HTML file"
- @echo " json to make JSON files"
- @echo " epub to make an epub"
- @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
- @echo " pdf to make LaTeX files and run them through pdflatex"
- @echo " txt to make text files"
- @echo " man to make manual pages"
- @echo " texinfo to make Texinfo files"
- @echo " info to make Texinfo files and run them through makeinfo"
- @echo " gettext to make PO message catalogs"
- @echo " xml to make Docutils-native XML files"
- @echo " pseudoxml to make pseudoxml-XML files for display purposes"
- @echo " doctest to run all doctests embedded in the documentation (if enabled)"
-
-clean:
- rm -rf $(BUILDDIR)/*
-
-
-# The html-linked builder does not support caching, so we
-# remove all cached state first.
-html:
- $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
- @echo
- @echo "Build finished. The HTML page is in $(BUILDDIR)/html."
-
-json:
- $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
- @echo
- @echo "Build finished; now you can process the JSON files."
-
-epub:
- $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
- @echo
- @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
-
-latex:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
- @echo
- @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
- @echo "Run \`make' in that directory to run these through (pdf)latex" \
- "(use \`make latexpdf' here to do that automatically)."
-
-pdf:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/pdf
- @echo "Running LaTeX files through pdflatex..."
- $(MAKE) -C $(BUILDDIR)/pdf all-pdf
- @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/pdf."
-
-txt:
- $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/txt
- @echo
- @echo "Build finished. The text files are in $(BUILDDIR)/txt."
-
-man:
- $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
- @echo
- @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
-
-texinfo:
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
- @echo
- @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
- @echo "Run \`make' in that directory to run these through makeinfo" \
- "(use \`make info' here to do that automatically)."
-
-info:
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/info
- @echo "Running Texinfo files through makeinfo..."
- make -C $(BUILDDIR)/texinfo info
- @echo "makeinfo finished; the Info files are in $(BUILDDIR)/info."
-
-gettext:
- $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
- @echo
- @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
-
-doctest:
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
- @echo "Testing of doctests in the sources finished, look at the " \
- "results in $(BUILDDIR)/doctest/output.txt."
-
-xml:
- $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
- @echo
- @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
diff --git a/contrib/pp/README b/contrib/pp/README
deleted file mode 100644
index 17a17c584..000000000
--- a/contrib/pp/README
+++ /dev/null
@@ -1,58 +0,0 @@
-This directory contains the privacy policy (template) for exchange
-operators.
-
-
-Dependencies
-============
-
-Generating a new Privacy Policy requires Sphinx, LaTeX with babel
-packages for all supported languages. On Debian, you should
-at least install:
-
-$ apt install python3-sphinx sphinx-intl texlive-lang-german texlive-lang-english latexmk texlive-latex-recommended texlive-latex-extra
-
-(NOTE: List may be incomplete.)
-
-
-Updating the Privacy Policy
-===========================
-
-The master file with the Privacy Policy is 'pp.rst'.
-
-If you make substantial changes, you MUST change the "PP_VERSION"
-in contrib/Makefile.am to the new Etag.
-
-To begin the translation into other languages after editing the master
-file, run
-
-$ make gettext
-
-to generate the master PO file. Then, run
-
-$ sphinx-intl update -p _build/locale/ -l de -l fr -l it
-
-to update the PO files for the various languages (extend the list of
-languages as necessary). The PO files for the translators are kept
-at locale/$LANG/LC_MESSAGES/pp.po for the language $LANG.
-
-Once all PO files have been updated with new translations, run
-
-$ make update-pp
-
-in the "contrib/" directory to generate all of the formats. The
-respective make rule calls the '../update-pp.sh' script in the
-contrib/ directory, which calls the 'Makefile' in the pp/
-directory for the various supported languages and file formats
-and then moves the generated files to the target directory
-('contrib/pp/$LANG/$VERSION.$FORMAT')
-
-
-Adding a new language
-=====================
-
-To add a new language $LANG, add $LANG to "PP_LANGUAGES" in
-'contrib/Makefile.am' and run
-
-$ sphinx-intl update -p _build/gettext -l $LANG
-
-to generate the PO template.
diff --git a/contrib/pp/conf.py b/contrib/pp/conf.py
deleted file mode 100644
index 9acb9786a..000000000
--- a/contrib/pp/conf.py
+++ /dev/null
@@ -1,282 +0,0 @@
-"""
- This file is part of GNU TALER.
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-
- @author Florian Dold
- @author Benedikt Muller
- @author Sree Harsha Totakura
- @author Marcello Stanisci
-"""
-# -*- coding: utf-8 -*-
-#
-# neuro documentation build configuration file, created by
-# sphinx-quickstart on Sat May 31 13:11:06 2014.
-#
-# This file is execfile()d with the current directory set to its
-# containing dir.
-#
-# Note that not all possible configuration values are present in this
-# autogenerated file.
-#
-# All configuration values have a default; values that are commented out
-# serve to show the default.
-
-import sys
-import os
-
-sys.path.append(os.path.abspath('_exts'))
-
-#import taler_sphinx_theme
-
-# If extensions (or modules to document with autodoc) are in another directory,
-# add these directories to sys.path here. If the directory is relative to the
-# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
-
-# -- General configuration ------------------------------------------------
-
-# If your documentation needs a minimal Sphinx version, state it here.
-needs_sphinx = '1.8.5'
-
-# Add any Sphinx extension module names here, as strings. They can be
-# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
-# ones.
-extensions = [
- 'sphinx.ext.todo',
- 'sphinx.ext.imgmath',
-]
-
-# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
-
-source_suffix = {
- '.rst': 'restructuredtext',
-}
-
-# The encoding of source files.
-#source_encoding = 'utf-8-sig'
-
-# The master toctree document.
-master_doc = 'pp'
-
-# General information about the project.
-project = u'pp'
-copyright = u'2014-2020 Taler Systems SA (GPLv3+ or GFDL 1.3+)'
-
-# The version info for the project you're documenting, acts as replacement for
-# |version| and |release|, also used in various other places throughout the
-# built documents.
-#
-# The short X.Y version.
-version = '0'
-# The full version, including alpha/beta/rc tags.
-release = '0'
-
-# The language for content autogenerated by Sphinx. Refer to documentation
-# for a list of supported languages.
-# language = "en de"
-
-# There are two options for replacing |today|: either, you set today to some
-# non-false value, then it is used:
-#today = ''
-# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
-
-# List of patterns, relative to source directory, that match files and
-# directories to ignore when looking for source files.
-exclude_patterns = ['_build', '_exts', 'cf', 'prebuilt']
-
-# The reST default role (used for this markup: `text`) to use for all
-# documents.
-# default_role = "ts:type"
-
-locale_dirs = ['locale/']
-gettext_compact = False
-
-# If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
-
-# If true, the current module name will be prepended to all description
-# unit titles (such as .. function::).
-#add_module_names = True
-
-# If true, sectionauthor and moduleauthor directives will be shown in the
-# output. They are ignored by default.
-#show_authors = False
-
-# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
-
-# A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
-
-# If true, keep warnings as "system message" paragraphs in the built documents.
-#keep_warnings = False
-
-# -- Options for HTML output ----------------------------------------------
-
-# The theme to use for HTML and HTML Help pages. See the documentation for
-# a list of builtin themes.
-html_theme = 'epub'
-
-#html_theme_path = taler_sphinx_theme.html_theme_path()
-
-#html_sidebars = {'**': ['logo-text.html', 'globaltoc.html', 'searchbox.html']}
-
-rst_epilog = ""
-
-html_show_sphinx = False
-
-html_theme_options = {
- # Set the name of the project to appear in the sidebar
- "relbar1": "false",
- "footer": "false",
-}
-
-# Add any paths that contain custom themes here, relative to this directory.
-#html_theme_path = []
-
-# The name for this set of Sphinx documents. If None, it defaults to
-# "<project> v<release> documentation".
-html_title = "Taler Privacy Policy"
-
-# A shorter title for the navigation bar. Default is the same as html_title.
-html_short_title = "Privacy Policy"
-
-# The name of an image file (relative to this directory) to place at the top
-# of the sidebar.
-#html_logo = None
-
-# The name of an image file (within the static path) to use as favicon of the
-# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
-# pixels large.
-#html_favicon = None
-
-# Add any paths that contain custom static files (such as style sheets) here,
-# relative to this directory. They are copied after the builtin static files,
-# so a file named "default.css" will overwrite the builtin "default.css".
-# html_static_path = ['_static']
-
-# Add any extra paths that contain custom files (such as robots.txt or
-# .htaccess) here, relative to this directory. These files are copied
-# directly to the root of the documentation.
-#html_extra_path = []
-
-# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
-# using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
-
-# If true, SmartyPants will be used to convert quotes and dashes to
-# typographically correct entities.
-#html_use_smartypants = True
-
-# Custom sidebar templates, maps document names to template names.
-#html_sidebars = {}
-
-# Additional templates that should be rendered to pages, maps page names to
-# template names.
-#html_additional_pages = {}
-
-# If false, no module index is generated.
-#html_domain_indices = True
-
-# If false, no index is generated.
-#html_use_index = True
-
-# If true, the index is split into individual pages for each letter.
-#html_split_index = False
-
-# If true, links to the reST sources are added to the pages.
-#html_show_sourcelink = True
-
-# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
-html_show_sphinx = False
-
-# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
-#html_show_copyright = True
-
-# If true, an OpenSearch description file will be output, and all pages will
-# contain a <link> tag referring to it. The value of this option must be the
-# base URL from which the finished HTML is served.
-#html_use_opensearch = ''
-
-# This is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = None
-
-# -- Options for LaTeX output ---------------------------------------------
-
-latex_elements = {
- # The paper size ('letterpaper' or 'a4paper').
- #'papersize': 'letterpaper',
-
- # The font size ('10pt', '11pt' or '12pt').
- #'pointsize': '10pt',
-
- # Additional stuff for the LaTeX preamble.
- #'preamble': '',
-}
-
-# Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title,
-# author, documentclass [howto, manual, or own class]).
-latex_documents = [
- ('pp', 'pp.tex',
- 'Privacy Policy', 'GNU Taler team', 'manual'),
-]
-
-# The name of an image file (relative to this directory) to place at the top of
-# the title page.
-#latex_logo = None
-
-# For "manual" documents, if this is true, then toplevel headings are parts,
-# not chapters.
-#latex_use_parts = False
-
-# If true, show page references after internal links.
-#latex_show_pagerefs = False
-
-# If true, show URL addresses after external links.
-#latex_show_urls = False
-
-# Documents to append as an appendix to all manuals.
-# latex_appendices = ["fdl-1.3"]
-
-# If false, no module index is generated.
-#latex_domain_indices = True
-
-# -- Options for manual page output ---------------------------------------
-
-# If true, show URL addresses after external links.
-#man_show_urls = False
-
-# -- Options for Texinfo output -------------------------------------------
-
-# Documents to append as an appendix to all manuals.
-#texinfo_appendices = []
-
-# If false, no module index is generated.
-#texinfo_domain_indices = True
-
-# How to display URL addresses: 'footnote', 'no', or 'inline'.
-#texinfo_show_urls = 'footnote'
-
-# If true, do not generate a @detailmenu in the "Top" node's menu.
-#texinfo_no_detailmenu = False
-
-
-# -- Options for epub output ----------------------------
-
-epub_basename = "pp"
-
-epub_title = "Privacy Policy"
diff --git a/contrib/pp/en/0.epub b/contrib/pp/en/0.epub
deleted file mode 100644
index 7e9e5343c..000000000
--- a/contrib/pp/en/0.epub
+++ /dev/null
Binary files differ
diff --git a/contrib/pp/en/0.html b/contrib/pp/en/0.html
deleted file mode 100644
index ce7045350..000000000
--- a/contrib/pp/en/0.html
+++ /dev/null
@@ -1,211 +0,0 @@
-
-
-<html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Privacy Policy &#8212; Taler Privacy Policy</title>
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
- <link rel="stylesheet" href="_static/epub.css" type="text/css" />
- <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
- <script src="_static/jquery.js"></script>
- <script src="_static/underscore.js"></script>
- <script src="_static/doctools.js"></script>
- </head><body>
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="privacy-policy">
-<h1>Privacy Policy<a class="headerlink" href="#privacy-policy" title="Permalink to this headline">¶</a></h1>
-<p>Last Updated: 11.12.2019</p>
-<p>This Privacy Policy describes the policies and procedures of Taler Systems SA
-(“we,” “our,” or “us”) pertaining to the collection, use, and disclosure of
-your information on our sites and related mobile applications and products we
-offer (the “Services” or “Taler Wallet”). This Privacy Statement applies to
-your personal data when you use our Services, and does not apply to online
-websites or services that we do not own or control.</p>
-<div class="section" id="overview">
-<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
-<p>Your privacy is important to us. We follow a few fundamental principles: We
-don’t ask you for personally identifiable information (defined below). That
-being said, your contact information, such as your phone number, social media
-handle, or email address (depending on how you contact us), may be collected
-when you communicate with us, for example to report a bug or other error
-related to the Taler Wallet. We don’t share your information with third
-parties except when strictly required to deliver you our Services and
-products, or to comply with the law. If you have any questions or concerns
-about this policy, please reach out to us at <a class="reference external" href="mailto:privacy&#37;&#52;&#48;taler-systems&#46;net">privacy<span>&#64;</span>taler-systems<span>&#46;</span>net</a>.</p>
-</div>
-<div class="section" id="how-you-accept-this-policy">
-<h2>How you accept this policy<a class="headerlink" href="#how-you-accept-this-policy" title="Permalink to this headline">¶</a></h2>
-<p>By using our Services or visiting our sites, you agree to the use, disclosure,
-and procedures outlined in this Privacy Policy.</p>
-</div>
-<div class="section" id="what-personal-information-do-we-collect-from-our-users">
-<h2>What personal information do we collect from our users?<a class="headerlink" href="#what-personal-information-do-we-collect-from-our-users" title="Permalink to this headline">¶</a></h2>
-<p>The information we collect from you falls into two categories: (i) personally
-identifiable information (i.e., data that could potentially identify you as an
-individual) (“Personal Information”), and (ii) non-personally identifiable
-information (i.e., information that cannot be used to identify who you are)
-(“Non-Personal Information”). This Privacy Policy covers both categories and
-will tell you how we might collect and use each type.</p>
-<p>We do our best to not collect any Personal Information from Taler Wallet
-users. We believe that the Taler Wallet never transmits personal information
-to our services without at least clear implied consent, and we only process
-and retain information with a strict business need. That being said, when
-using our Services, we inherently have to collect the following information:</p>
-<blockquote>
-<div><ul class="simple">
-<li><p>Bank account details necessary when receiving funds from you to top-up your wallet or to transfer funds to you when you are being paid via Taler. At the current experimental stage, only the pseudonym and password you entered in the bank demonstrator is stored.</p></li>
-<li><p>The amounts being withdrawn or deposited, with associated unique transaction identifiers and cryptographic signatures authorizing the transaction. Note that for purchases, we cannot identify the buyer from the collected data, so when you spend money, we only receive non-personal information.</p></li>
-<li><p>When you contact us. We may collect certain information if you choose to contact us, for example to report a bug or other error with the Taler Wallet. This may include contact information such as your name, email address or phone number depending on the method you choose to contact us.</p></li>
-</ul>
-</div></blockquote>
-</div>
-<div class="section" id="how-we-collect-and-process-information">
-<h2>How we collect and process information<a class="headerlink" href="#how-we-collect-and-process-information" title="Permalink to this headline">¶</a></h2>
-<p>We may process your information for the following reasons:</p>
-<blockquote>
-<div><ul class="simple">
-<li><p>to transfer money as specified by our users (Taler transactions);</p></li>
-<li><p>to assist government entities in linking income to the underlying contract as required by law and local regulations</p></li>
-<li><p>to support you using the Taler Wallet or to improve our Services</p></li>
-</ul>
-</div></blockquote>
-</div>
-<div class="section" id="how-we-share-and-use-the-information-we-gather">
-<h2>How we share and use the information we gather<a class="headerlink" href="#how-we-share-and-use-the-information-we-gather" title="Permalink to this headline">¶</a></h2>
-<p>We may share your Personal Data or other information about you only if you are
-a merchant receiving income, with your bank, to the degree necessary to
-execute the payment.</p>
-<p>We retain Personal Data to transfer funds to the accounts designated by our
-users. We may retain Personal Data only for as long as mandated by law and
-required for the wire transfers.</p>
-<p>We primarily use the limited information we receive directly from you to
-enhance the Taler Wallet. Some ways we may use your Personal Information are
-to: Contact you when necessary to respond to your comments, answer your
-questions, or obtain additional information on issues related to bugs or
-errors with the Taler Wallet that you reported.</p>
-</div>
-<div class="section" id="agents-or-third-party-partners">
-<h2>Agents or third party partners<a class="headerlink" href="#agents-or-third-party-partners" title="Permalink to this headline">¶</a></h2>
-<p>We may provide your Personal Information to our employees, contractors,
-agents, service providers, and designees (“Agents”) to enable them to perform
-certain services for us exclusively, including: improvement and maintenance of
-our software and Services.</p>
-</div>
-<div class="section" id="protection-of-us-and-others">
-<h2>Protection of us and others<a class="headerlink" href="#protection-of-us-and-others" title="Permalink to this headline">¶</a></h2>
-<p>We reserve the right to access, read, preserve, and disclose any information
-that we reasonably believe is necessary to comply with the law or a court
-order.</p>
-</div>
-<div class="section" id="what-personal-information-can-i-access-or-change">
-<h2>What personal information can I access or change?<a class="headerlink" href="#what-personal-information-can-i-access-or-change" title="Permalink to this headline">¶</a></h2>
-<p>You can request access to the information we have collected from you. You can
-do this by contacting us at <a class="reference external" href="mailto:privacy&#37;&#52;&#48;taler-systems&#46;net">privacy<span>&#64;</span>taler-systems<span>&#46;</span>net</a>. We will make sure to
-provide you with a copy of the data we process about you. To comply with your
-request, we may ask you to verify your identity. We will fulfill your request
-by sending your copy electronically. For any subsequent access request, we may
-charge you with an administrative fee. If you believe that the information we
-have collected is incorrect, you are welcome to contact us so we can update it
-and keep your data accurate. Any data that is no longer needed for purposes
-specified in the “How We Use the Information We Gather” section will be
-deleted after ninety (90) days.</p>
-</div>
-<div class="section" id="what-are-your-data-protection-rights">
-<h2>What are your data protection rights?<a class="headerlink" href="#what-are-your-data-protection-rights" title="Permalink to this headline">¶</a></h2>
-<p>Anastasis would like to make sure you are fully aware of all of your
-data protection rights. Every user is entitled to the following:</p>
-<dl class="simple">
-<dt><strong>The right to access</strong>: You have the right to request Anastasis for</dt><dd><p>copies of your personal data. We may charge you a small fee for this
-service.</p>
-</dd>
-</dl>
-<p><strong>The right to rectification</strong>: You have the right to request that
-Anastasis correct any information you believe is inaccurate. You also
-have the right to request Anastasis to complete information you
-believe is incomplete. The right to erasure - You have the right to
-request that Anastasis erase your personal data, under certain
-conditions.</p>
-<dl class="simple">
-<dt><strong>The right to restrict processing</strong>: You have the right to request</dt><dd><p>that Anastasis restrict the processing of your personal data, under
-certain conditions.</p>
-</dd>
-<dt><strong>The right to object to processing</strong>: You have the right to object to</dt><dd><p>Anastasis’s processing of your personal data, under certain
-conditions.</p>
-</dd>
-<dt><strong>The right to data portability</strong>: You have the right to request that</dt><dd><p>Anastasis transfer the data that we have collected to another
-organization, or directly to you, under certain conditions.</p>
-</dd>
-</dl>
-<p>If you make a request, we have one month to respond to you. If you
-would like to exercise any of these rights, please contact us at our
-email: <a class="reference external" href="mailto:privacy&#37;&#52;&#48;taler-systems&#46;com">privacy<span>&#64;</span>taler-systems<span>&#46;</span>com</a></p>
-<p>You can always contact your local data protection authority to enforce
-your rights.</p>
-</div>
-<div class="section" id="data-retention">
-<h2>Data retention<a class="headerlink" href="#data-retention" title="Permalink to this headline">¶</a></h2>
-<p>If you uninstall the Taler Wallet mobile applications from your device, or
-request that your information be deleted, we still may retain some information
-that you have provided to us to maintain the Taler Wallet or to comply with
-relevant laws.</p>
-</div>
-<div class="section" id="data-security">
-<h2>Data security<a class="headerlink" href="#data-security" title="Permalink to this headline">¶</a></h2>
-<p>We are committed to making sure your information is protected. We employ
-several physical and electronic safeguards to keep your information safe,
-including encrypted user passwords, two factor verification and authentication
-on passwords where possible, and securing connections with industry standard
-transport layer security. You are also welcome to contact us using GnuPG
-encrypted e-mail. Even with all these precautions, we cannot fully guarantee
-against the access, disclosure, alteration, or deletion of data through
-events, including but not limited to hardware or software failure or
-unauthorized use. Any information that you provide to us is done so entirely
-at your own risk.</p>
-</div>
-<div class="section" id="changes-and-updates-to-privacy-policy">
-<h2>Changes and updates to privacy policy<a class="headerlink" href="#changes-and-updates-to-privacy-policy" title="Permalink to this headline">¶</a></h2>
-<p>We reserve the right to update and revise this privacy policy at any time. We
-occasionally review this Privacy Policy to make sure it complies with
-applicable laws and conforms to changes in our business. We may need to update
-this Privacy Policy, and we reserve the right to do so at any time. If we do
-revise this Privacy Policy, we will update the “Effective Date” at the bottom
-of this page so that you can tell if it has changed since your last visit. As
-we generally do not collect contact information and also do not track your
-visits, we will not be able to notify you directly. However, the Taler Wallet
-may inform you about a change in the privacy policy once it detects that the
-policy has changed. Please review this Privacy Policy regularly to ensure that
-you are aware of its terms. Any use of our Services after an amendment to our
-Privacy Policy constitutes your acceptance to the revised or amended
-agreement.</p>
-</div>
-<div class="section" id="international-users-and-visitors">
-<h2>International users and visitors<a class="headerlink" href="#international-users-and-visitors" title="Permalink to this headline">¶</a></h2>
-<p>Our Services are hosted in Switzerland. If you are a user accessing the
-Services from the European Union, Asia, US, or any other region with laws or
-regulations governing personal data collection, use, and disclosure that
-differ from Swiss laws, please be advised that through your continued use of
-the Services, which is governed by Swiss law, you are transferring your
-Personal Information to Switzerland and you consent to that transfer.</p>
-</div>
-<div class="section" id="questions">
-<h2>Questions<a class="headerlink" href="#questions" title="Permalink to this headline">¶</a></h2>
-<p>Please contact us at <a class="reference external" href="mailto:privacy&#37;&#52;&#48;taler-systems&#46;net">privacy<span>&#64;</span>taler-systems<span>&#46;</span>net</a> if you have questions about our
-privacy practices that are not addressed in this Privacy Statement.</p>
-</div>
-</div>
-
-
- <div class="clearer"></div>
- </div>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- </body>
-</html> \ No newline at end of file
diff --git a/contrib/pp/en/0.pdf b/contrib/pp/en/0.pdf
deleted file mode 100644
index 842a83066..000000000
--- a/contrib/pp/en/0.pdf
+++ /dev/null
Binary files differ
diff --git a/contrib/pp/en/0.txt b/contrib/pp/en/0.txt
deleted file mode 100644
index d6e42faf6..000000000
--- a/contrib/pp/en/0.txt
+++ /dev/null
@@ -1,237 +0,0 @@
-Privacy Policy
-**************
-
-Last Updated: 11.12.2019
-
-This Privacy Policy describes the policies and procedures of Taler
-Systems SA (“we,” “our,” or “us”) pertaining to the collection, use,
-and disclosure of your information on our sites and related mobile
-applications and products we offer (the “Services” or “Taler Wallet”).
-This Privacy Statement applies to your personal data when you use our
-Services, and does not apply to online websites or services that we do
-not own or control.
-
-
-Overview
-========
-
-Your privacy is important to us. We follow a few fundamental
-principles: We don’t ask you for personally identifiable information
-(defined below). That being said, your contact information, such as
-your phone number, social media handle, or email address (depending on
-how you contact us), may be collected when you communicate with us,
-for example to report a bug or other error related to the Taler
-Wallet. We don’t share your information with third parties except when
-strictly required to deliver you our Services and products, or to
-comply with the law. If you have any questions or concerns about this
-policy, please reach out to us at privacy@taler-systems.net.
-
-
-How you accept this policy
-==========================
-
-By using our Services or visiting our sites, you agree to the use,
-disclosure, and procedures outlined in this Privacy Policy.
-
-
-What personal information do we collect from our users?
-=======================================================
-
-The information we collect from you falls into two categories: (i)
-personally identifiable information (i.e., data that could potentially
-identify you as an individual) (“Personal Information”), and (ii) non-
-personally identifiable information (i.e., information that cannot be
-used to identify who you are) (“Non-Personal Information”). This
-Privacy Policy covers both categories and will tell you how we might
-collect and use each type.
-
-We do our best to not collect any Personal Information from Taler
-Wallet users. We believe that the Taler Wallet never transmits
-personal information to our services without at least clear implied
-consent, and we only process and retain information with a strict
-business need. That being said, when using our Services, we inherently
-have to collect the following information:
-
- * Bank account details necessary when receiving funds from you to
- top-up your wallet or to transfer funds to you when you are being
- paid via Taler. At the current experimental stage, only the
- pseudonym and password you entered in the bank demonstrator is
- stored.
-
- * The amounts being withdrawn or deposited, with associated unique
- transaction identifiers and cryptographic signatures authorizing
- the transaction. Note that for purchases, we cannot identify the
- buyer from the collected data, so when you spend money, we only
- receive non-personal information.
-
- * When you contact us. We may collect certain information if you
- choose to contact us, for example to report a bug or other error
- with the Taler Wallet. This may include contact information such
- as your name, email address or phone number depending on the
- method you choose to contact us.
-
-
-How we collect and process information
-======================================
-
-We may process your information for the following reasons:
-
- * to transfer money as specified by our users (Taler transactions);
-
- * to assist government entities in linking income to the underlying
- contract as required by law and local regulations
-
- * to support you using the Taler Wallet or to improve our Services
-
-
-How we share and use the information we gather
-==============================================
-
-We may share your Personal Data or other information about you only if
-you are a merchant receiving income, with your bank, to the degree
-necessary to execute the payment.
-
-We retain Personal Data to transfer funds to the accounts designated
-by our users. We may retain Personal Data only for as long as mandated
-by law and required for the wire transfers.
-
-We primarily use the limited information we receive directly from you
-to enhance the Taler Wallet. Some ways we may use your Personal
-Information are to: Contact you when necessary to respond to your
-comments, answer your questions, or obtain additional information on
-issues related to bugs or errors with the Taler Wallet that you
-reported.
-
-
-Agents or third party partners
-==============================
-
-We may provide your Personal Information to our employees,
-contractors, agents, service providers, and designees (“Agents”) to
-enable them to perform certain services for us exclusively, including:
-improvement and maintenance of our software and Services.
-
-
-Protection of us and others
-===========================
-
-We reserve the right to access, read, preserve, and disclose any
-information that we reasonably believe is necessary to comply with the
-law or a court order.
-
-
-What personal information can I access or change?
-=================================================
-
-You can request access to the information we have collected from you.
-You can do this by contacting us at privacy@taler-systems.net. We will
-make sure to provide you with a copy of the data we process about you.
-To comply with your request, we may ask you to verify your identity.
-We will fulfill your request by sending your copy electronically. For
-any subsequent access request, we may charge you with an
-administrative fee. If you believe that the information we have
-collected is incorrect, you are welcome to contact us so we can update
-it and keep your data accurate. Any data that is no longer needed for
-purposes specified in the “How We Use the Information We Gather”
-section will be deleted after ninety (90) days.
-
-
-What are your data protection rights?
-=====================================
-
-Anastasis would like to make sure you are fully aware of all of your
-data protection rights. Every user is entitled to the following:
-
-**The right to access**: You have the right to request Anastasis for
- copies of your personal data. We may charge you a small fee for
- this service.
-
-**The right to rectification**: You have the right to request that
-Anastasis correct any information you believe is inaccurate. You also
-have the right to request Anastasis to complete information you
-believe is incomplete. The right to erasure - You have the right to
-request that Anastasis erase your personal data, under certain
-conditions.
-
-**The right to restrict processing**: You have the right to request
- that Anastasis restrict the processing of your personal data, under
- certain conditions.
-
-**The right to object to processing**: You have the right to object to
- Anastasis's processing of your personal data, under certain
- conditions.
-
-**The right to data portability**: You have the right to request that
- Anastasis transfer the data that we have collected to another
- organization, or directly to you, under certain conditions.
-
-If you make a request, we have one month to respond to you. If you
-would like to exercise any of these rights, please contact us at our
-email: privacy@taler-systems.com
-
-You can always contact your local data protection authority to enforce
-your rights.
-
-
-Data retention
-==============
-
-If you uninstall the Taler Wallet mobile applications from your
-device, or request that your information be deleted, we still may
-retain some information that you have provided to us to maintain the
-Taler Wallet or to comply with relevant laws.
-
-
-Data security
-=============
-
-We are committed to making sure your information is protected. We
-employ several physical and electronic safeguards to keep your
-information safe, including encrypted user passwords, two factor
-verification and authentication on passwords where possible, and
-securing connections with industry standard transport layer security.
-You are also welcome to contact us using GnuPG encrypted e-mail. Even
-with all these precautions, we cannot fully guarantee against the
-access, disclosure, alteration, or deletion of data through events,
-including but not limited to hardware or software failure or
-unauthorized use. Any information that you provide to us is done so
-entirely at your own risk.
-
-
-Changes and updates to privacy policy
-=====================================
-
-We reserve the right to update and revise this privacy policy at any
-time. We occasionally review this Privacy Policy to make sure it
-complies with applicable laws and conforms to changes in our business.
-We may need to update this Privacy Policy, and we reserve the right to
-do so at any time. If we do revise this Privacy Policy, we will update
-the “Effective Date” at the bottom of this page so that you can tell
-if it has changed since your last visit. As we generally do not
-collect contact information and also do not track your visits, we will
-not be able to notify you directly. However, the Taler Wallet may
-inform you about a change in the privacy policy once it detects that
-the policy has changed. Please review this Privacy Policy regularly to
-ensure that you are aware of its terms. Any use of our Services after
-an amendment to our Privacy Policy constitutes your acceptance to the
-revised or amended agreement.
-
-
-International users and visitors
-================================
-
-Our Services are hosted in Switzerland. If you are a user accessing
-the Services from the European Union, Asia, US, or any other region
-with laws or regulations governing personal data collection, use, and
-disclosure that differ from Swiss laws, please be advised that through
-your continued use of the Services, which is governed by Swiss law,
-you are transferring your Personal Information to Switzerland and you
-consent to that transfer.
-
-
-Questions
-=========
-
-Please contact us at privacy@taler-systems.net if you have questions
-about our privacy practices that are not addressed in this Privacy
-Statement.
diff --git a/contrib/pp/en/0.xml b/contrib/pp/en/0.xml
deleted file mode 100644
index d4400542c..000000000
--- a/contrib/pp/en/0.xml
+++ /dev/null
@@ -1,214 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd">
-<!-- Generated by Docutils 0.16 -->
-<document source="/research/taler/exchange/contrib/pp/pp.rst">
- <section ids="privacy-policy" names="privacy\ policy">
- <title>Privacy Policy</title>
- <paragraph>Last Updated: 11.12.2019</paragraph>
- <paragraph>This Privacy Policy describes the policies and procedures of Taler Systems SA
- (“we,” “our,” or “us”) pertaining to the collection, use, and disclosure of
- your information on our sites and related mobile applications and products we
- offer (the “Services” or “Taler Wallet”). This Privacy Statement applies to
- your personal data when you use our Services, and does not apply to online
- websites or services that we do not own or control.</paragraph>
- <section ids="overview" names="overview">
- <title>Overview</title>
- <paragraph>Your privacy is important to us. We follow a few fundamental principles: We
- don’t ask you for personally identifiable information (defined below). That
- being said, your contact information, such as your phone number, social media
- handle, or email address (depending on how you contact us), may be collected
- when you communicate with us, for example to report a bug or other error
- related to the Taler Wallet. We don’t share your information with third
- parties except when strictly required to deliver you our Services and
- products, or to comply with the law. If you have any questions or concerns
- about this policy, please reach out to us at <reference refuri="mailto:privacy@taler-systems.net">privacy@taler-systems.net</reference>.</paragraph>
- </section>
- <section ids="how-you-accept-this-policy" names="how\ you\ accept\ this\ policy">
- <title>How you accept this policy</title>
- <paragraph>By using our Services or visiting our sites, you agree to the use, disclosure,
- and procedures outlined in this Privacy Policy.</paragraph>
- </section>
- <section ids="what-personal-information-do-we-collect-from-our-users" names="what\ personal\ information\ do\ we\ collect\ from\ our\ users?">
- <title>What personal information do we collect from our users?</title>
- <paragraph>The information we collect from you falls into two categories: (i) personally
- identifiable information (i.e., data that could potentially identify you as an
- individual) (“Personal Information”), and (ii) non-personally identifiable
- information (i.e., information that cannot be used to identify who you are)
- (“Non-Personal Information”). This Privacy Policy covers both categories and
- will tell you how we might collect and use each type.</paragraph>
- <paragraph>We do our best to not collect any Personal Information from Taler Wallet
- users. We believe that the Taler Wallet never transmits personal information
- to our services without at least clear implied consent, and we only process
- and retain information with a strict business need. That being said, when
- using our Services, we inherently have to collect the following information:</paragraph>
- <block_quote>
- <bullet_list bullet="*">
- <list_item>
- <paragraph>Bank account details necessary when receiving funds from you to top-up your wallet or to transfer funds to you when you are being paid via Taler. At the current experimental stage, only the pseudonym and password you entered in the bank demonstrator is stored.</paragraph>
- </list_item>
- <list_item>
- <paragraph>The amounts being withdrawn or deposited, with associated unique transaction identifiers and cryptographic signatures authorizing the transaction. Note that for purchases, we cannot identify the buyer from the collected data, so when you spend money, we only receive non-personal information.</paragraph>
- </list_item>
- <list_item>
- <paragraph>When you contact us. We may collect certain information if you choose to contact us, for example to report a bug or other error with the Taler Wallet. This may include contact information such as your name, email address or phone number depending on the method you choose to contact us.</paragraph>
- </list_item>
- </bullet_list>
- </block_quote>
- </section>
- <section ids="how-we-collect-and-process-information" names="how\ we\ collect\ and\ process\ information">
- <title>How we collect and process information</title>
- <paragraph>We may process your information for the following reasons:</paragraph>
- <block_quote>
- <bullet_list bullet="*">
- <list_item>
- <paragraph>to transfer money as specified by our users (Taler transactions);</paragraph>
- </list_item>
- <list_item>
- <paragraph>to assist government entities in linking income to the underlying contract as required by law and local regulations</paragraph>
- </list_item>
- <list_item>
- <paragraph>to support you using the Taler Wallet or to improve our Services</paragraph>
- </list_item>
- </bullet_list>
- </block_quote>
- </section>
- <section ids="how-we-share-and-use-the-information-we-gather" names="how\ we\ share\ and\ use\ the\ information\ we\ gather">
- <title>How we share and use the information we gather</title>
- <paragraph>We may share your Personal Data or other information about you only if you are
- a merchant receiving income, with your bank, to the degree necessary to
- execute the payment.</paragraph>
- <paragraph>We retain Personal Data to transfer funds to the accounts designated by our
- users. We may retain Personal Data only for as long as mandated by law and
- required for the wire transfers.</paragraph>
- <paragraph>We primarily use the limited information we receive directly from you to
- enhance the Taler Wallet. Some ways we may use your Personal Information are
- to: Contact you when necessary to respond to your comments, answer your
- questions, or obtain additional information on issues related to bugs or
- errors with the Taler Wallet that you reported.</paragraph>
- </section>
- <section ids="agents-or-third-party-partners" names="agents\ or\ third\ party\ partners">
- <title>Agents or third party partners</title>
- <paragraph>We may provide your Personal Information to our employees, contractors,
- agents, service providers, and designees (“Agents”) to enable them to perform
- certain services for us exclusively, including: improvement and maintenance of
- our software and Services.</paragraph>
- </section>
- <section ids="protection-of-us-and-others" names="protection\ of\ us\ and\ others">
- <title>Protection of us and others</title>
- <paragraph>We reserve the right to access, read, preserve, and disclose any information
- that we reasonably believe is necessary to comply with the law or a court
- order.</paragraph>
- </section>
- <section ids="what-personal-information-can-i-access-or-change" names="what\ personal\ information\ can\ i\ access\ or\ change?">
- <title>What personal information can I access or change?</title>
- <paragraph>You can request access to the information we have collected from you. You can
- do this by contacting us at <reference refuri="mailto:privacy@taler-systems.net">privacy@taler-systems.net</reference>. We will make sure to
- provide you with a copy of the data we process about you. To comply with your
- request, we may ask you to verify your identity. We will fulfill your request
- by sending your copy electronically. For any subsequent access request, we may
- charge you with an administrative fee. If you believe that the information we
- have collected is incorrect, you are welcome to contact us so we can update it
- and keep your data accurate. Any data that is no longer needed for purposes
- specified in the “How We Use the Information We Gather” section will be
- deleted after ninety (90) days.</paragraph>
- </section>
- <section ids="what-are-your-data-protection-rights" names="what\ are\ your\ data\ protection\ rights?">
- <title>What are your data protection rights?</title>
- <paragraph>Anastasis would like to make sure you are fully aware of all of your
- data protection rights. Every user is entitled to the following:</paragraph>
- <definition_list>
- <definition_list_item>
- <term><strong>The right to access</strong>: You have the right to request Anastasis for</term>
- <definition>
- <paragraph>copies of your personal data. We may charge you a small fee for this
- service.</paragraph>
- </definition>
- </definition_list_item>
- </definition_list>
- <paragraph><strong>The right to rectification</strong>: You have the right to request that
- Anastasis correct any information you believe is inaccurate. You also
- have the right to request Anastasis to complete information you
- believe is incomplete. The right to erasure - You have the right to
- request that Anastasis erase your personal data, under certain
- conditions.</paragraph>
- <definition_list>
- <definition_list_item>
- <term><strong>The right to restrict processing</strong>: You have the right to request</term>
- <definition>
- <paragraph>that Anastasis restrict the processing of your personal data, under
- certain conditions.</paragraph>
- </definition>
- </definition_list_item>
- <definition_list_item>
- <term><strong>The right to object to processing</strong>: You have the right to object to</term>
- <definition>
- <paragraph>Anastasis’s processing of your personal data, under certain
- conditions.</paragraph>
- </definition>
- </definition_list_item>
- <definition_list_item>
- <term><strong>The right to data portability</strong>: You have the right to request that</term>
- <definition>
- <paragraph>Anastasis transfer the data that we have collected to another
- organization, or directly to you, under certain conditions.</paragraph>
- </definition>
- </definition_list_item>
- </definition_list>
- <paragraph>If you make a request, we have one month to respond to you. If you
- would like to exercise any of these rights, please contact us at our
- email: <reference refuri="mailto:privacy@taler-systems.com">privacy@taler-systems.com</reference></paragraph>
- <paragraph>You can always contact your local data protection authority to enforce
- your rights.</paragraph>
- </section>
- <section ids="data-retention" names="data\ retention">
- <title>Data retention</title>
- <paragraph>If you uninstall the Taler Wallet mobile applications from your device, or
- request that your information be deleted, we still may retain some information
- that you have provided to us to maintain the Taler Wallet or to comply with
- relevant laws.</paragraph>
- </section>
- <section ids="data-security" names="data\ security">
- <title>Data security</title>
- <paragraph>We are committed to making sure your information is protected. We employ
- several physical and electronic safeguards to keep your information safe,
- including encrypted user passwords, two factor verification and authentication
- on passwords where possible, and securing connections with industry standard
- transport layer security. You are also welcome to contact us using GnuPG
- encrypted e-mail. Even with all these precautions, we cannot fully guarantee
- against the access, disclosure, alteration, or deletion of data through
- events, including but not limited to hardware or software failure or
- unauthorized use. Any information that you provide to us is done so entirely
- at your own risk.</paragraph>
- </section>
- <section ids="changes-and-updates-to-privacy-policy" names="changes\ and\ updates\ to\ privacy\ policy">
- <title>Changes and updates to privacy policy</title>
- <paragraph>We reserve the right to update and revise this privacy policy at any time. We
- occasionally review this Privacy Policy to make sure it complies with
- applicable laws and conforms to changes in our business. We may need to update
- this Privacy Policy, and we reserve the right to do so at any time. If we do
- revise this Privacy Policy, we will update the “Effective Date” at the bottom
- of this page so that you can tell if it has changed since your last visit. As
- we generally do not collect contact information and also do not track your
- visits, we will not be able to notify you directly. However, the Taler Wallet
- may inform you about a change in the privacy policy once it detects that the
- policy has changed. Please review this Privacy Policy regularly to ensure that
- you are aware of its terms. Any use of our Services after an amendment to our
- Privacy Policy constitutes your acceptance to the revised or amended
- agreement.</paragraph>
- </section>
- <section ids="international-users-and-visitors" names="international\ users\ and\ visitors">
- <title>International users and visitors</title>
- <paragraph>Our Services are hosted in Switzerland. If you are a user accessing the
- Services from the European Union, Asia, US, or any other region with laws or
- regulations governing personal data collection, use, and disclosure that
- differ from Swiss laws, please be advised that through your continued use of
- the Services, which is governed by Swiss law, you are transferring your
- Personal Information to Switzerland and you consent to that transfer.</paragraph>
- </section>
- <section ids="questions" names="questions">
- <title>Questions</title>
- <paragraph>Please contact us at <reference refuri="mailto:privacy@taler-systems.net">privacy@taler-systems.net</reference> if you have questions about our
- privacy practices that are not addressed in this Privacy Statement.</paragraph>
- </section>
- </section>
-</document>
diff --git a/contrib/pp/locale/de/LC_MESSAGES/pp.po b/contrib/pp/locale/de/LC_MESSAGES/pp.po
deleted file mode 100644
index b97b70372..000000000
--- a/contrib/pp/locale/de/LC_MESSAGES/pp.po
+++ /dev/null
@@ -1,221 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) 2014-2020 Taler Systems SA (GPLv3+ or GFDL 1.3+)
-# This file is distributed under the same license as the pp package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: pp 0\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-09-30 21:41+0200\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: ../../pp.rst:2
-msgid "Privacy Policy"
-msgstr ""
-
-#: ../../pp.rst:4
-msgid "Last Updated: 11.12.2019"
-msgstr ""
-
-#: ../../pp.rst:6
-msgid "This Privacy Policy describes the policies and procedures of Taler Systems SA (“we,” “our,” or “us”) pertaining to the collection, use, and disclosure of your information on our sites and related mobile applications and products we offer (the “Services” or “Taler Wallet”). This Privacy Statement applies to your personal data when you use our Services, and does not apply to online websites or services that we do not own or control."
-msgstr ""
-
-#: ../../pp.rst:15
-msgid "Overview"
-msgstr ""
-
-#: ../../pp.rst:17
-msgid "Your privacy is important to us. We follow a few fundamental principles: We don’t ask you for personally identifiable information (defined below). That being said, your contact information, such as your phone number, social media handle, or email address (depending on how you contact us), may be collected when you communicate with us, for example to report a bug or other error related to the Taler Wallet. We don’t share your information with third parties except when strictly required to deliver you our Services and products, or to comply with the law. If you have any questions or concerns about this policy, please reach out to us at privacy@taler-systems.net."
-msgstr ""
-
-#: ../../pp.rst:29
-msgid "How you accept this policy"
-msgstr ""
-
-#: ../../pp.rst:31
-msgid "By using our Services or visiting our sites, you agree to the use, disclosure, and procedures outlined in this Privacy Policy."
-msgstr ""
-
-#: ../../pp.rst:36
-msgid "What personal information do we collect from our users?"
-msgstr ""
-
-#: ../../pp.rst:38
-msgid "The information we collect from you falls into two categories: (i) personally identifiable information (i.e., data that could potentially identify you as an individual) (“Personal Information”), and (ii) non-personally identifiable information (i.e., information that cannot be used to identify who you are) (“Non-Personal Information”). This Privacy Policy covers both categories and will tell you how we might collect and use each type."
-msgstr ""
-
-#: ../../pp.rst:45
-msgid "We do our best to not collect any Personal Information from Taler Wallet users. We believe that the Taler Wallet never transmits personal information to our services without at least clear implied consent, and we only process and retain information with a strict business need. That being said, when using our Services, we inherently have to collect the following information:"
-msgstr ""
-
-#: ../../pp.rst:51
-msgid "Bank account details necessary when receiving funds from you to top-up your wallet or to transfer funds to you when you are being paid via Taler. At the current experimental stage, only the pseudonym and password you entered in the bank demonstrator is stored."
-msgstr ""
-
-#: ../../pp.rst:53
-msgid "The amounts being withdrawn or deposited, with associated unique transaction identifiers and cryptographic signatures authorizing the transaction. Note that for purchases, we cannot identify the buyer from the collected data, so when you spend money, we only receive non-personal information."
-msgstr ""
-
-#: ../../pp.rst:55
-msgid "When you contact us. We may collect certain information if you choose to contact us, for example to report a bug or other error with the Taler Wallet. This may include contact information such as your name, email address or phone number depending on the method you choose to contact us."
-msgstr ""
-
-#: ../../pp.rst:59
-msgid "How we collect and process information"
-msgstr ""
-
-#: ../../pp.rst:61
-msgid "We may process your information for the following reasons:"
-msgstr ""
-
-#: ../../pp.rst:63
-msgid "to transfer money as specified by our users (Taler transactions);"
-msgstr ""
-
-#: ../../pp.rst:64
-msgid "to assist government entities in linking income to the underlying contract as required by law and local regulations"
-msgstr ""
-
-#: ../../pp.rst:65
-msgid "to support you using the Taler Wallet or to improve our Services"
-msgstr ""
-
-#: ../../pp.rst:69
-msgid "How we share and use the information we gather"
-msgstr ""
-
-#: ../../pp.rst:71
-msgid "We may share your Personal Data or other information about you only if you are a merchant receiving income, with your bank, to the degree necessary to execute the payment."
-msgstr ""
-
-#: ../../pp.rst:75
-msgid "We retain Personal Data to transfer funds to the accounts designated by our users. We may retain Personal Data only for as long as mandated by law and required for the wire transfers."
-msgstr ""
-
-#: ../../pp.rst:79
-msgid "We primarily use the limited information we receive directly from you to enhance the Taler Wallet. Some ways we may use your Personal Information are to: Contact you when necessary to respond to your comments, answer your questions, or obtain additional information on issues related to bugs or errors with the Taler Wallet that you reported."
-msgstr ""
-
-#: ../../pp.rst:87
-msgid "Agents or third party partners"
-msgstr ""
-
-#: ../../pp.rst:89
-msgid "We may provide your Personal Information to our employees, contractors, agents, service providers, and designees (“Agents”) to enable them to perform certain services for us exclusively, including: improvement and maintenance of our software and Services."
-msgstr ""
-
-#: ../../pp.rst:96
-msgid "Protection of us and others"
-msgstr ""
-
-#: ../../pp.rst:98
-msgid "We reserve the right to access, read, preserve, and disclose any information that we reasonably believe is necessary to comply with the law or a court order."
-msgstr ""
-
-#: ../../pp.rst:104
-msgid "What personal information can I access or change?"
-msgstr ""
-
-#: ../../pp.rst:106
-msgid "You can request access to the information we have collected from you. You can do this by contacting us at privacy@taler-systems.net. We will make sure to provide you with a copy of the data we process about you. To comply with your request, we may ask you to verify your identity. We will fulfill your request by sending your copy electronically. For any subsequent access request, we may charge you with an administrative fee. If you believe that the information we have collected is incorrect, you are welcome to contact us so we can update it and keep your data accurate. Any data that is no longer needed for purposes specified in the “How We Use the Information We Gather” section will be deleted after ninety (90) days."
-msgstr ""
-
-#: ../../pp.rst:119
-msgid "What are your data protection rights?"
-msgstr ""
-
-#: ../../pp.rst:121
-msgid "Anastasis would like to make sure you are fully aware of all of your data protection rights. Every user is entitled to the following:"
-msgstr ""
-
-#: ../../pp.rst:126
-msgid "**The right to access**: You have the right to request Anastasis for"
-msgstr ""
-
-#: ../../pp.rst:125
-msgid "copies of your personal data. We may charge you a small fee for this service."
-msgstr ""
-
-#: ../../pp.rst:128
-msgid "**The right to rectification**: You have the right to request that Anastasis correct any information you believe is inaccurate. You also have the right to request Anastasis to complete information you believe is incomplete. The right to erasure - You have the right to request that Anastasis erase your personal data, under certain conditions."
-msgstr ""
-
-#: ../../pp.rst:137
-msgid "**The right to restrict processing**: You have the right to request"
-msgstr ""
-
-#: ../../pp.rst:136
-msgid "that Anastasis restrict the processing of your personal data, under certain conditions."
-msgstr ""
-
-#: ../../pp.rst:141
-msgid "**The right to object to processing**: You have the right to object to"
-msgstr ""
-
-#: ../../pp.rst:140
-msgid "Anastasis's processing of your personal data, under certain conditions."
-msgstr ""
-
-#: ../../pp.rst:145
-msgid "**The right to data portability**: You have the right to request that"
-msgstr ""
-
-#: ../../pp.rst:144
-msgid "Anastasis transfer the data that we have collected to another organization, or directly to you, under certain conditions."
-msgstr ""
-
-#: ../../pp.rst:147
-msgid "If you make a request, we have one month to respond to you. If you would like to exercise any of these rights, please contact us at our email: privacy@taler-systems.com"
-msgstr ""
-
-#: ../../pp.rst:151
-msgid "You can always contact your local data protection authority to enforce your rights."
-msgstr ""
-
-#: ../../pp.rst:156
-msgid "Data retention"
-msgstr ""
-
-#: ../../pp.rst:158
-msgid "If you uninstall the Taler Wallet mobile applications from your device, or request that your information be deleted, we still may retain some information that you have provided to us to maintain the Taler Wallet or to comply with relevant laws."
-msgstr ""
-
-#: ../../pp.rst:165
-msgid "Data security"
-msgstr ""
-
-#: ../../pp.rst:167
-msgid "We are committed to making sure your information is protected. We employ several physical and electronic safeguards to keep your information safe, including encrypted user passwords, two factor verification and authentication on passwords where possible, and securing connections with industry standard transport layer security. You are also welcome to contact us using GnuPG encrypted e-mail. Even with all these precautions, we cannot fully guarantee against the access, disclosure, alteration, or deletion of data through events, including but not limited to hardware or software failure or unauthorized use. Any information that you provide to us is done so entirely at your own risk."
-msgstr ""
-
-#: ../../pp.rst:180
-msgid "Changes and updates to privacy policy"
-msgstr ""
-
-#: ../../pp.rst:182
-msgid "We reserve the right to update and revise this privacy policy at any time. We occasionally review this Privacy Policy to make sure it complies with applicable laws and conforms to changes in our business. We may need to update this Privacy Policy, and we reserve the right to do so at any time. If we do revise this Privacy Policy, we will update the “Effective Date” at the bottom of this page so that you can tell if it has changed since your last visit. As we generally do not collect contact information and also do not track your visits, we will not be able to notify you directly. However, the Taler Wallet may inform you about a change in the privacy policy once it detects that the policy has changed. Please review this Privacy Policy regularly to ensure that you are aware of its terms. Any use of our Services after an amendment to our Privacy Policy constitutes your acceptance to the revised or amended agreement."
-msgstr ""
-
-#: ../../pp.rst:198
-msgid "International users and visitors"
-msgstr ""
-
-#: ../../pp.rst:200
-msgid "Our Services are hosted in Switzerland. If you are a user accessing the Services from the European Union, Asia, US, or any other region with laws or regulations governing personal data collection, use, and disclosure that differ from Swiss laws, please be advised that through your continued use of the Services, which is governed by Swiss law, you are transferring your Personal Information to Switzerland and you consent to that transfer."
-msgstr ""
-
-#: ../../pp.rst:209
-msgid "Questions"
-msgstr ""
-
-#: ../../pp.rst:211
-msgid "Please contact us at privacy@taler-systems.net if you have questions about our privacy practices that are not addressed in this Privacy Statement."
-msgstr ""
diff --git a/contrib/samples/wire-auditor.json b/contrib/samples/wire-auditor.json
index ce2baf2e8..905bbfcf2 100644
--- a/contrib/samples/wire-auditor.json
+++ b/contrib/samples/wire-auditor.json
@@ -38,8 +38,8 @@
"value": 5,
"fraction": 1000000
},
- "missattribution_in_inconsistencies": [],
- "total_missattribution_in": {
+ "misattribution_in_inconsistencies": [],
+ "total_misattribution_in": {
"currency": "KUDOS",
"value": 0,
"fraction": 0
@@ -233,4 +233,4 @@
"fraction": 1000000
},
"lag_details": []
-} \ No newline at end of file
+}
diff --git a/contrib/sigp/h.header b/contrib/sigp/h.header
index a0e3c6ae3..6ed22a63d 100644
--- a/contrib/sigp/h.header
+++ b/contrib/sigp/h.header
@@ -27,6 +27,5 @@
#ifndef TALER_SIGNATURES_H
#define TALER_SIGNATURES_H
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_amount_lib.h"
-#include "taler_crypto_lib.h"
+
+
diff --git a/contrib/taler-auditor-dbconfig b/contrib/taler-auditor-dbconfig
new file mode 100755
index 000000000..245d6970d
--- /dev/null
+++ b/contrib/taler-auditor-dbconfig
@@ -0,0 +1,132 @@
+#!/bin/bash
+# This file is part of GNU TALER.
+# Copyright (C) 2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along with
+# TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+#
+# @author Christian Grothoff
+#
+#
+# Error checking on
+set -eu
+
+RESET_DB=0
+SKIP_DBINIT=0
+DBUSER="taler-auditor-httpd"
+DBNAME="auditor"
+CFGFILE="/etc/taler/secrets/auditor-db.secret.conf"
+
+# Parse command-line options
+while getopts ':hn:rsu:' OPTION; do
+ case "$OPTION" in
+ h)
+ echo 'Supported options:'
+ echo " -c FILENAME -- write configuration to FILENAME (default: $CFGFILE)"
+ echo " -n NAME -- user NAME for database name (default: $DBNAME)"
+ echo " -r -- reset database (dangerous)"
+ echo " -s -- skip database initialization"
+ echo " -u USER -- taler-auditor to be run by USER (default: $DBUSER)"
+ exit 0
+ ;;
+ n)
+ DBNAME="$OPTARG"
+ ;;
+ r)
+ RESET_DB="1"
+ ;;
+ s)
+ SKIP_DBINIT="1"
+ ;;
+ u)
+ DBUSER="$OPTARG"
+ ;;
+ ?)
+ exit_fail "Unrecognized command line option"
+ ;;
+ esac
+done
+
+if ! id postgres > /dev/null
+then
+ echo "Could not find 'postgres' user. Please install Postgresql first"
+ exit 1
+fi
+
+if [ "$(id -u)" -ne 0 ]
+then
+ echo "This script must be run as root"
+ exit 1
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+ if ! taler-auditor-dbinit -v 2> /dev/null
+ then
+ echo "Required 'taler-auditor-dbinit' not found. Please fix your installation."
+ fi
+fi
+
+if ! id "$DBUSER" > /dev/null
+then
+ echo "Could not find '$DBUSER' user. Please set it up first"
+ exit 1
+fi
+
+if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null
+then
+ if [ 1 = "$RESET_DB" ]
+ then
+ echo "Deleting existing database '$DBNAME'." 1>&2
+ sudo -i -u postgres dropdb "$DBNAME"
+ else
+ echo "Database '$DBNAME' already exists, refusing to setup again."
+ echo "Use -r to delete the existing database first (dangerous!)."
+ exit 77
+ fi
+fi
+
+echo "Setting up database user $DBUSER." 1>&2
+
+if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null
+then
+ echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
+fi
+
+echo "Creating database $DBNAME." 1>&2
+
+if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME"
+then
+ echo "Failed to create database '$DBNAME'"
+ exit 1
+fi
+
+if [ -f "$CFGFILE" ]
+then
+ echo "Adding database configuration to '$CFGFILE'." 1>&2
+ echo -e "[auditordb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE"
+else
+ echo "Configuration '$CFGFILE' does not yet exist, creating it." 1>&2
+ mkdir -p "$(dirname "$CFGFILE")"
+ echo -e "[auditordb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE"
+ chown "$DBUSER":root "$CFGFILE"
+ chmod 460 "$CFGFILE"
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+ echo "Initializing database '$DBNAME'." 1>&2
+ sudo -u "$DBUSER" taler-auditor-dbinit
+fi
+
+echo "Database configuration finished." 1>&2
+
+exit 0
diff --git a/contrib/taler-bank-manage-testing b/contrib/taler-bank-manage-testing
deleted file mode 100755
index 4fa80b177..000000000
--- a/contrib/taler-bank-manage-testing
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/sh
-# This file is in the public domain
-# Wrapper around 'taler-bank-manage' to first configure the required
-# testing accounts before launching the bank properly.
-#
-# Takes 3 arguments:
-# $1: the configuration file name
-# $2: the database name
-# $3: serve-http or serve-uwsgi
-
-set -eu
-
-if [ "$#" -ne 3 ];
-then
- echo "illegal number of parameters"
- exit 1
-fi
-
-# Ensure starting accounts exist
-taler-bank-manage -c $1 --with-db $2 django provide_accounts
-taler-bank-manage -c $1 --with-db $2 django add_bank_account 42
-taler-bank-manage -c $1 --with-db $2 django add_bank_account 43
-
-taler-bank-manage -c $1 --with-db $2 django changepassword_unsafe Exchange x
-
-# Now run Django for good
-exec taler-bank-manage -c $1 --with-db $2 $3
diff --git a/contrib/taler-exchange-dbconfig b/contrib/taler-exchange-dbconfig
new file mode 100755
index 000000000..eb90ee721
--- /dev/null
+++ b/contrib/taler-exchange-dbconfig
@@ -0,0 +1,186 @@
+#!/bin/bash
+# This file is part of GNU TALER.
+# Copyright (C) 2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along with
+# TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+#
+# @author Christian Grothoff
+#
+#
+# Error checking on
+set -eu
+
+RESET_DB=0
+SKIP_DBINIT=0
+FORCE_PERMS=0
+DBUSER="taler-exchange-httpd"
+DBGROUP="taler-exchange-db"
+CFGFILE="/etc/taler/taler.conf"
+
+# Parse command-line options
+while getopts 'c:g:hprsu:' OPTION; do
+ case "$OPTION" in
+ c)
+ CFGFILE="$OPTARG"
+ ;;
+ h)
+ echo 'Supported options:'
+ echo " -c FILENAME -- use configuration FILENAME (default: $CFGFILE)"
+ echo " -g GROUP -- taler-exchange to be run by GROUP (default: $DBGROUP)"
+ echo " -h -- print this help text"
+ echo " -r -- reset database (dangerous)"
+ echo " -p -- force permission setup even without database initialization"
+ echo " -s -- skip database initialization"
+ echo " -u USER -- taler-exchange to be run by USER (default: $DBUSER)"
+ exit 0
+ ;;
+ p)
+ FORCE_PERMS="1"
+ ;;
+ r)
+ RESET_DB="1"
+ ;;
+ s)
+ SKIP_DBINIT="1"
+ ;;
+ u)
+ DBUSER="$OPTARG"
+ ;;
+ ?)
+ echo "Unrecognized command line option" 1>&2
+ exit 1
+ ;;
+ esac
+done
+
+if ! id postgres > /dev/null
+then
+ echo "Could not find 'postgres' user. Please install Postgresql first"
+ exit 1
+fi
+
+if [ "$(id -u)" -ne 0 ]
+then
+ echo "This script must be run as root"
+ exit 1
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+ if ! taler-exchange-dbinit -v 2> /dev/null
+ then
+ echo "Required 'taler-exchange-dbinit' not found. Please fix your installation."
+ exit 1
+ fi
+ DBINIT=$(which taler-exchange-dbinit)
+fi
+
+if ! id "$DBUSER" > /dev/null
+then
+ echo "Could not find '$DBUSER' user. Please set it up first"
+ exit 1
+fi
+
+echo "Setting up database user '$DBUSER'." 1>&2
+
+if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null
+then
+ echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
+fi
+
+DBPATH=$(taler-config \
+ -c "$CFGFILE" \
+ -s exchangedb-postgres \
+ -o CONFIG)
+
+if ! echo "$DBPATH" | grep "postgres://" > /dev/null
+then
+ echo "Invalid database configuration value '$DBPATH'." 1>&2
+ exit 1
+fi
+
+DBNAME=$(echo "$DBPATH" \
+ | sed \
+ -e "s/postgres:\/\/.*\///" \
+ -e "s/?.*//")
+
+if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null
+then
+ if [ 1 = "$RESET_DB" ]
+ then
+ echo "Deleting existing database '$DBNAME'." 1>&2
+ if ! sudo -i -u postgres dropdb "$DBNAME"
+ then
+ echo "Failed to delete existing database '$DBNAME'"
+ exit 1
+ fi
+ DO_CREATE=1
+ else
+ echo "Database '$DBNAME' already exists, continuing anyway."
+ DO_CREATE=0
+ fi
+else
+ DO_CREATE=1
+fi
+
+if [ 1 = "$DO_CREATE" ]
+then
+ echo "Creating database '$DBNAME'." 1>&2
+
+ if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME"
+ then
+ echo "Failed to create database '$DBNAME'"
+ exit 1
+ fi
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+ echo "Initializing database '$DBNAME'." 1>&2
+ if ! sudo -u "$DBUSER" "$DBINIT" -c "$CFGFILE"
+ then
+ echo "Failed to initialize database schema"
+ exit 1
+ fi
+fi
+
+if [ 0 = "$SKIP_DBINIT" ] || [ 1 = "$FORCE_PERMS" ]
+then
+ DB_GRP="$(getent group "$DBGROUP" | sed -e "s/.*://g" -e "s/,/ /g")"
+ echo "Initializing permissions for '$DB_GRP'." 1>&2
+ for GROUPIE in $DB_GRP
+ do
+ if [ "$GROUPIE" != "$DBUSER" ]
+ then
+ if ! sudo -i -u postgres createuser "$GROUPIE" 2> /dev/null
+ then
+ echo "Database user '$GROUPIE' already existed. Continuing anyway." 1>&2
+ fi
+ echo -e 'GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA exchange TO "'"$GROUPIE"'";\n' \
+ 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO "'"$GROUPIE"'";\n' \
+ | sudo -u "$DBUSER" psql "$DBNAME"
+ echo -e 'GRANT USAGE ON SCHEMA exchange TO "'"$GROUPIE"'"' \
+ | sudo -u "$DBUSER" psql "$DBNAME"
+ # FIXME: double-check the following GRANTs
+ echo -e 'GRANT USAGE ON SCHEMA _v TO "'"$GROUPIE"'"' \
+ | sudo -u "$DBUSER" psql "$DBNAME"
+ echo -e 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA _v TO "'"$GROUPIE"'"' \
+ | sudo -u "$DBUSER" psql "$DBNAME"
+
+
+ fi
+ done
+fi
+
+echo "Database configuration finished." 1>&2
+
+exit 0
diff --git a/contrib/taler-nexus-prepare b/contrib/taler-nexus-prepare
deleted file mode 100755
index 66a0b1c1e..000000000
--- a/contrib/taler-nexus-prepare
+++ /dev/null
@@ -1,128 +0,0 @@
-#!/usr/bin/env python3
-# This file is in the public domain.
-
-from requests import get, post
-from subprocess import call
-import base64
-
-# EBICS details
-EBICS_URL = "http://localhost:5000/ebicsweb"
-HOST_ID = "HOST01"
-PARTNER_ID = "PARTNER1"
-USER_ID = "USER1"
-EBICS_VERSION = "H004"
-
-SUBSCRIBER_IBAN = "ES9121000418450200051332"
-SUBSCRIBER_BIC = "BIC"
-SUBSCRIBER_NAME = "Exchange"
-
-BANK_ACCOUNT_LABEL = "my-bank-account"
-BANK_CONNECTION_LABEL = "my-bank-connection"
-FACADE_LABEL="my-facade"
-
-USERNAME="Exchange"
-USER_AUTHORIZATION_HEADER = "basic {}".format(
- base64.b64encode(b"Exchange:x").decode("utf-8")
-)
-
-def assertResponse(response):
- if response.status_code != 200:
- print("Test failed on URL: {}".format(response.url))
- # stdout/stderr from both services is A LOT of text.
- # Confusing to dump all that to console.
- print("Check nexus.log and sandbox.log, probably under /tmp")
- exit(1)
- # Allows for finer grained checks.
- return response
-
-# Create a nexus (super-) user
-check_call(["libeufin-nexus",
- "superuser",
- "--db-name", "/tmp/nexus-exchange-test.sqlite3",
- "Exchange",
- "--password", "x"]
-)
-
-# Create a EBICS bank connection.
-assertResponse(
- post(
- "http://localhost:5001/bank-connections",
- json=dict(
- name=BANK_CONNECTION_LABEL,
- source="new",
- type="ebics",
- data=dict(
- ebicsURL=EBICS_URL, hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID
- ),
- ),
- headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
- )
-)
-
-# Create a facade
-assertResponse(
- post(
- "http://localhost:5001/facades",
- json=dict(
- name=FACADE_LABEL,
- type="taler-wire-gateway",
- creator=USERNAME,
- config=dict(
- bankAccount=BANK_ACCOUNT_LABEL,
- bankConnection=BANK_CONNECTION_LABEL,
- reserveTransferLevel="UNUSED",
- intervalIncremental="UNUSED"
- )
- ),
- headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
- )
-)
-
-# Create the EBICS host at the Sandbox.
-assertResponse(
- post(
- "http://localhost:5000/admin/ebics/host",
- json=dict(hostID=HOST_ID, ebicsVersion=EBICS_VERSION),
- )
-)
-
-# Create Exchange EBICS subscriber at the Sandbox.
-assertResponse(
- post(
- "http://localhost:5000/admin/ebics/subscribers",
- json=dict(hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID),
- )
-)
-
-# Create a bank account associated to the Exchange's EBICS subscriber,
-# again at the Sandbox.
-assertResponse(
- post(
- "http://localhost:5000/admin/ebics/bank-accounts",
- json=dict(
- subscriber=dict(hostID=HOST_ID, partnerID=PARTNER_ID, userID=USER_ID),
- iban=SUBSCRIBER_IBAN,
- bic=SUBSCRIBER_BIC,
- name=SUBSCRIBER_NAME,
- label=BANK_ACCOUNT_LABEL,
- ),
- )
-)
-
-# 'connect' to the bank: upload+download keys.
-assertResponse(
- post(
- "http://localhost:5001/bank-connections/{}/connect".format(BANK_CONNECTION_LABEL),
- json=dict(),
- headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
- )
-)
-
-# Download bank accounts.
-assertResponse(
- post(
- "http://localhost:5001/bank-connections/{}/ebics/import-accounts".format(BANK_CONNECTION_LABEL),
- json=dict(),
- headers=dict(Authorization=USER_AUTHORIZATION_HEADER),
- )
-)
diff --git a/contrib/taler-terms-generator b/contrib/taler-terms-generator
new file mode 100755
index 000000000..4a25afa4b
--- /dev/null
+++ b/contrib/taler-terms-generator
@@ -0,0 +1,295 @@
+#!/bin/bash
+# This file is part of GNU TALER.
+# Copyright (C) 2014-2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License along with
+# TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+#
+# @author Florian Dold
+# @author Benedikt Muller
+# @author Sree Harsha Totakura
+# @author Marcello Stanisci
+# @author Christian Grothoff
+#
+#
+# Error checking on
+set -eu
+
+# Call with target language as first argument.
+function make_config() {
+ cat >"${BUILDDIR}/conf.py" <<EOF
+import sys
+import os
+sys.path.append(os.path.abspath('_exts'))
+needs_sphinx = '1.8.5'
+extensions = [
+ 'sphinx.ext.todo',
+ 'sphinx.ext.imgmath',
+ 'sphinx_markdown_builder',
+]
+templates_path = ['_templates']
+source_suffix = {
+ '.rst': 'restructuredtext',
+}
+master_doc = '$VERSION_BASENAME'
+project = u'$VERSION_BASENAME'
+copyright = u'$COPYRIGHT'
+version = '$VERSION_BASENAME'
+release = '$VERSION_BASENAME'
+language = "$LANGUAGE"
+exclude_patterns = ['_build', '_exts', 'cf', 'prebuilt']
+locale_dirs = ['$LOCALE_DIR/']
+gettext_compact = False
+pygments_style = 'sphinx'
+html_theme = 'epub'
+rst_epilog = ""
+html_show_sphinx = False
+html_theme_options = {
+ "relbar1": "false",
+ "footer": "false",
+}
+html_title = "$TITLE"
+html_short_title = "$TITLE"
+html_use_index = True
+html_show_sphinx = False
+latex_elements = {
+ # The paper size ('letterpaper' or 'a4paper').
+ #'papersize': 'letterpaper',
+
+ # The font size ('10pt', '11pt' or '12pt').
+ #'pointsize': '10pt',
+
+ # Additional stuff for the LaTeX preamble.
+ #'preamble': '',
+}
+latex_documents = [
+ ('$VERSION_BASENAME', '$VERSION_BASENAME.tex',
+ '$VERSION_BASENAME', '$VERSION_BASENAME', 'manual'),
+]
+epub_basename = "$VERSION_BASENAME"
+epub_title = "$TITLE"
+EOF
+}
+
+# Output file given as first argument to stderr, then exit with a failure.
+function failcat() {
+ cat "$1" 1>&2
+ exit 1
+}
+
+# defaults
+AUTHOR="GNU Taler team"
+VERSION="exchange-tos-v0"
+LOCALE_DIR=$(taler-config -s "PATHS" -o "LOCALEDIR" -f)
+OUTPUT=$(taler-config -s "EXCHANGE" -o "TERMS_DIR" -f)
+PAPER="a4"
+COPYRIGHT="2014-2023 Taler Systems SA (GPLv3+ or GFDL 1.3+)"
+INCREMENTAL=0
+
+# Parse command-line options
+while getopts ':a:C:hKi:l:L:o:p:t:' OPTION; do
+ case "$OPTION" in
+ a)
+ AUTHOR="$OPTARG"
+ ;;
+ C)
+ COPYRIGHT="$OPTARG"
+ ;;
+ h)
+ echo 'Supported options:'
+ echo ' -a AUTHOR -- set author header' "(default: $AUTHOR)"
+ echo ' -C COPYRIGHT -- set copyright header' "(default: $COPYRIGHT)"
+ echo ' -h -- print this help'
+ echo ' -K -- rebuild only if input is older than output'
+ echo ' -i INPUT -- input file to convert' "(default: $VERSION)"
+ echo ' -l LANGUAGE -- target language to add'
+ echo ' -L LOCALE_DIR -- directory with resources for translation' "(default: $LOCALE_DIR)"
+ echo ' -o OUTPUT -- output directory' "(default: $OUTPUT)"
+ echo ' -p PAPER -- paper format' "(default: $PAPER)"
+ echo ' -t TITLE -- title of the document to generate'
+ exit 0
+ ;;
+ l)
+ ADD_LANGUAGE="$OPTARG"
+ ;;
+ L)
+ LOCALE_DIR="$OPTARG"
+ ;;
+ i)
+ VERSION="$OPTARG"
+ ;;
+ o)
+ OUTPUT="$OPTARG"
+ ;;
+ p)
+ PAPER="$OPTARG"
+ case "$PAPER" in
+ a4 | letter) ;;
+ *)
+ echo "Error: Paper format '$PAPER' invalid (use 'a4' or 'letter')" 1>&2
+ exit 1
+ ;;
+ esac
+ ;;
+ t)
+ TITLE="$OPTARG"
+ ;;
+ K)
+ INCREMENTAL=1
+ ;;
+ ?)
+ echo "Unrecognized command line option" 1>&2
+ exit 1
+ ;;
+ esac
+done
+
+if ! which sphinx-build >/dev/null; then
+ echo "Command 'sphinx-build' not found, but required. Please install sphinx." 1>&2
+ exit 1
+fi
+
+if ! which pandoc >/dev/null; then
+ echo "Command 'pandoc' not found, but required. Please install pandoc." 1>&2
+ exit 1
+fi
+
+if ! which gs >/dev/null; then
+ echo "Command 'gs' not found, but required. Please install ghostscript." 1>&2
+ exit 1
+fi
+
+if ! which pdfroff >/dev/null; then
+ echo "Command 'pdfroff' not found, but required. Please install pdfroff/groff." 1>&2
+ exit 1
+fi
+
+if ! which make >/dev/null; then
+ echo "Command 'make' not found, but required. Please install make." 1>&2
+ exit 1
+fi
+
+# We append ".rst" if needed, remove if given on command-line
+# shellcheck disable=SC2001
+VERSION=$(echo "${VERSION}" | sed -e "s/\.rst$//")
+
+# Sometimes we just want the basename, not the directory.
+VERSION_BASENAME=$(basename "${VERSION}")
+
+BUILDDIR=$(mktemp -d /tmp/taler-terms-XXXXXX)
+if [ ! -f "${VERSION}.rst" ]; then
+ echo "Error: File '${VERSION}.rst' not found. Please check '-i' option." 1>&2
+ exit 1
+fi
+
+cp "${VERSION}.rst" "${BUILDDIR}/"
+
+if [ -z ${TITLE+x} ]; then
+ TITLE=$(head -n1 "${VERSION}.rst")
+ echo "Title automatically set to '$TITLE'" 1>&2
+fi
+
+if [ -n "${ADD_LANGUAGE+x}" ]; then
+ if ! echo "${ADD_LANGUAGE}" | grep -e '^..$' >/dev/null; then
+ echo "Error: Invalid language '${ADD_LANGUAGE}'. Two characters (en, de, fr, ...) expected." 1>&2
+ exit 1
+ fi
+ echo "Adding language files for translations to '${ADD_LANGUAGE}'" 1>&2
+ make_config "${ADD_LANGUAGE}"
+ sphinx-build \
+ -b gettext \
+ -D language="${ADD_LANGUAGE}" \
+ -d "${BUILDDIR}/.doctrees" \
+ "${BUILDDIR}" \
+ "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/" \
+ &>"${BUILDDIR}/add-language.log" ||
+ failcat "${BUILDDIR}/add-language.log"
+ if [ -f "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.po" ]; then
+ msgmerge --lang="${ADD_LANGUAGE}" \
+ --no-location \
+ -o "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.mrg" \
+ "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.po" \
+ "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.pot"
+ mv "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.mrg" \
+ "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.po"
+ else
+ mv "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.pot" \
+ "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.po"
+ fi
+ rm -f "${LOCALE_DIR}/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.pot"
+ echo "Done" 1>&2
+ exit 0
+fi
+
+# As a heuristic for incremental builds, we only check the text output file.
+if [[ $INCREMENTAL -eq 1 ]]; then
+ if [[ "${VERSION}.rst" -ot "${OUTPUT}/buildstamp" ]]; then
+ echo "Not rebuilding, input file $VERSION is older than $OUTPUT/buildstamp."
+ exit 0
+ fi
+fi
+
+# shellcheck disable=SC2086
+for d in en $(ls -d ${LOCALE_DIR}/?? | grep -v "en" 2>/dev/null || true); do
+ LANGUAGE=$(basename "$d")
+ if [ "en" != "${LANGUAGE}" ] && [ ! -f "${LOCALE_DIR}/${LANGUAGE}/LC_MESSAGES/${VERSION_BASENAME}.po" ]; then
+ echo "Skipping language ${LANGUAGE}: no translation for ${VERSION_BASENAME} found."
+ continue
+ fi
+ echo "Generating files at '$OUTPUT' for ETag '$VERSION_BASENAME' and language '${LANGUAGE}' in '${BUILDDIR}':" 1>&2
+
+ make_config "$LANGUAGE"
+ mkdir -p "${OUTPUT}/${LANGUAGE}/"
+
+ LBUILD="sphinx-build -D language=${LANGUAGE} -d ${BUILDDIR}/.doctrees"
+
+ OUTBASE="${OUTPUT}/${LANGUAGE}/${VERSION_BASENAME}"
+
+ echo "$VERSION_BASENAME MD ($LANGUAGE)..." 1>&2
+ $LBUILD \
+ -b markdown \
+ "${BUILDDIR}" \
+ "${BUILDDIR}/md" \
+ &>"${BUILDDIR}/md-sphinx.log" ||
+ failcat "${BUILDDIR}/md-sphinx.log"
+ BUILDFILE_MARKDOWN="${BUILDDIR}/md/${VERSION_BASENAME}.md"
+ cp "$BUILDFILE_MARKDOWN" "${OUTBASE}.md"
+
+ # Convert the generated Markdown (!) to other formats.
+
+ echo "$VERSION_BASENAME PDF ($LANGUAGE)..." 1>&2
+ pandoc \
+ -i "$BUILDFILE_MARKDOWN" \
+ -o "${OUTBASE}.pdf" \
+ --pdf-engine=pdfroff \
+ --shift-heading-level-by=-1
+
+ echo "$VERSION_BASENAME HTML ($LANGUAGE)..." 1>&2
+ # FIXME: Newer versions of pandic should use
+ # --embed-resources --standalone instead of --self-contained
+ pandoc \
+ -i "$BUILDFILE_MARKDOWN" \
+ -o "${OUTBASE}.html" \
+ --self-contained \
+ --shift-heading-level-by=-1
+
+ echo "$VERSION_BASENAME TXT ($LANGUAGE)..." 1>&2
+ pandoc \
+ -i "$BUILDFILE_MARKDOWN" \
+ -o "${OUTBASE}.txt"
+done
+
+if [[ $INCREMENTAL -eq 1 ]]; then
+ touch "${OUTPUT}/buildstamp"
+fi
+
+echo "Done" 1>&2
+exit 0
diff --git a/contrib/tos/.gitignore b/contrib/tos/.gitignore
deleted file mode 100644
index fb83616eb..000000000
--- a/contrib/tos/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-sphinx.err
-sphinx.log
-_build/
diff --git a/contrib/tos/Makefile b/contrib/tos/Makefile
deleted file mode 100644
index ab29543cb..000000000
--- a/contrib/tos/Makefile
+++ /dev/null
@@ -1,109 +0,0 @@
-# Makefile for Sphinx documentation
-#
-# You can set these variables from the command line.
-SPHINXOPTS =
-SPHINXBUILD = sphinx-build
-PAPER =
-BUILDDIR = _build
-
-# User-friendly check for sphinx-build
-ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
-$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
-endif
-
-# Internal variables.
-PAPEROPT_a4 = -D latex_paper_size=a4
-PAPEROPT_letter = -D latex_paper_size=letter
-ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
-# the i18n builder cannot share the environment and doctrees with the others
-I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
-
-.PHONY: help clean html json epub latex latexpdf text man doctest gettext
-
-help:
- @echo "Please use \`make <target>' where <target> is one of"
- @echo " html to make a single large HTML file"
- @echo " json to make JSON files"
- @echo " epub to make an epub"
- @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
- @echo " pdf to make LaTeX files and run them through pdflatex"
- @echo " txt to make text files"
- @echo " man to make manual pages"
- @echo " texinfo to make Texinfo files"
- @echo " info to make Texinfo files and run them through makeinfo"
- @echo " gettext to make PO message catalogs"
- @echo " xml to make Docutils-native XML files"
- @echo " pseudoxml to make pseudoxml-XML files for display purposes"
- @echo " doctest to run all doctests embedded in the documentation (if enabled)"
-
-clean:
- rm -rf $(BUILDDIR)/*
-
-
-# The html-linked builder does not support caching, so we
-# remove all cached state first.
-html:
- $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
- @echo
- @echo "Build finished. The HTML page is in $(BUILDDIR)/html."
-
-json:
- $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
- @echo
- @echo "Build finished; now you can process the JSON files."
-
-epub:
- $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
- @echo
- @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
-
-latex:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
- @echo
- @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
- @echo "Run \`make' in that directory to run these through (pdf)latex" \
- "(use \`make latexpdf' here to do that automatically)."
-
-pdf:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/pdf
- @echo "Running LaTeX files through pdflatex..."
- $(MAKE) -C $(BUILDDIR)/pdf all-pdf
- @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/pdf."
-
-txt:
- $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/txt
- @echo
- @echo "Build finished. The text files are in $(BUILDDIR)/txt."
-
-man:
- $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
- @echo
- @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
-
-texinfo:
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
- @echo
- @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
- @echo "Run \`make' in that directory to run these through makeinfo" \
- "(use \`make info' here to do that automatically)."
-
-info:
- $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/info
- @echo "Running Texinfo files through makeinfo..."
- make -C $(BUILDDIR)/texinfo info
- @echo "makeinfo finished; the Info files are in $(BUILDDIR)/info."
-
-gettext:
- $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
- @echo
- @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
-
-doctest:
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
- @echo "Testing of doctests in the sources finished, look at the " \
- "results in $(BUILDDIR)/doctest/output.txt."
-
-xml:
- $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
- @echo
- @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
diff --git a/contrib/tos/README b/contrib/tos/README
deleted file mode 100644
index dd78024cb..000000000
--- a/contrib/tos/README
+++ /dev/null
@@ -1,58 +0,0 @@
-This directory contains the terms of service (template) for exchange
-operators.
-
-
-Dependencies
-============
-
-Generating new Terms of Service requires Sphinx, LaTeX with babel
-packages for all supported languages. On Debian, you should
-at least install:
-
-$ apt install python3-sphinx sphinx-intl texlive-lang-german texlive-lang-english latexmk texlive-latex-recommended texlive-latex-extra
-
-(NOTE: List may be incomplete.)
-
-
-Updating the Terms of Service
-=============================
-
-The master file with the Terms of service is 'tos.rst'.
-
-If you make substantial changes, you MUST change the "TOS_VERSION"
-in contrib/Makefile.am to the new Etag.
-
-To begin the translation into other languages after editing the master
-file, run
-
-$ make gettext
-
-to generate the master PO file. Then, run
-
-$ sphinx-intl update -p _build/locale/ -l de -l fr -l it
-
-to update the PO files for the various languages (extend the list of
-languages as necessary). The PO files for the translators are kept
-at locale/$LANG/LC_MESSAGES/tos.po for the language $LANG.
-
-Once all PO files have been updated with new translations, run
-
-$ make update-tos
-
-in the "contrib/" directory to generate all of the formats. The
-respective make rule calls the '../update-tos.sh' script in the
-contrib/ directory, which calls the 'Makefile' in the tos/
-directory for the various supported languages and file formats
-and then moves the generated files to the target directory
-('contrib/tos/$LANG/$VERSION.$FORMAT')
-
-
-Adding a new language
-=====================
-
-To add a new language $LANG, add $LANG to "TOS_LANGUAGES" in
-'contrib/Makefile.am' and run
-
-$ sphinx-intl update -p _build/gettext -l $LANG
-
-to generate the PO template.
diff --git a/contrib/tos/conf.py b/contrib/tos/conf.py
deleted file mode 100644
index 29392556f..000000000
--- a/contrib/tos/conf.py
+++ /dev/null
@@ -1,282 +0,0 @@
-"""
- This file is part of GNU TALER.
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Lesser General Public License as published by the Free Software
- Foundation; either version 2.1, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-
- @author Florian Dold
- @author Benedikt Muller
- @author Sree Harsha Totakura
- @author Marcello Stanisci
-"""
-# -*- coding: utf-8 -*-
-#
-# neuro documentation build configuration file, created by
-# sphinx-quickstart on Sat May 31 13:11:06 2014.
-#
-# This file is execfile()d with the current directory set to its
-# containing dir.
-#
-# Note that not all possible configuration values are present in this
-# autogenerated file.
-#
-# All configuration values have a default; values that are commented out
-# serve to show the default.
-
-import sys
-import os
-
-sys.path.append(os.path.abspath('_exts'))
-
-#import taler_sphinx_theme
-
-# If extensions (or modules to document with autodoc) are in another directory,
-# add these directories to sys.path here. If the directory is relative to the
-# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
-
-# -- General configuration ------------------------------------------------
-
-# If your documentation needs a minimal Sphinx version, state it here.
-needs_sphinx = '1.8.5'
-
-# Add any Sphinx extension module names here, as strings. They can be
-# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
-# ones.
-extensions = [
- 'sphinx.ext.todo',
- 'sphinx.ext.imgmath',
-]
-
-# Add any paths that contain templates here, relative to this directory.
-templates_path = ['_templates']
-
-source_suffix = {
- '.rst': 'restructuredtext',
-}
-
-# The encoding of source files.
-#source_encoding = 'utf-8-sig'
-
-# The master toctree document.
-master_doc = 'tos'
-
-# General information about the project.
-project = u'tos'
-copyright = u'2014-2020 Taler Systems SA (GPLv3+ or GFDL 1.3+)'
-
-# The version info for the project you're documenting, acts as replacement for
-# |version| and |release|, also used in various other places throughout the
-# built documents.
-#
-# The short X.Y version.
-version = '0'
-# The full version, including alpha/beta/rc tags.
-release = '0'
-
-# The language for content autogenerated by Sphinx. Refer to documentation
-# for a list of supported languages.
-# language = "en de"
-
-# There are two options for replacing |today|: either, you set today to some
-# non-false value, then it is used:
-#today = ''
-# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
-
-# List of patterns, relative to source directory, that match files and
-# directories to ignore when looking for source files.
-exclude_patterns = ['_build', '_exts', 'cf', 'prebuilt']
-
-# The reST default role (used for this markup: `text`) to use for all
-# documents.
-# default_role = "ts:type"
-
-locale_dirs = ['locale/']
-gettext_compact = False
-
-# If true, '()' will be appended to :func: etc. cross-reference text.
-#add_function_parentheses = True
-
-# If true, the current module name will be prepended to all description
-# unit titles (such as .. function::).
-#add_module_names = True
-
-# If true, sectionauthor and moduleauthor directives will be shown in the
-# output. They are ignored by default.
-#show_authors = False
-
-# The name of the Pygments (syntax highlighting) style to use.
-pygments_style = 'sphinx'
-
-# A list of ignored prefixes for module index sorting.
-#modindex_common_prefix = []
-
-# If true, keep warnings as "system message" paragraphs in the built documents.
-#keep_warnings = False
-
-# -- Options for HTML output ----------------------------------------------
-
-# The theme to use for HTML and HTML Help pages. See the documentation for
-# a list of builtin themes.
-html_theme = 'epub'
-
-#html_theme_path = taler_sphinx_theme.html_theme_path()
-
-#html_sidebars = {'**': ['logo-text.html', 'globaltoc.html', 'searchbox.html']}
-
-rst_epilog = ""
-
-html_show_sphinx = False
-
-html_theme_options = {
- # Set the name of the project to appear in the sidebar
- "relbar1": "false",
- "footer": "false",
-}
-
-# Add any paths that contain custom themes here, relative to this directory.
-#html_theme_path = []
-
-# The name for this set of Sphinx documents. If None, it defaults to
-# "<project> v<release> documentation".
-html_title = "Taler Terms of Service"
-
-# A shorter title for the navigation bar. Default is the same as html_title.
-html_short_title = "Terms of Service"
-
-# The name of an image file (relative to this directory) to place at the top
-# of the sidebar.
-#html_logo = None
-
-# The name of an image file (within the static path) to use as favicon of the
-# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
-# pixels large.
-#html_favicon = None
-
-# Add any paths that contain custom static files (such as style sheets) here,
-# relative to this directory. They are copied after the builtin static files,
-# so a file named "default.css" will overwrite the builtin "default.css".
-# html_static_path = ['_static']
-
-# Add any extra paths that contain custom files (such as robots.txt or
-# .htaccess) here, relative to this directory. These files are copied
-# directly to the root of the documentation.
-#html_extra_path = []
-
-# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
-# using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
-
-# If true, SmartyPants will be used to convert quotes and dashes to
-# typographically correct entities.
-#html_use_smartypants = True
-
-# Custom sidebar templates, maps document names to template names.
-#html_sidebars = {}
-
-# Additional templates that should be rendered to pages, maps page names to
-# template names.
-#html_additional_pages = {}
-
-# If false, no module index is generated.
-#html_domain_indices = True
-
-# If false, no index is generated.
-#html_use_index = True
-
-# If true, the index is split into individual pages for each letter.
-#html_split_index = False
-
-# If true, links to the reST sources are added to the pages.
-#html_show_sourcelink = True
-
-# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
-html_show_sphinx = False
-
-# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
-#html_show_copyright = True
-
-# If true, an OpenSearch description file will be output, and all pages will
-# contain a <link> tag referring to it. The value of this option must be the
-# base URL from which the finished HTML is served.
-#html_use_opensearch = ''
-
-# This is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = None
-
-# -- Options for LaTeX output ---------------------------------------------
-
-latex_elements = {
- # The paper size ('letterpaper' or 'a4paper').
- #'papersize': 'letterpaper',
-
- # The font size ('10pt', '11pt' or '12pt').
- #'pointsize': '10pt',
-
- # Additional stuff for the LaTeX preamble.
- #'preamble': '',
-}
-
-# Grouping the document tree into LaTeX files. List of tuples
-# (source start file, target name, title,
-# author, documentclass [howto, manual, or own class]).
-latex_documents = [
- ('tos', 'tos.tex',
- 'Terms of Service', 'GNU Taler team', 'manual'),
-]
-
-# The name of an image file (relative to this directory) to place at the top of
-# the title page.
-#latex_logo = None
-
-# For "manual" documents, if this is true, then toplevel headings are parts,
-# not chapters.
-#latex_use_parts = False
-
-# If true, show page references after internal links.
-#latex_show_pagerefs = False
-
-# If true, show URL addresses after external links.
-#latex_show_urls = False
-
-# Documents to append as an appendix to all manuals.
-# latex_appendices = ["fdl-1.3"]
-
-# If false, no module index is generated.
-#latex_domain_indices = True
-
-# -- Options for manual page output ---------------------------------------
-
-# If true, show URL addresses after external links.
-#man_show_urls = False
-
-# -- Options for Texinfo output -------------------------------------------
-
-# Documents to append as an appendix to all manuals.
-#texinfo_appendices = []
-
-# If false, no module index is generated.
-#texinfo_domain_indices = True
-
-# How to display URL addresses: 'footnote', 'no', or 'inline'.
-#texinfo_show_urls = 'footnote'
-
-# If true, do not generate a @detailmenu in the "Top" node's menu.
-#texinfo_no_detailmenu = False
-
-
-# -- Options for epub output ----------------------------
-
-epub_basename = "tos"
-
-epub_title = "Terms of Service"
diff --git a/contrib/tos/en/0.epub b/contrib/tos/en/0.epub
deleted file mode 100644
index 4417674e6..000000000
--- a/contrib/tos/en/0.epub
+++ /dev/null
Binary files differ
diff --git a/contrib/tos/en/0.html b/contrib/tos/en/0.html
deleted file mode 100644
index 0a1c1d331..000000000
--- a/contrib/tos/en/0.html
+++ /dev/null
@@ -1,316 +0,0 @@
-
-
-<html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Terms Of Service &#8212; Taler Terms of Service</title>
- <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
- <link rel="stylesheet" href="_static/epub.css" type="text/css" />
- <script id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
- <script src="_static/jquery.js"></script>
- <script src="_static/underscore.js"></script>
- <script src="_static/doctools.js"></script>
- </head><body>
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
- <div class="body" role="main">
-
- <div class="section" id="terms-of-service">
-<h1>Terms Of Service<a class="headerlink" href="#terms-of-service" title="Permalink to this headline">¶</a></h1>
-<p>Last Updated: 09.06.2022</p>
-<p>Welcome! The ICE research center of the Bern University of Applied Sciences
-in Switzerland (“we,” “our,” or “us”) provides an experimental payment service
-through our Internet presence (collectively the “Services”). Before using our
-Services, please read the Terms of Service (the “Terms” or the “Agreement”)
-carefully.</p>
-<div class="section" id="this-is-research">
-<h2>This is research<a class="headerlink" href="#this-is-research" title="Permalink to this headline">¶</a></h2>
-<p>This is a research experiment. Any funds wired to our Bitcoin address are
-considered a donation to our research group. We may use them to enable
-payments following the GNU Taler protocol, or simply keep them at our
-discretion. The service is experimental and may also be discontinued at
-any time, in which case all remaining funds will definitively be kept by
-the research group.</p>
-</div>
-<div class="section" id="overview">
-<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">¶</a></h2>
-<p>This section provides a brief summary of the highlights of this
-Agreement. Please note that when you accept this Agreement, you are accepting
-all of the terms and conditions and not just this section. We and possibly
-other third parties provide Internet services which interact with the Taler
-Wallet’s self-hosted personal payment application. When using the Taler Wallet
-to interact with our Services, you are agreeing to our Terms, so please read
-carefully.</p>
-<div class="section" id="highlights">
-<h3>Highlights:<a class="headerlink" href="#highlights" title="Permalink to this headline">¶</a></h3>
-<blockquote>
-<div><ul class="simple">
-<li><p>You are responsible for keeping the data in your Taler Wallet at all times
-under your control. Any losses arising from you not being in control of
-your private information are your problem.</p></li>
-<li><p>We may transfer funds we receive from our users to any legal
-recipient to the best of our ability within the limitations of the law and
-our implementation. However, the Services offered today are highly
-experimental and the set of recipients of funds is severely restricted.
-Again, we stress this is a research experiment and technically all funds
-held by the exchange are owned by the research group of the university.</p></li>
-<li><p>For our Services, we may charge transaction fees. The specific fee structure
-is provided based on the Taler protocol and should be shown to you when you
-withdraw electronic coins using a Taler Wallet. You agree and understand
-that the Taler protocol allows for the fee structure to change.</p></li>
-<li><p>You agree to not intentionally overwhelm our systems with requests and
-follow responsible disclosure if you find security issues in our services.</p></li>
-<li><p>We cannot be held accountable for our Services not being available due to
-any circumstances. If we modify or terminate our services,
-we may give you the opportunity to recover your funds. However,
-given the experimental state of the Services today, this may not be
-possible. You are strongly advised to limit your use of the Service
-to small-scale experiments expecting total loss of all funds.</p></li>
-</ul>
-</div></blockquote>
-<p>These terms outline approved uses of our Services. The Services and these
-Terms are still at an experimental stage. If you have any questions or
-comments related to this Agreement, please send us a message to
-<a class="reference external" href="mailto:ice&#37;&#52;&#48;bfh&#46;ch">ice<span>&#64;</span>bfh<span>&#46;</span>ch</a>. If you do not agree to this Agreement, you must not
-use our Services.</p>
-</div>
-</div>
-<div class="section" id="how-you-accept-this-policy">
-<h2>How you accept this policy<a class="headerlink" href="#how-you-accept-this-policy" title="Permalink to this headline">¶</a></h2>
-<p>By sending funds to us (to top-up your Taler Wallet), you acknowledge that you
-have read, understood, and agreed to these Terms. We reserve the right to
-change these Terms at any time. If you disagree with the change, we may in the
-future offer you with an easy option to recover your unspent funds. However,
-in the current experimental period you acknowledge that this feature is not
-yet available, resulting in your funds being lost unless you accept the new
-Terms. If you continue to use our Services other than to recover your unspent
-funds, your continued use of our Services following any such change will
-signify your acceptance to be bound by the then current Terms. Please check
-the effective date above to determine if there have been any changes since you
-have last reviewed these Terms.</p>
-</div>
-<div class="section" id="services">
-<h2>Services<a class="headerlink" href="#services" title="Permalink to this headline">¶</a></h2>
-<p>We will try to transfer funds that we receive from users to any legal
-recipient to the best of our ability and within the limitations of the
-law. However, the Services offered today are highly experimental and the set
-of recipients of funds is severely restricted. The Taler Wallet can be loaded
-by exchanging fiat or cryptocurrencies against electronic coins. We are
-providing this exchange service. Once your Taler Wallet is loaded with
-electronic coins they can be spent for purchases if the seller is accepting
-Taler as a means of payment. We are not guaranteeing that any seller is
-accepting Taler at all or a particular seller. The seller or recipient of
-deposits of electronic coins must specify the target account, as per the
-design of the Taler protocol. They are responsible for following the protocol
-and specifying the correct bank account, and are solely liable for any losses
-that may arise from specifying the wrong account. We may allow the government
-to link wire transfers to the underlying contract hash. It is the
-responsibility of recipients to preserve the full contracts and to pay
-whatever taxes and charges may be applicable. Technical issues may lead to
-situations where we are unable to make transfers at all or lead to incorrect
-transfers that cannot be reversed. We may refuse to execute transfers if the
-transfers are prohibited by a competent legal authority and we are ordered to
-do so.</p>
-<p>When using our Services, you agree to not take any action that intentionally
-imposes an unreasonable load on our infrastructure. If you find security
-problems in our Services, you agree to first report them to
-<a class="reference external" href="mailto:security&#37;&#52;&#48;taler-systems&#46;com">security<span>&#64;</span>taler-systems<span>&#46;</span>com</a> and grant us the right to publish your report. We
-warrant that we will ourselves publicly disclose any issues reported within 3
-months, and that we will not prosecute anyone reporting security issues if
-they did not exploit the issue beyond a proof-of-concept, and followed the
-above responsible disclosure practice.</p>
-</div>
-<div class="section" id="fees">
-<h2>Fees<a class="headerlink" href="#fees" title="Permalink to this headline">¶</a></h2>
-<p>You agree to pay the fees for exchanges and withdrawals completed via the
-Taler Wallet (“Fees”) as defined by us, which we may change from time to
-time. With the exception of wire transfer fees, Taler transaction fees are set
-for any electronic coin at the time of withdrawal and fixed throughout the
-validity period of the respective electronic coin. Your wallet should obtain
-and display applicable fees when withdrawing funds. Fees for coins obtained as
-change may differ from the fees applicable to the original coin. Wire transfer
-fees that are independent from electronic coins may change annually. You
-authorize us to charge or deduct applicable fees owed in connection with
-deposits, exchanges and withdrawals following the rules of the Taler protocol.
-We reserve the right to provide different types of rewards to users either in
-the form of discount for our Services or in any other form at our discretion
-and without prior notice to you.</p>
-</div>
-<div class="section" id="eligibility-and-financial-self-responsibility">
-<h2>Eligibility and Financial self-responsibility<a class="headerlink" href="#eligibility-and-financial-self-responsibility" title="Permalink to this headline">¶</a></h2>
-<p>To be eligible to use our Services, you must be able to form legally binding
-contracts or have the permission of your legal guardian. By using our
-Services, you represent and warrant that you meet all eligibility requirements
-that we outline in these Terms.</p>
-<p>You will be responsible for maintaining the availability, integrity and
-confidentiality of the data stored in your wallet. When you setup a Taler
-Wallet, you are strongly advised to follow the precautionary measures offered
-by the software to minimize the chances to losse access to or control over
-your Wallet data. We will not be liable for any loss or damage arising from
-your failure to comply with this paragraph.</p>
-</div>
-<div class="section" id="copyrights-and-trademarks">
-<h2>Copyrights and trademarks<a class="headerlink" href="#copyrights-and-trademarks" title="Permalink to this headline">¶</a></h2>
-<p>The Taler Wallet is released under the terms of the GNU General Public License
-(GNU GPL). You have the right to access, use, and share the Taler Wallet, in
-modified or unmodified form. However, the GPL is a strong copyleft license,
-which means that any derivative works must be distributed under the same
-license terms as the original software. If you have any questions, you should
-review the GNU GPL’s full terms and conditions at
-<a class="reference external" href="https://www.gnu.org/licenses/gpl-3.0.en.html">https://www.gnu.org/licenses/gpl-3.0.en.html</a>. “Taler” itself is a trademark
-of Taler Systems SA. You are welcome to use the name in relation to processing
-payments using the Taler protocol, assuming your use is compatible with an
-official release from the GNU Project that is not older than two years.</p>
-</div>
-<div class="section" id="limitation-of-liability-disclaimer-of-warranties">
-<h2>Limitation of liability &amp; disclaimer of warranties<a class="headerlink" href="#limitation-of-liability-disclaimer-of-warranties" title="Permalink to this headline">¶</a></h2>
-<p>You understand and agree that we have no control over, and no duty to take any
-action regarding: Failures, disruptions, errors, or delays in processing that
-you may experience while using our Services; The risk of failure of hardware,
-software, and Internet connections; The risk of malicious software being
-introduced or found in the software underlying the Taler Wallet; The risk that
-third parties may obtain unauthorized access to information stored within your
-Taler Wallet, including, but not limited to your Taler Wallet coins or backup
-encryption keys. You release us from all liability related to any losses,
-damages, or claims arising from:</p>
-<ol class="loweralpha simple">
-<li><p>user error such as forgotten passwords, incorrectly constructed
-transactions;</p></li>
-<li><p>server failure or data loss;</p></li>
-<li><p>unauthorized access to the Taler Wallet application;</p></li>
-<li><p>bugs or other errors in the Taler Wallet software; and</p></li>
-<li><p>any unauthorized third party activities, including, but not limited to,
-the use of viruses, phishing, brute forcing, or other means of attack
-against the Taler Wallet. We make no representations concerning any
-Third Party Content contained in or accessed through our Services.</p></li>
-</ol>
-<p>Any other terms, conditions, warranties, or representations associated with
-such content, are solely between you and such organizations and/or
-individuals.</p>
-<p>To the fullest extent permitted by applicable law, in no event will we or any
-of our officers, directors, representatives, agents, servants, counsel,
-employees, consultants, lawyers, and other personnel authorized to act,
-acting, or purporting to act on our behalf (collectively the “Taler Parties”)
-be liable to you under contract, tort, strict liability, negligence, or any
-other legal or equitable theory, for:</p>
-<ol class="loweralpha simple">
-<li><p>any lost profits, data loss, cost of procurement of substitute goods or
-services, or direct, indirect, incidental, special, punitive, compensatory,
-or consequential damages of any kind whatsoever resulting from:</p></li>
-</ol>
-<blockquote>
-<div><ol class="lowerroman simple">
-<li><p>your use of, or conduct in connection with, our services;</p></li>
-<li><p>any unauthorized use of your wallet and/or private key due to your
-failure to maintain the confidentiality of your wallet;</p></li>
-<li><p>any interruption or cessation of transmission to or from the services; or</p></li>
-<li><p>any bugs, viruses, trojan horses, or the like that are found in the Taler
-Wallet software or that may be transmitted to or through our services by
-any third party (regardless of the source of origination), or</p></li>
-</ol>
-</div></blockquote>
-<ol class="loweralpha simple" start="2">
-<li><p>any direct damages.</p></li>
-</ol>
-<p>These limitations apply regardless of legal theory, whether based on tort,
-strict liability, breach of contract, breach of warranty, or any other legal
-theory, and whether or not we were advised of the possibility of such
-damages. Some jurisdictions do not allow the exclusion or limitation of
-liability for consequential or incidental damages, so the above limitation may
-not apply to you.</p>
-<p>Our services are provided “as is” and without warranty of any kind. To the
-maximum extent permitted by law, we disclaim all representations and
-warranties, express or implied, relating to the services and underlying
-software or any content on the services, whether provided or owned by us or by
-any third party, including without limitation, warranties of merchantability,
-fitness for a particular purpose, title, non-infringement, freedom from
-computer virus, and any implied warranties arising from course of dealing,
-course of performance, or usage in trade, all of which are expressly
-disclaimed. In addition, we do not represent or warrant that the content
-accessible via the services is accurate, complete, available, current, free of
-viruses or other harmful components, or that the results of using the services
-will meet your requirements. Some states do not allow the disclaimer of
-implied warranties, so the foregoing disclaimers may not apply to you. This
-paragraph gives you specific legal rights and you may also have other legal
-rights that vary from state to state.</p>
-</div>
-<div class="section" id="indemnity-and-time-limitation-on-claims-and-termination">
-<h2>Indemnity and Time limitation on claims and Termination<a class="headerlink" href="#indemnity-and-time-limitation-on-claims-and-termination" title="Permalink to this headline">¶</a></h2>
-<p>To the extent permitted by applicable law, you agree to defend, indemnify, and
-hold harmless the Taler Parties from and against any and all claims, damages,
-obligations, losses, liabilities, costs or debt, and expenses (including, but
-not limited to, attorney’s fees) arising from: (a) your use of and access to
-the Services; (b) any feedback or submissions you provide to us concerning the
-Taler Wallet; (c) your violation of any term of this Agreement; or (d) your
-violation of any law, rule, or regulation, or the rights of any third party.</p>
-<p>You agree that any claim you may have arising out of or related to your
-relationship with us must be filed within one year after such claim arises,
-otherwise, your claim in permanently barred.</p>
-<p>In the event of termination concerning your use of our Services, your
-obligations under this Agreement will still continue.</p>
-</div>
-<div class="section" id="discontinuance-of-services-and-force-majeure">
-<h2>Discontinuance of services and Force majeure<a class="headerlink" href="#discontinuance-of-services-and-force-majeure" title="Permalink to this headline">¶</a></h2>
-<p>We may, in our sole discretion and without cost to you, with or without prior
-notice, and at any time, modify or discontinue, temporarily or permanently,
-any portion of our Services. We will use the Taler protocol’s provisions to
-notify Wallets if our Services are to be discontinued. It is your
-responsibility to ensure that the Taler Wallet is online at least once every
-three months to observe these notifications. We shall not be held responsible
-or liable for any loss of funds in the event that we discontinue or depreciate
-the Services and your Taler Wallet fails to transfer out the coins within a
-three months notification period.</p>
-<p>We shall not be held liable for any delays, failure in performance, or
-interruptions of service which result directly or indirectly from any cause or
-condition beyond our reasonable control, including but not limited to: any
-delay or failure due to any act of God, act of civil or military authorities,
-act of terrorism, civil disturbance, war, strike or other labor dispute, fire,
-interruption in telecommunications or Internet services or network provider
-services, failure of equipment and/or software, other catastrophe, or any
-other occurrence which is beyond our reasonable control and shall not affect
-the validity and enforceability of any remaining provisions.</p>
-</div>
-<div class="section" id="governing-law-waivers-severability-and-assignment">
-<h2>Governing law, Waivers, Severability and Assignment<a class="headerlink" href="#governing-law-waivers-severability-and-assignment" title="Permalink to this headline">¶</a></h2>
-<p>No matter where you’re located, the laws of Switzerland will govern these
-Terms. If any provisions of these Terms are inconsistent with any applicable
-law, those provisions will be superseded or modified only to the extent such
-provisions are inconsistent. The parties agree to submit to the ordinary
-courts in Bern, Switzerland for exclusive jurisdiction of any dispute
-arising out of or related to your use of the Services or your breach of these
-Terms.</p>
-<p>Our failure to exercise or delay in exercising any right, power, or privilege
-under this Agreement shall not operate as a waiver; nor shall any single or
-partial exercise of any right, power, or privilege preclude any other or
-further exercise thereof.</p>
-<p>You agree that we may assign any of our rights and/or transfer, sub-contract,
-or delegate any of our obligations under these Terms.</p>
-<p>If it turns out that any part of this Agreement is invalid, void, or for any
-reason unenforceable, that term will be deemed severable and limited or
-eliminated to the minimum extent necessary.</p>
-<p>This Agreement sets forth the entire understanding and agreement as to the
-subject matter hereof and supersedes any and all prior discussions,
-agreements, and understandings of any kind (including, without limitation, any
-prior versions of this Agreement) and every nature between us. Except as
-provided for above, any modification to this Agreement must be in writing and
-must be signed by both parties.</p>
-</div>
-<div class="section" id="questions-or-comments">
-<h2>Questions or comments<a class="headerlink" href="#questions-or-comments" title="Permalink to this headline">¶</a></h2>
-<p>We welcome comments, questions, concerns, or suggestions. Please send us a
-message on our contact page at <a class="reference external" href="mailto:legal&#37;&#52;&#48;taler-systems&#46;com">legal<span>&#64;</span>taler-systems<span>&#46;</span>com</a>.</p>
-</div>
-</div>
-
-
- <div class="clearer"></div>
- </div>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- </body>
-</html> \ No newline at end of file
diff --git a/contrib/tos/en/0.pdf b/contrib/tos/en/0.pdf
deleted file mode 100644
index f145a83a4..000000000
--- a/contrib/tos/en/0.pdf
+++ /dev/null
Binary files differ
diff --git a/contrib/tos/en/0.txt b/contrib/tos/en/0.txt
deleted file mode 100644
index 19db09844..000000000
--- a/contrib/tos/en/0.txt
+++ /dev/null
@@ -1,349 +0,0 @@
-Terms Of Service
-****************
-
-Last Updated: 09.06.2022
-
-Welcome! The ICE research center of the Bern University of Applied
-Sciences in Switzerland (“we,” “our,” or “us”) provides an
-experimental payment service through our Internet presence
-(collectively the “Services”). Before using our Services, please read
-the Terms of Service (the “Terms” or the “Agreement”) carefully.
-
-
-This is research
-================
-
-This is a research experiment. Any funds wired to our Bitcoin address
-are considered a donation to our research group. We may use them to
-enable payments following the GNU Taler protocol, or simply keep them
-at our discretion. The service is experimental and may also be
-discontinued at any time, in which case all remaining funds will
-definitively be kept by the research group.
-
-
-Overview
-========
-
-This section provides a brief summary of the highlights of this
-Agreement. Please note that when you accept this Agreement, you are
-accepting all of the terms and conditions and not just this section.
-We and possibly other third parties provide Internet services which
-interact with the Taler Wallet’s self-hosted personal payment
-application. When using the Taler Wallet to interact with our
-Services, you are agreeing to our Terms, so please read carefully.
-
-
-Highlights:
------------
-
- * You are responsible for keeping the data in your Taler Wallet at
- all times under your control. Any losses arising from you not
- being in control of your private information are your problem.
-
- * We may transfer funds we receive from our users to any legal
- recipient to the best of our ability within the limitations of
- the law and our implementation. However, the Services offered
- today are highly experimental and the set of recipients of funds
- is severely restricted. Again, we stress this is a research
- experiment and technically all funds held by the exchange are
- owned by the research group of the university.
-
- * For our Services, we may charge transaction fees. The specific
- fee structure is provided based on the Taler protocol and should
- be shown to you when you withdraw electronic coins using a Taler
- Wallet. You agree and understand that the Taler protocol allows
- for the fee structure to change.
-
- * You agree to not intentionally overwhelm our systems with
- requests and follow responsible disclosure if you find security
- issues in our services.
-
- * We cannot be held accountable for our Services not being
- available due to any circumstances. If we modify or terminate our
- services, we may give you the opportunity to recover your funds.
- However, given the experimental state of the Services today, this
- may not be possible. You are strongly advised to limit your use
- of the Service to small-scale experiments expecting total loss of
- all funds.
-
-These terms outline approved uses of our Services. The Services and
-these Terms are still at an experimental stage. If you have any
-questions or comments related to this Agreement, please send us a
-message to ice@bfh.ch. If you do not agree to this Agreement, you must
-not use our Services.
-
-
-How you accept this policy
-==========================
-
-By sending funds to us (to top-up your Taler Wallet), you acknowledge
-that you have read, understood, and agreed to these Terms. We reserve
-the right to change these Terms at any time. If you disagree with the
-change, we may in the future offer you with an easy option to recover
-your unspent funds. However, in the current experimental period you
-acknowledge that this feature is not yet available, resulting in your
-funds being lost unless you accept the new Terms. If you continue to
-use our Services other than to recover your unspent funds, your
-continued use of our Services following any such change will signify
-your acceptance to be bound by the then current Terms. Please check
-the effective date above to determine if there have been any changes
-since you have last reviewed these Terms.
-
-
-Services
-========
-
-We will try to transfer funds that we receive from users to any legal
-recipient to the best of our ability and within the limitations of the
-law. However, the Services offered today are highly experimental and
-the set of recipients of funds is severely restricted. The Taler
-Wallet can be loaded by exchanging fiat or cryptocurrencies against
-electronic coins. We are providing this exchange service. Once your
-Taler Wallet is loaded with electronic coins they can be spent for
-purchases if the seller is accepting Taler as a means of payment. We
-are not guaranteeing that any seller is accepting Taler at all or a
-particular seller. The seller or recipient of deposits of electronic
-coins must specify the target account, as per the design of the Taler
-protocol. They are responsible for following the protocol and
-specifying the correct bank account, and are solely liable for any
-losses that may arise from specifying the wrong account. We may allow
-the government to link wire transfers to the underlying contract hash.
-It is the responsibility of recipients to preserve the full contracts
-and to pay whatever taxes and charges may be applicable. Technical
-issues may lead to situations where we are unable to make transfers at
-all or lead to incorrect transfers that cannot be reversed. We may
-refuse to execute transfers if the transfers are prohibited by a
-competent legal authority and we are ordered to do so.
-
-When using our Services, you agree to not take any action that
-intentionally imposes an unreasonable load on our infrastructure. If
-you find security problems in our Services, you agree to first report
-them to security@taler-systems.com and grant us the right to publish
-your report. We warrant that we will ourselves publicly disclose any
-issues reported within 3 months, and that we will not prosecute anyone
-reporting security issues if they did not exploit the issue beyond a
-proof-of-concept, and followed the above responsible disclosure
-practice.
-
-
-Fees
-====
-
-You agree to pay the fees for exchanges and withdrawals completed via
-the Taler Wallet ("Fees") as defined by us, which we may change from
-time to time. With the exception of wire transfer fees, Taler
-transaction fees are set for any electronic coin at the time of
-withdrawal and fixed throughout the validity period of the respective
-electronic coin. Your wallet should obtain and display applicable fees
-when withdrawing funds. Fees for coins obtained as change may differ
-from the fees applicable to the original coin. Wire transfer fees that
-are independent from electronic coins may change annually. You
-authorize us to charge or deduct applicable fees owed in connection
-with deposits, exchanges and withdrawals following the rules of the
-Taler protocol. We reserve the right to provide different types of
-rewards to users either in the form of discount for our Services or in
-any other form at our discretion and without prior notice to you.
-
-
-Eligibility and Financial self-responsibility
-=============================================
-
-To be eligible to use our Services, you must be able to form legally
-binding contracts or have the permission of your legal guardian. By
-using our Services, you represent and warrant that you meet all
-eligibility requirements that we outline in these Terms.
-
-You will be responsible for maintaining the availability, integrity
-and confidentiality of the data stored in your wallet. When you setup
-a Taler Wallet, you are strongly advised to follow the precautionary
-measures offered by the software to minimize the chances to losse
-access to or control over your Wallet data. We will not be liable for
-any loss or damage arising from your failure to comply with this
-paragraph.
-
-
-Copyrights and trademarks
-=========================
-
-The Taler Wallet is released under the terms of the GNU General Public
-License (GNU GPL). You have the right to access, use, and share the
-Taler Wallet, in modified or unmodified form. However, the GPL is a
-strong copyleft license, which means that any derivative works must be
-distributed under the same license terms as the original software. If
-you have any questions, you should review the GNU GPL’s full terms and
-conditions at https://www.gnu.org/licenses/gpl-3.0.en.html. “Taler”
-itself is a trademark of Taler Systems SA. You are welcome to use the
-name in relation to processing payments using the Taler protocol,
-assuming your use is compatible with an official release from the GNU
-Project that is not older than two years.
-
-
-Limitation of liability & disclaimer of warranties
-==================================================
-
-You understand and agree that we have no control over, and no duty to
-take any action regarding: Failures, disruptions, errors, or delays in
-processing that you may experience while using our Services; The risk
-of failure of hardware, software, and Internet connections; The risk
-of malicious software being introduced or found in the software
-underlying the Taler Wallet; The risk that third parties may obtain
-unauthorized access to information stored within your Taler Wallet,
-including, but not limited to your Taler Wallet coins or backup
-encryption keys. You release us from all liability related to any
-losses, damages, or claims arising from:
-
-1. user error such as forgotten passwords, incorrectly constructed
- transactions;
-
-2. server failure or data loss;
-
-3. unauthorized access to the Taler Wallet application;
-
-4. bugs or other errors in the Taler Wallet software; and
-
-5. any unauthorized third party activities, including, but not limited
- to, the use of viruses, phishing, brute forcing, or other means of
- attack against the Taler Wallet. We make no representations
- concerning any Third Party Content contained in or accessed through
- our Services.
-
-Any other terms, conditions, warranties, or representations associated
-with such content, are solely between you and such organizations
-and/or individuals.
-
-To the fullest extent permitted by applicable law, in no event will we
-or any of our officers, directors, representatives, agents, servants,
-counsel, employees, consultants, lawyers, and other personnel
-authorized to act, acting, or purporting to act on our behalf
-(collectively the “Taler Parties”) be liable to you under contract,
-tort, strict liability, negligence, or any other legal or equitable
-theory, for:
-
-1. any lost profits, data loss, cost of procurement of substitute
- goods or services, or direct, indirect, incidental, special,
- punitive, compensatory, or consequential damages of any kind
- whatsoever resulting from:
-
- 1. your use of, or conduct in connection with, our services;
-
- 2. any unauthorized use of your wallet and/or private key due to
- your failure to maintain the confidentiality of your wallet;
-
- 3. any interruption or cessation of transmission to or from the
- services; or
-
- 4. any bugs, viruses, trojan horses, or the like that are found in
- the Taler Wallet software or that may be transmitted to or
- through our services by any third party (regardless of the
- source of origination), or
-
-2. any direct damages.
-
-These limitations apply regardless of legal theory, whether based on
-tort, strict liability, breach of contract, breach of warranty, or any
-other legal theory, and whether or not we were advised of the
-possibility of such damages. Some jurisdictions do not allow the
-exclusion or limitation of liability for consequential or incidental
-damages, so the above limitation may not apply to you.
-
-Our services are provided "as is" and without warranty of any kind. To
-the maximum extent permitted by law, we disclaim all representations
-and warranties, express or implied, relating to the services and
-underlying software or any content on the services, whether provided
-or owned by us or by any third party, including without limitation,
-warranties of merchantability, fitness for a particular purpose,
-title, non-infringement, freedom from computer virus, and any implied
-warranties arising from course of dealing, course of performance, or
-usage in trade, all of which are expressly disclaimed. In addition, we
-do not represent or warrant that the content accessible via the
-services is accurate, complete, available, current, free of viruses or
-other harmful components, or that the results of using the services
-will meet your requirements. Some states do not allow the disclaimer
-of implied warranties, so the foregoing disclaimers may not apply to
-you. This paragraph gives you specific legal rights and you may also
-have other legal rights that vary from state to state.
-
-
-Indemnity and Time limitation on claims and Termination
-=======================================================
-
-To the extent permitted by applicable law, you agree to defend,
-indemnify, and hold harmless the Taler Parties from and against any
-and all claims, damages, obligations, losses, liabilities, costs or
-debt, and expenses (including, but not limited to, attorney’s fees)
-arising from: (a) your use of and access to the Services; (b) any
-feedback or submissions you provide to us concerning the Taler Wallet;
-(c) your violation of any term of this Agreement; or (d) your
-violation of any law, rule, or regulation, or the rights of any third
-party.
-
-You agree that any claim you may have arising out of or related to
-your relationship with us must be filed within one year after such
-claim arises, otherwise, your claim in permanently barred.
-
-In the event of termination concerning your use of our Services, your
-obligations under this Agreement will still continue.
-
-
-Discontinuance of services and Force majeure
-============================================
-
-We may, in our sole discretion and without cost to you, with or
-without prior notice, and at any time, modify or discontinue,
-temporarily or permanently, any portion of our Services. We will use
-the Taler protocol’s provisions to notify Wallets if our Services are
-to be discontinued. It is your responsibility to ensure that the Taler
-Wallet is online at least once every three months to observe these
-notifications. We shall not be held responsible or liable for any loss
-of funds in the event that we discontinue or depreciate the Services
-and your Taler Wallet fails to transfer out the coins within a three
-months notification period.
-
-We shall not be held liable for any delays, failure in performance, or
-interruptions of service which result directly or indirectly from any
-cause or condition beyond our reasonable control, including but not
-limited to: any delay or failure due to any act of God, act of civil
-or military authorities, act of terrorism, civil disturbance, war,
-strike or other labor dispute, fire, interruption in
-telecommunications or Internet services or network provider services,
-failure of equipment and/or software, other catastrophe, or any other
-occurrence which is beyond our reasonable control and shall not affect
-the validity and enforceability of any remaining provisions.
-
-
-Governing law, Waivers, Severability and Assignment
-===================================================
-
-No matter where you’re located, the laws of Switzerland will govern
-these Terms. If any provisions of these Terms are inconsistent with
-any applicable law, those provisions will be superseded or modified
-only to the extent such provisions are inconsistent. The parties agree
-to submit to the ordinary courts in Bern, Switzerland for exclusive
-jurisdiction of any dispute arising out of or related to your use of
-the Services or your breach of these Terms.
-
-Our failure to exercise or delay in exercising any right, power, or
-privilege under this Agreement shall not operate as a waiver; nor
-shall any single or partial exercise of any right, power, or privilege
-preclude any other or further exercise thereof.
-
-You agree that we may assign any of our rights and/or transfer, sub-
-contract, or delegate any of our obligations under these Terms.
-
-If it turns out that any part of this Agreement is invalid, void, or
-for any reason unenforceable, that term will be deemed severable and
-limited or eliminated to the minimum extent necessary.
-
-This Agreement sets forth the entire understanding and agreement as to
-the subject matter hereof and supersedes any and all prior
-discussions, agreements, and understandings of any kind (including,
-without limitation, any prior versions of this Agreement) and every
-nature between us. Except as provided for above, any modification to
-this Agreement must be in writing and must be signed by both parties.
-
-
-Questions or comments
-=====================
-
-We welcome comments, questions, concerns, or suggestions. Please send
-us a message on our contact page at legal@taler-systems.com.
diff --git a/contrib/tos/en/0.xml b/contrib/tos/en/0.xml
deleted file mode 100644
index 7f42db04d..000000000
--- a/contrib/tos/en/0.xml
+++ /dev/null
@@ -1,323 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE document PUBLIC "+//IDN docutils.sourceforge.net//DTD Docutils Generic//EN//XML" "http://docutils.sourceforge.net/docs/ref/docutils.dtd">
-<!-- Generated by Docutils 0.16 -->
-<document source="/home/grothoff/research/taler/exchange/contrib/tos/tos.rst">
- <section ids="terms-of-service" names="terms\ of\ service">
- <title>Terms Of Service</title>
- <paragraph>Last Updated: 09.06.2022</paragraph>
- <paragraph>Welcome! The ICE research center of the Bern University of Applied Sciences
- in Switzerland (“we,” “our,” or “us”) provides an experimental payment service
- through our Internet presence (collectively the “Services”). Before using our
- Services, please read the Terms of Service (the “Terms” or the “Agreement”)
- carefully.</paragraph>
- <section ids="this-is-research" names="this\ is\ research">
- <title>This is research</title>
- <paragraph>This is a research experiment. Any funds wired to our Bitcoin address are
- considered a donation to our research group. We may use them to enable
- payments following the GNU Taler protocol, or simply keep them at our
- discretion. The service is experimental and may also be discontinued at
- any time, in which case all remaining funds will definitively be kept by
- the research group.</paragraph>
- </section>
- <section ids="overview" names="overview">
- <title>Overview</title>
- <paragraph>This section provides a brief summary of the highlights of this
- Agreement. Please note that when you accept this Agreement, you are accepting
- all of the terms and conditions and not just this section. We and possibly
- other third parties provide Internet services which interact with the Taler
- Wallet’s self-hosted personal payment application. When using the Taler Wallet
- to interact with our Services, you are agreeing to our Terms, so please read
- carefully.</paragraph>
- <section ids="highlights" names="highlights:">
- <title>Highlights:</title>
- <block_quote>
- <bullet_list bullet="•">
- <list_item>
- <paragraph>You are responsible for keeping the data in your Taler Wallet at all times
- under your control. Any losses arising from you not being in control of
- your private information are your problem.</paragraph>
- </list_item>
- <list_item>
- <paragraph>We may transfer funds we receive from our users to any legal
- recipient to the best of our ability within the limitations of the law and
- our implementation. However, the Services offered today are highly
- experimental and the set of recipients of funds is severely restricted.
- Again, we stress this is a research experiment and technically all funds
- held by the exchange are owned by the research group of the university.</paragraph>
- </list_item>
- <list_item>
- <paragraph>For our Services, we may charge transaction fees. The specific fee structure
- is provided based on the Taler protocol and should be shown to you when you
- withdraw electronic coins using a Taler Wallet. You agree and understand
- that the Taler protocol allows for the fee structure to change.</paragraph>
- </list_item>
- <list_item>
- <paragraph>You agree to not intentionally overwhelm our systems with requests and
- follow responsible disclosure if you find security issues in our services.</paragraph>
- </list_item>
- <list_item>
- <paragraph>We cannot be held accountable for our Services not being available due to
- any circumstances. If we modify or terminate our services,
- we may give you the opportunity to recover your funds. However,
- given the experimental state of the Services today, this may not be
- possible. You are strongly advised to limit your use of the Service
- to small-scale experiments expecting total loss of all funds.</paragraph>
- </list_item>
- </bullet_list>
- </block_quote>
- <paragraph>These terms outline approved uses of our Services. The Services and these
- Terms are still at an experimental stage. If you have any questions or
- comments related to this Agreement, please send us a message to
- <reference refuri="mailto:ice@bfh.ch">ice@bfh.ch</reference>. If you do not agree to this Agreement, you must not
- use our Services.</paragraph>
- </section>
- </section>
- <section ids="how-you-accept-this-policy" names="how\ you\ accept\ this\ policy">
- <title>How you accept this policy</title>
- <paragraph>By sending funds to us (to top-up your Taler Wallet), you acknowledge that you
- have read, understood, and agreed to these Terms. We reserve the right to
- change these Terms at any time. If you disagree with the change, we may in the
- future offer you with an easy option to recover your unspent funds. However,
- in the current experimental period you acknowledge that this feature is not
- yet available, resulting in your funds being lost unless you accept the new
- Terms. If you continue to use our Services other than to recover your unspent
- funds, your continued use of our Services following any such change will
- signify your acceptance to be bound by the then current Terms. Please check
- the effective date above to determine if there have been any changes since you
- have last reviewed these Terms.</paragraph>
- </section>
- <section ids="services" names="services">
- <title>Services</title>
- <paragraph>We will try to transfer funds that we receive from users to any legal
- recipient to the best of our ability and within the limitations of the
- law. However, the Services offered today are highly experimental and the set
- of recipients of funds is severely restricted. The Taler Wallet can be loaded
- by exchanging fiat or cryptocurrencies against electronic coins. We are
- providing this exchange service. Once your Taler Wallet is loaded with
- electronic coins they can be spent for purchases if the seller is accepting
- Taler as a means of payment. We are not guaranteeing that any seller is
- accepting Taler at all or a particular seller. The seller or recipient of
- deposits of electronic coins must specify the target account, as per the
- design of the Taler protocol. They are responsible for following the protocol
- and specifying the correct bank account, and are solely liable for any losses
- that may arise from specifying the wrong account. We may allow the government
- to link wire transfers to the underlying contract hash. It is the
- responsibility of recipients to preserve the full contracts and to pay
- whatever taxes and charges may be applicable. Technical issues may lead to
- situations where we are unable to make transfers at all or lead to incorrect
- transfers that cannot be reversed. We may refuse to execute transfers if the
- transfers are prohibited by a competent legal authority and we are ordered to
- do so.</paragraph>
- <paragraph>When using our Services, you agree to not take any action that intentionally
- imposes an unreasonable load on our infrastructure. If you find security
- problems in our Services, you agree to first report them to
- <reference refuri="mailto:security@taler-systems.com">security@taler-systems.com</reference> and grant us the right to publish your report. We
- warrant that we will ourselves publicly disclose any issues reported within 3
- months, and that we will not prosecute anyone reporting security issues if
- they did not exploit the issue beyond a proof-of-concept, and followed the
- above responsible disclosure practice.</paragraph>
- </section>
- <section ids="fees" names="fees">
- <title>Fees</title>
- <paragraph>You agree to pay the fees for exchanges and withdrawals completed via the
- Taler Wallet (“Fees”) as defined by us, which we may change from time to
- time. With the exception of wire transfer fees, Taler transaction fees are set
- for any electronic coin at the time of withdrawal and fixed throughout the
- validity period of the respective electronic coin. Your wallet should obtain
- and display applicable fees when withdrawing funds. Fees for coins obtained as
- change may differ from the fees applicable to the original coin. Wire transfer
- fees that are independent from electronic coins may change annually. You
- authorize us to charge or deduct applicable fees owed in connection with
- deposits, exchanges and withdrawals following the rules of the Taler protocol.
- We reserve the right to provide different types of rewards to users either in
- the form of discount for our Services or in any other form at our discretion
- and without prior notice to you.</paragraph>
- </section>
- <section ids="eligibility-and-financial-self-responsibility" names="eligibility\ and\ financial\ self-responsibility">
- <title>Eligibility and Financial self-responsibility</title>
- <paragraph>To be eligible to use our Services, you must be able to form legally binding
- contracts or have the permission of your legal guardian. By using our
- Services, you represent and warrant that you meet all eligibility requirements
- that we outline in these Terms.</paragraph>
- <paragraph>You will be responsible for maintaining the availability, integrity and
- confidentiality of the data stored in your wallet. When you setup a Taler
- Wallet, you are strongly advised to follow the precautionary measures offered
- by the software to minimize the chances to losse access to or control over
- your Wallet data. We will not be liable for any loss or damage arising from
- your failure to comply with this paragraph.</paragraph>
- </section>
- <section ids="copyrights-and-trademarks" names="copyrights\ and\ trademarks">
- <title>Copyrights and trademarks</title>
- <paragraph>The Taler Wallet is released under the terms of the GNU General Public License
- (GNU GPL). You have the right to access, use, and share the Taler Wallet, in
- modified or unmodified form. However, the GPL is a strong copyleft license,
- which means that any derivative works must be distributed under the same
- license terms as the original software. If you have any questions, you should
- review the GNU GPL’s full terms and conditions at
- <reference refuri="https://www.gnu.org/licenses/gpl-3.0.en.html">https://www.gnu.org/licenses/gpl-3.0.en.html</reference>. “Taler” itself is a trademark
- of Taler Systems SA. You are welcome to use the name in relation to processing
- payments using the Taler protocol, assuming your use is compatible with an
- official release from the GNU Project that is not older than two years.</paragraph>
- </section>
- <section ids="limitation-of-liability-disclaimer-of-warranties" names="limitation\ of\ liability\ &amp;\ disclaimer\ of\ warranties">
- <title>Limitation of liability &amp; disclaimer of warranties</title>
- <paragraph>You understand and agree that we have no control over, and no duty to take any
- action regarding: Failures, disruptions, errors, or delays in processing that
- you may experience while using our Services; The risk of failure of hardware,
- software, and Internet connections; The risk of malicious software being
- introduced or found in the software underlying the Taler Wallet; The risk that
- third parties may obtain unauthorized access to information stored within your
- Taler Wallet, including, but not limited to your Taler Wallet coins or backup
- encryption keys. You release us from all liability related to any losses,
- damages, or claims arising from:</paragraph>
- <enumerated_list enumtype="loweralpha" prefix="(" suffix=")">
- <list_item>
- <paragraph>user error such as forgotten passwords, incorrectly constructed
- transactions;</paragraph>
- </list_item>
- <list_item>
- <paragraph>server failure or data loss;</paragraph>
- </list_item>
- <list_item>
- <paragraph>unauthorized access to the Taler Wallet application;</paragraph>
- </list_item>
- <list_item>
- <paragraph>bugs or other errors in the Taler Wallet software; and</paragraph>
- </list_item>
- <list_item>
- <paragraph>any unauthorized third party activities, including, but not limited to,
- the use of viruses, phishing, brute forcing, or other means of attack
- against the Taler Wallet. We make no representations concerning any
- Third Party Content contained in or accessed through our Services.</paragraph>
- </list_item>
- </enumerated_list>
- <paragraph>Any other terms, conditions, warranties, or representations associated with
- such content, are solely between you and such organizations and/or
- individuals.</paragraph>
- <paragraph>To the fullest extent permitted by applicable law, in no event will we or any
- of our officers, directors, representatives, agents, servants, counsel,
- employees, consultants, lawyers, and other personnel authorized to act,
- acting, or purporting to act on our behalf (collectively the “Taler Parties”)
- be liable to you under contract, tort, strict liability, negligence, or any
- other legal or equitable theory, for:</paragraph>
- <enumerated_list enumtype="loweralpha" prefix="(" suffix=")">
- <list_item>
- <paragraph>any lost profits, data loss, cost of procurement of substitute goods or
- services, or direct, indirect, incidental, special, punitive, compensatory,
- or consequential damages of any kind whatsoever resulting from:</paragraph>
- </list_item>
- </enumerated_list>
- <block_quote>
- <enumerated_list enumtype="lowerroman" prefix="(" suffix=")">
- <list_item>
- <paragraph>your use of, or conduct in connection with, our services;</paragraph>
- </list_item>
- <list_item>
- <paragraph>any unauthorized use of your wallet and/or private key due to your
- failure to maintain the confidentiality of your wallet;</paragraph>
- </list_item>
- <list_item>
- <paragraph>any interruption or cessation of transmission to or from the services; or</paragraph>
- </list_item>
- <list_item>
- <paragraph>any bugs, viruses, trojan horses, or the like that are found in the Taler
- Wallet software or that may be transmitted to or through our services by
- any third party (regardless of the source of origination), or</paragraph>
- </list_item>
- </enumerated_list>
- </block_quote>
- <enumerated_list enumtype="loweralpha" prefix="(" start="2" suffix=")">
- <list_item>
- <paragraph>any direct damages.</paragraph>
- </list_item>
- </enumerated_list>
- <paragraph>These limitations apply regardless of legal theory, whether based on tort,
- strict liability, breach of contract, breach of warranty, or any other legal
- theory, and whether or not we were advised of the possibility of such
- damages. Some jurisdictions do not allow the exclusion or limitation of
- liability for consequential or incidental damages, so the above limitation may
- not apply to you.</paragraph>
- <paragraph>Our services are provided “as is” and without warranty of any kind. To the
- maximum extent permitted by law, we disclaim all representations and
- warranties, express or implied, relating to the services and underlying
- software or any content on the services, whether provided or owned by us or by
- any third party, including without limitation, warranties of merchantability,
- fitness for a particular purpose, title, non-infringement, freedom from
- computer virus, and any implied warranties arising from course of dealing,
- course of performance, or usage in trade, all of which are expressly
- disclaimed. In addition, we do not represent or warrant that the content
- accessible via the services is accurate, complete, available, current, free of
- viruses or other harmful components, or that the results of using the services
- will meet your requirements. Some states do not allow the disclaimer of
- implied warranties, so the foregoing disclaimers may not apply to you. This
- paragraph gives you specific legal rights and you may also have other legal
- rights that vary from state to state.</paragraph>
- </section>
- <section ids="indemnity-and-time-limitation-on-claims-and-termination" names="indemnity\ and\ time\ limitation\ on\ claims\ and\ termination">
- <title>Indemnity and Time limitation on claims and Termination</title>
- <paragraph>To the extent permitted by applicable law, you agree to defend, indemnify, and
- hold harmless the Taler Parties from and against any and all claims, damages,
- obligations, losses, liabilities, costs or debt, and expenses (including, but
- not limited to, attorney’s fees) arising from: (a) your use of and access to
- the Services; (b) any feedback or submissions you provide to us concerning the
- Taler Wallet; (c) your violation of any term of this Agreement; or (d) your
- violation of any law, rule, or regulation, or the rights of any third party.</paragraph>
- <paragraph>You agree that any claim you may have arising out of or related to your
- relationship with us must be filed within one year after such claim arises,
- otherwise, your claim in permanently barred.</paragraph>
- <paragraph>In the event of termination concerning your use of our Services, your
- obligations under this Agreement will still continue.</paragraph>
- </section>
- <section ids="discontinuance-of-services-and-force-majeure" names="discontinuance\ of\ services\ and\ force\ majeure">
- <title>Discontinuance of services and Force majeure</title>
- <paragraph>We may, in our sole discretion and without cost to you, with or without prior
- notice, and at any time, modify or discontinue, temporarily or permanently,
- any portion of our Services. We will use the Taler protocol’s provisions to
- notify Wallets if our Services are to be discontinued. It is your
- responsibility to ensure that the Taler Wallet is online at least once every
- three months to observe these notifications. We shall not be held responsible
- or liable for any loss of funds in the event that we discontinue or depreciate
- the Services and your Taler Wallet fails to transfer out the coins within a
- three months notification period.</paragraph>
- <paragraph>We shall not be held liable for any delays, failure in performance, or
- interruptions of service which result directly or indirectly from any cause or
- condition beyond our reasonable control, including but not limited to: any
- delay or failure due to any act of God, act of civil or military authorities,
- act of terrorism, civil disturbance, war, strike or other labor dispute, fire,
- interruption in telecommunications or Internet services or network provider
- services, failure of equipment and/or software, other catastrophe, or any
- other occurrence which is beyond our reasonable control and shall not affect
- the validity and enforceability of any remaining provisions.</paragraph>
- </section>
- <section ids="governing-law-waivers-severability-and-assignment" names="governing\ law,\ waivers,\ severability\ and\ assignment">
- <title>Governing law, Waivers, Severability and Assignment</title>
- <paragraph>No matter where you’re located, the laws of Switzerland will govern these
- Terms. If any provisions of these Terms are inconsistent with any applicable
- law, those provisions will be superseded or modified only to the extent such
- provisions are inconsistent. The parties agree to submit to the ordinary
- courts in Bern, Switzerland for exclusive jurisdiction of any dispute
- arising out of or related to your use of the Services or your breach of these
- Terms.</paragraph>
- <paragraph>Our failure to exercise or delay in exercising any right, power, or privilege
- under this Agreement shall not operate as a waiver; nor shall any single or
- partial exercise of any right, power, or privilege preclude any other or
- further exercise thereof.</paragraph>
- <paragraph>You agree that we may assign any of our rights and/or transfer, sub-contract,
- or delegate any of our obligations under these Terms.</paragraph>
- <paragraph>If it turns out that any part of this Agreement is invalid, void, or for any
- reason unenforceable, that term will be deemed severable and limited or
- eliminated to the minimum extent necessary.</paragraph>
- <paragraph>This Agreement sets forth the entire understanding and agreement as to the
- subject matter hereof and supersedes any and all prior discussions,
- agreements, and understandings of any kind (including, without limitation, any
- prior versions of this Agreement) and every nature between us. Except as
- provided for above, any modification to this Agreement must be in writing and
- must be signed by both parties.</paragraph>
- </section>
- <section ids="questions-or-comments" names="questions\ or\ comments">
- <title>Questions or comments</title>
- <paragraph>We welcome comments, questions, concerns, or suggestions. Please send us a
- message on our contact page at <reference refuri="mailto:legal@taler-systems.com">legal@taler-systems.com</reference>.</paragraph>
- </section>
- </section>
-</document>
diff --git a/contrib/tos/locale/de/LC_MESSAGES/tos.po b/contrib/tos/locale/de/LC_MESSAGES/tos.po
deleted file mode 100644
index e821c9c1f..000000000
--- a/contrib/tos/locale/de/LC_MESSAGES/tos.po
+++ /dev/null
@@ -1,241 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) 2014-2020 Taler Systems SA (GPLv3+ or GFDL 1.3+)
-# This file is distributed under the same license as the tos package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: tos 0\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2021-09-30 21:42+0200\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: ../../tos.rst:2
-msgid "Terms Of Service"
-msgstr ""
-
-#: ../../tos.rst:4
-msgid "Last Updated: 12.4.2019"
-msgstr ""
-
-#: ../../tos.rst:6
-msgid "Welcome! Taler Systems SA (“we,” “our,” or “us”) provides a payment service through our Internet presence (collectively the “Services”). Before using our Services, please read the Terms of Service (the “Terms” or the “Agreement”) carefully."
-msgstr ""
-
-#: ../../tos.rst:12
-msgid "Overview"
-msgstr ""
-
-#: ../../tos.rst:14
-msgid "This section provides a brief summary of the highlights of this Agreement. Please note that when you accept this Agreement, you are accepting all of the terms and conditions and not just this section. We and possibly other third parties provide Internet services which interact with the Taler Wallet’s self-hosted personal payment application. When using the Taler Wallet to interact with our Services, you are agreeing to our Terms, so please read carefully."
-msgstr ""
-
-#: ../../tos.rst:23
-msgid "Highlights:"
-msgstr ""
-
-#: ../../tos.rst:25
-msgid "You are responsible for keeping the data in your Taler Wallet at all times under your control. Any losses arising from you not being in control of your private information are your problem."
-msgstr ""
-
-#: ../../tos.rst:28
-msgid "We will try to transfer funds we hold in escrow for our users to any legal recipient to the best of our ability within the limitations of the law and our implementation. However, the Services offered today are highly experimental and the set of recipients of funds is severely restricted."
-msgstr ""
-
-#: ../../tos.rst:32
-msgid "For our Services, we may charge transaction fees. The specific fee structure is provided based on the Taler protocol and should be shown to you when you withdraw electronic coins using a Taler Wallet. You agree and understand that the Taler protocol allows for the fee structure to change."
-msgstr ""
-
-#: ../../tos.rst:36
-msgid "You agree to not intentionally overwhelm our systems with requests and follow responsible disclosure if you find security issues in our services."
-msgstr ""
-
-#: ../../tos.rst:38
-msgid "We cannot be held accountable for our Services not being available due to circumstances beyond our control. If we modify or terminate our services, we will try to give you the opportunity to recover your funds. However, given the experimental state of the Services today, this may not be possible. You are strongly advised to limit your use of the Service to small-scale experiments expecting total loss of all funds."
-msgstr ""
-
-#: ../../tos.rst:45
-msgid "These terms outline approved uses of our Services. The Services and these Terms are still at an experimental stage. If you have any questions or comments related to this Agreement, please send us a message to legal@taler-systems.com. If you do not agree to this Agreement, you must not use our Services."
-msgstr ""
-
-#: ../../tos.rst:52
-msgid "How you accept this policy"
-msgstr ""
-
-#: ../../tos.rst:54
-msgid "By sending funds to us (to top-up your Taler Wallet), you acknowledge that you have read, understood, and agreed to these Terms. We reserve the right to change these Terms at any time. If you disagree with the change, we may in the future offer you with an easy option to recover your unspent funds. However, in the current experimental period you acknowledge that this feature is not yet available, resulting in your funds being lost unless you accept the new Terms. If you continue to use our Services other than to recover your unspent funds, your continued use of our Services following any such change will signify your acceptance to be bound by the then current Terms. Please check the effective date above to determine if there have been any changes since you have last reviewed these Terms."
-msgstr ""
-
-#: ../../tos.rst:67
-msgid "Services"
-msgstr ""
-
-#: ../../tos.rst:69
-msgid "We will try to transfer funds that we hold in escrow for our users to any legal recipient to the best of our ability and within the limitations of the law and our implementation. However, the Services offered today are highly experimental and the set of recipients of funds is severely restricted. The Taler Wallet can be loaded by exchanging fiat currencies against electronic coins. We are providing this exchange service. Once your Taler Wallet is loaded with electronic coins they can be spent for purchases if the seller is accepting Taler as a means of payment. We are not guaranteeing that any seller is accepting Taler at all or a particular seller. The seller or recipient of deposits of electronic coins must specify the target account, as per the design of the Taler protocol. They are responsible for following the protocol and specifying the correct bank account, and are solely liable for any losses that may arise from specifying the wrong account. We will allow the government to link wire transfers to the underlying contract hash. It is the responsibility of recipients to preserve the full contracts and to pay whatever taxes and charges may be applicable. Technical issues may lead to situations where we are unable to make transfers at all or lead to incorrect transfers that cannot be reversed. We will only refuse to execute transfers if the transfers are prohibited by a competent legal authority and we are ordered to do so."
-msgstr ""
-
-#: ../../tos.rst:90
-msgid "When using our Services, you agree to not take any action that intentionally imposes an unreasonable load on our infrastructure. If you find security problems in our Services, you agree to first report them to security@taler-systems.com and grant us the right to publish your report. We warrant that we will ourselves publicly disclose any issues reported within 3 months, and that we will not prosecute anyone reporting security issues if they did not exploit the issue beyond a proof-of-concept, and followed the above responsible disclosure practice."
-msgstr ""
-
-#: ../../tos.rst:101
-msgid "Fees"
-msgstr ""
-
-#: ../../tos.rst:103
-msgid "You agree to pay the fees for exchanges and withdrawals completed via the Taler Wallet (\"Fees\") as defined by us, which we may change from time to time. With the exception of wire transfer fees, Taler transaction fees are set for any electronic coin at the time of withdrawal and fixed throughout the validity period of the respective electronic coin. Your wallet should obtain and display applicable fees when withdrawing funds. Fees for coins obtained as change may differ from the fees applicable to the original coin. Wire transfer fees that are independent from electronic coins may change annually. You authorize us to charge or deduct applicable fees owed in connection with deposits, exchanges and withdrawals following the rules of the Taler protocol. We reserve the right to provide different types of rewards to users either in the form of discount for our Services or in any other form at our discretion and without prior notice to you."
-msgstr ""
-
-#: ../../tos.rst:118
-msgid "Eligibility and Financial self-responsibility"
-msgstr ""
-
-#: ../../tos.rst:120
-msgid "To be eligible to use our Services, you must be able to form legally binding contracts or have the permission of your legal guardian. By using our Services, you represent and warrant that you meet all eligibility requirements that we outline in these Terms."
-msgstr ""
-
-#: ../../tos.rst:125
-msgid "You will be responsible for maintaining the availability, integrity and confidentiality of the data stored in your wallet. When you setup a Taler Wallet, you are strongly advised to follow the precautionary measures offered by the software to minimize the chances to losse access to or control over your Wallet data. We will not be liable for any loss or damage arising from your failure to comply with this paragraph."
-msgstr ""
-
-#: ../../tos.rst:133
-msgid "Copyrights and trademarks"
-msgstr ""
-
-#: ../../tos.rst:135
-msgid "The Taler Wallet is released under the terms of the GNU General Public License (GNU GPL). You have the right to access, use, and share the Taler Wallet, in modified or unmodified form. However, the GPL is a strong copyleft license, which means that any derivative works must be distributed under the same license terms as the original software. If you have any questions, you should review the GNU GPL’s full terms and conditions at https://www.gnu.org/licenses/gpl-3.0.en.html. “Taler” itself is a trademark of Taler Systems SA. You are welcome to use the name in relation to processing payments using the Taler protocol, assuming your use is compatible with an official release from the GNU Project that is not older than two years."
-msgstr ""
-
-#: ../../tos.rst:148
-msgid "Limitation of liability & disclaimer of warranties"
-msgstr ""
-
-#: ../../tos.rst:150
-msgid "You understand and agree that we have no control over, and no duty to take any action regarding: Failures, disruptions, errors, or delays in processing that you may experience while using our Services; The risk of failure of hardware, software, and Internet connections; The risk of malicious software being introduced or found in the software underlying the Taler Wallet; The risk that third parties may obtain unauthorized access to information stored within your Taler Wallet, including, but not limited to your Taler Wallet coins or backup encryption keys. You release us from all liability related to any losses, damages, or claims arising from:"
-msgstr ""
-
-#: ../../tos.rst:160
-msgid "user error such as forgotten passwords, incorrectly constructed transactions;"
-msgstr ""
-
-#: ../../tos.rst:162
-msgid "server failure or data loss;"
-msgstr ""
-
-#: ../../tos.rst:163
-msgid "unauthorized access to the Taler Wallet application;"
-msgstr ""
-
-#: ../../tos.rst:164
-msgid "bugs or other errors in the Taler Wallet software; and"
-msgstr ""
-
-#: ../../tos.rst:165
-msgid "any unauthorized third party activities, including, but not limited to, the use of viruses, phishing, brute forcing, or other means of attack against the Taler Wallet. We make no representations concerning any Third Party Content contained in or accessed through our Services."
-msgstr ""
-
-#: ../../tos.rst:170
-msgid "Any other terms, conditions, warranties, or representations associated with such content, are solely between you and such organizations and/or individuals."
-msgstr ""
-
-#: ../../tos.rst:174
-msgid "To the fullest extent permitted by applicable law, in no event will we or any of our officers, directors, representatives, agents, servants, counsel, employees, consultants, lawyers, and other personnel authorized to act, acting, or purporting to act on our behalf (collectively the “Taler Parties”) be liable to you under contract, tort, strict liability, negligence, or any other legal or equitable theory, for:"
-msgstr ""
-
-#: ../../tos.rst:181
-msgid "any lost profits, data loss, cost of procurement of substitute goods or services, or direct, indirect, incidental, special, punitive, compensatory, or consequential damages of any kind whatsoever resulting from:"
-msgstr ""
-
-#: ../../tos.rst:185
-msgid "your use of, or conduct in connection with, our services;"
-msgstr ""
-
-#: ../../tos.rst:186
-msgid "any unauthorized use of your wallet and/or private key due to your failure to maintain the confidentiality of your wallet;"
-msgstr ""
-
-#: ../../tos.rst:188
-msgid "any interruption or cessation of transmission to or from the services; or"
-msgstr ""
-
-#: ../../tos.rst:189
-msgid "any bugs, viruses, trojan horses, or the like that are found in the Taler Wallet software or that may be transmitted to or through our services by any third party (regardless of the source of origination), or"
-msgstr ""
-
-#: ../../tos.rst:193
-msgid "any direct damages."
-msgstr ""
-
-#: ../../tos.rst:195
-msgid "These limitations apply regardless of legal theory, whether based on tort, strict liability, breach of contract, breach of warranty, or any other legal theory, and whether or not we were advised of the possibility of such damages. Some jurisdictions do not allow the exclusion or limitation of liability for consequential or incidental damages, so the above limitation may not apply to you."
-msgstr ""
-
-#: ../../tos.rst:202
-msgid "Our services are provided \"as is\" and without warranty of any kind. To the maximum extent permitted by law, we disclaim all representations and warranties, express or implied, relating to the services and underlying software or any content on the services, whether provided or owned by us or by any third party, including without limitation, warranties of merchantability, fitness for a particular purpose, title, non-infringement, freedom from computer virus, and any implied warranties arising from course of dealing, course of performance, or usage in trade, all of which are expressly disclaimed. In addition, we do not represent or warrant that the content accessible via the services is accurate, complete, available, current, free of viruses or other harmful components, or that the results of using the services will meet your requirements. Some states do not allow the disclaimer of implied warranties, so the foregoing disclaimers may not apply to you. This paragraph gives you specific legal rights and you may also have other legal rights that vary from state to state."
-msgstr ""
-
-#: ../../tos.rst:219
-msgid "Indemnity and Time limitation on claims and Termination"
-msgstr ""
-
-#: ../../tos.rst:221
-msgid "To the extent permitted by applicable law, you agree to defend, indemnify, and hold harmless the Taler Parties from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, and expenses (including, but not limited to, attorney’s fees) arising from: (a) your use of and access to the Services; (b) any feedback or submissions you provide to us concerning the Taler Wallet; (c) your violation of any term of this Agreement; or (d) your violation of any law, rule, or regulation, or the rights of any third party."
-msgstr ""
-
-#: ../../tos.rst:229
-msgid "You agree that any claim you may have arising out of or related to your relationship with us must be filed within one year after such claim arises, otherwise, your claim in permanently barred."
-msgstr ""
-
-#: ../../tos.rst:233
-msgid "In the event of termination concerning your use of our Services, your obligations under this Agreement will still continue."
-msgstr ""
-
-#: ../../tos.rst:238
-msgid "Discontinuance of services and Force majeure"
-msgstr ""
-
-#: ../../tos.rst:240
-msgid "We may, in our sole discretion and without cost to you, with or without prior notice, and at any time, modify or discontinue, temporarily or permanently, any portion of our Services. We will use the Taler protocol’s provisions to notify Wallets if our Services are to be discontinued. It is your responsibility to ensure that the Taler Wallet is online at least once every three months to observe these notifications. We shall not be held responsible or liable for any loss of funds in the event that we discontinue or depreciate the Services and your Taler Wallet fails to transfer out the coins within a three months notification period."
-msgstr ""
-
-#: ../../tos.rst:250
-msgid "We shall not be held liable for any delays, failure in performance, or interruptions of service which result directly or indirectly from any cause or condition beyond our reasonable control, including but not limited to: any delay or failure due to any act of God, act of civil or military authorities, act of terrorism, civil disturbance, war, strike or other labor dispute, fire, interruption in telecommunications or Internet services or network provider services, failure of equipment and/or software, other catastrophe, or any other occurrence which is beyond our reasonable control and shall not affect the validity and enforceability of any remaining provisions."
-msgstr ""
-
-#: ../../tos.rst:262
-msgid "Governing law, Waivers, Severability and Assignment"
-msgstr ""
-
-#: ../../tos.rst:264
-msgid "No matter where you’re located, the laws of Switzerland will govern these Terms. If any provisions of these Terms are inconsistent with any applicable law, those provisions will be superseded or modified only to the extent such provisions are inconsistent. The parties agree to submit to the ordinary courts in Zurich, Switzerland for exclusive jurisdiction of any dispute arising out of or related to your use of the Services or your breach of these Terms."
-msgstr ""
-
-#: ../../tos.rst:272
-msgid "Our failure to exercise or delay in exercising any right, power, or privilege under this Agreement shall not operate as a waiver; nor shall any single or partial exercise of any right, power, or privilege preclude any other or further exercise thereof."
-msgstr ""
-
-#: ../../tos.rst:277
-msgid "You agree that we may assign any of our rights and/or transfer, sub-contract, or delegate any of our obligations under these Terms."
-msgstr ""
-
-#: ../../tos.rst:280
-msgid "If it turns out that any part of this Agreement is invalid, void, or for any reason unenforceable, that term will be deemed severable and limited or eliminated to the minimum extent necessary."
-msgstr ""
-
-#: ../../tos.rst:284
-msgid "This Agreement sets forth the entire understanding and agreement as to the subject matter hereof and supersedes any and all prior discussions, agreements, and understandings of any kind (including, without limitation, any prior versions of this Agreement) and every nature between us. Except as provided for above, any modification to this Agreement must be in writing and must be signed by both parties."
-msgstr ""
-
-#: ../../tos.rst:293
-msgid "Questions or comments"
-msgstr ""
-
-#: ../../tos.rst:295
-msgid "We welcome comments, questions, concerns, or suggestions. Please send us a message on our contact page at legal@taler-systems.com."
-msgstr ""
diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit
index 24873330f..d0a64ef72 100755
--- a/contrib/uncrustify_precommit
+++ b/contrib/uncrustify_precommit
@@ -1,11 +1,10 @@
#!/bin/sh
# use as .git/hooks/pre-commit
-
exec 1>&2
RET=0
-changed=$(git diff --cached --name-only)
+changed=$(git diff --cached --name-only | grep -v mustach | grep -v templating/test | grep -v valgrind.h)
crustified=""
for f in $changed;
@@ -29,7 +28,7 @@ done
if [ $RET = 1 ];
then
echo "Run"
- echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
+ echo "uncrustify --replace -c uncrustify.cfg ${crustified}"
echo "before committing."
fi
exit $RET
diff --git a/contrib/update-pp.sh b/contrib/update-pp.sh
index db31ba18a..728216c58 100755
--- a/contrib/update-pp.sh
+++ b/contrib/update-pp.sh
@@ -14,7 +14,8 @@ cd pp
for l in $@
do
mkdir -p $l
- echo Generating PP for language $l
+ echo "Generating PP for language $l"
+ cat conf.py.in | sed -e "s/%VERSION%/$VERSION/g" > conf.py
# 'f' is for the supported formats, note that the 'make' target
# MUST match the file extension.
for f in html txt pdf epub xml
@@ -22,7 +23,16 @@ do
rm -rf _build
echo " Generating format $f"
make -e SPHINXOPTS="-D language='$l'" $f >>sphinx.log 2>>sphinx.err < /dev/null
- mv _build/$f/pp.$f $l/${VERSION}.$f
+ if test $f = "html"
+ then
+ htmlark -o $l/${VERSION}.$f _build/$f/${VERSION}.$f
+ else
+ mv _build/$f/${VERSION}.$f $l/${VERSION}.$f
+ fi
+ if test $f = "txt"
+ then
+ cp $l/${VERSION}.$f $l/${VERSION}.md
+ fi
done
done
cd ..
diff --git a/contrib/update-tos.sh b/contrib/update-tos.sh
index 47d3af778..dcf9e3919 100755
--- a/contrib/update-tos.sh
+++ b/contrib/update-tos.sh
@@ -14,7 +14,8 @@ cd tos
for l in $@
do
mkdir -p $l
- echo Generating TOS for language $l
+ echo "Generating TOS for language $l"
+ cat conf.py.in | sed -e "s/%VERSION%/$VERSION/g" > conf.py
# 'f' is for the supported formats, note that the 'make' target
# MUST match the file extension.
for f in html txt pdf epub xml
@@ -22,7 +23,17 @@ do
rm -rf _build
echo " Generating format $f"
make -e SPHINXOPTS="-D language='$l'" $f >>sphinx.log 2>>sphinx.err < /dev/null
- mv _build/$f/tos.$f $l/${VERSION}.$f
+ if test $f = "html"
+ then
+ htmlark -o $l/${VERSION}.$f _build/$f/${VERSION}.$f
+ else
+ mv _build/$f/${VERSION}.$f $l/${VERSION}.$f
+ fi
+ if test $f = "txt"
+ then
+ cp $l/${VERSION}.$f $l/${VERSION}.md
+ fi
done
done
cd ..
+echo "Success"
diff --git a/contrib/wallet-core b/contrib/wallet-core
new file mode 160000
+Subproject 240d647da85de6b575d15c37efec04757541e3d
diff --git a/debian/changelog b/debian/changelog
index c151d9bad..cab5345dc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,145 @@
+taler-exchange (0.10.2) unstable; urgency=low
+
+ * Updated man pages and other resources for release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Fri, 12 Apr 2024 09:50:12 +0200
+
+taler-exchange (0.10.1) unstable; urgency=low
+
+ * Fixed crash in OTP calculation logic if required amount was not
+ provided.
+ * Fixed HTTP headers for /terms, /config and /keys responses
+ (remove last-modified-since distinguisher, remove duplicate headers)
+ * Improved systemd files (new offline timer job, exchange slice)
+ * Implement exchange protocol v19 (include refunds in transaction
+ aggregation data, expose wire account priorities)
+ * Update mustach to latest version
+
+ -- Christian Grothoff <grothoff@gnu.org> Tue, 9 Apr 2024 09:50:12 +0200
+
+taler-exchange (0.10.0) unstable; urgency=low
+
+ * Fixed major issue where uploading wire data to an
+ exchange twice would result in broken signatures and
+ a permanently non-working account.
+ * Implemented #8000, allowing an exchange to express
+ preferences over the different bank accounts so that
+ users are shown the best choices to withdraw from first.
+ * This version requires a more recent GNUnet (>= 0.21.1).
+
+ -- Christian Grothoff <grothoff@gnu.org> Sat, 9 Mar 2024 21:50:12 +0200
+
+taler-exchange (0.9.4-2) unstable; urgency=low
+
+ * Created new taler-terms-generator package
+ * v0.9.4a bugfix release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Mon, 3 Mar 2024 21:50:12 +0200
+
+taler-exchange (0.9.4-1) unstable; urgency=low
+
+ * Actual v0.9.4 release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Sat, 10 Feb 2024 03:50:12 +0200
+
+taler-exchange (0.9.4) unstable; urgency=low
+
+ * Preparations for v0.9.4 release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Sun, 21 Jan 2024 03:50:12 +0200
+
+taler-exchange (0.9.3-7) unstable; urgency=low
+
+ * Move currencies.conf into libtalerexchange base package.
+
+ -- Christian Grothoff <grothoff@gnu.org> Tue, 15 Dec 2023 18:50:12 -0700
+
+taler-exchange (0.9.3-6) unstable; urgency=low
+
+ * Generate proper markdown in taler-terms-generator.
+ * Return language code for legal terms.
+
+ -- Christian Grothoff <grothoff@gnu.org> Tue, 13 Dec 2023 18:50:12 -0700
+
+taler-exchange (0.9.3-5) unstable; urgency=low
+
+ * More fixes to the database setup automation scripts.
+ * Implement latest /config API in fakebank.
+
+ -- Christian Grothoff <grothoff@gnu.org> Thu, 7 Dec 2023 00:50:12 -0800
+
+taler-exchange (0.9.3-4) unstable; urgency=low
+
+ * Minor hot-fixes to the database setup automation script.
+
+ -- Christian Grothoff <grothoff@gnu.org> Fri, 1 Dec 2023 10:50:12 -0800
+
+taler-exchange (0.9.3-3) unstable; urgency=low
+
+ * This packages the v0.9.3b bugfix release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Wed, 29 Nov 2023 03:50:12 +0200
+
+taler-exchange (0.9.3-2) unstable; urgency=low
+
+ * This packages the v0.9.3a bugfix release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Wed, 29 Nov 2023 03:50:12 +0200
+
+taler-exchange (0.9.3-1) unstable; urgency=low
+
+ * Actual v0.9.3 release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Wed, 27 Sep 2023 03:50:12 +0200
+
+taler-exchange (0.9.3) unstable; urgency=low
+
+ * First work towards packaging v0.9.3.
+
+ -- Christian Grothoff <grothoff@gnu.org> Thu, 7 Sep 2023 23:50:12 +0200
+
+taler-exchange (0.9.2-3) unstable; urgency=low
+
+ * Improvements to timeout handling when DB is not available yet.
+
+ -- Florian Dold <dold@taler.net> Tue, 14 Mar 2023 12:30:15 +0100
+
+taler-exchange (0.9.2-2) unstable; urgency=low
+
+ * Further improvements to Debian package.
+
+ -- Christian Grothoff <grothoff@gnu.org> Sat, 3 Mar 2023 23:50:12 +0200
+
+taler-exchange (0.9.2-1) unstable; urgency=low
+
+ * Minor improvements to Debian package, also adds age-withdraw REST APIs.
+
+ -- Christian Grothoff <grothoff@gnu.org> Sat, 3 Mar 2023 13:50:12 +0200
+
+taler-exchange (0.9.2) unstable; urgency=low
+
+ * Packaging latest release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Tue, 21 Feb 2023 13:50:12 +0200
+
+taler-exchange (0.9.1) unstable; urgency=low
+
+ * Packaging latest release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Tue, 17 Jan 2023 11:50:12 +0200
+
+taler-exchange (0.9.0) unstable; urgency=low
+
+ * Packaging latest release.
+
+ -- Christian Grothoff <grothoff@gnu.org> Sat, 5 Nov 2022 11:50:12 +0200
+
+taler-exchange (0.8.99-2) unstable; urgency=low
+
+ * Packaging latest pre-release from Git.
+
+ -- Christian Grothoff <grothoff@gnu.org> Mon, 26 Sep 2022 09:50:12 +0200
+
taler-exchange (0.8.99-1) unstable; urgency=low
* Updating to latest pre-release from Git.
diff --git a/debian/control b/debian/control
index 3f55173e1..cf99dd1ed 100644
--- a/debian/control
+++ b/debian/control
@@ -7,22 +7,21 @@ Build-Depends:
automake (>=1.11.1),
autopoint,
bash,
+ gcc-12,
debhelper-compat (= 12),
gettext,
- libgnunet-dev (>=0.17.1),
+ libgnunet-dev (>=0.21),
libcurl4-gnutls-dev (>=7.35.0) | libcurl4-openssl-dev (>= 7.35.0),
libgcrypt20-dev (>=1.8),
libgnutls28-dev (>=3.2.12),
libidn2-dev,
- libjansson-dev,
+ libjansson-dev (>= 2.13),
libltdl-dev (>=2.2),
libmicrohttpd-dev (>=0.9.71),
- libpq-dev (>=13),
+ libpq-dev (>=14),
libsodium-dev (>=1.0.11),
libunistring-dev (>=0.9.2),
- python3-jinja2,
po-debconf,
- python3-dev,
texinfo (>=5.2),
zlib1g-dev
Standards-Version: 4.5.0
@@ -39,7 +38,26 @@ Depends:
netbase,
${misc:Depends},
${shlibs:Depends}
-Description: libraries to talk to a GNU Taler exchange
+Description: Libraries to talk to a GNU Taler exchange.
+ The package also contains various files fundamental
+ to all GNU Taler installations, such as the
+ taler-config configuration command-line tool,
+ various base configuration files and associated
+ documentation.
+
+Package: taler-terms-generator
+Architecture: any
+Pre-Depends:
+ ${misc:Pre-Depends}
+Depends:
+ lsb-base,
+ pandoc,
+ groff,
+ ghostscript,
+ ${misc:Depends}
+Description: Tool to generate the terms of service
+ and privacy policy for various languages and data
+ formats. Useful for various GNU Taler components.
Package: taler-exchange-database
Architecture: any
@@ -50,7 +68,10 @@ Depends:
netbase,
${misc:Depends},
${shlibs:Depends}
-Description: programs and libraries to manage a GNU Taler exchange database
+Description: Programs and libraries to manage a GNU Taler exchange database.
+ This package contains only the code to setup the
+ (Postgresql) database interaction (taler-exchange-dbinit
+ and associated resource files).
Package: taler-exchange
Architecture: any
@@ -63,13 +84,29 @@ Depends:
lsb-base,
netbase,
ucf,
- dbconfig-pgsql | dbconfig-no-thanks,
${misc:Depends},
${shlibs:Depends}
Recommends:
taler-exchange-offline (= ${binary:Version}),
- postgresql (>=13.0)
-Description: GNU's payment system operator
+ taler-terms-generator,
+ apache2 | nginx | httpd,
+ postgresql (>=14.0)
+Description: GNU's payment system operator.
+ GNU Taler is the privacy-preserving digital payment
+ system from the GNU project. This package contains the
+ core logic that must be run by the payment service
+ provider or bank to offer payments to consumers and
+ merchants. At least one exchange must be operated
+ per currency.
+ In addition to the core logic, an exchange operator
+ must also have a system running the "offline" logic
+ which is packaged as taler-exchange-offline. It is
+ recommended to keep the "offline" logic on a system
+ that is never connected to the Internet. However, it
+ is also possible to run the "offline" logic directly
+ on the production system, especially for testing.
+ Finally, an exchange operator should also be prepared
+ to run a taler-auditor.
Package: taler-exchange-offline
Architecture: any
@@ -82,7 +119,14 @@ Depends:
netbase,
${misc:Depends},
${shlibs:Depends}
-Description: tools for managing the GNU Taler exchange offline keys
+Description: Tools for managing the GNU Taler exchange offline keys.
+ A GNU Taler exchange uses an offline key to sign its online
+ keys, fee structure, bank routing information and other meta
+ data. The offline signing key is the root of the Taler PKI
+ that is then embedded in consumer wallets and merchant backends.
+ This package includes the tool to download material to sign
+ from the exchange, create signatures, and upload the resulting
+ signatures to the exchange.
Package: taler-auditor
Architecture: any
@@ -94,18 +138,24 @@ Depends:
adduser,
lsb-base,
netbase,
- dbconfig-pgsql | dbconfig-no-thanks,
- python3-jinja2,
${misc:Depends},
${shlibs:Depends}
-Description: GNU's payment system auditor
+Description: GNU's payment system auditor.
+ GNU Taler is the privacy-preserving digital payment
+ system from the GNU project. This package contains the
+ auditor logic. It verifies that the taler-exchange run
+ by a payment service provider is correctly performing
+ its bank transactions and thus has the correct balance
+ in its escrow account. Each exchange operator is
+ expected to make use of one or more auditors as part
+ of its regulatory compliance.
Package: libtalerexchange-dev
Section: libdevel
Architecture: any
Depends:
libtalerexchange (= ${binary:Version}),
- libgnunet-dev (>=0.17.1),
+ libgnunet-dev (>=0.21),
libgcrypt20-dev (>=1.8),
libmicrohttpd-dev (>=0.9.71),
${misc:Depends},
diff --git a/debian/etc-libtalerexchange/taler/taler.conf b/debian/etc-libtalerexchange/taler/taler.conf
index 71663be5e..2cf815656 100644
--- a/debian/etc-libtalerexchange/taler/taler.conf
+++ b/debian/etc-libtalerexchange/taler/taler.conf
@@ -30,14 +30,16 @@
# systems is always rounded to this unit.
#currency_round_unit = KUDOS:0.01
+# Monthly amount that mandatorily triggers an AML check
+#AML_THRESHOLD = KUDOS:10000000
[paths]
-TALER_HOME = /var/lib/taler
-TALER_RUNTIME_DIR = /run/taler
-TALER_CACHE_HOME = /var/cache/taler
-TALER_CONFIG_HOME = /etc/taler
-TALER_DATA_HOME = /var/lib/taler
+TALER_HOME = /var/lib/taler/
+TALER_RUNTIME_DIR = /run/taler/
+TALER_CACHE_HOME = /var/cache/taler/
+TALER_CONFIG_HOME = /etc/taler/
+TALER_DATA_HOME = /var/lib/taler/
# Inline configurations from all Taler components.
diff --git a/debian/etc-taler-auditor/nginx/sites-available/taler-auditor b/debian/etc-taler-auditor/nginx/sites-available/taler-auditor
index 3fdffdad3..f74035d53 100644
--- a/debian/etc-taler-auditor/nginx/sites-available/taler-auditor
+++ b/debian/etc-taler-auditor/nginx/sites-available/taler-auditor
@@ -1,7 +1,18 @@
-location /taler-auditor/ {
- proxy_pass http://unix:/var/lib/taler-auditor/auditor.sock;
- proxy_redirect off;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-Host "example.com";
- proxy_set_header X-Forwarded-Proto "https";
+server {
+
+ listen 80;
+ listen [::]:80;
+
+ server_name localhost;
+
+ access_log /var/log/nginx/auditor.log;
+ error_log /var/log/nginx/auditor.err;
+
+ location /taler-auditor/ {
+ proxy_pass http://unix:/var/lib/taler-auditor/auditor.sock;
+ proxy_redirect off;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-Host "localhost";
+ #proxy_set_header X-Forwarded-Proto "https";
+ }
} \ No newline at end of file
diff --git a/debian/etc-taler-auditor/taler/secrets/auditor-db.secret.conf b/debian/etc-taler-auditor/taler/secrets/auditor-db.secret.conf
index b81bb817f..1278a563b 100644
--- a/debian/etc-taler-auditor/taler/secrets/auditor-db.secret.conf
+++ b/debian/etc-taler-auditor/taler/secrets/auditor-db.secret.conf
@@ -4,7 +4,7 @@
# Typically, there should only be a single line here, of the form:
-CONFIG=postgres:///DATABASE
+CONFIG=postgres:///taler-auditor
# The details of the URI depend on where the database lives and how
# access control was configured.
diff --git a/debian/etc-taler-exchange/nginx/sites-available/taler-exchange b/debian/etc-taler-exchange/nginx/sites-available/taler-exchange
index 13ab88633..9b61a32df 100644
--- a/debian/etc-taler-exchange/nginx/sites-available/taler-exchange
+++ b/debian/etc-taler-exchange/nginx/sites-available/taler-exchange
@@ -2,13 +2,16 @@ server {
listen 80;
listen [::]:80;
- #server_name example.com;
+ server_name localhost;
+
+ access_log /var/log/nginx/exchange.log;
+ error_log /var/log/nginx/exchange.err;
location /taler-exchange/ {
proxy_pass http://unix:/run/taler/exchange-httpd/exchange-http.sock:/;
proxy_redirect off;
proxy_set_header Host $host;
- #proxy_set_header X-Forwarded-Host "example.com";
+ proxy_set_header X-Forwarded-Host "localhost";
#proxy_set_header X-Forwarded-Proto "https";
}
}
diff --git a/debian/etc-taler-exchange/taler/conf.d/exchange-business.conf b/debian/etc-taler-exchange/taler/conf.d/exchange-business.conf
index 554852a14..d5938f2b1 100644
--- a/debian/etc-taler-exchange/taler/conf.d/exchange-business.conf
+++ b/debian/etc-taler-exchange/taler/conf.d/exchange-business.conf
@@ -6,11 +6,19 @@
# which you can get using `taler-exchange-offline setup`.
# This is just an example, your key will be different!
# MASTER_PUBLIC_KEY = YE6Q6TR1EDB7FD0S68TGDZGF1P0GHJD2S0XVV8R2S62MYJ6HJ4ZG
-MASTER_PUBLIC_KEY =
+# MASTER_PUBLIC_KEY =
# Publicly visible base URL of the exchange.
# BASE_URL = https://example.com/
-BASE_URL =
+# BASE_URL =
+
+# Here you MUST configure the amount above which transactions are
+# always subject to manual AML review.
+# AML_THRESHOLD =
+
+# Attribute encryption key for storing attributes encrypted
+# in the database. Should be a high-entropy nonce.
+ATTRIBUTE_ENCRYPTION_KEY = SET_ME_PLEASE
# For your terms of service and privacy policy, you should specify
# an Etag that must be updated whenever there are significant
@@ -20,18 +28,23 @@ BASE_URL =
# TERMS_ETAG =
# PRIVACY_ETAG =
+SERVE = unix
+UNIXPATH_MODE = 666
# Bank accounts used by the exchange should be specified here:
[exchange-account-1]
-enable_credit = yes
-enable_debit = yes
+ENABLE_CREDIT = NO
+ENABLE_DEBIT = NO
# Account identifier in the form of an RFC-8905 payto:// URI.
# For SEPA, looks like payto://sepa/$IBAN?receiver-name=$NAME
# Make sure to URL-encode spaces in $NAME!
-payto_uri =
+PAYTO_URI =
# Credentials to access the account are in a separate
# config file with restricted permissions.
-@inline-secret@ exchange-accountcredentials-1 ../secrets/exchange-accountcredentials.secret.conf
+@inline-secret@ exchange-accountcredentials-1 ../secrets/exchange-accountcredentials-1.secret.conf
+
+
+
diff --git a/debian/etc-taler-exchange/taler/conf.d/exchange-system.conf b/debian/etc-taler-exchange/taler/conf.d/exchange-system.conf
index 75c670f71..4ad7e06f6 100644
--- a/debian/etc-taler-exchange/taler/conf.d/exchange-system.conf
+++ b/debian/etc-taler-exchange/taler/conf.d/exchange-system.conf
@@ -8,3 +8,6 @@
# Only supported database is Postgres right now.
DATABASE = postgres
+
+
+
diff --git a/debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf b/debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf
new file mode 100644
index 000000000..8c8d14320
--- /dev/null
+++ b/debian/etc-taler-exchange/taler/secrets/exchange-accountcredentials-1.secret.conf
@@ -0,0 +1,17 @@
+# This file contains the secret credentials
+# to access the Taler Wire Gateway API (usually
+# provided by LibEuFin) for the exchange accounts.
+#
+# Each exchange-account-* section should have a matching
+# exchange-accountcredentials-* section here.
+#
+# Each of those sections must be imported via @inline-secret@,
+# usually in conf.d/exchange-business.conf.
+
+[exchange-accountcredentials-1]
+
+wire_gateway_auth_method = basic
+password =
+username =
+wire_gateway_url =
+
diff --git a/debian/etc-taler-exchange/taler/secrets/exchange-db.secret.conf b/debian/etc-taler-exchange/taler/secrets/exchange-db.secret.conf
index 596dcc92b..08c20074c 100644
--- a/debian/etc-taler-exchange/taler/secrets/exchange-db.secret.conf
+++ b/debian/etc-taler-exchange/taler/secrets/exchange-db.secret.conf
@@ -4,7 +4,7 @@
# Typically, there should only be a single line here, of the form:
-CONFIG=postgres:///DATABASE
+CONFIG=postgres:///taler-exchange
# The details of the URI depend on where the database lives and how
# access control was configured.
diff --git a/debian/libtalerexchange-dev.install b/debian/libtalerexchange-dev.install
index e21973509..aa1de818a 100644
--- a/debian/libtalerexchange-dev.install
+++ b/debian/libtalerexchange-dev.install
@@ -1,13 +1,20 @@
# Benchmarks, only install them for the dev package.
usr/bin/taler-aggregator-benchmark
+usr/bin/taler-bank-benchmark
usr/bin/taler-exchange-benchmark
+usr/bin/taler-exchange-kyc-tester
usr/bin/taler-fakebank-run
-usr/bin/taler-bank-benchmark
+usr/bin/taler-unified-setup.sh
+usr/bin/taler-exchange-kyc-oauth2-test-converter.sh
+
+# Man pages
+usr/share/man/man1/taler-aggregator-benchmark*
+usr/share/man/man1/taler-bank-benchmark*
+usr/share/man/man1/taler-exchange-kyc-tester*
+usr/share/man/man1/taler-exchange-benchmark*
+usr/share/man/man1/taler-fakebank-run*
+usr/share/man/man1/taler-unified-setup*
-# Only used in test cases. Maybe these
-# shouldn't even be installed?
-usr/bin/taler-nexus-prepare
-usr/bin/taler-bank-manage-testing
# Headers
usr/include/taler/*
@@ -22,5 +29,4 @@ usr/lib/*/libtalertesting.so
usr/lib/*/libtalerfakebank.so
# Documentation
-usr/share/man/man1/taler-exchange-benchmark*
usr/share/info/taler-developer-manual*
diff --git a/debian/libtalerexchange.install b/debian/libtalerexchange.install
index 62dd84a61..f3c52ba8d 100644
--- a/debian/libtalerexchange.install
+++ b/debian/libtalerexchange.install
@@ -2,9 +2,9 @@ usr/lib/*/libtaler*.so.*
# FIXME: All this should eventually go into taler-base.
usr/share/taler/config.d/paths.conf
+usr/share/taler/config.d/currencies.conf
usr/share/taler/config.d/taler.conf
debian/etc-libtalerexchange/* etc/
usr/bin/taler-config
-usr/bin/taler-crypto-worker
usr/share/man/man5/taler.conf.5
usr/share/man/man1/taler-config*
diff --git a/debian/libtalerexchange.postinst b/debian/libtalerexchange.postinst
new file mode 100644
index 000000000..40b4be061
--- /dev/null
+++ b/debian/libtalerexchange.postinst
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+set -e
+
+. /usr/share/debconf/confmodule
+
+case "${1}" in
+configure)
+
+ if ! dpkg-statoverride --list /etc/taler/taler.conf >/dev/null 2>&1; then
+ dpkg-statoverride --add --update \
+ root root 644 \
+ /etc/taler/taler.conf
+ fi
+
+ ;;
+
+abort-upgrade | abort-remove | abort-deconfigure) ;;
+
+*)
+ echo "postinst called with unknown argument \`${1}'" >&2
+ exit 1
+ ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/rules b/debian/rules
index fa259625e..3d8809c50 100755
--- a/debian/rules
+++ b/debian/rules
@@ -8,7 +8,7 @@ include /usr/share/dpkg/architecture.mk
dh ${@}
override_dh_builddeb:
- dh_builddeb -- -Zgzip
+ dh_builddeb -- -Zgzip
override_dh_auto_configure-arch:
dh_auto_configure -- --disable-rpath --with-microhttpd=yes $(shell dpkg-buildflags --export=configure)
@@ -36,16 +36,20 @@ override_dh_auto_clean:
override_dh_installsystemd:
# Need to specify units manually, since we have multiple
# and dh_installsystemd by default only looks for "<package>.service".
- dh_installsystemd -ptaler-exchange --name=taler-exchange-httpd --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-aggregator --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-transfer --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-wirewatch --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-cs --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-eddsa --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-rsa --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange-closer --no-start --no-enable
- dh_installsystemd -ptaler-auditor --name=taler-auditor-httpd --no-start --no-enable
- dh_installsystemd -ptaler-exchange --name=taler-exchange --no-start --no-enable
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-httpd --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-aggregator --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-expire --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-transfer --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-wirewatch --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-cs --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-eddsa --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-secmod-rsa --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange-closer --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange --name=taler-exchange --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-auditor --name=taler-auditor-httpd --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-auditor --name=taler-helper-auditor-deposits --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange-offline --name=taler-exchange-offline --no-start --no-enable --no-stop-on-upgrade
+ dh_installsystemd -ptaler-exchange-offline --name=taler-exchange-offline.timer --no-start --no-enable --no-stop-on-upgrade
# final invocation to generate daemon reload
dh_installsystemd
diff --git a/debian/taler-auditor.install b/debian/taler-auditor.install
index 0d7d941a0..4f3d5a1b2 100644
--- a/debian/taler-auditor.install
+++ b/debian/taler-auditor.install
@@ -1,16 +1,20 @@
usr/bin/taler-auditor
+usr/bin/taler-auditor-dbconfig
usr/bin/taler-auditor-dbinit
-usr/bin/taler-auditor-exchange
usr/bin/taler-auditor-httpd
usr/bin/taler-auditor-offline
usr/bin/taler-auditor-sync
usr/bin/taler-helper-auditor-*
+
usr/lib/*/taler/libtaler_plugin_auditor*.so
usr/lib/*/libauditor*
usr/lib/*/libtalerauditordb*
+
usr/share/man/man1/taler-auditor*
usr/share/man/man1/taler-helper-auditor*
+
usr/share/info/taler-auditor*
+
usr/share/taler/config.d/auditor*
usr/share/taler/sql/auditor/*
diff --git a/debian/taler-auditor.postinst b/debian/taler-auditor.postinst
index 4e89be226..847e4aac1 100644
--- a/debian/taler-auditor.postinst
+++ b/debian/taler-auditor.postinst
@@ -20,9 +20,10 @@ configure)
adduser --quiet --system --ingroup ${_GROUPNAME} --no-create-home --home ${TALER_HOME} ${_USERNAME}
fi
- if ! dpkg-statoverride --list /etc/taler/secrets/auditor-db.secret.conf >/dev/null 2>&1; then
+ if ! dpkg-statoverride --list /etc/taler/secrets/auditor-db.secret.conf >/dev/null 2>&1
+ then
dpkg-statoverride --add --update \
- ${_USERNAME} ${_GROUPNAME} 660 \
+ ${_USERNAME} ${_GROUPNAME} 640 \
/etc/taler/secrets/auditor-db.secret.conf
fi
diff --git a/debian/taler-auditor.postrm b/debian/taler-auditor.postrm
index 752510e63..639e3241e 100644
--- a/debian/taler-auditor.postrm
+++ b/debian/taler-auditor.postrm
@@ -6,9 +6,16 @@ if [ -f /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
fi
+_USERNAME=taler-auditor-httpd
+_GROUPNAME=taler-auditor-httpd
+
case "${1}" in
purge)
- ;;
+ dpkg-statoverride --remove \
+ /etc/taler/secrets/auditor-db.secret.conf || true
+ deluser --system --quiet ${_USERNAME} || true
+ delgroup --only-if-empty --quiet ${_GROUPNAME} || true
+ ;;
remove | upgrade | failed-upgrade | abort-install | abort-upgrade | disappear) ;;
*)
diff --git a/debian/taler-auditor.taler-auditor-httpd.service b/debian/taler-auditor.taler-auditor-httpd.service
index 9aefab641..ac68e41c8 100644
--- a/debian/taler-auditor.taler-auditor-httpd.service
+++ b/debian/taler-auditor.taler-auditor-httpd.service
@@ -6,7 +6,8 @@ After=postgres.service network.target
User=taler-auditor-httpd
Type=simple
Restart=on-failure
-ExecStart=/usr/bin/taler-auditor-httpd -c /etc/taler/taler.conf
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-auditor-httpd -c /etc/taler/taler.conf -L INFO
[Install]
WantedBy=multi-user.target
diff --git a/debian/taler-auditor.taler-helper-auditor-deposits.service b/debian/taler-auditor.taler-helper-auditor-deposits.service
new file mode 100644
index 000000000..7185a8d52
--- /dev/null
+++ b/debian/taler-auditor.taler-helper-auditor-deposits.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=GNU Taler auditor helper reporting confirmation deposits
+After=postgres.service
+
+[Service]
+User=taler-auditor-httpd
+Type=simple
+Restart=always
+RestartSec=1s
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-helper-auditor-deposits -c /etc/taler/taler.conf -L INFO
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange-database.install b/debian/taler-exchange-database.install
index 56332366d..da8b0dc47 100644
--- a/debian/taler-exchange-database.install
+++ b/debian/taler-exchange-database.install
@@ -1,5 +1,7 @@
+usr/bin/taler-exchange-dbconfig
usr/bin/taler-exchange-dbinit
usr/lib/*/taler/libtaler_plugin_exchange*.so
+usr/share/man/man1/taler-exchange-dbconfig.1
usr/share/man/man1/taler-exchange-dbinit.1
usr/share/taler/sql/exchange/*
usr/share/taler/config.d/exchangedb.conf
diff --git a/debian/taler-exchange-offline.postinst b/debian/taler-exchange-offline.postinst
index e22ad5920..337bfa5d4 100644
--- a/debian/taler-exchange-offline.postinst
+++ b/debian/taler-exchange-offline.postinst
@@ -4,20 +4,21 @@ set -e
. /usr/share/debconf/confmodule
-TALER_HOME="/var/lib/taler"
-
case "${1}" in
configure)
if ! getent group taler-exchange-offline >/dev/null; then
- addgroup --quiet --system taler-exchange-offline
+ addgroup --quiet taler-exchange-offline
fi
if ! getent passwd taler-exchange-offline >/dev/null; then
- adduser --quiet --system \
+ adduser --quiet \
+ --disabled-password \
+ --system \
+ --shell /bin/bash \
+ --home /home/taler-exchange-offline \
--ingroup taler-exchange-offline \
- --no-create-home \
- --home ${TALER_HOME} taler-exchange-offline
+ taler-exchange-offline
fi
;;
diff --git a/debian/taler-exchange-offline.taler-exchange-offline.service b/debian/taler-exchange-offline.taler-exchange-offline.service
new file mode 100644
index 000000000..bd1b93bb3
--- /dev/null
+++ b/debian/taler-exchange-offline.taler-exchange-offline.service
@@ -0,0 +1,23 @@
+# This file is in the public domain.
+#
+# This service is expected to be run via the respective
+# timer to ensure that the keys and fees of the exchange
+# are always current.
+#
+# You are expected to edit it to match your desired
+# setup!
+#
+[Unit]
+Description=Daily taler-exchange-offline run
+Documentation=man:taler-exchange-offline(1)
+
+[Service]
+Type=oneshot
+User=taler-exchange-offline
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+
+Environment="REGIO_CURRENCY=$(taler-config -s taler -o CURRENCY)"
+ExecStart=bash -c 'taler-exchange-offline download sign wire-fee now iban "${REGIO_CURRENCY}":0 "${REGIO_CURRENCY}":0 wire-fee now x-taler-bank "${REGIO_CURRENCY}":0 "${REGIO_CURRENCY}":0 global-fee now "${REGIO_CURRENCY}:0" "${REGIO_CURRENCY}:0" "${REGIO_CURRENCY}:0" 4weeks 6years 4 upload'
diff --git a/debian/taler-exchange-offline.taler-exchange-offline.timer b/debian/taler-exchange-offline.taler-exchange-offline.timer
new file mode 100644
index 000000000..5e605e818
--- /dev/null
+++ b/debian/taler-exchange-offline.taler-exchange-offline.timer
@@ -0,0 +1,20 @@
+# This file is in the public domain.
+#
+# Note that this timer is deliberately NOT active
+# by default as it is ONLY applicable if the
+# taler-exchange-offline tool is run on the *online*
+# service and not actually offline. It is provided
+# for convenience in setups that do not use offline
+# signing. You may need to adjust the
+# taler-exchange-offline.service file before using it!
+[Unit]
+Description=taler-exchange-offline maintenance
+Documentation=man:taler-exchange-offline(1)
+
+[Timer]
+OnCalendar=daily
+AccuracySec=12h
+Persistent=true
+
+[Install]
+WantedBy=timers.target
diff --git a/debian/taler-exchange.install b/debian/taler-exchange.install
index 0af0788ae..f8fef2c3b 100644
--- a/debian/taler-exchange.install
+++ b/debian/taler-exchange.install
@@ -1,8 +1,12 @@
usr/bin/taler-exchange-aggregator
usr/bin/taler-exchange-closer
-usr/bin/taler-exchange-dbinit
+usr/bin/taler-exchange-drain
usr/bin/taler-exchange-expire
usr/bin/taler-exchange-httpd
+usr/bin/taler-exchange-kyc-aml-pep-trigger.sh
+usr/bin/taler-exchange-kyc-oauth2-challenger.sh
+usr/bin/taler-exchange-kyc-kycaid-converter.sh
+usr/bin/taler-exchange-kyc-persona-converter.sh
usr/bin/taler-exchange-router
usr/bin/taler-exchange-secmod-cs
usr/bin/taler-exchange-secmod-eddsa
@@ -10,25 +14,27 @@ usr/bin/taler-exchange-secmod-rsa
usr/bin/taler-exchange-transfer
usr/bin/taler-exchange-wirewatch
usr/bin/taler-exchange-wire-gateway-client
+usr/lib/*/taler/libtaler_plugin_kyclogic_*.so
+usr/lib/*/taler/libtaler_extension_*.so
usr/share/man/man1/taler-exchange-aggregator*
usr/share/man/man1/taler-exchange-closer*
+usr/share/man/man1/taler-exchange-dbconfig*
usr/share/man/man1/taler-exchange-dbinit*
+usr/share/man/man1/taler-exchange-drain*
usr/share/man/man1/taler-exchange-expire*
usr/share/man/man1/taler-exchange-httpd*
+usr/share/man/man1/taler-exchange-kyc-aml-pep-trigger*
usr/share/man/man1/taler-exchange-router*
+usr/share/man/man1/taler-exchange-secmod-cs*
usr/share/man/man1/taler-exchange-secmod-eddsa*
usr/share/man/man1/taler-exchange-secmod-rsa*
-usr/share/man/man1/taler-exchange-secmod-cs*
usr/share/man/man1/taler-exchange-transfer*
-usr/share/man/man1/taler-exchange-wirewatch*
-usr/share/man/man1/taler-bank*
usr/share/man/man1/taler-exchange-wire-gateway-client*
-usr/share/info/taler-bank*
+usr/share/man/man1/taler-exchange-wirewatch*
usr/share/info/taler-exchange*
usr/share/taler/config.d/*
+usr/share/taler/exchange/templates/*.must
+usr/share/taler/exchange/spa/*
# configuration files in /etc/taler
debian/etc-taler-exchange/* etc/
-
-usr/share/taler/exchange/pp/*/*
-usr/share/taler/exchange/tos/*/*
diff --git a/debian/taler-exchange.postinst b/debian/taler-exchange.postinst
index b68ee19f4..7509a7749 100644
--- a/debian/taler-exchange.postinst
+++ b/debian/taler-exchange.postinst
@@ -13,6 +13,7 @@ _CSECUSERNAME=taler-exchange-secmod-cs
_RSECUSERNAME=taler-exchange-secmod-rsa
_ESECUSERNAME=taler-exchange-secmod-eddsa
_AGGRUSERNAME=taler-exchange-aggregator
+_EXPIUSERNAME=taler-exchange-expire
_WIREUSERNAME=taler-exchange-wire
case "${1}" in
@@ -30,6 +31,7 @@ configure)
if ! getent passwd ${_EUSERNAME} >/dev/null; then
adduser --quiet --system --no-create-home --ingroup ${_GROUPNAME} --home ${TALER_HOME} ${_EUSERNAME}
adduser --quiet ${_EUSERNAME} ${_DBGROUPNAME}
+ adduser --quiet ${_EUSERNAME} ${_GROUPNAME}
fi
if ! getent passwd ${_RSECUSERNAME} >/dev/null; then
adduser --quiet --system --no-create-home --ingroup ${_GROUPNAME} --home ${TALER_HOME} ${_RSECUSERNAME}
@@ -52,16 +54,20 @@ configure)
adduser --quiet --system --no-create-home --home ${TALER_HOME} ${_AGGRUSERNAME}
adduser --quiet ${_AGGRUSERNAME} ${_DBGROUPNAME}
fi
+ if ! getent passwd ${_EXPIUSERNAME} >/dev/null; then
+ adduser --quiet --system --no-create-home --home ${TALER_HOME} ${_EXPIUSERNAME}
+ adduser --quiet ${_EXPIUSERNAME} ${_DBGROUPNAME}
+ fi
- if ! dpkg-statoverride --list /etc/taler/secrets/exchange-accountcredentials.secret.conf >/dev/null 2>&1; then
+ if ! dpkg-statoverride --list /etc/taler/secrets/exchange-accountcredentials-1.secret.conf >/dev/null 2>&1; then
dpkg-statoverride --add --update \
- ${_WIREUSERNAME} root 460 \
- /etc/taler/secrets/exchange-accountcredentials.secret.conf
+ ${_WIREUSERNAME} root 640 \
+ /etc/taler/secrets/exchange-accountcredentials-1.secret.conf
fi
if ! dpkg-statoverride --list /etc/taler/secrets/exchange-db.secret.conf >/dev/null 2>&1; then
dpkg-statoverride --add --update \
- root ${_DBGROUPNAME} 660 \
+ root ${_DBGROUPNAME} 640 \
/etc/taler/secrets/exchange-db.secret.conf
fi
diff --git a/debian/taler-exchange.postrm b/debian/taler-exchange.postrm
index 6488d268b..fcde84b58 100644
--- a/debian/taler-exchange.postrm
+++ b/debian/taler-exchange.postrm
@@ -2,6 +2,18 @@
set -e
+_GROUPNAME=taler-exchange-secmod
+_DBGROUPNAME=taler-exchange-db
+_EUSERNAME=taler-exchange-httpd
+_CLOSERUSERNAME=taler-exchange-closer
+_CSECUSERNAME=taler-exchange-secmod-cs
+_RSECUSERNAME=taler-exchange-secmod-rsa
+_ESECUSERNAME=taler-exchange-secmod-eddsa
+_AGGRUSERNAME=taler-exchange-aggregator
+_EXPIUSERNAME=taler-exchange-expire
+_WIREUSERNAME=taler-exchange-wire
+
+
if [ -f /usr/share/debconf/confmodule ]; then
. /usr/share/debconf/confmodule
fi
@@ -9,6 +21,20 @@ fi
case "${1}" in
purge)
rm -rf /var/lib/taler/exchange-offline /var/lib/taler/exchange-secmod-*
+ dpkg-statoverride --remove \
+ /etc/taler/secrets/exchange-accountcredentials-1.secret.conf || true
+ dpkg-statoverride --remove \
+ /etc/taler/secrets/exchange-db.secret.conf || true
+ deluser --quiet --system ${_CSECUSERNAME} || true
+ deluser --quiet --system ${_RSECUSERNAME} || true
+ deluser --quiet --system ${_ESECUSERNAME} || true
+ deluser --quiet --system ${_AGGRUSERNAME} || true
+ deluser --quiet --system ${_EXPIUSERNAME} || true
+ deluser --quiet --system ${_WIREUSERNAME} || true
+ deluser --quiet --system ${_CLOSERUSERNAME} || true
+ deluser --quiet --system ${_EUSERNAME} || true
+ delgroup --only-if-empty --quiet ${_DBGROUPNAME} || true
+ delgroup --only-if-empty --quiet ${_GROUPNAME} || true
;;
remove | upgrade | failed-upgrade | abort-install | abort-upgrade | disappear)
diff --git a/debian/taler-exchange.taler-exchange-aggregator.service b/debian/taler-exchange.taler-exchange-aggregator.service
index 683c1a81e..db297270f 100644
--- a/debian/taler-exchange.taler-exchange-aggregator.service
+++ b/debian/taler-exchange.taler-exchange-aggregator.service
@@ -1,15 +1,20 @@
[Unit]
Description=GNU Taler payment system exchange aggregator service
PartOf=taler-exchange.target
+After=postgres.service
[Service]
User=taler-exchange-aggregator
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/taler.conf
+RestartMode=direct
+RestartSec=1s
+RestartPreventExitStatus=2 3 4 5 6 9
+ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange-aggregator@.service b/debian/taler-exchange.taler-exchange-aggregator@.service
new file mode 100644
index 000000000..b13997ae2
--- /dev/null
+++ b/debian/taler-exchange.taler-exchange-aggregator@.service
@@ -0,0 +1,24 @@
+# This is a systemd service template to instantiate
+# the service multiple times for parallelism.
+# We currently don't ship it with the package,
+# but might use it for future high-performance
+# deployments.
+
+[Unit]
+Description=GNU Taler payment system exchange aggregator service
+PartOf=taler-exchange.target
+
+[Service]
+User=taler-exchange-aggregator
+Type=simple
+Restart=always
+RestartSec=1s
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/taler.conf -L INFO
+StandardOutput=journal
+StandardError=journal
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange-closer.service b/debian/taler-exchange.taler-exchange-closer.service
index 01c52b2d4..ba57522b0 100644
--- a/debian/taler-exchange.taler-exchange-closer.service
+++ b/debian/taler-exchange.taler-exchange-closer.service
@@ -1,15 +1,20 @@
[Unit]
Description=GNU Taler payment system exchange closer service
PartOf=taler-exchange.target
+After=network.target postgres.service
[Service]
User=taler-exchange-closer
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-closer -c /etc/taler/taler.conf
+RestartMode=direct
+RestartSec=1s
+RestartPreventExitStatus=2 3 4 5 6 9
+ExecStart=/usr/bin/taler-exchange-closer -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange-expire.service b/debian/taler-exchange.taler-exchange-expire.service
index f44829c5e..8fd9a9f74 100644
--- a/debian/taler-exchange.taler-exchange-expire.service
+++ b/debian/taler-exchange.taler-exchange-expire.service
@@ -1,15 +1,20 @@
[Unit]
Description=GNU Taler payment system exchange expire service
PartOf=taler-exchange.target
+After=postgres.service
[Service]
User=taler-exchange-expire
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-expire -c /etc/taler/taler.conf
+RestartMode=direct
+RestartSec=1s
+RestartPreventExitStatus=2 3 4 5 6 9
+ExecStart=/usr/bin/taler-exchange-expire -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange-httpd.service b/debian/taler-exchange.taler-exchange-httpd.service
index 68bde0d66..cbde72522 100644
--- a/debian/taler-exchange.taler-exchange-httpd.service
+++ b/debian/taler-exchange.taler-exchange-httpd.service
@@ -8,17 +8,28 @@ PartOf=taler-exchange.target
[Service]
User=taler-exchange-httpd
Type=simple
-# Depending on the configuration, the service suicides and then
-# needs to be restarted.
+
+# Depending on the configuration, the service process kills itself and then
+# needs to be restarted. Thus no significant delay on restarts.
Restart=always
-# Do not dally on restarts.
+RestartMode=direct
RestartSec=1ms
-ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf
+RestartPreventExitStatus=2 3 4 5 6 9
+
+# Disable the service if more than 5 restarts are encountered within 5s.
+# These are usually the systemd defaults, but can be overwritten, thus we set
+# them here explicitly, as the exchange code assumes StartLimitInterval
+# to be >=5s.
+StartLimitBurst=5
+StartLimitInterval=5s
+
+ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
[Install]
WantedBy=multi-user.target
diff --git a/debian/taler-exchange.taler-exchange-httpd@.service b/debian/taler-exchange.taler-exchange-httpd@.service
index 4235f72e9..c4d010b80 100644
--- a/debian/taler-exchange.taler-exchange-httpd@.service
+++ b/debian/taler-exchange.taler-exchange-httpd@.service
@@ -1,4 +1,9 @@
-% This is a systemd service template.
+# This is a systemd service template to instantiate
+# the service multiple times for parallelism.
+# We currently don't ship it with the package,
+# but might use it for future high-performance
+# deployments.
+
[Unit]
Description=GNU Taler payment system exchange REST API at %I
AssertPathExists=/run/taler/exchange-httpd
@@ -14,13 +19,15 @@ Type=simple
Restart=always
# Do not dally on restarts.
RestartSec=1ms
+RestartPreventExitStatus=9
EnvironmentFile=/etc/environment
-ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf
+ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
[Install]
WantedBy=multi-user.target
diff --git a/debian/taler-exchange.taler-exchange-secmod-cs.service b/debian/taler-exchange.taler-exchange-secmod-cs.service
index 15b87a3c9..b11c04552 100644
--- a/debian/taler-exchange.taler-exchange-secmod-cs.service
+++ b/debian/taler-exchange.taler-exchange-secmod-cs.service
@@ -8,9 +8,12 @@ User=taler-exchange-secmod-cs
Type=simple
Restart=always
RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-secmod-cs -c /etc/taler/taler.conf
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-exchange-secmod-cs -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
diff --git a/debian/taler-exchange.taler-exchange-secmod-eddsa.service b/debian/taler-exchange.taler-exchange-secmod-eddsa.service
index e4898581c..17f1da3f5 100644
--- a/debian/taler-exchange.taler-exchange-secmod-eddsa.service
+++ b/debian/taler-exchange.taler-exchange-secmod-eddsa.service
@@ -8,9 +8,12 @@ User=taler-exchange-secmod-eddsa
Type=simple
Restart=always
RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-secmod-eddsa -c /etc/taler/taler.conf
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-exchange-secmod-eddsa -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
diff --git a/debian/taler-exchange.taler-exchange-secmod-rsa.service b/debian/taler-exchange.taler-exchange-secmod-rsa.service
index 6c5a3d613..854737d03 100644
--- a/debian/taler-exchange.taler-exchange-secmod-rsa.service
+++ b/debian/taler-exchange.taler-exchange-secmod-rsa.service
@@ -8,9 +8,12 @@ User=taler-exchange-secmod-rsa
Type=simple
Restart=always
RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-secmod-rsa -c /etc/taler/taler.conf
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-exchange-secmod-rsa -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full
+IPAddressDeny=any
+Slice=taler-exchange.slice
diff --git a/debian/taler-exchange.taler-exchange-transfer.service b/debian/taler-exchange.taler-exchange-transfer.service
index b2615b7c9..ffe2f1955 100644
--- a/debian/taler-exchange.taler-exchange-transfer.service
+++ b/debian/taler-exchange.taler-exchange-transfer.service
@@ -1,16 +1,20 @@
[Unit]
Description=Taler Exchange Transfer Service
-After=network.target
+After=network.target postgres.service
PartOf=taler-exchange.target
[Service]
User=taler-exchange-wire
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-transfer -c /etc/taler/taler.conf
+RestartMode=direct
+RestartSec=1s
+RestartPreventExitStatus=2 3 4 5 6 9
+ExecStart=/usr/bin/taler-exchange-transfer -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange-wirewatch.service b/debian/taler-exchange.taler-exchange-wirewatch.service
index 54704cb80..40103bb51 100644
--- a/debian/taler-exchange.taler-exchange-wirewatch.service
+++ b/debian/taler-exchange.taler-exchange-wirewatch.service
@@ -1,16 +1,20 @@
[Unit]
Description=GNU Taler payment system exchange wirewatch service
-After=network.target
+After=network.target postgres.service
PartOf=taler-exchange.target
[Service]
User=taler-exchange-wire
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf
+RestartMode=direct
+RestartSec=1s
+RestartPreventExitStatus=2 3 4 5 6 9
+RuntimeMaxSec=3600s
+ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
diff --git a/debian/taler-exchange.taler-exchange-wirewatch@.service b/debian/taler-exchange.taler-exchange-wirewatch@.service
index 54704cb80..a2836c6b9 100644
--- a/debian/taler-exchange.taler-exchange-wirewatch@.service
+++ b/debian/taler-exchange.taler-exchange-wirewatch@.service
@@ -1,3 +1,9 @@
+# This is a systemd service template to instantiate
+# the service multiple times for parallelism.
+# We currently don't ship it with the package,
+# but might use it for future high-performance
+# deployments.
+
[Unit]
Description=GNU Taler payment system exchange wirewatch service
After=network.target
@@ -7,10 +13,13 @@ PartOf=taler-exchange.target
User=taler-exchange-wire
Type=simple
Restart=always
-RestartSec=100ms
-ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf
+RestartSec=1s
+RestartPreventExitStatus=9
+ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/taler.conf -L INFO
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
+Slice=taler-exchange.slice
+RuntimeMaxSec=3600s
diff --git a/debian/taler-exchange.taler-exchange.slice b/debian/taler-exchange.taler-exchange.slice
new file mode 100644
index 000000000..b5bb71e2e
--- /dev/null
+++ b/debian/taler-exchange.taler-exchange.slice
@@ -0,0 +1,7 @@
+[Unit]
+Description=Slice for GNU taler exchange processes
+Before=slices.target
+
+[Slice]
+# Add settings that should affect all GNU Taler exchange
+# components here.
diff --git a/debian/taler-exchange.tmpfiles b/debian/taler-exchange.tmpfiles
index 79554ccf2..c2a796539 100644
--- a/debian/taler-exchange.tmpfiles
+++ b/debian/taler-exchange.tmpfiles
@@ -1,7 +1,8 @@
#Type Path Mode UID GID Age Argument
d /run/taler/exchange-secmod-rsa 0755 taler-exchange-secmod-rsa taler-exchange-secmod - -
+d /run/taler/exchange-secmod-cs 0755 taler-exchange-secmod-cs taler-exchange-secmod - -
d /run/taler/exchange-secmod-eddsa 0755 taler-exchange-secmod-eddsa taler-exchange-secmod - -
d /run/taler/exchange-httpd 0750 taler-exchange-httpd www-data - -
-d /var/lib/taler/exchange-offline 0700 taler-exchange-offline taler-exchange-offline - -
+d /var/lib/taler/exchange-secmod-cs 0700 taler-exchange-secmod-cs taler-exchange-secmod - -
d /var/lib/taler/exchange-secmod-rsa 0700 taler-exchange-secmod-rsa taler-exchange-secmod - -
d /var/lib/taler/exchange-secmod-eddsa 0700 taler-exchange-secmod-eddsa taler-exchange-secmod - -
diff --git a/debian/taler-terms-generator.install b/debian/taler-terms-generator.install
new file mode 100644
index 000000000..19972ffc7
--- /dev/null
+++ b/debian/taler-terms-generator.install
@@ -0,0 +1,8 @@
+usr/share/man/man1/taler-terms-generator.1
+usr/bin/taler-terms-generator
+
+# Terms of service / privacy policy templates
+usr/share/taler/terms/*.rst
+
+# Translations of ToS/PP
+usr/share/locale/*/LC_MESSAGES/*.po
diff --git a/doc/Makefile.am b/doc/Makefile.am
index edb226a86..ca973a1a5 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -9,40 +9,56 @@ infoimagedir = $(infodir)/images
man_MANS = \
prebuilt/man/taler.conf.5 \
prebuilt/man/taler-config.1 \
+ prebuilt/man/taler-aggregator-benchmark.1 \
prebuilt/man/taler-auditor.1 \
prebuilt/man/taler-auditor-dbinit.1 \
- prebuilt/man/taler-auditor-exchange.1 \
prebuilt/man/taler-auditor-httpd.1 \
prebuilt/man/taler-auditor-offline.1 \
prebuilt/man/taler-auditor-sign.1 \
prebuilt/man/taler-auditor-sync.1 \
- prebuilt/man/taler-bank-transfer.1 \
+ prebuilt/man/taler-bank-benchmark.1 \
prebuilt/man/taler-exchange-aggregator.1 \
prebuilt/man/taler-exchange-benchmark.1 \
prebuilt/man/taler-exchange-closer.1 \
+ prebuilt/man/taler-exchange-dbconfig.1 \
prebuilt/man/taler-exchange-dbinit.1 \
+ prebuilt/man/taler-exchange-drain.1 \
prebuilt/man/taler-exchange-expire.1 \
prebuilt/man/taler-exchange-httpd.1 \
+ prebuilt/man/taler-exchange-kyc-aml-pep-trigger.1 \
+ prebuilt/man/taler-exchange-kyc-tester.1 \
prebuilt/man/taler-exchange-offline.1 \
+ prebuilt/man/taler-exchange-router.1\
prebuilt/man/taler-exchange-secmod-cs.1\
prebuilt/man/taler-exchange-secmod-eddsa.1\
prebuilt/man/taler-exchange-secmod-rsa.1 \
- prebuilt/man/taler-exchange-router.1\
prebuilt/man/taler-exchange-transfer.1\
- prebuilt/man/taler-exchange-wirewatch.1 \
prebuilt/man/taler-exchange-wire-gateway-client.1\
+ prebuilt/man/taler-exchange-wirewatch.1 \
+ prebuilt/man/taler-fakebank-run.1 \
prebuilt/man/taler-helper-auditor-aggregation.1 \
prebuilt/man/taler-helper-auditor-coins.1\
prebuilt/man/taler-helper-auditor-deposits.1\
+ prebuilt/man/taler-helper-auditor-purses.1\
prebuilt/man/taler-helper-auditor-reserves.1\
- prebuilt/man/taler-helper-auditor-wire.1
+ prebuilt/man/taler-helper-auditor-wire.1 \
+ prebuilt/man/taler-terms-generator.1 \
+ prebuilt/man/taler-unified-setup.1
info_TEXINFOS = \
prebuilt/texinfo/taler-auditor.texi \
- prebuilt/texinfo/taler-bank.texi \
prebuilt/texinfo/taler-developer-manual.texi \
prebuilt/texinfo/taler-exchange.texi
+install-info-local:
+ @echo " $(MKDIR_P) '$(DESTDIR)$(infodir)/taler-auditor-figures'"; \
+ $(MKDIR_P) "$(DESTDIR)$(infodir)/taler-auditor-figures" || exit 1; \
+ @echo " $(MKDIR_P) '$(DESTDIR)$(infodir)/taler-exchange-figures'"; \
+ $(MKDIR_P) "$(DESTDIR)$(infodir)/taler-exchange-figures" || exit 1; \
+ echo " $(INSTALL_DATA) auditor-db.png replication.png '$(DESTDIR)$(infodir)/taler-auditor-figures'"; \
+ $(INSTALL_DATA) '$(srcdir)/prebuilt/texinfo/taler-auditor-figures/auditor-db.png' '$(srcdir)/prebuilt/texinfo/taler-auditor-figures/replication.png' "$(DESTDIR)$(infodir)/taler-auditor-figures" || exit 1;
+ echo " $(INSTALL_DATA) kyc-process.png exchange-db.png '$(DESTDIR)$(infodir)/taler-exchange-figures'"; \
+ $(INSTALL_DATA) '$(srcdir)/prebuilt/texinfo/taler-exchange-figures/kyc-process.png' '$(srcdir)/prebuilt/texinfo/taler-exchange-figures/exchange-db.png' "$(DESTDIR)$(infodir)/taler-exchange-figures" || exit 1;
EXTRA_DIST = \
$(man_MANS) \
@@ -50,16 +66,5 @@ EXTRA_DIST = \
$(info_TEXINFOS) \
prebuilt/texinfo/taler-auditor-figures/auditor-db.png \
prebuilt/texinfo/taler-auditor-figures/replication.png \
- prebuilt/texinfo/taler-bank-figures/arch-api.png \
- prebuilt/texinfo/taler-bank-figures/auditor-db.png \
- prebuilt/texinfo/taler-bank-figures/exchange-db.png \
- prebuilt/texinfo/taler-bank-figures/merchant-db.png \
- prebuilt/texinfo/taler-bank-figures/replication.png \
- prebuilt/texinfo/taler-developer-manual-figures/arch-api.png \
- prebuilt/texinfo/taler-developer-manual-figures/auditor-db.png \
- prebuilt/texinfo/taler-developer-manual-figures/exchange-db.png \
- prebuilt/texinfo/taler-developer-manual-figures/merchant-db.png \
- prebuilt/texinfo/taler-developer-manual-figures/replication.png \
- prebuilt/texinfo/taler-exchange-figures/auditor-db.png \
- prebuilt/texinfo/taler-exchange-figures/exchange-db.png\
- prebuilt/texinfo/taler-exchange-figures/replication.png
+ prebuilt/texinfo/taler-exchange-figures/kyc-process.png \
+ prebuilt/texinfo/taler-exchange-figures/exchange-db.png
diff --git a/doc/cs/content/4_2_specification.tex b/doc/cs/content/4_2_specification.tex
index fe745fc69..bfbe5edc7 100644
--- a/doc/cs/content/4_2_specification.tex
+++ b/doc/cs/content/4_2_specification.tex
@@ -467,7 +467,7 @@ The exchange offline signer requests the future, not yet signed keys by calling
master\_pub & Exchange's master public key \\
denom\_secmod\_public\_key & RSA security module public key \\
denom\_secmod\_cs\_public\_key & \gls{CSBS} security module public key \\
- signkey\_secmod\_public\_key & Online singing security module public key \\
+ signkey\_secmod\_public\_key & Online signing security module public key \\
\end{tabular}
\caption{GET \url{/management/keys} response data}
\label{tab:management-keys-get}
diff --git a/doc/doxygen/taler.doxy b/doc/doxygen/taler.doxy
index dafe78fa5..1516811c5 100644
--- a/doc/doxygen/taler.doxy
+++ b/doc/doxygen/taler.doxy
@@ -1,17 +1,144 @@
-# Doxyfile 1.5.6
+# Doxyfile 1.9.4
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a double hash (##) is considered a comment and is placed in
+# front of the TAG it is preceding.
+#
+# All text after a single hash (#) is considered a comment and will be ignored.
+# The format is:
+# TAG = value [value, ...]
+# For lists, items can also be appended using:
+# TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (\" \").
+#
+# Note:
+#
+# Use doxygen to compare the used configuration file with the template
+# configuration file:
+# doxygen -x [configFile]
+# Use doxygen to compare the used configuration file with the template
+# configuration file without replacing the environment variables:
+# doxygen -x_noenv [configFile]
#---------------------------------------------------------------------------
# Project related configuration options
#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the configuration
+# file that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# https://www.gnu.org/software/libiconv/ for the list of possible encodings.
+# The default value is: UTF-8.
+
DOXYFILE_ENCODING = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by
+# double-quotes, unless you are using Doxywizard) that should identify the
+# project for which the documentation is generated. This name is used in the
+# title of most generated pages and in a few other places.
+# The default value is: My Project.
+
PROJECT_NAME = "GNU Taler: Exchange"
-PROJECT_NUMBER = 0.8.3
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number. This
+# could be handy for archiving the generated documentation or if some version
+# control system is used.
+
+PROJECT_NUMBER = 0.10.2
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer a
+# quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF =
+
+# With the PROJECT_LOGO tag one can specify a logo or an icon that is included
+# in the documentation. The maximum height of the logo should not exceed 55
+# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy
+# the logo to the output directory.
+
PROJECT_LOGO = logo.svg
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path
+# into which the generated documentation will be written. If a relative path is
+# entered, it will be relative to the location where doxygen was started. If
+# left blank the current directory will be used.
+
OUTPUT_DIRECTORY = .
+
+# If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096
+# sub-directories (in 2 levels) under the output directory of each output format
+# and will distribute the generated files over these directories. Enabling this
+# option can be useful when feeding doxygen a huge amount of source files, where
+# putting all generated files in the same directory would otherwise causes
+# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to
+# control the number of sub-directories.
+# The default value is: NO.
+
CREATE_SUBDIRS = YES
+
+# Controls the number of sub-directories that will be created when
+# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every
+# level increment doubles the number of directories, resulting in 4096
+# directories at level 8 which is the default and also the maximum value. The
+# sub-directories are organized in 2 levels, the first level always has a fixed
+# number of 16 directories.
+# Minimum value: 0, maximum value: 8, default value: 8.
+# This tag requires that the tag CREATE_SUBDIRS is set to YES.
+
+# CREATE_SUBDIRS_LEVEL = 8
+
+# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
+# characters to appear in the names of generated files. If set to NO, non-ASCII
+# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode
+# U+3044.
+# The default value is: NO.
+
+ALLOW_UNICODE_NAMES = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian,
+# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English
+# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek,
+# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with
+# English messages), Korean, Korean-en (Korean with English messages), Latvian,
+# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese,
+# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish,
+# Swedish, Turkish, Ukrainian and Vietnamese.
+# The default value is: English.
+
OUTPUT_LANGUAGE = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
+# descriptions after the members that are listed in the file and class
+# documentation (similar to Javadoc). Set to NO to disable this.
+# The default value is: YES.
+
BRIEF_MEMBER_DESC = YES
+
+# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief
+# description of a member or function before the detailed description
+#
+# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+# The default value is: YES.
+
REPEAT_BRIEF = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator that is
+# used to form the text in various listings. Each string in this list, if found
+# as the leading text of the brief description, will be stripped from the text
+# and the result, after processing the whole list, is used as the annotated
+# text. Otherwise, the brief description is used as-is. If left blank, the
+# following values are used ($name is automatically replaced with the name of
+# the entity):The $name class, The $name widget, The $name file, is, provides,
+# specifies, contains, represents, a, an and the.
+
ABBREVIATE_BRIEF = "The $name class" \
"The $name widget" \
"The $name file" \
@@ -23,282 +150,2550 @@ ABBREVIATE_BRIEF = "The $name class" \
a \
an \
the
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# doxygen will generate a detailed section even if there is only a brief
+# description.
+# The default value is: NO.
+
ALWAYS_DETAILED_SEC = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+# The default value is: NO.
+
INLINE_INHERITED_MEMB = NO
+
+# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path
+# before files name in the file list and in the header files. If set to NO the
+# shortest path that makes the file name unique will be used
+# The default value is: YES.
+
FULL_PATH_NAMES = YES
+
+# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
+# Stripping is only done if one of the specified strings matches the left-hand
+# part of the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the path to
+# strip.
+#
+# Note that you can specify absolute paths here, but also relative paths, which
+# will be relative from the directory where doxygen is started.
+# This tag requires that the tag FULL_PATH_NAMES is set to YES.
+
STRIP_FROM_PATH = ../..
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
+# path mentioned in the documentation of a class, which tells the reader which
+# header file to include in order to use a class. If left blank only the name of
+# the header file containing the class definition is used. Otherwise one should
+# specify the list of include paths that are normally passed to the compiler
+# using the -I flag.
+
STRIP_FROM_INC_PATH = ../../src/include \
src/include \
include
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but
+# less readable) file names. This can be useful is your file systems doesn't
+# support long names like on DOS, Mac, or CD-ROM.
+# The default value is: NO.
+
SHORT_NAMES = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the
+# first line (until the first dot) of a Javadoc-style comment as the brief
+# description. If set to NO, the Javadoc-style will behave just like regular Qt-
+# style comments (thus requiring an explicit @brief command for a brief
+# description.)
+# The default value is: NO.
+
JAVADOC_AUTOBRIEF = YES
+
+# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line
+# such as
+# /***************
+# as being the beginning of a Javadoc-style comment "banner". If set to NO, the
+# Javadoc-style will behave just like regular comments and it will not be
+# interpreted by doxygen.
+# The default value is: NO.
+
+JAVADOC_BANNER = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
+# line (until the first dot) of a Qt-style comment as the brief description. If
+# set to NO, the Qt-style will behave just like regular Qt-style comments (thus
+# requiring an explicit \brief command for a brief description.)
+# The default value is: NO.
+
QT_AUTOBRIEF = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a
+# multi-line C++ special comment block (i.e. a block of //! or /// comments) as
+# a brief description. This used to be the default behavior. The new default is
+# to treat a multi-line C++ comment block as a detailed description. Set this
+# tag to YES if you prefer the old behavior instead.
+#
+# Note that setting this tag to YES also means that rational rose comments are
+# not recognized any more.
+# The default value is: NO.
+
MULTILINE_CPP_IS_BRIEF = NO
+
+# By default Python docstrings are displayed as preformatted text and doxygen's
+# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the
+# doxygen's special commands can be used and the contents of the docstring
+# documentation blocks is shown as doxygen documentation.
+# The default value is: YES.
+
+PYTHON_DOCSTRING = YES
+
+# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the
+# documentation from any documented member that it re-implements.
+# The default value is: YES.
+
INHERIT_DOCS = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new
+# page for each member. If set to NO, the documentation of a member will be part
+# of the file/class/namespace that contains it.
+# The default value is: NO.
+
SEPARATE_MEMBER_PAGES = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen
+# uses this value to replace tabs by spaces in code fragments.
+# Minimum value: 1, maximum value: 16, default value: 4.
+
TAB_SIZE = 8
+
+# This tag can be used to specify a number of aliases that act as commands in
+# the documentation. An alias has the form:
+# name=value
+# For example adding
+# "sideeffect=@par Side Effects:^^"
+# will allow you to put the command \sideeffect (or @sideeffect) in the
+# documentation, which will result in a user-defined paragraph with heading
+# "Side Effects:". Note that you cannot put \n's in the value part of an alias
+# to insert newlines (in the resulting output). You can put ^^ in the value part
+# of an alias to insert a newline as if a physical newline was in the original
+# file. When you need a literal { or } or , in the value part of an alias you
+# have to escape them by means of a backslash (\), this can lead to conflicts
+# with the commands \{ and \} for these it is advised to use the version @{ and
+# @} or use a double escape (\\{ and \\})
+
ALIASES =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources
+# only. Doxygen will then generate output that is more tailored for C. For
+# instance, some of the names that are used will be different. The list of all
+# members will be omitted, etc.
+# The default value is: NO.
+
OPTIMIZE_OUTPUT_FOR_C = YES
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or
+# Python sources only. Doxygen will then generate output that is more tailored
+# for that language. For instance, namespaces will be presented as packages,
+# qualified scopes will look different, etc.
+# The default value is: NO.
+
OPTIMIZE_OUTPUT_JAVA = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources. Doxygen will then generate output that is tailored for Fortran.
+# The default value is: NO.
+
OPTIMIZE_FOR_FORTRAN = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for VHDL.
+# The default value is: NO.
+
OPTIMIZE_OUTPUT_VHDL = NO
+
+# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice
+# sources only. Doxygen will then generate output that is more tailored for that
+# language. For instance, namespaces will be presented as modules, types will be
+# separated into more groups, etc.
+# The default value is: NO.
+
+OPTIMIZE_OUTPUT_SLICE = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given
+# extension. Doxygen has a built-in mapping, but you can override or extend it
+# using this tag. The format is ext=language, where ext is a file extension, and
+# language is one of the parsers supported by doxygen: IDL, Java, JavaScript,
+# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice,
+# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran:
+# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser
+# tries to guess whether the code is fixed or free formatted code, this is the
+# default for Fortran type files). For instance to make doxygen treat .inc files
+# as Fortran files (default is PHP), and .f files as C (default is Fortran),
+# use: inc=Fortran f=C.
+#
+# Note: For files without extension you can use no_extension as a placeholder.
+#
+# Note that for custom extensions you also need to set FILE_PATTERNS otherwise
+# the files are not read by doxygen. When specifying no_extension you should add
+# * to the FILE_PATTERNS.
+#
+# Note see also the list of default file extension mappings.
+
+EXTENSION_MAPPING =
+
+# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments
+# according to the Markdown format, which allows for more readable
+# documentation. See https://daringfireball.net/projects/markdown/ for details.
+# The output of markdown processing is further processed by doxygen, so you can
+# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in
+# case of backward compatibilities issues.
+# The default value is: YES.
+
+MARKDOWN_SUPPORT = YES
+
+# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up
+# to that level are automatically included in the table of contents, even if
+# they do not have an id attribute.
+# Note: This feature currently applies only to Markdown headings.
+# Minimum value: 0, maximum value: 99, default value: 5.
+# This tag requires that the tag MARKDOWN_SUPPORT is set to YES.
+
+TOC_INCLUDE_HEADINGS = 5
+
+# When enabled doxygen tries to link words that correspond to documented
+# classes, or namespaces to their corresponding documentation. Such a link can
+# be prevented in individual cases by putting a % sign in front of the word or
+# globally by setting AUTOLINK_SUPPORT to NO.
+# The default value is: YES.
+
+AUTOLINK_SUPPORT = YES
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should set this
+# tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string);
+# versus func(std::string) {}). This also make the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+# The default value is: NO.
+
BUILTIN_STL_SUPPORT = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+# The default value is: NO.
+
CPP_CLI_SUPPORT = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip (see:
+# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen
+# will parse them like normal C++ but will assume all classes use public instead
+# of private inheritance when no explicit protection keyword is present.
+# The default value is: NO.
+
SIP_SUPPORT = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate
+# getter and setter methods for a property. Setting this option to YES will make
+# doxygen to replace the get and set methods by a property in the documentation.
+# This will only work if the methods are indeed getting or setting a simple
+# type. If this is not the case, or you want to show the methods anyway, you
+# should set this option to NO.
+# The default value is: YES.
+
IDL_PROPERTY_SUPPORT = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+# The default value is: NO.
+
DISTRIBUTE_GROUP_DOC = NO
+
+# If one adds a struct or class to a group and this option is enabled, then also
+# any nested class or struct is added to the same group. By default this option
+# is disabled and one has to add nested compounds explicitly via \ingroup.
+# The default value is: NO.
+
+GROUP_NESTED_COMPOUNDS = NO
+
+# Set the SUBGROUPING tag to YES to allow class member groups of the same type
+# (for instance a group of public functions) to be put as a subgroup of that
+# type (e.g. under the Public Functions section). Set it to NO to prevent
+# subgrouping. Alternatively, this can be done per class using the
+# \nosubgrouping command.
+# The default value is: YES.
+
SUBGROUPING = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions
+# are shown inside the group in which they are included (e.g. using \ingroup)
+# instead of on a separate page (for HTML and Man pages) or section (for LaTeX
+# and RTF).
+#
+# Note that this feature does not work in combination with
+# SEPARATE_MEMBER_PAGES.
+# The default value is: NO.
+
+INLINE_GROUPED_CLASSES = NO
+
+# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions
+# with only public data fields or simple typedef fields will be shown inline in
+# the documentation of the scope in which they are defined (i.e. file,
+# namespace, or group documentation), provided this scope is documented. If set
+# to NO, structs, classes, and unions are shown on a separate page (for HTML and
+# Man pages) or section (for LaTeX and RTF).
+# The default value is: NO.
+
+INLINE_SIMPLE_STRUCTS = NO
+
+# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or
+# enum is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically be
+# useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+# The default value is: NO.
+
TYPEDEF_HIDES_STRUCT = NO
+
+# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This
+# cache is used to resolve symbols given their name and scope. Since this can be
+# an expensive process and often the same symbol appears multiple times in the
+# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small
+# doxygen will become slower. If the cache is too large, memory is wasted. The
+# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range
+# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536
+# symbols. At the end of a run doxygen will report the cache usage and suggest
+# the optimal cache size from a speed point of view.
+# Minimum value: 0, maximum value: 9, default value: 0.
+
+LOOKUP_CACHE_SIZE = 0
+
+# The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use
+# during processing. When set to 0 doxygen will based this on the number of
+# cores available in the system. You can set it explicitly to a value larger
+# than 0 to get more control over the balance between CPU load and processing
+# speed. At this moment only the input processing can be done using multiple
+# threads. Since this is still an experimental feature the default is set to 1,
+# which effectively disables parallel processing. Please report any issues you
+# encounter. Generating dot graphs in parallel is controlled by the
+# DOT_NUM_THREADS setting.
+# Minimum value: 0, maximum value: 32, default value: 1.
+
+NUM_PROC_THREADS = 1
+
#---------------------------------------------------------------------------
# Build related configuration options
#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in
+# documentation are documented, even if no documentation was available. Private
+# class members and static file members will be hidden unless the
+# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES.
+# Note: This will also disable the warnings about undocumented members that are
+# normally produced when WARNINGS is set to YES.
+# The default value is: NO.
+
EXTRACT_ALL = YES
+
+# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
+# be included in the documentation.
+# The default value is: NO.
+
EXTRACT_PRIVATE = NO
+
+# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual
+# methods of a class will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PRIV_VIRTUAL = NO
+
+# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
+# scope will be included in the documentation.
+# The default value is: NO.
+
+EXTRACT_PACKAGE = NO
+
+# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be
+# included in the documentation.
+# The default value is: NO.
+
EXTRACT_STATIC = YES
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined
+# locally in source files will be included in the documentation. If set to NO,
+# only classes defined in header files are included. Does not have any effect
+# for Java sources.
+# The default value is: YES.
+
EXTRACT_LOCAL_CLASSES = NO
+
+# This flag is only useful for Objective-C code. If set to YES, local methods,
+# which are defined in the implementation section but not in the interface are
+# included in the documentation. If set to NO, only methods in the interface are
+# included.
+# The default value is: NO.
+
EXTRACT_LOCAL_METHODS = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base name of
+# the file that contains the anonymous namespace. By default anonymous namespace
+# are hidden.
+# The default value is: NO.
+
EXTRACT_ANON_NSPACES = YES
+
+# If this flag is set to YES, the name of an unnamed parameter in a declaration
+# will be determined by the corresponding definition. By default unnamed
+# parameters remain unnamed in the output.
+# The default value is: YES.
+
+RESOLVE_UNNAMED_PARAMS = YES
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all
+# undocumented members inside documented classes or files. If set to NO these
+# members will be included in the various overviews, but no documentation
+# section is generated. This option has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
HIDE_UNDOC_MEMBERS = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy. If set
+# to NO, these classes will be included in the various overviews. This option
+# has no effect if EXTRACT_ALL is enabled.
+# The default value is: NO.
+
HIDE_UNDOC_CLASSES = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend
+# declarations. If set to NO, these declarations will be included in the
+# documentation.
+# The default value is: NO.
+
HIDE_FRIEND_COMPOUNDS = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any
+# documentation blocks found inside the body of a function. If set to NO, these
+# blocks will be appended to the function's detailed documentation block.
+# The default value is: NO.
+
HIDE_IN_BODY_DOCS = NO
+
+# The INTERNAL_DOCS tag determines if documentation that is typed after a
+# \internal command is included. If the tag is set to NO then the documentation
+# will be excluded. Set it to YES to include the internal documentation.
+# The default value is: NO.
+
INTERNAL_DOCS = YES
+
+# With the correct setting of option CASE_SENSE_NAMES doxygen will better be
+# able to match the capabilities of the underlying filesystem. In case the
+# filesystem is case sensitive (i.e. it supports files in the same directory
+# whose names only differ in casing), the option must be set to YES to properly
+# deal with such files in case they appear in the input. For filesystems that
+# are not case sensitive the option should be set to NO to properly deal with
+# output files written for symbols that only differ in casing, such as for two
+# classes, one named CLASS and the other named Class, and to also support
+# references to files without having to specify the exact matching casing. On
+# Windows (including Cygwin) and MacOS, users should typically set this option
+# to NO, whereas on Linux or other Unix flavors it should typically be set to
+# YES.
+# The default value is: system dependent.
+
CASE_SENSE_NAMES = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with
+# their full class and namespace scopes in the documentation. If set to YES, the
+# scope will be hidden.
+# The default value is: NO.
+
HIDE_SCOPE_NAMES = NO
+
+# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will
+# append additional text to a page's title, such as Class Reference. If set to
+# YES the compound reference will be hidden.
+# The default value is: NO.
+
+HIDE_COMPOUND_REFERENCE= NO
+
+# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class
+# will show which file needs to be included to use the class.
+# The default value is: YES.
+
+# SHOW_HEADERFILE = YES
+
+# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of
+# the files that are included by a file in the documentation of that file.
+# The default value is: YES.
+
SHOW_INCLUDE_FILES = YES
+
+# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each
+# grouped member an include statement to the documentation, telling the reader
+# which file to include in order to use the member.
+# The default value is: NO.
+
+SHOW_GROUPED_MEMB_INC = NO
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include
+# files with double quotes in the documentation rather than with sharp brackets.
+# The default value is: NO.
+
+FORCE_LOCAL_INCLUDES = NO
+
+# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the
+# documentation for inline members.
+# The default value is: YES.
+
INLINE_INFO = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the
+# (detailed) documentation of file and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order.
+# The default value is: YES.
+
SORT_MEMBER_DOCS = NO
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief
+# descriptions of file, namespace and class members alphabetically by member
+# name. If set to NO, the members will appear in declaration order. Note that
+# this will also influence the order of the classes in the class list.
+# The default value is: NO.
+
SORT_BRIEF_DOCS = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the
+# (brief and detailed) documentation of class members so that constructors and
+# destructors are listed first. If set to NO the constructors will appear in the
+# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS.
+# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief
+# member documentation.
+# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting
+# detailed member documentation.
+# The default value is: NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy
+# of group names into alphabetical order. If set to NO the group names will
+# appear in their defined order.
+# The default value is: NO.
+
SORT_GROUP_NAMES = YES
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by
+# fully-qualified names, including namespaces. If set to NO, the class list will
+# be sorted only by class name, not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the alphabetical
+# list.
+# The default value is: NO.
+
SORT_BY_SCOPE_NAME = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper
+# type resolution of all parameters of a function it will reject a match between
+# the prototype and the implementation of a member function even if there is
+# only one candidate or it is obvious which candidate to choose by doing a
+# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still
+# accept a match between prototype and implementation in such cases.
+# The default value is: NO.
+
+STRICT_PROTO_MATCHING = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo
+# list. This list is created by putting \todo commands in the documentation.
+# The default value is: YES.
+
GENERATE_TODOLIST = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test
+# list. This list is created by putting \test commands in the documentation.
+# The default value is: YES.
+
GENERATE_TESTLIST = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug
+# list. This list is created by putting \bug commands in the documentation.
+# The default value is: YES.
+
GENERATE_BUGLIST = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO)
+# the deprecated list. This list is created by putting \deprecated commands in
+# the documentation.
+# The default value is: YES.
+
GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional documentation
+# sections, marked by \if <section_label> ... \endif and \cond <section_label>
+# ... \endcond blocks.
+
ENABLED_SECTIONS =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the
+# initial value of a variable or macro / define can have for it to appear in the
+# documentation. If the initializer consists of more lines than specified here
+# it will be hidden. Use a value of 0 to hide initializers completely. The
+# appearance of the value of individual variables and macros / defines can be
+# controlled using \showinitializer or \hideinitializer command in the
+# documentation regardless of this setting.
+# Minimum value: 0, maximum value: 10000, default value: 30.
+
MAX_INITIALIZER_LINES = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at
+# the bottom of the documentation of classes and structs. If set to YES, the
+# list will mention the files that were used to generate the documentation.
+# The default value is: YES.
+
SHOW_USED_FILES = YES
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This
+# will remove the Files entry from the Quick Index and from the Folder Tree View
+# (if specified).
+# The default value is: YES.
+
SHOW_FILES = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces
+# page. This will remove the Namespaces entry from the Quick Index and from the
+# Folder Tree View (if specified).
+# The default value is: YES.
+
SHOW_NAMESPACES = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command command input-file, where command is the value of the
+# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided
+# by doxygen. Whatever the program writes to standard output is used as the file
+# version. For an example see the documentation.
+
FILE_VERSION_FILTER =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. To create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option. You can
+# optionally specify a file name after the option, if omitted DoxygenLayout.xml
+# will be used as the name of the layout file. See also section "Changing the
+# layout of pages" for information.
+#
+# Note that if you run doxygen from a directory containing a file called
+# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE
+# tag is left empty.
+
+LAYOUT_FILE =
+
+# The CITE_BIB_FILES tag can be used to specify one or more bib files containing
+# the reference definitions. This must be a list of .bib files. The .bib
+# extension is automatically appended if omitted. This requires the bibtex tool
+# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info.
+# For LaTeX the style of the bibliography can be controlled using
+# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the
+# search path. See also \cite for info how to create references.
+
+CITE_BIB_FILES =
+
#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
+# Configuration options related to warning and progress messages
#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated to
+# standard output by doxygen. If QUIET is set to YES this implies that the
+# messages are off.
+# The default value is: NO.
+
QUIET = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES
+# this implies that the warnings are on.
+#
+# Tip: Turn warnings on while writing the documentation.
+# The default value is: YES.
+
WARNINGS = YES
+
+# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate
+# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag
+# will automatically be disabled.
+# The default value is: YES.
+
WARN_IF_UNDOCUMENTED = YES
+
+# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as documenting some parameters in
+# a documented function twice, or documenting parameters that don't exist or
+# using markup commands wrongly.
+# The default value is: YES.
+
WARN_IF_DOC_ERROR = YES
+
+# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete
+# function parameter documentation. If set to NO, doxygen will accept that some
+# parameters have no documentation without warning.
+# The default value is: YES.
+
+# WARN_IF_INCOMPLETE_DOC = YES
+
+# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that
+# are documented, but have no documentation for their parameters or return
+# value. If set to NO, doxygen will only warn about wrong parameter
+# documentation, but not about the absence of documentation. If EXTRACT_ALL is
+# set to YES then this flag will automatically be disabled. See also
+# WARN_IF_INCOMPLETE_DOC
+# The default value is: NO.
+
WARN_NO_PARAMDOC = YES
-WARN_FORMAT = "$file:$line: $text"
+
+# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when
+# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS
+# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but
+# at the end of the doxygen process doxygen will return with a non-zero status.
+# Possible values are: NO, YES and FAIL_ON_WARNINGS.
+# The default value is: NO.
+
+WARN_AS_ERROR = FAIL_ON_WARNINGS
+
+# The WARN_FORMAT tag determines the format of the warning messages that doxygen
+# can produce. The string should contain the $file, $line, and $text tags, which
+# will be replaced by the file and line number from which the warning originated
+# and the warning text. Optionally the format may contain $version, which will
+# be replaced by the version of the file (if it could be obtained via
+# FILE_VERSION_FILTER)
+# See also: WARN_LINE_FORMAT
+# The default value is: $file:$line: $text.
+
+# WARN_FORMAT = "$file:$line: $text"
+
+# In the $text part of the WARN_FORMAT command it is possible that a reference
+# to a more specific place is given. To make it easier to jump to this place
+# (outside of doxygen) the user can define a custom "cut" / "paste" string.
+# Example:
+# WARN_LINE_FORMAT = "'vi $file +$line'"
+# See also: WARN_FORMAT
+# The default value is: at line $line of file $file.
+
+WARN_LINE_FORMAT = "at line $line of file $file"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning and error
+# messages should be written. If left blank the output is written to standard
+# error (stderr). In case the file specified cannot be opened for writing the
+# warning and error messages are written to standard error. When as file - is
+# specified the warning and error messages are written to standard output
+# (stdout).
+
WARN_LOGFILE =
+
#---------------------------------------------------------------------------
-# configuration options related to the input files
+# Configuration options related to the input files
#---------------------------------------------------------------------------
+
+# The INPUT tag is used to specify the files and/or directories that contain
+# documented source files. You may enter file names like myfile.cpp or
+# directories like /usr/src/myproject. Separate the files or directories with
+# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
+# Note: If this tag is empty the current directory is searched.
+
INPUT = ../../src
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
+# libiconv (or the iconv built into libc) for the transcoding. See the libiconv
+# documentation (see:
+# https://www.gnu.org/software/libiconv/) for the list of possible encodings.
+# The default value is: UTF-8.
+
INPUT_ENCODING = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and
+# *.h) to filter out the source-files in the directories.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# read by doxygen.
+#
+# Note the list of default checked file patterns might differ from the list of
+# default file extension mappings.
+#
+# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp,
+# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h,
+# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml,
+# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C
+# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd,
+# *.vhdl, *.ucf, *.qsf and *.ice.
+
FILE_PATTERNS = *.c \
- *.cc \
- *.cxx \
- *.cpp \
- *.c++ \
- *.d \
- *.java \
- *.ii \
- *.ixx \
- *.ipp \
- *.i++ \
- *.inl \
- *.h \
- *.hh \
- *.hxx \
- *.hpp \
- *.h++ \
- *.idl \
- *.odl \
- *.cs \
- *.php \
- *.php3 \
- *.inc \
- *.m \
- *.mm \
- *.dox \
- *.py \
- *.f90 \
- *.f \
- *.vhd \
- *.vhdl \
- *.C \
- *.CC \
- *.C++ \
- *.II \
- *.I++ \
- *.H \
- *.HH \
- *.H++ \
- *.CS \
- *.PHP \
- *.PHP3 \
- *.M \
- *.MM \
- *.PY \
- *.F90 \
- *.F \
- *.VHD \
- *.VHDL
+ *.h
+
+# The RECURSIVE tag can be used to specify whether or not subdirectories should
+# be searched for input files as well.
+# The default value is: NO.
+
RECURSIVE = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should be
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+#
+# Note that relative paths are relative to the directory from which doxygen is
+# run.
+
EXCLUDE =
+
+# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+# The default value is: NO.
+
EXCLUDE_SYMLINKS = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories.
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories for example use the pattern */test/*
+
EXCLUDE_PATTERNS = */test_* \
- */.svn/* \
*/.git/* \
- */perf_* .* \
+ */perf_* \
.* \
- */gnu-taler-error-codes/*
+ .* \
+ */gnu-taler-error-codes/* \
+ */src/templating/mustach*
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# ANamespace::AClass, ANamespace::*Test
+#
+# Note that the wildcards are matched against the file with absolute path, so to
+# exclude all test directories use the pattern */test/*
+
EXCLUDE_SYMBOLS =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or directories
+# that contain example code fragments that are included (see the \include
+# command).
+
EXAMPLE_PATH =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
+# *.h) to filter out the source-files in the directories. If left blank all
+# files are included.
+
EXAMPLE_PATTERNS = *
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude commands
+# irrespective of the value of the RECURSIVE tag.
+# The default value is: NO.
+
EXAMPLE_RECURSIVE = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or directories
+# that contain images that are to be included in the documentation (see the
+# \image command).
+
IMAGE_PATH =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command:
+#
+# <filter> <input-file>
+#
+# where <filter> is the value of the INPUT_FILTER tag, and <input-file> is the
+# name of an input file. Doxygen will then use the output that the filter
+# program writes to standard output. If FILTER_PATTERNS is specified, this tag
+# will be ignored.
+#
+# Note that the filter must not add or remove lines; it is applied before the
+# code is scanned, but not when the output code is generated. If lines are added
+# or removed, the anchors will not be placed correctly.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
INPUT_FILTER =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis. Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match. The filters are a list of the form: pattern=filter
+# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how
+# filters are used. If the FILTER_PATTERNS tag is empty or if none of the
+# patterns match the file name, INPUT_FILTER is applied.
+#
+# Note that for custom extensions or not directly supported extensions you also
+# need to set EXTENSION_MAPPING for the extension otherwise the files are not
+# properly processed by doxygen.
+
FILTER_PATTERNS =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will also be used to filter the input files that are used for
+# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES).
+# The default value is: NO.
+
FILTER_SOURCE_FILES = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and
+# it is also possible to disable source filtering for a specific pattern using
+# *.ext= (so without naming a filter).
+# This tag requires that the tag FILTER_SOURCE_FILES is set to YES.
+
+FILTER_SOURCE_PATTERNS =
+
+# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that
+# is part of the input, its contents will be placed on the main page
+# (index.html). This can be useful if you have a project on for instance GitHub
+# and want to reuse the introduction page also for the doxygen output.
+
+USE_MDFILE_AS_MAINPAGE =
+
#---------------------------------------------------------------------------
-# configuration options related to source browsing
+# Configuration options related to source browsing
#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will be
+# generated. Documented entities will be cross-referenced with these sources.
+#
+# Note: To get rid of all source code in the generated output, make sure that
+# also VERBATIM_HEADERS is set to NO.
+# The default value is: NO.
+
SOURCE_BROWSER = YES
+
+# Setting the INLINE_SOURCES tag to YES will include the body of functions,
+# classes and enums directly into the documentation.
+# The default value is: NO.
+
INLINE_SOURCES = YES
+
+# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any
+# special comment blocks from generated source code fragments. Normal C, C++ and
+# Fortran comments will always remain visible.
+# The default value is: YES.
+
STRIP_CODE_COMMENTS = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES then for each documented
+# entity all documented functions referencing it will be listed.
+# The default value is: NO.
+
REFERENCED_BY_RELATION = YES
+
+# If the REFERENCES_RELATION tag is set to YES then for each documented function
+# all documented entities called/used by that function will be listed.
+# The default value is: NO.
+
REFERENCES_RELATION = YES
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set
+# to YES then the hyperlinks from functions in REFERENCES_RELATION and
+# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will
+# link to the documentation.
+# The default value is: YES.
+
REFERENCES_LINK_SOURCE = YES
+
+# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the
+# source code will show a tooltip with additional information such as prototype,
+# brief description and links to the definition and documentation. Since this
+# will make the HTML file larger and loading of large files a bit slower, you
+# can opt to disable this feature.
+# The default value is: YES.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
+SOURCE_TOOLTIPS = YES
+
+# If the USE_HTAGS tag is set to YES then the references to source code will
+# point to the HTML generated by the htags(1) tool instead of doxygen built-in
+# source browser. The htags tool is part of GNU's global source tagging system
+# (see https://www.gnu.org/software/global/global.html). You will need version
+# 4.8.6 or higher.
+#
+# To use it do the following:
+# - Install the latest version of global
+# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file
+# - Make sure the INPUT points to the root of the source tree
+# - Run doxygen as normal
+#
+# Doxygen will invoke htags (and that will in turn invoke gtags), so these
+# tools must be available from the command line (i.e. in the search path).
+#
+# The result: instead of the source browser generated by doxygen, the links to
+# source code will now point to the output of htags.
+# The default value is: NO.
+# This tag requires that the tag SOURCE_BROWSER is set to YES.
+
USE_HTAGS = NO
+
+# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a
+# verbatim copy of the header file for each class for which an include is
+# specified. Set to NO to disable this.
+# See also: Section \class.
+# The default value is: YES.
+
VERBATIM_HEADERS = YES
+
+# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the
+# clang parser (see:
+# http://clang.llvm.org/) for more accurate parsing at the cost of reduced
+# performance. This can be particularly helpful with template rich C++ code for
+# which doxygen's built-in parser lacks the necessary type information.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse_libclang=ON option for CMake.
+# The default value is: NO.
+
+CLANG_ASSISTED_PARSING = NO
+
+# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS
+# tag is set to YES then doxygen will add the directory of each input to the
+# include path.
+# The default value is: YES.
+# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
+
+CLANG_ADD_INC_PATHS = YES
+
+# If clang assisted parsing is enabled you can provide the compiler with command
+# line options that you would normally use when invoking the compiler. Note that
+# the include paths will already be set by doxygen for the files and directories
+# specified with INPUT and INCLUDE_PATH.
+# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES.
+
+CLANG_OPTIONS =
+
+# If clang assisted parsing is enabled you can provide the clang parser with the
+# path to the directory containing a file called compile_commands.json. This
+# file is the compilation database (see:
+# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the
+# options used when the source files were built. This is equivalent to
+# specifying the -p option to a clang tool, such as clang-check. These options
+# will then be passed to the parser. Any options specified with CLANG_OPTIONS
+# will be added as well.
+# Note: The availability of this option depends on whether or not doxygen was
+# generated with the -Duse_libclang=ON option for CMake.
+
+CLANG_DATABASE_PATH =
+
#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
+# Configuration options related to the alphabetical class index
#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all
+# compounds will be generated. Enable this if the project contains a lot of
+# classes, structs, unions or interfaces.
+# The default value is: YES.
+
ALPHABETICAL_INDEX = YES
+
+# In case all classes in a project start with a common prefix, all classes will
+# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag
+# can be used to specify a prefix (or a list of prefixes) that should be ignored
+# while generating the index headers.
+# This tag requires that the tag ALPHABETICAL_INDEX is set to YES.
+
IGNORE_PREFIX = TALER_
+
#---------------------------------------------------------------------------
-# configuration options related to the HTML output
+# Configuration options related to the HTML output
#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output
+# The default value is: YES.
+
GENERATE_HTML = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
HTML_OUTPUT = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each
+# generated HTML page (for example: .htm, .php, .asp).
+# The default value is: .html.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
HTML_FILE_EXTENSION = .html
+
+# The HTML_HEADER tag can be used to specify a user-defined HTML header file for
+# each generated HTML page. If the tag is left blank doxygen will generate a
+# standard header.
+#
+# To get valid HTML the header file that includes any scripts and style sheets
+# that doxygen needs, which is dependent on the configuration options used (e.g.
+# the setting GENERATE_TREEVIEW). It is highly recommended to start with a
+# default header using
+# doxygen -w html new_header.html new_footer.html new_stylesheet.css
+# YourConfigFile
+# and then modify the file new_header.html. See also section "Doxygen usage"
+# for information on how to generate the default header that doxygen normally
+# uses.
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. For a description
+# of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
HTML_HEADER =
+
+# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each
+# generated HTML page. If the tag is left blank doxygen will generate a standard
+# footer. See HTML_HEADER for more information on how to generate a default
+# footer and what special commands can be used inside the footer. See also
+# section "Doxygen usage" for information on how to generate the default footer
+# that doxygen normally uses.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
HTML_FOOTER =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style
+# sheet that is used by each HTML page. It can be used to fine-tune the look of
+# the HTML output. If left blank doxygen will generate a default style sheet.
+# See also section "Doxygen usage" for information on how to generate the style
+# sheet that doxygen normally uses.
+# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as
+# it is more robust and this tag (HTML_STYLESHEET) will in the future become
+# obsolete.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
HTML_STYLESHEET =
-GENERATE_HTMLHELP = NO
+
+# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# cascading style sheets that are included after the standard style sheets
+# created by doxygen. Using this option one can overrule certain style aspects.
+# This is preferred over using HTML_STYLESHEET since it does not replace the
+# standard style sheet and is therefore more robust against future updates.
+# Doxygen will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list). For an example see the documentation.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_STYLESHEET =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that the
+# files will be copied as-is; there are no commands or markers available.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_EXTRA_FILES =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen
+# will adjust the colors in the style sheet and background images according to
+# this color. Hue is specified as an angle on a color-wheel, see
+# https://en.wikipedia.org/wiki/Hue for more information. For instance the value
+# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300
+# purple, and 360 is red again.
+# Minimum value: 0, maximum value: 359, default value: 220.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_HUE = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors
+# in the HTML output. For a value of 0 the output will use gray-scales only. A
+# value of 255 will produce the most vivid colors.
+# Minimum value: 0, maximum value: 255, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_SAT = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the
+# luminance component of the colors in the HTML output. Values below 100
+# gradually make the output lighter, whereas values above 100 make the output
+# darker. The value divided by 100 is the actual gamma applied, so 80 represents
+# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not
+# change the gamma.
+# Minimum value: 40, maximum value: 240, default value: 80.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_COLORSTYLE_GAMMA = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting this
+# to YES can help to show when doxygen was last run and thus if the
+# documentation is up to date.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_TIMESTAMP = NO
+
+# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML
+# documentation will contain a main index with vertical navigation menus that
+# are dynamically created via JavaScript. If disabled, the navigation index will
+# consists of multiple levels of tabs that are statically embedded in every HTML
+# page. Disable this option to support browsers that do not have JavaScript,
+# like the Qt help browser.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_MENUS = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_DYNAMIC_SECTIONS = NO
+
+# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries
+# shown in the various tree structured indices initially; the user can expand
+# and collapse entries dynamically later on. Doxygen will expand the tree to
+# such a level that at most the specified number of entries are visible (unless
+# a fully collapsed tree already exceeds this amount). So setting the number of
+# entries 1 will produce a full collapsed tree by default. 0 is a special value
+# representing an infinite number of entries and will result in a full expanded
+# tree by default.
+# Minimum value: 0, maximum value: 9999, default value: 100.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_INDEX_NUM_ENTRIES = 100
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files will be
+# generated that can be used as input for Apple's Xcode 3 integrated development
+# environment (see:
+# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To
+# create a documentation set, doxygen will generate a Makefile in the HTML
+# output directory. Running make will produce the docset in that directory and
+# running make install will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at
+# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy
+# genXcode/_index.html for more information.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
GENERATE_DOCSET = NO
+
+# This tag determines the name of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# The default value is: Doxygen generated docs.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
DOCSET_FEEDNAME = "GNU Taler Source Documentation"
-DOCSET_BUNDLE_ID = net.taler
-HTML_DYNAMIC_SECTIONS = NO
+
+# This tag determines the URL of the docset feed. A documentation feed provides
+# an umbrella under which multiple documentation sets from a single provider
+# (such as a company or product suite) can be grouped.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+# DOCSET_FEEDURL =
+
+# This tag specifies a string that should uniquely identify the documentation
+# set bundle. This should be a reverse domain-name style string, e.g.
+# com.mycompany.MyDocSet. Doxygen will append .docset to the name.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_BUNDLE_ID = net.taler.exchange
+
+# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+# The default value is: org.doxygen.Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_ID = net.taler
+
+# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher.
+# The default value is: Publisher.
+# This tag requires that the tag GENERATE_DOCSET is set to YES.
+
+DOCSET_PUBLISHER_NAME = "Taler Systems SA"
+
+# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three
+# additional HTML index files: index.hhp, index.hhc, and index.hhk. The
+# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop
+# on Windows. In the beginning of 2021 Microsoft took the original page, with
+# a.o. the download links, offline the HTML help workshop was already many years
+# in maintenance mode). You can download the HTML help workshop from the web
+# archives at Installation executable (see:
+# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo
+# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe).
+#
+# The HTML Help Workshop contains a compiler that can convert all HTML output
+# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML
+# files are now used as the Windows 98 help format, and will replace the old
+# Windows help format (.hlp) on all Windows platforms in the future. Compressed
+# HTML files also contain an index, a table of contents, and you can search for
+# words in the documentation. The HTML workshop also contains a viewer for
+# compressed HTML files.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_HTMLHELP = NO
+
+# The CHM_FILE tag can be used to specify the file name of the resulting .chm
+# file. You can add a path in front of the file if the result should not be
+# written to the html output directory.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
CHM_FILE =
+
+# The HHC_LOCATION tag can be used to specify the location (absolute path
+# including file name) of the HTML help compiler (hhc.exe). If non-empty,
+# doxygen will try to run the HTML help compiler on the generated index.hhp.
+# The file has to be specified with full path.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
HHC_LOCATION =
+
+# The GENERATE_CHI flag controls if a separate .chi index file is generated
+# (YES) or that it should be included in the main .chm file (NO).
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
GENERATE_CHI = NO
+
+# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc)
+# and project file content.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
CHM_INDEX_ENCODING =
+
+# The BINARY_TOC flag controls whether a binary table of contents is generated
+# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it
+# enables the Previous and Next buttons.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
BINARY_TOC = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members to
+# the table of contents of the HTML help documentation and to the tree view.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTMLHELP is set to YES.
+
TOC_EXPAND = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that
+# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help
+# (.qch) of the generated HTML documentation.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_QHP = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify
+# the file name of the resulting .qch file. The path specified is relative to
+# the HTML output folder.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QCH_FILE =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help
+# Project output. For more information please see Qt Help Project / Namespace
+# (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace).
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_NAMESPACE = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt
+# Help Project output. For more information please see Qt Help Project / Virtual
+# Folders (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders).
+# The default value is: doc.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_VIRTUAL_FOLDER = doc
+
+# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom
+# filter to add. For more information please see Qt Help Project / Custom
+# Filters (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_NAME =
+
+# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see Qt Help Project / Custom
+# Filters (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_CUST_FILTER_ATTRS =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's filter section matches. Qt Help Project / Filter Attributes (see:
+# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes).
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHP_SECT_FILTER_ATTRS =
+
+# The QHG_LOCATION tag can be used to specify the location (absolute path
+# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to
+# run qhelpgenerator on the generated .qhp file.
+# This tag requires that the tag GENERATE_QHP is set to YES.
+
+QHG_LOCATION =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be
+# generated, together with the HTML files, they form an Eclipse help plugin. To
+# install this plugin and make it available under the help contents menu in
+# Eclipse, the contents of the directory containing the HTML and XML files needs
+# to be copied into the plugins directory of eclipse. The name of the directory
+# within the plugins directory should be the same as the ECLIPSE_DOC_ID value.
+# After copying Eclipse needs to be restarted before the help appears.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+GENERATE_ECLIPSEHELP = NO
+
+# A unique identifier for the Eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have this
+# name. Each documentation set should have its own identifier.
+# The default value is: org.doxygen.Project.
+# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES.
+
+ECLIPSE_DOC_ID = org.doxygen.Project
+
+# If you want full control over the layout of the generated HTML pages it might
+# be necessary to disable the index and replace it with your own. The
+# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top
+# of each HTML page. A value of NO enables the index and the value YES disables
+# it. Since the tabs in the index contain the same information as the navigation
+# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
DISABLE_INDEX = NO
-ENUM_VALUES_PER_LINE = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information. If the tag
+# value is set to YES, a side panel will be generated containing a tree-like
+# index structure (just like the one that is generated for HTML Help). For this
+# to work a browser that supports JavaScript, DHTML, CSS and frames is required
+# (i.e. any modern browser). Windows users are probably better off using the
+# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can
+# further fine tune the look of the index (see "Fine-tuning the output"). As an
+# example, the default style sheet generated by doxygen has an example that
+# shows how to put an image at the root of the tree instead of the PROJECT_NAME.
+# Since the tree basically has the same information as the tab index, you could
+# consider setting DISABLE_INDEX to YES when enabling this option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
GENERATE_TREEVIEW = NONE
+
+# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the
+# FULL_SIDEBAR option determines if the side bar is limited to only the treeview
+# area (value NO) or if it should extend to the full height of the window (value
+# YES). Setting this to YES gives a layout similar to
+# https://docs.readthedocs.io with more room for contents, but less room for the
+# project logo, title, and description. If either GENERATE_TREEVIEW or
+# DISABLE_INDEX is set to NO, this option has no effect.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+# FULL_SIDEBAR = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that
+# doxygen will group on one line in the generated HTML documentation.
+#
+# Note that a value of 0 will completely suppress the enum values from appearing
+# in the overview section.
+# Minimum value: 0, maximum value: 20, default value: 4.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+ENUM_VALUES_PER_LINE = 4
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used
+# to set the initial width (in pixels) of the frame in which the tree is shown.
+# Minimum value: 0, maximum value: 1500, default value: 250.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
TREEVIEW_WIDTH = 250
+
+# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to
+# external symbols imported via tag files in a separate window.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+EXT_LINKS_IN_WINDOW = NO
+
+# If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email
+# addresses.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+# OBFUSCATE_EMAILS = YES
+
+# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg
+# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see
+# https://inkscape.org) to generate formulas as SVG images instead of PNGs for
+# the HTML output. These images will generally look nicer at scaled resolutions.
+# Possible values are: png (the default) and svg (looks nicer but requires the
+# pdf2svg or inkscape tool).
+# The default value is: png.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+HTML_FORMULA_FORMAT = png
+
+# Use this tag to change the font size of LaTeX formulas included as images in
+# the HTML documentation. When you change the font size after a successful
+# doxygen run you need to manually remove any form_*.png images from the HTML
+# output directory to force them to be regenerated.
+# Minimum value: 8, maximum value: 50, default value: 10.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
FORMULA_FONTSIZE = 10
+
+# Use the FORMULA_TRANSPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are not
+# supported properly for IE 6.0, but are supported on all modern browsers.
+#
+# Note that when changing this option you need to delete any form_*.png files in
+# the HTML output directory before the changes have effect.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+FORMULA_TRANSPARENT = YES
+
+# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands
+# to create new LaTeX commands to be used in formulas as building blocks. See
+# the section "Including formulas" for details.
+
+FORMULA_MACROFILE =
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
+# https://www.mathjax.org) which uses client side JavaScript for the rendering
+# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX
+# installed or if you want to formulas look prettier in the HTML output. When
+# enabled you may also need to install MathJax separately and configure the path
+# to it using the MATHJAX_RELPATH option.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+# USE_MATHJAX = NO
+
+# With MATHJAX_VERSION it is possible to specify the MathJax version to be used.
+# Note that the different versions of MathJax have different requirements with
+# regards to the different settings, so it is possible that also other MathJax
+# settings have to be changed when switching between the different MathJax
+# versions.
+# Possible values are: MathJax_2 and MathJax_3.
+# The default value is: MathJax_2.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_VERSION = MathJax_2
+
+# When MathJax is enabled you can set the default output format to be used for
+# the MathJax output. For more details about the output format see MathJax
+# version 2 (see:
+# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3
+# (see:
+# http://docs.mathjax.org/en/latest/web/components/output.html).
+# Possible values are: HTML-CSS (which is slower, but has the best
+# compatibility. This is the name for Mathjax version 2, for MathJax version 3
+# this will be translated into chtml), NativeMML (i.e. MathML. Only supported
+# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This
+# is the name for Mathjax version 3, for MathJax version 2 this will be
+# translated into HTML-CSS) and SVG.
+# The default value is: HTML-CSS.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_FORMAT = HTML-CSS
+
+# When MathJax is enabled you need to specify the location relative to the HTML
+# output directory using the MATHJAX_RELPATH option. The destination directory
+# should contain the MathJax.js script. For instance, if the mathjax directory
+# is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax
+# Content Delivery Network so you can quickly see the result without installing
+# MathJax. However, it is strongly recommended to install a local copy of
+# MathJax from https://www.mathjax.org before deployment. The default value is:
+# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2
+# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_RELPATH =
+
+# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax
+# extension names that should be enabled during MathJax rendering. For example
+# for MathJax version 2 (see
+# https://docs.mathjax.org/en/v2.7-latest/tex.html#tex-and-latex-extensions):
+# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols
+# For example for MathJax version 3 (see
+# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html):
+# MATHJAX_EXTENSIONS = ams
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_EXTENSIONS =
+
+# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces
+# of code that will be used on startup of the MathJax code. See the MathJax site
+# (see:
+# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an
+# example see the documentation.
+# This tag requires that the tag USE_MATHJAX is set to YES.
+
+MATHJAX_CODEFILE =
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box for
+# the HTML output. The underlying search engine uses javascript and DHTML and
+# should work on any modern browser. Note that when using HTML help
+# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET)
+# there is already a search function so this one should typically be disabled.
+# For large projects the javascript based search engine can be slow, then
+# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to
+# search using the keyboard; to jump to the search box use <access key> + S
+# (what the <access key> is depends on the OS and browser, but it is typically
+# <CTRL>, <ALT>/<option>, or both). Inside the search box use the <cursor down
+# key> to jump into the search results window, the results can be navigated
+# using the <cursor keys>. Press <Enter> to select an item or <escape> to cancel
+# the search. The filter options can be selected when the cursor is inside the
+# search box by pressing <Shift>+<cursor down>. Also here use the <cursor keys>
+# to select a filter and <Enter> or <escape> to activate or cancel the filter
+# option.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_HTML is set to YES.
+
+SEARCHENGINE = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a web server instead of a web client using JavaScript. There
+# are two flavors of web server based searching depending on the EXTERNAL_SEARCH
+# setting. When disabled, doxygen will generate a PHP script for searching and
+# an index file used by the script. When EXTERNAL_SEARCH is enabled the indexing
+# and searching needs to be provided by external tools. See the section
+# "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SERVER_BASED_SEARCH = NO
+
+# When EXTERNAL_SEARCH tag is enabled doxygen will no longer generate the PHP
+# script for searching. Instead the search results are written to an XML file
+# which needs to be processed by an external indexer. Doxygen will invoke an
+# external search engine pointed to by the SEARCHENGINE_URL option to obtain the
+# search results.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see:
+# https://xapian.org/).
+#
+# See the section "External Indexing and Searching" for details.
+# The default value is: NO.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH = NO
+
+# The SEARCHENGINE_URL should point to a search engine hosted by a web server
+# which will return the search results when EXTERNAL_SEARCH is enabled.
+#
+# Doxygen ships with an example indexer (doxyindexer) and search engine
+# (doxysearch.cgi) which are based on the open source search engine library
+# Xapian (see:
+# https://xapian.org/). See the section "External Indexing and Searching" for
+# details.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHENGINE_URL =
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed
+# search data is written to a file for indexing by an external tool. With the
+# SEARCHDATA_FILE tag the name of this file can be specified.
+# The default file is: searchdata.xml.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+SEARCHDATA_FILE = searchdata.xml
+
+# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the
+# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is
+# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple
+# projects and redirect the results back to the right project.
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTERNAL_SEARCH_ID =
+
+# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen
+# projects other than the one defined by this configuration file, but that are
+# all added to the same external search index. Each project needs to have a
+# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id of
+# to a relative location where the documentation can be found. The format is:
+# EXTRA_SEARCH_MAPPINGS = tagname1=loc1 tagname2=loc2 ...
+# This tag requires that the tag SEARCHENGINE is set to YES.
+
+EXTRA_SEARCH_MAPPINGS =
+
#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
+# Configuration options related to the LaTeX output
#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES, doxygen will generate LaTeX output.
+# The default value is: YES.
+
GENERATE_LATEX = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: latex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
LATEX_OUTPUT = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked.
+#
+# Note that when not enabling USE_PDFLATEX the default is latex when enabling
+# USE_PDFLATEX the default is pdflatex and when in the later case latex is
+# chosen this is overwritten by pdflatex. For specific output languages the
+# default can have been set differently, this depends on the implementation of
+# the output language.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
LATEX_CMD_NAME = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to generate
+# index for LaTeX.
+# Note: This tag is used in the Makefile / make.bat.
+# See also: LATEX_MAKEINDEX_CMD for the part in the generated output file
+# (.tex).
+# The default file is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
MAKEINDEX_CMD_NAME = makeindex
+
+# The LATEX_MAKEINDEX_CMD tag can be used to specify the command name to
+# generate index for LaTeX. In case there is no backslash (\) as first character
+# it will be automatically added in the LaTeX code.
+# Note: This tag is used in the generated output file (.tex).
+# See also: MAKEINDEX_CMD_NAME for the part in the Makefile / make.bat.
+# The default value is: makeindex.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_MAKEINDEX_CMD = makeindex
+
+# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
COMPACT_LATEX = YES
+
+# The PAPER_TYPE tag can be used to set the paper type that is used by the
+# printer.
+# Possible values are: a4 (210 x 297 mm), letter (8.5 x 11 inches), legal (8.5 x
+# 14 inches) and executive (7.25 x 10.5 inches).
+# The default value is: a4.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
PAPER_TYPE = a4
+
+# The EXTRA_PACKAGES tag can be used to specify one or more LaTeX package names
+# that should be included in the LaTeX output. The package can be specified just
+# by its name or with the correct syntax as to be used with the LaTeX
+# \usepackage command. To get the times font for instance you can specify :
+# EXTRA_PACKAGES=times or EXTRA_PACKAGES={times}
+# To use the option intlimits with the amsmath package you can specify:
+# EXTRA_PACKAGES=[intlimits]{amsmath}
+# If left blank no extra packages will be included.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
EXTRA_PACKAGES =
+
+# The LATEX_HEADER tag can be used to specify a user-defined LaTeX header for
+# the generated LaTeX document. The header should contain everything until the
+# first chapter. If it is left blank doxygen will generate a standard header. It
+# is highly recommended to start with a default header using
+# doxygen -w latex new_header.tex new_footer.tex new_stylesheet.sty
+# and then modify the file new_header.tex. See also section "Doxygen usage" for
+# information on how to generate the default header that doxygen normally uses.
+#
+# Note: Only use a user-defined header if you know what you are doing!
+# Note: The header is subject to change so you typically have to regenerate the
+# default header when upgrading to a newer version of doxygen. The following
+# commands have a special meaning inside the header (and footer): For a
+# description of the possible markers and block names see the documentation.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
LATEX_HEADER =
+
+# The LATEX_FOOTER tag can be used to specify a user-defined LaTeX footer for
+# the generated LaTeX document. The footer should contain everything after the
+# last chapter. If it is left blank doxygen will generate a standard footer. See
+# LATEX_HEADER for more information on how to generate a default footer and what
+# special commands can be used inside the footer. See also section "Doxygen
+# usage" for information on how to generate the default footer that doxygen
+# normally uses. Note: Only use a user-defined footer if you know what you are
+# doing!
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_FOOTER =
+
+# The LATEX_EXTRA_STYLESHEET tag can be used to specify additional user-defined
+# LaTeX style sheets that are included after the standard style sheets created
+# by doxygen. Using this option one can overrule certain style aspects. Doxygen
+# will copy the style sheet files to the output directory.
+# Note: The order of the extra style sheet files is of importance (e.g. the last
+# style sheet in the list overrules the setting of the previous ones in the
+# list).
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_STYLESHEET =
+
+# The LATEX_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the LATEX_OUTPUT output
+# directory. Note that the files will be copied as-is; there are no commands or
+# markers available.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EXTRA_FILES =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated is
+# prepared for conversion to PDF (using ps2pdf or pdflatex). The PDF file will
+# contain links (just like the HTML output) instead of page references. This
+# makes the output suitable for online browsing using a PDF viewer.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
PDF_HYPERLINKS = YES
+
+# If the USE_PDFLATEX tag is set to YES, doxygen will use the engine as
+# specified with LATEX_CMD_NAME to generate the PDF file directly from the LaTeX
+# files. Set this option to YES, to get a higher quality PDF documentation.
+#
+# See also section LATEX_CMD_NAME for selecting the engine.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
USE_PDFLATEX = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \batchmode
+# command to the generated LaTeX files. This will instruct LaTeX to keep running
+# if errors occur, instead of asking the user for help.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
LATEX_BATCHMODE = NO
+
+# If the LATEX_HIDE_INDICES tag is set to YES then doxygen will not include the
+# index chapters (such as File Index, Compound Index, etc.) in the output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
LATEX_HIDE_INDICES = NO
+
+# The LATEX_BIB_STYLE tag can be used to specify the style to use for the
+# bibliography, e.g. plainnat, or ieeetr. See
+# https://en.wikipedia.org/wiki/BibTeX and \cite for more info.
+# The default value is: plain.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_BIB_STYLE = plain
+
+# If the LATEX_TIMESTAMP tag is set to YES then the footer of each generated
+# page will contain the date and time when the page was generated. Setting this
+# to NO can help when comparing the output of multiple runs.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_TIMESTAMP = NO
+
+# The LATEX_EMOJI_DIRECTORY tag is used to specify the (relative or absolute)
+# path from which the emoji images will be read. If a relative path is entered,
+# it will be relative to the LATEX_OUTPUT directory. If left blank the
+# LATEX_OUTPUT directory will be used.
+# This tag requires that the tag GENERATE_LATEX is set to YES.
+
+LATEX_EMOJI_DIRECTORY =
+
#---------------------------------------------------------------------------
-# configuration options related to the RTF output
+# Configuration options related to the RTF output
#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES, doxygen will generate RTF output. The
+# RTF output is optimized for Word 97 and may not look too pretty with other RTF
+# readers/editors.
+# The default value is: NO.
+
GENERATE_RTF = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: rtf.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
RTF_OUTPUT = rtf
+
+# If the COMPACT_RTF tag is set to YES, doxygen generates more compact RTF
+# documents. This may be useful for small projects and may help to save some
+# trees in general.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
COMPACT_RTF = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated will
+# contain hyperlink fields. The RTF file will contain links (just like the HTML
+# output) instead of page references. This makes the output suitable for online
+# browsing using Word or some other Word compatible readers that support those
+# fields.
+#
+# Note: WordPad (write) and others do not support links.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
RTF_HYPERLINKS = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# configuration file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+#
+# See also section "Doxygen usage" for information on how to generate the
+# default style sheet that doxygen normally uses.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
RTF_STYLESHEET_FILE =
+
+# Set optional variables used in the generation of an RTF document. Syntax is
+# similar to doxygen's configuration file. A template extensions file can be
+# generated using doxygen -e rtf extensionFile.
+# This tag requires that the tag GENERATE_RTF is set to YES.
+
RTF_EXTENSIONS_FILE =
+
#---------------------------------------------------------------------------
-# configuration options related to the man page output
+# Configuration options related to the man page output
#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES, doxygen will generate man pages for
+# classes and files.
+# The default value is: NO.
+
GENERATE_MAN = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it. A directory man3 will be created inside the directory specified by
+# MAN_OUTPUT.
+# The default directory is: man.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
MAN_OUTPUT = man
+
+# The MAN_EXTENSION tag determines the extension that is added to the generated
+# man pages. In case the manual section does not start with a number, the number
+# 3 is prepended. The dot (.) at the beginning of the MAN_EXTENSION tag is
+# optional.
+# The default value is: .3.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
MAN_EXTENSION = .3
+
+# The MAN_SUBDIR tag determines the name of the directory created within
+# MAN_OUTPUT in which the man pages are placed. If defaults to man followed by
+# MAN_EXTENSION with the initial . removed.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
+MAN_SUBDIR =
+
+# If the MAN_LINKS tag is set to YES and doxygen generates man output, then it
+# will generate one additional man file for each entity documented in the real
+# man page(s). These additional files only source the real man page, but without
+# them the man command would be unable to find the correct page.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_MAN is set to YES.
+
MAN_LINKS = NO
+
#---------------------------------------------------------------------------
-# configuration options related to the XML output
+# Configuration options related to the XML output
#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES, doxygen will generate an XML file that
+# captures the structure of the code including all documentation.
+# The default value is: NO.
+
GENERATE_XML = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put. If a
+# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
+# it.
+# The default directory is: xml.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
XML_OUTPUT = xml
+
+# If the XML_PROGRAMLISTING tag is set to YES, doxygen will dump the program
+# listings (including syntax highlighting and cross-referencing information) to
+# the XML output. Note that enabling this will significantly increase the size
+# of the XML output.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
XML_PROGRAMLISTING = YES
+
+# If the XML_NS_MEMB_FILE_SCOPE tag is set to YES, doxygen will include
+# namespace members in file scope as well, matching the HTML output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_XML is set to YES.
+
+XML_NS_MEMB_FILE_SCOPE = NO
+
#---------------------------------------------------------------------------
-# configuration options for the AutoGen Definitions output
+# Configuration options related to the DOCBOOK output
#---------------------------------------------------------------------------
+
+# If the GENERATE_DOCBOOK tag is set to YES, doxygen will generate Docbook files
+# that can be used to generate PDF.
+# The default value is: NO.
+
+GENERATE_DOCBOOK = NO
+
+# The DOCBOOK_OUTPUT tag is used to specify where the Docbook pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be put in
+# front of it.
+# The default directory is: docbook.
+# This tag requires that the tag GENERATE_DOCBOOK is set to YES.
+
+DOCBOOK_OUTPUT = docbook
+
+#---------------------------------------------------------------------------
+# Configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES, doxygen will generate an
+# AutoGen Definitions (see http://autogen.sourceforge.net/) file that captures
+# the structure of the code including all documentation. Note that this feature
+# is still experimental and incomplete at the moment.
+# The default value is: NO.
+
GENERATE_AUTOGEN_DEF = NO
+
#---------------------------------------------------------------------------
-# configuration options related to the Perl module output
+# Configuration options related to the Perl module output
#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES, doxygen will generate a Perl module
+# file that captures the structure of the code including all documentation.
+#
+# Note that this feature is still experimental and incomplete at the moment.
+# The default value is: NO.
+
GENERATE_PERLMOD = NO
+
+# If the PERLMOD_LATEX tag is set to YES, doxygen will generate the necessary
+# Makefile rules, Perl scripts and LaTeX code to be able to generate PDF and DVI
+# output from the Perl module output.
+# The default value is: NO.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
PERLMOD_LATEX = NO
+
+# If the PERLMOD_PRETTY tag is set to YES, the Perl module output will be nicely
+# formatted so it can be parsed by a human reader. This is useful if you want to
+# understand what is going on. On the other hand, if this tag is set to NO, the
+# size of the Perl module output will be much smaller and Perl will parse it
+# just the same.
+# The default value is: YES.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
PERLMOD_PRETTY = YES
+
+# The names of the make variables in the generated doxyrules.make file are
+# prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. This is useful
+# so different doxyrules.make files included by the same Makefile don't
+# overwrite each other's variables.
+# This tag requires that the tag GENERATE_PERLMOD is set to YES.
+
PERLMOD_MAKEVAR_PREFIX =
+
#---------------------------------------------------------------------------
# Configuration options related to the preprocessor
#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES, doxygen will evaluate all
+# C-preprocessor directives found in the sources and include files.
+# The default value is: YES.
+
ENABLE_PREPROCESSING = YES
+
+# If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names
+# in the source code. If set to NO, only conditional compilation will be
+# performed. Macro expansion can be done in a controlled way by setting
+# EXPAND_ONLY_PREDEF to YES.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
MACRO_EXPANSION = YES
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
+# the macro expansion is limited to the macros specified with the PREDEFINED and
+# EXPAND_AS_DEFINED tags.
+# The default value is: NO.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
EXPAND_ONLY_PREDEF = NO
+
+# If the SEARCH_INCLUDES tag is set to YES, the include files in the
+# INCLUDE_PATH will be searched if a #include is found.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
SEARCH_INCLUDES = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by the
+# preprocessor. Note that the INCLUDE_PATH is not recursive, so the setting of
+# RECURSIVE has no effect here.
+# This tag requires that the tag SEARCH_INCLUDES is set to YES.
+
INCLUDE_PATH =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will be
+# used.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
INCLUDE_FILE_PATTERNS =
-PREDEFINED = GNUNET_UNUSED="" GNUNET_PACKED=""
+
+# The PREDEFINED tag can be used to specify one or more macro names that are
+# defined before the preprocessor is started (similar to the -D option of e.g.
+# gcc). The argument of the tag is a list of macros of the form: name or
+# name=definition (no spaces). If the definition and the "=" are omitted, "=1"
+# is assumed. To prevent a macro definition from being undefined via #undef or
+# recursively expanded use the := operator instead of the = operator.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
+PREDEFINED = GNUNET_UNUSED= \
+ GNUNET_PACKED=
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
+# tag can be used to specify a list of macro names that should be expanded. The
+# macro definition that is found in the sources will be used. Use the PREDEFINED
+# tag if you want to use a different macro definition that overrules the
+# definition found in the source code.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
EXPAND_AS_DEFINED =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES then doxygen's preprocessor will
+# remove all references to function-like macros that are alone on a line, have
+# an all uppercase name, and do not end with a semicolon. Such function macros
+# are typically used for boiler-plate code, and will confuse the parser if not
+# removed.
+# The default value is: YES.
+# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
+
SKIP_FUNCTION_MACROS = YES
+
#---------------------------------------------------------------------------
-# Configuration::additions related to external references
+# Configuration options related to external references
#---------------------------------------------------------------------------
-TAGFILES = ../../contrib/gnunet.tag ../../contrib/microhttpd.tag
+
+# The TAGFILES tag can be used to specify one or more tag files. For each tag
+# file the location of the external documentation should be added. The format of
+# a tag file without this location is as follows:
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where loc1 and loc2 can be relative or absolute paths or URLs. See the
+# section "Linking to external documentation" for more information about the use
+# of tag files.
+# Note: Each tag file must have a unique name (where the name does NOT include
+# the path). If a tag file is not located in the directory in which doxygen is
+# run, you must also specify the path to the tagfile here.
+
+TAGFILES = ../../contrib/gnunet.tag \
+ ../../contrib/microhttpd.tag
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create a
+# tag file that is based on the input files it reads. See section "Linking to
+# external documentation" for more information about the usage of tag files.
+
GENERATE_TAGFILE = taler-exchange.tag
+
+# If the ALLEXTERNALS tag is set to YES, all external class will be listed in
+# the class index. If set to NO, only the inherited external classes will be
+# listed.
+# The default value is: NO.
+
ALLEXTERNALS = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES, all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will be
+# listed.
+# The default value is: YES.
+
EXTERNAL_GROUPS = YES
+# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
+# the related pages index. If set to NO, only the current project's pages will
+# be listed.
+# The default value is: YES.
+
+EXTERNAL_PAGES = YES
+
#---------------------------------------------------------------------------
# Configuration options related to the dot tool
#---------------------------------------------------------------------------
-CLASS_DIAGRAMS = YES
+
+# You can include diagrams made with dia in doxygen documentation. Doxygen will
+# then run dia to produce the diagram and insert it in the documentation. The
+# DIA_PATH tag allows you to specify the directory where the dia binary resides.
+# If left empty dia is assumed to be found in the default search path.
+
+DIA_PATH =
+
+# If set to YES the inheritance and collaboration graphs will hide inheritance
+# and usage relations if the target is undocumented or is not a class.
+# The default value is: YES.
+
HIDE_UNDOC_RELATIONS = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz (see:
+# http://www.graphviz.org/), a graph visualization toolkit from AT&T and Lucent
+# Bell Labs. The other options in this section have no effect if this option is
+# set to NO
+# The default value is: YES.
+
HAVE_DOT = YES
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is allowed
+# to run in parallel. When set to 0 doxygen will base this on the number of
+# processors available in the system. You can set it explicitly to a value
+# larger than 0 to get control over the balance between CPU load and processing
+# speed.
+# Minimum value: 0, maximum value: 32, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_NUM_THREADS = 0
+
+# When you want a differently looking font in the dot files that doxygen
+# generates you can specify the font name using DOT_FONTNAME. You need to make
+# sure dot is able to find the font, which can be done by putting it in a
+# standard location or by setting the DOTFONTPATH environment variable or by
+# setting DOT_FONTPATH to the directory containing the font.
+# The default value is: Helvetica.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTNAME = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size (in points) of the font of
+# dot graphs.
+# Minimum value: 4, maximum value: 24, default value: 10.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTSIZE = 10
+
+# By default doxygen will tell dot to use the default font as specified with
+# DOT_FONTNAME. If you specify a different font using DOT_FONTNAME you can set
+# the path where dot can find it using this tag.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_FONTPATH =
+
+# If the CLASS_GRAPH tag is set to YES (or GRAPH) then doxygen will generate a
+# graph for each documented class showing the direct and indirect inheritance
+# relations. In case HAVE_DOT is set as well dot will be used to draw the graph,
+# otherwise the built-in generator will be used. If the CLASS_GRAPH tag is set
+# to TEXT the direct and indirect inheritance relations will be shown as texts /
+# links.
+# Possible values are: NO, YES, TEXT and GRAPH.
+# The default value is: YES.
+
CLASS_GRAPH = NO
+
+# If the COLLABORATION_GRAPH tag is set to YES then doxygen will generate a
+# graph for each documented class showing the direct and indirect implementation
+# dependencies (inheritance, containment, and class references variables) of the
+# class with other documented classes.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
COLLABORATION_GRAPH = NO
+
+# If the GROUP_GRAPHS tag is set to YES then doxygen will generate a graph for
+# groups, showing the direct groups dependencies. See also the chapter Grouping
+# in the manual.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
GROUP_GRAPHS = NO
+
+# If the UML_LOOK tag is set to YES, doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
UML_LOOK = NO
+
+# If the UML_LOOK tag is enabled, the fields and methods are shown inside the
+# class node. If there are many fields or methods and many nodes the graph may
+# become too big to be useful. The UML_LIMIT_NUM_FIELDS threshold limits the
+# number of items for each type to make the size more manageable. Set this to 0
+# for no limit. Note that the threshold may be exceeded by 50% before the limit
+# is enforced. So when you set the threshold to 10, up to 15 fields may appear,
+# but if the number exceeds 15, the total amount of fields shown is limited to
+# 10.
+# Minimum value: 0, maximum value: 100, default value: 10.
+# This tag requires that the tag UML_LOOK is set to YES.
+
+UML_LIMIT_NUM_FIELDS = 10
+
+# If the DOT_UML_DETAILS tag is set to NO, doxygen will show attributes and
+# methods without types and arguments in the UML graphs. If the DOT_UML_DETAILS
+# tag is set to YES, doxygen will add type and arguments for attributes and
+# methods in the UML graphs. If the DOT_UML_DETAILS tag is set to NONE, doxygen
+# will not generate fields with class member information in the UML graphs. The
+# class diagrams will look similar to the default class diagrams but using UML
+# notation for the relationships.
+# Possible values are: NO, YES and NONE.
+# The default value is: NO.
+# This tag requires that the tag UML_LOOK is set to YES.
+
+DOT_UML_DETAILS = NO
+
+# The DOT_WRAP_THRESHOLD tag can be used to set the maximum number of characters
+# to display on a single line. If the actual line length exceeds this threshold
+# significantly it will wrapped across multiple lines. Some heuristics are apply
+# to avoid ugly line breaks.
+# Minimum value: 0, maximum value: 1000, default value: 17.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_WRAP_THRESHOLD = 17
+
+# If the TEMPLATE_RELATIONS tag is set to YES then the inheritance and
+# collaboration graphs will show the relations between templates and their
+# instances.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
TEMPLATE_RELATIONS = NO
+
+# If the INCLUDE_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are set to
+# YES then doxygen will generate a graph for each documented file showing the
+# direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
INCLUDE_GRAPH = YES
+
+# If the INCLUDED_BY_GRAPH, ENABLE_PREPROCESSING and SEARCH_INCLUDES tags are
+# set to YES then doxygen will generate a graph for each documented file showing
+# the direct and indirect include dependencies of the file with other documented
+# files.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
INCLUDED_BY_GRAPH = YES
+
+# If the CALL_GRAPH tag is set to YES then doxygen will generate a call
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable call graphs for selected
+# functions only using the \callgraph command. Disabling a call graph can be
+# accomplished by means of the command \hidecallgraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
CALL_GRAPH = YES
+
+# If the CALLER_GRAPH tag is set to YES then doxygen will generate a caller
+# dependency graph for every global function or class method.
+#
+# Note that enabling this option will significantly increase the time of a run.
+# So in most cases it will be better to enable caller graphs for selected
+# functions only using the \callergraph command. Disabling a caller graph can be
+# accomplished by means of the command \hidecallergraph.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
CALLER_GRAPH = YES
+
+# If the GRAPHICAL_HIERARCHY tag is set to YES then doxygen will graphical
+# hierarchy of all classes instead of a textual one.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
GRAPHICAL_HIERARCHY = NO
+
+# If the DIRECTORY_GRAPH tag is set to YES then doxygen will show the
+# dependencies a directory has on other directories in a graphical way. The
+# dependency relations are determined by the #include relations between the
+# files in the directories.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DIRECTORY_GRAPH = YES
+
+# The DIR_GRAPH_MAX_DEPTH tag can be used to limit the maximum number of levels
+# of child directories generated in directory dependency graphs by dot.
+# Minimum value: 1, maximum value: 25, default value: 1.
+# This tag requires that the tag DIRECTORY_GRAPH is set to YES.
+
+# DIR_GRAPH_MAX_DEPTH = 1
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. For an explanation of the image formats see the section
+# output formats in the documentation of the dot tool (Graphviz (see:
+# http://www.graphviz.org/)).
+# Note: If you choose svg you need to set HTML_FILE_EXTENSION to xhtml in order
+# to make the SVG files visible in IE 9+ (other browsers do not have this
+# requirement).
+# Possible values are: png, jpg, jpg:cairo, jpg:cairo:gd, jpg:gd, jpg:gd:gd,
+# gif, gif:cairo, gif:cairo:gd, gif:gd, gif:gd:gd, svg, png:gd, png:gd:gd,
+# png:cairo, png:cairo:gd, png:cairo:cairo, png:cairo:gdiplus, png:gdiplus and
+# png:gdiplus:gdiplus.
+# The default value is: png.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DOT_IMAGE_FORMAT = svg
+
+# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to
+# enable generation of interactive SVG images that allow zooming and panning.
+#
+# Note that this requires a modern browser other than Internet Explorer. Tested
+# and working are Firefox, Chrome, Safari, and Opera.
+# Note: For IE 9+ you need to set HTML_FILE_EXTENSION to xhtml in order to make
+# the SVG files visible. Older versions of IE do not have SVG support.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
INTERACTIVE_SVG = NO
+
+# The DOT_PATH tag can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DOT_PATH =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the \dotfile
+# command).
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DOTFILE_DIRS =
-DOT_GRAPH_MAX_NODES = 100
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the \mscfile
+# command).
+
+MSCFILE_DIRS =
+
+# The DIAFILE_DIRS tag can be used to specify one or more directories that
+# contain dia files that are included in the documentation (see the \diafile
+# command).
+
+DIAFILE_DIRS =
+
+# When using plantuml, the PLANTUML_JAR_PATH tag should be used to specify the
+# path where java can find the plantuml.jar file or to the filename of jar file
+# to be used. If left blank, it is assumed PlantUML is not used or called during
+# a preprocessing step. Doxygen will generate a warning when it encounters a
+# \startuml command in this case and will not generate output for the diagram.
+
+PLANTUML_JAR_PATH =
+
+# When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a
+# configuration file for plantuml.
+
+PLANTUML_CFG_FILE =
+
+# When using plantuml, the specified paths are searched for files specified by
+# the !include statement in a plantuml block.
+
+PLANTUML_INCLUDE_PATH =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of nodes
+# that will be shown in the graph. If the number of nodes in a graph becomes
+# larger than this value, doxygen will truncate the graph, which is visualized
+# by representing a node as a red box. Note that doxygen if the number of direct
+# children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note that
+# the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+# Minimum value: 0, maximum value: 10000, default value: 50.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
+DOT_GRAPH_MAX_NODES = 1000
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the graphs
+# generated by dot. A depth value of 3 means that only nodes reachable from the
+# root by following a path via at most 3 edges will be shown. Nodes that lay
+# further from the root node will be omitted. Note that setting this option to 1
+# or 2 may greatly reduce the computation time needed for large code bases. Also
+# note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+# Minimum value: 0, maximum value: 1000, default value: 0.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
MAX_DOT_GRAPH_DEPTH = 2
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not seem
+# to support this out of the box.
+#
+# Warning: Depending on the platform used, enabling this option may lead to
+# badly anti-aliased labels on the edges of a graph (i.e. they become hard to
+# read).
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DOT_TRANSPARENT = YES
+
+# Set the DOT_MULTI_TARGETS tag to YES to allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10) support
+# this, this feature is disabled by default.
+# The default value is: NO.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
DOT_MULTI_TARGETS = NO
+
+# If the GENERATE_LEGEND tag is set to YES doxygen will generate a legend page
+# explaining the meaning of the various boxes and arrows in the dot generated
+# graphs.
+# Note: This tag requires that UML_LOOK isn't set, i.e. the doxygen internal
+# graphical representation for inheritance and collaboration diagrams is used.
+# The default value is: YES.
+# This tag requires that the tag HAVE_DOT is set to YES.
+
GENERATE_LEGEND = YES
+
+# If the DOT_CLEANUP tag is set to YES, doxygen will remove the intermediate
+# files that are used to generate the various graphs.
+#
+# Note: This setting is not only used for dot files but also for msc temporary
+# files.
+# The default value is: YES.
+
DOT_CLEANUP = YES
-#---------------------------------------------------------------------------
-# Configuration::additions related to the search engine
-#---------------------------------------------------------------------------
-SEARCHENGINE = YES
diff --git a/doc/flows/.gitignore b/doc/flows/.gitignore
new file mode 100644
index 000000000..f0de8a3d5
--- /dev/null
+++ b/doc/flows/.gitignore
@@ -0,0 +1 @@
+main.pdf
diff --git a/doc/flows/Makefile b/doc/flows/Makefile
new file mode 100644
index 000000000..e6af0897c
--- /dev/null
+++ b/doc/flows/Makefile
@@ -0,0 +1,3 @@
+all:
+ pdflatex main.tex
+ pdflatex main.tex
diff --git a/doc/flows/fees-coins.tex b/doc/flows/fees-coins.tex
new file mode 100644
index 000000000..c24f19a28
--- /dev/null
+++ b/doc/flows/fees-coins.tex
@@ -0,0 +1,39 @@
+\section{Fees per coin} \label{sec:fees:coin}
+
+Payments with Taler are always made using coins. Each coin has a specific
+denomination, and an exchange will issue coins in different denominations (in
+the same currency). The fees per coin depend on the operation and the
+denomination.
+
+The primary fee to be paid is a {\bf deposit} fee that is
+charged whenever a coin is fully or partially deposited
+into a bank account or another wallet.
+
+A secondary fee to be paid is a {\bf change} fee that is
+charged whenever a coin partially spent and change must
+be rendered.
+
+Coins also have an {\bf expiration} date of approximately {\bf one year}.
+After the expiration date, coins become worthless. Wallets that are online
+{\bf three months} {\em before} a coin expires will automatically trade any
+such coins for one or more fresh coins with a later expiration date. This
+process is also subject to the {\bf change} fee.
+
+
+\begin{table}[h!]
+ \caption{Fees per coin. Coin denomination values are given in units of CHF 0.01.}
+ \label{table:fees:coins}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Denomination} & {\bf Fee type} & {\bf Amount} \\ \hline \hline
+ $2^{-4}-2^{ 0}$ & deposit & {\em CHF 0.00125} \\
+ $2^{-4}-2^{ 0}$ & change & {\em CHF 0.00125} \\
+ $2^{ 0}-2^{ 3}$ & deposit & {\em CHF 0.00250} \\
+ $2^{ 0}-2^{ 3}$ & change & {\em CHF 0.00125} \\
+ $2^{ 4}-2^{ 8}$ & deposit & {\em CHF 0.005} \\
+ $2^{ 4}-2^{ 8}$ & change & {\em CHF 0.00125} \\
+ $2^{ 8}-2^{12}$ & deposit & {\em CHF 0.01} \\
+ $2^{ 8}-2^{12}$ & change & {\em CHF 0.00125} \\
+ \end{tabular}
+ \end{center}
+\end{table}
diff --git a/doc/flows/fees-wire.tex b/doc/flows/fees-wire.tex
new file mode 100644
index 000000000..214a69021
--- /dev/null
+++ b/doc/flows/fees-wire.tex
@@ -0,0 +1,30 @@
+\section{Fees per wire} \label{sec:fees:wire}
+
+Wire fees apply whenever an exchange needs to initiate a wire transfer to
+another bank account. Wire fees do not apply to every individual payment to a
+merchant, as merchants can choose to {\em aggregate} multiple micropayments
+into one large payment on the wire. Wire fees also do not apply to
+wallet-to-wallet payments within the Taler system.
+
+A {\bf wire} fee is applied when a merchant receives
+an aggregated payment into their bank account.
+
+A {\bf closing} fee is applied when a wallet fails to
+withdraw coins and money has to be sent back to the
+originating bank account.
+
+\begin{table}[h!]
+ \caption{Table with wire fees. Wire fees are set annually.}
+ \label{table:fees:wire}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Year} & {\bf Fee type} & {\bf Amount} \\ \hline \hline
+ 2023 & wire & {\em CHF 0.05} \\
+ 2023 & closing & {\em CHF 0.10} \\
+ 2024 & wire & {\em CHF 0.05} \\
+ 2024 & closing & {\em CHF 0.10} \\
+ 2025 & wire & {\em CHF 0.05} \\
+ 2025 & closing & {\em CHF 0.10} \\
+ \end{tabular}
+ \end{center}
+\end{table}
diff --git a/doc/flows/int-deposit.tex b/doc/flows/int-deposit.tex
new file mode 100644
index 000000000..661f4dccb
--- /dev/null
+++ b/doc/flows/int-deposit.tex
@@ -0,0 +1,52 @@
+\section{Deposit} \label{sec:deposit}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{bank}{\shortstack{Retail bank \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Checking \\ Accounts};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \begin{callself}{wallet}{Review deposit fees}{}
+ \end{callself}
+ \mess[0]{wallet}{Deposit {(Coins)}}{exchange}
+ \begin{sdblock}{Acceptable account?}{}
+ \mess[0]{exchange}{{Refuse deposit}}{wallet}
+ \end{sdblock}
+ \begin{sdblock}{KYC/AML required?}{}
+ \begin{callself}{exchange}{Figures~\ref{fig:proc:kyc}, \ref{fig:proc:aml}}{}
+ \end{callself}
+ \end{sdblock}
+% \prelevel
+% \prelevel
+% \begin{sdblock}{User abort?}{}
+% \mess[0]{wallet}{{Request abort}}{exchange}
+% \mess[0]{exchange}{{Abort confirmation}}{wallet}
+% \end{sdblock}
+ \mess[0]{exchange}{{Initiate transfer}}{bank}
+
+\end{sequencediagram}
+ \caption{A customer deposits the coins issued by a Taler exchange (payment
+ service provider) into a bank account. Even if the
+ bank account is owned by the same customer, the
+ KYC checks from Section~\ref{sec:kyc:deposit} apply.}
+ \label{fig:int:deposit}
+\end{figure}
+
+We do {\bf not} permit the customer to regain control over their funds {\em
+ unless} they pass the KYC/AML checks. The technical reason is simply that
+the KYC/AML checks happen {\em after} the aggregation logic and at this point
+refunds are no longer permitted. From a compliance perspective, this also
+prevents malicious customers from risk-free probing of the system.
diff --git a/doc/flows/int-pay.tex b/doc/flows/int-pay.tex
new file mode 100644
index 000000000..2968c4c2e
--- /dev/null
+++ b/doc/flows/int-pay.tex
@@ -0,0 +1,60 @@
+\section{Pay} \label{sec:pay}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[1]{merchant}{\shortstack{Merchant \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[1]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[1]{bank}{\shortstack{Merchant bank \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Commercial \\ Accounts};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \mess[0]{wallet}{Browse catalog}{merchant}
+ \mess[0]{merchant}{Commercial offer}{wallet}
+ \begin{callself}{wallet}{Review offer}{}
+ \end{callself}
+ \mess[0]{wallet}{Pay {(Coins)}}{merchant}
+ \mess[0]{merchant}{Deposit {(Coins)}}{exchange}
+ \begin{sdblock}{Acceptable account?}{}
+ \mess[0]{exchange}{{Refuse deposit}}{merchant}
+ \mess[0]{merchant}{{Refund purchase}}{wallet}
+ \end{sdblock}
+ \mess[0]{exchange}{{Confirm deposit}}{merchant}
+ \mess[0]{merchant}{Fulfill order}{wallet}
+ \begin{callself}{exchange}{Aggregate transactions}{}
+ \end{callself}
+ \begin{sdblock}{KYC/AML required?}{}
+ \begin{callself}{exchange}{Figures~\ref{fig:proc:kyc}, \ref{fig:proc:aml}}{}
+ \end{callself}
+ \end{sdblock}
+ \mess[0]{exchange}{{Initiate transfer}}{bank}
+ \end{sequencediagram}
+ \caption{Payments from a customer to merchant result in
+ depositing coins at the Taler exchange (payment service provider)
+ which then credits the merchant's bank account.
+ The KYC/AML checks are described in Section~\ref{sec:kyc:deposit}}
+ \label{fig:int:pay}
+\end{figure}
+
+{\bf Internal note:} The exchange refusing a deposit immediately based on
+unaccaptable merchant accounts may not be fully implemented (this is a very
+recent feature, after all); especially the merchant then automatically
+refunding the purchase to the customer is certainly missing. However,
+the entire situation only arises when a merchant is incorrectly configured
+and in violation of the terms of service.
diff --git a/doc/flows/int-pull.tex b/doc/flows/int-pull.tex
new file mode 100644
index 000000000..38caef6c8
--- /dev/null
+++ b/doc/flows/int-pull.tex
@@ -0,0 +1,56 @@
+\section{Pull payment (aka invoicing)} \label{sec:pull}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{payer}{\shortstack{Payer \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Pre-funded \\ Wallet};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{payee}{\shortstack{Payee \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \begin{callself}{payee}{Review pull payment fees}{}
+ \end{callself}
+ \mess[0]{payee}{{Create invoice (Wallet ID)}}{exchange}
+
+ \mess[0]{exchange}{{Invoice ready}}{payee}
+ \mess[0]{payee}{{Send invoice (e.g. via QR code)}}{payer}
+
+ \begin{callself}{payer}{Review invoice}{}
+ \end{callself}
+ \mess[0]{payer}{{Make payment (Coins)}}{exchange}
+
+ \begin{sdblock}{Domestic wallet?}{}
+ \begin{callself}{exchange}{Figure~\ref{fig:proc:domestic}}{}
+ \end{callself}
+ \end{sdblock}
+ \begin{sdblock}{KYC/AML required?}{}
+ \begin{callself}{exchange}{Figures~\ref{fig:proc:kyc}, \ref{fig:proc:aml}}{}
+ \end{callself}
+ \end{sdblock}
+
+ \mess[0]{exchange}{{Distribute digital cash}}{payee}
+
+\end{sequencediagram}
+ \caption{Interactions between wallets and Taler exchange
+ in a pull payment. KYC/AML checks are described in
+ Section~\ref{sec:kyc:pull}.}
+ \label{fig:int:pull}
+\end{figure}
+
+We do {\bf not} permit the payer to regain control over their funds, once the
+payment was made they are locked {\em until} the payee passes the KYC/AML
+checks. We only do the AML/KYC process once the funds are locked at the
+exchange. This ensures we know the actual transacted amounts (which may be
+lower than the total amounts requested) and prevents risk-free probing
+attacks.
diff --git a/doc/flows/int-push.tex b/doc/flows/int-push.tex
new file mode 100644
index 000000000..faea50f72
--- /dev/null
+++ b/doc/flows/int-push.tex
@@ -0,0 +1,48 @@
+\section{Push payment} \label{sec:push}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{payer}{\shortstack{Payer \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Pre-funded \\ Wallet};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{payee}{\shortstack{Payee \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \begin{callself}{payer}{Review push payment fees}{}
+ \end{callself}
+ \mess[0]{payer}{{Push funds (Coins)}}{exchange}
+ \mess[0]{payer}{{Offer payment (e.g. via QR code)}}{payee}
+ \begin{callself}{payee}{Review payment offer}{}
+ \end{callself}
+ \mess[0]{payee}{{Request funds (Wallet ID)}}{exchange}
+ \begin{sdblock}{Domestic wallet?}{}
+ \begin{callself}{exchange}{Figure~\ref{fig:proc:domestic}}{}
+ \end{callself}
+ \end{sdblock}
+ \begin{sdblock}{KYC/AML required?}{}
+ \begin{callself}{exchange}{Figures~\ref{fig:proc:kyc}, \ref{fig:proc:aml}}{}
+ \end{callself}
+ \end{sdblock}
+ \mess[0]{exchange}{{Distribute digital cash}}{payee}
+% \postlevel
+ \begin{sdblock}{Payment offer expired?}{}
+ \mess[0]{exchange}{{Return funds}}{payer}
+ \end{sdblock}
+
+\end{sequencediagram}
+ \caption{Interactions between wallets and Taler exchange
+ in a push payment. KYC/AML checks are described
+ in Section~\ref{sec:kyc:push}.}
+ \label{fig:int:push}
+\end{figure}
diff --git a/doc/flows/int-refund.tex b/doc/flows/int-refund.tex
new file mode 100644
index 000000000..3f11e5600
--- /dev/null
+++ b/doc/flows/int-refund.tex
@@ -0,0 +1,39 @@
+\section{Refund}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{merchant}{\shortstack{Merchant \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \begin{callself}{merchant}{Initiate refund}{}
+ \end{callself}
+ \mess[0]{merchant}{{Refund offer (QR code)}}{wallet}
+ \mess[0]{wallet}{Download refund}{merchant}
+ \mess[0]{merchant}{Approve refund}{exchange}
+ \mess[0]{exchange}{Confirm refund}{merchant}
+ \mess[0]{merchant}{Return refund confirmation}{wallet}
+ \end{sequencediagram}
+ \caption{Refund processing when a merchant is unable to fulfill
+ a contract. Refunds must happen {\em before} the
+ exchange has aggregated the original transaction for
+ a bank transfer to the merchant. Furthermore, refunds
+ can only go to the customer who made the original payment
+ and the refund cannot exceed the amount of the original
+ payment.}
+ \label{fig:int:refund}
+\end{figure}
diff --git a/doc/flows/int-shutdown.tex b/doc/flows/int-shutdown.tex
new file mode 100644
index 000000000..e8ee6feed
--- /dev/null
+++ b/doc/flows/int-shutdown.tex
@@ -0,0 +1,48 @@
+\section{Shutdown}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{bank}{\shortstack{Customer bank \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Checking \\ Accounts};
+ \end{tikzpicture}
+ }}
+ \postlevel
+
+ \begin{callself}{exchange}{Operator initiates shutdown}{}
+ \end{callself}
+ \mess[0]{exchange}{{Shutdown alert}}{wallet}
+ \begin{sdblock}{Bank account known?}{}
+ \begin{callself}{wallet}{Designate bank account}{}
+ \end{callself}
+ \end{sdblock}
+ \mess[0]{wallet}{{Deposit (Coins)}}{exchange}
+ \begin{sdblock}{Acceptable account?}{}
+ \mess[0]{exchange}{{Refuse deposit}}{wallet}
+ \end{sdblock}
+ \begin{sdblock}{KYC/AML required?}{}
+ \begin{callself}{exchange}{Figures~\ref{fig:proc:kyc}, \ref{fig:proc:aml}}{}
+ \end{callself}
+ \end{sdblock}
+ \mess[0]{exchange}{{Initiate transfer}}{bank}
+\end{sequencediagram}
+ \caption{Shutdown interactions between customer, Taler exchange (payment
+ service provider) and bank.}
+ \label{fig:int:shutdown}
+\end{figure}
+
+KYC/AML requirements are relaxed in cases where the customer is able to
+cryptographically demonstrate that they previously withdrew these coins from
+the designated checking account. Thus, KYC/AML checks here primarily still
+apply if the customer received the funds via P2P transfers from other wallets.
diff --git a/doc/flows/int-withdraw.tex b/doc/flows/int-withdraw.tex
new file mode 100644
index 000000000..11ae25de9
--- /dev/null
+++ b/doc/flows/int-withdraw.tex
@@ -0,0 +1,49 @@
+\section{Withdraw}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{bank}{\shortstack{Customer bank \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] {Checking \\ Accounts};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \mess[0]{wallet}{Withdraw {(Amount)}}{exchange}
+ \mess[0]{exchange}{{Configuration (ToS, Fees)}}{wallet}
+ \begin{sdblock}{once}{}
+ \begin{callself}{wallet}{Accept ToS}{}
+ \end{callself}
+ \end{sdblock}
+ \begin{callself}{wallet}{Review withdraw fees}{}
+ \end{callself}
+ \mess[0]{wallet}{{Initiate transfer (Amount, Credit account, Wallet ID)}}{bank}
+ \mess[0]{bank}{{Credit (Wallet ID)}}{exchange}
+
+ \begin{sdblock}{Acceptable transfer?}{}
+ \mess[0]{exchange}{{Bounce funds}}{bank}
+ \end{sdblock}
+ \postlevel
+ \mess[0]{exchange}{Confirm wire transfer}{wallet}
+ \mess[0]{wallet}{Request digital cash}{exchange}
+ \mess[0]{exchange}{Distribute digital cash}{wallet}
+ \postlevel
+ \begin{sdblock}{Withdraw period expired?}{}
+ \mess[0]{exchange}{{Return remaining funds}}{bank}
+ \end{sdblock}
+\end{sequencediagram}
+ \caption{Withdraw interactions between customer, Taler exchange (payment
+ service provider) and bank. The amount of digital cash distributed is
+ subject to limits per origin account (see Section~\ref{sec:kyc:withdraw}).}
+ \label{fig:int:withdraw}
+\end{figure}
diff --git a/doc/flows/kyc-balance.tex b/doc/flows/kyc-balance.tex
new file mode 100644
index 000000000..de8953665
--- /dev/null
+++ b/doc/flows/kyc-balance.tex
@@ -0,0 +1,58 @@
+\section{KYC: Balance}
+
+Note: this process is not implemented and would require non-trivial extra work
+if required.
+
+\begin{figure}[h!]
+ \begin{center}
+\begin{tikzpicture}[node distance=1cm,font=\sffamily,
+ start/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=yellow!30},
+ end/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
+ process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
+ failed/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
+ io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
+ decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
+ arr/.style={very thick,-latex},
+ every edge quotes/.style = {auto, font=\footnotesize, sloped}
+ ]
+ \node (start) [start] {Start};
+ \node (balance) [decision,below=of start,text width=3cm] {Transaction leaves wallet balance below AML threshold?};
+ \node (registered) [decision,below=of balance,text width=3cm] {Wallet has been subject to KYC?};
+ \node (kyc) [process, below=of registered] {KYC process};
+ \node (aml) [process, left=of kyc] {AML process};
+ \node (allow) [end, right=of balance] {Allow};
+ \node (deny) [failed, right=of registered] {Deny};
+ \draw[arr] (start) -> (balance) {};
+ \draw[arr] (balance) -> (registered);
+ \draw (balance) edge["No"] (registered);
+ \draw[arr] (balance) -> (allow);
+ \draw (balance) edge["Yes"] (allow);
+
+ \draw[arr] (registered) -> (kyc);
+ \draw (registered) edge["No"] (kyc);
+ \draw[arr] (registered) -> (deny);
+ \draw (registered) edge["Yes"] (deny);
+
+ \draw[arr] (kyc) -> (deny);
+ \draw (kyc) edge["Failed"] (deny);
+ \draw[arr] (kyc) -> (aml);
+ \draw (kyc) edge["Ok"] (aml);
+
+ \draw[arr] (aml) -> (balance.west);
+ \draw (aml) edge["New threshold"] (balance.west);
+\end{tikzpicture}
+ \end{center}
+ \caption{Regulatory process when a wallet exceeds its AML threshold.
+ When the transfer is denied the transaction (withdraw, P2P transfer)
+ is refused by the wallet.}
+\end{figure}
+
+
+\begin{table}[h!]
+ \caption{Settings for the balance trigger.}
+ \begin{tabular}{l|l|r}
+ {\bf Setting} & {\bf Type} & {\bf Value} \\ \hline \hline
+ KYC threshold & Amount & {\em 5000 CHF} \\
+ Default AML threshold & Amount & {\em 5000 CHF} \\
+ \end{tabular}
+\end{table}
diff --git a/doc/flows/kyc-deposit.tex b/doc/flows/kyc-deposit.tex
new file mode 100644
index 000000000..0132cebf6
--- /dev/null
+++ b/doc/flows/kyc-deposit.tex
@@ -0,0 +1,85 @@
+\section{KYC: Deposit} \label{sec:kyc:deposit}
+
+\begin{figure}[h!]
+ \begin{center}
+\begin{tikzpicture}[node distance=1cm,font=\sffamily,
+ start/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=yellow!30},
+ end/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
+ process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
+ failed/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
+ io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
+ decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
+ arr/.style={very thick,-latex},
+ every edge quotes/.style = {auto, font=\footnotesize, sloped}
+ ]
+ \node (start) [start] {Start};
+ \node (country) [decision,below=of start,text width=2.5cm] {Target account in allowed country?};
+ \node (amount) [decision, below=of country,text width=2.5cm] {Target account received less than KYB threshold?};
+ \node (kyc) [process, right=of amount] {KYB process};
+ \node (high) [decision, below=of amount,text width=2.5cm] {Target account received more than its AML threshold?};
+ \node (aml) [process, right=of high] {AML process};
+ \node (dummy) [below right=of aml] {};
+ \node (allow) [end, below right=of dummy] {Allow};
+ \node (deny) [failed, right=of kyc] {Deny};
+ \draw[arr] (start) -> (country) {};
+
+ \draw[arr] (country) -> (amount);
+ \draw (country) edge["Yes"] (amount);
+
+ \draw[arr] (country.east) -> (deny);
+ \draw (country.east) edge["No"] (deny);
+
+ \draw[arr] (amount) -> (high);
+ \draw (amount) edge["Yes"] (high);
+
+ \draw[arr] (amount.east) -> (kyc);
+ \draw (amount.east) edge["No"] (kyc);
+
+ \draw[arr] (kyc) -> (deny);
+ \draw (kyc) edge["Failed"] (deny);
+
+ \draw[arr] (kyc) -> (high);
+ \draw (kyc) edge["Succeeded"] (high);
+
+ \draw[arr] (high.south) -> (allow);
+ \draw (high.south) edge["Yes"] (allow);
+
+ \draw[arr] (high.east) -> (aml);
+ \draw (high.east) edge["No"] (aml);
+
+ \draw[arr] (aml) -> (deny);
+ \draw (aml) edge["Violation"] (deny);
+
+ \draw[arr] (aml) -> (allow);
+ \draw (aml) edge["Ok"] (allow);
+\end{tikzpicture}
+ \end{center}
+ \caption{Regulatory process when depositing digital cash into a bank
+ account. When the transfer is denied, the money is held in escrow
+ until authorities authorize the transfer.}
+\end{figure}
+
+
+\begin{table}[h!]
+ \caption{Settings for the deposit trigger. Note that the operation
+ must satisfy all of the given rules.}
+ \begin{tabular}{l|l|r}
+ {\bf Setting} & {\bf Type} & {\bf Value} \\ \hline \hline
+ Allowed bank accounts & RFC 8905 RegEx & {\em CH*} \\ \hline
+ KYB deposit threshold & Amount/month & {\em 5000 CHF} \\
+ KYB deposit threshold & Amount/year & {\em 15000 CHF} \\
+ Default AML deposit threshold & Amount/month & {\em 5000 CHF} \\
+ \end{tabular}
+\end{table}
+
+%The KYB deposit threshold of 5'000 \CURRENCY{} per month and than 15'000
+%\CURRENCY{} per year ensure compliance. % with article 48-1b.
+
+Additionally, our terms of service will prohibit businesses to receive
+amounts exceeding 1'000 \CURRENCY{} per transaction.
+%(well below the 15'000 \CURRENCY{} threshold defined in article 24-1c).
+
+SMS-Identification is done by in-house software. KYB data is initially
+obtained and vetted by one of several external KYB providers before
+being passed for manual validation by our own staff who can then
+determine appropriate AML thresholds and set review criteria.
diff --git a/doc/flows/kyc-pull.tex b/doc/flows/kyc-pull.tex
new file mode 100644
index 000000000..4d4f2c852
--- /dev/null
+++ b/doc/flows/kyc-pull.tex
@@ -0,0 +1,92 @@
+\section{KYC/AML: Pull Payment} \label{sec:kyc:pull}
+
+\begin{figure}[h!]
+ \begin{center}
+\begin{tikzpicture}[node distance=0.9cm,font=\sffamily,
+ start/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=yellow!30},
+ end/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
+ process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
+ failed/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
+ io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
+ decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
+ arr/.style={very thick,-latex},
+ every edge quotes/.style = {auto, font=\footnotesize, sloped}
+ ]
+ \node (start) [start] {Start};
+ \node (wallet) [decision,below=of start,text width=2.5cm] {Wallet linked to (domestic) phone number?};
+ \node (domestic) [process, right=of wallet] {Validate phone number};
+ \node (amount) [decision, below=of wallet,text width=2.5cm] {Wallet received less than KYC threshold from other wallets?};
+ \node (kyc) [process, right=of amount] {KYC process};
+ \node (high) [decision, below=of amount,text width=2.5cm] {Wallet received more than its AML threshold?};
+ \node (aml) [process, right=of high] {AML process};
+ \node (dummy) [below right=of aml] {};
+ \node (allow) [end, below right=of dummy] {Allow invoicing};
+ \node (deny) [failed, right=of kyc] {Deny};
+ \draw[arr] (start) -> (wallet) {};
+
+ \draw[arr] (wallet) -> (amount);
+ \draw (wallet) edge["Yes"] (amount);
+
+ \draw[arr] (wallet.east) -> (domestic);
+ \draw (wallet.east) edge["No"] (domestic);
+
+ \draw[arr] (domestic) -> (amount);
+ \draw (domestic) edge["Confirmed"] (amount);
+
+ \draw[arr] (domestic) -> (deny);
+ \draw (domestic) edge["Failed"] (deny);
+
+ \draw[arr] (amount) -> (high);
+ \draw (amount) edge["Yes"] (high);
+
+ \draw[arr] (amount.east) -> (kyc);
+ \draw (amount.east) edge["No"] (kyc);
+
+ \draw[arr] (kyc) -> (deny);
+ \draw (kyc) edge["Failed"] (deny);
+
+ \draw[arr] (kyc) -> (high);
+ \draw (kyc) edge["Succeeded"] (high);
+
+ \draw[arr] (high.south) -> (allow);
+ \draw (high.south) edge["Yes"] (allow);
+
+ \draw[arr] (high.east) -> (aml);
+ \draw (high.east) edge["No"] (aml);
+
+ \draw[arr] (aml) -> (deny);
+ \draw (aml) edge["Violation"] (deny);
+
+ \draw[arr] (aml) -> (allow);
+ \draw (aml) edge["Ok"] (allow);
+\end{tikzpicture}
+ \end{center}
+ \caption{Regulatory process when receiving payments from another wallet.
+ The threshold depends on the risk profile from the KYC process.
+ When KYC thresholds would be passed, the receiving wallet cannot
+ generate a valid invoice until it has provided the KYC data.
+ When a transfer is denied by AML staff, the money is held in escrow
+ until authorities authorize the transfer.}
+\end{figure}
+
+
+\begin{table}[h!]
+ \caption{Settings for the pull payment trigger. Note that the operation
+ must satisfy all of the given rules.}
+ \begin{tabular}{l|l|r}
+ {\bf Setting} & {\bf Type} & {\bf Value} \\ \hline \hline
+ Permitted phone numbers & Dialing prefix & {\em +41} \\
+ SMS-Identification & Amount/month & {\em 0 CHF} \\
+ P2P KYC threshold & Amount/month & {\em 5000 CHF} \\
+ P2P KYC threshold & Amount/year & {\em 15000 CHF} \\
+ Default P2P AML threshold & Amount/month & {\em 5000 CHF} \\
+ \end{tabular}
+\end{table}
+
+%The P2P KYC thresholds of 5'000 \CURRENCY{} per month and than 15'000
+%\CURRENCY{} per year ensure compliance with article 49-2c.
+
+SMS-Identification is done by in-house software. KYC data is initially
+obtained and vetted by one of several external KYC providers before
+being passed for manual validation by our own staff who can then
+determine appropriate AML thresholds and set review criteria.
diff --git a/doc/flows/kyc-push.tex b/doc/flows/kyc-push.tex
new file mode 100644
index 000000000..c74b3ce16
--- /dev/null
+++ b/doc/flows/kyc-push.tex
@@ -0,0 +1,90 @@
+\section{KYC/AML: Push Payment} \label{sec:kyc:push}
+
+\begin{figure}[h!]
+ \begin{center}
+\begin{tikzpicture}[node distance=0.9cm,font=\sffamily,
+ start/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=yellow!30},
+ end/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
+ process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
+ failed/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
+ io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
+ decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
+ arr/.style={very thick,-latex},
+ every edge quotes/.style = {auto, font=\footnotesize, sloped}
+ ]
+ \node (start) [start] {Start};
+ \node (wallet) [decision,below=of start,text width=2.5cm] {Wallet linked to (domestic) phone number?};
+ \node (domestic) [process, right=of wallet] {Validate phone number};
+ \node (amount) [decision, below=of wallet,text width=2.5cm] {Wallet received less than KYC threshold from other wallets?};
+ \node (kyc) [process, right=of amount] {KYC process};
+ \node (high) [decision, below=of amount,text width=2.5cm] {Wallet received more than its AML threshold?};
+ \node (aml) [process, right=of high] {AML process};
+ \node (dummy) [below right=of aml] {};
+ \node (allow) [end, below right=of dummy] {Allow};
+ \node (deny) [failed, right=of kyc] {Deny};
+ \draw[arr] (start) -> (wallet) {};
+
+ \draw[arr] (wallet) -> (amount);
+ \draw (wallet) edge["Yes"] (amount);
+
+ \draw[arr] (wallet.east) -> (domestic);
+ \draw (wallet.east) edge["No"] (domestic);
+
+ \draw[arr] (domestic) -> (amount);
+ \draw (domestic) edge["Confirmed"] (amount);
+
+ \draw[arr] (domestic) -> (deny);
+ \draw (domestic) edge["Failed"] (deny);
+
+ \draw[arr] (amount) -> (high);
+ \draw (amount) edge["Yes"] (high);
+
+ \draw[arr] (amount.east) -> (kyc);
+ \draw (amount.east) edge["No"] (kyc);
+
+ \draw[arr] (kyc) -> (deny);
+ \draw (kyc) edge["Failed"] (deny);
+
+ \draw[arr] (kyc) -> (high);
+ \draw (kyc) edge["Succeeded"] (high);
+
+ \draw[arr] (high.south) -> (allow);
+ \draw (high.south) edge["Yes"] (allow);
+
+ \draw[arr] (high.east) -> (aml);
+ \draw (high.east) edge["No"] (aml);
+
+ \draw[arr] (aml) -> (deny);
+ \draw (aml) edge["Violation"] (deny);
+
+ \draw[arr] (aml) -> (allow);
+ \draw (aml) edge["Ok"] (allow);
+\end{tikzpicture}
+ \end{center}
+ \caption{Regulatory process when receiving payments from another wallet.
+ The threshold depends on the risk profile from the KYC process.
+ When the transfer is denied, the money is held in escrow
+ until authorities authorize the transfer.}
+\end{figure}
+
+
+\begin{table}[h!]
+ \caption{Settings for the push payment trigger. Note that the operation
+ must satisfy all of the given rules.}
+ \begin{tabular}{l|l|r}
+ {\bf Setting} & {\bf Type} & {\bf Value} \\ \hline \hline
+ Permitted phone numbers & Dialing prefix & {\em +41} \\
+ SMS-Identification & Amount/month & {\em 0 CHF} \\
+ P2P KYC threshold & Amount/month & {\em 5000 CHF} \\
+ P2P KYC threshold & Amount/year & {\em 15000 CHF} \\
+ Default P2P AML threshold & Amount/month & {\em 5000 CHF} \\
+ \end{tabular}
+\end{table}
+
+%The P2P KYC thresholds of 5'000 \CURRENCY{} per month and than 15'000
+%\CURRENCY{} per year ensure compliance. % with article 49-2c.
+
+SMS-Identification is done by in-house software. KYC data is initially
+obtained and vetted by one of several external KYC providers before
+being passed for manual validation by our own staff who can then
+determine appropriate AML thresholds and set review criteria.
diff --git a/doc/flows/kyc-withdraw.tex b/doc/flows/kyc-withdraw.tex
new file mode 100644
index 000000000..b5605618e
--- /dev/null
+++ b/doc/flows/kyc-withdraw.tex
@@ -0,0 +1,58 @@
+\section{KYC: Withdraw} \label{sec:kyc:withdraw}
+
+\begin{figure}[h!]
+ \begin{center}
+\begin{tikzpicture}[node distance=1cm,font=\sffamily,
+ start/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=yellow!30},
+ end/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm,text centered, draw=black, fill=red!30},
+ process/.style={rectangle, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=orange!30},
+ failed/.style={rectangle, rounded corners, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=red!30},
+ io/.style={trapezium, trapezium left angle=70, trapezium right angle=110, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30},
+ decision/.style={diamond, minimum width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30},
+ arr/.style={very thick,-latex},
+ every edge quotes/.style = {auto, font=\footnotesize, sloped}
+ ]
+ \node (start) [start] {Start};
+ \node (country) [decision,below=of start,text width=3cm] {Wire transfer originates from allowed country?};
+ \node (amount) [decision, below=of country,text width=3cm] {Transferred less than maximum amount from origin account over last month?};
+ \node (allow) [end, below=of amount] {Allow};
+ \node (deny) [failed, right=of allow] {Deny};
+ \draw[arr] (start) -> (country) {};
+ \draw[arr] (country) -> (amount);
+ \draw (country) edge["Yes"] (amount);
+ \draw[arr] (country.east) -> (deny);
+ \draw (country.east) edge["No"] (deny);
+ \draw[arr] (amount) -> (allow);
+ \draw (amount) edge["Yes"] (allow);
+ \draw[arr] (amount.east) -> (deny);
+ \draw (amount.east) edge["No"] (deny);
+\end{tikzpicture}
+ \end{center}
+ \caption{Regulatory process when withdrawing digital cash from a
+ bank account.
+ If the transfer is denied or the user fails to withdraw the
+ funds for any other reason, the money is automatically returned
+ after the bounce period (see Table~\ref{table:kyc:withdraw:settings}) to
+ the originating bank account.}
+ \label{fig:kyc:withdraw}
+\end{figure}
+
+\begin{table}[h!]
+ \caption{Settings for the withdraw trigger. Note that the operation
+ must satisfy all of the given rules.} \label{table:kyc:withdraw:settings}
+ \begin{tabular}{l|l|r}
+ {\bf Setting} & {\bf Type} & {\bf Value} \\ \hline \hline
+ Allowed bank accounts & RFC 8905 RegEx & {\em CH*} \\ \hline
+ SMS-Identification & Amount/month & {\em 200 CHF} \\
+ Withdraw limit & Amount/month & {\em 5000 CHF} \\
+ Withdraw limit & Amount/year & {\em 15000 CHF} \\
+ Bounce period & Delay & 1 month \\
+ \end{tabular}
+\end{table}
+
+%The limit of 200 \CURRENCY{} results from article 48-2. Strictly limiting
+%withdrawals to less than 5'000 \CURRENCY{} per month and less than 15'000
+%\CURRENCY{} per year assures compliance with article 48-1c.
+
+SMS-Identification is done by in-house software. Withdraw limits are
+hard and cannot be raised even if the customer is known.
diff --git a/doc/flows/main.de.tex b/doc/flows/main.de.tex
new file mode 100644
index 000000000..5f224007d
--- /dev/null
+++ b/doc/flows/main.de.tex
@@ -0,0 +1,239 @@
+% This is a (partial) translation of main.tex into
+% German. Please keep the structure as parallel as
+% possible when improving / expanding the translation!
+\documentclass[10pt,a4paper,oneside]{book}
+\usepackage[utf8]{inputenc}
+\usepackage{url}
+\usepackage{enumitem}
+\usepackage{graphicx}
+\usepackage{hyperref}
+\usepackage{qrcode}
+\usepackage{pgf-umlsd}
+\usepackage{tikz}
+\usetikzlibrary{shapes,arrows}
+\usetikzlibrary{positioning}
+\usetikzlibrary{calc}
+\usetikzlibrary{quotes}
+\author{Christian Grothoff}
+\title{Flows in the GNU Taler System}
+
+\begin{document}
+
+\tableofcontents
+
+\newcommand\TALER{TALER OPERATIONS AG}
+\newcommand\CURRENCY{CHF}
+\newcommand\LAND{der Schweiz}
+
+\section{Transaktionen im Taler-Bezahlsystem}\label{sec:Transaktionen}
+
+Dieser Abschnitt stellt die Transaktionen im Taler-Bezahlsystem
+vor. Die Grafiken geben wieder, in welcher Reihenfolge die beteiligten
+Parteien interagieren. \\
+F\"ur jede einzelne Transaktion ist die automatische Ausl\"osung von
+Compliance-Prozessen durch den Taler-Exchange einstellbar.
+Die im Rahmen des jeweiligen Compliance-Prozesses erzwungenen
+Pr\"ufschritte beschreibt Abschnitt~\ref{sec:triggers}.
+
+Folgende Transaktionen kommen als Ausl\"oser f\"ur AML- und KYC-Prozesse
+in Betracht:
+\begin{description}[noitemsep]
+ \item[withdraw] Ein Nutzer hebt digitales Bargeld (e-money) in Form von
+ Taler-Coins in ein Taler-Wallet ab
+ \item[reimburse] Ein Nutzer l\"asst den Gegenwert von Taler-Coins vom
+ Taler-Exchange an das urspr\"ungliche IBAN-Bankkonto zur\"uck\"uberweisen
+ \item[pay] Ein Nutzer zahlt zugunsten eines IBAN-Bankkontos des Empf\"angers
+ \item[refund] Ein Verk\"aufer erteilt einem Zahlenden die R\"uckerstattung
+ eines Zahlbetrags
+ \item[push] Ein Nutzer sendet einen Zahlbetrag an ein anderes Taler-Wallet
+ \item[pull] Ein Nutzer stellt einem anderen Taler-Wallet eine Rechnung aus
+ und fordert eine Zahlung von diesem Wallet
+ \item[shutdown] Der Betreiber des Taler-Exchange informiert die Inhaber von
+ Coins, die diese von jenem Exchange abgehoben hatten, dass der Exchange
+ geplant eingestellt und die Gegenwerte der Coins restituiert werden
+\end{description}
+
+Die Nutzer beginnen ein gesch\"aftliches Nutzungsverh\"altnis mit
+\TALER{}, wenn sie ihre Taler-Wallets anweisen, eine Abhebung durchzuf\"uhren.
+Das Taler-Bezahlsystem verwendet jedoch keine Konten, sondern wert-basierte
+Token und explizit keine konten-basierten Geld-\"Aquivalente.
+Taler soll digitales Bargeld sein und erlaubt technisch bedingt
+kein Nachvollziehen der Transaktionen seiner Nutzer, wie es Konten mit
+Eing\"angen und Ausg\"angen von Zahlungen erm\"oglichen w\"urden.
+Es gibt daher kein ``Er\"offnen'' oder ``Schliessen'' von Konten der Nutzer.
+Die Begriffe ``opening'' und ``closing'' lassen sich deshalb auch nicht auf
+das System anwenden oder \"ubertragen. \\
+
+Die Nutzer k\"onnen
+\begin{enumerate}[noitemsep]
+\item die treuh\"andisch verwalteten Einlagen gezielt auf ein bestimmtes
+Bankkonto auszahlen lassen,
+%(siehe Abschnitt~\ref{sec:deposit})
+\item an einen Verk\"aufer zahlen,
+%(siehe Abschnitt~\ref{sec:deposit})
+\item einem anderen Empf\"anger mittels peer-to-peer-Verfahren Coins zukommen
+lassen
+%(siehe Abschnitte~\ref{sec:push} und~\ref{sec:pull})
+\item die Coins in ihrem Wallet, das verloren ging oder zerst\"ort wurde,
+durch Ablauf der G\"ultigkeit entwerten lassen (dies w\"are ebenso der Fall
+bei einer langen Zeit ohne Internet-Anbindung oder ohne Installation),
+\item den Wert der Coins im Wallet durch Zahlung von Geb\"uhren f\"ur
+die Verl\"angerung ihrer G\"ultigkeit langsam verringern lassen.
+%(siehe Abschnitt~\ref{sec:fees:coin})
+\end{enumerate}
+
+Das Taler-Bezahlsystem verwehrt den Nutzern kategorisch die Abhebung
+von h\"oheren Betr\"agen als 5.000 \CURRENCY{} pro Monat bzw. von
+mehr als 15.000 \CURRENCY{} pro Jahr. Damit wird gew\"ahrleistet,
+dass die Nutzer stets unterhalb der Grenzwerte bleiben, ab denen die
+meisten Pr\"ufschritte aufgrund regulatorischer Bestimmungen erforderlich
+werden. \TALER{} stellt dar\"uber hinaus sicher, dass die Nutzer
+ausschliesslich in \LAND{} ans\"assig sind
+(siehe Abschnitt~\ref{sec:proc:domestic}), da auf ihrer Seite ein Bankkonto
+in \LAND{} f\"ur die \"Uberweisungen an den Taler-Exchange und/oder
+eine Telefonnummer mit entsprechender Vorwahl (++41) ben\"otigt werden.
+Zus\"atzlich setzt das Taler-Wallet zu jeder Zeit eine Obergrenze
+von 5.000 \CURRENCY{} auf die Coin-Betr\"age in Summe fest, so dass es
+keine weitere Abhebung \"uber diesen Grenzwert hinaus bewirken kann.
+
+F\"ur {\bf Verk\"aufer} beginnt ein gesch\"aftliches Nutzungsverh\"altnis
+mit \TALER{}, sobald sie Geldeing\"ange auf ihren IBAN-Bankkonten erhalten,
+die als Zahlungen von Nutzern des Taler-Bezahlsystems ausgel\"ost wurden
+(siehe Abschnitt~\ref{sec:deposit}). Sollten die Summen der Eing\"ange
+5.000 \CURRENCY{} pro Monat bzw. 15.000 \CURRENCY{} pro Jahr \"ubersteigen,
+kommt es zu einer KYB-Pr\"ufung, die dem Begriff ``Er\"offnen'' eines
+Kontos entspricht und die eine aktualisierte KYB-Information sowie
+die Pr\"ufung von Sanktionslisten erfordert, sofern der Verk\"aufer
+innerhalb von 24 Monaten wenigstens einen Geldeingang erhielt.
+
+Im Gegensatz zu normalen Nutzern k\"onnen Verk\"aufer im Prinzip
+Zahlungen ohne Limit empfangen. Allerdings m\"ussen diese Transaktionen
+auch wirklich als Eing\"ange auf dem Bankkonto des Unternehmens verzeichnet
+werden (im Kontoauszug). In Abh\"angigkeit von den an das Gesch\"aftskonto
+\"uberwiesenen Betr\"agen wird der Verk\"aufer einer KYB-Pr\"ufung unterzogen
+(siehe Abschnitt~\ref{sec:KYB}). Dies gilt ebenso f\"ur
+Geldw\"asche-\"Uberpr\"ufungen (AML checks).
+
+Das Taler-Bezahlsystem transferiert lediglich Gelder auf die bestehenden
+Bankkonten der Verk\"aufer, die f\"ur ihre G\"uterleistungen Zahlungen
+der Nutzer erhalten, f\"ur die bereits bei der \"Uberweisung von deren
+Kundenkonten eine KYC-Pr\"ufung erfolgte. Daher wird unseres Erachtens
+der Betreiber eines Taler-Exchange keine Mittelherkunft verlangen bzw.
+nachweisen m\"ussen
+\footnote{Wenn Unternehmen das Taler-Bezahlsystem ihrerseits f\"ur
+Zahlungen nutzen wollen, m\"ussen sie genauso wie alle anderen Nutzer
+zuerst Geld von ihrem Bankkonto an einen Taler-Exchange \"uberweisen,
+eine KYC-Pr\"ufung absolvieren und dann ihr Wallet Coins abheben lassen.
+F\"ur die gesch\"aftlichen K\"aufer gelten ebenfalls die Limits wie
+f\"ur alle anderen Nutzer.}.
+
+
+\include{int-withdraw}
+\include{int-deposit}
+\include{int-pay}
+\include{int-refund}
+\include{int-push}
+\include{int-pull}
+\include{int-shutdown}
+
+
+
+\chapter{Regulatory Triggers} \label{chap:triggers}
+
+In this chapter we show decision diagrams for regulatory processes of the
+various core operations of the GNU Taler payment system. In each case, the
+{\bf start} state refers to one of the interactions described in the previous
+chapter. The payment system will then use the process to arrive at an {\bf
+ allow} decision which permits the transaction to go through, or at a {\bf
+ deny} decision which ensures that the funds are not moved.
+
+The specific {\em decisions} (in green) depend on the risk profile and the
+regulatory environment. The tables in each section list the specific values
+that are to be configured.
+
+There are five types if interactions that can trigger regulatory processes:
+
+\begin{description}
+ \item[withdraw] a customer withdraws digital cash from their {\bf bank account}
+ \item[deposit] a merchant's {\bf bank account} is designated to receive a payment in digital cash
+ \item[push] a {\bf wallet} accepts a payment from another wallet
+ \item[pull] a {\bf wallet} requests a payment from another wallet
+ \item[balance] a withdraw or P2P payment causes the balance of a {\bf wallet} to exceed a given threshold
+\end{description}
+
+We note in bold the {\bf anchor} for the regulator process. The anchor is used
+to link the interaction to an identity. Once an identity has been established
+for a particular anchor, that link is considered established for all types of
+activities involving that anchor. A wallet is uniquely identified in the
+system by its unique cryptographic key. A bank account is uniquely identified
+in the system by its (RFC 8905) bank routing data (usually including BIC, IBAN
+and account owner name).
+
+The KYC and AML processes themselves are described in
+Chapter~\ref{chap:regproc}.
+
+\include{kyc-withdraw}
+\include{kyc-deposit}
+\include{kyc-push}
+\include{kyc-pull}
+\include{kyc-balance}
+
+\chapter{Regulatory Processes} \label{chap:regproc}
+
+This chapter describes the interactions between the customer, exchange and
+organizations or staff assisting with regulatory processes designed to ensure
+that customers are residents in the area of operation of the payment service
+provider, are properly identified, and do not engage in money laundering.
+
+The three main regulatory processes are:
+
+\begin{description}
+\item[domestic check] This process establishes that a user is generally
+ eligible to use the payment system. The process checks that the user has an
+ eligible address, but stops short of establishing the user's identity.
+\item[kyc] This process establishes a user's legal identity, possibly
+ using external providers to review documents and check against blacklists.
+\item[aml] The AML process reviews suspicious payment activities for
+ money laundering. Here AML staff reviews all collected information.
+\end{description}
+
+\include{proc-domestic}
+%\include{proc-kyc}
+\include{proc-kyb}
+\include{proc-aml}
+
+\chapter{Fees} \label{chap:fees}
+
+The business model for operating a Taler exchange is to charge transaction
+fees. Fees are charged on certain operations by the exchange. There are two
+types of fees, {\bf wire fees} and {\bf coin fees}. This chapter describes
+the fee structure.
+
+Fixed, amount-independent {\bf wire fees} are charged on wire transfers using
+the core banking system. Details on wire fees are described in
+Section~\ref{sec:fees:wire}.
+
+Coin fees are more complex, as they do not exactly follow neither the usual
+percentage of volume model of other payment systems. Instead, coin fees are
+applied per coin, resulting in a {\em logarithmic} fee structure. As a
+result, the effective fee {\em percentage} for tiny transactions is high (for
+example 50\% for transactions of 0.0025 CHF) while the effective fee
+percentage for large transactions is nominal (for example $\approx$ 0.05\% for
+transactions of $\approx$ 40 CHF). Details on coin fees are described in
+Section~\ref{sec:fees:coin}.
+
+Fees are configurable (and that fee types beyond those described here are
+supported by the software). Thus, the specific fees may be adjusted in the
+future based on business decisions. However, changes to the fees are never
+retroactively applied to coins already in circulation. Wire fees that have
+been publicly announced for a particular time period also cannot be changed.
+Finally, any change to the terms of service must also be explicitly accepted
+by the users before they withdraw additional funds.
+
+
+\include{fees-wire}
+\include{fees-coins}
+%\include{fees-other}
+
+
+\end{document}
diff --git a/doc/flows/main.tex b/doc/flows/main.tex
new file mode 100644
index 000000000..d46d93251
--- /dev/null
+++ b/doc/flows/main.tex
@@ -0,0 +1,206 @@
+\documentclass[10pt,a4paper,oneside]{book}
+\usepackage[utf8]{inputenc}
+\usepackage{url}
+\usepackage{graphicx}
+\usepackage{hyperref}
+\usepackage{qrcode}
+\usepackage{pgf-umlsd}
+\usepackage{tikz}
+\usetikzlibrary{shapes,arrows}
+\usetikzlibrary{positioning}
+\usetikzlibrary{calc}
+\usetikzlibrary{quotes}
+\author{Christian Grothoff}
+\title{Flows in the GNU Taler System}
+
+\newcommand\CURRENCY{CHF}
+
+\begin{document}
+
+\maketitle
+\tableofcontents
+
+\chapter{Interactions} \label{chap:interactions}
+
+This chapter introduces the main payment interactions in the GNU Taler payment
+system. For each interaction, we introduce the parties involved and in which
+order they interact and how. In each interaction it is possible that the
+Taler exchange needs to trigger a compliance process. These regulatory
+riggers are described in more detail in Chapter~\ref{chap:triggers}.
+
+The main interactions of the system are:
+
+\begin{description}
+ \item[withdraw] a customer withdraws digital cash to their wallet
+ \item[deposit] a customer returns digital cash into their bank account
+ \item[pay] a customer pays into bank account of a merchant
+ \item[refund] a merchant decides to return funds to a customer
+ \item[push] a customer sends a payment to another wallet
+ \item[pull] a customer requests a payment from another wallet (effectively sending an invoice)
+ \item[shutdown] the Taler payment system operator informs the customers that the system is being shut down for good
+\end{description}
+
+In the analysis of the legal requirements, it is important to differentiate
+between transactions between wallets (customer-to-customer) and transactions
+where money flows from a wallet into a bank account (customer-to-merchant) as
+these have different limits: When digital coins are used to pay at a business in
+Taler, the business never actually receives usable digital coins but instead
+the amount is always directly credited to their bank account. Depending on
+the transacted amounts, the business will nevertheless be subject to KYB
+(Section~\ref{sec:proc:kyb}) and AML checks.
+
+{\bf Customers} begin their business relationship with us when they withdraw
+digital cash. Taler has no accounts (this is digital cash) and thus there is
+no ``opening'' or ``closing'' of accounts for consumers. Given digital cash,
+the customers can either (1) deposit the funds explicitly into a bank account
+(see Section~\ref{sec:deposit}), (2) pay a merchant (see
+Section~\ref{sec:pay}), (3) pay another customer using a peer-to-peer
+transfer (see Sections~\ref{sec:push} and~\ref{sec:pull}), or (4) the coins
+will expire if the wallet was lost (including offline for a long time or
+uninstalled). Finally, if a wallet remains (occasionally) online but a user
+does simply not spend the coins will (5) diminish in value from the change
+fees (see Section~\ref{sec:fees:coin}) that apply to prevent the coins from
+expiring outright.
+
+For customers, we will categorically limit of digital cash withdrawn per month
+to less than CHF 5'000 per month and less than CHF 15'000 per year, thus
+ensuring that consumers remain below the thresholds where most regulatory
+processes become applicable. Payments between users will be limited
+to receiving less than CHF 2'500 per month and less than CHF 15'000 per year.
+We will ensure that customers are Swiss
+(see Section~\ref{sec:proc:domestic}) by requiring them to have a Swiss bank
+account and/or a Swiss phone number (+41-prefix).
+%Furthermore, the wallet will
+%impose an upper limit of CHF 5000 on its balance at any point in time.
+
+For {\bf merchants}, the Taler equivalent of ``opening'' an account and thus
+establishing an ongoing business relationship is for a business to receive
+payments (see Section~\ref{sec:pay}) exceeding CHF 5'000/month or CHF
+15'000/year. We will consider the account ``open'' (and require up-to-date KYB
+information and check sanction lists) as long as the business has made any
+transactions within the last 24 months.
+
+As we will only transfer money into the existing bank accounts of the
+merchants to compensate them for sales made using the Taler payment system, we
+do not need to check the origin of funds for those merchants as they will only
+receive funds from us.\footnote{Should businesses want to use Taler for
+expenditures, they will need to withdraw digital coins from their bank account
+just like customers, and the limits for customers will continue to apply.}
+
+For individual {\bf transactions}, we will impose a limit of CHF
+1'000/transaction (even though our reading of the regulations would permit
+individual transactions up to CHF 15'000).
+
+The following sections describe the respective processes for each of these
+interactions.
+
+\include{int-withdraw}
+\include{int-deposit}
+\include{int-pay}
+\include{int-refund}
+\include{int-push}
+\include{int-pull}
+\include{int-shutdown}
+
+
+\chapter{Regulatory Triggers} \label{chap:triggers}
+
+In this chapter we show decision diagrams for regulatory processes of the
+various core operations of the GNU Taler payment system. In each case, the
+{\bf start} state refers to one of the interactions described in the previous
+chapter. The payment system will then use the process to arrive at an {\bf
+ allow} decision which permits the transaction to go through, or at a {\bf
+ deny} decision which ensures that the funds are not moved.
+
+The specific {\em decisions} (in green) depend on the risk profile and the
+regulatory environment. The tables in each section list the specific values
+that are to be configured.
+
+There are five types if interactions that can trigger regulatory processes:
+
+\begin{description}
+ \item[withdraw] a customer withdraws digital cash from their {\bf bank account}
+ \item[deposit] a customer or merchant's {\bf bank account} is
+ designated to receive a payment due someone paying with or
+ depositing digital cash
+ \item[push] a {\bf wallet} accepts a payment from another wallet
+ \item[pull] a {\bf wallet} requests a payment from another wallet
+% \item[balance] a withdraw or P2P payment causes the balance of a {\bf wallet} to exceed a given threshold
+\end{description}
+
+We note in bold the {\bf anchor} for the regulator process. The anchor is used
+to link the interaction to an identity. Once an identity has been established
+for a particular anchor, that link is considered established for all types of
+activities involving that anchor. A wallet is uniquely identified in the
+system by its unique cryptographic key. A bank account is uniquely identified
+in the system by its (RFC 8905) bank routing data (usually including BIC, IBAN
+and account owner name).
+
+The KYC and AML processes themselves are described in
+Chapter~\ref{chap:regproc}.
+
+\include{kyc-withdraw}
+\include{kyc-deposit}
+\include{kyc-push}
+\include{kyc-pull}
+%\include{kyc-balance}
+
+\chapter{Regulatory Processes} \label{chap:regproc}
+
+This chapter describes the interactions between the customer, exchange and
+organizations or staff assisting with regulatory processes designed to ensure
+that customers are residents in the area of operation of the payment service
+provider, are properly identified, and do not engage in money laundering.
+
+The three main regulatory processes are:
+
+\begin{description}
+\item[domestic check] This process establishes that a user is generally
+ eligible to use the payment system. The process checks that the user has an
+ eligible address, but stops short of establishing the user's identity.
+\item[kyc] This process establishes a user's legal identity, possibly
+ using external providers to review documents and check against blacklists.
+\item[aml] The AML process reviews suspicious payment activities for
+ money laundering. Here AML staff reviews all collected information.
+\end{description}
+
+\include{proc-domestic}
+\include{proc-kyc}
+\include{proc-kyb}
+\include{proc-aml}
+
+\chapter{Fees} \label{chap:fees}
+
+The business model for operating a Taler exchange is to charge transaction
+fees. Fees are charged on certain operations by the exchange. There are two
+types of fees, {\bf wire fees} and {\bf coin fees}. This chapter describes
+the fee structure.
+
+Fixed, amount-independent {\bf wire fees} are charged on wire transfers using
+the core banking system. Details on wire fees are described in
+Section~\ref{sec:fees:wire}.
+
+Coin fees are more complex, as they do not exactly follow neither the usual
+percentage of volume model of other payment systems. Instead, coin fees are
+applied per coin, resulting in a {\em logarithmic} fee structure. As a
+result, the effective fee {\em percentage} for tiny transactions is high (for
+example 50\% for transactions of 0.0025 CHF) while the effective fee
+percentage for large transactions is nominal (for example $\approx$ 0.05\% for
+transactions of $\approx$ 40 CHF). Details on coin fees are described in
+Section~\ref{sec:fees:coin}.
+
+Fees are configurable (and that fee types beyond those described here are
+supported by the software). Thus, the specific fees may be adjusted in the
+future based on business decisions. However, changes to the fees are never
+retroactively applied to coins already in circulation. Wire fees that have
+been publicly announced for a particular time period also cannot be changed.
+Finally, any change to the terms of service must also be explicitly accepted
+by the users before they withdraw additional funds.
+
+
+\include{fees-wire}
+\include{fees-coins}
+%\include{fees-other}
+
+
+\end{document}
diff --git a/doc/flows/proc-aml.tex b/doc/flows/proc-aml.tex
new file mode 100644
index 000000000..04700faf8
--- /dev/null
+++ b/doc/flows/proc-aml.tex
@@ -0,0 +1,47 @@
+\section{AML process}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Action};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{staff}{\shortstack{AML staff \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Access \\ Token};
+ \end{tikzpicture}
+ }}
+ \postlevel
+ \mess[0]{wallet}{{Initial action}}{exchange}
+ \begin{callself}{exchange}{Establish AML requirement}{}
+ \end{callself}
+ \begin{callself}{exchange}{Queue AML task}{}
+ \end{callself}
+ \mess[0]{exchange}{Wait for AML}{wallet}
+ \mess[0]{staff}{Request AML work}{exchange}
+ \mess[0]{exchange}{{Open AML task(s)}}{staff}
+ \mess[0]{staff}{Request details}{exchange}
+ \mess[0]{exchange}{KYC/AML data}{staff}
+ \begin{callself}{staff}{Review and decide}{}
+ \end{callself}
+ \mess[0]{staff}{{Decision documentation}}{exchange}
+ \mess[0]{exchange}{AML decision}{wallet}
+ \mess[0]{wallet}{{Retry action}}{exchange}
+\end{sequencediagram}
+ \caption{Deposit interactions between customer, Taler exchange (payment
+ service provider) and the AML staff. The process can be
+ triggered by various {\em actions} described in Chapter~\ref{chap:triggers}.
+ AML staff interactions are cryptographically secured and
+ decisions and the provided reasoning are archived by the exchange.
+ AML staff may interact with the customer (out-of-band)
+ in its decision process.
+ }
+ \label{fig:proc:aml}
+\end{figure}
diff --git a/doc/flows/proc-domestic.tex b/doc/flows/proc-domestic.tex
new file mode 100644
index 000000000..f3a1b7b18
--- /dev/null
+++ b/doc/flows/proc-domestic.tex
@@ -0,0 +1,66 @@
+\section{Domestic wallet check} \label{sec:proc:domestic}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer wallet \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Wallet ID};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{sms}{\shortstack{Address validator}}
+
+ \postlevel
+ \mess[0]{wallet}{{P2P payment (Wallet ID)}}{exchange}
+ \begin{callself}{exchange}{New wallet?}{}
+ \end{callself}
+ \mess[0]{exchange}{Request address validation}{sms}
+ \mess[0]{sms}{Validation process ID}{exchange}
+ \mess[0]{exchange}{Request address validation}{wallet}
+ \mess[0]{wallet}{Send address}{sms}
+ \mess[0]{sms}{{Send confirmation code (to address)}}{wallet}
+ \mess[0]{wallet}{Supply confirmation code}{sms}
+ \mess[0]{sms}{{Confirmed customer address}}{exchange}
+ \mess[0]{exchange}{{Confirm completion}}{wallet}
+ \mess[0]{wallet}{{Retry action}}{exchange}
+\end{sequencediagram}
+ \caption{Deposit interactions between customer, Taler exchange (payment
+ service provider) and external address validation service. The process can be
+ triggered by wallet-to-wallet (P2P) payments described in Chapter~\ref{chap:triggers}.}
+ \label{fig:proc:domestic}
+\end{figure}
+
+Our users have to accept the terms of service which restrict the use of the
+service to domestic customers. For interactions with the core banking system,
+this simply means that we only accept payments from or to domestic bank
+accounts. For P2P payments between wallets, we require that the wallets are
+controlled by a domestic entity. We define domestic entities as those that
+are able to receive messages at a domestic address. Two types of addresses are
+supported:
+
+\begin{itemize}
+\item Control over a domestic {\bf mobile phone number} is established
+ by sending an SMS message with a confirmation code to the MSIN.
+\item Control over a domestic {\bf postal address} is established by
+ sending a letter with a confirmation code to the address.
+\end{itemize}
+
+Depending on the type of address, a validation has a limited validity period,
+as shown in Table~\ref{table:proc:domestic}. When the validity period is
+over, a wallet has to re-do the address validation before they can receive any
+further funds through the service.
+
+\begin{table}[h!]
+ \caption{Restrictions on address validations}
+ \label{table:proc:domestic}
+ \begin{tabular}{l|l|r}
+ {\bf Type} & {\bf Validity period} & {\bf Restricted to} \\ \hline \hline
+ Mobile phone number & 12 months & {\em +41} \\
+ Postal address & 36 months & {\em Switzerland} \\
+ \end{tabular}
+\end{table}
diff --git a/doc/flows/proc-kyb.tex b/doc/flows/proc-kyb.tex
new file mode 100644
index 000000000..6c84f414c
--- /dev/null
+++ b/doc/flows/proc-kyb.tex
@@ -0,0 +1,98 @@
+\section{KYB process} \label{sec:proc:kyb}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{merchant}{\shortstack{Merchant \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Action};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{kyb}{\shortstack{KYB provider \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+
+ \postlevel
+ \mess[0]{merchant}{{Initial action}}{exchange}
+ \begin{callself}{exchange}{Establish KYB requirement}{}
+ \end{callself}
+ \mess[0]{exchange}{Request new KYB process}{kyb}
+ \mess[0]{kyb}{{Process identifier (PI)}}{exchange}
+ \mess[0]{exchange}{{KYB required (PI)}}{merchant}
+ \mess[0]{merchant}{{KYB start (PI)}}{kyb}
+ \mess[0]{kyb}{{Request identity documentation}}{merchant}
+ \mess[0]{merchant}{{Upload identity documentation}}{kyb}
+ \begin{callself}{kyb}{Validate documentation}{}
+ \end{callself}
+ \mess[0]{kyb}{{Share documentation (PI)}}{exchange}
+ \mess[0]{kyb}{{Confirm completion}}{merchant}
+ \mess[0]{merchant}{{Retry action}}{exchange}
+\end{sequencediagram}
+ \caption{Deposit interactions between customer, Taler exchange (payment
+ service provider) and external KYB provider. The process can be
+ triggered by various {\em actions} described in Chapter~\ref{chap:triggers}.}
+ \label{fig:proc:kyb}
+\end{figure}
+
+At the beginning of the KYB process, the user needs to specify whether they
+are an {\bf individual} (not incorporated) or a {\bf business}.\footnote{In
+practice, we expect most owners of bank accounts crossing the KYB threshold to
+be businesses, but in principle such a bank account could be owned by an
+individual operating a business without a separate legal entity.} This then
+determines which types of attributes are collected in the KYB process
+(Table~\ref{table:proc:kyb:individual}
+vs. Table~\ref{table:proc:kyb:business}).
+
+\begin{table}
+ \caption{Information collected for unincorporated individuals}
+ \label{table:proc:kyb:individual}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Type} & {\bf Required} & {\bf Example} \\ \hline \hline
+ Surname & yes & Mustermann \\
+ First name(s) & yes & Max \\
+ Date of birth & yes & 1.1.1980 \\
+ Nationality & yes & Swiss \\
+ Actual address of domicile & yes & Seestrasse 3, 8008 Zuerich \\
+ Phone number & no & +41-123456789 \\
+ E-mail & no & me@example.com \\
+ Identification document & yes & JPG image \\
+ Taxpayer identification & yes & ZPV Nr. 253'123'456 \\
+ \end{tabular}
+ \end{center}
+\end{table}
+
+
+\begin{table}
+ \caption{Information collected for businesses. Information on individals is
+ collected for owners with more than 25\% ownership and for those with
+ signature authority for the business.}
+ \label{table:proc:kyb:business}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Type} & {\bf Required} & {\bf Example} \\ \hline \hline
+ Company name & yes & Mega AG \\
+ Registered office & yes & Seestrasse 4, 8008 Zuerich \\
+ Company identification document & yes & PDF file \\
+ Power of attorney arrangement & yes & PDF file \\
+ Business registration number & yes & \\
+ Business registration document & yes & PDF file \\
+ Registration authority & yes & \\ \hline
+ Authorized person name & yes & Max Mustermann \\
+ Share/authorization certification & yes & PDF file \\
+ Identification document & yes & JPG image \\
+ Date of birth & yes & 1.1.1980 \\
+ Nationality & yes & Swiss \\
+ E-mail & yes & me@example.com \\
+ Phone number & no & +41-123456789 \\
+ \end{tabular}
+ \end{center}
+\end{table}
diff --git a/doc/flows/proc-kyc.tex b/doc/flows/proc-kyc.tex
new file mode 100644
index 000000000..87465f44c
--- /dev/null
+++ b/doc/flows/proc-kyc.tex
@@ -0,0 +1,88 @@
+\section{KYC process}
+
+\begin{figure}[h!]
+ \begin{sequencediagram}
+ \newinst{wallet}{\shortstack{Customer \\
+ \\ \begin{tikzpicture}
+ \node [fill=gray!20,draw=black,thick,align=center] { Unique \\ Action};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{exchange}{\shortstack{Taler (exchange) \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+ \newinst[2]{kyc}{\shortstack{KYC provider \\
+ \\ \begin{tikzpicture}[shape aspect=.5]
+ \tikzset{every node/.style={cylinder,shape border rotate=90, draw,fill=gray!25}}
+ \node at (1.5,0) {\shortstack{{{\tiny Database}}}};
+ \end{tikzpicture}
+ }}
+
+ \postlevel
+ \mess[0]{wallet}{{Initial action}}{exchange}
+ \begin{callself}{exchange}{Establish KYC requirement}{}
+ \end{callself}
+ \mess[0]{exchange}{Request new KYC process}{kyc}
+ \mess[0]{kyc}{{Process identifier (PI)}}{exchange}
+ \mess[0]{exchange}{{KYC required (PI)}}{wallet}
+ \mess[0]{wallet}{{KYC start (PI)}}{kyc}
+ \mess[0]{kyc}{{Request identity documentation}}{wallet}
+ \mess[0]{wallet}{{Upload identity documentation}}{kyc}
+ \begin{callself}{kyc}{Validate documentation}{}
+ \end{callself}
+ \mess[0]{kyc}{{Share documentation (PI)}}{exchange}
+ \mess[0]{kyc}{{Confirm completion}}{wallet}
+ \mess[0]{wallet}{{Retry action}}{exchange}
+\end{sequencediagram}
+ \caption{Deposit interactions between customer, Taler exchange (payment
+ service provider) and external KYC provider. The process can be
+ triggered by various {\em actions} described in Chapter~\ref{chap:triggers}.}
+ \label{fig:proc:kyc}
+\end{figure}
+
+At the beginning of the KYC process, the user needs to specify whether they
+are an {\bf individual} or a {\bf business}.\footnote{ In practice, we expect
+most wallet-users to be individuals, but in principle a wallet could be owned
+by a business.} This then determines which types of attributes are collected
+in the KYC process (Table~\ref{table:proc:kyc:individual} vs.
+Table~\ref{table:proc:kyc:business}).
+
+\begin{table}
+ \caption{Information collected for individuals}
+ \label{table:proc:kyc:individual}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Type} & {\bf Required} & {\bf Example} \\ \hline \hline
+ Surname & yes & Mustermann \\
+ First name(s) & yes & Max \\
+ Date of birth & yes & 1.1.1980 \\
+ Nationality & yes & Swiss \\
+ Actual address of domicile & yes & Seestrasse 3, 8008 Zuerich \\
+ Phone number & no & +41-123456789 \\
+ E-mail & no & me@example.com \\
+ Identification document & yes & JPG image \\
+ \end{tabular}
+ \end{center}
+\end{table}
+
+\begin{table}
+ \caption{Information collected for businesses}
+ \label{table:proc:kyc:business}
+ \begin{center}
+ \begin{tabular}{l|c|r}
+ {\bf Type} & {\bf Required} & {\bf Example} \\ \hline \hline
+ Company name & yes & Mega AG \\
+ Registered office & yes & Seestrasse 4, 8008 Zuerich \\
+ Company identification document & yes & PDF file \\ \hline
+ Contact person name & yes & Max Mustermann \\
+ Phone number & no & +41-123456789 \\
+ E-mail & yes & me@example.com \\
+ Identification document & yes & JPG image \\
+ Date of birth & yes & 1.1.1980 \\
+ Nationality & yes & Swiss \\ \hline
+ Power of attorney arrangement & yes & PDF file \\
+ \end{tabular}
+ \end{center}
+\end{table}
diff --git a/doc/prebuilt b/doc/prebuilt
-Subproject 1ed97b23f19c80fa84b21a5eb0c686d5491e8ec
+Subproject b8d2d2fa2ed2a771880f451725176f256583cb2
diff --git a/doc/system/taler/implementation.tex b/doc/system/taler/implementation.tex
index 9d7cb9a9e..e7d8b9dc7 100644
--- a/doc/system/taler/implementation.tex
+++ b/doc/system/taler/implementation.tex
@@ -1179,7 +1179,7 @@ Section~\ref{sec:compromised-signing-key-detection}.
In the future, we plan for the auditor to expose additional endpoints where
wallets and merchant backends can submit (cryptographic) proofs of
-missbehavior from an exchange. The goal would be to automatically verify the
+misbehavior from an exchange. The goal would be to automatically verify the
proofs, take corrective action by including the information in the audit
report and possibly even compensating the victim.
diff --git a/m4/libgnurl.m4 b/m4/libgnurl.m4
deleted file mode 100644
index 412709373..000000000
--- a/m4/libgnurl.m4
+++ /dev/null
@@ -1,266 +0,0 @@
-# LIBGNURL_CHECK_CONFIG ([DEFAULT-ACTION], [MINIMUM-VERSION],
-# [ACTION-IF-YES], [ACTION-IF-NO])
-# ----------------------------------------------------------
-# David Shaw <dshaw@jabberwocky.com> May-09-2006
-#
-# Checks for libgnurl. DEFAULT-ACTION is the string yes or no to
-# specify whether to default to --with-libgnurl or --without-libgnurl.
-# If not supplied, DEFAULT-ACTION is yes. MINIMUM-VERSION is the
-# minimum version of libgnurl to accept. Pass the version as a regular
-# version number like 7.10.1. If not supplied, any version is
-# accepted. ACTION-IF-YES is a list of shell commands to run if
-# libgnurl was successfully found and passed the various tests.
-# ACTION-IF-NO is a list of shell commands that are run otherwise.
-# Note that using --without-libgnurl does run ACTION-IF-NO.
-#
-# This macro #defines HAVE_LIBGNURL if a working libgnurl setup is
-# found, and sets @LIBGNURL@ and @LIBGNURL_CPPFLAGS@ to the necessary
-# values. Other useful defines are LIBGNURL_FEATURE_xxx where xxx are
-# the various features supported by libgnurl, and LIBGNURL_PROTOCOL_yyy
-# where yyy are the various protocols supported by libgnurl. Both xxx
-# and yyy are capitalized. See the list of AH_TEMPLATEs at the top of
-# the macro for the complete list of possible defines. Shell
-# variables $libgnurl_feature_xxx and $libgnurl_protocol_yyy are also
-# defined to 'yes' for those features and protocols that were found.
-# Note that xxx and yyy keep the same capitalization as in the
-# gnurl-config list (e.g. it's "HTTP" and not "http").
-#
-# Users may override the detected values by doing something like:
-# LIBGNURL="-lgnurl" LIBGNURL_CPPFLAGS="-I/usr/myinclude" ./configure
-#
-# For the sake of sanity, this macro assumes that any libgnurl that is
-# found is after version 7.7.2, the first version that included the
-# gnurl-config script. Note that it is very important for people
-# packaging binary versions of libgnurl to include this script!
-# Without gnurl-config, we can only guess what protocols are available,
-# or use gnurl_version_info to figure it out at runtime.
-
-AC_DEFUN([LIBGNURL_CHECK_CONFIG],
-[
- AH_TEMPLATE([LIBGNURL_FEATURE_SSL],[Defined if libgnurl supports SSL])
- AH_TEMPLATE([LIBGNURL_FEATURE_KRB4],[Defined if libgnurl supports KRB4])
- AH_TEMPLATE([LIBGNURL_FEATURE_IPV6],[Defined if libgnurl supports IPv6])
- AH_TEMPLATE([LIBGNURL_FEATURE_LIBZ],[Defined if libgnurl supports libz])
- AH_TEMPLATE([LIBGNURL_FEATURE_ASYNCHDNS],[Defined if libgnurl supports AsynchDNS])
- AH_TEMPLATE([LIBGNURL_FEATURE_IDN],[Defined if libgnurl supports IDN])
- AH_TEMPLATE([LIBGNURL_FEATURE_SSPI],[Defined if libgnurl supports SSPI])
- AH_TEMPLATE([LIBGNURL_FEATURE_NTLM],[Defined if libgnurl supports NTLM])
-
- AH_TEMPLATE([LIBGNURL_PROTOCOL_HTTP],[Defined if libgnurl supports HTTP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_HTTPS],[Defined if libgnurl supports HTTPS])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_FTP],[Defined if libgnurl supports FTP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_FTPS],[Defined if libgnurl supports FTPS])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_FILE],[Defined if libgnurl supports FILE])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_TELNET],[Defined if libgnurl supports TELNET])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_LDAP],[Defined if libgnurl supports LDAP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_DICT],[Defined if libgnurl supports DICT])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_TFTP],[Defined if libgnurl supports TFTP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_RTSP],[Defined if libgnurl supports RTSP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_POP3],[Defined if libgnurl supports POP3])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_IMAP],[Defined if libgnurl supports IMAP])
- AH_TEMPLATE([LIBGNURL_PROTOCOL_SMTP],[Defined if libgnurl supports SMTP])
-
- AC_ARG_WITH(libgnurl,
- AS_HELP_STRING([--with-libgnurl=PREFIX],[look for the gnurl library in PREFIX/lib and headers in PREFIX/include]),
- [_libgnurl_with=$withval],[_libgnurl_with=ifelse([$1],,[yes],[$1])])
-
- if test "$_libgnurl_with" != "no" ; then
-
- AC_PROG_AWK
-
- _libgnurl_version_parse="eval $AWK '{split(\$NF,A,\".\"); X=256*256*A[[1]]+256*A[[2]]+A[[3]]; print X;}'"
-
- _libgnurl_try_link=yes
-
- if test -d "$_libgnurl_with" ; then
- LIBGNURL_CPPFLAGS="-I$withval/include"
- _libgnurl_ldflags="-L$withval/lib"
- AC_PATH_PROG([_libgnurl_config],[gnurl-config],[],
- ["$withval/bin"])
- else
- AC_PATH_PROG([_libgnurl_config],[gnurl-config],[],[$PATH])
- fi
-
- if test x$_libgnurl_config != "x" ; then
- AC_CACHE_CHECK([for the version of libgnurl],
- [libgnurl_cv_lib_gnurl_version],
- [libgnurl_cv_lib_gnurl_version=`$_libgnurl_config --version | $AWK '{print $[]2}'`])
-
- _libgnurl_version=`echo $libgnurl_cv_lib_gnurl_version | $_libgnurl_version_parse`
- _libgnurl_wanted=`echo ifelse([$2],,[0],[$2]) | $_libgnurl_version_parse`
-
- if test $_libgnurl_wanted -gt 0 ; then
- AC_CACHE_CHECK([for libgnurl >= version $2],
- [libgnurl_cv_lib_version_ok],
- [
- if test $_libgnurl_version -ge $_libgnurl_wanted ; then
- libgnurl_cv_lib_version_ok=yes
- else
- libgnurl_cv_lib_version_ok=no
- fi
- ])
- fi
-
- if test $_libgnurl_wanted -eq 0 || test x$libgnurl_cv_lib_version_ok = xyes ; then
- if test x"$LIBGNURL_CPPFLAGS" = "x" ; then
- LIBGNURL_CPPFLAGS=`$_libgnurl_config --cflags`
- fi
- if test x"$LIBGNURL" = "x" ; then
- LIBGNURL=`$_libgnurl_config --libs`
-
- # This is so silly, but Apple actually has a bug in their
- # gnurl-config script. Fixed in Tiger, but there are still
- # lots of Panther installs around.
- case "${host}" in
- powerpc-apple-darwin7*)
- LIBGNURL=`echo $LIBGNURL | sed -e 's|-arch i386||g'`
- ;;
- esac
- fi
-
- # All gnurl-config scripts support --feature
- _libgnurl_features=`$_libgnurl_config --feature`
-
- # Is it modern enough to have --protocols? (7.12.4)
- if test $_libgnurl_version -ge 461828 ; then
- _libgnurl_protocols=`$_libgnurl_config --protocols`
- fi
- else
- _libgnurl_try_link=no
- fi
-
- unset _libgnurl_wanted
- fi
-
- if test $_libgnurl_try_link = yes ; then
-
- # we didn't find gnurl-config, so let's see if the user-supplied
- # link line (or failing that, "-lgnurl") is enough.
- LIBGNURL=${LIBGNURL-"$_libgnurl_ldflags -lgnurl"}
-
- AC_CACHE_CHECK([whether libgnurl is usable],
- [libgnurl_cv_lib_gnurl_usable],
- [
- _libgnurl_save_cppflags=$CPPFLAGS
- CPPFLAGS="$LIBGNURL_CPPFLAGS $CPPFLAGS"
- _libgnurl_save_libs=$LIBS
- LIBS="$LIBGNURL $LIBS"
-
- AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <curl/curl.h>],[
-/* Try and use a few common options to force a failure if we are
- missing symbols or can't link. */
-int x;
-curl_easy_setopt(NULL,CURLOPT_URL,NULL);
-x=CURL_ERROR_SIZE;
-x=CURLOPT_WRITEFUNCTION;
-x=CURLOPT_FILE;
-x=CURLOPT_ERRORBUFFER;
-x=CURLOPT_STDERR;
-x=CURLOPT_VERBOSE;
-])],libgnurl_cv_lib_gnurl_usable=yes,libgnurl_cv_lib_gnurl_usable=no)
-
-# BEGIN Changes from original libcurl.m4:
-# Give it a 2nd shot using 'gnurl/curl.h'
- AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <gnurl/curl.h>],[
-/* Try and use a few common options to force a failure if we are
- missing symbols or can't link. */
-int x;
-curl_easy_setopt(NULL,CURLOPT_URL,NULL);
-x=CURL_ERROR_SIZE;
-x=CURLOPT_WRITEFUNCTION;
-x=CURLOPT_FILE;
-x=CURLOPT_ERRORBUFFER;
-x=CURLOPT_STDERR;
-x=CURLOPT_VERBOSE;
-])],libgnurl_cv_lib_gnurl_usable=yes)
-# END Changes from original libcurl.m4:
-
- CPPFLAGS=$_libgnurl_save_cppflags
- LIBS=$_libgnurl_save_libs
- unset _libgnurl_save_cppflags
- unset _libgnurl_save_libs
- ])
-
- if test $libgnurl_cv_lib_gnurl_usable = yes ; then
-
- # Does gnurl_free() exist in this version of libgnurl?
- # If not, fake it with free()
-
- _libgnurl_save_cppflags=$CPPFLAGS
- CPPFLAGS="$CPPFLAGS $LIBGNURL_CPPFLAGS"
- _libgnurl_save_libs=$LIBS
- LIBS="$LIBS $LIBGNURL"
-
- AC_CHECK_FUNC(curl_free,,
- AC_DEFINE(curl_free,free,
- [Define curl_free() as free() if our version of gnurl lacks curl_free.]))
-
- CPPFLAGS=$_libgnurl_save_cppflags
- LIBS=$_libgnurl_save_libs
- unset _libgnurl_save_cppflags
- unset _libgnurl_save_libs
-
- AC_DEFINE(HAVE_LIBGNURL,1,
- [Define to 1 if you have a functional gnurl library.])
- AC_SUBST(LIBGNURL_CPPFLAGS)
- AC_SUBST(LIBGNURL)
-
- for _libgnurl_feature in $_libgnurl_features ; do
- AC_DEFINE_UNQUOTED(AS_TR_CPP(libgnurl_feature_$_libgnurl_feature),[1])
- eval AS_TR_SH(libgnurl_feature_$_libgnurl_feature)=yes
- done
-
- if test "x$_libgnurl_protocols" = "x" ; then
-
- # We don't have --protocols, so just assume that all
- # protocols are available
- _libgnurl_protocols="HTTP FTP FILE TELNET LDAP DICT TFTP"
-
- if test x$libgnurl_feature_SSL = xyes ; then
- _libgnurl_protocols="$_libgnurl_protocols HTTPS"
-
- # FTPS wasn't standards-compliant until version
- # 7.11.0 (0x070b00 == 461568)
- if test $_libgnurl_version -ge 461568; then
- _libgnurl_protocols="$_libgnurl_protocols FTPS"
- fi
- fi
-
- # RTSP, IMAP, POP3 and SMTP were added in
- # 7.20.0 (0x071400 == 463872)
- if test $_libgnurl_version -ge 463872; then
- _libgnurl_protocols="$_libgnurl_protocols RTSP IMAP POP3 SMTP"
- fi
- fi
-
- for _libgnurl_protocol in $_libgnurl_protocols ; do
- AC_DEFINE_UNQUOTED(AS_TR_CPP(libgnurl_protocol_$_libgnurl_protocol),[1])
- eval AS_TR_SH(libgnurl_protocol_$_libgnurl_protocol)=yes
- done
- else
- unset LIBGNURL
- unset LIBGNURL_CPPFLAGS
- fi
- fi
-
- unset _libgnurl_try_link
- unset _libgnurl_version_parse
- unset _libgnurl_config
- unset _libgnurl_feature
- unset _libgnurl_features
- unset _libgnurl_protocol
- unset _libgnurl_protocols
- unset _libgnurl_version
- unset _libgnurl_ldflags
- fi
-
- if test x$_libgnurl_with = xno || test x$libgnurl_cv_lib_gnurl_usable != xyes ; then
- # This is the IF-NO path
- ifelse([$4],,:,[$4])
- else
- # This is the IF-YES path
- ifelse([$3],,:,[$3])
- fi
-
- unset _libgnurl_with
-])dnl
diff --git a/src/Makefile.am b/src/Makefile.am
index 5d46850c2..e10ecf8d8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,12 +23,15 @@ SUBDIRS = \
$(PQ_DIR) \
$(SQ_DIR) \
mhd \
+ templating \
bank-lib \
exchangedb \
+ kyclogic \
exchange \
auditordb \
auditor \
lib \
exchange-tools \
+ extensions/age_restriction \
testing \
benchmark
diff --git a/src/auditor/.gitignore b/src/auditor/.gitignore
index 6d25d8bae..11c875dc6 100644
--- a/src/auditor/.gitignore
+++ b/src/auditor/.gitignore
@@ -19,3 +19,10 @@ generate-auditor-basedb-revocation.conf
revocation-tmp-*
auditor-basedb.wdb
taler-auditor-sync
+auditor-basedb.sqlite3
+taler-auditor-test.sqlite3
+libeufin-nexus.pid
+libeufin-sandbox.pid
+taler-helper-auditor-purses
+generate-kyc-basedb.conf.edited
+generate-auditor-basedb.conf.edited
diff --git a/src/auditor/Makefile.am b/src/auditor/Makefile.am
index 6d49da6db..381c0b115 100644
--- a/src/auditor/Makefile.am
+++ b/src/auditor/Makefile.am
@@ -16,12 +16,12 @@ clean-local:
bin_PROGRAMS = \
taler-auditor-dbinit \
- taler-auditor-exchange \
taler-auditor-httpd \
taler-auditor-sync \
taler-helper-auditor-aggregation \
taler-helper-auditor-coins \
taler-helper-auditor-deposits \
+ taler-helper-auditor-purses \
taler-helper-auditor-reserves \
taler-helper-auditor-wire
@@ -65,9 +65,9 @@ taler_auditor_dbinit_CPPFLAGS = \
-I$(top_srcdir)/src/pq/ \
$(POSTGRESQL_CPPFLAGS)
-taler_helper_auditor_reserves_SOURCES = \
- taler-helper-auditor-reserves.c
-taler_helper_auditor_reserves_LDADD = \
+taler_helper_auditor_coins_SOURCES = \
+ taler-helper-auditor-coins.c
+taler_helper_auditor_coins_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
@@ -80,9 +80,9 @@ taler_helper_auditor_reserves_LDADD = \
-lgnunetutil \
$(XLIB)
-taler_helper_auditor_coins_SOURCES = \
- taler-helper-auditor-coins.c
-taler_helper_auditor_coins_LDADD = \
+taler_helper_auditor_aggregation_SOURCES = \
+ taler-helper-auditor-aggregation.c
+taler_helper_auditor_aggregation_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
@@ -95,9 +95,9 @@ taler_helper_auditor_coins_LDADD = \
-lgnunetutil \
$(XLIB)
-taler_helper_auditor_aggregation_SOURCES = \
- taler-helper-auditor-aggregation.c
-taler_helper_auditor_aggregation_LDADD = \
+taler_helper_auditor_deposits_SOURCES = \
+ taler-helper-auditor-deposits.c
+taler_helper_auditor_deposits_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
@@ -110,9 +110,24 @@ taler_helper_auditor_aggregation_LDADD = \
-lgnunetutil \
$(XLIB)
-taler_helper_auditor_deposits_SOURCES = \
- taler-helper-auditor-deposits.c
-taler_helper_auditor_deposits_LDADD = \
+taler_helper_auditor_purses_SOURCES = \
+ taler-helper-auditor-purses.c
+taler_helper_auditor_purses_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \
+ $(top_builddir)/src/auditordb/libtalerauditordb.la \
+ libauditorreport.la \
+ -ljansson \
+ -lgnunetjson \
+ -lgnunetutil \
+ $(XLIB)
+
+taler_helper_auditor_reserves_SOURCES = \
+ taler-helper-auditor-reserves.c
+taler_helper_auditor_reserves_LDADD = \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/json/libtalerjson.la \
@@ -125,6 +140,8 @@ taler_helper_auditor_deposits_LDADD = \
-lgnunetutil \
$(XLIB)
+
+
taler_helper_auditor_wire_SOURCES = \
taler-helper-auditor-wire.c
taler_helper_auditor_wire_LDADD = \
@@ -145,7 +162,7 @@ taler_helper_auditor_wire_LDADD = \
taler_auditor_httpd_SOURCES = \
taler-auditor-httpd.c taler-auditor-httpd.h \
taler-auditor-httpd_deposit-confirmation.c taler-auditor-httpd_deposit-confirmation.h \
- taler-auditor-httpd_exchanges.c taler-auditor-httpd_exchanges.h \
+ taler-auditor-httpd_deposit-confirmation-get.c taler-auditor-httpd_deposit-confirmation-get.h \
taler-auditor-httpd_mhd.c taler-auditor-httpd_mhd.h
taler_auditor_httpd_LDADD = \
$(LIBGCRYPT_LIBS) \
@@ -161,15 +178,6 @@ taler_auditor_httpd_LDADD = \
-lz \
$(XLIB)
-taler_auditor_exchange_SOURCES = \
- taler-auditor-exchange.c
-taler_auditor_exchange_LDADD = \
- $(LIBGCRYPT_LIBS) \
- $(top_builddir)/src/util/libtalerutil.la \
- $(top_builddir)/src/auditordb/libtalerauditordb.la \
- -lgnunetutil \
- $(XLIB)
-
taler_auditor_sync_SOURCES = \
taler-auditor-sync.c
taler_auditor_sync_LDADD = \
@@ -189,29 +197,22 @@ taler_auditor_sync_CPPFLAGS = \
check_SCRIPTS = \
test-auditor.sh \
+ test-kyc.sh \
test-revocation.sh \
test-sync.sh
.NOTPARALLEL:
-# revocation test disabled for now: need working wallet first!
-TESTS = $(check_SCRIPTS)
+# TESTS = $(check_SCRIPTS)
EXTRA_DIST = \
taler-auditor.in \
taler-helper-auditor-render.py \
auditor.conf \
+ setup.sh \
test-sync-in.conf \
test-sync-out.conf \
generate-auditor-basedb.sh \
- generate-revoke-basedb.sh \
generate-auditor-basedb.conf \
- generate-auditor-basedb-template.conf \
- $(check_SCRIPTS) \
- auditor-basedb.age \
- auditor-basedb.conf \
- auditor-basedb.sql \
- auditor-basedb.mpub \
- revoke-basedb.age \
- revoke-basedb.conf \
- revoke-basedb.sql \
- revoke-basedb.mpub
+ generate-kyc-basedb.conf \
+ generate-revoke-basedb.sh \
+ $(check_SCRIPTS)
diff --git a/src/auditor/auditor-basedb.age b/src/auditor/auditor-basedb.age
deleted file mode 100644
index 808d192fe..000000000
--- a/src/auditor/auditor-basedb.age
+++ /dev/null
@@ -1 +0,0 @@
-1655640402
diff --git a/src/auditor/auditor-basedb.conf b/src/auditor/auditor-basedb.conf
deleted file mode 100644
index 5f864849f..000000000
--- a/src/auditor/auditor-basedb.conf
+++ /dev/null
@@ -1,183 +0,0 @@
-[benchmark]
-MERCHANT_DETAILS = merchant_details.json
-BANK_DETAILS = bank_details.json
-
-[coin_kudos_10]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_deposit = TESTKUDOS:0.01
-fee_withdraw = TESTKUDOS:0.01
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:10
-
-[coin_kudos_8]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.04
-fee_refresh = TESTKUDOS:0.03
-fee_deposit = TESTKUDOS:0.02
-fee_withdraw = TESTKUDOS:0.05
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:8
-
-[coin_kudos_5]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_deposit = TESTKUDOS:0.01
-fee_withdraw = TESTKUDOS:0.01
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:5
-
-[coin_kudos_4]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.02
-fee_refresh = TESTKUDOS:0.04
-fee_deposit = TESTKUDOS:0.03
-fee_withdraw = TESTKUDOS:0.03
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:4
-
-[coin_kudos_2]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.02
-fee_refresh = TESTKUDOS:0.04
-fee_deposit = TESTKUDOS:0.03
-fee_withdraw = TESTKUDOS:0.03
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:2
-
-[coin_kudos_1]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_deposit = TESTKUDOS:0.02
-fee_withdraw = TESTKUDOS:0.02
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:1
-
-[coin_kudos_ct_10]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_deposit = TESTKUDOS:0.01
-fee_withdraw = TESTKUDOS:0.01
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:0.10
-
-[coin_kudos_ct_1]
-rsa_keysize = 1024
-CIPHER = RSA
-fee_refund = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_withdraw = TESTKUDOS:0.01
-duration_legal = 3 years
-duration_spend = 2 years
-duration_withdraw = 7 days
-value = TESTKUDOS:0.01
-
-[payments-generator]
-exchange = http://localhost:8081/
-exchange-admin = http://localhost:18080/
-exchange_admin = http://localhost:18080/
-merchant = http://localhost:9966/
-bank = http://localhost:8082/
-instance = default
-currency = TESTKUDOS
-
-[merchant-exchange-default]
-CURRENCY = TESTKUDOS
-EXCHANGE_BASE_URL = http://localhost:8081/
-MASTER_KEY = JM0NJXHM6Y6HYAPK2WDFH3HDJ2E9KZWGKM3E0FYRV2V3HCTB3DQ0
-
-[merchant-account-merchant]
-ACTIVE_default = YES
-HONOR_default = YES
-PAYTO_URI = payto://x-taler-bank/localhost/42
-
-[exchange-accountcredentials-1]
-PASSWORD = x
-USERNAME = Exchange
-WIRE_GATEWAY_AUTH_METHOD = basic
-WIRE_GATEWAY_URL = http://localhost:8082/taler-wire-gateway/Exchange/
-
-[exchange-account-1]
-enable_credit = yes
-enable_debit = yes
-PAYTO_URI = payto://x-taler-bank/localhost/Exchange
-
-[instance-default]
-NAME = Merchant Inc.
-KEYFILE = ${TALER_DATA_HOME}/merchant/default.priv
-
-[taler]
-CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
-CURRENCY = TESTKUDOS
-
-[merchantdb-postgres]
-CONFIG = postgres:///auditor-basedb
-
-[merchant]
-DEFAULT_MAX_WIRE_FEE = TESTKUDOS:0.10
-KEYFILE = ${TALER_DATA_HOME}/merchant/merchant.priv
-DEFAULT_MAX_DEPOSIT_FEE = TESTKUDOS:0.1
-WIREFORMAT = default
-WIRE_TRANSFER_DELAY = 1 minute
-FORCE_AUDIT = YES
-UNIXPATH = ${TALER_RUNTIME_DIR}/merchant.http
-
-[exchangedb-postgres]
-CONFIG = postgres:///auditor-basedb
-
-[exchange]
-LOOKAHEAD_SIGN = 32 weeks 1 day
-SIGNKEY_DURATION = 4 weeks
-MASTER_PUBLIC_KEY = JM0NJXHM6Y6HYAPK2WDFH3HDJ2E9KZWGKM3E0FYRV2V3HCTB3DQ0
-SIGNKEY_LEGAL_DURATION = 4 weeks
-UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
-
-[bank]
-SERVE = http
-ALLOW_REGISTRATIONS = YES
-SUGGESTED_EXCHANGE_PAYTO = payto://x-taler-bank/localhost/2
-SUGGESTED_EXCHANGE = http://localhost:8081/
-HTTP_PORT = 8082
-MAX_DEBT_BANK = TESTKUDOS:100000.0
-MAX_DEBT = TESTKUDOS:50.0
-DATABASE = postgres:///auditor-basedb
-
-[auditordb-postgres]
-CONFIG = postgres:///auditor-basedb
-
-[auditor]
-PUBLIC_KEY = 73NJKBP4MHJF8274K88F4WFWKNYMK8T6MTSE6HHYS6WC01H9YH7G
-TINY_AMOUNT = TESTKUDOS:0.01
-BASE_URL = http://localhost:8083/
-
-[PATHS]
-TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
-TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
-TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
-TALER_HOME = ${PWD}/generate_auditordb_home/
diff --git a/src/auditor/auditor-basedb.fees b/src/auditor/auditor-basedb.fees
deleted file mode 100644
index ef2a6d121..000000000
--- a/src/auditor/auditor-basedb.fees
+++ /dev/null
Binary files differ
diff --git a/src/auditor/auditor-basedb.mpub b/src/auditor/auditor-basedb.mpub
deleted file mode 100644
index ede1a7319..000000000
--- a/src/auditor/auditor-basedb.mpub
+++ /dev/null
@@ -1 +0,0 @@
-JM0NJXHM6Y6HYAPK2WDFH3HDJ2E9KZWGKM3E0FYRV2V3HCTB3DQ0
diff --git a/src/auditor/auditor-basedb.sql b/src/auditor/auditor-basedb.sql
deleted file mode 100644
index 69950d5b5..000000000
--- a/src/auditor/auditor-basedb.sql
+++ /dev/null
@@ -1,16991 +0,0 @@
---
--- PostgreSQL database dump
---
-
--- Dumped from database version 13.7 (Debian 13.7-0+deb11u1)
--- Dumped by pg_dump version 13.7 (Debian 13.7-0+deb11u1)
-
-SET statement_timeout = 0;
-SET lock_timeout = 0;
-SET idle_in_transaction_session_timeout = 0;
-SET client_encoding = 'UTF8';
-SET standard_conforming_strings = on;
-SELECT pg_catalog.set_config('search_path', '', false);
-SET check_function_bodies = false;
-SET xmloption = content;
-SET client_min_messages = warning;
-SET row_security = off;
-
---
--- Name: _v; Type: SCHEMA; Schema: -; Owner: -
---
-
-CREATE SCHEMA _v;
-
-
---
--- Name: SCHEMA _v; Type: COMMENT; Schema: -; Owner: -
---
-
-COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
-
-
---
--- Name: assert_patch_is_applied(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_patch_is_applied(in_patch_name text) RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- t_text TEXT;
-BEGIN
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF NOT FOUND THEN
- RAISE EXCEPTION 'Patch % is not applied!', in_patch_name;
- END IF;
- RETURN format('Patch %s is applied.', in_patch_name);
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_patch_is_applied(in_patch_name text); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_patch_is_applied(in_patch_name text) IS 'Function that can be used to make sure that patch has been applied.';
-
-
---
--- Name: assert_user_is_not_superuser(); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_not_superuser() RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RAISE EXCEPTION 'Current user is superuser - cannot continue.';
- END IF;
- RETURN 'assert_user_is_not_superuser: OK';
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_not_superuser(); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_not_superuser() IS 'Function that can be used to make sure that patch is being applied using normal (not superuser) account.';
-
-
---
--- Name: assert_user_is_one_of(text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_one_of(VARIADIC p_acceptable_users text[]) RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
-BEGIN
- IF current_user = any( p_acceptable_users ) THEN
- RETURN 'assert_user_is_one_of: OK';
- END IF;
- RAISE EXCEPTION 'User is not one of: % - cannot continue.', p_acceptable_users;
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_one_of(VARIADIC p_acceptable_users text[]); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_one_of(VARIADIC p_acceptable_users text[]) IS 'Function that can be used to make sure that patch is being applied by one of defined users.';
-
-
---
--- Name: assert_user_is_superuser(); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_superuser() RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RETURN 'assert_user_is_superuser: OK';
- END IF;
- RAISE EXCEPTION 'Current user is not superuser - cannot continue.';
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_superuser(); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_superuser() IS 'Function that can be used to make sure that patch is being applied using superuser account.';
-
-
---
--- Name: register_patch(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(text) RETURNS SETOF integer
- LANGUAGE sql
- AS $_$
- SELECT _v.register_patch( $1, NULL, NULL );
-$_$;
-
-
---
--- Name: FUNCTION register_patch(text); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(text) IS 'Wrapper to allow registration of patches without requirements and conflicts.';
-
-
---
--- Name: register_patch(text, text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(text, text[]) RETURNS SETOF integer
- LANGUAGE sql
- AS $_$
- SELECT _v.register_patch( $1, $2, NULL );
-$_$;
-
-
---
--- Name: FUNCTION register_patch(text, text[]); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(text, text[]) IS 'Wrapper to allow registration of patches without conflicts.';
-
-
---
--- Name: register_patch(text, text[], text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer) RETURNS SETOF integer
- LANGUAGE plpgsql
- AS $$
-DECLARE
- t_text TEXT;
- t_text_a TEXT[];
- i INT4;
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF FOUND THEN
- RAISE EXCEPTION 'Patch % is already applied!', in_patch_name;
- END IF;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE patch_name = any( in_conflicts ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Versioning patches conflict. Conflicting patche(s) installed: %.', array_to_string( t_text_a, ', ' );
- END IF;
-
- IF array_upper( in_requirements, 1 ) IS NOT NULL THEN
- t_text_a := '{}';
- FOR i IN array_lower( in_requirements, 1 ) .. array_upper( in_requirements, 1 ) LOOP
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_requirements[i];
- IF NOT FOUND THEN
- t_text_a := t_text_a || in_requirements[i];
- END IF;
- END LOOP;
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Missing prerequisite(s): %.', array_to_string( t_text_a, ', ' );
- END IF;
- END IF;
-
- INSERT INTO _v.patches (patch_name, applied_tsz, applied_by, requires, conflicts ) VALUES ( in_patch_name, now(), current_user, coalesce( in_requirements, '{}' ), coalesce( in_conflicts, '{}' ) );
- RETURN;
-END;
-$$;
-
-
---
--- Name: FUNCTION register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer) IS 'Function to register patches in database. Raises exception if there are conflicts, prerequisites are not installed or the migration has already been installed.';
-
-
---
--- Name: unregister_patch(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.unregister_patch(in_patch_name text, OUT versioning integer) RETURNS SETOF integer
- LANGUAGE plpgsql
- AS $$
-DECLARE
- i INT4;
- t_text_a TEXT[];
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE in_patch_name = ANY( requires ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Cannot uninstall %, as it is required by: %.', in_patch_name, array_to_string( t_text_a, ', ' );
- END IF;
-
- DELETE FROM _v.patches WHERE patch_name = in_patch_name;
- GET DIAGNOSTICS i = ROW_COUNT;
- IF i < 1 THEN
- RAISE EXCEPTION 'Patch % is not installed, so it can''t be uninstalled!', in_patch_name;
- END IF;
-
- RETURN;
-END;
-$$;
-
-
---
--- Name: FUNCTION unregister_patch(in_patch_name text, OUT versioning integer); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.unregister_patch(in_patch_name text, OUT versioning integer) IS 'Function to unregister patches in database. Dies if the patch is not registered, or if unregistering it would break dependencies.';
-
-
---
--- Name: add_constraints_to_account_merges_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_account_merges_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE account_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT account_merges_' || partition_suffix || '_account_merge_request_serial_id_key '
- 'UNIQUE (account_merge_request_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_aggregation_tracking_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_aggregation_tracking_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE aggregation_tracking_' || partition_suffix || ' '
- 'ADD CONSTRAINT aggregation_tracking_' || partition_suffix || '_aggregation_serial_id_key '
- 'UNIQUE (aggregation_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_contracts_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_contracts_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE contracts_' || partition_suffix || ' '
- 'ADD CONSTRAINT contracts_' || partition_suffix || '_contract_serial_id_key '
- 'UNIQUE (contract_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_cs_nonce_locks_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_cs_nonce_locks_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE cs_nonce_locks_' || partition_suffix || ' '
- 'ADD CONSTRAINT cs_nonce_locks_' || partition_suffix || '_cs_nonce_lock_serial_id_key '
- 'UNIQUE (cs_nonce_lock_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_deposits_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_deposits_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT deposits_' || partition_suffix || '_deposit_serial_id_pkey '
- 'PRIMARY KEY (deposit_serial_id) '
- ',ADD CONSTRAINT deposits_' || partition_suffix || '_coin_pub_merchant_pub_h_contract_terms_key '
- 'UNIQUE (coin_pub, merchant_pub, h_contract_terms)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_known_coins_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_known_coins_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE known_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT known_coins_' || partition_suffix || '_known_coin_id_key '
- 'UNIQUE (known_coin_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_deposits_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_deposits_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_deposits_' || partition_suffix || '_purse_deposit_serial_id_key '
- 'UNIQUE (purse_deposit_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_merges_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_merges_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_merges_' || partition_suffix || '_purse_merge_request_serial_id_key '
- 'UNIQUE (purse_merge_request_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_refunds_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_refunds_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_refunds_' || partition_suffix || '_purse_refunds_serial_id_key '
- 'UNIQUE (purse_refunds_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_requests_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_requests_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_requests_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_requests_' || partition_suffix || '_purse_requests_serial_id_key '
- 'UNIQUE (purse_requests_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_recoup_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_recoup_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_' || partition_suffix || '_recoup_uuid_key '
- 'UNIQUE (recoup_uuid) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_recoup_refresh_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_recoup_refresh_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_refresh_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_refresh_' || partition_suffix || '_recoup_refresh_uuid_key '
- 'UNIQUE (recoup_refresh_uuid) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_commitments_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_commitments_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_commitments_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_commitments_' || partition_suffix || '_melt_serial_id_key '
- 'UNIQUE (melt_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_revealed_coins_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_revealed_coins_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_revealed_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_rrc_serial_key '
- 'UNIQUE (rrc_serial) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_coin_ev_key '
- 'UNIQUE (coin_ev) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_h_coin_ev_key '
- 'UNIQUE (h_coin_ev) '
- ',ADD PRIMARY KEY (melt_serial_id, freshcoin_index) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_transfer_keys_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_transfer_keys_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_transfer_keys_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_transfer_keys_' || partition_suffix || '_rtc_serial_key '
- 'UNIQUE (rtc_serial)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refunds_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refunds_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT refunds_' || partition_suffix || '_refund_serial_id_key '
- 'UNIQUE (refund_serial_id) '
- ',ADD PRIMARY KEY (deposit_serial_id, rtransaction_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_close_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_close_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_close_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_close_' || partition_suffix || '_close_uuid_pkey '
- 'PRIMARY KEY (close_uuid)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_in_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_in_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_in_' || partition_suffix || '_reserve_in_serial_id_key '
- 'UNIQUE (reserve_in_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_out_' || partition_suffix || '_reserve_out_serial_id_key '
- 'UNIQUE (reserve_out_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wad_in_entries_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wad_in_entries_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_in_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_in_entries_' || partition_suffix || '_wad_in_entry_serial_id_key '
- 'UNIQUE (wad_in_entry_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wad_out_entries_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wad_out_entries_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_out_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_out_entries_' || partition_suffix || '_wad_out_entry_serial_id_key '
- 'UNIQUE (wad_out_entry_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wads_in_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wads_in_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_in_serial_id_key '
- 'UNIQUE (wad_in_serial_id) '
- ',ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_is_origin_exchange_url_key '
- 'UNIQUE (wad_id, origin_exchange_url) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wads_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wads_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_out_' || partition_suffix || '_wad_out_serial_id_key '
- 'UNIQUE (wad_out_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wire_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wire_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wire_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_out_' || partition_suffix || '_wireout_uuid_pkey '
- 'PRIMARY KEY (wireout_uuid)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wire_targets_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wire_targets_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- EXECUTE FORMAT (
- 'ALTER TABLE wire_targets_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_targets_' || partition_suffix || '_wire_target_serial_id_key '
- 'UNIQUE (wire_target_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: create_foreign_hash_partition(character varying, integer, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_hash_partition(source_table_name character varying, modulus integer, shard_suffix character varying, current_shard_num integer, local_user character varying DEFAULT 'taler-exchange-httpd'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating %_% on %', source_table_name, shard_suffix, shard_suffix;
-
- EXECUTE FORMAT(
- 'CREATE FOREIGN TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s) '
- 'SERVER %I'
- ,source_table_name || '_' || shard_suffix
- ,source_table_name
- ,modulus
- ,current_shard_num-1
- ,shard_suffix
- );
-
- EXECUTE FORMAT(
- 'ALTER FOREIGN TABLE %I OWNER TO %I'
- ,source_table_name || '_' || shard_suffix
- ,local_user
- );
-
-END
-$$;
-
-
---
--- Name: create_foreign_range_partition(character varying, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_range_partition(source_table_name character varying, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-
---
--- Name: create_foreign_servers(integer, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_servers(amount integer, domain character varying, remote_user character varying DEFAULT 'taler'::character varying, remote_user_password character varying DEFAULT 'taler'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM prepare_sharding();
-
- FOR i IN 1..amount LOOP
- PERFORM create_shard_server(
- i::varchar
- ,amount
- ,i
- ,'shard-' || i::varchar || '.' || domain
- ,remote_user
- ,remote_user_password
- ,'taler-exchange'
- ,'5432'
- ,'taler-exchange-httpd'
- );
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
-
---
--- Name: create_hash_partition(character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_hash_partition(source_table_name character varying, modulus integer, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating partition %_%', source_table_name, partition_num;
-
- EXECUTE FORMAT(
- 'CREATE TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
- ,source_table_name || '_' || partition_num
- ,source_table_name
- ,modulus
- ,partition_num-1
- );
-
-END
-$$;
-
-
---
--- Name: create_partitioned_table(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_partitioned_table(table_definition character varying, table_name character varying, main_table_partition_str character varying, shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- IF shard_suffix IS NOT NULL THEN
- table_name=table_name || '_' || shard_suffix;
- main_table_partition_str = '';
- END IF;
-
- EXECUTE FORMAT(
- table_definition,
- table_name,
- main_table_partition_str
- );
-
-END
-$$;
-
-
---
--- Name: create_partitions(integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_partitions(num_partitions integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- modulus INTEGER;
-BEGIN
-
- modulus := num_partitions;
-
- PERFORM detach_default_partitions();
-
- LOOP
-
- PERFORM create_hash_partition(
- 'wire_targets'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_targets_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'reserves_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_close'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_close_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'known_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_known_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_commitments'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_commitments_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_revealed_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_revealed_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_transfer_keys'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_transfer_keys_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_deposits_partition(num_partitions::varchar);
-
--- TODO: dynamically (!) creating/deleting deposits partitions:
--- create new partitions 'as needed', drop old ones once the aggregator has made
--- them empty; as 'new' deposits will always have deadlines in the future, this
--- would basically guarantee no conflict between aggregator and exchange service!
--- SEE also: https://www.cybertec-postgresql.com/en/automatic-partition-creation-in-postgresql/
--- (article is slightly wrong, as this works:)
---CREATE TABLE tab (
--- id bigint GENERATED ALWAYS AS IDENTITY,
--- ts timestamp NOT NULL,
--- data text
--- PARTITION BY LIST ((ts::date));
--- CREATE TABLE tab_def PARTITION OF tab DEFAULT;
--- BEGIN
--- CREATE TABLE tab_part2 (LIKE tab);
--- insert into tab_part2 (id,ts, data) values (5,'2022-03-21', 'foo');
--- alter table tab attach partition tab_part2 for values in ('2022-03-21');
--- commit;
--- Naturally, to ensure this is actually 100% conflict-free, we'd
--- need to create tables at the granularity of the wire/refund deadlines;
--- that is right now configurable via AGGREGATOR_SHIFT option.
-
--- FIXME: range partitioning
--- PERFORM create_range_partition(
--- 'deposits_by_ready'
--- ,modulus
--- ,num_partitions
--- );
---
--- PERFORM create_range_partition(
--- 'deposits_for_matching'
--- ,modulus
--- ,num_partitions
--- );
-
- PERFORM create_hash_partition(
- 'refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wire_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'aggregation_transient'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'aggregation_tracking'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_aggregation_tracking_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'recoup_refresh'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_refresh_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'prewire'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'cs_nonce_locks'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_cs_nonce_locks_partition(num_partitions::varchar);
-
- ---------------- P2P ----------------------
-
- PERFORM create_hash_partition(
- 'purse_requests'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_requests_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'account_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_account_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'contracts'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_contracts_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'history_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'close_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'purse_deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_deposits_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_out_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_out_entries_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wads_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wads_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_in_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_in_entries_partition(num_partitions::varchar);
-
- num_partitions=num_partitions-1;
- EXIT WHEN num_partitions=0;
-
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
-
---
--- Name: create_range_partition(character varying, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_range_partition(source_table_name character varying, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-
---
--- Name: create_shard_server(character varying, integer, integer, character varying, character varying, character varying, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying DEFAULT 'taler-exchange'::character varying, remote_port integer DEFAULT 5432, local_user character varying DEFAULT 'taler-exchange-httpd'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating server %', remote_host;
-
- EXECUTE FORMAT(
- 'CREATE SERVER IF NOT EXISTS %I '
- 'FOREIGN DATA WRAPPER postgres_fdw '
- 'OPTIONS (dbname %L, host %L, port %L)'
- ,shard_suffix
- ,remote_db_name
- ,remote_host
- ,remote_port
- );
-
- EXECUTE FORMAT(
- 'CREATE USER MAPPING IF NOT EXISTS '
- 'FOR %I SERVER %I '
- 'OPTIONS (user %L, password %L)'
- ,local_user
- ,shard_suffix
- ,remote_user
- ,remote_user_password
- );
-
- EXECUTE FORMAT(
- 'GRANT ALL PRIVILEGES '
- 'ON FOREIGN SERVER %I '
- 'TO %I;'
- ,shard_suffix
- ,local_user
- );
-
- PERFORM create_foreign_hash_partition(
- 'wire_targets'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_close'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'known_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_commitments'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_revealed_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_transfer_keys'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_by_ready'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_for_matching'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
- PERFORM create_foreign_hash_partition(
- 'refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wire_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_transient'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_tracking'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_refresh'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'prewire'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'cs_nonce_locks'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
- ------------------- P2P --------------------
-
- PERFORM create_foreign_hash_partition(
- 'purse_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'account_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'contracts'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'history_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'close_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_out_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wads_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_in_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
-END
-$$;
-
-
---
--- Name: FUNCTION create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying, remote_port integer, local_user character varying); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying, remote_port integer, local_user character varying) IS 'Create a shard server on the master
- node with all foreign tables and user mappings';
-
-
---
--- Name: create_table_account_merges(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_account_merges(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'account_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(account_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' -- REFERENCES purse_requests (purse_pub)
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_aggregation_tracking(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_aggregation_tracking(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_tracking';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(aggregation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',deposit_serial_id INT8 PRIMARY KEY' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE' -- FIXME change to coint_pub + deposit_serial_id for more efficient depost -- or something else ???
- ',wtid_raw BYTEA NOT NULL' -- CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (deposit_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wtid_raw_index '
- 'ON ' || table_name || ' '
- '(wtid_raw);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_wtid_raw_index '
- 'IS ' || quote_literal('for lookup_transactions') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_aggregation_transient(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_aggregation_transient(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_transient';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_close_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_close_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'close_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(close_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',close_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',close_val INT8 NOT NULL'
- ',close_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,close_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_contracts(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_contracts(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'contracts';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(contract_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',pub_ckey BYTEA NOT NULL CHECK (LENGTH(pub_ckey)=32)'
- ',contract_sig BYTEA NOT NULL CHECK (LENGTH(contract_sig)=64)'
- ',e_contract BYTEA NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_cs_nonce_locks(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_cs_nonce_locks(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)'
- ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)'
- ',max_denomination_serial INT8 NOT NULL'
- ') %s ;'
- ,'cs_nonce_locks'
- ,'PARTITION BY HASH (nonce)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',known_coin_id INT8 NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE' --- FIXME: column needed???
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wallet_timestamp INT8 NOT NULL'
- ',exchange_timestamp INT8 NOT NULL'
- ',refund_deadline INT8 NOT NULL'
- ',wire_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
- ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',done BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_blocked BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_details_serial_id INT8' -- REFERENCES extension_details (extension_details_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits_by_ready(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits_by_ready(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_by_ready';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_deadline INT8 NOT NULL'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (wire_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(wire_deadline ASC, shard ASC, coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits_for_matching(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits_for_matching(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_for_matching';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (refund_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(refund_deadline ASC, merchant_pub, coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_history_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_history_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'history_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',request_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',history_fee_val INT8 NOT NULL'
- ',history_fee_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,request_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_known_coins(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_known_coins(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'known_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
- ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
- ',denom_sig BYTEA NOT NULL'
- ',remaining_val INT8 NOT NULL DEFAULT(0)'
- ',remaining_frac INT4 NOT NULL DEFAULT(0)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)' -- FIXME: or include denominations_serial? or multi-level partitioning?;
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-
---
--- Name: create_table_prewire(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_prewire(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'prewire';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
- ',wire_method TEXT NOT NULL'
- ',finished BOOLEAN NOT NULL DEFAULT false'
- ',failed BOOLEAN NOT NULL DEFAULT false'
- ',buf BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (prewire_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_finished_index '
- 'ON ' || table_name || ' '
- '(finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_finished_index '
- 'IS ' || quote_literal('for gc_prewire') || ';'
- );
- -- FIXME: find a way to combine these two indices?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_failed_finished_index '
- 'ON ' || table_name || ' '
- '(failed,finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index '
- 'IS ' || quote_literal('for wire_prepare_data_get') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_deposits(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_deposits(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',PRIMARY KEY (purse_pub,coin_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by coin_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_merges(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_merges(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY '-- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(length(reserve_pub)=32)'--REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' --REFERENCES purse_requests (purse_pub) ON DELETE CASCADE
- ',merge_sig BYTEA NOT NULL CHECK (LENGTH(merge_sig)=64)'
- ',merge_timestamp INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_refunds(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_refunds(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_refunds_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-
---
--- Name: create_table_purse_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_requests_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',merge_pub BYTEA NOT NULL CHECK (LENGTH(merge_pub)=32)'
- ',purse_creation INT8 NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',age_limit INT4 NOT NULL'
- ',flags INT4 NOT NULL'
- ',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',purse_fee_val INT8 NOT NULL'
- ',purse_fee_frac INT4 NOT NULL'
- ',balance_val INT8 NOT NULL DEFAULT (0)'
- ',balance_frac INT4 NOT NULL DEFAULT (0)'
- ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by merge_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_merge_pub '
- 'ON ' || table_name || ' '
- '(merge_pub);'
- );
-
- -- FIXME: drop index on master (crosses shards)?
- -- Or use materialized index? (needed?)
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_purse_expiration '
- 'ON ' || table_name || ' '
- '(purse_expiration);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves_out (reserve_out_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub);'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup_by_reserve(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup_by_reserve(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves (reserve_out_serial_id) ON DELETE CASCADE
- ',coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_out_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup_refresh(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup_refresh(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_refresh';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_refresh_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',known_coin_id BIGINT NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',rrc_serial INT8 NOT NULL' -- REFERENCES refresh_revealed_coins (rrc_serial) ON DELETE CASCADE -- UNIQUE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: any query using this index will be slow. Materialize index or change query?
- -- Also: which query uses this index?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_rrc_serial_index '
- 'ON ' || table_name || ' '
- '(rrc_serial);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_commitments(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_commitments(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_commitments';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(melt_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
- ',old_coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',noreveal_index INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (rc)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- Note: index spans partitions, may need to be materialized.
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_old_coin_pub_index '
- 'ON ' || table_name || ' '
- '(old_coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_revealed_coins(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_revealed_coins(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_revealed_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rrc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 NOT NULL' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',freshcoin_index INT4 NOT NULL'
- ',link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_ev BYTEA NOT NULL' -- UNIQUE'
- ',h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)' -- UNIQUE'
- ',ev_sig BYTEA NOT NULL'
- ',ewv BYTEA NOT NULL'
- -- ,PRIMARY KEY (melt_serial_id, freshcoin_index) -- done per shard
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_coins_by_melt_serial_id_index '
- 'ON ' || table_name || ' '
- '(melt_serial_id);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_transfer_keys(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_transfer_keys(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_transfer_keys';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rtc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 PRIMARY KEY' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)'
- ',transfer_privs BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refunds(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refunds(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8 NOT NULL' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE'
- ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
- ',rtransaction_id INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- -- ,PRIMARY KEY (deposit_serial_id, rtransaction_id) -- done per shard!
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
- ',reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)'
- ',current_balance_val INT8 NOT NULL DEFAULT(0)'
- ',current_balance_frac INT4 NOT NULL DEFAULT(0)'
- ',purses_active INT8 NOT NULL DEFAULT(0)'
- ',purses_allowed INT8 NOT NULL DEFAULT(0)'
- ',kyc_required BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',kyc_passed BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',max_age INT4 NOT NULL DEFAULT(120)'
- ',expiration_date INT8 NOT NULL'
- ',gc_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_expiration_index '
- 'ON ' || table_name || ' '
- '(expiration_date'
- ',current_balance_val'
- ',current_balance_frac'
- ');'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_expiration_index '
- 'IS ' || quote_literal('used in get_expired_reserves') || ';'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_gc_date_index '
- 'ON ' || table_name || ' '
- '(gc_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_gc_date_index '
- 'IS ' || quote_literal('for reserve garbage collection') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_close(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_close(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_close';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE / PRIMARY KEY'
- ',reserve_pub BYTEA NOT NULL' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',execution_date INT8 NOT NULL'
- ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',closing_fee_val INT8 NOT NULL'
- ',closing_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_close_uuid_index '
- 'ON ' || table_name || ' '
- '(close_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-END
-$$;
-
-
---
--- Name: create_table_reserves_in(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_in(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',reserve_pub BYTEA PRIMARY KEY' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',wire_reference INT8 NOT NULL'
- ',credit_val INT8 NOT NULL'
- ',credit_frac INT4 NOT NULL'
- ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',execution_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_in_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_in_serial_id);'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_section_execution_date_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section '
- ',execution_date'
- ');'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_reserve_in_serial_id_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section,'
- 'reserve_in_serial_id DESC'
- ');'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64) UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial)'
- ',denom_sig BYTEA NOT NULL'
- ',reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',execution_date INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,'reserves_out'
- ,'PARTITION BY HASH (h_blind_ev)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_out_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
- -- FIXME: change query to use reserves_out_by_reserve instead and materialize execution_date there as well???
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid, execution_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'IS ' || quote_literal('for get_reserves_out and exchange_do_withdraw_limit_check') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_out_by_reserve(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_out_by_reserve(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves_out_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64)'
- ') %s '
- ,table_name
- ,'PARTITION BY HASH (reserve_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wad_in_entries(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wad_in_entries(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_in_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_in_serial_id INT8' -- REFERENCES wads_in (wad_in_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wad_out_entries(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wad_out_entries(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_out_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_out_serial_id INT8' -- REFERENCES wads_out (wad_out_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wads_in(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wads_in(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',origin_exchange_url TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',arrival_time INT8 NOT NULL'
- ',UNIQUE (wad_id, origin_exchange_url)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wads_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wads_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',partner_serial_id INT8 NOT NULL' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',execution_time INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wire_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wire_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wire_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',execution_date INT8 NOT NULL'
- ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wtid_raw)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wire_target_h_payto_index '
- 'ON ' || table_name || ' '
- '(wire_target_h_payto);'
- );
-
-
-END
-$$;
-
-
---
--- Name: create_table_wire_targets(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wire_targets(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)'
- ',payto_uri VARCHAR NOT NULL'
- ',kyc_ok BOOLEAN NOT NULL DEFAULT (FALSE)'
- ',external_id VARCHAR'
- ') %s ;'
- ,'wire_targets'
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: defer_wire_out(); Type: PROCEDURE; Schema: public; Owner: -
---
-
-CREATE PROCEDURE public.defer_wire_out()
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
-IF EXISTS (
- SELECT 1
- FROM information_Schema.constraint_column_usage
- WHERE table_name='wire_out'
- AND constraint_name='wire_out_ref')
-THEN
- SET CONSTRAINTS wire_out_ref DEFERRED;
-END IF;
-
-END $$;
-
-
---
--- Name: deposits_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
-
- IF (was_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_delete_trigger() IS 'Replicate deposit deletions into materialized indices.';
-
-
---
--- Name: deposits_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
-
- IF (is_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_insert_trigger() IS 'Replicate deposit inserts into materialized indices.';
-
-
---
--- Name: deposits_update_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_update_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
- IF (was_ready AND NOT is_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- IF (is_ready AND NOT was_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_update_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_update_trigger() IS 'Replicate deposits changes into materialized indices.';
-
-
---
--- Name: detach_default_partitions(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.detach_default_partitions() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Detaching all default table partitions';
-
- ALTER TABLE IF EXISTS wire_targets
- DETACH PARTITION wire_targets_default;
-
- ALTER TABLE IF EXISTS reserves
- DETACH PARTITION reserves_default;
-
- ALTER TABLE IF EXISTS reserves_in
- DETACH PARTITION reserves_in_default;
-
- ALTER TABLE IF EXISTS reserves_close
- DETACH PARTITION reserves_close_default;
-
- ALTER TABLE IF EXISTS reserves_out
- DETACH PARTITION reserves_out_default;
-
- ALTER TABLE IF EXISTS reserves_out_by_reserve
- DETACH PARTITION reserves_out_by_reserve_default;
-
- ALTER TABLE IF EXISTS known_coins
- DETACH PARTITION known_coins_default;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DETACH PARTITION refresh_commitments_default;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DETACH PARTITION refresh_revealed_coins_default;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DETACH PARTITION refresh_transfer_keys_default;
-
- ALTER TABLE IF EXISTS deposits
- DETACH PARTITION deposits_default;
-
---- TODO range partitioning
--- ALTER TABLE IF EXISTS deposits_by_ready
--- DETACH PARTITION deposits_by_ready_default;
---
--- ALTER TABLE IF EXISTS deposits_for_matching
--- DETACH PARTITION deposits_default_for_matching_default;
-
- ALTER TABLE IF EXISTS refunds
- DETACH PARTITION refunds_default;
-
- ALTER TABLE IF EXISTS wire_out
- DETACH PARTITION wire_out_default;
-
- ALTER TABLE IF EXISTS aggregation_transient
- DETACH PARTITION aggregation_transient_default;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DETACH PARTITION aggregation_tracking_default;
-
- ALTER TABLE IF EXISTS recoup
- DETACH PARTITION recoup_default;
-
- ALTER TABLE IF EXISTS recoup_by_reserve
- DETACH PARTITION recoup_by_reserve_default;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DETACH PARTITION recoup_refresh_default;
-
- ALTER TABLE IF EXISTS prewire
- DETACH PARTITION prewire_default;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DETACH partition cs_nonce_locks_default;
-
- ALTER TABLE IF EXISTS purse_requests
- DETACH partition purse_requests_default;
-
- ALTER TABLE IF EXISTS purse_refunds
- DETACH partition purse_refunds_default;
-
- ALTER TABLE IF EXISTS purse_merges
- DETACH partition purse_merges_default;
-
- ALTER TABLE IF EXISTS account_merges
- DETACH partition account_merges_default;
-
- ALTER TABLE IF EXISTS contracts
- DETACH partition contracts_default;
-
- ALTER TABLE IF EXISTS history_requests
- DETACH partition history_requests_default;
-
- ALTER TABLE IF EXISTS close_requests
- DETACH partition close_requests_default;
-
- ALTER TABLE IF EXISTS purse_deposits
- DETACH partition purse_deposits_default;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DETACH partition wad_out_entries_default;
-
- ALTER TABLE IF EXISTS wads_in
- DETACH partition wads_in_default;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DETACH partition wad_in_entries_default;
-END
-$$;
-
-
---
--- Name: FUNCTION detach_default_partitions(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.detach_default_partitions() IS 'We need to drop default and create new one before deleting the default partitions
- otherwise constraints get lost too. Might be needed in shardig too';
-
-
---
--- Name: drop_default_partitions(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.drop_default_partitions() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Dropping default table partitions';
-
- DROP TABLE IF EXISTS wire_targets_default;
- DROP TABLE IF EXISTS reserves_default;
- DROP TABLE IF EXISTS reserves_in_default;
- DROP TABLE IF EXISTS reserves_close_default;
- DROP TABLE IF EXISTS reserves_out_default;
- DROP TABLE IF EXISTS reserves_out_by_reserve_default;
- DROP TABLE IF EXISTS known_coins_default;
- DROP TABLE IF EXISTS refresh_commitments_default;
- DROP TABLE IF EXISTS refresh_revealed_coins_default;
- DROP TABLE IF EXISTS refresh_transfer_keys_default;
- DROP TABLE IF EXISTS deposits_default;
---DROP TABLE IF EXISTS deposits_by_ready_default;
---DROP TABLE IF EXISTS deposits_for_matching_default;
- DROP TABLE IF EXISTS refunds_default;
- DROP TABLE IF EXISTS wire_out_default;
- DROP TABLE IF EXISTS aggregation_transient_default;
- DROP TABLE IF EXISTS aggregation_tracking_default;
- DROP TABLE IF EXISTS recoup_default;
- DROP TABLE IF EXISTS recoup_by_reserve_default;
- DROP TABLE IF EXISTS recoup_refresh_default;
- DROP TABLE IF EXISTS prewire_default;
- DROP TABLE IF EXISTS cs_nonce_locks_default;
-
- DROP TABLE IF EXISTS purse_requests_default;
- DROP TABLE IF EXISTS purse_refunds_default;
- DROP TABLE IF EXISTS purse_merges_default;
- DROP TABLE IF EXISTS account_merges_default;
- DROP TABLE IF EXISTS contracts_default;
- DROP TABLE IF EXISTS history_requests_default;
- DROP TABLE IF EXISTS close_requests_default;
- DROP TABLE IF EXISTS purse_deposits_default;
- DROP TABLE IF EXISTS wad_out_entries_default;
- DROP TABLE IF EXISTS wads_in_default;
- DROP TABLE IF EXISTS wad_in_entries_default;
-
-END
-$$;
-
-
---
--- Name: FUNCTION drop_default_partitions(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.drop_default_partitions() IS 'Drop all default partitions once other partitions are attached.
- Might be needed in sharding too.';
-
-
---
--- Name: exchange_do_account_merge(bytea, bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_account_merge(in_purse_pub bytea, in_reserve_pub bytea, in_reserve_sig bytea, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
- -- FIXME: function/API is dead! Do DCE?
-END $$;
-
-
---
--- Name: exchange_do_batch_withdraw(bigint, integer, bytea, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.';
-
-
---
--- Name: exchange_do_batch_withdraw_insert(bytea, bigint, integer, bytea, bigint, bytea, bytea, bytea, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- denom_serial INT8;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-out_denom_unknown=TRUE;
-out_conflict=TRUE;
-out_nonce_reuse=TRUE;
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- out_denom_unknown=TRUE;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-out_denom_unknown=FALSE;
-
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- out_conflict=TRUE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
--- Special actions needed for a CS withdraw?
-out_nonce_reuse=FALSE;
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- out_nonce_reuse=TRUE;
- ASSERT false, 'nonce reuse attempted by client';
- RETURN;
- END IF;
- END IF;
-END IF;
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean) IS 'Stores information about a planchet for a batch withdraw operation. Checks if the planchet already exists, and in that case indicates a conflict';
-
-
---
--- Name: exchange_do_close_request(bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_close_request(in_reserve_pub bytea, in_reserve_sig bytea, OUT out_final_balance_val bigint, OUT out_final_balance_frac integer, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
- -- FIXME
-END $$;
-
-
---
--- Name: exchange_do_deposit(bigint, integer, bytea, bytea, bigint, bigint, bigint, bigint, bytea, character varying, bytea, bigint, bytea, bytea, bigint, boolean, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_deposit(in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_h_contract_terms bytea, in_wire_salt bytea, in_wallet_timestamp bigint, in_exchange_timestamp bigint, in_refund_deadline bigint, in_wire_deadline bigint, in_merchant_pub bytea, in_receiver_wire_account character varying, in_h_payto bytea, in_known_coin_id bigint, in_coin_pub bytea, in_coin_sig bytea, in_shard bigint, in_extension_blocked boolean, in_extension_details character varying, OUT out_exchange_timestamp bigint, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- wtsi INT8; -- wire target serial id
-DECLARE
- xdi INT8; -- eXstension details serial id
-BEGIN
--- Shards: INSERT extension_details (by extension_details_serial_id)
--- INSERT wire_targets (by h_payto), on CONFLICT DO NOTHING;
--- INSERT deposits (by coin_pub, shard), ON CONFLICT DO NOTHING;
--- UPDATE known_coins (by coin_pub)
-
-IF NOT NULL in_extension_details
-THEN
- INSERT INTO extension_details
- (extension_options)
- VALUES
- (in_extension_details)
- RETURNING extension_details_serial_id INTO xdi;
-ELSE
- xdi=NULL;
-END IF;
-
-
-INSERT INTO wire_targets
- (wire_target_h_payto
- ,payto_uri)
- VALUES
- (in_h_payto
- ,in_receiver_wire_account)
-ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto)
- RETURNING wire_target_serial_id INTO wtsi;
-
-IF NOT FOUND
-THEN
- SELECT wire_target_serial_id
- INTO wtsi
- FROM wire_targets
- WHERE wire_target_h_payto=in_h_payto;
-END IF;
-
-
-INSERT INTO deposits
- (shard
- ,coin_pub
- ,known_coin_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,wallet_timestamp
- ,exchange_timestamp
- ,refund_deadline
- ,wire_deadline
- ,merchant_pub
- ,h_contract_terms
- ,coin_sig
- ,wire_salt
- ,wire_target_h_payto
- ,extension_blocked
- ,extension_details_serial_id
- )
- VALUES
- (in_shard
- ,in_coin_pub
- ,in_known_coin_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_wallet_timestamp
- ,in_exchange_timestamp
- ,in_refund_deadline
- ,in_wire_deadline
- ,in_merchant_pub
- ,in_h_contract_terms
- ,in_coin_sig
- ,in_wire_salt
- ,in_h_payto
- ,in_extension_blocked
- ,xdi)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and wire_target_h_payto
- -- primarily here to maximally use the existing index.
- SELECT
- exchange_timestamp
- INTO
- out_exchange_timestamp
- FROM deposits
- WHERE shard=in_shard
- AND merchant_pub=in_merchant_pub
- AND wire_target_h_payto=in_h_payto
- AND coin_pub=in_coin_pub
- AND coin_sig=in_coin_sig;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_balance_ok=TRUE;
- out_conflict=FALSE;
-
- RETURN;
-END IF;
-
-
-out_exchange_timestamp=in_exchange_timestamp;
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_conflict=FALSE;
-
-END $$;
-
-
---
--- Name: exchange_do_expire_purse(bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean) RETURNS boolean
- LANGUAGE plpgsql
- AS $$
-DECLARE
- my_purse_pub BYTEA;
-DECLARE
- my_deposit record;
-BEGIN
-
-SELECT purse_pub
- INTO my_purse_pub
- FROM purse_requests
- WHERE (purse_expiration >= in_start_time) AND
- (purse_expiration < in_end_time) AND
- (NOT finished) AND
- (NOT refunded)
- ORDER BY purse_expiration ASC
- LIMIT 1;
-out_found = FOUND;
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-UPDATE purse_requests
- SET refunded=TRUE,
- finished=TRUE
- WHERE purse_pub=my_purse_pub;
-
-INSERT INTO purse_refunds
- (purse_pub)
- VALUES
- (my_purse_pub);
-
--- restore balance to each coin deposited into the purse
-FOR my_deposit IN
- SELECT coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- FROM purse_deposits
- WHERE purse_pub = my_purse_pub
-LOOP
- UPDATE known_coins SET
- remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac
- - CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+my_deposit.amount_with_fee_val
- + CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub = my_deposit.coin_pub;
- END LOOP;
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean) IS 'Finds an expired purse in the given time range and refunds the coins (if any).';
-
-
---
--- Name: exchange_do_gc(bigint, bigint); Type: PROCEDURE; Schema: public; Owner: -
---
-
-CREATE PROCEDURE public.exchange_do_gc(in_ancient_date bigint, in_now bigint)
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_uuid_min INT8; -- minimum reserve UUID still alive
-DECLARE
- melt_min INT8; -- minimum melt still alive
-DECLARE
- coin_min INT8; -- minimum known_coin still alive
-DECLARE
- deposit_min INT8; -- minimum deposit still alive
-DECLARE
- reserve_out_min INT8; -- minimum reserve_out still alive
-DECLARE
- denom_min INT8; -- minimum denomination still alive
-BEGIN
-
-DELETE FROM prewire
- WHERE finished=TRUE;
-
-DELETE FROM wire_fee
- WHERE end_date < in_ancient_date;
-
--- TODO: use closing fee as threshold?
-DELETE FROM reserves
- WHERE gc_date < in_now
- AND current_balance_val = 0
- AND current_balance_frac = 0;
-
-SELECT
- reserve_out_serial_id
- INTO
- reserve_out_min
- FROM reserves_out
- ORDER BY reserve_out_serial_id ASC
- LIMIT 1;
-
-DELETE FROM recoup
- WHERE reserve_out_serial_id < reserve_out_min;
--- FIXME: recoup_refresh lacks GC!
-
-SELECT
- reserve_uuid
- INTO
- reserve_uuid_min
- FROM reserves
- ORDER BY reserve_uuid ASC
- LIMIT 1;
-
-DELETE FROM reserves_out
- WHERE reserve_uuid < reserve_uuid_min;
-
--- FIXME: this query will be horribly slow;
--- need to find another way to formulate it...
-DELETE FROM denominations
- WHERE expire_legal < in_now
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM reserves_out)
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup))
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup_refresh));
-
-SELECT
- melt_serial_id
- INTO
- melt_min
- FROM refresh_commitments
- ORDER BY melt_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refresh_revealed_coins
- WHERE melt_serial_id < melt_min;
-
-DELETE FROM refresh_transfer_keys
- WHERE melt_serial_id < melt_min;
-
-SELECT
- known_coin_id
- INTO
- coin_min
- FROM known_coins
- ORDER BY known_coin_id ASC
- LIMIT 1;
-
-DELETE FROM deposits
- WHERE known_coin_id < coin_min;
-
-SELECT
- deposit_serial_id
- INTO
- deposit_min
- FROM deposits
- ORDER BY deposit_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refunds
- WHERE deposit_serial_id < deposit_min;
-
-DELETE FROM aggregation_tracking
- WHERE deposit_serial_id < deposit_min;
-
-SELECT
- denominations_serial
- INTO
- denom_min
- FROM denominations
- ORDER BY denominations_serial ASC
- LIMIT 1;
-
-DELETE FROM cs_nonce_locks
- WHERE max_denomination_serial <= denom_min;
-
-END $$;
-
-
---
--- Name: exchange_do_history_request(bytea, bytea, bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_history_request(in_reserve_pub bytea, in_reserve_sig bytea, in_request_timestamp bigint, in_history_fee_val bigint, in_history_fee_frac integer, OUT out_balance_ok boolean, OUT out_idempotent boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- -- Insert and check for idempotency.
- INSERT INTO history_requests
- (reserve_pub
- ,request_timestamp
- ,reserve_sig
- ,history_fee_val
- ,history_fee_frac)
- VALUES
- (in_reserve_pub
- ,in_request_timestamp
- ,in_reserve_sig
- ,in_history_fee_val
- ,in_history_fee_frac)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- out_balance_ok=TRUE;
- out_idempotent=TRUE;
- RETURN;
- END IF;
-
- out_idempotent=FALSE;
-
- -- Update reserve balance.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_history_fee_frac
- + CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_history_fee_val
- - CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE
- reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_history_fee_val) OR
- ( (current_balance_frac >= in_history_fee_frac) AND
- (current_balance_val >= in_history_fee_val) ) );
-
- IF NOT FOUND
- THEN
- -- Either reserve does not exist, or balance insufficient.
- -- Both we treat the same here as balance insufficient.
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-
- out_balance_ok=TRUE;
-END $$;
-
-
---
--- Name: exchange_do_melt(bytea, bigint, integer, bytea, bytea, bytea, bigint, integer, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_melt(in_cs_rms bytea, in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_rc bytea, in_old_coin_pub bytea, in_old_coin_sig bytea, in_known_coin_id bigint, in_noreveal_index integer, in_zombie_required boolean, OUT out_balance_ok boolean, OUT out_zombie_bad boolean, OUT out_noreveal_index integer) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- denom_max INT8;
-BEGIN
--- Shards: INSERT refresh_commitments (by rc)
--- (rare:) SELECT refresh_commitments (by old_coin_pub) -- crosses shards!
--- (rare:) SEELCT refresh_revealed_coins (by melt_serial_id)
--- (rare:) PERFORM recoup_refresh (by rrc_serial) -- crosses shards!
--- UPDATE known_coins (by coin_pub)
-
-INSERT INTO refresh_commitments
- (rc
- ,old_coin_pub
- ,old_coin_sig
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,noreveal_index
- )
- VALUES
- (in_rc
- ,in_old_coin_pub
- ,in_old_coin_sig
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_noreveal_index)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- out_noreveal_index=-1;
- SELECT
- noreveal_index
- INTO
- out_noreveal_index
- FROM refresh_commitments
- WHERE rc=in_rc;
- out_balance_ok=FOUND;
- out_zombie_bad=FALSE; -- zombie is OK
- RETURN;
-END IF;
-
-
-IF in_zombie_required
-THEN
- -- Check if this coin was part of a refresh
- -- operation that was subsequently involved
- -- in a recoup operation. We begin by all
- -- refresh operations our coin was involved
- -- with, then find all associated reveal
- -- operations, and then see if any of these
- -- reveal operations was involved in a recoup.
- PERFORM
- FROM recoup_refresh
- WHERE rrc_serial IN
- (SELECT rrc_serial
- FROM refresh_revealed_coins
- WHERE melt_serial_id IN
- (SELECT melt_serial_id
- FROM refresh_commitments
- WHERE old_coin_pub=in_old_coin_pub));
- IF NOT FOUND
- THEN
- out_zombie_bad=TRUE;
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_zombie_bad=FALSE; -- zombie is OK
-
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_noreveal_index=-1;
- out_balance_ok=FALSE;
- RETURN;
-END IF;
-
-
-
--- Special actions needed for a CS melt?
-IF NOT NULL in_cs_rms
-THEN
- -- Get maximum denominations serial value in
- -- existence, this will determine how long the
- -- nonce will be locked.
- SELECT
- denominations_serial
- INTO
- denom_max
- FROM denominations
- ORDER BY denominations_serial DESC
- LIMIT 1;
-
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_rms
- ,denom_serial
- ,in_rc)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- Record exists, make sure it is the same
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_rms
- AND op_hash=in_rc;
-
- IF NOT FOUND
- THEN
- -- Nonce reuse detected
- out_balance_ok=FALSE;
- out_zombie_bad=FALSE;
- out_noreveal_index=42; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_noreveal_index=in_noreveal_index;
-
-END $$;
-
-
---
--- Name: exchange_do_purse_deposit(bigint, bytea, bigint, integer, bytea, bytea, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_purse_deposit(in_partner_id bigint, in_purse_pub bytea, in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_coin_pub bytea, in_coin_sig bytea, in_amount_without_fee_val bigint, in_amount_without_fee_frac integer, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_merged BOOLEAN;
-DECLARE
- psi INT8; -- partner's serial ID (set if merged)
-DECLARE
- my_amount_val INT8; -- total in purse
-DECLARE
- my_amount_frac INT4; -- total in purse
-DECLARE
- was_paid BOOLEAN;
-DECLARE
- my_reserve_pub BYTEA;
-BEGIN
-
--- Store the deposit request.
-INSERT INTO purse_deposits
- (partner_serial_id
- ,purse_pub
- ,coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,coin_sig)
- VALUES
- (in_partner_id
- ,in_purse_pub
- ,in_coin_pub
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_coin_sig)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: check if coin_sig is the same,
- -- if so, success, otherwise conflict!
- PERFORM
- FROM purse_deposits
- WHERE coin_pub = in_coin_pub
- AND purse_pub = in_purse_pub
- AND coin_sig = in_cion_sig;
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-END IF;
-
-
--- Debit the coin
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
-
--- Credit the purse.
-UPDATE purse_requests
- SET
- balance_frac=balance_frac+in_amount_without_fee_frac
- - CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- balance_val=balance_val+in_amount_without_fee_val
- + CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE purse_pub=in_purse_pub;
-
-out_conflict=FALSE;
-out_balance_ok=TRUE;
-
--- See if we can finish the merge or need to update the trigger time and partner.
-SELECT partner_serial_id
- ,reserve_pub
- INTO psi
- ,my_reserve_pub
- FROM purse_merges
- WHERE purse_pub=in_purse_pub;
-
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-SELECT
- amount_with_fee_val
- ,amount_with_fee_frac
- INTO
- my_amount_val
- ,my_amount_frac
- FROM purse_requests
- WHERE (purse_pub=in_purse_pub)
- AND ( ( ( (amount_with_fee_val <= balance_val)
- AND (amount_with_fee_frac <= balance_frac) )
- OR (amount_with_fee_val < balance_val) ) );
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-IF (0 != psi)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=psi
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update balance immediately.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=my_reserve_pub;
-
- -- ... and mark purse as finished.
- -- FIXME: combine with UPDATE above?
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-END $$;
-
-
---
--- Name: exchange_do_purse_merge(bytea, bytea, bigint, bytea, character varying, bytea, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- my_amount_val INT8;
-DECLARE
- my_amount_frac INT4;
-DECLARE
- my_purse_fee_val INT8;
-DECLARE
- my_purse_fee_frac INT4;
-DECLARE
- my_partner_serial_id INT8;
-DECLARE
- my_finished BOOLEAN;
-BEGIN
-
-IF in_partner_url IS NULL
-THEN
- my_partner_serial_id=0;
-ELSE
- SELECT
- partner_serial_id
- INTO
- my_partner_serial_id
- FROM partners
- WHERE partner_base_url=in_partner_url
- AND start_date <= in_merge_timestamp
- AND end_date > in_merge_timestamp;
- IF NOT FOUND
- THEN
- out_no_partner=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_no_partner=FALSE;
-
-
--- Check purse is 'full'.
-SELECT amount_with_fee_val
- ,amount_with_fee_frac
- ,purse_fee_val
- ,purse_fee_frac
- ,finished
- INTO my_amount_val
- ,my_amount_frac
- ,my_purse_fee_val
- ,my_purse_fee_frac
- ,my_finished
- FROM purse_requests
- WHERE purse_pub=in_purse_pub
- AND balance_val >= amount_with_fee_val
- AND ( (balance_frac >= amount_with_fee_frac) OR
- (balance_val > amount_with_fee_val) );
-IF NOT FOUND
-THEN
- out_no_balance=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_no_balance=FALSE;
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (my_partner_serial_id
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-ASSERT NOT my_finished, 'internal invariant failed';
-
-IF ( (in_partner_url IS NULL) AND
- (in_require_kyc) )
-THEN
- -- Need to do KYC check.
- SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
- IF NOT FOUND
- THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- RETURN;
- END IF;
- out_no_reserve=FALSE;
-
- IF (out_no_kyc)
- THEN
- RETURN;
- END IF;
-ELSE
- -- KYC is not our responsibility
- out_no_reserve=FALSE;
- out_no_kyc=FALSE;
-END IF;
-
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
--- If we need a wad transfer, mark purse ready for it.
-IF (0 != my_partner_serial_id)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=my_partner_serial_id
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update reserve balance immediately.
-
- -- Refund the purse fee, by adding it to the purse value:
- my_amount_val = my_amount_val + my_purse_fee_val;
- my_amount_frac = my_amount_frac + my_purse_fee_frac;
- -- normalize result
- my_amount_val = my_amount_val + my_amount_frac / 100000000;
- my_amount_frac = my_amount_frac % 100000000;
-
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=in_reserve_pub;
-
- -- ... and mark purse as finished.
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-RETURN;
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.';
-
-
---
--- Name: exchange_do_recoup_by_reserve(bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_by_reserve(res_pub bytea) RETURNS TABLE(denom_sig bytea, denominations_serial bigint, coin_pub bytea, coin_sig bytea, coin_blind bytea, amount_val bigint, amount_frac integer, recoup_timestamp bigint)
- LANGUAGE plpgsql
- AS $$
-DECLARE
- res_uuid BIGINT;
- blind_ev BYTEA;
- c_pub BYTEA;
-BEGIN
- SELECT reserve_uuid
- INTO res_uuid
- FROM reserves
- WHERE reserves.reserve_pub = res_pub;
-
- FOR blind_ev IN
- SELECT h_blind_ev
- FROM reserves_out_by_reserve
- WHERE reserves_out_by_reserve.reserve_uuid = res_uuid
- LOOP
- SELECT robr.coin_pub
- INTO c_pub
- FROM recoup_by_reserve robr
- WHERE robr.reserve_out_serial_id = (
- SELECT reserves_out.reserve_out_serial_id
- FROM reserves_out
- WHERE reserves_out.h_blind_ev = blind_ev
- );
- RETURN QUERY
- SELECT kc.denom_sig,
- kc.denominations_serial,
- rc.coin_pub,
- rc.coin_sig,
- rc.coin_blind,
- rc.amount_val,
- rc.amount_frac,
- rc.recoup_timestamp
- FROM (
- SELECT *
- FROM known_coins
- WHERE known_coins.coin_pub = c_pub
- ) kc
- JOIN (
- SELECT *
- FROM recoup
- WHERE recoup.coin_pub = c_pub
- ) rc USING (coin_pub);
- END LOOP;
-END;
-$$;
-
-
---
--- Name: FUNCTION exchange_do_recoup_by_reserve(res_pub bytea); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_recoup_by_reserve(res_pub bytea) IS 'Recoup by reserve as a function to make sure we hit only the needed partition and not all when joining as joins on distributed tables fetch ALL rows from the shards';
-
-
---
--- Name: exchange_do_recoup_to_coin(bytea, bigint, bytea, bytea, bigint, bytea, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_to_coin(in_old_coin_pub bytea, in_rrc_serial bigint, in_coin_blind bytea, in_coin_pub bytea, in_known_coin_id bigint, in_coin_sig bytea, in_recoup_timestamp bigint, OUT out_recoup_ok boolean, OUT out_internal_failure boolean, OUT out_recoup_timestamp bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
-
--- Shards: UPDATE known_coins (by coin_pub)
--- SELECT recoup_refresh (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- INSERT recoup_refresh (by coin_pub)
-
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup_refresh
- WHERE coin_pub=in_coin_pub;
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the old coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+tmp_frac
- - CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+tmp_val
- + CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase old coin balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup_refresh
- (coin_pub
- ,known_coin_id
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,rrc_serial
- )
-VALUES
- (in_coin_pub
- ,in_known_coin_id
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_rrc_serial);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
-
---
--- Name: exchange_do_recoup_to_reserve(bytea, bigint, bytea, bytea, bigint, bytea, bigint, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_to_reserve(in_reserve_pub bytea, in_reserve_out_serial_id bigint, in_coin_blind bytea, in_coin_pub bytea, in_known_coin_id bigint, in_coin_sig bytea, in_reserve_gc bigint, in_reserve_expiration bigint, in_recoup_timestamp bigint, OUT out_recoup_ok boolean, OUT out_internal_failure boolean, OUT out_recoup_timestamp bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
--- Shards: SELECT known_coins (by coin_pub)
--- SELECT recoup (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- UPDATE reserves (by reserve_pub)
--- INSERT recoup (by coin_pub)
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup
- WHERE coin_pub=in_coin_pub;
-
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the reserve and update reserve timers.
-UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+tmp_frac
- - CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+tmp_val
- + CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END,
- gc_date=GREATEST(gc_date, in_reserve_gc),
- expiration_date=GREATEST(expiration_date, in_reserve_expiration)
- WHERE reserve_pub=in_reserve_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase reserve balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup
- (coin_pub
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,reserve_out_serial_id
- )
-VALUES
- (in_coin_pub
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_reserve_out_serial_id);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
-
---
--- Name: exchange_do_refund(bigint, integer, bigint, integer, bigint, integer, bytea, bigint, bigint, bigint, bytea, bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_refund(in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_amount_val bigint, in_amount_frac integer, in_deposit_fee_val bigint, in_deposit_fee_frac integer, in_h_contract_terms bytea, in_rtransaction_id bigint, in_deposit_shard bigint, in_known_coin_id bigint, in_coin_pub bytea, in_merchant_pub bytea, in_merchant_sig bytea, OUT out_not_found boolean, OUT out_refund_ok boolean, OUT out_gone boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- dsi INT8; -- ID of deposit being refunded
-DECLARE
- tmp_val INT8; -- total amount refunded
-DECLARE
- tmp_frac INT8; -- total amount refunded
-DECLARE
- deposit_val INT8; -- amount that was originally deposited
-DECLARE
- deposit_frac INT8; -- amount that was originally deposited
-BEGIN
--- Shards: SELECT deposits (coin_pub, shard, h_contract_terms, merchant_pub)
--- INSERT refunds (by coin_pub, rtransaction_id) ON CONFLICT DO NOTHING
--- SELECT refunds (by coin_pub)
--- UPDATE known_coins (by coin_pub)
-
-SELECT
- deposit_serial_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,done
-INTO
- dsi
- ,deposit_val
- ,deposit_frac
- ,out_gone
-FROM deposits
- WHERE coin_pub=in_coin_pub
- AND shard=in_deposit_shard
- AND merchant_pub=in_merchant_pub
- AND h_contract_terms=in_h_contract_terms;
-
-IF NOT FOUND
-THEN
- -- No matching deposit found!
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=TRUE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-INSERT INTO refunds
- (deposit_serial_id
- ,coin_pub
- ,merchant_sig
- ,rtransaction_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- )
- VALUES
- (dsi
- ,in_coin_pub
- ,in_merchant_sig
- ,in_rtransaction_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and h_contract_terms
- -- primarily here to maximally use the existing index.
- PERFORM
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi
- AND rtransaction_id=in_rtransaction_id
- AND amount_with_fee_val=in_amount_with_fee_val
- AND amount_with_fee_frac=in_amount_with_fee_frac;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but have conflicting refund.
- out_refund_ok=FALSE;
- out_conflict=TRUE;
- out_not_found=FALSE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_refund_ok=TRUE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-IF out_gone
-THEN
- -- money already sent to the merchant. Tough luck.
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Check refund balance invariant.
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- tmp_val
- ,tmp_frac
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi;
-IF tmp_val IS NULL
-THEN
- RAISE NOTICE 'failed to sum up existing refunds';
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Normalize result before continuing
-tmp_val = tmp_val + tmp_frac / 100000000;
-tmp_frac = tmp_frac % 100000000;
-
--- Actually check if the deposits are sufficient for the refund. Verbosely. ;-)
-IF (tmp_val < deposit_val)
-THEN
- out_refund_ok=TRUE;
-ELSE
- IF (tmp_val = deposit_val) AND (tmp_frac <= deposit_frac)
- THEN
- out_refund_ok=TRUE;
- ELSE
- out_refund_ok=FALSE;
- END IF;
-END IF;
-
-IF (tmp_val = deposit_val) AND (tmp_frac = deposit_frac)
-THEN
- -- Refunds have reached the full value of the original
- -- deposit. Also refund the deposit fee.
- in_amount_frac = in_amount_frac + in_deposit_fee_frac;
- in_amount_val = in_amount_val + in_deposit_fee_val;
-
- -- Normalize result before continuing
- in_amount_val = in_amount_val + in_amount_frac / 100000000;
- in_amount_frac = in_amount_frac % 100000000;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+in_amount_frac
- - CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+in_amount_val
- + CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub;
-
-
-out_conflict=FALSE;
-out_not_found=FALSE;
-
-END $$;
-
-
---
--- Name: exchange_do_reserve_purse(bytea, bytea, bigint, bytea, boolean, bigint, integer, bytea, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (0
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- out_no_funds=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_funds=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
-IF NOT FOUND
-THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- out_no_funds=TRUE;
- RETURN;
-END IF;
-out_no_reserve=FALSE;
-
-IF (out_no_kyc AND in_require_kyc)
-THEN
- out_no_funds=FALSE;
- RETURN;
-END IF;
-
-IF (in_reserve_quota)
-THEN
- -- Increment active purses per reserve (and check this is allowed)
- UPDATE reserves
- SET purses_active=purses_active+1
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND purses_active < purses_allowed;
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-ELSE
- -- UPDATE reserves balance (and check if balance is enough to pay the fee)
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_purse_fee_frac
- + CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_purse_fee_val
- - CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 1
- ELSE 0
- END
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_purse_fee_val) OR
- ( (current_balance_frac >= in_purse_fee_frac) AND
- (current_balance_val >= in_purse_fee_val) ) );
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-END IF;
-
-out_no_funds=FALSE;
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) IS 'Create a purse for a reserve.';
-
-
---
--- Name: exchange_do_withdraw(bytea, bigint, integer, bytea, bytea, bytea, bytea, bytea, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- denom_serial INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=0;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- We optimistically insert, and then on conflict declare
--- the query successful due to idempotency.
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- idempotent query, all constraints must be satisfied
- reserve_found=TRUE;
- balance_ok=TRUE;
- kycok=TRUE;
- account_uuid=0;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
-
--- Special actions needed for a CS withdraw?
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=1; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result';
-
-
---
--- Name: exchange_do_withdraw_limit_check(bigint, bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean) RETURNS boolean
- LANGUAGE plpgsql
- AS $$
-DECLARE
- total_val INT8;
-DECLARE
- total_frac INT8; -- INT4 could overflow during accumulation!
-BEGIN
--- NOTE: Read-only, but crosses shards.
--- Shards: reserves by reserve_pub
--- reserves_out by reserve_uuid -- crosses shards!!
-
-
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- total_val
- ,total_frac
- FROM reserves_out
- WHERE reserve_uuid=ruuid
- AND execution_date > start_time;
-
--- normalize result
-total_val = total_val + total_frac / 100000000;
-total_frac = total_frac % 100000000;
-
--- compare to threshold
-below_limit = (total_val < upper_limit_val) OR
- ( (total_val = upper_limit_val) AND
- (total_frac <= upper_limit_frac) );
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean) IS 'Check whether the withdrawals from the given reserve since the given time are below the given threshold';
-
-
---
--- Name: prepare_sharding(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.prepare_sharding() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- CREATE EXTENSION IF NOT EXISTS postgres_fdw;
-
- PERFORM detach_default_partitions();
-
- ALTER TABLE IF EXISTS wire_targets
- DROP CONSTRAINT IF EXISTS wire_targets_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves
- DROP CONSTRAINT IF EXISTS reserves_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_in
- DROP CONSTRAINT IF EXISTS reserves_in_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_close
- DROP CONSTRAINT IF EXISTS reserves_close_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_out
- DROP CONSTRAINT IF EXISTS reserves_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS reserves_out_denominations_serial_fkey
- ,DROP CONSTRAINT IF EXISTS reserves_out_h_blind_ev_key
- ;
-
- ALTER TABLE IF EXISTS known_coins
- DROP CONSTRAINT IF EXISTS known_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS known_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DROP CONSTRAINT IF EXISTS refresh_commitments_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_old_coin_pub_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DROP CONSTRAINT IF EXISTS refresh_revealed_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_revealed_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DROP CONSTRAINT IF EXISTS refresh_transfer_keys_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS deposits
- DROP CONSTRAINT IF EXISTS deposits_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS deposits_extension_details_serial_id_fkey
- ,DROP CONSTRAINT IF EXISTS deposits_coin_pub_merchant_pub_h_contract_terms_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS refunds
- DROP CONSTRAINT IF EXISTS refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wire_out
- DROP CONSTRAINT IF EXISTS wire_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wire_out_wtid_raw_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DROP CONSTRAINT IF EXISTS aggregation_tracking_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS aggregation_tracking_wtid_raw_fkey
- ;
-
- ALTER TABLE IF EXISTS recoup
- DROP CONSTRAINT IF EXISTS recoup_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DROP CONSTRAINT IF EXISTS recoup_refresh_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS prewire
- DROP CONSTRAINT IF EXISTS prewire_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DROP CONSTRAINT IF EXISTS cs_nonce_locks_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_requests
- DROP CONSTRAINT IF EXISTS purse_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_refunds
- DROP CONSTRAINT IF EXISTS purse_refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_merges
- DROP CONSTRAINT IF EXISTS purse_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS account_merges
- DROP CONSTRAINT IF EXISTS account_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS contracts
- DROP CONSTRAINT IF EXISTS contracts_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS history_requests
- DROP CONSTRAINT IF EXISTS history_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS close_requests
- DROP CONSTRAINT IF EXISTS close_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_deposits
- DROP CONSTRAINT IF EXISTS purse_deposits_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_out
- DROP CONSTRAINT IF EXISTS wads_out_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DROP CONSTRAINT IF EXISTS wad_out_entries_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_in
- DROP CONSTRAINT IF EXISTS wads_in_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wads_in_wad_id_origin_exchange_url_key
- ;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DROP CONSTRAINT IF EXISTS wad_in_entries_pkey CASCADE
- ;
-
-END
-$$;
-
-
---
--- Name: purse_requests_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.purse_requests_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- ASSERT NOT NEW.finished,'Internal invariant violated';
- INSERT INTO
- purse_actions
- (purse_pub
- ,action_date)
- VALUES
- (NEW.purse_pub
- ,NEW.purse_expiration);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION purse_requests_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.purse_requests_insert_trigger() IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
-
-
---
--- Name: purse_requests_on_update_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.purse_requests_on_update_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- IF (NEW.finished AND NOT OLD.finished)
- THEN
- -- If this purse counted against the reserve's
- -- quota of purses, decrement the reserve accounting.
- IF (NEW.in_reserve_quota)
- THEN
- UPDATE reserves
- SET purses_active=purses_active-1
- WHERE reserve_pub IN
- (SELECT reserve_pub
- FROM purse_merges
- WHERE purse_pub=NEW.purse_pub
- LIMIT 1);
- NEW.in_reserve_quota=FALSE;
- END IF;
- -- Delete from the purse_actions table, we are done
- -- with this purse for good.
- DELETE FROM purse_actions
- WHERE purse_pub=NEW.purse_pub;
- RETURN NEW;
- END IF;
-
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION purse_requests_on_update_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.purse_requests_on_update_trigger() IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is finished.';
-
-
---
--- Name: recoup_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.recoup_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM recoup_by_reserve
- WHERE reserve_out_serial_id = OLD.reserve_out_serial_id
- AND coin_pub = OLD.coin_pub;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION recoup_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.recoup_delete_trigger() IS 'Replicate recoup deletions into recoup_by_reserve table.';
-
-
---
--- Name: recoup_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.recoup_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO recoup_by_reserve
- (reserve_out_serial_id
- ,coin_pub)
- VALUES
- (NEW.reserve_out_serial_id
- ,NEW.coin_pub);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION recoup_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.recoup_insert_trigger() IS 'Replicate recoup inserts into recoup_by_reserve table.';
-
-
---
--- Name: reserves_out_by_reserve_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.reserves_out_by_reserve_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM reserves_out_by_reserve
- WHERE reserve_uuid = OLD.reserve_uuid;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION reserves_out_by_reserve_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.reserves_out_by_reserve_delete_trigger() IS 'Replicate reserve_out deletions into reserve_out_by_reserve table.';
-
-
---
--- Name: reserves_out_by_reserve_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.reserves_out_by_reserve_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO reserves_out_by_reserve
- (reserve_uuid
- ,h_blind_ev)
- VALUES
- (NEW.reserve_uuid
- ,NEW.h_blind_ev);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION reserves_out_by_reserve_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.reserves_out_by_reserve_insert_trigger() IS 'Replicate reserve_out inserts into reserve_out_by_reserve table.';
-
-
---
--- Name: wire_out_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.wire_out_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM aggregation_tracking
- WHERE wtid_raw = OLD.wtid_raw;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION wire_out_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.wire_out_delete_trigger() IS 'Replicate reserve_out deletions into aggregation_tracking. This replaces an earlier use of an ON DELETE CASCADE that required a DEFERRABLE constraint and conflicted with nice partitioning.';
-
-
-SET default_tablespace = '';
-
-SET default_table_access_method = heap;
-
---
--- Name: patches; Type: TABLE; Schema: _v; Owner: -
---
-
-CREATE TABLE _v.patches (
- patch_name text NOT NULL,
- applied_tsz timestamp with time zone DEFAULT now() NOT NULL,
- applied_by text NOT NULL,
- requires text[],
- conflicts text[]
-);
-
-
---
--- Name: TABLE patches; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON TABLE _v.patches IS 'Contains information about what patches are currently applied on database.';
-
-
---
--- Name: COLUMN patches.patch_name; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.patch_name IS 'Name of patch, has to be unique for every patch.';
-
-
---
--- Name: COLUMN patches.applied_tsz; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.applied_tsz IS 'When the patch was applied.';
-
-
---
--- Name: COLUMN patches.applied_by; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.applied_by IS 'Who applied this patch (PostgreSQL username)';
-
-
---
--- Name: COLUMN patches.requires; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.requires IS 'List of patches that are required for given patch.';
-
-
---
--- Name: COLUMN patches.conflicts; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.conflicts IS 'List of patches that conflict with given patch.';
-
-
---
--- Name: account_merges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.account_merges (
- account_merge_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT account_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT account_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT account_merges_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE account_merges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.account_merges IS 'Merge requests where a purse- and account-owner requested merging the purse into the account';
-
-
---
--- Name: COLUMN account_merges.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.reserve_pub IS 'public key of the target reserve';
-
-
---
--- Name: COLUMN account_merges.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.reserve_sig IS 'signature by the reserve private key affirming the merge, of type TALER_SIGNATURE_WALLET_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN account_merges.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.purse_pub IS 'public key of the purse';
-
-
---
--- Name: account_merges_account_merge_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.account_merges ALTER COLUMN account_merge_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.account_merges_account_merge_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: account_merges_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.account_merges_default (
- account_merge_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT account_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT account_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT account_merges_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.account_merges ATTACH PARTITION public.account_merges_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: aggregation_tracking; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_tracking (
- aggregation_serial_id bigint NOT NULL,
- deposit_serial_id bigint NOT NULL,
- wtid_raw bytea NOT NULL
-)
-PARTITION BY HASH (deposit_serial_id);
-
-
---
--- Name: TABLE aggregation_tracking; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.aggregation_tracking IS 'mapping from wire transfer identifiers (WTID) to deposits (and back)';
-
-
---
--- Name: COLUMN aggregation_tracking.wtid_raw; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_tracking.wtid_raw IS 'identifier of the wire transfer';
-
-
---
--- Name: aggregation_tracking_aggregation_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.aggregation_tracking ALTER COLUMN aggregation_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.aggregation_tracking_aggregation_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: aggregation_tracking_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_tracking_default (
- aggregation_serial_id bigint NOT NULL,
- deposit_serial_id bigint NOT NULL,
- wtid_raw bytea NOT NULL
-);
-ALTER TABLE ONLY public.aggregation_tracking ATTACH PARTITION public.aggregation_tracking_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: aggregation_transient; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_transient (
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- wtid_raw bytea NOT NULL,
- CONSTRAINT aggregation_transient_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT aggregation_transient_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-)
-PARTITION BY HASH (wire_target_h_payto);
-
-
---
--- Name: TABLE aggregation_transient; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.aggregation_transient IS 'aggregations currently happening (lacking wire_out, usually because the amount is too low); this table is not replicated';
-
-
---
--- Name: COLUMN aggregation_transient.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_transient.amount_val IS 'Sum of all of the aggregated deposits (without deposit fees)';
-
-
---
--- Name: COLUMN aggregation_transient.wtid_raw; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_transient.wtid_raw IS 'identifier of the wire transfer';
-
-
---
--- Name: aggregation_transient_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_transient_default (
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- wtid_raw bytea NOT NULL,
- CONSTRAINT aggregation_transient_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT aggregation_transient_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-);
-ALTER TABLE ONLY public.aggregation_transient ATTACH PARTITION public.aggregation_transient_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: app_bankaccount; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_bankaccount (
- is_public boolean NOT NULL,
- account_no integer NOT NULL,
- balance character varying NOT NULL,
- user_id integer NOT NULL
-);
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.app_bankaccount_account_no_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.app_bankaccount_account_no_seq OWNED BY public.app_bankaccount.account_no;
-
-
---
--- Name: app_banktransaction; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_banktransaction (
- id bigint NOT NULL,
- amount character varying NOT NULL,
- subject character varying(200) NOT NULL,
- date timestamp with time zone NOT NULL,
- cancelled boolean NOT NULL,
- request_uid character varying(128) NOT NULL,
- credit_account_id integer NOT NULL,
- debit_account_id integer NOT NULL
-);
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.app_banktransaction_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.app_banktransaction_id_seq OWNED BY public.app_banktransaction.id;
-
-
---
--- Name: app_talerwithdrawoperation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_talerwithdrawoperation (
- withdraw_id uuid NOT NULL,
- amount character varying NOT NULL,
- selection_done boolean NOT NULL,
- confirmation_done boolean NOT NULL,
- aborted boolean NOT NULL,
- selected_reserve_pub text,
- selected_exchange_account_id integer,
- withdraw_account_id integer NOT NULL
-);
-
-
---
--- Name: auditor_balance_summary; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_balance_summary (
- master_pub bytea NOT NULL,
- denom_balance_val bigint NOT NULL,
- denom_balance_frac integer NOT NULL,
- deposit_fee_balance_val bigint NOT NULL,
- deposit_fee_balance_frac integer NOT NULL,
- melt_fee_balance_val bigint NOT NULL,
- melt_fee_balance_frac integer NOT NULL,
- refund_fee_balance_val bigint NOT NULL,
- refund_fee_balance_frac integer NOT NULL,
- risk_val bigint NOT NULL,
- risk_frac integer NOT NULL,
- loss_val bigint NOT NULL,
- loss_frac integer NOT NULL,
- irregular_recoup_val bigint NOT NULL,
- irregular_recoup_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_balance_summary; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_balance_summary IS 'the sum of the outstanding coins from auditor_denomination_pending (denom_pubs must belong to the respectives exchange master public key); it represents the auditor_balance_summary of the exchange at this point (modulo unexpected historic_loss-style events where denomination keys are compromised)';
-
-
---
--- Name: auditor_denom_sigs; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_denom_sigs (
- auditor_denom_serial bigint NOT NULL,
- auditor_uuid bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- auditor_sig bytea,
- CONSTRAINT auditor_denom_sigs_auditor_sig_check CHECK ((length(auditor_sig) = 64))
-);
-
-
---
--- Name: TABLE auditor_denom_sigs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_denom_sigs IS 'Table with auditor signatures on exchange denomination keys.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.auditor_uuid; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.auditor_uuid IS 'Identifies the auditor.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.denominations_serial IS 'Denomination the signature is for.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.auditor_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.auditor_sig IS 'Signature of the auditor, of purpose TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS.';
-
-
---
--- Name: auditor_denom_sigs_auditor_denom_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.auditor_denom_sigs ALTER COLUMN auditor_denom_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.auditor_denom_sigs_auditor_denom_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: auditor_denomination_pending; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_denomination_pending (
- denom_pub_hash bytea NOT NULL,
- denom_balance_val bigint NOT NULL,
- denom_balance_frac integer NOT NULL,
- denom_loss_val bigint NOT NULL,
- denom_loss_frac integer NOT NULL,
- num_issued bigint NOT NULL,
- denom_risk_val bigint NOT NULL,
- denom_risk_frac integer NOT NULL,
- recoup_loss_val bigint NOT NULL,
- recoup_loss_frac integer NOT NULL,
- CONSTRAINT auditor_denomination_pending_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64))
-);
-
-
---
--- Name: TABLE auditor_denomination_pending; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_denomination_pending IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
-
-
---
--- Name: COLUMN auditor_denomination_pending.num_issued; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.num_issued IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
-
-
---
--- Name: COLUMN auditor_denomination_pending.denom_risk_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.denom_risk_val IS 'amount that could theoretically be lost in the future due to recoup operations';
-
-
---
--- Name: COLUMN auditor_denomination_pending.recoup_loss_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.recoup_loss_val IS 'amount actually lost due to recoup operations past revocation';
-
-
---
--- Name: auditor_exchange_signkeys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_exchange_signkeys (
- master_pub bytea NOT NULL,
- ep_start bigint NOT NULL,
- ep_expire bigint NOT NULL,
- ep_end bigint NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT auditor_exchange_signkeys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT auditor_exchange_signkeys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE auditor_exchange_signkeys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_exchange_signkeys IS 'list of the online signing keys of exchanges we are auditing';
-
-
---
--- Name: auditor_exchanges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_exchanges (
- master_pub bytea NOT NULL,
- exchange_url character varying NOT NULL,
- CONSTRAINT auditor_exchanges_master_pub_check CHECK ((length(master_pub) = 32))
-);
-
-
---
--- Name: TABLE auditor_exchanges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_exchanges IS 'list of the exchanges we are auditing';
-
-
---
--- Name: auditor_historic_denomination_revenue; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_historic_denomination_revenue (
- master_pub bytea NOT NULL,
- denom_pub_hash bytea NOT NULL,
- revenue_timestamp bigint NOT NULL,
- revenue_balance_val bigint NOT NULL,
- revenue_balance_frac integer NOT NULL,
- loss_balance_val bigint NOT NULL,
- loss_balance_frac integer NOT NULL,
- CONSTRAINT auditor_historic_denomination_revenue_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64))
-);
-
-
---
--- Name: TABLE auditor_historic_denomination_revenue; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_historic_denomination_revenue IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
-
-
---
--- Name: COLUMN auditor_historic_denomination_revenue.revenue_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_historic_denomination_revenue.revenue_balance_val IS 'the sum of all of the profits we made on the coin except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
-
-
---
--- Name: auditor_historic_reserve_summary; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_historic_reserve_summary (
- master_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- reserve_profits_val bigint NOT NULL,
- reserve_profits_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_historic_reserve_summary; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_historic_reserve_summary IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
-
-
---
--- Name: auditor_predicted_result; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_predicted_result (
- master_pub bytea NOT NULL,
- balance_val bigint NOT NULL,
- balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_predicted_result; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_predicted_result IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance. This is the final amount that the exchange should have in its bank account right now.';
-
-
---
--- Name: auditor_progress_aggregation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_aggregation (
- master_pub bytea NOT NULL,
- last_wire_out_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_aggregation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_aggregation IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_coin; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_coin (
- master_pub bytea NOT NULL,
- last_withdraw_serial_id bigint DEFAULT 0 NOT NULL,
- last_deposit_serial_id bigint DEFAULT 0 NOT NULL,
- last_melt_serial_id bigint DEFAULT 0 NOT NULL,
- last_refund_serial_id bigint DEFAULT 0 NOT NULL,
- last_recoup_serial_id bigint DEFAULT 0 NOT NULL,
- last_recoup_refresh_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_deposits_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_refunds_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_coin; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_coin IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_deposit_confirmation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_deposit_confirmation (
- master_pub bytea NOT NULL,
- last_deposit_confirmation_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_deposit_confirmation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_deposit_confirmation IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_reserve (
- master_pub bytea NOT NULL,
- last_reserve_in_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_out_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_recoup_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_close_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_merges_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_deposits_serial_id bigint DEFAULT 0 NOT NULL,
- last_account_merges_serial_id bigint DEFAULT 0 NOT NULL,
- last_history_requests_serial_id bigint DEFAULT 0 NOT NULL,
- last_close_requests_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_reserve IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_reserve_balance; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_reserve_balance (
- master_pub bytea NOT NULL,
- reserve_balance_val bigint NOT NULL,
- reserve_balance_frac integer NOT NULL,
- withdraw_fee_balance_val bigint NOT NULL,
- withdraw_fee_balance_frac integer NOT NULL,
- purse_fee_balance_val bigint NOT NULL,
- purse_fee_balance_frac integer NOT NULL,
- history_fee_balance_val bigint NOT NULL,
- history_fee_balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_reserve_balance; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_reserve_balance IS 'sum of the balances of all customer reserves (by exchange master public key)';
-
-
---
--- Name: auditor_reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_reserves (
- reserve_pub bytea NOT NULL,
- master_pub bytea NOT NULL,
- reserve_balance_val bigint NOT NULL,
- reserve_balance_frac integer NOT NULL,
- withdraw_fee_balance_val bigint NOT NULL,
- withdraw_fee_balance_frac integer NOT NULL,
- expiration_date bigint NOT NULL,
- auditor_reserves_rowid bigint NOT NULL,
- origin_account text,
- CONSTRAINT auditor_reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-
-
---
--- Name: TABLE auditor_reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_reserves IS 'all of the customer reserves and their respective balances that the auditor is aware of';
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auditor_reserves_auditor_reserves_rowid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auditor_reserves_auditor_reserves_rowid_seq OWNED BY public.auditor_reserves.auditor_reserves_rowid;
-
-
---
--- Name: auditor_wire_fee_balance; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_wire_fee_balance (
- master_pub bytea NOT NULL,
- wire_fee_balance_val bigint NOT NULL,
- wire_fee_balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_wire_fee_balance; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_wire_fee_balance IS 'sum of the balances of all wire fees (by exchange master public key)';
-
-
---
--- Name: auditors; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditors (
- auditor_uuid bigint NOT NULL,
- auditor_pub bytea NOT NULL,
- auditor_name character varying NOT NULL,
- auditor_url character varying NOT NULL,
- is_active boolean NOT NULL,
- last_change bigint NOT NULL,
- CONSTRAINT auditors_auditor_pub_check CHECK ((length(auditor_pub) = 32))
-);
-
-
---
--- Name: TABLE auditors; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditors IS 'Table with auditors the exchange uses or has used in the past. Entries never expire as we need to remember the last_change column indefinitely.';
-
-
---
--- Name: COLUMN auditors.auditor_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.auditor_pub IS 'Public key of the auditor.';
-
-
---
--- Name: COLUMN auditors.auditor_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.auditor_url IS 'The base URL of the auditor.';
-
-
---
--- Name: COLUMN auditors.is_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.is_active IS 'true if we are currently supporting the use of this auditor.';
-
-
---
--- Name: COLUMN auditors.last_change; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.last_change IS 'Latest time when active status changed. Used to detect replays of old messages.';
-
-
---
--- Name: auditors_auditor_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.auditors ALTER COLUMN auditor_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.auditors_auditor_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: auth_group; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_group (
- id integer NOT NULL,
- name character varying(150) NOT NULL
-);
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_group_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_group_id_seq OWNED BY public.auth_group.id;
-
-
---
--- Name: auth_group_permissions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_group_permissions (
- id bigint NOT NULL,
- group_id integer NOT NULL,
- permission_id integer NOT NULL
-);
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_group_permissions_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_group_permissions_id_seq OWNED BY public.auth_group_permissions.id;
-
-
---
--- Name: auth_permission; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_permission (
- id integer NOT NULL,
- name character varying(255) NOT NULL,
- content_type_id integer NOT NULL,
- codename character varying(100) NOT NULL
-);
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_permission_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_permission_id_seq OWNED BY public.auth_permission.id;
-
-
---
--- Name: auth_user; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user (
- id integer NOT NULL,
- password character varying(128) NOT NULL,
- last_login timestamp with time zone,
- is_superuser boolean NOT NULL,
- username character varying(150) NOT NULL,
- first_name character varying(150) NOT NULL,
- last_name character varying(150) NOT NULL,
- email character varying(254) NOT NULL,
- is_staff boolean NOT NULL,
- is_active boolean NOT NULL,
- date_joined timestamp with time zone NOT NULL
-);
-
-
---
--- Name: auth_user_groups; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user_groups (
- id bigint NOT NULL,
- user_id integer NOT NULL,
- group_id integer NOT NULL
-);
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_groups_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_groups_id_seq OWNED BY public.auth_user_groups.id;
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_id_seq OWNED BY public.auth_user.id;
-
-
---
--- Name: auth_user_user_permissions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user_user_permissions (
- id bigint NOT NULL,
- user_id integer NOT NULL,
- permission_id integer NOT NULL
-);
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_user_permissions_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_user_permissions_id_seq OWNED BY public.auth_user_user_permissions.id;
-
-
---
--- Name: close_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.close_requests (
- close_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- close_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- close_val bigint NOT NULL,
- close_frac integer NOT NULL,
- CONSTRAINT close_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT close_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE close_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.close_requests IS 'Explicit requests by a reserve owner to close a reserve immediately';
-
-
---
--- Name: COLUMN close_requests.close_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.close_timestamp IS 'When the request was created by the client';
-
-
---
--- Name: COLUMN close_requests.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.reserve_sig IS 'Signature affirming that the reserve is to be closed';
-
-
---
--- Name: COLUMN close_requests.close_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.close_val IS 'Balance of the reserve at the time of closing, to be wired to the associated bank account (minus the closing fee)';
-
-
---
--- Name: close_requests_close_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.close_requests ALTER COLUMN close_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.close_requests_close_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: close_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.close_requests_default (
- close_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- close_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- close_val bigint NOT NULL,
- close_frac integer NOT NULL,
- CONSTRAINT close_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT close_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.close_requests ATTACH PARTITION public.close_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: contracts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.contracts (
- contract_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- pub_ckey bytea NOT NULL,
- contract_sig bytea NOT NULL,
- e_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- CONSTRAINT contracts_contract_sig_check CHECK ((length(contract_sig) = 64)),
- CONSTRAINT contracts_pub_ckey_check CHECK ((length(pub_ckey) = 32)),
- CONSTRAINT contracts_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE contracts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.contracts IS 'encrypted contracts associated with purses';
-
-
---
--- Name: COLUMN contracts.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.purse_pub IS 'public key of the purse that the contract is associated with';
-
-
---
--- Name: COLUMN contracts.pub_ckey; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.pub_ckey IS 'Public ECDH key used to encrypt the contract, to be used with the purse private key for decryption';
-
-
---
--- Name: COLUMN contracts.contract_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.contract_sig IS 'signature over the encrypted contract by the purse contract key';
-
-
---
--- Name: COLUMN contracts.e_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.e_contract IS 'AES-GCM encrypted contract terms (contains gzip compressed JSON after decryption)';
-
-
---
--- Name: contracts_contract_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.contracts ALTER COLUMN contract_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.contracts_contract_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: contracts_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.contracts_default (
- contract_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- pub_ckey bytea NOT NULL,
- contract_sig bytea NOT NULL,
- e_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- CONSTRAINT contracts_contract_sig_check CHECK ((length(contract_sig) = 64)),
- CONSTRAINT contracts_pub_ckey_check CHECK ((length(pub_ckey) = 32)),
- CONSTRAINT contracts_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.contracts ATTACH PARTITION public.contracts_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: cs_nonce_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.cs_nonce_locks (
- cs_nonce_lock_serial_id bigint NOT NULL,
- nonce bytea NOT NULL,
- op_hash bytea NOT NULL,
- max_denomination_serial bigint NOT NULL,
- CONSTRAINT cs_nonce_locks_nonce_check CHECK ((length(nonce) = 32)),
- CONSTRAINT cs_nonce_locks_op_hash_check CHECK ((length(op_hash) = 64))
-)
-PARTITION BY HASH (nonce);
-
-
---
--- Name: TABLE cs_nonce_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.cs_nonce_locks IS 'ensures a Clause Schnorr client nonce is locked for use with an operation identified by a hash';
-
-
---
--- Name: COLUMN cs_nonce_locks.nonce; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.nonce IS 'actual nonce submitted by the client';
-
-
---
--- Name: COLUMN cs_nonce_locks.op_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.op_hash IS 'hash (RC for refresh, blind coin hash for withdraw) the nonce may be used with';
-
-
---
--- Name: COLUMN cs_nonce_locks.max_denomination_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.max_denomination_serial IS 'Maximum number of a CS denomination serial the nonce could be used with, for GC';
-
-
---
--- Name: cs_nonce_locks_cs_nonce_lock_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.cs_nonce_locks ALTER COLUMN cs_nonce_lock_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.cs_nonce_locks_cs_nonce_lock_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: cs_nonce_locks_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.cs_nonce_locks_default (
- cs_nonce_lock_serial_id bigint NOT NULL,
- nonce bytea NOT NULL,
- op_hash bytea NOT NULL,
- max_denomination_serial bigint NOT NULL,
- CONSTRAINT cs_nonce_locks_nonce_check CHECK ((length(nonce) = 32)),
- CONSTRAINT cs_nonce_locks_op_hash_check CHECK ((length(op_hash) = 64))
-);
-ALTER TABLE ONLY public.cs_nonce_locks ATTACH PARTITION public.cs_nonce_locks_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: denomination_revocations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.denomination_revocations (
- denom_revocations_serial_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT denomination_revocations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE denomination_revocations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.denomination_revocations IS 'remembering which denomination keys have been revoked';
-
-
---
--- Name: denomination_revocations_denom_revocations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.denomination_revocations ALTER COLUMN denom_revocations_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.denomination_revocations_denom_revocations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: denominations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.denominations (
- denominations_serial bigint NOT NULL,
- denom_pub_hash bytea NOT NULL,
- denom_type integer DEFAULT 1 NOT NULL,
- age_mask integer DEFAULT 0 NOT NULL,
- denom_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- valid_from bigint NOT NULL,
- expire_withdraw bigint NOT NULL,
- expire_deposit bigint NOT NULL,
- expire_legal bigint NOT NULL,
- coin_val bigint NOT NULL,
- coin_frac integer NOT NULL,
- fee_withdraw_val bigint NOT NULL,
- fee_withdraw_frac integer NOT NULL,
- fee_deposit_val bigint NOT NULL,
- fee_deposit_frac integer NOT NULL,
- fee_refresh_val bigint NOT NULL,
- fee_refresh_frac integer NOT NULL,
- fee_refund_val bigint NOT NULL,
- fee_refund_frac integer NOT NULL,
- CONSTRAINT denominations_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64)),
- CONSTRAINT denominations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE denominations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.denominations IS 'Main denominations table. All the valid denominations the exchange knows about.';
-
-
---
--- Name: COLUMN denominations.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.denominations_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN denominations.denom_type; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.denom_type IS 'determines cipher type for blind signatures used with this denomination; 0 is for RSA';
-
-
---
--- Name: COLUMN denominations.age_mask; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.age_mask IS 'bitmask with the age restrictions that are being used for this denomination; 0 if denomination does not support the use of age restrictions';
-
-
---
--- Name: denominations_denominations_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.denominations ALTER COLUMN denominations_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.denominations_denominations_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: deposit_confirmations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposit_confirmations (
- master_pub bytea NOT NULL,
- serial_id bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- h_extensions bytea NOT NULL,
- h_wire bytea NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- amount_without_fee_val bigint NOT NULL,
- amount_without_fee_frac integer NOT NULL,
- coin_pub bytea NOT NULL,
- merchant_pub bytea NOT NULL,
- exchange_sig bytea NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT deposit_confirmations_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposit_confirmations_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT deposit_confirmations_exchange_sig_check CHECK ((length(exchange_sig) = 64)),
- CONSTRAINT deposit_confirmations_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposit_confirmations_h_contract_terms_check1 CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposit_confirmations_h_wire_check CHECK ((length(h_wire) = 64)),
- CONSTRAINT deposit_confirmations_master_sig_check CHECK ((length(master_sig) = 64)),
- CONSTRAINT deposit_confirmations_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-
-
---
--- Name: TABLE deposit_confirmations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposit_confirmations IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.deposit_confirmations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.deposit_confirmations_serial_id_seq OWNED BY public.deposit_confirmations.serial_id;
-
-
---
--- Name: deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits (
- deposit_serial_id bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wallet_timestamp bigint NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- coin_sig bytea NOT NULL,
- wire_salt bytea NOT NULL,
- wire_target_h_payto bytea,
- done boolean DEFAULT false NOT NULL,
- extension_blocked boolean DEFAULT false NOT NULL,
- extension_details_serial_id bigint,
- CONSTRAINT deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT deposits_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposits_merchant_pub_check CHECK ((length(merchant_pub) = 32)),
- CONSTRAINT deposits_wire_salt_check CHECK ((length(wire_salt) = 16)),
- CONSTRAINT deposits_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits IS 'Deposits we have received and for which we need to make (aggregate) wire transfers (and manage refunds).';
-
-
---
--- Name: COLUMN deposits.shard; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.shard IS 'Used for load sharding in the materialized indices. Should be set based on merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.';
-
-
---
--- Name: COLUMN deposits.known_coin_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.known_coin_id IS 'Used for garbage collection';
-
-
---
--- Name: COLUMN deposits.wire_salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.wire_salt IS 'Salt used when hashing the payto://-URI to get the h_wire';
-
-
---
--- Name: COLUMN deposits.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.wire_target_h_payto IS 'Identifies the target bank account and KYC status';
-
-
---
--- Name: COLUMN deposits.done; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.done IS 'Set to TRUE once we have included this deposit in some aggregate wire transfer to the merchant';
-
-
---
--- Name: COLUMN deposits.extension_blocked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.extension_blocked IS 'True if the aggregation of the deposit is currently blocked by some extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.';
-
-
---
--- Name: COLUMN deposits.extension_details_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.extension_details_serial_id IS 'References extensions table, NULL if extensions are not used';
-
-
---
--- Name: deposits_by_ready; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_by_ready (
- wire_deadline bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_by_ready_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY RANGE (wire_deadline);
-
-
---
--- Name: TABLE deposits_by_ready; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits_by_ready IS 'Enables fast lookups for deposits_get_ready, auto-populated via TRIGGER below';
-
-
---
--- Name: deposits_by_ready_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_by_ready_default (
- wire_deadline bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_by_ready_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.deposits_by_ready ATTACH PARTITION public.deposits_by_ready_default DEFAULT;
-
-
---
--- Name: deposits_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_default (
- deposit_serial_id bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wallet_timestamp bigint NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- coin_sig bytea NOT NULL,
- wire_salt bytea NOT NULL,
- wire_target_h_payto bytea,
- done boolean DEFAULT false NOT NULL,
- extension_blocked boolean DEFAULT false NOT NULL,
- extension_details_serial_id bigint,
- CONSTRAINT deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT deposits_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposits_merchant_pub_check CHECK ((length(merchant_pub) = 32)),
- CONSTRAINT deposits_wire_salt_check CHECK ((length(wire_salt) = 16)),
- CONSTRAINT deposits_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-);
-ALTER TABLE ONLY public.deposits ATTACH PARTITION public.deposits_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: deposits_deposit_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.deposits ALTER COLUMN deposit_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.deposits_deposit_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: deposits_for_matching; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_for_matching (
- refund_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_for_matching_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_for_matching_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-)
-PARTITION BY RANGE (refund_deadline);
-
-
---
--- Name: TABLE deposits_for_matching; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits_for_matching IS 'Enables fast lookups for deposits_iterate_matching, auto-populated via TRIGGER below';
-
-
---
--- Name: deposits_for_matching_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_for_matching_default (
- refund_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_for_matching_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_for_matching_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-ALTER TABLE ONLY public.deposits_for_matching ATTACH PARTITION public.deposits_for_matching_default DEFAULT;
-
-
---
--- Name: django_content_type; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_content_type (
- id integer NOT NULL,
- app_label character varying(100) NOT NULL,
- model character varying(100) NOT NULL
-);
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.django_content_type_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.django_content_type_id_seq OWNED BY public.django_content_type.id;
-
-
---
--- Name: django_migrations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_migrations (
- id bigint NOT NULL,
- app character varying(255) NOT NULL,
- name character varying(255) NOT NULL,
- applied timestamp with time zone NOT NULL
-);
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.django_migrations_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.django_migrations_id_seq OWNED BY public.django_migrations.id;
-
-
---
--- Name: django_session; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_session (
- session_key character varying(40) NOT NULL,
- session_data text NOT NULL,
- expire_date timestamp with time zone NOT NULL
-);
-
-
---
--- Name: exchange_sign_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.exchange_sign_keys (
- esk_serial bigint NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- valid_from bigint NOT NULL,
- expire_sign bigint NOT NULL,
- expire_legal bigint NOT NULL,
- CONSTRAINT exchange_sign_keys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT exchange_sign_keys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE exchange_sign_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.exchange_sign_keys IS 'Table with master public key signatures on exchange online signing keys.';
-
-
---
--- Name: COLUMN exchange_sign_keys.exchange_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.exchange_pub IS 'Public online signing key of the exchange.';
-
-
---
--- Name: COLUMN exchange_sign_keys.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.master_sig IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
-
-
---
--- Name: COLUMN exchange_sign_keys.valid_from; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.valid_from IS 'Time when this online signing key will first be used to sign messages.';
-
-
---
--- Name: COLUMN exchange_sign_keys.expire_sign; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.expire_sign IS 'Time when this online signing key will no longer be used to sign.';
-
-
---
--- Name: COLUMN exchange_sign_keys.expire_legal; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.expire_legal IS 'Time when this online signing key legally expires.';
-
-
---
--- Name: exchange_sign_keys_esk_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.exchange_sign_keys ALTER COLUMN esk_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.exchange_sign_keys_esk_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: extension_details; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extension_details (
- extension_details_serial_id bigint NOT NULL,
- extension_options character varying
-)
-PARTITION BY HASH (extension_details_serial_id);
-
-
---
--- Name: TABLE extension_details; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.extension_details IS 'Extensions that were provided with deposits (not yet used).';
-
-
---
--- Name: COLUMN extension_details.extension_options; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extension_details.extension_options IS 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the extensions supported by the exchange.';
-
-
---
--- Name: extension_details_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extension_details_default (
- extension_details_serial_id bigint NOT NULL,
- extension_options character varying
-);
-ALTER TABLE ONLY public.extension_details ATTACH PARTITION public.extension_details_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: extension_details_extension_details_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.extension_details ALTER COLUMN extension_details_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.extension_details_extension_details_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: extensions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extensions (
- extension_id bigint NOT NULL,
- name character varying NOT NULL,
- config bytea
-);
-
-
---
--- Name: TABLE extensions; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.extensions IS 'Configurations of the activated extensions';
-
-
---
--- Name: COLUMN extensions.name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extensions.name IS 'Name of the extension';
-
-
---
--- Name: COLUMN extensions.config; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extensions.config IS 'Configuration of the extension as JSON-blob, maybe NULL';
-
-
---
--- Name: extensions_extension_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.extensions ALTER COLUMN extension_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.extensions_extension_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: global_fee; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.global_fee (
- global_fee_serial bigint NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- kyc_fee_val bigint NOT NULL,
- kyc_fee_frac integer NOT NULL,
- account_fee_val bigint NOT NULL,
- account_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- purse_timeout bigint NOT NULL,
- kyc_timeout bigint NOT NULL,
- history_expiration bigint NOT NULL,
- purse_account_limit integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT global_fee_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE global_fee; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.global_fee IS 'list of the global fees of this exchange, by date';
-
-
---
--- Name: COLUMN global_fee.global_fee_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.global_fee.global_fee_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: global_fee_global_fee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.global_fee ALTER COLUMN global_fee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.global_fee_global_fee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: history_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.history_requests (
- history_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- request_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- CONSTRAINT history_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT history_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE history_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.history_requests IS 'Paid history requests issued by a client against a reserve';
-
-
---
--- Name: COLUMN history_requests.request_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.request_timestamp IS 'When was the history request made';
-
-
---
--- Name: COLUMN history_requests.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.reserve_sig IS 'Signature approving payment for the history request';
-
-
---
--- Name: COLUMN history_requests.history_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.history_fee_val IS 'History fee approved by the signature';
-
-
---
--- Name: history_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.history_requests_default (
- history_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- request_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- CONSTRAINT history_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT history_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.history_requests ATTACH PARTITION public.history_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: history_requests_history_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.history_requests ALTER COLUMN history_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.history_requests_history_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: known_coins; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.known_coins (
- known_coin_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_pub bytea NOT NULL,
- age_commitment_hash bytea,
- denom_sig bytea NOT NULL,
- remaining_val bigint DEFAULT 0 NOT NULL,
- remaining_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT known_coins_age_commitment_hash_check CHECK ((length(age_commitment_hash) = 32)),
- CONSTRAINT known_coins_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE known_coins; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.known_coins IS 'information about coins and their signatures, so we do not have to store the signatures more than once if a coin is involved in multiple operations';
-
-
---
--- Name: COLUMN known_coins.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.denominations_serial IS 'Denomination of the coin, determines the value of the original coin and applicable fees for coin-specific operations.';
-
-
---
--- Name: COLUMN known_coins.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.coin_pub IS 'EdDSA public key of the coin';
-
-
---
--- Name: COLUMN known_coins.age_commitment_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.age_commitment_hash IS 'Optional hash of the age commitment for age restrictions as per DD 24 (active if denom_type has the respective bit set)';
-
-
---
--- Name: COLUMN known_coins.denom_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.denom_sig IS 'This is the signature of the exchange that affirms that the coin is a valid coin. The specific signature type depends on denom_type of the denomination.';
-
-
---
--- Name: COLUMN known_coins.remaining_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.remaining_val IS 'Value of the coin that remains to be spent';
-
-
---
--- Name: known_coins_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.known_coins_default (
- known_coin_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_pub bytea NOT NULL,
- age_commitment_hash bytea,
- denom_sig bytea NOT NULL,
- remaining_val bigint DEFAULT 0 NOT NULL,
- remaining_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT known_coins_age_commitment_hash_check CHECK ((length(age_commitment_hash) = 32)),
- CONSTRAINT known_coins_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.known_coins ATTACH PARTITION public.known_coins_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: known_coins_known_coin_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.known_coins ALTER COLUMN known_coin_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.known_coins_known_coin_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_accounts (
- account_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- h_wire bytea NOT NULL,
- salt bytea NOT NULL,
- payto_uri character varying NOT NULL,
- active boolean NOT NULL,
- CONSTRAINT merchant_accounts_h_wire_check CHECK ((length(h_wire) = 64)),
- CONSTRAINT merchant_accounts_salt_check CHECK ((length(salt) = 16))
-);
-
-
---
--- Name: TABLE merchant_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_accounts IS 'bank accounts of the instances';
-
-
---
--- Name: COLUMN merchant_accounts.h_wire; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.h_wire IS 'salted hash of payto_uri';
-
-
---
--- Name: COLUMN merchant_accounts.salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.salt IS 'salt used when hashing payto_uri into h_wire';
-
-
---
--- Name: COLUMN merchant_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.payto_uri IS 'payto URI of a merchant bank account';
-
-
---
--- Name: COLUMN merchant_accounts.active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.active IS 'true if we actively use this bank account, false if it is just kept around for older contracts to refer to';
-
-
---
--- Name: merchant_accounts_account_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_accounts ALTER COLUMN account_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_accounts_account_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_contract_terms; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_contract_terms (
- order_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- order_id character varying NOT NULL,
- contract_terms bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- creation_time bigint NOT NULL,
- pay_deadline bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- paid boolean DEFAULT false NOT NULL,
- wired boolean DEFAULT false NOT NULL,
- fulfillment_url character varying,
- session_id character varying DEFAULT ''::character varying NOT NULL,
- claim_token bytea NOT NULL,
- CONSTRAINT merchant_contract_terms_claim_token_check CHECK ((length(claim_token) = 16)),
- CONSTRAINT merchant_contract_terms_h_contract_terms_check CHECK ((length(h_contract_terms) = 64))
-);
-
-
---
--- Name: TABLE merchant_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_contract_terms IS 'Contracts are orders that have been claimed by a wallet';
-
-
---
--- Name: COLUMN merchant_contract_terms.merchant_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.merchant_serial IS 'Identifies the instance offering the contract';
-
-
---
--- Name: COLUMN merchant_contract_terms.order_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.order_id IS 'Not a foreign key into merchant_orders because paid contracts persist after expiration';
-
-
---
--- Name: COLUMN merchant_contract_terms.contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.contract_terms IS 'These contract terms include the wallet nonce';
-
-
---
--- Name: COLUMN merchant_contract_terms.h_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.h_contract_terms IS 'Hash over contract_terms';
-
-
---
--- Name: COLUMN merchant_contract_terms.pay_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.pay_deadline IS 'How long is the offer valid. After this time, the order can be garbage collected';
-
-
---
--- Name: COLUMN merchant_contract_terms.refund_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.refund_deadline IS 'By what times do refunds have to be approved (useful to reject refund requests)';
-
-
---
--- Name: COLUMN merchant_contract_terms.paid; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.paid IS 'true implies the customer paid for this contract; order should be DELETEd from merchant_orders once paid is set to release merchant_order_locks; paid remains true even if the payment was later refunded';
-
-
---
--- Name: COLUMN merchant_contract_terms.wired; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.wired IS 'true implies the exchange wired us the full amount for all non-refunded payments under this contract';
-
-
---
--- Name: COLUMN merchant_contract_terms.fulfillment_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.fulfillment_url IS 'also included in contract_terms, but we need it here to SELECT on it during repurchase detection; can be NULL if the contract has no fulfillment URL';
-
-
---
--- Name: COLUMN merchant_contract_terms.session_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.session_id IS 'last session_id from we confirmed the paying client to use, empty string for none';
-
-
---
--- Name: COLUMN merchant_contract_terms.claim_token; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.claim_token IS 'Token optionally used to access the status of the order. All zeros (not NULL) if not used';
-
-
---
--- Name: merchant_deposit_to_transfer; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_deposit_to_transfer (
- deposit_serial bigint NOT NULL,
- coin_contribution_value_val bigint NOT NULL,
- coin_contribution_value_frac integer NOT NULL,
- credit_serial bigint NOT NULL,
- execution_time bigint NOT NULL,
- signkey_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- CONSTRAINT merchant_deposit_to_transfer_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_deposit_to_transfer; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_deposit_to_transfer IS 'Mapping of deposits to (possibly unconfirmed) wire transfers; NOTE: not used yet';
-
-
---
--- Name: COLUMN merchant_deposit_to_transfer.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposit_to_transfer.execution_time IS 'Execution time as claimed by the exchange, roughly matches time seen by merchant';
-
-
---
--- Name: merchant_deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_deposits (
- deposit_serial bigint NOT NULL,
- order_serial bigint,
- deposit_timestamp bigint NOT NULL,
- coin_pub bytea NOT NULL,
- exchange_url character varying NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- deposit_fee_val bigint NOT NULL,
- deposit_fee_frac integer NOT NULL,
- refund_fee_val bigint NOT NULL,
- refund_fee_frac integer NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- signkey_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- account_serial bigint NOT NULL,
- CONSTRAINT merchant_deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT merchant_deposits_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_deposits IS 'Refunds approved by the merchant (backoffice) logic, excludes abort refunds';
-
-
---
--- Name: COLUMN merchant_deposits.deposit_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.deposit_timestamp IS 'Time when the exchange generated the deposit confirmation';
-
-
---
--- Name: COLUMN merchant_deposits.wire_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.wire_fee_val IS 'We MAY want to see if we should try to get this via merchant_exchange_wire_fees (not sure, may be too complicated with the date range, etc.)';
-
-
---
--- Name: COLUMN merchant_deposits.signkey_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.signkey_serial IS 'Online signing key of the exchange on the deposit confirmation';
-
-
---
--- Name: COLUMN merchant_deposits.exchange_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.exchange_sig IS 'Signature of the exchange over the deposit confirmation';
-
-
---
--- Name: merchant_deposits_deposit_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_deposits ALTER COLUMN deposit_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_deposits_deposit_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_exchange_signing_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_exchange_signing_keys (
- signkey_serial bigint NOT NULL,
- master_pub bytea NOT NULL,
- exchange_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- expire_date bigint NOT NULL,
- end_date bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT merchant_exchange_signing_keys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT merchant_exchange_signing_keys_master_pub_check CHECK ((length(master_pub) = 32)),
- CONSTRAINT merchant_exchange_signing_keys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_exchange_signing_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_exchange_signing_keys IS 'Here we store proofs of the exchange online signing keys being signed by the exchange master key';
-
-
---
--- Name: COLUMN merchant_exchange_signing_keys.master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_exchange_signing_keys.master_pub IS 'Master public key of the exchange with these online signing keys';
-
-
---
--- Name: merchant_exchange_signing_keys_signkey_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_exchange_signing_keys ALTER COLUMN signkey_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_exchange_signing_keys_signkey_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_exchange_wire_fees; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_exchange_wire_fees (
- wirefee_serial bigint NOT NULL,
- master_pub bytea NOT NULL,
- h_wire_method bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT merchant_exchange_wire_fees_h_wire_method_check CHECK ((length(h_wire_method) = 64)),
- CONSTRAINT merchant_exchange_wire_fees_master_pub_check CHECK ((length(master_pub) = 32)),
- CONSTRAINT merchant_exchange_wire_fees_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_exchange_wire_fees; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_exchange_wire_fees IS 'Here we store proofs of the wire fee structure of the various exchanges';
-
-
---
--- Name: COLUMN merchant_exchange_wire_fees.master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_exchange_wire_fees.master_pub IS 'Master public key of the exchange with these wire fees';
-
-
---
--- Name: merchant_exchange_wire_fees_wirefee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_exchange_wire_fees ALTER COLUMN wirefee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_exchange_wire_fees_wirefee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_instances; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_instances (
- merchant_serial bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- auth_hash bytea,
- auth_salt bytea,
- merchant_id character varying NOT NULL,
- merchant_name character varying NOT NULL,
- address bytea NOT NULL,
- jurisdiction bytea NOT NULL,
- default_max_deposit_fee_val bigint NOT NULL,
- default_max_deposit_fee_frac integer NOT NULL,
- default_max_wire_fee_val bigint NOT NULL,
- default_max_wire_fee_frac integer NOT NULL,
- default_wire_fee_amortization integer NOT NULL,
- default_wire_transfer_delay bigint NOT NULL,
- default_pay_delay bigint NOT NULL,
- website character varying,
- email character varying,
- logo bytea,
- CONSTRAINT merchant_instances_auth_hash_check CHECK ((length(auth_hash) = 64)),
- CONSTRAINT merchant_instances_auth_salt_check CHECK ((length(auth_salt) = 32)),
- CONSTRAINT merchant_instances_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-
-
---
--- Name: TABLE merchant_instances; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_instances IS 'all the instances supported by this backend';
-
-
---
--- Name: COLUMN merchant_instances.auth_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.auth_hash IS 'hash used for merchant back office Authorization, NULL for no check';
-
-
---
--- Name: COLUMN merchant_instances.auth_salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.auth_salt IS 'salt to use when hashing Authorization header before comparing with auth_hash';
-
-
---
--- Name: COLUMN merchant_instances.merchant_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.merchant_id IS 'identifier of the merchant as used in the base URL (required)';
-
-
---
--- Name: COLUMN merchant_instances.merchant_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.merchant_name IS 'legal name of the merchant as a simple string (required)';
-
-
---
--- Name: COLUMN merchant_instances.address; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.address IS 'physical address of the merchant as a Location in JSON format (required)';
-
-
---
--- Name: COLUMN merchant_instances.jurisdiction; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.jurisdiction IS 'jurisdiction of the merchant as a Location in JSON format (required)';
-
-
---
--- Name: COLUMN merchant_instances.website; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.website IS 'merchant site URL';
-
-
---
--- Name: COLUMN merchant_instances.email; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.email IS 'email';
-
-
---
--- Name: COLUMN merchant_instances.logo; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.logo IS 'data image url';
-
-
---
--- Name: merchant_instances_merchant_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_instances ALTER COLUMN merchant_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_instances_merchant_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_inventory; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_inventory (
- product_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- product_id character varying NOT NULL,
- description character varying NOT NULL,
- description_i18n bytea NOT NULL,
- unit character varying NOT NULL,
- image bytea NOT NULL,
- taxes bytea NOT NULL,
- price_val bigint NOT NULL,
- price_frac integer NOT NULL,
- total_stock bigint NOT NULL,
- total_sold bigint DEFAULT 0 NOT NULL,
- total_lost bigint DEFAULT 0 NOT NULL,
- address bytea NOT NULL,
- next_restock bigint NOT NULL,
- minimum_age integer DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE merchant_inventory; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_inventory IS 'products offered by the merchant (may be incomplete, frontend can override)';
-
-
---
--- Name: COLUMN merchant_inventory.description; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.description IS 'Human-readable product description';
-
-
---
--- Name: COLUMN merchant_inventory.description_i18n; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.description_i18n IS 'JSON map from IETF BCP 47 language tags to localized descriptions';
-
-
---
--- Name: COLUMN merchant_inventory.unit; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.unit IS 'Unit of sale for the product (liters, kilograms, packages)';
-
-
---
--- Name: COLUMN merchant_inventory.image; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.image IS 'NOT NULL, but can be 0 bytes; must contain an ImageDataUrl';
-
-
---
--- Name: COLUMN merchant_inventory.taxes; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.taxes IS 'JSON array containing taxes the merchant pays, must be JSON, but can be just "[]"';
-
-
---
--- Name: COLUMN merchant_inventory.price_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.price_val IS 'Current price of one unit of the product';
-
-
---
--- Name: COLUMN merchant_inventory.total_stock; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_stock IS 'A value of -1 is used for unlimited (electronic good), may never be lowered';
-
-
---
--- Name: COLUMN merchant_inventory.total_sold; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_sold IS 'Number of products sold, must be below total_stock, non-negative, may never be lowered';
-
-
---
--- Name: COLUMN merchant_inventory.total_lost; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_lost IS 'Number of products that used to be in stock but were lost (spoiled, damaged), may never be lowered; total_stock >= total_sold + total_lost must always hold';
-
-
---
--- Name: COLUMN merchant_inventory.address; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.address IS 'JSON formatted Location of where the product is stocked';
-
-
---
--- Name: COLUMN merchant_inventory.next_restock; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.next_restock IS 'GNUnet absolute time indicating when the next restock is expected. 0 for unknown.';
-
-
---
--- Name: COLUMN merchant_inventory.minimum_age; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.minimum_age IS 'Minimum age of the customer in years, to be used if an exchange supports the age restriction extension.';
-
-
---
--- Name: merchant_inventory_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_inventory_locks (
- product_serial bigint NOT NULL,
- lock_uuid bytea NOT NULL,
- total_locked bigint NOT NULL,
- expiration bigint NOT NULL,
- CONSTRAINT merchant_inventory_locks_lock_uuid_check CHECK ((length(lock_uuid) = 16))
-);
-
-
---
--- Name: TABLE merchant_inventory_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_inventory_locks IS 'locks on inventory helt by shopping carts; note that locks MAY not be honored if merchants increase total_lost for inventory';
-
-
---
--- Name: COLUMN merchant_inventory_locks.total_locked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory_locks.total_locked IS 'how many units of the product does this lock reserve';
-
-
---
--- Name: COLUMN merchant_inventory_locks.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory_locks.expiration IS 'when does this lock automatically expire (if no order is created)';
-
-
---
--- Name: merchant_inventory_product_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_inventory ALTER COLUMN product_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_inventory_product_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_keys (
- merchant_priv bytea NOT NULL,
- merchant_serial bigint NOT NULL,
- CONSTRAINT merchant_keys_merchant_priv_check CHECK ((length(merchant_priv) = 32))
-);
-
-
---
--- Name: TABLE merchant_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_keys IS 'private keys of instances that have not been deleted';
-
-
---
--- Name: merchant_kyc; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_kyc (
- kyc_serial_id bigint NOT NULL,
- kyc_timestamp bigint NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- exchange_sig bytea,
- exchange_pub bytea,
- exchange_kyc_serial bigint DEFAULT 0 NOT NULL,
- account_serial bigint NOT NULL,
- exchange_url character varying NOT NULL,
- CONSTRAINT merchant_kyc_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT merchant_kyc_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_kyc; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_kyc IS 'Status of the KYC process of a merchant account at an exchange';
-
-
---
--- Name: COLUMN merchant_kyc.kyc_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.kyc_timestamp IS 'Last time we checked our KYC status at the exchange. Useful to re-check if the status is very stale. Also the timestamp used for the exchange signature (if present).';
-
-
---
--- Name: COLUMN merchant_kyc.kyc_ok; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.kyc_ok IS 'true if the KYC check was passed successfully';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_sig IS 'signature of the exchange affirming the KYC passed (or NULL if exchange does not require KYC or not kyc_ok)';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_pub IS 'public key used with exchange_sig (or NULL if exchange_sig is NULL)';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_kyc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_kyc_serial IS 'Number to use in the KYC-endpoints of the exchange to check the KYC status or begin the KYC process. 0 if we do not know it yet.';
-
-
---
--- Name: COLUMN merchant_kyc.account_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.account_serial IS 'Which bank account of the merchant is the KYC status for';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_url IS 'Which exchange base URL is this KYC status valid for';
-
-
---
--- Name: merchant_kyc_kyc_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_kyc ALTER COLUMN kyc_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_kyc_kyc_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_order_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_order_locks (
- product_serial bigint NOT NULL,
- total_locked bigint NOT NULL,
- order_serial bigint NOT NULL
-);
-
-
---
--- Name: TABLE merchant_order_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_order_locks IS 'locks on orders awaiting claim and payment; note that locks MAY not be honored if merchants increase total_lost for inventory';
-
-
---
--- Name: COLUMN merchant_order_locks.total_locked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_order_locks.total_locked IS 'how many units of the product does this lock reserve';
-
-
---
--- Name: merchant_orders; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_orders (
- order_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- order_id character varying NOT NULL,
- claim_token bytea NOT NULL,
- h_post_data bytea NOT NULL,
- pay_deadline bigint NOT NULL,
- creation_time bigint NOT NULL,
- contract_terms bytea NOT NULL,
- CONSTRAINT merchant_orders_claim_token_check CHECK ((length(claim_token) = 16)),
- CONSTRAINT merchant_orders_h_post_data_check CHECK ((length(h_post_data) = 64))
-);
-
-
---
--- Name: TABLE merchant_orders; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_orders IS 'Orders we offered to a customer, but that have not yet been claimed';
-
-
---
--- Name: COLUMN merchant_orders.merchant_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.merchant_serial IS 'Identifies the instance offering the contract';
-
-
---
--- Name: COLUMN merchant_orders.claim_token; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.claim_token IS 'Token optionally used to authorize the wallet to claim the order. All zeros (not NULL) if not used';
-
-
---
--- Name: COLUMN merchant_orders.h_post_data; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.h_post_data IS 'Hash of the POST request that created this order, for idempotency checks';
-
-
---
--- Name: COLUMN merchant_orders.pay_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.pay_deadline IS 'How long is the offer valid. After this time, the order can be garbage collected';
-
-
---
--- Name: COLUMN merchant_orders.contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.contract_terms IS 'Claiming changes the contract_terms, hence we have no hash of the terms in this table';
-
-
---
--- Name: merchant_orders_order_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_orders ALTER COLUMN order_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_orders_order_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_refund_proofs; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_refund_proofs (
- refund_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- signkey_serial bigint NOT NULL,
- CONSTRAINT merchant_refund_proofs_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_refund_proofs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_refund_proofs IS 'Refunds confirmed by the exchange (not all approved refunds are grabbed by the wallet)';
-
-
---
--- Name: merchant_refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_refunds (
- refund_serial bigint NOT NULL,
- order_serial bigint NOT NULL,
- rtransaction_id bigint NOT NULL,
- refund_timestamp bigint NOT NULL,
- coin_pub bytea NOT NULL,
- reason character varying NOT NULL,
- refund_amount_val bigint NOT NULL,
- refund_amount_frac integer NOT NULL
-);
-
-
---
--- Name: COLUMN merchant_refunds.rtransaction_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_refunds.rtransaction_id IS 'Needed for uniqueness in case a refund is increased for the same order';
-
-
---
--- Name: COLUMN merchant_refunds.refund_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_refunds.refund_timestamp IS 'Needed for grouping of refunds in the wallet UI; has no semantics in the protocol (only for UX), but should be from the time when the merchant internally approved the refund';
-
-
---
--- Name: merchant_refunds_refund_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_refunds ALTER COLUMN refund_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_refunds_refund_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tip_pickup_signatures; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_pickup_signatures (
- pickup_serial bigint NOT NULL,
- coin_offset integer NOT NULL,
- blind_sig bytea NOT NULL
-);
-
-
---
--- Name: TABLE merchant_tip_pickup_signatures; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_pickup_signatures IS 'blind signatures we got from the exchange during the tip pickup';
-
-
---
--- Name: merchant_tip_pickups; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_pickups (
- pickup_serial bigint NOT NULL,
- tip_serial bigint NOT NULL,
- pickup_id bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT merchant_tip_pickups_pickup_id_check CHECK ((length(pickup_id) = 64))
-);
-
-
---
--- Name: TABLE merchant_tip_pickups; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_pickups IS 'tips that have been picked up';
-
-
---
--- Name: merchant_tip_pickups_pickup_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tip_pickups ALTER COLUMN pickup_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tip_pickups_pickup_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tip_reserve_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_reserve_keys (
- reserve_serial bigint NOT NULL,
- reserve_priv bytea NOT NULL,
- exchange_url character varying NOT NULL,
- payto_uri character varying,
- CONSTRAINT merchant_tip_reserve_keys_reserve_priv_check CHECK ((length(reserve_priv) = 32))
-);
-
-
---
--- Name: COLUMN merchant_tip_reserve_keys.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserve_keys.payto_uri IS 'payto:// URI used to fund the reserve, may be NULL once reserve is funded';
-
-
---
--- Name: merchant_tip_reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_reserves (
- reserve_serial bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- merchant_serial bigint NOT NULL,
- creation_time bigint NOT NULL,
- expiration bigint NOT NULL,
- merchant_initial_balance_val bigint NOT NULL,
- merchant_initial_balance_frac integer NOT NULL,
- exchange_initial_balance_val bigint DEFAULT 0 NOT NULL,
- exchange_initial_balance_frac integer DEFAULT 0 NOT NULL,
- tips_committed_val bigint DEFAULT 0 NOT NULL,
- tips_committed_frac integer DEFAULT 0 NOT NULL,
- tips_picked_up_val bigint DEFAULT 0 NOT NULL,
- tips_picked_up_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT merchant_tip_reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-
-
---
--- Name: TABLE merchant_tip_reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_reserves IS 'private keys of reserves that have not been deleted';
-
-
---
--- Name: COLUMN merchant_tip_reserves.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.expiration IS 'FIXME: EXCHANGE API needs to tell us when reserves close if we are to compute this';
-
-
---
--- Name: COLUMN merchant_tip_reserves.merchant_initial_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.merchant_initial_balance_val IS 'Set to the initial balance the merchant told us when creating the reserve';
-
-
---
--- Name: COLUMN merchant_tip_reserves.exchange_initial_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.exchange_initial_balance_val IS 'Set to the initial balance the exchange told us when we queried the reserve status';
-
-
---
--- Name: COLUMN merchant_tip_reserves.tips_committed_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.tips_committed_val IS 'Amount of outstanding approved tips that have not been picked up';
-
-
---
--- Name: COLUMN merchant_tip_reserves.tips_picked_up_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.tips_picked_up_val IS 'Total amount tips that have been picked up from this reserve';
-
-
---
--- Name: merchant_tip_reserves_reserve_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tip_reserves ALTER COLUMN reserve_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tip_reserves_reserve_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tips; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tips (
- tip_serial bigint NOT NULL,
- reserve_serial bigint NOT NULL,
- tip_id bytea NOT NULL,
- justification character varying NOT NULL,
- next_url character varying NOT NULL,
- expiration bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- picked_up_val bigint DEFAULT 0 NOT NULL,
- picked_up_frac integer DEFAULT 0 NOT NULL,
- was_picked_up boolean DEFAULT false NOT NULL,
- CONSTRAINT merchant_tips_tip_id_check CHECK ((length(tip_id) = 64))
-);
-
-
---
--- Name: TABLE merchant_tips; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tips IS 'tips that have been authorized';
-
-
---
--- Name: COLUMN merchant_tips.reserve_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.reserve_serial IS 'Reserve from which this tip is funded';
-
-
---
--- Name: COLUMN merchant_tips.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.expiration IS 'by when does the client have to pick up the tip';
-
-
---
--- Name: COLUMN merchant_tips.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.amount_val IS 'total transaction cost for all coins including withdraw fees';
-
-
---
--- Name: COLUMN merchant_tips.picked_up_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.picked_up_val IS 'Tip amount left to be picked up';
-
-
---
--- Name: merchant_tips_tip_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tips ALTER COLUMN tip_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tips_tip_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_transfer_signatures; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfer_signatures (
- credit_serial bigint NOT NULL,
- signkey_serial bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- credit_amount_val bigint NOT NULL,
- credit_amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- CONSTRAINT merchant_transfer_signatures_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_transfer_signatures; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfer_signatures IS 'table represents the main information returned from the /transfer request to the exchange.';
-
-
---
--- Name: COLUMN merchant_transfer_signatures.credit_amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_signatures.credit_amount_val IS 'actual value of the (aggregated) wire transfer, excluding the wire fee, according to the exchange';
-
-
---
--- Name: COLUMN merchant_transfer_signatures.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_signatures.execution_time IS 'Execution time as claimed by the exchange, roughly matches time seen by merchant';
-
-
---
--- Name: merchant_transfer_to_coin; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfer_to_coin (
- deposit_serial bigint NOT NULL,
- credit_serial bigint NOT NULL,
- offset_in_exchange_list bigint NOT NULL,
- exchange_deposit_value_val bigint NOT NULL,
- exchange_deposit_value_frac integer NOT NULL,
- exchange_deposit_fee_val bigint NOT NULL,
- exchange_deposit_fee_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE merchant_transfer_to_coin; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfer_to_coin IS 'Mapping of (credit) transfers to (deposited) coins';
-
-
---
--- Name: COLUMN merchant_transfer_to_coin.exchange_deposit_value_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_to_coin.exchange_deposit_value_val IS 'Deposit value as claimed by the exchange, should match our values in merchant_deposits minus refunds';
-
-
---
--- Name: COLUMN merchant_transfer_to_coin.exchange_deposit_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_to_coin.exchange_deposit_fee_val IS 'Deposit value as claimed by the exchange, should match our values in merchant_deposits';
-
-
---
--- Name: merchant_transfers; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfers (
- credit_serial bigint NOT NULL,
- exchange_url character varying NOT NULL,
- wtid bytea,
- credit_amount_val bigint NOT NULL,
- credit_amount_frac integer NOT NULL,
- account_serial bigint NOT NULL,
- verified boolean DEFAULT false NOT NULL,
- confirmed boolean DEFAULT false NOT NULL,
- CONSTRAINT merchant_transfers_wtid_check CHECK ((length(wtid) = 32))
-);
-
-
---
--- Name: TABLE merchant_transfers; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfers IS 'table represents the information provided by the (trusted) merchant about incoming wire transfers';
-
-
---
--- Name: COLUMN merchant_transfers.credit_amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.credit_amount_val IS 'actual value of the (aggregated) wire transfer, excluding the wire fee, according to the merchant';
-
-
---
--- Name: COLUMN merchant_transfers.verified; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.verified IS 'true once we got an acceptable response from the exchange for this transfer';
-
-
---
--- Name: COLUMN merchant_transfers.confirmed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.confirmed IS 'true once the merchant confirmed that this transfer was received';
-
-
---
--- Name: merchant_transfers_credit_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_transfers ALTER COLUMN credit_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_transfers_credit_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: partner_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.partner_accounts (
- payto_uri character varying NOT NULL,
- partner_serial_id bigint,
- partner_master_sig bytea,
- last_seen bigint NOT NULL,
- CONSTRAINT partner_accounts_partner_master_sig_check CHECK ((length(partner_master_sig) = 64))
-);
-
-
---
--- Name: TABLE partner_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.partner_accounts IS 'Table with bank accounts of the partner exchange. Entries never expire as we need to remember the signature for the auditor.';
-
-
---
--- Name: COLUMN partner_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.payto_uri IS 'payto URI (RFC 8905) with the bank account of the partner exchange.';
-
-
---
--- Name: COLUMN partner_accounts.partner_master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.partner_master_sig IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS by the partner master public key';
-
-
---
--- Name: COLUMN partner_accounts.last_seen; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.last_seen IS 'Last time we saw this account as being active at the partner exchange. Used to select the most recent entry, and to detect when we should check again.';
-
-
---
--- Name: partners; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.partners (
- partner_serial_id bigint NOT NULL,
- partner_master_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- next_wad bigint DEFAULT 0 NOT NULL,
- wad_frequency bigint NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- partner_base_url text NOT NULL,
- CONSTRAINT partners_master_sig_check CHECK ((length(master_sig) = 64)),
- CONSTRAINT partners_partner_master_pub_check CHECK ((length(partner_master_pub) = 32))
-);
-
-
---
--- Name: TABLE partners; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.partners IS 'exchanges we do wad transfers to';
-
-
---
--- Name: COLUMN partners.partner_master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.partner_master_pub IS 'offline master public key of the partner';
-
-
---
--- Name: COLUMN partners.start_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.start_date IS 'starting date of the partnership';
-
-
---
--- Name: COLUMN partners.end_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.end_date IS 'end date of the partnership';
-
-
---
--- Name: COLUMN partners.next_wad; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.next_wad IS 'at what time should we do the next wad transfer to this partner (frequently updated); set to forever after the end_date';
-
-
---
--- Name: COLUMN partners.wad_frequency; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.wad_frequency IS 'how often do we promise to do wad transfers';
-
-
---
--- Name: COLUMN partners.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.wad_fee_val IS 'how high is the fee for a wallet to be added to a wad to this partner';
-
-
---
--- Name: COLUMN partners.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.master_sig IS 'signature of our master public key affirming the partnership, of purpose TALER_SIGNATURE_MASTER_PARTNER_DETAILS';
-
-
---
--- Name: COLUMN partners.partner_base_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.partner_base_url IS 'base URL of the REST API for this partner';
-
-
---
--- Name: partners_partner_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.partners ALTER COLUMN partner_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.partners_partner_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: prewire; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.prewire (
- prewire_uuid bigint NOT NULL,
- wire_method text NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- failed boolean DEFAULT false NOT NULL,
- buf bytea NOT NULL
-)
-PARTITION BY HASH (prewire_uuid);
-
-
---
--- Name: TABLE prewire; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.prewire IS 'pre-commit data for wire transfers we are about to execute';
-
-
---
--- Name: COLUMN prewire.finished; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.finished IS 'set to TRUE once bank confirmed receiving the wire transfer request';
-
-
---
--- Name: COLUMN prewire.failed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.failed IS 'set to TRUE if the bank responded with a non-transient failure to our transfer request';
-
-
---
--- Name: COLUMN prewire.buf; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.buf IS 'serialized data to send to the bank to execute the wire transfer';
-
-
---
--- Name: prewire_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.prewire_default (
- prewire_uuid bigint NOT NULL,
- wire_method text NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- failed boolean DEFAULT false NOT NULL,
- buf bytea NOT NULL
-);
-ALTER TABLE ONLY public.prewire ATTACH PARTITION public.prewire_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: prewire_prewire_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.prewire ALTER COLUMN prewire_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.prewire_prewire_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_actions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_actions (
- purse_pub bytea NOT NULL,
- action_date bigint NOT NULL,
- partner_serial_id bigint,
- CONSTRAINT purse_actions_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-
-
---
--- Name: TABLE purse_actions; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_actions IS 'purses awaiting some action by the router';
-
-
---
--- Name: COLUMN purse_actions.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.purse_pub IS 'public (contract) key of the purse';
-
-
---
--- Name: COLUMN purse_actions.action_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.action_date IS 'when is the purse ready for action';
-
-
---
--- Name: COLUMN purse_actions.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.partner_serial_id IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
-
-
---
--- Name: purse_deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_deposits (
- purse_deposit_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- purse_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- coin_sig bytea NOT NULL,
- CONSTRAINT purse_deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT purse_deposits_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_deposits IS 'Requests depositing coins into a purse';
-
-
---
--- Name: COLUMN purse_deposits.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.partner_serial_id IS 'identifies the partner exchange, NULL in case the target purse lives at this exchange';
-
-
---
--- Name: COLUMN purse_deposits.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN purse_deposits.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.coin_pub IS 'Public key of the coin being deposited';
-
-
---
--- Name: COLUMN purse_deposits.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.amount_with_fee_val IS 'Total amount being deposited';
-
-
---
--- Name: COLUMN purse_deposits.coin_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.coin_sig IS 'Signature of the coin affirming the deposit into the purse, of type TALER_SIGNATURE_PURSE_DEPOSIT';
-
-
---
--- Name: purse_deposits_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_deposits_default (
- purse_deposit_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- purse_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- coin_sig bytea NOT NULL,
- CONSTRAINT purse_deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT purse_deposits_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_deposits ATTACH PARTITION public.purse_deposits_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_deposits_purse_deposit_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_deposits ALTER COLUMN purse_deposit_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_deposits_purse_deposit_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_merges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_merges (
- purse_merge_request_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- merge_sig bytea NOT NULL,
- merge_timestamp bigint NOT NULL,
- CONSTRAINT purse_merges_merge_sig_check CHECK ((length(merge_sig) = 64)),
- CONSTRAINT purse_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_merges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_merges IS 'Merge requests where a purse-owner requested merging the purse into the account';
-
-
---
--- Name: COLUMN purse_merges.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.partner_serial_id IS 'identifies the partner exchange, NULL in case the target reserve lives at this exchange';
-
-
---
--- Name: COLUMN purse_merges.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.reserve_pub IS 'public key of the target reserve';
-
-
---
--- Name: COLUMN purse_merges.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.purse_pub IS 'public key of the purse';
-
-
---
--- Name: COLUMN purse_merges.merge_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.merge_sig IS 'signature by the purse private key affirming the merge, of type TALER_SIGNATURE_WALLET_PURSE_MERGE';
-
-
---
--- Name: COLUMN purse_merges.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.merge_timestamp IS 'when was the merge message signed';
-
-
---
--- Name: purse_merges_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_merges_default (
- purse_merge_request_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- merge_sig bytea NOT NULL,
- merge_timestamp bigint NOT NULL,
- CONSTRAINT purse_merges_merge_sig_check CHECK ((length(merge_sig) = 64)),
- CONSTRAINT purse_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_merges ATTACH PARTITION public.purse_merges_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_merges_purse_merge_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_merges ALTER COLUMN purse_merge_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_merges_purse_merge_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_refunds (
- purse_refunds_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT purse_refunds_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_refunds; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_refunds IS 'Purses that were refunded due to expiration';
-
-
---
--- Name: COLUMN purse_refunds.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_refunds.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: purse_refunds_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_refunds_default (
- purse_refunds_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT purse_refunds_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_refunds ATTACH PARTITION public.purse_refunds_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_refunds_purse_refunds_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_refunds ALTER COLUMN purse_refunds_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_refunds_purse_refunds_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_requests (
- purse_requests_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- merge_pub bytea NOT NULL,
- purse_creation bigint NOT NULL,
- purse_expiration bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- age_limit integer NOT NULL,
- flags integer NOT NULL,
- refunded boolean DEFAULT false NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- in_reserve_quota boolean DEFAULT false NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- balance_val bigint DEFAULT 0 NOT NULL,
- balance_frac integer DEFAULT 0 NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT purse_requests_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT purse_requests_merge_pub_check CHECK ((length(merge_pub) = 32)),
- CONSTRAINT purse_requests_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_requests_purse_sig_check CHECK ((length(purse_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_requests IS 'Requests establishing purses, associating them with a contract but without a target reserve';
-
-
---
--- Name: COLUMN purse_requests.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_creation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_creation IS 'Local time when the purse was created. Determines applicable purse fees.';
-
-
---
--- Name: COLUMN purse_requests.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_expiration IS 'When the purse is set to expire';
-
-
---
--- Name: COLUMN purse_requests.h_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.h_contract_terms IS 'Hash of the contract the parties are to agree to';
-
-
---
--- Name: COLUMN purse_requests.flags; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.flags IS 'see the enum TALER_WalletAccountMergeFlags';
-
-
---
--- Name: COLUMN purse_requests.refunded; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.refunded IS 'set to TRUE if the purse could not be merged and thus all deposited coins were refunded';
-
-
---
--- Name: COLUMN purse_requests.finished; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.finished IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
-
-
---
--- Name: COLUMN purse_requests.in_reserve_quota; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.in_reserve_quota IS 'set to TRUE if this purse currently counts against the number of free purses in the respective reserve';
-
-
---
--- Name: COLUMN purse_requests.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.amount_with_fee_val IS 'Total amount expected to be in the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_fee_val IS 'Purse fee the client agreed to pay from the reserve (accepted by the exchange at the time the purse was created). Zero if in_reserve_quota is TRUE.';
-
-
---
--- Name: COLUMN purse_requests.balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.balance_val IS 'Total amount actually in the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_sig IS 'Signature of the purse affirming the purse parameters, of type TALER_SIGNATURE_PURSE_REQUEST';
-
-
---
--- Name: purse_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_requests_default (
- purse_requests_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- merge_pub bytea NOT NULL,
- purse_creation bigint NOT NULL,
- purse_expiration bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- age_limit integer NOT NULL,
- flags integer NOT NULL,
- refunded boolean DEFAULT false NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- in_reserve_quota boolean DEFAULT false NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- balance_val bigint DEFAULT 0 NOT NULL,
- balance_frac integer DEFAULT 0 NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT purse_requests_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT purse_requests_merge_pub_check CHECK ((length(merge_pub) = 32)),
- CONSTRAINT purse_requests_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_requests_purse_sig_check CHECK ((length(purse_sig) = 64))
-);
-ALTER TABLE ONLY public.purse_requests ATTACH PARTITION public.purse_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_requests_purse_requests_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_requests ALTER COLUMN purse_requests_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_requests_purse_requests_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: recoup; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup (
- recoup_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- reserve_out_serial_id bigint NOT NULL,
- CONSTRAINT recoup_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_coin_sig_check CHECK ((length(coin_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE recoup; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup IS 'Information about recoups that were executed between a coin and a reserve. In this type of recoup, the amount is credited back to the reserve from which the coin originated.';
-
-
---
--- Name: COLUMN recoup.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_pub IS 'Coin that is being debited in the recoup. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-
-
---
--- Name: COLUMN recoup.coin_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_sig IS 'Signature by the coin affirming the recoup, of type TALER_SIGNATURE_WALLET_COIN_RECOUP';
-
-
---
--- Name: COLUMN recoup.coin_blind; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_blind IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the withdraw operation.';
-
-
---
--- Name: COLUMN recoup.reserve_out_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.reserve_out_serial_id IS 'Identifies the h_blind_ev of the recouped coin and provides the link to the credited reserve.';
-
-
---
--- Name: recoup_by_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_by_reserve (
- reserve_out_serial_id bigint NOT NULL,
- coin_pub bytea,
- CONSTRAINT recoup_by_reserve_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY HASH (reserve_out_serial_id);
-
-
---
--- Name: TABLE recoup_by_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup_by_reserve IS 'Information in this table is strictly redundant with that of recoup, but saved by a different primary key for fast lookups by reserve_out_serial_id.';
-
-
---
--- Name: recoup_by_reserve_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_by_reserve_default (
- reserve_out_serial_id bigint NOT NULL,
- coin_pub bytea,
- CONSTRAINT recoup_by_reserve_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.recoup_by_reserve ATTACH PARTITION public.recoup_by_reserve_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_default (
- recoup_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- reserve_out_serial_id bigint NOT NULL,
- CONSTRAINT recoup_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_coin_sig_check CHECK ((length(coin_sig) = 64))
-);
-ALTER TABLE ONLY public.recoup ATTACH PARTITION public.recoup_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_recoup_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.recoup ALTER COLUMN recoup_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.recoup_recoup_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: recoup_refresh; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_refresh (
- recoup_refresh_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- rrc_serial bigint NOT NULL,
- CONSTRAINT recoup_refresh_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_refresh_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_refresh_coin_sig_check CHECK ((length(coin_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE recoup_refresh; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup_refresh IS 'Table of coins that originated from a refresh operation and that were recouped. Links the (fresh) coin to the melted operation (and thus the old coin). A recoup on a refreshed coin credits the old coin and debits the fresh coin.';
-
-
---
--- Name: COLUMN recoup_refresh.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.coin_pub IS 'Refreshed coin of a revoked denomination where the residual value is credited to the old coin. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-
-
---
--- Name: COLUMN recoup_refresh.known_coin_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.known_coin_id IS 'FIXME: (To be) used for garbage collection (in the future)';
-
-
---
--- Name: COLUMN recoup_refresh.coin_blind; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.coin_blind IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the refresh operation.';
-
-
---
--- Name: COLUMN recoup_refresh.rrc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.rrc_serial IS 'Link to the refresh operation. Also identifies the h_blind_ev of the recouped coin (as h_coin_ev).';
-
-
---
--- Name: recoup_refresh_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_refresh_default (
- recoup_refresh_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- rrc_serial bigint NOT NULL,
- CONSTRAINT recoup_refresh_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_refresh_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_refresh_coin_sig_check CHECK ((length(coin_sig) = 64))
-);
-ALTER TABLE ONLY public.recoup_refresh ATTACH PARTITION public.recoup_refresh_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_refresh_recoup_refresh_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.recoup_refresh ALTER COLUMN recoup_refresh_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.recoup_refresh_recoup_refresh_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_commitments; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_commitments (
- melt_serial_id bigint NOT NULL,
- rc bytea NOT NULL,
- old_coin_pub bytea NOT NULL,
- old_coin_sig bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- noreveal_index integer NOT NULL,
- CONSTRAINT refresh_commitments_old_coin_sig_check CHECK ((length(old_coin_sig) = 64)),
- CONSTRAINT refresh_commitments_rc_check CHECK ((length(rc) = 64))
-)
-PARTITION BY HASH (rc);
-
-
---
--- Name: TABLE refresh_commitments; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_commitments IS 'Commitments made when melting coins and the gamma value chosen by the exchange.';
-
-
---
--- Name: COLUMN refresh_commitments.rc; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.rc IS 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol';
-
-
---
--- Name: COLUMN refresh_commitments.old_coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.old_coin_pub IS 'Coin being melted in the refresh process.';
-
-
---
--- Name: COLUMN refresh_commitments.noreveal_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.noreveal_index IS 'The gamma value chosen by the exchange in the cut-and-choose protocol';
-
-
---
--- Name: refresh_commitments_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_commitments_default (
- melt_serial_id bigint NOT NULL,
- rc bytea NOT NULL,
- old_coin_pub bytea NOT NULL,
- old_coin_sig bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- noreveal_index integer NOT NULL,
- CONSTRAINT refresh_commitments_old_coin_sig_check CHECK ((length(old_coin_sig) = 64)),
- CONSTRAINT refresh_commitments_rc_check CHECK ((length(rc) = 64))
-);
-ALTER TABLE ONLY public.refresh_commitments ATTACH PARTITION public.refresh_commitments_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_commitments_melt_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_commitments ALTER COLUMN melt_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_commitments_melt_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_revealed_coins; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_revealed_coins (
- rrc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- freshcoin_index integer NOT NULL,
- link_sig bytea NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_ev bytea NOT NULL,
- h_coin_ev bytea NOT NULL,
- ev_sig bytea NOT NULL,
- ewv bytea NOT NULL,
- CONSTRAINT refresh_revealed_coins_h_coin_ev_check CHECK ((length(h_coin_ev) = 64)),
- CONSTRAINT refresh_revealed_coins_link_sig_check CHECK ((length(link_sig) = 64))
-)
-PARTITION BY HASH (melt_serial_id);
-
-
---
--- Name: TABLE refresh_revealed_coins; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_revealed_coins IS 'Revelations about the new coins that are to be created during a melting session.';
-
-
---
--- Name: COLUMN refresh_revealed_coins.rrc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.rrc_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN refresh_revealed_coins.melt_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.melt_serial_id IS 'Identifies the refresh commitment (rc) of the melt operation.';
-
-
---
--- Name: COLUMN refresh_revealed_coins.freshcoin_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.freshcoin_index IS 'index of the fresh coin being created (one melt operation may result in multiple fresh coins)';
-
-
---
--- Name: COLUMN refresh_revealed_coins.coin_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.coin_ev IS 'envelope of the new coin to be signed';
-
-
---
--- Name: COLUMN refresh_revealed_coins.h_coin_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.h_coin_ev IS 'hash of the envelope of the new coin to be signed (for lookups)';
-
-
---
--- Name: COLUMN refresh_revealed_coins.ev_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.ev_sig IS 'exchange signature over the envelope';
-
-
---
--- Name: COLUMN refresh_revealed_coins.ewv; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.ewv IS 'exchange contributed values in the creation of the fresh coin (see /csr)';
-
-
---
--- Name: refresh_revealed_coins_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_revealed_coins_default (
- rrc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- freshcoin_index integer NOT NULL,
- link_sig bytea NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_ev bytea NOT NULL,
- h_coin_ev bytea NOT NULL,
- ev_sig bytea NOT NULL,
- ewv bytea NOT NULL,
- CONSTRAINT refresh_revealed_coins_h_coin_ev_check CHECK ((length(h_coin_ev) = 64)),
- CONSTRAINT refresh_revealed_coins_link_sig_check CHECK ((length(link_sig) = 64))
-);
-ALTER TABLE ONLY public.refresh_revealed_coins ATTACH PARTITION public.refresh_revealed_coins_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_revealed_coins_rrc_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_revealed_coins ALTER COLUMN rrc_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_revealed_coins_rrc_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_transfer_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_transfer_keys (
- rtc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- transfer_pub bytea NOT NULL,
- transfer_privs bytea NOT NULL,
- CONSTRAINT refresh_transfer_keys_transfer_pub_check CHECK ((length(transfer_pub) = 32))
-)
-PARTITION BY HASH (melt_serial_id);
-
-
---
--- Name: TABLE refresh_transfer_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_transfer_keys IS 'Transfer keys of a refresh operation (the data revealed to the exchange).';
-
-
---
--- Name: COLUMN refresh_transfer_keys.rtc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.rtc_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN refresh_transfer_keys.melt_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.melt_serial_id IS 'Identifies the refresh commitment (rc) of the operation.';
-
-
---
--- Name: COLUMN refresh_transfer_keys.transfer_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.transfer_pub IS 'transfer public key for the gamma index';
-
-
---
--- Name: COLUMN refresh_transfer_keys.transfer_privs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.transfer_privs IS 'array of TALER_CNC_KAPPA - 1 transfer private keys that have been revealed, with the gamma entry being skipped';
-
-
---
--- Name: refresh_transfer_keys_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_transfer_keys_default (
- rtc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- transfer_pub bytea NOT NULL,
- transfer_privs bytea NOT NULL,
- CONSTRAINT refresh_transfer_keys_transfer_pub_check CHECK ((length(transfer_pub) = 32))
-);
-ALTER TABLE ONLY public.refresh_transfer_keys ATTACH PARTITION public.refresh_transfer_keys_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_transfer_keys_rtc_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_transfer_keys ALTER COLUMN rtc_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_transfer_keys_rtc_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refunds (
- refund_serial_id bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint NOT NULL,
- merchant_sig bytea NOT NULL,
- rtransaction_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT refunds_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT refunds_merchant_sig_check CHECK ((length(merchant_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE refunds; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refunds IS 'Data on coins that were refunded. Technically, refunds always apply against specific deposit operations involving a coin. The combination of coin_pub, merchant_pub, h_contract_terms and rtransaction_id MUST be unique, and we usually select by coin_pub so that one goes first.';
-
-
---
--- Name: COLUMN refunds.deposit_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refunds.deposit_serial_id IS 'Identifies ONLY the merchant_pub, h_contract_terms and coin_pub. Multiple deposits may match a refund, this only identifies one of them.';
-
-
---
--- Name: COLUMN refunds.rtransaction_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refunds.rtransaction_id IS 'used by the merchant to make refunds unique in case the same coin for the same deposit gets a subsequent (higher) refund';
-
-
---
--- Name: refunds_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refunds_default (
- refund_serial_id bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint NOT NULL,
- merchant_sig bytea NOT NULL,
- rtransaction_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT refunds_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT refunds_merchant_sig_check CHECK ((length(merchant_sig) = 64))
-);
-ALTER TABLE ONLY public.refunds ATTACH PARTITION public.refunds_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refunds_refund_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refunds ALTER COLUMN refund_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refunds_refund_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves (
- reserve_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- current_balance_val bigint DEFAULT 0 NOT NULL,
- current_balance_frac integer DEFAULT 0 NOT NULL,
- purses_active bigint DEFAULT 0 NOT NULL,
- purses_allowed bigint DEFAULT 0 NOT NULL,
- kyc_required boolean DEFAULT false NOT NULL,
- kyc_passed boolean DEFAULT false NOT NULL,
- max_age integer DEFAULT 120 NOT NULL,
- expiration_date bigint NOT NULL,
- gc_date bigint NOT NULL,
- CONSTRAINT reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves IS 'Summarizes the balance of a reserve. Updated when new funds are added or withdrawn.';
-
-
---
--- Name: COLUMN reserves.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.reserve_pub IS 'EdDSA public key of the reserve. Knowledge of the private key implies ownership over the balance.';
-
-
---
--- Name: COLUMN reserves.current_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.current_balance_val IS 'Current balance remaining with the reserve.';
-
-
---
--- Name: COLUMN reserves.purses_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.purses_active IS 'Number of purses that were created by this reserve that are not expired and not fully paid.';
-
-
---
--- Name: COLUMN reserves.purses_allowed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.purses_allowed IS 'Number of purses that this reserve is allowed to have active at most.';
-
-
---
--- Name: COLUMN reserves.kyc_required; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.kyc_required IS 'True if a KYC check must have been passed before withdrawing from this reserve. Set to true once a reserve received a P2P payment.';
-
-
---
--- Name: COLUMN reserves.kyc_passed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.kyc_passed IS 'True once KYC was passed for this reserve. The KYC details are then available via the wire_targets table under the key of wire_target_h_payto which is to be derived from the reserve_pub and the base URL of this exchange.';
-
-
---
--- Name: COLUMN reserves.expiration_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.expiration_date IS 'Used to trigger closing of reserves that have not been drained after some time';
-
-
---
--- Name: COLUMN reserves.gc_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.gc_date IS 'Used to forget all information about a reserve during garbage collection';
-
-
---
--- Name: reserves_close; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_close (
- close_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- execution_date bigint NOT NULL,
- wtid bytea NOT NULL,
- wire_target_h_payto bytea,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- CONSTRAINT reserves_close_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT reserves_close_wtid_check CHECK ((length(wtid) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves_close; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_close IS 'wire transfers executed by the reserve to close reserves';
-
-
---
--- Name: COLUMN reserves_close.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_close.wire_target_h_payto IS 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.';
-
-
---
--- Name: reserves_close_close_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_close ALTER COLUMN close_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_close_close_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_close_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_close_default (
- close_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- execution_date bigint NOT NULL,
- wtid bytea NOT NULL,
- wire_target_h_payto bytea,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- CONSTRAINT reserves_close_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT reserves_close_wtid_check CHECK ((length(wtid) = 32))
-);
-ALTER TABLE ONLY public.reserves_close ATTACH PARTITION public.reserves_close_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_default (
- reserve_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- current_balance_val bigint DEFAULT 0 NOT NULL,
- current_balance_frac integer DEFAULT 0 NOT NULL,
- purses_active bigint DEFAULT 0 NOT NULL,
- purses_allowed bigint DEFAULT 0 NOT NULL,
- kyc_required boolean DEFAULT false NOT NULL,
- kyc_passed boolean DEFAULT false NOT NULL,
- max_age integer DEFAULT 120 NOT NULL,
- expiration_date bigint NOT NULL,
- gc_date bigint NOT NULL,
- CONSTRAINT reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-ALTER TABLE ONLY public.reserves ATTACH PARTITION public.reserves_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_in; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_in (
- reserve_in_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- wire_reference bigint NOT NULL,
- credit_val bigint NOT NULL,
- credit_frac integer NOT NULL,
- wire_source_h_payto bytea,
- exchange_account_section text NOT NULL,
- execution_date bigint NOT NULL,
- CONSTRAINT reserves_in_wire_source_h_payto_check CHECK ((length(wire_source_h_payto) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves_in; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_in IS 'list of transfers of funds into the reserves, one per incoming wire transfer';
-
-
---
--- Name: COLUMN reserves_in.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.reserve_pub IS 'Public key of the reserve. Private key signifies ownership of the remaining balance.';
-
-
---
--- Name: COLUMN reserves_in.credit_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.credit_val IS 'Amount that was transferred into the reserve';
-
-
---
--- Name: COLUMN reserves_in.wire_source_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.wire_source_h_payto IS 'Identifies the debited bank account and KYC status';
-
-
---
--- Name: reserves_in_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_in_default (
- reserve_in_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- wire_reference bigint NOT NULL,
- credit_val bigint NOT NULL,
- credit_frac integer NOT NULL,
- wire_source_h_payto bytea,
- exchange_account_section text NOT NULL,
- execution_date bigint NOT NULL,
- CONSTRAINT reserves_in_wire_source_h_payto_check CHECK ((length(wire_source_h_payto) = 32))
-);
-ALTER TABLE ONLY public.reserves_in ATTACH PARTITION public.reserves_in_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_in_reserve_in_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_in ALTER COLUMN reserve_in_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_in_reserve_in_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out (
- reserve_out_serial_id bigint NOT NULL,
- h_blind_ev bytea,
- denominations_serial bigint NOT NULL,
- denom_sig bytea NOT NULL,
- reserve_uuid bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- execution_date bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT reserves_out_h_blind_ev_check CHECK ((length(h_blind_ev) = 64)),
- CONSTRAINT reserves_out_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (h_blind_ev);
-
-
---
--- Name: TABLE reserves_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_out IS 'Withdraw operations performed on reserves.';
-
-
---
--- Name: COLUMN reserves_out.h_blind_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_out.h_blind_ev IS 'Hash of the blinded coin, used as primary key here so that broken clients that use a non-random coin or blinding factor fail to withdraw (otherwise they would fail on deposit when the coin is not unique there).';
-
-
---
--- Name: COLUMN reserves_out.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_out.denominations_serial IS 'We do not CASCADE ON DELETE here, we may keep the denomination data alive';
-
-
---
--- Name: reserves_out_by_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_by_reserve (
- reserve_uuid bigint NOT NULL,
- h_blind_ev bytea,
- CONSTRAINT reserves_out_by_reserve_h_blind_ev_check CHECK ((length(h_blind_ev) = 64))
-)
-PARTITION BY HASH (reserve_uuid);
-
-
---
--- Name: TABLE reserves_out_by_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_out_by_reserve IS 'Information in this table is strictly redundant with that of reserves_out, but saved by a different primary key for fast lookups by reserve public key/uuid.';
-
-
---
--- Name: reserves_out_by_reserve_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_by_reserve_default (
- reserve_uuid bigint NOT NULL,
- h_blind_ev bytea,
- CONSTRAINT reserves_out_by_reserve_h_blind_ev_check CHECK ((length(h_blind_ev) = 64))
-);
-ALTER TABLE ONLY public.reserves_out_by_reserve ATTACH PARTITION public.reserves_out_by_reserve_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_default (
- reserve_out_serial_id bigint NOT NULL,
- h_blind_ev bytea,
- denominations_serial bigint NOT NULL,
- denom_sig bytea NOT NULL,
- reserve_uuid bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- execution_date bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT reserves_out_h_blind_ev_check CHECK ((length(h_blind_ev) = 64)),
- CONSTRAINT reserves_out_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.reserves_out ATTACH PARTITION public.reserves_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_out_reserve_out_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_out ALTER COLUMN reserve_out_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_out_reserve_out_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_reserve_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves ALTER COLUMN reserve_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_reserve_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: revolving_work_shards; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE UNLOGGED TABLE public.revolving_work_shards (
- shard_serial_id bigint NOT NULL,
- last_attempt bigint NOT NULL,
- start_row integer NOT NULL,
- end_row integer NOT NULL,
- active boolean DEFAULT false NOT NULL,
- job_name character varying NOT NULL
-);
-
-
---
--- Name: TABLE revolving_work_shards; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.revolving_work_shards IS 'coordinates work between multiple processes working on the same job with partitions that need to be repeatedly processed; unlogged because on system crashes the locks represented by this table will have to be cleared anyway, typically using "taler-exchange-dbinit -s"';
-
-
---
--- Name: COLUMN revolving_work_shards.shard_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.shard_serial_id IS 'unique serial number identifying the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.last_attempt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.last_attempt IS 'last time a worker attempted to work on the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.start_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.start_row IS 'row at which the shard scope starts, inclusive';
-
-
---
--- Name: COLUMN revolving_work_shards.end_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.end_row IS 'row at which the shard scope ends, exclusive';
-
-
---
--- Name: COLUMN revolving_work_shards.active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.active IS 'set to TRUE when a worker is active on the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.job_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.job_name IS 'unique name of the job the workers on this shard are performing';
-
-
---
--- Name: revolving_work_shards_shard_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.revolving_work_shards ALTER COLUMN shard_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.revolving_work_shards_shard_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: signkey_revocations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.signkey_revocations (
- signkey_revocations_serial_id bigint NOT NULL,
- esk_serial bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT signkey_revocations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE signkey_revocations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.signkey_revocations IS 'Table storing which online signing keys have been revoked';
-
-
---
--- Name: signkey_revocations_signkey_revocations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.signkey_revocations ALTER COLUMN signkey_revocations_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.signkey_revocations_signkey_revocations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wad_in_entries; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_in_entries (
- wad_in_entry_serial_id bigint NOT NULL,
- wad_in_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_in_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_in_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_in_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_in_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_in_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE wad_in_entries; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wad_in_entries IS 'list of purses aggregated in a wad according to the sending exchange';
-
-
---
--- Name: COLUMN wad_in_entries.wad_in_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.wad_in_serial_id IS 'wad for which the given purse was included in the aggregation';
-
-
---
--- Name: COLUMN wad_in_entries.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.reserve_pub IS 'target account of the purse (must be at the local exchange)';
-
-
---
--- Name: COLUMN wad_in_entries.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_pub IS 'public key of the purse that was merged';
-
-
---
--- Name: COLUMN wad_in_entries.h_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.h_contract IS 'hash of the contract terms of the purse';
-
-
---
--- Name: COLUMN wad_in_entries.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_expiration IS 'Time when the purse was set to expire';
-
-
---
--- Name: COLUMN wad_in_entries.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.merge_timestamp IS 'Time when the merge was approved';
-
-
---
--- Name: COLUMN wad_in_entries.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.amount_with_fee_val IS 'Total amount in the purse';
-
-
---
--- Name: COLUMN wad_in_entries.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.wad_fee_val IS 'Total wad fees paid by the purse';
-
-
---
--- Name: COLUMN wad_in_entries.deposit_fees_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.deposit_fees_val IS 'Total deposit fees paid when depositing coins into the purse';
-
-
---
--- Name: COLUMN wad_in_entries.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.reserve_sig IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN wad_in_entries.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_sig IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-
---
--- Name: wad_in_entries_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_in_entries_default (
- wad_in_entry_serial_id bigint NOT NULL,
- wad_in_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_in_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_in_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_in_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_in_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_in_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.wad_in_entries ATTACH PARTITION public.wad_in_entries_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wad_in_entries_wad_in_entry_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wad_in_entries ALTER COLUMN wad_in_entry_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wad_in_entries_wad_in_entry_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wad_out_entries; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_out_entries (
- wad_out_entry_serial_id bigint NOT NULL,
- wad_out_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_out_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_out_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_out_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_out_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_out_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE wad_out_entries; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wad_out_entries IS 'Purses combined into a wad';
-
-
---
--- Name: COLUMN wad_out_entries.wad_out_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.wad_out_serial_id IS 'Wad the purse was part of';
-
-
---
--- Name: COLUMN wad_out_entries.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.reserve_pub IS 'Target reserve for the purse';
-
-
---
--- Name: COLUMN wad_out_entries.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN wad_out_entries.h_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.h_contract IS 'Hash of the contract associated with the purse';
-
-
---
--- Name: COLUMN wad_out_entries.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_expiration IS 'Time when the purse expires';
-
-
---
--- Name: COLUMN wad_out_entries.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.merge_timestamp IS 'Time when the merge was approved';
-
-
---
--- Name: COLUMN wad_out_entries.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.amount_with_fee_val IS 'Total amount in the purse';
-
-
---
--- Name: COLUMN wad_out_entries.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.wad_fee_val IS 'Wat fee charged to the purse';
-
-
---
--- Name: COLUMN wad_out_entries.deposit_fees_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.deposit_fees_val IS 'Total deposit fees charged to the purse';
-
-
---
--- Name: COLUMN wad_out_entries.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.reserve_sig IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN wad_out_entries.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_sig IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-
---
--- Name: wad_out_entries_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_out_entries_default (
- wad_out_entry_serial_id bigint NOT NULL,
- wad_out_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_out_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_out_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_out_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_out_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_out_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.wad_out_entries ATTACH PARTITION public.wad_out_entries_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wad_out_entries_wad_out_entry_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wad_out_entries ALTER COLUMN wad_out_entry_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wad_out_entries_wad_out_entry_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wads_in; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_in (
- wad_in_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- origin_exchange_url text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- arrival_time bigint NOT NULL,
- CONSTRAINT wads_in_wad_id_check CHECK ((length(wad_id) = 24))
-)
-PARTITION BY HASH (wad_id);
-
-
---
--- Name: TABLE wads_in; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wads_in IS 'Incoming exchange-to-exchange wad wire transfers';
-
-
---
--- Name: COLUMN wads_in.wad_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.wad_id IS 'Unique identifier of the wad, part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_in.origin_exchange_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.origin_exchange_url IS 'Base URL of the originating URL, also part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_in.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.amount_val IS 'Actual amount that was received by our exchange';
-
-
---
--- Name: COLUMN wads_in.arrival_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.arrival_time IS 'Time when the wad was received';
-
-
---
--- Name: wads_in_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_in_default (
- wad_in_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- origin_exchange_url text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- arrival_time bigint NOT NULL,
- CONSTRAINT wads_in_wad_id_check CHECK ((length(wad_id) = 24))
-);
-ALTER TABLE ONLY public.wads_in ATTACH PARTITION public.wads_in_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wads_in_wad_in_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wads_in ALTER COLUMN wad_in_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wads_in_wad_in_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wads_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_out (
- wad_out_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- partner_serial_id bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- CONSTRAINT wads_out_wad_id_check CHECK ((length(wad_id) = 24))
-)
-PARTITION BY HASH (wad_id);
-
-
---
--- Name: TABLE wads_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wads_out IS 'Wire transfers made to another exchange to transfer purse funds';
-
-
---
--- Name: COLUMN wads_out.wad_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.wad_id IS 'Unique identifier of the wad, part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_out.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.partner_serial_id IS 'target exchange of the wad';
-
-
---
--- Name: COLUMN wads_out.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.amount_val IS 'Amount that was wired';
-
-
---
--- Name: COLUMN wads_out.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.execution_time IS 'Time when the wire transfer was scheduled';
-
-
---
--- Name: wads_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_out_default (
- wad_out_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- partner_serial_id bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- CONSTRAINT wads_out_wad_id_check CHECK ((length(wad_id) = 24))
-);
-ALTER TABLE ONLY public.wads_out ATTACH PARTITION public.wads_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wads_out_wad_out_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wads_out ALTER COLUMN wad_out_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wads_out_wad_out_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_accounts (
- payto_uri character varying NOT NULL,
- master_sig bytea,
- is_active boolean NOT NULL,
- last_change bigint NOT NULL,
- CONSTRAINT wire_accounts_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE wire_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_accounts IS 'Table with current and historic bank accounts of the exchange. Entries never expire as we need to remember the last_change column indefinitely.';
-
-
---
--- Name: COLUMN wire_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.payto_uri IS 'payto URI (RFC 8905) with the bank account of the exchange.';
-
-
---
--- Name: COLUMN wire_accounts.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.master_sig IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS';
-
-
---
--- Name: COLUMN wire_accounts.is_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.is_active IS 'true if we are currently supporting the use of this account.';
-
-
---
--- Name: COLUMN wire_accounts.last_change; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.last_change IS 'Latest time when active status changed. Used to detect replays of old messages.';
-
-
---
--- Name: wire_auditor_account_progress; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_auditor_account_progress (
- master_pub bytea NOT NULL,
- account_name text NOT NULL,
- last_wire_reserve_in_serial_id bigint DEFAULT 0 NOT NULL,
- last_wire_wire_out_serial_id bigint DEFAULT 0 NOT NULL,
- wire_in_off bigint NOT NULL,
- wire_out_off bigint NOT NULL
-);
-
-
---
--- Name: TABLE wire_auditor_account_progress; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_auditor_account_progress IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: wire_auditor_progress; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_auditor_progress (
- master_pub bytea NOT NULL,
- last_timestamp bigint NOT NULL,
- last_reserve_close_uuid bigint NOT NULL
-);
-
-
---
--- Name: wire_fee; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_fee (
- wire_fee_serial bigint NOT NULL,
- wire_method character varying NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT wire_fee_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE wire_fee; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_fee IS 'list of the wire fees of this exchange, by date';
-
-
---
--- Name: COLUMN wire_fee.wire_fee_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_fee.wire_fee_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: wire_fee_wire_fee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_fee ALTER COLUMN wire_fee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_fee_wire_fee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_out (
- wireout_uuid bigint NOT NULL,
- execution_date bigint NOT NULL,
- wtid_raw bytea NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT wire_out_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT wire_out_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-)
-PARTITION BY HASH (wtid_raw);
-
-
---
--- Name: TABLE wire_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_out IS 'wire transfers the exchange has executed';
-
-
---
--- Name: COLUMN wire_out.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_out.wire_target_h_payto IS 'Identifies the credited bank account and KYC status';
-
-
---
--- Name: COLUMN wire_out.exchange_account_section; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_out.exchange_account_section IS 'identifies the configuration section with the debit account of this payment';
-
-
---
--- Name: wire_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_out_default (
- wireout_uuid bigint NOT NULL,
- execution_date bigint NOT NULL,
- wtid_raw bytea NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT wire_out_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT wire_out_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-);
-ALTER TABLE ONLY public.wire_out ATTACH PARTITION public.wire_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wire_out_wireout_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_out ALTER COLUMN wireout_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_out_wireout_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_targets; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_targets (
- wire_target_serial_id bigint NOT NULL,
- wire_target_h_payto bytea NOT NULL,
- payto_uri character varying NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- external_id character varying,
- CONSTRAINT wire_targets_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-)
-PARTITION BY HASH (wire_target_h_payto);
-
-
---
--- Name: TABLE wire_targets; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_targets IS 'All senders and recipients of money via the exchange';
-
-
---
--- Name: COLUMN wire_targets.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.wire_target_h_payto IS 'Unsalted hash of payto_uri';
-
-
---
--- Name: COLUMN wire_targets.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.payto_uri IS 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)';
-
-
---
--- Name: COLUMN wire_targets.kyc_ok; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.kyc_ok IS 'true if the KYC check was passed successfully';
-
-
---
--- Name: COLUMN wire_targets.external_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.external_id IS 'Name of the user that was used for OAuth 2.0-based legitimization';
-
-
---
--- Name: wire_targets_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_targets_default (
- wire_target_serial_id bigint NOT NULL,
- wire_target_h_payto bytea NOT NULL,
- payto_uri character varying NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- external_id character varying,
- CONSTRAINT wire_targets_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-);
-ALTER TABLE ONLY public.wire_targets ATTACH PARTITION public.wire_targets_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wire_targets_wire_target_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_targets ALTER COLUMN wire_target_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_targets_wire_target_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: work_shards; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.work_shards (
- shard_serial_id bigint NOT NULL,
- last_attempt bigint NOT NULL,
- start_row bigint NOT NULL,
- end_row bigint NOT NULL,
- completed boolean DEFAULT false NOT NULL,
- job_name character varying NOT NULL
-);
-
-
---
--- Name: TABLE work_shards; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.work_shards IS 'coordinates work between multiple processes working on the same job';
-
-
---
--- Name: COLUMN work_shards.shard_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.shard_serial_id IS 'unique serial number identifying the shard';
-
-
---
--- Name: COLUMN work_shards.last_attempt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.last_attempt IS 'last time a worker attempted to work on the shard';
-
-
---
--- Name: COLUMN work_shards.start_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.start_row IS 'row at which the shard scope starts, inclusive';
-
-
---
--- Name: COLUMN work_shards.end_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.end_row IS 'row at which the shard scope ends, exclusive';
-
-
---
--- Name: COLUMN work_shards.completed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.completed IS 'set to TRUE once the shard is finished by a worker';
-
-
---
--- Name: COLUMN work_shards.job_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.job_name IS 'unique name of the job the workers on this shard are performing';
-
-
---
--- Name: work_shards_shard_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.work_shards ALTER COLUMN shard_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.work_shards_shard_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: app_bankaccount account_no; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount ALTER COLUMN account_no SET DEFAULT nextval('public.app_bankaccount_account_no_seq'::regclass);
-
-
---
--- Name: app_banktransaction id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction ALTER COLUMN id SET DEFAULT nextval('public.app_banktransaction_id_seq'::regclass);
-
-
---
--- Name: auditor_reserves auditor_reserves_rowid; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves ALTER COLUMN auditor_reserves_rowid SET DEFAULT nextval('public.auditor_reserves_auditor_reserves_rowid_seq'::regclass);
-
-
---
--- Name: auth_group id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group ALTER COLUMN id SET DEFAULT nextval('public.auth_group_id_seq'::regclass);
-
-
---
--- Name: auth_group_permissions id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions ALTER COLUMN id SET DEFAULT nextval('public.auth_group_permissions_id_seq'::regclass);
-
-
---
--- Name: auth_permission id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission ALTER COLUMN id SET DEFAULT nextval('public.auth_permission_id_seq'::regclass);
-
-
---
--- Name: auth_user id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user ALTER COLUMN id SET DEFAULT nextval('public.auth_user_id_seq'::regclass);
-
-
---
--- Name: auth_user_groups id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups ALTER COLUMN id SET DEFAULT nextval('public.auth_user_groups_id_seq'::regclass);
-
-
---
--- Name: auth_user_user_permissions id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions ALTER COLUMN id SET DEFAULT nextval('public.auth_user_user_permissions_id_seq'::regclass);
-
-
---
--- Name: deposit_confirmations serial_id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations ALTER COLUMN serial_id SET DEFAULT nextval('public.deposit_confirmations_serial_id_seq'::regclass);
-
-
---
--- Name: django_content_type id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type ALTER COLUMN id SET DEFAULT nextval('public.django_content_type_id_seq'::regclass);
-
-
---
--- Name: django_migrations id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_migrations ALTER COLUMN id SET DEFAULT nextval('public.django_migrations_id_seq'::regclass);
-
-
---
--- Data for Name: patches; Type: TABLE DATA; Schema: _v; Owner: -
---
-
-COPY _v.patches (patch_name, applied_tsz, applied_by, requires, conflicts) FROM stdin;
-exchange-0001 2022-06-19 14:06:05.845802+02 grothoff {} {}
-merchant-0001 2022-06-19 14:06:06.801597+02 grothoff {} {}
-merchant-0002 2022-06-19 14:06:07.218735+02 grothoff {} {}
-auditor-0001 2022-06-19 14:06:07.360062+02 grothoff {} {}
-\.
-
-
---
--- Data for Name: account_merges_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.account_merges_default (account_merge_request_serial_id, reserve_pub, reserve_sig, purse_pub) FROM stdin;
-\.
-
-
---
--- Data for Name: aggregation_tracking_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.aggregation_tracking_default (aggregation_serial_id, deposit_serial_id, wtid_raw) FROM stdin;
-\.
-
-
---
--- Data for Name: aggregation_transient_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.aggregation_transient_default (amount_val, amount_frac, wire_target_h_payto, exchange_account_section, wtid_raw) FROM stdin;
-\.
-
-
---
--- Data for Name: app_bankaccount; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_bankaccount (is_public, account_no, balance, user_id) FROM stdin;
-t 3 +TESTKUDOS:0 3
-t 4 +TESTKUDOS:0 4
-t 5 +TESTKUDOS:0 5
-t 6 +TESTKUDOS:0 6
-t 7 +TESTKUDOS:0 7
-t 8 +TESTKUDOS:0 8
-t 9 +TESTKUDOS:0 9
-f 10 +TESTKUDOS:0 10
-f 11 +TESTKUDOS:0 11
-f 12 +TESTKUDOS:90 12
-t 1 -TESTKUDOS:200 1
-f 13 +TESTKUDOS:82 13
-t 2 +TESTKUDOS:28 2
-\.
-
-
---
--- Data for Name: app_banktransaction; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_banktransaction (id, amount, subject, date, cancelled, request_uid, credit_account_id, debit_account_id) FROM stdin;
-1 TESTKUDOS:100 Joining bonus 2022-06-19 14:06:17.194631+02 f a43af79c-fad5-401b-889a-a363e36aecac 12 1
-2 TESTKUDOS:10 HRGRTQAX05S2Q8P881TJS82Q05PSXSVZJ7686REZX4YK5R47Q1WG 2022-06-19 14:06:20.752813+02 f 7668adf5-d217-422d-92ef-cd569f8018db 2 12
-3 TESTKUDOS:100 Joining bonus 2022-06-19 14:06:27.794023+02 f cadcef48-6d5f-41db-8c31-a09a40d9f932 13 1
-4 TESTKUDOS:18 1DCW1ACQCWXY35T5PQV1FAB1WJDPJE4AHWQQEKGNE8KQ151K4FEG 2022-06-19 14:06:28.454299+02 f 16cddff4-1bc6-439e-97a2-70fab6ee18d2 2 13
-\.
-
-
---
--- Data for Name: app_talerwithdrawoperation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_talerwithdrawoperation (withdraw_id, amount, selection_done, confirmation_done, aborted, selected_reserve_pub, selected_exchange_account_id, withdraw_account_id) FROM stdin;
-1c75882b-64a2-4661-ab39-e41a51ffc059 TESTKUDOS:10 t t f HRGRTQAX05S2Q8P881TJS82Q05PSXSVZJ7686REZX4YK5R47Q1WG 2 12
-bb82dbb8-93ba-40ed-9f04-74d93682aacc TESTKUDOS:18 t t f 1DCW1ACQCWXY35T5PQV1FAB1WJDPJE4AHWQQEKGNE8KQ151K4FEG 2 13
-\.
-
-
---
--- Data for Name: auditor_balance_summary; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_balance_summary (master_pub, denom_balance_val, denom_balance_frac, deposit_fee_balance_val, deposit_fee_balance_frac, melt_fee_balance_val, melt_fee_balance_frac, refund_fee_balance_val, refund_fee_balance_frac, risk_val, risk_frac, loss_val, loss_frac, irregular_recoup_val, irregular_recoup_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_denom_sigs; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_denom_sigs (auditor_denom_serial, auditor_uuid, denominations_serial, auditor_sig) FROM stdin;
-1 1 81 \\x5e2ae1c64a2c1a432404d23c3041845d1031c6898893ae0233b2788c18ed1736690774c83669fcc8020229245aa700b4c94cc3841eae15545bf1ebbc38c74003
-2 1 225 \\xadad8526f9cafdf8cbd600e63987ef4c3b70b27891c25013df07524988b9b6aa32c50ba6ca8b2372f33c07579c876bae93ad3f50e39ebf7286b36e426e2c0903
-3 1 96 \\xb524870268d6946cf49c3458e1764b82666ee7f11afe519ef5f1281fb9176e89cea68fad579c1ca40019803b6bdf5b3ddb0f6b491179e3e9f51060ff44599a0f
-4 1 126 \\x99ab1fa3ac26bc637972de6845e8f72e0342a5db99dc75aa2c27e39616408f16b19cecbf796aa430dfbe2b87d582a87ffe8e754f1a4f3037cc9a2ba84928960b
-5 1 245 \\x7e3bb08189693d75009a3133405deb2ed97f092c70f223bb78d982881cd3739cdff2d21b8f1e60645ec2ee7fbf479ff0246d9c8db535984301da6e00af8f650d
-6 1 110 \\x721e44c6b056c380bbe22b668a5799ab3769d60b41e3aca864b09765c6da9d28b710689d6d82841123d932282f10227f247e4d2c2c9904cbe5038fe4925cfb0d
-7 1 324 \\x0672a28f9aa91962acf0c190b4ab167a4fa88616475247171d1a547e62261490bb9a995091d241387a326089bf7b5abb92ae74954f58fa36cd870207418fbc0f
-8 1 121 \\x5145ecdc0f55d97a7e133b394303afc55f665a9ec1ed318fca6b4e5e69dbcbba4e5b9a28faa20cf832f621b5a1eee1407ea470d159a99845995e90e8d49bf603
-9 1 200 \\x7c22cf64e19192d254c16b46323fcd36b265fe6161687c2414cf99c26b77a02c984defb9dd2addbbc509ddb398f92856bdb9b5b9e3c89c1cd4652205f31faf0b
-10 1 224 \\xb1d0036178e1fa74eaab101e2ccf44c07e0a69758c8dff16fbb5a85dcda18a246fa5d1f894af7f184f9ef930ce4bdbc325437386f883d01ea7dab6403b10470d
-11 1 244 \\x535b0e8a20b20b8adf1fb7ec0f1ad611cd0c6f8f0f1bbbd739451976e2b7a7e4bbe903e09bf1d286efa2e4208d1a2c68b3d70896692c68b7f45138fb0e88d00d
-12 1 170 \\x2a70764ea0889074b13da192230af5e9a6cf4fbc7e28e3acf2672b594c6075099cb01dd99fcbb8dbfe72f07193ec3e3619928a9095d1c6970807c1fab0798c05
-13 1 364 \\xcddcf82bce96d8f20e00beb30dde66c827719915e45f68003c442bb000fb215db4534dd7bd0229cdc498297b56492eb512ce3d0b850d874f5a37ecfdb3cec405
-14 1 23 \\x556a61324a8f57155988c25c1b02bad03bbb5b2f396e430effde1f006c3da8d256f7020e4e8f081924366f9021a375f2054699d8f66503dae7d287fe9847b308
-15 1 67 \\xf28085a47106339be3ffd9421a39866b58a2f34acddf869a88fe38df002c6a83a82ed757665ffbd63779df16c8801fe2e7ff6988c8d28237a7339bb4974e980f
-16 1 74 \\x75e9d9d51228135f7208f1a7a77d3c66e0b29876d9ff3861cb6e1f4586f54528d96172d35c0e567913313169b90ec2e050af1343db2596bf254c030cdd9dd003
-17 1 33 \\x468966d06412dff760ba704148d346b4d9286646b157fd0859d6dafc5e82f37ac587c549b2e786a3b8fd404d7e61cd5e4182ad2c19740eb3455578000039df0a
-18 1 195 \\x0c294f297559680e73e5945cef01a6206c74613de77b802c2a792f413c7198fc315277d17fb0a6eb568ca04c733a7d01556c4b4b3d8bfdc88e3df85a810a6707
-19 1 41 \\x1ade82b3faa959a5e34c820c4c7a5455c31454e520b3eb753225eecb99340a60f77d85c5229ebfaabc438da2b50381a8875c221c84f78d44f8626ac80078e106
-20 1 235 \\xd2bb1d4946c003b7f33f30502ed81659ac5f99477da91e0d86c4a0fb475d344fb03aaacbf198d7ddaad0b3bf6672ba640b20792fe372d6b6275445972b8e510b
-21 1 419 \\x5c8abe0250d7f4316c6fbffbde1e4165b5b1e05cd9eba0f872969caf29f788e44a371cbc01deb1471b3f76c9f158ff98835d00670609fb0a8f86f502d4b1be05
-22 1 240 \\xac46e258bb6a104afc8c8fc19f6be5b9bd5d73a7ac90fa8ff9ddb9fd86d1c469d3081e9bd003c9ae44b02f2848645ed73cdc3248262ea6a10d1739fb0db40800
-23 1 395 \\x1f0041524e4c7c5a721c757c88438f05cb924d3eabf5e3a040a9dd99f4128a19891565e7d37bdd7efbc0a05d08b7397fd7fc1bb18cbc045f465ae839d3bb060c
-24 1 98 \\x739a786b40b535301eff6ec3fc2b4abe6c6ee13716fec256b39595e25760a0a8b20b93d4670efc6eb168b626e5df1c6777f0b1d5caff8e20a2d639d154506001
-25 1 340 \\x5cd78229d21ff8ebd8cccb1d13ee02d127555920f865d91ef289338492c8ba3fd8066148c84cea632e612986371e6cc35a1f7fe53e3d731d64537c3707487304
-26 1 270 \\xa103fa757c69a1ee20d6d4766e8f0a81710737e4550845ee84008300940445d82e162600a3585774cc36932a1a438a79bdfa2b27816412b4704229e28ddd460a
-27 1 129 \\xa706ab23872d2a3f09a279071af0c07a652e3132d4db06133f0634e0173d2466fc32a682d7ec931a3d706c0b6c6851ba90fc875098c4b7f11ad6c3f0b1c85e05
-28 1 139 \\x031948742c78dcf41b0c2fb64394aff794e6f30f404eae914a0b27df95c761b330d6b614866b5a19a67fa0e2abc1dfe087d9b8cd2eb281a6d51abd4be9289c00
-29 1 390 \\xfcb21a5da1dc1e53416b24d4f009556b6b3f6582a76b502b4a4e71f432ae1959d403a34781691c41e7296e5c42ac5fb40d9736cf9a38c97b5657cea3e28f5001
-30 1 140 \\x1c2c66a02b49e6c51b39b397a302cdbaa16e999346ed000c1b18ec687ac6fcf700f526e820bdf64fe51b51fe3771e9dbb214499664d9d520b5c9f118cecc6a0d
-31 1 19 \\xb3043958170efcf3af2f849b7c81db8bc0429e041d8be644ffeda4d17f01b1a93b5a18a87a6b7c15e1388eac19de357fcfc9238a1d34465228d19ed4485b810d
-32 1 157 \\xca60b054a3f9c531493d4b076a2a89f01f7bc2b437c67741ca073c65b84cf0b0803fa16c2c4acaeac699626239b0d73074499cb355cec58c8507c972409ece04
-33 1 54 \\xb6667ccb86919d21bd96a58601f725b2aa16e53d8badf4e82117e29458e5d56d01161813665356fc8ce0289dea35ff3d68cd845689c0bc5592e80e23ffb5530c
-34 1 198 \\x5be3995f33533656460ee6f8e5055f4f5c1aff78735601682bf703470949780676fc114ef640bb46e9d3c10d71c25d8299418e43194de44b73dcf936c2704a06
-35 1 52 \\x55fea0391d0279ae0f87042054656d1debec601330c2a414f50e68572fe012e31086a0d54c83776dcbb17c47ef828d316ca993279676985ab53c133784e4780e
-36 1 278 \\x1e7a966fa019e5cc116194e0c018d09850e0e8fcfb59de7bf88ad3ce7a7481c47cc1b3ff04e0c6a5b05c470d649dc4c1b1872966d561e01378080695eb0bdc09
-37 1 299 \\x9ca4a69429be91bd19dcbc0a786b7152b35babbb7558c36bec3a5c9b9d1067d7cea0b4df494716e6d1d31e7dbc57991ab7e392c401c835a639fa7881dea1c306
-38 1 150 \\xfad6eaa9e06538496a15b92ede51616aeccd700ca0cffbc201ecbc9da98c96a64057a05e14913a7725d0ff9a12b83e72525b9b703f89f5a95a873eed6913a007
-39 1 231 \\x336372e1afb326accee1153fd28a7f5173f63d09fae9dcc8eb34e30020830a081e51b6d070a2cf99af4865948ec4c0e8fddbfb1156cbd306a4c7757379f0900a
-40 1 349 \\x85086347219f6402377d82df4ed672d57f7c2e1a2e6e0dec26c1807728795814ccdddff12897ad86c2a0f7156370b11e7413e99a4c1d163075bea8ecb2255902
-41 1 298 \\xc09a6ca6c633ba63ee855aa2041cee5551ac358b0f617d505a448970dafa5007f812468c431d4e430f23e6e220207dda8a0233df9fd63af30fe5940ae44b630c
-42 1 160 \\x2faafe1b53f6d53d008369403100566af0e08fd6af0e53bba5699c600ec8a0961c5bb3894269e6f7010466210d68f5669b1cca82b6a79ee9229e438e3e4f3207
-43 1 327 \\x8b7ddfba2a5722599fb83325c914b5a9f6c50e3e1edc07894d141956105de311af6eddcea0ef9b3ad16003b73df2e0554a05c391f7e7249507b6ef3c95243f02
-44 1 264 \\x7ba2027a291cf55337ea8629ff7fb7389425fb342839811b1f1c3dbc2bea8abab88813099ab9e1e3aa50d41dac2f9e3dc00b4c53dd489fb3ce99f0ec3ee8bc0e
-45 1 331 \\xda8fcab64665fbabe49f71701585a4efeb8b4624a8dfc90f5ae6b718aa691bddce3cce514e5b8eb25f7dde831b629233dacfdd729592755101f78a9eac97c202
-46 1 164 \\xe741c1e0b424ceea9d8b372616ac7f406804d45c978a7717ac806d24a2074510fcaea4ce07cc301508c13a5cf6076bb3bee7f3c035af69e9813b4327f4986f03
-47 1 97 \\x3bc084ad32ab9d856a3f78ca704a7f8cb203615139b2fd7b942f1303ffebc3f8400b8b5ffd4ab9321524168d411f34627799f0372bbe623b706f22587b2fd005
-48 1 115 \\xbdd269a80429559e2e13bfa6f25a00c4365a9f5df00185c34cc1f3655f3c50ae23ed04e0044590fcc9ea4b5b29ac5aa9c963fa8ac2409231439fc3f53b2e5e0b
-49 1 197 \\x1fef5b3a3a9a9075d97143674efa156b40e5a03c5b51a50ba62522a6accda2285b9872464c758b0783dad7fabf448a97b0da3ada834f8a5ffd9d4ec1d0a5a308
-50 1 268 \\x7d0c3053c15b4dadd9667f6cffb4d3955f2133d42c04f2726f2f3ffcccf695ba00b2461c6294527bace3f0bce6611f53bd3d5ad71ecfc2c801bd4c3709070e0c
-51 1 151 \\x33cacca0311ad773f3bac91c90d87f2cd4223871386607bba6c21cea6f8b15632dadd80a36d8482633dc4d9fe91971a418d8d9d0ed857952300c1d57718f780c
-52 1 102 \\x587d1e9e376b806fc136e05438a70eeb653a89849c941b1c576346dac49d7030b82de087e4f5a3b91aefcd35145f17d98861ef1703a865fa24f26258ede5cf0a
-53 1 203 \\x45abf364d1b6948ef922b20972de9cced3bc2f31a3296b7b5d112ce1233adb3f1b672aaaff26a149994d800d03c0b458afe96ad5c55b41fa38d5e3a18df55701
-54 1 232 \\x1cbbf812a250ec093715aa492efe3acb18718d315c1d784f0e33a0ac4fc5fb7680e31ca2633bb666c184dece355983947178e183290d3dabda360a35d038b604
-55 1 329 \\xb09b39d317f4e4eaea9757d3d1eddfed230b88475db259bd482908924452ba0b0e27d5ed6f854ec9d44ab3e9a2c745d7d5ae340567842ab6231a2536dd0be504
-56 1 173 \\xd877e0abda526820c6f07df6082e4dfe44a2e8ef9094cf69d776e0aa21bd7a48c2eab5037f8a19732b1c0a90becdda96a2b45c4e8b0f8f6b2f585ec71054d50b
-57 1 134 \\xede1ad426861d61cd21f0dafef6e59ee2ebb021d16e6a2a1312ffbd163dd97569b438bf980ef45ef0757fbac3a388a826009dcb80a963a8dc021bc57ee030a03
-58 1 123 \\xdb17ea5e47ba915a8acf0ce235e8f1e1e35e1e02cba13e2ac2a113662a557430f06675f7e17e1c64d1a86566c66e08f412981a2db397cbf9e34eb224acc69609
-59 1 103 \\x3092c063bedeecf60e6d57b2bcc3d9e44fc2c39bfeff789855f0d710e553a315019aa4fb35221ee56b3b96d26ae0ccfe11865fe87eeed1c6fad1952c67acd006
-60 1 86 \\x987746a701f9068b2219d94e90206d0c878b25a84314f59a0104d3ba31bbdd88e3fa2e3d1f0accdbf4caf6f2c07f145481554a59d41d4d3de15762ab007e3304
-61 1 184 \\xb00fbd56e33eb2dea1812bdb441a2afea8e48c92f4bee0e5e0a6d3db7b247066535bd0d1a2696b4ab6d06d2cd66d5a3095b18a34a2806ad9f54565262092b909
-62 1 47 \\xac33cbe4c07dd0bdcd9b73c4b1771a5b878f823be9d657e1713f60c35a2325bf2489ff571cf7cae1065fda86734336124d70a6893e1bd2d14c7a87ac5dd16309
-63 1 209 \\xd586bc920c8116aea2138d3f9031f2b046402f3caf8c630daa8e87318db3bf2aee66240eb724ba3241aebdfca1a02e86d30761cce3e26839da080336ef6d1500
-64 1 206 \\x15b65c9d8aa6e50d9ecf64da412ef6ce3e5ea6394c2c8b7ee3c4893a580ddf1b4ec7640da3aac2fc266386a599ca1351a068e0288fb8951dd57ff5d0a216ce0a
-65 1 204 \\x00b6e85d285a1c8284aa6da37f6a3977da56c75b85d4ea5bfc8966e352006835d69a2911d1de857b6072bcef5368810c4ea52bd9f4fcd6c0c3d23913fa0b9a06
-66 1 258 \\x4c8119485f104f1bf020beae5085d49b74e9347b7cc1eeedc0dfb6d7ca9ed7128d217af915a8d460b984eee5d8292e3dea2a07611eb7f1a54cba7a4ab70fe30c
-67 1 302 \\x2ed8cbeb549ac005e1e0affa21dae53cc52c936b44447645151d61a216f5da6529f2534441fcd4ee79affa4c260f07cb2eb9949df04d4da984a21330b4e4a806
-68 1 130 \\xae5bc1f0226aca5136e504506ea796a875e1679742364403dfcbc984b0d22a535c562bd29c9abc8f123f1d3660fa2f5205e2fadca0c41e2dce48dbcdc4219909
-69 1 159 \\x2dd74854fdbadc82e720e488240418127395d01946f5e2f5fc2f7a565366ff0fcc2c474590ec0703fd57f8d61b5946c2c64bb4f7795861d0387bdc05a4872f07
-70 1 175 \\x403318148a4a45facc9cefc5e39ab82c66976780889868e7c61409e76bfa11571dd3640ee66b6364b546557a29e515ef183dee7bcfb9805da9e43f616bea1504
-71 1 131 \\xf44e445aba8fa818df3d8460103e7b7e6469786cd473c19f93c087aa955688025ee8d041fad0918642c8883ec261ebd229985e804b110fa5c31a5f2c7fec4d0d
-72 1 205 \\xc9412a74c4d671377a0f2da9fc950d35c6cb1694fafae83ac1dcd058bbd7c64fae0d2ad781585e01e376a019a8b19d41946cd2f3a42da93c3506a93e27730901
-73 1 40 \\x293a8081c9c1e63388f010bb55e4612f33265cb7d2b76af292852bcd1fd384fb2567d8fbee5fddfafe45b1c0195475a39763de11e8e31b1a9bda10ddf1d21607
-74 1 363 \\x304b2f94366aad4e9815fc40227b585be5683366a18bf4afdec5c42dea324908fd0ac637079834932440cb8c572ed8eb2318e2847361cab2a3b2b57b81095a02
-75 1 70 \\xcc8ef960f32335adb4d3127852b4d60dea91a06a8cc64427c498bf5b81e480f5a4294aba5a38c09211a6834004f3d0116db5f29e6f23c0b9a545b94dbc6eb40d
-76 1 413 \\x10111b9918697f5fbd199da212ae9f3183d8245fc2a9a5d909a363ffa8e5afdf104ed743f89e1eaa1bed4005266db18f865417ba82e6c02e8abfbaaf6b2f400c
-77 1 177 \\xd298b4966c5bd112c2ba7cf128bc8e01e97ca907b7d1f0324e5af784d103b6a3ce8fbc6c29f9c818994e563251519681015f470b429c34502603d29da8d0a202
-78 1 5 \\xb4882b3db6b542add726e9abe9b13a20c270fa42e96b87bd29941d4559707676373ed57ac505c689c7700144773d0222977cfa414abfb9e531d9beca2c08630c
-79 1 16 \\x4bc6146ae728f53b22bb2f9071a671919a23b1923615222bce3b944070d09e97e43f360d79fa04303c21e3ca9bb6d660e021b5bc5eb67c77a812268edf87930d
-80 1 122 \\x6cd26f81c089287d54248ef92a6be9997752487a2e317d070435edf964454faa642bd9dc060133300dc8dcdb0997a667ccf775262191077385e1e80f8246f101
-81 1 17 \\xc97f1de820927b6108b2c21cbe04a46f2730dc6aeb5d840afb9a140cabd0ccd660dcfdf422d0289410452270a61cee9e4c25e8e155223c1b8f3f993127c9a002
-82 1 57 \\x1147af51ba348e2bbdc2f5635d09e0fcc7dd6c402245c70ee1530a90b52b1ca2a9a2cece96718dde2fec998c618ed6cf63447923bc18a6d471ac8155a4c87f02
-83 1 269 \\xd19876269e5c1d82e6c4c3ef684c772e1d6dfb27c76e6dddb9f1fda36efb9a9780d2db1915e36c21ad5dc60ed03ff81ab3d56e11c183d736daf0e56fa068b300
-84 1 166 \\x76499abcb322073da74822a06f41e43f0cfc2b39c4519b019daa65fde1b22645b99e6f31e0ba0cfb8d16c7b015d75c4b6b3d594d5761281858bdf93faf25f905
-85 1 236 \\xcdf02e9ed7ffb1e1b09595a8b79761cc076c1ea9838b85e09b570de1cfdd38c9d16ee8bc222b39d7f96ac8530b64ad822c63a559c303d512a527a0b744c61308
-86 1 279 \\x84499554cfdee3e2fcaaafd1407ba8b4c3ca5a9945dbfef07b072f8a6ace4e3575f09fe930fe5a3094c57ca18ceab3fcfdc0ef051dacf535e85b7b90c2d3c90b
-87 1 176 \\x475c672cad74734d2d824858db4c58f06a6c10b815d9e6ee86d0c091c5a6120ef89b03b0351ca96dc1a911408341fc352073c04847300b648640f628bb784a02
-88 1 371 \\x9609a3dd04f23c19e3bc3cd5ad9c2800117c545b201522cd7a6007f42ed888e3791b7d713e72f619d7b2b7ffd9e9a342d1114f5d2c6971171a1466158c13da0d
-89 1 249 \\x81a585b38b7c4c6ed1ff38f7bb204812e8d3985539d86f3e40b87ee54ca66ec13295a021cb32d4e42d28e9423c2d4e551874606f3ed93c3476dabe719fd2c401
-90 1 25 \\xfc49f6afc06ddbda59c97cf721e9e0aed4eb00a3457d8447b229a04a81063fe0f3e6cf2d151bc07d0392f7f62cf933c07a8a089b201aa3ea9a73c420ba992a02
-91 1 152 \\xa4ef236692d4b4d49940e9da1c78973294393b25b0572de95b0e016b52fc9339a2cf316b5c1eb7e69cce1696099c8eb16d42b1c86d317478d74d2051fbec6206
-92 1 368 \\xbb8754ac5491accd8038f8f81806f691279805ee3b7c8df129dbe348505bbeb3b27630971761c6c23b3cc0c223dfc7f74d05ad42d1f621dc891110d01bdffc02
-93 1 161 \\x59d52e8817ea100de37df9325074cdce50eb0ac4bde3a95a7d0dbb33d7092f2d9bcb107103de987bfe4ce6a1d7c6938223e1763a257365fc5fc5e5aef49fd206
-94 1 37 \\x292af2ed2a16ff32e160c0d5392c545f41e9ecc939e95da46a5cc63a70ee6331a0d811a2e64ae82ba9305aacc2f9a03d7bb16e0dcef2516d01c4cb2a63e3f509
-95 1 310 \\x8e3622e1742997ba86a82f865a09f427a96cdae0f5b1ddddc0039e2c71f50930479d0e895f9cde79f5fa2741f9f8eef7c95b594b29f38ec4cf2dbd0bdeeb1202
-96 1 342 \\xe7c8beb326dc83bafae9cb168e847a86ea2f5ed8fbf86c98c404a644e1c58c946755dc083b25e248259ed6af8df97ec0168fcff019318fe54a6ae00e6848cb0c
-97 1 295 \\x3774c318f2f7e7e29ea6cd511a2e659c6491e6bf3f3a2ffd0df57fd435cef74c08fcfabf3ef093c41ee3eeb79669f17527978502e79cde9ac5e8dff3d902ff0f
-98 1 420 \\xec315f89a0e4fda63f27067ffaa68c2f9076c985607f21772ebd98b1257332e4222e47c393fa2cc26c920d577dea52e734677b2465de846552382af2a794ad00
-99 1 24 \\x193137517f0e75ed6e9ef22b0e505ad629f4769ba364e9a0c389f3087a092e366228b0de535629a46e9bf3e1f6762c0c111bbea1314f5b9433dea6f4b1fcb509
-100 1 38 \\x66e5b84191457a6bb5cffe177926c07d81d08db34f61444fb9d37b5519deb3d0c3efa1869cf754f49b02bdb76ab24d2daf7cdb8d5b57d5cc04cd704f5fc7ac0e
-101 1 399 \\x92f556b5bb3fa83e7221d5e576de9215f5535b325fd9d6f39186e89393664da920f798a43a36661318fc831956eb06de2a042560dc2137902143f04c07c08f0a
-102 1 114 \\xd3c8f2042cba21ec89fbb63eedb0d2484bc9816237f1cb38fae120e0f2634e01ed5c76b7dd79c63ac8fd72fb55717f60e8e6f0e84d70d0257f185ff0f49dd60a
-103 1 155 \\x013eff58fb4bc6e9ccb167bade34e7d016906f3a6634fe9204002c917e3dc810d61ede4452d222234b21e9bcb7ac486dca6463dc86b2aa4129d87dfba80a4d06
-104 1 116 \\xb4777c146648cf8a77579f83fd8fed7a3b3f2c26dcf6b7c48fc62b13c71258b3d2ebc5f25b2e7221cf2d8403bb4067b4d6ad96d6080d7573fd9ba5cc1bc3e209
-105 1 190 \\xfcd097cc749539b498640853586d8b8f88b68e2cfd1e23ad2db492d5cef2d7f0f94e2e74c45c38ca45d5f73b544062ff6f17c614d7e4ba9b2508752c01868503
-106 1 365 \\xae537096a182174a0f705d441005b85a8121a0fc28eb6ca1a32534fa11b3fd88f44c822ba2e2d8294ae2935ede3bf7f5667be2427f46a0f687d8390aae7caf07
-107 1 148 \\x4cf2aaa26355a96ea367ae11d52a2d35ebcc2ef5e915dad2cdffabf0ba155c0c13599e12fb5b73d78df7d6bb01af9195ba12ad8d1772b8bdf00b60dabadc3d08
-108 1 61 \\xa89152522c7c80838e97dc3d6290d7dbed9263f2db734dd2a3cd1d5fca0e012e63c43b406452660b509e89801c5667390d749a04fe9f0df9eb72f8b65899770b
-109 1 171 \\x8a7dfb68a0a36e22880b0445cfb2398c77753809f3f393f5e80b98f7b610edb6c5553956785013e8fc0e786f5ae1a8923948c2bb6865bbbfdff8d84767ccab06
-110 1 144 \\x8e9172c021efbfc8b530e415540f0ab03ea35f0dbdc1fb0fcf8472ea26a47c1644e09c3def1874ae96236e4aca7401cbaa636c0bf40e760991016156befcf70c
-111 1 280 \\x23733d5f27909d06583e468a611eb1640681f2df42405e1801a6380299ebb3df943a9b464c412188c6856c2bd611fc139b81a9d9d2b6cef1797056e53148fd06
-112 1 220 \\x40dffefcbb2acc17741b8cb52590e2622eb7915ed233852126605053c814f47184bc21572634bdbe46a2e51ee31dc9538a86f32c430d92aaef635026e87dbf09
-113 1 172 \\x3deef9610e8d74edc2d8c71e70a8080a3f90dbcd9d70cda332085fe781723e4e781aaa04c1a7832f36c4733761df1f3e1a77f2a5e7209c65587d2b7c7d6c620d
-114 1 360 \\x35a1aee149fd937f43dbd82b0fa55c85c3c95f8b9b1b02b62d40d6a0fc0c20fdb5e8696a06d522d90349e55b0b262bc360f8cef35530bf1a566a3795a103de0b
-115 1 398 \\x6fcb9cf5787f53615c8a14387ade9dc81e794a1b9b08de6c01b1a4a81f372c40e3ea1a6ed19a3aa0942cbadd23fa1377af1bb5efcd5118e92fb295cc1ea27b0c
-116 1 228 \\x3f3a4b20760ec9139cf6755dc92038dd5e3a4b3f165033b826e90524a7280a458110c104865a61fd6a0bae1998e5a94b1ffa273d9b0151ba6e8f23a87169b50e
-117 1 90 \\xdab7e865494234f15ab5c736f76099ab435666e4eb9aa27f42b4043e23d69f5b1b3adaa051d43aaba356ec83fad1e909850f6634a8fd04d4bcf67fd5c8c40a06
-118 1 253 \\x0a4e42f1c5094a5c1d6e47d28da5d461b1295fc565a6286f5af0e8fc6afc70240e5b92c5456ee39c8bd459ed8a878c3a724ebd2fcaa45207f6598027df01e308
-119 1 179 \\xf8faabbcb8732d1b05c8c96bbf9048e0585552e2716862dca25ee9807517067c8a90181a45351d06ec8d6a66121230cfa14096c8177c09703cf1e5241d7c8800
-120 1 45 \\x4a563b876a6f365371502de3b9f22ceb0ae2a793a8964982f606f1a80a0d8b4d7ef65929ce51726e9a61753f838c4a7cda32d2f4035e498aa7b581526665a008
-121 1 277 \\x4d327fd42dbc4c62d3f35032005053a7f8149513a2aae2452ca272fa2abd74979536e3b92c5605339068c63ea8bc079f7933a622307ca46cbe0be185ea1f860d
-122 1 284 \\xb90cb53a770cf18825d2e9116001f722c189b9bce2da12c08c2f8ffb3259dc6b604170a7c51a6100892803fbaf90be31b03692f6ce15db481fbd788455494b06
-123 1 234 \\x6af7e44b08db815296903f32f3c4c93877e494cc5ca9521370efbe634e0619c0dec1f747a90c504370442682dbfb3bf2d1a6f6a2bbf6172c18bf148fe8197e0d
-124 1 53 \\x7b6326f17f11bd18f5e5b9ea6a747e747b4c4b8772e07f65e4c7563e71033dbc272f729a2358b7fc6acdbc53615b75eb7d97dc48f28a74fa95bbc5d838631d02
-125 1 95 \\x8ea7452ad6557e1506aa167f861e9be0f81676966f71707679a31b370c0b392a03f1550d7ccb0e46229c07180f78543a91734f486134f91d6d3851aa16055f05
-126 1 281 \\x63c5d2c002ca6ff05e81ed96276343871fcf8c430800bd8c6a7be22daf1c4d9adab9b43d595b3cfe954538c3a0a1af0d80a13fb359f1e590e16048ff6c78aa08
-127 1 353 \\xfa6779bc51942bd488233b214af8fa0e9c3a58c5d00f230a60c0c69d7ff4c99bac7beb616d3601c42339389095ba868d5a8d0b806ba5a6051b17c7f6e0af0607
-128 1 217 \\xc6d373974154bc15a4da491c2f217f42dd8e784a66b95dd660a3317241fbd31d768bca607b51a19e81cbff22002c5e609b1aac918e1284bb865a335c776ed006
-129 1 156 \\x7f96da32d0f3d7511f96ba188beeccc648f4551ae1e623fe3b6f31db86b269b78b48c682c98c7c0d325f2b60be7017102b1ab7abd737610e2b7ca87ebcd55201
-130 1 250 \\x5b35b714683623e2a0c6ce15e573957384274e0f3be20e7abee31307da80ca33fb1589e5574f36ff07ee510bc46276528bc19d220b4044c1582f34ffad015a0f
-131 1 380 \\xe4c704a48005624dde50d05a6ecbe7ba8bd8b0e9865b3c25d7bcee83311b95939e1973cef23381639ab312b3da912b7d10701e42e8b77c0593bf65f477cae800
-132 1 136 \\x07ec39c322baeab5d455d422f4056f91d4b9288fbf86c011c89fea49f93cee568e623e74faba27ddacd8b50c3f5973f33664b94a4100c7b7fab27cd95af82008
-133 1 337 \\x58d4c27864c3252fc6d097f909a8d2ba438ae2773454580af43667287fb8e282c2ec5099e12110f15d567c5b5d70f2ed185eb0a774fc71e91a3edce2017ae907
-134 1 294 \\x360bab3efe612912891e351982662feeb4a2d5f371284158eb9f1d5b259db92fe37d90c5094e960bbdf17ea56a335d354a62633863320f5b5409c4ce22eb7305
-135 1 286 \\xe8b82736ee20581c8ce2c032319767294c97ec3d48fa2916848870a3525bd61906cebfa0e2d806bb647931530f642331e11a32ee23691ffe0565a52af8e8a201
-136 1 296 \\x6d1d3a04131d10d4caad5a4d7c6c530778f97561722a3a0d14224d42479ab190d86e9747a018ed4195938714726c6c7d33e79f04be3304123a8b214cd7ee6f03
-137 1 251 \\x73b415eb0bd462d1d27a855fee5049f7f517f482b8f7711b0fa0ddad34eee4b0bd02638e7439cf193a9390d7a2e1dc6d4b9b694934d293603f6a9cf591f78304
-138 1 149 \\x872fc95a5b9d6d4e33b356960590bbec48997908e40c402ea3164d7ecba7a6c1010a4e27735c537ccdcba7c28b625a9124f8d07214c45d9b8c076f4b33cec10e
-139 1 196 \\x3062df479d576fb14276dda35b2d736f8087b10be7642a4015b90db0ec87147f3069b61138b37252856a105e02b8e7c315ac3300fb59f2f6502106b9b67bbf0a
-140 1 29 \\xc48d45e2510af07e864f23d17cf34e3c1f15dddcbe20f14a18ea8b998002552c3813e12195e61efade81bf98ea30a37633b05660ba7a4302293ba1025d675a01
-141 1 154 \\x6fade8f89114ef17f26c37b26a111f42c1ac5802db4b008f42805ef180377c81673895c8103a64fae21a62b468bd37995ab8ee646e7cc0f3a9d429ab8e7f1904
-142 1 355 \\xff092e359b782c6d930c3e7bad08254863acde3f710b322b43ee12042ffb6da600874515debe3c9bce8af31acbb7c91134d6dcd9a1f0de833fb8fb623465e50e
-143 1 185 \\x8cf5ef75ce9b21212e9eb12c4f065309a354ec8bc40d83933e7a384e13d01f13896a042eec1b501819dc425e773d424a6ab61ff24e8d5237caa115f5f846a900
-144 1 101 \\x06d6daa85c23fc58021d6372980f269d9d8549c8b6a39c8393edb59044e21555622129629a221c4287124e070be0dd2f61d3726f3319a7c8dd146415a4743503
-145 1 213 \\xef8c48a52e4802969fc90526b911a49c1b7651f88302ec5e4f1bd0b00cd027739991373f9ae526862cfb7894977027f6019eeda126add6f403cda1379d78d506
-146 1 247 \\x88ba83b4e9893f293015c2199c17d60cc8a8be93ab103725e47a609929b9561b3f9d4e6035233922128efa55e24eb3501a10e2b83e37ebc1f67c4fc9c57e7e00
-147 1 293 \\x2e864dcb5060d4cb98a03e13a0906ce7b65bd3b30af09a020a74a28dc69130107f9eebd339fc671212726692ae34587e114ef5ec16910c7cb5026c2e115efb0f
-148 1 135 \\x1f645d910348ccd3f717eb06470f242202e9f8f333dd33e307dbbfc551ef97bf0bf0ee3a51e61b0cdc87d864bb3fc86f5e01903b17f95b49a24cf0ff05dd0901
-149 1 357 \\x5e6f69313268efee9d5ed9c137beac170867aece7370111105f97541dee2108ecd09616002a4d3bad9ae9b7609b97b29782fa1c9b5b6afd60eec511bfeb67208
-150 1 22 \\xe6d3ba57845787efd0be7f2d1f7354a0e8681c3c9b88911cec79400c44ca87f8c22c2848e64452e21350be24c333eae12a5847a15d67a723e00ca29e41fa2002
-151 1 239 \\x3a10759ca3a627b00446249b049afb85ff072f964162f14c8ac21eadde78b4c4d16af94591627176d52eab124db041fd40c3f14a5832f6afb428245387a8d003
-152 1 262 \\x0cd3595bf0918eb5456022cd82df62c677c0d3a447e43651ebf5b85bb753ec1d22ebf2d482ee7646ca1cf87e345ac5c05fab6249f8ab897fed85cecf07f5160a
-153 1 285 \\xa4e96516e5e20967d49fb8ce8f0cd013262fa38556097a31bafcd1d868d974c40913c423475ce21616edfb932c10c3fa1d7c503e72f8778b8398facf72103507
-154 1 263 \\x60a1a443c673d983d1724b5d2433a8ee3a356523d902fbdae0b01e356917577ec74cf9476dab8ba7be67e6de06ae66b2d540ed4efdc4ab07958f9bb81bebbe0a
-155 1 352 \\xd363d63cc9f47971a3167c6de5f72d93a2fe7d7214c8970019db641b850fa9994e4edc3582a7fa76cc5774a0be82369bbb5f704980849857ac5a141733431903
-156 1 80 \\x1c5f1b612af7b2b8be6b75a36a7f1acb908b6357694c43c9bc00ead8597e21a3132e51647f43da608596f59421b27ea013df234b249c93ae146ba15249b5000d
-157 1 393 \\x2b58f41410c5160341656abb80b9220a3d0ddfcf28d3e4973f68544175820895cade5a72c0a79a6d7b81d4518a76d0b65bb5b3a82d4f65b21c903a269ad2f701
-158 1 305 \\xc360b77015ac3c382f74cc61a7261fa15495fd9f569a0f29140f2262926725ad5762086ca160e9d6f4b7d5c1022c7b84deb419d5facb542200bb8c90e4c1d004
-159 1 167 \\x6b093f220a6966f8668e369b8b3b6f669263a8ba5e2f8aee82f2487fb6ef4f80c94e06bbe6ab4cdebbafab386ecfb5df934a10e54782ad2c5397575e472e580c
-160 1 339 \\x4d9156c1edf353a5d3d9e89d499c389f8e11846e2f5bfce3b3dce82993f2886fcc2e6dea21e1bbb5ca6b0c083f69c3571b67b76539e72367e358e629f88d780f
-161 1 362 \\x3a2dc3f2f1a1ede2e22685c78a4a4ed8b0538431f9d0ce95673ea2444025da16354e8b779b69eae71b9b6fd5bd6b2f22322b034d2db47177d70fc4916ad71a09
-162 1 138 \\xd68d6525b678d68f4509c1d1257619841b7d7dbe58240c63286728f6e0e10372b1e70812c38f9ae70de6c6c0010a1f68a0784cbbc185711cc6cf076b5062fb06
-163 1 76 \\x500f0075af712dfaff7c88534b1c49d39f75e59ee9d9e1448f3ee3a88cdf9e3a5a2610d6b99df3596a93b919dbb8dc3a0d1da89bc8f2930d19ad4d3941fcd604
-164 1 163 \\x15f5e8d2f0db9f16c09366a3aaec6d8bf905981b392830f7919427443db3e746846164bb667b9bbdfd3fa5a414f299589e356346147da5cbd693000ceccd110f
-165 1 66 \\xe35f91a1fd109aa6b7e9be5bccfec423841b938c9d15484f18b060ba2f373a8d72612c9e86e46be6511ea4e80827697416baf874b1c0412675f6a6176fe0930d
-166 1 314 \\x4f20343ce851459ab380ac2f0b78d17bc94ecd016472b35e6caa8fd3706bbceef063dea190eebb6592c873e8cef98f56bea6a5c8d2c1d506d2f298e687d8ef0c
-167 1 400 \\x538010e3902226d16349b4c5393619c8c502aaab140f80e20e7dcac75e294eff46e2c24407f491354e5241b1165f79f856c66e3230cfe5af08f57d53118a170d
-168 1 13 \\xa5121e894063c83aca11b9b6cf8f2c5a52483a7d5ddb62447693d7530afb299c22acffed80ef23a192275ba7bf7c18567dd6191d26c309b53dc1975bdbd0950b
-169 1 128 \\x038ea07c154db88cfe4222c14b148b5326f5192caff640c2d9d1bc1b4a8ad44e46bfe755d0653b275b3333dbb50cff756f88b3a3f3d1542b4db4c54957e4470c
-170 1 229 \\x111171a650c77d6cdb1ab6ffae5ce13accb73d85336eddb6b8221617fe889e54fdbcfa3789c482580cf7f518a2e839a515d9fb6b832f178147fbc48ac6213c08
-171 1 72 \\x3d4ee0ac827cfb805c35b02db1a94091107fba7f1d2afd9f5d9dfd44ff580c182bf4a78c4d3cfd3ad0dc6e382f71afe8bcd202fb652f90a697c8e38d94c24e02
-172 1 104 \\xd827ae75316ef2e44dadea30ea51d52a1f709bcf4d5f7c6c906549c7a811b46e91f2880dd71f11c0960324440ade3e1877e9c530d05785e5b985b26815b5b803
-173 1 311 \\x0e3e19af02ec8651e68a65d6b2ed06e896ab3f7a57ef127d6361d5a99e2622c468268d0c2556cd801f95b984259b93fdcaf3b4fcf48c97829224b5b5e5c6ad0b
-174 1 230 \\xf046bc7ca6a2f735e1b0651b69d2ebefab06850d1a3fa24fb33c8bcc0bf9ac7f376f87df8f02a5918ec511100e04d4ec12ce64e273fb9f82a4b2652bcbe1ea07
-175 1 174 \\xe4f48737dde0a9dc5595c154fe3b7c1e38f2122684bb6dabd7fcf4ff08b36cacd8acdb0e7843e52411eb39abe0148c4d80899a67dfedd629e4eb52eace342308
-176 1 132 \\x82716417755023a0fb8658e19d78a745a5279382e8d3d5d7c73b8a67b49be3e8a5bac1e9ae6bec896c66f4c13945fe22f47a8727646895a3d515852d81534706
-177 1 199 \\x19928b9ee6e205a5e5ecb81a7170d3c062718c8ee6f441eb07e967f104c1dd275e0ce728c7cf79d1fa6afd0445e87bd31afb8e884e4e9be5f6c1e9fc3a7bbd0d
-178 1 402 \\x194ed6da8ec1232c48c65a493829c07fe1d8997db469cdda0ece0678bd37219c96e062cc0048b97374282398524a30ab4592437ac95e312addaa74daa9d52f0a
-179 1 62 \\x196a87859cb79a1d3c93729d3666a77c0aff7420e268ff28092b4ab79d85c45c16b3b4a68cec1ae6b87940967f97eebdf28d2cc4d28ccd038e698e2a70d0da04
-180 1 266 \\xe6ead3c5f35217d776ef6c17926a474ee95a1fa4c0b494bf327518ed1f2fd0a7cde3f8be89da8344b3710be3d563329f64227ed1dc53833c730b4882029bab06
-181 1 93 \\xcc99eb886487180163b811f1016e8e820ef1a6f3c6e1a22f05677aab21ac786da87f64d8629e4e9eba6f75a856c121a8fcf83ff74db70f39e7ed4ec407cf940d
-182 1 288 \\x04d1d9e22a068ad667cf118167506e83229f9828f4c4ad8bffcbec01b181bad9d9d58c7f14ae90655e63294ccad6c129d86151ff802658ab61c384acfb506100
-183 1 109 \\x7dd9ba9293df0e18c89bea8e5b88a8b87a8c06eafb85ff93c30b3c794a974fb044c98e2bb14124a690e5b0b22f31dbbe728eb7970ecf93606269fda53340660b
-184 1 28 \\x0f0b4dc8b5878d0f8d342e5d9ebdc462d4763c02fc8605d6f69f129dfd16293978fd82defee559cd166852c4b2d0f8c3be553f6c90b311241a03d1a310890a0f
-185 1 51 \\x1d20748b3d88504714bce11531403f289fd9aaa55c1ebbbc2e7640a63e954b6c81d4e05d8d373998039f740188de5b4e73f1f1b6f1886498ee1fcb8582294c06
-186 1 421 \\xd265c19f0125100a1ea93f3040e47f09036f8f49162200eaf41995544c7b30a03c17dd03022dc7cbded0d566321b5dd0ae7db3c793f24dedd7a1adc1f29ae202
-187 1 30 \\xbbae106a733d5f596f5a997cfc028337ea7a9cc4e237f6cc19d62b915f861aebb41e3c527aabadbf6e2b3fbb3ab446cff1129f05674cb28b034b4d7649a01909
-188 1 112 \\x6a6667f21dc0bb131de5dfcfe0b7a7d06d6eea98c7a2e79f7a9a29df3ce306ed8449c57c14111254049922bcbb38edf91cb0894bbe6fcd9f7892e6007c37c002
-189 1 64 \\xbfa8411e5f6671633644336c3e1d079af4a617aa10c8d91f7ee82dd78e07946468b4b96fc234f08949899951e066441aad284e4e572c67309a267181a711a705
-190 1 275 \\xe05afa31cb2d0b297cf031fc609744b60dd9a38034223b1147aec6bd698cc3461f35d8ba2405ebddd70de5c96bd30db124ba603804ae718d0bddf621d1293c08
-191 1 265 \\xa27f79578c5f117b5785da42116ed16438cad4d652d022027d1f1f3251fc54b2de8d0f0edf781f753a526a9c2aa3d21fd3774d5cbab4ff3183d5739c8e88080d
-192 1 351 \\xb7565a1328562b06e6b1b772cbfdfd51986afd81ec6e7a1e76c3b78d7c39a42b1c2bd6d2e750d3f8b26320ddf8b9afecb80ab8e41da76dbdbb779cf62322080e
-193 1 238 \\x6a42d1815a339b159e127374e06f43034509d50578ba2b651c4ab240e52a4f6d0526fa4f23757fbdb11f5d04b2e82ce8d8d6fbf3d81dcdda1c529652b32e770f
-194 1 267 \\x46760d1271698615171e5ed1b998f3dda87ef417c916481671bc853b984252f846e27657bfedf25f8e23d1115a83ad58e7cc59617680109d9f86ce1fcb1ef805
-195 1 343 \\x39a8ea25644e06aa3b746e2b48b97c402cef66ed167468c3103444e7d1b9b757d42b954525a1e2b31366d16c5d402ac43eb852e285c89966b52ff1111db2960e
-196 1 69 \\xdecfd74ff01caead593a3ef6b59232374937bbc18095d3515210b796e6b2adee967f66a46bb3ee66a8e8f8f7ec20428939ffd563d37dd5edd3764774d56a3406
-197 1 272 \\x2bcc40e2bcecbaffc92fd5271eb72023879c2c0f92b0c891d41c3bf3baaf5d22bd4f58311087a4d22f256f99a3a7ce920e8bca4f4c1b2f82a7f3189021bd330d
-198 1 282 \\x305f0d0b072b475276cb6aea4bcb748835f0f7d270bcd6660f6ca9ffebe323852999e470a228216f7db743b7d661a043fc5b59cc032c0428c998c9739f5d860f
-199 1 407 \\x02a195b3740522b6d0b27a5f3ebe617b9174954d8e0a18f03aeee52592988fbd0762bd81aac0aef5ef6b22b00f50b9d3f7f0318bd1e9928c7676c329c8775600
-200 1 333 \\x0415f706523ce3e6f058d19b13cff560734a5b52cad7c2a94a4db6abcc359d23ef3afa516652f7987828147d950dbec0bc27e1e5c952f15abf09d3dc23606503
-201 1 317 \\xfbc81f222620e438027b65c29c0257578e0c4c277b66ba44cfb56bbde61d3f7d2c02ab2b323f1a26286ab40045a428b5885236e5b507c6bab14917b740e42a0e
-202 1 369 \\xc4e433de8a507ecdb862e8bdaa5964da20396c5717fbe05223bcd380495f17d3bcadb5de526b6e7f4e9b4f7e66e06cdf43dc42733b860715d454cf2d6d97e208
-203 1 414 \\x4a98b723517f11522249d1caa820ce8e4d7829c4c603af9ee13126176f44edc699e34fb680eec2f7b14a3c7fb2ae86e21a7088dc55a8bc69786aa493139d7906
-204 1 320 \\x6ab1985ce7f91efaac57b962aee162378abeeac9902368990ed1a41afb3f5025e0da250aed3613c0553d56e936ff66eed02234d19d04c859f569a03c94f7f10b
-205 1 186 \\x540b7857933a581a6450fc10b4154977b1a744443f5cd5d401ef99b676fc49f7870b2ddff15e8b104fbed216fa1265828767702cf12426f6f1c866d7191c2a06
-206 1 392 \\x9582cabce9e09679e052d410fd5e028f6297c2671ced0d72f5516fdb825cd2264f4935deefe6b8ba244bafde6fbea4119cab0540888fdc042c85f60b559fed03
-207 1 233 \\x9f56bbf75fd4ddace9c7cb6527120dffb70d77d54e134425e89cb0e21b7d1a8cfbea860a3ecb400df391b2c99245b9fecffc7d4b4cddc36d360fc89e50985301
-208 1 46 \\x17ac2bb08eaebad053121222c0885eca57f02f8b583ebf31c094689ea26817318b65380d6e88570a952c0f175fd51f6efd208ad8e652ceeec32e14948cf9af0e
-209 1 273 \\x0d68e858249337c4e13681e5e5abb99e321d0632748e86f9f2884afd6203ed2c7360aec3004cc10d883218fb5d2aa5b90a4636782263166912140e4cf9219a07
-210 1 356 \\xcdb90561a4cb91ad0ce3f91e04efcf1c073636619c76c8e22903dc2fb4696b3e57a0123b8e580223cf97ebd75b2949b2e50914f36a68d2a67b34f92f982c3e01
-211 1 336 \\x277ca37e58ca26956f94ca80441d826a419827f514976d0ffee440b8bfd88cb0f4788f2c7b03f72c7d68cae87b87e57ec086eaf1a6844b5cb5b81a321fce5008
-212 1 367 \\xb0bd843ea9182c60de74145b9b011db771e23f0312c14beb290c3e5368c76cb1b1d088c6cccb1579854b5ded94a7f634dc08baabbddbb659c5400891e428ac00
-213 1 124 \\xfbdf55774c6ea870b30b38176bd41a8a16c01978ca3060b26027078c2010a4fcf713599cb7f3495e83da14af725fdda5c92afc50df39f240e2882a64394c6e00
-214 1 212 \\x5480e7e72040a3ac911b0727d1d0b275b77e2923bf0c1a74256684df89e29b15f10478229701cc6679ed029f31c81ef9b9bc9fa23f45a7efe287340d18464401
-215 1 377 \\x30ca73f53cd53c42794b4ca51d5dd2953caa0b3005d0a044be7aed4d48a37f2e2d2bfac61d2fc0b737013e03c7fba77c884cbc77e9895ecbd8bebc4b11040c07
-216 1 326 \\xef05dc88cda8a9e5e3681eb21f1182ffc7112a93cc8b84a718fb86761aff88c17807b2b8958a16b87a1e44e9fa1b3bd7e88af7cae0bb4c308258adf2fb719a0c
-217 1 65 \\xbbf54f64742a5e2074bcd743b81d9e2f9aee518bae0e65756e3b7ec3d293a09191a6f2d958a0adacec4214543ddb074ed3a99e338d7e18abce1d43e85a402508
-218 1 192 \\x12072462a676eb0d2a4ec34023a3d9309278bfded23491e50376cd88ccfc66b7cc9a856c04a8bce236b6b442d642e9bc423c01f6cad51255e504382b188fd108
-219 1 100 \\xd529fabe53cf14da649561527124c15b9f4eac63c2d71e9389f70ccc709d72b6d83ad06d8de2641540442cc92bb5c6bf3dbb95b7752ceafe9dbb25837c83c607
-220 1 12 \\x5a9d7329dfbfb2d9f590eebadfdcc46ff4b1c3a18fc59738aab9ea80c3e88d600622ed887510a79b2f7b6cca74e90076b6eb24160e7b3d3527ea7df485096d08
-221 1 259 \\xd8ad5687b2e13edfb0eac7ecbed46924b6e40486a49d8f615c502eba8d4aadbd5719b7c07082ea84660f8619613a0997b0ad400c67fe14a0b79c3a57fe3e860c
-222 1 287 \\x4483fb23eb6450aa09fe08dfe4204615ec59f27ab77264f04f5cdf340c8c4a25f242fe782e231f1ef8283cd75485f6f4678003b12465e94d70ffb44a944bc30f
-223 1 158 \\x9d5904ac5ce218107735c68bec261b88aa071a553c72a639c0ca0b89c681a39718c78a00aac20b1bf906a77a40936fd5c43a2dce5cd2ec36459752b82af3b102
-224 1 375 \\x1c93185d539456b62df2ef8b08d9e0fb23aab1b16e880f2d86206a3ae29b1d2ae053663eced5fa75a67cce673bf5a04f81fbc4291ec3b6f5fea4cf30ee14410c
-225 1 322 \\xf9eb26f3f492a7f3ea5b7efa5fd7de97842cd3a54d003c991a544ab0f81e795d12b489b08320b6ddf36e4642f1f4ba16df0f5469a220214de85a0c79ba0e8101
-226 1 243 \\x0ee22485312510a08220a4a11688dbc1e7f30660fa7b65300bdc9fd4e6d10ee87b8e49661b3e2eeb21d67f7f400f8ae0c846f9abae6ccb18740d08add5ad2902
-227 1 246 \\xf515592f34b6b31a431829c2ce77768de64a6b9d1c448cf994941f7224ef9ac0d0167190651ce13b80299c1250e354d3e5b89949c7325298fa9ed9ed3cca3302
-228 1 378 \\x2800f73eb34fc98717afa993deb1797cc2a44f7c0c1e3031d6dcab9f8268241ebf6a4df3059d7cc52dbf3745bb27235ec31062576275918794ba4c983fdeee0f
-229 1 381 \\x89bea7fa7899712cf882b12e091ecbd759a3da8dbec16c90eea7420b31b56b9d9424a69dbf25708300c82d5b7eb7fb1b10107375f0b94a69b2e5aa96d605bf04
-230 1 145 \\x71c3d3c4724f372a5c782165c73b1ec2064183a1e6232dfee67da3dfa84059ff30b8028d820f6d54f22848f4e498cac4520ab0d004cc2e361a6ea393ec98490d
-231 1 71 \\x26be5832ce2b2d118f00bee4546a4cc296c79af3aee34e4379115a3894b21b1ce40c1117b453ef6dc9be4f7c344b93e5baa76989da8dcc9f3b5a7127dd699308
-232 1 388 \\xbfa3cd9ebc86aa3db2b28b8b3f160d479a7b4763d5adb4285a3d597407a4fc804a80a483d506f03e9cdf51ad946019e27c3a0bcb18be25f31fe6ff6cdd71e005
-233 1 111 \\x3effc64b68bf4b0e3fe827871a965701fba26d22374db045956d580e9fd17f4e1c522bcca995fda7d19998c05247090fe81296c5080bf628cac3591547cf6809
-234 1 344 \\xaed6fc94af52866612209eef2ef35628bb6f9a89669558eb991ea04f99c03dbc4e254a3770220f3fcb29a8f89185313a2a783218a3413c53f0fb38cf6f170c04
-235 1 147 \\x08ca8c4c396f5e90c8fdfee06ef95f8271bb55cc2be51dcd6ec688eab740ee94d6b3ca1c525ddf2188545143fbde8bf94edbb5aad4aa67d3c60bf5078b9a3c0d
-236 1 168 \\xae971ec0107d5b015b06d018bae4dba6dbcd91759ff2a8f4cd5907e2fe417ed59e4eeaee13b73a9270722e9796baeabbba05e566e2bbb331ef03f3045d59ed03
-237 1 226 \\xb93d65e43ab2a730fdbb006d43b50fc63f109dbfb726d8962d30411f64d1317b0dfa0042cbb71ba244673ad790ff07a7a00c09e5fed876376c854c32f5083d0f
-238 1 193 \\xc5e8caac48e53e2a73519c639b9c68b9c806c822f1d4aaa0b6915ed5b2eeb501a270b847a0a2178d12a0c00db8a3365db80683d18ca5347141afc654d29a6d01
-239 1 376 \\x0467dc373769eb82983b89dc855991c60aec389da6b38c247bf64bdaf254e54e2d4ff969412b727629f16558090878ccef651bb7467d818f02009fd3b257c600
-240 1 404 \\x73a66e5b3caa8358ac1d9cfbe2785e18a537a8e7439c4b4b4022098aaf3dc9cb21af62e33c670c500b8aa276b91b16d1041856f46d62d0a0ce17b7139855bb05
-241 1 18 \\xc41d09ca5f7195f09f42ef5b0e8b0634679d011799c54df5bd642729e3f2af8a4b0a3dd15d767bd1f5eb4403c150c95ae4d3701f420b850f2cee77ad9469790b
-242 1 91 \\xc695717d15dd8f2186d403a42790a8204330cf997f414164d91a554456b60bb09aacdbf165e13543838ad5d5a1e6948440ced96b0aad97156838044d53a6df0d
-243 1 94 \\xca36a35ada97b119b7877a07eff74dae7ad94eb89e9574d86ade8eb837994f0c4e5fe096c1be19da1746c4e81f498bc11f8ad3013318793c1553b737620e5f00
-244 1 401 \\x285b1c292d9318638384aaefbe925312abcce398fa9beef3faae5014f3bcf4f43221a3af69f82347bcfdc55d67f00c475535728aac092653f6c22490de9e480b
-245 1 92 \\x7cfe306099952361878233f0773935b288c15f9a03893828be28cb8f2f93f2dd33fa15223b68482b3fea6fcf40f49a97d5e9c51e63a5f71f9d7f780e55fe1c0c
-246 1 108 \\x5d6cb52b38908cc1666b3b79dc49af655cd1946f42965b16c3e60354ba6c934d24752e803610c5df078840f9164e2a8273ef1591d7fa97bd6ce408a5da4fc808
-247 1 394 \\xeae0b4c686e005678aa00e37890de8a7d52d40013aa84b444afbbdec77850fedcb9ba33534275c51e59fa028087e2dcfdb9960319425396593d26a3a395cca0d
-248 1 143 \\xa9483963cccc1c5eb902164d56d51878822aa3754730cf472f552ed7a9bb9d7ad98b928c6a3be0f9143fc37d86a9d7a5b3f85c0602ca0f4a02fdb0440824840d
-249 1 55 \\xd87941f3feae46246503b20a4e85b37bb8af5b493e4863cd13848d4f64ee7d8ff1835cf89d4406e8d5ffca497067c67eb027aad6b201606b93cca8fad9628508
-250 1 207 \\x528489ae0eadb2c1054bf51a8dd07d907c098f62cc3b2ee9d28be329595c3b4234997a8ca0d1fdd6d359b855aab215459b739da43a5a419b376926be4c2e2009
-251 1 391 \\x01004df8322a1ae41fd40ca317488c024a9fd491ce5798cb19b9ad7f015ca266483dc9f4155e94ee245d76573eb7adc2244ea3f144111f5467378017831b150f
-252 1 361 \\x6a55fbe7e5616495728942077f256002eec52cc524a4d58df290f2d9f2d40a9ab0c96c91f54d383bd424cf5856733a3edc14f0de302856d490a73c6a98634304
-253 1 312 \\xcbe7cf73e129e7c2fcfa1c33ab4c83f0d6c5f2836be5e842150603aeee902cd10a32a32a6697f77395c7832b54d35da35b067669caea77c0e0eadf979ee62907
-254 1 274 \\x10b99e849f40e3e31c5dd2cdb1795e2819ad754a0a6bc6c531624b154a9f48c3b1267064681249ad910c93fff82da7798cae736422bfeadfde516561b88e3a04
-255 1 416 \\x876b30279032160b29a460eed20b8d45c5a0b649b4f55dbddd1ebdf020e5d87483471fe33d7a8573af138dd3591334c80215555f4944d5be44ad05c3799cff0f
-256 1 384 \\x84bde94e2f074394a886b0f57f4a64e014d80fb68bc8da90379f3f83691b1efaa86837ca2bfcd57d2bdacdc6c1b20dbac3a071057e59e0acc6a8bd8893781007
-257 1 9 \\x0e881cb20fc81b6e549271a8787136bcd0504a3fa571a3af6eff938b15756ee7afca71be2468657c238aa96df0c015e8ec9b93a10e32977f5627fd9cda042000
-258 1 301 \\x099a1ed6e215b095fe4ec8ba72f4257ae61c02b7b0ad709239e44ab5f40cb9077be5010c7893f33568c333f954d3569b92d7caf0f101e0d9395348947f1f3408
-259 1 283 \\xbcce9c1b158e8baa7fd1b769350eb2623426ff6b89e0cd4f2886448dab24e6a3450ffae01a68d4a1d8177ffcc8be294afc6aeac6cc4b2306b61cb4e6d982520a
-260 1 118 \\x6a35eb2e993c6a6d43e5a1cb587f231fbc794012a119366177643b2d1ac5d22853e892b8f75d9f47c6c25de2b182f465b1b99193bdfa52b00ea7e0bb038d100c
-261 1 338 \\x0abda3341094efecef5b9ece8f1a4ee2c0d0c6a577fe940f0a1058127ee286115e11d83784f5575bafa38fb8f42f319ccaca06251387a4cb3999ca713b774a07
-262 1 242 \\xe146db68808771e852860c1730c09007486205139059d88ac7ac55c64ea8634c936a5cd70ab4500fbe54f62489a64e8b9b5893ef829661a0e763fb25de72e707
-263 1 256 \\xa05ce7163c05efe42f584cf99c5f371977d58215f2debf91610fb3a0191b5fbfe3314b885e2ab8cdd67bd4fa130f6daede302564b452a916746a60571aac020e
-264 1 39 \\xe2b1d9b6d2e06a24d086330092fe16006bf5389ce5e19cf72d358b4f7fca20e2a49eb54c8a554180e13e8b1cb4027eec35dbc22ce34ed3d77272a848d7434a0b
-265 1 383 \\x727419377145042dadb7f9db6fcdb31c5661b83f8bc09c310c77be12f568f0a390c63315efcf7bc401f2218c1a0c51d14c4ed49daba2eb8f23722559a95f8c02
-266 1 1 \\x3f5c18205f308f7b00b877d6e0920ad4fb0f78ca5fff12274e49bce4b7e5124690168282d68843cc28cc1a004f8e3d37b43743be9e57eba4d6a4129cd484de06
-267 1 50 \\x792211e5a1107cc7ddfbe7b521155d5cb32867de699d4539201aa7b15e4e83443d190d0eacaa3f01eb621af1fae990db386ac689f7937826cd8918c98e637009
-268 1 347 \\x8229a3fa1c1ef9dc4c6fd7ccd5e9c135a5ec5b88302e48c72be279b1354a98a852f9db1e339c025eeb2631a9ab2c91115b5ef83436516d8ddb2df2989b0a020e
-269 1 73 \\xcd3a13718f390d62e697dcd63d40a58da75062689092ac7105ab564537889350fbe4e31ce6cb92641021cb2f0d7f1d0cce85fe3985ff32041eb7a3d53b5ebe0f
-270 1 189 \\xcae82c11e720c5183b436232c006871a8c119e48a92bf34f135770fdef5531dc704fa3e01fe0bf6a4c5acbfa373c058bd743d8fac0be97d71d01e787f369dd0e
-271 1 418 \\xd792afd515b9a4fd058b747ea325f30d80eba6236c6415e4fc6d880020ed6204b6961a0414ced015ffa8dfa4705b566f36476d0cad2cc0fa5e2227b09027d101
-272 1 60 \\xd3ae051c19969d41a959db3d5b54b2eee098bce0baef0c6a0521bf6cfe053907b39b29375e267e8475a1cc615de82199ce2041fd27ae362fbed2e90188f93a05
-273 1 241 \\xd4b67b07a9aa6adf8d420bf0f58bd125ac6423b96e59d754e48912be3f17c64760c3d11c6e70a9ba89b073aa8db331dcfc4d0244bb471cec45974c59a1825f01
-274 1 303 \\x7dc57ddc06c7cf73e9dab639458e0acec0805d1b83f91bd7919fedf491161a4c47b65e5b20c96bc1854c2fa5ad1a37d68cd471c88b32d69a19095574ce096f0b
-275 1 127 \\x097155ef693033eac864fe33d68a6bb5cdcf02ac606e8b81dafd8e2467ca3a92166d4e8de7beceb03d2d77aaaaec9a1f9eb1604d08cc5acf680999a707edfa0d
-276 1 165 \\xd152f5c0a3d0d28e3df561b9866848dd506245ed70b462021ef4a2b915d7f2da21b03894b235680721521f547966b5a58997faba35a89974989fc1697dc1fd00
-277 1 254 \\xe74a88a60c5a639b862956a485c5aa203872627138f34e95bf4aa7ed0ca489191290775809e853120cfe20928e4bbb39c0b50b22808a498031d6685fca0d3708
-278 1 188 \\x756efa53c2ac07781c487690a2c35da425b845e44dabde253e5df281b966dedcb6aed9be79169153cf5a0c5d3861bfa1b8b972e320bb110e2def2b1b5c94bd00
-279 1 36 \\x34f0bfa73be6e7af4b82fab52136fd1eb98aa883f1e53ac10e7262f35671a0c6eb1abf667fc1852a1f6eae9c5d11a099a278638ceb6b334a6f14d21a55f74d05
-280 1 325 \\x3d793e9119f4cba85e2d6a5a64ef304105c702ac46d15d9de9b981fbf8ae17a588fe4a213f5b2870f2b4dc7dfc41d8e81b6920bb02eb1d7cf40814de26852105
-281 1 2 \\x8839fa5b128c17023fa3feaa60d60fea0196b97c7c8e50fca4d132dcfe7104026d58a24d538ffaae867942c0e3689caa6d9253b09ee6a8ff738874f30c3b8f0e
-282 1 141 \\xee0c7999133df00e766ee17cfa7d125c90dfc442bbe7db8ad497b5b38cd0644ab14492bf71cf4509f124af5e5e902a90c560117bd4520a301876beb67444b501
-283 1 237 \\x3d0cd128eaac6daf4f67c82caf96f3676d534e6b0aa1db2b6e373809fade86aa565cb58afd5d2602cbcbab62f9e4327bc50c4d6b05f54ed36631ffbbf52c7600
-284 1 315 \\x62e7d3d10cbd51713a2c3724b5ef8b2effd96f36c4bbf5485734b11630bfd77e4343da94006fba785125891cfdd0471ad17c696dc58f6f478e998a76bf29f909
-285 1 345 \\xb20df19ba45be73d6b63f32521449d1f3959f8981ab6c4662b0e9a39c8d8be075030e436bf9d099d6d63f504fb8bbfa921bc5beb8f7105874f9ee26bb60aaa08
-286 1 330 \\x25be0a1b2db06bad3bf2f019e04e6331d38f8a399a81a708e70d80390ea3e45cee516810164c04cba1718c100735f05384ed8dbd617cb4812a2626abe67f2107
-287 1 85 \\xdd8bae45cb1ef8a34b1c12a1ed12c8fdbf1b0b2edfad5e0a1b89119f699caa631208958823126db733de7160e3078ab30e2c24a33194537c6a0f7c6a239d450d
-288 1 373 \\x0adedb9ca7e36b453d6a109885e9999e21a3bacdb9655bfd47453590c4209a5fe7f8f5b36f89a90646a4dc7802847b543834fd7a1517444bac99e685468a6d04
-289 1 142 \\xf0c2427ef75927401cd3425a21a332a7b42ed68c6ef6ed7cf3f4a71dc2f7fbbca29a96d066662b66464442a2b811a101363b2c9f38a78149b2e24bbed63f0d06
-290 1 162 \\xdc9fb850a137da530cd74751cf2868bbedaed64fcc4f6973c64335096cb0b7635d28282d9784a317b3cb840ed748b7d9b16f4b83d94402169694a8c71243d40a
-291 1 297 \\x853eae3816562a7593467c01851cd1279f18448deae112843df2826702212fe129f2421bd1ba1ba797d90ebc07d75b3c8c11f0a61f80fb01903e54e9dc7b9300
-292 1 321 \\x1bcd3724a8eac9f395f692c0488b68b39da988182be312a26bd09851e6b99685606cfbfd4ceae0de22fa6b2fdd349cad107b603e7ceec13ef8fca19990b91905
-293 1 105 \\x7778434b982546ecc7345458112f914120dde39d0efcbe06778835dcd1ece86542c7bd54a5ac7ccf5782b47b8692369e2418a46d380996e39e63b34c63a2ae0a
-294 1 257 \\xb70a74a947c1722f47a6d5b65b9dfa1a06063c188ea6fa45ecd5773300a6ee015958c035b379539cfeba179299cc770cf3307bcb5591b43730c6a4797991a607
-295 1 27 \\x78cf4da07339c3badbc32575f433b0fad71f55e1c1063e706b152c4a724bde541f7b4abeb6c177d252f6fdedaebbbca12896a9637cf9b1479797d45a041f2d07
-296 1 214 \\xec548853a172d389230c1042b3975368f5a434bc2700ec6b7613d13450b61b1e0d6e5845098632cd76ca6052b47d125981cb2ae6861f16ba141ae89b4bc8070d
-297 1 350 \\x760053901d290075aaa23f90c73d14b40319da51f6cb02d3196112915c23e6183b5833bd5959067d2a245777e5d3ecd3c07e96b1b5e595db74284213febb8d0a
-298 1 372 \\xf5e489fd301581e2149f4154c584925f12051a14bcebce596c4bb9814f7116c04fb61e8ef83ba54013965970460f66e0081943244f4f6963c59b25d299f67d0c
-299 1 75 \\x9b0698edc0e9d6a967a609db25ff4e0fd0642ffa2f969cf3ce149e6e123c5e6d2e81e100016cee54deaff6e3a768b36f995cb484fd6f969b4bf1af159192ff0b
-300 1 201 \\x8d8cc027de9d6b90865045ba09a0cec5777b81f897a0381263201b8dbdab65872dffd0522a1310cd9db494ba2795ce936f5b780f99869d30b1b3853ed8fee10f
-301 1 68 \\x0b5ed1077c09c8fbd5d682955edbe250d68b3e2f1852d0c712881732737919670165239852306c4a2c0701d0fc9865c4242816ecb9dd72c52c688f5d1269ed08
-302 1 354 \\xc3fca7a38a0997a32c0aabb7b1483e431f72a07c9783a08799577c1469fe13d448ceeec0ebfe56c1f3ed513c4079f696c6ed2bf2208e0e30c64c866aebea4b0c
-303 1 26 \\x90279d6bfb649c0401603d4bc743dfa768207760a81301eae6f72050d9298633b74f8fbb16e2708765e50c9e121d6e731a9887a3ab0a72e10153b2e0dfb4bb06
-304 1 335 \\xfbcb785cbad3f00408ed11410be4c12f73690e00eb54ad3181228c8be415cd67eda90722d6c0a939a89dd7fb8e7a95d0e8b08af5d1725f2aa22211f343454504
-305 1 290 \\xa91074b8bf0cf0cc9bc9316904b867d0c887da4572eb8a0684160901e840b909b3da2c420e7aec8977943a74872e4843a14e56ac9cc0cc187c3631117aa4f505
-306 1 410 \\x8bf6b9b8ddf476657f037f647e423b1850b388af550fa0e42539449e145c39264356cc8965f7fdee9bda929bcdadcbcea162d4248fe83f8ff6ad106cd7d6480e
-307 1 313 \\x798bbac7d6975d14b1891fd2b96782192ebefcbdc08f6a698d90e18a7aed54cedd00434972fd50fb85dbeaec2809f23b2dd7bf1473d20143fa19e9124341680e
-308 1 389 \\x45df91ad75ae1b13c34c592150dde5d336803144ada5a8046b25fa691f10a801b79b18aa48ad7b2c449b5b4e82293d7bb913268ac765926e2341e5cdd329f209
-309 1 323 \\x43e002e8d19b0a86421d86c2b8bd4d234bb2895a8f5bdeeed8b517b40179ba97c2ef24670e53a53be33098ced5fc0b46f79342b62520c54bd472cb6ed8f37e0f
-310 1 44 \\xd06d205bbe11a8bcea027f18677b707524e0d16c8138f02cf0b6712525dd56218c38d78508e10a1c5c34dbada42957f76d3a4b487d43b216e6ddceabfc98db0b
-311 1 210 \\x52d860e24496938c6c032f3efd582b70ea779eb905f6a77e82662095ee78ed8a06cbbdeb2455b1a284212795a9489642502754c297849c3b53f6c799d4caaa0d
-312 1 153 \\xa0c138245bfa88c34334bee4d972d1ffc10bb6b5d9c668a348b6b696eb0d13677ffa1f080c4b186fe10bdb2aa38d4c582ce88c3c76c5851aa2a83719a5e4c80b
-313 1 133 \\x6b8f8ecee21339e5ad25247a1ef9947a71934a38c0d226e69c483cc43b5d7fc5f11f9fea39a086749b1484e85c1f2fcefbbde2b57312c405fce01eb154628f07
-314 1 106 \\x14c554841cd0c36d9e3e2c62f35d2924e588293a70757ec560751f7b83c64eea684f13f4e54dfb1d82a306f81c1aa72df175eff8527cc9e892580d3b0c4c890d
-315 1 261 \\x84d9137cbb0a38d76a3b20ca9673596b6f17239924dacbe0987514c64fb2b21d0f0fa7b61fd5ff07f9a6a67c30361bbfbb7932b923bf3bf91f71905833458609
-316 1 34 \\x08eeb0b6cb89b9dfac4b305451890307372e18f7b706fcd7ac5136729092945286dda886cfc45f3e0d86b52c71d06e228aeb8f44752c37b9805fe49160c89d08
-317 1 328 \\x49277e12b0c968c05c17cf717cb005cbdf9d1c50bf198ae5598805b96a9a8b1e793a799af93a03cb4c3d294d39cee9dd8b9e9869e134b62d81bb877d334fb304
-318 1 211 \\xbfb681817f9e2014db5b23ca61fb69aa634b0f65fc734618c359eb464ebabdb6907e2d71e651e199e8641b782a9e099cd5e25604e0f5679e6585360d3ab6b001
-319 1 77 \\xfe43e99a1d83098e740fb99d4a0105fff155c00ee68546a2ff78c0230433c60671c95f416f37e133eaf59a71b004206dc69682d5c7907798d57320b041a3c80d
-320 1 412 \\x9a36b752bad7f39ddc855282080ba61a9c1a92a9026c22af39484ec5c3d477fc6916c49a92f7cab14e2bbe63714830ad7d85cb957bd97046278eec4be9c97901
-321 1 307 \\xae34b47703ce3ca807830b82725128612a5b090b288d75e1aa6ccad6886783b30bac261301682006f8a99e59d9d579fc35dbf62b53b911c7a302b5ed1113fc00
-322 1 187 \\xf00f49fed6fda79da30be4bcf4698ef1634c5bf088ee05bd8f5ce167d04042bc716c1fa6fd5bb39de132a7aa9e71359a7682f4f6a9baddd7fa6a2ad4b2a13000
-323 1 422 \\xf30036ff32b0d9dd163d3500362175951801bbcd62832d54332ee9382fbf9a59112839c009d21d017e4f343d82ed80046109c61cecd99496a994e437d0803a07
-324 1 255 \\x5ce60615f78ae4b9e4a294d216e3c56339a837498466b3f49e018fcba04760e1864970442fbce15a95d13741d5f6231e710160e5742ea65edeea86284d6c190f
-325 1 417 \\x792892ba802f2684dc9009703956d3508af0ad8f5b70cf80a96764b2b00a9c3ffdf2d4c31b586655639551923caa39454e6942847d1ce5a95516657debd9e403
-326 1 8 \\xe14a58e2b507dc2b2f7d49476898da22ed8d3d22fc393e90274269dab3ce6052a38e55eb9019c24fa6510d56ab5c22e7e663476d32744136269399fce7292105
-327 1 370 \\x75211a612811d0fc3ac7ce88745e0c6fc2f2652ccd1e8996cfda8de716b6fc654c640d0ab267f70c001278acf214a01992aed7f59e3349bb8434fc7da840a109
-328 1 63 \\xea91966b20925393be3766b2ce70d34bef6353b3cc08ae54c9a9df1d4d5ac8a9456aaa970f73bf7f32cfde86e66bffeda5bba78bae63712b0f75974b8e569200
-329 1 194 \\xa3fc13c79bf2cfb2028456666fbc7d2e41030ee4b266d24ab9bb7ba4e7a56d25045695c0dd98c8855d53100c0ff9a64e0a3b5c55ccab56d351242415b8530107
-330 1 6 \\x84ed6299ee4827f749c5cf0705619bd8a634ad3dddc181389ca57a6f3b8850a0ffd3ad5ea6deacb9d9f01c90ffd2be237e81b9a3449e107d69a4fa9b04034e04
-331 1 125 \\xbc1bf4c23e94214cb6cf9e25246a79b4aa0076758fcd1c87625f52dc4e6999800be3187d1d245513f0934411c83e9b193bf325db3e8a5a1fd4aa8bea84553806
-332 1 87 \\x75db2b0ad46e01ea81d963ad63dba6152b1a93a8579d5477720a3b083931e4a02ca61d65ce3c4b82019a12e0003a71cb6413dc0b0f86e205a0518bec899ec108
-333 1 379 \\x4b8d3d2c50d1a561a10a3593d522287ca0e72e16f90e61e64205d731c7fb7845fbd24547a9bdf87cf3133a1807186f2aad7271ea833e035dbab2eec4da74140c
-334 1 308 \\x8f70e49859fd8a516f4b388e621eda12384cd494a77108aff447aad08aa213359febd2d309ac648a2ac41876e1f6d23a818b195a1179a781d1901ec5d40a6001
-335 1 424 \\x54a056307d28b998a0ed3340f5092027c001c31a79117b8613ff89e3656a55c9d084012558b10f596b973d81879a87c2c4c93b90a1b96d65736ed4f6de323202
-336 1 382 \\xcba8ac160f695fedd8736fded816de642abccff4f5427f78f5111a04e1db631f6efddca4a85819ff4b6ea0bfa853a44921cb6c3a568051f971556bb36d9c440d
-337 1 117 \\xbb70d4c97499794ecc251b4fd59159e0f0357c02d2169ecfbf4facff9b998ce98c7ba3b0e658938cf13d82b0c292576361dfa4360ab4601dcaa1448c728db50f
-338 1 181 \\xb8934b96c3442c9b9c64a2bb04fbd285bdfb86f28b88562b5beb685bc55450064328d35111b4cb3606c8e61c7e419e3bcfeadf178c793295c9b94960dceaae09
-339 1 319 \\x44f9f9c68e893d4934436d6372e18a3a7b3672edc9ad93db1f340423bf8892493697ece71e5c2881cc2babf6a4ba7366553668310b44742129cf6aba3c9b320e
-340 1 227 \\xecee394ab88e496287f6b293fde9eed964a7251f5324043b91af6ff7a152e0c971bccc60b3deba3c06f9993541e01ded2fe06b027b347543daaf538253f66800
-341 1 218 \\xae0bcbf1b126a760465bf112ce7bd73274366a7da7b64d3e0d7bc8587989b5f8ed6ecabac15f0a8460fae9b09173d811249f81c37c96ffe99dbb39bcc470e103
-342 1 334 \\xa9ff39bc95e6eeef6153060441101ea113bdd87fdd1a54f5f9cb2f195243743e42f25edf7f6d89c308f40b281659e7549f692916e95016d2f5f30fedd5afb604
-343 1 408 \\x99493bdaa59d918abe36b20052bcbd14875a8a09a96939717f201d695648148e243984cd31127acd330fd46b4eca6ae36c2d6b676d5ea810aec77c7e73864c04
-344 1 271 \\xa14d7addf3909aa8a34f967809945000ecd7860a49d5708e4b154cf39305e1e8bbf583f326827078203ed7f9471b0f8a380040f2d0529fecbaef6cd45a8fb205
-345 1 35 \\x9f9f3992b48d9d835075a7d54a6289119b4ffb0c37560111eaefe19854af2f44c6e7cb6cb661332470da9caab056cc417503b674c743181afe99851f2f7f7102
-346 1 42 \\x4e12febc103afc2c2c9f380453e1630cc2d975d36099a5e19b9efee496104f6241e43ca484fc7bfe54b1b9cd951265515a7387a5b683c4fb74e594ad2e254a08
-347 1 341 \\x71c75dc50e4f865fb6374234ddc49b577892ba546193050f24fe7507e405b2a5e98f0a0d2e78def0af9054b81d25059819f3b7ecc81a8755f3d536181f5b7503
-348 1 304 \\x3cd653ea9b6575eb3e288b87715c049026c2f863a6d3015a23af14213d5ac7f80b909ba03d0525fd0516e57bf0fcf6d878df6036128e6ac6801ba595ad61cf08
-349 1 191 \\x65a31048110b8a2022500468d15ee2e3a1896ca388c6cf9feebc55eb7f4153ecda305a82e47ae0d450cfbd2620b0409ad981f0a8948e7a09964272ae94c99107
-350 1 406 \\x25d463163900982cbbefeea1f162637df406fe556f9687a6f0c1a2dad68b4756f81ee12c3f46ce0eb9f781ac0658905469ff276af9b27b4577854bb5f9239f0a
-351 1 396 \\xe43492200de7c6a1158332a38d4832bdf19796513a89523983026a1c928b34219ab9d7b2f0e9eef59f6e10b2b8608b62a474b8e34a706216434a46ee3b040e0b
-352 1 183 \\xac151a1f17e0bd37061ca2405b86dbb28636d15f28cb5abdac549f92ad5835f9a63ae68e54aa3878f1ccf56e8e4a7176f24fac84d5b9fca3358b635572b4b201
-353 1 182 \\xa3dd60939b5e5e74706c1a8035ddf2b3e6862dbb8aad794bc9203b2406bee198fb4e90699ad6a2769ea2fcc7121386e8ff391cfd6a848a546f8bc71c9e932100
-354 1 82 \\x922a445393c815d5f51daf23f970720a191baa717ebb8c10891631fd9c0c9ec95a1922b714f01055171aec9a85b14a7d08a346c4a9e6ced27d77f917fc7cc804
-355 1 221 \\xd28effdfefcdfb1290dabaa268af4258d1c419f7c56736a5870a4e2fe3e3b71aac205c1aa76558a5617b4951d6767de26e1bfa266456a54839a2c856535b5f0f
-356 1 219 \\x593011412b5b9f46d519ceff14900678989f8c1c01b3dc5d50a8cb0b1e454b6b25934423d708b7cf0f619957138c8e40417c6b03be1796a431e66ea29a97d400
-357 1 3 \\x7bf32e22d110da1d7cd2ac77798d2cfc005bd3a53c8ac8376c147f3ad5a095a1c68a30dcf5fcd57354aa0c132aab15579a935ab252efbeb3495ec6ad73fdfb07
-358 1 215 \\x39345b1c7b0542223ccde877c7874ed5feba02a5b596142c753878bf32b7800d4a232a8faa20c50a81209e3e47736af932a216014d611db2ae1de1258f560a06
-359 1 56 \\x334c5f0a37733da2488273b05747396615adec3225cb80968f577fd8961814654514408249297138e283157457429a8b417038b68b2f086d7079561a04960b04
-360 1 359 \\xa283dcb7bfac3644805961812769173ecc3d9aae7844c02f4d516016ce0395f7b5568e2744ef777baec9336dc017e28c4015c339a56394f26d8f442fa9e99e00
-361 1 252 \\x0f9adbd9aae500a0ff8ed1d4efcba6e18b325b87ef0fc9b6a57d2aebf9b47f0f09f59ba7f022cc2de20a6f1cf51a04a1299c56600e83cdd6868abbcf891acf06
-362 1 300 \\x4659cfa80a0a62e5c58fc62ff01101ff2985f45adaea036d2366556fac84fe5439b9e1124e3c83430484d075159074bac3a39b4633d7ccb3764fa16f29df2b07
-363 1 358 \\x08b391fcf24b1337dd47b372c145b041327ee40da06442ac0037a69e0d959cf0c18ce05836dcbe8d05202de8a5784d7413ad3f2c53e28ef178c87fab38a5610e
-364 1 409 \\x2e9ece322980a23f01121a3e7d031df81f57639c7cd91bc2ed1db2bb151a492279147f881adb8f82c982d1734341d1ab67aa29d91c54f02ae66c802382ae5109
-365 1 202 \\xc3f8fc853e1ff84315b2393dc491c46c686c41eb348bd81498835bacb6cd5f6c96473798a5b6cb8b26d292e3f812b23f311b320bb82bf3e449c787bc77af520f
-366 1 348 \\x9ca1829f5d24fa205daa14a73c10190655c3a5db150773cdfa06aa717bfb3d1c40b5e9eba3a08b9b4e3680440c1f1eb227479c350e65e0ab145b168ab73afb04
-367 1 180 \\x2ed20cb8380b9cd49af3bc6854b6d4410879a356b447bb0595f894fcb3f3d4c028604c7b0195077d46f9ff7dcb0b26e69dafb80f58c190c41598d0991c74db0e
-368 1 21 \\x8dc8243ee995c0af92ca4c38579e7bc9ca5eaa5525300bd029e6aa774bd6f2e62c17a534d92ffd02e03520f7c74ff57178b6e07f64157dbce10f1eaf1e505302
-369 1 222 \\x20f2365bd2136d1712aef7e726c0a080e9bc96528e88a2508ce19f08fae2ec78a33a143e6963ef3241764de77c6c184c40b2d3742b8ca59daf04030b9e9cd606
-370 1 332 \\x8ac3e2ea66b483901404c1be554661ad6f0be79766097c9a58273a15024d3618bf7336f9fdd282c835b28466e3d5f3018d6c025a5cea3827666a995147cc5208
-371 1 79 \\xd82c89f9af962e9c29b7f52ef861dfcb1413c46d970a75087b698d5663ebc3344beb0a652b2c421978d05959c2095d4dadf71b93bd904c0e2b12339409c58507
-372 1 88 \\xbd5916b9f43946f387ffc9bb4bfd8ddfbedfefe15545db6f98eeb29706ba99935a8a8c6c708593ee143c404d2679f80a04509e82fbf2d2cea0abdb5b30085609
-373 1 7 \\xdc23355ca42eb90bc74591613262f15cf58f45219c1e556379593756769bd43ad78540546f570ef94f12b6b77986f72bb378288909d5ac4caf97bc9802420904
-374 1 405 \\xbdd0fb261a434dcddcb967851079787c1f15b05893ed9f2e31c564788953492bfaa678b8fa38f247c4653f4ff6e1d195d7d2b802179621d4ee08eca8a144960a
-375 1 386 \\xc3f8b9910444cc8d6f3225d68c33db069934bed04588c9f857186418efe50352d54207eefc3edc8f20c11c8ab2378d2da8e14e7d5bf3c8da73589f1414096809
-376 1 99 \\x2048ba15a918b434ab407c7f5ba690cdccc5a550c68e4caccf650f2454e7f405a7d043a7c8c1d9f42586058ba4424f63423ba63b5aab478fcac459ff0a335c04
-377 1 59 \\x872a91865bd0ee7cdcbffe9e912901cbeebb0712c9a7cb78b8f0b8ac4dd896939413e365f9f47a2fc28d7b576f18bafb508e8511ee35713497ea1bbc28d38f07
-378 1 411 \\xf69b775d3079aaba6a2310365a0383a131747133bda395ca071922547f8efff8fd8a6491d970bd99b4653cfb3bf422e755a024abdf93e305d5afe252b3af3904
-379 1 78 \\x9714f3ed8aa3a5c0e4dce4b2f3f39919f0e1f45908eadc0a3ed582404e0473d49380ea8c59e17d12771d82c83f6c3b26d5c12b7b5dec82a7ef9eae75d6a2760b
-380 1 309 \\xe3cc41e11e71910c671d8ca4eff9ded5e522e7e6fdb76021536de1b1b25535d1cdb980fd980327bc69b2dc600199177ffdc821e62c6d3c8a381eb05798773d03
-381 1 260 \\xf18f6b12dca5f39a0e9cdaa6375f4402822c239a31d70bfb85ed265efcd209fe49c592eaf8b179e16f61b853653df1026145e7c16062083b6be75f63a76c750b
-382 1 291 \\xb2994a9bd16f25af89fa454768af6e4f5489a28a62fda75d4d8d9989a8607a88fbdeee33c87fce28464a7a59a4defae2958723d2b03178dc97182aac54399700
-383 1 107 \\xdbe7496d9dc1032d296230ad3aaa69f3e490c9cea69527edaf3c38559566c05adffb92723f1b2640e07d93ad613071f21883365aa2d30855640881f6f88b8a02
-384 1 216 \\xd36e4a5eb2dbef27027468845917be310189b07e5f6fcbc0a4e087d8a3585978dbc500662f4904cfe152ff0c162e3d08e7a70bc0b8fa0d81afd09ccbf06c4e04
-385 1 43 \\x60b55e1780ded89a366c52ca58aa54adb644faf0178663c045b52000cec083fec94ccc20ec06299b4826b82ab79001cb7b5f391ef3c12266bbb9e33540650d01
-386 1 316 \\xc20f4c4d52173cbf700c843ec3e27f64987e0cda287b566585eebb22908f4d1321d33ed9fb05f227af2293e2faeaf14a5594a247718632e4957c84a90a091c0f
-387 1 223 \\x98bb9f57155280cc46d61554c7645330a33c844a6741e35d75d9840cb0c354c8b3c044302c5c1c1c784c936853f9e638d433ba5edb2dcabf3859a603c22b0c08
-388 1 387 \\x1f9cd388884e23c2c1e030cae221c3a3819bbac50f988a57dfc96f856fe7f0b5af3f4c42660c88561ee3351190c9330c77ebb8dc77af0c5dfa77551d9cdd8209
-389 1 58 \\xd47ddb8cb0ae4903e0a2f4b2132240600f303af3830e5dafc9d678817caa045608a7ea482b69505419c89724b545ad25c582d19934de8d4c630650a67de9df09
-390 1 289 \\x5e854160ef2c19eef036de7c75acd80d75fbdf5e4ee51c58e1f315f259ae0f9b03bb392700db24a29baad41f19a89d9b115bcc359b91352dc764f1b5ccd4e008
-391 1 49 \\x659e2e78710fe26c028e3f8df6ca8ee73e2393838cf1abb7f9c4eb8737549b7806f716af74b93154635875f262e2fc959a3dfb99cdb1fcdc1f5c6289cd8a2603
-392 1 15 \\xee6fd7770a17a9f7cea153557839aed9d0cf97844570ad003e2a32112c4d893c3bd13be9fc0f5bce09450c83086305eebf58b800726b640448634d5c2839f00d
-393 1 119 \\x03c14f4e907d150a7329761da3c181ca1acf8aaa8043a97e3c6e12e590137cb29af811124353c8c2fd9cf79067f6549833c4f0f46c25111169412616b439c404
-394 1 120 \\x53258acd2c1fadbd7a40c83de108bce5ec5488fd7927146a44ff13ad007ec350f569f7d6928b17436658cdf54ebcc6a9864c77c27afd1cfa4816f44992557e06
-395 1 397 \\xc325d5e31d2c02386c398dc84929b89b6f3fcdaffa468c5c8cff48e6b42a1249baa7097e142ef010d836a2c24e158a3e5e803eb5ef57392a7723ade051810902
-396 1 20 \\x3b100474903711f1e7ecd8d46848b698f2f2fe67c6ff653e3d63314b5c2c683f7b69ad1dfbbb27aae1253f2b19bb0dee0ec97951c17c5aac0c97fee775d8de0f
-397 1 169 \\x196596a4cccba5337f9410e0b9c8409b5b4fd3dde645c7fa7fe5d89f735843d211db907de9eecdd77325d063bff0e024a76bef3bf1aaa52b11549a4b968eb10a
-398 1 83 \\x515da605baa3c569076fdaf89c9bcf1d37869b7085c7e065723d7cec997f8e5534a541a82ff3adbf451d6b2dc3c90ea1706058dd6064b236f6b0f9233a702f08
-399 1 146 \\x5398b2988ace36a540fb9b54cf8b0686e15fe21357a75a5175106664f53d7a1a34e9f602855459219820d92f82f9e26b694714004cb4e2d9ed7fd94188e3b809
-400 1 4 \\x7967a96d51b64974a1f186a8d681d7165baae4bf98de8fec329d50d514c4dc40527c1e6a8191d9c5dc466e548c50b5012fcee2380845258e27595df2b213e806
-401 1 385 \\xb054314bb68902b0ff49c1c24c116be177a6481a039ee3ba53c245f008c81d84e3136fdd9963b804f82434db2cee049c32e5d566307c64ea00968a149de4d90a
-402 1 31 \\x3f090ddd00da4f09373091382980b7cf3475df51b98054bc0af8b70ffe15f30aa4ba43a803d8d6a94591c78a781fa5912191647eda6ae8763a0743a1acdc2402
-403 1 32 \\xc26d9163f6f6df8f0b690b1e9a6f60f97cc8593ed0bd25cac343ec9d8e8a64eabb0046ec7fe27ff93920a4c9fe052676133a0385ee3dad46ae5dfd6c9a51dc04
-404 1 292 \\x950dc2b770b8f6d4b9c3dd7c4423668b2e12b87835932dd4ce4438bb71c5641fc5f549d3c77f83f0b266dc5de506a58e4a73216b6ec96f5c35685e203a417c00
-405 1 318 \\xb91e86b5b6fe1cfa64b4ced85512dcd38ea932d5f4123123d171fb5c7b4d85e5721490eda95e4e0ce007a6155278fd719c7a1ae5b69f2491faa29cb973ddd30c
-406 1 84 \\x6949cc06445d9c8338f8db58e228a71d46d04953fc28974305b5a903681c5dc087d9ed07fbd401411fb49064d7fd7cbaa809159159e9078e4d8b04cd1806c703
-407 1 113 \\xd73b11a297dff4ba8719a810abfd89ff1a7b54e0001daf8ee2a830d7df2cb3305fcb587c03deca6e4f1cfe94d051ee6343dc975295516c49fc5fab147ac93406
-408 1 137 \\x9aa181b071a5afeab66ce1a4813b87c298103cfdc8950d4b5bd174bc191bc7ab159a59a953dd0a375015bf66cafac7a2bf4c86d98b59b6b080a8f0297318cd00
-409 1 415 \\x4c5441303fa07a10ff04174eb032142255b408312a8e25cd1e32354ec448effd4a762a5f0853e7ea2e6783149a2a136b2defd087ca905ba8965523d620615401
-410 1 10 \\xb0c432f2d6e10d0e48bfd2e61fb40d586abcbef3775aab047ad8e3af6c8ad56c057187e4c5cff9106c31ef92e4bd90231a2b6a71c1122c007ce955b680349201
-411 1 366 \\x51f01e5572680c84ba223386cd8519ebb1334b85f5086c90c56b2beb5a2caac24191589c96a892334010766f6cd213d28989fa9373c50b7aeab6776be6bae60f
-412 1 14 \\x0d7941dcbfbeb0d10722512b28fd19f28af9c1de63cc2d79bbb9e8f77796e40f104fe251649b736fe0e4dad8e3b280d08c59e5abf31b3b6bda5041cf45769e03
-413 1 306 \\x1d818037a21e4e7026c7bb1e242489d2224774cd3150e980a5f216de35ec6d521fef94853bab8690a4a637a79950a620d95cdd3ab00a3d843ada76d0bb06ec08
-414 1 89 \\x8e8f82f5ce0492d7f47166fd37876c7928364749465b6917b75e2d277c71e08b7f44f63aa984f335e1c68d69b571dca8148fc77199a0298b40b755a153b19f0b
-415 1 346 \\x2aab1421bf380edca31f8d31e3080457215a4f5f50c063de24becaf3abf75cca3b52032cb23dec52f7f77e0930d04932c916f8df7a3d68cd5bcba0e55c6ffd09
-416 1 403 \\x438d9b414d72a5793fc11c9dcbf5204a3e325bc0e6a5022b78ca962204ba8a6bf72246adde142ea95489e01f73fd14492f3ee73d964c701813d750febdca2f05
-417 1 248 \\xbe2e624240207795fb63a63e31a04aad75e8df35243d03998d57eb9bcb23ac81eaa577cab71af5a1182e972b831e692e74a1b1ea62f9c376a5add9efdb5c350f
-418 1 208 \\x62adfafff2c8afe4eaf8d83cc8de0c169a1aabe6422a104064078fe46bdadeb3d0726b4b6324e93d0d36bfd8e41db548333633fe4921d14022a00675a0e32201
-419 1 423 \\x33cbea90a1cc345f4b1598e96b07dcf15049e016817d445ed1ee26142b4f7f797f8b0b8f788c827faf58c0b127b562ef8e549c3abd82616fbf09e7d24712700d
-420 1 374 \\x8571ce63dd839ed50c5a609cf04eed6b878d41a80b886f342fadc19415d60ab25166d76b85be3b6f52cf172fc8ae67ee103f4404a0cfd3abef6e4ee123e87906
-421 1 11 \\x21daf4a716ea3eb3d720a54d2d27deff95cb721b9d9816a77286be812fb0fe4edd7e56a71ad1f82cb6c0c8216b6805acc5fe3eca2444f9e1fbf5f085cf76e300
-422 1 48 \\x1bd62f3dfd1531c0b24c251554d9470f0b0d23a60836f1a59c8c10fef58c1edabc17187b6713fd578c02fa0c892d1542f922a91d8ec8098b4e05c1b2a34c6d08
-423 1 178 \\x05de6072205b2c8c099ead9b12ce0582c9a3536ab21f164d92ece1bf0d2afae20b7abc675ae93e3475b6c18c0851bd3015532882f41f18b3fde9663302f38207
-424 1 276 \\x58e6f8c747769d2737cacd9545cec884f8810614d32f81927a31735721776903517df464e042954ed60120a1a9134395866eda6bcd279537f16af8d24bff180d
-\.
-
-
---
--- Data for Name: auditor_denomination_pending; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_denomination_pending (denom_pub_hash, denom_balance_val, denom_balance_frac, denom_loss_val, denom_loss_frac, num_issued, denom_risk_val, denom_risk_frac, recoup_loss_val, recoup_loss_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_exchange_signkeys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_exchange_signkeys (master_pub, ep_start, ep_expire, ep_end, exchange_pub, master_sig) FROM stdin;
-\\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e 1655640367000000 1662897967000000 1665317167000000 \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d \\xf94cdd1c684c1e6a736bb5c5aaec3d5c4f60310ce02f2702e35de62f9297a9d623bc474fb42bf174eba9a0938594151bd7cbc5bfc4b70987a2dcdd8cb0c29a08
-\.
-
-
---
--- Data for Name: auditor_exchanges; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_exchanges (master_pub, exchange_url) FROM stdin;
-\\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e http://localhost:8081/
-\.
-
-
---
--- Data for Name: auditor_historic_denomination_revenue; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_historic_denomination_revenue (master_pub, denom_pub_hash, revenue_timestamp, revenue_balance_val, revenue_balance_frac, loss_balance_val, loss_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_historic_reserve_summary; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_historic_reserve_summary (master_pub, start_date, end_date, reserve_profits_val, reserve_profits_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_predicted_result; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_predicted_result (master_pub, balance_val, balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_aggregation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_aggregation (master_pub, last_wire_out_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_coin; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_coin (master_pub, last_withdraw_serial_id, last_deposit_serial_id, last_melt_serial_id, last_refund_serial_id, last_recoup_serial_id, last_recoup_refresh_serial_id, last_purse_deposits_serial_id, last_purse_refunds_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_deposit_confirmation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_deposit_confirmation (master_pub, last_deposit_confirmation_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_reserve; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_reserve (master_pub, last_reserve_in_serial_id, last_reserve_out_serial_id, last_reserve_recoup_serial_id, last_reserve_close_serial_id, last_purse_merges_serial_id, last_purse_deposits_serial_id, last_account_merges_serial_id, last_history_requests_serial_id, last_close_requests_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_reserve_balance; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_reserve_balance (master_pub, reserve_balance_val, reserve_balance_frac, withdraw_fee_balance_val, withdraw_fee_balance_frac, purse_fee_balance_val, purse_fee_balance_frac, history_fee_balance_val, history_fee_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_reserves; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_reserves (reserve_pub, master_pub, reserve_balance_val, reserve_balance_frac, withdraw_fee_balance_val, withdraw_fee_balance_frac, expiration_date, auditor_reserves_rowid, origin_account) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_wire_fee_balance; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_wire_fee_balance (master_pub, wire_fee_balance_val, wire_fee_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditors; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditors (auditor_uuid, auditor_pub, auditor_name, auditor_url, is_active, last_change) FROM stdin;
-1 \\x38eb29aec4a464f408e49a10f271fc9d7d49a346a6b2e3463ec9b8c00629f44f TESTKUDOS Auditor http://localhost:8083/ t 1655640374000000
-\.
-
-
---
--- Data for Name: auth_group; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_group (id, name) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_group_permissions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_group_permissions (id, group_id, permission_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_permission; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_permission (id, name, content_type_id, codename) FROM stdin;
-1 Can add permission 1 add_permission
-2 Can change permission 1 change_permission
-3 Can delete permission 1 delete_permission
-4 Can view permission 1 view_permission
-5 Can add group 2 add_group
-6 Can change group 2 change_group
-7 Can delete group 2 delete_group
-8 Can view group 2 view_group
-9 Can add user 3 add_user
-10 Can change user 3 change_user
-11 Can delete user 3 delete_user
-12 Can view user 3 view_user
-13 Can add content type 4 add_contenttype
-14 Can change content type 4 change_contenttype
-15 Can delete content type 4 delete_contenttype
-16 Can view content type 4 view_contenttype
-17 Can add session 5 add_session
-18 Can change session 5 change_session
-19 Can delete session 5 delete_session
-20 Can view session 5 view_session
-21 Can add bank account 6 add_bankaccount
-22 Can change bank account 6 change_bankaccount
-23 Can delete bank account 6 delete_bankaccount
-24 Can view bank account 6 view_bankaccount
-25 Can add taler withdraw operation 7 add_talerwithdrawoperation
-26 Can change taler withdraw operation 7 change_talerwithdrawoperation
-27 Can delete taler withdraw operation 7 delete_talerwithdrawoperation
-28 Can view taler withdraw operation 7 view_talerwithdrawoperation
-29 Can add bank transaction 8 add_banktransaction
-30 Can change bank transaction 8 change_banktransaction
-31 Can delete bank transaction 8 delete_banktransaction
-32 Can view bank transaction 8 view_banktransaction
-\.
-
-
---
--- Data for Name: auth_user; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user (id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined) FROM stdin;
-1 pbkdf2_sha256$260000$pcpbRoDT4RG48YNgFpZ1Px$gxYivSss9VE7VWTO7nu0/k4/Fo1LGMVjhAdtP7cvRss= \N f Bank f t 2022-06-19 14:06:08.27175+02
-3 pbkdf2_sha256$260000$LlkPhswpnWf1lcXeNjw7F3$5CMiNC48CHR398j50/yZObaUdVORXWbsgjwByLERFu0= \N f blog f t 2022-06-19 14:06:08.455085+02
-4 pbkdf2_sha256$260000$YQ6RaehIWOwvMOmg97nJiG$GDdm96J0SsTZS9TdQ6XBd4uh0M9cY8WJNgV9cJjBVRU= \N f Tor f t 2022-06-19 14:06:08.546014+02
-5 pbkdf2_sha256$260000$Bbfsk4StqT4rZVzfDUtAzi$OFG/u52Wa7nvdAAAXlfkNSrxpSEvP7EXWfExxI9UQTc= \N f GNUnet f t 2022-06-19 14:06:08.637378+02
-6 pbkdf2_sha256$260000$iLn9Zz6Sci3B6PxjmlZOP0$iwGWeu0/yFqGSeS8E2VKHHyvDnq6TNkDmrC27BX56B8= \N f Taler f t 2022-06-19 14:06:08.727175+02
-7 pbkdf2_sha256$260000$y3tQCIVmtF9lSIZWMsYjmN$m7EnbugicRTyQCgzIZFNtXmNmHRmwDFgj3yYiKZf+1A= \N f FSF f t 2022-06-19 14:06:08.819347+02
-8 pbkdf2_sha256$260000$Vtf4mJKjXwgOVgC3tL9hF1$5ijyctqb3Ma7ru4rLse0/zhrqRNKXiqU/9L8lQZD4Ro= \N f Tutorial f t 2022-06-19 14:06:08.912558+02
-9 pbkdf2_sha256$260000$eLzhn8z4Cl75ZvnuFWUiAb$9FoFghWMvcQb4AwE4cVzUcfdcwxkxYEPeizplbQSrQc= \N f Survey f t 2022-06-19 14:06:09.002011+02
-10 pbkdf2_sha256$260000$jhNoBHQL9wqMA2jNVJfST7$e8L/3T23PhUlN628d6QRrN1HXMJkGRPZu79aQSMWTGI= \N f 42 f t 2022-06-19 14:06:09.45234+02
-11 pbkdf2_sha256$260000$Jk6SLrSajOSkNcy7hW0hjA$rYKO0oJBegZRi5oc8kqLMK0HcK68l7kvbYYvOTowQRE= \N f 43 f t 2022-06-19 14:06:09.911245+02
-2 pbkdf2_sha256$260000$UVpOACZUylhTNags3wzLnC$ZZO2K9mysdtC2jFNfYgBlchQCy46Uh2+C7zUaYPrJN8= \N f Exchange f t 2022-06-19 14:06:08.363938+02
-12 pbkdf2_sha256$260000$SwmEE5mbf5UoIsNid1htpM$xXRHpVXKgjHOX81oMC/fAbL+Mh4eb68CpirZHwKE9ZQ= \N f testuser-gk6lkeb2 f t 2022-06-19 14:06:17.06455+02
-13 pbkdf2_sha256$260000$bzKAIysOtJxIPtS2t59N8B$6MR15gYeU2MlDgd5viLMvo0K1yXwsiWjywXxAcQn5Is= \N f testuser-bbpholtl f t 2022-06-19 14:06:27.670786+02
-\.
-
-
---
--- Data for Name: auth_user_groups; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user_groups (id, user_id, group_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_user_user_permissions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user_user_permissions (id, user_id, permission_id) FROM stdin;
-\.
-
-
---
--- Data for Name: close_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.close_requests_default (close_request_serial_id, reserve_pub, close_timestamp, reserve_sig, close_val, close_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: contracts_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.contracts_default (contract_serial_id, purse_pub, pub_ckey, contract_sig, e_contract, purse_expiration) FROM stdin;
-\.
-
-
---
--- Data for Name: cs_nonce_locks_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.cs_nonce_locks_default (cs_nonce_lock_serial_id, nonce, op_hash, max_denomination_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: denomination_revocations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.denomination_revocations (denom_revocations_serial_id, denominations_serial, master_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: denominations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.denominations (denominations_serial, denom_pub_hash, denom_type, age_mask, denom_pub, master_sig, valid_from, expire_withdraw, expire_deposit, expire_legal, coin_val, coin_frac, fee_withdraw_val, fee_withdraw_frac, fee_deposit_val, fee_deposit_frac, fee_refresh_val, fee_refresh_frac, fee_refund_val, fee_refund_frac) FROM stdin;
-1 \\x027095cca0384f53c7029b7827af4b2171daa4ca15f4e7192bc615a363046ab473d7f7108145becc279899586e359cf9e3d36e65e40482a3725ff97d6f6204c7 1 0 \\x000000010000000000800003d78db7d9f7d43b2b973de3cfc0bea83822f5e6e3d7ba0c18638ed32298cd37545612e784163ca3f4456104729f8286a43c41fe3fe6f483a100b76cf81cf4b2525087e45d56ec17f34d9e3c040f0f66aeb65823049b20d0a1f1f2fe64f2c72f48c8bff22d41c346cb21fbf1eabc556a5c8fa370ef617b874b109c5f1ed67894b5010001 \\x0e899a551d03f930514e30967a0d8699166a6e067ef35a32a7daff578e135bf342e48e41b34da8becf98404102c0d41a14c8fabdca4df488b8865a876e77d40e 1667125867000000 1667730667000000 1730802667000000 1825410667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-2 \\x0620ba03c684f707bfe8a4c5c3b4a498de3e163968ece698cc08591326a002330b96b002b8d9ed287920e303ebcb43b0beb6b4f156ad33f9661260ccdd7bfa6f 1 0 \\x000000010000000000800003b64c33185e6ef0b4e3acbfd00751d51e037f9ef180c81cc6b35d7a833f02917f93291e28dc391e4271a1167ce65a8f88d55e23fb5a723f19814a08aaba8f0bf564ed2299f3c31c0bb3227c46e0c86be6c0e7e0ae2e7e45fb86929232212785e49f73f492cf115f8171161875f0bface61174feed659d4c261cb8a9a8dcba762d010001 \\x73aad1055b93fb4a2995259c53023d2952131576fcb1e58a1798d0bc176c8b4a8af38667dfc7b100d578515fc6a7c008a5f043523b0e4bf0dca9a5a12a4bab0b 1665916867000000 1666521667000000 1729593667000000 1824201667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-3 \\x08ec100740a819e68f6706528c948c86540f3bfdc6065358fdf5e85e87ed608f9cc0996a25cf85f17ed7adafcbe64521643d90cb1f65806af8c1d090824ccbc5 1 0 \\x000000010000000000800003d260654a90cf372c1dce6d09697b3f58fe0223f1e862d072779fa16e835ab8a173df4f6bfbc98b324473d8bf6455345e5495ae762e00299893a2c60102f6199c7c7f3d6f124577f02ca5f86c21a60905b4d5976d2f1dc0b83994a27e3d8f37145c4ccca2594ad90983d26a98d96826bd8fc50b48a640c029f0b89ff7cfe0f327010001 \\xfba134eb7ad7020f0a8436d0d83e08a8afb94c1e9a3d8babba084c7c30db4e9f7bf3f587c4b46bddb4892fd2fc600e8062c23eb4331464aa1625dc2e1d65d104 1660476367000000 1661081167000000 1724153167000000 1818761167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-4 \\x0a906b4f6a79add9f98362b15446d08dfc5f293b3db757368f13582f2af36f343a944bef32abbbeb15c7075b86a10fcc223aa94623f5184cb15f8dfd6816a5d3 1 0 \\x000000010000000000800003bb7ae60a3c4af099244eed03427824848724bd3c11f3bb8d0a52a708c2b23245f839f6df32006027b2d82ae4ab5532f797721ab5e483b4cb7b705002d403abd38a0d6117421c1923109934f3be7aa5be1a7beb00bd1c528019731df6e018c52795263d4d71d04786e5cc7a80240988113f7320ef51b9a90adb607415d7746d91010001 \\x942d2cd9322caa12ff72c170904fc5f5bf296b60cc8fa9681dce6f4bfa26c4b2a3296f5a7a15f1939f9092be63232e8cdf173e771d18eb94523b86e2dad0230c 1657453867000000 1658058667000000 1721130667000000 1815738667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-5 \\x0fc0f90e46e4e5710b011cd52df7e4abdd6e766ac0a551c7bc34b50af7f93d5d08107be85053dc264e80d43424e41c0de79b3d2ededb837b263ae2d8bd51ab6b 1 0 \\x000000010000000000800003b192c67ab1bf257198e98367adc63d49ecf66408a77b4809d4aa899ddbc3a3d448ad29c4f62239e3f36fc4e7d60942a1c1668774b032ad0713bcd15f5830b0b00cf9934f446eb52e26008277affc0c531ad12cc1f49f1566e36567d73859cb4b84490a426278c622457637ee108eb89c54c9ad0c9e68ada9d60b2757fa805c19010001 \\xf17c683f587cfb7f055275d8a03bbbb6a293549dea1bfd1e79b3bd1fb54b9de99431b0f69b5bedb67e6c1c4b4f68e8388a50d6d3e9a010c259c97686b77c6700 1681633867000000 1682238667000000 1745310667000000 1839918667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-6 \\x10145d8db1fb88337eda42fd6c252ac899324aa31a3e8f13121104ae49fc97ee8bdaa8df41688088f33a9214bf403fa853cce45eb7254775467bb781337ccfaf 1 0 \\x000000010000000000800003d37453cadc70b9612837171bfb8dc52dd68fed18438dcca285d5be5973cfe2a57c1684bbb609bf133574a976ebc02c0a6521e54ac12d4abea36d3d09dcc3910245ff5676d0d9eecc2cc903bb4619b91c39957bedfb15aefdd56174b36bea2a5702e956d1304b24a2b06da8fd67a7c1942c103b7a93348aa15905881d448e3d93010001 \\x167daebf8c8ca0f90a80ac4da10ddf62f50736d1989d793f4401ea1b3d0e2b1144f05beac109b841412e7ef9856e5365508ceb1efb6308a4b494b12e5a893f09 1662289867000000 1662894667000000 1725966667000000 1820574667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-7 \\x1024594b548789fce5801bbb71b13676c9b6ebe417c16b3a88495e37499812cdc4a10d499b8e7405bef623dac4ebeef85bc63fb1535f8d9dc1f587f4dfe1bbaa 1 0 \\x000000010000000000800003aee5146b61846ecbeb47724c1ec9cfc68ec5c61e3f9567938076dd6b66c8541b8df2397f58befeaf1b8f32260a3d26c2ff5a0e4ec3ec8ecc1dcf84218718c0ffac53aba58982b2256a0cdc76da0db629a4eb54fb36910eb5ded858381d041ed105997c1182065aa2dd69bd7b802af3571fabda6980e1799137889d3dfaf3bcb5010001 \\x8f9531da2c25e1a55fd44500fcac32bfbcaa87a224bc4d7e19528f9c290b4b10279cf4aed1f19acc696762e821b110244c3d7cb4be776119cd00b2ae0b0b1305 1659267367000000 1659872167000000 1722944167000000 1817552167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-8 \\x11fc198a3502ac67a522c509179699db30cda9f7fd96ead5a0074b1a883112d64a2660b2ebb79cd91348d5ba2c3d3c45ee6ecf0919478be46cc26c32bbae18e8 1 0 \\x000000010000000000800003bad0539aa5080e6b6e2c981ee3339e94765e39c2813548451ca592d71577c19bdbd789bf982d0a88da7d64d462cceaca8a78c44878214eb166cca7612a52ef245b2dd1efeeefa7e21f5e6ab8764dcb9a6eea1d63f828f9a0ce0685221e806c0b9227095d1b7f3167cb405c2f087423ef5586dadad23cb4a5ecee57a581abfc8d010001 \\x7f8c9275ceac5e60dec24d8bb3cb864deb7ed48e7fc7bb59f116c211bb23503536da2568dc61a4cc5c55eec4e9188d0060e1ca097462a172be2f7785cac8bd04 1662894367000000 1663499167000000 1726571167000000 1821179167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-9 \\x17f83ed63bb30193a232997365c1cc4312328d56a1625cf07a88583aa04fb7c9bfd91fb961b1e8786c71d8a752fb29420182c92c8beb9b87ae250aa5f5830ce3 1 0 \\x000000010000000000800003cc79d0e3482f8f2228f9942854d55e8dc18ee34fbbf1a0212d78148b128ae314b8b56f3f6ae2c59a8126ade62e935d7aecefc6cc4ab619e91a06278d8dab529b37827a52caa9e3ecaf453339dd687e19826b0548f34dbde75aba811e90b27419ba5ea4455bfd00fd9669fcba177720d42d995fb39c0540c8f20b7d34bfba3c6b010001 \\x4d3d273ef6ed76af54218b72ee5cf019413ae356a409b5b77d2ec361e4eb3f0aa3d0a3ffb2f17d6616d7944bff2ba56ca2e8c243a399a8882c2db672a746450d 1667730367000000 1668335167000000 1731407167000000 1826015167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-10 \\x1a00c0fa6ee0c351f2010b48c8014eab56d2941f9078515278facab55832e635ebb1e1219fe17c2e51fcb715dcc61c9b8718be5b9ea488409c343e7620a86462 1 0 \\x000000010000000000800003dc0cc90b3e2278fe66dd1614e03e5da44e64d80d854cd687c2abb05525f6a8652842878e0de0e87e796544b82453c09a140d49826d1a472a0feb0281b85ff5aacf355947982c2b26480340463426e4c1efdaeea95750c82f8a1e6339a6849e2c713d458b23b730767894e68f0ad5e916bff29c7857de7ec7af3042af6992ec1b010001 \\x42584e6228d632ed719c63a626626644b2061d8d6fb5dd50a2513a3b657e3d41a4c13956b46085c33ce465928cc3fc0e9eb866227a86beb8558ec6edf4e4ef09 1656244867000000 1656849667000000 1719921667000000 1814529667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-11 \\x1fc0cd3a5b989852b8f174df01fe37c2a0b3b4d8da8c2e432ac24d13c411cadfff03ef31ac9a905337e316ff56809feee01589f82df14cffdd81deadb10fa6cb 1 0 \\x000000010000000000800003c4a48bc8a73cf7895ad9d2ad9c5c87d887e7bfc44babdbb38ff364958cdf92ef5adec747d15db413bf9b6a2d2e3f2edf062de0022ffe121f1719b6d164cdff45b9688548843adce49eb3ac25037d3c57554ab71174178707e6b76d4647ced5547b1496a09e06f39a31f90c52b7d85c262ea7999d0b87cecd9bdb428e0b7d487f010001 \\xae9e455d79a9782ccbb7bd81134ed8e6697b2faabe4a5907c558e01916d4bf8dba5b317a1512af91b25eee77658c46181b5f10ec71f6bf68c95e79ba642aac0a 1655640367000000 1656245167000000 1719317167000000 1813925167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-12 \\x21f481692a964774f77a54f0d74aff0b2a8d76c27f2b2991abf300c5168ef2c98387f0e72badff150654227f5f51f26852d164ce19f4eaeff74b956bf7d13db6 1 0 \\x000000010000000000800003bd79124c55c70003b3b613028f3dbf8fdd23bfd1500743f10868c8263e95091d0ed2d1890ac62695bdecac7347a220f4c98356b138f9e7faee4af87f0a344dbaa37a7abdb2757bb661398a6b4a941678f61dee2fb3e22a87f12ff366a7c0c9431cd16dc53fc8f79fa819bf03d4e114a586039873574a976c3f843b90d192a1e3010001 \\xba393cde6f1fae4698a64aef84a84a485af0447a4787e1766e64ec75e0683c429e3c08ec470c2309ce7c543c50ec6f0a097e2039a9e7624b467de83fbe07d207 1670752867000000 1671357667000000 1734429667000000 1829037667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-13 \\x2c8c5607af0b845b1775f394d9154fa2fa59af6409c29b7d86af9e2be0dce73bce204c32aed2037e15a9d67236692df1df6370b015284992140829c911e2cc50 1 0 \\x0000000100000000008000039a66ad484a0ffae93c953efb949c0b359d531e45021cef83aa01d12e9bd767047b7a87103382e6a4b942bf1f05a86422ada9d62512aa28b5e545dcda54c2e20c320f621f04484296c0785f505df4e62a38c41f24d03f05a714042143168482ab49100427d2544156ff60896cf5d02194d1bf3d1ec030cf61be996259e1ecd1a9010001 \\xd8fd1b21eede14c6608bd31cde5aa46a5e6c70481790b331b67adb64d80179788bdfae0d3af1009fffba8a4f99e617c9dbf151fd94c4c8102f1e35430d837506 1674984367000000 1675589167000000 1738661167000000 1833269167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-14 \\x377c56886e5c93a9c046c4b802f593e677b692f2f54ed323c0f02ed7df3cdefc95b8591afb1fe3acb82e5ac7ab372c0916e577ca0ebbf5497c69861c26331a46 1 0 \\x000000010000000000800003a9653ddb091faed4236eb782007a2ffbf2cea1e09071814dcd7107e63b2e507ddf1c1f5956519a9a60d4c5fdbec70433d7b49e39212a133d1254ad299ddec3bd82e1168cc6776751f52ff6642ebcd29c33d6d15b1f34548ec9b4f89a97897df1c0463223fd6e5ff4394e46582be106ea7bd17990a841a149c9330c644047522b010001 \\xda1a5ee664f93a87861c3360318f76899180228a13ac76a840312530c14d2aa0ee95c2662f5b35000b017de38eb54af3fee4a7ca4b6021f01cf8f3da5b671901 1656244867000000 1656849667000000 1719921667000000 1814529667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-15 \\x374c74b0504ab62c4cb1dd83f94fc996ecfa8043b8b63ef3422810a7f3a780866dc7d12eeb7cf265c5a0c0a8602b936541f8f855f2f2617f6a00217088712f9d 1 0 \\x000000010000000000800003bea1f4fa54793a03446e9b6a47390c42582d0e039eec30f0f47d15d65eab6a4df161d20f950b0d50405d1b077b3e31c1b92912bb950fda8ab5b877119086ac4405e7aaef9518124c18dcd6836c3e03251fba1486ca1460ea32bbc7d92c9162243fd483475f62bea4ed4162befe6a2bbdcd02cb09bc6c01007d0f9184c2b007c1010001 \\x4fafa84c521bbaa29b72aa0f1282b02040b4624087d341287c8b850df611dfda5dec84c8e022da1dab3abaca3d9da9df04872598cbd647b1ee909459f2c57d00 1658058367000000 1658663167000000 1721735167000000 1816343167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-16 \\x39386471396c185eca8bb3e143aaea32d573953a29330f9356794ee25b3f2cc59004433ba3127269862d35135a7ff3d95ec29a82e6491742a313aee19e764dd4 1 0 \\x000000010000000000800003d5169b3aaafe1751c65b8a26a04ba907507d39ccdd62752221fac6fd9d84159cd2791458bff9083953d4d8edd51d9e6c70005924418388e5b96ef63a6407e11dd816f2168d8ea0761f1d5d9cc92a2dea363ca2f97ab7a087eddbc04f66decbfc1bb3ae1a3af1dde1ed094378152ff159608e6f3f955dd6fdf527b6ffec2dad25010001 \\x3eb6b7cfad6f0f5e85b5b75616295e0661597da906bce9f11dc7af47b3f80f70750d948ccf393852913f08bbbf7cb0e0c9bff714add5a697627e0a40699b2604 1681633867000000 1682238667000000 1745310667000000 1839918667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-17 \\x39a090b11bbd0aa7cad0c708d26925f6c0e03f9cd6f7788105a8ee28302f3a408548bab6b60be81174e9dfdab56b6310e42be40679aa29fbe56c58a5ec33a4ee 1 0 \\x000000010000000000800003e022966d15628005b3a8a6298ed2de07c26e7ef3a8386ab584a164771167eb2db2b6b311fb0412070c33fbcf662f11746cdb209fd8902c5856d953670a51a6bc42cca986355fa2a8b4f3cb37fcf62c84fd61ffdacca78b70c0db75c96b8847ba2a1bb49f592e710c35651e3decdd2e530c6d37b1c17693a26146edd8ca448541010001 \\x1df3f1b42fafe4d7e4ba3b85409149a0ad8e46c16032e4d86539905a164c656ef87e18a03948a6f327f06a030b7cf214cdb26bb83c4d6e9b149503a13fe2c80a 1681029367000000 1681634167000000 1744706167000000 1839314167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-18 \\x3930ec48024232d9cc3a8e77fd3b065fe2796962d12cbacffd0d1533cb5bafade7aab5b1fb5b8c0cb335e87042de4627714bc41f60906af3a7d3636515576837 1 0 \\x000000010000000000800003a10e46f8eea9258be4e19bae8e19c7bad965f5f3cd4e4c122fa345ff83199cdc104fe974a717386646299f2598e16ef66f92b37b843b0a42ba55bfa733d39ca1be83466a4a148a4de3ab658dbc78d11711c3e09caf679f536f7810995c30438f80e0efca65d68eb0708e593f06817c48025219bbae58971411585e9f5a9ce849010001 \\x2c62209d96a3261d357234951d3fecb5b9ea9d75c06dbe78cab7103103d7215e63b3bf513e2aac74f3c9cf605517255e112325d100f28b42c299bc044865b10b 1668939367000000 1669544167000000 1732616167000000 1827224167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-19 \\x3bc073ef9156998c30f70cbebff40e3eee5786682dee45d7978210ba0ecec2dfd2b7c716f302556afd5609acb834a83668f7e6b72d29926835079d61cbcf68aa 1 0 \\x000000010000000000800003c1edb35684e35b22632f4fc5e038172a038a3a8b54700d9b469d59e432c17f137d57cd7f07858d20dc4ac49648a9911b2ff2b5e95e8902990aa3596a87262d2d973189bfd54e51ec89c4b47e4bcb32c667aff4bdd82a5ef912be396f31132fec1392a91231c3c50500dda77ced8a9227be15a8909ac9d7cd62b3b70f40baf89f010001 \\x30d636de39299d0c6eb7bf88a575de3c7aa84ae9d94309e6fa687bb34c0a5dde89546920e42212abe33d5aef41805f63e357f158bc4657ab4a67fea1e65f1a0e 1685260867000000 1685865667000000 1748937667000000 1843545667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-20 \\x3b40cdb0669520feb7218c0f7379b2c38bfd76d7e313de48c5b99c6d1ee8c20688e56a540a10bffceaa68ddf059e40dff056c65f0f9b50428cdd79707a92e955 1 0 \\x000000010000000000800003c3ce91d38f005e16d77b3973fa1b181ff845bac2ba4426cb066f5a15a30de73191c16a8c9f2a1228df82028e28a8773589cbbceea14b0851c40e65af9a488d40d594dda8b1c82975a535378631639e3b29c950311bae1ad2c2f3a8a5a6cffede60c2c30ff9225671d80347fb540089eb98259d2f63ae007676ef03b6273a9fb5010001 \\xcae397361c385bea03e94918175963e3a37c97c556cb7357092c8ba6879a91983e8007ccae4317d4f0d7baf4c40dd4f9ae2b0639c747a91b354bf7c0123fdb0d 1657453867000000 1658058667000000 1721130667000000 1815738667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-21 \\x3da8d7624d899da91bd604215a5e83f6d63217bd591c161ff68e4c8cec168735c76b54857060fafed467cfc60fc34a07b19667ec40bb732e3a8303070adbe517 1 0 \\x000000010000000000800003d133bea9ef74dddd57a86b295141b07e4d69d1c7061e25edc55fcc4dd3ff114933556bac6028b3a88965191ca1d7209783b6045003db596d38128dc7728971ee4e1bbfb7388e8012569b2cc702c18d8da0c1543458292a40080395863d9f8ed7ca68c70a1f318693da408637d8049e0f29e0c63540b161baf8c12db65a49f80d010001 \\x2e8f7c22363170da584e112c3af20cf8dbd99b123d4eb14c82beb213a4d93d85bea47e1d49661c8f4f9564e1440497c0009aa5df12cc951a3a0b98d256c2b407 1659871867000000 1660476667000000 1723548667000000 1818156667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-22 \\x3e4cb15b705648e86aeb5e327793784fd712d765865edd93ed820f14f9c7a334ad8fd5781708e9f0f418f3f90ea65ae111968181c7b5c78dbb5110a74a473c9a 1 0 \\x000000010000000000800003a56494a5107b9c8201f76cfc9e90c904543149717d9f27c2177fcb2e7e7fd0c97de8c35b9b3b768cbbc9290952a1aebf95e511b9446a9a813fa98447937b4cde25a87831c4e7bfa7031c59d93dfffdeef0c35aec5abf2005e0a868e23fc72aee8e0902338cf67af0c33816955e5863ad09ceef395e94f329ea04afe499602683010001 \\xe7780b029e4afbd9f7ee0d14d9c4d4dd9bf4b778344a3c5089c433fe47788f7ac84427a3897a5f560f715bee99a5946fbed54a27bf9fb46e53e456a0df97b902 1676193367000000 1676798167000000 1739870167000000 1834478167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-23 \\x43d8403376bed10ea96c0800fedbe85cc457381ec576c5e4328517b6ca4da90139e71753562c3f925bc0c5ed4b76b3c7bf96ef76b4201bbdc6cc9b5c13d8f141 1 0 \\x000000010000000000800003dae5af2b366c0ade66579e3baeb9d7b40784159601e71bffc015eb32625907fce2270f8307703cbb2af8bbe437ad0d4792d4b91b85e264ee8bc3584c1ba9fd96f24501799b6db4a683b9809106f8a810d421573edfe700722e6dda3a728752ae37e19e6861d43046f1987709878d026d6373b555e5b74965411fe85e7f983333010001 \\xd8deebe27d77c4b2cb01fd70531b5e74b3e8d6ade89c05411c104cf793d8c9a5e3ee98113a3ec6bc5898ff7195f736e2885c53613b3e96e0d6231e393734bb06 1686469867000000 1687074667000000 1750146667000000 1844754667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-24 \\x44442cd6c5e320bc968d4c9447e247430ecf1ad2c1b35dd287ca5ca183b2615212249aa317a2c1645eafaff6f9d02f5a136d90886f6aeb66f34f9d8da754127c 1 0 \\x000000010000000000800003f31cc60a29756c32d9373a75d54028f9b3d89ff7b5dea033f64a4eb012ef465a6e454fb2c5cc929b2b99d9a11dce100482f750450858fa7b051a1d32705202e37b56c39c5f72ad9ce194867cdfe7b2f41f9e0dfe87353a1916ee2ee2e1d60502cbfd3ae09da6f7fe8d09802994d7dd8865f7c085eba607ce68f92ff6a3862e8f010001 \\xdf9f4cd7c923171601eed196496663a0aa5baad7b230e45d355b95d6a872e31305e8a061bd974bb84aa4edcb451efa409b7b23de938ca27eeabe032f3ebf3e04 1679820367000000 1680425167000000 1743497167000000 1838105167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-25 \\x4564b0cc2ef030aa91705c1d776cc9a5586541c492943e11e546633bd6a2524b8d411483f4912b8f2f22672dc824a5324f4ad2f11a5f5140bc4a637b40fb9fc8 1 0 \\x000000010000000000800003b996c5c43edae6e6799c86bfa76c853b435ecebfc96c4da0f259038f5422792a5412b46ad2f7333873e227c21b863f3df215eeba0e5f4357920e5797d7d54a9b14bd6c3921954ad77d38d11a42b04b03d72f99b6f06be66000c600e21ff2b7a36817366e481459e31861db8600d42c7a385534ff051917ec55a320e73c65abef010001 \\x30b91292cc1c86ad7f0566996129e4034d92ecdd044feced0ea640dca4c9a6a7d353134872f19c00bd01018583cd2601c080f99d14402a2f81c7079c4ee2ce06 1680424867000000 1681029667000000 1744101667000000 1838709667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-26 \\x48e8a1d919f43a833e659f6b86207a791da91731110c5ee8d94ba7977a209538e883f277e330b16100eef70323e315fc006d97c16b67e105084be9bac3cb6b45 1 0 \\x000000010000000000800003cf92eeb16f8f12ebccff8d6b4e0aa566261624883efceb9782fd5cd4d52e4c79aabc7cd07ee5bb57d980e1e39700957d4299b2abe1386186ce1501cdd721ab291fb36349869a48f67972f1349108fb6cd03013022313205b7394904d448abf23ac8ccee73abced0537966f481883d75d17fe6ac2946e01f72ff0a9fe1bafc779010001 \\x47f5f10c8681946399daf90a4de23d36205296499be0823dd2fd366070fc45e1faa4f4bd1eeb8197eea90120c3cdf9037b0cdf21b0ba3c84b6d1e0296e1f1404 1664707867000000 1665312667000000 1728384667000000 1822992667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-27 \\x4de01e1089e3039c430c9024305494e1941ff85a76e6c36057549f97cd57d78c63d31193564eb027cef9f4df95f0a422dc201bf6ccb0d99edeb655d7133e1115 1 0 \\x0000000100000000008000039f1d8a26d853e55e5c90a7fa2f94cad3df8586c0a31696c144c075a94382bb007e948a545864102050110c21beabe2d0924d0d22973c1b7d48195e2fe7bbaa8504640b93c8f36bdc8e3bac50c45163c0c2c9fa689c704b0f2b8c82360246b7bf0d415b4a541b1339319ab724baf5fb490fb0f5b944815874e84c725ef0c254d7010001 \\x0b833d176086deeb725ba3dec8c28517d7105052ddd45fcb0352193231cd2a9dbd2714ec81c53f01441a647bdc8ad7e2f13b2752cd4a2c69a02d375d76b52f09 1665312367000000 1665917167000000 1728989167000000 1823597167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-28 \\x53d8dcf4a3ff3d3e4336bc31151c437164f4e510be29e558dec22c9fd96082c90fc447c1c05dba571efee81281951a5b11ee86188a567346267509e94e005a0c 1 0 \\x000000010000000000800003ae6efa4b4fe89b4a914049e83677b55eb5a61cc0da7bbc8c7105ea1da5d4b9e7acb1a12e38e1123a99efc2177e97e36f0de899cb98322c3aa30fc5f77f3ff3afcae5d2126c05082f7afd05a02226d6bc5a86df2ffcad34c98e953a5f90ed512ade08743f3aaf95201bbbcc7fe35f58b86da68b897300d823f68af460d0d58529010001 \\x4798659ea7a60b25c0ffed2bb6c5b06219fa549a75c24187c039cb2a0fe1af6733997c53d999a1a6f084cba4b1fbf9d060a2eee19634600481a2f80d65085908 1673775367000000 1674380167000000 1737452167000000 1832060167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-29 \\x548491f47c8ef5cf82a85e9f7a065534564f827186a8ec9e7591c62841654af92e213510c17a636d24e0ac3267adbb09463d2fb80bba50534b7c82e66c6cef3e 1 0 \\x000000010000000000800003aaedf3f0d9f90e38b17d58d54adc4acca9d74db14c86e25e23de69175e9a36c5582336f6eefded324d31788376f167a1047f2f98f14feca1b2050de766e9908f43f17fb24b8ef322a2bb3f0f3c06ea1cc128cc3b75cdd5cc2bb7ff585bf27541fd68db55efbcae624f0fa31311a44146ddb28ae90d6d6003302359789cedcb89010001 \\xb5a5f4e4baf82728ed7710b4be4c1cc4fa689b0cd87a9270af0343218614d4473a82127665a3b225bd4c216a21fda87815de5c64037381a43837fbca590f3400 1676797867000000 1677402667000000 1740474667000000 1835082667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-30 \\x56d47a5d4a9707f355a65a79e5f378287685152cabffa7e3d6e142b8c749ac374e6f857d4defc1a5165d831ca854689ec43bc3dc4e2e69e1a3770bc2a6525aa5 1 0 \\x000000010000000000800003db418799802129d211c2b8365e568d66a8a0f4833382043210e72d6d2cf50bbf107b7e2213d56fd7d0277d454a90c3d221e2d40ce86724c054c236492d0f3451cbf974bb591414a38dd7800ef15745e2bc63172af2410dc0167535989d1f11aacd243fbd58d90c091f73f9e4e2f0c9433d28feccd6d12feb2cbb96fae262f453010001 \\x4fd188a7a15f7d0a5cb874ebd79a31bf15d075402a7bb1f6efb5c8a29131015b59fc0cfa8a9724ee99c2c6ed2439c045d9473cd0d6e9b97df864c3244de0ff0f 1673170867000000 1673775667000000 1736847667000000 1831455667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-31 \\x5a28f40074a8a3142950f4c8c79c287488adf52b7a5b34b9678d99afd66c2ba3c83092519715525ce758d7f1f5f15bafe44f18f0e192e310c49aa7a611d6193d 1 0 \\x000000010000000000800003975e4e39022f530b5343d1551506ebb05ed3730e4d432a5fb7197b1553c4ad2ea739ff39761fd2a50e9c4596f83903b7689222b07338905e3439c3c5612d25201dfd84fa59d5db2c470661e4fa0fd5aaebef89b113c20f8711359ca918c05ff0889e4d837c7f41029ed04548f4ac713050a22f7794aafd3a6a9ae6ef2211fdbf010001 \\xbf5c20b6356da4592c1311343f123bffbe0a5459658580d75e8fabb593f47cdb02145b27ff7f1d1ebe5f5328a5497df204ac59b1d15d03b308ffc725817b6e06 1656849367000000 1657454167000000 1720526167000000 1815134167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-32 \\x5af4631ddfac5e15d62d2d3cdb40ae76a45ddd985d0d7f8b515b240b1779ae02321e8207978ca67f2478640fa6c1509859f3c345c346b95228b75612da4674bf 1 0 \\x0000000100000000008000039dde752529216fba9bfa35c734542d0f8fbe76fa26d3e4a97d97e9db38822ab809812554560156dd31166cb8825986827f87ad398a6c990562342c692b5c9d1afa3c56548c67f65fe749465fc8888181b61ab5b305a10c3e76d52f9488fb9a5bb4470008833777008e58d6acff65f2869060bcbae2dd3a4a88a61ac6765b59ad010001 \\xf494c315f492a7e4bfae017f90fdf0595b06255d2ae0429cd779f9db7496eaca0f4803704ebb4143bc205a44fdf1a4d15e647fc5eee2a72fc6dd2450f8a7d30c 1656849367000000 1657454167000000 1720526167000000 1815134167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-33 \\x5c68d148d1a2756a553d30beeb457e971aacc39239f9cc59fb4acb9befe443eb8f536a7b72f2095099a50f274a5dc28e6909a860e6f810768839898a127b4f37 1 0 \\x000000010000000000800003ba377498c7828da3eed108ac894f3d4dd900764141f99b6792e0331ace4d9bca6317b9c37d9b3c06b88c85995c5033e906e00ed4f770469d5c0d486df078cb967bc22e9844d58c3b5714c3e7f8e252ccfef4fed2b6c851386abdd3aad34a37bfc7364ee1bfb72ba936fbb6866b9082f682a2c535ccb38e046fdd0de9b98e8eed010001 \\x065cddc1ee34f6ed01fef03d1c6b8241256f27b89808a615fe6db9a6754b094be75b09834ea3d418c35786f38b6a027534d48d609f2c60b35488a434ceb6800c 1685865367000000 1686470167000000 1749542167000000 1844150167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-34 \\x65b442ebce9ff663cb2ded2d0da128b8f83fd512aa1ab1d1364cf8ec8530cf9faec8c5313286ebb47e19c6a9d6fc0870163f298c7da659382ffab8d862e24400 1 0 \\x0000000100000000008000039bdbeb67ec856942544f6e9218bf38bf3e5c3262c8ace78909c0ca29c84b088163fda3ec61cd23f6cb849eb6aa4f0a9ee77026cfb2de9de18c1b322aa0a45ece7c3b0d985318311ebdb0303df5dc3932d63a1ab0e85b143e1a39b895374b60fd8649053de7a8a3934e11a60605ceddd12b12e06b25283e605810a2038e3710d1010001 \\xf80febcd2a96f025d75e735f5386027b78b4b3d7071e384dee6813e4435eac565c3bdff8d0c0f441efa0129232e07aa79ea54fe52fe5c964c257e9053f533200 1663498867000000 1664103667000000 1727175667000000 1821783667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-35 \\x665004da18cd49195f857b0cccf179b251a733b183a4aebc8ee0363fb6d49d3603e8523002b0696df99fc8e3180251f9fd8226699400f01dd453400a9e970438 1 0 \\x000000010000000000800003bf62641420c57853f91aed3155d6b54550eb6f315ac986b5afe461b2082d5fb78f4ed4c6c244d30d1267ea36d5e5e4cb2154d55c61709552225887144268c139d8fae5ed074ec0cfe0ffe822417b7773039a32033da8b0b7bf987c35fdd6be24e42f7345eaeb73748aaf79b09cbd01d2bc80c35c9cea5d9fb3885185bf6c631b010001 \\x4d26cea32bf0ffd6c1643cc28632825f832f308ad35875673255d69528db6eb0f586b5eb30e944d03100099c7321ba4d4ff8a9f79b25512d6c766b1b09f35303 1661080867000000 1661685667000000 1724757667000000 1819365667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-36 \\x68c4ad682a000585cbc80c3745965c7bdb8232d424f373ca80c7c59d06f2dd128db936675a502386258e494da38f866fb383cfcaedba31f2903e5be96cdd2dd4 1 0 \\x000000010000000000800003bcfe08a6bff69a2db03bb676d8395cb63e7819701f98515a8bc56c328ad6903ea1b09d39a7dc2176796262598256deff3ab727ab89735c6c8ce2698eb1c7fa5c90452a3f07924d1fd3af4f269cbd972b637c699341f9ef37902282d13bb2044b75a7dd4d5a16f394b1dc6de1543360d321dc27736fb501c945d5959e3ed0db13010001 \\xe1bc9dfcbfd595926cb9d446dc08ced2a2506090219c9d821a14aa0f84a71bdf73f6f6e5edc66497d4095c62993311d6aa4e34e322ad242dcab650c24955e40c 1666521367000000 1667126167000000 1730198167000000 1824806167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-37 \\x6868f610f499495da55a4bd3374bfff12dc75ce44ba77340e1d21b811306834b456d994436e07d1be684f2b3722bb91b8e6d2457a777101ba73f142adfe8e83a 1 0 \\x000000010000000000800003c90b2e527ffad312b72224a56ca8d2029993c69fa4f53ebb43e21716cc6c5de8c79ecead1ee8671f82c867d72e659a081cdfa215a649245a9880979b3b74353644df9ec6cca524f2fe04bfa7736185e87dc1d011c2f7e7b0404cdd1b36d37698712eaa69e925459f285d49fd85d080d75528906f0f778c15eaa22910d71cecc9010001 \\x3050781e818d0a02cc552d24d045b35b3a5c9ce276a7f3b6b4beeae476e13c00f1123dfe425a12d8b13dd985dd7191e6938a5a145b33e91f9707a81e4ff0f708 1680424867000000 1681029667000000 1744101667000000 1838709667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-38 \\x6984aca5758f3e2202cd5d7589e4a8a058b616dce9881d35011a2816d8c09f6939ce5fd4a2efe93fdacbbedf3310fca4510ce38160e9e36c5dd557be4b43389e 1 0 \\x000000010000000000800003a4bfc2140ae8a35d2e30b1a436f2b094fee13fcf3f2b56352b305870bd4db2cf415265023e81bdd6a1f17a0c4f7fc0f53b089e0eb393f32bf7cce2b4d61cad1a33501fd9ef882348bcd27e0fa7e3428e9663a19e4728c5b82dbc6a58ae505966430068dd1603313eb8755612a8162629d0c5c06d7a2db5376683ed2861a659b1010001 \\x5124589fe94a412183997be1182a5face01527d4a6de25a085c2ce39fc5c80d2e6df6248bdc34e4beca4c7ad726eb5f01080625c9ec90dd0b5f523fb02e67306 1679820367000000 1680425167000000 1743497167000000 1838105167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-39 \\x69944c6df63b27b9ea485e7fdd3781004170d3c266ad5b048ae299d40aac1e3aed9663cfd58044693e71966b9e16424de5deccedee0b20aed99effe1b2f4fdbb 1 0 \\x000000010000000000800003f5440e89eaffdd6cb17f9debb1d886d9e07dbd4e5c4dff8a49714869b7e4dc2236cb69bb2a3d3ff897ca90f0e57cd31497dbaaf9a91f8fac46b61d6d9fb68c16b375e449da26148faadcd4510c90c34b4c3aa1fa34c101e22885b60d781c5f54956e35a653898a0b81f5a0bbc832a3622666620c565592cb0341b52a8849cfb9010001 \\x997f67917cc2b8a73d611feabb36ecd40ec6693082db585a403d19823bb8c2158cfb9b231606001c92159994361b3497725b45436508e8cac506f0924ded960d 1667730367000000 1668335167000000 1731407167000000 1826015167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-40 \\x6b4076a2d1f6752c96457e5efd829c1d3f8e6b92e0b5f644e310bef13a50ff30ae5c05bb024a32ae1c8728ff0e3e525d537cb0d961775de954b7d75550078c61 1 0 \\x000000010000000000800003a999038c617999fec6f94860925e0d7e1e99f3978fece7839182e7da7d821bde355fdbe8ce81c86c20e855aa0aebcef85eb092c8d5da895713bed49f93e643d3399b05d221686060523bc8dc2b8b62ed4ccf01950fe8c28e471ee68312c02028c4b1da2ddc09c1f82af0b18ef5febf915787575e980a598caee4fa19d2af977d010001 \\x5bebdbea6a758bc1fdb58ac420f7b241e8bc2e7260d7185c5f477f2b402e2272ad0046794995ef68919161ce253c92db49a20f63098039b6ff6cd708c13e8409 1681633867000000 1682238667000000 1745310667000000 1839918667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-41 \\x6e7ca01dfc7959f18e36a3e20c157240d6bf48622229c615f8d273f26d9bed0719c53d9369f1155481ee5838067e838bc77bcecf23ddeba3b4049ecabb94f6d6 1 0 \\x000000010000000000800003b87ea92930f8e3d074e890af3144d14ad8b8c798af6208a7f43888f2c8eb46eaa558d27af16771cecdeeb1ed6c10e06d13ebb170734ad12c0f643ed4f62fa627717497040668b58b8e17a4840ddd52ba5952f0fde9c1efa74c1375bb1728be93d99cc1b94aa4ef8b72ea649a3c3dda0fac4a58004d3d0f90a565062c393e0077010001 \\xac66b95f06958da87a09dc9bb7b84063867521b128c5f6913a121e8c6418c04d56f671fcf65c6f8d5c2f51b0eeee8f2fb827eb56d37ffcac516b265ee9182b0a 1685865367000000 1686470167000000 1749542167000000 1844150167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-42 \\x70f090c6443926d16ce5b23d6ab82076da682043a03a2194f79e7503eaf7f87f230bc56b1961e1f48b2767cbe7ffb1c958382858ad966744fef29f6a8287ea38 1 0 \\x000000010000000000800003bdf732b0f7d202eb55eda8962099f2781520d9be15bd4202fff0760fea5f3db40fd41873eeeb140ee1b13d9b2ac5941fa5ad6bb1f319084347bffa304650437084774c597101ee9e64618c826e22a9ef4303e6cdcea650f33b9f229ee1bd99cda23168c6a1da2bc93c0ccaae9d46d518e88aeb8867a405413688ff90275a9ee7010001 \\x2a0a24a6dc8b9f1552e11f647a47d9cf4f33d096ee984deaf1da222da01df0b918fc9dbf1a5e6736ab168b9638438b53a1af0c2046029c6b7bed8006bb68650f 1661080867000000 1661685667000000 1724757667000000 1819365667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-43 \\x7108ab1e557adf6b2a0cf690a0e4f6601b4c996b01da767b4d967c0f8cb8d35b584d8684e7ff422967d3810c855b09fa6c04550a64d768493445f08943bbc19a 1 0 \\x000000010000000000800003f38d2d64e5a1b2ac7032aba685e8e86db5b0fad18cce850392b95774ef783872f213ec09912ed42839e873cef2632233ea9cba43f3fb60200e6a80e7e9710edd9de16a359a2bfd578685f66f37bfb121afaa15a2fa09014f3d36bd650fec1988e503097047918d088dd45f17f79765a37867b1e9c0689b0a1b556278f703fb15010001 \\x1bbb7060c931672d02dc4b07ef4fb507c703060cbd1ed261cd86e5d9c4d786671c2e1c210e97b0fb533ac315f1ee4c6f0f1499d4e52cd732273c2c65a686a00b 1658058367000000 1658663167000000 1721735167000000 1816343167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-44 \\x72fcbcfe94161978c7ebbb51727c51c67708934c94d4f47aba021f4c3b5bc444d544ae1b10678327f9bb82d05312be5b6f3f115dbf1f7d1abfbd67f140aea089 1 0 \\x00000001000000000080000394e2d4f8cb6bd5f7258c1d669dd6ad843351fa40cb2e0c6c867db7e44b3c28aaff48e760df749ea0372ca584b895876dd586392f717bace728efa7f4e7d652c66270dde2279bac554d83d72e11c6f35118b31b8f95d74c28f9e79d501acd13f5ba454d470a5cb648f0e130b2c640042702c0558ea312e5747fff5c0689e15d1f010001 \\xd2528dca4f35a64d377ca66b446f7eaadfa97d0e81f2de1e531f6af922eb945e70254330243d7aa7a9a383f2ed6f1fb47915a18217e236c4ea3528dd6c2c8505 1664103367000000 1664708167000000 1727780167000000 1822388167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-45 \\x76283433dc1c450da525fd7dc4ee30ea1df210abdc0f73cb7a4f5ff146a372dc717b8c90ec3111c5ab852fbe551d3fddfc74c70989ee513596e31c34ac65c07e 1 0 \\x000000010000000000800003b53fba5435fdd07f5ec5683b502a593082e5f8ea03684c21098cffc5450aa224ea89f556929a19e3e9704104e371f47570e28ab8cc44b55d964eeb24ce4a3847ca438df77cb4720296d074e71ffd7bb84375fa177bdf666c33879b5ba9ccb7c12bb2a909caae5cfa4eef7b17d271ac7a37662787e730e4b6b111c44d8fad24c7010001 \\x1fa2c11eadba79dec01d13cf592c4d9727401cbc8ac1c2b751445b4ecaaa3ae7d3c1ee4f75bc0041babf6e398e15c1be3b9973fb3f49d420785a4dc4d8c17e01 1678611367000000 1679216167000000 1742288167000000 1836896167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-46 \\x78d08978b0f66eb65f52328485e805f10d0a6359c5b76fb1dc159fd7f98f659fc1668ea42cb228764192ce8b4972f51b2bf2e12784ed175612df8323adf8b676 1 0 \\x000000010000000000800003f54ce8d65cc68edae981c75316dbbf0cda9a59e7b96b979b9bff590631de64dc9d0dacbc5b68d01f0d3eecb2754f9ac0073c6fc976fdc28ef86a19d0314ca4bd1c928272136692f6ecee6a97f421b4e8b91820eee575adbc36e103fe4ceafb33bd8c3feb84b76a67362274b8014caf2b7abfb8f8f510b09528c58aabe24fd19d010001 \\xf899db5c67ae5a557eea9f1e0b1a803dd15baedf120b27997e09a0bc24b9b5e1a412c6fd8273188702c5446592981edae73b1fef8003fa525bfdebde93aedf0c 1671961867000000 1672566667000000 1735638667000000 1830246667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-47 \\x7898d01259b2ebd8a90e7dc2097536f7e2af8d9822c11da994d0023bc44c515a78d532568737adece61df3c5079a54057bb1722e05df8ed1bd388b631cdf1a20 1 0 \\x000000010000000000800003b268bb4bab66499f792e523278676355bb7449ce0644799abe96294c67e5bd9b05fed58c9f69d1813462f28938f71b956deb6108048bbb1cc8dc83bbdbbabc1a97bd87125b87222b42890e0afe79c8e2be293c076011425f97cdbc19796a7fddd2efaedac02624e0238ca36e7d4fecccc93e07eef8dd0616a60d0b9e5cf392bb010001 \\xde5e49339945737c191c9c0ac1ba2e7ee1e0aeb56667296bbfcf81b241b34ca8a11cfbc0c37cb74f03d857e87176c6c5bc5deae3e32a554bd0a584b27209470e 1682842867000000 1683447667000000 1746519667000000 1841127667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-48 \\x7c34360e142f47a96ca632ea7297639c4d1302a36fc6e0de34ee055f74a27fcc05f27ad154be5078a2f248871d45febf58e5b3581cce22a25ce758ae7e70425e 1 0 \\x000000010000000000800003b0b4ead1d743965dae92ba759a1f35c19b63f925477eecfd4f028025ac667a127f1c14d78b5fbac1ee36e532ec27a6c78f8996f83dd29c8b369fc54866b2d2029deffd647cc629e2eeae00642212b10e36d1cd4d90b32d1ff0aa0e4e556a18c41c0f12a87f9bd3559526c1cfc149b9c7450d609e565ac2ab47d10f2c1ae24b83010001 \\x082197741af56d782cf39ed558b21c20308f45ba653ff0b00b96aea6df6cdc1920dd115089dd4171cd0294ca6a768c639f9b01d0769b8e927736a4d73afc910c 1655640367000000 1656245167000000 1719317167000000 1813925167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-49 \\x7e88b804cee54d41a75173d9f1a6467f40ab68318633896ec099161617f582ed543654e9253caf253f31b283002a80a4786e60194adcbbd2dae50d7c4a15fe61 1 0 \\x000000010000000000800003dc96de181a69aa48393ef17d74edea22cd8fbb4f263ccdb5e79e474b42d4feafd16ffb7a34646acb993fbd3aa9c5a365f81ee0623d3acf433e3bcaeca86d1d3fc8d12f52db1f5eebda05c23a08426e5182d0699ad9457a0dc9bd4996aabceac1022a22bc6187aefaa35cfc55593d8d94332b7d738d73ffc78a5e2ba4a2fb51f1010001 \\x93ffd9531d16693bf1726f19486df3ab17009476e6146617adee5b0c3a7a8d7dbf23775d11c9594754e163f0d7069b54c3424ddf2c28e183bf4955f8956d3702 1658058367000000 1658663167000000 1721735167000000 1816343167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-50 \\x807427a48d8b58670edc87886ff2704f24cc00eacd3ae5780d03e85308f1114291e2f75c6aa46a9e32fe1d5fe06fb1513e85ea4360cafbdb85e7dbee2a84bce3 1 0 \\x000000010000000000800003a3da9d146f02d1de94b5c79a142a6af4ff25cf4cb91d6d326881d8540a01c3be77af5c1be11068bf7c8b8460897e0dfd397dc8253fad74855aada4ef2fb4c704c13419fceac6a38b4a3274e43f7f28daad6b6ad7cb5470f2bfb43d9a430173fa43dc76fffb81464e3ce0c60fec983980bd8ab8b46fc3fae83666128ad93ee057010001 \\x75581b1d8e03899252cfd0aa0b7b600b546f1517b71c466bca7a4a41c1aa738f8b12d596f6e0d2b90048ecbc16b3f40c9c4df533b136636ddb46b4e718197d01 1667125867000000 1667730667000000 1730802667000000 1825410667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-51 \\x817894c055bece0072633d98c51341b1e21b50eb98a247982d9f46760addf45c36d6f3a9d074a9afa324a95ea1ede33bb9eb8ac0d835e27105de47377a8af7eb 1 0 \\x000000010000000000800003c89d99ba5ddc4b0c8d63bbd77e40882535cb6d47bb6df5473a6e49c7cc8019ef3a01fa62ba73018559ec4aa278e72afdf9a721d1e05e77d38283bb9b6f42dd874d52b44709d9272bb87b1c5978ce99d9e37b4cd31018b723e25673318cbfd30fa7dee250f69ef325fba5e7baa87843ecc3183afe3cf993d0ac510d86ace86499010001 \\x6473534a1033a52627fc4555a9f9e6aab98177ec7d862751ffa9cc2515d89c5ce91ae90c9a9508c2cbeac0288b607e6de708c3b95f9297f0f638fca6afc7af0f 1673170867000000 1673775667000000 1736847667000000 1831455667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-52 \\x83e4457363fa9fb27f77aa7dd43841c9d3768b756ae79fd1dc69c849db957cf69611abf1660cc83d5e135348fe020506cc5613e40273895cf08519305b66d3df 1 0 \\x000000010000000000800003b28d91abd26c6441eae17ed9b32f355533d36976bc59212996d180032418f052e5a31e4c045248d747b8bbc9d3a315fb69feadac680c63148f18749b2cd03135dffc51753cae145d14242f910549610946de128ce0a68fbfac893c9ceb60eeccb31883f60e162bf668b79b3fa489797fb930887a8c3da869960199ff625610cf010001 \\x62e5a91f2638295fd8c73414c73494017f83a8cc360fa9446bb5b4568c94d481f17dee25341b14456cf869acd103fa2f29011444398e3b2acda898ae628a120c 1684656367000000 1685261167000000 1748333167000000 1842941167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-53 \\x8b00a55bfc859d7a0394a9fb691ea8c8e35a3bae3a3b6592991fe34dc1228facd4d25f011a0c60fb458529c82714f92255e5ca673d6c697bb32d09b4964968fc 1 0 \\x000000010000000000800003cbeb921fca251bd90413a6477c30120c6b0e3e09e018d59ca1cef48ee54fb0d02fb7db60713ca2c02bd766cd93d425d7cf80cb7b4c7eb71578b3a4f682df372719fdf4f0f0fa68f069cd72f3a9cb0d39a84abe0d3e947a5b0c956b02a59aa5c5a8f55f8e60f11a4d59ef9dbbdbcdc2c04bc05e749f7f0a6858afc95c6ce71e23010001 \\xa589b9dad49f5c63a1a181ae4b8e59ca3770a24d7fa344760f66e04b1001e0b7d73d26804e9084336b9922b05adc867df6b845200006f18df764021e871a9800 1678006867000000 1678611667000000 1741683667000000 1836291667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-54 \\x8d0028b4b7f087f11ab98b5f65cfc5708d86cecd2c58e6d27dc7ee0e0f35858a14572e6a5d0337111ad90831dbee0bedb03c0788520bc7d215d9834e31c72b75 1 0 \\x0000000100000000008000039ad2b94d356a441d29e6ddb32ffcbfde9f81d961c8974d189f81ae6cda7a7299f9480188b663fb0ff7aee41cc957b8b259a3bbdab9d11aa89ee8fceb179a38be47e1aeabb9c7c0b5b14b2d17fe3a52c5c5e2ebaba1e057d7cd6140fe463ff5f37853d034a0d976d8eaa9cc6b94a6277c8472e2f1a049dc3adf8b6f54c19ae87f010001 \\x8101e30429a1c46f83af7c2fa82aee41461a8e842ce709c4cb374fa7ef604e8da61697b9db844ce71ebc5cb9e96a5ff7de4b246d67562c4c822dea65518b460c 1684656367000000 1685261167000000 1748333167000000 1842941167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-55 \\x9490db74a961874d2e3165ae963e787bd7be9f96b978e33136f919ccc2e80d0e345d0f0ea32355b9e0c16927758f64bc3f792d694aa2deb6969bac637a59d6d5 1 0 \\x000000010000000000800003c468e65da2db112cb685a589def1d6b3d2f1c0e84dd6707523461cddc440783c7e180b7e0e96377a396d121001e3fa6b1e0e50b3c9f27b13e589928753cc91e9ab828b94fbf8719e03a91316a21455971fafbab7f1c0a7a0baedb8ff3203521c33d9f42682bce824e809c6a0d178799853a932e1bea81084b794563dd4be0325010001 \\x529a0e91ab22e1f6a93094e09a89502658f4f948583507aabb1583488ddf4bfe07f9160af3cfff3ac3dd3b12d79f1d0410ade90b16f47690fb5cb72933c8e709 1668334867000000 1668939667000000 1732011667000000 1826619667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-56 \\x9734c939e1fbbaec0cd3a28d63a0659ec8c0dfd035cbaa52ab9ef0f7fc66f9ba03ba2f9617e6ae5a5a70f32da8a90efac27b244329112af6dc58997b96c52c73 1 0 \\x000000010000000000800003bfdccde4bcbc718b227ae859de5ba77898788cb17d11a0df212813294f6374e997ea926124cc6419f0eb021b5053d44c0fb2de522f1ed0c4af22f123b50c781507bb16017721a0bf1e457640258e6cb52729d79f622a12562165b7c8c7fb29b0eee82a4afc8140ce7fcf2aea6c8ce404c719e299ecfc6baa044a6ac012ccea01010001 \\xdd0ea52098a91815c2319754a79a1d453160844cd9bf0ed7a68c64038f64fecd031ae50df6abc771261654795ce3e9dbc8a12ee789d9f787a71a25faead80807 1660476367000000 1661081167000000 1724153167000000 1818761167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-57 \\x99e8259eb2acf5546f91096e742941c4d60a2ad091cec8903366ec400d2e40a041a1e6f21b7a6261e354800c088fb53e9f52ad4cc6641dea35e5cd6f53fe56fa 1 0 \\x00000001000000000080000395ed94090c297c46e9049849971fb588159012326f50309a0ae016b8e1079d990d76453f4925b6addd5ca078c4c66ef75bd7ec3220d245ca9ae3a8e3751d241f952c70623a3e96f693db75a71f3221219d9a9d8bf21aa89ad8ac45760985a18a644ebbc3ccb1e6511b787640ca788a95939f4c3d69b649ea3e4ec0497d6a5223010001 \\xa04747f54f7c0332b532167a81865e2b57f0b406778f2468a252f45a6958b61aa4a9b385d674709b86d5bda8c40299a02f0991b2f1a58838f078f130b8b86502 1681029367000000 1681634167000000 1744706167000000 1839314167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-58 \\x9d6089448245becc0bca00fad97fb631287fb1f0a028506845f955922af8f6696d07dc68afc6b17250e217f9c81350ea67ce9335ad215a46325d0f821b1482a1 1 0 \\x000000010000000000800003bc7520f79a85203c48e0dbeefa6b8d829c951a90bab06e7ed9dc593826474a7801e1247e0d2a768b4f179cd5de8a1682a2f9c39b891d7163244248d6207d5079893760039baa634086a29c83f1f63180466cd82201ca4d5339958c27e9a026bfe6750af58fafc403940faa8a30dc8e093472603e420fcb5fe8dd02188de2015b010001 \\xb95a8f8eca93c6726ed2b42b524826d9c991e535989d46c21761c9076b2cfab5c87ae0cce8d119904dec4a26931bd6f708c1b32e62929bbe1e667684bd0f190d 1658058367000000 1658663167000000 1721735167000000 1816343167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-59 \\xa10cad68dc6c088f9beefdbe820b55a30e5cc6e80153013506cc3e1fda002e7e62ed18bfc640a04b75c5f7779dc94f1c6b6a11783688e010658a2054f1ebab36 1 0 \\x000000010000000000800003e1cc4220066c6d6d9c245db05961ad4cf67397aff854fe064c98a779434268f161dd2a630bba39b8eb91bd00a4eb9f81264991d71e4a3cb855ed3cdf545a85204ca2a01e7ccfb9b03ccf80140f0494768ea2028ed30057228344408e2cd384ea7df6150189b2f166c82981717fe66aba34fc7516b1d3da45f8428de2c5a5a40f010001 \\x23a467caed0ca3d3127232918e9ade5bfd2739874f83cff166dbe1edd8f0bada0fad8caa42e174fa29ee7db7d1f5df9b4173f7866595a854da628791651f760b 1658662867000000 1659267667000000 1722339667000000 1816947667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-60 \\xa330919023de8bfebdde31456c1c05984c9e0581ccda9ff2af2071e76579c92cd2cf3dc465638e09decbf17490e7b9aebf5165237d797dea742ab72b71b6275d 1 0 \\x000000010000000000800003dfe4702afc372996eaa6790c6b73f6893ea5805c204a2da5fa736e9d484d701220bb5c410606831cbb8a7e0e7c472a6c144cc9e074bc256d9749a2db812ca8d7dd6fc82436a71b4f7cc83186e30bd77684762629b6758e1a2fdaa6b00a68c0b524f74fc7bbc4b38334d762b53dcf908d6b6e9799d1c3e8982bd8203a541f8c59010001 \\x39cfe46782cddf3a2e2f4791a12910dfe003461248e2b2cfb61366bac9542794ed43ed19f9dbbe882280f0f065b6d82c138a34f4ca5c29abc05cea4656e65500 1667125867000000 1667730667000000 1730802667000000 1825410667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-61 \\xa7dcca057cd2b1a127785e37d5c3688d09bed8f503c8723e2039db20a552408893dc1668e9de3b3fbd50f290a180b702b51e2380be347352420808e267aa7bab 1 0 \\x000000010000000000800003b1738d14b51820cf1954da46c20cb2569acf93bae75f927e2f4b4fdd39bd4709df6ac7f3dc6a72dfb7e439e5ac261afcdf58a6cae0c7c61a2c59801bb71ee0423277e8704a832a22aa17dd00666cd920f81e003e785e01bb79be3a3f156a5897f27991b10750482bbca978408f959e907920e996ec19c74553457b58643a191d010001 \\xa38457ce394df871fc4c2792f8b48598b7097166ca6c32a01738d16654970a859ad3da349bfc00e0f2bbf776fad5a3e298c7dd98a3d9c97e3af544d45dff0809 1679215867000000 1679820667000000 1742892667000000 1837500667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-62 \\xa830e6f37076ff074e57e6c2a287d52c8018acbd8e1286d2c7b89e68e9e67bc4734f4981fe91f1d91f536b31dad16d547350d8e29e254215e66fd1415703196a 1 0 \\x000000010000000000800003be8474ca7bd272994bc9d442be9cd1f0e5ebe7882e6f04b1bef94c80fd917007061150eb06e30671904c581a8ded994e037247192324c801fbe4902aa072ee97fbc3a3b4838d5bdad96813f3ffaecdd323b4472ae66d597939e6070e15ac1290324bc7764cb0df7247b762e278f276a4f70d1f12bd9753ea4e21d278ebe6aedf010001 \\xb197801dd090ad284242dd97d3dc6340c6bde182279049c375fab89767ffd738ad598a62f5d99216a2fe6b6340111687463afe80958952e6b88267b5bbb7250e 1673775367000000 1674380167000000 1737452167000000 1832060167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-63 \\xaa30f31c44a7ac45267df4452a8d68e8a0817bfac92c4fba6dfa5d2466824527a1ba2749dbebf4a6571fd6bc1c3f0790274ee3f07c3a3bad24d1a7a42abdcc9a 1 0 \\x000000010000000000800003a0621378ea2adc8fa57bfc0d5c54a2d7a45d66a91339158c065109bf730e305816b75f1b96017ca0f916d983c37b362316736301e5a97538f941fcc795e44bdc4e8e9999b2f8b5fdf585c628414db6f3f5395ee8a1ecf3bc05664c374cde7d0cd94e50447f8c3c20f4adb340aeb69d3d21711983f442aa470784b0d4f5480771010001 \\xe8f8c2734f7861ba85886bfe7884d91d49149ed6661b7267b524db03b77c88bdbc5a37727214e12abfa7dab166ce2d84a2319fae20c6af8025f8b182ff83c20b 1662894367000000 1663499167000000 1726571167000000 1821179167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-64 \\xac6826fd8865e6fd771d29c2403d3f7c8f7be44345eb3c39335476042ac7b7b3928a581cb0b7075e142023127193008a3db4621c9dc91aa56e781006c9b891b8 1 0 \\x000000010000000000800003bd57c161f40171599f92cdacf3f462aecaa6855153b6f203f42ecb4d92bbbc42f80f65930868d64cdeb87fcd22425f692a6444fb474545643b96d03316b382b29c8a30636761a1cbf1459b68a33d3d5881d2a6c275f64cef47743d338d78781766158445e2905dfca3cd959d9b5cc8360117b3e644205de3b943bfc5c2286b7d010001 \\xa3eed78542290760aaa45e6e8a9969573ad0a20ba6f8bc02bf92fe9eb87ecd902697c8acb409a16077095f8f497995accfb340a88340a50e20419c4e52b59103 1673170867000000 1673775667000000 1736847667000000 1831455667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-65 \\xad0063009fa923c06ac5f284db1a5570d8204b29aa40de107b86ad6b181c1b82e8419084025d45398b767412117d45ef1ca15661001ee6ba15cd0101d8936238 1 0 \\x000000010000000000800003e5b0a7cb86a6a9fd0040abf71b106079d0d92e2e709d89ac1cb7e6888b76b4c6c70e39e51b3cc11bc4d197dcd63176e79857208047a6659c4ce27a10b4a4168597f33adf45d24ae9b600ac59607dccc86c9c06cae43f328aa50d4132eb97ea65ed97632d3912e1ff7c4b703b1f1866d173fb69b7115ef9933a5988c3d374255f010001 \\x37b432123d709aa0af547796e9064471bd45fa0122a0907d79df34c29b8404809159c75b88df3c79cea86135a96e0064e978aacb0d6d17da47558ebb25fa7e02 1670752867000000 1671357667000000 1734429667000000 1829037667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-66 \\xadd8ea3b9d2768cae70a410ef0b0321383a58505197f28ffefe68821280f4868f41edea18383409714d98193ba4c469714da40e328c072989294dfb45450a39f 1 0 \\x000000010000000000800003b72c9e040d21b6bf6e2b4c01525b81aed5d692db440674ae0e212a9d4b9bd6d6159a6816f95aa98a7cfcf1c344523b9f77bb68f48d0cdfb36e621aec17cf29f4c75378b8ecceb3d9d588a54e436b00e652011d072ccaecdea1d89e6e72a4378a6a5a0a7690f22496f884e875aa4fea40839185e87cf220959a247e55d3c615e7010001 \\xf3494091ffbeb5f48f38cd3c78154741e650667b77ac8d2a109c971006801e359902b29a0ff9d5a2522c6b2fee95ea92e412f39aa70f10922c8d6022ea7da80b 1674984367000000 1675589167000000 1738661167000000 1833269167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-67 \\xaf48205807b428e8c93fecd4cc54518ffab47f6ddf6f5e7d4b3654726eb1d1edf2a6272faf57724f3b1dc5474e01a86f48618e1c3877a5c6424eb6e2cf3f5975 1 0 \\x000000010000000000800003a9cf43ed433e0f9751ea687d466e6ffb02768b7733faf6aefd96658c043e8e489272fb1e094aae67d91a0997e6e5c030a0737340d2e481031bd8899e30ad7858a7ae8eed6c84a85c09b77b835e4b8829832b5c7bef5164b4b03f4bd078366557d56194b4763c7fe9747e8799702ddffdf0bac401f06d54d5934beeab6cc75b97010001 \\x6678a0c2e6f01287cc8296f0c8e0e163a422372d26c62b50c4d2c09b407b2e302e819917ea888fcd0021886f836371359c919e63cb4427df76b9c24d87161607 1686469867000000 1687074667000000 1750146667000000 1844754667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-68 \\xb6b03adbf5f7e1edc5c8ac8072ced679bd68557a496c9f8c41b1bb109d6b66f8ee0ba96649ff81ac57d456fb451d4c34c73a26353114663c135b24cdd42b16a6 1 0 \\x000000010000000000800003bfb74ee0b913a681007de9250e6a8cf0e57d65dcae6eb23ce0c2158355e89624f5a03744e1140cd8a501e274891e0fcb9d3882e7c62bac42062871c72e10abfaec282edb681e3ebca9bed9838f6972df3aed46da2520320d61a75400944c7f9b8c4d8755b5c2720a6dcead8d71bef146c589bd09a38f0509088b2c09b8dc91d9010001 \\x99bf806b107b34f69d82e9c327532690b92b9445b497fa34eb012618e59e8278076eadfa86461afb0801b50a2889f8de1bbd064d8f0f9c63ce45b0355cb1d505 1664707867000000 1665312667000000 1728384667000000 1822992667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-69 \\xbcf8f943ac8078b089cd0a374f778eb1ab06d2ad14d499b1fe8d91f0c80ee1831b4b2fb6ed1ecf184829be2eeb06eb6c8c1cd135d4a6efd6ac85944d479a17b7 1 0 \\x000000010000000000800003a60643d5c05adcbd277e356b5c31346ea58f2e3addf6cc1e6a19cffa56a961047e298b1dc21dc13e25f5556c7114f4bfb19ef0798ba3321fbb2ebff66b69ca1280350215b7b43bfbbf9297e980f228bc69934831b8a4eda1b0f06fadb34318ae59e4013a5c231b6c5385d06ab098503160c7c5e0338f6d01cb983cbf7ca0dc53010001 \\xc80ab30ea9b83c4a7f2d4d6fbd9784b03a18a7133a102ce9edd713c3e44d32ee0f01aa09615125f825681f5a465d2ccd38037eae5e0a2781accdc96740879703 1672566367000000 1673171167000000 1736243167000000 1830851167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-70 \\xbe78975cfd7150489ea1fcf0e355ca676ea18a065b134c7e452ea1fe9ad60158ce5671c910c7ba1b3fb377789133104e22e317447ebcd4f8a7c2830c176b5bde 1 0 \\x000000010000000000800003d126920b0cd22f0c430e838eb3d8a6ef075bfe90eb9edcb81c2511461966bd60098aa867d4768601e59668fb3fe487ccc04ba7d5ae49fbaacb7313271619d6e8b8d52576a95e77295a08f2a6e85d85272eb23e1806e2070b4951fa0dd6216a0bf45caea8a5885197b1a2eaaf5d2b0a4e598dde8a0418845831c12df8f3187ac9010001 \\x47bf2b59e4fa296c0eb26bbd69c0d13d9cc71fd8748e4261d4f3dec5eb754ef6048750a007b87a8717cb93ab9b3932475eafae4304d13fdb7f2206c5cf59170e 1681633867000000 1682238667000000 1745310667000000 1839918667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-71 \\xc0fc594253f7813d755b5c070282685a2673c130cef75e010ea150f629a54de68170a8a2966c45b0ef163eb662cb67f2a78484260381d3769f0c8fff701ce8a3 1 0 \\x000000010000000000800003d251ddcd61c1930bae12b0a6348c20832576a1b83474aa4c9cc416a5e61d8b47c5d99610bc63df5a7e791feafb406e810a6379a911b5265738c71a0c40c2a4b720690df3bac7177d90128208741f64eb5a13f39f4f38d560b73627e58ad3037cbf0711f3aab98ef70c54535c75da00a38c1cf2729956de4a05c6cebbb29be629010001 \\xdf2515983b416d9dcdce7d26d0523a1e7efdfbff3d5e44ce77835653bcbd9bec6cb6b021f5e10e22075f38e4c829963609cd40b70203ed0bf564f7e07d22bc02 1670148367000000 1670753167000000 1733825167000000 1828433167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-72 \\xc320949327fd1b246af423e7594e9187d89cf57a18e495745d050b16256494a224c74a05759fa34ecb0547cbebe6cd02076bad7f74a91f0ba94cf37ab3acd803 1 0 \\x000000010000000000800003e6463e2e05df624083747cad978993ee5b80a5945d9d375d5e9c2668baee3914c444c135d6919cae8c1283bc89a9762d89e81a1dccee9884129e77acb13fabb594ab95142aa64bf9bcb6de461ffc04d4175e6778694aa52d9c1de37da30d2e0476e35285a2b5410bcd5457c1c16fad03a3048b5a12fb2c16b8fdeaafe73d910f010001 \\x7c8227f3cd52eca39263a9552e79da1e28dc895863dec4d092140a14b777ddc8a947593926a740db874c815aeeaf763c648e5970793b514192e69330ab758d0e 1674379867000000 1674984667000000 1738056667000000 1832664667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-73 \\xc3847e542883304148fa214447a1cf60133c74a74866cb0eab9d9d3a17628a9518bd67b24a6540c37451524d057c887dbe8148a4cf982b2e338fac77b424acc2 1 0 \\x000000010000000000800003beaa1eb6fa68f1db0e297e63108f0e3e4efec4eac910ef6a4848c00d96fb72e9436baa1e9e521e3e17632ece6f897f2e7b1ff2ba055bed9a047d97a83ee1caf7f13c178c6dd2402629d7e239f3ecafa0d3cb5930fc90b5d664819797013cbc43db82e1f06065239ef6e51fa23a867aa610c76c6c3ba1fb1aeb2e8c687fdb0c55010001 \\x2cd0006b5969c047e1eacbd70781d856c3ff486066a03afc282255a81dd7fa402e01226448a326076a182ea8882640192f4e0fea9c042cc58e60542d727c1d07 1667125867000000 1667730667000000 1730802667000000 1825410667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-74 \\xc3e06c93be91b5c409c47cdd040f6d60c4257bca6ee7856fcd10e073593d205ce6f2810a78dce1af11db4c44ace5f255593617cb362184eebd4f9efcca110be2 1 0 \\x000000010000000000800003d6c42a8b93a606be2950ba3694d3a8356caf748490da38fcca18dd95c6b2e11df91fc61418e5e52d433a0983d7398a994ff208bbf191db371165f5f44e49b3413bfe7690f1c00e87c942f8c0791094dd88706014bf90d66d64f2cc05428588c80db7d2a3266abba617abeb7af2e27bedaa08f9655f0df0ff70e5fa2ae4f4f79f010001 \\x09d6f4e83e905b69a51a7b81faa93067dc6a76eb23dcd13053275c6ff590ddb93c71d676f38effe97430f08590cb9d13d2e263e034154abc7478fffd12129604 1686469867000000 1687074667000000 1750146667000000 1844754667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-75 \\xc6746d90b5109f301ae63e6f8aad3eef0c8b28a31c672f378b7be3282ecae47a1d52df639e8aff0e8ff8be53759729c3d97f1fa78890c8628427e9fef5eb860f 1 0 \\x000000010000000000800003c806e72c44c848d456d1eda2a61de161b6ddeea408ece5e1701a617ceb6f231930d6aeef0abe23b84d7a65f5a12b61d09c65708d472ec0dd5bc02d6a855e3b1481db503cf5eba7a4e4d2463746ceb36b8d02651b217b48860b0eb7be8fd8b93726535d1c4a1f4ec4cf0ce64792d4bd8f0b6306b91cae5a1dd57e0e324df8d931010001 \\x811ac06754698afa0c2d3887982be4dbf3baacd154d11b7fbb6b2e1074b93a8137a97ac15cf70f146bdb9d475bac877913a34865ab7b93cb3324fd7947778d08 1664707867000000 1665312667000000 1728384667000000 1822992667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-76 \\xc78cad1641fb646c8c0504173094f72a0b15d0834675b04d9503fc335056e7477450e4d9504ad5839d3595327d3182c30f6300856441d8ccb55fbaaaec575456 1 0 \\x000000010000000000800003b7894a5395f70ffba15569c8508ebe90e94dd19b70bdf17bdb695770aa2b5c1c609c0eccc87f3a2fef43b3840402e1074e11836fbea8084f147aa05b4a69551e3db85ac8683710e19181c73ace1cd0ac4b95629bf39d22452c68d56b10efd427fa2d79b66cb0c7359f8a135edec4803fc275629a70facab153e24d15110821db010001 \\x2f1f760a4ba0e915c86c6d07583690f5dc0cd21742f1496cf7ac2e98cf00c1e2f60e503362ea2e468e6bba320e6ba0e125967c9bccd91e4ce5f6f3b875308c00 1674984367000000 1675589167000000 1738661167000000 1833269167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-77 \\xcb48c3ab7c81708aaa7f050e94c10bd794a213730ae9599c2786235378c4214f82cec647f68d6dbc5b12aa1530f5eb70b1911803616ba9846e7645570577fbde 1 0 \\x000000010000000000800003f2634c84e63e929ebc3628ef65c92d6082a54664eec805964d1108af22d82178c28dc58a7373baa667074e0047a022ff067251e099e829baa8a6c03e6511e61316cf7845ba5751bdf5a91d682a568047093068871db3ceb8ac30755553ec1bfd1c9037605e37a6e93bec5436f63413c326b7b377a73c07513802382ea949f8b9010001 \\x5dfb8810029d47fa9cf4b0e470e0f0ae6ac68a9b6ae3ed67d5265dcec2bb54f3414f65d5e61e2c988cdc41df7433c48740111eea57df2b6b381da73144eb8c08 1663498867000000 1664103667000000 1727175667000000 1821783667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-78 \\xcde4f0dc2640f6a6148c7b5cccc1596b14ce9d89e646e3138750356086427e7ac56e8bf5d7f2b4cb3617a748fe5ff1ba4822509e42d8f52559769c2c82903d3f 1 0 \\x000000010000000000800003c0e0d74a7eb35c9acca3158c4bf14b139e97a84db01dacb4e54cde1c74528f67e0d03059a4f8ca03a033b37c93e9a03eff2bd595ac1e5106d953312c74b2941479848256d64b30220d8fd6a0815fa8c270f443b91d09bfe72fe381364810d95e9f9c327e6e145db43751425a77912bcf6673f069ae35fb795fc282d420c2be4b010001 \\x018c30db2226bcb079c170d3a724aa89fb431b17cef51250e4b1dc29053cb0a42d73e9bfa3472c3a018021ad35047955f7fd8619f1b0850d2309c2520c13e004 1658662867000000 1659267667000000 1722339667000000 1816947667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-79 \\xd1d8f1e8ea84cced4be7a536471c28f2508e1836f006a769edbdd12a644cae7d4148e848811d9caf1affeec80b3bff89bf8ece91746e540b652017978edb779a 1 0 \\x000000010000000000800003beeb2c2b7d75749a04eef78eb88a2de5b2bc490a5296a375da6e5a523c3cf4ff36d8ba70b1da38c1f33d41e328631bd66ec3ef7017f2eac9457c48acfcf45376b50a00feba5655f9e420627d498f587603e26902bf6d7199a190b3e3c6d3f9e1a6517c89385b9267a60f78a9eb35368260d20535c3f893a5202d39d3046634cb010001 \\x30ea78ffd7631f64226968ff257fd6fd3085ec3ea698aa96d14b0d92f90fff322b5f5e8e3c2129ebaf00c0f37ed81f3c82bfca39599512a7a679cd4afcb28a09 1659267367000000 1659872167000000 1722944167000000 1817552167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-80 \\xd26c6d65f8126323be5c6769a9d6ab676abc37bd0483e93908d3291a46a9b767b15857e83a85ba0f239c9488dd1249dc413f960b113d436c13a24c17a78f6807 1 0 \\x000000010000000000800003ee899309a2291bb1241ba9297a4912dbbed5ca718ae7c6b8882ec04ae91d8c12b179de3539f849a28082bc71a3929701803ae69f7c14e877d77c30e97534a6ce09dff706b4a0ce94725ae2af7de3c3b2d03753961d4fb9f718eff9b22ce6e0d174d7500b5828cb197aecdb63f94c905d7a85023068ed6899e26a205bcf01a527010001 \\x86d09e9c4151c5979cf83ad3bd4a69f9d29c5741a272f6a77d07a8b44e594cc8e6d922a9c59120d13c38db75745bd385ee4780b63b5d707cfbc3253b8f98b108 1675588867000000 1676193667000000 1739265667000000 1833873667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-81 \\xd3dc16df7e84df873d34a160118fb6aabe53e312ae4e33665679d340e6780ad72764f99b4a3dcdc1729d80f2235a1bf6c2bc5cdde559dfe54e17855114c00c40 1 0 \\x0000000100000000008000039de5d3316aea05bc572e6563a806731de32399288c3fc00cee1fdde013fe90b59acaaf3f1ff144586282e289b6e4617ae4688063f35957efdedaea76206ed9a31abcde9048fc2693f48e634e23b5baafb533f7a22884324f7433bff93ab62496e0a57527921eaf9a34805ef906f77a3668b0fe1408275043aa8b55e575eb7ec5010001 \\x837b24fa6613d795adedb1ecf5c05b68ffd4285d433e62493829e23dbe20e4b7be1d9db4a279d5c894f4b22cde48870ca53b4f8536e5074d425e1a72fe351103 1687074367000000 1687679167000000 1750751167000000 1845359167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-82 \\xd4ccebd1478fadbb6fd12087e17f6e10d1f960163b91a8ef28403b5a007043edfea51f6ed74f56f1fbd49f6c18512854816f7940d00a086452523310c5e13127 1 0 \\x000000010000000000800003bef75ba75abfa84bf98a82b9fbf825a447e98052c3848a4d5d657156b4e845d4f16b28580e0708500222799fdc0e484596bb0fa37088c40ea3843b0fb203332f0adb43f51ce0896ca78129fd14a02c1ab36764250ab4d5ba06714680b9f5fffa169e26dd0ef6f49e285ae786aa250d3f770f133da10f688cedef6d092c16133b010001 \\x6046f0b2cf42d03523d84fdc5326487f14193badce28c0e433c88cc8c8bda41d0cc106b5bbdfaf2a68d1d8d36664e44a80f7b77271866334d2dc905ef087250a 1660476367000000 1661081167000000 1724153167000000 1818761167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-83 \\xd5f4cbf8ccffcb759ab146a3486a2dc2c0be276076f94a82cae9f1db9a1110ae20e8008f54d2d29907c57e652a64ee7e1e3255c3209b00d5cbf3d76d1bb19674 1 0 \\x0000000100000000008000039cb5c90ccc3aa2b8b9d2f3c89f728d5738cba31f2039c7b1b090910b9ac705663e9152c539757e05153eb444c2574f0380886ae16f633e91f1ab060b4d38aca657429854d98829711ee171a3b9b8764e74f5d6d8a4ed4443598abb1372fa2fa3a57b5ed33a3155b97683c60e48267fc63f94dae1eb4edbcce936171ee5c80981010001 \\x8237db8edc65473ffb962a9d7e35adac4cb3024024a0992013ec7c6c82bde3439d2f3e3e778ee5c0ceeddc05e9734fed084f736f63cfdbdb8766c41ad38b7b09 1657453867000000 1658058667000000 1721130667000000 1815738667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-84 \\xd77c639bc3c0956a34c4f26a96176a8c97643bf1b0a0382fb9cf122f218193727a5e5456ec3afcefa41fc0e257f1bb984e0ecd3e816a90b6a6510b5a07860679 1 0 \\x000000010000000000800003b8255e7f4fcb0336bbbb8f8e4ee8dab40556de1aaff20d8d2915be3f0908aaeee0ec85284e530bf9b0ad05940d3a51a989cc5a025c1e39356028a5c5f31d9ae26bb61c80bc1f3f53480388ec4a97170f8dfd684828eeac02575cd3c1f5b384a08124bc42e37394b80bc942e29015c217a458584f2a70c160503bd525479d9305010001 \\x68bb8c66c1a917b534054f0bb2bc0acc2a137510030fa68a7d1c456bed7c6a9c452b2ead5275183c8c686c0be06833f3e5a41079bc8997a2ea1904e2e594ea09 1656849367000000 1657454167000000 1720526167000000 1815134167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-85 \\xda2c51b214b00ebf6092d88a1fad20597878cee283a5830d237e9deb4c2af3fded5d70c42df78826e4808f56208614a4c5d70f1dd915b7f5afacd59b95debba7 1 0 \\x000000010000000000800003bb3c3c22ce064365f36f8f65e0586db5dc808a8ad10e2f83aa08df3247ccb43b17f77e2196052a850db5c4a88b788e5c237d27960c0ea0eb77f118697a8445e2d6c80702f476481170d595f1b714dc057939ea1fc7fe348af24b81a45ef1cfd1b21f205580d9990fe69b802bddc23b672b7090a8fe1e89c16effb74789481afd010001 \\x41c193556c00af80b04a8f2dfb8e74948094ce017d9187c25104635bf92a5974a2902f9c13044bd19a9c0ba182414f1bb4c95be48c161a542fa86f185932600a 1665916867000000 1666521667000000 1729593667000000 1824201667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-86 \\xdb48fa149c6a0eaf5f985d6db0c5dbef9788f6fe113f0c91f168256dcbf60f966af6df2a620ffd8d3d59fcad2b8395f9ce61f38de0233e18bb10d0f17df23056 1 0 \\x000000010000000000800003c3619dd0deb1c41f0c622bac9d023eaf872cbdfe544d3c60d0380cae7dbf02cb0280096114bb5e0468b01469de9a35e0778189e57d5b1cf0c2abe7458cfee48f12d4121512ada44085c176c52f0c58d56290d75b915be27e78a2c6e25a9e044700f3651f74dea1b991f517b191bd1daf5aeecfabf33b9e67ec4a286226e99143010001 \\xfda40c4260ee02e5fa82086e2d130f00c8c7702b56c6d23b03d0e5e813845c14b92414099ca584ba4d3521227d9325707a9d5e35058949d1f70ca4d32359ab0f 1682842867000000 1683447667000000 1746519667000000 1841127667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-87 \\xdd1c891c9cf2ebf4336aec442e2ac8a8c8f3aae17bae573e82fdef7c145121f0950f5abd59454373765a99df7bd504ccffed3101ca6131af60de47d6a0c1c45b 1 0 \\x000000010000000000800003ce40790239b3c86b1233b32adcecd491df31c6a951e118e9c4fc9eb4260da8b5c2a5ce0ee48b2816a454452720bafe25c27bc620e12a9656ea3a1acc14440bcda4671deab877e705d5e87ae3cb30c43a46822fd84f7a2c1347b87260f1a40c71391a70550bcd18a1430dea170a1d351a6c707a621e4925d1b6ad31f4e497b02b010001 \\xcca051f84a156d3d2cdbc7028295d749ddc997bb911640811cfc0c3cfba17583ebd58d0e82007dd4504102a87c66f44985ac463bd15bf0bda0c868c7ec3d8b05 1662289867000000 1662894667000000 1725966667000000 1820574667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-88 \\xe46ca06511d01c0a726d792ddd9f66757a78069ce37afdb35e50219c16262a66e9c37fd5bda23680bd21556569d718c585c3f71548cd6e316e74dccdf68936ac 1 0 \\x000000010000000000800003b94cf05db590e30c86ec1d6654c7f6c56baef8442d6695439e6d0df25dc8fc7a203c1075281160bf2c869ebf052347f56c84ec965d8776798b512530c77867a1b3e772a85f527695856438284601916644d741757895875f166d4b1c7404611af2b29973dfb77e6e024ebd5c33c4728b50b96e3b63fab502aa4bb3a849e0c229010001 \\x21d6632fde8bbbde9f401908762b2e37e3dfb87000131779b304ee4b06ebcca85c234d114e5b5f7b3a31708ad69cdf580b68b0ef71dd91ec246ab09b04958c05 1659267367000000 1659872167000000 1722944167000000 1817552167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-89 \\xeb608624536e096583c1d70a151207da55db264fd2402c7fc7df18e132f73b07232c5fe902b04cbb000d5fc27e829282692f01557d3adaa7f64f39c5af527e97 1 0 \\x000000010000000000800003c14b806b4131a6cfa16664b98d89c28fdbda25fefe12669098182a0f567a86fdefc4d8b8e573c8f6e74bc57d99204d21d0626d9e2fffb75307d185744796f3c3086448c6b00abf1b480c0dd6d28dadb29a6acb0ba6eebd500745fcf9ea1f3d19a1c35655d598c96cdbb2a78722584103efcb7c67d7889cbc316330a6630dcd8b010001 \\x1791aadf9bfe3f7817b6a08f1e05faa7cfec36cfe75100ee4e458847b811fa2aa7eb2a3f547cc83252ed4e3303559f5e40fedb1f5c429f7245cbde69addd340c 1656244867000000 1656849667000000 1719921667000000 1814529667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-90 \\xecccf735c1f4f0c7db00c2b79cc397bc3b6b9c6f92e3f66ada24b5e5c52762059759fbdaf020c925838013f4855a48a40297b6519bdf0fa67c82802ef3b01a37 1 0 \\x000000010000000000800003a4b4d10ba6ab4a5e241525252ef4adcced7da68d88297d0eb77930e57f24c991a32de4d5e05d27cd9f7f3392df09e59c3e3b2bdacc3fdc5beb6b4d114882175f3b0fbc7352160f0b4c1015066a22bf4e29c30f14fb7a33df711ef210a94444930ac90e522c14380d855ea6e7429962b8e5bf69353e40a25391a5ebd2294f502d010001 \\xf03ca80394f5cba304a88c9ca7899b12fd5fd85f5be1d70a15e996523f4b4c84c2c2ddc3f8f0e0dd695ff0ce551e052e29eb7be55eb8a002af2eed4c9403d40d 1678611367000000 1679216167000000 1742288167000000 1836896167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-91 \\xf1bcfa8b1357c8ecc586c70d87b89514d75bfcdbea910c9fcbf70b1f1859115dd89170f447ee89ba417ffc622b488c52ed3e2ed1d20bef7bfcf32b407f5d6095 1 0 \\x000000010000000000800003e1464e868ffc73b8a035517708c1995a4a2aac3dbddf616d909bfde027977b5f4439dba50766ace8375f049c5a075d143eeb03fabb4c9853afc23162273e27e989ca0b7e87f2bdfb44a64b89ba5791ee44952b4d21fac27ac43c6df28630af45c0a998c6e5398ae3dfd048c064b2b247739ba8136bd9dc7338537f994c88b5f7010001 \\x39607490024e177ec311e6f65cbba2707ce1a6824259a6f1e0b80bafbb9dd1e63a42379c2f14509c1e2705f3809364da6ca42f3d651b4127aaed7c2ffbb05108 1668939367000000 1669544167000000 1732616167000000 1827224167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-92 \\xf3a04272043ec72b256dca7b188f1fcaf03ed832396466ff851ad475130351e7b5afeee0ef206f91a30cf151307faddcb59c626463c66d5178f01e3afa717054 1 0 \\x000000010000000000800003bd7ece2e5b1e7395022ce0709d7a9ff41bada5e4f5acd8b2de6847ac86b9cfecd9667f8311bd88832279ed860d569d4176b6bba39bc73ac72e7645355612ae6c73cebd3e8859f40b377980c0d0efc58ce0d1ff5e971c430f0ed1773f44f6d75ed12a7aa80f4cf815f1573d3841ffd49a3ec7b4ab1bc5cba9f6da1d3bf415dccf010001 \\xb387ce9f9bc43d46fb1ab77d3c75e793fc2ee404d22a620eba83eae45a809f2b8d3ee531d7b79b77adb0dc3f954f0f6e992a1771e73fcc91fb7d732f8242bf03 1668939367000000 1669544167000000 1732616167000000 1827224167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-93 \\xf6787c832b76413e96eba859af3c9205e8ab95502224c8ba84f9d18a790045766c52652f514b1f20038bd69354e8efa89bba44042bf4c0979477aa483c0c59c0 1 0 \\x000000010000000000800003cff0ba339bd06972bd30312ff01a6fde7590dcd262453bc474a1a6cb8e5b5db4cd4d8ae4b6fe87fbd61de2e89b2ca94ebfd6b4062470bc787c0db2478138ab2fb8d6e67645342f61281222ab2cd904000bd110582286801c5f80a2ba6db6e4bb114970f57b2b4028e200d62b4f9c0b88eacb31e06be31170d16f65c433c31e63010001 \\x29e8c8f1e456e8fada8c47de5db53c34e3b92a9290f95b1da2847cf889c9f5eb7c6178b18bc5a2f81c2b2a5b6e2ac47a056fa3a279998f28075882a02a043007 1673775367000000 1674380167000000 1737452167000000 1832060167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-94 \\xf66070910751558e747f06fd9bb7a36249f493f8b3e645aaaa1640df2e9a61da851635b76fce5f5fb94d11d92174a393e0a6841fde05076a0347e6bf1a011787 1 0 \\x0000000100000000008000039c9af4c04321448b6ac1e116e9f74db91c506d10cce25504bee17ba235b437e481e2723ad6ac3ed4b253e30d277d6ec376b60ff46fd182ca5f039c1e16301c08ba84d2707afcbe49391e98f37558a3251793eefbc34e17a45316a0e2a006a7fa68e995dc41781237708935753544103c80a70267e990df3b3e5de07f1cd8600d010001 \\x4ffdaec8236b6449521861a8d25dfa94b9330abc962d7d1683eb9b90104ea2e69197fdcd91546e4a9e57befa539e7a2d44ad56f1fd974a1ca90a92bbab9ad108 1668939367000000 1669544167000000 1732616167000000 1827224167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-95 \\xf73c97b03952ad04c8d5f9c5516c92a53831e661965a052b1e36c99724fd266c8093ff012a4d596e068b6eda9f26234f8aa908b58484d8239579c26b1c795865 1 0 \\x000000010000000000800003c6c752ee0af15545a150a05634d213ed7ce1175695c1c40951d3b829b4dbad8b7cb058843c594ab4785172e3e5c0f31e44878c48701af2e3129f83df133817f146b29fb7b3ef59cbd916f12872bca36425d328e2ec034c1a9574d8bb9fdd8505facc1069ab40a2f1e2c51682a0c8ef141ae3d6c53d995c6d173f333bb1f593a9010001 \\x844fa8f3a102db60152f08d12f546505c9b41e03edf513f14c69f85594c55eab9b3f4a953697b324c87855a542f4ca9ff7ea81b3a694094fcad2181d0366d304 1678006867000000 1678611667000000 1741683667000000 1836291667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-96 \\xf95cc28f415405392edc61016d49a025272792b53eaafd3bead60b0a6461c5f3d4fe54d65b6f0d8181b5eab4ea23b3a4648d591d5f1a2a059d75f7d3de06d473 1 0 \\x000000010000000000800003b725ef576b44eb3b44e4037d821ca5b4470ea0bf50933af423d62dc70f36986f731f0fefe40cb16cbe2ae3bd33b03a2a9edda2411f28b981c125f12b660d72c79b451a4d97b7bb57e3ce864e7fd66f45a8342d39f36969dd7c6b774e3ea4873b0497c0db18f92b7f83a4e5b9e181ab382e2f5a551a6d45007240d3e8a1e9b68d010001 \\x7bdf1c427d3cfd0ee176f7f2ee98b29dc543d8881c23f18935e601c858b98eca97cc73e02d42f14eaaa0ccbe36c1463a77673536ec02e52622bf84884adade01 1687074367000000 1687679167000000 1750751167000000 1845359167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-97 \\xf994b40d7b534dc23a041aaf50d12c2bf824a35702c939fa38a92ea65d603180dd9e5d4a10b157a12691a6f07fc09b5cea4768ecb0631adb0cd8aaa9a4c09dd3 1 0 \\x000000010000000000800003b1ba431aa63ba0869ce97f57fb0a1f338ad9e3443a672682e4d4cae528ce35ba6dffe5c0d15aa5dd6e559a4d760c3af5bd22f40645ba314aa73dcf79866ef5486d11a1cf7897044d3c5c23e92083f22fa52c7ba86ab4f0ff31028960adc6fade2c420a79e2a6aaa63a823e8daa75c734e202fc40c2ae2367ff4690337632a2e5010001 \\x8d609371aff8bebc4837f52b9c9738c5b659bfd6bbdf90c3d717c01c90a731d7cb3432286c634ed8239e1bc360c77e9973af4a03cec0dfeb3c7a194a3999b501 1684051867000000 1684656667000000 1747728667000000 1842336667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-98 \\xfaac60d18d631569ff0cd9f6135d4aee99ea605145204f27383c5fd0417a731cc840b9de069aaaafd5da26f5a568a38703108ce6360fdaaa7d9501be2436e2e2 1 0 \\x000000010000000000800003c45501be7eade1872bb6585c703d5587d2e2c1190132c5576dea6aba2614669bbb9130725c3c8667ce01ddad93bc4abc27524bfd8d941908046b3748e19cda9c2b37507a3cc0a2d7fb7f2afcef95987c5b380373411cc18dbd5164c2a975d0df206a931fd73fb8f5e754e1d357a8d9209c73e50a2acc2717f4e3edd11f68ce0d010001 \\x27e93d631064b297f21b0ff63d5ef488f95d97ede3381062447a9094ba3445b18e171c2b1658e4297f27eebe5692e5b47e7bee76d4dfdfaa59618cf1554d5801 1685865367000000 1686470167000000 1749542167000000 1844150167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-99 \\xfdbc63ac73f31fd9b74dea0cf4f5dd98f597d051a411afb110350b435019c3190a3ff0b0ce6af652df1383b25d070f3e133a88665aaad9e8a6428f943369a045 1 0 \\x000000010000000000800003cde5f1fec3f1fb315a9b5eddc051edd8b63d6114998789a310c3ca3c1465c4d15ea80e8d8d7fc3a5e045fabb8768e6e14f2069b9d3a10db0e0adf5f4aa4ae12ca6941966633b6e73d8cac574fb3ba5d23caa486c8790ad71855133c3717011f4058f6e169db328b0829f4dce5b3907f1a080316870f357490854690ceeb7849d010001 \\xb8625cf7b91b47371870463f7689e1ef021070ca3660f1056fc15d0cf40189ac7ac8763b6e35be99772f9e99b4c3782f4612790b102deaa5419ee5bf02fc6f0b 1659267367000000 1659872167000000 1722944167000000 1817552167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-100 \\x05e9be39b480f6fe3f66da4739d39c663123b33fc786a6c2e8b9f3c6ef91d8253327f5f9d725e46b9ed64b244117a42cfa636cc5063576ac5d05c36c1bd72735 1 0 \\x000000010000000000800003b1faec6018cab4675b36446c8a252572e7a98c08d616a2306513a3aab8181f44937f08bea2f96683276108babe08526355fc0ac22fab6e09ec53c4fa58c458aa170bf013dcdadfacea711153be2178afc02c007615f53ceb9c3fc8cc51e93701e02190819fc063269db5c4584caca8a9f8208065471ee033845ffc7d74ac4ec9010001 \\xe6809316bb703b224697353d87c2957f16a34e0f1b5ea670d7d7c28b1fe769bc4c102690337a5d376954730a9b6963c5db53b8bd59de9d603cf0d58187b6e20e 1670752867000000 1671357667000000 1734429667000000 1829037667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-101 \\x0669e383d2538048fc4302b8eb1a2cdb991db9fbe01c6f1207cfe3b0def6b8278d47a494ba16e6ea92dd895fa6bfd1c8075703084e007315e402423a5ed5b3d4 1 0 \\x000000010000000000800003d992ceed05b5962322795dda08747817e9acb8b59ea879d3c46d37f5c502972d2a9527099c3b4b1270d151ab5d7a3e04ec7cb575b12850d6d9a25986ce9388159333df9da876e584da6f43c0fef4460b872c51b320be7799601a52de834c6e5759220d52e0e59aeed56f18327c7b7b62f757524133ee8529c40f6fc059afec4f010001 \\x9fef6af26716e125239bcc0ba450cdd43615bc48762550a9f421b496832b729c57b49ef7e08e448d2ca1e73709629deda51e82d16b7c5094ec62111db081d10c 1676797867000000 1677402667000000 1740474667000000 1835082667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-102 \\x06d9a1e986881d186ce3a1232b9c6c11ab6f4f806c348d24489226ceff8c97a73cf3f2a09f5579d408f6a1047d25a5eaa8a8c3bf2fcce37b1cdf6c38253ea2da 1 0 \\x000000010000000000800003d405bb273afa1844c92539647863850f745e405cf1ddbd31520de123c6af1b5973cab0ed6a327a8270c7de4d899d929da63205325c0c5f2231b19bead168af20cc0a0e8c616a086049c26cafedf022f24abfed1db90fca2a7891d52a825a70cbcebc8a35ccba08fd56f81430f132f43cbb76c0e3495b3f56cdea9dbc1fc30883010001 \\x8572a37cbafbd09ec31112721a694950336b374c5a11ae5e28da456e7c3e483e730606f12b943f9cb22ec83d3b308f3c91f69e0ee2264d6809eed8b20010ec06 1683447367000000 1684052167000000 1747124167000000 1841732167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-103 \\x0bf9979a814682cfd3ba04a4299489ad6565c289a38612e5cfbb33c10165cc6b3f1245a20b62c25afe7a1b9b53e05ba8287744dfcd63044809c7da89bb70a308 1 0 \\x000000010000000000800003c6bec0e5345050ba6387eeabba7d0d7aabdbcae12f522affb7dc5ca4a23154f9ee0e285d1d573af1872f84ce3922a418ee7e043cfe9ae76c50228ebeab51e90406f28782754d873ce04b1e53a7d5164503ad75883ddaea89fc8a98d287887e0163c416fca4287b423494a220ac990bb84e6b6c49317fb39aba69a43de7da79f1010001 \\x1fe66b7299e2379793c5cd996b45d07a861f58b4ef65551cd10f96d81351402d42644de0dddc43e0a075285920abd3fa4edf96ec3b1252d75d621cb05b5cdb0c 1682842867000000 1683447667000000 1746519667000000 1841127667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-104 \\x0c19e3f0bb0f3008f28c4eedbe6ea1fefe3e28411b751a180edac9082fcb0444eeacc0562f9cad73c5a40b7599e227b058f6eff0b7fc6fa6d56615a5d7d7d1fe 1 0 \\x000000010000000000800003e9ee9def153e3c495fe87a99f86aa3449c4e783119e118d06213018514f3340024143440afd025842406c6fee70d5d4d2a4da6f31ee4504605efce8fb4e12762814ac4130cc67858a4bf143818e3be9ada8711cde8843b14da78e4c48742f92328aa21a3c19826cf0c115ebe78b61fc27646093821b9d417f3cde7d32a50f98b010001 \\xbed2d7e08b61106fa51e8f1aa1e3c1c635cbe3f0bfa27e7ce54ab1df9cc1ec21144657516a027536f1ad18f63b84c785ec63d9af3e884ccb2992277c857e1802 1674379867000000 1674984667000000 1738056667000000 1832664667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-105 \\x1141988904b6dc7990aabbe036e0542d356c6715c115e51f28325802380fd52e1eaeeb2ab47653ed0085c188555806c325179fdfa393049c2da5df2a2985b70e 1 0 \\x000000010000000000800003bddda2500342b19ebda17ea1adff3a1cefc85b251a7ef08f4fc7df4e1176519e551cb1de43e25acd62189797da9b440737746eef1b09d3957804d2467c3cdc2d9a25453e9f288deee603e5ef15efca79323a0c4d9764666883ba5803a9016a9be5e0d668c6a7d0c92edd6228969d6cfa3852c929dd43088301f3f06c1cd0aa11010001 \\xe5f8e5ea1664a42a67ccd7353d0565044826b21cc668a8a2c8cc202b42298f9635606465358e7c9a7753ccfb7fbdb959b3c40dd538e9145c949d31e2f5522803 1665312367000000 1665917167000000 1728989167000000 1823597167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-106 \\x140da9fcbd7448468a55cfe1385ec75405085784e7aa55a0bc1a16c164dfed7e8252abf85c35fcea873b2fb645796ffb54d37e1755c11acb6c916e9fd3fc93e9 1 0 \\x000000010000000000800003ae76a07644311827aa55e7e5696233bc5121d07376a73264bbe11c03d3fba23ba6fd5a5240e74025d2afa72b2228966a81dfc3055d671bac652720ff544f248d18b039191d2992b66019392de46bb0c92ed4e3514b1a3340a2db9f1e1d9c15529c51603a3658549783d7b0e0b474e823177b62e6edc4cf168167bcbe810c77a3010001 \\xa54fdd3eb62d90bc21abcca33acf8034de4c642a905d6f8cc0fd0ca9982942ff93386c6ccab0385c137c1d5f7fa3a90ea6bb0cfb29702ea7ec3e0d30d6e34b08 1663498867000000 1664103667000000 1727175667000000 1821783667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-107 \\x18e9adb45d82f4ae2a82e6bcd6a24ef863442f77eefbc13edf96d6186cbc82ea4ffb68a1900d6ab952a74d4cb1bf3935093c307e5b72e096e39674d7221b0e49 1 0 \\x000000010000000000800003bb1ce02e07f94a2d0f0637e2382b4345bb7d294bd807051912467d92e7993395dbcd95e31d571899bea2c8fd163602ecab3b6220dc7c41d6ca609582255c93025778aed5ce7a687b538312edd4075aa1d020b52df96bd1a4ea3fa2401ce561b505fef9b8cc46dd31871b198cd8a0af42c38d107e58f3b15bd77d34e71eaf501f010001 \\xac99e604ec2a1b1e325ab1782ebd1ecb161c4530546a2cba8de4a288c16ae4c06bf9ada4dd599f6dcfc157e7d36fd67ab1475b12d99f7e32f86b853973f85b03 1658662867000000 1659267667000000 1722339667000000 1816947667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-108 \\x1ae13664d2dc4a072b7f21e8c34c1ea651c683809b67a82623983357e364dc252d3dc394348e37be17da539799db3219fe1049f8f1c01a8f2befe20c147517c1 1 0 \\x000000010000000000800003a3887b72dffc93c79c11b5e7df81a0e38e2911f902e414144489d49626160cb0e8329da649d4e78f9728bcb3476857860e55361d2e7dd770406e7312f1d7e6983657ead1dd13f8d19e95571b2d8eb0a758a50c7b095fb19a34ba60658ac3e149f5a254c18ee6369a69ac1593be1ea638647ddc76df369be1a38c45cfd37a7a77010001 \\xbe83c4967ed97d7e38024085f0fdda551f8d5c6e78bfb428f51e2159b47be71c93b29d19ce3882463395b2d3fc4a4afaba637c49897e36dfa2e0ea96171ef00e 1668939367000000 1669544167000000 1732616167000000 1827224167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-109 \\x1bf12c3787f67266aa5cfd3037f9d69e327968284f272ae03d9202583488893e6b8de2eeca7b9131ac0c32cd91dc82354e7e7d13fcba52f5dd3d0ab1a28ed7ef 1 0 \\x000000010000000000800003d455920cc4ed37589a3193169a9ee74e9352c30067e5759dd885215f134af8e3720f15afb72e78dc19185cd7a1aa3b1cb5cc5f948e7c7e68344915f1cb93fd3288b65563d8e702da4ba39c9837d4e09fa090001b9bc9d7690eead8be5274354ea2567133ca8d04eeaed9117c954000de448dcbbfd54281635871cbef29034d81010001 \\x640c6d1a039f5ca39e7373377ae68712da84fb96550068ee33168469da040b6cb978052630e155f7b15aa1528b73434d51b0d5fc805e252920f43548f9c01902 1673775367000000 1674380167000000 1737452167000000 1832060167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-110 \\x1e85d10c35aff8fad4eb1b4edcf63390187825e9905dd2459e905fc640b17d7bb5326cc7e8ea3a3abd394619a8c5862e16ff5c41244bdabea919b827f7c733ed 1 0 \\x000000010000000000800003e881dfc102dff531a86ebf704625246c71b8dc8a1729226e4c853286d9e0a003e66cf2d09c337b19cc291930920b58cda50407dd2a8e6d8d26da591e7876bf768fd23fcaa86b57963a1095fa5eda9cf8a1d4cf760c01089088cda704d6e9bc4b45e67a2d9bd65174b80fab096ec4d5bea69e1b6299dbd3dbb66c939d96c082ab010001 \\x6fd0bde88c84fe939ef36aa62b34cb5d84307b1f035a992b768025a4472063752e99e66fc207ef919fcdac9021f9803c115f363e33d0d5f1dd6b04c3f1104606 1687074367000000 1687679167000000 1750751167000000 1845359167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-111 \\x1ecdeb7b18c63ef9effd76096abc39994045245482239550ef089fa9c9efab26e7cf4d5573a054bfcc0114aab7199d91c0e7f0f11662bb4747c38df9fc080946 1 0 \\x000000010000000000800003cc0cd1cacc269222fe722849f665dab4579c2423a9d8e2f97f68dc11a986d9b5883d4d48e6e9c2567bc5b9d5c2796665b172cb43324b87e71c976d8a3d09a1239eeffc515028d88f5840c8b99793c855c4874f4d6f147a8f374f6345aa51182e3ad54bb13a96b52c13c0cc5fceb952860a240dc0c70a52d961518dead5bf2b2d010001 \\x6c36748ba90b30fca32c56f8183de86aeeccb1c03c3cc1f155bfa5cb9f686dfab2e1c1ee14015f9e4c8f013f4e7979aae15cc399e95b1566e97699572c1c6c0d 1669543867000000 1670148667000000 1733220667000000 1827828667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-112 \\x1f05d94db73cdb7f1b8510699ce3ff0d860b6f95d1b0f225df2ab16254d50842e02372a2c1c6533e1d9169ea09ae2da258f2580652d4cbc97629287d83860ea0 1 0 \\x000000010000000000800003cbbee2565e13c293023d333b331769a1873534f72f4e0cda41fb1914b97cd471b9752bf160eb6c5fa266656a5a624b8a629547712fb0ab80071f15fdfaa7d51c769604fa72b3b03dec691663bd8ae1a4a86848a79d33860ff35cf4cc8994733f81334af0199e34b12bfeed41252507e8b6660c98d742f062d6baac96b21548b7010001 \\x99fde4d9b339acbe9a78d0a6e6165ea3dba7af69a1e80ced9a3c640a2d531934e41d985e3474b37a34776abb4be9efcc14e634e5d979e141ec2919b7658b2903 1673170867000000 1673775667000000 1736847667000000 1831455667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-113 \\x2099201e295721ef90ea189d01be2ac94f716a865aba5310affe36bc8b943a2ab97b5ba7e7c951f9a40bd9e28a6674e56e4bb2fd96b6ee7d83468a5c89128f54 1 0 \\x000000010000000000800003ea2b1c892bd02131e8a03b2addcf4a7962922d313ec0c5e2f0860459b8183cd3e3c200c8a09b9b7a27e6038f1c8962d4cf241e84ce5f9824b7a39fee58d34d93fec172cc32233a32793512ec859654c0f656e8c01c2d9155d02a23b4a6e9d38b017086613e6990c346d6316d45c49ac4d9d99a64d75ff473128f3ff435666401010001 \\xe2dbcb3834541f57e390443eaac048023e8036aa2dfe141975dbfde476f4da00c360b6646853826509b27b24c303b64e9a6ab970fb9b4bf0308ee513b1ff110a 1656849367000000 1657454167000000 1720526167000000 1815134167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-114 \\x21f50b1515b4066a72d37351a2d747229c410c208ba54c4861e55625993668c9475aa281a6eb02a4ecc7b780e49bc5dc8bd6eabea8bb11121c7936b2ef914e18 1 0 \\x000000010000000000800003f1e4c937963eeec67beccefe213721be14fecf12217a30b62706ca68c2a1ae1d573fbbe9f07258a59aba5ebd820c62e0a54dab007b8c99b47b1c000218e14e53485aedbb89634ca6d2aa9bf87e34646ab47fce08ccd5ce02e4cfb85b2de4127b76da57073e07513b2f2ad70d561a8f43b145702eb2c39d0a478c16a1dce0dbb5010001 \\xd4563165a9169baddc2b00d524eb388be40165f2883126c878f01cc308036a201ff5f89a22ece74c75a12ee394888376466aa1b0bd8028995caaa10e40de4f0b 1679820367000000 1680425167000000 1743497167000000 1838105167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-115 \\x248d05d96143cd03d1f0965688bf891096001c965eef885ffc0e99e23a385ac1cbee16d8ce436fecad4f92508c9cb1fb16cf26723c7dcf459c6e14add275cbb4 1 0 \\x000000010000000000800003b2ea5fcf7979d59704a6472fee890a64e4d1300f4756776d9e2d03860f6291459e2e389ffb92907a50a1bfafa6ab933d59eea32067d11a653bf8ab45a46aab7274bf4c7675efb5852183b3b7d9043d5ee758d5d0cb133980d66205391ee31221434c9a5c18810893928845d971cb9775ab8359301f8d34cb2d4aadab46e67aaf010001 \\x5feab291419ff7f1c4a7b264891c1fc22f4bdbecd5539558133e95884b793be34f0170194c4724805a572ae776ddb9defedca3763f969e8bca2b5ecbb1f78f04 1684051867000000 1684656667000000 1747728667000000 1842336667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-116 \\x249516628e8e354c099a95b27f076e4223bc7246f3cbafd297ef137a80b6f1f57402f8942866327afe33e41771f2091524163e3e717a48349e900bbb57c11b31 1 0 \\x000000010000000000800003be2a876600c0c237e6e8012f63acc1d08acb7a19634dc4a6a8e341afece4bc2fbd86d3dae1482b7bd1d0affa9689b2a912af8e7f1a4459be8c0aa8803af7fc0fc5a4eaab1942cd103920c0bded5dc8f8dc79f714b3a13e2303d9ef25ae2a6258226b106131224053e94d6df79b7feb31f675436f68f97e71e261f5264c969e73010001 \\x5931b8c7846bac16eaeb8a1ea91c2e61f47093c0d9c99e734aafdd8c936cd3ff92095bf50d226523b87dc17cb64d558683c4b48c4dbdf15e6098beb259c12005 1679820367000000 1680425167000000 1743497167000000 1838105167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-117 \\x2dc11cd8b053d9c24a73f00412278e83b4592f6ba4e79bcfd5a9399926c2ed97c053d0cacdb5fdce874b7bfc2886b75b1d029060cd54d6e906b42298ec6fd65c 1 0 \\x000000010000000000800003bffa8157eeb85622050a89e1c7e6092b6a62dffeb03edd50b4701b55db014fd44de85815aa429ebce55d7b85f52be3f79adae42f01d3ee0939b7b92627ae5aff94e4c127c8f5d943d9a6e46d2a8273dd35ad8e6eccf48248f713740a419176eb401ac2334fe4941b5fab1f96f6c315a9bc99f185078dd754ad4c5b681fdf52ad010001 \\xe2ac55a8a8ef92dfd716c0cd50206c050f3adef5d1e466bacce1de7822a1fbf41f2dd501f5ac05366e5b87e9416eff6e1d7fb588c0b36052848621c49c293e03 1661685367000000 1662290167000000 1725362167000000 1819970167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-118 \\x2f5d2d377c41db8c1a0443771b54024cdcd5a546cb6688a9e73b26625e5f62cc5aafd84cd410311bde9545039dac4ce6c528d6bf1eb80c8f1fc23bfe532b4fd4 1 0 \\x000000010000000000800003cdd40dde333f2b8ecb3020a2f3c1ab4b7e099f4b08654513e87051b81d6060c823064a194119c3b1e429a1df9e70dcee411084af56bd04fe76052da188e573630819a8f3206a26a2674c8f0cf7bfc1dbe6c0853378fb906efae93a59fd3feb0c42feb82b609d6f9704f09b464d2a563338b0fc98f68fc9c89feb80bcf8eef1b1010001 \\x7be42fe2fbe773b5f35d24d27bda00ae628b27455f591756b5bee226b68e85f16b2d92ed2e3c1f8dbb9e3c6d6c84e3825efb85950df7f32c523e9d1e9153330e 1667730367000000 1668335167000000 1731407167000000 1826015167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-119 \\x30356b50e9bd87aaf20edf00158f75004e48f2cfc5e1804891558a696b67d55b308cff604cdbb17965f4a82d6823eba3e997c07af97b0399be1a536ebac87b74 1 0 \\x000000010000000000800003af35752a3d4befe127a492b1385a8a245ab3fde09f67b952f8848b2a05243aa933d2945eee49762dcd3544ad88ca94dc9dec6ee155f596f6e98d92a82ff3d914937e3e2475783aaa480d075d972c333178154507be346a9d42b03205df650ac1bcc2f2df877ce77e0d3666d3ce27bba0c57934f709fa998080eafb2cfb0ccfd5010001 \\x98fd7c9e0b78fd2df8baaad6a27e83e79aefaf036e02ff2b5f1dbe75b3c621ec8ab84ab07004a2c1057b5f74578e542d59f22149b12f477969ce64d453f90604 1657453867000000 1658058667000000 1721130667000000 1815738667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-120 \\x30913d48f354cdededf0f6a962bc21f3e615cb607d605bb91655e0bf5b3b249fa2b50a50586c69b6f652c49f5fab216d9ade95c354d2d2f3b367a04510f45500 1 0 \\x000000010000000000800003ae702073d121df2be5aacfc08c08be3aa232ecf0c245d2c99ce65aff10243faf94d1d9e34fcbfe076b96b2914e73685c5bb3aa359bd755a6c4365fe17925fa573353d973a1231c7d264af178c6a554b9d0ee2f92fd6b63664317bffed6effeb20b9e1db07f96fae1a2d496fcffab8ed1a526bb57f1402db5b69d54401b427a21010001 \\x03b797dde96e4f0c1c45ed3843c9e010b946f74c091336d572ae69d0c200d10094d79f14d5a6a3e0c1b439529270d5a0779501f39b63ba034b49884da7f94305 1657453867000000 1658058667000000 1721130667000000 1815738667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-121 \\x31b95e5e1c7881b58b8bd0f5b0d861f9766c361ea84af715f01b9edb78112a9580a6774ae323c269bbafd18ce08617ea4336411a852975f644e0fe8e0c989b08 1 0 \\x000000010000000000800003ec669798a56ad3406fea069433a68c0eb3983d1922e69ec8ad7954a4376429bd3c295fbfcb12b845dc6d73d3037ed431827ce38ce361244c0d885c5688c918f445b8797b2addf73b38981ed90f214fae63b3ffdf4e25e5f9a4c79a14d872434f2d3bafdc224e9735482876ee715cb104a02f475168265610e324ee4d0bcc78f5010001 \\x9530597e6e01c872c97617456d9f8a9b7792f3277c7f1345d290467dbee4cc6385a3706f0231efb2c3a6b98880356bafb1e7cb706ef30c5b46fcef1b04877a0f 1687074367000000 1687679167000000 1750751167000000 1845359167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-122 \\x32bdb058c79d9d4f411ef945c9917752565d68d5a5638a53d953c451bfde2330b2612b2b402883e1749403428178a0fc0f504482a15c4aedb3f9c3208417704d 1 0 \\x0000000100000000008000039f1daa9fe58c68904850d3c19c1dc51a1b06d906b19b6d9ec169e973ce9e32481dbcb0b490056f9ef7689ad9d9b21314ae4114f5ec73eb946ec2332c830c7021ee563cb83ff3ca9333d86e9da152adc6643ed2053c45aadad678d6ba630603973fd7cde3cb0444c06f55f857cc7a4f0472a0295c81fce3adee54a796458fb32b010001 \\x3a785cca72d0137de93957456f433ba87dc29c0640d2d01bdad0a0eca467728cf1fad5a8cc33d4de86b5570a06748f8c04ce96665217f1a94ca0187c9ebc6d0e 1681633867000000 1682238667000000 1745310667000000 1839918667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-123 \\x366994434af2ca2b1f42f6b798947c99b0bdfabfe6e230972bb92c5ac24cf689a7d7dc6f919c641caa86e8d71b71582ce01ed3726e917200479df23a6ed1234a 1 0 \\x0000000100000000008000039fff99ececb06385693306b3d303a8665490a79921df17abaa2caefc8f31cd8fc672e17590580f70d553a4b7048735c5e9b6b679caa623b628ea7ae418afff971b53547c1b989cec5152c565a5d3f43185b90b590e2e20dc3ef646d443f00d1c36aaa5642062edd5d7d68fe8ed4267879dcb7b39ddb1316873e1ab31c14b0c31010001 \\xd49f99090ad2d42320bf081c5baee45185140864b708dead90c57d1605aa95b9b13490e02bb49b36772bd96cb066bc339af2d6a2cea68a775905c81a4252a00c 1682842867000000 1683447667000000 1746519667000000 1841127667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-124 \\x3aeda761a2a359d95b41fd43e36055b2d85c793548b8ba74abc3c20b5b0ef0d0b0293d6cd3f11482a78801d259177a66f0cd4bc7a306e58ebcf0bd75ddace00a 1 0 \\x000000010000000000800003c7764dc86e72b5018edea3ec4a852e29c2538cd1f02530043a80166482e409be14df452fd7daa6012e60d92484152869f7d2ecbac8b90a29c14b0ab4385b554707c98c53042d7bf5f6b3fe635a5906c3ce965bc6ffdabc4d4e7993e9df711704976199a04909f93f3a555d66bf271b45902de58918961c799796477c2f14a07d010001 \\xa59e2a2745ef6307aa35a40d42acd617be8e2eb56109811cece8b3efe5a3d50d1ef3d544e932392a02edb9f1694275ce275acb10902d9d6c02344c6a3edb8c04 1671357367000000 1671962167000000 1735034167000000 1829642167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-125 \\x3dd96550c5231ca0fe19136c1edf0f21109819c147dc7556759db10ba9223dedea34396f80c151cbbaff3c69184ede8ef599f0d1ca99a4187ec633c5f3add8c1 1 0 \\x000000010000000000800003d0b6a204edf179d5e90489425fd31736f5c21c13561749da0afce6b19cbb5a25e3ab1d0c32963d1780a306103c1636433b052390fd161d06448b0890587e0bd103c497f9e39de708b96c31be7ad3febe7d8d732d494d9ed5edc41cb8c5833a0acbe25f30d2d57ee036c5a0afe508e85b0ac466dcac91babb25c9caa07e26247b010001 \\xa4a1f07196e7d1f38e47abfa21cb439659fed04b8c4fb86b07e457d06be5650b63c864d73c24d1c4729ee384e34a8d7d056340b29301d396b76b0577f4240f03 1662289867000000 1662894667000000 1725966667000000 1820574667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-126 \\x4aa9cf7a3344cd4cf55dcbcdd9f0b62fabdd3c1cd3bf19d21d1510c75b240ec86c3e103413809b21103529c6979709b5ba32777a4ac82dc0ddf46edeaab2d206 1 0 \\x000000010000000000800003bdcb5dc1fcf6bc4e4c71d4a5e562bf76c7e8d0fc638ac1e509b78fab1a59bc34113e9d100afc4dad5809d91b9a229dc49a9467ceaa8062bf02be9c188a6a461eb6557d179b7e1a5121d3baaaaee10752b793483e768987289a647fd13df76a95c1bbd638ca6a94059061af4d0a59027555e6b8a29110fe71d3135a0766a62d69010001 \\x7e30588609ea713b61d04e8a6e0d4ee3d198f679320e9c60ea818553eb2b57855c5b0575f0226f63203750583e74e75eb50743275f0e3d16923aec8e1a04c20a 1687074367000000 1687679167000000 1750751167000000 1845359167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-127 \\x53fd8b9365340b3dcca20f2de6babc94db176b48375cb1af6e93496e0c07810bbfe022f110a30f0bd8affa76fa59fe47c3b5274bebee0870a007da7f997f02f9 1 0 \\x000000010000000000800003c507c335f5454690526fd3da9178e45a137cfdd561c07d0646878bb0b36a43491c8514a4fcbe7883e0612fe671298320b945cb1b3cabf8e3f62b550a781d676244cd05739045b0fceb83618e308665928dcd3799452489a99551e36a6a076d56ff1b964854c1ae84d78d734cd005a8fd779def722d5809549cb0143ad62bf679010001 \\xc56a72180d98f9648bbdff98ecd4baa67476abc990e2e08f8565fdb2e9a832940b1f6672e8c2f0d1af4e813df5ee7b3fd626e102366a9eaa8214c1df47553a01 1666521367000000 1667126167000000 1730198167000000 1824806167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-128 \\x5525e8715a46d7b20833f4b8944309fd2d60fe2ac7870712608162dfe52ae390732a7c29175d25d12fe58c79505814c78f7c1c76e53eb24fbfbe36d18fc1b66c 1 0 \\x000000010000000000800003bc74a59cf0c443a217bd414536e78bad10727a7f7b2679682e818818c52cb9eb93dc1e30388e11f0fa4870c194eb8e18d85e58e0a6cf81a11ec5bbc736d31ef18128013afe8995e874dc5faae773deb911a20a0626673e3f0696b09d036859a35386f315d0e6d51912a0e4928a3ce83b0fd08aa88fa059864c030084db6a220d010001 \\xc656f73dbc600d0d118c8fb52f48c670544fb969fec44e43deca5156e4054df6dea127b993cf00f11f381f23bafd990beba9236b9cd8de4ec5f53318bd2a740e 1674379867000000 1674984667000000 1738056667000000 1832664667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-129 \\x55797efb91ed752a0d4109a260c439ce7ee1f6ceb6891344b472bbc758932b8f535f1e61cdbf177280f6d6095ca0ffeefedd350ee187945b6ce289f2d9a7d107 1 0 \\x000000010000000000800003bcbbc93f6389cf3bc6ec605d215396b6c38cc55d9e6112240d04058e70b026eaa73b435cdd9ec747b8496e7089e349007bfcd9c5b019b719e9ee4bd488880ecbc17deeaf92008121c9950d6a1045bb3dc083a2568575dd88b036a06239a3c4ea297be40477d49ea17eb88677257fdd53641cdffade4e222abba8ddcbec72f5a1010001 \\x8bfacac6f0d22d4f1d421325723962c907b90741b045738a2c421919251561b3ca23b3c826016cb6eafb486a84f0833104047089cadf8391c59ae4547cc94b04 1685260867000000 1685865667000000 1748937667000000 1843545667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-130 \\x5665aafea14a0c77f65dc7e0459a604f26142641fbc65cb760a1ecc7e6f35385672d92c0ffb5fdd2e3f53e6edc58ea42af1a081202ab213689477de44f3d560b 1 0 \\x000000010000000000800003ada6898e0ccb37c0d7afe8feaf552bc4ef17f25a4e412136179e6054fcbf73b1a6225469370df8a1615a0d4ed7177f0e67aa444a8807667ee5535a03bdc29f6a3f62740148b5cae57320c9749f9d2323728408b41acb9c24b57bbaf45157eb6096f462b06a3b65743a8144d16fe814150e8e198423cf26881b9cae21fdc7cab7010001 \\x1faa4aee4e6fb9e504486a48ff3deab65c747a351bc6670f51124a1b2651586f99498a1bad3b75e609fed56d03b30a433db20973798c479d3860ff47cae93109 1682238367000000 1682843167000000 1745915167000000 1840523167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-131 \\x5751ef82145ddf27f1200f07d34305c0ec30349e9112e140dc29a92ddaffad2754ba531bfae72e13fdaaadf96b7012f7def600133e88c55531b04ae83afddc39 1 0 \\x000000010000000000800003d18dd19946e4f60ddacd8444151f8580c5c73f650a68cb6488da4de650dd29fee998f967531498faff4b28e3b0e0ff0362f13c830fdf2dc6c35878ea4994f526e61a47b33c8bceaee4285e8b7bd728661fa2dda2747691f0494ce2c28072f6697a12ea60fe25b4ef5eb52248b7ee45796934322491f4c8d673ae9c25725100c5010001 \\xf95db4e71b117926ea43593818f78993748fc2cd61c7edc8519b2e8b65b6b86967d8445ecefd99ceed0e7b5dcea469d40cd5c5957c1e65a2eaef6ff8e5870905 1682238367000000 1682843167000000 1745915167000000 1840523167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-132 \\x5705aebf18b081184d9f3414963355311108a1e4624fea956ea9edc6e5e61ce9d8a899a369c7064cc476d739bd200abebc6f46b3008097e30a9d6e22416a9602 1 0 \\x000000010000000000800003c2fa7273b6b3db7799682f185f2849e86f925c5f11b394721c411a477700da6dbb56caf5f8b5253a898d6f937076f24a70ecd8016082ab3f8916fe77aa322ead9af44920f3b2aa49a3730f6a7e600e0e18ad25fca4ff08bad135ddcebdfe5b52435c6041c339a092b3fedae065873a32e2ca61fcd69829c6d4306d6dbe05e15b010001 \\xd44eeba6c3a2021a6bcf680c59f500ab5895ca7fd3755792d9a21f339ae093976cd98ce691b5a53ea885e739e866d7b851e1b135ba7fcbf9e2a906d7d3206101 1674379867000000 1674984667000000 1738056667000000 1832664667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-133 \\x5b3d4c7a08e455331dd5e660c6e15ba6c3f7ba8b3f5d39448571add4573efe8e8ea0b3252f27885525f3c176e2730e4570a373ed9f3b572a795d928f01a9b0c4 1 0 \\x000000010000000000800003b4cc701e86bec6310d02a1f9e6201f77b69c4d5ac31b9e6537014147d071738ceafbb7fbb289d793609206c1aec4336b44fd905031fc313d30e2269cdbd001ba13f79b1cf91c492473476a944e7ffd8af02928346e49de13dca73f88e6dff68b250acb2f9c57f9e070a3138d60f608050b3bf7e4b3c1c93059bb1af009611e51010001 \\xa8b3c1196e6c79dd69bf07984e4dd58b628dad0d8ba240812a9b832abab8bc613bef52b5519167f76773a7326edaef478a34df2824b18058202fbeaaafc16002 1663498867000000 1664103667000000 1727175667000000 1821783667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-134 \\x5ecdd51746c008a8d06345e7ff9c4689177c0011fbeed1e09afbab669cfdef0f21b02be01a6b154d36eb9875c6527cbe6ee3fcc07cdeb4e1c5acf92e7aec05e4 1 0 \\x000000010000000000800003d78e1f2e52acaa2a0d4c94c39181119d58af931b01636514a375a94e3a1fb83c87aeb700339e09e3e3d923482aaa7320069a8addc7ed7f5c07261cea2846d172698b33f1a420a8147992a9114c56c48d9fc169dd8fcd182706dc43ba39fabb245ffffe7174d59f75d6d0f60ac146284f90cc7992096a0a7dbb6fd503ca8240af010001 \\x9b8a416e25b563b27705bdf71e8bcc3147163dd3018bc6a3c10e06c70b729cd32e4e8464350bdd3515b1b73c616aa57e927d78bd7e2483ec87e88e0d4b310e03 1682842867000000 1683447667000000 1746519667000000 1841127667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-135 \\x5fa9c8aee95084113a82e4c28796bd9332de49863e8711edd65a477226ca6e3c4c39db942b496e79959e142506296ef43c6af3fc8b6618631976281acff1344a 1 0 \\x000000010000000000800003f13da1788569501f05f824b99df9035c080a9706ced40802c5810f9ebaae439dfc752e354cfe9f48c22d81b9525c726ccb4acaaa16f562fda27df952de961228ee5a74c40b02780e2ee901c2d7c8330bd49a39509a9cce7c97bba4cf1f3608dc269cc0a9ab3ea8a18a491e1a4c46875897dc5246a775aa1fe07a6da2c6be249d010001 \\x42274b9050680981bb5f2952abbe9f52bff300209af09cb59a8e7c05ab0a4ffaf143101f094c334d86dd53a1057abe26d591ed328d45c79c0622a7ed7a559002 1676193367000000 1676798167000000 1739870167000000 1834478167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-136 \\x6201d954e0f59d992494cad8a49b88d1c7376c2066664bf9f29e6197fd4a5a0ce8174129eca4c845519877803383613cd050625a65935186282812f0e62ed683 1 0 \\x000000010000000000800003cfd01ff1b06c50a618bf7ddf2e6a214672318b7efc374a46f3036d2f4b1d4c2560ae1da1f4ef1aef72cc2f9b60c168a6634d244b19f70ae227bc75904e1624d3c4160450d701fe6134bd4b58f2acf7c5ef363ebd8bbd71b729f70bab324e25a4e146548c88de8f5606ee7e1bec7b562c46d504081b3e1c8c16f98c6a8ba2d0e7010001 \\xfaafee30d2fed46e566dee831a3488b3535cbf70b30f76be4ff50ff09ce314f21a3fa9cdef5e22c94430ee9a996261638e17e7b692fb082b760ffcbb202a7902 1677402367000000 1678007167000000 1741079167000000 1835687167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-137 \\x6475dac6be0e09f1c995012ad12f09452c6014e150c2d9d9baa4eed37e3d8b44dcb3fe7ef5e52593972f9a9f8ca74330fce96e6a9af97abe4cc4bccc895c1613 1 0 \\x000000010000000000800003b2ef56a39037afaaf65b0f70e8370dc43588f2551130acc8e316993e0c803ad0193b37bff330fc575c0073f8664d61805d925214fb0ae6897c9b186c653c27ddb43ca28a489613390e54ee9a471021e887c8ddd1c9b5a2e1587b8fd5123c8780920ca64ddaed085528e77ce28bd8deeaf7ad13ea2705751359eb1c1cce3e73a9010001 \\x73b04e6bf3b59cbd861c839f2429fbb3f4263e73b6011d7b1e25dc32039f7814b20f1b3bb61bc8403bcab08c9a85f0502b3159233be209e0a68bbbf70c4a870c 1656849367000000 1657454167000000 1720526167000000 1815134167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-138 \\x67d9d4d7bb9bea56dba5392881adaef4280b52f3e64a1f25f3bbb3fd865e37d91bfd7808b3f1696836bc7df31410889d69b99ae640149852371657a928e54f7c 1 0 \\x000000010000000000800003af515b5c2a9579c08eaae455debea529b805732585c55ac9b6a352e13eb1f82fe1f49771ec944b6c2a4ead556f2b76101fd7058652fc2a0ebc0fe3a71cc01e027db221cda3f745419f6cffd33ffe4274e017ddbd161eb90c060379d1ae05e8168038761f393900ec33b6b7aaeabe580c8408ff72dd2295824105913bdd9162a9010001 \\x7066b67350c28ed783083ecaed04f0844f6dde50d7061451c4536f65c2054e15b28229143ef4ed48d54e1d631481e18c7f29536f9767000195a7174a8be49a05 1674984367000000 1675589167000000 1738661167000000 1833269167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-139 \\x68d17a90d540a2346a6ba1a43440bc5a1133bba9d266b3d1c5361b6b4e4190081a7d3ddc546c31316d892b2556e1bc9f45fd29993030a496b0d0c3520a341719 1 0 \\x000000010000000000800003ac02ca8ca5f988ea8713288c06ebcc2a2e9f3184e0869fa12cd3eca38732a325dd850cdd94001ff2bc75b4fe74df25deed59ed940e347a29841b9f7a4e990ac51f421e77b6e288cdfac1a2f7c3e0f9d35fdb90d096b438828c9ba3a0bd39c049031842e726f2ff03c42bf4fb51c4fc25a648899d98b9629c915fcbe3278685df010001 \\x48b532cbe8ce00e9eb76fb2b45087d4838e14bb811c3a2a161172085e6641e9d6834e967d586f7bceee679446fe6bbb6da2bf22121a48d582f173a24cb047005 1685260867000000 1685865667000000 1748937667000000 1843545667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-140 \\x6851bf0de0dcfc806b9f265743622f43c473a0343b1a1d5b2aab10a6fdc1afd48865e51e1ec78d6f66e9e268971ee8ac698e78cc6d893b1da1216c747e95508a 1 0 \\x000000010000000000800003c02a451e8aef3f6d9f1d4145fa1654d38ad93fd6c0432af6fa6b2f399140870a249a3281fa85f3e62a941aa32c9b69053df80687fa6bfca8afca171b9a7d516dbdc9cf19d73a152ca7f38165f9e814cf6fb074fcb6e9fb2bbc428b42e484231efdea3d6ed46f816fbdf3a9565f8f690c5d2e2f2f86aed765c66cc89e599fa6b5010001 \\xa3c4980c9849a482425eef514c38b9c11da4c71909a2364d64313b2dfd1c6a0ed73942a7921b04330346450a2859d057b0faada206dfc6627b67bb9b23b0b608 1685260867000000 1685865667000000 1748937667000000 1843545667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-141 \\x699595be8726cbbf3967763255afac91624243ea75e59d4f883f90711bb6916a151e97be6665acdebb026476db5d61809cd00296a25050d9c079afa308387de3 1 0 \\x0000000100000000008000039cb1cef6149e52c24f0727e19b52112bf3c759acdf2a9a8acb4b270c542ac6128e82fa908e366451c23de47dd227dd8405ce5116dc338de57a950589590d82340b0152e5f6808e9b9c34db9349ab57343e155e1b51852e67861547f479f6216487c83266f531be6d28c84ee01a7a25d59c4e32941216fd7b874163bb9892d5c5010001 \\x0babb0c553855a1b6e7ef4098d8c9a8661d3d13198b1d7bae9a08cdf8a2970f97cf97f345a9beb908cf75baeeba977b0eb3d04c7c97b4d2c5dd7c906a5415906 1665916867000000 1666521667000000 1729593667000000 1824201667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-142 \\x6b4d5ff16cf837095c3b38c17b3f8a9f104da4a8ced8badd0d821448779d92ca36bd293fede635fc2f0c923b2ca4a56683243a4a589af75a37948ea58501f119 1 0 \\x000000010000000000800003d3453e646266e19d57434987a51b64f3a1bb53797ec2d4766a59cd80b7cf0e0b81eb9d7f354eea8b81c5f932b8f86d64c7f2f99735613744c2c04540f0b83cb0644af36325039c049ccbcb1d4c59c9bfd31017ab20c79090fb681bbb985cc38a922fc98b3f3a88b44f6515481e8d06512022b2e96fa81b5e0fa1f58a371009a9010001 \\xa6f04572736239868070fb2a54c171522940348a9a81f125add7f7a49b2bfa23eb2eddcfdd8b79c615faf53f4a0a59a6b429a92c7dbc2e3e21bf0b3745e3ce04 1665312367000000 1665917167000000 1728989167000000 1823597167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-143 \\x6fc113e9a8012ddd65ddd92299a92d0b4148919b534eab8bb27676764c6fc40da08781d3fb7c36a6f38bd58c2419fc8be7dcb70d36376bf94830e59ba61b79c3 1 0 \\x000000010000000000800003afa0e9c2225f7d16acfb751f87362793203a89fb292871ffae6639bbd2d0a7d23a665f845bdfcf0ec9ae30dcb00a2be8577881bd0f92c1776371bfb46e05b51eef9d96049a41c6706733dcda20e800091acc81d03d77c34d6b83f8f45c299765595fb7ff634189d96f285c460117f8d58e07215420c830109c99a508002b5475010001 \\x6dbdc96985ab69cabf8bb26e0118451a5b94d7bf496542b503a2f90410fc2f07fbe58aef7f9eb07bd1d956a34f9da421b52602fb43ca7984a7b8687034e64d08 1668939367000000 1669544167000000 1732616167000000 1827224167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-144 \\x7105171b799bfa062db4589a3befd284e3e5f1751ebcc17357c7dafa9c68db34962cc9c6bd49f9e5453c20ba4e28b4bd7af02bad1372dfb94a5a8feb181075a5 1 0 \\x000000010000000000800003c40c4a93ae47707a85f1e0e6dbdd2a79733a27e5e562dd0f16862966e7fbf0da4a0c79f74a8a7d391c738fc6a730a34852dce76354f8d2a5e2ae37be1641c79fa4f7dade829b95616d1e82204218b0c762411b63026b98d93ddecd9dbab803d7d0228044ad5ad8fb8b168070171f4a63d31eba874c0394a477336a5dad4a3285010001 \\x891e4939840fc31e207e59b81d276fe529e15554c197eb1ef40ce96b0142ea9d215e43b2466ee2c7a43b9425c0e23fc3994445c0ec4f640219dd34df36ea1f0d 1679215867000000 1679820667000000 1742892667000000 1837500667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-145 \\x71e5fefa4b2ae13213b34576ae189c655203c7e9554f476ab711b7439bee83bd8319eeaf78fa3d0fe75471e89c7df90383b8c8fdd1fa4ba892c950ec67abad65 1 0 \\x000000010000000000800003c283ec2c17bf02abc24f4eba701b295e1196acf24eb3ac0d3078dcafa4815194e7a1d09b74fa626a091d452bfeabe9e200930af6499c602c03dc74064234dce25d2048b773d81da850df6c2467010a1c7e5c80db20e3b65b773d4bcb5e2e321a706e65805905e4a368e1c39f41a78abf5a1bda5b0a93e9ae7630b004d94a744f010001 \\xb524f261e885d781ebf9c67dc79f85e87594f8b138b2ea85999ce60bf20137dfaa95614cc2f25a98477ec7fadc157a57fb45ffe76503285f5fb6c9c0aa835704 1670148367000000 1670753167000000 1733825167000000 1828433167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-146 \\x72fd733ecffa91e4bf173350dbe5ddbf9af06221daa3b50288cf3ec07ac3d920ebafe1f8432a39d09f7d88f4e27ffae9f4a997c717fd3f39daf794479e93d1c3 1 0 \\x000000010000000000800003d01511af3adcf9a63df5964197b7029225a533bd339f06801db6e81c417a27eacc44b1335aa8fe0489eedd2baa72d64fa9782835b78ee1ab8615f57c8baa5f98fd79d32e7809e544ca61c7cf5ed7dbe78ba2b5b581a4202923d236b2730db1430c57ca6c151590781ebb5b2079b5c452722eebbfb6ec912e540bc1974c219cb9010001 \\x35ea34cff997ff00793db6020af31fbd02936f511b980987a524e45200ec96358c738df109c665d04d4e65af48a82cde87decf2529ed3d208773c62a59c3b607 1657453867000000 1658058667000000 1721130667000000 1815738667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-147 \\x75f11b48b7563651198f1e44fb20a575db3722db569796cdfcbd4d407d862e2a0537400f303b90f35f2acfbcb81ca8301db1f24bfcc42e9c71a9339718889d1f 1 0 \\x000000010000000000800003bd61b1ced896a78ad3b7f32365163fa4223385de32221068c4f6ef1f4f66ba8ae4f13a9f992ee48662f84db13fc5d25394dc6c55e0431111288645ddfa1ccc2ab1a8624bb0ef10f6c1bf8b56085387861817719344300f47d48793648e194780635f963c3842a56776e0cd677507c6c9f97a744fa07b2a782b24c6e76ace5fef010001 \\xcd4f122e6bb67c7826d8cff5b5e959feec2f158f52351e74ed38ec5652da8f961dd795d196047f420526186e2af41a4f4f5645768d1d7d88462d3bf75f54ca08 1669543867000000 1670148667000000 1733220667000000 1827828667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-148 \\x76317d60a568b0df9809f761580882ec660dd2cfcc6d218f77abe6a05a0af183dddb8a840d5c6289608d6cadab9e655d8a7bbcf44061a7ebc79defcd763072cd 1 0 \\x000000010000000000800003c1142283a7b90b09b4cfe835d625450ee8e95041b404b652386b54386291c752305cf8832d883c2b86131bbfa073ee0dc45db05891bfca0cb235d86174e715f12f3efffdb536268b16fdb712180c32e59e53605af034513835f2e258e81da9099ef95818652e6ea64597bd98db9605af7bc309a0b86c5ac307bb27fa4a229a27010001 \\xa8c9609cb690f774ed0a50e1e3da794e057c41f60560fec2d623f8e30a5f968377cb520dec0d787ab3a77a9580e384b3ffeee786bea7d3fd12ab67f275f69f0f 1679215867000000 1679820667000000 1742892667000000 1837500667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-149 \\x76157af42857a8ae5e87665c2eb58a747fa87747fef5ac8937acd8a00307f6a0aeb7be08c321f30b7775f9ebe242c36978ea02a7c4a01c894b5ab12c55dcc27a 1 0 \\x000000010000000000800003d1ccc32db2f540de1d14c6296ae62ecb2a6a0400982636522f1a17fb7683c863e8299f4d8e47918e01ffad1834a0499f047b2b5a27d41035cf54b01372403ad7d787757ddcac497dfbafde77745b200ad86ff4afd2b4c1b97882389e7c0091c2a4d0128b5ae5cb6c9675e77e19c28222ee537f1adc90fe090356be8d130e1b5b010001 \\x82934c6d61c35996b0f78cacbaa666622466a25cb18e959e53db89d887156e2ccda344a6db863c46da2ed9bea72627d542699e73e4b7fbe361fff1fe1b7a3a0e 1676797867000000 1677402667000000 1740474667000000 1835082667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-150 \\x7a5191ae0b5f1385dceef3785733d4c85f2cd3f89c867feb91224c523797f19c6e862aa3458d120cf389eda65c4fcec95823a209e2c76709607063ea126e17cf 1 0 \\x000000010000000000800003cb5ed87a408c0c9da562506d75d93a08a9ab915cf74e235819093a990d618a0a7ba9055324e191c27bc8073aa3605a17c6a88a71f56a2d093c4e3ebe8279b322d1f1516fd5c2ed6cd61d6d4517a0485995dc5400d00b7ca7c8e35e9a3bee70a4aaac04621b60ff948a3c07d43ccae98f8808ad755583c57c1a4c0af2124781e7010001 \\x8cd9036ecf6cc9f018c79b5de26b9bd6ffd0624b45bbf79f22e87e7024966f902d3fe11bf5fd73b23ba54169d3c624944fae38ebc756eae63caa3f4765ea3809 1684656367000000 1685261167000000 1748333167000000 1842941167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-151 \\x7c35f2db28eda0181f14f28443df15f4fd25b1944ab37b28873684339e1334d690333638747c725788f749a25a8a293e41a952fb57a6396151f7187a29942b1a 1 0 \\x000000010000000000800003be310ee9e73e388d223f79456cfa7189088c83e62f5a54f5e8a2385abc0e11e858a46c0555fdc6dc3637fd9b3ce72a0142c076606d464c92f7f080347e535008585d6b0a42bf727ae089ead85503cbaf47577f9351f5af23c9241ab0cbaa019b0c1916accbe383047cd72a10b9e54bd60098d8e0903b8d4affa842eb6514179d010001 \\xcf0a7cf3b0bb55926331f2e852b1f39ebf179b4673d1b37fff2bd26f5fdf946ce4dc6ed601fd8f155a2e6e4227fcc4f29c1f46c9e5bc2a0ad05038b76a6c5e0d 1683447367000000 1684052167000000 1747124167000000 1841732167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-152 \\x7ff90b8d06bb94753d3e454139159d384b1f4d5a8ec66ef48bb919b712277c497d8b8fbe054a7a3c4f025349d4d276918f531708fe767a6b1a89188d8dcf3bd6 1 0 \\x000000010000000000800003cc56cd9f858f31ea9ffbf20f10c7464992fc7b7a8ce7c1a47c33c2e3987c76d2baacb801ff2e1d4a01265f3edb0b259a7868f1c91d5192b77168438a9f4f0efe402947b5911b9c0d3e873f1c054ee00f6fffcf93812d8015c5fa0ebddd33bcba0fee3d2b10208f28d17b943925f684c1da749ea86ebc155af52a6abcc70bda77010001 \\xb5def87206717cb746c318c1c09afc5766e0f050784c959d5cc759cf0b04320ca9f4fdebe71f10b81392abfd931568d7fcbd7f06c6c6e6578429df342e9ac908 1680424867000000 1681029667000000 1744101667000000 1838709667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-153 \\x80c57ffd67775571e155cc86fc6734c04c3254d96f3b86461f0f9374c1cef6a0ee505fbba10c6126f00b3808fd55c7163ea5f8f6ffe5682df66cea002aba4295 1 0 \\x000000010000000000800003bc3645eeee6d372705d61bf59580ba01cccdd3db018ca3510a34b7e40810c305fdb925d29d274b8aed750d2bb8a72aaf068fd80d5baaace49e4c2a6b0787ef1aa94f6c08192879c1c6294837d81c4a835e87103b433f375632f915d2d26fb948d0ab7ffc37765e911967fdc7fdd715ab50dd103246ce19988c92bea233751179010001 \\x364c68e6927c3c60fb72a0830fc8256f8d3e1ca1810047c44cd2eddd7ee35380ebcea94fa54abbe490687b3aaf3978508af8e7840b491c65246093963f76fd02 1664103367000000 1664708167000000 1727780167000000 1822388167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-154 \\x810d7096bcb9f4718ac4ffc3ddd3cc0cea99285bb86f5e4be72ada81902068aa269ef37e040a8826ea66be46b22d471775a646a52d845891726a2c6367ab5e7b 1 0 \\x000000010000000000800003ec4c76a24958775faca6aa4d6f10398821bf1fdd838a207385bc481028a9f58b844ed39668ceb0cab4bbc0c793dc35d1639e686e563e837b2dd156d962a1b7e727d862650aec01dde80ae2190dbbe48f1e05ef509e426f35da1efc7959d64c26aa01a13563561b255b9bbbdf551eeb9658d8e18078c69846ecd0e23bd5c78a4b010001 \\x2a435782291b2175710a8d99b5f5e93c9e6062cc4ebe265adfb84f2f1dd1174c70f29a6ceef101f4c49e9d8eac264883370be8405c2651635c375ea774d3e900 1676797867000000 1677402667000000 1740474667000000 1835082667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-155 \\x833d168e071b058e4643dbe44cfbd8e1910919b1170a97e3240afcc766903442e5d7e6b28a983c2152527fdb8e31a31937d244251389e67ec261220ef067530b 1 0 \\x000000010000000000800003cd0cdb8a2c13da721cac6e9ebc4d9c5cc7cf6b3645067e6d9e1d46a9147cfcbfd0ab51c730bdb007bba38f6181808e2c7b795d0dd8570d946791b8145ef87021d60908d257057910dfce0a147c11148d2bad12caa6ac0207e1b324a5d2878d716df38823909d3b7a69e27cfe5d9412ebaaaf990854584aa733b727f5df8527c9010001 \\xedaffbbdcfb441570a166447278405b9f31ed48031266282a39cd5bcd3e217107a29dea6fe2d0a02c814f1e060b490e1db8a60bbd3f57caf35f0f7094ade1203 1679820367000000 1680425167000000 1743497167000000 1838105167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-156 \\x8ac5e622efccc8977f506436c1e9e778b5f8e38ed0c6e980e5140ff5554c14c6bc48981e8240ef8d89e1a826fc13c574bd6d81e1ed3a6488621747e01de97987 1 0 \\x000000010000000000800003b476cf686a0f75c6e3b5e6056a54f8ddf54054074f645016ac90291ba1594e17949e89de5998f718411cafa47c463c1630a00678349d2895b8952552d438e1a213b7232f172e1655675ac7b6edf66abcc2d7b180ca82464dbdf1fce5498c9b88092f798092b114143cbcd4e52b9a439550f80f31fe2326b4c6609cddb65de139010001 \\xd00f3a067af78a9efb3d5946850c1ca52617c6978d5a0e0f95d78ead4051386eb0c6cc634b73db0fc667e62f271e2558c7d568ec9727ca0998a47bd0c5db460a 1677402367000000 1678007167000000 1741079167000000 1835687167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-157 \\x8c49e3b8565dd655023360d3e6991eb2f8e8c2d6a206cf020e1b5529dde7521fedacfec59460447cc8e5dd03c6710800f7c6d88fdc9e5efcb2d20addfdd05972 1 0 \\x000000010000000000800003a3d29ee6b172a7add2b97aa1ccee08966b827f24e5bc3e1fe8cdb7e98beaa5b0f60c5e5e9e8413432a767db7324ad915dc0832b9a9b800a26872b7ad02686ea772600b21063dcc336b24513a7798788bf9e4179fc78e85ebd3395e6d2fa393fa4e4e350cbb346391b9b8d4f7b1da438acf8be62b8872ee2716ce5d175eed8995010001 \\xd0efcf755bf0a41c1e9a219158363292d053829488f30202981adfe466cd439310320c7c1f91c8785848cd690a414c28269cec4f6f5ef337fd5ae9d7fd0be006 1685260867000000 1685865667000000 1748937667000000 1843545667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-158 \\x8eb5dad7dcc04663c354a797bf0635a79469b17f809b6f915e2c4ce606d7196e1e56d70b214dd9e8fc7a895f9353013dfd23bd033e35d83011a7cdf8ec2ebd76 1 0 \\x000000010000000000800003c61e3e57d490e23246944b77f4984e011eebafeb0b70b0ec93e23b3683a36a9c097c9a9b83ac76d35dbbbefa8cc7cf9224a566f2dc7cb42615f0b2e8463fa57e30b275474d485ebb3d31a17e6d0625b87d56ec070ccdaebc3c7b597db0a11a9cbb13b5c1ce1b16aeff3803c9e54535457b314e83528fb82225e16853d73a5009010001 \\x15f9efd287867f73dca47c1a4a4ea003d6d48762522fb37119edd737ca7b8e61ba853322608f0329b45f29cbfca86481d7e40f563a968c7a35ed70d980a6660f 1670752867000000 1671357667000000 1734429667000000 1829037667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-159 \\x91a5f3a5e0b9ce45ce9d9ec506500e125572d47e05198f41776b058348963bdfe86b3d1df110e798a941b6c2b7e7ad3c6df8f6c9dbeac23f77c670f5508b39ac 1 0 \\x000000010000000000800003e63cc806d76db12efc90585be6cb931e5568a4ab9eaa1d03472640f6c8080fbe4ce091530abd22ff05ec1e869d37f569f497970544fa4c52c22ff186e88b1cf4d5596287b54725ceb6e22e46cf8abc0c1ca787929285add3a4527fdb7ee22ed7a4bf35e777c27b3a5a40e7984ac866609e91b6baf610bd20013b17ae1b22d9f9010001 \\x5c3992a9ca866a423378adbd2a1dcb6677ad38f91925e43345bdb585450104d3901eee987a21e0e26342aee95f4c0c7453651751f5f054265bfc4bf850b53006 1682238367000000 1682843167000000 1745915167000000 1840523167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-160 \\x922d33bf63aa85d73d0c2be86eafd617fb5cf5f5fba86f2f552ad58f4cb0745e0315ad7c7b9f70429f9f762bbcc89c53dd00cfb3cd57049d4cbf0ac7c808eeba 1 0 \\x000000010000000000800003baf70e8c34319cd2d706c8cb8fc82f512c7355d6a340791c88b677142f778e1ebd30bd04f29fd99ff3b421b6a2e8ed19f7dcc6190e1b205b370f1e9f1567e52429efaeb2419c65d2d3f324f8576857e64dd1d4e243666c56b0561a605b9407c60d6256d9c3eef1e78ad037d942d2c4c37bc4c6808ce24bca5f23455555cd50e7010001 \\x038cc2cc74ba0706d1adb15f2be732f8079d560c5237055d62e397c9a522e33e45b77b7c70aff64c8ed8569ca47791aaa6810ed80ead47bdbe8dab3d99254d00 1684051867000000 1684656667000000 1747728667000000 1842336667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-161 \\x980146940b82b91f0b58510f4279ea791b38cdd66e6e1b99d8d6b40d7202191c16f27c802afbb93d9bd433960096eeea6ec878836dc93a94db738719e8d24c1e 1 0 \\x000000010000000000800003adedb6c134d674b4c6fcab2f06f057ab35377411ba7428d8e31efa83247699e45ecdac18cb534a0db703eff9ed6d14c224ce18393c0d42bcfa9892949640c4fc59bc006ef1c5f7e02106f8b026e0aedcbb5fd9d923ef8f5fdf72cf5b5727552b72f8be9bf2053371dbe4cf49071784da2e1925a985f3e4de8361449b40002b59010001 \\x011681bc9144a484805df3ae3af2efb73742bc1d9e8002b0d36264951086cef50740f87669fd09b825ff6cd88963df93ae14034f125d91c9244428f21ea21f01 1680424867000000 1681029667000000 1744101667000000 1838709667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-162 \\xa375fb9aa596c765c30085ae517e524b80ce0dcc6b4f1fcdc8aceb5969152b46f0ada6be78f29771ab1c4278cea356a9fb264ebd90015018aad32e79fd996d86 1 0 \\x000000010000000000800003ca799c4989dfbe426f96991ef2212d49eb6580144b64a69a0e40e7627b2e3eaa3a6cb2ab098a21b74127aa0fd0a5c0b867518bda9707797f0847c29327f29c7ccdc9573a67c30e50b3430eafef337390dc3da0608b3fc3697bfdc5ae4d791ee4b26beda9e58cb01a637508492d9431ad8687013bbad6fdc135ac0f610d033f67010001 \\x577421ea112ee1081f8fe7d1b375749404c51715f9f6033ecc393ae7671306d3b07242917a36e52eb37e8a9674f7deca6699f76acbce890af60a2dff4784700a 1665312367000000 1665917167000000 1728989167000000 1823597167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-163 \\xa605e3aa9f5e0d57de29de1902196dc21241e349e745977a66f6e137d85c898ff8138c80f4e5e8c3edb8c0aa5fb4e7703ca4ffc26f74ff0d5a794e6be6eab323 1 0 \\x000000010000000000800003a3b4921fe5380b995af30fda4bd091d3058067d9181582c1ad0bfc9de2fa926f5e767a002f380f72eea7473f55cd1a1950bf031666fca7cb0db72a6631b59a7138d2e2cf8f22633000b03c73f55549b2ee547ba81101444fb358ff1f52d46c19ff67e1f4ef40d7d65ccda6bd4d910b3c1440385857277c69101f1cf720577dc5010001 \\xc928cde10a32f1ba8fa25c59508df7deaff694217e80af98e5a9ecc9d477259c6ddd522920b58d3f5b15e0a11d09b110712e5389451a9719e5dc1dc9cccf1e05 1674984367000000 1675589167000000 1738661167000000 1833269167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-164 \\xa84160a9f51282ec47c0b612762d7f1361ade19c5c30cf08cf197f3d66780fa3bcf073ab2af783d8db33361e4d7217fdefeb3992a2a5e97dcedaffeb6c973128 1 0 \\x000000010000000000800003cb283ab6df9d9faadeab4dadb172fb3bf152b2ed679b28344be1882ea8a274a99d412dd31ff45af17e86daf5df334a14af0dfe740cdf588f646cfcb00115c9658d096ef884d9bf125a3c0824bca43274a424193dc1056a9447d62c36a71fb256b93358cff1595854cf2ec426cd915aabfaf61a93b82cb1115dcf81106b136153010001 \\x0435e3e7f98d2fa2bb4605969dfa1c3f89181306e1df56157714f3cc42b0a6ab10a7ec2493e1012886c4e4982b0fd0de7b88d192327b5991f46ca1c673048a0e 1684051867000000 1684656667000000 1747728667000000 1842336667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-165 \\xaa7596fbad0bb4ff7c14e3b7d5432ed60621c975983fb357359691cc4ac953d2d2092146eaf90337fc2f7a1be1ec1ad72a9dc105aff4fae9466c52fbf7004165 1 0 \\x000000010000000000800003a8eb1fe3f499293d755a291db944b5fd45deeabc28f28482d890e326e951e6f26ad6f1e13310c34be0e8ecd70428846014663227537dc54437aefd32ba14a1bad3e5ab50d761df220d02193ab9a2ac94dd4eb30a427f5f1f57ae4a97a5efade5a91f15f6905c79b41a259a6a06efb202281d752634c2731dad46f63116379857010001 \\xbed771e1373313346d4111fb8ea57d0f1b900eb8c6bd870687690be8386603400007a8a85b075cad1f979b9e480993425ee99259b0b287ee7085b4031d21e90e 1666521367000000 1667126167000000 1730198167000000 1824806167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-166 \\xab418257b715adee01e12cd2a63df8e04f05adae2c76e3e4c251954e813c7b4cf27e361dffc269e5b152397623374c9fb4e879ac0bb21bcab8449e2bb4e88436 1 0 \\x000000010000000000800003c6194382355927837e49e78596154f21c2e898598ebf87e883bf0909fef9050652ebac85729ba108cd0e645a9bcb1a36e2f946e49f6d39e1b8b8e687bcbf44c6b437c49ad975c15648ceaa9c0841c45b0dca92a10654cde8903e3b54d110288815e9250507320a9d236a20e4fb63c51eba5b628ceace6eb11ceca7e040992717010001 \\x4c73dc4463beceef86d8df946b6c6b2fd2b00cd21f02fdf724f43dc23124579e2b4a63179a13c4f5ace04cc925965e5ffbd115cb2f1278fd6ae77659e6fef50c 1681029367000000 1681634167000000 1744706167000000 1839314167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-167 \\xab0de7301dc106cc2b109f080be385d77706933cf06f8e28aabf3920ff4a6487736056d7f1f2ba7c7fd0c720626af5ab80d02a9e56a244d8cdc47568b9dbcba2 1 0 \\x000000010000000000800003cd76a8807b5634647d106914fb608637bb30fde7a94d83716ff1a92d7678d204bf2026cb80df57100acfa53a7322b10104ebf968705de1eaa09a10887d0d044ef446bb8094a50bb12695906b7c1b1962b9c38155ef7f5880ba77e9348e8aa240584efca1250083decb38080d05dedaef3bc9d055a306cfd1ddefade775bf1bf1010001 \\xf539456874fe4731e1e0631055db1e9151c7f486197677132b25d1e8e8d0040cbbb0adc09ae1a79cf24aacf5ba72786ba5789dce4a75121104ce81fc936e9c09 1675588867000000 1676193667000000 1739265667000000 1833873667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-168 \\xadb9eb2f72b2f07ac3f064503e2ee21f5b7af2f473c0afa65a330acd5f3be27c69facf1d590d764359210e710d7e5918083f35880242481de2d64aba4d5d8b22 1 0 \\x000000010000000000800003c8aca64b5a85c3886e1ffddab53e9e648b78e30ca44fffc5be1d8fa4cc0cc78907fd934b26f9d08dca008e228af3990ebc10a915f18b77976313a3a29ae69708f54804cae174df5f29d8f4403e802bb5173632b31c143654651d00177b4ce4ac670865c2409e5ce34a7664c64a268ae4a85de86c46a97be084f98b8e0e7a4caf010001 \\x0beb373f8c848da540ae6ea63617bea2b53f340e0b0e1ba6b05a2b051f83dab3b0793622eb27c1763e063c89fedb4dd86718eacb6e7b4e5783671cde71e17b04 1669543867000000 1670148667000000 1733220667000000 1827828667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-169 \\xb02d8390a5ce9959b6940ec6ba2581fa691e98a589d58aab8462d21fd003a3a6b085d66afd7d6d6093369584708c99fc96d2153ae1f2924d899a2d7182af3066 1 0 \\x000000010000000000800003b22a623e2e5b2654efb7a7db01eba5f347cf16ac4a762b5b3f790d1517b910ebc4b974237cf56e489a14d2937ea3a4c56cc0dcac3c92f7d4ed6a3bb345498d11e73f2f759adaa1183100d4ee5d4d937f8156f7d84ff4d5e203e8ade0fdae266791703c9d70cfb937e94d8dc716d55311e1b988208effbff5907d734a5c9d5223010001 \\x37d4280109d2788e50f396fffd945c5c41056a2bf7fe6555ec3588e31e3e4abc674f08a19155da11cfffb8c8421bc78ec32a254b6c57414202e7b82445215403 1657453867000000 1658058667000000 1721130667000000 1815738667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-170 \\xb1812d95c20e8ce3a90575e040c49284ca076daa95bba7778b4bb9d457a6c281b8053e8717838ae7cc69917300f2e17f94bf4acb666823fc45aa0851cfe0db7a 1 0 \\x000000010000000000800003c5591554489b94dbcb865a1d7f41d116af3b1ad996238271615e85712385d80e690d96797d59844049506ecf865063bfb73b74d8eff02efdf16f3bc2871208dc155a191d29005305e70b87694e8841cfff73b6c391bb5240b224635b5a8e843e8fa1b8040379ef870195b5654555579a1d27ad87eb2ec8fbdc712e34f6b1b2bb010001 \\x16ff7558a2096f7a8ab2ed7dbda8006818a428fb7a970701ab209f19a5f07b50098a8b24a3f6d45e3a53ef1aa1c6ee61658282ec61246878fe78bd54f2317a0a 1686469867000000 1687074667000000 1750146667000000 1844754667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-171 \\xb3057085d01117a4efb66a5ccf22731806b428795c1fc2dfd36bfd4908e4e5f78d404fddc459d8d29c64939532ddab26cf454b79e95bb67a286d95dde6bce61b 1 0 \\x000000010000000000800003e3719c1d4ec3a73da339504927bd40606a197c8c800aa498550c80b9f56969eff1b3a4e0165c783aed349e6ec7586a424164979a27ede5486db1fd5edbb236807ae84c70256b432b23e92a19fbdc7ab9a8a92dd91f5ba1177cb6ead9e199bda22c0528ebf19856c4b16ed6edc2c563bda5c0bddf348ab330bdb1a8f4edb65b57010001 \\x01af0e5bade60b3621e156ada4678d015530254cbe1bc26ed468dfe84d60ce119370ab0dbee5a5ed25eccf8f00d0bb63edb6f4fc089923fef0f2657c7e99890a 1679215867000000 1679820667000000 1742892667000000 1837500667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-172 \\xb7490537768b043426fdbbc56c08d3941ae1f4d3d6a38e16c1cda551e7604b110aa90b554264a82e7f157b09b7c4ea14f21096aef04498febe54d24d91ead13b 1 0 \\x000000010000000000800003b11a387a9dd89671b39a0a79e9b5f031f31bd9999552bbc36d1ad6a3a4cf80b8559d2a068fe059dcce436b8fe8c0b7c6288e29575b50e28bb259d4b6adc0e3681d0b7ff2d1ed72a635a0c6760a486d2915ade8ff646817dc3fd1935c3c9d32032328e0b56f1b64032b99d1b498754fbc0cda04d21a949bd2737d91e180ff7415010001 \\x90119f99b3ff35df3c10255c9f4dbd46eeefb8a15ef46319b9befbf815ef9d896a5064ecb176ab5bf40e43a4a42aa799ca38205d57b7db8abf3fda8805687109 1678611367000000 1679216167000000 1742288167000000 1836896167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-173 \\xbb25bd72ad4bf9c5b98d00392ef0cca8553ebc8a81079b752086a9cc7c156bc24c21f2724f69fa32450471b49234779b8e8bc8231212e64b7e4d72c7fe359984 1 0 \\x000000010000000000800003cfa63fb57955060f356163c575485d32f36efbb60fea95e11bb5b7e6a459ed8dd2c61353ddebc4f5d87d3856672a3314ff6e5ced2b72b7bfdc5b3f00bf3a3aae741f84c7cf8f1eaf731601955d13253ef6a6f5ea3ec55eb6d1fd0212eac286a766cf90a7b442a5dce7af1466b4295c19e3cc048be3686fc4416c826b0d03c4db010001 \\x809b889bf777d4c12c144feba597690c996404c7c7de5a66d54badf63a8decd104b64ec32c758ff7bd0ca758bf26190d35711e204ae2260037e1e71d4f343205 1683447367000000 1684052167000000 1747124167000000 1841732167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-174 \\xbb191acc901b87ad875fe4a33ff747efb51b1576b7a1b2db3a7e89f8ef393916f855725a2c6d5b336e21c9a4c001fefb2aa730f205e2d29ed30fec2b78906900 1 0 \\x0000000100000000008000039a71ab37a3d6c56790ee290318fccb956f93591d73e7eafb4393907aced102ec0e2ec93fd1224c5439ad99283ffef46359e75574e5a14c6cc91ffcbd72ffc4eb13379577f8cd354398ce60880d03506b39c0eef15ae1544944c8e1164228a72610923b018e43a6538299fbcb11ba33185a5b166db49c6c42432ebe0c825e437f010001 \\xd4d86e5907d9bab245a1ad866c468509b8a2da11c7098f66c8bf12adbe95037e6e3b31e284dfc9735b0d927e25fed8ed218b4341e63b6eeed884638fa2853d06 1674379867000000 1674984667000000 1738056667000000 1832664667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-175 \\xc4791a4697fc6e0ee54dfcea59c39577de50cb02cf421dedbaf98bc07ff95085494f4561b86499b31b665d76914882422665377649cf84731c088abca5933dee 1 0 \\x000000010000000000800003ca5df15a79ad06c85d2e0e190b9fe07b96b13c781d3a579542a11deb7c13f871cddc0708605f7e826ed37822b6e6677c4a82a54213d4b00c659acd7526135d6288c7c2f4444f9a76148b9132be837529bd905a5ade835586fcf0980787d5aee63f6f2586a1933dd69f488733b5c37eae8a599aaf4549b0933a74dd15052301f3010001 \\xfee89dff0e54f3f4b8fe90988d98faaa69378bf8a07a0d6e9a30d796404ab546aee9c2ceb043cf0991a219aef29b3ee8ceb20ae88cce60ffc7549810e3931801 1682238367000000 1682843167000000 1745915167000000 1840523167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-176 \\xc42d397a177ded0ff5ed0c13647caa725bd336f91867469e839dd42c88be746f8fa6f28134eec0604cb85bc6c588419d19a90652d1e2a67a9efa456cb1b940a3 1 0 \\x000000010000000000800003d32de56cb296c41260096e52fd98c7d0c1ce047bf0ed18b05875e67836b79eea47a70b3434e07077cb4e4af8322306a3eb95630ce4e9d256d197f1b04c26fcfc2b7bce8cd907d3116afb2b01094110081dda39a38ee44e20512489c0745916da7d0ae8d582f86b0c80f6ae6bf632c16c50c724089ada1924acef402f9e1be991010001 \\xb7863c7c98e470fa10ed12461b15812b1d3dad5ebd8529362a375ba934b9b8b5a99b18db0318e27951e6e9fc88586ec3c988843d4b7ed306c97870eda15da203 1681029367000000 1681634167000000 1744706167000000 1839314167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-177 \\xc5cd22ba069e748d8bddeb1fcd4a43a5b21f42730ef20f2789452fc73333cbd5e159456269c1c28bd3c962aa834d18d79a93e70b0d6b59d633c3c467142ce00b 1 0 \\x000000010000000000800003dea77b2ce97b8a9c950ec1b61c201b61fc41334a8aedb2f9e17431ba5a3902461a75a9f1b2ef1f89bc0c0701ab201b2b86627575279397e8666fa5f5ee10b5e2727498544ef420c7c602189c2d4721fa45d4902009ba55fd4adf9a7fccf411a4250029536cdf00c6f91114635cb3f858fb6b13a5d989311269f799925b257a39010001 \\xdcf549258925f5a34f9af89cada05213965494973024a3d0bba2ff6220531ea1916cccd1ed34af1260cdc34097f58210e73858b2d592eb71ce2aaf226abc2b0b 1681633867000000 1682238667000000 1745310667000000 1839918667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-178 \\xc89de1e180ea11ff81d1f73ceeee0d73f3085fc525847a0837cc23131022ea4b3aaec97d966a2cc081ae9ddbfc564a06b4a6c61cf4418c3d7524c44fb6b68cfb 1 0 \\x000000010000000000800003bcd87b362dfd1659f0fe75490b6073f5df5fb2800c2f782bcbc944ea69080f809d0af180a030819c27a740f99013cfe06d07324d024f1e2841490823859df53ce6524b9713e4184295068e82f047fdd149b6bf09e7740b87c8c57a6d6014fd0c00bfda7a19082789b368a0695a4147f3c11f7121aeecaaa0701f91258edc1e65010001 \\x1c2f49f9e50cf4d83707dd1cdbd0737cd73c3a68dab95026b535b3417272f283b6a3f0bf2b50bd9e8826d0b473ae139f879fc8641b1da6614c44eadf710adf0a 1655640367000000 1656245167000000 1719317167000000 1813925167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-179 \\xcbd10b5cb738230ecf9a174d8bd44f89ef4a6a030418e695edd52d8c783e5aa126e5f65a79678cb9e93cc7acdf79ba831951e36f011c2ff4aac4e320493a709b 1 0 \\x000000010000000000800003b64258f531113a0a5334c4642829d898867d5cbbb33e51b60db1dc5d445ec45f98b7cf5c55a835677d234bcc8d719635fcab43ab7851a2dc5fd185dd6307a0700134b489a745fb1c52ea843df27d0a2c71fb876805e0576b753f8b36f29b0e2428cd6be07b70b01c38d283393de4f0b8a70ddf7d1970036758e701b74a943133010001 \\x0f77bc38e35ebec1cac00a619f1a176f97854858127bbc85d753a2adaeaa627292a34ef621e2bbce6b6a20f17ff5626681a3972e5d6f19a63616501681c3190e 1678611367000000 1679216167000000 1742288167000000 1836896167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-180 \\xcb0d788e8a12ad6c1e73fb78de8c2d2a77e7fec9c768d1f664d6030b5bb0cd77006249a86705fd56b961082a6d3acb0515918ae53d77020f4cf113487f808275 1 0 \\x000000010000000000800003e0d53491c22c7a0836a38c0091e6132700f6ded768a9db7f58c877f3cfc113c883255b52b9db7d287e08f51bab87d72e4426ac388f3401c6566072e0d6fa6b071f7f87a5f004162556a8826f29c82b4da37491944109c96272af080c30f1048be527a5696aee6ce72b4cf7556ea94271f4cd8b8ca68ceac50b4492b0208e3d01010001 \\x92e5a1f945d8fac44126c9192522e143dbcf0fca7be29ecb9cc300e89f77ca084499877ad07f84eb938a8b4251cd2588b1512e98200ee72505a6afee911a390b 1659871867000000 1660476667000000 1723548667000000 1818156667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-181 \\xceada1eae8f2ff59608c1fd76139a353fabacb46d79d574fb7de96c47c170bc2e306cd6e3a5a8d09afde72d40b308459032e364ff33ba25a8cce356634ef5aee 1 0 \\x000000010000000000800003c53740c012a194631f4b099801701a95da3886aa728c94eddab0bffe0e589ff62a759a782be7e6c90cadbd74149e9792b29621bbb4a7b3e7c753ffde6196bd556ae6f8560d43cb386da500b4f9a85358fd6ef669fd1ab6f0c77e7d91ffd98b23fefc2d4224a6617aa7e35605452ceed117d0f678a44e28ebf8f386aac402b0db010001 \\xad15c65978cdfdb0b1dbd455f653fc28d1db2aa2e69fd5996c553cbd4b552179e46a5e96b2b3ed9d730803d7b6c7cb1268230f3abf2d41332a33325063988c0a 1661685367000000 1662290167000000 1725362167000000 1819970167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-182 \\xd2712769942681357f0b3462253d10d02016e5b91044212b75bc1fa884fcbc1c6ef9ae17595565c8dc96b7ceae4dc8773a71c3dc08940b00dd27996757eafae7 1 0 \\x000000010000000000800003b12fc115029b34ff33a3549a63d65082e5f3715e3b2a56b10792162c13164ad40fd69942edc1c12088cafc39c4508f767fa1e422da20c435e463bdeab964c250421871d6c43b079e47f5ee05d43c12a3092f48eb15692ae8a302199c9935353388af0bcfa44ac4025f15b308789b05dccfdea6c0e41e365aeb683fb7440483df010001 \\x311b662751ca1ffdd3f6067b5cac212accc58378dee7a1b3fabaac247cdce0ea2ba437e898a11c8d97f8424283083a43c3d471a8235e0580a59dc7cb0e15e202 1660476367000000 1661081167000000 1724153167000000 1818761167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-183 \\xd25d04b7045f5060e86670f701ff63d9ba8d3100091bbdea457168cfcc3ab9cbfb29dcc24f718c1c11a0580187921f0c87ef31325cf4f8d40aff366031bb21c3 1 0 \\x000000010000000000800003b3c387525a561acb5be802e49e4c898f66f9b4095a2e0f7c8bdd5ca91ec3cb77996895c2afbd93a72d12261904d42667b44f58ba764bee7543e39d660566878ec2b6fd114b5e49b84916797944f68c6fefd540ee584f131ebb8a4938d8281d89c89859fb4d64043039d90b6fa9d1caa127701172a5be991ced08b52e774d9d79010001 \\xcce1af14b8b70468250c2b22d8f4aad94810d89a436af2b38c77f686ba422200d9839eefe5bd94b1a51e8ecc44d952ef2456f66317ea13ad6eebded60994770b 1661080867000000 1661685667000000 1724757667000000 1819365667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-184 \\xd4d5410f704cbacb1d5ced921b29e20a65b651a58ea6e7b46efaee33d31bbfe71d72237a77a4207920b802645c50a243388e886c8ff754c24e7b29609a7579e0 1 0 \\x000000010000000000800003b6ce294ba9d70943672be329f5e3d6631004f77d80608234de9d0a3fb77aa4c12ceea132d2685fb1ee1f454cad7f7ed36f93a532c51ecd17c5fc5c633be3e8db0c4b0f76e10d42de621a904e3d8112be476138525ed30e0083be719bd9e68be5bdf9ecd9c75da25907fa212565c8df5f19228fc920b312999d82ec8edbfacf11010001 \\xe6e8ab4a26ac771d4fd46a8929e3f71985bad83a036f76fe94546e1edaeebd5342d4221e38c922e5d5dc919ad4c8b6702594deb9df2636d03834d6ffabb12205 1682842867000000 1683447667000000 1746519667000000 1841127667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-185 \\xd4f53caa47346b89b8270ae073bb25fe9c9de4827e3e16f550279e6f04249ebf2976f0a4ca698ecbe8b21777e53c824392f9a4273e3b4816ca99c6d0745c01df 1 0 \\x000000010000000000800003edeb3074f7407daeb447836d808c2293f3465c562450d236134c2114e73508a113680eebebfaf595cf9e2e415d8957337cb07fee0af48df087b9128678b336d4675a9dbf76aceca9511bbe21136cb024dffee27b8c35f785acfa27dee47b4662d62c95c4b15d918207e7c0900e123c2d0c213ef00684e048d88b6536c9315a97010001 \\xca90418e1909705654be3a4a0b3a5e5d0fd2c9e98f04357a2638296430bb25866947a0e334b86183d652f5f1c74c90b2bd2294ab1bff4b062630b7cb74d7f907 1676797867000000 1677402667000000 1740474667000000 1835082667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-186 \\xd7fdbd925000f82d8c8b0da1fa64ca3c286658eb750c90448f403e62a75cca720a1d844aaa9a508d106f594ed29bfa91ceb131d1b1ecda4f77f8739bde0e7bce 1 0 \\x000000010000000000800003c6ea6c19bd7e0a9734c3af7ab599131237e4f7c60d49b0d4f94f2e7524f0a6a41f203fa92f334edc38b75a625568bf2b97962f1f9cfb9de9da36aa6235264f547d53c78baaad5b5970256dc9d5c99885efab86a3c1907c77aa19b58f60dea876e48d0ec9c310c7d8c2c45c038a83ab9f1d215573a255c10106b14372bf7a3ec5010001 \\xbd4510822a2e0dd5046e0aba2c32aa8ca2584fb624b8af820a1e98d59b39ba4ac438ec3bbeb5840970da4346f47c82ce675545b1087360d7efe264f3e3e2480e 1671961867000000 1672566667000000 1735638667000000 1830246667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-187 \\xd80dd68c94276e5b286c645e8a76b38e657dcd388150bb5561bf413a6c44f16ee07138092a29aa4691090728fc78745e822e75e9b79521e148402db861c5bed0 1 0 \\x000000010000000000800003bea60f724f8c9bf1fc049276924a8b96bf4c1d33e4172fb1b8bbf70fd480a8d2b9ba5724d40b15a653502940482b674d63bf585ad7531c66259d49639436bc043f7f70cd642a4989539a9c53c18b44da518949daf68cada7304b84e8c0b0402212b7feda9f2ab8aa3afcb50467e84337a8d479ae486dba62e5fb78cc271a735b010001 \\x07f4ff15c2c0b46898a82ef1d99297fcd0da5d784dea50a3760a7fe70478defe581736cce38432850e2ad7c397104efa2285f32b382168d06654376063ffce0f 1662894367000000 1663499167000000 1726571167000000 1821179167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-188 \\xda8dcda8cc1d586b0301e2434ff1f089af1da88173422ea2ac1a47bce871488181c355414e8a9588a67c7a9763a2c9e3e3085387533c49ed3674922c5544c2df 1 0 \\x000000010000000000800003976a37af67ca407d58d50e002a8ca8c70dcb8365f00dc6a601bb12d29c46c6e28c6f0d983d0052507aa24f60860fa4df805c4ffc79ab3ab442e141afa61c19e120116d8c5be3d9743777d8b8713b739a345ce82735dd603819658a2048c923dff87334178833b4c7ca79cda25d9b9ccb8ec067a21da6b64660baaaf2d63d07fb010001 \\x8fcbcc34524e24f76ef45da47d82ad7c32f2511814823d9a57b2a9971a8a58be21fea2c3f2af56d5bbd6cc4e57f8e6eaf0e4530ecc4e9d47ea3b334a0f30e70f 1666521367000000 1667126167000000 1730198167000000 1824806167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-189 \\xdc8107ccd95b47c5c81d0e64ad1a6d81011c3b27baf67cd56c1ebe5efc42cc3ba4377a238172f440abac56f16e68421ab0fd1442d20081e75bedcf0fec6695fc 1 0 \\x000000010000000000800003ca2d5d3f5bf17dd4b1057271287c487563e70694cdecd5f6fbae6ef875c55e17cc57124faa522c93d586bdbb34afbf81930ebd6e1f797a5353ada1d5ee7e16033ef120bc725680578e6c5ec909526eef7c64c4ef3e7c615c4f65ac920b95fa4a6ccc5fa1d5262cacfd4f92493099e56764e6789d67285488112a169f616625cb010001 \\x6a76fb6d5bcb407db2513d8745ae6f97c23252e5486a7610563ce698ea8216c325711ea98c2f821da6c01a1d848bf4871be3d0049c5311f0cad4e8b2c2cdc906 1667125867000000 1667730667000000 1730802667000000 1825410667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-190 \\xdda5883ecfaeb1083241d4fb64ad5a8c8bfd0772e59814c81e88f47eb9e6d5a3a7ae80ebbfaa6c2d879760b4b312d1341bbd0fc221a961706cae18bf43705072 1 0 \\x000000010000000000800003d94c78cfda0fb4b8fc0ee1f18bad5317cb283818cb81783eaad5d877e6b90271aee7a51686834a7e9fe30de1a25cdbce1f39e8e068bbea426f00033cda80b82d8eb94e89149e875b7bcf7bdb615d1d6930bb5d0a79cd57f20fa92d921bbacd67f40a4f20213fdd7e1d43669c4b297f6a098f7d6231c6ecfdfbf7a0cf9e33c5c9010001 \\xcc7c2766ec036a8a06a1f1466cd793d4e66d090ce2ebf27e00b6e858b6880c6e54f7df72b1bd7af3c02facafffbaea6d15ebb42ef6c3288af02a2532d465cf09 1679215867000000 1679820667000000 1742892667000000 1837500667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-191 \\xde714a3860ac78202de1d8d1edbf3c82fce2ece4a7dd6ac8c7016dddce6f1748561257480655b83d8eeba2526a09843e82ee9875706a314e38383b7ffc4fb73a 1 0 \\x000000010000000000800003bcfb75d98d599f3b24882434d4a1ccc7c2611eaaa8b1c6c27ee20f5db2c795b1ae02f262949411b8dbe4ecae8f23b394a5cee4eddab5afc41660d52323e9fe4a03634082191a81c72af9770f28b228e62e61a1c3719f323dd7cb64bce3f1955535a25f02db41850ff29c2945f94af79b19198a25d9b0ff70e70286c7f01dcfdb010001 \\x6008b78bd9fa0ba5b442bf32a48dd2091d43b05d988a0f36f75c36983363f700e59212b46fcd94dba5b0c727a9deb96ce2f06a160d90504351d60bfceea51301 1661080867000000 1661685667000000 1724757667000000 1819365667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-192 \\xe4a55ea7b3ef1ba025d559653074c5963d83c9e40a94ba28f332a7dfdedf8ba93d4a5394110a26aa4be71d8c22f178f422de007b1ea004d65cfe43ccc5e053a8 1 0 \\x000000010000000000800003d37afe1e207e2f5a11073a947847b4493356b5004da72813f6d33035ea150c1a9b3ef527bc23774e05c7ebf5afbbfd9c5004b15d6af0b38e9e8eb1b8868194cc02fb09f5bfb5ace6277c003744a414b7dff4cfe6da5256bcd55fa312ed1fbcb890f9194bd60a110f4ea0b387a1ee483f51a5c7084f48cd6f24c2578f2fc306e3010001 \\x4366c8f4a380b9000543d8a96a91463f8e10cd8a28c13a6ef02e145d626ab4c5e97d4fb0e240fbfd5dc0199b786404544af2a58c7fcc74a5d8ed2b0e87d5e900 1670752867000000 1671357667000000 1734429667000000 1829037667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-193 \\xe71114a4407c947558332131f9339036caee54d5c190af315888d06ab5d60f20af3397837e9467c00c6f66b082c72d36cfdf5e9105fa0bbfb59f89048cbec059 1 0 \\x000000010000000000800003caddfa6762c88ecfbb2eebf76d69016844f22ba2a60fa59e0ff08c7964a8341ac173877061a61a903664f9eff7b9fed5a73ba3611d4d792cee0c6c904111c9f1baf2296b8ea2bb1231e666001bbde88d13576e5b24bba238fac5ac726dddcf9bdde51433a27a2d19e20acfe1a7bba95d9bdc9aeace6a5580139c4e8a6de62ae5010001 \\x9c60d1fea09670d51c58f92a3954d4d86a46ddb79d82b83bd4e132f21af1d8363619dfa5378bfaf0a5c525753da1338ca4ac1c8bf7110ed43026e9bf62f4e40a 1669543867000000 1670148667000000 1733220667000000 1827828667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-194 \\xeb3112cda81f8990122614a91394d0163140ae659da585af1fffc1f3b1add490501ff63527678257c6340d738573474d4de0f65fa4ed2ab0716c7a98c3a8e5ff 1 0 \\x000000010000000000800003ac364ae2c37395129222f94738a52d0d536f21e203499b799d56fbe54814aaf1b78f4396797da37b4f8d99e3106a062a29353c33942ac602a24fcc116673ca4ce267630ac8f5885e17e2cf468e92e08d09099cbb45d9632bbeb55a2b6edb77ce48b47130603bfacc13a1621ea7154fdb181879962bfabdb10c5e0449effbe593010001 \\x869600a24af20291bf6aadeceefff8669b837cac7debeb9018a763a858a99adeaa0e1dfb7bc94e6f09a13939257fb55ccfd4e4bdaea7b3037af887510884930d 1662289867000000 1662894667000000 1725966667000000 1820574667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-195 \\xeeedc9a9b6c6660f94330cffbede2144316356d027bfa2de6179b6e43591d030fd87792351d62a02867e976321db3df1adbb8b6dfb9c5bc780bd852db4b57a19 1 0 \\x000000010000000000800003ac25852b15ebabc9ed5c20a6c110711ae853d5433156da8bf03a0f2b5297b4c4d095d84b35c19431a99cef4e4295e32403ec42d70357df3722d11c24e0278c5ab99572908873e64369cc05562d91243aeb3e950b469ed0e7e5b58d1cd3eb798c21d83a646c2418a4eba7daa03f58be4a36bded06dca4890f7b8696bbdced90cb010001 \\x0a2ddd511742ae03d9a21fa48bdc97830588c78a607459b12e83840cb39cd44f3511c0e55e1957fd414a604b7db1827ba55e297ba7bdfd285f7278a854284203 1685865367000000 1686470167000000 1749542167000000 1844150167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-196 \\xef79cbcf8c014c1053f16eb81ce640910a5d26e325c1cfebd81ca2ef050f0ee19ee75a5894e1ed90167c51b749ffa99d34b9e730e3e36350a8725aa01f6fd1b1 1 0 \\x000000010000000000800003d0a5e7b7ce9ddf9b2e0289757fa729e80279cad3d6e205b101dcfe8a1ba1a6021af23e31b20ed34944fc37e125e7259656d0ea1abf47b76d84ee921c23a8c14a671bff0a01d10fb6db40308f5c49f1da2cda8067e3559eca74084f25bc8a7782064e74bd4e09da35362ba1e2a6f81e1896e723a53664ee33243bc5678e7032c7010001 \\xfd4f2dfa0df9661d6a8bd377abfaab901dddbc5c6cfc3a304154370f5985a825add2686bc0aea8d283bf21b3ffcf1106d6fab2102331ccb71f393135496e3206 1676797867000000 1677402667000000 1740474667000000 1835082667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-197 \\xeff9806f1dad8332a2ffa4e5ed32190c6bcd6044a2102b1e4d7f6235dc48b2082248f063aed388af5620f32ad623dfda50ab777f9f0419b2e629b03c79b82f8b 1 0 \\x000000010000000000800003b05c81155da5bde7bc9b231e29c00b9d64a93ee910415c0d639a5c18590e341cc5019298dbe529fdfb85fed362ff5d1c6d79ae3518d2c0ee5c4fb7ccf931776c65a1e3951b45d6b428e57878940f733185b1ca6af492f5cb3f98a9fb6a7448f2c4cf2017ff005dacc4df38363212b98a54fab9f25859bb91de95b86576875d87010001 \\x245a9b599d282299658177265ff007606a9154dceca4f173ad0d0a5dff839eb39e7f2eb1821c9072632d406def4a898ae9137bd30be39e15bc6b11cf996bff08 1683447367000000 1684052167000000 1747124167000000 1841732167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-198 \\xf1d9306060c1264396308e34e0fec9dc38029aafc99baf7cfdf61779b03e9f421397377a369c26d3c307905f388fb2675a480c622d8e8447a16f5732bf9f6c31 1 0 \\x000000010000000000800003a8644899c0f30585cc194f9c3fd53eba8314da0bc24803eda743eae5d7bcc13d19735124896cef76206a8c1ecb5a70b51e9a1c1c1a035ab53219bffba02c1f1b5c795d78766d27961c4ec23abb3b464ddf36f9c20ec0a90a0b9e78c5ed72ffbd0ef0949c0cf2495164377117c3292a23dc0145abe878cf198eedb6ca1172679b010001 \\xb6162915a590ca22aa6419673be0d1c4609940c23d2b0237f680394f729dacafe8abd6087909856eafc72e443376ca55d6ca48db9a1bfa5d36be2e23889ca203 1684656367000000 1685261167000000 1748333167000000 1842941167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-199 \\xf1a5607fc0eac2cb8205596003a06acae1ef4cdf39345d596a9d3b8b3a50df6980ac74ef3a3291a68dfcea1800ca079805682719c1605bbe9ab56fd95e3ccad2 1 0 \\x000000010000000000800003bd9e916415e00af539a294d31b85e5c116eb7ac2cb2fbef1852c37612e8ced8cbe52c1ec52809bfe542d7a7c1e8f863f84d793f9e6d188c1b764640f89b205fe19370d5982dbc6ac0785490c2e10890b888438255ee43021f6b63eea6e60d90b867b3c389b110907149b26a5d8c505fe83cc4a335dd936cca6dc090081a70c29010001 \\xc65fce06cbe17ff5d59c1b3ffba50444fb212aa30ff6969478d413b04afbb6764b51821584139828a176e4e58269c0b9ad9295292709183453602c5036e21802 1673775367000000 1674380167000000 1737452167000000 1832060167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-200 \\xf18d1eb13e35e5a08fb4d6dce186d857ec0e80aea12ec8bdc0068c9b182b18c3f0830fd73fe7c01fb8eb7482ae9059898a93f787812526f6a26b4da1cbe62a91 1 0 \\x000000010000000000800003c371fdfbf3d3f57202b59c14e43a724fa10cc87b05d8dcb1208b82ba92cedf65f287621a50fc4ce746bd5276bef390fe57178a4d5f5ceabe931e0c3fa262301856b0269e7dbbb2d4024e70bf8804e6fcad8c25eaead87d8c99d4645bd0089f803fd43517dd3bacd36db0568637d792e6b97b6da80b453d9069c9a8c18114620b010001 \\x2ba3e980d0542e01aab3330f92a9fa804f3ac9c4bc327be46e0daee89a87e2be7892570740d82c7a8795956ae8697f6388a4fd2804e93ae798d932b633e5850e 1686469867000000 1687074667000000 1750146667000000 1844754667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-201 \\xf2ad562c98a0b0d283f3d37c27d6e7d93b0cbc0a474963d14f74e7b94c8ea280a2d65755a5dc247760735474f3cf0613595c0bd211d6d76bba11199a8965076d 1 0 \\x000000010000000000800003cc88e3539033302a15a3eef03855d0066b7016a149153a01af57dfd4eae5c59da21a236287f8371af8e0326b46a8c31c2a47c723d74ad2d1d01dc7c100d380ff05f5456b8010707eec3df52196e9dd2f6789fe9a74be540eec020752bd21ebe0d924d7a153bc9e97464e164ae5f517f4ad1065be6c2a5dd859b41ae4f6f75943010001 \\x1795a02d88ac1a8a44f98fab427050e0e5f04e310228312b18b2d1ae43db98c0a56f698a508d0ab469e60961ae8729bd24b3af2fe8c4db64f62357a33066820f 1664707867000000 1665312667000000 1728384667000000 1822992667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-202 \\xf2e111a5665a172ad26067ed2dc8fe0cdb57f854617fbb7beb01b474dbfa8fdfec0e06a3e055d1369c1851a701917b3267669803687e478f7a86f53e242b8011 1 0 \\x000000010000000000800003bb397f6d9480d652e8b46514525318ad71c8c8703d252901876357d1559a8b195b8486c5b19b64bc2e7dce23bc33b8f2056ff2779d635ff1b5ef9c826e33e4eb7766535fad3477f60112d2fadcdec53abee2bd8761ee28337072dd2e51e0cc78f1a3986bfe98a8860fba3c1be9b3deacd2058dac02297171ef1047daf2391671010001 \\x0b3549248be140cd7886b931fef03c4aff2bd3faf0b728d7a88e5fc4f97480e344ba1301f12ce91c91a12967a1d70f1ae8838434b0fb97d52f55c4abfc69790c 1659871867000000 1660476667000000 1723548667000000 1818156667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-203 \\xf3a5cb21772b829f81e9a4a25a223679c120c2f9e4c79dc3035b49b27799cd1739f469324434991ed452c694d9574b2e23a2df6b615f98ca8327f4c5685b1763 1 0 \\x000000010000000000800003c6e317b99834ad6b87965b31aa38bede7dad4f304827015394531ad378c42654f38cb9221dbf2ed35da0f317d7deccb8af4083e91cb3901d20beacd7cd651d3f019a14f670975c01c8d78223f894c43979540af85ea0291e704cf10226b70ce6736c8345e33b383f4cfe16344ffae6a530215e8179f4e90fd93face240c65a35010001 \\xe37a7f5c8c4795651a08b243f1623b80bebe88088e0ad881cab97c26952362973293ba91a532e97f8c3711a4c431877261d941bcce1d5e36ca54628b8d16bb03 1683447367000000 1684052167000000 1747124167000000 1841732167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-204 \\xf3653859f56ed20ac1400c76f7a94dd275ef3d03e1dff130a0d35b9b426c9f98e0d515a0b3980c69fdb2008511f3799596ef048f0c6120bfdae54e3c0c37e942 1 0 \\x000000010000000000800003baf400d69a6eeab29e55741f9a46f06175eda1af59038c3ae9f61f620b51cd141554ce27a428d66ab86a48f45ead7b497b954f49b7186d7c4bc8b31d171877a9f07794e67762109d46bd6850441ad65a7208788f5c8e5b2a0845954a1b54e2e6d58eba2f8fc58fa7b6b151a35db2c99ecc1267aa6bf8de2bdb2c85b638742f0b010001 \\x6cb747f142cce1e95a7299bd3e4a1291bcfa8e7b2faca54e2fd6e16950e12a778ad603072da7d72949633076d8a7fcd109c742e46b9442f6076a1666ad49140f 1682238367000000 1682843167000000 1745915167000000 1840523167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-205 \\xf35568db2f35b4190669b9ba188e35b539a0b035127a33cc65bd3e74f1e8f12c24f763812d37af70a66413d92a4e08a8284cbf98719c0e33d225b0205cfe3f8a 1 0 \\x000000010000000000800003f36e7b3955dea99dcd14cb8d2fc14691ce1319942a443437897dc7c07c10090dfd0ce25e7fd423fb83e50b9db202aa184ebfe56075955f358162ec6b164291b591668a8bb20b744a62957c945ace4cffd03b4efde09094ca0877d593f4ddd6a787397de774be73d003fbb0c5825fbf809be46df1a4011e928d1115f4b6f23f95010001 \\x5f0d6f953747cb6a1f9bfe5666645f10385bc8c9dc21bf402e51d1b92f5cebc5cb339a064079b9250314ae9a3162a0e71b2309d368b3dd0b58344f03ba83c60c 1682238367000000 1682843167000000 1745915167000000 1840523167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-206 \\xf3751246ab836dec1b8e90286106f5a205a39358bd347613fd05aef2ef9e3e379d68cf0134481e2c51f3349234b9a4309c64508bd9cc0c66db4c0fd091fc84f1 1 0 \\x000000010000000000800003c853cb2c390429f2eb98f66f599b40425a50fcf92448ee7e129407d7513c4ef92bb8f5c59d99a1746e6277da5d4ca46c25b601dd583925a62314840ad1ba9bf1c3a84abcca11a4b6f0a581c85ad261dbd10e6c2773e611e2df75f99089156f49d4b8e09c0256c05ac56933d2cdf5ae6fc38c9f2bd8ccd7c8744d501c154de0d7010001 \\x0a9f226732f882a87ebab8f892ee1262b490af1c0e752221b2d2777d7b560d0927395fc533018e574eb63b04a2e6cf681740ad1d05464ba6201d85568cc6b70f 1682842867000000 1683447667000000 1746519667000000 1841127667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-207 \\xf50d7a5c9f0311a727ffb5cdf88b277ab01f681e7fdc3e8a713c675bde920beb22bcb4293d5d3b22e08e648229987630a0853f0169688a4f97ecb7cec030b138 1 0 \\x000000010000000000800003d66d83a890147817664e0eef754afd9a2dfac43c2ce6b02286348048e87f0e294f051909353c79a6653317b74610fb08ddb9704520fbc34880325fb54b766ff92dcf19d1443c0ef9b824ee2e91f773006ed091dd3177a11f60ec2f3815f7552859a7bcca0cb33131b14490de9305af772e8849103f5bb8fbdda5fa227fb61db3010001 \\x577a50f5c967dd4fe7e23383669bdc3c7318a2abc304cc1bef1e0497cd29de4ab92723955b6319b714914583efea57440e17683201f0b9fd1a881842bd25ee07 1668334867000000 1668939667000000 1732011667000000 1826619667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-208 \\xf92dd35f50da0f3f185963de9d0509a35ec745dfd1dd4119e2628c562627b03e9e16a9f579bf7d7fbf619398f33b8766354e15cd7b46ab1638c7cac89dfa526e 1 0 \\x000000010000000000800003a71075979a888bd4e33ebbbf1556e2569ce4d2a411c21b6fa2d0dba6a476984e0cfa2fb1361ec003852ed4e1048502b91ca012af284f013e4b200c77e41c9bacde7b340737f965d2fc478c71b71d35b020835806f8d7e862903f97c46da7cb8e42c5eb52a3758396842fb23a7010f0142ebc46688c5938a7207f904cf74870a1010001 \\x439cc2502658f151d628cbd8f50685f340294fff45048e2af2f12f7cee115d730a4e66b7b0e64ffeae86c0ac882319632101b018968f0d1f638995e6d42c7709 1655640367000000 1656245167000000 1719317167000000 1813925167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-209 \\xfb3d303c6e8eddb1525a96aabd72be9f29327c7c112e8e51608f061572e8e4c2f95c720ac4f7674aa0123673b1900519d562d9f4fe9d0b0ec042c236e60743cf 1 0 \\x000000010000000000800003ac4d017831769afedc686cd87921695095ac5d393f4073b9070db49feed64a0d95cdd32bbd45bc6dc9e1cc5431a36a93373c691c2c92a7802ee0060cc56e9ff75afd3c66d15ce8c2c0af31880f1c432c29a3d7814fed5c04402d3a53f6335f9769083b34d9c4273f25fa39a7d3affde75dfeeabbba4b6eb35483f43168728da7010001 \\xfa8e13bb2caca4ac76a69d1e15af903dbb0918482539a1aa6de4f4afdefe94b6116667a211fd7a10e9bc9461652fdbaa3b048aa0453c6a9cd09a2e4e7ce6fa0a 1682842867000000 1683447667000000 1746519667000000 1841127667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-210 \\xfdd1eda7c93dfa92596aeb2b7e184fdb8f7da1df12459998399918d70c0261c182cdeaab48696a51fa37e83db6f60fcd78cde78c6e91d8e6c2959e08b3c48351 1 0 \\x000000010000000000800003da9d7a9c011b650dc47615403ccc14fc74f83d42d272b327fc72f4f22ad455b62f64650bbff3e4db18d731d1ef42621aa2a5cc664d4391de0c3f75a1265192ff2cec04743818ca61bbea2c49ba08df60567ed007699090271b0501082c558a8694a3a4e91065faa9b68daf5c3b9ee7ca2d8844cccc3b1202d6bf13d9f64666a7010001 \\x6ed34f135e2ed71a611f13543c55a19580984833b5c2477a1d55ac3e4a828dfab72b90365fc4cf4bc80b58afd6db427afce7ad0dd134261b256efbd309edc407 1664103367000000 1664708167000000 1727780167000000 1822388167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-211 \\x06fab014f0635b6c8f07ebad03069396c7b983158298b2d40a21aa2505ed74b9f326e3e2964d3bde849f33cd315034388966d9af681e2502d3071b43c48f6403 1 0 \\x000000010000000000800003a059f5dcda9aea2ee6214952953ac77aaeb5eaa00b19e6f1e4970d9685403e5001fa54192603016d329bae53f162fbb131f9eaae32483aac0970ffa70eb40bbe06d1a5fa901e526a86d2d484bc0cefcb0bd952ec4e2a46afbad33d914eb8d394e2f828fd6d2bca00ab8bc80bad88652c0b55960fecc7ed00b140ae06d9833923010001 \\x087f8903e436c149560fa1f6dc7b5dfbfb9856b63b47c7d15a3079dfca5d76e8c0d3ac99737870d74d3a1d79e94ae531187e55edb74961d8ed43bc4c9501b60a 1663498867000000 1664103667000000 1727175667000000 1821783667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-212 \\x114a007e49296b89888b6e6cbfd77ee41937a16f318e81a025eea37ba8ffcb85fc92e088a9a7bdf4cf8eb917a997fbd223ddb681e0f9b48cc9a12cb7c675bcd6 1 0 \\x000000010000000000800003e3e045a0cefc4776d623ee775cbfab1de563576558c5d7e60bcd654bb23bd2a1fe67f93efd56ef7fa5faa62d73c0acb1385c7bcb0d7114050915e5bd14faacbbec7fad4b34a2fec6f7d7bc0068ae97725bd5010f334be163eccabf8bf6c4245ceef892c1524c77fb0e4b71cb3408ccf95f0071904edce01ff98e2e7582d30465010001 \\x8f6e026c1043204499399a4ee95702b203dddb5aad8afb73ab6a5d706e199a82eeed272637aeedccf5b6b40869c8fa45c8764e773b9d8c474364187865bacf0e 1671357367000000 1671962167000000 1735034167000000 1829642167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-213 \\x1226592a24a136d38f453f1cf7e82cf76dba8e2004791577baa2ef7c73adfe0666ed6e2986a1f9de5945348d1eac860edd59d87f4a17073be17969473de1dbe0 1 0 \\x000000010000000000800003978ca7b0b33a324abe669783105153e4a750ff680986517b7de40a6ceea99392a38e2b3747134470212f483f9a67acb58e57361a582738c6951482b6e4277570a3aaccf8603d116de360838ee1e1bdc0589fdd9c88febe332c6f6c09d8af9e4036d891923540e19e94e0150c877ad2f88dfb9018ce8400ffa4850db111900cbd010001 \\x2f85497b7bca775327cc5504f07f3afa121dc6b510348f2a11a55638ac5631df5bbcf222d70ce20ded4239d3c5b66d454eb290b81f12c98e3762b851b08c060c 1676193367000000 1676798167000000 1739870167000000 1834478167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-214 \\x14b25bd0d4ae1a3b71882b4d8c11e9a8564448923c080ac780141b2cdb188b574c1d3e07903bc6cd98ee7e4de486078e210acd48083b9fab9893aae5986da685 1 0 \\x000000010000000000800003e03718a5679aec850763affff435d3245b1c386314dc9da1001458782045e0266464a3783739b566192734e1dfff1f78dde32af3bc08dbfeb71767ebe7e3b0734d43a2fd7395ac47e9a7003fc4b284f53fe0724e24854ef3c3526f829f2755e53841be997f38e8fa256c1e01a437aa21b26e3f964de9cbffa82aa1bd7eede4a3010001 \\x02b104ef188a227ba4d235379564b2d27aeecc88908c3c675df7c32a96ee01776cb95120ff0854a964e2af723b8d42515b62799d2bef25d3e3c388b62d2b4c01 1665312367000000 1665917167000000 1728989167000000 1823597167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-215 \\x151e15747c771931769c2ee1a0ca9ceb91587625f98c467222ff7fd904545747b5fb509308ac72c670ce67d8094c41300c66543ab183d846e474e3583d2b0947 1 0 \\x000000010000000000800003c7926aed39620879873bc93e56f8501171a6cb765e1086b0c5c448194a4663b8ccf5aca944d1962cc4f4fccbd8368dd86fd86f2c2e4fd4da654e343ea00a8375551ab5685f511f32ddf6765d0885739b57ded2eebf2113227220b4aee457fb6912d9377d88e041d1a632170554b02e32e2144455f8503b7b339a1ea023af4e7f010001 \\x5386f92764214bff46547f8e33ba00dcc73cd8f1ffbde5de6838b5db97f5ace91867a693c259cde40d75a34cc73a145fbca98cdf3917fc4d8f6e8f69a3487a05 1660476367000000 1661081167000000 1724153167000000 1818761167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-216 \\x156a1a11c6f3989716a90c0d04e947acfa653e0ffc76d5380b19cccd5f548695c9c7b217e377877c83056a45fa3f4d7c7bb0f630feed5a9b5c4fe64e24c64c03 1 0 \\x000000010000000000800003a9155397d6b06d44f49de71e1bf066b8d0de9868eb358f8f765b81d307cd4dc92aae43d62c5d59746faf990e1968908bffa9ce8f8c42880a2adf2464af9bf32abdeacf82fc5f91769947f7fde7bd2fd043a68a8dd515594cee54bba6ffffc9d3d92677b8cf1607040a0122e4801d5af030fbcedb6a17463de725035c00d2c67b010001 \\x4122186816c74621b4c8ffe773db897da46a70177a7ddd9694b445f458e38439866cae43e52903cdc168be5f4c746b13e6a65e9b7de142156ddae40d4419ac02 1658662867000000 1659267667000000 1722339667000000 1816947667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-217 \\x17ca5862c5930c71ea53f86541e4520e5dc81393a8ca9d24fd8e3ecf441aec1c583f28b65c436c0d08689ace01b85ad843adbe627e47ee25987ace53bbbaf32a 1 0 \\x000000010000000000800003bd0e21aefd799e25bbfc7a57da20f701f7a4ae925384b6b533aa46d35320cc572ad12174cb89f5d9f3a6e24ffae6cd0b66e1964b5899b37ebddd58bf389cff7c279cb07667ee588205dacbdc066509c3428a52ecfe607293fc9905abe35a5288f34fe3c80b99a91b3b976cc026577d290b9655af4b0d21ba0de76f2d2e52bc8f010001 \\x5a9791692ea895db66ef310f65a487ec0160d2332c2f1343c39aad96c781b31f9c6cbd40e77f3cb1aa14d7cbb21da66a294ea6a8bc2deaaa368af805e14cbb0a 1678006867000000 1678611667000000 1741683667000000 1836291667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-218 \\x1bf6df01848f18c25f7c426b2f0aab9b952ef5a7b92c9ff8dd20b2f9e33f8d1c6e2b1a060d23e8ada7cd7007bf72eeb45c49df4573f566ca8ce1d5c4f0db0366 1 0 \\x000000010000000000800003b9a770901e3e6139560801c17c0601103d70d551a2e268d2ee10e53fc09dd12b18366cf1d93594d5b06a101b2d4f829857975ba672b5fc236c36942203e338f6e0aea93530a07cc963bec9dc953baf6758d30cba5ea8d617e69be2d14ff99a1721bd239b3a9763f160e2e7f5ba9b3c107d913a21d675e488bbaa702feaf2a6d9010001 \\xc7b358acf8342c47061270d00742c19c45780c19c343f60c7b7de67bda914ed5c1ae26a2c252989c3c1a94aa9b79daa0a30efb9c0d04d625d1a912bac9a6fb09 1661685367000000 1662290167000000 1725362167000000 1819970167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-219 \\x1b6e4e668bab76cd6fb264376d1f4d7f25fbaa64bc0aa0746936ea8510d1eaf505eb6493dee8f59e5c285372ae22c6f92d365fda557422b5f82f0e483d12fabc 1 0 \\x000000010000000000800003ad57dcc91f5630b629046f85f52bca60168220cc10cdc59f3ed73057c883738d3f503f596bd4fce18e2bd45b137a56e811f7636e4f624fb4e239b23907a482890a51b1fe46bcfd3742105cca31fb6a8325be8b69727dd06277abc70fb405dc439bba4759d294badea02de68db67c14c5787dec8b2a420c2a14de10afa60b1775010001 \\x0f5588217e80dcaa6a4bf1c071e727f82ed4dabd3a1f44fa17f7f92312fef1cc7036887838449e0677d8d58fbb9ea135bb7f064f028ae5db292b81b8f9fd7609 1660476367000000 1661081167000000 1724153167000000 1818761167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-220 \\x1e2ec8bb573ebf794d3275b8605b869b10347fbebde7ded773d275bc3ce092f95ed05d3bcedda0f0c37370cd5316a0865b5db1a7864ac6393cfe60c93acb26b9 1 0 \\x000000010000000000800003abb4eb1fb8f1d0e27f095f95729725fadd43491c0a5de72a6418c32323fb3100d42b7592fd3d3e2bfa2e226d64921c38c58c785180f3acea8ede728ec43aa14eb965a13d0839a2e36ce32def0d400278a2490c93acee1734107f21e6fb6ef2460f1db346b87d66ba269987016eae1130df5979ea0d84940edac49f2406a676c9010001 \\x8eed482b3ed1c563a4d6be77f6168b38ce7c5adfb9ba4f55dcc5d0d1edcf1537d562257c0310ddff2252c5626a39c3e65b64571c101acf896b093ca5e5c9bd08 1679215867000000 1679820667000000 1742892667000000 1837500667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-221 \\x2676d09a1833a5e29a073e30684b4309538882748337885e211506c6f37651ea0d7d8f91b8df8f451c643c34db0e280eef5c8aa9a81aebb1f73d015147ea73f3 1 0 \\x000000010000000000800003be797916648f89a92ac828cb2a14e67cbc70233e7a80e03ec40c7ffc5548f7b547b3c0715d465b0c77375fdb3457e6ac83d7fa4f54d1fe1ced47202240e94c886045033f5e307bc70b359dfb79dc3cdeea365315f8494796a58ff46e57132c618c0f21b56f318cedcd7171ef17ab634c04e8d040b5743d2a648724a41ac0d63b010001 \\x26b60b9d2f6109df3ee425cd8ed6f88ec9c62530e475e8c3955d13ad192014899f630f4a476178a218b10fd8e2732d16802b9dd2e893e16cbe65cf1cbc26ec03 1660476367000000 1661081167000000 1724153167000000 1818761167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-222 \\x281e21c9be7a945fec20b0aeca1ee173423928aa0839490d3cbc55303c978b273cccf8fff8aea77fce82ec84a37bf2e55defb5531d08d31c2ca58978787402d7 1 0 \\x000000010000000000800003cda071b8e46a68810ee337d7cffc06d99d03cb68fb4c91d1c84239fd81f16a02a6ebaada3dffb6de3bc32a7c4ea8ec8d5948837df3abcea6a866386670f7112c254a14a3a3ff62a6a4479c87133601eabdbc85a08ef380733159d7586ae3f85863a9ee094d30f6eafc9a47832fa386a8c9fbe7f6f958170e0fd87e7c496a4da3010001 \\x4b1af57b59ee911cc85ebf8fceca8a364f362d8ad1f574802012583133a0bdbe43fb69450a1298bb47bca6ee281cc16131ad7f21d85d2c20275c6e877bd07002 1659267367000000 1659872167000000 1722944167000000 1817552167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-223 \\x2a3a9e1d5b2980b3463528862dff4144b2ac7e0c6ffd3431906c05f42cebe8b98c02d0ea5fdfa3ce1c456f89eaf08292f7993d0888de6537b2b9d24d09d031d3 1 0 \\x000000010000000000800003c2ad185c03295b1658b99bee2f034f40ff9591cebd7e69e1255daceae3ad2487e3141ba8ca9ae0fd34170710a0ad125388d79ef27966ec2d9093bc3092ab3acd43aa49f54e128758c8fb78ccd2d8a138ad5132da0a530672eece340d2d2cc039213e67a96a0f5db294e52fbeab0471a833714674b61969f4d1acb65bc99c3bd1010001 \\xced34990a6cf2c0ef4072d2bd672446b0b15e59220889d93300b60cb8277b296558f9f36625054b1a945e360c239a08872714807d74fb39afbf0faba4e837004 1658058367000000 1658663167000000 1721735167000000 1816343167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-224 \\x2abac246b8714106e96601c02a1aa2890fbd0d59ab6a4d27165a370a56dffd09f862f68b1a8c7e29825d67082d12a78c2358d44ea6819cbf980e60a781ea18a6 1 0 \\x000000010000000000800003a4942c3aa4bcb43e622dd116bf675a252c59d69b26724e64aad33441b1d210f551bbdad50ee62a0eb47c3bacc18a7a9a37d61f8951db2049bec9d69e42744aff106021a0582ed94833a83cf5c16e8175a8a038ea49f6aecc923f0f372d775c3a24de6597578fd87b7a244db816aa689c0ca877a2e6bc3e73a358a5627957d9cf010001 \\x50548fbb6bd5d5d6739fac5e7e7fc0f766a2d5b80ec626d40da9b6fa1c0e3881f66fa777dc4609d8c5ddc4a5a5312581d4089351dde55fa5b53b7dd0da0f670a 1686469867000000 1687074667000000 1750146667000000 1844754667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-225 \\x2ad61ed9dcb20264bd0b8833e1c2570d99f842437a8265cbdceaee1cb27eefa2b3e64aa9163ddb5c840c19f4d30a33fc3677c241aec7f019ef236089749fd53e 1 0 \\x000000010000000000800003c8ace5c36d1387d0fdc4ac82b2dbe087ba8f419367da464523c4d7d28f75c6fb86ee2afccffc00205115744f3aa0045cc28262097ea1db0917ed8bfb9bb11d2907285c0dda465ee859a807c7bbf9fae8a38876bb458fa54b90b3903773e3c96c2070d280e39292ac3813524d5312c28d862332ee55218b26e90a8bd22a3f90bd010001 \\xa6fc8064cf5057b0ac96f3dbd4afb48209c02b32a4099f9e7f67b012b8486661ea9294bd7a0a1ede7b6e0bf5aa1a593539e542be79655552b64628bf79502702 1687074367000000 1687679167000000 1750751167000000 1845359167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-226 \\x33aa8a0c6c6f30da54099f39831d749d94c6a1adcd80158fadf1b226cfc985d728b6d8e03cfb43f03db2ce09ca87eeec8e91f0da548e593af9655034a8ab32ee 1 0 \\x000000010000000000800003c1696696db270af1c6b2bff1efb95b02389215f0771638e24d6240b6f305ff662e92057bb9b66fc9cdaab9f5daed9702823c0b933f9e7c760710111b268b3a91bafd3da516aec154cc3b027ce280e087f6255c15981bd1f04b13a0f9e12b71c73286173d48deef85535634b54d5bfdee32f64fbae5a9ca0845e60702cd20a9cd010001 \\xfc47a5f80780a3cd38c775ef3de945f79f1e24181c17b9b1db77c19c81987343f3b2c0bb242e48995a49ff2298a361cc90dd69e1a26709cc87e74d4e456d2f0b 1669543867000000 1670148667000000 1733220667000000 1827828667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-227 \\x3686467c8e0f9edfff141cfe3b95929e3b8076da53ddbd0505ac480a130c89466bfcd75e042ea490259f992e34ab4ec78cc92b4e41f94a81613e5379a501dbdd 1 0 \\x000000010000000000800003e432c69118fc43a404e8faf436bea4883ef446c149dc41151d40d5d7d3d2cb687790def263ab245ef25c6539dae5dc601c79e8092b8b88914a2a88fa8eeeb084155b0a11c6a1999738ebc9d0c9ad3392dda4f9bacf4ec995793fff4b56026b6e93ad0e9771dbd1a4f0528980b333319291befb2e1b70a131871cae33fe356407010001 \\x970f33a906d9db7c47032c8aecdb1b70d1f543e6c41e839c11e427c34bb5c891d01a3cc6887df7750e1bba0bc0360df7f45a45bb022f7ae6022c85cbfe6a7b07 1661685367000000 1662290167000000 1725362167000000 1819970167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-228 \\x37269d107d9ecaff6d4698f31ecd98299ca1ec1875675400bd270358a78d503f75c2e402ea1fcdd7603ca78a7375db0d7e25868b0abfc96bb1ac7e40132c2028 1 0 \\x000000010000000000800003c6181edc81644dc91d49a6f379c5ebe9335e080135cf7fe0e0a4036b1024adb69a7ed86ff35e2d23c9bf0f299fc52a6e1e414099897279833e21398078625ab94aafd43d561ed5e95d1db9a0ac924eb214f2617628b4f97e6ea2b600641ad1e69ef37978c7bdffa8fb0af8d1148a64688e24206516628cbf610d2eaafec19d33010001 \\xc255c3fadc088acfea32380757b4ef357e61ce15c8e863e94584342addecb80d028bac3d81b20b0940574d540d6a51aae27f7f5d65e765e0fc86b87a428f7100 1678611367000000 1679216167000000 1742288167000000 1836896167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-229 \\x374e7af06adf28d171cf296dd34d14cdf4d5952dc4a35213e1d30445272c16fff70dbdcf950bf9c6866ef6186b94d9a253933da3e8ef9712357c19e19df895b3 1 0 \\x000000010000000000800003a7e4c8e9cd89b24847d5d54978ad6409a63b7ea64e07a8f7345c33d118833f9e787b20767d719e4cf1c888f3703f54a70f644f9f6b03e6918cd76d666a5bbeabf43b535dcd06e1d21bf1c1a0c17a869a14853a9acd4994053a0f8895c21a811589a8adbf14dd8f1f0b20494a19ce1cee47dcb0b2e1c8c8c0f1347500b1a6917d010001 \\xf7e271b4cfc493dcafd10599c6bcf35450d516e320be7c8a455267780f3368cf0a347d56ba2905e0c691d83f281484b55cf341e65deaeb3cfa9bb9a1c58ba008 1674379867000000 1674984667000000 1738056667000000 1832664667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-230 \\x4152bad66db5717722b9c6f18bb0938e4ea44f660dc0d78412983b64db3485c432d03c8bee99e1ea6452309475b79845ae1c23bce57f72d90c78e0aaaf93d828 1 0 \\x000000010000000000800003bc5e471450a85e4f7e9f9da1d8d2afa5a401907e3da23e63887f0cd7ec0954ce9bc3cfc7e3b24cc32d635797a844fff86a824bba0dc842b922f225af113f22bcf7caf761856bf293864e3ea404f09d00afd4b5021588f5d23aab751e4ea7006700613b565c99ccc07b8251084e4b1a9b89c28ba6c3b3e21344e5b1e3bcbc9b61010001 \\xdef6638a27e39c76bb547d9ccfe54bc7093fbc2fb7959170f41958a4f0f873bde0c522b1f52fa6c4632820669d4feea7282234820f1d65ea2e08c381d974c80f 1674379867000000 1674984667000000 1738056667000000 1832664667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-231 \\x466e1be3b02190db0416aa8487b1a3a0310b4e045d98449a484ea216d2f1182a70c8263b5c1ed87ac20b4158353aa9c391ea99886b6f6f1658c98bc8786e8626 1 0 \\x000000010000000000800003d4248bccab489e0ceb11e0f5b478393bc9a4582b9905f3ad9df06378abf94be39754bd71a1c590fac9c04cb55ed67c13011e17b334ea8186bd71164b2b466418eb26d7e6e478564b0acc949ee008901638d445b7ba4eb5b6054879addb9a46b6cc3f39739489d9efd9e573dcacb06e1e8b904cbc3618657f16d9f001bdf7b6a1010001 \\x9f509edf07920f8cdf295c5df2891506506083dff147850e7564e0b99c4a20e7ccd2711902d4f3d3af9927c02b6883169e93a4aa6dc4dbabfc3aa0fb1edc4006 1684656367000000 1685261167000000 1748333167000000 1842941167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-232 \\x4d76af61538f40c9a04612f0ee8bd2aa12b9186f87ace9021f89fdad3f65100b307738d6526be4e2a0c1559b6cd083046aa6539ab800a7d3c4423a870c14bed4 1 0 \\x000000010000000000800003a82860d8fb969b438b5954472ce171bb0f92e90fc4948fe27b9aeaf5fbc9698576a3d734adf672f9c31d486bcdeff0154f928d57ac9ce8f0b2bff360b078c14051a65e3adee0d7a5fc0c23d17d1808ea6605360c3e49b86b897f73ca014c717c61ea113e8da20b493db31c33b25258afe7dfd2e0c12f3b01c0ec50a34f6349fb010001 \\x897b2da2178f247ded576633a5e0c35284ffbd51f336a2add30b69355b28ce45b16e1a5dcac966bc0669311b0ae83a4480ce4644502ad8c45971a18060e31a0f 1683447367000000 1684052167000000 1747124167000000 1841732167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-233 \\x4d1af64782053351ddb3567f9ce728bdc0c09d3af861199e00b3facd8f804bbd1513322fb5cc2f6e69cac922078ff0e94f8b2042554b93549d84b9a4d14c3c95 1 0 \\x0000000100000000008000039ffdbb937d75c5323ba56634b3c9d3bfb52c27ba1f4886d3ade44f6035bae22dbe69d67eb5e44534863c18a5d6758b2bc80dc961cdd9c66222e43cc899aa92990cc7e956b4e4be28cd78a4b4a00729f9c73212807ae476d0c6931e18141498c308ca784e858d7683015086b3accddeee6a09d0622e0a543cf064601d008732e7010001 \\x4b7929cc944f60ed578eb43c9c09bd39050aa01baf3ff73e95daf79ab885850fe66c6ae8df43931a1cf11c7ff5dc32b7998b07835d4249b84ffa53b22288e30c 1671961867000000 1672566667000000 1735638667000000 1830246667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-234 \\x5326a3a6da4fe4695b493c111017b43480b9b73b72f81ff4b039a16dd29a71af5be12d7c0d16b5d7546d7904de2bbfc68b2c66496c53b33afb4e8e8c7947ac40 1 0 \\x000000010000000000800003ecb6cca8d2e09777e3d50f5d79502776cdc6b5a01c4e7c9120984dfcca95c2bf8fa8168787b5e17d62049c65ad872cffff7e247b3d5ad22d430bdf06bd5bec31cb6479af61fd505ae7f0dd7fe434c7cc37a8c6d0040477e6a7d229c08816307e2f6e20ab05420f03067fbf251a06c0b68c4822673fb31221c680211d184a3007010001 \\xa4e1e91e4c93865d98e3bacca9edb29cc08a9c4c23ac12de16c5918a1b02c3e8456685a8ca7b67894d15d2ebfc0a7417d025844a2fe0314e85f7803603b8b302 1678006867000000 1678611667000000 1741683667000000 1836291667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-235 \\x54dec3ecbd35f84365d4be5da160c595b0bd84a1dae8aabe5a1403acfa73037b377d254af2ef1ac3d146aa8632acc70763cf52ae361089a718cb5700f8f9801e 1 0 \\x000000010000000000800003e681f64d95913a681343c82bfeb6b2bf169d9578cb267c204af6665d70eec4c29dd35a7d644c4442bc8445a87c1cf8ede028e022b8e2e8f6cce8be87dd56d077c72d3474d2729c4fd55a89d45437826d0fccda92d1183c8437eafca10a2c3935f0c15248508c475147768eb39b811b8001fb776ca719f7248db6c2b4f1f61fe3010001 \\xa22ada634960d42007f3bf1a8c4ddb6724cadd0d3f4eca7e378e405e1fccb88ffbc4b679381ca123dc505c550aca72e96cc23eb9b470068cf3c8366a1ae28502 1685865367000000 1686470167000000 1749542167000000 1844150167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-236 \\x554ecb0a975a945faa219b60689f111c7eec2b955f913b678a040460e5243eb11dbaaa7064c906d2d37fb01d08b04c70117f0c218c9021df20e0e573c631b633 1 0 \\x000000010000000000800003deba033683888f9ab03513a855aeef9359f54a7075d715fc6092f697722539673e9ef519848afbab50b046408655cf1828c4e6ccac0f0350e1701873f72eca9334c48561ef2f09cfd705fb4fcf98612b6a93e5a0b78822cd6831f06ec5d4d1ec35cd5152015b36c62dc0d8b4a91aa6cc28c1f43c8860e5454580b99968997ce1010001 \\x5fc06f156f29128ae1bed85d0e91e2edb3d97d5ce91d899f9a489d81c58c0d54b0142284acecf0a72f9f0d43830ba3ea76a820487fe3a413b49def98120e9b01 1681029367000000 1681634167000000 1744706167000000 1839314167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-237 \\x5c6ec91ad433d400de48b85e2e6ed52b519c51956bfc94dd27ebaba7a0c6caaa20d2b92ebf166ada8da1df793ab7ac28538b75bb3643480540c8e3a0a63a3bd7 1 0 \\x00000001000000000080000394e55ee3b597b0926f0b00e369e28ebb3405a9f37dcc6853d54dc099169879b4a3793241aac1450cfaf77de92cad0c183999f520a642fd21d50c122ea8547e4403f5b500f6cdbc0005c805d28f66a13b5850e150d1c66e2a6b787390c89f823e8cf8bfe5002666131f0f4bcc52dfde2b8725f16dd5a8b970e400fcb6521cf3af010001 \\x11ea6a8fe177773015b4ea13a1b1c608d61efdad148e4c8899bf15141b25eaf6adefd79ebfc069428d304c5afe8cbb1f07d5ba8a0b8ee7bf51673f1700a1fd0f 1665916867000000 1666521667000000 1729593667000000 1824201667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-238 \\x5d62981f5f3aa728b46e2efd63bc57c313f54058dd8fca349ab73e9e7456b689f86b99a7a269070f184ec260777cd449e25411e00353d30226b6970f307dc4b4 1 0 \\x000000010000000000800003a919611da4f6b4cd458d3faadd61f25b0a06ff4656f09cda9f262f15e9b436a7c234db64315dbfbb86cda086d1aac1817b96738346b608c16b54f8e334719151bcfc8dbf9d2e4affb6e6eb494de8faa2c3c22fddd7ed226924556bde3a14c0a72d82b939d5a995478b6f7ec1f3c421f7d5d8f73d8566f92f2379ecdce32d89ff010001 \\xf8dbfc266cc053cf9329635ce67ec43ea5a38576174f27d9099b742f5bcd8429a91fc5114d182e94aa0ab1295e1acd38ec989ab2c92b9b39a4bc354dd88cef06 1672566367000000 1673171167000000 1736243167000000 1830851167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-239 \\x5e12862becdfe1c59a436af82800eaa89663384fd42bb8027809f6deb32b56c1450cccacba7c175c476f49bcc8bf6f9c2615f0703fc626df09b54f040e41a1f1 1 0 \\x000000010000000000800003c612cdb143699ef08c2c904c27242fb097be8c1124947d557b18d548011cd7798ae2f062e749e46d96b176e1e36f1cadc0bbe260798011fefc2c6450db5883b0168c8ebb4a5c482ddf798ae3be5dc2eb9b027b04d4f69c331dc25ba877d4bcba6ca597c9a52fbc9d3c2dfc87e9d29b33f429e87f5f418ce64140a7f02603b581010001 \\xeb0897d27d05ee0d79ad1f055101390d3e8b1e56d27017d1d1597ad2aa94b78065320a7f66cd883f768051bab26ba5f2f9cb94dbf5d1f19bfaa5cbb688766108 1676193367000000 1676798167000000 1739870167000000 1834478167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-240 \\x60e62ab09aa717595e0ff847ab1993999674367a80e076e77108980444b9a32566d416cdd274c8b463b04cda875816205efca999df77855398c9b81485a763da 1 0 \\x000000010000000000800003e891d1becae1bfc32e0def009f14fd2e38241a528b66de4f2c50a2c7bcfc96b08c3b1aff53d44fd81c269d720e7355c0f9a44ff349093a4b4fb06b2d8f25af1f345e58ce350e9c1f896825d609a72296610ec2391b98af5ed65c5874f5b036fd8c0dc64f1d046187f0e501209207313888b477be13fb161283c4c240bccd2ffd010001 \\x9ff4b2bb1354240f1a381ab3c11ea38f9b123802904f34e445152c517201c03ab9d74c17eb7b39b5cf6a8c549dea303bbf5fadff819309f98ca5889c88f1980a 1685865367000000 1686470167000000 1749542167000000 1844150167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-241 \\x6022401cb488642b981976c454fa6d8e1111d651192f66ebe2a81717305880d6a1fd8164dce630b40b8eb834e14daf6c7c591ed30870d6de257e77536160b115 1 0 \\x000000010000000000800003db11ce24924e8bae14899e28afe9a92ab6a5239ddf11f8d4c41e10e9d7d6b6134a51098c4585352a77bd0a42ada9f2e1cf8da750af2d4a31d92c60ca7b0b6ca3a261b4ea1c89e98e1577255057a367d9a9339fc844b79ffffe9d66c4f64335480cfaee8ea458980c3328d84ef9f14355e570e9f63939ca9ca964c16192de2add010001 \\x66d95c27caa0f191ed56689c9158e7207a139791e5f5c3c9d0a4d7171254c0c61f320406ef50d3924507a9f27b52067bbd13a808712e35c45c04d789102bcb0e 1666521367000000 1667126167000000 1730198167000000 1824806167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-242 \\x618a219a87c460290d6188e5db19be3c04c361d8b4781cf1469e1fcb761a05e66c2579f47e618b6e00125c3ddebee5851c8d7649ceb5cc3169d8d6673b2d7bde 1 0 \\x000000010000000000800003bfa84ad0192dd1da9ea496a5f977929fb59dce8a0b5972b0a04b098f060b845c7d3408cf10babbda3e2ed9a8a4e77951412e24441797328727d0e5822aded3c8a15c44a2e0d0d25becc957c8b5e9271411696c8553d71186c47fdc8169c9a4042b588f62defe7420a7b1235e03bf08f4ae7c89ff62b60d7d0d83aec3405d62a9010001 \\xa149bb9852d65d791714e11b0f3bc9e990a81492a21c57a1dd1bba5d1c593bddf80936f207b883cfa8b0686f4e714d8afe55ab49df14f9086cf935e5d5709f00 1667730367000000 1668335167000000 1731407167000000 1826015167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-243 \\x624eb76a07f9847f6237db8861818772202d633f5e8844c00debb38e8fe2e67747381c330c4b4e595715f00f01471133a39cb8e6c2ef135ad82a8bd62f1efa66 1 0 \\x0000000100000000008000039863ef8de4e8c378e17eba27aa2393c9d972c09512676f05429ec376ddd889697a690bcbf7027a2eeaf6978b00c70c861dfb1dd174d81abea195e4b61992d50abbba10fa4d72efb2845137f332abb31edba2bb50af44c6f452677be0b274b43d28461f4a3924ac539a264885a4691feecc4908d71a845bc549a8a0ddd263126d010001 \\x084ac8173be7e63285e1661ff46422a1ac01695931a4c9fcf77a792639e3a3cbd68439f77b0edb4623a5f2df0bdc435f0be6753367dd0a0a007ef14e759a9605 1670148367000000 1670753167000000 1733825167000000 1828433167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-244 \\x6556170ef38393e63ba9ec4a08857006d77734f3b57c6921047f87e12aa58b6d55b6410e4ef1427b9f99a05b1b5281f9a5bd1557a9f4f86e1c29711acc9333e7 1 0 \\x000000010000000000800003d0c1b2421ef257b60d41b19bf76e1ba8ea8a360d364ba2685ef5ce89c861134e0277addcc6e7972097e307a95358b308e4ce10ceea974750744e9cd50ecd58fd22155d57c809ea5a10258415e83f67e9a17e94a29b2fef581804f38ff50bfb8de89e4ba7055a309ecc74702bcf3748bb8dfa166d4b88bad3c6a87eedd6f954c1010001 \\x9a932c5a91807a7be3c643b29d240fb92787255c572661d8bd1b65487d8a64128628458620fcfda192370dff6d7690e9645aab9f47abba8038f41f7200d4d109 1686469867000000 1687074667000000 1750146667000000 1844754667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-245 \\x679e7c386a1d6ad141adc7641432e99874f36df60b5ef13584bd8c0e38419842e0b7030054f3f527c032333d96ffef9ffccdc6b2c8877945a6567351c4007d67 1 0 \\x000000010000000000800003de8536ab3e94a40caa47eeb22221adc204d3c53f234436e5bf39baa8310b771873f592d57546451de1d01d5ea5ca77805843db08a115cc10542cd9e4a175bd03d745b366fd6537e0f00b6f1f577008fe374ad5b306facdc3ae53f88fbfc3df4348ae123cfeb6dc16619d5a420174fac3005e0673c3b5ba72e510815cf4f0dafb010001 \\x48cbd435394b3a2308701b8c63954ebe1506f7408a972f0e3c587fa189438d8a3ff009bd35fdb695e02871279ca43cb7d1ab371bf1262d188fcb82acf28b050c 1687074367000000 1687679167000000 1750751167000000 1845359167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-246 \\x6776aebf383ae43f4a839948b87292a1fde75dce40447000087012cff38e967c387fcad0d838604c9d9a8d8c39c96041319458ea52ae8b679acfe2aba196c743 1 0 \\x000000010000000000800003ad84a431237075647e53b9067aa31afc68962ef5af62d4f5aea1aef669ff5245d6ccc363cfa1e91eed8f0e9f6f38332ea6f93d41fcb4e21064bc0f4513d4d714e4000921e1619007a3d382b9f205c144ad147fc5cc4f355053761cbcbc125050cadd24c3e06d0edb9da2cced1d93417a7f64377ca49eb559e741fa9f43f41a47010001 \\x756edbf4f75e3023a85c65c5bcc2831fe6a01342513d8b2b81ea99a7496d19afd09cca15420a7d120a484f7254151c71ef99dac311fde293247587d265c4a602 1670148367000000 1670753167000000 1733825167000000 1828433167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-247 \\x6b1e37b3fb2bf5d7d1b173580c7fe29b5ee71e53ae17b9126f9efc75d6c11f27f018829a425a7a1a11ed63d404f51021d0caccbe4a0f6ab483e7416d71e0bbaa 1 0 \\x000000010000000000800003cb284f0f1f9cdc919a7a661da8330a71ce25892f2de823580fdff2fc60c89e5c8af7b77047806e7ac897026ce76f7ae7195ceca4121862daaeb7a6569fbf6690f49f1cfe078375df9200871c2c8dbb9c83a120c70be294826af53e87ad5dea4fe249383cd34410af75bcfd9a98f59dd24f31be4f3f2f60b7cdb72725ff97315b010001 \\x7b44e6537535c40fdb1dc922a0ab4ffc12fd9256bdb573f4557c924268720c935c22bbedb0289bac379e2064f6c45c529213d2b15d89e68b3e53932aeac26f08 1676193367000000 1676798167000000 1739870167000000 1834478167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-248 \\x7132d35e47454ee8e42beaa4388a89ee647e0085c4160f1571e0cbf27dbe1def6425b7cf7575c358cf1cbbfecf20b5e08f14afeb2d363272009e4b4b03038e5a 1 0 \\x000000010000000000800003e9a121548e4684a0556855425cae8bea9b80719a9dfb6990b880f6392216fc7df5e37ed0b611ffb3c867eb597fa6d16160a77b1a8d174c465afeb2df9e049a82274f1a0d3264a7ea0944bf9ec45a8d0eb3f60f39103fc00649f21fca06d9ce78e232de09b8c010849686e3c2389e7ebae5a905120439e4ce1de2d1141a7728ed010001 \\xe9c9d099b19ef1649eb49c0fcd5dbb3717fa89f4eda2cf4d03832554e0dae8d35f193112028954ccea8906f7aec6ddd7d07c2df084bec94939dcee2edb3b4301 1655640367000000 1656245167000000 1719317167000000 1813925167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-249 \\x72726e443f77027b8ca8e605319f9f0ad954ce494e373d5a4fb90afbdc0e21129c954c21429068f726dc2b193492227e51d164f46a627d21320837c850d6054a 1 0 \\x000000010000000000800003de7729f02b759e9f06bea01d2b7b53c9cbf770d564acb81c96b3e0026dc6f079a8af76056274fc600eda2965a903af240e53e68cca738fb8de85f617a842094e19beb5ea7e716f304bfb8bda1f4cdc6b940168dd874fb5dc38c02d97a8e17e1cb7d0b3bd0010f26e98a839a9f1ffaa0ea0a35674ab7f3b6357bc49b76fdfc3b5010001 \\xe07c7ffe70902aad0e6bce34192cc5ca3eab1780a5e635fe2e2bcc530c981931774bc35f9e2c468cf78faf4ea2a3d0ebb8f6df5b57bc4deb41fa9d146ce0b00b 1680424867000000 1681029667000000 1744101667000000 1838709667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-250 \\x7272f4a77597a2c6728abb886c7fc608f95f1b06c3da3eeee7f5c33c35d6577b5f90ef70cf3dfa72b30e2bb89584d381a8755c20c4096ff38eac4df560371aac 1 0 \\x000000010000000000800003d683f8b21528e61c883944562a266c871807ecb4ba4e7d675aac9d477dbc24bcb46f0efea5a748bc6dbb301afcca18b641879da288eb36ff3106ac294158d8683f739730522f1c0465169670e76c94bbbdc508c136da297325d9cad7f0bee1226760d4bced04d5813c8e7b4bd6c1ab2020a40efd88a46b49198f071e118629bf010001 \\xd13f9595a96241c8a41640aeafcb2286b4f4f9bae760030f929dd7f16c03f4406baf6ff20bc55935b40de0acb7156b3e57bd48433864f38836398a5d347a8404 1677402367000000 1678007167000000 1741079167000000 1835687167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-251 \\x754e5c8a32472a816e25f5bdf513b9b209ba1e67729660820bd132cc852d479225d40e3de81ac6c90febddc8496a6e317727a739568946688ba8c2efc8f340c7 1 0 \\x000000010000000000800003fa4e509439be697f92c91de020c32b95b23f8c50e419558e4a8fc6995a3931605a6654aa3da0dd1147fc3f792e1f269f1038303ee4bc898a80ee59a5b7d7f14e39b73f2f34ffa8d8374c8986f994a072c3f7d7eaa1e7e6ca33d9b7b9cb639f03e40d1b1117861a0902fbd15272d2c532acc5491882e3936fa87b61fca3d7c5ef010001 \\x88b4910ab0978f223fcaeb567ba9e77f99953c3151367760847ab273dceb869276d8e2236046d710c8012505d307987b20529948faa075c752381f8da051000c 1676797867000000 1677402667000000 1740474667000000 1835082667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-252 \\x77aed22a8bc58bc1429d074d440d078571a366bd5cd781b3d92b685a29595c6d3f432d90e0821d9160dc611acc597be262b94183b15c307dcc2da72e156096a5 1 0 \\x000000010000000000800003eee4aee78e4b16b262908dc200e2ea5f6bd43a1b540c7a1f0b8721b5c1fe16679546082ca8bdad334bda99e8f6279f83f8fd8a1df3c18ceb8899c1dbf09eaeb2def1cb7beb8ac66644fd232f01dc5f22fdac91812b896c7237049bbf195d1952da6a0b1f68777f5508c27830336cce20138b440e765a3b0608b88154a5d4728b010001 \\x374d2e0ec8fd5f659dac5ddca809e20e41e9dcc726b6fd5bf77a4b4d1a8361d1dbc77fc05169478f9af747a0e266314de2e294c77ff1c1ea29b0b0f0ea9ed403 1659871867000000 1660476667000000 1723548667000000 1818156667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-253 \\x785a20ab63a958566b0d0d2d680d6b3e87cdac1252d1eafe55a6ef2bf6f8742b67a1b660d9619ef876a62d731245211fe0a5e6ea95303fd1f9cc4ee00baf662d 1 0 \\x000000010000000000800003a11c86e780495598b9d4692f2f649cbc9b4a407701f3e0f2ba3bf572c51d615ddf837e5051d7ece9d8f3791580629e354a3b65923da836815c102e40c4fc1b61f09339ef23b61bbbd51f2e728d93dd5d91cb95ecabb325922c4be2ade0c7203bb560af26e414692b066fc87fcccf0b1b95b47f9200379dcbee76636638623c77010001 \\x127f464e809cbd2193a70d51f52cf16506c9d1c0d2b769fa01b8f238dee8f64c6b24c7f1fa30ae3aa2271a89c19584b334c40479f66c4da23b04ec4e85b36506 1678611367000000 1679216167000000 1742288167000000 1836896167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-254 \\x796a32721d04afb2aac83857ca4f892756f1cff409d8fb542df2e6febb5172bce58b04c45081118d85f35a5792e2d7cc8c4a6b8d2abaa32bea18f6f2ff5fdb01 1 0 \\x000000010000000000800003aa61f75855c825a94fd80d9d8a6450214f40c51942221a67059861253922972cba18b9dae3370adaff319719c7a9ce61ad186c1805148ceb185b4d7b7c206690cb3fbe8c9e4ac6ccc5ad6db8dc1c6ad456c63168c288034b6169e055d536c1597ae9e86f0bdafda806f766414e72c60d0f4c39b90f9be04d077f35f5a6b41743010001 \\x7faa128b5371a8aa97009ec8038bf42c724b40098bbb430a62d98324e8876caed1e24fecd9b7e4de88fbc406895c41a1ab0a3db033e143a280cab558ca527907 1666521367000000 1667126167000000 1730198167000000 1824806167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-255 \\x7a06ec9e864c03041e3d87661aca74e8b331fd6d385f1cac56034a927ba698d57b428be4966fce29e15136be6734095d585c1bac81b97ddbf5e4d4b33fa9bb88 1 0 \\x000000010000000000800003d8153992518883c4764e1f72ecd5cfb3adef100c9adf15a86059c895d99083b1243658a1f93ee734475fbc2acfab596c9835531c0f848023176cf5c3929a0ddbf659f95920121017d7642ca219d7cd04476af5e49f1ed936e6eff3069e6faf30b14e8cd1c3674810ec8386b99e9bb67e9328e732c3bcfedcfe4099290efc63e9010001 \\x7904d126d99f3509eebbd80f643c0ef87c03d1a517b4841c8f066a39ca2502dd88a2f3b59ca01e8f80e30f9d4149398677202190c8f459fd2584c6007bae2309 1662894367000000 1663499167000000 1726571167000000 1821179167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-256 \\x7b3e5b3f96c0dbd3c202145aa6de364445fb7daa9f2d3c379990b399f4807db23946b9a8baaecf5619c9090f47c3c7eb110fef9624a879419f41c209ff73ae2a 1 0 \\x000000010000000000800003b18d8d03144e986dcc1fb0436b38be1b04e695c23cbddb34c763f1704cfad10c6d3dc0148d8462577230efbe30078698f308afb4aff20bf8bda7bbd43b5d28d5b504f4ce43c91853c3536e47641979a1eef867b7885652eef8254e38eb09e4a5d847c719e16883b33d81caaea227fc7aaa3c9082ec6b84485c41a565a3c23149010001 \\x2ee0d6e00adf77fbc90ae07e9fac522702cbcf740ec31f6390afee7e164e8fa5eedd61149bca285c7832e5ffff4330c38b025df5b3f0c8c7041d3ba4cb962d0d 1667730367000000 1668335167000000 1731407167000000 1826015167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-257 \\x7dba70b9e0d13d676835b707ce3600d0adcd998dea88b4db38624e5a43ff0a2608ff466aea9619e30a277aa7d05c55854b5a74aaf0e4f0c25f716333df402d30 1 0 \\x000000010000000000800003db86488cc1c3415da723ca368f6a20b77734aced889a13864ce435df5e26065b3b8cf5e666c6df24c91a6f0a97b47d0541315f6dbb76140b7c0e99b4c2a5831ffa61d6fc769ceaa6a61f7cc96398e4de650d950f8056953d89c2ac3769dac6734b49bd9f844054c9f8d5ad891088cac7417edf5bab70ddf79f4d64c96b7a5f87010001 \\x31165fd0f0912f644276309584d0320a50165d76ca85f69b0bcd9192653f206b19c1c18c76a3601656d6fa11ed7039b2047521ea412f1ecc845903f4f987aa04 1665312367000000 1665917167000000 1728989167000000 1823597167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-258 \\x7dc697673a47db31e77d56d6934003bcec744d9586444b742e9a955b5a55f5bd25f5e7f48f2143b4fb0743e0d6fdd0cc8ff410c479ccdc8014900cedd34a3b11 1 0 \\x000000010000000000800003cbf6d22f9088775c8ff036aba0e8817d1a7b2e1fe0833ce5089b24f7fe73e164eb3b067a7b57b316058f0ec6957550e68e113013dfbdc63a4a7dfd3cbdc6e858d11c634f75e87a1e89bc2ade057790803ad119e939e7c7cca7e198da97db02535b8bf2e231b67529fdaea1f18a4a8c86aefa46906c4b8f863b001864ac7c4c01010001 \\xdf89cecd19ce5e7baa078119ee541ede906d11c83cc3e4aab1821d3670a659fd676fd9f0379c15c79d1d3e92586ba2f64c9bf3dfddd7522e5655ef6689b3bb0c 1682238367000000 1682843167000000 1745915167000000 1840523167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-259 \\x7fde6d0c7e7aeba0d65edfd6315d8f74fd77a1ad47a83a63d133db6a3546b866919cdb11294b18c676b3ce93caaeead320db26c217e731297a0fadb5bbd0a736 1 0 \\x000000010000000000800003bc4e3513c936b5d2de310ffa060532b7d8a7b5527218716d8b4d691e6e4b0ffdbd72c736431ade07f559b57a945df8b23d37735544bc83a2e436cab51af9ff6e37fbf3e44a9e50545492d6fa81e6ac829519d3ad03a3931881196005b9d0051125555fe8dd82c0d0669f94631ebbc097e0454d3fa0d078cb4de091d89372dd0d010001 \\x142850bc55bdd30f7f47f5eff30361148d1cc15f879cea999c4eeaa159bbdacf5c8fa1758b48659299a06fcaee6c790c474bd21bc38929a0752c4ac35145700b 1670752867000000 1671357667000000 1734429667000000 1829037667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-260 \\x80465b259caff650cb649a2dbaeba891d1f162db2e573b89aec475a1e32b028980cf58b38ee25fe3c2ed3ef87e23843ab4306f8c3eca1e8892b20021d967ccbb 1 0 \\x000000010000000000800003c9f956de904f7cfb1f2cd6df76c26cfdb1aef76c98e21a69b5e404695918b9cb6bf5769479fe653579267fd14c77690bc72764b9f547893e4549cc8e0e514f7d09260720cd26aa6a77a5abcd5e5e3ea2335aec49e6af0547d6637342acfc2a4b629682eb3e126c09bc5f8b09a04d580d7e40bca8d45c582901002f74b35ee273010001 \\x0d963a9728d94ed89e463d72fa2c54da299877c10e517f1196ae50c4bbca9c5c7a2cfa5c9e17b4e668f0ec53fda9aa3a9638a4a9b0dc8e992816f84c2d54160e 1658662867000000 1659267667000000 1722339667000000 1816947667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-261 \\x88ce1549ad77ab05350cfd742a093db3308f5e14d7c4a4ee1ae35016cc7998a13eb0303039f6cc44f3ff9b735ceb7faeee6614b572b334341a18b96dbff52d41 1 0 \\x000000010000000000800003b1ebb3c23f1b4f7f352f9b45f3d3261d7175ac664fdfa2d20b08e6cea8a74208d59d2ba9bb6eb9de4aa2437d941c23714b8c47f24c9c970019bb91bfb304b0a018c01fae0aa75e58fff92e7a4db17a6d0bb20582560bd12ac081de63254a94d5c09093fc0706de3e04421a656c9e4fe5aae2fdcf46a7a09efc3c152ae357252d010001 \\x5cc153aa5627ef029c629094e952e186c4b113e26db060c2344986b897dd68e607739187223acd5e8f43fc8191c31f55708c41aa3fcb5923f12a95e7c53d7408 1663498867000000 1664103667000000 1727175667000000 1821783667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-262 \\x8bbae91a26612c40df5cec5aff5742decba9b3136c7b06b44a1308715d822f337dfa030c1c345085e382987cfbaf2b4217ae0122d229da941dffe965a758b36e 1 0 \\x000000010000000000800003d7681839ccf2dc1017ef117d6d296b74c22e36a99ff699c5246a33d66d0dcd008d103647e154f6141316aa93334fc5e757d6d6d80fc481a6c30ae3c012c2a632f5daa831ecadab046a7a31ce147985d5b2795884c98069fbf5c40913e5a50e7b0d02211e3615f7caa3a90dadbe05cde99d53f3e21d78027f41a84efd6965325b010001 \\xe2449848c1c49714aa673a2ed771c5523b84b90c66a289cd4655f88c4ecbc2da4a371c9f32057a10912065abee3a8dfdbec85b9750fcfbb633b311260507560e 1676193367000000 1676798167000000 1739870167000000 1834478167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-263 \\x8d12d38b01948c86c6fed36aaf0f8ee1c4732e8ed716a74a5da6a2c64b2021add73e371b06563f5f9b5b927d25685aa3071a54c77765f55781e070af30b26e45 1 0 \\x000000010000000000800003bc3385d560ca880f0563f3d2fecc1979c0d0f227b8a59d1ee7b311d62c91c08602ab13b010f4e00439455fddea87d8f1f4122a50bf53c9c896b9753a3e8543ac834360bb919135b500c75431aee65ecb18f88a0bc776b7a6e8a4b8aac5c4ba3608a5227efb7b1114af42ea5e0b94119350105caec59a2320b6354d4e5b457a0f010001 \\x6dd55b6cd0928c2a3bac69d95dc326375d8e1f26ab79a88a75c715ff2d7d1c76bd9e8ccd983c12184d98d03ead0e5b65cc5decd2581277cbfe519c2782142605 1675588867000000 1676193667000000 1739265667000000 1833873667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-264 \\x8fae987d02499879c0e81be9ce59af83b4b9bf2fdc1cca6ac29ca9371cac0c487b6032617cfb5b034f55e01dfa9d91d73078ebbf4543035c7f47e93331b14d8e 1 0 \\x000000010000000000800003d469845d3638cc0939a5d12bed34946cf3327b608f31e141d8f94bda538151413d3b1aadc08f444745115232d35bef2040147621ee3113a2a80d5976b4b25e8fc86641ac4474ef88e2e29159f09c18c99f114b6c8e0a6bc05737d5dea08a865b3672e497e0596b871223c643fa7ec77740f32b727bd1a22b40b101c1b099dcd3010001 \\xaecba406501061c82e2a86f0c472d4a577a5d76f59261a80cb22cfdc17a757f652abdf73b8cd92c48d1c8800d86481142ed9e85b72a94c4a3c6ff968c445c109 1684051867000000 1684656667000000 1747728667000000 1842336667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-265 \\x92fe9fafaee08315defdec87adb755c38cdbf1d4d45dfa57cb2af9ab3d9059725f89e8e8b9bf3f8d91f2c7486064d67edae1d87dc0e692137101b3e3b72b38d4 1 0 \\x000000010000000000800003b3740c88db3289246a37df747c7a34074fa7714e70da48f501c5ab7d839a686f3eaa0f6c14e8bd5cd7699beb37a4fb7293faea08895ab072b05c4e530842ba5e6dbdc98fc291b39ea767cfb1fbb46f4248aa3d5350cb7a797f1440acc0d398979ce8ecb419d916229c4273d38e198dbfcb93ea4d86a9a7fc05521ed58dcba93b010001 \\xff7da6a2dd8923ff32cbda65922c155bf07dcac149d4b2eb87f8503822eb0de3b9b5a8b395be765396ea473a7f852aad0a360373864a6f05ec7f925d019e1404 1673170867000000 1673775667000000 1736847667000000 1831455667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-266 \\x948e3231c986dc258bca4ed5073fe9d4ad061edc368fb727de7a77e72e9bac5aa2950d1da49445ff7e34bbbf5b5cbc1ebb344e17998b63b9bf167b4bfa68ab3e 1 0 \\x000000010000000000800003beb3d811a44e4d069280349deec99e7a2f620f41fd3a54c7a646f4de02d5f265dbc37ef988ebcceb4f9604b972e2b0d4181222baacab59a54fd5abe878ac9c58f6b7a73578385f7b325d72eb0cd39c076d9d07097a8970caec7fa49f2840ce3e391b69a325ea1db2ba60283509eb4a9683be8c9022309a0589e0364aeb58a263010001 \\x5c4035103b88557f80025bd09a942ef8ce6b398645ec810650778fd5890179a11110e740f3f64a45f680d3b59f612fb020fd3357adb5698ec6d081064197420e 1673775367000000 1674380167000000 1737452167000000 1832060167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-267 \\x97c2d30b97b7ea4cc65c8081c94de88b8a5123481b0dbfccd60b42cf55e33a1bcd381fc2e663f6f25a31b67b5b80a8bf091438ba7304ae76999f581da09faafb 1 0 \\x000000010000000000800003b054d767a825f0387abbe92641f3853a30891c84af798d6e81c0474a2700990ad4f361b33b93b891cd81ff426bcdda4ba4cacd7bb0bc622e1db77a0fb8d94e8c2638f6ba8d9c01fc07281584125a9ae9afce749e6257d70d20e2c2a6d305713c48f4861de939c2c6e1ab92354bb0ed6d5f25b906b55d5b1b9fbaa4324d242911010001 \\x73123cc8afc66cec8413b248eae1b432a5a2aa07ff740a414e4df9df5e43780066d903987f953b46a1af8fd6a8bb52e65d02012fbcddb7b0c4068df3bb074e0e 1672566367000000 1673171167000000 1736243167000000 1830851167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-268 \\x9e6a9fc408556275d8f3f09d5326017c93152f3b4b49bbccffed12a93634dbdd9b15c39c0ca66eb31ace0558fdb930148b7783edc9b3885c5adadb5842a3eeb7 1 0 \\x000000010000000000800003a64e120d17301e21704ce7fd084c1b8791281d814a2277e02c61a1924424d6fdd3bd97ed13511ff5f3df8254dd514da75b9475e0624bf8579008dd8f43139c33245012bab524c373a19f529c527917f3dce6660d2b79075ae25c5f3117c4cca3d946dcca4a79f8a0b27ae363ac64539fa5d19119fd9c42eef40a3872f956dc9f010001 \\xdbc5f3abea415bc1ed597ae5a7b3152f5fc754e945b8c7038c446a58ccf7139ce1d7646d2b68330df9b8d76cf06a5174195d54bcad014d29db82980df7be6e04 1683447367000000 1684052167000000 1747124167000000 1841732167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-269 \\xa28ebc6a44eff83fd70c972ffcfc645b26d3555ab6c409f3e20792caf8d94bc912f37ca4b580b81859c9194ad661cbd3431e8fff95ef43468bab60efd806c96c 1 0 \\x000000010000000000800003b0512bd33668a9fe3ecd0a81e3f0d026d238ec3821097a6c59781944000886d2843b4a706bd0e27fdb67cd19644ccf2590f6cfb5e754a223be599b5406fa9b025d285075bc7ba08b3047b0d7b7b4df4443bfc27ee4eb7ad9b4fda180558826f8f56dc5cccd92343764b47b6dcd7dfa77269c80778f013a1190a53baa6a4ea493010001 \\xb126b480f62186812dfa20060b52286e9c5509bff9549fde3e9b28ec5efb1dd49886f5e84082864cc171e1370d462fdac887398ce98586be9091c839d3120309 1681029367000000 1681634167000000 1744706167000000 1839314167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-270 \\xa3d24283da32369df68b07de3b3d0296d96bcea3cbf28a67274e5645b521edb6b3775188c9929a898db7567bdc8563235137c030cb78a67a9fdcbf059a34cff2 1 0 \\x000000010000000000800003d52347c197bff9f2cb52dac541bf1a8cda7161eaac1f50e47255f0601120b13ea270ab9a2ae3f77f68c86722c450eaca9423ba85500c5053e902ac873a54cc68a9c9df781641c939595c5b48f4de1e89464a13666f6c3c75facef88396c2ec7af8eb1329229d5e95520d2f5af86c91a87c6e75aa9ce0583f8e3946a60925069b010001 \\xd186b3dc7f211f400aefff301dc4ef4c56d847882ab38d02a38083acac8442427966b41befaf50af88b31d65bc8547372654f42e6e109925affcd54029bfa608 1685260867000000 1685865667000000 1748937667000000 1843545667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-271 \\xa43a8d0b8f1e0c763549bee5107e1074f0dc1b35e5a5331a290bdaaf2ca9d13dd339a919d9a0449e18d31b45580a0625cc0c5a6b99cc7c7b990b49990e76ea00 1 0 \\x000000010000000000800003c37304b8f6bb6143d91640147fe39bb84781589f4256685c45e81af6476941b7574ccbabd06b1d46df3ee2eee470e96083868476f319c741cfe53dff21daddb022901f39a8a21b73bfbcf12a1801f5b457500c597dd8c3a797d045f4e92a4ca0d65f2b87f728817d9db0994e8d6341c6453e9636f284bb927f1e22e2dcc1a95d010001 \\x61283e117e81c829b47c88c0249137ade2b1b028c456f6344bea293218904ec61766631b47fe7a0d076ad4add82e355bc66e1eb3d84483650c19775ec7472802 1661685367000000 1662290167000000 1725362167000000 1819970167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-272 \\xa5328c1a6c9821dfe97410ac14be91969a6c86a04e4ffbf96914ea65ca145e7aa493595bd732165b114a28bcdc2313ecdae129af77a9df4c378096768e9d2936 1 0 \\x000000010000000000800003cdf04df2d37752c5ea539a3046f1391024833f4d2cf480a2bf090ac515ee3987d49a951d6ce64503a9319e77234e0dc2703345919ca209f2bdd7a375db91a2141bc73d09eaf75b672f4fbe47625cc637cf5fa30c40d77860f4d62454562f23dcc7d78c0b7617446a916d781aabd3995acb32ce305d4d71142ca9ca689716b9fd010001 \\x1d38c2b1bbb7383888d1cb807bc6c71122c8e972fb204da918a64c7e624a42b464891cd49040a719b095da97e1e3bd59b4e1a17b0bf8d4aee74a54e7ca851d0e 1672566367000000 1673171167000000 1736243167000000 1830851167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-273 \\xa9221ae254ec02c6b85b031a07407c6efacfc7e7ac1b9570e2009d9216661f3f69875e3ec3560aa01846bcaa1f77e47ecd7f986740cb109df2ed36f60f39d658 1 0 \\x000000010000000000800003e4fd24e449c2552d90a9f8728beb6db391afdbf3c352654604d2025cf33f44623d4b729f87a816daa8c9b86bd423a501a13987a1ef5625a52717f2f4f7d604ad9a1400c778f13a147c5fb2b92a13b0bc943d36e5418d21a13f00edcea41001e4bcae5aeb37c999031c8b361716e1f870123e988f0630e960c4ee9c3a6203185d010001 \\x581d8698d616909f5e240a5a6c55a751b205acfe8cd672c9825182e61202188c357c94badc0daa70fec4920c18c1ee88bbb58e4e209c9dc64c04072dfcba7800 1671357367000000 1671962167000000 1735034167000000 1829642167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-274 \\xacdaea04dc08c2c636389005d6220c6e9c355e37fe80ae5a5bb213221cff3f0faabcb03b6c2f9279139c3c861ce2bae681953a38946b9d8a9570230572caaec0 1 0 \\x000000010000000000800003bc8e35d265044f91573812ad59260c9f3857eff79b39ce7183714ea77a33f106a5299893a773841e272d576ae606a24e6e1cba253e1acafcd5d3de89f80afb5749e1935ca8a54068b43583d83789c1e0d80a9119ced391c0a9cb64addf51ac00b18f207934a3f7b423b5414ff748df26a3be27ff88ba115af807cc4c33035083010001 \\xca6d6a552a696c5122898335cb75de5d36a6bb9562f62ec2bab580c5d0391ae41a85d5d657a619fd6b4ae1f7bcdcfcf1e9dd583c6d83075f3b8643fcd81d220e 1668334867000000 1668939667000000 1732011667000000 1826619667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-275 \\xae52d9c8a70f658f27fe21c236cd3cd794aa15ff5a87ad848e43be28d467e8e4411346fdb8b1c88866513081363c92b73dcfe9a4bfdd98f7741c6e481b80e3a8 1 0 \\x000000010000000000800003d15c66ca261e6fce8e6b8e1a72fbd357caffc31c48ecaf80c456037a09d678b9e6a126c8d062de4014a53df74b781f0a3a280808f6474d10aa84c7fd55f4696d46a21f87496e3dfcb6f77a692c8722e62c1f59faeb365327ff84f37d02734cadfdcd7706b3fb3f1340b1b0b6648ded10999150f42fcfc4b0aade296e5c22c0d5010001 \\x0a1ebd64e094211832a1d9dd1107d75f83fe3b92805b5dae31fe0fdca8709e4e7f82f4f4bc65a72c73cce814fcb2dba8c5f9642553ed908bbfce581e92ff7800 1673170867000000 1673775667000000 1736847667000000 1831455667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-276 \\xae86ee3befd2bebef11fe610ed40cffbeefb708f016b7569efb73673b12bf865f298c641ac9a3d380f2f14458604f0440780eca106f59534b34c772225179da6 1 0 \\x000000010000000000800003dbdfb2904b5cb30f7638c103da017ccf4d39645aaf4bbdf46b6ebb19fe12c8c696ceb9379e4ea2cba3a191a61737c04a0a17821ab3eba3a9982d3eb49a58bc3b16a5517e05dc5c23b45bd89f7c8c72e3acd96f5eaaea899af3588369433b0f8c0609dc9bf2d77ae5f38d525b4a3388d9db278491fbb171d54be9ec174a7c539f010001 \\x22c6cc98a1fc52decd0c1fcf9d8d0f34aa565a92d772a606dd9a3a72ae87f7197986303053064532bd08ff8274fbfcc7206d7a3ee08a28ef98338c7516c2f40e 1655640367000000 1656245167000000 1719317167000000 1813925167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-277 \\xb1f202751b5a37f534323535c82fe36198c7038ec121b311735f3c798915060ab4db9f791f440a7d229c09510d77609e12202c97e9e6e8cc2c9c971bc83b35b2 1 0 \\x000000010000000000800003c727cf71ad813b2b82f7f6b2c00760fd83510b47b4957066b6678cdac12c3763e6fd9be233d289cf2ffd3ba4682cb9c3a726f9af2604b38c1f9065615d1b856c3f818144d222b7707d9203b2a0e4071d5c0a0865c5a53e3889a730a838895449d08e4c68e0b3e1a709618ddf31e8c0da63c0576efe8cf92a5e604d61a9070b9b010001 \\xd850b209fb0a9c9d674a7cf9197b67ab5c72b7ea290a7cd20486a7ca7dbf453a963318eba436d225e5d19a6ace01cb2d69ac60efed7c37bfc5a1cf4beec81a0c 1678006867000000 1678611667000000 1741683667000000 1836291667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-278 \\xb41a566e20fc5d2aca1ea3dc7bdd5e8b649c7d94b49d231f638d7cf92dd31faa597ffa15d70a2be87a1837ba3a792632e03929dd0400e86159c31d356bead8c3 1 0 \\x000000010000000000800003c7f48559b205eee1e7dd0388b025f5897a3fee630a7e773277decfcd62fe87f18e0527d8cf6ff04824fbaf560904f5e6a10a13bdb7bb20418a0f6b4f7b1f284a62e8421650fa07b38430ca20752ed59d7694e9d1eebca170b11bfa3173028dbb42210d9a391bf1e138aa8c7f187de69d27c22e4e3f65b55236aae27457e6c611010001 \\x23fb3e9cf0f6da7e5c34f3e6ea92510c38ee43b252a78f128c51b5decafcca84b767f62df0e9e4e8ce4a2782bdd4ad288dc53a4fa0c45a25485f3ff4f6c8180a 1684656367000000 1685261167000000 1748333167000000 1842941167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-279 \\xb56e61c6e23ec7c5b1d9460b232ee91a165524cc65c65c446f44e7a0f03076041319873afec109ad11a6b36910e219d6a646a48ef3a49ed6e2d7e99437c7ff6d 1 0 \\x000000010000000000800003d94282e52342f80bbb745daab99410f76ffb0f56d278e8fefbff7633d7954eae690c63d288fa30594326b8b7053564223db3649f5d98b2f39500a9e60588ce5a5dcb40aeb8f44f75392cd1637d22f95eb1fa2fb684ea36a6f097da229331128dca8b1d73aeabd77765f6cef6cd7a01ec1f07545c675aedb7eab2192697faea3f010001 \\x37ceb11a41b8cccdc9305dcb1480ea05419d98500168f12b5afddf1149b51047bc0affdb80ffe641879107320579cdffa1bae9f0a55a89fc154e533e5d26320d 1681029367000000 1681634167000000 1744706167000000 1839314167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-280 \\xb64e1811b6bad326343b6d153763284fa79264d8f534c2de94458a4ffe80e8108d3dacd643507964089d3a1ba5bce5388edd7d1607f5ac228c69dff0c16d698f 1 0 \\x0000000100000000008000039cb76709dd3d9707de5fa158f22226e760a905becd7b8d6131c03a0d9348806b1a6959c419c61aeb2ae5ab894b6bc1a03ec56ef574d81aeb796a8884516bddcbf11f8d50e350848c57d2cb9624eafb8b0f599f974646652f8558f66917764bb5e0efc5cd6a7b03fae61802c46fa304688388f7f22ab53ecece552cf9cbbfc635010001 \\xaafdbf4146be2cf4e24373dbe082829915fcbff9259576888dd8f13ff036e485be6a6aaf3049b3a2bca692bee06b11fc2ec6b86540dae6bd3dc7cf5a9929f906 1679215867000000 1679820667000000 1742892667000000 1837500667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-281 \\xb89efee1de588ea67214e316748e9489436cbd249a4b7042ef268d0a3fdcb7cf48c8d46372145251d235a3927f3e565c2c2030a8f511ddf5d1bb50a3c204b684 1 0 \\x000000010000000000800003af51b6b0bc2d662bfe14c0996fac9fa8ebdfc235ac5377a4cdeff7a1a292646ae3d3e7e7fd3216bace67d52797c1b47e625e4cae801ace9da6aa3f886b54e428136199092d2cbf8904400b36375b6d732755f4b529c3bab7d182ca5a5cbe7c7e28132444b36bbeec1d33e4520e0cdbf2cc11d9a55c80716e0db5d01a4e8bc2bb010001 \\xedb9b83430fbd6ef4a79da9e251f53e85a51b106f12c2c78401c7396ca590a80735d505fa3ab75fd20c4229b34557ef115ea0f80f457c81466ae2abc6ddf6600 1678006867000000 1678611667000000 1741683667000000 1836291667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-282 \\xb8daa6756662e03d001212d8ddaca6b91f813814ae38ec2c01c354c452cd35513bfa4ed212ce21c7f395ca6f240047bcdf7df50fb89aca6f5c446e9cc2af5fe6 1 0 \\x000000010000000000800003cc6b2197b94aeda6c551077cce8eb4d8356d46f08b86ac9ca70f2c244e518404e7beca419eed0d79cee68f8266b40bcfe05c72d2b9520f6f8cdddeb44b4167f61dfbe1717ead3bd78bd64d8ec327d3341a3a2c55fd56bebb355e35d9695b104ffa65c4889398a835f0fcff90bbe218c14375504037794acafa5b333ef4889dc7010001 \\xf8685702521440216445a713b6287ab0f4047ff11ead16de4329a9c16402aeb4bcae1cf3f95e272ed3e5dbab7e8cd20c692341318be5d66f0d6bf335aaeed50b 1672566367000000 1673171167000000 1736243167000000 1830851167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-283 \\xbae65ea658fe567fa1e5a0bc5e230db3d2d23dd615372cda5bfb6659f7a17cbf86fce75c6916d97389cc5b1358b0342917d335580e0b9d7472a1eaee0e0e7f2d 1 0 \\x000000010000000000800003b119620ee133f19414ae4d6179b2b0afbfd6e6a5d4f7313b7bd78c8650208d3ef6c83a99442c9ff4b2fb393051f439bff78ad9ea2e57da3d72e85f58813e1d8087108c43044cccbe9c8fb5896f737a2d764ae437ee4d20d366ca78c0f556287b111dea4a1b9465c8b561541c3becdf2ae21913446175b9e10a7aba005d75f3ad010001 \\xec825ac00d51d45a36adf8611ab61380d950ae895d7f109dc6b9264281c2be5ac6edb05d6af34ca0d50d49ea794adfe0a15a3e1a74173823eb7731124f077703 1667730367000000 1668335167000000 1731407167000000 1826015167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-284 \\xbd46eb43e3d763b1927334cb3df6a7b0ebff2dc9ed24eab594e27651ffc301f4fdb424a31342ec509a5a80a7215cfeb3fba245982553531005ceca111b7af143 1 0 \\x000000010000000000800003ef82b6862166f821cede658298c5b131eae0983bcd5d040e5733c0da59774e98206c0e7dd189edf46e3c09eae64dd91b5d1ac94c97b8a17186a871c275c2b56bef62a27b36c46c6c391faf69ce69b6956e7da375485af7c95f80bcc20a739549f762e92071f2f4ef8c4e2f9e257f2421c9224d8ec9e2bec1dbd5d6ef0241e0f9010001 \\x2175fc57c61c813bf34f2e18536eefa6d4e76cf8d2c01ac25a438868d3bc9393b67bf58af75f4f96c1806fdea2545ad81635ce479edac8f411d8b220f70de905 1678006867000000 1678611667000000 1741683667000000 1836291667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-285 \\xc016863d3cbc69f5160ba6824ccd650bbc497b62a63443c83155129fd8d877b82930b2171e78dd57b593185100671d9ef61e31fa2fe81953800ebf2bec4e0eed 1 0 \\x000000010000000000800003ae30d3d753706cf2bb53210a214aaa426a51059b2fd0dde3a54ab483dd05bcea658c53afcc697fbc79463a30e0e144245062bb32ca275cfbad6962cd5d4622832701e6f09e284be6f74c05a0502087344b04db4b13d127ad6783c2cd4511a237b991510bbfd2d2c3e3a62d0373f626097af853902b09cfc28cecd1435f74f793010001 \\xfeb75cb0afe11768d0b43891ebe7a80236b131fceb2d5051f99cebdd5c31f952735ccb6dbdc974316e0e5d0f6caa6205d562047a0c59d34c0dece6be2ef89f04 1675588867000000 1676193667000000 1739265667000000 1833873667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-286 \\xc1e6656ec5fae150d98cb301b8da256792270d5507cc035f1a43b800107cd225cf8dead58282ae2605ffd8bb7ff7fac4e301d14c87c85b22ddddbeb6e76855a2 1 0 \\x000000010000000000800003c816293dbdb6ac78a75bff46ebb743c6baaeea18c5257a74eabcfdb58c3e4be2ac9c736f47c4910e33f1431511486884f4d115426f2a49dbe000e393fcad8b01c53258631bc80da89120125cb56ed69982d5fe3831613dedb4c1c69a70cc832f76a4ac5faf511cf2977a082e3edda6b555ac6776e00897473436397d3a1a1e7b010001 \\x9f9d5b5625d2b55f7a24251f03556e3c52e73f39ef7d865fcf742542d8c5211f3d669040b30d7f3481b6c800e437e6b5fa29cf862959844d3a1c2262a9c43e08 1677402367000000 1678007167000000 1741079167000000 1835687167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-287 \\xc1c6f7b67025c2994e4c1a70bebcfe2008041bea2248d8e66126490218d9c23b72f7b8b94c33dc86611b84b2ede6aaad6a323540c7f6bc28ba4439a3ade3ba7a 1 0 \\x000000010000000000800003b531f8b2b557665dea67971bb7a3167b01b194ae3f1aab6d77acdfbd1544a6a3470ed05a8440249dc696104a9bc8866b50be187a46d028868321bf15321985864114d58c77fbbd70140d44df5df40373eb3bace8ff828491c5501dc37f83d6b35926d9146ecf4144c63bc399c62ba9d116a177ae3085b660c945d1cdfcfeb639010001 \\xf13478dfb123c025fc6e8b3b01c53e837bac642079b1e4d2523717f3e55b476812097c4d445a685480e22793c0c45fd2ed6e03fec4be5853f24e382cc2329100 1670752867000000 1671357667000000 1734429667000000 1829037667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-288 \\xc2c25abdbf561d99f8ccb1ab99d5f78d138ba48f8efd383c90116c379a47be6fd88cd64d01b24bda8ab0ef5e8980e25fed54c78706a43027e6f9f730f38ffc79 1 0 \\x000000010000000000800003b3c0b589a9d1f1e7aa358991548bab5b438fd027f11b60f33fb5f2b3b236337e101ad8b824436f5fcb12747809e741c6f895bc228f2f3fa4753d4fd971af1b29a017d9c1f092fb0608cac6fc26705db13d33af182094e1cda0ec17a5129afa52fc20e1be26d646925f36b706cbad4d281a83eb0c826fb5f07059f47aede93653010001 \\xe7f3fca6a7fb764d10b54ab41732a1cddf7bcf1b295a1da76519b8c483b1cee118f6f805a8d709cb77033532d3262a06a1c07b428eea9ae6eb679372dfacc301 1673775367000000 1674380167000000 1737452167000000 1832060167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-289 \\xc3a6a1a28dd2753c14d1d48e1f10d7d4ad24b83af9168828565a50faa70cd851dab25cf0387094d5125159af603c70681d5ad53d1f96c90000e551f97cf081ba 1 0 \\x000000010000000000800003a71dc8033676db9df744e9ef87c30221a547dc5f08b3aaca4cc49c47ea7bf39c740317d88647342f752539daf97d82bb6914d97debe52b9ff0518e8778e2de7ac42895ca41be321c457bab35d05cee0826bb7922780f1cfab1a6c259dd9d38f16b876216e601969f74aedf30d330ec99777c091bd17cc45186ea91f50ee1e5f7010001 \\x1f4344f5354311cdd62e4c7660033eab4068aa95d2c95500e7def9a0211eb9cc96fbc5cddc90c6013c264da54ca0b4221c28fac366ca95e91f84a0cf6bf7cc01 1658058367000000 1658663167000000 1721735167000000 1816343167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-290 \\xc552781dfab244ab99885632f3d3a0e07f1a7e22569c4d93beacda3b5380fb17a30cded6264e2010460d2e1c0fc37422ac31f480ea6fad1aabb48a73b2826327 1 0 \\x000000010000000000800003e3f7a6b8cca23ee3937c2e70723f1e7dafa5ca3d856c047ccb61673529e435d344eb7f53b213c940ceb001a29ca4ed5d317512d8a48f63f27488aa3e1f9722ef9e7c4e4bdf07798478d1585feecdf9fe855e6f3d86489b9d5940b74c635bba970532277ff1f866f688b707796f45022ae63dfcddb715fc248ab001b3c4d8cf0f010001 \\xd4a3a82221e7829e41a6cdfe9a94b995f9208dae3bf0df10efdce127d6e99af5363bf0e5076389af19f28edadc8e5e81b15f598b197db176442fa0fffc89870d 1664103367000000 1664708167000000 1727780167000000 1822388167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-291 \\xc7421640362060b0b295d70f14a26c5f38d17b53d0f2b83f471ec7b8c8b4e8837a2926912c3f6b1c7102b50d475f3ed357bb9e39b206d7627bb4d96e515145fd 1 0 \\x000000010000000000800003d93c81ef5bca823af975bfb506f1acd3f166cd55d0b701773a6ac7411dd420fb84b90cc04cced244916d76654dd5051baa3c5083eda49ca94f8de327991dff294d3a35d86e78f75b4e6dfb798679e9d6efb6f16d45b5c71a6c278ab8714eef2ae2d0c26440652d4618c716200aaee7d117c0d728f0ddd1dee9e5ad9f4eae4eb9010001 \\x7adafa97480640c38e208b55367b29d49bdc5179eca80dd1445470f791031f86738024f88ef2fb0e7b24e4d4f1b667e74ed295384f81a4b9882da9a1085d1c0f 1658662867000000 1659267667000000 1722339667000000 1816947667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-292 \\xccbed1c4fbf25164f05af326bcc254769e39601815a8e9aeb35985f315da30469f491f5c816e18af2cad6404e95abca6f7deac9e8449074391b3afd9c24ab680 1 0 \\x000000010000000000800003ceb389bb1ce078f48fa6745e7ee099db1f401498f215e73f67aa31db5d4be171d7b0606df3342b63ae25ac187b1a878d49d64b6e8973876066b9d6b39b6b5ec77799368ea994c40c85537caab2d8c8dc0eb357683c098b9e8e26eec1c2a35de1b6d73b002223fa263b4ae0ac62bb4f992f19174df5f7a49e0bd8a5e7346b0653010001 \\x98c02bd6f3dd5f3c3ac7e0514b30c5d800891baa010782a792264bd6c846e1b258f2f2de53c0889e6610b6c3b7e69830700e4477ca8c3aec35e171da9df2cb03 1656849367000000 1657454167000000 1720526167000000 1815134167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-293 \\xcc3efc8d9b6b01109d9934b8e19192ae364c6759d9e10cc8a0801a76802713bb108770ca4982250fc33af7846e86e9e88eb3d7749da2214adda81510e6a4e0da 1 0 \\x000000010000000000800003cef7281154f8aedd23df090d0408bdd1c553e44136deec9889055e3f59027a38f5667463123e7c2c91f17165f0589c84c1e46369d7966e87753f6f063a4168323d542c7b130e064c5fbde0b50eca6eae75319f49d421bbf28140780d9116e3ea1e0dd4a3a8b13f7f2dafba6d3353a2a9a56639c79b863a2407068e6b70516163010001 \\x4917f55185492fc3f2893160420fcb9578345233b43d818551ddaa271550497bcb6076e2f8d7b6f42d885286d44a4ee86f4099a5050aa5f4124b18172664e60b 1676193367000000 1676798167000000 1739870167000000 1834478167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-294 \\xcf92631d9295bf53e8adca087de47b10d506432b0cdbec8ace81dd665e53f88aed506b99b034f8f9d514a389e8b463af089af6f081168326e6c3279d9d9d8874 1 0 \\x000000010000000000800003df1e7062598e407960bf876e95371a315718007d086266b6af13ff2ef326d2855137bb2bf109e04f441686cfba4da4cc8291bc753616fd265a1b929b4bcf3391af93ac8df44029f977dbe343aa46c24353f57608829357432e7ea029ca4443343a68d487ff26c2ab01758c88a0d204fdf74c52bc825cf52de6d9d93502c88149010001 \\x19fe29aae11077d383eb7cd4daea01805b991aa9ee20f05f8313d0f1792b2f5d33685c5eb65487d5aef3981132c12367032d5cf3e9a6c47d988906729dbd1308 1677402367000000 1678007167000000 1741079167000000 1835687167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-295 \\xd126de3b3854dfa793076de68000fc885e612f459ab968c29eea6670cff58bec5e6d8045851172e87745c975cebbc673ccc57c8191477a680e9b3a0c542bfcc0 1 0 \\x0000000100000000008000039869be18f55108142bed38d140e955322b021b1c6521fa3a8075d7f2f72aa3bd6cfac3b5497986784e6863643090bea6111ffb16384fb1a9d02e5e310f85b1736eba572f798a04526c044207a8d1ea9a11b7e17a5cdfa7f140d476d6290bdb6d701d32f7b87ff051463aa610b02ab1fe76bfbed6655be10a349b25750fb59ad3010001 \\x8c192aeb746631beb5e8bfd0a2182fbb6bb0d5c9cc1796b00d4413cad9754f0cc3835d429145f8be7684566c5bd9ea852085a117c3b2cd983de6a95a7a40200d 1679820367000000 1680425167000000 1743497167000000 1838105167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-296 \\xd17a4919eb0dbe91debbbd209eae757d55c0f3fbe6cf3e561b4dade57747f46a9353a45a69bcd3b42d895342975b9ad24b4084e058c59876fd3f93d5c7ba6383 1 0 \\x0000000100000000008000039ab3e3ba89a4c4d3412874dfebd03c284dcfb7322e38caf1a6b92614413b8a77e17c0429749835d935325fe3f7d25a619340b9b6c55c832baa75f00e35f16b06c771bbb824ddda5213efa1ffc0dc2e81b95f448e5acdf408faa131e6a6acf70a378e506871f2d85cafcfba128cf2dadda3470477283d6ea73ef5cf6886e3babf010001 \\xd3f4cec27d18c55b0f55f569fe1f0571ba2d98c8c422686caace6b02d057f15289caea375a3aaef957e38a543adc2fbf6bae3ba2080d9e24e6ed742eeb868a0a 1677402367000000 1678007167000000 1741079167000000 1835687167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-297 \\xd2be2e7de577f3520f320d2c85b97045630eeb0ab900e47bf199b5b5c1545b0c91df0cd7da55179cba1aafce9bc57069b76cd984786841824ae53d055813ef63 1 0 \\x000000010000000000800003ab1d6572beffaab0e0b125bb3b8a76eaf36f948e2e2fc5c93c435cf2f5c25aa4c781299248cc714da23bd7b12738679635d65015e11da32a22c6acd7b10499d8467b59aface5b0fb6a3cb1b0f689a66299b087dc6d57780f571d0d170ae2c19807527fc7c7057543dd70e9f6880c21ed386c10f17d3689c182ad69b541cd4731010001 \\xf0b2b6d662324817d79c0f45c77b16a0df7d651a06fcfd8266dc29147a37029ff860eba36092739cb57fa70967bf972ed09213ebd3703ca1686bf8797972bc0f 1665312367000000 1665917167000000 1728989167000000 1823597167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-298 \\xd39afa8f50fbe0e6aeb98b5ac8f3ac5d970c35297ed0a0fc0e46cdaa978f2a4f84695860a5baf2f6ad283a5437c85b65169186d3296ab275a2fd04a4aa69f1a1 1 0 \\x000000010000000000800003b53a28b6c1a18340285ddbc7b1fe07818f4c57204c43fb10677c14d2c98fef52434152b400f85eaf489941911e036369dfc8baed319a192f16264591909a2e6e8d9bd9bc62083579debb13eb6dec1d7860b49415b46c45941d07465e6a93aca9693b23584a5608321cfff2547fd819288a5f2890127f112b75ede8fc621408dd010001 \\xd5931265c2475caf837b60d18fdd8ed154f0de074056d3fb3b85058587d5a8848c5cc1cb6f4fa047a8edc6a33adb5ff6111f5f044b090fbbbdff30577f811d04 1684051867000000 1684656667000000 1747728667000000 1842336667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-299 \\xd9be2e47275954b419342dd844b760598ae06300bf3580ab44d255f7b6c473153770297fff197f21070bdf5154ffca2a8067b9fee2b4c1d67ecc8768e415d685 1 0 \\x000000010000000000800003c6314727cd0215a28cf351520de3307acca81458e65ce392895b4f94b40757c28e438278ddc6b305eea124679b32d7a8842e58b2dc8e206d108d4b2a55c6a13251ea656739a28a8bc557e915af15788870cbdaef4b8aedb1e523b01b3c14bee339ced0e9a5c8238a5d36836bacb397886be5bcb581565a016c0f8de6d684b299010001 \\x86a502baeb94901878353b02a6f7c046a6194e51e2422c45cfffb2f1cae444ad415bb398f167d18ff9216478808b1bb4b01d985c95fd5fcc45649b3b31146f06 1684656367000000 1685261167000000 1748333167000000 1842941167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-300 \\xde0acbc6c7f09e34a6a0e91203187a7c50e7c4e0e08b648e1679b45c40ce85f9ab8d13dbaa18e0af751da3fe4cc2d09640cb24635eba0f7b15249692ed1a2a3c 1 0 \\x000000010000000000800003b2edb1dd35024af419fbe03340811687a62cdc42c8d447a325779dc94816c6ab37edf64f99183aa0e8d21a768658dcec3c9f12046c0596504db11a5ce83638d1b2901039546d36a134cb772bb62d7ead34d4036809bce49d9f9713f45f034a28f00431b6d835665751a117fdd8b709446eb1a672e8b2b210ef9f8fc19935992b010001 \\x587725671ee07ce9a0b5fe8eb47c9245a00536491f9d656003fd05578074f2022958a7042a5e8bb8e0e9eaa88939cdfa78c57cecf8ec55c6a4828922176efa00 1659871867000000 1660476667000000 1723548667000000 1818156667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-301 \\xe34a92d329550c88039598a3c86ede2e6f697b41d5ef18eb4ecf5223d204a6802e575c309edd7cb37011629b726f50a3b972b55c700213b812801a3c9b17e8a6 1 0 \\x000000010000000000800003ddc3b76e444e1f719871347d9a489926fc82d0534f48397b03f833d0505f1813566396a6156b3f908db0accbb47e89b2d906e0bdfcb5d60aeb954864f7b657d04f49b6bb49f8f9bb07ad27d6f164d7b3fbdfdfddc90a4009530d47b57b680f10b2916980fe26effb6d68130bf39f032e438d4c5c8ef9403077680beef8d21909010001 \\xc7f5de8761e204688701d298410302206a442c733aa811b395c4b7a098c1e268285bf37b9c8e4be7c09c7d3f5642f2340bbe1aedfc3b8d253d04bb236f7b0500 1667730367000000 1668335167000000 1731407167000000 1826015167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-302 \\xe482b7ccd0d5092677cbd2a5662bacd4e6f2bbac1d337513922ab7b7f156a637123cf11bedd1af023a45646cd3624e7199c07ef0d39251e86c2d90702f995a62 1 0 \\x000000010000000000800003c236ea39e84918b7165da08d2427833a81b2c06782008d1ff19078f6501e079e22d7bc95c3ec8524fa5e6a104aaacd93347d08d63e72b86fd4082050f47108601d5ccf3e90a688f8a9ce839d67a608a31d677aa10ca5cd14869ae7209873f32868663bfeed032be7cc663cee671c5a56f8d48ba3d23d3589de99b4f8e517693f010001 \\x8027dcb38aa968adff760bd1c37b5638fa65d2c71905296c4bd01673faf21024f8bb46581bad636708c2d08dee29b6e0131227846cbc7a395ffbdeb870b1f905 1682238367000000 1682843167000000 1745915167000000 1840523167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-303 \\xe8268bfe9073c309bb57f201e088938b24ec88e47412e4029facdf7363cd89ba77e2d1c62c47333af5cb7f3674a7b8eb0a95b8fd988c7286d9663da258026579 1 0 \\x000000010000000000800003baca0d45b1d1087bb3fb4760b0593db3abd746efa2bdd7bfcb4bfb2f4ac899d95149ba89ea7bbff0ee121e0498949810040d8c0f221979e345da930f59ad8e0aefee1e038bac0b191a1c2601beff77705a9bead63b361aa62cd16696c78c199a7e65e251e6e855178382f4e5471c97cdb1b38b134806325c25e5faf95404d8f5010001 \\xd8b260651185174b1e6541fc8260040b9df5cd6b2fa3eb0bbbb39d3ff1ab75e133fa11d36bc6599970193e06d9805d6e9eb8c96c22bacc35a24d0b27496aa200 1666521367000000 1667126167000000 1730198167000000 1824806167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-304 \\xe9b6a15ee08cdac34c77ac12b34be56bdc47cb7688708e0a7e8ebe63edbb47cb935dda11797158579f2cebbeb3a7ba3254b756afa4abddc3adfa1769f61ad328 1 0 \\x000000010000000000800003e52fca067a46286ce5eb2bec735eec3350da706cc7b3285ec1092b3bc257311211f6109706b8bd6ef9d0e39a13cf27628057909d34f1c801f40503edb78a94c9052745fb86b0e723f6878c77ea820bc6f0b41c9065d5354fb08922ef4ae89d2516065f69be8bdf4cff0aeddcaf58972829d6d8c2540239112efc49dcd68de94f010001 \\x98688314bdf5e7f1ba067db8b18f2ab0a3b602a6260843c26a2caa7d2684d0b54fe1ba7fe407532598ce49469b930a3a06489c995b9c72201bdf22cd877c0804 1661080867000000 1661685667000000 1724757667000000 1819365667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-305 \\xea7688d0b4b17ad3b4ba4a220e09df2c5b9cb67c44e452f3e9638b0ed1efb4f6a6cbbd330ca8c3b89601b1e315bd49aaa7b2bf345985272cf04d996b32089638 1 0 \\x0000000100000000008000039e2740cc210aa59cf2370181873bac8031e6cd97fcb51f79129eca8a0aa7c2d1a2e5a858ac57b3aaa096983a3b5b21feef0dd3e97f8164c4c4ad5d3e735d56b8ca02a0222c5903643f87bb5b162dbbbf4d6377971472d15ff6636cc589a18dce80b6d120abc0df4b06a7cce76215702a8aacc795295c48e37990a307bf18c9e9010001 \\x6704bb478cd9d5f5947d49ab02ff16d341b15e64cd6306238ea5b446c1e8f77e312e55f813956dada539e669adbe84f13a0b3289f33f285bd075cccc4ac7980f 1675588867000000 1676193667000000 1739265667000000 1833873667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-306 \\xea46ee9fcbb2c6efdc97bc71d5589a898b1e9fca87fe806bd68928b00532634ed3d62910ad04c24aca2eb21aa719ea31ac3d509d774ea776f6cd12eaabb9aa7f 1 0 \\x000000010000000000800003c5e17d19943eb014c3179e058f3a76477ad71c9c4a783a0c3df9e843698b6fbd17380a0c890da3b6d7f4fe3f884350f1d36d4ba41dd9856f80c05dd266973551980bd11ca3e1811149a3a54d7880b8b7827279e1e9cf79025ad8e3cfa018c87ad220b6fdc9db378fdc7f95c75617452f6911ea0ea6060025bc5c20e588442cdf010001 \\x38bf866b9f8845527d3639b05e471b98674ac53575e1bc08d9e84fd94742e3ccff5509557b1fc9932356d0c7f05f3e4571941669b5420ed9f0cf07649d4d4f08 1656244867000000 1656849667000000 1719921667000000 1814529667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-307 \\xec5a57ca29751f0a3cd504b901633ebf4afdaaa20be0d0709b083f7167bebec007353a37142653767d9183e9ac7435fa8da2fc112b481cce991e23ea7f8bc282 1 0 \\x000000010000000000800003da55e6970568761a0ff4d6480906d439908e86bd74ec3fd8d1ec503e6bbb4d63cb78589a2fb05ed03b9cc519c4cd6175af0c031ac774684398295754c4f78c6f7dd17ea027d8bff9d7a66c5c6ae74eb1f0bbce9f51e412d58e45aa696818a3e54659cc188b5eb39be0a937c649bea8bc0a16c2bfed548c3cd09d6e9432c6121f010001 \\x760a7902c4d5e3e27a198e68f87a88b30b861d783d3f065ebd1a8859b4c2d7c7087fdb17cf5fd6fac5e2a8452737761b59bb85748709376d410cfed588b6a009 1662894367000000 1663499167000000 1726571167000000 1821179167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-308 \\xf05e198f9712949be02064edd3fa272928b833309bdd1752610b98d58f2fbf3bef68398410dbd5a9dc11764df4f664ed5b021b9a46bc108f92b94d0f127fb5a3 1 0 \\x000000010000000000800003cd4daa5e230ee61dde4ff057e19327c58b9d7a46d3661a2079bed483cea7f486b9d3e083971ec19551c1a7cc978d7a2934e5a0af83ac7cc9d5c0fe254fd4e1ea71daf9d285ee9a1a76c32dbe92b2f757efba405060eeee814501209dcba11d3ffb16d44e56bb9535cc49f7161e6e435f680e2fdead3a1b4e44de30d7d19c1f53010001 \\x8e2226f49a705cea7bcf730a74390d92079a453c35abdee83dbb10daf0690df78fdd54841e996fdac3f81dc029d53128c90d957445e5b450778de0b17d3f7c04 1662289867000000 1662894667000000 1725966667000000 1820574667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-309 \\xf36e3bdd5126bd43e40901ccb2bdac0d32ee0d17db19ba48023c0d6361d0810add0e89917515185c5162f0452e47c6d48b707014a34152729fdc9e80b75d1718 1 0 \\x000000010000000000800003ba6127110da8111e722a441fdd5b1385d57ad1f186d5bb183f497d02898ce2080c1580714bc866135108e6af23dfae61bfa758f08d605db8c633d3e52ef6224e8350157b575c31b07db4b2a3067717f97ee12aa4e3250ada8442f086479188f1ee9c79e9d54d7f15060ee08b0083d14c0588e0b28b37af6ac6afb929ef49bbab010001 \\x875c18737851761b09362354cd1024ea85fe764e83a7304ad5e596d0cf574e9046d85f102c32022f9c4de3e00ab83661d6f3a65b9ad43b1278b7018cec4e0e0f 1658662867000000 1659267667000000 1722339667000000 1816947667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-310 \\xf52e9ffc22c7545fdb9ca042ed05cb02453cc41b97f77ded6dcbf560dbe9c3b63fbf59b5b7b5507771fb7db1913553aecae6d92bf4df47d7111611bbdb74b1a7 1 0 \\x000000010000000000800003e1e924c134b1e996e1a2948c9c7f42419341bf5eb0ff594c899c5047e9d7c3f870cd0b2d0b412755db70332e236d7a575420464e3d2f7542b6acef001548be23b3510aaf5062879c59f1f60415d31abbbafa6212a7bae53c2384c2834d64b51e630c42e4db53f51be7ed66233d1dd63826c29d6135e1e74143c128e05c9754e5010001 \\xe55c15f8c661d40f382e8e0a7fd12522154e08b7719781af0518ded4d47f9647aa97a0aa15cecbd2de3e6c912f77a24360d7b8e5bbf2d4f98cb82c588e1c8005 1680424867000000 1681029667000000 1744101667000000 1838709667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-311 \\xfa3ecf2462e0d68244a73242b181a3c00118fa8f124d2594e84eb74faaf54ad785d685d3378c6938cdfe4137020d9bb977f8beaa8ac7e9f709b59f4c7bc70cb0 1 0 \\x0000000100000000008000039e5bd403400d4230423d94ad734733f9ddb905f0391c302fee66097a6c3012b86f374482008a5e481f785420b50b3b8c50b6edabb79465aca633367479259898616466d437c233ae963cd311f321147b07a7df3a8869ef6a53ac2aaac5051acb07d59a5f2e3e75d2caac444bf05f653ac07d47cdfdce24e6f41659e403754895010001 \\x6e92ec096b0415620e0571647a841528b460a83107803151dcf65c89a72667a6294f5a098da0f4ee07831a948f472f47c3d4f2ec29b793f4bf8c736d7c20f601 1674379867000000 1674984667000000 1738056667000000 1832664667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-312 \\xfab2b777375bc6b056cacdf6334d6c1e1f64cbca3c2412c2accaac891b006a3114427e1ac8260f893ce7ca4b7a8a3d4bfaa2810046a8e8ef772bf46053b47f28 1 0 \\x000000010000000000800003be67d2401aef87d57b5068126ec1dc09fb4dcf0ce5556a16936cb2392c54a441f25718d0bf9a65098d00e50e7488b2077d9606e2c38c0241dcbb0f5d23c95e960d5674e76817eb6f5888ff999925c251bd2651bb3e5af5585e4a70de5f2f450b17f5ccf3a7566b259f931b048c25ada0ec651e7973ebb373e8ea190e0760675d010001 \\xf1cb1a5cbee114bd11af941e8fa0b368bc542e610934db298edef11633b76d0b79a07e649ce7be0a32c940f5fed1882cf5277c9d6e9302f82e87c7be5b1af10f 1668334867000000 1668939667000000 1732011667000000 1826619667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-313 \\xfce682c7af543584cd32f5b2a5f4f95e9b436af21a307dbdfbc7764a4b9ddaeaf49f29e0d3c50aeb0bbb441f8498f88b84cf162b9ee68928627637e51a682bf1 1 0 \\x000000010000000000800003bada471b2336af1602662ff7267b9690bad5ce2f120c6c86099350eb92c4ebe214cc187787f4e8e2b493635fbc1840694988133f332cad85cebedee3033be8f470a06cd202678bc75e061e1bad835be97a4157f12c5306b317c426dc243f2689f783ee582f9ca76e0391b94cf7c9d1480a6ba8ed0789b00837248ed8a1ffa78d010001 \\xe623da217de0165d4fb77f684229098575414993cd5adf40bd53f87b94b5cb0dc0a28f3df0ffb22c643435044d9b030ecab8929fd4908c6a82761bbd7a8d8509 1664103367000000 1664708167000000 1727780167000000 1822388167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-314 \\xfd26d64778b0e28f0eb0b589c47cb10e2a35d05916b4ddf716cc5ae1896a660ca9fbcbd108b19f6677c8b757544d74dd49fa5fdd714c4bb53cc9978abf3c9e7f 1 0 \\x000000010000000000800003a63ac2dc7db873eb837e575a384408c06c831e7162cc1e8cdbf3cba7207785eeef6cbf1fbc9c38f52c63a2eb60e19cfaefb35cf1d18a17e63e24ec83ddccb411f477a0d2cde36f5b7ee734ac474fef0ce6af408164b7296504c7094aaf2436095323c362881a87d66dda35ee96c3a300e2d4400d93b0a8aabfd479e28376cef3010001 \\xfe6b74f118c872d240679da17b62af3625c0943971109d0d3758105535102d6ac8c78dbcb96be72ae880cdccb7366263cd4184789cc8cd5e61e1922e10f2c90d 1674984367000000 1675589167000000 1738661167000000 1833269167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-315 \\x02434d7a879771f2abf8414418cb7d0db25e3c7a835922833e13bcf580e6975ded291811e4c137936000321fe189c59350cb9dc04c1d7b4195e54cc58a82dd2d 1 0 \\x0000000100000000008000039b4ba3007cc4a47d8c1a0071c288546c37f2e379f0f7934f5fb30164f677afafc8990eb079323568a85864feb53b5180758c8c43baa2206fdc11a7c8a5c1f766fde3d7a19a655edfa665c45fd34224edcf08d72ebf43f1d1ec46ba43ea0a3f6cef9c352129bdedb8be5123f41820acb10a4fee5ca7521a130804b588b47aa91b010001 \\x2292d1ec764503168313b47aee293d8c872cbcb4654256090782cefd78781b44b52f59b24c8a572ea28a9498209b997eb69b92365abe1a309df51348c5f7e306 1665916867000000 1666521667000000 1729593667000000 1824201667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-316 \\x0567e4466ccfb095c271e91134fbfd515dc68f5bdb6fe2ad54af11333ac0171ec6a8e931a4aef735204967c605cf37bd338b59e8ac88d79186c16a13f31f0782 1 0 \\x000000010000000000800003ae6c1610c48b2e6ebc65d0c386c4c75f2486a3f8ae2d5f3c95ebc647212e1174a68ed45966c96b598f2805f626366ce720f2089db3617c18c3809ff9078fb7f20e4daf9574c1bd144f89db8ab9586d941874e6408cbf7f30935b784cbbeb6d749b286207d04ff794f55d302e6befb02773c55eaecbc78ab6e28d7acadeb8202d010001 \\x944c3481d7eceb2a5323c4cac03f7b3054331af938478ef40bbb741457a1041c3798fc7132fd39206e909e81e7ce0973613862e175b1d4266fb59b12ed60d501 1658058367000000 1658663167000000 1721735167000000 1816343167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-317 \\x1173cba970cc600382e2b776347d55e64f534d3ef7ffc8db091e485ff71ce00a39bb491f280fc715984fb67f21c8f4a27d54995d76753ca35a0954a2ff35bc2d 1 0 \\x000000010000000000800003bf90136fd9b8502c29ad96704dfeee1431f2bc77def17d5d0fefd6272514ffbaa7d057f11012a313a46348b7d12f62418775c469447b4c3ea3ceae644a0d15ef48e001d8e6dadf49af9de4b35b06ac3012b9b17a5e18db5e4f6c844215c929abbe628784b4b363fb5cc040408d13809b14c1ea1abde6e15475eddf6162bffc83010001 \\xb056c6f0749992fc6af130c1437105953fcfcdef260552304d4d710264a2b87bd4f38218c56c9cf7abc5b68ed4c71cf44d543c2d38c5fc6f6489e237feca6d0c 1671961867000000 1672566667000000 1735638667000000 1830246667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-318 \\x1133efd83e3d2a721d63f7eb2e5de8d8b65a089caf09235aa7d8368eebb2f96816c4d7eff0f67528505516c434217fdbdf40ae7226b9762d65499cd617c1cd22 1 0 \\x000000010000000000800003c626ea7847c10ea15f216c8c1e38926e943677047f3fec28209d2f242c9603027e5431f0f1da6ce085a2e90365531a12c922e09ce6a418c60b5f7435e36d24162ac3d34180c23b79df1f010d647e5ff42d27e18749b944763c79e8efa454b9231d88dfb69ba6b0329eb80df6ce5240d0dddf3071285dc4dca5a122b2d8153b59010001 \\x21c55a34f12fc1a88cc5075de637fa1c271b4a088b5a51784509f934103070b05dcae7371bc584566f8ee057147de9e6b630188dcca670973f348c34ad721406 1656849367000000 1657454167000000 1720526167000000 1815134167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-319 \\x14df098a2c0bc68ec52edcc927dfddd725dbef8b50375a158142dbbc29408bdda30dd49347a784a29f7ef3ddd9273e5d3204243d076ddda16e33558129ff254d 1 0 \\x000000010000000000800003b202879338c1ccd020d185d470ae77e218c5b9b42167e763f10fc16096d0f00a53b40cbd9dd337f16a6d9883e3b79255fe458d5ccc274c9bd026d0854c57b8f8ff955d138bfe21d2be68603c3f313b276819c0b214e52d5bba6dfc270613de5e0516771656db5532a3b0ea66d6e1aa897a9afe6470908bb4ca1da2fd9ae5fc81010001 \\x1f09dc3e076e69c444cb51eed0fb6c8dc978689c1b379d54a0e8e281f250e4226078759eb4013b5d5a35dddd2cc58ce4ec594d9e83b9a04f3c38be9c989ca90f 1661685367000000 1662290167000000 1725362167000000 1819970167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-320 \\x18bfbf305bcc527639ceb26f6aeaa49ca5f380bf8d0bbcbfdca75e94b56974f784f1f5e96ffeb708857bdc6f703be46baffa3024213c8ad705e97981cff90f59 1 0 \\x000000010000000000800003b17aa45c703c4a34f5a5256ea33fdcf99996049ea6d103ce4039586c0a4c2076d9c65143e7d744c450adbd3c8100e03db2c0ac6e1ad44b6b951a9958d560288ee04fafa947ee177f8e7b09b22822024c473ff52585a13a9f1d3858edc57b78ddaf0841bbc015baad70f54c0b6060458b78f0ebdd2580818a0b3f026c53e2397f010001 \\x6e1a3a765f68c5c5d3dac4d5d8daed2e67e98ec371242841161c3aae58f9c90ada707a3de7e0f53187d0fe52613c0d73c4cedaa5359c8670424d2eb1442fe604 1671961867000000 1672566667000000 1735638667000000 1830246667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-321 \\x1813cc0079e0266e991012ca6a697d463076e2995afa979f5eafb370876d86dd98304df165df29b942110304ea178a65b4f8bfe549f02f47d03962e22d3773c9 1 0 \\x000000010000000000800003db0b7a68d0c8edcee28dab6eb3fc5aff5bacdf6212cd421e04b634096863b346469016dc3d5071673ba4c83d685701337b118fe2d539c56e3d5706acabc29659fd27a0a6b831954c05a43e220a04142af4c60d3fdd1f4885df17d31c75d89f413dedfbc67f925c32cfff019fc9e28564c4ae42b3cce1d5dcfa7b73defd124bab010001 \\xe85b1b799b6f896c4dee444d2e8ce62e5e70a38aeaae39741d8d44a3fb47b7caae9781cb1982cbf345694c15a5df0f31e927093f0c0959bdcf9e549162b2450d 1665312367000000 1665917167000000 1728989167000000 1823597167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-322 \\x1b9bf48722871bb49d382311bc578a32f8cca3983fe1775c95a3f77383b492678c3aeb1132cee60dca0892ce6c53fb9ee2280dc6495c6a0d7a701d03cc59cfe3 1 0 \\x000000010000000000800003b1b8ecfedb7fb49ad8fd5f93bff6697a10065053a071dcb5b82f48dbf808ba0a64f5be74eeb5f0fa0626bf2712497e642d212561e8ef2ade89988258a8497b436e85b2b6b72b2d0223cdd39fe803127bc0165acbcb6bcabd3d45046305b077e1f1c86802249e5ed7bde66dc99131756feb28f4b020d1d90e168a3b2ec742f271010001 \\xeb410ec659b80a61cfd77f12f9633922c4dc6b593961557e9b529195e29ff7d9d3dd25408bbd60e5b901067f75ee8749053b15bb4b978d08c4bf23a34046ff0f 1670148367000000 1670753167000000 1733825167000000 1828433167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-323 \\x1f13f0fc8ca25b49f225dc19ba7f7769f047a5d07f2f981e011d07eba7272b83153d867c8a58f039e6e3c7079384d74716469d89d13b2b72b4d0853d045c2eba 1 0 \\x000000010000000000800003b551c66814ff640016d63a89b5566207eb049b5be130d0361efda7203749111efc43ba367f00582ceeec38affaa21b52e2d922d80083821835661af795c693e5c4a8c171849c12ccb66bf973be1fe9abb2212f8b6065c2c88a52c31c3a64c0264a18197efbd866f034ae6663b81004d7765d8ddb9e270a3804996e251829c875010001 \\x3123c53c1426e56d178eda8f5df53e49a4449b6f204e8bd6f4be782ebc2918464c9cc40328428aceac6507ed0dfb8e1bd2298efd3dca162febfa18a10dc99a05 1664103367000000 1664708167000000 1727780167000000 1822388167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-324 \\x231b4a87dea1c57238a4bd284bda3b7c027fbc945133cc6f462f61f6b47b7eb760aa209f3489d414dcb3aa03c79041be1101742796f605ab55ff43a85b7d923c 1 0 \\x000000010000000000800003db18cbcdc4bc1be0317253cec4e199d356e90fef55d1ed29bfb2dc3c667029d59e5234101bb37603e6ea923c6271105f13850767b689c8997bf241f5836a2a768ec76e870eb3110f99cd1e76a6541432030ed467f8ce57b422c280b68474aa723fc075eab32ac379a125d216420a9585a69d5de6b797d91e21e62d015c189c4b010001 \\xdddf6f97f68987c1c5f1f67181196cbf5b4bb5eed21a551f74b5f2819a1aaff38314931448b764b4726c834c39c100d29b977c0be04503e3655666e354d88000 1687074367000000 1687679167000000 1750751167000000 1845359167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-325 \\x24e7d6724b95941aae62989ecbb3d492e80137741d8232d2e208c0cbe817fea4aa1e88f12b25b3ca261be68dc694f42576e90c80746104ccb8c6b1a76960057a 1 0 \\x000000010000000000800003d3559b7d655f872e9ccfb7bb9834406a60f6ea771fe5999036f17a1454c850965b7cc3924035f7b8d4d6cb136b6487d8cbf9baab48b76da811f6999399022cf4af1fefb36bce745f0c285b7045fb065ef48fe710705c58d78927118d4314caba40a67f944751b32117223fcf6697814b47bfcf0de8217346a43e581cb072db9f010001 \\x689da9287ced84936cf65e320302e9d28854d6026fe1dcfe8b26f123134b07030201f2a82bb4c9b66561865c8aacf41f9d0f6587a55e30da9ae821050309600a 1666521367000000 1667126167000000 1730198167000000 1824806167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-326 \\x26db02fb67a0e9033043a8541940c14ce64e98f85478fee788b3e58ca2d8ecd66867f8404bc657ce1a8430b1af3b9123233e1ab97e51bfe7a5c14947a37f3557 1 0 \\x000000010000000000800003bf7aca62ee190c72cd0b0802737e793a90294db66738869ab1992f2d63b1129037fd85574bf28f8fe3a130c69516797fd8f8a928cd02606ab3c0052ba521e887c606bc6251539f0c9374d192474f1f52d30f7143b5cf683d33018ac4baa671f01321059e94d2af7306c896d824e0b08887969b2a517c7ee632c13d2ecf60dd1b010001 \\x36bfda479cf03449b3ec223470e9778f7d503cd18bf70377c1c7d9169f0e4101841ed734d2f5ab6713e4d135992aaef2ef3dc6804c29513e9f3eb8e9bc682600 1671357367000000 1671962167000000 1735034167000000 1829642167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-327 \\x265b54e34318bb32bfa0896dad1d89c1f5587b95fa45b07d2ca47c5a1c2a4c3a485c8ede476cdf95b3cbff98192709d52fa59897e36f10a49c918c66ae0c942f 1 0 \\x000000010000000000800003b61b0435e89a49d17d331845eb9c5dd0af2c962e7c6d32f8f79ff7654f63f2b7e67aa486942e15236acfcc023de309ab50dd11f38ce449c94988f434ff0a8a117ef921927a056caabbb194951b71c800b8a6e0a6820f47548e4f87a8d75273e379849a75196f9d08bcd831c30393c18e32e5ce720c8c710dbdcd7afe508ee497010001 \\x4892f8247edbea9a06fc636fe9483e9224c2bb4f77bf8942cc2d4d6cc91fc452ee4f688cd6109855666b74e43260c26aa66b22970a9b0de373e34cb8d63b7a09 1684051867000000 1684656667000000 1747728667000000 1842336667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-328 \\x27079f291a72e01a007db9e9e003194ba90fc26de5cafc4fb79dc246394fd568ef3428d72123c87c20d7e63e4b88a0868aa52c6f3e3c89956134dd05db14c822 1 0 \\x000000010000000000800003d0a6ade645d38367428d0f191afca279761cecbcafc201c48f2e9350e787f99c620cbfa2bc7a5e8d0f97af5656e5f8bfe5d25fbf3460230cd79643978c04ddcd847576a38dce47349edf0fe4badf86b6206eeeef1526b0a374c7cc390088854fc191a5e005927db9c245a1da06d84063c599873a26006e0bebab3f2298b51f8f010001 \\x8a86dfb92f1e64c24df7cae2b8e17753d44ce820a2396efbafb482c1790dede341d0a4c3b6eb54c91d41ff110e8b5c5d9568d4a3ce4e54e4cb053a7e03b2dd00 1663498867000000 1664103667000000 1727175667000000 1821783667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-329 \\x2adfd7d912de2f7a906ef9693f94ab9b56000a6ed878aacc5eb681b53196dd67d9da0cc8713c937c29ad7902832d79e1be318e809754f0efe0c36456e4f42149 1 0 \\x000000010000000000800003bdec12c93fb68448e2766527d697308a9f681205d1bb4cd5eeb205627efff03a9c078a1e27d5cf89326db4dae1c091adfbb41383d72c0be3f06690e34c7846c8f31fcc2ff538c5f7e783dba12f01f285c3ca50fa3377a04384f98b75b56e285953d57495b4af4cb1189396daf26402504daf8be56415d91adec3a8f7179df997010001 \\x80a0e131949e36970235d0be18d1f17464bed95cd41087a0971c8b2921e5f07ac99e18616a991b113331ceb6512ac40eb9e8a294eb30eb9feaeeab459abeba06 1683447367000000 1684052167000000 1747124167000000 1841732167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-330 \\x2c27e9edbeb49ff855481d970484e4ef97423029ddc1213a2ceb576a6742da85ea0530550ae6e036f1b6c2528e6b05107bcfaf1ff8414d83e4b19505089f6cd5 1 0 \\x000000010000000000800003a81bdc62becb1bf38185b40364f294910bfa9aa14f6f6e7d997b9f24931242bce6b81dc85c266bb107207df1b2f4bb6d63f7a739c41088854188342759d8ed13a192ab14da0d77ad3957bcd11823a07148920576d6c63006f22700ce2334195124beac47f33ca6c4c84d33e3c283c30ce63e8915f82867d468ebf138c275f1a9010001 \\xf2901c4dd64caf4ae156846d8ccb0c38dfa152d28ecea33080d7b3f7263fcf727160c1683088a0ef0c5be5f20eeeeb9daa114eea2d13a806b32d5e68daefd400 1665916867000000 1666521667000000 1729593667000000 1824201667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-331 \\x30eb8bb3ce0884c33a4b5c5e38e5f89216e9061169eae63aa12b90fbbd5da9b40c5b61b8400088258ffaab2693bfdf07fbadfd9b62e97c8f4ac06ddafad656d0 1 0 \\x000000010000000000800003d9663e3f38c31f9a3b623ec1a37dce46aec9f2ad600735abb28e12cb17133971c9600f50ced6e631dc4b9f0b6f0ff4acbb71c875c7a9fa7ca556e2726b431754bbacbc69561168f31ef535d0ada83bcf924a5c4a322c771b86d1345432a0ad50a520888b6273e4fecd645f93da43f7a957d706acbd0d9cf410e32f5f02e02739010001 \\x4c71c421f8792ee71d38e1ba1e268078399f7a99f6fdda7ae92f92c7f65faea45d945a29d87f65fdcea35eb5e1c03fa64f60bd99d49b71a7733a977e4f1e1006 1684051867000000 1684656667000000 1747728667000000 1842336667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-332 \\x306ba17396e532304406b4475b68f55622f64d548d7dc3c1c6cf00e89457325d21624b17c082d59de4a76d32a6fec6e714d4d285a050f335790c8d7574aa2a73 1 0 \\x000000010000000000800003b8ff6da347f4c40896cc3c33bb066e745a296535cb423a7dcb00c377057d94f1169f5a9487f01a192783e83c6a6fadd0ffd3213cf95f94ec0f39ea4fd55e1597ceeba85fe779fd2d757525fb354acdcde8a04cd00019d1df5d4a15baf67105267bfcdf5b0075425a545fc32213e72d1da7634ddf8dca72be66ffa1dea6b4cc0f010001 \\x2be01cc8f8fece97d65b01125d76fc6694706d86bf58dd7c00ee4c65773e8e59b93e98c34be0dc3e3d4409c75c37f33d853acbcf9f9517b6c3e5a7189c36030d 1659267367000000 1659872167000000 1722944167000000 1817552167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-333 \\x32a79ddfe1a2638137c211d6e20d5f69c89af26d0d857a401290a570c93775e78205d00d6384189c81f4a40cc1936710e23c0520517fbdf92ceefa8b7c75bacd 1 0 \\x000000010000000000800003b2bb631f5a2957e20a510bcef012b336e2729f32d596a97a30efcf2ce047e003a23df04c97cec819102b4fcfd929d67d7274c9816ef148b7da848abdd173ca9d76ab8454c72b79bc57f7784f1f31e6be425e5fe0a66373a814fbaacb636cdc7a8edbd01f6306e20aa1d61857f7969a0b405433718a66bb5c3a6de4d93843cf05010001 \\x5b0ab72bbba34691346e36c4fceb8d8baf740a0fb151b415ec98bd994aa3d2df266c5fe1d1dae73ab2be3aa2fe05e3c672e585e9321678efa9b7c37467147f0e 1672566367000000 1673171167000000 1736243167000000 1830851167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-334 \\x35d74de26cc9dc3f8e9bc07d678bb40c07e43aac12e21566088f0ee62168ec122ded3517175691c5d48a101d41ab0878a494fafc07b24ed5633d54d4e429e963 1 0 \\x000000010000000000800003c61c240c2f5fd334de6c9e6924840e150764719fccfbc611179ce2932079ed70c1b77c04b54bac7c7f8acfaa2670474c371e28849a18906678c025653796537a334c67fcc7b282724b13fd2404d4ace9d9555890cc530ad0e7764339739a97ee717a6b7c974198e5001a0737f2cb7b87fd9262a29e8ea23705ccea7aec48dc43010001 \\x6034197855aa6212cb3bdf55590da82833471a1eab01a01ad6c542187bd58f6a54efd78a39c0c2591fca61c12b812eea4e472af2bbda880445c0d06ecbc2790e 1661685367000000 1662290167000000 1725362167000000 1819970167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-335 \\x36bbd20c0e3936e762f2c7e89adff5c95bf74e6766bd7997e5620ef590cb87b0413ce538cd5d1c64cafdbda8d9192b20e14af02f4a009cbe0251b53b25107124 1 0 \\x000000010000000000800003ac84180bac37492baf28f3cbe4d98c63a5f7e73d85bd57061800bfbdbc80edf32a691098869bf663871690a2f09247a01bf994861c2e7f7b8e962be67a59cbd9e9c48372a26e25f05d17cb5b782fd56af9425162c658bed33fe20753f9a13826fb900f74e32fb75fb466c1c1f0325c474e1fb6cf601b64eabd6e1527008f3ad3010001 \\xcd81b335b27dce35ebba5a30a1ddea6e898ad13d3d31a101225fa368528d3b58c68ad5bdef00cb6014bf7302a3a5af69c2fc4e52c0bb842fccfee5676e3b0d03 1664707867000000 1665312667000000 1728384667000000 1822992667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-336 \\x36831a8884682db9f580be67709a3099a30222474f0d9418ee77d2b841ef29298b0250a6559142a5c01fcb2d81fa343f1282d4e8353959a894aabb434395f5d8 1 0 \\x000000010000000000800003aa749f43185a8fd7b6c74856768828834c32ad6133018a82f01e5743eee4fb4673a405dacc08363b62ea204c38347bf50088da8692a61807bf2e99592a61aa99ee00b0834c2d39d42a8b3f8e9751dc15f34709acf634f50f0571dee1efba951feb1e80be02390752094e2f763d14b276b9d22c92b3dd8535ca2ab8761eb6a853010001 \\x716e6bc561b72add58563e112a8f3852c4fb96d754ec5c98437df0c01d13e174622bf929babd8d1343197d3640e4e930c0ba48302c7684134ca3e66776759b0a 1671357367000000 1671962167000000 1735034167000000 1829642167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-337 \\x3863f645bc9fde3f9f9271fa535eb30352f67e700f0e22d7a4d551d3ba189ca48d20558dccb90d89edb2a0157f02a00b447d4da84e279189c21ef73de6a64c1d 1 0 \\x000000010000000000800003b82c57ea9fb0c21d9aeb95a772d8849c0be6ab62adcfb9079ff01d8143b8ef6e25eb66e0df4c436d3480088a968603a37779ff37a4745d48ba54212151267803a242515a5599b535ff4ea95003562ba127109f34983ff9283c409378fd8bd2814c58f4903fc71e4180c2542e0d1a4ca8c368e2d87d918986fc919ee5382e9277010001 \\x94fb53336275cf66257a909d572f472822680a716fdbf0f1e2d0373b01d1adfcf82ff4ecc8fbc38dc0810efecef97cffc9f3acf3276dd494358ef62924366701 1677402367000000 1678007167000000 1741079167000000 1835687167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-338 \\x380b50fe22f2c6529273055d6bb2f36557c535694f0953179835eb912b316a43d27af36b7e0424c38b917ac68ab627fc85c6836517f5f4c2fca996f9eb361703 1 0 \\x000000010000000000800003b8239d5355e96eddd42a7769d515374914445071958340eb54f6e32286a8e92f4dc724dcf3b61372e59f35e79aae977406e50a6025e8c5205ef3be6d70a5ef164df0094a8d366b643ebc40534972c6df313596ad7730eb33669ff390303400c4000b4386dcd0fe7199eb15deeb1be1ebf272c62a7f5ffdc3202ef5c797cc2371010001 \\xd2291c8510f3d3184a5bb2694db475b714f417cec898837fbe850411d0eca0486a19673b014c21a202237bd97f94ee697b54a1b049a6a76be7419d984229aa00 1667730367000000 1668335167000000 1731407167000000 1826015167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-339 \\x3963c54ddbfe57cf89869b7f0f19f7ccebb45d764428cf1b0f9fbf75fd5cc071252c9d30eabe663b6ad8048ca0666672608d5201712e3342a8def67e4f441591 1 0 \\x000000010000000000800003beddc4ed29bc3cdbc85d0ba6f69b964d2e7e2fcd5cfc6d9ad89a5dd8f3024f290b04185c5b81ad32d8509bc05266376c6ec51a7114096a7f8043a60cfe853f2086f9eacb3e29276b8721304b06f89362bd0f80101ce428fd316670b0deafcbfb535647efe5a423bc87b255573a4a4e459215e4905dff9c752bc3681d3e288f97010001 \\x6510366378ae9c3be1380c95b5347a8e2b0ae8fa8da887e5082578652193a5ed418a516c3315537a9b58f362a60fde266f54e6ef9b784b150ad81d8f464b210a 1675588867000000 1676193667000000 1739265667000000 1833873667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-340 \\x3b7304a323f38fcfe13f8c79f4ff80cfe4900acb6e109742d3a8cb120def75eff56b2b63de6f15a672b1dc3bd93fc6462d93a3cb28a871a87a50408e8095400a 1 0 \\x000000010000000000800003c0563721c3a4ed488f3e4c3704828e2651093878dcdc7dd940094680787b0c8ab74a7e27fdc0904f40d3a401e3ba86dc0f2a32662e6cdca02fa2937c1e2eb85c44ac16a3df4040488cffe860229d93445f1f372181cdeafaa6d52081d622ed06e8aa19372d8d5faff4d35931838db9d01f7b5165fc315dd0ac5ab1891ec9c92f010001 \\xe7a2b5742feff8b3983071ce522afc7efa581c2f2a347843902dcd6c8b6f6df149609d73977df87996faeec531b3da3938a0bed112e7b7528397083666f43e01 1685260867000000 1685865667000000 1748937667000000 1843545667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-341 \\x3ee763930ee9c8b43c5b0cd800a2922576d3fc5fd7b229567b76b007f9e0a3c3e06bbe48285798a557c92d37d7b4461f17513b88b7c865aa46cd3812ed8a4100 1 0 \\x000000010000000000800003be2b9a5dcb72693d118b3f268b6b374911f58c612e7850d8579ac65f5f31abb2e634a00ec942ac572bd647b2656cd1361f57e271209a5994706fbb04f3318495c0c2ba7945a17b0f308e35e27102ca08df238d6b88b9bb37bb74e98a3eace5fa2e8e436f07d7f8e2f832d1409584de26635d43697ce4a5ec97985b764705b747010001 \\xce7bc4139a31ca894a45a870d0a151decaa93d67ddba63eafbff69891b681796b1f3b7c2b9c5017e0f36c455f1172bf9129f56bb528c8a9991c9858937c10f01 1661080867000000 1661685667000000 1724757667000000 1819365667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-342 \\x418bce2ce7d199648982547f88c70a07b9da00eef11f857ffdfcc94612f639d7ff004fdb6c7c424a61f415cd54e46375b80c79a2a8d6c1538ce138be619a4f47 1 0 \\x000000010000000000800003e4cd3f84ec3ddd28a15233c017c7982a4be64e475f102e6bfd2a992d5bd514ec85b38ba62d998fce72a67678cc1ed8c5d435c55707ffd99920a9c985f3f5f8ceb1463aec7f007241f1f9a51a7da0b69e1d78e2d0645e329db6412378b733992ad62b15fdf0996f23b1909bc81080cf00d7854f63c76ca842668edeac3a9b10bb010001 \\x396a0f28384b60902dc1be5f820f14b3db29fd44ba59ac311e4a1a9eaf150efdeec7a6e77b5fe84db363e03e9a713a65475397fed37a0b95e241b09badc80c01 1680424867000000 1681029667000000 1744101667000000 1838709667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-343 \\x43eb42e53f0b0e7ea05ad5786ee86b14c8b962e94b5fd4747fb1433930eef03ff7f48dcc5185e72919fa5d1a6d22c446803b5f51e2abbe55008b1c98442978ba 1 0 \\x000000010000000000800003ac3be42ea0f3df72cce7357b8c7ce4a4bedbdd8e72a633b6d7316148aff226512e7e04b72f453f146066e0a2d8debbc0c40d00be8bc546d80e627043429f130cca6cd1e800bbe34d16696d33069809a45530ddfa90815673532a6fadc370d90064a6da0d9b361fa29721712b984a614c32c7f78659f7f4df5c7be8581ec6005d010001 \\xf67513d91c1c845b76aa171088f6bd527aa031c42d52f8de520c7c8be9a937c9683144184ef77c17a1f356747648bffeb916ccb87590bfb822df9f501060760b 1672566367000000 1673171167000000 1736243167000000 1830851167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-344 \\x486f129e828ff84339f63ca554ad0445194535900faa4729a6a439a3e1066ae36e701a944eaedf58cc8e2d4019262de72e4c0dd85e3460899e0bae4c5064f473 1 0 \\x000000010000000000800003e1c49e234389c689f6c0bcbdd97d4c95c4d7537617f4b1f857cf042a0c44cde25900b862bc526c904ec1bfc82537ee60eadc5f1dfa6b695496f1ba4d229d115ee91b55ed3c13f9a003a64d6b4bb2fcec2a3314aa3bc9abe399f1d732d2b71217e484236355be67628d62229d4af3bb91f50fe39c879ca35d046b02f07624e909010001 \\x66696ae80c9eff4254830f64b7f4430201a922705428d9beac417dd38c22bea5746aa0f99710d4d804a3f0eacaf3e446b91182fba22758bbf0ab1888c89c000a 1669543867000000 1670148667000000 1733220667000000 1827828667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-345 \\x49bfdde405ff26c27caabd9b6c020a6120470e42c1281757f898772596f210e8239af5bf0a214a3ca8769bd25dd7841b9ef0e208c2476512f815361c2a6e43fc 1 0 \\x000000010000000000800003ac6e675ba46be3ae460a2e2ff9475cd04e178bcdd8aea6cbe14fa5daf5f4947b2f9f924bdf59ec1bfb12c3524d776b38b6275710b68e96c99cf6a9fa4abb18815285004e38ac941a87dd41f9ca5300e6cc20e48cbb8e509cb440185ebba19ae5bcb19e2ce309e82201288d3c3a5e5d9578fd72b65064e883ac846191a93e71a1010001 \\xb419d3828a30961c87dafef97dc23afe35aa97560357b09e5f6eae63c56c013548fffddf3ef04dddb756303365ce4d39f6a5d903501705b70e98a48aff8b7006 1665916867000000 1666521667000000 1729593667000000 1824201667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-346 \\x4c6f300e174d9e3483d669e2a357c5f5e6346c819fa6bcf28c43934a2ed7ff9e5692b8e57e0c2d3f17aed19f5ae28a6f9e5dc934d4184c99bdeca298e9eb4436 1 0 \\x000000010000000000800003f4cb61be65927e72ab452a3dd70779b36275c24b603c6c04e20bd8fd2219642feea7e96fa51d788d57121c17bad947e9c98150071980c8bdc0d62c234c8f12ec495a22ab6a220f2130befbf98d628055d526b3632ec9564673d381c45e7cba0ad49929448d2788086ff4fbe3942789f526a68fc60b484ce76892e2f3632c2227010001 \\x6524715a9316cb15d8a44e5f75c36f41bab89f0b6575f80545224c572bd54b28defa77f3e5d46d3c891d702188fcfec6afc7c8f980dbfd8b830acc5121b12b01 1656244867000000 1656849667000000 1719921667000000 1814529667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-347 \\x4dbf9c92686fed2054248d9d46e93be1e8ad55b5291806a7e1fc314239e6dd0765c9fc39b703d67b136b20a0138782ddaf6909e19bf4e5623630171c0837d846 1 0 \\x000000010000000000800003b4764dcd5a9ef0d8763bb1384a8e806bd6fb28c2593392093eac51d8ade792f0ecfebc7422c5a993047f8cf51288c27fc39d551b0ef8bbbfaed7f3021b8d3b9372ba89bebb4cb3405df24fe4c74e8b4e2381e93458abd8e54a792dfb41f911db9d53e5f5029623e0c3f95a9858991398b815cc9a99c1d8b84d83c4112829642d010001 \\x729853c3ab37953bacdd222d6ad19a47c935a100209c9008e51cea20a212f6309255c520cd46c17abed9a0391f3b3345db8dae6122cd1f9aca3a2c7fa4ef0309 1667125867000000 1667730667000000 1730802667000000 1825410667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-348 \\x4f77e6a2da211a8fac4b83be699bf7a5aa811f9ff0c3640c717ee5f8455abe97a8542f0c9329b6403d1751d0f5aea90021d273ed7ce98d142974ec5536437826 1 0 \\x000000010000000000800003c4b01698c348b35540ad1f743c3b9761b1697c062a81e02ebcb6a70709324a432573fc8e4a5d19c1f910e0760e2434d306882ec0335e97dcda3f1052f5ec43adbd2ff5cae1bb0de6fa9f9a5d43808546598d224903c1b855b1a8b82fe10e7d8627b394bbbba8de80fdf11c43f94b963fca0654ad9ed5309dd2fac1935101c291010001 \\x6ed6dacf52a36f48c352dcd41bed17d19a368e3aa8f4fb29581837fd9365f49a8dbd6b8d06e74c0685b6d6daa90e61fb7a498ba6b7d1590b15874fb5ce503c0e 1659871867000000 1660476667000000 1723548667000000 1818156667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-349 \\x51e380bd43909efc49f521940d62d0a73355f1b046fbee44f91724ee9428bc741432641483767863ba2f9e6f8add46596291de3d9150eaec2c242c65f064438e 1 0 \\x000000010000000000800003c7e75fd79051de9ace014f45fa0302c487c63a35c2233870af522ad218cc52111f59fb60b63c29bfade7876882a567dfac74591e5df1cc6442a64c161610e0657d2a856bcfaa85db10c839d73885b77119612b996559dcf3aed2c6315c7af81b334d4968c8c421d9b635ad76afa1a5faf995611aa237aa8d5a55a5d21ede911f010001 \\x2b090efb5749d69f59ace51dc947de8ab6afc8c72714d9522c9837c2216503e60f1c54488725a3c5a3ec6ca7458d509ca9448c9b6c2b1db62fe55b9d265f760e 1684656367000000 1685261167000000 1748333167000000 1842941167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-350 \\x51d7bd38dfdb252ee86306da2bfb189c35b75a3ee7bfa892460d64abbe50e35dbb9073fff41464ad8bcd72a4188a7d0522c2ab162a277bead88854f259f3e945 1 0 \\x0000000100000000008000039ada1a14f448f82c49b31c796e8a8ba769d3e4a9603739e0067a0a945c81e44786d388f4fcd0365391f99c8c5e3da8828f2f423c189b6dc2c6b3bdf0a55aee4332195d4e4b97c3c6b920907597b0ce5f7642874e92a33f1e9f6e627efa88b57235b2373a2168389835099c9e8f62f4ab4c5874987e3ee94feaa5f1a841e593eb010001 \\x647eba0e0ce6183d33c717a0bc661290c49f58fbb9c97f4b3452400df4ef32d4a3c6930aff0ffa5aab5aeb2ec725bcf1ebf334beaeab92ddaeb5cd7a0c0ae90b 1664707867000000 1665312667000000 1728384667000000 1822992667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-351 \\x542f4df8728c336f9d2396aad50d16a0a0e76d215a308128d65027d514af0102e75e8ff3bf4dabedcb327b6d1bbda02e33f1fddd7bcaaa39d359e891333ae04b 1 0 \\x000000010000000000800003db23b153eeb679fba5687607bfd17a45cfda0e9f27cbb4f8cb77af94b8bd78f5c251b418163172a1ffb6db8cdad884ae3b6ee719361f81333d73a5a06e3623c96cb74c7bd2f16a21a1ea6206314a198e9515cf64ba4999eab77423fc0f89b4bb43d7d4db2014a60acc18642b0b4f0c47bc0d5c85ecb48ba94af70fa108c5ac71010001 \\x1986595841b9bb0a32075201acdadc37ac6847d713208abd7416d5d4c6d6c247bfb0ef807e3e104452a102166952ecc206062eb3e7eabcc70ffb861242b58b02 1673170867000000 1673775667000000 1736847667000000 1831455667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-352 \\x572ba76911a46a77476cddc48ed4bfded43fe36f8e87dcb23febfeab78d8ac76497579b9671a9b0578ac5c7d54b980a8838514a0ed08a7cc5f4a26bf94fb644e 1 0 \\x000000010000000000800003e08c5b1d26776c44b1afe7dcc92d8f0679537dbcf342a2f6b6ff8789bdd1f914d076a87f7dc66367de90e37cbc4fde28609c1ac6292767b50369c8eb70a99146fec492e724373834c797e7a5b75f49321ccfd5ece5e465b492f92ce338817f20d17137820eedbbaf37d12e9b08e62ca331c3201929efada004fc4da64c9ae555010001 \\x1ebb3ff29f944f0093c4c500033eebe933f1e04df114ec36d605dc7dc9f034880feaeb1ae036d905b5df0f60339959d48119fa248767f9748c50278061b82303 1675588867000000 1676193667000000 1739265667000000 1833873667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-353 \\x5ac7dd76faa7e75cf0c357cd354a173f70549dffc066e46a4e7a7e7637268167c88021982c3e16e821cbaf6e93d1c3487d5d44a83f925e16ad40060b4df021de 1 0 \\x000000010000000000800003e13de8b61337e76b36f469ec74d2e07a84dbb271346fc317a3d5d6467c84fbc5b78737f4cc9b9ad94a770d72d66054938033197a206d5b851822216da3749c67a5b4224135ea0735213ceb464bb0516ace20211ad0133c41aeaaff2495869c88b9d5a11175c41e6cd7944ce4420ff4b1719abacee7ee4d39e05a52e032f4b7f5010001 \\xfff23a0096151efd1d6c04fb14f574e0502973e04f4ecb882f159deedb32c5ab790e76bcb0863880681c7d405714833492a413d78e6a1626ce9adccf0c5fc20e 1678006867000000 1678611667000000 1741683667000000 1836291667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-354 \\x5fd7f262cc291f91703c99d6661762bec7fe030505fbfab96103c50285ffb454ad8b00c59e7907ab4ff34c188182b4a2b4e86ce1bf54d0a180bfe84619258eba 1 0 \\x00000001000000000080000398558f97491df6a6200697421fb17e6444c6f66f982c6f8eeb5bba221e8a88f289816fbe2c2cf712189f67d286f0e85d99e44eac8f1e16a94026a1ea53e1ca3dd5c759137f7e9f818c6c04f3e8ec1b4e8bad79b04c678ae441c45f59b267b580a9941ca24a5f7809eac9b5eec38ad2c0dc0084fc4d6f9d21ca3e8de8ded06469010001 \\xd51bbe2d6f75a1aee9ea35dbf051036b54c73fa67199f17470081ae5af392afa88ca862dfd7606371766b95999f21e58ca1faeac3a68874c8c0814959ecd6c0a 1664707867000000 1665312667000000 1728384667000000 1822992667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-355 \\x6043ec1fcdad91c3bdfd93c29a1135060dd6e980734ecea8ef4c6b215d830b95ab04722a2aecec3a1bdd3f0b5bc9046a34c80df30187a3c679d98373366cba7e 1 0 \\x000000010000000000800003d26af7460147e35a8831f5951351f2b87807a0f452c6ae34d3bde8f59c9cb60a87d7016da9d73d8bae66c9f25df05d480b70ed6f95a0b57f40714916246ebda943a2bade8b17eb9998dac35cfa682f6c1c50021a18ac52f02eeb8d60f68942577f0e70e4ce31d2181ec524dc1a71f38678d9af53c89a32a161b65dbfd5c35db7010001 \\xaa4b77ee2ffed2e21d7a7d0e9de1e8f8b4ececf88441608a3788cbe55888a9015abeb99d3660c149f6f47ffc7d66b8fc8b718561c4f4e7cf7b719cb124f9830f 1676797867000000 1677402667000000 1740474667000000 1835082667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-356 \\x63273fbac71a02bd498c6280d3f82f84ad3ce15d6224338946da117c8e3b1d187a4201f464d3b24c1865076eae48ebf1236109c3d486a1639dfb91ae1a6035ac 1 0 \\x000000010000000000800003afab87c89adaf24aac73ede6b5ce4a1ad501c7c6bb31ef1f4c86a4826247b8c89f872a851a76acd0afda0b6e0bb13a9d1e338ba95223e7f36a407eee4ceb32a0f9faa02e6234896be4a9764f0c0f46b915df725c2d8074d625e848d1dcc5f5ba422dba73f8171879f9170b9937fef93a6ae8dfab0ad12e3b3f6a3a8744236859010001 \\x8b64d0571b232c4de371150fbc6e7b5e8ab1f911cc121d0c8e29712eaa82b1b964b02982e5218c480bf76324ce0e851b2bf95264d0f8a5b70214bd8415e2e308 1671357367000000 1671962167000000 1735034167000000 1829642167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-357 \\x644f52fafdf23216a5bf31ff7cd3a8e829ef5a4c3276a3e5b8065fb078487868ff715ed510f4698af116def4e5331a59a0ca48e1aa957f835decec590b41c8dd 1 0 \\x000000010000000000800003acd67b1b92bbe82f5bf007eac59c72f06aab07aeab404161e0ba77309e12b48d664968ed97f922bc65905952dd994545d3f84e997e37af4844e494c32c61788f24e4bf9331e0e6d012cba0c446d9e6657c6980ae1f4eb8c2c8e6f511271424b837c2053a552920eb89477c232d8edd6187ae347e5b57d8c96caf289e5804df5d010001 \\xe95b8613f43518ad73306af9e983ba924bc6fe01ae70fd4444c8bd3700ac60ce51c132e40b7fc964fcec820a35ffffbc5f048821a239737419c60c1975dea703 1676193367000000 1676798167000000 1739870167000000 1834478167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-358 \\x6593ca0d849a73172492fa467b4e8e0276f4b3e69f4e4447fcc603ee02f90704dc8f8014ba6be1bd689013eac24c0de102c872b83b7695ba26e4bbfe642cd9a5 1 0 \\x000000010000000000800003e1707d6613a76c64a19701bedca491a0fa1e6720ba552cc36508fbc81976f41258fd7c23d587b284d5dee44400212e7450bd7d1d2207999557adea4229ec40f19bd4f2e515f73b941297a8589fdb64872634a90f5e23d053dc86487d691b14638a9688a32c12d549c8e65762a71371fe857d8b7f27772283923b0946836a79d3010001 \\x7cdbffb31f4672d3cdf18438dbd758b3b6036186678279031325ac1530f4082fa4e2693900bcc513c288ad2c5bd6af372729dc8bead189502b587f8188d2090e 1659871867000000 1660476667000000 1723548667000000 1818156667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-359 \\x66bb5d1fc483ff3e92dbaf772a937ec2ce22b0c476e20597a1242b3ee116ea22ebef63732dc700058dd6d62fb311e7627d18e5863d144bc40cbffb316cec313d 1 0 \\x000000010000000000800003e00045e3a1532dd951128d0a8056de7b283d8363eadeb3de127da894ae21dcc5e42651e9505a4f5bd1ab06fd2af7dd44999c986be6a6d244b81b432364181018a5e2e9b99fe98ed1f34ac607bc1a203579323578ddcaca097834295346bcc63562aedc7317776d17a0337ea5264bebaecaeb4a2b4e6bbfeb06c3e5ac91df4d5d010001 \\xd8104c9f3522f6f27ba4a4e28ca26eaeffd86b31e95e9cf6613f69b723dab6b960a688271ab16f041d5bc7f317b3efb8dfe2035dc96279d5802dc32b3ec22c06 1660476367000000 1661081167000000 1724153167000000 1818761167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-360 \\x6733119bd404ac21df863a68a10e61b02e1c75c892a7092eefcebb35b7a91517f1e4b813d3569d1a9cfbd0bbc9d38033a453ae9801790fbe897dd6fd074975ab 1 0 \\x000000010000000000800003c1a74bf8083be2d5cfabf805515824197d7e729ba5ee0a6d940685a2b1794456a59b69d3f71085506ea326a326a9d49a192947868c4c0ee6f24e05f347ccfb0a9b6cd843f36cf3b8ad913ba58fd443b895793310a1b920dc9216df887b9385cd1cf1b6df8bf709ac666f663b90713fbef169724257807e0670e7c01212410e81010001 \\xdb5572e33dcedfe1f2722c117e7def7718a3009f8b5964f931d55a87eb38715d0127a53c9a6d73a479c7c2a3570305ba0efe40dcba6775df828be6544b34e20d 1678611367000000 1679216167000000 1742288167000000 1836896167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-361 \\x68b7a8b4898eca178ebe5eb40a2b9ddcddc64539c2e69c3f44c3fdf15a3c1f221774703572f7f6c691fdc9bd336cd9d1a555f8149c1fd6cf217fc8bb61e798e0 1 0 \\x000000010000000000800003ce241f04c0ef401091abcae5333c0264229c68fe4147eed0b2b47e1e622a1dadfa4801d88035044e83e3a4d0be3de5582efd78bf43d4b02c01966a1a6934ebf94488e6ec11fb8fcea398a5c00826e27f294126a4da74c13f11e6044e785b10c00aaa8711627edf0466cceb2bc3f806328e6a42efaefb922a736810802c6fb2c3010001 \\xb7d52ab202e9933dcfe10d5ffef1d7ecd026823a5d1573d8f59ec6ad4bb5e6f3ba4be8442e52f9318673a3d5800b8e9089b2ea44ade2c5a1cf50c050b5ef4007 1668334867000000 1668939667000000 1732011667000000 1826619667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-362 \\x6a67a076dae0efa79bfa6dcc4ced2e09e8efc50a291516541776b4c9f35d068ba1a33e66938d699a6ed9e14f36db93feb1794a60a0a1a7ce538670b469e635cb 1 0 \\x000000010000000000800003bcd5227fe025c53e69326fa66e5e4f0bd603e48366b393159d13a399e0a9457a7f109effd4b21fd6a5c9b0d0d4bf5617af1a19a8e4bc3edbc76379cf160d16015830d17e4b6de4ecd1220ad261646072957280874391c74db941f8f1f205ef6263120398b2e0f68aa5d3c79fc720867d2a70ad66c99c0650e0d6cfbfb78478a9010001 \\x430be3687cea18659591c2aeab90e9fce464dfab6fc81c361376c56d5e104ba75acbeb241e6a71e9f999103b4da8bdf2e202c435ae217e971ea701f26a1a9509 1674984367000000 1675589167000000 1738661167000000 1833269167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-363 \\x706b61d80a25fa26ecd17c395a46603275fdbd28f624d01d3da51be15638261b27d81aeaffefe89868a788c0266071784d91fe1bd8995cfbbe8055a2e18c217f 1 0 \\x000000010000000000800003b63e53673a17be835d5736406f6a6c24cb0423605104b26fe6ff2fca20bf7793b061e77acb81417699321262c40d4553b4bf046d71ca60c31744c8482a334ef6a7dcd6facd3390b6017be2e29a5f3e283b64c91592b9b8bbb39b60513640a41c6bb2f9dd83fce5dec368ca87b0cd7085dd6b4dff758bf9df3dde97412fde158f010001 \\xed8b85b4d0f43fca98877ee15cddfe9193b07b169557d2efd58925136cb7400a65bfd958439d16826f24f59eb14629bcbf0cf1b71d3223166a52e7545fcd5b02 1681633867000000 1682238667000000 1745310667000000 1839918667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-364 \\x74633570808dcce601dfc026f6c49b3853a8220992e61d5f7ef2613a0ad229dc3c624d404260cdf9359224cff7e82d5bcae6f32a0efc8d915bdbb27291b264ae 1 0 \\x000000010000000000800003f80baa0b4d4d70ec83f5839ab3fcf5246f6e09bf1d368efef0485bce776d915a35efc6cbf034536272b61d269a09aa7271f1d0b2c5dcdf59a2e20c7fcafc4915882b23ebb2ec9ac8db37f9dedf5efb536053c5a4b2efa467f802fd5e6be29ab2ac9738850fd56ef56c7bfc3ae10eb6658e9f6a8bb7188c838ecbcb6299d80eb9010001 \\x0aaa58eab2ecb56e3eb92fd979dff80b5fc676a957d55f4020ab4ee6c687c5ce47d3c55bfb74af82ec39723a81ed83a6a78c8ca5b887e937c55404bf07dd4409 1686469867000000 1687074667000000 1750146667000000 1844754667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-365 \\x76dfdb0ea650c923cad20e4c198254a92db278b357c1678c1a32cda745acc884c89f238e448b1d166963c8c48df07fe2d22168a70afee09b0bd0cb7cc1341f90 1 0 \\x000000010000000000800003e45aed6cf05a725bdad3da0296b557f22bb9801a440ecadaf8792a1ca15be62a196aefdf303b89101b6ae039743701d64a40f0f69243af49a218ff34764c9c75dda8761d053fb54548ccb6dac7a90584c154cdff0ab07e16c95d9ad8302d916d8e4a1e791ad14fe832fb13f37cd6ecca44d6f77e2837240f9ce7b47a1592427f010001 \\xa15ca7e662a98018ffbddead9381a2822a85e64dda9d097b9a071dee1de56343c86f05df21fd8d62390b54820a9ad58d777e759eeb585004d90b02c3628e2405 1679215867000000 1679820667000000 1742892667000000 1837500667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-366 \\x77bbc6ce018058b39f6d487d35f8fcd6b722f510231daeccd4861ffcd8ca3ba86448c3cb762094b18bda66d7e83db3043537eb9611dd2df4e11df310d58c5775 1 0 \\x000000010000000000800003e5ab011164b8703be1ddf644264e27937a00fbda5b5b0df762696c832781f40a8936bc03ca84ac4cefb3258decb455b5655095ff928f512e2c08e1a5182648c3bd097918efe4d097ec3415b3d8fd1f7ff6d5c6109c7c41417b6308a0142fbd6629b83e3294eb48b4b96eab63090419df664c3ceb1cb4ad1ba84f431b04064b8f010001 \\x935cd9c134b6d7cdd967b657ba24e00c20737b33e33146780ba6d3759714806b0923bfa377b4d289d518bed53a1f290995f482057d26bbf99acf89370e980b0d 1656244867000000 1656849667000000 1719921667000000 1814529667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-367 \\x7b1bb80d963e4e00a6a202a8d84fc6891b63031f4e11ab212783fd00005beedcbb57b2364c56941aaeebc9d1032c1f68b66fe5d7408f25172d28a63f3b281b04 1 0 \\x000000010000000000800003be12483f3b3f8d5b0f7b01f2f3430bafd54e2555292a322a195318b2f35f7789cb41267382945fb495b742781eaf5dea2cc4a0499460f42936e905e16121557261a4d1b06a6a98ae26f9f9171dbe48f6a38b62b5718d5643bb76e5ed620d6d0c6d2594f2a36ed5e41a7879f4a7b9a60f01180ba84fd6c8e4fd36d6d8245060a7010001 \\x26ae2c21f414e2b5755ff447819822234229820878a47439142d4a5077a1ea484fdfa5bc6d84dffe6a68f3094a7c5f9609453d9f8d6b46c70cb802a0f6364a0e 1671357367000000 1671962167000000 1735034167000000 1829642167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-368 \\x7d8b9ebf9dc1f79fc6f94122ac51455c63d7e6a6c62b4d5fd84ffd3f5774976eddf38e68fcaf072144d7fb55d98dba5dcbf0d83f7e4b7f6f6f51724278db7f50 1 0 \\x000000010000000000800003dd8c3f6c00271cfc639895fc0bb2db147fb5525bf7435050122f0379682a8eabe29bed6c99027acf6b3b2e38e970c34c1b903f5cbafa45b8a068ad68eadec35d623bb439bfbdfb4a61376250bd862cd35dd64659015e7a3e03ded3eac3e962f0ac38aa6789358197980125156939c71c67a82d448b5f6fe99288fde4fbf3b441010001 \\x7f643255264ffc40cb801477c582132e31bf9dec07617f645443291a0940ca0a4fe5649d267e6a27a518e46035c87db340bdd2767304fb6322dc65bd63d8190a 1680424867000000 1681029667000000 1744101667000000 1838709667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-369 \\x7d83ce0b20668a0cf997d648276170c66e7fcc91c703417a715e5540c7cce0ab6970c5a1aa712dd55e850fbb545d29d00a62e95fd6ce22a8a064e4a34820c7b4 1 0 \\x0000000100000000008000039bfa292073414dbbd7765f930b30194b3fe1ae302414a03cc42e744cde00fe012181007bc59867613440c7870f64519c2374df04c1f17317699862d71ac56762a154d030842a0f4cbb2006da301565c7259556c97337a31ba78064c14b96d47a99d0fbbbfcc5328b4d401c0acd1f7323cebc1cf348c8614535601750934c3ab7010001 \\xfad06a03083c18a3e6cd2106356c10d7071ff48bcb47bbc11fdf24013353ca5a932d55b41d607011bbab9509c17dc827d45528353eba66299154057c38114509 1671961867000000 1672566667000000 1735638667000000 1830246667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-370 \\x8243c17053976197e28de12401a7ec603fb90184aebc5c2693addf00ba6155af659425346f2ea76a9d921642a5142dfdcaa970d4317b0d0c7f6db55bec5ee25d 1 0 \\x000000010000000000800003d074388ab7c0f3bda54eca898c16c78f9f948bc311ce5204e8bea203db277d9fcfb4900dbd0dc463568220164c1b0ad558609f050e79e5fe60bdef2ae9a23d342dc5943ac2b09697b9bb782e17b5f6218de8fabf9fe7fe50fafec4c3ec937a99c82219ce18ee4e555e7c3c27e012d55a19fb1c93fe241f9666fbae57239dc3e5010001 \\x1dcf504c12f3d0a1a94b63a1022316f2c59fb6c3277489f7bb0b698fd60453819fcd9d0494d7d4fad2444c80d427a81d90d9471758a61d9a3a3a858dfd7b2408 1662894367000000 1663499167000000 1726571167000000 1821179167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-371 \\x847f2cd203a6e6bf2aefc33a2dd6d043f0417ac6c50e11d60fdfef6e801663240b42a1490605e014f8ba39e4377af4f9ed055c08a5c101f5e346054338d6b531 1 0 \\x0000000100000000008000039b55ebca68460f6414fca7d42058825ef9880b40d6003ecb375b87845df529c15b281ed4f953d2c3f0b52a38f851cef5f1eda585aafe4112a23997f71c3ef086734d91aca98b2cbea39f57a8fc74965dd72210ecae8bc20619b4adba2055b420a8611d7477ce73a007d291ce63295ded4b95c5f32b9352450323493bbb978dbf010001 \\xb839e77a92f992dc6257ba8c4fd9c5963f69e856cc2d025e95cf6581b85b24a1accd25815e6583e2f45e62fa31ed3f5a3cda43ae7123fcd6e65ecb126e4fcd04 1681029367000000 1681634167000000 1744706167000000 1839314167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-372 \\x89ab30aa801fddee5cb039cc5810276fe7ad20e1b3b180aab1157166a17707eabef508961acead73330771a5c2914d96a1b2463613b5b761711169119970ec60 1 0 \\x000000010000000000800003a8976649848538add403d62e78760e1b5ad4537aab9468ed40838ac6256f4aebee5b9056a7cee0edaafced40073332d876e7902b92fa25390de8860ea9939e4832ecfb51d4853400590aaa25f49238376e84dbab25494646fe92767a206869e7274e55cbd988b939475916082762bf5825f300c47be36d2b09fa3ef44417606d010001 \\x104a10a342c5acdecdc61e5349961f3d2e3d16bdeba62413b6b3827db7c9c23b76087349ed8360c9785b6b3973dd65d45bdacabe3f438baa2bab6b7ac6f6cc07 1664707867000000 1665312667000000 1728384667000000 1822992667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-373 \\x8cab835b7dcaf3673ba670f9295b8420549ea0f11afab1e29cc161e8a3a5c19d814f93a55fce46f492ca4b591e57441b8c7a92dcbf1c7e1d970b60ee031a63ff 1 0 \\x000000010000000000800003a8e04160894e49967db536ebe8e0ba44d52cd5595494806e77653a5bac55613a3ee471513c88471b1dd442c6c5fda857b5394233a1a4fcec8ede00bd677520a96d43f1afc14923a456679022c10954a064b4bc14ae1edcc71222391821b5d7104ebd0c00858753fd14d852480109c9afc15e7014b442aaaeb5cd560be66e9ff3010001 \\x156bebb6f75785278dce2b4d7bc80239fd8f906e4f8c6f5bedea32c2fc463e29840c3343b2ec1e60530d9c00248fd078031affb4f6e622ea70011560ea2c700a 1665916867000000 1666521667000000 1729593667000000 1824201667000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-374 \\x8e7b779be56c3cf08742e6be6270d28714a8843d60269a67a99a2e6bbdb07bdbebdf6188eb66e53de5df79c7677cfd623c7015bd504125d4b48ea685dd32713d 1 0 \\x000000010000000000800003f76469bd128a360e9aecbb8bf0274d055688ece6a089eb0d9197c234a05c8b76d3b86bae3807ac1f8d2fd610cc9b434ddd58bbd606fd11389995e9b608e87dae9650cbafde22006b67e8cfce2d6c5e42956061a34e9343fb55b7179211b355ddd7ce9bcb83a552da36957ea0e833cff3036810a797991f72ecabcf1ecad9a9bb010001 \\xeece1848aae8e240a68f737a84bf20606eb881f1833584e5849c836385573d793bc9e060ea796a072fa12ee5f22c94df48036719dd0eb2886e0155c2a5899906 1655640367000000 1656245167000000 1719317167000000 1813925167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-375 \\x8ed75a55096c7c9acb667d4cdd0a3ef7768d749f719af7ac84f563828599ded400d54e8418568174e7b95e116f8b21e02aa3a8e6fb13232053277c9afc0a4f46 1 0 \\x000000010000000000800003b2e0465deaef3ff2c7c479a730c8e6ce489c199eff8544f5a79ad8dd7c3a5a6ddb8fb0fc3932342e099fb459d254459fe33e3933b5d59b3b69f198ec1af4d40a6eaae5bc318eba9516e93b10e5cba6d6082a15140733cc120972581737c948f8ee544a7c1ae817b3b5b07b319c42798fbd3c1b5a88caad3cc8a0748bc9ac400f010001 \\x0873ec5dcff0a76003627f4a3cc379104fc16b66b56463edfbf10689b032dee0ab55f8dabe711360367253692898aa62fe7de79cff455b37bbb34c9ce94d7800 1670752867000000 1671357667000000 1734429667000000 1829037667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-376 \\x8e7f77e41fda3deb6ec54a80dab954b50c21195d965bd8b6a90957616494b085143ba206f3d4aa127c7b312f1df381ae9ebe3e26f1d51a10c8ef7cc700462d2b 1 0 \\x000000010000000000800003c3d175870755fa89c486def7d36d4af7d2191dc1094941dd1b9d2874349e1332c13fc1023f10a756b6c418c0682b008d283663f7ff408ced2a33d72fc893fb8b2d2fd63fb8c5ef4a6a993e34874961668fdaf5e4c78ee4f50e7c316a416368982ec693109aeea57c9cce8d28969541ca7acacbdf2b9d7f225f2d35f210aa153d010001 \\xd63eb133013df6bae02d1e5c3d770f6d0da86426987f5e94fb752751c88e9cae109467b6dc5e031acc9f27aaf5bf15164361a53c3c87a53ce6ed65de5c695e00 1669543867000000 1670148667000000 1733220667000000 1827828667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-377 \\x91b7c199761865d418be39b96e81a2cdb79b0b74cc2a4ae2576bdc9de887c19b8f1ec100d1bfaa691d5e610ec92df9ece47380a3d0c33ac57718fbfea5c40b0d 1 0 \\x000000010000000000800003bb0ba34b665ae5392c4d9ff899b0dd7a1b1899a6bdcfe9d1b15c2a6c8a1f7f4355b96ddbfe4c7486b2bd38a13ce2fea06f920a77d5e36979aba1dd16aec107eea3e5b76ea6b425f426732d7ee493a4210d26d100d38ffbe639a81e2151b2ecbb011be3777cec2704d24504e86632a88495acb51d27bd8cc4ea498b7798395303010001 \\x742c2c895da071fe720291d1cb98809cbca77813f516c4cb7b4ff4d332e8d30c8696716dd7d4211be572c566d8b7e513089b09d96d144a34449120e3916c3002 1671357367000000 1671962167000000 1735034167000000 1829642167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-378 \\x92577d989e67747663f623c8dd87a03c6e227ef5aa905db83edc302caaf23957af3181e520ee44d99aa5cbc473d0ddd561855b49a2d2322675ef4b8def29c082 1 0 \\x000000010000000000800003aa9748e25e06f3ae565d0be091a5535f8859220976c0ee8d8daffd14ca5231e2b6003b7460d3d931e7452bec1b0af2f9c5c6be42c7662eea031524265b494c6a9c693faf970cac8973be3fae9b14363bf4c8b786d47981e3bcad6487ae57f73a58332d21b6e45ec047adad87fb003ed511e85cd775fa5d3d1108d1aa7c3972d9010001 \\xc499a573e9c79a25e0c17699e9065a49a0093446a126008127720d0aaa766bec6836617f98f3876273d0886d29e66bd9fb614f801b2f72b68bd79b37a5e7b201 1670148367000000 1670753167000000 1733825167000000 1828433167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-379 \\x937bcb99affe195e65e9b380c91d744fafd2ead790141ee33aabc611da344a566bfa584a42c0c71246f117d155f5b0fa88019b596d3ae8c624ce328d2b08dd22 1 0 \\x000000010000000000800003bad6c53688425f99301e1b4ad0ebe92cb562ded0dc009ebd38bd03aa59b2df5f327ada1b756e01c473af26614e5fbcf9ad030be9c673dbf424f794fe2312a61de1516a67af0ee9212e46d476c4bdf10bfbabbf1b4bb1149c49cbad650851e832303c2b8cc96c01dc0f8f07e4528e3b6cfe9e4d9718e692af78b4049052e37745010001 \\xf00c5c8f22fb1c6a3071ac2c8ef5a88ff96e22607aa0e1eaf58baf8ec6660a3c0b2401b967452fd82a6512afac9fa1c0e56225d92ccd9b646f99403070e56309 1662289867000000 1662894667000000 1725966667000000 1820574667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-380 \\x9b8b3c2a6ac857701eaae867e876a796897d9af48f82b02de5915b1e417c76dcf4ef845b1200e06eb066a5d0ad77a994704910a6a7e994db47165da90e523be8 1 0 \\x000000010000000000800003be2edde13e37ea17cf86f4651c5fb3d8030d5c32178850090cb7ad3023a580e96591f6320969f1d3c89fd82af2ddbd89590253737df88f01dc0d67e4061c9766ef5eab321d98eef88ef6dac327452b6a422e1ad78a2bb1bd59306d86942e3343124960e9bc7dc7536fc609afd3d3b4dade50fae0cca2f4dca84eb8724024cbed010001 \\x4b2ab68dd889a2fce15431a59981d29c63a17fcf394ae510d0a3204909d410cfe8ae61a65054bb7b63f354f0d63630fa35f0a34679e2bf190594ad5b5fb98e01 1677402367000000 1678007167000000 1741079167000000 1835687167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-381 \\x9bbb0bffef935bebdb8e3ba746437ed0d490e5c20f1f65c6702a6cfae77107c4c50790049c573a37982db98cc94fd14235d39255d8aeac87c6d7092740651d1a 1 0 \\x000000010000000000800003afd563d2cae6b5163b8f8961c5c398d13af4aba46db4eed064ee350eb0a1e3cc2ece69c057e756a3093092d4730f5230ab617da45917ec03e42e39989b05dffd985a0b086f1f9136afc3123222c5833dc8b42c09cb912a36309405664e700085baa6952dc42e30ac9a89dc5d2b744c10c8a2065db92d055208a60d890a7c4c5d010001 \\x7d8ca1bba00a21a14aa02e1944760fdfc33b2d645342815de6265e2a7a0ae8b5aff269edc7742dd73fe5115b9acb70f33c65410819282c10fff82d15ea9f080a 1670148367000000 1670753167000000 1733825167000000 1828433167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-382 \\x9c87d4ab0e090d79084465c2dae7a9bd9f3732460e423837c945bf9f5903bf094f32b599855172545b981543fbeedbf257f33f076003ecd36166808446a3e9c0 1 0 \\x000000010000000000800003aee343cb4449184498089795aa8bf0ed4e6000950808915982ed6570ed1cbeec8a3326bf8ba8e4230d90eb7796a42c5ec9fd4c5fccf0822ce5b55f4458cbd624d51e5529a4f27fc34f35d4615834d857750bf635c15a7e1b091f785bdcb5f6e2e94b5b8ad90813c376c880836ecd8e566ab1ebd82cc2623b8fe81814ea2d6d37010001 \\x212b6f96f86172b586c34171805018e372444fb4fcff16af085982f877cb55ce2510a8ffc8ec9c4575947f5b5fd2c4e3118cb97d435e602d389f1e3fc996e00f 1662289867000000 1662894667000000 1725966667000000 1820574667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-383 \\x9cafb1c708e624555da86b4e4ea612d2a75407478c547dc3dba5016503ba9b2bf8ba800635eb3f921eef659f031df21e8109b0292e35bef47e0805a04dce7a39 1 0 \\x000000010000000000800003bb3ae8c8ce1914d5b4aeffcbe4f1b2fd56b271bbb065062d70c2dffc8e4468d472074aeb82f69b0e00b4178debcb5326d9d22670914b3560540e35acaf11b9959c8b0395a78e9655a43d399866a57736c72cad26c7eeb7a155e15440f8aa242742a6fb4766092f99eb3988762e1fd1bf13c03939d7a63dd65a2c80b2bfc26247010001 \\x6f0416a630c2d37b77d40e5c44ce9f3b7112278887d964479b0c90ce64f9ec72e1634e863531e02051b581f2e3f93efc2c5e1f17a3e5dcda6cd4a3979e206a09 1667125867000000 1667730667000000 1730802667000000 1825410667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-384 \\x9d1378e72eb5c7acdc31d0e3bafc7a5851d1e6e14a79292d29712612765930061bad58edf4a5148ff329f2bb69a5570ad268a3ff355dd02a218d730ce4542c70 1 0 \\x000000010000000000800003cb5f83b94a08c2abfc974e1ece51a46dd6a118b217abd49038a528e447b82c07870ab6f4c19318f01704013b01fe3950ec6790c2aef2e2aaf55579104a91918e545831acd9cd7509a1d6f55ee08a30a1a674d2effda646e962bdbee925c1c2530b0539104567ffe9cfd629c382388e84b34f38f826d9c1599201358cf234b41d010001 \\x7875b250562050aeee31c4dc55758f1be081681d29da9d12e5ba8e152373b8ff97ebfb94b7f91005ee1430c28091e42aff11846d3341e8897f6ec53b47bb990e 1668334867000000 1668939667000000 1732011667000000 1826619667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-385 \\x9d536fc52cffec064636a96b7582318d72b10c1a0bc1282126c4f25597be31013735ba39ef9407a8fd1ed4ed1935aaecc94caf0600b6f800c42b263b997720b0 1 0 \\x000000010000000000800003f090acdf003627df1fd6bfdd6de9d586c3e8bf60492ccb4ad0c3dde4e50be03424380be8573a3af0ea7c1bcd3d9b890f76d7a8d9ae05bbe22d7c984bd0e8e0b0a7808df3ffa1b7110493631595c907310c354486c8d2de7fe0db5a231a057a3d062fd11fa013d7b01fcef48eda57515c1526a32f9f1c9a47fec7ec1096a62ce5010001 \\x0c71ad2747a5f40a282e6d58ed6d43526ce53f0e1745f014ac007ffeb3087d0eea9baa3606e971233cd445e23802c9967b285b2106301b8c10961c044377ad0a 1656849367000000 1657454167000000 1720526167000000 1815134167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-386 \\xa20351dbae8bca44a961469ff1ba5bb81c9636b0adf28e789a0b3a828e0ff50e508427d49716a232d245ba5b02c7e03043f11c80fa0bb8060bf5986fc8735e25 1 0 \\x000000010000000000800003d5f5f60ad5ea3c6f02fb170d15a8982e6d23dbe0b1ad2a39a04330e39c374a803b70b4fe12cc19f1ff9ca78bd2aad5612ae4cb8fcf6c3dd787d89543f134f96ad437c8e811afd0eddbec5151cfa7e35e779dae96d5b1023cff01ece4e41629b9702ddbeba8fcfc49d07903332124f3967948a681b3eb317f2cbfd2ec195af399010001 \\xe832fd55fb3d73471f3b1d350e1ed1cd893a5002b0dc705b2fcbd2431fdaaca5c5097e3cd5dd70f9becf33f9ecd21aac38314393c08bab9cbd183887d4989d0a 1659267367000000 1659872167000000 1722944167000000 1817552167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-387 \\xa257c31d53823ea176df815969bb374f7a4aba0ca71d4001cae94cf8b9b420121758efa6fffc198c11501212ba5a55bc922bfa62bd7b79478384813cd3e7fc46 1 0 \\x000000010000000000800003a12c635ac23b7b89e65ed4c3802fbf66759706f78e001eaaac57d365f8ca1a3496198552cf28c1a52bd5fab7417e725c1d7d8abae958dc41fdf6d978a2bb532cc4485fdde1e309904ffb972f0338ea7bf2b19db9817a8741a846e45579390a4617fa7967c661902177a39762a66ed7d415871b098414c384c0c47c308c31410f010001 \\x65c343978e4e1c232610395d7252257893876906edb44e56807614bb6d8d004a09b48204f05ca34e890d2a851dbf3ddd1ba84e8e08c11ac6e44182d38576c201 1658058367000000 1658663167000000 1721735167000000 1816343167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-388 \\xa47322eef0528da051141c8e8c91e81aa01c2484a0fa15e03a8b4ce4cd7386f776bd4766001d2f81f237a2ff67f37edbfef363f89e1a26047abfe808e7d1fecb 1 0 \\x000000010000000000800003aa02817ade3d1de2b70d1e5a666cc56e3e075b83ef2927dd4ca07cf86bf87619072d5cd2b8d972883b3a5b1b3f67f62d280f4ab2fb27858468fce285cf8e9eab9c8c7118cc7b372fcc17fe337871ec2e76b936bf45bbec163f093d0c20cc5ffe3523b2b51905af7229e169974e1344c79473f5e96d9b14513f76b0f36857206f010001 \\x64a59d9ab3a7e0a49d0dee15c7ede9445c5499667279982571246dd5f1711395ca28c41997dbc2ffc0c6c34f49b35d64e71639e03e502f4d8851b5d6082bb607 1670148367000000 1670753167000000 1733825167000000 1828433167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-389 \\xa47b70d9193696fbcb6247fb8c5e81ec144c9fc5036d639d9e62958986ce66091c8310ffc6a4a5865a3d13d0621bba21107d6000cca065433e60b25e6217e008 1 0 \\x000000010000000000800003e3b88ea9de32c90d0b5d873ee2e03b448ae926de41ab5a2c44f8a4ea154da72dbfd8f304d8c990908de4f5aa3ddba8677dbe5b4465056b2790316129de51c6bec092ae9d23d8b58391e97a61e33ca8d2dd9af31bb2e83bd8f021f67148339e7aa0ae78e3773f685cffa4787119fa01fdce9e3f769c0af73428d6aa0ce4ff7e5b010001 \\xad5f17baedfd66d0b66206355988359cff415bdf28198bed34e5bc0ba2cc5d802f722a53251015aee96dac93e20e01e019e6538791c66878086c73e6dc7a8a02 1664103367000000 1664708167000000 1727780167000000 1822388167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-390 \\xa737da7fd56e297bd3f4bc2d3667b3f4dd1ca5018ad1f373f0397dc3139b50f072dcaa58f3026524c7ba68638f7d9b5f84805848b8e01503a48cf289d6b4281c 1 0 \\x000000010000000000800003b3bc32eed5664f9659169c49108b96e7a15d49243426f3b768a7aa55cff96c278bf40fbe17cc64a31431c247459387811368e316a837b7a577568aab23533e048bd8af8ff20419c27231df5468d3cbd467eca988b057ba29abeb0646758c440e6e61dcadf935fe27e322ad5acb76f2e5574e9cffbdfc30aca981c2755d1c5173010001 \\x0d03d0774d6d64daa393505ecd639f7821bd03a1dbb0f8ca65c6bc6be74d345ad054a0556c081c6261bbfcd169a234567cb845e009e0f2a36df6bf677f94240e 1685260867000000 1685865667000000 1748937667000000 1843545667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-391 \\xadd3ef02c26be39077f0b258249be20b158ecac29942a4d954c103f443a00a58306c43453e4290b6cb01bba072979ba162daef7814c0962aacf26173f870775c 1 0 \\x000000010000000000800003d0517014312a33e69fca29c1e7a3749bbb58e452de123746d092a07fa97e8f515badd6dbdb60628d0a72f7dd1f93dcbf5b26445b9be0d0ba78fadef761fe8630ee23b2226a1aef9423a3dcfea8657fd647c203e11d19801aa16762b99bcd7a2f25a6ac17b12460cff1f9fe17600cbf5aeacb444c8f95d14e6bb7d7f13a581965010001 \\x1e2d1a6df1f0cfbe1871adaf280d3612053a3fa172567581cdb745e2ab00b5980ebfcf987804922aa56c3aec06a22d41486e1b13e215f0c610ed9844d5bbcb01 1668334867000000 1668939667000000 1732011667000000 1826619667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-392 \\xadcbe53bd75b3b0677852446c9f4736c856072211d683b902511cc0d201680026181f65c04564090d2557552b9fe57ce09a539306f5702d716f122683e471de3 1 0 \\x000000010000000000800003bb2121e8ce2e1e2d6db34fede439803b90b77575a5cd438f104a83409b35c2be9ea0aad89895752b8d97e9f1270d19733fd992b3b63fd9616510350c0ea623b8299ef6cfbeef8c19526080548a0dd1faccc39f7df070de1877247f639a82b1b67cef11aa54134c19cb8d1b91ef0936be8c2d60c9a312f1a1daa38f45c5963355010001 \\x8c0cd1518c2d7254108bc9026c8f341fee6983bcbb7917e4878773aa6bfff3351963dc204d1dbebca7169dca532f12a3769f4ca3cb995ecbf48bd45a7d019208 1671961867000000 1672566667000000 1735638667000000 1830246667000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-393 \\xb15b809375b1d54a944638d7e3ad7eaed7c28554f2d921f6c289086772a5c214f17197fbe0e2ba532ae36c11e1e93e9c5c519180f8a86455abb50487cd9704ed 1 0 \\x0000000100000000008000039e378e38508abfe48cc6f6a23b5120d5d55a68435e80e78cb5e65d6250df5a2ccd70a6bd4ff0f28289c0e4efcaee030464ecf75f99800094c7fac8ebba32cd9024617e567cdb6c1215dc239c1bbf0172f32c3ba4303044680141255fed99435d911007cb0047896a4d7c0477fc62e45ba17ba8b1b095f9ab1bff8041e99ca67f010001 \\xabd7532402e9f7a300ec90e54a4120839712606884b245364d8a2e7b0499bf23a739da0793864cfb4239dd9581502aa86b1548d2278098dbc3f09e0cdb9a6d0c 1675588867000000 1676193667000000 1739265667000000 1833873667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-394 \\xb5db326c3d9308093d208d6798a661c66ec7d3faa96b96f2c82c4c01aaeef02977da24b9907436b189b0197062bd4da6bb6948882f0976ed55a75c73318a0f9b 1 0 \\x000000010000000000800003d07aa5569a04d5e7c839790f6ca632179c04c771599751599ca9c270598f9af6d1fc07a105f140538775659c6048eca55232203e02996c220dd154bb7da7a16b6f167d2c2b6f05246182a7e0dd4fc5c310fd9cb9eaf5fa37c1b1698c365b463837744f0f2deb8f059c090631ce60d60ebdb0332f9d28bddee62c127f427605c1010001 \\xb3f2b2874f7cb15cdd458a6bd895323e101e0c8ad6f7ffd5602ef0eec2a78b6198f07cab752aba730086111da04bff8dcc3afc72de03780c93274554dcad1905 1668939367000000 1669544167000000 1732616167000000 1827224167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-395 \\xb8cf4831948935caecf0c4ef71332567d7edcbcd86808216be7d340af4d2dbd84f359d74fa464f1f0a357dc98489c87e5fbde7dbd395bc68b616dcd3926caeea 1 0 \\x000000010000000000800003c52c6a252eacabe661c13d0b6c8dd2cba0159b4624e499eb0274f73fab65c0e236272f62d6db68c7f662e7d0a8f4236d0318239bb5175f77b3bfe59c820f0a1512266d97438ff54e9ad49bda70718c8bbc19193d5711b5ca9d2f1c43c4786730fd71b09c663aa8de7e228f65e25a74e63e6147ac1624af9a2e519842295e70eb010001 \\x23babe15506fb2b3a5836fea7c4b13ca06e2e831d4ac5a55ad78bdb4e2e0f20fab1cf6e297b78eceb00db9eff541a7e4cb24e97b660631650196c1ebe280590a 1685865367000000 1686470167000000 1749542167000000 1844150167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-396 \\xb913bd7ac731555a7a0abaa0979ea5d554ad40b74df7cf3753fd022d1ba638c1670248605d4cddec15503d5b3002b18f3a24e4a714d928f77c4a0f71a9314d72 1 0 \\x000000010000000000800003d2984b453425ecb6fd30708b123c42eb85503a27e33824d9972b8e58d85ad926f4e0bc9cf69bc7b03918c38f4b63e3f31404902da18b1a2ee87ede3b92aa3d2e585fd57145dd946d835a4f8c5cf977bb7596f903a43b30c16d65db99541cdd7fb22fe60ad8d697763e3436198975801c738d6647776e7a7b272fe65952cddd7b010001 \\x5bb593655e93a0f9fe4f980f70da3ee8384bea026a988df511c3eeb369e1dce9b2b9ea595da278418118dfbb1b99fb653242ef32016419b10f277edb5e5c0303 1661080867000000 1661685667000000 1724757667000000 1819365667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-397 \\xb977bed35f27fc608001f191dae6a0c102c837cc446464cd400c9c050c4485d429d6db68f96d2860dd8c9025bf4883e91a35e142f8ed931893deaa4e9976e09e 1 0 \\x0000000100000000008000039903f4e1c678e22de49e59b14cf6760101823b295a6e97f5a1d50d3ac5f96895f861fd7f085ad44f6f62075c4061587685c9021ab45dd1f56b7b24a6de3bd0e738d9ffba6e894b2a3c2e8ea2594e025d53cbca2c18ad4da730a1ab31b75beef947833abc3a1acd0da2c74ef82b0356cb6a90026107259a15651f479f3aa5a9d3010001 \\xdf95e9c39a72374433abbf44756fe39d76b084e959eb7f063afeee5aee6a376920b2ffb8a5b97d6a749b3fc89871b7bde9c8995042f23a617aac25c05f586807 1657453867000000 1658058667000000 1721130667000000 1815738667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-398 \\xbcdb2963f3ae9c98da8f7808a38779f7d2b4ba7294243004699b6d7d52a5e776135ecb93248fc806ed5478adfd6bb2b365a9c12d3091b4529be3eda3542a6e95 1 0 \\x000000010000000000800003e5758fa99fc290f2c3f7be962e473dcd33cf61871259eb89bb252af3a1093ace4e448445b89af48ae33652bfab417796b12922f85a3d84615f8142517df17d63b19ea0096dbadd82393eb27d7e489c00f9e09f409213d3d4274bc88d64434165ae2ee7fc3b19d46c275da338b5fc341fcd86439bb15611aaffe88cc9946a1883010001 \\x7e442e1d2f2eae7bb1a631c2576220116d84cd855ca58d3253a70a1831164f286382beea524674cbf093f87d8b42cfd764d22614f1bb1f397fc9e6402b62c40f 1678611367000000 1679216167000000 1742288167000000 1836896167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-399 \\xbd773ae9b93b9af398ef5f9f8be9c178af0d9d5ec370b5cf239f4d8af7d386b07a80680eb38135922d00810d81c715bc0c31012a4c1ff653884d1d2b96d09811 1 0 \\x000000010000000000800003da9fbe55d1c09571dfef430e3c265f252e8a3155ffcca158aa574e077317eba6cfff93cf7d6478441e7aae3e44f9e5bb360c3434a1c116a2f4566eaa241625028fb4ec27cb1d9d44df78266795926d08621729cd92739fc7183f9a49c8ad1eb81f25fedaa6c4e5931de23fb9b12217b71296d45ed8fca0697b5d1cda0d08174d010001 \\xed9819c15460714bd02155a03ce841722fe3648c5c25ce48f082ab99d5e4939dfc21e1db1e44bf367e50debcb510d96f7dbda6afca8281308bffde1addeb0202 1679820367000000 1680425167000000 1743497167000000 1838105167000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-400 \\xbe23ed58927510d0c7027f07b8db48902d49af72f0eed714a5a2da6c259357aa5c0333adf9d4a1fb7399b4136365cd1d0da3d410c93ea574da2e8c8d89df80f4 1 0 \\x000000010000000000800003b97bc0f4bb6d447d1fda63d42bf5c9e9918a7343ba1332526fb35393fb65086a1270f7fd5e75e8b3cf3e0cff787c175cbc66f5f071a1d0229496de76cad45643fad78c2284f8786361b8df217a9186d25caa8227476ad5ea7ecdc4428e9e9235e13f72ead5f0d4b5c658b67597c6576a493b9988eb4c35c9a1ad1d2dfeae765b010001 \\x95860f05a6efa112c9b483edbe672bbb6375dd0e836e56f26ea530db1abd3e7aa7da3861a9a55adcd7b9e06a52787cf6e33c8af0b91a47f7938995f2ac56a203 1674984367000000 1675589167000000 1738661167000000 1833269167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-401 \\xbe2354a0dffcf04dd6f841ec617025aba285ca38a9842c302f95db876d94fafad088f04d05e0e741ecbdb809ef5b703627c8f2c2c0ad5d2c26f1d65d957c9439 1 0 \\x000000010000000000800003ac26a4746b5e593812d9d8e29e5c5dbee49ec970f6d568b05d947c8874da0f878661483f21190658e6405a33234b1ffa5790d611b22c86130e8f52c27825c650e85df5c5f7a47e270c7595334e958ab70c736425eaf88879ac4b6588d7463e6a47f32d40b3b3bf68c253ed41b2abbaa6b3929616c7639803a93f16301973a84f010001 \\x1fe55188af1d8877c9a486a0da6970ee91151e1e7f3bb38eaff36050f04dc4d8e0b2e20e8d9cbd88b8637921fda34d8d0f6ced2b29ead1e9a5f045ce81a2ef01 1668939367000000 1669544167000000 1732616167000000 1827224167000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-402 \\xbe3319cdaac15081dbac82f63721d626abd4abd505b1f10256408eeab3a9e6bfb9d0e0f2dc518672a0620157b6b2158812f9d159b422c82284bf0a916e14209f 1 0 \\x000000010000000000800003b68ec69e677e0fe061caee84b5fab2b93d3e557ebe81e64fb66d8cfc68d44611dee76d8fc414d7e23a27f44882c40cf88dace4491fcd89c6585d8707f35ebf6d27d3fce9dcb976f2f48bd7a7a56426704d82589068864859cc7942ebcd7c138aa0911ae7ff25ad406a9d025f7ec7cebb93f34ec5902793c7f3c571f6cbd1beff010001 \\x62db941675a8c1bbccdcc0972b568336059a9d2c0afa27fcae30bef777afeaf5258df626c5ba9b63330e72678843caf826d64a56717de82103a035104f9fe60d 1673775367000000 1674380167000000 1737452167000000 1832060167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-403 \\xbe0b989b852c85b797c2a6590c07d5aff1cb30802daa6669a0c7bf2d19755a08c4532926671c4a4621f5e0b9c644b6918f6bffde8fb00de02d5594e3013d8ddb 1 0 \\x0000000100000000008000039f7c05b05ce3458088c1b96b181e25ecac6898e99278796c9bd32dbc377df808940668924e6f79dec87cf3dab0bbbee75bafe3ef6e63f960ccfe7731f61ce8b06bc22875db93842fcce1eb127c81ecdaf1655917b9fd8d811288ba953e816308e22a58127a7ccb87d16b2e3cb51bfadd11a76703431549fb98ca2c900cc11391010001 \\x398f4f203b5bb163a2b5c4993de2816a32d725e7833ba48cd423a2575d446da11336c9d0611cff43890d0472ad59c7a6d7309f235c71791f2108dc700aa3570d 1656244867000000 1656849667000000 1719921667000000 1814529667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-404 \\xbe7f08b4c3d06f5368091bfafe308f2143bda23dced9ec2b885b0d8402ad83aca4fc0397d6abbb01f94e85231e7e9e1ce0a8e6d352fae89088207e81b76986c2 1 0 \\x000000010000000000800003d238cdfd772823a4790a34cf55bc5c9badf9f4b838a2b2bb4647cd57a18f3baa037ba85c095d5ecc465020a48a6e63671994835a9cf5340e587cef2ad7e4ca82e6d7bb2942c14ba000082eef1987b820b79e8b5cad9b9504d424125fdabb909f3fc89f257bd93a3b6205f887e6c0e75fa28c64da413f6bf60508e25b72681f7b010001 \\x60cf66d6c303a22272b4ad2a01ba87890b95e1b2c85ed46f1ae48441b2e12530548d8b501d6677f6f25ee5d2e3fdbda0e033e2d504510be2659af961e75df700 1669543867000000 1670148667000000 1733220667000000 1827828667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-405 \\xc183bd303f2baa209a584113ffc84b8ff55e712a36f01147615c45f3d87e414cf22bc13bbec3cc0c960b125605bc476df1ad16c00340b8e1d8577dd8a541cb00 1 0 \\x000000010000000000800003d2700251b34bb94de6efca3fdfe518ee1e5b42393f8efb550a61fd8d4e0d63203c1b421d7aef57e04cdecee4a11b9bb190989d468fb719be5da90d152226c56acd8eafe177599f4c3c5ec6614833aa89b76874237e4dd844378068fd479b4c35930103eb8f7b6f64f43ec655aacd3995867b87e3e02d2d9b5a29d902e12ca103010001 \\x018210bcfaf08c6679531a650d80989b54bf0d754dc22bd9397cf478f7528db3088b249e3c557463b72eaacdae08287102be05d414b07702c70d7c6144302e02 1659267367000000 1659872167000000 1722944167000000 1817552167000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-406 \\xc2bfefdf1d9ed332b5bbaad0af8aebd94520eb44f831a3fedb920f4fea2ba202409a25c54cc04950d67ca88786a8bb20545dada74495a02407b9f0834d585dc5 1 0 \\x000000010000000000800003b7b05f599f6656180862301861d87e9767a88f3855b978c7f236b837300ba42084f6b058dff42fa18e9be84a3c09f3d560e9aa61a57b6a713d3d082506e9141a6a09d4fa478704b403e3f0530e090cf6525473d747195be5015f65e9fddbb6d7e9cceed0a031ed131e81f444365cc2edc344e31562ee4b4db3ea07f5c9fef64b010001 \\xdff6b91c79f674f703e6b0c8f0427098d90bb70c147f4f726e467e72137ac0cd6a7b5ad33e78be2fc6877e2d1caa4c97c37e7a7cb21acfcc13c639c6250c7f05 1661080867000000 1661685667000000 1724757667000000 1819365667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-407 \\xc317c5902947abebfefb7d23fba8f1b321c794c1e3da741bde84c50cb579c7e98cc0ef62dfb62a8d72a23dbdd2f9f3dfe61b1b11e06de87e97c25a82e500c64e 1 0 \\x000000010000000000800003e1d470d215a16d65e24d3177a00ae71a70504d0273390895bdb8371450a68128d30bb20006f8deaf5f6df670defae577fa16dabeb8555b1ce0bac368e8df8cfde2e8df77a4c3dd61d00aa5c33bd202f9c5a8ddfd34496f27f4ba52a0e6337f55f7d806f962b2e3a699f0720066f3cc72f250c6b724bebab3a4bda693c2d5d73b010001 \\x8f311c4dd1ba4701ddb1773a4e019e5a1ff1619d688f48a40bbb9a4752671fd2be358aa442aa9213881d6c7bf8b424e36fa49a8eb4db5bd30bd8f74bb9458f06 1672566367000000 1673171167000000 1736243167000000 1830851167000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-408 \\xcca3d387e99b7e812563a1bf5b267c660a5d4d57f26b8e0590a9560d4feb64b9b299c28937dc6775dacfe2af6556ee4058e065b3de66786dda82b037861fa332 1 0 \\x000000010000000000800003a7d2294fa8ff7d0303efc536f67f5efdb119382efeb927d39f3cc69cd34bf42b4587a679cbdfb090481069c30453435ef05e904f918722d9f538110278d555ffe057391eeae6d93e127be35ea30945ba23e5e93d60ca0f1678ec0869212dad09d2865c223906409c54b6fc5b91f6e0a4996f4751f85156b84ee76021c1b96a25010001 \\x87a20423bd9611437a4e086de1c916ea1e9403e2a47be1f2c3406aea14f5b1dddfc5f9d357cfa1433a014ba4138ef6fe5878cf79b6fb33c5700818d08df6e104 1661685367000000 1662290167000000 1725362167000000 1819970167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-409 \\xce072cf7406ec5acf124ea5600927cce7f9d41d22a039a70355d20e7083a44f43d875385f131e92e460ebc7d655f3666b8b1342c7c75b90a8b21b55ff878e942 1 0 \\x000000010000000000800003b3255fd09ba0fcac41cd6fcc842b359fbc07e7fdf00a04aa76dab415dfcf857a774111f0c5c772fac5b49992e60cf58d411df979ad2b00171082b254222bab7e56832bc382d10bc9f5932064157fb516ab837538d01ab95fad6b9697057e9973670d9e8a691e3513507180b5e4bb6cac29a2ac239695df479592e8bd5a958bcb010001 \\xe6f8dfe6ce8632612a03b9099b6e12082ecb37d6a1f1bb6510a5d298e8b78493c24e65348067c04bda53a124e8a5a48f19cead7e161b24b657e4fafd27285509 1659871867000000 1660476667000000 1723548667000000 1818156667000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-410 \\xcf2b0ecdb97d4a5bc963e58d54128be4678500c8a5361b4706da1c074709429f7878e1772c6540d5d4839111650f48a333ec7b599afd2e937949e3036e29c046 1 0 \\x000000010000000000800003c04e6354bad8fb201dd96e1d1f3870af2ff603ee6ffd6710ea60a9e8098e10a73e4cffe9711fbbd216a6823606a555531ca4fa29b9929d9ee0e3849d3b4d8bf37fdefd1aaa11338ef236e3d8c889848e851d001b0d34090e37c24af9953306a4065dbe2359e555ea3932f10362109b42141dc16d21f732ba1b2a827c65e3ac77010001 \\xb2ad3f53e7b8c1a55d7c0f12830717bea141549a673615f2c7beca87bcef1b0043b0c55cbd5bb211b51d7a378a0296512a41561729013be5be5073b235ee7b07 1664103367000000 1664708167000000 1727780167000000 1822388167000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-411 \\xd0db3601b517ba46fffd7992851e0b7fb699a9bee6deb5cda4c258764191da419462cbd3d76f37d7fd9d5a984099f43c3ec01dfa15f4a6c90da7f7353f518652 1 0 \\x000000010000000000800003ac73ce483cfe186521b0e81fad9637ec26b051f2d725e0c81eb995ddbd51953462343640ad7c8ba8ea5eb7be3f12b43858e1bbfc4a9046bb927a24a0b345c02dd0a833284198756790d652e28deb7531f1210c04de5752a325df84c8dd6e71f5742876679c90d83c4fb6a3405f84fcd271a899a21d326cf1ae7a64a8d3cee62f010001 \\x7eb5c4d9c9dd2e9f7f464b629f434ff294316602a04c8767721d17056b10287f282dce1b4057356b6edb8d136cd206b4ff0ecef80269c200013e342cff1bc204 1658662867000000 1659267667000000 1722339667000000 1816947667000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-412 \\xd37309d7b30a5f6e50a6b7eb6dc13d147a5e84a75b4f1c3d082ba4170af8eac7ff1da3cc242ed19ed553510a42208f79684f2802187e67ae87b218564575d705 1 0 \\x000000010000000000800003b8069f76f1a1e2611f37352f07676a8bed96fb2421cf391bb5f94d9b092429cc80468898344fec9ef37f5de4d0a627052e0459e6761a9c6ddc6a2fbae77c665f5910ff68485f832772bf2eac9c8ca763ed6a29ebae05151957967b4764cde5b5a3c18ccd83b7024029c94000702dbc5dc78d80fbb42ae0705fca0aa0d6ae470b010001 \\x70ce974c09a48855ce0af23dec178aa7dea6bcbf28b553e4eb4e1695865ac69487d667d8fc916fcbd659cd6329059397eb86030042ca9f627e33038c71a6ab04 1663498867000000 1664103667000000 1727175667000000 1821783667000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-413 \\xd943fd5139d37c77a142d16cd8b6edf7068502e30b044b8a43fddee786f61a771f2632aa28d4c89581f1405b5eb01f7af56c649e3e847c44eb1a5ef8617c8dc2 1 0 \\x000000010000000000800003d99e99d70f639b0e3b38ad0799762d3bcfc1467fd62ce84599dd9910837e19997126740319503fa44d634bff97078092e1597f6d7ef0859e4384c4a4c2059f270ca797a4cb68ee3f9bf6f2dde66696733233eb8b3485044e6be2e48859fc55aa34a38baf65065befc7e893e89e8dc1e7be5833a9921f72b7ce14742b6b61a5a7010001 \\x86070cb381d5e3e67fdb19516d31948b05b5dac6251a674ac490274a7679c9c9761a86c4b996d8f67802cbaf60cc5e342c0c50fc35c66c84d02391b42a343c00 1681633867000000 1682238667000000 1745310667000000 1839918667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-414 \\xda035a1d1d057bdf74f79e70f8f9114274cc6dfee7d63e82d9a8d8aafba29bac843ff1b5c9ebb016be774546d2943fde12919a20bbcb84307f5de61188246b87 1 0 \\x000000010000000000800003b54a2f9048ab9cd027cc5414a64258d27b08a71e63a125f101f3bbdfd4639e05d55877c255e2634ea99b6ab1794b1a1d43119cecec2c1b53209b3b84240c89f7191761703808415ab45a172b9b926b1076e33d6381a01ff89d322171bc2538b4a2a9954114b6fc72b88b4847067c4aed4e22cd9615dba911ffcc39fea1065b99010001 \\x2b1816fb3c546f4863b4e0c1f4348ddf446bf3d743f991b58eb9882b04af9f691572c91de374956e52379f5c67b1c9b6dd53844ca7494434fe11d779516f8602 1671961867000000 1672566667000000 1735638667000000 1830246667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-415 \\xdcd7443dfe31d217a69c1b6789112e9347db23770597ea9d8a72a24ba186da53b3a9c8b36aff616dbf6f6b77cc85210e66fcbb9a5c28733dde8b2ef9e32e8f5d 1 0 \\x000000010000000000800003c91c7d365e4016b606f05456160a9f99c3817418a12e4efa8b7782d2fff3cb590ac7368778fbe5714e128dd0d425b3581aaf612712fd9ce8ca4edaea495bb2d988f95bd681aa25386a69d314b58957301cf7f6fcd9e0328c3b4c146788b843b339306dd097abf01ac98fb87900c6ee3419347214b3d4de1b944dade5be63ea19010001 \\x37a52fe29f411167d984c4b345188a01ab55deed44ce2d624294c0e2e0bc93940164b29430999f7362dc7bc1f2aeab46d21d74354dcdde3eaeb304f0a66dff0d 1656244867000000 1656849667000000 1719921667000000 1814529667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-416 \\xdcdb6e2c631822f1b077ae0374259a3be3397df645f4af1c89fa789015f138d3c14dc9189c6f4ead54ae5e4571fbd2774f045afe5f77f8e0061886c6773200de 1 0 \\x000000010000000000800003c52cbd85b28a23f20731b618c8808e28b6dd6cd680410df18ecf2163ead23ae4ae20652a2e75122db3570565fc8b40370fdea40edf4e9dc51b79eb633ccdcb5ed626b846b8357a2c217ae52b2046d6565104e2a190b5b2311e25af888d7e24e0cb1e177f0f789fd840ac9361fdb6d3fe80622752381b66582ce16f46046a4215010001 \\x1064e9a2bc056043db5e636929b69f26726c69d79b7fdcd9ccc3546f31b1876ce26e62f5d8a852768e1116ec5d330862546223d64fec9f2ee898beadfca4770a 1668334867000000 1668939667000000 1732011667000000 1826619667000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-417 \\xde0b75cf7dc1e737adf985979bf7483fb7b963bf34678c1b98e780f9ee6c38ef7131f0caaa994bacd0bf0b1af6b61450c39c0d81994846fb83624227a845cb4b 1 0 \\x000000010000000000800003d2167a137975701120a6dd3701b9a3e4c3f35d5262f276fe7f12b45efdb27a2da05107107831bd3dd0a9d49968d7a7a61da0821a2a84f2865563cde252e1f97288a24862946cb403ba4cefb59623a32d68a45bef7a99253f5c0ca1236adaa5f81d525931b380b0a647b6fef0df80f5c23c3b93f59820f9e6ad85f71dc713a709010001 \\x0bea4a4627c0309c5e2ca5cbe964985e2b76385d2cb267304cf64f8c835a9d2622d58185753c81c8a45c7266ba9e8e385abd6fbb6bb6277a6c2b09818fc2b50a 1662894367000000 1663499167000000 1726571167000000 1821179167000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-418 \\xe707c3d0376d6de24d990c31c1ba1f722b09a02db337ef6c2477b9f2cf5fb2daf3048f476b2b94cc2e1359fad4cfbd5571a6f17ee12fe735adb26d4a760ddc3b 1 0 \\x000000010000000000800003d956848e6c6035037abe9648098b0d766e07d7d8410f99787189cdd074f623e9cc31830b938a0518302c1bfeeca0601724b7f71ef15b6adad3dfdd40589cc8ef33ce358488a1d10485ccd4d2cf257a412377a25a47ae9ed1724bcf51be8ed5034469dc7eaf0db72ca49f142ab63bd651f7a6e279e14213046edc28fbd64824b3010001 \\xcb00898cd59de1c342efe2685137e72f9e9ffcff10598238378eed0f467a4205847c2649b9555c52903470de1511a1cbfcd0f97dec4418657dd63ab0a40b9502 1667125867000000 1667730667000000 1730802667000000 1825410667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-419 \\xe74fb1223159b4ae12727d792baa63ad7c127609299d83f0e4772735748398197ab25b08c0a04d445ba7ad8fc65027179fd26a065f1851d8785546ba4fe78fa8 1 0 \\x000000010000000000800003c3e5425bf5727ff3bd480a7df4f4587bfcc0e6060009a17c9b3c61c6d6187a2a37901689dcf0a7544b2a71b3573f7eb7eabe5e45a4fd5bf2194af376bc9c15087c6d471262539c4c3b8817dac9e0af05a087ca666fd3ca2b33349a0784b96a78b76a13a1c14befbc0a2923fa87ec40f9be63b0bbb454616a4982b37a8c6559a7010001 \\x70631c07038ad3c9057d187c111762be08643eedf3e270190d9909c23532a6b4479d090844709e4870380426c98ca844ae49b5a8c4d69c76420e24c5cd1e0f02 1685865367000000 1686470167000000 1749542167000000 1844150167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-420 \\xed1b3762433c79a7aa13cd17a929e5b006c3bd2ebdab3ef5acd5fd9cf7c1cd5a8bbba9b94c94411c3900d2c651988e27a6eb85a1e4c3c47bb724b3585341d7f8 1 0 \\x000000010000000000800003be49e41b4eab8cc4ac6c0a2e26ff080f126db7affa9720c2dca1bc9e544f7b73fb826d41fab5e6aa3f1e20737dc526235d525cee7657ac13d5f32bd3ce6150ec5df14be7fd96f497a0a3cadb91831e6df9758f07d6c35c28a68b442f0267e906dddc92d0a91cfab93908b9cdd544035a958eb1ebca789724657e7137fd47b441010001 \\x4e9e83e3547b3ae816c236ce3c92d365811117b808002ed7c0f9d7209df3344ed1f0e644ef551d67139f44ff2ec95ca26b409f9d1904c1fa7f94fa57b43edf08 1679820367000000 1680425167000000 1743497167000000 1838105167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-421 \\xf29767fd862bb2e37297781c502409136dc9ad1405fb1fea2f734c11865cacb80ce57e00e6aaf4d8c5a02060c9ed61560ecb967f3e505208e4e33b7112f48cb3 1 0 \\x000000010000000000800003b23e24c0b178d26898e408cd98102e0aaed01d38bf99910ab91ca969f1e258ef2337f600855b1f4f76db852a00d17983d4b8e6b5c03a90ddebc248db8a4486db5a80a064f770d7153379cc990b8326a21c55f28096f34a1287255dec52ef941fcb42223d8bbb8a26b03b01130a4d532faae4a4052589ec6175fb1a6428e27d6f010001 \\xd65201eee2396708fc0664096149f522be2d2600c712965e8535d03905a782ebe8f09dbe2a24585b4bd28e210b5b1c505486b5063cec1f776d20e907f1e40b02 1673170867000000 1673775667000000 1736847667000000 1831455667000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-422 \\xf2871acad8a43f8a5a2546a29da3cc831c70684249336698beaa91383495e8a0fe8206012e1b0a65bae3348404dddfbc99d283db263806fa6cffea5d9af05195 1 0 \\x000000010000000000800003b569c48e2d1b5a1a8b181ae0edacf0cdcb1f4aad645f74dea072c6d8b79a8a3aabecfc3e41d40dab19385019e3eda19a5ec6f1b33ab39c55529a2eab5a68e59678f37a8cde792aa6e8ed24756694966ac7e0806284cd67bc383d778d962555293c32dfd43eebb0faa7cc0fe53a14a7b2dd809012868703a95b095ac072cdc11d010001 \\x623c17bdf6e76f6f3b7559280274cd5acfe89e0b7699a1e4919321c6d72e71ee78624cea830948ca14b4f4424bbfba044c062646cb42535617de206e0c439109 1662894367000000 1663499167000000 1726571167000000 1821179167000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-423 \\xf447389383dbe1edc4dbf5589123b8fef8bab2f68dc6efcff065f802cb0e50b7bc39c7c5eb9a05f4047b7b6dc704dd0b75258af4d80fd280748d3a70cdef44e2 1 0 \\x000000010000000000800003bdd9693cf038be25d1877a194ef6cbaefa20c42a2ba39588057b781345549d4bba1e76811a9beee132afc7cee0837f9da5a6e712a4afc2695c82551396b872b4f8049ccd41fa8bb5356e5c4b0e4e2db0a3e34f75db5f7ea1f926154a0d143216be884b4a6afcd9101a7ab16fbec28bd16f722ac456cd3facfdb276924c29329f010001 \\x9ae2b19e01cb1d936ee4b1a4b858f883d4e73d5b918b66407a33603f68415ea7069f9aee96c0cac1b24e5e1218acaef2272dde99069b0080e646823b83851204 1655640367000000 1656245167000000 1719317167000000 1813925167000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-424 \\xf5d3e14ec6dcb2f5b672793683b97fbb539b15dc99c104add50b351c214d2dc79dc4e58fe4b16e4f7b995b537950bf39ff998fde4a1547af4ebe259e16e858f5 1 0 \\x000000010000000000800003b7cf51684d8cf161fb2fd8747568aa67c0b48c6dab935b4dd46959c7bb441a96d45fc8b65557c3a64c0b3ccf2f77e9a3d536de015eb3d1b2508a486ab6a3e0b0946826a9545b7cc09c1391a389d4ba4671185054b568b7ed8eec452e600ff0c534f07617d45ab181d47a1841e61a784fc8dba683de12eca6d94617b9e378f13d010001 \\x675a8622fc674349f59e86b01e23a72fdf57a3f25559a424e6145ca74380290a4086ed578405faf21a0e688d76e5f1bf68e5ea9fb1ae292149b60fe1c318b40f 1662289867000000 1662894667000000 1725966667000000 1820574667000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-\.
-
-
---
--- Data for Name: deposit_confirmations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposit_confirmations (master_pub, serial_id, h_contract_terms, h_extensions, h_wire, exchange_timestamp, refund_deadline, wire_deadline, amount_without_fee_val, amount_without_fee_frac, coin_pub, merchant_pub, exchange_sig, exchange_pub, master_sig) FROM stdin;
-\\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e 1 \\x95de2c8d8d584af667e3a66b91d0278d8f5fa810dff939501c5b0a707a6e93601f6982c42d31a16f72038aad89e7ebed1c7e78e5f31f94ec9f8631eb26bd2fa9 \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\xb65713724f4d8e1ac62efbe9ca84492fbf03b3dfe1c2cbee05236cf12cb83e1713977406c29475d037332f20fbbf54f11e302f3f5695416d8fbc84ec31f91420 1655640385000000 1655641283000000 1655641283000000 3 98000000 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x162020ebd1048386539554bf0ae7876128e037b5f1c46346a354705e6ba271763bf2146add46addc81ea50e61d5431eec4012606b27d54a99bd49a5075aac403 \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d \\x10990c4fff7f00001d29349bf15500007da03f9bf1550000da9f3f9bf1550000c09f3f9bf1550000c49f3f9bf1550000b0233f9bf15500000000000000000000
-\\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e 2 \\x734b89a6fa655225e628975df6bda32fe724bab6bc7dcc9f5ae0dbe677453b4dab131bb277c040b3e5b4e3605371389f9cad7b0315a98c48f0914467bdc28113 \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\xb65713724f4d8e1ac62efbe9ca84492fbf03b3dfe1c2cbee05236cf12cb83e1713977406c29475d037332f20fbbf54f11e302f3f5695416d8fbc84ec31f91420 1655640392000000 1655641290000000 1655641290000000 6 99000000 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x8564c4f2463a851d487a8ae156efe67fe0b549d9c7a85268ec59035fcfa8dfbfb18633d04d4a495964bcb4aab42673ca8193349b719e06d4762b23066fcae00f \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d \\x10990c4fff7f00001d29349bf15500009d60409bf1550000fa5f409bf1550000e05f409bf1550000e45f409bf155000090833f9bf15500000000000000000000
-\\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e 3 \\x051dde6d8850aa30ad3e18762851ebcc2fd8fb8e0b8984c04a8faf1a12d2162e1b855b80297792d4c6e2ed30262e9f5a9abba9f2e422c798d42503585a93d3bd \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\xb65713724f4d8e1ac62efbe9ca84492fbf03b3dfe1c2cbee05236cf12cb83e1713977406c29475d037332f20fbbf54f11e302f3f5695416d8fbc84ec31f91420 1655640398000000 1655641296000000 1655641296000000 2 99000000 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x704e4b2359901a534a87c51cf55eaa79ccd9aefdadbcd79b11b3030f4052c706961482094b6e7300e84f225e7d5e50d11708231afbf49e2320def6a5ab707403 \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d \\x10990c4fff7f00001d29349bf15500007da03f9bf1550000da9f3f9bf1550000c09f3f9bf1550000c49f3f9bf1550000e0853f9bf15500000000000000000000
-\.
-
-
---
--- Data for Name: deposits_by_ready_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_by_ready_default (wire_deadline, shard, coin_pub, deposit_serial_id) FROM stdin;
-1655641283000000 358907221 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b 1
-1655641290000000 358907221 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf 2
-1655641296000000 358907221 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 3
-\.
-
-
---
--- Data for Name: deposits_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_default (deposit_serial_id, shard, coin_pub, known_coin_id, amount_with_fee_val, amount_with_fee_frac, wallet_timestamp, exchange_timestamp, refund_deadline, wire_deadline, merchant_pub, h_contract_terms, coin_sig, wire_salt, wire_target_h_payto, done, extension_blocked, extension_details_serial_id) FROM stdin;
-1 358907221 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b 1 4 0 1655640383000000 1655640385000000 1655641283000000 1655641283000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x95de2c8d8d584af667e3a66b91d0278d8f5fa810dff939501c5b0a707a6e93601f6982c42d31a16f72038aad89e7ebed1c7e78e5f31f94ec9f8631eb26bd2fa9 \\xe39ca10cd50fb266bff9816211dd92ef083d51bdc3fcdbad4cfe300cfefc387fd7c82e5270c28a9048ca821bff59798e8a7704ea0b353fab135593ff49f4500a \\xec515a94f4b41acf32dc6e3f3a8587a5 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-2 358907221 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf 3 7 0 1655640390000000 1655640392000000 1655641290000000 1655641290000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x734b89a6fa655225e628975df6bda32fe724bab6bc7dcc9f5ae0dbe677453b4dab131bb277c040b3e5b4e3605371389f9cad7b0315a98c48f0914467bdc28113 \\xfc2b3ca2efe7d4bbb0854f4bbd61045e9477b53595b54ecdcbd7db283dc5df7e5b8b78c9b0159f60b6cccbf75d41a5add88e0fc22997627354c22829b3532a0b \\xec515a94f4b41acf32dc6e3f3a8587a5 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-3 358907221 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 6 3 0 1655640396000000 1655640398000000 1655641296000000 1655641296000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x051dde6d8850aa30ad3e18762851ebcc2fd8fb8e0b8984c04a8faf1a12d2162e1b855b80297792d4c6e2ed30262e9f5a9abba9f2e422c798d42503585a93d3bd \\x67a6c98db10e90eaed8a7dc8b3e414f4537913a62ac34f34e7db8eb6abe0d847073f23bbd30485710382b9b7e88a987f0213933a1b82a54c0dafdbdfae359d0f \\xec515a94f4b41acf32dc6e3f3a8587a5 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-\.
-
-
---
--- Data for Name: deposits_for_matching_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_for_matching_default (refund_deadline, merchant_pub, coin_pub, deposit_serial_id) FROM stdin;
-1655641283000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b 1
-1655641290000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf 2
-1655641296000000 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 3
-\.
-
-
---
--- Data for Name: django_content_type; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_content_type (id, app_label, model) FROM stdin;
-1 auth permission
-2 auth group
-3 auth user
-4 contenttypes contenttype
-5 sessions session
-6 app bankaccount
-7 app talerwithdrawoperation
-8 app banktransaction
-\.
-
-
---
--- Data for Name: django_migrations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_migrations (id, app, name, applied) FROM stdin;
-1 contenttypes 0001_initial 2022-06-19 14:06:07.778114+02
-2 auth 0001_initial 2022-06-19 14:06:07.909903+02
-3 app 0001_initial 2022-06-19 14:06:08.00535+02
-4 contenttypes 0002_remove_content_type_name 2022-06-19 14:06:08.024281+02
-5 auth 0002_alter_permission_name_max_length 2022-06-19 14:06:08.037325+02
-6 auth 0003_alter_user_email_max_length 2022-06-19 14:06:08.049206+02
-7 auth 0004_alter_user_username_opts 2022-06-19 14:06:08.058824+02
-8 auth 0005_alter_user_last_login_null 2022-06-19 14:06:08.068975+02
-9 auth 0006_require_contenttypes_0002 2022-06-19 14:06:08.071941+02
-10 auth 0007_alter_validators_add_error_messages 2022-06-19 14:06:08.081588+02
-11 auth 0008_alter_user_username_max_length 2022-06-19 14:06:08.097021+02
-12 auth 0009_alter_user_last_name_max_length 2022-06-19 14:06:08.107046+02
-13 auth 0010_alter_group_name_max_length 2022-06-19 14:06:08.120467+02
-14 auth 0011_update_proxy_permissions 2022-06-19 14:06:08.132188+02
-15 auth 0012_alter_user_first_name_max_length 2022-06-19 14:06:08.143816+02
-16 sessions 0001_initial 2022-06-19 14:06:08.169546+02
-\.
-
-
---
--- Data for Name: django_session; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_session (session_key, session_data, expire_date) FROM stdin;
-\.
-
-
---
--- Data for Name: exchange_sign_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.exchange_sign_keys (esk_serial, exchange_pub, master_sig, valid_from, expire_sign, expire_legal) FROM stdin;
-1 \\x210afbe5bb8866a19b5f295d9430d7a339863561dce1431c9d4566f782f5fee5 \\xb8911b7845d5c0606d43ad5eedc780344aee4fd936606cd6a9fd1ad59d957c431412a3ea4b3efda88a9df7c6b3db77a19011bc77416ca283ae7ce63b9005cb08 1670154967000000 1677412567000000 1679831767000000
-2 \\xac28b75d81c040fe21b06acfed1f8b69594927091442d4478788836452d57995 \\xca8520d51f7775304c53618ed83a04deb35d42b82bc901b3a8d5ea868c4b78c55ef7611b6bb863880583d6d8feef44e2a9a3130acd8a75882d1b2e14b2e0a302 1677412267000000 1684669867000000 1687089067000000
-3 \\x71a5e021472ae50c77dbb8fb43bcc2c3fecd526c3f0f8ada5d982e4d09199939 \\xccff7779ad74e8a010cdb28fe958a27b915693729b0991f6a3680895fe1e7141bfd5d91da1d470ac801403d51640d31814db2d2a39fb98181c83212019bf9908 1662897667000000 1670155267000000 1672574467000000
-4 \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d \\xf94cdd1c684c1e6a736bb5c5aaec3d5c4f60310ce02f2702e35de62f9297a9d623bc474fb42bf174eba9a0938594151bd7cbc5bfc4b70987a2dcdd8cb0c29a08 1655640367000000 1662897967000000 1665317167000000
-5 \\x1ef93e3311ab00c04940af7425f0487670114350f7e6f0ddc67f2bc0f5b2c11a \\x480f176c9458e5ea1bc106c88bc41ea49cb33fb92e5be554f7fd080a7c99dd6c29a131e800fcfd072bec3ad3499f449a9806eb5c1c9d8ad65e3eda1bd774080f 1684669567000000 1691927167000000 1694346367000000
-\.
-
-
---
--- Data for Name: extension_details_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.extension_details_default (extension_details_serial_id, extension_options) FROM stdin;
-\.
-
-
---
--- Data for Name: extensions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.extensions (extension_id, name, config) FROM stdin;
-\.
-
-
---
--- Data for Name: global_fee; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.global_fee (global_fee_serial, start_date, end_date, history_fee_val, history_fee_frac, kyc_fee_val, kyc_fee_frac, account_fee_val, account_fee_frac, purse_fee_val, purse_fee_frac, purse_timeout, kyc_timeout, history_expiration, purse_account_limit, master_sig) FROM stdin;
-1 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 0 1000000 3600000000 3600000000 31536000000000 5 \\x31b9a57344ca4526d135d52315d9f7dd51fe9933584540738c8ce32ff0486d0ce1560ed830c0f28ca4abf9d0aa99a4d5373a423b0a429b660e4e857989b8880e
-\.
-
-
---
--- Data for Name: history_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.history_requests_default (history_request_serial_id, reserve_pub, request_timestamp, reserve_sig, history_fee_val, history_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: known_coins_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.known_coins_default (known_coin_id, denominations_serial, coin_pub, age_commitment_hash, denom_sig, remaining_val, remaining_frac) FROM stdin;
-1 208 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b \\x0000000000000000000000000000000000000000000000000000000000000000 \\x000000010000000074b9c8513bbba52f0ed6226fa1d35264bc5acfaff159c63e9dda2d9a84b611d8bad0876bc0701adcd91f176ec213e937912c30f730f8e7d027410e4db719b6eaa43fc6f5cddb67260750d93bf42f5203beed6c03e9e8d43707aab10793db0e9f7cbff0c07d906754792f671076ef35a86595d88a77e2b139dd3b3ae4cb598b38 0 0
-3 276 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf \\x0000000000000000000000000000000000000000000000000000000000000000 \\x000000010000000073ecba6d95f0c449741905187de4ec660bc15ffc0bac5d010e994e27adb1dab89b5bc206128705ed77f32f4543d735f318c319429a8761bf1f5c53bf5b01a1a94b6014a2f189cc784f6cd8b76ac6b2d879ff0207ebdf7a50434294a92de999add68c3d2a116f1339c9378bfac72db26ef19b8b6fbe89d66f27935c1f0519b330 0 1000000
-6 248 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x0000000100000000815e71d37c316e9e277d65498b2504e4474cda5d4a56140464749242f53d1b3a8e2b715b2e3b66253c47db983da05b3ca50606bee8898a1cb0e78c5154c1dc3376d0fb832394fb491ce7ea04dde7a96e74992f33619468f45ed3f411503f26e10e629450c89007e0e89264c88d479a891f0e8c6b543ce356f069989330d6b509 0 1000000
-\.
-
-
---
--- Data for Name: merchant_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_accounts (account_serial, merchant_serial, h_wire, salt, payto_uri, active) FROM stdin;
-1 1 \\xb65713724f4d8e1ac62efbe9ca84492fbf03b3dfe1c2cbee05236cf12cb83e1713977406c29475d037332f20fbbf54f11e302f3f5695416d8fbc84ec31f91420 \\xec515a94f4b41acf32dc6e3f3a8587a5 payto://x-taler-bank/localhost/43 t
-\.
-
-
---
--- Data for Name: merchant_contract_terms; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_contract_terms (order_serial, merchant_serial, order_id, contract_terms, h_contract_terms, creation_time, pay_deadline, refund_deadline, paid, wired, fulfillment_url, session_id, claim_token) FROM stdin;
-1 1 2022.170-0345FDM7WCNXP \\x7b22616d6f756e74223a22544553544b55444f533a34222c2273756d6d617279223a2268656c6c6f20776f726c64222c2266756c66696c6c6d656e745f75726c223a2274616c65723a2f2f66756c66696c6c6d656e742d737563636573732f746878222c22726566756e645f646561646c696e65223a7b22745f73223a313635353634313238337d2c22776972655f7472616e736665725f646561646c696e65223a7b22745f73223a313635353634313238337d2c2270726f6475637473223a5b5d2c22685f77697265223a225053424836574a46395037314e4848455a464d574e31323935595a473743595a57373143515647353444504632423552375242483735564d30563139385845473657534a59383756515841463237484735575a4e44354131445037565331374336375748383830222c22776972655f6d6574686f64223a22782d74616c65722d62616e6b222c226f726465725f6964223a22323032322e3137302d3033343546444d3757434e5850222c2274696d657374616d70223a7b22745f73223a313635353634303338332c22745f6d73223a313635353634303338333030307d2c227061795f646561646c696e65223a7b22745f73223a313635353634333938332c22745f6d73223a313635353634333938333030307d2c226d61785f776972655f666565223a22544553544b55444f533a31222c226d61785f666565223a22544553544b55444f533a31222c22776972655f6665655f616d6f7274697a6174696f6e223a312c226d65726368616e745f626173655f75726c223a22687474703a2f2f6c6f63616c686f73743a393936362f222c226d65726368616e74223a7b226e616d65223a2264656661756c74222c2261646472657373223a7b7d2c226a7572697364696374696f6e223a7b7d7d2c2265786368616e676573223a5b7b2275726c223a22687474703a2f2f6c6f63616c686f73743a383038312f222c226d61737465725f707562223a224a4d304e4a58484d365936485941504b32574446483348444a3245394b5a57474b4d334530465952563256334843544233445130227d5d2c2261756469746f7273223a5b5d2c226d65726368616e745f707562223a2234335952474136333847364345574653535251484b58534233374858524a4854314d32525a54504d3247465733304d5939535647222c226e6f6e6365223a225a4e30545954305452393834584336313657303638424b30444a38514548474832514237343850394143434643444e5a57504730227d \\x95de2c8d8d584af667e3a66b91d0278d8f5fa810dff939501c5b0a707a6e93601f6982c42d31a16f72038aad89e7ebed1c7e78e5f31f94ec9f8631eb26bd2fa9 1655640383000000 1655643983000000 1655641283000000 t f taler://fulfillment-success/thx \\x6cdca09da86013a7add5ce8b8c954858
-2 1 2022.170-03E9CXP2DN5KP \\x7b22616d6f756e74223a22544553544b55444f533a37222c2273756d6d617279223a226f7264657220746861742077696c6c20626520726566756e646564222c2266756c66696c6c6d656e745f75726c223a2274616c65723a2f2f66756c66696c6c6d656e742d737563636573732f746878222c22726566756e645f646561646c696e65223a7b22745f73223a313635353634313239307d2c22776972655f7472616e736665725f646561646c696e65223a7b22745f73223a313635353634313239307d2c2270726f6475637473223a5b5d2c22685f77697265223a225053424836574a46395037314e4848455a464d574e31323935595a473743595a57373143515647353444504632423552375242483735564d30563139385845473657534a59383756515841463237484735575a4e44354131445037565331374336375748383830222c22776972655f6d6574686f64223a22782d74616c65722d62616e6b222c226f726465725f6964223a22323032322e3137302d3033453943585032444e354b50222c2274696d657374616d70223a7b22745f73223a313635353634303339302c22745f6d73223a313635353634303339303030307d2c227061795f646561646c696e65223a7b22745f73223a313635353634333939302c22745f6d73223a313635353634333939303030307d2c226d61785f776972655f666565223a22544553544b55444f533a31222c226d61785f666565223a22544553544b55444f533a31222c22776972655f6665655f616d6f7274697a6174696f6e223a312c226d65726368616e745f626173655f75726c223a22687474703a2f2f6c6f63616c686f73743a393936362f222c226d65726368616e74223a7b226e616d65223a2264656661756c74222c2261646472657373223a7b7d2c226a7572697364696374696f6e223a7b7d7d2c2265786368616e676573223a5b7b2275726c223a22687474703a2f2f6c6f63616c686f73743a383038312f222c226d61737465725f707562223a224a4d304e4a58484d365936485941504b32574446483348444a3245394b5a57474b4d334530465952563256334843544233445130227d5d2c2261756469746f7273223a5b5d2c226d65726368616e745f707562223a2234335952474136333847364345574653535251484b58534233374858524a4854314d32525a54504d3247465733304d5939535647222c226e6f6e6365223a223238344d3946474d4e54345158313756524451465a32413135505a4a56374548424a3950524a3354443552513952465645475847227d \\x734b89a6fa655225e628975df6bda32fe724bab6bc7dcc9f5ae0dbe677453b4dab131bb277c040b3e5b4e3605371389f9cad7b0315a98c48f0914467bdc28113 1655640390000000 1655643990000000 1655641290000000 t f taler://fulfillment-success/thx \\xff36f5efa9cb2b8aed6122e9c1cf795e
-3 1 2022.170-03MA3XHVY98FP \\x7b22616d6f756e74223a22544553544b55444f533a33222c2273756d6d617279223a227061796d656e7420616674657220726566756e64222c2266756c66696c6c6d656e745f75726c223a2274616c65723a2f2f66756c66696c6c6d656e742d737563636573732f746878222c22726566756e645f646561646c696e65223a7b22745f73223a313635353634313239367d2c22776972655f7472616e736665725f646561646c696e65223a7b22745f73223a313635353634313239367d2c2270726f6475637473223a5b5d2c22685f77697265223a225053424836574a46395037314e4848455a464d574e31323935595a473743595a57373143515647353444504632423552375242483735564d30563139385845473657534a59383756515841463237484735575a4e44354131445037565331374336375748383830222c22776972655f6d6574686f64223a22782d74616c65722d62616e6b222c226f726465725f6964223a22323032322e3137302d30334d41335848565939384650222c2274696d657374616d70223a7b22745f73223a313635353634303339362c22745f6d73223a313635353634303339363030307d2c227061795f646561646c696e65223a7b22745f73223a313635353634333939362c22745f6d73223a313635353634333939363030307d2c226d61785f776972655f666565223a22544553544b55444f533a31222c226d61785f666565223a22544553544b55444f533a31222c22776972655f6665655f616d6f7274697a6174696f6e223a312c226d65726368616e745f626173655f75726c223a22687474703a2f2f6c6f63616c686f73743a393936362f222c226d65726368616e74223a7b226e616d65223a2264656661756c74222c2261646472657373223a7b7d2c226a7572697364696374696f6e223a7b7d7d2c2265786368616e676573223a5b7b2275726c223a22687474703a2f2f6c6f63616c686f73743a383038312f222c226d61737465725f707562223a224a4d304e4a58484d365936485941504b32574446483348444a3245394b5a57474b4d334530465952563256334843544233445130227d5d2c2261756469746f7273223a5b5d2c226d65726368616e745f707562223a2234335952474136333847364345574653535251484b58534233374858524a4854314d32525a54504d3247465733304d5939535647222c226e6f6e6365223a224633384541314d364e593531394148483338543347354359544132515a464252525257484736445a335233523432585658365730227d \\x051dde6d8850aa30ad3e18762851ebcc2fd8fb8e0b8984c04a8faf1a12d2162e1b855b80297792d4c6e2ed30262e9f5a9abba9f2e422c798d42503585a93d3bd 1655640396000000 1655643996000000 1655641296000000 t f taler://fulfillment-success/thx \\x2c01ff4b336c21ea3d9396e46011eabd
-\.
-
-
---
--- Data for Name: merchant_deposit_to_transfer; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_deposit_to_transfer (deposit_serial, coin_contribution_value_val, coin_contribution_value_frac, credit_serial, execution_time, signkey_serial, exchange_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_deposits; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_deposits (deposit_serial, order_serial, deposit_timestamp, coin_pub, exchange_url, amount_with_fee_val, amount_with_fee_frac, deposit_fee_val, deposit_fee_frac, refund_fee_val, refund_fee_frac, wire_fee_val, wire_fee_frac, signkey_serial, exchange_sig, account_serial) FROM stdin;
-1 1 1655640385000000 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b http://localhost:8081/ 4 0 0 2000000 0 4000000 0 1000000 4 \\x162020ebd1048386539554bf0ae7876128e037b5f1c46346a354705e6ba271763bf2146add46addc81ea50e61d5431eec4012606b27d54a99bd49a5075aac403 1
-2 2 1655640392000000 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf http://localhost:8081/ 7 0 0 1000000 0 1000000 0 1000000 4 \\x8564c4f2463a851d487a8ae156efe67fe0b549d9c7a85268ec59035fcfa8dfbfb18633d04d4a495964bcb4aab42673ca8193349b719e06d4762b23066fcae00f 1
-3 3 1655640398000000 \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 http://localhost:8081/ 3 0 0 1000000 0 1000000 0 1000000 4 \\x704e4b2359901a534a87c51cf55eaa79ccd9aefdadbcd79b11b3030f4052c706961482094b6e7300e84f225e7d5e50d11708231afbf49e2320def6a5ab707403 1
-\.
-
-
---
--- Data for Name: merchant_exchange_signing_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_exchange_signing_keys (signkey_serial, master_pub, exchange_pub, start_date, expire_date, end_date, master_sig) FROM stdin;
-1 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\x210afbe5bb8866a19b5f295d9430d7a339863561dce1431c9d4566f782f5fee5 1670154967000000 1677412567000000 1679831767000000 \\xb8911b7845d5c0606d43ad5eedc780344aee4fd936606cd6a9fd1ad59d957c431412a3ea4b3efda88a9df7c6b3db77a19011bc77416ca283ae7ce63b9005cb08
-2 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\xac28b75d81c040fe21b06acfed1f8b69594927091442d4478788836452d57995 1677412267000000 1684669867000000 1687089067000000 \\xca8520d51f7775304c53618ed83a04deb35d42b82bc901b3a8d5ea868c4b78c55ef7611b6bb863880583d6d8feef44e2a9a3130acd8a75882d1b2e14b2e0a302
-3 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\x71a5e021472ae50c77dbb8fb43bcc2c3fecd526c3f0f8ada5d982e4d09199939 1662897667000000 1670155267000000 1672574467000000 \\xccff7779ad74e8a010cdb28fe958a27b915693729b0991f6a3680895fe1e7141bfd5d91da1d470ac801403d51640d31814db2d2a39fb98181c83212019bf9908
-4 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\x9bd85dc28e06af0b1bec2d0927025abed8ddd199cbcdcc41cfd996598cd4a83d 1655640367000000 1662897967000000 1665317167000000 \\xf94cdd1c684c1e6a736bb5c5aaec3d5c4f60310ce02f2702e35de62f9297a9d623bc474fb42bf174eba9a0938594151bd7cbc5bfc4b70987a2dcdd8cb0c29a08
-5 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\x1ef93e3311ab00c04940af7425f0487670114350f7e6f0ddc67f2bc0f5b2c11a 1684669567000000 1691927167000000 1694346367000000 \\x480f176c9458e5ea1bc106c88bc41ea49cb33fb92e5be554f7fd080a7c99dd6c29a131e800fcfd072bec3ad3499f449a9806eb5c1c9d8ad65e3eda1bd774080f
-\.
-
-
---
--- Data for Name: merchant_exchange_wire_fees; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_exchange_wire_fees (wirefee_serial, master_pub, h_wire_method, start_date, end_date, wire_fee_val, wire_fee_frac, closing_fee_val, closing_fee_frac, wad_fee_val, wad_fee_frac, master_sig) FROM stdin;
-1 \\x9501597634378d1f2ad3171af88e2d909c99ff909d06e03fd8d8b638b34b1b6e \\xf9099467bd884e86871559a62a7f23b6e876bf084a30371891b5129ce4440d3cbe27afe387d39b2ce8d9625abd388517c81bfc8da9f2e0f8c9471bff65a802b2 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 \\x272066002ec5e5b2ead4170a9725486d79cd121990451d0eed8c37b9f0ccc296960affd10de255286930dac890a321aceb167df1ee8c77b5138773e07a3b8a09
-\.
-
-
---
--- Data for Name: merchant_instances; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_instances (merchant_serial, merchant_pub, auth_hash, auth_salt, merchant_id, merchant_name, address, jurisdiction, default_max_deposit_fee_val, default_max_deposit_fee_frac, default_max_wire_fee_val, default_max_wire_fee_frac, default_wire_fee_amortization, default_wire_transfer_delay, default_pay_delay, website, email, logo) FROM stdin;
-1 \\x20fd8828c3440cc771f9ce2f19f72b19e3dc4a3a0d058fead4141fc1829e4e77 \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\x0000000000000000000000000000000000000000000000000000000000000000 default default \\x7b7d \\x7b7d 1 0 1 0 1 3600000000 3600000000 \N \N \N
-\.
-
-
---
--- Data for Name: merchant_inventory; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_inventory (product_serial, merchant_serial, product_id, description, description_i18n, unit, image, taxes, price_val, price_frac, total_stock, total_sold, total_lost, address, next_restock, minimum_age) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_inventory_locks; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_inventory_locks (product_serial, lock_uuid, total_locked, expiration) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_keys (merchant_priv, merchant_serial) FROM stdin;
-\\x68387e39384f371dd3761afc47422d5314c9abcdf94a0ac24847e80c8b4e5459 1
-\.
-
-
---
--- Data for Name: merchant_kyc; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_kyc (kyc_serial_id, kyc_timestamp, kyc_ok, exchange_sig, exchange_pub, exchange_kyc_serial, account_serial, exchange_url) FROM stdin;
-1 1655640385000000 f \N \N 2 1 http://localhost:8081/
-\.
-
-
---
--- Data for Name: merchant_order_locks; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_order_locks (product_serial, total_locked, order_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_orders; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_orders (order_serial, merchant_serial, order_id, claim_token, h_post_data, pay_deadline, creation_time, contract_terms) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_refund_proofs; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_refund_proofs (refund_serial, exchange_sig, signkey_serial) FROM stdin;
-1 \\x3505e69731a66b6f6c12665792abecb96ad8f69e524bcfe460f3d5c3c3862f8150804f3fa10437a0ef96e1c606222623f73563359751fa9ea74ae9061071a10b 4
-\.
-
-
---
--- Data for Name: merchant_refunds; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_refunds (refund_serial, order_serial, rtransaction_id, refund_timestamp, coin_pub, reason, refund_amount_val, refund_amount_frac) FROM stdin;
-1 2 1 1655640393000000 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf test refund 6 0
-\.
-
-
---
--- Data for Name: merchant_tip_pickup_signatures; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_pickup_signatures (pickup_serial, coin_offset, blind_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_pickups; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_pickups (pickup_serial, tip_serial, pickup_id, amount_val, amount_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_reserve_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_reserve_keys (reserve_serial, reserve_priv, exchange_url, payto_uri) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_reserves; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_reserves (reserve_serial, reserve_pub, merchant_serial, creation_time, expiration, merchant_initial_balance_val, merchant_initial_balance_frac, exchange_initial_balance_val, exchange_initial_balance_frac, tips_committed_val, tips_committed_frac, tips_picked_up_val, tips_picked_up_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tips; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tips (tip_serial, reserve_serial, tip_id, justification, next_url, expiration, amount_val, amount_frac, picked_up_val, picked_up_frac, was_picked_up) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfer_signatures; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfer_signatures (credit_serial, signkey_serial, wire_fee_val, wire_fee_frac, credit_amount_val, credit_amount_frac, execution_time, exchange_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfer_to_coin; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfer_to_coin (deposit_serial, credit_serial, offset_in_exchange_list, exchange_deposit_value_val, exchange_deposit_value_frac, exchange_deposit_fee_val, exchange_deposit_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfers; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfers (credit_serial, exchange_url, wtid, credit_amount_val, credit_amount_frac, account_serial, verified, confirmed) FROM stdin;
-\.
-
-
---
--- Data for Name: partner_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.partner_accounts (payto_uri, partner_serial_id, partner_master_sig, last_seen) FROM stdin;
-\.
-
-
---
--- Data for Name: partners; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.partners (partner_serial_id, partner_master_pub, start_date, end_date, next_wad, wad_frequency, wad_fee_val, wad_fee_frac, master_sig, partner_base_url) FROM stdin;
-\.
-
-
---
--- Data for Name: prewire_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.prewire_default (prewire_uuid, wire_method, finished, failed, buf) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_actions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_actions (purse_pub, action_date, partner_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_deposits_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_deposits_default (purse_deposit_serial_id, partner_serial_id, purse_pub, coin_pub, amount_with_fee_val, amount_with_fee_frac, coin_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_merges_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_merges_default (purse_merge_request_serial_id, partner_serial_id, reserve_pub, purse_pub, merge_sig, merge_timestamp) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_refunds_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_refunds_default (purse_refunds_serial_id, purse_pub) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_requests_default (purse_requests_serial_id, purse_pub, merge_pub, purse_creation, purse_expiration, h_contract_terms, age_limit, flags, refunded, finished, in_reserve_quota, amount_with_fee_val, amount_with_fee_frac, purse_fee_val, purse_fee_frac, balance_val, balance_frac, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: recoup_by_reserve_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_by_reserve_default (reserve_out_serial_id, coin_pub) FROM stdin;
-\.
-
-
---
--- Data for Name: recoup_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_default (recoup_uuid, coin_pub, coin_sig, coin_blind, amount_val, amount_frac, recoup_timestamp, reserve_out_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: recoup_refresh_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_refresh_default (recoup_refresh_uuid, coin_pub, known_coin_id, coin_sig, coin_blind, amount_val, amount_frac, recoup_timestamp, rrc_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: refresh_commitments_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_commitments_default (melt_serial_id, rc, old_coin_pub, old_coin_sig, amount_with_fee_val, amount_with_fee_frac, noreveal_index) FROM stdin;
-1 \\x4655f04cc16666410f93bf35b6606ac3870cd6540972ad000f17bd49174892d1371b6567c766497085634eafdaa755bb707bb1579b78886b3f99843e206ba007 \\x59756ec3b15b5a54f816ab5b0440852501067e9d37ad2037fa0e61c1d6ff774b \\xfdf15c29135df0f060e76978b430b90e77385f053a62a13b485c281ad43b09b99358429595970f407f817f18ed02dfb1322ece790c5bfa66d1839cc10a87500e 4 0 1
-2 \\xeba9cd52e1d82d98419110732b918e8adc9cb5029ea4d217bffd6735c4736c22635b232a5559a47ab6fb7dd1fe06c508cc585707139566cacdd458352a0b1470 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf \\xc0758993a761cb6c180061cbdcb3310511822fa2764ac71d63bb4fa076e3a214272c09f62496f56652436f1a394e1511e29eec3655601fd441ccac4170baf705 3 0 1
-3 \\xd063041939a7f4080c0c780ed34660ab68a0ab43390298d0c3b0d288c9aada048d6bfe8e0bb94c42fded5561b57662c924df94a7ca1f3635edd4c6fca24ad6fe \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf \\xd543331f5a7b0de9456ac7efeb5cb7f03afbc3244e59ca80a1d2e25bf458d0249155ee865cf885249b5ef8ced40fa3e40962d54d6c7773d0e933ce810e4e7c07 5 98000000 1
-4 \\x6ee59c008971a38230f1e6535af3a871169d3ee47efdc0b92fb303543297caaa20f34eb9681436ce917c5466b2893c548f94d1ab46d41dc8044d89e18a8ec61d \\x084583bb8fb2f7f09c7329413ec6e45f03bedbed5ade5c4c5347b6deb3e21c67 \\xedfb55a5e872fa519e3bbb6e54966afdef3a6312eb503252cad859cead8ddf91f5f88283186fd1e009ee32a6452fdd9b378b8b393737b8f26ccc3ac848d04c05 1 99000000 0
-\.
-
-
---
--- Data for Name: refresh_revealed_coins_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_revealed_coins_default (rrc_serial, melt_serial_id, freshcoin_index, link_sig, denominations_serial, coin_ev, h_coin_ev, ev_sig, ewv) FROM stdin;
-1 1 0 \\xd445fa88afc20a9f90ac2a31aeaee92a056a14146530f54059e6221738708113074ce2d87dc2a82efa7def48d33216a01b0a5c93ae31105eb943e7d5e7a1ae0b 423 \\x000000010000010052bdffc0c10571b8986683fcefc9fa44b034ebc70bb6780f8e7aea61387a1db78f6f611a105b1cc0ce4656d9e60da0387dc33fc540be85e335410523b05dd06090009ef66ad3c5ed7753ab10ce0a86c402bd6babbf0c59f27cdfb4fb3cc65b8960e040e71085587603ca39cdbf8ab96328d0385b84d47066a0929ca264d5de0b \\xbbe9fa5c5586eb0469dc503efc8d912543b5c1b41a0eeab4d6c9d7595438ae6002b2275883696ff75123b88e32747e08b8efa7c3a0344cf98c9314c49596acf4 \\x000000010000000159376c75a8f46081e62644013a61490e2b64608d4e2901c25c1b491701e46b6812c178883828e68e248c2166ab419d360e0bd665256c61d9a4c848636631e9fc95690f544697f9de205140e8b747bf8be3b729a80ad4c68ebf68757299f32b068ecae2d76f81af533e7f4da4775432465f94b3cda506413a6dfe54db711bf57e \\x0000000100010000
-2 1 1 \\x89b67681083751ec4295ed9cd4c0d36ea4af26af2071d30fd36598a1fdd5035a25f6d33d2224867a9baf6f6e13313e0373aecb1390763c6fecabca790d39f80e 48 \\x0000000100000100a09d2b1f85e8d9d4394e124d1861d57cd5188adc53470fcf4b8aa3a069fbf400b42acf514242b00a5a1f4fdcd2513c1b747e07a8f08318e386bc112d3218a049b86afb22f06502231aa10f30ffe93e756208af09d9ac766e87133f75c253f74209bad69f31d8f158b853dacb4b2dc08df7f8beb3d4c50f8318b2c62b42eda212 \\x4c03f101a17040ca0e9bd70ea94859d89fd427266ca3ba6d1ad5376afde4b93a7ced83688f017e8c68fd9d31f3d6da5675781789f06be659318e0580c811bee5 \\x000000010000000105a1b40d25de41c89a5352bab8f771975e13a578561d45c5d796ca7e91c6b2f84a4ab1d4d27b7df43f0a82cb1c68c908072e750bba1b5aec8781607c76ca367b58bc49d6772d5b1e46d7d7f365610eb04bf4e93bd75dcc321937b00e06678af1a9de9fb18818fa259c66aa82d97c80b75f0ee41b9615f5be26e93d1940dfea66 \\x0000000100010000
-3 1 2 \\x62026d6fc0c0fe422cb690b44ac9dee4e66619ab8fac03fbc36f41bf9934d886c99c3c7e5bb43fc11e49ab77a90f1993d85eb2e3bdca82e37409657d48062b07 178 \\x0000000100000100651db7d747403645224801972617c9a71e711bb77a8f2853d31ac554998888ce3cc6a115e1cb6a2a0d5b58bedfb2c76a0ca007adfcb60502bba8ffe0d5dac400bad9f19916229e5a6c6ec6dcd5b28738c8da68bb66dc552a0c84d28cbb2e66da1bb5142a1a210d63d73dcb1048a2b4ff467ba074adbab1e710fb6dfbdb956a4e \\x7f2a34b4498443effb1a923be1e2fa1350c5553bffe2ebdbd6eca2449262841981c8f870720f27d002d35b5ea79381f3e52da4679abf7583f87b90bcbea4b31b \\x000000010000000161878697cd53e14dc7107dba562d2bc83349f023c2406852681346e6105b5317a17652e0ddaff2f449e48bd4b8b536a5c93ba664e7caf872ce239020adebf740cc9d36e2fd1efa221e4f980a2a6a7f7ebe44d07b92645b7c5967b3ad7185f4814700501e54d92a4fbba165bd10a0be4b29863ee0fe087645c269f72706ba5949 \\x0000000100010000
-4 1 3 \\x92f00c49067fb1e9ca4eed70cf460647b951d0b74ddbf96753a498205d4925e4c7768ae808ae99a41e281156508bd5232707dbb2c33a17a2ccf6344440734901 178 \\x0000000100000100848785e17d2f2f211f2f958fdbb08acb8925d6ce615362abdd97015709ca4d0ff64efea284ecde9565fb5378cfc59706b6d896b8658106e829ff082ea5a930acd52ab8eb454f3512dbe1270f423ef59842894a5e914fd1d511c1721e15f635ac8e26568591ac6aabfcebea7fce9a9fcb33b9ecde08f1790396b9e5823bc718f3 \\xe3dc47b1699757c2a6dfd4deccb059ddb6f0574b9556c406ad2bd9dda89cef3d60ee38727db78cc8fe1877ca630d0938ad10817d894b832b2212ed3ce1d698ae \\x0000000100000001b8af90c561c9d95a19c38e7f4799a64575949877b44fdd193dd1bcf8ef5d9a82c0cf8d7023d79e8f6693de85af34f72fbcc73996de6eb3c632f1d67e742b5a2d33bd8d4a1709aaae3e7786c34f856f25f8b16191fb36bd944331a183b66391a91f73d37213e3840c734b602d0b6940edf2cd9864ce498ed0d00ca8940cee3eba \\x0000000100010000
-5 1 4 \\x66ff42d094120d951d0becba6c69153657d52c4a217b12760cc5d2c04e913cdab8ba72d8821e5c8c9c01d7d26cd922bd822623fd745f958559acbc42948d810b 178 \\x000000010000010025965f0b49df3d15fd402d395c391b197bb6f1810b16f316cfdbecb12c6084f9ed2fa0d4e9a77e760d79b374fe2cfb37e6f680c68c775d1fd91a9ec92926be018dd2bf8d21d977161efb9b0fcef559864a45640be1ab304ec0e02c5df7fe195cd61b1cc186eac7dd569509736f2570c20119f29448b41de1b0c9ca32590506de \\xac8bc40d6934bf269c42cfb022a9b128b1dd36557aafa6a0be7a44159b48038b9e2070bc8122ebca2e64bc1b68c02062a25d188eed2ca8996af0a857f0cc8353 \\x00000001000000010ba9a44771ab9ef2ce8643af6707d24444abe63d44149919281c034f8b64db9d235b48758ea0c04bcfd470f610123130a4e61ae0248aaa986efb204cd4c6b17f883f5319ee229bc378d2bfbded988f1ef39fdab65bbfe87e4fb3de4b7294e46f6cd521c2acadde47cf61afabfcaeee16660e3ffc883aa071ab8279a96787462d \\x0000000100010000
-6 1 5 \\x198913cb54490c331d6c3dbddc5509fd96116cc005016097ef840750f41697533ffc0697a0b2a61689f5a3113778825394e823323c95acbbd54ef34d951caa0d 178 \\x000000010000010080ee86c44113370835b24d7d00175ac3e83d66bd2f31154d8fe0a79868a4d54308668616e88f7a713c91fb691b51129846bf11d54b0992e6110b980015c9d99035b78bb1f536424207b4e16ef60d5f049513dd9fa4aa2648f85a64a2a77c79ddee782fb13a3b221ddb66d9e1c7ff080d6df06ce4ad00c42f760a4bada6fb9b0b \\x717a9a8bb945410b530a80e4437a70b9d88e106d54de34f28ee793498a95f227c6992efdb0eef29506ffd54d05b9468e46c0dc1e53abc54882adbee0afc817c7 \\x00000001000000019eebfd210894331a2a880d0a2ddce26f6a1811140f928a44b6c2ea51c757ae98ea120e8b6b8acd60c87fdd45b49a00e58c41ac6523d9211f4fac97c32ad92cccaddeb5491a465a53b4d17b856ff12b0e291efc8ee5b25bccd51c7b960b809ad28814632a96cb574fca77af5ac8ecf8fb8fc30d06b25d4f4648b6100b27e3421e \\x0000000100010000
-7 1 6 \\x637170acfae29f14847704631a49573409150256255f856d7b2b741dd8651ca421680133dcdeabf819db8cbf1eb700608bdbc36b632c7c20db96ba085c504307 178 \\x00000001000001001e1d8568143696600cfef3c4bceab2c6ca9a99e7615a128404080a772b5f14e64109ab9def046d87a8e786115f00514c9144fa437e92e508f5a513552f744d562e624d99079641a6e93a6571b14423a47fa936e150ec9427113449c7abcba63cb32717d2fbd33025111b7106eb8e2a653978d08ac76c0b5288145317ba2adcaf \\xd1f6d982d2e2ed973ebf838a88fdd3c8505c4e8a8a469d1072d1f9d7be4b8d60558aac1bc137059749ee1eaadef14c9d6eb5283611ff07b8411fb442fed5ec19 \\x00000001000000016004134afd635124fb22156ee2e191ff104b264af3d52965b7f308bb21a512942fbebc6885c38d034fb5e938857009edc4a36f7e9debaf38169cace6eb52938268d3a3f05111ecb936d509932971120d390d2cf22e7de8ab3d3c0b3bc4b930ee39e87a9142c36589b2c830a7a4b404679e9f4d98f42b8ebc23caae9e4fcae4c3 \\x0000000100010000
-8 1 7 \\x5af1ea3cf3480f4b4fc86adf6e65d87551aeeff179a4dab7d3402485fba5b7d78387ebc246fc4052f1f6a2d8bd8717afcd5dae65c26dfd301877723257eeda04 178 \\x0000000100000100a559952cf51b6f964d62bfb9c4d3b00f2560dcaba5e1fb837c2b630aefd802401db9b814396511468a40a90ec0b693707f3128bab45e5c46bacc975fbe7fb613cd8e664145fab09b9f9f43229ab5ebbe4eb8b6071e7c124f481ae7703044b869ed8c37610fcdd2c9ce3445aecb497fe81246b33f4dde32982f29dfa73fa372b7 \\x8809f4cb4370d3a2b5c17f79ca41ac415b543e6afff818f01138fb0f1a5062ea22ece6426f9aefdf7dab23d1120a22679b981415373a303996d20fb2ca51df81 \\x0000000100000001081d5a4b9884d2cf1d0b3868a3cbcfc8063541ddba1eaef0f91f2a7c4f94e4c2868bdffb630c4b6a198430ff7ddb3fffc0d49600d06d1bbb3c8b9ae44327bb58a7b125b8e87f441ea10491d9eefe1425de7fda9a44f07104561d50707d40d5e967d1c7f06f55e9df38ee66813fb79a86bc69dcd6638ad81ae8c05d76f4972069 \\x0000000100010000
-9 1 8 \\x27311115ee41d7bc99ceaf07c545c539c0ae3196367531d972dfbae5358bca7402131ecd2b169025594c9bbf91325620d05b22c50d73fc50f02c881d95299d0d 178 \\x000000010000010039f3eba33bdb8473f5f7c95a33d4d31b0d05edfa80999b716e1ebaaa1dd5c7798a650c49938872fefaf4cbb558f1500fca9ede6eace27df7a14eac7534c50cf43efd8e25e30540f0762f60299eb3312a4b613f2765bf4d59f1d1a1df7e9c29424d5e00b92ae17e3c5f235ff21c46c0ac7004abf47a0706ac375638acfb247274 \\xa7b49ee0ca2e0ed377a2d66005c8589214e62bfd855107116d66052f69b7a3cd852a0ef4671a1f06b7df396d8417776e5e00ffcd1dbc72214167dba4d549fdda \\x000000010000000183179c4a7e83c623f799bc65797838c636300a7a751dad2fd689a06a1feae49fea7b1d2030c83eb3f6a9cea16375965a03c71bb3a5b2bba5255612f327ae91e6e298673d3b31673fb848084776ae17f5e8c3adc293869e67a3900bf0aa46e078789be4b5ca140611829d0344dab31b44423a3ecb39d1adaa7a5f0ef38156fe76 \\x0000000100010000
-10 1 9 \\x169aeda1840f1a495b457f11365691fd9201e867c7c9f1fbdb686fb79aaaddc44a179bfc4b1d75527217ff66f7e353576343976583cbc1ae80d1b0ef92d09404 178 \\x00000001000001002f2d859291089e18f36f0ec514e2729d7fad3d29df8c9dd8b413da9e4fb6065b45c4776be58220ef410ab4e0eaab8fbc545cd98a28bdfd9d23ec88afaf5044d5f7272a7ed60d8a6a9a567cb92dce2d7e21cbcf2841017f44571cfc6a09bf928027262312eb3625e756ca98408e189d6206ca35152768e3ac290a2e5997c93ad0 \\x144001dc0e5eec7c7d81a2cece7fc2dd2e5cfa53639163cb441ebb83d2a8e9e7cdeac2ee75d5a7393edfee3ac80d3175099341c9adf73e67b9f284f45de8a17f \\x00000001000000014b1f848e953f589874cc21cd9950117b7a5ea838161fd8a8cb13df23e24a87ee17d84761c8da55837b277c738b3bd9083212e03fad905fa4c92a23be7da56c67ac001f22683a118f9c70b60db5ec6f04c812bd605b9d9d62d6ca5288cbcd53e6fe04345d61d9ea1bc7d793f5f0a128cae9fa06aa013d789f729f323bb4611611 \\x0000000100010000
-11 1 10 \\xb58824cf443b3650aa22e0dc80ec12265294878afca43d973988e882c1ea8f4a8c286ce3466f85144a3d62aaa9a0a60f5ca347cf0a076dfe7272ce97b7888c09 374 \\x0000000100000100f0bb954df030d98e0a7a051d1d4b59a879b34c75a5ce0f906f90cb6fb8558bb104a64c2e9612e5966d2cb3362aebfbdecca796ce97b118254533451b4b7f9de7b48e2f6ab6cd7a74337275054d0bd559472156749d5d9ad5590b4c491348bcf1a6a207bb7c1ca67c55f3dbbdb7d73f477010192ab8abf470e857e7de68ffa4f9 \\x95bb014f8fc80c38e15ea54df8107215dbab39d5643eccdd14b9fbfa55e56a921d979d3def467e182068818698dc76fa6ff9b498aa4568db0c108383419d26b7 \\x000000010000000125bb48cad7a98f1802d5537af8da5901e40c0a16ac6be4e9b24d9bfcc24bb579f79d329d879ee62502a20e48d4af209fe0ee58efb0af09427ef901cc0e38e1705c0f15f0f6e032fca6a7d536e5cfdffea6b7eb6c58205795bdaf5835286853766ed2010104d2f50deb6348e44f0f33f560f1d270daa49a412565ab3574f7904d \\x0000000100010000
-12 1 11 \\x025ccb1a6c928a3c4a235bddadf5cc9d06410f9c21d01ccda6a51b813a86b8a5523c867d2cdbf0d32a7e36ba85d72a200152e6b8e00a24d38070ba8b5b0e8802 374 \\x0000000100000100579eb205c07d0bcdf6c799e69e2b344bc585caf309503f09d8819279f2080602fd5eb70e01d0019546577c5c9ad16ac5975c679fd9f352d3aa4bfcae8e2d78aba86e79bfc12bcb5161ab382108c99ce56f8b34ae86abbc573cd6d6a739594f5550ffe27dd96b27483c6930dee2c4cdfb3d45278f8668e0095f347798e6935a6c \\x2e5fcd98babac79a07a81a5e4083c97b3360c8cbfa871ae5120d15e3505161874d9d3eb8d48180bef1dc17d8190359ff89efc9516d7ea859042e69e20a2cdf30 \\x0000000100000001692b7c48082b7eccd4002f5c0e2d20330b7525bf5d94d3479fc2afce4aa216f7a8e604dd1f96463e74c43efc2d9865fc3cd93965c8294edb8506ceddebd0fc678ce010f237bdb0939538e7fd4e7daf7b80824bcb6dacd122ca861c8e6dcec56d1bc85dac7171f44516221170afe38297fe2f352b27c11db20aaff992e66862c1 \\x0000000100010000
-13 2 0 \\x5f67d7e422bf49cbf017556ca0a591764af8503e2ac74a7bdae692b9b7416d2c8a7c3672e43af5059ea6aaf95e673d66d3cdba3a17b2be3fba98ceb38e86dd01 423 \\x00000001000001000b035c54882ead471c3ec97ee07d42eba73221b870f199fcd434584c44fb3bb9060984f0e111c2fd836a263b2528736c6e744d6ea2a448c0355b8140a0cdf92850cc22a5359225490d14cc8e7dfb8ef73ddf2b4e3e12039efe63dfd31e134d0abc77f182fa4c542756206aa25fdaa33233404b313a83aa472261e1b8d6a4ae37 \\xa1f310984e326de6e06782d5d8c81f066f118cc2f27213807ed9159b288366e8ae440a8156f9535ac07d73a7e7889f8c007098acde97d50da2d0a545c11ee98e \\x0000000100000001960e40ca86b0202f689d801cf6663691953c698675554dbbb70e983d9f0ac6d889092be2f436a3e433a044cbf3a45e19694c73ba65c7f0c809ff133733db40874fc8e3e4e964583543980bdd18088af8abbece2eb37cd40d9ae9b3d25bb8b74b57448e214d15631dc6536094016ecc4b90292e0f27c2fcaeb008d10acb2be062 \\x0000000100010000
-14 2 1 \\x8927d3826cd3dce9770366f52f39c254cbbd3b8bfa61a09868dea4c16b854a7bee14c5f8bf08f7bbbc0a9d2dbbeddb9f74bf1bc25fab508ffd518cecdcf36509 178 \\x000000010000010038cfed045bea46e5e029a5ce60cb42069d046ed58a063fd74e605f1092fee6db47dab2e6e1cfb807c4bedbf972d32dcb007486ef3e61318c898665eb9cbc808070e710b699c8552fa509fb2c2a3c34cf61da61321f327699aba46dcc437fce050fbd1684d425d683debf1d0dd60ae58777e53ef29f47e7f957f4fb77826aff3d \\x5a9429e3beea68ddab36d02e36962f16f3b0af118f0c9a9868fa16b4a80cfe463f7967a746e031222fe80774749cff8afeaa003b179a9c0777a333280e86f7ab \\x00000001000000015ad5ce16380108fd078a5a483791a3986649bd9859d9a2ac8ad7a322eb3487a133c4e405a02f0ac157b1bb000a37098842a3af5df796889dc7068c290d397698e456d0f5bda1c81b75568976fe0b5c1894325a6f0737b5dd6e692e933aaa8f352d7d1b66cc8330c317d731dc0fcb8fd716d48f71d8db24459e910eb924291ad3 \\x0000000100010000
-15 2 2 \\xefafc9858fbec39fcd52f384c90cd109c99005728f59c11eb8c1c09e5072f517137f60ca7fa08f06c5409ba8bc1c6d29756c33e88300ff86459f0915872cf00e 178 \\x0000000100000100469a84509778fe928cb894002e123ff08613a955bcb46cf60d7008c5972e1cc4b0e91541406758240f2dfdaad2f3cfd1e10b422864f5fd1b26019d7bc457407bfa4bcb1ffa48caad7de9398ba2237defdb239f5f639d99c4f619fdaf921c2b693c1ca41fb0fe8e4f965af989c7dff53f3b671c3f882ab2c75a052a41e9e7339d \\x6df31843a74bb2ed3d4135b35c28811ab98ea8298f3e81a93906b71a4bccba3d63458828e571454eeac885d6e76cb25b0b6eded0a7a138a37c88204b27cd00a9 \\x000000010000000119ed74461914b2d0681af07e9a37075833ff8b426fa51e9241aafe6e707406b9120e2909bdc96f271631332b414d96f3aad496d17aad13c8c0654fac66af2eb2104cd2e4e17ed4bf70aafdaaa0a4f68f4bc6dd18a7940e85bba9ce947155b76919d93920d02d0fc72ebdc9b5cbaf612df5cac6d7a58d4926ecbe9b2aed86d9d9 \\x0000000100010000
-16 2 3 \\xaf28eec35a9472324b41933f3d44c1646dfe5992bab52b9c87dfa691df7db0d439dd244b52e95f79b5078fef2e749a7f0d44d9bc0a35e9c8dcae13712e2eff0e 178 \\x000000010000010048f3721a4d7446a5dae9ee9712da1fa2086813d91e573aa1ed12e91cdf8d4d7e31d0c45119de54164da6a9ced43f3e0d57cf87b74c5f2e427845b7f0a3dcfac66a8cc3d97cdcd1587724baa1340bd478b0c5c2531febf16858a1524f849465b89f7fe116428cedb3607709b2693c62fc135dd475028d294db6d4205d765c9bf4 \\x72d671f57edf7bff359491e53eed35f23c32cbaba8ee15c7ac5e40541fe5e5789d0176223eb674367224dccc3289e68ccae3d4582c200c5ed5933dd2776edffa \\x00000001000000010dc9e161178ad280aaf48002f817140056ff77f161a72130816d9d9bd181164a55fcf73c159cf572a2323b5553530b5456d4689f9bc07097fced6826120b77a1433562b223af48a8e959e35012fc7ca2c55d1cb9cd903d506bc1a1639081b230176601359eaa68b48fc5176fa0955f277067ad470ce2bd41109c1d3f82bd9b5a \\x0000000100010000
-17 2 4 \\x359adefe4cf2687a077f06c10185a42f801cee59ea4254271814aa8aa46423c6980c40fe931c5b736d5a361df499d179dc036d52b8dca3598ce8a782a04a760a 178 \\x000000010000010032e43f08789c26330db5328c146c113251b188169247f11ffacb9ee2163379663ebc6224e27405c2a3ebd7c21c10a61fc82cc7b73347ad4d458169cf685ec6698019af0ee6f1fe972c0726e19726d09e4cd1339559f81b4f56aa29f6a58dc5258fce3afb8759beb43575e83bc0c7d5df981ed53b209f2aef444a87ea63bfc052 \\x21039f7aa14fe3bcbcf27d9292aca93d1d0e20d64446992d8a0f4a8a2fad47fec786da788a1e27a897bf2acc00f85c7388a5a1a80dd3b25840ae24da10970297 \\x00000001000000015f3660dd4e0af927b793452d0ecb6c23efd0051975fe19765dd9d90bfd0114eb73b9e2111b8935c4adfb8e223a6c90f5e5224b2f5a033c338f9cc44de050676bba680921235cf7c24891c3f282249bd98bf04370d4150ac81d876f440487a2a8c96166660b159600e2c326623b87f33e6d03c9361049f3c84bd84fa58e6ec299 \\x0000000100010000
-18 2 5 \\x745a7119abd1cdb7d3d1815fd8366125a9e0f845afa427825962054acf21c49296cd91d73b7849563c89bee63ea1a5ad1bde547f9fa36426c7ebe225385be40b 178 \\x0000000100000100107815d93828f1465c3345834479d714d4d87b7d2aebcf735496151ee4f529602707badd16ebfc8fda31cee701ffddf5458f785b4a1a896a8c132b72273bc1f30a7d1b827a848ebfe7166672005b536b6150d865c8fb199bb6ade874f93218531e094fe1f3f461a19746648c114f79db7bcb1e8a071b86a46da4ab4dc29ad007 \\xc593625b9c113dcf1a76fe1b4db0e86666afe0030f04692a25dee7e8570917103934a9dc1a56b589d57b3135008d661ff108701298bf0b7110700f4fbbbb63f7 \\x00000001000000017bbd84655ef8835faf0570cf8e88f94c482a8450aa4cb1e173b25a636b1fe7d7e1453747e62e6f69f9914fad1d03bda2c5cda8f7627cd8ddd91dc037d7c76e5f30194d2aba9e964001fdfdbf45e006511e561b33cf6213268fda1eaeef38c6dbcf59ecd589beac26847e6e0ef8830d5c7fef90a31f4b98c5ca69e693d447a345 \\x0000000100010000
-19 2 6 \\x8523c4861aa6d828a67dd8c3584921b1af8735f9930de2a06b4a7166af363bfdf68f94eb40e1e682d7bbce5133861dc3ff67201facf96f08d5168d3d2f005d00 178 \\x000000010000010049bfad4cbd7b8fa1d67c815e713dbd808fb13d3859133e9f9a3e13c109f672398cc4b4ec9c9981d264dbd90ad2b0d0967cfa24e0b6593ed02f6a57534ba7669177b01ea2bced1f3402d44af6cd10201f4df4dbb8f0dd7b08c0575dd9592b6740157b615dd28290120807b532860c4f432d2e9f67986d07b0e0bbed080aae0507 \\xb04492e6bfa1e985529e7568d0a460dc844be639c943b937aa343009644efac36e16718e21ef09f1b57bd6acad65c8aa5e7fee75e27c9338f7d8a0dc7ee1d9d6 \\x00000001000000019305e6e87e4ed10e53460100d844b1342cce466d767b7cbe327824201642ef5894377b88c650ec7f708667512b5d9368ed232d94186bb24f3f005172d1e201ca91975d79ed1552a01d12e9ea0c278b1969cccbe770483a900311940b3b46180676683fa448bd0af8cbf166e7b68e02aa3743a9f61bec7720ba0ea3cf2faf7978 \\x0000000100010000
-20 2 7 \\x2016acafca2df78b9ae502b066a27b33d6edc5e87b08b1fe34a88b678fcad3ef6f6564b7f4d2c5b55cae27c3897a7cab34c61b4721135220912d84b3dfbc8b0d 178 \\x000000010000010008e350d2702b42c7912c6a5187c3ad370c85ec2eafea25a39676a7c40b9ae6a6ff7d2dcaa7e615b2b69374e573b2c33b35eaa6e9b0afc1017268e1833a1e8778f2cfb27d1ba3db460d16dcedcfb4f29e8fbccd3a314fded4e471e6ffde209822513995546e8cabaa9da92f926489214899119e4afec2e6c93255bcf75fe69a11 \\x8a7e452464873c7ec434cc1bf5c90663b0671fecb27bdd66b0097f196cfed7047598b538c0ee0c912006fb95860050b6a89379281f9ab7354c3d63b739719e1a \\x000000010000000182ceb6a263ecea3da597e41dd93bb07853a9083d4b9fafe07cab1ca65e41f334d4b9bdcb956cb5bda3e6c31a2f4bb7aa1bcba1e44c17faa4156006689aac9df98e19f3f595d31530bd2f144076217f8a91b6952c4c85cdbe1ce5a798b043f4896ba4f0ca3243d291d658cc18ada3fbbdb6f8830f34d5146ded11846b606da0fa \\x0000000100010000
-21 2 8 \\xef8fdd4193d9995b93133b34926930c798add57d875543c84c4bff71c1f69daee4f9a4b6b7b3d5a2e49659b716c9d88e26a76cbce05f200eb11f08c3ee341309 178 \\x000000010000010089befbf58180fbc586461ed7806a69f77367f0a68b63afeb09c5bb2c189d5cd683b070e0eb473170c068439d79d753698d62d9bf8226a1410f1ccaf1e1a118d994225cfd9defef4a92dd7274069359872f1abe8927dbc63e15bfc11d75e202901d887da01e6448342466ad463876990923392f1187a8bdb4f8661c881c113d12 \\x1ab7c8e4d9ef5f6fe3c96e74659324d32f1dd26809e00db82ae437870d51b9d5f474da44656de3825e6843a1425ff6584e07f136dabc7a94b4733702c306ced9 \\x000000010000000106c4f12cd67e82ec83d7a1280a1fde90717a1a04dec42e688124ed197cd5310f2f2f4be35556f0239946542c82556cb9abafe4ff41603d4426cf763e4a4bd05ceeb63544e67e16f501d298f01c8528c60bdb96a652f3db2ce7c96592d96fbd3dbc8d2628606e7db4e06cfd0206da7d65a96539ce9278fe443763678d968c97d4 \\x0000000100010000
-22 2 9 \\x6c67ac6c9ee220496f60604902ddf27344cf60d0742a429d2727e0c5d5228407a794c5ccc1b22fb8dc3fbfa44587514286c0efc83f23f55fe4b97b3b6a4ef909 374 \\x0000000100000100070544945f8f387073e83485fc6717bb5d4bc84b41d8985f8094d9a54bb6c53d6662ff416980c36cda6ea3837a78e52ca822f4f9de8858d8d9e6ae0c0a339a408ee068f6ec0a4cbcf790e87666b9ececb5c47d909d5281a7864646b469824808920974a4d56056e7d52a2a1fdaad1e69e0e5aec575ee73a13410628a5612340c \\xdadc0252ea1c48364ff716e10b2ef0098aa03e261b08d857fc933aaa9ebe9f7b810491b667ff310e7824399a94fcade823f328e609555bd73f2b2db1b29ef6ba \\x000000010000000159e10de6ec907a5432673b9b24eaf7d4728d612fea5540035789a1c16d35e9ec5b5cfcb750caa20a724058bb05f1b1923cd2deb9ea850128d079a81e3fa887cec5067020906045e7d61046b629716d38191aa38e15c3edfec3f3928cd026663fb65e7f7efbc05ee8831a51b9c0a26513b675c6001a9e61c684691a4e61f0b9e5 \\x0000000100010000
-23 2 10 \\xff332b709fd3028edd3bf615d8dfb6a49235285a535dceeb7544b9cf3eb8eafaf58ef3673f7dc97461dd968d36e8824edb5810b4fe9ae5f0e318e49acd611e03 374 \\x0000000100000100de351bc0222662da94cfea353c1f38dc0cdc918fb3113b3c44a5ffa72b5b319878106c264b1927659db9c99dfcf3cda3632155cfeafc64a5e79be0cc3bfda830e6d7cd2b41b2e33112bbc8e61f6c89ac8a6ac680bab5a82d0ca3dd36d899f05d9a2284cc66878fb002e32ca36da7b024705272a03258b2369aed0ec9f80bc69a \\xb6bddd920185c2daf34f923e12e1bc57b251ec6189231c58644422de7652f22089fee57d1b42999c85b6dc34fe3bd29ddc76cc12a4cca9e3b4f1f62a0753bbbd \\x0000000100000001661ac161fe0389db6f3543efd83164b7e22cd063bd7493f857b7c5f41699a500434e3fc423d5c86efe430bc2b11088d128ee38daafa295dc702eec34c291a06cbe8eb80d0770bfe60f6d6d64e7a516dcd4750b23d3c6e6b0bb4fdf41e4c45e03d8aad5d9ff2c01a8a1fa5282caa9bdd82649e7698ad6b9a708aa1c44c02e3f7e \\x0000000100010000
-24 2 11 \\x08ec604eab695f93ce2fa2e25dda65f818ea5c54d591011f539eba77daaddd399c07907580d319ad56a8d722c5f5f2faacc5f1f0b78b9bd1600c1abc99a2ff04 374 \\x0000000100000100b79a4bd8b20c48aa045fff56b0720f2d5d1801ab5b5d295d694263841fe42043576fd8edd92371ef8b5be8704a5bc8757817051fa854bb442bed2b1394856dcb9a12cffc64cae743a3f1b4835e9e768268ff5a997d2e05f36e67b40f9a8f09af09fa9338d787fb040961a85bacbf40852238a4c59bcbd1f1ef9df73decc95910 \\xdf8fe371d1189b52eb519086c9b54dd44a84d6119a62ac7ff7ad9a8641786ca417ca403708178502e3977f402a764a18bff727ed21f046db74228c3245b0aaad \\x00000001000000019cb2cdde7948f478e435e4af3dcfd9b6c997fca932fed7e1481b8902e69d561dd0cf2023ab2136c29d26d26535c4597c423a68349d6c70493118091e510a6c5d1a69d4148980c175000e226116f6269a5436ee68d343ad3aae67a9a3226ebaba16e5f0cacf6237c44b5bf4353930f4c657090bc8b9269b2347185105ee4addb1 \\x0000000100010000
-25 3 0 \\xea26f36d335c035ab829e01fc43a6925713fec5880ed3330e2b411215951c74e8c5132a11335433b53421a726b30fc9ce149ac02ea0debf2bcee0cc5ae8c8505 248 \\x0000000100000100aa975fd1358e09dd1c07e97ca62b2433b79916788f1c7cd50a3f28bfad3a0316dafeb6d76a03ecc93994a80cb929d24632631e4b805b58ee51cdcc767245e41e81b5fd761067b64fc80eb69c242902b9b1a3fafa7bf8f8901d833f8f60d296d70c0cb723cfcb97de787b089ccf5b779767a111019340a15611a2ccf07ebb942c \\x154d89e0203ed22a365a2e299e440625238b2ea270209f38472e11c0e1d188704acd81ec100df0130a8379fbaf610dcd220ebf30fef9836b4c564f6532f65a1e \\x00000001000000013532d73e3cdf5d9d57a95b25e0e87ae7a349f3c10a6d06de7af038e06563a5f361c7c26b1d1079c7a750db8d79c4d9660ca625d83f301f894ff9a9fc072137aae49135f682c1da41cd11a2a4cde3c5e41733c83f1e3535b37b9ea4ec7aac209c2de63ec0d14fe1f8f1d0fc38d16be1cf9acae43a57d3c2f7948370e644a1fc70 \\x0000000100010000
-26 3 1 \\x97df77eff8beab5d7a690d91fdc3503edb2e9d44b10d7f0ac25f6dc6d780b2a70983945118db743e1c404513db0b82bc4f4a4fcd3a6b85a405aada16c04d9204 178 \\x00000001000001004538f6f4f459b03794bc2072cf821284ee57bfea26b3b5353de5a42c55403dbe193e52e6d3a3f7e6af177fd25479a8cc76a7f3fd5ba9d5d34275dfbf25c0704f551de85ead8c39d103bf1adb664e1d1a32f104264322e50913d399f5c94f21a066b9ac3b09d272de2269fb0c61e68bd330797442e3e531710e75f17c28d0c10c \\xd7c3eec653cb3122cb518c72982baf6b63e94a65095c1ebd321e7c840a59555a58fb55314d014e763d89e6f23d6ee239db7497fe8bd6ae35f3f4af8bedb22623 \\x0000000100000001b074dab128af6103aeec81ed6b89bd904d6a1f8cee1c0962515ba487b4dde1f110e2956bce1a1bd9325c6bed3a2231f237c94c8908ace56baabc230d0c39f825604e3a8c7a45a7ac339db0d2d789fa475c52ecd9b6b98231424d6de8382f320be1e212bf18cc649a6521048357a6e06b754e4ae0bbccac4aa9327d516a86b4eb \\x0000000100010000
-27 3 2 \\xabda75ede481d2b0345497adf5bf7ecaf45b6e857da63c3c384ee4342d2be7c102e7cd1fbee30292e1b3b96b6d14be2ad7793fcc536adf64764b0fb0d6a4e50c 178 \\x0000000100000100b45605caa3863a33570d1fd05efb5f554c1a419c69d2e4694b6542500f1a40ebd37bef8f659cd7bb1c7dced98d961f630df36d1edd034774f4ee49ca725abbc279382307f67c5efbc0adcf4ea76e81d6ba58cfabadfe02dc9caf6565ff238ab65b554b4eab098ae31a7cb00890b8c921b44b5642ba5774c45914004fdf13e777 \\xddf0a6ac28eb46d7e6b7a9a5cd8be79689cd89fed6c31292225bf8a2d7efa22615579cc3d24c3ab9686a2fb6a28d953e69c9017ef35fa7868e4dca76293f8a8c \\x00000001000000011dfab5d264ff145f49220b2ea101edfe9117b70e408e7fd0b38a5d2d290fc5627d0550fee3ceac54d6601fe331fc3a759da2b239479f43695bc82039bf71de2eba5c7677890e02f251dbb93e96e6b12ce43c51b16116c907447bdfa531e5a39993e5b379f322dfe44c051a50de18260ff5deea012d91b1f9956476a06802e1b5 \\x0000000100010000
-28 3 3 \\x21e8b8b9ddf94cd70fab94731c09991d4718b8fdaeb6cb4a1e0751ce95d6edd84409fbce7b7ca9dd2386ff6205930c257ce9ea59fae04fa61a856db7c606f506 178 \\x00000001000001005c75387f91047a23ee85db70fda4e1edbe1f47fafc6b8ed953b1394df269eb5b5831775b17b911f445ee65617822ef014ee13f5373a81dec9e7dbe6d2800e9e1cf515b6456c5a9ed6fc895744248b351d3789202d6ad356965f836e3334950dfda4a4f920d98f63694c5afeb9a90e29d978659ad14e933aa75e0a39fc7762831 \\xb7648b53984ec1e58390d1170c192b141d80812a9fa43df80f4b7f857f3264eeeabb11f0d1c955790a445dfc3f75f4de57238c7b89d6ae89dde66d7ea8c7e908 \\x00000001000000012f545fcebe894226475e9846d78f10449510c6f7db6cbd1948173be81856685d32b1105c7f42362e7907a9df17fcfc2418f7a44394ac3790856082434a97ac9a52f00960f1143e380dce7f5dbebadc19606dad23f5d68be9b3b863c5e69777119697a42cae70e1b707a76877942cf105163dc0a9c3fe05d1328d6dea695e4c58 \\x0000000100010000
-29 3 4 \\xeabe8ce317fd255c354ca44c7b83a98731913750e248a3d54639d030520f128a1b6585a5ffaa2487d18ce0fe6dd4a24d5f7f5752df22b8a9a1d2a69dadde0907 178 \\x00000001000001000530d095687dd1548d53f3ae234d6e9b7a0a64e8ff48913011ee1f6d31c208f023a37613add440808b46755f3b1ed8fcdd216d48a1c024834731e174c02da1fa4f8f222d0d2fb9199dca555e87e17b8cc2ad4ed2d93d6ca3852da938ed6d07aab1983b8c15dcb2e50cac0a3a093495af54b7daf36c844fbe6ef9c99eafdfabbb \\x27d4eb3d7aa74084c616a58888f45a829b85e40f523bc215723e5bab0f7d3f7a35822eda92680dde7061cb213f8bffbc70ddaa2b05147eb023b826f21259ba6e \\x00000001000000017014f6c1c10a8cc7a3779dbca9da1ad18eaa5a7856363cfe79c0a1a8897042635b89ce3b9c4e5bc73cbba879a8bb9dd1459f819a350ee91e9bd11f945d224e26c6ced88c2ea25ecf18a5a80ce4e1eabedbc736ba597de14dacd5eef023ceee9bd1f6191ff1212b059310b5b0845bc9fe42b33b983b285476bb235000f263b152 \\x0000000100010000
-30 3 5 \\xf0f9e3a6de5ccc4bc999bf42263bf8ca3e6adca0e08fd9cd248be934b9f36cc0becf67189723fbb20e2ea2fc05cc8ccdd12b633d4c0f3937a8a7f7294029940b 178 \\x00000001000001003b48c2d277a5f231ff7057e5f8a25def085b52e98c551285e5df7308581ac39d3439bd0fb528a29879c3ff434fbfe43637e48c74351a515333970f186f48e66be47d09d5eb41819a368eccb90ab0bbd0a07d082461b02da233d92d7fd3c1bbde58d529c62e80078200156b8a309ce28264ebb5760549991a990f507212dfb187 \\x4713689b3980c8d262d421ce9e1acc64b2601321bfbc56d5739eae6e5892094a13e34c86bbb15d2197edb0b3e5e76fc80763899597ee48ace8763dc65024e480 \\x000000010000000133f465487dd9618297f1b9675c8d1393b06c5bb29a7633abc748395e5ab8a14f95099f964784bd1ee52cbee963e5c6291dfc1a04eee7cf06c4054764788238146bc60a706406a6ef9fb20dfeb8aa1fda567c6219f8fa4ef308d3f237f49d5df6719cbb54f21e6c0fb1316200fe1463dda3d260a28fd69cb783cc5f2d2794bdb0 \\x0000000100010000
-31 3 6 \\x43d8d08227ef0cdd67d33491b684a86f5aa6dc3f02f43e21c8dd5ccaa75928b1bf1fb1d00b3859010fedfe20f120f1a1003fec8b511f48f21486507cb037c704 178 \\x000000010000010080ed6fdbf618eca8610376e297ce5ea487d1cc44a395f3fd4821c6979cf81f36e56e6bb217371454f55f9e0c1a0dbff78dd7ef54d6af5977c69608bada7027163c71609497390073143e58208343ad0b40de7c2b491abe7ba6dc6ae219dfea651f94e3f80054dcb17c857037041a0d4cff52d0083860f2ccb5501d057fec1e32 \\xb93fd660e0e17ccc9c8014bdf7561408dcf25c4da796007d5b35121c1ef3866ed3bb05e28e2397e4c0bee634e2697ff3c2cf803bd86daab75f677fb40bdc10a5 \\x000000010000000116e994c4437d8b6de29aa10aa56620cf8a96c31f29018fce1f3ca3c5cc4f5c9e6e43094d71d402499b62fae9eb875c57aa075de3f4cdd340b08d3419be8b9e5848374293edeaeb73a6453a325c15db767a62cb3b838697b3ff889757c9959f2a44e4b47ab2c279e105559bb6fc0e0761eb340fb86ff4af858fc0ca05f5262309 \\x0000000100010000
-32 3 7 \\x86a3cd89f186636bf1d25e043a26ddb2aef6d4784259a196b9ebfe059b2412e0b9d47a11d7801c3e1f48319e8fb2ec8aa1f01afa456aedbe31a99db8be7b660b 178 \\x000000010000010012e137566937560fa639093ef901cec08b40c1c7ece2fec195da529b076d3b7de56ae272964ae80cd1c323d4a7b337068b9dba3fb5251148005966a2fb60a981e982cece17aac49b2f99edbac17deecd4a7139cb06606e99f4528d5fa382d6287f9d3e7919fe4487f6fff8049e7470eb58eb81e83f6baf6e2becf3eb5cf7aab0 \\x186912e27ced8ea99d1b15a2d769b972a3062c6f7b50f3ec6e862786cfe31bfd48682a4ff16db0686480ebcd4b17a31b644957959cc2bb272ba92e33874fc422 \\x000000010000000197b47bec854dab4fa96acb9a1c5088edc3b75bacec980f35872ebec81da0b10fa8955fa23b21b1db3a46bb2a1299a7b0c9eaf444da52536b338fd194fb596f15492f43bdac025a065dbcea1bf57483a02373ce8363af4520f8ab5dcf495bfa980cb7909b28809c51420fab29ab01d5d31d21a82cc362eb6c780caf852497e54a \\x0000000100010000
-33 3 8 \\x6d752eff83e0ad99bbb82e6711cbf317e7edf71674593c862ca2e8e549096e812345b8351114427680d5344c7661813e3541beae0a86868958c64089139a460c 178 \\x00000001000001009afdb46d1eb50230a63161f61994abc0ea2fed64a354d1c7d44705242bb23626e6ff14d2ff2d55ede092f3b4b169bf7a5908265f7b194d15d3bc81d37e3528bcd23f97ba12cb1631ea43dd7ac13fa93aa90f7d2d2bbffbecf342ce825ee4b495c33d09144715c74d9d3bc349d607a5583e556a8ea200b1dd74e1a552254d189b \\x977e6d815c655938d6ec28b63a26be1e306113e7790642976ab39f79db956b6a524cd314860cea6f0e2f60e0af2995905dc5c48e4a86dbb2d5ad163683b488e0 \\x000000010000000114b79909aee52139a271688ebb7a24f9e7aae17eae341d15d4ca49a4f8d17c49b9746532fcf1db5e029fd6f6625f243e65a5ae66795a351b8277c8e564648a5bac5ed1ceb34b966d4855f1f55744efb0601dfb3b5ffc8df55d193d192c8fda8133837dfb851a9254d74a314aa17583fec5fa38679d0716d1bcd1aea29c748f1e \\x0000000100010000
-34 3 9 \\x84db3bdba4f765c24bc0284ecdc832072967868fa5f1fb50f3dc225d9b07f2b16d01eec08684f096c9722679ae767ac40b6a245ce2cf6167b3d27b72af511b0c 374 \\x00000001000001007e81bbe337697d5927002cb03ef64822f52ad82130f110092c4af09bc6775e2c52704343b516fcd222f3a8d083b6ef9253f053054df4e0162c675750388a68ece8794311b2d106546631d687c2844da2348b522aade0372e876edc4951a7c13cd153df6c83f6e20ff95b3b8aac5d2d308f9c990f1646c0b3aae83e970bb3aced \\xdc8124e3ca78cb7488a1d0c20b022ac6bb1de63bf0676414e86c9b139db6a9e0824feac8516cc552ce8c9f2f2f25fe21d99c46b87f6bffc9db40594f52f6cbac \\x0000000100000001f48cedd2357eeee7532ca8f3a27934f6ab88821915459fe08c490f224091747b62442f8dc92a44a0e8c93550eb9e11c9cd0b53395b234219d3a46709c5252ff413f4bccd2633a70968c50e324a0b4c31b0ba897411fc46d55052648ef27d3bbcbe82d97c87a1b055abe8be9f6e87b7bbd655585226ee622bb9a81055fe8f9198 \\x0000000100010000
-35 3 10 \\xa3004d43d9220f9225bc9b9c61cf0e3324a373c8fea10fc6a853d2e4e1113e87d96d04ae940efa5247a60a849ad4bd07f39a2c6b393b5d4eb756a8a530df9507 374 \\x0000000100000100eeb931d329c0f50323563b16ffca3aaa094832f6d484707c18211877bb376df1ddb2417d65f024cdd946624eabdc0454e6bdda6984c8c477b444810dec4c44ce84eb54158ec786d967f7eb94e776b9a7c53a291a755cb3f3e99a74faa4df0e4a7500569455cbc7d1208a035be47a3307aed78094bbacd25632c9937a4090a608 \\xb33a908694e1f8854e9f5214d2a2a928a294e4b1568b46daf6c446d44e1a3de9aadf07bb404c280e9c1f765218c3ae15d792629b794af1dbc318c83e520b16d7 \\x0000000100000001755f3cb86cb75dd455496d891a28f0b8f7448e48552b67bac98662cb7c5e60ce11cf2b461677e39c4dc231e32a26aad8453633a235b2b2285a26c6b169ee7818d39aadec5473ef0927008c868b7e102253ca97e509b9a5a29acdcb54f3898185f4982fdedca69b37a8d468e7562d32c6dedabff5c208d9dfb7e3cb8f6cf002a1 \\x0000000100010000
-36 3 11 \\xd59fb86827174175c838025ff287c3d8ddbb03c56f5b770418d8db31dadb2b957023bd5d21c45a2e5f304cc896d9621378cc849b25e284779708f022ff502a07 374 \\x00000001000001007900305be757cf27957ee199278f6a5404abc8f3722de8d8ea0d161c5b52d6ad5fd47a83ccaa63cebe91bfbf453e5c53e004aedab1b4976a235191f141007647a7c0316404a3f09c7a4dbb79a1f721f65f5f1bf05e6d6d60ce3c768d09862a7d0846c530ef68b97f1b5b98f13c1d062fbc2cfca8c3c63c9957a4e7fb77d8cf81 \\x20fb3fb4e2e46dd703bd91a84b87c0c12646c24e6e6bbc34e4cc8a358150de10bd31e0b1f8850d0e4e4670919354079b7fb2bfa811cb2536acf16408639cfff9 \\x0000000100000001f545bdb63b0fd0f45e5d3031ed196a49ab73894eb39d74dede48607bcce48db7c19cd933a9e278ea075ca54bd2b2f32595c0680d63f502d85794930960855a6ba1e793a44821b760bf6e44195893fa78b1539e5a09c6eb96ac734128e400bee89022704967987511c25291ca6dc8774b4b9f541222178ba6934543d66cdcfd6d \\x0000000100010000
-37 4 0 \\xa752c2d2852e4fa3f853b6a84438100b3b1a7151b644ab97ac0cc48b85a1aa25807074f0cc847a6232799f6cb445a7836965b970a86e7b5c7ccbe6e05b204c0a 48 \\x000000010000010092b1d17e01afdc422eb72001545b9f1c84762837b5ebb5ba99ca0fe7f6a62da1e20153b5be0a0fa681a858c69e210f3150f09cd1557fe552470043e23717321377bb846829e24708fa1a04db884de11020e8e7522014ede689740fb400b9170bc92fa2ad4e3be6a18fcfb30f6912acdc48300c8ba434565f0f34d046d6e72bb3 \\x95ec9858e93ac33511f7d718992bdd8890e867867f89cd79d929e4f9ce81210f6c9557e3e2aae750379cf5d5ba4b8e3be5c31ff2b495d1e2a51690f011bcae7c \\x00000001000000010d4d80c2ed69df0dd73f5f176018a14cb65944b71ac2d30396ce5568c141a5b1ade0154485ea228819baa5fecf11eca4993b3786fce0573c2903a439b9b031b03d393d181f7fa8409c8117bb9c36d1dc36c7aacaf8bb59c9143abd90d44bac7514b8237660f2b830156bc90295286cde44bb3c419cf4ac76788792de8a8f07fd \\x0000000100010000
-38 4 1 \\x28b672b474483fbc31677b7ead92f00d926ac34d093b759749d06c860bec0332028437faef4847e7ef62f174201109167a5a726b9b17d0bf6c4f50d581649501 178 \\x0000000100000100897afe2aa62f4f41c8b025e52afc04d613b4d76a785416ec9eed0b8920ebd0192df3d4bbe6044dd6103554e4b4f30bcf1f122b8dd00af54b6f6d8c4928509caff2c0864787d1d5c2e11f2a767ff231857a7c61e9efd62288fd90fb1f63fd94282294e4d5d867b63919de589b83ea233bf02853cb6c966164992564829d0ec6d0 \\x843e09508b1babb2eb932ee58a87535eda8b2348aa7a623242c59e121b9e486cb6d5547b58a598918ff611bc9a4cbac7a6af7ed648d83cbeffcddc51891291df \\x000000010000000178f38feb0682863dbb88ad86de448d74dd121d0915d93ef22ca8c48e7b1522e504ba54b3905592edc2316b6144c2c99dc69be59af881166b2f721be9d6e113655949714edd4155344bf2fda726acc5cef686b32c60f98b4ac8f8697262e4f5be5d66437164cbafe035171a8102ac2981303177ac9e35e5a61132f24f7a9e953a \\x0000000100010000
-39 4 2 \\xb7108f6a30b8211c27e268f3e4082ad5a24cd843ee19295a6ec04500be45be3508b874b607b112b691bc70c73b02065980672cb23359e214193e5e3eba0fed05 178 \\x00000001000001001e9677ccea4eaaf1f55a4ddbb0e83c597df6aeaa68e53cf5143f05e7ebf79d7faccbb7dccbad60aaa313158ec14f78af249bdb5e7e3ab0d8468ba643424a9c247268b0951a3b854ea912d91ab461cd8d59b5fa99b71c5840b2f988c49c6c5f1297e7968895ad282f4218f9af833584a38b4bc9256e2f5d47de2b708842ebdde9 \\x6b3012d9e4b947c87561e445ddd4fb87dc250b8826437d42b20a783c5af0af9784d35da3378752d79f4018d1949389faaae6e665631d3a2bb7d6ecd98316f2d0 \\x00000001000000014242fc39868d9ef5bcab8c8a7c05564eae98ede36cc02959984fd1802f01dd4102726be8bd14da5fc37296537056c8e4f8c0ad5da837eea414499ed108c30930153dd0cb8fef776ce6240d35335514b9a85c8b54a70c525243b30f63be6e3069433d122f5ad35c9705c4f5bd39bd06df8a7fe5f784bfac6453dd8dd13396e9b7 \\x0000000100010000
-40 4 3 \\x196b541dd1566ce3f856621ff0c7d3dcb2c67cb37c595387cd6af8ce93c8cf67619950e85bcd91b22cc8a21fe19189c45e84c8b8ada5a960aa9df61c16d2da00 178 \\x00000001000001000dbb402991960b79d5a431ff9d8cf0b9b29328606ad4ffcbcdb27b5043688cd9426b8d0e4c9eb9cc6e434ff2728d56f47f15567394a1e6f2fd3fd81d54599ff7692846ea3d8e7ae0b0b79c6d01303fad1907b62079e9dd3be3ff4e63052504b5c9d83f3f6dd5a1896fcc6d89ef388758a46a0c04ed185a21591cb1a67cee3a21 \\xf3b8bfc1f795e9e0419dabd9faa09d4d4bc44b41937ea26ca04aeda45a2822307ea819ddde587923751676a4d14bca1bf67c3a76ba9aab29367b91d97828794c \\x0000000100000001b64fa5f80793bb4beb712b483539f4336fd40089b27a8a528c737fb748e4c67f131415a63ba9d8afbab274fd275338addc97e5c4760d87f31f74f3f7775b035338190c22188617d1a4f53b300ffd7e56f0daa424689aea53680107e24f0811b67a49b9730c28fea8e324e95da030f8c620d5d1ea51660adcda25ad5433b6b7d7 \\x0000000100010000
-41 4 4 \\x7cb4238fc6ef1df30159998043c6beceeab4670d703d7e7e67d14b71b8e334eca8b6671a1da7df988dd3af3142e2a65636640e49764d6fed3be992b657361809 178 \\x00000001000001005fa5965217a01384487a8bbffaa6137c05a3830c9def1ef57428a479214b7d95b35dceaddd2a94637345bf4512112fd54fd12beb1b211c368b26fa9a7c55362ba18eaf65cee138e9a2a1a5bdc3d774b517389dd2c817719638c51bbc6bfc843fd3464d68657d5069a24ff39eab7ae00e95705708fd8350701ec462a7c2c4a0eb \\xd12ec53ec09e3bfe08556f99a8bf847325d323c6f6d4c1e49d26b55a063e1e26c460615a6cd17601ef6730fc92aa5a358c4a314f487d6ae8677f56db527a46fa \\x00000001000000018642612ae5ceac94cd830f278e47036e0892e654205c86e191118e29900b697587189d54497c28f798dc89adf8785fb5cfbe84d94cb2bc9e34e3f319bf988dcb2667ae94e59ed6a784960b6ce4b83e85ddcccc0669df6ced6c0d52c1ffdbbe5f88322cc0b01ff16febaffde2bdaa4afb21fb752a89aa26c081eed5d6e2860e81 \\x0000000100010000
-42 4 5 \\xbf1f39a7a33f6ef800ef0e4dfc92f0002f6914f1743595fa2c3ef43056ff4c2bf6f62421aa2c90236279dab96dd1ba16d286407508a90aef45b86138018a6c06 178 \\x00000001000001008503f1b2fe07debeb20ea72ea956233ae5984c47e9de2df7ca96961db962b38b2a14ce4d00cf6d8f5db150285a02ceb6c5f8a53ab64c67ec706f16ad68535ba3faac0c7420a57ed92ad3f042d17bda7454e45a3e0ef3f488a6796e6df3cbf8ee6875abf97b24957aa8a65d0a0e08e015bd9de50f1328a5c3d04f439d578c38a4 \\x25659370d0f7e8741c386fc9dae228be4146ab52d588f954353cc07af602673e0e2c9aea130ddbcaf94df2ccc9b4dcde306a4bb36631ed20a5fe8b244fc9466d \\x000000010000000164d6e5d7aac658939f187f5b344b84c6183f47b6ddd5b80ccd6f3724a60380669921d7f817bc6d8afefbe419c0e898e741c644d3f09371b676b7333949af5796fbb7e05288a77c92888330c3c39919870db8000aacb571ca984f91839e3309e9e22777be1a4ccf93af18d99822f6e24ee7621d5be1c374cbaee5d15415f8ed4d \\x0000000100010000
-43 4 6 \\xe2b1b8fe388d10f1dc46db9a6a29939741f2a287e62eb0e92b2125d115df5152a127a351d06f0ca5792550c59e8baeb3c2eef73a14acf4f317dc2df529200109 178 \\x0000000100000100528daa565cf9958cf388a9c33dccd7a40c099518d3f21a58ef800d7bf8835cf55c46fbcb4ffb6e6c04f0b6b6ff9b3017a21b5e05f002f200f0ea20778388ae10f785ebee4a4cf4b3a11984f26aef2fd5b1a22b65c9ce4b6e70bcd33dfb45baf17acc0102b461e0d7e39bf1efc1eb4b5ef49e64d75583a1d76e0098fabe652d6c \\x6faf75b145bf8a879374f7893a3a12f9c020849ee523338790cb12b8540078da836da4db6c7152a9646b53aae2df5844aff04c2d0be7e7007d66c59d679a5784 \\x000000010000000198261bb71c35206f3856e6ff89552c8f61b1d2cf7434e6e6e140cfbf9d96d7421a4a8dc205a674d774eec4092be8c1789812548c2b69e476ad121ea696c058b3186563b60f2638bb3cb2636647bfc429556e48fc2ae6e40b21cef1c3d75c199092230c4e760cd3bc6e6a88c1ccdfad6ca564872b609282bfdc1c46c4ef49cb97 \\x0000000100010000
-44 4 7 \\x57e397a60261d10d7a3bbb41d50d12cd9fa63c09fe21e7a56a56b8672231a3a5dccc99fc110500d45d44b1787881f180ccb442135abb85679cdb7e66bc27db06 178 \\x000000010000010076f596fe37520d4cc1b7172a390350d40729b0fbb3019a6e9c3e40dd6b072d2a39ad41f60211db254936de892a938a4830056b9a6b77490c779ffd738fc3bcdb0b063edbdcec516896d41de4ecf5bb0f52839dedd147052a7bf11e080e9901f760b7d73ef2aa9449c8eb2144485e179f70c0776d289fb42fa5be5caa8607e5c0 \\x5b484012196d78f165300b7ee7dac7be25a828bf88c54ee8f2a389de4dbae177504bbfddfcadc60ab12b53d464d9c00efd05e4dc1ded8657c892a3f217f9ec71 \\x000000010000000111c5c49afc9ba2655fe61b7841076ca4255a228513f1343bb6892a6031f4e8a2d7a34d08d781f6b5c7a0870c0fcf07639676517e4b99cfcc242f229a1425991a50050ad709069bc79d17b009b74a93512849e7e46488f8088263adef3c4bf95b468155d7c2be03ef6401d67a9ce9602d3931def1222c72ac0cfaaa5295cc805b \\x0000000100010000
-45 4 8 \\x90ff2e3570bcaa1384a7b513b4e5b115b58c72120711e948470c02c0e42f0859b7e36bc2c6420e8ec309a6bdead8d0ad922eb0c06bdae8cc2173113663460c07 178 \\x0000000100000100a3cfe7be5215491e0690d3ae332197c1386e70fda49dc31365c3db989a708aebc2b1a8e8ab8d19401db530d5c3b55e38d9baaefb95aaa76ca566fdc68812c95ee8f3dc575360a69058115c80acab9883f0affc0dab8cd8745a36be29e6deda48d7ade3d0ac8c1bbe1d278bcde11cb08d89242694c30014ac71c44295c942b930 \\x277635470860b2e793bc1cb0890ce5e82740518ad1b8b923450aca457cdfb60909b5f559ff6a1abb1ae3db9289d46cdb3162626fffaf2f2e71e2203638c67259 \\x000000010000000125e04e415f6d18c371fbafb8de68999d9e62e0daeb5fbe7f012ccc2ddd8bbcb6182c4e889fe5c1e58c8cb27b8d8a8f953f134375779479223db4215866536a9619af37ad92566f9718910e59aa1124e56568f128101b7bbc3a433853e248aef357548ea78bdd4fc49e87ce13181c3183d2daa387d3c21885714e8abf2c4b8e84 \\x0000000100010000
-46 4 9 \\x2a673e2cb58908f7d47b1c8c2dcf0ce282aa69239f782344bf060361f02c525ecd4c22e13f73ea3b79e9af3253c7b415a05081b5e7995cbe29f1bc76d294fd06 374 \\x00000001000001008c9751c6f4a5148fd369fb16ae274a128ca7b4f607c9f86ca3950298e758739ab179d55da7590a2273cfc2d6af207513e2168dff60cdbcbfa5931ee6c09c9f9e7760fdfe92580ef89ce701bb5c842620e68cfb42c389546a5868f2fc613d279fb9955e495808b5961fa0b8d77763ccd60227c817007bb1ff61ae973a91d227d4 \\xb9d959225db080ed72b1002326eb585a6f47db7e46e849d557f289d52edfa6f3f6369241f7e695b71adddb3a0d64ce628d7f2454f66a7b9d3927fab8b26494db \\x0000000100000001f547980db9d79dd56901f532a3f79500d8aae0f71f44f30ac1ca518e9722fcb9d45a3a08c5572eb050ae81adce0ccd42220e7c3204fdb264f59d8f16e78c642e16c170a676c23e5e6920ddd179faa5fde0336dac6eb294788ce036a72029603a0cc7f1c2ec99cd707c94ff493dc111866273186235cf84f5d20478b835a8b569 \\x0000000100010000
-47 4 10 \\x61c72212663be87e819c81a3717c469cb1a46ac484a53bb6f62374ad4d7c6e3df209984e5670315404bbfe7d3c26174150623611eebc640fdb0a160bd7737e06 374 \\x0000000100000100712247ebef606d95285433edff9529de0e12de17cdbabb3c67e230908bb8384312f298dc170cc41d215ffb09858217b7085f7006f0148940a78c8e2a52de6964927b296a82f7d56a6220c0e3f346f44a3cd5ad2bfc563ceb7a188896750160477ab5bcef4a46cbf88b4c167b0c85bdc30eb73464470bd8f0e34a99da2ad8c3cd \\xa773881b04b2679ecfb4246708c036267079d8dce6e02f24d0da48470b7abbfbb57a68515d8612d8e1d9f1088a6935413651aedefad0dd6d40df354b1b08dc04 \\x0000000100000001d28de7f114b657f3ea240f973e31fa693a90b258bdd492fddcd2759340e8c04b6211fd254f4480bd930748a4037834f5d47875d887ffba719ef16b0f81b260a0ed1f7175e50ea532cda270eb17f791314bac10c765694987565357a7ff0bb3536b8e81613e62661f1fea65629ea4317a4a990cb38e7de82bbfe877b47d3d6390 \\x0000000100010000
-48 4 11 \\xccce3ecbb58164afbc9a6da871cf0b0fa218acbdb95997f41dad9d2be38c6e025b40a31d10b6230dc64c3c71e40e589f274fd6eb0b7219d7ec18ed1ac8ce090b 374 \\x0000000100000100b30e965420e2f457cbe2a3e1adfc26dab518d8cc1bb65ae3da65df58dd34c6f478c3ed23a05512dfc90a8bee505c9ea27ae46e27eebd100582b03f0a664684a02475d46bbb0adf622930f147c96b534bbbb73732d05ea0fc7ca4aa4031ca391cf8f3a903b6fdc0c46fceb4e04d72f60d9f38137a7ca3ec99738e835111f10010 \\xcd6ec33b6efd04ce19debe01d37ab43a78ed620a81b637ffed238b85e11f85bd6552a6186430be1ba99517cec4f2076b61d3c33cdade46394b1e6659a156d294 \\x0000000100000001b2a04106dedd9e4619c6c307f2a8f087ca22f0eb226fc1c1d27b63e0af6a7b801c608c6447c21b471a1ecf8dfff38837f5e82179044dbe334841eee39601a27d7cccd29d9bd814bf994c027bf9365c2eeb5283a02526c45e7b3727787f25cc42d6d6e6303dcc4634303cbb6b18eb72385a27156b07081f4a4eedbcf800547bef \\x0000000100010000
-\.
-
-
---
--- Data for Name: refresh_transfer_keys_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_transfer_keys_default (rtc_serial, melt_serial_id, transfer_pub, transfer_privs) FROM stdin;
-1 1 \\x7229049fb28410a2fae30ef73b30a3376067542d870474737e4f1c980b490e46 \\xafa552e0893803649f3b0d697ffcc25c8d7a2878a470790fcda29237488c7b2ce5dcec57024f5f860d816cebab20ee7dc23b4e64e922c7e39e1a0ef77ee5c39f
-2 2 \\x855d7745457bd9d1ad7665a5bec644387935036362a4436b7e12adc573bbbd08 \\xa83a8c10a2d90140be891047a8b453809dd2ec341fb1e2d4cd355e8912d5ad8ea155c1698ad9471522dd4b7325d4e0630560009b1abd9a513596de2a7ebc7db2
-3 3 \\x651ed3a0e2e3af5ad14f93f538670ea27abc6ca01a7144b77878133759214c34 \\xf8a18ed32ad26099721265acdc9742744fa29b033fc6162843164b98abd42cad16804fb25bda53bdef2e2b5ac68a21fe3352823983f2ef77b13da66620f74652
-4 4 \\xa58d196dc16ae44c9befd9a5508b71042d4f0057a0464b28a9bc190eecbb3550 \\xcb2b7c26cd69881a4d2b9dd7e819ffe1ee31d471db66acb3ef5c80678db9a89db14fea7612c948f2f00dea5065bad796243b57c742eb159a03f6b517deed86fe
-\.
-
-
---
--- Data for Name: refunds_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refunds_default (refund_serial_id, coin_pub, deposit_serial_id, merchant_sig, rtransaction_id, amount_with_fee_val, amount_with_fee_frac) FROM stdin;
-1 \\xe577cc9b4807132edb0408b20d74b1b50e6d1ffd4fb6b332a7e5ce5bd7665dbf 2 \\x3c268fc11fdd5bc41c1caa4d34e833486c87e8a95e6837a5b84b4db58d075a1c8120decc69e7f6e130cfbf810d12ecaf52dde67b2aa7cad5f682430e153d7e03 1 6 0
-\.
-
-
---
--- Data for Name: reserves_close_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_close_default (close_uuid, reserve_pub, execution_date, wtid, wire_target_h_payto, amount_val, amount_frac, closing_fee_val, closing_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: reserves_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_default (reserve_uuid, reserve_pub, current_balance_val, current_balance_frac, purses_active, purses_allowed, kyc_required, kyc_passed, max_age, expiration_date, gc_date) FROM stdin;
-1 \\x8e218d5d5d01722ba2c840752ca057016d9ee77f91cc8361dfe93d32e087b879 0 1000000 0 0 f f 120 1658059580000000 1876392383000000
-5 \\x0b59c0a997673be19745b5f617a961e49b69388a8f2f774e15722770943323dd 0 1000000 0 0 f f 120 1658059588000000 1876392390000000
-\.
-
-
---
--- Data for Name: reserves_in_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_in_default (reserve_in_serial_id, reserve_pub, wire_reference, credit_val, credit_frac, wire_source_h_payto, exchange_account_section, execution_date) FROM stdin;
-1 \\x8e218d5d5d01722ba2c840752ca057016d9ee77f91cc8361dfe93d32e087b879 2 10 0 \\x1be0980cd3e088d4b0e7a46d6ece6bf749bcb131fdede29f4822b1856efb5050 exchange-account-1 1655640380000000
-5 \\x0b59c0a997673be19745b5f617a961e49b69388a8f2f774e15722770943323dd 4 18 0 \\x5dcc39674dd6e447dd1de57098e134cc951d0d2f10b23b3583edf607327b574f exchange-account-1 1655640388000000
-\.
-
-
---
--- Data for Name: reserves_out_by_reserve_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_out_by_reserve_default (reserve_uuid, h_blind_ev) FROM stdin;
-1 \\xfc6bc2553f968e66b9e5601eb9942afca52d5e25b3c6a691db4d14db28f48578fc3efdef8fb91244cd75987baeff71cd04718ce820ca070f1565486ec9e9e203
-1 \\x0c453ea1855c481d2441920c3a36d46ba843930b8e732f58b388ec8057df19ec240322ba75356e140722363afbeee73c296e511b4ea4e876dfb49d074f6321f4
-1 \\x5fd075c57e0b0813d12cf909c2c682dfe2151093dca8679f12f8b4e72a0b62db96eb4be075eee34e40dcd6a5cb5be75914de319c53bb469a24cae0bc4372af24
-1 \\xb338c8171efa63ae43830c78dcff7a61b96600aef15bf6d1a91f493d7e3594fefe6acce750e77307edd0a934cc944ec769de8720c5f0bb561a2260a018823b8c
-1 \\xc7fff15c00453fbb8e99bb7df7c2d7b312ac304d17f4fb912e068600b8468ab410e98eb4bdb808727ba5fac4b3fae465349d0c5e25dccbbc32eb48393fcf903a
-1 \\x80c2ae29e872004919244e7275ae595a792402868a62544386ed1a5b0668c7ada90e5a789e5b7eb16bca6aaec612988200f1727bdfbd4e0d866a4f2a12d99c30
-1 \\xa51ffa96a41752c1de52204a880d61352646692e6a647292f0f211a18655b0e28a6f5b2006e8dd1cbfee4c32492beb3460fa951ec705362186a5dc73185d5c40
-1 \\x9c684c092b8a229cd4dd220126fca864d4d00b46e0c721476fc25a4416c1bb76bb271c1017d9e99d878413c414c33e777defbd495c7de6a1a878f4a7e24819bc
-1 \\x25f89e81627d3f6427f6b41c5b06b405d930b4dfc8d69b71bb0726214224cb84aac221d12683d7655a56f52644041088ad20607fab8d90eeac43de11d5783570
-1 \\xfa48df8c82e11e259925936cbb0f7b9aa39b3bdd1fc477b25fb53a5ab0f76c10238d279e44b68dcaaf22432731a5c3e16d1c1ef123351787038a4230f60d7840
-1 \\x68f61d1090cb606cae07a539d6afc4bb62396ea59fdcb069b524c8c11ccc73af9d57c232063b6cdb3f770bf0e51c127f56717680a88c48b58591e1237b40543e
-1 \\xa3caf100ec69148f3275276284ba612d8c37892487bbf65dd976b6b6f218542f6f46be0cd8bf9059c56dc371b5691d19cd1889e2bddf22dc96555ac5f61cf477
-5 \\x75f45bc40f1d2da8ee35963efa67a5051b82abbebd044b79d1d32e71aafa83d7c71cd21152e89a35f238f5764fd5e2d32b71e76890d0da875e4716e3d7c7bf58
-5 \\x4948e408eafb5ee22f338a228ef1ada0779f9cd7c8a3964e5416f9517b934f0dd73db85c485970bbb9617405a0affa0b31ee85bc079a7a1ddfe0f6a9fcb6a15a
-5 \\x93b266c53aa27144eb4e76ba3e940ea28725c169aba62d6a4ee33d2c803a36b582fa13e201c40e66dedede0ee47e453cc3c8afca2bfc9d8bdbba36e75fc3fcc7
-5 \\x3c32bf83d1cc9eb3c1615b618b34c4e015ad7b3c81be5830dc395e0e6514fa242cde76074531be10e36602d5751a606868e548174bbe730a8a7aa51b53287265
-5 \\x5c0760782b196e39215cb555bf50612963fbd1b5ee82c0a7942cc1006210f57f94a561eb97e271aaad28de7971aa4b732b4b3bf86fcd0185cbc2162b579bb164
-5 \\x4f94897ac4be7925bd183ac8ceff2445646620bb547e7c4e023f904bf1bb20131ff1918b9701e53b1b06eff6282130c7dcfcb0e5f79046d3739c219a098c8fd9
-5 \\xcf25428ae38cde94912f9f19826ca4aea790cebc5e5642c7274fdf3a25355065e79a26f090b5d591f69e8a89f03207176eb7c9de0881e327af730c59cbb0220c
-5 \\x05a59555df5d6ba2ab41352e1871ca8c4d290223395153ccd2930b438cdf9012e00c52553c05499804de719f17d85cb6d4bf10d388b66ba93f044d876927bbce
-5 \\x38d18f9a4cba086242daa57f88183f2a85513b5df826462f08503fb845d5e781f5320fc322b3d9a1a6e0c7bd2e6bbbe96124657fb4099c62ee470c4db338bff5
-5 \\xabc5c32a539a00f0a4b8f5eb0acdf40209aab636e8d70d5dc9037ec0187bee586928a919c1bb0d0107b82ad98fa9491916e43826179f498db0f435396578a505
-5 \\xd02142e3ec1c84eea41c1b6faebd7d567640e22f51ab5bc960003ebb5fafdeb62f9f4e8d0cc9a6b1ea7c232b928c5120ca9dcefe0193b69369c5c73b8afbe2c6
-5 \\x042d69e6ec3df3f28545d6dafab2d2f5709e125558821731b983b7bf5e019851e4d0e4c3bd3a4e0b6caa60bac5ac58db86f8cbc1bc8652e7e5ab05395376b95b
-5 \\x96934e398e4b786a44faebe707c2928ed2d39c6565fabf552fa44173ca9c12283da6fbd3ae67a5da638387d82e4655d96d6e80abb70e8459c1e26452bf7b1ce1
-5 \\xb6d2a3c3b38566c6a6cba1ce26e24f9eb91b4baebaada102ef2f2d26b9fb3f32d8a11743008018796b3b59596490d5905d9782a7b2b59f2c1172d1bdbcbb33b7
-\.
-
-
---
--- Data for Name: reserves_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_out_default (reserve_out_serial_id, h_blind_ev, denominations_serial, denom_sig, reserve_uuid, reserve_sig, execution_date, amount_with_fee_val, amount_with_fee_frac) FROM stdin;
-1 \\xfc6bc2553f968e66b9e5601eb9942afca52d5e25b3c6a691db4d14db28f48578fc3efdef8fb91244cd75987baeff71cd04718ce820ca070f1565486ec9e9e203 208 \\x00000001000000010fcd8f507d75b69adc3bfe070b60822112d9bc27d3524dffc9456a756979d6dfd3d831848b16e0e9ac5f54d5be3becc34c307c639f9b3687e06271dbae96b720079a97c0413307cba4f12f8ec94b0af3f852e3697aa867f47e1a24e21b1612965e38273a3a3776e1f8d43d23db1de31fb28551a58a2c761a744ee77754b17c5d 1 \\x05025c7a57de79e879c49d5c18842baeee164b0f337eaf9b0fa60c9969520c4d888dc9f891000fae05b22de1c495cf780e787d4064a842d3e1389894a3e05306 1655640383000000 8 5000000
-2 \\x0c453ea1855c481d2441920c3a36d46ba843930b8e732f58b388ec8057df19ec240322ba75356e140722363afbeee73c296e511b4ea4e876dfb49d074f6321f4 48 \\x00000001000000011a76e632372644605bc307873383802214b5496c822112725d480e58c1442c237885e448d4ec11cf68a79df963475e66ce28360c29d3ee55aee146e7cb8299efa7827db15261991bdd260c042c81be277ada9a398963999b574d305ee170a1da3a389d87f8452c088e454c72131da8cd03653e57ba6a947259ab4f028d30e374 1 \\xfd3dceb686e7362c2bdbbd315471b74c52a1a1a15df168477ad008b0430c1e233ba49dc9bb93b191dff1aec4303956ec058b119fc0c73ffbe1075ab247a0e005 1655640383000000 1 2000000
-3 \\x5fd075c57e0b0813d12cf909c2c682dfe2151093dca8679f12f8b4e72a0b62db96eb4be075eee34e40dcd6a5cb5be75914de319c53bb469a24cae0bc4372af24 178 \\x00000001000000016d5cf6ac32806ef87eeeaa2b3178c6e4e74b806d4a70c9bb084edd5547294f994e91a04a837416fc86ef14fca591ed66fbf85fdec0fe53593cbf33d989248e660144b2a72492f8889000396573c8937f19c3286ce13c4c71b47d5e78310e24736b980f3c533681f399a158566af66dde22452855ce5c15afdb7214a6b1d00495 1 \\x41110120bf7fb7642caece4d66185818d091bea7db397d94b7f4b92d92140815b70e373b08b3980ebe3bab87cf7950082a53e73e62fc28e3c1f86bdc4317860b 1655640383000000 0 11000000
-4 \\xb338c8171efa63ae43830c78dcff7a61b96600aef15bf6d1a91f493d7e3594fefe6acce750e77307edd0a934cc944ec769de8720c5f0bb561a2260a018823b8c 178 \\x00000001000000018c52292d1e3a8f3959c6358f3be0c1c80787ecfe2458298f4b9f74a175a035bf3d16fca9a5d22526d8ac0a14f7dfc00ce7793a532d65a26720ac3c393b9e8293d0c24af58319c8adf6865c945e6cd68eff437eda82e79c1a78eb7dd69f806aa647551a61f583a35bcede3e1c96df2326674c5025133f0b08f8d389932eb7b631 1 \\x2b214a1832b4caf096bab0a1c541c4af2d34deabbf1a30c0cf6880af38eab8cf5d7e95a1bd2fc82eb112a66d10271c1223ac4b8d29f799d9ef3f1df7228b980a 1655640383000000 0 11000000
-5 \\xc7fff15c00453fbb8e99bb7df7c2d7b312ac304d17f4fb912e068600b8468ab410e98eb4bdb808727ba5fac4b3fae465349d0c5e25dccbbc32eb48393fcf903a 178 \\x0000000100000001328b8f9fc397fdc1726d0bd0c49166a880fbdaa2617b8b7e37ce95db6cb771936938ea931ad61a4df9dc9060b7584f095a8510961b5560f1c5a3cde7fb9d23c8fcbd90842c612c72ad7b90633556ccf1ecd897984d19c9ccf439d34aa8a6b50577302a79a2fbdbb436c99c0414d164de18de3b329a0f881a12ac180b556a4cb4 1 \\xed2eea990f14556c5496789ade45019936cb61221fc52a4663ccda3bf87be8c569379ef8c3ab49e996316297b3d2ab30a6001a0ce1887f5c30ea3f44ace80b02 1655640383000000 0 11000000
-6 \\x80c2ae29e872004919244e7275ae595a792402868a62544386ed1a5b0668c7ada90e5a789e5b7eb16bca6aaec612988200f1727bdfbd4e0d866a4f2a12d99c30 178 \\x000000010000000116f316463d7ac2e0f628ccdb9452accf0fe770a4cb22e5df4e439813c09c9757036a681814e5e291990f3b59f3794765ce64baadd66d44c7c4290b9c21df08e60b107e762cfa4aa8ac77d907725321bddf8f54da2b263c3a480f5e743814547f345ec2294df76544ca4ed8fe29bd09f7a134f34b87846cb579b6a40ff424570a 1 \\x18db40d352e59633521b0fc74bf24a953ad1bd2db7d0780189b1cbbf51f4ca9698b800619fec46644c01e713b2c9e92d45c619e033cd6786cfe29546558c1b0a 1655640383000000 0 11000000
-7 \\xa51ffa96a41752c1de52204a880d61352646692e6a647292f0f211a18655b0e28a6f5b2006e8dd1cbfee4c32492beb3460fa951ec705362186a5dc73185d5c40 178 \\x000000010000000101f9d0fd6f1c28f118d52db3b1b66c6156fc86bdc8a5f796a967894302fad9ad26708bacdb95bd35ea6a7ca4fc81aeae6af62e29814a68feaf3850fffe999b69a27af42267ca92227f13d1a165c7e49270323c34078984270f683031f5c8a9cb8213615cce0ce9c27e57d1223aa4c3337e9fe609302720a6bcead297df8f4a1e 1 \\x9ad09fdfd2dff5b17487d173728058108739b78c0983e9ab42d57d76915783c4455b8fef53c0f86da1ab674557b481b52193eadad2c0d03c61154c6c8c09f101 1655640383000000 0 11000000
-8 \\x9c684c092b8a229cd4dd220126fca864d4d00b46e0c721476fc25a4416c1bb76bb271c1017d9e99d878413c414c33e777defbd495c7de6a1a878f4a7e24819bc 178 \\x0000000100000001025663877bbc133477c6dc8bd753573c97dbe1a7218c9f0c1148dddfdc50085292bf65c2f583297824fc586c7f5420119802e4638de89baf5a537316dbbd2c9fbd48e3acfe3ae352a2f5e0a836eb3398f15c9a04a20f0f56a1b929e1d2cbd7982b903c82706629a2fb377ada4a8715de18c05c5d6dcf0b5bea798d3aa4454f5b 1 \\x0452d4d4406fefd54b2abe91437aa8a0ce6a202df69dae8677483b84fdb578e47c268df32374634ad94b45185150b4bc0a508fe992e2fb2cbea9a1a11eaddd02 1655640383000000 0 11000000
-9 \\x25f89e81627d3f6427f6b41c5b06b405d930b4dfc8d69b71bb0726214224cb84aac221d12683d7655a56f52644041088ad20607fab8d90eeac43de11d5783570 178 \\x0000000100000001093b3ffd8cea7461f21ec0596aa130c234c15dd276b911752471b1e7ec6ed6ab2e11f1b300440ced89a937d59cccc48095b058b3a832cddd1e11bc9d966cd554612fd0afa2acc59e154618426a3b0fd044ad5bf29c3b791bff1c622a99e49431de44c7e148ffe8ca4a010e1925c97f29aebb76627c14614a5e6c1447bd4422a5 1 \\x28f81835a1eafdbe85754b211cbbce3292aa80c6e8af28a3b4ab8e09f216e264c04f5cdd0952e4acc479ba28b436b625481caab39abdaacf7e82891a4cc07408 1655640383000000 0 11000000
-10 \\xfa48df8c82e11e259925936cbb0f7b9aa39b3bdd1fc477b25fb53a5ab0f76c10238d279e44b68dcaaf22432731a5c3e16d1c1ef123351787038a4230f60d7840 178 \\x0000000100000001ba82cd27d9ce2de7645cf95f6dd5c36bbe7e26e45a3f3667c45e3ce44603b127859027ae200b04e4ab971927782257c7c8c702a67468ee80ba2bfc11f0cc9ce40134ad45191d1ec61850a97ba27aabe202164411b08320007f5ab46eb247539d657a3f0fef17aba10cb8a89e3e8bc7f0eef480aee2f9460a5c482241d216a16b 1 \\x4c3f91c595d78e43050d7dc82cd387872adccd1ddb035e1f4e8d7ef6f863c87d0810722f45b29420e32ec1f5dab185d37b74f022c55fc01511c0e36b9dbda005 1655640383000000 0 11000000
-11 \\x68f61d1090cb606cae07a539d6afc4bb62396ea59fdcb069b524c8c11ccc73af9d57c232063b6cdb3f770bf0e51c127f56717680a88c48b58591e1237b40543e 374 \\x000000010000000183aefdefcd1684fa9a559083a71e08daec0692437065ceaa92c0a6ab192a6ad4dc3aca4f1376e71d51d7ca679d0bfd2e00a6e235c2d98a09784be2345ad11737fa138a72ef2faaf3ba8c842f451b310eefde77bbe8114426f4a75f50c8280738a911a67d75a8dfb280135a8a9e05a3ffe6aeb1040659ba91df3f8fab17bdad04 1 \\x57bee4fe1e9359f01120891dd9c8d32b61ed220b4b6c941042dfc7becfbf0260b337e467915a15d9fd01a4353d787c5fd07d592ac831e5a1b5bb76986fb0010a 1655640383000000 0 2000000
-12 \\xa3caf100ec69148f3275276284ba612d8c37892487bbf65dd976b6b6f218542f6f46be0cd8bf9059c56dc371b5691d19cd1889e2bddf22dc96555ac5f61cf477 374 \\x0000000100000001314e11d17b7c3653b907d5997b302581dea7545917a026d387ad1fb35c944518a000eebddecfbccd8e0bb29fbf6a5b7725cbdc177a1d86ebbc6c2a17eec6caaff9bbc046faab95b2b8c7adb7160b0c01e1cddd7c1984a5bd25dedcf7368a6b95d31f28f2b7bfd361009ab091d598fd9005a1a00cbc23138677bdfd27bbae6d8f 1 \\x8f980f547c324b2854fb3d9b01ec0d7c6d60a8ee457d8c5100f51206cfb6b0fa2598fc22de4129c9cf1bf05b6c3e29625e54c8809f1cc49ac66f7b5fefc9cb03 1655640383000000 0 2000000
-13 \\x75f45bc40f1d2da8ee35963efa67a5051b82abbebd044b79d1d32e71aafa83d7c71cd21152e89a35f238f5764fd5e2d32b71e76890d0da875e4716e3d7c7bf58 276 \\x000000010000000153a59248727912f14f88eb8deb36e5e8ce04d6d5afec696db57cafd76d02547139076c9ae970cb92d9cc9b90f02a9aca27f0a20f06e5ef6f75f2b68884d4cab7285910e435c2e1a7a891aa2509545ab2021605b66fb4a577a7ea04e2a7027a7e449af5611528c29a1f84422511cd6a8ca9d2eaf00b8324454f1b194f4b0829ed 5 \\x60f232a005dd07cf17213145cc9a0d6983c5794eb92e47ff7ed22b1be7da0312e0792fe49c5e351283ad05df3827160368020311b7a69b49c7aa40cfb070aa01 1655640390000000 10 1000000
-14 \\x4948e408eafb5ee22f338a228ef1ada0779f9cd7c8a3964e5416f9517b934f0dd73db85c485970bbb9617405a0affa0b31ee85bc079a7a1ddfe0f6a9fcb6a15a 248 \\x00000001000000012d7cf42decfdbd7819d3fb93bae53054d489d591ae7934ab62b436b6848d1c4fc993b89b4dad2e1c10727d484672f13772d7c9b35b5ba519d0a2fe025d368db5857504a7716b969dc6b4582d946cca35f2ab6a3ed924d1f28aa82204d26f6934ec898d197f3c90e1b1de7056657803e68b6cf01f51ea8bdb341f24f820591678 5 \\xf8b1e81cf0ec2e2492289d949da6450f1d8762bec2646f22ba5031fcd5cc96c931a8c4f4e1e6fd8b3365032e16178793d4a6b7bdcf69c738547c777a6be7a200 1655640390000000 5 1000000
-15 \\x93b266c53aa27144eb4e76ba3e940ea28725c169aba62d6a4ee33d2c803a36b582fa13e201c40e66dedede0ee47e453cc3c8afca2bfc9d8bdbba36e75fc3fcc7 423 \\x0000000100000001e3cfa010b286fd13a771870145abf0f8212259235d12ce358c16e5605c0d213d0c569299ff202c8d154bbf1562b3196caf2d9160be967f645991b0853a007a580c9e327a9d77f82bf17cf3af9b7db018beebb0a523c40439462cb7bc7464a7f376a3fdaae8b545f8ccdb7407d3e475f2d3346e32669f3a739b60d473cbfbbb 5 \\xa48393c4c7736e0d89365a54af90bd7c2190e29adf75a1b80e069ccba252a01ec1dbdb3c6a64688cfc5a1ce555f88e8124fc3e50883cce77feae006879402105 1655640390000000 2 3000000
-16 \\x3c32bf83d1cc9eb3c1615b618b34c4e015ad7b3c81be5830dc395e0e6514fa242cde76074531be10e36602d5751a606868e548174bbe730a8a7aa51b53287265 178 \\x00000001000000010d227775af11a28a34d570bb572ddc2152b35d052485ce10645c25f23f4d1436f917a651ccd0873803a308f626e4d2c1499957bf8952c689f47c978e87ad6a45805981320e255a02c3c24765a250cdbaa57272e5f6ea7a36aac3d9fb48a52ea6748765a82c8510c06b9b081687e159a45b8ed927369c33dacd8cb31d63e30264 5 \\xc60565ef05326dfb1d3cb2584b2f7ac6ec05c3bf4944abb85b34628baa9e0457cdcafc7a99858e8fb2068c923d7bebc11e0c9f628f52ab2d20c65e496c704b02 1655640390000000 0 11000000
-17 \\x5c0760782b196e39215cb555bf50612963fbd1b5ee82c0a7942cc1006210f57f94a561eb97e271aaad28de7971aa4b732b4b3bf86fcd0185cbc2162b579bb164 178 \\x000000010000000183704dcc7f71f7305b1e7ee06bb60735ab53dfca027fc36addb5b19ba7ceea8b8315aaad69ebf3a5d260f889bea9739c2891704eaae580c6bb0b19848bc0af5fccbbe161f605016d1e145674455a79c82703fa66d30994cfdac116959d4dfcfb467887850600d8aeaadf7a0f52d87876b824545e549246f4e3f9c9f5e9857259 5 \\x36d37b7dae9cdc9326b66fb95c6720456a959c4e82b4ce2a4d9d79d2d1e82f015bc0ef5206d6ca9211ab1f21de1075a65b587f27e289fb11b58dc2da671cc005 1655640390000000 0 11000000
-18 \\x4f94897ac4be7925bd183ac8ceff2445646620bb547e7c4e023f904bf1bb20131ff1918b9701e53b1b06eff6282130c7dcfcb0e5f79046d3739c219a098c8fd9 178 \\x00000001000000010e6991fa9d6dc4f88e2f67f103f6c95bd251bed83c6a045dee08bcdc55bc5c9a613cf5bf99cd91b28644463ad93b10e25823d6d57632542b2ec0c47ee84abcd58116357cd5b044930406e0741d35cc19e66b0bcaf15112ad0bd383be2dd3912b2acdaac0d0916e626f3c9ed2ba4a32b50ac57d60287682ca97ef6b171ec5db46 5 \\x6dc7e73e2a872a6e633d9b4633f61257fbc88563db2abf1205bc97aa04ef50274ae62d795ac1914bd7612c79dace38235a6b2fa3f686baf62bab6e47f6d1bc09 1655640390000000 0 11000000
-19 \\xcf25428ae38cde94912f9f19826ca4aea790cebc5e5642c7274fdf3a25355065e79a26f090b5d591f69e8a89f03207176eb7c9de0881e327af730c59cbb0220c 178 \\x00000001000000011630be5cfce6fbedcfc8b0f952b5b9ea9b544c56327446b3d98d24d31228918babcceebb95ac605f2fc37a3cbf3b1215e02fa4be24dd534d3853a3b294880fbf8daab3c107d87861daf3d7eefd45842d0126f4d4893500ce2e42365096c06071af100eb9bd708fce19b62125f6caa989a49bbe09af115a6672e08e17a8a40610 5 \\x6abacb3113738b10e42e1da6b43617c31aaf686fed5b0e9e92be1b2ff0cffe51ff932cbdefa6e98a8686ee1763326203dd8e2bec9a2c9e3f9b3b1200fe59c802 1655640390000000 0 11000000
-20 \\x05a59555df5d6ba2ab41352e1871ca8c4d290223395153ccd2930b438cdf9012e00c52553c05499804de719f17d85cb6d4bf10d388b66ba93f044d876927bbce 178 \\x000000010000000123a5203ae3fbb0c50b9bcbd0907ecca5ad51a812d62a61461cacaf4e933a687300f6f8ee68c57f2bfc5d411b2e49ce58c200d064de348504523eb57ea351a2c38ddf4e50c85996cffb9e71802f0a054865e801583d443e9bfd7b36f5c8a1921e92f18ecd8ad9f46cbce6b320906502248db498f2074794eff94d71be902edcb9 5 \\xfcd43aa02c0c0de7d54c2b5752f1e9336499178bfe39a01a7bb0072e88dbd4f2c7245688728b5058e86c91d8edbd8b93d61c40bc92b86baf95d0a66985bb4007 1655640390000000 0 11000000
-21 \\x38d18f9a4cba086242daa57f88183f2a85513b5df826462f08503fb845d5e781f5320fc322b3d9a1a6e0c7bd2e6bbbe96124657fb4099c62ee470c4db338bff5 178 \\x000000010000000174d532fe861567a5fadead64332f0da2e1a1eb6abf3825a0a3628eb7c36e6f1ab0b9094791b26088f3302b9e1cd1a2799b3809fe1862714ad98e9514195d1910841620b25568813c400f0d18ffd9bc46ebc50c65db75b9967f43ba9bba6ea3a02de9d76e6b54508204d7cfd59d5f397eb3767ee2f323b62c1893d5477e2794f5 5 \\xb31cbce594f1cda43aacb275352efe8f4f63b648f244d946c68d936cebec60968e5564d0218f49cc009f0551485f8c6ea518bcea56c5b66dd0fff13246e9100f 1655640390000000 0 11000000
-22 \\xabc5c32a539a00f0a4b8f5eb0acdf40209aab636e8d70d5dc9037ec0187bee586928a919c1bb0d0107b82ad98fa9491916e43826179f498db0f435396578a505 178 \\x000000010000000149e1ff1f58615beb30b79c5dc6f729dec4fc65c6d49e10bc39d3a40a365a542a33dbcbffc3d5675ab36992abf5d31f835c1910517227a83beaac515abced74209dacdcbc07e54856832c8235c242efd5b931bd2676f2757dfe617983cd1ee483dde0c7ee2c6b8ffb5a617ad4109461fa202308295ac60e8028ca8b6c3e6ca4a7 5 \\xa10a3ed49fa568352955ced37e9c765db150a881e7498782eb646042cc67ab5357933259deac5e5c2ab7da62d27203101647ac933cdab6f35de1949d53dadf0f 1655640390000000 0 11000000
-23 \\xd02142e3ec1c84eea41c1b6faebd7d567640e22f51ab5bc960003ebb5fafdeb62f9f4e8d0cc9a6b1ea7c232b928c5120ca9dcefe0193b69369c5c73b8afbe2c6 178 \\x00000001000000013afcf0eb7570367bd520da7acbb4ccc558528a305dff31cd6c782e7315468df5b1b731261d148b5c359bc298257e3f2a3c077c8bf31b12bbbb2c4e93bca9f151a51cc5b5a797bc64c0fb362e9b5716ad5417c86d6d4201008f51570f0dec0481cf0db2c4694c83ce91a343a9b39b46c49c616b1ac2686edd79784f2d3d54d76e 5 \\x9531a482a38bd1c1b7c651271043dd0c7e6da493a6ed571f7b9e99f3d2f69a4b11d52d3b839556087d7b4c09906215cde2eec6b4892f69ab8ba5816ee7aec609 1655640390000000 0 11000000
-24 \\x042d69e6ec3df3f28545d6dafab2d2f5709e125558821731b983b7bf5e019851e4d0e4c3bd3a4e0b6caa60bac5ac58db86f8cbc1bc8652e7e5ab05395376b95b 374 \\x0000000100000001d6d67e70f8946dbcd30d933d857f9037e8f7c5b3affc64e1b17b7ab5a7f426a2e456929621c3cc80e062b95e8577c9b5a93b742a95d6cd5ac2a14e5f2c64ed8936ca20de8f8df3d7dd1b4aa45bece94d2041c4b26e358c881c25342b93d61b9ba917d2494114d8a22e0c4eb28063a5570bcc861c32b75ede4809304509d99d6c 5 \\x309734682e342ee38c9a70707edf45d563921cb06f54f4098924d4ea49745c3cedaefbc38f16febc3a6953488c0e04d541a14add18faab50b5bd374de1924a00 1655640390000000 0 2000000
-25 \\x96934e398e4b786a44faebe707c2928ed2d39c6565fabf552fa44173ca9c12283da6fbd3ae67a5da638387d82e4655d96d6e80abb70e8459c1e26452bf7b1ce1 374 \\x0000000100000001efaf539ea0432a215af6f4d8a0483068e75322edbf73331d16a74f0cf7945cf086da8d53804d253e2cf2fdac2a8831dc93f4cabe7bdc1ca427404fd9aeb0c2cbcae9dec0e3e1512b75826f650f83ed792b3d415da5ea93dae330a7a418151df98073da3ce8804ee4eb7a4a95f9ed9470d11fb614af1b1c3e1d2f4548574056fb 5 \\xf33e8a54bafebc0530ebc9bfc2d873c09fcde80ae7fe45547ac642f4edc1892bf4dead7cfe39ce0e26442463b14f00bf33f9d6d85608ed36eafa3f538b6ec701 1655640390000000 0 2000000
-26 \\xb6d2a3c3b38566c6a6cba1ce26e24f9eb91b4baebaada102ef2f2d26b9fb3f32d8a11743008018796b3b59596490d5905d9782a7b2b59f2c1172d1bdbcbb33b7 374 \\x0000000100000001604d779855f380404112809093f4bbbae9e41078d446640a9f107cc5e3956296e548e2862f15ddd10f5c5644413750ca84b024d04cce06e3d80a710fbe787a4e0a2851ebd27315b84347db0f7d7f061f241eec9f5686659c1974ea526de17060aaacfb3f2b1191caf7fc768e3eb249de6faa511fd73f9bf397f74eea0c7a2477 5 \\x3a4241288342b8c679028433a3a64c0e05f07b4c23d410b3783d5f8fd9e7d7031e02db17af4b043046025933574981c0c4fc9de2375945e0210752bf5c7ad609 1655640390000000 0 2000000
-\.
-
-
---
--- Data for Name: revolving_work_shards; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.revolving_work_shards (shard_serial_id, last_attempt, start_row, end_row, active, job_name) FROM stdin;
-\.
-
-
---
--- Data for Name: signkey_revocations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.signkey_revocations (signkey_revocations_serial_id, esk_serial, master_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wad_in_entries_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wad_in_entries_default (wad_in_entry_serial_id, wad_in_serial_id, reserve_pub, purse_pub, h_contract, purse_expiration, merge_timestamp, amount_with_fee_val, amount_with_fee_frac, wad_fee_val, wad_fee_frac, deposit_fees_val, deposit_fees_frac, reserve_sig, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wad_out_entries_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wad_out_entries_default (wad_out_entry_serial_id, wad_out_serial_id, reserve_pub, purse_pub, h_contract, purse_expiration, merge_timestamp, amount_with_fee_val, amount_with_fee_frac, wad_fee_val, wad_fee_frac, deposit_fees_val, deposit_fees_frac, reserve_sig, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wads_in_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wads_in_default (wad_in_serial_id, wad_id, origin_exchange_url, amount_val, amount_frac, arrival_time) FROM stdin;
-\.
-
-
---
--- Data for Name: wads_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wads_out_default (wad_out_serial_id, wad_id, partner_serial_id, amount_val, amount_frac, execution_time) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_accounts (payto_uri, master_sig, is_active, last_change) FROM stdin;
-payto://x-taler-bank/localhost/Exchange \\x0ff7a538a2664e233a108b7aa4beb14d38abdeebbe13443126bb061646fa64af25116b26038b2847bfd178f671ba6dd3346e4c9d392bd29d191728665922300c t 1655640374000000
-\.
-
-
---
--- Data for Name: wire_auditor_account_progress; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_auditor_account_progress (master_pub, account_name, last_wire_reserve_in_serial_id, last_wire_wire_out_serial_id, wire_in_off, wire_out_off) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_auditor_progress; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_auditor_progress (master_pub, last_timestamp, last_reserve_close_uuid) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_fee; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_fee (wire_fee_serial, wire_method, start_date, end_date, wire_fee_val, wire_fee_frac, closing_fee_val, closing_fee_frac, wad_fee_val, wad_fee_frac, master_sig) FROM stdin;
-1 x-taler-bank 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 \\x272066002ec5e5b2ead4170a9725486d79cd121990451d0eed8c37b9f0ccc296960affd10de255286930dac890a321aceb167df1ee8c77b5138773e07a3b8a09
-\.
-
-
---
--- Data for Name: wire_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_out_default (wireout_uuid, execution_date, wtid_raw, wire_target_h_payto, exchange_account_section, amount_val, amount_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_targets_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_targets_default (wire_target_serial_id, wire_target_h_payto, payto_uri, kyc_ok, external_id) FROM stdin;
-1 \\x1be0980cd3e088d4b0e7a46d6ece6bf749bcb131fdede29f4822b1856efb5050 payto://x-taler-bank/localhost/testuser-gk6lkeb2 f \N
-2 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c payto://x-taler-bank/localhost/43 f \N
-3 \\x5dcc39674dd6e447dd1de57098e134cc951d0d2f10b23b3583edf607327b574f payto://x-taler-bank/localhost/testuser-bbpholtl f \N
-\.
-
-
---
--- Data for Name: work_shards; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.work_shards (shard_serial_id, last_attempt, start_row, end_row, completed, job_name) FROM stdin;
-1 0 0 1024 f wirewatch-exchange-account-1
-\.
-
-
---
--- Name: account_merges_account_merge_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.account_merges_account_merge_request_serial_id_seq', 1, false);
-
-
---
--- Name: aggregation_tracking_aggregation_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.aggregation_tracking_aggregation_serial_id_seq', 1, false);
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.app_bankaccount_account_no_seq', 13, true);
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.app_banktransaction_id_seq', 4, true);
-
-
---
--- Name: auditor_denom_sigs_auditor_denom_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditor_denom_sigs_auditor_denom_serial_seq', 424, true);
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditor_reserves_auditor_reserves_rowid_seq', 1, false);
-
-
---
--- Name: auditors_auditor_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditors_auditor_uuid_seq', 1, true);
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_group_id_seq', 1, false);
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_group_permissions_id_seq', 1, false);
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_permission_id_seq', 32, true);
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_groups_id_seq', 1, false);
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_id_seq', 13, true);
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_user_permissions_id_seq', 1, false);
-
-
---
--- Name: close_requests_close_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.close_requests_close_request_serial_id_seq', 1, false);
-
-
---
--- Name: contracts_contract_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.contracts_contract_serial_id_seq', 1, false);
-
-
---
--- Name: cs_nonce_locks_cs_nonce_lock_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.cs_nonce_locks_cs_nonce_lock_serial_id_seq', 1, false);
-
-
---
--- Name: denomination_revocations_denom_revocations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.denomination_revocations_denom_revocations_serial_id_seq', 1, false);
-
-
---
--- Name: denominations_denominations_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.denominations_denominations_serial_seq', 424, true);
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.deposit_confirmations_serial_id_seq', 3, true);
-
-
---
--- Name: deposits_deposit_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.deposits_deposit_serial_id_seq', 3, true);
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.django_content_type_id_seq', 8, true);
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.django_migrations_id_seq', 16, true);
-
-
---
--- Name: exchange_sign_keys_esk_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.exchange_sign_keys_esk_serial_seq', 5, true);
-
-
---
--- Name: extension_details_extension_details_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.extension_details_extension_details_serial_id_seq', 1, false);
-
-
---
--- Name: extensions_extension_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.extensions_extension_id_seq', 1, false);
-
-
---
--- Name: global_fee_global_fee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.global_fee_global_fee_serial_seq', 1, true);
-
-
---
--- Name: history_requests_history_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.history_requests_history_request_serial_id_seq', 1, false);
-
-
---
--- Name: known_coins_known_coin_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.known_coins_known_coin_id_seq', 7, true);
-
-
---
--- Name: merchant_accounts_account_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_accounts_account_serial_seq', 1, true);
-
-
---
--- Name: merchant_deposits_deposit_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_deposits_deposit_serial_seq', 3, true);
-
-
---
--- Name: merchant_exchange_signing_keys_signkey_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_exchange_signing_keys_signkey_serial_seq', 5, true);
-
-
---
--- Name: merchant_exchange_wire_fees_wirefee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_exchange_wire_fees_wirefee_serial_seq', 1, true);
-
-
---
--- Name: merchant_instances_merchant_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_instances_merchant_serial_seq', 1, true);
-
-
---
--- Name: merchant_inventory_product_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_inventory_product_serial_seq', 1, false);
-
-
---
--- Name: merchant_kyc_kyc_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_kyc_kyc_serial_id_seq', 1, true);
-
-
---
--- Name: merchant_orders_order_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_orders_order_serial_seq', 3, true);
-
-
---
--- Name: merchant_refunds_refund_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_refunds_refund_serial_seq', 1, true);
-
-
---
--- Name: merchant_tip_pickups_pickup_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tip_pickups_pickup_serial_seq', 1, false);
-
-
---
--- Name: merchant_tip_reserves_reserve_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tip_reserves_reserve_serial_seq', 1, false);
-
-
---
--- Name: merchant_tips_tip_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tips_tip_serial_seq', 1, false);
-
-
---
--- Name: merchant_transfers_credit_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_transfers_credit_serial_seq', 1, false);
-
-
---
--- Name: partners_partner_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.partners_partner_serial_id_seq', 1, false);
-
-
---
--- Name: prewire_prewire_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.prewire_prewire_uuid_seq', 1, false);
-
-
---
--- Name: purse_deposits_purse_deposit_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_deposits_purse_deposit_serial_id_seq', 1, false);
-
-
---
--- Name: purse_merges_purse_merge_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_merges_purse_merge_request_serial_id_seq', 1, false);
-
-
---
--- Name: purse_refunds_purse_refunds_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_refunds_purse_refunds_serial_id_seq', 1, false);
-
-
---
--- Name: purse_requests_purse_requests_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_requests_purse_requests_serial_id_seq', 1, false);
-
-
---
--- Name: recoup_recoup_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.recoup_recoup_uuid_seq', 1, false);
-
-
---
--- Name: recoup_refresh_recoup_refresh_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.recoup_refresh_recoup_refresh_uuid_seq', 1, false);
-
-
---
--- Name: refresh_commitments_melt_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_commitments_melt_serial_id_seq', 4, true);
-
-
---
--- Name: refresh_revealed_coins_rrc_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_revealed_coins_rrc_serial_seq', 48, true);
-
-
---
--- Name: refresh_transfer_keys_rtc_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_transfer_keys_rtc_serial_seq', 4, true);
-
-
---
--- Name: refunds_refund_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refunds_refund_serial_id_seq', 1, true);
-
-
---
--- Name: reserves_close_close_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_close_close_uuid_seq', 1, false);
-
-
---
--- Name: reserves_in_reserve_in_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_in_reserve_in_serial_id_seq', 11, true);
-
-
---
--- Name: reserves_out_reserve_out_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_out_reserve_out_serial_id_seq', 26, true);
-
-
---
--- Name: reserves_reserve_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_reserve_uuid_seq', 11, true);
-
-
---
--- Name: revolving_work_shards_shard_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.revolving_work_shards_shard_serial_id_seq', 1, false);
-
-
---
--- Name: signkey_revocations_signkey_revocations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.signkey_revocations_signkey_revocations_serial_id_seq', 1, false);
-
-
---
--- Name: wad_in_entries_wad_in_entry_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wad_in_entries_wad_in_entry_serial_id_seq', 1, false);
-
-
---
--- Name: wad_out_entries_wad_out_entry_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wad_out_entries_wad_out_entry_serial_id_seq', 1, false);
-
-
---
--- Name: wads_in_wad_in_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wads_in_wad_in_serial_id_seq', 1, false);
-
-
---
--- Name: wads_out_wad_out_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wads_out_wad_out_serial_id_seq', 1, false);
-
-
---
--- Name: wire_fee_wire_fee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_fee_wire_fee_serial_seq', 1, true);
-
-
---
--- Name: wire_out_wireout_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_out_wireout_uuid_seq', 1, false);
-
-
---
--- Name: wire_targets_wire_target_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_targets_wire_target_serial_id_seq', 5, true);
-
-
---
--- Name: work_shards_shard_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.work_shards_shard_serial_id_seq', 1, true);
-
-
---
--- Name: patches patches_pkey; Type: CONSTRAINT; Schema: _v; Owner: -
---
-
-ALTER TABLE ONLY _v.patches
- ADD CONSTRAINT patches_pkey PRIMARY KEY (patch_name);
-
-
---
--- Name: account_merges_default account_merges_default_account_merge_request_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges_default
- ADD CONSTRAINT account_merges_default_account_merge_request_serial_id_key UNIQUE (account_merge_request_serial_id);
-
-
---
--- Name: account_merges account_merges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges
- ADD CONSTRAINT account_merges_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: account_merges_default account_merges_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges_default
- ADD CONSTRAINT account_merges_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: aggregation_tracking_default aggregation_tracking_default_aggregation_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking_default
- ADD CONSTRAINT aggregation_tracking_default_aggregation_serial_id_key UNIQUE (aggregation_serial_id);
-
-
---
--- Name: aggregation_tracking aggregation_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking
- ADD CONSTRAINT aggregation_tracking_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: aggregation_tracking_default aggregation_tracking_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking_default
- ADD CONSTRAINT aggregation_tracking_default_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: app_bankaccount app_bankaccount_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_pkey PRIMARY KEY (account_no);
-
-
---
--- Name: app_bankaccount app_bankaccount_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_user_id_key UNIQUE (user_id);
-
-
---
--- Name: app_banktransaction app_banktransaction_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_pkey PRIMARY KEY (id);
-
-
---
--- Name: app_banktransaction app_banktransaction_request_uid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_request_uid_key UNIQUE (request_uid);
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawoperation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawoperation_pkey PRIMARY KEY (withdraw_id);
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_auditor_denom_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_auditor_denom_serial_key UNIQUE (auditor_denom_serial);
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_pkey PRIMARY KEY (denominations_serial, auditor_uuid);
-
-
---
--- Name: auditor_denomination_pending auditor_denomination_pending_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denomination_pending
- ADD CONSTRAINT auditor_denomination_pending_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: auditor_exchanges auditor_exchanges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_exchanges
- ADD CONSTRAINT auditor_exchanges_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_historic_denomination_revenue auditor_historic_denomination_revenue_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_denomination_revenue
- ADD CONSTRAINT auditor_historic_denomination_revenue_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: auditor_progress_aggregation auditor_progress_aggregation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_aggregation
- ADD CONSTRAINT auditor_progress_aggregation_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_coin auditor_progress_coin_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_coin
- ADD CONSTRAINT auditor_progress_coin_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_deposit_confirmation auditor_progress_deposit_confirmation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_deposit_confirmation
- ADD CONSTRAINT auditor_progress_deposit_confirmation_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_reserve auditor_progress_reserve_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_reserve
- ADD CONSTRAINT auditor_progress_reserve_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_reserves auditor_reserves_auditor_reserves_rowid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves
- ADD CONSTRAINT auditor_reserves_auditor_reserves_rowid_key UNIQUE (auditor_reserves_rowid);
-
-
---
--- Name: auditors auditors_auditor_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditors
- ADD CONSTRAINT auditors_auditor_uuid_key UNIQUE (auditor_uuid);
-
-
---
--- Name: auditors auditors_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditors
- ADD CONSTRAINT auditors_pkey PRIMARY KEY (auditor_pub);
-
-
---
--- Name: auth_group auth_group_name_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group
- ADD CONSTRAINT auth_group_name_key UNIQUE (name);
-
-
---
--- Name: auth_group_permissions auth_group_permissions_group_id_permission_id_0cd325b0_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_group_id_permission_id_0cd325b0_uniq UNIQUE (group_id, permission_id);
-
-
---
--- Name: auth_group_permissions auth_group_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_group auth_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group
- ADD CONSTRAINT auth_group_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_permission auth_permission_content_type_id_codename_01ab375a_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_content_type_id_codename_01ab375a_uniq UNIQUE (content_type_id, codename);
-
-
---
--- Name: auth_permission auth_permission_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_groups auth_user_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_groups auth_user_groups_user_id_group_id_94350c0c_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_user_id_group_id_94350c0c_uniq UNIQUE (user_id, group_id);
-
-
---
--- Name: auth_user auth_user_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user
- ADD CONSTRAINT auth_user_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_user_id_permission_id_14a6b632_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_user_id_permission_id_14a6b632_uniq UNIQUE (user_id, permission_id);
-
-
---
--- Name: auth_user auth_user_username_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user
- ADD CONSTRAINT auth_user_username_key UNIQUE (username);
-
-
---
--- Name: close_requests close_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.close_requests
- ADD CONSTRAINT close_requests_pkey PRIMARY KEY (reserve_pub, close_timestamp);
-
-
---
--- Name: close_requests_default close_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.close_requests_default
- ADD CONSTRAINT close_requests_default_pkey PRIMARY KEY (reserve_pub, close_timestamp);
-
-
---
--- Name: contracts_default contracts_default_contract_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts_default
- ADD CONSTRAINT contracts_default_contract_serial_id_key UNIQUE (contract_serial_id);
-
-
---
--- Name: contracts contracts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts
- ADD CONSTRAINT contracts_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: contracts_default contracts_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts_default
- ADD CONSTRAINT contracts_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: cs_nonce_locks_default cs_nonce_locks_default_cs_nonce_lock_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks_default
- ADD CONSTRAINT cs_nonce_locks_default_cs_nonce_lock_serial_id_key UNIQUE (cs_nonce_lock_serial_id);
-
-
---
--- Name: cs_nonce_locks cs_nonce_locks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks
- ADD CONSTRAINT cs_nonce_locks_pkey PRIMARY KEY (nonce);
-
-
---
--- Name: cs_nonce_locks_default cs_nonce_locks_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks_default
- ADD CONSTRAINT cs_nonce_locks_default_pkey PRIMARY KEY (nonce);
-
-
---
--- Name: denomination_revocations denomination_revocations_denom_revocations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_denom_revocations_serial_id_key UNIQUE (denom_revocations_serial_id);
-
-
---
--- Name: denomination_revocations denomination_revocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_pkey PRIMARY KEY (denominations_serial);
-
-
---
--- Name: denominations denominations_denominations_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denominations
- ADD CONSTRAINT denominations_denominations_serial_key UNIQUE (denominations_serial);
-
-
---
--- Name: denominations denominations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denominations
- ADD CONSTRAINT denominations_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: deposit_confirmations deposit_confirmations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT deposit_confirmations_pkey PRIMARY KEY (h_contract_terms, h_wire, coin_pub, merchant_pub, exchange_sig, exchange_pub, master_sig);
-
-
---
--- Name: deposit_confirmations deposit_confirmations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT deposit_confirmations_serial_id_key UNIQUE (serial_id);
-
-
---
--- Name: deposits_default deposits_default_coin_pub_merchant_pub_h_contract_terms_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposits_default
- ADD CONSTRAINT deposits_default_coin_pub_merchant_pub_h_contract_terms_key UNIQUE (coin_pub, merchant_pub, h_contract_terms);
-
-
---
--- Name: deposits_default deposits_default_deposit_serial_id_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposits_default
- ADD CONSTRAINT deposits_default_deposit_serial_id_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: django_content_type django_content_type_app_label_model_76bd3d3b_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type
- ADD CONSTRAINT django_content_type_app_label_model_76bd3d3b_uniq UNIQUE (app_label, model);
-
-
---
--- Name: django_content_type django_content_type_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type
- ADD CONSTRAINT django_content_type_pkey PRIMARY KEY (id);
-
-
---
--- Name: django_migrations django_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_migrations
- ADD CONSTRAINT django_migrations_pkey PRIMARY KEY (id);
-
-
---
--- Name: django_session django_session_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_session
- ADD CONSTRAINT django_session_pkey PRIMARY KEY (session_key);
-
-
---
--- Name: exchange_sign_keys exchange_sign_keys_esk_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.exchange_sign_keys
- ADD CONSTRAINT exchange_sign_keys_esk_serial_key UNIQUE (esk_serial);
-
-
---
--- Name: exchange_sign_keys exchange_sign_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.exchange_sign_keys
- ADD CONSTRAINT exchange_sign_keys_pkey PRIMARY KEY (exchange_pub);
-
-
---
--- Name: extension_details extension_details_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extension_details
- ADD CONSTRAINT extension_details_pkey PRIMARY KEY (extension_details_serial_id);
-
-
---
--- Name: extension_details_default extension_details_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extension_details_default
- ADD CONSTRAINT extension_details_default_pkey PRIMARY KEY (extension_details_serial_id);
-
-
---
--- Name: extensions extensions_extension_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extensions
- ADD CONSTRAINT extensions_extension_id_key UNIQUE (extension_id);
-
-
---
--- Name: extensions extensions_name_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extensions
- ADD CONSTRAINT extensions_name_key UNIQUE (name);
-
-
---
--- Name: global_fee global_fee_global_fee_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.global_fee
- ADD CONSTRAINT global_fee_global_fee_serial_key UNIQUE (global_fee_serial);
-
-
---
--- Name: global_fee global_fee_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.global_fee
- ADD CONSTRAINT global_fee_pkey PRIMARY KEY (start_date);
-
-
---
--- Name: history_requests history_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.history_requests
- ADD CONSTRAINT history_requests_pkey PRIMARY KEY (reserve_pub, request_timestamp);
-
-
---
--- Name: history_requests_default history_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.history_requests_default
- ADD CONSTRAINT history_requests_default_pkey PRIMARY KEY (reserve_pub, request_timestamp);
-
-
---
--- Name: known_coins_default known_coins_default_known_coin_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins_default
- ADD CONSTRAINT known_coins_default_known_coin_id_key UNIQUE (known_coin_id);
-
-
---
--- Name: known_coins known_coins_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins
- ADD CONSTRAINT known_coins_pkey PRIMARY KEY (coin_pub);
-
-
---
--- Name: known_coins_default known_coins_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins_default
- ADD CONSTRAINT known_coins_default_pkey PRIMARY KEY (coin_pub);
-
-
---
--- Name: merchant_accounts merchant_accounts_h_wire_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_h_wire_key UNIQUE (h_wire);
-
-
---
--- Name: merchant_accounts merchant_accounts_merchant_serial_payto_uri_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_merchant_serial_payto_uri_key UNIQUE (merchant_serial, payto_uri);
-
-
---
--- Name: merchant_accounts merchant_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_pkey PRIMARY KEY (account_serial);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_h_contract_terms_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_h_contract_terms_key UNIQUE (merchant_serial, h_contract_terms);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_order_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_order_id_key UNIQUE (merchant_serial, order_id);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_pkey PRIMARY KEY (order_serial);
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_deposit_serial_credit_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_deposit_serial_credit_serial_key UNIQUE (deposit_serial, credit_serial);
-
-
---
--- Name: merchant_deposits merchant_deposits_order_serial_coin_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_order_serial_coin_pub_key UNIQUE (order_serial, coin_pub);
-
-
---
--- Name: merchant_deposits merchant_deposits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_pkey PRIMARY KEY (deposit_serial);
-
-
---
--- Name: merchant_exchange_signing_keys merchant_exchange_signing_key_exchange_pub_start_date_maste_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_signing_keys
- ADD CONSTRAINT merchant_exchange_signing_key_exchange_pub_start_date_maste_key UNIQUE (exchange_pub, start_date, master_pub);
-
-
---
--- Name: merchant_exchange_signing_keys merchant_exchange_signing_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_signing_keys
- ADD CONSTRAINT merchant_exchange_signing_keys_pkey PRIMARY KEY (signkey_serial);
-
-
---
--- Name: merchant_exchange_wire_fees merchant_exchange_wire_fees_master_pub_h_wire_method_start__key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_wire_fees
- ADD CONSTRAINT merchant_exchange_wire_fees_master_pub_h_wire_method_start__key UNIQUE (master_pub, h_wire_method, start_date);
-
-
---
--- Name: merchant_exchange_wire_fees merchant_exchange_wire_fees_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_wire_fees
- ADD CONSTRAINT merchant_exchange_wire_fees_pkey PRIMARY KEY (wirefee_serial);
-
-
---
--- Name: merchant_instances merchant_instances_merchant_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_merchant_id_key UNIQUE (merchant_id);
-
-
---
--- Name: merchant_instances merchant_instances_merchant_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_merchant_pub_key UNIQUE (merchant_pub);
-
-
---
--- Name: merchant_instances merchant_instances_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_pkey PRIMARY KEY (merchant_serial);
-
-
---
--- Name: merchant_inventory merchant_inventory_merchant_serial_product_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_merchant_serial_product_id_key UNIQUE (merchant_serial, product_id);
-
-
---
--- Name: merchant_inventory merchant_inventory_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_pkey PRIMARY KEY (product_serial);
-
-
---
--- Name: merchant_keys merchant_keys_merchant_priv_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_merchant_priv_key UNIQUE (merchant_priv);
-
-
---
--- Name: merchant_keys merchant_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_pkey PRIMARY KEY (merchant_serial);
-
-
---
--- Name: merchant_kyc merchant_kyc_kyc_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_kyc_serial_id_key UNIQUE (kyc_serial_id);
-
-
---
--- Name: merchant_kyc merchant_kyc_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_pkey PRIMARY KEY (account_serial, exchange_url);
-
-
---
--- Name: merchant_orders merchant_orders_merchant_serial_order_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_merchant_serial_order_id_key UNIQUE (merchant_serial, order_id);
-
-
---
--- Name: merchant_orders merchant_orders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_pkey PRIMARY KEY (order_serial);
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_pkey PRIMARY KEY (refund_serial);
-
-
---
--- Name: merchant_refunds merchant_refunds_order_serial_coin_pub_rtransaction_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_order_serial_coin_pub_rtransaction_id_key UNIQUE (order_serial, coin_pub, rtransaction_id);
-
-
---
--- Name: merchant_refunds merchant_refunds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_pkey PRIMARY KEY (refund_serial);
-
-
---
--- Name: merchant_tip_pickup_signatures merchant_tip_pickup_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickup_signatures
- ADD CONSTRAINT merchant_tip_pickup_signatures_pkey PRIMARY KEY (pickup_serial, coin_offset);
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_pickup_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_pickup_id_key UNIQUE (pickup_id);
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_pkey PRIMARY KEY (pickup_serial);
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_priv_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_priv_key UNIQUE (reserve_priv);
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_serial_key UNIQUE (reserve_serial);
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_pkey PRIMARY KEY (reserve_serial);
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_reserve_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_reserve_pub_key UNIQUE (reserve_pub);
-
-
---
--- Name: merchant_tips merchant_tips_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_pkey PRIMARY KEY (tip_serial);
-
-
---
--- Name: merchant_tips merchant_tips_tip_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_tip_id_key UNIQUE (tip_id);
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_pkey PRIMARY KEY (credit_serial);
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_deposit_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_deposit_serial_key UNIQUE (deposit_serial);
-
-
---
--- Name: merchant_transfers merchant_transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_pkey PRIMARY KEY (credit_serial);
-
-
---
--- Name: merchant_transfers merchant_transfers_wtid_exchange_url_account_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_wtid_exchange_url_account_serial_key UNIQUE (wtid, exchange_url, account_serial);
-
-
---
--- Name: partner_accounts partner_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partner_accounts
- ADD CONSTRAINT partner_accounts_pkey PRIMARY KEY (payto_uri);
-
-
---
--- Name: partners partners_partner_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partners
- ADD CONSTRAINT partners_partner_serial_id_key UNIQUE (partner_serial_id);
-
-
---
--- Name: prewire prewire_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.prewire
- ADD CONSTRAINT prewire_pkey PRIMARY KEY (prewire_uuid);
-
-
---
--- Name: prewire_default prewire_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.prewire_default
- ADD CONSTRAINT prewire_default_pkey PRIMARY KEY (prewire_uuid);
-
-
---
--- Name: purse_actions purse_actions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_actions
- ADD CONSTRAINT purse_actions_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_deposits purse_deposits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits
- ADD CONSTRAINT purse_deposits_pkey PRIMARY KEY (purse_pub, coin_pub);
-
-
---
--- Name: purse_deposits_default purse_deposits_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits_default
- ADD CONSTRAINT purse_deposits_default_pkey PRIMARY KEY (purse_pub, coin_pub);
-
-
---
--- Name: purse_deposits_default purse_deposits_default_purse_deposit_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits_default
- ADD CONSTRAINT purse_deposits_default_purse_deposit_serial_id_key UNIQUE (purse_deposit_serial_id);
-
-
---
--- Name: purse_merges purse_merges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges
- ADD CONSTRAINT purse_merges_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_merges_default purse_merges_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges_default
- ADD CONSTRAINT purse_merges_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_merges_default purse_merges_default_purse_merge_request_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges_default
- ADD CONSTRAINT purse_merges_default_purse_merge_request_serial_id_key UNIQUE (purse_merge_request_serial_id);
-
-
---
--- Name: purse_refunds purse_refunds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds
- ADD CONSTRAINT purse_refunds_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_refunds_default purse_refunds_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds_default
- ADD CONSTRAINT purse_refunds_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_refunds_default purse_refunds_default_purse_refunds_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds_default
- ADD CONSTRAINT purse_refunds_default_purse_refunds_serial_id_key UNIQUE (purse_refunds_serial_id);
-
-
---
--- Name: purse_requests purse_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests
- ADD CONSTRAINT purse_requests_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_requests_default purse_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests_default
- ADD CONSTRAINT purse_requests_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_requests_default purse_requests_default_purse_requests_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests_default
- ADD CONSTRAINT purse_requests_default_purse_requests_serial_id_key UNIQUE (purse_requests_serial_id);
-
-
---
--- Name: recoup_default recoup_default_recoup_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.recoup_default
- ADD CONSTRAINT recoup_default_recoup_uuid_key UNIQUE (recoup_uuid);
-
-
---
--- Name: recoup_refresh_default recoup_refresh_default_recoup_refresh_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.recoup_refresh_default
- ADD CONSTRAINT recoup_refresh_default_recoup_refresh_uuid_key UNIQUE (recoup_refresh_uuid);
-
-
---
--- Name: refresh_commitments_default refresh_commitments_default_melt_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments_default
- ADD CONSTRAINT refresh_commitments_default_melt_serial_id_key UNIQUE (melt_serial_id);
-
-
---
--- Name: refresh_commitments refresh_commitments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments
- ADD CONSTRAINT refresh_commitments_pkey PRIMARY KEY (rc);
-
-
---
--- Name: refresh_commitments_default refresh_commitments_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments_default
- ADD CONSTRAINT refresh_commitments_default_pkey PRIMARY KEY (rc);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_coin_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_coin_ev_key UNIQUE (coin_ev);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_h_coin_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_h_coin_ev_key UNIQUE (h_coin_ev);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_pkey PRIMARY KEY (melt_serial_id, freshcoin_index);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_rrc_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_rrc_serial_key UNIQUE (rrc_serial);
-
-
---
--- Name: refresh_transfer_keys refresh_transfer_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys
- ADD CONSTRAINT refresh_transfer_keys_pkey PRIMARY KEY (melt_serial_id);
-
-
---
--- Name: refresh_transfer_keys_default refresh_transfer_keys_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys_default
- ADD CONSTRAINT refresh_transfer_keys_default_pkey PRIMARY KEY (melt_serial_id);
-
-
---
--- Name: refresh_transfer_keys_default refresh_transfer_keys_default_rtc_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys_default
- ADD CONSTRAINT refresh_transfer_keys_default_rtc_serial_key UNIQUE (rtc_serial);
-
-
---
--- Name: refunds_default refunds_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refunds_default
- ADD CONSTRAINT refunds_default_pkey PRIMARY KEY (deposit_serial_id, rtransaction_id);
-
-
---
--- Name: refunds_default refunds_default_refund_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refunds_default
- ADD CONSTRAINT refunds_default_refund_serial_id_key UNIQUE (refund_serial_id);
-
-
---
--- Name: reserves_close_default reserves_close_default_close_uuid_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_close_default
- ADD CONSTRAINT reserves_close_default_close_uuid_pkey PRIMARY KEY (close_uuid);
-
-
---
--- Name: reserves reserves_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves
- ADD CONSTRAINT reserves_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_default reserves_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_default
- ADD CONSTRAINT reserves_default_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in reserves_in_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in
- ADD CONSTRAINT reserves_in_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in_default reserves_in_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in_default
- ADD CONSTRAINT reserves_in_default_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in_default reserves_in_default_reserve_in_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in_default
- ADD CONSTRAINT reserves_in_default_reserve_in_serial_id_key UNIQUE (reserve_in_serial_id);
-
-
---
--- Name: reserves_out reserves_out_h_blind_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out
- ADD CONSTRAINT reserves_out_h_blind_ev_key UNIQUE (h_blind_ev);
-
-
---
--- Name: reserves_out_default reserves_out_default_h_blind_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out_default
- ADD CONSTRAINT reserves_out_default_h_blind_ev_key UNIQUE (h_blind_ev);
-
-
---
--- Name: reserves_out_default reserves_out_default_reserve_out_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out_default
- ADD CONSTRAINT reserves_out_default_reserve_out_serial_id_key UNIQUE (reserve_out_serial_id);
-
-
---
--- Name: revolving_work_shards revolving_work_shards_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.revolving_work_shards
- ADD CONSTRAINT revolving_work_shards_pkey PRIMARY KEY (job_name, start_row);
-
-
---
--- Name: revolving_work_shards revolving_work_shards_shard_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.revolving_work_shards
- ADD CONSTRAINT revolving_work_shards_shard_serial_id_key UNIQUE (shard_serial_id);
-
-
---
--- Name: signkey_revocations signkey_revocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_pkey PRIMARY KEY (esk_serial);
-
-
---
--- Name: signkey_revocations signkey_revocations_signkey_revocations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_signkey_revocations_serial_id_key UNIQUE (signkey_revocations_serial_id);
-
-
---
--- Name: wad_in_entries wad_in_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries
- ADD CONSTRAINT wad_in_entries_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_in_entries_default wad_in_entries_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries_default
- ADD CONSTRAINT wad_in_entries_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_in_entries_default wad_in_entries_default_wad_in_entry_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries_default
- ADD CONSTRAINT wad_in_entries_default_wad_in_entry_serial_id_key UNIQUE (wad_in_entry_serial_id);
-
-
---
--- Name: wad_out_entries wad_out_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries
- ADD CONSTRAINT wad_out_entries_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_out_entries_default wad_out_entries_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries_default
- ADD CONSTRAINT wad_out_entries_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_out_entries_default wad_out_entries_default_wad_out_entry_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries_default
- ADD CONSTRAINT wad_out_entries_default_wad_out_entry_serial_id_key UNIQUE (wad_out_entry_serial_id);
-
-
---
--- Name: wads_in wads_in_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in
- ADD CONSTRAINT wads_in_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_in_default wads_in_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_in wads_in_wad_id_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in
- ADD CONSTRAINT wads_in_wad_id_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_in_default wads_in_default_wad_id_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_id_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_in_default wads_in_default_wad_in_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_in_serial_id_key UNIQUE (wad_in_serial_id);
-
-
---
--- Name: wads_in_default wads_in_default_wad_is_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_is_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_out wads_out_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out
- ADD CONSTRAINT wads_out_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_out_default wads_out_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out_default
- ADD CONSTRAINT wads_out_default_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_out_default wads_out_default_wad_out_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out_default
- ADD CONSTRAINT wads_out_default_wad_out_serial_id_key UNIQUE (wad_out_serial_id);
-
-
---
--- Name: wire_accounts wire_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_accounts
- ADD CONSTRAINT wire_accounts_pkey PRIMARY KEY (payto_uri);
-
-
---
--- Name: wire_auditor_account_progress wire_auditor_account_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_account_progress
- ADD CONSTRAINT wire_auditor_account_progress_pkey PRIMARY KEY (master_pub, account_name);
-
-
---
--- Name: wire_auditor_progress wire_auditor_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_progress
- ADD CONSTRAINT wire_auditor_progress_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: wire_fee wire_fee_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_fee
- ADD CONSTRAINT wire_fee_pkey PRIMARY KEY (wire_method, start_date);
-
-
---
--- Name: wire_fee wire_fee_wire_fee_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_fee
- ADD CONSTRAINT wire_fee_wire_fee_serial_key UNIQUE (wire_fee_serial);
-
-
---
--- Name: wire_out_default wire_out_default_wireout_uuid_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out_default
- ADD CONSTRAINT wire_out_default_wireout_uuid_pkey PRIMARY KEY (wireout_uuid);
-
-
---
--- Name: wire_out wire_out_wtid_raw_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out
- ADD CONSTRAINT wire_out_wtid_raw_key UNIQUE (wtid_raw);
-
-
---
--- Name: wire_out_default wire_out_default_wtid_raw_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out_default
- ADD CONSTRAINT wire_out_default_wtid_raw_key UNIQUE (wtid_raw);
-
-
---
--- Name: wire_targets wire_targets_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets
- ADD CONSTRAINT wire_targets_pkey PRIMARY KEY (wire_target_h_payto);
-
-
---
--- Name: wire_targets_default wire_targets_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets_default
- ADD CONSTRAINT wire_targets_default_pkey PRIMARY KEY (wire_target_h_payto);
-
-
---
--- Name: wire_targets_default wire_targets_default_wire_target_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets_default
- ADD CONSTRAINT wire_targets_default_wire_target_serial_id_key UNIQUE (wire_target_serial_id);
-
-
---
--- Name: work_shards work_shards_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.work_shards
- ADD CONSTRAINT work_shards_pkey PRIMARY KEY (job_name, start_row);
-
-
---
--- Name: work_shards work_shards_shard_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.work_shards
- ADD CONSTRAINT work_shards_shard_serial_id_key UNIQUE (shard_serial_id);
-
-
---
--- Name: account_merges_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX account_merges_by_reserve_pub ON ONLY public.account_merges USING btree (reserve_pub);
-
-
---
--- Name: account_merges_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX account_merges_default_reserve_pub_idx ON public.account_merges_default USING btree (reserve_pub);
-
-
---
--- Name: aggregation_tracking_by_wtid_raw_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX aggregation_tracking_by_wtid_raw_index ON ONLY public.aggregation_tracking USING btree (wtid_raw);
-
-
---
--- Name: INDEX aggregation_tracking_by_wtid_raw_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.aggregation_tracking_by_wtid_raw_index IS 'for lookup_transactions';
-
-
---
--- Name: aggregation_tracking_default_wtid_raw_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX aggregation_tracking_default_wtid_raw_idx ON public.aggregation_tracking_default USING btree (wtid_raw);
-
-
---
--- Name: app_banktransaction_credit_account_id_a8ba05ac; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_credit_account_id_a8ba05ac ON public.app_banktransaction USING btree (credit_account_id);
-
-
---
--- Name: app_banktransaction_date_f72bcad6; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_date_f72bcad6 ON public.app_banktransaction USING btree (date);
-
-
---
--- Name: app_banktransaction_debit_account_id_5b1f7528; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_debit_account_id_5b1f7528 ON public.app_banktransaction USING btree (debit_account_id);
-
-
---
--- Name: app_banktransaction_request_uid_b7d06af5_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_request_uid_b7d06af5_like ON public.app_banktransaction USING btree (request_uid varchar_pattern_ops);
-
-
---
--- Name: app_talerwithdrawoperation_selected_exchange_account__6c8b96cf; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_talerwithdrawoperation_selected_exchange_account__6c8b96cf ON public.app_talerwithdrawoperation USING btree (selected_exchange_account_id);
-
-
---
--- Name: app_talerwithdrawoperation_withdraw_account_id_992dc5b3; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_talerwithdrawoperation_withdraw_account_id_992dc5b3 ON public.app_talerwithdrawoperation USING btree (withdraw_account_id);
-
-
---
--- Name: auditor_historic_reserve_summary_by_master_pub_start_date; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date ON public.auditor_historic_reserve_summary USING btree (master_pub, start_date);
-
-
---
--- Name: auditor_reserves_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auditor_reserves_by_reserve_pub ON public.auditor_reserves USING btree (reserve_pub);
-
-
---
--- Name: auth_group_name_a6ea08ec_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_name_a6ea08ec_like ON public.auth_group USING btree (name varchar_pattern_ops);
-
-
---
--- Name: auth_group_permissions_group_id_b120cbf9; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_permissions_group_id_b120cbf9 ON public.auth_group_permissions USING btree (group_id);
-
-
---
--- Name: auth_group_permissions_permission_id_84c5c92e; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_permissions_permission_id_84c5c92e ON public.auth_group_permissions USING btree (permission_id);
-
-
---
--- Name: auth_permission_content_type_id_2f476e4b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_permission_content_type_id_2f476e4b ON public.auth_permission USING btree (content_type_id);
-
-
---
--- Name: auth_user_groups_group_id_97559544; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_groups_group_id_97559544 ON public.auth_user_groups USING btree (group_id);
-
-
---
--- Name: auth_user_groups_user_id_6a12ed8b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_groups_user_id_6a12ed8b ON public.auth_user_groups USING btree (user_id);
-
-
---
--- Name: auth_user_user_permissions_permission_id_1fbb5f2c; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_user_permissions_permission_id_1fbb5f2c ON public.auth_user_user_permissions USING btree (permission_id);
-
-
---
--- Name: auth_user_user_permissions_user_id_a95ead1b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_user_permissions_user_id_a95ead1b ON public.auth_user_user_permissions USING btree (user_id);
-
-
---
--- Name: auth_user_username_6821ab7c_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_username_6821ab7c_like ON public.auth_user USING btree (username varchar_pattern_ops);
-
-
---
--- Name: denominations_by_expire_legal_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX denominations_by_expire_legal_index ON public.denominations USING btree (expire_legal);
-
-
---
--- Name: deposits_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_coin_pub_index ON ONLY public.deposits USING btree (coin_pub);
-
-
---
--- Name: deposits_by_ready_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_ready_main_index ON ONLY public.deposits_by_ready USING btree (wire_deadline, shard, coin_pub);
-
-
---
--- Name: deposits_by_ready_default_wire_deadline_shard_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_ready_default_wire_deadline_shard_coin_pub_idx ON public.deposits_by_ready_default USING btree (wire_deadline, shard, coin_pub);
-
-
---
--- Name: deposits_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_default_coin_pub_idx ON public.deposits_default USING btree (coin_pub);
-
-
---
--- Name: deposits_for_matching_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_for_matching_main_index ON ONLY public.deposits_for_matching USING btree (refund_deadline, merchant_pub, coin_pub);
-
-
---
--- Name: deposits_for_matching_default_refund_deadline_merchant_pub__idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_for_matching_default_refund_deadline_merchant_pub__idx ON public.deposits_for_matching_default USING btree (refund_deadline, merchant_pub, coin_pub);
-
-
---
--- Name: django_session_expire_date_a5c62663; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX django_session_expire_date_a5c62663 ON public.django_session USING btree (expire_date);
-
-
---
--- Name: django_session_session_key_c0390e0f_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX django_session_session_key_c0390e0f_like ON public.django_session USING btree (session_key varchar_pattern_ops);
-
-
---
--- Name: global_fee_by_end_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX global_fee_by_end_date_index ON public.global_fee USING btree (end_date);
-
-
---
--- Name: merchant_contract_terms_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_expiration ON public.merchant_contract_terms USING btree (paid, pay_deadline);
-
-
---
--- Name: INDEX merchant_contract_terms_by_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.merchant_contract_terms_by_expiration IS 'for unlock_contracts';
-
-
---
--- Name: merchant_contract_terms_by_merchant_and_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_and_expiration ON public.merchant_contract_terms USING btree (merchant_serial, pay_deadline);
-
-
---
--- Name: INDEX merchant_contract_terms_by_merchant_and_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.merchant_contract_terms_by_merchant_and_expiration IS 'for delete_contract_terms';
-
-
---
--- Name: merchant_contract_terms_by_merchant_and_payment; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_and_payment ON public.merchant_contract_terms USING btree (merchant_serial, paid);
-
-
---
--- Name: merchant_contract_terms_by_merchant_session_and_fulfillment; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_session_and_fulfillment ON public.merchant_contract_terms USING btree (merchant_serial, fulfillment_url, session_id);
-
-
---
--- Name: merchant_inventory_locks_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_inventory_locks_by_expiration ON public.merchant_inventory_locks USING btree (expiration);
-
-
---
--- Name: merchant_inventory_locks_by_uuid; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_inventory_locks_by_uuid ON public.merchant_inventory_locks USING btree (lock_uuid);
-
-
---
--- Name: merchant_orders_by_creation_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_by_creation_time ON public.merchant_orders USING btree (creation_time);
-
-
---
--- Name: merchant_orders_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_by_expiration ON public.merchant_orders USING btree (pay_deadline);
-
-
---
--- Name: merchant_orders_locks_by_order_and_product; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_locks_by_order_and_product ON public.merchant_order_locks USING btree (order_serial, product_serial);
-
-
---
--- Name: merchant_refunds_by_coin_and_order; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_refunds_by_coin_and_order ON public.merchant_refunds USING btree (coin_pub, order_serial);
-
-
---
--- Name: merchant_tip_reserves_by_exchange_balance; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_exchange_balance ON public.merchant_tip_reserves USING btree (exchange_initial_balance_val, exchange_initial_balance_frac);
-
-
---
--- Name: merchant_tip_reserves_by_merchant_serial_and_creation_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_merchant_serial_and_creation_time ON public.merchant_tip_reserves USING btree (merchant_serial, creation_time);
-
-
---
--- Name: merchant_tip_reserves_by_reserve_pub_and_merchant_serial; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_reserve_pub_and_merchant_serial ON public.merchant_tip_reserves USING btree (reserve_pub, merchant_serial, creation_time);
-
-
---
--- Name: merchant_tips_by_pickup_and_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tips_by_pickup_and_expiration ON public.merchant_tips USING btree (was_picked_up, expiration);
-
-
---
--- Name: merchant_transfers_by_credit; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_transfers_by_credit ON public.merchant_transfer_to_coin USING btree (credit_serial);
-
-
---
--- Name: partner_accounts_index_by_partner_and_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX partner_accounts_index_by_partner_and_time ON public.partner_accounts USING btree (partner_serial_id, last_seen);
-
-
---
--- Name: partner_by_wad_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX partner_by_wad_time ON public.partners USING btree (next_wad);
-
-
---
--- Name: prewire_by_failed_finished_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_by_failed_finished_index ON ONLY public.prewire USING btree (failed, finished);
-
-
---
--- Name: INDEX prewire_by_failed_finished_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.prewire_by_failed_finished_index IS 'for wire_prepare_data_get';
-
-
---
--- Name: prewire_by_finished_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_by_finished_index ON ONLY public.prewire USING btree (finished);
-
-
---
--- Name: INDEX prewire_by_finished_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.prewire_by_finished_index IS 'for gc_prewire';
-
-
---
--- Name: prewire_default_failed_finished_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_default_failed_finished_idx ON public.prewire_default USING btree (failed, finished);
-
-
---
--- Name: prewire_default_finished_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_default_finished_idx ON public.prewire_default USING btree (finished);
-
-
---
--- Name: purse_action_by_target; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_action_by_target ON public.purse_actions USING btree (partner_serial_id, action_date);
-
-
---
--- Name: purse_deposits_by_coin_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_deposits_by_coin_pub ON ONLY public.purse_deposits USING btree (coin_pub);
-
-
---
--- Name: purse_deposits_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_deposits_default_coin_pub_idx ON public.purse_deposits_default USING btree (coin_pub);
-
-
---
--- Name: purse_merges_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_merges_reserve_pub ON ONLY public.purse_merges USING btree (reserve_pub);
-
-
---
--- Name: INDEX purse_merges_reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.purse_merges_reserve_pub IS 'needed in reserve history computation';
-
-
---
--- Name: purse_merges_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_merges_default_reserve_pub_idx ON public.purse_merges_default USING btree (reserve_pub);
-
-
---
--- Name: purse_requests_merge_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_merge_pub ON ONLY public.purse_requests USING btree (merge_pub);
-
-
---
--- Name: purse_requests_default_merge_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_default_merge_pub_idx ON public.purse_requests_default USING btree (merge_pub);
-
-
---
--- Name: purse_requests_purse_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_purse_expiration ON ONLY public.purse_requests USING btree (purse_expiration);
-
-
---
--- Name: purse_requests_default_purse_expiration_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_default_purse_expiration_idx ON public.purse_requests_default USING btree (purse_expiration);
-
-
---
--- Name: recoup_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_coin_pub_index ON ONLY public.recoup USING btree (coin_pub);
-
-
---
--- Name: recoup_by_reserve_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_reserve_main_index ON ONLY public.recoup_by_reserve USING btree (reserve_out_serial_id);
-
-
---
--- Name: recoup_by_reserve_default_reserve_out_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_reserve_default_reserve_out_serial_id_idx ON public.recoup_by_reserve_default USING btree (reserve_out_serial_id);
-
-
---
--- Name: recoup_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_default_coin_pub_idx ON public.recoup_default USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_by_coin_pub_index ON ONLY public.recoup_refresh USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_by_rrc_serial_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_by_rrc_serial_index ON ONLY public.recoup_refresh USING btree (rrc_serial);
-
-
---
--- Name: recoup_refresh_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_default_coin_pub_idx ON public.recoup_refresh_default USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_default_rrc_serial_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_default_rrc_serial_idx ON public.recoup_refresh_default USING btree (rrc_serial);
-
-
---
--- Name: refresh_commitments_by_old_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_commitments_by_old_coin_pub_index ON ONLY public.refresh_commitments USING btree (old_coin_pub);
-
-
---
--- Name: refresh_commitments_default_old_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_commitments_default_old_coin_pub_idx ON public.refresh_commitments_default USING btree (old_coin_pub);
-
-
---
--- Name: refresh_revealed_coins_coins_by_melt_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_revealed_coins_coins_by_melt_serial_id_index ON ONLY public.refresh_revealed_coins USING btree (melt_serial_id);
-
-
---
--- Name: refresh_revealed_coins_default_melt_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_revealed_coins_default_melt_serial_id_idx ON public.refresh_revealed_coins_default USING btree (melt_serial_id);
-
-
---
--- Name: refunds_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refunds_by_coin_pub_index ON ONLY public.refunds USING btree (coin_pub);
-
-
---
--- Name: refunds_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refunds_default_coin_pub_idx ON public.refunds_default USING btree (coin_pub);
-
-
---
--- Name: reserves_by_expiration_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_expiration_index ON ONLY public.reserves USING btree (expiration_date, current_balance_val, current_balance_frac);
-
-
---
--- Name: INDEX reserves_by_expiration_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_by_expiration_index IS 'used in get_expired_reserves';
-
-
---
--- Name: reserves_by_gc_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_gc_date_index ON ONLY public.reserves USING btree (gc_date);
-
-
---
--- Name: INDEX reserves_by_gc_date_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_by_gc_date_index IS 'for reserve garbage collection';
-
-
---
--- Name: reserves_by_reserve_uuid_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_reserve_uuid_index ON ONLY public.reserves USING btree (reserve_uuid);
-
-
---
--- Name: reserves_close_by_close_uuid_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_by_close_uuid_index ON ONLY public.reserves_close USING btree (close_uuid);
-
-
---
--- Name: reserves_close_by_reserve_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_by_reserve_pub_index ON ONLY public.reserves_close USING btree (reserve_pub);
-
-
---
--- Name: reserves_close_default_close_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_default_close_uuid_idx ON public.reserves_close_default USING btree (close_uuid);
-
-
---
--- Name: reserves_close_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_default_reserve_pub_idx ON public.reserves_close_default USING btree (reserve_pub);
-
-
---
--- Name: reserves_default_expiration_date_current_balance_val_curren_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_expiration_date_current_balance_val_curren_idx ON public.reserves_default USING btree (expiration_date, current_balance_val, current_balance_frac);
-
-
---
--- Name: reserves_default_gc_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_gc_date_idx ON public.reserves_default USING btree (gc_date);
-
-
---
--- Name: reserves_default_reserve_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_reserve_uuid_idx ON public.reserves_default USING btree (reserve_uuid);
-
-
---
--- Name: reserves_in_by_exch_accnt_reserve_in_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_exch_accnt_reserve_in_serial_id_idx ON ONLY public.reserves_in USING btree (exchange_account_section, reserve_in_serial_id DESC);
-
-
---
--- Name: reserves_in_by_exch_accnt_section_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_exch_accnt_section_execution_date_idx ON ONLY public.reserves_in USING btree (exchange_account_section, execution_date);
-
-
---
--- Name: reserves_in_by_reserve_in_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_reserve_in_serial_id_index ON ONLY public.reserves_in USING btree (reserve_in_serial_id);
-
-
---
--- Name: reserves_in_default_exchange_account_section_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_exchange_account_section_execution_date_idx ON public.reserves_in_default USING btree (exchange_account_section, execution_date);
-
-
---
--- Name: reserves_in_default_exchange_account_section_reserve_in_ser_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_exchange_account_section_reserve_in_ser_idx ON public.reserves_in_default USING btree (exchange_account_section, reserve_in_serial_id DESC);
-
-
---
--- Name: reserves_in_default_reserve_in_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_reserve_in_serial_id_idx ON public.reserves_in_default USING btree (reserve_in_serial_id);
-
-
---
--- Name: reserves_out_by_reserve_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_main_index ON ONLY public.reserves_out_by_reserve USING btree (reserve_uuid);
-
-
---
--- Name: reserves_out_by_reserve_default_reserve_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_default_reserve_uuid_idx ON public.reserves_out_by_reserve_default USING btree (reserve_uuid);
-
-
---
--- Name: reserves_out_by_reserve_out_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_out_serial_id_index ON ONLY public.reserves_out USING btree (reserve_out_serial_id);
-
-
---
--- Name: reserves_out_by_reserve_uuid_and_execution_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_uuid_and_execution_date_index ON ONLY public.reserves_out USING btree (reserve_uuid, execution_date);
-
-
---
--- Name: INDEX reserves_out_by_reserve_uuid_and_execution_date_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_out_by_reserve_uuid_and_execution_date_index IS 'for get_reserves_out and exchange_do_withdraw_limit_check';
-
-
---
--- Name: reserves_out_default_reserve_out_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_default_reserve_out_serial_id_idx ON public.reserves_out_default USING btree (reserve_out_serial_id);
-
-
---
--- Name: reserves_out_default_reserve_uuid_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_default_reserve_uuid_execution_date_idx ON public.reserves_out_default USING btree (reserve_uuid, execution_date);
-
-
---
--- Name: revolving_work_shards_by_job_name_active_last_attempt_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX revolving_work_shards_by_job_name_active_last_attempt_index ON public.revolving_work_shards USING btree (job_name, active, last_attempt);
-
-
---
--- Name: wad_in_entries_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_in_entries_reserve_pub ON ONLY public.wad_in_entries USING btree (reserve_pub);
-
-
---
--- Name: INDEX wad_in_entries_reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.wad_in_entries_reserve_pub IS 'needed in reserve history computation';
-
-
---
--- Name: wad_in_entries_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_in_entries_default_reserve_pub_idx ON public.wad_in_entries_default USING btree (reserve_pub);
-
-
---
--- Name: wad_out_entries_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_out_entries_by_reserve_pub ON ONLY public.wad_out_entries USING btree (reserve_pub);
-
-
---
--- Name: wad_out_entries_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_out_entries_default_reserve_pub_idx ON public.wad_out_entries_default USING btree (reserve_pub);
-
-
---
--- Name: wire_fee_by_end_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_fee_by_end_date_index ON public.wire_fee USING btree (end_date);
-
-
---
--- Name: wire_out_by_wire_target_h_payto_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_out_by_wire_target_h_payto_index ON ONLY public.wire_out USING btree (wire_target_h_payto);
-
-
---
--- Name: wire_out_default_wire_target_h_payto_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_out_default_wire_target_h_payto_idx ON public.wire_out_default USING btree (wire_target_h_payto);
-
-
---
--- Name: work_shards_by_job_name_completed_last_attempt_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX work_shards_by_job_name_completed_last_attempt_index ON public.work_shards USING btree (job_name, completed, last_attempt);
-
-
---
--- Name: account_merges_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.account_merges_pkey ATTACH PARTITION public.account_merges_default_pkey;
-
-
---
--- Name: account_merges_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.account_merges_by_reserve_pub ATTACH PARTITION public.account_merges_default_reserve_pub_idx;
-
-
---
--- Name: aggregation_tracking_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.aggregation_tracking_pkey ATTACH PARTITION public.aggregation_tracking_default_pkey;
-
-
---
--- Name: aggregation_tracking_default_wtid_raw_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.aggregation_tracking_by_wtid_raw_index ATTACH PARTITION public.aggregation_tracking_default_wtid_raw_idx;
-
-
---
--- Name: close_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.close_requests_pkey ATTACH PARTITION public.close_requests_default_pkey;
-
-
---
--- Name: contracts_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.contracts_pkey ATTACH PARTITION public.contracts_default_pkey;
-
-
---
--- Name: cs_nonce_locks_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.cs_nonce_locks_pkey ATTACH PARTITION public.cs_nonce_locks_default_pkey;
-
-
---
--- Name: deposits_by_ready_default_wire_deadline_shard_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_by_ready_main_index ATTACH PARTITION public.deposits_by_ready_default_wire_deadline_shard_coin_pub_idx;
-
-
---
--- Name: deposits_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_by_coin_pub_index ATTACH PARTITION public.deposits_default_coin_pub_idx;
-
-
---
--- Name: deposits_for_matching_default_refund_deadline_merchant_pub__idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_for_matching_main_index ATTACH PARTITION public.deposits_for_matching_default_refund_deadline_merchant_pub__idx;
-
-
---
--- Name: extension_details_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.extension_details_pkey ATTACH PARTITION public.extension_details_default_pkey;
-
-
---
--- Name: history_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.history_requests_pkey ATTACH PARTITION public.history_requests_default_pkey;
-
-
---
--- Name: known_coins_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.known_coins_pkey ATTACH PARTITION public.known_coins_default_pkey;
-
-
---
--- Name: prewire_default_failed_finished_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_by_failed_finished_index ATTACH PARTITION public.prewire_default_failed_finished_idx;
-
-
---
--- Name: prewire_default_finished_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_by_finished_index ATTACH PARTITION public.prewire_default_finished_idx;
-
-
---
--- Name: prewire_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_pkey ATTACH PARTITION public.prewire_default_pkey;
-
-
---
--- Name: purse_deposits_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_deposits_by_coin_pub ATTACH PARTITION public.purse_deposits_default_coin_pub_idx;
-
-
---
--- Name: purse_deposits_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_deposits_pkey ATTACH PARTITION public.purse_deposits_default_pkey;
-
-
---
--- Name: purse_merges_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_merges_pkey ATTACH PARTITION public.purse_merges_default_pkey;
-
-
---
--- Name: purse_merges_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_merges_reserve_pub ATTACH PARTITION public.purse_merges_default_reserve_pub_idx;
-
-
---
--- Name: purse_refunds_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_refunds_pkey ATTACH PARTITION public.purse_refunds_default_pkey;
-
-
---
--- Name: purse_requests_default_merge_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_merge_pub ATTACH PARTITION public.purse_requests_default_merge_pub_idx;
-
-
---
--- Name: purse_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_pkey ATTACH PARTITION public.purse_requests_default_pkey;
-
-
---
--- Name: purse_requests_default_purse_expiration_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_purse_expiration ATTACH PARTITION public.purse_requests_default_purse_expiration_idx;
-
-
---
--- Name: recoup_by_reserve_default_reserve_out_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_by_reserve_main_index ATTACH PARTITION public.recoup_by_reserve_default_reserve_out_serial_id_idx;
-
-
---
--- Name: recoup_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_by_coin_pub_index ATTACH PARTITION public.recoup_default_coin_pub_idx;
-
-
---
--- Name: recoup_refresh_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_refresh_by_coin_pub_index ATTACH PARTITION public.recoup_refresh_default_coin_pub_idx;
-
-
---
--- Name: recoup_refresh_default_rrc_serial_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_refresh_by_rrc_serial_index ATTACH PARTITION public.recoup_refresh_default_rrc_serial_idx;
-
-
---
--- Name: refresh_commitments_default_old_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_commitments_by_old_coin_pub_index ATTACH PARTITION public.refresh_commitments_default_old_coin_pub_idx;
-
-
---
--- Name: refresh_commitments_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_commitments_pkey ATTACH PARTITION public.refresh_commitments_default_pkey;
-
-
---
--- Name: refresh_revealed_coins_default_melt_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_revealed_coins_coins_by_melt_serial_id_index ATTACH PARTITION public.refresh_revealed_coins_default_melt_serial_id_idx;
-
-
---
--- Name: refresh_transfer_keys_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_transfer_keys_pkey ATTACH PARTITION public.refresh_transfer_keys_default_pkey;
-
-
---
--- Name: refunds_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refunds_by_coin_pub_index ATTACH PARTITION public.refunds_default_coin_pub_idx;
-
-
---
--- Name: reserves_close_default_close_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_close_by_close_uuid_index ATTACH PARTITION public.reserves_close_default_close_uuid_idx;
-
-
---
--- Name: reserves_close_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_close_by_reserve_pub_index ATTACH PARTITION public.reserves_close_default_reserve_pub_idx;
-
-
---
--- Name: reserves_default_expiration_date_current_balance_val_curren_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_expiration_index ATTACH PARTITION public.reserves_default_expiration_date_current_balance_val_curren_idx;
-
-
---
--- Name: reserves_default_gc_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_gc_date_index ATTACH PARTITION public.reserves_default_gc_date_idx;
-
-
---
--- Name: reserves_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_pkey ATTACH PARTITION public.reserves_default_pkey;
-
-
---
--- Name: reserves_default_reserve_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_reserve_uuid_index ATTACH PARTITION public.reserves_default_reserve_uuid_idx;
-
-
---
--- Name: reserves_in_default_exchange_account_section_execution_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_exch_accnt_section_execution_date_idx ATTACH PARTITION public.reserves_in_default_exchange_account_section_execution_date_idx;
-
-
---
--- Name: reserves_in_default_exchange_account_section_reserve_in_ser_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_exch_accnt_reserve_in_serial_id_idx ATTACH PARTITION public.reserves_in_default_exchange_account_section_reserve_in_ser_idx;
-
-
---
--- Name: reserves_in_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_pkey ATTACH PARTITION public.reserves_in_default_pkey;
-
-
---
--- Name: reserves_in_default_reserve_in_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_reserve_in_serial_id_index ATTACH PARTITION public.reserves_in_default_reserve_in_serial_id_idx;
-
-
---
--- Name: reserves_out_by_reserve_default_reserve_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_main_index ATTACH PARTITION public.reserves_out_by_reserve_default_reserve_uuid_idx;
-
-
---
--- Name: reserves_out_default_h_blind_ev_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_h_blind_ev_key ATTACH PARTITION public.reserves_out_default_h_blind_ev_key;
-
-
---
--- Name: reserves_out_default_reserve_out_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_out_serial_id_index ATTACH PARTITION public.reserves_out_default_reserve_out_serial_id_idx;
-
-
---
--- Name: reserves_out_default_reserve_uuid_execution_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_uuid_and_execution_date_index ATTACH PARTITION public.reserves_out_default_reserve_uuid_execution_date_idx;
-
-
---
--- Name: wad_in_entries_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_in_entries_pkey ATTACH PARTITION public.wad_in_entries_default_pkey;
-
-
---
--- Name: wad_in_entries_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_in_entries_reserve_pub ATTACH PARTITION public.wad_in_entries_default_reserve_pub_idx;
-
-
---
--- Name: wad_out_entries_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_out_entries_pkey ATTACH PARTITION public.wad_out_entries_default_pkey;
-
-
---
--- Name: wad_out_entries_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_out_entries_by_reserve_pub ATTACH PARTITION public.wad_out_entries_default_reserve_pub_idx;
-
-
---
--- Name: wads_in_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_in_pkey ATTACH PARTITION public.wads_in_default_pkey;
-
-
---
--- Name: wads_in_default_wad_id_origin_exchange_url_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_in_wad_id_origin_exchange_url_key ATTACH PARTITION public.wads_in_default_wad_id_origin_exchange_url_key;
-
-
---
--- Name: wads_out_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_out_pkey ATTACH PARTITION public.wads_out_default_pkey;
-
-
---
--- Name: wire_out_default_wire_target_h_payto_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_out_by_wire_target_h_payto_index ATTACH PARTITION public.wire_out_default_wire_target_h_payto_idx;
-
-
---
--- Name: wire_out_default_wtid_raw_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_out_wtid_raw_key ATTACH PARTITION public.wire_out_default_wtid_raw_key;
-
-
---
--- Name: wire_targets_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_targets_pkey ATTACH PARTITION public.wire_targets_default_pkey;
-
-
---
--- Name: deposits deposits_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_delete AFTER DELETE ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_delete_trigger();
-
-
---
--- Name: deposits deposits_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_insert AFTER INSERT ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_insert_trigger();
-
-
---
--- Name: deposits deposits_on_update; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_update AFTER UPDATE ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_update_trigger();
-
-
---
--- Name: purse_requests purse_requests_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER purse_requests_on_insert AFTER INSERT ON public.purse_requests FOR EACH ROW EXECUTE FUNCTION public.purse_requests_insert_trigger();
-
-
---
--- Name: TRIGGER purse_requests_on_insert ON purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TRIGGER purse_requests_on_insert ON public.purse_requests IS 'Here we install an entry for the purse expiration.';
-
-
---
--- Name: purse_requests purse_requests_on_update; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER purse_requests_on_update BEFORE UPDATE ON public.purse_requests FOR EACH ROW EXECUTE FUNCTION public.purse_requests_on_update_trigger();
-
-
---
--- Name: TRIGGER purse_requests_on_update ON purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TRIGGER purse_requests_on_update ON public.purse_requests IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
-
-
---
--- Name: recoup recoup_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER recoup_on_delete AFTER DELETE ON public.recoup FOR EACH ROW EXECUTE FUNCTION public.recoup_delete_trigger();
-
-
---
--- Name: recoup recoup_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER recoup_on_insert AFTER INSERT ON public.recoup FOR EACH ROW EXECUTE FUNCTION public.recoup_insert_trigger();
-
-
---
--- Name: reserves_out reserves_out_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER reserves_out_on_delete AFTER DELETE ON public.reserves_out FOR EACH ROW EXECUTE FUNCTION public.reserves_out_by_reserve_delete_trigger();
-
-
---
--- Name: reserves_out reserves_out_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER reserves_out_on_insert AFTER INSERT ON public.reserves_out FOR EACH ROW EXECUTE FUNCTION public.reserves_out_by_reserve_insert_trigger();
-
-
---
--- Name: wire_out wire_out_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER wire_out_on_delete AFTER DELETE ON public.wire_out FOR EACH ROW EXECUTE FUNCTION public.wire_out_delete_trigger();
-
-
---
--- Name: app_bankaccount app_bankaccount_user_id_2722a34f_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_user_id_2722a34f_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_banktransaction app_banktransaction_credit_account_id_a8ba05ac_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_credit_account_id_a8ba05ac_fk_app_banka FOREIGN KEY (credit_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_banktransaction app_banktransaction_debit_account_id_5b1f7528_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_debit_account_id_5b1f7528_fk_app_banka FOREIGN KEY (debit_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawope_selected_exchange_ac_6c8b96cf_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawope_selected_exchange_ac_6c8b96cf_fk_app_banka FOREIGN KEY (selected_exchange_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawope_withdraw_account_id_992dc5b3_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawope_withdraw_account_id_992dc5b3_fk_app_banka FOREIGN KEY (withdraw_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_auditor_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_auditor_uuid_fkey FOREIGN KEY (auditor_uuid) REFERENCES public.auditors(auditor_uuid) ON DELETE CASCADE;
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_denominations_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_denominations_serial_fkey FOREIGN KEY (denominations_serial) REFERENCES public.denominations(denominations_serial) ON DELETE CASCADE;
-
-
---
--- Name: auth_group_permissions auth_group_permissio_permission_id_84c5c92e_fk_auth_perm; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissio_permission_id_84c5c92e_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_group_permissions auth_group_permissions_group_id_b120cbf9_fk_auth_group_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_group_id_b120cbf9_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_permission auth_permission_content_type_id_2f476e4b_fk_django_co; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_content_type_id_2f476e4b_fk_django_co FOREIGN KEY (content_type_id) REFERENCES public.django_content_type(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_groups auth_user_groups_group_id_97559544_fk_auth_group_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_group_id_97559544_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_groups auth_user_groups_user_id_6a12ed8b_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_user_id_6a12ed8b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: denomination_revocations denomination_revocations_denominations_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_denominations_serial_fkey FOREIGN KEY (denominations_serial) REFERENCES public.denominations(denominations_serial) ON DELETE CASCADE;
-
-
---
--- Name: auditor_exchange_signkeys master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_exchange_signkeys
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_reserve master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_reserve
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_aggregation master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_aggregation
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_deposit_confirmation master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_deposit_confirmation
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_coin master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_coin
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: wire_auditor_account_progress master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_account_progress
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: wire_auditor_progress master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_progress
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_reserves master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_reserve_balance master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserve_balance
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_wire_fee_balance master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_wire_fee_balance
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_balance_summary master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_balance_summary
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_historic_denomination_revenue master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_denomination_revenue
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_historic_reserve_summary master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_reserve_summary
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: deposit_confirmations master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_predicted_result master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_predicted_result
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: merchant_accounts merchant_accounts_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial);
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_deposit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_deposit_serial_fkey FOREIGN KEY (deposit_serial) REFERENCES public.merchant_deposits(deposit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_contract_terms(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_inventory_locks merchant_inventory_locks_product_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory_locks
- ADD CONSTRAINT merchant_inventory_locks_product_serial_fkey FOREIGN KEY (product_serial) REFERENCES public.merchant_inventory(product_serial);
-
-
---
--- Name: merchant_inventory merchant_inventory_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_keys merchant_keys_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_kyc merchant_kyc_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_order_locks merchant_order_locks_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_order_locks
- ADD CONSTRAINT merchant_order_locks_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_orders(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_order_locks merchant_order_locks_product_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_order_locks
- ADD CONSTRAINT merchant_order_locks_product_serial_fkey FOREIGN KEY (product_serial) REFERENCES public.merchant_inventory(product_serial);
-
-
---
--- Name: merchant_orders merchant_orders_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_refund_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_refund_serial_fkey FOREIGN KEY (refund_serial) REFERENCES public.merchant_refunds(refund_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refunds merchant_refunds_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_contract_terms(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_pickup_signatures merchant_tip_pickup_signatures_pickup_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickup_signatures
- ADD CONSTRAINT merchant_tip_pickup_signatures_pickup_serial_fkey FOREIGN KEY (pickup_serial) REFERENCES public.merchant_tip_pickups(pickup_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_tip_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_tip_serial_fkey FOREIGN KEY (tip_serial) REFERENCES public.merchant_tips(tip_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_serial_fkey FOREIGN KEY (reserve_serial) REFERENCES public.merchant_tip_reserves(reserve_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tips merchant_tips_reserve_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_reserve_serial_fkey FOREIGN KEY (reserve_serial) REFERENCES public.merchant_tip_reserves(reserve_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_deposit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_deposit_serial_fkey FOREIGN KEY (deposit_serial) REFERENCES public.merchant_deposits(deposit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfers merchant_transfers_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: partner_accounts partner_accounts_partner_serial_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partner_accounts
- ADD CONSTRAINT partner_accounts_partner_serial_id_fkey FOREIGN KEY (partner_serial_id) REFERENCES public.partners(partner_serial_id) ON DELETE CASCADE;
-
-
---
--- Name: signkey_revocations signkey_revocations_esk_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_esk_serial_fkey FOREIGN KEY (esk_serial) REFERENCES public.exchange_sign_keys(esk_serial) ON DELETE CASCADE;
-
-
---
--- PostgreSQL database dump complete
---
diff --git a/src/auditor/auditor.conf b/src/auditor/auditor.conf
index 270836283..3c04d196f 100644
--- a/src/auditor/auditor.conf
+++ b/src/auditor/auditor.conf
@@ -9,7 +9,7 @@ DB = postgres
#TINY_AMOUNT = KUDOS:0.01
# Where do we store the auditor's private key?
-AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}/auditor/offline-keys/auditor.priv
+AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}auditor/offline-keys/auditor.priv
# What is the public key of this auditor? Used for processes that
# verify auditor's signatures but have no access to the private key.
@@ -17,7 +17,7 @@ AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}/auditor/offline-keys/auditor.priv
# What is the Web site of the auditor (i.e. to file complaints about
# a misbehaving exchange)?
-# BASE_URL = https://auditor.taler.net/
+BASE_URL = http://localhost:8083/
# Network configuration for the normal API/service HTTP server
@@ -26,7 +26,7 @@ SERVE = tcp
# Unix domain socket to listen on,
# only effective with "SERVE = unix"
-UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
+UNIXPATH = ${TALER_RUNTIME_DIR}exchange.http
UNIXPATH_MODE = 660
# HTTP port the auditor listens to
diff --git a/src/auditor/batch.conf b/src/auditor/batch.conf
index bdbef4b19..cd8c64b8e 100644
--- a/src/auditor/batch.conf
+++ b/src/auditor/batch.conf
@@ -121,7 +121,7 @@ PAYTO_URI = payto://x-taler-bank/localhost/42
PASSWORD = x
USERNAME = Exchange
WIRE_GATEWAY_AUTH_METHOD = basic
-WIRE_GATEWAY_URL = http://localhost:8082/taler-wire-gateway/Exchange/
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/Exchange/taler-wire-gateway/
[exchange-account-1]
enable_credit = yes
diff --git a/src/auditor/batch.sh b/src/auditor/batch.sh
index fed690432..bbe1be0ba 100755
--- a/src/auditor/batch.sh
+++ b/src/auditor/batch.sh
@@ -64,22 +64,22 @@ createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
# obtain key configuration data
-MASTER_PRIV_FILE=`taler-config -f -c $CONF -s exchange-offline -o MASTER_PRIV_FILE`
-MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE`
+MASTER_PRIV_FILE=$(taler-config -f -c $CONF -s exchange-offline -o MASTER_PRIV_FILE)
+MASTER_PRIV_DIR=$(dirname $MASTER_PRIV_FILE)
mkdir -p $MASTER_PRIV_DIR
gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null
-MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE`
-EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
-MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT`
+MASTER_PUB=$(gnunet-ecc -p $MASTER_PRIV_FILE)
+EXCHANGE_URL=$(taler-config -c $CONF -s EXCHANGE -o BASE_URL)
+MERCHANT_PORT=$(taler-config -c $CONF -s MERCHANT -o PORT)
MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
-BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
+BANK_PORT=$(taler-config -c $CONF -s BANK -o HTTP_PORT)
BANK_URL=http://localhost:${BANK_PORT}/
AUDITOR_URL=http://localhost:8083/
-AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE`
-AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE`
+AUDITOR_PRIV_FILE=$(taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE)
+AUDITOR_PRIV_DIR=$(dirname $AUDITOR_PRIV_FILE)
mkdir -p $AUDITOR_PRIV_DIR
gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null
-AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE`
+AUDITOR_PUB=$(gnunet-ecc -p $AUDITOR_PRIV_FILE)
echo "AUDITOR PUB is $AUDITOR_PUB using file $AUDITOR_PRIV_FILE"
@@ -193,7 +193,7 @@ echo " DONE"
echo -n "Setting up merchant"
-curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 3600000},"default_pay_delay":{"d_ms": 3600000}}' http://localhost:9966/management/instances
+curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"accounts":[{"payto_uri":"payto://x-taler-bank/localhost/43"}],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000}}' http://localhost:9966/management/instances
echo " DONE"
@@ -214,7 +214,7 @@ bash
# {
# amountToSpend: "TESTKUDOS:4",
# amountToWithdraw: "TESTKUDOS:10",
-# bankBaseUrl: $BANK_URL,
+# corebankApiBaseUrl: $BANK_URL,
# exchangeBaseUrl: $EXCHANGE_URL,
# merchantBaseUrl: $MERCHANT_URL,
# }' \
diff --git a/src/auditor/generate-auditor-basedb-template.conf b/src/auditor/generate-auditor-basedb-template.conf
deleted file mode 100644
index 1d18740c7..000000000
--- a/src/auditor/generate-auditor-basedb-template.conf
+++ /dev/null
@@ -1 +0,0 @@
-@INLINE@ generate-auditor-basedb.conf
diff --git a/src/auditor/generate-auditor-basedb.conf b/src/auditor/generate-auditor-basedb.conf
index 5540aa3b8..8cf63fbba 100644
--- a/src/auditor/generate-auditor-basedb.conf
+++ b/src/auditor/generate-auditor-basedb.conf
@@ -1,101 +1,123 @@
+[PATHS]
+TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
+TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
+TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
+TALER_HOME = ${PWD}/generate_auditordb_home/
+[taler]
+CURRENCY = TESTKUDOS
+CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
+
[exchange]
-MAX_KEYS_CACHING = forever
-DB = postgres
-SERVE = tcp
-UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
-UNIXPATH_MODE = 660
-PORT = 8081
-BASE_URL = http://localhost:8081/
+MASTER_PUBLIC_KEY = M4FGP18EQFXFGGFQ1AWXHACN2JX0SMVK9CNF6459Z1WG18JSN0BG
SIGNKEY_DURATION = 4 weeks
-SIGNKEY_LEGAL_DURATION = 4 weeks
LOOKAHEAD_SIGN = 32 weeks 1 day
+SIGNKEY_LEGAL_DURATION = 4 weeks
+AML_THRESHOLD = TESTKUDOS:1000000
+db = postgres
+BASE_URL = http://localhost:8081/
+IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
+LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks
-[merchant]
-SERVE = tcp
-PORT = 9966
-UNIXPATH = ${TALER_RUNTIME_DIR}/merchant.http
-UNIXPATH_MODE = 660
-DEFAULT_WIRE_FEE_AMORTIZATION = 1
-DB = postgres
-WIREFORMAT = default
-# Set very low, so we can be sure that the database generated
-# will contain wire transfers "ready" for the aggregator.
-WIRE_TRANSFER_DELAY = 1 minute
-DEFAULT_PAY_DEADLINE = 1 day
-DEFAULT_MAX_DEPOSIT_FEE = TESTKUDOS:0.1
-KEYFILE = ${TALER_DATA_HOME}/merchant/merchant.priv
-DEFAULT_MAX_WIRE_FEE = TESTKUDOS:0.10
-
-# Ensure that merchant reports EVERY deposit confirmation to auditor
-FORCE_AUDIT = YES
-
-[instance-default]
-KEYFILE = ${TALER_DATA_HOME}/merchant/default.priv
-NAME = Merchant Inc.
+[exchangedb]
+IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
+LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks
+AGGREGATOR_SHIFT = 1 s
+DEFAULT_PURSE_LIMIT = 1
-[auditor]
-DB = postgres
-AUDITOR_PRIV_FILE = ${TALER_DATA_HOME}/auditor/offline-keys/auditor.priv
+[libeufin-bank]
+CURRENCY = TESTKUDOS
+DEFAULT_CUSTOMER_DEBT_LIMIT = TESTKUDOS:200
+DEFAULT_ADMIN_DEBT_LIMIT = TESTKUDOS:2000
+ALLOW_REGISTRATION = yes
+REGISTRATION_BONUS_ENABLED = yes
+REGISTRATION_BONUS = TESTKUDOS:100
+SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/
+WIRE_TYPE = iban
+IBAN_PAYTO_BIC = SANDBOXX
SERVE = tcp
-UNIXPATH = ${TALER_RUNTIME_DIR}/exchange.http
-UNIXPATH_MODE = 660
-PORT = 8083
-BASE_URL = http://localhost:8083/
-TINY_AMOUNT = TESTKUDOS:0.01
+PORT = 8082
-[PATHS]
-TALER_HOME = ${PWD}/generate_auditordb_home/
-TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
-TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
-TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-system-runtime/
-
-[bank]
-DATABASE = postgres:///taler-auditor-basedb
-MAX_DEBT = TESTKUDOS:50.0
-MAX_DEBT_BANK = TESTKUDOS:100000.0
-HTTP_PORT = 8082
-SUGGESTED_EXCHANGE = http://localhost:8081/
-SUGGESTED_EXCHANGE_PAYTO = payto://x-taler-bank/localhost/2
-ALLOW_REGISTRATIONS = YES
-SERVE = http
+[libeufin-bankdb-postgres]
+CONFIG = postgresql:///auditor-basedb
-[exchangedb]
+[exchangedb-postgres]
+CONFIG = postgres:///auditor-basedb
+SQL_DIR = $DATADIR/sql/exchange/
IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
-LEGAL_RESERVE_EXPIRATION_TIME = 7 years
-
-[taler]
-CURRENCY = TESTKUDOS
-CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
+LEGAL_RESERVE_EXPIRATION_TIME = 4 weeks
[exchange-account-1]
-PAYTO_URI = payto://x-taler-bank/localhost/Exchange
-enable_debit = yes
-enable_credit = yes
+PAYTO_URI = payto://iban/SANDBOXX/DE989651?receiver-name=Exchange+Company
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/taler-wire-gateway/Exchange/"
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/exchange/taler-wire-gateway/
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = exchange
+PASSWORD = x
+
+[exchange-account-2]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-2]
WIRE_GATEWAY_AUTH_METHOD = basic
USERNAME = Exchange
PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
-[merchant-account-merchant]
-PAYTO_URI = payto://x-taler-bank/localhost/42
-HONOR_default = YES
-ACTIVE_default = YES
+[admin-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+# For now, fakebank still checks against the Exchange account...
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+
+[merchant]
+FORCE_AUDIT = YES
+SERVE = TCP
+PORT = 8888
+
+[merchantdb-postgres]
+CONFIG = postgres:///auditor-basedb
+SQL_DIR = $DATADIR/sql/merchant/
[merchant-exchange-default]
+MASTER_KEY = M4FGP18EQFXFGGFQ1AWXHACN2JX0SMVK9CNF6459Z1WG18JSN0BG
EXCHANGE_BASE_URL = http://localhost:8081/
CURRENCY = TESTKUDOS
-[payments-generator]
-currency = TESTKUDOS
-instance = default
-bank = http://localhost:8082/
-merchant = http://localhost:9966/
-exchange_admin = http://localhost:18080/
-exchange-admin = http://localhost:18080/
-exchange = http://localhost:8081/
+[bank]
+HTTP_PORT = 8082
+
+[libeufin-nexus]
+DB_CONNECTION="postgresql:///auditor-basedb"
+
+[libeufin-sandbox]
+DB_CONNECTION="postgresql:///auditor-basedb"
+
+[libeufin-bank]
+CURRENCY = TESTKUDOS
+DEFAULT_CUSTOMER_DEBT_LIMIT = TESTKUDOS:200 # dead
+DEFAULT_ADMIN_DEBT_LIMIT = TESTKUDOS:2000
+REGISTRATION_BONUS_ENABLED = yes
+REGISTRATION_BONUS = TESTKUDOS:100
+SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/
+SERVE = tcp
+PORT = 8082
+
+[auditor]
+BASE_URL = http://localhost:8083/
+TINY_AMOUNT = TESTKUDOS:0.01
+PUBLIC_KEY = 0EHPW5WEKHXPPN4MPJNGA7Z6D29JP21GKVNV8ARFB1YW7WWJX20G
+db = postgres
+
+[auditordb-postgres]
+CONFIG = postgres:///auditor-basedb
+SQL_DIR = $DATADIR/sql/auditor/
[coin_kudos_ct_1]
value = TESTKUDOS:0.01
@@ -192,31 +214,3 @@ fee_refresh = TESTKUDOS:0.03
fee_refund = TESTKUDOS:0.01
CIPHER = RSA
rsa_keysize = 1024
-
-[coin_kudos_ct_1]
-value = TESTKUDOS:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.01
-fee_refund = TESTKUDOS:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_kudos_ct_10]
-value = TESTKUDOS:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = TESTKUDOS:0.01
-fee_deposit = TESTKUDOS:0.01
-fee_refresh = TESTKUDOS:0.03
-fee_refund = TESTKUDOS:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[benchmark]
-BANK_DETAILS = bank_details.json
-MERCHANT_DETAILS = merchant_details.json
diff --git a/src/auditor/generate-auditor-basedb.sh b/src/auditor/generate-auditor-basedb.sh
index 4006addfd..bbce37cdc 100755
--- a/src/auditor/generate-auditor-basedb.sh
+++ b/src/auditor/generate-auditor-basedb.sh
@@ -1,227 +1,114 @@
#!/bin/bash
-# Script to generate the basic database for auditor
-# testing from a 'correct' interaction between exchange,
-# wallet and merchant.
+# This file is in the public domain.
#
-# Creates $BASEDB.sql, $BASEDB.fees, $BASEDB.mpub and
-# $BASEDB.age.
-# Default $BASEDB is "auditor-basedb", override via $1.
+# Script to generate the basic database for auditor testing from a 'correct'
+# interaction between exchange, wallet and merchant.
#
-# Currently must be run online as it interacts with
-# bank.test.taler.net; also requires the wallet CLI
-# to be installed and in the path. Furthermore, the
-# user running this script must be Postgres superuser
-# and be allowed to create/drop databases.
+# Creates "$1.sql".
+#
+# Requires the wallet CLI to be installed and in the path. Furthermore, the
+# user running this script must be Postgres superuser and be allowed to
+# create/drop databases.
#
set -eu
-# Cleanup to run whenever we exit
-function cleanup()
-{
- for n in `jobs -p`
- do
- kill $n 2> /dev/null || true
- done
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
-
-# Exit, with status code "skip" (no 'real' failure)
-function exit_skip() {
- echo $1
- exit 77
-}
+. setup.sh
+
+CONF="generate-auditor-basedb.conf"
+# Parse command-line options
+while getopts ':c:d:h' OPTION; do
+ case "$OPTION" in
+ c)
+ CONF="$OPTARG"
+ ;;
+ d)
+ BASEDB="$OPTARG"
+ ;;
+ h)
+ echo 'Supported options:'
+# shellcheck disable=SC2016
+ echo ' -c $CONF -- set configuration'
+# shellcheck disable=SC2016
+ echo ' -d $DB -- set database name'
+ ;;
+ ?)
+ exit_fail "Unrecognized command line option"
+ ;;
+ esac
+done
# Where do we write the result?
-BASEDB=${1:-"auditor-basedb"}
-
-# Name of the Postgres database we will use for the script.
-# Will be dropped, do NOT use anything that might be used
-# elsewhere
-export TARGET_DB=`basename ${BASEDB}`
-
-export WALLET_DB=${BASEDB:-"wallet"}.wdb
-
-# delete existing wallet database
-rm -f $WALLET_DB
-
-
-# Configuration file will be edited, so we create one
-# from the template.
-CONF=${BASEDB}.conf
-cp generate-auditor-basedb.conf $CONF
-
+if [ ! -v BASEDB ]
+then
+ exit_fail "-d option required"
+fi
-echo -n "Testing for taler-bank-manage"
-taler-bank-manage --help >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-echo -n "Testing for taler-wallet-cli"
-taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-echo -n "Testing for curl"
+echo -n "Testing for curl ..."
curl --help >/dev/null </dev/null || exit_skip " MISSING"
echo " FOUND"
-
-pwd
-# Clean up
-
-DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME`
-rm -rf $DATA_DIR || true
-
# reset database
-dropdb $TARGET_DB >/dev/null 2>/dev/null || true
-createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
+echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+dropdb "auditor-basedb" >/dev/null 2>/dev/null || true
+createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at $PGHOST"
+echo " DONE"
+# Launch exchange, merchant and bank.
+setup -c "$CONF" \
+ -abemw \
+ -d "iban"
# obtain key configuration data
-MASTER_PRIV_FILE=`taler-config -f -c $CONF -s exchange-offline -o MASTER_PRIV_FILE`
-MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE`
-mkdir -p $MASTER_PRIV_DIR
-gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null
-MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE`
-EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
-MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT`
-MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
-BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
-BANK_URL=http://localhost:${BANK_PORT}/
-AUDITOR_URL=http://localhost:8083/
-AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE`
-AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE`
-mkdir -p $AUDITOR_PRIV_DIR
-gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null
-AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE`
-
-echo "AUDITOR PUB is $AUDITOR_PUB using file $AUDITOR_PRIV_FILE"
-
-# patch configuration
-taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB
-taler-config -c $CONF -s auditor -o PUBLIC_KEY -V $AUDITOR_PUB
-taler-config -c $CONF -s merchant-exchange-default -o MASTER_KEY -V $MASTER_PUB
-taler-config -c $CONF -s exchangedb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s auditordb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s bank -o database -V postgres:///$TARGET_DB
-
-# setup exchange
-echo "Setting up exchange"
-taler-exchange-dbinit -c $CONF
-
-echo "Setting up merchant"
-taler-merchant-dbinit -c $CONF
-
-# setup auditor
-echo "Setting up auditor"
-taler-auditor-dbinit -c $CONF || exit_skip "Failed to initialize auditor DB"
-taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL || exit_skip "Failed to add exchange to auditor"
-
-# Launch services
-echo "Launching services"
-taler-bank-manage-testing $CONF postgres:///$TARGET_DB serve &> taler-bank.log &
-TFN=`which taler-exchange-httpd`
-TBINPFX=`dirname $TFN`
-TLIBEXEC=${TBINPFX}/../lib/taler/libexec/
-taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log &
-taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log &
-taler-exchange-secmod-cs -c $CONF 2> taler-exchange-secmod-cs.log &
-taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log &
-taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
-taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log &
-taler-auditor-httpd -L INFO -c $CONF 2> taler-auditor-httpd.log &
-
-# Wait for all bank to be available (usually the slowest)
-for n in `seq 1 50`
-do
- echo -n "."
- sleep 0.2
- OK=0
- # bank
- wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- exit_skip "Failed to launch services"
-fi
-
-# Wait for all services to be available
-for n in `seq 1 50`
-do
- echo -n "."
- sleep 0.1
- OK=0
- # exchange
- wget http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null || continue
- # merchant
- wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || continue
- # Auditor
- wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- exit_skip "Failed to launch services"
-fi
+EXCHANGE_URL=$(taler-config -c "$CONF" -s EXCHANGE -o BASE_URL)
+MERCHANT_PORT=$(taler-config -c "$CONF" -s MERCHANT -o PORT)
+MERCHANT_URL="http://localhost:${MERCHANT_PORT}/"
+BANK_PORT=$(taler-config -c "$CONF" -s BANK -o HTTP_PORT)
+BANK_URL="http://localhost:${BANK_PORT}"
+
+echo -n "Checking setup worked ..."
+wget \
+ --tries=1 \
+ --timeout=1 \
+ "${EXCHANGE_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null
+echo "DONE"
+
+export MERCHANT_URL
+echo -n "Setting up merchant ..."
+
+curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000},"use_stefan":false}' "${MERCHANT_URL}management/instances"
echo " DONE"
-echo -n "Setting up keys"
-taler-exchange-offline -c $CONF \
- download sign \
- enable-account payto://x-taler-bank/localhost/Exchange \
- enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \
- wire-fee now x-taler-bank TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 \
- global-fee now TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 1h 1h 1year 5 \
- upload &> taler-exchange-offline.log
-
-echo -n "."
-
-for n in `seq 1 2`
-do
- echo -n "."
- OK=0
- wget --timeout=1 http://localhost:8081/keys -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
+echo -n "Setting up merchant account ..."
+FORTYTHREE="payto://iban/SANDBOXX/DE474361?receiver-name=Merchant43"
+STATUS=$(curl -H "Content-Type: application/json" -X POST \
+ "${MERCHANT_URL}private/accounts" \
+ -d '{"payto_uri":"'"$FORTYTHREE"'"}' \
+ -w "%{http_code}" -s -o /dev/null)
-if [ 1 != $OK ]
+if [ "$STATUS" != "200" ]
then
- exit_skip "Failed to setup keys"
+ exit_fail "Expected 200 OK. Got: $STATUS"
fi
-
-echo " DONE"
-echo -n "Adding auditor signatures ..."
-
-taler-auditor-offline -c $CONF \
- download sign upload &> taler-auditor-offline.log
-
echo " DONE"
-# Setup merchant
-
-echo -n "Setting up merchant"
-
-curl -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 3600000},"default_pay_delay":{"d_ms": 3600000}}' http://localhost:9966/management/instances
-
-echo " DONE"
-
-# run wallet CLI
-echo "Running wallet"
-
-
-taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'runIntegrationTest' \
+# delete existing wallet database
+export WALLET_DB="wallet.wdb"
+rm -f "$WALLET_DB"
+
+echo -n "Running wallet ..."
+taler-wallet-cli \
+ --no-throttle \
+ --wallet-db="$WALLET_DB" \
+ api \
+ --expect-success \
+ 'runIntegrationTest' \
"$(jq -n '
{
amountToSpend: "TESTKUDOS:4",
amountToWithdraw: "TESTKUDOS:10",
- bankBaseUrl: $BANK_URL,
+ corebankApiBaseUrl: $BANK_URL,
exchangeBaseUrl: $EXCHANGE_URL,
merchantBaseUrl: $MERCHANT_URL,
}' \
@@ -229,27 +116,28 @@ taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'runIntegrationTest' \
--arg EXCHANGE_URL "$EXCHANGE_URL" \
--arg BANK_URL "$BANK_URL"
)" &> taler-wallet-cli.log
+echo " DONE"
-
-echo "Shutting down services"
-cleanup
+taler-wallet-cli --wallet-db="$WALLET_DB" run-until-done
# Dump database
-echo "Dumping database"
-pg_dump -O $TARGET_DB | sed -e '/AS integer/d' > ${BASEDB}.sql
-
-echo $MASTER_PUB > ${BASEDB}.mpub
+mkdir -p "$(dirname "$BASEDB")"
-date +%s > ${BASEDB}.age
+echo "Dumping database ${BASEDB}.sql"
+pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql"
+cp "${CONF}.edited" "${BASEDB}.conf"
+cp "$(taler-config -c "${CONF}.edited" -s exchange-offline -o MASTER_PRIV_FILE -f)" "${BASEDB}.mpriv"
# clean up
-echo "Final clean up"
-dropdb $TARGET_DB
-
-rm -rf $DATA_DIR || true
+echo -n "Final clean up ..."
+kill -TERM "$SETUP_PID"
+wait
+unset SETUP_PID
+dropdb "auditor-basedb"
+echo " DONE"
echo "====================================="
-echo " Finished generation of $BASEDB"
+echo "Finished generation of ${BASEDB}.sql"
echo "====================================="
exit 0
diff --git a/src/auditor/generate-kyc-basedb.conf b/src/auditor/generate-kyc-basedb.conf
new file mode 100644
index 000000000..7f4a55cee
--- /dev/null
+++ b/src/auditor/generate-kyc-basedb.conf
@@ -0,0 +1,4 @@
+# This file is in the public domain.
+@INLINE@ generate-auditor-basedb.conf
+
+# FIXME: add options for KYC here! \ No newline at end of file
diff --git a/src/auditor/generate-revoke-basedb.sh b/src/auditor/generate-revoke-basedb.sh
index 2be431199..29aa74b27 100755
--- a/src/auditor/generate-revoke-basedb.sh
+++ b/src/auditor/generate-revoke-basedb.sh
@@ -6,263 +6,138 @@
# create/drop databases.
#
set -eu
+# set -x
-# Cleanup to run whenever we exit
-function cleanup()
-{
- for n in `jobs -p`
- do
- kill $n 2> /dev/null || true
- done
- wait
-}
-
-# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
-
-# Exit, with status code "skip" (no 'real' failure)
-function exit_skip() {
- echo $1
- exit 77
-}
+. setup.sh
-# Where do we write the result?
-export BASEDB=${1:-"revoke-basedb"}
-
-# Name of the Postgres database we will use for the script.
-# Will be dropped, do NOT use anything that might be used
-# elsewhere
-export TARGET_DB=`basename ${BASEDB}`
-TMP_DIR=`mktemp -d revocation-tmp-XXXXXX`
-export WALLET_DB=wallet-revocation.json
-rm -f $WALLET_DB
-
-# Configuration file will be edited, so we create one
-# from the template.
-export CONF=generate-auditor-basedb-revocation.conf
-cp generate-auditor-basedb.conf $CONF
-
-
-echo -n "Testing for taler-bank-manage"
-taler-bank-manage --help >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-echo -n "Testing for taler-wallet-cli"
-taler-wallet-cli -v >/dev/null </dev/null || exit_skip " MISSING"
-echo " FOUND"
-echo -n "Testing for curl"
+echo -n "Testing for curl ..."
curl --help >/dev/null </dev/null || exit_skip " MISSING"
echo " FOUND"
-
-
-# Clean up
-DATA_DIR=`taler-config -f -c $CONF -s PATHS -o TALER_HOME`
-rm -rf $DATA_DIR || true
+CONF="generate-auditor-basedb.conf"
# reset database
-dropdb $TARGET_DB >/dev/null 2>/dev/null || true
-createdb $TARGET_DB || exit_skip "Could not create database $TARGET_DB"
-
-# obtain key configuration data
-MASTER_PRIV_FILE=`taler-config -f -c $CONF -s exchange-offline -o MASTER_PRIV_FILE`
-MASTER_PRIV_DIR=`dirname $MASTER_PRIV_FILE`
-mkdir -p $MASTER_PRIV_DIR
-gnunet-ecc -g1 $MASTER_PRIV_FILE > /dev/null
-export MASTER_PUB=`gnunet-ecc -p $MASTER_PRIV_FILE`
-export EXCHANGE_URL=`taler-config -c $CONF -s EXCHANGE -o BASE_URL`
-MERCHANT_PORT=`taler-config -c $CONF -s MERCHANT -o PORT`
-export MERCHANT_URL=http://localhost:${MERCHANT_PORT}/
-BANK_PORT=`taler-config -c $CONF -s BANK -o HTTP_PORT`
-export BANK_URL=http://localhost:${BANK_PORT}/
-export AUDITOR_URL=http://localhost:8083/
-AUDITOR_PRIV_FILE=`taler-config -f -c $CONF -s AUDITOR -o AUDITOR_PRIV_FILE`
-AUDITOR_PRIV_DIR=`dirname $AUDITOR_PRIV_FILE`
-mkdir -p $AUDITOR_PRIV_DIR
-gnunet-ecc -g1 $AUDITOR_PRIV_FILE > /dev/null
-AUDITOR_PUB=`gnunet-ecc -p $AUDITOR_PRIV_FILE`
-
-# patch configuration
-taler-config -c $CONF -s exchange -o MASTER_PUBLIC_KEY -V $MASTER_PUB
-taler-config -c $CONF -s merchant-exchange-default -o MASTER_KEY -V $MASTER_PUB
-taler-config -c $CONF -s exchangedb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s auditordb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s merchantdb-postgres -o CONFIG -V postgres:///$TARGET_DB
-taler-config -c $CONF -s bank -o database -V postgres:///$TARGET_DB
-taler-config -c $CONF -s exchange -o KEYDIR -V "${TMP_DIR}/keydir/"
-taler-config -c $CONF -s exchange -o REVOCATION_DIR -V "${TMP_DIR}/revdir/"
-
-# setup exchange
-echo "Setting up exchange"
-taler-exchange-dbinit -c $CONF
-
-echo "Setting up merchant"
-taler-merchant-dbinit -c $CONF
-
-# setup auditor
-echo "Setting up auditor"
-taler-auditor-dbinit -c $CONF
-taler-auditor-exchange -c $CONF -m $MASTER_PUB -u $EXCHANGE_URL
-
-# Launch services
-echo "Launching services"
-taler-bank-manage-testing $CONF postgres:///$TARGET_DB serve &> revocation-bank.log &
-TFN=`which taler-exchange-httpd`
-TBINPFX=`dirname $TFN`
-TLIBEXEC=${TBINPFX}/../lib/taler/libexec/
-taler-exchange-secmod-eddsa -c $CONF 2> taler-exchange-secmod-eddsa.log &
-SIGNKEY_HELPER_PID=$!
-taler-exchange-secmod-rsa -c $CONF 2> taler-exchange-secmod-rsa.log &
-RSA_DENOM_HELPER_PID=$!
-taler-exchange-secmod-cs -c $CONF 2> taler-exchange-secmod-cs.log &
-CS_DENOM_HELPER_PID=$!
-taler-exchange-httpd -c $CONF 2> taler-exchange-httpd.log &
-EXCHANGE_PID=$!
-taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
-MERCHANT_PID=$!
-taler-exchange-wirewatch -c $CONF 2> taler-exchange-wirewatch.log &
-taler-auditor-httpd -c $CONF 2> taler-auditor-httpd.log &
-
-# Wait for all bank to be available (usually the slowest)
-for n in `seq 1 50`
-do
- echo -n "."
- sleep 0.2
- OK=0
- # bank
- wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- exit_skip "Failed to launch Bank services"
-fi
-
-# Wait for all other services to be available
-for n in `seq 1 50`
-do
- echo -n "."
- sleep 0.1
- OK=0
- # exchange
- wget http://localhost:8081/seed -o /dev/null -O /dev/null >/dev/null || continue
- # merchant
- wget http://localhost:9966/ -o /dev/null -O /dev/null >/dev/null || continue
- # Auditor
- wget http://localhost:8083/ -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- cleanup
- exit_skip "Failed to launch Taler services"
-fi
+echo -n "Reset 'auditor-basedb' database ..."
+dropdb "auditor-basedb" >/dev/null 2>/dev/null || true
+createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB'"
echo " DONE"
-echo -n "Setting up keys"
-
-taler-exchange-offline -c $CONF \
- download sign \
- enable-account payto://x-taler-bank/localhost/Exchange \
- enable-auditor $AUDITOR_PUB $AUDITOR_URL "TESTKUDOS Auditor" \
- wire-fee now x-taler-bank TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 \
- global-fee now TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 TESTKUDOS:0.01 1h 1h 1year 5 \
- upload &> taler-exchange-offline.log
-
-echo -n "."
-
-for n in `seq 1 2`
-do
- echo -n "."
- OK=0
- # bank
- wget --timeout=1 http://localhost:8081/keys -o /dev/null -O /dev/null >/dev/null || continue
- OK=1
- break
-done
-
-if [ 1 != $OK ]
-then
- exit_skip "Failed to setup keys"
-fi
+# Launch exchange, merchant and bank.
+setup -c "$CONF" \
+ -abemw \
+ -d "iban"
+# obtain key configuration data
+EXCHANGE_URL=$(taler-config -c "$CONF" -s EXCHANGE -o BASE_URL)
+MERCHANT_PORT=$(taler-config -c "$CONF" -s MERCHANT -o PORT)
+MERCHANT_URL="http://localhost:${MERCHANT_PORT}/"
+BANK_PORT=$(taler-config -c "$CONF" -s BANK -o HTTP_PORT)
+BANK_URL="http://localhost:${BANK_PORT}"
-taler-auditor-offline -c $CONF \
- download sign upload &> taler-auditor-offline.log
-
-echo " DONE"
# Setup merchant
-echo -n "Setting up merchant"
-
-curl -H "Content-Type: application/json" -X POST -d '{"auth": {"method": "external"}, "payto_uris":["payto://x-taler-bank/localhost/43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_ms" : 3600000},"default_pay_delay":{"d_ms": 3600000}}' http://localhost:9966/management/instances
+echo -n "Setting up merchant ..."
+curl -H "Content-Type: application/json" -X POST -d '{"auth": {"method": "external"}, "accounts":[{"payto_uri":"payto://iban/SANDBOXX/DE474361?receiver-name=Merchant43"}],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"TESTKUDOS:1", "default_max_deposit_fee":"TESTKUDOS:1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 3600000000},"default_pay_delay":{"d_us": 3600000000},"use_stefan":true}' "${MERCHANT_URL}management/instances"
+echo " DONE"
# run wallet CLI
echo "Running wallet"
-taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'withdrawTestBalance' \
+export WALLET_DB="wallet.wdb"
+rm -f "$WALLET_DB"
+
+taler-wallet-cli \
+ --no-throttle \
+ --wallet-db="$WALLET_DB" \
+ api \
+ --expect-success 'withdrawTestBalance' \
"$(jq -n '
{
amount: "TESTKUDOS:8",
- bankBaseUrl: $BANK_URL,
+ corebankApiBaseUrl: $BANK_URL,
exchangeBaseUrl: $EXCHANGE_URL,
}' \
- --arg BANK_URL $BANK_URL \
- --arg EXCHANGE_URL $EXCHANGE_URL
- )"
+ --arg BANK_URL "$BANK_URL" \
+ --arg EXCHANGE_URL "$EXCHANGE_URL"
+ )" &> taler-wallet-cli-withdraw.log
-taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ --no-throttle \
+ --wallet-db="$WALLET_DB" \
+ run-until-done \
+ &> taler-wallet-cli-withdraw-finish.log
-export coins=$(taler-wallet-cli --wallet-db=$WALLET_DB advanced dump-coins)
+export COINS=$(taler-wallet-cli --wallet-db="$WALLET_DB" advanced dump-coins)
echo -n "COINS are:"
-echo $coins
+echo "$COINS"
# Find coin we want to revoke
-export rc=$(echo "$coins" | jq -r '[.coins[] | select((.denom_value == "TESTKUDOS:2"))][0] | .coin_pub')
+export rc=$(echo "$COINS" | jq -r '[.coins[] | select((.denom_value == "TESTKUDOS:2"))][0] | .coin_pub')
# Find the denom
-export rd=$(echo "$coins" | jq -r '[.coins[] | select((.denom_value == "TESTKUDOS:2"))][0] | .denom_pub_hash')
-echo "Revoking denomination ${rd} (to affect coin ${rc})"
+export rd=$(echo "$COINS" | jq -r '[.coins[] | select((.denom_value == "TESTKUDOS:2"))][0] | .denom_pub_hash')
+echo -n "Revoking denomination ${rd} (to affect coin ${rc}) ..."
# Find all other coins, which will be suspended
-export susp=$(echo "$coins" | jq --arg rc "$rc" '[.coins[] | select(.coin_pub != $rc) | .coin_pub]')
+export susp=$(echo "$COINS" | jq --arg rc "$rc" '[.coins[] | select(.coin_pub != $rc) | .coin_pub]')
# Do the revocation
-taler-exchange-offline -c $CONF \
- revoke-denomination "${rd}" upload &> taler-exchange-offline-revoke.log
-
+taler-exchange-offline \
+ -c $CONF \
+ revoke-denomination "${rd}" \
+ upload \
+ &> taler-exchange-offline-revoke.log
+echo "DONE"
+
+echo -n "Signing replacement keys ..."
sleep 1 # Give exchange time to create replacmenent key
# Re-sign replacement keys
-taler-auditor-offline -c $CONF \
- download sign upload &> taler-auditor-offline.log
+taler-auditor-offline \
+ -c $CONF \
+ download \
+ sign \
+ upload \
+ &> taler-auditor-offline-reinit.log
+echo " DONE"
# Now we suspend the other coins, so later we will pay with the recouped coin
-taler-wallet-cli --wallet-db=$WALLET_DB advanced suspend-coins "$susp"
+taler-wallet-cli \
+ --wallet-db="$WALLET_DB" \
+ advanced \
+ suspend-coins "$susp"
# Update exchange /keys so recoup gets scheduled
-taler-wallet-cli --wallet-db=$WALLET_DB exchanges update \
- -f $EXCHANGE_URL
+taler-wallet-cli \
+ --wallet-db="$WALLET_DB" \
+ exchanges \
+ update \
+ -f "$EXCHANGE_URL"
# Block until scheduled operations are done
-taler-wallet-cli --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ --wallet-db="$WALLET_DB"\
+ run-until-done
-# Now we buy something, only the coins resulting from recouped will be
+# Now we buy something, only the coins resulting from recoup will be
# used, as other ones are suspended
-taler-wallet-cli --no-throttle --wallet-db=$WALLET_DB api 'testPay' \
+taler-wallet-cli \
+ --no-throttle \
+ --wallet-db="$WALLET_DB" \
+ api \
+ 'testPay' \
"$(jq -n '
{
amount: "TESTKUDOS:1",
merchantBaseUrl: $MERCHANT_URL,
summary: "foo",
}' \
- --arg MERCHANT_URL $MERCHANT_URL
+ --arg MERCHANT_URL "$MERCHANT_URL"
)"
-taler-wallet-cli --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ --wallet-db="$WALLET_DB" \
+ run-until-done
echo "Purchase with recoup'ed coin (via reserve) done"
@@ -275,9 +150,6 @@ echo "Will refresh coin ${rrc} of denomination ${zombie_denom}"
# Find all other coins, which will be suspended
export susp=$(echo "$coins" | jq --arg rrc "$rrc" '[.coins[] | select(.coin_pub != $rrc) | .coin_pub]')
-export rrc
-export zombie_denom
-
# Travel into the future! (must match DURATION_WITHDRAW option)
export TIMETRAVEL="--timetravel=604800000000"
@@ -286,13 +158,13 @@ kill -TERM $EXCHANGE_PID
kill -TERM $RSA_DENOM_HELPER_PID
kill -TERM $CS_DENOM_HELPER_PID
kill -TERM $SIGNKEY_HELPER_PID
-taler-exchange-secmod-eddsa $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-eddsa.log &
+taler-exchange-secmod-eddsa $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-eddsa.log &
SIGNKEY_HELPER_PID=$!
-taler-exchange-secmod-rsa $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-rsa.log &
+taler-exchange-secmod-rsa $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-rsa.log &
RSA_DENOM_HELPER_PID=$!
-taler-exchange-secmod-cs $TIMETRAVEL -c $CONF 2> taler-exchange-secmod-cs.log &
+taler-exchange-secmod-cs $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-secmod-cs.log &
CS_DENOM_HELPER_PID=$!
-taler-exchange-httpd $TIMETRAVEL -c $CONF 2> taler-exchange-httpd.log &
+taler-exchange-httpd $TIMETRAVEL -c $CONF 2> ${MY_TMP_DIR}/taler-exchange-httpd.log &
export EXCHANGE_PID=$!
# Wait for exchange to be available
@@ -308,8 +180,15 @@ do
done
echo "Refreshing coin $rrc"
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB advanced force-refresh "$rrc"
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ "$TIMETRAVEL" \
+ --wallet-db="$WALLET_DB" \
+ advanced force-refresh \
+ "$rrc"
+taler-wallet-cli \
+ "$TIMETRAVEL" \
+ --wallet-db="$WALLET_DB" \
+ run-until-done
# Update our list of the coins
export coins=$(taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB advanced dump-coins)
@@ -332,29 +211,49 @@ export susp=$(echo "$coins" | jq --arg freshc "$freshc" '[.coins[] | select(.coi
# Do the revocation of freshc
echo "Revoking ${fresh_denom} (to affect coin ${freshc})"
-taler-exchange-offline -c $CONF \
- revoke-denomination "${fresh_denom}" upload &> taler-exchange-offline-revoke-2.log
+taler-exchange-offline \
+ -c "$CONF" \
+ revoke-denomination \
+ "${fresh_denom}" \
+ upload &> taler-exchange-offline-revoke-2.log
sleep 1 # Give exchange time to create replacmenent key
# Re-sign replacement keys
-taler-auditor-offline -c $CONF \
- download sign upload &> taler-auditor-offline.log
+taler-auditor-offline \
+ -c "$CONF" \
+ download \
+ sign \
+ upload &> taler-auditor-offline.log
# Now we suspend the other coins, so later we will pay with the recouped coin
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB advanced suspend-coins "$susp"
+taler-wallet-cli \
+ "$TIMETRAVEL" \
+ --wallet-db="$WALLET_DB" \
+ advanced \
+ suspend-coins "$susp"
# Update exchange /keys so recoup gets scheduled
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB exchanges update \
- -f $EXCHANGE_URL
+taler-wallet-cli \
+ "$TIMETRAVEL"\
+ --wallet-db="$WALLET_DB" \
+ exchanges update \
+ -f "$EXCHANGE_URL"
# Block until scheduled operations are done
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ "$TIMETRAVEL" \
+ --wallet-db="$WALLET_DB" \
+ run-until-done
echo "Restarting merchant (so new keys are known)"
kill -TERM $MERCHANT_PID
-taler-merchant-httpd -c $CONF -L INFO 2> taler-merchant-httpd.log &
+taler-merchant-httpd \
+ -c "$CONF" \
+ -L INFO \
+ 2> ${MY_TMP_DIR}/taler-merchant-httpd.log &
MERCHANT_PID=$!
+
# Wait for merchant to be again available
for n in `seq 1 50`
do
@@ -378,30 +277,35 @@ taler-wallet-cli $TIMETRAVEL --no-throttle --wallet-db=$WALLET_DB api 'testPay'
}' \
--arg MERCHANT_URL $MERCHANT_URL
)"
-taler-wallet-cli $TIMETRAVEL --wallet-db=$WALLET_DB run-until-done
+taler-wallet-cli \
+ "$TIMETRAVEL" \
+ --wallet-db="$WALLET_DB" \
+ run-until-done
echo "Bought something with refresh-recouped coin"
echo "Shutting down services"
-cleanup
+exit_cleanup
-# Dump database
-echo "Dumping database"
-pg_dump -O $TARGET_DB | sed -e '/AS integer/d' > ${BASEDB}.sql
+# Where do we write the result?
+export BASEDB=${1:-"revoke-basedb"}
+
-echo $MASTER_PUB > ${BASEDB}.mpub
-date +%s > ${BASEDB}.age
+# Dump database
+echo "Dumping database ${BASEDB}.sql"
+pg_dump -O "auditor-basedb" | sed -e '/AS integer/d' > "${BASEDB}.sql"
# clean up
-echo "Final clean up"
-dropdb $TARGET_DB
-rm -rf $DATA_DIR || true
-rm -f $CONF
-rm -r $TMP_DIR
+echo -n "Final clean up ..."
+kill -TERM "$SETUP_PID"
+wait
+unset SETUP_PID
+dropdb "auditor-basedb"
+echo " DONE"
echo "====================================="
-echo " Finished revocation DB generation "
+echo "Finished generation of ${BASEDB}.sql"
echo "====================================="
exit 0
diff --git a/src/auditor/generate_auditordb_home/.local/share/taler/exchange-offline/master.priv b/src/auditor/generate_auditordb_home/.local/share/taler/exchange-offline/master.priv
new file mode 100644
index 000000000..85195dd8f
--- /dev/null
+++ b/src/auditor/generate_auditordb_home/.local/share/taler/exchange-offline/master.priv
@@ -0,0 +1 @@
+%I7qYX2@%'1OJ \ No newline at end of file
diff --git a/src/auditor/report-lib.c b/src/auditor/report-lib.c
index e4f66b31c..d0e1325ea 100644
--- a/src/auditor/report-lib.c
+++ b/src/auditor/report-lib.c
@@ -260,7 +260,7 @@ TALER_ARL_get_denomination_info (
*
* @param analysis analysis to run
* @param analysis_cls closure for @a analysis
- * @return #GNUNET_OK if @a analysis succeessfully committed,
+ * @return #GNUNET_OK if @a analysis successfully committed,
* #GNUNET_NO if we had an error on commit (retry may help)
* #GNUNET_SYSERR on hard errors
*/
@@ -361,31 +361,6 @@ TALER_ARL_setup_sessions_and_run (TALER_ARL_Analysis ana,
}
-/**
- * Test if the given @a mpub matches the #TALER_ARL_master_pub.
- * If so, set "found" to GNUNET_YES.
- *
- * @param cls a `int *` pointing to "found"
- * @param mpub exchange master public key to compare
- * @param exchange_url URL of the exchange (ignored)
- */
-static void
-test_master_present (void *cls,
- const struct TALER_MasterPublicKeyP *mpub,
- const char *exchange_url)
-{
- int *found = cls;
-
- if (0 == GNUNET_memcmp (mpub,
- &TALER_ARL_master_pub))
- {
- *found = GNUNET_YES;
- GNUNET_free (TALER_ARL_exchange_url);
- TALER_ARL_exchange_url = GNUNET_strdup (exchange_url);
- }
-}
-
-
void
TALER_ARL_amount_add_ (struct TALER_Amount *sum,
const struct TALER_Amount *a1,
@@ -557,6 +532,18 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
"BASE_URL");
return GNUNET_SYSERR;
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (TALER_ARL_cfg,
+ "exchange",
+ "BASE_URL",
+ &TALER_ARL_exchange_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+
if (GNUNET_is_zero (&TALER_ARL_master_pub))
{
/* -m option not given, try configuration */
@@ -588,6 +575,9 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
GNUNET_free (master_public_key_str);
return GNUNET_SYSERR;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running auditor against exchange master public key `%s'\n",
+ master_public_key_str);
GNUNET_free (master_public_key_str);
} /* end of -m not given */
@@ -713,29 +703,13 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c)
TALER_ARL_done (NULL);
return GNUNET_SYSERR;
}
+ if (GNUNET_SYSERR ==
+ TALER_ARL_adb->preflight (TALER_ARL_adb->cls))
{
- int found;
-
- if (GNUNET_SYSERR ==
- TALER_ARL_adb->preflight (TALER_ARL_adb->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to start session with auditor database.\n");
- TALER_ARL_done (NULL);
- return GNUNET_SYSERR;
- }
- found = GNUNET_NO;
- (void) TALER_ARL_adb->list_exchanges (TALER_ARL_adb->cls,
- &test_master_present,
- &found);
- if (GNUNET_NO == found)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Exchange's master public key `%s' not known to auditor DB. Did you forget to run `taler-auditor-exchange`?\n",
- GNUNET_p2s (&TALER_ARL_master_pub.eddsa_pub));
- TALER_ARL_done (NULL);
- return GNUNET_SYSERR;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start session with auditor database.\n");
+ TALER_ARL_done (NULL);
+ return GNUNET_SYSERR;
}
return GNUNET_OK;
}
diff --git a/src/auditor/report-lib.h b/src/auditor/report-lib.h
index db15494cd..db29abc3a 100644
--- a/src/auditor/report-lib.h
+++ b/src/auditor/report-lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2020 Taler Systems SA
+ Copyright (C) 2016-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero Public License as published by the Free Software
@@ -28,6 +28,52 @@
#include "taler_bank_service.h"
#include "taler_signatures.h"
+/**
+ * Macro to use to access progress point value @a name.
+ */
+#define TALER_ARL_USE_PP(name) TAC_ ## name
+
+/**
+ * Macro to use to declare progress point value @a name.
+ */
+#define TALER_ARL_DEF_PP(name) \
+ uint64_t TALER_ARL_USE_PP (name) = 0
+
+/**
+ * Macro to use to GET progress point value @a name from DB.
+ */
+#define TALER_ARL_GET_PP(name) \
+ TALER_S (name), &TALER_ARL_USE_PP (name)
+
+/**
+ * Macro to use to SET progress point value @a name in DB.
+ */
+#define TALER_ARL_SET_PP(name) \
+ TALER_S (name), TALER_ARL_USE_PP (name)
+
+/**
+ * Macro to use to access amount balance @a name.
+ */
+#define TALER_ARL_USE_AB(name) TAC_ ## name
+
+/**
+ * Macro to use to declare amount balance @a name.
+ */
+#define TALER_ARL_DEF_AB(name) \
+ struct TALER_Amount TALER_ARL_USE_AB (name)
+
+/**
+ * Macro to use to GET amount balance @a name from DB.
+ */
+#define TALER_ARL_GET_AB(name) \
+ TALER_S (name), &TALER_ARL_USE_AB (name)
+
+/**
+ * Macro to use to SET amount balance @a name in DB.
+ */
+#define TALER_ARL_SET_AB(name) \
+ TALER_S (name), &TALER_ARL_USE_AB (name)
+
/**
* Command-line option "-r": restart audit from scratch
diff --git a/src/auditor/revoke-basedb.age b/src/auditor/revoke-basedb.age
deleted file mode 100644
index 9e02070a6..000000000
--- a/src/auditor/revoke-basedb.age
+++ /dev/null
@@ -1 +0,0 @@
-1655640625
diff --git a/src/auditor/revoke-basedb.conf b/src/auditor/revoke-basedb.conf
index 5209cc2ce..706f97347 100644
--- a/src/auditor/revoke-basedb.conf
+++ b/src/auditor/revoke-basedb.conf
@@ -4,31 +4,31 @@ TINY_AMOUNT = TESTKUDOS:0.01
BASE_URL = http://localhost:8083/
[exchange-account-1]
-PAYTO_URI = payto://x-taler-bank/localhost/Exchange
+PAYTO_URI = payto://iban/SANDBOXX/DE717324?receiver-name=Exchange+Company
enable_debit = yes
enable_credit = yes
[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/taler-wire-gateway/Exchange/"
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/exchange/taler-wire-gateway/"
WIRE_GATEWAY_AUTH_METHOD = basic
-USERNAME = Exchange
+USERNAME = exchange
PASSWORD = x
[exchangedb]
WIREFEE_BASE_DIR = ${PWD}/wirefees/
[auditordb-postgres]
-CONFIG = postgres:///taler-auditor-test
+CONFIG = postgres:///revoke-basedb
[exchangedb-postgres]
-CONFIG = postgres:///taler-auditor-test
+CONFIG = postgres:///revoke-basedb
[taler]
CURRENCY = TESTKUDOS
CURRENCY_ROUND_UNIT = TESTKUDOS:0.01
[bank]
-DATABASE = postgres:///taler-auditor-test
+DATABASE = postgres:///revoke-basedb
MAX_DEBT = TESTKUDOS:50.0
MAX_DEBT_BANK = TESTKUDOS:100000.0
HTTP_PORT = 8082
diff --git a/src/auditor/revoke-basedb.fees b/src/auditor/revoke-basedb.fees
deleted file mode 100644
index d9b45a374..000000000
--- a/src/auditor/revoke-basedb.fees
+++ /dev/null
Binary files differ
diff --git a/src/auditor/revoke-basedb.mpub b/src/auditor/revoke-basedb.mpub
deleted file mode 100644
index 483d1f7dc..000000000
--- a/src/auditor/revoke-basedb.mpub
+++ /dev/null
@@ -1 +0,0 @@
-MREDG0XYVSX4RPYSA6JNQZ93P2DDBG45F3M6RBZXRS49M0JTVN40
diff --git a/src/auditor/revoke-basedb.sql b/src/auditor/revoke-basedb.sql
deleted file mode 100644
index f0aff7650..000000000
--- a/src/auditor/revoke-basedb.sql
+++ /dev/null
@@ -1,17003 +0,0 @@
---
--- PostgreSQL database dump
---
-
--- Dumped from database version 13.7 (Debian 13.7-0+deb11u1)
--- Dumped by pg_dump version 13.7 (Debian 13.7-0+deb11u1)
-
-SET statement_timeout = 0;
-SET lock_timeout = 0;
-SET idle_in_transaction_session_timeout = 0;
-SET client_encoding = 'UTF8';
-SET standard_conforming_strings = on;
-SELECT pg_catalog.set_config('search_path', '', false);
-SET check_function_bodies = false;
-SET xmloption = content;
-SET client_min_messages = warning;
-SET row_security = off;
-
---
--- Name: _v; Type: SCHEMA; Schema: -; Owner: -
---
-
-CREATE SCHEMA _v;
-
-
---
--- Name: SCHEMA _v; Type: COMMENT; Schema: -; Owner: -
---
-
-COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
-
-
---
--- Name: assert_patch_is_applied(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_patch_is_applied(in_patch_name text) RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- t_text TEXT;
-BEGIN
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF NOT FOUND THEN
- RAISE EXCEPTION 'Patch % is not applied!', in_patch_name;
- END IF;
- RETURN format('Patch %s is applied.', in_patch_name);
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_patch_is_applied(in_patch_name text); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_patch_is_applied(in_patch_name text) IS 'Function that can be used to make sure that patch has been applied.';
-
-
---
--- Name: assert_user_is_not_superuser(); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_not_superuser() RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RAISE EXCEPTION 'Current user is superuser - cannot continue.';
- END IF;
- RETURN 'assert_user_is_not_superuser: OK';
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_not_superuser(); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_not_superuser() IS 'Function that can be used to make sure that patch is being applied using normal (not superuser) account.';
-
-
---
--- Name: assert_user_is_one_of(text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_one_of(VARIADIC p_acceptable_users text[]) RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
-BEGIN
- IF current_user = any( p_acceptable_users ) THEN
- RETURN 'assert_user_is_one_of: OK';
- END IF;
- RAISE EXCEPTION 'User is not one of: % - cannot continue.', p_acceptable_users;
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_one_of(VARIADIC p_acceptable_users text[]); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_one_of(VARIADIC p_acceptable_users text[]) IS 'Function that can be used to make sure that patch is being applied by one of defined users.';
-
-
---
--- Name: assert_user_is_superuser(); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.assert_user_is_superuser() RETURNS text
- LANGUAGE plpgsql
- AS $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RETURN 'assert_user_is_superuser: OK';
- END IF;
- RAISE EXCEPTION 'Current user is not superuser - cannot continue.';
-END;
-$$;
-
-
---
--- Name: FUNCTION assert_user_is_superuser(); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.assert_user_is_superuser() IS 'Function that can be used to make sure that patch is being applied using superuser account.';
-
-
---
--- Name: register_patch(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(text) RETURNS SETOF integer
- LANGUAGE sql
- AS $_$
- SELECT _v.register_patch( $1, NULL, NULL );
-$_$;
-
-
---
--- Name: FUNCTION register_patch(text); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(text) IS 'Wrapper to allow registration of patches without requirements and conflicts.';
-
-
---
--- Name: register_patch(text, text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(text, text[]) RETURNS SETOF integer
- LANGUAGE sql
- AS $_$
- SELECT _v.register_patch( $1, $2, NULL );
-$_$;
-
-
---
--- Name: FUNCTION register_patch(text, text[]); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(text, text[]) IS 'Wrapper to allow registration of patches without conflicts.';
-
-
---
--- Name: register_patch(text, text[], text[]); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer) RETURNS SETOF integer
- LANGUAGE plpgsql
- AS $$
-DECLARE
- t_text TEXT;
- t_text_a TEXT[];
- i INT4;
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF FOUND THEN
- RAISE EXCEPTION 'Patch % is already applied!', in_patch_name;
- END IF;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE patch_name = any( in_conflicts ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Versioning patches conflict. Conflicting patche(s) installed: %.', array_to_string( t_text_a, ', ' );
- END IF;
-
- IF array_upper( in_requirements, 1 ) IS NOT NULL THEN
- t_text_a := '{}';
- FOR i IN array_lower( in_requirements, 1 ) .. array_upper( in_requirements, 1 ) LOOP
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_requirements[i];
- IF NOT FOUND THEN
- t_text_a := t_text_a || in_requirements[i];
- END IF;
- END LOOP;
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Missing prerequisite(s): %.', array_to_string( t_text_a, ', ' );
- END IF;
- END IF;
-
- INSERT INTO _v.patches (patch_name, applied_tsz, applied_by, requires, conflicts ) VALUES ( in_patch_name, now(), current_user, coalesce( in_requirements, '{}' ), coalesce( in_conflicts, '{}' ) );
- RETURN;
-END;
-$$;
-
-
---
--- Name: FUNCTION register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.register_patch(in_patch_name text, in_requirements text[], in_conflicts text[], OUT versioning integer) IS 'Function to register patches in database. Raises exception if there are conflicts, prerequisites are not installed or the migration has already been installed.';
-
-
---
--- Name: unregister_patch(text); Type: FUNCTION; Schema: _v; Owner: -
---
-
-CREATE FUNCTION _v.unregister_patch(in_patch_name text, OUT versioning integer) RETURNS SETOF integer
- LANGUAGE plpgsql
- AS $$
-DECLARE
- i INT4;
- t_text_a TEXT[];
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE in_patch_name = ANY( requires ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Cannot uninstall %, as it is required by: %.', in_patch_name, array_to_string( t_text_a, ', ' );
- END IF;
-
- DELETE FROM _v.patches WHERE patch_name = in_patch_name;
- GET DIAGNOSTICS i = ROW_COUNT;
- IF i < 1 THEN
- RAISE EXCEPTION 'Patch % is not installed, so it can''t be uninstalled!', in_patch_name;
- END IF;
-
- RETURN;
-END;
-$$;
-
-
---
--- Name: FUNCTION unregister_patch(in_patch_name text, OUT versioning integer); Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON FUNCTION _v.unregister_patch(in_patch_name text, OUT versioning integer) IS 'Function to unregister patches in database. Dies if the patch is not registered, or if unregistering it would break dependencies.';
-
-
---
--- Name: add_constraints_to_account_merges_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_account_merges_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE account_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT account_merges_' || partition_suffix || '_account_merge_request_serial_id_key '
- 'UNIQUE (account_merge_request_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_aggregation_tracking_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_aggregation_tracking_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE aggregation_tracking_' || partition_suffix || ' '
- 'ADD CONSTRAINT aggregation_tracking_' || partition_suffix || '_aggregation_serial_id_key '
- 'UNIQUE (aggregation_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_contracts_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_contracts_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE contracts_' || partition_suffix || ' '
- 'ADD CONSTRAINT contracts_' || partition_suffix || '_contract_serial_id_key '
- 'UNIQUE (contract_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_cs_nonce_locks_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_cs_nonce_locks_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE cs_nonce_locks_' || partition_suffix || ' '
- 'ADD CONSTRAINT cs_nonce_locks_' || partition_suffix || '_cs_nonce_lock_serial_id_key '
- 'UNIQUE (cs_nonce_lock_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_deposits_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_deposits_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT deposits_' || partition_suffix || '_deposit_serial_id_pkey '
- 'PRIMARY KEY (deposit_serial_id) '
- ',ADD CONSTRAINT deposits_' || partition_suffix || '_coin_pub_merchant_pub_h_contract_terms_key '
- 'UNIQUE (coin_pub, merchant_pub, h_contract_terms)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_known_coins_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_known_coins_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE known_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT known_coins_' || partition_suffix || '_known_coin_id_key '
- 'UNIQUE (known_coin_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_deposits_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_deposits_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_deposits_' || partition_suffix || '_purse_deposit_serial_id_key '
- 'UNIQUE (purse_deposit_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_merges_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_merges_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_merges_' || partition_suffix || '_purse_merge_request_serial_id_key '
- 'UNIQUE (purse_merge_request_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_refunds_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_refunds_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_refunds_' || partition_suffix || '_purse_refunds_serial_id_key '
- 'UNIQUE (purse_refunds_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_purse_requests_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_purse_requests_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_requests_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_requests_' || partition_suffix || '_purse_requests_serial_id_key '
- 'UNIQUE (purse_requests_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_recoup_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_recoup_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_' || partition_suffix || '_recoup_uuid_key '
- 'UNIQUE (recoup_uuid) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_recoup_refresh_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_recoup_refresh_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_refresh_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_refresh_' || partition_suffix || '_recoup_refresh_uuid_key '
- 'UNIQUE (recoup_refresh_uuid) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_commitments_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_commitments_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_commitments_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_commitments_' || partition_suffix || '_melt_serial_id_key '
- 'UNIQUE (melt_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_revealed_coins_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_revealed_coins_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_revealed_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_rrc_serial_key '
- 'UNIQUE (rrc_serial) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_coin_ev_key '
- 'UNIQUE (coin_ev) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_h_coin_ev_key '
- 'UNIQUE (h_coin_ev) '
- ',ADD PRIMARY KEY (melt_serial_id, freshcoin_index) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refresh_transfer_keys_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refresh_transfer_keys_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_transfer_keys_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_transfer_keys_' || partition_suffix || '_rtc_serial_key '
- 'UNIQUE (rtc_serial)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_refunds_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_refunds_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT refunds_' || partition_suffix || '_refund_serial_id_key '
- 'UNIQUE (refund_serial_id) '
- ',ADD PRIMARY KEY (deposit_serial_id, rtransaction_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_close_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_close_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_close_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_close_' || partition_suffix || '_close_uuid_pkey '
- 'PRIMARY KEY (close_uuid)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_in_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_in_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_in_' || partition_suffix || '_reserve_in_serial_id_key '
- 'UNIQUE (reserve_in_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_reserves_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_reserves_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_out_' || partition_suffix || '_reserve_out_serial_id_key '
- 'UNIQUE (reserve_out_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wad_in_entries_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wad_in_entries_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_in_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_in_entries_' || partition_suffix || '_wad_in_entry_serial_id_key '
- 'UNIQUE (wad_in_entry_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wad_out_entries_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wad_out_entries_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_out_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_out_entries_' || partition_suffix || '_wad_out_entry_serial_id_key '
- 'UNIQUE (wad_out_entry_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wads_in_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wads_in_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_in_serial_id_key '
- 'UNIQUE (wad_in_serial_id) '
- ',ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_is_origin_exchange_url_key '
- 'UNIQUE (wad_id, origin_exchange_url) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wads_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wads_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_out_' || partition_suffix || '_wad_out_serial_id_key '
- 'UNIQUE (wad_out_serial_id) '
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wire_out_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wire_out_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wire_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_out_' || partition_suffix || '_wireout_uuid_pkey '
- 'PRIMARY KEY (wireout_uuid)'
- );
-END
-$$;
-
-
---
--- Name: add_constraints_to_wire_targets_partition(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.add_constraints_to_wire_targets_partition(partition_suffix character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- EXECUTE FORMAT (
- 'ALTER TABLE wire_targets_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_targets_' || partition_suffix || '_wire_target_serial_id_key '
- 'UNIQUE (wire_target_serial_id)'
- );
-END
-$$;
-
-
---
--- Name: create_foreign_hash_partition(character varying, integer, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_hash_partition(source_table_name character varying, modulus integer, shard_suffix character varying, current_shard_num integer, local_user character varying DEFAULT 'taler-exchange-httpd'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating %_% on %', source_table_name, shard_suffix, shard_suffix;
-
- EXECUTE FORMAT(
- 'CREATE FOREIGN TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s) '
- 'SERVER %I'
- ,source_table_name || '_' || shard_suffix
- ,source_table_name
- ,modulus
- ,current_shard_num-1
- ,shard_suffix
- );
-
- EXECUTE FORMAT(
- 'ALTER FOREIGN TABLE %I OWNER TO %I'
- ,source_table_name || '_' || shard_suffix
- ,local_user
- );
-
-END
-$$;
-
-
---
--- Name: create_foreign_range_partition(character varying, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_range_partition(source_table_name character varying, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-
---
--- Name: create_foreign_servers(integer, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_foreign_servers(amount integer, domain character varying, remote_user character varying DEFAULT 'taler'::character varying, remote_user_password character varying DEFAULT 'taler'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM prepare_sharding();
-
- FOR i IN 1..amount LOOP
- PERFORM create_shard_server(
- i::varchar
- ,amount
- ,i
- ,'shard-' || i::varchar || '.' || domain
- ,remote_user
- ,remote_user_password
- ,'taler-exchange'
- ,'5432'
- ,'taler-exchange-httpd'
- );
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
-
---
--- Name: create_hash_partition(character varying, integer, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_hash_partition(source_table_name character varying, modulus integer, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating partition %_%', source_table_name, partition_num;
-
- EXECUTE FORMAT(
- 'CREATE TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
- ,source_table_name || '_' || partition_num
- ,source_table_name
- ,modulus
- ,partition_num-1
- );
-
-END
-$$;
-
-
---
--- Name: create_partitioned_table(character varying, character varying, character varying, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_partitioned_table(table_definition character varying, table_name character varying, main_table_partition_str character varying, shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- IF shard_suffix IS NOT NULL THEN
- table_name=table_name || '_' || shard_suffix;
- main_table_partition_str = '';
- END IF;
-
- EXECUTE FORMAT(
- table_definition,
- table_name,
- main_table_partition_str
- );
-
-END
-$$;
-
-
---
--- Name: create_partitions(integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_partitions(num_partitions integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- modulus INTEGER;
-BEGIN
-
- modulus := num_partitions;
-
- PERFORM detach_default_partitions();
-
- LOOP
-
- PERFORM create_hash_partition(
- 'wire_targets'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_targets_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'reserves_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_close'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_close_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'known_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_known_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_commitments'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_commitments_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_revealed_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_revealed_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_transfer_keys'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_transfer_keys_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_deposits_partition(num_partitions::varchar);
-
--- TODO: dynamically (!) creating/deleting deposits partitions:
--- create new partitions 'as needed', drop old ones once the aggregator has made
--- them empty; as 'new' deposits will always have deadlines in the future, this
--- would basically guarantee no conflict between aggregator and exchange service!
--- SEE also: https://www.cybertec-postgresql.com/en/automatic-partition-creation-in-postgresql/
--- (article is slightly wrong, as this works:)
---CREATE TABLE tab (
--- id bigint GENERATED ALWAYS AS IDENTITY,
--- ts timestamp NOT NULL,
--- data text
--- PARTITION BY LIST ((ts::date));
--- CREATE TABLE tab_def PARTITION OF tab DEFAULT;
--- BEGIN
--- CREATE TABLE tab_part2 (LIKE tab);
--- insert into tab_part2 (id,ts, data) values (5,'2022-03-21', 'foo');
--- alter table tab attach partition tab_part2 for values in ('2022-03-21');
--- commit;
--- Naturally, to ensure this is actually 100% conflict-free, we'd
--- need to create tables at the granularity of the wire/refund deadlines;
--- that is right now configurable via AGGREGATOR_SHIFT option.
-
--- FIXME: range partitioning
--- PERFORM create_range_partition(
--- 'deposits_by_ready'
--- ,modulus
--- ,num_partitions
--- );
---
--- PERFORM create_range_partition(
--- 'deposits_for_matching'
--- ,modulus
--- ,num_partitions
--- );
-
- PERFORM create_hash_partition(
- 'refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wire_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'aggregation_transient'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'aggregation_tracking'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_aggregation_tracking_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'recoup_refresh'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_refresh_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'prewire'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'cs_nonce_locks'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_cs_nonce_locks_partition(num_partitions::varchar);
-
- ---------------- P2P ----------------------
-
- PERFORM create_hash_partition(
- 'purse_requests'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_requests_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'account_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_account_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'contracts'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_contracts_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'history_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'close_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'purse_deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_deposits_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_out_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_out_entries_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wads_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wads_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_in_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_in_entries_partition(num_partitions::varchar);
-
- num_partitions=num_partitions-1;
- EXIT WHEN num_partitions=0;
-
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
-
---
--- Name: create_range_partition(character varying, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_range_partition(source_table_name character varying, partition_num integer) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-
---
--- Name: create_shard_server(character varying, integer, integer, character varying, character varying, character varying, character varying, integer, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying DEFAULT 'taler-exchange'::character varying, remote_port integer DEFAULT 5432, local_user character varying DEFAULT 'taler-exchange-httpd'::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Creating server %', remote_host;
-
- EXECUTE FORMAT(
- 'CREATE SERVER IF NOT EXISTS %I '
- 'FOREIGN DATA WRAPPER postgres_fdw '
- 'OPTIONS (dbname %L, host %L, port %L)'
- ,shard_suffix
- ,remote_db_name
- ,remote_host
- ,remote_port
- );
-
- EXECUTE FORMAT(
- 'CREATE USER MAPPING IF NOT EXISTS '
- 'FOR %I SERVER %I '
- 'OPTIONS (user %L, password %L)'
- ,local_user
- ,shard_suffix
- ,remote_user
- ,remote_user_password
- );
-
- EXECUTE FORMAT(
- 'GRANT ALL PRIVILEGES '
- 'ON FOREIGN SERVER %I '
- 'TO %I;'
- ,shard_suffix
- ,local_user
- );
-
- PERFORM create_foreign_hash_partition(
- 'wire_targets'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_close'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'known_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_commitments'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_revealed_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_transfer_keys'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_by_ready'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_for_matching'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
- PERFORM create_foreign_hash_partition(
- 'refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wire_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_transient'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_tracking'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_refresh'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'prewire'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'cs_nonce_locks'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
- ------------------- P2P --------------------
-
- PERFORM create_foreign_hash_partition(
- 'purse_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'account_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'contracts'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'history_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'close_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_out_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wads_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_in_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
-END
-$$;
-
-
---
--- Name: FUNCTION create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying, remote_port integer, local_user character varying); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.create_shard_server(shard_suffix character varying, total_num_shards integer, current_shard_num integer, remote_host character varying, remote_user character varying, remote_user_password character varying, remote_db_name character varying, remote_port integer, local_user character varying) IS 'Create a shard server on the master
- node with all foreign tables and user mappings';
-
-
---
--- Name: create_table_account_merges(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_account_merges(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'account_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(account_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' -- REFERENCES purse_requests (purse_pub)
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_aggregation_tracking(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_aggregation_tracking(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_tracking';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(aggregation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',deposit_serial_id INT8 PRIMARY KEY' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE' -- FIXME change to coint_pub + deposit_serial_id for more efficient depost -- or something else ???
- ',wtid_raw BYTEA NOT NULL' -- CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (deposit_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wtid_raw_index '
- 'ON ' || table_name || ' '
- '(wtid_raw);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_wtid_raw_index '
- 'IS ' || quote_literal('for lookup_transactions') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_aggregation_transient(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_aggregation_transient(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_transient';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_close_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_close_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'close_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(close_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',close_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',close_val INT8 NOT NULL'
- ',close_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,close_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_contracts(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_contracts(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'contracts';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(contract_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',pub_ckey BYTEA NOT NULL CHECK (LENGTH(pub_ckey)=32)'
- ',contract_sig BYTEA NOT NULL CHECK (LENGTH(contract_sig)=64)'
- ',e_contract BYTEA NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_cs_nonce_locks(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_cs_nonce_locks(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)'
- ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)'
- ',max_denomination_serial INT8 NOT NULL'
- ') %s ;'
- ,'cs_nonce_locks'
- ,'PARTITION BY HASH (nonce)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',known_coin_id INT8 NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE' --- FIXME: column needed???
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wallet_timestamp INT8 NOT NULL'
- ',exchange_timestamp INT8 NOT NULL'
- ',refund_deadline INT8 NOT NULL'
- ',wire_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
- ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',done BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_blocked BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_details_serial_id INT8' -- REFERENCES extension_details (extension_details_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits_by_ready(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits_by_ready(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_by_ready';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_deadline INT8 NOT NULL'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (wire_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(wire_deadline ASC, shard ASC, coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_deposits_for_matching(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_deposits_for_matching(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_for_matching';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (refund_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(refund_deadline ASC, merchant_pub, coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_history_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_history_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'history_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',request_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',history_fee_val INT8 NOT NULL'
- ',history_fee_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,request_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_known_coins(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_known_coins(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'known_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
- ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
- ',denom_sig BYTEA NOT NULL'
- ',remaining_val INT8 NOT NULL DEFAULT(0)'
- ',remaining_frac INT4 NOT NULL DEFAULT(0)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)' -- FIXME: or include denominations_serial? or multi-level partitioning?;
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-
---
--- Name: create_table_prewire(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_prewire(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'prewire';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
- ',wire_method TEXT NOT NULL'
- ',finished BOOLEAN NOT NULL DEFAULT false'
- ',failed BOOLEAN NOT NULL DEFAULT false'
- ',buf BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (prewire_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_finished_index '
- 'ON ' || table_name || ' '
- '(finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_finished_index '
- 'IS ' || quote_literal('for gc_prewire') || ';'
- );
- -- FIXME: find a way to combine these two indices?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_failed_finished_index '
- 'ON ' || table_name || ' '
- '(failed,finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index '
- 'IS ' || quote_literal('for wire_prepare_data_get') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_deposits(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_deposits(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',PRIMARY KEY (purse_pub,coin_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by coin_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_merges(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_merges(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY '-- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(length(reserve_pub)=32)'--REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' --REFERENCES purse_requests (purse_pub) ON DELETE CASCADE
- ',merge_sig BYTEA NOT NULL CHECK (LENGTH(merge_sig)=64)'
- ',merge_timestamp INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_purse_refunds(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_refunds(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_refunds_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-
---
--- Name: create_table_purse_requests(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_purse_requests(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_requests_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',merge_pub BYTEA NOT NULL CHECK (LENGTH(merge_pub)=32)'
- ',purse_creation INT8 NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',age_limit INT4 NOT NULL'
- ',flags INT4 NOT NULL'
- ',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',purse_fee_val INT8 NOT NULL'
- ',purse_fee_frac INT4 NOT NULL'
- ',balance_val INT8 NOT NULL DEFAULT (0)'
- ',balance_frac INT4 NOT NULL DEFAULT (0)'
- ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by merge_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_merge_pub '
- 'ON ' || table_name || ' '
- '(merge_pub);'
- );
-
- -- FIXME: drop index on master (crosses shards)?
- -- Or use materialized index? (needed?)
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_purse_expiration '
- 'ON ' || table_name || ' '
- '(purse_expiration);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves_out (reserve_out_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub);'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup_by_reserve(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup_by_reserve(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves (reserve_out_serial_id) ON DELETE CASCADE
- ',coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_out_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_recoup_refresh(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_recoup_refresh(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_refresh';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_refresh_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',known_coin_id BIGINT NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',rrc_serial INT8 NOT NULL' -- REFERENCES refresh_revealed_coins (rrc_serial) ON DELETE CASCADE -- UNIQUE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: any query using this index will be slow. Materialize index or change query?
- -- Also: which query uses this index?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_rrc_serial_index '
- 'ON ' || table_name || ' '
- '(rrc_serial);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_commitments(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_commitments(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_commitments';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(melt_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
- ',old_coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',noreveal_index INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (rc)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- Note: index spans partitions, may need to be materialized.
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_old_coin_pub_index '
- 'ON ' || table_name || ' '
- '(old_coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_revealed_coins(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_revealed_coins(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_revealed_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rrc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 NOT NULL' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',freshcoin_index INT4 NOT NULL'
- ',link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_ev BYTEA NOT NULL' -- UNIQUE'
- ',h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)' -- UNIQUE'
- ',ev_sig BYTEA NOT NULL'
- ',ewv BYTEA NOT NULL'
- -- ,PRIMARY KEY (melt_serial_id, freshcoin_index) -- done per shard
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_coins_by_melt_serial_id_index '
- 'ON ' || table_name || ' '
- '(melt_serial_id);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refresh_transfer_keys(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refresh_transfer_keys(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_transfer_keys';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rtc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 PRIMARY KEY' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)'
- ',transfer_privs BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_refunds(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_refunds(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8 NOT NULL' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE'
- ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
- ',rtransaction_id INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- -- ,PRIMARY KEY (deposit_serial_id, rtransaction_id) -- done per shard!
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
- ',reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)'
- ',current_balance_val INT8 NOT NULL DEFAULT(0)'
- ',current_balance_frac INT4 NOT NULL DEFAULT(0)'
- ',purses_active INT8 NOT NULL DEFAULT(0)'
- ',purses_allowed INT8 NOT NULL DEFAULT(0)'
- ',kyc_required BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',kyc_passed BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',max_age INT4 NOT NULL DEFAULT(120)'
- ',expiration_date INT8 NOT NULL'
- ',gc_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_expiration_index '
- 'ON ' || table_name || ' '
- '(expiration_date'
- ',current_balance_val'
- ',current_balance_frac'
- ');'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_expiration_index '
- 'IS ' || quote_literal('used in get_expired_reserves') || ';'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_gc_date_index '
- 'ON ' || table_name || ' '
- '(gc_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_gc_date_index '
- 'IS ' || quote_literal('for reserve garbage collection') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_close(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_close(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_close';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE / PRIMARY KEY'
- ',reserve_pub BYTEA NOT NULL' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',execution_date INT8 NOT NULL'
- ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',closing_fee_val INT8 NOT NULL'
- ',closing_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_close_uuid_index '
- 'ON ' || table_name || ' '
- '(close_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-END
-$$;
-
-
---
--- Name: create_table_reserves_in(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_in(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',reserve_pub BYTEA PRIMARY KEY' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',wire_reference INT8 NOT NULL'
- ',credit_val INT8 NOT NULL'
- ',credit_frac INT4 NOT NULL'
- ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',execution_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_in_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_in_serial_id);'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_section_execution_date_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section '
- ',execution_date'
- ');'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_reserve_in_serial_id_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section,'
- 'reserve_in_serial_id DESC'
- ');'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR default 'reserves_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64) UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial)'
- ',denom_sig BYTEA NOT NULL'
- ',reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',execution_date INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,'reserves_out'
- ,'PARTITION BY HASH (h_blind_ev)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_out_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
- -- FIXME: change query to use reserves_out_by_reserve instead and materialize execution_date there as well???
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid, execution_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'IS ' || quote_literal('for get_reserves_out and exchange_do_withdraw_limit_check') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_reserves_out_by_reserve(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_reserves_out_by_reserve(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves_out_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64)'
- ') %s '
- ,table_name
- ,'PARTITION BY HASH (reserve_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wad_in_entries(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wad_in_entries(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_in_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_in_serial_id INT8' -- REFERENCES wads_in (wad_in_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wad_out_entries(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wad_out_entries(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_out_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_out_serial_id INT8' -- REFERENCES wads_out (wad_out_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wads_in(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wads_in(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',origin_exchange_url TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',arrival_time INT8 NOT NULL'
- ',UNIQUE (wad_id, origin_exchange_url)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wads_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wads_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',partner_serial_id INT8 NOT NULL' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',execution_time INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: create_table_wire_out(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wire_out(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wire_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',execution_date INT8 NOT NULL'
- ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wtid_raw)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wire_target_h_payto_index '
- 'ON ' || table_name || ' '
- '(wire_target_h_payto);'
- );
-
-
-END
-$$;
-
-
---
--- Name: create_table_wire_targets(character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.create_table_wire_targets(shard_suffix character varying DEFAULT NULL::character varying) RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)'
- ',payto_uri VARCHAR NOT NULL'
- ',kyc_ok BOOLEAN NOT NULL DEFAULT (FALSE)'
- ',external_id VARCHAR'
- ') %s ;'
- ,'wire_targets'
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
-
---
--- Name: defer_wire_out(); Type: PROCEDURE; Schema: public; Owner: -
---
-
-CREATE PROCEDURE public.defer_wire_out()
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
-IF EXISTS (
- SELECT 1
- FROM information_Schema.constraint_column_usage
- WHERE table_name='wire_out'
- AND constraint_name='wire_out_ref')
-THEN
- SET CONSTRAINTS wire_out_ref DEFERRED;
-END IF;
-
-END $$;
-
-
---
--- Name: deposits_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
-
- IF (was_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_delete_trigger() IS 'Replicate deposit deletions into materialized indices.';
-
-
---
--- Name: deposits_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
-
- IF (is_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_insert_trigger() IS 'Replicate deposit inserts into materialized indices.';
-
-
---
--- Name: deposits_update_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.deposits_update_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
- IF (was_ready AND NOT is_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- IF (is_ready AND NOT was_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION deposits_update_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.deposits_update_trigger() IS 'Replicate deposits changes into materialized indices.';
-
-
---
--- Name: detach_default_partitions(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.detach_default_partitions() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Detaching all default table partitions';
-
- ALTER TABLE IF EXISTS wire_targets
- DETACH PARTITION wire_targets_default;
-
- ALTER TABLE IF EXISTS reserves
- DETACH PARTITION reserves_default;
-
- ALTER TABLE IF EXISTS reserves_in
- DETACH PARTITION reserves_in_default;
-
- ALTER TABLE IF EXISTS reserves_close
- DETACH PARTITION reserves_close_default;
-
- ALTER TABLE IF EXISTS reserves_out
- DETACH PARTITION reserves_out_default;
-
- ALTER TABLE IF EXISTS reserves_out_by_reserve
- DETACH PARTITION reserves_out_by_reserve_default;
-
- ALTER TABLE IF EXISTS known_coins
- DETACH PARTITION known_coins_default;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DETACH PARTITION refresh_commitments_default;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DETACH PARTITION refresh_revealed_coins_default;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DETACH PARTITION refresh_transfer_keys_default;
-
- ALTER TABLE IF EXISTS deposits
- DETACH PARTITION deposits_default;
-
---- TODO range partitioning
--- ALTER TABLE IF EXISTS deposits_by_ready
--- DETACH PARTITION deposits_by_ready_default;
---
--- ALTER TABLE IF EXISTS deposits_for_matching
--- DETACH PARTITION deposits_default_for_matching_default;
-
- ALTER TABLE IF EXISTS refunds
- DETACH PARTITION refunds_default;
-
- ALTER TABLE IF EXISTS wire_out
- DETACH PARTITION wire_out_default;
-
- ALTER TABLE IF EXISTS aggregation_transient
- DETACH PARTITION aggregation_transient_default;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DETACH PARTITION aggregation_tracking_default;
-
- ALTER TABLE IF EXISTS recoup
- DETACH PARTITION recoup_default;
-
- ALTER TABLE IF EXISTS recoup_by_reserve
- DETACH PARTITION recoup_by_reserve_default;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DETACH PARTITION recoup_refresh_default;
-
- ALTER TABLE IF EXISTS prewire
- DETACH PARTITION prewire_default;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DETACH partition cs_nonce_locks_default;
-
- ALTER TABLE IF EXISTS purse_requests
- DETACH partition purse_requests_default;
-
- ALTER TABLE IF EXISTS purse_refunds
- DETACH partition purse_refunds_default;
-
- ALTER TABLE IF EXISTS purse_merges
- DETACH partition purse_merges_default;
-
- ALTER TABLE IF EXISTS account_merges
- DETACH partition account_merges_default;
-
- ALTER TABLE IF EXISTS contracts
- DETACH partition contracts_default;
-
- ALTER TABLE IF EXISTS history_requests
- DETACH partition history_requests_default;
-
- ALTER TABLE IF EXISTS close_requests
- DETACH partition close_requests_default;
-
- ALTER TABLE IF EXISTS purse_deposits
- DETACH partition purse_deposits_default;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DETACH partition wad_out_entries_default;
-
- ALTER TABLE IF EXISTS wads_in
- DETACH partition wads_in_default;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DETACH partition wad_in_entries_default;
-END
-$$;
-
-
---
--- Name: FUNCTION detach_default_partitions(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.detach_default_partitions() IS 'We need to drop default and create new one before deleting the default partitions
- otherwise constraints get lost too. Might be needed in shardig too';
-
-
---
--- Name: drop_default_partitions(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.drop_default_partitions() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- RAISE NOTICE 'Dropping default table partitions';
-
- DROP TABLE IF EXISTS wire_targets_default;
- DROP TABLE IF EXISTS reserves_default;
- DROP TABLE IF EXISTS reserves_in_default;
- DROP TABLE IF EXISTS reserves_close_default;
- DROP TABLE IF EXISTS reserves_out_default;
- DROP TABLE IF EXISTS reserves_out_by_reserve_default;
- DROP TABLE IF EXISTS known_coins_default;
- DROP TABLE IF EXISTS refresh_commitments_default;
- DROP TABLE IF EXISTS refresh_revealed_coins_default;
- DROP TABLE IF EXISTS refresh_transfer_keys_default;
- DROP TABLE IF EXISTS deposits_default;
---DROP TABLE IF EXISTS deposits_by_ready_default;
---DROP TABLE IF EXISTS deposits_for_matching_default;
- DROP TABLE IF EXISTS refunds_default;
- DROP TABLE IF EXISTS wire_out_default;
- DROP TABLE IF EXISTS aggregation_transient_default;
- DROP TABLE IF EXISTS aggregation_tracking_default;
- DROP TABLE IF EXISTS recoup_default;
- DROP TABLE IF EXISTS recoup_by_reserve_default;
- DROP TABLE IF EXISTS recoup_refresh_default;
- DROP TABLE IF EXISTS prewire_default;
- DROP TABLE IF EXISTS cs_nonce_locks_default;
-
- DROP TABLE IF EXISTS purse_requests_default;
- DROP TABLE IF EXISTS purse_refunds_default;
- DROP TABLE IF EXISTS purse_merges_default;
- DROP TABLE IF EXISTS account_merges_default;
- DROP TABLE IF EXISTS contracts_default;
- DROP TABLE IF EXISTS history_requests_default;
- DROP TABLE IF EXISTS close_requests_default;
- DROP TABLE IF EXISTS purse_deposits_default;
- DROP TABLE IF EXISTS wad_out_entries_default;
- DROP TABLE IF EXISTS wads_in_default;
- DROP TABLE IF EXISTS wad_in_entries_default;
-
-END
-$$;
-
-
---
--- Name: FUNCTION drop_default_partitions(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.drop_default_partitions() IS 'Drop all default partitions once other partitions are attached.
- Might be needed in sharding too.';
-
-
---
--- Name: exchange_do_account_merge(bytea, bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_account_merge(in_purse_pub bytea, in_reserve_pub bytea, in_reserve_sig bytea, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
- -- FIXME: function/API is dead! Do DCE?
-END $$;
-
-
---
--- Name: exchange_do_batch_withdraw(bigint, integer, bytea, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_batch_withdraw(amount_val bigint, amount_frac integer, rpub bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.';
-
-
---
--- Name: exchange_do_batch_withdraw_insert(bytea, bigint, integer, bytea, bigint, bytea, bytea, bytea, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- denom_serial INT8;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-out_denom_unknown=TRUE;
-out_conflict=TRUE;
-out_nonce_reuse=TRUE;
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- out_denom_unknown=TRUE;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-out_denom_unknown=FALSE;
-
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- out_conflict=TRUE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
--- Special actions needed for a CS withdraw?
-out_nonce_reuse=FALSE;
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- out_nonce_reuse=TRUE;
- ASSERT false, 'nonce reuse attempted by client';
- RETURN;
- END IF;
- END IF;
-END IF;
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_batch_withdraw_insert(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, ruuid bigint, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, OUT out_denom_unknown boolean, OUT out_nonce_reuse boolean, OUT out_conflict boolean) IS 'Stores information about a planchet for a batch withdraw operation. Checks if the planchet already exists, and in that case indicates a conflict';
-
-
---
--- Name: exchange_do_close_request(bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_close_request(in_reserve_pub bytea, in_reserve_sig bytea, OUT out_final_balance_val bigint, OUT out_final_balance_frac integer, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
- -- FIXME
-END $$;
-
-
---
--- Name: exchange_do_deposit(bigint, integer, bytea, bytea, bigint, bigint, bigint, bigint, bytea, character varying, bytea, bigint, bytea, bytea, bigint, boolean, character varying); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_deposit(in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_h_contract_terms bytea, in_wire_salt bytea, in_wallet_timestamp bigint, in_exchange_timestamp bigint, in_refund_deadline bigint, in_wire_deadline bigint, in_merchant_pub bytea, in_receiver_wire_account character varying, in_h_payto bytea, in_known_coin_id bigint, in_coin_pub bytea, in_coin_sig bytea, in_shard bigint, in_extension_blocked boolean, in_extension_details character varying, OUT out_exchange_timestamp bigint, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- wtsi INT8; -- wire target serial id
-DECLARE
- xdi INT8; -- eXstension details serial id
-BEGIN
--- Shards: INSERT extension_details (by extension_details_serial_id)
--- INSERT wire_targets (by h_payto), on CONFLICT DO NOTHING;
--- INSERT deposits (by coin_pub, shard), ON CONFLICT DO NOTHING;
--- UPDATE known_coins (by coin_pub)
-
-IF NOT NULL in_extension_details
-THEN
- INSERT INTO extension_details
- (extension_options)
- VALUES
- (in_extension_details)
- RETURNING extension_details_serial_id INTO xdi;
-ELSE
- xdi=NULL;
-END IF;
-
-
-INSERT INTO wire_targets
- (wire_target_h_payto
- ,payto_uri)
- VALUES
- (in_h_payto
- ,in_receiver_wire_account)
-ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto)
- RETURNING wire_target_serial_id INTO wtsi;
-
-IF NOT FOUND
-THEN
- SELECT wire_target_serial_id
- INTO wtsi
- FROM wire_targets
- WHERE wire_target_h_payto=in_h_payto;
-END IF;
-
-
-INSERT INTO deposits
- (shard
- ,coin_pub
- ,known_coin_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,wallet_timestamp
- ,exchange_timestamp
- ,refund_deadline
- ,wire_deadline
- ,merchant_pub
- ,h_contract_terms
- ,coin_sig
- ,wire_salt
- ,wire_target_h_payto
- ,extension_blocked
- ,extension_details_serial_id
- )
- VALUES
- (in_shard
- ,in_coin_pub
- ,in_known_coin_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_wallet_timestamp
- ,in_exchange_timestamp
- ,in_refund_deadline
- ,in_wire_deadline
- ,in_merchant_pub
- ,in_h_contract_terms
- ,in_coin_sig
- ,in_wire_salt
- ,in_h_payto
- ,in_extension_blocked
- ,xdi)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and wire_target_h_payto
- -- primarily here to maximally use the existing index.
- SELECT
- exchange_timestamp
- INTO
- out_exchange_timestamp
- FROM deposits
- WHERE shard=in_shard
- AND merchant_pub=in_merchant_pub
- AND wire_target_h_payto=in_h_payto
- AND coin_pub=in_coin_pub
- AND coin_sig=in_coin_sig;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_balance_ok=TRUE;
- out_conflict=FALSE;
-
- RETURN;
-END IF;
-
-
-out_exchange_timestamp=in_exchange_timestamp;
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_conflict=FALSE;
-
-END $$;
-
-
---
--- Name: exchange_do_expire_purse(bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean) RETURNS boolean
- LANGUAGE plpgsql
- AS $$
-DECLARE
- my_purse_pub BYTEA;
-DECLARE
- my_deposit record;
-BEGIN
-
-SELECT purse_pub
- INTO my_purse_pub
- FROM purse_requests
- WHERE (purse_expiration >= in_start_time) AND
- (purse_expiration < in_end_time) AND
- (NOT finished) AND
- (NOT refunded)
- ORDER BY purse_expiration ASC
- LIMIT 1;
-out_found = FOUND;
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-UPDATE purse_requests
- SET refunded=TRUE,
- finished=TRUE
- WHERE purse_pub=my_purse_pub;
-
-INSERT INTO purse_refunds
- (purse_pub)
- VALUES
- (my_purse_pub);
-
--- restore balance to each coin deposited into the purse
-FOR my_deposit IN
- SELECT coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- FROM purse_deposits
- WHERE purse_pub = my_purse_pub
-LOOP
- UPDATE known_coins SET
- remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac
- - CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+my_deposit.amount_with_fee_val
- + CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub = my_deposit.coin_pub;
- END LOOP;
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_expire_purse(in_start_time bigint, in_end_time bigint, OUT out_found boolean) IS 'Finds an expired purse in the given time range and refunds the coins (if any).';
-
-
---
--- Name: exchange_do_gc(bigint, bigint); Type: PROCEDURE; Schema: public; Owner: -
---
-
-CREATE PROCEDURE public.exchange_do_gc(in_ancient_date bigint, in_now bigint)
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_uuid_min INT8; -- minimum reserve UUID still alive
-DECLARE
- melt_min INT8; -- minimum melt still alive
-DECLARE
- coin_min INT8; -- minimum known_coin still alive
-DECLARE
- deposit_min INT8; -- minimum deposit still alive
-DECLARE
- reserve_out_min INT8; -- minimum reserve_out still alive
-DECLARE
- denom_min INT8; -- minimum denomination still alive
-BEGIN
-
-DELETE FROM prewire
- WHERE finished=TRUE;
-
-DELETE FROM wire_fee
- WHERE end_date < in_ancient_date;
-
--- TODO: use closing fee as threshold?
-DELETE FROM reserves
- WHERE gc_date < in_now
- AND current_balance_val = 0
- AND current_balance_frac = 0;
-
-SELECT
- reserve_out_serial_id
- INTO
- reserve_out_min
- FROM reserves_out
- ORDER BY reserve_out_serial_id ASC
- LIMIT 1;
-
-DELETE FROM recoup
- WHERE reserve_out_serial_id < reserve_out_min;
--- FIXME: recoup_refresh lacks GC!
-
-SELECT
- reserve_uuid
- INTO
- reserve_uuid_min
- FROM reserves
- ORDER BY reserve_uuid ASC
- LIMIT 1;
-
-DELETE FROM reserves_out
- WHERE reserve_uuid < reserve_uuid_min;
-
--- FIXME: this query will be horribly slow;
--- need to find another way to formulate it...
-DELETE FROM denominations
- WHERE expire_legal < in_now
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM reserves_out)
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup))
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup_refresh));
-
-SELECT
- melt_serial_id
- INTO
- melt_min
- FROM refresh_commitments
- ORDER BY melt_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refresh_revealed_coins
- WHERE melt_serial_id < melt_min;
-
-DELETE FROM refresh_transfer_keys
- WHERE melt_serial_id < melt_min;
-
-SELECT
- known_coin_id
- INTO
- coin_min
- FROM known_coins
- ORDER BY known_coin_id ASC
- LIMIT 1;
-
-DELETE FROM deposits
- WHERE known_coin_id < coin_min;
-
-SELECT
- deposit_serial_id
- INTO
- deposit_min
- FROM deposits
- ORDER BY deposit_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refunds
- WHERE deposit_serial_id < deposit_min;
-
-DELETE FROM aggregation_tracking
- WHERE deposit_serial_id < deposit_min;
-
-SELECT
- denominations_serial
- INTO
- denom_min
- FROM denominations
- ORDER BY denominations_serial ASC
- LIMIT 1;
-
-DELETE FROM cs_nonce_locks
- WHERE max_denomination_serial <= denom_min;
-
-END $$;
-
-
---
--- Name: exchange_do_history_request(bytea, bytea, bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_history_request(in_reserve_pub bytea, in_reserve_sig bytea, in_request_timestamp bigint, in_history_fee_val bigint, in_history_fee_frac integer, OUT out_balance_ok boolean, OUT out_idempotent boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- -- Insert and check for idempotency.
- INSERT INTO history_requests
- (reserve_pub
- ,request_timestamp
- ,reserve_sig
- ,history_fee_val
- ,history_fee_frac)
- VALUES
- (in_reserve_pub
- ,in_request_timestamp
- ,in_reserve_sig
- ,in_history_fee_val
- ,in_history_fee_frac)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- out_balance_ok=TRUE;
- out_idempotent=TRUE;
- RETURN;
- END IF;
-
- out_idempotent=FALSE;
-
- -- Update reserve balance.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_history_fee_frac
- + CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_history_fee_val
- - CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE
- reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_history_fee_val) OR
- ( (current_balance_frac >= in_history_fee_frac) AND
- (current_balance_val >= in_history_fee_val) ) );
-
- IF NOT FOUND
- THEN
- -- Either reserve does not exist, or balance insufficient.
- -- Both we treat the same here as balance insufficient.
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-
- out_balance_ok=TRUE;
-END $$;
-
-
---
--- Name: exchange_do_melt(bytea, bigint, integer, bytea, bytea, bytea, bigint, integer, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_melt(in_cs_rms bytea, in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_rc bytea, in_old_coin_pub bytea, in_old_coin_sig bytea, in_known_coin_id bigint, in_noreveal_index integer, in_zombie_required boolean, OUT out_balance_ok boolean, OUT out_zombie_bad boolean, OUT out_noreveal_index integer) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- denom_max INT8;
-BEGIN
--- Shards: INSERT refresh_commitments (by rc)
--- (rare:) SELECT refresh_commitments (by old_coin_pub) -- crosses shards!
--- (rare:) SEELCT refresh_revealed_coins (by melt_serial_id)
--- (rare:) PERFORM recoup_refresh (by rrc_serial) -- crosses shards!
--- UPDATE known_coins (by coin_pub)
-
-INSERT INTO refresh_commitments
- (rc
- ,old_coin_pub
- ,old_coin_sig
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,noreveal_index
- )
- VALUES
- (in_rc
- ,in_old_coin_pub
- ,in_old_coin_sig
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_noreveal_index)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- out_noreveal_index=-1;
- SELECT
- noreveal_index
- INTO
- out_noreveal_index
- FROM refresh_commitments
- WHERE rc=in_rc;
- out_balance_ok=FOUND;
- out_zombie_bad=FALSE; -- zombie is OK
- RETURN;
-END IF;
-
-
-IF in_zombie_required
-THEN
- -- Check if this coin was part of a refresh
- -- operation that was subsequently involved
- -- in a recoup operation. We begin by all
- -- refresh operations our coin was involved
- -- with, then find all associated reveal
- -- operations, and then see if any of these
- -- reveal operations was involved in a recoup.
- PERFORM
- FROM recoup_refresh
- WHERE rrc_serial IN
- (SELECT rrc_serial
- FROM refresh_revealed_coins
- WHERE melt_serial_id IN
- (SELECT melt_serial_id
- FROM refresh_commitments
- WHERE old_coin_pub=in_old_coin_pub));
- IF NOT FOUND
- THEN
- out_zombie_bad=TRUE;
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_zombie_bad=FALSE; -- zombie is OK
-
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_noreveal_index=-1;
- out_balance_ok=FALSE;
- RETURN;
-END IF;
-
-
-
--- Special actions needed for a CS melt?
-IF NOT NULL in_cs_rms
-THEN
- -- Get maximum denominations serial value in
- -- existence, this will determine how long the
- -- nonce will be locked.
- SELECT
- denominations_serial
- INTO
- denom_max
- FROM denominations
- ORDER BY denominations_serial DESC
- LIMIT 1;
-
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_rms
- ,denom_serial
- ,in_rc)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- Record exists, make sure it is the same
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_rms
- AND op_hash=in_rc;
-
- IF NOT FOUND
- THEN
- -- Nonce reuse detected
- out_balance_ok=FALSE;
- out_zombie_bad=FALSE;
- out_noreveal_index=42; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_noreveal_index=in_noreveal_index;
-
-END $$;
-
-
---
--- Name: exchange_do_purse_deposit(bigint, bytea, bigint, integer, bytea, bytea, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_purse_deposit(in_partner_id bigint, in_purse_pub bytea, in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_coin_pub bytea, in_coin_sig bytea, in_amount_without_fee_val bigint, in_amount_without_fee_frac integer, OUT out_balance_ok boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_merged BOOLEAN;
-DECLARE
- psi INT8; -- partner's serial ID (set if merged)
-DECLARE
- my_amount_val INT8; -- total in purse
-DECLARE
- my_amount_frac INT4; -- total in purse
-DECLARE
- was_paid BOOLEAN;
-DECLARE
- my_reserve_pub BYTEA;
-BEGIN
-
--- Store the deposit request.
-INSERT INTO purse_deposits
- (partner_serial_id
- ,purse_pub
- ,coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,coin_sig)
- VALUES
- (in_partner_id
- ,in_purse_pub
- ,in_coin_pub
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_coin_sig)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: check if coin_sig is the same,
- -- if so, success, otherwise conflict!
- PERFORM
- FROM purse_deposits
- WHERE coin_pub = in_coin_pub
- AND purse_pub = in_purse_pub
- AND coin_sig = in_cion_sig;
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-END IF;
-
-
--- Debit the coin
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
-
--- Credit the purse.
-UPDATE purse_requests
- SET
- balance_frac=balance_frac+in_amount_without_fee_frac
- - CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- balance_val=balance_val+in_amount_without_fee_val
- + CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE purse_pub=in_purse_pub;
-
-out_conflict=FALSE;
-out_balance_ok=TRUE;
-
--- See if we can finish the merge or need to update the trigger time and partner.
-SELECT partner_serial_id
- ,reserve_pub
- INTO psi
- ,my_reserve_pub
- FROM purse_merges
- WHERE purse_pub=in_purse_pub;
-
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-SELECT
- amount_with_fee_val
- ,amount_with_fee_frac
- INTO
- my_amount_val
- ,my_amount_frac
- FROM purse_requests
- WHERE (purse_pub=in_purse_pub)
- AND ( ( ( (amount_with_fee_val <= balance_val)
- AND (amount_with_fee_frac <= balance_frac) )
- OR (amount_with_fee_val < balance_val) ) );
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-IF (0 != psi)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=psi
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update balance immediately.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=my_reserve_pub;
-
- -- ... and mark purse as finished.
- -- FIXME: combine with UPDATE above?
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-END $$;
-
-
---
--- Name: exchange_do_purse_merge(bytea, bytea, bigint, bytea, character varying, bytea, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- my_amount_val INT8;
-DECLARE
- my_amount_frac INT4;
-DECLARE
- my_purse_fee_val INT8;
-DECLARE
- my_purse_fee_frac INT4;
-DECLARE
- my_partner_serial_id INT8;
-DECLARE
- my_finished BOOLEAN;
-BEGIN
-
-IF in_partner_url IS NULL
-THEN
- my_partner_serial_id=0;
-ELSE
- SELECT
- partner_serial_id
- INTO
- my_partner_serial_id
- FROM partners
- WHERE partner_base_url=in_partner_url
- AND start_date <= in_merge_timestamp
- AND end_date > in_merge_timestamp;
- IF NOT FOUND
- THEN
- out_no_partner=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_no_partner=FALSE;
-
-
--- Check purse is 'full'.
-SELECT amount_with_fee_val
- ,amount_with_fee_frac
- ,purse_fee_val
- ,purse_fee_frac
- ,finished
- INTO my_amount_val
- ,my_amount_frac
- ,my_purse_fee_val
- ,my_purse_fee_frac
- ,my_finished
- FROM purse_requests
- WHERE purse_pub=in_purse_pub
- AND balance_val >= amount_with_fee_val
- AND ( (balance_frac >= amount_with_fee_frac) OR
- (balance_val > amount_with_fee_val) );
-IF NOT FOUND
-THEN
- out_no_balance=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_no_balance=FALSE;
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (my_partner_serial_id
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-ASSERT NOT my_finished, 'internal invariant failed';
-
-IF ( (in_partner_url IS NULL) AND
- (in_require_kyc) )
-THEN
- -- Need to do KYC check.
- SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
- IF NOT FOUND
- THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- RETURN;
- END IF;
- out_no_reserve=FALSE;
-
- IF (out_no_kyc)
- THEN
- RETURN;
- END IF;
-ELSE
- -- KYC is not our responsibility
- out_no_reserve=FALSE;
- out_no_kyc=FALSE;
-END IF;
-
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
--- If we need a wad transfer, mark purse ready for it.
-IF (0 != my_partner_serial_id)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=my_partner_serial_id
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update reserve balance immediately.
-
- -- Refund the purse fee, by adding it to the purse value:
- my_amount_val = my_amount_val + my_purse_fee_val;
- my_amount_frac = my_amount_frac + my_purse_fee_frac;
- -- normalize result
- my_amount_val = my_amount_val + my_amount_frac / 100000000;
- my_amount_frac = my_amount_frac % 100000000;
-
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=in_reserve_pub;
-
- -- ... and mark purse as finished.
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-RETURN;
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_purse_merge(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_partner_url character varying, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_partner boolean, OUT out_no_balance boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.';
-
-
---
--- Name: exchange_do_recoup_by_reserve(bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_by_reserve(res_pub bytea) RETURNS TABLE(denom_sig bytea, denominations_serial bigint, coin_pub bytea, coin_sig bytea, coin_blind bytea, amount_val bigint, amount_frac integer, recoup_timestamp bigint)
- LANGUAGE plpgsql
- AS $$
-DECLARE
- res_uuid BIGINT;
- blind_ev BYTEA;
- c_pub BYTEA;
-BEGIN
- SELECT reserve_uuid
- INTO res_uuid
- FROM reserves
- WHERE reserves.reserve_pub = res_pub;
-
- FOR blind_ev IN
- SELECT h_blind_ev
- FROM reserves_out_by_reserve
- WHERE reserves_out_by_reserve.reserve_uuid = res_uuid
- LOOP
- SELECT robr.coin_pub
- INTO c_pub
- FROM recoup_by_reserve robr
- WHERE robr.reserve_out_serial_id = (
- SELECT reserves_out.reserve_out_serial_id
- FROM reserves_out
- WHERE reserves_out.h_blind_ev = blind_ev
- );
- RETURN QUERY
- SELECT kc.denom_sig,
- kc.denominations_serial,
- rc.coin_pub,
- rc.coin_sig,
- rc.coin_blind,
- rc.amount_val,
- rc.amount_frac,
- rc.recoup_timestamp
- FROM (
- SELECT *
- FROM known_coins
- WHERE known_coins.coin_pub = c_pub
- ) kc
- JOIN (
- SELECT *
- FROM recoup
- WHERE recoup.coin_pub = c_pub
- ) rc USING (coin_pub);
- END LOOP;
-END;
-$$;
-
-
---
--- Name: FUNCTION exchange_do_recoup_by_reserve(res_pub bytea); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_recoup_by_reserve(res_pub bytea) IS 'Recoup by reserve as a function to make sure we hit only the needed partition and not all when joining as joins on distributed tables fetch ALL rows from the shards';
-
-
---
--- Name: exchange_do_recoup_to_coin(bytea, bigint, bytea, bytea, bigint, bytea, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_to_coin(in_old_coin_pub bytea, in_rrc_serial bigint, in_coin_blind bytea, in_coin_pub bytea, in_known_coin_id bigint, in_coin_sig bytea, in_recoup_timestamp bigint, OUT out_recoup_ok boolean, OUT out_internal_failure boolean, OUT out_recoup_timestamp bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
-
--- Shards: UPDATE known_coins (by coin_pub)
--- SELECT recoup_refresh (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- INSERT recoup_refresh (by coin_pub)
-
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup_refresh
- WHERE coin_pub=in_coin_pub;
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the old coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+tmp_frac
- - CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+tmp_val
- + CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase old coin balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup_refresh
- (coin_pub
- ,known_coin_id
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,rrc_serial
- )
-VALUES
- (in_coin_pub
- ,in_known_coin_id
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_rrc_serial);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
-
---
--- Name: exchange_do_recoup_to_reserve(bytea, bigint, bytea, bytea, bigint, bytea, bigint, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_recoup_to_reserve(in_reserve_pub bytea, in_reserve_out_serial_id bigint, in_coin_blind bytea, in_coin_pub bytea, in_known_coin_id bigint, in_coin_sig bytea, in_reserve_gc bigint, in_reserve_expiration bigint, in_recoup_timestamp bigint, OUT out_recoup_ok boolean, OUT out_internal_failure boolean, OUT out_recoup_timestamp bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
--- Shards: SELECT known_coins (by coin_pub)
--- SELECT recoup (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- UPDATE reserves (by reserve_pub)
--- INSERT recoup (by coin_pub)
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup
- WHERE coin_pub=in_coin_pub;
-
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the reserve and update reserve timers.
-UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+tmp_frac
- - CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+tmp_val
- + CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END,
- gc_date=GREATEST(gc_date, in_reserve_gc),
- expiration_date=GREATEST(expiration_date, in_reserve_expiration)
- WHERE reserve_pub=in_reserve_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase reserve balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup
- (coin_pub
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,reserve_out_serial_id
- )
-VALUES
- (in_coin_pub
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_reserve_out_serial_id);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
-
---
--- Name: exchange_do_refund(bigint, integer, bigint, integer, bigint, integer, bytea, bigint, bigint, bigint, bytea, bytea, bytea); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_refund(in_amount_with_fee_val bigint, in_amount_with_fee_frac integer, in_amount_val bigint, in_amount_frac integer, in_deposit_fee_val bigint, in_deposit_fee_frac integer, in_h_contract_terms bytea, in_rtransaction_id bigint, in_deposit_shard bigint, in_known_coin_id bigint, in_coin_pub bytea, in_merchant_pub bytea, in_merchant_sig bytea, OUT out_not_found boolean, OUT out_refund_ok boolean, OUT out_gone boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- dsi INT8; -- ID of deposit being refunded
-DECLARE
- tmp_val INT8; -- total amount refunded
-DECLARE
- tmp_frac INT8; -- total amount refunded
-DECLARE
- deposit_val INT8; -- amount that was originally deposited
-DECLARE
- deposit_frac INT8; -- amount that was originally deposited
-BEGIN
--- Shards: SELECT deposits (coin_pub, shard, h_contract_terms, merchant_pub)
--- INSERT refunds (by coin_pub, rtransaction_id) ON CONFLICT DO NOTHING
--- SELECT refunds (by coin_pub)
--- UPDATE known_coins (by coin_pub)
-
-SELECT
- deposit_serial_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,done
-INTO
- dsi
- ,deposit_val
- ,deposit_frac
- ,out_gone
-FROM deposits
- WHERE coin_pub=in_coin_pub
- AND shard=in_deposit_shard
- AND merchant_pub=in_merchant_pub
- AND h_contract_terms=in_h_contract_terms;
-
-IF NOT FOUND
-THEN
- -- No matching deposit found!
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=TRUE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-INSERT INTO refunds
- (deposit_serial_id
- ,coin_pub
- ,merchant_sig
- ,rtransaction_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- )
- VALUES
- (dsi
- ,in_coin_pub
- ,in_merchant_sig
- ,in_rtransaction_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and h_contract_terms
- -- primarily here to maximally use the existing index.
- PERFORM
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi
- AND rtransaction_id=in_rtransaction_id
- AND amount_with_fee_val=in_amount_with_fee_val
- AND amount_with_fee_frac=in_amount_with_fee_frac;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but have conflicting refund.
- out_refund_ok=FALSE;
- out_conflict=TRUE;
- out_not_found=FALSE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_refund_ok=TRUE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-IF out_gone
-THEN
- -- money already sent to the merchant. Tough luck.
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Check refund balance invariant.
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- tmp_val
- ,tmp_frac
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi;
-IF tmp_val IS NULL
-THEN
- RAISE NOTICE 'failed to sum up existing refunds';
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Normalize result before continuing
-tmp_val = tmp_val + tmp_frac / 100000000;
-tmp_frac = tmp_frac % 100000000;
-
--- Actually check if the deposits are sufficient for the refund. Verbosely. ;-)
-IF (tmp_val < deposit_val)
-THEN
- out_refund_ok=TRUE;
-ELSE
- IF (tmp_val = deposit_val) AND (tmp_frac <= deposit_frac)
- THEN
- out_refund_ok=TRUE;
- ELSE
- out_refund_ok=FALSE;
- END IF;
-END IF;
-
-IF (tmp_val = deposit_val) AND (tmp_frac = deposit_frac)
-THEN
- -- Refunds have reached the full value of the original
- -- deposit. Also refund the deposit fee.
- in_amount_frac = in_amount_frac + in_deposit_fee_frac;
- in_amount_val = in_amount_val + in_deposit_fee_val;
-
- -- Normalize result before continuing
- in_amount_val = in_amount_val + in_amount_frac / 100000000;
- in_amount_frac = in_amount_frac % 100000000;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+in_amount_frac
- - CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+in_amount_val
- + CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub;
-
-
-out_conflict=FALSE;
-out_not_found=FALSE;
-
-END $$;
-
-
---
--- Name: exchange_do_reserve_purse(bytea, bytea, bigint, bytea, boolean, bigint, integer, bytea, boolean); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) RETURNS record
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (0
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- out_no_funds=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_funds=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
-IF NOT FOUND
-THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- out_no_funds=TRUE;
- RETURN;
-END IF;
-out_no_reserve=FALSE;
-
-IF (out_no_kyc AND in_require_kyc)
-THEN
- out_no_funds=FALSE;
- RETURN;
-END IF;
-
-IF (in_reserve_quota)
-THEN
- -- Increment active purses per reserve (and check this is allowed)
- UPDATE reserves
- SET purses_active=purses_active+1
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND purses_active < purses_allowed;
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-ELSE
- -- UPDATE reserves balance (and check if balance is enough to pay the fee)
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_purse_fee_frac
- + CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_purse_fee_val
- - CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 1
- ELSE 0
- END
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_purse_fee_val) OR
- ( (current_balance_frac >= in_purse_fee_frac) AND
- (current_balance_val >= in_purse_fee_val) ) );
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-END IF;
-
-out_no_funds=FALSE;
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_reserve_purse(in_purse_pub bytea, in_merge_sig bytea, in_merge_timestamp bigint, in_reserve_sig bytea, in_reserve_quota boolean, in_purse_fee_val bigint, in_purse_fee_frac integer, in_reserve_pub bytea, in_require_kyc boolean, OUT out_no_funds boolean, OUT out_no_kyc boolean, OUT out_no_reserve boolean, OUT out_conflict boolean) IS 'Create a purse for a reserve.';
-
-
---
--- Name: exchange_do_withdraw(bytea, bigint, integer, bytea, bytea, bytea, bytea, bytea, bigint, bigint); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) RETURNS record
- LANGUAGE plpgsql
- AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- denom_serial INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=0;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- We optimistically insert, and then on conflict declare
--- the query successful due to idempotency.
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- idempotent query, all constraints must be satisfied
- reserve_found=TRUE;
- balance_ok=TRUE;
- kycok=TRUE;
- account_uuid=0;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
-
--- Special actions needed for a CS withdraw?
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=1; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_withdraw(cs_nonce bytea, amount_val bigint, amount_frac integer, h_denom_pub bytea, rpub bytea, reserve_sig bytea, h_coin_envelope bytea, denom_sig bytea, now bigint, min_reserve_gc bigint, OUT reserve_found boolean, OUT balance_ok boolean, OUT kycok boolean, OUT account_uuid bigint, OUT ruuid bigint) IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result';
-
-
---
--- Name: exchange_do_withdraw_limit_check(bigint, bigint, bigint, integer); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean) RETURNS boolean
- LANGUAGE plpgsql
- AS $$
-DECLARE
- total_val INT8;
-DECLARE
- total_frac INT8; -- INT4 could overflow during accumulation!
-BEGIN
--- NOTE: Read-only, but crosses shards.
--- Shards: reserves by reserve_pub
--- reserves_out by reserve_uuid -- crosses shards!!
-
-
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- total_val
- ,total_frac
- FROM reserves_out
- WHERE reserve_uuid=ruuid
- AND execution_date > start_time;
-
--- normalize result
-total_val = total_val + total_frac / 100000000;
-total_frac = total_frac % 100000000;
-
--- compare to threshold
-below_limit = (total_val < upper_limit_val) OR
- ( (total_val = upper_limit_val) AND
- (total_frac <= upper_limit_frac) );
-END $$;
-
-
---
--- Name: FUNCTION exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.exchange_do_withdraw_limit_check(ruuid bigint, start_time bigint, upper_limit_val bigint, upper_limit_frac integer, OUT below_limit boolean) IS 'Check whether the withdrawals from the given reserve since the given time are below the given threshold';
-
-
---
--- Name: prepare_sharding(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.prepare_sharding() RETURNS void
- LANGUAGE plpgsql
- AS $$
-BEGIN
-
- CREATE EXTENSION IF NOT EXISTS postgres_fdw;
-
- PERFORM detach_default_partitions();
-
- ALTER TABLE IF EXISTS wire_targets
- DROP CONSTRAINT IF EXISTS wire_targets_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves
- DROP CONSTRAINT IF EXISTS reserves_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_in
- DROP CONSTRAINT IF EXISTS reserves_in_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_close
- DROP CONSTRAINT IF EXISTS reserves_close_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_out
- DROP CONSTRAINT IF EXISTS reserves_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS reserves_out_denominations_serial_fkey
- ,DROP CONSTRAINT IF EXISTS reserves_out_h_blind_ev_key
- ;
-
- ALTER TABLE IF EXISTS known_coins
- DROP CONSTRAINT IF EXISTS known_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS known_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DROP CONSTRAINT IF EXISTS refresh_commitments_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_old_coin_pub_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DROP CONSTRAINT IF EXISTS refresh_revealed_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_revealed_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DROP CONSTRAINT IF EXISTS refresh_transfer_keys_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS deposits
- DROP CONSTRAINT IF EXISTS deposits_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS deposits_extension_details_serial_id_fkey
- ,DROP CONSTRAINT IF EXISTS deposits_coin_pub_merchant_pub_h_contract_terms_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS refunds
- DROP CONSTRAINT IF EXISTS refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wire_out
- DROP CONSTRAINT IF EXISTS wire_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wire_out_wtid_raw_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DROP CONSTRAINT IF EXISTS aggregation_tracking_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS aggregation_tracking_wtid_raw_fkey
- ;
-
- ALTER TABLE IF EXISTS recoup
- DROP CONSTRAINT IF EXISTS recoup_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DROP CONSTRAINT IF EXISTS recoup_refresh_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS prewire
- DROP CONSTRAINT IF EXISTS prewire_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DROP CONSTRAINT IF EXISTS cs_nonce_locks_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_requests
- DROP CONSTRAINT IF EXISTS purse_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_refunds
- DROP CONSTRAINT IF EXISTS purse_refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_merges
- DROP CONSTRAINT IF EXISTS purse_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS account_merges
- DROP CONSTRAINT IF EXISTS account_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS contracts
- DROP CONSTRAINT IF EXISTS contracts_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS history_requests
- DROP CONSTRAINT IF EXISTS history_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS close_requests
- DROP CONSTRAINT IF EXISTS close_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_deposits
- DROP CONSTRAINT IF EXISTS purse_deposits_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_out
- DROP CONSTRAINT IF EXISTS wads_out_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DROP CONSTRAINT IF EXISTS wad_out_entries_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_in
- DROP CONSTRAINT IF EXISTS wads_in_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wads_in_wad_id_origin_exchange_url_key
- ;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DROP CONSTRAINT IF EXISTS wad_in_entries_pkey CASCADE
- ;
-
-END
-$$;
-
-
---
--- Name: purse_requests_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.purse_requests_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- ASSERT NOT NEW.finished,'Internal invariant violated';
- INSERT INTO
- purse_actions
- (purse_pub
- ,action_date)
- VALUES
- (NEW.purse_pub
- ,NEW.purse_expiration);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION purse_requests_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.purse_requests_insert_trigger() IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
-
-
---
--- Name: purse_requests_on_update_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.purse_requests_on_update_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- IF (NEW.finished AND NOT OLD.finished)
- THEN
- -- If this purse counted against the reserve's
- -- quota of purses, decrement the reserve accounting.
- IF (NEW.in_reserve_quota)
- THEN
- UPDATE reserves
- SET purses_active=purses_active-1
- WHERE reserve_pub IN
- (SELECT reserve_pub
- FROM purse_merges
- WHERE purse_pub=NEW.purse_pub
- LIMIT 1);
- NEW.in_reserve_quota=FALSE;
- END IF;
- -- Delete from the purse_actions table, we are done
- -- with this purse for good.
- DELETE FROM purse_actions
- WHERE purse_pub=NEW.purse_pub;
- RETURN NEW;
- END IF;
-
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION purse_requests_on_update_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.purse_requests_on_update_trigger() IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is finished.';
-
-
---
--- Name: recoup_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.recoup_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM recoup_by_reserve
- WHERE reserve_out_serial_id = OLD.reserve_out_serial_id
- AND coin_pub = OLD.coin_pub;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION recoup_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.recoup_delete_trigger() IS 'Replicate recoup deletions into recoup_by_reserve table.';
-
-
---
--- Name: recoup_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.recoup_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO recoup_by_reserve
- (reserve_out_serial_id
- ,coin_pub)
- VALUES
- (NEW.reserve_out_serial_id
- ,NEW.coin_pub);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION recoup_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.recoup_insert_trigger() IS 'Replicate recoup inserts into recoup_by_reserve table.';
-
-
---
--- Name: reserves_out_by_reserve_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.reserves_out_by_reserve_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM reserves_out_by_reserve
- WHERE reserve_uuid = OLD.reserve_uuid;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION reserves_out_by_reserve_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.reserves_out_by_reserve_delete_trigger() IS 'Replicate reserve_out deletions into reserve_out_by_reserve table.';
-
-
---
--- Name: reserves_out_by_reserve_insert_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.reserves_out_by_reserve_insert_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO reserves_out_by_reserve
- (reserve_uuid
- ,h_blind_ev)
- VALUES
- (NEW.reserve_uuid
- ,NEW.h_blind_ev);
- RETURN NEW;
-END $$;
-
-
---
--- Name: FUNCTION reserves_out_by_reserve_insert_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.reserves_out_by_reserve_insert_trigger() IS 'Replicate reserve_out inserts into reserve_out_by_reserve table.';
-
-
---
--- Name: wire_out_delete_trigger(); Type: FUNCTION; Schema: public; Owner: -
---
-
-CREATE FUNCTION public.wire_out_delete_trigger() RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM aggregation_tracking
- WHERE wtid_raw = OLD.wtid_raw;
- RETURN OLD;
-END $$;
-
-
---
--- Name: FUNCTION wire_out_delete_trigger(); Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON FUNCTION public.wire_out_delete_trigger() IS 'Replicate reserve_out deletions into aggregation_tracking. This replaces an earlier use of an ON DELETE CASCADE that required a DEFERRABLE constraint and conflicted with nice partitioning.';
-
-
-SET default_tablespace = '';
-
-SET default_table_access_method = heap;
-
---
--- Name: patches; Type: TABLE; Schema: _v; Owner: -
---
-
-CREATE TABLE _v.patches (
- patch_name text NOT NULL,
- applied_tsz timestamp with time zone DEFAULT now() NOT NULL,
- applied_by text NOT NULL,
- requires text[],
- conflicts text[]
-);
-
-
---
--- Name: TABLE patches; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON TABLE _v.patches IS 'Contains information about what patches are currently applied on database.';
-
-
---
--- Name: COLUMN patches.patch_name; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.patch_name IS 'Name of patch, has to be unique for every patch.';
-
-
---
--- Name: COLUMN patches.applied_tsz; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.applied_tsz IS 'When the patch was applied.';
-
-
---
--- Name: COLUMN patches.applied_by; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.applied_by IS 'Who applied this patch (PostgreSQL username)';
-
-
---
--- Name: COLUMN patches.requires; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.requires IS 'List of patches that are required for given patch.';
-
-
---
--- Name: COLUMN patches.conflicts; Type: COMMENT; Schema: _v; Owner: -
---
-
-COMMENT ON COLUMN _v.patches.conflicts IS 'List of patches that conflict with given patch.';
-
-
---
--- Name: account_merges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.account_merges (
- account_merge_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT account_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT account_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT account_merges_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE account_merges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.account_merges IS 'Merge requests where a purse- and account-owner requested merging the purse into the account';
-
-
---
--- Name: COLUMN account_merges.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.reserve_pub IS 'public key of the target reserve';
-
-
---
--- Name: COLUMN account_merges.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.reserve_sig IS 'signature by the reserve private key affirming the merge, of type TALER_SIGNATURE_WALLET_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN account_merges.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.account_merges.purse_pub IS 'public key of the purse';
-
-
---
--- Name: account_merges_account_merge_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.account_merges ALTER COLUMN account_merge_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.account_merges_account_merge_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: account_merges_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.account_merges_default (
- account_merge_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT account_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT account_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT account_merges_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.account_merges ATTACH PARTITION public.account_merges_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: aggregation_tracking; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_tracking (
- aggregation_serial_id bigint NOT NULL,
- deposit_serial_id bigint NOT NULL,
- wtid_raw bytea NOT NULL
-)
-PARTITION BY HASH (deposit_serial_id);
-
-
---
--- Name: TABLE aggregation_tracking; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.aggregation_tracking IS 'mapping from wire transfer identifiers (WTID) to deposits (and back)';
-
-
---
--- Name: COLUMN aggregation_tracking.wtid_raw; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_tracking.wtid_raw IS 'identifier of the wire transfer';
-
-
---
--- Name: aggregation_tracking_aggregation_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.aggregation_tracking ALTER COLUMN aggregation_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.aggregation_tracking_aggregation_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: aggregation_tracking_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_tracking_default (
- aggregation_serial_id bigint NOT NULL,
- deposit_serial_id bigint NOT NULL,
- wtid_raw bytea NOT NULL
-);
-ALTER TABLE ONLY public.aggregation_tracking ATTACH PARTITION public.aggregation_tracking_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: aggregation_transient; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_transient (
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- wtid_raw bytea NOT NULL,
- CONSTRAINT aggregation_transient_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT aggregation_transient_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-)
-PARTITION BY HASH (wire_target_h_payto);
-
-
---
--- Name: TABLE aggregation_transient; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.aggregation_transient IS 'aggregations currently happening (lacking wire_out, usually because the amount is too low); this table is not replicated';
-
-
---
--- Name: COLUMN aggregation_transient.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_transient.amount_val IS 'Sum of all of the aggregated deposits (without deposit fees)';
-
-
---
--- Name: COLUMN aggregation_transient.wtid_raw; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.aggregation_transient.wtid_raw IS 'identifier of the wire transfer';
-
-
---
--- Name: aggregation_transient_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.aggregation_transient_default (
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- wtid_raw bytea NOT NULL,
- CONSTRAINT aggregation_transient_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT aggregation_transient_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-);
-ALTER TABLE ONLY public.aggregation_transient ATTACH PARTITION public.aggregation_transient_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: app_bankaccount; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_bankaccount (
- is_public boolean NOT NULL,
- account_no integer NOT NULL,
- balance character varying NOT NULL,
- user_id integer NOT NULL
-);
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.app_bankaccount_account_no_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.app_bankaccount_account_no_seq OWNED BY public.app_bankaccount.account_no;
-
-
---
--- Name: app_banktransaction; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_banktransaction (
- id bigint NOT NULL,
- amount character varying NOT NULL,
- subject character varying(200) NOT NULL,
- date timestamp with time zone NOT NULL,
- cancelled boolean NOT NULL,
- request_uid character varying(128) NOT NULL,
- credit_account_id integer NOT NULL,
- debit_account_id integer NOT NULL
-);
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.app_banktransaction_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.app_banktransaction_id_seq OWNED BY public.app_banktransaction.id;
-
-
---
--- Name: app_talerwithdrawoperation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.app_talerwithdrawoperation (
- withdraw_id uuid NOT NULL,
- amount character varying NOT NULL,
- selection_done boolean NOT NULL,
- confirmation_done boolean NOT NULL,
- aborted boolean NOT NULL,
- selected_reserve_pub text,
- selected_exchange_account_id integer,
- withdraw_account_id integer NOT NULL
-);
-
-
---
--- Name: auditor_balance_summary; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_balance_summary (
- master_pub bytea NOT NULL,
- denom_balance_val bigint NOT NULL,
- denom_balance_frac integer NOT NULL,
- deposit_fee_balance_val bigint NOT NULL,
- deposit_fee_balance_frac integer NOT NULL,
- melt_fee_balance_val bigint NOT NULL,
- melt_fee_balance_frac integer NOT NULL,
- refund_fee_balance_val bigint NOT NULL,
- refund_fee_balance_frac integer NOT NULL,
- risk_val bigint NOT NULL,
- risk_frac integer NOT NULL,
- loss_val bigint NOT NULL,
- loss_frac integer NOT NULL,
- irregular_recoup_val bigint NOT NULL,
- irregular_recoup_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_balance_summary; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_balance_summary IS 'the sum of the outstanding coins from auditor_denomination_pending (denom_pubs must belong to the respectives exchange master public key); it represents the auditor_balance_summary of the exchange at this point (modulo unexpected historic_loss-style events where denomination keys are compromised)';
-
-
---
--- Name: auditor_denom_sigs; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_denom_sigs (
- auditor_denom_serial bigint NOT NULL,
- auditor_uuid bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- auditor_sig bytea,
- CONSTRAINT auditor_denom_sigs_auditor_sig_check CHECK ((length(auditor_sig) = 64))
-);
-
-
---
--- Name: TABLE auditor_denom_sigs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_denom_sigs IS 'Table with auditor signatures on exchange denomination keys.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.auditor_uuid; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.auditor_uuid IS 'Identifies the auditor.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.denominations_serial IS 'Denomination the signature is for.';
-
-
---
--- Name: COLUMN auditor_denom_sigs.auditor_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denom_sigs.auditor_sig IS 'Signature of the auditor, of purpose TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS.';
-
-
---
--- Name: auditor_denom_sigs_auditor_denom_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.auditor_denom_sigs ALTER COLUMN auditor_denom_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.auditor_denom_sigs_auditor_denom_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: auditor_denomination_pending; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_denomination_pending (
- denom_pub_hash bytea NOT NULL,
- denom_balance_val bigint NOT NULL,
- denom_balance_frac integer NOT NULL,
- denom_loss_val bigint NOT NULL,
- denom_loss_frac integer NOT NULL,
- num_issued bigint NOT NULL,
- denom_risk_val bigint NOT NULL,
- denom_risk_frac integer NOT NULL,
- recoup_loss_val bigint NOT NULL,
- recoup_loss_frac integer NOT NULL,
- CONSTRAINT auditor_denomination_pending_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64))
-);
-
-
---
--- Name: TABLE auditor_denomination_pending; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_denomination_pending IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
-
-
---
--- Name: COLUMN auditor_denomination_pending.num_issued; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.num_issued IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
-
-
---
--- Name: COLUMN auditor_denomination_pending.denom_risk_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.denom_risk_val IS 'amount that could theoretically be lost in the future due to recoup operations';
-
-
---
--- Name: COLUMN auditor_denomination_pending.recoup_loss_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_denomination_pending.recoup_loss_val IS 'amount actually lost due to recoup operations past revocation';
-
-
---
--- Name: auditor_exchange_signkeys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_exchange_signkeys (
- master_pub bytea NOT NULL,
- ep_start bigint NOT NULL,
- ep_expire bigint NOT NULL,
- ep_end bigint NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT auditor_exchange_signkeys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT auditor_exchange_signkeys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE auditor_exchange_signkeys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_exchange_signkeys IS 'list of the online signing keys of exchanges we are auditing';
-
-
---
--- Name: auditor_exchanges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_exchanges (
- master_pub bytea NOT NULL,
- exchange_url character varying NOT NULL,
- CONSTRAINT auditor_exchanges_master_pub_check CHECK ((length(master_pub) = 32))
-);
-
-
---
--- Name: TABLE auditor_exchanges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_exchanges IS 'list of the exchanges we are auditing';
-
-
---
--- Name: auditor_historic_denomination_revenue; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_historic_denomination_revenue (
- master_pub bytea NOT NULL,
- denom_pub_hash bytea NOT NULL,
- revenue_timestamp bigint NOT NULL,
- revenue_balance_val bigint NOT NULL,
- revenue_balance_frac integer NOT NULL,
- loss_balance_val bigint NOT NULL,
- loss_balance_frac integer NOT NULL,
- CONSTRAINT auditor_historic_denomination_revenue_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64))
-);
-
-
---
--- Name: TABLE auditor_historic_denomination_revenue; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_historic_denomination_revenue IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
-
-
---
--- Name: COLUMN auditor_historic_denomination_revenue.revenue_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditor_historic_denomination_revenue.revenue_balance_val IS 'the sum of all of the profits we made on the coin except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
-
-
---
--- Name: auditor_historic_reserve_summary; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_historic_reserve_summary (
- master_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- reserve_profits_val bigint NOT NULL,
- reserve_profits_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_historic_reserve_summary; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_historic_reserve_summary IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
-
-
---
--- Name: auditor_predicted_result; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_predicted_result (
- master_pub bytea NOT NULL,
- balance_val bigint NOT NULL,
- balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_predicted_result; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_predicted_result IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance. This is the final amount that the exchange should have in its bank account right now.';
-
-
---
--- Name: auditor_progress_aggregation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_aggregation (
- master_pub bytea NOT NULL,
- last_wire_out_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_aggregation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_aggregation IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_coin; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_coin (
- master_pub bytea NOT NULL,
- last_withdraw_serial_id bigint DEFAULT 0 NOT NULL,
- last_deposit_serial_id bigint DEFAULT 0 NOT NULL,
- last_melt_serial_id bigint DEFAULT 0 NOT NULL,
- last_refund_serial_id bigint DEFAULT 0 NOT NULL,
- last_recoup_serial_id bigint DEFAULT 0 NOT NULL,
- last_recoup_refresh_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_deposits_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_refunds_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_coin; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_coin IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_deposit_confirmation; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_deposit_confirmation (
- master_pub bytea NOT NULL,
- last_deposit_confirmation_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_deposit_confirmation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_deposit_confirmation IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_progress_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_progress_reserve (
- master_pub bytea NOT NULL,
- last_reserve_in_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_out_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_recoup_serial_id bigint DEFAULT 0 NOT NULL,
- last_reserve_close_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_merges_serial_id bigint DEFAULT 0 NOT NULL,
- last_purse_deposits_serial_id bigint DEFAULT 0 NOT NULL,
- last_account_merges_serial_id bigint DEFAULT 0 NOT NULL,
- last_history_requests_serial_id bigint DEFAULT 0 NOT NULL,
- last_close_requests_serial_id bigint DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE auditor_progress_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_progress_reserve IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: auditor_reserve_balance; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_reserve_balance (
- master_pub bytea NOT NULL,
- reserve_balance_val bigint NOT NULL,
- reserve_balance_frac integer NOT NULL,
- withdraw_fee_balance_val bigint NOT NULL,
- withdraw_fee_balance_frac integer NOT NULL,
- purse_fee_balance_val bigint NOT NULL,
- purse_fee_balance_frac integer NOT NULL,
- history_fee_balance_val bigint NOT NULL,
- history_fee_balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_reserve_balance; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_reserve_balance IS 'sum of the balances of all customer reserves (by exchange master public key)';
-
-
---
--- Name: auditor_reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_reserves (
- reserve_pub bytea NOT NULL,
- master_pub bytea NOT NULL,
- reserve_balance_val bigint NOT NULL,
- reserve_balance_frac integer NOT NULL,
- withdraw_fee_balance_val bigint NOT NULL,
- withdraw_fee_balance_frac integer NOT NULL,
- expiration_date bigint NOT NULL,
- auditor_reserves_rowid bigint NOT NULL,
- origin_account text,
- CONSTRAINT auditor_reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-
-
---
--- Name: TABLE auditor_reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_reserves IS 'all of the customer reserves and their respective balances that the auditor is aware of';
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auditor_reserves_auditor_reserves_rowid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auditor_reserves_auditor_reserves_rowid_seq OWNED BY public.auditor_reserves.auditor_reserves_rowid;
-
-
---
--- Name: auditor_wire_fee_balance; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditor_wire_fee_balance (
- master_pub bytea NOT NULL,
- wire_fee_balance_val bigint NOT NULL,
- wire_fee_balance_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE auditor_wire_fee_balance; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditor_wire_fee_balance IS 'sum of the balances of all wire fees (by exchange master public key)';
-
-
---
--- Name: auditors; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auditors (
- auditor_uuid bigint NOT NULL,
- auditor_pub bytea NOT NULL,
- auditor_name character varying NOT NULL,
- auditor_url character varying NOT NULL,
- is_active boolean NOT NULL,
- last_change bigint NOT NULL,
- CONSTRAINT auditors_auditor_pub_check CHECK ((length(auditor_pub) = 32))
-);
-
-
---
--- Name: TABLE auditors; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.auditors IS 'Table with auditors the exchange uses or has used in the past. Entries never expire as we need to remember the last_change column indefinitely.';
-
-
---
--- Name: COLUMN auditors.auditor_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.auditor_pub IS 'Public key of the auditor.';
-
-
---
--- Name: COLUMN auditors.auditor_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.auditor_url IS 'The base URL of the auditor.';
-
-
---
--- Name: COLUMN auditors.is_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.is_active IS 'true if we are currently supporting the use of this auditor.';
-
-
---
--- Name: COLUMN auditors.last_change; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.auditors.last_change IS 'Latest time when active status changed. Used to detect replays of old messages.';
-
-
---
--- Name: auditors_auditor_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.auditors ALTER COLUMN auditor_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.auditors_auditor_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: auth_group; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_group (
- id integer NOT NULL,
- name character varying(150) NOT NULL
-);
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_group_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_group_id_seq OWNED BY public.auth_group.id;
-
-
---
--- Name: auth_group_permissions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_group_permissions (
- id bigint NOT NULL,
- group_id integer NOT NULL,
- permission_id integer NOT NULL
-);
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_group_permissions_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_group_permissions_id_seq OWNED BY public.auth_group_permissions.id;
-
-
---
--- Name: auth_permission; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_permission (
- id integer NOT NULL,
- name character varying(255) NOT NULL,
- content_type_id integer NOT NULL,
- codename character varying(100) NOT NULL
-);
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_permission_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_permission_id_seq OWNED BY public.auth_permission.id;
-
-
---
--- Name: auth_user; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user (
- id integer NOT NULL,
- password character varying(128) NOT NULL,
- last_login timestamp with time zone,
- is_superuser boolean NOT NULL,
- username character varying(150) NOT NULL,
- first_name character varying(150) NOT NULL,
- last_name character varying(150) NOT NULL,
- email character varying(254) NOT NULL,
- is_staff boolean NOT NULL,
- is_active boolean NOT NULL,
- date_joined timestamp with time zone NOT NULL
-);
-
-
---
--- Name: auth_user_groups; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user_groups (
- id bigint NOT NULL,
- user_id integer NOT NULL,
- group_id integer NOT NULL
-);
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_groups_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_groups_id_seq OWNED BY public.auth_user_groups.id;
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_id_seq OWNED BY public.auth_user.id;
-
-
---
--- Name: auth_user_user_permissions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.auth_user_user_permissions (
- id bigint NOT NULL,
- user_id integer NOT NULL,
- permission_id integer NOT NULL
-);
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.auth_user_user_permissions_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.auth_user_user_permissions_id_seq OWNED BY public.auth_user_user_permissions.id;
-
-
---
--- Name: close_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.close_requests (
- close_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- close_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- close_val bigint NOT NULL,
- close_frac integer NOT NULL,
- CONSTRAINT close_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT close_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE close_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.close_requests IS 'Explicit requests by a reserve owner to close a reserve immediately';
-
-
---
--- Name: COLUMN close_requests.close_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.close_timestamp IS 'When the request was created by the client';
-
-
---
--- Name: COLUMN close_requests.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.reserve_sig IS 'Signature affirming that the reserve is to be closed';
-
-
---
--- Name: COLUMN close_requests.close_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.close_requests.close_val IS 'Balance of the reserve at the time of closing, to be wired to the associated bank account (minus the closing fee)';
-
-
---
--- Name: close_requests_close_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.close_requests ALTER COLUMN close_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.close_requests_close_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: close_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.close_requests_default (
- close_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- close_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- close_val bigint NOT NULL,
- close_frac integer NOT NULL,
- CONSTRAINT close_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT close_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.close_requests ATTACH PARTITION public.close_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: contracts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.contracts (
- contract_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- pub_ckey bytea NOT NULL,
- contract_sig bytea NOT NULL,
- e_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- CONSTRAINT contracts_contract_sig_check CHECK ((length(contract_sig) = 64)),
- CONSTRAINT contracts_pub_ckey_check CHECK ((length(pub_ckey) = 32)),
- CONSTRAINT contracts_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE contracts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.contracts IS 'encrypted contracts associated with purses';
-
-
---
--- Name: COLUMN contracts.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.purse_pub IS 'public key of the purse that the contract is associated with';
-
-
---
--- Name: COLUMN contracts.pub_ckey; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.pub_ckey IS 'Public ECDH key used to encrypt the contract, to be used with the purse private key for decryption';
-
-
---
--- Name: COLUMN contracts.contract_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.contract_sig IS 'signature over the encrypted contract by the purse contract key';
-
-
---
--- Name: COLUMN contracts.e_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.contracts.e_contract IS 'AES-GCM encrypted contract terms (contains gzip compressed JSON after decryption)';
-
-
---
--- Name: contracts_contract_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.contracts ALTER COLUMN contract_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.contracts_contract_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: contracts_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.contracts_default (
- contract_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- pub_ckey bytea NOT NULL,
- contract_sig bytea NOT NULL,
- e_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- CONSTRAINT contracts_contract_sig_check CHECK ((length(contract_sig) = 64)),
- CONSTRAINT contracts_pub_ckey_check CHECK ((length(pub_ckey) = 32)),
- CONSTRAINT contracts_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.contracts ATTACH PARTITION public.contracts_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: cs_nonce_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.cs_nonce_locks (
- cs_nonce_lock_serial_id bigint NOT NULL,
- nonce bytea NOT NULL,
- op_hash bytea NOT NULL,
- max_denomination_serial bigint NOT NULL,
- CONSTRAINT cs_nonce_locks_nonce_check CHECK ((length(nonce) = 32)),
- CONSTRAINT cs_nonce_locks_op_hash_check CHECK ((length(op_hash) = 64))
-)
-PARTITION BY HASH (nonce);
-
-
---
--- Name: TABLE cs_nonce_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.cs_nonce_locks IS 'ensures a Clause Schnorr client nonce is locked for use with an operation identified by a hash';
-
-
---
--- Name: COLUMN cs_nonce_locks.nonce; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.nonce IS 'actual nonce submitted by the client';
-
-
---
--- Name: COLUMN cs_nonce_locks.op_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.op_hash IS 'hash (RC for refresh, blind coin hash for withdraw) the nonce may be used with';
-
-
---
--- Name: COLUMN cs_nonce_locks.max_denomination_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.cs_nonce_locks.max_denomination_serial IS 'Maximum number of a CS denomination serial the nonce could be used with, for GC';
-
-
---
--- Name: cs_nonce_locks_cs_nonce_lock_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.cs_nonce_locks ALTER COLUMN cs_nonce_lock_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.cs_nonce_locks_cs_nonce_lock_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: cs_nonce_locks_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.cs_nonce_locks_default (
- cs_nonce_lock_serial_id bigint NOT NULL,
- nonce bytea NOT NULL,
- op_hash bytea NOT NULL,
- max_denomination_serial bigint NOT NULL,
- CONSTRAINT cs_nonce_locks_nonce_check CHECK ((length(nonce) = 32)),
- CONSTRAINT cs_nonce_locks_op_hash_check CHECK ((length(op_hash) = 64))
-);
-ALTER TABLE ONLY public.cs_nonce_locks ATTACH PARTITION public.cs_nonce_locks_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: denomination_revocations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.denomination_revocations (
- denom_revocations_serial_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT denomination_revocations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE denomination_revocations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.denomination_revocations IS 'remembering which denomination keys have been revoked';
-
-
---
--- Name: denomination_revocations_denom_revocations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.denomination_revocations ALTER COLUMN denom_revocations_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.denomination_revocations_denom_revocations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: denominations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.denominations (
- denominations_serial bigint NOT NULL,
- denom_pub_hash bytea NOT NULL,
- denom_type integer DEFAULT 1 NOT NULL,
- age_mask integer DEFAULT 0 NOT NULL,
- denom_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- valid_from bigint NOT NULL,
- expire_withdraw bigint NOT NULL,
- expire_deposit bigint NOT NULL,
- expire_legal bigint NOT NULL,
- coin_val bigint NOT NULL,
- coin_frac integer NOT NULL,
- fee_withdraw_val bigint NOT NULL,
- fee_withdraw_frac integer NOT NULL,
- fee_deposit_val bigint NOT NULL,
- fee_deposit_frac integer NOT NULL,
- fee_refresh_val bigint NOT NULL,
- fee_refresh_frac integer NOT NULL,
- fee_refund_val bigint NOT NULL,
- fee_refund_frac integer NOT NULL,
- CONSTRAINT denominations_denom_pub_hash_check CHECK ((length(denom_pub_hash) = 64)),
- CONSTRAINT denominations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE denominations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.denominations IS 'Main denominations table. All the valid denominations the exchange knows about.';
-
-
---
--- Name: COLUMN denominations.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.denominations_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN denominations.denom_type; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.denom_type IS 'determines cipher type for blind signatures used with this denomination; 0 is for RSA';
-
-
---
--- Name: COLUMN denominations.age_mask; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.denominations.age_mask IS 'bitmask with the age restrictions that are being used for this denomination; 0 if denomination does not support the use of age restrictions';
-
-
---
--- Name: denominations_denominations_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.denominations ALTER COLUMN denominations_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.denominations_denominations_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: deposit_confirmations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposit_confirmations (
- master_pub bytea NOT NULL,
- serial_id bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- h_extensions bytea NOT NULL,
- h_wire bytea NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- amount_without_fee_val bigint NOT NULL,
- amount_without_fee_frac integer NOT NULL,
- coin_pub bytea NOT NULL,
- merchant_pub bytea NOT NULL,
- exchange_sig bytea NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT deposit_confirmations_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposit_confirmations_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT deposit_confirmations_exchange_sig_check CHECK ((length(exchange_sig) = 64)),
- CONSTRAINT deposit_confirmations_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposit_confirmations_h_contract_terms_check1 CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposit_confirmations_h_wire_check CHECK ((length(h_wire) = 64)),
- CONSTRAINT deposit_confirmations_master_sig_check CHECK ((length(master_sig) = 64)),
- CONSTRAINT deposit_confirmations_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-
-
---
--- Name: TABLE deposit_confirmations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposit_confirmations IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.deposit_confirmations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.deposit_confirmations_serial_id_seq OWNED BY public.deposit_confirmations.serial_id;
-
-
---
--- Name: deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits (
- deposit_serial_id bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wallet_timestamp bigint NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- coin_sig bytea NOT NULL,
- wire_salt bytea NOT NULL,
- wire_target_h_payto bytea,
- done boolean DEFAULT false NOT NULL,
- extension_blocked boolean DEFAULT false NOT NULL,
- extension_details_serial_id bigint,
- CONSTRAINT deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT deposits_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposits_merchant_pub_check CHECK ((length(merchant_pub) = 32)),
- CONSTRAINT deposits_wire_salt_check CHECK ((length(wire_salt) = 16)),
- CONSTRAINT deposits_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits IS 'Deposits we have received and for which we need to make (aggregate) wire transfers (and manage refunds).';
-
-
---
--- Name: COLUMN deposits.shard; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.shard IS 'Used for load sharding in the materialized indices. Should be set based on merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.';
-
-
---
--- Name: COLUMN deposits.known_coin_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.known_coin_id IS 'Used for garbage collection';
-
-
---
--- Name: COLUMN deposits.wire_salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.wire_salt IS 'Salt used when hashing the payto://-URI to get the h_wire';
-
-
---
--- Name: COLUMN deposits.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.wire_target_h_payto IS 'Identifies the target bank account and KYC status';
-
-
---
--- Name: COLUMN deposits.done; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.done IS 'Set to TRUE once we have included this deposit in some aggregate wire transfer to the merchant';
-
-
---
--- Name: COLUMN deposits.extension_blocked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.extension_blocked IS 'True if the aggregation of the deposit is currently blocked by some extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.';
-
-
---
--- Name: COLUMN deposits.extension_details_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.deposits.extension_details_serial_id IS 'References extensions table, NULL if extensions are not used';
-
-
---
--- Name: deposits_by_ready; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_by_ready (
- wire_deadline bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_by_ready_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY RANGE (wire_deadline);
-
-
---
--- Name: TABLE deposits_by_ready; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits_by_ready IS 'Enables fast lookups for deposits_get_ready, auto-populated via TRIGGER below';
-
-
---
--- Name: deposits_by_ready_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_by_ready_default (
- wire_deadline bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_by_ready_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.deposits_by_ready ATTACH PARTITION public.deposits_by_ready_default DEFAULT;
-
-
---
--- Name: deposits_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_default (
- deposit_serial_id bigint NOT NULL,
- shard bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wallet_timestamp bigint NOT NULL,
- exchange_timestamp bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- wire_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- coin_sig bytea NOT NULL,
- wire_salt bytea NOT NULL,
- wire_target_h_payto bytea,
- done boolean DEFAULT false NOT NULL,
- extension_blocked boolean DEFAULT false NOT NULL,
- extension_details_serial_id bigint,
- CONSTRAINT deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT deposits_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT deposits_merchant_pub_check CHECK ((length(merchant_pub) = 32)),
- CONSTRAINT deposits_wire_salt_check CHECK ((length(wire_salt) = 16)),
- CONSTRAINT deposits_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-);
-ALTER TABLE ONLY public.deposits ATTACH PARTITION public.deposits_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: deposits_deposit_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.deposits ALTER COLUMN deposit_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.deposits_deposit_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: deposits_for_matching; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_for_matching (
- refund_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_for_matching_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_for_matching_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-)
-PARTITION BY RANGE (refund_deadline);
-
-
---
--- Name: TABLE deposits_for_matching; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.deposits_for_matching IS 'Enables fast lookups for deposits_iterate_matching, auto-populated via TRIGGER below';
-
-
---
--- Name: deposits_for_matching_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.deposits_for_matching_default (
- refund_deadline bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint,
- CONSTRAINT deposits_for_matching_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT deposits_for_matching_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-ALTER TABLE ONLY public.deposits_for_matching ATTACH PARTITION public.deposits_for_matching_default DEFAULT;
-
-
---
--- Name: django_content_type; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_content_type (
- id integer NOT NULL,
- app_label character varying(100) NOT NULL,
- model character varying(100) NOT NULL
-);
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.django_content_type_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.django_content_type_id_seq OWNED BY public.django_content_type.id;
-
-
---
--- Name: django_migrations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_migrations (
- id bigint NOT NULL,
- app character varying(255) NOT NULL,
- name character varying(255) NOT NULL,
- applied timestamp with time zone NOT NULL
-);
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-CREATE SEQUENCE public.django_migrations_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1;
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
---
-
-ALTER SEQUENCE public.django_migrations_id_seq OWNED BY public.django_migrations.id;
-
-
---
--- Name: django_session; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.django_session (
- session_key character varying(40) NOT NULL,
- session_data text NOT NULL,
- expire_date timestamp with time zone NOT NULL
-);
-
-
---
--- Name: exchange_sign_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.exchange_sign_keys (
- esk_serial bigint NOT NULL,
- exchange_pub bytea NOT NULL,
- master_sig bytea NOT NULL,
- valid_from bigint NOT NULL,
- expire_sign bigint NOT NULL,
- expire_legal bigint NOT NULL,
- CONSTRAINT exchange_sign_keys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT exchange_sign_keys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE exchange_sign_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.exchange_sign_keys IS 'Table with master public key signatures on exchange online signing keys.';
-
-
---
--- Name: COLUMN exchange_sign_keys.exchange_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.exchange_pub IS 'Public online signing key of the exchange.';
-
-
---
--- Name: COLUMN exchange_sign_keys.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.master_sig IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
-
-
---
--- Name: COLUMN exchange_sign_keys.valid_from; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.valid_from IS 'Time when this online signing key will first be used to sign messages.';
-
-
---
--- Name: COLUMN exchange_sign_keys.expire_sign; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.expire_sign IS 'Time when this online signing key will no longer be used to sign.';
-
-
---
--- Name: COLUMN exchange_sign_keys.expire_legal; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.exchange_sign_keys.expire_legal IS 'Time when this online signing key legally expires.';
-
-
---
--- Name: exchange_sign_keys_esk_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.exchange_sign_keys ALTER COLUMN esk_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.exchange_sign_keys_esk_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: extension_details; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extension_details (
- extension_details_serial_id bigint NOT NULL,
- extension_options character varying
-)
-PARTITION BY HASH (extension_details_serial_id);
-
-
---
--- Name: TABLE extension_details; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.extension_details IS 'Extensions that were provided with deposits (not yet used).';
-
-
---
--- Name: COLUMN extension_details.extension_options; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extension_details.extension_options IS 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the extensions supported by the exchange.';
-
-
---
--- Name: extension_details_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extension_details_default (
- extension_details_serial_id bigint NOT NULL,
- extension_options character varying
-);
-ALTER TABLE ONLY public.extension_details ATTACH PARTITION public.extension_details_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: extension_details_extension_details_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.extension_details ALTER COLUMN extension_details_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.extension_details_extension_details_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: extensions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.extensions (
- extension_id bigint NOT NULL,
- name character varying NOT NULL,
- config bytea
-);
-
-
---
--- Name: TABLE extensions; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.extensions IS 'Configurations of the activated extensions';
-
-
---
--- Name: COLUMN extensions.name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extensions.name IS 'Name of the extension';
-
-
---
--- Name: COLUMN extensions.config; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.extensions.config IS 'Configuration of the extension as JSON-blob, maybe NULL';
-
-
---
--- Name: extensions_extension_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.extensions ALTER COLUMN extension_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.extensions_extension_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: global_fee; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.global_fee (
- global_fee_serial bigint NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- kyc_fee_val bigint NOT NULL,
- kyc_fee_frac integer NOT NULL,
- account_fee_val bigint NOT NULL,
- account_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- purse_timeout bigint NOT NULL,
- kyc_timeout bigint NOT NULL,
- history_expiration bigint NOT NULL,
- purse_account_limit integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT global_fee_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE global_fee; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.global_fee IS 'list of the global fees of this exchange, by date';
-
-
---
--- Name: COLUMN global_fee.global_fee_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.global_fee.global_fee_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: global_fee_global_fee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.global_fee ALTER COLUMN global_fee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.global_fee_global_fee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: history_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.history_requests (
- history_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- request_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- CONSTRAINT history_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT history_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE history_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.history_requests IS 'Paid history requests issued by a client against a reserve';
-
-
---
--- Name: COLUMN history_requests.request_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.request_timestamp IS 'When was the history request made';
-
-
---
--- Name: COLUMN history_requests.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.reserve_sig IS 'Signature approving payment for the history request';
-
-
---
--- Name: COLUMN history_requests.history_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.history_requests.history_fee_val IS 'History fee approved by the signature';
-
-
---
--- Name: history_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.history_requests_default (
- history_request_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- request_timestamp bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- history_fee_val bigint NOT NULL,
- history_fee_frac integer NOT NULL,
- CONSTRAINT history_requests_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT history_requests_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.history_requests ATTACH PARTITION public.history_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: history_requests_history_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.history_requests ALTER COLUMN history_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.history_requests_history_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: known_coins; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.known_coins (
- known_coin_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_pub bytea NOT NULL,
- age_commitment_hash bytea,
- denom_sig bytea NOT NULL,
- remaining_val bigint DEFAULT 0 NOT NULL,
- remaining_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT known_coins_age_commitment_hash_check CHECK ((length(age_commitment_hash) = 32)),
- CONSTRAINT known_coins_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE known_coins; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.known_coins IS 'information about coins and their signatures, so we do not have to store the signatures more than once if a coin is involved in multiple operations';
-
-
---
--- Name: COLUMN known_coins.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.denominations_serial IS 'Denomination of the coin, determines the value of the original coin and applicable fees for coin-specific operations.';
-
-
---
--- Name: COLUMN known_coins.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.coin_pub IS 'EdDSA public key of the coin';
-
-
---
--- Name: COLUMN known_coins.age_commitment_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.age_commitment_hash IS 'Optional hash of the age commitment for age restrictions as per DD 24 (active if denom_type has the respective bit set)';
-
-
---
--- Name: COLUMN known_coins.denom_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.denom_sig IS 'This is the signature of the exchange that affirms that the coin is a valid coin. The specific signature type depends on denom_type of the denomination.';
-
-
---
--- Name: COLUMN known_coins.remaining_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.known_coins.remaining_val IS 'Value of the coin that remains to be spent';
-
-
---
--- Name: known_coins_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.known_coins_default (
- known_coin_id bigint NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_pub bytea NOT NULL,
- age_commitment_hash bytea,
- denom_sig bytea NOT NULL,
- remaining_val bigint DEFAULT 0 NOT NULL,
- remaining_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT known_coins_age_commitment_hash_check CHECK ((length(age_commitment_hash) = 32)),
- CONSTRAINT known_coins_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.known_coins ATTACH PARTITION public.known_coins_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: known_coins_known_coin_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.known_coins ALTER COLUMN known_coin_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.known_coins_known_coin_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_accounts (
- account_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- h_wire bytea NOT NULL,
- salt bytea NOT NULL,
- payto_uri character varying NOT NULL,
- active boolean NOT NULL,
- CONSTRAINT merchant_accounts_h_wire_check CHECK ((length(h_wire) = 64)),
- CONSTRAINT merchant_accounts_salt_check CHECK ((length(salt) = 16))
-);
-
-
---
--- Name: TABLE merchant_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_accounts IS 'bank accounts of the instances';
-
-
---
--- Name: COLUMN merchant_accounts.h_wire; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.h_wire IS 'salted hash of payto_uri';
-
-
---
--- Name: COLUMN merchant_accounts.salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.salt IS 'salt used when hashing payto_uri into h_wire';
-
-
---
--- Name: COLUMN merchant_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.payto_uri IS 'payto URI of a merchant bank account';
-
-
---
--- Name: COLUMN merchant_accounts.active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_accounts.active IS 'true if we actively use this bank account, false if it is just kept around for older contracts to refer to';
-
-
---
--- Name: merchant_accounts_account_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_accounts ALTER COLUMN account_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_accounts_account_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_contract_terms; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_contract_terms (
- order_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- order_id character varying NOT NULL,
- contract_terms bytea NOT NULL,
- h_contract_terms bytea NOT NULL,
- creation_time bigint NOT NULL,
- pay_deadline bigint NOT NULL,
- refund_deadline bigint NOT NULL,
- paid boolean DEFAULT false NOT NULL,
- wired boolean DEFAULT false NOT NULL,
- fulfillment_url character varying,
- session_id character varying DEFAULT ''::character varying NOT NULL,
- claim_token bytea NOT NULL,
- CONSTRAINT merchant_contract_terms_claim_token_check CHECK ((length(claim_token) = 16)),
- CONSTRAINT merchant_contract_terms_h_contract_terms_check CHECK ((length(h_contract_terms) = 64))
-);
-
-
---
--- Name: TABLE merchant_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_contract_terms IS 'Contracts are orders that have been claimed by a wallet';
-
-
---
--- Name: COLUMN merchant_contract_terms.merchant_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.merchant_serial IS 'Identifies the instance offering the contract';
-
-
---
--- Name: COLUMN merchant_contract_terms.order_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.order_id IS 'Not a foreign key into merchant_orders because paid contracts persist after expiration';
-
-
---
--- Name: COLUMN merchant_contract_terms.contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.contract_terms IS 'These contract terms include the wallet nonce';
-
-
---
--- Name: COLUMN merchant_contract_terms.h_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.h_contract_terms IS 'Hash over contract_terms';
-
-
---
--- Name: COLUMN merchant_contract_terms.pay_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.pay_deadline IS 'How long is the offer valid. After this time, the order can be garbage collected';
-
-
---
--- Name: COLUMN merchant_contract_terms.refund_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.refund_deadline IS 'By what times do refunds have to be approved (useful to reject refund requests)';
-
-
---
--- Name: COLUMN merchant_contract_terms.paid; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.paid IS 'true implies the customer paid for this contract; order should be DELETEd from merchant_orders once paid is set to release merchant_order_locks; paid remains true even if the payment was later refunded';
-
-
---
--- Name: COLUMN merchant_contract_terms.wired; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.wired IS 'true implies the exchange wired us the full amount for all non-refunded payments under this contract';
-
-
---
--- Name: COLUMN merchant_contract_terms.fulfillment_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.fulfillment_url IS 'also included in contract_terms, but we need it here to SELECT on it during repurchase detection; can be NULL if the contract has no fulfillment URL';
-
-
---
--- Name: COLUMN merchant_contract_terms.session_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.session_id IS 'last session_id from we confirmed the paying client to use, empty string for none';
-
-
---
--- Name: COLUMN merchant_contract_terms.claim_token; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_contract_terms.claim_token IS 'Token optionally used to access the status of the order. All zeros (not NULL) if not used';
-
-
---
--- Name: merchant_deposit_to_transfer; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_deposit_to_transfer (
- deposit_serial bigint NOT NULL,
- coin_contribution_value_val bigint NOT NULL,
- coin_contribution_value_frac integer NOT NULL,
- credit_serial bigint NOT NULL,
- execution_time bigint NOT NULL,
- signkey_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- CONSTRAINT merchant_deposit_to_transfer_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_deposit_to_transfer; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_deposit_to_transfer IS 'Mapping of deposits to (possibly unconfirmed) wire transfers; NOTE: not used yet';
-
-
---
--- Name: COLUMN merchant_deposit_to_transfer.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposit_to_transfer.execution_time IS 'Execution time as claimed by the exchange, roughly matches time seen by merchant';
-
-
---
--- Name: merchant_deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_deposits (
- deposit_serial bigint NOT NULL,
- order_serial bigint,
- deposit_timestamp bigint NOT NULL,
- coin_pub bytea NOT NULL,
- exchange_url character varying NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- deposit_fee_val bigint NOT NULL,
- deposit_fee_frac integer NOT NULL,
- refund_fee_val bigint NOT NULL,
- refund_fee_frac integer NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- signkey_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- account_serial bigint NOT NULL,
- CONSTRAINT merchant_deposits_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT merchant_deposits_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_deposits IS 'Refunds approved by the merchant (backoffice) logic, excludes abort refunds';
-
-
---
--- Name: COLUMN merchant_deposits.deposit_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.deposit_timestamp IS 'Time when the exchange generated the deposit confirmation';
-
-
---
--- Name: COLUMN merchant_deposits.wire_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.wire_fee_val IS 'We MAY want to see if we should try to get this via merchant_exchange_wire_fees (not sure, may be too complicated with the date range, etc.)';
-
-
---
--- Name: COLUMN merchant_deposits.signkey_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.signkey_serial IS 'Online signing key of the exchange on the deposit confirmation';
-
-
---
--- Name: COLUMN merchant_deposits.exchange_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_deposits.exchange_sig IS 'Signature of the exchange over the deposit confirmation';
-
-
---
--- Name: merchant_deposits_deposit_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_deposits ALTER COLUMN deposit_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_deposits_deposit_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_exchange_signing_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_exchange_signing_keys (
- signkey_serial bigint NOT NULL,
- master_pub bytea NOT NULL,
- exchange_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- expire_date bigint NOT NULL,
- end_date bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT merchant_exchange_signing_keys_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT merchant_exchange_signing_keys_master_pub_check CHECK ((length(master_pub) = 32)),
- CONSTRAINT merchant_exchange_signing_keys_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_exchange_signing_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_exchange_signing_keys IS 'Here we store proofs of the exchange online signing keys being signed by the exchange master key';
-
-
---
--- Name: COLUMN merchant_exchange_signing_keys.master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_exchange_signing_keys.master_pub IS 'Master public key of the exchange with these online signing keys';
-
-
---
--- Name: merchant_exchange_signing_keys_signkey_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_exchange_signing_keys ALTER COLUMN signkey_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_exchange_signing_keys_signkey_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_exchange_wire_fees; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_exchange_wire_fees (
- wirefee_serial bigint NOT NULL,
- master_pub bytea NOT NULL,
- h_wire_method bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT merchant_exchange_wire_fees_h_wire_method_check CHECK ((length(h_wire_method) = 64)),
- CONSTRAINT merchant_exchange_wire_fees_master_pub_check CHECK ((length(master_pub) = 32)),
- CONSTRAINT merchant_exchange_wire_fees_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_exchange_wire_fees; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_exchange_wire_fees IS 'Here we store proofs of the wire fee structure of the various exchanges';
-
-
---
--- Name: COLUMN merchant_exchange_wire_fees.master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_exchange_wire_fees.master_pub IS 'Master public key of the exchange with these wire fees';
-
-
---
--- Name: merchant_exchange_wire_fees_wirefee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_exchange_wire_fees ALTER COLUMN wirefee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_exchange_wire_fees_wirefee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_instances; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_instances (
- merchant_serial bigint NOT NULL,
- merchant_pub bytea NOT NULL,
- auth_hash bytea,
- auth_salt bytea,
- merchant_id character varying NOT NULL,
- merchant_name character varying NOT NULL,
- address bytea NOT NULL,
- jurisdiction bytea NOT NULL,
- default_max_deposit_fee_val bigint NOT NULL,
- default_max_deposit_fee_frac integer NOT NULL,
- default_max_wire_fee_val bigint NOT NULL,
- default_max_wire_fee_frac integer NOT NULL,
- default_wire_fee_amortization integer NOT NULL,
- default_wire_transfer_delay bigint NOT NULL,
- default_pay_delay bigint NOT NULL,
- website character varying,
- email character varying,
- logo bytea,
- CONSTRAINT merchant_instances_auth_hash_check CHECK ((length(auth_hash) = 64)),
- CONSTRAINT merchant_instances_auth_salt_check CHECK ((length(auth_salt) = 32)),
- CONSTRAINT merchant_instances_merchant_pub_check CHECK ((length(merchant_pub) = 32))
-);
-
-
---
--- Name: TABLE merchant_instances; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_instances IS 'all the instances supported by this backend';
-
-
---
--- Name: COLUMN merchant_instances.auth_hash; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.auth_hash IS 'hash used for merchant back office Authorization, NULL for no check';
-
-
---
--- Name: COLUMN merchant_instances.auth_salt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.auth_salt IS 'salt to use when hashing Authorization header before comparing with auth_hash';
-
-
---
--- Name: COLUMN merchant_instances.merchant_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.merchant_id IS 'identifier of the merchant as used in the base URL (required)';
-
-
---
--- Name: COLUMN merchant_instances.merchant_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.merchant_name IS 'legal name of the merchant as a simple string (required)';
-
-
---
--- Name: COLUMN merchant_instances.address; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.address IS 'physical address of the merchant as a Location in JSON format (required)';
-
-
---
--- Name: COLUMN merchant_instances.jurisdiction; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.jurisdiction IS 'jurisdiction of the merchant as a Location in JSON format (required)';
-
-
---
--- Name: COLUMN merchant_instances.website; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.website IS 'merchant site URL';
-
-
---
--- Name: COLUMN merchant_instances.email; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.email IS 'email';
-
-
---
--- Name: COLUMN merchant_instances.logo; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_instances.logo IS 'data image url';
-
-
---
--- Name: merchant_instances_merchant_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_instances ALTER COLUMN merchant_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_instances_merchant_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_inventory; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_inventory (
- product_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- product_id character varying NOT NULL,
- description character varying NOT NULL,
- description_i18n bytea NOT NULL,
- unit character varying NOT NULL,
- image bytea NOT NULL,
- taxes bytea NOT NULL,
- price_val bigint NOT NULL,
- price_frac integer NOT NULL,
- total_stock bigint NOT NULL,
- total_sold bigint DEFAULT 0 NOT NULL,
- total_lost bigint DEFAULT 0 NOT NULL,
- address bytea NOT NULL,
- next_restock bigint NOT NULL,
- minimum_age integer DEFAULT 0 NOT NULL
-);
-
-
---
--- Name: TABLE merchant_inventory; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_inventory IS 'products offered by the merchant (may be incomplete, frontend can override)';
-
-
---
--- Name: COLUMN merchant_inventory.description; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.description IS 'Human-readable product description';
-
-
---
--- Name: COLUMN merchant_inventory.description_i18n; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.description_i18n IS 'JSON map from IETF BCP 47 language tags to localized descriptions';
-
-
---
--- Name: COLUMN merchant_inventory.unit; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.unit IS 'Unit of sale for the product (liters, kilograms, packages)';
-
-
---
--- Name: COLUMN merchant_inventory.image; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.image IS 'NOT NULL, but can be 0 bytes; must contain an ImageDataUrl';
-
-
---
--- Name: COLUMN merchant_inventory.taxes; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.taxes IS 'JSON array containing taxes the merchant pays, must be JSON, but can be just "[]"';
-
-
---
--- Name: COLUMN merchant_inventory.price_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.price_val IS 'Current price of one unit of the product';
-
-
---
--- Name: COLUMN merchant_inventory.total_stock; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_stock IS 'A value of -1 is used for unlimited (electronic good), may never be lowered';
-
-
---
--- Name: COLUMN merchant_inventory.total_sold; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_sold IS 'Number of products sold, must be below total_stock, non-negative, may never be lowered';
-
-
---
--- Name: COLUMN merchant_inventory.total_lost; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.total_lost IS 'Number of products that used to be in stock but were lost (spoiled, damaged), may never be lowered; total_stock >= total_sold + total_lost must always hold';
-
-
---
--- Name: COLUMN merchant_inventory.address; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.address IS 'JSON formatted Location of where the product is stocked';
-
-
---
--- Name: COLUMN merchant_inventory.next_restock; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.next_restock IS 'GNUnet absolute time indicating when the next restock is expected. 0 for unknown.';
-
-
---
--- Name: COLUMN merchant_inventory.minimum_age; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory.minimum_age IS 'Minimum age of the customer in years, to be used if an exchange supports the age restriction extension.';
-
-
---
--- Name: merchant_inventory_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_inventory_locks (
- product_serial bigint NOT NULL,
- lock_uuid bytea NOT NULL,
- total_locked bigint NOT NULL,
- expiration bigint NOT NULL,
- CONSTRAINT merchant_inventory_locks_lock_uuid_check CHECK ((length(lock_uuid) = 16))
-);
-
-
---
--- Name: TABLE merchant_inventory_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_inventory_locks IS 'locks on inventory helt by shopping carts; note that locks MAY not be honored if merchants increase total_lost for inventory';
-
-
---
--- Name: COLUMN merchant_inventory_locks.total_locked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory_locks.total_locked IS 'how many units of the product does this lock reserve';
-
-
---
--- Name: COLUMN merchant_inventory_locks.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_inventory_locks.expiration IS 'when does this lock automatically expire (if no order is created)';
-
-
---
--- Name: merchant_inventory_product_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_inventory ALTER COLUMN product_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_inventory_product_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_keys (
- merchant_priv bytea NOT NULL,
- merchant_serial bigint NOT NULL,
- CONSTRAINT merchant_keys_merchant_priv_check CHECK ((length(merchant_priv) = 32))
-);
-
-
---
--- Name: TABLE merchant_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_keys IS 'private keys of instances that have not been deleted';
-
-
---
--- Name: merchant_kyc; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_kyc (
- kyc_serial_id bigint NOT NULL,
- kyc_timestamp bigint NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- exchange_sig bytea,
- exchange_pub bytea,
- exchange_kyc_serial bigint DEFAULT 0 NOT NULL,
- account_serial bigint NOT NULL,
- exchange_url character varying NOT NULL,
- CONSTRAINT merchant_kyc_exchange_pub_check CHECK ((length(exchange_pub) = 32)),
- CONSTRAINT merchant_kyc_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_kyc; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_kyc IS 'Status of the KYC process of a merchant account at an exchange';
-
-
---
--- Name: COLUMN merchant_kyc.kyc_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.kyc_timestamp IS 'Last time we checked our KYC status at the exchange. Useful to re-check if the status is very stale. Also the timestamp used for the exchange signature (if present).';
-
-
---
--- Name: COLUMN merchant_kyc.kyc_ok; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.kyc_ok IS 'true if the KYC check was passed successfully';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_sig IS 'signature of the exchange affirming the KYC passed (or NULL if exchange does not require KYC or not kyc_ok)';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_pub IS 'public key used with exchange_sig (or NULL if exchange_sig is NULL)';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_kyc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_kyc_serial IS 'Number to use in the KYC-endpoints of the exchange to check the KYC status or begin the KYC process. 0 if we do not know it yet.';
-
-
---
--- Name: COLUMN merchant_kyc.account_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.account_serial IS 'Which bank account of the merchant is the KYC status for';
-
-
---
--- Name: COLUMN merchant_kyc.exchange_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_kyc.exchange_url IS 'Which exchange base URL is this KYC status valid for';
-
-
---
--- Name: merchant_kyc_kyc_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_kyc ALTER COLUMN kyc_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_kyc_kyc_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_order_locks; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_order_locks (
- product_serial bigint NOT NULL,
- total_locked bigint NOT NULL,
- order_serial bigint NOT NULL
-);
-
-
---
--- Name: TABLE merchant_order_locks; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_order_locks IS 'locks on orders awaiting claim and payment; note that locks MAY not be honored if merchants increase total_lost for inventory';
-
-
---
--- Name: COLUMN merchant_order_locks.total_locked; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_order_locks.total_locked IS 'how many units of the product does this lock reserve';
-
-
---
--- Name: merchant_orders; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_orders (
- order_serial bigint NOT NULL,
- merchant_serial bigint NOT NULL,
- order_id character varying NOT NULL,
- claim_token bytea NOT NULL,
- h_post_data bytea NOT NULL,
- pay_deadline bigint NOT NULL,
- creation_time bigint NOT NULL,
- contract_terms bytea NOT NULL,
- CONSTRAINT merchant_orders_claim_token_check CHECK ((length(claim_token) = 16)),
- CONSTRAINT merchant_orders_h_post_data_check CHECK ((length(h_post_data) = 64))
-);
-
-
---
--- Name: TABLE merchant_orders; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_orders IS 'Orders we offered to a customer, but that have not yet been claimed';
-
-
---
--- Name: COLUMN merchant_orders.merchant_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.merchant_serial IS 'Identifies the instance offering the contract';
-
-
---
--- Name: COLUMN merchant_orders.claim_token; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.claim_token IS 'Token optionally used to authorize the wallet to claim the order. All zeros (not NULL) if not used';
-
-
---
--- Name: COLUMN merchant_orders.h_post_data; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.h_post_data IS 'Hash of the POST request that created this order, for idempotency checks';
-
-
---
--- Name: COLUMN merchant_orders.pay_deadline; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.pay_deadline IS 'How long is the offer valid. After this time, the order can be garbage collected';
-
-
---
--- Name: COLUMN merchant_orders.contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_orders.contract_terms IS 'Claiming changes the contract_terms, hence we have no hash of the terms in this table';
-
-
---
--- Name: merchant_orders_order_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_orders ALTER COLUMN order_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_orders_order_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_refund_proofs; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_refund_proofs (
- refund_serial bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- signkey_serial bigint NOT NULL,
- CONSTRAINT merchant_refund_proofs_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_refund_proofs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_refund_proofs IS 'Refunds confirmed by the exchange (not all approved refunds are grabbed by the wallet)';
-
-
---
--- Name: merchant_refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_refunds (
- refund_serial bigint NOT NULL,
- order_serial bigint NOT NULL,
- rtransaction_id bigint NOT NULL,
- refund_timestamp bigint NOT NULL,
- coin_pub bytea NOT NULL,
- reason character varying NOT NULL,
- refund_amount_val bigint NOT NULL,
- refund_amount_frac integer NOT NULL
-);
-
-
---
--- Name: COLUMN merchant_refunds.rtransaction_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_refunds.rtransaction_id IS 'Needed for uniqueness in case a refund is increased for the same order';
-
-
---
--- Name: COLUMN merchant_refunds.refund_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_refunds.refund_timestamp IS 'Needed for grouping of refunds in the wallet UI; has no semantics in the protocol (only for UX), but should be from the time when the merchant internally approved the refund';
-
-
---
--- Name: merchant_refunds_refund_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_refunds ALTER COLUMN refund_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_refunds_refund_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tip_pickup_signatures; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_pickup_signatures (
- pickup_serial bigint NOT NULL,
- coin_offset integer NOT NULL,
- blind_sig bytea NOT NULL
-);
-
-
---
--- Name: TABLE merchant_tip_pickup_signatures; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_pickup_signatures IS 'blind signatures we got from the exchange during the tip pickup';
-
-
---
--- Name: merchant_tip_pickups; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_pickups (
- pickup_serial bigint NOT NULL,
- tip_serial bigint NOT NULL,
- pickup_id bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT merchant_tip_pickups_pickup_id_check CHECK ((length(pickup_id) = 64))
-);
-
-
---
--- Name: TABLE merchant_tip_pickups; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_pickups IS 'tips that have been picked up';
-
-
---
--- Name: merchant_tip_pickups_pickup_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tip_pickups ALTER COLUMN pickup_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tip_pickups_pickup_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tip_reserve_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_reserve_keys (
- reserve_serial bigint NOT NULL,
- reserve_priv bytea NOT NULL,
- exchange_url character varying NOT NULL,
- payto_uri character varying,
- CONSTRAINT merchant_tip_reserve_keys_reserve_priv_check CHECK ((length(reserve_priv) = 32))
-);
-
-
---
--- Name: COLUMN merchant_tip_reserve_keys.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserve_keys.payto_uri IS 'payto:// URI used to fund the reserve, may be NULL once reserve is funded';
-
-
---
--- Name: merchant_tip_reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tip_reserves (
- reserve_serial bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- merchant_serial bigint NOT NULL,
- creation_time bigint NOT NULL,
- expiration bigint NOT NULL,
- merchant_initial_balance_val bigint NOT NULL,
- merchant_initial_balance_frac integer NOT NULL,
- exchange_initial_balance_val bigint DEFAULT 0 NOT NULL,
- exchange_initial_balance_frac integer DEFAULT 0 NOT NULL,
- tips_committed_val bigint DEFAULT 0 NOT NULL,
- tips_committed_frac integer DEFAULT 0 NOT NULL,
- tips_picked_up_val bigint DEFAULT 0 NOT NULL,
- tips_picked_up_frac integer DEFAULT 0 NOT NULL,
- CONSTRAINT merchant_tip_reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-
-
---
--- Name: TABLE merchant_tip_reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tip_reserves IS 'private keys of reserves that have not been deleted';
-
-
---
--- Name: COLUMN merchant_tip_reserves.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.expiration IS 'FIXME: EXCHANGE API needs to tell us when reserves close if we are to compute this';
-
-
---
--- Name: COLUMN merchant_tip_reserves.merchant_initial_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.merchant_initial_balance_val IS 'Set to the initial balance the merchant told us when creating the reserve';
-
-
---
--- Name: COLUMN merchant_tip_reserves.exchange_initial_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.exchange_initial_balance_val IS 'Set to the initial balance the exchange told us when we queried the reserve status';
-
-
---
--- Name: COLUMN merchant_tip_reserves.tips_committed_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.tips_committed_val IS 'Amount of outstanding approved tips that have not been picked up';
-
-
---
--- Name: COLUMN merchant_tip_reserves.tips_picked_up_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tip_reserves.tips_picked_up_val IS 'Total amount tips that have been picked up from this reserve';
-
-
---
--- Name: merchant_tip_reserves_reserve_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tip_reserves ALTER COLUMN reserve_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tip_reserves_reserve_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_tips; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_tips (
- tip_serial bigint NOT NULL,
- reserve_serial bigint NOT NULL,
- tip_id bytea NOT NULL,
- justification character varying NOT NULL,
- next_url character varying NOT NULL,
- expiration bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- picked_up_val bigint DEFAULT 0 NOT NULL,
- picked_up_frac integer DEFAULT 0 NOT NULL,
- was_picked_up boolean DEFAULT false NOT NULL,
- CONSTRAINT merchant_tips_tip_id_check CHECK ((length(tip_id) = 64))
-);
-
-
---
--- Name: TABLE merchant_tips; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_tips IS 'tips that have been authorized';
-
-
---
--- Name: COLUMN merchant_tips.reserve_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.reserve_serial IS 'Reserve from which this tip is funded';
-
-
---
--- Name: COLUMN merchant_tips.expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.expiration IS 'by when does the client have to pick up the tip';
-
-
---
--- Name: COLUMN merchant_tips.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.amount_val IS 'total transaction cost for all coins including withdraw fees';
-
-
---
--- Name: COLUMN merchant_tips.picked_up_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_tips.picked_up_val IS 'Tip amount left to be picked up';
-
-
---
--- Name: merchant_tips_tip_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_tips ALTER COLUMN tip_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_tips_tip_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: merchant_transfer_signatures; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfer_signatures (
- credit_serial bigint NOT NULL,
- signkey_serial bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- credit_amount_val bigint NOT NULL,
- credit_amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- exchange_sig bytea NOT NULL,
- CONSTRAINT merchant_transfer_signatures_exchange_sig_check CHECK ((length(exchange_sig) = 64))
-);
-
-
---
--- Name: TABLE merchant_transfer_signatures; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfer_signatures IS 'table represents the main information returned from the /transfer request to the exchange.';
-
-
---
--- Name: COLUMN merchant_transfer_signatures.credit_amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_signatures.credit_amount_val IS 'actual value of the (aggregated) wire transfer, excluding the wire fee, according to the exchange';
-
-
---
--- Name: COLUMN merchant_transfer_signatures.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_signatures.execution_time IS 'Execution time as claimed by the exchange, roughly matches time seen by merchant';
-
-
---
--- Name: merchant_transfer_to_coin; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfer_to_coin (
- deposit_serial bigint NOT NULL,
- credit_serial bigint NOT NULL,
- offset_in_exchange_list bigint NOT NULL,
- exchange_deposit_value_val bigint NOT NULL,
- exchange_deposit_value_frac integer NOT NULL,
- exchange_deposit_fee_val bigint NOT NULL,
- exchange_deposit_fee_frac integer NOT NULL
-);
-
-
---
--- Name: TABLE merchant_transfer_to_coin; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfer_to_coin IS 'Mapping of (credit) transfers to (deposited) coins';
-
-
---
--- Name: COLUMN merchant_transfer_to_coin.exchange_deposit_value_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_to_coin.exchange_deposit_value_val IS 'Deposit value as claimed by the exchange, should match our values in merchant_deposits minus refunds';
-
-
---
--- Name: COLUMN merchant_transfer_to_coin.exchange_deposit_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfer_to_coin.exchange_deposit_fee_val IS 'Deposit value as claimed by the exchange, should match our values in merchant_deposits';
-
-
---
--- Name: merchant_transfers; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.merchant_transfers (
- credit_serial bigint NOT NULL,
- exchange_url character varying NOT NULL,
- wtid bytea,
- credit_amount_val bigint NOT NULL,
- credit_amount_frac integer NOT NULL,
- account_serial bigint NOT NULL,
- verified boolean DEFAULT false NOT NULL,
- confirmed boolean DEFAULT false NOT NULL,
- CONSTRAINT merchant_transfers_wtid_check CHECK ((length(wtid) = 32))
-);
-
-
---
--- Name: TABLE merchant_transfers; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.merchant_transfers IS 'table represents the information provided by the (trusted) merchant about incoming wire transfers';
-
-
---
--- Name: COLUMN merchant_transfers.credit_amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.credit_amount_val IS 'actual value of the (aggregated) wire transfer, excluding the wire fee, according to the merchant';
-
-
---
--- Name: COLUMN merchant_transfers.verified; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.verified IS 'true once we got an acceptable response from the exchange for this transfer';
-
-
---
--- Name: COLUMN merchant_transfers.confirmed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.merchant_transfers.confirmed IS 'true once the merchant confirmed that this transfer was received';
-
-
---
--- Name: merchant_transfers_credit_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.merchant_transfers ALTER COLUMN credit_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.merchant_transfers_credit_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: partner_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.partner_accounts (
- payto_uri character varying NOT NULL,
- partner_serial_id bigint,
- partner_master_sig bytea,
- last_seen bigint NOT NULL,
- CONSTRAINT partner_accounts_partner_master_sig_check CHECK ((length(partner_master_sig) = 64))
-);
-
-
---
--- Name: TABLE partner_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.partner_accounts IS 'Table with bank accounts of the partner exchange. Entries never expire as we need to remember the signature for the auditor.';
-
-
---
--- Name: COLUMN partner_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.payto_uri IS 'payto URI (RFC 8905) with the bank account of the partner exchange.';
-
-
---
--- Name: COLUMN partner_accounts.partner_master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.partner_master_sig IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS by the partner master public key';
-
-
---
--- Name: COLUMN partner_accounts.last_seen; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partner_accounts.last_seen IS 'Last time we saw this account as being active at the partner exchange. Used to select the most recent entry, and to detect when we should check again.';
-
-
---
--- Name: partners; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.partners (
- partner_serial_id bigint NOT NULL,
- partner_master_pub bytea NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- next_wad bigint DEFAULT 0 NOT NULL,
- wad_frequency bigint NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- partner_base_url text NOT NULL,
- CONSTRAINT partners_master_sig_check CHECK ((length(master_sig) = 64)),
- CONSTRAINT partners_partner_master_pub_check CHECK ((length(partner_master_pub) = 32))
-);
-
-
---
--- Name: TABLE partners; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.partners IS 'exchanges we do wad transfers to';
-
-
---
--- Name: COLUMN partners.partner_master_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.partner_master_pub IS 'offline master public key of the partner';
-
-
---
--- Name: COLUMN partners.start_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.start_date IS 'starting date of the partnership';
-
-
---
--- Name: COLUMN partners.end_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.end_date IS 'end date of the partnership';
-
-
---
--- Name: COLUMN partners.next_wad; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.next_wad IS 'at what time should we do the next wad transfer to this partner (frequently updated); set to forever after the end_date';
-
-
---
--- Name: COLUMN partners.wad_frequency; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.wad_frequency IS 'how often do we promise to do wad transfers';
-
-
---
--- Name: COLUMN partners.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.wad_fee_val IS 'how high is the fee for a wallet to be added to a wad to this partner';
-
-
---
--- Name: COLUMN partners.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.master_sig IS 'signature of our master public key affirming the partnership, of purpose TALER_SIGNATURE_MASTER_PARTNER_DETAILS';
-
-
---
--- Name: COLUMN partners.partner_base_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.partners.partner_base_url IS 'base URL of the REST API for this partner';
-
-
---
--- Name: partners_partner_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.partners ALTER COLUMN partner_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.partners_partner_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: prewire; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.prewire (
- prewire_uuid bigint NOT NULL,
- wire_method text NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- failed boolean DEFAULT false NOT NULL,
- buf bytea NOT NULL
-)
-PARTITION BY HASH (prewire_uuid);
-
-
---
--- Name: TABLE prewire; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.prewire IS 'pre-commit data for wire transfers we are about to execute';
-
-
---
--- Name: COLUMN prewire.finished; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.finished IS 'set to TRUE once bank confirmed receiving the wire transfer request';
-
-
---
--- Name: COLUMN prewire.failed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.failed IS 'set to TRUE if the bank responded with a non-transient failure to our transfer request';
-
-
---
--- Name: COLUMN prewire.buf; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.prewire.buf IS 'serialized data to send to the bank to execute the wire transfer';
-
-
---
--- Name: prewire_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.prewire_default (
- prewire_uuid bigint NOT NULL,
- wire_method text NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- failed boolean DEFAULT false NOT NULL,
- buf bytea NOT NULL
-);
-ALTER TABLE ONLY public.prewire ATTACH PARTITION public.prewire_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: prewire_prewire_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.prewire ALTER COLUMN prewire_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.prewire_prewire_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_actions; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_actions (
- purse_pub bytea NOT NULL,
- action_date bigint NOT NULL,
- partner_serial_id bigint,
- CONSTRAINT purse_actions_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-
-
---
--- Name: TABLE purse_actions; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_actions IS 'purses awaiting some action by the router';
-
-
---
--- Name: COLUMN purse_actions.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.purse_pub IS 'public (contract) key of the purse';
-
-
---
--- Name: COLUMN purse_actions.action_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.action_date IS 'when is the purse ready for action';
-
-
---
--- Name: COLUMN purse_actions.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_actions.partner_serial_id IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
-
-
---
--- Name: purse_deposits; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_deposits (
- purse_deposit_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- purse_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- coin_sig bytea NOT NULL,
- CONSTRAINT purse_deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT purse_deposits_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_deposits; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_deposits IS 'Requests depositing coins into a purse';
-
-
---
--- Name: COLUMN purse_deposits.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.partner_serial_id IS 'identifies the partner exchange, NULL in case the target purse lives at this exchange';
-
-
---
--- Name: COLUMN purse_deposits.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN purse_deposits.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.coin_pub IS 'Public key of the coin being deposited';
-
-
---
--- Name: COLUMN purse_deposits.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.amount_with_fee_val IS 'Total amount being deposited';
-
-
---
--- Name: COLUMN purse_deposits.coin_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_deposits.coin_sig IS 'Signature of the coin affirming the deposit into the purse, of type TALER_SIGNATURE_PURSE_DEPOSIT';
-
-
---
--- Name: purse_deposits_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_deposits_default (
- purse_deposit_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- purse_pub bytea NOT NULL,
- coin_pub bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- coin_sig bytea NOT NULL,
- CONSTRAINT purse_deposits_coin_sig_check CHECK ((length(coin_sig) = 64)),
- CONSTRAINT purse_deposits_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_deposits ATTACH PARTITION public.purse_deposits_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_deposits_purse_deposit_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_deposits ALTER COLUMN purse_deposit_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_deposits_purse_deposit_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_merges; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_merges (
- purse_merge_request_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- merge_sig bytea NOT NULL,
- merge_timestamp bigint NOT NULL,
- CONSTRAINT purse_merges_merge_sig_check CHECK ((length(merge_sig) = 64)),
- CONSTRAINT purse_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_merges; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_merges IS 'Merge requests where a purse-owner requested merging the purse into the account';
-
-
---
--- Name: COLUMN purse_merges.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.partner_serial_id IS 'identifies the partner exchange, NULL in case the target reserve lives at this exchange';
-
-
---
--- Name: COLUMN purse_merges.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.reserve_pub IS 'public key of the target reserve';
-
-
---
--- Name: COLUMN purse_merges.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.purse_pub IS 'public key of the purse';
-
-
---
--- Name: COLUMN purse_merges.merge_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.merge_sig IS 'signature by the purse private key affirming the merge, of type TALER_SIGNATURE_WALLET_PURSE_MERGE';
-
-
---
--- Name: COLUMN purse_merges.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_merges.merge_timestamp IS 'when was the merge message signed';
-
-
---
--- Name: purse_merges_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_merges_default (
- purse_merge_request_serial_id bigint NOT NULL,
- partner_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- merge_sig bytea NOT NULL,
- merge_timestamp bigint NOT NULL,
- CONSTRAINT purse_merges_merge_sig_check CHECK ((length(merge_sig) = 64)),
- CONSTRAINT purse_merges_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_merges_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_merges ATTACH PARTITION public.purse_merges_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_merges_purse_merge_request_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_merges ALTER COLUMN purse_merge_request_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_merges_purse_merge_request_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_refunds (
- purse_refunds_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT purse_refunds_purse_pub_check CHECK ((length(purse_pub) = 32))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_refunds; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_refunds IS 'Purses that were refunded due to expiration';
-
-
---
--- Name: COLUMN purse_refunds.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_refunds.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: purse_refunds_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_refunds_default (
- purse_refunds_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- CONSTRAINT purse_refunds_purse_pub_check CHECK ((length(purse_pub) = 32))
-);
-ALTER TABLE ONLY public.purse_refunds ATTACH PARTITION public.purse_refunds_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_refunds_purse_refunds_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_refunds ALTER COLUMN purse_refunds_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_refunds_purse_refunds_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: purse_requests; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_requests (
- purse_requests_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- merge_pub bytea NOT NULL,
- purse_creation bigint NOT NULL,
- purse_expiration bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- age_limit integer NOT NULL,
- flags integer NOT NULL,
- refunded boolean DEFAULT false NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- in_reserve_quota boolean DEFAULT false NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- balance_val bigint DEFAULT 0 NOT NULL,
- balance_frac integer DEFAULT 0 NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT purse_requests_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT purse_requests_merge_pub_check CHECK ((length(merge_pub) = 32)),
- CONSTRAINT purse_requests_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_requests_purse_sig_check CHECK ((length(purse_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.purse_requests IS 'Requests establishing purses, associating them with a contract but without a target reserve';
-
-
---
--- Name: COLUMN purse_requests.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_creation; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_creation IS 'Local time when the purse was created. Determines applicable purse fees.';
-
-
---
--- Name: COLUMN purse_requests.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_expiration IS 'When the purse is set to expire';
-
-
---
--- Name: COLUMN purse_requests.h_contract_terms; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.h_contract_terms IS 'Hash of the contract the parties are to agree to';
-
-
---
--- Name: COLUMN purse_requests.flags; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.flags IS 'see the enum TALER_WalletAccountMergeFlags';
-
-
---
--- Name: COLUMN purse_requests.refunded; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.refunded IS 'set to TRUE if the purse could not be merged and thus all deposited coins were refunded';
-
-
---
--- Name: COLUMN purse_requests.finished; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.finished IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
-
-
---
--- Name: COLUMN purse_requests.in_reserve_quota; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.in_reserve_quota IS 'set to TRUE if this purse currently counts against the number of free purses in the respective reserve';
-
-
---
--- Name: COLUMN purse_requests.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.amount_with_fee_val IS 'Total amount expected to be in the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_fee_val IS 'Purse fee the client agreed to pay from the reserve (accepted by the exchange at the time the purse was created). Zero if in_reserve_quota is TRUE.';
-
-
---
--- Name: COLUMN purse_requests.balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.balance_val IS 'Total amount actually in the purse';
-
-
---
--- Name: COLUMN purse_requests.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.purse_requests.purse_sig IS 'Signature of the purse affirming the purse parameters, of type TALER_SIGNATURE_PURSE_REQUEST';
-
-
---
--- Name: purse_requests_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.purse_requests_default (
- purse_requests_serial_id bigint NOT NULL,
- purse_pub bytea NOT NULL,
- merge_pub bytea NOT NULL,
- purse_creation bigint NOT NULL,
- purse_expiration bigint NOT NULL,
- h_contract_terms bytea NOT NULL,
- age_limit integer NOT NULL,
- flags integer NOT NULL,
- refunded boolean DEFAULT false NOT NULL,
- finished boolean DEFAULT false NOT NULL,
- in_reserve_quota boolean DEFAULT false NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- purse_fee_val bigint NOT NULL,
- purse_fee_frac integer NOT NULL,
- balance_val bigint DEFAULT 0 NOT NULL,
- balance_frac integer DEFAULT 0 NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT purse_requests_h_contract_terms_check CHECK ((length(h_contract_terms) = 64)),
- CONSTRAINT purse_requests_merge_pub_check CHECK ((length(merge_pub) = 32)),
- CONSTRAINT purse_requests_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT purse_requests_purse_sig_check CHECK ((length(purse_sig) = 64))
-);
-ALTER TABLE ONLY public.purse_requests ATTACH PARTITION public.purse_requests_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: purse_requests_purse_requests_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.purse_requests ALTER COLUMN purse_requests_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.purse_requests_purse_requests_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: recoup; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup (
- recoup_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- reserve_out_serial_id bigint NOT NULL,
- CONSTRAINT recoup_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_coin_sig_check CHECK ((length(coin_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE recoup; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup IS 'Information about recoups that were executed between a coin and a reserve. In this type of recoup, the amount is credited back to the reserve from which the coin originated.';
-
-
---
--- Name: COLUMN recoup.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_pub IS 'Coin that is being debited in the recoup. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-
-
---
--- Name: COLUMN recoup.coin_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_sig IS 'Signature by the coin affirming the recoup, of type TALER_SIGNATURE_WALLET_COIN_RECOUP';
-
-
---
--- Name: COLUMN recoup.coin_blind; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.coin_blind IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the withdraw operation.';
-
-
---
--- Name: COLUMN recoup.reserve_out_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup.reserve_out_serial_id IS 'Identifies the h_blind_ev of the recouped coin and provides the link to the credited reserve.';
-
-
---
--- Name: recoup_by_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_by_reserve (
- reserve_out_serial_id bigint NOT NULL,
- coin_pub bytea,
- CONSTRAINT recoup_by_reserve_coin_pub_check CHECK ((length(coin_pub) = 32))
-)
-PARTITION BY HASH (reserve_out_serial_id);
-
-
---
--- Name: TABLE recoup_by_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup_by_reserve IS 'Information in this table is strictly redundant with that of recoup, but saved by a different primary key for fast lookups by reserve_out_serial_id.';
-
-
---
--- Name: recoup_by_reserve_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_by_reserve_default (
- reserve_out_serial_id bigint NOT NULL,
- coin_pub bytea,
- CONSTRAINT recoup_by_reserve_coin_pub_check CHECK ((length(coin_pub) = 32))
-);
-ALTER TABLE ONLY public.recoup_by_reserve ATTACH PARTITION public.recoup_by_reserve_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_default (
- recoup_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- reserve_out_serial_id bigint NOT NULL,
- CONSTRAINT recoup_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_coin_sig_check CHECK ((length(coin_sig) = 64))
-);
-ALTER TABLE ONLY public.recoup ATTACH PARTITION public.recoup_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_recoup_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.recoup ALTER COLUMN recoup_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.recoup_recoup_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: recoup_refresh; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_refresh (
- recoup_refresh_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- rrc_serial bigint NOT NULL,
- CONSTRAINT recoup_refresh_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_refresh_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_refresh_coin_sig_check CHECK ((length(coin_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE recoup_refresh; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.recoup_refresh IS 'Table of coins that originated from a refresh operation and that were recouped. Links the (fresh) coin to the melted operation (and thus the old coin). A recoup on a refreshed coin credits the old coin and debits the fresh coin.';
-
-
---
--- Name: COLUMN recoup_refresh.coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.coin_pub IS 'Refreshed coin of a revoked denomination where the residual value is credited to the old coin. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-
-
---
--- Name: COLUMN recoup_refresh.known_coin_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.known_coin_id IS 'FIXME: (To be) used for garbage collection (in the future)';
-
-
---
--- Name: COLUMN recoup_refresh.coin_blind; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.coin_blind IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the refresh operation.';
-
-
---
--- Name: COLUMN recoup_refresh.rrc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.recoup_refresh.rrc_serial IS 'Link to the refresh operation. Also identifies the h_blind_ev of the recouped coin (as h_coin_ev).';
-
-
---
--- Name: recoup_refresh_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.recoup_refresh_default (
- recoup_refresh_uuid bigint NOT NULL,
- coin_pub bytea NOT NULL,
- known_coin_id bigint NOT NULL,
- coin_sig bytea NOT NULL,
- coin_blind bytea NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- recoup_timestamp bigint NOT NULL,
- rrc_serial bigint NOT NULL,
- CONSTRAINT recoup_refresh_coin_blind_check CHECK ((length(coin_blind) = 32)),
- CONSTRAINT recoup_refresh_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT recoup_refresh_coin_sig_check CHECK ((length(coin_sig) = 64))
-);
-ALTER TABLE ONLY public.recoup_refresh ATTACH PARTITION public.recoup_refresh_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: recoup_refresh_recoup_refresh_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.recoup_refresh ALTER COLUMN recoup_refresh_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.recoup_refresh_recoup_refresh_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_commitments; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_commitments (
- melt_serial_id bigint NOT NULL,
- rc bytea NOT NULL,
- old_coin_pub bytea NOT NULL,
- old_coin_sig bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- noreveal_index integer NOT NULL,
- CONSTRAINT refresh_commitments_old_coin_sig_check CHECK ((length(old_coin_sig) = 64)),
- CONSTRAINT refresh_commitments_rc_check CHECK ((length(rc) = 64))
-)
-PARTITION BY HASH (rc);
-
-
---
--- Name: TABLE refresh_commitments; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_commitments IS 'Commitments made when melting coins and the gamma value chosen by the exchange.';
-
-
---
--- Name: COLUMN refresh_commitments.rc; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.rc IS 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol';
-
-
---
--- Name: COLUMN refresh_commitments.old_coin_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.old_coin_pub IS 'Coin being melted in the refresh process.';
-
-
---
--- Name: COLUMN refresh_commitments.noreveal_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_commitments.noreveal_index IS 'The gamma value chosen by the exchange in the cut-and-choose protocol';
-
-
---
--- Name: refresh_commitments_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_commitments_default (
- melt_serial_id bigint NOT NULL,
- rc bytea NOT NULL,
- old_coin_pub bytea NOT NULL,
- old_coin_sig bytea NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- noreveal_index integer NOT NULL,
- CONSTRAINT refresh_commitments_old_coin_sig_check CHECK ((length(old_coin_sig) = 64)),
- CONSTRAINT refresh_commitments_rc_check CHECK ((length(rc) = 64))
-);
-ALTER TABLE ONLY public.refresh_commitments ATTACH PARTITION public.refresh_commitments_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_commitments_melt_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_commitments ALTER COLUMN melt_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_commitments_melt_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_revealed_coins; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_revealed_coins (
- rrc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- freshcoin_index integer NOT NULL,
- link_sig bytea NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_ev bytea NOT NULL,
- h_coin_ev bytea NOT NULL,
- ev_sig bytea NOT NULL,
- ewv bytea NOT NULL,
- CONSTRAINT refresh_revealed_coins_h_coin_ev_check CHECK ((length(h_coin_ev) = 64)),
- CONSTRAINT refresh_revealed_coins_link_sig_check CHECK ((length(link_sig) = 64))
-)
-PARTITION BY HASH (melt_serial_id);
-
-
---
--- Name: TABLE refresh_revealed_coins; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_revealed_coins IS 'Revelations about the new coins that are to be created during a melting session.';
-
-
---
--- Name: COLUMN refresh_revealed_coins.rrc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.rrc_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN refresh_revealed_coins.melt_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.melt_serial_id IS 'Identifies the refresh commitment (rc) of the melt operation.';
-
-
---
--- Name: COLUMN refresh_revealed_coins.freshcoin_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.freshcoin_index IS 'index of the fresh coin being created (one melt operation may result in multiple fresh coins)';
-
-
---
--- Name: COLUMN refresh_revealed_coins.coin_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.coin_ev IS 'envelope of the new coin to be signed';
-
-
---
--- Name: COLUMN refresh_revealed_coins.h_coin_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.h_coin_ev IS 'hash of the envelope of the new coin to be signed (for lookups)';
-
-
---
--- Name: COLUMN refresh_revealed_coins.ev_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.ev_sig IS 'exchange signature over the envelope';
-
-
---
--- Name: COLUMN refresh_revealed_coins.ewv; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_revealed_coins.ewv IS 'exchange contributed values in the creation of the fresh coin (see /csr)';
-
-
---
--- Name: refresh_revealed_coins_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_revealed_coins_default (
- rrc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- freshcoin_index integer NOT NULL,
- link_sig bytea NOT NULL,
- denominations_serial bigint NOT NULL,
- coin_ev bytea NOT NULL,
- h_coin_ev bytea NOT NULL,
- ev_sig bytea NOT NULL,
- ewv bytea NOT NULL,
- CONSTRAINT refresh_revealed_coins_h_coin_ev_check CHECK ((length(h_coin_ev) = 64)),
- CONSTRAINT refresh_revealed_coins_link_sig_check CHECK ((length(link_sig) = 64))
-);
-ALTER TABLE ONLY public.refresh_revealed_coins ATTACH PARTITION public.refresh_revealed_coins_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_revealed_coins_rrc_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_revealed_coins ALTER COLUMN rrc_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_revealed_coins_rrc_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refresh_transfer_keys; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_transfer_keys (
- rtc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- transfer_pub bytea NOT NULL,
- transfer_privs bytea NOT NULL,
- CONSTRAINT refresh_transfer_keys_transfer_pub_check CHECK ((length(transfer_pub) = 32))
-)
-PARTITION BY HASH (melt_serial_id);
-
-
---
--- Name: TABLE refresh_transfer_keys; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refresh_transfer_keys IS 'Transfer keys of a refresh operation (the data revealed to the exchange).';
-
-
---
--- Name: COLUMN refresh_transfer_keys.rtc_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.rtc_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: COLUMN refresh_transfer_keys.melt_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.melt_serial_id IS 'Identifies the refresh commitment (rc) of the operation.';
-
-
---
--- Name: COLUMN refresh_transfer_keys.transfer_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.transfer_pub IS 'transfer public key for the gamma index';
-
-
---
--- Name: COLUMN refresh_transfer_keys.transfer_privs; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refresh_transfer_keys.transfer_privs IS 'array of TALER_CNC_KAPPA - 1 transfer private keys that have been revealed, with the gamma entry being skipped';
-
-
---
--- Name: refresh_transfer_keys_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refresh_transfer_keys_default (
- rtc_serial bigint NOT NULL,
- melt_serial_id bigint NOT NULL,
- transfer_pub bytea NOT NULL,
- transfer_privs bytea NOT NULL,
- CONSTRAINT refresh_transfer_keys_transfer_pub_check CHECK ((length(transfer_pub) = 32))
-);
-ALTER TABLE ONLY public.refresh_transfer_keys ATTACH PARTITION public.refresh_transfer_keys_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refresh_transfer_keys_rtc_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refresh_transfer_keys ALTER COLUMN rtc_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refresh_transfer_keys_rtc_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: refunds; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refunds (
- refund_serial_id bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint NOT NULL,
- merchant_sig bytea NOT NULL,
- rtransaction_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT refunds_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT refunds_merchant_sig_check CHECK ((length(merchant_sig) = 64))
-)
-PARTITION BY HASH (coin_pub);
-
-
---
--- Name: TABLE refunds; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.refunds IS 'Data on coins that were refunded. Technically, refunds always apply against specific deposit operations involving a coin. The combination of coin_pub, merchant_pub, h_contract_terms and rtransaction_id MUST be unique, and we usually select by coin_pub so that one goes first.';
-
-
---
--- Name: COLUMN refunds.deposit_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refunds.deposit_serial_id IS 'Identifies ONLY the merchant_pub, h_contract_terms and coin_pub. Multiple deposits may match a refund, this only identifies one of them.';
-
-
---
--- Name: COLUMN refunds.rtransaction_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.refunds.rtransaction_id IS 'used by the merchant to make refunds unique in case the same coin for the same deposit gets a subsequent (higher) refund';
-
-
---
--- Name: refunds_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.refunds_default (
- refund_serial_id bigint NOT NULL,
- coin_pub bytea NOT NULL,
- deposit_serial_id bigint NOT NULL,
- merchant_sig bytea NOT NULL,
- rtransaction_id bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT refunds_coin_pub_check CHECK ((length(coin_pub) = 32)),
- CONSTRAINT refunds_merchant_sig_check CHECK ((length(merchant_sig) = 64))
-);
-ALTER TABLE ONLY public.refunds ATTACH PARTITION public.refunds_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: refunds_refund_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.refunds ALTER COLUMN refund_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.refunds_refund_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves (
- reserve_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- current_balance_val bigint DEFAULT 0 NOT NULL,
- current_balance_frac integer DEFAULT 0 NOT NULL,
- purses_active bigint DEFAULT 0 NOT NULL,
- purses_allowed bigint DEFAULT 0 NOT NULL,
- kyc_required boolean DEFAULT false NOT NULL,
- kyc_passed boolean DEFAULT false NOT NULL,
- max_age integer DEFAULT 120 NOT NULL,
- expiration_date bigint NOT NULL,
- gc_date bigint NOT NULL,
- CONSTRAINT reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves IS 'Summarizes the balance of a reserve. Updated when new funds are added or withdrawn.';
-
-
---
--- Name: COLUMN reserves.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.reserve_pub IS 'EdDSA public key of the reserve. Knowledge of the private key implies ownership over the balance.';
-
-
---
--- Name: COLUMN reserves.current_balance_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.current_balance_val IS 'Current balance remaining with the reserve.';
-
-
---
--- Name: COLUMN reserves.purses_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.purses_active IS 'Number of purses that were created by this reserve that are not expired and not fully paid.';
-
-
---
--- Name: COLUMN reserves.purses_allowed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.purses_allowed IS 'Number of purses that this reserve is allowed to have active at most.';
-
-
---
--- Name: COLUMN reserves.kyc_required; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.kyc_required IS 'True if a KYC check must have been passed before withdrawing from this reserve. Set to true once a reserve received a P2P payment.';
-
-
---
--- Name: COLUMN reserves.kyc_passed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.kyc_passed IS 'True once KYC was passed for this reserve. The KYC details are then available via the wire_targets table under the key of wire_target_h_payto which is to be derived from the reserve_pub and the base URL of this exchange.';
-
-
---
--- Name: COLUMN reserves.expiration_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.expiration_date IS 'Used to trigger closing of reserves that have not been drained after some time';
-
-
---
--- Name: COLUMN reserves.gc_date; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves.gc_date IS 'Used to forget all information about a reserve during garbage collection';
-
-
---
--- Name: reserves_close; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_close (
- close_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- execution_date bigint NOT NULL,
- wtid bytea NOT NULL,
- wire_target_h_payto bytea,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- CONSTRAINT reserves_close_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT reserves_close_wtid_check CHECK ((length(wtid) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves_close; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_close IS 'wire transfers executed by the reserve to close reserves';
-
-
---
--- Name: COLUMN reserves_close.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_close.wire_target_h_payto IS 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.';
-
-
---
--- Name: reserves_close_close_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_close ALTER COLUMN close_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_close_close_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_close_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_close_default (
- close_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- execution_date bigint NOT NULL,
- wtid bytea NOT NULL,
- wire_target_h_payto bytea,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- CONSTRAINT reserves_close_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT reserves_close_wtid_check CHECK ((length(wtid) = 32))
-);
-ALTER TABLE ONLY public.reserves_close ATTACH PARTITION public.reserves_close_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_default (
- reserve_uuid bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- current_balance_val bigint DEFAULT 0 NOT NULL,
- current_balance_frac integer DEFAULT 0 NOT NULL,
- purses_active bigint DEFAULT 0 NOT NULL,
- purses_allowed bigint DEFAULT 0 NOT NULL,
- kyc_required boolean DEFAULT false NOT NULL,
- kyc_passed boolean DEFAULT false NOT NULL,
- max_age integer DEFAULT 120 NOT NULL,
- expiration_date bigint NOT NULL,
- gc_date bigint NOT NULL,
- CONSTRAINT reserves_reserve_pub_check CHECK ((length(reserve_pub) = 32))
-);
-ALTER TABLE ONLY public.reserves ATTACH PARTITION public.reserves_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_in; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_in (
- reserve_in_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- wire_reference bigint NOT NULL,
- credit_val bigint NOT NULL,
- credit_frac integer NOT NULL,
- wire_source_h_payto bytea,
- exchange_account_section text NOT NULL,
- execution_date bigint NOT NULL,
- CONSTRAINT reserves_in_wire_source_h_payto_check CHECK ((length(wire_source_h_payto) = 32))
-)
-PARTITION BY HASH (reserve_pub);
-
-
---
--- Name: TABLE reserves_in; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_in IS 'list of transfers of funds into the reserves, one per incoming wire transfer';
-
-
---
--- Name: COLUMN reserves_in.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.reserve_pub IS 'Public key of the reserve. Private key signifies ownership of the remaining balance.';
-
-
---
--- Name: COLUMN reserves_in.credit_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.credit_val IS 'Amount that was transferred into the reserve';
-
-
---
--- Name: COLUMN reserves_in.wire_source_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_in.wire_source_h_payto IS 'Identifies the debited bank account and KYC status';
-
-
---
--- Name: reserves_in_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_in_default (
- reserve_in_serial_id bigint NOT NULL,
- reserve_pub bytea NOT NULL,
- wire_reference bigint NOT NULL,
- credit_val bigint NOT NULL,
- credit_frac integer NOT NULL,
- wire_source_h_payto bytea,
- exchange_account_section text NOT NULL,
- execution_date bigint NOT NULL,
- CONSTRAINT reserves_in_wire_source_h_payto_check CHECK ((length(wire_source_h_payto) = 32))
-);
-ALTER TABLE ONLY public.reserves_in ATTACH PARTITION public.reserves_in_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_in_reserve_in_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_in ALTER COLUMN reserve_in_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_in_reserve_in_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out (
- reserve_out_serial_id bigint NOT NULL,
- h_blind_ev bytea,
- denominations_serial bigint NOT NULL,
- denom_sig bytea NOT NULL,
- reserve_uuid bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- execution_date bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT reserves_out_h_blind_ev_check CHECK ((length(h_blind_ev) = 64)),
- CONSTRAINT reserves_out_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (h_blind_ev);
-
-
---
--- Name: TABLE reserves_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_out IS 'Withdraw operations performed on reserves.';
-
-
---
--- Name: COLUMN reserves_out.h_blind_ev; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_out.h_blind_ev IS 'Hash of the blinded coin, used as primary key here so that broken clients that use a non-random coin or blinding factor fail to withdraw (otherwise they would fail on deposit when the coin is not unique there).';
-
-
---
--- Name: COLUMN reserves_out.denominations_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.reserves_out.denominations_serial IS 'We do not CASCADE ON DELETE here, we may keep the denomination data alive';
-
-
---
--- Name: reserves_out_by_reserve; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_by_reserve (
- reserve_uuid bigint NOT NULL,
- h_blind_ev bytea,
- CONSTRAINT reserves_out_by_reserve_h_blind_ev_check CHECK ((length(h_blind_ev) = 64))
-)
-PARTITION BY HASH (reserve_uuid);
-
-
---
--- Name: TABLE reserves_out_by_reserve; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.reserves_out_by_reserve IS 'Information in this table is strictly redundant with that of reserves_out, but saved by a different primary key for fast lookups by reserve public key/uuid.';
-
-
---
--- Name: reserves_out_by_reserve_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_by_reserve_default (
- reserve_uuid bigint NOT NULL,
- h_blind_ev bytea,
- CONSTRAINT reserves_out_by_reserve_h_blind_ev_check CHECK ((length(h_blind_ev) = 64))
-);
-ALTER TABLE ONLY public.reserves_out_by_reserve ATTACH PARTITION public.reserves_out_by_reserve_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.reserves_out_default (
- reserve_out_serial_id bigint NOT NULL,
- h_blind_ev bytea,
- denominations_serial bigint NOT NULL,
- denom_sig bytea NOT NULL,
- reserve_uuid bigint NOT NULL,
- reserve_sig bytea NOT NULL,
- execution_date bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- CONSTRAINT reserves_out_h_blind_ev_check CHECK ((length(h_blind_ev) = 64)),
- CONSTRAINT reserves_out_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.reserves_out ATTACH PARTITION public.reserves_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: reserves_out_reserve_out_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves_out ALTER COLUMN reserve_out_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_out_reserve_out_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: reserves_reserve_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.reserves ALTER COLUMN reserve_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.reserves_reserve_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: revolving_work_shards; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE UNLOGGED TABLE public.revolving_work_shards (
- shard_serial_id bigint NOT NULL,
- last_attempt bigint NOT NULL,
- start_row integer NOT NULL,
- end_row integer NOT NULL,
- active boolean DEFAULT false NOT NULL,
- job_name character varying NOT NULL
-);
-
-
---
--- Name: TABLE revolving_work_shards; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.revolving_work_shards IS 'coordinates work between multiple processes working on the same job with partitions that need to be repeatedly processed; unlogged because on system crashes the locks represented by this table will have to be cleared anyway, typically using "taler-exchange-dbinit -s"';
-
-
---
--- Name: COLUMN revolving_work_shards.shard_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.shard_serial_id IS 'unique serial number identifying the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.last_attempt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.last_attempt IS 'last time a worker attempted to work on the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.start_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.start_row IS 'row at which the shard scope starts, inclusive';
-
-
---
--- Name: COLUMN revolving_work_shards.end_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.end_row IS 'row at which the shard scope ends, exclusive';
-
-
---
--- Name: COLUMN revolving_work_shards.active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.active IS 'set to TRUE when a worker is active on the shard';
-
-
---
--- Name: COLUMN revolving_work_shards.job_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.revolving_work_shards.job_name IS 'unique name of the job the workers on this shard are performing';
-
-
---
--- Name: revolving_work_shards_shard_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.revolving_work_shards ALTER COLUMN shard_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.revolving_work_shards_shard_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: signkey_revocations; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.signkey_revocations (
- signkey_revocations_serial_id bigint NOT NULL,
- esk_serial bigint NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT signkey_revocations_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE signkey_revocations; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.signkey_revocations IS 'Table storing which online signing keys have been revoked';
-
-
---
--- Name: signkey_revocations_signkey_revocations_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.signkey_revocations ALTER COLUMN signkey_revocations_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.signkey_revocations_signkey_revocations_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wad_in_entries; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_in_entries (
- wad_in_entry_serial_id bigint NOT NULL,
- wad_in_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_in_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_in_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_in_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_in_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_in_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE wad_in_entries; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wad_in_entries IS 'list of purses aggregated in a wad according to the sending exchange';
-
-
---
--- Name: COLUMN wad_in_entries.wad_in_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.wad_in_serial_id IS 'wad for which the given purse was included in the aggregation';
-
-
---
--- Name: COLUMN wad_in_entries.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.reserve_pub IS 'target account of the purse (must be at the local exchange)';
-
-
---
--- Name: COLUMN wad_in_entries.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_pub IS 'public key of the purse that was merged';
-
-
---
--- Name: COLUMN wad_in_entries.h_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.h_contract IS 'hash of the contract terms of the purse';
-
-
---
--- Name: COLUMN wad_in_entries.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_expiration IS 'Time when the purse was set to expire';
-
-
---
--- Name: COLUMN wad_in_entries.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.merge_timestamp IS 'Time when the merge was approved';
-
-
---
--- Name: COLUMN wad_in_entries.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.amount_with_fee_val IS 'Total amount in the purse';
-
-
---
--- Name: COLUMN wad_in_entries.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.wad_fee_val IS 'Total wad fees paid by the purse';
-
-
---
--- Name: COLUMN wad_in_entries.deposit_fees_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.deposit_fees_val IS 'Total deposit fees paid when depositing coins into the purse';
-
-
---
--- Name: COLUMN wad_in_entries.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.reserve_sig IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN wad_in_entries.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_in_entries.purse_sig IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-
---
--- Name: wad_in_entries_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_in_entries_default (
- wad_in_entry_serial_id bigint NOT NULL,
- wad_in_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_in_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_in_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_in_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_in_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_in_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.wad_in_entries ATTACH PARTITION public.wad_in_entries_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wad_in_entries_wad_in_entry_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wad_in_entries ALTER COLUMN wad_in_entry_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wad_in_entries_wad_in_entry_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wad_out_entries; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_out_entries (
- wad_out_entry_serial_id bigint NOT NULL,
- wad_out_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_out_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_out_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_out_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_out_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_out_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-)
-PARTITION BY HASH (purse_pub);
-
-
---
--- Name: TABLE wad_out_entries; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wad_out_entries IS 'Purses combined into a wad';
-
-
---
--- Name: COLUMN wad_out_entries.wad_out_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.wad_out_serial_id IS 'Wad the purse was part of';
-
-
---
--- Name: COLUMN wad_out_entries.reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.reserve_pub IS 'Target reserve for the purse';
-
-
---
--- Name: COLUMN wad_out_entries.purse_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_pub IS 'Public key of the purse';
-
-
---
--- Name: COLUMN wad_out_entries.h_contract; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.h_contract IS 'Hash of the contract associated with the purse';
-
-
---
--- Name: COLUMN wad_out_entries.purse_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_expiration IS 'Time when the purse expires';
-
-
---
--- Name: COLUMN wad_out_entries.merge_timestamp; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.merge_timestamp IS 'Time when the merge was approved';
-
-
---
--- Name: COLUMN wad_out_entries.amount_with_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.amount_with_fee_val IS 'Total amount in the purse';
-
-
---
--- Name: COLUMN wad_out_entries.wad_fee_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.wad_fee_val IS 'Wat fee charged to the purse';
-
-
---
--- Name: COLUMN wad_out_entries.deposit_fees_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.deposit_fees_val IS 'Total deposit fees charged to the purse';
-
-
---
--- Name: COLUMN wad_out_entries.reserve_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.reserve_sig IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-
-
---
--- Name: COLUMN wad_out_entries.purse_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wad_out_entries.purse_sig IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-
---
--- Name: wad_out_entries_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wad_out_entries_default (
- wad_out_entry_serial_id bigint NOT NULL,
- wad_out_serial_id bigint,
- reserve_pub bytea NOT NULL,
- purse_pub bytea NOT NULL,
- h_contract bytea NOT NULL,
- purse_expiration bigint NOT NULL,
- merge_timestamp bigint NOT NULL,
- amount_with_fee_val bigint NOT NULL,
- amount_with_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- deposit_fees_val bigint NOT NULL,
- deposit_fees_frac integer NOT NULL,
- reserve_sig bytea NOT NULL,
- purse_sig bytea NOT NULL,
- CONSTRAINT wad_out_entries_h_contract_check CHECK ((length(h_contract) = 64)),
- CONSTRAINT wad_out_entries_purse_pub_check CHECK ((length(purse_pub) = 32)),
- CONSTRAINT wad_out_entries_purse_sig_check CHECK ((length(purse_sig) = 64)),
- CONSTRAINT wad_out_entries_reserve_pub_check CHECK ((length(reserve_pub) = 32)),
- CONSTRAINT wad_out_entries_reserve_sig_check CHECK ((length(reserve_sig) = 64))
-);
-ALTER TABLE ONLY public.wad_out_entries ATTACH PARTITION public.wad_out_entries_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wad_out_entries_wad_out_entry_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wad_out_entries ALTER COLUMN wad_out_entry_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wad_out_entries_wad_out_entry_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wads_in; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_in (
- wad_in_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- origin_exchange_url text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- arrival_time bigint NOT NULL,
- CONSTRAINT wads_in_wad_id_check CHECK ((length(wad_id) = 24))
-)
-PARTITION BY HASH (wad_id);
-
-
---
--- Name: TABLE wads_in; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wads_in IS 'Incoming exchange-to-exchange wad wire transfers';
-
-
---
--- Name: COLUMN wads_in.wad_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.wad_id IS 'Unique identifier of the wad, part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_in.origin_exchange_url; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.origin_exchange_url IS 'Base URL of the originating URL, also part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_in.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.amount_val IS 'Actual amount that was received by our exchange';
-
-
---
--- Name: COLUMN wads_in.arrival_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_in.arrival_time IS 'Time when the wad was received';
-
-
---
--- Name: wads_in_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_in_default (
- wad_in_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- origin_exchange_url text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- arrival_time bigint NOT NULL,
- CONSTRAINT wads_in_wad_id_check CHECK ((length(wad_id) = 24))
-);
-ALTER TABLE ONLY public.wads_in ATTACH PARTITION public.wads_in_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wads_in_wad_in_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wads_in ALTER COLUMN wad_in_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wads_in_wad_in_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wads_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_out (
- wad_out_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- partner_serial_id bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- CONSTRAINT wads_out_wad_id_check CHECK ((length(wad_id) = 24))
-)
-PARTITION BY HASH (wad_id);
-
-
---
--- Name: TABLE wads_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wads_out IS 'Wire transfers made to another exchange to transfer purse funds';
-
-
---
--- Name: COLUMN wads_out.wad_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.wad_id IS 'Unique identifier of the wad, part of the wire transfer subject';
-
-
---
--- Name: COLUMN wads_out.partner_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.partner_serial_id IS 'target exchange of the wad';
-
-
---
--- Name: COLUMN wads_out.amount_val; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.amount_val IS 'Amount that was wired';
-
-
---
--- Name: COLUMN wads_out.execution_time; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wads_out.execution_time IS 'Time when the wire transfer was scheduled';
-
-
---
--- Name: wads_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wads_out_default (
- wad_out_serial_id bigint NOT NULL,
- wad_id bytea NOT NULL,
- partner_serial_id bigint NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- execution_time bigint NOT NULL,
- CONSTRAINT wads_out_wad_id_check CHECK ((length(wad_id) = 24))
-);
-ALTER TABLE ONLY public.wads_out ATTACH PARTITION public.wads_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wads_out_wad_out_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wads_out ALTER COLUMN wad_out_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wads_out_wad_out_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_accounts; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_accounts (
- payto_uri character varying NOT NULL,
- master_sig bytea,
- is_active boolean NOT NULL,
- last_change bigint NOT NULL,
- CONSTRAINT wire_accounts_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE wire_accounts; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_accounts IS 'Table with current and historic bank accounts of the exchange. Entries never expire as we need to remember the last_change column indefinitely.';
-
-
---
--- Name: COLUMN wire_accounts.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.payto_uri IS 'payto URI (RFC 8905) with the bank account of the exchange.';
-
-
---
--- Name: COLUMN wire_accounts.master_sig; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.master_sig IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS';
-
-
---
--- Name: COLUMN wire_accounts.is_active; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.is_active IS 'true if we are currently supporting the use of this account.';
-
-
---
--- Name: COLUMN wire_accounts.last_change; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_accounts.last_change IS 'Latest time when active status changed. Used to detect replays of old messages.';
-
-
---
--- Name: wire_auditor_account_progress; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_auditor_account_progress (
- master_pub bytea NOT NULL,
- account_name text NOT NULL,
- last_wire_reserve_in_serial_id bigint DEFAULT 0 NOT NULL,
- last_wire_wire_out_serial_id bigint DEFAULT 0 NOT NULL,
- wire_in_off bigint NOT NULL,
- wire_out_off bigint NOT NULL
-);
-
-
---
--- Name: TABLE wire_auditor_account_progress; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_auditor_account_progress IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
---
--- Name: wire_auditor_progress; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_auditor_progress (
- master_pub bytea NOT NULL,
- last_timestamp bigint NOT NULL,
- last_reserve_close_uuid bigint NOT NULL
-);
-
-
---
--- Name: wire_fee; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_fee (
- wire_fee_serial bigint NOT NULL,
- wire_method character varying NOT NULL,
- start_date bigint NOT NULL,
- end_date bigint NOT NULL,
- wire_fee_val bigint NOT NULL,
- wire_fee_frac integer NOT NULL,
- closing_fee_val bigint NOT NULL,
- closing_fee_frac integer NOT NULL,
- wad_fee_val bigint NOT NULL,
- wad_fee_frac integer NOT NULL,
- master_sig bytea NOT NULL,
- CONSTRAINT wire_fee_master_sig_check CHECK ((length(master_sig) = 64))
-);
-
-
---
--- Name: TABLE wire_fee; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_fee IS 'list of the wire fees of this exchange, by date';
-
-
---
--- Name: COLUMN wire_fee.wire_fee_serial; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_fee.wire_fee_serial IS 'needed for exchange-auditor replication logic';
-
-
---
--- Name: wire_fee_wire_fee_serial_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_fee ALTER COLUMN wire_fee_serial ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_fee_wire_fee_serial_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_out; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_out (
- wireout_uuid bigint NOT NULL,
- execution_date bigint NOT NULL,
- wtid_raw bytea NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT wire_out_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT wire_out_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-)
-PARTITION BY HASH (wtid_raw);
-
-
---
--- Name: TABLE wire_out; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_out IS 'wire transfers the exchange has executed';
-
-
---
--- Name: COLUMN wire_out.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_out.wire_target_h_payto IS 'Identifies the credited bank account and KYC status';
-
-
---
--- Name: COLUMN wire_out.exchange_account_section; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_out.exchange_account_section IS 'identifies the configuration section with the debit account of this payment';
-
-
---
--- Name: wire_out_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_out_default (
- wireout_uuid bigint NOT NULL,
- execution_date bigint NOT NULL,
- wtid_raw bytea NOT NULL,
- wire_target_h_payto bytea,
- exchange_account_section text NOT NULL,
- amount_val bigint NOT NULL,
- amount_frac integer NOT NULL,
- CONSTRAINT wire_out_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32)),
- CONSTRAINT wire_out_wtid_raw_check CHECK ((length(wtid_raw) = 32))
-);
-ALTER TABLE ONLY public.wire_out ATTACH PARTITION public.wire_out_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wire_out_wireout_uuid_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_out ALTER COLUMN wireout_uuid ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_out_wireout_uuid_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: wire_targets; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_targets (
- wire_target_serial_id bigint NOT NULL,
- wire_target_h_payto bytea NOT NULL,
- payto_uri character varying NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- external_id character varying,
- CONSTRAINT wire_targets_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-)
-PARTITION BY HASH (wire_target_h_payto);
-
-
---
--- Name: TABLE wire_targets; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.wire_targets IS 'All senders and recipients of money via the exchange';
-
-
---
--- Name: COLUMN wire_targets.wire_target_h_payto; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.wire_target_h_payto IS 'Unsalted hash of payto_uri';
-
-
---
--- Name: COLUMN wire_targets.payto_uri; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.payto_uri IS 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)';
-
-
---
--- Name: COLUMN wire_targets.kyc_ok; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.kyc_ok IS 'true if the KYC check was passed successfully';
-
-
---
--- Name: COLUMN wire_targets.external_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.wire_targets.external_id IS 'Name of the user that was used for OAuth 2.0-based legitimization';
-
-
---
--- Name: wire_targets_default; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.wire_targets_default (
- wire_target_serial_id bigint NOT NULL,
- wire_target_h_payto bytea NOT NULL,
- payto_uri character varying NOT NULL,
- kyc_ok boolean DEFAULT false NOT NULL,
- external_id character varying,
- CONSTRAINT wire_targets_wire_target_h_payto_check CHECK ((length(wire_target_h_payto) = 32))
-);
-ALTER TABLE ONLY public.wire_targets ATTACH PARTITION public.wire_targets_default FOR VALUES WITH (modulus 1, remainder 0);
-
-
---
--- Name: wire_targets_wire_target_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.wire_targets ALTER COLUMN wire_target_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.wire_targets_wire_target_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: work_shards; Type: TABLE; Schema: public; Owner: -
---
-
-CREATE TABLE public.work_shards (
- shard_serial_id bigint NOT NULL,
- last_attempt bigint NOT NULL,
- start_row bigint NOT NULL,
- end_row bigint NOT NULL,
- completed boolean DEFAULT false NOT NULL,
- job_name character varying NOT NULL
-);
-
-
---
--- Name: TABLE work_shards; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TABLE public.work_shards IS 'coordinates work between multiple processes working on the same job';
-
-
---
--- Name: COLUMN work_shards.shard_serial_id; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.shard_serial_id IS 'unique serial number identifying the shard';
-
-
---
--- Name: COLUMN work_shards.last_attempt; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.last_attempt IS 'last time a worker attempted to work on the shard';
-
-
---
--- Name: COLUMN work_shards.start_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.start_row IS 'row at which the shard scope starts, inclusive';
-
-
---
--- Name: COLUMN work_shards.end_row; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.end_row IS 'row at which the shard scope ends, exclusive';
-
-
---
--- Name: COLUMN work_shards.completed; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.completed IS 'set to TRUE once the shard is finished by a worker';
-
-
---
--- Name: COLUMN work_shards.job_name; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON COLUMN public.work_shards.job_name IS 'unique name of the job the workers on this shard are performing';
-
-
---
--- Name: work_shards_shard_serial_id_seq; Type: SEQUENCE; Schema: public; Owner: -
---
-
-ALTER TABLE public.work_shards ALTER COLUMN shard_serial_id ADD GENERATED BY DEFAULT AS IDENTITY (
- SEQUENCE NAME public.work_shards_shard_serial_id_seq
- START WITH 1
- INCREMENT BY 1
- NO MINVALUE
- NO MAXVALUE
- CACHE 1
-);
-
-
---
--- Name: app_bankaccount account_no; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount ALTER COLUMN account_no SET DEFAULT nextval('public.app_bankaccount_account_no_seq'::regclass);
-
-
---
--- Name: app_banktransaction id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction ALTER COLUMN id SET DEFAULT nextval('public.app_banktransaction_id_seq'::regclass);
-
-
---
--- Name: auditor_reserves auditor_reserves_rowid; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves ALTER COLUMN auditor_reserves_rowid SET DEFAULT nextval('public.auditor_reserves_auditor_reserves_rowid_seq'::regclass);
-
-
---
--- Name: auth_group id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group ALTER COLUMN id SET DEFAULT nextval('public.auth_group_id_seq'::regclass);
-
-
---
--- Name: auth_group_permissions id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions ALTER COLUMN id SET DEFAULT nextval('public.auth_group_permissions_id_seq'::regclass);
-
-
---
--- Name: auth_permission id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission ALTER COLUMN id SET DEFAULT nextval('public.auth_permission_id_seq'::regclass);
-
-
---
--- Name: auth_user id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user ALTER COLUMN id SET DEFAULT nextval('public.auth_user_id_seq'::regclass);
-
-
---
--- Name: auth_user_groups id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups ALTER COLUMN id SET DEFAULT nextval('public.auth_user_groups_id_seq'::regclass);
-
-
---
--- Name: auth_user_user_permissions id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions ALTER COLUMN id SET DEFAULT nextval('public.auth_user_user_permissions_id_seq'::regclass);
-
-
---
--- Name: deposit_confirmations serial_id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations ALTER COLUMN serial_id SET DEFAULT nextval('public.deposit_confirmations_serial_id_seq'::regclass);
-
-
---
--- Name: django_content_type id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type ALTER COLUMN id SET DEFAULT nextval('public.django_content_type_id_seq'::regclass);
-
-
---
--- Name: django_migrations id; Type: DEFAULT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_migrations ALTER COLUMN id SET DEFAULT nextval('public.django_migrations_id_seq'::regclass);
-
-
---
--- Data for Name: patches; Type: TABLE DATA; Schema: _v; Owner: -
---
-
-COPY _v.patches (patch_name, applied_tsz, applied_by, requires, conflicts) FROM stdin;
-exchange-0001 2022-06-19 14:09:15.999773+02 grothoff {} {}
-merchant-0001 2022-06-19 14:09:16.903953+02 grothoff {} {}
-merchant-0002 2022-06-19 14:09:17.293337+02 grothoff {} {}
-auditor-0001 2022-06-19 14:09:17.419085+02 grothoff {} {}
-\.
-
-
---
--- Data for Name: account_merges_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.account_merges_default (account_merge_request_serial_id, reserve_pub, reserve_sig, purse_pub) FROM stdin;
-\.
-
-
---
--- Data for Name: aggregation_tracking_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.aggregation_tracking_default (aggregation_serial_id, deposit_serial_id, wtid_raw) FROM stdin;
-\.
-
-
---
--- Data for Name: aggregation_transient_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.aggregation_transient_default (amount_val, amount_frac, wire_target_h_payto, exchange_account_section, wtid_raw) FROM stdin;
-\.
-
-
---
--- Data for Name: app_bankaccount; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_bankaccount (is_public, account_no, balance, user_id) FROM stdin;
-t 3 +TESTKUDOS:0 3
-t 4 +TESTKUDOS:0 4
-t 5 +TESTKUDOS:0 5
-t 6 +TESTKUDOS:0 6
-t 7 +TESTKUDOS:0 7
-t 8 +TESTKUDOS:0 8
-t 9 +TESTKUDOS:0 9
-f 10 +TESTKUDOS:0 10
-f 11 +TESTKUDOS:0 11
-t 1 -TESTKUDOS:100 1
-f 12 +TESTKUDOS:92 12
-t 2 +TESTKUDOS:8 2
-\.
-
-
---
--- Data for Name: app_banktransaction; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_banktransaction (id, amount, subject, date, cancelled, request_uid, credit_account_id, debit_account_id) FROM stdin;
-1 TESTKUDOS:100 Joining bonus 2022-06-19 14:09:27.273418+02 f 7cba7a12-88ff-4a37-b5af-3cc84c9c17e2 12 1
-2 TESTKUDOS:8 BANA5SS040WY8ZBD4C873D1G91S31EZ49ZG3647TT4GF8EGZPDHG 2022-06-19 14:09:30.797861+02 f d6f3182c-5314-4eeb-99a2-ad3c1beaa30f 2 12
-\.
-
-
---
--- Data for Name: app_talerwithdrawoperation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.app_talerwithdrawoperation (withdraw_id, amount, selection_done, confirmation_done, aborted, selected_reserve_pub, selected_exchange_account_id, withdraw_account_id) FROM stdin;
-3a864693-f24f-43f0-acfa-148a4f69d9c1 TESTKUDOS:8 t t f BANA5SS040WY8ZBD4C873D1G91S31EZ49ZG3647TT4GF8EGZPDHG 2 12
-\.
-
-
---
--- Data for Name: auditor_balance_summary; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_balance_summary (master_pub, denom_balance_val, denom_balance_frac, deposit_fee_balance_val, deposit_fee_balance_frac, melt_fee_balance_val, melt_fee_balance_frac, refund_fee_balance_val, refund_fee_balance_frac, risk_val, risk_frac, loss_val, loss_frac, irregular_recoup_val, irregular_recoup_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_denom_sigs; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_denom_sigs (auditor_denom_serial, auditor_uuid, denominations_serial, auditor_sig) FROM stdin;
-1 1 10 \\xe1d58cc74ab5af00c931a317004abe22764c42ae5c630cef8653d3d96c77a75d0852de21438b2cabe9680a716e5ab9caf362e2fe14136d13315d2438b769b40a
-2 1 215 \\x97592d7f2376552627e494c2c4fa2e83b6b339d7b3fe6b3a7a2b41277f1df56f47311fb62c71f6e9cc484f74e08d0e1903e0bf93e1027dfe013c2b17fbbcb50d
-3 1 355 \\x8b94eb6fa0c7e551bfeb95bf1a19b06f93cc77d66cbb40a4007bfcfb8010cb61d8ac6edcb96113decf3943b789ae066a0088c7bbaff7288b1a47c656f1b6240f
-4 1 395 \\x51b236d3b2e4868af65f8e4fb5d747eed7b9b0a5cbb6f58d409d5226568ab668ddd3a4e693d3eee737474d9d8fc45c65b778cf0024de9e6a10bb37ceb483020e
-5 1 17 \\xcc1c22a8f417573a7ca58657275adf17e58ad8aac5ea1622dc2b04bcc4da46645cc45d1f8caa1d0c4816c9765b994ac438c8b61622c5b74d6ce77f76ec350e0f
-6 1 166 \\xb45282f048f61e1d088daa6695a7424b4d60d5338470f973e99596a57c681361e661543d12c008a01d69175cef8eb3cd2860d923156b576bcedda7902ae1db03
-7 1 131 \\x0e7e5d724f3260b856ff650a4b20e1243e20ec9f8c5723c8396646e9c1f242a0ce8291da7675963ca50f25cd7e50f794bfec22f5f67a39d778141851844e750b
-8 1 180 \\x67dc17c067255aa0146977e9b7608a25536d97d10f5e0cf8facbc6ccd4e6531902c3ebac303f89ac683beeb7c1cddc6b430244667e9c9af3b96053a6092a9806
-9 1 234 \\xda58cf11fef79edaa5d66473a3c721a005258e29bd5476acd5de607d04f38a8a3df0e501c68f364f2fd451a383b11b93d1338cbadb1526fd75281be249eb0e0e
-10 1 272 \\x7fbf049f568e3891a80912a226a78e3ab57edcf8e771cc3f3fc6075d700c097a99570799432ef81c95948103eff69485b575f3185baf271fcf4cc421beba9907
-11 1 19 \\xa6db3c839e1c9c2d3affabb05bb3e8584be2402880783eb55baaa6f7c9506b3a162c8585c898250bb5951f40db5514bb665877ae34806241b3d3772ade60650e
-12 1 384 \\xf9377b7677087786e133d7abd43abc3f8bcc6794a4378e8367410693160f67d907b051df26041acb3387f854d00235c8edfbeddf19c89bcebb34f8767650cd03
-13 1 278 \\xf10deb8d0ba054d6445a7d27e07b81271d99d0eb1b8570e004040b6a56f4bbfa1b9c8705bca514c3c4d411e94f2ccd3d10467cded46edb0571dd535da1fec70e
-14 1 233 \\x15aaa37efd6cb226009bca1cea602f7a070ea70ec66bc067331a078b1956298632fd1ee2ef05ee9e11243250c8bfbee607fb45f2a4d8d12c51eb28670619d504
-15 1 241 \\x1453ad028f2a1029e7ab31f60ab31cc1ee85894245901f238b07daa833977f9a2721a4fcc67cfad63b0c60fa9354c95a3b00db6bc4c74d9ef68233a308c10d0e
-16 1 175 \\x1950307bb3b0d8ccc5bde73c95cf4c4edce9bd12b4fba4639fb1e828ad2af400965cedefdae32f63cff9e2f71c9e4d27076ca91205b7039976676be605e50c04
-17 1 9 \\xa3c12032743f0bb93c483274858869533e211cb5513073ba2e4bd86747ca7a8b714197dd472c06566bf46a7bd2a9e6939d7cda6e706e0e5ef961dcc058d85208
-18 1 247 \\xbaea199d68ee37fed1e96bde4ff03f04d95b7c67c97780dffbb012280ded7d5c2d747586a8e99fc57432c1d3d1aa128d79e8ea2f8c07cd0dfb72d73efc9eef03
-19 1 137 \\x35b5191a95fed5b9fabb63cd5cdad36690ddb13a510e158905956a7c0981198ac5abd90b967893a0aa71b6b6719953f9461e8a890be0f9dec47734046d9cd60a
-20 1 317 \\x35ca08288646ca4521e79c24835b0b0995a33f8747e4339f97c8544b143d2292b2462ba86d2dad4dc26fee475488f148b014efc2db54d830e785dd610cc2d20b
-21 1 144 \\x6054a18978ca63ea7b647b7704faa42ea493da7be3ef34af3c667c1989fbb39146f13a9c848ba5c73a9ce62424ebeba3116e91f99aa843184a04f0f3cac0d007
-22 1 225 \\x9d375fa26838de6ee26224171837d30be15859e40d116fa50deed47e5290ed62d1ab6fdb7e466314b75fd868ab5668067334ef26d044f3074c57aec24458fa0b
-23 1 357 \\x5843bd074c7b1df424a8114679d34fc68963a9c13ee3b54df0e50529a4cbb71a9ba9602a04da13a72e5d4ce2c1b51ba73714578b96e6abb4f5f66269d6da580a
-24 1 231 \\x395a1ad256dd4cfb8a30dcc6af4b04b4083e64464a0beffab50085c7ce82c77d071660c3a0e013ab657b6b0c6e9b5951de200d5f2e2529fc7ce5c80acd5e5b06
-25 1 189 \\xd9c525eb5c97b6389ae02e6651c963cd6d897a36a0d3a109e57f2ff6d3640526f98d20bc0f48b86645c2708345d0b505c7b0db26e74c0081c3f5728fec71e90f
-26 1 102 \\x94d173ff1b775b5b94a5e0c4ded3b2b17274619b7eb41c04308253496bdad3ac0d2368e3415ccc2c45932a81f4830c31cec60fc199c57fc69da79c2de9cb440e
-27 1 21 \\x6bd807418dc0465d184c681f243d1af62bd4109185543c399e2f1e2d51f600b47040d83751285813376814a8de2a4b9e31f65832d31bfd6aa36e48ad6fb9fe05
-28 1 289 \\xaafd54f58cbf20c783243ce326e9c6960f5339f4addc876b2c04b8b7ac5e90856958436f31d965e68eb89c4ce8ae1ebf64fbd512ae794a66afae2889b8bfd302
-29 1 226 \\x97f857ab984dc034ec5d9cf189f7b3af2fbc857175ca8182bf5c71d71c55974800c015f58311e5cebe7c9e447fd0df234f6faae399d48677b5c9fbc68b5fdd04
-30 1 89 \\x311bfc0c19f7b4bbc3b65fc24a485b230af850acce6cf417576cfa379b7215557bdb644fceda32738e797eb557947206a86cd2230e19915ac292c5086fe87103
-31 1 1 \\x28a964c8a0d92682ccefccee72c6b0bfc3c563b9953903e16bbf4db640ebbcd86daf02cc11c911be575634664eb99530f482b0ea988b4912f2f714d9e0a3e502
-32 1 2 \\x92f8dd688f9a3947ab4d4898a0f87216a0460db8cb636d027aa759eece7daf1ee4028e38b1913e48949aa5ddbd511a73a59b33e6ea12c109c1dc551c9dea4f0d
-33 1 142 \\xa8bed11d177a06f68899c96e8d1d810d935f7f7feb1433102f8667ab87210fcfe7287531c5b67b82bb95b69a26dd48afc30f89e13cc5b460e983cc7585def805
-34 1 163 \\x900f059560670ed137a16449277b619cb66627185cd0ff19c2ec89df06b641878404f1a1eb2e7b1cb0815c101c2882f45ffaec19c9ac1610866377544191470b
-35 1 263 \\x6f31f0f60e46681d2acc4e683a44369f53bff3420320434b6d995d935a4bdeb7df1cd14601a9c663fa5594e2b483cba19a92964a2457c43fa9e1c06744d73f09
-36 1 68 \\xa3074e1c2b4d61cfc473317dd70f812736a4fca40a68e47c5022d8986f546a99f27d3cc6e9904792ef5fe932071f382734e1a757697caf383bbb374f10ffd107
-37 1 246 \\xabf2e8c78185d21294bcbde3d06307a65bb70ac77c210ee7ed0a7a40b7ef1611538221da5202b61a558308984f8b55f426eafa7f68584ea4d091d90cd52bf305
-38 1 80 \\x79a0bcb7a2aa33e212a4f6dcb5fe99d4f2d8901d18ff24029de13977237ac619c1fabc1d377a95b2bca4ea6c95ba0816957de622911b19da7d1d13272074c50b
-39 1 188 \\x1d3d2aae703d8e399561d410312e5219ade426497a9023c5cfa4c77f52bbfb59c943851bd0995568ed67db52823669b06ac4eb30b5aaae1de20f1f69a7431b02
-40 1 237 \\xc8cd7774632eb090b9a829f07c7c7535ee84292dbe0fbad8dea2701113903b2f1a673c4a7abd8bb94c897ac7c81e8ffb248cf5568a60c6c4e19b5461c44c6f0c
-41 1 385 \\x394c839097331240ab965ea75b68850d754853a4fa02ba2ed1c2809a7a08d238ca9b687bada3d2ffd54f32777cd95a9defa27ce3f9e3fd6407ca2bfdcd287b0d
-42 1 63 \\x7182d1a377c79463197f31d37caee3e7b85cf90bd77b468dc45666a6b1b4511b08cf40c1651451ba3090f355b8fa14db3ba26850c3077c77f25d65ffbe228d06
-43 1 126 \\xd6609e33c6b41b7adee721398935828545f4628525100a98b973e20d524c6862d3b61e330cc2c3e0a5e314e02b67d9707646612af372148790a3d66b35066708
-44 1 160 \\x523ae325e390ee43977460d9cc83086d67f135f4c01c0a73c493725bf8588a57f536af4465f38fd91f8140ab6cc06039624904d622242ee7c719c6c4967b790c
-45 1 342 \\xb2a5e9d25d2cb29e92c92a6ea1ef8bc51b135bea49d49196e4d3e121db4f47aef39205f799330c8bf564f9f6ac0fd27e7db9d86974aecd78bd4273dedb480d0c
-46 1 413 \\x7aca3f1e6e7479ad190025d53d591fe334621d2ea558e41ff5718e105789b0b27f3df435054e7dc307d14a62e500ed6dac0fe14db3195ddb6c843f7d48df9505
-47 1 424 \\x67b82ba6356b136f3a1499a25b9d0681e6e446d623ae57cee6a414d4e965e2ded6520d73034b8a0de006010ce6d42ab3af2d20b563aeecb3deec3cfcf3c5b903
-48 1 242 \\x4d7a35f7ecec5fa390c1274c34c3f0ed7b806947b5e341ba6d4081af9bdf8b0e12f120f1a10eabc36538a00a00ea9b6323dc4fa5913e39d5e6578104494e390b
-49 1 103 \\x576e422e3b2c1eeeb069a7a566664d83cb43f157ead3c883816d88ab9078ed3de611899d7688353a8a32d52db731c962aea071504bd890031e6534715342830c
-50 1 117 \\x0c7b4c90b861791616069f6921f63627e52a162786b80b36a99a7384e09df95f46f12a736d6ae32f0d1349b6861a15bcfcc506fd5c81bb708bdc75ac30d24e08
-51 1 359 \\x323429a114271c4ac44beeea7cc16c36f9a3d721e34b8324602245e62a4f780c9c7aaaa714e2b15509acf1b1ca504b3852fbc13ab57fdc125aebf800e90f8400
-52 1 170 \\xa6b38bead301a30cf0f24ef95e947fc80db6cd5cde7ff1fab524c585ec9406f56505c4921201b1f1c090bd7da883aab3e632ae68542790d7a62c74fbeee7f00a
-53 1 29 \\x65ba4faae7354415140e8dd6d9f4c1511b9c53814b4ec0f3e86cc762d248fb06bc8e9271d1acc2eda4a094e4402edb721b9d198da13c9bcbaedff722a6d98504
-54 1 370 \\xe7287e3aaa32d9b8addc5c386ed0474e16057be1f6c3e25c82b2ae8287288ae34a149df911f3294d058529f21bba88a03175f5b8de297cded13abbe29e5af00f
-55 1 348 \\x5b6d9a23e3e4549bd291b66a6b4c932196398bebb1078dc41b5333bba812eaa72498ec830597ce574ca2737b637a0a3786c290e5aad1d4ccfeef36a546421501
-56 1 389 \\xb1c67fa45b97e53c366be83a6b62f990bdf75483391b591d8e5bb36e2f603d1f212cab4daa42000002e136856f8531ee4aeccc5c742e0d81010b76d67498c702
-57 1 43 \\xee56c93601df65e73435f2cd51355af8079817a95e3d2b6642e53c202d2f20fbf13d6f3712467d9e948033ffe5dc7679040b8e1b60b76c2fd4bd8de16a5a2d0b
-58 1 123 \\xc634d13a8bb6f7d5b41ac2705fe3fe8ea40ad557634ce7dda5765485ffeb4a951dd1c9da4873c231cc28d66fbe473da85803234bfa7a95f9bceb8511b2baa00f
-59 1 400 \\xc7ff961fa1d7cab4c17e803cdacba83c9d8c9add095bad5a223b97b72512ea9c2f61d0f71e0ec6cff0acb823135427319d5a66f07dda741af5e1252d8cbb9d04
-60 1 141 \\x4a0695f6e6b51977ada90cee9599e8220307844c7124d7bc2a595cadcd1e8eb2f2f81b28214d22559672f9cbaaeb44321b4139e01f4cf7de9e5678a3c187ef08
-61 1 365 \\x51651b768b4616ea030c01b376b94b8f29d3a6625a54072002d31d9cfd770d3d9a344e8bd3970ce034d626b6800a446ddc877f5634ffeedbdcee76f7420b1a07
-62 1 24 \\xac0836e01e0fc817591b91a3472cafc5f297edc5d9134e28cf382d4842e414de89a5e8bdc48283efebaed7820b16cc45bbe42b50ad580a9bb997bf9b9458ad08
-63 1 220 \\xeb349ff388015133490b0ace2730f66e517cb774c3641d6baf9434ad2e6d08cf214148fc3de43939f9eb34c5406507771b3afc0bf1c3d3504daf96de673dd804
-64 1 271 \\x0a9766aeb831f0bfc335aa72a13bb5ea97865dca98db00ae4a071770f0f29669b0e477fefc2d2757fbced4f9cc422f0a4c5859a85fb1e7b1df9c8a74c271bf0a
-65 1 154 \\xd212ce988d5116b3aecd77b4c3b75d33046bd7a00c24a26e332d60920bb0d58fbebfc967634a84c9fde00d37a75be5fd865dc40995909fa6cbd53e360fc12a02
-66 1 280 \\xba63e4cbc8e7c0b4325cd93834edbef6e6a5d29174fa9735b79cab6e602196d5b7c2c58b00a6b350671668da9213e4c865cb888627bf319e8885e26701fcb10a
-67 1 109 \\xa5ea3b72fe6c9d7637075e794c202e38ccd32f52e7ff1c356a7fe83d83f69521882f40a5dd4b996f9aec42e12582c1f9c159d62fe73e0ecea5c8f2825cd18809
-68 1 20 \\xae272f2f8df59b2d83445001a94d684a9af5932d60737e7f31fb1f481e3f6790a0503d90ac943493f56d112f55c314aef2ea42bdcdb16cf99308da9145e75a0c
-69 1 196 \\x102ae48354f79d4a0711a0670938c8ebdc81f01a237e0140eef3c1d7ece1f0a844f534962b29f596c45314d5025769c5bb6c6b54a0817aed922061b13ee2c601
-70 1 203 \\xc53ae7678ea3d6155ed75885bd7f91eb02b885f8fcfbb57141e1afcaec48a9ff2eb0f220e4f7a0a10f23f08514f1bfb7715e3562ec7ba3fbc2597fd6c114c502
-71 1 221 \\xfd7d8bc89f222d967399dfcbd8dc4a34c77ceb391c2681cc168d9c5496c8473e0a9f8b01f5351c6b3e4b97fe39796a0d66003feb787f14d20984d6caac620704
-72 1 262 \\xcc7b8ad0e7f09a1a5dac18c42e3b092d94bd2dc99bb1381f44727d451aadeac3be8ceb44d61ccf8652744680e8478569bc6bf46a5f64db95bb02e6bcd2b4730e
-73 1 200 \\x3c4ea854aa0706c0f1353a009c42d3939b7d2dbb107f3ec43e195b2611349b673c6bd1d4de984d78f87c0175853310f459fa6d4df741a0da018345ccadad7c0a
-74 1 270 \\x8940bd24045c81b8cdece19a5b968a25821121f6374d02eef654fa1367d65d24576a719d2f41ce007f80589b3987a4c963e96b2d1d7499546126a6f6c1f4fd03
-75 1 95 \\x204615b8edec1551967086c6081fff94691f54738ec7fd0b5fdcccbf2b6c8151a8765c339ab59012d7c68380ea52f9a861a4980c4fd3d8b006f24cc532e2f104
-76 1 298 \\x3d1c8fb27200bf2b1baad7fc7fd406d0de8c5be4881231620a3587ae0ffb511d6d576ca30485115fea4ab9d56306fc520c3a6a69cf0a7e00714328d00611f909
-77 1 401 \\xb13931d35fadd53cb5d3a5fd78ff9c88225f20b1022034fcab4547a3aed5b33fb61a98ab8f471e5ada0a442631452ae8016b491f4adb8c52aa7fb84506aac506
-78 1 417 \\xcb4c3915b0d492834742c78b57a5ea3f8c3b94169548b80693367ed2f2be147b8c3aa4b39fbec8d95d5b0fde64f73a23e086f551c4f2a41b6847da7a1901d10e
-79 1 423 \\xab3d8611a29162e2502f5e7315ba0b960a62a0ea06cc7cb6e4a7075bf8958e448384470a415ad88e29b1333df2d2b491cb02bd2ec780912eee0fa01bc230e009
-80 1 7 \\x6bdf3955f6f8050d64eed2de847878440c667b478accfda9c2ce089e2748cd11a44895ddef41d8769b518f0644376f3538328c87f37a711431a1aefd8ee6b309
-81 1 381 \\xc4f470904cf65c364d73812bbab114080de82aa0a1bcbf22e4a4f124a91ef5bb1a367cff8d5beb6c5cc92b98be1c3cd6b04ee09c13ff8c3cc3d032d9fae61c0b
-82 1 259 \\xd781a4db470e5cd4591aed5beb3b9127fa4239c29bd7baa6610ee486aa51ad88a56f11c9c53502425ddd60265f5a62471a361fdf4cb2234bf1f20d06a28c390d
-83 1 18 \\x367ce871719bcccb4b23eee679fc4d413d42330c6249a72428a2f8d204d45d60199ac726c212b92d726f859222efd2d2fd896b775bb65a7d19a9fd3951d97d07
-84 1 28 \\x25e753c04a4261de0da2b780c64bb12198781c4235029ded162fbe4756dde12ef40e2bd63a1ab4d74266dba243f7a7e130dfa3be551c2840793b52a59eb5ab0a
-85 1 105 \\x983dc501f9b1db845018c87285588733aa829df37815bf3b7b1200aa153ad99609b190175f2d165fc5a76819e8abd63ceffa598c09fc374fe4a254d1d2d9fa05
-86 1 311 \\xefc12d89021c0c5a850355eb735abf8cba84aab9ef7158c08c60219644bc16505c257cb1168e0d30e92f24eab94a588b25c472f03b7a68ce8b39c1597bc3cc0a
-87 1 205 \\xcb6c5b6d0d7d7199440c8bdcd930f277c8ea6ccad3d29333588c496f0ce6fa5f5854738307f970ec663be67f70c1ec3e1f53dc69f6a070e4f37524fe7f5d2e05
-88 1 275 \\x73f21728aa4f49c0084f21709e8f61060e05d2159575e14f3e4c87741728c2d8c127b54b5591cdc9c6935069e765ea6a5dd000c30b69ef28e61ff017c7b08b0b
-89 1 13 \\x8b0a99cacd7842beede1f57a9eea33789185c6ab25d206c842a89245f07d6ebf5b3b7c825a850aa149edbacb28f6f5e8860e2c340d131e422321fc2f53cd6f0b
-90 1 218 \\x219d8c9faf9b3dc3cdace6265d2cd87d251d8f38ba0b8455da98ae740e301b47991f77706e3714d17ee8847d2586a764a2663b1bdc3a81524b6e0ed0487bc903
-91 1 239 \\xdbdef0f092ce0612d274700fe3cb248b1a76c0b2f918438ccc765da51812e10e83205dd9a238c8e016a864a85923ef96c24e3ad9e5d44940eedf4944200b0a01
-92 1 378 \\xb0ca7b5ca26dd8aa55d4af654f0ff55c5d0831810a8b8a79b7be5ca7275b959d97156bdd7176a6db64563c0e00ee3920457946e789db2b1684a8156186f20902
-93 1 399 \\x6e6e2c76bd7ce46092296d62d317b1527d7d578e5a47053d37c67c3e1f32b441c0634362babc1fcbf1cacf1c49773bdcf71423e2b45d94937564d32e3a071805
-94 1 151 \\xd0e9d6cb2e5cb070a9c020ec95d27b832e2156ff44149f1d9dfbdf0445136e7172a69e4a998cc14d147130b19b584038015489b4c3060c03ac34551176750407
-95 1 373 \\x7410d1f64106aa2ddd1e3ab755705d287b62adf905b8d9d303c9147dc47a589c43387397767d71693dd46f133bc55cfec31f492c738e2585f0093d969fce0100
-96 1 230 \\x9c1ba772f95f31042bc1261fe4031e7651bea02186a5d30588adaa88fca51c3db3d67311106e90567dc9ff79da7578527e35d069d1ea599cc30edffa2352ac02
-97 1 394 \\xe9700af05ca116669c41a48eb80605db5320ee1b42edf521b937ca5ed406eca76793dad71a9deb324b5e99ca710b7fa9e4fd06697c965ce3584076f279edba0a
-98 1 382 \\x57a78b2424f4b6c1283017eb20f5f94cc8416b446802241ed357a803cb8f96d6f8feb87ee68b8f340821d5574122a2d3748f7531d54d6ef911f9bf98c949880e
-99 1 343 \\xca0dec791b4db5fa9eb7a629389f1af4f4dfd735e0ba108c8837f809b88c30ea2e31d5d4cb6254b5450f44ab384fbc4078615a6eef7dfb3f8b7f99b594ae100e
-100 1 363 \\xa29bc4c27b3a16bf9d3d9654a15cfa29ab2f420ae3352462678fcbd587876487e0722ec5cf8e154cf8bc28665566c7be0a9886a8caccef6266e3f40b18ff7a00
-101 1 335 \\x7a2aeffa6518db55f305988bc1cadfddb47e845be2ba17a06f59d16424d667ba5b8b724fed06c77c5ad4a5389e555f8d3bcaa520c5ce72bce9a186b168e18304
-102 1 152 \\xfdf31417d21fb9e50206fceb69b53e868e1f06e3316d8170dd2b609d084558cfa7a6ac7cc636d9c31148424d36fa3304b64e4e078123c09065e7d04a23e61d0f
-103 1 15 \\xc842da515f0610560aaadc2333e86ba3ef1d0d799383f531c00485b6590ed61e2899786efe2b2cf60ca4accd4682eb5bba262e18a554fcaffe3d098edac7b004
-104 1 323 \\x7f4fbbd29cbb3c211fbbb84a8ca3ac6fe74f490569a2d8691d25e0021908bc66d5df20addd3c9cc00f15f304bf4ae9af3a55c4dd32d7622f11f3d230cb42d304
-105 1 58 \\xa5baa5f71c700c90975b35b215a9d507044cdcb4631269e73d1acce867fb11c0dc2fda80ca209b302c6258166f65bba081a4ce3d4e6617387a99ae27803d8409
-106 1 26 \\x9e0c83ed465ca8d7f7380e3fb0c0d36415dd09691f926bf7a603e0c007fe497bc7e9b282ce91a122555030756047920d454e228204d2f471f94d6b40ed8bf907
-107 1 133 \\x6fa2cdb304a4b9a3c8e14495109c6bb9534e7c6fa7e0056a72251894436fe4a94fad6c9f4119ddd71f1c8acdb20e7090b8de955e86a763179c79e46c974a3102
-108 1 186 \\x362dfb321fbcceb099eed4f16078f84908abb301dc5c290f144b7783b3d99630730c76f812ae29d01cbd431de5dce3b30d2fee4e7f5da8f09576160c52f09604
-109 1 347 \\x4684138ab6caa57bfba838183a89f4060bb1e017430bd2597f527de11956b5804e626b754b05a5ab91af96bc96f83fb222d25d9dda0425f72e9d9378be4fa306
-110 1 193 \\xfe53781ec51838b00bec0893f6bcb074b9b65f79ea20a8ae57c6dafc62f340273a1810f77e62fd5998f61165fe626a13f704e63e9be565d321582184a2c2df0e
-111 1 351 \\x92ffedf542ef13d47d933fec344840b5b0d073b837a1228ea1ea9b998ebe93c6e9973fcf3dc61352d593fbd43ec2d8b2f1504246ed1a916b8e3804595119b106
-112 1 167 \\x9d46b04921df9a3c59d522449b102a8e9869ab4279a2476f8e789bde1bcd4fd311b0e1e2c5ee21f45ac802e1677a9e9aa5772ee39e22dcbdf99eac94b1eb7b00
-113 1 55 \\x9acb981fd75338bc53f36390084897539085b3b18e420bc280c7a752f2abb4d10197b0a2af85b0ec3dce8fe45678933f2d29f30d6e81c29420d39392dbdfe60b
-114 1 210 \\xb46d67682ff725dbbfb61d412e88b87f799085845b16b9af7a5b4331c7d92b577bb74b3144e9e5ebaf7e3974b2efd8eff094aac19cd33ca022d80dfc900b0007
-115 1 11 \\xba7d0535465b0ce5ddc2e3c046358e0ac6ee9ca83e21df08908aec10394aa0bdcabb848aea8432f6058d78cf0c70594609f0e3e2ac9303da9f11d81f17e6240f
-116 1 315 \\xc35eccf31a2c2ba7dfbadba40d8e5d70b5e2873f6665b73a59247080bf7595c0212d286de16324907dd239b839cb1a897b13cb9d22355faca62d623fa3a96d03
-117 1 155 \\x2bdfd8af0346aa3ec5ed25c4bd8d7e5026a80182419d0e98aaa2318a6b445c7c608004b85c040f1f8204a75476452facc8c46b71b296fd85b3a63fac09e1930d
-118 1 158 \\xbc45bd545205c1c62af5e137168a46b6a0e46f5b8217489e7022ac95f719c11da24dfbdeae8049beaf313596a94c5f811c0f82b0f260da27bbcb9d3d6a91a20e
-119 1 116 \\x275266fb3d94d8c4cf4ef84e5d5eef4b6a9c8b6885c9d7f8d4f92a214b416a09477dfb2e55d3dc6c19802f4a47a21546f670e2aaab341e628fa8e75267a76303
-120 1 285 \\x3ae29942eacf6d8e1451cfbede290fa4c260732e4181a7be361f8f12d327b923e57604c36bedab6cbbc2eae0f6bc9ab941b7a6b1773d7f310a72ee22aedf8801
-121 1 118 \\x94ef84f8a0f00370f25f7a49b6415644d6d4712c02f7b339b8ea639150d1771b5cbadc2be81a21d2c5480c94212b8048ec4c0d59a93c7969a59d639d6f5e5b0e
-122 1 396 \\x482f181ede6b64766ba8b6214181c0e3df912f4efd06f778c283a200a4f92c45f43d0b5799978e3628453696cea62ed942e271ec64fa22afd202ce9ea997860d
-123 1 398 \\x0d302191451e6714b960cef88c2e2384066fac81ca0339f5eb10172c98a05a05f79f79983d28d33b8049fe93d7a2ee4ab2c334d4a5dd2b643cf0ee89dcb7fb05
-124 1 253 \\x8b2ae3143347f83c701ec3255ba42d104e76c02af0375d698769dc1f5c2664b6a0d0ed50711bd21e46776e7435bbc43127398ea2274b9f07f9a07d584456df0f
-125 1 132 \\x351720735e8947ab1925a70e425fbd26ff14ce7fde87d49420c5d2aa5ea0ababe301982fc49f750a94d5639fd58992afec53c1f7b6f67eab236034acae70cb0f
-126 1 202 \\x0598dee7dff69eeefc74da9d76843406651e240f0dfd6af645916a7926ac308a5ba22a2134f717182bb513e87827740a0fbdcc2955691d95aa8fb56f3b86500b
-127 1 216 \\x390ff49a1e1cf8efa0074497ddfddbc0f0c8f036a791aad6351d2f8a93530077c587a159918aa8d569a6024634449f652ba594ae286977a6b8e9f44ef028de09
-128 1 22 \\xba8de7afa082e359334689d478e6bdffc79242fed09248a81fa7c2c13280e52e76bda3066900500d13f762ab5a64229d27135677ba4529609ed241a4090e3e09
-129 1 316 \\x88be5c19f302827a63085659c40ac1d61ca00987967d5c0bc4e97c880cfb690bb99b7fa90c3dbbe276fa71b3417ac8a753fdd3eedc6d19cfa9ed464c6566e20a
-130 1 107 \\xb4bc3582f4956e3c6f4cb0d9785c8fa83f8e3ddfc0f475f03ed9f8a940a6962d62041061949f7da96451d49a898456d02a31dbed6827dce789422b2be9b0b404
-131 1 266 \\x5ade64a1eead9ccf22bb728f39b36d1736d61de2f685ea4f36b1cc54cdccd44621954288fb35ad728c6d15e8da155e5e4d7c629d382f7d4bf9b905e32160c10f
-132 1 287 \\x16c156918abc50ec2f906f28856287b49f326172c4e8d99ed45de35838bad60686846853da29a09ec84baeca696266fcfd0741ce936666554b85cc8ed994ce06
-133 1 45 \\xa928f192bdfc47610d415fe461501efbfa6d7adf3110cccb40dd542f35c4ac042769e57d0b80a7eaad0023df2d0ce6bca4c61e3605f9c4c337ec160cf2ab1f02
-134 1 99 \\xbab61e2868e0cb7b5d367a05725689b8d3e0cdadc7560b96f0b38905e7d0b5dec2afe84c8861e7516888180a4950af2b5bd80bf9561b0c9a7b8858ca90d2130f
-135 1 182 \\xb2d964ae8feeb92be1152d67f0bb7911dcc3ca4b41e7e3f9ca459addcfdd2fcbb865ef7ad1252976e1df8af2361b95bc7f8207e0ffb31b6fa82e5d41f0d7c706
-136 1 422 \\xbf71eee54fac8d1cac4ef5e8391b669a5d6a86b1bb3d38abfc50045bcc6ab46826d651b8570864b4c77c09280ef8905ac07ed3c688dea541af12742276682401
-137 1 224 \\x7c1bff5b64ae2d79d5d0af80afe6001a5ea6f25d00839faa5314bb826e3c30b0909fbfd7c31c170479c1d0f373bb3d44f0cc1a37d46cf3b7eb3465b74ed24003
-138 1 409 \\x67dcf271d0706722a02fad43f88dc964c60b35ac39d8c2af0e7d1510cfe349de72b8039cc743f9d53620b0e4353198b50ba47bb7185f2bd1922a9d7fe1532104
-139 1 48 \\x0897ab58a32495747e34a8cab37498d37972f13184c2b66e7ac8c29df8f8dedc1223c9c479aad71319e71791913e57d1f9266a17da319ab15b49c7392ed3a10b
-140 1 334 \\x118afc758a0c54af2653eca01692ac76cafa5cacc60ad444df3d4bb3cacfcd6b89603e079e01e25f614fe67b2defba39b362c64c2434d4334244dd57097a8b06
-141 1 267 \\x603070d90a602b479c3e7952cdc33595987403da587d2acc35924f5e662a8fe3f180072c0974ab2b0264fd78fa98a91ca4c3c69f2daa0a70bcff4b970ec25f09
-142 1 108 \\xb87a6586fb2e80c44d01ee84c3c1e6763863a64c4302b6cc637486d18ac08c15c0476e26db106d32f3e99b4a0385b226f07b166307d857734dcc9f10b75f1f07
-143 1 37 \\x9272d3b6c6bf3d4177d9bbc87837ff9fe8f72db60dce97cb9835c7592b70441456491b309222209ff8bae867243d31b5311a495c4d80cdcf3323e4f2b5da6b0d
-144 1 288 \\x421978691f5db0e7aa19f67d2bb0f37d061ad708dd08a3f91403da76ca4be3c412b07de164b3dde4511766a150db924c1242e426640e19d239f49631b8f0fc0c
-145 1 16 \\x1dd97336ea5bc25c6e7ee924dfa5814ba347e70b94de11681ecf441dc8f6f8b3d296d7ad5efd473d9d8f3bfc067efe46c7f74643e5b26ed325b5ccce05203d06
-146 1 207 \\x19dcb3c7ede94f69d650d733dc93a52f24bc7c4e4dc2b18b660e0495136e3844a898707cb02e0dc20d73a5526e2c003bd207ef9bbb34fc0f5011fe5c0500dd0d
-147 1 356 \\xa3e27e946fa9c1bfa4b0cb963651fdbac4e32d736168946578038180eb6f15747b593d8b0b4fdfda81734b47353b4021ef4afdad867634e028011983ab36a70e
-148 1 299 \\x99e45a124e0524d60c8d7f3a274edaffb9196b6232cc9611b2c2447d5aea2c651fd37606f6cecd4dd4915d9b31d8b4c7963fa0400b92d7e07d01a2d88fb49e0e
-149 1 178 \\x6923f3f30299922897f722a4f8368b9f8faa23386886888e1f63909870028b40782af42469e603e71b8033f670a7d5251b633dffc4df07eafe3cace10f18ea04
-150 1 173 \\xd88a4495e2b3387366c1a4ff3ee8e248c2855793f70ab34c2fee83522241230f585cd68eea5e37330dba9fd5343aa029ab30c4626bb06f9bb775279d008e9201
-151 1 380 \\x67c050ee64db75bb282f975e679d99e82c53b6f5d4e17cd71e0e90d90d3e20cc2a52642da85f2b03e465dcdc3616ba64c510b58b1ebbe7fa2758145b08777004
-152 1 367 \\x8eecc72e4d5805f5dcde98c54ff89a703c1fdfdd9c2e1225c4ba2bd36c5d768c462cfe08992cbbfee5b5b63f48dcfbfe178b8fd0e0ce8d9596a9b51469359806
-153 1 78 \\xfee3c3bb1d748ab0ca0c66c43b5381cf137f39c714d56f4696e4a5a13f2fc9ccfd740088fb0739dce6ca7dacd3ada54e5a1d242445d136aeaef38cd7d060e102
-154 1 329 \\x1116899a33784effec7e3566f245961e61d1acfbe6a3eea4bad82405c80941f23f45e474c328d69ad2bbcc3622fa544944dc05ea05f0e6ee05b7cb5f1a6bd70c
-155 1 404 \\x9a7935c1e3b0433fdde3db3a9c4b26fed97f3537f1e2f20d23cff821d33847a2f0a8500b2986cb720b4dbe21dfef558ede79821369cc9abb3975eb5414e6c906
-156 1 127 \\xab4067e8bd08ff6835ceffbafe1e476460a7269f87432a6e6b62161c1f8411a888a68d8b4776e66743484d6b5f6cca3f0eb7ea00993dbbe7c64710e4c9ce8f00
-157 1 14 \\x3ba3e4a0bf6981b00462969073f73be39d8cb3193a2bb6f68da3bcf77da83d4d64f661215787b6a5f9fe3555a4fb5f868864bada1209cd28de50acdb2f655702
-158 1 309 \\x67e2cf3d747e018a1e9e3e9fd50ee2b3457b90aed0455e334e325dfc1d47175a51afadf233e6859225a7ffd27bd89c6fd36ede100c523180f56cf6e3ce9ea80e
-159 1 52 \\xf1f3d75d7376f45d8963abd71a1fe4674e0797b9c1385c625684a756a170d627d5bc7962e61a30d9d8863a1dfb80d2b96aa9fac5b946db901e42b7eed4b3490c
-160 1 54 \\xdb503f2f8cce2d14bc4d013f054abbbb84bc646ba07f1fd33c9446fa23f868cd43539801544251d691706b9c6f730c73f6b84c113ee0b6abf057711ce0258e04
-161 1 238 \\x60e121ad105ec5c48e714473fefea745d398df7f440a4a0b406dec49767896cb89e0804d781d2e2e32eddc29f0388f3a79e21d22c709bc9c16cad45ba2e0cd0b
-162 1 372 \\x882b72b6cef3cfbfbcd8ed9e55cc3fa1dc8cf416d90905eb3fef582b6166058b41e968ec8f3ba3f35b417f4b959c631dde54be5135f50c871a5b69daf2db890c
-163 1 326 \\x5d5f6e230ace292e01d645956531f84a0b8680cd84dd5f26a5fb678d9328f28428627f307356f632429dfa7ccdc0066c628cd39b861b7d71cae0ec9e10700c04
-164 1 284 \\xa785c43dae9e1b4b5e7d0afd9d83f92257028cd2aab2cde65283e8b3f5a08b51d2ca7c5aee9408d4f75676b6cff2b35793e9f0936cd1bf6c1868834fd224c109
-165 1 61 \\xa9a6de95144ce046f50ee11b879ac42763f4998da33793725f77efc50add45749086df735364d699ee64d6d80d6d1a0329a1d9b5778f8dae6eb8d56d5ab7d80c
-166 1 332 \\x3d2414d269f98ed7c1c6224751cd588ebfd66719224c8ee385f83fa010fb370ff00cbdc035751170e72f2f792cd6fd9d9a9e07e4a1ac277ffdf17a894ec7020d
-167 1 49 \\xff2659eccb306a322ded9010e1b237bfd87d005b00132f85af9f176f744c6779463e4d0039f2df0d1e9472ac5f0e1ae22cf90d5a0ff432f2ec44fff3736beb07
-168 1 257 \\xeb46d5c8271c4a3b5a54965578ebf3a787da657e22dee88d00e0e144f23ec76c1e31edc5be61c7a662c970eb787729f1756a386c495888e59a9bceeb789c9a0f
-169 1 312 \\x8b8c6044abfd8eca13c30e890b677fa2617f39abb85036b3192959fe3135db127364ed3ec35b8db52b1ddc655a8e3218800c805d4688c82192d8aab3c41c6f00
-170 1 92 \\xaafb536e990e9708db72917e6aa84ab91838a48bbcb6ba3cf0a51be8f8969d82c1dc460096cfa5ab4d860037510faea742660724c7d8d2fc8d27ef36c01b8c0c
-171 1 339 \\x0b65cdc713ef095926577c38c44c50cc93cd9b44ccc8a772522c8cac3a067ed8f0519442e8fd9de896b07e555ee25a6fca40aef6bc6d7c33db800efeaa576505
-172 1 360 \\x9337159347c63897efcff57c6f56fdb719f2d9779e490fe606b6810c18bd0d94ebe2c46d59b60a1a14ab0cad4aba390e7f779a9b8dbd15d2353e90f336cc2f02
-173 1 172 \\x05bb7de3bf079f8e63d4c0b9dcb9260fd79373ba8a3b1cd5dba343800b2aec29e08769154371dfed9d5ce7f42e061ecd7610100588ea97ece4e446448b622503
-174 1 148 \\x47d11ea1a8f765f6d351da93e5e059b66e7fafca0ae4e6796694d314b31b9f3ff44340a6a3ed95179cf845136bab7def8daf1675e8a042dbe4b989390947ea09
-175 1 82 \\xb3d23511f1a569be4d279911b8a0dc109a335570a792abeb3589a933644b496096071cb7c461036c62253897778e15ea6223c5b48eec18227e6120ebc7c44207
-176 1 169 \\x0a6277b4a9a62dfe5207df455c929719e3386a0e54665fc1de90bf9459a6d47e7dd7a23e013dffb8263fad02f5b519d2c7cfe8c1e2e29b8a4058a8f23933cf0a
-177 1 76 \\xc99e6b5620fd8485e36b792fd72b5a28085969e49ed436ef747dd5783eee599af1c81b579750d3777d34ef09f320658c2b8366ab59d21e15712c4ee2e17d0704
-178 1 223 \\xad4cf9ad7f52fa2257de5aa75474e56c2f2e66ae4fd92d77a10cdcb2b20657ec443bb8094f7ee1b0d1cfb75788bb88bf1fa999ca86471e7d7c3fafa8d65a130f
-179 1 217 \\x2bd40fbe3f23505d7482519d4683cbffc6dc6d473a44eed439b321180edbcfc1aaae709bed340bd6d6f09f7dd2f6ee33eb8e55238bfd531d3eb2de5dfaa99109
-180 1 174 \\x9ff8872a1b4cbcdc6952fbc3edd0d8ea1be12595b4c17a8454f0a32ffea64a69a0df45e6ed7abd25833baddb4840d7bc8e0d5d9387379d1d45f6f39d69f76009
-181 1 4 \\xf80ee1e0e5f509b73658b4df55a0d117e8392bbf7382073fc6df4f5eaddc11e56855f91ef928c0eeab3bd3616dac28b11d82453dd7fbda407580b1134041ba0f
-182 1 112 \\xbdab5aa212f6429fc083c1cd662db5953720e6a0856a0d583fc1125c332c3e37ff520fb561eeff53a706abd7f3f5cef2ce23d975fb1cbc9eef7eb28d10d2e203
-183 1 318 \\x0f930735a8d8fbb312cfe0717997b3363a6f9a4ffd882608017f34bd8f67cdaa28ab705ddc5a2321125405b76c95b359174445ee9469e11c5445b3932d640c01
-184 1 264 \\xaec8af12e21973d56952b4b4fe573d6f56b0e4de75072d8ed1920dd07638874f35f352dc8646f9a1fee1727c7465f99796ede9063f821b27a5191d495bbf680e
-185 1 101 \\x67bde5cfd8f9c9cfd611b73cfe7b919d0080d5cabadbcb94444b2e87d1ac441a936f15d7f3fdc57e432532a330e4536948ceae8714ee09a41069c06edeecc802
-186 1 96 \\x8823c825e376aabf19e9029462a9bef4479d31d08c8b805def9b6e23bf9ed16ff306f63fd1dda3806e27b0a73562f345899e3f64c64d30fa4fa518564e014702
-187 1 212 \\x992b8d53c8efac293eb92802066d7940725305cc2965e5ee3bebd3d3c582215e81da7714d2965500f60df1a083e2fe36ecfe5a2fe19ce6c898c2569ecd99010a
-188 1 211 \\x1bf68d4df2ce71d180f871f7015318688cea809efb9f510165b0b2d426f4bfe4892e9bc0b6090f43b04ea01158c204c173487da1f3cba606409eb482ba372a07
-189 1 277 \\x47fe18d663cd3ebc44fd6d3a44569fe2730874d925cb3a887f12daeae4daed37db1c8e6cca5d0c2bf0889ca068a0ce9d684e6e598f3177a5fce8965bacba7a0d
-190 1 353 \\xbf0b991b60dc1a833a8a474cd337d58ff7bc7130239d0b5773c668f87e1e2910f9fd626a61f4cb7f499a0a365c11de639c0732944328c985ce1a9e9638809a07
-191 1 308 \\xaa6bde9c62c1c939b957fd39ca6325146087d9a810b69f2adcd6a72cecba551da5f88da4189b7194199a1904cf7af35b5615e86385cd640782a4d681bdedd10f
-192 1 341 \\x552f33d33d5bcee498921e311e66294bc3aaa394535e85268f06e39575cf3fd07fc3f54478d13f24037af2af2ee4932ba96b67c11af7c990f8e7aa760c0f9c0e
-193 1 187 \\xa12bdd525a00e7a7d256683fe4c0ed1939b57789ac2faebbddefd5d9994611ed7cae84a7b8bc4f71a21c4f3edf58361aab1730f8e014c3a47bbe4c8a256bd40d
-194 1 75 \\xe0963a51a44cb707661d6def06c839f33d1be129104e487e5b405174e5824413585cfb987aa4f6b9d8c5d8564551d451cade910f848344b1a2a6d5a58298b408
-195 1 410 \\xcf7b73afbd804ee53a136e6e5ab506d4ab087fd8284695ddcfde4cf9ff4d04365e75f000b4aed3443a8d213a151e25e4bf005363b0be30da94c06392b12b6e0b
-196 1 150 \\xf9e17e9ad22a373be0a0842be93d4af09b73f91fa15af6eb6b21982ed6e73a2adc6dc2966b5036830e2d958cecdaade861d976dab143b03ae4019184db341401
-197 1 136 \\xf9bba003e528c9801e110ed15f32e8f0d971bc42d9d4953e210cfa37f0c85720296efe37b5a96f6c01263e8abe7a6d232612f228adb2457d3dc305153fdddc0b
-198 1 265 \\x1c7e7b8d10b7d5439fca94147ed897ed89108d637001ddd74b339e2f965d1bc579c7cb8974f2c8282167e643948b6331fe6fc76e3324e1984ac23f78d3a57407
-199 1 336 \\x952f353932a822ecadfa3558610f5c711868045b4ef651021995bbaac58a3e53aac4aa65ab709e394b69676ddb8caff39ec3f29871f6e49132194e32e3bcb003
-200 1 198 \\xb5dcadab72c46a8bd5bae8b5a9c15b3d562947978d3d808ad210299159d634a26fd46ed8e3d5e15cee1e50d08d51fc701ddf42dadb68022504f181c0210b1e09
-201 1 361 \\x662778d852f1f1a4a938a5c15b4751d4913f6bddf5fde4eefa137e05203e60748f86ad5bc10a5a891bba3e7b2128a33f5f45c8fe0e54d29ad0977c56610a510a
-202 1 313 \\x52e2c7915576c2df0680647fb0b533cb03e081fc6ed3d5f27825ccc52026ededde569008ee9d82f74933229798fec32ddc09707683579b6627b693209810df00
-203 1 368 \\x0d9137e2e34ef8fe68ef312ffa5172fab0ebf0bfee8f320f7a3e61fbf20a3dd6497531ffa1c7b5c014a9c9e2774883a835c314c2141b920aea8b8b3a1bca970f
-204 1 268 \\x230c6062dcc04f8fa9867f78ce7c4ea24f87df227be020fe71866702643bc2d83b007b25fcdfb1eb9d1f0350e801cbb26baa8d2c2ead09cf4e8c116872d06604
-205 1 408 \\x27513357b80588055edd9abfd6cc984866b04ff0f3ee958154d880f640ff844285d90143ad6bdd3d28917cd4fcb5463d2dc1af10fc8906ece5a374a897478606
-206 1 387 \\x30ab722fe91b4cbbf7a24a95b8ee7d214ba6a34d1db79fd49081e3762fee267d893a01adc8ff88920c3e32a673830d3429cced5fcaa826621c6f16f85de60b06
-207 1 46 \\x0c7506c7da071dfaa062d955fc9fc62b401f8a836a4617703851610c4f56aeea80c497a6ac38cda03883cd7e2742edf0550b30264c26b8b654a4496f27491009
-208 1 421 \\xac42affa6b6853d799aad2a3c0a0d2f6456f5c2380cb5f949df44e6559003356cfa18e6d2b50c5be5759fc458582502cc4bfec6e3f615f91f74e78057e0f7508
-209 1 60 \\x48c95b561c79c88d4a5ff49498936c6638fe8a00fd95a97c4c69365e258c7dff8c4dce79106958e46ccd006532fc0d1ea59921356bea6f822340a24bbeb0cb05
-210 1 254 \\x793a563e66cc36af9c8195165b477b794abf012c7f5ba7112d4ad831bf1b473f3c27e853ce316f5f1574b952bae733e42253e67f87721599a332c4bb2d553707
-211 1 304 \\x27eac405d63e5697c8e6475a25686f48741e5351aca81427158cfb8350bb276a2ff11b10f25d3c3ea254958b95da62f8a5f98cb2c12aa98ac84312b6fea9e207
-212 1 120 \\x39570e266e043ccb8fb3f23fbde377c27a49e9322c78f8dc6c24d01fdbb48f5d6999ed9d1b393e9e6ad62364b68c88b3dfdf0dc46407f0369e38af9ac9181c05
-213 1 209 \\x89bdc014ee5ac38112995f30058f470e2d394a7d0990c2226b6cbf30da8d8dd83d591fc9a613d5f7e5653563574977c46f554a5f98f95290a814bd3b37a9ff0e
-214 1 235 \\xf785a391b496c9ea5eab22d424c437a9e7aa693f2f9e6aa86a3c0f4a2f8b4d8e80a1387e5cfc5c5b1250614d01b772a458135ee88e8288c941cfd1e15ccf2308
-215 1 383 \\x051952fdd325b6bdd06f020b904f6ef9e3e9ff1777cbc183d2b54ba352bdc704ae322f2f93e21b8476ab48ae5344fbce3d350b0faffc3a2247d34d9f3a40da0c
-216 1 388 \\x1699b47e5a6d636ab78a8b39c88953d5b2256bda2d547865a34d267f4b2f71cf5bce2cf28db55544003cab525a7acc059f06a4070513bf1326c89af7cd81df08
-217 1 295 \\x0000835d424342118dd796f25b4f5801771a4331cd88e2bff7aa0e29e861b2b7db1c4c11a9064b2b7bbf4ccc549a8e26a3550627fd572de7baa8715881bf1a0d
-218 1 35 \\x9026c8ebf7781ff809a4cb9bd52d63d52ba8c08a17bc237fdd287ccba137a0c0db10d9089dc2b3fca8ff663090d13db99ed3ddb4f8c8a979252d02c9f922370e
-219 1 415 \\xf2254cf98d15e478de544aef983455501046d59ffca7c1dbb60e2eab2815d0b8eb8b682e9dad638eba328749c652752a9fa3cf415b894993f444d209b388b302
-220 1 33 \\x5bc494c927aa233144ebeaa5f09f46749cd39d8f0cdef8be9abf146edfaa4b25d96a2411fa8aac568de1f66d8f4f4c9b44f6e20e697faf27f4800783a6c54409
-221 1 208 \\xf09b8561725ad4458d600519810041915772b54cec3ac09ecdf84c3480e75b19bb25676c74200eeac4b895dd6ad8e01cd52ac0f6e48251dd96b208d44a518b04
-222 1 310 \\x2bc6be92c66d6d4b82f492458d4e3a564dfaaf7c6c0e784ba281ba608856ceaf381dfb738ae23724f50b49e58bb8ab01fc36d606ab704909f8b28cd0fae9e70b
-223 1 327 \\x6bfaac24459ccfb1fcb663b9f876c6780e949b835e177c18b1ab5abf7cfe8c91e55c5e35b655da4e0e4630116febc821f9ecf502817fc4b14703a19c112b680d
-224 1 3 \\xcbbca9032da27abab469e97417b2edc278db06f9fb34bc058c20a29989091283ec74bddb515e48df8b1d9ef3b25dae96156bd8d1dc006234a2d45f8cfbadfc0d
-225 1 190 \\x1efc9e60e341ad142b732730d70905049fdde5e2a8ea2a5281a58fc0dc598717649290df2d7d131a108ba25fb4524138fcb117f357bec00130b71262a38cca07
-226 1 168 \\x08062b8eccf9466658f1d9f852a64a0dc2a93f648da361531f63447d3acad822b0af4cc29dc50310cc264832941bdba69b17b718a723b7db850d8bd829cc910b
-227 1 252 \\x82d9b4b4f2452cee62d5a3221d6d3c1e3ac876414d8cd85328fe396fd4b6cb9ce63dbd243a66ecc5b427c9f08ae637c40df478e33a2acc01436f5c74c0819a09
-228 1 296 \\x14360e8405026d8d3d1992866c891381856b878d546b81eea8928893121af262dd0c9d54f1f8bb94ea1cd1db2e3ab5743de39eb3fc725e624c1e69981399980e
-229 1 236 \\x565a8cb74786e5c133099cc916fa9cb5cf4e06228d1d371a6a29bced18d7fc63be5b4497f87c02adc9dc0f1d8d6a82802c9755af1021f755d512c2a42633af00
-230 1 371 \\xd24b0d6d79e2e2d86d0d9d9419aa35952c1b690790a023b0f19fb7a51e5ac99375a587b0e2c5776734be39e73b89c4a0d409d314255e2099a7c9edade6da500c
-231 1 36 \\xf04fb757f29ef75cd7365a95123e28f1e121a76788cc2247ad29bb32ad1aa85773ab927ff9a5968f501b884f6efb5d9c578c8135870c84593090f21722a8550b
-232 1 192 \\x275072cd1641a4dc273d1de11873b450713e570433a30b08ba709ac0b7c6a27fcdc921ac056bc3c1329ca1d358eb14de722ba9e4c434d6901bcdd33ca65af408
-233 1 219 \\xec8d265426e62184a2dd77aa719bb25e66e2ed72ee012bc071a8887ba7a557c6bcaed8c19aaaec3c8622118b579193176c6182eb4db8228eb273f30bba5f1f03
-234 1 31 \\x4550b8e230b20da0c626775f10aa9439ecdd7855085272ca8e531d6f0e26cc371232e71e89a6122d7a9fd12f8dd4cf105bd4f51023a9ddae1795beb784cda906
-235 1 69 \\xe401f5aebe48211e3efd4dec70e51927955861a68147dfeb998e9ae3cf3152a4c1474e2601025d456b143b31c21b0e264c0436446eb9e0456727c2d099510003
-236 1 291 \\xbb8c873411f33ef3e996c7224565483657c546a5ebf1835db34a8d9ceae13f7d1d40dcb6549a22511d01c8ea2c8aeefeaaaa6b5722bdb406349a386280a29107
-237 1 314 \\x3feedf2ba6bd0bce64d5a3f03d3ff6144d3d40dba6546461b9053b3e9cf282687c6ade069283f588f37ad9f70ce23a64fad8ccd7d2d2dd3f55d9163c3e213803
-238 1 64 \\x4e2dd2adef3ae8bd723207f6d415a98c7ab631977ac10ed0ebb5e713d7bfdbdf8928b98906103326bbe1eef5febc9a0fcc0d773e9af626e244af0623292efe07
-239 1 62 \\xc32510a8d5597f9b0101686e2d19c2daf6173403adaa33f6c592953a69c3d121d43133f9a214e72c59e6890860a3a939d6349789b544f99dd52720d04d128309
-240 1 12 \\xa11a0930a806c24bb815a13accb3db6804e539ea9255a771286f12a401097212ed5c14f0c01062e5186d8deb33407fd59d72c5c2e68a40deffc21c507c53610a
-241 1 5 \\x6b94d4057c8d44796eb91a772984e47e95ab0b20ddea72afe3f45e490d3658f1780ae7c5674318cb68d8fdc20de40e0b01ce71e714b6e659658778e2937a9905
-242 1 251 \\x72603a573a02b9d5912c4b6a13afdf7758f6f51139d35010bf95cd6ac17f8310e6158ad03e4def871a34a23d1872bcd236f1878052bff7d128e7ecb3d223b60d
-243 1 338 \\x744500ed4987cd73fbc60eac310a71c82618a9b14f0fa9a703eb1f4c15c3b5eb4d9b6015644082386f078ffc3021fc8183f5e97ecdf4b24bc5510f81ae211502
-244 1 305 \\xc0f86fc409fa55704f172dff5be712c9be4d41bea23007e94c074552bc3d4e3680e2cdaa5fbb2ca423c31c5e8336a970217ece8b598ed47f4c144788feaeeb00
-245 1 349 \\x3a433bd2e4c00e2fa5e682bb2ff370055db10f50edbbb230d09a276b31dcd9009a1b90b8591dc534c831c5e6d9d6b716d97fdf4ea4c46095bfa6f8e091c64e01
-246 1 146 \\x5e614c2587844128b47ff5b85c8ccabfc3ffbb2846fb133d93bd01af068a106152eae1cfbc46b2dd52a58fb70b700fd8bd87551b8d4d867aaed5f5cc3c3e7f02
-247 1 214 \\x9fe1ffc501881eb028a04cc66ea49f7d3ab57243626075fa1fb3730c357fee8e2642a39cd03e0569c0fadb09a4ef4dc208db24bf6820a654bf2d14136f5e3c06
-248 1 153 \\x27b55f4c3a2738bac4d391ffde53a89e9c6ea451fc2eca01d8a40c89a7a67733704801fc1a43c0436fd51d4ef492675d6dff0ccfb18e79da48851a0d8d7f0906
-249 1 83 \\xe98edc4d9bf47c73710d97b74cb746a010c2bb8b2a8b47478f9c1f502c079331c51f7499e8f0b8c5fe25d78c522295cd1ac9aa6170601b39a795440380a44003
-250 1 306 \\x70720ed857a106eb01479e4ad5212bd6cb3123b05ef5f74220c67cdc5359597fae4646b0f721f61c669a222ea13d149c8ffbfddf07d0e4c0ea4466de503ead07
-251 1 122 \\x65c65e125b556db72e1fa994988062fa6f5eade46c74af894d95e339908ce4dbc1f2f537e7affef1d20173557097b36e63a8feb1abe8f36ff9709b05ad55cd02
-252 1 50 \\x1ec1241e7d4d66520043010c1809c31fbeb19d30516f36a422cbfee664dcbe596c32ce27113b3849c4e9c31d42b96dea24314088d061f25d2676a1b8faaa7106
-253 1 222 \\x19ef470f1eff0a74385e85412b3bf05048ec1717b67bf8fc81fbde83bb5e8173f12f21dd5c976e42f6b7d431a000cd938e55e567adfd60b42d706f6d314a6500
-254 1 104 \\xb7133a363d43cadff8d5fbb3b679a644d7040ca10b6e63e2399737ece42a45ddc224977275636796eab8d5036215c3359c6b693fa3e95f1b439c39761d0ff906
-255 1 88 \\xfad91c60df33c8c741e4b9d982d9f3442d261368a42283d229ff6babf9b3d683ee02026ea78de81f409f20f83a04ab3c1ebabd42450c4d91a2e3336daadccf08
-256 1 119 \\x6fc75d7a2d03b0e55f78fc07fe60c527f731e4f437f5001564f38e0d6a8761bdb52e9d74a766eca296f819f5247b35606ae7dd2ef8ad5f7bb4755b180d74c207
-257 1 161 \\x957e3bc90b45f652363bdba4c6f10b3ae154674eb9b006ff1ef70ffc423d2966ff3a047181875ec185df3e4ed04fa86c39aed9abe1874aa89acb17749c240b00
-258 1 328 \\xf4b6f97b006d38e28b55f0b35763b2914fe18b001160e97bac8ffc88f073001665bec661a4a20add2ecb1e90a4a30d7821e8693a605db0e01ee7d3fd929d5203
-259 1 340 \\x0af9e1a9bc1123e9565bb981b9a4451032bd1a03708f1c8a7b90276715be8881341feb9228e4e311610e2ba21d210f60f19dac57025e0b48410a045b17fe260d
-260 1 346 \\x75d0c7ebf47cb763b149b4e8330bd2c198a8c0920a3a8df4e75601e22e84de245eca814eb0e821fdeb6d70ce2f1e0d456d02d72896af3507ad0fd4c3fb3be502
-261 1 292 \\x8e62a4e488f8202e9580e2c38ea22590e5cd43b0b5640e73f25fcc80256d6830c4da9b77534d5796ceba6cfd1b53372e94d6891b6897a081671ade94f5f56b0c
-262 1 85 \\xf19cd5e7db5e31ca051923eeb98bd5108bde7d4237d5ea32bc567845e7c67482233af317352d756cc4c8862fa1bc855acf7bacfc9530c8c0871f9801cafcff02
-263 1 324 \\xada00adbf43a320ab8505c8f3deae353d2abf0a0ba198b63555a0603e3cf83a56fd575624e5dbb6cbb781d306f796a4f29fcaff921543d905926647343d65d02
-264 1 32 \\x8f9957ff19d7434811ff83bdf413fc1afc056a18318b3dcb0bf275cd7cc8af9b466c5daff709bbbf48f17688028421e95a4756f72a8165819d02bedbce3c9903
-265 1 248 \\x21c2e5b086b43ca6ff5a896808980944190fd6434ed7dd1a8627410779d9866814e59d68f7015150af3fa58c8a2b2f56412c00bc11fabe43d6f642b819138500
-266 1 414 \\x3a4efdcbc7785b1e889a0c1111dde1b0b985341cc55541df4ae041d53ec558422cb1b8a8800ba87effad72fec183616feeefc6a190aa4292ac6b3f39a1f18803
-267 1 129 \\x7878caeb9e6d422530c03dca716609ea91a8646f3fb90cd825272d846cfeb8a462ede1241962a6ea400ba47100d03b0e9e384fe66d03ee48847cb916dd3d1401
-268 1 81 \\x10a158dd368f5857a13326c4c54edeb6d3279c49ca437d72e2db42abd0e2e4e0a253ecd18bc71b5be3f7aa5fd6f5edf2b34074ca7570e9fc9bc405c52dbd860c
-269 1 42 \\x4171b3600abbc77bcf81c28a81c7b70ce47db02f78e1dd6e73be8b5672e622b719294bebf4b0d3df90c314ef2926871f2cca4dd49c440b3dae24823233baaa03
-270 1 177 \\x1222d34d995c480f6e3ef15fd04d14b8cd84b52ac0405fe6be92036aeaa588309c41a89d235c5c8233aebf3071098476429a8c7269dc4ca6d499570a5efb9d0b
-271 1 93 \\x137580eec8403820b920325727e54bc7b7c7ecaf473f9b8bc37184ce6abb1dbf2fb0dc1097a2da5219a6afb8a319e11dc51dd44050d9b8951a972ab258c05703
-272 1 70 \\x689095cdd7b67164b481b2ab6b91c5617e36e35983541697b4f0d9f2b0a281f6b9a76950945f0e7f52815cec36030e7dd7eb7a0071c985811d0e6c4e981ee504
-273 1 276 \\x750ed1e23ff5bd198a921ed7c13d1062779343b1c7cd94fa6cfb04ab0c71e1f46bb059b49a7ee5b3f930131d7ba60e22a511c984bc42c50618a33f4c97744903
-274 1 171 \\x7b45ab732df7401f6abdb00ef14144d384bc70077314001e91e4c4cbbd294fcc550984aa157714d45fe2acad913fb848c33ceec64c4a1441045077ef87b57d0a
-275 1 403 \\xb3503b340fd81e034f0589c40a50d9f6c2f14aad763124740254c234fa8036d13430e585f170de67ccde41f85222877891afc508eafb22e6ca8dbf79110de90c
-276 1 110 \\x7bc70fdc276994025c0026fb7eb9e7bd2b21f115873c8d80583a898bb7e148488efe756eb921a906e320c347de978a995de721c5968cafc6de22d84945f98503
-277 1 369 \\x27e6104a808d3770f0518914e05310e801598fdf070301309cbaf9f9f8e02665030091c1f9eeae0e69ca01be0d33d112f84252e873c79d19405243cd1823b10a
-278 1 86 \\x544cb9d31599fcfe6964b2d8628e8786ef3cc9c2ff27d0cd273b8f92cc40d09f4929ec666491029e035fc3e23eed215a72da33270cd5bcde75aec1973e07cd02
-279 1 283 \\xf0d596aa2496345f1448d41c776d958898979794b462ee5818db384b5ec82fe57ba7eb48f591ed6db1704c3244140a47c431bd3a9edeaba6b151b1b9b8fcfc03
-280 1 147 \\xeadd2b446e38b057a78a02dd76ad273508e4723f3ed638d77901d2582d2245905e9b4c468c5b72bba81d02ed754e4fbf0c820a9b4c764ceeabfd60e2fcec5301
-281 1 344 \\x6b8b71ccab687b17395c4dff9487e28d3298c80ccc0b9eaaa49ac301083fc117e3720a3277e824f4fced80f1da5ed7d0b8c448fc3bc9abdeae2d17575d6e970f
-282 1 165 \\xf6728352facc4592244f546f3011c433239e2067a90ff2005ce223512dc3d31025aba237364dea635f554f6c1e28eaa9fb4dce26f470b2d37c55d804f648000f
-283 1 139 \\xf24465217e16dbb524df0776c5053d978647ac91cecb02f5f4a8ba9d3517fdc613e258aacc0992452dae5ea39a7e49fdcc84f59c79d0dccdec4a92a127e1c10f
-284 1 156 \\x76e1104ccd428c4d0ae98470ae5e3c2f829a9268b30c60b27ded8d40dc1e4ea000eaa529013b7a97f111696f10fbb4e55afd30892c3d4f00669ae5c9672aa103
-285 1 106 \\x28b6d64cd0d795beb1aea2b1d4f16d05a059ce1a9c419ecf71d40ad8b51477becaf7e79ba7115ed8ab257020bb415fbdcc59701553cc0f10bbe9804036bf2208
-286 1 138 \\xfe18a34b7b930797b8a48ab19a74c730e1f4603d65b7dafdfa81a110e14daa80ef24ad6edfa5a9a710933bfcb5819275b8f9ad9cae29c56c9dd1ff4eabb78809
-287 1 30 \\x9b981ca93fb915497da6a9ddf6e1e803ebb10e6d5b1252c7391d6548ec26fcadb7575de66e560c24ff04556f84d43881a00c95737cc49600508406e83d49a005
-288 1 322 \\x456f0d29e6130168daa14402ddd7c10777b4877ef7dda6f5657b419e716a0799027db4f00231ae9181112c7026ace4bf75b796dfa0b0785fd5ad7835bfab2d0d
-289 1 79 \\xd7984915f5fc1854f23e3342ffe1adcb39dea891475cac0d133eb89492c1e4bc0d91ac39c3be64acceb32aa654f5d01f90257a92a942b6fdea3dd62b275a5f08
-290 1 358 \\x51853ca5e9362996b48b60e192716f61267bd41cc9d750392fe516672c0e347e087f4e440e426358c3b71d1a00c551f974f85d1c3cbf956471676361390bba06
-291 1 53 \\xe5b7a07fa456222ea0acfa85bfcf271d2bf428137c7142b86bc4a415d564452d3c68f1ea94835a0f3a115fbf7ed1c2137c8155a581dc34f284b707b8d0e2f806
-292 1 269 \\x442124944b526afb6b76295ef52bfd2a2343a3fc428164695afd3b24cfc20482a643e53b0876044e4b4ea0cb5d6efc7ff0a960ffa2ec12a7715c3c6a3de4dc01
-293 1 352 \\x63cf067e2df82988c725b8e12a2f4fb5bf8782b5df516dc7b0cbc8f9f4525f60f66915d1c7c247ad5a07e9d54e3e20daadafcf0ac997eff7f3920bc81a5bdf06
-294 1 100 \\xffb71c392d486bdc68e118e3d852a1c367a491b37130eeb43cce72075d932fe3559aec4e19ba43b1dcbb2de26fd7f4f4a93f5c09f16ccc9a9896b989f74f5409
-295 1 377 \\xd4101926aafe064d1f7d4c1e7f23033b990ab0b6d2c66f65b4d3ba4ce18eb8aac3cd5891bea3511867a724990f3004dcb1f28aa15d7cdb0fc168140bdc4e6a05
-296 1 281 \\xea19e458c8b6d4aa5e4686832729f58208ab9905a63a274db292c1a7241b8aff76e6839ddae5b874e952ff992a68ca88e7cb0657607d6defe6b4bb96f3846a0b
-297 1 183 \\xbf98141ede06fe7c52d131599af67ebb2b1997dcd1ef8aa9d33e69877c85cd6479db806e940e2cc5bbc23ce3b81984613b2c93f99a9de29c1ee21f7e9dd6420a
-298 1 84 \\x07af707113ea842c272f0b86814aae5bf25b7fcf011d557f3f5fb75be29ba73994e964a0ea75cebee6adfe0eae7dfefd129399ef22dcb4504eee9fe31e3fe80f
-299 1 416 \\x12c0bd0301ad8be33e12ab139cf5893f7991f82ae75e18c15b309bb0afd989a6bc0c0d413264e62011c6b4787031cb1eb7ace57d730285fa68e7d064e0c45109
-300 1 258 \\xcc0ac0be321c2d1112d42509880508f0ee86d0b5e41f3a29417e4823b7b55fa3ed80491989bd547ad8e131d1830fd19dbe462baf3f50fd77bfe984b31b12b408
-301 1 227 \\x5b2a4729245a508c6ee61cc5efde2f1540a71f6024713d8daf2d9605b31434f23f4018508046bee35c943d468b4f31157e611178297336d8fc6128e5cc7e800d
-302 1 392 \\x88eff9de0b46f273f030ee6a2c3016a8ba32c80f4085c58229e78811b2d6d6535e45d88b3896a54648425dfab96a6f9530819343e3b2556e5c3d56ce7f5b0208
-303 1 321 \\x5144d2c80a01f80b2091d0a2c27c60e01423072e2fbe3ec92e2cc69fb49921781e825ad51eff184e5c20707a8c69c89796bedda5568908ffcd93f15b11f8f50c
-304 1 386 \\xd4ee25003d147afd10ac8ee7ebda4e94e10e139e7b806aca4d0f1bcae5a9cd36c8df649f7994c8cae4ea5770f6a348336ec0b3d54e335a25e0cfbf7513a83e06
-305 1 244 \\xc12210f22756718c34d329a5123e8e8da83642ab95e035f9e0e61ade35a289dafb2c13dc1914be06e3b07792c718a0fa08cc8b1a9f49e3ed46078a7560750b00
-306 1 157 \\x431b8005009e313e6a1823e60bf9342bae0251a465e9ba32b215b2e011594b04a68405ee09673c6abed572c158a78bf32f13e6c9ade394a5a9745ee9d8627d0f
-307 1 366 \\x8e7a74aad26ccb12c777e144be555311c27d39822da80f508f3b7b7f323b7e0cf9516611c8219b9e4003efabae7a10dfbb3c68a00ec830c57aae96d46ac44a02
-308 1 307 \\xad7959781e797e13218e34734ebc2a9819cb7843a57e218d814293e92f75314422cee6e1ef63d7380ea41d7a1e8925ab9407ec33987e6907f7ac25c330cc6d03
-309 1 345 \\x80ce6282f1c2a5cf4d7bfd3935fa0a9b5999d9c269867770f7b02a585da3297da58f2d3a45efcfe6fac79112984a0d75a4aa644951c2939821f663e223f3c501
-310 1 41 \\x214d62b874c8b269cffbbac072afae678dd634e1770abcf7d149c747c673a899d29916ef8d831142125c1d13ec900ec40246210ac68ad62aa0dbc700e6372306
-311 1 199 \\xd1f8c3be2f07be7f5368bb683c07c204f53baa14ce190a0360db947721a0e790980db34d11c8e4a45695de31f1a66feb0125e9de1ab4392ae9f91d0fe2ed7905
-312 1 87 \\x8b741d8db6da808edfb61215a914ebb8448cb99cbf6782383b73add5673049ac3366b56c0a1837deed00bcde1e2256f89e141326569b4233366bc8e939c01306
-313 1 181 \\x2ba7ee89f9640c0420dce34aa219d8f479ee6332119a5e88edf82ffa1bffdcb3d515ee450a6ead918ec106e7c2fc7da874bdc34c41800bbb86d0087b21e4f60f
-314 1 130 \\xccce02bd438fa6a1592c770ab3f33166f2697c1ea40c10853eb398eead6ff746aec03727fa065556ca723ad06492d8f88255df77cff82c2b83b56419e054f500
-315 1 379 \\x58c8b9ec5698984cefe6ac678e3d4642821da11007ed65174ddf3024fcdef9ff0fdaebf2294e177f89504c02240f16752a6e4b46cf512b12344c1bfbc59a0305
-316 1 376 \\xd07e79be9e4d263e7448b95123d50a6899f4eec24d8219430a2594822893a6da493705f4ebd019486b4e359c7742ffbe40802bf6cb186801493db71281b8de04
-317 1 256 \\xe3064ed238c47543ff09ea86a1ab2f04d626e9c3d90cb4452786e30335ef666f81a9a9e5da77ed9977c6b989169c029b12a2c02f2b838579944f93f4dbe93201
-318 1 23 \\x384ad1fcf281c717006b17aa0590a492987a825ef299218be105e2ac2ac9326a5a9882ff0a4967ba13348cc0ea935a16cf85caa2bc4f6585fd254340ad49700f
-319 1 66 \\x49903072be2176b63a5719c1f24d831de2e3a4f96dbb424a2f14576cc5df5372c1f109a5bd3a423635f478f6c69cf0e868b36b79c6ef2b4656c65a8603f3f409
-320 1 302 \\x5104c70a897b3a46148abf29ecf2b4ade07cba9d3ea68949b446a3f82f0a0c47ec28b5f6df45073e042a13d3bb56df7f77ee84c078c747919b8f8fd6d2804e0d
-321 1 134 \\x4f21d447088160f68cc625a20bd210c9356bad157e9c6ecf87259370a354129ed9501ebdeafc7a6b5b330287767e81009bf766be4c6c938a7b32438399bc7e0f
-322 1 6 \\xaa9d3601864fbc2480f25c77c4b33081461915d14562ef4bee64654fca0091c10877e8e18623ac6deec772b9db329c64b62d5d9caf916ea81b968fd28c4ead08
-323 1 185 \\x5d05a74ab871a83ccf7aff02f43b5177fa40a440f925987be95a1a57c3c787f1a89745a647cdd4a1de53dbe4d13568ccfaaa6e449726607710af6c5fbbc8e102
-324 1 56 \\x7b11e4a5f41d3f5f97404b56c38491016c3e9857e397338e550ed004c259506a424239650140049dc38e2844034c3ab7563fbb65115678472e2764e5a7419305
-325 1 47 \\xc0740fabd73b453fafb34b9ac98230dba03b9092facba4642dedd891b9836702930dd98bafa737b8506318d9c7abd7fab19c9becb4a2e6d050c2fbed507b6809
-326 1 67 \\xcbbe78c5cc5856f022237031288ef1e3e60ef8293d12671359c9714e18d440abf02190ffee5d3ab79c89e7f7ac10230a72f8b15657e009989f0244d0fc40fa09
-327 1 274 \\x95353e6e6244f54ad459bd3e14ed90b96fdb3f95118fd9dbeb1234ed77cedf5a8bdb22aa52f0064600e4aae65d51f40d016123b096b9dff8b217f8d454fde303
-328 1 97 \\x63a30a0c0f35357afd94ddfd51e894753a8991eb1a5c9f026ab4882537f6d4304959bff02bd99579fe4371746ff5a740777bf2309060380c914496b452fb6a03
-329 1 250 \\x3050adc3b292376dbd056207bf8a17f0ae32915c0678de25c725b83e0799b9fd5cdc455e321e4248341cc6da8ce7b87721aac15cd92bc5684d48b52554a5de0a
-330 1 243 \\x702dd149777a690ee7ad1c4eb963330b649c1c6f240e40329e0acf6d88d8e779ba6aaa85d855a96553579e34fcf979c22165137bf05770d4f791d96143ee190b
-331 1 406 \\x3921cec0d38af6c1c8c1586f201b74f2853e1fcd1f6ed8ae67d8ed24ace1bb852995c7680d0fb772e3fc29d2dcb4c906988e6c77c0b551a42c14a7664943830b
-332 1 73 \\x6fd37b2afbb25b06671aff5f88f07b30a79563170f588de5ce8b0feaf140298d0abe6987f0b9fb515fcfba341e1d5024ff5485cec50e29b44073c0c88aea7a0e
-333 1 74 \\x50c9af51fcf6389dc47f4164980755da6cf3ee9639d1db68c2798d3f5526eaf6e4790631a362abddcfae8e9094bf5db5c9f2aa09905a0aaae2567a8d7310f50f
-334 1 159 \\xb4464fbd59388f7366bd0f65555abb13f65b9dcb00b58e0e58ea7bb97f23f856027eae040b572742c6c9cb8b51bb229d436d2fab4ed13e6bd9ec502675eefb08
-335 1 143 \\x7e04e5e462769d6b0153d18b9ecc4edef0ea7daa0cdf411c0e4c90133b5ed63e3f7b0d5d5c8b9201161427497520b8fdec3b55dfbe1d878487c3ce3b071bed04
-336 1 204 \\xfab16f1080703211bb02e63948ab4d6c4312196ec0e0330d73b4f28d854b4850cb6c0d57b1727521f8c82ff10f560b7102cefb12879cf90e3b08aadc5d7eb407
-337 1 51 \\xf515e6e7e682daf338ad4a4ff70637ec6c93bcfe11e67b27301ab7d8f296456e68ae1c09a03ba9aa7076309a6c953a298d1b0e6ece798048ebe1e84cc97b0109
-338 1 25 \\x3e5c96483dd162658668832a36410874761a3f4011ded6bc198b9e09e9f7966492b00928174f6c3610ac26a24309cbee2e702db3b6d1eb382fc677c368146806
-339 1 303 \\xbaa47e1b0a545ae8711e161d1effb46890b3c25793360e76e299453849b13aa2d80ca8500d50a10e1e289225db29c9b10cfd2503996319e3216726bcb53be501
-340 1 255 \\x06e5163299ef0f813cf244ee53aeea00212cd348a86e665450ffd7bd93a209e82e91e913d891dec2f1355647cdf38af1d3c82d4112f0920be52b26b26da9bc0e
-341 1 261 \\x0dd58876c635f502ac342df11a7cc0bb96a2e99c37735dc942358997dbc136dac9def39964d13f25f5b8f0275fadab7b716536d22fd5fb191e3b86320945ad06
-342 1 197 \\x20161e991af095f17d4b4b337a65176d8ac18e40c6ff7a7920efb69cd6c42f4062c8f73059c1c4fb288b0bf47ce34d2712234e4b06817f56c3908f9e760d3303
-343 1 72 \\xa8c29d53927b63e4d61b2c63b3d98ea84493aaaaa584e46fd79d6a74d707c22c791558480e08a1bd20c8082a289216ee64f0648cb18c26f5a775786db8b03e00
-344 1 94 \\x2b5ae2469dffd94e2828611b2001d7c04b031fdfb509480b011d469b53444b5b64be622e45dc2a8e63f88da4dd16bc4a6e6a29c4e0464eccb87e15fffd08e800
-345 1 294 \\x380650e39181c5f200328e0133521d71d889d5a32b0d4818023db616047086bf0b67611f0ea7c57b1547643ee935df964d99ae5a64851c8c0628544dcbd2b609
-346 1 114 \\x36b98733f644b9059cddbc0bd7fa869325220a8095a693026e6ed950c89faf1da7f19f9f6d2a46aba75355e0244a256d687a2b7a7c573f027f696ae55a51cd0e
-347 1 319 \\x316d36152803ee8173c369fae7dae3b07cfdfc68310104a94135c62e3611621dbcd9e6275b547de16849f0b8ba9098ef1204b703cbccbad6dee69037bb78b902
-348 1 354 \\x914ea3e551ed9cdb4b527c1dbc9c105c50333900316fcb2852b257981999117b11b9eda025831eea474da55e33ac48a512ac719d294edaf66030fa80b979e60c
-349 1 362 \\x88a017958552c2132aaddd30e2f1b0cc1bb04c8c5b9101505564eefa5b26da09ec528ad7fb40ea1c42bf29e06a3cda8b53db5b4e9f52fbd3830fc90cd5fc450a
-350 1 124 \\xc0f5ef7935490a0f1eda9ff13f9e8a1b8b9f2e25028e43f26494249be206111e6d39ac2db04a15c3e25aac5a4ef116033cbcf52ec97f218ca3fa58a906ae2902
-351 1 135 \\x519cb91149dcbfd07a1872624c8cab7c1cf3952bdd9a8236e651971d5c998b306d8567ac39b4a7ce38c4af02f3b1e95b1b6366a260c24ec4310d93b55b742d0e
-352 1 374 \\x4c23e86fa586dd5be96991517ad5ebd7a7c61ae5ea3c7e6bd031bf3766de3a2485f0e852265142647782bcc532f94cd347699cd33dc8ff4aea4a2fe3fbb31a0c
-353 1 206 \\x620501efb92cee67bc6f97f8e376c424275ebdc8484528993fc199d18bd45cdf1990eb1acd69917628110a452ce50a1ddfd577089c21196e2a832b30e482450b
-354 1 301 \\xfcbbe990d25f48249f5a96b9c3612416fdce225b94de54767aacfb71882cddd3488fd9972f229ef2f6648b81e018353e0489dfeb781a604b575cac1bc009c80a
-355 1 290 \\x81e7cf743f874a3cb7754597474aa6d34faef6e1ab20be269578d3efa2dbba32646865a8bc73057121b6c24ead5345145f2910ea4f5229302df3191b779a6e01
-356 1 350 \\x56e38792aa8db3dac1e9363c071272f3930da193e407de52d9004e9db22f5c70a014799b85eb91b119f9390415ce43b8898ed4b456955a4cad69b8f03ac1f902
-357 1 44 \\x990579a4139f5e20d219804648554251a78eb7591d0f3406280b39f420f95fcc55794ca988ede63f93a1587f43467d02c34ca3bdea39f6ab1f77182a73bc7f0e
-358 1 27 \\x34965485838c6924325bf0935c47572fb0639c7c0964c6ae2c7dd92ae66f5087b20a3a964382f17f6b11b389fd7606013ad5a7afd618f91d18daa7a80a65f301
-359 1 98 \\x35ec0d7f07267c7d3a3c7c55da9d49ca6e922e9eabadc17c7da710bd0d13232506ebef33ad675afe4aff7fa097cd7849c708a2af892d48ae39144229c95c5603
-360 1 330 \\x1ef795bd43d1f9242b8caeb633558b158c48dd19fa0d08c00b4aa5ff47a3dfc234f2902aa91f509b12267c4e473546bc5abc1a1fc646b5b969bf729230931601
-361 1 149 \\x27079af179d874e1789350cd767dfe3cf494789862f102629df84c7308bdb4937c553d3d930d0c878a6fa519ce6f6f89e6ccb750cdf17034faf6decd32c1ac07
-362 1 405 \\x5a7670da92c3534b0a37be51dc1456aff393d18af3fcb62d44178346909ad04998641d97669a86e7af40229e8a446e9f7f0ea136e7cf52478a825585b4d36206
-363 1 111 \\x7d42479c7ec8c3cd2ef8bee1e305a7628fa502876ac74e2a9e49febe5edaea4c706cdaf93d7b807ce58313aed953405d998a89c49e13b62b02142aa1bbcbcf0d
-364 1 90 \\xf21f5baccf124d380ea09938d9b29a363d5599dd8cdd4c341ed295ab97b8cc3223e0e5d426f4e9db8238a9f8e0de5f0f66e74da8a95b934c494f9d72c3c13302
-365 1 176 \\x124d6b77a7755d30ed5517745a4174c41b637ea1dbf2f16aa6ae920ec3077a9ac632fc82fb70cc779d7d9646d7f4d783a30aee11310100e4184da095eb82c90a
-366 1 412 \\x7adc7ec3340f7ebc6ba682ee52c3f27671d636bfe4bc30859afdeeb95f77f2cff8e531564d917b5421018bf2d4d65cab14085dbac76ff76cb0ace23941e56505
-367 1 164 \\x87fd4b11bccc608aa351ae1a5601404d819a102134b6a9aa9302d41437d793e5add54fc30a3a550868063f767a48176a86647d44cc1d08a8838d7a75a11cb302
-368 1 393 \\x47543ee189caea6c3a67119c669eff080bedc835f2117e4a18bf7773e87d3855a1b1d430ba257b8f0b3778516c8671960590754ad345637ed95e43dec5bd8a07
-369 1 390 \\xfe9b6771be73f129b8f6527d209d548c314c08ce2dee58531b205d91f014c3c496ff4ea110f169fa1f9b5351526766bc8053ed58377f0cc2d9eb75cb7315ec00
-370 1 407 \\x8cdd73bd6a37d1309724c33434bbc5c020fd962ded33e955178155549004241c777c8ba11b490fa2bbd52752fe6b21a9cfb10f4a3b2d9134421dd0b1760bff0c
-371 1 59 \\x85e1aa6cb3ef8f895ddf2a66d3b161395aac9ca788fdcf8a7d7a494d4e5820ae1b29261013a83e427e0bfc8224ce1d241be4f2cd3fd77e6bdea7e0b4cff6da09
-372 1 297 \\x5817801f1695cadf45eaca931683cb436c8357fc7f4e74a3b3a9580d2e71145274d3d3c056d6d264c890f6a333560dd4ee078bb06886f74909369f0dce2da300
-373 1 420 \\x9d9f64e41420e660a5be3c84732e3881b53d9448475f0854cf1c84d4ee05a9e297cc3f31c4833c2ea81498969ffc85d4e65e4c77ec154346fe0d0bd9d7057806
-374 1 125 \\xe4eb5ed671059548d6ad7354fe872908579de714b08e702c063f1e7398fa70d042669f1dbeae0dbc417ab9997656e88218ae7efadb8739b227a05454450f3004
-375 1 34 \\x4c2e51a767bc585782f9e584ba9af152752fb7fb6e71f2da2ce2228ea66fd94c9c2de4b54a65cf2e8c00d1e653dc6857c7bcc7bea689f679aedc3165f443ee0f
-376 1 191 \\x224f8e7287e9c04cdb80847c7ecc6d3be9532b5929043f6d772cb3f1621aa01a61a187defc0fefd17b847a756f4a5df98097a3c9a342d2bdbde5a0158cf4cb09
-377 1 145 \\xcf3c64a78709592962e6e88e8fef5d58b9e01745c008fc3266c04b0ac8242b93d1b21dd34d252160e07d81a352635ed99047dd40e705d2a0a6c09340ebf1a00e
-378 1 286 \\x77f3c41856177c36d7a5374377de702b65e918d6e06cb2465358fd8a7a919c840cbbe55975586127a6217a7a27b8c4cbf692451a06ff1ba8764abbf116a13b09
-379 1 115 \\x9794b221f19c71b8946ccd862636355769517e9feec93c393c7095b1ef470f77b716d46571507fed4437a4bc20e69df42e9d8d372ff6ae8a31bc73d897e4870e
-380 1 195 \\xb62e23af716d3cbefc95cb93d455988590221015eda5bb913c2a96a65d10eedc0daec85e7eba524da31ca4b05158d8d255eb62ee7a20e16411557c7bb8b66e0f
-381 1 162 \\x76ae74d7a44fe39bb2d5853430222bb2c0f62eb0b018202f777e4028b060e095a67536b0a677ea895cc7d9898eea22307f052ee1b602849207963448804bc70a
-382 1 364 \\x045934e0100b2e2457b6f5d451314bb8958b8529312fc4835a0b1d6646c731e8b879c3cd4a7a306be1b76b53c8eb72badaffdf79108310360423436e0eb7450e
-383 1 320 \\x61ee769a37161f445fca8073cc041ca51562e9601711e8b53683468a25f70d4242c499c5a142fc7631e45aec81e568e2d4e68dcca79e97f8c0559d8a0204e30d
-384 1 38 \\x65ed6f7110393f91fe4ea072f290cb52fcf0dc8bae250b9a269ba1eaad5531d58ad56c8e72a3c0f1d2101cfec7b8af7e33f9713188862d3c9b81fb98a6e9420f
-385 1 140 \\xa704770829cd36d0e29f949481d157db52482093f5ec243d9fc6edfb4f6990793addeb520bdb5e8057a3ada187b0d305600a4f9222ebcf9bab45e44f3d6d4e0b
-386 1 8 \\xe551e1fcc2351496e124f851da67ced29a2725d5b2633bb0ad69205d91ccd63b512ae8e69ebbe29a74add75f127cff6b7cb5751a8790d8a5390b33384e70c102
-387 1 279 \\xb7b7cd51ea453817e1b2cc27bc112b3aa09cd02080447d85f429a38f0f6e5e840f4e9d3145127218df226ad6b8e6264ef2d9690ca6178867c618429f993e700c
-388 1 282 \\x4aaa78935f3e0f69b5af2741b4a800637226ea7b04b8013531fc65baa05b74cd716df87fd59b69b28a7dcc1d4a1041baff6e751bdd4e9221cd0186394cbc5303
-389 1 391 \\x8d2cb1f92f14d6f8af2a933fe060f3e682f07059e42dbebbad4f02d3e97ff51e9c8eb09467f0ca25615078d47ca217d7b762981595d592fd17c14cf16839790d
-390 1 337 \\xda286d217007bcd45c4399374bcc84d6bc69c47068a83a511a9d0bba1f20d2e1e3e3fc77138e90a8865bf1603890c085b0624d6c272389c4239d62e07fb0b203
-391 1 121 \\x43e0d743d8c4f46830e10691d5b797e6f05fd572b62f0a2117f6bad8d496434a2f75d60711873fe7947d6a49e1408b232f8ceb7626193efe5faedb2400587b00
-392 1 39 \\xb5c71376ea3f9a7212d5f5b07711dbf9a7dd3ad91dfec7d4e979450f0eee212e93dfac6fbf46f58b0a104c57327e1f07ea0143b9e2d7ca1f33911acb36b3510d
-393 1 273 \\x161ea3625978dc6fdb69ba77a26860b6d97b0db5496aa8c789f1ca6c19cb19b0f18364a3e626a0b9c124ebddc181ff54d91b65c1065458541818aa3757ff9903
-394 1 411 \\xf5b21d79b8e9242467f6e65f059c3cd0273c0a9e6310dfa6ec62bbee0f4388001c441c4c5096cb6c15a23eddd0e7a26a946181acdaf8066c3bf113b6b0d1510a
-395 1 245 \\x1d42c457864108ef1d144ea838510d7483efe25a11473f633be13f0d776d5699cd9a22081ff50dfc7ba99f7a12479d87b04eaac3993eec9e9a480a10cfc3000a
-396 1 419 \\x21b1652717aba0f13a1ff36527af92586660f98bfb3135232190ef54c85e724ffad1c77023f33d8953562fae4e9438dca8058dd9d56f1ce4f00fc3d695650d0f
-397 1 213 \\x83d6bc7ab8e7f5362304690d77b8fa61d1a66edaeabd0b7bfbc909595b3adefa0469cc6af7a9b0c8ece67570dae501cfcb180d073122a44d784145e47ec57200
-398 1 397 \\x97c65d3027fcf76484fd3114e0ac253a6023490de15da6a3f272332a85fe47e9566fb496048597846a823c557447025c8ff39bfe46a8fddb99cebcc5982ffc03
-399 1 300 \\x864882fe9eed787f4e5ef1e760b145fb8b51025fa51e3be46690fd389e5b76b0c312f33694835e934449b2faa2203d2dfe33ee1d767d8ac8355d81eb589f7606
-400 1 418 \\x2df9bb765180e50500eabfe75a64fcc3f4a6cda46c451182a091716a065ab188810a9a9effc92ca92529a2e717f39c8c64b995baa39520447832c6ae60cd880b
-401 1 325 \\xb3f1858ed906f7e97f232a914852c7b47d7666e28e84bd97bdfdf621a7bf44aed51c743a1a278c31b6b5fe43f850e68516648de29918eb7696789156eb15d904
-402 1 201 \\x2028d96d96b0eb949774caba753a50893a4d2e9d4a13e7d4af18c53a32df18c294e210ac79caa843c9fcc36d6a3ebb610e73ca133dd2eb4816d0c2b65e44c300
-403 1 232 \\xe80d0b9f49ea50a69f874fedcb04fcb1b3c52c7d97c8fc2844609bc7ea718571c76d0f6aff95cd972c876b52864c4150907703e4158917b34b84043793c78f01
-404 1 65 \\xe8f62d437f851ada609b2628661efcbd37a006f8a38594a20ebe0e508a1af7c7ce05892ff8a1e26c293ff5c32aa0a8d60756307cff47bb5635fa116d86500002
-405 1 40 \\x5ee68bb4fd72033235a918fe57fc75e0fbd44be0df3d25d774b9a061f8523c6a6c4f0580e3063883ef9d45bd10fa3d17a23ceb3724eca99fa604ba64a7867c08
-406 1 402 \\xdd98db5c69d46a533c1cbbd50b6c24fe1f14f556bb5bf3cb88b384cf513c1a7c15392a575f4bb199f970fd6bb1ac7e1bc3af809cb4e552a4da00b4be346c5200
-407 1 249 \\xbd1aa9e5584a99c9975a4e3544a25989dc7db8c1d9b835dfea3f3eb79a38ff63c236263c1ed1778d9b2a0a1fe66729c51d3a547c7bda504ef2ec58b8dc3ff403
-408 1 228 \\x9d13705fb044e66715ba28557e0980230e03406d0afffcc54ed3cfb5fd85ac90e4c2d6dbfca50eb017b15a11bbdfe40d7214cf3782629de06e789f558c85570a
-409 1 293 \\x9fe0921c8b37e8a30a1c73f0ea16d846c57fd5646edd31bbeaf07fc9fc9ac987398d4a53381c8b4e956049c4574943d60c18a2f6dd73c55eff72279525f8f004
-410 1 375 \\x5e6bf832d015008d23d2bda78e5deeae3ab70f662ec4ad0dd5edc83f953144f3749223f0dbbfb5d34039f93dd29156527e81d47a8c0f11f9be85e10a0b979905
-411 1 331 \\xfc34a2c8f858df4017c18d5dd234f6b4b4783daef132c30a81d59159102c5c1dc479e864e11229061d9f8e14a90f4cac84013b49f72aba159dec6d4a674dd00c
-412 1 71 \\x0ae0b44455f76639d3390e60fc33f0d9417f7f3b90e37d2a0de8666335ca4549cc9db95faa32e6d409f79a3d344139806ffbab696ce15f00dd5047863b0e700f
-413 1 184 \\xd2017af86c542a7ffbd1f3d8f48edd9645940b2cdc995e5de325793e596f54fac5e400f3175908d8d097a564fbe19970b78dd8325698ed410375d086cc11ab0d
-414 1 179 \\x217e036b0aff99d9cf98658414f4eea8de00236db4cf7c7946592bc0a8da673cda65a20902d47d6c28694509febdaf3c1f4b7eecd6ba393544b44e49a1cd770f
-415 1 91 \\xa956221672641ac380b4423803e4276f19ce815faf1895a20507fdfc7cfb2c5e113e52372d5e7afe0b249288694dc179826ddfc8ca4d8a31f52568fbf65ca104
-416 1 240 \\x741dc119d67742b3ce1874db544257affcbeb85747501eb222bd175f7fd375bdd93a8d0ca9252b5e3eb6a6c29595d87b55a322a598be923f902ac3995e69a803
-417 1 113 \\x012ca9d7f6dea931d93607f30480e602f24361cc34578e5f9697a018510385b2e80f9a4c9c449d8bb436b1fc25f6c550b7cf202757cff8b48d39f25c22456d03
-418 1 128 \\x0cf80cde478ec592983431ad82c57d0e5faf6cd550a6de8fc0b3cdfe35334d19e81036657a6568a089f45aa21eebfb3a1cccfdd9c839dfdb5fd09996f681a60e
-419 1 194 \\x0c232085373245ec4b689e654811ea78391f20fb2dbd1b8d4547ec31534eb9aa8b1dccfd167d2ce9e9b6fa9effaa12b97a59ebacd415cd3162dd502d0052300f
-420 1 333 \\x156b4f235a61d3ca601cb3d1c917ddcea7ebe7a1316dd7afe0a97ad354ca72d38bb78ced260702878c488a46c21f941cabb364f6c0a0eefab469a854e1905d0a
-421 1 57 \\x3c0de2d85a9c826fad6af4a2c122d706cfae7f837a5c5b59c03e3bed9ed0fbe614983fefbe2d6d4362bd0c6b8c59021959727042f2878688bb0c109c0967a70d
-422 1 260 \\xc13e9ecaf7807cb5c51af4cc8dd1a434e81a55a07ad5d72e908d34412d4de8462766bf31987fc20020b1d3146528486459367c0ff3c6ad1b3f3a1d4e291dcb0c
-423 1 229 \\xdd98db0c77cbc2ee6fb7ffd9ea3287a25782b1833aaa08af31b635ad693b98c9dcd99df4a8c5acae9ea470d65b6bfab188463d4a67408c06ea181df672ed090d
-424 1 77 \\x6fae8111bb410af325f2241d18bdad808a57a05fbc3885c583d04a36ae57e2286cce21ff2247d5195fba01f70fb8b8cf8b4df836d5eacfe20b5ba38830fd7d03
-\.
-
-
---
--- Data for Name: auditor_denomination_pending; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_denomination_pending (denom_pub_hash, denom_balance_val, denom_balance_frac, denom_loss_val, denom_loss_frac, num_issued, denom_risk_val, denom_risk_frac, recoup_loss_val, recoup_loss_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_exchange_signkeys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_exchange_signkeys (master_pub, ep_start, ep_expire, ep_end, exchange_pub, master_sig) FROM stdin;
-\\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 1655640557000000 1662898157000000 1665317357000000 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 \\xafe3bd45c87ddaa6ea471d5a66a3a038269230ff0904d959a862bc7e0b45644d06e95ae4229fb5270d8b4c065ea45ba63a29d30630094ee1eeddf7ba10709b05
-\.
-
-
---
--- Data for Name: auditor_exchanges; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_exchanges (master_pub, exchange_url) FROM stdin;
-\\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 http://localhost:8081/
-\.
-
-
---
--- Data for Name: auditor_historic_denomination_revenue; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_historic_denomination_revenue (master_pub, denom_pub_hash, revenue_timestamp, revenue_balance_val, revenue_balance_frac, loss_balance_val, loss_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_historic_reserve_summary; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_historic_reserve_summary (master_pub, start_date, end_date, reserve_profits_val, reserve_profits_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_predicted_result; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_predicted_result (master_pub, balance_val, balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_aggregation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_aggregation (master_pub, last_wire_out_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_coin; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_coin (master_pub, last_withdraw_serial_id, last_deposit_serial_id, last_melt_serial_id, last_refund_serial_id, last_recoup_serial_id, last_recoup_refresh_serial_id, last_purse_deposits_serial_id, last_purse_refunds_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_deposit_confirmation; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_deposit_confirmation (master_pub, last_deposit_confirmation_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_progress_reserve; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_progress_reserve (master_pub, last_reserve_in_serial_id, last_reserve_out_serial_id, last_reserve_recoup_serial_id, last_reserve_close_serial_id, last_purse_merges_serial_id, last_purse_deposits_serial_id, last_account_merges_serial_id, last_history_requests_serial_id, last_close_requests_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_reserve_balance; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_reserve_balance (master_pub, reserve_balance_val, reserve_balance_frac, withdraw_fee_balance_val, withdraw_fee_balance_frac, purse_fee_balance_val, purse_fee_balance_frac, history_fee_balance_val, history_fee_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_reserves; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_reserves (reserve_pub, master_pub, reserve_balance_val, reserve_balance_frac, withdraw_fee_balance_val, withdraw_fee_balance_frac, expiration_date, auditor_reserves_rowid, origin_account) FROM stdin;
-\.
-
-
---
--- Data for Name: auditor_wire_fee_balance; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditor_wire_fee_balance (master_pub, wire_fee_balance_val, wire_fee_balance_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: auditors; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auditors (auditor_uuid, auditor_pub, auditor_name, auditor_url, is_active, last_change) FROM stdin;
-1 \\xc3a02e84d73f0e68b9826d81596154680bfa87107d0128503aeac7549e703004 TESTKUDOS Auditor http://localhost:8083/ t 1655640564000000
-\.
-
-
---
--- Data for Name: auth_group; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_group (id, name) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_group_permissions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_group_permissions (id, group_id, permission_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_permission; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_permission (id, name, content_type_id, codename) FROM stdin;
-1 Can add permission 1 add_permission
-2 Can change permission 1 change_permission
-3 Can delete permission 1 delete_permission
-4 Can view permission 1 view_permission
-5 Can add group 2 add_group
-6 Can change group 2 change_group
-7 Can delete group 2 delete_group
-8 Can view group 2 view_group
-9 Can add user 3 add_user
-10 Can change user 3 change_user
-11 Can delete user 3 delete_user
-12 Can view user 3 view_user
-13 Can add content type 4 add_contenttype
-14 Can change content type 4 change_contenttype
-15 Can delete content type 4 delete_contenttype
-16 Can view content type 4 view_contenttype
-17 Can add session 5 add_session
-18 Can change session 5 change_session
-19 Can delete session 5 delete_session
-20 Can view session 5 view_session
-21 Can add bank account 6 add_bankaccount
-22 Can change bank account 6 change_bankaccount
-23 Can delete bank account 6 delete_bankaccount
-24 Can view bank account 6 view_bankaccount
-25 Can add taler withdraw operation 7 add_talerwithdrawoperation
-26 Can change taler withdraw operation 7 change_talerwithdrawoperation
-27 Can delete taler withdraw operation 7 delete_talerwithdrawoperation
-28 Can view taler withdraw operation 7 view_talerwithdrawoperation
-29 Can add bank transaction 8 add_banktransaction
-30 Can change bank transaction 8 change_banktransaction
-31 Can delete bank transaction 8 delete_banktransaction
-32 Can view bank transaction 8 view_banktransaction
-\.
-
-
---
--- Data for Name: auth_user; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user (id, password, last_login, is_superuser, username, first_name, last_name, email, is_staff, is_active, date_joined) FROM stdin;
-1 pbkdf2_sha256$260000$0Nk9sFAkUuwKp13eoE2Fyq$Jw6jKZc62NKUM7VXPGXIFfn5GzWc0fkCNL8WHHaRdog= \N f Bank f t 2022-06-19 14:09:18.35267+02
-3 pbkdf2_sha256$260000$imGMIBBxtgJ0D1rfWRcuPc$0IUycrmTq8m3gZktURaiH1vExUfFKNoOVB17z07Y0qM= \N f blog f t 2022-06-19 14:09:18.542836+02
-4 pbkdf2_sha256$260000$2HwRHNH9Q2XC0iS5w3abaz$Z7Tgl2hTW/c8lBkwffGF8TmVFaP5pA0nzqUlHNEaWCU= \N f Tor f t 2022-06-19 14:09:18.637257+02
-5 pbkdf2_sha256$260000$xqHYfHryA5aILKgODOvs2J$S3mcZa8zn92MOMcIceJDGwcHIO4thpDy26eaTjakZeA= \N f GNUnet f t 2022-06-19 14:09:18.733397+02
-6 pbkdf2_sha256$260000$qtWebIwgyDomY1rJtfpvDy$+9givxgn7Uwz3jhxwd4CxdRWNUav6p28VVCnRz5O1zg= \N f Taler f t 2022-06-19 14:09:18.830494+02
-7 pbkdf2_sha256$260000$w3Bisdw8RgvDWlSfxBMM8L$guyILdXtCA3GFuUswAlFLHFAmmjSJcPHx4Gf+1tUrlw= \N f FSF f t 2022-06-19 14:09:18.924503+02
-8 pbkdf2_sha256$260000$37ZLZHSIfXcdl8z80fgcI4$uxfI93ftpcTqkoHTQQgOY9WM7Y/A3iM+bUdpQI0G9Y4= \N f Tutorial f t 2022-06-19 14:09:19.019958+02
-9 pbkdf2_sha256$260000$7P1exzuUkoVqlj9SzWt4hM$fQU/z7JB7uXnsLUg9FmFTjh9jdEb1TZJspux4PQ6g0c= \N f Survey f t 2022-06-19 14:09:19.11515+02
-10 pbkdf2_sha256$260000$meDHz25kyrjANxtbwyjC3L$kj0NdRXEqETSterPnlITygIuQ8vHgzV+LFqXDZgrJ0M= \N f 42 f t 2022-06-19 14:09:19.569582+02
-11 pbkdf2_sha256$260000$eRt8twaL64JXiA9bdg2KcA$4HG4gbyhjsJ3xA95W3dKpJv6fCkHFIl3TjkJCpx3bjc= \N f 43 f t 2022-06-19 14:09:20.024089+02
-2 pbkdf2_sha256$260000$6pkmIymnT7H1BeGVsr9FEe$T37eQLgxGTrOQKikMx6yACGIG/KpkqSDIk4hARnuMyk= \N f Exchange f t 2022-06-19 14:09:18.448095+02
-12 pbkdf2_sha256$260000$0NikfnbYrVx0rLJXfkREmw$Ztk43rfDY8Jz/uW+FucrLrCNmJc81T1xpPShJnMk3pg= \N f testuser-ljgqtzra f t 2022-06-19 14:09:27.167398+02
-\.
-
-
---
--- Data for Name: auth_user_groups; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user_groups (id, user_id, group_id) FROM stdin;
-\.
-
-
---
--- Data for Name: auth_user_user_permissions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.auth_user_user_permissions (id, user_id, permission_id) FROM stdin;
-\.
-
-
---
--- Data for Name: close_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.close_requests_default (close_request_serial_id, reserve_pub, close_timestamp, reserve_sig, close_val, close_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: contracts_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.contracts_default (contract_serial_id, purse_pub, pub_ckey, contract_sig, e_contract, purse_expiration) FROM stdin;
-\.
-
-
---
--- Data for Name: cs_nonce_locks_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.cs_nonce_locks_default (cs_nonce_lock_serial_id, nonce, op_hash, max_denomination_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: denomination_revocations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.denomination_revocations (denom_revocations_serial_id, denominations_serial, master_sig) FROM stdin;
-1 57 \\x5bba4ba907b413a40589d32ddfba3ddb5a76c117b748824cc68823cc74c82fc3f049368d350b0208474d1a5eb5a043ddd2a42e697c797efe519a34cf5e693305
-2 293 \\xede76eb00447c3dd33a646a071cf5688fc2ba6aeaa971d22a7ce32112d110d26c484bd9616f89364757a73814d8b93fe84e57a632f21b853e5129b4d9c977e03
-\.
-
-
---
--- Data for Name: denominations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.denominations (denominations_serial, denom_pub_hash, denom_type, age_mask, denom_pub, master_sig, valid_from, expire_withdraw, expire_deposit, expire_legal, coin_val, coin_frac, fee_withdraw_val, fee_withdraw_frac, fee_deposit_val, fee_deposit_frac, fee_refresh_val, fee_refresh_frac, fee_refund_val, fee_refund_frac) FROM stdin;
-1 \\x00683800c64d9cc02dfa7cc066e76414ee93ccbb1f4b9c723010e9a3bbe19655bfe1420d391a6bce0ef7c842104f53473a7098c531804d9460d255db8321134a 1 0 \\x000000010000000000800003c542eaaebf3d5e437abd0d212ca29a949a154eb7834037cf4c6d26385d80086f19f3262d9a0912f7eac7ef29524261ccf00a107c20e732e0cc5772325ba74e0dce34d9b059a5ff1906e597f0b0742ae0d9e718670e48bffa98df208c3fd756c9b0218e355ff259f6c248f691050804834aceae08ea7214176e10f3bdb8bf8571010001 \\x6e0a557756f303b694cf123ecbe42811e310ec2444bdffa024dbc88f3dc51616247ebd1028fe5399654d3f0ce4a26e1478833851dbae3a5878110ba528de2000 1685261057000000 1685865857000000 1748937857000000 1843545857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-2 \\x02b030c8ab8a7f87122167163804a203dda43d26608b6e578e85cf2f847329ebe2d6cd5dbc542b9e1cf18c7d63cbf998ba48788b2e45503ceb03de39927aef11 1 0 \\x000000010000000000800003be35babdf376f228e6f185fb4c2c9ffd454ffe44d847afae5b6a52f906a932901c57d9775e2e3027c0983d0a920a663252ae4a25d5283c1a68b800617472226dba56c1eeb88bd0f50d14770b0995e468fb7eebabce86b7dbcca31570ee736a2169ef1f6ed9e75cdfb7efdf47bd1783797970d1adc3b17c406ec229569c3d0961010001 \\x75fb6255f65e4e4d498ed98fcebe2f4d4a63ef76d6b790c3b1a5d8d40324a562d441fbd3c9e2d37d4e6a61fb5c4ce227c1c5e6a5206e85fd7ad05cfe9ebb6a00 1685261057000000 1685865857000000 1748937857000000 1843545857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-3 \\x025807bdb4caf718de80dfd61231b0898c27044ad7eab075abf9a4c43f0d49247cd18566bbf9da208801045890643b41abd020efa03be1a166e64f4c6a1ee1c9 1 0 \\x000000010000000000800003eb664840d1c572a268af0bee7911e5e65889488cfdaa518720f064ca6cebad6279c098dae6825c214c4b0aff7ef10d25e543f163a757ddf814bc9120fffb4e5590fbf35f16193ffc72205136def7e52a020fc3f201e92a4d14ba87115337102602b8d7d78e9631bc7c5f2edfe1eb4cbed069c8762dd0a3afdb1cf4fab262da11010001 \\xee2608b6db91966650da32c41b0b4f6d73759946a9695806e731da8a7aaa43127f054a367fc2f4ac0fcf21e0ffc0d3a36b7049d8deab4c7c7f30ed84f7b7b00f 1670753057000000 1671357857000000 1734429857000000 1829037857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-4 \\x0df0c4fb49f5b3f8803b54ce52f216968965adbfac25f874ccd443eeb7d4e5271bb3f3c56c98f3f3aa4a4cb49331d119fb95b341db626acec9afd357035e131e 1 0 \\x000000010000000000800003bf2c08b2ef2c0693aebc00835ca12be769fbe314826ecc052c0fbf4f3eebf3bf6fc58a1c1b20aeee77e5702a9904a62abca58991b8c92c754dd6b03a145f3fe475f61ae4572213163ce3499af262b69de8a217163542e0074a32e47cf9ff254576878d3f17e1ca75ad3d78a8a57c5d19f3d2cf97ed30c4ed6800914e5a03ac71010001 \\x61e484cb315c873be7a16139c531907eb670224e2843e2f6a6d3d57bbff5952bbf92961f78a89e6232d1cfb837861e572565aa1b64036895565ad2715fd60e02 1673775557000000 1674380357000000 1737452357000000 1832060357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-5 \\x0f6016178cdcf9c0ab423ddb2f79da4ef4ca33b84193d482d1156cf29ff6fc04b344d0a368fa4332ae480b04c04c284cfd67f5de46855fa4378ce20e6ff98fd6 1 0 \\x000000010000000000800003ae7cb164293576a2bb6779179f28b3f5b5ffcc2ccfe3afa475a7a18f27d3fa8aeaf8b17270b04d9c94dc37dbc89aed5630c7ca4ce88282341b1fb2a00e97dd017e949d5bb6695cd3a4746140418ebb7b43ea42c268fae750824e8e3920148d41e2ce1fbac431404b6790aa61f89f35f0b9e51435db073890ed957e2e8cb3c8fb010001 \\xac0f0d5e7ed65edda9af2f5eb62ff5b04b93b5e74e5c4a2e821e36f852f14e99198aa842728011a4f02905c987624e84032871f8f3e55c7d01bf6fb4d45aff03 1668939557000000 1669544357000000 1732616357000000 1827224357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-6 \\x0f2484ffa37e91614d9d3af00bf570527c7cc948e82a7fb7a71d8ae19b246d48cfec5925aafd3da70414cfb5eabdcc1f462fe5d53ab95536e8c5d46fda7d3425 1 0 \\x000000010000000000800003cd9dc84b2060758a5d7b253068ae149abab7b046f5c96d8fb9a273e8fc74cfe37e0c466ec4351791dbadfaea0e7a7a31f02fe1b1f3755611730ef43fa9f2f68dc44b9a88b35720e2ded02478c2b4d521945ca936bf5d8629527db7e6f587b6c88a2ff0eccd864180444d56c0d0dbea536a237268491f4c379fc51a952664e059010001 \\xe2837de4378f8fd8b3305d91df0bd817d37206adafcb524791d76f993770a81204351e3e5d506d94bd88e104aaf945b8f142bf50fdd4a896643ce2accfd07101 1662894557000000 1663499357000000 1726571357000000 1821179357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-7 \\x10781b1bee9d3fd5411243b5ea03bcdc9861e9f735b62049a1aa54088d5658e60e233b7a809a25bb8cd6acd4c022baa1d390160d4b4478b85c5aed2472d7c636 1 0 \\x000000010000000000800003bacb571fb6b6dd2d7c9f78796095a70f2e4788dafba78679fa75dab230ba8be71a0737fee389945dcf5464c52f4014eef734d13a62685ed9db20e6e6411dbdd0c46c3f51358fa51be00843b0f6ce4d1257c35ebbb2a36ad275f763601f6422821abb858838bb567131a70c09198684060ac1d469d45a68698c8fa397210ad8c9010001 \\x072771665de823382fc68cff00a28be9c2856a4f50d0d1bdd6656b49f4dcd1f06a51b56108aa0a7f9aec0d465a149977f413c9165488fe0439333ef26f41ff05 1681634057000000 1682238857000000 1745310857000000 1839918857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-8 \\x13b41bad97620b4a00faff63061398451033df395a2fdf37a5df7d833fa04d4f8ffef858c6632138c993c40c083f4be57af4ed8b2f1407081e5ef643a44e5bdd 1 0 \\x000000010000000000800003c0f83259e4441ac28a695992021b4313a31221164fe11e3818a0a14d2ad88542e84b52853079e4519a676e209e41515adf27bf530598cebdff4b39b184aa16e4c6edb988d7e03363cf4fbe3887fbcc38879d7b2e300a16d8ae9807cb97c21ff9bdafcbcbd08b7cecab0cf3790a6cc14e9a42585f21b272ac53ff48febd0d9113010001 \\x99f94cb27ce85a94da1522e79f658c186063b171bf7834a0ee41a65a5dc6bad2ea0cc171559907c4f743b7730308c79dc6031879d0b2faf8cc9a365e6ffa390a 1658058557000000 1658663357000000 1721735357000000 1816343357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-9 \\x1724fe01d3ccd0353a77a1cbfdd33a3b13f7b7651099d02521171412f369c7076579d8bc31548f6d56d800a4f2ec80d3b58a87856969768d35b8319acf0ada97 1 0 \\x000000010000000000800003ca1b71fd768d2c98d80ebc9064f67d4cb28e20b2c72b1615dcf482443737dd7a86ad504c971afe2298eab047368ab7e497d7e383aaad370a9a9c3a3bb91e400bf18e4550e318f8b4b3a93a76eef5c019288cf9ba40aabe3d74fd3c98514ce5afccb98b31ce9cf7a3cfb9bb7d5b8d1c5cb2fc60266b140974c90bbf2f6bebc585010001 \\x4e7e5ed2a62b8be70df6e882b97a7b843b8306d47712c885178d38ff9dbc1bc4422adda2fc4020878ff681787074154c7d7123ffe84b354d7f136ceac1764103 1685865557000000 1686470357000000 1749542357000000 1844150357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-10 \\x1a088e43ac30b7761737bce9c393643d61ef72913d32d382cafeaad6942e2fe2b7f9c6c4b68da208ba1a3b0b397feaeda72963c1f236e53b06125c44a0681c63 1 0 \\x000000010000000000800003b2be19dbe77d457da569c99d120fec32017dda2af1d2c68ce5327b0c2dda51f369fd2822c20c87e733bd8caba61818ad38b9ab7eae2a44d6c358935bbd73a3c7b2f68d96274756f8a41b14cf4514a77bc8c1e19a45251b5a8ce5a31b725f7370c5cf9df9c2004789e80c0a98c80caeaa8e593ee40458783580e4177f62027ea1010001 \\xf9991c8f50fa9db6c296f22c86135fa56b47fa3bfaa307d8820bf50b7658c355d112b2bc169532aba52a2846382d830c1214aa57922080c04fb923594352af0e 1687074557000000 1687679357000000 1750751357000000 1845359357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-11 \\x1dc0f4adc0de41075926abf65657a27fea7213ccbd1d676341f8dc60fc1705ed34fd3596a184bc418d7a555d83422d27e8f3b256273283336f63781a6c6ebd78 1 0 \\x000000010000000000800003b51ef13e04540bfcf78f78127cf43be45327f123e3023b257c1e305bcb47f797478b557440167e1c9494c4cbbad599c274e51ceb6f5c3ec048bacfdae870dbdebe3c560600086c3e79a3887dac97eb5cf0183a898065f8f98b419906722437432ae651b71c139824eac08951033b2d76a6a7cf9a712f9d6cffccc2700194a37f010001 \\x3d2d151a89433ba68a9af882d7b68fc50bc2fd9de89a76ff0d8c1a1c71424aa96eda88ffdbc376b744d145278c79e360a136a6f55b2aa8aa7498703652cf0a07 1678611557000000 1679216357000000 1742288357000000 1836896357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-12 \\x1d605e35de0003b5a9b95ff9df58c40b021b6fe3d4e359f12653a3d1720dcec1586bcdb099c937837c499ab8f1c12b89ef82b3993ead7f1493002863362a16e8 1 0 \\x000000010000000000800003c15ed2ee8a170357d68fb0c82e782786806eefe0ce866f9e73b6c0323994e2eead4eaf7e021855cab3198034e7e989d308d130cb4eab0497d98fa4e4ec11c9fbe853f92c7101eac41ad3aa0d4373f1fbe52bdfe862964b8284af85e284d11dc9edbba2e9df35f378d79b68a4276880e7420901461b17a7203170985efb47134f010001 \\x241d13d0ed143f659a816b4fd46fbbf64d550d53d0f019039cf326acb612276f24b89a986a59252df931f174b60158ceba4a0218fa5195bd3bc11d708a6c3c0f 1669544057000000 1670148857000000 1733220857000000 1827828857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-13 \\x1f749255cc2010a30bc45180e6b953bdb4d2811500b33854696abdd0697a863f8805d12ba7fa21c30587eb02e80ffb6f20747450536e548c5ec00920df92db6b 1 0 \\x000000010000000000800003f1d73063321fa3142c31aa6f3ec73e734134ecf191e80e5fc370ec419d1a7fd0e8a0bdc7c9a01558d081f41a1f0203790395ce9f7c78bd76282235f34588e8cbe198581de565a5d9bf78a189ace92769590646321c1b80146554bd6d3a72940e1d5fa2d6edd16a6b483a81eff0ec8d8c73191c75d202248a5b9b29953c9f7d7d010001 \\xad09ac771eba04d666449892b3d93d272b6d9214b7745c8f10ef0d7be491761a68cff1080bdf44bc2cad3f268d5a970c21abd939ffaf0d6adb535f3399c2e80f 1680425057000000 1681029857000000 1744101857000000 1838709857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-14 \\x1f98d3e8601cabf3218d2a1323a39867d3a20cf68796b08640395efb6b6b06062ca0f56d1d847cac65ccd9d5e9f55eb079580fafdaee75e56a0eb909e9f6f0d0 1 0 \\x000000010000000000800003d617123593dfe57ec49d3379231e3865b853070f0932cfbd49e963fd8566d41390671508d4ddc73dd4813a339e6fe7898035c22f38553fe405d5548e5a79e296fc92205a9089760ddaa7bc099468eb4755b3d9eb24f0642903cc907a4d9b43f83f132fbd892d355b58e6799607d21e67dc72f3a6cdbd7388636853c5b4ca1af7010001 \\xf35548d88a62d6aafb0b4c9c2a8b997ffcb47b719db4ed1e2186317c6fc353220298bd00ec3f3bf4e38f2e9b601e3db2e0f98726f395f2d572aba4c81caef504 1675589057000000 1676193857000000 1739265857000000 1833873857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-15 \\x1f48286896cba78bca374dbf7df7d27a202487b506b474679ac9786d130c065f83edfef3f72f1223082d870a2be76e63580950daefbf3cc500a181cc69915aa4 1 0 \\x000000010000000000800003ce1fa693d4f982d3b49dace6f83b196f0ed83264a42d890d1450740878e6ce26eb4e7e649af4adb82f0cb9f913bf0bb8d1e083b04db3c6ec197220460f44e5bc87e74bedbccedd8bdeefa8a5b9b2e648691e6b8b287c7d68281acd10acdcaf41c69983e303e5ab3cffc839433cc2aa9616f93abc105143ab8d9958fcef131603010001 \\x65b19b5297fac83e7bd77c6d37458dd845c2f8680435c10f85346c5f555fb39618e551fbb797a6367c4c48f2e82454efcdb230e377d9fffad41c74198dba9e04 1679820557000000 1680425357000000 1743497357000000 1838105357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-16 \\x208080d369bd9633e2fbd0fe023f9c7b3ef1456da3d497fd3d3781eb262f45b343326ad41458f76c7f023c55600181b811f7f5f75aaeeb8794165bc6e1abb382 1 0 \\x000000010000000000800003cedab4a4afa502419ec999f42155a9e6da5358d1403cdb591956809774396d530ea70f89ead3fe46d87041ed126685d18b5ca8e4cbbe93174abfd60a2680c84e9a7f70e6f4c13d6256d93b8f99dc73a5dda80a84af5b8ce451510135460fd71ac50b482ed01a13a1597be376c1c20849b612ac2735daff69df48a38d95eac3b7010001 \\x4707b0cf83b2775e373d77ade6072898d42f2b1210552456689d5a3d513213d59378dba743f8e2b316401801c07045626935b2b8c330146f8d65bab32820a603 1676193557000000 1676798357000000 1739870357000000 1834478357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-17 \\x2a90dd58cea34e61991a61f9c1b7d020f9194dc337c2fcdd48914e60aa68fa49fc002091c6ca8e82e968c3e5f68082d2dc0345fbc1e06a51d6d8bd5e6069b21d 1 0 \\x000000010000000000800003a8e5ec8b6604724d7cc9c95762c54cde069f3ee2487c60b1ac045a159216e4e74024d4d5284668ae05e4555e542e888fb755045ad1831d3a2cc7b930ae752fc321faa2b9caeccbb07024e16acfbc6d3c8b8f52a3d9a52aab00bbef5300ef23d1b69f48c2b49e077457981a17e8ea82e83e40f9ed92588518439b624199c25391010001 \\xa7ded64a7407bb6af6e626e7d9b771b2e27c1a56cdf126e272fe559227aa8719788a06da7aa1daa5c15e430539a7abe8ddae0e72b5f6f723ac7e5aa10dc56803 1687074557000000 1687679357000000 1750751357000000 1845359357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-18 \\x2c2cec8c589197bdf22e2c8e65d88e33f06e016db689b6051213807b693180f39f35efd30b3e8a7832ff0e89498ec95f9320ef85d66d5a35278000e7aabda3b2 1 0 \\x000000010000000000800003d7658f11733b3dae615e068a942cfa912c12fb2be7bb52536baf8d0ae5b88cceb47e6833107e2fc35110169f24f8136fc550d030e8bd7e9e4f78de301181e04ce7a3665f3f587d208fba10c411947503abdf3b99f28e2ad3bdb824ba42d35e3e77ca9786c976976a2c3cc46c7f41678baf81f0d37d6d8251e092c62e61140c3d010001 \\xa00e055c733eb328a0db42729fb1fdf0c01ccd83c9845326ec312d37becd9c0deccf08e8a5dea0c7058763d927378a890ea08bed35462544e0900bb6c1bf8409 1681029557000000 1681634357000000 1744706357000000 1839314357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-19 \\x2de802d9f3818c9aa8eddbdb573906c104a05e69e146a9b025daf27c69aebe59deeab1fb645ea94dcf9438951358f3176c52122096ad5a255dc8f5bed78dfbc6 1 0 \\x000000010000000000800003bd4d31282a1c8f49d60004221f347fc53c21a5174c2704f05f9e8bf64ddd0454b4fff1599358afada905294f8daa3f4cf407fe08fe7fedfda9f2acd93807b2e2c35731971df85f093a03c985b934c562e89b7cf41cc65a8c3c898d5106fdae7adfbfa3194f7990e10f5e3176c89863cd761f755d10ea068c2aa044243c1fd6fd010001 \\xe63db9daf283643d0535bffe8034c06e653a3d363c7f5f4a75d427697f00e065430e17c3e3ec557e46fba9d2801b0f18241f0c2e70774661d5cf76414064480a 1686470057000000 1687074857000000 1750146857000000 1844754857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-20 \\x2fa8ca5403d0ce2260f51bb45e5cdb81dc992d667e640875a825f424b93a8245cb58392b68a8e642ca6bce8256052d17ea4ba641a863d48b35cd3f16bc6a4e76 1 0 \\x000000010000000000800003e708f2b2b211dd0e3be279fd75586a9272b3ec0814061b79aadf5ae99df168e1a1ff0805b1fe44f709eb029176ffd998e6d17e809b87065a8bded606f6b589ece181c56e1843a53b96f1ea43273917521c44bc76e4347c3dbf2d4964078829976da9eb814de344927b669f99a5c6b3c3c5b718a9e2403007502f5f4029322065010001 \\x3189504b7d5a0fa4c7c4d55920e188f734f0be0fbc78a86279eae51e533fbf747a20da07c539519452280fdd9229c85d17fa94b90bd6a8c52e9ef193bc8d7e06 1682238557000000 1682843357000000 1745915357000000 1840523357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-21 \\x31302bd097a6b7059990c7e8ff09d7d62b4bf8376c2ba7416190aa7765e84913228578945786c2020ae320c8e0977fa48679623ed9bbcbbd079b9306a9a98066 1 0 \\x000000010000000000800003bbcd7a451f5773745076d270c33a3851dde45b08c47b5e254788a495acc202b60a286098c89075644e90db912dbc4d26cc8aba846f3c0934e74f93a7b0a4a91a6ec157a1d8a95651f2730f380b0f65d6a5f0837e07de81d059637ac094c44317e42804a6a1cd3d4e93db3c082cf1cdf531e166a5a1daf43d55544d2553eb470f010001 \\xcb291996066af646e83b93a2cd02dbed85ad0ea1f58f396a8f221e085f5817bbc8ae36e2fd4e7bb2391e4c999947e2f46d2bde1b55f558e79e6a9cbd48ddfe09 1685261057000000 1685865857000000 1748937857000000 1843545857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-22 \\x3a749b0f49e87d581ed7821e01742b2faedc1713ca11fd84a4d53aec79857dcfb5f12ca9994383b97327c2c0f48270b8ba7c73721f9fb724eb7c05379573726e 1 0 \\x000000010000000000800003d089e2432e6c8a84a5d5ab2f9a2832670a39289ddf9778dfe3169bb0b47dd50250e45d100bc6dcc4d37b4308da9baba8687acb69fae523ba0604a9c4b0fe8e5695820315e9106759c38a98a1e7db47d7753d257566f877b773268d2e9c9521d86bf4df7e391dc4407aa70442f09d67ac1f01960a3a41e5d777a73b54b191f22f010001 \\x75ea479655b174dbe4ecedb257777430d9ad5c5957be8e96f90940cbd786d76870f27aa735235bcfcba22062f340ccaa6381e7ee4fb2165b7e226a46658cc009 1678007057000000 1678611857000000 1741683857000000 1836291857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-23 \\x3b54a9d2816868cb2924149cf45469bf8a1d8920ca2e0910963a2c4676128ae84fef6ba7c0ebf72ce113d57bff386ae07c346d9f95a1c5f7cfd92fa7429c2822 1 0 \\x000000010000000000800003c9120895ca0783a87d80c169b2721f6c97cd29411b84f27210caa352edeaf66540963f18810b6472d7f7549df7437c4f66354feb1b2f26af319332b8fa241682ea8dc7916b8a33c9d8e330db05a69cb2476c139ec201ec5db55814a62e02c4cb31d94747f5a786263a7160d998d5cd1f30c0472c6c0b804a4cb083bbab789433010001 \\x73a10e8cc71bc7f970911c12239c5c8c575130b893499149d845bc8b7aaeab30b9dbb862dbd0685042a40c54e0c83d473654ec6eb8171710fca880c37337b10f 1663499057000000 1664103857000000 1727175857000000 1821783857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-24 \\x3ba00608f8fff079f9b4310586a4bbd7895b8ec99f8abb1963778c8b925a2b5ab6579e2f8286a4cd84ac54bce2824eddae0ec6d82b60a95a06e32301fbf944da 1 0 \\x000000010000000000800003b0b06d97581693e4f0e8c97167722bd9031a269f2cf85cd759d5ed1be0d86ddd91eecd5676f5310837bacc18c518e6c7c491d593c3bd86b6c63108e46169d0ae69628fa89be70467569a50da0a290779e48c758a45752f77e46f48643856116d1b6e2ca20092e265eae4b2f5edcab1751be6430f39d2bda40bcd3758d68d3dfd010001 \\x86028bb0421e6bcce39d2109f8ab49027cdd3877bb1cacc5591142e7320b0bfd6a2adec98413b4f352e8aeae3cfe32e9f211f153254e5be56770b4ee20d89b07 1682843057000000 1683447857000000 1746519857000000 1841127857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-25 \\x41b0c503b3dac4c8c3c2096af640e471d11297506e7fe41308976bd577877b36e47dca54d285ebdce957ae818ff1c76559b93e1e68fec7376159b6858de8367d 1 0 \\x000000010000000000800003c76901c9abb1456cc55bcc46e44686e6145a0d0616b1564137be124915eaea1662944475a544201dbbf1775d67fed06c95ca7c19d45552251e5de987d55b7588748b4da6b41d03a1b5b2c966bac3e417c68e182f425d607b62f9c5d3aa7f845f5a5f2acab254f0857c0965d598c28d7292a8c79687d84f6981a8172217983b1d010001 \\xdfdaab9a3b508616dc890f0764d7115e7fceeca5fc67e35a05a099dcc2be723893ee31dcd1bb1c2c178c3fdb65e117cc33e016e8022ec95cab3250ae00abdc01 1661685557000000 1662290357000000 1725362357000000 1819970357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-26 \\x42b00dd5dd2938f3a51daf2aa6e70675c42e20ce1885268eb7647c64ea1e317072023e5923bd12e879cf82a92d55608fe1dcc20a4a62e96ef5bdd250428dc34c 1 0 \\x0000000100000000008000039836bbb68104694d074d2dd8b7e19233d7df5453e099afa93b464da6f7c8c2c55f87c5c39fc5e56e1634fe492e146e10d1e31acbb0b34df7b37f8c43d46c6fd3812d57aeeabd03535e9ec92c1022425489884c79aa47c8196331f160c60f55a6106ef0fd88cb4f88f1466b3bbf9d509b8f10f5153de95f5312c483c1b53cb267010001 \\x70950990316f990f9368c7316844e8b3c141015352aa4573f87b0e5d17e56c9136da0f8d9b5fbc28c8d7d08f75e90ca0fbc0cc6c11b356fa942e5fa58c00df0d 1679216057000000 1679820857000000 1742892857000000 1837500857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-27 \\x47bcec50593acf791807f3045e0923b6d52e785878a87c183d62428f7753410d965846b89e9c7c851847ee4542ae7581edb5b6b99321a70319f846199aa46019 1 0 \\x000000010000000000800003c5ade7e2de4450d621d3bc5685d2de992e9955324a1a3e31c75d56ad93d60fa8b38f754a7c0408b506bf9fb116e0a8f91d245898673a171703a51e05f1dde49e92c449fce113de307bd1aaa7b4948e36bd5e44eb1f90c260c0fe00a1a8a50e67649acc9c1d8a4b2ff041a52e3595e9b1b3c6dc57f7545f1560f7bc7c39205a09010001 \\x2cc79ca4579e426797e1f072322eeb4f2d1aaabc37678bbd0f6651c2dc898a26cbab5704fdacb4422fce77f1004e96e642967d02fc3cf6cf12e47e5dacb3b30f 1660476557000000 1661081357000000 1724153357000000 1818761357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-28 \\x4928316e28d093a5b5012cdbd6eb2c82c5b902a62bbeec0de39b73d2cb46357149230907b98230c770f44a5d8628d08a92a91973e27506433cc69b81418cd932 1 0 \\x000000010000000000800003c740a1640c7ba742d414e1a17d72d64dc0c90a126f86e16061d8ed9b9321041b7f89c3359f13baebce0b8c8892dfc6784ce061e66363dacd6c4bbf7f4078979b3c8dabf99828ec5f77d6a2afcfea006f290711adf7b6949ca8503099c8df164a4a596dc85d7ea8eb3c62be5f2de47a798aecaccbc5cf17ad12e4e08618eb8107010001 \\xe16bf36c8ea6ad5c7f9c8fbe18d60e898425e1440748c468a63680cb63f7f31046c8bebcf6b6c0e6aa6106118dda2e334c246aef4a0a5f665002d75dcf405d03 1681029557000000 1681634357000000 1744706357000000 1839314357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-29 \\x5354b02a9fd7e9dddc602d4d363c7b4d9ce36306b75b98f7a84d337095806c266d9959ed3bd89a21fe927da3dadc7d2f097d08ef47260dd7a3665d3f95794243 1 0 \\x000000010000000000800003dda27447cc30c1d20dc8df9b3e90311cb766f9f77a8467edb6fe7e9f2888501acffce4c0a9576aa60ab5882e9c1c4d2d428e7e6cf94498d41c258c9e1abac311172ac3a5ff59586b205f0ae86e89b2efcc67367868b6e0b5ed871ca450b557ecbfec5315aae9decf96cd114e288f399f5aaa9d124b573719326012b5c61860f9010001 \\xf50a4f7ffc52d17e0d62ea71e8e6196e26d258f852e05f7edd2d612cb420835f31995b063dd8d49765d61864de20e7c104385c3ca877d2c9cca922a86f74d609 1683447557000000 1684052357000000 1747124357000000 1841732357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-30 \\x541c7a8a5f2f9c0ecf9db2b20a5130408ee22573c6a8ff084dc9cfe2451ca7d3ec3038166069f0dbe4694617d4a51e0c508dabbb19e2c5352923035339d7e842 1 0 \\x000000010000000000800003b30f2496b7d445b4dc7dfdb8a748d23392e68cf00878e41f3878cdae00d0dfdc4ad90e5820b61ebeec76a33049c358ad8c50598721d9364bdc0e90142776e640ed990a05402366304612e189347933cd218bc95aaeca0a2c04c766439bfa962898b334175ef65f4eaa1f97c5ba567fb2a3fb1ed64c61734f41ab8a09055f43e3010001 \\x17be2bce4ce0df242081dc5498bc8820a08e73c94828e0ce2d526ebba6618c8674fd3a0ad74e70c5cf736edc24e233cebb24c8cda4669114619238a45cf3020f 1665917057000000 1666521857000000 1729593857000000 1824201857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-31 \\x5524ae1678d05e584fc01df305757c78a8c919a71f6f4f092faa2e88036ac33c8d53d75974f328818d5340f7ad0947d0668dc30774635927783be174942e7c6d 1 0 \\x000000010000000000800003ee44449e9f48beef8d9c5561255da3ef3a239a5a066a82867baccca79bbf090357bf5af8d55b24fa5ecc00438b9dae0bfa6002b4b6e4171be3e58bc10c612790583e1eaedfbd9402a78beee6fa7ae33a5f7d5e201a780170bb3d3a8b7eba3d1df17053ddcaa11e0a2069f24fd6e545ef1d03a4c1649d65b93bb72dbb0ccc7811010001 \\xa3ad28f1e3841f5304653908ca66d71750130ffef5a2e1b07c303c9753dc76d1e2fa49ab957d3112406338b21df48b2e1d9e764271de0f0628fb0dcf97d87b0a 1669544057000000 1670148857000000 1733220857000000 1827828857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-32 \\x56dc8c97f86b382b7233a942f12c5d1027deec57d90f7e5d87e3f2f29e339c1bedd77075d5ce6d6a4fa930f5f3d9337658e09b7079d51d5d80b7cfada9c078c7 1 0 \\x000000010000000000800003e52850c3c20c2429a54c8a0f8d35b3b69403771cf4abce7dee89236ccb713865d54ae8a7df93bf38bd3ddd03db9772dc3958f96f34b4e11379f50a8d9388684bb0683d67182cb0d674391a16846972156281f56a3b270884aea80d44b1b061a00830d5d28e8c458e2344784555d350e0dec4abe0972e1f092c5e09d107fe7285010001 \\x274c4dc9482a96123a2213c7fa45416cb8f5d0aac78785664846e2f91a784110a290a68effd0ec12448cbf79706e9d008f77c2778aeb9ac5baf85429f189700e 1667730557000000 1668335357000000 1731407357000000 1826015357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-33 \\x583883948296c9fee0ac787e437c6963fd07fd59e3e9bd960b7634ec76384bb08383d1254a145773c7dedb5d750e1dd47f842a5c07789c7e23c5bc989283145d 1 0 \\x000000010000000000800003ac5a3a35bc1e782560efd94ffda32bd905561bf5bb6ff366dae530a7a991e17727ffc7420134562eeb79497fcc0a25c8e12ede234aaba6bce4ae16928f2d18d88339cb528f270f39f1d41a442c618aa727960fbf46d8a5bf6505ca125a3729bc0e1e7dc56418f5e25525ce60ddc5f30c3873f41ac3ca58279927a77c6a4afcf1010001 \\xb31da122b5ce0cf8c078052d27deac28d3a56c10620e752e10e148c0765309415b35237d12ad9be789665fe79cec403b438a920c00e050bf69d2e110f790e50b 1670753057000000 1671357857000000 1734429857000000 1829037857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-34 \\x60ac2e47b67e79ac123d4e6176c6be1ef86d556b5b21243c7bcce9881fd6fb8547ad5e365b445f3cc2e3a803a5caa0811d12417056093291c48b6e0fe382c52b 1 0 \\x000000010000000000800003eb19a0f1b8c5b6ff5995530559a41d9e36fcfbbf42d89627856be91bd240bd3a46d429f41afc4830f92646cf18ad9faa70f467e8202318842bf602f8cafedc6efa6a785a3ccf1bb669851690161ae87a403b92b73d9bcf14abb9ef11e1619bcd962b83a9bc641e2cf8a55a78a891be4072b3cc1bc27e8b2c731c65a87bbf87a9010001 \\x33e34102bc2291afb7e10bffbec68c078d194ac152ff61978eafe893261527879a6a0bcc9ab0f77bb9f0e9f37b3730e43cd1c7910a111d2465378256ba3a7b00 1659267557000000 1659872357000000 1722944357000000 1817552357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-35 \\x66b8af8617abc1660403e3ba45868d0438a450378c8078740a794030dcd0ec03164d3ad73ed0ac60da9f97478df2209d8178942601ddd168b1e1266fe250733d 1 0 \\x000000010000000000800003ecb00ef3b4a8aefd598eb897be57431c505813c935171fea9154c3d81e6121f1a426dc1107a1ecfa8d16f22f0153752f1130f79fae503d6955d9104c794115b1e8b12049f36830e6db3354f21acd3c7f78a9b88a3cfd9c680116d10ebb20ac409de0bdb0f62676a7dd8865bb4d5ba1bc8351e3003a03b5a88c31ef4c6f6e50fd010001 \\xc4f21599b8ecaaf9133ca930c4acaacadce74946ca4bd13450c0ff0f0997632c9a792698e6772ae23631e2257a76a1c357d5d2605a23be637d145792375b3f0f 1670753057000000 1671357857000000 1734429857000000 1829037857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-36 \\x67b0448aef0d931df6e741e9c0db8809eb79ebacd7bf3fd976dd09281b51170cc9834ce16d087611a37037abe4ea3ef0319cfc7313894c49d82b31e9fdece4d2 1 0 \\x000000010000000000800003bbf8d4520d5889dadb2effaadaed3cb50a329a773e9e38d25cdf951faabe56da0cf571564d0d32f38dcd83aad9c2dc8c45b0cf3ed1d79e754452fec08895c286ee9059166c88b307297fca1d7457aef310e65a88f555dee4e7410710d6f7293079d265923f1412858925829950f2a77cac6c5e1a55e0e6bd5dc95356e3bb1313010001 \\xa577b3d145753afa8f866ec306a812972a8efa2d23ba0bd9d30c0e502875c581dcc314bb4cd62f9a6c5f3f52f96bfe7a43c25086fd6d84a555f88e12b4b3a506 1670148557000000 1670753357000000 1733825357000000 1828433357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-37 \\x68c805b4f5cd6fb6a04eacd94560b5d3cf9553ebf9ab0705426d01e6572cc969d34bb81dd9e29607945dccf4b5e759700e4841aadb4c61392dc4e2ed6213337d 1 0 \\x000000010000000000800003e8976139d2cee41fe3a5cdb1b4c34e5e33d14a4e7c85d36169f748e0cd596f1706a8720259850d0428856ee662674652df36f2d76285183f84256e79c4d58bbb7797debbd637537555c112929a545df225df86655b2f115a9c93189edd68fba0ab6100274736ee66c980554023d506c89c08f02b7cf87cd3e54621691ea6beb7010001 \\x58123c92025e6f6e1e4e184d0905a062592688bfca26d5aefd0f8bc0d0a0a0ca723e0a306818cf59b80ac162be01e25ad5247893b29c04b4a7cec668c22c560a 1676798057000000 1677402857000000 1740474857000000 1835082857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-38 \\x6b9c6585ff9c9cc0d9541c6a0d2949c566c5b41c20e733397e274e10478145cd0d4a4ca6c25a2d3b56e4556d35ca62690164ebaa6939995b20c18ff62b2ffe82 1 0 \\x000000010000000000800003c098c669e9cd6b24c44b2e119ccb11bbce9633b173c97c0bbed9b7bba85260959550ea6bd2b1d621afb426bdeeb999f70862fcdb332886f7126c842f1488d29b69c1ed123e0fe33c2674452b6f7de5421a81fe4698bd7293a02b4871714e1c3f2c7421b0f54b26110dfd2847cbcdacdc99c7f579da6d7fa1dcbf4666876540cb010001 \\x57599fa34537c8507f8d76819a49791f8777556b06310c2486da600b58edc5d091b11f316f844ce601e4d8f261fb4a03248350f8e55f91abf4b5796f386f930d 1658663057000000 1659267857000000 1722339857000000 1816947857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-39 \\x6bdc0d0b0ce4c03479129efa65b8191ce457f653ab19fb1652cea4ca0472179ea1ef8cf9dc48112a199c47eba1297a2bdd5645a24d391d4207b2a0817b70a43c 1 0 \\x000000010000000000800003f09ae9471933d1c3b70f175e00dd41146533b631d82facfcd2b9f9753e6bf585488f825c4f5df32fa7860dd448ca8197bfd6c20cf6b7e26d2fccf9e258f18a204b0590a637dd16e35a9a92cf9c3a8978b053b399d8d837fa1685262dd2feb0f366c861940246d99b5d3cdf7b1dd0e63826b6fecf4e9ea9ff729572c78b90249d010001 \\x3b9c3b3b78c058861d56bd7a49df2049ab529e2cf7dbe51ea10f0d13b8da3e4f4fc394e8355b890c00044bc9499c5fd88d6cc45adbbdf34827e7e04468a2e50f 1658058557000000 1658663357000000 1721735357000000 1816343357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-40 \\x6ca03bc4db3cfde86c1d50974e5098092d07de0cae55edc89ca31fdfa28302792daef074b288278f3337fd1a55a6affe6bb62de965164fa37f45e9c30e9a3ffd 1 0 \\x000000010000000000800003b96ad8e3e9a4f31315ced693098356f7ba78137287750d9ebc2a391c104352f0e9af7eb08062d186116fe877bcfddc75e735b2cad7b09fd85d2879c21d69cba0263969eceb914be3834deed11af6be416a48ebac55996f70c6566029da3a45d4e116c25692cb7ccfd4b5a6079b58a15555d0ed46c5b0fe7a160341ac8b0b6611010001 \\x039464ae350ad04e8baf44167a2593b11b404c723038ca0c16dff4a39f4c426f56a0f53b8779b13ee02b6223b487e4ea0ea81603434dae8025a53e743f56a50c 1656849557000000 1657454357000000 1720526357000000 1815134357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-41 \\x6fb45ca71d8e83cf35aa12a953d646f4e06df5e133f74f366e92a5c0bf9f4e77abcd4a9faa3c344230fc3efb1aee40cd21002337c804962d683909743a1fb591 1 0 \\x000000010000000000800003f1b662e961851136e1cb15eeb938d289c16c531d7567dfb36084bca8aa0357231e11dacef59755bb9da638c86faeb1aecf2afebdd34ba646aaf43b46a4e19c2b063f3e61e5cbb17c2921545cd1f36efc98e2ebcdbc20d24a48310d059e66a043e98086bf8bb26b292a69db09b4d2ae0ee35a6deee86d8b1745bf2745f095f62b010001 \\xed825f41bc15d5f93f44f4d50def73a4bc9b0d6893846c1ab2dcbeda88806f9e219b6769f74a64f854a4be1afeca97b34cf96c3b050971cabbe4b8b892c3b000 1664103557000000 1664708357000000 1727780357000000 1822388357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-42 \\x707c1b238d7f2a237447e4b62795e12d430de377edde6be8e4818e4b477fdb396784ec2c7ee1aca9469c92d2f96183894e0e6b6bb73943212dc4d5ea1a2c24a0 1 0 \\x000000010000000000800003aec741f3cd09d344b7f54354638510869baf64e4bc30bbb571606962ff047dad661dcbbbcb985b8c980d89c23f3f040ee37b9d84e4b6f9a8262d66fdaf47e8f35995952405c799960825adb096fd1e1e1a0a40680e5d5fd6d0f82582faaad02ffbe45849307f8ce3b11f246c3c2982771e1ba8e8834f171c16bb4c3092724d15010001 \\x24a591096ce1e3fbe9f296e8f98ef76eaac4b0f5a1df59134af42b38ca4442228c96bc9efee709447c45cc30a18dc1874b40ba4047c966fca3aa0718217bc402 1667126057000000 1667730857000000 1730802857000000 1825410857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-43 \\x7364536776e716282a1d6f76edbab36ba9a93c3d03e7e2ae1e56529511c3960ab995b94513c0501f23a31a91e78c190b00397856cf423eb9d0a2e44857699ba4 1 0 \\x000000010000000000800003b318dded3b3ce737aa470bae6751660e7a1b2c6c88db361060ad25f0ab4c8c8a3c5c4a5346c53d2cf1cfa481da1da0966145e8fa53f41660ff95eb22738728e4ef63cf84a6487f65d6697a849b28e3d68ede04bcbf3a63700504afe027548de421e9e0147a4aba65ef197aca76e1a1aaaa2136762529570a425b5b626bb81063010001 \\x2c9a6981b2daa4eef8c87398ac930973e4d905570886caa3fe499b8a22411c0ddda71a4c3a8f6eb2bfc9fb341ccde64f19811ae7fad7715baf3add1818987f0a 1682843057000000 1683447857000000 1746519857000000 1841127857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-44 \\x74246b87d5cbe6d782c55732ffb6bae18f5a1910e1c4561fdc7d16417b389087832d249ba438ead37c332ec28d672ad795eb4631ac91bbbe762810c1675b2c48 1 0 \\x000000010000000000800003cedbd7e1cbfdbb2d31397a574fe125bcea7693722f01a5e5c8be37e6772b942ded916420dcd3642460e5af4eeeed21be8b843c0225772986cf19317975c1ea0a0e2d841e3bb3aa066ab908b744942b6fc1269a603491e13ddd4c3ff7bd261d73c0b62f6353de69c5960598de801df547bdc0adfdfaa47ac9b9af9cca918c8ddb010001 \\xce485278628f8fd862c67b3c69722b009ac4e651dc6cd61c552f753386495d0f108489c9c1e94d76a0d122b98698fc53193f94f7cba827f641ad2ae70dd60908 1660476557000000 1661081357000000 1724153357000000 1818761357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-45 \\x7478073894cd8c545cf903b7ee90419a4b037561829446be67003916cb88aef05c154cb45e2de9ec9818cc6f619d7efe42ff7582a1e3d14db076e147101b4458 1 0 \\x000000010000000000800003d687c47d487ea17fe4b509816262cdcd7d166a8dff842dfa4b7f5bb7a84338022dad2fe2fcd987434e59c8fb06bead57f2fb0fb3be734ddadb71f50fc4af35a2b7d995724a68c6d1fa7b5dc08f6eb6cf661bdc975489523a279b22bf2947ebf1a18001043f64270ce8d3d3c32ac962863a62a97512b3880e6440a35b3f32ff31010001 \\x50a13b9dd12513996c47c04432167d145f9c64c41b97ba14b85175c99e2902670bf9a895c22ff916824336a4ef2297afc64ec6bce4bb75768d1bae5b1b654f00 1677402557000000 1678007357000000 1741079357000000 1835687357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-46 \\x776861fdbcb4c3fefc830fa0b2917ae14ff11cae2f3b85b4f20224725c6b459b748d829b20f7a39e048e1962523e5f804180a8b0f8588376f08e2f82aaf3bf1d 1 0 \\x000000010000000000800003bf17e4cefada72ed4ff0658f3bc2c67f4f426ea7bcb8bd10beca2f210db393e1641776569a167457aa1e58080a17d514d267e7bbef6df83477620caa52453e845b6b70ece2dd5dd8aa7f66d4282cab81207926348c5704cebe75414554d897c120cf2d34c1a532be794fe31ab2815ffb15d15c9f7a38064dd77930854a79d26b010001 \\x883b16c157a03a52c6f0dbc4338a8ff3f2fd5f63c93f5797b3fb7ca5e57d17bbf2bcd2129785db25a786665bfe71bd86d41b7e404f32336cf72820859a03d801 1671962057000000 1672566857000000 1735638857000000 1830246857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-47 \\x7d049c931915821a0dd302b465c91ea689fc1992c82ebf51dcb8d7ba4fda8c943ea43a373db602e2d9e826fadecffb54a95bb68285d5cec32d42d7ddfef1b98c 1 0 \\x000000010000000000800003aaf3e0de672ec38a26a30a99028a284e5ca07a8d80dfb59586f88aa16705cffd370dd6d505a1f5716448b46929a6f4267f45ae0aa16f34bde2394dd6ac7f9045e94108d75b924a03930e45b1ee61b1ad5536c28b5b8b6c251207879511548c6a0168b32ab5a645c98876827fc48d05bb5bbf602bb3229432189fcb4465fe248b010001 \\x8e5b3ed86cb3b21850f5f57aaab2c82a98d50695aca8c419fec5fde491b8437961bd8cd27a4884581b260acc64b9691e85bb8dcdcc9dd3d7cac8858dac58f107 1662894557000000 1663499357000000 1726571357000000 1821179357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-48 \\x7d04a7eb69f35777e56bbac322a182ef9922eb264d1c8c0358ae75a5a4a2669ab02ae05597be75792fe1163d33e2b96bd55403c0bb17ca601ec5dac8711b0af5 1 0 \\x000000010000000000800003cd72a0cbe68327fc332492b79f4238ad4a681a663b7597ea992e57a88abdae4439ccbcd713c58a80fbda478731bf90769eaeb740fa32562c6c5c9810db6a2e7400feae7bf340b90d09a8d74e491d1107eab77d7a871272a23f51eae6b5237e19dffe061c394fe8fac2351a750ce10c42abd80968a3123e7feccbc27c6b1ae7cf010001 \\x45e87b6c706b3ca29a8ef3a6ed5e2d4b683b4e960417348ac6b12e6bfa9e614813ba71cf18ea6da9a22a71671aa93aeed6b5762ef21fefdacbd73143aeeefe0f 1676798057000000 1677402857000000 1740474857000000 1835082857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-49 \\x7e0c627b84394fbda5f02558b02d1e58cf45b49181d49b44f5f76cc2d3cb626419e95b93561991bba716f8f140151d7c4935e192cd41e011589f9c2c61cfd55c 1 0 \\x000000010000000000800003b922bccdafc0a075f41454f88855fe9f83fee229e232fbd3c204690315f90ff6781bfa132718d548297355c20b7aa2d4affde7e77731c9b09327fac1b252d969c4fdaa1e5421093f784c9884998cc0c1a3e5b5d098ae2b5b75c2d4133810a0b37554979e0156969221678a12ca433b75a1c16f45779171750760da7b4abc93cf010001 \\xd063ebaac6418da66badf44cfc7df52538deb0c166ca425f7cdaea72c63bb13c260ceb5458e158a31094040da90752d5c63c48c0d0658c2bbda0e2c06bc23702 1674984557000000 1675589357000000 1738661357000000 1833269357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-50 \\x7f9445ac12d2f3233bb5b3cf75dda6352e203d3c21b83889af322b8f0b6c8cea9479ade66d9cfa5a1089207f50880cdb5a9afeb701f485be1d0130ea14eb9f53 1 0 \\x000000010000000000800003c500cadc1ceec6bc5a27ed05f3f091ed6796f0e7845e6cf417e4473a934f2336d0c5de959aa46b128256ca9eb6189f4bc5bcf51aeaff6de1b32fd4fd9bffc938edc686306fbc5416bb264ac1a5996b021ae8a58dd9f2a000fe174f63e96a4b5b62d6663a61abe43415e9318ae8de1f673bd0a7c09beb11057f84e4718ece4387010001 \\xcbb2e113a8bcc4c299e17ff1b18e2726f3b696e63cd867d48bc5f3e164ea69b2fe6e3c62b8037b4de485aeeff7d5bff59a2ba5bebf75c79b37d6d072dd506905 1668335057000000 1668939857000000 1732011857000000 1826619857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-51 \\x8db027abc443d7d707c1c270fd9672394c6e83675d2697c7f3cefa6349fcfd56884580785b8c3984994ee061c50fe228c66bc38d9100139daca60579f1991c1a 1 0 \\x000000010000000000800003bcf3484c804c570167bdbfc38e274332158643b12cde503e60b713dd651be244a4275f4a936170234fb8c5980acdf6c36186cf047be600522d51a487d8c8f56334d8807c2a10d3f2376aa3ab4cb0a7d6342d620c7bfd26d1035a94bff043beeea4c4d965d7a4a197aba361d01ee6a84883274f75f43497780200b1eca2fed541010001 \\x5bce8c31ff0ef94836255fba2a95ce9f3ea25002a44efd33ef79197bf6252b548fc481942bea870d8ddec757bee9d0cb490c506fae466f8d475609b781613404 1661685557000000 1662290357000000 1725362357000000 1819970357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-52 \\x8d8487470d9576751ff22f22d8caa9ef6ffe92636cf09f5f0a33caa147e8e0c564b00d1da6c29246ea9fbd78ae2c62988ae5ac25cb9b0cead96ad21cd7f3d19a 1 0 \\x000000010000000000800003cb6d6bb07ffbca2ac864d6ed10b53167f84cefac9aed1a439b6b8c50243cae565bfbd1814ba92508d02a2b9024e2e43a5571a083d8f372877812d0624e70b072cb858cc32b3c4b19714f8c8804b0b75ac7d9f1069702649144dabf8bc616b7239b845e9689bf30b57cc3904dbe4f6d1573ef293797da1dedf11f29f07525f52b010001 \\xb2ce44bf31044ff5096aa407f7792e41f08cee7dd07d5dc59a9c9776e9f0e8f2ad7072dfae4bbb71c0654cac24ca16b1163612a0494faf6b00722cb467b59305 1675589057000000 1676193857000000 1739265857000000 1833873857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-53 \\x8e04ad6ca6d66af799ca74f2e17212c5b51404e1107a8776f8782663d4047264d7d9dca402555ec6f26394c50f52362283d8f4a3e03d241b7042e81328f457c5 1 0 \\x000000010000000000800003baeacad32740f974e23289f009f2bafceef14fb5fb70bf7fb9b9795a7b2c43da777f6978cbcabb2c98a8b69970912349d30032dafa29cad4e7e0c268475f16cccfaa0ea39aea60c9d59650adc7fb33ed27327b0da8da3e184f799c00e45c62007a56e59c3472f60493a076d2f6e66f350c2829bc44d81248f434de9e3412311f010001 \\x3a5f4f4e1081c4c3d08a43c1aa3442af3bea6196a204f0b67d1ad3ce37af742f4f55d5b3be848c764d657275a22abb9d79f620ffd17d250d52a7f26b444e2004 1665312557000000 1665917357000000 1728989357000000 1823597357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-54 \\x90803f10bd24f9fe6f5f155e7aa9e1602742d4d9e44cadf02b5b43b8609ec671a2fa1d0415390d41d0ab08e7b16a217147cbe703c88ab2e92de52105ce28c0af 1 0 \\x000000010000000000800003a0acf0f0fdeea86ef8e4b1180826ac07d38bae89fdacd8ac509ac82a8d463e7ec73bd6f7d3003e57852706bdaecdca6b3ae5753687c66e68f7cd7e5bf133162f76db713f0fcb43c310b76ef60e7e8863e4c02b852a0733fb589fec2267cfb7200ad25e1045c7c26ebc4bf7d761557f8ee3d9f5a3544b57259d5f4090b5fe8af3010001 \\x748b3e7adbfb3ba11bfadb50795c17d0347e9e6d77dbb6fac2a897cfc63c3047deef4a8e015c4ab9593b44053a0dbef85aa8ec71baaca25be8babb96d46cf902 1675589057000000 1676193857000000 1739265857000000 1833873857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-55 \\x916c9eaeab8157bf4d218cde52cc6bd38aee98c92c7f9936d6fe86bfb9300fcf073e94e3a6ec44e719aea66367a4c2f689cbc577b984d5f484948f24826cf84c 1 0 \\x000000010000000000800003e0b232f4bc8f6927bf128aad5e7bf7cc4f037161bbd7ff8f6d04a07eb55937c503ef5e47c98b4da36041523deb3cc4bad64e70f3895fb0658bde7d1c2fd0a1ccbe4cbdb759c7d22ceb3eb3dca6c38856819a8aa76822254f946a10d7d49ca1a3799cdae28d69e67b190e22a59018b5ca2e0937fc2c3716ae30c7b92780421f45010001 \\xe3eecc3bfa23681b03a94e390b7b7671630bcb66661e1363b748fc452c309e51657fa839aad2a5e803b4d1840a2604a1c82f1a5a229e8b04bdeaf468ef331902 1678611557000000 1679216357000000 1742288357000000 1836896357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-56 \\x98e04edf8c716462957c977a0692dd93079af163a110a85526671950d8f097ca8f8cd9d84bb54571d93caa21a809a588e938118e1ee4470d19d010e657d9d832 1 0 \\x000000010000000000800003a0c6799afb148ccc064849f547801133db8e20644e65f0114679fd14776ac8662d32a2357c16a564f9ea0b85cfc71533892e0182b8b20ba469c9b4bd6315fa1453a1e22d62f9b28e75356d46d9373ba79fd2c17c6e9f0079c40359d2845130ba5fa42732b49b5f341049fee1f428fd532633b94e73e308df199c3646bb707727010001 \\x9094821e50a9ecd1fcf515cd3b194fca46a441a290582e63a617b796827d2ea6dac18157200bd7943c1b8c0b390bd310d27f05c24656c1f5f65f9a8ce4bf670e 1662894557000000 1663499357000000 1726571357000000 1821179357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-57 \\x9a30f35fa4b0ebb5ee2d0c4541e9852d0e7048583935c23be57ef77cd70bd294aa061ba5f6d64de9cf9c3b6153ebf542ffccc560e4022daad3a3d0ae4a2e1aca 1 0 \\x000000010000000000800003bf9a3408e11ca64228e285cc13e0588b8a12133c984af575ec64dbfb97a61a40c0da403e1b7d244a3be8f9faae0dbe1a6a790f5526d2fa88d4d2b8a63d89f32f8620570508bb2ead9af47a47335da327f7a44aaa617c15d7b3207fc09bef8267c48d843e2f79858a5170dd4937dc209c0fe1493ecd9d2c829c85c0460af08db5010001 \\x8c914e9b6aaea4df3abcf4b9cda1570e862fade8acb92bcbe5f1509616833c6c8b00acb589fbdecb119488f67c50e1a1a483903ecd51b5e6026d9e560e94d30a 1655640557000000 1656245357000000 1719317357000000 1813925357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-58 \\x9bc8afbb9b647678dcd5116e9ae6f6233d2d9732e66caee2b32b2872e20c1f9b844e99942541552559aba9607167e30d8c93e9bb4f6909219602ffa8cbf0e381 1 0 \\x000000010000000000800003bcd5ef3566834f2189416ac9c52db17c596bfb1b48524dc7fa53c132d54bc22007adcb562486983db7a4d41d253d116863a6e6433d78d26871a1c37be1091350c1d4ce5a7b8c90768857a8f22fe8d750855415a6ed75321a2b05e955877fd263d30aa8584761ada04af269c6ed44a0af1fe92e30c1cb445097d2e36a7cbd9067010001 \\xb1c30b3407f4bbc81eff4b2b8e5e241f728d7a76ad311b76ff37c11f7998309251a78bb1b0313c54cd681103567344f58bc48435378c3e67a029daca068d0a07 1679216057000000 1679820857000000 1742892857000000 1837500857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-59 \\x9c0826b29d61f7b80eecb560a28d38a2202550a3c7ff3ab5d04a189d88a3aef4e890fd9fe2376f9964a8c4af0246c28b92707a28b2ade4dcaaabd24c2b661672 1 0 \\x000000010000000000800003e310f7747a314a9bd535de3c9047d453a5128854c581340429476455f6541c25be421b11cc06300c284b0115cfd514f9a9f2aab238436b7668d98aaaeaa6a44d8268d274d30e9df3c9b0e63adedf1aaa0f771f524719da4a1f0f5d6a2b01cf8e250f776f6af87babcdb8fe671256fec111a9f7e14d80909634fd70462e4feaf5010001 \\xf79f663c9e7456b2a5a5220f593cbb37ba0d9f5ecae93547627c36db73ae8a30067858e4675c3395173aeff17bbcc4f44be5594738029ed202719d5c8d65860b 1659267557000000 1659872357000000 1722944357000000 1817552357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-60 \\x9c8c8690eb9ca7a05799b819acbf0bb21316713d4a1267610e35215f73441acbc52476831616262f0570ada2635d75318b8d9974b0a393d9f9ee762a879287f3 1 0 \\x000000010000000000800003bd32e8c442c8297c30526a9ab66a176c7149e0e2690ca49601957e6adc17684cb9f13ad3c311a78cce0dd08f887193af9f4400143408c738567ae32cecda4cb281ab8e54f9afd7456d8e61dd4272ba37af76ee27a7e59e6468ed2d6a058bab398bb33243b978dc35a5f12d012892d6445b76ff4408be0a4299a292ac5e4ffe0f010001 \\x65568b803ad33802bbec7bd80a96d7d355bb6d303eae5e3ae7f586ff4e3eaa53be577151f351dfa2af21b2ba846c4a790ff487fa220c4d77ba9ae06e2e33e80a 1671357557000000 1671962357000000 1735034357000000 1829642357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-61 \\x9da45dab4ae4a6f2fc78cb0778e491a2f52b0a83488981e4c6647659dc0c3d21468dcc2e4fa7d21a2c6b8fa06d711828fad9bed9d12d8100f3138400b7f9e8b5 1 0 \\x000000010000000000800003a3cd51263182fc9636632ad020834dd099ac5cde9e5d46f992de39021ceb5af2ce7ba44f59cc6ff2a1d3941619a0a2c60416c7d972213ff9573af588a72718cd6790f6c631ebb3f644b38f6f2e49b309503e03257a9d5c8e9503e65817b436b31146f8f64c384db6b5b2465b35f10e125b27ab32639b8ed69e96945363106675010001 \\x01c3590b2a080db2758b55d83e672f682b1737618f15415edecaadf82b2563907fdfd195c9382e339927fa777a379e9b1f4b79b83895fa5beddb845b4bf7de0e 1674984557000000 1675589357000000 1738661357000000 1833269357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-62 \\x9d0419b01473a238e72c723a867ad08a1533c38640fee487b554f8428d0cdcd9f3a88aa40593ee1ae4d064929da41d90d1d645ce03a47e3564598bc4ee5978f4 1 0 \\x000000010000000000800003a32c12df2d89bafe825ae0e22d0fffab87182149cfe6583e4ca5ef35b78d8b0b2b53718b735cd9987a11158367dbd369615c99525230b12aeed36cd687528739addf8a8b676d493ec83baf7d70fba0b62241c0ff016b2a38c1b9b6144fce0a8d6cdeac613c0eb8bea409484ca48fcd4fbe4281019044e9b28aca88719f218835010001 \\xfcf6d399e0fa53aac3d58aa3398df6dbae823aa17b5a6a49e467682843d6e512f98e0b3029aa1a4c4ff743fe8d4b86598a001ef11461778826075bd822ddca0a 1669544057000000 1670148857000000 1733220857000000 1827828857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-63 \\x9deca5f019077e7c68035b16bec9e51f3f687a4c52d9488913edd25ae85aa864cbab3a4795d21eed9df1c377ee06936ded9cda124ff476334bd06a6328ea999d 1 0 \\x000000010000000000800003bb052a6f78687b604a9b507165bebd5b0688ad7f07958f72b14eb6360d0ca756d41ecb0968d3be08526b9a95d5eabb6c6421e7217cafb706840d4788c67b092090264f1aa8c0e885d9c0096555fc5450ec0612ad5f0a684126344cd1b3f778a69bb7728849255067871eb2e9e5dfafbbccbc68aa26f37dba8d3be610c435a729010001 \\xa09bb67852df01cee375d1a1ff0b5595746624c566427c504f89720c52161ed3dedc991f96b2b44ce7a9ddbba39c3810fe4809f5d66a8c311371c3c2f060ea0a 1684052057000000 1684656857000000 1747728857000000 1842336857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-64 \\x9ed4cc8712edff70a379e5b3358260b08afb9c0c5db9a438f67a266525be1536ebf14c58d58ab41e6cd5ad461fa23a59cc590741526d89061d1af3d7a2f0fea1 1 0 \\x000000010000000000800003e0e9fd29a3b6bb7c1dd1178ac9e72c9eea12a01239be5fb5424fd2b5c980a114dc76ab8d0cad8b8da924b5fb6e484f6468d5b679e9672f3d2f2fc64f05225b11a467c00fbdc2f88472229e47cd4812bab93614f02ddb650d7be0a250d0febd34a3c094f6c69c4db3e36965d7eaa7ccfa431beddbd5820e7fb4de5c29a5774999010001 \\x5fea40e6ad0781ea42aa6402f97c66da904ec3ba3e8de7f85876efbd255017c02e186db1c8027869d931294f06ab9948318aa13aac925b9ce068c3881f88ad05 1669544057000000 1670148857000000 1733220857000000 1827828857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-65 \\xaaccd61d0d7245a536bfec179677e42c8ffd0f1c72b93ba9c413c989cd8653ff4513c1d18f8c7a1dab9c893a59e1ac8b98382b96be13944e85ca246aabfcfefe 1 0 \\x000000010000000000800003bbf1ba79a16f3a85f4b7b4239d668d399db2264856c1daf8bc46da813fbfa4988b1d04b1bfbd4a7510cc21ec10e60fbb29a5332ddb786d901719175d1b3d8efd47c69d8bdfaa7b47ff378025d19add303b28948d9ad99d866c23a77a67bb08aef1e465417fa38dd61f8d86901157da8317fca1e3ba496913fd42751a05bb8113010001 \\xc8d51d922ebc8a93230b8e2f3cf644c404819d8cd6ed07d6c67195ea41870d3beaa9f582bd2a2c011641aeb71f7ffd9e3219a0bb67ed39793b2b2a7cd4ae5501 1656849557000000 1657454357000000 1720526357000000 1815134357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-66 \\xae702901bcce8800cb2179cc843d153ca2af29b28886d2b9705d4d0e3bad29bc3618b4c16182fc2bba3f9d7003d473f87d6bf9391a31b5b26b18089de57df95a 1 0 \\x000000010000000000800003aee4fedbc8871851ab9b564a578f05b3bca15794e0085ca1f760ef6e3eccec9ddae4f5b6c8a70245df13c1ee67f87be6a2c182a0dec4ad10f28786976ee5f1cae771f3921a230946932644284634500a859f86cf53c4c257ee6b6699283502b37356e6738014c6649b95bfc5edd40e93a7a3d83199b9ea07938f9ac1ba9ca783010001 \\xe814a82c5eb53eb1d92c9c7d65997941d4fe4e86b63ea8c0f45643a392c8a8c36f45079a14d126ed453a6165680c48a1e6eddeb33850a2c4d97fc883c95a1f06 1663499057000000 1664103857000000 1727175857000000 1821783857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-67 \\xb428ec92f7bb463544c38b9fa6b021bdccbf14989b5edfb45f3ce73f260e13c3d794f662e43d42f4e4065bda1c7443df13ba00cd3346a47d1eeaf8461350c463 1 0 \\x000000010000000000800003db4a61bbfd0b4a6bc36a0fa936d83025dcd5aab187802853dc2119a2abbd7f7d120beaa3bb4e15a92cbd480dbce0267d882eab2c2afb810cff23cb3df054b13b3e4fdcd505f3157ae5bef33bae3a7da8926a06a61b9552b3a72fcc8ab98537299ef0c14fdd3e9f867252255c6a3861f885143c4399ec198ad202342c7f58681d010001 \\xba8a65963f28cc1ba7392e9fc78975cb9aa45bc14a639f46402e5cac8b23bce0fff895eb9bcb7820bdd7106eb2ba0572114ab290acb7a92e403f16964072f605 1662894557000000 1663499357000000 1726571357000000 1821179357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-68 \\xb62cda783c94a4b91ce89023c1629355172223068c41763cec1b802299852accab195308bce16fa4348f8557c359fec56874417f6edc42c08893018134390ea9 1 0 \\x000000010000000000800003d5ab662e0bf78da44d995a3e32f372efcbb31b88df645a1cea8dd7ef035b9210ef83bef19667c400c63daa371f08563e297e4c442d063ccbf9b00e419d26da54b0c73f2237523eff0e6b78d759ccd94049cea67faf8b4828a3c275cca93efcbc98b4950109a0848d1dcecc129451a235797692eddaad9564796ffb139dfbed49010001 \\x3122dd79ff1b53835e7968cc9646a344c6dadc9678c300256c22163826c5f17b294c8b71a7a3492f54b6fd3c9e5da14b6aa4af66f01ba25ab66d9d775990fe0b 1684656557000000 1685261357000000 1748333357000000 1842941357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-69 \\xbc380bf6a39ddeffd5ec5bb8d7348ce80cab6f75f5adf5be7a84f0f0ef2a8ab2b0c22425e3934d8d43d76aa0a72929cf3b68ebda04c8e1a928e319f8963eb057 1 0 \\x000000010000000000800003acc9d4203c8ba9c0b03669c749eb9cb2f161d400035095be8266c9bc25fc1ef3f71e53950c944a0d2593e44ab9ca692e7510fd410d2e2122e611909b491508b5c3064c695069b5acb33dcacd00b7e1e9e470882a5472fcca3ed0003e84166afcf39834648725abbc86e65245478f560809a1e8581017eff2ef3cd93028f7ad03010001 \\x0bfe22eb352a769e4d9c7016843fae1e2c3c19971925cf17f72d0cf901ecf9e848249cf4208214778ecf9c82c40c28200e12bb66b8c793410c6e954c6248220b 1669544057000000 1670148857000000 1733220857000000 1827828857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-70 \\xbcd8f8a1f0a02a09bf6f40fe494f80cbfe64ff67947f34a310da91ff263afc2f68d2db60e3fddd9095f7c3248897c37f5fa94b12f47eee54162eef482883b93e 1 0 \\x000000010000000000800003da1d380aad13013d335b3cce0f4feb6f7163e43225c84a71936ae8bff99d5b4f1c2efec1476bb72d048fb99e247dce4d4c5dd2fe166ee7d17c73e26d8b4cf8e18a2d8aebfad26443842534a833518fd6dfd1de4eeb0d2d3130ab2d49e1e89136c227540fcbd0ac954d32cf38c4e0cd9f7a2091515ba3c4752387c0a910d5f343010001 \\x81dd8cfc85dec2e4ee4c23f3f73cdfc3d7e7da1fe4bb852cf4688a0f669bbcc2735e3d60b952f9037b817f161e8a5b88ef0fcdda9a47350fda7091258179680e 1667126057000000 1667730857000000 1730802857000000 1825410857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-71 \\xbd5c72675d936ae753bfcb2faccf226c6d7aaab73478109f804aa054544ac06ec896df21871f88bd40dd2b7539f837853aa166bbf6d7dafdf4a0407ed9068a3b 1 0 \\x000000010000000000800003cd71d9def2752242ed449fe9dab331452ba8ad5cc95ca72b06b6fc3311d6b4ec9ab94593ed8a1931e55a35be011c3f0bfc139f7edaef0cc3ec82ddcb29094372148610d6d543d9d64a99da0c19de109446d01c7295cff1c7deeb71e1203a23a62bb1697060fe0dfbbb04af91fa4a7b0054f3d03bc38a05e968a3bd683ae4305b010001 \\x47293777f5cec3160a1dcddfffaca77c1579d28e4e38907e9491fb17d59bb620caf1dce7188681e4af1c796e03f29e49e112b39f6ba0ae3a6f6c45f7e500f308 1656245057000000 1656849857000000 1719921857000000 1814529857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-72 \\xbff416a241d606cd4a50d6f72430fdb7cf4403bf246b266c6503ddc7963cfc087d36131c537675210e37920e9821143c87de601d5d0850f72b2e9d0bc25d68a5 1 0 \\x000000010000000000800003a1cf47a804707a5488c2aa6d54558a1f826ce15f9b704072634ccdd2d3a3c831a8ee3a3c1a2f51730543f578b38d8e8e512de2370ee7514b673e7a19fdc9e5356cf20ce0449fe3d9d0d7887d94ef9bde1fe5836d9c7cea68f3a7b0b0cec742bd05347bebe0bcc6b664cfc4cfca8cfc74bf8135092a5cfa0f5f6d501562172b57010001 \\xa1c85d2bddf9c7bd47d5dd680be15cf09380eee2ffd8530a41b4944f213ac1002267ee216d87dc9215f48384999c384372ebf958c6c518a53f828a4313fbc709 1661685557000000 1662290357000000 1725362357000000 1819970357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-73 \\xc1c86cedfcee36e6f9404ed70c167f6a515a2d913fdbf01cdb6c9af281f3f0c85e7e247e49912c27284991b27af91c28a1532a891c0e47c0b70aeb36e9a5be1c 1 0 \\x000000010000000000800003d3341a6775db9a90082c4db96d25502b311f96bf6bcb0d9d383f5ba127fd42ce6ca4f766461b8396ec52ee491813d3cc3e4f992903fc6776e40cc079910a6b6081c1ef874dc4db0da71e883ce98d7a8f10c150e9189f1ec4ad7e9c724c86db0c402db3bc9106e23b1bc62b8119112789b4c88a6a6dfb0d1ffc0cc8320dc0ea97010001 \\x6fc28845726fbf24faf19a2cdb8d2d23adfa776ce3073466ee618e3f29c34c12f732bf9ff07a01fac1d11bc66a7b538b68bb3dc95ecdd7c3aca7c13c957e9c0d 1662290057000000 1662894857000000 1725966857000000 1820574857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-74 \\xc24cb6d746ec7dc6b9532bd8d5bc0c33e10465c64e39cb09f6c907ce1abf15795796c2adcf8f6e92fc138748f45e7f9491379df1c57f789858e8c4f9d2728ab8 1 0 \\x000000010000000000800003b41479a3ab43a8ebf55fd3baf5b994a233de61a8e4a128c35d4c91355aba6a589597c06c9463f5a1d1d1cb46b196849cfba334922000c52758a5fb8a7ec4433aefc3d490451afe0eabdc31b5900d86bf83912c60925088dc013cf177d2e73efd49ef6c53c3940bc8f2d064ece422ac165c15485428c7236b49767e2564c8c2fb010001 \\x094fccb10d1f1c2fae5caf3f2abb41519dfb977c793effe804b46766c7223e0ca56ab3b0f5acdecb2e42c122dc58b8f83b6b67bcc612d4c71f98b100c566a007 1662290057000000 1662894857000000 1725966857000000 1820574857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-75 \\xc2fc389f8e627ea019b967b508fdf572550c775d8cc8622e45a80c68dedbfed7397293b30ca50059acdf785162a843f4d0f5ad3d69aaedbfba439cfab361f630 1 0 \\x000000010000000000800003e9275ead8cddeed936ae6e28259ada5f1a374c280c9ae8343c1d9fe378fa2fe438b0207811ea192be7b7fc8fdfec78ea56914f4273735c187d56346be2b9f378c5a9cd0d0cbd83c8f2e9f36e45f8e821bc76de5ec505adbd474eeab1b8f2a9724d3d67c8110c8a2071af49ffde657c2dcc7253345d2e639fc4457058181a287d010001 \\x35a043382fd2c88f7caa7dcc586f27e6e1dc36a0d289c8f94bfd3de83b57064cd97578cc94221f1002d3bbbae262b9dbf2ec1fc22837da3cba74f27ad1ce4f05 1672566557000000 1673171357000000 1736243357000000 1830851357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-76 \\xc3441d74468c060560885a32dfff18f6f73a87754f3299b2309772c320ad196324b8444e31a0a28fc246a502c49bac80bc4a31786f3d539a2e8c0bccfc02cf02 1 0 \\x0000000100000000008000039fa5a3601afee7c26d5fa5f174fa34071167b38e6122de6131add5d0e936df2fdc7e6bfec7269ef02803ad8c90dc216d01118a634649b3cb35a671782f2ca56a97a8150504b3eab6ac127f0a9c6f52a8c7ea4bd49ab4d3d01703edf12901290ba768a8be0cfd56322918663c13daabae1c5eb82945475a8c296f058be8587a8d010001 \\x80b95c27fa6bd6e54c43762b06d1e38cdf94ac19d96f95ac51adfb142b14f02864249d9788d4c013c10b147dbd4c8b8c538fd7a5276efa74b867f3be8dc18b0b 1673775557000000 1674380357000000 1737452357000000 1832060357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-77 \\xc518539ee9c07e3df0059cbb7ffed64e266364f63da7bcde1f20f2920cfb07e9965c14c7c85278c504d8412715856be380e1a65a1f661af5f4f796d52f6b646d 1 0 \\x000000010000000000800003b394c6d79ce5faac3de2009b437946561333666cb33a70c681d5bdc420396e7ce0c1a9a8fc83408f9a8e45014c82ffdfd9720421ebd6c9a828331248f9d25232bf5eabf1482b6f4ab0353899ef4bac6bffddba0938b7c6309dbb4e0e60d2f7bbd85dc97cb31cb94a0ab20b790f4a0fe7117e37ecfd862323f47edb2e2521c0b1010001 \\x45ede2664977e55402442a86fa719da32704db63426c8c0dd92e19187bba9d88de5d06abe47026fcc48248fe2abb4becdfca35280465d24d0c98ec7978419c0f 1655640557000000 1656245357000000 1719317357000000 1813925357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-78 \\xc69ce60fe1c4eac3d566491c3eb71f0bbe8d871d1a165380c5bc700f4d2baaa5daea7956b6c74065f8524dda3911c8e053b05299cb8997ee097d6b10b8a9a7f5 1 0 \\x0000000100000000008000039e10d01945ce039e342fbca39ea4b2da26c526ca7381fd42ea44ed396ab4eadb2087a0d581ac6612d980d65380a22a8ecb4bda094b18538ed6699a2cb6a045e81400df7df1d5b0fef19e76ba2bde1e09c387fa40e606607659bfa3e89a5d545b68b1da9f7c18a672a02493b09d36709f20e3982b1be0e626285b6aa8b56b1f85010001 \\xd2084e4e24479e8b1c49cb136cf240a7bbfa7c0896a712d8723645a8012e4d1f2a6429b6d69381477079d03567818670ead44e3899b3a8648e0cd0ebbec50a0e 1675589057000000 1676193857000000 1739265857000000 1833873857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-79 \\xca489e1bb9bd47bb071ddbdfd6b62b93c4a64494c2d322ba6dc8337638114934ead60348a4b5b6cc9e8c4a07308e7e2c1efe7d29ca311e56e9804715f1eec9a8 1 0 \\x000000010000000000800003a715453d57e369599ef3b91b59db0468df815960d413b1c3bf247890376aee4353485125fee1e69248044189156cf5c5414f82ba86b82a761db210f4a10f0b6e8d6fcb578609ab4bc419bfd4d5b827923aafa2242d8ccc73b567dca6bf2969b83f41b7f8cf01310f9805426e767a3093ebc0258099f87c9ebd5527945c8022f1010001 \\xc5621b3c9a5f269f36684297e97665e79fb799c0dfc46f51a2110c040c31bcb028e85e22560c55ac43395c3cdcb91347fc0014797b46e85115a0eb7369da970d 1665312557000000 1665917357000000 1728989357000000 1823597357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-80 \\xce383aa17965cbc570e17fe52a35949c8d21654fe238b05657d958f25024de7667dcc8b5e8f7b0ba33493129d866ec9a707a00503c0980d415eab18d70e217ba 1 0 \\x000000010000000000800003b99e6f3ac8f34275e29fd9aaf91b1185e38df572ed7da3140e5a25c048a2baae9b845d34f02504120cd0262e8aa4488aa4d3d63e823a01e78dfbece3278fba71425caf68429fb0b06c0ce57078f7fbf1fa325596a95e26ede56bddab6de40798493e56bce79894ddf38d8237eb450eca2193df618aaf5d2a4e4208467df02a7f010001 \\x891aca9aec70c8699638a359f14ef4e87fa61f91df97866a0bfcd4afba86e25b1d7e7a436860896f44c41bb4b2c90666c5ce680eacef5e1bca25ed8fcab48704 1684656557000000 1685261357000000 1748333357000000 1842941357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-81 \\xd1d8986363ede28c625afb66115528e7cf777a519c4b834b1cc95d5f9841386e30a0edfe554bdfabd98bb50a0f2203d6f3f81eb0d7ebd3e45eec276693d58ba9 1 0 \\x000000010000000000800003cb4875ab86cfd4cc8a49cdf24d973c15f88fb00ab5ad6fa6e98b0b2f5644661bbf81b1da3f60417fc538253414275c09dfd37a4ec05d27d186ef18070dbfb8c628919778ea1b6d5752c11f7caa9548408b2d0f3a28d6f94679204913967a4e461f22e7d11223b22ca3bffda341c1a1f09fe25179e84bd9c83181cb1fd9861769010001 \\x226d2132bf470ecb72413989aafd9e64dbe6122c3abbd98c97587bd016b3bb3790970df7affbdb7a7f7818e776728482b47ca5aa65f689e77cd8ca12d4ff0b07 1667126057000000 1667730857000000 1730802857000000 1825410857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-82 \\xd31cbfe227e4291ada52faa12f7c13939e95062bdec4a2965c63ce75ed7c1e4c37404033d9597712c8686243023e6d23d60d63db946784a618fa154cb4661aee 1 0 \\x000000010000000000800003a888cc910384fde72b02fbc64dedd42760157829fce074f6e738fb91d61d8a26973142b93d543ff7524e216afea5567eccc49e4a1fc562609ce70deb89518c584f720daf32fb540290fea7231df461c10ff82965e3f54389ae1fbbeeaf0d595ad0045cf011a2218b4c2ea8b7dbbc22336177e4a364b2e9fe2571a71cbe93f30b010001 \\x32b04855e8f9e91250bc345316683fab1e44d7be6c99390b643bee44af9119368179e1a6d7843d53d800e6fb3679746bd2daa7d2ce919c719defefe39f093801 1674380057000000 1674984857000000 1738056857000000 1832664857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-83 \\xd388f3ab66d218ca1a68f5f7db01b4528653d29fae60cb107799820c2c73b1d08b7fa89fde4967221e8e2515c68aff992f4eb55d833c58947cbfcff2ddf45b15 1 0 \\x000000010000000000800003c4dfda3c5446e87c8d852094304b080139f03381fb1c55ed198caae8f8ddfe9239a96da023802098f303df79dc4d2163649a3f42e00a594084a06cf37038fb1be2cd9c71ddea17b6aafaebee25c84a4b43782956ed024b8b78e5b8160f4ebd546c59608fbcb4beaea21fd518990994268f298a7ba167b10e3a2992601615a1a9010001 \\x46b8f16c076937c9156c72c5a3b356e95f4ff52205f7c01079ce388ca69851ae1516de909833352282258f82605e156c696516fca53d18ebabb633f279458408 1668335057000000 1668939857000000 1732011857000000 1826619857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-84 \\xd82849a91a2cb61fab20282e54c5774a75f5ab7829786d97d15b34f40cbdd409a6f2600b478fe31fc1daae61a24b6dea5a875db4d164a762b3bfd6bda6c7f6ae 1 0 \\x000000010000000000800003dacff6cbdeaf68e05487d625a206675bf9db6dac6f9ba31538d66d5d12a48d04659548f26b3590c664e58599a023cab95ecd8ee4fea7ffe3890aa4f49eba2ddce06b9f8d8ce9e2c9da8ea8220d275b699fdc765d28279f53a5f59ccf343d42e9ff7bd885abb5f232658307ecdb774cabd97bdf7f15a155b2f9f32b813da12a81010001 \\x4e8c720fb181d23d11e59c012edf34e59adc1919f8120e1054e695742402b5d312ecc3097ba01edc8a6af83f8159833c0cd743718f8952f016bb75396a525f04 1664708057000000 1665312857000000 1728384857000000 1822992857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-85 \\xd8144e3a9646a632583b1511a095209c51bdac72ffba01c01fd9a2cb2ebcc5d511fb8ede5bec7730e5ed1664abbe67ff3f970c27cc02f1b7ec8aa5dd61c5acab 1 0 \\x000000010000000000800003cc2df278a77ca29a200361756b021bb375f9fb233dcf1ec3e1c784b4e66a8d42e75359e1191955c40aa7f82233c5285fceb1c13a10969d53fd5d147ae1b9264dda6ad6474588e53f3225218851fd2c5a704a8b6aedffab6c1386bbaabd3dfc8e7d4b46b7726d0ce29cff267bf6c1e53605a0bc3654063815cdb8e55699f2252b010001 \\xd69bf53a1c24c0679b503824b2f85619e169e0f01f4312d2883ed6df006008a327da4dc99dfc9f530086739912d398f496a27d525187a1fa780fe32e64b7cf05 1667730557000000 1668335357000000 1731407357000000 1826015357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-86 \\xdec056237e51b3852440c403d2abac526ab10fb25adf8908f990faa945f1dd5c93f621a3aa6147d3ff2372d1baf4fb5d6e1d95db7f0c593347ab9ab8e55f7d19 1 0 \\x000000010000000000800003cfd416355111f58e56bd0fc57232fa6527668e43f757cbb7211004a4800e5caa3e2234ba41d864ae7e37f476325f12fa19398a2ec68bf1a8e1935e00286143fadb630742b86aa045ba9f96f19663540d97cb6d7b8ba4b29098df721e9bac6d33519f00ece9721ed6f6e1547a3be02a51f84bddfcf2154e7068554a787f972529010001 \\xa7842a0c67b096d517a09c669069c401f3582bc407ea5669a091b05101333f10fc9887e5782149ed63543506f9fc999aab4b65d3cba74cfa2f7a475a75045609 1666521557000000 1667126357000000 1730198357000000 1824806357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-87 \\xe288680cdf1c1a6973cbb985da0cbd43624eef50a37f6379a95434b7088a1c1f478a092be9bb343aa6c36fdc4a50480ce7f1503be2332d8601196ae9bdf62548 1 0 \\x000000010000000000800003b90e0164bed744259fa9fca68139b311315179848aada01fac7c4a2e0e68f6662403d000f3a6faa010100faa2551748d9b5d72ac3562d56748c395b22223c4b3c498c7c1d7fa169b57bed70a3190e802e8347ab8d2a9fa9249d83796e392f2e25aee0e84d084b3302cd53a0a271235e25222ad5adf9e7b3b47e45e7663082d4f010001 \\x1610fefc8e507db2f3fc1131f84c09a5e0e4415fb2c73bbceca838c436b85ec274c03da92c6138ee60df2a9e55103636dfe5e8750f8595f7ba7973c99f81b106 1664103557000000 1664708357000000 1727780357000000 1822388357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-88 \\xe6842cbdc03fffaa4ed80a825cdbddd19c7392d7bf693b8a87ea88975a1d55d8e21be730f7ca788df3b3c4fbfbb81d0fb9beb3427c901ee08be4fd37a793e072 1 0 \\x000000010000000000800003c29a1fcbd8e8a760f867eb80091858326a6196afac10c6337bd4a15301dcfbc1c0d869641aeb2dd3e1eb1626ebddcaf13d648d2ebd0fbc4c913bf51b6798db71b359a87ab47075e119b38f52265a6b528116101d3c2e724bad908706bf8f53ce38268b766e00cae8697991af89ceeaccbef7ac88f11248c03b55556bd2d26f0b010001 \\xbb965711a70dce0c2946330db61e700b265ae513470c16dee0673b180250036087fb7bed421a656f836777b8ce20b947ae6571aff195a26820610558946a2508 1668335057000000 1668939857000000 1732011857000000 1826619857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-89 \\xe8d093fb7f5e77089d562093bd25e838ceeabe26d0cf5d3214c5a78a39f30a9a34fdb3ec90857630746c00ee63a1f497f317f50cb5776dd3bc0dd046fea566a1 1 0 \\x000000010000000000800003c1ee10c1492f35060d96aed02e3c4e4e25ccd2ed5e624cc6f95f524c78883b280bca58211586782295180bea1a2ea4af830356f4480ee6b9abc0d95ca6c62f3e5c3464dd95ba2bd48c415848ea5d44db5e6b7955ba46aeca55b5915f9a24867a96998b177e6dd62712b8c2b2afdfea2b600d8ddd867c3264703bd3b6c914116f010001 \\xa5363eb3171612e7abb5b6e26a2501393077875ccf0e5942a5afbca73fabfcb5ccdeb24e5e9448f8193a2a15c3eaf5566c45bff12548e7bf793cc2911d7b0404 1685261057000000 1685865857000000 1748937857000000 1843545857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-90 \\xf088c3b5f9495dcb24bdf321e1d41d94489dfe92cfc92f7a1b325d7f1b3f322981006e2d796724973f54513b044f48dcbe7cbd3ee032bc3bb1a95e50769b808b 1 0 \\x000000010000000000800003d173d3c3cd99a7b95c5b67f2dd074d8021d77dfe9d7c6ac2f1d420ebcab9beb8e37d1929b8e05e50cb96cce601cf61bcbb30d52299eb323b4be187cc53b920e397a925d35f0fa58ed4b06c1c82e0ca5d0becf71168fad625c35e8d8306dad15c67db261654b71235613af2de3b2003e90edf37ea80b61f73d73883dec748d0b5010001 \\x60354d3c0654c3d6f928afa6bf0e80b0653f06c8dee7e42c322c47a1a3d27ed56f5af32f3f0adb13ae78b2a86c40f5dd0bccee501d17ada1fa384a8ebcaa2c0d 1659872057000000 1660476857000000 1723548857000000 1818156857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-91 \\xf3e016ef1e69020cbaf418a7cebdfae9728aad98964e3d04a3257514ba8a0cd128dfdce0a99d458608b9d5f68dc0b1e8c8c907e79c6f05db34fb8ecc720f7fa5 1 0 \\x000000010000000000800003a258ea37b6ecf1cfd443c79b288e570f3fcf061fa2ee1c4ce89931f84fb2bdf6a48365a907670edf29e586f18535766c0bc46bc41caa04aec06e1c4ff81847f4261c8646e1e7939b96a4dca75139bba697f729fda2c9c7942d2c4bf86dae03d8875afaf8c5523c692e9eb320c2d99ce759cd1f7ac61396a9aa32ad73a393f545010001 \\x121d6d5464363c2a910194f2ed93ad3f56dceea9ff214447ec539e8573d30fb97578419ac5698a833def83c2fbc46d59b3e27af4e419cd71b27331a6172fea07 1656245057000000 1656849857000000 1719921857000000 1814529857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-92 \\xf5c0117092c0c23ce4b956d78977ec6ebb6bc8af4836c9679d3704b7fa0bd735803f107d954aacbfba33aba089b6800469a751a1d3af8e9d1ce92797330ad87d 1 0 \\x000000010000000000800003b78f77f34d4fa938366f3407406a6a3892e78a5ce548f6b3f8c0af0ed3968adb8eebd5a6f56f7ff43eaa44746e7d627fbac8c758d05865d3ba1cfd18f2bb5c2a21bc2a867a03c86b4ee73deb09dc13e6648b875624e530a00334fb34b25211865a4574ee3be062c4b1cfecd8deddacff23de3363b2346fc60c633ccbcfa7c3cd010001 \\xe5baf4a650fb3528094a2f76b3555e1195c8d39ec5ca981da70d9a9cee90d7a3e183ed63299f1f32500300ea61e089e939dd5a0380e2b2614d98be690429c506 1674380057000000 1674984857000000 1738056857000000 1832664857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-93 \\xf58cc64a51ec0daa404f049b4423a6f8b8ad0387689597ce28077f412a8a4ac8a03166ec4a8072cca8c1b2fafa31193a5e869aa3c15d8f6d19d06a2b8fdedc67 1 0 \\x000000010000000000800003e57ccb68ce77336f4898541922d9e84cb629dbfc3faeb6932e29f628a55e206ea9ae4ecdf47002eea60eaec69a1d1eb729cc25f1edadb3ba687c5d11aaf0513f2e87beff0b22b24d6f67c15d2991d1485ec7279b8cd135c5b7efe4858db041c65affc8a899c3e3350c7e74c6c5668f565ddac38c7fc809664e021bdab08e6d07010001 \\xcd387ace45ef9e685eccb8e85cc4c02f880b25ab89e7a76fbcb9a695285dcfe3fbff41856509347072c1be2fba664d146eb53573a00b8501ea60553fd36a290a 1667126057000000 1667730857000000 1730802857000000 1825410857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-94 \\xf9d03685962b549c21d1182887ae034671adcd0228939ce44352a70a10a3157e7e0715d5118597e70ef91c962e013b3bb4f114b14d8572103a13f613b1075867 1 0 \\x000000010000000000800003c4164a5faca8af76b21367185818061fbd114c6374d1232a0c0f8207508e2fd81ed448cda94bcb135dc737c8732cca5f8bf52392ee388b6a850c60fead530c1f325d1977c0b8f831fab8d64765439931bc07a05c350cef79238b38178548b7198672fd1acd85561e7f605b0068200650bdba327095f69581ae34ebd97596d6c3010001 \\x835168e0d608a5b0cd932558cabc5e76848b6bdf82553a5dac0a6c5ff95ddcc2c6324a981ac90534bb3d69b5cd877fac70bb968a390c69f02d0beca92724f602 1661685557000000 1662290357000000 1725362357000000 1819970357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-95 \\xfa207efa5d6f8d7ff79c7d374ec9c5021a7aa1f432a279175f9c96b361ccac4691052cf9a580489553ea3f3540006389e33207d71a350c028ffb0cfa25d97a95 1 0 \\x000000010000000000800003d05804ce28a0032fa519c3cc5b41e2f8c64f6f8ebc0d40c7816763b2903d1db28339ce868a410cd06a14f649700702cf200f94c29e5f84cc5497f32faddee253e53ebda937c75f13809d98c6c945bbcbbe20825d5b9ab72ebdd74e662518ce661fc2116560352850db0296be066e07d578a937790543b43d1fb936d22f2f6a9f010001 \\x73394fb6b89bcee20762d641b566e2e1fda20766e506465cbe7d953bb11904032832a4a6ee4d7e8f78a755bf43e003c97fd22e06849f23a5d3346f88113e100d 1681634057000000 1682238857000000 1745310857000000 1839918857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-96 \\xfa98046bcdc2280d27a45875d5375e22c1efdc4aad97f2ec9083e4f4e10c26e169094851281a84afa6f4619b8a0b11f264676f1a07db70a832a4705a37c84bf8 1 0 \\x000000010000000000800003b21d5d7aa85a14ea9514241ab67920e044f727210d7b3bdbef7404f2a096f91230e2460d529a4d49880377738327161914a69d588def7563f663b6487ff79411629608cc662420208d4e69f8bb677911e44ec76b287e7b5710fe63029aaecc56f96b23c4c60ca372c1499fb2abfcd4092cb82e24995e9b3f2b3ee46416222ee3010001 \\x9a65b3bed421891ce80030bd05dea9efc0cae5258f43f3efd4dbad590a332ec8493103918ea8916fdf82b1a2b350c38a0e42bf9226aef564c7056f19843c9b0e 1673171057000000 1673775857000000 1736847857000000 1831455857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-97 \\x002159e326095cc5deb156b6c2ccf05f9ba12753bbcea770ff9efe7db2621d83209fd97707559c38e77e16d77110454a22ed64777cda311249e7228eff8a84ae 1 0 \\x000000010000000000800003e64c573c2023515aa5c2134043fe2e366bc08cad44ff55dd4e53f9bb151dcc48180c9729a2d1aedffe7994ae3a6ef32c5247ed6b6d43374734e87fd2d1f8135fd13c8379c50e736e140a089918470deb1e08bff794cc161d3832bb5ea4043f2c9943d777f08e7239fc2d696715ee72504e95b6da1576c74af7dfc01f3b919e79010001 \\x31a570e5427cc50900d322971cf1f7e4e778f249748a214ef514c93bbc139535b2a5627d7443405926011d41768c3cd69917593c9657fc9a5c457a47b0a1f404 1662894557000000 1663499357000000 1726571357000000 1821179357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-98 \\x06fdca50a0053f75db67190b567b4c571c6a73017dbe38f03cf87f584158a786345f1c32b06ef6554398a3a74e66c6e1ddad96b759b1b07062b8da0a9961aa32 1 0 \\x000000010000000000800003b1bf4ee9fdcf13f5321f76e9f2a3ecc2d919988af88254b0f803325db7138c51f16ab9765b7be22371b3447e4a6150f64967592548108e963febf98096d1612a6dacbb3d376ac3aa84d34eb1497ef5d8ecf2796643d14bacc47a91ac9ee68f4e3c46599b75b8036a8ea5a2a1b875429c56a37034fcb4f4871920281ba89ebf2d010001 \\x012308c64716fa93516b5f206bf151d97a6fcfaeee2baad700ae259a19acba35add73627db51d850f9546a66cc4c1d87ae3f5f9321bd80107d89fdb87cbe3a06 1660476557000000 1661081357000000 1724153357000000 1818761357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-99 \\x0795010ddd54d43dce255beae68f968fdbf11f502f57c7dee20e9dbfb24d379d15acabb664d26ffacdafd3a3b0518c4d1474b44ee238bf12df4e8b707a6a4504 1 0 \\x000000010000000000800003ab82881c8540926f4815fbc7eb455a03af048dff3152ab95ab12d45244251ca3f6aa4bbc8293004002a51a6ffd007e0052967892267be94005c5d4a75edbe56fabdbafe4c7a03fbe7fc28f94614402c4eaabc74454cb87d5dda7699ec19cbc7f65be0529677ddd308405a4196fb561f6e66fba90a803deb7f25754f93f9f7285010001 \\x509458a7d239f12a6651f960d8f874e7fd32208f82a314659dd83b75c2ec0a386a7eb11dd120b3a5f3148947c3eeb9065e3eafb3e2189344ee9ac34fc2bbd209 1677402557000000 1678007357000000 1741079357000000 1835687357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-100 \\x0825f787347075e059cc8852c33ee7c64676e58ad5a0f337d15c0fe6c7c93cb7a554c4701a39183d02474502eb19a1d4053f0a47a1e01eda489a26e0c4f34984 1 0 \\x000000010000000000800003b91263b925eea583b7052c10ef6e137c4f0a8153794f5939cc26c1db902685590e08e720fc4af2ed88bc482f404c3df9567e102750f0bcbb37e66c75c95307c066ef669690f080db9a03f46264c695d8c1ca7a59e172d332320f26f634d57352366e2f5b2d3c17f305e7cb00528872767380268c2a9835920e81e6fe811bfced010001 \\x177ba315da6baec62a959ceaa664e4b04a047862755e853f5d0b2f16632c3cf8c94fa28f6062bd9031b2ad01d56f364a758133db7add69833c32232214cd3404 1665312557000000 1665917357000000 1728989357000000 1823597357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-101 \\x091db9f52fbbd01968d810baf66b4b637f587de7ae5c8618af48b88791c9672445988663c969e4ca04a661bc137d58a498cf9109dbcd1f6740467bc7fab50e26 1 0 \\x000000010000000000800003d7615e1aae19db2c39250269260606def9a82be85b2adfaf6ceaf70c7af3250b68f7c8db0f64351bad52adae636eebc4b4fa75cb099139b3036f32964ad8682803fae41ee430c6e4728293ceb2d71106d85bd021f46ac367066a3eab5bf3832c8818135ba8fd40db2d1089ea23cead26d089c0d8715e5032e46a63ea80db4e3d010001 \\xdfeaa481022addd86094882cabd607da4a418b54ca4681a37515cde139d3cb915c2970f20b4e31b7210c84fa041e47ea1aa4eac4b5cd53dab9f0253b5b999500 1673171057000000 1673775857000000 1736847857000000 1831455857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-102 \\x0aa5778426446013cc3f3126493198f9302f0ee43e35aedf33ba294cb23a73f022cfe47004a9e09a0364bdfa658b31283b3470d8a30f23c3db389c09f947f227 1 0 \\x000000010000000000800003b05c2529b7f3e864c814de71553b5e387081227a562debb5a790ffa5c17c2930e45fe2c049576fa77f4888fa702c65bfc9d7bd9057e5e07f5b10d058911b26ba07c03aaccd15950e3f4c35dd3baf51a5602d2c01103578c504d5be6dffc12c49c95f50ea1ccd8d482c240d9a20885036b7a8b6cd5029c87d94a00386f74b0e21010001 \\xb43ff7521ab0c7e023aaa5fc3e12730072bb0799439d2225f6299d31d58707db3b17885ee7998ccb4077e64f5bfc78d7b79b4b4940a0d8a3e9cfbba01cd6cb05 1685261057000000 1685865857000000 1748937857000000 1843545857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-103 \\x1021db3964358247664e196dd7d59479a76577d958e86761f95a2e8bd2e92747500a83f7954204daa0db16105fe2462e3dec79062e41fd5129f31c242afab152 1 0 \\x000000010000000000800003c3b7bb08760547ac9c5ecb6b1e4efcef5a4c4e4a8224691079f3b38c424643eb9bc2b3d1e20308dac443884e79280f2a84ac790abca650d760a90291698d637476dfd751e27d4bccb26faaba0bd0cf01e0acd31acd61bf9d268335e28ba5edc940892fd92b6a5820956074f6a975eeea770c137c04fd6de39a0deff3862b09df010001 \\x51825a0963d8fe7eb69b1edbefaf76979d7e36daf3aa2ba0ea45c611bdae1a0a640ebcda6895e04de751b50d9e9e1afd10ebac20fad13e348526fc6fd88f080a 1683447557000000 1684052357000000 1747124357000000 1841732357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-104 \\x1b295c4ec4a0f7bf13da708c4d3cd444b65c2855cc1a0ce993e6e3a9f599f7e9d07adc86d4f7e71654855a88619a9555203e635c7ac66d618d5790dabe19527a 1 0 \\x000000010000000000800003d9d8413881ca6f022376db5d894a17c745a1d184a40079c71d1978cb9f0b641e3ffbd860d78381d37f6d7dd892d35f9bfdde5c09d8cf380113e4e4af11f9ad92bbe39a8e2a5cf28b4cadd64cfadc5b5e4d94943d18a9a6fbc51211f3fa1edb7a08a8de4292ac6c65e591b293c091d2a7d2424809f947cf4a5fccbe20b57acb99010001 \\x4e74f81347a647175b25b55f2c9747ba5d30a468a116819491e28f80bfd2873c7c2c07b844547f37bbe81c9a9cb91b6ce7d2bee2d50688e3907e134f55bc1a0a 1668335057000000 1668939857000000 1732011857000000 1826619857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-105 \\x1e21b19a7f47f92ca26dcd063e2d09f78a43813a9b67d1e2523f0ad324bb5aa90bb688e8514dd965c448504379517772d1988c2c838051e5c500a6abd2110708 1 0 \\x000000010000000000800003eb1e37db4822ea1b8831b4ae2041b3e71cfae6389da3dd1913b299cfd1c768d3a475cff94045981cc2f53ff5c03cdfcd59e564d4b734ef1a937839ff85bf825f42b5aac49582951d4eafbd16d06e6a39f2dae2a50c328e7db83754c6b42e1ff6953aed476a133585cd95caff674678636fa48f18dc91cf0c1d2804db81858591010001 \\x0a145c5e5c28b062ad0194cb13c3067e43f551e4f644041784dcf537a7d5f3ff151d989c3e2c7ad64f865ce65c12cfc46da6e8f52d7d1c16d4efbc24a9ac240a 1681029557000000 1681634357000000 1744706357000000 1839314357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-106 \\x1fb9fbc731022caae79f8d813ff1d1605cbc4fbf70637fdec90ad51d882d6f3b2961c1efcdd2b27e7116da462bbc002fb259d4db60b53b4c1a9e481d220ecc3d 1 0 \\x000000010000000000800003c5475a0a1654c39e3a7f129eb4a97f9db3340662078638eac15c02062ed01e53fdd12b7dc54d2d6d90624ac80acf673d9e2c3d1752eb74c7d3aea9531d8ab5c4475f0bba9b3392ad1760b529555625e69eac3d053a22f1d8d622ec3878c4966035b28d453324cecaf00b2c0176d6cb4067d1195e32745f6eb006a5d57582aa2f010001 \\xd1162f5404d900bff85835cd7df24250dc517281ab226d75cc291154c94729f483ca95260b986caf69ab1372e76abe65dbb979845c9a3f6a908c12150088ac0a 1665917057000000 1666521857000000 1729593857000000 1824201857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-107 \\x2091412a4ebd585d49ee9f86be5c26ecc807e6eb36703c6602f897d2894f93a135eaa96e943dff72f685f40182efd075045a62336003cc8445c0fbd83d393747 1 0 \\x000000010000000000800003d874e6c407e98928ac9f3627822132438654945e9f45cb438234cb789bc975e014f737b045156611c10f04d343396ba8f2a8735341c1f8a8cc213c52d0abe1f2f66e85a5efe26c0a78b679ec78ccd1684ac3403e11828bcebdad5aa33989ca8799addf404e7421f7b99db321a3c51a75d4bd31bda2bf30ae4f1e505ad03dc0b3010001 \\xf1843cdd834905fa746ae26ce0eae982b26d4c9857414f85ee80f1ee98cc5caa9c5e43c07f7d56ad16244c2909c3721c7580993ba9869be25c1c6fe994d6800e 1677402557000000 1678007357000000 1741079357000000 1835687357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-108 \\x21cd9351bb3b66398a79a5ad37a506a87c77bd15ffd68275f17e2eb0bff3bb7cd85a9435c545ea656887569ef22442c08799c647182c8305fc8a844f01cc2884 1 0 \\x000000010000000000800003f0099c35431bfed22d6d361cdc80610a6b2a86f5a7359bbba43dd63c6962a21f9049efe39712d41e36014a37635ce8fbab274c0395cf9739f7eecda15d8f2e7c437fdd58cd262aa3698787e1e48f6301f358fea3f58e9afa6a59904a612de6ebe7629086222ed7354b7a7074b5aee2b2fe6c51694250290427e3683ee8d15827010001 \\x918f7fa46192c9d39aee43c649df5505c7d334a5b3f3d5fcc0a2c334d7552bb99b5e5dea1798ad3275f61de0bced571bf11a92585b39bfbadd779e970a788607 1676798057000000 1677402857000000 1740474857000000 1835082857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-109 \\x26596db45b09e628bb954f25fc5ee21176930d66d4658b28528ef4a617a08f52798f970894e2b74691019b71246ddcc815db35e6045c2b6edd15aded2cb36555 1 0 \\x000000010000000000800003c9dabc5da2846367142dc6f97baed82d8efa236e225d80ea4054e370b4df8cf6c7ca5ae960ee954ec3e2f2dfc6b06e58dc4ace80c891504dd8f43bc0b6e74a51a09da44c47d5b72be00f609b8721a698677d73e0ed17e4d93ae9a76b312e44849b77cba63d825d130245b223cd3ec4d99c89d4f9c976e524cd7a6ba6fc560d49010001 \\xf4d1b39d31137540f5c811a48511ddd0c7477d0d5f94ad5393e32b2e603ded61e1291b74d46b58b2599aa724e6bd85be97732ab484de1127f13a737a0e069107 1682238557000000 1682843357000000 1745915357000000 1840523357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-110 \\x2ca981b7f6ce975fe9d2cb9a96b6a2d2ae3a152b997da22b5856a3a43a3c742dd1ac1b2a192e3ac9e764f6982543896804031b679b0bf7b28fdee42b36b482ab 1 0 \\x000000010000000000800003dcfa3e94f463579d941c48e250516a1438343697edbd1a929daddaacc1d80c14800b1b66dd0eb2f49124df0d6a9226b896e2edf2009f4b5d2b3a9d269604e3c379ae103d6b9f1108050c155605cfeecd48083e68cebc8056c8840d02381d5cc97db244417d79e3d39fffc74a6dfeb22e75508cb2d5ddfba5280682e51f2ba9ad010001 \\x51bcf0fd376c2cb86853730e83aa5737efff32a5556df7aa51b2abb4846ade170334bdc71070b50ad16f4fa3a8821da561cbdb091d12ecef8b7bbb6993729e0d 1666521557000000 1667126357000000 1730198357000000 1824806357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-111 \\x2cd9de98d8578ea8bf5f20f691a8373d68b43d9b8e3aad2c0001f8498c79d1da87266583a394aa985f358de4291008f8aad50188df8ccc54829dc1c338abd551 1 0 \\x000000010000000000800003c648455715cab29edcb857b6a5230c4789a965352dadfbe00406ada1bc6854df744a7b666fa0609a4f43c1470a92a27ec0a7a79d7c4a2cbb6e001d8b756e63041398933f910e620b12de50b45dc5d363ba6eff40a2a372b548e225a2d697af78a21d21c9a194c31941e17c97f63873c01784118c470bb1e20c44f54e2cb50453010001 \\x387c58eaa9c7d6265197649831be4df5860bb16b914fed7262b5752be73a39d99d74352f03024124029c914409e5c78d83b616e2ec5f57ecca1bde21f48e9b0d 1659872057000000 1660476857000000 1723548857000000 1818156857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-112 \\x356d338a3bb66f9609ff81af2c4f9539b8dc5eecaae99833cbc3d5d9e7148ce7a872c90bbf39fee625e54e7de6e3cbfffcca106b60f6444da2d8e659d506e25e 1 0 \\x000000010000000000800003b37df85a536ee338f0d7845953ac436df797206dfe124dbe506b22190a46ead429030effe65b9e67458e335de1a66c42626d962c1007008ad95e09be566b6531c5575daae93ed5359a97fc85c20e582e3bd7ad9c7c1e79f465ca38b2d8a597a5f601378c5af6e7c39a8c0d8178313c7eb8b85d65ae7b4ae800bbce2d9260b997010001 \\x9f1241c315a96bbad6fb3019f73cad100dabf83adb93c7246367089885da7375e1b3165e95bed3fc9c719dd04b9e584efc5b69fef6b22417408ab0a1f3ec4904 1673775557000000 1674380357000000 1737452357000000 1832060357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-113 \\x3551f17f64de8123d0bab3043a3aa8388fc443e0691cac0cbb3e557603203ea56942b085527d139a42cc78d58f9d042ab2189f1e3295cb95c2281373b30884d2 1 0 \\x000000010000000000800003b2ecd49e4976d24d9aab7ab4adb4234770a32fb8f99b7bf835c1abd561857d40013860053196fb9687b1e0875872c03235bc0fe0c7d29f71400faf6fa05fbabe5828a4841ed4913f88cbb9ef2234eb6e5258d377116972d982fdeb90cc11fe22fe8f02b92dae8a2d616fd080c57c2b1cad73676ad3116afbc7429d3c41d48189010001 \\x3826637ac96bcfae8967483cef994d90416c0e0f534f8605e463022df73f1d9716fef62f77353ec6c1b3458358fb59998578ebcf524fe77b2196dec12b6cd70e 1655640557000000 1656245357000000 1719317357000000 1813925357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-114 \\x37f9152779005cfff96a2967bf59f7420d721474edbb1b1d8138aaf52b5c351c3905e3a6848204050eca6f836a41d9798b3104f75208ba0605462689e427f7ed 1 0 \\x000000010000000000800003cf5847fec81eb30c1244adaeaa0c927b8f49dd3b4bbe24893462129ada226e8b8333b11f4b077490d1dc897c0ed6a7f38678d2146beb762d8c89267479133110f25e998b206ba99730e6b04598818132c49c513c902c60d495008fab5f31134abcb95ca1c01c47979672ca2f051e5efa55172b204db21de98900a0cd2b40fc97010001 \\xfe057c87a9acbec99e751513c595ee54d0c2ba7b94c9106da5c5063a931b4a9c9f16a228c209da16eb1a4593d55fcfad88d6962755ff1beee5e5dd4dae82030b 1661081057000000 1661685857000000 1724757857000000 1819365857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-115 \\x39713e98b4e02d2442a68954f938245aa15ef7ba10b6b297f9cdfcdc63720566dd9cc921b603b7e1f21a9a9203d48bfe764f72e52242407070b0c09d5f540585 1 0 \\x000000010000000000800003a6720915b59aba91f8730a10662f5777bcd72595a94203633484d09d9ef52d48e04d1525b10b29aa013f8daba3ee896cf6778c14d49082a30a2c10ace8d9eb7629c73e6b2ab83cd00243c0a77857d8278b11fa70e8cb0ca8620aac4a92194d859b0318cb13c550ea9b1a4410c9219ae9a488f70ed3c22c5887ba34e86bc7582f010001 \\xaf6cb9477480a3891d940b29c1c82d9b79ae1c986668f5ffd82d71e94702f1e5eae7399490da78329116f67454e8d9ba4cde546a947e74fc9ed1aa77d6b99a02 1658663057000000 1659267857000000 1722339857000000 1816947857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-116 \\x3a953e90c624d22de95b34b0efd3d84504cb27f0053fac2ec96b3d58b9e231ca2a301372e06c3859485491cc7140c53cc37f54eba604c8f3a53239e6672e4a8d 1 0 \\x0000000100000000008000039e959fe4970421b1f69f2efe9af0f297a43460b291f5044eea14cd9bcaea89c21bd7b8dc7039ece4c977d83bc299dd1e02a5703181b7cbcf54b2c38f15f0d2c4ee5f310b8d26e84b8087219e13715ca7030afb9b22e05e07e5a27431f4565ef1b7512f6065d94a4ede8cce254f612ecdc02cec21f10feea5f06a47e69445bb8b010001 \\x1ed1221b04af50cb9720629ce3843a96877f205131728595fb3cd8c6033ac0708b213452754381f904662686045eed0def8b39870ac02e925a3400c561a2d109 1678611557000000 1679216357000000 1742288357000000 1836896357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-117 \\x3b312989073291c6a421d730c446f2cc1cbbfb78ec133977bfaea69485238588ff1a4ce4ee5dbe927abbdf4f173bd35c116211d9d9992eb8b9fe9e48e3db4ee2 1 0 \\x000000010000000000800003afa932dc6de1a29310e96108d9128b5b2c908aa2e4ce9cbade9177e7b2e0acb7549a6c80b08d5844e7c6eedbda45e6766e1400506e97cb26367981f1936976bdade84751ddaad66a0c4108e5c1e0e0d212476c742535e354632e5afb9141af2999c566eed83f223bb06f59a8a7336088990ac11f494321da7b859ef94e002869010001 \\x26a60fccd043d90e7df3500f6f11a3cdf9dca27a256e317462c6a6fbfd83cc0b88e2bc5aee76278498192255352970bc76df9aea17e1a7f4de4a4ca382a97409 1683447557000000 1684052357000000 1747124357000000 1841732357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-118 \\x3bcd3abd3aaadabcbbed39af6123904b2bd5e4c5ea05c7b1ffa552200265c740edadca9d6335104ebb82dffc1dd815b730ebb97eb34f5c041608fa3e32ecc217 1 0 \\x0000000100000000008000039937b865211332d57571a6038faac660c3a25a5cb3a1ed58f7a415ac7de90dd403f45f0c4f5edbbeb353f14f8e9ef96583ca6a81f689c07ed8a9590729ff5360dfc4ba8aae5b0fc5a5c5c1cd9fb555bbfad774df2ddeeec68103b9fd9b7a5966e3d187069570e3303c0cb4bbe9e4c20fb8c9f0b8e993429633f92bbb42c4796b010001 \\xa16f4aa7c1d5ee6e99c7227d5f3ea60513a4bfa9627d0e179bac384c97a7339f189c1dd035c48401263b678f98f1f6e390fe90f21ec17c014b1562c502bfa505 1678007057000000 1678611857000000 1741683857000000 1836291857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-119 \\x4079602be44bee523e83be13d503e63543548a67a3fdf0fd186467c06b7ae2719e765f77d814614a57f06ffc8206163084c784ff9eab89599effabc0651cea7d 1 0 \\x000000010000000000800003b375c8dded8859a4555f2cfa5241d17a736b11cf472a57d117add1ed1df70c4d6f1678f714a04b80882a9ce88a7b8eed4354c67b9403fd1febb40aea58dd460ccc137db49e971a6493c9e595dd4b03adb5b1c0ac1f5c5c5d81d7f8bcd707603baa32eaa2414ef8085731d6f1aebc24e15305d70c407e399808ec8007e3d666c5010001 \\xa9491e3a6e6c7ee9d370b22e66b8ad7e8fd98f81e8992b29e2d1cef9f6f9487d324958ad12e4b3ab1fb72eba06df7a05b61f056ba6ed4ead6cc4a83b6d0a560d 1668335057000000 1668939857000000 1732011857000000 1826619857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-120 \\x46ed834788230459b4a0ba27abd7f819257a6f6ae75b24dff882b5beea45484f4c16d9f19e72b283257ddd9711cc246c843da42e8dbb2c3a9ab407bb516a6195 1 0 \\x0000000100000000008000039c87768b37c61055b6ec214d56db4e8850e36fa45d25bc2183f8538e7b9fe72b41a65df2ce4eba1e989a315f246db1f6955051b35a06830112a216cf8cec50043abc9d038b690ae76b08d841b8ec9574be197578ad12a28b4760fcef235c75720c7a3320b5f94d83b73f3626b05d4023a15da8da7017e62582879907b7f8a473010001 \\x883836a91cc56ba3d0fa236b27a595e479db93eba10849d2d460fc0106f48c70e8e4e112e34bee38bb3e94511f9b51853012980f4532df72b521b214a4ab0008 1671357557000000 1671962357000000 1735034357000000 1829642357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-121 \\x47d9eeea0206a2a537172e6dd06ad99aa49f8c5def9b2ec3cdd95b8eb8654a82a6d3bc7147b06b91ed2337181a17fc25bea94575a9b0aa1482481a8f1ba9904b 1 0 \\x000000010000000000800003a44ee4747761f2f0d817c59e1ecd38db45ae9e7197837da15293a1da95c444a52c6aa5e154bb2d1067ecc07df10d6210af32d97357cdd8498cd2609a82b768abc6137df3cc73cf5382c8a9e754ed7a57630a554e4c7d60ed087ece802ea9a313838d0f7985165a0ac27ecbfa1078089472963fd077d6c050c735caad4b184b4f010001 \\xc06e1d4cd401fc5bc8d09d16560c53d617fed8da3db5a30b8b20a93de8750c9624cac5b5aca92f2ce825192d75907aa7e2f6dc9664858a12a19604cbbac9ce03 1658058557000000 1658663357000000 1721735357000000 1816343357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-122 \\x4abd1efde328ebf25c577e560285d90284eea0bc5bb4329c0130fdf1b3e9893bbdd8122dd6ee8a22b5d3e7c04055cdb7975fa95a69809f69dfc02432c8eb3553 1 0 \\x000000010000000000800003d85a88f45373f3fecf6d1ee0b80c6590136ceb025cf4e90a42138e90b56172b5009fd404eb9e0bdab7bbda30fa37c0f9cda586a1995f3df8bb1992eeada65a182ee85cb6cae51c9c742878b10552c7c784c4bc42078d25b8372ad3946844f37822362d971fc1f92d1c36fe1e4e8040df99838fbde5adaf92362a616d781f081d010001 \\x6842cca7f77dffb9e9ec728ed1404d7932618d2c7af08f966250b4ec1ef92b5d0a9385e88eee7cb206cef22927926bbac9cf276274cb7bfd02196d041674b209 1668335057000000 1668939857000000 1732011857000000 1826619857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-123 \\x4a81bd22c8b8f336e8d065dbfcfc179137de12c1e259a84c351ede689454444fa843873ee898df213b5acb94f6a1ac4f7fc7fe2d56df3d043e9763233b80d5c9 1 0 \\x000000010000000000800003f422878cd23d26b4a065d8aaee4909c88bebc422f5ae65116a72f91b8e22afb2650b82ca469ac88d1b5216c19cb3966ad5b5b2963d175edb09b737e7e8d887f7b5d21ea16b42a73259ddf72735b0b77602bb49d424049df71d6ef709a5d5407df8b73a15d801ce6e1d82410aec836ec5ceaafd1b8aef12b1b68e32cc1eca3bdd010001 \\x9b1453988e72c5d0893908ee063c87fe102ee7ddd1b15eaf92947d9770887fe28000f856a69d76d5e8a50f39f02492ddac440409cf364ad3db662feb6f0ae308 1682843057000000 1683447857000000 1746519857000000 1841127857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-124 \\x4d35202732272c48ca0c465e6843768bd6278e93c43088fa39da8fc34d5f4aaed1770bc3f815f0161b105b289e5ab57670eea8b9931851ab7f37641106f336b5 1 0 \\x000000010000000000800003bc4e1d3dd2e8ea4f0deeed8b2080b5389d0d846c18c2bfa26a7ecdd274d84038a1ed461860ec67ff6e21a6d2e00bcb5076d2a1ce0d32f75dcde3ca37ad6054d078fc449b7cfeb6dc7d57d9122b01cd8facbdfa43166ab9edfd05755504c6b01bdd16f30c85703ce26a0b24124268243a4730d690faee97aa2dbbe1b38a98baa3010001 \\x552d3fb384fa20db072647a37d4cddd33225f7b74c55bb1863ba6485c81b523874a6695100eb4d541635be42b863e4f52f8c839e38fb1f5c4f9fa49d66122902 1661081057000000 1661685857000000 1724757857000000 1819365857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-125 \\x4e29b47d4b6a4e3fa89032c736d99eec11f8844b2cff885c88a1139ab40acfbaf14f7396a34405f0f3a7cd77800a90f8de02fb4a46040266c21e098dbc0fa659 1 0 \\x000000010000000000800003de37021f1fc1ae55968d18d6799bbf677eaf26004abac5b48e83d2e0ac6f8faef07c996715eaa23113234af9c83b1d77a5e51544f65c93ba8ff40c31ceadda9c7ca74eceba1cf55d685ea88f58c6b721d0abb97aa955444d755462aaac9dce43fcf2f4f201d3109cc3e0c40ce916526fc09b5ddcd16190d4e7ceb8b3f8d8ef05010001 \\xe676888d3633fddf4edb2aaa3c0e724cd30f2c8980b24fd517d90711c613fa91e4dd3577921f20ccf7b18f275a5c3f3fd2ba665e46da961623e7bcabf42fbb0c 1659267557000000 1659872357000000 1722944357000000 1817552357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-126 \\x4e11bc41a2ad385078df1c43e6c8fefa1e193bdcaba2f1abdfffd1cf13dd1b81ce5fac5ea708b6eca6bd4fbe59c0978f0eb6d29c50957ccca20b0b2901f945b1 1 0 \\x000000010000000000800003ba522b37915d4e6f8ff8a4508fb8c0d64ef8ac116facf34bfad7d28c30f176fba57a54a3414ff96d41c2d6943e90aba13da94809703cc02c330570a21041b46aa84045b5f35d7e9621f575a3944234ac6637f6526a59cd7e603b3c2f37a54d77aaf51456acf9ffd85ebf627a39960625e7fc277ed6c117ea9583eee2335c0a8d010001 \\x06377370a8d006e82a1050bc5bfa2777c3f5c789a5d1e7c5400c03640157e3828b03b259e0fc7e09d1748610c695f47c0881ac94829e7e5a5193bd654b592f0d 1684052057000000 1684656857000000 1747728857000000 1842336857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-127 \\x53216ae84bd8b98e75326ace371b7af714bfce0a1d4f677b545ed715e9e67bc5888e7479bf7516a1b8202b70286a62d0cf765e0ed7c538f6505e2160d53c78d4 1 0 \\x000000010000000000800003c212465a44040bbd728809daf4549e5344881d67a3f3dfefdb51e84d0c546142e872fb1c971d56f95542c1a80657dbfcef5215367587d55fd857737718a1caf7032bb2b75fedecd7ace13675c0c221a5c00953345f80d445d23558978b4507423ec2118be729efd4729be44329ffecdea3e196588550ca1805f7676ed0b69d7f010001 \\x9e19b1dc3537a8d4f667f59a0efb6c4595b7232d18e5112af3fb5c86a6ab307ccc12eae1bf454688e13eeec52463e853b53511b278e3ad9f2aa5bbf987657308 1675589057000000 1676193857000000 1739265857000000 1833873857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-128 \\x54e50b805e502b05dc89fdbe4a7ed2ae95d56b6c6d93310412fdeada00dfe2eee9c631336d9a13ca38b9374301b88441c76331f18cbddffaeb2294f8184412d3 1 0 \\x0000000100000000008000039a89d56f94f5d098e6729d38fd1de69bd4a118fadd1149aee1fe9c4850e3f1daa2645d35c03490449875182198b4edc938768e4cbea13261a264e9d5d96893b7cedf2dd4f3091be74612ec23901c85b3932ccc356a2498b659a4691187f4a41b2e31e3d442b913714dc9529e83e5dee648af7022df9f73ff7d124d1f6c9ec2f5010001 \\xbfda14e94d7fb577fdbb51260c8e739a1a6841a5e9091c6fd221c2ca3c6b0d10bd2d3710a92ae3dc4c1f21638a847ab9ac5768459944a92149beb8d9f6c14307 1655640557000000 1656245357000000 1719317357000000 1813925357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-129 \\x562dcd14e56d1cb6bd37f946b7c5ffe64f3c5c42f968b3104483f76d0688ff10a30f4b127be74c3f49ddae0f62a08bf5aa8364df8e34ff92c55d2e4bb8a3fe89 1 0 \\x000000010000000000800003ae13cc144ec828147efe255ba341e8a736115256f851e6a48807cb5f645617a3b6e23a249de24400625ccaaf2d234717a8ce58977e6aa044b05b60bcbb9e966f84b1338f9776f9bc153939031412c1b7f1e9095c6d61acb3d254466c31b1ea77e3cd3603f28341767852d4c6da79d91f6ef09399fdd3659bcd91512de64e3b59010001 \\x267fb9a17e5d402d82a27b88c524aa69ed1a326063946abd2ecd62a44c8e3a6b7da3853cd1078b9fe1f1527a0a0d5e3cc40b6127eb714984f6d6a90132431801 1667126057000000 1667730857000000 1730802857000000 1825410857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-130 \\x56ada0cf3a841716bc1f6e59bcf274c494d455deaeda7ed5dd9818a9abe5081a924a1a3ea8d10d387be3ff1a6ad960f53fb84616288e17124eafeab39a7c97ed 1 0 \\x000000010000000000800003bd97aa2ba311d69bcc37b1f734dfdea5318128f8925a10b9899926b8dc026d608ef106178c62670f1b465e4f0099578de1c3ab73a7e3966384a2f7387d08f13cdb05eeb3b7f5c10fd05d8104d173b4e1659b73d7447a6362e5ea079c22eb24161895a5f931054e3daeb24189b0955732b43fcc2b16d41aa90e8594cb4366e597010001 \\x84ce96ecc16cd2262caa418900672cf0eed923c4bdeeb2867eafb0e48b6ea55ad3f886ed3101755c54deb240a9108133b5636a4ef1324b70978f70bfcbe07b03 1663499057000000 1664103857000000 1727175857000000 1821783857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-131 \\x5815a8794d9e95c7f07be2a42a3f3a1fbc1ca1f879182d4c8438618abe6070c56fe3bb841c4e5406b6c6ce5bad279ca109de482d38a342f9066cfc4b74fd4ce9 1 0 \\x000000010000000000800003c03f06e4335c3dfdfcb8d73c06dcc5d2b603e5895203dab070e36967a709a2660033763805742a17541529042ec156a18071dfedaeebd51ffbd41c78a02710ace862c7f61f89885187d6a6c19dd5b14d26600b116abf6ba54274e6283fa796418ef782dea78ee8cd651e0d2683274801caaec522d5ef3ea378a0abd91291de4f010001 \\x9282fec18dd670f3ba82852edbe46fcaad85a9965ad3d9bab32024c2f803e98664d6c67c1bf550efcb4634c4c0a7fd903107d3c2ef6115aed1e4d142ef525905 1687074557000000 1687679357000000 1750751357000000 1845359357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-132 \\x58f5e684fb2cf931f8b6c854451f7301d9a61fe49e33bd879354f085a85c70bf9d0798706870b91f475283f1859fd0127ec2d3b136c9a88d4b9c2be4ca0106c4 1 0 \\x000000010000000000800003c9a18a69a2c347549083c3cff1f489f602004fdf0db99091f7c108a7f8e913d7a4e8f56652b9e7d929b483d2ce34b2627aeae74c8c9f820f69efb0b757a0f902ed3aa45bbfd5c04b2b835d483092c8977524cc68960e754667d4fdc6baf9ffc18d425083a22b88804ac0fb878c29031d03d6438f1684973198401e70ad28f3a1010001 \\x286343efb30fa73bb77cba6cf18e6b555f3a562a23c0afe9c6e4343df6e4dfb19515febf2ab7819f85f875503b722e72a15955474ac92a665f979a9dd122da08 1678007057000000 1678611857000000 1741683857000000 1836291857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-133 \\x5bbdafd7819668cdeed66a839c3056fc723cf502677160b71da44da759275c248ee16c526ab5f3452a77530e90befb81d0919c188dfbc51702ed583915c423ed 1 0 \\x000000010000000000800003c929b71edc09f7ebe8f6c1ad0150b7cecffe5ea93556e7b06fd67c0699a24d49be8007254006319352e1ad55e4f9e15ac643df6b965d71fd7bee8cefc94447abad728620f397eccc1214a88d213e433760d3f60209579fb1dba5e197966b42e6573e50639143d48953d15491af1b75b846b9ec4551b5c80b3fc567916220f955010001 \\x3667565c12a2ef40bfd78ab08548e2aa0726bbea31f560d77555fe66a0a9339871ca89adc319cdbe87b992aca08dae474d101bae5198550c8bc3bd69ba26c003 1679216057000000 1679820857000000 1742892857000000 1837500857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-134 \\x5be5499b46342e7075dfe19cdf76821fb3f752099aed89eb4db11c3fcb8718b8a202d608d7a1b9f68bbedc26601ccf0d148a3a5faf24ca6a7aaa5df1bfa33ab6 1 0 \\x000000010000000000800003b194f25c55df0e3405e3c7fec75cebe80fe14e2e8730a45faf6390bbad34ba294dc54410d96303e83fd164f6a35ae8062b0a179025fb6c9ad11fa088fb2cd84e85001aeee2b44bf7891f65f8d4e8234ed6904ae4ae22600c49250ae71c57538b295482b717ef901c7b164866a5bc927695aef569491b5f31c1f986ef45ab4b1f010001 \\x691cfaefc59cf215eae390c4fc9c749870fcf89d2b12d665bf9c50612456d585d25464ac11768312d5ec28f00aa7444288de1d482225c272df324605922d6508 1662894557000000 1663499357000000 1726571357000000 1821179357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-135 \\x60994712e683df157edb73907aa4eba213323e83448f69fc3cde4181e855e75d15fa53586a539f05258cacfd9e7764569d65d01b836e63db731ecfff13a95892 1 0 \\x000000010000000000800003d1b64ab5cae393d3a47e27a00b072fda74d295546c22c3d89dc49b4a25feb6113a22d1cf856fa790064a7cd34143546b9e6d8a220cf6813fedc71929bf5902e21ec567bc2b9514bd4b89f8179e2d4dcf224e763b232e5a38706f8b8ce46b931e217ded67704c7880abe6ba82d6387dd4f405cd4447169fd337c11fd8784e7c5d010001 \\x6b7bbef59c8a43a8eea16d62021a57f4c09d3a9a7891d1cd7cdea774e3bcd4e0f6c69230e0caca3aed6799024b62540377c890a2c870ce2d97ec5aa55265f809 1661081057000000 1661685857000000 1724757857000000 1819365857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-136 \\x6435fa26159555178e3b0a42c0674d56c1c1db199711e23c5c6adcd21859a42634e2857411bd408a11850f05dacb67bb8a5dc33bc9efe5611e9ff7d1ab63a9d5 1 0 \\x000000010000000000800003f51e9d777b8e30efa64ad27e3b439705b3ebc3e9816a1fe4ddd473243b16544dafa144f6b3c58c2ab898d88b65e3b8158e89ebfb439e31043519235857583a875eb86904f2697b12d1ab3dcf0dd1a68d03852d10e9f83b2c6249f730da4a9cb713b43bcdd9166f12ab06d973182f33e9c0c9c130a03bd70303ff68f89cc4eb85010001 \\x3c5997763756aa529268180ea8eefb869d6933b4bb8c7f7a7894f1ba22303d75f205f9752af814a4fd8de8e08d2e676afcee69914d8867b3aff2ee70bfb46a03 1672566557000000 1673171357000000 1736243357000000 1830851357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-137 \\x656584268365cccebf4ac3725f2ed7c79a3bf352d3e2d57fd68eb0507558f57ab895abfa0f489f8b1642e6c483d834094ea2874afe5fdaf7f833548ce0afa70e 1 0 \\x000000010000000000800003d178f458ea4e8f240a854f0fa1273bdb0d165f6f6fefc6ef30f865f6f719f248631e0d4af0d1b50728b283a49f2f40324029c99d906dd99330f7f38a7ce7cfb89b7e1caba24dcf248cf9e83948cba562b6e083308c94adabb6e5468618097c20397c8c4ef4a38504997261c641c4de678f11fe7681b6a070ec3d0b84ff71d1f7010001 \\xd290c104facec80837f9e80258b43c9b06ce9d5ebe4080a99a9e147454df19c7da60c6e4958c863fc4c56b571d064b68ea815c30bdaa81e6f943b3159da83805 1685865557000000 1686470357000000 1749542357000000 1844150357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-138 \\x66c92336d79bf38804cc5258a326662c93c9077b79afd000abaa9ac9a80b6be2f6deb0baa2d31e6522cbca3aab039068ed7bb3cefc6c4a520219fe90fc46aca7 1 0 \\x000000010000000000800003ba0efa9dbffd8ea9981ed3d02bbd875b33e74de200533f8fb482e4ef7de406f1fb7310dd5f59c7101c8d47aca00f5de782943001f3ff99c443ac04f57124fbde556859ed4c1186333dfd2847e3c7bce5a837fc05ac5df13c8b7899fb94bd57bb87113a8565772b970e4cf40b53a1179734cae180912e3aa5d273810b4f01fc45010001 \\xec1390187dce8cdcca0a8139ea2280732f7bc0eccee53765a054bdae62e12df1a2c6fe4690970030f81e59d67d10de19f719f3089faf7dcd54405380a0d29902 1665917057000000 1666521857000000 1729593857000000 1824201857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-139 \\x673521981556dbcbd24d758c5813d228a3208caf11d885876c6a8a392027b836e7d3edad4cf1091d97c8f2d3ae023d2696a04207cf458432378dd1f5fe02cf91 1 0 \\x000000010000000000800003e640bc2727dddc2324be7e149854447b2541fbc8668f1fb1e08486c6377c89e06cb4a1015148998bdda10844db274f3445f2d8e429941e0a1861c572fd99cd31c836cea5d9a537648eaab30c11fa4d0ab4574ab7f91dbe2f4922ae2f07ab89ac7f530569181879d0c6d0af8661de0fa44527be535b00c51e819dddbd2c878a6f010001 \\x46971480bbbd9f9290d61e6aff1e9d352a44434e86bfdb4be17e7825882d99e39c559d594c0b4ed4f472609ae6326ab7f67215dda502ccb1aba1c607406f7a02 1665917057000000 1666521857000000 1729593857000000 1824201857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-140 \\x67353b12de56dd71d3e680440ee1bd5bc22a2cf71c6b65e5fe2dfc26ca2d336b5c6a895ebb69cde321c82ad2a7b3a3fdafaa86665ea79294cf50c4dedac2a6ae 1 0 \\x000000010000000000800003e4abfe8d355a227043bdb0f16858a839da7abeae45068cf6e1bcba54529ceffaac8fc6f2dc74a3597a270121b4d96b92646ed3f648663c895f6a809bed31442ffe94661539426e4722c8ee48b01c863cf452dbf1bbd1f55b8b63e1772e6902c82d45d508f07b57634b6e9948e5118e99a8585e0ebd8ef3bbe4192c75ceb4d927010001 \\x21fff547b798021daa301d65ce386be5a89497dd02170c3ad9eae5eceddb36c7db2369a1cac6a87bc695b621f3a17f76b8d05f31e97374fffbc51fd029155807 1658058557000000 1658663357000000 1721735357000000 1816343357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-141 \\x6b99fc505e77807592807c61b7bfe89995081f24500d04c6147cee5c85c9832c05e889e277782345020e5a59c4902e2817829bd5e08764e8f54404fdbe72b153 1 0 \\x000000010000000000800003e333aa5b3147c54e4d065269aa48420c3eb187f6b9b01605c78258f39df91b496d7b8663da5ed550b6f17e6f8800b584a39f8d93c3b4b74a204af4043cc958aca5e1a8cfdc82d31c6df99c9db5d01de1215de204b26c736c0b229e4d83cdf10983065121d375c6fc91ba7b8f752d6f9a76ce102a45bb773f473d6911df5e344f010001 \\x70761137410a1aa6c17c0a7185cc72cb905b8cbcfd7a5625400c178bf286f30b4575ebcba3e902bed2532c36bf5544b2481ad18fcf4e24a62405a39ba3b8f208 1682843057000000 1683447857000000 1746519857000000 1841127857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-142 \\x6de934f478a00e960f765c6628b46cd9939f9b48f70c2f5a797b1bc81dd3959253065e15b09db785433af8947a053a81e721f166fb6833703af8380d12cd9746 1 0 \\x000000010000000000800003cbd61b883221d0676807fc3478c4181a7c56117b37e8ebc074036eee4d5d2dc99da269b6b7c2d91f449f06da7d45776bb30bd1591f42b02102be035fe306e7f0daf2f175f5bba642baf55a7df05d54630f888729931c190d6ef45bd171e7423abb438f3a363d82a646542aba39fb3fc71d8b43046e87fc25158d52bbfbfcf21b010001 \\x9e34d00966868a32a1041f9b2c9f08e0830123bbca63309fb5bc4bdba5097af983efe5cdc4c53eea5d8c31d4f241739c62dd6ad8c4c46592ae26ffb3c813cf06 1684656557000000 1685261357000000 1748333357000000 1842941357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-143 \\x6dd99641a73fd2120997dc063b2b3ddf9149ef283174bb8efc24c9b81cbfc0433b65edf47efdab1e1e9cd0a0e5a61b4a1f902d9bab82772fe567541952af29dc 1 0 \\x000000010000000000800003b338514ab900a0d8226f7506a1cc9d662938ca964e046897343892ad244e6ffeb0dfbb392f9d0c3b7367d1ac70a1bb23f931cebf031e7243cc94ab3baecad5222e87e7760423011602ac32c73e315cc1d6695bbd10f6563fd254de29d665141b921579dd3cb1fe9cfaad1ecc04a7d3b67362d6739af793d3e90468c5dbb755f9010001 \\x3cde02595a73e6976f30bdb36c87704dc53ada712ac005211790d3df18a3cb24d1cf0ca29a5d42b8916e769bebf73a1465928c8ae74acb30ad0b9e4d50c9d70b 1662290057000000 1662894857000000 1725966857000000 1820574857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-144 \\x73294f01fe40e562db112ffcb1d7b1d2825d0bd4da3f0f26922a82a1d5772e46f068d0fc1e616f975ee6baf136526bce1d7696e627cc9c5c3cd9f268b14e1f5f 1 0 \\x000000010000000000800003db1d36f4309faa000c59b35483afc98c5f08ffd18027c0cd9dfa01bb866e33a09637c52a8eb82ed3c56bcef43b65df2179b5562dfb3a50d184f78d6cda49f755cc1d8e88f5ed3f4b7a2ea8a2d0f8e1b999bd964db052f69956566b4d505bc5e9fd4bd0a7c27bec4f301fe7268f8a0a871b6334a174647928d25bf1281c38d589010001 \\x5ce0cf31a563a38af9fd8ffaa28252a8296121b0b70b2c50fd3ebbfeaf69c48eb720431607707f81c9957ff08ef8cedf7e28de8fd2dcf38aa09595ea792a1807 1685865557000000 1686470357000000 1749542357000000 1844150357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-145 \\x730deba39d3c3d92523033cca74c7231ac70a855c8a4451bad19780350a2920c9b39c0a2bafcfaeee01beac6fc0379917f9a5dcfeacf8049c30d28bf1139d9aa 1 0 \\x000000010000000000800003ad09f9adad1c2ff1d0ccb058fc5de74f7b0c98377c93ddd25d233a4cb6e680b1d5517c15bd09b4e98ebc4d7b0ada7a2288e26818c714d0f206a1ac83fe859a83cec864187fec101399ba1dd1a815478c84470a73df1a586e40c40cef39835f1fc81648e602ad6be3295ed280c80c2b0119c3ad2c595b5baaa16955e007009fbd010001 \\x130a3207cfc2c747f1b9c26fad2faf00bf86a7f6d36282edd63235c7393b9229d0374946fa6970c97c1be62a70c0cf846f0cef24110911d00554b0eb0a786e05 1658663057000000 1659267857000000 1722339857000000 1816947857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-146 \\x74b19ac3170e8f35cc3d7f06a3b0d709ebb6806b2b752910712e2a692d2b97ae38d9e8966f4ee80c06d723ce3c2a8f29a19d84419ad0087cba9d9ad5d09ac753 1 0 \\x000000010000000000800003ae8b3ebe4e8dffaa3e5bc5bc795fb38eec74213e4f82343735dab666c5092fe35ac736fb768538cf44a97785dc2ffbf4608b63be04d70134e285572ef00b58ed890b2e9fa29253c5df8a1d43ccde2b895c80e2972d073c545f5336508400ba695f98e6a04c9e4a3ac734d8016eb8fa1c721376fea36d24878d9710ab8ef6e48d010001 \\xcc3e0afb2a5ef41afdd30110e5bec2c6d31b604506e8f9b57040af01db684590f1da8e880c8bb5fe3c27145f1eb43bc9b0a153c3b3dcf59b351bf12cf8835000 1668939557000000 1669544357000000 1732616357000000 1827224357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-147 \\x7a71e39344614a37a836fd77bb0dfa7e1b4b87ebd99c40fa0a10bbcacd8bcd6beffa1b3dcb03a1306b0eee503c64f5770644fdf28ee284b8dcf92b9b12b1ae65 1 0 \\x000000010000000000800003a3386bd203055a7c178cdb832a66b0a89fb42885616421fdf443095fcf011bad54ffb1d499ae82105378def18be32c5fe2f412cf9047358bf4a5272df19f4199fe1b05ad3bdcf807db581525fa0ae22683c811b53a8dc113cbf2f0f9dcbb7436472400d7b7ee95d8b02a7bbe5d33902c4432fc21dcc6bb08051ea1aa7f5292f1010001 \\x331dbbae1b2899b4a31305564bb0db7bb7f12bc5af747eefc48c025135db42bf2386cf70eea0dca7e87e7f83ffc3964bfbabb5630ff3c8334f0c762573dc2e00 1666521557000000 1667126357000000 1730198357000000 1824806357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-148 \\x7a9588523a30aac178d6cc7f78ec4743fa02d21418381f5fa5df11a871a333dbf41d6e10eeacac83e9d1453690d5e59dbc1ebb88a7679b7111f03f4409746f50 1 0 \\x000000010000000000800003b52b18f2ee5c5efcc8506388858eba1214aba71262c0889e0c66fb32acc6262cc5c9926866a67a376fee6eb363ec6968cbe09befd2502bac746b624b9ef63ba6eab01a622a0dac8239cb6318c6e26536e3978f0e866b899c442113240cdce0af55d0eac1313bd8d503d88f20358f9a63afdaca63e0eef6c56a9a85825abebfe9010001 \\x8d42887694e1615eaf1a4427c04d5747ac5b9d376e01012603dec4dd7276cea7d56703a5f3cc603b94bd8c8c946be14c6f6be4e276a1005b101051a47fe2160e 1674380057000000 1674984857000000 1738056857000000 1832664857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-149 \\x7b0d2b7d0008f4f632e1218231778540356a543b76830a6a939c681b1b05c6180cfa84f2a779979e95aa137ad5d09cc5714a1f30ca607b1552d51923f9b21066 1 0 \\x000000010000000000800003bb8124c264006b98c523afb388b7cccdc572b1d3a19a27caaa5c1de4e5f23043496769385bae5654959b247e5f004a1cd04a073def10d64baf9498995fea9e3fc027c4c8c0ff8fc0518b4108f0510a776d4cf8f680590197c7a95976d564870634de9aaa9c57340394d168de6f1babc5a38cce64b34364434dea61f7043d90b9010001 \\xe75e6940a4fb7d73b49cac7d8b6fc55f9edc2cb57396e90c6fd3f3a134e9e444aec91dc59799e0b110bd0ac306242317c1b2a59c9daee547f1b51f8d34381a0b 1659872057000000 1660476857000000 1723548857000000 1818156857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-150 \\x7fc1104922f2f4fbd47cde843e83558ca71635e074b35dc42b0576514f59fbfc113951a2443e8e79d74ae09bc7cec946ffad228e985fffe2d9c31edd9d6d25a2 1 0 \\x000000010000000000800003cf9bf987f40341e3e764b9b088cc82f36085af7457f9678050f18433dcb994be89c52494b2c47cedba5ce51d50b66f5ec5a35d06074836ec10ea9db6b574da78d4838094ee88bb03f9a6afb6eef9dea44fdbb1992053c1ebe2e0d1198d501d77adeaf1cc01d4c875c9f11ade597b5eb1da684d9f5f446e73ca60eebcc20ec5b9010001 \\x276be449b08a2b60670da182abcd8a632dceae4285a615703cb8b3495726ac948f5d86492988a4df583429b5cb32446f337a51eebb89c560414c25ce59bf2207 1672566557000000 1673171357000000 1736243357000000 1830851357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-151 \\x80d5a8390395f49d518f13fa13e93713239678ae8d3bca941d29426308ffd69865b45649bc0199620be6ab6166613f72bed454b16c745f83133c9c9a71218510 1 0 \\x000000010000000000800003b423da78664a195ec7dbe2a43da1f4cb9eee98c342c1da66f41a1a9ee6a23e47f427f93ccf06d6aa46ab39b72ae9333929233af67c7ff79b29648d9564bd5a7e4aed2741344cddb648784d9341faf3b588ac30b84a26fe1b4b05e49ff6502dde69f17368fd48fcc008445a941bcb5017e70ab96d40b3e97d045ada86fa2841cf010001 \\x402948b63a73f51775d590c44bb64bbf23f38bce2d8bb6ca7aea934f9c25bc3900e875c7c2eff99d83697c07c80e7e0635865488a398fd2692bc764e5f427f0b 1680425057000000 1681029857000000 1744101857000000 1838709857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-152 \\x81950d7aa0c8ef4dc8692c1470ea62e09b85505528483350620d939aed6e83862fa96b7c93359242a8346c1f22276d025410d485a59af3a93376b24dd47e37c3 1 0 \\x000000010000000000800003b8ba4ef0c73e441fcb781ad2e5584db4d7d827e3619204b1fda2060c6cc5e967d258e788533f89481ce5038068dd30937f6c0cefac028d0d05aa2cb3f7c9c89e65998da9a5a1a716122b3a71c3089cf75045aec0f9a0428114c661a22cc1d5f855b2c1d1bca6cd39ab3256c2034ee131078e21eb6f0a7b8bef1dd3f546a25587010001 \\xfdb28df13f5a0a8be4ba1859482e3b22fd5ede546987d5b3edb95e1ce655effd701d8d29616c40f8b9e3521d6e3be8a92315132269a4d8f10157b78f3ba4b10d 1679820557000000 1680425357000000 1743497357000000 1838105357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-153 \\x8169255361af7456b6d7159e250d332dce46cdcb3339e6cb1b7f334e3f807330aa6e353e58fb66f325d945cc2f074e3418ba4a00b49e197de21e243180cef64b 1 0 \\x000000010000000000800003a65e516016cad6a796b52600aae17c77601972563f63e3eefcbb7d7bc8fee9097241b300abc1aef13ce12c850722de5829b6086652983565b6a1bca8dff9a0bbff7481f01bf59f704545d15c2c258aba150297256346bd44e2b8a82e3efde6b6a263623f227eaaf9321e3550774b48dc320174785dd482d469514193611efbe9010001 \\x0ff171d9fce3111b09493e6adb742299daf8ac2bd6087d0e7921028e651197d90ade7bcf6ed041af39975d8da976a14e531188e675932c88905e719255d88503 1668939557000000 1669544357000000 1732616357000000 1827224357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-154 \\x8229ea932fbf782e592b10f50db250bba6ea682b9bb160e4ef371ea5a58fe466760970b8804f781d6b5148b7e8bb9e3740526ac09ddbff8e2acb3990ba8acedb 1 0 \\x000000010000000000800003b9ec51cd696ac2f428205b1826deac86728551bd8a84f6b3f7a1de0ee437b04abedd4e5077161f10c507089d9b4320991a5e141a6a7d3cd55a973b091b1aca26fd7ff88e000a2ae2ff080f799182c5a469632236c634146c69d58f70f8f5759c7e840cbaeffa1920659944e953248bbe84f5b7e8b1ea7a0e8384f71b7d7aa11d010001 \\x44a81409c43044ad25d25054e469b5aa4699503670eb5681a0c3016ed8a26581bbaa951b24d9db43157e209c5f8616b0ba9d31db022cf17c0ad42dd84b1a410f 1682238557000000 1682843357000000 1745915357000000 1840523357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-155 \\x875984c40528b5cda994e9e69d595d857853ebd952c09a3b119cd7ee7dd389ac691057ba9d5f18ebb5b31313eb1c6d1146e5bcb157cf818c25dfbe4a509c489a 1 0 \\x000000010000000000800003a140d4debf359769d99697c0c78c5161a3c46603bc20bf584745e60a590ddf60824b0fafd0559b677e9b130e45ac57b7a8ec903bdc120fab2172ce9f2ea820ebacf9bdfa0e2f98397ec33e13504e0c68047ee24cd8deb99e378dfeabdfa81da8e6de4ec900f8d187fbe90f89f5eb3cfa1079ecff45716b449a5d26f02fac6f15010001 \\x15957da5c9e2228d30a16032714bdb9f4a42ffb5024cdd96d177d4d382c42a2cc7f8c1be6aa632170c625a67668d6900a3b99aa81b3f51b553b7e4395236790b 1678611557000000 1679216357000000 1742288357000000 1836896357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-156 \\x88ed4a94b31ab177bb291b29eb8366bec5bb5246a8b407181cdeadfcd7def2b9cf3ca3aa418646f8803e0d08e2b352c69423d309bdad97ba42d98c35c5220260 1 0 \\x0000000100000000008000039b8e87542e4762f8baf37e071d8046dfc122b331115b72e4c31846970965974f90f59c3018cff50d9e74078cbc61832fff42382aaa839da97dbec0a5eb766313950eaab36fd4c0d9c15db9852727a1331481382f651ce3cd008e06481758ae43513618a6dd66bd528c2bc0160221c4508a1b416ee0ff74ede02e35070e2196b7010001 \\xd56b93f24dd28a8cabc5c3c3d60d364fe4a2067c5e4d6334b47d5e1f4e5be6ad31f7960f2eaed1862a6beaf5581b912d2235ce20a67c6d3fa7e68dcb79dc080f 1665917057000000 1666521857000000 1729593857000000 1824201857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-157 \\x883982e657b5594d2659f74677ec02113fa77ec612187cebbd9e4dce5715e78453f47ef9876f71952674e3f6e167a86a5f909fab183860fd7d58cd090a97267a 1 0 \\x000000010000000000800003b455ff8ac18a69beb74526d91488c7894d4941807d5c61b07b41aaeb4eed3c8477047175623bdb3e97e27cc8fd3bcfaa5c78de4cc382d27ae9428a6d169ebb78859b998f3ed27db8c3e43b91d011af7f3ddc05fe12a232185c7970e811b64aec317f2261fc7521ea5ea41aa07a51210a423ef2989b0c935efb154df7e441ab63010001 \\xa8ce44b0ae2054e6c89aed3324f157e7065d7f1601b8ad476d9e1b6feeae9e40fe36c232b33a6ac9e717a5617246921910e50f409a0b4c6542677faa1884960b 1664103557000000 1664708357000000 1727780357000000 1822388357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-158 \\x8cadafc07be917a29241b81f1b488aea67a3ef4604bc693efa18e233416322a8425182c5e341cb358011f0885ecfaa4723c78efd31f92d4788a04eb47d154169 1 0 \\x000000010000000000800003d2f25f01be6c345705705b828e720b5791e8203874706e9b8668a772bea2e7af994aeb1d9e4bf3612b857b94a16682fd4e60a41abec841635c6ec2a632c608c1d8ca004c283415a60ee28f9b1807b7b142fc34c407b9d56e84f22a3e9c016b349ab8bde97f6d9cf48556dfc8d34b17762f10d007b47f969db9e02c83568e1e9d010001 \\x27532690683b9ed3353884c16a4bd9f2848acee282fbea41165df371757d54c0e7c9604546583c7a58a0e29f9c682d8ed5df506a3fdb513934aa488acc819009 1678611557000000 1679216357000000 1742288357000000 1836896357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-159 \\x8d41044e8bf8aa06c559d0a389863394ab9874dff3be34c9c6e16296f25fe0d364b5e645fcfa9deb5c60c6bbbdc4b78771618cc7a34d4f895f6776332ffd9dbc 1 0 \\x000000010000000000800003ca3ef7506a657dd65464e79be184f02ed066d89d71ca6ccc0bbb3a5ac819dcf2a7a7a337264020389704d38e37914e9824bb833ffbac19987345f6d983d64b061dcbbb1607ca7bff37e17c7f6b8650ae098986a9562cc82498882adaea48c70e937cd0b1fed3fd9de63d6ad8400b621393ee82945cad77c55e79fcb1cf009653010001 \\x035dcce90ebe6b03743218afe99dd4c69ceae85e0fae95945cb6f14c0ca5845876bac8c39f033564da0933968abe9fe4bdb1f51649145f3e4d3521beb95b5109 1662290057000000 1662894857000000 1725966857000000 1820574857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-160 \\x8efd5a0111d525a42b43ba5cd3e1428da5743d13cf5bfc7932b19d2c1ab8396061e162f5702d7ff14b30c27c73e83a09918c4b3e78965d38b61210e5c74fb6da 1 0 \\x000000010000000000800003a0ed66d6b6c90fa362c1cbfd00eba303bdc41e31dfb4d2069afabc6c527916ee9d4b1438eedbd818bcef0838ac6816f790056264416c77f2d9840fad41aa28986b59b55243dd03f8de7fc7d243480bfae197661d4e01628d5063a18c719b3cbc0e0f920e72e986b712eddfb03d3bd0d908860665906854a4fcdcb489efce1d4b010001 \\xe0ea057c90b2c8e4688bad079ec12ceacee344ef9560c340e2aafb06a2a01018e4c0451c032277883ad028da58f15dd9cfbd2386a80af7025f138801ca43e80d 1684052057000000 1684656857000000 1747728857000000 1842336857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-161 \\x927185493202f08201b928095313108bcf7cd774978301a0d248872ed360f385e9afaf7f6835e987d50d46273817322a7112b8fa0d2062dfb8da2fe11ff1b9a2 1 0 \\x000000010000000000800003c69733fe993d4b1628360c68853bab60dfe4f8c2fdf829ae257b9d513eb8333cd1c7689ca96e5d94131cb8f7fad3c4a81f80d62193ef84b3f882247fbfc28d1cbadc0f0dced8269e845126fec06fead80e7e7da5dae07670a28805b9d8477e034c91801a8189c565c09c56adc1786398be386888236e09aab829c4ec1ac8eb7b010001 \\x0ea83ca0ef7b3c94028ff0d066a6274921805089b23b4eb551e34993320cdabf356e5673dadac70c824cd28888342345006fe0b121fb4a2399e62297bf659d0d 1667730557000000 1668335357000000 1731407357000000 1826015357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-162 \\x92f92e9de502c07be8decdb1293cfe6347ed63d07f16b391fc587406c33e3a1b6971bac33f5f43bb7bed98fb2031c821861a2d2741bb03605e29ebe944626ea4 1 0 \\x000000010000000000800003b7f15699eb7f01c92f5a05301251731461f69de7c721570ea0e977be78e25623a536043f5b9287d35fd08d29e6a8edbd4d8b02251370fc7ac3be0a6a7b7841ffc97c722d27652e4723620064fe7b2618e5922f1b2865bcdce71250ea544064b5bd70f37518004583385dde3b48221d54355a167d914d6543fc483c380b61e72f010001 \\x9d15b2b76d110b26f3ec0a000c8467b229471e5a326a2327e623fdaab00517c3688d7d93505e50df8327bad02e25a25570b648c0818b2869df9ae36ecadfcb0a 1658663057000000 1659267857000000 1722339857000000 1816947857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-163 \\x943df7797f63f86601fdf464288cc2e3eb9f862126c487ee5e803c6ba45616ed29b964575600593a2f626a224c00793a49eb645d4bb8e2415cf02d523d564b0f 1 0 \\x000000010000000000800003b3cabb0712c5a0375f64fb071f48350d42ec6514945d8166bcdde26327fc47e1ed9e1552cd171ac9e96b75459710f49b724fa42f2a98a8ac991ac952e5b9dbe63a6cff0c6d7cbe252a0bdb8e59188ec82431474d68974c55d00a2e7aa488724987decb6efb15d23406b846ea53f42371c98ccd0634a0ef1808a9cc4801ecfe35010001 \\x880e4c8106ed2058d917ecc640a123bf90b283adb2adf22f5afd46445d3aaccaae637427428c4dbe59e33d2954abc97dd175d42883bf715e37d14cb7c6134203 1684656557000000 1685261357000000 1748333357000000 1842941357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-164 \\x99f15c6a41cb0908f8705d9417bf64337d747502db6e6cc74dc4594e4d0b41715a16fb9894d53976ebd67e63922f95fdd2cda5a131aaaa3f42122fe28fc9e165 1 0 \\x000000010000000000800003db87d2d125b5526c5604e631cb997a6397f993d68aff4c1ede15e2830e66c4478482cf9baa89dc930b10a7cfcbe9d49af3d7054fd2d087c98d2de9582287d9cef53efe20ba4b331d83c55ead1049092a2be60d4f6c91f09b9f03f5866f96de316546cc6c8b9d8bccbc3c44fbdae111e8726ada54d415b8ae619536f5700b2ec7010001 \\x43962e270a7229da2ce3fbf8b4d7ce9b0ed64d15f8c25c759a78fcee57c987cea3bd5c9b0c088b9f1f211d4fcb4a045cd9a1ed54c2fde7bdbfe450555c628905 1659872057000000 1660476857000000 1723548857000000 1818156857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-165 \\x9cdd5e829fa66c9da8c14f7eaafb656560c08217df62e369d84eddc5aedb836716537a687aaedb6bd00984a8a50cecafd176e61c45e11791d2657c0eff7346da 1 0 \\x0000000100000000008000039e8ddf6df0aba3b2985cca7aab514c6ffbc663c4287ea0e8b4811c85977dfd263a5a2ece281ef52b0cc8ce91ef7ee8b41c654fe2d9174f87b005c24c67de1ce1ee2ae7b62d0dc444acca64cfd49ad045f5ecd2790d717ef1f18dc0fc643cb2b4b58ff4a67c0b92fe3dd216d56f442b2b7e91d03d7a018e5dfc54c84de667166d010001 \\xa596a7d9d824edbdb30768682fbfcb9ce573ccad59089272864c41dff8ce4b42b3624027dbcc0aa5aa286b97e3a41fb397c08a917dd7b49fff48646985dab305 1665917057000000 1666521857000000 1729593857000000 1824201857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-166 \\x9db900f537036e82f4b89f1fff39ca9cbcdac427c368e8631400e78891c2db8f4d87fa8621c7c0d9b9ee27dc2515822825b145b3b71cdc7eb194f4a54ea64290 1 0 \\x000000010000000000800003c245520ff54fb98f2155f9a7525ca38d3ab4a47199477e9468e15fc7df61e7f91ca59f6d817f5d06cc8755900ecdeb0448f070edd4a0cbed2bab73a1724a19aad0fe6251b7f6c3589566eb9560e5cecce4d65091cff27b32eb1728bb6a8ede9cfd66b405cfa859c4189dc45a94fcbe7346d26d6eae22f7ed911f33d6c3bcf369010001 \\x39147a18981d14af6fd23b234f7e6099e204ddbd05aed3c69b80ae606ec1430d4f63848c61401e2f6cdde76af06bc576ac0f39aa0e01e7799e17a6e3f15d0702 1687074557000000 1687679357000000 1750751357000000 1845359357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-167 \\xa15d251ea52572155e9109fda8e6b59a2506cf45861c5d3e4dc778db1b6006c56d6ce962a13cffe819e5b3674a6189442e3c9f3fac63f9631d83fff8ef8c8250 1 0 \\x000000010000000000800003b7667e39bc64b8584af24e5571775815b726972d128d8397c2c98b633d447b92d89eff008d35f2d2f65e500aa84f7ecbb5efcd1342cfc618ec4685853d635054e2b1556c62a4a81140a8c708dc0223f61e97520a8c106b857db821c3e705745d4761df00d3e70c5a96f8ed33c871787df2d9868d7feed42636ceec1b90c9237f010001 \\x93ce4a85af5c131f537a21d3cfbc5f5bb43bd464b8e46ae4d0d7c1f1f93edd1b682817eb9e15bf58a6eb661dd7f7a16443b116205cd0e677fae5ee09599ea00f 1679216057000000 1679820857000000 1742892857000000 1837500857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-168 \\xa45d7a76bd9527662bbd2bda0cd8b7e2911f3f0efab66744ddbe7f094a99fa9673f7a3fb58d05b7dfad9474a6423d8aa9f54cc2a2f27cf94081afdb3a7545274 1 0 \\x000000010000000000800003b475d2e37f81008ad27cf596bbf58d6642fb57a161f892ee570941823ebc7c0f5b03bf4e3d7584c069be620aa51dd8f81ea093282e757fa718e769eaaf138e31236f37c2c5fd31ecbefae2fd19931aa08f9d691c7ae890802634384174b234e8241f46891848056338655a43a2daa68b7ef51b3452d09f24d3098b9a28627723010001 \\x9b269b93df22fa36b663fb2912655477c70b61647d128f3153eb5549dc98cac56b619b495b8f7fffe7bb52413acfd9624693c1c1896cd9589330335046903001 1670148557000000 1670753357000000 1733825357000000 1828433357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-169 \\xa581e2e7b6ddbefff80ec38600be094788126968c392f7da6856d2b837b3a80d60397f0fe732101c5f5c61a98754db9bb0cd0bebd0c08e9d0c5758c919a42f07 1 0 \\x000000010000000000800003c06e5d6cebb17572b76fad3df4dd86911f9757a4bdfd395a1027f0a1be18262256df08dd57c3ba8e2b66df141829bd92bb7fbd5b2871bb42bf35c63da9bfe5d9143295bbea4fc95b86e1351401d68dddf59b43244978af25f1ec083d654f21a683d3ee10a87e60f60c7b7567e048fab5a6cb182214db2a0817d3dfe07de37515010001 \\x26764a8f60a11d201f527392eb739e9050c1a705623f0bff9d10a389c7cf8a7a9b694660ce0248ca45c3c5dceb0881f334842a14021ec23dd7b9cc5976ba7008 1674380057000000 1674984857000000 1738056857000000 1832664857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-170 \\xa9596d701529f8b355d299bb3b76837860bfd479ddf84440c42a67756e263560046a012d05848c3ef16614e9a593cc17cc4d872a053e6d51c8c17c6a63062da5 1 0 \\x000000010000000000800003f3df78148a221a6c627b9bb3eafdd421b886075062228eddc8193475ec4ebae37e034ab83d7ccdf3f11cf8e289c5ce01039ae759bb60883b760233b0698e734e28417626207d4cf9856bb8dfc54da465d17405c42600e0c09a7f8877d15d6f2125337d2697eb13f6a1b94cf3d04d113115565b4d1717187415df8d8088f87a89010001 \\x1db5f620689d33b0e7b66d53436f112d2d9fbeafb708f8cf632dd3dd8dc6f26cf7e443028e3e9e45678318f2524085f56c400b9e1e7b62d6d13a20d0830a1709 1683447557000000 1684052357000000 1747124357000000 1841732357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-171 \\xaadd969d02b913bb66c2433d42105f999ce0bfac5892df71c411a05a0d075e594c32715fd8d7cdac3b19189977c7c1fd9e6e8f3c9e4a26505865d887bd581ab9 1 0 \\x000000010000000000800003d9f87b2849dfba4ce1d78a7e956954af10ba374091f9ef821b8b2443e517c5199884a643cc3ab32d86bc7b3f966661233536d0cad89aeca4ee0703a9a2e52e5c8755c721c5a40562a203b2f04d984bdb358dc01c1ffbc178ca7f9a965baff8e99855f49229daf3224860893cc1b14ffde526c0f7cae8c2abfcb6e262cd18fbc5010001 \\x8d545da2ab0e7450bf4e4d3a2e357d775ae25178a7ccf9612dd11f242f697e4cc4313d5edc9461c81025e094493469c3b57206022f9e1eec0991975ca032db07 1666521557000000 1667126357000000 1730198357000000 1824806357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-172 \\xaced803672f834ff99ed92564a379d538175543aba0654c4950d1ffb76dd89ad635d962e28cb744f1850c32d6dc89af5c79a5932065e97d8f4941b5862bcdf60 1 0 \\x000000010000000000800003c2e26615e269db0080127b1c22c949abe9f76a3ea8d7cc963e92ad0d66901c52059edd22f99268449c82129a369ca038564a31d127a21ee6c2c4f8da95f4b95c0cad3cf2b5a71afae03888ab2859031811946ba4f65354af2ed42c7025b5a254f769506b9860210a42efde4f0c296d88805cf0d8aae21e600a1b0a2efed702cf010001 \\xe57697962249364edf66a757a9b78d9724a1cd1e59bdb962101a104c361494837dbb548fa963827501ffd3b99b76ef17c1f3512c2372fa29986e60082052e901 1674380057000000 1674984857000000 1738056857000000 1832664857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-173 \\xad094b7fbf15d97b38a2b30741ac7f66607d0d765755a3ccf7724bf3766d77f6b67e61beb5202a9f21b9619634991bb3392ed96cba30fcaf6a09d2f62080cca7 1 0 \\x000000010000000000800003cd736dabfb1cab762a504edc6cd118ca51160864a154beb567cc2642e6450b90df0d51198d244314f6b1cfa295c498113ae3422367f24de0e83cf1b6ae7947a28c7bfed864b4febdb8c48c1266ff074f0f82addc476e48cc5a3f329ad4230fc689cee2fc5598b5b1f1d5749622ffb36a2cb0b9554d8555cb33326945e2811213010001 \\x09b26c50c180095678a443c6795c4265a7f35d4e0f60b1d72c9518258064b6788f61a597b6b0146de9dc80365e8be4dd9ac54aba4930e3147361268936977d03 1676193557000000 1676798357000000 1739870357000000 1834478357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-174 \\xae11a8c08ef779e5e93039a01eecfc8db858228be4b7d8b74c469b3d1611d550df8034e7f88d642450edb5960698a740d55d79c62c9bf0135755a43b5dc2430c 1 0 \\x0000000100000000008000039d6618d53d193bf56afeba3f3f30dd53fc04379981b6c0fe9fb2ba44def7b0c7c123dc4bb2617c410dc5264bb80adaf3b9f20babb3c90fe53fb32c86a49815aa422a9037a9fb68a8c4656ae3302a4c95f2fc49b4aa0659a50ecfbbaf3a6d610462ba974bee0f10d7dcf0cf94186dbb9b84855ddbc26374d72408ff30af0a1b4d010001 \\x3de2aebf14f7d62d6adfbe01811b8c2d288c7f1c0de4e4e88b3f567e18397e1a39097ab54a71bac996cc95600981a231abc29f5c249eac7a14080560c2dbf204 1673775557000000 1674380357000000 1737452357000000 1832060357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-175 \\xb1113abbd5104b1ff99a7e3cef66d8e4bb5f40a8d0c947c1830209f45c2c2efc68434ab5c5d58e67cd3c42e00e79a0b6b45edc198922c5f1dc3a157b60a57491 1 0 \\x000000010000000000800003c6e384f7003843ae3d8d8fc57a9b82571650f71094febce8716b510ba1760a41efea7ae535fca8c35cb0dfebf644a53066040a80568266df73a243c94dd6ba2b524f32e0cc3e47f3b50a519fdf0cc92bb14ea7e2fb05d07c00927706d83efd635b199a320905da2c51cfc7b8da0408d4a463ad256db2ec232d7a4bd922ad8d31010001 \\x676d4f958a29ee4399ca1c64b83e0ca5a59a1215c7455b51daee29843a445eb7a61633acb78b3ee5f438eb4ae19b7bee82958d014a921bfe684e75c6fe2ddc0a 1686470057000000 1687074857000000 1750146857000000 1844754857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-176 \\xb2e9a9b5f6428f322dbac921dcd7ec76ec76fa31a07fdf993d617d46d999a079eb82ba9a989eb4e854a3b11745af501ce1717316ca2fe131ffa7a64c548b7463 1 0 \\x000000010000000000800003aa5e66aafa1c7a7223438a141cf676744d18e4eceb432f2e1724a743fec8604ff6e0f7277f569015043f4f365f8609693b0f1c37d00edb03d9069af507047ad9b54e5c06fe27c85491babc14014f7c2571738d1660b8a2244fd4c1a909b736660da1b07ec435a0b964e8710b2cdb839aeacd9cda8df674ceb9f3d0ba2ca577ab010001 \\x3730b8ece28915afa266a234a8dcea52a42266944f9026b15dd92f998172ed9625bfad7bfd1542af1d19ca571d5e46407cdc9874be6720ab1bb69eecaffb1e00 1659872057000000 1660476857000000 1723548857000000 1818156857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-177 \\xb2fdabf3f8f21472ff2253220ade047ae39d3ee1c9fa804e7214f538385f70f1e91a6b85a36e24182febe7b7988ebe52ac98b15e7303f0c69a00e04c1e8cae31 1 0 \\x000000010000000000800003d5dbe53df5b67eb33543085550c9f8eafb0f22cc37191cd4fd659d8f2041dd61d5d0934c5ffeb5c706a3da43dbe42f87c6e6357bdd82660795773bebe9c1fee732d93bea7741972364272b944694c3c1ef4572f27a2b31690c370c0fd866a3974aca96715cb5600f5a6d139a5920ae7897a7c22160d92829fe73376c06769dd3010001 \\x8a334b558ed9da015c2627daf1b42cc17bbec2cf34ae13c7171abd7b1c7be8439c86f56dc8125f80fb9bceac5fbf6bbfa751bb116ec789bf59e0c156fa500000 1667126057000000 1667730857000000 1730802857000000 1825410857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-178 \\xb3618b06474459c5297b71ca4be3aab845f78ba1d780ca259baf9e64803c91f6299111fcbca4be607f4e39b8bb16704e4d858187da6fe98ba177026ca65239dd 1 0 \\x000000010000000000800003fd9217a5137a5ab90d03fb46c3eaec55f8e283a0fd63aa6c12e2316e01e529bd5e55c29e8fd45abff46c03e008cb46a3c6061a17155c5d6aae830226f528a5cdbd79521d3a8242a3368542568d95e7401dac2386dfcac1c7387c61e2e5d08b74f9e167592ab6559941b2ff9000e426d2b45f2d93f0cfbbe0cdf127df171f4c11010001 \\x4870be716f1f71beac633a27d41b092ef2fb4557e068aa9ffe95dd1dea77c74218955e6f1e9ec312cfb58da8c019f3b725eb5a2ace14b5411edaa28c09f3af02 1676193557000000 1676798357000000 1739870357000000 1834478357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-179 \\xb651da48999f7b60f3791ef9a77472163105cf406555b3198d7ff1594c158f03eb2263dc37ce80cd5889282e2c13ba35f092f1f4805a685256110a0a910491fa 1 0 \\x000000010000000000800003dddd1bc32e0195766804fb15cc532acc08302d3b2dcb8766dbb42655b09d386c6521d548e6ed139fbba25afb6e007aa854eea94f7e68e018ec88ba0b31c1e2ef1f9fa054bb43ed7e22fa1ca000d23245c7f6b2801f835e61a516e97fa6ff1e920ca7a4dadaee0c793c3633e5f9050638e156f8f20cbcab32891b5279ce0fc7ef010001 \\x31901eb2d336a5dc84b5ac05cfad110a78feb013d4a63f9e2925210f911663844e38fbcc70ccf3cf78ec1e5f868b06f373a5e2b6d698efc81b29572e42e4f409 1656245057000000 1656849857000000 1719921857000000 1814529857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-180 \\xb9b15dc2e6f9638788fd12c7a12e71a77b9b7223c2503b466ecb0c9c4dfc8fdb4bd37d4e33bc5738f02d072730b51ecd88416afc5608265194a4943087b88e18 1 0 \\x000000010000000000800003c26dfd65786013204c6d5e805a87b4a4a9b1a974ced48d0fe3af852f140e46e5027f78a51ee19e6f2bb9a0d5c518e8d59700eaec372fb403d1e84ff4d2750267654ea1bc39783a94907d041f881f69f7f7b3e3d043207347a8fe62b65e6e00a8403394a9806b96c13b4607f90681952773d719cb4a1423c2bab4eaa72eed7cb1010001 \\x68b6dbce51cfa37fad1eb83e1197c3ffe03dae10cfec679947de5641b67941fae8206ece5dc60f332fe2b6c412da16dc6cc79509990a102b9be38f6cb79d8a0b 1687074557000000 1687679357000000 1750751357000000 1845359357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-181 \\xbc8514280e48ce2263c9fea9596870ea2861195b2f9e03570be242230666f670fd3cf6ae1e0bf6251d5d27cff93f8454e4c548154ab685fbf7d1af41791471f6 1 0 \\x000000010000000000800003ba8e52bba9d297d4b62be6a79e7d6a10dd6ea6b24f0f0c4683b8bb2f77fe63722bc35ac3c47f899b13853790c393751d6a7a10b9b77eb2f62bd926c7ba93535c59101e8b86f4703b3160a8c28b7c835542a28e036b99deaa48714dc847847d2577895f7e0c8b71d8ade5970885f986551d70cc3246e2fa1a757629b0b0cf2571010001 \\x70b02a7b0a6fd41408153912a283da55ad61676fb558612fbcef108c6f249e23741b72a5143b17bf562ba9f89c38a1438819d026b3836c8e493bb2243a390a0f 1663499057000000 1664103857000000 1727175857000000 1821783857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-182 \\xbf4d22690d6009a80f7f0e85006550760c71727e969c66f9d1396141c2edd9aae9d61727bb6fd7835495929b0ce9720613bc6fb9f89781dcd202535f6791e222 1 0 \\x000000010000000000800003be489a328581f27b084ab82179f7a50cb807c62d5cecc520fbef8cde7571806a735525220e4b1003f62a347bbd1da8115032ab6bbf60bf890ea2bce021dacbc796032e14ee27cbf2a5735cc1bc80cbb06ab131c7f233213874985c5cad9be56fad34105d8a5b1081e8dae55eafb935318b6a61959e27116662fa7ed2e44bbfef010001 \\xc85571079ca27250bdb1b5d9eaaf287c049150e19cf1e24da1611cd2ab67b5a5b930e2756d1cc5d96db57b53c66c9f709db83af34af9ae481dbcdea738524c02 1677402557000000 1678007357000000 1741079357000000 1835687357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-183 \\xbf4da73839fd26585970918dd98b6e893cde41bcb33b3b7ab30d90b7fa99cc2e6e70c6fa6612a1f2814e509ff3f69e55f7677c2c35e6ac326299da9e84c7f6ff 1 0 \\x000000010000000000800003d75720de628ea8010e852472292404fd211424e5d9fb107873fc17c5994ffbd92df7afeddc75bd7d58333d82e15352689f8e0134346fcde7895891f94c632d26779a977c71c8577afaa5361c9078586621de11212f7d8ff90347fc70d082945b026cc0c6d8113fadf53eea9de927e92a541568e85b09d00e23051c6e3dfce58f010001 \\xea52ebbbaaa3ea4cad3995f017e64fdc681ff0f8b945f33eae50408844be378caececcabdd34fa7240d05cc062373615dbe498d48fcf79deefe5a96f8c30550b 1664708057000000 1665312857000000 1728384857000000 1822992857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-184 \\xc249be26028b291f39e2745c4eb929038934dc4492d4e4b93c1ef6e6fe94a91d8499d4e95441e145c0f5053435cde3d3e73627befbf2443f4ba3924d93109012 1 0 \\x000000010000000000800003d14b8a6f25b543b938e9686861be06e7015bb1ea4b15b9c93d8e1bb385464b6556f0a9a1240e67d58dd6cb696dfc5879765c996d0e3b7a8a1d8f9cffcb60e3fa7e9efe572d6a6e0b0154680b296e06c05abe480fdc0e8f4950350a3cb11503e4a2d27f298a61b127b8828574d90759e72c7974ea1698c0b067bd159571f00451010001 \\x28b89ecefe6144f4fb25622aded545b03593d067ac8025c9cfa224a557e34c73f019c56ad1c159a7a640f3722c582fc1b0ad9d56c5c166e4f66e61dd09cc7d07 1656245057000000 1656849857000000 1719921857000000 1814529857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-185 \\xc375ae29555d01e60f37a971dce744a897974d9d6afb830018591a7d4cf1182eca146c2cf0b4d4b17f9f03990722b32f691b5a1b725534d58a7c83dcc67dec35 1 0 \\x000000010000000000800003db6af775ab773c4d2696c9413fab6d2b660bef17800d33ace3865f3d210af896016098da79978e5be39be59df254a01905c48952bb53744bcb698fbe437dd8ef641a328bbca278965f968f410ead2595f1d95e2165a520c5477ac3be82cb144fbe5bda10cb0e66b69bcc05bd18c743fed854341ebddf688a621fccc0f610a899010001 \\x345a5ae05581dedd9a127064f2c931558a5d5d17ce21eee1535738d1c919244fa675592d046ce02398cedc269aaf63eb899e3549bcbab1de082f634f75c42608 1662894557000000 1663499357000000 1726571357000000 1821179357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-186 \\xc7f98773ed54a4bb14b4f686696f7856ce095e418934779f33b15ed3b28ba5dc575005b846a0f4c598e9c400ea854693ea80ba114370d3c84beae563bef323f0 1 0 \\x000000010000000000800003c1abadf933c6e59d3b43c19824bf78b4b1169595dcba904c35dd40404b18c14567836367c501ab105b1c20ed6df57553fb2ce4ef408f420c4f458888d19984393be31932304e645610513110637b357ceb373211bf003ce2a2c248da0e768183c75a55bfaa2a1238c40118dfb98a5aad7713974b547e94283b5f8b373a411eb9010001 \\x5eea7411b458dca68e5a8e2c467719546ea8d167740465045c3e3cf557b94b768924c978d0a42a7d7972a694532874e70a218f875eae644968b17287c0c9c407 1679216057000000 1679820857000000 1742892857000000 1837500857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-187 \\xd06d6f1dd80f26f151d7bf5677d751f9c3dcb641b9eadd2730860514e04ac4b5d1e99db158ae41aa193bc6959d6f1a65bf8fc4e3499c5528b5d95dd1b8e8bb8a 1 0 \\x000000010000000000800003ad4e995f152d4772bf998cd2f88b0ff87e37bbbbb2516a5a6d280fae973ef2776cfefa89f116a20409cf28896c216d088cb11f5cd665fb42b2d501b1899663be771335468e61acec14115854fdb31096487d5306f1465246a1b02c009597b9ffbbd8bab432aba47015139675a0accb5738d7a8358536702aabac66e426f39aef010001 \\x07643ddc27d09ac3662c423625650564243329ff91e036baeae63e700b438261f5474cf308414a9abcfdce71aa4344b0b80d45e27fa14ed10920dccecca5f208 1672566557000000 1673171357000000 1736243357000000 1830851357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-188 \\xd19922d9af544dacf25dcd40b37d12602bd322148f0575f7419190aa35672a5c8bea7fad85f0c190c3e40903cdd0d66b616ca96824a3b5faad8b2522f16eed28 1 0 \\x000000010000000000800003d593e13425e319372e0c19bf839334007d810c391d2e0517a5525141870491cda6626d96d76175f42e0e3a78d7fdddd6b09028cd7724541edd7abcf496e9a319efdfd984493dfc129706bc03726c8e1c4fd05cab3cbdd74695f19fb66b346772171820b038df6bb5e6005df97fa5cf0fc913c604d945743042b1217068f9af73010001 \\xdf55a834da2fd26f0add62c07dab1804b10872242d64bc9decda0f843188a8a7749ca9f4e1e91f9047277bcd8d3a283fe38a445834342f68b87bd7faeed9500a 1684656557000000 1685261357000000 1748333357000000 1842941357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-189 \\xd28dd7615b4f437e3867a9be8b3d04ce89558c94063b332249cf94302014486dbbdaa7f9dcb52b460b23d4dbfe7487470386cb4a482a200486469555f3194c82 1 0 \\x000000010000000000800003b5cb13a5934601ed700a61227afc9cfde9dbf0c1013da3c80f071600f14db20521234bbcd8770d9396ab37ccd6405d646789f8c8d938afda316988f207c0c5c6fda0879413cad7902d4a786894dc83455f344b20bf53169f2d09875e2697294b97057dae7b85aced3854f27ceb450fbd08bf7027d91b1d23d11662521f3fd7f1010001 \\x3cbf72112086c2ab19f089dee5741e595173e9c3369066e0b2b4a8e0a9c891efa95867c20ac3934483363d93a603ee3fb30e08e22e1d5518007540d2ccc5a406 1685261057000000 1685865857000000 1748937857000000 1843545857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-190 \\xd2459b41ec3d44ce9be1371b49ee87815350d671b3ab7df1b6838725681d6680cbf1d40850e1e6f00276a66aea87fd65ccda0efecbbad7d64aaacc4fc3135f5a 1 0 \\x000000010000000000800003c524ac7ccea4220c80938062322ee4fb05040cfd87b6120602fc1090fea9d5648cdd8199cc5a42a9d386c7bab6fe1639619c4838c3d2e454876574e39b35f5a0f5cbe6ba4761a2d5d957d75f8efaf657205c7f5b0b54752bcc394f8070ac7c47d3a837bd0295a19df21efba123da375e526611a582947b7a8e670c80b623b305010001 \\x04abe65996dff7898e8092b2fba0191f5a496820f8be16ecdbfb97752ec9f1dc83279d09470d11327e88f3e51fddee6d6e06822576a1998b10623819e6278905 1670148557000000 1670753357000000 1733825357000000 1828433357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-191 \\xda5d319f783abfed5d28264c0196598cd8daa6999efef6829a7a574698d8a081a8029229d8b22eb0dd584fcff5b2c13985d937f6e00f85e1339f37f23a1e8db6 1 0 \\x000000010000000000800003e4de2478a06627e3c248230706b90deeeb3da648dcad9d7c80abf1a0f11a374a615c1a4093415ecf95e56a934d993b79499b9af2087ee7e0aa9a62014dcf91419898721ccf945597c84c09ad4961678af3a3c9128588d0c32c7c2f26ac11820eee9df88d09a24bae7e1b1b91057d5b2e8e5d7df74905f70941c2ecc7d5d2c945010001 \\xf4ad271876fd0d806d3c75d0f252e28cf6b35327e28d63d9a7216e6ec3f3675f08eec63ea18a9c2b2b9001bb6cbee897e33946f0e1d4a353250b81ec852c2b02 1659267557000000 1659872357000000 1722944357000000 1817552357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-192 \\xe289eb6fb2ed760301d1754b7b62f4a4eb316721caf675f5d9bf72ef4451241194fd8c39ad686cc7d5669ed7acd677030ab6ad4ce622f9558eef75024dcada43 1 0 \\x000000010000000000800003a4fc7df4fdfdee5d4851bfac9499634726c97d04044519cf45e2843e7a86e5a7bff8a51f5c6804872d2116a9c079eae3e6ba1b33d29af72e28dbbf85ab5889a785a115788839de51c17c3f52c134fc4c8454e23158dd455ca63bb6f11d46a6ff6afd99d432a18cd44bd9eb0e4078459ce1792496681a7ec4210203538c6d5a35010001 \\xe0799ca0a8b6d9f2f13d269a545c235f72b0e9862eb3d100fc9388d63ce5ce4fcd6f58872c44bb71941410a4728bb09abc23e02f4ab46bc22d9aac4c5e12c009 1670148557000000 1670753357000000 1733825357000000 1828433357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-193 \\xe2d9974cc3cfb084e2b2ca24da3d54f5069e7ff789c744a36c17de2bc44c7c2f95f95f506e1ad725a80fc6ef144334560e71d1dbec52645c7dc877ab895ea11f 1 0 \\x000000010000000000800003c87dea5b853c55468f83c976e6ba50a02352fda54e7b4c31707c83daa18cecbccfb56d921c99072dccfdb9b8f074c5b99fef9ad6c410e7528096958e77fe1cf2099314bf2efaa530864a46ccfe15074feb431f30d69fec29199b033a2cde76eada606527e91e081b597d13219e555f7d2fbe5025765801e6a1b625cddccbfd83010001 \\xa061f29e8295f40588c812afb586a1a0b7790cf99f1fafb2285d334cdede43d478204af88558b1e631f600424f6c2491bfa97923eb2c8f3038b5df4489d0e506 1679216057000000 1679820857000000 1742892857000000 1837500857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-194 \\xe4f95993e183aa4f1ff65235f692cac80e6cb0d751990e159c2785f389dd1f32115b8888a302985f9781238b67e719f83f91450d20c22ab2f4b5d20b0d7bc33d 1 0 \\x000000010000000000800003bedeb7250869320c91cb21b2a1fb5917eb9909a21a442810703ee6ea6901db192e7dfd5c4f33dedd16987e438646417c618d15f0496f35d7027dd310ef7f0775c3f4e82a92b4514d112c76379a3ed665e710bb0f07fcc6514f83e9d958518cf3396e6485a7a7cfdf376c763b9794e65788fefde713ac37376384bde738765ef7010001 \\x510ce8219c282037e2697828bb2b801d62f279b036c1db23d2276adba000f0a22230f540b815e77ad5bb6be24c66e568231e6b102ab56b0712dff8b3a86eff07 1655640557000000 1656245357000000 1719317357000000 1813925357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-195 \\xe5c55cd0317c8712ce3cf569285aae5a5e5999c0169227364e05565d33d3470661cc9acd9a35cce5113da3558b6b38467a8001dd8d404635a0d89ebd08ae8194 1 0 \\x000000010000000000800003f28f63e1a46fdca10ed0e8b97b5c1fad947a3ab309bf0f4432715dd5fb4378a9f6d15e128cbdf86ed9786e4015fd6f09482038fbb75b318075b507f8172a654229bdd21073ab42391f3856b209e2fc4646a4e15714c97f189a35a65fdf838cb94f8243a9a41fbc1b83be2754b365ff456503b0f6cc14119d65f43bf46097115f010001 \\x9c7440e2084e1d5495c13d3aca2f50c6be31eecdf6dbad9734bbee9465e06d8c8fc99a258b63d6750f89dfd22a3dbd0caf49ce30108789bd05d115d0295aaa03 1658663057000000 1659267857000000 1722339857000000 1816947857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-196 \\xe80976c0f3b3c05e2e712a849a8b014cb79256bea36867039e58e92f4ebb927c76088d23322ac26f627dff9ea01c237b930e9291ce140d11e5a3d33a2f3be00f 1 0 \\x000000010000000000800003ea98de8d1fe15e1b36cf1b59165b381cc715d6a2899cd1c7487fab18da76a80dd896f8428f65f44ef89eded5aea2455e9a03156c5a347b9b0b65bfe9e65515acdefff7b8538a07722a2da94ec689cf60c3460f6a2bb226893ce6651045aec2c917594ca593dbcff5c2ecc4e641b579b49bf78d5311361c737d5912acdc98726d010001 \\xb1af1a06cc42c436eeb5bea86babae46236e99a554ccfaabf867a6a0f8a6988b1de65090cd865a31e4e6a8314b4b1ba8edaa8c25047645bcaaf8864868594606 1682238557000000 1682843357000000 1745915357000000 1840523357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-197 \\xe8751feee57cf472af7e6ea8fac6394ab3df6c4e0e166efccd05bbd450988f75893e1c52368556181e3db1570725c00fcab57f9d1e9a975398b4878f27cb46e8 1 0 \\x000000010000000000800003c0b17b11facd0adc564e7238c1256c6833655c3c9c54743bf3c1c556ffa9f4dbcef789989c04225ff767720b5d81926466b043b69d85e44ca95373c9d0c8dd2a94320430c2ed5c5a0116c4b6efb5a9813da3d94e8b413e486d8af6f2e00ce9bbae41260fcac53bcb28af4d212b4db2acf8ef80cf7fe06095c137867a4502804f010001 \\x49accffbe5c4a6f1cae6d29d5f4d066b76bd93eb3c3db9d3d20d7f399551c83d308fcbada155b4eb6ad5b210c4740ebeb4b06a5949b23ca376a27fc3e6475b0c 1661685557000000 1662290357000000 1725362357000000 1819970357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-198 \\xeb859eca2b55a62d79ff69c7a83f3c11355eb27b7ae27b06a54530df98a6fb5c64d0b6a9a9813e0596c78c5998ed6ba613a515b6d4d61f6cede154d23c31d7f9 1 0 \\x000000010000000000800003b64340aacb23a3467728415fd505db7d95d603c1b006215a0984807bcd56f69bb11fd15a8bd72a8a7a00bce7af46a5c94bab91fbd7c51964746020a738491835df4c9c575e9f8485e64945e3bd70ec83315e47669a8dce414eca24b472ef338d1beb000ac1faa93829b973a5a5747d9422d78a55d58411fdba235a53ba7bee5b010001 \\x66ee2e7f6bfc12dd343d3b830e411b3e82a0928422284f22b2dc62e9f2a26cdb904cd9eec288e93daac22618d12f5549ed95d31768e05e0bdf0d3421912ddb07 1672566557000000 1673171357000000 1736243357000000 1830851357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-199 \\xf6658e07cd03327399de43812b4ff26cc37fc10c45c40457741ce2f39d681349966de23827fd6be82fef8320488a353c84fe27f9cbf2d5142fdda2ed0d06b2fd 1 0 \\x0000000100000000008000039e230bdc8ca17c66933d90f94d882f544960b3966f8a0f1a969f56ffe4bb9b26670fde866797f1986fcc3879c6b0e140df9e4c9c5bc84659fa049c9cce8d13f7ef137caeb22dc17893e88df6206dd4ab2a2db82f3f6f8047b04fc224972cd476c84d9879676d108c7524e3ec31e5e7fdbeec9e10fe475cd2a904cc5e66de945f010001 \\xd94144f2e75bc8252606b337dfeaf654d5f4a93fc4a0e4ef0d62c8bfaf01e39d2084deca087f740954e5795b703bc313ab0533df730ec569029e5b48c5722607 1664103557000000 1664708357000000 1727780357000000 1822388357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-200 \\xf9d95ea501e1805eb87605e773a0c13abc0d8c2212b336de172df7b3e4c27ee3d305a30cb4a6caa62b2f68a77e3d6d8e86ae7de1350b9e6106c849ccf21d1d13 1 0 \\x000000010000000000800003b75f400b63f4c015100731b31d0db8c07827543f29f6048cea9b7a2557eda0c356fbfbace9b7b0f8b72299b288f8b9ea6300420455056604edc3b7a73a587903b44d73b280cd346f3cc50d194e2af0290b2e7355984c6a5dfe488773bdec6414a977dc2a4f19dc9bcf91488fb8a53c29183e0d9ac4e8e9a33642c33a65e9e255010001 \\x021d34390670ded59fafc97a3a6ed69a593047b03716f6c671f6b20b46eb5fc1eaede24d9f806ec29921ad3ce7fe60c5cc69ff46f12fa929cc36a958c56b9a0a 1681634057000000 1682238857000000 1745310857000000 1839918857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-201 \\xfc21de90e2abd9653c7c3985f5db466cd3ad94abb90f50b6e23ca5b4c3020bd31596866b15ea8cf446bd814fab084b70fedf4b1eff683136ea9cc7baa9fab532 1 0 \\x000000010000000000800003c4487e8b5a2fa6cc0bd0f87acd22ff3b35c321cc95ee17c5a4032eaf0911556882918992414d9dea40869d928fdbafa5765ff5f55d312544cbc0c0503ee08917c9273ecbb7bd64104b1e8ac0602df223c4bc94b8978b68e8ec04f8246e674d11db4f772cfcb3955d83f91bdb33177294c09b4bb59b97e45b4fffd8b6411cece5010001 \\xed4759540bb4cb7a6e940a8ee652b7bf6f021840ef136378a8d60366eb59904d89301e867fb077beb05080f2ed1c5d588e9ad0ec2acbec259915c09a3ef76609 1656849557000000 1657454357000000 1720526357000000 1815134357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-202 \\xfdf9f9b61b0eb8b1de17560ea51db496f843383fdcf718f6360285e0973f161173a0846c48842b91608ac5d607f0e1216bb32b93d1fe4f8028d723048e03aba7 1 0 \\x000000010000000000800003c61e22a8cb0dcf49342446db23ac8ab23204cda16b38f5e324d84071d2d4147f2f26454cbe9b5dd068ed6f0be1a34e7c79a92f9c4ed3121e3e7a31ecc84101730b43b0ac29aaf929036cda9379cc0bd090f71a131f6eb9c243205e727e480779c78527fe9f07d1991e2ab2d74b85d8acbeef116525031e8601aab200ffaaa78f010001 \\x6c29a0b63536458c1d551e13c2a0df461e7f560335767bf7b14e3f18d0cd4bfd5ee560c4e43f5fa3a3f70bad3d9eec9e5747d276879af8fc0360e8d66f1bd207 1678007057000000 1678611857000000 1741683857000000 1836291857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-203 \\x016257b2c0db7cdf2f0a854a18eea369cbb93a1beabcecdddc61e5a8e47c9be5d482db686fc8a86cdb09b0b7e119c985204e02b0bc63897b5f7ac64ffa3de2f9 1 0 \\x000000010000000000800003dc223da48af90a9647c76abe56e1cea3abb0068469dbb5da74f239e5ea5342587885011087660a14e43b710eea8c35352adf351512ebea68adc75a238b82f1e2328c4d56ca29387d81db8349339d3ea5c15603d9a41829e26d1e7f67d5a44fd428784e79b127b27b46db0413246139b6b614aaef3ffce2b7e51ccf237fd52bcf010001 \\xb81c742276e51bcfd4fd6c860980e212e3f21a18289c87eab5a356f92c61c15563e68babb86cfe04cd32627c882ac6ea44160e0766bf3151238797c72b317809 1682238557000000 1682843357000000 1745915357000000 1840523357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-204 \\x0342ae5207aa85532fa21e5a79034e5ce6b65fa72fef28454d6d931c5387fe2d810a5c7d5afdcbb6d673856847b0088b6563566e153993aeb9bf1de02625c901 1 0 \\x000000010000000000800003e25a5742fc4e89aeaeea0f4de474d712609687075f8a715eb601f437e657c62d7d5ea89444cdf108e1809be65ae3957c7b27f6f61c0698bd813696558c45e44d047f24c0cc9ff9d813217511ecdd8e72e7b5a79e1b43d7713d9cfe89994dd86d888ed16e17fff676c96d2dd0d985f2105d29e3b117fc82df2a40ed36793df63d010001 \\x61065fbd26cf00b450ea86fb82e13980d9f55734bda3326122ff487019d0e211bb3cf3368a7e62960ca40b7991127baec75670fe8f22173b9872a070f86a2e0c 1662290057000000 1662894857000000 1725966857000000 1820574857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-205 \\x047653ca588eb2f561d09d17b506b55c9bb9487e19fe966e786a441aaba81cac58e3b6ce135c4b1f439b72f0c1a22b5885c76132041bbd1130bef00b9703f530 1 0 \\x000000010000000000800003bbfb1c13008a521c88a023fa404fbbd88771132d11d847b789db4d77d669ae16eb74b7bacbee32c2ff580e9a838e55761574550ac23692bb7a47593614ba9436dbac5f7436de550103db1b8b7ecb0176af457ebab7120a03b5ee6e59e077ca9e2a217ad52482879104a7e1cb579daf5f95e45d90b54627fdb63a3667565f9403010001 \\x429c3a5460da50155b3e463dad799626ddbcab470dcc3ad1f69401a362d684130c77ca4ad7c7d0022648e78fc00d548abc2648fa4983dfee6bbccee202427807 1681029557000000 1681634357000000 1744706357000000 1839314357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-206 \\x0852a1ffa0b74aacfa84d72cdbacba36d9a9fcc79057fd53e55bbcdee9c565c19f26f464cc1ce80c01aa19271873a95820fd8e6fc3c3f3fa18f0b4e7822e7121 1 0 \\x000000010000000000800003aaf5eb70bc28d5c985ec35a23a895bfb008773ffe44ca59af023b5dac4d5d0c4cdc505389cd85961896234102a4e7d25021b74ec1b97d1ecfe722d9a72c0efb56ede22f6d674a8d0b9f99cbd61cbe2b89c288e15b979ae2e9ec36bf22587500da843d5b91b864ca21cdc04b1641d38fbec52b3a47722fa4394909e31207e31cd010001 \\xda04269293e6de2a36656916380416a63ba76d531110b85ca73ed3be462b62f22683238e11c1fbba2e00399a7e8926974893c59c0f7d0eac76a0ed4971f53d04 1660476557000000 1661081357000000 1724153357000000 1818761357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-207 \\x0c96ca54925debb8dea7beb7025ac709a072a093e42bcbc571bf4211f20cb58cab20f00237b571ae6758fb7447f3723daba153a63dda72e5762e365c0d4fdc70 1 0 \\x000000010000000000800003d4a25b78cdd7f84ec6c7eb9b35bf611372d565e04965b7b636a492811c738be269b035ae8bd9fffaeb236f38d8c9f72512c8b947ca3f653e717286444ef2c74731c24e6b909f5ca54bc7b9d5aa1a2281f846ef18909541f62c2db7f03815e85be70efce908e8b2068191b01563489e35450d013b0fb475d024ac66f4a7753261010001 \\x5b2de38cc119c9b64c73c1b8dbbd94624b79ff3f8bda424208c126dcf981c3b3a6076c5ea8f66631fe190d6ee390eff45dcd87a539ce9cffbe0fd75d0b3f9b00 1676193557000000 1676798357000000 1739870357000000 1834478357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-208 \\x0ce60eeaa1a130c8b49e0b23bc3d91f554ab7abcef416ddf9ac78388b523d8ce6b793366cbb4c8ad8c8c65b7630351d41374b5df14e8e9dd2028a857d39686d0 1 0 \\x000000010000000000800003da8f047e474c9196013bb7655b9319590f86d003e91e2ef44f0f7864ae2e9d060d2726f6db5d79e24422072cda3e9027bbe8d597270390460957fb5751bb79c4400e706364f45103fed7f5d2ee3467a386cb0187e0652ef3b5677eb5a0550b61a3effaeb341bb3d3974b101186ff4831fd527e2ef1a87ee736b6fb51fe948dfb010001 \\x849f509930166eacfb1ddcb90ef2dc968d653d30ee7ddb788a1ade4e8a5565b540b880ad2b71cdc1e918d04b78fc4cdec93640686a0b697f32157ac7457f4d0f 1670753057000000 1671357857000000 1734429857000000 1829037857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-209 \\x0e7a90f892de3b18229ea09f0f1b074c1373e2de530a761e7f61b107d1c45bcd81d805aea5df78277db1062c121a1a23011fde2b81869f168a2db30ebf0966cf 1 0 \\x0000000100000000008000039a511918ad22a5cf34d82009d4fd86ef8c41b5688792a49d02438604718f57e285ac0a3bf1aced42ec52442fcf26fdc328e12807b74297d8221295df9a3b33b49f13f43101b00e2de98fee77e790e4e493ee1304f448028bbf18dd5e570e6bf82e2486402b45366c6e8a8da49aefb01a651a3e125b3d93dc70c01d457a3edcb9010001 \\x627afebca6ab1509175cc13d4c3d9f53a78140c3096f9f3269aef440a4c77f2b81a1a16b0fb6bc8cfda519f333e7ad2d8da491c8ba106542ff80e9d8460dcb01 1671357557000000 1671962357000000 1735034357000000 1829642357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-210 \\x12aed7b54f14be4a9e7a0274f891df4f9c6c9bc29984ee5157232ef9965a0dd283a81bf322ae66c9aacc9502f768c01fd78d3ea3b0c3e715d383f81309578c97 1 0 \\x000000010000000000800003b1de39efc74ecfdeebba9eb34334d40abfff47243a46a3388a05914c3df19479f9d9c2481b514d81062963b66a53b6d8f5348c1e4df3fbd8f1888b0e647c79d09113833f400cb831d773fccbb8accc811b887259ff767eca468eac3cd5c33bc94f8e07c00fcf523c529094a89193bc478aa0521f7848e223ffdab9ff4d1306db010001 \\xc3324bcb8e492684a59ba254498a1d75012e44358c47305ac659d46acf983b838ed982ee3fcc70bef206468d38403e29f4115e09acf736c94cd7763758c9590c 1678611557000000 1679216357000000 1742288357000000 1836896357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-211 \\x16569a7ebeb3505f0c700634ed3531cf6c09d584dce7e8eac4d809c956cd111082fe32070fd7040c66fffe84a935ad55f3e801d879e372f3a773ff157616b1fe 1 0 \\x000000010000000000800003d06e13e9a2982a0f4b30dc0129757e9f54abacc751b1ac928b61fd2ac91638c7a34159634e342add54ef75c3c916ed1877cf8d04bfb457986f5a1759b3a0e142bfba63908962b09ea9504bdfea01495bafc9f59d2793b5086d624b1557f786b535dfa52257090d55cef0367a5a3ed8e40d2f0432feb519fdeea0cee6524bd8b3010001 \\xab5513f54b32defedb5c7ee3bf85f5f9184c2eb50428fa2fc032bab289802d48368446decd601a7407f4bd0ce931323f0747d14c77f01cdb3f0531b25f2a4d0a 1673171057000000 1673775857000000 1736847857000000 1831455857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-212 \\x19e615bacb44b772b0ea177491fcb9d5721442a16b6b41fac2a3387f509b8cd1ed35b94b1db9eba4bf14d069f294e223251db84f650dd11554e780ae432b5a16 1 0 \\x000000010000000000800003b85482357ee4934f723ee8f9dd4ad34cf6556aae97023e22d03093ea0318937976481f6ac8e1def1db3b131d5b76fe7746bb5fcceb1298971b28901651e743318bdf1bd29c2608c8b0129ce9a55681ee59ae9115f8e2abe696c1c2c4431c65e9c729b277458eb375f34edb272c2fbc367858db8ad14d813913d8da1cf33b7041010001 \\x8c50da67c86de84d0c3c447c980db1ddadc6e1c367404b3c763fa6ee0e7642d4e3f9a933ac265a91d57cc5866b3988f9d2a305c4dd9b83e93ec3dcb9680d8e03 1673171057000000 1673775857000000 1736847857000000 1831455857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-213 \\x1caa62df99f02a2841cc43f52398f7d8e2361f700be27f2996863ab53c571bd5ceafd7275f1e734e441e6819801a41b5df2e391d49af805ab4fed90a98cef1aa 1 0 \\x000000010000000000800003ee787fbdabd58c1b05e1dfa9c929144f828d97b55c7381eae7337917371037fd41d4610fe18c96a36d8dd1c47d3c4bfd2393c1b6f6801a25a25187bc481e8305e749941cb4d1d977e1f07097c6a1913528f5c381dbc2eb9e00b7a583189a94ed29e4c7937cd5a46c21254948fc5b112d4876d93f7897c332101f8506a5f13a71010001 \\x8858a7f4f60badcec6e8dbb792b913ff1f3ab2ec9e16f76343ba95dfd03ab9c4dafa88ba1e6c02ff22d97d55cd16f506d74b999a71387c23aa7483e1dc329209 1657454057000000 1658058857000000 1721130857000000 1815738857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-214 \\x1e967ba4ad86c9f440a9d8d6c5754e5846912d5a549a3a46c56e322b95a4ac700db1e3b366b808ba72ce598fd05f3da446fbb18e2295dbd161a2927451d9a8ab 1 0 \\x000000010000000000800003d3b484ee3c2c24611f90a568613e5a6c57c7369a894358fc8eb5c3e2ac6b2e31b1c1f0596edbdfa1fe08765c5c6ff6b147fc55e6de79fc3fe098a29aa4add09849532f8bfd5bf342bbae83ab476dba55f972d84a3883a1f1fdee6e7d3bf75c2be653d9617d0694a4607dc0ea0c54450b05fbf0b7f40539023f914828d01168e1010001 \\xf37569b9f38421d118070fed7e5290755037f740ec58c5e9777673d70b125825aaf34e88e4af91dcae3e0f3b82b63cd45c6d43bbe96449fc84a3800262f5850a 1668939557000000 1669544357000000 1732616357000000 1827224357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-215 \\x1fe2b0e6b8365d2f51b2d1fbb7f89146b54932eeee5b83985b4a7d03c443efd5b60944d37c9e686bac878514bf1072d8ec76515b0152f1d49b2285928568e367 1 0 \\x000000010000000000800003bdef71b27157e0b44fbeb5c5deb7e9ffef2d64004eb28b193bf7bd99fe1bf3b416fbdd6a4080c20cfe38fae6e2bece79edb20a751903e689387e51a867617dab65d4f27995f4da7d4a7797b218e404596fd9a91e424a926e539d83e3dc72ca1bb21cc077644e7d059bf89d28721e7598f0f85354362f679ed65da7c69bbb4513010001 \\xc2c9cec3a038c465547000e81eb026fe8fc1252d47efb03fddf7de8acbdaaf0416861dd8ea0ad57d42377cdc48f2cf1a927ade346ac0b0de2aa2fcc838eb750e 1687074557000000 1687679357000000 1750751357000000 1845359357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-216 \\x2362545c17d26fa889afd495ba6e6e1e506997d89e18cb4d77bb8bb9ec4de9b6030ccca2bea4cbca636b5ea87bdb5bfcd9040b2d1583814a2a6c7bfb0e217542 1 0 \\x000000010000000000800003b58886dfe255eea7ac3f02b30ff3e7917caf6619f21617109dadcdac36cb88e4a32e386d3fc08d5493d75441b90a8943e4e9e418268267482d38bebd9f32423a93cc0f1759626c73f73a95bf9d1917259c4f5203f6254244c52119708562c0c2c7c50f4f557f463ca00378ba73b3601d07826f345dc122fa859f8dbca4ac46f9010001 \\x3a5b7cc8922b0a319e10d36637cfc50131260f9de1750703da5c3f1df130950853987a36f812b6622b7496e0ee24b394b626ff9e233dc93953d8c45dd221330a 1678007057000000 1678611857000000 1741683857000000 1836291857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-217 \\x247e0dc45d360eaaed60d47afd483f582a83af98be2f0203dfe5a3b688e94a277662edc517a3f4d42dd7ea5d295a4340e6ac4ad9948c06282413e13f04c53041 1 0 \\x000000010000000000800003b3f907bf6e5f20b8a0e21a1fbe240dca8f6b48f27da7079cc251ef5c5003936c5d6fdb2070d1e9d6db181343959e759482af4890a980ccead42fe932b5cae3568420c21d2727b335cf974fc9d7e17431595bc8b2f050cb3c5c8ebf2e3dc91d2ecc4697e18909c36103b770a7f8f7ddb8a69ef34343290a792de09dac4e341c5d010001 \\xad17daa33ba519ff68105a722402941d47b1e3e15d379ceca3ffec566c108ec8431c905ff63b36c5a141e4f7b95791e0c21864cf3731b195f8bc698e2cf5e60d 1673775557000000 1674380357000000 1737452357000000 1832060357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-218 \\x2686440c4afb009bcfe35edd52e30c50c31e7c1416e6fbe31723df0b7a2a67fc50a92fe31a9bbf695a499bc7505ce5b9e9d1a21683d9523938b6b36a81deddef 1 0 \\x000000010000000000800003ee83033716411ad454b1bae0036ce48ae32cae645f74f05bfd002c5f85c8da227f5041543856a6c4ca8dbab78b595cb7e06586e07ab4c3506cd41addd23ad0cc065ec684b7d6201ddbc5c2f32760c98d1dacafa8be796f8f31b2d7f7f9b6ca2b3a315ea4dd4b781b4cb90e5834406986436e6a2e3615e6e6527dc1435e5f8965010001 \\x6dd93596cad5090333639d40459457511eb5084982d5d01273b8757f883485a65c9b44ab8fac0766a1d0ceb26ea407a4644069db1fae58e48f2c34c66fd6810d 1680425057000000 1681029857000000 1744101857000000 1838709857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-219 \\x2786f51ca2d4a2cf0c3330facc699aae735d81170328d8a0d19cc363c7af4fee3c000eaab75e2d3f797e8d869a570d4eae2080c0c0590e70b7b168727a2aa90a 1 0 \\x000000010000000000800003da47dc21f4ca12304be43c49b60980594414afed8a4c566402ab608c752dcf0c57da6dad0ffbd7b616b4a1c1297dd6150cee4470dbdeb7b1200bde3c0fc795535deaeb9b327b1fc13b962b25aa944c0c33cd505ffe7f651ab7ed2a4fbb234eced1a3330623db912676ef100c2f27ed5463275ea40c95a04f8297376652219ed9010001 \\xd7ced3db4e2e851446822a214b4d8ea976fb7fb52c222db86b4c4dc3b459f90cc4242b96eaf28ec21c31c901cac4be2f5db8b2e13525f28b4520f2cc4cc80404 1669544057000000 1670148857000000 1733220857000000 1827828857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-220 \\x2acac47d28b0bb1d77670cb99880a0590fce099dfebb65fa431ac30ef115769f63e06c9a7df53b2d4526c2320068dc02c9faa49b1679b5b10d9038fe91a22a7f 1 0 \\x000000010000000000800003d93989c7f1103cfc9dacac06684dcb5b81bf9fb7f697031dcee7b11fef3ca04eb579063bb009d4421bf4d056e90011776fc72204059c96044d308603e35011390b035ee10868881b136950a849a2f44fbf187f4d3ab21462e54ce217c1fcf7d29f5a35edbf55a8b74216554d64d6b139107f693dbe07f8540a1f26fa53c89f71010001 \\x13c71aaf327e21fb48c7e2335fa9b558251c71063912517809d646f31becd1633afabab469086e546e604f694f6cef166c842864873181d4a25ea2fd7f2baf04 1682843057000000 1683447857000000 1746519857000000 1841127857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-221 \\x2bf2e99b36c2e52eec209ac16e9f21680b30d115e228d2e4151dca5ef9db014c4fd86c4b00bc2b998aad56a5ab23a49f9e5b5317b8d0cba55377b85056d4af1e 1 0 \\x0000000100000000008000039b917094c6801820afd7de4a6e2fb0f66a99b2117860982a3f625aa7a7fe5899beceba0e645015685cd3203dfbf2e991802a3799a47261b5d205e8085e31b0559acb8748bdee33821aadb0dab8c516207210f53bbe294c88fd737eca67c036748b22fa9ba889df1458e88d8c6d2f882f84113cadcaeb4975b1279a941f7c0e93010001 \\xaa0772848d105972a2d9a164ad1a20e7d9963ded13e9b619db1a2d543e1c6a632c526799c2012ab6e168e9a856066386fe1ccd1b81bfa90cbe94d5d8d67f4d07 1682238557000000 1682843357000000 1745915357000000 1840523357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-222 \\x2c9e36460a7c9891fa623390de15be8986bdff9643595e1cc9187b3395e4373a56fdf428167fee1c799ce2b4ad29d7e8d76e6b85c4a19c1eb26a55780d1d0c4d 1 0 \\x000000010000000000800003e95535b3548667c601530fdc2a6a5bfb9c2b85e457770e2daec657b3abe576b97912765b2ac2355ed337fb34c94a6862eea731fc2d0a3e5709148445fde1009f13e9cdf0693822826d62b38bab713d9d772c53fbb327935d8632fa1128c2aa1ff04971d1659a87635491a60928449fa05115c97c1930324129295625e8ff5607010001 \\x493ef2a300315c2b164c729b1d912ac911b5b87b7004cf561bf9372d4bd5e799a4f6340d477dc5742859a909560287c47b8e12f3cfea37cf20c3a0e41c480106 1668335057000000 1668939857000000 1732011857000000 1826619857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-223 \\x2db2d50c0e8d2091cae0454ac8d8a827e4865a6ba48a2a242ddd9f24f0848d60d2136934bc9d85123f2a2cf489b9a44fa42c988604793e4f2186c8598521cee9 1 0 \\x000000010000000000800003b0c0d2d216183936248dc3a038b536c74bf56c4c6c3b80fefb9315204a6089e175d6c8d408851630c18020f708c01985466a361100b00413e8e00f5716ecfa4adcde6886e7170af5820dde95f27588ffc3e6c3941ada25aeb52dd4e3ee6188be8dca322d0c3398f24cae89017833c62dbefb3d586a6e52bdacf11a57ebf622f1010001 \\x0d8eb36e0f84b1e42913b2850e852fe75344cdd313019605ff99498e6785a9477326830f9b087d7c4ea8db52df246042d272266f115f7591c24686bc1b9fad0d 1673775557000000 1674380357000000 1737452357000000 1832060357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-224 \\x36aa6405708d256fddc1a0158b563500edaf9909f9f0fe95cc383fd3f036040907bef11c1a5a4ee26fb6dd3bf3e9a8a2aa9520fc1dc3bc479ac12af456b26437 1 0 \\x000000010000000000800003b853a832562970128c436281e57dcd886d76212867c2b45ebd7ec70e580054678b860c06e8a57176e47fc5b8f8add70df27ac1c5b9368111ea9588a4f86b128e60316f979b5103f372446f780d0b192701125336b4a001c29ef8cda836f1c3a434f60837927d7a8d1fd8a610a665d6e7b1f0c6adc1813433661edcde72146f59010001 \\x619ea1a01b1b372dc1fbd44ae9201d4c320cf21ffff198ae87b7adad87bc799bf64612aa75b09511481b0eb6982b3ed978e7778c36b285b28aacca35359eb107 1676798057000000 1677402857000000 1740474857000000 1835082857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-225 \\x3906a78daa246fb435bb97dc5988861b5d49b240069d292f5039492ec10a51aad286b638eb756fb5a3f7554c9c9e55fa0654f4ca59a31dd07da7fc66a1311def 1 0 \\x0000000100000000008000039d7e0eebff6838dbee9dbec98070761808af46d7152ec8097fb33d87c8b4841b601f32301770f253c9746c1cf9b4d82829ac33248bdf5c5faeb32b10f3bd43b5d124b22571f22f522cb4f23b4441a7d0082f61c5880fb9707d13c91bf725fa2b523826087de79883bd4ea31f66ab2d1ce78787df633558b30c3320f35378f3e7010001 \\x6e5e785c4e61a3399d73e0d50650f44e1be438f39dd12a3029071b5b12a608ef1496a3d758aad031c5749a072c65c0e73ab730b04a5862facdb9370bba293509 1685865557000000 1686470357000000 1749542357000000 1844150357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-226 \\x3a123aeec7b8450c46573271397351f4af3678e14620b662bf7d080abffb6d26b053fcd123129af502e06e3a65f003686a8f44fdd33772727961753404787a58 1 0 \\x000000010000000000800003b84b753ffbea7eb58fa2817a96ac2f40bc15a7503cf64c3b724a169aed7d4dd19d83a20c18e663eab0b8a052d76ef89ce14511ff3ce8a564d006b0eb968690635808485b32b849eae69dfed5c12432500052f25f798af6b17578d4e3465eed99116af13abcb80847ea25d771fb32addbff54ea8e061537a224cbe572ed666b2f010001 \\x05e3605015afb085683ae7d524cb248dea796367e0d8acd5a687917546214bfca57d01df0f473ed3b3021c74104f7e66e72c12a41c8431f55af119c63ee57d05 1685261057000000 1685865857000000 1748937857000000 1843545857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-227 \\x3a428e11de8449a173929dc1bf774ac065dc69bf0de53311c99ad631027460e861d1b54556bd462366a53695864beeccca0b3fa3fe9fab383e885c948aa1442a 1 0 \\x000000010000000000800003c35a8f38bf06940506de6dd0138d2948904aaf690e9beff00fbd239b4f9cb4f1634595511d5e2bb1860c142b3853cfd92a4034dbeac322b37dfeecd445442e86a9db27b6ab5163339b8faa3006225ec7efa5389a47f6f5d324f96c77a5b283c7c8a8e68546e87da1c6f37538fc53ddf33f8308624f3ca48ad3500a06dd2e8afd010001 \\x3796230558da295539f006ab2ccdd2da157b5cad95c2efb9868f68a8476dbc2b0306dcc58fc93e395ec3183bd22810a4c46a53742dcb6141b5ac8193646a5201 1664708057000000 1665312857000000 1728384857000000 1822992857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-228 \\x3cc2a88d704f0459451696b7f35551aeca7ff8d684619663c451f4726ad4f554b57f8b690954021bfd903c488f26cf659059ade7b55a4307b93b0b4dc12bc57f 1 0 \\x000000010000000000800003960f20eda3ebbfd1c619319998355f6cd54d19e8cbf3b1394f217892054b37bc86aa2e2e80afb6eeb8887d01d4102c5f2b8dc91eb51981d7cc6dca6137415dcbb5e37987da07b969a1302f498a7a58a7a10b62ec03e14b17067ea05278489d56336e06db9a7adaf655d474ddefcdd158790a7940219279b1cdfc51195580f90f010001 \\xfde2ec91673f1a4ee3417deccd12266e8a3c4ceefa0e39c1e89663abed80eec926a81daa0e51f8ca087a58f8741203b7b9dc0db4d43434855474bb30b71bc50b 1656849557000000 1657454357000000 1720526357000000 1815134357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-229 \\x3d124ff3cacd5dc5cd2b9033484feb76d7445e2d54ba4a4e9ce8ad14081c2a781698a945201a6f4fc74f8d8420f5dd7831489b23771cb189509527bf8e002650 1 0 \\x000000010000000000800003d37df21db988a2c2fedd15c1699b5f1b22c7aa775e2ad0da69d303bff0b724aafa24ccb5b0db72866898a51019e5f0e5b4aea988cd408d27deb77a8c7bf71e87ba9b1c4826720ad20fc91597046930547cc586f3bb9fd94595c5e51b9bb74aade9802460392fd6cde99313d5d28c4e41e55c8cfc697feed6bce62d2540c62977010001 \\x787ec95841105b5307c8c6b5c978aa9a566bf72761bc6d03b469e24460dd03c0d27dc577d178d6a2b4c23bde341fd6ed03ff707b8ae9711e325b9f2fd0c8ca0b 1655640557000000 1656245357000000 1719317357000000 1813925357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-230 \\x43fe772ee26bf2aeb458a1702399deae73622c263d74397b32157db5c2af4ed861b4cde12ecd39b914a08de5e96a1b88283b58be57c56481fec24dc1824d0ddd 1 0 \\x000000010000000000800003b05ea7a9221cb51992f049666f3bebb3b8403063286c9c895cb22febc3e6ee184289e887e5c09cd87dfb25785e9608f532b9752025eb58d6e817596642724d4f06bcdc510109b5a5802c14322bf72dec97634ef018a35992b1213cf7b2514453a7891acb09f115e0162c41466d8ae3a3c23d39995903900a11a3789d5b17ae81010001 \\xf9959c75db19e701a0e2b5c5e67a475532d76a55aa63e11c9963c916b9d888f98988a7ac1dc1630ba2722ca8cf4bf38210feb727480c54ce7d7ad0a5b5889c09 1680425057000000 1681029857000000 1744101857000000 1838709857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-231 \\x4316945def3badf225bf1650c8aaee52947791c69e75337545e71d07673abafd12ddf629c809cc99619de43795d883637fd50a7793f6b1d7a436aaf05435808a 1 0 \\x000000010000000000800003a21be3fbafe357d449a6d474584ab8c62c05b7c026d57b1de554dc72619d712cbce100e19465626322c047467ef46aa9a80ddb021a45afc216626c14c9238177f2d8f58cab3e06e8502b9b85ae65e15742d485e187718e9bd855403a500e1b375abc22cb7725d4c57b7fc17d2dd9698d5b3537166db460d9d622ff602785be8b010001 \\xc88687c6fa6898c86898ef45174101e86a36a078867b0a185b649bb51511d1ac3de0bdc758df4842300070f54031d495b3fd31151f4910fb4eb9e65355641c03 1685865557000000 1686470357000000 1749542357000000 1844150357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-232 \\x45e6524bf0e3b202ff038ed18d04663a250bb1455dacfb9970821fc68d1cda574026a9318b8b0f38941d846871bb718f95325c9f8a94f24b4d9ec3407ecff072 1 0 \\x000000010000000000800003ed7afbf598e9f56d5237acbb8f526547a3fe96307f8c5b56867994e80b16b790167c7eb797b06852897b162f5397f803bd66e9884ef79ff756f42cd421ac55d4086803bab354101cf68f9eef0988c1a879532aa2ad72311bdf5a622c291e3968216ad5ffcabcbde2c10d69dcf8cab563e8c3abeb78a4ecdefa9d9d6d2123d04b010001 \\xfc1871fa21a965717f7e42385336b84186393dbd2a45decd13570cd1f3776c598679a6865cf15e7bda3389fdebebc714e8c0b8d602dac574956b4a78be7a8904 1656849557000000 1657454357000000 1720526357000000 1815134357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-233 \\x48d2100c44c5f3a007a0036970220a733e98de60283430efb93a578257c68418e42b6327904e22f9a7d3a22c71f8a6849a247188eea2e0ea450451f37ebb4c23 1 0 \\x000000010000000000800003d46d4298ad66b9881e1a382fb41cdee9271608fdbea61c20d0b7c00c02c68e81db5de17c56c252c99a9b111d7a8c9d6c2862364b97fb11a6e380f771937fd274897774f18dcc25e600ed88d631fce11a69df0e975484ad171256843357db74296a5aa251d3e14ac95aa3c84672a044a181167903480eeb5a0ea88620b336fcf3010001 \\x5727a3ec747edcb29306011ce94532d5f88687065285b6b6024b959904516fd193d5a1ecdff4b7dbebec03b0419a7c1c25bb4263cebe3d13d04244aecf2c5a0c 1686470057000000 1687074857000000 1750146857000000 1844754857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-234 \\x4fa6be8f8bb8ac07194296188337212393bc42c999da2c70bf58b0d3c0df5cb738a5547162670f7820a20802e93a9c9448dfe0cbddf07ee1ef97d778f59d4415 1 0 \\x000000010000000000800003b98963efe976dd240c0b15c80795dbba426ede4be20a4844ad5085b6751c546f083a2185baf7b872208235c5ed591fcb516ffe44ae5af728321af8dbe3448da0dd45054cf3e774565dd8e75ed9b335f44c8d496bb361c8a713975adacb8e4c03f5e8ccd342e18957895e0a3d7758aeb61c8778093e2da9f0c8c526de6952939b010001 \\xbe15ff05469aa45de2511eaeaa45b60315934831cf71559569c419ad50d8b931e9a550629f79043b67b17d60becdd9c6d0bf615d406673f836cb8e8bb3bd3008 1686470057000000 1687074857000000 1750146857000000 1844754857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-235 \\x56fefd79a6f71ccb5a9a5b114a54071a6af713fa5439ceb501563ff3e7ed1e3a813f713e9c3517d9ad847e29653424e7cbe300f6f537cc2102f544c452898fd1 1 0 \\x000000010000000000800003b806c78b7c1ceb66735f262eee5ecc08ed7cd899a4ad5de1c053578043576894aeb67a1d16ea5b4f6b2abe9f8b43f2d9c3e9596fe0420d24b95812eba26e7d673378771a661b028ab0e6532db0b71da5ad53e7b3467bac20da9cccd2fb640572632e63a532026cd1596ce48e93af712f128e7e030ff1bbfe6a3c50851f9d1195010001 \\x9e9fc931c317038f69788b463aff6dcb5c1873f9ac0b23e7b71388ba00dc5556f5ed0b16433daf3935aefc23b66d201156fcc92d7a2f0b50f416cbda5b07280c 1671357557000000 1671962357000000 1735034357000000 1829642357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-236 \\x562a24da988139a298dda942caaf605ffe9523fb3dc772ce3849e839ba677465a68660ca3699fee75afeaaf817179246680d1835a9884ce633d22aa43818ccfc 1 0 \\x000000010000000000800003e442cb2ce981babc4da3153932c1d8548f3d9cc6aec140fbe08a36848cfa7425f416d22be2efa72656e0870eb0cd74c9de1a3597f2daf03f5810e9d57ba8eb44800b9f7c619e2418a0961a09bd44cd8feed13e14eb11e51d5b06729d75a39ca6f74fd5064e8537d2fe1bf50d84fab7520ec4f945ead26d1b211235316279ccd7010001 \\x93f4be54d1fc2835153351c30ffd50908768e3bb02639f8714f7200b21d3be759f055128af5f2b574ff165072d0f5bb5e2e81ef166509f3d83ef8f6a0add1908 1670148557000000 1670753357000000 1733825357000000 1828433357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-237 \\x578233d7fe0c3c0754610c3bbb041c5c4c7af9f1a09b369ded445f17c2323acd5ddc29d28a8e191e87bbd5983de2705c6b6627fa1e4cb1a4b297429ef59d94ef 1 0 \\x0000000100000000008000039dd46d1bf1df6666bd79e8c2ea30a5a4a0426339637103ec2f256edc6afbce9eb6c74903bd9e0e22de1951e062fe9f4f2ee7425292054e77065b8a5f712603384f1b4ea0f77c595e23df99cd09690d0463969bce28268cfa87de990bedd43b0715424121e8627d96cc7a67d372f735efde374d5943a628c72ac3951223b1f793010001 \\x77d0c1e36d520c4e91d2e31bb01f3a5252dc666ce7e74b1b0216c57fd4ce94a55ab7933c8acecb7c61020adbfd3ae74c1db315af8a4957fb98aa285944e0d005 1684656557000000 1685261357000000 1748333357000000 1842941357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-238 \\x5912c455746114c96b6bda93d25c37ecffecfb0e5a82d2cf26ca754509063808a997f4fba4795066d8f725aacf820d436b5b09c5ffdb58343978c4b198a93470 1 0 \\x000000010000000000800003bfcf0d0ad6debc6e15e5ab39462dfa3d00b91625d964ac61a263c07cbca65752ae79a69d2e13d93d60f50c2f409397e4eb663a9d74df7821907105cac9b36daeaab7f799252f0f393e1e93237c40be3908cbbd508cdcae9f6df2e657a0ccc4e5e02ea7eb5d1ac83259daf8594ff00d5afc0a1150e3e2af6992c87a3f61b1d66f010001 \\x0c28c88e0f16ebf450c22864f996767e969efdb7c39c0f4f15b7a6e8401a88a9f9bdabe661877616cc4a3f13871344382a4b2df27d6a359e6de90a490f208a08 1674984557000000 1675589357000000 1738661357000000 1833269357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-239 \\x5ef286a67d66eefc75c36a5fe10bc1dc56ad460396e1049959a752a98dbafefca948d9ee3ca13fe6b623cc221abf04513dad031e0693fada5c547164eec14542 1 0 \\x000000010000000000800003c41ca6a2075dc517fa85ba8d54f03ea482a8d7741616431468933100c2df60c8cbfadacc800fb657273652afa7875eda4843ce1e4b2bcf55410568981935bf48a511bdbde2efeea1f0327cd7f563afe1ea8740efcd049bdd5a32f2c07bcb66f009c508a05bec27d7d5868ce5023f21d8536d05e12ba5ba5f045473a664b4c5ff010001 \\x5a9856704138e35dc593f5316b00336b2f2feca04975db3c1845e7248e7c24128ee0660ce83d800bbf5781682fe429a666c9f79a4db469a404ea400f475fac0c 1680425057000000 1681029857000000 1744101857000000 1838709857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-240 \\x6046434266cba06f28e78e8f2fe9be2f114e2857a618d9d0510c3fdd50528e6f5e8c2d15046ff6f945898dbc2aee42a439e3df23d4f2ce311d3684a45ae2a635 1 0 \\x000000010000000000800003d41acd6de98e4159512bb543e0d1ea37996a7ef1f0dcebd526d877a6d12d0dae0854574a5079e3dee429b4b8748876d2ad1b36ad38fe803ac88f6962162fcb24fa826a0523624deafe334db1c36ad4379bb2246b8972416db59167f4521fb58aff1f2d0f9d20df8927831fc9ce00e41e20af2790a21ab98b1cee2c23c258b8c3010001 \\x7104f06e2d23205eafec081d2c548e6ea76db9a60e647af81219f30f8d57c819f443a557f9da634c436a89429d8246bdc94e6ffb7499f2c029cfe9fbe865960a 1656245057000000 1656849857000000 1719921857000000 1814529857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-241 \\x64d288fae4bb0451013d78489b2f7f8771eb27864bf0c019b28097c46ddda7de89b701575d1b25c7896789f2af449c862c0511c8fe952cec9ee0385317b56688 1 0 \\x000000010000000000800003ec361141896e9851bb7d5133858eac2004467e3cdd75a139705d778dd4640ddfd151271c7d7305240b2afc2f55b502050dae66a38c1048e7584ff9560813283a48165fc46c6f8acbe04b788cf362174ff84b976a3497971f167c63256d4ede9d27893987e14d9ace14ea2d81c4f86394c2893c0e115235cf11172f5bc6089409010001 \\x367dd93973cbdb49891cdf9291a01fb5c83b77ca9071351f8a82ece9394ab17ad9808447c9200e53507f59e38d68c592681c43210fe9b352d2a5cab5bcadce0d 1686470057000000 1687074857000000 1750146857000000 1844754857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-242 \\x65e665f839c534f095cd5f88a629e57b9233506899f949b228a7594896a2124b5b0cc408a166cd6d63718b195dc63ae6834bed0dab7b9d147415aff55214b867 1 0 \\x000000010000000000800003d8cb56fcaabbbd256334a37e591c8341ce89683b5546e483092e542aecfc175a72d36b92fdc7d8d2057b2d807ef3aa9ce70d15fe52007fea05b6c4d8401669611801a5f596b032f1ca82a718d3077ca53a771870ffe523abdd97133850f25a78f001d294413e1850c771324cd43ae17da3bc898e5fe6e3bb21588f4ef49cd421010001 \\xa06724389d9d597a23a909460fcb6871c681a7eda72acc2f0adff61060fe1ebd858a19e3493f905e45e4eb0c8d5e47ada9b9fcd15e3a73b275b60b5f64ac8509 1684052057000000 1684656857000000 1747728857000000 1842336857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-243 \\x65a22c9c3739a78dcfa3c195bf8fa1871f29d48dd58957858676b7128c86cee2db72bb662699eb6abe76c8fc422e388aadd76290381fe45937ddae223b79ef60 1 0 \\x000000010000000000800003d1b2dab5abff99a478610f64553ea8959b5d3a84c893df251600ae4a4c19891c0cf413f4f9367d83b1d5fe08f1c002ba080521031a5a4a79ee87d96c680100738be46d6586e3024e4423986fb676bc834313fa330fc8ff390ba4146d13edcdee65daeb2420afd728943ee18624667c53cc0a7fde6190a3168bff9959d6fe3d03010001 \\xe6ec634c10aa869f8158c284ac0ff3cc74f24fa5c98db278c8b1f9ec8b603b9285a647e96f9634697b328b7e112d885d9e39fe0111de156c3b87cfe898b8b305 1662290057000000 1662894857000000 1725966857000000 1820574857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-244 \\x6662b787e9379da736066644ea3b2f336e8e1685baa14dc8f25e63030bf45fb07a6679b799871659c1038b50ce7c92d2b86f0bbd9204d235021e11f0aa2a2d9a 1 0 \\x000000010000000000800003d78ad4a72534375b926ba68613bf86b06a75fc4242bf24c5628a39fb89c2605c0c8f113191ff0220cac9fbf53b23da1cb37a11996bb8a908247fc04b57c10b49eb4a6759bc69079acde9e6b5f606ed73b901b6d843aa5d86cc5dcc0905c438d9563ca97de0ab60f06b5420579520412c8f13948e5596f1a6894a961195740f61010001 \\x482ec13b7174a7352b17bc652b4bd0b185ea7cf4f2d10b28b030a7b1b4fe16f936c405a52583d113d5ed3f1832f8956282ed1836dc46c432c8e387c575f3ae03 1664103557000000 1664708357000000 1727780357000000 1822388357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-245 \\x6f524c272b991dd3f67fdf929939740f269466fdf835157ee0302782761cdb8c06dae3a9719b9313a38cba724efdce54921396c813a152f00aa618c056703e4f 1 0 \\x000000010000000000800003c276c836e4a0d6ed9dac28072bf443ac5b6c5c2b7fc4a31d075b508cc9532fc7da348115a7022930fa1c60afc831d038ea99e8ee1444fb3cfe562fe009e25dad610a115feab119df11eb4b538c27adaefe160a5115fa44961936023889a1537a8224dddbed73fd977c7845a7924e42b0f11fd9a691f653d91dc2f090b43fec4f010001 \\xa617ff0b29836ef4e7e49801e02bed07dafb4c838fe3d28832d7c7287f3d6adc6b36060d58d048d6c22d101e5fbad7218ae772db6c513dff4f80b5da1e64b60c 1657454057000000 1658058857000000 1721130857000000 1815738857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-246 \\x7182cf312082635da43f9a76fe2a76efe0f8c5ed0bb5fbd9ad28880a81bcc0983e70a46bfb52f9984ea8a5d5444d4409f69233dc094a83d9a176f763ff3b0b57 1 0 \\x000000010000000000800003e6f7dce272fedc8e503305db5d50cb8e2f304edb7e91f2620cc0d69de45532c06a76e413acd82679a00ed40a00cc4924aac6c9fef4551ce837dc7c69705fe7ba5d6519d4b8302debcff47fc77f1470af043a7213d3f0e9c28439079edac9cf43583a2e761939237210a4dcfd6d45cb6b8547d7fb68244c9ccebf1753918da861010001 \\x53ccbeff495bf3ca3a1602ef38856ad9a8d5affa73b16f5ac9a0f500b8499a250bca9b894e2e5b7116deab37ece0166d2bf7b5b9f6ff5304bba8996b0d0e6802 1684656557000000 1685261357000000 1748333357000000 1842941357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-247 \\x756635b874cb840f164d156e4540928406285256c445e491757df471f0636a326517716efa4c3143013a0ae41a8fa33da7b04c61730ab11b59cda8c037ecccbf 1 0 \\x000000010000000000800003d2b5872852debf3b0183145f496978a8066091b765cb1d64d71f6e6e44682b4ca892b372311928e290db929888eab3f8d4e4339bd69a28b03743cfa78ce4e675045309fb82c6291beadb48fe854e2d4b722a9c34e7718729c0d44ac1c7148d18676bb2dbdecc1c7824f40b40305a3af91d9cc3c36705e59ff88f9b7c917f5817010001 \\x45662d4e109e82d12ee1ab789bfd1b2985fde1e310460658be35217e33862922eeb75ae7e89fc1ad92aaf71caaefac31f7b863516d24f67e9121b42d2592bd00 1685865557000000 1686470357000000 1749542357000000 1844150357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-248 \\x79e699fb3c4891e8df6459606e960f0601fdd243fc3ddfac44fc8543c700457f348d4a96c3f0230188d9144653e36e61ae7fea22fbeb3b1ff8cc0f603a24f787 1 0 \\x000000010000000000800003b7ab1efa60c00adbdc3a004c1d05eb5a543a456da5fd3c3088e33db5a26a8fb946a9932693ada2aa669f7f98fc175362c30e6e7f1a6d9433b5c979fcf4d83f4257aeeeafa414f304daf63c82faa22ede3cea8f6c819ef540c30e78f514357214ff4663d6069bfc26c25974599a71a5beb950500f0e4ce8c91202b794a9ce8ad9010001 \\x300152d7b82da4a279f23918bc4f298b6f2487bac06969c1224d7398774ea8843e67f92c867f1986c3ac2d9efde37bebe8e733e76fc8d968aaa560f1ae74bd0b 1667126057000000 1667730857000000 1730802857000000 1825410857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-249 \\x7c52175b475edbb5486c6178ec30773aa925fa90870b5de91a01ef8368d0cfd3775cc627f88bd35f5a1ced93e231b87d7c9f237092fb173c13ea66b5a173b04c 1 0 \\x000000010000000000800003c50a4648ba5a19c5daf8fd8f02d50dbd6e097b1d8aefaf002bb5487d07ab297bcc3dd92537ab20a592268ed50b8b770e98fe3d62c2973cf8e39ac9b9860332a96d4ba83a40b073f2e8393f39532b80ec5891decf6ca3c7e6bf3f2fe27204e6b1ada42ebdf7cb96807db41e2fa124bde608106e5b141838a85768c08204978801010001 \\x00d9fcd95925e98df20259960cc3f7eb8e29c6ea5366c8d3318466df6a4e4c0b9a1e597ba8773ee81b18224167ebca3d0da2070a873661d81ac530f5e46b6c05 1656849557000000 1657454357000000 1720526357000000 1815134357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-250 \\x80126eb0cdf4dc86bc53f6e0190c0952e8fc9e9f2f3f52a2cd9560134722187407bb560d6c7ba77e61cd7deb53edaba6f32b0f1c0acc1e04ba53d0b67ea2cffd 1 0 \\x000000010000000000800003a088350a0bb1501cab50089102b313cca4771176e6126236767b1df6b8d8ec00b979ca00ea8dd7410cebbc5b10dc980de2df6a7fd20bbc2d2edf719fc35a4142eca7388ae8fe29e96408d57dd7a81f8045ce0fcc28917be12b0906ee9d5c335121e2da9db9b4b0e70d887d851711abc90259d3449d15ea5b7fafb1c919eed9dd010001 \\xe5239ae91f50a496ea0856ece3ab11ddb6d1a55187145d5be4a63049bc460c25c6455755c181d1dd077d4220595e47dfb24c24c564ac70dd6d47c044be316b09 1662290057000000 1662894857000000 1725966857000000 1820574857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-251 \\x809ad422d94e77867d416c1d65ad9d01e5c3439fb3d9f90a1d1814b137237960daa3fd4966b802eb65d73395ee80c604a63b6491d86c12051cec605b15bcad47 1 0 \\x000000010000000000800003eefd4699d9b505435a2eda45e9159763662fb193c025eb6eb22750afd0478b13a954be0028a594571ced1a469fbfe024e7dec39bf80a0287aad60b510c97e0fe7085d29ba06148b5ec955c53d9e5fd5b026c096523abaa45c2a8077ea96fa4dccd2d58f554df21826cb7d733dad954dd2c8b563b5373e7d598f9d7a122f8356b010001 \\xca8591627f5e9a45a96e01b391c824298824b7be541da89c68f0aa2033088c3b793fde4a64291a8a94f91c25706a4861f060a948762898ac5b0cbf54d9dfac0c 1668939557000000 1669544357000000 1732616357000000 1827224357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-252 \\x81ee9e2f94e0e62d5be7d9adea04eabdfb9b744f9d1f8cbc3bf038ab0ea58e45a68de664eb06ddc78c7ebcfa647fb13dc88aeb0d54c5c9ef03a3264c569ce003 1 0 \\x000000010000000000800003bcf92ba7a7f5871a93bb2547bc8ad84ff37160ab3edff31940df88e75d5db2c8d7db6de0857e333484c7107d66063ec2c6093cf4fc6667f9f89799cc0705cff3f32eec571a8e78c50108e47984d98a0f8d46b024415000316d2c364d42beacb5bef69ee08133dcf4e6f386557fbe44095ee3a1931085cb9dc332345911e0e88b010001 \\xe5943a3fd853ab60869f9458a69cedb2bb5e853ade9c5c8aad3f7048bc700c870d9c76eda837a80a2fa76d957a0ded37b91f831bd8ea784ed3997520729daa03 1670148557000000 1670753357000000 1733825357000000 1828433357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-253 \\x850eed79dcb09e93463fd625b2ef20f1b801097f31c494173bc3592cbd7372f68c080cb8d2023549beb57b2318efda3d0c3256c6c24899361ef19acd4073fbe3 1 0 \\x000000010000000000800003d7105edd9932facdbe2e3ec453f84f90eeb8d4e066619fc7c35863d65251684d51b257a6a3f5d5bbbee477f4d27df7cb5c0a1c0a6db308f5cdec0a998c0edbf5cdb91dc394e30ee55dbe6179a295d72b01a9b72186db788bcfea7bdb06174735a06903bbad01ccaea61231b5f8c62d492b23de80a38bb77a9ad3ca5ec09d5bbd010001 \\xf9cdc36569d2b0b00158c71a2df15db86c8ecf62d3fde2da9c0b77c1b0daf85005487a909bb71a1f10f0d8d7e829184afb69081558930620a126dab3e5a99c03 1678007057000000 1678611857000000 1741683857000000 1836291857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-254 \\x8522205bd925e238681703fbeddccfe8c01857f5c0d7863ef56678264eb8a28257e0dc8178f62a345eaec8177d71089bbba0a2664c47b1a1188b1babaee28acd 1 0 \\x000000010000000000800003d54a3ab4da9f46c20f578823b792ec0aff88af2fed4c3a9e31b1349fbaf850e201fe0ecd5695b4af5741532c152be3f5a4d78fb5a2188a6ffad1232adb61799dd2aa745fc8ab94d8f873eda44b2487a7568e3322dc2f22bba3f8f896d32cfb3ed3baa6f08a41d02644c878c943f989fcb2a4f49be7395dc865bcaf5174de21fb010001 \\xe950751fd44403d50e20b7c2727e13c193d77379825c99b61997f5e056206e5f22a92cd1503bae7fdef75666d84c873cb056a07bdc5605c036cdd376cb60af0f 1671357557000000 1671962357000000 1735034357000000 1829642357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-255 \\x853e9a92417763af925e40bcf5b86996580dd80112c1bb95c177304167a6db0cd9f0fdb146a29a1087e8ba695492c78cf7971a7664a76142515f9b5956dfb0ac 1 0 \\x000000010000000000800003e1927bf8f96759a317120a357ccba0d87425d69c27ec629962f05c2903e533d0ff8885bac15df1e793f6d8dd61186cdb3eb9c54bb7b0678d574341911956412203df86c4623c6b5d06e6017429df9d0f15b9704ad9c058edd03869c847aa7cfccbdfe40ab3199d84e6ab09fae0fb725182491ade054c72076437a505cb3dbe21010001 \\xa53076502930e73ffc25bee5905878f21a5aed5812c29643630c1ee06a66e432c036fc86a950c2cfca752ecf24ed47a62944defe5e5285fef071b51eeb016201 1661685557000000 1662290357000000 1725362357000000 1819970357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-256 \\x86d2229587a5d5008ce44a09197a431260331a3b729644e98b6f6411eb991b51bcec44430e09ae3ed4ce8e74137faf3bcedd04a8a5b1d7ae260e07c045a32225 1 0 \\x000000010000000000800003b447512e9f9877255e85e92595979e93862d57bbcb706ecbd58daedd18ec3afc4a5f8b6587c9934b43172bd6f66479c57f523c47b26c0d805a54749e32ed00a458143e524043009e66eba6b350dfcfbb65f629f61a1a94b1c3da80125d6914ec43f138a07ee2d6151befb3dfa15a36cd7e4a9f09af050897de65770e4708e935010001 \\xfcf554a8fb4dfabb1b0e9b6215f95cbb8a091a6a388fd9849345a7f03783d6393dbd37743b0466cdcd5652f48f3deea8db43b51bac6858ce91e6963bb6a17907 1663499057000000 1664103857000000 1727175857000000 1821783857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-257 \\x86f6037ea728f3eba0e89367e8084f2a256487ed9ae126ffbdcad5411c174d3efbc4ac3a4f6ab3b7b7b36739cc6b4c6b8cee6f24d194277094a21ca86045b10e 1 0 \\x000000010000000000800003a5bc21722e03ff6d8e0910c6ced302e7224ecffcd1792974e3a5f239e11f9f037e008fcf3dd08402d81255c706e26cda6c41b395513f5b83c167580d786297ae1059fcbc60ac9d4886f703fe1f7b373c45d79fbda38de88cb03c7baa574fa35c1f12a8ddf40c876e9c0dc98466c58062524a96c7d9ed55738e8e6b1d4848fa63010001 \\x8a9e9d53469bfa1aa1089996c206060bd06199f4ca6bb9cb7756d79fe22e6879acfa9be730b7f582d6d890fe98ec5764beb0f6753e873be899d0e377ffa93502 1674984557000000 1675589357000000 1738661357000000 1833269357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-258 \\x90320ad18e35dd0c7858b392afb37a2b8c35674789f66c75ce3ffb3bbeb43d4a860daa068f2104e06840080705567fe4d5aacd20d88aa7aa9168541c5ce505fb 1 0 \\x000000010000000000800003b0d2cbbe4c21916be0d4f8a68200d3702a183c4a8668a9ebe99ebdd6017e2c76aca22f77bf68fd15e59632266c0edcdf9fb634a50d3e5902a9cba9b67e262a8a0cb2734e3346e8fdf08a0612328f5fed93889b380da0bb8cf14e1101b1b5b1b6003eb1ee51310a2ea9c1820f1e72050534361a92f2e2dd8b7f10f560acf3abf7010001 \\x3b8534b44d145195c7899097098bf2070d2692fb878d5228d1551e588eab0b2da819a7a65f8613c79c3fcda84d08da658e40cb420cdb35d9f8c662e49ce75a0b 1664708057000000 1665312857000000 1728384857000000 1822992857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-259 \\x91667573ffe6e23a544219086442bcec8dba1eaa2a7f3347d3985c5df9916bfcd00bf940bd7574415c09d794c15307a7bc14d441715bb9329ab927b7f1a41300 1 0 \\x000000010000000000800003c5f14ebf1da7839915fd03e820fbb563b113c6cc34c596bd7a12ca328b11fb75efb5ec79522a7c3b511818a4cb06e9df1c603824fb24584c4fa204584e126076a4b346a39595c2a4bda497c86079c7e3e33d397148c798cf68ee0244f972cd3d5dc16eaf6476c7e5fd6f8f281b2361ecd31b6a38e2800fcbf07410f7cf41668b010001 \\x30e4e37927830fd101f8f7eb387851d0a3a7eef5ce736c166966f5f789e8b4aeae39c20447c6d663d46663577c0ae4c3d20028c716448ec0ff7f034aaaf79904 1681029557000000 1681634357000000 1744706357000000 1839314357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-260 \\x91024d31fccca7351de6197e07a156cd8b485afd1a451be0b0470dd11778eed817825b59eb9e9880033ee9f06b6275203a746d7581157781bd5a61e95e8a9e90 1 0 \\x000000010000000000800003c49d265019859b77f38e71887815182fc1dfc490c3f26baf686a043a2f4cad65d95486f07d123a771796073c92b5bebbca1861e82ffd0862d622c6c5efa9d342de5eb126de9f381b1dfaa608865da31a210253dc4965d15fa999f143115ae96491bdb2032eaa47b5f3fc85dd5915c954785a1262a02d8924c27c03a578f82c27010001 \\xc20b1796b688252912e0128010c24849ff523fa94dc9fb667f13c41f22c271fe16507328a7b376099f3aece3e83c03d8b7b94ea6b4a099e8b125e0101e10ff0b 1655640557000000 1656245357000000 1719317357000000 1813925357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-261 \\x947e76d03faef44025898dc6884b913fefbf1a716db410f5da11ca7d8d1780b4ed267c0222f1ce574d6fb5ac604c1c55638c65e1e00b250c3d307196efff0e27 1 0 \\x000000010000000000800003b1884cbd960383f3a2f4ba449a4fefd0f1b9db56cf27de96362d22301a0d886950c3e402bc452430217913f4e52653b763d6f9c12c0e3972845be2465a8e43ae14177c632d6c49e6b79f5f8a985e9ceff7cd19114d13df55aa77ca046b85cb75f5cb50ec89af6350c76f286198d5eb085f6119e8722796e721979ffa8078c293010001 \\x5aa62c739431d48bc4bdf653dcbe6b3312a1bb960b5f90c97af762517ba96889f501cfa3fa550d3b2bb643d4d480ddda4d9db804395dfc8f33d18737d677fa03 1661685557000000 1662290357000000 1725362357000000 1819970357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-262 \\x944a547f847b510979f2f7fd7db5613960ab77cda6d29fc436f5f3971a360903f85d97d1565f39fb0f899269ff572f20873fcbbf198d8301c18bcc8c3ca25004 1 0 \\x000000010000000000800003b173e73be03eafb0d6e4fd7d912a7e1b1b04f645583c38a5ed8f30c882d3527ae4477f281d2c7f5dbf87c1534f90ab8068aa0f1da95703d5913c0535e9a2ac4fa5ac7896312b5bf4e0724056496fe9a0ff43265ae8d6389a0e2aa527f33378e8daadcbc9769745f9d4634e7033e4e85c8de8a0d817e391937ed7a3e35728a449010001 \\x44f5975737721264bc93ff6ef545b234b2f19ecd5c74df2553f8c886d9a9a60d55a14b8f2e2d9d3496017652d37c4b826dd75876f2d96d4f011e6da03a41f308 1682238557000000 1682843357000000 1745915357000000 1840523357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-263 \\x98126d37ecdafb005316e4296a6ea34bdef275b5f6695e44598d0741a8c9a14b197410a9cc918cb9ed0ee0e0424a4bb752925bbc2b1feb7c80449616665fa672 1 0 \\x000000010000000000800003efdd2d26829838174567a75209da23ca129fe8b1e70b191ebe9ca2887c14b03b3b64344ca5d5e52c20bf0b24b1601cf05d1fb7ab05d5fcc08a73342da9a703d743db65538aef2d5c7022aa055b77ef9bd7e4e052e40686fe9dbe5351b82f82ecc063884546a6741b3024ce21544170eb82d4f9b655466e6d12758f59be84b347010001 \\x3562af93862114df8d7514175a3db5eb38e62ef22fb0b70ac1b6907f345f320d3bf8c50911e6d44f3cd983c448edd292df105d752d1bcd4d6c145dbb348c0e06 1684656557000000 1685261357000000 1748333357000000 1842941357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-264 \\x9c3e973e9198f2587ba6a8325ee6eec28619f262be74a0fd9ca140992fe1e2ac791b5d0dc6da3ffe99c56dc2a7793b9044b1ae5512902375dc0cdc4c0f485bdf 1 0 \\x000000010000000000800003ce9a2eadf29072cd99d883bb40b5f3bdb7d5891ad4828c3f386c02240d20fa87c579db55b2a0d8e7af0363baba5b5eba5d5e8d876b43ddf4b5edd485f41b75a17bff74d8c586cbb6aa2e308bff645dbc44ad1a70b005ef41ef97be5c57cca2c41c4a7e86a4d9578c78d248a01c87f68af49e156d52a6f77ecdb14b1bece2a84d010001 \\xabbf6f56c307403923520d609021813b6bf99eb5e350edc7c4469bd1347ef460d31c5bbe2081eb0c280977aed5e411695235ba3b26f6878da410ff16b521fd0b 1673775557000000 1674380357000000 1737452357000000 1832060357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-265 \\x9dd6925f31bd2b60a2be25288c6699b774080329f209d341053f172e0ba16bc830b431273fc1db4207ec0102a10464bd595f67df890c200a14ee567f53c21111 1 0 \\x000000010000000000800003d26ecec21b6b0fc491e965c6fa54accfc1ce901e24aba84f4273d833a302dd8d3d551aed399a7b523dc9769d9685099d6c3b25bb69357c33bfb79020bac06605b98e6f7717f6540196c57ad6d73ba1ec3a91be8995962ec40d773fccc25ca9eeeab594e2010b9dc47bfd1477be50aa18e1f9811b353c0525c2d06af1a6ad75e9010001 \\x7378a72b49c5e745abb35efc3351958d272f71f05a03062ea2c58d447c14f15ad965798fcbbef31fd58295e08ada06fa95a78c712e088b82b04787f7ee2ae408 1672566557000000 1673171357000000 1736243357000000 1830851357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-266 \\xa0de0b15b29076849306325fa948c8a9faee51b286316a12b4f2003d2d0b203209d33634d5f6ba5d36fd04e981b2e639b3179675267a371bf8d9fa86b66354a4 1 0 \\x000000010000000000800003ac6d24d4fc079f90561c9b40799b2cb41bc1dadb1508b5d01523ced1f049a53d414827576507784fde6a29d22d85583d1b8d161ada08fd333fb645e359ea0cc26c0a303893e2e869167d1d8c7b4442ab4ad6bf81bcdbc8658935643233d8814e160d46d9741aafce5467f35c08343cb4d2f6407ccbaff2bf22e9e72c06bcdc93010001 \\x8ac6b502a6d2cddfd3ef640481e769425d343471465ed244f9e758c58035a14d2ccf21e09968495430e144ab8791ddc9aa313d1ce82197bb821afeb7c92b2207 1677402557000000 1678007357000000 1741079357000000 1835687357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-267 \\xa7caa5778da6e7255d375e037e0fa273f2ce613bcd1710859c5bf12320bfbc47c0f20aae5d3b20d3fddd8d3b3fca70a8276cdfea3d152fb84b973de4dfc3c153 1 0 \\x000000010000000000800003a99d4b5d59b8460e4ca6e0eb26832c0da07c7a5d6dd39d66681013e00191b6c4ee90bb541e39760cbd181492f3b48d003746ba06663e2e0497e83ab855053cc0c51b651c946cf154a40dee209c1353c839f9d7a3724a9dbf94ae8776d37ff66d93eb050df5c64190de5277231921ce6d47c1142f7d36f8341614ad3ab3ac86a1010001 \\xc7dc09c843e257ad1d5413c9088ce775a8eca163c5d137a5ca00fd2d24a2df53fc00d5bec5609822a1c342b905870f11890dc4464003353a43b435b4dfb7660f 1676798057000000 1677402857000000 1740474857000000 1835082857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-268 \\xa79a26f1c4acf351f6d67bca00cdb1665cf93b4125d70e50eb3a953585f3e79a31bf76ecc42c41e32a7b80ddffd185a5721bcce2d88e41a9c8103ddf606e4f76 1 0 \\x000000010000000000800003ac4a67549f3dc0018f9bfc7c52a687091fded577052aa2ccb64bb77a02f9c98e5fb5a482157022e38568d5525a595a390a11905933058eb1d9611b9bbd14442252e395c7012ceb2d32b33af7b05a7b22083073b09b515383b2f6fba304f23f864aa0cb721380013c845c782500cd4b6a7efd989409779c28fd1725e554646013010001 \\xbb5b00c7bb13486b72e41ba6de48a2ba04c6bbbc27d1426f51d6c4a640e3544e04b61e5b0156396c8ffbb2b8b14ca0d63694effa2e02d52641a7eeb536c29e0e 1671962057000000 1672566857000000 1735638857000000 1830246857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-269 \\xa83eb641d4b593a4629cc7821532fcd322bde133e83a4d53dac89bc76ad3988955625461f77bdfb02a36ab6760a0e19b18cbb2d44377c3fd84aabae789153278 1 0 \\x000000010000000000800003b4f10e64cd59d30f543134897641b9c9dbafc3a38df5358330488438405d2ca57f0f569c4c354344f1ee3ca266bb75bb69dbf88e39148cc3f718f84c61ecf2ededc798e3d5388b5bfadb626f068768079be0d87f655e658606444179bcc6562ad7bb4833d83fffaed20c374a1035de062e39f6ba5fdb4292645759c873c903fd010001 \\x919e57b810036da8e0c2f281049555b35d8255bac182854f8782d2a4ccfb80da1c543de13f3772b2d6642120336ad0fae615a38ed0f712e5a3d4b0cbaefd1805 1665312557000000 1665917357000000 1728989357000000 1823597357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-270 \\xaa1edef02a8c4dbd406da62d7b8e5da38ee3b88a0e04fa32d42eb4b4140ab5ff6e9065fba06092f82ac308ff9957c26e689ab792bd45bf2fdefa617c0eb00868 1 0 \\x000000010000000000800003c94595d2dda47d7a700989693ef6adf5f30b33d67eb891d24e8541949a64ff3a524a9d10ecf566e3c045a8a44836c7a5841305da0ea8fffd5eec35f4a48edc6010c1a6f6b16867e57af37f940d9f6584a2c9b9cacd1d988a0c8b7e5f49fcb75541dfd4260f1e3a0bd8b5a4ded95d580cb30204365429830f4cfae75764f6bad7010001 \\x4dd31ac2571f9921f65fe356d77c8b082265e750f0169663e1f4ac2bdbdb2f2c16ffd444b068ffcca0e3f28bab4599ae4b7666790e5cfb822c18e9870cf1970e 1681634057000000 1682238857000000 1745310857000000 1839918857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-271 \\xab22d11b8bd5f209a182d09b0dbebaf7be2e2af5c47daa466d470cf8a8f7ad302713f45a2b49fb6575d9e94f488d91736891a5ad5dfe209bbee8fa2a8d934e47 1 0 \\x000000010000000000800003cbc2145afd1c24b111c8606c4332854531708cc15bd92a31dd83e4f718f352c4af7e8848013697490a1b038f774b24bdee61e0215622343a4e2dd75d32a0091a59831b57bfae4b23d07c63e6d8802014179ae85b34c0cf2cb1ef99d06e3f42246e352827c15a09c06a4050c1f08eb6d33e0edc4c5aa75cc0f87cdc3073a37e7d010001 \\xc3c75a01a3f9e23432a5fe11b98d9b2fdec116cb62b7eafc90daa7babe9c7eb6fdb9ceb8287615bdeb7af5206c6e2266aa7cb13618d1b6ed86b058da959fa806 1682843057000000 1683447857000000 1746519857000000 1841127857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-272 \\xb5523815dcc4eccb4a09cb6d969ecfc068cd2d4d129983844de15e1531efe651b7b4abfe537a960bc209548fbe2ccf484b66a727010d36f425362fe30bf21908 1 0 \\x000000010000000000800003baf4aeaad8686a2dc8702921b6874f0c02f211a6e5c177e1d952fb8eb1f559ed6c5575db40d603bb9340c1e5770a9ee7d4d0f49315184d7df02ddd417715be73ec026ace84a19314ded946a5241638121dcb63ba61b1d81cbf6a7281eefdfa3206b15bf418dc1f8b204f874f8eb8279e2f9bebb73b0367e845b5dae4e7e0aaa9010001 \\x131758d25f1cb912db98e0920110ed64c41aad5c2b4de1941499e11ffa070f938cd5522a316f8debe4c578727f6fc5afb1bd662be91b22e3fe273ea51ae6e905 1686470057000000 1687074857000000 1750146857000000 1844754857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-273 \\xb87ab7c50fbd33e1045e1d10412dbb865f6dca3a3d30125273dfcf74cc1aae91e0f22eeafe089b72b30475c5e965a60e9e0ade5474c34ff9540c4f17a064f3c6 1 0 \\x000000010000000000800003b0265235adef17f35bea307cb5e18070b51b25960e05bc2162c986118b3eb78951150ac1731c80aa1eef83037736eaa14ecf9c4396e254a0ba47002b2a5a7460bed903adfb874dfef46c7adbdc8b56e567c3b5f5614ca83e0360757467a3f7be32d9fd93b02dc6289e4581e5a679db08f2fc695e8b50d2d1d57e3fb550f4430d010001 \\x8dd61bf35dbb3312be7198478958dcb4063bcb07d9b4faca31e6b49c94cd1d70fa10d97652889c3011a01a4f5d49ad468dea86dc66e893183d62cd2c04d11b09 1657454057000000 1658058857000000 1721130857000000 1815738857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-274 \\xbd9653e0497b9ade8036687feb8bf5e2ab50c36ae817f252986d12daa7d5d23b76b17b239c29c8eee8eb121f18a12591173ee3639b4877091137af70dd9a1941 1 0 \\x000000010000000000800003ec41f985ca399d677613e1d1ed07ef063e83fbefa5e478c2d9d079a045d467a6ba632306956f74d5e772cb6c31fad1ff0f4bbf86cf18b9195a58242379f49dc25bdf6825459f7fc0563672acd709a897128d2df3ef0bbf9d21489d2b9c4180a30ca845552d2941b4ad431de435162fd4157660b6689e837f841a39de2796f2bb010001 \\xc1fbcbc2ffd79b8efdeaed8ea668248e492f43ed26498512a0252c5201a1b2f067a53220da2ac4d2aca332fc1b364a33649ddb1165600c002ca424e33d76cb06 1662894557000000 1663499357000000 1726571357000000 1821179357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-275 \\xbf0ab5e5ca3832733ed16ed410df4ec7344914d3a9215db061de662849bcf8ebafeaf47bb040a55f75d4cf25b5e4f6b450c0ab88791b230095cccb540586dd98 1 0 \\x000000010000000000800003dd6cbbb78719ae19e64729a7f7c5f784b3fbe36c50e16be3cb2f1c419ca44da4dca8519abf0d07c6d59b88319630f0bb80dbf838156282f2fb9a7287b13aae856331889a1388bd756c5ed966f24803d897e2876152722bedaf9aee13e7dccfdc70db30096d61f741fa65a09e680c7e12b05afcf80b496b928e9e54f3532a2ce1010001 \\x88de7f1d294a44b9836024024be86edea29ee3f9318ef5c29bf8158994db66bfb3ac5af59b393a8b58fe08cf0a222647da610af1d3875eaa0295564f107fcc0f 1681029557000000 1681634357000000 1744706357000000 1839314357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-276 \\xc1bec44dd12e52bf2ac370c653e8abfd5da6875ccea7dabc9e2715bb8836b131185e1fa0dd0ec2935aeecb4b39215c20e2e45e0a1114bcb161c7373b10200422 1 0 \\x000000010000000000800003cdff500bd5d15eb3f77bdbcbc545b6965178e4b47293ce77fcb69196c60fdaef17045be6825d7c350d4e6a9a879f1cbd689e0a8a5ce37229843cdd0398be70e7e9a04d7142daee7bcdad47a288bf0f6c96f61f1a74393f596c896d9049f6caed12580845a07d222cbc63c9cbbb31c1ee8d51197bc2dc9c4565d97d20e37e65b1010001 \\x25bcbbd6c30817bf3d6359a11d1f32d063edb554169da40bd0c39a34aff79a7439b54b2e1a6045cb80a017e4b85355bbb4451d7c321af07fba7cc73cf866330d 1666521557000000 1667126357000000 1730198357000000 1824806357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-277 \\xc2d2ee2d1f287c95f633ceaef045dcaf8468c5b83c1a94a7d55de6aa67289c0021707a7428dd0323534f312e7f47289791e130b4ee036cffcbbf734ae2f0d274 1 0 \\x000000010000000000800003d68decf611750a10c25fd395e409eb38ea7b2ef139a2ca04fb2db481e87536280ef1ab5153233079f85e0b4ca072081ecc6d04a433fcd461589a4c9f7f1e063072edc973378f5ce531582d41a313db2011d3319bb1872edbccb614d4431a8fb7a630044c2552a0a53d5be6fc21068628d30283dd8b71d5128ecc5c86cd1dab4f010001 \\xc2d1bec5f96b04b457bdb35e3e24f64967d9f0cc8640028cdf38d90022622ab2b3f230116880d82b7c8960e415a8c1b58bdc0d8f9257f3ed3ac4efdbab942200 1673171057000000 1673775857000000 1736847857000000 1831455857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-278 \\xc356bc274e0ee9b57ee00df070b55439d36b55406eb9be59defd71226c081d029f841d03bc728a3d3d45b260e9c242f734d470bf6bf70bae1bfc75bc8f51a0b8 1 0 \\x000000010000000000800003cd4525dd2254b5d849def64027919089bb2bb2a8481c259217aa9674368bf904611e6f89fbc46103bb3cfb8e3cfa2df28be95037d0d7cf9d4657d1e0b2aff499f4096fca3ec5527f07139dbaa421a8bb0654bd2da4ce2a2d36f8fb91dea52190f816c7627ee6701f61d5ea348a25e9304ed139adfe8bc48655146a649fa3983b010001 \\x3810d6be93249141d46dcc7246d4b8b7a9083fa0cca6b6e868d19e15e1e2c61960a1d4918b0a6d31b4f6cd547cc191f7a9c917fe3b9544157ec3ccb011421905 1686470057000000 1687074857000000 1750146857000000 1844754857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-279 \\xc5ea14e1cfcdac4ce44596cf239e1de829e6ca9db496cb9fd2ffb33af13ff9dd4f89c75bde95d9c7e27093008a26328246aed6d581627d559c9911cf7dd3df76 1 0 \\x000000010000000000800003a9c66ca8e9eb34ff4a0ef382c6c1fd0611a501e15f84db113c25d2150513cd937d492f23f501b9bac1485206a65706473486bb2087ae1425cb3a5d96572926d53980e5e421238e7eca7338530cb8a094ffb3668b05a0b67a0f56da46a16a48377b5304dd655a70eb10e7c1951424697751da965ec1043ddbd5195f14bdce6295010001 \\x42b497e397c5960825bbf9aa08c45e9ca424dcf38b597986aa6daa3d11f772c36abf469e188bdf1733a7bb1f3b674e8e8fe4a616ed0c91bb7769c79288d21a07 1658058557000000 1658663357000000 1721735357000000 1816343357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-280 \\xc63284608f095861071811b1969596e30beb8209a46dd37122d88506976a47a6e55c66dfedf5248f062a4c6d7b8bccea9d4c39983d96c22b91ac2314120638ed 1 0 \\x000000010000000000800003d4e49177d2dc4d0e9b24177416ac2759eb5bba5746ae733704cb24b6fda666b7fb3bc23fb2bf1548eca95cb7b952cf9329aefb7b64a759e4290098d5f1cca367a9ee036c82fe2f08be1ccc588d7c34972af769a8e54f8b86ea1f147f0fced0521bb19e7180a9d65bcab84e24a0caef8c67a6093fc96d73682cbeeba8dccf6065010001 \\xc59daa7eb80fb66baf6935683eee577d6c7d4f824e1c56e48ab0f327d5bafa9d4350220551d4422d9b472ff01dc7f80d608ff3662ee1da057ed323612a253501 1682238557000000 1682843357000000 1745915357000000 1840523357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-281 \\xc86e007fd21715a191918d0d401355806167ee10d3ad55c4cc72ea0a201fefaa516820f104420f362351fabf6689ad9dea3f5ec69d93c6db5ad54d9db1979a4b 1 0 \\x000000010000000000800003d0ed0f666fbf5eaab745e82333bcb7c19c0dca1410508112fdede5583d50346ab9b6234e1b7cc57b8e08e1d0e7d81addd24bcba61d5cdd260942d3be08ccb7f64c040c10b8156487e6e3ba29c95cc64c4001a0b54307b7f7b32813b1dd92cb1e8bc702ee01216a7486b9013055dc526cc4ff2b92fe667d7b96e0f175222f8a13010001 \\xbaeb9d9a5d1333568186640f51c8faf1f02277d57543acdce8fc69e23ad04ed2cb761e751187f86894bb2c0f5afe3b06da3da0f5120bddf67e830790442c0f0e 1665312557000000 1665917357000000 1728989357000000 1823597357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-282 \\xc96e0ced4650397ab5943a2440c5c384be26df919e2c5f0c20d4158aa8956e0fc0e6680911c75047996b405bf6a7f60eabb7dd94aa8083979095352546aff4c5 1 0 \\x000000010000000000800003b192a3c821f7fa30729d62708bf08a76e11ac64d417c424fef373a9bdd7d5d94377869db33a223877b908e01576dbc9496235f043f7174a56fa087cd6e6d38e232b2cc9b68a1302b088aab19120537e403a6523e0ec4d119881428f4d3e5adcb15112b65b27dca24a5cd1bb8aaa5b61c17cbe6e88525ebc97f7927fd98a3f8bf010001 \\x4d85008910200988e74ce6ae5302f0e98aaa8aa5f95af4845ff2d83df702e9f54d0e479c593b478a6f18abaf8573e33d76475668105fe8958dd4b92f38b5d90b 1658058557000000 1658663357000000 1721735357000000 1816343357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-283 \\xca169d4ad1ed445e7ef2f62abdfe3e725fecf58a644beea3b17797e18d3fdbe4f4639d7a9e3087ba584386ea68cb769b5424231c1235b98098df2822c1eb6d2e 1 0 \\x000000010000000000800003d76f918104292ab84fd524df7ad38e2c3856226ca50a34a0c685dd6719b9e89274cb4b4ea2c9d55c07cb4d4124da65e32c9061402ea6d3f0191c2c070adb9308701e10af09d8c4daff3ae93f0e8e4943a7176928e52da27efba6ec01f0c71dfd5e52d88845406737d76031ca2af64b0d6b849333c966d33c271978c5f3a60823010001 \\x4577847bd92984d7827f3f68b496f644cb28ea421589f0025bb144fa48dc5785f58dd711bb98fc01625832f14946ac25ebefaf74d32d265eee92904d627fd908 1666521557000000 1667126357000000 1730198357000000 1824806357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-284 \\xd22eaf579659cd369716938fa8ff16ccf8b9466916eb0d0200fafba7d185f3acf1461c18a6c6999be4e1b1d58060ab0331e7cbc501d5f605d55fc2773e5671e3 1 0 \\x000000010000000000800003ae138ff77de606d58b36e8b5e3b435cdb65b8ddf6e51e981cd37465bc0768f7c5ab3e43b70e60454b64ca35a9bd847fd7f00bfa57fa135f650b73d606533c54daa3de7b4c4d157f20315cdcdb7c0f42e15bf3fe9d956dc65d057ea20c991e0951ef13d94559139af35fc781a7fa8092765ca18132cf7f3ddc75820a220c8af0f010001 \\x63fca97e9c42222776acbbc48b482688e53e1b4b4860c7b80b7cf23113b023c637b00870922f117d8e307449ec01d4695506d8410dc5786470ca8e16206b500d 1674984557000000 1675589357000000 1738661357000000 1833269357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-285 \\xd3d6d31df266c8a88c29fed7e7642fb2cd383bbdae410a6e485d6856e14a5c38500ed47206c953168cf051015cc8500a846b9a38ed03a767534b313545dfac0b 1 0 \\x000000010000000000800003b6dce483ceb2a063acee978c3a1ba86bc571690a9a5a8f29e27037f81ee797a6f43b7f2c7068bdb5ca6d788d0ecf8d94608498ad87f707d019503027737b0febfeb557627ef5dfa08afe6157f17373c1f32df0f517eaa89c8cf8606422dab8d0ecc2da7c493a072cc5fd0c473d0369db85d733d7464a92142f2f82304b806d95010001 \\x281d749f5e6bd7fec1b6c3b5d02e3e4bd50161695482111692d3117f5a76838dc00cf1457a1e61aa35ee14d97454d776487522789ea04eb32d2613ca56adc50b 1678611557000000 1679216357000000 1742288357000000 1836896357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-286 \\xd872be98960761ab5fef39a9dde2042c56fd516d202118d66a7c90e2a1da15c1209833a15b26f938b389ba1b298a23c9c83ee19c66f1c396bc4fea29f4c0ce7d 1 0 \\x000000010000000000800003aecfbf32a87bfb8b33656d3dddbb997742e539edd63853a6480d3e9058c8ad56a628ee8a10821af58dc0d77c2b2fb2b9e25c0520aebbf2980bae8fe7791f95acd9db5e7df35305707cb516b259b9999de276cd620e1c64d528ea38f9a910e061376e6d30730fe4798d3a76997dda29659aa39817efae97520cb6d67d1f7ac55f010001 \\x7992716bda2a87f0fe6b2eeea46c3b36f66cfd2bd8225eecdc559483ac8dfcd68762c1d8bb2f970c20c81e22cb8d9b8206f1c678fddb3a07ca3b6bece436fb02 1658663057000000 1659267857000000 1722339857000000 1816947857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-287 \\xd94a30df40485450386ec127b60635c8db7a6dbabb3ffc50d069972d5cf5c24bcef9d2bb8c4e4a4ab1d98e8700dd53f32c07ff4b5750154d2dbdbd9267455ab9 1 0 \\x000000010000000000800003a9a8411878770a4deecf9f5511b692423bc37512fcc24901dcee35707a73831168b4f7199cc47c3f8b1c3e22625124572d9b06040cd13cff0f406a3274108a951af2e4b14f3cb7d103b68fe905028b4a509efce77405247b7d58925f2af214d3f4e4de6ea1c06dcb2891266f3515d7f83c202bb86ad45371dd4df95d4e3c13ef010001 \\x4ecbb8624749621b136823fb9093cd5028cced9b013a5514f39d243b53e19368eb8befab0f88880789fe1a8bd31e3f3af95ac2d749d6eb7939d602c7b34f8401 1677402557000000 1678007357000000 1741079357000000 1835687357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-288 \\xdabaf6c22078f31fe5d9f5a40db7249fdd9e2d5759c58babf18c8fad29c165108a4852502bdf468343167a9e8c040534ee8e748f0e8a02b2d57d31f51e83b0d9 1 0 \\x000000010000000000800003da5519683bd5240ed5b92214b97747f7c939cbd00aa1bd67bbfd6bad4484353ec9b5d1a61a31b85ebde951b219a04149f304bf55c2e3551a56632bb026d6ef87bd142d9b4777577b23a343fb1d0f4b04650688b37c8c1e88c2a78c23b87ce20f530bffe089b0300721b96f1b25e348bfd09c32c8542d3a2f7d827f18861333e1010001 \\xd716bfea8149a9d8f3ba3c1ec49cfc411f7d10bc1cb836c667de949d0c495ad57c2f6cd52fe000b71c5f5e32d1f8918df034a02d4b232f67b36ab93db37ff50f 1676798057000000 1677402857000000 1740474857000000 1835082857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-289 \\xdc96162e0585bd188a460ba12aede192609cdedce341a75ade07a9dba57fab223b634e9db1d0cb4d8b41fa437d3d7d2ecbc507aadd434fd933a43d5f82e3352b 1 0 \\x000000010000000000800003c68dce3149c49e1734f8976ede6f1541605130b5e0dceb4d10ef5ddfd523f793619d37807468749362d860ff042241efe9860dab29f667b7bd48b571fcee0a2a289500e237f36a7cb806da550d6a96e4faf0ce7623d3d7fc67fac2ecc7dc7bfcbe31e245f5b5d8764c85b964648b660458f16fbd5e83d8051699eabcad71b73f010001 \\x4878c2f6ff043624424b6d56f5cd7e95e3fea0290c16960b3c1210d08a8e0509114f6cfd885aa8a72f4c436309a25048753b4c6e58cb362d5ae0f59cd5dac80e 1685261057000000 1685865857000000 1748937857000000 1843545857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-290 \\xdc6a96c4ce08f314e8f1a43bb161d748ed8e49e87f208aa0515ec349a998d959ad2ec56dd987facb91de404b26a77a08af12920292b6c5459a6f2613cb7712d2 1 0 \\x000000010000000000800003a4d6fba444b364357ed85737a21062ca65e8d3376a2c0c64485b5e8262baf6e37a23f01b1aa6ff6d1981f7c4a15e9e241596406c0dce4c41103c500a93c18f4012b9b43f6e010824b9a6bdbef4460a3e22b622f06701ec562a683994d922dae639b865a1bcdd0e039ab91dd292b7336ae3c10324f211291eadeb59e069229a67010001 \\x9e09d4be7e36a39ffed2a3b26ad8c93c5c928168c4db427f04e64884c417018f0c966ef425fa61d5377b35db2e62f448044360dba6361abf23015dcdbefea30e 1660476557000000 1661081357000000 1724153357000000 1818761357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-291 \\xdda6af0f691e8d8f3aa9a3c611d4d9d8ddc902e6bab987e616e841a0abaf0068f89af21b0836c7d2fb2aa06ebb85843f7b11df439263b5843138f029a8a0e5d8 1 0 \\x000000010000000000800003de67d7e5a1321c5166aeebfda749e1370019e41062b2174c7fadca4649bb16da7f5d987b9566f43a19d0861a77eef80e23843cacece0fc627b2320eb4f43fda2957047a526652914e2945b15428e0e118dd149e6bda935057d27c783a99cac4bf2579041d13e73f944ceb769e693e1e9b00331d7f722072b7e2f13f5582fb52d010001 \\x0b157f024ccfe21c940fc770e04bc014ca08981082ce0c213a5b737889111b0adc86edc4a55d3818ba299fb2b3e800d594f201877a4d7d052d30c7beabd8790c 1669544057000000 1670148857000000 1733220857000000 1827828857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-292 \\xdef6738f05715bc11b8b88923dbccd73fc98e8dc396aa0730a8ee342612df42808e7e2449569c3d20c541831a3a23146051a4d2cea3bfa45d45cafc2ef96d5eb 1 0 \\x000000010000000000800003d5f81e9872eee366a2a64baf7162937e7d9fa0c52191f729a9aeae83c0396d088430a2d33f8c09f44775d6f2851e8a4c960739e37d5e7996a0e05bda083ce2e4637a9a71c76b5c148d5c79c162f67686dbbeaa72d3b5b346798bccec505be7abf16dac035f04ce99aaebacb758fdfb3767849913acca2f24beef479c84625a27010001 \\xe293638e50fa9fc66ffc7e44ccadf9f10b8bf47277eb1d43cd60efb679e0237b03ada011120b008219983b531ba9d9be99ff20a29e6dbe1a37886032e26e8205 1667730557000000 1668335357000000 1731407357000000 1826015357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-293 \\xe0421bbc753ce731e257f01cbf5e51d7b4ec0420999b0b28ae7e79a76fbebe3013b464a4bb14852e2c477fb0d851da10edec6206b07b388b8f1f86bfdc2b8b77 1 0 \\x000000010000000000800003c9d11c837805b62ff98a618dee02df52e74693c28154e5e401a4fa814805f84b285603e9fa2fa1504222ce135583facd0cd695f18cbda335c96406d2fc37864df6cad5266547a79ec1d5225009f1199f0433b9e78d495cbf8d13ba1b6ef9979d0a49fea89828af6c48e2e760bdc9ec3c970ed34d9bb966ac1263a241ff2346ad010001 \\x4af219d52b37728186c04225f83df3566ffa04bbe4ce04b961370d4b2cec4db7457ffbe068622aee2e511b77a95f3fcdb2178631e05197bb223131a47581a707 1656245057000000 1656849857000000 1719921857000000 1814529857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-294 \\xe276fb3f624ba9f72860fa4f959eb019994395af1dfa1333cac008df299db9ea97da29fda59b88706172cdaae84c5dfe84eb238d8cbf9e58e9e16994f1b6577f 1 0 \\x000000010000000000800003aaae566222940d6397c0d90dc26a88e6f9867eecc020e65590b7b4889479116b7a3aa12abae9ba14a71a417d29ad7deaa2308e1b5d88a20de284b721aa4ace0e82179238be9c62a2470add7535e2a96657f549eb2decb0932220ebe11e6b13c4613005acea49bba69f95249b01ca9bbc982d8d923121322630325e788b6dbb99010001 \\xcba50474fbfb43aa15e1389a77239239df427a4480e0dc4368bbb572deebc382cd6d19e7eb3ad0d7da67dcfc8f983270b36458b748d67942591f9296ef85160d 1661081057000000 1661685857000000 1724757857000000 1819365857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-295 \\xe30a3fd504a5273e11fb5b2420318c36782b8f75890fda2e650507f16c8e7ec12833865fcad6ce42812b1646f24f2f571872a4e989a193a3e792b9d0b6c7334e 1 0 \\x000000010000000000800003b3b16c6e8fb240173a5a639cc1fdfc9212e418854b52880d0962619ae012c2b9f4be7258a30cc2b792595cfc1c0abc92f2dfbdfffae8492cf31a74486e674211a815fe121b77305f3166c1736d1ef4cc399dae2c75ad8f2e9513106ae0f1eb6ad8622a1d86fa3f3dd51e6795b09bdee6548985e10c2e9d7091f964e7cfaf0f71010001 \\x91a7c4b3cf84a37fabfdeca48f89fd55b2ca612743d201b844e461cad9527393ec07f883bca17760b703e7ebba84e13d45a32afb4ca0320a048d3a4667e19007 1670753057000000 1671357857000000 1734429857000000 1829037857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-296 \\xe382097774910f60ea9a35f7881296fd244e0d10f600bf485b6641bf0ad3e4e15345de953ea34f7ba618926856e4c936c5bb62201fd0365f074ee08ac4a8a44b 1 0 \\x000000010000000000800003e11d448e5c7d9d1eaebf718c4165bb8c761bab925a4dcb044b8d4de70401e085e077cea784c37b24516d3501f542beff555f475988955ff26139d105ea8970395f8547350b25c9a86e8475987234031cc9512a51229185878c17b59e28d08e48f2b18a64d12b2093cc7b70ef27e415394ce8d06c73879f8ddcef6cc38cb1cbb5010001 \\xb7cc57a752655b7827180c9dc09dae28eb53cb66dd909a8de53d1fa76033d6816929e7dd4059a6bb6053c1110258ec12467cc11bc7d89286b9993a625dcb8104 1670148557000000 1670753357000000 1733825357000000 1828433357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-297 \\xe3ae42b4b81bc4f1a73ed668a08c9bd02c7395f99607bd36404e47a4540bf09acd10faf582133004c91ccbd31816577a4c98da08b60197aeb6ac303a2fadc430 1 0 \\x000000010000000000800003ad958ddcdb7b9eca778dbb0506c164f1cabe3af298eb8ede5fcc85485771c6a698d55913a1bb213e97958a34b930b15b7576893a8aea4e5b917968a49c0ff3a70183aa3f1eab9afb886df82f60b322e99cb795af64c2d8115b5e2d9a758a29fa2d2baea86c05c0768e189a61b6d3a0c09e0bade8e4bb895c80b7481671055bf3010001 \\x936e1f02e724a2982dd96dfa968bd4dd99d85988752104679783ca1b709da06a9d353dca9b7d9c98e974d0a4fd1b64400e83952c151629c893a82f33ca3eb300 1659267557000000 1659872357000000 1722944357000000 1817552357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-298 \\xe7be3c438c3b85b85984cfa9d7fdda04bb5cfaeedaabcf0e67fde514f2b50df91d0ebd005ecc748dbce07786602a74d2451d2516c145b37834c177779d493b43 1 0 \\x000000010000000000800003fb55a4310fbc4ebcad66ae8000b649710c3d1cf0b22602e7843d6e945b634c6b4d97d6f53f3dfdae18a15e93308d46e715294cc2c512c486ade8cc191aa2c1445a59c271993939e5aad6cb102eab2118a2be638b1b3d5e84369430bb0e4dd81868d83fbf3a76020ca2edec6cdd2a3963db6b694066baf3ce991cdd41d497bf9b010001 \\xde8e086bd4288be371b06ce08a37003f5cdf19d17d0a941cefee8a684dff9ea324c58f50f9a78196ed6377fb4fbc4052c3a1ca515b95bf2bc8304e130355660e 1681634057000000 1682238857000000 1745310857000000 1839918857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-299 \\xeb1eb2126e951169d47d1b2d882668ce66c3f18ee2269b23850b76d7241fe9b283faab26280c4b45d6f65626334627133a8e319f5e97225d1109327735642c69 1 0 \\x000000010000000000800003c96cb5e0c0354a504189e65e065bf1eb1dec7f902bf35de45ebd7ac1cf395fc13f0746752507510549d27e8ab36fe0baae92b229aa8d7d77cca5ac940c6cf14370937a302c93c540a8fff7bef56ddb9e7462efbda8fa89922dd79fd7bd972fccbfcd96a41b84ece81299f686b284e1467583eb974f535a6957f46c46f022c075010001 \\x37929fbcb0e0557ad26ac1191ce0a15edfbba59fc7ab31330e389fba98794fdd9bbac81bace1fe3d8c81aac1e60c52eac87e77bf4e272d05f4e0a10e6b0ad101 1676193557000000 1676798357000000 1739870357000000 1834478357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-300 \\xecea617c599df6b8a3a5dd7625c3d202f6bb9493c8c9142df5ee68f648c7449c0b3eb3b759b2cdbe24b9df9ea4ecf4d7f449db5cd391d465111079f5fa6d0f9f 1 0 \\x000000010000000000800003b4fe8cc4dddcee1a8d497c105d80e3ef7ff487852f3ece35540949ae982456c7490aa861b9cb1537032c1417f1b28b043b789d066d071e9f06e72dd7ac4e0bc08b153fce9910a26bc6ff1af37a9fce1591a95c4fa609b166224136fb0a29ec1716db100199b24eef10e54c5661ead0d571da3e5b29871b3f03c01edc52bc8d85010001 \\xee5d72ad2e269d4d723d02cec78c272a4944123686c48a57587f9d9011fe8bd2605cf168ce98f36f78ac166c769eca155df4c8a1bc58e1cee3bfee66ef643f03 1657454057000000 1658058857000000 1721130857000000 1815738857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-301 \\xeeae2930f1bb562aabf9f1a267249f9067109495432462e622619919e372e99ac737b2322ec61cd54208f8ac7c343f85fa0d487429bf4d6d963bbc7480a73cbf 1 0 \\x000000010000000000800003c2a4ca562559e90e1a635f7c6d8eeee9aeba17a71c3b419fc055815a293f0fc015a32833cdecead670618e6b8749bf252e02d0853986db482bd8656b4cbffd6618f98b3cc8f6cbe9ad5e794b6c683583402340a74b0a5769c1892283ee85d26cdc6045a1f9899d7803880a838488f8ea9d55705bcfb802a67dd0c9a8c6483947010001 \\xc9ee7c3948a234777e3e6e69e23d8e90e08e282581b03557d5aed6642db8fc58fd6b91878fea9e0ba050aadbe1badf8f7cebacb5bcddc892054160699bece20a 1660476557000000 1661081357000000 1724153357000000 1818761357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-302 \\xef3ecb954fe52537789544340a95a4791615a28d35f110d5843702787793cd90f219ee185082ef7ccaedbc5a6018ea34b0eecf06729febe871436b097f600f6e 1 0 \\x000000010000000000800003af2fa410a6bb34ccbe8bc6df3a0b20b498310abb1e39c7a549ab1b5568c0906f9dff75a648808419b7d64030559749bd1a97d04fe239c20535461116fe1142458905a4daa1ce90228cf6f978d1e96b251208706ee39c8bd0ed748b5ff4050ea170d79b52722f3f4b0da9a82074c89d27a5e00d56a40dbd2a2a460fa5b6259f71010001 \\x4edc5465012cb642dc2efe0bcb9c343e71ec6369a10c6df4e2a6e4fe76bf1caea852d94bb9f23fc70c39f124f2bca79bcafe8644e26362152fa5d877fd205108 1663499057000000 1664103857000000 1727175857000000 1821783857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-303 \\xf5a66e8e150ad97e8f142f40ea25ec6575c1f52702a13d162de277591b2d770943a819d134dc357f8dcca388b90f399a1809dc22fb48ef6570e2c64357f9faf9 1 0 \\x000000010000000000800003acb65d2014a0ca54ba18821084b3d387c58b489ba498be886a2f320a5a9270a9921d08fab14943413e5bb3ed77048fdb92546d2849b77e159f512f418dc32248a415d293c664741f93db3f24ee4b46cfb0666fb1b4953c1b85af8712d41a6def04489321bd7f8c7f4a33573e45dd6bb2129da1865c2f18ba13f759ca92d4add5010001 \\xfa979cb1db55f3e66033cb14d683d2051464457afc49cb44fd04f560026d13e955ed6508957243e4836ac602297b2eefecc6809bf9717e9daf196d49f648780d 1661685557000000 1662290357000000 1725362357000000 1819970357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-304 \\xf69e0d2f3cf88fa4952ea75ab8431cd1418dfc33ebdeec3f170a526953298fe8281cfd015c990868056d6e6a245437a548ee61a7a888f7b3fb5da0529a6d2d36 1 0 \\x000000010000000000800003a4bc210882ffb4e8f8239cf71966b4fc906fab80200d50b8daa5aae1fafd20e65ad1d420f5ef6bb4f41919485c47339892bc0e47cf60afdcb19bd3f61e58968dcd5d0e25f84fded242f0edc05a726f7a844f84b8304b5f82abb3a534a13c2283a7ce0653ea74bb90264e670f597329d7173a1176ea9c5a93b3357c786b8cb82d010001 \\xf55df2adc0976393284454004f7315c1a0f9257e6fbe224653a74af3c3ac1873486f40d10397561e229b4d0e2f4149177eea40d71814c52e1b0be04f09e3f30c 1671357557000000 1671962357000000 1735034357000000 1829642357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-305 \\xf6a68d982960b98033206d3523f94641b51409a102567d2ec6a83e9c858010689bbbfd4e572049da52ce6c0ff970893ec750f032a2275de704c49b50b7fe7017 1 0 \\x000000010000000000800003d76c688170ec40e23b768d28f1e462f296610be3df425a51edaefbb12b7be8e3a18f5527a3a202ce1c2064f987e25f4aee0205f37ba47fb75bb49295c71f7c67a32c1a3d9fb47c5e8248771f401f14b6d03a1d0cc6d7603a98ab9c892b38a7447fc86fde463b1807fa6eb66c0d7758b364bff44345520d8c8dcce65b94d07ff1010001 \\x4814c7c63ae2f55813afa9ba7ffdb8a8fc32102f9d48b7f228e0a39e469882fb26ae7c87482980cb31d39439046d1007be4b31979b811eba4f316b4d9ae48900 1668939557000000 1669544357000000 1732616357000000 1827224357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-306 \\xf70eb4f416d0900d4eafedc0027c4830275017c1f826bcf706515a29acdc46bea7df9af78dc47cb0ef5ced4bbd44312ff02b0eeaac386f31c34401b4ef2c4a38 1 0 \\x000000010000000000800003c2c3afb1e8f6321ac13fa13734e8117515e54b17202dee6a6d87558a1eba1d909eacb37e0fcb275ba3eef6d99f9546350bafe2418faf433462b7ddf2d7d2f964ebe7442b26d338dcccf758ef553dfb4531ce3c33d6ded3f412f01b36a4de201206fc40c4dc27c97cea542b198782a83d9b7caf852c1f3ecc9e07eba3b6b42f9d010001 \\x21237820f3915bd4d63206485548448c2ba0682207e6dc4279fb303031a844135e4b2551edb039032a296caf6de95b819ac43c273e2f6720553537e335fad001 1668335057000000 1668939857000000 1732011857000000 1826619857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-307 \\xf7ceea56c21d1d53a3bb4d5e67ecce070aee7975556e3c281bae50240df0e6711383ce9c0aab4bee0a87114984f43d7ddc572c422b921fb1cbc9fa4348a189ea 1 0 \\x000000010000000000800003a4b0fe6b6fb877990a3e386e213816b5cd17e7d1b067035ba869060a0ba0ccd3850785c2eb29ba472b9c13e7128083695f875aa55dca72a0f716bca10ed295710f5298e4c433d9dea9f7384c309800cfb8f199c531fa88b35ac28386d67130c692b85fcc3a387a33bd207986e9c7f11ed49e9d2c100b39bf95bd0fa5ea0717b1010001 \\xb9e6ad55bd8076d5d6e2f66f15c5121ff95d6809b154e524a4bfef993858abe91880a928bc391b76e3058738875bcdcec9270ae2161bb876caabd796d11ba002 1664103557000000 1664708357000000 1727780357000000 1822388357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-308 \\xf88aed25b48726361ccd0a32c6d645690215dd1ddc36c800a3d6569c713fb70ada934ae724310507967c03c73b143fe7de4ff3d8fff251d2bd33da63665f3b2c 1 0 \\x000000010000000000800003c2d5b0e52b2a92b15fa91879c6803e7de7410aca83b4a2ffddea843388262783b750763d87da43f0ba2f2d88f75b70c52f21a3227e28ef40a3ab2e7488c5ee3e34bb8c878d31ea744abe40f0d829a4c657844bd9ea6cb673472990097c896fbb308fb1bdb65d964bea16f9c2c18a2ca9d29291efe2f9d5bcaeb406f5bbbfa47d010001 \\x25c29e75520f67df96fee6fcc05b39bd1d20704e800fd3df532aa63ebd5d17c6ac02c530132fa80cd863698241eb0639c4239844e1ac1974627ccf19935b6107 1673171057000000 1673775857000000 1736847857000000 1831455857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-309 \\xf8866b3894106d1c30a62e19fdc752341b59f2372134a1595ae55154b84419b07116f58ef58da7d07bd20134811f7478bf677e03029096304eeaa29dcd59459a 1 0 \\x000000010000000000800003b394da6ea17ea54d82580a488fcfb4000db1a41e4d3c32b5386d762701d461b08bcc15dc408b3cace62dfa3cfc3382f46f41339c0a18884159d982f4381924da04cb06a86cbb6de50b30d7001b2fafed46ad435a5bfec4a98a7f840d3b94a78fc8d48ea107e223322b3df7cb84f9029b14928ca7273b9a5a4b48399d16624179010001 \\x428357a63b0f4667a5c0248aae140c387875fa64694ab8628589b3d383c9f8932e899ef8b3c7819a8daf39d7f3721dd1dea9e33aa4c134df8c6d9dd321c62501 1675589057000000 1676193857000000 1739265857000000 1833873857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-310 \\xf9ea3a651f320239a4c35ea5beb63e1ef01bd6349eda679a4f77c8063072628bdd1ce1cd874f2c2825b4a4d6c3c3ea1535fb6de307cf3c9cc16a31bc4e2fb449 1 0 \\x000000010000000000800003c9be260a51bc61dd1d7dd24d279401f76bc1542da8f6f2649f7a8ad333fddb03a067a197d921491389251f5eb66eddd8a4c6fb596b5bbc2ec746c2d1e7e6e84cd8f2af6d66fcae7063ff98f4c0a3b7070c2236221ce308a05dc5cc3b41204da32287524087531d4cde7b9979ca65154c42d0061eb8fb951c61d37c5db989124d010001 \\x25647287394cdca32a27b1bb774462c6219485c205716f9e3b786722905a9f9e89e903edc50b8b558996ebe5ade2d8addc2268df5c1614f2e92923a1224ad104 1670753057000000 1671357857000000 1734429857000000 1829037857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-311 \\xf9c6626c3e09364af7d85c2bca3b930f0940606b20a528e4352930188919ef7b1a18ea1b696125e1a3909f657eed785559cb740e4d70fd782166477094194195 1 0 \\x000000010000000000800003d210a0939052fd9b7a441621c495b7b998ad996dee86c9d8d6385599564f4668c459a2cf3827f9320908bc9468ad1f7782bd84cf752d3348d43926a3d1e328fee7f0cc4de533064cd75585bae92ae37200ac97d112f57e22df8b9e863a804b2e156a41fad3d3b01a43910910ced53a4a538992fcd9fbbf2b2572cfd9d210f647010001 \\xa6a0dfb7cf4ba7d501c1a28f8b7c798df2a11810f3e1c813c3e210b917dd8ecbf0903638766a85673b841b475f385f124d3e803f142c0a33277ce60d750d9a0b 1681029557000000 1681634357000000 1744706357000000 1839314357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-312 \\xfdae7092ca00504df40cc8a182539f7d89ed40c6599ec2266edd941af6dec4d0eb15e74f585ea5da69a2efedde4b4777d758a8ed9fa448b7abd598015d9d6a27 1 0 \\x000000010000000000800003d12fd17116ddcf6b236056c5a03f8c5e84a22f125c6ddb7c7a1587e576d4080b186581af36778f48e3ecb5e2fe170681065687cfbdffdd265b9e431859f782e73a7c3f5d54a265f2a50a15f8a9f77eec91a7a045dfb255cc1e7c6cb6bb2806d0db1b9d5a5a2956aaae47b3e88b222df7ac47a3911a96bcc127840e1a8195a22d010001 \\x3f5a39dc31ad4f9d585c307b6b18abfbde1b9039952ede3799b938a3cb2833372a07aabf122cc0944b4e9e81ea7b96eba9f4ab764f352ea3fdb1ea464d16ad0e 1674380057000000 1674984857000000 1738056857000000 1832664857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-313 \\xfda646d02b37fa33d98eb6128295504c0afa5289f1a1e79534d916ddb26c17d8c93b5299a666f391f5561994ee4663d520b5a35150d500e81be6442fdd059544 1 0 \\x000000010000000000800003da8a43289bc3dffe1647b86565a9bdc53fb826d7d47507abce8faabc8e4f69c0f9b973c401558b1f0b0e5e379008c40347bb33ef01664ff92c15104b1800428744b9375c2695f6116c918334e084709048b937afaec6e4f2c152233112bbc50720a01acc20054584591baea35ea771b5a41856a38b263f78a7b8d9bc9987cfe9010001 \\x3177e384949004c6d402bacfd8f038168d429207d310f6bc6eca88eb9fb40fb64e68d7628ccc4dd02a8821df4e46aed27d412f29f48d9e0a93b896cb0a57a505 1671962057000000 1672566857000000 1735638857000000 1830246857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-314 \\xfd86436b5183f78e3dce83266e678b5fa46bda06b3a4a84686780d66f91a87bbd72489d2c428af3d5bb236c1db11a5bf77881d82462e6e5718a35a56fc0cf2ce 1 0 \\x000000010000000000800003b22e1e8629a50dc10d6f28f8c3e1223cd3f1827799d06e95103a3849950d3d620a342f4a295caf16b1b39a1f036e6b4c37204f068df6cf0cd63e8b6e7f4979f86286f7359f93611b340a3987feeb5ebee4ff455b468614efb8f1aa630a6279554bc3bceb128f28e28a392a8cf00bd95b814d12a80a4412f7bcb424c13b4619ff010001 \\xf1d4a7b5510c09bc172127f082bbcb5824a26c9e9f17889a0bd832491cfc616c5c426c339749e4280d9dfc5ce6a05520b966eec0ab1d8ac06b3c01cad2c23f03 1669544057000000 1670148857000000 1733220857000000 1827828857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-315 \\xfeb2f5ceedc0e173849302155556552958ed8f190b62cafe8713578083ddd1b27373b7a1f47be742af5c02f924ded61e09bd217cdf10b4c9ce7b12f7143a9026 1 0 \\x000000010000000000800003c53e2857c5234eb2ecfdd46cac3c645956ad018ca90e2b9bcca25009133f07ade3ba935ee2eba64e95ed0922bd0eb36e9fe2d5a3a4e5a7d75ab761ebea9712ea1e913aa10fb797dc403e0d97ac97ae32855e20cb74962b8141132c75161c7aad960fb03d2838a497d3acc3f1444b4bbd9e8e3ebf1347391fa626f4168f6c7a65010001 \\x2c4092ec9470f9161b9eae6ffda316335b7e1537a0d529fe279db1f768a461033cd55fd5776a0282f3d3d11bf54df9d86c125528eeb059fc31060e46985f0504 1678611557000000 1679216357000000 1742288357000000 1836896357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-316 \\x000b76229e6a25007817649d1bf1b220d2f7ea6a9430ea959aa1c1c51973f8f388614b6d20287184f57e5947f67d780f8d6bb7f24ffc143311061b3d7174b23a 1 0 \\x000000010000000000800003d762acbfc670aa892ada7b1511ae5cbb5972276eede75c1798d03501d50db01d64659f5589b438666f89c81609622e5d623cf1e61f0c93084ca360aa48ef1a4460ae785e6c6ee29c2e63ef81a3d69b8e75f4d1400dee2e632d8de391a9c7dc9479d244f6ae3cac78dd82bc39fb4615fb470ab724cb9c34237a648bb34decd183010001 \\x1ef75c9202a21dc9a7c6bece413eac18d162f5de9939be442659329e18ef784cb189a05e9a017320333645f928b2837f1921d549a8cd776d302b63f260492907 1677402557000000 1678007357000000 1741079357000000 1835687357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-317 \\x00e7f96fddcfed206ccef994e38f5dc24ef59de60ff0ceee712e758b1786bebc7c60da73ea3096884d66a3a84cd90188026e46b4e9f1339832d4264ed4259cd8 1 0 \\x000000010000000000800003da4e1c16ee721b88cb9f471a22527642987e7f8b97332e1d356c654fa6d2fa3316155a26d40fed3721d60765f8a9cb0511e230c0ada8a304f7a0b4e8bc258ade2e5e2131d13a793a7067a1a30f5770ba5012f31182dc60f8367cb911855e68d1d1a867756ba261e4317eed05b66a0c429dbb84d8b653ecab8f235559d008f577010001 \\x3623d48328f295d8920b1b1c9398489e1b851353a2dfc3371e9f8f877abe6f76213b243f12ef775995019183d26e653eccb720638bf0ff5fe18807de1f14f203 1685865557000000 1686470357000000 1749542357000000 1844150357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-318 \\x01bbcff8ca374cf069cc26d034daf989ab715cab2bc05ae8dd75260866a2581a957c163406c9f66739f8fc72b5c93315dac622d01a5239b6b0bf9d8d06cb432c 1 0 \\x000000010000000000800003beebd794c049a1c583546ecd25dd392fd73864b83b30fb9443faef34f58f11d97bdb9129c7d1366a0a453c5223a4f1ce0145814cf567d0779e53697a12ba3437cd9b1a5660af9d36c32c32466c8d64af23277dac0ffa4ed1a8c79fc4322e07da6b861b8603dd6296db61758f6a899d374ad906fe8e9aa40a56c8f1b6fa1e8345010001 \\xeb21d43141d8c470c1c8c6265817081125e9c8d4f461f4b026a5de65b3ad9475cd74d26cc8c7a4af8280c02904495c941796c1a21899ea6d50a99eae80fca00b 1673775557000000 1674380357000000 1737452357000000 1832060357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-319 \\x086ff9d1a872ec79a822aa77c50be6d143ad5315cbd79bb9a7dd4ee3b14b435b4667a1a8a0a5f62d9ea95edd33ffc8b933a4e08b8aba8cb693ea1aa7e057f527 1 0 \\x000000010000000000800003f9c7510d1964555be15d2b2700b3875ebc271ab1210bb709c16d7cdd046610de584b472ab54e36276066896fa30a2e691bcff77fd62deaeddd375753679c6c2cca5c17bf17ee7669fdae58bac4f503d174067bca486d9696cc146c2e8cf81c317dcf2daec91571ddf637b56e821039d7ad88a5097e7704892760af3af606ec7b010001 \\x11d6537829b79c4ff76c5df3bc115bb05efb5527ae00ca4c2813d3fdcbd8dea7e091b8a72e0b4f1b668fa7383b4f976c866b3082307d68bb8e4ab8a15381050a 1661081057000000 1661685857000000 1724757857000000 1819365857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-320 \\x0b07b1e397a338ed4e0a3ceabb2e57fbcda86f0230e0ed0d00aff11178985627fa16e7bfb4e0dade41a1d57834617f25f8a9547b9a401010c5b62ecec5059491 1 0 \\x000000010000000000800003bf58918a2ab153f4af7835e7ba9473e198dd34b12c1dab48073727c8f4a416c74a12d6d0ade6e8f7b628688c7e867022d0f07f85d3e719ec0234e506c66b96a4d3e95753dbf17f622ec1f36f03bfc247ac1cfd0b963f10fb9645036e233d611b81270c05499a7a4f7a8e3330eddf40701d167e1e91d4ce276d6dd79f72af43d9010001 \\x7fe9d4ab59f4699d40e988a536d4b1df29068f39986900d68848d0e1266e6a5d0c29a42188ffb384c93f122ae7de61631b08109f2032b450a105d86c19963a05 1658663057000000 1659267857000000 1722339857000000 1816947857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-321 \\x0ba3159a6da0febddc9eb6b9dd3dcc727ebbe55193766edaba55e50b0e56dcbaf00ad26776ec32076fe98e7b2da6b38201f30272c2e3d2209a25ffe41f2a6826 1 0 \\x000000010000000000800003b3e2674c569942cb46c0c6e28cd4791712c82162ac56a71259040c71b93e6630cc91e2b147d8990e2c7f5d8dae484f69c9f220540f74836e76f4b75ea4c6d17f696882dd55d89ed7977c96f1e520e7bc9f246bc9fcc51f262e98791aed7f61ad2161664862ac44259a5f0d4313dc21232a046c44f7d8acef68099cbe960b0f9d010001 \\x1f91f76edf5f9dd27d7a365ab020989cafb8143baf13676ba51a29290f677857928bbebbeccd3122a45a280f70a7fd91f49492c482d0ddc7c3b80851338ffc0a 1664708057000000 1665312857000000 1728384857000000 1822992857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-322 \\x0e0b917746af8f495db10e0b6bd9dab87a2f5d0942f1aebd2bf034f3fcfd887b02bc733e480460c45596b48f3806e6fa9ff2a81a529eee9824864f9724c39814 1 0 \\x0000000100000000008000039c8a3a3ea98ec06cb6ad0c3e281a6a4ce6f718bdeef62321cde6642c16b4185a26748abddf217bfb10165dc9d2c81a992752ca70485f0ca953ba927a63fd4d9f37e4fc75d5c79469df0c49e1b8a1150dce91bfb3c44ab308a23dcecc1eabc8e0dfcdc425c914e791643a7c09dccc4b08afae64b3551cea775647b5b589daf62d010001 \\x41f95c1ad915f6e3fc45e5b1ac3784f5a2181a310aa042cfd87862d36c4df74457c740e944e2a698e381a15cbde2b25d18284a1c297c9a2db935a3b24bc37c06 1665917057000000 1666521857000000 1729593857000000 1824201857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-323 \\x101b458a6a464d6c2dc0b272ebd7b16e5fd5efc02aeb2bbab19ead3ed26b86d4e16c1158c49e2a7cc57be5d335ce34ad4f91d92fb3be0d181fb45039605e28a4 1 0 \\x000000010000000000800003a7e579221f62cea478cd7d39c04edfe900a2f4527d784db010ff9c6a9ad78dfedf956d5fce8c9dc2d5b3ce15e5a819b06f0e9dab1db00840135aa3a18ea9fc55f9356ef64f6c26cbb1ca641f2464d1e87ef7c3e221abb201ed8d9edc1cccb2bcf6525255177f9537794a97f4acc5a977c56a98269dab46017f95dcab783b17a3010001 \\x8436048146b80226b0a0e2d6a7132ebe1aff8d76623be63f085e84095a64f95cb7fca16952f98849f9c95ab7246aa223bac81fd000d2b35b4065983b53b67709 1679820557000000 1680425357000000 1743497357000000 1838105357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-324 \\x12fbbd49a65c85739264570a5f401fb3ed5f67b6b547e7e62688c0ae626108f76865a404004eb39f1729a225f0cb026b96466992304abc197e80889811185878 1 0 \\x000000010000000000800003d12adf5029b37a6d81715ed49e9581b63bfedbda86679d0abcf9b600c28cb930bfa41e6f6601ae991f4b03c29a2d36fd72f61779154408923edca48f62a345d3311596a57c927232296d832175a90ed1cca17212696bc0434a1e133c5ad197c80e5060ff32efc507cbeb65d47cfb5b64335167fa9eb1fd0396707ca1de55e9a9010001 \\x97c46c6be4b5f8db215585a6b0444ef0ee8c8d95869da6731264ae6bd49908d642fd15e6dd67c6fb3649ea6183e9a9855fef258a02bd69707b8ee0a385219408 1667730557000000 1668335357000000 1731407357000000 1826015357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-325 \\x12fbdf0a54dcaeabca541345c3cc15165c85d50057a0ae0abaeb627dfaf2df945e70ee169c6f40dfcd76773f677570abcbfc327d6c8e3960da44b128225cd258 1 0 \\x000000010000000000800003c4ed1c7c8654609e3d00d046ca1e957537029adeb92e9f73edd2e5d2af79846d29caa9e3c359b2b7c3b1e31989b9d74fe448f03ac8a5fd7d21244b7c06dd16c2481336f5d155c98dd60989ff6c1c3707a09d161750dc3a4253f2479ac06c8697799acc46a3fd9777edeadb0e7e9ca65d203fa8f78c3d17fcb943b4bb2e95c99f010001 \\x7df4b69db67ecd58dd7d6e6b5f4b12f27daec479a4a55d3650edd285f03593f2404dcb2666e8b7b668bf254e4f744c69e30ff7f8055171078c7b351d2823430c 1656849557000000 1657454357000000 1720526357000000 1815134357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-326 \\x14d3bcdd6f03ebc5ba60f4e3e194a80b184cfa84518e716a32c044214fa63de17a8534b507b638705df02b80d815de8ab08e63e0686856e2cf2186257f4cfb4b 1 0 \\x000000010000000000800003af5dbe16f0818785ceb7d4e3d210aa1692b6c1df274468335602758fc4be5abff983249ea62449d6770c39908bfd031e0c85e42bb9d260511fba23b056be5a3da6d58825628e153d1b4e83223b864be844247566a84a5bae661c361e409cbc9336b2b8efe9804ad142a926be86b7e7a20bdeec992cfbfd6eba1ed894fbd10be7010001 \\xdea742f95cc16d5325bec8a9bb13cd4c8f6acc9ba222b2feaf70f6534e6254665dae4b2a87e2308e01c1105b06c314312084e761ed5a0b127e53ce87da62b501 1674984557000000 1675589357000000 1738661357000000 1833269357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-327 \\x15e7ba664824a81f2fa32de89896e694551ea8cdb43ec7aa7b8ef685485ce7ea9687d519df06c2e77e8777dafca2c2bb268ccca8bff6206e479aedc0f160a4d5 1 0 \\x000000010000000000800003a65bc77a3a3b3354166d519d56b748ef7fc44fcccf9f4be3c3fb07b6689834ec199fa390712832be8ac0c5bf9c7bf9a86ff1f7126ed4572b8d1d8b842206d3b1e17b9d2323448b0424c926193159009a84b37589bbf128d4127ac96306b886216c9015883ec637deb85c34155256306224cfbf33fd4ed7c6cd3847183ef1f2c7010001 \\x65214e3603e5b615174093f570ce67f1a12129c51fc70406c64971c4ed570a318bc3151d11e1037c12edf375b1bd07d0e435c208e04d71c8b07f9d4b90cbd10f 1670753057000000 1671357857000000 1734429857000000 1829037857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-328 \\x16b75fcbc23ee0f48d27b4cfe63e9bf40d8ee45c0389a0e4772bdad5a7b2ed70ab4993fc35a4d25adc242cefe99520d34877ebcb83e798d8ce4d76f2a1208179 1 0 \\x000000010000000000800003dacbc636fca43ba08b7f81bc2a03d674513c000e79a390667373f181325d871d2a560d4974be1d2d4112f47229e481a0d66148703d0d2c94de1a6d2e3601d4c965ca05eb9dd03756b6be963a35a9e94ea4875f87d7fed93509de93bd0284d08e32bfcb64aa1792adef36e1d1b096a2d594e43c30aea08865f344c816407978c9010001 \\xf8327655f2cf16f66a4979b1bc2915bdd1af8bae58a1e12173b7bfa67beea548eadfb68cde6134eded5e9730b51334208ed9a3e33f10b89b2039f308313deb0c 1667730557000000 1668335357000000 1731407357000000 1826015357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-329 \\x197323d1827d40dbf83cbdce3a526316e0eca9a6bea43a13e8c0471a2de3c6da82b7db8467fc80d3525586caa61952c61d739638bb0dd5644b4b9abf0e207f6a 1 0 \\x000000010000000000800003c09d9dc3929a65bb03fe04851c26d84bd36ad683b4d851dfadbf0e43ba67a3e2ad4b9c4df5c7cf3715643d0f23fcc2659607d2cdf15fc0ef81ec62a8cff06ded1abd90e1ed982a5a3a284a25b80351c918d9f5d608b4197352377313f8d327df91117700b1e304c279722e253501514890afa98698897e7c674e9cdf8447f679010001 \\x326346cae605f660e96658175ef0c3feba9164e644b08227209a9e2a09ecbb5b7e015138d1ce2a695819045687854f02461ef7fda57703ce8c51cd21806df809 1675589057000000 1676193857000000 1739265857000000 1833873857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-330 \\x1ab3095e48fb9c0133a84cc326fcb9cf25c72c3cf334eca66a070728e36f0ed30975e43954843270375ff4c480393e55dfcc98173c5365d04a9dca3d7d9b59e6 1 0 \\x000000010000000000800003b9798d4a52e1ab1162d827a486706e22906882d76bb2aa7f19dde3ba1d18873985b76865b9f8be91d03533493456dc62bcdecf67465a995a4e91eb25006a8e7eb4febc7577121eba0d977193d034332d3a94be36d9d9ef4ac3a11ddf6ac0b277abac777a263cd8489a376156d3a8ff5be980d9cfec5248717f9756bf5deafb53010001 \\x9e754a24ae42a767021b4b38c60e8057943e11ac01c6cd0bf3b7f26d24c9e01a9ef7dc90d8d6b3738d88d7828c0f039c3342701fe42ca2048030c1efc12d2c06 1660476557000000 1661081357000000 1724153357000000 1818761357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-331 \\x1cc78f178d0daebd4405dd52193b8bae8db64bfaeb95d2c7b66fd0809c05bd0ae5a2613adc9c5758a36e234812343952fc18373b4e5b2a5127ab3dd2bb98347e 1 0 \\x000000010000000000800003d17150dc00464ce218814add51962f8fd7b74a971a1b25e60d4935c74ec9a3bee451a97eee850fc1d603568d2b5ca2e955ca221b0d535d4111fb6fabd5a44f41f1a52fc3ea34e5da699686c2efdfe00e2b77eb4e8705f3fed6ce37975381f46479317ce063e033b6365e078fdd8c208e6f71799eea3df023fcabcffaa7ee2e7f010001 \\xcb751f139fb909332563f6cc92bbd07259b4686e938f5531d735cf367ad6af4844af9a74d1cf03727c9473bfe783169657d4667b5a7f00a5d854375a89d4cf08 1656245057000000 1656849857000000 1719921857000000 1814529857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-332 \\x1e83551cb94a08673ae144021e818d0d8e77b4d6e00c0f33b7f7a63209283f3f1912b78a1503eb5cd445f683f4d8a5bad810a546a174803fff8127ade1f927c2 1 0 \\x000000010000000000800003c7e78669855509f305a4758ef94a8952a959221e52e8e46a17eb04763fa22babe297b1f177184df7b2ecd4964c712ed71330af1492e4c490d3770dff4f4735915bd664d4ae5794352e97965982e5d8fe6b937a2f20e6c37e56531d9fa96a01037e847b09c75a3845eae2c780202e0b89ace4d580f7209a5db387e8de900b9f63010001 \\x669441709ad5fedb6e60647fc0bbb2b74f52deddef3d0e1a7d95aec11218f899b1df990134cbe795b050c1c6ee4858b771c4ca4b52eb09292613a6d3155c6302 1674984557000000 1675589357000000 1738661357000000 1833269357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-333 \\x1e3baf8bdebe87e63d3c90d34aa8ade173f7d49681d4e9639b2a11dded6bf3775867b6d3a8562e9e78ea0a9ae63f6d795e7d51709e2e307755c1b74ce4f95a97 1 0 \\x000000010000000000800003f5659dfec4e23389a680068830951b129a7ed6d45341443bcb3e46fab4b9f7ea1bb3dfdeef44d4ec2640abec6879befcc18e797e2290dae63ccb2338e858318ccd1836999158c09735800710882d24dd72f4142069f19036407988eb06b56bb32541f220a3c8474111091c677735b4926f59d77c6aa4c73f3e2dacfd0e808b3d010001 \\x91aed150b1fa53de80ccc16cadb42623de5372974291806060234954be6ac68f80ec12611be5ecb5d4c0d49bfd9f1b0010a8e625725ab75e009a179854c8a108 1655640557000000 1656245357000000 1719317357000000 1813925357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-334 \\x2293b4c3d57822179949bf2d9d480dcbb1599293bf4daba7def9e9f1477e4b0d32a5182e19d0d2936e81704d549b5998e3a823d1f2e020b494725084df82aefe 1 0 \\x000000010000000000800003b2d4d48a5283dd44bf8e6443215f7718222b2ba39ea6ccc57a6a3bd983c71e13c31a2043b18aa88cbf1106db816ddec958c41d0fbceaae5829a70de99a27e81a58560f29c2a92b3e66f4ea065edae3c10e013cc980ae5627214d2eef4a113d4b573bc0996b3dfac844a72f1d14152d68b785aa62b1bda6e209e4177ab8c489e3010001 \\x16a2d5c3b526f4a63adf08ea53796f1ab9c6aa9c5a99ceb82cae7c2f3cd8a627ce6f3f737c0015cb00a3fb38b043d50d68d4faae547d217eb7b783284d0f6e05 1676798057000000 1677402857000000 1740474857000000 1835082857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-335 \\x24ebc3bcc1404165bc8ca40aabf98c144c5ec257968b8ef4d55aed9d01ae1eef5b4784adcbef7cb7bc98e48c9010a5280096f54f55f30c3778351b9044566586 1 0 \\x000000010000000000800003e62f072d3ce8fcbb4b4a45d1a602ad218a4f281ce9535ed058f2d580724dd173d6a704166512da18a997aeff93189e56ac6e1875032626c93a9ca7992cdb4a46860f03b83576ad9bf354833dc5c2a9f584b9cc6f1e1cf295fb99d4f55d4ce82461dc828beb9899f015c8eb122b452d3a7da16fe796db998dba97c985ba8a3745010001 \\xaa5f4fe22c6a637352aa2a231eec21bcb176bbe7d8bd0c7ba1129dff7776d7442bb9d21be2053f4b3ce4e8c0657e11241a2b315e48c95f7cb630d4c534e72a00 1679820557000000 1680425357000000 1743497357000000 1838105357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-336 \\x26a32305ae0e81223325e5a683d67b79ff4d08ed5dc6ea9c473cedf8a05077a8e55a08aa9bce7c5f75520338cb671ac1d630d28b51e0b341ed8a3d944aeddbdb 1 0 \\x000000010000000000800003d86690852c8e1cf1d7e0ff4e68acef0db4b3f13bd3f65020743121764f1efb463a24308c9f7d7d9633c6d756a35565f0fcfc56820335c382ef6d14fb214d3ff8a05897566aedf9e374525e0f21132d94d53ff6c2234a20bc1865f9d5ea7f0c60668b3ed65e9a980496ce08cf620ba39a9a0b555224e290e05d6b58cad983a52b010001 \\x75ad8293d4a2e0ffed9f3ddae27fc65c028ea9daf21491fe87ea01b5123057a3bf9d435efca13d277ba0385d91d776a1070d1afdd16983325bd28d4b21cd8408 1672566557000000 1673171357000000 1736243357000000 1830851357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-337 \\x270fbf9ad8ec3c175dc91fb8133f69f54616bda639d69f4acaff779d8f1c7c178839288d0b49301d0fbfb001fa2985a91ae0ad3fbe6ace69943b7613981763ef 1 0 \\x000000010000000000800003c3b83445c707408fe6ba21ef2b71bf58ebeaa284b9fb623ea1fe3f2333338c6d59d99da32e50541a1a10f8f491144b9c10341ffd2e68296321c0b0625cf38939f8c0a17ed5d4e917938c0a227fb66ccbdcfc073ebb0be8df9902f28ed90f671848c1dd1aacafd3a885363bd9dba27c85cef1fe9772d1fd0c7f7274c43acba987010001 \\x0438d6b68149319390baa6e333f6e6e93e9df707a0a76f341438d830ad669134f53e178fcfa4f46cfc96634caafe66b5f6cff4389a0d8ea9766824e9be8c4e01 1658058557000000 1658663357000000 1721735357000000 1816343357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-338 \\x2cf330f61cb416427762a3cc55f5304e8fb3add3addfee6dea3f324990927b1a05cae6b8a476d498f897f199156632ae756657f7b992109c448d7f4211efed4c 1 0 \\x000000010000000000800003b48c5f76789b04f1b6f16fd108ad1db84608294a61bbbc6b73fbb8a6443a8cd4a1f66c0f5915f3e3fa0316a1d986120df1ef758af0342056bc7d3206350f6781d0a129ecfae99f54701e4b9091ced9465224e2a41c38cb2db613d5be5014ad90db571337f2f43dff50a73c763d20677e1c692876d08559a6f8c71348141d09dd010001 \\xe7bf65ea9eec37731a1be8135378be878842a44c774608b8165c39979d12f35243f4735590bc27973512cf611f23d3886b449cf3bdb58e7f2d9c3a1db8d35700 1668939557000000 1669544357000000 1732616357000000 1827224357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-339 \\x3aaf1cc484b935889f185f5fb8446d7e244797f34f80877c5cd410aa0f5a9ce816003456910f358fef5ea7f239d12e8b85a103081c2f1321d097ddfdce31a4e3 1 0 \\x000000010000000000800003dcbbdabb6f24d47d6357ec4fc9ce9c3a03921d79b604ea8f0a99c57ff85ba536000847866ad40c3e62dccaeff723afb9306937da735a7567f03589411ab2121a061e5989e2a990931a63c526428dad267df8adce322122a91a8f2b24fc08078b550663477850eb5e61fa91dc234586b1b262d17aba28830b07d626a3c29c912d010001 \\x6a3d87652a91fef65792760f772c71ffa8905ee603e6e303049d6b21ad2f315dd26fabe2474d36fea3650182b416d2f170978f3f89cf17f166d5416d0cb18304 1674380057000000 1674984857000000 1738056857000000 1832664857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-340 \\x3a3bd244873376d583952e4bc735ef5f33bda30e13dc5759429fcea6128ee7729275f9e523d7810dfec732a81a9a709a6f53e882105b80241aceb4dd54fa72cb 1 0 \\x000000010000000000800003f93affc9d576fd6c4ecca43fdcb27065e268ef1ca63df9ee389993f0062df70fb25ee7becda1e10f2374a87cf62da77f1d9a38ac523dfe8ec74c49115f6c22597481d77f55a6f5ed7011889b20586a388087db87076d5140dcf440448dd72fb39724471e0a78a3a2bf2cfddec7c82b368855a43a1ba31a75ff2f7f91dfd8ea2b010001 \\x155e182a50bbe1023eb5530f0cf51a1bfe0e77cc598052fb993d41f472d465620a96275b0843ecdcd1d74b61a32edf0de9eaf7582e36cbd85cd3c3f2824cb10a 1667730557000000 1668335357000000 1731407357000000 1826015357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-341 \\x3d3b020c77798aefd18d2c827836a6aea461aa11e8ec7933263819909aaee331a61977f6ad05e9cf08ae09b4a63085300a3d0ab8f3afdd558b482006e3582d15 1 0 \\x000000010000000000800003da5ae67c5765df63352628e870c53ad487e3d0c3ea4dbf9d5f09456784d4c1922bb3cd3a03bde262eba7ba0b5404f2efe49362da742dee3baeb20a51f667582ce127577945f78ccb8da326caabe8e27851cc5e1d1f14523316a440899f633fd872971c54158d17e1946db15f4a9bff39a3516cfe486d513fcf9bd3e571860e2b010001 \\xd70b83b605cc0dd171855c031cdfea54526e2a10d4a8bb4d77e923532d2669237ea62b80432fc55053fdb7a34fbfcf99802d7d8aaae594988409b9c505bc770a 1673171057000000 1673775857000000 1736847857000000 1831455857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-342 \\x3ee31a9dbb9da77dcf16df1d962f041724d0c881721539309977bcb5d59d04604c5a8030a228500af050fb9cd44b9d37d65f040e0c2d95ff95f697fe7878b947 1 0 \\x000000010000000000800003b4b26f07a0085b6e1cd738e6725d1ac09c9272c9d9cf75eb884897565ce51a1c38b306a4e38626933e5d297072141942567bbdee14aa2b06bf6e9da92191cf4b2bbb53a8262f05cdc1dd756804621ddc684aff92709dbb7c067dc427e571c809ca2d4a179b8bdeab29ab4ea6ee0ea0657a49f02b0c447f2989b07d65208838fd010001 \\xb11e6648a839958f4d0c9ce3d04efa4b36e246802abbb0f76bea0db401c8e3f7c505c8a531533a013f6c11a2d34c0afdcbf11e31b7237bce3abe679430e23206 1684052057000000 1684656857000000 1747728857000000 1842336857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-343 \\x45ff648c5c50b151d7b88d8faff6a2abf353581e52c0bfcd6a4744b0a4b7098db0b956d6fd9a32e48db5033fec7695cb5a627e93399a07fcf50298e675aa78f3 1 0 \\x0000000100000000008000039cb999762631a986c251fd7514f3f2789a6ae74b6106fdaf944b7c4a739002469c3afa3cebcf997d3bc68483da05c1bafeebc1365a728ad3c2cfba5535762e8c4125eb1442dafb273eeff3ba4e494b77234a71b2ff92724b7502846217af1725edb4a1c7ff68507a52df692cc93171f28d458634078ff712787ce77d09a42d89010001 \\xdb4b6ba00933ef95f3e10e806985a4fe9f6df3bceb5edc369fea3095613f7554d8b919fac79ef19839853ad265d654f434fc5c3292aa51d96f82d0a090cf6d0b 1679820557000000 1680425357000000 1743497357000000 1838105357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-344 \\x4573a090b824877ac8784baa2938e7250d54e2db461468947ce6be47200072687aafdeac2c250da26ae8fc06c868bb49ad3d4f835b1ae5efccab5b88c4ba98cc 1 0 \\x000000010000000000800003cdd9abe095cf7f5a3cce51685b0e0273895606c936990b0cdb07e43164f3dedd493873854a77301b9dfe6a6c711faf0bdad9077720dea2eb0614ee76a538707b284e48f39abd63c1d19a079d5d9fafb1d0a529bc17b23bb17555f204e83f5271b41721b33453f904d12f3abcfe8aea366ab23d11ce74cac302580224b1a0ac79010001 \\xb8cb059714d0be2f7755cee167be4129e5bc65d77f4e4c5101056b10b187a12a6164cad8e1457e4f3c9f367903bc2d9bfbe63127e1aba605dc109580937eb30b 1665917057000000 1666521857000000 1729593857000000 1824201857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-345 \\x49bb586530b74600443157f7a6d565cb9101a1bf3186543bfefd77df7737fce1aba2b3066f7dc390a50675a81a00d697281f756c90a6630e8f9c67559a5ccb6e 1 0 \\x000000010000000000800003af2b9e15db63a8dd9d469fdbc7b931c30a952169df97dd94bb3836bf4087ed2d076a3939d3e0e880c3388c324ea641849048056f7442a16c1b4204a1b8db745e242f58332ca436e4f5fea1d0bfbcf8d03aed6436431b7c749b9ecfd60c2101020e684b473262d3d21ee7c1f1ceb1787d06bf5bd03d441a6d01f0524b14038067010001 \\x23ab6f5a472b731125358c1c8e925c088a0d2ef7a445b108b007abcb670a137544ca93983f95af674f51cb89d5ab1cf6eeaf8710816949a2951338ed17871206 1664103557000000 1664708357000000 1727780357000000 1822388357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-346 \\x505762bac350086a210b515e439db36ec856e1ecd3d7f027f27a018315c4baa44faa7c0da40816c3de1e0b900f2f54bba2f63ec746f2307b96a063a363563cac 1 0 \\x000000010000000000800003b7d15e480158101deec3074488cf590074aaa0d32ae62e2edbd19683ea0af6a73854937eb2c4beb86a553812cf227367bfaa77330ba404b348ab6185c7f5bb02be9086af766142d3214da4437ebb50699b79435f4134d2b56afccd5df28cdc0a4c104551ad915cf327ff9a97cbcf6435d4384001c86b048cff2fa08340b7a3f3010001 \\x17a50478b470485b529d78c3fcfd088e93c075643ea562207cc55f70e27daca90b8481d294f60ef3aa7c05f86bbc53527754ade342d23947eb827fe0d7bd8802 1667730557000000 1668335357000000 1731407357000000 1826015357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-347 \\x52ffff1227775f193282f1004074939755e5285b060800b8c1abcd42292caa746be22cb35556068840b66f867a3046c0ba3ae754a2d244f71bb78455197ea045 1 0 \\x000000010000000000800003d46defa79074da8ff2daf99af9571c981ad2d8e0a7feafef350c939592ccdc403b280f2a88a503c64804cbf3428200d0bf6bc174c600adc9f3db14be7bc01a79e744d66b727a9b297a831c8cd27b83c470d26195090bb8bcb8e5fc44158d1a840c19c87b75655ab70d32302c737dd04e5dd805c3fab46a4d2f15cb8d36ba4d13010001 \\xd4c566e624a8d6721b1ba263bec57f32c8294d55f69078e2dce87f3b3e43fa836b39c6da39dfd0fbf6a1d26aa2cde7b1055934ac94f07310bc70213dd0c07305 1679216057000000 1679820857000000 1742892857000000 1837500857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-348 \\x527bd876dce3a145846fef8c6b8245f9cea64c3753c58d84c6e61d0490acbcb5a92869192abaf3e4b18a2e5012831396f9c5d5fdd28c6fecf512233497280e06 1 0 \\x000000010000000000800003b77b325569b21a3de57e9b55e9f7278943cf97e643d1ad5889594cb3736f9b3bdf5279252276b1a872170453f5ec8e453147011668066279c9dfda7170eae436126c5703fa7c5547cfbed6d121f0b5f6ed499fa87456191260cac3223133382d0b12847b2befc6f42ca2c37c334f3f46b030b445cb289ef19a0e50bcb95bb5f3010001 \\x046bb55acd58a87f896b198b36e9d9f675b92340b41f8e7966641b1f74212331ea349dadd906a8e4d8d56147ca90afc8e3e60f2da6711d6ba01d9392d323e003 1683447557000000 1684052357000000 1747124357000000 1841732357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-349 \\x56333e2f39c20877180a40338f500deb1363e94e551868da6c69a75f1e3c3184b96ca62777812f47b2d511528aad128ddf94bec4a430d8cc65c148e5f6636ce5 1 0 \\x000000010000000000800003a93648b0e1019d42e1d2f7cbdef3db6ea5b409148a7b6c9dab8ea55ef8b5cefd1a2e3ba398207a65fef935e3d7b6a920072b9c6a49773602cd72af314f11e033d0e08f9daaab65495ae65235ef3ade140f7eae124d0fa1d890cc9bb2e4e47765b09a19b1b2b7488a8ba312dfc891c6b295751a336bdf50803117157bc77c9e13010001 \\x57a364eefcb9bba3b2922be8b82f18b67a0b90e4a1462c27e46d2b39f43934c19384f6f529aac9fb8c6c15812e86ff0fc5a423d05465d03f61c4dbf6b640a10a 1668939557000000 1669544357000000 1732616357000000 1827224357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-350 \\x57bf774685b0229e6904c295aa7ee1a22952bad686cc484a1a04d6c016a7a93a96b0f09f6324b0b52dc2c4743ef430c6f5012472815d4eed7e85612dc6f8d821 1 0 \\x000000010000000000800003f2202bd1ab3076633af19cdd9a8857b1061815581609cb87de1545277071219778eda6e2392a2c1b83b752febef3768247683184dfc089219bf0c60d4cb5cae83fe25929135eaec75bd0a40fa5e1afcc3e5711a4d99bc85ba00b57997503fb05da0cb90236f385260a04b32aa9478cc1aadef68b9a3cd04171adaf51cadcd20b010001 \\x9679635610201652b955e1d5e04710678b2496a1f81439ca186d827d63128c2e691f8c8d8448e5639710f818d7569cca500148725e282253182298a04bbee103 1660476557000000 1661081357000000 1724153357000000 1818761357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-351 \\x583b423abb69b990f3814c820d4fb6664598e62f7c6cebe94f86fe6582ca874f70571c55d13242608c0fd6f4739999da3aa267e2d2f5c4094453b0cbffd6acbf 1 0 \\x000000010000000000800003b355b58893cd47a96a52b8a9c41000f7ea833ab58afa5c689c402d97e2052281dfa1aba902f7abdf193426a6075322df5510ae42f67c3b8670a6b62b3e7d15804ad319558d7ad4543cc0c374220e95d357d24ba6ecd47606942942a7362da241a536adecdb5fb132d082be638147f34874303039ce024041b22c82e53df16997010001 \\x9221718c94816247bf161494576c7b82c8640f049fe15c74d22f1360e7a826017c84bf3e7014b9e83e634fb694a9aede8bed35c2c56a0484a7d32dd04c3ee803 1679216057000000 1679820857000000 1742892857000000 1837500857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-352 \\x5a076ae028ec514606c44fa6a89c85b6a82fda5f4f0cfd9183c1a0b7cd53c4c93d1cff3df40f34cb24ca537db2df3ced17e9865c402d02c23c160e0533c40d51 1 0 \\x000000010000000000800003c24b6a25a92bda54e08657a9dfb83221229e7d38f38fbdcdb16c33c4bd4744b19bbb3648fa29876f127f0b1e6ae4ca339c2553467fa3845012c52bfb0c13a2f44729d9c4c688fcac32d6bec8cb467a142761d5b87f586be40546d8384e9cd86b7443f61c130e2161c09401593a93d679b228996e7d446e70c2313c5c46fa461d010001 \\xe4b1b12d106c89ae8a28b6e90bbc534250e151fe936de468a42ae238e3d06563ed9d0a5142f77f57e1cef9af963921ff2a111fd245682236d64600f3ba1e2d01 1665312557000000 1665917357000000 1728989357000000 1823597357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-353 \\x5bc74f025520311f7189f9018d8e3236f1a486fcfe43c22d68d6503deb65d6c916ec65d2d361fb7e0453190ca8e0fb8105343ac83d4369f70c603ef0010704b1 1 0 \\x000000010000000000800003b68a117cd74a17fbb5ecd131b14e48c8a7ea279ff93e5c67ca381dd423e6bf33b878f0b37ecaceaabcd4073b24184817c2d97d86d04a28a76c18bafcc10e8bdc5c676627d96eba485105d58b8ec0f23a2295ad16c1ebcd369e28b266caf91d31e5424d9198ba182895eadeca15e9879fac67a5bf4c867a2d2f61201661cec5ef010001 \\x8106bbfcc6322e4df1312b69d7977319ac7a19472518dc08511385b2c98220962a2ed5887494cdcc617ffc0bdd0e560db3a259e020429563446d4cac46b7780b 1673171057000000 1673775857000000 1736847857000000 1831455857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-354 \\x5c3b4cfcc91a200e8a1a651b2f07e55a9aa9b122673b03a4449cce6d5dff7d0bed0ccd8fdbedc76f0f535d1a45a125476833414a53d3d90c808ca8d2d0ab2276 1 0 \\x000000010000000000800003ccc4013425065ed822eb0537d48099c4334e478786f1e4b8f6f92fe9279e615db7a63d77e7c2e778cc42ecbd9e34b631ca5633f9a2f2deb8207af348d283d2b3fa67b458d0251411bcd023fb47bfbcc41d43c166928a818f01f52fc651c504aa77203821a2f57a1b588a05b5737a120765baa7edae386ea57d4961fb5c1e7d51010001 \\xd85ae64cc1cbedb9fc8ff8dff886b3bd6d4c6a37d16aece4873ca82499ea7ab860b362c13d6a5ec98174a053a8c8114cbf58b84556e3be5f9f77af63c0283603 1661081057000000 1661685857000000 1724757857000000 1819365857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-355 \\x63e3bf64cc15d81f976a00edbf7e43184c0e33ced5ae5f69adf4bd84dfbc741090000cef93a71e7857a8c32c572470b07c3108e11b11e23dcce59de447fa7550 1 0 \\x000000010000000000800003c63a27dccc12dc2bb06ef8c6888921ba520e81a382ad167c986b5142c92b5d97f031043dca5196f6248fcce905afdaa1692cff6ee895fa5be88bde9a44306cda200a843b97c21c06238f6765c47409fe0f4b8f32383e5b81fa3fc7caf8c3185b862f98d6166668760bb246715db3231ae6f5dfc77e57377f348efde1de723389010001 \\x20976f9a3ccd28949b86edf667a42c943264bf9438cc8c1fb233d456c7d3b72c7c7a495a0e719cec58f1ffa1d5728ef41b6ce7e47917d0751e70d7b6dd3ae605 1687074557000000 1687679357000000 1750751357000000 1845359357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-356 \\x649b420c34a250dfd820537a9d1c8ad5987e53983eb5b6942b56f94a4a6d3f6aefd7b173561170a6c76d578ae49726e531ad578bb7332daccd34c0002523f1cc 1 0 \\x000000010000000000800003c1628763c37468b05263778e283ed2cb6ff707a5a36b8c9f3cbbb8e1bd7974f7a48fb3e2fc6b183e97f205aa9bba755432fa572d33cc496cf7415142fc4a526f37b1690bf65095ec712c728dacf8fd896678bcc74ed7a73af90ddfa7af13a14bdd5c9b4a5ebc43d817839b8a8908a0b263a845763c98fb6efbe7846c088abe43010001 \\x1bc08742780ffce0022fb3ebb5db56cc0a107d6ccb717277719c253814d2a65a67325f302b9de70b84fe705a5499b80a98c81367f44ca42d4af28f948100f201 1676193557000000 1676798357000000 1739870357000000 1834478357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-357 \\x6677f359b77264c7b892f120f323565281175ee45a5561696eaeae3748cf79bbd272c943ea47635300647c9f39ec420627b496ec4ba5179d2e435996b52b2f09 1 0 \\x000000010000000000800003d0152901b8104b2d8f4b0a486a3acdbbff59d85af88a5f0e47a8ac14151df812de203d36c43d279ec9f2469181e7c2157043545e12ce8586c23b0af6d505f3f4d5fe641dc2088e4f14ca2a2340602afa04b19127b2638de55a9735176633f5997bb16332c5eec8243f52d48cdbb230237760cc984612e2f899a91b22f88af9e5010001 \\x5aa3d19a7076e1e70bb6d7eff2ee47bd033a02998c3792cdca921ee72fd1a401072b32196f8fc70157eee3561123129a4ef67c43022736293685a4b962efe005 1685865557000000 1686470357000000 1749542357000000 1844150357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-358 \\x6613d5613357dd96ef8a7c5cae455198a6e1481572cabde6e5b22f090492450634a95d974db057cbe55f2c1685537cac58bc999b98691c7303c5f83a8451827a 1 0 \\x000000010000000000800003c791e093420d47c495f342d3e4d0bd981658cb7f86c70b711f93d9b4e808ebc39d010f967eb3263efeb8ee896bccf8e2b3f70b41f44cd26ba7ccccd429fc8e459fbc719a3d9b6d7b4ed71d167876adf4d2acf7232deb1e2ed20c028c54dbc598ac6347ce31bbcaf5c7e9a6bcc0424619c4573b8f86cc7451369c5fb6e324b41b010001 \\x15a7a6be20bbbda0bbcdd6fb716e763e3766f16a6176747c902787ec7a164b056334d31a116ba6691f3e0f73b14900621b78d341e44ff381495b8e51124a1404 1665312557000000 1665917357000000 1728989357000000 1823597357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-359 \\x6e9b07e49b776feb63c51e0846d22f282c2d7884d8f35b267cfa774d41d2212653479f9747a0597b5968db922b5f6bb0eec486f37bd344b3f1d17de138208ff2 1 0 \\x000000010000000000800003b925eac41556bc26d3fdee063784b18db3183ce80b20fd458b5a5e15bbab9c5beb014fa4a88f3d38d6de7e338e59832449b1de1121c8bde1025e85e9537989505208fc393de4f2f92e9f35c83f2988062a750cb5b7ad1ce00b7da2c224c293b7f17b8e688e86365672c634596564a94543ab501aed5fffda9a11449c01cf12ef010001 \\xc41f4dc6b568b3bd4148ed2670df75bd1c56d1365914e405babac06e7d6f131527668db2130683bf81bccb2895d78d8df560e51da4af2753fb6a8a5346485b03 1683447557000000 1684052357000000 1747124357000000 1841732357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-360 \\x72c7d9a97a38232869cad31b6fdc5a6eda2c616f035da40120897fa0f9ff7a913efda54728c96509a4730133e2c9506c201f8495f655dcf0886036b02987dccf 1 0 \\x000000010000000000800003d7bde7f122f571d88cf7f8814f2ae73a023cb4c9c0102c5625863ea0ea2d60484ce3d0cf50be3bb276ecd10d3d09f4b9b370c1f2de9d671b10c5bd2974ccb8876cf07b42968cfdcbeb562837c5066f6df1aebb1cc6b0ddeed609bd663654ce5f9ae366596818038e39935d7d2d8e1c2539174106f3f4ba22c1499f205fd1f145010001 \\xc1f709a378674c8856eff5436b6e1b0c5263b766417041cb97754392c7169816805ea2a42a3dba079a30807a2601eb5eeb2a8ab0da2a1c81be496a8b7af08809 1674380057000000 1674984857000000 1738056857000000 1832664857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-361 \\x729f4689b311de76baae4ad5a77096233aa70325186dc721666a608e99fafc9e232bb822fdf6988c69c6b3a5d8f24ede422fb69f1cee233b571be1aa5acda1b3 1 0 \\x000000010000000000800003cd83cea27c308b0cdfb3c4cf06d6d7c59a3427304d0d48c64be27650d17e407aa3fceab2c055442c49f81bd259237b1d5172133a6180575061a5b0fbed2a31c83914cd026aae9e9d711b332bf1e0436083881b2f5c7c21e4ee3b926bf09b214d20491e70b0216533a9b253d7ac9ffd33afad15350cdd79a32007ac117b6f556f010001 \\x2bef4ec2d8f3ffe5164ca86f4c91d9cc297c11552866c81f844d2716513c3b34a9913e622b97e68558c2885dbf3b618027d0505cfc99748c05399f51c2a6710c 1671962057000000 1672566857000000 1735638857000000 1830246857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-362 \\x727b6ee2934bccfbd97db2cff20e66743344da8c8455d78a403b4ece0ec4ccc8c1c6509e670098cf3965df9a95f9d6b456093abe0f1bbfad6fdf1771b7c023b1 1 0 \\x000000010000000000800003cb8a60ef35c43bdb98c73a0aca0c8e0a60e161b552ae2bbda2e2916117b4dbc768ee4f677dd39a0fc0791fb86a862440c9fc928f0c87a840ea87459e53f7a987d2e7fcc96aa68ad6bc41fda6d72f9ef6266307765da875ba8cebfb8380d516920145f1f21ebdd08e1b93d86fbd30a35dfd9cb463d34187a484d5bd850c88140b010001 \\xfe27080c133b6954ca32e6326221b8d8c346073711c2f8c517fe2fec7b64bb8db77e965ecd5c5074ad329b224b432aa70fc6ee23109d128deb1967b9db20e10d 1661081057000000 1661685857000000 1724757857000000 1819365857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-363 \\x75e7e124ba102fe129892cb23988b5d54410bc5b2d2cf84c43d92f97f84a6124642cdcc4eabaac78852d294df7abecdba1945a53a67593a4c85d2ba2239bb82a 1 0 \\x000000010000000000800003c493c17995ad7aa8af54f91d7d2e742ced057cd8df72263ace32219e30547a3b962fdd76551c72425f496daf42dafc379444728241a34de94352b1cd34ff81d93fc869fdc0d3afa035db779f32be1dac8a634a492cd1fe944b98520fc0a59e49123b9ad42e1b4a65ecc2727b7b73b2a62cda818083d881e8ba49b9c8bf0e0b2d010001 \\x104a5f55378de4d2741c99bf4957014cc3fce9cb75f1dbbaf2a809a237c85e6278bce1f26838fe0cb031d1d692682dbd98010ffbe71d497a531f02144bc5b40d 1679820557000000 1680425357000000 1743497357000000 1838105357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-364 \\x7543ee57e4f7905af6e14172a717967620973c7abdbca1132108145fe28fe4248d3552991bf36550f2f124c2c1cd3ed9972e9ddeeb815684da363d3540329706 1 0 \\x000000010000000000800003ca325e8845de89aef557f234f0a3e8122f635cde76b4617127a08d4b70813e5b917914c5b648d3852e35287f426f1dda301ba9f78210aa7d685156c525f80debab7817dee4ce172ee9417762a9f5c9d193e48b0f41b178749af75748bb5137939a1231423d55f118c8c6d303da2fe7979cd6501a93911fa7875d908848bbd555010001 \\x7a9a1d49d55cfa9d6b7d25a810c4095540b9d3dc91e09756acabc18c19b0ee35306c022ae790d556bbefc83510a39e61cafd9f67fcb02867bbabbd43fa1c510f 1658663057000000 1659267857000000 1722339857000000 1816947857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-365 \\x7cfbb94a3c796b770fd7efd5d6e6732b450b837e188fd43e92d240b6396a243b46d6f17902ff920453e485faab4315ead4f8a8925549cbf748a9b2ca27fa63e4 1 0 \\x000000010000000000800003c81611258f561521d6d146db0579193f942074fc85916cd566f1e90b84412379bc6fd30ddcd7d048b44318033785105f141b1a363acf5cbeb22d51699a7fb59cf5180e9369d50f7cbcbbbe7e0c6f0283626718185dfeb69783ba16d73ff29fdb0d2e46b2e8e0fe5ee88198e511d5ace8634e3acc5c4da184ed7ef815c6fcc1b9010001 \\x0fd8584b120693dc9a4f13f3b87fe97ff2869e846c86fe5652b76f01f9e99e3a9d9bbfaf27e9fbeb6face2a083bdd180876ff25e20e963727da45d42ccf62e07 1682843057000000 1683447857000000 1746519857000000 1841127857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-366 \\x7c7be7f63cee33d7df37951770e75d95db9a5d3f5f6452ecd679837ef24e955de0d8aa42a6e6ed7c3e2453600987971351820177862888e6cf5e162dc5f20bb7 1 0 \\x000000010000000000800003d8d54d3bd3c678456e0fb894dea4acb5a0e5c7656cf0f97ca65cb55436eef39d2690e81a1f8db4765b081656d5ffef8c4555c87483996581f15f342cd3a9fb48b49307a0fc075487a5c4d7731010ef40bd767c0dbaa17883c2b3b2757929ce7807fa8368d9e1f1ab4339c91ba298b704d0d44a9d990c9b605837ebc9231afb65010001 \\xc0661d1b7cc0ac5818363f6777cba0d20932525c6ff41f6b5faecd24c477278f5fa73781e702d49adc4dc81f05add8c2f7810174e8781ef3f657ce0d9c6a5806 1664103557000000 1664708357000000 1727780357000000 1822388357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-367 \\x7fbf5425d9eb5c417c6fa05d526be68743f2f0d3ba0501e0e788541bab4791480f68f825c598483c051aec4b54aed237256dfed7b379687bbb3faf04ca1e1d9a 1 0 \\x000000010000000000800003d59db68c0aef4b1fc7fa22a1932a1588dc8ba25f193345dbf8d8f761fc45eec0c3a792cc216ec6fd3f75b97b1697db2f5b5b0caa8fb445aacb0e0310a3bb1ee5a6a0dfb665af1ae88169b67a1c08642ed2e72e8411c42239450014862e3176896c1b5b78e77f09348b96cc4a3b04ce7c61918da0d4185ab8ccb6b178f3aad9f5010001 \\x4c08cace32f27da2600d7e3c2e91a7f533f368842c50cfa6062505e2a3737d4112232cbf86472774639a1091d8ef50834cd5292a12e82bb0ac05ab063725f605 1676193557000000 1676798357000000 1739870357000000 1834478357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-368 \\x83eb9fca59dc55769dd1cf8404934393dbe5c99a20da71c5368cba283a92cb37a3464362bdf092a59c2c733494129ae27b2fcf54b6b3be506f32dccd4e7db056 1 0 \\x000000010000000000800003c43f09541edeaec9ca4a5f79a8dda1affffe32dbfe8509c6ea825d6ee51724e8f21932f58a09b0ca424251dc006f1b2816ff45c5eccd2943c4d3483b0fca44d59cd499edba514ca7aef2f73733b40cee95e081506bbc756e43e5c3d838859f467efd96d05c2a31f087c10efe8f873d1f826eac63a68be5afa852e7cb7651ea4d010001 \\x094020b04d68cb04cd4da89b39957c2b9da3b5e42e9a1ad659cdd4c97eb1ca16547d8ac66b308311cbc60732bbf9e38923dacef623ae8744cd76d56540d55a08 1671962057000000 1672566857000000 1735638857000000 1830246857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-369 \\x8797e545afb34d7931311ef2271021f94dd51aa7d5e17654a64a83fe94b2150a0af6c2f500c6e132d101ab1970f3ef8f19685d91e41ae511585d472579f2a43d 1 0 \\x000000010000000000800003b79bcdcf073effdc1f4715d00f1979b95c2a131fa05eac6be5a99ad3405e59976476a95a8c6baa2f1cd5cac226d494b57637a961773545239563a66faa21296b5555d167212fa0323f7a179730bd7b6882675dd003c208dbcf1b59d45611b27a8c6076325530e4d9b5790f56bac38450234d73b5a4fe4f3a09c9f0c52bc5c71f010001 \\xca7702418121a8597ba10881c44bdc627b9ab1c004d359d353897cd5f160a81c0f77ad515909f9ec5a092fc9a3e3d71e86e7d869b1de7fff126fb360ade90405 1666521557000000 1667126357000000 1730198357000000 1824806357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-370 \\x897f6106bf8e428ca31672c1d783049e3a47c9b1106ed635734f4923a75c55dfdd3a5f5edc80f3834b5617a69c1e6aa58eac5500ebc39bac9d33b6ddedca661c 1 0 \\x000000010000000000800003dbae76ab7082ef282462258e6efaea0ddf728222401af35a22f86cdef237abe1e7f876272e0ed3f650178b1396237d3de841a5d123904b3cb0432fa4797b4d56ad0841f8c07c6332d3e31d8e3fdb38eb3f812cc18e4090879378a41a8f69e50b28660cc60e340e43636de07151082d9a9a782e7713084c6fc982eaec0dc05629010001 \\x81ea9319fb1617081cf224859bc4530a59360b7517e9b233a807f7d6b625a187a30210765eb2243261a1f8ecd80e7981a6c1e3eabe6625e7d3f1c9690631f90d 1683447557000000 1684052357000000 1747124357000000 1841732357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-371 \\x8c53a1850d9f556f808c5dd4f3d0619a23c6541bceea4e1a8dccdfaead552f8d3b8fe97ccf1ff1df2f381690d0b4dc64db8334b3dc558b07fad3b91c18ac9662 1 0 \\x000000010000000000800003c366ac63ac161150dfda7064395d07da1f048461d26ea04d90eebc2ffc4089e60b9d1ba7466f9b85d864d1e9536f5bac98db5ff57c904f285071fd5429ad61660901ac6fd4f74e65d42716cfdfbe4b8713387ee524bb417ec6408897b9c94d8fb27cc7ed075487795ec2ed6d2b90fa9d571a66077c78a9f916a554f9f81fba93010001 \\x60d04ab4b2a7b9dcb2fff0438cf425f7684e55a44123c451ff5edda0f8679137651bcd1f029a6c0c3f3079dd8fd24a94a5a6061d9e1f7985487b6f87df9a4304 1670148557000000 1670753357000000 1733825357000000 1828433357000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-372 \\x8f9749c097263f7ade8fa20e010365153cc7b6a1f6ef4f4161422e73ca4ee7a440b6d36c5adfa059e98c612b7b9e4d9c98c8769c0a8ec1960a3bcc808fbb231d 1 0 \\x000000010000000000800003e6ee5988de371101809b950bf7b69eea42dcab672d48b35d8c9d2aed309dac268a9e2bbdac29f65527e8ca7f76341d7b063a36ee02acbe4e1d91603ca96b90e04222f5017eef6f33db9ab37e50d6690183b92c108e2b45c1cf9538d00ebc37d3506de751ee6321824b42ec34de5abd321ff72119d688cfc65be52bc82d4ca411010001 \\xb92af7a1a56744346d1ee580e35a49819ee4a6bec8b5073b21e8c58cf5ab904c5b869547cd436fa52f84e1382b561fa3eb0fa0f34a0d2f7c88e945ccb0ba6a04 1674984557000000 1675589357000000 1738661357000000 1833269357000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-373 \\x97272a7f0b6a7514eb6d95d4e44f9c8f00e71082e7d7837a20e3158e5d872580c57435bc6493b869ed2910ae8478f924d87ca54b0509193155598010263bfa00 1 0 \\x000000010000000000800003e0a99516fcb5f69de428d25eaed35d2c79711a6f853f93b11555677bccdde696e91081edbdf003458e9c38a797aeb9d0dc3a87ce187d7bd97c7fd7f8f7b69e8ea3d2f0f8695ebd543d2aa4838cc11c1db355db0d8142267aea7c3c599df7d4a3e9cd1ac485dc77c9fe2b126e22ce9e3997ea69bf08b0efd8cef0e302abb6d9ff010001 \\x91a1abca337c33362d6456e3d6a0d79f82cac672224407d77287108a5f9095bb8f631b84743b37dc0d44a6600ea3ffc9d3cad2a03ac54be18cc39a585df8a40a 1680425057000000 1681029857000000 1744101857000000 1838709857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-374 \\x98a7587080680e9fa498fb8ef612f8c2de1894de638ad678ecfec7d910c07f51f169a4c5de0e236b180b8116bfb4248c3ea37ea21add1367d7c352c8fa7f1a17 1 0 \\x000000010000000000800003b1f8dae8fa75f8f335e3e39107789bccfb83a0f1523fed906b15810d6bd005379a0a1b6353cd5106da29badb7bb46d88ccd4bd5d9f7a40b8d6e9fde4e659b8dbce0f17f18398cc60a688ebc07b5c6fb91ca9097db4ad129739dff5d02365c54d6c01019457aaf3206ca66bf362909c5a8c51317748745621b2854a885ce09f9f010001 \\xdc156afe2debb18b073b69e6f3d77fcdf22ebe5282e04dc434c6b1f5ef596e895bf2f78ddca762f4520c770becde44f3c0ace89a50849ae37a643bcd13ec410e 1661081057000000 1661685857000000 1724757857000000 1819365857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-375 \\x98c75608231f9d805bac7cd5a089c213f22e583609a6dc09bee7b67ea3fee3ee1748d81938d4eb80301d09276ca5143bb92ef2117a75a0b5f0eda86ec3f4d9c6 1 0 \\x000000010000000000800003d3dc2db2499725e25f278cb7c8115e28aacd48487009ba036f0c3e2f0340622623b9733375f9b8578aa7daaf6ccb0d182d07eea1288602c41e43480c061e15c98e6402d0f5922c43684dd74775d983e967f50307fecf8170ec7ee77b6a874e9fe3b87f7e0d8c72e0a91482476cfd700c6fa822e927a0673532eb7f06a70dc951010001 \\xc321a3267fc23be7203dcbcfb764e7250f31d601a2c5250445c93c8c58ae913866898a611963b1b82fbab81cf5b2e839fa358d1df70652bfe7911c50c56d5b0a 1656245057000000 1656849857000000 1719921857000000 1814529857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-376 \\x9aeff5b7f0eaa78d4e10ddb7d4497519ef766a13f756047c4456c11c8519ae19731c2622eaf9124245596c4c34335b0f4119b4862b46c051fcd3d86acfd8dfdb 1 0 \\x0000000100000000008000039f04e9b21ab10b4fc12487fdb732c0be12beaf2ef0bfd1d061fc06588031f627b514d256f750d4cf12ce4f4957988cda71154b58b620c24a01ce9b61716751d124fbad20cd58e4ca48abb6c0686c3ef64a99e58874ee4ea658959e4166c3d7cd1013b86148d6312069421098df4f0f1b0f09ccc687ae63c432c931b873636a1b010001 \\x472bf275c6ab25fe0e34b810b8eeea331d4b41a3c8c1b195f1f25a5344ef58cbb9bb8c0a9b1fab6b67271252279e3f52eb9e7d28b6297deb29942f5b8a5fed01 1663499057000000 1664103857000000 1727175857000000 1821783857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-377 \\x9c0f4b9dc32f0a5f2510e2e6e2b58a93d8e3148742bdca08beb3ab40b1fbb82fe068e3d2338934cd98348f37802bf348034e25f8f9e3a16a7c9a71d9d3029381 1 0 \\x000000010000000000800003c0aab4557d9ebf22ab78b90cc6b0a5260f902f8cd9523eaacb6f68b782b8c0a8acd08ce5ce815ae2795209cea4242b41d9eec5dacaf54967b59630988f44a1d9c64e54ca1114ac68dafd575e2f4acba94e90751271c16f1e49b30e98848eaf29d1eef6afb58b56b5d72badb7b2000bdee9f8fa6a3c51a40cd91b6d6e27f00ad5010001 \\xd8c6826515ca9b5aff8ec6e17b24ce297ef91eaf1ed17c583a637694ffdbfa1493d4cff0b2534272f7c8eaf28e249b0b17a3906bc7c18ed6ab794840b57de20f 1665312557000000 1665917357000000 1728989357000000 1823597357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-378 \\x9f0f31f6eaf08c97330bcf5ccb0cb48ecec52c81ec477cc97d0b3f554fb74ba61876b4c0388cc0856720320e5edcc6b70363d86a1f387a2ad1b3844f47ec97a9 1 0 \\x000000010000000000800003c70b95c0b477f1f27ed1d321ba961aa55ea32223fe84dca0fff2160447fee963da57f13e1a2198dce3c9f8cfec45810133a8f40899a2b97528041785f3a271a5d422f98752d83b215585a4de5b5f248aaa3f818caa50d026b2afe19c7a4698e89456bb4c763d37609e9809e80a204362df982f915a17ad6dca213062f2337e13010001 \\x4285a8f8efb104273592d88db2bef0e71455d78ec810e289e4c8be8d9d869ec246539caaefa6b63b8110bfbcc4ef7ca5407988bb2cefe9f5d2e9c8d5630ca20b 1680425057000000 1681029857000000 1744101857000000 1838709857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-379 \\xa8831e10b9a1635d46977e0e98c08b1c4ff4ab38f124aceb704f5cdef69d9178d5b7f10a2beb1502966dc5c3c1c5650d22c84632bf842d117793333382a79df4 1 0 \\x000000010000000000800003d587244cf2546dbc3161377ebb31e14b3118e35fbaa65b08918b3fd5e259a3bfa4b554b8f7c2eb5f600f23a31dca190a1530b06e2ea4475c6727245712f82abdd8de4c905f0d3ad13df5c7808c7ed5955477da06ceeacc8f0e0b3c63bbf197fd49106b91fd12f63effc91687a19699a1230ddd279218e6e6ea91e97aca945445010001 \\x5f18cad75f532b2ff8bfe28c19f70bbff68c70fb5ac767e7e8544e114edb4d5f40cb1059981ae77bb289a8bf7dd576a2b0f18ed37be7c8e306e519b2b6d06102 1663499057000000 1664103857000000 1727175857000000 1821783857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-380 \\xac335698036ca743c7c01e74ca7bb3afa3f1f1855a90d5b0ff6df34f92fb81473e87169c28652599ee5e9e24a69e865cef203c0f7068ac1d1a1dc7359b660dab 1 0 \\x000000010000000000800003ec9e8154d090bd2124f08c3121d4db65685e46bf27a812e82ff17de72b156b6e6d920197654c5b405a4b18007f3ddfeb1ad93a647efdb65402bd7a537764b07519dbcc9b0d73a725c94fa972ca68790da78f4ab6f683ed75cb0548a2e680adf3b822bad57d4f5697a3da16f25719fe31881da85783bba6a4413994b1d6b33103010001 \\x125cb8b2e37ed378b0d3a8709d883e90b037f8479c73e87aebe7df6b8ea94a1b758e8da36ddd8b35077d98eb51e459db7d5e45b1e26260eae5472c1b18f0ba06 1676193557000000 1676798357000000 1739870357000000 1834478357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-381 \\xad532c262394e8bd447b612405e094835f2e541d0173f0ed34b836ce390662006675b88a4266b59c48cbd2377db7ce72f0288bc5f8732f16c09c0f3b9ea66735 1 0 \\x000000010000000000800003c82acb80f84a47b2a2653319767936577f1fc88ba6b368e67383bf4cd917352bd04d91d0c3fb75ac239ea846458c409cd711d78752705d235a61aa65c450f9ebf8adf1a72c8ec8b7cdf5196719c373cf855f35f9583fe873543f385e23cdbb94a8660269dd36a178e0e1a04a7723dd90623b3c419597ede3203a4dc5708c60c7010001 \\xa04f60dd7c97a0126e906abd8ea39d279afffd620f920be553ac54ebe1cad406e93f204083e0c265c7a17ec0b6bd572c34e5636bd51f96910ceb4a682e357807 1681029557000000 1681634357000000 1744706357000000 1839314357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-382 \\xad53fc7bf8a92608ade67365fa61164e22e057eb8fa33cd790a0a072d199c7166128029c20757eed0b3758b98dfe84ba1084c4db76299d46cb71256e2baaeecb 1 0 \\x000000010000000000800003bd99121cbe07059b0b632d54200d412f742d4aa3d62ce5d05772207a2eee10cb9c3d14f59c21bacab68169992f40318c024cabced90738f404e788c59fe84e2ba1664243b31fea8d1a27603289f2abecea3881c60545a33d2797a27b9393cd59b217cb17a4e8643fff4819a00d7ecd72ac2463c5c4d0db0bef835b3934edb967010001 \\x5c39e6d6fd33f38fecba082afc6f4fcaba0b068e29d4cd1e1b3e37984ffadbb15b7d95fc1c3e1f2e2014903da6c3e76c9000b76529e8714a3b3f5b98d2a44c03 1679820557000000 1680425357000000 1743497357000000 1838105357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-383 \\xb21f58c2c8ed7faa719a922662336eaa2ab0e8ea16e5de9b778e19fc22305302e56bb2125be184443c4e8bca9edc6618668f27c7a1cb2999ec570dd2c095a44f 1 0 \\x000000010000000000800003c60e4996ed9db3c63e520a8e4b7b17d3b38bcaaad48a8e6cba6db656b211964c9242bf9ca1cf442179cbe4cf95d130e5c47e7d351ccb0b442f150fcce07081e371d85e5a27d11bb0cc70862b4ad4b28f9202ef641f29a187e4dfc32182cf7de86794f0f7934855b3b2ab1707002c513a97b77d17ab20619442cf7e969696c2a7010001 \\x415254fde92ac7c13086b117b9409e32a0e438cf9583ec24d8e93941a36e9c07f65fc7434ae3c83b9e6cc14f6dbfb0091e1be7cf82a5b665f5b335a10cd4760e 1671357557000000 1671962357000000 1735034357000000 1829642357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-384 \\xb3af86df55ba5156c00a4ad350afac998e994d7d53f294917984952b312ed299927c54b4b4a5b6de4c27e9822971467abdcb93bb1074fde8e90d459c6c3c477e 1 0 \\x000000010000000000800003aab50c0977de9b4c101a1c9d6a4cea44c2007d22236e55b4be4f5c94d0d6317381a7fd02fa8f7d85171cf3375b9f6a94f581a2a8ff1ad828fc4e35417fef680456555a2bfd4493a6c0c4a3499030e9552a1fc220c66e0b27524db246c8c21ad59d4b5ade9d1ee620d8b688597e9af3abcdb35988b0e878bb2d9807148caa8a7d010001 \\xff1bcf971bc4c087239fa55f12861dc18607031e694b72d535757f139b259f1b2c293f3619ea751bae316ae309aed61e8229651fbce0e8b8651afe2fa7c1c601 1686470057000000 1687074857000000 1750146857000000 1844754857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-385 \\xb3ef859797c8a66fdd3436e175b9ce0b8e1c05ca5450949c2039a6ee6406e491d80d95252f3054e6ebf5b0ed1b43ed4946dae49fad05d499c8ca2ecb3068a3b6 1 0 \\x000000010000000000800003d371d11b53f2ad463fb84855faeb6a84a4a075a6ffe4f1848602edd2dfbaa95b21abdd7bf6e94830c3ba8241f11eef88e642c20b4c9e42e2def78852bf30527456a5fe51834a4aeca6aa3592f54a236589f2fbf467e064111ee1bc0d486014d3e8ea462ab5dcea51fb1c0edb25d467ed4d0b483a64cd373d3e4a10e4bf9dba0b010001 \\xae21cf4d45eee405da4a7bf888fc059a2a77f7181676643298bc92c277713dce8cf336880414f4bbbe086ac324148db745866cc61e0f25e8c5b798aaa0f77e09 1684052057000000 1684656857000000 1747728857000000 1842336857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-386 \\xb4e30c9156ef13dec41ba9cad3daa4e6671f254a12846e4a84b5df47ce9d1f12d0c95f14a79965c1c9c01f2321b90e1ce7523ea0334724b5e9df955712c917a9 1 0 \\x000000010000000000800003aa5834b2610d0b4c576c41db88cf8831f4509d49d253bd66d1055768a4dfedcc9b63327618a0a5ef63fff93a36901dd704c3ac130420b2e7785782a6abfe4f01342ac6cbd2c2c75d2dec5170b837a6bc9954cdeebaca428b156b2251e0a7d6b5d4ec3f2a6e4563d3925cacf2084cde3682c7e69ca258a96362a30b02ba2597e3010001 \\xf949fb870490a8418248d2748f8bfd736b404947da672918269b2761fddb42a7b2e20e09e4a9e3956d1efcb94c04a98255ddb831e1d97210b34b00b104f73c03 1664708057000000 1665312857000000 1728384857000000 1822992857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-387 \\xb7ab71fdb9222d62af8a35d4a151d88d77165adb546ef0234d625742ce1ac818a3b4091b9e9fce467af28e27d0e5c0e2fd0bdfeed3d218c96747773055016d75 1 0 \\x000000010000000000800003a8bb5ec8e1794c3cadbe5944d13c95b4cc61e4553d79cf9a441db4a343cd5ead2ff901676fa743be546e9e8b6944721564d299ed74525ff64d0ba2e2ef86693d5179aad4046ff851078668024be0434dc35876ae97fb9e64c0d4a1b2f0496f8d347ed3cf956e79068c9d690d9f621d05b3b350a089b7e3c2b379e8632fbd6fff010001 \\x32c535cc227cafb16354aa38812ff0c6030e1e086bdf92aec6f0739b9160f17a3d640aeeb5e0b7c9a0349dd1f45d1b7290fb60fa72616ebe194e28f43622fb06 1671962057000000 1672566857000000 1735638857000000 1830246857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-388 \\xba7f5828ac10adf2a1ef207693aeeb43f7ff3e2133986a1e1b96c781f669a8095a1e088e6a6acb46a00fde3e6369dabc0aad7c50d11b16c77d3d1c8c79b163c4 1 0 \\x000000010000000000800003adf44612b16961e2f2bfccbe8c54ddd8a2d5644d426fe435e80872bf8500b08a2128315385530c8717fbd0e88a528a8723a48b94cd34924437514ee36e7593ac06f6aea4f1203a7aecbdb9e9c012b29d9b3ab2164aafc9b699b345707263f66262911173cf0d1ef2a956a51a6883687bcc6b1173f194aa07290d4570ec86e45f010001 \\x765fd159d9940940b536d13ffa627ca40d0d8fba3ee0fd9293dabffabba99c7d4f61a40314f08d0a5958bd6319000e8cfa3976b28390746d1fa6ca31fbaf5900 1671357557000000 1671962357000000 1735034357000000 1829642357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-389 \\xbdbffa2bbb8e7476723109f2c1253b224c0ab6215485b8466e515521746bdfdf63a2d3093aee3d7930424eddcd95a6f1cce531764b349227ab78ae780dd276ef 1 0 \\x000000010000000000800003bf8b1f26732c54ed37ee5d7d339ec2e9c493f1941753d110a8f8e8f03c294f1dd7dec1d1025aa90db4f331e06cda37bffcd3e0425aea13ed6675423c551a37d94bb8ac1bc86c3da0b0f05ff8463d1f61e898d4f1533bfb851653b4cddf2968b958bfdd4c6bb95fb5c0ec08abdbfb51737cf282c17c1f6f3b00320bcec03f4edd010001 \\xe0ca4551f9595ffe6b4b6284cbc7f3fabe8e25089c6d0d821370010df7bfc8e782f98ea0cfa7157f33b08b1cdad4c4897db73dabff1880b967f6a3f9a470820a 1683447557000000 1684052357000000 1747124357000000 1841732357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-390 \\xc157316d9919a2ce878f689fbc9e36edc28b15e7d273cf235c1d9425fe193fcdb4a242a938762321cdf6e832572e36bfab9cda27f991b20daba3ec852bed42a2 1 0 \\x000000010000000000800003c8a0cbf59a4a03c89ac20e286881e8292c053c6c31076e14bd3ba59b42126774d265a2fa274d5d0d6dd0d393725710ef56ba84973dc92b306f149b66cf55ae097dc8270ed3c0167161e8c4f17b178753e32a570d17bb7b9841fbba40df467e692b47c0cb3d06761b905f1a9ba8dba247c345ed17ecf6bf5b94a825d900c9331d010001 \\xf22f785bf5c8385441fd9844f8a30099e66a731b312b18dccb6a1b532e267d2f0430ffc600fd5b614891ff7bcfa9431fcd282e13c9429f4ed0b81a708d2e3d02 1659267557000000 1659872357000000 1722944357000000 1817552357000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-391 \\xc113f8b17a734b79558ca7f10a72bae98889c6139fda806342cb8a5484fd3fa9167e4cc3627d44f54211847aaca0bf414027ff28d843a4b3e87e06cc8952a169 1 0 \\x000000010000000000800003ae944366efc56f0077989338da616b11d0d75d8b1cbed8929f4a3f8868d76ae03593197030414b51cd332bf029395853fb3095633493902a47914af19c86f497cdc8f691de1add817582bfbc80a9b1cf4cf47a8c7ceea963498fa70c96f84dfde694f80975d1d1f5a1670bdb47c7dd06ea42b5ad2fe995e164b274060a1df13b010001 \\xa18e6715b6bae777ae1cbe4ec8f097087a41d9cfd48ef626bd6fbeb17defd003f3c513a8ba7ad392686c59e18f39fed8a817489286281857c644c3841f90a701 1658058557000000 1658663357000000 1721735357000000 1816343357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-392 \\xc2eb1cb80f44390c898cf80ada3e3523b5e4d28c2f21fbc9d525f45ed5bddf80caac6abc6a4bd2dc2d75c2dec012b23e8dfd354fd35775c70dcf58ded5a7e3f7 1 0 \\x000000010000000000800003df524974ffb20937e0673db6415acca015d9726e86d5f7b7add5e12b5f8330afec78449d14b28ce6e46e6307b1d875ed458896a4724fdc9b0fde1732deba0d7b7abdf4ba704b52d7896eba536bac3f14e73b2b7c108eb5a673bafd251e2a9aac55969c5443dfd819b91922c9c6f17228e64e7f2aa82ca39b8b34a0032f2d0445010001 \\xea0f751d1c5ae4145b4b190a44b6c1682ac3b5f6d069ea5967dc4ba553720fd394fcce3b8e5203ec7adf8beaa01b5e702076f8a97d17c12079a50d0148cb4b0f 1664708057000000 1665312857000000 1728384857000000 1822992857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-393 \\xc56bdd81cfe56043a3d6e32c6c012acbd4ee2318f8df55f2e783efa1d679e074821f6215807982e25f6a28c827b9ab5f1dca4e207810854ab3663f9412342404 1 0 \\x000000010000000000800003cc6460e01cbe5d7abd7ac9be42c3cf946d96f1c6add77ec05e0b086bf900e1e1b15aa288d82871e2c17b046a593680e9b03525f589b0e46410657703bcca7a5173d4d7b8a44b1b81edb14b97b6c11e2e73f491530270fae766cf2ff47e1ee1f1933ffe0888b02c880d8a1b2fd2201ca055a0563eff75d681c3aa327313cdda6b010001 \\xc103456c2b09ae6ae5c1e4b7b87587a6173d4db0ce4977bafea15982271b4c3c9e4f35e1cb0dc7b7ece9824dc64087b8ef3236db3dbf8e26a38a41d794015203 1659872057000000 1660476857000000 1723548857000000 1818156857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-394 \\xc6c3f337dbd34255cdfb0190bbb74cbc91781a0724a4291a741fd0fd31192832394ffacfeda32c065b19ee0de0a4375f2a9174dc0d2794faeb9c389a5823a0a7 1 0 \\x000000010000000000800003cfd094dc2b6fb7fd929ef6335962ff05646282a3d53f972d9f7494a07db789dcdb7668fe90a5a2ab57c5daff6a15dcf6df35c29abf72de92e6d941af1f640188444d96cfbe22b3b8a6cbc105d0df242af5a1c7e5e45bbb15605ad5ef3b2dca5e426c0bb3853fb27410493a17b2fddbb603ca1b2f45e7e3bafd85c275aa51a429010001 \\xdce95a50cc853d8249b7ea2767f4612d59e3d84739f7aa95f19838d5c7f93db89148ff60a99ea322640d7c744e97d5914e6ea80c18eb43133f02d0f40a36d409 1679820557000000 1680425357000000 1743497357000000 1838105357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-395 \\xc9db6814520c028bb27df5f129e06aae22f71928d7991bb7809c27ad8a6349a06e25ec1381841af7cb5b000d6a15fa8b5eee4a9981fb1ac55ce9c8c648b375af 1 0 \\x000000010000000000800003c9aad0fef22b826ddd7ada4335d4bc9bc7745a4e27ff651a6b913400bf360a35c33db23dd3f8809132d01a6e8f843ca6f2d48d420214290e9dd338f4bac99dee92c9ea4e44f60ac28afbe2615709a1fbe2cf1042dc071a5f467031e6bd2eb94c1b4b33d882a3f4baf8d21dbb9571ea7fae9ef4a86b33306417dc9e4ed2103033010001 \\xf297c28a425a29ba8a87bd79c0ffd7a5d1618633552a3001bdd787aa08a35e65ae492e57b2a385c7434fb7c9c42df8f1dec4b0e3dd59b12ed9501c835387c705 1687074557000000 1687679357000000 1750751357000000 1845359357000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-396 \\xca4fd6174c63e4e64dde563a10969ead6e5005a26bf83dae1d352d4287eff225fb847ed0a38c4fb7e992bbdec86c8720087a37ba3142962babef98ff5b633650 1 0 \\x000000010000000000800003a35810e8be692fd341dd5d47d4bad036e1ff7b6e335be8f6377cb70e2d76ecde2b75bd6c9478cf8bb0ab73f469b3e9f44ed68a1c9693e9189e44e7985884a1de6b8d4b53f44fffc43db70e5edcbc521e60325debd87d64c0c8548e85372261510578b91fdba9f36a5e1f8f22328648091a9ca9e73dc5b7ff53569403e15d68bd010001 \\xcc21d88e2f15963b44da2501182a814020b2e4c690c9dfaa4f3cec0ea70b0fabd637b9a04f334005cd580b68b1a671bd210e4ba87d4fff4714d54fc6fc4e9503 1678007057000000 1678611857000000 1741683857000000 1836291857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-397 \\xcabf2ad262e81793b5b56ef65b7a61cbe211e322f8033984661e04bfdc7cf2c52db9c2bba312b4ed1353ec9415323e7f010962a0b230b9117bcd544ddd9e8199 1 0 \\x000000010000000000800003b118481e158f4e1d37f9c1798c7dda842ad185bcc7a06d18ab2ed152a9f5b2cfb70049798216e0d1d7a3fe955de76b6903aa5d5df5b7837b69bb49520d83b5291ec4ff7b3fb88804739019421aa577e5a318bf541bf4707817a25d2037a6953c86c80dce5a72464d3c7c3a2ced6d533ef210f67677921ef073d6f682f8de0929010001 \\x75ef0d9511df4d2087df0fcc6a9d3092ea206f8299990a089390b2e5c064b52d51ffe15847ff39d3a8a04af7c864ddf692deba11c6bb52a9879f12c210d45a02 1657454057000000 1658058857000000 1721130857000000 1815738857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-398 \\xcb1f04be0d06577541e4434295907e3088bca5e696a3deb89f11620bc38cba30741b942a988f1451a93c052fdcde1dfbfa46a4ccb790b2e9f4af1ffe4a60160e 1 0 \\x000000010000000000800003e8a9439bd5cb6ef9904cda73b3400979e4789c70c4f62fdb51b0d8b2c77093dd6785123616dd72c47c0ca854df4be9f4861d529547383143f38e7938d08e94135f9b7c8159c2d5ae72236cb3d17e43bd79510f577384eac54b3f3a4a2498a7bbf582892484e80614f90359c8d81e9a79d57434d8152f55ba0792e74442b92709010001 \\x27a5305dda49cafff6fd159b2d06ffad83bb584ea21f5697bbece9626da745f9aec000133cbb927552828ec31b990a8c6b206410723fd071d089968a30111500 1678007057000000 1678611857000000 1741683857000000 1836291857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-399 \\xd65f4073edaa5b43666a95e05a5eca90411f83a7ebd4834a1f5c866774e776ec45fd9607d51201c9b336f1c7c19992640601ffd1379a86a57b15963f7cf05bf0 1 0 \\x000000010000000000800003b3e6060a30e267c90ca5dd82c25091bc2feba0b6a6501fa0e69dfeaa2a7a441d65bf9947ceb5d4f0a6ef824d7e26405b2e04d3de63dc043080cacdc6d3631a2a46095a19a278bfb8dd2fbad5f4cccd7aa61c923342f3cff2b6982d18e1d63b8871dc5a15358fad0cbcaa9f2481532ac984cc60ea10ad8078e70296e0a6f4d471010001 \\xcb79b9e517e902d75569a130d053bb3c3d8cbbff4b0b5eaa1468925afd9004ef9c70cf0accb72b1689578260a89da95c5eedd10002e13e4e0f66779d9b8ce700 1680425057000000 1681029857000000 1744101857000000 1838709857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-400 \\xd71b96cfdb7f2c0d00069603794218cdc0b11a064edddf62a9ddbd15f3db01aa0b55cc51c3b7d533ae25963cee4fb3c52bdabddd51aae016d5eaf5bdbe9eba5c 1 0 \\x000000010000000000800003d0612e8fb827d38d54c42cb5812aba1c77ea9e9db7bc7e18c6d392299ffd70302f04c591a50c84064a748789d8f8c9521622e2e21cea99982b21eaad38e4008f626832c798bf3fdb98604ccd2ff11ed799be8544f98d713f253eddf2414f66427d612a40b07a8ef8a139495cc00e1d76fe7705b5d639ee6fe43c86892623b7a7010001 \\x189aa6bc547bc7b307cbeccd6a30eb53da89cefb14e99135af4aff24083f56264c4043293ea9fc7a85ac2e41f32e49a5e9c2f1fdbbd29869972863b5fff14303 1682843057000000 1683447857000000 1746519857000000 1841127857000000 2 0 0 3000000 0 3000000 0 4000000 0 2000000
-401 \\xda1be67a6e5c52325b72000e7fc5d159b3839f0a18988704c1ce1be9dd49fb23981152d2ac8d0922fefa31794102dd9d2c8fafbd09f78226177ab1851803ad6f 1 0 \\x000000010000000000800003ab89ed05676b9eb95e2a83e7d64cf12bc9adad2522028802f09a9c78029c1ab11e45d4de38cfc6080d63caf55d6878dd23ee95dd84d0ca2004faa2940906804b09ef31bac87e2d2ad61a1b8ad5ae242811c9a6ba340994d8c782727444a96eca08baff9afd4f33477b0f02c3825306641738ec207091d5c562f748344262265b010001 \\xc467f977f5dd42d497bdbb00fa7f599a9bda948a4cb374d5006be4e9385639f5e674bc397f2e218fe8153abe7ab225dba4a73adce4cac6a063bb3a0792414709 1681634057000000 1682238857000000 1745310857000000 1839918857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-402 \\xdca310778dcff475e224a960615608c37f9a2b8f54756b717905be8a9fd7c378e9fa34b69cb843267ea1d7b3db836a94bee42a77e1043a60a96e4e7255c59aba 1 0 \\x000000010000000000800003f796ca07fe7ba6c34b29fb19c0c6f77bc5f4b00378e7b1fd32b0722a6ba64255635fe0e90ad63aa38ae66c062f95d8d1ba62507cdd818dd4cfc938dd2ae2b4d04607deee4a3bbb3bf25e525b91d2ef64a98749bcca9f89308f4517ac4522b62d6295a48d225eaaa70aef8389cdf58cf0af309faf11a136a7f329714fa0e04a01010001 \\xf5a0d3ef6ab8f3995d0d297c677efddfa181f45dd3a6b1d40cd57d58cd50519d2190320c7ed4337d69030ec33c61df10df867a01036a9b727c59a8429a267a04 1656849557000000 1657454357000000 1720526357000000 1815134357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-403 \\xdd43632c267744ac81e8b9ef029c6e47b4ee695ffd1572686a9569551aa642f8e6d8422937a910ae6b38271f067b76c124c5075691b41189d473520be9e0bbf9 1 0 \\x000000010000000000800003a78b395fd30d2428e257f8e20f5d96ee3ad5b089c307c6fd99f1727e4fd1ba07780a325da353e6787201cf09656babb10ac9584b3750c7313e55454df18560ac8abc2abc2b810b5bc84f51330a6b71f3acb5a947c5e589cbe293e22174a0e4d392e58c085cdd40cc14f112919c33736708d93cbe9c05994c5f4d1eb3cdcc1143010001 \\x24c5c2e53728a138bda3bb7beae5896a2eae1cc8146772f823b41bf83898e11aa9cd94e0525e4eacdcfec113bde869774559ca8804c7e1af6bf7e95889ede203 1666521557000000 1667126357000000 1730198357000000 1824806357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-404 \\xe3071f24547d35855ede8440fde7d05bc0ab4eb83734a750b2b159f58ac9f9c0c5a0c35b25c46c42d8643e4b014b51f35402c5d556e9465810bda95fc57cc5a6 1 0 \\x000000010000000000800003c2a364d54832a76940885856b4d5365f1e0e194e7565c0efb8a557ec1db78428ee60986d5301c29cf77c3db68555ba56560078c6ce7cba291c93d31b3277577669afa28057f653b685187a0364d3b727cca425d5cfdb24e8622bfeed9ac1a5a251955bb5bcda79ab1ba659b7da11a9c7fa653b3ea2e924713928d0eb171d4ed7010001 \\x1bb86b4d9c06d68b721a6fc30b8af9770f554637b6efceff50f81845811ff36804276cee31fad9acba9fdfeaa42cb18019bcb9ad1ca0e7a6cd5eaf39f31fd004 1675589057000000 1676193857000000 1739265857000000 1833873857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-405 \\xe317f35717d9bfc49787eb40c7cabd409c4431e8f66021f28a1247bfea6b0951e7ab5bf34253926cb079028a9e71c8d8db04f385a7adf6636050b3a56c2dc531 1 0 \\x000000010000000000800003cdb0e05a6b30b5d70b920af5c434e3e60122e6ebd3e627c282bbd8f912891e51c30aa0ddca2e6f549ff31607a14004f193f010265e46415eafac638c799ea25eb9bf09c60d25c8f568bd674d162e1e2b2b9cb91b5f03a0d7e5c0b9d6bbe03c039c7dc2801680f3e20359cb54302f5b80b5dfcdd403f9aeb73e81de2ca128d435010001 \\x18cad548f93e0c6815462037106973650acf86c7d96726f238a2d556246fe8ced59c17158278fa37ece287858dd43789fa44ccac4d994d7e10b9cdf45579a90b 1659872057000000 1660476857000000 1723548857000000 1818156857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-406 \\xe47b7cb7ddafa82f545a25bde64232ef2751ac084c0828548fe5a3e5856caca5e90d7818964041f1276781c262cabf4e7ec58dff47c8ac36ac6882122022a334 1 0 \\x000000010000000000800003e3b98daa01b52bc5d342b340caecee404f7b2c04e9106336e2dd1ce07d243b1bc979ae2fd7734058630fcce58982e9bc96fc6b3ee4da9ee2cd3cbcd74c8f7196073695f0e1646638eafa783cdee939f836e0a13e1076fc029ce47104751e5ede39d1b95a318f25001caff50cc788647a2c56058ccac99de52a67f1a5642e57fd010001 \\xbdf18b9c77ac5b9ea0682c64189e41ba919efd6ecdc08d35aa0c1b37e2212f861aa69b80dfd471b07554f2b4ad38e5b76a24625128a4a8836557457277afd601 1662290057000000 1662894857000000 1725966857000000 1820574857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-407 \\xe41b7ead4c186b50fa78602a9462194514b5947c83841582ea0aaf22a3532381d544059fee9128b93242076e5b42c7d05162a8638db298ea133b21aa632ee274 1 0 \\x000000010000000000800003dea1e88d56f203fcfa1a2a88425e0da1688f52317536478e1980a8aeea74f435c663b2a98084a55feb2369f062a59804c7a55bf4d07bc105136894abbf9856f3027d9809d61f6d85c67db775f4289bacb0e7322098f8fecfbb773c90d82cdfdcc84d91a9818fddcbb7105ce75f401cbf6ebd58d976b369774665728d07f5f995010001 \\x3cea61abedc877e27d9b2a1e9143c050d5f18515f2f554005419327d6581cb320af405440c5cba65b02d3fd1b0fd65cb6a373818b33db76a81bb7cbf6763f001 1659267557000000 1659872357000000 1722944357000000 1817552357000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-408 \\xe8e713ad8edad8046df31d675387ce76d59bf35f8f2922cb900907d09263b6a9ea41d2afe2ff9847b02f25177994661840710323ccca18eccfc48e24c468cd85 1 0 \\x000000010000000000800003b7b4ac14dc22ab6ae06ac748ab3fcd8fa2a95689a20f21b735d984a7ccf9de06001414a62e356d706ad15f88aff5a5a7ed37c47f18ead307f7f00559627192da102a16d5cba9fe59984abda43eadbd0ea48661ae7ef92b5a38e67fc5665b8457c20038b47eb792e7e2efdf8494c540ad3a11fa409cac56d5f62d9951241a09df010001 \\x605eeb0d8a9b1b1c904702a5f434bc8c747055c029c9eb909ac3d370fec4a260c05237851effcf182e883ab14f703ec8389a39bb42c017c2d3befeb114ff7a0f 1671962057000000 1672566857000000 1735638857000000 1830246857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-409 \\xe907b50285f1ffbbf42cc3d48646f660f25091f5db842a48d3d92deb332fe1a047d66fe18c0540ef8d06c9637d992e1b8f3b5afd9f7b093ca9ffc84c72972b32 1 0 \\x000000010000000000800003c19da293549a07895d638efac147269907990d397599675352fefc56f21857d4788aa55b4d5702a1dec2aca774eeec79a9100536139f841738eff7bfbed6dcf98f05df7ec6f98738a8d09a9556eb911f323d7696731c8a9e7dc8a7acf4302d16b78404cb66f38d1b3245db8942fdb60cb0666144516d607f9e5db709de2e8edb010001 \\x89faa312fd18952fc7011e4d61fbb161bb3cd6e19f34936d2dffa4c8a9c0be5a3872003b01fe25d58f86a8656d17ece3c6ef74725efc7ff58da99cad91269009 1676798057000000 1677402857000000 1740474857000000 1835082857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-410 \\xeaf764731f1cf22cc027571ad91b244ce24577bb20f435966d80d70494bbcf261db4568cdcd3af6a71562f8ed5742d466d78fd5ac60e1a8743c04a04f50d1aa3 1 0 \\x000000010000000000800003d4f3f0960caba5d0cd8c3c35f0c2c13a5599bf12df27975f658661f29ba6185e85e22c51f305fc8de0c16ad00611f5f515910c90d60e2a3f9e2f26956e46eea6c44b35ca86bb0bdd53c3d66475e70f97eb7bfd2ef5bff3db78f7ca7b52ad67177242f4ff17f864f8013ca842af856246c3a947274994fd44ecb9c4aca4fb8455010001 \\x7185ce8e019b12889a39335459dbc7e23b5e84427560007cac9049b5a2aebfe7ddcecaf51f26dcf2e7cfcc7a7db55bc43f1b73655adb0912f8e1f90a19600c03 1672566557000000 1673171357000000 1736243357000000 1830851357000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-411 \\xec8b2abd06630c9333bb5684ac954c0a884b18126c7ae0fb258721189076e33bf9451d1565172321c43ae0881c1c4fae5d9f9d38cd0c01aa43ca91997316b8bc 1 0 \\x000000010000000000800003d498a3d5efa41b3b2ca4552eeb96ea09511f4cb8394342c20abda7db9b78dc68fdbe163ff5ab65b6543c72d3e447600fbb09edb6d68396b343d5da067ceffcd2e55f4733b5f0e441ac993346d884cf8f53235de47a1902c4701738ab4b4a018abd8d37069281d76d6ed70317bdf1f2b52ad1a015bf290a787af8467b6996eaa9010001 \\xcd964dd656920da8ae5f432b892ea587adacbe6b8e4930bc51477edf3400bf8b05a23f0308e7735eca207e08610172dbe479a1ed72f9fe629585fadb02e7f806 1657454057000000 1658058857000000 1721130857000000 1815738857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-412 \\xed0f74b4a76d2f48f20333d267120e1ce378189d5153be4373621bd61d6677c2fb9dba2fbf40935f74d81f9fbd494d28a9f19c2f8f32367e62e9272f8cc9e3c9 1 0 \\x000000010000000000800003b709f284e354233d487df7a9615cfef4ea491f52c35e4a9a2dcc49b96942f27eb1894dd62796cf61481bf0586ac6d91e7a8b0c50278a7f16cca633650288398ea088a62282ca20ba12cc0276983162b3d2c876896f3f74e6ef690b96c2fe4f926e5c241e2e7d5443bd7f8a6bc2d12e705ae9cd62cc08e2fc5e0d26e2f1c8edd9010001 \\x031dee484bf4f8d58ebde6c1d9349e181d7eefe3499c57b83c6413718f196cb6f0ce2111dd67d7fe27e6871f4c95655e221f441b363892648b5f060c2e79190c 1659872057000000 1660476857000000 1723548857000000 1818156857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-413 \\xeefb940cc5515afcb8a76bcb0238888c7179321641170952d7babc3ea96fd762de6ed1a4b62e444531bb8604199a56a1e36b97f3eb557face8f96790abdea0b1 1 0 \\x000000010000000000800003abae4e94d3cef8b821c30855dc754811d02c83211cc08ccb0574325dff435e369709d2ea83392e6abf82be07118dad9a882ffef401ffb86902738b4a3d37d448cb6c3765011e68f7f7a48f4c446d7205b415b91c611378d600c7cc12629b7636f9c3f115af58d5ba7df9ae02932305a15674975a63195b5f016df11dd3e2677d010001 \\x2efbcb2d1a6b6f8b93d3a11f979bbd824e24347e82bc1db1711f1bcccf44b521749345b92346fda91e95b944d6a9bbd4969cdc3b86a4280c015e5986d7c35609 1684052057000000 1684656857000000 1747728857000000 1842336857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-414 \\xef8fa3e48332c7bf4aa9f13ddf8e4c11b712ec6858535ac2817eced70be31b76d6b9aeb8c5ca09db3f699e19cfd67b57cbcdcb727ec8052b4b0b8e0add4b7ac5 1 0 \\x000000010000000000800003afe2d87e60f8a7cc4a8d3d0d3ac3da1cff71fc7f0cdd62f5312b31a74a6c1422fdbf0d337e479238cb70ede72627eb5b98adcbed0fb61aeaf1dd468f8cc655a679e572ccb2855b2f808c7d8f7a5d8597d44f95f0427b907aebb72e5beb676d89ae367af192c5ddf8e9db94617c70a4866a5d171587bb7cecf9e404f902945695010001 \\xb9fa7bc7be2ce2c4c7c8f93842adf0a3a7202928ae8a51da3b27b1a361954daf42e4a8f6173ab16ab9cb4de153dbe2a7eaa6f90f6a7683f6c988b50a7bfe3c01 1667126057000000 1667730857000000 1730802857000000 1825410857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-415 \\xf1130d5405aef6e118196148aed8b97f04a6ddf5a575378e2252e55d47c2a09d188eb188cfc736cf75058d1cc4b0d1a2a3e67a5d76081dccb1e5ddac6de84f88 1 0 \\x000000010000000000800003ce8a5bc1f4f2d31a9dab65383233e3e56d4c5c13efa057b99d70f079647ae114d2c34c61000542f508992fb5adb68acf1c0a3d296530c6f1f245401fa3077bbb1895413b0cd2c18036922777c26a427e7989cd34b3274e710dd64ecac1ff5913420745a93b26928bc642739be77aa8ba5fda88fd120f3fd00d30aad35e78bb99010001 \\x0c49eb0caf527477e9baf026716d57912ac8bb6e9509a33d88260e21b35a0cb56bb868243f1f3d5449ce5545b61e5714c6e27ca8cbf1f6626f21171487fe010f 1670753057000000 1671357857000000 1734429857000000 1829037857000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-416 \\xf197bd0f9dd3e4d9623abcd9c9c1cc9fc122556bedc41ae08da74d751c5db0a4c09029ce14ffa7cd9d08168e7190fcda9a8a7d330ec1c908bd8d127629785816 1 0 \\x000000010000000000800003d6cea21e5bee50e886c14a3a89bf180d1cb2ea450803cd7053aae361288ba690a450dbb5347a4a569c50ed272dab8924c08614a7cfbae81564c5bb1aafe30e8a44c8effd84691bb4a288a417706a5fd788a210b64bbc10458d6cf069d2b5d2399569dc584755fcfd99ad62180b57a22e6e70831b15cda376c44396f77fda23d7010001 \\xa6d6b794003c17bc316b97c43340e35f8e052d693d69879c96cbe0d6340894fcca41635a31c17b35543059fdda51b3334891b5c668078f8df550cb4006adad0b 1664708057000000 1665312857000000 1728384857000000 1822992857000000 1 0 0 2000000 0 2000000 0 3000000 0 1000000
-417 \\xf103a3acc67ee08d1bb0445c21926ebb8c06ee774d8a6522772ea80b27ab8d917109e16da134b74734128f18f0f37f042ae9522529917b6f12811d81dfc09656 1 0 \\x000000010000000000800003b50f2bb02fbb9166350ad2cfa3bd3bfc130375ca5192155f05cb97055a7a096faf13707d5c6bbd4969ce33819cbb59a67f9ad1dee8f7b51732578227784d02d28af66514d9de77b9e7aa711df8241a5e7ecd6df5d749475eeeea75cc15277800788fb99dd8300cf4896904cd9dc5b8ddd1d3960022d9ca9cbaa6f25f37f73eb3010001 \\x7e1d4be83935c9a2e12c7dd913e75043ddb7f99cf2120ab8e96da97581f30911e1cd3c1f3cb4b17f744d2c97699edaaaebbf4ae5c03b7d64ab97ae12f0a55109 1681634057000000 1682238857000000 1745310857000000 1839918857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-418 \\xf34f0dbcb2d80cd2b639a0fca62e937c43355cb3fc6204a901e3863a90fa88e7a91b40dbf158f48c5e860cd7f1ab8bf4105afdbf498b6e2e12d8aa01e1503caa 1 0 \\x000000010000000000800003d3114e393add238d6cfd8e28af1db3908b4149cf549f12f6cd6fc22e901514febd1a9b81c964723069940a33e68e34deb2c1104ce6530ea91a0b1fced44918bc89cff64946615cc4c56fd9dd004130f666123e47c404f2b2bc78026b437dab753fb90ab78d923197a2d607f19e0683ad886ba02e73daf33e6f58039e633c2c41010001 \\x89bb29becd1f3747b6f8531de09577931c0c3d4e37a9180e8049bfaffbc1cce1bff39f533aff953eab9b01066da69ddab3320b1eb592f0e25aa3c84af5d0ee0a 1657454057000000 1658058857000000 1721130857000000 1815738857000000 4 0 0 3000000 0 3000000 0 4000000 0 2000000
-419 \\xf3c3ca97fef3db06864b81dbe97a7f3fd64e6becf137d911d4f8f0beeb2e82bbfca8c4c900490ea593f63875b7f84b75cdc69dc17e551ff2b652bdb85dd61d45 1 0 \\x000000010000000000800003dd07a7b42c688985bca39bdfa171e9d9c0a0f47e66d09e067f837972d6292664122bb67c3961bd70bf4ebd87c6adc06573fef9edf57ce013df4d092f9e8bb3b47c8af670005fd97bcb77da79ad5c3f0c3d135923d101aec187a6abcf1e152bd156550ebdf6c17908918f0decd9975a6ea8a8043a60aefe1ab7ecb4165774d10d010001 \\x77ce9212747c4a2a621675ba7abf44f56d893246d35805693e4c79d2615d6d5a43fd70cbdf2037428074aafb811cb1737f39a9bfb1e17b4e22d845196cba3304 1657454057000000 1658058857000000 1721130857000000 1815738857000000 0 1000000 0 1000000 0 1000000 0 1000000 0 1000000
-420 \\xf62301a0f8bb6e58833ec455509e117fd7f1a853b976d34f6c0068b0864f17df10e66eb01f519cd125e75da3d82bc687a3cb9fa37f7e3b266f20dd02dc50d741 1 0 \\x000000010000000000800003ca27dbc66b4b36b62c8ef0a8a0321970459f65eac494ad858f52bd0483a48b58560876e29a13c35518af530108d3c42896966e723b6783ac19ec35e21a389cc3590db8c9fe8073acf3f4012126dd2216ef6c9163605320c2fb5f816035dc1d842d87c5d5a5f496fa40fd4348288e9817c76b7e6bb001f32fec6ace5069922247010001 \\xc0f551c6a3cbb8aec82799ced4703a6834493264b639a6139b1cc3e5a0a5e71e551bab7985f536c99f4a44df6116900dc71f685772c62c5bff0f3bcdbd714b0c 1659267557000000 1659872357000000 1722944357000000 1817552357000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-421 \\xfa9b2642d5bb288268d0292eb4bac842bde971d62978a3bc9cb3df05b3c0ece1654cc3c285cdeedb1baac563740f6ba5fe795dce460c0b904f81e62341587c7e 1 0 \\x000000010000000000800003c006693d9d9d91f97889821373aecc49b16c3b68af86d952b105cf9b1a8f8cddec86638f7ab5edd0f8d6ec2480f3d6ca19814638168c177b380c14862ecc6f4bf7ad7c9f2c1b977c0fb8016078989adbeabaab96023bc3a359a72a9d6445736cb6950c36c108cd45ea21aad53c91eb593a343efc007de44892ed01d2d0abdfb9010001 \\x66ebb34e6d30415bc602db03e6a860eb04514bf6ac59b548ff69f12a8af6d164dfc6bf58ae09cdd7e52e45a19aee0fe07eee595636e4a7608ae2a728bfe83b0d 1671962057000000 1672566857000000 1735638857000000 1830246857000000 10 0 0 1000000 0 1000000 0 3000000 0 1000000
-422 \\xfa8f808cea3de2ed08475e719447db17e0bdffbef6c57476f8255a93f273b40cdb86c79377056b0461411317b04a941f6cc3a57a4b4993c8d3772296c2e648fa 1 0 \\x000000010000000000800003d583e5ca4104f1d47c1c61907567203f252106c403bef6c830b2a5b6e36bfbf4d240b7a346b8f84d594795bd57e56fadbdafb793695bc01b6042e05bebde45f6cf371656af2fcbf372db694f37380dcadbd0e95af873b7be8ebedc0d971453b262cc0dcebf872d095019e906bd7c74ceaff8a8063f4b373bb09116324d1f75b7010001 \\x02d27f45d003fa8658258eb30f85272a3029ce76135dd882c4894089af7aa7891fa96d2267ae5a9955d34d46d7af8590bfa2de1ddec88a1d0012f905287bdf06 1677402557000000 1678007357000000 1741079357000000 1835687357000000 8 0 0 5000000 0 2000000 0 3000000 0 4000000
-423 \\xfb7fe989bc764c57dea1010bfbbc6088d5143f60761a63b772e46ba7d3afebfbd2c3896d2fa86bdf22e8e4b78dcab36fd161db456e6217676a9af22ee41fdb21 1 0 \\x000000010000000000800003e244500770a499f598ea8c41066becd35afadc8f597fe5fd49a92b629c47331d3ed2cdfffc988eb0771fc9a42871fe24f584168e68b57eda6db2631c0f2d2f990a6cced4dc76d40a17c4b9248ce463704ffec709c062f67acb6688261520aca6a7592b9d0c6bf1e67c3277d30ad493efe03eeb974137dbeba1e42f494150cfc7010001 \\x45c3cb30049aee67b67d3c2952471c963df68f7ceca770340583ed89c2070e463616bfc8b8e680864328efb7cb2088b6b4ca46271a1be6e83dfbfca2ed832a0f 1681634057000000 1682238857000000 1745310857000000 1839918857000000 0 10000000 0 1000000 0 1000000 0 3000000 0 1000000
-424 \\xff6383b8ecf9d487195b195e9b0e28f61c9b183c3d905f2d653deb6899c79b2270689b2def088586097e2b59d6a52c5db7f0f1bd68fbdeec1db495bcd62a96f6 1 0 \\x000000010000000000800003db43ac3574e40c51ce543808216ede011031f3fe820ce81c65de7895fc1c2deb225f90a5f8c66eaf33fe42ff32df00f5c6761c69d32fc47abea8deb435304a01ec7fa51354f574786e854f74e6a7592c4952e19977b4fb0820ae2526c90d5bf1b4c320339f6620de8022bfe89e92c421c7a818fa15c10bf36d309dff921d2a9d010001 \\xee48f223dfba7579c0b547bad3608559bd3bd9d0de7fe4bb6af623e30c80586770281b93616f07a4bafc041f8450d4b868cae6861c2e98cfa84ddc265f7bcf0d 1684052057000000 1684656857000000 1747728857000000 1842336857000000 5 0 0 1000000 0 1000000 0 3000000 0 1000000
-\.
-
-
---
--- Data for Name: deposit_confirmations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposit_confirmations (master_pub, serial_id, h_contract_terms, h_extensions, h_wire, exchange_timestamp, refund_deadline, wire_deadline, amount_without_fee_val, amount_without_fee_frac, coin_pub, merchant_pub, exchange_sig, exchange_pub, master_sig) FROM stdin;
-\\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 1 \\x446d924ac3616f31c181ecfec6a3d6967a813dd128d58345c2081213684988fa3df4a7f2a607ec38a63c074eb880b1c2c48870a70d4baa39a25cf3a0dd277402 \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\x3e551a82672c154fd6890b5e98616a2357edf78351e51d163ac5974648e335ed5e772c7fa9019835bd667fd6e7e77602e9c048db589e7cf5919e8dd9c6f864de 1655640588000000 1655641486000000 1655641486000000 0 98000000 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\xf7a324cd130124c6426a996c3e7aec64f5e03cadffdd2ac03ce329b97d097d1eaff6cefefecc7ca28070d07dc630d9b926a3c7cccbc705e52365bab63b29bd06 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 \\x80034bdeff7f00001d9904bee85500006dfac4bee8550000caf9c4bee8550000b0f9c4bee8550000b4f9c4bee8550000c082c5bee85500000000000000000000
-\\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 2 \\x8777bfd11f12e9e6cc970e4ce3639e53a8e28c95dd71b1252d64f1136e7cf22ae2fe2ef65d9ba1c72a65ddb789a70181592ff5232a92d33378d25837140ad11c \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\x3e551a82672c154fd6890b5e98616a2357edf78351e51d163ac5974648e335ed5e772c7fa9019835bd667fd6e7e77602e9c048db589e7cf5919e8dd9c6f864de 1656245422000000 1655641518000000 1655641518000000 0 0 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x336f89de26b436c0cbb26d657d7fc2eee0562e74378e85c1eb16bbc61afebabb3694fa64415bbaa00f7f4805ccc7bbd151b01cf0731ac59853f9d9c6de93cf00 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 \\x80034bdeff7f00001d9904bee85500001d27c6bee85500007a26c6bee85500006026c6bee85500006426c6bee855000080fcc4bee85500000000000000000000
-\\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 3 \\x8777bfd11f12e9e6cc970e4ce3639e53a8e28c95dd71b1252d64f1136e7cf22ae2fe2ef65d9ba1c72a65ddb789a70181592ff5232a92d33378d25837140ad11c \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\x3e551a82672c154fd6890b5e98616a2357edf78351e51d163ac5974648e335ed5e772c7fa9019835bd667fd6e7e77602e9c048db589e7cf5919e8dd9c6f864de 1656245422000000 1655641518000000 1655641518000000 0 0 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x5a3e7839f76886498ed6a79645603a9d84d29827aa64f761c22f599ed26d65b2feb7186cee916026da6b52f67163f19b3b6e55b36f3eea6686b2e13226e8c409 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 \\x80034bdeff7f00001d9904bee85500002da7c6bee85500008aa6c6bee855000070a6c6bee855000074a6c6bee8550000e002c5bee85500000000000000000000
-\.
-
-
---
--- Data for Name: deposits_by_ready_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_by_ready_default (wire_deadline, shard, coin_pub, deposit_serial_id) FROM stdin;
-1655641486000000 1290768505 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 1
-1655641518000000 1290768505 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f 2
-1655641518000000 1290768505 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b 3
-\.
-
-
---
--- Data for Name: deposits_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_default (deposit_serial_id, shard, coin_pub, known_coin_id, amount_with_fee_val, amount_with_fee_frac, wallet_timestamp, exchange_timestamp, refund_deadline, wire_deadline, merchant_pub, h_contract_terms, coin_sig, wire_salt, wire_target_h_payto, done, extension_blocked, extension_details_serial_id) FROM stdin;
-1 1290768505 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 2 1 0 1655640586000000 1655640588000000 1655641486000000 1655641486000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x446d924ac3616f31c181ecfec6a3d6967a813dd128d58345c2081213684988fa3df4a7f2a607ec38a63c074eb880b1c2c48870a70d4baa39a25cf3a0dd277402 \\x0c56a9369d7efed59f505251f0e4d0618ca9fc5eb84578028d03d9283b3023343a2fc6061180cdac96859edd8986e2f24ef38b2b4a1644b4360777a0b5c5030a \\x1d58b2abc9ad337262b6c683dc44e809 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-2 1290768505 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f 13 0 1000000 1655640618000000 1656245422000000 1655641518000000 1655641518000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x8777bfd11f12e9e6cc970e4ce3639e53a8e28c95dd71b1252d64f1136e7cf22ae2fe2ef65d9ba1c72a65ddb789a70181592ff5232a92d33378d25837140ad11c \\xc45a777d798979b639fc7b302d3c7e702b68126235989bc44bc24330e7cfbe1c13058ea2b82147334a54b3638a62d33c94c0003ba4d60f8c266f9c920fb86b0b \\x1d58b2abc9ad337262b6c683dc44e809 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-3 1290768505 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b 14 0 1000000 1655640618000000 1656245422000000 1655641518000000 1655641518000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x8777bfd11f12e9e6cc970e4ce3639e53a8e28c95dd71b1252d64f1136e7cf22ae2fe2ef65d9ba1c72a65ddb789a70181592ff5232a92d33378d25837140ad11c \\xdcd355615d2bd94bf23b0685c05be006001520ac84f7c184fead78b23f67c87eed6218e8ff2aa9608df9792a811e82f8123593ea0dd6391124bc99a68bc8a706 \\x1d58b2abc9ad337262b6c683dc44e809 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c f f \N
-\.
-
-
---
--- Data for Name: deposits_for_matching_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.deposits_for_matching_default (refund_deadline, merchant_pub, coin_pub, deposit_serial_id) FROM stdin;
-1655641486000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 1
-1655641518000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f 2
-1655641518000000 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b 3
-\.
-
-
---
--- Data for Name: django_content_type; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_content_type (id, app_label, model) FROM stdin;
-1 auth permission
-2 auth group
-3 auth user
-4 contenttypes contenttype
-5 sessions session
-6 app bankaccount
-7 app talerwithdrawoperation
-8 app banktransaction
-\.
-
-
---
--- Data for Name: django_migrations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_migrations (id, app, name, applied) FROM stdin;
-1 contenttypes 0001_initial 2022-06-19 14:09:17.867501+02
-2 auth 0001_initial 2022-06-19 14:09:17.99087+02
-3 app 0001_initial 2022-06-19 14:09:18.084734+02
-4 contenttypes 0002_remove_content_type_name 2022-06-19 14:09:18.103148+02
-5 auth 0002_alter_permission_name_max_length 2022-06-19 14:09:18.115787+02
-6 auth 0003_alter_user_email_max_length 2022-06-19 14:09:18.128539+02
-7 auth 0004_alter_user_username_opts 2022-06-19 14:09:18.138399+02
-8 auth 0005_alter_user_last_login_null 2022-06-19 14:09:18.149173+02
-9 auth 0006_require_contenttypes_0002 2022-06-19 14:09:18.152537+02
-10 auth 0007_alter_validators_add_error_messages 2022-06-19 14:09:18.162986+02
-11 auth 0008_alter_user_username_max_length 2022-06-19 14:09:18.1794+02
-12 auth 0009_alter_user_last_name_max_length 2022-06-19 14:09:18.189932+02
-13 auth 0010_alter_group_name_max_length 2022-06-19 14:09:18.20326+02
-14 auth 0011_update_proxy_permissions 2022-06-19 14:09:18.216478+02
-15 auth 0012_alter_user_first_name_max_length 2022-06-19 14:09:18.226724+02
-16 sessions 0001_initial 2022-06-19 14:09:18.249227+02
-\.
-
-
---
--- Data for Name: django_session; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.django_session (session_key, session_data, expire_date) FROM stdin;
-\.
-
-
---
--- Data for Name: exchange_sign_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.exchange_sign_keys (esk_serial, exchange_pub, master_sig, valid_from, expire_sign, expire_legal) FROM stdin;
-1 \\x2323cacce95f64054a17a6b27f0c46c75a67511e2586b8be6bcc0f16d5b74a2b \\x1f77e6009d721c0307ed72dec032c0f14e13e78e404c8ac061e4446bfd934d728786ee20de096fd34943b55c4bab98d3dd059077a957c5c7a688b1d9632df705 1684669757000000 1691927357000000 1694346557000000
-2 \\x44628fe1b23ee69049e56354b0a9415248520c51fb6a8da3cde42f930315977e \\x1d27d7c1ed4300027e2de3b89dfb64e666ed7a5cfb23bebcdaa1b36c214afcd0885d47cf4dd6b9f71d269f4b4348d321ab5dcc0854c98725a7a3ebb78a979d0b 1662897857000000 1670155457000000 1672574657000000
-3 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 \\xafe3bd45c87ddaa6ea471d5a66a3a038269230ff0904d959a862bc7e0b45644d06e95ae4229fb5270d8b4c065ea45ba63a29d30630094ee1eeddf7ba10709b05 1655640557000000 1662898157000000 1665317357000000
-4 \\x0fd09e664b38194f365b1b94f10d7b325b7161596b0085faf57dc00a105f422d \\xcb54ed7c75669fa6aceb9ed05dda9a555fdf236c5bd032bf097b692591904372645a859f43271c6a61378ce4de478757f0e3670d4cc9ac77fedbe0cfaebe060d 1670155157000000 1677412757000000 1679831957000000
-5 \\xfb4430a08d5fbfdcb0e978a79515fb750c6671f7db584b80ef6e3e8873ff5979 \\xce3da1c96fa341c0a683d4e179ff7801e98215f7b9a30700e612b411cc94bea96c7975772b58879fab0d61706f31a3dac09f966f023871057123afe0230b040b 1677412457000000 1684670057000000 1687089257000000
-\.
-
-
---
--- Data for Name: extension_details_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.extension_details_default (extension_details_serial_id, extension_options) FROM stdin;
-\.
-
-
---
--- Data for Name: extensions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.extensions (extension_id, name, config) FROM stdin;
-\.
-
-
---
--- Data for Name: global_fee; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.global_fee (global_fee_serial, start_date, end_date, history_fee_val, history_fee_frac, kyc_fee_val, kyc_fee_frac, account_fee_val, account_fee_frac, purse_fee_val, purse_fee_frac, purse_timeout, kyc_timeout, history_expiration, purse_account_limit, master_sig) FROM stdin;
-1 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 0 1000000 3600000000 3600000000 31536000000000 5 \\xaaa6cbb8eab49ce0e7403fc736614adeff5f331b251ae9d3a0f0a4ca59fe8d648a4fc3c2cfd7caa14ae1f098a903f0f5c0df5673ca69ac90cab144d2ef484501
-\.
-
-
---
--- Data for Name: history_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.history_requests_default (history_request_serial_id, reserve_pub, request_timestamp, reserve_sig, history_fee_val, history_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: known_coins_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.known_coins_default (known_coin_id, denominations_serial, coin_pub, age_commitment_hash, denom_sig, remaining_val, remaining_frac) FROM stdin;
-1 57 \\xeb4a542d360b0d828e00756683f933203da76ac6ceca96d65c71a7cb99cd47a8 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000003680373aa69cddf2c313a189c8745ee5b3384df4bb4f629c6a794feecc1696a41225343da6d42bf072adb766e707dc5bcccb4fef45b43989adc0a2fc84743b5e32ffb59b58dd20b0a595426a07eaf4fbb6f05d143033d4a5b69bebad3ed25e9823d5cf2c62e3c17cde0dd803e562c2e4152aa6b35ef79374d7a8dbd5cc4d4ae3 0 0
-2 113 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000008dff217bac8235f49321bdb37c46dc3126b77ecfad5e51dc19f0af0671999baa71846e1574a27a260fec3f75a8413cd099f5a0d1fb368b409ed4385fc1d15f9be32d229ae0e888f85d7f283ba2b3dd270f66f8781e08af124d34240d3ac4e48d16828ab6dea0d7424913680be92010664caa4f32e2f20cf538dc1aa093db62cd 0 0
-11 293 \\xdfbdb7f4eeb2063c34d4eb4c120ce4f22e62586c7a4ee2d037462021ee7fff0e \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000009e548151758f039cc14439dbcde6b0fed605c7bd21bf4a66bfca15903e96d03d79f70a3f01c9a626de91a71e0164f26cb3b99253b84a0d34b9bb0287df699dcd1cde7b55dedb6974b8afd412a06bb8f5d78fbe1a37abc5443b5215ced5e0d33eba47e589a3ff0f64b339febb13067abbd5d82e0a3ecb412781f64b2ad55c2838 0 0
-4 293 \\x216e1ceff6791b0853c76f6574feb33457e465d94fad2e3fa5dafecd357f159e \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000002e83c90060ed93c83040770efe26331d73fd532cba874188181f5bf0ea167aaea33953ed83f3e848633b13f1d9ddcb78a2620e41b02c365a3fc9ebc34841c8472fd96e4bb0403807e30c8b07b6e3f36c530234435422f1a7f94d9e80caebf3fe7b81290df8f9c5baba3ef3fff2ba543090c2df1ebce607e2a24fca52b9667f4b 0 0
-5 293 \\x8e85a27e630bb9f33a419d5422b03c7f500b36e11887bb3d0fd1080e8ead7366 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000003173aa8ab44d38d4f508de4f8a06b46224f78aff14153371c9e3cd4a2f6b2f8139721031d0001ea54cf88d4bfbde940cd50bf08b5fae279506d020a6466866ad472e695acff63b09ab27cec01db5ee1c68d22d213b6188765eb3f9d71ac475f9f81445a8f1dae0ac89928d39e3fa3f7420e23bdfaeab358892f64167c3326362 0 0
-3 333 \\x42f9ca46570da62fa188ad50b68e620766b311011d21e3f267d043bf93ea5f2e \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000009d1a3a38654457722967e58280ef17a912c1f71b1461da3ae4b6ed692f67a303195b7006111d5b10625555748966fa3185975a1ac6a46b979d0a62348e2661af422aae901e00b9511cbb115aaca0b23846ddd374a3fe2ef9d76605a5e1957f4551ec1369bba2bbc42492da1bcd2d470480454b822e1eb1dbfbd95eef9de67576 0 1000000
-6 293 \\x8066b8abc93de0c8bcc9b6d5fa45657a6bd0cb51277df2a47e7cd73985177304 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x0000000100000000bb9fd8cff28210891133e72a53be54fdd6e365fd00d34e285b2707cdf644e1d2082e21f3dc71205263930b1e26054bed566ee20cf42a2ecf1702c1e6ec6ee6e09babe79bb8d3cdcb3ff8a13a91daa19a6d1024096e81c488b062120937cde0f8b68efdc92f08d9bd7b4057e58a1a872915204678fb1039dd0a6525233752adc4 0 0
-7 293 \\x56986e5ebcc14aad7895e3ac7ca5e8946305b938770685c00b1098ddb64dec12 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000000dc7cee7d915780f7638c4432e92d3d69e215c4afebc5952982927f5df8aeecb55443f01613e3a55714b759dbee7faca5229acd453b6d3dc0c5b83afbf654da756a08bff2ac883b0c919ea58f660642862b7e2554bbf955b8a16cd36e21e4551a6c912a87e9efe61830f54160fc2a37177624dd50c4432a879ee09d05ad1f69a 0 0
-13 240 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000006b5ee4344f29438ce1a2ba5f42f8341fbec25943d8541a666728fd5b2c297498514c5f6621f5422394d477f1024d2cc887653212dd83b5943b223bd8d9e2ec88d2894af4b36882be94bae11adc0991c0e8b21870a11bf80cb9ec24d7cfbf3d998be36d568213a86a2535d1025a0f34250f667b70269d9a1383f6f181bb35118d 0 0
-8 293 \\xde1b7e0ec87550a7bd3780784a5c258ab86e5c7763a481055ba556cc4fd58a41 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x000000010000000027cc6732164f250dba06d13e1f38ac4ba65c3bf0461480e1a03d957e9dfa3518275e9f403f5a0daa1cf5b47152c095875c3f3e29e689cdfe346ea276c2219bb7665b79e96378e45408df69d56ed01ad129a746e3bb8d17f9c8b640fcb3081d824a40b635f4310e1145224719cfca8cafc47192d467c40027ff366ad7075fdf50 0 0
-9 293 \\x4cac6c8dc22cb26fb6097366c1cc5c4b56fa1680b282e911c7f668b7f70996f6 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x0000000100000000c9164e5a372455a3a67ebcb51c8fd3f77bf54c9f22f75da608f44e29e2a14f6055c45abf1158fe4ddbe8cba461171afb40585595d09100319ffd2cac74fc84f5114808f06f5b73abfeb5dc464059cc0310c0c1b37d5a0562b967f6df2073215b1262373f193f8686fc48d3b46843fe7b8aac26dcde175938f9e036a92854410f 0 0
-14 240 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000005ceee14188040c64f3b3819e519470088ec7df999a0b765d4c131f0f4cd18d7aa3029ac00650010b2cd74d11bf2c511e2ecaf17ab0b3f7144a05576105d14e720ba0a707ace4dd0ac3838b0da024cf277d21607b200da8c4f86966ef8f46f1a6ff71267ac557dc80c0afafaca103e2eb86f1455b014b68d77a82e73315724d24 0 0
-10 293 \\xb6fe1e53f197e8dc3a67059e04f28009f8e490ad46b82c4f09c36b38a74bbcc1 \\x0000000000000000000000000000000000000000000000000000000000000000 \\x00000001000000006557265383718d29d688c9cc3fe5fec6551699a6ad4380008dadbfff9147bb275403610fd67a328157627ab6b2c94bd589a1ef31ebb95fada5194d7c701ce029ec03a147705e57c5aef74cfd5c8ee86e7e546d2857948a9529f5fe827573e2f6f421b3013cb11e718b999aa98189658386405e626d2426d8e4870a2060291ab0 0 0
-\.
-
-
---
--- Data for Name: merchant_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_accounts (account_serial, merchant_serial, h_wire, salt, payto_uri, active) FROM stdin;
-1 1 \\x3e551a82672c154fd6890b5e98616a2357edf78351e51d163ac5974648e335ed5e772c7fa9019835bd667fd6e7e77602e9c048db589e7cf5919e8dd9c6f864de \\x1d58b2abc9ad337262b6c683dc44e809 payto://x-taler-bank/localhost/43 t
-\.
-
-
---
--- Data for Name: merchant_contract_terms; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_contract_terms (order_serial, merchant_serial, order_id, contract_terms, h_contract_terms, creation_time, pay_deadline, refund_deadline, paid, wired, fulfillment_url, session_id, claim_token) FROM stdin;
-1 1 2022.170-00R0ZXV0JY3QP \\x7b22616d6f756e74223a22544553544b55444f533a31222c2273756d6d617279223a22666f6f222c2266756c66696c6c6d656e745f75726c223a2274616c65723a2f2f66756c66696c6c6d656e742d737563636573732f7468616e6b2b796f75222c22726566756e645f646561646c696e65223a7b22745f73223a313635353634313438367d2c22776972655f7472616e736665725f646561646c696e65223a7b22745f73223a313635353634313438367d2c2270726f6475637473223a5b5d2c22685f77697265223a22375341484e304b373547414d5a4e4d393144463947524241344442595658573341374a48543548545250424d434a37333651504e5758534346594d473336314e514e4b375a4e513757585630355445303933444e48374b57595038535833455352565736395147222c22776972655f6d6574686f64223a22782d74616c65722d62616e6b222c226f726465725f6964223a22323032322e3137302d303052305a5856304a59335150222c2274696d657374616d70223a7b22745f73223a313635353634303538362c22745f6d73223a313635353634303538363030307d2c227061795f646561646c696e65223a7b22745f73223a313635353634343138362c22745f6d73223a313635353634343138363030307d2c226d61785f776972655f666565223a22544553544b55444f533a31222c226d61785f666565223a22544553544b55444f533a31222c22776972655f6665655f616d6f7274697a6174696f6e223a312c226d65726368616e745f626173655f75726c223a22687474703a2f2f6c6f63616c686f73743a393936362f222c226d65726368616e74223a7b226e616d65223a2264656661756c74222c2261646472657373223a7b7d2c226a7572697364696374696f6e223a7b7d7d2c2265786368616e676573223a5b7b2275726c223a22687474703a2f2f6c6f63616c686f73743a383038312f222c226d61737465725f707562223a224d52454447305859565358345250595341364a4e515a3933503244444247343546334d3652425a58525334394d304a54564e3430227d5d2c2261756469746f7273223a5b5d2c226d65726368616e745f707562223a2259435652474648544337503233574a4a41463853325a48595339355631504d424e364d4233343544313836315842343936374d47222c226e6f6e6365223a2250344841415a355833483648334b51394847455a5642574545523131505337514752574331524759305956485a4b315935535130227d \\x446d924ac3616f31c181ecfec6a3d6967a813dd128d58345c2081213684988fa3df4a7f2a607ec38a63c074eb880b1c2c48870a70d4baa39a25cf3a0dd277402 1655640586000000 1655644186000000 1655641486000000 t f taler://fulfillment-success/thank+you \\x5d8ff2e8bb4568bae0b6af6fd1738112
-2 1 2022.170-03WD45ZSFFMRP \\x7b22616d6f756e74223a22544553544b55444f533a302e3032222c2273756d6d617279223a22626172222c2266756c66696c6c6d656e745f75726c223a2274616c65723a2f2f66756c66696c6c6d656e742d737563636573732f7468616e6b2b796f75222c22726566756e645f646561646c696e65223a7b22745f73223a313635353634313531387d2c22776972655f7472616e736665725f646561646c696e65223a7b22745f73223a313635353634313531387d2c2270726f6475637473223a5b5d2c22685f77697265223a22375341484e304b373547414d5a4e4d393144463947524241344442595658573341374a48543548545250424d434a37333651504e5758534346594d473336314e514e4b375a4e513757585630355445303933444e48374b57595038535833455352565736395147222c22776972655f6d6574686f64223a22782d74616c65722d62616e6b222c226f726465725f6964223a22323032322e3137302d3033574434355a5346464d5250222c2274696d657374616d70223a7b22745f73223a313635353634303631382c22745f6d73223a313635353634303631383030307d2c227061795f646561646c696e65223a7b22745f73223a313635353634343231382c22745f6d73223a313635353634343231383030307d2c226d61785f776972655f666565223a22544553544b55444f533a31222c226d61785f666565223a22544553544b55444f533a31222c22776972655f6665655f616d6f7274697a6174696f6e223a312c226d65726368616e745f626173655f75726c223a22687474703a2f2f6c6f63616c686f73743a393936362f222c226d65726368616e74223a7b226e616d65223a2264656661756c74222c2261646472657373223a7b7d2c226a7572697364696374696f6e223a7b7d7d2c2265786368616e676573223a5b7b2275726c223a22687474703a2f2f6c6f63616c686f73743a383038312f222c226d61737465725f707562223a224d52454447305859565358345250595341364a4e515a3933503244444247343546334d3652425a58525334394d304a54564e3430227d5d2c2261756469746f7273223a5b5d2c226d65726368616e745f707562223a2259435652474648544337503233574a4a41463853325a48595339355631504d424e364d4233343544313836315842343936374d47222c226e6f6e6365223a223237503646455053364637334853314e4d444433374554475959584838564d37454a5a5131475137425632425a364d4d4a4e3730227d \\x8777bfd11f12e9e6cc970e4ce3639e53a8e28c95dd71b1252d64f1136e7cf22ae2fe2ef65d9ba1c72a65ddb789a70181592ff5232a92d33378d25837140ad11c 1655640618000000 1655644218000000 1655641518000000 t f taler://fulfillment-success/thank+you \\x7c8e6bfb2d09fec33fb6e3a9ca596341
-\.
-
-
---
--- Data for Name: merchant_deposit_to_transfer; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_deposit_to_transfer (deposit_serial, coin_contribution_value_val, coin_contribution_value_frac, credit_serial, execution_time, signkey_serial, exchange_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_deposits; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_deposits (deposit_serial, order_serial, deposit_timestamp, coin_pub, exchange_url, amount_with_fee_val, amount_with_fee_frac, deposit_fee_val, deposit_fee_frac, refund_fee_val, refund_fee_frac, wire_fee_val, wire_fee_frac, signkey_serial, exchange_sig, account_serial) FROM stdin;
-1 1 1655640588000000 \\xdad90d6dc263d39fcb288d066e4391d92e8f307f934585fc104b4699147e9673 http://localhost:8081/ 1 0 0 2000000 0 1000000 0 1000000 3 \\xf7a324cd130124c6426a996c3e7aec64f5e03cadffdd2ac03ce329b97d097d1eaff6cefefecc7ca28070d07dc630d9b926a3c7cccbc705e52365bab63b29bd06 1
-2 2 1656245422000000 \\x0a938661f11ca2b6284a512cae4b1a01e5c89e9a5f9cbda49608110ae166639f http://localhost:8081/ 0 1000000 0 1000000 0 1000000 0 1000000 3 \\x336f89de26b436c0cbb26d657d7fc2eee0562e74378e85c1eb16bbc61afebabb3694fa64415bbaa00f7f4805ccc7bbd151b01cf0731ac59853f9d9c6de93cf00 1
-3 2 1656245422000000 \\x13137681cde0c2f734d8c2865b9666bede70c5630949a936b5da1b8c41baa84b http://localhost:8081/ 0 1000000 0 1000000 0 1000000 0 1000000 3 \\x5a3e7839f76886498ed6a79645603a9d84d29827aa64f761c22f599ed26d65b2feb7186cee916026da6b52f67163f19b3b6e55b36f3eea6686b2e13226e8c409 1
-\.
-
-
---
--- Data for Name: merchant_exchange_signing_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_exchange_signing_keys (signkey_serial, master_pub, exchange_pub, start_date, expire_date, end_date, master_sig) FROM stdin;
-1 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\x2323cacce95f64054a17a6b27f0c46c75a67511e2586b8be6bcc0f16d5b74a2b 1684669757000000 1691927357000000 1694346557000000 \\x1f77e6009d721c0307ed72dec032c0f14e13e78e404c8ac061e4446bfd934d728786ee20de096fd34943b55c4bab98d3dd059077a957c5c7a688b1d9632df705
-2 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\x44628fe1b23ee69049e56354b0a9415248520c51fb6a8da3cde42f930315977e 1662897857000000 1670155457000000 1672574657000000 \\x1d27d7c1ed4300027e2de3b89dfb64e666ed7a5cfb23bebcdaa1b36c214afcd0885d47cf4dd6b9f71d269f4b4348d321ab5dcc0854c98725a7a3ebb78a979d0b
-3 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\x85c532e0499b11517a10665c66301831599632bbd934c51a829365d590a774a7 1655640557000000 1662898157000000 1665317357000000 \\xafe3bd45c87ddaa6ea471d5a66a3a038269230ff0904d959a862bc7e0b45644d06e95ae4229fb5270d8b4c065ea45ba63a29d30630094ee1eeddf7ba10709b05
-4 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\x0fd09e664b38194f365b1b94f10d7b325b7161596b0085faf57dc00a105f422d 1670155157000000 1677412757000000 1679831957000000 \\xcb54ed7c75669fa6aceb9ed05dda9a555fdf236c5bd032bf097b692591904372645a859f43271c6a61378ce4de478757f0e3670d4cc9ac77fedbe0cfaebe060d
-5 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\xfb4430a08d5fbfdcb0e978a79515fb750c6671f7db584b80ef6e3e8873ff5979 1677412457000000 1684670057000000 1687089257000000 \\xce3da1c96fa341c0a683d4e179ff7801e98215f7b9a30700e612b411cc94bea96c7975772b58879fab0d61706f31a3dac09f966f023871057123afe0230b040b
-\.
-
-
---
--- Data for Name: merchant_exchange_wire_fees; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_exchange_wire_fees (wirefee_serial, master_pub, h_wire_method, start_date, end_date, wire_fee_val, wire_fee_frac, closing_fee_val, closing_fee_frac, wad_fee_val, wad_fee_frac, master_sig) FROM stdin;
-1 \\xa61cd803bede7a4c5bd951a55bfd23b09ad5c08578e86c2ffdc6489a025add48 \\xf9099467bd884e86871559a62a7f23b6e876bf084a30371891b5129ce4440d3cbe27afe387d39b2ce8d9625abd388517c81bfc8da9f2e0f8c9471bff65a802b2 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 \\x2cc20db7f38de122d90c286fe3954a28cd9d942dd6d849a80838d71c1be3f5ce1325a61fd7b576f139a4ca72b2407922e0dc87cda6e48b58be95c3a77e95be0b
-\.
-
-
---
--- Data for Name: merchant_instances; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_instances (merchant_serial, merchant_pub, auth_hash, auth_salt, merchant_id, merchant_name, address, jurisdiction, default_max_deposit_fee_val, default_max_deposit_fee_frac, default_max_wire_fee_val, default_max_wire_fee_frac, default_wire_fee_amortization, default_wire_transfer_delay, default_pay_delay, website, email, logo) FROM stdin;
-1 \\xf337883e3a61ec21f25253d1917e3eca4bb0da8ba9a8b190ad0a0c1eac8931e9 \\x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 \\x0000000000000000000000000000000000000000000000000000000000000000 default default \\x7b7d \\x7b7d 1 0 1 0 1 3600000000 3600000000 \N \N \N
-\.
-
-
---
--- Data for Name: merchant_inventory; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_inventory (product_serial, merchant_serial, product_id, description, description_i18n, unit, image, taxes, price_val, price_frac, total_stock, total_sold, total_lost, address, next_restock, minimum_age) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_inventory_locks; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_inventory_locks (product_serial, lock_uuid, total_locked, expiration) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_keys (merchant_priv, merchant_serial) FROM stdin;
-\\xa922384f62eb331b9b0f2567e4144a77be94542afcb80f374a2297a543d63e99 1
-\.
-
-
---
--- Data for Name: merchant_kyc; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_kyc (kyc_serial_id, kyc_timestamp, kyc_ok, exchange_sig, exchange_pub, exchange_kyc_serial, account_serial, exchange_url) FROM stdin;
-1 1655640588000000 f \N \N 2 1 http://localhost:8081/
-\.
-
-
---
--- Data for Name: merchant_order_locks; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_order_locks (product_serial, total_locked, order_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_orders; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_orders (order_serial, merchant_serial, order_id, claim_token, h_post_data, pay_deadline, creation_time, contract_terms) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_refund_proofs; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_refund_proofs (refund_serial, exchange_sig, signkey_serial) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_refunds; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_refunds (refund_serial, order_serial, rtransaction_id, refund_timestamp, coin_pub, reason, refund_amount_val, refund_amount_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_pickup_signatures; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_pickup_signatures (pickup_serial, coin_offset, blind_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_pickups; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_pickups (pickup_serial, tip_serial, pickup_id, amount_val, amount_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_reserve_keys; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_reserve_keys (reserve_serial, reserve_priv, exchange_url, payto_uri) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tip_reserves; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tip_reserves (reserve_serial, reserve_pub, merchant_serial, creation_time, expiration, merchant_initial_balance_val, merchant_initial_balance_frac, exchange_initial_balance_val, exchange_initial_balance_frac, tips_committed_val, tips_committed_frac, tips_picked_up_val, tips_picked_up_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_tips; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_tips (tip_serial, reserve_serial, tip_id, justification, next_url, expiration, amount_val, amount_frac, picked_up_val, picked_up_frac, was_picked_up) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfer_signatures; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfer_signatures (credit_serial, signkey_serial, wire_fee_val, wire_fee_frac, credit_amount_val, credit_amount_frac, execution_time, exchange_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfer_to_coin; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfer_to_coin (deposit_serial, credit_serial, offset_in_exchange_list, exchange_deposit_value_val, exchange_deposit_value_frac, exchange_deposit_fee_val, exchange_deposit_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: merchant_transfers; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.merchant_transfers (credit_serial, exchange_url, wtid, credit_amount_val, credit_amount_frac, account_serial, verified, confirmed) FROM stdin;
-\.
-
-
---
--- Data for Name: partner_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.partner_accounts (payto_uri, partner_serial_id, partner_master_sig, last_seen) FROM stdin;
-\.
-
-
---
--- Data for Name: partners; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.partners (partner_serial_id, partner_master_pub, start_date, end_date, next_wad, wad_frequency, wad_fee_val, wad_fee_frac, master_sig, partner_base_url) FROM stdin;
-\.
-
-
---
--- Data for Name: prewire_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.prewire_default (prewire_uuid, wire_method, finished, failed, buf) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_actions; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_actions (purse_pub, action_date, partner_serial_id) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_deposits_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_deposits_default (purse_deposit_serial_id, partner_serial_id, purse_pub, coin_pub, amount_with_fee_val, amount_with_fee_frac, coin_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_merges_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_merges_default (purse_merge_request_serial_id, partner_serial_id, reserve_pub, purse_pub, merge_sig, merge_timestamp) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_refunds_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_refunds_default (purse_refunds_serial_id, purse_pub) FROM stdin;
-\.
-
-
---
--- Data for Name: purse_requests_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.purse_requests_default (purse_requests_serial_id, purse_pub, merge_pub, purse_creation, purse_expiration, h_contract_terms, age_limit, flags, refunded, finished, in_reserve_quota, amount_with_fee_val, amount_with_fee_frac, purse_fee_val, purse_fee_frac, balance_val, balance_frac, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: recoup_by_reserve_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_by_reserve_default (reserve_out_serial_id, coin_pub) FROM stdin;
-2 \\xeb4a542d360b0d828e00756683f933203da76ac6ceca96d65c71a7cb99cd47a8
-\.
-
-
---
--- Data for Name: recoup_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_default (recoup_uuid, coin_pub, coin_sig, coin_blind, amount_val, amount_frac, recoup_timestamp, reserve_out_serial_id) FROM stdin;
-1 \\xeb4a542d360b0d828e00756683f933203da76ac6ceca96d65c71a7cb99cd47a8 \\x2521b2624377d34720dc6b7cf246eee9fea257dc3c5566018f3497c0787fd1abadfc41c2d5e345c9e43f2821f0957f9f495887f5b27f46560bc571e22584a309 \\x65aecb66245101c2f805c3f9b5d9d1ad09e0070cb87c25b248a28f43f50a02f3 2 0 1655640584000000 2
-\.
-
-
---
--- Data for Name: recoup_refresh_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.recoup_refresh_default (recoup_refresh_uuid, coin_pub, known_coin_id, coin_sig, coin_blind, amount_val, amount_frac, recoup_timestamp, rrc_serial) FROM stdin;
-1 \\x216e1ceff6791b0853c76f6574feb33457e465d94fad2e3fa5dafecd357f159e 4 \\xf517e00abbd57c646f62eeb630c204269d6908791180a0d4123e52272de58140055e305abf912bad557369ca785a48fec2342de74e2d898b41ceb5e05726de03 \\x1a555715db8f096f2279a4dcb8e32b8a470975c8eab7d6d9dbf650cdaaa8cc57 0 10000000 1656245408000000 2
-2 \\x8e85a27e630bb9f33a419d5422b03c7f500b36e11887bb3d0fd1080e8ead7366 5 \\x9a86a85fbdd0c0696d4545425f1515494b44acee9f592313f61109c608c55ca4488da012f9039ec2913b69735df95c81f99d43bf73de97fa54e3d88c37c4050f \\x175189bff5a66b6c427dd35c7b5972a08e1801222558354b8afb1ac2c429988d 0 10000000 1656245408000000 6
-3 \\x8066b8abc93de0c8bcc9b6d5fa45657a6bd0cb51277df2a47e7cd73985177304 6 \\x90f8f00273023b1001f2be74b99afc1a1868a515d210ff3a6b418a4251261c24d5888d166c00fa74d04a22d712c039fb5c04df465a663d20f0831dc96e97ba0f \\x7444d17531cc85ac7519faca8a9c509867860be6a909da0157a4e0a77e35fd93 0 10000000 1656245408000000 9
-4 \\x56986e5ebcc14aad7895e3ac7ca5e8946305b938770685c00b1098ddb64dec12 7 \\x71580af5b7b43f1f93e07ce7c3ef71f529507edb0466d7e06205d81a84da54eefee40ea7746328ffa78128a326c1574f95fa6dcf6e446d1bb137f9652e17270d \\x9f45ee93397e518ffecc6d193d71127662516ca246097f217707a9d563f456d0 0 10000000 1656245408000000 8
-5 \\xde1b7e0ec87550a7bd3780784a5c258ab86e5c7763a481055ba556cc4fd58a41 8 \\x8e9b8c1c3709d1ebec240056e63711fd449e9b1c94d8dd051afbbf54801220c2233afe95b39329d0ac2cfa9a61e77073466a9cd280ba1d74f503c5fe92e81208 \\x48b5c8e5d4ec038a64ea3c7efd4cd8ec266275a220f8b1c615d0c1d5d1919ada 0 10000000 1656245408000000 5
-6 \\x4cac6c8dc22cb26fb6097366c1cc5c4b56fa1680b282e911c7f668b7f70996f6 9 \\x385b50f47ddf8737eb099a9e811bd21e64f6c9a465e4af59a66732c3cbd6d26f0b00e28fbd645bdd069d21f70857f1191e42def4d587883872c9d9ce82507e0d \\x1f4deb49bb037a23681b5346fc1097d2bfd9c605cf5e48f4703e8a342fda57fa 0 10000000 1656245408000000 7
-7 \\xb6fe1e53f197e8dc3a67059e04f28009f8e490ad46b82c4f09c36b38a74bbcc1 10 \\x7e3fc256c073712033744677476e5cfee9d0fea9255edce2dc162fc9841b8307a0ba0f163e9e1fe172b6b2fa011ce30ce110586a4d3d1a0bd292fed553c31d01 \\x1f71992140e6281c003c6edc99ce9cf5f9b37050f6769ded3adde3adadd92d5a 0 10000000 1656245408000000 4
-8 \\xdfbdb7f4eeb2063c34d4eb4c120ce4f22e62586c7a4ee2d037462021ee7fff0e 11 \\x7bc3498da3e1ff05830bdf12d2540404713941c61a9bc25de62a7a0f7e30ce76d0f2ab07419c49d8273242e21fbe9490ed7fa27f3335129666f6bbdad25f7102 \\xa66876c3986f9bf4a46bd248594af960d8b9e80c1154a0b9536c1ee8bb2332aa 0 10000000 1656245408000000 3
-\.
-
-
---
--- Data for Name: refresh_commitments_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_commitments_default (melt_serial_id, rc, old_coin_pub, old_coin_sig, amount_with_fee_val, amount_with_fee_frac, noreveal_index) FROM stdin;
-1 \\xa68fc56f73ead457a1dd1debd09bd04e45271d4eba3af281c1c911efbf971efd289b07934b46d6e0d5945345692c2b44870ecbfa896b548d17b65e1722b4ff89 \\x42f9ca46570da62fa188ad50b68e620766b311011d21e3f267d043bf93ea5f2e \\x7e9ab139da5f3f97f19700a9e755f5ba2d82c56937bcf738cd62c34b09ca95ee39289131edd495822d051027eb06f311284aba08e7ab27b0c27abd64d62ea309 5 0 1
-2 \\xee546e2d4877e7c9b83fc1c79a92cf5e9734cf2a6b9af0903c10b6fc9bb5036742583662c4dc7654eec77b6582ee75002bba4ac5177ebc329ccf6946f72a20ce \\x42f9ca46570da62fa188ad50b68e620766b311011d21e3f267d043bf93ea5f2e \\xc1d35e6f45f2ac62b79dfcbabe0e1f2f6ebf1a24855a67ba422097ff93e120bd31119cdb334df56832d72cf8b82abb1afc6e6ef8cbb9fbd8079c039f4f3fac07 0 79000000 2
-\.
-
-
---
--- Data for Name: refresh_revealed_coins_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_revealed_coins_default (rrc_serial, melt_serial_id, freshcoin_index, link_sig, denominations_serial, coin_ev, h_coin_ev, ev_sig, ewv) FROM stdin;
-1 1 0 \\x8d000a1e71479ab24ee4860d24a42ab49976c413881cbe64e9a33c94254c168ded5f8ae61206bd93e91216ab121edaed8480c5bc835c44e87f5eabb0a8c74c05 331 \\x0000000100000100c99a00e9495fbb74f8eca72cffffd6797811cc655360f8b58a03e91f49b65c3f98df7190683c9352442ce64a0000293e853fef42257420ea70f5f6f7872e5f9118c35c2f49b5f6ae2bbdb1fc23541b2be1e6d1e0ebbe2d390cad510ef203cb2a2532ebbe8ca69aa0782fcd26607678104e67391d8e9e50dc3fcd5bf4d3684fb5 \\x8e156c466618ba4c82ad3c22e2abfba299858933109bf2272932b770600ca71eebe6d33be59cf738063207a111c4a773fe94a0948a01d300954ea094ea3ff9d9 \\x0000000100000001110e9fed0626426bc537ef9be0e16aa1553ce8336b915bcacabcfb439d9f97c8fcbffdfdfed65e8879ab34e91acb23edc01dfe0cf6cb3d9c0adb9b1b2c323033b2250df95a1a3256fa43e39c72b58f8c3adeda603db3cbf9a625fcc91186f26c96e9ab705f98b6ed168f597cf27774ffadbc8bbcf7ffedcb2a768fec3cd63dc4 \\x0000000100010000
-2 1 1 \\x9d040d892bfa3bbb0031531ce35c8257d2d7e199e5d351dd84eb9858d197b04afc4c9349394cd9e27aa72c9bb30589737aec1e979f11a2c20025091cab53e008 293 \\x0000000100000100a7eca7d57442aedeb3d5916074e8bf7f0d33ca4337ddedf36a5bf35e5a596141ddc7884ea2b53f80831348abe821c37c64650b4d722d4b2a87bdefbc266ecf832769c7f58356018849b8ed524b149a0656365b546ae2d47584deb7f59b13c36ea8ad49cb21270ec7086d215e4b48e0715fc760c7a5e750e97124a706ae4d7079 \\x2d5fd330f683648b11aad89eb4cf84ef228fd62bdef9b9f0ab608e40f3f1e24abd40a8263610c9d02ab13b4aee1db9bd76d60075be6143978bc4a3032699bdff \\x00000001000000015b34938b71a3f056d31d5f19677fdd866d3027203802d1d385f8b83ec0232f889b49996d095a3ce196ecc114935c5965b42333a96bc205f688ba45a88b3891dedc1b153c79399d7405dfb8b5c54690258ff701fe87fe31167b4ac5d385dbfeb0c27b944f0730619e749906bfe4437513c46247d4553fc24e39156d13a32eb4be \\x0000000100010000
-3 1 2 \\x6fbf0031c9d9107eebe4688fcd16092ef1dbbda2b5b8c94da50e5f3d170e8992c0510d8e48a55492ea9d61d5bc06f84b62355f54cba40fc2b2d9dadfc884390b 293 \\x00000001000001000b3afba4146abfc2ed9c3b42b3cd3970434a44dc055e5feb71d06beedd2307382f500f07b9244775c8b15e4610ac73039b7f490b015ed31b9162401a85c4a2a0f8c4b052bf62070c2000a9f726c32b367b1bb567038aa31598ec1cb2cbf5198b2f35c03866c73b2b40a2a3dc71942ef6c8b61ddf7cd14b78a07649123e2a0f5d \\x66a4e5aeb4ce29b77f8ad3070d715d2a3145d5d45cff5aa33ba354445b89d9dd91df9b0b6abab4fb74149e74339d591af42194584e37b8e7ffe967d436044963 \\x00000001000000016efd2203a4c4cd74b0d629d8b8dbdcbfb60066a399e72840ec2d55e1c2d9973c0ebc2e7abf7b81cc8a958c0cdba5d82b6c4f5982e1782c69fca87e58c45e557f116f7f6914ae84c208be4dd82087d9a9643fde7036ec92b18dbc5b7af7a87d52c429e4ffd9df1f2a769e87d0b66f6d24cfddf5641c32c2a623e6ecc39e301283 \\x0000000100010000
-4 1 3 \\x39977b5188e8c53d0c072b12e9fcf99c6213d679af3adcf515a71ced437b0da755429aaca7c67f39948f0ced12f8a0cf9bb4cfd0488f9f1611a85187cb6dc708 293 \\x0000000100000100b52f534e7d04034afa7f04536517cad00d62046c3148b368777603e08ad532b14eabe498f09ccaa7293202cfc5819bd7b8b2d40871b424ca33cf63a05de4d06ed6235a9907221c711e75471d43ac2dcd1cb709b7091cccbb6a3e30358d10e374bf797d250d32717e7eb6cd8ac389268be7923cca4dabe497065b57c9f83c3225 \\x459f849bd9713cf137ffb08f1fbdac20d23a727f198709ce3a657d997a2009a3038289b8ce8f3ddcf86583b7629c9df0b78662fdfc973dcd8d7916d610382e01 \\x000000010000000139ba98586e1466f99b1e59f648607be96662ede72eb6e2ced098afc66a3143a93dee804c9e0b2688bd42a1803841398aba1ab1e5ae9321f33279f98ffd90acba22ecce2eb7d7c037ebda0dc24aa7242b64256410e913e4c53accaa3d0fb929342f9bfa83e64a881c48ab5a9f13f4a25172ec6fc37a71220a66843189f63033b5 \\x0000000100010000
-5 1 4 \\x66ae107464dc9a5c1a3a876222252936699a84543e46be953f159247412151b85f5dd998b497eae318a71e27f335989ea5ab4d7203008095371c0f95fa43f30b 293 \\x00000001000001006f63c1b5a04a9db813b772eb5678d03015a23c987b75ce6b2aab96ce850e55bbed5c0886da73a578bf51db031a04e80440a4d6955fa38cba5fa1ba4391fb6d3ae6e396a3cb0906bb75d79b6e3ebd9b29ea87605c534303bf6ed4a2e89fc3f17df551e061ba8dc3867838821a7f5ae48eb1fdcd9b7c6d3b90f2c06d0a324da38b \\xea05a4cf4120e8839e16facc5b2ba4df324de04c4a0715810fd4b1e5cd30f4a66922b1438e5ca0b0827b842b53ad732037b841735d5ba803460f35f657fe88ba \\x0000000100000001c6cd4a2f2c4a350f990488048c2da8d78fdc9453e4e6a32eab83636590c119988d7f7e826f94d3b86d9f739bafafdab71e896964512d2f9eb1aa7dbbab7b7a664ce7b7122686994f408c0d1808eff80d14325f06eb06372cc14f124cfdc780b49120474ed730e33be69cd7a0bc545936c2ca3425e10ef7cbb3208a4251077363 \\x0000000100010000
-6 1 5 \\xf27353945ca6512ea37158b178475d7635af5017c34e2c85cb7f8969bc8db254dbd549a6dfae09c7d672ca202991ed750c06a9cac153601f3391dc0659dea108 293 \\x0000000100000100496e165e69525a7357850b6644ed404b8caad436eb5b6c7645ca66649af2f6388e1eaa9cedb0dfe790e1dbbc1305f051be0a315a342cf934299f375c9c962bb0610d0262e9cc4a201ed4f8598e8be9b4edd9a090b2d9f03929bd4626c5c4af651e4ef81226a02533425eda352b421846db20d24715136231cf0cdd2f5e398320 \\xb2a483fdc559cefe18ee031ae5ccae9b31f5a4813b12160056e24a42825a21702be47696c31c49e8bf6132b325053342929ad471fdee18584439ae5b193a442f \\x000000010000000167b28b489ce39eda3856a0b476f8e5319991af144db80a90ea60162e7b1d86eb9820a353237670dbff9484d1220a043e69b9166acdb869acb62145a9c8b25051cc119a77a9a913a1bd26b14ffe611f2bb87c15953aa2bbad52bc1653efc7ec7338e9b25385e66ae888e04ce5c8e65ff125f120ac9a9d838552026cc3a96d6e5c \\x0000000100010000
-7 1 6 \\xe8ae1ea31b9fcb5e7fad242456b436709e370fb8362e7f882561c346ff223b8aa47a2d50ebfc483878ce61e3843d89fa96d2ba78ac067401075485e40e87880f 293 \\x00000001000001002208c3807b4974bb08e0d72ab0798383265a92fbd8ba98e1f9e3fcd6b042d663c58e9ec23de0d9b7e449c1093aace937a83a7458772db04f0b1a271fd8d74e15550f18a64f679071f19fbd6265913e1cabc56835da3d1268e039eb414b0eb0292455cd195b9db04c958f972e137c7385bbe1404edea6a45db6c1ae92810177c0 \\x95fe170ddd36e5af11882811c913b1af0d13439b591c29b3cb7cdae7590477c317f1817c35db6adfec14244aec1a796a42fec25a4b57ebc3491562c478a5bdb4 \\x0000000100000001500f7c75e4d278546e3c4e2a4e65bac500b8292f52dabf82f7b5766160762b85fa54d52ce3286202344532846a700a62704e06cad3ab7f1308f114bfd0d51e60188a8cb269c483e56f4ab3a8ded5a74950b439802333383a2ad58a0bcc095c1e460b1514fd151b1a6f4d13c0681e626a080027183d2ba3428e746e50ea25245a \\x0000000100010000
-8 1 7 \\x2140b5db65dda22e9065c2544d1ae5d44745a6d2ddb64b25ffa0072a9e85ebb3bc5a809cce4492f836071dfea4cdae784354810e2f4b57c2fa72e3b8a8945709 293 \\x00000001000001007dd245af8af2bfd675b9c3f72435313d59965eec4a188fe04c6c3cfb153949a6ba5ec40ff0370e249922e324532791bb4bb8ffdc52290eeedb99c4e0a985e5be96198ababcc950adfee9d1197ffe2d5bc1db3455d42826fc70d52f03654eee037a54a78bcfd2146b84dab55ad6e56cea00da129be226fea1e2bea4957812a9fb \\x88137a60ee794093cfec2c724de1cff5acc7d20d6d81786b5d81defa553abbd0cbf21e7fa145a59b271444b556921de59640494008bf53d9a28baf55c8eaaef4 \\x00000001000000010537af6a6dd783c32a2cbadd84f3b3530997cfc9c79ab0679bda2bd8aace893ff5867da7968cb9a94e463242598542ac650aaab72f8f19ae02c433afbe1f3c63aad39d0cda1ec107894d41bd5088a14dc86efedb2c443ebc9eddb9fd3f83a6ebb032f781ffde7a3a00c5b2646ff916ba3a913a7fbe6a5d60e225ffec5b3cac0b \\x0000000100010000
-9 1 8 \\x94fb44cb63dde84e5836a5f5f164d1c6617dd4a62e0eca717b4b4b72144144c3e3112b275a437965cbc1c603eeb65abac71061d367f104d3104d7d3c0f711b04 293 \\x00000001000001007b49d462af6e467c7788d07aa9a79b64ba3553f6342cd122a2f0f5190f83f54f4c0ad301c4812704c422c0d3d6ec64b8e3f20d7870ae54dbd7a3934fc04bd99e72928120f71d3d26eaf831c77e5749aab170e984c0933d9bcc18f4cfbde0475c419f4e2a5951a0e5dd49d41a0f39aba93f2c81adb0d0ac024c815bbbd05e6a5b \\xec11952e0735f655db2fe096b038452f5dc129ae86c75efe5ec69e301d2215b2f9f2beefbca0b0450793bda48832e9bb0434333b19fc4cbfe7a49f7508ac6127 \\x0000000100000001196cb640d90be3ddfc57ffc2499fe2a85675cb68ac0f1957e0f87c7fac6eabca689ae798b04283901887a370df8c8944003e0968d6e9eafa40d6297a791ca331ab23aa499b70f5cfeece60c7436c6cfc7a3ed5f04e3fe226542d5d99d4f5160edfabfc165e6bcbef0f730ae055fe91317bcce5326f142740b5d649415a16e3ba \\x0000000100010000
-10 1 9 \\x830d6902d35fc0c6d7686f8c9db654c9518feefb433146e63b759afac78ff475599c59136e086d8f8b11c292f376dff4b1c4793325d0f3b3ff1f585276c5f90f 240 \\x00000001000001000977de9bf0e11eea965657c352a384697b06dc510f45a394bbfcf4cf6d430739587618f49ed7f0122fcb21f0bb43f865d5b82ac89464f40a93264d26a78c046f32675591aa85f2fb1e4f3531e7c3b4e6bcc0a77bab82000d4ac4e20ce69d9734be023f27af7208fd066050bab33dca5bf4d1737370510e8ca0524d73ceec6e44 \\xc725e375ade1edd8533d9bfb31a83e9a83d6f9f2f60ca2a197a66ea7fc320fa5a9140f6c767cff7d4d4882dd308e132728ab65872e9bd5138378e926636d2079 \\x0000000100000001b5c764d624f8ee9cfc496a5c8ab4de50cd6cf34a3ba5e7c41f590aa3c34226f6babde182aa8e6c58b96872f107abd8ee288d674c8bb1f347ea6cc423db5b5b1cdd86f7006f46631c6d3de94ab27eacfa5eb87cd5afad9f719f0fc9b0a2df5f89c1d2a7923a06eb392cc51f1424c7b640329c7a13837524060ee420fa5daecfec \\x0000000100010000
-11 1 10 \\xae3e9f4180da00b1acfd974b4d374cc332becbfd8f46cafa2c0725309f26f6bdb69c3eae736e47d3ea24b22504ecb0bdab191a960e81ac69974c5b8f9563390b 240 \\x00000001000001001ae50faaf317fcbd3d2efb9a204e93ba549b4a25ca01d73027cb012d5df690c09a022e9cbcda2646d495d714ad711c8e9fcdc9e949ea5b3146ad9729824eddbc4036fda9780ea0c177a585ae08239e91d8e27f7a4b02bc0164ffaa8282b99d553bbe8ec323f3f5f46ea7851c84b75453ea2eb9409314be5f877018e82888114c \\x1c3ab312cbdc241714c089a0572e4669f683ad7dc2b53039cf934c4bc66f5863ee358851b1f5641e7bd2a3d5310c7f8a8fd49828df4f57b2c3ad9eb87c0cdc04 \\x00000001000000015cba2df6107a709f17a33079769ac47083660e319862cf5acefc576f4f71a76d2d425056ae8d31ff8df7205fff74e624d8bd44febb15822eed63ea1dfab67bd72536d87e7929cfd1527348ff99d78f88846ce436ba0c1b1a6173cc4e02bda61ae6e7b03d54e8ad74ed47d7ec77befabbf385616aad11cee7fa1ea983cec83ce9 \\x0000000100010000
-12 1 11 \\x3055b3893d869a9c9f68229b308323f41b65c9466797a57b3a5060e8bf6c21c5144215f65a209968cdab3fd8e09676595aa7a6c63a381aec8a0a5d59c332a507 240 \\x0000000100000100accd4c6aaf5c15096abb4758304a3a65955968a61229c146ad64cd84799d9c75069750c6d45158aca44e43247fa2bd51087ca0b059d7a28de72c229f968b76610401e4f57c97abec2760c697a192ecefc984b664a56ddc55c6f7d0a55bb180e8cc1040135013e93ea955d7be8540f7f1f70ed5a0d15d325ab8d079102cc53163 \\x5c3f9a08ed3ccc80422b252abcb6b1de1c6b4daadf243e31258e94f0634eb0e4f30a7a4e0d265cc4247cd9201f30c76e93af62af93b127cc1216fc826f426155 \\x00000001000000013d6c7b36a45ba6e9f081fcdb2dde30b0de4a40d5d3f273c548c142aa9fee7da54aa1433db0e01aaef4cf571de668b23aff2c39534f2a7ac2f56b3822af18beb4025e6123d9ee8db6637eb597ad1011dbc58bd2326aa5404538035a84dd2d98d0217491557f221384e842b377993c3a26498826db4846edea878cba364e273928 \\x0000000100010000
-13 2 0 \\xb8d874e91e4f67546556d853cdbd331d3e9cdf03f5b442f6c16a9fb1f215c36fe07cff2c8373a41df3ceb0a9b3f76016319355772e5af6119340736a855ab90c 240 \\x000000010000010079999f55c460e2c6125f327f5c0a66736eab5ea247c11df4a1d70d7207ec2dcc392b5144ce8a939d8b0c0df1fa1624cf773341be62d56374ffcdd84c8133a8dff847bd2d9f3256c64aec1150653b9b6186577e36c33ce1ade38215904ad4b16aecf14d772aa85f34bfcd41131c11d5610a12675e0db1cd7a75ac6a1f907a7263 \\x389c13c678b8c36af10907ed7d3501b267a8243654ffaa36926e3a50db8f06274157d927d0d37c8fa1f68d34306e8378c8ad3bef99e0e4f55a46b9a0cd840984 \\x0000000100000001b16b5b9b10148da945cdf4338be6e55d5678b388ed6b3da09e1cea8b3d53428cbbf7622077bda538201380d9f755e3fe26f80c5fa0fa88358ffa795cf2c3ccaca96851fc787f93dc1aa535d3fc5c7f3661cd02351f63eca2174b6d3749be48bd27bdd180ff4cbef28c082c7eaeacafc6183ba5ab4c22637f6ae740decdc1d29e \\x0000000100010000
-14 2 1 \\x9647e8abbc21dc09a54f088a0e4bd0423a62ad419d6f91d8fae5a469b7bbdf494169ac5e7b2be012fd35da48b2540e5712a60d69939abb0205aabaeb624c9407 240 \\x000000010000010034bb038039517434715d6c8e59bbcadbc2fa1e6311857edf0e98beb13e95d9a7b1bdb8dfef42d43247b2d9c12906d1c94f14526b210dac7d2b4380e445d8b9805946bfe95bef95d2ce816b8db44799e98b8bdf0902eca3c6de7cdaa3533c220df81f38ac31ea37eb9ed22fb232a8f28d7a0581779adaad33dbf75a9eec6c7600 \\x3c7dbbe835036f1274316da639a64cc5d580f5346d8cd5bac2ba212ed1b842543194a74713db5b10c1f006a64cffbab8a4a62e6e791d8fc6b9a4974605197902 \\x00000001000000013ef7be1f4b544ca10ae3d43682553058a4925bd3bda0bc3bb158586d797c23b9a935fa0af580b3ab1dacb4cb332891d97ca3bef01e38c8a7a52f33c58f626931b13d6f98d8ef1fc3b41d90e07a7e89dc9a1fa14de37c98ab5193317010b554d81bece558c09d39ea5aa0ffefa1387706b4df5c7a056a1bba6f006955dcfc37ae \\x0000000100010000
-15 2 2 \\xde24132f01fdc91a7f575ce4317796f65327f277bbcf76e8da37060685fc0a6f644109c1ea6978e2df6902e638e46f7066e8d08d523b9c9ff0d823eae7b13e07 240 \\x00000001000001004d02823b5c55cf64962baa608f1e6009162a952207492c37f0b4541f62489f9e03fec6fbf1b2e5a94e7d33a9057a9590e715b02aa419d6bfda896e8e444a7ff69155798390d652a8aaece61ee71a640e1ea8e4975b9bfcc28aff1cf5f2b4f720ede9814788ff91c0d296d804f32dc3711c29371dc163811af432cd567b4a58d8 \\x5b59d96d051d9bc892c354c3e00a5f54360accf78c61d048a6251e669137db69fa1e368d4f8f561ccac8ad52bb6116b2c5159613770458e979b966b12883e6d2 \\x0000000100000001650e70e6bff2147f16f4cc7445e8ed978d9dc8da718fb61ac95ced049ba89865dcc3eca7f8fdc342678f29612571d6e859e1c2916a320aeffd17174c0c4abdfc739dcdd4ebd350f4c435de84a1ec4d1caca34367a2e61a89f4f2e7b0220131644d6dc6f44f4ed1715fae41e08e17bc30622d6aa5acb0c928463d55f7bf3770bc \\x0000000100010000
-16 2 3 \\x063cfd01a7db812ac76b8879419a6cf86f4b1c1a05445741cfda0787d75736d9584ed3023f5b8c16827b25a2b8077c75795a5ae909b85e373c4087dc31eb400f 240 \\x0000000100000100184c1b6e2c0192a409fc4b31acbe56cc1e7e99588097f2ad074291666280c8bba10e0b1a9d3ca38e91843de171c62ea86054d017c02c45ffb460dbf81ca114c166cc138f6d220afeea5adb782a0855c268ebf0e8617dbc27d94d29aa6f9c3f0c9f44e90ac2e9238fe1910fc93797e3a06e57d782f1bd16049dfc3fdda421ea47 \\xcac83a06debd6e9dab1c3b01a86de91e68c9270e6ab4dbb419d2994346ce43d8b92762f3525ff0406d9c2d6f84670587714ffeb9aeffd1b6c35351dedcd2045d \\x00000001000000014a4caa4546de02bb51e8ff11d4b4408dc8078a413aee21b1f97681050d639fa6d6add1c364edccdfaaab7d4aecde363936ebab4813073d1a52835333adfcb0f4581c9b1108ac47e768f5b8e4cd69f6b87a5690a25f9068b7843fe94c9a08c77a65a441e5ddf8855135ea7a050a586de0ea3599b125b353f9c9e3e3b75e8b1c52 \\x0000000100010000
-17 2 4 \\xa61269f01cac69ab24eea8b9dfc15da93949a845b7cde6d0d0f5100632af3b64e87fae7983e8ee42d68897f43bb2ef21e32b8173b81374bb055a1e41e2d56202 240 \\x000000010000010096ac673322d45d9488b6a13be402b715bb5de09c203a3cca3b18dfa9bc154c5120f8c267aba3adde232d3b20b3b284611a5427db9b6b14954c18dba7fa5a18b372371aa4131240ef26b267ab4853ae50736dff4d927319b23b50bc8493335b5f6704b9b2f8ab4776cb6ca79ccb194281c545b33d7793b0dbcb9aac1a4e3569f7 \\x624912ac14636d47af2b20376ea080edccd890db07f17b403735acaaa05b014d7ecf2607171b1710242e5b196fd941ccb3fd378624e4a59db427e594f859d831 \\x00000001000000013ddb3e812a218aa69536451a25d9aa9bb857f5494e5b5431a31a18d715ba2e33dc310e6c97c0a83be95fdb7c61fa3544d65429814652eec116617453f42ee79ab91c6ea5ee6c85bc148d5fe227f2d4906ea4522b1d28f880c99e2f5f00195abf900eaa20c2f3e24a0e0ead28b370cf62e49f612fcbf2232c1760568069e18290 \\x0000000100010000
-18 2 5 \\x353d9386481c8e230283c2b3ca91160034d0c97236958c86d7773cd38706d7419b66665bd79e08cb47afd6f4fe5c99d3d71729d62c2359dc7aa92630377d7e05 240 \\x00000001000001002dacd9dc3c9b5f902a9aba4b8c1e11e4bfee4a77c87c605d55ba0921b727e56ea64056a9275773585d05f63d8c44a4476bf561d3f7a65ddedd9e2e8876b941c73c6293978eab84bd165ce804e59132654df2c123cce7e0e88f95527f9c5c32ffe3442305827724e0565a336fb44a988f84444f81ec390ce5293fab7ae5a92c9e \\x8a84454c54f6bce03b35608ae2e67f26d56399e299547a924357be470ba2788ead1639b2b33e5047c5ee3d2b4b936691b2ebf5fadb435fc9a3a11e555efb0617 \\x0000000100000001a0f2322b6c1ca570ba24e5407be349567e50f5399ffccae588fbda1b98c679414494394b53f432c6bc82b6368d69b7ce452ee76f77a63b0af8849ad1661c43d355ed9a995fd85eb4fd81319fa8d3978f2abcd818d8ada8b3fb8063a575ad9b7a2e3b24609686894f37f2514f5f8e42ae46dbbd52dfe2a74c765c9f0874703f14 \\x0000000100010000
-19 2 6 \\xac7003d5b76c0676c416e7d8b43bf36b6be8882d00d0231346ed72d22a8a40fa95244d9bb6d1d3fd94ee1c4fb4c904b559ae25497bb0545220c03de8c43e5904 240 \\x0000000100000100202cf06e6cf63e0c2dea402082c06a9b24364bf72915d5bd0443540e1a8da5526b65a10c89944d160eec261f8d6bf1766e2d321176f6cda071b6de3f8b9518e9bffec1ab79ca2a859f95f81fcf2a698b80a75dca1b68caae31a9fa4b06a939dd6f4e0e88c914908dacde76d0de4d69df36427a6ce9a0ad303fb3940913b9c209 \\xd5ea8c5f1984cc7ec2019769355bf6a24016e443fa982d4bf938f3eea3c4b23e7dbd72e77361288a4d48826a136ef9285a4146801f34eb823793f7cb2a01a88a \\x0000000100000001b3960fd72a8656926409d6ce17690f1b9789edd9f19fa6f2ec6ac12c6955a448ae937939b9c6b83d503a9d27a66e5dd5425641959672b16b611a919749bfce235eb25e0f7847c9528a0ab25f3fef24b983641c8971f65ca35af1f75c01280d67c507b4d0bfd1bd0c9bee7335b8e233cdb862c99707d6d06495b7b19c81e64283 \\x0000000100010000
-20 2 7 \\x1a1b505bf0c7fcf649198debd888d1dd33b0ab93526c65d5f7528d96d1c7d0342e00ec1c4bca71a2857f81492ba0a01b4b395fa07f37a04032bc6cdd57fe5c0a 240 \\x0000000100000100991645cfbf79e76a04ccd9020619cf9673bedf96d57f93eca8c6b03b70039694975096d08d9d11cb9a2fa3dc4ec84c06288c436ac37eb5fc3dc6dee7d0d7a76967cbbdca8753406553b9230fcf4229dcc1d20366a9fa0b6dc25da6722f5a36ea5632573dbd2a7331219d2f7016f65c3bea2ea0ab8036f3b58ec74962ea7e3d80 \\x71a188f14ea9b2534aa5df1acebcde004d10addcf347bcda755b2d5dbe034be83e0404491aaf6923de6c886649c276921ca732fd08090730e397bddde337c5f3 \\x00000001000000011d21b944f55772f538f51495470d97a5e6062cb5c67e5e1d326b1264dc8fdbe8a39894455c36f74f981d6df084c4f162f12ca766515ad8113359009dd8a7fbc5d8146518508b629902cb2e192b7db1be72a80127cf52cfe21c16a0380cad8a9562ad6ee727e263c7d46019ab1f100f600118105c062aa434dd27c38da9dadd46 \\x0000000100010000
-21 2 8 \\xd00539124c8bc9dccfbd5206b67d2403e42f91a9bc53e6fa63e729c9621d6bd172a6bb947f88e935a869f0de934a38c49bc1800adad768cd64c9b2b355b8aa0e 240 \\x000000010000010054ff190bdfc0689538567561bda3c096588402c61ee7e428c0678d675bfab54c107908069c730f731ef19a2c1dc7f3b5bfd9ec9cf88f5625312a3d961ff5b1534f1f6c2254297d3bdbdc8d25f0de137954c87cbd1535eb782504c1444f6d0cf563705f38ba04d3a822c31b16fb5d65247411fd5d4577e449421ea7d8f87bc182 \\x7d2dbd9af656d3f34450fc2a7e4d17e1986d10d4da47bc72ba912eb56b04004f9fc2d490d05c9d21d2a79b074dd8a72639afb7e4bd5981af56c13b5bc5661adb \\x00000001000000019216cec8cc93a7f00e3e1d0efda989c3f117d28a9aec5aa7f99d52d3254799c327312bd15c9a53876a51bcdd7690425d720f53bd037856041751d3130cc7041e373ffec59faa04bc53da7703311a906c02e11e640abec24b41134c1b95e9c1e28cb1511ae7173046f12660a991d2d5b2278d4435ef7b491a9e3a5ee5960f233a \\x0000000100010000
-22 2 9 \\xc1f6a10be4dc6f4644859b3e336b281f65d2bbbc1ab7e578b8726e121005fd5fb1957789b72f8094cbeea888030259e551f548b4267c2965a4eb446cd1d6310d 240 \\x00000001000001005826ebcc5a73ef73fbbaaade2891943a5a7297a7ccef111e84feeb0aafd09788fb99bf6f68fbe92afe9024a3ee6eaab3e19628f9bc94b323a536de75a39ee66daf46f1f71e13551d225390166d4b407959e284c795a9574fc7cc72406dcb1820dcd8f07e40d0794f276e1ca2ef9c74cc534b27e75201b321c2ef76e86bb7d903 \\xecaff04ff6bc06248ddc748ce0de4e1da799c5dcc13c5a19039820189b7bb450ad30074de578a8763200cea2598bdb7d81830077243e1f946529e7acf489002b \\x00000001000000019e3885748fd2651c6fd4e80d97833b5eb3311a5525de3e123997a540b24b220424401a43cb9831a3e0ce0d611e9b5416d967c404176bf21db33e68178f2322568312a7c7fe63a58d6a7c4f0aa015ef4ced85d9088ef30483d8ee622202b554ded01ae2982533669da06dd78ce4a55dddcf79f2815cc3483f6a3204d449db0c49 \\x0000000100010000
-23 2 10 \\x98c5ffbba75ed404169ad411d81f7f246fb757e471f5a94f4d8070e10525ea65f06222830c4fe7c4142e500334adc45afb583dc71a305ddc66e7079d88f39400 240 \\x0000000100000100d0751fb83925413df61e30cb0ebe178805ed32bc488a10ada9f7b92164748281599a0fcbdca43ddf79a40967b2ea59dfc4d59c2223b26ad3fa2790403884e4e61c9b5612cba4f5514fffe2875946b0b1b7989051884fef3052eb780ba92325e962f9b5c573d72cf9550eaa97dc3b11cc28fc7644aa00457e1a8cfd6faae3398d \\xb69313ae8933d101c0066dfafb342a546849d70b248c7dff5f67a945fc896ac3096cef4d00bf8e637d75b04033812d291bf6481d2dec82b8ec21cee46ad454b1 \\x00000001000000016f82dd54e720b205f18a2b6211dfb06ccb4c17856bea2816af7b669bd2d7416b7d03786791f025ba9a83521c4121e1b59622e5bcc71d217c82b7931a22fa8b27fc6930cfc120c088fdf69b9736af2db6f689c070929e3b0d395ba3c79e3a0f79a902de4e22579ae657ece05fc53a5934d0820e9e04896869cb9b05332884abac \\x0000000100010000
-24 2 11 \\x6deb57dcbc4e02234b76a23acae07ba0b058404d3aec9b5c9105c2753fccee9294d3e1694d88f6dd5fdbbda687e42af9fb82ad4b4e603144b5aefccc9041f90e 240 \\x000000010000010022388c09c817ce8f5752f3ab0df8cda328f216f104ff23a5a07efd9924c7ac15a3922c4734461199c64994311a5fef3ae7b5defd022c2be17dda680c5ef5796f7d79bc4f402211b4850c1318043a86810f7fbffae6c5a41ac0ce53354253c9cd2e2ebed6fd252bdaa4ee609e90966212bafa24b12fb50e201b9376dfde8cea6f \\x35aa4216fa2fcb7f79900111d64e81436ddd039e469ec852df59075b8e8679b1e32fe1e6d25bf9a1f6567656bca45a29905fde98d0881b3e82d26c554b63f247 \\x00000001000000011059871156305133139e24d20e4f35ba08100ab2496c012eaaaa8817e15c3eac5f52bd41ebdb6a624ceac7026e7f08bae9a92358de783af1f3654043351cf24727bed215faed1dc8205ea2cb659a26fa95d8cd9284efcd9def821e9d191c63b03ae018074320d1c78f8e410f0a97b3ef37d10311cfdb5e8bb9d101438a8f73c2 \\x0000000100010000
-25 2 12 \\xf6bff200656c4eacd83027db2dbf02e39c288e30cc8838e494731f12f18860672d5951cf188374b40954e476cf4854a0289da6339f2dbf7ed152f38b9719ab07 240 \\x00000001000001007d15ea68fc7591c55b15e2c77dc2a7a0be516a3a9fd85667693f82631a5a266304c793b4112c797d9f41eab64f37b4fe138da1b03807ced0f8d8173d9efbc5e8a52196f1b88c8e5dbe7b3047927f7553f9b055313642e3971cc6ef61b388f188bb711b22c5c1101e59892693548912fff86e2514b01c466444b7b174a6e8cbd5 \\x335b2505bf166cde02128c1361fda0e2f7deaa4174fb51c22d73ec7242d96b638bd1442f7442bd7997aa032503cc1f3128d6672f38ab8ea3c9d8354af49563cc \\x00000001000000015f8f831646630058c76da93e13e98df5a29f0aa3d8e02bda2920eb926dd9a4f7c3135560da70d966001039e87e75e136f350e840869f6b8811d510ef848d0b1d2ab69e093c404642a3580e0f95fff0a57dd6b77be1f54bf233b34436cd290c69b9a23c54f417f4d305e7215086827c256a2ac319fe78b538c3998bf7f7fb7c10 \\x0000000100010000
-26 2 13 \\x895f84f9fb92a82604d6e59cc294bc977a952a3d99b29a5a636e02e26e778c32468cf7488dc4215218b5f76ad987354be95cce9c8c0a3e3213190a6cd0d6230a 240 \\x000000010000010074f90a2f78d5211fcbb0afa8c842a7c7eabb8099ac30d9123d8595762abb99e267f1d311455363a041e49902d1104118d05b588e03d9105b2acba08a73885209e9fd0ca88a0fd708e0f50ac0e1e460f24adc62bbe297f5690b75e30cba6698cb2314de04e5409b616eed759801edd24eda1cc2b91689af161d55e772a35448 \\xca2eff057047fd04fd51304fa7c7e322eefe0a07ea9919ec3a3d2d6074f292d0c7a9b872fbd4967b690201489c9dc26da57ed77fcc15461ae426a9030c95ee61 \\x0000000100000001c0b0112551ebaf1a6358423b96d5cefcea40c59815fcc6af97c250474da802550f108f5be4a1d9b9f9eeb039c7164edad02be4e3bf4f53d796c5574457827dafcae43baa7aca33c0ba4b1a7c50609ec494510ed34670da289b53d550c827b7e0085c0c5ef3e02602523c5008d18b415331e5c78a6765b6996f8c9b104ad6f2a5 \\x0000000100010000
-27 2 14 \\x7059cb0faa53b5fae7a134147c99a96f94cb7f5d47a4d81a6af22f7d63e672b7c4ef0c1bfdc22d4c706d0f9a8c693a368c7192565239b358e33660092c53fe07 240 \\x0000000100000100a47aae6db0e7df27243ae446bbdd1fc5bf9043183ee7a460f3b379048f22b8e76d939b478117f4b5c00617c704fe9248de0ac26308b80599d3047a826b8b3c514e385dbceecb7bbb2c5188755e1210d82eb6ffbfc80b887bbabc2481c08006096229721ce20e6ecfa876b6cadc95d424990e9c25dfbb690804974d32bb7b8c13 \\x6e4720f6867a7921d86f91471487ad07291a96141a145bd7552885fd602242f8da26e356d49521c76c78c8e3301c9edadc247d8beeae072a76b73baf88722380 \\x0000000100000001c2d8f413812df10b7b87026a5c521995fdca4911a976f990b119e9198c3bf67286ccd2fce764d5d53188a6fe23507643077a84302a85af5b6fa63ec3b8bf316a3c09835401fe653deda539d693849b10eadb63a980bec3cbad0f68da2e233c2efdbbdf1974bd86c47cc6f34e3f061ff0505fe0fbce7358f8a14ce7fd86eef06d \\x0000000100010000
-28 2 15 \\x46da0db73d44fb34d7fb1c31a509629a409ade43c182fa4ecbe436eb8cfa81e6962c9bfe65d0e33727107be78b0500536e4f48c7725be24ef5bcf388799e7202 240 \\x00000001000001005e21226472a0c5f8a8b9231f443313c3bc37a35e3b7d6b088e0edd3437deee43e54df1b7ae51ffccb8f1035b20481918b320b040deef41b8c86560f187910a0be5efd2b126dbb6d01edf0a98073b25935256119a9eee443aa32760bc721105133f1af3a5d93607564c58fe8e74d3e70d05aad05b7ca3c69d962fe832e5af7d6f \\xccd0fda3b41154eb9a7a509048ecdce625d09d6192e93af477a76747c20b52da949f268b35fd6b48071031ced0499c26cff81dd0e5e12c9148f95b6fb6dc2f5b \\x00000001000000019092075aff8e7741451317fac1c8fef66f0ac59bc9f90636e7ada9ecac1025564dc2699814cbaca5b397300aa213eb189e508f9b849f4e665b7af756d036ba1507fab0314255118d50c2d70b7ed023ba84d2dfe85dae2776bc81d7327bbfd2596872ac61c274fed831ed867319c08fc5ac86ab48e8928eb95e8501e5373116ba \\x0000000100010000
-29 2 16 \\x442b686e68c8fd6a503bf5e1cf2e4ee2ef017e8a7e5efafecb01b46b116a77a600be6e17333668c16573679fe9d2860ba08479907c34d44fdaed5322716a3205 240 \\x000000010000010086b81c643dc48e2428fbd4680b451bf2edb481df96673927f7d1614ecd4d40bb94a799a72ec6b2d00c588f8b67b59e78f1c639c0b82d749c3696d935630714e09f6312881b8638d175d9daf6452fc40bdcb5cf44e724e3e855458db0fc3177d6e9e2607f6f1e2881e4293d70399bffe9c92d67c9951f05ad64f9a917290d062d \\x43924f8019f8e384a617b7941e81a23b76dcfc60d2af960ebfd2a60a05a7a9b6615b64cf227237959c844e465430f371c21ae532f787b6b2b091047c775f81b1 \\x000000010000000170b9d19788970902c4af6f6ce207158c613e0f4174672c74238b11944803a68f4fca20edbf31fa5a76a01d05e462f86e69f9bd65779fdb299c4d32c92dae3aa5a0b74181fb96472d1be810c19fb8532206bfb4387f2e7b556c2d4de06bc0d7b57578aa6ad4d73616ac21d16dfe11dde9096ebd473e6094e2d2378bda29ccfb34 \\x0000000100010000
-30 2 17 \\xe707ae6f38cec3b08ae470ebe6d70e105ed080c8e6b1e56e6b0d7e475a82a8d6ceda12141e71dc3c162d30c63f5011388ecad80b103d49489754c46472b1b208 240 \\x000000010000010013c9294ef2bfa12884a155c730c082cf00d249ecc2eaed41dbcc50d1d9ded59cc09b4669e74ef725daff850416054bf04f44b41b77aca818878784e2bc43ab61cd81ccf928c9180223759ae893324f1c291c6f3feb4dd17369cf4323c95a65b9dc5c93dc1eaa9f770bbd5786def0c7642b5e80cf1a0db9deb94010e28eb964c7 \\x711c9f9519ec419ffd1e6b411c26ac69eff151fa1dcf61ebd0041efdfd55fdfb7fba6c03485a6205f9d0751210dd942d0b7282e70b591040d7dba5cae90271e1 \\x00000001000000011431e2d77ed942b11783de48a09ff9aeb7f0593b1f5067160dbc2635f223fe14e8877e9c2c7a2b78191523e7f78151fae46c8edc468293c80aad63680d2dc583fe4521ab0747d91b715a0a318007789ba5292d389ba5cefca389835f7fa8e1688deadd8588015087c2de6678c65476641af8e5607007c0efd289579827ef23e6 \\x0000000100010000
-31 2 18 \\x4b4ae75bacf7e398fb523a162060fa5a5e0203919c8b4a280a6ce2432aa74d88f05ebb0ab38e63da2216d8abe9709b0ad9385180c04b5b360e415e475bef1b00 240 \\x00000001000001000509532c9eee882b5641be9714cf0381694bb7fbb6d50a29f452f90a046d925ce19a0bee445d55c30f38c8ce21b105416aa2df1387ef0a3706bd8866b4cab646bbe769c86cdf72b09f79f590b6ba6b35d952ec3b1cce3d750e8c4aa8c6d8720ea400de717be389b68c965cb32e60f72e32644870e188d2161f72e2e5138d1433 \\xa0b67c058203ee8efc5d95eee49ad70650aba05cd6dca629139fcd6dc085785976c154c59d44b48895e2f03f8f9a2772c1462f7e78fd54d4708fed8c1d0c6e6f \\x00000001000000010f065d6a0eef1fe2cf99c2f915438090fa1edeb39ab8088e5a3bc1dcb802c6959cd4abca202f7eff5b3983a0cbaf5d1a31c1928ebbaee4e08c360d799c3a38c9d1ea930997fa33b7e9d440dc3b8d0e7c7ed2a9ef32eebf95a04937286e2b8b7864ba99b129ee312cf67bcd0bc7db5b942f1ea4705ed8f65a794cf0b149fa0635 \\x0000000100010000
-32 2 19 \\x1df11660e21aef86396677d18fe9a61c5737b4a1da49ae03df44b8440bcb3254aa7a42f361f9af22b07cc8a70f020fb708f1624d683b97e062bc2c884ec6cc0b 240 \\x000000010000010032a1d5712b8f462574dc71f4cf109481381b5d3da57d1d51f4e3534a9d3cb9656a7b3fc141c529d469e3d6ef704fe5fae1ea70105700ea2ebc33841ef6ed7e627aceba5962a9484b69beee627eb1c0fef50b53a6bca2ff03be1dfb4534e1b8927f518323261e5f772ce10f0be733b37e50757621efb826e55f696933fd750e9f \\x18fb59fe6511a38f216ce5c66f64794b762244a1511f69caabba2a19bdc723c83789de4c36b2d9ff69ca046c2277508c28d8a16a922e1fb7c14ade5251586c5b \\x00000001000000012a8562305bef742a7429cf21cec99d9d643acdfaf1eac99a99e349c86d8ba20f588ba3584db5b00396b6701af048d716a8202286266d7d133f54ddb7721ee114b25c4a74ab69b58ca27cf899a70d6221f6d9c7de15a48bcde34bef66e3792f7df8b43a1ee8d53857062491178a8c7aa37fa1a41e5e5117579f0f1b3f049e7d9a \\x0000000100010000
-33 2 20 \\x03337f95b20abdaad4aa82fd333c723eaeccbdd9b3d6bb5eeaff513953ac60fbdd585d0f3d74e06823d40e5ab2f43c9d8c18a87257a7551d066484803903d304 240 \\x0000000100000100403bb4ee6f9ca5b887391fc51b9c5179563744b0a55e8ec43a2d0babe14de37928988984c2984548560ce95b853c7226cf181fdf30a8557308347bd4806c0ec4894976950d964b6b085b58567874e5491b7948f5deee178f44124e81c1d88d58ac9c2c74b0c25a4960ab6f9e1de6dd8428c17dd6dbe768cb85315f817ac22d26 \\x20398d7c2bcaca869a788277fb9e877735d2f33046abb2f5d74430b2c1714fcf271ac75c0b6d00fb9134542c566e880fffb3150c8c72c44d78feaba95105bb63 \\x0000000100000001cd8f39c8193e69017ea70b7aedb36e51adaec16eb2ef54622180126cdd67c9a324c4aacd4c0aa5398fdeb332d107def7aabfa22b3b0bd178b8b1c1494a1c16a3ac873a5f084f9c0e7db56c98612ca2efab19745ac8ac8f13ffc7dbd3d8b546dfe59dbe4212ce6bdf20f3410e8b50051088975ebc1eb1f781b8d5811d18781eb5 \\x0000000100010000
-34 2 21 \\xa1060be12e5c96fc651795b8183427703b268b5787bcba8f4d93a8b36cdea09dfff4ea6f5cf0ed691fe5c342325e78aa787137913900c14a07d8f8bf0fab8704 240 \\x0000000100000100316d57b97d0c840ed8452a14435a12eb7d597ddfc6fe36413eff08c904ecd52570785dfbec4b56aab92bb2d8f5e997fc28e10cd7d03e566ad8a972267a798431e07dd770c458afc11c1dfc26350cbb1c1769f1bb4ceeceb99738a24ebb9ad70b5d5f02a623367441059c8941c4f287025e52e35bfaaebdb217fe4aeb385a7b94 \\x79f6b0ffff859edb2f84a6f29ea1a50b68de656e8bcac75cb36aa5c06b6fb0ef31c8fb4b081fbbe9455148e8397283e5200f552074ead255aa9070b32ae929f5 \\x000000010000000179db9a044c7e4fcff45a407c66453032267fd5675610da45bc68e14ab5172efd9ac7ccdab6b7005f96032189ecf27045851b89986b1f87b9fef51de8a1cde1da58a9bb004767bfd9b10cf0acc27609e8e30fdff065acd904a5b4d4576b41fc54f69173f3fc5a1c1f16b32a27a666c2d91bfc06dcd3696602f38a78330bb558e3 \\x0000000100010000
-35 2 22 \\x6f3c42609544974a50d09f41b92f536228c7f92fa14ffcead2d88efeb011b27de0f8db897601d6ae47852cba2d0386a3f83d513d1f674ca1f27bb106d94ea608 240 \\x00000001000001003fa606d1256b2acba34f830de5154c55f6b32103d0e6d67d57c0ff7929220bd7b5fda27cd99fd52089682d4e45c4c9a12607f2ede002ca7ba4b44ef7d071701d9992c04f3fad65dcb5c46ac8712f97f3a033c57eaff842dcfbccc26893bb3a7c1a05c876404e45ab1026ec72123151144e12fdef617eb84fcda4fcb9d99454bd \\xca0e8928564123197d99c9cdc497635def689cd2e89543848d89fd699fdb055d9bd5d20bcaab76a03d988635910395ff597b65d3de46ed38b94c8f8443050124 \\x000000010000000143114b50ffefed1d68c0ae27725300ea6fd19110455175d0e87c065c6544267e8353d9aae810020e741e6cd78efc965fe603a42600ca99b0298ba05c38f0928cec8b29a428960efba1e7c7425780688e4fa961b6df167398080f4687f3bb2eec5e1a708e5b805f11b49457d5ce2e74a57942a4cfcaac5580c6a2976c172101d5 \\x0000000100010000
-36 2 23 \\xf71c4981e29eb342a779967493cb41c92712738f1a9cc7d9ddb123943b0dbe202aecc9d05a5d56b3327fe9e0f89e3dae3ba36893b4adc89ce5499bc14ca23b0e 240 \\x000000010000010013b0f074759a5fc7f2fd5d0b66fc7e3d50d76ae62bed1bc4fa69e90f77c0f59edc377faf2192a1b0b8a52c51d351ea8fcfde4cb2a0875ec4ea6de17d7f1fccbeea49faaa622e4b4830a91e7d632d15a5d9cd871edd9f7463a14c24d0c5938bfa0d1f47ce58b0f3ed5bd62f3ecc318967c34fa1b77cab375326a4e9167a852438 \\x910c52f7980fe1e37dbacbe6fd79368a267966bc6ee93c7ceb282c742a327e8ec42088b525f98c1ebb56d7ef24dacc1fba355c5aaffd8dcb369a61f729ff0c82 \\x00000001000000010ef64cd0aa16de75ab5d5d61359186f7eae8c01f0eae996e0596928323d539041a24ff4bfe58918cc3fd05fcb2197ca6f2414a0c2ec656e15f7819cd5059196fb972466940ef8ee98f11a956cb774cfe738412e11f49b986357b76dcc7b27280695fec1256e6ca9ec1e950ddcdb95db1ad648a1a5d29d69ab0c29302ea41a79c \\x0000000100010000
-37 2 24 \\x0222f5f615a3b108d25ccee2b1f42eb162dabb82c2a7ea745bfb2678fd153505aa236ffad2d15aca3424b1299991f412c69dfefaadd9d54b00ffa00e7065dd0d 240 \\x0000000100000100b0aba0895c166fb60bc5c5e6af3fb4676bd0515f8afe38fa1150fbad72bcde5db153c51d6dc2fd2ac3d325c33c61558c76147ede0637eaff327975620609db38c850aee87f6310390a2a695a18dd2d2f8e4f0620ace13645f7936b964f0e8d57199700d7e29fc962d053953262fefe698fe76e62319feed87fb33772d4deb397 \\x6ea77cc84f5352c696fd1d3bd0bbb228067ec54994965bc5b5c5c5680849082457f1c408bb2059a0f338be63a334592bfd03df621ea75a5a4d38b60d2f7db785 \\x0000000100000001a9956e689cd943ed4bff37f97b88c3b714b9e834290b6f7dc4cdf28929ce8a14108ec0c4528a2e7761dfea7a410d0a12d3e784be6446b9e74febdc0a872c072036bb98cffbf5dbaedb0c162df765a2e3bf3eca9016fbfe606d62bfbff2833b3c593b416df38d8e2b89a65e11f4123c1373dcc8655c1f75c439e9bf4159e0ae35 \\x0000000100010000
-38 2 25 \\xe397990e3ae1a5f22c4e0d209218fdb6bcd0d741d23b82459c5a0e8887340bcb08255a9e5351391e5f85590f3381c728b5b9860d70b169fbf0611f76e6e73c00 240 \\x00000001000001005c72c27cdfeaee65ee2bca47f7a85d25c4ba4adabc3e9f154576e7d951fced42ac93cc15227795956a3b1a45b21e1228e42691190c26dc616b373216f4f6714a6abc51b3c8f2d9c061a095ebe1117de01d2bf312a8ace38d828bd9a8cc2b89d7c7c94e76ee1e5c47ed6a797381402f0280c5d51e2302e0b644275efd6b3161bd \\x6f4773a971a41b18e7ea2207bb1793063be2a9496aa6af4b9e120bde5fb1b81008d41c42c6cda80f7863e5944513bfc6d3644c2d6df24b38b132d56d7f636515 \\x00000001000000015a1b68f49ee7e7c7c2c678acf64a4c188b3d2239a5a158164910f06f643d5c4b15fd289677e85cff3381742dcd98be1096af5468df9aa8e2838d557dbc9881a509a1f520fd370be21e444b2de1bd807d17c84258bba694955d5bb758e8b04630eae97dd816a4d9dc610838a183b23435405f28def51c1f37a6493e71aa10c5d8 \\x0000000100010000
-39 2 26 \\xc1ba80ca80f38576b342d3c4c05189b449cfa0102a07aff3a5ad2e19194df862c948872a97750e59e5a71449976cf360352f8ffff03b56119ab1fd26d066a00c 240 \\x0000000100000100c666a195b0f88f0b1684891be03dd3ec0eb0edb284cc99e70b5eeb619effb10fc7c5888a73b10ab17b4472153edf81e00a796dd9141f3248a14147cdda7d92db2e820f0c8655894439d9659c3cfb9cb9645f20fa1a71c5f9a8ccd770e18efc526bb3267d11affd426bd7df61b27bac9da652b8df0f27f9e3e48d91d95cdcf534 \\x782f12315d98754adfb4bdd0ebe1ad96fc9858ce0aa8bf896d38ae73d753934fe926a1d68691fde4de46343871e27696617416e36293701b6f3bf29077f6fc21 \\x00000001000000018f10fd007714855d97163be3acb24f7fe368f7568afe23514fba0839a10c32fb391198327cd84a04f32282b2073a28910a62324580736dbd7f1c939f1d10793b299d92947c39ecdc99152f885276d7e00d57174063d732c83047da2008c047dc38a9201174e575135c35c7c70bab403024e4e8257f41836b5d9c3d0072f89b38 \\x0000000100010000
-40 2 27 \\x945943b7e1d3d37a2ace7c3790d824b9f7ba50ba9c2d091795c923bd7701330d2806f9abe2ab8c0b23fc285b9a1f03dad36cbdf15aa5dcad34194ebd6e944405 240 \\x000000010000010058b1f85bfe2316044ce24bcff8f89eda5fa427fcca6b7076dcf60718c47141356042fcd5df97fc8e8fadbf29d407b7b986fb81606f6e84aec825ae95b82bb4b90abc78217e85651d0c03c4bb3fc4d1f2ecaac78eb09d6605f879c3661a1f7b5ca5b5f5a045f45229785490123808dcc2e89c08c8abd0ea42cc2fdc1e3ec9b7a4 \\x6a145e202d1a6a1028d306bb8ec0e8ebb019bcdb8f14226dc25a593b1f9dfb2b5bc09e0a108e334b1190acfd72034ba39b4d7681a6dbdb7b21706e7e91024a1d \\x0000000100000001a018a452cdea6d4450f1058ad791827f7b93741fdc9e1f5085272446ed89a9f68d48591ab3a5de54375332bb235438d78bb0e6219ec0d30c75f67ccceb1409236cf59aba02ecf7ce1465fdd0f59963c0e8c24dcbce4ae89771bb592975c5f3a2d32f88f599f54295524fb5aaefbceb8e79ea96aa57cab10bf266d951f32d8cf3 \\x0000000100010000
-41 2 28 \\xe00c47915b2552eea894e85f344672fee5f3effd0584fe904ed8bc8d94994b748e6c983f345a045a08ed084d493c68f8dea369842816c68ac6050b4615d5cb05 240 \\x00000001000001000a170634778462a8165275e362d67ef460e02e4ae14de163802a75cc353211aff1785edae1a8a235526f0d7b0672be520c1143ab5a6e4ac19683566044fd6d6f46fc93707ba4f845bc60193da734a8fc519cd9849836b72110f95c2efcca5e2e4d4c74791da214bc720fe24e4f3b9ccd60aeeec8a35008e5f504133a7509adc3 \\x296fc4c5f4f8ada17b8d26cfd93b8a1b7a5ca7f74ba9335925d6aeadc26487242b97c68eda683c06f37afbf83539dc96538a197697334bfb911db1c947ab1a12 \\x00000001000000016468b6e1b3ff3a9d65c402e833eb096586a2ddf2d5e1f2bc4b2d85202711bf883bac8290ced7ecde6589ebf09e550734473e471cef18ecf1527bb53df37e565dda9cc617e3c500523e90aa48d1f5e2d122ad21f52ff4cf3e9df710a60eba1a8a2d301d1bfa18fcf34aa04b83562a934b58a3545deab19b3feb31ed8dc4f4d26b \\x0000000100010000
-42 2 29 \\xd940862d94e01aa97c7d53439bd2b7e0c924556de2b055b289ab35b9f40c032e105bf522552757189f7b3844ee6ca6d8f117d6370e471dfc9052371a07c5740a 240 \\x00000001000001005bae312f1ca02a030ebfd3f68ac45e50911ad1666561a3d0a58bacb132ca1e88c6fe122447391e8e04b688e1d90226aa5a786858f9b62de3c32a7cf66df2ba29123773d10167b2f404c547288592fe65c14211253c9f77ad1efbcf4d7aa85b0b37b1cf5b33fcc220b02e962c4da1fdae1e5985f3af542cd04d5821197f9712f0 \\x206cf01ea8876c306784bd6d4cf9d753be5c8c75aa2bac9b4246019366439df55166bf4517662877f3176bd47cfb2f757f45ba11908092947990aae88fb3a317 \\x000000010000000123f20517b049d016d3805e0a6b1ab3db2779d3f6cba38730b6173a8effb7041f2f4d1c509712145603ac357976abb2cdb878de2be4c347ef15f312af57ab121a5ee05bc9e9e22992eebae8ffb9001cde59227c48b01d26576b7c87ad6d56d2d6f5b0732e8e504537fe2b036f63e9fbbf0ad0f4820ebc464d2daaf3e846e82420 \\x0000000100010000
-43 2 30 \\xd433c8036e5421a401faa51807e7f810af598f5891a0642a379951e579fd66097dee343cbae948a7d5ac6ea27d0ad4671ce0e5b753856bfa93b530d5ef0ccd0f 240 \\x00000001000001007d92ee7e6ab87fcb82d57090f1d3c1c390e5aa1cc32333432eaf11240f81cb70759ce998a0c1ddf5b23f61c8c8046277ed40f2802442623a0c56a55a6fc23d02ccd40d9864e3d9dce991a8e572ce4d3e23f3c00764702d343edd244da998e508df3bb78c9995e45b73fe523ba869e5c9ecfae3794c8120dd25c52023fdbdb8a8 \\x75546ecd0b9c79e9dee61122c9457f7a951aa11b8bb492f7f1e9a720ea64f8705db333cd62333485917a2edb85bd23abda1f3e7424f0013062df906b98c72eb8 \\x00000001000000018eb19253e5461200d940b57d729ac113b201166140a592eb1cdc7fc2fdf7d9eff19b7622263345066e1f9de9dece27cc493c64c9230a9d368a354dd500618ef8d7aa9e60d2bb60da417315e7f99744a0b682bf42f8cb07e0167c21a195243d02e451586342274601ac6b0090e7211d0ed403228ba49fb579d6a7c7b48b377aa1 \\x0000000100010000
-44 2 31 \\x03ae5d7ff956739d41ccb500b6e24dd2c0004a16b5811c51bb914c6e457f9e3b6fef8bc10fcc5ed4f232f245ba683b233e600c73bc509dc6bdc45c6332bb8308 240 \\x000000010000010042fe5c1b4082cf1bcbb77d830aa0b28e5cee23cfc676b03fbdf08be98892127214f2d1ee249c65f37e4149da01af9c18c1afcabc3e38081583e0a944b094b9f159071ff2eb05beefbd1d93b15a9c486fdff6085152b913ea095eabe18d01f56aa61adfc50470eb574f8a8487b10ceed749f6838ae4843808dcac03468b1d0297 \\xc13b87abae4cbe1a0e53f30352efe6a4f497106ddb55a9216cf8019274f26968738292ac1f44ec2332cdc7c9dddd5c229b421ac5b9d1cd56df638521106dcb96 \\x00000001000000019fb55e0fc361cf6fc71631857e33a09f2f36004125c664a76708d6ca82b06b23a205fa96ca8665e277cc28c5103ee21799109059acdf48a26a607ec4e1558a9aa0a2a587241060bb4b7b5dbaa72bb77c608ff8cbccd2018ebc8531ba5ba2559cf4d6f46b5c43888e4f108665cf40c48276cf75497ae0e68ba953fd6c73238659 \\x0000000100010000
-45 2 32 \\x88fc4d15c021ea56ab506a29124983273ebf5a5dcecef2d2d392e310ca7bc28674e2f1f97d77fa0d61087aaa2d39584b47dd9c83fc0a49f982720bfc85c2980c 240 \\x00000001000001003acebd409db25a974dd55b354826cf4ed0b860f3bd94ce784dbbc03a72734880621cc17815da8cc6f23a32eb385328ff546214e4a2d685167613f629847d7ab3452f7ef1008481204c89d87b45e5554d8bf577f1a0538d2bc3d18e576992143a5be2d91726b200704a5e88c4112ebd6a6f7912ec08cc4ab3bca158969c15ecd9 \\xafb8a48224205961bf13f927a548a32599dfd1cf4837f673b37195adef9d949833ec93b126cd74c780d509f721d25d9c73b77ff649f1f47b1e6564158b32adb7 \\x000000010000000167e09d04845130d25bf18f757f3dfa6404b207262063ed22ec6ecc1c7e7ebc4cc76bc786127811e4fb559a338fcfae479e22829bd5e13d51f00b68a80876cb6f44b9318bb917bf625987533882c4d9f393f37808c6567f95556eff101df50ba172a9889541854b3082d99fa622f17d383435770e04628f685f545881a6752855 \\x0000000100010000
-46 2 33 \\xd6edab2668b6eaa34baf1e06efd7ae583ae924d6c5b600b8934d54c2d83c3850d9e310b02649e47ae4950ac46bcfd57174fe8c302d66e31562c3b10913dc300a 240 \\x00000001000001007a2090bd0bbac7f6aca6dfc135422951a5e5b6aa2c63340735fc977dfd5d500694fad6395aa62343d63d08f0474d5432b114e25597259fe1d64479e5bb4d856527d9ab30e2066a2087524e3c0cff07d2ebaaad8b8df810ec6ee378a2628c55eef9e7a1bc2bded673c940e27f77e87437c2d054312047a6bfb1153dff1cf27d10 \\x34f5fb65e88e4a5a6d7090af7f6d351fef10e1ea0a02693b056cdddf6e46323686c2670140e7bae82ec0f702a3850826b226835a29d11a95cece3415d3fb8ee6 \\x000000010000000126a1170fa2106c92587ef38a8a0a4d5052e5b2f5b384a23221997f49d97c76f569c5560c49db02bfcbd8e4cd8dd8b28fc6ceaef052d8306b0af0414f7f8ffb535ff0b00edc9121566bfcea9439b0946a2031b18f265305082477a2dcf03808b356495b83191710aac7daebbdf20ffd09e853dd28b2d176cfcbd8e39bc71797a1 \\x0000000100010000
-47 2 34 \\xfffff94f32fdceac63483c5020607444c813c10f83e7dd9b11d2eeb5d46e5346f621ff984fac50d69df8fd8bf1f5facb80d8c011801e818434431ebc5096a203 240 \\x00000001000001005de332fe66a07e10bff206dcf736cb3bbe6e8aab3ea7e126e7a2c354132936b8666f316dfc963749bc1950db312f95748665e486e635f74647b2fba374e50475281b1a4f182278070b5e0e65cf3b746c0241b1b20f289cf11acd10f014a9e6216bc77208c0252efcd18d006d70df6e8e4d918e2796830f3048813cc715e61409 \\x0af39040e84d3acdee68f8926c156fd056f5484f2c40b15c39a14661340a6579b9a307424d34fdd1a7c378f734817c2d2c3f5e32921d12416f00cea472515dea \\x0000000100000001ca2a94f49318ed1c9d46b4aa4b03bd19bf119337b4dee9c165ad4ed49d594838050396c84a55af06d09e4cd31ddde74d27102108d459c4a05b8602dbe81d1adc0a561b562d97399ba1947cf1a06ba00796f67a018ad364bcdb533c5a24d5d5dff43e1a0a8c65d6a05bb56867646cc222ffd4b954c858947e8a52d75714c7390a \\x0000000100010000
-48 2 35 \\xf6947d991b82957c4edc283e9b615e109ecfc0dd3aff4cdbe4a64d7cd99f8ae4f65fa1066462d731aaf66623508533f953a4fa4e02ad54337ea9294d69778801 240 \\x00000001000001002032d9be7d2b58660aadb12c82524a77a737eb891ad921e2961a1d2ae813fa2c2e6cdbad166ef0255a91877c074f5fee80a8c8978fa2dea69d82a9e6f3eb8a917b35080f83dc018a563bcd4b689feb0d17134f6fbcb315ceef6dd385acc64547eb8fcb1a55c7a21dbc8dc286428caa5c317191561b95d0820fd7af9711742587 \\x25048ced31ca2ca2ba8b9325a3d2c5532d33931c3b96135d22c92e5f592d59b5f526922df2a0b390a1abd7ee2b92b85e106a8d57986c05213c54993f738a5203 \\x0000000100000001c0c7a8ec897c7910d48e85e4d26050510550159d28098ad4053a4e8fb5abfe0720db45d9170fa441edad286e50a2294b409fc7ff7e54e411c8a046b8df38de20dc39b4c485e78da4556f3b35b72bc4e5415646a60ec6d001a5ea974cb05d20730bc42229564deb5417766d4f38859ce78adc50be37b75b2decf6a4f7e24ad342 \\x0000000100010000
-49 2 36 \\x3a1272ad23c295fdff6d075cd803e7d52a0960a4688541207a77e9614df77d8587cf30d0d254fb31ec9ec2f9c1921f8eb59d952d151e1b3c9dd3658c81a3d107 240 \\x0000000100000100ae2ac965d1fba4c93c169c7549db748e3fd0ec4b7807a1bcd366483333c0a91086047ddefce6e32a2944f0978996c07028c0b898ab02fb3240709b454c0b20fae8afea2dee9faf0bf425ad9198477a89da67b1a4140f766b8f751a20d81303baf0bf9d1a94eddc02378adc216068573204aed6888874c4e61f18e268f42cb0f3 \\x47037c99e07f661282c2acc8314c8b3aac9d7dcfc61cd7d677a2769705b1f38397942fb5f886a8ac6b096b0f049c3353d278646b9948361f9119202e428ce5e2 \\x0000000100000001b7ef9d18c29973a8abc6846ce3bfecb89fb103d20750668aa9ac6e63300cc05d88a4e76e618e9365bd441f6d0e1d10e2b267191bf90a05ba9913bc143e6d3f8ad636590d2610a07a2583f183d3ae196ee56da9c486366485bfad1e9fe3a4c0f3e657b3488d8aa16512e3e915e8f477178f6f2bbf3e34992be3dc894f3c304627 \\x0000000100010000
-50 2 37 \\x389221ff53d6d07dcb91e242553aef6e7fe510d1b444ada7b63bbfec8d9c28f735f8f89d03b87adf2df622d67a8176638893199335cef37588364022ba58ff01 240 \\x000000010000010019553984c4ef07b1c93d540da328096d8e791a15dda8f8879282c6032b44f6876875b483744be82c8b16459ba993e6ccef307ccb6214b06a139400dccd379fda7ac91410f101f84dd276a1e66b6e9781efe0344b7eb2926345ea0575865488cc1c2c0ea3ea362d3d1e2cd3f5241f92cbc8930cb6c9155aa7d3f05f489783798a \\x1794c2d24fcbddfea527cd95320d3e900855052e590b54e20d538f42286fb19d6ab50f5b566001649999d2502672007af8c3d781ee29959f1c790905dd6f5257 \\x000000010000000151090942899afb42a200ce6d0ba01df9fd79656d7172702eec94469dcb8c4e4b6b7edaf9e7d22ee298f8d5e80f540a9168aa35e5a30a8c541118d5550011d90edddf3a2454754bb797eea706b84f53787db82e2d6c2436c91c00ea200df6e4532f5a69b44df1fb3c86fb6d351bcf0ff37f70edf09ddd8df384892a12787ebbec \\x0000000100010000
-\.
-
-
---
--- Data for Name: refresh_transfer_keys_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refresh_transfer_keys_default (rtc_serial, melt_serial_id, transfer_pub, transfer_privs) FROM stdin;
-1 1 \\x0129756951c56d84ecd5a5af7d655b06a89e52746410b56b14e5d8e227624f26 \\xd689024c991c9b3a6139e3c0875f1ded910f22f9199a8cf3d9f87168738a68bd0f0406fcdd90285ed7dc2d7260b48b1a2c713a4aefebe3654c915c4d15efae23
-2 2 \\x361e5de57998416e718d7c651475274d64d6c384d6baddcf5966fd145ec7196b \\x624ff293586f9e33ab6ff72280a2d652581be70dc37d61b2852b972204a0abf927e7954ff193c9c417ada334469301cffac41ea96c293aa1f86f551cde0bfc65
-\.
-
-
---
--- Data for Name: refunds_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.refunds_default (refund_serial_id, coin_pub, deposit_serial_id, merchant_sig, rtransaction_id, amount_with_fee_val, amount_with_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: reserves_close_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_close_default (close_uuid, reserve_pub, execution_date, wtid, wire_target_h_payto, amount_val, amount_frac, closing_fee_val, closing_fee_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: reserves_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_default (reserve_uuid, reserve_pub, current_balance_val, current_balance_frac, purses_active, purses_allowed, kyc_required, kyc_passed, max_age, expiration_date, gc_date) FROM stdin;
-1 \\x5aaaa2e7202039e47d6d231071b430487230bbe44fe03310fad120f43a1fb363 0 0 0 0 f f 120 1658059784000000 1876392585000000
-\.
-
-
---
--- Data for Name: reserves_in_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_in_default (reserve_in_serial_id, reserve_pub, wire_reference, credit_val, credit_frac, wire_source_h_payto, exchange_account_section, execution_date) FROM stdin;
-1 \\x5aaaa2e7202039e47d6d231071b430487230bbe44fe03310fad120f43a1fb363 2 8 0 \\x1db2fa56550bcb94b6d488e373484844ff4e47013b00ce57df739290a0bad591 exchange-account-1 1655640570000000
-\.
-
-
---
--- Data for Name: reserves_out_by_reserve_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_out_by_reserve_default (reserve_uuid, h_blind_ev) FROM stdin;
-1 \\x11d1b66bcf52042de4cacf76b9dc02060607a58557f0f847f2d1d97102aa0b381ccd05f2f4a5929e780c5e1dae0f5073b08bfe1518ee99e15dcf296d2504621a
-1 \\x852467a9b2b862c2ccefce1f99b0c28aada9804a6d5bfc3a01e8795dcff9fbcd1b21cded3ec9d20ee0df272b5738357d685c1323597b00ddb24d0586e5c560d8
-1 \\x3e44fabace5fb0f459db6045de962689a6883771211a99b104e9f5dc1f6286e634fb8f3ec55e88bf6126f8100bfbfae0f0ea2145585ba17862af301947bd72df
-1 \\x4fca019753789ba83083eb07b2653952d6dfb47c11aab24471b4621898fdd5a73080d4c28a4626b293336252a35e499087b25c0da964857c24a05e942babf83c
-1 \\xc118a43be3715a9d1469b8a6c211fcfae0a447456d1ca95129a99afb820b40222678f819bc358930c98b77fe6dcbfd166752781eeec564fe18f3b377aa7ca4bf
-1 \\x8bd14e0caf2ae43d4877b46893c36d0fbb57006103a18c36dd279418d443c8d4794ee4b0faa1258df7aa5db7c20cb6f5791e322bc510d443f13aa2cba0948046
-1 \\x1413046d323a5bbc884d5d43a3d055314aecf35440d4753d8cd162895e15c72ca76d9e2ecf1cd4044b46bef63c9c7791c179b88d376a018920d09767f23697a8
-1 \\x22885831d3d19204025b4f2497ea0c1af8ae59e3b40f9fbb6a6dcebb31c0fc000fd2790805188113f0148f0a1483ad993d2e2fed9080187fd122cd914a49d26e
-1 \\xf38095bc89c74ad761802b0deaf0b7b94dd3e6ee232353e5053dec1d5eec8546c3e969a0e86d4e7ee0d2c50f80638fc739aee9827619d3ef529e40a4ff5c8626
-1 \\x61154adcdd414269ae78b7aeff01182402af547c82cc15d84dbb3c5c5831587ffd1eebf04a4da78f3d609e77d18884c69ab5e03425f3df76912ac7bc7413b754
-1 \\xe623ac096b83f861e2f707ba71944f25a4dd232f80e74da2cf795a7c1c0fc4d064ee9e8a930b729f91ccfcbe2ee2edd20e45ba12b53e60d3c65e95055bf1e977
-1 \\xd334ba98b8fbe0fb6a8df73c2727f830571e0e5880facc23927ce7c04b08db25f61f39273c2e0d1c0561b9c055bd8836215ff278b3d838218b591474f327b23d
-1 \\x3b49d802dd9c3e8b8ccd79b58f92e1b81b8ebd0cb8ac41a3cc66c0cb00ae7488236d752636757960157e64d10343d54f8fe2a6783e3908b4ab90b3aee2922865
-1 \\x62255d8aa461a9b663d45c4d7e20fcc9720b68e56b171fb90f946fd662a606154751278763d500e0f872d35e31fe39902b7a1824fddae47344feb41c42566cdf
-1 \\xbdf0d832960008b6ef619deda9b8692853b5bd5c048ef2cdf2f3d278c30dc0e4de378e7d6d0d441888a0e43c66de58a19f3229360c05a3b3be62ab93266a829c
-1 \\x6b8b894e2c7d18c957f39b916654cef04cc710b54ea850933e81076316afffc84475490366fe7ecda949e00d8bbc88a96c51475292a3c8713014aeb24b09afe0
-1 \\xee8618b0e296c9cc7e340ef86cb34e55bf0660476a16da6093e5fc27a4a7e2167ce797fba31cb01ecddd194fc6775e66b68938bbd10bb01cda27fdbd4ed32e99
-1 \\xf768888a9fb0fb709c75dbc50731c1367d31cb451f5bdb1d8943d401e2fda94e69d96b172f5faa660ac5c332ef8a983d66791e3261da554281a326fdf88323ea
-1 \\x8d9e557ab5391b42598705ac5aad57777b32bfb58dd3bf14e58c46b6abd80f85aa92f87ba8c37f7632dd0a6dc0f3901ca13239260bcc6462f0b822ff57e192fb
-1 \\x977ea0d13e9eaa39d08be569b33a25b975aaf53d7a5611646cd9401702e8b835802b53295e733a6af93c4c0d0c4528c7b5ab0180795802e95c007fcea5999214
-1 \\x4ecf6dbf58e0285bb95a953602938788c904b5e1d499c6c17ece226622808893ec8d6201bacd9fb94a32159a05879e5f93dcd03f0fe69a824b20c9640685cf2d
-1 \\xf7e6f4d36dd9c3bf79b2d045b25063b7c02175d52749bff822cd221d307f4574986eef4dc4bfeb5f8df6fa95cfc1a039f1a992b57bcfe25054b910b9f0b5867d
-1 \\x4f40e4a013d6a6e39a29a046d694035cff0a039eb6fb69cdbbd614c1bdc93d1edbc7e66e96e09857f544fba053810f71ee18fa34e845d54838cf4c8d02dfb496
-1 \\x033dec4b2ebffbaab4123fa00bba226f6e615c5b1372d0c44a9e106f6904d55a2f7c52e7f06207e6d15a4314f5e15422475a1d55d98a4efb662128c0f058e02d
-1 \\xb55545c1457a869bfd62efb837eef2a97293aeb9a05f6b3a9df96730aef30b14b9e2699fbf549c1782976396c3f231d625e8e9eecb67c0e7d458f69a3c813944
-1 \\x210dfb838a5c6b62bdc636c8ca6958aa8d581c2fd5f6dce9713d4aca873f1ba9fad926738249b75e3c8da0b6eccac3ef49d859bd43dabe511a4ec7adcacea23e
-1 \\xe4d7c150ff14772a9417ffe332bf3b9016c99a533b2dfb5a79b7b48c46c0866f1138caa151c70b723d6f3dfbbbcde636d26b834616ce54507ad72c3d1cebca2f
-1 \\x125e1ae7aaf3a596c6d2567646981f1e8f87944efa3eb3abedbe77051fc30602428a880852395b0d38e2262482dc4fe1c3df58c220224e990a9139dd64ef7733
-\.
-
-
---
--- Data for Name: reserves_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.reserves_out_default (reserve_out_serial_id, h_blind_ev, denominations_serial, denom_sig, reserve_uuid, reserve_sig, execution_date, amount_with_fee_val, amount_with_fee_frac) FROM stdin;
-1 \\x11d1b66bcf52042de4cacf76b9dc02060607a58557f0f847f2d1d97102aa0b381ccd05f2f4a5929e780c5e1dae0f5073b08bfe1518ee99e15dcf296d2504621a 333 \\x0000000100000001306a51fb331c4d538e5ce008d1a582addb306548de0d0d43cde43ea050fc8866f5ab696a31890bb92dc394d670b5d3d4ef5942985887b0c825072f50b069d2c0058df02826a9aad4d82f75413e9fad7c05353b955e7e17a9baadba839592ce4117ab07b3cf9cfb230ea20399c50cfba31665be2a75202491f3271f6dbdf0ad52 1 \\xfde553731a1e7d44e99faae20ea0788a6f24e78ee67b9788391128f3e3b96f5c979ce502e9f00a6f767e5a879799e2ae18faddee89cfb987ca45fa8932dcf308 1655640574000000 5 1000000
-2 \\x852467a9b2b862c2ccefce1f99b0c28aada9804a6d5bfc3a01e8795dcff9fbcd1b21cded3ec9d20ee0df272b5738357d685c1323597b00ddb24d0586e5c560d8 57 \\x00000001000000018b401365d0aa4fe014f2ba42af9bfd99683c124bbd330625d8ce5fb37e149624bc3d83d164ecec242ed9075430d600cacaedc88bc5e3d1acca25b2a36b9f4504fd02c7d4fad7c0ab33a6776cb0dcf5c2a59233b5aac1020aef85aaa85a1cffd98de30397b1efc72ae336c266553fc59a3d9956598e59ee8832c6f148dbb1f393 1 \\x11ccc307707ed59cd6b74c924d038e72aa0b9bfd80d370927f434bb2f6d2d0c90804836b945442b3eb112fcc6d7282a3626982dcbf2e6cb49f7345360c99d300 1655640574000000 2 3000000
-3 \\x3e44fabace5fb0f459db6045de962689a6883771211a99b104e9f5dc1f6286e634fb8f3ec55e88bf6126f8100bfbfae0f0ea2145585ba17862af301947bd72df 194 \\x0000000100000001559209240d4dac70c87ad82f3b4be7b1c5a689cab11a78506c0f4c856663177fdda0196d61d50e44df76d3d982955cb5694b7e9f10d547892e53c1f6ebb51bf4ffcf0d5a13604845fe4e0aa58e58685bd3c8602037b46476e499fb4219058c36ef834c2aef480e8ab250942a5d6bdcfd841a2a7bdf23de57c33f4d876725b799 1 \\x260a04eeb917d739c5d5cba3b0594ddb129cfadf67a4699634584bc6ab3941900698abbdb2db8306170a467bd72aed4238f6b32d87ba5a2ad671125e54e97b01 1655640574000000 0 11000000
-4 \\x4fca019753789ba83083eb07b2653952d6dfb47c11aab24471b4621898fdd5a73080d4c28a4626b293336252a35e499087b25c0da964857c24a05e942babf83c 194 \\x00000001000000012bfad807bd147bc6918cfb627af53e3d9acc9ff7f122c259a70a414c22275d1bd7aef8c83160abfd957b9183a99e3695a44f42599b2dcfde0a027963984b99d69f742919c68dca435fcfb05c4bf583565f66fce9fbf143c42672e7d7f2aaccd3febe530045d2b13aa15fbf2ae12e83e9d69721b666bddd60b0639efddaafbe3d 1 \\x7f31081b8a4ddf89570e08e7a67d94a893ddfe7c99c9e0491ad70775eb9840626e66d091f16e89c313ff63d47911b0ea2717ec548a17a59f177c43d02b7a0307 1655640574000000 0 11000000
-5 \\xc118a43be3715a9d1469b8a6c211fcfae0a447456d1ca95129a99afb820b40222678f819bc358930c98b77fe6dcbfd166752781eeec564fe18f3b377aa7ca4bf 194 \\x00000001000000015a4fe9fb8b4697d2234c3303087c8fdf9e7d555274ed139ce0d811284aa2af6cbf69090979ba55da0577796af9d9a2b7399e68335f7d0b123f581d32b78af160f3efda5c08bc1d75df9a45ec49985ca1790beedb9bb82fb08dd30361461971b3863aaf6d65597e7b8fd6bf6fdc4902de13c5ab6fe96d49dae07d9d55f97af2a7 1 \\xc5ad5a541c3b90b5c56b6b41d0fecbea64a8d2477f9bd6fcf361ca8c8b9178d0c04f24e73ef6cdd216990a33d2b9314a833801064f6ba20602bcc7e1672e6701 1655640574000000 0 11000000
-6 \\x8bd14e0caf2ae43d4877b46893c36d0fbb57006103a18c36dd279418d443c8d4794ee4b0faa1258df7aa5db7c20cb6f5791e322bc510d443f13aa2cba0948046 194 \\x000000010000000144927ed6b7f39937d38555da136b3a3cb36ca0579cf9964bfca1588aa8ca2f77b2834e23b174e32e20632402a7009945b083e2161390ef9a77e544eb994504b729e0c8803b2024d7f19444c2dbe33ecfda774ff1a5b3b0ba2955a2a3ddc082fb05485f63a322f9a5627b72883cf118fc9083422e89fa982de3b6eb98988655e2 1 \\x39a1a4b0c88aa47f3fe42227ea453dbeb0fdde9c16805a00a69e5a7f1d7cabd611dbad02bed19ab7b33149ebec71c340aaecd3baf5904b274ddf3feb80015c03 1655640574000000 0 11000000
-7 \\x1413046d323a5bbc884d5d43a3d055314aecf35440d4753d8cd162895e15c72ca76d9e2ecf1cd4044b46bef63c9c7791c179b88d376a018920d09767f23697a8 194 \\x0000000100000001830cd74f4e84de64e4c8569005defa2cc15bf35c423872aa69d07a9712bf9e594a276ac1950e61455254088fe745c413e0d6cebbe6e3fb09e9b6afd992577fb10a3e916db4451c1fa784e816d62bcdb2318ad31035b20a8b5f4b62f7d9a5a7567672f1d9ccb59fc15639c939fa51e107a0ab2c07ff3afd712a36dc3b2742329b 1 \\x3e0037b45bd2a943a23aa0f9af3f2b4283dd73c029bcb54cd4cf2bfaa513cdf3a46067a2d8c785907fe593118cc38315c1e6572955d2c16725204b01ca0d1503 1655640574000000 0 11000000
-8 \\x22885831d3d19204025b4f2497ea0c1af8ae59e3b40f9fbb6a6dcebb31c0fc000fd2790805188113f0148f0a1483ad993d2e2fed9080187fd122cd914a49d26e 194 \\x00000001000000018e0c5d7b8c253e9aa185be7347ef761faadd7221607fb715800a05b91ba614c21128628a45dcf200183d5737b3f498121713fcd0fa2ee0ec8d7b29da9f96606cd2299bb6cfc07b49f27351c405be21b6105b51fbd354ff951653bf94a5774ea8dcb95579a6ac52764196af501bae42386cca84c2ce7765a8886579c7050671d0 1 \\xad910ccc19e9032f5feab90165deef132eed1b60902d69f095f1e2d3d688c14898c448b23369ee31b215b92ff09d628528aa2887d58b73740851f16e07fdff06 1655640574000000 0 11000000
-9 \\xf38095bc89c74ad761802b0deaf0b7b94dd3e6ee232353e5053dec1d5eec8546c3e969a0e86d4e7ee0d2c50f80638fc739aee9827619d3ef529e40a4ff5c8626 194 \\x00000001000000018d362fd37e041e7a8fd5beac2091e539ae2ed672d0b88f5d35655f98589d50abdca4b2a82ac74617c4589d2bbab5c098831e7023ae58b586132aec314411f0e4711de6eb28f7b748c946d14871719e7aeb468187aee7d6ccb1ffd477754b3a30387bad7fbfa9f2fcd0c1ab9279e1e23c9880be8d439cb3b8789015b4a7e4adca 1 \\x2ea412257567726b13a20583bd86d6c595c2a0588cf16acaca2121266c7cbb58e0969f3e3c7421306f6a3842592cab6a47e929d2da30cec146715ad0fdb9dc09 1655640574000000 0 11000000
-10 \\x61154adcdd414269ae78b7aeff01182402af547c82cc15d84dbb3c5c5831587ffd1eebf04a4da78f3d609e77d18884c69ab5e03425f3df76912ac7bc7413b754 194 \\x000000010000000178482b1f2038030dc5b9af5456440f11f520a1fb6e9f3a643e27a5d131a521775aba226c8fe9830a4d8e4fe51ce01aa438de978ecb16121f8a50988518525b1ff7a1bc04adf1c7ad0efbccb4a13fb91f4e850a6c191c79cc1cebd7106ff0cacfb5e51b2298c3abc290d9d811e62c0a88292d748255bf7ec3341c6ecc64a6037c 1 \\xad38b5db8f768a28ccb6988dd86e5b01e9c068f7254da80c47b41ca1c5d77c23dc174be3f96f25600b40fd56bead65df4bb3cf4e79861341859ed8424ef51803 1655640574000000 0 11000000
-11 \\xe623ac096b83f861e2f707ba71944f25a4dd232f80e74da2cf795a7c1c0fc4d064ee9e8a930b729f91ccfcbe2ee2edd20e45ba12b53e60d3c65e95055bf1e977 128 \\x000000010000000176c6f7a4960c5964599f800af2a8fa7fa6861e92016f18555284c75608a85a9c20ab8f4070e1d6fb5b053a71a67ee588c80c040a7d9bf6c4bfedd2f326ff0191921de9eb14f52fabbd0fa1e87f644bfba7a1e82e7c14047138913c200a4e98bad78d0ff806fb774c1ee9a914d864b781bf111581e39d8bfba6bcb2dac7fd884e 1 \\x77264f8fa37ff6a348e3654f6e4742d33bc903f930fbc7ece35321a84b612208acdce6c528d51422ff9e199b0935571e5f85f4b163a095027f39385e9cbc7906 1655640574000000 0 2000000
-12 \\xd334ba98b8fbe0fb6a8df73c2727f830571e0e5880facc23927ce7c04b08db25f61f39273c2e0d1c0561b9c055bd8836215ff278b3d838218b591474f327b23d 128 \\x0000000100000001788ce69d5b342a234f9d938e2d8d420474becfe5f85d5535f45220798cc22a35d86a6e69c079cdd54d56e62378c461c397133780b2e3b014a4d9f0557174a08643da9c7089147206caa9763ff28a13391109060a96f5e6a323ee327486ad19d12118c16f766ac39e47c386a02967b56ee97ac82015221c887883a674a0743f8f 1 \\xb5d0f74d09d1ff53fc261e083a1d340a4ce3360228d1afce0baab11f16e2d45c5ecc175c7c7eeead8b42bba3bc8458bbb1aa81067b9c9955b614e75e60beed01 1655640574000000 0 2000000
-13 \\x3b49d802dd9c3e8b8ccd79b58f92e1b81b8ebd0cb8ac41a3cc66c0cb00ae7488236d752636757960157e64d10343d54f8fe2a6783e3908b4ab90b3aee2922865 128 \\x000000010000000125aca229b90a00a30facab9b1ad037970efa19ae5c31d71ad2f82bfb6350e54af7ad5f491fa71dfaae140469aafd80772ee9c1cd51fc3bc69ee7aded85962ff8a78ffe67a59101db6c03380ddf016b6da817ea6501a00e8e7a14619ec994ace51fb26f670db501431911729f99cebc2a69a819a54c8c978610814c00f6d397ee 1 \\x9193a90b43db22607a8547fd562ded8e6d2a2a74f0fcfe61130aecf95abcc5109e29fc0f8c9a432a026b92d6c19bb4821e5471d8661bf0d16f91fc0ccdf2b90b 1655640574000000 0 2000000
-14 \\x62255d8aa461a9b663d45c4d7e20fcc9720b68e56b171fb90f946fd662a606154751278763d500e0f872d35e31fe39902b7a1824fddae47344feb41c42566cdf 128 \\x00000001000000016f0f0b272593e180ff399b4669e9642379529757a4df6c9fc15ba083a486b6278bb7430313477bcf086341c7fb0b9f745d741ba1d9cb62d53ccf1b83c524d9304e13822d23084c30dd9a75392107345ebe8acc16bbc894d43bcc088be6931383a9d911748f2831d9fe212c950aa17d788e5b55fda20ef06c72cccf6f7a9ee412 1 \\x1a2ff059dcd042007f6b91eb31abfb89cc47c579acfbe2061d0f6c78e54780c3ba9c53365866a8032bffdebf4615f81adf300f104753d2f965612b4399e6e504 1655640574000000 0 2000000
-15 \\xbdf0d832960008b6ef619deda9b8692853b5bd5c048ef2cdf2f3d278c30dc0e4de378e7d6d0d441888a0e43c66de58a19f3229360c05a3b3be62ab93266a829c 113 \\x000000010000000158e1f2a1b52f6340c43f743e8e68bf1143c77f291896a628ed763baba7d4a8913e42911e0a7a4ce287a105bd6ddd6f6ff3e8e9d0ed50a13a687b1c0e9019db11a716e647859f84e79138dba05267346f01a961249acd45ce0f1848eb3545f64a6463f251b83c25c5deb2b070e294c3abd9356524bd3d60caf2a30c5cde33d810 1 \\x32b298176d59e4a7be51244482e98a679c4ef57dfa48d11cee794166a0698213e97cfa767c146e9de84c3944125e05f9318d5b3af236153370220ba9ba9e4e0a 1655640585000000 1 2000000
-16 \\x6b8b894e2c7d18c957f39b916654cef04cc710b54ea850933e81076316afffc84475490366fe7ecda949e00d8bbc88a96c51475292a3c8713014aeb24b09afe0 194 \\x0000000100000001415a583f8fd7ae8b7a153aba6a5eb096ada7e944823d286e965e64c37cf249fa3b8146d185c1b93b052280353c6011c32ff40b994413539313f345b8b0d13cc86486a46add6fd080335d722a8b27ca7daee1190b75b39907513ca97d0ec3188646fcba2178656482f5f3fa8fe13dbf4d1459d9671c4dc3e16b7878c5fb8b8724 1 \\xde1d7af7fe490adc4d947ad48849420df0649012bdbfb726e717a0bab2d120dc4bfa7c7a508c695b654adbeaa6688895336e20705d5059480d01fd0f3231250c 1655640585000000 0 11000000
-17 \\xee8618b0e296c9cc7e340ef86cb34e55bf0660476a16da6093e5fc27a4a7e2167ce797fba31cb01ecddd194fc6775e66b68938bbd10bb01cda27fdbd4ed32e99 194 \\x00000001000000018be8266df6a71ae0a3d7d27d38f7d21057fa6486747f0b8d4e308c5b6516083bc50124367e6639a56e7eeba55b4813be2b54bb0e10658457faba9a86014de09cf6c1ea56ce11f5dd82a89832932815effd12bf9e5a65bde35643921a78f8ed9ccce8670882c88e4bbb78a4e94405d65b2c7ddc3968b21f8f7587756220cdd8e7 1 \\xfd97c879da147122a21d13f42224d68140997ca9449caa73be521681b5134fc7fba3a3e5e441e3065d13262e4f00833daac59f7bcb21e1ab596ce9d88b7c9a03 1655640585000000 0 11000000
-18 \\xf768888a9fb0fb709c75dbc50731c1367d31cb451f5bdb1d8943d401e2fda94e69d96b172f5faa660ac5c332ef8a983d66791e3261da554281a326fdf88323ea 194 \\x0000000100000001926c5e4a601bcc508f899eabec266aca2880df8b801259878dee6fae526fb2b3526fbfdfd1b37669ce8a2142b3aebc0e154b105c69b5b3df4b2511133918ca8a234a750ed0711eb5531483a52747da9b8d8148d2ef87b36e2167c2ab183fe2538b08cbee99ab3bdc10e420e69efaf93dfaf80d33893d37f7509cd4b274e4d59d 1 \\x8428a3bbb444726331bd573ddabe6240657c51ce07b8b65d087e549fbc84f277a3c6c71f1d346ea6166b9fcf7b8a68e379048edbce506651b3100286bf1aaf09 1655640585000000 0 11000000
-19 \\x8d9e557ab5391b42598705ac5aad57777b32bfb58dd3bf14e58c46b6abd80f85aa92f87ba8c37f7632dd0a6dc0f3901ca13239260bcc6462f0b822ff57e192fb 194 \\x0000000100000001027521e9418f5366f04e08524822cabff5a19c663d4c5c5de7704bf8c31d09f2cb4ca777b8d6d774fafcb3d82420645f2b6cfe43143d490599cdc723980e8327b2dc1c9d050c1983ed3274d1113f3d84c556bee2c3816cd997f3005e294f86360cbd949919880b661f1972476a842a4d244a993192f86a54c8c33b48534f4ff8 1 \\xcfc7f34462b486b1fcef63a7671286d3f0a1eff543e1f714250325e202acddf3ac7f314821c4a33e1c620e51271127faf6579c3a3a7bd5eadfd09f279a387d0b 1655640585000000 0 11000000
-20 \\x977ea0d13e9eaa39d08be569b33a25b975aaf53d7a5611646cd9401702e8b835802b53295e733a6af93c4c0d0c4528c7b5ab0180795802e95c007fcea5999214 194 \\x0000000100000001797897bf2f12dafb8fd8729df286a4858dba622d23275312e938a26735c63231846b7a9f3c0b78f9f11256325ea1340f3af784467a0bf66e52101f098209c28219372752ffa353ca4b15867a053ed9ecd0a567aaef29fe67829e58b96708bf18b2b08df5fb3dbde4e58bfcda9a74aab4820387fa399986ac4fd3ea0ee49257d7 1 \\x2dece29d6feb83e96eba617b9bd11eb4a0b7a0eebf5cb9e1d2cdcaf9c6a47d966149ac1d0f8b09402d81f4b3c1f51d6b8474ec0eaaa5a963ebe46f99d2e5850e 1655640585000000 0 11000000
-21 \\x4ecf6dbf58e0285bb95a953602938788c904b5e1d499c6c17ece226622808893ec8d6201bacd9fb94a32159a05879e5f93dcd03f0fe69a824b20c9640685cf2d 194 \\x000000010000000140807edc9c108c9130f6deba97c154c442a48f8d19907d7eb4d51432e2346b2e24ecefa76c1126aec76bb71109609d4381b46e5ba98c2713ed044208544a36a6913130f47f7595b2981d996328fab0e82f0b6f2033f51633dfa2a296df61c8c51edc6360886a75c8a37e6f0d517443f622e3295eb2407ef60cd912478aa7b244 1 \\x9fe3ecaf85367effd71d72790fc34ab7ef00ce8ca1d0a775ccadd78b8668145f11aca82af7888db4445a5742f1fda2fb33e20fba69c0c4b618ebf9c48e491602 1655640585000000 0 11000000
-22 \\xf7e6f4d36dd9c3bf79b2d045b25063b7c02175d52749bff822cd221d307f4574986eef4dc4bfeb5f8df6fa95cfc1a039f1a992b57bcfe25054b910b9f0b5867d 194 \\x000000010000000109b1b4b5413ed4d233f27003d10df6fdebd5ab435ebcc005f9dd5421e6e1ebb0ccc3087766c70fc01190f3fde03f64e996c118b16c4b088982bb96025da45abaad399a537697919211fa3efb95ab19b0f15f35e483339dbd11cdf7e8ee802f2d064b6cfbeffc618598ff49eb3fad0121eae94a198498fd2c26d356b3043910ab 1 \\xc1633f8d979fddce49a818c2c866e0b75df026e66bb205378278bf0f09c9c03f88105544223674e4d862084ec37d6541bf78a26da3c81922f08328fe7224a80a 1655640585000000 0 11000000
-23 \\x4f40e4a013d6a6e39a29a046d694035cff0a039eb6fb69cdbbd614c1bdc93d1edbc7e66e96e09857f544fba053810f71ee18fa34e845d54838cf4c8d02dfb496 194 \\x000000010000000157db256c1e96b2a389a0a493b666acdcdb78cd14a6c6a85f43d587ed721ddb9153e43462bb29ebf4db96d5ff6bda175eb22c8b9d39ab4a32df16cf1394074dbce9d601dc759c462cc6db325d18aaf55aa973c7e1148a37565710b774c55aafcfe20f7a0a201ac13dec7618c51dab37834d7c4c45c29f135b4909426c1f957bbe 1 \\x04a1203c8917663a4ccc3be9c23bb33e07cc200bfe1da774aca035c675b04e8df3b10b76e4b03224e26b51ec48a2a5cb048babef3fa252d68a88f312a7964b08 1655640585000000 0 11000000
-24 \\x033dec4b2ebffbaab4123fa00bba226f6e615c5b1372d0c44a9e106f6904d55a2f7c52e7f06207e6d15a4314f5e15422475a1d55d98a4efb662128c0f058e02d 128 \\x00000001000000017702b16ce55e70614ae3ea42fa476ad7ddc1253ec312743a2cb10ecbf569dcdd5a571773fe2b728e08f5073536afb4c8ff60921d6f3b1f71518324aab4d4b6d4c8456bbf42065a7e700b09b00fa0ef62800c46c5543e94cd24678bfb5de0f110df1eaea8771c500298677db6ae1a3bc51971ab035e7591f5f224895264de8e89 1 \\x4c37dd0d461c3b3a19bc084ca053fe95c1ad7a0e5da635d71074b4afd8b2ecb4f6775b2e6f9dddc920132929d9d1561c924afaf745e5df3b4e5f2d084eacfc08 1655640585000000 0 2000000
-25 \\xb55545c1457a869bfd62efb837eef2a97293aeb9a05f6b3a9df96730aef30b14b9e2699fbf549c1782976396c3f231d625e8e9eecb67c0e7d458f69a3c813944 128 \\x000000010000000133b57573ac8fb9f6c0aeb5e7f31b3df9b18b445802c80cb7947acb177dff17c333b7b67bf1d40b5252bb76bbb8a95b4aa32fc42d80b6189f93a948e5a5b02c1c733c033848bbaba305ebbb6abc750e3391c245db2f05dfc65cf1a5685ed533f41cb52b259c15d681c3f22c7ebc6fc18af4009b011d5540b50255e57d0d76e9fb 1 \\xee1dcf5ffe1313521e5e0358c46bcdcdf0f29968e88f209d13785a2fea1eb3a2e8d7300c9f706b8c4f7b61d7754e39bf2d7c3f257768b719c587cf88518f4f0c 1655640585000000 0 2000000
-26 \\x210dfb838a5c6b62bdc636c8ca6958aa8d581c2fd5f6dce9713d4aca873f1ba9fad926738249b75e3c8da0b6eccac3ef49d859bd43dabe511a4ec7adcacea23e 128 \\x00000001000000014b63d2f9201cb4c318f31f6af26dfac65850142eed0dcfc888174180a16c4315cee4561bb115b170d8897576ccbc583ad35398af50afe644e845f14975155a5270d0ff6e421a3ae2c38df4a6e9f9f0f4e672e2a43c70440bc03ff30e954c4265441467f822b325f27f95fc2281696b111a3250293193500441218b47686dea58 1 \\xbaba9b9258c74f7801967e2f1ed96870c588f5b4c88ada496db8f265619d2a3d7b0e689b764822867923a42ad81e9419f4a122ba7503cf0421e652c32218cd03 1655640585000000 0 2000000
-27 \\xe4d7c150ff14772a9417ffe332bf3b9016c99a533b2dfb5a79b7b48c46c0866f1138caa151c70b723d6f3dfbbbcde636d26b834616ce54507ad72c3d1cebca2f 128 \\x00000001000000018f1cb81b555f352b98dda79393ffdfc278ea07b9e54b39d237835ae5f4ebd42891ee27c36a3ea7eb4f6b02259ed2cc8d4bd43d6837ede22a8d1dc4cb17cd04bbb543a538546d83fdb7ed66dbdd8ac67bbd6e63b75b08226a23743d13028599060792f86b41522040522af008dc5cb636d4abda58952e45065da5ff00812c4fb5 1 \\x1d51b2fac0cfcae46b2d659cc2c87235bb351c20f5c217660a170890544dfc8356cebde3863dabbce0e87aadb89de207723b91aec263131e58217a89803c470c 1655640585000000 0 2000000
-28 \\x125e1ae7aaf3a596c6d2567646981f1e8f87944efa3eb3abedbe77051fc30602428a880852395b0d38e2262482dc4fe1c3df58c220224e990a9139dd64ef7733 128 \\x00000001000000017f1d005a2a9203470fe393f2ffd3d8c9b02691e7b00131aec1638dbad4f0cc4fcfa722ef4cb312a5c36ecc17e5af8b1597b27231986209b87f877b53bd0ddbc75c9ceb0bdd6d7e1a72d58be91f4cbf63ca60b7cdbdcb337c924791a99dc8d34aa1b186db02b461e16571c1dc1fe5128ed2614008fd8f8d5324ad80b9ff035c0e 1 \\xe201f6d1967f1c79cddc624c4762723754efbb797646119cd663ca0ee20f4a37c8705a72920a57433b82999d19b76bfcdbba618e4d9ac706abe575c87c6c7605 1655640585000000 0 2000000
-\.
-
-
---
--- Data for Name: revolving_work_shards; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.revolving_work_shards (shard_serial_id, last_attempt, start_row, end_row, active, job_name) FROM stdin;
-\.
-
-
---
--- Data for Name: signkey_revocations; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.signkey_revocations (signkey_revocations_serial_id, esk_serial, master_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wad_in_entries_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wad_in_entries_default (wad_in_entry_serial_id, wad_in_serial_id, reserve_pub, purse_pub, h_contract, purse_expiration, merge_timestamp, amount_with_fee_val, amount_with_fee_frac, wad_fee_val, wad_fee_frac, deposit_fees_val, deposit_fees_frac, reserve_sig, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wad_out_entries_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wad_out_entries_default (wad_out_entry_serial_id, wad_out_serial_id, reserve_pub, purse_pub, h_contract, purse_expiration, merge_timestamp, amount_with_fee_val, amount_with_fee_frac, wad_fee_val, wad_fee_frac, deposit_fees_val, deposit_fees_frac, reserve_sig, purse_sig) FROM stdin;
-\.
-
-
---
--- Data for Name: wads_in_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wads_in_default (wad_in_serial_id, wad_id, origin_exchange_url, amount_val, amount_frac, arrival_time) FROM stdin;
-\.
-
-
---
--- Data for Name: wads_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wads_out_default (wad_out_serial_id, wad_id, partner_serial_id, amount_val, amount_frac, execution_time) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_accounts; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_accounts (payto_uri, master_sig, is_active, last_change) FROM stdin;
-payto://x-taler-bank/localhost/Exchange \\x119dc0cafa9281232f37301cf780a12f9b0cf252e87ea4d336c276377ffe77a3ca9acf5e5ba432ac03c1fb443deef4c634038f10fd747e710828172f1b4e4307 t 1655640564000000
-\.
-
-
---
--- Data for Name: wire_auditor_account_progress; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_auditor_account_progress (master_pub, account_name, last_wire_reserve_in_serial_id, last_wire_wire_out_serial_id, wire_in_off, wire_out_off) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_auditor_progress; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_auditor_progress (master_pub, last_timestamp, last_reserve_close_uuid) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_fee; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_fee (wire_fee_serial, wire_method, start_date, end_date, wire_fee_val, wire_fee_frac, closing_fee_val, closing_fee_frac, wad_fee_val, wad_fee_frac, master_sig) FROM stdin;
-1 x-taler-bank 1640995200000000 1672531200000000 0 1000000 0 1000000 0 1000000 \\x2cc20db7f38de122d90c286fe3954a28cd9d942dd6d849a80838d71c1be3f5ce1325a61fd7b576f139a4ca72b2407922e0dc87cda6e48b58be95c3a77e95be0b
-\.
-
-
---
--- Data for Name: wire_out_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_out_default (wireout_uuid, execution_date, wtid_raw, wire_target_h_payto, exchange_account_section, amount_val, amount_frac) FROM stdin;
-\.
-
-
---
--- Data for Name: wire_targets_default; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.wire_targets_default (wire_target_serial_id, wire_target_h_payto, payto_uri, kyc_ok, external_id) FROM stdin;
-1 \\x1db2fa56550bcb94b6d488e373484844ff4e47013b00ce57df739290a0bad591 payto://x-taler-bank/localhost/testuser-ljgqtzra f \N
-2 \\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660c payto://x-taler-bank/localhost/43 f \N
-\.
-
-
---
--- Data for Name: work_shards; Type: TABLE DATA; Schema: public; Owner: -
---
-
-COPY public.work_shards (shard_serial_id, last_attempt, start_row, end_row, completed, job_name) FROM stdin;
-1 0 0 1024 f wirewatch-exchange-account-1
-\.
-
-
---
--- Name: account_merges_account_merge_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.account_merges_account_merge_request_serial_id_seq', 1, false);
-
-
---
--- Name: aggregation_tracking_aggregation_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.aggregation_tracking_aggregation_serial_id_seq', 1, false);
-
-
---
--- Name: app_bankaccount_account_no_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.app_bankaccount_account_no_seq', 12, true);
-
-
---
--- Name: app_banktransaction_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.app_banktransaction_id_seq', 2, true);
-
-
---
--- Name: auditor_denom_sigs_auditor_denom_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditor_denom_sigs_auditor_denom_serial_seq', 1269, true);
-
-
---
--- Name: auditor_reserves_auditor_reserves_rowid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditor_reserves_auditor_reserves_rowid_seq', 1, false);
-
-
---
--- Name: auditors_auditor_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auditors_auditor_uuid_seq', 1, true);
-
-
---
--- Name: auth_group_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_group_id_seq', 1, false);
-
-
---
--- Name: auth_group_permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_group_permissions_id_seq', 1, false);
-
-
---
--- Name: auth_permission_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_permission_id_seq', 32, true);
-
-
---
--- Name: auth_user_groups_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_groups_id_seq', 1, false);
-
-
---
--- Name: auth_user_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_id_seq', 12, true);
-
-
---
--- Name: auth_user_user_permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.auth_user_user_permissions_id_seq', 1, false);
-
-
---
--- Name: close_requests_close_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.close_requests_close_request_serial_id_seq', 1, false);
-
-
---
--- Name: contracts_contract_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.contracts_contract_serial_id_seq', 1, false);
-
-
---
--- Name: cs_nonce_locks_cs_nonce_lock_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.cs_nonce_locks_cs_nonce_lock_serial_id_seq', 1, false);
-
-
---
--- Name: denomination_revocations_denom_revocations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.denomination_revocations_denom_revocations_serial_id_seq', 2, true);
-
-
---
--- Name: denominations_denominations_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.denominations_denominations_serial_seq', 424, true);
-
-
---
--- Name: deposit_confirmations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.deposit_confirmations_serial_id_seq', 3, true);
-
-
---
--- Name: deposits_deposit_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.deposits_deposit_serial_id_seq', 3, true);
-
-
---
--- Name: django_content_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.django_content_type_id_seq', 8, true);
-
-
---
--- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.django_migrations_id_seq', 16, true);
-
-
---
--- Name: exchange_sign_keys_esk_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.exchange_sign_keys_esk_serial_seq', 5, true);
-
-
---
--- Name: extension_details_extension_details_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.extension_details_extension_details_serial_id_seq', 1, false);
-
-
---
--- Name: extensions_extension_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.extensions_extension_id_seq', 1, false);
-
-
---
--- Name: global_fee_global_fee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.global_fee_global_fee_serial_seq', 1, true);
-
-
---
--- Name: history_requests_history_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.history_requests_history_request_serial_id_seq', 1, false);
-
-
---
--- Name: known_coins_known_coin_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.known_coins_known_coin_id_seq', 14, true);
-
-
---
--- Name: merchant_accounts_account_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_accounts_account_serial_seq', 1, true);
-
-
---
--- Name: merchant_deposits_deposit_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_deposits_deposit_serial_seq', 3, true);
-
-
---
--- Name: merchant_exchange_signing_keys_signkey_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_exchange_signing_keys_signkey_serial_seq', 10, true);
-
-
---
--- Name: merchant_exchange_wire_fees_wirefee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_exchange_wire_fees_wirefee_serial_seq', 2, true);
-
-
---
--- Name: merchant_instances_merchant_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_instances_merchant_serial_seq', 1, true);
-
-
---
--- Name: merchant_inventory_product_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_inventory_product_serial_seq', 1, false);
-
-
---
--- Name: merchant_kyc_kyc_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_kyc_kyc_serial_id_seq', 1, true);
-
-
---
--- Name: merchant_orders_order_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_orders_order_serial_seq', 2, true);
-
-
---
--- Name: merchant_refunds_refund_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_refunds_refund_serial_seq', 1, false);
-
-
---
--- Name: merchant_tip_pickups_pickup_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tip_pickups_pickup_serial_seq', 1, false);
-
-
---
--- Name: merchant_tip_reserves_reserve_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tip_reserves_reserve_serial_seq', 1, false);
-
-
---
--- Name: merchant_tips_tip_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_tips_tip_serial_seq', 1, false);
-
-
---
--- Name: merchant_transfers_credit_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.merchant_transfers_credit_serial_seq', 1, false);
-
-
---
--- Name: partners_partner_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.partners_partner_serial_id_seq', 1, false);
-
-
---
--- Name: prewire_prewire_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.prewire_prewire_uuid_seq', 1, false);
-
-
---
--- Name: purse_deposits_purse_deposit_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_deposits_purse_deposit_serial_id_seq', 1, false);
-
-
---
--- Name: purse_merges_purse_merge_request_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_merges_purse_merge_request_serial_id_seq', 1, false);
-
-
---
--- Name: purse_refunds_purse_refunds_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_refunds_purse_refunds_serial_id_seq', 1, false);
-
-
---
--- Name: purse_requests_purse_requests_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.purse_requests_purse_requests_serial_id_seq', 1, false);
-
-
---
--- Name: recoup_recoup_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.recoup_recoup_uuid_seq', 1, true);
-
-
---
--- Name: recoup_refresh_recoup_refresh_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.recoup_refresh_recoup_refresh_uuid_seq', 8, true);
-
-
---
--- Name: refresh_commitments_melt_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_commitments_melt_serial_id_seq', 2, true);
-
-
---
--- Name: refresh_revealed_coins_rrc_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_revealed_coins_rrc_serial_seq', 50, true);
-
-
---
--- Name: refresh_transfer_keys_rtc_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refresh_transfer_keys_rtc_serial_seq', 2, true);
-
-
---
--- Name: refunds_refund_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.refunds_refund_serial_id_seq', 1, false);
-
-
---
--- Name: reserves_close_close_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_close_close_uuid_seq', 1, false);
-
-
---
--- Name: reserves_in_reserve_in_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_in_reserve_in_serial_id_seq', 22, true);
-
-
---
--- Name: reserves_out_reserve_out_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_out_reserve_out_serial_id_seq', 28, true);
-
-
---
--- Name: reserves_reserve_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.reserves_reserve_uuid_seq', 22, true);
-
-
---
--- Name: revolving_work_shards_shard_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.revolving_work_shards_shard_serial_id_seq', 1, false);
-
-
---
--- Name: signkey_revocations_signkey_revocations_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.signkey_revocations_signkey_revocations_serial_id_seq', 1, false);
-
-
---
--- Name: wad_in_entries_wad_in_entry_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wad_in_entries_wad_in_entry_serial_id_seq', 1, false);
-
-
---
--- Name: wad_out_entries_wad_out_entry_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wad_out_entries_wad_out_entry_serial_id_seq', 1, false);
-
-
---
--- Name: wads_in_wad_in_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wads_in_wad_in_serial_id_seq', 1, false);
-
-
---
--- Name: wads_out_wad_out_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wads_out_wad_out_serial_id_seq', 1, false);
-
-
---
--- Name: wire_fee_wire_fee_serial_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_fee_wire_fee_serial_seq', 1, true);
-
-
---
--- Name: wire_out_wireout_uuid_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_out_wireout_uuid_seq', 1, false);
-
-
---
--- Name: wire_targets_wire_target_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.wire_targets_wire_target_serial_id_seq', 4, true);
-
-
---
--- Name: work_shards_shard_serial_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
---
-
-SELECT pg_catalog.setval('public.work_shards_shard_serial_id_seq', 1, true);
-
-
---
--- Name: patches patches_pkey; Type: CONSTRAINT; Schema: _v; Owner: -
---
-
-ALTER TABLE ONLY _v.patches
- ADD CONSTRAINT patches_pkey PRIMARY KEY (patch_name);
-
-
---
--- Name: account_merges_default account_merges_default_account_merge_request_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges_default
- ADD CONSTRAINT account_merges_default_account_merge_request_serial_id_key UNIQUE (account_merge_request_serial_id);
-
-
---
--- Name: account_merges account_merges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges
- ADD CONSTRAINT account_merges_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: account_merges_default account_merges_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.account_merges_default
- ADD CONSTRAINT account_merges_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: aggregation_tracking_default aggregation_tracking_default_aggregation_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking_default
- ADD CONSTRAINT aggregation_tracking_default_aggregation_serial_id_key UNIQUE (aggregation_serial_id);
-
-
---
--- Name: aggregation_tracking aggregation_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking
- ADD CONSTRAINT aggregation_tracking_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: aggregation_tracking_default aggregation_tracking_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.aggregation_tracking_default
- ADD CONSTRAINT aggregation_tracking_default_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: app_bankaccount app_bankaccount_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_pkey PRIMARY KEY (account_no);
-
-
---
--- Name: app_bankaccount app_bankaccount_user_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_user_id_key UNIQUE (user_id);
-
-
---
--- Name: app_banktransaction app_banktransaction_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_pkey PRIMARY KEY (id);
-
-
---
--- Name: app_banktransaction app_banktransaction_request_uid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_request_uid_key UNIQUE (request_uid);
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawoperation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawoperation_pkey PRIMARY KEY (withdraw_id);
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_auditor_denom_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_auditor_denom_serial_key UNIQUE (auditor_denom_serial);
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_pkey PRIMARY KEY (denominations_serial, auditor_uuid);
-
-
---
--- Name: auditor_denomination_pending auditor_denomination_pending_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denomination_pending
- ADD CONSTRAINT auditor_denomination_pending_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: auditor_exchanges auditor_exchanges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_exchanges
- ADD CONSTRAINT auditor_exchanges_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_historic_denomination_revenue auditor_historic_denomination_revenue_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_denomination_revenue
- ADD CONSTRAINT auditor_historic_denomination_revenue_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: auditor_progress_aggregation auditor_progress_aggregation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_aggregation
- ADD CONSTRAINT auditor_progress_aggregation_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_coin auditor_progress_coin_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_coin
- ADD CONSTRAINT auditor_progress_coin_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_deposit_confirmation auditor_progress_deposit_confirmation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_deposit_confirmation
- ADD CONSTRAINT auditor_progress_deposit_confirmation_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_progress_reserve auditor_progress_reserve_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_reserve
- ADD CONSTRAINT auditor_progress_reserve_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: auditor_reserves auditor_reserves_auditor_reserves_rowid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves
- ADD CONSTRAINT auditor_reserves_auditor_reserves_rowid_key UNIQUE (auditor_reserves_rowid);
-
-
---
--- Name: auditors auditors_auditor_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditors
- ADD CONSTRAINT auditors_auditor_uuid_key UNIQUE (auditor_uuid);
-
-
---
--- Name: auditors auditors_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditors
- ADD CONSTRAINT auditors_pkey PRIMARY KEY (auditor_pub);
-
-
---
--- Name: auth_group auth_group_name_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group
- ADD CONSTRAINT auth_group_name_key UNIQUE (name);
-
-
---
--- Name: auth_group_permissions auth_group_permissions_group_id_permission_id_0cd325b0_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_group_id_permission_id_0cd325b0_uniq UNIQUE (group_id, permission_id);
-
-
---
--- Name: auth_group_permissions auth_group_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_group auth_group_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group
- ADD CONSTRAINT auth_group_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_permission auth_permission_content_type_id_codename_01ab375a_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_content_type_id_codename_01ab375a_uniq UNIQUE (content_type_id, codename);
-
-
---
--- Name: auth_permission auth_permission_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_groups auth_user_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_groups auth_user_groups_user_id_group_id_94350c0c_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_user_id_group_id_94350c0c_uniq UNIQUE (user_id, group_id);
-
-
---
--- Name: auth_user auth_user_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user
- ADD CONSTRAINT auth_user_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_pkey PRIMARY KEY (id);
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_user_id_permission_id_14a6b632_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_user_id_permission_id_14a6b632_uniq UNIQUE (user_id, permission_id);
-
-
---
--- Name: auth_user auth_user_username_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user
- ADD CONSTRAINT auth_user_username_key UNIQUE (username);
-
-
---
--- Name: close_requests close_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.close_requests
- ADD CONSTRAINT close_requests_pkey PRIMARY KEY (reserve_pub, close_timestamp);
-
-
---
--- Name: close_requests_default close_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.close_requests_default
- ADD CONSTRAINT close_requests_default_pkey PRIMARY KEY (reserve_pub, close_timestamp);
-
-
---
--- Name: contracts_default contracts_default_contract_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts_default
- ADD CONSTRAINT contracts_default_contract_serial_id_key UNIQUE (contract_serial_id);
-
-
---
--- Name: contracts contracts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts
- ADD CONSTRAINT contracts_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: contracts_default contracts_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.contracts_default
- ADD CONSTRAINT contracts_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: cs_nonce_locks_default cs_nonce_locks_default_cs_nonce_lock_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks_default
- ADD CONSTRAINT cs_nonce_locks_default_cs_nonce_lock_serial_id_key UNIQUE (cs_nonce_lock_serial_id);
-
-
---
--- Name: cs_nonce_locks cs_nonce_locks_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks
- ADD CONSTRAINT cs_nonce_locks_pkey PRIMARY KEY (nonce);
-
-
---
--- Name: cs_nonce_locks_default cs_nonce_locks_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.cs_nonce_locks_default
- ADD CONSTRAINT cs_nonce_locks_default_pkey PRIMARY KEY (nonce);
-
-
---
--- Name: denomination_revocations denomination_revocations_denom_revocations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_denom_revocations_serial_id_key UNIQUE (denom_revocations_serial_id);
-
-
---
--- Name: denomination_revocations denomination_revocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_pkey PRIMARY KEY (denominations_serial);
-
-
---
--- Name: denominations denominations_denominations_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denominations
- ADD CONSTRAINT denominations_denominations_serial_key UNIQUE (denominations_serial);
-
-
---
--- Name: denominations denominations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denominations
- ADD CONSTRAINT denominations_pkey PRIMARY KEY (denom_pub_hash);
-
-
---
--- Name: deposit_confirmations deposit_confirmations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT deposit_confirmations_pkey PRIMARY KEY (h_contract_terms, h_wire, coin_pub, merchant_pub, exchange_sig, exchange_pub, master_sig);
-
-
---
--- Name: deposit_confirmations deposit_confirmations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT deposit_confirmations_serial_id_key UNIQUE (serial_id);
-
-
---
--- Name: deposits_default deposits_default_coin_pub_merchant_pub_h_contract_terms_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposits_default
- ADD CONSTRAINT deposits_default_coin_pub_merchant_pub_h_contract_terms_key UNIQUE (coin_pub, merchant_pub, h_contract_terms);
-
-
---
--- Name: deposits_default deposits_default_deposit_serial_id_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposits_default
- ADD CONSTRAINT deposits_default_deposit_serial_id_pkey PRIMARY KEY (deposit_serial_id);
-
-
---
--- Name: django_content_type django_content_type_app_label_model_76bd3d3b_uniq; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type
- ADD CONSTRAINT django_content_type_app_label_model_76bd3d3b_uniq UNIQUE (app_label, model);
-
-
---
--- Name: django_content_type django_content_type_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_content_type
- ADD CONSTRAINT django_content_type_pkey PRIMARY KEY (id);
-
-
---
--- Name: django_migrations django_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_migrations
- ADD CONSTRAINT django_migrations_pkey PRIMARY KEY (id);
-
-
---
--- Name: django_session django_session_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.django_session
- ADD CONSTRAINT django_session_pkey PRIMARY KEY (session_key);
-
-
---
--- Name: exchange_sign_keys exchange_sign_keys_esk_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.exchange_sign_keys
- ADD CONSTRAINT exchange_sign_keys_esk_serial_key UNIQUE (esk_serial);
-
-
---
--- Name: exchange_sign_keys exchange_sign_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.exchange_sign_keys
- ADD CONSTRAINT exchange_sign_keys_pkey PRIMARY KEY (exchange_pub);
-
-
---
--- Name: extension_details extension_details_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extension_details
- ADD CONSTRAINT extension_details_pkey PRIMARY KEY (extension_details_serial_id);
-
-
---
--- Name: extension_details_default extension_details_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extension_details_default
- ADD CONSTRAINT extension_details_default_pkey PRIMARY KEY (extension_details_serial_id);
-
-
---
--- Name: extensions extensions_extension_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extensions
- ADD CONSTRAINT extensions_extension_id_key UNIQUE (extension_id);
-
-
---
--- Name: extensions extensions_name_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.extensions
- ADD CONSTRAINT extensions_name_key UNIQUE (name);
-
-
---
--- Name: global_fee global_fee_global_fee_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.global_fee
- ADD CONSTRAINT global_fee_global_fee_serial_key UNIQUE (global_fee_serial);
-
-
---
--- Name: global_fee global_fee_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.global_fee
- ADD CONSTRAINT global_fee_pkey PRIMARY KEY (start_date);
-
-
---
--- Name: history_requests history_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.history_requests
- ADD CONSTRAINT history_requests_pkey PRIMARY KEY (reserve_pub, request_timestamp);
-
-
---
--- Name: history_requests_default history_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.history_requests_default
- ADD CONSTRAINT history_requests_default_pkey PRIMARY KEY (reserve_pub, request_timestamp);
-
-
---
--- Name: known_coins_default known_coins_default_known_coin_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins_default
- ADD CONSTRAINT known_coins_default_known_coin_id_key UNIQUE (known_coin_id);
-
-
---
--- Name: known_coins known_coins_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins
- ADD CONSTRAINT known_coins_pkey PRIMARY KEY (coin_pub);
-
-
---
--- Name: known_coins_default known_coins_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.known_coins_default
- ADD CONSTRAINT known_coins_default_pkey PRIMARY KEY (coin_pub);
-
-
---
--- Name: merchant_accounts merchant_accounts_h_wire_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_h_wire_key UNIQUE (h_wire);
-
-
---
--- Name: merchant_accounts merchant_accounts_merchant_serial_payto_uri_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_merchant_serial_payto_uri_key UNIQUE (merchant_serial, payto_uri);
-
-
---
--- Name: merchant_accounts merchant_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_pkey PRIMARY KEY (account_serial);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_h_contract_terms_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_h_contract_terms_key UNIQUE (merchant_serial, h_contract_terms);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_order_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_order_id_key UNIQUE (merchant_serial, order_id);
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_pkey PRIMARY KEY (order_serial);
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_deposit_serial_credit_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_deposit_serial_credit_serial_key UNIQUE (deposit_serial, credit_serial);
-
-
---
--- Name: merchant_deposits merchant_deposits_order_serial_coin_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_order_serial_coin_pub_key UNIQUE (order_serial, coin_pub);
-
-
---
--- Name: merchant_deposits merchant_deposits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_pkey PRIMARY KEY (deposit_serial);
-
-
---
--- Name: merchant_exchange_signing_keys merchant_exchange_signing_key_exchange_pub_start_date_maste_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_signing_keys
- ADD CONSTRAINT merchant_exchange_signing_key_exchange_pub_start_date_maste_key UNIQUE (exchange_pub, start_date, master_pub);
-
-
---
--- Name: merchant_exchange_signing_keys merchant_exchange_signing_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_signing_keys
- ADD CONSTRAINT merchant_exchange_signing_keys_pkey PRIMARY KEY (signkey_serial);
-
-
---
--- Name: merchant_exchange_wire_fees merchant_exchange_wire_fees_master_pub_h_wire_method_start__key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_wire_fees
- ADD CONSTRAINT merchant_exchange_wire_fees_master_pub_h_wire_method_start__key UNIQUE (master_pub, h_wire_method, start_date);
-
-
---
--- Name: merchant_exchange_wire_fees merchant_exchange_wire_fees_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_exchange_wire_fees
- ADD CONSTRAINT merchant_exchange_wire_fees_pkey PRIMARY KEY (wirefee_serial);
-
-
---
--- Name: merchant_instances merchant_instances_merchant_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_merchant_id_key UNIQUE (merchant_id);
-
-
---
--- Name: merchant_instances merchant_instances_merchant_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_merchant_pub_key UNIQUE (merchant_pub);
-
-
---
--- Name: merchant_instances merchant_instances_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_instances
- ADD CONSTRAINT merchant_instances_pkey PRIMARY KEY (merchant_serial);
-
-
---
--- Name: merchant_inventory merchant_inventory_merchant_serial_product_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_merchant_serial_product_id_key UNIQUE (merchant_serial, product_id);
-
-
---
--- Name: merchant_inventory merchant_inventory_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_pkey PRIMARY KEY (product_serial);
-
-
---
--- Name: merchant_keys merchant_keys_merchant_priv_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_merchant_priv_key UNIQUE (merchant_priv);
-
-
---
--- Name: merchant_keys merchant_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_pkey PRIMARY KEY (merchant_serial);
-
-
---
--- Name: merchant_kyc merchant_kyc_kyc_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_kyc_serial_id_key UNIQUE (kyc_serial_id);
-
-
---
--- Name: merchant_kyc merchant_kyc_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_pkey PRIMARY KEY (account_serial, exchange_url);
-
-
---
--- Name: merchant_orders merchant_orders_merchant_serial_order_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_merchant_serial_order_id_key UNIQUE (merchant_serial, order_id);
-
-
---
--- Name: merchant_orders merchant_orders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_pkey PRIMARY KEY (order_serial);
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_pkey PRIMARY KEY (refund_serial);
-
-
---
--- Name: merchant_refunds merchant_refunds_order_serial_coin_pub_rtransaction_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_order_serial_coin_pub_rtransaction_id_key UNIQUE (order_serial, coin_pub, rtransaction_id);
-
-
---
--- Name: merchant_refunds merchant_refunds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_pkey PRIMARY KEY (refund_serial);
-
-
---
--- Name: merchant_tip_pickup_signatures merchant_tip_pickup_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickup_signatures
- ADD CONSTRAINT merchant_tip_pickup_signatures_pkey PRIMARY KEY (pickup_serial, coin_offset);
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_pickup_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_pickup_id_key UNIQUE (pickup_id);
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_pkey PRIMARY KEY (pickup_serial);
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_priv_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_priv_key UNIQUE (reserve_priv);
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_serial_key UNIQUE (reserve_serial);
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_pkey PRIMARY KEY (reserve_serial);
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_reserve_pub_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_reserve_pub_key UNIQUE (reserve_pub);
-
-
---
--- Name: merchant_tips merchant_tips_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_pkey PRIMARY KEY (tip_serial);
-
-
---
--- Name: merchant_tips merchant_tips_tip_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_tip_id_key UNIQUE (tip_id);
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_pkey PRIMARY KEY (credit_serial);
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_deposit_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_deposit_serial_key UNIQUE (deposit_serial);
-
-
---
--- Name: merchant_transfers merchant_transfers_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_pkey PRIMARY KEY (credit_serial);
-
-
---
--- Name: merchant_transfers merchant_transfers_wtid_exchange_url_account_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_wtid_exchange_url_account_serial_key UNIQUE (wtid, exchange_url, account_serial);
-
-
---
--- Name: partner_accounts partner_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partner_accounts
- ADD CONSTRAINT partner_accounts_pkey PRIMARY KEY (payto_uri);
-
-
---
--- Name: partners partners_partner_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partners
- ADD CONSTRAINT partners_partner_serial_id_key UNIQUE (partner_serial_id);
-
-
---
--- Name: prewire prewire_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.prewire
- ADD CONSTRAINT prewire_pkey PRIMARY KEY (prewire_uuid);
-
-
---
--- Name: prewire_default prewire_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.prewire_default
- ADD CONSTRAINT prewire_default_pkey PRIMARY KEY (prewire_uuid);
-
-
---
--- Name: purse_actions purse_actions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_actions
- ADD CONSTRAINT purse_actions_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_deposits purse_deposits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits
- ADD CONSTRAINT purse_deposits_pkey PRIMARY KEY (purse_pub, coin_pub);
-
-
---
--- Name: purse_deposits_default purse_deposits_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits_default
- ADD CONSTRAINT purse_deposits_default_pkey PRIMARY KEY (purse_pub, coin_pub);
-
-
---
--- Name: purse_deposits_default purse_deposits_default_purse_deposit_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_deposits_default
- ADD CONSTRAINT purse_deposits_default_purse_deposit_serial_id_key UNIQUE (purse_deposit_serial_id);
-
-
---
--- Name: purse_merges purse_merges_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges
- ADD CONSTRAINT purse_merges_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_merges_default purse_merges_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges_default
- ADD CONSTRAINT purse_merges_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_merges_default purse_merges_default_purse_merge_request_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_merges_default
- ADD CONSTRAINT purse_merges_default_purse_merge_request_serial_id_key UNIQUE (purse_merge_request_serial_id);
-
-
---
--- Name: purse_refunds purse_refunds_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds
- ADD CONSTRAINT purse_refunds_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_refunds_default purse_refunds_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds_default
- ADD CONSTRAINT purse_refunds_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_refunds_default purse_refunds_default_purse_refunds_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_refunds_default
- ADD CONSTRAINT purse_refunds_default_purse_refunds_serial_id_key UNIQUE (purse_refunds_serial_id);
-
-
---
--- Name: purse_requests purse_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests
- ADD CONSTRAINT purse_requests_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_requests_default purse_requests_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests_default
- ADD CONSTRAINT purse_requests_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: purse_requests_default purse_requests_default_purse_requests_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.purse_requests_default
- ADD CONSTRAINT purse_requests_default_purse_requests_serial_id_key UNIQUE (purse_requests_serial_id);
-
-
---
--- Name: recoup_default recoup_default_recoup_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.recoup_default
- ADD CONSTRAINT recoup_default_recoup_uuid_key UNIQUE (recoup_uuid);
-
-
---
--- Name: recoup_refresh_default recoup_refresh_default_recoup_refresh_uuid_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.recoup_refresh_default
- ADD CONSTRAINT recoup_refresh_default_recoup_refresh_uuid_key UNIQUE (recoup_refresh_uuid);
-
-
---
--- Name: refresh_commitments_default refresh_commitments_default_melt_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments_default
- ADD CONSTRAINT refresh_commitments_default_melt_serial_id_key UNIQUE (melt_serial_id);
-
-
---
--- Name: refresh_commitments refresh_commitments_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments
- ADD CONSTRAINT refresh_commitments_pkey PRIMARY KEY (rc);
-
-
---
--- Name: refresh_commitments_default refresh_commitments_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_commitments_default
- ADD CONSTRAINT refresh_commitments_default_pkey PRIMARY KEY (rc);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_coin_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_coin_ev_key UNIQUE (coin_ev);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_h_coin_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_h_coin_ev_key UNIQUE (h_coin_ev);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_pkey PRIMARY KEY (melt_serial_id, freshcoin_index);
-
-
---
--- Name: refresh_revealed_coins_default refresh_revealed_coins_default_rrc_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_revealed_coins_default
- ADD CONSTRAINT refresh_revealed_coins_default_rrc_serial_key UNIQUE (rrc_serial);
-
-
---
--- Name: refresh_transfer_keys refresh_transfer_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys
- ADD CONSTRAINT refresh_transfer_keys_pkey PRIMARY KEY (melt_serial_id);
-
-
---
--- Name: refresh_transfer_keys_default refresh_transfer_keys_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys_default
- ADD CONSTRAINT refresh_transfer_keys_default_pkey PRIMARY KEY (melt_serial_id);
-
-
---
--- Name: refresh_transfer_keys_default refresh_transfer_keys_default_rtc_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refresh_transfer_keys_default
- ADD CONSTRAINT refresh_transfer_keys_default_rtc_serial_key UNIQUE (rtc_serial);
-
-
---
--- Name: refunds_default refunds_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refunds_default
- ADD CONSTRAINT refunds_default_pkey PRIMARY KEY (deposit_serial_id, rtransaction_id);
-
-
---
--- Name: refunds_default refunds_default_refund_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.refunds_default
- ADD CONSTRAINT refunds_default_refund_serial_id_key UNIQUE (refund_serial_id);
-
-
---
--- Name: reserves_close_default reserves_close_default_close_uuid_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_close_default
- ADD CONSTRAINT reserves_close_default_close_uuid_pkey PRIMARY KEY (close_uuid);
-
-
---
--- Name: reserves reserves_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves
- ADD CONSTRAINT reserves_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_default reserves_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_default
- ADD CONSTRAINT reserves_default_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in reserves_in_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in
- ADD CONSTRAINT reserves_in_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in_default reserves_in_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in_default
- ADD CONSTRAINT reserves_in_default_pkey PRIMARY KEY (reserve_pub);
-
-
---
--- Name: reserves_in_default reserves_in_default_reserve_in_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_in_default
- ADD CONSTRAINT reserves_in_default_reserve_in_serial_id_key UNIQUE (reserve_in_serial_id);
-
-
---
--- Name: reserves_out reserves_out_h_blind_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out
- ADD CONSTRAINT reserves_out_h_blind_ev_key UNIQUE (h_blind_ev);
-
-
---
--- Name: reserves_out_default reserves_out_default_h_blind_ev_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out_default
- ADD CONSTRAINT reserves_out_default_h_blind_ev_key UNIQUE (h_blind_ev);
-
-
---
--- Name: reserves_out_default reserves_out_default_reserve_out_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.reserves_out_default
- ADD CONSTRAINT reserves_out_default_reserve_out_serial_id_key UNIQUE (reserve_out_serial_id);
-
-
---
--- Name: revolving_work_shards revolving_work_shards_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.revolving_work_shards
- ADD CONSTRAINT revolving_work_shards_pkey PRIMARY KEY (job_name, start_row);
-
-
---
--- Name: revolving_work_shards revolving_work_shards_shard_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.revolving_work_shards
- ADD CONSTRAINT revolving_work_shards_shard_serial_id_key UNIQUE (shard_serial_id);
-
-
---
--- Name: signkey_revocations signkey_revocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_pkey PRIMARY KEY (esk_serial);
-
-
---
--- Name: signkey_revocations signkey_revocations_signkey_revocations_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_signkey_revocations_serial_id_key UNIQUE (signkey_revocations_serial_id);
-
-
---
--- Name: wad_in_entries wad_in_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries
- ADD CONSTRAINT wad_in_entries_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_in_entries_default wad_in_entries_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries_default
- ADD CONSTRAINT wad_in_entries_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_in_entries_default wad_in_entries_default_wad_in_entry_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_in_entries_default
- ADD CONSTRAINT wad_in_entries_default_wad_in_entry_serial_id_key UNIQUE (wad_in_entry_serial_id);
-
-
---
--- Name: wad_out_entries wad_out_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries
- ADD CONSTRAINT wad_out_entries_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_out_entries_default wad_out_entries_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries_default
- ADD CONSTRAINT wad_out_entries_default_pkey PRIMARY KEY (purse_pub);
-
-
---
--- Name: wad_out_entries_default wad_out_entries_default_wad_out_entry_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wad_out_entries_default
- ADD CONSTRAINT wad_out_entries_default_wad_out_entry_serial_id_key UNIQUE (wad_out_entry_serial_id);
-
-
---
--- Name: wads_in wads_in_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in
- ADD CONSTRAINT wads_in_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_in_default wads_in_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_in wads_in_wad_id_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in
- ADD CONSTRAINT wads_in_wad_id_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_in_default wads_in_default_wad_id_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_id_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_in_default wads_in_default_wad_in_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_in_serial_id_key UNIQUE (wad_in_serial_id);
-
-
---
--- Name: wads_in_default wads_in_default_wad_is_origin_exchange_url_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_in_default
- ADD CONSTRAINT wads_in_default_wad_is_origin_exchange_url_key UNIQUE (wad_id, origin_exchange_url);
-
-
---
--- Name: wads_out wads_out_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out
- ADD CONSTRAINT wads_out_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_out_default wads_out_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out_default
- ADD CONSTRAINT wads_out_default_pkey PRIMARY KEY (wad_id);
-
-
---
--- Name: wads_out_default wads_out_default_wad_out_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wads_out_default
- ADD CONSTRAINT wads_out_default_wad_out_serial_id_key UNIQUE (wad_out_serial_id);
-
-
---
--- Name: wire_accounts wire_accounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_accounts
- ADD CONSTRAINT wire_accounts_pkey PRIMARY KEY (payto_uri);
-
-
---
--- Name: wire_auditor_account_progress wire_auditor_account_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_account_progress
- ADD CONSTRAINT wire_auditor_account_progress_pkey PRIMARY KEY (master_pub, account_name);
-
-
---
--- Name: wire_auditor_progress wire_auditor_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_progress
- ADD CONSTRAINT wire_auditor_progress_pkey PRIMARY KEY (master_pub);
-
-
---
--- Name: wire_fee wire_fee_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_fee
- ADD CONSTRAINT wire_fee_pkey PRIMARY KEY (wire_method, start_date);
-
-
---
--- Name: wire_fee wire_fee_wire_fee_serial_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_fee
- ADD CONSTRAINT wire_fee_wire_fee_serial_key UNIQUE (wire_fee_serial);
-
-
---
--- Name: wire_out_default wire_out_default_wireout_uuid_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out_default
- ADD CONSTRAINT wire_out_default_wireout_uuid_pkey PRIMARY KEY (wireout_uuid);
-
-
---
--- Name: wire_out wire_out_wtid_raw_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out
- ADD CONSTRAINT wire_out_wtid_raw_key UNIQUE (wtid_raw);
-
-
---
--- Name: wire_out_default wire_out_default_wtid_raw_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_out_default
- ADD CONSTRAINT wire_out_default_wtid_raw_key UNIQUE (wtid_raw);
-
-
---
--- Name: wire_targets wire_targets_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets
- ADD CONSTRAINT wire_targets_pkey PRIMARY KEY (wire_target_h_payto);
-
-
---
--- Name: wire_targets_default wire_targets_default_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets_default
- ADD CONSTRAINT wire_targets_default_pkey PRIMARY KEY (wire_target_h_payto);
-
-
---
--- Name: wire_targets_default wire_targets_default_wire_target_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_targets_default
- ADD CONSTRAINT wire_targets_default_wire_target_serial_id_key UNIQUE (wire_target_serial_id);
-
-
---
--- Name: work_shards work_shards_pkey; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.work_shards
- ADD CONSTRAINT work_shards_pkey PRIMARY KEY (job_name, start_row);
-
-
---
--- Name: work_shards work_shards_shard_serial_id_key; Type: CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.work_shards
- ADD CONSTRAINT work_shards_shard_serial_id_key UNIQUE (shard_serial_id);
-
-
---
--- Name: account_merges_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX account_merges_by_reserve_pub ON ONLY public.account_merges USING btree (reserve_pub);
-
-
---
--- Name: account_merges_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX account_merges_default_reserve_pub_idx ON public.account_merges_default USING btree (reserve_pub);
-
-
---
--- Name: aggregation_tracking_by_wtid_raw_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX aggregation_tracking_by_wtid_raw_index ON ONLY public.aggregation_tracking USING btree (wtid_raw);
-
-
---
--- Name: INDEX aggregation_tracking_by_wtid_raw_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.aggregation_tracking_by_wtid_raw_index IS 'for lookup_transactions';
-
-
---
--- Name: aggregation_tracking_default_wtid_raw_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX aggregation_tracking_default_wtid_raw_idx ON public.aggregation_tracking_default USING btree (wtid_raw);
-
-
---
--- Name: app_banktransaction_credit_account_id_a8ba05ac; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_credit_account_id_a8ba05ac ON public.app_banktransaction USING btree (credit_account_id);
-
-
---
--- Name: app_banktransaction_date_f72bcad6; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_date_f72bcad6 ON public.app_banktransaction USING btree (date);
-
-
---
--- Name: app_banktransaction_debit_account_id_5b1f7528; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_debit_account_id_5b1f7528 ON public.app_banktransaction USING btree (debit_account_id);
-
-
---
--- Name: app_banktransaction_request_uid_b7d06af5_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_banktransaction_request_uid_b7d06af5_like ON public.app_banktransaction USING btree (request_uid varchar_pattern_ops);
-
-
---
--- Name: app_talerwithdrawoperation_selected_exchange_account__6c8b96cf; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_talerwithdrawoperation_selected_exchange_account__6c8b96cf ON public.app_talerwithdrawoperation USING btree (selected_exchange_account_id);
-
-
---
--- Name: app_talerwithdrawoperation_withdraw_account_id_992dc5b3; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX app_talerwithdrawoperation_withdraw_account_id_992dc5b3 ON public.app_talerwithdrawoperation USING btree (withdraw_account_id);
-
-
---
--- Name: auditor_historic_reserve_summary_by_master_pub_start_date; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date ON public.auditor_historic_reserve_summary USING btree (master_pub, start_date);
-
-
---
--- Name: auditor_reserves_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auditor_reserves_by_reserve_pub ON public.auditor_reserves USING btree (reserve_pub);
-
-
---
--- Name: auth_group_name_a6ea08ec_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_name_a6ea08ec_like ON public.auth_group USING btree (name varchar_pattern_ops);
-
-
---
--- Name: auth_group_permissions_group_id_b120cbf9; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_permissions_group_id_b120cbf9 ON public.auth_group_permissions USING btree (group_id);
-
-
---
--- Name: auth_group_permissions_permission_id_84c5c92e; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_group_permissions_permission_id_84c5c92e ON public.auth_group_permissions USING btree (permission_id);
-
-
---
--- Name: auth_permission_content_type_id_2f476e4b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_permission_content_type_id_2f476e4b ON public.auth_permission USING btree (content_type_id);
-
-
---
--- Name: auth_user_groups_group_id_97559544; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_groups_group_id_97559544 ON public.auth_user_groups USING btree (group_id);
-
-
---
--- Name: auth_user_groups_user_id_6a12ed8b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_groups_user_id_6a12ed8b ON public.auth_user_groups USING btree (user_id);
-
-
---
--- Name: auth_user_user_permissions_permission_id_1fbb5f2c; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_user_permissions_permission_id_1fbb5f2c ON public.auth_user_user_permissions USING btree (permission_id);
-
-
---
--- Name: auth_user_user_permissions_user_id_a95ead1b; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_user_permissions_user_id_a95ead1b ON public.auth_user_user_permissions USING btree (user_id);
-
-
---
--- Name: auth_user_username_6821ab7c_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX auth_user_username_6821ab7c_like ON public.auth_user USING btree (username varchar_pattern_ops);
-
-
---
--- Name: denominations_by_expire_legal_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX denominations_by_expire_legal_index ON public.denominations USING btree (expire_legal);
-
-
---
--- Name: deposits_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_coin_pub_index ON ONLY public.deposits USING btree (coin_pub);
-
-
---
--- Name: deposits_by_ready_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_ready_main_index ON ONLY public.deposits_by_ready USING btree (wire_deadline, shard, coin_pub);
-
-
---
--- Name: deposits_by_ready_default_wire_deadline_shard_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_by_ready_default_wire_deadline_shard_coin_pub_idx ON public.deposits_by_ready_default USING btree (wire_deadline, shard, coin_pub);
-
-
---
--- Name: deposits_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_default_coin_pub_idx ON public.deposits_default USING btree (coin_pub);
-
-
---
--- Name: deposits_for_matching_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_for_matching_main_index ON ONLY public.deposits_for_matching USING btree (refund_deadline, merchant_pub, coin_pub);
-
-
---
--- Name: deposits_for_matching_default_refund_deadline_merchant_pub__idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX deposits_for_matching_default_refund_deadline_merchant_pub__idx ON public.deposits_for_matching_default USING btree (refund_deadline, merchant_pub, coin_pub);
-
-
---
--- Name: django_session_expire_date_a5c62663; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX django_session_expire_date_a5c62663 ON public.django_session USING btree (expire_date);
-
-
---
--- Name: django_session_session_key_c0390e0f_like; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX django_session_session_key_c0390e0f_like ON public.django_session USING btree (session_key varchar_pattern_ops);
-
-
---
--- Name: global_fee_by_end_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX global_fee_by_end_date_index ON public.global_fee USING btree (end_date);
-
-
---
--- Name: merchant_contract_terms_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_expiration ON public.merchant_contract_terms USING btree (paid, pay_deadline);
-
-
---
--- Name: INDEX merchant_contract_terms_by_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.merchant_contract_terms_by_expiration IS 'for unlock_contracts';
-
-
---
--- Name: merchant_contract_terms_by_merchant_and_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_and_expiration ON public.merchant_contract_terms USING btree (merchant_serial, pay_deadline);
-
-
---
--- Name: INDEX merchant_contract_terms_by_merchant_and_expiration; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.merchant_contract_terms_by_merchant_and_expiration IS 'for delete_contract_terms';
-
-
---
--- Name: merchant_contract_terms_by_merchant_and_payment; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_and_payment ON public.merchant_contract_terms USING btree (merchant_serial, paid);
-
-
---
--- Name: merchant_contract_terms_by_merchant_session_and_fulfillment; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_contract_terms_by_merchant_session_and_fulfillment ON public.merchant_contract_terms USING btree (merchant_serial, fulfillment_url, session_id);
-
-
---
--- Name: merchant_inventory_locks_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_inventory_locks_by_expiration ON public.merchant_inventory_locks USING btree (expiration);
-
-
---
--- Name: merchant_inventory_locks_by_uuid; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_inventory_locks_by_uuid ON public.merchant_inventory_locks USING btree (lock_uuid);
-
-
---
--- Name: merchant_orders_by_creation_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_by_creation_time ON public.merchant_orders USING btree (creation_time);
-
-
---
--- Name: merchant_orders_by_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_by_expiration ON public.merchant_orders USING btree (pay_deadline);
-
-
---
--- Name: merchant_orders_locks_by_order_and_product; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_orders_locks_by_order_and_product ON public.merchant_order_locks USING btree (order_serial, product_serial);
-
-
---
--- Name: merchant_refunds_by_coin_and_order; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_refunds_by_coin_and_order ON public.merchant_refunds USING btree (coin_pub, order_serial);
-
-
---
--- Name: merchant_tip_reserves_by_exchange_balance; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_exchange_balance ON public.merchant_tip_reserves USING btree (exchange_initial_balance_val, exchange_initial_balance_frac);
-
-
---
--- Name: merchant_tip_reserves_by_merchant_serial_and_creation_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_merchant_serial_and_creation_time ON public.merchant_tip_reserves USING btree (merchant_serial, creation_time);
-
-
---
--- Name: merchant_tip_reserves_by_reserve_pub_and_merchant_serial; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tip_reserves_by_reserve_pub_and_merchant_serial ON public.merchant_tip_reserves USING btree (reserve_pub, merchant_serial, creation_time);
-
-
---
--- Name: merchant_tips_by_pickup_and_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_tips_by_pickup_and_expiration ON public.merchant_tips USING btree (was_picked_up, expiration);
-
-
---
--- Name: merchant_transfers_by_credit; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX merchant_transfers_by_credit ON public.merchant_transfer_to_coin USING btree (credit_serial);
-
-
---
--- Name: partner_accounts_index_by_partner_and_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX partner_accounts_index_by_partner_and_time ON public.partner_accounts USING btree (partner_serial_id, last_seen);
-
-
---
--- Name: partner_by_wad_time; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX partner_by_wad_time ON public.partners USING btree (next_wad);
-
-
---
--- Name: prewire_by_failed_finished_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_by_failed_finished_index ON ONLY public.prewire USING btree (failed, finished);
-
-
---
--- Name: INDEX prewire_by_failed_finished_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.prewire_by_failed_finished_index IS 'for wire_prepare_data_get';
-
-
---
--- Name: prewire_by_finished_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_by_finished_index ON ONLY public.prewire USING btree (finished);
-
-
---
--- Name: INDEX prewire_by_finished_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.prewire_by_finished_index IS 'for gc_prewire';
-
-
---
--- Name: prewire_default_failed_finished_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_default_failed_finished_idx ON public.prewire_default USING btree (failed, finished);
-
-
---
--- Name: prewire_default_finished_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX prewire_default_finished_idx ON public.prewire_default USING btree (finished);
-
-
---
--- Name: purse_action_by_target; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_action_by_target ON public.purse_actions USING btree (partner_serial_id, action_date);
-
-
---
--- Name: purse_deposits_by_coin_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_deposits_by_coin_pub ON ONLY public.purse_deposits USING btree (coin_pub);
-
-
---
--- Name: purse_deposits_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_deposits_default_coin_pub_idx ON public.purse_deposits_default USING btree (coin_pub);
-
-
---
--- Name: purse_merges_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_merges_reserve_pub ON ONLY public.purse_merges USING btree (reserve_pub);
-
-
---
--- Name: INDEX purse_merges_reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.purse_merges_reserve_pub IS 'needed in reserve history computation';
-
-
---
--- Name: purse_merges_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_merges_default_reserve_pub_idx ON public.purse_merges_default USING btree (reserve_pub);
-
-
---
--- Name: purse_requests_merge_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_merge_pub ON ONLY public.purse_requests USING btree (merge_pub);
-
-
---
--- Name: purse_requests_default_merge_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_default_merge_pub_idx ON public.purse_requests_default USING btree (merge_pub);
-
-
---
--- Name: purse_requests_purse_expiration; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_purse_expiration ON ONLY public.purse_requests USING btree (purse_expiration);
-
-
---
--- Name: purse_requests_default_purse_expiration_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX purse_requests_default_purse_expiration_idx ON public.purse_requests_default USING btree (purse_expiration);
-
-
---
--- Name: recoup_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_coin_pub_index ON ONLY public.recoup USING btree (coin_pub);
-
-
---
--- Name: recoup_by_reserve_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_reserve_main_index ON ONLY public.recoup_by_reserve USING btree (reserve_out_serial_id);
-
-
---
--- Name: recoup_by_reserve_default_reserve_out_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_by_reserve_default_reserve_out_serial_id_idx ON public.recoup_by_reserve_default USING btree (reserve_out_serial_id);
-
-
---
--- Name: recoup_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_default_coin_pub_idx ON public.recoup_default USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_by_coin_pub_index ON ONLY public.recoup_refresh USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_by_rrc_serial_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_by_rrc_serial_index ON ONLY public.recoup_refresh USING btree (rrc_serial);
-
-
---
--- Name: recoup_refresh_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_default_coin_pub_idx ON public.recoup_refresh_default USING btree (coin_pub);
-
-
---
--- Name: recoup_refresh_default_rrc_serial_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX recoup_refresh_default_rrc_serial_idx ON public.recoup_refresh_default USING btree (rrc_serial);
-
-
---
--- Name: refresh_commitments_by_old_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_commitments_by_old_coin_pub_index ON ONLY public.refresh_commitments USING btree (old_coin_pub);
-
-
---
--- Name: refresh_commitments_default_old_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_commitments_default_old_coin_pub_idx ON public.refresh_commitments_default USING btree (old_coin_pub);
-
-
---
--- Name: refresh_revealed_coins_coins_by_melt_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_revealed_coins_coins_by_melt_serial_id_index ON ONLY public.refresh_revealed_coins USING btree (melt_serial_id);
-
-
---
--- Name: refresh_revealed_coins_default_melt_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refresh_revealed_coins_default_melt_serial_id_idx ON public.refresh_revealed_coins_default USING btree (melt_serial_id);
-
-
---
--- Name: refunds_by_coin_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refunds_by_coin_pub_index ON ONLY public.refunds USING btree (coin_pub);
-
-
---
--- Name: refunds_default_coin_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX refunds_default_coin_pub_idx ON public.refunds_default USING btree (coin_pub);
-
-
---
--- Name: reserves_by_expiration_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_expiration_index ON ONLY public.reserves USING btree (expiration_date, current_balance_val, current_balance_frac);
-
-
---
--- Name: INDEX reserves_by_expiration_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_by_expiration_index IS 'used in get_expired_reserves';
-
-
---
--- Name: reserves_by_gc_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_gc_date_index ON ONLY public.reserves USING btree (gc_date);
-
-
---
--- Name: INDEX reserves_by_gc_date_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_by_gc_date_index IS 'for reserve garbage collection';
-
-
---
--- Name: reserves_by_reserve_uuid_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_by_reserve_uuid_index ON ONLY public.reserves USING btree (reserve_uuid);
-
-
---
--- Name: reserves_close_by_close_uuid_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_by_close_uuid_index ON ONLY public.reserves_close USING btree (close_uuid);
-
-
---
--- Name: reserves_close_by_reserve_pub_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_by_reserve_pub_index ON ONLY public.reserves_close USING btree (reserve_pub);
-
-
---
--- Name: reserves_close_default_close_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_default_close_uuid_idx ON public.reserves_close_default USING btree (close_uuid);
-
-
---
--- Name: reserves_close_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_close_default_reserve_pub_idx ON public.reserves_close_default USING btree (reserve_pub);
-
-
---
--- Name: reserves_default_expiration_date_current_balance_val_curren_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_expiration_date_current_balance_val_curren_idx ON public.reserves_default USING btree (expiration_date, current_balance_val, current_balance_frac);
-
-
---
--- Name: reserves_default_gc_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_gc_date_idx ON public.reserves_default USING btree (gc_date);
-
-
---
--- Name: reserves_default_reserve_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_default_reserve_uuid_idx ON public.reserves_default USING btree (reserve_uuid);
-
-
---
--- Name: reserves_in_by_exch_accnt_reserve_in_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_exch_accnt_reserve_in_serial_id_idx ON ONLY public.reserves_in USING btree (exchange_account_section, reserve_in_serial_id DESC);
-
-
---
--- Name: reserves_in_by_exch_accnt_section_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_exch_accnt_section_execution_date_idx ON ONLY public.reserves_in USING btree (exchange_account_section, execution_date);
-
-
---
--- Name: reserves_in_by_reserve_in_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_by_reserve_in_serial_id_index ON ONLY public.reserves_in USING btree (reserve_in_serial_id);
-
-
---
--- Name: reserves_in_default_exchange_account_section_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_exchange_account_section_execution_date_idx ON public.reserves_in_default USING btree (exchange_account_section, execution_date);
-
-
---
--- Name: reserves_in_default_exchange_account_section_reserve_in_ser_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_exchange_account_section_reserve_in_ser_idx ON public.reserves_in_default USING btree (exchange_account_section, reserve_in_serial_id DESC);
-
-
---
--- Name: reserves_in_default_reserve_in_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_in_default_reserve_in_serial_id_idx ON public.reserves_in_default USING btree (reserve_in_serial_id);
-
-
---
--- Name: reserves_out_by_reserve_main_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_main_index ON ONLY public.reserves_out_by_reserve USING btree (reserve_uuid);
-
-
---
--- Name: reserves_out_by_reserve_default_reserve_uuid_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_default_reserve_uuid_idx ON public.reserves_out_by_reserve_default USING btree (reserve_uuid);
-
-
---
--- Name: reserves_out_by_reserve_out_serial_id_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_out_serial_id_index ON ONLY public.reserves_out USING btree (reserve_out_serial_id);
-
-
---
--- Name: reserves_out_by_reserve_uuid_and_execution_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_by_reserve_uuid_and_execution_date_index ON ONLY public.reserves_out USING btree (reserve_uuid, execution_date);
-
-
---
--- Name: INDEX reserves_out_by_reserve_uuid_and_execution_date_index; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.reserves_out_by_reserve_uuid_and_execution_date_index IS 'for get_reserves_out and exchange_do_withdraw_limit_check';
-
-
---
--- Name: reserves_out_default_reserve_out_serial_id_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_default_reserve_out_serial_id_idx ON public.reserves_out_default USING btree (reserve_out_serial_id);
-
-
---
--- Name: reserves_out_default_reserve_uuid_execution_date_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX reserves_out_default_reserve_uuid_execution_date_idx ON public.reserves_out_default USING btree (reserve_uuid, execution_date);
-
-
---
--- Name: revolving_work_shards_by_job_name_active_last_attempt_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX revolving_work_shards_by_job_name_active_last_attempt_index ON public.revolving_work_shards USING btree (job_name, active, last_attempt);
-
-
---
--- Name: wad_in_entries_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_in_entries_reserve_pub ON ONLY public.wad_in_entries USING btree (reserve_pub);
-
-
---
--- Name: INDEX wad_in_entries_reserve_pub; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON INDEX public.wad_in_entries_reserve_pub IS 'needed in reserve history computation';
-
-
---
--- Name: wad_in_entries_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_in_entries_default_reserve_pub_idx ON public.wad_in_entries_default USING btree (reserve_pub);
-
-
---
--- Name: wad_out_entries_by_reserve_pub; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_out_entries_by_reserve_pub ON ONLY public.wad_out_entries USING btree (reserve_pub);
-
-
---
--- Name: wad_out_entries_default_reserve_pub_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wad_out_entries_default_reserve_pub_idx ON public.wad_out_entries_default USING btree (reserve_pub);
-
-
---
--- Name: wire_fee_by_end_date_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_fee_by_end_date_index ON public.wire_fee USING btree (end_date);
-
-
---
--- Name: wire_out_by_wire_target_h_payto_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_out_by_wire_target_h_payto_index ON ONLY public.wire_out USING btree (wire_target_h_payto);
-
-
---
--- Name: wire_out_default_wire_target_h_payto_idx; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX wire_out_default_wire_target_h_payto_idx ON public.wire_out_default USING btree (wire_target_h_payto);
-
-
---
--- Name: work_shards_by_job_name_completed_last_attempt_index; Type: INDEX; Schema: public; Owner: -
---
-
-CREATE INDEX work_shards_by_job_name_completed_last_attempt_index ON public.work_shards USING btree (job_name, completed, last_attempt);
-
-
---
--- Name: account_merges_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.account_merges_pkey ATTACH PARTITION public.account_merges_default_pkey;
-
-
---
--- Name: account_merges_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.account_merges_by_reserve_pub ATTACH PARTITION public.account_merges_default_reserve_pub_idx;
-
-
---
--- Name: aggregation_tracking_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.aggregation_tracking_pkey ATTACH PARTITION public.aggregation_tracking_default_pkey;
-
-
---
--- Name: aggregation_tracking_default_wtid_raw_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.aggregation_tracking_by_wtid_raw_index ATTACH PARTITION public.aggregation_tracking_default_wtid_raw_idx;
-
-
---
--- Name: close_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.close_requests_pkey ATTACH PARTITION public.close_requests_default_pkey;
-
-
---
--- Name: contracts_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.contracts_pkey ATTACH PARTITION public.contracts_default_pkey;
-
-
---
--- Name: cs_nonce_locks_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.cs_nonce_locks_pkey ATTACH PARTITION public.cs_nonce_locks_default_pkey;
-
-
---
--- Name: deposits_by_ready_default_wire_deadline_shard_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_by_ready_main_index ATTACH PARTITION public.deposits_by_ready_default_wire_deadline_shard_coin_pub_idx;
-
-
---
--- Name: deposits_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_by_coin_pub_index ATTACH PARTITION public.deposits_default_coin_pub_idx;
-
-
---
--- Name: deposits_for_matching_default_refund_deadline_merchant_pub__idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.deposits_for_matching_main_index ATTACH PARTITION public.deposits_for_matching_default_refund_deadline_merchant_pub__idx;
-
-
---
--- Name: extension_details_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.extension_details_pkey ATTACH PARTITION public.extension_details_default_pkey;
-
-
---
--- Name: history_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.history_requests_pkey ATTACH PARTITION public.history_requests_default_pkey;
-
-
---
--- Name: known_coins_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.known_coins_pkey ATTACH PARTITION public.known_coins_default_pkey;
-
-
---
--- Name: prewire_default_failed_finished_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_by_failed_finished_index ATTACH PARTITION public.prewire_default_failed_finished_idx;
-
-
---
--- Name: prewire_default_finished_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_by_finished_index ATTACH PARTITION public.prewire_default_finished_idx;
-
-
---
--- Name: prewire_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.prewire_pkey ATTACH PARTITION public.prewire_default_pkey;
-
-
---
--- Name: purse_deposits_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_deposits_by_coin_pub ATTACH PARTITION public.purse_deposits_default_coin_pub_idx;
-
-
---
--- Name: purse_deposits_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_deposits_pkey ATTACH PARTITION public.purse_deposits_default_pkey;
-
-
---
--- Name: purse_merges_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_merges_pkey ATTACH PARTITION public.purse_merges_default_pkey;
-
-
---
--- Name: purse_merges_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_merges_reserve_pub ATTACH PARTITION public.purse_merges_default_reserve_pub_idx;
-
-
---
--- Name: purse_refunds_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_refunds_pkey ATTACH PARTITION public.purse_refunds_default_pkey;
-
-
---
--- Name: purse_requests_default_merge_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_merge_pub ATTACH PARTITION public.purse_requests_default_merge_pub_idx;
-
-
---
--- Name: purse_requests_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_pkey ATTACH PARTITION public.purse_requests_default_pkey;
-
-
---
--- Name: purse_requests_default_purse_expiration_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.purse_requests_purse_expiration ATTACH PARTITION public.purse_requests_default_purse_expiration_idx;
-
-
---
--- Name: recoup_by_reserve_default_reserve_out_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_by_reserve_main_index ATTACH PARTITION public.recoup_by_reserve_default_reserve_out_serial_id_idx;
-
-
---
--- Name: recoup_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_by_coin_pub_index ATTACH PARTITION public.recoup_default_coin_pub_idx;
-
-
---
--- Name: recoup_refresh_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_refresh_by_coin_pub_index ATTACH PARTITION public.recoup_refresh_default_coin_pub_idx;
-
-
---
--- Name: recoup_refresh_default_rrc_serial_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.recoup_refresh_by_rrc_serial_index ATTACH PARTITION public.recoup_refresh_default_rrc_serial_idx;
-
-
---
--- Name: refresh_commitments_default_old_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_commitments_by_old_coin_pub_index ATTACH PARTITION public.refresh_commitments_default_old_coin_pub_idx;
-
-
---
--- Name: refresh_commitments_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_commitments_pkey ATTACH PARTITION public.refresh_commitments_default_pkey;
-
-
---
--- Name: refresh_revealed_coins_default_melt_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_revealed_coins_coins_by_melt_serial_id_index ATTACH PARTITION public.refresh_revealed_coins_default_melt_serial_id_idx;
-
-
---
--- Name: refresh_transfer_keys_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refresh_transfer_keys_pkey ATTACH PARTITION public.refresh_transfer_keys_default_pkey;
-
-
---
--- Name: refunds_default_coin_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.refunds_by_coin_pub_index ATTACH PARTITION public.refunds_default_coin_pub_idx;
-
-
---
--- Name: reserves_close_default_close_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_close_by_close_uuid_index ATTACH PARTITION public.reserves_close_default_close_uuid_idx;
-
-
---
--- Name: reserves_close_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_close_by_reserve_pub_index ATTACH PARTITION public.reserves_close_default_reserve_pub_idx;
-
-
---
--- Name: reserves_default_expiration_date_current_balance_val_curren_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_expiration_index ATTACH PARTITION public.reserves_default_expiration_date_current_balance_val_curren_idx;
-
-
---
--- Name: reserves_default_gc_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_gc_date_index ATTACH PARTITION public.reserves_default_gc_date_idx;
-
-
---
--- Name: reserves_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_pkey ATTACH PARTITION public.reserves_default_pkey;
-
-
---
--- Name: reserves_default_reserve_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_by_reserve_uuid_index ATTACH PARTITION public.reserves_default_reserve_uuid_idx;
-
-
---
--- Name: reserves_in_default_exchange_account_section_execution_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_exch_accnt_section_execution_date_idx ATTACH PARTITION public.reserves_in_default_exchange_account_section_execution_date_idx;
-
-
---
--- Name: reserves_in_default_exchange_account_section_reserve_in_ser_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_exch_accnt_reserve_in_serial_id_idx ATTACH PARTITION public.reserves_in_default_exchange_account_section_reserve_in_ser_idx;
-
-
---
--- Name: reserves_in_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_pkey ATTACH PARTITION public.reserves_in_default_pkey;
-
-
---
--- Name: reserves_in_default_reserve_in_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_in_by_reserve_in_serial_id_index ATTACH PARTITION public.reserves_in_default_reserve_in_serial_id_idx;
-
-
---
--- Name: reserves_out_by_reserve_default_reserve_uuid_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_main_index ATTACH PARTITION public.reserves_out_by_reserve_default_reserve_uuid_idx;
-
-
---
--- Name: reserves_out_default_h_blind_ev_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_h_blind_ev_key ATTACH PARTITION public.reserves_out_default_h_blind_ev_key;
-
-
---
--- Name: reserves_out_default_reserve_out_serial_id_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_out_serial_id_index ATTACH PARTITION public.reserves_out_default_reserve_out_serial_id_idx;
-
-
---
--- Name: reserves_out_default_reserve_uuid_execution_date_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.reserves_out_by_reserve_uuid_and_execution_date_index ATTACH PARTITION public.reserves_out_default_reserve_uuid_execution_date_idx;
-
-
---
--- Name: wad_in_entries_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_in_entries_pkey ATTACH PARTITION public.wad_in_entries_default_pkey;
-
-
---
--- Name: wad_in_entries_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_in_entries_reserve_pub ATTACH PARTITION public.wad_in_entries_default_reserve_pub_idx;
-
-
---
--- Name: wad_out_entries_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_out_entries_pkey ATTACH PARTITION public.wad_out_entries_default_pkey;
-
-
---
--- Name: wad_out_entries_default_reserve_pub_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wad_out_entries_by_reserve_pub ATTACH PARTITION public.wad_out_entries_default_reserve_pub_idx;
-
-
---
--- Name: wads_in_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_in_pkey ATTACH PARTITION public.wads_in_default_pkey;
-
-
---
--- Name: wads_in_default_wad_id_origin_exchange_url_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_in_wad_id_origin_exchange_url_key ATTACH PARTITION public.wads_in_default_wad_id_origin_exchange_url_key;
-
-
---
--- Name: wads_out_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wads_out_pkey ATTACH PARTITION public.wads_out_default_pkey;
-
-
---
--- Name: wire_out_default_wire_target_h_payto_idx; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_out_by_wire_target_h_payto_index ATTACH PARTITION public.wire_out_default_wire_target_h_payto_idx;
-
-
---
--- Name: wire_out_default_wtid_raw_key; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_out_wtid_raw_key ATTACH PARTITION public.wire_out_default_wtid_raw_key;
-
-
---
--- Name: wire_targets_default_pkey; Type: INDEX ATTACH; Schema: public; Owner: -
---
-
-ALTER INDEX public.wire_targets_pkey ATTACH PARTITION public.wire_targets_default_pkey;
-
-
---
--- Name: deposits deposits_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_delete AFTER DELETE ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_delete_trigger();
-
-
---
--- Name: deposits deposits_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_insert AFTER INSERT ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_insert_trigger();
-
-
---
--- Name: deposits deposits_on_update; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER deposits_on_update AFTER UPDATE ON public.deposits FOR EACH ROW EXECUTE FUNCTION public.deposits_update_trigger();
-
-
---
--- Name: purse_requests purse_requests_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER purse_requests_on_insert AFTER INSERT ON public.purse_requests FOR EACH ROW EXECUTE FUNCTION public.purse_requests_insert_trigger();
-
-
---
--- Name: TRIGGER purse_requests_on_insert ON purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TRIGGER purse_requests_on_insert ON public.purse_requests IS 'Here we install an entry for the purse expiration.';
-
-
---
--- Name: purse_requests purse_requests_on_update; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER purse_requests_on_update BEFORE UPDATE ON public.purse_requests FOR EACH ROW EXECUTE FUNCTION public.purse_requests_on_update_trigger();
-
-
---
--- Name: TRIGGER purse_requests_on_update ON purse_requests; Type: COMMENT; Schema: public; Owner: -
---
-
-COMMENT ON TRIGGER purse_requests_on_update ON public.purse_requests IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
-
-
---
--- Name: recoup recoup_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER recoup_on_delete AFTER DELETE ON public.recoup FOR EACH ROW EXECUTE FUNCTION public.recoup_delete_trigger();
-
-
---
--- Name: recoup recoup_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER recoup_on_insert AFTER INSERT ON public.recoup FOR EACH ROW EXECUTE FUNCTION public.recoup_insert_trigger();
-
-
---
--- Name: reserves_out reserves_out_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER reserves_out_on_delete AFTER DELETE ON public.reserves_out FOR EACH ROW EXECUTE FUNCTION public.reserves_out_by_reserve_delete_trigger();
-
-
---
--- Name: reserves_out reserves_out_on_insert; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER reserves_out_on_insert AFTER INSERT ON public.reserves_out FOR EACH ROW EXECUTE FUNCTION public.reserves_out_by_reserve_insert_trigger();
-
-
---
--- Name: wire_out wire_out_on_delete; Type: TRIGGER; Schema: public; Owner: -
---
-
-CREATE TRIGGER wire_out_on_delete AFTER DELETE ON public.wire_out FOR EACH ROW EXECUTE FUNCTION public.wire_out_delete_trigger();
-
-
---
--- Name: app_bankaccount app_bankaccount_user_id_2722a34f_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_bankaccount
- ADD CONSTRAINT app_bankaccount_user_id_2722a34f_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_banktransaction app_banktransaction_credit_account_id_a8ba05ac_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_credit_account_id_a8ba05ac_fk_app_banka FOREIGN KEY (credit_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_banktransaction app_banktransaction_debit_account_id_5b1f7528_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_banktransaction
- ADD CONSTRAINT app_banktransaction_debit_account_id_5b1f7528_fk_app_banka FOREIGN KEY (debit_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawope_selected_exchange_ac_6c8b96cf_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawope_selected_exchange_ac_6c8b96cf_fk_app_banka FOREIGN KEY (selected_exchange_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: app_talerwithdrawoperation app_talerwithdrawope_withdraw_account_id_992dc5b3_fk_app_banka; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.app_talerwithdrawoperation
- ADD CONSTRAINT app_talerwithdrawope_withdraw_account_id_992dc5b3_fk_app_banka FOREIGN KEY (withdraw_account_id) REFERENCES public.app_bankaccount(account_no) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_auditor_uuid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_auditor_uuid_fkey FOREIGN KEY (auditor_uuid) REFERENCES public.auditors(auditor_uuid) ON DELETE CASCADE;
-
-
---
--- Name: auditor_denom_sigs auditor_denom_sigs_denominations_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_denom_sigs
- ADD CONSTRAINT auditor_denom_sigs_denominations_serial_fkey FOREIGN KEY (denominations_serial) REFERENCES public.denominations(denominations_serial) ON DELETE CASCADE;
-
-
---
--- Name: auth_group_permissions auth_group_permissio_permission_id_84c5c92e_fk_auth_perm; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissio_permission_id_84c5c92e_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_group_permissions auth_group_permissions_group_id_b120cbf9_fk_auth_group_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_group_permissions
- ADD CONSTRAINT auth_group_permissions_group_id_b120cbf9_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_permission auth_permission_content_type_id_2f476e4b_fk_django_co; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_permission
- ADD CONSTRAINT auth_permission_content_type_id_2f476e4b_fk_django_co FOREIGN KEY (content_type_id) REFERENCES public.django_content_type(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_groups auth_user_groups_group_id_97559544_fk_auth_group_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_group_id_97559544_fk_auth_group_id FOREIGN KEY (group_id) REFERENCES public.auth_group(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_groups auth_user_groups_user_id_6a12ed8b_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_groups
- ADD CONSTRAINT auth_user_groups_user_id_6a12ed8b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permi_permission_id_1fbb5f2c_fk_auth_perm FOREIGN KEY (permission_id) REFERENCES public.auth_permission(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: auth_user_user_permissions auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auth_user_user_permissions
- ADD CONSTRAINT auth_user_user_permissions_user_id_a95ead1b_fk_auth_user_id FOREIGN KEY (user_id) REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED;
-
-
---
--- Name: denomination_revocations denomination_revocations_denominations_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.denomination_revocations
- ADD CONSTRAINT denomination_revocations_denominations_serial_fkey FOREIGN KEY (denominations_serial) REFERENCES public.denominations(denominations_serial) ON DELETE CASCADE;
-
-
---
--- Name: auditor_exchange_signkeys master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_exchange_signkeys
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_reserve master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_reserve
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_aggregation master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_aggregation
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_deposit_confirmation master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_deposit_confirmation
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_progress_coin master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_progress_coin
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: wire_auditor_account_progress master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_account_progress
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: wire_auditor_progress master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.wire_auditor_progress
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_reserves master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserves
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_reserve_balance master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_reserve_balance
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_wire_fee_balance master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_wire_fee_balance
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_balance_summary master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_balance_summary
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_historic_denomination_revenue master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_denomination_revenue
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_historic_reserve_summary master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_historic_reserve_summary
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: deposit_confirmations master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.deposit_confirmations
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: auditor_predicted_result master_pub_ref; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.auditor_predicted_result
- ADD CONSTRAINT master_pub_ref FOREIGN KEY (master_pub) REFERENCES public.auditor_exchanges(master_pub) ON DELETE CASCADE;
-
-
---
--- Name: merchant_accounts merchant_accounts_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_accounts
- ADD CONSTRAINT merchant_accounts_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_contract_terms merchant_contract_terms_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_contract_terms
- ADD CONSTRAINT merchant_contract_terms_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial);
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_deposit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_deposit_serial_fkey FOREIGN KEY (deposit_serial) REFERENCES public.merchant_deposits(deposit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposit_to_transfer merchant_deposit_to_transfer_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposit_to_transfer
- ADD CONSTRAINT merchant_deposit_to_transfer_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_contract_terms(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_deposits merchant_deposits_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_deposits
- ADD CONSTRAINT merchant_deposits_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_inventory_locks merchant_inventory_locks_product_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory_locks
- ADD CONSTRAINT merchant_inventory_locks_product_serial_fkey FOREIGN KEY (product_serial) REFERENCES public.merchant_inventory(product_serial);
-
-
---
--- Name: merchant_inventory merchant_inventory_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_inventory
- ADD CONSTRAINT merchant_inventory_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_keys merchant_keys_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_keys
- ADD CONSTRAINT merchant_keys_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_kyc merchant_kyc_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_kyc
- ADD CONSTRAINT merchant_kyc_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_order_locks merchant_order_locks_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_order_locks
- ADD CONSTRAINT merchant_order_locks_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_orders(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_order_locks merchant_order_locks_product_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_order_locks
- ADD CONSTRAINT merchant_order_locks_product_serial_fkey FOREIGN KEY (product_serial) REFERENCES public.merchant_inventory(product_serial);
-
-
---
--- Name: merchant_orders merchant_orders_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_orders
- ADD CONSTRAINT merchant_orders_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_refund_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_refund_serial_fkey FOREIGN KEY (refund_serial) REFERENCES public.merchant_refunds(refund_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refund_proofs merchant_refund_proofs_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refund_proofs
- ADD CONSTRAINT merchant_refund_proofs_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_refunds merchant_refunds_order_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_refunds
- ADD CONSTRAINT merchant_refunds_order_serial_fkey FOREIGN KEY (order_serial) REFERENCES public.merchant_contract_terms(order_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_pickup_signatures merchant_tip_pickup_signatures_pickup_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickup_signatures
- ADD CONSTRAINT merchant_tip_pickup_signatures_pickup_serial_fkey FOREIGN KEY (pickup_serial) REFERENCES public.merchant_tip_pickups(pickup_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_pickups merchant_tip_pickups_tip_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_pickups
- ADD CONSTRAINT merchant_tip_pickups_tip_serial_fkey FOREIGN KEY (tip_serial) REFERENCES public.merchant_tips(tip_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_reserve_keys merchant_tip_reserve_keys_reserve_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserve_keys
- ADD CONSTRAINT merchant_tip_reserve_keys_reserve_serial_fkey FOREIGN KEY (reserve_serial) REFERENCES public.merchant_tip_reserves(reserve_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tip_reserves merchant_tip_reserves_merchant_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tip_reserves
- ADD CONSTRAINT merchant_tip_reserves_merchant_serial_fkey FOREIGN KEY (merchant_serial) REFERENCES public.merchant_instances(merchant_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_tips merchant_tips_reserve_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_tips
- ADD CONSTRAINT merchant_tips_reserve_serial_fkey FOREIGN KEY (reserve_serial) REFERENCES public.merchant_tip_reserves(reserve_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_signatures merchant_transfer_signatures_signkey_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_signatures
- ADD CONSTRAINT merchant_transfer_signatures_signkey_serial_fkey FOREIGN KEY (signkey_serial) REFERENCES public.merchant_exchange_signing_keys(signkey_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_credit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_credit_serial_fkey FOREIGN KEY (credit_serial) REFERENCES public.merchant_transfers(credit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfer_to_coin merchant_transfer_to_coin_deposit_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfer_to_coin
- ADD CONSTRAINT merchant_transfer_to_coin_deposit_serial_fkey FOREIGN KEY (deposit_serial) REFERENCES public.merchant_deposits(deposit_serial) ON DELETE CASCADE;
-
-
---
--- Name: merchant_transfers merchant_transfers_account_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.merchant_transfers
- ADD CONSTRAINT merchant_transfers_account_serial_fkey FOREIGN KEY (account_serial) REFERENCES public.merchant_accounts(account_serial) ON DELETE CASCADE;
-
-
---
--- Name: partner_accounts partner_accounts_partner_serial_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.partner_accounts
- ADD CONSTRAINT partner_accounts_partner_serial_id_fkey FOREIGN KEY (partner_serial_id) REFERENCES public.partners(partner_serial_id) ON DELETE CASCADE;
-
-
---
--- Name: signkey_revocations signkey_revocations_esk_serial_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
---
-
-ALTER TABLE ONLY public.signkey_revocations
- ADD CONSTRAINT signkey_revocations_esk_serial_fkey FOREIGN KEY (esk_serial) REFERENCES public.exchange_sign_keys(esk_serial) ON DELETE CASCADE;
-
-
---
--- PostgreSQL database dump complete
---
diff --git a/src/auditor/setup.sh b/src/auditor/setup.sh
new file mode 100755
index 000000000..bb17e92ae
--- /dev/null
+++ b/src/auditor/setup.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+# This file is in the public domain
+
+# Script to be inlined into the main test scripts. Defines function 'setup()'
+# which wraps around 'taler-unified-setup.sh' to launch GNU Taler services.
+# Call setup() with the arguments to pass to 'taler-unified-setup'. setup()
+# will then launch GNU Taler, wait for the process to be complete before
+# returning. The script will also install an exit handler to ensure the GNU
+# Taler processes are stopped when the shell exits.
+
+set -eu
+
+# Cleanup to run whenever we exit
+function exit_cleanup()
+{
+ if [ ! -z ${SETUP_PID+x} ]
+ then
+ echo "Killing taler-unified-setup ($SETUP_PID)" >&2
+ kill -TERM "$SETUP_PID" 2> /dev/null || true
+ wait "$SETUP_PID" 2> /dev/null || true
+ fi
+}
+
+# Install cleanup handler (except for kill -9)
+trap exit_cleanup EXIT
+
+function setup()
+{
+ echo "Starting test system ..." >&2
+ # Create a named pipe in a temp directory we own.
+ FIFO_DIR=$(mktemp -d fifo-XXXXXX)
+ FIFO_OUT=$(echo "$FIFO_DIR/out")
+ mkfifo "$FIFO_OUT"
+ # Open pipe as FD 3 (RW) and FD 4 (RO)
+ exec 3<> "$FIFO_OUT" 4< "$FIFO_OUT"
+ rm -rf "$FIFO_DIR"
+ # We require '-W' for our termination logic to work.
+ taler-unified-setup.sh -W "$@" \
+ > >(tee taler-unified-setup.log >&3) &
+ SETUP_PID=$!
+ # Close FD3
+ exec 3>&-
+ sed -u '/<<READY>>/ q' <&4
+ # Close FD4
+ exec 4>&-
+ echo "Test system ready" >&2
+}
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_fail() {
+ echo "$@" >&2
+ exit 1
+}
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+ echo "SKIPPING: $1"
+ exit 77
+}
+
+function get_payto_uri() {
+ export LIBEUFIN_SANDBOX_USERNAME="$1"
+ export LIBEUFIN_SANDBOX_PASSWORD="$2"
+ export LIBEUFIN_SANDBOX_URL="http://localhost:18082"
+ echo "get_payto_uri currently not implemented"
+ exit 1
+# libeufin-cli sandbox demobank info --bank-account "$1" | jq --raw-output '.paytoUri'
+}
+
+# Stop libeufin-bank (if running)
+function stop_libeufin()
+{
+ echo -n "Stopping libeufin... "
+ if [ -f "${MY_TMP_DIR:-/}/libeufin-bank.pid" ]
+ then
+ PID=$(cat "${MY_TMP_DIR}/libeufin-bank.pid" 2> /dev/null)
+ echo "Killing libeufin-bank $PID"
+ rm "${MY_TMP_DIR}/libeufin-bank.pid"
+ kill "$PID" 2> /dev/null || true
+ wait "$PID" || true
+ fi
+ echo "DONE"
+}
+
+
+function launch_libeufin () {
+ libeufin-bank serve \
+ -c "$CONF" \
+ -L "INFO" \
+ > "${MY_TMP_DIR}/libeufin-bank-stdout.log" \
+ 2> "${MY_TMP_DIR}/libeufin-bank-stderr.log" &
+ echo $! > "${MY_TMP_DIR}/libeufin-bank.pid"
+}
diff --git a/src/auditor/taler-auditor-dbinit.c b/src/auditor/taler-auditor-dbinit.c
index 54f8152a5..4cb46f470 100644
--- a/src/auditor/taler-auditor-dbinit.c
+++ b/src/auditor/taler-auditor-dbinit.c
@@ -90,7 +90,9 @@ run (void *cls,
"Failed to restart audits\n");
}
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls))
+ plugin->create_tables (plugin->cls,
+ false,
+ 0))
{
fprintf (stderr,
"Failed to initialize database.\n");
diff --git a/src/auditor/taler-auditor-exchange.c b/src/auditor/taler-auditor-exchange.c
deleted file mode 100644
index 04181ce3f..000000000
--- a/src/auditor/taler-auditor-exchange.c
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-auditor-exchange.c
- * @brief Tool used by the auditor to add or remove the exchange's master key
- * to its database.
- * @author Christian Grothoff
- */
-#include <platform.h>
-#include "taler_exchangedb_lib.h"
-#include "taler_auditordb_lib.h"
-
-
-/**
- * URL of the exchange.
- */
-static char *exchange_url;
-
-/**
- * Master public key of the exchange.
- */
-static struct TALER_MasterPublicKeyP master_public_key;
-
-/**
- * Our configuration.
- */
-static struct GNUNET_CONFIGURATION_Handle *cfg;
-
-/**
- * Handle to access the auditor's database.
- */
-static struct TALER_AUDITORDB_Plugin *adb;
-
-/**
- * -r option given.
- */
-static int remove_flag;
-
-
-/**
- * The main function of the taler-auditor-exchange tool. This tool is used
- * to add (or remove) an exchange's master key and base URL to the auditor's
- * database.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return 0 ok, non-zero on error
- */
-int
-main (int argc,
- char *const *argv)
-{
- char *cfgfile = NULL;
- const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_cfgfile (&cfgfile),
- GNUNET_GETOPT_option_help (
- "Add or remove exchange to list of audited exchanges"),
- GNUNET_GETOPT_option_mandatory
- (GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &master_public_key)),
- GNUNET_GETOPT_option_string ('u',
- "exchange-url",
- "URL",
- "base URL of the exchange",
- &exchange_url),
- GNUNET_GETOPT_option_flag ('r',
- "remove",
- "remove the exchange's key (default is to add)",
- &remove_flag),
- GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION),
- GNUNET_GETOPT_OPTION_END
- };
-
- TALER_gcrypt_init (); /* must trigger initialization manually at this point! */
- GNUNET_assert (GNUNET_OK ==
- GNUNET_log_setup ("taler-auditor-exchange",
- "WARNING",
- NULL));
- {
- int ret;
-
- ret = GNUNET_GETOPT_run ("taler-auditor-exchange",
- options,
- argc, argv);
- if (GNUNET_NO == ret)
- return EXIT_SUCCESS;
- if (GNUNET_SYSERR == ret)
- return EXIT_INVALIDARGUMENT;
- }
- if (NULL == cfgfile)
- cfgfile = GNUNET_CONFIGURATION_default_filename ();
- if (NULL == cfgfile)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Can't find default configuration file.\n");
- return EXIT_NOTCONFIGURED;
- }
- cfg = GNUNET_CONFIGURATION_create ();
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Loading config file: %s\n",
- cfgfile);
-
- if (GNUNET_SYSERR ==
- GNUNET_CONFIGURATION_load (cfg,
- cfgfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed configuration file `%s', exit ...\n",
- cfgfile);
- GNUNET_free (cfgfile);
- return EXIT_NOTCONFIGURED;
- }
- GNUNET_free (cfgfile);
-
- if (! remove_flag)
- {
- if (NULL == exchange_url)
- {
- fprintf (stderr,
- _ ("Missing either `%s' or `%s'.\n"),
- "-u URL",
- "--remove");
- return EXIT_INVALIDARGUMENT;
- }
- if ( (0 == strlen (exchange_url)) ||
- ( (0 != strncasecmp ("http://",
- exchange_url,
- strlen ("http://"))) &&
- (0 != strncasecmp ("https://",
- exchange_url,
- strlen ("https://"))) ) ||
- ('/' != exchange_url[strlen (exchange_url) - 1]) )
- {
- fprintf (stderr,
- "Exchange URL must begin with `http://` or `https://` and end with `/'\n");
- return EXIT_INVALIDARGUMENT;
- }
- }
-
-
- if (NULL ==
- (adb = TALER_AUDITORDB_plugin_load (cfg)))
- {
- fprintf (stderr,
- "Failed to initialize auditor database plugin.\n");
- return EXIT_NOTINSTALLED;
- }
-
- /* Create required tables */
- if (GNUNET_OK !=
- adb->create_tables (adb->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create tables in auditor's database\n");
- TALER_AUDITORDB_plugin_unload (adb);
- return EXIT_NOPERMISSION;
- }
-
- /* Update DB */
- {
- enum GNUNET_DB_QueryStatus qs;
-
- if (GNUNET_SYSERR ==
- adb->preflight (adb->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to initialize database connection\n");
- TALER_AUDITORDB_plugin_unload (adb);
- return EXIT_FAILURE;
- }
-
- if (remove_flag)
- {
- qs = adb->delete_exchange (adb->cls,
- &master_public_key);
- }
- else
- {
- qs = adb->insert_exchange (adb->cls,
- &master_public_key,
- exchange_url);
- }
- if (0 > qs)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to update auditor database (status code: %d)\n",
- qs);
- TALER_AUDITORDB_plugin_unload (adb);
- return EXIT_FAILURE;
- }
- if (0 == qs)
- {
- GNUNET_log (
- GNUNET_ERROR_TYPE_WARNING,
- (remove_flag)
- ? "Could not remove exchange from database: entry already absent\n"
- : "Could not add exchange to database: entry already exists\n");
- TALER_AUDITORDB_plugin_unload (adb);
- return EXIT_FAILURE;
- }
- }
- TALER_AUDITORDB_plugin_unload (adb);
- return EXIT_SUCCESS;
-}
-
-
-/* end of taler-auditor-exchange.c */
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c
index a212eddca..59bd849bc 100644
--- a/src/auditor/taler-auditor-httpd.c
+++ b/src/auditor/taler-auditor-httpd.c
@@ -31,7 +31,7 @@
#include "taler_auditordb_lib.h"
#include "taler_exchangedb_lib.h"
#include "taler-auditor-httpd_deposit-confirmation.h"
-#include "taler-auditor-httpd_exchanges.h"
+#include "taler-auditor-httpd_deposit-confirmation-get.h"
#include "taler-auditor-httpd_mhd.h"
#include "taler-auditor-httpd.h"
@@ -48,7 +48,8 @@
* release version, and the format is NOT the same that semantic
* versioning uses either.
*/
-#define AUDITOR_PROTOCOL_VERSION "0:0:0"
+#define AUDITOR_PROTOCOL_VERSION "1:0:1"
+
/**
* Backlog for listen operation on unix domain sockets.
@@ -81,6 +82,12 @@ struct TALER_EXCHANGEDB_Plugin *TAH_eplugin;
static struct TALER_AuditorPublicKeyP auditor_pub;
/**
+ * Exchange master public key (according to the
+ * configuration). (global)
+ */
+struct TALER_MasterPublicKeyP TAH_master_public_key;
+
+/**
* Default timeout in seconds for HTTP requests.
*/
static unsigned int connection_timeout = 30;
@@ -132,7 +139,7 @@ handle_mhd_completion_callback (void *cls,
/**
- * Handle a "/version" request.
+ * Handle a "/config" request.
*
* @param rh context of the handler
* @param connection the MHD connection to handle
@@ -142,11 +149,11 @@ handle_mhd_completion_callback (void *cls,
* @return MHD result code
*/
static MHD_RESULT
-handle_version (struct TAH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+handle_config (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
{
static json_t *ver; /* we build the response only once, keep around for next query! */
@@ -157,12 +164,18 @@ handle_version (struct TAH_RequestHandler *rh,
if (NULL == ver)
{
ver = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("name",
+ "taler-auditor"),
GNUNET_JSON_pack_string ("version",
AUDITOR_PROTOCOL_VERSION),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:taler-auditor:c-reference"),
GNUNET_JSON_pack_string ("currency",
TAH_currency),
GNUNET_JSON_pack_data_auto ("auditor_public_key",
- &auditor_pub));
+ &auditor_pub),
+ GNUNET_JSON_pack_data_auto ("exchange_master_public_key",
+ &TAH_master_public_key));
}
if (NULL == ver)
{
@@ -204,12 +217,15 @@ handle_mhd_request (void *cls,
{ "/deposit-confirmation", MHD_HTTP_METHOD_PUT, "application/json",
NULL, 0,
&TAH_DEPOSIT_CONFIRMATION_handler, MHD_HTTP_OK },
- { "/exchanges", MHD_HTTP_METHOD_GET, "application/json",
+ { "/deposit-confirmation", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
- &TAH_EXCHANGES_handler, MHD_HTTP_OK },
- { "/version", MHD_HTTP_METHOD_GET, "application/json",
+ &TAH_DEPOSIT_CONFIRMATION_handler_get, MHD_HTTP_OK },
+// { "/deposit-confirmation", MHD_HTTP_METHOD_DELETE, "application/json",
+// NULL, 0,
+// &TAH_DEPOSIT_CONFIRMATION_delete, MHD_HTTP_OK },
+ { "/config", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0,
- &handle_version, MHD_HTTP_OK },
+ &handle_config, MHD_HTTP_OK },
/* Landing page, for now tells humans to go away
* (NOTE: ideally, the reverse proxy will respond with a nicer page) */
{ "/", MHD_HTTP_METHOD_GET, "text/plain",
@@ -298,6 +314,40 @@ auditor_serve_process_config (void)
{
return GNUNET_SYSERR;
}
+
+ {
+ char *master_public_key_str;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "MASTER_PUBLIC_KEY",
+ &master_public_key_str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "MASTER_PUBLIC_KEY");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (
+ master_public_key_str,
+ strlen (master_public_key_str),
+ &TAH_master_public_key.eddsa_pub))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "MASTER_PUBLIC_KEY",
+ "invalid base32 encoding for a master public key");
+ GNUNET_free (master_public_key_str);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Launching auditor for exchange `%s'...\n",
+ master_public_key_str);
+ GNUNET_free (master_public_key_str);
+ }
+
{
char *pub;
diff --git a/src/auditor/taler-auditor-httpd.h b/src/auditor/taler-auditor-httpd.h
index 79e56ff55..853722f09 100644
--- a/src/auditor/taler-auditor-httpd.h
+++ b/src/auditor/taler-auditor-httpd.h
@@ -39,6 +39,12 @@ extern struct TALER_AUDITORDB_Plugin *TAH_plugin;
extern struct TALER_EXCHANGEDB_Plugin *TAH_eplugin;
/**
+ * Exchange master public key (according to the
+ * configuration). (global)
+ */
+extern struct TALER_MasterPublicKeyP TAH_master_public_key;
+
+/**
* Our currency.
*/
extern char *TAH_currency;
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c
new file mode 100644
index 000000000..265d625c4
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.c
@@ -0,0 +1,166 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file taler-auditor-httpd_deposit-confirmation-get.c
+ * @brief Handle /deposit-confirmation requests; return list of deposit confirmations from merchant
+ * that were not received from the exchange, by auditor.
+ * @author Nic Eigel
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-auditor-httpd.h"
+#include "taler-auditor-httpd_deposit-confirmation-get.h"
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Information about a signing key of the exchange. Signing keys are used
+ * to sign exchange messages other than coins, i.e. to confirm that a
+ * deposit was successful or that a refresh was accepted.
+ */
+struct ExchangeSigningKeyDataP
+{
+
+ /**
+ * When does this signing key begin to be valid?
+ */
+ struct GNUNET_TIME_TimestampNBO start;
+
+ /**
+ * When does this signing key expire? Note: This is currently when
+ * the Exchange will definitively stop using it. Signatures made with
+ * the key remain valid until @e end. When checking validity periods,
+ * clients should allow for some overlap between keys and tolerate
+ * the use of either key during the overlap time (due to the
+ * possibility of clock skew).
+ */
+ struct GNUNET_TIME_TimestampNBO expire;
+
+ /**
+ * When do signatures with this signing key become invalid? After
+ * this point, these signatures cannot be used in (legal) disputes
+ * anymore, as the Exchange is then allowed to destroy its side of the
+ * evidence. @e end is expected to be significantly larger than @e
+ * expire (by a year or more).
+ */
+ struct GNUNET_TIME_TimestampNBO end;
+
+ /**
+ * The public online signing key that the exchange will use
+ * between @e start and @e expire.
+ */
+ struct TALER_ExchangePublicKeyP signkey_pub;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+/**
+ * Add deposit confirmation to the list.
+ *
+ * @param[in,out] cls a `json_t *` array to extend
+ * @param serial_id location of the @a dc in the database
+ * @param dc struct of deposit confirmation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
+ */
+static enum GNUNET_GenericReturnValue
+add_deposit_confirmation (void *cls,
+ uint64_t serial_id,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc)
+{
+ json_t *list = cls;
+ json_t *obj;
+
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("dc",
+ dc));
+ GNUNET_break (0 ==
+ json_array_append_new (list,
+ obj));
+ return GNUNET_OK;
+}
+
+
+/**
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ json_t *ja;
+ enum GNUNET_DB_QueryStatus qs;
+
+ (void) rh;
+ (void) connection_cls;
+ (void) upload_data;
+ (void) upload_data_size;
+ if (GNUNET_SYSERR ==
+ TAH_plugin->preflight (TAH_plugin->cls))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SETUP_FAILED,
+ NULL);
+ }
+ ja = json_array ();
+ GNUNET_break (NULL != ja);
+ // TODO correct below
+ qs = TAH_plugin->get_deposit_confirmations (
+ TAH_plugin->cls,
+ 0, /* FIXME: get from query parameters! */
+ false, /* FIXME: get from query parameters! */
+ &add_deposit_confirmation,
+ ja);
+
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ json_decref (ja);
+ TALER_LOG_WARNING (
+ "Failed to handle GET /deposit-confirmation in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "deposit-confirmation");
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("deposit-confirmation",
+ ja));
+}
+
+
+/* end of taler-auditor-httpd_deposit-confirmation-get.c */
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h
new file mode 100644
index 000000000..f1f522787
--- /dev/null
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation-get.h
@@ -0,0 +1,70 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-auditor-httpd_deposit-confirmation-get.h
+ * @brief Handle GET /deposit-confirmation requests
+ * @author Nic Eigel
+ */
+#ifndef TALER_AUDITOR_HTTPD_DEPOSIT_CONFIRMATION_GET_H
+#define TALER_AUDITOR_HTTPD_DEPOSIT_CONFIRMATION_GET_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <microhttpd.h>
+#include "taler-auditor-httpd.h"
+
+/**
+ * Initialize subsystem.
+ */
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_init (void);
+
+/**
+ * Shut down subsystem.
+ */
+void
+TEAH_DEPOSIT_CONFIRMATION_GET_done (void);
+
+/**
+ * Handle a "/deposit-confirmation" request.
+ *
+ * @param rh context of the handler
+ * @param connection the MHD connection to handle
+ * @param[in,out] connection_cls the connection's closure (can be updated)
+ * @param upload_data upload data
+ * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @return MHD result code
+ */
+MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_handler_get (struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size);
+
+/**
+ * Handle a DELETE "/deposit-confirmation/$dc" request.
+ *
+ * @param rc request details about the request to handle
+ * @param args argument with the dc primary key
+ * @return MHD result code
+ */
+/*MHD_RESULT
+TAH_DEPOSIT_CONFIRMATION_delete (
+ struct TEH_RequestContext *rc,
+ const char *const args[1]);*/
+
+
+#endif
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.c b/src/auditor/taler-auditor-httpd_deposit-confirmation.c
index f4d89b7ca..8b449bf47 100644
--- a/src/auditor/taler-auditor-httpd_deposit-confirmation.c
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -31,7 +31,6 @@
#include "taler-auditor-httpd.h"
#include "taler-auditor-httpd_deposit-confirmation.h"
-
GNUNET_NETWORK_STRUCT_BEGIN
/**
@@ -115,9 +114,14 @@ verify_and_execute_deposit_confirmation (
.end = GNUNET_TIME_timestamp_hton (es->ep_end),
.signkey_pub = es->exchange_pub
};
+ const struct TALER_CoinSpendSignatureP *coin_sigps[
+ GNUNET_NZL (dc->num_coins)];
+
+ for (unsigned int i = 0; i < dc->num_coins; i++)
+ coin_sigps[i] = &dc->coin_sigs[i];
if (GNUNET_TIME_absolute_is_future (es->ep_start.abs_time) ||
- GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time) )
+ GNUNET_TIME_absolute_is_past (es->ep_expire.abs_time))
{
/* Signing key expired */
TALER_LOG_WARNING ("Expired exchange signing key\n");
@@ -129,7 +133,7 @@ verify_and_execute_deposit_confirmation (
/* check our cache */
GNUNET_CRYPTO_hash (&skv,
- sizeof (skv),
+ sizeof(skv),
&h);
GNUNET_assert (0 == pthread_mutex_lock (&lock));
cached = GNUNET_CONTAINER_multihashmap_get (cache,
@@ -153,7 +157,7 @@ verify_and_execute_deposit_confirmation (
es->ep_start,
es->ep_expire,
es->ep_end,
- &es->master_public_key,
+ &TAH_master_public_key,
&es->master_sig))
{
TALER_LOG_WARNING ("Invalid signature on exchange signing key\n");
@@ -227,12 +231,13 @@ verify_and_execute_deposit_confirmation (
TALER_exchange_online_deposit_confirmation_verify (
&dc->h_contract_terms,
&dc->h_wire,
- NULL /* h_extensions! */,
+ &dc->h_policy,
dc->exchange_timestamp,
dc->wire_deadline,
dc->refund_deadline,
- &dc->amount_without_fee,
- &dc->coin_pub,
+ &dc->total_without_fee,
+ dc->num_coins,
+ coin_sigps,
&dc->merchant,
&dc->exchange_pub,
&dc->exchange_sig))
@@ -265,40 +270,47 @@ verify_and_execute_deposit_confirmation (
MHD_RESULT
-TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
+TAH_DEPOSIT_CONFIRMATION_handler (
+ struct TAH_RequestHandler *rh,
+ struct MHD_Connection *connection,
+ void **connection_cls,
+ const char *upload_data,
+ size_t *upload_data_size)
{
- struct TALER_AUDITORDB_DepositConfirmation dc;
+ struct TALER_AUDITORDB_DepositConfirmation dc = {
+ .refund_deadline = GNUNET_TIME_UNIT_ZERO_TS
+ };
struct TALER_AUDITORDB_ExchangeSigningKey es;
+ const json_t *jcoin_sigs;
+ const json_t *jcoin_pubs;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
&dc.h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("h_extensions",
- &dc.h_extensions),
+ GNUNET_JSON_spec_fixed_auto ("h_policy",
+ &dc.h_policy),
GNUNET_JSON_spec_fixed_auto ("h_wire",
&dc.h_wire),
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
&dc.exchange_timestamp),
- GNUNET_JSON_spec_timestamp ("refund_deadline",
- &dc.refund_deadline),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("refund_deadline",
+ &dc.refund_deadline),
+ NULL),
GNUNET_JSON_spec_timestamp ("wire_deadline",
&dc.wire_deadline),
- TALER_JSON_spec_amount ("amount_without_fee",
+ TALER_JSON_spec_amount ("total_without_fee",
TAH_currency,
- &dc.amount_without_fee),
- GNUNET_JSON_spec_fixed_auto ("coin_pub",
- &dc.coin_pub),
+ &dc.total_without_fee),
+ GNUNET_JSON_spec_array_const ("coin_pubs",
+ &jcoin_pubs),
+ GNUNET_JSON_spec_array_const ("coin_sigs",
+ &jcoin_sigs),
GNUNET_JSON_spec_fixed_auto ("merchant_pub",
&dc.merchant),
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
&dc.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&dc.exchange_pub),
- GNUNET_JSON_spec_fixed_auto ("master_pub",
- &es.master_public_key),
GNUNET_JSON_spec_timestamp ("ep_start",
&es.ep_start),
GNUNET_JSON_spec_timestamp ("ep_expire",
@@ -309,13 +321,14 @@ TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh,
&es.master_sig),
GNUNET_JSON_spec_end ()
};
+ unsigned int num_coins;
+ json_t *json;
(void) rh;
(void) connection_cls;
(void) upload_data;
(void) upload_data_size;
{
- json_t *json;
enum GNUNET_GenericReturnValue res;
res = TALER_MHD_parse_post_json (connection,
@@ -325,28 +338,94 @@ TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh,
&json);
if (GNUNET_SYSERR == res)
return MHD_NO;
- if ( (GNUNET_NO == res) ||
- (NULL == json) )
+ if ((GNUNET_NO == res) ||
+ (NULL == json))
return MHD_YES;
res = TALER_MHD_parse_json_data (connection,
json,
spec);
- json_decref (json);
if (GNUNET_SYSERR == res)
- return MHD_NO; /* hard failure */
+ {
+ json_decref (json);
+ return MHD_NO; /* hard failure */
+ }
if (GNUNET_NO == res)
- return MHD_YES; /* failure */
+ {
+ json_decref (json);
+ return MHD_YES; /* failure */
+ }
}
-
- es.exchange_pub = dc.exchange_pub; /* used twice! */
- dc.master_public_key = es.master_public_key;
+ num_coins = json_array_size (jcoin_sigs);
+ if (num_coins != json_array_size (jcoin_pubs))
{
+ GNUNET_break_op (0);
+ json_decref (json);
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "coin_pubs.length != coin_sigs.length");
+ }
+ if (0 == num_coins)
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "coin_pubs array is empty");
+ }
+ {
+ struct TALER_CoinSpendPublicKeyP coin_pubs[num_coins];
+ struct TALER_CoinSpendSignatureP coin_sigs[num_coins];
MHD_RESULT res;
+ for (unsigned int i = 0; i < num_coins; i++)
+ {
+ json_t *jpub = json_array_get (jcoin_pubs,
+ i);
+ json_t *jsig = json_array_get (jcoin_sigs,
+ i);
+ const char *ps = json_string_value (jpub);
+ const char *ss = json_string_value (jsig);
+
+ if ((NULL == ps) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (ps,
+ strlen (ps),
+ &coin_pubs[i],
+ sizeof(coin_pubs[i]))))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "coin_pub[] malformed");
+ }
+ if ((NULL == ss) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (ss,
+ strlen (ss),
+ &coin_sigs[i],
+ sizeof(coin_sigs[i]))))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "coin_sig[] malformed");
+ }
+ }
+ dc.num_coins = num_coins;
+ dc.coin_pubs = coin_pubs;
+ dc.coin_sigs = coin_sigs;
+ es.exchange_pub = dc.exchange_pub; /* used twice! */
res = verify_and_execute_deposit_confirmation (connection,
&dc,
&es);
GNUNET_JSON_parse_free (spec);
+ json_decref (json);
return res;
}
}
@@ -371,6 +450,3 @@ TEAH_DEPOSIT_CONFIRMATION_done (void)
GNUNET_assert (0 == pthread_mutex_destroy (&lock));
}
}
-
-
-/* end of taler-auditor-httpd_deposit-confirmation.c */
diff --git a/src/auditor/taler-auditor-httpd_deposit-confirmation.h b/src/auditor/taler-auditor-httpd_deposit-confirmation.h
index a7c331916..1226dda69 100644
--- a/src/auditor/taler-auditor-httpd_deposit-confirmation.h
+++ b/src/auditor/taler-auditor-httpd_deposit-confirmation.h
@@ -56,4 +56,5 @@ TAH_DEPOSIT_CONFIRMATION_handler (struct TAH_RequestHandler *rh,
const char *upload_data,
size_t *upload_data_size);
+
#endif
diff --git a/src/auditor/taler-auditor-httpd_exchanges.c b/src/auditor/taler-auditor-httpd_exchanges.c
deleted file mode 100644
index f9a9e9e60..000000000
--- a/src/auditor/taler-auditor-httpd_exchanges.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-auditor-httpd_exchanges.c
- * @brief Handle /exchanges requests; returns list of exchanges we audit
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <jansson.h>
-#include <microhttpd.h>
-#include <pthread.h>
-#include "taler_json_lib.h"
-#include "taler_mhd_lib.h"
-#include "taler-auditor-httpd.h"
-#include "taler-auditor-httpd_exchanges.h"
-
-
-/**
- * Add exchange information to the list.
- *
- * @param[in,out] cls a `json_t *` array to extend
- * @param master_pub master public key of an exchange
- * @param exchange_url base URL of an exchange
- */
-static void
-add_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url)
-{
- json_t *list = cls;
- json_t *obj;
-
- obj = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("master_pub",
- master_pub),
- GNUNET_JSON_pack_string ("exchange_url",
- exchange_url));
- GNUNET_break (0 ==
- json_array_append_new (list,
- obj));
-
-}
-
-
-/**
- * Handle a "/exchanges" request.
- *
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
- * @return MHD result code
- */
-MHD_RESULT
-TAH_EXCHANGES_handler (struct TAH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size)
-{
- json_t *ja;
- enum GNUNET_DB_QueryStatus qs;
-
- (void) rh;
- (void) connection_cls;
- (void) upload_data;
- (void) upload_data_size;
- if (GNUNET_SYSERR ==
- TAH_plugin->preflight (TAH_plugin->cls))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_SETUP_FAILED,
- NULL);
- }
- ja = json_array ();
- GNUNET_break (NULL != ja);
- qs = TAH_plugin->list_exchanges (TAH_plugin->cls,
- &add_exchange,
- ja);
- if (0 > qs)
- {
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- json_decref (ja);
- TALER_LOG_WARNING ("Failed to handle /exchanges in database\n");
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "exchanges");
- }
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal ("exchanges",
- ja));
-}
-
-
-/* end of taler-auditor-httpd_exchanges.c */
diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c
index 6a44bc20c..e4022d325 100644
--- a/src/auditor/taler-auditor-sync.c
+++ b/src/auditor/taler-auditor-sync.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -92,9 +92,13 @@ static struct Table tables[] = {
{ .rt = TALER_EXCHANGEDB_RT_DENOMINATIONS},
{ .rt = TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS},
{ .rt = TALER_EXCHANGEDB_RT_WIRE_TARGETS},
+ { .rt = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES},
+ { .rt = TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS},
{ .rt = TALER_EXCHANGEDB_RT_RESERVES},
{ .rt = TALER_EXCHANGEDB_RT_RESERVES_IN},
{ .rt = TALER_EXCHANGEDB_RT_RESERVES_CLOSE},
+ { .rt = TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS},
+ { .rt = TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS},
{ .rt = TALER_EXCHANGEDB_RT_RESERVES_OUT},
{ .rt = TALER_EXCHANGEDB_RT_AUDITORS},
{ .rt = TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS},
@@ -104,7 +108,8 @@ static struct Table tables[] = {
{ .rt = TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS},
{ .rt = TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS},
{ .rt = TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS},
- { .rt = TALER_EXCHANGEDB_RT_DEPOSITS},
+ { .rt = TALER_EXCHANGEDB_RT_BATCH_DEPOSITS},
+ { .rt = TALER_EXCHANGEDB_RT_COIN_DEPOSITS},
{ .rt = TALER_EXCHANGEDB_RT_REFUNDS},
{ .rt = TALER_EXCHANGEDB_RT_WIRE_OUT},
{ .rt = TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING},
@@ -113,9 +118,10 @@ static struct Table tables[] = {
{ .rt = TALER_EXCHANGEDB_RT_RECOUP},
{ .rt = TALER_EXCHANGEDB_RT_RECOUP_REFRESH },
{ .rt = TALER_EXCHANGEDB_RT_EXTENSIONS},
- { .rt = TALER_EXCHANGEDB_RT_EXTENSION_DETAILS },
+ { .rt = TALER_EXCHANGEDB_RT_POLICY_DETAILS },
+ { .rt = TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS },
{ .rt = TALER_EXCHANGEDB_RT_PURSE_REQUESTS},
- { .rt = TALER_EXCHANGEDB_RT_PURSE_REFUNDS},
+ { .rt = TALER_EXCHANGEDB_RT_PURSE_DECISION},
{ .rt = TALER_EXCHANGEDB_RT_PURSE_MERGES},
{ .rt = TALER_EXCHANGEDB_RT_PURSE_DEPOSITS},
{ .rt = TALER_EXCHANGEDB_RT_ACCOUNT_MERGES},
@@ -125,6 +131,7 @@ static struct Table tables[] = {
{ .rt = TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES},
{ .rt = TALER_EXCHANGEDB_RT_WADS_IN},
{ .rt = TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES},
+ { .rt = TALER_EXCHANGEDB_RT_PROFIT_DRAINS},
{ .end = true }
};
@@ -154,7 +161,7 @@ struct InsertContext
* @return #GNUNET_OK to continue to iterate,
* #GNUNET_SYSERR to fail with an error
*/
-static int
+static enum GNUNET_GenericReturnValue
do_insert (void *cls,
const struct TALER_EXCHANGEDB_TableData *td)
{
@@ -387,7 +394,7 @@ do_sync (void *cls)
* @param value actual value of the option (a string)
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
void *scls,
const char *option,
@@ -599,6 +606,9 @@ main (int argc,
level,
NULL));
GNUNET_free (level);
+ /* suppress compiler warnings... */
+ GNUNET_assert (NULL != src_cfgfile);
+ GNUNET_assert (NULL != dst_cfgfile);
if (0 == strcmp (src_cfgfile,
dst_cfgfile))
{
diff --git a/src/auditor/taler-auditor.in b/src/auditor/taler-auditor.in
index 6a8e88daa..ab3d8d202 100644
--- a/src/auditor/taler-auditor.in
+++ b/src/auditor/taler-auditor.in
@@ -83,14 +83,17 @@ optcheck "$@"
ARGS=("$@")
ARGS=(${ARGS[@]/$INF})
-DIR=`mktemp -d reportXXXXXX`
-for n in aggregation coins deposits reserves
+DATE=`date +%F_%H:%M:%S`
+DIR="report_$DATE"
+mkdir $DIR
+for n in aggregation coins deposits purses reserves
do
taler-helper-auditor-$n ${ARGS[*]} > ${DIR}/$n.json
done
taler-helper-auditor-wire $INF ${ARGS[*]} > ${DIR}/wire.json
+echo "Generating auditor report in ${DIR}."
taler-helper-auditor-render.py \
${DIR}/aggregation.json \
${DIR}/coins.json \
diff --git a/src/auditor/taler-helper-auditor-aggregation.c b/src/auditor/taler-helper-auditor-aggregation.c
index 1c22a48b2..a0f2a190f 100644
--- a/src/auditor/taler-helper-auditor-aggregation.c
+++ b/src/auditor/taler-helper-auditor-aggregation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2022 Taler Systems SA
+ Copyright (C) 2016-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero Public License as published by the Free Software
@@ -34,17 +34,26 @@
static int global_ret;
/**
- * Checkpointing our progress for aggregations.
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
*/
-static struct TALER_AUDITORDB_ProgressPointAggregation ppa;
+static int test_mode;
/**
* Checkpointing our progress for aggregations.
*/
-static struct TALER_AUDITORDB_ProgressPointAggregation ppa_start;
+static TALER_ARL_DEF_PP (aggregation_last_wire_out_serial_id);
+
+/**
+ * Total aggregation fees (wire fees) earned.
+ */
+static TALER_ARL_DEF_AB (aggregation_total_wire_fee_revenue);
+
/**
- * Array of reports about row inconsitencies.
+ * Array of reports about row inconsistencies.
*/
static json_t *report_row_inconsistencies;
@@ -102,11 +111,6 @@ static struct TALER_Amount total_arithmetic_delta_plus;
static struct TALER_Amount total_arithmetic_delta_minus;
/**
- * Total aggregation fees earned.
- */
-static struct TALER_Amount total_aggregation_fee_income;
-
-/**
* Array of reports about coin operations with bad signatures.
*/
static json_t *report_bad_sig_losses;
@@ -398,9 +402,9 @@ check_transaction_history_for_deposit (
struct TALER_Amount expenditures;
struct TALER_Amount refunds;
struct TALER_Amount spent;
+ struct TALER_Amount *deposited = NULL;
struct TALER_Amount merchant_loss;
const struct TALER_Amount *deposit_fee;
- bool refund_deposit_fee;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking transaction history of coin %s\n",
@@ -422,24 +426,33 @@ check_transaction_history_for_deposit (
compute positive (deposit, melt) and negative (refund) values separately
here, and then subtract the negative from the positive at the end (after
the loops). */
- refund_deposit_fee = false;
deposit_fee = NULL;
for (const struct TALER_EXCHANGEDB_TransactionList *tl = tl_head;
NULL != tl;
tl = tl->next)
{
- const struct TALER_Amount *amount_with_fee;
const struct TALER_Amount *fee_claimed;
switch (tl->type)
{
case TALER_EXCHANGEDB_TT_DEPOSIT:
/* check wire and h_wire are consistent */
- amount_with_fee = &tl->details.deposit->amount_with_fee; /* according to exchange*/
+ if (NULL != deposited)
+ {
+ TALER_ARL_report (report_row_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("table",
+ "deposits"),
+ GNUNET_JSON_pack_uint64 ("row",
+ tl->serial_id),
+ GNUNET_JSON_pack_string ("diagnostic",
+ "multiple deposits of the same coin into the same contract detected")));
+ }
+ deposited = &tl->details.deposit->amount_with_fee; /* according to exchange*/
fee_claimed = &tl->details.deposit->deposit_fee; /* Fee according to exchange DB */
TALER_ARL_amount_add (&expenditures,
&expenditures,
- amount_with_fee);
+ deposited);
/* Check if this deposit is within the remit of the aggregation
we are investigating, if so, include it in the totals. */
if ( (0 == GNUNET_memcmp (merchant_pub,
@@ -450,7 +463,7 @@ check_transaction_history_for_deposit (
struct TALER_Amount amount_without_fee;
TALER_ARL_amount_subtract (&amount_without_fee,
- amount_with_fee,
+ deposited,
fee_claimed);
TALER_ARL_amount_add (merchant_gain,
merchant_gain,
@@ -474,97 +487,155 @@ check_transaction_history_for_deposit (
}
break;
case TALER_EXCHANGEDB_TT_MELT:
- amount_with_fee = &tl->details.melt->amount_with_fee;
- fee_claimed = &tl->details.melt->melt_fee;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- /* Check that the fees given in the transaction list and in dki match */
- if (0 !=
- TALER_amount_cmp (&issue->fees.refresh,
- fee_claimed))
{
- /* Disagreement in fee structure between exchange and auditor */
- report_amount_arithmetic_inconsistency ("melt fee",
- 0,
- fee_claimed,
- &issue->fees.refresh,
- 1);
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.melt->amount_with_fee;
+ fee_claimed = &tl->details.melt->melt_fee;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ /* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.refresh,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between exchange and auditor */
+ report_amount_arithmetic_inconsistency ("melt fee",
+ 0,
+ fee_claimed,
+ &issue->fees.refresh,
+ 1);
+ }
+ break;
}
- break;
case TALER_EXCHANGEDB_TT_REFUND:
- amount_with_fee = &tl->details.refund->refund_amount;
- fee_claimed = &tl->details.refund->refund_fee;
- TALER_ARL_amount_add (&refunds,
- &refunds,
- amount_with_fee);
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- fee_claimed);
- /* Check if this refund is within the remit of the aggregation
- we are investigating, if so, include it in the totals. */
- if ( (0 == GNUNET_memcmp (merchant_pub,
- &tl->details.refund->merchant_pub)) &&
- (0 == GNUNET_memcmp (h_contract_terms,
- &tl->details.refund->h_contract_terms)) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Detected applicable refund of %s\n",
- TALER_amount2s (amount_with_fee));
- TALER_ARL_amount_add (&merchant_loss,
- &merchant_loss,
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.refund->refund_amount;
+ fee_claimed = &tl->details.refund->refund_fee;
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
amount_with_fee);
- /* If there is a refund, we give back the deposit fee */
- /* FIXME: wrong: only if this is a FULL
- refund we refund the deposit fee! */
- refund_deposit_fee = true;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ fee_claimed);
+ /* Check if this refund is within the remit of the aggregation
+ we are investigating, if so, include it in the totals. */
+ if ( (0 == GNUNET_memcmp (merchant_pub,
+ &tl->details.refund->merchant_pub)) &&
+ (0 == GNUNET_memcmp (h_contract_terms,
+ &tl->details.refund->h_contract_terms)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Detected applicable refund of %s\n",
+ TALER_amount2s (amount_with_fee));
+ TALER_ARL_amount_add (&merchant_loss,
+ &merchant_loss,
+ amount_with_fee);
+ }
+ /* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.refund,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between exchange and auditor! */
+ report_amount_arithmetic_inconsistency ("refund fee",
+ 0,
+ fee_claimed,
+ &issue->fees.refund,
+ 1);
+ }
+ break;
}
- /* Check that the fees given in the transaction list and in dki match */
- if (0 !=
- TALER_amount_cmp (&issue->fees.refund,
- fee_claimed))
+ case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
{
- /* Disagreement in fee structure between exchange and auditor! */
- report_amount_arithmetic_inconsistency ("refund fee",
- 0,
- fee_claimed,
- &issue->fees.refund,
- 1);
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.old_coin_recoup->value;
+ /* We count recoups of refreshed coins like refunds for the dirty old
+ coin, as they equivalently _increase_ the remaining value on the
+ _old_ coin */
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
+ amount_with_fee);
+ break;
}
- break;
- case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
- amount_with_fee = &tl->details.old_coin_recoup->value;
- /* We count recoups of refreshed coins like refunds for the dirty old
- coin, as they equivalently _increase_ the remaining value on the
- _old_ coin */
- TALER_ARL_amount_add (&refunds,
- &refunds,
- amount_with_fee);
- break;
case TALER_EXCHANGEDB_TT_RECOUP:
- /* We count recoups of the coin as expenditures, as it
- equivalently decreases the remaining value of the recouped coin. */
- amount_with_fee = &tl->details.recoup->value;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- break;
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ /* We count recoups of the coin as expenditures, as it
+ equivalently decreases the remaining value of the recouped coin. */
+ amount_with_fee = &tl->details.recoup->value;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
- /* We count recoups of the coin as expenditures, as it
- equivalently decreases the remaining value of the recouped coin. */
- amount_with_fee = &tl->details.recoup_refresh->value;
- TALER_ARL_amount_add (&expenditures,
- &expenditures,
- amount_with_fee);
- break;
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ /* We count recoups of the coin as expenditures, as it
+ equivalently decreases the remaining value of the recouped coin. */
+ amount_with_fee = &tl->details.recoup_refresh->value;
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
- amount_with_fee = &tl->details.purse_deposit->amount;
- if (! tl->details.purse_deposit->refunded)
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.purse_deposit->amount;
+ if (! tl->details.purse_deposit->refunded)
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ amount_with_fee);
+ break;
+ }
+
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.purse_refund->refund_amount;
+ fee_claimed = &tl->details.purse_refund->refund_fee;
+ TALER_ARL_amount_add (&refunds,
+ &refunds,
+ amount_with_fee);
+ TALER_ARL_amount_add (&expenditures,
+ &expenditures,
+ fee_claimed);
+ /* Check that the fees given in the transaction list and in dki match */
+ if (0 !=
+ TALER_amount_cmp (&issue->fees.refund,
+ fee_claimed))
+ {
+ /* Disagreement in fee structure between exchange and auditor! */
+ report_amount_arithmetic_inconsistency ("refund fee",
+ 0,
+ fee_claimed,
+ &issue->fees.refund,
+ 1);
+ }
+ break;
+ }
+
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ {
+ const struct TALER_Amount *amount_with_fee;
+
+ amount_with_fee = &tl->details.reserve_open->coin_contribution;
TALER_ARL_amount_add (&expenditures,
&expenditures,
amount_with_fee);
- break;
- }
+ break;
+ }
+ } /* switch (tl->type) */
} /* for 'tl' */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -574,14 +645,15 @@ check_transaction_history_for_deposit (
"Aggregation loss due to refunds is %s\n",
TALER_amount2s (&merchant_loss));
*deposit_gain = *merchant_gain;
- if ( (refund_deposit_fee) &&
- (NULL != deposit_fee) )
+ if ( (NULL != deposited) &&
+ (NULL != deposit_fee) &&
+ (0 == TALER_amount_cmp (&refunds,
+ deposited)) )
{
- /* We had a /deposit operation AND a /refund operation,
- and should thus not charge the merchant the /deposit fee */
- /* FIXME: this is wrong, the merchant never pays either
- fee, the deposit fee is simply not charged to the coin
- IF there is a full refund. */
+ /* We had a /deposit operation AND /refund operations adding up to the
+ total deposited value including deposit fee. Thus, we should not
+ subtract the /deposit fee from the merchant gain (as it was also
+ refunded). */
TALER_ARL_amount_add (merchant_gain,
merchant_gain,
deposit_fee);
@@ -699,6 +771,7 @@ wire_transfer_information_cb (
struct TALER_CoinPublicInfo coin;
enum GNUNET_DB_QueryStatus qs;
struct TALER_PaytoHashP hpt;
+ uint64_t etag_out;
TALER_payto_hash (account_pay_uri,
&hpt);
@@ -711,10 +784,23 @@ wire_transfer_information_cb (
"h-payto does not match payto URI");
}
/* Obtain coin's transaction history */
- qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
- coin_pub,
- GNUNET_YES,
- &tl);
+ /* TODO: could use 'start' mechanism to only fetch transactions
+ we did not yet process, instead of going over them
+ again and again.*/
+
+ {
+ struct TALER_Amount balance;
+ struct TALER_DenominationHashP h_denom_pub;
+
+ qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
+ coin_pub,
+ 0,
+ 0,
+ &etag_out,
+ &balance,
+ &h_denom_pub,
+ &tl);
+ }
if ( (qs < 0) ||
(NULL == tl) )
{
@@ -1013,8 +1099,9 @@ check_wire_out_cb (void *cls,
char *method;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppa.last_wire_out_serial_id);
- ppa.last_wire_out_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id));
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id) = rowid + 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Checking wire transfer %s over %s performed on %s\n",
@@ -1101,8 +1188,8 @@ check_wire_out_cb (void *cls,
&wcc.total_deposits,
&final_amount);
/* Sum up aggregation fees (we simply include the rounding gains) */
- TALER_ARL_amount_add (&total_aggregation_fee_income,
- &total_aggregation_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue),
+ &TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue),
&exchange_gain);
/* Check that calculated amount matches actual amount */
@@ -1174,9 +1261,10 @@ analyze_aggregations (void *cls)
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing aggregations\n");
- qsp = TALER_ARL_adb->get_auditor_progress_aggregation (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ qsp = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -1189,18 +1277,19 @@ analyze_aggregations (void *cls)
}
else
{
- ppa_start = ppa;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming aggregation audit at %llu\n",
- (unsigned long long) ppa.last_wire_out_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ aggregation_last_wire_out_serial_id));
}
memset (&ac,
0,
sizeof (ac));
- qsx = TALER_ARL_adb->get_wire_fee_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
if (0 > qsx)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@@ -1209,7 +1298,7 @@ analyze_aggregations (void *cls)
ac.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
qs = TALER_ARL_edb->select_wire_out_above_serial_id (
TALER_ARL_edb->cls,
- ppa.last_wire_out_serial_id,
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id),
&check_wire_out_cb,
&ac);
if (0 > qs)
@@ -1235,30 +1324,30 @@ analyze_aggregations (void *cls)
return ac.qs;
}
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
- ac.qs = TALER_ARL_adb->insert_wire_fee_summary (
+ ac.qs = TALER_ARL_adb->insert_balance (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ TALER_ARL_SET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
else
- ac.qs = TALER_ARL_adb->update_wire_fee_summary (
+ ac.qs = TALER_ARL_adb->update_balance (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_aggregation_fee_income);
+ TALER_ARL_SET_AB (aggregation_total_wire_fee_revenue),
+ NULL);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ac.qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == ac.qs);
return ac.qs;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_aggregation (
+ qs = TALER_ARL_adb->update_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_auditor_progress_aggregation (
+ qs = TALER_ARL_adb->insert_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppa);
+ TALER_ARL_SET_PP (aggregation_last_wire_out_serial_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1268,7 +1357,8 @@ analyze_aggregations (void *cls)
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Concluded aggregation audit step at %llu\n",
- (unsigned long long) ppa.last_wire_out_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ aggregation_last_wire_out_serial_id));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -1303,7 +1393,8 @@ run (void *cls,
"Starting audit\n");
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_aggregation_fee_income));
+ &TALER_ARL_USE_AB (
+ aggregation_total_wire_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_wire_out_delta_plus));
@@ -1397,14 +1488,14 @@ run (void *cls,
"total_arithmetic_delta_minus",
&total_arithmetic_delta_minus),
TALER_JSON_pack_amount (
- "total_aggregation_fee_income",
- &total_aggregation_fee_income),
+ "aggregation_total_wire_fee_revenue",
+ &TALER_ARL_USE_AB (aggregation_total_wire_fee_revenue)),
GNUNET_JSON_pack_uint64 (
"start_ppa_wire_out_serial_id",
- ppa_start.last_wire_out_serial_id),
+ 0 /* defunct */),
GNUNET_JSON_pack_uint64 (
"end_ppa_wire_out_serial_id",
- ppa.last_wire_out_serial_id),
+ TALER_ARL_USE_PP (aggregation_last_wire_out_serial_id)),
/* block #4 */
TALER_JSON_pack_time_abs_human (
"auditor_start_time",
@@ -1434,11 +1525,10 @@ main (int argc,
"internal",
"perform checks only applicable for exchange-internal audits",
&internal_checks),
- GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &TALER_ARL_master_pub),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_OPTION_END
diff --git a/src/auditor/taler-helper-auditor-coins.c b/src/auditor/taler-helper-auditor-coins.c
index 20c9b2ed1..f88f39eaf 100644
--- a/src/auditor/taler-helper-auditor-coins.c
+++ b/src/auditor/taler-helper-auditor-coins.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2022 Taler Systems SA
+ Copyright (C) 2016-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero Public License as published by the Free Software
@@ -45,14 +45,37 @@
static int global_ret;
/**
- * Checkpointing our progress for coins.
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
*/
-static struct TALER_AUDITORDB_ProgressPointCoin ppc;
+static int test_mode;
/**
* Checkpointing our progress for coins.
*/
-static struct TALER_AUDITORDB_ProgressPointCoin ppc_start;
+static TALER_ARL_DEF_PP (coins_withdraw_serial_id);
+static TALER_ARL_DEF_PP (coins_deposit_serial_id);
+static TALER_ARL_DEF_PP (coins_melt_serial_id);
+static TALER_ARL_DEF_PP (coins_refund_serial_id);
+static TALER_ARL_DEF_PP (coins_recoup_serial_id);
+static TALER_ARL_DEF_PP (coins_recoup_refresh_serial_id);
+static TALER_ARL_DEF_PP (coins_purse_deposits_serial_id);
+static TALER_ARL_DEF_PP (coins_purse_refunds_serial_id);
+
+
+/**
+ * Global coin balance sheet (for coins).
+ */
+static TALER_ARL_DEF_AB (coin_balance_risk);
+static TALER_ARL_DEF_AB (total_escrowed);
+static TALER_ARL_DEF_AB (coin_irregular_loss);
+static TALER_ARL_DEF_AB (coin_melt_fee_revenue);
+static TALER_ARL_DEF_AB (coin_deposit_fee_revenue);
+static TALER_ARL_DEF_AB (coin_refund_fee_revenue);
+static TALER_ARL_DEF_AB (total_recoup_loss);
+
/**
* Array of reports about denomination keys with an
@@ -67,7 +90,7 @@ static json_t *report_emergencies;
static json_t *report_emergencies_by_count;
/**
- * Array of reports about row inconsitencies.
+ * Array of reports about row inconsistencies.
*/
static json_t *report_row_inconsistencies;
@@ -112,40 +135,6 @@ static struct TALER_Amount reported_emergency_loss;
*/
static struct TALER_Amount reported_emergency_loss_by_count;
-/**
- * Expected balance in the escrow account.
- */
-static struct TALER_Amount total_escrow_balance;
-
-/**
- * Active risk exposure.
- */
-static struct TALER_Amount total_risk;
-
-/**
- * Actualized risk (= loss) from recoups.
- */
-static struct TALER_Amount total_recoup_loss;
-
-/**
- * Recoups we made on denominations that were not revoked (!?).
- */
-static struct TALER_Amount total_irregular_recoups;
-
-/**
- * Total deposit fees earned.
- */
-static struct TALER_Amount total_deposit_fee_income;
-
-/**
- * Total melt fees earned.
- */
-static struct TALER_Amount total_melt_fee_income;
-
-/**
- * Total refund fees earned.
- */
-static struct TALER_Amount total_refund_fee_income;
/**
* Array of reports about coin operations with bad signatures.
@@ -153,15 +142,10 @@ static struct TALER_Amount total_refund_fee_income;
static json_t *report_bad_sig_losses;
/**
- * Total amount lost by operations for which signatures were invalid.
- */
-static struct TALER_Amount total_bad_sig_loss;
-
-/**
* Array of refresh transactions where the /refresh/reveal has not yet
* happened (and may of course never happen).
*/
-static json_t *report_refreshs_hanging;
+static json_t *report_refreshes_hanging;
/**
* Total amount lost by operations for which signatures were invalid.
@@ -207,9 +191,9 @@ coin_history_index (const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
uint32_t i;
- memcpy (&i,
- coin_pub,
- sizeof (i));
+ GNUNET_memcpy (&i,
+ coin_pub,
+ sizeof (i));
return i % MAX_COIN_HISTORIES;
}
@@ -470,11 +454,24 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct TALER_Amount refunded;
struct TALER_Amount deposit_fee;
bool have_refund;
+ uint64_t etag_out;
- qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
- coin_pub,
- true,
- &tl);
+ /* TODO: could use 'etag' mechanism to only fetch transactions
+ we did not yet process, instead of going over them
+ again and again. */
+ {
+ struct TALER_Amount balance;
+ struct TALER_DenominationHashP h_denom_pub;
+
+ qs = TALER_ARL_edb->get_coin_transactions (TALER_ARL_edb->cls,
+ coin_pub,
+ 0,
+ 0,
+ &etag_out,
+ &balance,
+ &h_denom_pub,
+ &tl);
+ }
if (0 >= qs)
return qs;
GNUNET_assert (GNUNET_OK ==
@@ -540,8 +537,22 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub,
&spent,
&pos->details.purse_deposit->amount);
break;
- }
- }
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ TALER_ARL_amount_add (&refunded,
+ &refunded,
+ &tl->details.purse_refund->refund_amount);
+ TALER_ARL_amount_add (&spent,
+ &spent,
+ &pos->details.purse_refund->refund_fee);
+ have_refund = true;
+ break;
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ TALER_ARL_amount_add (&spent,
+ &spent,
+ &tl->details.reserve_open->coin_contribution);
+ break;
+ } /* switch (pos->type) */
+ } /* for (...) */
if (have_refund)
{
@@ -592,33 +603,9 @@ check_coin_history (const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct DenominationSummary
{
/**
- * Total value of outstanding (not deposited) coins issued with this
- * denomination key.
- */
- struct TALER_Amount denom_balance;
-
- /**
- * Total losses made (once coins deposited exceed
- * coins withdrawn and thus the @e denom_balance is
- * effectively negative).
+ * Information about the circulation.
*/
- struct TALER_Amount denom_loss;
-
- /**
- * Total value of coins issued with this denomination key.
- */
- struct TALER_Amount denom_risk;
-
- /**
- * Total value of coins subjected to recoup with this denomination key.
- */
- struct TALER_Amount denom_recoup;
-
- /**
- * How many coins (not their amount!) of this denomination
- * did the exchange issue overall?
- */
- uint64_t num_issued;
+ struct TALER_AUDITORDB_DenominationCirculationData dcd;
/**
* Denomination key information for this denomination.
@@ -681,11 +668,7 @@ init_denomination (const struct TALER_DenominationHashP *denom_hash,
qs = TALER_ARL_adb->get_denomination_balance (TALER_ARL_adb->cls,
denom_hash,
- &ds->denom_balance,
- &ds->denom_loss,
- &ds->denom_risk,
- &ds->denom_recoup,
- &ds->num_issued);
+ &ds->dcd);
if (0 > qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -699,22 +682,22 @@ init_denomination (const struct TALER_DenominationHashP *denom_hash,
{
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &ds->denom_balance));
+ &ds->dcd.denom_balance));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &ds->denom_loss));
+ &ds->dcd.denom_loss));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &ds->denom_risk));
+ &ds->dcd.denom_risk));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &ds->denom_recoup));
+ &ds->dcd.recoup_loss));
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting balance for denomination `%s' is %s (%llu)\n",
GNUNET_h2s (&denom_hash->hash),
- TALER_amount2s (&ds->denom_balance),
- (unsigned long long) ds->num_issued);
+ TALER_amount2s (&ds->dcd.denom_balance),
+ (unsigned long long) ds->dcd.num_issued);
qs = TALER_ARL_edb->get_denomination_revocation (TALER_ARL_edb->cls,
denom_hash,
&msig,
@@ -829,15 +812,14 @@ sync_denomination (void *cls,
else
qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
- ( (0 != ds->denom_risk.value) ||
- (0 != ds->denom_risk.fraction) ) )
+ (! TALER_amount_is_zero (&ds->dcd.denom_risk)) )
{
/* The denomination expired and carried a balance; we can now
book the remaining balance as profit, and reduce our risk
exposure by the accumulated risk of the denomination. */
- TALER_ARL_amount_subtract (&total_risk,
- &total_risk,
- &ds->denom_risk);
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_balance_risk),
+ &TALER_ARL_USE_AB (coin_balance_risk),
+ &ds->dcd.denom_risk);
/* If the above fails, our risk assessment is inconsistent!
This is really, really bad (auditor-internal invariant
would be violated). Hence we can "safely" assert. If
@@ -845,22 +827,20 @@ sync_denomination (void *cls,
in the auditor _or_ the auditor's database is corrupt. */
}
if ( (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) &&
- ( (0 != ds->denom_balance.value) ||
- (0 != ds->denom_balance.fraction) ) )
+ (! TALER_amount_is_zero (&ds->dcd.denom_balance)) )
{
/* book denom_balance coin expiration profits! */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Denomination `%s' expired, booking %s in expiration profits\n",
GNUNET_h2s (denom_hash),
- TALER_amount2s (&ds->denom_balance));
+ TALER_amount2s (&ds->dcd.denom_balance));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
(qs = TALER_ARL_adb->insert_historic_denom_revenue (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
&denom_h,
expire_deposit,
- &ds->denom_balance,
- &ds->denom_recoup)))
+ &ds->dcd.denom_balance,
+ &ds->dcd.recoup_loss)))
{
/* Failed to store profits? Bad database */
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -877,8 +857,8 @@ sync_denomination (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Final balance for denomination `%s' is %s (%llu)\n",
GNUNET_h2s (denom_hash),
- TALER_amount2s (&ds->denom_balance),
- (unsigned long long) ds->num_issued);
+ TALER_amount2s (&ds->dcd.denom_balance),
+ (unsigned long long) ds->dcd.num_issued);
cnt = TALER_ARL_edb->count_known_coins (TALER_ARL_edb->cls,
&denom_h);
if (0 > cnt)
@@ -890,39 +870,31 @@ sync_denomination (void *cls,
}
else
{
- if (ds->num_issued < (uint64_t) cnt)
+ if (ds->dcd.num_issued < (uint64_t) cnt)
{
/* more coins deposited than issued! very bad */
report_emergency_by_count (issue,
- ds->num_issued,
+ ds->dcd.num_issued,
cnt,
- &ds->denom_risk);
+ &ds->dcd.denom_risk);
}
if (ds->report_emergency)
{
/* Value of coins deposited exceed value of coins
issued! Also very bad! */
report_emergency_by_amount (issue,
- &ds->denom_risk,
- &ds->denom_loss);
+ &ds->dcd.denom_risk,
+ &ds->dcd.denom_loss);
}
if (ds->in_db)
qs = TALER_ARL_adb->update_denomination_balance (TALER_ARL_adb->cls,
&denom_h,
- &ds->denom_balance,
- &ds->denom_loss,
- &ds->denom_risk,
- &ds->denom_recoup,
- ds->num_issued);
+ &ds->dcd);
else
qs = TALER_ARL_adb->insert_denomination_balance (TALER_ARL_adb->cls,
&denom_h,
- &ds->denom_balance,
- &ds->denom_loss,
- &ds->denom_risk,
- &ds->denom_recoup,
- ds->num_issued);
+ &ds->dcd);
}
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
@@ -984,8 +956,9 @@ withdraw_cb (void *cls,
(void) execution_date;
(void) amount_with_fee;
- GNUNET_assert (rowid >= ppc.last_withdraw_serial_id); /* should be monotonically increasing */
- ppc.last_withdraw_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (coins_withdraw_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_withdraw_serial_id) = rowid + 1;
qs = TALER_ARL_get_denomination_info (denom_pub,
&issue,
@@ -1019,22 +992,22 @@ withdraw_cb (void *cls,
"Issued coin in denomination `%s' of total value %s\n",
GNUNET_h2s (&dh.hash),
TALER_amount2s (&issue->value));
- ds->num_issued++;
- TALER_ARL_amount_add (&ds->denom_balance,
- &ds->denom_balance,
- &issue->value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' is %s\n",
GNUNET_h2s (&dh.hash),
- TALER_amount2s (&ds->denom_balance));
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ TALER_amount2s (&ds->dcd.denom_balance));
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
+ &TALER_ARL_USE_AB (total_escrowed),
&issue->value);
- TALER_ARL_amount_add (&total_risk,
- &total_risk,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk),
+ &TALER_ARL_USE_AB (coin_balance_risk),
&issue->value);
- TALER_ARL_amount_add (&ds->denom_risk,
- &ds->denom_risk,
+ ds->dcd.num_issued++;
+ TALER_ARL_amount_add (&ds->dcd.denom_balance,
+ &ds->dcd.denom_balance,
+ &issue->value);
+ TALER_ARL_amount_add (&ds->dcd.denom_risk,
+ &ds->dcd.denom_risk,
&issue->value);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -1188,8 +1161,8 @@ check_known_coin (
loss_potential),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
loss_potential);
}
TALER_denom_sig_free (&ci.denom_sig);
@@ -1200,7 +1173,7 @@ check_known_coin (
/**
* Update the denom balance in @a dso reducing it by
* @a amount_with_fee. If this is not possible, report
- * an emergency. Also updates the #total_escrow_balance.
+ * an emergency. Also updates the balance.
*
* @param dso denomination summary to update
* @param rowid responsible row (for logging)
@@ -1215,19 +1188,19 @@ reduce_denom_balance (struct DenominationSummary *dso,
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&tmp,
- &dso->denom_balance,
+ &dso->dcd.denom_balance,
amount_with_fee))
{
- TALER_ARL_amount_add (&dso->denom_loss,
- &dso->denom_loss,
+ TALER_ARL_amount_add (&dso->dcd.denom_loss,
+ &dso->dcd.denom_loss,
amount_with_fee);
dso->report_emergency = true;
}
else
{
- dso->denom_balance = tmp;
+ dso->dcd.denom_balance = tmp;
}
- if (-1 == TALER_amount_cmp (&total_escrow_balance,
+ if (-1 == TALER_amount_cmp (&TALER_ARL_USE_AB (total_escrowed),
amount_with_fee))
{
/* This can theoretically happen if for example the exchange
@@ -1239,20 +1212,20 @@ reduce_denom_balance (struct DenominationSummary *dso,
report_amount_arithmetic_inconsistency (
"subtracting amount from escrow balance",
rowid,
- &total_escrow_balance,
+ &TALER_ARL_USE_AB (total_escrowed),
amount_with_fee,
0);
}
else
{
- TALER_ARL_amount_subtract (&total_escrow_balance,
- &total_escrow_balance,
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (total_escrowed),
+ &TALER_ARL_USE_AB (total_escrowed),
amount_with_fee);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' is %s\n",
GNUNET_h2s (&dso->issue->denom_hash.hash),
- TALER_amount2s (&dso->denom_balance));
+ TALER_amount2s (&dso->dcd.denom_balance));
}
@@ -1292,8 +1265,9 @@ refresh_session_cb (void *cls,
enum GNUNET_DB_QueryStatus qs;
(void) noreveal_index;
- GNUNET_assert (rowid >= ppc.last_melt_serial_id); /* should be monotonically increasing */
- ppc.last_melt_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (coins_melt_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_melt_serial_id) = rowid + 1;
qs = TALER_ARL_get_denomination_info (denom_pub,
&issue,
@@ -1341,6 +1315,7 @@ refresh_session_cb (void *cls,
coin_pub,
coin_sig))
{
+ GNUNET_break_op (0);
TALER_ARL_report (report_bad_sig_losses,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("operation",
@@ -1351,8 +1326,8 @@ refresh_session_cb (void *cls,
amount_with_fee),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount_with_fee);
}
}
@@ -1385,7 +1360,7 @@ refresh_session_cb (void *cls,
/* This can legitimately happen if reveal was not yet called or only
with invalid data, even if the exchange is correctly operating. We
still report it. */
- TALER_ARL_report (report_refreshs_hanging,
+ TALER_ARL_report (report_refreshes_hanging,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_uint64 ("row",
rowid),
@@ -1452,11 +1427,12 @@ refresh_session_cb (void *cls,
&amount_without_fee));
}
- /* check old coin covers complete expenses (of withdraw operations) */
+ /* check old coin covers complete expenses (of refresh operation) */
if (1 == TALER_amount_cmp (&refresh_cost,
&amount_without_fee))
{
/* refresh_cost > amount_without_fee, which is bad (exchange lost) */
+ GNUNET_break_op (0);
report_amount_arithmetic_inconsistency ("melt (cost)",
rowid,
&amount_without_fee, /* 'exchange' */
@@ -1486,22 +1462,22 @@ refresh_session_cb (void *cls,
"Created fresh coin in denomination `%s' of value %s\n",
GNUNET_h2s (&ni->denom_hash.hash),
TALER_amount2s (&ni->value));
- dsi->num_issued++;
- TALER_ARL_amount_add (&dsi->denom_balance,
- &dsi->denom_balance,
+ dsi->dcd.num_issued++;
+ TALER_ARL_amount_add (&dsi->dcd.denom_balance,
+ &dsi->dcd.denom_balance,
&ni->value);
- TALER_ARL_amount_add (&dsi->denom_risk,
- &dsi->denom_risk,
+ TALER_ARL_amount_add (&dsi->dcd.denom_risk,
+ &dsi->dcd.denom_risk,
&ni->value);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' is %s\n",
GNUNET_h2s (&ni->denom_hash.hash),
- TALER_amount2s (&dsi->denom_balance));
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ TALER_amount2s (&dsi->dcd.denom_balance));
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
+ &TALER_ARL_USE_AB (total_escrowed),
&ni->value);
- TALER_ARL_amount_add (&total_risk,
- &total_risk,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk),
+ &TALER_ARL_USE_AB (coin_balance_risk),
&ni->value);
}
}
@@ -1526,8 +1502,8 @@ refresh_session_cb (void *cls,
}
/* update global melt fees */
- TALER_ARL_amount_add (&total_melt_fee_income,
- &total_melt_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_melt_fee_revenue),
+ &TALER_ARL_USE_AB (coin_melt_fee_revenue),
&issue->fees.refresh);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -1562,8 +1538,9 @@ deposit_cb (void *cls,
(void) done;
(void) exchange_timestamp;
- GNUNET_assert (rowid >= ppc.last_deposit_serial_id); /* should be monotonically increasing */
- ppc.last_deposit_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (coins_deposit_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_deposit_serial_id) = rowid + 1;
qs = TALER_ARL_get_denomination_info (denom_pub,
&issue,
@@ -1623,8 +1600,11 @@ deposit_cb (void *cls,
&issue->fees.deposit,
&h_wire,
&deposit->h_contract_terms,
+ deposit->no_wallet_data_hash
+ ? NULL
+ : &deposit->wallet_data_hash,
&deposit->coin.h_age_commitment,
- NULL /* FIXME: h_extensions! */,
+ &deposit->h_policy,
&h_denom_pub,
deposit->timestamp,
&deposit->merchant_pub,
@@ -1642,8 +1622,8 @@ deposit_cb (void *cls,
&deposit->amount_with_fee),
GNUNET_JSON_pack_data_auto ("coin_pub",
&deposit->coin.coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
&deposit->amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -1674,8 +1654,8 @@ deposit_cb (void *cls,
}
/* update global deposit fees */
- TALER_ARL_amount_add (&total_deposit_fee_income,
- &total_deposit_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_deposit_fee_revenue),
+ &TALER_ARL_USE_AB (coin_deposit_fee_revenue),
&issue->fees.deposit);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -1719,8 +1699,8 @@ refund_cb (void *cls,
struct TALER_Amount amount_without_fee;
enum GNUNET_DB_QueryStatus qs;
- GNUNET_assert (rowid >= ppc.last_refund_serial_id); /* should be monotonically increasing */
- ppc.last_refund_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_refund_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_refund_serial_id) = rowid + 1;
qs = TALER_ARL_get_denomination_info (denom_pub,
&issue,
@@ -1759,8 +1739,8 @@ refund_cb (void *cls,
amount_with_fee),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -1800,31 +1780,31 @@ refund_cb (void *cls,
}
else
{
- TALER_ARL_amount_add (&ds->denom_balance,
- &ds->denom_balance,
+ TALER_ARL_amount_add (&ds->dcd.denom_balance,
+ &ds->dcd.denom_balance,
&amount_without_fee);
- TALER_ARL_amount_add (&ds->denom_risk,
- &ds->denom_risk,
+ TALER_ARL_amount_add (&ds->dcd.denom_risk,
+ &ds->dcd.denom_risk,
&amount_without_fee);
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
+ &TALER_ARL_USE_AB (total_escrowed),
&amount_without_fee);
- TALER_ARL_amount_add (&total_risk,
- &total_risk,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk),
+ &TALER_ARL_USE_AB (coin_balance_risk),
&amount_without_fee);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' after refund is %s\n",
GNUNET_h2s (&issue->denom_hash.hash),
- TALER_amount2s (&ds->denom_balance));
+ TALER_amount2s (&ds->dcd.denom_balance));
}
/* update total refund fee balance */
- TALER_ARL_amount_add (&total_refund_fee_income,
- &total_refund_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_refund_fee_revenue),
+ &TALER_ARL_USE_AB (coin_refund_fee_revenue),
&issue->fees.refund);
if (full_refund)
{
- TALER_ARL_amount_subtract (&total_deposit_fee_income,
- &total_deposit_fee_income,
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_deposit_fee_revenue),
+ &TALER_ARL_USE_AB (coin_deposit_fee_revenue),
&issue->fees.deposit);
}
if (TALER_ARL_do_abort ())
@@ -1892,26 +1872,26 @@ purse_refund_coin_cb (
}
else
{
- TALER_ARL_amount_add (&ds->denom_balance,
- &ds->denom_balance,
+ TALER_ARL_amount_add (&ds->dcd.denom_balance,
+ &ds->dcd.denom_balance,
amount_with_fee);
- TALER_ARL_amount_add (&ds->denom_risk,
- &ds->denom_risk,
+ TALER_ARL_amount_add (&ds->dcd.denom_risk,
+ &ds->dcd.denom_risk,
amount_with_fee);
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_escrowed),
+ &TALER_ARL_USE_AB (total_escrowed),
amount_with_fee);
- TALER_ARL_amount_add (&total_risk,
- &total_risk,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_balance_risk),
+ &TALER_ARL_USE_AB (coin_balance_risk),
amount_with_fee);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' after purse-refund is %s\n",
GNUNET_h2s (&issue->denom_hash.hash),
- TALER_amount2s (&ds->denom_balance));
+ TALER_amount2s (&ds->dcd.denom_balance));
}
/* update total deposit fee balance */
- TALER_ARL_amount_subtract (&total_deposit_fee_income,
- &total_deposit_fee_income,
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (coin_deposit_fee_revenue),
+ &TALER_ARL_USE_AB (coin_deposit_fee_revenue),
&issue->fees.deposit);
return GNUNET_OK;
@@ -1926,18 +1906,25 @@ purse_refund_coin_cb (
* @param cls closure
* @param rowid unique serial ID for the refund in our DB
* @param purse_pub public key of the purse
+ * @param reserve_pub public key of the targeted reserve (ignored)
+ * @param val targeted amount to be in the reserve (ignored)
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
static enum GNUNET_GenericReturnValue
purse_refund_cb (void *cls,
uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub)
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *val)
{
struct CoinContext *cc = cls;
enum GNUNET_DB_QueryStatus qs;
- GNUNET_assert (rowid >= ppc.last_purse_refunds_serial_id); /* should be monotonically increasing */
- ppc.last_purse_refunds_serial_id = rowid + 1;
+ (void) val; /* irrelevant on refund */
+ (void) reserve_pub; /* irrelevant, may even be NULL */
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (coins_purse_refunds_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_purse_refunds_serial_id) = rowid + 1;
qs = TALER_ARL_edb->select_purse_deposits_by_purse (TALER_ARL_edb->cls,
purse_pub,
&purse_refund_coin_cb,
@@ -1975,13 +1962,23 @@ check_recoup (struct CoinContext *cc,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind)
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind)
{
struct DenominationSummary *ds;
enum GNUNET_DB_QueryStatus qs;
const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
if (GNUNET_OK !=
+ TALER_wallet_recoup_verify (&coin->denom_pub_hash,
+ coin_blind,
+ &coin->coin_pub,
+ coin_sig))
+ {
+ report_row_inconsistency (operation,
+ rowid,
+ "recoup signature invalid");
+ }
+ if (GNUNET_OK !=
TALER_test_coin_valid (coin,
denom_pub))
{
@@ -1995,8 +1992,8 @@ check_recoup (struct CoinContext *cc,
amount),
GNUNET_JSON_pack_data_auto ("coin_pub",
&coin->denom_pub_hash)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount);
}
qs = TALER_ARL_get_denomination_info_by_hash (&coin->denom_pub_hash,
@@ -2056,15 +2053,15 @@ check_recoup (struct CoinContext *cc,
amount),
GNUNET_JSON_pack_data_auto ("coin_pub",
&coin->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount);
}
- TALER_ARL_amount_add (&ds->denom_recoup,
- &ds->denom_recoup,
+ TALER_ARL_amount_add (&ds->dcd.recoup_loss,
+ &ds->dcd.recoup_loss,
amount);
- TALER_ARL_amount_add (&total_recoup_loss,
- &total_recoup_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_recoup_loss),
+ &TALER_ARL_USE_AB (total_recoup_loss),
amount);
}
if (TALER_ARL_do_abort ())
@@ -2096,12 +2093,12 @@ recoup_cb (void *cls,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind)
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind)
{
struct CoinContext *cc = cls;
- GNUNET_assert (rowid >= ppc.last_recoup_serial_id); /* should be monotonically increasing */
- ppc.last_recoup_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_recoup_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_recoup_serial_id) = rowid + 1;
(void) timestamp;
(void) reserve_pub;
if (GNUNET_OK !=
@@ -2120,8 +2117,8 @@ recoup_cb (void *cls,
amount),
GNUNET_JSON_pack_data_auto ("coin_pub",
&coin->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -2164,7 +2161,7 @@ recoup_refresh_cb (void *cls,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind)
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind)
{
struct CoinContext *cc = cls;
const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
@@ -2172,8 +2169,8 @@ recoup_refresh_cb (void *cls,
(void) timestamp;
(void) old_coin_pub;
- GNUNET_assert (rowid >= ppc.last_recoup_refresh_serial_id); /* should be monotonically increasing */
- ppc.last_recoup_refresh_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (coins_recoup_refresh_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (coins_recoup_refresh_serial_id) = rowid + 1;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Recoup-refresh amount is %s\n",
TALER_amount2s (amount));
@@ -2208,13 +2205,13 @@ recoup_refresh_cb (void *cls,
}
else
{
- TALER_ARL_amount_add (&dso->denom_balance,
- &dso->denom_balance,
+ TALER_ARL_amount_add (&dso->dcd.denom_balance,
+ &dso->dcd.denom_balance,
amount);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New balance of denomination `%s' after refresh-recoup is %s\n",
GNUNET_h2s (&issue->denom_hash.hash),
- TALER_amount2s (&dso->denom_balance));
+ TALER_amount2s (&dso->dcd.denom_balance));
}
}
@@ -2234,8 +2231,8 @@ recoup_refresh_cb (void *cls,
amount),
GNUNET_JSON_pack_data_auto ("coin_pub",
&coin->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
amount);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -2358,8 +2355,9 @@ purse_deposit_cb (
(void) auditor_balance;
(void) purse_total;
(void) reserve_pub;
- GNUNET_assert (rowid >= ppc.last_purse_deposits_serial_id);
- ppc.last_purse_deposits_serial_id = rowid + 1;
+ GNUNET_assert (rowid >=
+ TALER_ARL_USE_PP (coins_purse_deposits_serial_id));
+ TALER_ARL_USE_PP (coins_purse_deposits_serial_id) = rowid + 1;
qs = TALER_ARL_get_denomination_info (denom_pub,
&issue,
&dh);
@@ -2407,8 +2405,8 @@ purse_deposit_cb (
&deposit->amount),
GNUNET_JSON_pack_data_auto ("coin_pub",
&deposit->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_irregular_loss),
+ &TALER_ARL_USE_AB (coin_irregular_loss),
&deposit->amount);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -2433,8 +2431,8 @@ purse_deposit_cb (
}
/* update global deposit fees */
- TALER_ARL_amount_add (&total_deposit_fee_income,
- &total_deposit_fee_income,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (coin_deposit_fee_revenue),
+ &TALER_ARL_USE_AB (coin_deposit_fee_revenue),
&issue->fees.deposit);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
@@ -2469,9 +2467,17 @@ analyze_coins (void *cls)
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing coins\n");
- qsp = TALER_ARL_adb->get_auditor_progress_coin (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppc);
+ qsp = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (coins_withdraw_serial_id),
+ TALER_ARL_GET_PP (coins_deposit_serial_id),
+ TALER_ARL_GET_PP (coins_melt_serial_id),
+ TALER_ARL_GET_PP (coins_refund_serial_id),
+ TALER_ARL_GET_PP (coins_recoup_serial_id),
+ TALER_ARL_GET_PP (coins_recoup_refresh_serial_id),
+ TALER_ARL_GET_PP (coins_purse_deposits_serial_id),
+ TALER_ARL_GET_PP (coins_purse_refunds_serial_id),
+ NULL);
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -2484,30 +2490,39 @@ analyze_coins (void *cls)
}
else
{
- ppc_start = ppc;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resuming coin audit at %llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppc.last_deposit_serial_id,
- (unsigned long long) ppc.last_melt_serial_id,
- (unsigned long long) ppc.last_refund_serial_id,
- (unsigned long long) ppc.last_withdraw_serial_id,
- (unsigned long long) ppc.last_recoup_refresh_serial_id,
- (unsigned long long) ppc.last_purse_deposits_serial_id);
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_INFO,
+ "Resuming coin audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_deposit_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_melt_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_refund_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_withdraw_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_recoup_refresh_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_purse_deposits_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_purse_refunds_serial_id));
}
/* setup 'cc' */
cc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
cc.denom_summaries = GNUNET_CONTAINER_multihashmap_create (256,
GNUNET_NO);
- qsx = TALER_ARL_adb->get_balance_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_deposit_fee_income,
- &total_melt_fee_income,
- &total_refund_fee_income,
- &total_risk,
- &total_recoup_loss,
- &total_irregular_recoups);
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (coin_balance_risk),
+ TALER_ARL_GET_AB (total_escrowed),
+ TALER_ARL_GET_AB (coin_irregular_loss),
+ TALER_ARL_GET_AB (coin_melt_fee_revenue),
+ TALER_ARL_GET_AB (coin_deposit_fee_revenue),
+ TALER_ARL_GET_AB (coin_refund_fee_revenue),
+ TALER_ARL_GET_AB (total_recoup_loss),
+ NULL);
if (0 > qsx)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@@ -2518,7 +2533,7 @@ analyze_coins (void *cls)
if (0 >
(qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_withdraw_serial_id,
+ TALER_ARL_USE_PP (coins_withdraw_serial_id),
&withdraw_cb,
&cc)) )
{
@@ -2532,7 +2547,7 @@ analyze_coins (void *cls)
if (0 >
(qs = TALER_ARL_edb->select_refunds_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_refund_serial_id,
+ TALER_ARL_USE_PP (coins_refund_serial_id),
&refund_cb,
&cc)))
{
@@ -2544,9 +2559,10 @@ analyze_coins (void *cls)
/* process purse_refunds */
if (0 >
- (qs = TALER_ARL_edb->select_purse_refunds_above_serial_id (
+ (qs = TALER_ARL_edb->select_purse_decisions_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_purse_refunds_serial_id,
+ TALER_ARL_USE_PP (coins_purse_refunds_serial_id),
+ true, /* only go for refunds! */
&purse_refund_cb,
&cc)))
{
@@ -2560,7 +2576,7 @@ analyze_coins (void *cls)
if (0 >
(qs = TALER_ARL_edb->select_recoup_refresh_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_recoup_refresh_serial_id,
+ TALER_ARL_USE_PP (coins_recoup_refresh_serial_id),
&recoup_refresh_cb,
&cc)))
{
@@ -2572,7 +2588,7 @@ analyze_coins (void *cls)
if (0 >
(qs = TALER_ARL_edb->select_recoup_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_recoup_serial_id,
+ TALER_ARL_USE_PP (coins_recoup_serial_id),
&recoup_cb,
&cc)))
{
@@ -2582,11 +2598,11 @@ analyze_coins (void *cls)
if (0 > cc.qs)
return cc.qs;
- /* process refreshs */
+ /* process refreshes */
if (0 >
(qs = TALER_ARL_edb->select_refreshes_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_melt_serial_id,
+ TALER_ARL_USE_PP (coins_melt_serial_id),
&refresh_session_cb,
&cc)))
{
@@ -2598,9 +2614,9 @@ analyze_coins (void *cls)
/* process deposits */
if (0 >
- (qs = TALER_ARL_edb->select_deposits_above_serial_id (
+ (qs = TALER_ARL_edb->select_coin_deposits_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_deposit_serial_id,
+ TALER_ARL_USE_PP (coins_deposit_serial_id),
&deposit_cb,
&cc)))
{
@@ -2614,7 +2630,7 @@ analyze_coins (void *cls)
if (0 >
(qs = TALER_ARL_edb->select_purse_deposits_above_serial_id (
TALER_ARL_edb->cls,
- ppc.last_purse_deposits_serial_id,
+ TALER_ARL_USE_PP (coins_purse_deposits_serial_id),
&purse_deposit_cb,
&cc)))
{
@@ -2636,25 +2652,27 @@ analyze_coins (void *cls)
return cc.qs;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx)
- qs = TALER_ARL_adb->update_balance_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_deposit_fee_income,
- &total_melt_fee_income,
- &total_refund_fee_income,
- &total_risk,
- &total_recoup_loss,
- &total_irregular_recoups);
+ qs = TALER_ARL_adb->update_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (coin_balance_risk),
+ TALER_ARL_SET_AB (total_escrowed),
+ TALER_ARL_SET_AB (coin_irregular_loss),
+ TALER_ARL_SET_AB (coin_melt_fee_revenue),
+ TALER_ARL_SET_AB (coin_deposit_fee_revenue),
+ TALER_ARL_SET_AB (coin_refund_fee_revenue),
+ TALER_ARL_SET_AB (total_recoup_loss),
+ NULL);
else
- qs = TALER_ARL_adb->insert_balance_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_deposit_fee_income,
- &total_melt_fee_income,
- &total_refund_fee_income,
- &total_risk,
- &total_recoup_loss,
- &total_irregular_recoups);
+ qs = TALER_ARL_adb->insert_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (coin_balance_risk),
+ TALER_ARL_SET_AB (total_escrowed),
+ TALER_ARL_SET_AB (coin_irregular_loss),
+ TALER_ARL_SET_AB (coin_melt_fee_revenue),
+ TALER_ARL_SET_AB (coin_deposit_fee_revenue),
+ TALER_ARL_SET_AB (coin_refund_fee_revenue),
+ TALER_ARL_SET_AB (total_recoup_loss),
+ NULL);
if (0 >= qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -2662,13 +2680,29 @@ analyze_coins (void *cls)
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_coin (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppc);
+ qs = TALER_ARL_adb->update_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (coins_withdraw_serial_id),
+ TALER_ARL_SET_PP (coins_deposit_serial_id),
+ TALER_ARL_SET_PP (coins_melt_serial_id),
+ TALER_ARL_SET_PP (coins_refund_serial_id),
+ TALER_ARL_SET_PP (coins_recoup_serial_id),
+ TALER_ARL_SET_PP (coins_recoup_refresh_serial_id),
+ TALER_ARL_SET_PP (coins_purse_deposits_serial_id),
+ TALER_ARL_SET_PP (coins_purse_refunds_serial_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_auditor_progress_coin (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppc);
+ qs = TALER_ARL_adb->insert_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (coins_withdraw_serial_id),
+ TALER_ARL_SET_PP (coins_deposit_serial_id),
+ TALER_ARL_SET_PP (coins_melt_serial_id),
+ TALER_ARL_SET_PP (coins_refund_serial_id),
+ TALER_ARL_SET_PP (coins_recoup_serial_id),
+ TALER_ARL_SET_PP (coins_recoup_refresh_serial_id),
+ TALER_ARL_SET_PP (coins_purse_deposits_serial_id),
+ TALER_ARL_SET_PP (coins_purse_refunds_serial_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -2677,13 +2711,17 @@ analyze_coins (void *cls)
return qs;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Concluded coin audit step at %llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppc.last_deposit_serial_id,
- (unsigned long long) ppc.last_melt_serial_id,
- (unsigned long long) ppc.last_refund_serial_id,
- (unsigned long long) ppc.last_withdraw_serial_id,
- (unsigned long long) ppc.last_recoup_refresh_serial_id,
- (unsigned long long) ppc.last_purse_deposits_serial_id);
+ "Concluded coin audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (coins_deposit_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (coins_melt_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (coins_refund_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (coins_withdraw_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_recoup_refresh_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_purse_deposits_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ coins_purse_refunds_serial_id));
return qs;
}
@@ -2729,25 +2767,29 @@ run (void *cls,
&reported_emergency_loss_by_count));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_escrow_balance));
+ &TALER_ARL_USE_AB (total_escrowed)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_risk));
+ &TALER_ARL_USE_AB (
+ coin_deposit_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_recoup_loss));
+ &TALER_ARL_USE_AB (
+ coin_melt_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_irregular_recoups));
+ &TALER_ARL_USE_AB (
+ coin_refund_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_deposit_fee_income));
+ &TALER_ARL_USE_AB (coin_balance_risk)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_melt_fee_income));
+ &TALER_ARL_USE_AB (total_recoup_loss)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_refund_fee_income));
+ &TALER_ARL_USE_AB (
+ coin_irregular_loss)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_arithmetic_delta_plus));
@@ -2756,9 +2798,6 @@ run (void *cls,
&total_arithmetic_delta_minus));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_bad_sig_loss));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (TALER_ARL_currency,
&total_refresh_hanging));
GNUNET_assert (NULL !=
(report_emergencies = json_array ()));
@@ -2774,7 +2813,7 @@ run (void *cls,
GNUNET_assert (NULL !=
(report_bad_sig_losses = json_array ()));
GNUNET_assert (NULL !=
- (report_refreshs_hanging = json_array ()));
+ (report_refreshes_hanging = json_array ()));
if (GNUNET_OK !=
TALER_ARL_setup_sessions_and_run (&analyze_coins,
NULL))
@@ -2787,27 +2826,26 @@ run (void *cls,
TALER_ARL_done (
GNUNET_JSON_PACK (
TALER_JSON_pack_amount ("total_escrow_balance",
- &total_escrow_balance),
- TALER_JSON_pack_amount ("total_active_risk",
- &total_risk),
+ &TALER_ARL_USE_AB (total_escrowed)),
TALER_JSON_pack_amount ("total_deposit_fee_income",
- &total_deposit_fee_income),
+ &TALER_ARL_USE_AB (coin_deposit_fee_revenue)),
TALER_JSON_pack_amount ("total_melt_fee_income",
- &total_melt_fee_income),
+ &TALER_ARL_USE_AB (coin_melt_fee_revenue)),
TALER_JSON_pack_amount ("total_refund_fee_income",
- &total_refund_fee_income),
+ &TALER_ARL_USE_AB (coin_refund_fee_revenue)),
+ TALER_JSON_pack_amount ("total_active_risk",
+ &TALER_ARL_USE_AB (coin_balance_risk)),
+ TALER_JSON_pack_amount ("total_recoup_loss",
+ &TALER_ARL_USE_AB (total_recoup_loss)),
+ /* Tested in test-auditor.sh #4/#5/#6/#13/#26 */
+ TALER_JSON_pack_amount ("irregular_loss",
+ &TALER_ARL_USE_AB (coin_irregular_loss)),
/* Tested in test-auditor.sh #18 */
GNUNET_JSON_pack_array_steal ("emergencies",
report_emergencies),
/* Tested in test-auditor.sh #18 */
TALER_JSON_pack_amount ("emergencies_risk_by_amount",
&reported_emergency_risk_by_amount),
- /* Tested in test-auditor.sh #4/#5/#6/#13/#26 */
- GNUNET_JSON_pack_array_steal ("bad_sig_losses",
- report_bad_sig_losses),
- /* Tested in test-auditor.sh #4/#5/#6/#13/#26 */
- TALER_JSON_pack_amount ("total_bad_sig_loss",
- &total_bad_sig_loss),
/* Tested in test-auditor.sh #31 */
GNUNET_JSON_pack_array_steal ("row_inconsistencies",
report_row_inconsistencies),
@@ -2820,11 +2858,11 @@ run (void *cls,
&total_arithmetic_delta_minus),
TALER_JSON_pack_amount ("total_refresh_hanging",
&total_refresh_hanging),
+ GNUNET_JSON_pack_array_steal ("bad_sig_losses",
+ report_bad_sig_losses),
/* Tested in test-auditor.sh #12 */
GNUNET_JSON_pack_array_steal ("refresh_hanging",
- report_refreshs_hanging),
- TALER_JSON_pack_amount ("total_recoup_loss",
- &total_recoup_loss),
+ report_refreshes_hanging),
/* Tested in test-auditor.sh #18 */
GNUNET_JSON_pack_array_steal ("emergencies_by_count",
report_emergencies_by_count),
@@ -2838,45 +2876,48 @@ run (void *cls,
TALER_JSON_pack_amount ("emergencies_loss_by_count",
&reported_emergency_loss_by_count),
GNUNET_JSON_pack_uint64 ("start_ppc_withdraw_serial_id",
- ppc_start.last_withdraw_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_deposit_serial_id",
- ppc_start.last_deposit_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_melt_serial_id",
- ppc_start.last_melt_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_refund_serial_id",
- ppc_start.last_refund_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_recoup_serial_id",
- ppc_start.last_recoup_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_recoup_refresh_serial_id",
- ppc_start.last_recoup_refresh_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_purse_deposits_serial_id",
- ppc_start.last_purse_deposits_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("start_ppc_purse_refunds_serial_id",
- ppc_start.last_purse_refunds_serial_id),
+ 0 /* not implemented */),
GNUNET_JSON_pack_uint64 ("end_ppc_withdraw_serial_id",
- ppc.last_withdraw_serial_id),
+ TALER_ARL_USE_PP (coins_withdraw_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_deposit_serial_id",
- ppc.last_deposit_serial_id),
+ TALER_ARL_USE_PP (coins_deposit_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_melt_serial_id",
- ppc.last_melt_serial_id),
+ TALER_ARL_USE_PP (coins_melt_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_refund_serial_id",
- ppc.last_refund_serial_id),
+ TALER_ARL_USE_PP (coins_refund_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_recoup_serial_id",
- ppc.last_recoup_serial_id),
+ TALER_ARL_USE_PP (coins_recoup_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_recoup_refresh_serial_id",
- ppc.last_recoup_refresh_serial_id),
+ TALER_ARL_USE_PP (
+ coins_recoup_refresh_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_purse_deposits_serial_id",
- ppc.last_purse_deposits_serial_id),
+ TALER_ARL_USE_PP (
+ coins_purse_deposits_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppc_purse_refunds_serial_id",
- ppc.last_purse_refunds_serial_id),
- TALER_JSON_pack_time_abs_human ("auditor_start_time",
- start_time),
+ TALER_ARL_USE_PP (
+ coins_purse_refunds_serial_id)),
+ TALER_JSON_pack_time_abs_human (
+ "auditor_start_time",
+ start_time),
TALER_JSON_pack_time_abs_human ("auditor_end_time",
GNUNET_TIME_absolute_get ()),
- TALER_JSON_pack_amount ("total_irregular_recoups",
- &total_irregular_recoups),
- GNUNET_JSON_pack_array_steal ("unsigned_denominations",
- report_denominations_without_sigs)));
+ GNUNET_JSON_pack_array_steal (
+ "unsigned_denominations",
+ report_denominations_without_sigs)));
}
@@ -2896,11 +2937,10 @@ main (int argc,
"internal",
"perform checks only applicable for exchange-internal audits",
&internal_checks),
- GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &TALER_ARL_master_pub),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_OPTION_END
diff --git a/src/auditor/taler-helper-auditor-deposits.c b/src/auditor/taler-helper-auditor-deposits.c
index 2499df2eb..3dbce0183 100644
--- a/src/auditor/taler-helper-auditor-deposits.c
+++ b/src/auditor/taler-helper-auditor-deposits.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2021 Taler Systems SA
+ Copyright (C) 2016-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero Public License as published by the Free Software
@@ -17,6 +17,7 @@
* @file auditor/taler-helper-auditor-deposits.c
* @brief audits an exchange database for deposit confirmation consistency
* @author Christian Grothoff
+ * @author Nic Eigel
*
* We simply check that all of the deposit confirmations reported to us
* by merchants were also reported to us by the exchange.
@@ -29,7 +30,29 @@
#include "taler_bank_service.h"
#include "taler_signatures.h"
#include "report-lib.h"
+#include "taler_dbevents.h"
+#include <jansson.h>
+/*
+--
+-- SELECT serial_id,h_contract_terms,h_wire,merchant_pub ...
+-- FROM auditor.auditor_deposit_confirmations
+-- WHERE NOT ancient
+-- ORDER BY exchange_timestamp ASC;
+-- SELECT 1
+- FROM exchange.deposits dep
+ WHERE ($RESULT.contract_terms = dep.h_contract_terms) AND ($RESULT.h_wire = dep.h_wire) AND ...);
+-- IF FOUND
+-- DELETE FROM auditor.auditor_deposit_confirmations
+-- WHERE serial_id = $RESULT.serial_id;
+-- SELECT exchange_timestamp AS latest
+-- FROM exchange.deposits ORDER BY exchange_timestamp DESC;
+-- latest -= 1 hour; // time is not exactly monotonic...
+-- UPDATE auditor.deposit_confirmations
+-- SET ancient=TRUE
+-- WHERE exchange_timestamp < latest
+-- AND NOT ancient;
+*/
/**
* Return value from main().
@@ -37,6 +60,14 @@
static int global_ret;
/**
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
+ */
+static int test_mode;
+
+/**
* Array of reports about missing deposit confirmations.
*/
static json_t *report_deposit_confirmation_inconsistencies;
@@ -56,6 +87,18 @@ static struct TALER_Amount total_missed_deposit_confirmations;
*/
static int internal_checks;
+static struct GNUNET_DB_EventHandler *eh;
+
+/**
+ * Our database plugin.
+ */
+static struct TALER_AUDITORDB_Plugin *db_plugin;
+
+/**
+ * The auditors's configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Closure for #test_dc.
*/
@@ -92,7 +135,6 @@ struct DepositConfirmationContext
};
-
/**
* Given a deposit confirmation from #TALER_ARL_adb, check that it is also
* in #TALER_ARL_edb. Update the deposit confirmation context accordingly.
@@ -102,14 +144,16 @@ struct DepositConfirmationContext
* @param dc the deposit confirmation we know
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop iterating
*/
-static int
+static enum GNUNET_GenericReturnValue
test_dc (void *cls,
uint64_t serial_id,
const struct TALER_AUDITORDB_DepositConfirmation *dc)
{
struct DepositConfirmationContext *dcc = cls;
+ bool missing = false;
dcc->last_seen_coin_serial = serial_id;
+ for (unsigned int i = 0; i < dc->num_coins; i++)
{
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_TIME_Timestamp exchange_timestamp;
@@ -118,20 +162,12 @@ test_dc (void *cls,
qs = TALER_ARL_edb->have_deposit2 (TALER_ARL_edb->cls,
&dc->h_contract_terms,
&dc->h_wire,
- &dc->coin_pub,
+ &dc->coin_pubs[i],
&dc->merchant,
dc->refund_deadline,
&deposit_fee,
&exchange_timestamp);
- if (qs > 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found deposit %s in exchange database\n",
- GNUNET_h2s (&dc->h_contract_terms.hash));
- if (TALER_ARL_do_abort ())
- return GNUNET_SYSERR;
- return GNUNET_OK; /* found, all good */
- }
+ missing |= (0 == qs);
if (qs < 0)
{
GNUNET_break (0); /* DB error, complain */
@@ -139,6 +175,15 @@ test_dc (void *cls,
return GNUNET_SYSERR;
}
}
+ if (! missing)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Found deposit %s in exchange database\n",
+ GNUNET_h2s (&dc->h_contract_terms.hash));
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK; /* all coins found, all good */
+ }
/* deposit confirmation missing! report! */
TALER_ARL_report (
report_deposit_confirmation_inconsistencies,
@@ -146,7 +191,7 @@ test_dc (void *cls,
TALER_JSON_pack_time_abs_human ("timestamp",
dc->exchange_timestamp.abs_time),
TALER_JSON_pack_amount ("amount",
- &dc->amount_without_fee),
+ &dc->total_without_fee),
GNUNET_JSON_pack_uint64 ("rowid",
serial_id),
GNUNET_JSON_pack_data_auto ("account",
@@ -156,7 +201,7 @@ test_dc (void *cls,
dcc->missed_count++;
TALER_ARL_amount_add (&dcc->missed_amount,
&dcc->missed_amount,
- &dc->amount_without_fee);
+ &dc->total_without_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -173,20 +218,18 @@ test_dc (void *cls,
static enum GNUNET_DB_QueryStatus
analyze_deposit_confirmations (void *cls)
{
- struct TALER_AUDITORDB_ProgressPointDepositConfirmation ppdc;
+ TALER_ARL_DEF_PP (deposit_confirmation_serial_id);
struct DepositConfirmationContext dcc;
enum GNUNET_DB_QueryStatus qs;
enum GNUNET_DB_QueryStatus qsx;
enum GNUNET_DB_QueryStatus qsp;
-
(void) cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Analyzing deposit confirmations\n");
- ppdc.last_deposit_confirmation_serial_id = 0;
- qsp = TALER_ARL_adb->get_auditor_progress_deposit_confirmation (
+
+ qsp = TALER_ARL_adb->get_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppdc);
+ TALER_ARL_GET_PP (deposit_confirmation_serial_id),
+ NULL);
+
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -201,7 +244,8 @@ analyze_deposit_confirmations (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Resuming deposit confirmation audit at %llu\n",
- (unsigned long long) ppdc.last_deposit_confirmation_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ deposit_confirmation_serial_id));
}
/* setup 'cc' */
@@ -211,10 +255,13 @@ analyze_deposit_confirmations (void *cls)
dcc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
dcc.missed_count = 0LLU;
dcc.first_missed_coin_serial = UINT64_MAX;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "lastdepconfserialid %lu\n",
+ TALER_ARL_USE_PP (deposit_confirmation_serial_id));
qsx = TALER_ARL_adb->get_deposit_confirmations (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- ppdc.last_deposit_confirmation_serial_id,
+ TALER_ARL_USE_PP (deposit_confirmation_serial_id),
+ true, /* return suppressed */
&test_dc,
&dcc);
if (0 > qsx)
@@ -225,28 +272,30 @@ analyze_deposit_confirmations (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzed %d deposit confirmations (above serial ID %llu)\n",
(int) qsx,
- (unsigned long long) ppdc.last_deposit_confirmation_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ deposit_confirmation_serial_id));
if (0 > dcc.qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == dcc.qs);
return dcc.qs;
}
- if (UINT64_MAX == dcc.first_missed_coin_serial)
- ppdc.last_deposit_confirmation_serial_id = dcc.last_seen_coin_serial;
- else
- ppdc.last_deposit_confirmation_serial_id = dcc.first_missed_coin_serial - 1;
+ /* if (UINT64_MAX == dcc.first_missed_coin_serial)
+ ppdc.last_deposit_confirmation_serial_id = dcc.last_seen_coin_serial;
+ else
+ ppdc.last_deposit_confirmation_serial_id = dcc.first_missed_coin_serial - 1;
+ */
/* sync 'cc' back to disk */
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_deposit_confirmation (
+ qs = TALER_ARL_adb->update_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppdc);
+ TALER_ARL_SET_PP (deposit_confirmation_serial_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_auditor_progress_deposit_confirmation (
+ qs = TALER_ARL_adb->insert_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppdc);
+ TALER_ARL_SET_PP (deposit_confirmation_serial_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -254,17 +303,90 @@ analyze_deposit_confirmations (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
+
number_missed_deposit_confirmations = (json_int_t) dcc.missed_count;
total_missed_deposit_confirmations = dcc.missed_amount;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Concluded deposit confirmation audit step at %llu\n",
- (unsigned long long) ppdc.last_deposit_confirmation_serial_id);
+ (unsigned long long) TALER_ARL_USE_PP (
+ deposit_confirmation_serial_id));
return qs;
}
/**
+ * Function called on events received from Postgres.
+ *
+ * @param cls closure, NULL
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+db_notify (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received notification for new deposit_confirmation\n");
+
+ (void) cls;
+ (void) extra;
+ (void) extra_size;
+
+ if (NULL ==
+ (db_plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize DB subsystem\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (NULL !=
+ (report_deposit_confirmation_inconsistencies = json_array ()));
+
+ if (GNUNET_OK !=
+ TALER_ARL_setup_sessions_and_run (&analyze_deposit_confirmations,
+ NULL))
+ {
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deposit audit complete\n");
+ TALER_ARL_done (
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("deposit_confirmation_inconsistencies",
+ report_deposit_confirmation_inconsistencies),
+ GNUNET_JSON_pack_uint64 ("missing_deposit_confirmation_count",
+ number_missed_deposit_confirmations),
+ TALER_JSON_pack_amount ("missing_deposit_confirmation_total",
+ &total_missed_deposit_confirmations),
+ TALER_JSON_pack_time_abs_human ("auditor_start_time",
+ start_time),
+ TALER_JSON_pack_time_abs_human ("auditor_end_time",
+ GNUNET_TIME_absolute_get ())));
+}
+
+
+/**
+ * Function called on shutdown.
+ */
+static void
+do_shutdown (void *cls)
+{
+ (void) cls;
+
+ db_plugin->event_listen_cancel (eh);
+ eh = NULL;
+ TALER_AUDITORDB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ TALER_ARL_done (NULL);
+}
+
+
+/**
* Main function that will be run.
*
* @param cls closure
@@ -281,6 +403,10 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
+ cfg = c;
+
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Launching deposit auditor\n");
if (GNUNET_OK !=
@@ -289,6 +415,34 @@ run (void *cls,
global_ret = EXIT_FAILURE;
return;
}
+
+ if (NULL ==
+ (db_plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize DB subsystem\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ db_plugin->preflight (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to database\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_EXCHANGE_AUDITOR_NEW_DEPOSIT_CONFIRMATION)
+ };
+ eh = db_plugin->event_listen (db_plugin->cls,
+ &es,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &db_notify,
+ NULL);
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting deposit audit\n");
GNUNET_assert (NULL !=
@@ -333,11 +487,10 @@ main (int argc,
"internal",
"perform checks only applicable for exchange-internal audits",
&internal_checks),
- GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &TALER_ARL_master_pub),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_OPTION_END
diff --git a/src/auditor/taler-helper-auditor-purses.c b/src/auditor/taler-helper-auditor-purses.c
new file mode 100644
index 000000000..967ac13a7
--- /dev/null
+++ b/src/auditor/taler-helper-auditor-purses.c
@@ -0,0 +1,1451 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero Public License for more details.
+
+ You should have received a copy of the GNU Affero Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file auditor/taler-helper-auditor-purses.c
+ * @brief audits the purses of an exchange database
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_auditordb_plugin.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_bank_service.h"
+#include "taler_signatures.h"
+#include "report-lib.h"
+
+
+/**
+ * Use a 1 day grace period to deal with clocks not being perfectly synchronized.
+ */
+#define EXPIRATION_GRACE_PERIOD GNUNET_TIME_UNIT_DAYS
+
+/**
+ * Return value from main().
+ */
+static int global_ret;
+
+/**
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
+ */
+static int test_mode;
+
+/**
+ * Checkpointing our progress for purses.
+ */
+static TALER_ARL_DEF_PP (purse_account_merge_serial_id);
+static TALER_ARL_DEF_PP (purse_decision_serial_id);
+static TALER_ARL_DEF_PP (purse_deposits_serial_id);
+static TALER_ARL_DEF_PP (purse_merges_serial_id);
+static TALER_ARL_DEF_PP (purse_request_serial_id);
+static TALER_ARL_DEF_PP (purse_open_counter);
+static TALER_ARL_DEF_AB (purse_global_balance);
+
+/**
+ * Array of reports about row inconsistencies.
+ */
+static json_t *report_row_inconsistencies;
+
+/**
+ * Array of reports about purse balance insufficient inconsistencies.
+ */
+static json_t *report_purse_balance_insufficient_inconsistencies;
+
+/**
+ * Total amount purses were merged with insufficient balance.
+ */
+static struct TALER_Amount total_balance_insufficient_loss;
+
+/**
+ * Total amount purse decisions are delayed past deadline.
+ */
+static struct TALER_Amount total_delayed_decisions;
+
+/**
+ * Array of reports about purses's not being closed inconsistencies.
+ */
+static json_t *report_purse_not_closed_inconsistencies;
+
+/**
+ * Total amount affected by purses not having been closed on time.
+ */
+static struct TALER_Amount total_balance_purse_not_closed;
+
+/**
+ * Report about amount calculation differences (causing profit
+ * or loss at the exchange).
+ */
+static json_t *report_amount_arithmetic_inconsistencies;
+
+/**
+ * Profits the exchange made by bad amount calculations.
+ */
+static struct TALER_Amount total_arithmetic_delta_plus;
+
+/**
+ * Losses the exchange made by bad amount calculations.
+ */
+static struct TALER_Amount total_arithmetic_delta_minus;
+
+/**
+ * Array of reports about coin operations with bad signatures.
+ */
+static json_t *report_bad_sig_losses;
+
+/**
+ * Total amount lost by operations for which signatures were invalid.
+ */
+static struct TALER_Amount total_bad_sig_loss;
+
+/**
+ * Should we run checks that only work for exchange-internal audits?
+ */
+static int internal_checks;
+
+/* ***************************** Report logic **************************** */
+
+
+/**
+ * Report a (serious) inconsistency in the exchange's database with
+ * respect to calculations involving amounts.
+ *
+ * @param operation what operation had the inconsistency
+ * @param rowid affected row, 0 if row is missing
+ * @param exchange amount calculated by exchange
+ * @param auditor amount calculated by auditor
+ * @param profitable 1 if @a exchange being larger than @a auditor is
+ * profitable for the exchange for this operation,
+ * -1 if @a exchange being smaller than @a auditor is
+ * profitable for the exchange, and 0 if it is unclear
+ */
+static void
+report_amount_arithmetic_inconsistency (
+ const char *operation,
+ uint64_t rowid,
+ const struct TALER_Amount *exchange,
+ const struct TALER_Amount *auditor,
+ int profitable)
+{
+ struct TALER_Amount delta;
+ struct TALER_Amount *target;
+
+ if (0 < TALER_amount_cmp (exchange,
+ auditor))
+ {
+ /* exchange > auditor */
+ TALER_ARL_amount_subtract (&delta,
+ exchange,
+ auditor);
+ }
+ else
+ {
+ /* auditor < exchange */
+ profitable = -profitable;
+ TALER_ARL_amount_subtract (&delta,
+ auditor,
+ exchange);
+ }
+ TALER_ARL_report (report_amount_arithmetic_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ operation),
+ GNUNET_JSON_pack_uint64 ("rowid",
+ rowid),
+ TALER_JSON_pack_amount ("exchange",
+ exchange),
+ TALER_JSON_pack_amount ("auditor",
+ auditor),
+ GNUNET_JSON_pack_int64 ("profitable",
+ profitable)));
+ if (0 != profitable)
+ {
+ target = (1 == profitable)
+ ? &total_arithmetic_delta_plus
+ : &total_arithmetic_delta_minus;
+ TALER_ARL_amount_add (target,
+ target,
+ &delta);
+ }
+}
+
+
+/**
+ * Report a (serious) inconsistency in the exchange's database.
+ *
+ * @param table affected table
+ * @param rowid affected row, 0 if row is missing
+ * @param diagnostic message explaining the problem
+ */
+static void
+report_row_inconsistency (const char *table,
+ uint64_t rowid,
+ const char *diagnostic)
+{
+ TALER_ARL_report (report_row_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("table",
+ table),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ GNUNET_JSON_pack_string ("diagnostic",
+ diagnostic)));
+}
+
+
+/**
+ * Obtain the purse fee for a purse created at @a time.
+ *
+ * @param atime when was the purse created
+ * @param[out] fee set to the purse fee
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+get_purse_fee (struct GNUNET_TIME_Timestamp atime,
+ struct TALER_Amount *fee)
+{
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_GlobalFeeSet fees;
+ struct GNUNET_TIME_Relative ptimeout;
+ struct GNUNET_TIME_Relative hexp;
+ uint32_t pacl;
+
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ TALER_ARL_edb->get_global_fee (TALER_ARL_edb->cls,
+ atime,
+ &start_date,
+ &end_date,
+ &fees,
+ &ptimeout,
+ &hexp,
+ &pacl,
+ &master_sig))
+ {
+ char *diag;
+
+ GNUNET_asprintf (&diag,
+ "purse fee unavailable at %s\n",
+ GNUNET_TIME_timestamp2s (atime));
+ report_row_inconsistency ("purse-fee",
+ atime.abs_time.abs_value_us,
+ diag);
+ GNUNET_free (diag);
+ return GNUNET_SYSERR;
+ }
+ *fee = fees.purse;
+ return GNUNET_OK;
+}
+
+
+/* ***************************** Analyze purses ************************ */
+/* This logic checks the purses_requests, purse_deposits,
+ purse_refunds, purse_merges and account_merges */
+
+/**
+ * Summary data we keep per purse.
+ */
+struct PurseSummary
+{
+ /**
+ * Public key of the purse.
+ * Always set when the struct is first initialized.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Balance of the purse from deposits (includes purse fee, excludes deposit
+ * fees), as calculated by auditor.
+ */
+ struct TALER_Amount balance;
+
+ /**
+ * Expected value of the purse, excludes purse fee.
+ */
+ struct TALER_Amount total_value;
+
+ /**
+ * Purse balance according to exchange DB.
+ */
+ struct TALER_Amount exchange_balance;
+
+ /**
+ * Contract terms of the purse.
+ */
+ struct TALER_PrivateContractHashP h_contract_terms;
+
+ /**
+ * Merge timestamp (as per exchange DB).
+ */
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+
+ /**
+ * Purse creation date. This is when the merge
+ * fee is applied.
+ */
+ struct GNUNET_TIME_Timestamp creation_date;
+
+ /**
+ * Purse expiration date.
+ */
+ struct GNUNET_TIME_Timestamp expiration_date;
+
+ /**
+ * Did we have a previous purse info? Used to decide between UPDATE and
+ * INSERT later. Initialized in #load_auditor_purse_summary().
+ */
+ bool had_pi;
+
+ /**
+ * Was the purse deleted? FIXME: Not yet handled (do we need to? purse
+ * might just appear as expired eventually; but in the meantime, exchange
+ * may seem to have refunded the coins for no good reason...), also we do
+ * not yet check the deletion signature.
+ */
+ bool purse_deleted;
+
+ /**
+ * Was the purse refunded? FIXME: Not yet handled (do we need to?)
+ */
+ bool purse_refunded;
+
+};
+
+
+/**
+ * Load the auditor's remembered state about the purse into @a ps.
+ *
+ * @param[in,out] ps purse summary to (fully) initialize
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+load_auditor_purse_summary (struct PurseSummary *ps)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ uint64_t rowid;
+
+ qs = TALER_ARL_adb->get_purse_info (TALER_ARL_adb->cls,
+ &ps->purse_pub,
+ &rowid,
+ &ps->balance,
+ &ps->expiration_date);
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ ps->had_pi = false;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &ps->balance));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating fresh purse `%s'\n",
+ TALER_B2S (&ps->purse_pub));
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ ps->had_pi = true;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Auditor remembers purse `%s' has balance %s\n",
+ TALER_B2S (&ps->purse_pub),
+ TALER_amount2s (&ps->balance));
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+/**
+ * Closure to the various callbacks we make while checking a purse.
+ */
+struct PurseContext
+{
+ /**
+ * Map from hash of purse's public key to a `struct PurseSummary`.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *purses;
+
+ /**
+ * Transaction status code, set to error codes if applicable.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+
+};
+
+
+/**
+ * Create a new reserve for @a reserve_pub in @a rc.
+ *
+ * @param[in,out] pc context to update
+ * @param purse_pub key for which to create a purse
+ * @return NULL on error
+ */
+static struct PurseSummary *
+setup_purse (struct PurseContext *pc,
+ const struct TALER_PurseContractPublicKeyP *purse_pub)
+{
+ struct PurseSummary *ps;
+ struct GNUNET_HashCode key;
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_CRYPTO_hash (purse_pub,
+ sizeof (*purse_pub),
+ &key);
+ ps = GNUNET_CONTAINER_multihashmap_get (pc->purses,
+ &key);
+ if (NULL != ps)
+ return ps;
+ ps = GNUNET_new (struct PurseSummary);
+ ps->purse_pub = *purse_pub;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &ps->balance));
+ /* get purse meta-data from exchange DB */
+ qs = TALER_ARL_edb->select_purse (TALER_ARL_edb->cls,
+ purse_pub,
+ &ps->creation_date,
+ &ps->expiration_date,
+ &ps->total_value,
+ &ps->exchange_balance,
+ &ps->h_contract_terms,
+ &ps->merge_timestamp,
+ &ps->purse_deleted,
+ &ps->purse_refunded);
+ if (0 >= qs)
+ {
+ GNUNET_free (ps);
+ pc->qs = qs;
+ return NULL;
+ }
+ if (0 > (qs = load_auditor_purse_summary (ps)))
+ {
+ GNUNET_free (ps);
+ pc->qs = qs;
+ return NULL;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (pc->purses,
+ &key,
+ ps,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ return ps;
+}
+
+
+/**
+ * Function called on purse requests.
+ *
+ * @param cls closure
+ * @param rowid which row in the database was the request stored in
+ * @param purse_pub public key of the purse
+ * @param merge_pub public key representing the merge capability
+ * @param purse_creation when was the purse created
+ * @param purse_expiration when would an unmerged purse expire
+ * @param h_contract_terms contract associated with the purse
+ * @param age_limit the age limit for deposits into the purse
+ * @param target_amount amount to be put into the purse
+ * @param purse_sig signature of the purse over the initialization data
+ * @return #GNUNET_OK to continue to iterate
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_requested (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_creation,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ const struct TALER_Amount *target_amount,
+ const struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct PurseContext *pc = cls;
+ struct PurseSummary *ps;
+ struct GNUNET_HashCode key;
+
+ TALER_ARL_USE_PP (purse_request_serial_id) = rowid;
+ if (GNUNET_OK !=
+ TALER_wallet_purse_create_verify (purse_expiration,
+ h_contract_terms,
+ merge_pub,
+ age_limit,
+ target_amount,
+ purse_pub,
+ purse_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "purse-reqeust"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ target_amount),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ purse_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ target_amount);
+ }
+ GNUNET_CRYPTO_hash (purse_pub,
+ sizeof (*purse_pub),
+ &key);
+ ps = GNUNET_new (struct PurseSummary);
+ ps->purse_pub = *purse_pub;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &ps->balance));
+ ps->creation_date = purse_creation;
+ ps->expiration_date = purse_expiration;
+ ps->total_value = *target_amount;
+ ps->h_contract_terms = *h_contract_terms;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (pc->purses,
+ &key,
+ ps,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about purse deposits that have been made, with
+ * the goal of auditing the deposit's execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param deposit deposit details
+ * @param reserve_pub which reserve is the purse merged into, NULL if unknown
+ * @param flags purse flags
+ * @param auditor_balance purse balance (according to the
+ * auditor during auditing)
+ * @param purse_total target amount the purse should reach
+ * @param denom_pub denomination public key of @a coin_pub
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_deposits (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *auditor_balance,
+ const struct TALER_Amount *purse_total,
+ const struct TALER_DenominationPublicKey *denom_pub)
+{
+ struct PurseContext *pc = cls;
+ struct TALER_Amount amount_minus_fee;
+ struct PurseSummary *ps;
+ const char *base_url
+ = (NULL == deposit->exchange_base_url)
+ ? TALER_ARL_exchange_url
+ : deposit->exchange_base_url;
+ struct TALER_DenominationHashP h_denom_pub;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_deposits_serial_id));
+ TALER_ARL_USE_PP (purse_deposits_serial_id) = rowid + 1;
+
+ {
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TALER_ARL_get_denomination_info (denom_pub,
+ &issue,
+ &h_denom_pub);
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Hard database error trying to get denomination %s from database!\n",
+ TALER_B2S (denom_pub));
+ pc->qs = qs;
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ report_row_inconsistency ("purse-deposit",
+ rowid,
+ "denomination key not found");
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+ }
+ TALER_ARL_amount_subtract (&amount_minus_fee,
+ &deposit->amount,
+ &issue->fees.deposit);
+ }
+
+ if (GNUNET_OK !=
+ TALER_wallet_purse_deposit_verify (base_url,
+ &deposit->purse_pub,
+ &deposit->amount,
+ &h_denom_pub,
+ &deposit->h_age_commitment,
+ &deposit->coin_pub,
+ &deposit->coin_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "purse-deposit"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ &deposit->amount),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ &deposit->coin_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ &deposit->amount);
+ return GNUNET_OK;
+ }
+
+ ps = setup_purse (pc,
+ &deposit->purse_pub);
+ if (NULL == ps)
+ {
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs)
+ {
+ report_row_inconsistency ("purse-deposit",
+ rowid,
+ "purse not found");
+ }
+ else
+ {
+ /* Database trouble!? */
+ GNUNET_break (0);
+ }
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&ps->balance,
+ &ps->balance,
+ &amount_minus_fee);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (purse_global_balance),
+ &TALER_ARL_USE_AB (purse_global_balance),
+ &amount_minus_fee);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about purse merges that have been made, with
+ * the goal of auditing the purse merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param partner_base_url where is the reserve, NULL for this exchange
+ * @param amount total amount expected in the purse
+ * @param balance current balance in the purse
+ * @param flags purse flags
+ * @param merge_pub merge capability key
+ * @param reserve_pub reserve the merge affects
+ * @param merge_sig signature affirming the merge
+ * @param purse_pub purse key
+ * @param merge_timestamp when did the merge happen
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_merged (
+ void *cls,
+ uint64_t rowid,
+ const char *partner_base_url,
+ const struct TALER_Amount *amount,
+ const struct TALER_Amount *balance,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp merge_timestamp)
+{
+ struct PurseContext *pc = cls;
+ struct PurseSummary *ps;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_merges_serial_id));
+ TALER_ARL_USE_PP (purse_merges_serial_id) = rowid + 1;
+
+ {
+ char *reserve_url;
+
+ reserve_url
+ = TALER_reserve_make_payto (NULL == partner_base_url
+ ? TALER_ARL_exchange_url
+ : partner_base_url,
+ reserve_pub);
+ if (GNUNET_OK !=
+ TALER_wallet_purse_merge_verify (reserve_url,
+ merge_timestamp,
+ purse_pub,
+ merge_pub,
+ merge_sig))
+ {
+ GNUNET_free (reserve_url);
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "merge-purse"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ amount),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ merge_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ amount);
+ return GNUNET_OK;
+ }
+ GNUNET_free (reserve_url);
+ }
+
+ ps = setup_purse (pc,
+ purse_pub);
+ if (NULL == ps)
+ {
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs)
+ {
+ report_row_inconsistency ("purse-merge",
+ rowid,
+ "purse not found");
+ }
+ else
+ {
+ /* Database trouble!? */
+ GNUNET_break (0);
+ }
+ return GNUNET_SYSERR;
+ }
+ GNUNET_break (0 ==
+ GNUNET_TIME_timestamp_cmp (merge_timestamp,
+ ==,
+ ps->merge_timestamp));
+ TALER_ARL_amount_add (&ps->balance,
+ &ps->balance,
+ amount);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about account merge requests that have been
+ * made, with the goal of auditing the account merge execution.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param reserve_pub reserve affected by the merge
+ * @param purse_pub purse being merged
+ * @param h_contract_terms hash over contract of the purse
+ * @param purse_expiration when would the purse expire
+ * @param amount total amount in the purse
+ * @param min_age minimum age of all coins deposited into the purse
+ * @param flags how was the purse created
+ * @param purse_fee if a purse fee was paid, how high is it
+ * @param merge_timestamp when was the merge approved
+ * @param reserve_sig signature by reserve approving the merge
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_account_merged (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct PurseContext *pc = cls;
+ struct PurseSummary *ps;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (purse_account_merge_serial_id));
+ TALER_ARL_USE_PP (purse_account_merge_serial_id) = rowid + 1;
+ if (GNUNET_OK !=
+ TALER_wallet_account_merge_verify (merge_timestamp,
+ purse_pub,
+ purse_expiration,
+ h_contract_terms,
+ amount,
+ purse_fee,
+ min_age,
+ flags,
+ reserve_pub,
+ reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "account-merge"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ purse_fee),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ purse_fee);
+ return GNUNET_OK;
+ }
+ ps = setup_purse (pc,
+ purse_pub);
+ if (NULL == ps)
+ {
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs)
+ {
+ report_row_inconsistency ("account-merge",
+ rowid,
+ "purse not found");
+ }
+ else
+ {
+ /* Database trouble!? */
+ GNUNET_break (0);
+ }
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (purse_global_balance),
+ &TALER_ARL_USE_AB (purse_global_balance),
+ purse_fee);
+ TALER_ARL_amount_add (&ps->balance,
+ &ps->balance,
+ purse_fee);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about purse decisions that have been made.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param purse_pub which purse was the decision made on
+ * @param refunded true if decision was to refund
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_decision (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ bool refunded)
+{
+ struct PurseContext *pc = cls;
+ struct PurseSummary *ps;
+ struct GNUNET_HashCode key;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_Amount purse_fee;
+ struct TALER_Amount balance_without_purse_fee;
+
+ TALER_ARL_USE_PP (purse_decision_serial_id) = rowid;
+ ps = setup_purse (pc,
+ purse_pub);
+ if (NULL == ps)
+ {
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == pc->qs)
+ {
+ report_row_inconsistency ("purse-decision",
+ rowid,
+ "purse not found");
+ }
+ else
+ {
+ /* Database trouble!? */
+ GNUNET_break (0);
+ }
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ get_purse_fee (ps->creation_date,
+ &purse_fee))
+ {
+ report_row_inconsistency ("purse-request",
+ rowid,
+ "purse fee unavailable");
+ }
+ if (0 >
+ TALER_amount_subtract (&balance_without_purse_fee,
+ &ps->balance,
+ &purse_fee))
+ {
+ report_row_inconsistency ("purse-request",
+ rowid,
+ "purse fee higher than balance");
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &balance_without_purse_fee));
+ }
+
+ if (refunded)
+ {
+ if (-1 != TALER_amount_cmp (&balance_without_purse_fee,
+ &ps->total_value))
+ {
+ report_amount_arithmetic_inconsistency ("purse-decision: refund",
+ rowid,
+ &balance_without_purse_fee,
+ &ps->total_value,
+ 0);
+ }
+ }
+ else
+ {
+ if (-1 == TALER_amount_cmp (&balance_without_purse_fee,
+ &ps->total_value))
+ {
+ report_amount_arithmetic_inconsistency ("purse-decision: merge",
+ rowid,
+ &ps->total_value,
+ &balance_without_purse_fee,
+ 0);
+ TALER_ARL_amount_add (&total_balance_insufficient_loss,
+ &total_balance_insufficient_loss,
+ &ps->total_value);
+ }
+ }
+
+ qs = TALER_ARL_adb->delete_purse_info (TALER_ARL_adb->cls,
+ purse_pub);
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ pc->qs = qs;
+ return GNUNET_SYSERR;
+ }
+ GNUNET_CRYPTO_hash (purse_pub,
+ sizeof (*purse_pub),
+ &key);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (pc->purses,
+ &key,
+ ps));
+ GNUNET_free (ps);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called on expired purses.
+ *
+ * @param cls closure
+ * @param purse_pub public key of the purse
+ * @param balance amount of money in the purse
+ * @param expiration_date when did the purse expire?
+ * @return #GNUNET_OK to continue to iterate
+ */
+static enum GNUNET_GenericReturnValue
+handle_purse_expired (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date)
+{
+ struct PurseContext *pc = cls;
+
+ (void) pc;
+ TALER_ARL_report (report_purse_not_closed_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("purse_pub",
+ purse_pub),
+ TALER_JSON_pack_amount ("balance",
+ balance),
+ TALER_JSON_pack_time_abs_human ("expired",
+ expiration_date.abs_time)));
+ TALER_ARL_amount_add (&total_delayed_decisions,
+ &total_delayed_decisions,
+ balance);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Check that the purse summary matches what the exchange database
+ * thinks about the purse, and update our own state of the purse.
+ *
+ * Remove all purses that we are happy with from the DB.
+ *
+ * @param cls our `struct PurseContext`
+ * @param key hash of the purse public key
+ * @param value a `struct PurseSummary`
+ * @return #GNUNET_OK to process more entries
+ */
+static enum GNUNET_GenericReturnValue
+verify_purse_balance (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct PurseContext *pc = cls;
+ struct PurseSummary *ps = value;
+ enum GNUNET_GenericReturnValue ret;
+ enum GNUNET_DB_QueryStatus qs;
+
+ ret = GNUNET_OK;
+ if (internal_checks)
+ {
+ struct TALER_Amount pf;
+ struct TALER_Amount balance_without_purse_fee;
+
+ /* subtract purse fee from ps->balance to get actual balance we expect, as
+ we track the balance including purse fee, while the exchange subtracts
+ the purse fee early on. */
+ if (GNUNET_OK !=
+ get_purse_fee (ps->creation_date,
+ &pf))
+ {
+ GNUNET_break (0);
+ report_row_inconsistency ("purse",
+ 0,
+ "purse fee unavailable");
+ }
+ if (0 >
+ TALER_amount_subtract (&balance_without_purse_fee,
+ &ps->balance,
+ &pf))
+ {
+ report_row_inconsistency ("purse",
+ 0,
+ "purse fee higher than balance");
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &balance_without_purse_fee));
+ }
+
+ if (0 != TALER_amount_cmp (&ps->exchange_balance,
+ &balance_without_purse_fee))
+ {
+ report_amount_arithmetic_inconsistency ("purse-balance",
+ 0,
+ &ps->exchange_balance,
+ &balance_without_purse_fee,
+ 0);
+ }
+ }
+
+ if (ps->had_pi)
+ qs = TALER_ARL_adb->update_purse_info (TALER_ARL_adb->cls,
+ &ps->purse_pub,
+ &ps->balance);
+ else
+ qs = TALER_ARL_adb->insert_purse_info (TALER_ARL_adb->cls,
+ &ps->purse_pub,
+ &ps->balance,
+ ps->expiration_date);
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
+ pc->qs = qs;
+ return GNUNET_SYSERR;
+ }
+
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multihashmap_remove (pc->purses,
+ key,
+ ps));
+ GNUNET_free (ps);
+ return ret;
+}
+
+
+/**
+ * Analyze purses for being well-formed.
+ *
+ * @param cls NULL
+ * @return transaction status code
+ */
+static enum GNUNET_DB_QueryStatus
+analyze_purses (void *cls)
+{
+ struct PurseContext pc;
+ enum GNUNET_DB_QueryStatus qsx;
+ enum GNUNET_DB_QueryStatus qs;
+ enum GNUNET_DB_QueryStatus qsp;
+
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Analyzing purses\n");
+ qsp = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (purse_account_merge_serial_id),
+ TALER_ARL_GET_PP (purse_decision_serial_id),
+ TALER_ARL_GET_PP (purse_deposits_serial_id),
+ TALER_ARL_GET_PP (purse_merges_serial_id),
+ TALER_ARL_GET_PP (purse_request_serial_id),
+ TALER_ARL_GET_PP (purse_open_counter),
+ NULL);
+ if (0 > qsp)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
+ return qsp;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsp)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "First analysis using this auditor, starting audit from scratch\n");
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resuming purse audit at %llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_request_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_decision_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_deposits_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_account_merge_serial_id));
+ }
+ pc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (purse_global_balance),
+ NULL);
+ if (qsx < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
+ return qsx;
+ }
+ pc.purses = GNUNET_CONTAINER_multihashmap_create (512,
+ GNUNET_NO);
+
+ qs = TALER_ARL_edb->select_purse_requests_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (purse_request_serial_id),
+ &handle_purse_requested,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
+ qs = TALER_ARL_edb->select_purse_merges_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (purse_merges_serial_id),
+ &handle_purse_merged,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ qs = TALER_ARL_edb->select_purse_deposits_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (purse_deposits_serial_id),
+ &handle_purse_deposits,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ /* Charge purse fee! */
+ qs = TALER_ARL_edb->select_account_merges_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (purse_account_merge_serial_id),
+ &handle_account_merged,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
+ qs = TALER_ARL_edb->select_all_purse_decisions_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (purse_decision_serial_id),
+ &handle_purse_decision,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
+ qs = TALER_ARL_adb->select_purse_expired (
+ TALER_ARL_adb->cls,
+ &handle_purse_expired,
+ &pc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+
+ GNUNET_CONTAINER_multihashmap_iterate (pc.purses,
+ &verify_purse_balance,
+ &pc);
+ GNUNET_break (0 ==
+ GNUNET_CONTAINER_multihashmap_size (pc.purses));
+ GNUNET_CONTAINER_multihashmap_destroy (pc.purses);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != pc.qs)
+ return qs;
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
+ {
+ qs = TALER_ARL_adb->insert_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (purse_global_balance),
+ NULL);
+ }
+ else
+ {
+ qs = TALER_ARL_adb->update_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (purse_global_balance),
+ NULL);
+ }
+ if (0 >= qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
+ qs = TALER_ARL_adb->update_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (purse_account_merge_serial_id),
+ TALER_ARL_SET_PP (purse_decision_serial_id),
+ TALER_ARL_SET_PP (purse_deposits_serial_id),
+ TALER_ARL_SET_PP (purse_merges_serial_id),
+ TALER_ARL_SET_PP (purse_request_serial_id),
+ TALER_ARL_SET_PP (purse_open_counter),
+ NULL);
+ else
+ qs = TALER_ARL_adb->insert_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (purse_account_merge_serial_id),
+ TALER_ARL_SET_PP (purse_decision_serial_id),
+ TALER_ARL_SET_PP (purse_deposits_serial_id),
+ TALER_ARL_SET_PP (purse_merges_serial_id),
+ TALER_ARL_SET_PP (purse_request_serial_id),
+ TALER_ARL_SET_PP (purse_open_counter),
+ NULL);
+ if (0 >= qs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Failed to update auditor DB, not recording progress\n");
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Concluded purse audit step at %llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_request_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_decision_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_deposits_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ purse_account_merge_serial_id));
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+/**
+ * Main function that will be run.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Launching auditor\n");
+ if (GNUNET_OK !=
+ TALER_ARL_init (c))
+ {
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (
+ purse_global_balance)));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_balance_insufficient_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_delayed_decisions));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_arithmetic_delta_plus));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_arithmetic_delta_minus));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_balance_purse_not_closed));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_bad_sig_loss));
+
+ GNUNET_assert (NULL !=
+ (report_row_inconsistencies = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_purse_balance_insufficient_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_purse_not_closed_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_amount_arithmetic_inconsistencies
+ = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_bad_sig_losses = json_array ()));
+ if (GNUNET_OK !=
+ TALER_ARL_setup_sessions_and_run (&analyze_purses,
+ NULL))
+ {
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ TALER_ARL_done (
+ GNUNET_JSON_PACK (
+ /* Globals (REVIEW!) */
+ TALER_JSON_pack_amount ("total_balance_insufficient",
+ &total_balance_insufficient_loss),
+ TALER_JSON_pack_amount ("total_delayed_purse_decisions",
+ &total_delayed_decisions),
+ GNUNET_JSON_pack_array_steal (
+ "purse_balance_insufficient_inconsistencies",
+ report_purse_balance_insufficient_inconsistencies),
+ TALER_JSON_pack_amount ("total_balance_purse_not_closed",
+ &total_balance_purse_not_closed),
+ TALER_JSON_pack_amount ("total_bad_sig_loss",
+ &total_bad_sig_loss),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_plus",
+ &total_arithmetic_delta_plus),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_minus",
+ &total_arithmetic_delta_minus),
+
+ /* Global 'balances' */
+ TALER_JSON_pack_amount ("total_purse_balance",
+ &TALER_ARL_USE_AB (purse_global_balance)),
+ GNUNET_JSON_pack_uint64 ("total_purse_count",
+ TALER_ARL_USE_PP (purse_open_counter)),
+
+ GNUNET_JSON_pack_array_steal ("purse_not_closed_inconsistencies",
+ report_purse_not_closed_inconsistencies),
+ GNUNET_JSON_pack_array_steal ("bad_sig_losses",
+ report_bad_sig_losses),
+ GNUNET_JSON_pack_array_steal ("row_inconsistencies",
+ report_row_inconsistencies),
+ GNUNET_JSON_pack_array_steal ("amount_arithmetic_inconsistencies",
+ report_amount_arithmetic_inconsistencies),
+ /* Information about audited range ... */
+ TALER_JSON_pack_time_abs_human ("auditor_start_time",
+ start_time),
+ TALER_JSON_pack_time_abs_human ("auditor_end_time",
+ GNUNET_TIME_absolute_get ()),
+ GNUNET_JSON_pack_uint64 ("start_ppp_purse_merges_serial_id",
+ 0 /* not supported anymore */),
+ GNUNET_JSON_pack_uint64 ("start_ppp_purse_deposits_serial_id",
+ 0 /* not supported anymore */),
+ GNUNET_JSON_pack_uint64 ("start_ppp_account_merge_serial_id",
+ 0 /* not supported anymore */),
+ GNUNET_JSON_pack_uint64 ("end_ppp_purse_merges_serial_id",
+ TALER_ARL_USE_PP (
+ purse_merges_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppp_purse_deposits_serial_id",
+ TALER_ARL_USE_PP (
+ purse_deposits_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppp_account_merge_serial_id",
+ TALER_ARL_USE_PP (
+ purse_account_merge_serial_id))));
+}
+
+
+/**
+ * The main function to check the database's handling of purses.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag ('i',
+ "internal",
+ "perform checks only applicable for exchange-internal audits",
+ &internal_checks),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
+ GNUNET_GETOPT_option_timetravel ('T',
+ "timetravel"),
+ GNUNET_GETOPT_OPTION_END
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ /* force linker to link against libtalerutil; if we do
+ not do this, the linker may "optimize" libtalerutil
+ away and skip #TALER_OS_init(), which we do need */
+ (void) TALER_project_data_default ();
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
+ return EXIT_INVALIDARGUMENT;
+ ret = GNUNET_PROGRAM_run (
+ argc,
+ argv,
+ "taler-helper-auditor-purses",
+ gettext_noop ("Audit Taler exchange purse handling"),
+ options,
+ &run,
+ NULL);
+ GNUNET_free_nz ((void *) argv);
+ if (GNUNET_SYSERR == ret)
+ return EXIT_INVALIDARGUMENT;
+ if (GNUNET_NO == ret)
+ return EXIT_SUCCESS;
+ return global_ret;
+}
+
+
+/* end of taler-helper-auditor-purses.c */
diff --git a/src/auditor/taler-helper-auditor-render.py b/src/auditor/taler-helper-auditor-render.py
index 4b086cb62..b9c92b29c 100644
--- a/src/auditor/taler-helper-auditor-render.py
+++ b/src/auditor/taler-helper-auditor-render.py
@@ -53,4 +53,14 @@ jinjaEnv = jinja2.Environment(loader=StdinLoader(),
autoescape=False)
tmpl = jinjaEnv.get_template('stdin');
-print(tmpl.render(aggregation = jsonData1, coins = jsonData2, deposits = jsonData3, reserves = jsonData4, wire = jsonData5))
+try:
+ print(tmpl.render(aggregation = jsonData1, coins = jsonData2, deposits = jsonData3, reserves = jsonData4, wire = jsonData5))
+except jinja2.TemplateSyntaxError as error:
+ print("Template syntax error: {error.message} on line {error.lineno}.".format(error=error))
+ exit(1)
+except jinja2.UndefinedError as error:
+ print("Template undefined error: {error.message}.".format(error=error))
+ exit(1)
+except TypeError as error:
+ print("Template type error: {0}.".format(error.args[0]))
+ exit(1)
diff --git a/src/auditor/taler-helper-auditor-reserves.c b/src/auditor/taler-helper-auditor-reserves.c
index c6c4d3ad3..aa35c6a75 100644
--- a/src/auditor/taler-helper-auditor-reserves.c
+++ b/src/auditor/taler-helper-auditor-reserves.c
@@ -39,6 +39,14 @@
static int global_ret;
/**
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
+ */
+static int test_mode;
+
+/**
* After how long should idle reserves be closed?
*/
static struct GNUNET_TIME_Relative idle_reserve_expiration_time;
@@ -46,15 +54,29 @@ static struct GNUNET_TIME_Relative idle_reserve_expiration_time;
/**
* Checkpointing our progress for reserves.
*/
-static struct TALER_AUDITORDB_ProgressPointReserve ppr;
+static TALER_ARL_DEF_PP (reserves_reserve_in_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_out_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_recoup_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_open_serial_id);
+static TALER_ARL_DEF_PP (reserves_reserve_close_serial_id);
+static TALER_ARL_DEF_PP (reserves_purse_decisions_serial_id);
+static TALER_ARL_DEF_PP (reserves_account_merges_serial_id);
+static TALER_ARL_DEF_PP (reserves_history_requests_serial_id);
/**
- * Checkpointing our progress for reserves.
+ * Tracked global reserve balances.
*/
-static struct TALER_AUDITORDB_ProgressPointReserve ppr_start;
+static TALER_ARL_DEF_AB (reserves_reserve_total_balance);
+static TALER_ARL_DEF_AB (reserves_reserve_loss);
+static TALER_ARL_DEF_AB (reserves_withdraw_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_close_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_purse_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_open_fee_revenue);
+static TALER_ARL_DEF_AB (reserves_history_fee_revenue);
+
/**
- * Array of reports about row inconsitencies.
+ * Array of reports about row inconsistencies.
*/
static json_t *report_row_inconsistencies;
@@ -65,39 +87,36 @@ static json_t *report_row_inconsistencies;
static json_t *denomination_key_validity_withdraw_inconsistencies;
/**
- * Array of reports about reserve balance insufficient inconsitencies.
+ * Array of reports about reserve balance insufficient inconsistencies.
*/
static json_t *report_reserve_balance_insufficient_inconsistencies;
/**
- * Array of reports about purse balance insufficient inconsitencies.
+ * Array of reports about purse balance insufficient inconsistencies.
*/
static json_t *report_purse_balance_insufficient_inconsistencies;
/**
- * Total amount reserves were charged beyond their balance.
- */
-static struct TALER_Amount total_balance_insufficient_loss;
-
-/**
* Array of reports about reserve balance summary wrong in database.
*/
static json_t *report_reserve_balance_summary_wrong_inconsistencies;
/**
* Total delta between expected and stored reserve balance summaries,
- * for positive deltas.
+ * for positive deltas. Used only when internal checks are
+ * enabled.
*/
static struct TALER_Amount total_balance_summary_delta_plus;
/**
* Total delta between expected and stored reserve balance summaries,
- * for negative deltas.
+ * for negative deltas. Used only when internal checks are
+ * enabled.
*/
static struct TALER_Amount total_balance_summary_delta_minus;
/**
- * Array of reports about reserve's not being closed inconsitencies.
+ * Array of reports about reserve's not being closed inconsistencies.
*/
static json_t *report_reserve_not_closed_inconsistencies;
@@ -123,31 +142,6 @@ static struct TALER_Amount total_arithmetic_delta_plus;
static struct TALER_Amount total_arithmetic_delta_minus;
/**
- * Expected balance in the escrow account.
- */
-static struct TALER_Amount total_escrow_balance;
-
-/**
- * Recoups we made on denominations that were not revoked (!?).
- */
-static struct TALER_Amount total_irregular_recoups;
-
-/**
- * Total withdraw fees earned.
- */
-static struct TALER_Amount total_withdraw_fee_income;
-
-/**
- * Total purse fees earned.
- */
-static struct TALER_Amount total_purse_fee_income;
-
-/**
- * Total history fees earned.
- */
-static struct TALER_Amount total_history_fee_income;
-
-/**
* Array of reports about coin operations with bad signatures.
*/
static json_t *report_bad_sig_losses;
@@ -220,8 +214,8 @@ report_amount_arithmetic_inconsistency (
if (0 != profitable)
{
target = (1 == profitable)
- ? &total_arithmetic_delta_plus
- : &total_arithmetic_delta_minus;
+ ? &total_arithmetic_delta_plus
+ : &total_arithmetic_delta_minus;
TALER_ARL_amount_add (target,
target,
&delta);
@@ -279,21 +273,15 @@ struct ReserveSummary
struct TALER_Amount total_out;
/**
- * Sum of withdraw fees encountered during this transaction.
+ * Sum of balance and fees encountered during this transaction.
*/
- struct TALER_Amount total_fee;
+ struct TALER_AUDITORDB_ReserveFeeBalance curr_balance;
/**
- * Previous balance of the reserve as remembered by the auditor.
+ * Previous balances of the reserve as remembered by the auditor.
* (updated based on @e total_in and @e total_out at the end).
*/
- struct TALER_Amount balance_at_previous_audit;
-
- /**
- * Previous withdraw fee balance of the reserve, as remembered by the auditor.
- * (updated based on @e total_fee at the end).
- */
- struct TALER_Amount a_withdraw_fee_balance;
+ struct TALER_AUDITORDB_ReserveFeeBalance prev_balance;
/**
* Previous reserve expiration data, as remembered by the auditor.
@@ -333,10 +321,8 @@ load_auditor_reserve_summary (struct ReserveSummary *rs)
qs = TALER_ARL_adb->get_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
&rowid,
- &rs->balance_at_previous_audit,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
&rs->a_expiration_date,
&rs->sender_account);
if (0 > qs)
@@ -349,31 +335,35 @@ load_auditor_reserve_summary (struct ReserveSummary *rs)
rs->had_ri = false;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (rs->total_in.currency,
- &rs->balance_at_previous_audit));
+ &rs->prev_balance.reserve_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.reserve_loss));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (rs->total_in.currency,
- &rs->a_withdraw_fee_balance));
+ &rs->prev_balance.withdraw_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.close_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.purse_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.open_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (rs->total_in.currency,
+ &rs->prev_balance.history_fee_balance));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating fresh reserve `%s' with starting balance %s\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->balance_at_previous_audit));
+ "Creating fresh reserve `%s'\n",
+ TALER_B2S (&rs->reserve_pub));
return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
}
rs->had_ri = true;
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&rs->balance_at_previous_audit,
- &rs->a_withdraw_fee_balance)) ||
- (GNUNET_YES !=
- TALER_amount_cmp_currency (&rs->total_in,
- &rs->balance_at_previous_audit)) )
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Auditor remembers reserve `%s' has balance %s\n",
TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->balance_at_previous_audit));
+ TALER_amount2s (&rs->prev_balance.reserve_balance));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -436,7 +426,25 @@ setup_reserve (struct ReserveContext *rc,
&rs->total_out));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &rs->total_fee));
+ &rs->curr_balance.reserve_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.reserve_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.withdraw_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.close_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.purse_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.open_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.history_fee_balance));
if (0 > (qs = load_auditor_reserve_summary (rs)))
{
GNUNET_free (rs);
@@ -479,9 +487,8 @@ handle_reserve_in (void *cls,
(void) wire_reference;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_in_serial_id);
- ppr.last_reserve_in_serial_id = rowid + 1;
-
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_in_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_in_serial_id) = rowid + 1;
rs = setup_reserve (rc,
reserve_pub);
if (NULL == rs)
@@ -489,9 +496,6 @@ handle_reserve_in (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- credit);
if (NULL == rs->sender_account)
rs->sender_account = GNUNET_strdup (sender_account_details);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -503,6 +507,9 @@ handle_reserve_in (void *cls,
idle_reserve_expiration_time));
rs->a_expiration_date = GNUNET_TIME_timestamp_max (rs->a_expiration_date,
expiry);
+ TALER_ARL_amount_add (&rs->total_in,
+ &rs->total_in,
+ credit);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -541,8 +548,8 @@ handle_reserve_out (void *cls,
struct TALER_DenominationHashP h_denom_pub;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_out_serial_id);
- ppr.last_reserve_out_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_out_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_out_serial_id) = rowid + 1;
/* lookup denomination pub data (make sure denom_pub is valid, establish fees);
initializes wsrd.h_denomination_pub! */
@@ -618,7 +625,7 @@ handle_reserve_out (void *cls,
amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
- return GNUNET_OK; /* exit function here, we cannot add this to the legitimate withdrawals */
+ return GNUNET_OK; /* exit function here, we cannot add this to the legitimate withdrawals */
}
TALER_ARL_amount_add (&auditor_amount_with_fee,
@@ -639,9 +646,6 @@ handle_reserve_out (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- &auditor_amount_with_fee);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Reserve `%s' reduced by %s from withdraw\n",
TALER_B2S (reserve_pub),
@@ -649,9 +653,15 @@ handle_reserve_out (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Increasing withdraw profits by fee %s\n",
TALER_amount2s (&issue->fees.withdraw));
- TALER_ARL_amount_add (&rs->total_fee,
- &rs->total_fee,
+ TALER_ARL_amount_add (&rs->curr_balance.withdraw_fee_balance,
+ &rs->curr_balance.withdraw_fee_balance,
+ &issue->fees.withdraw);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_withdraw_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_withdraw_fee_revenue),
&issue->fees.withdraw);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ &auditor_amount_with_fee);
if (TALER_ARL_do_abort ())
return GNUNET_SYSERR;
return GNUNET_OK;
@@ -684,7 +694,7 @@ handle_recoup_by_reserve (
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind)
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind)
{
struct ReserveContext *rc = cls;
struct ReserveSummary *rs;
@@ -696,8 +706,8 @@ handle_recoup_by_reserve (
(void) denom_pub;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_recoup_serial_id);
- ppr.last_reserve_recoup_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id) = rowid + 1;
/* We know that denom_pub matches denom_pub_hash because this
is how the SQL statement joined the tables. */
if (GNUNET_OK !=
@@ -741,8 +751,8 @@ handle_recoup_by_reserve (
report_row_inconsistency ("recoup",
rowid,
"denomination key not in revocation set");
- TALER_ARL_amount_add (&total_irregular_recoups,
- &total_irregular_recoups,
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_loss),
+ &TALER_ARL_USE_AB (reserves_reserve_loss),
amount);
}
else
@@ -770,10 +780,11 @@ handle_recoup_by_reserve (
}
else
{
- rev_rowid = 0; /* reported elsewhere */
+ rev_rowid = 0; /* reported elsewhere */
}
if ( (NULL != rev) &&
- (0 == strcmp (rev, "master signature invalid")) )
+ (0 == strcmp (rev,
+ "master signature invalid")) )
{
TALER_ARL_report (report_bad_sig_losses,
GNUNET_JSON_PACK (
@@ -868,6 +879,88 @@ get_closing_fee (const char *receiver_account,
/**
+ * Function called about reserve opening operations.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature affirming the operation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserve_open (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_open_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_open_serial_id) = rowid + 1;
+
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_open_verify (reserve_payment,
+ request_timestamp,
+ reserve_expiration,
+ purse_limit,
+ reserve_pub,
+ reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "reserve-open"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ reserve_payment),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ reserve_payment);
+ return GNUNET_OK;
+ }
+ TALER_ARL_amount_add (&rs->curr_balance.open_fee_balance,
+ &rs->curr_balance.open_fee_balance,
+ reserve_payment);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_open_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_open_fee_revenue),
+ reserve_payment);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ reserve_payment);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Additional open operation for reserve `%s' of %s\n",
+ TALER_B2S (reserve_pub),
+ TALER_amount2s (reserve_payment));
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
* Function called about reserve closing operations
* the aggregator triggered.
*
@@ -879,6 +972,8 @@ get_closing_fee (const char *receiver_account,
* @param reserve_pub public key of the reserve
* @param receiver_account where did we send the funds
* @param transfer_details details about the wire transfer
+ * @param close_request_row which close request triggered the operation?
+ * 0 if it was a timeout
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
static enum GNUNET_GenericReturnValue
@@ -890,15 +985,16 @@ handle_reserve_closed (
const struct TALER_Amount *closing_fee,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *transfer_details)
+ const struct TALER_WireTransferIdentifierRawP *transfer_details,
+ uint64_t close_request_row)
{
struct ReserveContext *rc = cls;
struct ReserveSummary *rs;
(void) transfer_details;
/* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_reserve_close_serial_id);
- ppr.last_reserve_close_serial_id = rowid + 1;
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_reserve_close_serial_id));
+ TALER_ARL_USE_PP (reserves_reserve_close_serial_id) = rowid + 1;
rs = setup_reserve (rc,
reserve_pub);
@@ -910,12 +1006,6 @@ handle_reserve_closed (
{
struct TALER_Amount expected_fee;
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- amount_with_fee);
- TALER_ARL_amount_add (&rs->total_fee,
- &rs->total_fee,
- closing_fee);
/* verify closing_fee is correct! */
if (GNUNET_OK !=
get_closing_fee (receiver_account,
@@ -935,20 +1025,117 @@ handle_reserve_closed (
1);
}
}
- if (NULL == rs->sender_account)
- {
- GNUNET_break (! rs->had_ri);
- report_row_inconsistency ("reserves_close",
- rowid,
- "target account not verified, auditor does not know reserve");
+
+ TALER_ARL_amount_add (&rs->curr_balance.close_fee_balance,
+ &rs->curr_balance.close_fee_balance,
+ closing_fee);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_close_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_close_fee_revenue),
+ closing_fee);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ amount_with_fee);
+ if (0 != close_request_row)
+ {
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct TALER_Amount close_balance;
+ struct TALER_Amount close_fee;
+ char *payto_uri;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TALER_ARL_edb->select_reserve_close_request_info (
+ TALER_ARL_edb->cls,
+ reserve_pub,
+ close_request_row,
+ &reserve_sig,
+ &request_timestamp,
+ &close_balance,
+ &close_fee,
+ &payto_uri);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "reserve close request unknown");
+ }
+ else
+ {
+ struct TALER_PaytoHashP h_payto;
+
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_close_verify (
+ request_timestamp,
+ &h_payto,
+ reserve_pub,
+ &reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "close-request"),
+ GNUNET_JSON_pack_uint64 ("row",
+ close_request_row),
+ TALER_JSON_pack_amount ("loss",
+ amount_with_fee),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ amount_with_fee);
+ }
+ }
+ if ( (NULL == payto_uri) &&
+ (NULL == rs->sender_account) )
+ {
+ GNUNET_break (! rs->had_ri);
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account not verified, auditor does not know reserve");
+ }
+ if (NULL == payto_uri)
+ {
+ if ( (NULL == rs->sender_account) ||
+ (0 != strcmp (rs->sender_account,
+ receiver_account)) )
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
+ }
+ else
+ {
+ if (0 != strcmp (payto_uri,
+ receiver_account))
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
+ }
+ GNUNET_free (payto_uri);
}
- else if (0 != strcmp (rs->sender_account,
- receiver_account))
+ else
{
- report_row_inconsistency ("reserves_close",
- rowid,
- "target account does not match origin account");
+ if (NULL == rs->sender_account)
+ {
+ GNUNET_break (! rs->had_ri);
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account not verified, auditor does not know reserve");
+ }
+ else if (0 != strcmp (rs->sender_account,
+ receiver_account))
+ {
+ report_row_inconsistency ("reserves_close",
+ rowid,
+ "target account does not match origin account");
+ }
}
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Additional closing operation for reserve `%s' of %s\n",
TALER_B2S (reserve_pub),
@@ -960,6 +1147,137 @@ handle_reserve_closed (
/**
+ * Function called with details about account merge requests that have been
+ * made, with the goal of accounting for the merge fee paid by the reserve (if
+ * applicable).
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the deposit in our DB
+ * @param reserve_pub reserve affected by the merge
+ * @param purse_pub purse being merged
+ * @param h_contract_terms hash over contract of the purse
+ * @param purse_expiration when would the purse expire
+ * @param amount total amount in the purse
+ * @param min_age minimum age of all coins deposited into the purse
+ * @param flags how was the purse created
+ * @param purse_fee if a purse fee was paid, how high is it
+ * @param merge_timestamp when was the merge approved
+ * @param reserve_sig signature by reserve approving the merge
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+handle_account_merged (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_Amount *amount,
+ uint32_t min_age,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ /* should be monotonically increasing */
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (reserves_account_merges_serial_id));
+ TALER_ARL_USE_PP (reserves_account_merges_serial_id) = rowid + 1;
+ if (GNUNET_OK !=
+ TALER_wallet_account_merge_verify (merge_timestamp,
+ purse_pub,
+ purse_expiration,
+ h_contract_terms,
+ amount,
+ purse_fee,
+ min_age,
+ flags,
+ reserve_pub,
+ reserve_sig))
+ {
+ TALER_ARL_report (report_bad_sig_losses,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("operation",
+ "account-merge"),
+ GNUNET_JSON_pack_uint64 ("row",
+ rowid),
+ TALER_JSON_pack_amount ("loss",
+ purse_fee),
+ GNUNET_JSON_pack_data_auto ("key_pub",
+ reserve_pub)));
+ TALER_ARL_amount_add (&total_bad_sig_loss,
+ &total_bad_sig_loss,
+ purse_fee);
+ return GNUNET_OK;
+ }
+ if ( (flags & TALER_WAMF_MERGE_MODE_MASK) !=
+ TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE)
+ return GNUNET_OK; /* no impact on reserve balance */
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_purse_fee_revenue),
+ &TALER_ARL_USE_AB (reserves_purse_fee_revenue),
+ purse_fee);
+ TALER_ARL_amount_add (&rs->curr_balance.purse_fee_balance,
+ &rs->curr_balance.purse_fee_balance,
+ purse_fee);
+ TALER_ARL_amount_add (&rs->total_out,
+ &rs->total_out,
+ purse_fee);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called with details about a purse that was merged into an account.
+ * Only updates the reserve balance, the actual verifications are done in the
+ * purse helper.
+ *
+ * @param cls closure
+ * @param rowid unique serial ID for the refund in our DB
+ * @param purse_pub public key of the purse
+ * @param reserve_pub which reserve is the purse credited to
+ * @param purse_value what is the target value of the purse
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+purse_decision_cb (void *cls,
+ uint64_t rowid,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *purse_value)
+{
+ struct ReserveContext *rc = cls;
+ struct ReserveSummary *rs;
+
+ GNUNET_assert (rowid >= TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id)); /* should be monotonically increasing */
+ TALER_ARL_USE_PP (reserves_purse_decisions_serial_id) = rowid + 1;
+ rs = setup_reserve (rc,
+ reserve_pub);
+ if (NULL == rs)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ TALER_ARL_amount_add (&rs->total_in,
+ &rs->total_in,
+ purse_value);
+ if (TALER_ARL_do_abort ())
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
* Check that the reserve summary matches what the exchange database
* thinks about the reserve, and update our own state of the reserve.
*
@@ -977,29 +1295,32 @@ verify_reserve_balance (void *cls,
{
struct ReserveContext *rc = cls;
struct ReserveSummary *rs = value;
- struct TALER_Amount balance;
+ struct TALER_Amount mbalance;
struct TALER_Amount nbalance;
enum GNUNET_DB_QueryStatus qs;
- int ret;
+ enum GNUNET_GenericReturnValue ret;
ret = GNUNET_OK;
/* Check our reserve summary balance calculation shows that
the reserve balance is acceptable (i.e. non-negative) */
- TALER_ARL_amount_add (&balance,
+ TALER_ARL_amount_add (&mbalance,
&rs->total_in,
- &rs->balance_at_previous_audit);
+ &rs->prev_balance.reserve_balance);
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&nbalance,
- &balance,
+ &mbalance,
&rs->total_out))
{
struct TALER_Amount loss;
TALER_ARL_amount_subtract (&loss,
&rs->total_out,
- &balance);
- TALER_ARL_amount_add (&total_balance_insufficient_loss,
- &total_balance_insufficient_loss,
+ &mbalance);
+ TALER_ARL_amount_add (&rs->curr_balance.reserve_loss,
+ &rs->prev_balance.reserve_loss,
+ &loss);
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_loss),
+ &TALER_ARL_USE_AB (reserves_reserve_loss),
&loss);
TALER_ARL_report (report_reserve_balance_insufficient_inconsistencies,
GNUNET_JSON_PACK (
@@ -1009,8 +1330,13 @@ verify_reserve_balance (void *cls,
&loss)));
/* Continue with a reserve balance of zero */
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (balance.currency,
- &nbalance));
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &rs->curr_balance.reserve_balance));
+ }
+ else
+ {
+ /* Update remaining reserve balance! */
+ rs->curr_balance.reserve_balance = nbalance;
}
if (internal_checks)
@@ -1020,13 +1346,10 @@ verify_reserve_balance (void *cls,
internal audit, as otherwise the balance of the 'reserves' table
is not replicated at the auditor. */
struct TALER_EXCHANGEDB_Reserve reserve;
- struct TALER_EXCHANGEDB_KycStatus kyc;
reserve.pub = rs->reserve_pub;
qs = TALER_ARL_edb->reserves_get (TALER_ARL_edb->cls,
- &reserve,
- &kyc);
- // FIXME: figure out what to do with KYC status!
+ &reserve);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
{
/* If the exchange doesn't have this reserve in the summary, it
@@ -1051,17 +1374,17 @@ verify_reserve_balance (void *cls,
else
{
/* Check that exchange's balance matches our expected balance for the reserve */
- if (0 != TALER_amount_cmp (&nbalance,
+ if (0 != TALER_amount_cmp (&rs->curr_balance.reserve_balance,
&reserve.balance))
{
struct TALER_Amount delta;
- if (0 < TALER_amount_cmp (&nbalance,
+ if (0 < TALER_amount_cmp (&rs->curr_balance.reserve_balance,
&reserve.balance))
{
/* balance > reserve.balance */
TALER_ARL_amount_subtract (&delta,
- &nbalance,
+ &rs->curr_balance.reserve_balance,
&reserve.balance);
TALER_ARL_amount_add (&total_balance_summary_delta_plus,
&total_balance_summary_delta_plus,
@@ -1072,7 +1395,7 @@ verify_reserve_balance (void *cls,
/* balance < reserve.balance */
TALER_ARL_amount_subtract (&delta,
&reserve.balance,
- &nbalance);
+ &rs->curr_balance.reserve_balance);
TALER_ARL_amount_add (&total_balance_summary_delta_minus,
&total_balance_summary_delta_minus,
&delta);
@@ -1084,10 +1407,11 @@ verify_reserve_balance (void *cls,
TALER_JSON_pack_amount ("exchange",
&reserve.balance),
TALER_JSON_pack_amount ("auditor",
- &nbalance)));
+ &rs->curr_balance.
+ reserve_balance)));
}
}
- } /* end of 'if (internal_checks)' */
+ } /* end of 'if (internal_checks)' */
/* Check that reserve is being closed if it is past its expiration date
(and the closing fee would not exceed the remaining balance) */
@@ -1144,26 +1468,43 @@ verify_reserve_balance (void *cls,
}
}
- /* Add withdraw fees we encountered to totals */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reserve reserve `%s' made %s in withdraw fees\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&rs->total_fee));
- TALER_ARL_amount_add (&rs->a_withdraw_fee_balance,
- &rs->a_withdraw_fee_balance,
- &rs->total_fee);
- TALER_ARL_amount_add (&total_escrow_balance,
- &total_escrow_balance,
+ /* We already computed the 'new' balance in 'curr_balance'
+ to include the previous balance, so this one is just
+ an assignment, not adding up! */
+ rs->prev_balance.reserve_balance = rs->curr_balance.reserve_balance;
+
+ /* Add up new totals to previous totals */
+ TALER_ARL_amount_add (&rs->prev_balance.reserve_loss,
+ &rs->prev_balance.reserve_loss,
+ &rs->curr_balance.reserve_loss);
+ TALER_ARL_amount_add (&rs->prev_balance.withdraw_fee_balance,
+ &rs->prev_balance.withdraw_fee_balance,
+ &rs->curr_balance.withdraw_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.close_fee_balance,
+ &rs->prev_balance.close_fee_balance,
+ &rs->curr_balance.close_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.purse_fee_balance,
+ &rs->prev_balance.purse_fee_balance,
+ &rs->curr_balance.purse_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.open_fee_balance,
+ &rs->prev_balance.open_fee_balance,
+ &rs->curr_balance.open_fee_balance);
+ TALER_ARL_amount_add (&rs->prev_balance.history_fee_balance,
+ &rs->prev_balance.history_fee_balance,
+ &rs->curr_balance.history_fee_balance);
+
+ /* Update global balance: add incoming first, then try
+ to subtract outgoing... */
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (reserves_reserve_total_balance),
+ &TALER_ARL_USE_AB (reserves_reserve_total_balance),
&rs->total_in);
- TALER_ARL_amount_add (&total_withdraw_fee_income,
- &total_withdraw_fee_income,
- &rs->total_fee);
{
struct TALER_Amount r;
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&r,
- &total_escrow_balance,
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance),
&rs->total_out))
{
/* We could not reduce our total balance, i.e. exchange allowed IN TOTAL (!)
@@ -1171,34 +1512,33 @@ verify_reserve_balance (void *cls,
went negative!). Woopsie. Calculate how badly it went and log. */
report_amount_arithmetic_inconsistency ("global escrow balance",
0,
- &total_escrow_balance, /* what we had */
- &rs->total_out, /* what we needed */
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance), /* what we had */
+ &rs->total_out, /* what we needed */
0 /* specific profit/loss does not apply to the total summary */);
/* We unexpectedly went negative, so a sane value to continue from
would be zero. */
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_escrow_balance));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)));
}
else
{
- total_escrow_balance = r;
+ TALER_ARL_USE_AB (reserves_reserve_total_balance) = r;
}
}
- if ( (0ULL == balance.value) &&
- (0U == balance.fraction) )
+ if (TALER_amount_is_zero (&rs->prev_balance.reserve_balance))
{
/* balance is zero, drop reserve details (and then do not update/insert) */
if (rs->had_ri)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Final balance of reserve `%s' is %s, dropping it\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ "Final balance of reserve `%s' is zero, dropping it\n",
+ TALER_B2S (&rs->reserve_pub));
qs = TALER_ARL_adb->del_reserve_info (TALER_ARL_adb->cls,
- &rs->reserve_pub,
- &TALER_ARL_master_pub);
+ &rs->reserve_pub);
if (0 >= qs)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
@@ -1209,9 +1549,8 @@ verify_reserve_balance (void *cls,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Final balance of reserve `%s' is %s, no need to remember it\n",
- TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ "Final balance of reserve `%s' is zero, no need to remember it\n",
+ TALER_B2S (&rs->reserve_pub));
}
}
else
@@ -1220,20 +1559,16 @@ verify_reserve_balance (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Remembering final balance of reserve `%s' as %s\n",
TALER_B2S (&rs->reserve_pub),
- TALER_amount2s (&nbalance));
+ TALER_amount2s (&rs->prev_balance.reserve_balance));
if (rs->had_ri)
qs = TALER_ARL_adb->update_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
- &nbalance,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
rs->a_expiration_date);
else
qs = TALER_ARL_adb->insert_reserve_info (TALER_ARL_adb->cls,
&rs->reserve_pub,
- &TALER_ARL_master_pub,
- &nbalance,
- &rs->a_withdraw_fee_balance,
+ &rs->prev_balance,
rs->a_expiration_date,
rs->sender_account);
if (0 >= qs)
@@ -1243,7 +1578,7 @@ verify_reserve_balance (void *cls,
rc->qs = qs;
}
}
-
+ /* now we can discard the cached entry */
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap_remove (rc->reserves,
key,
@@ -1255,426 +1590,6 @@ verify_reserve_balance (void *cls,
/**
- * Function called with details about purse deposits that have been made, with
- * the goal of auditing the deposit's execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param deposit deposit details
- * @param reserve_pub which reserve is the purse merged into, NULL if unknown
- * @param flags purse flags
- * @param auditor_balance purse balance (according to the
- * auditor during auditing)
- * @param purse_total target amount the purse should reach
- * @param denom_pub denomination public key of @a coin_pub
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_purse_deposits (
- void *cls,
- uint64_t rowid,
- const struct TALER_EXCHANGEDB_PurseDeposit *deposit,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *auditor_balance,
- const struct TALER_Amount *purse_total,
- const struct TALER_DenominationPublicKey *denom_pub)
-{
- struct ReserveContext *rc = cls;
- const char *base_url
- = (NULL == deposit->exchange_base_url)
- ? TALER_ARL_exchange_url
- : deposit->exchange_base_url;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount amount_minus_fee;
- struct TALER_Amount new_balance;
- struct ReserveSummary *rs;
- struct TALER_DenominationHashP h_denom_pub;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_purse_deposits_serial_id);
- ppr.last_purse_deposits_serial_id = rowid + 1;
-
- {
- const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TALER_ARL_get_denomination_info (denom_pub,
- &issue,
- &h_denom_pub);
- if (0 > qs)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Hard database error trying to get denomination %s from database!\n",
- TALER_B2S (denom_pub));
- rc->qs = qs;
- return GNUNET_SYSERR;
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- report_row_inconsistency ("purse-deposit",
- rowid,
- "denomination key not found");
- if (TALER_ARL_do_abort ())
- return GNUNET_SYSERR;
- return GNUNET_OK;
- }
- TALER_ARL_amount_subtract (&amount_minus_fee,
- &deposit->amount,
- &issue->fees.deposit);
- }
-
- if (GNUNET_OK !=
- TALER_wallet_purse_deposit_verify (base_url,
- &deposit->purse_pub,
- &deposit->amount,
- &h_denom_pub,
- &deposit->h_age_commitment,
- &deposit->coin_pub,
- &deposit->coin_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "purse-deposit"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- &deposit->amount),
- GNUNET_JSON_pack_data_auto ("key_pub",
- &deposit->coin_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- &deposit->amount);
- return GNUNET_OK;
- }
-
- TALER_ARL_amount_add (&new_balance,
- auditor_balance,
- &amount_minus_fee);
- qs = TALER_ARL_edb->set_purse_balance (TALER_ARL_edb->cls,
- &deposit->purse_pub,
- &new_balance);
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- rc->qs = qs;
- return GNUNET_SYSERR;
- }
- if (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE !=
- (flags & TALER_WAMF_MERGE_MODE_MASK))
- {
- /* This just created the purse, actual credit to
- the reserve will be done in handle_account_merged() */
- return GNUNET_OK;
- }
- if ( (NULL != deposit->exchange_base_url) &&
- (0 != strcmp (deposit->exchange_base_url,
- TALER_ARL_exchange_url)) )
- {
- /* credited reserve is at another exchange, do NOT credit here! */
- return GNUNET_OK;
- }
-
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if ( (-1 != TALER_amount_cmp (&new_balance,
- purse_total)) &&
- (-1 == TALER_amount_cmp (auditor_balance,
- purse_total)) )
- {
- /* new balance at or above purse_total
- (and previous balance was below); thus
- credit reserve with purse value! */
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- purse_total);
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about purse
- * merges that have been made, with
- * the goal of auditing the purse merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param partner_base_url where is the reserve, NULL for this exchange
- * @param amount total amount expected in the purse
- * @param balance current balance in the purse (according to the auditor)
- * @param flags purse flags
- * @param merge_pub merge capability key
- * @param reserve_pub reserve the merge affects
- * @param merge_sig signature affirming the merge
- * @param purse_pub purse key
- * @param merge_timestamp when did the merge happen
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_purse_merged (
- void *cls,
- uint64_t rowid,
- const char *partner_base_url,
- const struct TALER_Amount *amount,
- const struct TALER_Amount *balance,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp merge_timestamp)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
- char *reserve_url;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_purse_merges_serial_id);
- ppr.last_purse_merges_serial_id = rowid + 1;
- reserve_url
- = TALER_reserve_make_payto (NULL == partner_base_url
- ? TALER_ARL_exchange_url
- : partner_base_url,
- reserve_pub);
- if (GNUNET_OK !=
- TALER_wallet_purse_merge_verify (reserve_url,
- merge_timestamp,
- purse_pub,
- merge_pub,
- merge_sig))
- {
- GNUNET_free (reserve_url);
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "merge-purse"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- amount),
- GNUNET_JSON_pack_data_auto ("key_pub",
- merge_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- amount);
- return GNUNET_OK;
- }
- GNUNET_free (reserve_url);
- if (TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE ==
- (flags & TALER_WAMF_MERGE_MODE_MASK))
- {
- /* This just created the purse, actual credit to
- the reserve will be done in handle_purse_deposits() */
- return GNUNET_OK;
- }
- if ( (NULL != partner_base_url) &&
- (0 != strcmp (partner_base_url,
- TALER_ARL_exchange_url)) )
- {
- /* credited reserve is at another exchange, do NOT credit here! */
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if (-1 == TALER_amount_cmp (balance,
- amount))
- {
- struct TALER_Amount loss;
-
- TALER_ARL_amount_subtract (&loss,
- amount,
- balance);
- /* illegal merge, balance is still below total purse value */
- TALER_ARL_report (report_purse_balance_insufficient_inconsistencies,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "merge-purse"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- &loss),
- GNUNET_JSON_pack_data_auto ("purse_pub",
- purse_pub)));
- TALER_ARL_amount_add (&total_balance_insufficient_loss,
- &total_balance_insufficient_loss,
- &loss);
- return GNUNET_OK;
- }
- TALER_ARL_amount_add (&rs->total_in,
- &rs->total_in,
- amount);
- // rs->a_expiration_date = FIXME: do we care? If so, set to what (so that the auditor no longer complains about the reserve not being closed)
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about
- * account merge requests that have been made, with
- * the goal of auditing the account merge execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param reserve_pub reserve affected by the merge
- * @param purse_pub purse being merged
- * @param h_contract_terms hash over contract of the purse
- * @param purse_expiration when would the purse expire
- * @param amount total amount in the purse
- * @param min_age minimum age of all coins deposited into the purse
- * @param flags how was the purse created
- * @param purse_fee if a purse fee was paid, how high is it
- * @param merge_timestamp when was the merge approved
- * @param reserve_sig signature by reserve approving the merge
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_account_merged (
- void *cls,
- uint64_t rowid,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_Amount *amount,
- uint32_t min_age,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *purse_fee,
- struct GNUNET_TIME_Timestamp merge_timestamp,
- const struct TALER_ReserveSignatureP *reserve_sig)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_account_merges_serial_id);
- ppr.last_account_merges_serial_id = rowid + 1;
- if (GNUNET_OK !=
- TALER_wallet_account_merge_verify (merge_timestamp,
- purse_pub,
- purse_expiration,
- h_contract_terms,
- amount,
- purse_fee,
- min_age,
- flags,
- reserve_pub,
- reserve_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "account-merge"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- purse_fee),
- GNUNET_JSON_pack_data_auto ("key_pub",
- reserve_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- purse_fee);
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- TALER_ARL_amount_add (&total_purse_fee_income,
- &total_purse_fee_income,
- purse_fee);
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- purse_fee);
- return GNUNET_OK;
-}
-
-
-/**
- * Function called with details about
- * history requests that have been made, with
- * the goal of auditing the history request execution.
- *
- * @param cls closure
- * @param rowid unique serial ID for the deposit in our DB
- * @param history_fee fee paid for the request
- * @param ts timestamp of the request
- * @param reserve_pub reserve history was requested for
- * @param reserve_sig signature approving the @a history_fee
- * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
- */
-static enum GNUNET_GenericReturnValue
-handle_history_request (
- void *cls,
- uint64_t rowid,
- const struct TALER_Amount *history_fee,
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig)
-{
- struct ReserveContext *rc = cls;
- struct ReserveSummary *rs;
-
- /* should be monotonically increasing */
- GNUNET_assert (rowid >= ppr.last_history_requests_serial_id);
- ppr.last_history_requests_serial_id = rowid + 1;
- if (GNUNET_OK !=
- TALER_wallet_reserve_history_verify (ts,
- history_fee,
- reserve_pub,
- reserve_sig))
- {
- TALER_ARL_report (report_bad_sig_losses,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("operation",
- "account-history"),
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("loss",
- history_fee),
- GNUNET_JSON_pack_data_auto ("key_pub",
- reserve_pub)));
- TALER_ARL_amount_add (&total_bad_sig_loss,
- &total_bad_sig_loss,
- history_fee);
- return GNUNET_OK;
- }
- rs = setup_reserve (rc,
- reserve_pub);
- if (NULL == rs)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- TALER_ARL_amount_add (&total_history_fee_income,
- &total_history_fee_income,
- history_fee);
- TALER_ARL_amount_add (&rs->total_out,
- &rs->total_out,
- history_fee);
- return GNUNET_OK;
-}
-
-
-/**
* Analyze reserves for being well-formed.
*
* @param cls NULL
@@ -1691,9 +1606,17 @@ analyze_reserves (void *cls)
(void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Analyzing reserves\n");
- qsp = TALER_ARL_adb->get_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ qsp = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (reserves_reserve_in_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_out_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_recoup_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_open_serial_id),
+ TALER_ARL_GET_PP (reserves_reserve_close_serial_id),
+ TALER_ARL_GET_PP (reserves_purse_decisions_serial_id),
+ TALER_ARL_GET_PP (reserves_account_merges_serial_id),
+ TALER_ARL_GET_PP (reserves_history_requests_serial_id),
+ NULL);
if (0 > qsp)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsp);
@@ -1706,26 +1629,36 @@ analyze_reserves (void *cls)
}
else
{
- ppr_start = ppr;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resuming reserve audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppr.last_reserve_in_serial_id,
- (unsigned long long) ppr.last_reserve_out_serial_id,
- (unsigned long long) ppr.last_reserve_recoup_serial_id,
- (unsigned long long) ppr.last_reserve_close_serial_id,
- (unsigned long long) ppr.last_purse_merges_serial_id,
- (unsigned long long) ppr.last_purse_deposits_serial_id,
- (unsigned long long) ppr.last_account_merges_serial_id,
- (unsigned long long) ppr.last_history_requests_serial_id,
- (unsigned long long) ppr.last_close_requests_serial_id);
+ "Resuming reserve audit at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id));
}
rc.qs = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- qsx = TALER_ARL_adb->get_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ qsx = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (reserves_reserve_total_balance),
+ TALER_ARL_GET_AB (reserves_reserve_loss),
+ TALER_ARL_GET_AB (reserves_withdraw_fee_revenue),
+ TALER_ARL_GET_AB (reserves_close_fee_revenue),
+ TALER_ARL_GET_AB (reserves_purse_fee_revenue),
+ TALER_ARL_GET_AB (reserves_open_fee_revenue),
+ TALER_ARL_GET_AB (reserves_history_fee_revenue),
+ NULL);
if (qsx < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx);
@@ -1735,10 +1668,9 @@ analyze_reserves (void *cls)
GNUNET_NO);
rc.revoked = GNUNET_CONTAINER_multihashmap_create (4,
GNUNET_NO);
-
qs = TALER_ARL_edb->select_reserves_in_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_reserve_in_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_in_serial_id),
&handle_reserve_in,
&rc);
if (qs < 0)
@@ -1748,7 +1680,7 @@ analyze_reserves (void *cls)
}
qs = TALER_ARL_edb->select_withdrawals_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_reserve_out_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_out_serial_id),
&handle_reserve_out,
&rc);
if (qs < 0)
@@ -1758,7 +1690,7 @@ analyze_reserves (void *cls)
}
qs = TALER_ARL_edb->select_recoup_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_reserve_recoup_serial_id,
+ TALER_ARL_USE_PP (reserves_reserve_recoup_serial_id),
&handle_recoup_by_reserve,
&rc);
if (qs < 0)
@@ -1766,72 +1698,51 @@ analyze_reserves (void *cls)
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
- qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
- TALER_ARL_edb->cls,
- ppr.last_reserve_close_serial_id,
- &handle_reserve_closed,
- &rc);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- qs = TALER_ARL_edb->select_purse_deposits_above_serial_id (
- TALER_ARL_edb->cls,
- ppr.last_purse_deposits_serial_id,
- &handle_purse_deposits,
- &rc);
- if (qs < 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- /* Charge purse fee! */
- qs = TALER_ARL_edb->select_account_merges_above_serial_id (
+ qs = TALER_ARL_edb->select_reserve_open_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_account_merges_serial_id,
- &handle_account_merged,
+ TALER_ARL_USE_PP (reserves_reserve_open_serial_id),
+ &handle_reserve_open,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
- /* Credit purse value (if last op)! */
- qs = TALER_ARL_edb->select_purse_merges_above_serial_id (
+ qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_purse_merges_serial_id,
- &handle_purse_merged,
+ TALER_ARL_USE_PP (reserves_reserve_close_serial_id),
+ &handle_reserve_closed,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
- /* Charge history fee! */
- qs = TALER_ARL_edb->select_history_requests_above_serial_id (
- TALER_ARL_edb->cls,
- ppr.last_history_requests_serial_id,
- &handle_history_request,
- &rc);
- if (qs < 0)
+ /* process purse_decisions (to credit reserve) */
+ if (0 >
+ (qs = TALER_ARL_edb->select_purse_decisions_above_serial_id (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (reserves_purse_decisions_serial_id),
+ false, /* only go for merged purses! */
+ &purse_decision_cb,
+ &rc)))
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-#if FIXME
- /* TODO: do we even care about these? */
- qs = TALER_ARL_edb->select_close_requests_above_serial_id (
+ if (0 > rc.qs)
+ return rc.qs;
+ /* Charge purse fee! */
+ qs = TALER_ARL_edb->select_account_merges_above_serial_id (
TALER_ARL_edb->cls,
- ppr.last_close_requests_serial_id,
- &handle_close_request,
+ TALER_ARL_USE_PP (reserves_account_merges_serial_id),
+ &handle_account_merged,
&rc);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
return qs;
}
-#endif
GNUNET_CONTAINER_multihashmap_iterate (rc.reserves,
&verify_reserve_balance,
&rc);
@@ -1839,27 +1750,33 @@ analyze_reserves (void *cls)
GNUNET_CONTAINER_multihashmap_size (rc.reserves));
GNUNET_CONTAINER_multihashmap_destroy (rc.reserves);
GNUNET_CONTAINER_multihashmap_destroy (rc.revoked);
-
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != rc.qs)
return qs;
-
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qsx)
{
- qs = TALER_ARL_adb->insert_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ qs = TALER_ARL_adb->insert_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (reserves_reserve_total_balance),
+ TALER_ARL_SET_AB (reserves_reserve_loss),
+ TALER_ARL_SET_AB (reserves_withdraw_fee_revenue),
+ TALER_ARL_SET_AB (reserves_close_fee_revenue),
+ TALER_ARL_SET_AB (reserves_purse_fee_revenue),
+ TALER_ARL_SET_AB (reserves_open_fee_revenue),
+ TALER_ARL_SET_AB (reserves_history_fee_revenue),
+ NULL);
}
else
{
- qs = TALER_ARL_adb->update_reserve_summary (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &total_escrow_balance,
- &total_withdraw_fee_income,
- &total_purse_fee_income,
- &total_history_fee_income);
+ qs = TALER_ARL_adb->update_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (reserves_reserve_total_balance),
+ TALER_ARL_SET_AB (reserves_reserve_loss),
+ TALER_ARL_SET_AB (reserves_withdraw_fee_revenue),
+ TALER_ARL_SET_AB (reserves_close_fee_revenue),
+ TALER_ARL_SET_AB (reserves_purse_fee_revenue),
+ TALER_ARL_SET_AB (reserves_open_fee_revenue),
+ TALER_ARL_SET_AB (reserves_history_fee_revenue),
+ NULL);
}
if (0 >= qs)
{
@@ -1867,13 +1784,29 @@ analyze_reserves (void *cls)
return qs;
}
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsp)
- qs = TALER_ARL_adb->update_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ qs = TALER_ARL_adb->update_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (reserves_reserve_in_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_out_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_open_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_close_serial_id),
+ TALER_ARL_SET_PP (reserves_purse_decisions_serial_id),
+ TALER_ARL_SET_PP (reserves_account_merges_serial_id),
+ TALER_ARL_SET_PP (reserves_history_requests_serial_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_auditor_progress_reserve (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &ppr);
+ qs = TALER_ARL_adb->insert_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (reserves_reserve_in_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_out_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_recoup_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_open_serial_id),
+ TALER_ARL_SET_PP (reserves_reserve_close_serial_id),
+ TALER_ARL_SET_PP (reserves_purse_decisions_serial_id),
+ TALER_ARL_SET_PP (reserves_account_merges_serial_id),
+ TALER_ARL_SET_PP (reserves_history_requests_serial_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -1882,16 +1815,23 @@ analyze_reserves (void *cls)
return qs;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Concluded reserve audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
- (unsigned long long) ppr.last_reserve_in_serial_id,
- (unsigned long long) ppr.last_reserve_out_serial_id,
- (unsigned long long) ppr.last_reserve_recoup_serial_id,
- (unsigned long long) ppr.last_reserve_close_serial_id,
- (unsigned long long) ppr.last_purse_merges_serial_id,
- (unsigned long long) ppr.last_purse_deposits_serial_id,
- (unsigned long long) ppr.last_account_merges_serial_id,
- (unsigned long long) ppr.last_history_requests_serial_id,
- (unsigned long long) ppr.last_close_requests_serial_id);
+ "Concluded reserve audit step at %llu/%llu/%llu/%llu/%llu/%llu/%llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id),
+ (unsigned long long) TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id));
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
}
@@ -1937,22 +1877,33 @@ run (void *cls,
"Starting audit\n");
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_escrow_balance));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_irregular_recoups));
+ &TALER_ARL_USE_AB (
+ reserves_reserve_loss)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_withdraw_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_withdraw_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_history_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_close_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_purse_fee_income));
+ &TALER_ARL_USE_AB (
+ reserves_purse_fee_revenue)));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_balance_insufficient_loss));
+ &TALER_ARL_USE_AB (
+ reserves_open_fee_revenue)));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (
+ reserves_history_fee_revenue)));
+ // REVIEW:
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_balance_summary_delta_plus));
@@ -1971,6 +1922,7 @@ run (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_bad_sig_loss));
+
GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ()));
GNUNET_assert (NULL !=
@@ -2002,15 +1954,6 @@ run (void *cls,
}
TALER_ARL_done (
GNUNET_JSON_PACK (
- GNUNET_JSON_pack_array_steal (
- "reserve_balance_insufficient_inconsistencies",
- report_reserve_balance_insufficient_inconsistencies),
- GNUNET_JSON_pack_array_steal (
- "purse_balance_insufficient_inconsistencies",
- report_purse_balance_insufficient_inconsistencies),
- /* Tested in test-auditor.sh #3 */
- TALER_JSON_pack_amount ("total_loss_balance_insufficient",
- &total_balance_insufficient_loss),
/* Tested in test-auditor.sh #3 */
GNUNET_JSON_pack_array_steal (
"reserve_balance_summary_wrong_inconsistencies",
@@ -2019,26 +1962,49 @@ run (void *cls,
&total_balance_summary_delta_plus),
TALER_JSON_pack_amount ("total_balance_summary_delta_minus",
&total_balance_summary_delta_minus),
+ /* Tested in test-auditor.sh #21 */
+ TALER_JSON_pack_amount ("total_balance_reserve_not_closed",
+ &total_balance_reserve_not_closed),
+ /* Tested in test-auditor.sh #7 */
+ TALER_JSON_pack_amount ("total_bad_sig_loss",
+ &total_bad_sig_loss),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_plus",
+ &total_arithmetic_delta_plus),
+ TALER_JSON_pack_amount ("total_arithmetic_delta_minus",
+ &total_arithmetic_delta_minus),
+
+ /* Global 'balances' */
TALER_JSON_pack_amount ("total_escrow_balance",
- &total_escrow_balance),
+ &TALER_ARL_USE_AB (
+ reserves_reserve_total_balance)),
+ /* Tested in test-auditor.sh #3 */
+ TALER_JSON_pack_amount ("total_irregular_loss",
+ &TALER_ARL_USE_AB (reserves_reserve_loss)),
TALER_JSON_pack_amount ("total_withdraw_fee_income",
- &total_withdraw_fee_income),
- TALER_JSON_pack_amount ("total_history_fee_income",
- &total_history_fee_income),
+ &TALER_ARL_USE_AB (
+ reserves_withdraw_fee_revenue)),
+ TALER_JSON_pack_amount ("total_close_fee_income",
+ &TALER_ARL_USE_AB (reserves_close_fee_revenue)),
TALER_JSON_pack_amount ("total_purse_fee_income",
- &total_purse_fee_income),
+ &TALER_ARL_USE_AB (reserves_purse_fee_revenue)),
+ TALER_JSON_pack_amount ("total_open_fee_income",
+ &TALER_ARL_USE_AB (reserves_open_fee_revenue)),
+ TALER_JSON_pack_amount ("total_history_fee_income",
+ &TALER_ARL_USE_AB (reserves_history_fee_revenue)),
+
+ /* Detailed report tables */
+ GNUNET_JSON_pack_array_steal (
+ "reserve_balance_insufficient_inconsistencies",
+ report_reserve_balance_insufficient_inconsistencies),
+ GNUNET_JSON_pack_array_steal (
+ "purse_balance_insufficient_inconsistencies",
+ report_purse_balance_insufficient_inconsistencies),
/* Tested in test-auditor.sh #21 */
GNUNET_JSON_pack_array_steal ("reserve_not_closed_inconsistencies",
report_reserve_not_closed_inconsistencies),
- /* Tested in test-auditor.sh #21 */
- TALER_JSON_pack_amount ("total_balance_reserve_not_closed",
- &total_balance_reserve_not_closed),
/* Tested in test-auditor.sh #7 */
GNUNET_JSON_pack_array_steal ("bad_sig_losses",
report_bad_sig_losses),
- /* Tested in test-auditor.sh #7 */
- TALER_JSON_pack_amount ("total_bad_sig_loss",
- &total_bad_sig_loss),
/* Tested in test-revocation.sh #4 */
GNUNET_JSON_pack_array_steal ("row_inconsistencies",
report_row_inconsistencies),
@@ -2048,42 +2014,52 @@ run (void *cls,
denomination_key_validity_withdraw_inconsistencies),
GNUNET_JSON_pack_array_steal ("amount_arithmetic_inconsistencies",
report_amount_arithmetic_inconsistencies),
- TALER_JSON_pack_amount ("total_arithmetic_delta_plus",
- &total_arithmetic_delta_plus),
- TALER_JSON_pack_amount ("total_arithmetic_delta_minus",
- &total_arithmetic_delta_minus),
+
+ /* Information about audited range ... */
TALER_JSON_pack_time_abs_human ("auditor_start_time",
start_time),
TALER_JSON_pack_time_abs_human ("auditor_end_time",
GNUNET_TIME_absolute_get ()),
- TALER_JSON_pack_amount ("total_irregular_recoups",
- &total_irregular_recoups),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_in_serial_id",
- ppr_start.last_reserve_in_serial_id),
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_out_serial_id",
- ppr_start.last_reserve_out_serial_id),
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_recoup_serial_id",
- ppr_start.last_reserve_recoup_serial_id),
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_reserve_open_serial_id",
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("start_ppr_reserve_close_serial_id",
- ppr_start.last_reserve_close_serial_id),
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_purse_decisions_serial_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_account_merges_serial_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("start_ppr_history_requests_serial_id",
+ 0 /* no longer supported */),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_in_serial_id",
- ppr.last_reserve_in_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_in_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_out_serial_id",
- ppr.last_reserve_out_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_out_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_recoup_serial_id",
- ppr.last_reserve_recoup_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_recoup_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppr_reserve_open_serial_id",
+ TALER_ARL_USE_PP (
+ reserves_reserve_open_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_reserve_close_serial_id",
- ppr.last_reserve_close_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_purse_merges_serial_id",
- ppr.last_purse_merges_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_purse_deposits_serial_id",
- ppr.last_purse_deposits_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_reserve_close_serial_id)),
+ GNUNET_JSON_pack_uint64 ("end_ppr_purse_decisions_serial_id",
+ TALER_ARL_USE_PP (
+ reserves_purse_decisions_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_account_merges_serial_id",
- ppr.last_account_merges_serial_id),
+ TALER_ARL_USE_PP (
+ reserves_account_merges_serial_id)),
GNUNET_JSON_pack_uint64 ("end_ppr_history_requests_serial_id",
- ppr.last_history_requests_serial_id),
- GNUNET_JSON_pack_uint64 ("end_ppr_close_requests_serial_id",
- ppr.last_close_requests_serial_id)));
+ TALER_ARL_USE_PP (
+ reserves_history_requests_serial_id))));
}
@@ -2103,11 +2079,10 @@ main (int argc,
"internal",
"perform checks only applicable for exchange-internal audits",
&internal_checks),
- GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &TALER_ARL_master_pub),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_OPTION_END
diff --git a/src/auditor/taler-helper-auditor-wire.c b/src/auditor/taler-helper-auditor-wire.c
index 0de873f51..d48ac1f18 100644
--- a/src/auditor/taler-helper-auditor-wire.c
+++ b/src/auditor/taler-helper-auditor-wire.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017-2021 Taler Systems SA
+ Copyright (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -53,6 +53,20 @@
/**
+ * Run in test mode. Exit when idle instead of
+ * going to sleep and waiting for more work.
+ *
+ * FIXME: not yet implemented!
+ */
+static int test_mode;
+
+struct TALER_AUDITORDB_WireAccountProgressPoint
+{
+ uint64_t last_reserve_in_serial_id;
+ uint64_t last_wire_out_serial_id;
+};
+
+/**
* Information we keep for each supported account.
*/
struct WireAccount
@@ -93,14 +107,34 @@ struct WireAccount
struct TALER_AUDITORDB_WireAccountProgressPoint start_pp;
/**
- * Where we are in the inbound (CREDIT) transaction history.
+ * Where we are in the inbound transaction history.
+ */
+ uint64_t wire_off_in;
+
+ /**
+ * Where we are in the outbound transaction history.
*/
- uint64_t in_wire_off;
+ uint64_t wire_off_out;
/**
- * Where we are in the inbound (DEBIT) transaction history.
+ * Label under which we store our pp's reserve_in_serial_id.
*/
- uint64_t out_wire_off;
+ char *label_reserve_in_serial_id;
+
+ /**
+ * Label under which we store our pp's reserve_in_serial_id.
+ */
+ char *label_wire_out_serial_id;
+
+ /**
+ * Label under which we store our wire_off_in.
+ */
+ char *label_wire_off_in;
+
+ /**
+ * Label under which we store our wire_off_out.
+ */
+ char *label_wire_off_out;
/**
* Return value when we got this account's progress point.
@@ -183,20 +217,17 @@ static enum GNUNET_DB_QueryStatus qsx_gwap;
/**
* Last reserve_in / wire_out serial IDs seen.
*/
-static struct TALER_AUDITORDB_WireProgressPoint pp;
-
-/**
- * Last reserve_in / wire_out serial IDs seen.
- */
-static struct TALER_AUDITORDB_WireProgressPoint start_pp;
+static TALER_ARL_DEF_PP (wire_reserve_close_id);
+static TALER_ARL_DEF_PP (wire_batch_deposit_id);
+static TALER_ARL_DEF_PP (wire_aggregation_id);
/**
- * Array of reports about row inconsitencies in wire_out table.
+ * Array of reports about row inconsistencies in wire_out table.
*/
static json_t *report_wire_out_inconsistencies;
/**
- * Array of reports about row inconsitencies in reserves_in table.
+ * Array of reports about row inconsistencies in reserves_in table.
*/
static json_t *report_reserve_in_inconsistencies;
@@ -204,7 +235,7 @@ static json_t *report_reserve_in_inconsistencies;
* Array of reports about wrong bank account being recorded for
* incoming wire transfers.
*/
-static json_t *report_missattribution_in_inconsistencies;
+static json_t *report_misattribution_in_inconsistencies;
/**
* Array of reports about row inconsistencies.
@@ -228,6 +259,16 @@ static json_t *report_row_minor_inconsistencies;
static json_t *report_lags;
/**
+ * Array of reports about lagging transactions from deposits due to missing KYC.
+ */
+static json_t *report_kyc_lags;
+
+/**
+ * Array of reports about lagging transactions from deposits due to pending or frozen AML decisions.
+ */
+static json_t *report_aml_lags;
+
+/**
* Array of reports about lagging transactions from reserve closures.
*/
static json_t *report_closure_lags;
@@ -267,7 +308,7 @@ static struct TALER_Amount total_bad_amount_in_minus;
* for incoming funds and may thus wire funds to the wrong
* destination when closing the reserve.
*/
-static struct TALER_Amount total_missattribution_in;
+static struct TALER_Amount total_misattribution_in;
/**
* Total amount which the exchange did not transfer in time.
@@ -285,6 +326,36 @@ static struct TALER_Amount total_closure_amount_lag;
static struct TALER_Amount total_wire_format_amount;
/**
+ * Total amount credited to exchange accounts.
+ */
+static struct TALER_Amount total_wire_in;
+
+/**
+ * Total amount debited to exchange accounts.
+ */
+static struct TALER_Amount total_wire_out;
+
+/**
+ * Total amount of profits drained.
+ */
+static TALER_ARL_DEF_AB (total_drained);
+
+/**
+ * Final balance at the end of this iteration.
+ */
+static TALER_ARL_DEF_AB (final_balance);
+
+/**
+ * Starting balance at the beginning of this iteration.
+ */
+static struct TALER_Amount start_balance;
+
+/**
+ * True if #start_balance was initialized.
+ */
+static bool had_start_balance;
+
+/**
* Amount of zero in our currency.
*/
static struct TALER_Amount zero;
@@ -367,7 +438,7 @@ struct ReserveOutInfo
* @param value the `struct ReserveInInfo` to free
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
free_rii (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -392,7 +463,7 @@ free_rii (void *cls,
* @param value the `struct ReserveOutInfo` to free
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
free_roi (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -417,7 +488,7 @@ free_roi (void *cls,
* @param value the `struct ReserveClosure` to free
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
free_rc (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -469,11 +540,11 @@ do_shutdown (void *cls)
TALER_JSON_pack_amount ("total_wire_in_delta_minus",
&total_bad_amount_in_minus),
/* Tested in test-auditor.sh #9 */
- GNUNET_JSON_pack_array_steal ("missattribution_in_inconsistencies",
- report_missattribution_in_inconsistencies),
+ GNUNET_JSON_pack_array_steal ("misattribution_in_inconsistencies",
+ report_misattribution_in_inconsistencies),
/* Tested in test-auditor.sh #9 */
- TALER_JSON_pack_amount ("total_missattribution_in",
- &total_missattribution_in),
+ TALER_JSON_pack_amount ("total_misattribution_in",
+ &total_misattribution_in),
GNUNET_JSON_pack_array_steal ("row_inconsistencies",
report_row_inconsistencies),
/* Tested in test-auditor.sh #10/#17 */
@@ -485,12 +556,24 @@ do_shutdown (void *cls)
/* Tested in test-auditor.sh #19 */
GNUNET_JSON_pack_array_steal ("wire_format_inconsistencies",
report_wire_format_inconsistencies),
+ TALER_JSON_pack_amount ("total_wire_in",
+ &total_wire_in),
+ TALER_JSON_pack_amount ("total_wire_out",
+ &total_wire_out),
+ TALER_JSON_pack_amount ("total_drained",
+ &TALER_ARL_USE_AB (total_drained)),
+ TALER_JSON_pack_amount ("final_balance",
+ &TALER_ARL_USE_AB (final_balance)),
/* Tested in test-auditor.sh #1 */
TALER_JSON_pack_amount ("total_amount_lag",
&total_amount_lag),
/* Tested in test-auditor.sh #1 */
GNUNET_JSON_pack_array_steal ("lag_details",
report_lags),
+ GNUNET_JSON_pack_array_steal ("lag_aml_details",
+ report_aml_lags),
+ GNUNET_JSON_pack_array_steal ("lag_kyc_details",
+ report_kyc_lags),
/* Tested in test-auditor.sh #22 */
TALER_JSON_pack_amount ("total_closure_amount_lag",
&total_closure_amount_lag),
@@ -501,22 +584,28 @@ do_shutdown (void *cls)
start_time),
TALER_JSON_pack_time_abs_human ("wire_auditor_end_time",
GNUNET_TIME_absolute_get ()),
- GNUNET_JSON_pack_uint64 ("start_pp_reserve_close_uuid",
- start_pp.last_reserve_close_uuid),
- GNUNET_JSON_pack_uint64 ("end_pp_reserve_close_uuid",
- pp.last_reserve_close_uuid),
- TALER_JSON_pack_time_abs_human ("start_pp_last_timestamp",
- start_pp.last_timestamp.abs_time),
- TALER_JSON_pack_time_abs_human ("end_pp_last_timestamp",
- pp.last_timestamp.abs_time),
+ GNUNET_JSON_pack_uint64 ("start_pp_reserve_close_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("end_pp_reserve_close_id",
+ TALER_ARL_USE_PP (wire_reserve_close_id)),
+ GNUNET_JSON_pack_uint64 ("start_pp_last_batch_deposit_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("end_pp_last_batch_deposit_id",
+ TALER_ARL_USE_PP (wire_batch_deposit_id)),
+ GNUNET_JSON_pack_uint64 ("start_pp_last_aggregation_serial_id",
+ 0 /* no longer supported */),
+ GNUNET_JSON_pack_uint64 ("end_pp_last_aggregation_serial_id",
+ TALER_ARL_USE_PP (wire_aggregation_id)),
GNUNET_JSON_pack_array_steal ("account_progress",
report_account_progress)));
report_wire_out_inconsistencies = NULL;
report_reserve_in_inconsistencies = NULL;
report_row_inconsistencies = NULL;
report_row_minor_inconsistencies = NULL;
- report_missattribution_in_inconsistencies = NULL;
+ report_misattribution_in_inconsistencies = NULL;
report_lags = NULL;
+ report_kyc_lags = NULL;
+ report_aml_lags = NULL;
report_closure_lags = NULL;
report_account_progress = NULL;
report_wire_format_inconsistencies = NULL;
@@ -564,6 +653,10 @@ do_shutdown (void *cls)
GNUNET_CONTAINER_DLL_remove (wa_head,
wa_tail,
wa);
+ GNUNET_free (wa->label_reserve_in_serial_id);
+ GNUNET_free (wa->label_wire_out_serial_id);
+ GNUNET_free (wa->label_wire_off_in);
+ GNUNET_free (wa->label_wire_off_out);
GNUNET_free (wa);
}
if (NULL != ctx)
@@ -591,7 +684,7 @@ do_shutdown (void *cls)
* @param value the `struct ReserveClosure` to free
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
check_pending_rc (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -618,8 +711,8 @@ check_pending_rc (void *cls,
&rc->wtid),
GNUNET_JSON_pack_string ("account",
rc->receiver_account)));
- pp.last_reserve_close_uuid
- = GNUNET_MIN (pp.last_reserve_close_uuid,
+ TALER_ARL_USE_PP (wire_reserve_close_id)
+ = GNUNET_MIN (TALER_ARL_USE_PP (wire_reserve_close_id),
rc->rowid);
return GNUNET_OK;
}
@@ -641,12 +734,12 @@ hash_rc (const char *receiver_account,
size_t slen = strlen (receiver_account);
char buf[sizeof (struct TALER_WireTransferIdentifierRawP) + slen];
- memcpy (buf,
- wtid,
- sizeof (*wtid));
- memcpy (&buf[sizeof (*wtid)],
- receiver_account,
- slen);
+ GNUNET_memcpy (buf,
+ wtid,
+ sizeof (*wtid));
+ GNUNET_memcpy (&buf[sizeof (*wtid)],
+ receiver_account,
+ slen);
GNUNET_CRYPTO_hash (buf,
sizeof (buf),
key);
@@ -662,6 +755,42 @@ hash_rc (const char *receiver_account,
static enum GNUNET_DB_QueryStatus
commit (enum GNUNET_DB_QueryStatus qs)
{
+ if (qs >= 0)
+ {
+ if (had_start_balance)
+ {
+ struct TALER_Amount sum;
+
+ TALER_ARL_amount_add (&sum,
+ &total_wire_in,
+ &start_balance);
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (final_balance),
+ &sum,
+ &total_wire_out);
+ qs = TALER_ARL_adb->update_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (total_drained),
+ TALER_ARL_SET_AB (final_balance),
+ NULL);
+ }
+ else
+ {
+ TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (final_balance),
+ &total_wire_in,
+ &total_wire_out);
+ qs = TALER_ARL_adb->insert_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_AB (total_drained),
+ TALER_ARL_SET_AB (final_balance),
+ NULL);
+ }
+ }
+ else
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (final_balance)));
+ }
if (0 > qs)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -690,26 +819,33 @@ commit (enum GNUNET_DB_QueryStatus qs)
GNUNET_JSON_pack_uint64 ("end_reserve_in",
wa->pp.last_reserve_in_serial_id),
GNUNET_JSON_pack_uint64 ("start_wire_out",
- wa->start_pp.
- last_wire_out_serial_id),
+ wa->start_pp.last_wire_out_serial_id),
GNUNET_JSON_pack_uint64 ("end_wire_out",
wa->pp.last_wire_out_serial_id))));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == wa->qsx)
- qs = TALER_ARL_adb->update_wire_auditor_account_progress (
+ qs = TALER_ARL_adb->update_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- wa->ai->section_name,
- &wa->pp,
- wa->in_wire_off,
- wa->out_wire_off);
+ wa->label_reserve_in_serial_id,
+ wa->pp.last_reserve_in_serial_id,
+ wa->label_wire_out_serial_id,
+ wa->pp.last_wire_out_serial_id,
+ wa->label_wire_off_in,
+ wa->wire_off_in,
+ wa->label_wire_off_out,
+ wa->wire_off_out,
+ NULL);
else
- qs = TALER_ARL_adb->insert_wire_auditor_account_progress (
+ qs = TALER_ARL_adb->insert_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- wa->ai->section_name,
- &wa->pp,
- wa->in_wire_off,
- wa->out_wire_off);
+ wa->label_reserve_in_serial_id,
+ wa->pp.last_reserve_in_serial_id,
+ wa->label_wire_out_serial_id,
+ wa->pp.last_wire_out_serial_id,
+ wa->label_wire_off_in,
+ wa->wire_off_in,
+ wa->label_wire_off_out,
+ wa->wire_off_out,
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -722,13 +858,19 @@ commit (enum GNUNET_DB_QueryStatus qs)
&check_pending_rc,
NULL);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qsx_gwap)
- qs = TALER_ARL_adb->update_wire_auditor_progress (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &pp);
+ qs = TALER_ARL_adb->update_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (wire_reserve_close_id),
+ TALER_ARL_SET_PP (wire_batch_deposit_id),
+ TALER_ARL_SET_PP (wire_aggregation_id),
+ NULL);
else
- qs = TALER_ARL_adb->insert_wire_auditor_progress (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &pp);
+ qs = TALER_ARL_adb->insert_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_SET_PP (wire_reserve_close_id),
+ TALER_ARL_SET_PP (wire_batch_deposit_id),
+ TALER_ARL_SET_PP (wire_aggregation_id),
+ NULL);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -737,8 +879,9 @@ commit (enum GNUNET_DB_QueryStatus qs)
return qs;
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Concluded audit step at %s\n",
- GNUNET_TIME_timestamp2s (pp.last_timestamp));
+ "Concluded audit step at %llu/%llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (wire_aggregation_id),
+ (unsigned long long) TALER_ARL_USE_PP (wire_batch_deposit_id));
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{
@@ -775,59 +918,341 @@ commit (enum GNUNET_DB_QueryStatus qs)
/* ***************************** Analyze required transfers ************************ */
/**
- * Function called on deposits that are past their due date
- * and have not yet seen a wire transfer.
+ * Closure for import_wire_missing_cb().
+ */
+struct ImportMissingWireContext
+{
+ /**
+ * Set to maximum row ID encountered.
+ */
+ uint64_t max_batch_deposit_uuid;
+
+ /**
+ * Set to database errors in callback.
+ */
+ enum GNUNET_DB_QueryStatus err;
+};
+
+
+/**
+ * Function called on deposits that need to be checked for their
+ * wire transfer.
*
- * @param cls closure
- * @param rowid deposit table row of the coin's deposit
- * @param coin_pub public key of the coin
- * @param amount value of the deposit, including fee
- * @param payto_uri where should the funds be wired
- * @param deadline what was the requested wire transfer deadline
- * @param done did the exchange claim that it made a transfer?
- * NOTE: only valid in internal audit mode!
+ * @param cls closure, points to a `struct ImportMissingWireContext`
+ * @param batch_deposit_serial_id serial of the entry in the batch deposits table
+ * @param total_amount value of the missing deposits, including fee
+ * @param wire_target_h_payto where should the funds be wired
+ * @param deadline what was the earliest requested wire transfer deadline
*/
static void
-wire_missing_cb (void *cls,
- uint64_t rowid,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *amount,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp deadline,
- bool done)
+import_wire_missing_cb (void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline)
{
- json_t *rep;
+ struct ImportMissingWireContext *wc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ if (wc->err < 0)
+ return; /* already failed */
+ GNUNET_assert (batch_deposit_serial_id > wc->max_batch_deposit_uuid);
+ wc->max_batch_deposit_uuid = batch_deposit_serial_id;
+ qs = TALER_ARL_adb->insert_pending_deposit (
+ TALER_ARL_adb->cls,
+ batch_deposit_serial_id,
+ wire_target_h_payto,
+ total_amount,
+ deadline);
+ if (qs < 0)
+ wc->err = qs;
+}
+
+
+/**
+ * Information about a delayed wire transfer and the possible
+ * reasons for the delay.
+ */
+struct ReasonDetail
+{
+ /**
+ * Total amount that should have been transferred.
+ */
+ struct TALER_Amount total_amount;
+
+ /**
+ * Earliest deadline for an expected transfer to the account.
+ */
+ struct GNUNET_TIME_Timestamp deadline;
+
+ /**
+ * Target account, NULL if even that is not known (due to
+ * exchange lacking required entry in wire_targets table).
+ */
+ char *payto_uri;
+
+ /**
+ * Reasons due to pending KYC requests.
+ */
+ char *kyc_pending;
+
+ /**
+ * AML decision state for the target account.
+ */
+ enum TALER_AmlDecisionState status;
+
+ /**
+ * Current AML threshold for the account, may be an invalid account if the
+ * default threshold applies.
+ */
+ struct TALER_Amount aml_limit;
+};
+
+/**
+ * Closure for report_wire_missing_cb().
+ */
+struct ReportMissingWireContext
+{
+ /**
+ * Map from wire_target_h_payto to `struct ReasonDetail`.
+ */
+ struct GNUNET_CONTAINER_MultiShortmap *map;
+
+ /**
+ * Set to database errors in callback.
+ */
+ enum GNUNET_DB_QueryStatus err;
+};
+
+
+/**
+ * Closure for #clear_finished_transfer_cb().
+ */
+struct AggregationContext
+{
+ /**
+ * Set to maximum row ID encountered.
+ */
+ uint64_t max_aggregation_serial;
+
+ /**
+ * Set to database errors in callback.
+ */
+ enum GNUNET_DB_QueryStatus err;
+};
+
+
+/**
+ * Free memory allocated in @a value.
+ *
+ * @param cls unused
+ * @param key unused
+ * @param value must be a `struct ReasonDetail`
+ * @return #GNUNET_YES if we should continue to
+ * iterate,
+ * #GNUNET_NO if not.
+ */
+static enum GNUNET_GenericReturnValue
+free_report_entry (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value)
+{
+ struct ReasonDetail *rd = value;
+
+ GNUNET_free (rd->kyc_pending);
+ GNUNET_free (rd->payto_uri);
+ GNUNET_free (rd);
+ return GNUNET_YES;
+}
+
+
+/**
+ * We had an entry in our map of wire transfers that
+ * should have been performed. Generate report.
+ *
+ * @param cls unused
+ * @param key unused
+ * @param value must be a `struct ReasonDetail`
+ * @return #GNUNET_YES if we should continue to
+ * iterate,
+ * #GNUNET_NO if not.
+ */
+static enum GNUNET_GenericReturnValue
+generate_report (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *value)
+{
+ struct ReasonDetail *rd = value;
- (void) cls;
- TALER_ARL_amount_add (&total_amount_lag,
- &total_amount_lag,
- amount);
/* For now, we simplify and only check that the
amount was tiny */
- if (0 > TALER_amount_cmp (amount,
+ if (0 > TALER_amount_cmp (&rd->total_amount,
&tiny_amount))
- return; /* acceptable, amount was tiny */
- rep = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_uint64 ("row",
- rowid),
- TALER_JSON_pack_amount ("amount",
- amount),
- TALER_JSON_pack_time_abs_human ("deadline",
- deadline.abs_time),
- GNUNET_JSON_pack_data_auto ("coin_pub",
- coin_pub),
- GNUNET_JSON_pack_string ("account",
- payto_uri));
- if (internal_checks)
+ return free_report_entry (cls,
+ key,
+ value); /* acceptable, amount was tiny */
+ // TODO: maybe split total_amount_lag up by category below?
+ TALER_ARL_amount_add (&total_amount_lag,
+ &total_amount_lag,
+ &rd->total_amount);
+ if (NULL != rd->kyc_pending)
+ {
+ json_t *rep;
+
+ rep = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("total_amount",
+ &rd->total_amount),
+ TALER_JSON_pack_time_abs_human ("deadline",
+ rd->deadline.abs_time),
+ GNUNET_JSON_pack_string ("kyc_pending",
+ rd->kyc_pending),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("account",
+ rd->payto_uri)));
+ TALER_ARL_report (report_kyc_lags,
+ rep);
+ }
+ else if (TALER_AML_NORMAL != rd->status)
+ {
+ const char *sstatus = "<undefined>";
+ json_t *rep;
+
+ switch (rd->status)
+ {
+ case TALER_AML_NORMAL:
+ GNUNET_assert (0);
+ break;
+ case TALER_AML_PENDING:
+ sstatus = "pending";
+ break;
+ case TALER_AML_FROZEN:
+ sstatus = "frozen";
+ break;
+ }
+ rep = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("total_amount",
+ &rd->total_amount),
+ GNUNET_JSON_pack_allow_null (
+ TALER_JSON_pack_amount ("aml_limit",
+ TALER_amount_is_valid (&rd->aml_limit)
+ ? &rd->aml_limit
+ : NULL)),
+ TALER_JSON_pack_time_abs_human ("deadline",
+ rd->deadline.abs_time),
+ GNUNET_JSON_pack_string ("aml_status",
+ sstatus),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("account",
+ rd->payto_uri)));
+ TALER_ARL_report (report_aml_lags,
+ rep);
+ }
+ else
{
- /* the 'done' bit is only useful in 'internal' mode */
- GNUNET_assert (0 ==
- json_object_set (rep,
- "claimed_done",
- json_string ((done) ? "yes" : "no")));
+ json_t *rep;
+
+ rep = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("total_amount",
+ &rd->total_amount),
+ TALER_JSON_pack_time_abs_human ("deadline",
+ rd->deadline.abs_time),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("account",
+ rd->payto_uri)));
+ TALER_ARL_report (report_lags,
+ rep);
}
- TALER_ARL_report (report_lags,
- rep);
+
+ return free_report_entry (cls,
+ key,
+ value);
+}
+
+
+/**
+ * Function called on deposits that are past their due date
+ * and have not yet seen a wire transfer.
+ *
+ * @param cls closure, points to a `struct ReportMissingWireContext`
+ * @param batch_deposit_serial_id row in the database for which the wire transfer is missing
+ * @param total_amount value of the missing deposits, including fee
+ * @param wire_target_h_payto hash of payto-URI where the funds should have been wired
+ * @param deadline what was the earliest requested wire transfer deadline
+ */
+static void
+report_wire_missing_cb (void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline)
+{
+ struct ReportMissingWireContext *rc = cls;
+ struct ReasonDetail *rd;
+
+ rd = GNUNET_CONTAINER_multishortmap_get (rc->map,
+ &wire_target_h_payto->hash);
+ if (NULL == rd)
+ {
+ rd = GNUNET_new (struct ReasonDetail);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multishortmap_put (
+ rc->map,
+ &wire_target_h_payto->hash,
+ rd,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ rc->err = TALER_ARL_edb->select_justification_for_missing_wire (
+ TALER_ARL_edb->cls,
+ wire_target_h_payto,
+ &rd->payto_uri,
+ &rd->kyc_pending,
+ &rd->status,
+ &rd->aml_limit);
+ rd->total_amount = *total_amount;
+ rd->deadline = deadline;
+ }
+ else
+ {
+ TALER_ARL_amount_add (&rd->total_amount,
+ &rd->total_amount,
+ total_amount);
+ rd->deadline = GNUNET_TIME_timestamp_min (rd->deadline,
+ deadline);
+ }
+}
+
+
+/**
+ * Function called on aggregations that were done for
+ * a (batch) deposit.
+ *
+ * @param cls closure
+ * @param tracking_serial_id where in the table are we
+ * @param batch_deposit_serial_id which batch deposit was aggregated
+ */
+static void
+clear_finished_transfer_cb (
+ void *cls,
+ uint64_t tracking_serial_id,
+ uint64_t batch_deposit_serial_id)
+{
+ struct AggregationContext *ac = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ if (0 > ac->err)
+ return; /* already failed */
+ GNUNET_assert (ac->max_aggregation_serial < tracking_serial_id);
+ ac->max_aggregation_serial = tracking_serial_id;
+ qs = TALER_ARL_adb->delete_pending_deposit (
+ TALER_ARL_adb->cls,
+ batch_deposit_serial_id);
+ if (0 == qs)
+ {
+ /* Aggregated something twice or other error, report! */
+ GNUNET_break (0);
+ // FIXME: report more nicely!
+ }
+ if (0 > qs)
+ ac->err = qs;
}
@@ -838,30 +1263,78 @@ wire_missing_cb (void *cls,
static void
check_for_required_transfers (void)
{
- struct GNUNET_TIME_Timestamp next_timestamp;
+ struct ImportMissingWireContext wc = {
+ .max_batch_deposit_uuid = TALER_ARL_USE_PP (wire_batch_deposit_id),
+ .err = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+ };
+ struct GNUNET_TIME_Absolute deadline;
enum GNUNET_DB_QueryStatus qs;
+ struct ReportMissingWireContext rc = {
+ .err = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+ };
+ struct AggregationContext ac = {
+ .max_aggregation_serial = TALER_ARL_USE_PP (wire_aggregation_id),
+ .err = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+ };
+ qs = TALER_ARL_edb->select_batch_deposits_missing_wire (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (wire_batch_deposit_id),
+ &import_wire_missing_cb,
+ &wc);
+ if ( (0 > qs) || (0 > wc.err) )
+ {
+ GNUNET_break (0);
+ GNUNET_break ( (GNUNET_DB_STATUS_SOFT_ERROR == qs) ||
+ (GNUNET_DB_STATUS_SOFT_ERROR == wc.err) );
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ TALER_ARL_USE_PP (wire_batch_deposit_id) = wc.max_batch_deposit_uuid;
+ qs = TALER_ARL_edb->select_aggregations_above_serial (
+ TALER_ARL_edb->cls,
+ TALER_ARL_USE_PP (wire_aggregation_id),
+ &clear_finished_transfer_cb,
+ &ac);
+ if ( (0 > qs) || (0 > ac.err) )
+ {
+ GNUNET_break (0);
+ GNUNET_break ( (GNUNET_DB_STATUS_SOFT_ERROR == qs) ||
+ (GNUNET_DB_STATUS_SOFT_ERROR == ac.err) );
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ TALER_ARL_USE_PP (wire_aggregation_id) = ac.max_aggregation_serial;
/* Subtract #GRACE_PERIOD, so we can be a bit behind in processing
without immediately raising undue concern */
- next_timestamp = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
- GRACE_PERIOD));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Analyzing exchange's unfinished deposits (deadline: %s)\n",
- GNUNET_TIME_timestamp2s (next_timestamp));
- qs = TALER_ARL_edb->select_deposits_missing_wire (TALER_ARL_edb->cls,
- pp.last_timestamp,
- next_timestamp,
- &wire_missing_cb,
- &next_timestamp);
- if (0 > qs)
+ deadline = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
+ GRACE_PERIOD);
+ rc.map = GNUNET_CONTAINER_multishortmap_create (1024,
+ GNUNET_NO);
+ qs = TALER_ARL_adb->select_pending_deposits (
+ TALER_ARL_adb->cls,
+ deadline,
+ &report_wire_missing_cb,
+ &rc);
+ if ( (0 > qs) || (0 > rc.err) )
{
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ GNUNET_break (0);
+ GNUNET_break ( (GNUNET_DB_STATUS_SOFT_ERROR == qs) ||
+ (GNUNET_DB_STATUS_SOFT_ERROR == rc.err) );
+ GNUNET_CONTAINER_multishortmap_iterate (rc.map,
+ &free_report_entry,
+ NULL);
+ GNUNET_CONTAINER_multishortmap_destroy (rc.map);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
- pp.last_timestamp = next_timestamp;
+ GNUNET_CONTAINER_multishortmap_iterate (rc.map,
+ &generate_report,
+ NULL);
+ GNUNET_CONTAINER_multishortmap_destroy (rc.map);
/* conclude with success */
commit (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT);
GNUNET_SCHEDULER_shutdown ();
@@ -956,6 +1429,9 @@ wire_out_cb (void *cls,
GNUNET_TIME_timestamp2s (date),
TALER_amount2s (amount),
TALER_B2S (wtid));
+ TALER_ARL_amount_add (&total_wire_out,
+ &total_wire_out,
+ amount);
GNUNET_CRYPTO_hash (wtid,
sizeof (struct TALER_WireTransferIdentifierRawP),
&key);
@@ -965,7 +1441,7 @@ wire_out_cb (void *cls,
{
/* Wire transfer was not made (yet) at all (but would have been
justified), so the entire amount is missing / still to be done.
- This is moderately harmless, it might just be that the aggreator
+ This is moderately harmless, it might just be that the aggregator
has not yet fully caught up with the transfers it should do. */
TALER_ARL_report (
report_wire_out_inconsistencies,
@@ -1133,7 +1609,7 @@ struct CheckMatchContext
* @param key key of @a value in #reserve_closures
* @param value a `struct ReserveClosure`
*/
-static int
+static enum GNUNET_GenericReturnValue
check_rc_matches (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -1163,14 +1639,15 @@ check_rc_matches (void *cls,
/**
- * Check whether the given transfer was justified by a reserve closure. If
- * not, complain that we failed to match an entry from #out_map. This means a
- * wire transfer was made without proper justification.
+ * Check whether the given transfer was justified by a reserve closure or
+ * profit drain. If not, complain that we failed to match an entry from
+ * #out_map. This means a wire transfer was made without proper
+ * justification.
*
* @param cls a `struct WireAccount`
* @param key unused key
* @param value the `struct ReserveOutInfo` to report
- * @return #GNUNET_OK
+ * @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
complain_out_not_found (void *cls,
@@ -1195,6 +1672,131 @@ complain_out_not_found (void *cls,
&ctx);
if (ctx.found)
return GNUNET_OK;
+ /* check for profit drain */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ uint64_t serial;
+ char *account_section;
+ char *payto_uri;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct TALER_Amount amount;
+ struct TALER_MasterSignatureP master_sig;
+
+ qs = TALER_ARL_edb->get_drain_profit (TALER_ARL_edb->cls,
+ &roi->details.wtid,
+ &serial,
+ &account_section,
+ &payto_uri,
+ &request_timestamp,
+ &amount,
+ &master_sig);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ /* should fail on commit later ... */
+ GNUNET_break (0);
+ return GNUNET_NO;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* not a profit drain */
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Profit drain of %s to %s found!\n",
+ TALER_amount2s (&amount),
+ payto_uri);
+ if (GNUNET_OK !=
+ TALER_exchange_offline_profit_drain_verify (
+ &roi->details.wtid,
+ request_timestamp,
+ &amount,
+ account_section,
+ payto_uri,
+ &TALER_ARL_master_pub,
+ &master_sig))
+ {
+ GNUNET_break (0);
+ TALER_ARL_report (report_row_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("table",
+ "profit_drains"),
+ GNUNET_JSON_pack_uint64 ("row",
+ serial),
+ GNUNET_JSON_pack_data_auto ("id",
+ &roi->details.wtid),
+ GNUNET_JSON_pack_string ("diagnostic",
+ "invalid signature")));
+ TALER_ARL_amount_add (&total_bad_amount_out_plus,
+ &total_bad_amount_out_plus,
+ &amount);
+ }
+ else if (0 !=
+ strcasecmp (payto_uri,
+ roi->details.credit_account_uri))
+ {
+ TALER_ARL_report (
+ report_wire_out_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("row",
+ serial),
+ TALER_JSON_pack_amount ("amount_wired",
+ &roi->details.amount),
+ TALER_JSON_pack_amount ("amount_wired",
+ &amount),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &roi->details.wtid),
+ TALER_JSON_pack_time_abs_human ("timestamp",
+ roi->details.execution_date.abs_time),
+ GNUNET_JSON_pack_string ("account",
+ wa->ai->section_name),
+ GNUNET_JSON_pack_string ("diagnostic",
+ "wrong target account")));
+ TALER_ARL_amount_add (&total_bad_amount_out_plus,
+ &total_bad_amount_out_plus,
+ &amount);
+ }
+ else if (0 !=
+ TALER_amount_cmp (&amount,
+ &roi->details.amount))
+ {
+ TALER_ARL_report (
+ report_wire_out_inconsistencies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("row",
+ serial),
+ TALER_JSON_pack_amount ("amount_justified",
+ &roi->details.amount),
+ TALER_JSON_pack_amount ("amount_wired",
+ &amount),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &roi->details.wtid),
+ TALER_JSON_pack_time_abs_human ("timestamp",
+ roi->details.execution_date.abs_time),
+ GNUNET_JSON_pack_string ("account",
+ wa->ai->section_name),
+ GNUNET_JSON_pack_string ("diagnostic",
+ "profit drain amount incorrect")));
+ TALER_ARL_amount_add (&total_bad_amount_out_minus,
+ &total_bad_amount_out_minus,
+ &roi->details.amount);
+ TALER_ARL_amount_add (&total_bad_amount_out_plus,
+ &total_bad_amount_out_plus,
+ &amount);
+ }
+ GNUNET_free (account_section);
+ GNUNET_free (payto_uri);
+ /* profit drain was correct */
+ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_drained),
+ &TALER_ARL_USE_AB (total_drained),
+ &amount);
+ return GNUNET_OK;
+ }
+ }
+
TALER_ARL_report (
report_wire_out_inconsistencies,
GNUNET_JSON_PACK (
@@ -1241,6 +1843,7 @@ check_exchange_wire_out (struct WireAccount *wa)
{
enum GNUNET_DB_QueryStatus qs;
+ GNUNET_assert (NULL == wa->dhh);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzing exchange's wire OUT table for account `%s'\n",
wa->ai->section_name);
@@ -1274,92 +1877,92 @@ check_exchange_wire_out (struct WireAccount *wa)
* transactions).
*
* @param cls `struct WireAccount` with current wire account to process
- * @param http_status_code http status of the request
- * @param ec error code in case something went wrong
- * @param row_off identification of the position at which we are querying
- * @param details details about the wire transfer
- * @param json original response in JSON format
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param dhr HTTP response details
*/
-static enum GNUNET_GenericReturnValue
+static void
history_debit_cb (void *cls,
- unsigned int http_status_code,
- enum TALER_ErrorCode ec,
- uint64_t row_off,
- const struct TALER_BANK_DebitDetails *details,
- const json_t *json)
+ const struct TALER_BANK_DebitHistoryResponse *dhr)
{
struct WireAccount *wa = cls;
struct ReserveOutInfo *roi;
size_t slen;
- (void) json;
- if (NULL == details)
+ wa->dhh = NULL;
+ switch (dhr->http_status)
{
- wa->dhh = NULL;
- if ( (TALER_EC_NONE != ec) &&
- ( (! ignore_account_404) ||
- (MHD_HTTP_NOT_FOUND != http_status_code) ) )
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<dhr->details.ok.details_length; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error fetching debit history of account %s: %u/%u!\n",
- wa->ai->section_name,
- http_status_code,
- (unsigned int) ec);
- commit (GNUNET_DB_STATUS_HARD_ERROR);
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_SYSERR;
+ const struct TALER_BANK_DebitDetails *dd
+ = &dhr->details.ok.details[i];
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Analyzing bank DEBIT at %s of %s with WTID %s\n",
+ GNUNET_TIME_timestamp2s (dd->execution_date),
+ TALER_amount2s (&dd->amount),
+ TALER_B2S (&dd->wtid));
+ /* Update offset */
+ wa->wire_off_out = dd->serial_id;
+ slen = strlen (dd->credit_account_uri) + 1;
+ roi = GNUNET_malloc (sizeof (struct ReserveOutInfo)
+ + slen);
+ GNUNET_CRYPTO_hash (&dd->wtid,
+ sizeof (dd->wtid),
+ &roi->subject_hash);
+ roi->details.amount = dd->amount;
+ roi->details.execution_date = dd->execution_date;
+ roi->details.wtid = dd->wtid;
+ roi->details.credit_account_uri = (const char *) &roi[1];
+ GNUNET_memcpy (&roi[1],
+ dd->credit_account_uri,
+ slen);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put (out_map,
+ &roi->subject_hash,
+ roi,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ char *diagnostic;
+
+ GNUNET_asprintf (&diagnostic,
+ "duplicate subject hash `%s'",
+ TALER_B2S (&roi->subject_hash));
+ TALER_ARL_amount_add (&total_wire_format_amount,
+ &total_wire_format_amount,
+ &dd->amount);
+ TALER_ARL_report (report_wire_format_inconsistencies,
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("amount",
+ &dd->amount),
+ GNUNET_JSON_pack_uint64 ("wire_offset",
+ dd->serial_id),
+ GNUNET_JSON_pack_string ("diagnostic",
+ diagnostic)));
+ GNUNET_free (diagnostic);
+ }
}
check_exchange_wire_out (wa);
- return GNUNET_OK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Analyzing bank DEBIT at %s of %s with WTID %s\n",
- GNUNET_TIME_timestamp2s (details->execution_date),
- TALER_amount2s (&details->amount),
- TALER_B2S (&details->wtid));
- /* Update offset */
- wa->out_wire_off = row_off;
- slen = strlen (details->credit_account_uri) + 1;
- roi = GNUNET_malloc (sizeof (struct ReserveOutInfo)
- + slen);
- GNUNET_CRYPTO_hash (&details->wtid,
- sizeof (details->wtid),
- &roi->subject_hash);
- roi->details.amount = details->amount;
- roi->details.execution_date = details->execution_date;
- roi->details.wtid = details->wtid;
- roi->details.credit_account_uri = (const char *) &roi[1];
- memcpy (&roi[1],
- details->credit_account_uri,
- slen);
- if (GNUNET_OK !=
- GNUNET_CONTAINER_multihashmap_put (out_map,
- &roi->subject_hash,
- roi,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- char *diagnostic;
-
- GNUNET_asprintf (&diagnostic,
- "duplicate subject hash `%s'",
- TALER_B2S (&roi->subject_hash));
- TALER_ARL_amount_add (&total_wire_format_amount,
- &total_wire_format_amount,
- &details->amount);
- TALER_ARL_report (report_wire_format_inconsistencies,
- GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("amount",
- &details->amount),
- GNUNET_JSON_pack_uint64 ("wire_offset",
- row_off),
- GNUNET_JSON_pack_string ("diagnostic",
- diagnostic)));
- GNUNET_free (diagnostic);
- return GNUNET_OK;
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ check_exchange_wire_out (wa);
+ return;
+ case MHD_HTTP_NOT_FOUND:
+ if (ignore_account_404)
+ {
+ check_exchange_wire_out (wa);
+ return;
+ }
+ break;
+ default:
+ break;
}
- return GNUNET_OK;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error fetching debit history of account %s: %u/%u!\n",
+ wa->ai->section_name,
+ dhr->http_status,
+ (unsigned int) dhr->ec);
+ commit (GNUNET_DB_STATUS_HARD_ERROR);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -1390,10 +1993,12 @@ process_debits (void *cls)
"Checking bank DEBIT records of account `%s'\n",
wa->ai->section_name);
GNUNET_assert (NULL == wa->dhh);
+ // FIXME: handle the case where more than INT32_MAX transactions exist.
+ // (CG: used to be INT64_MAX, changed by MS to INT32_MAX, why? To be discussed with him!)
wa->dhh = TALER_BANK_debit_history (ctx,
wa->ai->auth,
- wa->out_wire_off,
- INT64_MAX,
+ wa->wire_off_out,
+ INT32_MAX,
GNUNET_TIME_UNIT_ZERO,
&history_debit_cb,
wa);
@@ -1416,8 +2021,9 @@ process_debits (void *cls)
static void
begin_debit_audit (void)
{
+ GNUNET_assert (NULL == out_map);
out_map = GNUNET_CONTAINER_multihashmap_create (1024,
- GNUNET_YES);
+ true);
process_debits (wa_head);
}
@@ -1432,8 +2038,11 @@ begin_debit_audit (void)
static void
conclude_credit_history (void)
{
- GNUNET_CONTAINER_multihashmap_destroy (in_map);
- in_map = NULL;
+ if (NULL != in_map)
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (in_map);
+ in_map = NULL;
+ }
/* credit done, now check debits */
begin_debit_audit ();
}
@@ -1452,7 +2061,7 @@ conclude_credit_history (void)
* @param execution_date when did we receive the funds
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
-static int
+static enum GNUNET_GenericReturnValue
reserve_in_cb (void *cls,
uint64_t rowid,
const struct TALER_ReservePublicKeyP *reserve_pub,
@@ -1471,6 +2080,9 @@ reserve_in_cb (void *cls,
GNUNET_TIME_timestamp2s (execution_date),
TALER_amount2s (credit),
TALER_B2S (reserve_pub));
+ TALER_ARL_amount_add (&total_wire_in,
+ &total_wire_in,
+ credit);
slen = strlen (sender_account_details) + 1;
rii = GNUNET_malloc (sizeof (struct ReserveInInfo) + slen);
rii->rowid = rowid;
@@ -1478,9 +2090,9 @@ reserve_in_cb (void *cls,
rii->details.execution_date = execution_date;
rii->details.reserve_pub = *reserve_pub;
rii->details.debit_account_uri = (const char *) &rii[1];
- memcpy (&rii[1],
- sender_account_details,
- slen);
+ GNUNET_memcpy (&rii[1],
+ sender_account_details,
+ slen);
GNUNET_CRYPTO_hash (&wire_reference,
sizeof (uint64_t),
&rii->row_off_hash);
@@ -1496,7 +2108,7 @@ reserve_in_cb (void *cls,
"reserves_in"),
GNUNET_JSON_pack_uint64 ("row",
rowid),
- GNUNET_JSON_pack_data_auto ("wire_offset_hash",
+ GNUNET_JSON_pack_data_auto ("id",
&rii->row_off_hash),
GNUNET_JSON_pack_string ("diagnostic",
"duplicate wire offset")));
@@ -1520,7 +2132,7 @@ reserve_in_cb (void *cls,
* @param value the `struct ReserveInInfo` to free
* @return #GNUNET_OK
*/
-static int
+static enum GNUNET_GenericReturnValue
complain_in_not_found (void *cls,
const struct GNUNET_HashCode *key,
void *value)
@@ -1564,52 +2176,19 @@ process_credits (void *cls);
/**
- * This function is called for all transactions that
- * are credited to the exchange's account (incoming
- * transactions).
+ * We got all of the incoming transactions for @a wa,
+ * finish processing the account.
*
- * @param cls `struct WireAccount` we are processing
- * @param http_status HTTP status returned by the bank
- * @param ec error code in case something went wrong
- * @param row_off identification of the position at which we are querying
- * @param details details about the wire transfer
- * @param json raw response
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param[in,out] wa wire account to process
*/
-static enum GNUNET_GenericReturnValue
-history_credit_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t row_off,
- const struct TALER_BANK_CreditDetails *details,
- const json_t *json)
+static void
+conclude_account (struct WireAccount *wa)
{
- struct WireAccount *wa = cls;
- struct ReserveInInfo *rii;
- struct GNUNET_HashCode key;
-
- (void) json;
- if (NULL == details)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reconciling CREDIT processing of account `%s'\n",
+ wa->ai->section_name);
+ if (NULL != in_map)
{
- wa->chh = NULL;
- if ( (TALER_EC_NONE != ec) &&
- ( (! ignore_account_404) ||
- (MHD_HTTP_NOT_FOUND != http_status) ) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error fetching credit history of account %s: %u/%s!\n",
- wa->ai->section_name,
- http_status,
- TALER_ErrorCode_get_hint (ec));
- commit (GNUNET_DB_STATUS_HARD_ERROR);
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_SYSERR;
- }
- /* end of operation */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Reconciling CREDIT processing of account `%s'\n",
- wa->ai->section_name);
GNUNET_CONTAINER_multihashmap_iterate (in_map,
&complain_in_not_found,
wa);
@@ -1617,16 +2196,32 @@ history_credit_cb (void *cls,
GNUNET_CONTAINER_multihashmap_iterate (in_map,
&free_rii,
NULL);
- process_credits (wa->next);
- return GNUNET_OK;
}
+ process_credits (wa->next);
+}
+
+
+/**
+ * Analyze credit transaction @a details into @a wa.
+ *
+ * @param[in,out] wa account that received the transfer
+ * @param details transfer details
+ * @return true on success, false to stop loop at this point
+ */
+static bool
+analyze_credit (struct WireAccount *wa,
+ const struct TALER_BANK_CreditDetails *details)
+{
+ struct ReserveInInfo *rii;
+ struct GNUNET_HashCode key;
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Analyzing bank CREDIT at %s of %s with Reserve-pub %s\n",
GNUNET_TIME_timestamp2s (details->execution_date),
TALER_amount2s (&details->amount),
TALER_B2S (&details->reserve_pub));
- GNUNET_CRYPTO_hash (&row_off,
- sizeof (row_off),
+ GNUNET_CRYPTO_hash (&details->serial_id,
+ sizeof (details->serial_id),
&key);
rii = GNUNET_CONTAINER_multihashmap_get (in_map,
&key);
@@ -1635,13 +2230,12 @@ history_credit_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Failed to find wire transfer at `%s' in exchange database. Audit ends at this point in time.\n",
GNUNET_TIME_timestamp2s (details->execution_date));
- wa->chh = NULL;
process_credits (wa->next);
- return GNUNET_SYSERR; /* not an error, just end of processing */
+ return false; /* not an error, just end of processing */
}
/* Update offset */
- wa->in_wire_off = row_off;
+ wa->wire_off_in = details->serial_id;
/* compare records with expected data */
if (0 != GNUNET_memcmp (&details->reserve_pub,
&rii->details.reserve_pub))
@@ -1652,7 +2246,7 @@ history_credit_cb (void *cls,
GNUNET_JSON_pack_uint64 ("row",
rii->rowid),
GNUNET_JSON_pack_uint64 ("bank_row",
- row_off),
+ details->serial_id),
TALER_JSON_pack_amount ("amount_exchange_expected",
&rii->details.amount),
TALER_JSON_pack_amount ("amount_wired",
@@ -1672,7 +2266,7 @@ history_credit_cb (void *cls,
GNUNET_JSON_pack_uint64 ("row",
rii->rowid),
GNUNET_JSON_pack_uint64 ("bank_row",
- row_off),
+ details->serial_id),
TALER_JSON_pack_amount ("amount_exchange_expected",
&zero),
TALER_JSON_pack_amount ("amount_wired",
@@ -1698,7 +2292,7 @@ history_credit_cb (void *cls,
GNUNET_JSON_pack_uint64 ("row",
rii->rowid),
GNUNET_JSON_pack_uint64 ("bank_row",
- row_off),
+ details->serial_id),
TALER_JSON_pack_amount ("amount_exchange_expected",
&rii->details.amount),
TALER_JSON_pack_amount ("amount_wired",
@@ -1739,19 +2333,19 @@ history_credit_cb (void *cls,
if (0 != strcasecmp (details->debit_account_uri,
rii->details.debit_account_uri))
{
- TALER_ARL_report (report_missattribution_in_inconsistencies,
+ TALER_ARL_report (report_misattribution_in_inconsistencies,
GNUNET_JSON_PACK (
TALER_JSON_pack_amount ("amount",
&rii->details.amount),
GNUNET_JSON_pack_uint64 ("row",
rii->rowid),
GNUNET_JSON_pack_uint64 ("bank_row",
- row_off),
+ details->serial_id),
GNUNET_JSON_pack_data_auto (
"reserve_pub",
&rii->details.reserve_pub)));
- TALER_ARL_amount_add (&total_missattribution_in,
- &total_missattribution_in,
+ TALER_ARL_amount_add (&total_misattribution_in,
+ &total_misattribution_in,
&rii->details.amount);
}
if (GNUNET_TIME_timestamp_cmp (details->execution_date,
@@ -1765,7 +2359,7 @@ history_credit_cb (void *cls,
GNUNET_JSON_pack_uint64 ("row",
rii->rowid),
GNUNET_JSON_pack_uint64 ("bank_row",
- row_off),
+ details->serial_id),
GNUNET_JSON_pack_string ("diagnostic",
"execution date mismatch")));
}
@@ -1774,7 +2368,60 @@ cleanup:
free_rii (NULL,
&key,
rii));
- return GNUNET_OK;
+ return true;
+}
+
+
+/**
+ * This function is called for all transactions that
+ * are credited to the exchange's account (incoming
+ * transactions).
+ *
+ * @param cls `struct WireAccount` we are processing
+ * @param chr HTTP response returned by the bank
+ */
+static void
+history_credit_cb (void *cls,
+ const struct TALER_BANK_CreditHistoryResponse *chr)
+{
+ struct WireAccount *wa = cls;
+
+ wa->chh = NULL;
+ switch (chr->http_status)
+ {
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<chr->details.ok.details_length; i++)
+ {
+ const struct TALER_BANK_CreditDetails *cd
+ = &chr->details.ok.details[i];
+
+ if (! analyze_credit (wa,
+ cd))
+ return;
+ }
+ conclude_account (wa);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ conclude_account (wa);
+ return;
+ case MHD_HTTP_NOT_FOUND:
+ if (ignore_account_404)
+ {
+ conclude_account (wa);
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error fetching credit history of account %s: %u/%s!\n",
+ wa->ai->section_name,
+ chr->http_status,
+ TALER_ErrorCode_get_hint (chr->ec));
+ commit (GNUNET_DB_STATUS_HARD_ERROR);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -1823,10 +2470,12 @@ process_credits (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting bank CREDIT history of account `%s'\n",
wa->ai->section_name);
+ // NOTE: handle the case where more than INT32_MAX transactions exist.
+ // (CG: used to be INT64_MAX, changed by MS to INT32_MAX, why? To be discussed with him!)
wa->chh = TALER_BANK_credit_history (ctx,
wa->ai->auth,
- wa->in_wire_off,
- INT64_MAX,
+ wa->wire_off_in,
+ INT32_MAX,
GNUNET_TIME_UNIT_ZERO,
&history_credit_cb,
wa);
@@ -1848,6 +2497,7 @@ process_credits (void *cls)
static void
begin_credit_audit (void)
{
+ GNUNET_assert (NULL == in_map);
in_map = GNUNET_CONTAINER_multihashmap_create (1024,
GNUNET_YES);
/* now go over all bank accounts and check delta with in_map */
@@ -1856,8 +2506,7 @@ begin_credit_audit (void)
/**
- * Function called about reserve closing operations
- * the aggregator triggered.
+ * Function called about reserve closing operations the aggregator triggered.
*
* @param cls closure
* @param rowid row identifier used to uniquely identify the reserve closing operation
@@ -1867,9 +2516,11 @@ begin_credit_audit (void)
* @param reserve_pub public key of the reserve
* @param receiver_account where did we send the funds, in payto://-format
* @param wtid identifier used for the wire transfer
+ * @param close_request_row which close request triggered the operation?
+ * 0 if it was a timeout (not used)
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
-static int
+static enum GNUNET_GenericReturnValue
reserve_closed_cb (void *cls,
uint64_t rowid,
struct GNUNET_TIME_Timestamp execution_date,
@@ -1877,12 +2528,14 @@ reserve_closed_cb (void *cls,
const struct TALER_Amount *closing_fee,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid)
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t close_request_row)
{
struct ReserveClosure *rc;
struct GNUNET_HashCode key;
(void) cls;
+ (void) close_request_row;
rc = GNUNET_new (struct ReserveClosure);
if (TALER_ARL_SR_INVALID_NEGATIVE ==
TALER_ARL_amount_subtract_neg (&rc->amount,
@@ -1895,7 +2548,7 @@ reserve_closed_cb (void *cls,
"reserves_closures"),
GNUNET_JSON_pack_uint64 ("row",
rowid),
- GNUNET_JSON_pack_data_auto ("reserve_pub",
+ GNUNET_JSON_pack_data_auto ("id",
reserve_pub),
TALER_JSON_pack_amount ("amount_with_fee",
amount_with_fee),
@@ -1908,8 +2561,8 @@ reserve_closed_cb (void *cls,
return GNUNET_SYSERR;
return GNUNET_OK;
}
- pp.last_reserve_close_uuid
- = GNUNET_MAX (pp.last_reserve_close_uuid,
+ TALER_ARL_USE_PP (wire_reserve_close_id)
+ = GNUNET_MAX (TALER_ARL_USE_PP (wire_reserve_close_id),
rowid + 1);
rc->receiver_account = GNUNET_strdup (receiver_account);
rc->wtid = *wtid;
@@ -1936,6 +2589,8 @@ reserve_closed_cb (void *cls,
static enum GNUNET_DB_QueryStatus
begin_transaction (void)
{
+ enum GNUNET_DB_QueryStatus qs;
+
if (GNUNET_SYSERR ==
TALER_ARL_edb->preflight (TALER_ARL_edb->cls))
{
@@ -1964,17 +2619,66 @@ begin_transaction (void)
GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &TALER_ARL_USE_AB (total_drained)));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_wire_in));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TALER_ARL_currency,
+ &total_wire_out));
+ qs = TALER_ARL_adb->get_balance (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_AB (total_drained),
+ TALER_ARL_GET_AB (final_balance),
+ NULL);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ had_start_balance = false;
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ had_start_balance = true;
+ break;
+ }
for (struct WireAccount *wa = wa_head;
NULL != wa;
wa = wa->next)
{
- wa->qsx = TALER_ARL_adb->get_wire_auditor_account_progress (
+ GNUNET_asprintf (&wa->label_reserve_in_serial_id,
+ "wire-%s-%s",
+ wa->ai->section_name,
+ "reserve_in_serial_id");
+ GNUNET_asprintf (&wa->label_wire_out_serial_id,
+ "wire-%s-%s",
+ wa->ai->section_name,
+ "wire_out_serial_id");
+ GNUNET_asprintf (&wa->label_wire_off_in,
+ "wire-%s-%s",
+ wa->ai->section_name,
+ "wire_off_in");
+ GNUNET_asprintf (&wa->label_wire_off_out,
+ "wire-%s-%s",
+ wa->ai->section_name,
+ "wire_off_out");
+ wa->qsx = TALER_ARL_adb->get_auditor_progress (
TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- wa->ai->section_name,
- &wa->pp,
- &wa->in_wire_off,
- &wa->out_wire_off);
+ wa->label_reserve_in_serial_id,
+ &wa->pp.last_reserve_in_serial_id,
+ wa->label_wire_out_serial_id,
+ &wa->pp.last_wire_out_serial_id,
+ wa->label_wire_off_in,
+ &wa->wire_off_in,
+ wa->label_wire_off_out,
+ &wa->wire_off_out,
+ NULL);
if (0 > wa->qsx)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == wa->qsx);
@@ -1982,9 +2686,12 @@ begin_transaction (void)
}
wa->start_pp = wa->pp;
}
- qsx_gwap = TALER_ARL_adb->get_wire_auditor_progress (TALER_ARL_adb->cls,
- &TALER_ARL_master_pub,
- &pp);
+ qsx_gwap = TALER_ARL_adb->get_auditor_progress (
+ TALER_ARL_adb->cls,
+ TALER_ARL_GET_PP (wire_reserve_close_id),
+ TALER_ARL_GET_PP (wire_batch_deposit_id),
+ TALER_ARL_GET_PP (wire_aggregation_id),
+ NULL);
if (0 > qsx_gwap)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qsx_gwap);
@@ -1997,11 +2704,11 @@ begin_transaction (void)
}
else
{
- start_pp = pp;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resuming wire audit at %s / %llu\n",
- GNUNET_TIME_timestamp2s (pp.last_timestamp),
- (unsigned long long) pp.last_reserve_close_uuid);
+ "Resuming wire audit at %llu / %llu / %llu\n",
+ (unsigned long long) TALER_ARL_USE_PP (wire_reserve_close_id),
+ (unsigned long long) TALER_ARL_USE_PP (wire_batch_deposit_id),
+ (unsigned long long) TALER_ARL_USE_PP (wire_aggregation_id));
}
{
@@ -2009,7 +2716,7 @@ begin_transaction (void)
qs = TALER_ARL_edb->select_reserve_closed_above_serial_id (
TALER_ARL_edb->cls,
- pp.last_reserve_close_uuid,
+ TALER_ARL_USE_PP (wire_reserve_close_id),
&reserve_closed_cb,
NULL);
if (0 > qs)
@@ -2111,11 +2818,15 @@ run (void *cls,
GNUNET_assert (NULL !=
(report_row_inconsistencies = json_array ()));
GNUNET_assert (NULL !=
- (report_missattribution_in_inconsistencies
+ (report_misattribution_in_inconsistencies
= json_array ()));
GNUNET_assert (NULL !=
(report_lags = json_array ()));
GNUNET_assert (NULL !=
+ (report_aml_lags = json_array ()));
+ GNUNET_assert (NULL !=
+ (report_kyc_lags = json_array ()));
+ GNUNET_assert (NULL !=
(report_closure_lags = json_array ()));
GNUNET_assert (NULL !=
(report_account_progress = json_array ()));
@@ -2133,7 +2844,7 @@ run (void *cls,
&total_bad_amount_in_minus));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
- &total_missattribution_in));
+ &total_misattribution_in));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TALER_ARL_currency,
&total_amount_lag));
@@ -2191,11 +2902,10 @@ main (int argc,
"ignore-not-found",
"continue, even if the bank account of the exchange was not found",
&ignore_account_404),
- GNUNET_GETOPT_option_base32_auto ('m',
- "exchange-key",
- "KEY",
- "public key of the exchange (Crockford base32 encoded)",
- &TALER_ARL_master_pub),
+ GNUNET_GETOPT_option_flag ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_OPTION_END
diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh
index 0d5dbc884..2cfea0532 100755
--- a/src/auditor/test-auditor.sh
+++ b/src/auditor/test-auditor.sh
@@ -1,4 +1,24 @@
#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2014-2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
+#
+#
+# shellcheck disable=SC2317
+# shellcheck disable=SC1091
+#
+#
# Setup database which was generated from a perfectly normal
# exchange-wallet interaction and run the auditor against it.
#
@@ -10,7 +30,7 @@ set -eu
# Set of numbers for all the testcases.
# When adding new tests, increase the last number:
-ALL_TESTS=`seq 0 32`
+ALL_TESTS=$(seq 0 33)
# $TESTS determines which tests we should run.
# This construction is used to make it easy to
@@ -28,60 +48,105 @@ TESTS=${1:-$ALL_TESTS}
# VALGRIND=valgrind
VALGRIND=""
-# Exit, with status code "skip" (no 'real' failure)
-function exit_skip() {
- echo $1
- exit 77
-}
+# Number of seconds to let libeuifn background
+# tasks apply a cycle of payment submission and
+# history request.
+LIBEUFIN_SETTLE_TIME=1
+
+. setup.sh
+
-# Exit, with error message (hard failure)
-function exit_fail() {
- echo $1
- exit 1
+# Cleanup exchange and libeufin between runs.
+function cleanup()
+{
+ if [ ! -z "${EPID:-}" ]
+ then
+ echo -n "Stopping exchange $EPID..."
+ kill -TERM "$EPID"
+ wait "$EPID" || true
+ echo "DONE"
+ unset EPID
+ fi
+ stop_libeufin
}
# Cleanup to run whenever we exit
-function cleanup()
+function exit_cleanup()
{
- for n in `jobs -p`
+ echo "Running exit-cleanup"
+ if [ ! -z "${POSTGRES_PATH:-}" ]
+ then
+ echo "Stopping Postgres at ${POSTGRES_PATH}"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ stop \
+ &> /dev/null \
+ || true
+ fi
+ cleanup
+ for n in $(jobs -p)
do
- kill $n 2> /dev/null || true
+ kill "$n" 2> /dev/null || true
done
- wait
+ wait || true
+ echo "DONE"
}
# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
+trap exit_cleanup EXIT
# Operations to run before the actual audit
function pre_audit () {
# Launch bank
- echo -n "Launching bank "
- taler-bank-manage-testing $CONF postgres:///$DB serve 2>bank.err >bank.log &
- for n in `seq 1 80`
+ echo -n "Launching libeufin-bank"
+ export CONF
+ export MY_TMP_DIR
+ launch_libeufin
+ for n in $(seq 1 80)
do
echo -n "."
sleep 0.1
OK=1
- wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null && break
+ wget http://localhost:8082/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ && break
OK=0
done
- if [ 1 != $OK ]
+ if [ 1 != "$OK" ]
then
- exit_skip "Failed to launch bank"
+ exit_skip "Failed to launch libeufin-bank"
fi
echo " DONE"
- if test ${1:-no} = "aggregator"
+ if [ "${1:-no}" = "aggregator" ]
then
echo -n "Running exchange aggregator ..."
- taler-exchange-aggregator -y -L INFO -t -c $CONF 2> aggregator.log || exit_fail "FAIL"
+ taler-exchange-aggregator \
+ -y \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/aggregator.log" \
+ || exit_fail "FAIL"
echo " DONE"
echo -n "Running exchange closer ..."
- taler-exchange-closer -L INFO -t -c $CONF 2> closer.log || exit_fail "FAIL"
+ taler-exchange-closer \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/closer.log" \
+ || exit_fail "FAIL"
echo " DONE"
echo -n "Running exchange transfer ..."
- taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL"
+ taler-exchange-transfer \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/transfer.log" \
+ || exit_fail "FAIL"
echo " DONE"
fi
}
@@ -92,26 +157,92 @@ function audit_only () {
echo -n "Running audit(s) ..."
# Restart so that first run is always fresh, and second one is incremental
- taler-auditor-dbinit -r -c $CONF
- $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> test-audit-aggregation.log || exit_fail "aggregation audit failed"
+ taler-auditor-dbinit \
+ -r \
+ -c "$CONF"
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-aggregation.out" \
+ 2> "${MY_TMP_DIR}/test-audit-aggregation.err" \
+ || exit_fail "aggregation audit failed (see ${MY_TMP_DIR}/test-audit-aggregation.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed"
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-aggregation-inc.out" \
+ 2> "${MY_TMP_DIR}/test-audit-aggregation-inc.err" \
+ || exit_fail "incremental aggregation audit failed (see ${MY_TMP_DIR}/test-audit-aggregation-inc.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> test-audit-coins.log || exit_fail "coin audit failed"
+ $VALGRIND taler-helper-auditor-coins \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-coins.out" \
+ 2> "${MY_TMP_DIR}/test-audit-coins.err" \
+ || exit_fail "coin audit failed (see ${MY_TMP_DIR}/test-audit-coins.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> test-audit-coins-inc.log || exit_fail "incremental coin audit failed"
+ $VALGRIND taler-helper-auditor-coins \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-coins-inc.out" \
+ 2> "${MY_TMP_DIR}/test-audit-coins-inc.err" \
+ || exit_fail "incremental coin audit failed (see ${MY_TMP_DIR}/test-audit-coins-inc.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> test-audit-deposits.log || exit_fail "deposits audit failed"
+ $VALGRIND taler-helper-auditor-deposits \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-deposits.out" \
+ 2> "${MY_TMP_DIR}/test-audit-deposits.err" \
+ || exit_fail "deposits audit failed (see ${MY_TMP_DIR}/test-audit-deposits.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed"
+ $VALGRIND taler-helper-auditor-deposits \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-deposits-inc.out" \
+ 2> "${MY_TMP_DIR}/test-audit-deposits-inc.err" \
+ || exit_fail "incremental deposits audit failed (see ${MY_TMP_DIR}/test-audit-deposits-inc.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> test-audit-reserves.log || exit_fail "reserves audit failed"
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-reserves.out" \
+ 2> "${MY_TMP_DIR}/test-audit-reserves.err" \
+ || exit_fail "reserves audit failed (see ${MY_TMP_DIR}/test-audit-reserves.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed"
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-reserves-inc.out" \
+ 2> "${MY_TMP_DIR}/test-audit-reserves-inc.err" \
+ || exit_fail "incremental reserves audit failed (see ${MY_TMP_DIR}/test-audit-reserves-inc.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> test-wire-audit.log || exit_fail "wire audit failed"
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-wire.out" \
+ 2> "${MY_TMP_DIR}/test-audit-wire.err" \
+ || exit_fail "wire audit failed (see ${MY_TMP_DIR}/test-audit-wire.*)"
echo -n "."
- $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> test-wire-audit-inc.log || exit_fail "wire audit failed"
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -t \
+ > "${MY_TMP_DIR}/test-audit-wire-inc.out" \
+ 2> "${MY_TMP_DIR}/test-audit-wire-inc.err" \
+ || exit_fail "wire audit inc failed (see ${MY_TMP_DIR}/test-audit-wire-inc.*)"
echo -n "."
echo " DONE"
@@ -120,16 +251,11 @@ function audit_only () {
# Cleanup to run after the auditor
function post_audit () {
- taler-exchange-dbinit -c $CONF -g || exit_fail "exchange DB GC failed"
-
+ taler-exchange-dbinit \
+ -c "$CONF" \
+ -g \
+ || exit_fail "exchange DB GC failed"
cleanup
- echo -n "TeXing ."
- taler-helper-auditor-render.py test-audit-aggregation.json test-audit-coins.json test-audit-deposits.json test-audit-reserves.json test-audit-wire.json < ../../contrib/auditor-report.tex.j2 > test-report.tex || exit_fail "Renderer failed"
-
- echo -n "."
- timeout 10 pdflatex test-report.tex >/dev/null || exit_fail "pdflatex failed"
- echo -n "."
- timeout 10 pdflatex test-report.tex >/dev/null
echo " DONE"
}
@@ -138,143 +264,207 @@ function post_audit () {
# generation. Pass "aggregator" as $1 to run
# $ taler-exchange-aggregator
# before auditor (to trigger pending wire transfers).
+# Pass "drain" as $2 to run a drain operation as well.
function run_audit () {
- pre_audit ${1:-no}
+ pre_audit "${1:-no}"
+ if [ "${2:-no}" = "drain" ]
+ then
+ echo -n "Starting exchange..."
+ taler-exchange-httpd \
+ -c "${CONF}" \
+ -L INFO \
+ 2> "${MY_TMP_DIR}/exchange-httpd-drain.err" &
+ EPID=$!
+
+ # Wait for all services to be available
+ for n in $(seq 1 50)
+ do
+ echo -n "."
+ sleep 0.1
+ OK=0
+ # exchange
+ wget "http://localhost:8081/seed" \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ || continue
+ OK=1
+ break
+ done
+ echo "... DONE."
+ export CONF
+
+ echo -n "Running taler-exchange-offline drain "
+
+ taler-exchange-offline \
+ -L DEBUG \
+ -c "${CONF}" \
+ drain TESTKUDOS:0.1 \
+ exchange-account-1 payto://iban/SANDBOXX/DE360679?receiver-name=Exchange+Drain \
+ upload \
+ 2> "${MY_TMP_DIR}/taler-exchange-offline-drain.log" \
+ || exit_fail "offline draining failed"
+ kill -TERM "$EPID"
+ wait "$EPID" || true
+ unset EPID
+ echo -n "Running taler-exchange-drain ..."
+ printf "\n" | taler-exchange-drain \
+ -L DEBUG \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/taler-exchange-drain.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+
+ echo -n "Running taler-exchange-transfer ..."
+ taler-exchange-transfer \
+ -L INFO \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/drain-transfer.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+ fi
audit_only
post_audit
-
}
# Do a full reload of the (original) database
-full_reload()
+function full_reload()
{
- echo -n "Doing full reload of the database... "
- dropdb $DB 2> /dev/null || true
- createdb -T template0 $DB || exit_skip "could not create database"
+ echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB at $PGHOST)... "
+ dropdb "$DB" 2> /dev/null || true
+ createdb -T template0 "$DB" \
+ || exit_skip "could not create database $DB (at $PGHOST)"
# Import pre-generated database, -q(ietly) using single (-1) transaction
- psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database"
+ psql -Aqt "$DB" \
+ -q \
+ -1 \
+ -f "${BASEDB}.sql" \
+ > /dev/null \
+ || exit_skip "Failed to load database $DB from ${BASEDB}.sql"
echo "DONE"
+ # Technically, this call shouldn't be needed as libeufin should already be stopped here...
+ stop_libeufin
}
function test_0() {
-echo "===========0: normal run with aggregator==========="
-run_audit aggregator
-
-echo "Checking output"
-# if an emergency was detected, that is a bug and we should fail
-echo -n "Test for emergencies... "
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
-echo -n "Test for deposit confirmation emergencies... "
-jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
-echo -n "Test for emergencies by count... "
-jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
-
-echo -n "Test for wire inconsistencies... "
-jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
-jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
-jq -e .missattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected missattribution inconsistency detected in ordinary run"
-jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
-jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
-jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
-jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
-jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
-
-
-# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
-# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+ echo "===========0: normal run with aggregator==========="
+ run_audit aggregator
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
+ echo -n "Test for deposit confirmation emergencies... "
+ jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
+
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
-echo PASS
+ echo PASS
-LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
-fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
-fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
-fi
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
+ fi
-echo -n "Test for wire amounts... "
-WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_missattribution_in < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total missattribution in wrong, got $WIRED"
-fi
-echo PASS
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
+ echo "PASS"
-echo -n "Checking for unexpected arithmetic differences "
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
-fi
+ echo -n "Checking for unexpected arithmetic differences "
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
+ fi
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
-echo PASS
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
+ echo "PASS"
-echo -n "Checking for unexpected wire out differences "
-jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
-echo PASS
+ echo -n "Checking for unexpected wire out differences "
+ jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
+ echo "PASS"
-# cannot easily undo aggregator, hence full reload
-full_reload
+ # cannot easily undo aggregator, hence full reload
+ full_reload
}
@@ -283,121 +473,147 @@ full_reload
# transfer lag!
function test_1() {
-echo "===========1: normal run==========="
-run_audit
-
-echo "Checking output"
-# if an emergency was detected, that is a bug and we should fail
-echo -n "Test for emergencies... "
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
-echo -n "Test for emergencies by count... "
-jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
-
-echo -n "Test for wire inconsistencies... "
-jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
-jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
-jq -e .missattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected missattribution inconsistency detected in ordinary run"
-jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
-jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
-jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
-
-# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
-# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
-
-echo PASS
-
-echo -n "Check for lag detection... "
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
- jq -e .lag_details[0] < test-audit-wire.json > /dev/null || exit_fail "Lag not detected in run without aggregator at age $DELTA"
+ echo "===========1: normal run==========="
+ run_audit
+
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency detected in ordinary run";
+ echo "PASS"
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency by count detected in ordinary run"
+ echo "PASS"
- LAG=`jq -r .total_amount_lag < test-audit-wire.json`
- if test $LAG = "TESTKUDOS:0"
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo "PASS"
+
+ echo -n "Check for lag detection... "
+
+ # Check wire transfer lag reported (no aggregator!)
+ # NOTE: This test is EXPECTED to fail for ~1h after
+ # re-generating the test database as we do not
+ # report lag of less than 1h (see GRACE_PERIOD in
+ # taler-helper-auditor-wire.c)
+ jq -e .lag_details[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ || exit_fail "Lag not detected in run without aggregator"
+
+ LAG=$(jq -r .total_amount_lag < test-audit-wire.json)
+ if [ "$LAG" = "TESTKUDOS:0" ]
then
exit_fail "Expected total lag to be non-zero"
fi
echo "PASS"
-else
- echo "SKIP (database too new)"
-fi
-echo -n "Test for wire amounts... "
-WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_missattribution_in < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total missattribution in wrong, got $WIRED"
-fi
-# Database was unmodified, no need to undo
-echo "OK"
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
+ # Database was unmodified, no need to undo
+ echo "OK"
}
# Change amount of wire transfer reported by exchange
function test_2() {
-echo "===========2: reserves_in inconsistency==========="
-echo "UPDATE reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" | psql -At $DB
+ echo "===========2: reserves_in inconsistency ==========="
+ echo "UPDATE exchange.reserves_in SET credit_val=5 WHERE reserve_in_serial_id=1" \
+ | psql -At "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-ROW=`jq .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json`
-if test $ROW != 1
-then
- exit_fail "Row $ROW is wrong"
-fi
-WIRED=`jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:10"
-then
- exit_fail "Amount wrong"
-fi
-EXPECTED=`jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json`
-if test $EXPECTED != "TESTKUDOS:5"
-then
- exit_fail "Expected amount wrong"
-fi
+ echo -n "Testing inconsistency detection... "
+ ROW=$(jq .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json)
+ if [ "$ROW" != 1 ]
+ then
+ exit_fail "Row $ROW is wrong"
+ fi
+ WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Amount wrong"
+ fi
+ EXPECTED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json)
+ if [ "$EXPECTED" != "TESTKUDOS:5" ]
+ then
+ exit_fail "Expected amount wrong"
+ fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
-fi
-DELTA=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $DELTA != "TESTKUDOS:5"
-then
- exit_fail "Expected total wire delta plus wrong, got $DELTA"
-fi
-echo PASS
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
+ fi
+ DELTA=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$DELTA" != "TESTKUDOS:5" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $DELTA"
+ fi
+ echo "PASS"
-# Undo database modification
-echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE exchange.reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" \
+ | psql -Aqt "$DB"
}
@@ -406,61 +622,62 @@ echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql
# lower than what exchange claims to have received.
function test_3() {
-echo "===========3: reserves_in inconsistency==========="
-echo "UPDATE reserves_in SET credit_val=15 WHERE reserve_in_serial_id=1" | psql -Aqt $DB
+ echo "===========3: reserves_in inconsistency==========="
+ echo "UPDATE exchange.reserves_in SET credit_val=15 WHERE reserve_in_serial_id=1" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-EXPECTED=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json`
-if test $EXPECTED != "TESTKUDOS:5.01"
-then
- exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (auditor)"
-fi
+ EXPECTED=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json)
+ if [ "$EXPECTED" != "TESTKUDOS:5.01" ]
+ then
+ exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (auditor)"
+ fi
-EXPECTED=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json`
-if test $EXPECTED != "TESTKUDOS:0.01"
-then
- exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (exchange)"
-fi
+ EXPECTED=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json)
+ if [ "$EXPECTED" != "TESTKUDOS:0.01" ]
+ then
+ exit_fail "Expected reserve balance summary amount wrong, got $EXPECTED (exchange)"
+ fi
-WIRED=`jq -r .total_loss_balance_insufficient < test-audit-reserves.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Wrong total loss from insufficient balance, got $WIRED"
-fi
+ WIRED=$(jq -r .total_irregular_loss < test-audit-reserves.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total loss from insufficient balance, got $WIRED"
+ fi
-ROW=`jq -e .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json`
-if test $ROW != 1
-then
- exit_fail "Row wrong, got $ROW"
-fi
+ ROW=$(jq -e .reserve_in_amount_inconsistencies[0].row < test-audit-wire.json)
+ if [ "$ROW" != 1 ]
+ then
+ exit_fail "Row wrong, got $ROW"
+ fi
-WIRED=`jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:15"
-then
- exit_fail "Wrong amount_exchange_expected, got $WIRED"
-fi
+ WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:15" ]
+ then
+ exit_fail "Wrong amount_exchange_expected, got $WIRED"
+ fi
-WIRED=`jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:10"
-then
- exit_fail "Wrong amount_wired, got $WIRED"
-fi
+ WIRED=$(jq -r .reserve_in_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Wrong amount_wired, got $WIRED"
+ fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:5"
-then
- exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
-fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:5" ]
+ then
+ exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
+ fi
-WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Wrong total wire_in_delta_plus, got $WIRED"
-fi
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total wire_in_delta_plus, got $WIRED"
+ fi
-# Undo database modification
-echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE exchange.reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql -Aqt "$DB"
}
@@ -469,46 +686,52 @@ echo "UPDATE reserves_in SET credit_val=10 WHERE reserve_in_serial_id=1" | psql
# lower than what exchange claims to have received.
function test_4() {
-echo "===========4: deposit wire target wrong================="
-# Original target bank account was 43, changing to 44
-SERIAL=`echo "SELECT deposit_serial_id FROM deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql $DB -Aqt`
-OLD_WIRE_ID=`echo "SELECT wire_target_h_payto FROM deposits WHERE deposit_serial_id=${SERIAL};" | psql $DB -Aqt`
-NEW_WIRE_ID=`echo "INSERT INTO wire_targets (payto_uri, wire_target_h_payto, kyc_ok) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b', false);" | psql $DB -Aqt`
-echo "UPDATE deposits SET wire_target_h_payto='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt $DB
+ echo "===========4: deposit wire target wrong================="
+ # Original target bank account was 43, changing to 44
+ SERIAL=$(echo "SELECT deposit_serial_id FROM exchange.deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql "$DB" -Aqt)
+ OLD_WIRE_ID=$(echo "SELECT wire_target_h_payto FROM exchange.deposits WHERE deposit_serial_id=${SERIAL};" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "INSERT INTO exchange.wire_targets (payto_uri, wire_target_h_payto) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b');" \
+ | psql "$DB" \
+ -Aqt \
+ > /dev/null
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.deposits SET wire_target_h_payto='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE deposit_serial_id=${SERIAL}" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
+ echo -n "Testing inconsistency detection... "
-jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad signature not detected"
+ jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad signature not detected"
-ROW=`jq -e .bad_sig_losses[0].row < test-audit-coins.json`
-if test $ROW != ${SERIAL}
-then
- exit_fail "Row wrong, got $ROW"
-fi
+ ROW=$(jq -e .bad_sig_losses[0].row < test-audit-coins.json)
+ if [ "$ROW" != "${SERIAL}" ]
+ then
+ exit_fail "Row wrong, got $ROW"
+ fi
-LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong deposit bad signature loss, got $LOSS"
-fi
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong deposit bad signature loss, got $LOSS"
+ fi
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-coins.json`
-if test $OP != "deposit"
-then
- exit_fail "Wrong operation, got $OP"
-fi
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "deposit" ]
+ then
+ exit_fail "Wrong operation, got $OP"
+ fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong total bad sig loss, got $LOSS"
-fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong total bad sig loss, got $LOSS"
+ fi
-echo PASS
-# Undo:
-echo "UPDATE deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt $DB
+ echo PASS
+ # Undo:
+ echo "UPDATE exchange.deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt "$DB"
}
@@ -517,42 +740,44 @@ echo "UPDATE deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_seria
# Test where h_contract_terms in the deposit table is wrong
# (=> bad signature)
function test_5() {
-echo "===========5: deposit contract hash wrong================="
-# Modify h_wire hash, so it is inconsistent with 'wire'
-SERIAL=`echo "SELECT deposit_serial_id FROM deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql $DB -Aqt`
-OLD_H=`echo "SELECT h_contract_terms FROM deposits WHERE deposit_serial_id=$SERIAL;" | psql $DB -Aqt`
-echo "UPDATE deposits SET h_contract_terms='\x12bb676444955c98789f219148aa31899d8c354a63330624d3d143222cf3bb8b8e16f69accd5a8773127059b804c1955696bf551dd7be62719870613332aa8d5' WHERE deposit_serial_id=$SERIAL" | psql -Aqt $DB
+ echo "===========5: deposit contract hash wrong================="
+ # Modify h_wire hash, so it is inconsistent with 'wire'
+ SERIAL=$(echo "SELECT deposit_serial_id FROM exchange.deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql "$DB" -Aqt)
+ OLD_H=$(echo "SELECT h_contract_terms FROM exchange.deposits WHERE deposit_serial_id=$SERIAL;" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.deposits SET h_contract_terms='\x12bb676444955c98789f219148aa31899d8c354a63330624d3d143222cf3bb8b8e16f69accd5a8773127059b804c1955696bf551dd7be62719870613332aa8d5' WHERE deposit_serial_id=$SERIAL" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Checking bad signature detection... "
-ROW=`jq -e .bad_sig_losses[0].row < test-audit-coins.json`
-if test $ROW != $SERIAL
-then
- exit_fail "Row wrong, got $ROW"
-fi
+ echo -n "Checking bad signature detection... "
+ ROW=$(jq -e .bad_sig_losses[0].row < test-audit-coins.json)
+ if [ "$ROW" != "$SERIAL" ]
+ then
+ exit_fail "Row wrong, got $ROW"
+ fi
-LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong deposit bad signature loss, got $LOSS"
-fi
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong deposit bad signature loss, got $LOSS"
+ fi
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-coins.json`
-if test $OP != "deposit"
-then
- exit_fail "Wrong operation, got $OP"
-fi
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "deposit" ]
+ then
+ exit_fail "Wrong operation, got $OP"
+ fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong total bad sig loss, got $LOSS"
-fi
-echo PASS
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong total bad sig loss, got $LOSS"
+ fi
+ echo PASS
-# Undo:
-echo "UPDATE deposits SET h_contract_terms='${OLD_H}' WHERE deposit_serial_id=$SERIAL" | psql -Aqt $DB
+ # Undo:
+ echo "UPDATE exchange.deposits SET h_contract_terms='${OLD_H}' WHERE deposit_serial_id=$SERIAL" | psql -Aqt "$DB"
}
@@ -560,40 +785,42 @@ echo "UPDATE deposits SET h_contract_terms='${OLD_H}' WHERE deposit_serial_id=$S
# Test where denom_sig in known_coins table is wrong
# (=> bad signature)
function test_6() {
-echo "===========6: known_coins signature wrong================="
-# Modify denom_sig, so it is wrong
-OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt`
-COIN_PUB=`echo "SELECT coin_pub FROM known_coins WHERE denom_sig='$OLD_SIG';" | psql $DB -Aqt`
-echo "UPDATE known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" | psql -Aqt $DB
+ echo "===========6: known_coins signature wrong================="
+ # Modify denom_sig, so it is wrong
+ OLD_SIG=$(echo 'SELECT denom_sig FROM exchange.known_coins LIMIT 1;' | psql "$DB" -Aqt)
+ COIN_PUB=$(echo "SELECT coin_pub FROM exchange.known_coins WHERE denom_sig='$OLD_SIG';" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-ROW=`jq -e .bad_sig_losses[0].row < test-audit-coins.json`
-if test $ROW != "1"
-then
- exit_fail "Row wrong, got $ROW"
-fi
+ ROW=$(jq -e .bad_sig_losses[0].row < test-audit-coins.json)
+ if [ "$ROW" != "1" ]
+ then
+ exit_fail "Row wrong, got $ROW"
+ fi
-LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-coins.json`
-if test $LOSS == "TESTKUDOS:0"
-then
- exit_fail "Wrong deposit bad signature loss, got $LOSS"
-fi
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-coins.json)
+ if [ "$LOSS" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong deposit bad signature loss, got $LOSS"
+ fi
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-coins.json`
-if test $OP != "melt"
-then
- exit_fail "Wrong operation, got $OP"
-fi
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "melt" ]
+ then
+ exit_fail "Wrong operation, got $OP"
+ fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS == "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss, got $LOSS"
-fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss, got $LOSS"
+ fi
-# Undo
-echo "UPDATE known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" | psql -Aqt $DB
+ # Undo
+ echo "UPDATE exchange.known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" | psql -Aqt "$DB"
}
@@ -601,51 +828,53 @@ echo "UPDATE known_coins SET denom_sig='$OLD_SIG' WHERE coin_pub='$COIN_PUB'" |
# Test where h_wire in the deposit table is wrong
function test_7() {
-echo "===========7: reserves_out signature wrong================="
-# Modify reserve_sig, so it is bogus
-HBE=`echo 'SELECT h_blind_ev FROM reserves_out LIMIT 1;' | psql $DB -Aqt`
-OLD_SIG=`echo "SELECT reserve_sig FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt`
-A_VAL=`echo "SELECT amount_with_fee_val FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt`
-A_FRAC=`echo "SELECT amount_with_fee_frac FROM reserves_out WHERE h_blind_ev='$HBE';" | psql $DB -Aqt`
-# Normalize, we only deal with cents in this test-case
-A_FRAC=`expr $A_FRAC / 1000000 || true`
-echo "UPDATE reserves_out SET reserve_sig='\x9ef381a84aff252646a157d88eded50f708b2c52b7120d5a232a5b628f9ced6d497e6652d986b581188fb014ca857fd5e765a8ccc4eb7e2ce9edcde39accaa4b' WHERE h_blind_ev='$HBE'" | psql -Aqt $DB
-
-run_audit
-
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-reserves.json`
-if test $OP != "withdraw"
-then
- exit_fail "Wrong operation, got $OP"
-fi
+ echo "===========7: reserves_out signature wrong================="
+ # Modify reserve_sig, so it is bogus
+ HBE=$(echo 'SELECT h_blind_ev FROM exchange.reserves_out LIMIT 1;' | psql "$DB" -Aqt)
+ OLD_SIG=$(echo "SELECT reserve_sig FROM exchange.reserves_out WHERE h_blind_ev='$HBE';" | psql "$DB" -Aqt)
+ A_VAL=$(echo "SELECT amount_with_fee_val FROM exchange.reserves_out WHERE h_blind_ev='$HBE';" | psql "$DB" -Aqt)
+ A_FRAC=$(echo "SELECT amount_with_fee_frac FROM exchange.reserves_out WHERE h_blind_ev='$HBE';" | psql "$DB" -Aqt)
+ # Normalize, we only deal with cents in this test-case
+ A_FRAC=$(( A_FRAC / 1000000))
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.reserves_out SET reserve_sig='\x9ef381a84aff252646a157d88eded50f708b2c52b7120d5a232a5b628f9ced6d497e6652d986b581188fb014ca857fd5e765a8ccc4eb7e2ce9edcde39accaa4b' WHERE h_blind_ev='$HBE'" \
+ | psql -Aqt "$DB"
-LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-reserves.json`
-LOSS_TOTAL=`jq -r .total_bad_sig_loss < test-audit-reserves.json`
-if test $LOSS != $LOSS_TOTAL
-then
- exit_fail "Expected loss $LOSS and total loss $LOSS_TOTAL do not match"
-fi
-if test $A_FRAC != 0
-then
- if [ $A_FRAC -lt 10 ]
+ run_audit
+
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-reserves.json)
+ if [ "$OP" != "withdraw" ]
then
- A_PREV="0"
- else
- A_PREV=""
+ exit_fail "Wrong operation, got $OP"
fi
- if test $LOSS != "TESTKUDOS:$A_VAL.$A_PREV$A_FRAC"
+
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-reserves.json)
+ LOSS_TOTAL=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
+ if [ "$LOSS" != "$LOSS_TOTAL" ]
then
- exit_fail "Expected loss TESTKUDOS:$A_VAL.$A_PREV$A_FRAC but got $LOSS"
+ exit_fail "Expected loss $LOSS and total loss $LOSS_TOTAL do not match"
fi
-else
- if test $LOSS != "TESTKUDOS:$A_VAL"
+ if [ "$A_FRAC" != 0 ]
then
- exit_fail "Expected loss TESTKUDOS:$A_VAL but got $LOSS"
+ if [ "$A_FRAC" -lt 10 ]
+ then
+ A_PREV="0"
+ else
+ A_PREV=""
+ fi
+ if [ "$LOSS" != "TESTKUDOS:$A_VAL.$A_PREV$A_FRAC" ]
+ then
+ exit_fail "Expected loss TESTKUDOS:$A_VAL.$A_PREV$A_FRAC but got $LOSS"
+ fi
+ else
+ if [ "$LOSS" != "TESTKUDOS:$A_VAL" ]
+ then
+ exit_fail "Expected loss TESTKUDOS:$A_VAL but got $LOSS"
+ fi
fi
-fi
-# Undo:
-echo "UPDATE reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" | psql -Aqt $DB
+ # Undo:
+ echo "UPDATE exchange.reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" | psql -Aqt "$DB"
}
@@ -653,460 +882,459 @@ echo "UPDATE reserves_out SET reserve_sig='$OLD_SIG' WHERE h_blind_ev='$HBE'" |
# Test wire transfer subject disagreement!
function test_8() {
-echo "===========8: wire-transfer-subject disagreement==========="
-OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10' ORDER BY id LIMIT 1;" | psql $DB -Aqt`
-OLD_WTID=`echo "SELECT subject FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt`
-NEW_WTID="CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG"
-echo "UPDATE app_banktransaction SET subject='$NEW_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB
+ echo "===========8: wire-transfer-subject disagreement==========="
+ # Technically, this call shouldn't be needed, as libeufin should already be stopped here.
+ stop_libeufin
+ echo "FIXME: test needs update to new libeufin-bank schema"
+ exit 0
+ OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}" -Aqt) \
+ || exit_fail "Failed to SELECT FROM NexusBankTransactions nexus DB!"
+ OLD_WTID=$(echo "SELECT \"reservePublicKey\" FROM TalerIncomingPayments WHERE payment='$OLD_ID';" \
+ | psql "${DB}" -Aqt)
+ NEW_WTID="CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG"
+ echo "UPDATE TalerIncomingPayments SET \"reservePublicKey\"='$NEW_WTID' WHERE payment='$OLD_ID';" \
+ | psql "${DB}" -q \
+ || exit_fail "Failed to update TalerIncomingPayments"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-DIAG=`jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-audit-wire.json`
-if test "x$DIAG" != "xwire subject does not match"
-then
- exit_fail "Diagnostic wrong: $DIAG (0)"
-fi
-WTID=`jq -r .reserve_in_amount_inconsistencies[0].reserve_pub < test-audit-wire.json`
-if test x$WTID != x"$OLD_WTID" -a x$WTID != x"$NEW_WTID"
-then
- exit_fail "WTID reported wrong: $WTID"
-fi
-EX_A=`jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json`
-if test x$WTID = x$OLD_WTID -a x$EX_A != x"TESTKUDOS:10"
-then
- exit_fail "Amount reported wrong: $EX_A"
-fi
-if test x$WTID = x$NEW_WTID -a x$EX_A != x"TESTKUDOS:0"
-then
- exit_fail "Amount reported wrong: $EX_A"
-fi
-DIAG=`jq -r .reserve_in_amount_inconsistencies[1].diagnostic < test-audit-wire.json`
-if test "x$DIAG" != "xwire subject does not match"
-then
- exit_fail "Diagnostic wrong: $DIAG (1)"
-fi
-WTID=`jq -r .reserve_in_amount_inconsistencies[1].reserve_pub < test-audit-wire.json`
-if test $WTID != "$OLD_WTID" -a $WTID != "$NEW_WTID"
-then
- exit_fail "WTID reported wrong: $WTID (wanted: $NEW_WTID or $OLD_WTID)"
-fi
-EX_A=`jq -r .reserve_in_amount_inconsistencies[1].amount_exchange_expected < test-audit-wire.json`
-if test $WTID = "$OLD_WTID" -a $EX_A != "TESTKUDOS:10"
-then
- exit_fail "Amount reported wrong: $EX_A"
-fi
-if test $WTID = "$NEW_WTID" -a $EX_A != "TESTKUDOS:0"
-then
- exit_fail "Amount reported wrong: $EX_A"
-fi
+ echo -n "Testing inconsistency detection... "
+ DIAG=$(jq -r .reserve_in_amount_inconsistencies[0].diagnostic < test-audit-wire.json)
+ if [ "x$DIAG" != "xwire subject does not match" ]
+ then
+ exit_fail "Diagnostic wrong: $DIAG (0)"
+ fi
+ WTID=$(jq -r .reserve_in_amount_inconsistencies[0].reserve_pub < test-audit-wire.json)
+ if [ "$WTID" != "$OLD_WTID" ] && [ "$WTID" != "$NEW_WTID" ]
+ then
+ exit_fail "WTID reported wrong: $WTID (wanted $OLD_WTID or $NEW_WTID)"
+ fi
+ EX_A=$(jq -r .reserve_in_amount_inconsistencies[0].amount_exchange_expected < test-audit-wire.json)
+ if [ "$WTID" = "$OLD_WTID" ] && [ "$EX_A" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Amount reported wrong: $EX_A"
+ fi
+ if [ "$WTID" = "$NEW_WTID" ] && [ "$EX_A" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Amount reported wrong: $EX_A"
+ fi
+ DIAG=$(jq -r .reserve_in_amount_inconsistencies[1].diagnostic < test-audit-wire.json)
+ if [ "$DIAG" != "wire subject does not match" ]
+ then
+ exit_fail "Diagnostic wrong: $DIAG (1)"
+ fi
+ WTID=$(jq -r .reserve_in_amount_inconsistencies[1].reserve_pub < test-audit-wire.json)
+ if [ "$WTID" != "$OLD_WTID" ] && [ "$WTID" != "$NEW_WTID" ]
+ then
+ exit_fail "WTID reported wrong: $WTID (wanted: $NEW_WTID or $OLD_WTID)"
+ fi
+ EX_A=$(jq -r .reserve_in_amount_inconsistencies[1].amount_exchange_expected < test-audit-wire.json)
+ if [ "$WTID" = "$OLD_WTID" ] && [ "$EX_A" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Amount reported wrong: $EX_A"
+ fi
+ if [ "$WTID" = "$NEW_WTID" ] && [ "$EX_A" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Amount reported wrong: $EX_A"
+ fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:10"
-then
- exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
-fi
-DELTA=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $DELTA != "TESTKUDOS:10"
-then
- exit_fail "Expected total wire delta plus wrong, got $DELTA"
-fi
-echo PASS
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Wrong total wire_in_delta_minus, got $WIRED"
+ fi
+ DELTA=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$DELTA" != "TESTKUDOS:10" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $DELTA"
+ fi
+ echo "PASS"
-# Undo database modification
-echo "UPDATE app_banktransaction SET subject='$OLD_WTID' WHERE id='$OLD_ID';" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE TalerIncomingPayments SET \"reservePublicKey\"='$OLD_WTID' WHERE payment='$OLD_ID';" \
+ | psql "${DB}" -q
}
-
# Test wire origin disagreement!
function test_9() {
-echo "===========9: wire-origin disagreement==========="
-OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10' ORDER BY id LIMIT 1;" | psql $DB -Aqt`
-OLD_ACC=`echo "SELECT debit_account_id FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt`
-echo "UPDATE app_banktransaction SET debit_account_id=1 WHERE id='$OLD_ID';" | psql -Aqt $DB
+ echo "===========9: wire-origin disagreement==========="
+ # Technically, this call shouldn't be needed, as libeufin should already be stopped here.
+ stop_libeufin
+ echo "FIXME: test needs update to new libeufin-bank schema"
+ exit 0
+ OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}" -Aqt)
+ OLD_ACC=$(echo 'SELECT "incomingPaytoUri" FROM TalerIncomingPayments WHERE payment='"'$OLD_ID';" | psql "${DB}" -Aqt)
+ echo "UPDATE TalerIncomingPayments SET \"incomingPaytoUri\"='payto://iban/SANDBOXX/DE144373?receiver-name=New+Exchange+Company' WHERE payment='$OLD_ID';" \
+ | psql "${DB}" -q
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-AMOUNT=`jq -r .missattribution_in_inconsistencies[0].amount < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:10"
-then
- exit_fail "Reported amount wrong: $AMOUNT"
-fi
-AMOUNT=`jq -r .total_missattribution_in < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:10"
-then
- exit_fail "Reported total amount wrong: $AMOUNT"
-fi
-echo PASS
+ echo -n "Testing inconsistency detection... "
+ AMOUNT=$(jq -r .misattribution_in_inconsistencies[0].amount < test-audit-wire.json)
+ if test "x$AMOUNT" != "xTESTKUDOS:10"
+ then
+ exit_fail "Reported amount wrong: $AMOUNT"
+ fi
+ AMOUNT=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if test "x$AMOUNT" != "xTESTKUDOS:10"
+ then
+ exit_fail "Reported total amount wrong: $AMOUNT"
+ fi
+ echo PASS
-# Undo database modification
-echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC WHERE id='$OLD_ID';" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE TalerIncomingPayments SET \"incomingPaytoUri\"='$OLD_ACC' WHERE payment='$OLD_ID';" \
+ | psql "${DB}" -q
}
# Test wire_in timestamp disagreement!
function test_10() {
+ NOW_MS=$(date +%s)000
+ echo "===========10: wire-timestamp disagreement==========="
+ # Technically, this call shouldn't be needed, as libeufin should already be stopped here.
+ stop_libeufin
+ echo "FIXME: test needs update to new libeufin-bank schema"
+ exit 0
+ OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}" -Aqt)
+ OLD_DATE=$(echo "SELECT \"timestampMs\" FROM TalerIncomingPayments WHERE payment='$OLD_ID';" | psql "${DB}" -Aqt)
+ echo "UPDATE TalerIncomingPayments SET \"timestampMs\"=$NOW_MS WHERE payment=$OLD_ID;" | psql "${DB}" -q
-echo "===========10: wire-timestamp disagreement==========="
-OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10' ORDER BY id LIMIT 1;" | psql $DB -Aqt`
-OLD_DATE=`echo "SELECT date FROM app_banktransaction WHERE id='$OLD_ID';" | psql $DB -Aqt`
-echo "UPDATE app_banktransaction SET date=NOW() WHERE id=$OLD_ID;" | psql -Aqt $DB
-
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-audit-wire.json`
-if test "x$DIAG" != "xexecution date mismatch"
-then
- exit_fail "Reported diagnostic wrong: $DIAG"
-fi
-TABLE=`jq -r .row_minor_inconsistencies[0].table < test-audit-wire.json`
-if test "x$TABLE" != "xreserves_in"
-then
- exit_fail "Reported table wrong: $TABLE"
-fi
-echo PASS
+ echo -n "Testing inconsistency detection... "
+ DIAG=$(jq -r .row_minor_inconsistencies[0].diagnostic < test-audit-wire.json)
+ if test "x$DIAG" != "xexecution date mismatch"
+ then
+ exit_fail "Reported diagnostic wrong: $DIAG"
+ fi
+ TABLE=$(jq -r .row_minor_inconsistencies[0].table < test-audit-wire.json)
+ if test "x$TABLE" != "xreserves_in"
+ then
+ exit_fail "Reported table wrong: $TABLE"
+ fi
+ echo "PASS"
-# Undo database modification
-echo "UPDATE app_banktransaction SET date='$OLD_DATE' WHERE id=$OLD_ID;" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE TalerIncomingPayments SET \"timestampMs\"='$OLD_DATE' WHERE payment=$OLD_ID;" | psql "${DB}" -q
}
# Test for extra outgoing wire transfer.
+# In case of changing the subject in the Nexus
+# ingested table: '.batches[0].batchTransactions[0].details.unstructuredRemittanceInformation'
function test_11() {
+ echo "===========11: spurious outgoing transfer ==========="
+ # Technically, this call shouldn't be needed, as libeufin should already be stopped here.
+ stop_libeufin
+ echo "FIXME: test needs update to new libeufin-bank schema"
+ exit 0
+ OLD_ID=$(echo "SELECT id FROM NexusBankTransactions WHERE amount='10' AND currency='TESTKUDOS' ORDER BY id LIMIT 1;" | psql "${DB}" -Aqt)
+ OLD_TX=$(echo "SELECT \"transactionJson\" FROM NexusBankTransactions WHERE id='$OLD_ID';" | psql "${DB}" -Aqt)
+ # Change wire transfer to be FROM the exchange (#2) to elsewhere!
+ # (Note: this change also causes a missing incoming wire transfer, but
+ # this test is only concerned about the outgoing wire transfer
+ # being detected as such, and we simply ignore the other
+ # errors being reported.)
+ OTHER_IBAN=$(echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | psql "${DB}" -Aqt)
+ NEW_TX=$(echo "$OLD_TX" | jq .batches[0].batchTransactions[0].details.creditDebitIndicator='"DBIT"' | jq 'del(.batches[0].batchTransactions[0].details.debtor)' | jq 'del(.batches[0].batchTransactions[0].details.debtorAccount)' | jq 'del(.batches[0].batchTransactions[0].details.debtorAgent)' | jq '.batches[0].batchTransactions[0].details.creditor'='{"name": "Forty Two"}' | jq .batches[0].batchTransactions[0].details.creditorAccount='{"iban": "'"$OTHER_IBAN"'"}' | jq .batches[0].batchTransactions[0].details.creditorAgent='{"bic": "SANDBOXX"}' | jq .batches[0].batchTransactions[0].details.unstructuredRemittanceInformation='"CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/"')
+ echo -e "UPDATE NexusBankTransactions SET \"transactionJson\"='""$NEW_TX""' WHERE id=$OLD_ID" \
+ | psql "${DB}" -q
+ # Now fake that the exchange prepared this payment (= it POSTed to /transfer)
+ # This step is necessary, because the TWG table that accounts for outgoing
+ # payments needs it. Worth noting here is the column 'rawConfirmation' that
+ # points to the transaction from the main Nexus ledger; without that column set,
+ # a prepared payment won't appear as actually outgoing.
+ echo -e "INSERT INTO PaymentInitiations (\"bankAccount\",\"preparationDate\",\"submissionDate\",sum,currency,\"endToEndId\",\"paymentInformationId\",\"instructionId\",subject,\"creditorIban\",\"creditorBic\",\"creditorName\",submitted,\"messageId\",\"rawConfirmation\") VALUES (1,1,1,10,'TESTKUDOS','NOTGIVEN','unused','unused','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/','""$OTHER_IBAN""','SANDBOXX','Forty Two',false,1,$OLD_ID)" \
+ | psql "${DB}" -q
+ # Now populate the TWG table that accounts for outgoing payments, in
+ # order to let /history/outgoing return one result.
+ echo -e "INSERT INTO TalerRequestedPayments (facade,payment,\"requestUid\",amount,\"exchangeBaseUrl\",wtid,\"creditAccount\") VALUES (1,1,'unused','TESTKUDOS:10','http://exchange.example.com/','CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG','payto://iban/SANDBOXX/""$OTHER_IBAN""?receiver-name=Forty+Two')" \
+ | psql "${DB}" -q
-echo "===========11: spurious outgoing transfer ==========="
-OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE amount='TESTKUDOS:10' ORDER BY id LIMIT 1;" | psql $DB -Aqt`
-OLD_ACC=`echo "SELECT debit_account_id FROM app_banktransaction WHERE id=$OLD_ID;" | psql $DB -Aqt`
-OLD_SUBJECT=`echo "SELECT subject FROM app_banktransaction WHERE id=$OLD_ID;" | psql $DB -Aqt`
-# Change wire transfer to be FROM the exchange (#2) to elsewhere!
-# (Note: this change also causes a missing incoming wire transfer, but
-# this test is only concerned about the outgoing wire transfer
-# being detected as such, and we simply ignore the other
-# errors being reported.)
-echo -e "UPDATE app_banktransaction SET debit_account_id=2,credit_account_id=1,subject='CK9QBFY972KR32FVA1MW958JWACEB6XCMHHKVFMCH1A780Q12SVG http://exchange.example.com/' WHERE id=$OLD_ID;" | psql -Aqt $DB
-
-run_audit
-
-echo -n "Testing inconsistency detection... "
-AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:10"
-then
- exit_fail "Reported wired amount wrong: $AMOUNT"
-fi
-AMOUNT=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:10"
-then
- exit_fail "Reported total plus amount wrong: $AMOUNT"
-fi
-AMOUNT=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:0"
-then
- exit_fail "Reported total minus amount wrong: $AMOUNT"
-fi
-AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json`
-if test "x$AMOUNT" != "xTESTKUDOS:0"
-then
- exit_fail "Reported justified amount wrong: $AMOUNT"
-fi
-DIAG=`jq -r .wire_out_amount_inconsistencies[0].diagnostic < test-audit-wire.json`
-if test "x$DIAG" != "xjustification for wire transfer not found"
-then
- exit_fail "Reported diagnostic wrong: $DIAG"
-fi
-echo PASS
+ run_audit
-# Undo database modification (exchange always has account #2)
-echo "UPDATE app_banktransaction SET debit_account_id=$OLD_ACC,credit_account_id=2,subject='$OLD_SUBJECT' WHERE id=$OLD_ID;" | psql -Aqt $DB
+ echo -n "Testing inconsistency detection... "
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
+ if [ "x$AMOUNT" != "xTESTKUDOS:10" ]
+ then
+ exit_fail "Reported wired amount wrong: $AMOUNT"
+ fi
+ AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "x$AMOUNT" != "xTESTKUDOS:10" ]
+ then
+ exit_fail "Reported total plus amount wrong: $AMOUNT"
+ fi
+ AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "x$AMOUNT" != "xTESTKUDOS:0" ]
+ then
+ exit_fail "Reported total minus amount wrong: $AMOUNT"
+ fi
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json)
+ if [ "x$AMOUNT" != "xTESTKUDOS:0" ]
+ then
+ exit_fail "Reported justified amount wrong: $AMOUNT"
+ fi
+ DIAG=$(jq -r .wire_out_amount_inconsistencies[0].diagnostic < test-audit-wire.json)
+ if [ "x$DIAG" != "xjustification for wire transfer not found" ]
+ then
+ exit_fail "Reported diagnostic wrong: $DIAG"
+ fi
+ echo "PASS"
+ full_reload
}
-
# Test for hanging/pending refresh.
function test_12() {
-echo "===========12: incomplete refresh ==========="
-OLD_ACC=`echo "DELETE FROM refresh_revealed_coins;" | psql $DB -Aqt`
-
-run_audit
-
-echo -n "Testing hung refresh detection... "
-
-HANG=`jq -er .refresh_hanging[0].amount < test-audit-coins.json`
-TOTAL_HANG=`jq -er .total_refresh_hanging < test-audit-coins.json`
-if test x$HANG = TESTKUDOS:0
-then
- exit_fail "Hanging amount zero"
-fi
-if test x$TOTAL_HANG = TESTKUDOS:0
-then
- exit_fail "Total hanging amount zero"
-fi
+ echo "===========12: incomplete refresh ==========="
+ OLD_ACC=$(echo "DELETE FROM exchange.refresh_revealed_coins;" | psql "$DB" -Aqt)
-echo PASS
+ run_audit
+ echo -n "Testing hung refresh detection... "
-# cannot easily undo DELETE, hence full reload
-full_reload
+ HANG=$(jq -er .refresh_hanging[0].amount < test-audit-coins.json)
+ TOTAL_HANG=$(jq -er .total_refresh_hanging < test-audit-coins.json)
+ if [ "$HANG" = "TESTKUDOS:0" ]
+ then
+ exit_fail "Hanging amount zero"
+ fi
+ if [ "$TOTAL_HANG" = "TESTKUDOS:0" ]
+ then
+ exit_fail "Total hanging amount zero"
+ fi
+ echo "PASS"
+ # cannot easily undo DELETE, hence full reload
+ full_reload
}
# Test for wrong signature on refresh.
function test_13() {
-echo "===========13: wrong melt signature ==========="
-# Modify denom_sig, so it is wrong
-COIN_PUB=`echo "SELECT old_coin_pub FROM refresh_commitments LIMIT 1;" | psql $DB -Aqt`
-OLD_SIG=`echo "SELECT old_coin_sig FROM refresh_commitments WHERE old_coin_pub='$COIN_PUB';" | psql $DB -Aqt`
-NEW_SIG="\xba588af7c13c477dca1ac458f65cc484db8fba53b969b873f4353ecbd815e6b4c03f42c0cb63a2b609c2d726e612fd8e0c084906a41f409b6a23a08a83c89a02"
-echo "UPDATE refresh_commitments SET old_coin_sig='$NEW_SIG' WHERE old_coin_pub='$COIN_PUB'" | psql -Aqt $DB
+ echo "===========13: wrong melt signature ==========="
+ # Modify denom_sig, so it is wrong
+ COIN_PUB=$(echo "SELECT old_coin_pub FROM exchange.refresh_commitments LIMIT 1;" | psql "$DB" -Aqt)
+ OLD_SIG=$(echo "SELECT old_coin_sig FROM exchange.refresh_commitments WHERE old_coin_pub='$COIN_PUB';" | psql "$DB" -Aqt)
+ NEW_SIG="\xba588af7c13c477dca1ac458f65cc484db8fba53b969b873f4353ecbd815e6b4c03f42c0cb63a2b609c2d726e612fd8e0c084906a41f409b6a23a08a83c89a02"
+ echo "UPDATE exchange.refresh_commitments SET old_coin_sig='$NEW_SIG' WHERE old_coin_pub='$COIN_PUB'" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
+ echo -n "Testing inconsistency detection... "
-OP=`jq -er .bad_sig_losses[0].operation < test-audit-coins.json`
-if test x$OP != xmelt
-then
- exit_fail "Operation wrong, got $OP"
-fi
+ OP=$(jq -er .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "melt" ]
+ then
+ exit_fail "Operation wrong, got $OP"
+ fi
-LOSS=`jq -er .bad_sig_losses[0].loss < test-audit-coins.json`
-TOTAL_LOSS=`jq -er .total_bad_sig_loss < test-audit-coins.json`
-if test x$LOSS != x$TOTAL_LOSS
-then
- exit_fail "Loss inconsistent, got $LOSS and $TOTAL_LOSS"
-fi
-if test x$TOTAL_LOSS = TESTKUDOS:0
-then
- exit_fail "Loss zero"
-fi
+ LOSS=$(jq -er .bad_sig_losses[0].loss < test-audit-coins.json)
+ TOTAL_LOSS=$(jq -er .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "$TOTAL_LOSS" ]
+ then
+ exit_fail "Loss inconsistent, got $LOSS and $TOTAL_LOSS"
+ fi
+ if [ "$TOTAL_LOSS" = "TESTKUDOS:0" ]
+ then
+ exit_fail "Loss zero"
+ fi
-echo PASS
+ echo "PASS"
-# cannot easily undo DELETE, hence full reload
-full_reload
+ # cannot easily undo DELETE, hence full reload
+ full_reload
}
# Test for wire fee disagreement
function test_14() {
-echo "===========14: wire-fee disagreement==========="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-wire-auditor.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========14: wire-fee disagreement==========="
# Wire fees are only checked/generated once there are
# actual outgoing wire transfers, so we need to run the
# aggregator here.
pre_audit aggregator
- echo "UPDATE wire_fee SET wire_fee_frac=100;" | psql -Aqt $DB
+ echo "UPDATE exchange.wire_fee SET wire_fee_frac=100;" \
+ | psql -Aqt "$DB"
audit_only
post_audit
echo -n "Testing inconsistency detection... "
- TABLE=`jq -r .row_inconsistencies[0].table < test-audit-aggregation.json`
- if test "x$TABLE" != "xwire-fee"
+ TABLE=$(jq -r .row_inconsistencies[0].table < test-audit-aggregation.json)
+ if [ "$TABLE" != "wire-fee" ]
then
exit_fail "Reported table wrong: $TABLE"
fi
- DIAG=`jq -r .row_inconsistencies[0].diagnostic < test-audit-aggregation.json`
- if test "x$DIAG" != "xwire fee signature invalid at given time"
+ DIAG=$(jq -r .row_inconsistencies[0].diagnostic < test-audit-aggregation.json)
+ if [ "$DIAG" != "wire fee signature invalid at given time" ]
then
exit_fail "Reported diagnostic wrong: $DIAG"
fi
- echo PASS
+ echo "PASS"
# cannot easily undo aggregator, hence full reload
full_reload
-
-else
- echo "Test skipped (database too new)"
-fi
-
}
# Test where salt in the deposit table is wrong
function test_15() {
-echo "===========15: deposit wire salt wrong================="
+ echo "===========15: deposit wire salt wrong================="
-# Modify wire_salt hash, so it is inconsistent
-SALT=`echo "SELECT wire_salt FROM deposits WHERE deposit_serial_id=1;" | psql -Aqt $DB`
-echo "UPDATE deposits SET wire_salt='\x1197cd7f7b0e13ab1905fedb36c536a2' WHERE deposit_serial_id=1;" | psql -Aqt $DB
+ # Modify wire_salt hash, so it is inconsistent
+ SALT=$(echo "SELECT wire_salt FROM exchange.deposits WHERE deposit_serial_id=1;" | psql -Aqt "$DB")
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.deposits SET wire_salt='\x1197cd7f7b0e13ab1905fedb36c536a2' WHERE deposit_serial_id=1;" \
+ | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-coins.json`
-if test "x$OP" != "xdeposit"
-then
- exit_fail "Reported operation wrong: $OP"
-fi
-echo PASS
+ echo -n "Testing inconsistency detection... "
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "deposit" ]
+ then
+ exit_fail "Reported operation wrong: $OP"
+ fi
+ echo "PASS"
-# Restore DB
-echo "UPDATE deposits SET wire_salt='$SALT' WHERE deposit_serial_id=1;" | psql -Aqt $DB
+ # Restore DB
+ echo "UPDATE exchange.deposits SET wire_salt='$SALT' WHERE deposit_serial_id=1;" \
+ | psql -Aqt "$DB"
}
# Test where wired amount (wire out) is wrong
function test_16() {
-echo "===========16: incorrect wire_out amount================="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========16: incorrect wire_out amount================="
+
+ # Check wire transfer lag reported (no aggregator!)
# First, we need to run the aggregator so we even
# have a wire_out to modify.
pre_audit aggregator
- # Modify wire amount, such that it is inconsistent with 'aggregation'
- # (exchange account is #2, so the logic below should select the outgoing
- # wire transfer):
- OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE debit_account_id=2 ORDER BY id LIMIT 1;" | psql $DB -Aqt`
- OLD_AMOUNT=`echo "SELECT amount FROM app_banktransaction WHERE id='${OLD_ID}';" | psql $DB -Aqt`
+ stop_libeufin
+ OLD_AMOUNT=$(echo "SELECT amount FROM TalerRequestedPayments WHERE id='1';" | psql "${DB}" -Aqt)
NEW_AMOUNT="TESTKUDOS:50"
- echo "UPDATE app_banktransaction SET amount='${NEW_AMOUNT}' WHERE id='${OLD_ID}';" | psql -Aqt $DB
-
+ echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" \
+ | psql "${DB}" -q
+ launch_libeufin
audit_only
echo -n "Testing inconsistency detection... "
- AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json`
- if test "x$AMOUNT" != "x$OLD_AMOUNT"
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json)
+ if [ "$AMOUNT" != "$OLD_AMOUNT" ]
then
exit_fail "Reported justified amount wrong: $AMOUNT"
fi
- AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json`
- if test "x$AMOUNT" != "x$NEW_AMOUNT"
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
+ if [ "$AMOUNT" != "$NEW_AMOUNT" ]
then
exit_fail "Reported wired amount wrong: $AMOUNT"
fi
- TOTAL_AMOUNT=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
- if test "x$TOTAL_AMOUNT" != "xTESTKUDOS:0"
+ TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$TOTAL_AMOUNT" != "TESTKUDOS:0" ]
then
exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT"
fi
- TOTAL_AMOUNT=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
- if test "x$TOTAL_AMOUNT" = "xTESTKUDOS:0"
+ TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$TOTAL_AMOUNT" = "TESTKUDOS:0" ]
then
exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT"
fi
- echo PASS
+ echo "PASS"
+ stop_libeufin
echo "Second modification: wire nothing"
NEW_AMOUNT="TESTKUDOS:0"
- echo "UPDATE app_banktransaction SET amount='${NEW_AMOUNT}' WHERE id='${OLD_ID}';" | psql -Aqt $DB
-
+ echo "UPDATE TalerRequestedPayments SET amount='${NEW_AMOUNT}' WHERE id='1';" \
+ | psql "${DB}" -q
+ launch_libeufin
audit_only
-
+ stop_libeufin
echo -n "Testing inconsistency detection... "
- AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json`
- if test "x$AMOUNT" != "x$OLD_AMOUNT"
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_justified < test-audit-wire.json)
+ if [ "$AMOUNT" != "$OLD_AMOUNT" ]
then
exit_fail "Reported justified amount wrong: $AMOUNT"
fi
- AMOUNT=`jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json`
- if test "x$AMOUNT" != "x$NEW_AMOUNT"
+ AMOUNT=$(jq -r .wire_out_amount_inconsistencies[0].amount_wired < test-audit-wire.json)
+ if [ "$AMOUNT" != "$NEW_AMOUNT" ]
then
exit_fail "Reported wired amount wrong: $AMOUNT"
fi
- TOTAL_AMOUNT=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
- if test "x$TOTAL_AMOUNT" != "x$OLD_AMOUNT"
+ TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$TOTAL_AMOUNT" != "$OLD_AMOUNT" ]
then
exit_fail "Reported total wired amount minus wrong: $TOTAL_AMOUNT (wanted $OLD_AMOUNT)"
fi
- TOTAL_AMOUNT=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
- if test "x$TOTAL_AMOUNT" != "xTESTKUDOS:0"
+ TOTAL_AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$TOTAL_AMOUNT" != "TESTKUDOS:0" ]
then
exit_fail "Reported total wired amount plus wrong: $TOTAL_AMOUNT"
fi
- echo PASS
+ echo "PASS"
post_audit
# cannot easily undo aggregator, hence full reload
full_reload
-else
- echo "Test skipped (database too new)"
-fi
-
}
-
# Test where wire-out timestamp is wrong
function test_17() {
-echo "===========17: incorrect wire_out timestamp================="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========17: incorrect wire_out timestamp================="
# First, we need to run the aggregator so we even
# have a wire_out to modify.
pre_audit aggregator
-
- # Modify wire amount, such that it is inconsistent with 'aggregation'
- # (exchange account is #2, so the logic below should select the outgoing
- # wire transfer):
- OLD_ID=`echo "SELECT id FROM app_banktransaction WHERE debit_account_id=2 ORDER BY id LIMIT 1;" | psql $DB -Aqt`
- OLD_DATE=`echo "SELECT date FROM app_banktransaction WHERE id='${OLD_ID}';" | psql $DB -Aqt`
+ stop_libeufin
+ OLD_ID=1
+ OLD_PREP=$(echo "SELECT payment FROM TalerRequestedPayments WHERE id='${OLD_ID}';" | psql "${DB}" -Aqt)
+ OLD_DATE=$(echo "SELECT \"preparationDate\" FROM PaymentInitiations WHERE id='${OLD_ID}';" | psql "${DB}" -Aqt)
# Note: need - interval '1h' as "NOW()" may otherwise be exactly what is already in the DB
# (due to rounding, if this machine is fast...)
- echo "UPDATE app_banktransaction SET date=NOW()- interval '1 hour' WHERE id='${OLD_ID}';" | psql -Aqt $DB
-
+ NOW_1HR=$(( $(date +%s) - 3600))
+ echo "UPDATE PaymentInitiations SET \"preparationDate\"='$NOW_1HR' WHERE id='${OLD_PREP}';" \
+ | psql "${DB}" -q
+ launch_libeufin
+ echo "DONE"
audit_only
post_audit
echo -n "Testing inconsistency detection... "
- TABLE=`jq -r .row_minor_inconsistencies[0].table < test-audit-wire.json`
- if test "x$TABLE" != "xwire_out"
+ TABLE=$(jq -r .row_minor_inconsistencies[0].table < test-audit-wire.json)
+ if [ "$TABLE" != "wire_out" ]
then
exit_fail "Reported table wrong: $TABLE"
fi
- DIAG=`jq -r .row_minor_inconsistencies[0].diagnostic < test-audit-wire.json`
- DIAG=`echo "$DIAG" | awk '{print $1 " " $2 " " $3}'`
- if test "x$DIAG" != "xexecution date mismatch"
+ DIAG=$(jq -r .row_minor_inconsistencies[0].diagnostic < test-audit-wire.json)
+ DIAG=$(echo "$DIAG" | awk '{print $1 " " $2 " " $3}')
+ if [ "$DIAG" != "execution date mismatch" ]
then
exit_fail "Reported diagnostic wrong: $DIAG"
fi
- echo PASS
+ echo "PASS"
# cannot easily undo aggregator, hence full reload
full_reload
-
-else
- echo "Test skipped (database too new)"
-fi
-
}
@@ -1114,64 +1342,67 @@ fi
# Test where we trigger an emergency.
function test_18() {
-echo "===========18: emergency================="
-
-echo "DELETE FROM reserves_out;" | psql -Aqt $DB
+ echo "===========18: emergency================="
-run_audit
+ echo "DELETE FROM exchange.reserves_out;" \
+ | psql -Aqt "$DB" -q
-echo -n "Testing emergency detection... "
-
-jq -e .reserve_balance_summary_wrong_inconsistencies[0] < test-audit-reserves.json > /dev/null || exit_fail "Reserve balance inconsistency not detected"
-
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null || exit_fail "Emergency not detected"
-jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null || exit_fail "Emergency by count not detected"
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null || exit_fail "Escrow balance calculation impossibility not detected"
-
-echo PASS
-
-echo -n "Testing loss calculation... "
+ run_audit
-AMOUNT=`jq -r .emergencies_loss < test-audit-coins.json`
-if test "x$AMOUNT" == "xTESTKUDOS:0"
-then
- exit_fail "Reported amount wrong: $AMOUNT"
-fi
-AMOUNT=`jq -r .emergencies_loss_by_count < test-audit-coins.json`
-if test "x$AMOUNT" == "xTESTKUDOS:0"
-then
- exit_fail "Reported amount wrong: $AMOUNT"
-fi
+ echo -n "Testing emergency detection... "
+ jq -e .reserve_balance_summary_wrong_inconsistencies[0] \
+ < test-audit-reserves.json \
+ > /dev/null \
+ || exit_fail "Reserve balance inconsistency not detected"
+ jq -e .emergencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ || exit_fail "Emergency not detected"
+ jq -e .emergencies_by_count[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ || exit_fail "Emergency by count not detected"
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ || exit_fail "Escrow balance calculation impossibility not detected"
+ echo "PASS"
-echo PASS
+ echo -n "Testing loss calculation... "
+ AMOUNT=$(jq -r .emergencies_loss < test-audit-coins.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Reported amount wrong: $AMOUNT"
+ fi
+ AMOUNT=$(jq -r .emergencies_loss_by_count < test-audit-coins.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Reported amount wrong: $AMOUNT"
+ fi
+ echo "PASS"
-# cannot easily undo broad DELETE operation, hence full reload
-full_reload
+ # cannot easily undo broad DELETE operation, hence full reload
+ full_reload
}
# Test where reserve closure was done properly
function test_19() {
-echo "===========19: reserve closure done properly ================="
-
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========19: reserve closure done properly ================="
- OLD_TIME=`echo "SELECT execution_date FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- OLD_VAL=`echo "SELECT credit_val FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- RES_PUB=`echo "SELECT reserve_pub FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- OLD_EXP=`echo "SELECT expiration_date FROM reserves WHERE reserve_pub='${RES_PUB}';" | psql $DB -Aqt`
+ OLD_TIME=$(echo "SELECT execution_date FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ OLD_VAL=$(echo "SELECT credit_val FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ RES_PUB=$(echo "SELECT reserve_pub FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ OLD_EXP=$(echo "SELECT expiration_date FROM exchange.reserves WHERE reserve_pub='${RES_PUB}';" | psql "$DB" -Aqt)
VAL_DELTA=1
- NEW_TIME=`expr $OLD_TIME - 3024000000000 || true` # 5 weeks
- NEW_EXP=`expr $OLD_EXP - 3024000000000 || true` # 5 weeks
- NEW_CREDIT=`expr $OLD_VAL + $VAL_DELTA || true`
- echo "UPDATE reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB
- echo "UPDATE reserves SET current_balance_val=${VAL_DELTA}+current_balance_val,expiration_date='${NEW_EXP}' WHERE reserve_pub='${RES_PUB}';" | psql -Aqt $DB
+ NEW_TIME=$(( OLD_TIME - 3024000000000)) # 5 weeks
+ NEW_EXP=$(( OLD_EXP - 3024000000000)) # 5 weeks
+ NEW_CREDIT=$(( OLD_VAL + VAL_DELTA))
+ echo "UPDATE exchange.reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" \
+ | psql -Aqt "$DB"
+ echo "UPDATE exchange.reserves SET current_balance_val=${VAL_DELTA}+current_balance_val,expiration_date='${NEW_EXP}' WHERE reserve_pub='${RES_PUB}';" \
+ | psql -Aqt "$DB"
# Need to run with the aggregator so the reserve closure happens
run_audit aggregator
@@ -1189,88 +1420,90 @@ then
# cannot easily undo aggregator, hence full reload
full_reload
-
-else
- echo "Test skipped (database too new)"
-fi
}
# Test where reserve closure was not done properly
function test_20() {
-echo "===========20: reserve closure missing ================="
-
-OLD_TIME=`echo "SELECT execution_date FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
-OLD_VAL=`echo "SELECT credit_val FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
-RES_PUB=`echo "SELECT reserve_pub FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
-NEW_TIME=`expr $OLD_TIME - 3024000000000 || true` # 5 weeks
-NEW_CREDIT=`expr $OLD_VAL + 100 || true`
-echo "UPDATE reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB
-echo "UPDATE reserves SET current_balance_val=100+current_balance_val WHERE reserve_pub='${RES_PUB}';" | psql -Aqt $DB
-
-# This time, run without the aggregator so the reserve closure is skipped!
-run_audit
+ echo "===========20: reserve closure missing ================="
+
+ OLD_TIME=$(echo "SELECT execution_date FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ OLD_VAL=$(echo "SELECT credit_val FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ RES_PUB=$(echo "SELECT reserve_pub FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ NEW_TIME=$(( OLD_TIME - 3024000000000 )) # 5 weeks
+ NEW_CREDIT=$(( OLD_VAL + 100 ))
+ echo "UPDATE exchange.reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" \
+ | psql -Aqt "$DB"
+ echo "UPDATE exchange.reserves SET current_balance_val=100+current_balance_val WHERE reserve_pub='${RES_PUB}';" \
+ | psql -Aqt "$DB"
+
+ # This time, run without the aggregator so the reserve closure is skipped!
+ run_audit
-echo -n "Testing reserve closure missing detected... "
-jq -e .reserve_not_closed_inconsistencies[0] < test-audit-reserves.json > /dev/null || exit_fail "Reserve not closed inconsistency not detected"
-echo "PASS"
+ echo -n "Testing reserve closure missing detected... "
+ jq -e .reserve_not_closed_inconsistencies[0] \
+ < test-audit-reserves.json \
+ > /dev/null \
+ || exit_fail "Reserve not closed inconsistency not detected"
+ echo "PASS"
-AMOUNT=`jq -r .total_balance_reserve_not_closed < test-audit-reserves.json`
-if test "x$AMOUNT" == "xTESTKUDOS:0"
-then
- exit_fail "Reported total amount wrong: $AMOUNT"
-fi
+ AMOUNT=$(jq -r .total_balance_reserve_not_closed < test-audit-reserves.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Reported total amount wrong: $AMOUNT"
+ fi
-# Undo
-echo "UPDATE reserves_in SET execution_date='${OLD_TIME}',credit_val=${OLD_VAL} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB
-echo "UPDATE reserves SET current_balance_val=current_balance_val-100 WHERE reserve_pub='${RES_PUB}';" | psql -Aqt $DB
+ # Undo
+ echo "UPDATE exchange.reserves_in SET execution_date='${OLD_TIME}',credit_val=${OLD_VAL} WHERE reserve_in_serial_id=1;" \
+ | psql -Aqt "$DB"
+ echo "UPDATE exchange.reserves SET current_balance_val=current_balance_val-100 WHERE reserve_pub='${RES_PUB}';" \
+ | psql -Aqt "$DB"
}
# Test reserve closure reported but wire transfer missing detection
function test_21() {
-echo "===========21: reserve closure missreported ================="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========21: reserve closure missreported ================="
- OLD_TIME=`echo "SELECT execution_date FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- OLD_VAL=`echo "SELECT credit_val FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- RES_PUB=`echo "SELECT reserve_pub FROM reserves_in WHERE reserve_in_serial_id=1;" | psql $DB -Aqt`
- OLD_EXP=`echo "SELECT expiration_date FROM reserves WHERE reserve_pub='${RES_PUB}';" | psql $DB -Aqt`
+ OLD_TIME=$(echo "SELECT execution_date FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ OLD_VAL=$(echo "SELECT credit_val FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ RES_PUB=$(echo "SELECT reserve_pub FROM exchange.reserves_in WHERE reserve_in_serial_id=1;" | psql "$DB" -Aqt)
+ OLD_EXP=$(echo "SELECT expiration_date FROM exchange.reserves WHERE reserve_pub='${RES_PUB}';" | psql "$DB" -Aqt)
VAL_DELTA=1
- NEW_TIME=`expr $OLD_TIME - 3024000000000 || true` # 5 weeks
- NEW_EXP=`expr $OLD_EXP - 3024000000000 || true` # 5 weeks
- NEW_CREDIT=`expr $OLD_VAL + $VAL_DELTA || true`
- echo "UPDATE reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" | psql -Aqt $DB
- echo "UPDATE reserves SET current_balance_val=${VAL_DELTA}+current_balance_val,expiration_date='${NEW_EXP}' WHERE reserve_pub='${RES_PUB}';" | psql -Aqt $DB
+ NEW_TIME=$(( OLD_TIME - 3024000000000 )) # 5 weeks
+ NEW_EXP=$(( OLD_EXP - 3024000000000 )) # 5 weeks
+ NEW_CREDIT=$(( OLD_VAL + VAL_DELTA ))
+ echo "UPDATE exchange.reserves_in SET execution_date='${NEW_TIME}',credit_val=${NEW_CREDIT} WHERE reserve_in_serial_id=1;" \
+ | psql -Aqt "$DB"
+ echo "UPDATE exchange.reserves SET current_balance_val=${VAL_DELTA}+current_balance_val,expiration_date='${NEW_EXP}' WHERE reserve_pub='${RES_PUB}';" \
+ | psql -Aqt "$DB"
# Need to first run the aggregator so the transfer is marked as done exists
pre_audit aggregator
-
+ stop_libeufin
# remove transaction from bank DB
- echo "DELETE FROM app_banktransaction WHERE debit_account_id=2 AND amount='TESTKUDOS:${VAL_DELTA}';" | psql -Aqt $DB
-
+ # Currently emulating this (to be deleted):
+ echo "DELETE FROM TalerRequestedPayments WHERE amount='TESTKUDOS:${VAL_DELTA}'" \
+ | psql "${DB}" -q
+ launch_libeufin
audit_only
post_audit
echo -n "Testing lack of reserve closure transaction detected... "
- jq -e .reserve_lag_details[0] < test-audit-wire.json > /dev/null || exit_fail "Reserve closure lag not detected"
+ jq -e .reserve_lag_details[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ || exit_fail "Reserve closure lag not detected"
- AMOUNT=`jq -r .reserve_lag_details[0].amount < test-audit-wire.json`
- if test "x$AMOUNT" != "xTESTKUDOS:${VAL_DELTA}"
+ AMOUNT=$(jq -r .reserve_lag_details[0].amount < test-audit-wire.json)
+ if [ "$AMOUNT" != "TESTKUDOS:${VAL_DELTA}" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
- AMOUNT=`jq -r .total_closure_amount_lag < test-audit-wire.json`
- if test "x$AMOUNT" != "xTESTKUDOS:${VAL_DELTA}"
+ AMOUNT=$(jq -r .total_closure_amount_lag < test-audit-wire.json)
+ if [ "$AMOUNT" != "TESTKUDOS:${VAL_DELTA}" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
@@ -1279,35 +1512,32 @@ then
# cannot easily undo aggregator, hence full reload
full_reload
-else
- echo "Test skipped (database too new)"
-fi
}
# Test use of withdraw-expired denomination key
function test_22() {
-echo "===========22: denomination key expired ================="
+ echo "===========22: denomination key expired ================="
-S_DENOM=`echo 'SELECT denominations_serial FROM reserves_out LIMIT 1;' | psql $DB -Aqt`
+ S_DENOM=$(echo 'SELECT denominations_serial FROM exchange.reserves_out LIMIT 1;' | psql "$DB" -Aqt)
-OLD_START=`echo "SELECT valid_from FROM denominations WHERE denominations_serial='${S_DENOM}';" | psql $DB -Aqt`
-OLD_WEXP=`echo "SELECT expire_withdraw FROM denominations WHERE denominations_serial='${S_DENOM}';" | psql $DB -Aqt`
-# Basically expires 'immediately', so that the withdraw must have been 'invalid'
-NEW_WEXP=$OLD_START
+ OLD_START=$(echo "SELECT valid_from FROM exchange.denominations WHERE denominations_serial='${S_DENOM}';" | psql "$DB" -Aqt)
+ OLD_WEXP=$(echo "SELECT expire_withdraw FROM exchange.denominations WHERE denominations_serial='${S_DENOM}';" | psql "$DB" -Aqt)
+ # Basically expires 'immediately', so that the withdraw must have been 'invalid'
+ NEW_WEXP=$OLD_START
-echo "UPDATE denominations SET expire_withdraw=${NEW_WEXP} WHERE denominations_serial='${S_DENOM}';" | psql -Aqt $DB
+ echo "UPDATE exchange.denominations SET expire_withdraw=${NEW_WEXP} WHERE denominations_serial='${S_DENOM}';" | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null || exit_fail "Denomination key withdraw inconsistency for $S_DENOM not detected"
+ echo -n "Testing inconsistency detection... "
+ jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null || exit_fail "Denomination key withdraw inconsistency for $S_DENOM not detected"
-echo PASS
+ echo "PASS"
-# Undo modification
-echo "UPDATE denominations SET expire_withdraw=${OLD_WEXP} WHERE denominations_serial='${S_DENOM}';" | psql -Aqt $DB
+ # Undo modification
+ echo "UPDATE exchange.denominations SET expire_withdraw=${OLD_WEXP} WHERE denominations_serial='${S_DENOM}';" | psql -Aqt "$DB"
}
@@ -1315,50 +1545,46 @@ echo "UPDATE denominations SET expire_withdraw=${OLD_WEXP} WHERE denominations_s
# Test calculation of wire-out amounts
function test_23() {
-echo "===========23: wire out calculations ================="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========23: wire out calculations ================="
# Need to first run the aggregator so the transfer is marked as done exists
pre_audit aggregator
- OLD_AMOUNT=`echo "SELECT amount_frac FROM wire_out WHERE wireout_uuid=1;" | psql $DB -Aqt`
- NEW_AMOUNT=`expr $OLD_AMOUNT - 1000000 || true`
- echo "UPDATE wire_out SET amount_frac=${NEW_AMOUNT} WHERE wireout_uuid=1;" | psql -Aqt $DB
+ OLD_AMOUNT=$(echo "SELECT amount_frac FROM exchange.wire_out WHERE wireout_uuid=1;" | psql "$DB" -Aqt)
+ NEW_AMOUNT=$(( OLD_AMOUNT - 1000000 ))
+ echo "UPDATE exchange.wire_out SET amount_frac=${NEW_AMOUNT} WHERE wireout_uuid=1;" \
+ | psql -Aqt "$DB"
audit_only
post_audit
echo -n "Testing inconsistency detection... "
- jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null || exit_fail "Wire out inconsistency not detected"
+ jq -e .wire_out_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ || exit_fail "Wire out inconsistency not detected"
- ROW=`jq .wire_out_inconsistencies[0].rowid < test-audit-aggregation.json`
- if test $ROW != 1
+ ROW=$(jq .wire_out_inconsistencies[0].rowid < test-audit-aggregation.json)
+ if [ "$ROW" != 1 ]
then
exit_fail "Row wrong"
fi
- AMOUNT=`jq -r .total_wire_out_delta_plus < test-audit-aggregation.json`
- if test "x$AMOUNT" != "xTESTKUDOS:0"
+ AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-aggregation.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0" ]
then
exit_fail "Reported amount wrong: $AMOUNT"
fi
- AMOUNT=`jq -r .total_wire_out_delta_minus < test-audit-aggregation.json`
- if test "x$AMOUNT" != "xTESTKUDOS:0.01"
+ AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-aggregation.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0.01" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
- echo PASS
+ echo "PASS"
echo "Second pass: changing how amount is wrong to other direction"
- NEW_AMOUNT=`expr $OLD_AMOUNT + 1000000 || true`
- echo "UPDATE wire_out SET amount_frac=${NEW_AMOUNT} WHERE wireout_uuid=1;" | psql -Aqt $DB
+ NEW_AMOUNT=$(( OLD_AMOUNT + 1000000 ))
+ echo "UPDATE exchange.wire_out SET amount_frac=${NEW_AMOUNT} WHERE wireout_uuid=1;" | psql -Aqt "$DB"
pre_audit
audit_only
@@ -1368,29 +1594,25 @@ then
jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null || exit_fail "Wire out inconsistency not detected"
- ROW=`jq .wire_out_inconsistencies[0].rowid < test-audit-aggregation.json`
- if test $ROW != 1
+ ROW=$(jq .wire_out_inconsistencies[0].rowid < test-audit-aggregation.json)
+ if [ "$ROW" != 1 ]
then
exit_fail "Row wrong"
fi
- AMOUNT=`jq -r .total_wire_out_delta_minus < test-audit-aggregation.json`
- if test "x$AMOUNT" != "xTESTKUDOS:0"
+ AMOUNT=$(jq -r .total_wire_out_delta_minus < test-audit-aggregation.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0" ]
then
exit_fail "Reported amount wrong: $AMOUNT"
fi
- AMOUNT=`jq -r .total_wire_out_delta_plus < test-audit-aggregation.json`
- if test "x$AMOUNT" != "xTESTKUDOS:0.01"
+ AMOUNT=$(jq -r .total_wire_out_delta_plus < test-audit-aggregation.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0.01" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
- echo PASS
-
+ echo "PASS"
# cannot easily undo aggregator, hence full reload
full_reload
-else
- echo "Test skipped (database too new)"
-fi
}
@@ -1398,179 +1620,173 @@ fi
# Test for missing deposits in exchange database.
function test_24() {
-echo "===========24: deposits missing ==========="
-# Modify denom_sig, so it is wrong
-CNT=`echo "SELECT COUNT(*) FROM deposit_confirmations;" | psql -Aqt $DB`
-if test x$CNT = x0
-then
- echo "Skipping deposits missing test: no deposit confirmations in database!"
-else
- echo "DELETE FROM deposits;" | psql -Aqt $DB
- echo "DELETE FROM deposits WHERE deposit_serial_id=1;" | psql -Aqt $DB
+ echo "===========24: deposits missing ==========="
+ # Modify denom_sig, so it is wrong
+ CNT=$(echo "SELECT COUNT(*) FROM auditor.deposit_confirmations;" | psql -Aqt "$DB")
+ if [ "$CNT" = "0" ]
+ then
+ echo "Skipping deposits missing test: no deposit confirmations in database!"
+ else
+ echo "DELETE FROM exchange.deposits;" | psql -Aqt "$DB"
+ echo "DELETE FROM exchange.deposits WHERE deposit_serial_id=1;" \
+ | psql -Aqt "$DB"
- run_audit
+ run_audit
- echo -n "Testing inconsistency detection... "
+ echo -n "Testing inconsistency detection... "
- jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null || exit_fail "Deposit confirmation inconsistency NOT detected"
+ jq -e .deposit_confirmation_inconsistencies[0] \
+ < test-audit-deposits.json \
+ > /dev/null \
+ || exit_fail "Deposit confirmation inconsistency NOT detected"
- AMOUNT=`jq -er .missing_deposit_confirmation_total < test-audit-deposits.json`
- if test x$AMOUNT = xTESTKUDOS:0
- then
- exit_fail "Expected non-zero total missing deposit confirmation amount"
- fi
- COUNT=`jq -er .missing_deposit_confirmation_count < test-audit-deposits.json`
- if test x$AMOUNT = x0
- then
- exit_fail "Expected non-zero total missing deposit confirmation count"
- fi
+ AMOUNT=$(jq -er .missing_deposit_confirmation_total < test-audit-deposits.json)
+ if [ "$AMOUNT" = "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected non-zero total missing deposit confirmation amount"
+ fi
+ COUNT=$(jq -er .missing_deposit_confirmation_count < test-audit-deposits.json)
+ if [ "$AMOUNT" = "0" ]
+ then
+ exit_fail "Expected non-zero total missing deposit confirmation count"
+ fi
- echo PASS
+ echo "PASS"
- # cannot easily undo DELETE, hence full reload
- full_reload
-fi
+ # cannot easily undo DELETE, hence full reload
+ full_reload
+ fi
}
# Test for inconsistent coin history.
function test_25() {
-echo "=========25: inconsistent coin history========="
-
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "=========25: inconsistent coin history========="
# Drop refund, so coin history is bogus.
- echo "DELETE FROM refunds WHERE refund_serial_id=1;" | psql -Aqt $DB
+ echo "DELETE FROM exchange.refunds WHERE refund_serial_id=1;" \
+ | psql -At "$DB"
run_audit aggregator
echo -n "Testing inconsistency detection... "
- jq -e .coin_inconsistencies[0] < test-audit-aggregation.json > /dev/null || exit_fail "Coin inconsistency NOT detected"
+ jq -e .coin_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ || exit_fail "Coin inconsistency NOT detected"
# Note: if the wallet withdrew much more than it spent, this might indeed
# go legitimately unnoticed.
- jq -e .emergencies[0] < test-audit-coins.json > /dev/null || exit_fail "Denomination value emergency NOT reported"
+ jq -e .emergencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ || exit_fail "Denomination value emergency NOT reported"
- AMOUNT=`jq -er .total_coin_delta_minus < test-audit-aggregation.json`
- if test x$AMOUNT = xTESTKUDOS:0
+ AMOUNT=$(jq -er .total_coin_delta_minus < test-audit-aggregation.json)
+ if [ "$AMOUNT" = "TESTKUDOS:0" ]
then
exit_fail "Expected non-zero total inconsistency amount from coins"
fi
# Note: if the wallet withdrew much more than it spent, this might indeed
# go legitimately unnoticed.
- COUNT=`jq -er .emergencies_risk_by_amount < test-audit-coins.json`
- if test x$AMOUNT = xTESTKUDOS:0
+ COUNT=$(jq -er .emergencies_risk_by_amount < test-audit-coins.json)
+ if [ "$COUNT" = "TESTKUDOS:0" ]
then
exit_fail "Expected non-zero emergency-by-amount"
fi
- echo PASS
+ echo "PASS"
# cannot easily undo DELETE, hence full reload
full_reload
-else
- echo "Test skipped (database too new)"
-fi
}
# Test for deposit wire target malformed
function test_26() {
-echo "===========26: deposit wire target malformed ================="
-# Expects 'payto_uri', not 'url' (also breaks signature, but we cannot even check that).
-SERIAL=`echo "SELECT deposit_serial_id FROM deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql $DB -Aqt`
-OLD_WIRE_ID=`echo "SELECT wire_target_h_payto FROM deposits WHERE deposit_serial_id=${SERIAL};" | psql $DB -Aqt`
-NEW_WIRE_ID=`echo "INSERT INTO wire_targets (payto_uri, wire_target_h_payto, kyc_ok) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b', false);" | psql $DB -Aqt`
-echo OLD_WIRE_ID=$OLD_WIRE_ID
-echo NEW_WIRE_ID=$NEW_WIRE_ID
-echo "UPDATE deposits SET wire_target_h_payto='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt $DB
+ echo "===========26: deposit wire target malformed ================="
+ # Expects 'payto_uri', not 'url' (also breaks signature, but we cannot even check that).
+ SERIAL=$(echo "SELECT deposit_serial_id FROM exchange.deposits WHERE amount_with_fee_val=3 AND amount_with_fee_frac=0 ORDER BY deposit_serial_id LIMIT 1" | psql "$DB" -Aqt)
+ OLD_WIRE_ID=$(echo "SELECT wire_target_h_payto FROM exchange.deposits WHERE deposit_serial_id=${SERIAL};" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "INSERT INTO exchange.wire_targets (payto_uri, wire_target_h_payto) VALUES ('payto://x-taler-bank/localhost/testuser-xxlargtp', '\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b');" \
+ | psql "$DB" -Aqt
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.deposits SET wire_target_h_payto='\x1e8f31936b3cee8f8afd3aac9e38b5db42d45b721ffc4eb1e5b9ddaf1565660b' WHERE deposit_serial_id=${SERIAL}" \
+ | psql -Aqt "$DB"
-run_audit
-
-echo -n "Testing inconsistency detection... "
+ run_audit
-jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad signature not detected"
+ echo -n "Testing inconsistency detection... "
-ROW=`jq -e .bad_sig_losses[0].row < test-audit-coins.json`
-if test $ROW != ${SERIAL}
-then
- exit_fail "Row wrong, got $ROW"
-fi
+ jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad signature not detected"
-LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong deposit bad signature loss, got $LOSS"
-fi
+ ROW=$(jq -e .bad_sig_losses[0].row < test-audit-coins.json)
+ if [ "$ROW" != "${SERIAL}" ]
+ then
+ exit_fail "Row wrong, got $ROW"
+ fi
-OP=`jq -r .bad_sig_losses[0].operation < test-audit-coins.json`
-if test $OP != "deposit"
-then
- exit_fail "Wrong operation, got $OP"
-fi
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong deposit bad signature loss, got $LOSS"
+ fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:3"
-then
- exit_fail "Wrong total bad sig loss, got $LOSS"
-fi
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-coins.json)
+ if [ "$OP" != "deposit" ]
+ then
+ exit_fail "Wrong operation, got $OP"
+ fi
-echo PASS
-# Undo:
-echo "UPDATE deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_serial_id=${SERIAL}" | psql -Aqt $DB
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Wrong total bad sig loss, got $LOSS"
+ fi
+ echo "PASS"
+ # Undo:
+ echo "UPDATE exchange.deposits SET wire_target_h_payto='$OLD_WIRE_ID' WHERE deposit_serial_id=${SERIAL}" \
+ | psql -Aqt "$DB"
}
# Test for duplicate wire transfer subject
function test_27() {
-echo "===========27: duplicate WTID detection ================="
-
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "===========27: duplicate WTID detection ================="
pre_audit aggregator
-
+ stop_libeufin
# Obtain data to duplicate.
- ID=`echo "SELECT id FROM app_banktransaction WHERE debit_account_id=2 LIMIT 1" | psql $DB -Aqt`
- WTID=`echo "SELECT subject FROM app_banktransaction WHERE debit_account_id=2 LIMIT 1" | psql $DB -Aqt`
- echo WTID=$WTID
- UUID="992e8936-a64d-4845-87d7-021440330f8a"
- echo "INSERT INTO app_banktransaction (amount,subject,date,credit_account_id,debit_account_id,cancelled,request_uid) VALUES ('TESTKUDOS:1','$WTID',NOW(),12,2,'f','$UUID')" | psql -Aqt $DB
-
+ WTID=$(echo SELECT wtid FROM TalerRequestedPayments WHERE id=1 | psql "${DB}" -Aqt)
+ OTHER_IBAN=$(echo -e "SELECT iban FROM BankAccounts WHERE label='fortytwo'" | psql "${DB}" -Aqt)
+ # 'rawConfirmation' is set to 2 here, that doesn't
+ # point to any record. That's only needed to set a non null value.
+ echo -e "INSERT INTO PaymentInitiations (\"bankAccount\",\"preparationDate\",\"submissionDate\",sum,currency,\"endToEndId\",\"paymentInformationId\",\"instructionId\",subject,\"creditorIban\",\"creditorBic\",\"creditorName\",submitted,\"messageId\",\"rawConfirmation\") VALUES (1,$(date +%s),$(( $(date +%s) + 2)),10,'TESTKUDOS','NOTGIVEN','unused','unused','$WTID http://exchange.example.com/','$OTHER_IBAN','SANDBOXX','Forty Two',false,1,2)" \
+ | psql "${DB}" -q
+ echo -e "INSERT INTO TalerRequestedPayments (facade,payment,\"requestUid\",amount,\"exchangeBaseUrl\",wtid,\"creditAccount\") VALUES (1,2,'unused','TESTKUDOS:1','http://exchange.example.com/','$WTID','payto://iban/SANDBOXX/$OTHER_IBAN?receiver-name=Forty+Two')" \
+ | psql "${DB}" -q
+ launch_libeufin
audit_only
post_audit
echo -n "Testing inconsistency detection... "
- AMOUNT=`jq -r .wire_format_inconsistencies[0].amount < test-audit-wire.json`
- if test "${AMOUNT}" != "TESTKUDOS:1"
+ AMOUNT=$(jq -r .wire_format_inconsistencies[0].amount < test-audit-wire.json)
+ if [ "${AMOUNT}" != "TESTKUDOS:1" ]
then
exit_fail "Amount wrong, got ${AMOUNT}"
fi
- AMOUNT=`jq -r .total_wire_format_amount < test-audit-wire.json`
- if test "${AMOUNT}" != "TESTKUDOS:1"
+ AMOUNT=$(jq -r .total_wire_format_amount < test-audit-wire.json)
+ if [ "${AMOUNT}" != "TESTKUDOS:1" ]
then
exit_fail "Wrong total wire format amount, got $AMOUNT"
fi
# cannot easily undo aggregator, hence full reload
full_reload
-else
- echo "Test skipped (database too new)"
-fi
-
}
@@ -1579,41 +1795,37 @@ fi
# Test where denom_sig in known_coins table is wrong
# (=> bad signature) AND the coin is used in aggregation
function test_28() {
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
echo "===========28: known_coins signature wrong================="
# Modify denom_sig, so it is wrong
- OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -Aqt`
- COIN_PUB=`echo "SELECT coin_pub FROM known_coins WHERE denom_sig='$OLD_SIG';" | psql $DB -Aqt`
- echo "UPDATE known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" | psql -Aqt $DB
+ OLD_SIG=$(echo 'SELECT denom_sig FROM exchange.known_coins LIMIT 1;' | psql "$DB" -Aqt)
+ COIN_PUB=$(echo "SELECT coin_pub FROM exchange.known_coins WHERE denom_sig='$OLD_SIG';" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" \
+ | psql -Aqt "$DB"
run_audit aggregator
echo -n "Testing inconsistency detection... "
- LOSS=`jq -r .bad_sig_losses[0].loss < test-audit-aggregation.json`
- if test $LOSS == "TESTKUDOS:0"
+ LOSS=$(jq -r .bad_sig_losses[0].loss < test-audit-aggregation.json)
+ if [ "$LOSS" == "TESTKUDOS:0" ]
then
exit_fail "Wrong deposit bad signature loss, got $LOSS"
fi
- OP=`jq -r .bad_sig_losses[0].operation < test-audit-aggregation.json`
- if test $OP != "wire"
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-aggregation.json)
+ if [ "$OP" != "wire" ]
then
exit_fail "Wrong operation, got $OP"
fi
- TAB=`jq -r .row_inconsistencies[0].table < test-audit-aggregation.json`
- if test $TAB != "deposit"
+ TAB=$(jq -r .row_inconsistencies[0].table < test-audit-aggregation.json)
+ if [ "$TAB" != "deposit" ]
then
exit_fail "Wrong table for row inconsistency, got $TAB"
fi
- LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json`
- if test $LOSS == "TESTKUDOS:0"
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$LOSS" == "TESTKUDOS:0" ]
then
exit_fail "Wrong total bad sig loss, got $LOSS"
fi
@@ -1621,10 +1833,6 @@ then
echo "OK"
# cannot easily undo aggregator, hence full reload
full_reload
-
-else
- echo "Test skipped (database too new)"
-fi
}
@@ -1632,27 +1840,27 @@ fi
# Test where fees known to the auditor differ from those
# accounted for by the exchange
function test_29() {
-echo "===========29: withdraw fee inconsistency ================="
+ echo "===========29: withdraw fee inconsistency ================="
-echo "UPDATE denominations SET fee_withdraw_frac=5000000 WHERE coin_val=1;" | psql -Aqt $DB
+ echo "UPDATE exchange.denominations SET fee_withdraw_frac=5000000 WHERE coin_val=1;" | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-AMOUNT=`jq -r .total_balance_summary_delta_minus < test-audit-reserves.json`
-if test "x$AMOUNT" == "xTESTKUDOS:0"
-then
- exit_fail "Reported total amount wrong: $AMOUNT"
-fi
+ echo -n "Testing inconsistency detection... "
+ AMOUNT=$(jq -r .total_balance_summary_delta_minus < test-audit-reserves.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Reported total amount wrong: $AMOUNT"
+ fi
-PROFIT=`jq -r .amount_arithmetic_inconsistencies[0].profitable < test-audit-coins.json`
-if test "x$PROFIT" != "x-1"
-then
- exit_fail "Reported wrong profitability: $PROFIT"
-fi
-echo "OK"
-# Undo
-echo "UPDATE denominations SET fee_withdraw_frac=2000000 WHERE coin_val=1;" | psql -Aqt $DB
+ PROFIT=$(jq -r .amount_arithmetic_inconsistencies[0].profitable < test-audit-coins.json)
+ if [ "$PROFIT" != "-1" ]
+ then
+ exit_fail "Reported wrong profitability: $PROFIT"
+ fi
+ echo "OK"
+ # Undo
+ echo "UPDATE exchange.denominations SET fee_withdraw_frac=2000000 WHERE coin_val=1;" | psql -Aqt "$DB"
}
@@ -1660,28 +1868,28 @@ echo "UPDATE denominations SET fee_withdraw_frac=2000000 WHERE coin_val=1;" | ps
# Test where fees known to the auditor differ from those
# accounted for by the exchange
function test_30() {
-echo "===========30: melt fee inconsistency ================="
+ echo "===========30: melt fee inconsistency ================="
-echo "UPDATE denominations SET fee_refresh_frac=5000000 WHERE coin_val=10;" | psql -Aqt $DB
+ echo "UPDATE exchange.denominations SET fee_refresh_frac=5000000 WHERE coin_val=10;" | psql -Aqt "$DB"
-run_audit
-echo -n "Testing inconsistency detection... "
-AMOUNT=`jq -r .bad_sig_losses[0].loss < test-audit-coins.json`
-if test "x$AMOUNT" == "xTESTKUDOS:0"
-then
- exit_fail "Reported total amount wrong: $AMOUNT"
-fi
+ run_audit
+ echo -n "Testing inconsistency detection... "
+ AMOUNT=$(jq -r .bad_sig_losses[0].loss < test-audit-coins.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Reported total amount wrong: $AMOUNT"
+ fi
-PROFIT=`jq -r .amount_arithmetic_inconsistencies[0].profitable < test-audit-coins.json`
-if test "x$PROFIT" != "x-1"
-then
- exit_fail "Reported profitability wrong: $PROFIT"
-fi
+ PROFIT=$(jq -r .amount_arithmetic_inconsistencies[0].profitable < test-audit-coins.json)
+ if [ "$PROFIT" != "-1" ]
+ then
+ exit_fail "Reported profitability wrong: $PROFIT"
+ fi
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run"
-echo "OK"
-# Undo
-echo "UPDATE denominations SET fee_refresh_frac=3000000 WHERE coin_val=1;" | psql -Aqt $DB
+ jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run"
+ echo "OK"
+ # Undo
+ echo "UPDATE exchange.denominations SET fee_refresh_frac=3000000 WHERE coin_val=10;" | psql -Aqt "$DB"
}
@@ -1690,39 +1898,27 @@ echo "UPDATE denominations SET fee_refresh_frac=3000000 WHERE coin_val=1;" | psq
# accounted for by the exchange
function test_31() {
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
-
echo "===========31: deposit fee inconsistency ================="
- echo "UPDATE denominations SET fee_deposit_frac=5000000 WHERE coin_val=8;" | psql -Aqt $DB
+ echo "UPDATE exchange.denominations SET fee_deposit_frac=5000000 WHERE coin_val=8;" | psql -Aqt "$DB"
run_audit aggregator
echo -n "Testing inconsistency detection... "
- AMOUNT=`jq -r .total_bad_sig_loss < test-audit-coins.json`
- if test "x$AMOUNT" == "xTESTKUDOS:0"
+ AMOUNT=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
- OP=`jq -r --arg dep "deposit" '.bad_sig_losses[] | select(.operation == $dep) | .operation'< test-audit-coins.json | head -n1`
- if test "x$OP" != "xdeposit"
+ OP=$(jq -r --arg dep "deposit" '.bad_sig_losses[] | select(.operation == $dep) | .operation'< test-audit-coins.json | head -n1)
+ if [ "$OP" != "deposit" ]
then
exit_fail "Reported wrong operation: $OP"
fi
echo "OK"
# Undo
- echo "UPDATE denominations SET fee_deposit_frac=2000000 WHERE coin_val=8;" | psql -Aqt $DB
-
-else
- echo "Test skipped (database too new)"
-fi
-
+ echo "UPDATE exchange.denominations SET fee_deposit_frac=2000000 WHERE coin_val=8;" | psql -Aqt "$DB"
}
@@ -1732,30 +1928,25 @@ fi
# (=> bad signature)
function test_32() {
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
-
echo "===========32: known_coins signature wrong w. aggregation================="
# Modify denom_sig, so it is wrong
- OLD_SIG=`echo 'SELECT denom_sig FROM known_coins LIMIT 1;' | psql $DB -At`
- COIN_PUB=`echo "SELECT coin_pub FROM known_coins WHERE denom_sig='$OLD_SIG';" | psql $DB -At`
- echo "UPDATE known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" | psql -Aqt $DB
+ OLD_SIG=$(echo 'SELECT denom_sig FROM exchange.known_coins LIMIT 1;' | psql "$DB" -Aqt)
+ COIN_PUB=$(echo "SELECT coin_pub FROM exchange.known_coins WHERE denom_sig='$OLD_SIG';" | psql "$DB" -Aqt)
+# shellcheck disable=SC2028
+ echo "UPDATE exchange.known_coins SET denom_sig='\x0000000100000000287369672d76616c200a2028727361200a2020287320233542383731423743393036444643303442424430453039353246413642464132463537303139374131313437353746324632323332394644443146324643333445393939413336363430334233413133324444464239413833353833464536354442374335434445304441453035374438363336434541423834463843323843344446304144363030343430413038353435363039373833434431333239393736423642433437313041324632414132414435413833303432434346314139464635394244434346374436323238344143354544364131373739463430353032323241373838423837363535453434423145443831364244353638303232413123290a2020290a20290b' WHERE coin_pub='$COIN_PUB'" \
+ | psql -Aqt "$DB"
run_audit aggregator
echo -n "Testing inconsistency detection... "
- AMOUNT=`jq -r .total_bad_sig_loss < test-audit-aggregation.json`
- if test "x$AMOUNT" == "xTESTKUDOS:0"
+ AMOUNT=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
then
exit_fail "Reported total amount wrong: $AMOUNT"
fi
- OP=`jq -r .bad_sig_losses[0].operation < test-audit-aggregation.json`
- if test "x$OP" != "xwire"
+ OP=$(jq -r .bad_sig_losses[0].operation < test-audit-aggregation.json)
+ if [ "$OP" != "wire" ]
then
exit_fail "Reported wrong operation: $OP"
fi
@@ -1763,54 +1954,147 @@ then
echo "OK"
# Cannot undo aggregation, do full reload
full_reload
-
-fi
}
-# Test where h_payto in the wire_targets table is wrong
function test_33() {
-echo "===========33: h_payto wrong================="
-# Check wire transfer lag reported (no aggregator!)
-# NOTE: this test is BRAND NEW and expected
-# to fail until we implement the check in the auditor!
+ echo "===========33: normal run with aggregator and profit drain==========="
+ run_audit aggregator drain
-# NOTE: This test is EXPECTED to fail for ~1h after
-# re-generating the test database as we do not
-# report lag of less than 1h (see GRACE_PERIOD in
-# taler-helper-auditor-wire.c)
-if [ $DATABASE_AGE -gt 3600 ]
-then
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
+ echo -n "Test for deposit confirmation emergencies... "
+ jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
- # Modify h_payto hash, so it is inconsistent with 'wire'
- WTSID=`echo "SELECT wire_target_serial_id FROM deposits WHERE deposit_serial_id=1;" | psql -Aqt $DB`
- echo "UPDATE wire_targets SET h_payto='\x973e52d193a357940be9ef2939c19b0575ee1101f52188c3c01d9005b7d755c397e92624f09cfa709104b3b65605fe5130c90d7e1b7ee30f8fc570f39c16b853' WHERE wire_target_serial_id=$WTSID" | psql -Aqt $DB
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
- # The auditor checks h_wire consistency only for
- # coins where the wire transfer has happened, hence
- # run aggregator first to get this test to work.
- run_audit aggregator
- echo -n "Testing inconsistency detection... "
- TABLE=`jq -r .row_inconsistencies[0].table < test-audit-aggregation.json`
- if test "x$TABLE" != "xwire_targets"
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo PASS
+
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
then
- exit_fail "Reported table wrong: $TABLE"
+ exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
+ fi
+
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
fi
echo PASS
- # cannot easily undo aggregator, hence full reload
- full_reload
+ echo -n "Checking for unexpected arithmetic differences "
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
+ fi
-else
- echo "Test skipped (database too new)"
-fi
-}
+ DRAINED=$(jq -r .total_drained < test-audit-wire.json)
+ if [ "$DRAINED" != "TESTKUDOS:0.1" ]
+ then
+ exit_fail "Wrong amount drained, got unexpected drain of $DRAINED"
+ fi
+
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-reserves.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
+ echo "PASS"
+ echo -n "Checking for unexpected wire out differences "
+ jq -e .wire_out_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
+ echo "PASS"
+ # cannot easily undo aggregator, hence full reload
+ full_reload
+}
# *************** Main test loop starts here **************
@@ -1818,21 +2102,18 @@ fi
# Run all the tests against the database given in $1.
# Sets $fail to 0 on success, non-zero on failure.
-check_with_database()
+function check_with_database()
{
- BASEDB=$1
+ BASEDB="$1"
+ CONF="$1.conf"
echo "Running test suite with database $BASEDB using configuration $CONF"
-
- # Setup database-specific globals
- MASTER_PUB=`cat ${BASEDB}.mpub`
-
- # Determine database age
- echo "Calculating database age based on ${BASEDB}.age"
- AGE=`cat ${BASEDB}.age`
- NOW=`date +%s`
- # NOTE: expr "fails" if the result is zero.
- DATABASE_AGE=`expr ${NOW} - ${AGE} || true`
- echo "Database age is ${DATABASE_AGE} seconds"
+ MASTER_PRIV_FILE="${BASEDB}.mpriv"
+ taler-config \
+ -f \
+ -c "${CONF}" \
+ -s exchange-offline \
+ -o MASTER_PRIV_FILE \
+ -V "${MASTER_PRIV_FILE}"
# Load database
full_reload
@@ -1841,7 +2122,7 @@ check_with_database()
fail=0
for i in $TESTS
do
- test_$i
+ "test_$i"
if test 0 != $fail
then
break
@@ -1854,61 +2135,121 @@ check_with_database()
-
-
# *************** Main logic starts here **************
# ####### Setup globals ######
-# Postgres database to use
-DB=auditor-basedb
-
-# Configuration file to use
-CONF=${DB}.conf
+# Postgres database to use (must match configuration file)
+export DB="auditor-basedb"
# test required commands exist
echo "Testing for jq"
jq -h > /dev/null || exit_skip "jq required"
-echo "Testing for taler-bank-manage"
-taler-bank-manage --help >/dev/null </dev/null || exit_skip "taler-bank-manage required"
+echo "Testing for faketime"
+faketime -h > /dev/null || exit_skip "faketime required"
+# NOTE: really check for all three libeufin commands?
+echo "Testing for libeufin"
+libeufin-bank --help >/dev/null 2> /dev/null </dev/null || exit_skip "libeufin required"
echo "Testing for pdflatex"
which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
+echo "Testing for taler-wallet-cli"
+taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required"
-# check if we should regenerate the database
-if test -n "${1:-}"
-then
- echo "Custom run, will only run on existing DB."
+
+echo -n "Testing for Postgres"
+# Available directly in path?
+INITDB_BIN=$(command -v initdb) || true
+if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
else
- echo -n "Testing for taler-wallet-cli"
- if taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null
+ HAVE_INITDB=$(find /usr -name "initdb" 2> /dev/null \
+ | head -1 2> /dev/null \
+ | grep postgres) \
+ || exit_skip " MISSING"
+ echo " FOUND at $(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
+fi
+POSTGRES_PATH=$(dirname "$INITDB_BIN")
+
+MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
+echo "Using $MY_TMP_DIR for logging and temporary data"
+TMPDIR="$MY_TMP_DIR/postgres"
+mkdir -p "$TMPDIR"
+echo -n "Setting up Postgres DB at $TMPDIR ..."
+$INITDB_BIN \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err"
+echo "DONE"
+
+# Once we move to PG16, we can use:
+# --set listen_addresses='' \
+# --set fsync=off \
+# --set max_wal_senders=0 \
+# --set synchronous_commit=off \
+# --set wal_level=minimal \
+# --set unix_socket_directories="${TMPDIR}/sockets" \
+
+
+SOCKETDIR="${TMPDIR}/sockets"
+mkdir "${SOCKETDIR}"
+
+echo -n "Launching Postgres service"
+
+cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+
+grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+"${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l "${MY_TMP_DIR}/postgres.log" \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+echo " DONE"
+PGHOST="$TMPDIR/sockets"
+export PGHOST
+MYDIR="${MY_TMP_DIR}/basedb"
+mkdir -p "${MYDIR}"
+
+if [ -z $REUSE_BASEDB_DIR ]
+then
+ echo "Generating fresh database at $MYDIR"
+
+ if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/$DB"
then
- MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX`
- echo " FOUND. Generating fresh database at $MYDIR"
- pwd
- if ./generate-auditor-basedb.sh $MYDIR/basedb
- then
- check_with_database $MYDIR/basedb
- if test x$fail != x0
- then
- exit $fail
- else
- echo "Cleaning up $MYDIR..."
- rm -rf $MYDIR || echo "Removing $MYDIR failed"
- fi
- else
- echo "Generation failed, running only on existing DB"
- fi
+ echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+ dropdb "auditor-basedb" >/dev/null 2>/dev/null || true
+ createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at $PGHOST"
+ echo " DONE"
else
- echo " NOT FOUND, running only on existing DB"
+ echo "Generation failed"
+ exit 1
fi
+else
+ echo "Reusing existing database from ${REUSE_BASEDB_DIR}"
+ cp -r "${REUSE_BASEDB_DIR}/basedb"/* "${MYDIR}/"
fi
-# run tests with pre-build database, if one is available
-if test -r auditor-basedb.mpub
+check_with_database "$MYDIR/$DB"
+if [ "$fail" != "0" ]
then
- check_with_database "auditor-basedb"
-else
- echo "Lacking auditor-basedb.mpub, skipping test"
- fail=77
+ exit "$fail"
+fi
+
+if [ -z $REUSE_BASEDB_DIR ]
+then
+ echo "Run 'export REUSE_BASEDB_DIR=${MY_TMP_DIR}' to re-run tests against the same database"
fi
-exit $fail
+exit 0
diff --git a/src/auditor/test-kyc.sh b/src/auditor/test-kyc.sh
new file mode 100755
index 000000000..2c4fa6594
--- /dev/null
+++ b/src/auditor/test-kyc.sh
@@ -0,0 +1,751 @@
+#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2014-2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
+#
+#
+# shellcheck disable=SC2317
+# shellcheck disable=SC1091
+#
+#
+# Setup database which was generated from a perfectly normal
+# exchange-wallet interaction with KYC enabled and transactions
+# blocked due to KYC and run the auditor against it.
+#
+# Check that the auditor report is as expected.
+#
+# Requires 'jq' tool and Postgres superuser rights!
+#
+set -eu
+#set -x
+
+# Set of numbers for all the testcases.
+# When adding new tests, increase the last number:
+ALL_TESTS=$(seq 0 1)
+
+# $TESTS determines which tests we should run.
+# This construction is used to make it easy to
+# only run a subset of the tests. To only run a subset,
+# pass the numbers of the tests to run as the FIRST
+# argument to test-kyc.sh, i.e.:
+#
+# $ test-kyc.sh "1 3"
+#
+# to run tests 1 and 3 only. By default, all tests are run.
+#
+TESTS=${1:-$ALL_TESTS}
+
+# Global variable to run the auditor processes under valgrind
+# VALGRIND=valgrind
+VALGRIND=""
+
+# Number of seconds to let libeuifn background
+# tasks apply a cycle of payment submission and
+# history request.
+LIBEUFIN_SETTLE_TIME=1
+
+. setup.sh
+
+
+# Cleanup exchange and libeufin between runs.
+function cleanup()
+{
+ if test ! -z "${EPID:-}"
+ then
+ echo -n "Stopping exchange $EPID..."
+ kill -TERM "$EPID"
+ wait "$EPID" || true
+ echo "DONE"
+ unset EPID
+ fi
+ stop_libeufin
+}
+
+# Cleanup to run whenever we exit
+function exit_cleanup()
+{
+ echo "Running exit-cleanup"
+ if test ! -z "${POSTGRES_PATH:-}"
+ then
+ echo "Stopping Postgres at ${POSTGRES_PATH}"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ stop \
+ &> /dev/null \
+ || true
+ fi
+ cleanup
+ for n in $(jobs -p)
+ do
+ kill "$n" 2> /dev/null || true
+ done
+ wait || true
+ echo "DONE"
+}
+
+# Install cleanup handler (except for kill -9)
+trap exit_cleanup EXIT
+
+
+
+# Operations to run before the actual audit
+function pre_audit () {
+ # Launch bank
+ echo -n "Launching bank"
+ launch_libeufin
+ for n in $(seq 1 80)
+ do
+ echo -n "."
+ sleep 0.1
+ OK=1
+ wget http://localhost:18082/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ && break
+ OK=0
+ done
+ if [ 1 != "$OK" ]
+ then
+ exit_skip "Failed to launch Sandbox"
+ fi
+ sleep "$LIBEUFIN_SETTLE_TIME"
+ for n in $(seq 1 80)
+ do
+ echo -n "."
+ sleep 0.1
+ OK=1
+ wget http://localhost:8082/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ && break
+ OK=0
+ done
+ if [ 1 != "$OK" ]
+ then
+ exit_skip "Failed to launch Nexus"
+ fi
+ echo " DONE"
+ if test "${1:-no}" = "aggregator"
+ then
+ echo -n "Running exchange aggregator ..."
+ taler-exchange-aggregator \
+ -y \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/aggregator.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+ echo -n "Running exchange closer ..."
+ taler-exchange-closer \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/closer.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+ echo -n "Running exchange transfer ..."
+ taler-exchange-transfer \
+ -L "INFO" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/transfer.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+ fi
+}
+
+# actual audit run
+function audit_only () {
+ # Run the auditor!
+ echo -n "Running audit(s) ..."
+
+ # Restart so that first run is always fresh, and second one is incremental
+ taler-auditor-dbinit \
+ -r \
+ -c "$CONF"
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-aggregation.json \
+ 2> "${MY_TMP_DIR}/test-audit-aggregation.log" \
+ || exit_fail "aggregation audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-aggregation-inc.json \
+ 2> "${MY_TMP_DIR}/test-audit-aggregation-inc.log" \
+ || exit_fail "incremental aggregation audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-coins \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-coins.json \
+ 2> "${MY_TMP_DIR}/test-audit-coins.log" \
+ || exit_fail "coin audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-coins \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-coins-inc.json \
+ 2> "${MY_TMP_DIR}/test-audit-coins-inc.log" \
+ || exit_fail "incremental coin audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-deposits \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-deposits.json \
+ 2> "${MY_TMP_DIR}/test-audit-deposits.log" \
+ || exit_fail "deposits audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-deposits \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-deposits-inc.json \
+ 2> "${MY_TMP_DIR}/test-audit-deposits-inc.log" \
+ || exit_fail "incremental deposits audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-reserves.json \
+ 2> "${MY_TMP_DIR}/test-audit-reserves.log" \
+ || exit_fail "reserves audit failed"
+ echo -n "."
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-reserves-inc.json \
+ 2> "${MY_TMP_DIR}/test-audit-reserves-inc.log" \
+ || exit_fail "incremental reserves audit failed"
+ echo -n "."
+ rm -f "${MY_TMP_DIR}/test-wire-audit.log"
+ thaw() {
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-wire.json \
+ 2>> "${MY_TMP_DIR}/test-wire-audit.log"
+ }
+ thaw || ( echo -e " FIRST CALL TO taler-helper-auditor-wire FAILED,\nRETRY AFTER TWO SECONDS..." | tee -a "${MY_TMP_DIR}/test-wire-audit.log"
+ sleep 2
+ thaw || exit_fail "wire audit failed" )
+ echo -n "."
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L DEBUG \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-wire-inc.json \
+ 2> "${MY_TMP_DIR}/test-wire-audit-inc.log" \
+ || exit_fail "wire audit inc failed"
+ echo -n "."
+
+ echo " DONE"
+}
+
+
+# Cleanup to run after the auditor
+function post_audit () {
+ taler-exchange-dbinit \
+ -c "$CONF" \
+ -g \
+ || exit_fail "exchange DB GC failed"
+
+ cleanup
+ echo -n "TeXing ."
+ taler-helper-auditor-render.py \
+ test-audit-aggregation.json \
+ test-audit-coins.json \
+ test-audit-deposits.json \
+ test-audit-reserves.json \
+ test-audit-wire.json \
+ < ../../contrib/auditor-report.tex.j2 \
+ > test-report.tex \
+ || exit_fail "Renderer failed"
+
+ echo -n "."
+ timeout 10 pdflatex test-report.tex \
+ >/dev/null \
+ || exit_fail "pdflatex failed"
+ echo -n "."
+ timeout 10 pdflatex test-report.tex \
+ >/dev/null
+ echo " DONE"
+}
+
+
+# Run audit process on current database, including report
+# generation. Pass "aggregator" as $1 to run
+# $ taler-exchange-aggregator
+# before auditor (to trigger pending wire transfers).
+# Pass "drain" as $2 to run a drain operation as well.
+function run_audit () {
+ pre_audit "${1:-no}"
+ if test "${2:-no}" = "drain"
+ then
+ echo -n "Starting exchange..."
+ taler-exchange-httpd \
+ -c "${CONF}" \
+ -L INFO \
+ 2> "${MY_TMP_DIR}/exchange-httpd-drain.err" &
+ EPID=$!
+
+ # Wait for all services to be available
+ for n in $(seq 1 50)
+ do
+ echo -n "."
+ sleep 0.1
+ OK=0
+ # exchange
+ wget "http://localhost:8081/seed" \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ || continue
+ OK=1
+ break
+ done
+ echo "... DONE."
+ export CONF
+
+ echo -n "Running taler-exchange-offline drain "
+
+ taler-exchange-offline \
+ -L DEBUG \
+ -c "${CONF}" \
+ drain TESTKUDOS:0.1 \
+ exchange-account-1 payto://iban/SANDBOXX/DE360679?receiver-name=Exchange+Drain \
+ upload \
+ 2> "${MY_TMP_DIR}/taler-exchange-offline-drain.log" \
+ || exit_fail "offline draining failed"
+ kill -TERM "$EPID"
+ wait "$EPID" || true
+ unset EPID
+ echo -n "Running taler-exchange-drain ..."
+ printf "\n" | taler-exchange-drain \
+ -L DEBUG \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/taler-exchange-drain.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+
+ echo -n "Running taler-exchange-transfer ..."
+ taler-exchange-transfer \
+ -L INFO \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/drain-transfer.log" \
+ || exit_fail "FAIL"
+ echo " DONE"
+
+ audit_only
+ post_audit
+}
+
+
+# Do a full reload of the (original) database
+function full_reload()
+{
+ echo -n "Doing full reload of the database (loading ${BASEDB}.sql into $DB at $PGHOST)... "
+ dropdb "$DB" 2> /dev/null || true
+ createdb -T template0 "$DB" \
+ || exit_skip "could not create database $DB (at $PGHOST)"
+ # Import pre-generated database, -q(ietly) using single (-1) transaction
+ psql -Aqt "$DB" \
+ -q \
+ -1 \
+ -f "${BASEDB}.sql" \
+ > /dev/null \
+ || exit_skip "Failed to load database $DB from ${BASEDB}.sql"
+ echo "DONE"
+ # Technically, this call shouldn't be needed as libeufin should already be stopped here...
+ stop_libeufin
+}
+
+
+function test_0() {
+
+ echo "===========0: normal run with aggregator==========="
+ run_audit aggregator
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
+ echo -n "Test for deposit confirmation emergencies... "
+ jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
+
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo PASS
+
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
+ fi
+
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
+ echo "PASS"
+
+ echo -n "Checking for unexpected arithmetic differences "
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
+ fi
+
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
+ echo "PASS"
+
+ echo -n "Checking for unexpected wire out differences "
+ jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
+ echo "PASS"
+
+ # cannot easily undo aggregator, hence full reload
+ full_reload
+
+}
+
+
+# Run without aggregator, hence auditor should detect wire
+# transfer lag!
+function test_1() {
+
+ echo "===========1: normal run==========="
+ run_audit
+
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency detected in ordinary run";
+ echo "PASS"
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency by count detected in ordinary run"
+ echo "PASS"
+
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo "PASS"
+
+ echo -n "Check for lag detection... "
+
+ # Check wire transfer lag reported (no aggregator!)
+ # NOTE: This test is EXPECTED to fail for ~1h after
+ # re-generating the test database as we do not
+ # report lag of less than 1h (see GRACE_PERIOD in
+ # taler-helper-auditor-wire.c)
+ jq -e .lag_details[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ || exit_fail "Lag not detected in run without aggregator"
+
+ LAG=$(jq -r .total_amount_lag < test-audit-wire.json)
+ if [ "$LAG" = "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total lag to be non-zero"
+ fi
+ echo "PASS"
+
+
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
+ # Database was unmodified, no need to undo
+ echo "OK"
+}
+
+
+
+# *************** Main test loop starts here **************
+
+
+# Run all the tests against the database given in $1.
+# Sets $fail to 0 on success, non-zero on failure.
+function check_with_database()
+{
+ BASEDB="$1"
+ CONF="$1.conf"
+ echo "Running test suite with database $BASEDB using configuration $CONF"
+ MASTER_PRIV_FILE="${BASEDB}.mpriv"
+ taler-config \
+ -f \
+ -c "${CONF}" \
+ -s exchange-offline \
+ -o MASTER_PRIV_FILE \
+ -V "${MASTER_PRIV_FILE}"
+ MASTER_PUB=$(gnunet-ecc -p "$MASTER_PRIV_FILE")
+
+ echo "MASTER PUB is ${MASTER_PUB} using file ${MASTER_PRIV_FILE}"
+
+ # Load database
+ full_reload
+
+ # Run test suite
+ fail=0
+ for i in $TESTS
+ do
+ "test_$i"
+ if test 0 != $fail
+ then
+ break
+ fi
+ done
+ echo "Cleanup (disabled, leaving database $DB behind)"
+ # dropdb $DB
+}
+
+
+
+
+# *************** Main logic starts here **************
+
+# ####### Setup globals ######
+# Postgres database to use (must match configuration file)
+export DB="auditor-basedb"
+
+# test required commands exist
+echo "Testing for jq"
+jq -h > /dev/null || exit_skip "jq required"
+echo "Testing for faketime"
+faketime -h > /dev/null || exit_skip "faketime required"
+# NOTE: really check for all three libeufin commands?
+echo "Testing for libeufin-bank"
+libeufin-bank --help >/dev/null 2> /dev/null </dev/null || exit_skip "libeufin-bank required"
+echo "Testing for pdflatex"
+which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
+echo "Testing for taler-wallet-cli"
+taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required"
+
+
+echo -n "Testing for Postgres"
+# Available directly in path?
+INITDB_BIN=$(command -v initdb) || true
+if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
+else
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) \
+ || exit_skip " MISSING"
+ echo " FOUND at $(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
+fi
+POSTGRES_PATH=$(dirname "$INITDB_BIN")
+
+MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
+echo "Using $MY_TMP_DIR for logging and temporary data"
+TMPDIR="$MY_TMP_DIR/postgres"
+mkdir -p "$TMPDIR"
+echo -n "Setting up Postgres DB at $TMPDIR ..."
+$INITDB_BIN \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err"
+echo "DONE"
+SOCKETDIR="${TMPDIR}/sockets"
+mkdir "${SOCKETDIR}"
+echo -n "Launching Postgres service"
+cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+"${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+echo " DONE"
+PGHOST="$TMPDIR/sockets"
+export PGHOST
+
+MYDIR="${MY_TMP_DIR}/basedb"
+mkdir -p "${MYDIR}"
+echo "Generating fresh database at $MYDIR"
+if faketime -f '-1 d' ./generate-auditor-basedb.sh \
+ -c generate-kyc-basedb.conf \
+ -d "$MYDIR/$DB"
+then
+ echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
+ dropdb "auditor-basedb" >/dev/null 2>/dev/null || true
+ createdb "auditor-basedb" || exit_skip "Could not create database '$BASEDB' at $PGHOST"
+ echo " DONE"
+ check_with_database "$MYDIR/$DB"
+ if [ "$fail" != "0" ]
+ then
+ exit "$fail"
+ fi
+else
+ echo "Generation failed"
+ exit 1
+fi
+
+exit 0
diff --git a/src/auditor/test-revocation.sh b/src/auditor/test-revocation.sh
index 9453c4458..277b102fb 100755
--- a/src/auditor/test-revocation.sh
+++ b/src/auditor/test-revocation.sh
@@ -1,15 +1,33 @@
#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2014-2022 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
+#
# Setup database which was generated from a exchange-wallet interaction
# with revocations and run the auditor against it.
#
# Check that the auditor report is as expected.
#
+# shellcheck disable=SC2317
+#
# Requires 'jq' tool and Postgres superuser rights!
set -eu
+# set -x
# Set of numbers for all the testcases.
# When adding new tests, increase the last number:
-ALL_TESTS=`seq 0 4`
+ALL_TESTS=$(seq 0 4)
# $TESTS determines which tests we should run.
# This construction is used to make it easy to
@@ -26,63 +44,114 @@ TESTS=${1:-$ALL_TESTS}
# Global variable to run the auditor processes under valgrind
# VALGRIND=valgrind
VALGRIND=""
+LOGLEVEL="INFO"
-# Exit, with status code "skip" (no 'real' failure)
-function exit_skip() {
- echo $1
- exit 77
-}
+. setup.sh
-# Exit, with error message (hard failure)
-function exit_fail() {
- echo $1
- exit 1
+# Cleanup to run whenever we exit
+function cleanup()
+{
+ if [ ! -z "${EPID:-}" ]
+ then
+ echo -n "Stopping exchange $EPID..."
+ kill -TERM "$EPID"
+ wait "$EPID"
+ echo " DONE"
+ unset EPID
+ fi
+ stop_libeufin
}
# Cleanup to run whenever we exit
-function cleanup()
+function exit_cleanup()
{
- for n in `jobs -p`
+ echo "Running exit-cleanup"
+ if [ ! -z "${POSTGRES_PATH:-}" ]
+ then
+ echo "Stopping Postgres at ${POSTGRES_PATH}"
+ "${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ stop \
+ &> /dev/null \
+ || true
+ fi
+ cleanup
+ for n in $(jobs -p)
do
- kill $n 2> /dev/null || true
+ kill "$n" 2> /dev/null || true
done
wait
+ echo "DONE"
}
# Install cleanup handler (except for kill -9)
-trap cleanup EXIT
+trap exit_cleanup EXIT
# Operations to run before the actual audit
function pre_audit () {
# Launch bank
echo -n "Launching bank "
- taler-bank-manage-testing $CONF postgres:///$DB serve 2>bank.err >bank.log &
- for n in `seq 1 80`
+ launch_libeufin
+ for n in $(seq 1 80)
+ do
+ echo -n "."
+ sleep 0.1
+ OK=1
+ wget http://localhost:18082/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null && break
+ OK=0
+ done
+ if [ 1 != "$OK" ]
+ then
+ exit_skip "Failed to launch Sandbox"
+ fi
+ for n in $(seq 1 80)
do
echo -n "."
sleep 0.1
OK=1
- wget http://localhost:8082/ -o /dev/null -O /dev/null >/dev/null && break
+ wget http://localhost:8082/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null && break
OK=0
done
- if [ 1 != $OK ]
+ if [ 1 != "$OK" ]
then
- exit_skip "Failed to launch bank"
+ exit_skip "Failed to launch Nexus"
fi
echo " DONE"
-
- if test ${1:-no} = "aggregator"
+ if [ "${1:-no}" = "aggregator" ]
then
export CONF
- echo -n "Running exchange aggregator ..."
- taler-exchange-aggregator -L INFO -t -c $CONF -y 2> aggregator.log || exit_fail "FAIL"
+ echo -n "Running exchange aggregator ... (config: $CONF)"
+ taler-exchange-aggregator \
+ -L "$LOGLEVEL" \
+ -t \
+ -c "$CONF" \
+ -y \
+ 2> "${MY_TMP_DIR}/aggregator.log" \
+ || exit_fail "FAIL"
echo " DONE"
echo -n "Running exchange closer ..."
- taler-exchange-closer -L INFO -t -c $CONF 2> closer.log || exit_fail "FAIL"
+ taler-exchange-closer \
+ -L "$LOGLEVEL" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/closer.log" \
+ || exit_fail "FAIL"
echo " DONE"
echo -n "Running exchange transfer ..."
- taler-exchange-transfer -L INFO -t -c $CONF 2> transfer.log || exit_fail "FAIL"
+ taler-exchange-transfer \
+ -L "$LOGLEVEL" \
+ -t \
+ -c "$CONF" \
+ 2> "${MY_TMP_DIR}/transfer.log" \
+ || exit_fail "FAIL"
echo " DONE"
fi
}
@@ -90,47 +159,120 @@ function pre_audit () {
# actual audit run
function audit_only () {
# Run the auditor!
- echo -n "Running audit(s) ..."
+ echo -n "Running audit(s) ... (conf is $CONF)"
# Restart so that first run is always fresh, and second one is incremental
- taler-auditor-dbinit -r -c $CONF
- $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation.json 2> test-audit-aggregation.log || exit_fail "aggregation audit failed"
+ taler-auditor-dbinit \
+ -r \
+ -c "$CONF"
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-aggregation.json \
+ 2> test-audit-aggregation.log \
+ || exit_fail "aggregation audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-aggregation -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-aggregation-inc.json 2> test-audit-aggregation-inc.log || exit_fail "incremental aggregation audit failed"
+ $VALGRIND taler-helper-auditor-aggregation \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-aggregation-inc.json \
+ 2> test-audit-aggregation-inc.log \
+ || exit_fail "incremental aggregation audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins.json 2> test-audit-coins.log || exit_fail "coin audit failed"
+ $VALGRIND taler-helper-auditor-coins \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-coins.json \
+ 2> test-audit-coins.log \
+ || exit_fail "coin audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-coins -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-coins-inc.json 2> test-audit-coins-inc.log || exit_fail "incremental coin audit failed"
+ $VALGRIND taler-helper-auditor-coins \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-coins-inc.json \
+ 2> test-audit-coins-inc.log \
+ || exit_fail "incremental coin audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits.json 2> test-audit-deposits.log || exit_fail "deposits audit failed"
+ $VALGRIND taler-helper-auditor-deposits \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-deposits.json \
+ 2> test-audit-deposits.log \
+ || exit_fail "deposits audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-deposits -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-deposits-inc.json 2> test-audit-deposits-inc.log || exit_fail "incremental deposits audit failed"
+ $VALGRIND taler-helper-auditor-deposits \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-deposits-inc.json \
+ 2> test-audit-deposits-inc.log \
+ || exit_fail "incremental deposits audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves.json 2> test-audit-reserves.log || exit_fail "reserves audit failed"
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-reserves.json \
+ 2> test-audit-reserves.log \
+ || exit_fail "reserves audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-reserves -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-reserves-inc.json 2> test-audit-reserves-inc.log || exit_fail "incremental reserves audit failed"
+ $VALGRIND taler-helper-auditor-reserves \
+ -i \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-reserves-inc.json \
+ 2> test-audit-reserves-inc.log \
+ || exit_fail "incremental reserves audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire.json 2> test-wire-audit.log || exit_fail "wire audit failed"
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-wire.json \
+ 2> test-wire-audit.log \
+ || exit_fail "wire audit failed"
echo -n "."
- $VALGRIND taler-helper-auditor-wire -i -L DEBUG -c $CONF -m $MASTER_PUB > test-audit-wire-inc.json 2> test-wire-audit-inc.log || exit_fail "wire audit failed"
+ $VALGRIND taler-helper-auditor-wire \
+ -i \
+ -L "$LOGLEVEL" \
+ -c "$CONF" \
+ -m "$MASTER_PUB" \
+ > test-audit-wire-inc.json \
+ 2> test-wire-audit-inc.log \
+ || exit_fail "wire audit failed"
echo -n "."
-
echo " DONE"
}
# Cleanup to run after the auditor
function post_audit () {
- echo -n "Cleanup ..."
cleanup
- echo " DONE"
echo -n "TeXing ."
- taler-helper-auditor-render.py test-audit-aggregation.json test-audit-coins.json test-audit-deposits.json test-audit-reserves.json test-audit-wire.json < ../../contrib/auditor-report.tex.j2 > test-report.tex || exit_fail "Renderer failed"
-
+ taler-helper-auditor-render.py \
+ test-audit-aggregation.json \
+ test-audit-coins.json \
+ test-audit-deposits.json \
+ test-audit-reserves.json \
+ test-audit-wire.json \
+ < ../../contrib/auditor-report.tex.j2 \
+ > test-report.tex \
+ || exit_fail "Renderer failed"
echo -n "."
- timeout 10 pdflatex test-report.tex >/dev/null || exit_fail "pdflatex failed"
+ timeout 10 pdflatex test-report.tex \
+ >/dev/null \
+ || exit_fail "pdflatex failed"
echo -n "."
- timeout 10 pdflatex test-report.tex >/dev/null
+ timeout 10 pdflatex test-report.tex \
+ >/dev/null
echo " DONE"
}
@@ -140,143 +282,158 @@ function post_audit () {
# $ taler-exchange-aggregator
# before auditor (to trigger pending wire transfers).
function run_audit () {
- pre_audit ${1:-no}
+ pre_audit "${1:-no}"
audit_only
post_audit
-
}
# Do a full reload of the (original) database
-full_reload()
+function full_reload()
{
echo -n "Doing full reload of the database... "
- dropdb $DB 2> /dev/null || true
- createdb -T template0 $DB || exit_skip "could not create database"
+ dropdb "$DB" 2> /dev/null || true
+ createdb -T template0 "$DB" \
+ || exit_skip "could not create database $DB (at $PGHOST)"
# Import pre-generated database, -q(ietly) using single (-1) transaction
- psql -Aqt $DB -q -1 -f ${BASEDB}.sql > /dev/null || exit_skip "Failed to load database"
+ psql -Aqt "$DB" \
+ -q \
+ -1 \
+ -f "${BASEDB}.sql" \
+ > /dev/null \
+ || exit_skip "Failed to load database $DB from ${BASEDB}.sql"
echo "DONE"
}
function test_0() {
+ echo "===========0: normal run with aggregator==========="
+ run_audit aggregator
+
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
+ echo -n "Test for deposit confirmation emergencies... "
+ jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
+
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo PASS
+
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
+ fi
+ LOSS=$(jq -r .total_bad_sig_loss < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
+ fi
-echo "===========0: normal run with aggregator==========="
-run_audit aggregator
-
-echo "Checking output"
-# if an emergency was detected, that is a bug and we should fail
-echo -n "Test for emergencies... "
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
-echo -n "Test for deposit confirmation emergencies... "
-jq -e .deposit_confirmation_inconsistencies[0] < test-audit-deposits.json > /dev/null && exit_fail "Unexpected deposit confirmation inconsistency detected" || echo PASS
-echo -n "Test for emergencies by count... "
-jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
-
-echo -n "Test for wire inconsistencies... "
-jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
-jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
-jq -e .missattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected missattribution inconsistency detected in ordinary run"
-jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
-jq -e .denomination_key_validity_withdraw_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected denomination key withdraw inconsistency detected in ordinary run"
-jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
-jq -e .lag_details[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected lag detected in ordinary run"
-jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
-
-
-# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
-# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
-
-echo PASS
-
-LOSS=`jq -r .total_bad_sig_loss < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from aggregation, got unexpected loss of $LOSS"
-fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from coins, got unexpected loss of $LOSS"
-fi
-LOSS=`jq -r .total_bad_sig_loss < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong total bad sig loss from reserves, got unexpected loss of $LOSS"
-fi
-
-echo -n "Test for wire amounts... "
-WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_missattribution_in < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total missattribution in wrong, got $WIRED"
-fi
-echo PASS
-
-echo -n "Checking for unexpected arithmetic differences "
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_plus < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
-fi
-LOSS=`jq -r .total_arithmetic_delta_minus < test-audit-reserves.json`
-if test $LOSS != "TESTKUDOS:0"
-then
- exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
-fi
-
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
-jq -e .amount_arithmetic_inconsistencies[0] < test-audit-reserves.json > /dev/null && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
-echo PASS
-
-echo -n "Checking for unexpected wire out differences "
-jq -e .wire_out_inconsistencies[0] < test-audit-aggregation.json > /dev/null && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
-echo PASS
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
+ echo "PASS"
-# cannot easily undo aggregator, hence full reload
-full_reload
+ echo -n "Checking for unexpected arithmetic differences "
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregations, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-aggregation.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from aggregation, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from coins, got unexpected minus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_plus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected plus of $LOSS"
+ fi
+ LOSS=$(jq -r .total_arithmetic_delta_minus < test-audit-reserves.json)
+ if [ "$LOSS" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Wrong arithmetic delta from reserves, got unexpected minus of $LOSS"
+ fi
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from aggregations detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from coins detected in ordinary run"
+ jq -e .amount_arithmetic_inconsistencies[0] \
+ < test-audit-reserves.json \
+ > /dev/null \
+ && exit_fail "Unexpected arithmetic inconsistencies from reserves detected in ordinary run"
+ echo "PASS"
+
+ echo -n "Checking for unexpected wire out differences "
+ jq -e .wire_out_inconsistencies[0] \
+ < test-audit-aggregation.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire out inconsistencies detected in ordinary run"
+ echo "PASS"
+
+ # cannot easily undo aggregator, hence full reload
+ full_reload
}
@@ -284,58 +441,84 @@ full_reload
# transfer lag!
function test_1() {
-echo "===========1: normal run==========="
-run_audit
-
-echo "Checking output"
-# if an emergency was detected, that is a bug and we should fail
-echo -n "Test for emergencies... "
-jq -e .emergencies[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency detected in ordinary run" || echo PASS
-echo -n "Test for emergencies by count... "
-jq -e .emergencies_by_count[0] < test-audit-coins.json > /dev/null && exit_fail "Unexpected emergency by count detected in ordinary run" || echo PASS
-
-echo -n "Test for wire inconsistencies... "
-jq -e .wire_out_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
-jq -e .reserve_in_amount_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
-jq -e .missattribution_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected missattribution inconsistency detected in ordinary run"
-jq -e .row_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected row inconsistency detected in ordinary run"
-jq -e .row_minor_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
-jq -e .wire_format_inconsistencies[0] < test-audit-wire.json > /dev/null && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
-
-# TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
-# TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
-
-echo PASS
-
-echo -n "Test for wire amounts... "
-WIRED=`jq -r .total_wire_in_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_in_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_plus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta plus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_wire_out_delta_minus < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total wire delta minus wrong, got $WIRED"
-fi
-WIRED=`jq -r .total_missattribution_in < test-audit-wire.json`
-if test $WIRED != "TESTKUDOS:0"
-then
- exit_fail "Expected total missattribution in wrong, got $WIRED"
-fi
+ echo "===========1: normal run==========="
+ run_audit
+
+ echo "Checking output"
+ # if an emergency was detected, that is a bug and we should fail
+ echo -n "Test for emergencies... "
+ jq -e .emergencies[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency detected in ordinary run" \
+ || echo "PASS"
+ echo -n "Test for emergencies by count... "
+ jq -e .emergencies_by_count[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ && exit_fail "Unexpected emergency by count detected in ordinary run" \
+ || echo "PASS"
+
+ echo -n "Test for wire inconsistencies... "
+ jq -e .wire_out_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire out inconsistency detected in ordinary run"
+ jq -e .reserve_in_amount_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected reserve in inconsistency detected in ordinary run"
+ jq -e .misattribution_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected misattribution inconsistency detected in ordinary run"
+ jq -e .row_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected row inconsistency detected in ordinary run"
+ jq -e .row_minor_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected minor row inconsistency detected in ordinary run"
+ jq -e .wire_format_inconsistencies[0] \
+ < test-audit-wire.json \
+ > /dev/null \
+ && exit_fail "Unexpected wire format inconsistencies detected in ordinary run"
+
+ # TODO: check operation balances are correct (once we have all transaction types and wallet is deterministic)
+ # TODO: check revenue summaries are correct (once we have all transaction types and wallet is deterministic)
+
+ echo "PASS"
+
+ echo -n "Test for wire amounts... "
+ WIRED=$(jq -r .total_wire_in_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_in_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_plus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta plus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_wire_out_delta_minus < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total wire delta minus wrong, got $WIRED"
+ fi
+ WIRED=$(jq -r .total_misattribution_in < test-audit-wire.json)
+ if [ "$WIRED" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Expected total misattribution in wrong, got $WIRED"
+ fi
-# Database was unmodified, no need to undo
-echo "OK"
+ # Database was unmodified, no need to undo
+ echo "OK"
}
@@ -343,38 +526,38 @@ echo "OK"
# Change recoup amount
function test_2() {
-echo "===========2: recoup amount inconsistency==========="
-echo "UPDATE recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt $DB
+ echo "===========2: recoup amount inconsistency==========="
+ echo "UPDATE exchange.recoup SET amount_val=5 WHERE recoup_uuid=1" | psql -Aqt "$DB"
-run_audit
+ run_audit
-# Reserve balance is now wrong
-echo -n "Testing inconsistency detection... "
-AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json`
-if test $AMOUNT != "TESTKUDOS:3"
-then
- exit_fail "Reserve auditor amount $AMOUNT is wrong"
-fi
-AMOUNT=`jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json`
-if test $AMOUNT != "TESTKUDOS:0"
-then
- exit_fail "Reserve exchange amount $AMOUNT is wrong"
-fi
-# Coin spent exceeded coin's value
-AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json`
-if test $AMOUNT != "TESTKUDOS:2"
-then
- exit_fail "Coin auditor amount $AMOUNT is wrong"
-fi
-AMOUNT=`jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json`
-if test $AMOUNT != "TESTKUDOS:5"
-then
- exit_fail "Coin exchange amount $AMOUNT is wrong"
-fi
-echo OK
+ # Reserve balance is now wrong
+ echo -n "Testing inconsistency detection... "
+ AMOUNT=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].auditor < test-audit-reserves.json)
+ if [ "$AMOUNT" != "TESTKUDOS:3" ]
+ then
+ exit_fail "Reserve auditor amount $AMOUNT is wrong"
+ fi
+ AMOUNT=$(jq -r .reserve_balance_summary_wrong_inconsistencies[0].exchange < test-audit-reserves.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Reserve exchange amount $AMOUNT is wrong"
+ fi
+ # Coin spent exceeded coin's value
+ AMOUNT=$(jq -r .amount_arithmetic_inconsistencies[0].auditor < test-audit-coins.json)
+ if [ "$AMOUNT" != "TESTKUDOS:2" ]
+ then
+ exit_fail "Coin auditor amount $AMOUNT is wrong"
+ fi
+ AMOUNT=$(jq -r .amount_arithmetic_inconsistencies[0].exchange < test-audit-coins.json)
+ if [ "$AMOUNT" != "TESTKUDOS:5" ]
+ then
+ exit_fail "Coin exchange amount $AMOUNT is wrong"
+ fi
+ echo "OK"
-# Undo database modification
-echo "UPDATE recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE exchange.recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt "$DB"
}
@@ -382,27 +565,27 @@ echo "UPDATE recoup SET amount_val=2 WHERE recoup_uuid=1" | psql -Aqt $DB
# Change recoup-refresh amount
function test_3() {
-echo "===========3: recoup-refresh amount inconsistency==========="
-echo "UPDATE recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB
+ echo "===========3: recoup-refresh amount inconsistency==========="
+ echo "UPDATE exchange.recoup_refresh SET amount_val=5 WHERE recoup_refresh_uuid=1" | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-# Coin spent exceeded coin's value
-AMOUNT=`jq -r .total_arithmetic_delta_minus < test-audit-coins.json`
-if test $AMOUNT != "TESTKUDOS:5"
-then
- exit_fail "Arithmetic delta minus amount $AMOUNT is wrong"
-fi
-AMOUNT=`jq -r .total_arithmetic_delta_plus < test-audit-coins.json`
-if test $AMOUNT != "TESTKUDOS:0"
-then
- exit_fail "Arithmetic delta plus amount $AMOUNT is wrong"
-fi
-echo OK
+ echo -n "Testing inconsistency detection... "
+ # Coin spent exceeded coin's value
+ AMOUNT=$(jq -r .total_arithmetic_delta_minus < test-audit-coins.json)
+ if [ "$AMOUNT" != "TESTKUDOS:5" ]
+ then
+ exit_fail "Arithmetic delta minus amount $AMOUNT is wrong"
+ fi
+ AMOUNT=$(jq -r .total_arithmetic_delta_plus < test-audit-coins.json)
+ if [ "$AMOUNT" != "TESTKUDOS:0" ]
+ then
+ exit_fail "Arithmetic delta plus amount $AMOUNT is wrong"
+ fi
+ echo "OK"
-# Undo database modification
-echo "UPDATE recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt $DB
+ # Undo database modification
+ echo "UPDATE exchange.recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql -Aqt "$DB"
}
@@ -410,72 +593,68 @@ echo "UPDATE recoup_refresh SET amount_val=0 WHERE recoup_refresh_uuid=1" | psql
# Void recoup-refresh entry by 'unrevoking' denomination
function test_4() {
-echo "===========4: invalid recoup==========="
-echo "DELETE FROM denomination_revocations;" | psql -Aqt $DB
+ echo "===========4: invalid recoup==========="
+ echo "DELETE FROM exchange.denomination_revocations;" | psql -Aqt "$DB"
-run_audit
+ run_audit
-echo -n "Testing inconsistency detection... "
-# Coin spent exceeded coin's value
-jq -e .bad_sig_losses[0] < test-audit-coins.json > /dev/null || exit_fail "Bad recoup not detected"
-AMOUNT=`jq -r .total_bad_sig_losses < test-audit-coins.json`
-if test $AMOUNT == "TESTKUDOS:0"
-then
- exit_fail "Total bad sig losses are wrong"
-fi
-TAB=`jq -r .row_inconsistencies[0].table < test-audit-reserves.json`
-if test $TAB != "recoup"
-then
- exit_fail "Wrong table for row inconsistency, got $TAB"
-fi
-echo OK
-
-# Undo database modification (can't easily undo DELETE, so full reload)
-full_reload
+ echo -n "Testing inconsistency detection... "
+ # Coin spent exceeded coin's value
+ jq -e .bad_sig_losses[0] \
+ < test-audit-coins.json \
+ > /dev/null \
+ || exit_fail "Bad recoup not detected"
+ AMOUNT=$(jq -r .irregular_loss < test-audit-coins.json)
+ if [ "$AMOUNT" == "TESTKUDOS:0" ]
+ then
+ exit_fail "Total bad sig losses are wrong"
+ fi
+ TAB=$(jq -r .row_inconsistencies[0].table < test-audit-reserves.json)
+ if [ "$TAB" != "recoup" ]
+ then
+ exit_fail "Wrong table for row inconsistency, got $TAB"
+ fi
+ echo "OK"
+ # Undo database modification (can't easily undo DELETE, so full reload)
+ full_reload
}
-
# *************** Main test loop starts here **************
# Run all the tests against the database given in $1.
# Sets $fail to 0 on success, non-zero on failure.
-check_with_database()
+function check_with_database()
{
- BASEDB=$1
+ BASEDB="$1"
+ # Configuration file to use
+ CONF="$1.conf"
echo "Running test suite with database $BASEDB using configuration $CONF"
- # Setup database-specific globals
- MASTER_PUB=`cat ${BASEDB}.mpub`
+ MASTER_PRIV_FILE="${BASEDB}.mpriv"
+ taler-config -f -c "${CONF}" -s exchange-offline -o MASTER_PRIV_FILE -V "${MASTER_PRIV_FILE}"
+ MASTER_PUB=$(gnunet-ecc -p "$MASTER_PRIV_FILE")
- # Determine database age
- echo "Calculating database age based on ${BASEDB}.age"
- AGE=`cat ${BASEDB}.age`
- NOW=`date +%s`
- # NOTE: expr "fails" if the result is zero.
- DATABASE_AGE=`expr ${NOW} - ${AGE} || true`
- echo "Database age is ${DATABASE_AGE} seconds"
+ echo "MASTER PUB is ${MASTER_PUB} using file ${MASTER_PRIV_FILE}"
# Load database
full_reload
-
# Run test suite
fail=0
for i in $TESTS
do
- test_$i
- if test 0 != $fail
+ "test_$i"
+ if [ 0 != "$fail" ]
then
break
fi
done
# echo "Cleanup (disabled, leaving database $DB behind)"
- dropdb $DB
- rm -f test-audit.log test-wire-audit.log
+ dropdb "$DB"
}
@@ -483,54 +662,91 @@ check_with_database()
# *************** Main logic starts here **************
# ####### Setup globals ######
-# Postgres database to use (must match revoke-basedb.conf)
-DB=taler-auditor-test
+# Postgres database to use
+DB=revoke-basedb
-# Configuration file to use
-CONF=revoke-basedb.conf
# test required commands exist
echo "Testing for jq"
jq -h > /dev/null || exit_skip "jq required"
-echo "Testing for taler-bank-manage"
-taler-bank-manage --help >/dev/null </dev/null || exit_skip "taler-bank-manage required"
+echo "Testing for faketime"
+faketime -h > /dev/null \
+ || exit_skip "faketime required"
+echo "Testing for libeufin-bank"
+libeufin-bank --help \
+ >/dev/null \
+ 2> /dev/null \
+ </dev/null \
+ || exit_skip "libeufin-bank required"
echo "Testing for pdflatex"
which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
-
-# check if we should regenerate the database
-if test -n "${1:-}"
-then
- echo "Custom run, will only run on existing DB."
+echo "Testing for taler-wallet-cli"
+taler-wallet-cli -h \
+ >/dev/null \
+ </dev/null \
+ 2>/dev/null \
+ || exit_skip "taler-wallet-cli required"
+
+echo -n "Testing for Postgres "
+# Available directly in path?
+INITDB_BIN=$(command -v initdb) || true
+if [[ -n "$INITDB_BIN" ]]; then
+ echo "FOUND (in path) at $INITDB_BIN"
else
- echo -n "Testing for taler-wallet-cli"
- if taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) || exit_skip " MISSING"
+ echo "FOUND at " "$(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
+fi
+echo -n "Setting up Postgres DB"
+POSTGRES_PATH=$(dirname "$INITDB_BIN")
+MY_TMP_DIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
+TMPDIR="${MY_TMP_DIR}/postgres/"
+mkdir -p "$TMPDIR"
+echo -n "Setting up Postgres DB at $TMPDIR ..."
+"$INITDB_BIN" \
+ --no-sync \
+ --auth=trust \
+ -D "${TMPDIR}" \
+ > "${MY_TMP_DIR}/postgres-dbinit.log" \
+ 2> "${MY_TMP_DIR}/postgres-dbinit.err"
+echo " DONE"
+mkdir "${TMPDIR}/sockets"
+echo -n "Launching Postgres service at $POSTGRES_PATH"
+cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+"${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MY_TMP_DIR}/postgres-start.log" \
+ 2> "${MY_TMP_DIR}/postgres-start.err"
+echo " DONE"
+PGHOST="$TMPDIR/sockets"
+export PGHOST
+
+echo "Generating fresh database at $MY_TMP_DIR"
+if faketime -f '-1 d' ./generate-revoke-basedb.sh "$MY_TMP_DIR/$DB"
+then
+ check_with_database "$MY_TMP_DIR/$DB"
+ if [ "x$fail" != "x0" ]
then
- MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX`
- echo " FOUND. Generating fresh database at $MYDIR"
- if ./generate-revoke-basedb.sh $MYDIR/basedb
- then
- check_with_database $MYDIR/basedb
- if test x$fail != x0
- then
- exit $fail
- else
- echo "Cleaning up $MYDIR..."
- rm -rf $MYDIR || echo "Removing $MYDIR failed"
- fi
- else
- echo "Generation failed, running only on existing DB"
- fi
+ exit "$fail"
else
- echo " NOT FOUND, running only on existing DB"
+ echo "Cleaning up $MY_TMP_DIR..."
+ rm -rf "$MY_TMP_DIR" || echo "Removing $MY_TMP_DIR failed"
fi
-fi
-
-# run tests with pre-build database, if one is available
-if test -r revoke-basedb.mpub
-then
- check_with_database "revoke-basedb"
else
- fail=77
+ echo "Generation failed"
fi
-exit $fail
+exit 0
diff --git a/src/auditor/test-sync.sh b/src/auditor/test-sync.sh
index a69201a8a..bcef908aa 100755
--- a/src/auditor/test-sync.sh
+++ b/src/auditor/test-sync.sh
@@ -1,43 +1,167 @@
-#!/bin/sh
+#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2014-2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 3, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
+#
+# shellcheck disable=SC2317
set -eu
-echo -n "Testing synchronization logic ..."
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+ echo "SKIPPING test: $1"
+ exit 77
+}
-dropdb talercheck-in 2> /dev/null || true
-dropdb talercheck-out 2> /dev/null || true
+# Exit, with error message (hard failure)
+function exit_fail() {
+ echo "FAILING test: $1"
+ exit 1
+}
-createdb talercheck-in || exit 77
-createdb talercheck-out || exit 77
-echo -n "."
+# Cleanup to run whenever we exit
+function cleanup() {
+ if [ -n "${POSTGRES_PATH:-}" ]
+ then
+ "${POSTGRES_PATH}/pg_ctl" -D "$TMPDIR" stop &> /dev/null || true
+ fi
+ for n in $(jobs -p)
+ do
+ kill "$n" 2> /dev/null || true
+ done
+ wait
+}
-taler-exchange-dbinit -c test-sync-out.conf
-echo -n "."
-psql talercheck-in < auditor-basedb.sql >/dev/null 2> /dev/null
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
-echo -n "."
-taler-auditor-sync -s test-sync-in.conf -d test-sync-out.conf -t
+function check_with_database()
+{
+ echo -n "Testing synchronization logic ..."
-# cs_nonce_locks excluded: no point
-for table in denominations denomination_revocations wire_targets reserves reserves_in reserves_close reserves_out auditors auditor_denom_sigs exchange_sign_keys signkey_revocations extensions extension_details known_coins refresh_commitments refresh_revealed_coins refresh_transfer_keys deposits refunds wire_out aggregation_tracking wire_fee recoup recoup_refresh
-do
+ dropdb talercheck-in 2> /dev/null || true
+ dropdb talercheck-out 2> /dev/null || true
+
+ createdb talercheck-in || exit 77
+ createdb talercheck-out || exit 77
echo -n "."
- CIN=`echo "SELECT COUNT(*) FROM $table" | psql talercheck-in -Aqt`
- COUT=`echo "SELECT COUNT(*) FROM $table" | psql talercheck-out -Aqt`
- if test ${CIN} != ${COUT}
- then
- dropdb talercheck-in
- dropdb talercheck-out
- echo "FAIL"
- echo "Record count mismatch: $CIN / $COUT in table $table"
- exit 1
- fi
-done
+ taler-exchange-dbinit -c test-sync-out.conf
+ echo -n "."
+ psql -Aqt talercheck-in \
+ -q -1 \
+ -f "$1.sql" \
+ >/dev/null \
+ || exit_skip "Failed to load database"
+
+ echo -n "."
+ taler-auditor-sync \
+ -s test-sync-in.conf \
+ -d test-sync-out.conf -t
-echo -n ". "
-dropdb talercheck-in
-dropdb talercheck-out
+ # cs_nonce_locks excluded: no point
+ for table in denominations denomination_revocations wire_targets reserves reserves_in reserves_close reserves_out auditors auditor_denom_sigs exchange_sign_keys signkey_revocations extensions policy_details policy_fulfillments known_coins refresh_commitments refresh_revealed_coins refresh_transfer_keys deposits refunds wire_out aggregation_tracking wire_fee recoup recoup_refresh
+ do
+ echo -n "."
+ CIN=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt)
+ COUT=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt)
-echo "PASS"
+ if [ "${CIN}" != "${COUT}" ]
+ then
+ dropdb talercheck-in
+ dropdb talercheck-out
+ echo "FAIL"
+ exit_fail "Record count mismatch: $CIN / $COUT in table $table"
+ fi
+ done
+
+ echo -n ". "
+ dropdb talercheck-in
+ dropdb talercheck-out
+
+ echo "PASS"
+ fail=0
+}
+
+# test required commands exist
+echo "Testing for jq"
+jq -h > /dev/null || exit_skip "jq required"
+echo "Testing for faketime"
+faketime -h > /dev/null || exit_skip "faketime required"
+echo "Testing for libeufin-bank"
+libeufin-bank --help >/dev/null </dev/null 2> /dev/null || exit_skip "libeufin-bank required"
+echo "Testing for pdflatex"
+which pdflatex > /dev/null </dev/null || exit_skip "pdflatex required"
+echo "Testing for taler-wallet-cli"
+taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet-cli required"
+
+echo -n "Testing for Postgres"
+# Available directly in path?
+INITDB_BIN=$(command -v initdb) || true
+if [[ -n "$INITDB_BIN" ]]; then
+ echo " FOUND (in path) at $INITDB_BIN"
+else
+ HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) || exit_skip " MISSING"
+ echo " FOUND at " "$(dirname "$HAVE_INITDB")"
+ INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
+fi
+echo -n "Setting up Postgres DB"
+POSTGRES_PATH=$(dirname "$INITDB_BIN")
+MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
+TMPDIR="$MYDIR/postgres/"
+mkdir -p "$TMPDIR"
+"$INITDB_BIN" --no-sync --auth=trust -D "${TMPDIR}" \
+ > "${MYDIR}/postgres-dbinit.log" \
+ 2> "${MYDIR}/postgres-dbinit.err"
+echo " DONE"
+mkdir "${TMPDIR}/sockets"
+echo -n "Launching Postgres service"
+cat - >> "$TMPDIR/postgresql.conf" <<EOF
+unix_socket_directories='${TMPDIR}/sockets'
+fsync=off
+max_wal_senders=0
+synchronous_commit=off
+wal_level=minimal
+listen_addresses=''
+EOF
+grep -v host \
+ < "$TMPDIR/pg_hba.conf" \
+ > "$TMPDIR/pg_hba.conf.new"
+mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf"
+"${POSTGRES_PATH}/pg_ctl" \
+ -D "$TMPDIR" \
+ -l /dev/null \
+ start \
+ > "${MYDIR}/postgres-start.log" \
+ 2> "${MYDIR}/postgres-start.err"
+echo " DONE"
+PGHOST="$TMPDIR/sockets"
+export PGHOST
+
+echo "Generating fresh database at $MYDIR"
+if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/auditor-basedb"
+then
+ check_with_database "$MYDIR/auditor-basedb"
+ if [ x$fail != x0 ]
+ then
+ exit "$fail"
+ else
+ echo "Cleaning up $MYDIR..."
+ rm -rf "$MYDIR" || echo "Removing $MYDIR failed"
+ fi
+else
+ echo "Generation failed"
+ exit 77
+fi
exit 0
diff --git a/src/auditordb/.gitignore b/src/auditordb/.gitignore
index 56c08312b..e1c7a648b 100644
--- a/src/auditordb/.gitignore
+++ b/src/auditordb/.gitignore
@@ -1 +1,5 @@
test-auditordb-postgres
+auditor-0002.sql
+procedures.sql
+test_auditordb_checkpoints_postgres
+test_auditordb-postgres
diff --git a/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql b/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql
new file mode 100644
index 000000000..19dfa682c
--- /dev/null
+++ b/src/auditordb/0002-auditor_amount_arithmetic_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_amount_arithmetic_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount,
+ profitable BOOLEAN
+);
+COMMENT ON TABLE auditor_amount_arithmetic_inconsistency
+ IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts';
diff --git a/src/auditordb/0002-auditor_bad_sig_losses.sql b/src/auditordb/0002-auditor_bad_sig_losses.sql
new file mode 100644
index 000000000..ac17a5120
--- /dev/null
+++ b/src/auditordb/0002-auditor_bad_sig_losses.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_bad_sig_losses
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ loss taler_amount,
+ operation_specific_pub BYTEA
+);
+COMMENT ON TABLE auditor_bad_sig_losses
+ IS 'Report a (serious) inconsistency with losses due to bad signatures'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_balances.sql b/src/auditordb/0002-auditor_balances.sql
new file mode 100644
index 000000000..8014b9c41
--- /dev/null
+++ b/src/auditordb/0002-auditor_balances.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE IF NOT EXISTS auditor_balances
+(
+ balance_key TEXT PRIMARY KEY NOT NULL
+ ,balance_value taler_amount
+);
+COMMENT
+ON TABLE auditor_balances
+ IS 'table storing various global balances of the auditor';
+COMMENT
+ON COLUMN auditor_balances.balance_key
+ IS 'unique name for the balance value';
+COMMENT
+ON COLUMN auditor_balances.balance_value
+ IS 'balance amount';
diff --git a/src/auditordb/0002-auditor_closure_lags.sql b/src/auditordb/0002-auditor_closure_lags.sql
new file mode 100644
index 000000000..8473b25f9
--- /dev/null
+++ b/src/auditordb/0002-auditor_closure_lags.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_closure_lags
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ deadline BIGINT,
+ wtid integer,
+ account BYTEA
+);
+COMMENT ON TABLE auditor_closure_lags
+ IS 'Report closure lags.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_coin_inconsistency.sql b/src/auditordb/0002-auditor_coin_inconsistency.sql
new file mode 100644
index 000000000..91f954a68
--- /dev/null
+++ b/src/auditordb/0002-auditor_coin_inconsistency.sql
@@ -0,0 +1,28 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_coin_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ operation BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount,
+ coin_pub BYTEA,
+ profitable BOOLEAN
+);
+COMMENT ON TABLE auditor_coin_inconsistency
+ IS 'Report a (serious) inconsistency in the exchange''s database with respect to calculations involving amounts'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql b/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql
new file mode 100644
index 000000000..fd18f35fb
--- /dev/null
+++ b/src/auditordb/0002-auditor_denomination_key_validity_withdraw_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_denomination_key_validity_withdraw_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ execution_date BIGINT,
+ reserve_pub BYTEA,
+ denompub_h BYTEA
+);
+COMMENT ON TABLE auditor_denomination_key_validity_withdraw_inconsistency
+ IS 'Report a (serious) denomination key validity withdraw inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_denomination_pending.sql b/src/auditordb/0002-auditor_denomination_pending.sql
new file mode 100644
index 000000000..f9ba535b4
--- /dev/null
+++ b/src/auditordb/0002-auditor_denomination_pending.sql
@@ -0,0 +1,34 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_denomination_pending
+ (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
+ ,denom_balance taler_amount NOT NULL
+ ,denom_loss taler_amount NOT NULL
+ ,num_issued INT8 NOT NULL
+ ,denom_risk taler_amount NOT NULL
+ ,recoup_loss taler_amount NOT NULL
+);
+COMMENT ON TABLE auditor_denomination_pending
+ IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
+COMMENT ON COLUMN auditor_denomination_pending.num_issued
+ IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
+COMMENT ON COLUMN auditor_denomination_pending.denom_risk
+ IS 'amount that could theoretically be lost in the future due to recoup operations';
+COMMENT ON COLUMN auditor_denomination_pending.denom_loss
+ IS 'amount that was lost due to failures by the exchange';
+COMMENT ON COLUMN auditor_denomination_pending.recoup_loss
+ IS 'amount actually lost due to recoup operations after a revocation';
diff --git a/src/auditordb/0002-auditor_denominations_without_sigs.sql b/src/auditordb/0002-auditor_denominations_without_sigs.sql
new file mode 100644
index 000000000..86c83e94f
--- /dev/null
+++ b/src/auditordb/0002-auditor_denominations_without_sigs.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_denominations_without_sigs
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ value taler_amount,
+ start_time BIGINT,
+ end_time BIGINT
+);
+COMMENT ON TABLE auditor_denominations_without_sigs
+ IS 'Report encountered denomination that auditor is not auditing.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_deposit_confirmations.sql b/src/auditordb/0002-auditor_deposit_confirmations.sql
new file mode 100644
index 000000000..1b7fec185
--- /dev/null
+++ b/src/auditordb/0002-auditor_deposit_confirmations.sql
@@ -0,0 +1,58 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_deposit_confirmations
+(deposit_confirmation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
+ ,h_policy BYTEA NOT NULL CHECK (LENGTH(h_policy)=64)
+ ,h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)
+ ,exchange_timestamp INT8 NOT NULL
+ ,refund_deadline INT8 NOT NULL
+ ,wire_deadline INT8 NOT NULL
+ ,total_without_fee taler_amount NOT NULL
+ ,coin_pubs BYTEA[] NOT NULL CHECK (CARDINALITY(coin_pubs)>0)
+ ,coin_sigs BYTEA[] NOT NULL CHECK (CARDINALITY(coin_sigs)=CARDINALITY(coin_pubs))
+ ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
+ ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
+ ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,suppressed BOOLEAN NOT NULL DEFAULT FALSE
+ ,ancient BOOLEAN NOT NULL DEFAULT FALSE
+ ,PRIMARY KEY (h_contract_terms,h_wire,merchant_pub,exchange_sig,exchange_pub,master_sig)
+ );
+COMMENT ON TABLE auditor_deposit_confirmations
+ IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
+
+CREATE INDEX IF NOT EXISTS auditor_deposit_confirmations_not_ancient
+ ON auditor_deposit_confirmations
+ (exchange_timestamp ASC)
+ WHERE NOT ancient;
+
+CREATE OR REPLACE FUNCTION auditor_new_transactions_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ NOTIFY XX81AFHF88YGN6ESNH39KR5VQE9MHD7GSSNMTCXB82SZ6T99ARHE0;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION auditor_new_transactions_trigger()
+ IS 'Call auditor_call_db_notify on new entry';
+
+CREATE TRIGGER auditor_notify_helper_deposits
+ AFTER INSERT
+ ON auditor.auditor_deposit_confirmations
+EXECUTE PROCEDURE auditor_new_transactions_trigger();
diff --git a/src/auditordb/0002-auditor_emergency.sql b/src/auditordb/0002-auditor_emergency.sql
new file mode 100644
index 000000000..2bb13d7e5
--- /dev/null
+++ b/src/auditordb/0002-auditor_emergency.sql
@@ -0,0 +1,29 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_emergency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ denom_risk taler_amount,
+ denom_loss taler_amount,
+ deposit_start BIGINT,
+ deposit_end BIGINT,
+ value taler_amount
+);
+COMMENT ON TABLE auditor_emergency
+ IS 'Report an emergency denomination.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_emergency_by_count.sql b/src/auditordb/0002-auditor_emergency_by_count.sql
new file mode 100644
index 000000000..4daa994a7
--- /dev/null
+++ b/src/auditordb/0002-auditor_emergency_by_count.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_emergency_by_count
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ denompub_h BYTEA,
+ num_issued integer,
+ num_known integer,
+ risk taler_amount,
+ start BIGINT,
+ deposit_end BIGINT,
+ value taler_amount
+);
+COMMENT ON TABLE auditor_emergency_by_count
+ IS 'Report an emergency denomination.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_exchange_signkeys.sql b/src/auditordb/0002-auditor_exchange_signkeys.sql
new file mode 100644
index 000000000..64349a2ff
--- /dev/null
+++ b/src/auditordb/0002-auditor_exchange_signkeys.sql
@@ -0,0 +1,35 @@
+ --
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_exchange_signkeys
+ (exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32)
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,ep_valid_from INT8 NOT NULL
+ ,ep_expire_sign INT8 NOT NULL
+ ,ep_expire_legal INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_exchange_signkeys
+ IS 'list of the online signing keys of exchanges we are auditing';
+COMMENT ON COLUMN auditor_exchange_signkeys.exchange_pub
+ IS 'Public online signing key of the exchange.';
+COMMENT ON COLUMN auditor_exchange_signkeys.master_sig
+ IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_valid_from
+ IS 'Time when this online signing key will first be used to sign messages.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_expire_sign
+ IS 'Time when this online signing key will no longer be used to sign.';
+COMMENT ON COLUMN auditor_exchange_signkeys.ep_expire_legal
+ IS 'Time when this online signing key legally expires.';
diff --git a/src/auditordb/0002-auditor_fee_time_inconsistency.sql b/src/auditordb/0002-auditor_fee_time_inconsistency.sql
new file mode 100644
index 000000000..b89cc59c7
--- /dev/null
+++ b/src/auditordb/0002-auditor_fee_time_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_fee_time_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ type BYTEA,
+ time BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_fee_time_inconsistency
+ IS 'Report a (serious) fee time inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_historic_denomination_revenue.sql b/src/auditordb/0002-auditor_historic_denomination_revenue.sql
new file mode 100644
index 000000000..bf7e4c07e
--- /dev/null
+++ b/src/auditordb/0002-auditor_historic_denomination_revenue.sql
@@ -0,0 +1,32 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_historic_denomination_revenue
+ (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
+ ,revenue_timestamp INT8 NOT NULL
+ ,revenue_balance taler_amount NOT NULL
+ ,loss_balance taler_amount NOT NULL
+ );
+COMMENT ON TABLE auditor_historic_denomination_revenue
+ IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.denom_pub_hash
+ IS 'hash of the denomination public key that created this revenue';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_timestamp
+ IS 'when was this revenue realized (by the denomination public key expiring)';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_balance
+ IS 'the sum of all of the profits we made on the denomination except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
+COMMENT ON COLUMN auditor_historic_denomination_revenue.loss_balance
+ IS 'the sum of all of the losses we made on the denomination (for example, because the signing key was compromised and thus we redeemed coins we never issued); of course should be zero in practice in most cases';
diff --git a/src/auditordb/0002-auditor_historic_reserve_summary.sql b/src/auditordb/0002-auditor_historic_reserve_summary.sql
new file mode 100644
index 000000000..819c4e160
--- /dev/null
+++ b/src/auditordb/0002-auditor_historic_reserve_summary.sql
@@ -0,0 +1,30 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary
+ (start_date INT8 PRIMARY KEY
+ ,end_date INT8 NOT NULL
+ ,reserve_profits taler_amount NOT NULL
+ );
+COMMENT ON TABLE auditor_historic_reserve_summary
+ IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
+COMMENT ON COLUMN auditor_historic_reserve_summary.start_date
+ IS 'start date of the time interval over which we made these profits from reserves';
+COMMENT ON COLUMN auditor_historic_reserve_summary.end_date
+ IS 'end date (exclusive) of the time interval over which we made these profits from reserves';
+COMMENT ON COLUMN auditor_historic_reserve_summary.reserve_profits
+ IS 'total amount in profits made';
diff --git a/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql b/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql
new file mode 100644
index 000000000..f786d0fdf
--- /dev/null
+++ b/src/auditordb/0002-auditor_misattribution_in_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_misattribution_in_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ bank_row BIGINT,
+ reserve_pub BYTEA
+);
+COMMENT ON TABLE auditor_misattribution_in_inconsistency
+ IS 'Report wire transfer that was smaller than it should have been.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_progress.sql b/src/auditordb/0002-auditor_progress.sql
new file mode 100644
index 000000000..288a08ae9
--- /dev/null
+++ b/src/auditordb/0002-auditor_progress.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE IF NOT EXISTS auditor_progress
+ (progress_key TEXT PRIMARY KEY NOT NULL
+ ,progress_offset INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_progress
+ IS 'Information about to the point until which the audit has progressed. Used for SELECTing the statements to process.';
+COMMENT ON COLUMN auditor_progress.progress_key
+ IS 'Name of the progress indicator';
+COMMENT ON COLUMN auditor_progress.progress_offset
+ IS 'Table offset or timestamp or counter until which the audit has progressed';
diff --git a/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql b/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql
new file mode 100644
index 000000000..5ffb6e85a
--- /dev/null
+++ b/src/auditordb/0002-auditor_purse_not_closed_inconsistencies.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_purse_not_closed_inconsistencies
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ purse_pub BYTEA,
+ amount taler_amount,
+ expiration_date BIGINT
+);
+COMMENT ON TABLE auditor_purse_not_closed_inconsistencies
+ IS 'Report expired purses'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_purses.sql b/src/auditordb/0002-auditor_purses.sql
new file mode 100644
index 000000000..86b6494d1
--- /dev/null
+++ b/src/auditordb/0002-auditor_purses.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_purses
+ (auditor_purses_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)
+ ,balance taler_amount NOT NULL DEFAULT(0,0)
+ ,target taler_amount NOT NULL
+ ,expiration_date INT8 NOT NULL
+ );
+COMMENT ON TABLE auditor_purses
+ IS 'all of the purses and their respective balances that the auditor is aware of';
diff --git a/src/auditordb/0002-auditor_refreshes_hanging.sql b/src/auditordb/0002-auditor_refreshes_hanging.sql
new file mode 100644
index 000000000..5544bc0d8
--- /dev/null
+++ b/src/auditordb/0002-auditor_refreshes_hanging.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_refreshes_hanging
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ coin_pub BYTEA
+);
+COMMENT ON TABLE auditor_refreshes_hanging
+ IS 'Report a hanging refresh.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql b/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql
new file mode 100644
index 000000000..bbc0c8118
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_balance_insufficient_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_balance_insufficient_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ inconsistency_gain BOOLEAN,
+ inconsistency_amount taler_amount
+);
+COMMENT ON TABLE auditor_reserve_balance_insufficient_inconsistency
+ IS 'Report a (serious) balance insufficiency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql b/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql
new file mode 100644
index 000000000..26d872132
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_balance_summary_wrong_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_balance_summary_wrong_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ exchange_amount taler_amount,
+ auditor_amount taler_amount
+);
+COMMENT ON TABLE auditor_reserve_balance_summary_wrong_inconsistency
+ IS 'Report a (serious) reserve balance insufficiency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_in_inconsistency.sql b/src/auditordb/0002-auditor_reserve_in_inconsistency.sql
new file mode 100644
index 000000000..bb90c4018
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_in_inconsistency.sql
@@ -0,0 +1,29 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_in_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount_exchange_expected taler_amount,
+ amount_wired taler_amount,
+ reserve_pub BYTEA,
+ timestamp BIGINT,
+ account BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_reserve_in_inconsistency
+ IS 'Report an incoming wire transfer claimed by exchange not found.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql b/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql
new file mode 100644
index 000000000..1147b4ae8
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserve_not_closed_inconsistency.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_reserve_not_closed_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ reserve_pub BYTEA,
+ balance taler_amount,
+ expiration_time BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_reserve_not_closed_inconsistency
+ IS 'Report a (serious) reserve balance insufficiency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_reserves.sql b/src/auditordb/0002-auditor_reserves.sql
new file mode 100644
index 000000000..808524b28
--- /dev/null
+++ b/src/auditordb/0002-auditor_reserves.sql
@@ -0,0 +1,31 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE auditor_reserves
+ (auditor_reserves_rowid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)
+ ,reserve_balance taler_amount NOT NULL
+ ,reserve_loss taler_amount NOT NULL
+ ,withdraw_fee_balance taler_amount NOT NULL
+ ,close_fee_balance taler_amount NOT NULL
+ ,purse_fee_balance taler_amount NOT NULL
+ ,open_fee_balance taler_amount NOT NULL
+ ,history_fee_balance taler_amount NOT NULL
+ ,expiration_date INT8 NOT NULL
+ ,origin_account TEXT
+ );
+COMMENT ON TABLE auditor_reserves
+ IS 'all of the customer reserves and their respective balances that the auditor is aware of';
diff --git a/src/auditordb/0002-auditor_row_inconsistency.sql b/src/auditordb/0002-auditor_row_inconsistency.sql
new file mode 100644
index 000000000..ece2e5661
--- /dev/null
+++ b/src/auditordb/0002-auditor_row_inconsistency.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_row_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ table BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_row_inconsistency
+ IS 'Report a (serious) row inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_row_minor_inconsistencies.sql b/src/auditordb/0002-auditor_row_minor_inconsistencies.sql
new file mode 100644
index 000000000..7836037c7
--- /dev/null
+++ b/src/auditordb/0002-auditor_row_minor_inconsistencies.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_row_minor_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ table BYTEA,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_row_minor_inconsistency
+ IS 'Report a (serious) row inconsistency in the exchange''s database.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_wire_format_inconsistency.sql b/src/auditordb/0002-auditor_wire_format_inconsistency.sql
new file mode 100644
index 000000000..1bc9af89d
--- /dev/null
+++ b/src/auditordb/0002-auditor_wire_format_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_wire_format_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ amount taler_amount,
+ wire_offset BIGINT,
+ diagnostic BYTEA
+);
+COMMENT ON TABLE auditor_wire_format_inconsistency
+ IS 'Report a (serious) format inconsistency.'; \ No newline at end of file
diff --git a/src/auditordb/0002-auditor_wire_out_inconsistency.sql b/src/auditordb/0002-auditor_wire_out_inconsistency.sql
new file mode 100644
index 000000000..6a49c24a0
--- /dev/null
+++ b/src/auditordb/0002-auditor_wire_out_inconsistency.sql
@@ -0,0 +1,26 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+SET search_path TO auditor;
+CREATE TABLE IF NOT EXISTS auditor_wire_out_inconsistency
+(
+ row_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE PRIMARY KEY,
+ destination_account BYTEA,
+ expected taler_amount,
+ claimed taler_amount
+);
+COMMENT ON TABLE auditor_wire_out_inconsistency
+ IS 'Report a (serious) wire inconsistency in the exchange''s database'; \ No newline at end of file
diff --git a/src/auditordb/9999.sql b/src/auditordb/9999.sql
deleted file mode 100644
index d6add4b20..000000000
--- a/src/auditordb/9999.sql
+++ /dev/null
@@ -1,53 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2020 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
-NOTE: This code is not yet ready / in use. It was archived here
-as we might want this kind of table in the future. It is NOT
-to be installed in a production system (hence in EXTRA_DIST and
-not in the SQL target!)
-
--- Check patch versioning is in place.
-SELECT _v.register_patch('auditor-9999', NULL, NULL);
-
-
--- Table with historic business ledger; basically, when the exchange
--- operator decides to use operating costs for anything but wire
--- transfers to merchants, it goes in here. This happens when the
--- operator users transaction fees for business expenses. purpose
--- is free-form but should be a human-readable wire transfer
--- identifier. This is NOT yet used and outside of the scope of
--- the core auditing logic. However, once we do take fees to use
--- operating costs, and if we still want auditor_predicted_result to match
--- the tables overall, we'll need a command-line tool to insert rows
--- into this table and update auditor_predicted_result accordingly.
--- (So this table for now just exists as a reminder of what we'll
--- need in the long term.)
-CREATE TABLE IF NOT EXISTS auditor_historic_ledger
- (master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,purpose VARCHAR NOT NULL
- ,timestamp INT8 NOT NULL
- ,balance_val INT8 NOT NULL
- ,balance_frac INT4 NOT NULL
- );
-CREATE INDEX history_ledger_by_master_pub_and_time
- ON auditor_historic_ledger
- (master_pub
- ,timestamp);
-
-COMMIT;
diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am
index 92aabcd31..c0282e9c9 100644
--- a/src/auditordb/Makefile.am
+++ b/src/auditordb/Makefile.am
@@ -13,17 +13,41 @@ pkgcfg_DATA = \
sqldir = $(prefix)/share/taler/sql/auditor/
+sqlinputs = \
+ 0002-*.sql \
+ auditor-0002.sql.in \
+ auditor_do_*.sql \
+ procedures.sql.in
+
sql_DATA = \
- auditor-0000.sql \
+ versioning.sql \
auditor-0001.sql \
- drop0001.sql \
- restart0001.sql
+ auditor-0002.sql \
+ drop.sql \
+ restart.sql \
+ procedures.sql
+
+CLEANFILES = \
+ auditor-0002.sql
+
+procedures.sql: procedures.sql.in auditor_do_*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < procedures.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
+ chmod ugo-w $@
+
+auditor-0002.sql: auditor-0002.sql.in 0002-*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < auditor-0002.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
+ chmod ugo-w $@
+
EXTRA_DIST = \
auditordb-postgres.conf \
test-auditor-db-postgres.conf \
+ $(sqlinputs) \
$(sql_DATA) \
- 9999.sql
+ pg_template.h pg_template.c \
+ pg_template.sh
plugindir = $(libdir)/taler
@@ -33,17 +57,48 @@ plugin_LTLIBRARIES = \
endif
libtaler_plugin_auditordb_postgres_la_SOURCES = \
- plugin_auditordb_postgres.c
-libtaler_plugin_auditordb_postgres_la_LIBADD = \
- $(LTLIBINTL)
+ plugin_auditordb_postgres.c pg_helper.h \
+ pg_delete_deposit_confirmations.c pg_delete_deposit_confirmations.h \
+ pg_delete_pending_deposit.c pg_delete_pending_deposit.h \
+ pg_delete_purse_info.c pg_delete_purse_info.h \
+ pg_del_denomination_balance.h pg_del_denomination_balance.c \
+ pg_del_reserve_info.c pg_del_reserve_info.h \
+ pg_get_auditor_progress.c pg_get_auditor_progress.h \
+ pg_get_balance.c pg_get_balance.h \
+ pg_get_denomination_balance.c pg_get_denomination_balance.h \
+ pg_get_deposit_confirmations.c pg_get_deposit_confirmations.h \
+ pg_get_purse_info.c pg_get_purse_info.h \
+ pg_get_reserve_info.c pg_get_reserve_info.h \
+ pg_get_wire_fee_summary.c pg_get_wire_fee_summary.h \
+ pg_insert_auditor_progress.c pg_insert_auditor_progress.h \
+ pg_insert_balance.c pg_insert_balance.h \
+ pg_insert_denomination_balance.c pg_insert_denomination_balance.h \
+ pg_insert_deposit_confirmation.c pg_insert_deposit_confirmation.h \
+ pg_insert_exchange_signkey.c pg_insert_exchange_signkey.h \
+ pg_insert_historic_denom_revenue.c pg_insert_historic_denom_revenue.h \
+ pg_insert_historic_reserve_revenue.c pg_insert_historic_reserve_revenue.h \
+ pg_insert_pending_deposit.c pg_insert_pending_deposit.h \
+ pg_insert_purse_info.c pg_insert_purse_info.h \
+ pg_insert_reserve_info.c pg_insert_reserve_info.h \
+ pg_select_historic_denom_revenue.c pg_select_historic_denom_revenue.h \
+ pg_select_historic_reserve_revenue.c pg_select_historic_reserve_revenue.h \
+ pg_select_pending_deposits.c pg_select_pending_deposits.h \
+ pg_select_purse_expired.c pg_select_purse_expired.h \
+ pg_update_auditor_progress.c pg_update_auditor_progress.h \
+ pg_update_balance.c pg_update_balance.h \
+ pg_update_denomination_balance.c pg_update_denomination_balance.h \
+ pg_update_purse_info.c pg_update_purse_info.h \
+ pg_update_reserve_info.c pg_update_reserve_info.h \
+ pg_update_wire_fee_summary.c pg_update_wire_fee_summary.h
libtaler_plugin_auditordb_postgres_la_LDFLAGS = \
- $(TALER_PLUGIN_LDFLAGS) \
+ $(TALER_PLUGIN_LDFLAGS)
+libtaler_plugin_auditordb_postgres_la_LIBADD = \
+ $(LTLIBINTL) \
$(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lpq \
-lgnunetpq \
-lgnunetutil \
- -lpthread \
+ -lpq \
$(XLIB)
lib_LTLIBRARIES = \
@@ -65,11 +120,22 @@ libtalerauditordb_la_LDFLAGS = \
check_PROGRAMS = \
- test-auditordb-postgres
+ test_auditordb_checkpoints-postgres \
+ test_auditordb-postgres
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \
- test-auditordb-postgres
+ test_auditordb_checkpoints-postgres \
+ test_auditordb-postgres
+
+test_auditordb_checkpoints_postgres_SOURCES = \
+ test_auditordb_checkpoints.c
+test_auditordb_checkpoints_postgres_LDADD = \
+ libtalerauditordb.la \
+ $(top_srcdir)/src/pq/libtalerpq.la \
+ $(top_srcdir)/src/util/libtalerutil.la \
+ -lgnunetutil \
+ $(XLIB)
test_auditordb_postgres_SOURCES = \
test_auditordb.c
diff --git a/src/auditordb/auditor-0000.sql b/src/auditordb/auditor-0000.sql
deleted file mode 100644
index 116f409b7..000000000
--- a/src/auditordb/auditor-0000.sql
+++ /dev/null
@@ -1,293 +0,0 @@
--- LICENSE AND COPYRIGHT
---
--- Copyright (C) 2010 Hubert depesz Lubaczewski
---
--- This program is distributed under the (Revised) BSD License:
--- L<http://www.opensource.org/licenses/bsd-license.php>
---
--- Redistribution and use in source and binary forms, with or without
--- modification, are permitted provided that the following conditions
--- are met:
---
--- * Redistributions of source code must retain the above copyright
--- notice, this list of conditions and the following disclaimer.
---
--- * Redistributions in binary form must reproduce the above copyright
--- notice, this list of conditions and the following disclaimer in the
--- documentation and/or other materials provided with the distribution.
---
--- * Neither the name of Hubert depesz Lubaczewski's Organization
--- nor the names of its contributors may be used to endorse or
--- promote products derived from this software without specific
--- prior written permission.
---
--- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
--- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
--- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
--- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
--- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
--- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
--- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
--- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
--- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
--- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---
--- Code origin: https://gitlab.com/depesz/Versioning/blob/master/install.versioning.sql
---
---
--- # NAME
---
--- **Versioning** - simplistic take on tracking and applying changes to databases.
---
--- # DESCRIPTION
---
--- This project strives to provide simple way to manage changes to
--- database.
---
--- Instead of making changes on development server, then finding
--- differences between production and development, deciding which ones
--- should be installed on production, and finding a way to install them -
--- you start with writing diffs themselves!
---
--- # INSTALLATION
---
--- To install versioning simply run install.versioning.sql in your database
--- (all of them: production, stage, test, devel, ...).
---
--- # USAGE
---
--- In your files with patches to database, put whole logic in single
--- transaction, and use \_v.\* functions - usually \_v.register_patch() at
--- least to make sure everything is OK.
---
--- For example. Let's assume you have patch files:
---
--- ## 0001.sql:
---
--- ```
--- create table users (id serial primary key, username text);
--- ```
---
--- ## 0002.sql:
---
--- ```
--- insert into users (username) values ('depesz');
--- ```
--- To change it to use versioning you would change the files, to this
--- state:
---
--- 0000.sql:
---
--- ```
--- BEGIN;
--- select _v.register_patch('000-base', NULL, NULL);
--- create table users (id serial primary key, username text);
--- COMMIT;
--- ```
---
--- ## 0002.sql:
---
--- ```
--- BEGIN;
--- select _v.register_patch('001-users', ARRAY['000-base'], NULL);
--- insert into users (username) values ('depesz');
--- COMMIT;
--- ```
---
--- This will make sure that patch 001-users can only be applied after
--- 000-base.
---
--- # AVAILABLE FUNCTIONS
---
--- ## \_v.register_patch( TEXT )
---
--- Registers named patch, or dies if it is already registered.
---
--- Returns integer which is id of patch in \_v.patches table - only if it
--- succeeded.
---
--- ## \_v.register_patch( TEXT, TEXT[] )
---
--- Same as \_v.register_patch( TEXT ), but checks is all given patches (given as
--- array in second argument) are already registered.
---
--- ## \_v.register_patch( TEXT, TEXT[], TEXT[] )
---
--- Same as \_v.register_patch( TEXT, TEXT[] ), but also checks if there are no conflicts with preexisting patches.
---
--- Third argument is array of names of patches that conflict with current one. So
--- if any of them is installed - register_patch will error out.
---
--- ## \_v.unregister_patch( TEXT )
---
--- Removes information about given patch from the versioning data.
---
--- It doesn't remove objects that were created by this patch - just removes
--- metainformation.
---
--- ## \_v.assert_user_is_superuser()
---
--- Make sure that current patch is being loaded by superuser.
---
--- If it's not - it will raise exception, and break transaction.
---
--- ## \_v.assert_user_is_not_superuser()
---
--- Make sure that current patch is not being loaded by superuser.
---
--- If it is - it will raise exception, and break transaction.
---
--- ## \_v.assert_user_is_one_of(TEXT, TEXT, ... )
---
--- Make sure that current patch is being loaded by one of listed users.
---
--- If ```current_user``` is not listed as one of arguments - function will raise
--- exception and break the transaction.
-
-BEGIN;
-
--- This file adds versioning support to database it will be loaded to.
--- It requires that PL/pgSQL is already loaded - will raise exception otherwise.
--- All versioning "stuff" (tables, functions) is in "_v" schema.
-
--- All functions are defined as 'RETURNS SETOF INT4' to be able to make them to RETURN literally nothing (0 rows).
--- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling.
-CREATE SCHEMA IF NOT EXISTS _v;
-COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
-
-CREATE TABLE IF NOT EXISTS _v.patches (
- patch_name TEXT PRIMARY KEY,
- applied_tsz TIMESTAMPTZ NOT NULL DEFAULT now(),
- applied_by TEXT NOT NULL,
- requires TEXT[],
- conflicts TEXT[]
-);
-COMMENT ON TABLE _v.patches IS 'Contains information about what patches are currently applied on database.';
-COMMENT ON COLUMN _v.patches.patch_name IS 'Name of patch, has to be unique for every patch.';
-COMMENT ON COLUMN _v.patches.applied_tsz IS 'When the patch was applied.';
-COMMENT ON COLUMN _v.patches.applied_by IS 'Who applied this patch (PostgreSQL username)';
-COMMENT ON COLUMN _v.patches.requires IS 'List of patches that are required for given patch.';
-COMMENT ON COLUMN _v.patches.conflicts IS 'List of patches that conflict with given patch.';
-
-CREATE OR REPLACE FUNCTION _v.register_patch( IN in_patch_name TEXT, IN in_requirements TEXT[], in_conflicts TEXT[], OUT versioning INT4 ) RETURNS setof INT4 AS $$
-DECLARE
- t_text TEXT;
- t_text_a TEXT[];
- i INT4;
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF FOUND THEN
- RAISE EXCEPTION 'Patch % is already applied!', in_patch_name;
- END IF;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE patch_name = any( in_conflicts ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Versioning patches conflict. Conflicting patche(s) installed: %.', array_to_string( t_text_a, ', ' );
- END IF;
-
- IF array_upper( in_requirements, 1 ) IS NOT NULL THEN
- t_text_a := '{}';
- FOR i IN array_lower( in_requirements, 1 ) .. array_upper( in_requirements, 1 ) LOOP
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_requirements[i];
- IF NOT FOUND THEN
- t_text_a := t_text_a || in_requirements[i];
- END IF;
- END LOOP;
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Missing prerequisite(s): %.', array_to_string( t_text_a, ', ' );
- END IF;
- END IF;
-
- INSERT INTO _v.patches (patch_name, applied_tsz, applied_by, requires, conflicts ) VALUES ( in_patch_name, now(), current_user, coalesce( in_requirements, '{}' ), coalesce( in_conflicts, '{}' ) );
- RETURN;
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[], TEXT[] ) IS 'Function to register patches in database. Raises exception if there are conflicts, prerequisites are not installed or the migration has already been installed.';
-
-CREATE OR REPLACE FUNCTION _v.register_patch( TEXT, TEXT[] ) RETURNS setof INT4 AS $$
- SELECT _v.register_patch( $1, $2, NULL );
-$$ language sql;
-COMMENT ON FUNCTION _v.register_patch( TEXT, TEXT[] ) IS 'Wrapper to allow registration of patches without conflicts.';
-CREATE OR REPLACE FUNCTION _v.register_patch( TEXT ) RETURNS setof INT4 AS $$
- SELECT _v.register_patch( $1, NULL, NULL );
-$$ language sql;
-COMMENT ON FUNCTION _v.register_patch( TEXT ) IS 'Wrapper to allow registration of patches without requirements and conflicts.';
-
-CREATE OR REPLACE FUNCTION _v.unregister_patch( IN in_patch_name TEXT, OUT versioning INT4 ) RETURNS setof INT4 AS $$
-DECLARE
- i INT4;
- t_text_a TEXT[];
-BEGIN
- -- Thanks to this we know only one patch will be applied at a time
- LOCK TABLE _v.patches IN EXCLUSIVE MODE;
-
- t_text_a := ARRAY( SELECT patch_name FROM _v.patches WHERE in_patch_name = ANY( requires ) );
- IF array_upper( t_text_a, 1 ) IS NOT NULL THEN
- RAISE EXCEPTION 'Cannot uninstall %, as it is required by: %.', in_patch_name, array_to_string( t_text_a, ', ' );
- END IF;
-
- DELETE FROM _v.patches WHERE patch_name = in_patch_name;
- GET DIAGNOSTICS i = ROW_COUNT;
- IF i < 1 THEN
- RAISE EXCEPTION 'Patch % is not installed, so it can''t be uninstalled!', in_patch_name;
- END IF;
-
- RETURN;
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.unregister_patch( TEXT ) IS 'Function to unregister patches in database. Dies if the patch is not registered, or if unregistering it would break dependencies.';
-
-CREATE OR REPLACE FUNCTION _v.assert_patch_is_applied( IN in_patch_name TEXT ) RETURNS TEXT as $$
-DECLARE
- t_text TEXT;
-BEGIN
- SELECT patch_name INTO t_text FROM _v.patches WHERE patch_name = in_patch_name;
- IF NOT FOUND THEN
- RAISE EXCEPTION 'Patch % is not applied!', in_patch_name;
- END IF;
- RETURN format('Patch %s is applied.', in_patch_name);
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.assert_patch_is_applied( TEXT ) IS 'Function that can be used to make sure that patch has been applied.';
-
-CREATE OR REPLACE FUNCTION _v.assert_user_is_superuser() RETURNS TEXT as $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RETURN 'assert_user_is_superuser: OK';
- END IF;
- RAISE EXCEPTION 'Current user is not superuser - cannot continue.';
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.assert_user_is_superuser() IS 'Function that can be used to make sure that patch is being applied using superuser account.';
-
-CREATE OR REPLACE FUNCTION _v.assert_user_is_not_superuser() RETURNS TEXT as $$
-DECLARE
- v_super bool;
-BEGIN
- SELECT usesuper INTO v_super FROM pg_user WHERE usename = current_user;
- IF v_super THEN
- RAISE EXCEPTION 'Current user is superuser - cannot continue.';
- END IF;
- RETURN 'assert_user_is_not_superuser: OK';
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.assert_user_is_not_superuser() IS 'Function that can be used to make sure that patch is being applied using normal (not superuser) account.';
-
-CREATE OR REPLACE FUNCTION _v.assert_user_is_one_of(VARIADIC p_acceptable_users TEXT[] ) RETURNS TEXT as $$
-DECLARE
-BEGIN
- IF current_user = any( p_acceptable_users ) THEN
- RETURN 'assert_user_is_one_of: OK';
- END IF;
- RAISE EXCEPTION 'User is not one of: % - cannot continue.', p_acceptable_users;
-END;
-$$ language plpgsql;
-COMMENT ON FUNCTION _v.assert_user_is_one_of(TEXT[]) IS 'Function that can be used to make sure that patch is being applied by one of defined users.';
-
-COMMIT;
diff --git a/src/auditordb/auditor-0001.sql b/src/auditordb/auditor-0001.sql
index daefdc172..0b7823cec 100644
--- a/src/auditordb/auditor-0001.sql
+++ b/src/auditordb/auditor-0001.sql
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2020 Taler Systems SA
+-- Copyright (C) 2014--2024 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -14,257 +14,283 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
--
--- Everything in one big transaction
BEGIN;
--- Check patch versioning is in place.
SELECT _v.register_patch('auditor-0001', NULL, NULL);
-
-CREATE TABLE IF NOT EXISTS auditor_exchanges
- (master_pub BYTEA PRIMARY KEY CHECK (LENGTH(master_pub)=32)
- ,exchange_url VARCHAR NOT NULL
+CREATE SCHEMA auditor;
+COMMENT ON SCHEMA auditor IS 'taler-auditor data';
+
+SET search_path TO auditor;
+
+---------------------------------------------------------------------------
+-- General procedures for DB setup
+---------------------------------------------------------------------------
+
+CREATE TABLE auditor_tables
+ (table_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY
+ ,name TEXT NOT NULL
+ ,version TEXT NOT NULL
+ ,action TEXT NOT NULL
+ ,partitioned BOOL NOT NULL
+ ,by_range BOOL NOT NULL
+ ,finished BOOL NOT NULL DEFAULT(FALSE));
+COMMENT ON TABLE auditor_tables
+ IS 'Tables of the auditor and their status';
+COMMENT ON COLUMN auditor_tables.name
+ IS 'Base name of the table (without partition/shard)';
+COMMENT ON COLUMN auditor_tables.version
+ IS 'Version of the DB in which the given action happened';
+COMMENT ON COLUMN auditor_tables.action
+ IS 'Action to take on the table (e.g. create, constrain, or foreign). Create is done for the master table and each partition; constrain is only for partitions or for master if there are no partitions; master only on master (takes no argument); foreign only on master if there are no partitions.';
+COMMENT ON COLUMN auditor_tables.partitioned
+ IS 'TRUE if the table is partitioned';
+COMMENT ON COLUMN auditor_tables.by_range
+ IS 'TRUE if the table is partitioned by range';
+COMMENT ON COLUMN auditor_tables.finished
+ IS 'TRUE if the respective migration has been run';
+
+
+CREATE FUNCTION create_partitioned_table(
+ IN table_definition TEXT -- SQL template for table creation
+ ,IN table_name TEXT -- base name of the table
+ ,IN main_table_partition_str TEXT -- declaration for how to partition the table
+ ,IN partition_suffix TEXT DEFAULT NULL -- NULL: no partitioning, 0: yes partitioning, no sharding, >0: sharding
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF (partition_suffix IS NULL)
+ THEN
+ -- no partitioning, disable option
+ main_table_partition_str = '';
+ ELSE
+ IF (partition_suffix::int > 0)
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ END IF;
+ EXECUTE FORMAT(
+ table_definition,
+ table_name,
+ main_table_partition_str
);
-COMMENT ON TABLE auditor_exchanges
- IS 'list of the exchanges we are auditing';
-
-
-CREATE TABLE IF NOT EXISTS auditor_exchange_signkeys
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,ep_start INT8 NOT NULL
- ,ep_expire INT8 NOT NULL
- ,ep_end INT8 NOT NULL
- ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+END $$;
+
+COMMENT ON FUNCTION create_partitioned_table
+ IS 'Generic function to create a table that is partitioned or sharded.';
+
+
+CREATE FUNCTION comment_partitioned_table(
+ IN table_comment TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON TABLE %s IS %s'
+ ,table_name
+ ,quote_literal(table_comment)
);
-COMMENT ON TABLE auditor_exchange_signkeys
- IS 'list of the online signing keys of exchanges we are auditing';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_reserve
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_reserve_in_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_out_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_recoup_serial_id INT8 NOT NULL DEFAULT 0
- ,last_reserve_close_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_merges_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_deposits_serial_id INT8 NOT NULL DEFAULT 0
- ,last_account_merges_serial_id INT8 NOT NULL DEFAULT 0
- ,last_history_requests_serial_id INT8 NOT NULL DEFAULT 0
- ,last_close_requests_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_reserve
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_aggregation
- (master_pub BYTEA CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_wire_out_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_aggregation
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_deposit_confirmation
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_deposit_confirmation_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_deposit_confirmation
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS auditor_progress_coin
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_withdraw_serial_id INT8 NOT NULL DEFAULT 0
- ,last_deposit_serial_id INT8 NOT NULL DEFAULT 0
- ,last_melt_serial_id INT8 NOT NULL DEFAULT 0
- ,last_refund_serial_id INT8 NOT NULL DEFAULT 0
- ,last_recoup_serial_id INT8 NOT NULL DEFAULT 0
- ,last_recoup_refresh_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_deposits_serial_id INT8 NOT NULL DEFAULT 0
- ,last_purse_refunds_serial_id INT8 NOT NULL DEFAULT 0
- ,PRIMARY KEY (master_pub)
- );
-COMMENT ON TABLE auditor_progress_coin
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS wire_auditor_account_progress
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,account_name TEXT NOT NULL
- ,last_wire_reserve_in_serial_id INT8 NOT NULL DEFAULT 0
- ,last_wire_wire_out_serial_id INT8 NOT NULL DEFAULT 0
- ,wire_in_off INT8 NOT NULL
- ,wire_out_off INT8 NOT NULL
- ,PRIMARY KEY (master_pub,account_name)
- );
-COMMENT ON TABLE wire_auditor_account_progress
- IS 'information as to which transactions the auditor has processed in the exchange database. Used for SELECTing the
- statements to process. The indices include the last serial ID from the respective tables that we have processed. Thus, we need to select those table entries that are strictly larger (and process in monotonically increasing order).';
-
-
-CREATE TABLE IF NOT EXISTS wire_auditor_progress
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,last_timestamp INT8 NOT NULL
- ,last_reserve_close_uuid INT8 NOT NULL
- ,PRIMARY KEY (master_pub)
- );
-
-
-CREATE TABLE IF NOT EXISTS auditor_reserves
- (reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)
- ,master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,reserve_balance_val INT8 NOT NULL
- ,reserve_balance_frac INT4 NOT NULL
- ,withdraw_fee_balance_val INT8 NOT NULL
- ,withdraw_fee_balance_frac INT4 NOT NULL
- ,expiration_date INT8 NOT NULL
- ,auditor_reserves_rowid BIGSERIAL UNIQUE
- ,origin_account TEXT
- );
-COMMENT ON TABLE auditor_reserves
- IS 'all of the customer reserves and their respective balances that the auditor is aware of';
-
-CREATE INDEX IF NOT EXISTS auditor_reserves_by_reserve_pub
- ON auditor_reserves
- (reserve_pub);
-
-
-CREATE TABLE IF NOT EXISTS auditor_reserve_balance
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,reserve_balance_val INT8 NOT NULL
- ,reserve_balance_frac INT4 NOT NULL
- ,withdraw_fee_balance_val INT8 NOT NULL
- ,withdraw_fee_balance_frac INT4 NOT NULL
- ,purse_fee_balance_val INT8 NOT NULL
- ,purse_fee_balance_frac INT4 NOT NULL
- ,history_fee_balance_val INT8 NOT NULL
- ,history_fee_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_reserve_balance
- IS 'sum of the balances of all customer reserves (by exchange master public key)';
-
-
-CREATE TABLE IF NOT EXISTS auditor_wire_fee_balance
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,wire_fee_balance_val INT8 NOT NULL
- ,wire_fee_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_wire_fee_balance
- IS 'sum of the balances of all wire fees (by exchange master public key)';
-
-
-CREATE TABLE IF NOT EXISTS auditor_denomination_pending
- (denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
- ,denom_balance_val INT8 NOT NULL
- ,denom_balance_frac INT4 NOT NULL
- ,denom_loss_val INT8 NOT NULL
- ,denom_loss_frac INT4 NOT NULL
- ,num_issued INT8 NOT NULL
- ,denom_risk_val INT8 NOT NULL
- ,denom_risk_frac INT4 NOT NULL
- ,recoup_loss_val INT8 NOT NULL
- ,recoup_loss_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_denomination_pending
- IS 'outstanding denomination coins that the exchange is aware of and what the respective balances are (outstanding as well as issued overall which implies the maximum value at risk).';
-COMMENT ON COLUMN auditor_denomination_pending.num_issued
- IS 'counts the number of coins issued (withdraw, refresh) of this denomination';
-COMMENT ON COLUMN auditor_denomination_pending.denom_risk_val
- IS 'amount that could theoretically be lost in the future due to recoup operations';
-COMMENT ON COLUMN auditor_denomination_pending.recoup_loss_val
- IS 'amount actually lost due to recoup operations past revocation';
-
-
-CREATE TABLE IF NOT EXISTS auditor_balance_summary
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,denom_balance_val INT8 NOT NULL
- ,denom_balance_frac INT4 NOT NULL
- ,deposit_fee_balance_val INT8 NOT NULL
- ,deposit_fee_balance_frac INT4 NOT NULL
- ,melt_fee_balance_val INT8 NOT NULL
- ,melt_fee_balance_frac INT4 NOT NULL
- ,refund_fee_balance_val INT8 NOT NULL
- ,refund_fee_balance_frac INT4 NOT NULL
- ,risk_val INT8 NOT NULL
- ,risk_frac INT4 NOT NULL
- ,loss_val INT8 NOT NULL
- ,loss_frac INT4 NOT NULL
- ,irregular_recoup_val INT8 NOT NULL
- ,irregular_recoup_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_balance_summary
- IS 'the sum of the outstanding coins from auditor_denomination_pending (denom_pubs must belong to the respectives exchange master public key); it represents the auditor_balance_summary of the exchange at this point (modulo unexpected historic_loss-style events where denomination keys are compromised)';
-
-
-CREATE TABLE IF NOT EXISTS auditor_historic_denomination_revenue
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
- ,revenue_timestamp INT8 NOT NULL
- ,revenue_balance_val INT8 NOT NULL
- ,revenue_balance_frac INT4 NOT NULL
- ,loss_balance_val INT8 NOT NULL
- ,loss_balance_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_historic_denomination_revenue
- IS 'Table with historic profits; basically, when a denom_pub has expired and everything associated with it is garbage collected, the final profits end up in here; note that the denom_pub here is not a foreign key, we just keep it as a reference point.';
-COMMENT ON COLUMN auditor_historic_denomination_revenue.revenue_balance_val
- IS 'the sum of all of the profits we made on the coin except for withdraw fees (which are in historic_reserve_revenue); so this includes the deposit, melt and refund fees';
-
-
-CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,start_date INT8 NOT NULL
- ,end_date INT8 NOT NULL
- ,reserve_profits_val INT8 NOT NULL
- ,reserve_profits_frac INT4 NOT NULL
- );
-COMMENT ON TABLE auditor_historic_reserve_summary
- IS 'historic profits from reserves; we eventually GC auditor_historic_reserve_revenue, and then store the totals in here (by time intervals).';
-
-CREATE INDEX IF NOT EXISTS auditor_historic_reserve_summary_by_master_pub_start_date
- ON auditor_historic_reserve_summary
- (master_pub
- ,start_date);
-
-
-CREATE TABLE IF NOT EXISTS deposit_confirmations
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,serial_id BIGSERIAL NOT NULL UNIQUE
- ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
- ,h_extensions BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
- ,h_wire BYTEA NOT NULL CHECK (LENGTH(h_wire)=64)
- ,exchange_timestamp INT8 NOT NULL
- ,refund_deadline INT8 NOT NULL
- ,wire_deadline INT8 NOT NULL
- ,amount_without_fee_val INT8 NOT NULL
- ,amount_without_fee_frac INT4 NOT NULL
- ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
- ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
- ,exchange_sig BYTEA NOT NULL CHECK (LENGTH(exchange_sig)=64)
- ,exchange_pub BYTEA NOT NULL CHECK (LENGTH(exchange_pub)=32)
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,PRIMARY KEY (h_contract_terms,h_wire,coin_pub,merchant_pub,exchange_sig,exchange_pub,master_sig)
- );
-COMMENT ON TABLE deposit_confirmations
- IS 'deposit confirmation sent to us by merchants; we must check that the exchange reported these properly.';
-
-
-CREATE TABLE IF NOT EXISTS auditor_predicted_result
- (master_pub BYTEA NOT NULL CONSTRAINT master_pub_ref REFERENCES auditor_exchanges(master_pub) ON DELETE CASCADE
- ,balance_val INT8 NOT NULL
- ,balance_frac INT4 NOT NULL
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_table
+ IS 'Generic function to create a comment on table that is partitioned.';
+
+
+CREATE FUNCTION comment_partitioned_column(
+ IN table_comment TEXT
+ ,IN column_name TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON COLUMN %s.%s IS %s'
+ ,table_name
+ ,column_name
+ ,quote_literal(table_comment)
);
-COMMENT ON TABLE auditor_predicted_result
- IS 'Table with the sum of the ledger, auditor_historic_revenue and the auditor_reserve_balance. This is the final amount that the exchange should have in its bank account right now.';
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_column
+ IS 'Generic function to create a comment on column of a table that is partitioned.';
+
+
+---------------------------------------------------------------------------
+-- Main DB setup loop
+---------------------------------------------------------------------------
+
+CREATE FUNCTION do_create_tables(
+ num_partitions INTEGER
+-- NULL: no partitions, add foreign constraints
+-- 0: no partitions, no foreign constraints
+-- 1: only 1 default partition
+-- > 1: normal partitions
+)
+ RETURNS VOID
+ LANGUAGE plpgsql
+AS $$
+DECLARE
+ tc CURSOR FOR
+ SELECT table_serial_id
+ ,name
+ ,action
+ ,partitioned
+ ,by_range
+ FROM auditor.auditor_tables
+ WHERE NOT finished
+ ORDER BY table_serial_id ASC;
+BEGIN
+ FOR rec IN tc
+ LOOP
+ CASE rec.action
+ -- "create" actions apply to master and partitions
+ WHEN 'create'
+ THEN
+ IF (rec.partitioned AND
+ (num_partitions IS NOT NULL))
+ THEN
+ -- Create master table with partitioning.
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('0')
+ );
+ IF (rec.by_range OR
+ (num_partitions = 0))
+ THEN
+ -- Create default partition.
+ IF (rec.by_range)
+ THEN
+ -- Range partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%s_default'
+ ' PARTITION OF %s'
+ ' DEFAULT'
+ ,rec.name
+ ,rec.name
+ );
+ ELSE
+ -- Hash partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%s_default'
+ ' PARTITION OF %s'
+ ' FOR VALUES WITH (MODULUS 1, REMAINDER 0)'
+ ,rec.name
+ ,rec.name
+ );
+ END IF;
+ ELSE
+ FOR i IN 1..num_partitions LOOP
+ -- Create num_partitions
+ EXECUTE FORMAT(
+ 'CREATE TABLE auditor.%I'
+ ' PARTITION OF %I'
+ ' FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
+ ,rec.name || '_' || i
+ ,rec.name
+ ,num_partitions
+ ,i-1
+ );
+ END LOOP;
+ END IF;
+ ELSE
+ -- Only create master table. No partitions.
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ END IF;
+ -- Constrain action apply to master OR each partition
+ WHEN 'constrain'
+ THEN
+ ASSERT rec.partitioned, 'constrain action only applies to partitioned tables';
+ IF (num_partitions IS NULL)
+ THEN
+ -- Constrain master table
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (NULL)'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ IF ( (num_partitions = 0) OR
+ (rec.by_range) )
+ THEN
+ -- Constrain default table
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('default')
+ );
+ ELSE
+ -- Constrain each partition
+ FOR i IN 1..num_partitions LOOP
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal(i)
+ );
+ END LOOP;
+ END IF;
+ END IF;
+ -- Foreign actions only apply if partitioning is off
+ WHEN 'foreign'
+ THEN
+ IF (num_partitions IS NULL)
+ THEN
+ -- Add foreign constraints
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,NULL
+ );
+ END IF;
+ WHEN 'master'
+ THEN
+ EXECUTE FORMAT(
+ 'SELECT auditor.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ ASSERT FALSE, 'unsupported action type: ' || rec.action;
+ END CASE; -- END CASE (rec.action)
+ -- Mark as finished
+ UPDATE auditor.auditor_tables
+ SET finished=TRUE
+ WHERE table_serial_id=rec.table_serial_id;
+ END LOOP; -- create/alter/drop actions
+END $$;
+
+COMMENT ON FUNCTION do_create_tables
+ IS 'Creates all tables for the given number of partitions that need creating. Does NOT support sharding.';
--- Finally, commit everything
COMMIT;
diff --git a/src/auditordb/auditor-0002.sql.in b/src/auditordb/auditor-0002.sql.in
new file mode 100644
index 000000000..ad459b472
--- /dev/null
+++ b/src/auditordb/auditor-0002.sql.in
@@ -0,0 +1,46 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('auditor-0002', NULL, NULL);
+
+SET search_path TO auditor;
+
+DO $$ BEGIN
+ CREATE TYPE taler_amount
+ AS
+ (val INT8
+ ,frac INT4
+ );
+ COMMENT ON TYPE taler_amount
+ IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
+EXCEPTION
+ WHEN duplicate_object THEN null;
+END $$;
+
+#include "0002-auditor_amount_arithmetic_inconsistency.sql"
+#include "0002-auditor_balances.sql"
+#include "0002-auditor_denomination_pending.sql"
+#include "0002-auditor_exchange_signkeys.sql"
+#include "0002-auditor_historic_denomination_revenue.sql"
+#include "0002-auditor_historic_reserve_summary.sql"
+#include "0002-auditor_progress.sql"
+#include "0002-auditor_purses.sql"
+#include "0002-auditor_reserves.sql"
+#include "0002-auditor_deposit_confirmations.sql"
+
+COMMIT;
diff --git a/src/auditordb/auditor_do_get_auditor_progress.sql b/src/auditordb/auditor_do_get_auditor_progress.sql
new file mode 100644
index 000000000..9371cf67b
--- /dev/null
+++ b/src/auditordb/auditor_do_get_auditor_progress.sql
@@ -0,0 +1,38 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author Christian Grothoff
+
+CREATE OR REPLACE FUNCTION auditor_do_get_auditor_progress(
+ IN in_keys TEXT[])
+RETURNS INT8
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_key TEXT;
+ my_off INT8;
+BEGIN
+ FOREACH my_key IN ARRAY in_keys
+ LOOP
+ SELECT progress_offset
+ INTO my_off
+ FROM auditor_progress
+ WHERE progress_key=my_key;
+ RETURN my_off;
+ END LOOP;
+END $$;
+
+COMMENT ON FUNCTION auditor_do_get_auditor_progress(TEXT[])
+ IS 'Finds all progress offsets associated with the array of keys given as the argument and returns them in order';
diff --git a/src/auditordb/auditor_do_get_balance.sql b/src/auditordb/auditor_do_get_balance.sql
new file mode 100644
index 000000000..782a31f89
--- /dev/null
+++ b/src/auditordb/auditor_do_get_balance.sql
@@ -0,0 +1,47 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author Christian Grothoff
+
+CREATE OR REPLACE FUNCTION auditor_do_get_balance(
+ IN in_keys TEXT[])
+RETURNS taler_amount
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_key TEXT;
+ my_rec RECORD;
+ my_val taler_amount;
+BEGIN
+ FOREACH my_key IN ARRAY in_keys
+ LOOP
+ SELECT (ab.balance_value).val
+ ,(ab.balance_value).frac
+ INTO my_rec
+ FROM auditor_balances ab
+ WHERE balance_key=my_key;
+ IF FOUND
+ THEN
+ my_val.val = my_rec.val;
+ my_val.frac = my_rec.frac;
+ RETURN my_val;
+ ELSE
+ RETURN NULL;
+ END IF;
+ END LOOP;
+END $$;
+
+COMMENT ON FUNCTION auditor_do_get_balance(TEXT[])
+ IS 'Finds all balances associated with the array of keys given as the argument and returns them in order';
diff --git a/src/auditordb/drop.sql b/src/auditordb/drop.sql
new file mode 100644
index 000000000..4bae66103
--- /dev/null
+++ b/src/auditordb/drop.sql
@@ -0,0 +1,31 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2020 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- Everything in one big transaction
+BEGIN;
+
+WITH xpatches AS (
+ SELECT patch_name
+ FROM _v.patches
+ WHERE starts_with(patch_name,'auditor-')
+)
+ SELECT _v.unregister_patch(xpatches.patch_name)
+ FROM xpatches;
+
+DROP SCHEMA auditor CASCADE;
+
+-- And we're out of here...
+COMMIT;
diff --git a/src/auditordb/drop0001.sql b/src/auditordb/drop0001.sql
deleted file mode 100644
index 8e42c8094..000000000
--- a/src/auditordb/drop0001.sql
+++ /dev/null
@@ -1,50 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2020 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- This script DROPs all of the tables we create, including the
--- versioning schema!
---
--- Unlike the other SQL files, it SHOULD be updated to reflect the
--- latest requirements for dropping tables.
-
--- Drops for 0001.sql
-DROP TABLE IF EXISTS auditor_predicted_result;
-DROP TABLE IF EXISTS auditor_historic_denomination_revenue;
-DROP TABLE IF EXISTS auditor_balance_summary;
-DROP TABLE IF EXISTS auditor_denomination_pending;
-DROP TABLE IF EXISTS auditor_reserve_balance;
-DROP TABLE IF EXISTS auditor_wire_fee_balance;
-DROP TABLE IF EXISTS auditor_reserves;
-DROP TABLE IF EXISTS auditor_progress_reserve;
-DROP TABLE IF EXISTS auditor_progress_aggregation;
-DROP TABLE IF EXISTS auditor_progress_deposit_confirmation;
-DROP TABLE IF EXISTS auditor_progress_coin;
-DROP TABLE IF EXISTS auditor_exchange_signkeys;
-DROP TABLE IF EXISTS wire_auditor_progress;
-DROP TABLE IF EXISTS wire_auditor_account_progress;
-DROP TABLE IF EXISTS auditor_historic_reserve_summary CASCADE;
-DROP TABLE IF EXISTS auditor_denominations CASCADE;
-DROP TABLE IF EXISTS deposit_confirmations CASCADE;
-DROP TABLE IF EXISTS auditor_exchanges CASCADE;
-
--- Drop versioning (auditor-0001.sql)
-SELECT _v.unregister_patch('auditor-0001');
-
--- And we're out of here...
-COMMIT;
diff --git a/src/auditordb/hdr.h b/src/auditordb/hdr.h
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/auditordb/hdr.h
diff --git a/src/auditordb/pg_del_denomination_balance.c b/src/auditordb/pg_del_denomination_balance.c
new file mode 100644
index 000000000..154dc50bb
--- /dev/null
+++ b/src/auditordb/pg_del_denomination_balance.c
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_del_denomination_balance.c
+ * @brief Implementation of the del_denomination_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_del_denomination_balance.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_del_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_del_denomination_balance",
+ "DELETE"
+ " FROM auditor_denomination_pending"
+ " WHERE denom_pub_hash=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_del_denomination_balance",
+ params);
+}
diff --git a/src/auditordb/pg_del_denomination_balance.h b/src/auditordb/pg_del_denomination_balance.h
new file mode 100644
index 000000000..56e9232b0
--- /dev/null
+++ b/src/auditordb/pg_del_denomination_balance.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_del_denomination_balance.h
+ * @brief implementation of the del_denomination_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DEL_DENOMINATION_BALANCE_H
+#define PG_DEL_DENOMINATION_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Delete information about a denomination key's balances.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the denomination public key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_del_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash);
+
+#endif
diff --git a/src/auditordb/pg_del_reserve_info.c b/src/auditordb/pg_del_reserve_info.c
new file mode 100644
index 000000000..619bd0afa
--- /dev/null
+++ b/src/auditordb/pg_del_reserve_info.c
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_del_reserve_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_del_reserve_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_del_reserve_info (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_del_reserve_info",
+ "DELETE"
+ " FROM auditor_reserves"
+ " WHERE reserve_pub=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_del_reserve_info",
+ params);
+}
diff --git a/src/auditordb/pg_del_reserve_info.h b/src/auditordb/pg_del_reserve_info.h
new file mode 100644
index 000000000..88a10bcfd
--- /dev/null
+++ b/src/auditordb/pg_del_reserve_info.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_del_reserve_info.h
+ * @brief implementation of the del_reserve_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_DEL_RESERVE_INFO_H
+#define PG_DEL_RESERVE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Delete information about a reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_del_reserve_info (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
+
+
+#endif
diff --git a/src/auditordb/pg_delete_deposit_confirmations.c b/src/auditordb/pg_delete_deposit_confirmations.c
new file mode 100644
index 000000000..6cb76d4e9
--- /dev/null
+++ b/src/auditordb/pg_delete_deposit_confirmations.c
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_deposit_confirmations.c
+ * @brief Implementation of the delete_deposit_confirmations function for Postgres
+ * @author Nicola Eigel
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_deposit_confirmations.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_deposit_confirmation (
+ void *cls,
+ uint64_t row_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&row_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_delete_deposit_confirmation",
+ "DELETE"
+ " FROM deposit_confirmations"
+ " WHERE deposit_confirmation_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_delete_deposit_confirmation",
+ params);
+}
diff --git a/src/auditordb/pg_delete_deposit_confirmations.h b/src/auditordb/pg_delete_deposit_confirmations.h
new file mode 100644
index 000000000..5f7700ba1
--- /dev/null
+++ b/src/auditordb/pg_delete_deposit_confirmations.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_deposit_confirmations.h
+ * @brief implementation of the delete_deposit_confirmation function for Postgres
+ * @author Nicola Eigel
+ */
+#ifndef PG_DELETE_DEPOSIT_CONFIRMATIONS_H
+#define PG_DELETE_DEPOSIT_CONFIRMATIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Delete a row from the deposit confirmations table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param row_id row to delete
+ * @return query transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_deposit_confirmation (
+ void *cls,
+ uint64_t row_id);
+
+
+#endif
diff --git a/src/auditordb/pg_delete_pending_deposit.c b/src/auditordb/pg_delete_pending_deposit.c
new file mode 100644
index 000000000..29814e84b
--- /dev/null
+++ b/src/auditordb/pg_delete_pending_deposit.c
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_pending_deposit.c
+ * @brief Implementation of the delete_pending_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_pending_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_pending_deposit (
+ void *cls,
+ uint64_t batch_deposit_serial_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&batch_deposit_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_delete_pending_deposit",
+ "DELETE"
+ " FROM auditor_pending_deposits"
+ " WHERE batch_deposit_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_delete_pending_deposit",
+ params);
+}
diff --git a/src/auditordb/pg_delete_pending_deposit.h b/src/auditordb/pg_delete_pending_deposit.h
new file mode 100644
index 000000000..8e7159eac
--- /dev/null
+++ b/src/auditordb/pg_delete_pending_deposit.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_pending_deposit.h
+ * @brief implementation of the delete_pending_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DELETE_PENDING_DEPOSIT_H
+#define PG_DELETE_PENDING_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Delete a row from the pending deposit table.
+ * Usually done when the respective wire transfer
+ * was finally detected.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param batch_deposit_serial_id which entry to delete
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_pending_deposit (
+ void *cls,
+ uint64_t batch_deposit_serial_id);
+
+
+#endif
diff --git a/src/auditordb/pg_delete_purse_info.c b/src/auditordb/pg_delete_purse_info.c
new file mode 100644
index 000000000..8fa77ba46
--- /dev/null
+++ b/src/auditordb/pg_delete_purse_info.c
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_purse_info.c
+ * @brief Implementation of the delete_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_purse_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_purses_delete",
+ "DELETE FROM auditor_purses "
+ " WHERE purse_pub=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_purses_delete",
+ params);
+}
diff --git a/src/auditordb/pg_delete_purse_info.h b/src/auditordb/pg_delete_purse_info.h
new file mode 100644
index 000000000..88393f9b8
--- /dev/null
+++ b/src/auditordb/pg_delete_purse_info.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_delete_purse_info.h
+ * @brief implementation of the delete_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DELETE_PURSE_INFO_H
+#define PG_DELETE_PURSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Delete information about a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the reserve
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_delete_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub);
+
+
+#endif
diff --git a/src/auditordb/pg_get_auditor_progress.c b/src/auditordb/pg_get_auditor_progress.c
new file mode 100644
index 000000000..3742d2eb6
--- /dev/null
+++ b/src/auditordb/pg_get_auditor_progress.c
@@ -0,0 +1,178 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_auditor_progress.c
+ * @brief Implementation of get_auditor_progress function
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_auditor_progress.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #auditor_progress_cb().
+ */
+struct AuditorProgressContext
+{
+
+ /**
+ * Where to store results.
+ */
+ uint64_t **dst;
+
+ /**
+ * Offset in @e dst.
+ */
+ unsigned int off;
+
+ /**
+ * Length of array at @e dst.
+ */
+ unsigned int len;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to true on failure.
+ */
+ bool failure;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_auditor_progress().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AuditorProgressContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+auditor_progress_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AuditorProgressContext *ctx = cls;
+
+ GNUNET_assert (num_results <= ctx->len);
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ bool is_missing = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("progress_offset",
+ ctx->dst[i]),
+ &is_missing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->failure = true;
+ return;
+ }
+ if (is_missing)
+ *ctx->dst[i] = 0;
+ ctx->off++;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_auditor_progress (void *cls,
+ const char *progress_key,
+ uint64_t *progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t *dsts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct AuditorProgressContext ctx = {
+ .dst = dsts,
+ .len = cnt,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ dsts[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ dsts[off] = va_arg (ap,
+ uint64_t *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "get_auditor_progress",
+ "SELECT"
+ " auditor_do_get_auditor_progress AS progress_offset"
+ " FROM auditor_do_get_auditor_progress "
+ "($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_auditor_progress",
+ params,
+ &auditor_progress_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if (ctx.failure)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ if (qs < 0)
+ return qs;
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_get_auditor_progress.h b/src/auditordb/pg_get_auditor_progress.h
new file mode 100644
index 000000000..fee7a4424
--- /dev/null
+++ b/src/auditordb/pg_get_auditor_progress.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_auditor_progress.h
+ * @brief implementation of the get_auditor_progress function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_AUDITOR_PROGRESS_H
+#define PG_GET_AUDITOR_PROGRESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about the progress of the auditor.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param progress_key name of the progress indicator
+ * @param[out] progress_offset set to offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to fetch
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_auditor_progress (void *cls,
+ const char *progress_key,
+ uint64_t *progress_offset,
+ ...);
+
+#endif
diff --git a/src/auditordb/pg_get_balance.c b/src/auditordb/pg_get_balance.c
new file mode 100644
index 000000000..4edc1c89f
--- /dev/null
+++ b/src/auditordb/pg_get_balance.c
@@ -0,0 +1,183 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_get_balance.c
+ * @brief Implementation of the get_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_balance.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #balance_cb().
+ */
+struct BalanceContext
+{
+
+ /**
+ * Where to store results.
+ */
+ struct TALER_Amount **dst;
+
+ /**
+ * Offset in @e dst.
+ */
+ unsigned int off;
+
+ /**
+ * Length of array at @e dst.
+ */
+ unsigned int len;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to true on failure.
+ */
+ bool failure;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_balance().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct BalanceContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+balance_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct BalanceContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ GNUNET_assert (num_results <= ctx->len);
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ bool is_missing = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_amount ("balance",
+ pg->currency,
+ ctx->dst[i]),
+ &is_missing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->failure = true;
+ return;
+ }
+ if (is_missing)
+ memset (ctx->dst[i],
+ 0,
+ sizeof (struct TALER_Amount));
+ ctx->off++;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_balance (void *cls,
+ const char *balance_key,
+ struct TALER_Amount *balance_value,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_value);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount *dsts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct BalanceContext ctx = {
+ .dst = dsts,
+ .len = cnt,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ dsts[0] = balance_value;
+
+ va_start (ap,
+ balance_value);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ dsts[off] = va_arg (ap,
+ struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "get_balance",
+ "SELECT "
+ " auditor_do_get_balance AS balance"
+ " FROM auditor_do_get_balance "
+ "($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_balance",
+ params,
+ &balance_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if (ctx.failure)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ if (qs < 0)
+ return qs;
+ GNUNET_assert (qs == ctx.off);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_get_balance.h b/src/auditordb/pg_get_balance.h
new file mode 100644
index 000000000..59d2af0ae
--- /dev/null
+++ b/src/auditordb/pg_get_balance.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_get_balance.h
+ * @brief implementation of the get_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_BALANCE_H
+#define PG_GET_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get summary information about balance tracked by the auditor.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param balance_key key of the balance to store
+ * @param[out] balance_value set to amount stored under @a balance_key
+ * @param ... NULL terminated list of additional key-value pairs to fetch
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_balance (void *cls,
+ const char *balance_key,
+ struct TALER_Amount *balance_value,
+ ...);
+
+#endif
diff --git a/src/auditordb/pg_get_denomination_balance.c b/src/auditordb/pg_get_denomination_balance.c
new file mode 100644
index 000000000..40af766cd
--- /dev/null
+++ b/src/auditordb/pg_get_denomination_balance.c
@@ -0,0 +1,68 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_denomination_balance.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_denomination_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_AUDITORDB_DenominationCirculationData *dcd)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance",
+ &dcd->denom_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss",
+ &dcd->denom_loss),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk",
+ &dcd->denom_risk),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss",
+ &dcd->recoup_loss),
+ GNUNET_PQ_result_spec_uint64 ("num_issued",
+ &dcd->num_issued),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "auditor_denomination_pending_select",
+ "SELECT"
+ " denom_balance"
+ ",denom_loss"
+ ",num_issued"
+ ",denom_risk"
+ ",recoup_loss"
+ " FROM auditor_denomination_pending"
+ " WHERE denom_pub_hash=$1");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "auditor_denomination_pending_select",
+ params,
+ rs);
+}
diff --git a/src/auditordb/pg_get_denomination_balance.h b/src/auditordb/pg_get_denomination_balance.h
new file mode 100644
index 000000000..31f377066
--- /dev/null
+++ b/src/auditordb/pg_get_denomination_balance.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_denomination_balance.h
+ * @brief implementation of the get_denomination_balance function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_DENOMINATION_BALANCE_H
+#define PG_GET_DENOMINATION_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about a denomination key's balances.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the denomination public key
+ * @param[out] dcd circulation data to initialize
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_AUDITORDB_DenominationCirculationData *dcd);
+
+#endif
diff --git a/src/auditordb/pg_get_deposit_confirmations.c b/src/auditordb/pg_get_deposit_confirmations.c
new file mode 100644
index 000000000..b8055a296
--- /dev/null
+++ b/src/auditordb/pg_get_deposit_confirmations.c
@@ -0,0 +1,199 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_deposit_confirmations.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_deposit_confirmations.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #deposit_confirmation_cb().
+ */
+struct DepositConfirmationContext
+{
+
+ /**
+ * Function to call for each deposit confirmation.
+ */
+ TALER_AUDITORDB_DepositConfirmationCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_get_deposit_confirmations().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositConfirmationContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+deposit_confirmation_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DepositConfirmationContext *dcc = cls;
+ struct PostgresClosure *pg = dcc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t serial_id;
+ struct TALER_AUDITORDB_DepositConfirmation dc = { 0};
+ struct TALER_CoinSpendPublicKeyP *coin_pubs = NULL;
+ struct TALER_CoinSpendSignatureP *coin_sigs = NULL;
+ size_t num_pubs = 0;
+ size_t num_sigs = 0;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &dc.h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("h_policy",
+ &dc.h_policy),
+ GNUNET_PQ_result_spec_auto_from_type ("h_wire",
+ &dc.h_wire),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ &dc.exchange_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &dc.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &dc.wire_deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_without_fee",
+ &dc.total_without_fee),
+ GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
+ "coin_pubs",
+ &num_pubs,
+ coin_pubs),
+ GNUNET_PQ_result_spec_auto_array_from_type (pg->conn,
+ "coin_sigs",
+ &num_sigs,
+ coin_sigs),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &dc.merchant),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_sig",
+ &dc.exchange_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ &dc.exchange_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &dc.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue rval;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if (num_sigs != num_pubs)
+ {
+ GNUNET_break (0);
+ dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_PQ_cleanup_result (rs);
+ return;
+ }
+ dcc->qs = i + 1;
+ dc.coin_pubs = coin_pubs;
+ dc.coin_sigs = coin_sigs;
+ dc.num_coins = num_sigs;
+ rval = dcc->cb (dcc->cb_cls,
+ serial_id,
+ &dc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != rval)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_deposit_confirmations (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_DepositConfirmationCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&start_id),
+ GNUNET_PQ_query_param_bool (return_suppressed),
+ GNUNET_PQ_query_param_end
+ };
+ struct DepositConfirmationContext dcc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "auditor_deposit_confirmation_select",
+ "SELECT"
+ " deposit_confirmation_serial_id"
+ ",h_contract_terms"
+ ",h_policy"
+ ",h_wire"
+ ",exchange_timestamp"
+ ",wire_deadline"
+ ",refund_deadline"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
+ ",merchant_pub"
+ ",exchange_sig"
+ ",exchange_pub"
+ ",master_sig"
+ " FROM auditor_deposit_confirmations"
+ " WHERE deposit_confirmation_serial_id>$1"
+ " AND ($2 OR NOT suppressed);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_deposit_confirmation_select",
+ params,
+ &deposit_confirmation_cb,
+ &dcc);
+ if (qs > 0)
+ return dcc.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/pg_get_deposit_confirmations.h b/src/auditordb/pg_get_deposit_confirmations.h
new file mode 100644
index 000000000..6b33e9e6f
--- /dev/null
+++ b/src/auditordb/pg_get_deposit_confirmations.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_deposit_confirmations.h
+ * @brief implementation of the get_deposit_confirmations function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_DEPOSIT_CONFIRMATIONS_H
+#define PG_GET_DEPOSIT_CONFIRMATIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about deposit confirmations from the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_id row/serial ID where to start the iteration (0 from
+ * the start, exclusive, i.e. serial_ids must start from 1)
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_deposit_confirmations (
+ void *cls,
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_DepositConfirmationCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/auditordb/pg_get_purse_info.c b/src/auditordb/pg_get_purse_info.c
new file mode 100644
index 000000000..6a0faf616
--- /dev/null
+++ b/src/auditordb/pg_get_purse_info.c
@@ -0,0 +1,62 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_get_purse_info.c
+ * @brief Implementation of the get_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_purse_info.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ uint64_t *rowid,
+ struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp *expiration_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ expiration_date),
+ GNUNET_PQ_result_spec_uint64 ("auditor_purses_rowid",
+ rowid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "auditor_get_purse_info",
+ "SELECT"
+ " expiration_date"
+ ",balance"
+ " FROM auditor_purses"
+ " WHERE purse_pub=$1");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "auditor_get_purse_info",
+ params,
+ rs);
+}
diff --git a/src/auditordb/pg_get_purse_info.h b/src/auditordb/pg_get_purse_info.h
new file mode 100644
index 000000000..e8268282e
--- /dev/null
+++ b/src/auditordb/pg_get_purse_info.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_get_purse_info.h
+ * @brief implementation of the get_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_PURSE_INFO_H
+#define PG_GET_PURSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the purse
+ * @param[out] rowid which row did we get the information from
+ * @param[out] balance set to balance of the purse
+ * @param[out] expiration_date expiration date of the purse
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ uint64_t *rowid,
+ struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp *expiration_date);
+
+#endif
diff --git a/src/auditordb/pg_get_reserve_info.c b/src/auditordb/pg_get_reserve_info.c
new file mode 100644
index 000000000..f16c6d995
--- /dev/null
+++ b/src/auditordb/pg_get_reserve_info.c
@@ -0,0 +1,88 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_reserve_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_reserve_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_reserve_info (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *rowid,
+ struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp *expiration_date,
+ char **sender_account)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
+ &rfb->reserve_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_loss",
+ &rfb->reserve_loss),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance",
+ &rfb->withdraw_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("close_fee_balance",
+ &rfb->close_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance",
+ &rfb->purse_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("open_fee_balance",
+ &rfb->open_fee_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee_balance",
+ &rfb->history_fee_balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ expiration_date),
+ GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid",
+ rowid),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("origin_account",
+ sender_account),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *sender_account = NULL;
+ PREPARE (pg,
+ "auditor_get_reserve_info",
+ "SELECT"
+ " reserve_balance"
+ ",reserve_loss"
+ ",withdraw_fee_balance"
+ ",close_fee_balance"
+ ",purse_fee_balance"
+ ",open_fee_balance"
+ ",history_fee_balance"
+ ",expiration_date"
+ ",auditor_reserves_rowid"
+ ",origin_account"
+ " FROM auditor_reserves"
+ " WHERE reserve_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "auditor_get_reserve_info",
+ params,
+ rs);
+}
diff --git a/src/auditordb/pg_get_reserve_info.h b/src/auditordb/pg_get_reserve_info.h
new file mode 100644
index 000000000..3eba035fc
--- /dev/null
+++ b/src/auditordb/pg_get_reserve_info.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_reserve_info.h
+ * @brief implementation of the get_reserve_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_RESERVE_INFO_H
+#define PG_GET_RESERVE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about a reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param[out] rowid which row did we get the information from
+ * @param[out] rfb where to store the reserve balance summary
+ * @param[out] expiration_date expiration date of the reserve
+ * @param[out] sender_account from where did the money in the reserve originally come from
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_reserve_info (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *rowid,
+ struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp *expiration_date,
+ char **sender_account);
+
+
+#endif
diff --git a/src/auditordb/pg_get_wire_fee_summary.c b/src/auditordb/pg_get_wire_fee_summary.c
new file mode 100644
index 000000000..b0eb9ba50
--- /dev/null
+++ b/src/auditordb/pg_get_wire_fee_summary.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_wire_fee_summary.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_wire_fee_summary.h"
+#include "pg_helper.h"
+
+
+/**
+ * Get summary information about an exchanges wire fee balance.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param[out] wire_fee_balance set amount the exchange gained in wire fees
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_wire_fee_summary (void *cls,
+ struct TALER_Amount *wire_fee_balance)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee_balance",
+ wire_fee_balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "auditor_wire_fee_balance_select",
+ "SELECT"
+ " wire_fee_balance"
+ " FROM auditor_wire_fee_balance");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "auditor_wire_fee_balance_select",
+ params,
+ rs);
+}
diff --git a/src/auditordb/pg_get_wire_fee_summary.h b/src/auditordb/pg_get_wire_fee_summary.h
new file mode 100644
index 000000000..4c7f1aebd
--- /dev/null
+++ b/src/auditordb/pg_get_wire_fee_summary.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_wire_fee_summary.h
+ * @brief implementation of the get_wire_fee_summary function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_WIRE_FEE_SUMMARY_H
+#define PG_GET_WIRE_FEE_SUMMARY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get summary information about an exchanges wire fee balance.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param[out] wire_fee_balance set amount the exchange gained in wire fees
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_get_wire_fee_summary (void *cls,
+ struct TALER_Amount *wire_fee_balance);
+
+
+#endif
diff --git a/src/auditordb/pg_helper.h b/src/auditordb/pg_helper.h
new file mode 100644
index 000000000..54ccd5978
--- /dev/null
+++ b/src/auditordb/pg_helper.h
@@ -0,0 +1,119 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_helper.h
+ * @brief shared internal definitions for postgres DB plugin
+ * @author Christian Grothoff
+ */
+#ifndef PG_HELPER_H
+#define PG_HELPER_H
+
+
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Type of the "cls" argument given to each of the functions in
+ * our API.
+ */
+struct PostgresClosure
+{
+
+ /**
+ * Postgres connection handle.
+ */
+ struct GNUNET_PQ_Context *conn;
+
+ /**
+ * Name of the ongoing transaction, used to debug cases where
+ * a transaction is not properly terminated via COMMIT or
+ * ROLLBACK.
+ */
+ const char *transaction_name;
+
+ /**
+ * Our configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * How often have we connected to the DB so far?
+ */
+ unsigned long long prep_gen;
+
+ /**
+ * Which currency should we assume all amounts to be in?
+ */
+ char *currency;
+};
+
+
+/**
+ * Prepares SQL statement @a sql under @a name for
+ * connection @a pg once.
+ * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure.
+ *
+ * @param pg a `struct PostgresClosure`
+ * @param name name to prepare the statement under
+ * @param sql actual SQL text
+ */
+#define PREPARE(pg,name,sql) \
+ do { \
+ static struct { \
+ unsigned long long cnt; \
+ struct PostgresClosure *pg; \
+ } preps[2]; /* 2 ctrs for taler-auditor-sync*/ \
+ unsigned int off = 0; \
+ \
+ while ( (NULL != preps[off].pg) && \
+ (pg != preps[off].pg) && \
+ (off < sizeof(preps) / sizeof(*preps)) ) \
+ off++; \
+ GNUNET_assert (off < \
+ sizeof(preps) / sizeof(*preps)); \
+ if (preps[off].cnt < pg->prep_gen) \
+ { \
+ struct GNUNET_PQ_PreparedStatement ps[] = { \
+ GNUNET_PQ_make_prepare (name, sql), \
+ GNUNET_PQ_PREPARED_STATEMENT_END \
+ }; \
+ \
+ if (GNUNET_OK != \
+ GNUNET_PQ_prepare_statements (pg->conn, \
+ ps)) \
+ { \
+ GNUNET_break (0); \
+ return GNUNET_DB_STATUS_HARD_ERROR; \
+ } \
+ preps[off].pg = pg; \
+ preps[off].cnt = pg->prep_gen; \
+ } \
+ } while (0)
+
+
+/**
+ * Wrapper macro to add the currency from the plugin's state
+ * when fetching amounts from the database.
+ *
+ * @param field name of the database field to fetch amount from
+ * @param[out] amountp pointer to amount to set
+ */
+#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \
+ amountp) TALER_PQ_result_spec_amount ( \
+ field,pg->currency,amountp)
+
+
+#endif
diff --git a/src/auditordb/pg_insert_auditor_progress.c b/src/auditordb/pg_insert_auditor_progress.c
new file mode 100644
index 000000000..3c5d25eef
--- /dev/null
+++ b/src/auditordb/pg_insert_auditor_progress.c
@@ -0,0 +1,97 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_auditor_progress.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_auditor_progress.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t offsets[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (cnt,
+ offsets,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ offsets[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ offsets[off] = va_arg (ap,
+ uint64_t);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_progress_insert",
+ "INSERT INTO auditor_progress "
+ "(progress_key"
+ ",progress_offset"
+ ") SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS INT8[]))"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_progress_insert",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_insert_auditor_progress.h b/src/auditordb/pg_insert_auditor_progress.h
new file mode 100644
index 000000000..a20e376c8
--- /dev/null
+++ b/src/auditordb/pg_insert_auditor_progress.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_auditor_progress.h
+ * @brief implementation of the insert_auditor_progress function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_AUDITOR_PROGRESS_H
+#define PG_INSERT_AUDITOR_PROGRESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about the auditor's progress with an exchange's
+ * data.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to insert
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
+
+#endif
diff --git a/src/auditordb/pg_insert_balance.c b/src/auditordb/pg_insert_balance.c
new file mode 100644
index 000000000..0d1762acc
--- /dev/null
+++ b/src/auditordb/pg_insert_balance.c
@@ -0,0 +1,97 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_balance.c
+ * @brief Implementation of the insert_balance function
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_balance (void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_value,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_value);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ const struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount amounts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (cnt,
+ amounts,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ amounts[0] = *balance_value;
+
+ va_start (ap,
+ balance_value);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ amounts[off] = *va_arg (ap,
+ const struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_balance_insert",
+ "INSERT INTO auditor_balances "
+ "(balance_key"
+ ",balance_value.val"
+ ",balance_value.frac"
+ ") SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS taler_amount[]))"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_balance_insert",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_insert_balance.h b/src/auditordb/pg_insert_balance.h
new file mode 100644
index 000000000..dff69eec9
--- /dev/null
+++ b/src/auditordb/pg_insert_balance.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_balance.h
+ * @brief implementation of the insert_balance function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_BALANCE_H
+#define PG_INSERT_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Insert information about a balance tracked by the auditor. There must not be an
+ * existing record.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param balance_key key of the balance to store
+ * @param balance_value value to store
+ * @param ... NULL terminated list of additional key-value pairs to insert
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_balance (void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_value,
+ ...);
+
+
+#endif
diff --git a/src/auditordb/pg_insert_denomination_balance.c b/src/auditordb/pg_insert_denomination_balance.c
new file mode 100644
index 000000000..bbf4127f4
--- /dev/null
+++ b/src/auditordb/pg_insert_denomination_balance.c
@@ -0,0 +1,65 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_denomination_balance.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_denomination_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_loss),
+ GNUNET_PQ_query_param_uint64 (&dcd->num_issued),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_risk),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->recoup_loss),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_denomination_pending_insert",
+ "INSERT INTO auditor_denomination_pending "
+ "(denom_pub_hash"
+ ",denom_balance"
+ ",denom_loss"
+ ",num_issued"
+ ",denom_risk"
+ ",recoup_loss"
+ ") VALUES ("
+ "$1,$2,$3,$4,$5,$6"
+ ");");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_denomination_pending_insert",
+ params);
+}
diff --git a/src/auditordb/pg_insert_denomination_balance.h b/src/auditordb/pg_insert_denomination_balance.h
new file mode 100644
index 000000000..90776367c
--- /dev/null
+++ b/src/auditordb/pg_insert_denomination_balance.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_denomination_balance.h
+ * @brief implementation of the insert_denomination_balance function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_DENOMINATION_BALANCE_H
+#define PG_INSERT_DENOMINATION_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about a denomination key's balances. There
+ * must not be an existing record for the denomination key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the denomination public key
+ * @param dcd circulation data to store
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd);
+
+
+#endif
diff --git a/src/auditordb/pg_insert_deposit_confirmation.c b/src/auditordb/pg_insert_deposit_confirmation.c
new file mode 100644
index 000000000..1b5205782
--- /dev/null
+++ b/src/auditordb/pg_insert_deposit_confirmation.c
@@ -0,0 +1,77 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_deposit_confirmation.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_deposit_confirmation.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_deposit_confirmation (
+ void *cls,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&dc->h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (&dc->h_policy),
+ GNUNET_PQ_query_param_auto_from_type (&dc->h_wire),
+ GNUNET_PQ_query_param_timestamp (&dc->exchange_timestamp),
+ GNUNET_PQ_query_param_timestamp (&dc->wire_deadline),
+ GNUNET_PQ_query_param_timestamp (&dc->refund_deadline),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dc->total_without_fee),
+ GNUNET_PQ_query_param_array_auto_from_type (dc->num_coins,
+ dc->coin_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_auto_from_type (dc->num_coins,
+ dc->coin_sigs,
+ pg->conn),
+ GNUNET_PQ_query_param_auto_from_type (&dc->merchant),
+ GNUNET_PQ_query_param_auto_from_type (&dc->exchange_sig),
+ GNUNET_PQ_query_param_auto_from_type (&dc->exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (&dc->master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_deposit_confirmation_insert",
+ "INSERT INTO deposit_confirmations "
+ "(h_contract_terms"
+ ",h_policy"
+ ",h_wire"
+ ",exchange_timestamp"
+ ",wire_deadline"
+ ",refund_deadline"
+ ",total_without_fee"
+ ",coin_pubs"
+ ",coin_sigs"
+ ",merchant_pub"
+ ",exchange_sig"
+ ",exchange_pub"
+ ",master_sig" /* master_sig could be normalized... */
+ ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_deposit_confirmation_insert",
+ params);
+}
diff --git a/src/auditordb/pg_insert_deposit_confirmation.h b/src/auditordb/pg_insert_deposit_confirmation.h
new file mode 100644
index 000000000..f3d11e3cb
--- /dev/null
+++ b/src/auditordb/pg_insert_deposit_confirmation.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_deposit_confirmation.h
+ * @brief implementation of the insert_deposit_confirmation function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_DEPOSIT_CONFIRMATION_H
+#define PG_INSERT_DEPOSIT_CONFIRMATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about a deposit confirmation into the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param dc deposit confirmation information to store
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_deposit_confirmation (
+ void *cls,
+ const struct TALER_AUDITORDB_DepositConfirmation *dc);
+
+
+#endif
diff --git a/src/auditordb/pg_insert_exchange_signkey.c b/src/auditordb/pg_insert_exchange_signkey.c
new file mode 100644
index 000000000..8bf439da0
--- /dev/null
+++ b/src/auditordb/pg_insert_exchange_signkey.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_exchange_signkey.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_exchange_signkey.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_exchange_signkey (
+ void *cls,
+ const struct TALER_AUDITORDB_ExchangeSigningKey *sk)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&sk->ep_start),
+ GNUNET_PQ_query_param_timestamp (&sk->ep_expire),
+ GNUNET_PQ_query_param_timestamp (&sk->ep_end),
+ GNUNET_PQ_query_param_auto_from_type (&sk->exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (&sk->master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_insert_exchange_signkey",
+ "INSERT INTO auditor_exchange_signkeys "
+ "(ep_start"
+ ",ep_expire"
+ ",ep_end"
+ ",exchange_pub"
+ ",master_sig"
+ ") VALUES ($1,$2,$3,$4,$5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_insert_exchange_signkey",
+ params);
+}
diff --git a/src/auditordb/pg_insert_exchange_signkey.h b/src/auditordb/pg_insert_exchange_signkey.h
new file mode 100644
index 000000000..1c1eefe35
--- /dev/null
+++ b/src/auditordb/pg_insert_exchange_signkey.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_exchange_signkey.h
+ * @brief implementation of the insert_exchange_signkey function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_EXCHANGE_SIGNKEY_H
+#define PG_INSERT_EXCHANGE_SIGNKEY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Insert information about a signing key of the exchange.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param sk signing key information to store
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_exchange_signkey (
+ void *cls,
+ const struct TALER_AUDITORDB_ExchangeSigningKey *sk);
+
+
+#endif
diff --git a/src/auditordb/pg_insert_historic_denom_revenue.c b/src/auditordb/pg_insert_historic_denom_revenue.c
new file mode 100644
index 000000000..2c3dd44cc
--- /dev/null
+++ b/src/auditordb/pg_insert_historic_denom_revenue.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_historic_denom_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_historic_denom_revenue.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_historic_denom_revenue (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct GNUNET_TIME_Timestamp revenue_timestamp,
+ const struct TALER_Amount *revenue_balance,
+ const struct TALER_Amount *loss_balance)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_timestamp (&revenue_timestamp),
+ TALER_PQ_query_param_amount (pg->conn,
+ revenue_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ loss_balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_historic_denomination_revenue_insert",
+ "INSERT INTO auditor_historic_denomination_revenue"
+ "(denom_pub_hash"
+ ",revenue_timestamp"
+ ",revenue_balance"
+ ",loss_balance"
+ ") VALUES ($1,$2,$3,$4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_historic_denomination_revenue_insert",
+ params);
+}
diff --git a/src/auditordb/pg_insert_historic_denom_revenue.h b/src/auditordb/pg_insert_historic_denom_revenue.h
new file mode 100644
index 000000000..02567119b
--- /dev/null
+++ b/src/auditordb/pg_insert_historic_denom_revenue.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_historic_denom_revenue.h
+ * @brief implementation of the insert_historic_denom_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_HISTORIC_DENOM_REVENUE_H
+#define PG_INSERT_HISTORIC_DENOM_REVENUE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about an exchange's historic
+ * revenue about a denomination key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the denomination key
+ * @param revenue_timestamp when did this profit get realized
+ * @param revenue_balance what was the total profit made from
+ * deposit fees, melting fees, refresh fees
+ * and coins that were never returned?
+ * @param loss_balance total losses suffered by the exchange at the time
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_historic_denom_revenue (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct GNUNET_TIME_Timestamp revenue_timestamp,
+ const struct TALER_Amount *revenue_balance,
+ const struct TALER_Amount *loss_balance);
+
+#endif
diff --git a/src/auditordb/pg_insert_historic_reserve_revenue.c b/src/auditordb/pg_insert_historic_reserve_revenue.c
new file mode 100644
index 000000000..953fba34a
--- /dev/null
+++ b/src/auditordb/pg_insert_historic_reserve_revenue.c
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_historic_reserve_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_historic_reserve_revenue.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_historic_reserve_revenue (
+ void *cls,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ const struct TALER_Amount *reserve_profits)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&start_time),
+ GNUNET_PQ_query_param_timestamp (&end_time),
+ TALER_PQ_query_param_amount (pg->conn,
+ reserve_profits),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_historic_reserve_summary_insert",
+ "INSERT INTO auditor_historic_reserve_summary"
+ "(start_date"
+ ",end_date"
+ ",reserve_profits"
+ ") VALUES ($1,$2,$3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_historic_reserve_summary_insert",
+ params);
+}
diff --git a/src/auditordb/pg_insert_historic_reserve_revenue.h b/src/auditordb/pg_insert_historic_reserve_revenue.h
new file mode 100644
index 000000000..a76a50b39
--- /dev/null
+++ b/src/auditordb/pg_insert_historic_reserve_revenue.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_historic_reserve_revenue.h
+ * @brief implementation of the insert_historic_reserve_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_HISTORIC_RESERVE_REVENUE_H
+#define PG_INSERT_HISTORIC_RESERVE_REVENUE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about an exchange's historic revenue from reserves.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_time beginning of aggregated time interval
+ * @param end_time end of aggregated time interval
+ * @param reserve_profits total profits made
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_historic_reserve_revenue (
+ void *cls,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ const struct TALER_Amount *reserve_profits);
+
+#endif
diff --git a/src/auditordb/pg_insert_pending_deposit.c b/src/auditordb/pg_insert_pending_deposit.c
new file mode 100644
index 000000000..50b655ee7
--- /dev/null
+++ b/src/auditordb/pg_insert_pending_deposit.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_insert_pending_deposit.c
+ * @brief Implementation of the insert_pending_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_pending_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_pending_deposit (
+ void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ const struct TALER_Amount *total_amount,
+ struct GNUNET_TIME_Timestamp deadline)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ total_amount),
+ GNUNET_PQ_query_param_auto_from_type (wire_target_h_payto),
+ GNUNET_PQ_query_param_uint64 (&batch_deposit_serial_id),
+ GNUNET_PQ_query_param_timestamp (&deadline),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_insert_pending_deposit",
+ "INSERT INTO auditor_pending_deposits "
+ "(total_amount"
+ ",wire_target_h_payto"
+ ",batch_deposit_serial_id"
+ ",deadline"
+ ") VALUES ($1,$2,$3,$4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_insert_pending_deposit",
+ params);
+}
diff --git a/src/auditordb/pg_insert_pending_deposit.h b/src/auditordb/pg_insert_pending_deposit.h
new file mode 100644
index 000000000..7c2b59809
--- /dev/null
+++ b/src/auditordb/pg_insert_pending_deposit.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_insert_pending_deposit.h
+ * @brief implementation of the insert_pending_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_PENDING_DEPOSIT_H
+#define PG_INSERT_PENDING_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert new row into the pending deposits table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the requested wire transfer deadline
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_pending_deposit (
+ void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ const struct TALER_Amount *total_amount,
+ struct GNUNET_TIME_Timestamp deadline);
+
+
+#endif
diff --git a/src/auditordb/pg_insert_purse_info.c b/src/auditordb/pg_insert_purse_info.c
new file mode 100644
index 000000000..7eaad8d3c
--- /dev/null
+++ b/src/auditordb/pg_insert_purse_info.c
@@ -0,0 +1,55 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_insert_purse_info.c
+ * @brief Implementation of the insert_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_purse_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
+ GNUNET_PQ_query_param_timestamp (&expiration_date),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_purses_insert",
+ "INSERT INTO auditor_purses "
+ "(purse_pub"
+ ",target"
+ ",expiration_date"
+ ") VALUES ($1,$2,$3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_purses_insert",
+ params);
+}
diff --git a/src/auditordb/pg_insert_purse_info.h b/src/auditordb/pg_insert_purse_info.h
new file mode 100644
index 000000000..ee1b3eebd
--- /dev/null
+++ b/src/auditordb/pg_insert_purse_info.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_insert_purse_info.h
+ * @brief implementation of the insert_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_PURSE_INFO_H
+#define PG_INSERT_PURSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Insert information about a purse. There must not be an
+ * existing record for the purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the purse
+ * @param balance balance of the purse
+ * @param expiration_date expiration date of the purse
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date);
+
+#endif
diff --git a/src/auditordb/pg_insert_reserve_info.c b/src/auditordb/pg_insert_reserve_info.c
new file mode 100644
index 000000000..4c99394fe
--- /dev/null
+++ b/src/auditordb/pg_insert_reserve_info.c
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_reserve_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_reserve_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_reserve_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date,
+ const char *origin_account)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->withdraw_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->close_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->purse_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->open_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->history_fee_balance),
+ GNUNET_PQ_query_param_timestamp (&expiration_date),
+ NULL == origin_account
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (origin_account),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_insert_reserve_info",
+ "INSERT INTO auditor_reserves "
+ "(reserve_pub"
+ ",reserve_balance"
+ ",reserve_loss"
+ ",withdraw_fee_balance"
+ ",close_fee_balance"
+ ",purse_fee_balance"
+ ",open_fee_balance"
+ ",history_fee_balance"
+ ",expiration_date"
+ ",origin_account"
+ ") VALUES "
+ "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_insert_reserve_info",
+ params);
+}
diff --git a/src/auditordb/pg_insert_reserve_info.h b/src/auditordb/pg_insert_reserve_info.h
new file mode 100644
index 000000000..b416aa556
--- /dev/null
+++ b/src/auditordb/pg_insert_reserve_info.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_reserve_info.h
+ * @brief implementation of the insert_reserve_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_RESERVE_INFO_H
+#define PG_INSERT_RESERVE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about a reserve. There must not be an
+ * existing record for the reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param rfb balance amounts for the reserve
+ * @param expiration_date when will the reserve expire
+ * @param origin_account where did the money in the reserve originally come from
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_insert_reserve_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date,
+ const char *origin_account);
+
+#endif
diff --git a/src/auditordb/pg_select_historic_denom_revenue.c b/src/auditordb/pg_select_historic_denom_revenue.c
new file mode 100644
index 000000000..aa44625e7
--- /dev/null
+++ b/src/auditordb/pg_select_historic_denom_revenue.c
@@ -0,0 +1,146 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_historic_denom_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_historic_denom_revenue.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #historic_denom_revenue_cb().
+ */
+struct HistoricDenomRevenueContext
+{
+ /**
+ * Function to call for each result.
+ */
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Number of results processed.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_select_historic_denom_revenue().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct HistoricRevenueContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+historic_denom_revenue_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct HistoricDenomRevenueContext *hrc = cls;
+ struct PostgresClosure *pg = hrc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_DenominationHashP denom_pub_hash;
+ struct GNUNET_TIME_Timestamp revenue_timestamp;
+ struct TALER_Amount revenue_balance;
+ struct TALER_Amount loss;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &denom_pub_hash),
+ GNUNET_PQ_result_spec_timestamp ("revenue_timestamp",
+ &revenue_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance",
+ &revenue_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance",
+ &loss),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+
+ hrc->qs = i + 1;
+ if (GNUNET_OK !=
+ hrc->cb (hrc->cb_cls,
+ &denom_pub_hash,
+ revenue_timestamp,
+ &revenue_balance,
+ &loss))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_historic_denom_revenue (
+ void *cls,
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct HistoricDenomRevenueContext hrc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "auditor_historic_denomination_revenue_select",
+ "SELECT"
+ " denom_pub_hash"
+ ",revenue_timestamp"
+ ",revenue_balance"
+ ",loss_balance"
+ " FROM auditor_historic_denomination_revenue;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_historic_denomination_revenue_select",
+ params,
+ &historic_denom_revenue_cb,
+ &hrc);
+ if (qs <= 0)
+ return qs;
+ return hrc.qs;
+}
diff --git a/src/auditordb/pg_select_historic_denom_revenue.h b/src/auditordb/pg_select_historic_denom_revenue.h
new file mode 100644
index 000000000..25a68dacb
--- /dev/null
+++ b/src/auditordb/pg_select_historic_denom_revenue.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_historic_denom_revenue.h
+ * @brief implementation of the select_historic_denom_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_HISTORIC_DENOM_REVENUE_H
+#define PG_SELECT_HISTORIC_DENOM_REVENUE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Obtain all of the historic denomination key revenue
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call with the results
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_historic_denom_revenue (
+ void *cls,
+ TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/auditordb/pg_select_historic_reserve_revenue.c b/src/auditordb/pg_select_historic_reserve_revenue.c
new file mode 100644
index 000000000..877c3e2d7
--- /dev/null
+++ b/src/auditordb/pg_select_historic_reserve_revenue.c
@@ -0,0 +1,140 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_historic_reserve_revenue.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_historic_reserve_revenue.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #historic_reserve_revenue_cb().
+ */
+struct HistoricReserveRevenueContext
+{
+ /**
+ * Function to call for each result.
+ */
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Number of results processed.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_select_historic_reserve_revenue().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct HistoricRevenueContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+historic_reserve_revenue_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct HistoricReserveRevenueContext *hrc = cls;
+ struct PostgresClosure *pg = hrc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_Amount reserve_profits;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits",
+ &reserve_profits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ hrc->qs = i + 1;
+ if (GNUNET_OK !=
+ hrc->cb (hrc->cb_cls,
+ start_date,
+ end_date,
+ &reserve_profits))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_historic_reserve_revenue (
+ void *cls,
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct HistoricReserveRevenueContext hrc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "auditor_historic_reserve_summary_select",
+ "SELECT"
+ " start_date"
+ ",end_date"
+ ",reserve_profits"
+ " FROM auditor_historic_reserve_summary");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_historic_reserve_summary_select",
+ params,
+ &historic_reserve_revenue_cb,
+ &hrc);
+ if (0 >= qs)
+ return qs;
+ return hrc.qs;
+}
diff --git a/src/auditordb/pg_select_historic_reserve_revenue.h b/src/auditordb/pg_select_historic_reserve_revenue.h
new file mode 100644
index 000000000..b067c8917
--- /dev/null
+++ b/src/auditordb/pg_select_historic_reserve_revenue.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_historic_reserve_revenue.h
+ * @brief implementation of the select_historic_reserve_revenue function
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_HISTORIC_RESERVE_REVENUE_H
+#define PG_SELECT_HISTORIC_RESERVE_REVENUE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Return information about an exchange's historic revenue from reserves.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_historic_reserve_revenue (
+ void *cls,
+ TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/auditordb/pg_select_pending_deposits.c b/src/auditordb/pg_select_pending_deposits.c
new file mode 100644
index 000000000..1190fb132
--- /dev/null
+++ b/src/auditordb/pg_select_pending_deposits.c
@@ -0,0 +1,149 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_select_pending_deposits.c
+ * @brief Implementation of the select_pending_deposits function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_pending_deposits.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #wire_missing_cb().
+ */
+struct WireMissingContext
+{
+
+ /**
+ * Function to call for each pending deposit.
+ */
+ TALER_AUDITORDB_WireMissingCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_select_purse_expired().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireMissingContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_missing_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireMissingContext *eic = cls;
+ struct PostgresClosure *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t batch_deposit_serial_id;
+ struct TALER_Amount total_amount;
+ struct TALER_PaytoHashP wire_target_h_payto;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
+ &total_amount),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &wire_target_h_payto),
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &deadline),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ eic->cb (eic->cb_cls,
+ batch_deposit_serial_id,
+ &total_amount,
+ &wire_target_h_payto,
+ deadline);
+ }
+ eic->qs = num_results;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_pending_deposits (
+ void *cls,
+ struct GNUNET_TIME_Absolute deadline,
+ TALER_AUDITORDB_WireMissingCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&deadline),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireMissingContext eic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "auditor_select_pending_deposits",
+ "SELECT"
+ " batch_deposit_serial_id"
+ ",total_amount"
+ ",wire_target_h_payto"
+ ",deadline"
+ " FROM auditor_pending_deposits"
+ " WHERE deadline<$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "auditor_select_pending_deposits",
+ params,
+ &wire_missing_cb,
+ &eic);
+ if (0 > qs)
+ return qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != eic.qs);
+ return eic.qs;
+}
diff --git a/src/auditordb/pg_select_pending_deposits.h b/src/auditordb/pg_select_pending_deposits.h
new file mode 100644
index 000000000..e165098c5
--- /dev/null
+++ b/src/auditordb/pg_select_pending_deposits.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_select_pending_deposits.h
+ * @brief implementation of the select_pending_deposits function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PENDING_DEPOSITS_H
+#define PG_SELECT_PENDING_DEPOSITS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Return (batch) deposits for which we have not yet
+ * seen the required wire transfer.
+ *
+ * @param cls closure
+ * @param deadline only return up to this deadline
+ * @param cb function to call on each entry
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_pending_deposits (
+ void *cls,
+ struct GNUNET_TIME_Absolute deadline,
+ TALER_AUDITORDB_WireMissingCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/auditordb/pg_select_purse_expired.c b/src/auditordb/pg_select_purse_expired.c
new file mode 100644
index 000000000..77c6d3b26
--- /dev/null
+++ b/src/auditordb/pg_select_purse_expired.c
@@ -0,0 +1,146 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_select_purse_expired.c
+ * @brief Implementation of the select_purse_expired function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_expired.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #purse_expired_cb().
+ */
+struct PurseExpiredContext
+{
+
+ /**
+ * Function to call for each expired purse.
+ */
+ TALER_AUDITORDB_ExpiredPurseCallback cb;
+
+ /**
+ * Closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Query status to return.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Helper function for #TAH_PG_select_purse_expired().
+ * To be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseExpiredContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_expired_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseExpiredContext *eic = cls;
+ struct PostgresClosure *pg = eic->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct GNUNET_TIME_Timestamp expiration_date;
+ struct TALER_Amount balance;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &expiration_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ eic->qs = i + 1;
+ if (GNUNET_OK !=
+ eic->cb (eic->cb_cls,
+ &purse_pub,
+ &balance,
+ expiration_date))
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_purse_expired (
+ void *cls,
+ TALER_AUDITORDB_ExpiredPurseCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp now
+ = GNUNET_TIME_timestamp_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseExpiredContext eic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "auditor_select_expired_purses",
+ "SELECT"
+ " purse_pub"
+ ",expiration_date"
+ ",balance"
+ " FROM auditor_purses"
+ " AND expiration_date<$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "auditor_select_expired_purses",
+ params,
+ &purse_expired_cb,
+ &eic);
+ if (qs > 0)
+ return eic.qs;
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+}
diff --git a/src/auditordb/pg_select_purse_expired.h b/src/auditordb/pg_select_purse_expired.h
new file mode 100644
index 000000000..36d81285c
--- /dev/null
+++ b/src/auditordb/pg_select_purse_expired.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_select_purse_expired.h
+ * @brief implementation of the select_purse_expired function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_EXPIRED_H
+#define PG_SELECT_PURSE_EXPIRED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Get information about expired purses.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on expired purses
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_select_purse_expired (
+ void *cls,
+ TALER_AUDITORDB_ExpiredPurseCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/auditordb/pg_template.c b/src/auditordb/pg_template.c
new file mode 100644
index 000000000..e44fdab60
--- /dev/null
+++ b/src/auditordb/pg_template.c
@@ -0,0 +1,26 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_template.c
+ * @brief Implementation of the template function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_template.h"
+#include "pg_helper.h"
diff --git a/src/auditordb/pg_template.h b/src/auditordb/pg_template.h
new file mode 100644
index 000000000..911faf107
--- /dev/null
+++ b/src/auditordb/pg_template.h
@@ -0,0 +1,29 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_template.h
+ * @brief implementation of the template function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_TEMPLATE_H
+#define PG_TEMPLATE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+#endif
diff --git a/src/auditordb/pg_template.sh b/src/auditordb/pg_template.sh
new file mode 100755
index 000000000..c0937dcd3
--- /dev/null
+++ b/src/auditordb/pg_template.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# This file is in the public domain.
+#
+# Instantiates pg_template for a particular function.
+
+for n in $*
+do
+ NCAPS=`echo $n | tr a-z A-Z`
+ if test ! -e pg_$n.c
+ then
+ cat pg_template.c | sed -e s/template/$n/g -e s/TEMPLATE/$NCAPS/g > pg_$n.c
+ cat pg_template.h | sed -e s/template/$n/g -e s/TEMPLATE/$NCAPS/g > pg_$n.h
+ echo " plugin->$n\n = &TAH_PG_$n;" >> tmpl.c
+ echo "#include \"pg_$n.h\"" >> tmpl.inc
+ echo " pg_$n.h pg_$n.c \\" >> tmpl.am
+ fi
+done
+
+echo "Add lines from tmpl.am to Makefile.am"
+echo "Add lines from tmpl.inc to plugin_auditordb_postgres.c at the beginning"
+echo "Add lines from tmpl.c to plugin_auditordb_postgres.c at the end"
diff --git a/src/auditordb/pg_update_auditor_progress.c b/src/auditordb/pg_update_auditor_progress.c
new file mode 100644
index 000000000..b30be18bd
--- /dev/null
+++ b/src/auditordb/pg_update_auditor_progress.c
@@ -0,0 +1,99 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_auditor_progress.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_auditor_progress.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ progress_offset);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ uint64_t);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ uint64_t offsets[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (cnt,
+ offsets,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = progress_key;
+ offsets[0] = progress_offset;
+
+ va_start (ap,
+ progress_offset);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ offsets[off] = va_arg (ap,
+ uint64_t);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_progress_update",
+ "UPDATE auditor_progress"
+ " SET progress_offset=data.off"
+ " FROM ("
+ " SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS INT8[]))"
+ " AS t(key,off)"
+ " ) AS data"
+ " WHERE auditor_progress.progress_key=data.key;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_progress_update",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_update_auditor_progress.h b/src/auditordb/pg_update_auditor_progress.h
new file mode 100644
index 000000000..e8de58161
--- /dev/null
+++ b/src/auditordb/pg_update_auditor_progress.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_auditor_progress.h
+ * @brief implementation of the update_auditor_progress function
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_AUDITOR_PROGRESS_H
+#define PG_UPDATE_AUDITOR_PROGRESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Update information about the progress of the auditor. There
+ * must be an existing record for the exchange.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to update
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_auditor_progress (
+ void *cls,
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
+
+#endif
diff --git a/src/auditordb/pg_update_balance.c b/src/auditordb/pg_update_balance.c
new file mode 100644
index 000000000..eff03056b
--- /dev/null
+++ b/src/auditordb/pg_update_balance.c
@@ -0,0 +1,100 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_update_balance.c
+ * @brief Implementation of the update_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_balance (
+ void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_amount,
+ ...)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int cnt = 1;
+ va_list ap;
+
+ va_start (ap,
+ balance_amount);
+ while (NULL != va_arg (ap,
+ const char *))
+ {
+ cnt++;
+ (void) va_arg (ap,
+ const struct TALER_Amount *);
+ }
+ va_end (ap);
+ {
+ const char *keys[cnt];
+ struct TALER_Amount amounts[cnt];
+ unsigned int off = 1;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_array_ptrs_string (cnt,
+ keys,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (cnt,
+ amounts,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ keys[0] = balance_key;
+ amounts[0] = *balance_amount;
+
+ va_start (ap,
+ balance_amount);
+ while (off < cnt)
+ {
+ keys[off] = va_arg (ap,
+ const char *);
+ amounts[off] = *va_arg (ap,
+ const struct TALER_Amount *);
+ off++;
+ }
+ GNUNET_assert (NULL == va_arg (ap,
+ const char *));
+ va_end (ap);
+
+ PREPARE (pg,
+ "auditor_balance_update",
+ "UPDATE auditor_balances"
+ " SET balance_value.val=data.val"
+ " ,balance_value.frac=data.frac"
+ " FROM ("
+ " SELECT *"
+ " FROM UNNEST (CAST($1 AS TEXT[]),"
+ " CAST($2 AS taler_amount[]))"
+ " AS t(key,val,frac)"
+ " ) AS data"
+ " WHERE auditor_balances.balance_key=data.key;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_balance_update",
+ params);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+ }
+}
diff --git a/src/auditordb/pg_update_balance.h b/src/auditordb/pg_update_balance.h
new file mode 100644
index 000000000..8f83726f5
--- /dev/null
+++ b/src/auditordb/pg_update_balance.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_update_balance.h
+ * @brief implementation of the update_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_BALANCE_H
+#define PG_UPDATE_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about a balance tracked by the auditor. Destructively updates an
+ * existing record, which must already exist.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param balance_key key of the balance to store
+ * @param balance_amount value to store
+ * @param ... NULL terminated list of additional key-value pairs to update
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_balance (
+ void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_amount,
+ ...);
+
+
+#endif
diff --git a/src/auditordb/pg_update_denomination_balance.c b/src/auditordb/pg_update_denomination_balance.c
new file mode 100644
index 000000000..0c738779e
--- /dev/null
+++ b/src/auditordb/pg_update_denomination_balance.c
@@ -0,0 +1,62 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_denomination_balance.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_denomination_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_loss),
+ GNUNET_PQ_query_param_uint64 (&dcd->num_issued),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->denom_risk),
+ TALER_PQ_query_param_amount (pg->conn,
+ &dcd->recoup_loss),
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_denomination_pending_update",
+ "UPDATE auditor_denomination_pending SET"
+ " denom_balance=$1"
+ ",denom_loss=$2"
+ ",num_issued=$3"
+ ",denom_risk=$4"
+ ",recoup_loss=$5"
+ " WHERE denom_pub_hash=$6");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_denomination_pending_update",
+ params);
+}
diff --git a/src/auditordb/pg_update_denomination_balance.h b/src/auditordb/pg_update_denomination_balance.h
new file mode 100644
index 000000000..474fcaafd
--- /dev/null
+++ b/src/auditordb/pg_update_denomination_balance.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_denomination_balance.h
+ * @brief implementation of the update_denomination_balance function
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_DENOMINATION_BALANCE_H
+#define PG_UPDATE_DENOMINATION_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Update information about a denomination key's balances. There
+ * must be an existing record for the denomination key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the denomination public key
+ * @param dcd circulation data to store
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_denomination_balance (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd);
+
+
+#endif
diff --git a/src/auditordb/pg_update_purse_info.c b/src/auditordb/pg_update_purse_info.c
new file mode 100644
index 000000000..66dfd490e
--- /dev/null
+++ b/src/auditordb/pg_update_purse_info.c
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_update_purse_info.c
+ * @brief Implementation of the update_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_purse_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance)
+{
+
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_purses_update",
+ "UPDATE auditor_purses"
+ " SET balance=$2"
+ " WHERE purse_pub=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_purses_update",
+ params);
+}
diff --git a/src/auditordb/pg_update_purse_info.h b/src/auditordb/pg_update_purse_info.h
new file mode 100644
index 000000000..ac37be7b4
--- /dev/null
+++ b/src/auditordb/pg_update_purse_info.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file auditordb/pg_update_purse_info.h
+ * @brief implementation of the update_purse_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_PURSE_INFO_H
+#define PG_UPDATE_PURSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Update information about a purse. Destructively updates an
+ * existing record, which must already exist.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the purse
+ * @param balance new balance for the purse
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_purse_info (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance);
+
+
+#endif
diff --git a/src/auditordb/pg_update_reserve_info.c b/src/auditordb/pg_update_reserve_info.c
new file mode 100644
index 000000000..2d38a2b0e
--- /dev/null
+++ b/src/auditordb/pg_update_reserve_info.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_reserve_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_reserve_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_reserve_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->reserve_loss),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->withdraw_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->purse_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->open_fee_balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ &rfb->history_fee_balance),
+ GNUNET_PQ_query_param_timestamp (&expiration_date),
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_update_reserve_info",
+ "UPDATE auditor_reserves SET"
+ " reserve_balance=$1"
+ ",reserve_loss=$2"
+ ",withdraw_fee_balance=$3"
+ ",purse_fee_balance=$4"
+ ",open_fee_balance=$5"
+ ",history_fee_balance=$6"
+ ",expiration_date=$7"
+ " WHERE reserve_pub=$8");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_update_reserve_info",
+ params);
+}
diff --git a/src/auditordb/pg_update_reserve_info.h b/src/auditordb/pg_update_reserve_info.h
new file mode 100644
index 000000000..25f43476a
--- /dev/null
+++ b/src/auditordb/pg_update_reserve_info.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_reserve_info.h
+ * @brief implementation of the update_reserve_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_RESERVE_INFO_H
+#define PG_UPDATE_RESERVE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Update information about a reserve. Destructively updates an
+ * existing record, which must already exist.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param rfb amounts for the reserve
+ * @param expiration_date expiration date of the reserve
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_reserve_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date);
+
+#endif
diff --git a/src/auditordb/pg_update_wire_fee_summary.c b/src/auditordb/pg_update_wire_fee_summary.c
new file mode 100644
index 000000000..192612f17
--- /dev/null
+++ b/src/auditordb/pg_update_wire_fee_summary.c
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_wire_fee_summary.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_wire_fee_summary.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_wire_fee_summary (
+ void *cls,
+ const struct TALER_Amount *wire_fee_balance)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ wire_fee_balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "auditor_wire_fee_balance_update",
+ "UPDATE auditor_wire_fee_balance SET"
+ " wire_fee_balance=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "auditor_wire_fee_balance_update",
+ params);
+}
diff --git a/src/auditordb/pg_update_wire_fee_summary.h b/src/auditordb/pg_update_wire_fee_summary.h
new file mode 100644
index 000000000..a004a2db4
--- /dev/null
+++ b/src/auditordb/pg_update_wire_fee_summary.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_update_wire_fee_summary.h
+ * @brief implementation of the update_wire_fee_summary function
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_WIRE_FEE_SUMMARY_H
+#define PG_UPDATE_WIRE_FEE_SUMMARY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_auditordb_plugin.h"
+
+
+/**
+ * Insert information about exchange's wire fee balance. Destructively updates an
+ * existing record, which must already exist.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wire_fee_balance amount the exchange gained in wire fees
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TAH_PG_update_wire_fee_summary (
+ void *cls,
+ const struct TALER_Amount *wire_fee_balance);
+
+#endif
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 971893204..f5c405d8d 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,9 +21,41 @@
*/
#include "platform.h"
#include "taler_pq_lib.h"
-#include "taler_auditordb_plugin.h"
#include <pthread.h>
#include <libpq-fe.h>
+#include "pg_delete_deposit_confirmations.h"
+#include "pg_delete_pending_deposit.h"
+#include "pg_delete_purse_info.h"
+#include "pg_del_denomination_balance.h"
+#include "pg_del_reserve_info.h"
+#include "pg_get_auditor_progress.h"
+#include "pg_get_balance.h"
+#include "pg_get_denomination_balance.h"
+#include "pg_get_deposit_confirmations.h"
+#include "pg_get_purse_info.h"
+#include "pg_get_reserve_info.h"
+#include "pg_get_wire_fee_summary.h"
+#include "pg_helper.h"
+#include "pg_insert_auditor_progress.h"
+#include "pg_insert_balance.h"
+#include "pg_insert_denomination_balance.h"
+#include "pg_insert_deposit_confirmation.h"
+#include "pg_insert_exchange_signkey.h"
+#include "pg_insert_historic_denom_revenue.h"
+#include "pg_insert_historic_reserve_revenue.h"
+#include "pg_insert_pending_deposit.h"
+#include "pg_insert_purse_info.h"
+#include "pg_insert_reserve_info.h"
+#include "pg_select_historic_denom_revenue.h"
+#include "pg_select_historic_reserve_revenue.h"
+#include "pg_select_pending_deposits.h"
+#include "pg_select_purse_expired.h"
+#include "pg_update_auditor_progress.h"
+#include "pg_update_balance.h"
+#include "pg_update_denomination_balance.h"
+#include "pg_update_purse_info.h"
+#include "pg_update_reserve_info.h"
+#include "pg_update_wire_fee_summary.h"
#define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", \
@@ -31,60 +63,6 @@
/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) \
- TALER_PQ_result_spec_amount ( \
- field,pg->currency,amountp)
-
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database. NBO variant.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field, \
- amountp) TALER_PQ_result_spec_amount_nbo ( \
- field,pg->currency,amountp)
-
-
-/**
- * Type of the "cls" argument given to each of the functions in
- * our API.
- */
-struct PostgresClosure
-{
-
- /**
- * Postgres connection handle.
- */
- struct GNUNET_PQ_Context *conn;
-
- /**
- * Name of the ongoing transaction, used to debug cases where
- * a transaction is not properly terminated via COMMIT or
- * ROLLBACK.
- */
- const char *transaction_name;
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Which currency should we assume all amounts to be in?
- */
- char *currency;
-};
-
-
-/**
* Drop all auditor tables OR deletes recoverable auditor state.
* This should only be used by testcases or when restarting the
* auditor from scratch.
@@ -97,20 +75,23 @@ struct PostgresClosure
*/
static enum GNUNET_GenericReturnValue
postgres_drop_tables (void *cls,
- int drop_exchangelist)
+ bool drop_exchangelist)
{
struct PostgresClosure *pc = cls;
struct GNUNET_PQ_Context *conn;
+ enum GNUNET_GenericReturnValue ret;
conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
"auditordb-postgres",
- (drop_exchangelist) ? "drop" : "restart",
+ NULL,
NULL,
NULL);
if (NULL == conn)
return GNUNET_SYSERR;
+ ret = GNUNET_PQ_exec_sql (conn,
+ (drop_exchangelist) ? "drop" : "restart");
GNUNET_PQ_disconnect (conn);
- return GNUNET_OK;
+ return ret;
}
@@ -118,23 +99,129 @@ postgres_drop_tables (void *cls,
* Create the necessary tables if they are not present
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param support_partitions true to support partitioning
+ * @param num_partitions number of partitions to use
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
static enum GNUNET_GenericReturnValue
-postgres_create_tables (void *cls)
+postgres_create_tables (void *cls,
+ bool support_partitions,
+ uint32_t num_partitions)
{
struct PostgresClosure *pc = cls;
+ enum GNUNET_GenericReturnValue ret = GNUNET_OK;
struct GNUNET_PQ_Context *conn;
+ struct GNUNET_PQ_QueryParam params[] = {
+ support_partitions
+ ? GNUNET_PQ_query_param_uint32 (&num_partitions)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare ("create_tables",
+ "SELECT"
+ " auditor.do_create_tables"
+ " ($1);"),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
"auditordb-postgres",
"auditor-",
- NULL,
- NULL);
+ es,
+ ps);
if (NULL == conn)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to database\n");
return GNUNET_SYSERR;
+ }
+ if (0 >
+ GNUNET_PQ_eval_prepared_non_select (conn,
+ "create_tables",
+ params))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to run 'create_tables' prepared statement\n");
+ ret = GNUNET_SYSERR;
+ }
+ if (GNUNET_OK == ret)
+ {
+ ret = GNUNET_PQ_exec_sql (conn,
+ "procedures");
+ if (GNUNET_OK != ret)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to load stored procedures\n");
+ }
GNUNET_PQ_disconnect (conn);
- return GNUNET_OK;
+ return ret;
+}
+
+
+/**
+ * Register callback to be invoked on events of type @a es.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to listen for
+ * @param timeout how long to wait for the event
+ * @param cb function to call when the event happens, possibly
+ * mulrewardle times (until cancel is invoked)
+ * @param cb_cls closure for @a cb
+ * @return handle useful to cancel the listener
+ */
+static struct GNUNET_DB_EventHandler *
+postgres_event_listen (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DB_EventCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+
+ return GNUNET_PQ_event_listen (pg->conn,
+ es,
+ timeout,
+ cb,
+ cb_cls);
+}
+
+
+/**
+ * Stop notifications.
+ *
+ * @param eh handle to unregister.
+ */
+static void
+postgres_event_listen_cancel (struct GNUNET_DB_EventHandler *eh)
+{
+ GNUNET_PQ_event_listen_cancel (eh);
+}
+
+
+/**
+ * Notify all that listen on @a es of an event.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to generate
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+postgres_event_notify (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ const void *extra,
+ size_t extra_size)
+{
+ struct PostgresClosure *pg = cls;
+
+ return GNUNET_PQ_event_notify (pg->conn,
+ es,
+ extra,
+ extra_size);
}
@@ -147,540 +234,9 @@ postgres_create_tables (void *cls)
static enum GNUNET_GenericReturnValue
setup_connection (struct PostgresClosure *pg)
{
- struct GNUNET_PQ_PreparedStatement ps[] = {
- /* used in #postgres_commit */
- GNUNET_PQ_make_prepare ("do_commit",
- "COMMIT",
- 0),
- /* used in #postgres_insert_exchange */
- GNUNET_PQ_make_prepare ("auditor_insert_exchange",
- "INSERT INTO auditor_exchanges "
- "(master_pub"
- ",exchange_url"
- ") VALUES ($1,$2);",
- 2),
- /* used in #postgres_delete_exchange */
- GNUNET_PQ_make_prepare ("auditor_delete_exchange",
- "DELETE"
- " FROM auditor_exchanges"
- " WHERE master_pub=$1;",
- 1),
- /* used in #postgres_list_exchanges */
- GNUNET_PQ_make_prepare ("auditor_list_exchanges",
- "SELECT"
- " master_pub"
- ",exchange_url"
- " FROM auditor_exchanges",
- 0),
- /* used in #postgres_insert_exchange_signkey */
- GNUNET_PQ_make_prepare ("auditor_insert_exchange_signkey",
- "INSERT INTO auditor_exchange_signkeys "
- "(master_pub"
- ",ep_start"
- ",ep_expire"
- ",ep_end"
- ",exchange_pub"
- ",master_sig"
- ") VALUES ($1,$2,$3,$4,$5,$6);",
- 6),
- /* Used in #postgres_insert_deposit_confirmation() */
- GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_insert",
- "INSERT INTO deposit_confirmations "
- "(master_pub"
- ",h_contract_terms"
- ",h_extensions"
- ",h_wire"
- ",exchange_timestamp"
- ",wire_deadline"
- ",refund_deadline"
- ",amount_without_fee_val"
- ",amount_without_fee_frac"
- ",coin_pub"
- ",merchant_pub"
- ",exchange_sig"
- ",exchange_pub"
- ",master_sig" /* master_sig could be normalized... */
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);",
- 14),
- /* Used in #postgres_get_deposit_confirmations() */
- GNUNET_PQ_make_prepare ("auditor_deposit_confirmation_select",
- "SELECT"
- " serial_id"
- ",h_contract_terms"
- ",h_extensions"
- ",h_wire"
- ",exchange_timestamp"
- ",wire_deadline"
- ",refund_deadline"
- ",amount_without_fee_val"
- ",amount_without_fee_frac"
- ",coin_pub"
- ",merchant_pub"
- ",exchange_sig"
- ",exchange_pub"
- ",master_sig" /* master_sig could be normalized... */
- " FROM deposit_confirmations"
- " WHERE master_pub=$1"
- " AND serial_id>$2",
- 2),
- /* Used in #postgres_update_auditor_progress_reserve() */
- GNUNET_PQ_make_prepare ("auditor_progress_update_reserve",
- "UPDATE auditor_progress_reserve SET "
- " last_reserve_in_serial_id=$1"
- ",last_reserve_out_serial_id=$2"
- ",last_reserve_recoup_serial_id=$3"
- ",last_reserve_close_serial_id=$4"
- ",last_purse_merges_serial_id=$5"
- ",last_purse_deposits_serial_id=$6"
- ",last_account_merges_serial_id=$7"
- ",last_history_requests_serial_id=$8"
- ",last_close_requests_serial_id=$9"
- " WHERE master_pub=$10",
- 10),
- /* Used in #postgres_get_auditor_progress_reserve() */
- GNUNET_PQ_make_prepare ("auditor_progress_select_reserve",
- "SELECT"
- " last_reserve_in_serial_id"
- ",last_reserve_out_serial_id"
- ",last_reserve_recoup_serial_id"
- ",last_reserve_close_serial_id"
- ",last_purse_merges_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_account_merges_serial_id"
- ",last_history_requests_serial_id"
- ",last_close_requests_serial_id"
- " FROM auditor_progress_reserve"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_auditor_progress_reserve() */
- GNUNET_PQ_make_prepare ("auditor_progress_insert_reserve",
- "INSERT INTO auditor_progress_reserve "
- "(master_pub"
- ",last_reserve_in_serial_id"
- ",last_reserve_out_serial_id"
- ",last_reserve_recoup_serial_id"
- ",last_reserve_close_serial_id"
- ",last_purse_merges_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_account_merges_serial_id"
- ",last_history_requests_serial_id"
- ",last_close_requests_serial_id"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);",
- 10),
- /* Used in #postgres_update_auditor_progress_aggregation() */
- GNUNET_PQ_make_prepare ("auditor_progress_update_aggregation",
- "UPDATE auditor_progress_aggregation SET "
- " last_wire_out_serial_id=$1"
- " WHERE master_pub=$2",
- 2),
- /* Used in #postgres_get_auditor_progress_aggregation() */
- GNUNET_PQ_make_prepare ("auditor_progress_select_aggregation",
- "SELECT"
- " last_wire_out_serial_id"
- " FROM auditor_progress_aggregation"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_auditor_progress_aggregation() */
- GNUNET_PQ_make_prepare ("auditor_progress_insert_aggregation",
- "INSERT INTO auditor_progress_aggregation "
- "(master_pub"
- ",last_wire_out_serial_id"
- ") VALUES ($1,$2);",
- 2),
- /* Used in #postgres_update_auditor_progress_deposit_confirmation() */
- GNUNET_PQ_make_prepare ("auditor_progress_update_deposit_confirmation",
- "UPDATE auditor_progress_deposit_confirmation SET "
- " last_deposit_confirmation_serial_id=$1"
- " WHERE master_pub=$2",
- 2),
- /* Used in #postgres_get_auditor_progress_deposit_confirmation() */
- GNUNET_PQ_make_prepare ("auditor_progress_select_deposit_confirmation",
- "SELECT"
- " last_deposit_confirmation_serial_id"
- " FROM auditor_progress_deposit_confirmation"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_auditor_progress_deposit_confirmation() */
- GNUNET_PQ_make_prepare ("auditor_progress_insert_deposit_confirmation",
- "INSERT INTO auditor_progress_deposit_confirmation "
- "(master_pub"
- ",last_deposit_confirmation_serial_id"
- ") VALUES ($1,$2);",
- 2),
- /* Used in #postgres_update_auditor_progress_coin() */
- GNUNET_PQ_make_prepare ("auditor_progress_update_coin",
- "UPDATE auditor_progress_coin SET "
- " last_withdraw_serial_id=$1"
- ",last_deposit_serial_id=$2"
- ",last_melt_serial_id=$3"
- ",last_refund_serial_id=$4"
- ",last_recoup_serial_id=$5"
- ",last_recoup_refresh_serial_id=$6"
- ",last_purse_deposits_serial_id=$7"
- ",last_purse_refunds_serial_id=$8"
- " WHERE master_pub=$9",
- 9),
- /* Used in #postgres_get_auditor_progress_coin() */
- GNUNET_PQ_make_prepare ("auditor_progress_select_coin",
- "SELECT"
- " last_withdraw_serial_id"
- ",last_deposit_serial_id"
- ",last_melt_serial_id"
- ",last_refund_serial_id"
- ",last_recoup_serial_id"
- ",last_recoup_refresh_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_purse_refunds_serial_id"
- " FROM auditor_progress_coin"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_auditor_progress() */
- GNUNET_PQ_make_prepare ("auditor_progress_insert_coin",
- "INSERT INTO auditor_progress_coin "
- "(master_pub"
- ",last_withdraw_serial_id"
- ",last_deposit_serial_id"
- ",last_melt_serial_id"
- ",last_refund_serial_id"
- ",last_recoup_serial_id"
- ",last_recoup_refresh_serial_id"
- ",last_purse_deposits_serial_id"
- ",last_purse_refunds_serial_id"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
- 9),
- /* Used in #postgres_insert_wire_auditor_account_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_account_progress_insert",
- "INSERT INTO wire_auditor_account_progress "
- "(master_pub"
- ",account_name"
- ",last_wire_reserve_in_serial_id"
- ",last_wire_wire_out_serial_id"
- ",wire_in_off"
- ",wire_out_off"
- ") VALUES ($1,$2,$3,$4,$5,$6);",
- 6),
- /* Used in #postgres_update_wire_auditor_account_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_account_progress_update",
- "UPDATE wire_auditor_account_progress SET "
- " last_wire_reserve_in_serial_id=$1"
- ",last_wire_wire_out_serial_id=$2"
- ",wire_in_off=$3"
- ",wire_out_off=$4"
- " WHERE master_pub=$5 AND account_name=$6",
- 6),
- /* Used in #postgres_get_wire_auditor_account_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_account_progress_select",
- "SELECT"
- " last_wire_reserve_in_serial_id"
- ",last_wire_wire_out_serial_id"
- ",wire_in_off"
- ",wire_out_off"
- " FROM wire_auditor_account_progress"
- " WHERE master_pub=$1 AND account_name=$2;",
- 2),
- /* Used in #postgres_insert_wire_auditor_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_progress_insert",
- "INSERT INTO wire_auditor_progress "
- "(master_pub"
- ",last_timestamp"
- ",last_reserve_close_uuid"
- ") VALUES ($1,$2,$3);",
- 3),
- /* Used in #postgres_update_wire_auditor_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_progress_update",
- "UPDATE wire_auditor_progress SET "
- " last_timestamp=$1"
- ",last_reserve_close_uuid=$2"
- " WHERE master_pub=$3",
- 3),
- /* Used in #postgres_get_wire_auditor_progress() */
- GNUNET_PQ_make_prepare ("wire_auditor_progress_select",
- "SELECT"
- " last_timestamp"
- ",last_reserve_close_uuid"
- " FROM wire_auditor_progress"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_reserve_info() */
- GNUNET_PQ_make_prepare ("auditor_reserves_insert",
- "INSERT INTO auditor_reserves "
- "(reserve_pub"
- ",master_pub"
- ",reserve_balance_val"
- ",reserve_balance_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",expiration_date"
- ",origin_account"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8);",
- 8),
- /* Used in #postgres_update_reserve_info() */
- GNUNET_PQ_make_prepare ("auditor_reserves_update",
- "UPDATE auditor_reserves SET"
- " reserve_balance_val=$1"
- ",reserve_balance_frac=$2"
- ",withdraw_fee_balance_val=$3"
- ",withdraw_fee_balance_frac=$4"
- ",expiration_date=$5"
- " WHERE reserve_pub=$6 AND master_pub=$7;",
- 7),
- /* Used in #postgres_get_reserve_info() */
- GNUNET_PQ_make_prepare ("auditor_reserves_select",
- "SELECT"
- " reserve_balance_val"
- ",reserve_balance_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",expiration_date"
- ",auditor_reserves_rowid"
- ",origin_account"
- " FROM auditor_reserves"
- " WHERE reserve_pub=$1 AND master_pub=$2;",
- 2),
- /* Used in #postgres_del_reserve_info() */
- GNUNET_PQ_make_prepare ("auditor_reserves_delete",
- "DELETE"
- " FROM auditor_reserves"
- " WHERE reserve_pub=$1 AND master_pub=$2;",
- 2),
- /* Used in #postgres_insert_reserve_summary() */
- GNUNET_PQ_make_prepare ("auditor_reserve_balance_insert",
- "INSERT INTO auditor_reserve_balance"
- "(master_pub"
- ",reserve_balance_val"
- ",reserve_balance_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9)",
- 9),
- /* Used in #postgres_update_reserve_summary() */
- GNUNET_PQ_make_prepare ("auditor_reserve_balance_update",
- "UPDATE auditor_reserve_balance SET"
- " reserve_balance_val=$1"
- ",reserve_balance_frac=$2"
- ",withdraw_fee_balance_val=$3"
- ",withdraw_fee_balance_frac=$4"
- ",purse_fee_balance_val=$5"
- ",purse_fee_balance_frac=$6"
- ",history_fee_balance_val=$7"
- ",history_fee_balance_frac=$8"
- " WHERE master_pub=$9;",
- 9),
- /* Used in #postgres_get_reserve_summary() */
- GNUNET_PQ_make_prepare ("auditor_reserve_balance_select",
- "SELECT"
- " reserve_balance_val"
- ",reserve_balance_frac"
- ",withdraw_fee_balance_val"
- ",withdraw_fee_balance_frac"
- ",purse_fee_balance_val"
- ",purse_fee_balance_frac"
- ",history_fee_balance_val"
- ",history_fee_balance_frac"
- " FROM auditor_reserve_balance"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_wire_fee_summary() */
- GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_insert",
- "INSERT INTO auditor_wire_fee_balance"
- "(master_pub"
- ",wire_fee_balance_val"
- ",wire_fee_balance_frac"
- ") VALUES ($1,$2,$3)",
- 3),
- /* Used in #postgres_update_wire_fee_summary() */
- GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_update",
- "UPDATE auditor_wire_fee_balance SET"
- " wire_fee_balance_val=$1"
- ",wire_fee_balance_frac=$2"
- " WHERE master_pub=$3;",
- 3),
- /* Used in #postgres_get_wire_fee_summary() */
- GNUNET_PQ_make_prepare ("auditor_wire_fee_balance_select",
- "SELECT"
- " wire_fee_balance_val"
- ",wire_fee_balance_frac"
- " FROM auditor_wire_fee_balance"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_denomination_balance() */
- GNUNET_PQ_make_prepare ("auditor_denomination_pending_insert",
- "INSERT INTO auditor_denomination_pending "
- "(denom_pub_hash"
- ",denom_balance_val"
- ",denom_balance_frac"
- ",denom_loss_val"
- ",denom_loss_frac"
- ",num_issued"
- ",denom_risk_val"
- ",denom_risk_frac"
- ",recoup_loss_val"
- ",recoup_loss_frac"
- ") VALUES ("
- "$1,$2,$3,$4,$5,$6,$7,$8,$9,$10"
- ");",
- 10),
- /* Used in #postgres_update_denomination_balance() */
- GNUNET_PQ_make_prepare ("auditor_denomination_pending_update",
- "UPDATE auditor_denomination_pending SET"
- " denom_balance_val=$1"
- ",denom_balance_frac=$2"
- ",denom_loss_val=$3"
- ",denom_loss_frac=$4"
- ",num_issued=$5"
- ",denom_risk_val=$6"
- ",denom_risk_frac=$7"
- ",recoup_loss_val=$8"
- ",recoup_loss_frac=$9"
- " WHERE denom_pub_hash=$10",
- 10),
- /* Used in #postgres_get_denomination_balance() */
- GNUNET_PQ_make_prepare ("auditor_denomination_pending_select",
- "SELECT"
- " denom_balance_val"
- ",denom_balance_frac"
- ",denom_loss_val"
- ",denom_loss_frac"
- ",num_issued"
- ",denom_risk_val"
- ",denom_risk_frac"
- ",recoup_loss_val"
- ",recoup_loss_frac"
- " FROM auditor_denomination_pending"
- " WHERE denom_pub_hash=$1",
- 1),
- /* Used in #postgres_insert_balance_summary() */
- GNUNET_PQ_make_prepare ("auditor_balance_summary_insert",
- "INSERT INTO auditor_balance_summary "
- "(master_pub"
- ",denom_balance_val"
- ",denom_balance_frac"
- ",deposit_fee_balance_val"
- ",deposit_fee_balance_frac"
- ",melt_fee_balance_val"
- ",melt_fee_balance_frac"
- ",refund_fee_balance_val"
- ",refund_fee_balance_frac"
- ",risk_val"
- ",risk_frac"
- ",loss_val"
- ",loss_frac"
- ",irregular_recoup_val"
- ",irregular_recoup_frac"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,"
- " $11,$12,$13,$14,$15);",
- 15),
- /* Used in #postgres_update_balance_summary() */
- GNUNET_PQ_make_prepare ("auditor_balance_summary_update",
- "UPDATE auditor_balance_summary SET"
- " denom_balance_val=$1"
- ",denom_balance_frac=$2"
- ",deposit_fee_balance_val=$3"
- ",deposit_fee_balance_frac=$4"
- ",melt_fee_balance_val=$5"
- ",melt_fee_balance_frac=$6"
- ",refund_fee_balance_val=$7"
- ",refund_fee_balance_frac=$8"
- ",risk_val=$9"
- ",risk_frac=$10"
- ",loss_val=$11"
- ",loss_frac=$12"
- ",irregular_recoup_val=$13"
- ",irregular_recoup_frac=$14"
- " WHERE master_pub=$15;",
- 15),
- /* Used in #postgres_get_balance_summary() */
- GNUNET_PQ_make_prepare ("auditor_balance_summary_select",
- "SELECT"
- " denom_balance_val"
- ",denom_balance_frac"
- ",deposit_fee_balance_val"
- ",deposit_fee_balance_frac"
- ",melt_fee_balance_val"
- ",melt_fee_balance_frac"
- ",refund_fee_balance_val"
- ",refund_fee_balance_frac"
- ",risk_val"
- ",risk_frac"
- ",loss_val"
- ",loss_frac"
- ",irregular_recoup_val"
- ",irregular_recoup_frac"
- " FROM auditor_balance_summary"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_historic_denom_revenue() */
- GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_insert",
- "INSERT INTO auditor_historic_denomination_revenue"
- "(master_pub"
- ",denom_pub_hash"
- ",revenue_timestamp"
- ",revenue_balance_val"
- ",revenue_balance_frac"
- ",loss_balance_val"
- ",loss_balance_frac"
- ") VALUES ($1,$2,$3,$4,$5,$6,$7);",
- 7),
- /* Used in #postgres_select_historic_denom_revenue() */
- GNUNET_PQ_make_prepare ("auditor_historic_denomination_revenue_select",
- "SELECT"
- " denom_pub_hash"
- ",revenue_timestamp"
- ",revenue_balance_val"
- ",revenue_balance_frac"
- ",loss_balance_val"
- ",loss_balance_frac"
- " FROM auditor_historic_denomination_revenue"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_historic_reserve_revenue() */
- GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_insert",
- "INSERT INTO auditor_historic_reserve_summary"
- "(master_pub"
- ",start_date"
- ",end_date"
- ",reserve_profits_val"
- ",reserve_profits_frac"
- ") VALUES ($1,$2,$3,$4,$5);",
- 5),
- /* Used in #postgres_select_historic_reserve_revenue() */
- GNUNET_PQ_make_prepare ("auditor_historic_reserve_summary_select",
- "SELECT"
- " start_date"
- ",end_date"
- ",reserve_profits_val"
- ",reserve_profits_frac"
- " FROM auditor_historic_reserve_summary"
- " WHERE master_pub=$1;",
- 1),
- /* Used in #postgres_insert_predicted_result() */
- GNUNET_PQ_make_prepare ("auditor_predicted_result_insert",
- "INSERT INTO auditor_predicted_result"
- "(master_pub"
- ",balance_val"
- ",balance_frac"
- ") VALUES ($1,$2,$3);",
- 3),
- /* Used in #postgres_update_predicted_result() */
- GNUNET_PQ_make_prepare ("auditor_predicted_result_update",
- "UPDATE auditor_predicted_result SET"
- " balance_val=$1"
- ",balance_frac=$2"
- " WHERE master_pub=$3;",
- 3),
- /* Used in #postgres_get_predicted_balance() */
- GNUNET_PQ_make_prepare ("auditor_predicted_result_select",
- "SELECT"
- " balance_val"
- ",balance_frac"
- " FROM auditor_predicted_result"
- " WHERE master_pub=$1;",
- 1),
- GNUNET_PQ_PREPARED_STATEMENT_END
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
};
struct GNUNET_PQ_Context *db_conn;
@@ -692,11 +248,12 @@ setup_connection (struct PostgresClosure *pg)
db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"auditordb-postgres",
NULL,
- NULL,
- ps);
+ es,
+ NULL);
if (NULL == db_conn)
return GNUNET_SYSERR;
pg->conn = db_conn;
+ pg->prep_gen++;
return GNUNET_OK;
}
@@ -811,6 +368,9 @@ postgres_commit (void *cls)
GNUNET_PQ_query_param_end
};
+ PREPARE (pg,
+ "do_commit",
+ "COMMIT");
return GNUNET_PQ_eval_prepared_non_select (pg->conn,
"do_commit",
params);
@@ -837,19 +397,18 @@ postgres_gc (void *cls)
struct GNUNET_PQ_Context *conn;
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_PQ_PreparedStatement ps[] = {
-#if 0
- GNUNET_PQ_make_prepare ("gc_auditor",
- "TODO: #4960",
- 0),
-#endif
GNUNET_PQ_PREPARED_STATEMENT_END
};
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO auditor;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
now = GNUNET_TIME_absolute_get ();
conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
"auditordb-postgres",
NULL,
- NULL,
+ es,
ps);
if (NULL == conn)
return GNUNET_SYSERR;
@@ -869,2036 +428,6 @@ postgres_gc (void *cls)
/**
- * Insert information about an exchange this auditor will be auditing.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param exchange_url public (base) URL of the API of the exchange
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (exchange_url),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_exchange",
- params);
-}
-
-
-/**
- * Delete an exchange from the list of exchanges this auditor is auditing.
- * Warning: this will cascade and delete all knowledge of this auditor related
- * to this exchange!
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_exchange (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_delete_exchange",
- params);
-}
-
-
-/**
- * Closure for #exchange_info_cb().
- */
-struct ExchangeInfoContext
-{
-
- /**
- * Function to call for each exchange.
- */
- TALER_AUDITORDB_ExchangeCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #postgres_list_exchanges().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ExchangeInfoContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-exchange_info_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ExchangeInfoContext *eic = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_MasterPublicKeyP master_pub;
- char *exchange_url;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_pub", &master_pub),
- GNUNET_PQ_result_spec_string ("exchange_url", &exchange_url),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- eic->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- eic->qs = i + 1;
- eic->cb (eic->cb_cls,
- &master_pub,
- exchange_url);
- GNUNET_free (exchange_url);
- }
-}
-
-
-/**
- * Obtain information about exchanges this auditor is auditing.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_list_exchanges (void *cls,
- TALER_AUDITORDB_ExchangeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct ExchangeInfoContext eic = {
- .cb = cb,
- .cb_cls = cb_cls
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_list_exchanges",
- params,
- &exchange_info_cb,
- &eic);
- if (qs > 0)
- return eic.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
-
-
-/**
- * Insert information about a signing key of the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param sk signing key information to store
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_exchange_signkey (
- void *cls,
- const struct TALER_AUDITORDB_ExchangeSigningKey *sk)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&sk->master_public_key),
- GNUNET_PQ_query_param_timestamp (&sk->ep_start),
- GNUNET_PQ_query_param_timestamp (&sk->ep_expire),
- GNUNET_PQ_query_param_timestamp (&sk->ep_end),
- GNUNET_PQ_query_param_auto_from_type (&sk->exchange_pub),
- GNUNET_PQ_query_param_auto_from_type (&sk->master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_insert_exchange_signkey",
- params);
-}
-
-
-/**
- * Insert information about a deposit confirmation into the database.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param dc deposit confirmation information to store
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_deposit_confirmation (
- void *cls,
- const struct TALER_AUDITORDB_DepositConfirmation *dc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&dc->master_public_key),
- GNUNET_PQ_query_param_auto_from_type (&dc->h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (&dc->h_extensions),
- GNUNET_PQ_query_param_auto_from_type (&dc->h_wire),
- GNUNET_PQ_query_param_timestamp (&dc->exchange_timestamp),
- GNUNET_PQ_query_param_timestamp (&dc->wire_deadline),
- GNUNET_PQ_query_param_timestamp (&dc->refund_deadline),
- TALER_PQ_query_param_amount (&dc->amount_without_fee),
- GNUNET_PQ_query_param_auto_from_type (&dc->coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&dc->merchant),
- GNUNET_PQ_query_param_auto_from_type (&dc->exchange_sig),
- GNUNET_PQ_query_param_auto_from_type (&dc->exchange_pub),
- GNUNET_PQ_query_param_auto_from_type (&dc->master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_deposit_confirmation_insert",
- params);
-}
-
-
-/**
- * Closure for #deposit_confirmation_cb().
- */
-struct DepositConfirmationContext
-{
-
- /**
- * Master public key that is being used.
- */
- const struct TALER_MasterPublicKeyP *master_pub;
-
- /**
- * Function to call for each deposit confirmation.
- */
- TALER_AUDITORDB_DepositConfirmationCallback cb;
-
- /**
- * Closure for @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Query status to return.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #postgres_get_deposit_confirmations().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositConfirmationContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-deposit_confirmation_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DepositConfirmationContext *dcc = cls;
- struct PostgresClosure *pg = dcc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t serial_id;
- struct TALER_AUDITORDB_DepositConfirmation dc = {
- .master_public_key = *dcc->master_pub
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial_id",
- &serial_id),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &dc.h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("h_extensions",
- &dc.h_extensions),
- GNUNET_PQ_result_spec_auto_from_type ("h_wire",
- &dc.h_wire),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- &dc.exchange_timestamp),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &dc.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &dc.wire_deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_without_fee",
- &dc.amount_without_fee),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &dc.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &dc.merchant),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_sig",
- &dc.exchange_sig),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
- &dc.exchange_pub),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &dc.master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dcc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- dcc->qs = i + 1;
- if (GNUNET_OK !=
- dcc->cb (dcc->cb_cls,
- serial_id,
- &dc))
- break;
- }
-}
-
-
-/**
- * Get information about deposit confirmations from the database.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_public_key for which exchange do we want to get deposit confirmations
- * @param start_id row/serial ID where to start the iteration (0 from
- * the start, exclusive, i.e. serial_ids must start from 1)
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_deposit_confirmations (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_public_key,
- uint64_t start_id,
- TALER_AUDITORDB_DepositConfirmationCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_public_key),
- GNUNET_PQ_query_param_uint64 (&start_id),
- GNUNET_PQ_query_param_end
- };
- struct DepositConfirmationContext dcc = {
- .master_pub = master_public_key,
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_deposit_confirmation_select",
- params,
- &deposit_confirmation_cb,
- &dcc);
- if (qs > 0)
- return dcc.qs;
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
- return qs;
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_close_requests_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_reserve",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_reserve_close_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_account_merges_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_history_requests_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppr->last_close_requests_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_reserve",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppr set to where the auditor is in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_auditor_progress_reserve (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointReserve *ppr)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_reserve_in_serial_id",
- &ppr->last_reserve_in_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_out_serial_id",
- &ppr->last_reserve_out_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_recoup_serial_id",
- &ppr->last_reserve_recoup_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_close_serial_id",
- &ppr->last_reserve_close_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_merges_serial_id",
- &ppr->last_purse_merges_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_deposits_serial_id",
- &ppr->last_purse_deposits_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_account_merges_serial_id",
- &ppr->last_account_merges_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_history_requests_serial_id",
- &ppr->last_history_requests_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_close_requests_serial_id",
- &ppr->last_close_requests_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_reserve",
- params,
- rs);
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppa->last_wire_out_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_aggregation",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppa->last_wire_out_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_aggregation",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppa set to where the auditor is in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_auditor_progress_aggregation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointAggregation *ppa)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_wire_out_serial_id",
- &ppa->last_wire_out_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_aggregation",
- params,
- rs);
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_deposit_confirmation",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_deposit_confirmation",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppdc set to where the auditor is in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_auditor_progress_deposit_confirmation (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_deposit_confirmation_serial_id",
- &ppdc->last_deposit_confirmation_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_deposit_confirmation",
- params,
- rs);
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_uint64 (&ppc->last_withdraw_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_insert_coin",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ppc->last_withdraw_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_deposit_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_melt_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_refund_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_query_param_uint64 (&ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_progress_update_coin",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppc set to where the auditor is in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_auditor_progress_coin (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointCoin *ppc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_withdraw_serial_id",
- &ppc->last_withdraw_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_deposit_serial_id",
- &ppc->last_deposit_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_melt_serial_id",
- &ppc->last_melt_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_refund_serial_id",
- &ppc->last_refund_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_recoup_serial_id",
- &ppc->last_recoup_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_recoup_refresh_serial_id",
- &ppc->last_recoup_refresh_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_deposits_serial_id",
- &ppc->last_purse_deposits_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_purse_refunds_serial_id",
- &ppc->last_purse_refunds_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_progress_select_coin",
- params,
- rs);
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp how far are we in the auditor's tables
- * @param in_wire_off how far are we in the incoming wire transfers
- * @param out_wire_off how far are we in the outgoing wire transfers
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t in_wire_off,
- uint64_t out_wire_off)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&in_wire_off),
- GNUNET_PQ_query_param_uint64 (&out_wire_off),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_account_progress_insert",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @param in_wire_off how far are we in the incoming wire transaction history
- * @param out_wire_off how far are we in the outgoing wire transaction history
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t in_wire_off,
- uint64_t out_wire_off)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_in_serial_id),
- GNUNET_PQ_query_param_uint64 (&pp->last_wire_out_serial_id),
- GNUNET_PQ_query_param_uint64 (&in_wire_off),
- GNUNET_PQ_query_param_uint64 (&out_wire_off),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_account_progress_update",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param[out] pp where is the auditor in processing
- * @param[out] in_wire_off how far are we in the incoming wire transaction history
- * @param[out] out_wire_off how far are we in the outgoing wire transaction history
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_auditor_account_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t *in_wire_off,
- uint64_t *out_wire_off)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("last_wire_reserve_in_serial_id",
- &pp->last_reserve_in_serial_id),
- GNUNET_PQ_result_spec_uint64 ("last_wire_wire_out_serial_id",
- &pp->last_wire_out_serial_id),
- GNUNET_PQ_result_spec_uint64 ("wire_in_off",
- in_wire_off),
- GNUNET_PQ_result_spec_uint64 ("wire_out_off",
- out_wire_off),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "wire_auditor_account_progress_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param pp where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_timestamp (&pp->last_timestamp),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_close_uuid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_progress_insert",
- params);
-}
-
-
-/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param pp where is the auditor in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&pp->last_timestamp),
- GNUNET_PQ_query_param_uint64 (&pp->last_reserve_close_uuid),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_auditor_progress_update",
- params);
-}
-
-
-/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] pp set to where the auditor is in processing
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_auditor_progress (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_WireProgressPoint *pp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_timestamp",
- &pp->last_timestamp),
- GNUNET_PQ_result_spec_uint64 ("last_reserve_close_uuid",
- &pp->last_reserve_close_uuid),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "wire_auditor_progress_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about a reserve. There must not be an
- * existing record for the reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
- * @param expiration_date expiration date of the reserve
- * @param origin_account where did the money in the reserve originally come from
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp expiration_date,
- const char *origin_account)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (reserve_balance),
- TALER_PQ_query_param_amount (withdraw_fee_balance),
- GNUNET_PQ_query_param_timestamp (&expiration_date),
- GNUNET_PQ_query_param_string (origin_account),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (reserve_balance,
- withdraw_fee_balance));
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_insert",
- params);
-}
-
-
-/**
- * Update information about a reserve. Destructively updates an
- * existing record, which must already exist.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
- * @param expiration_date expiration date of the reserve
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp expiration_date)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (reserve_balance),
- TALER_PQ_query_param_amount (withdraw_fee_balance),
- GNUNET_PQ_query_param_timestamp (&expiration_date),
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (reserve_balance,
- withdraw_fee_balance));
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_update",
- params);
-}
-
-
-/**
- * Delete information about a reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_del_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserves_delete",
- params);
-}
-
-
-/**
- * Get information about a reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @param[out] rowid which row did we get the information from
- * @param[out] reserve_balance amount stored in the reserve
- * @param[out] withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
- * @param[out] expiration_date expiration date of the reserve
- * @param[out] sender_account from where did the money in the reserve originally come from
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_info (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t *rowid,
- struct TALER_Amount *reserve_balance,
- struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp *expiration_date,
- char **sender_account)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance", reserve_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance", withdraw_fee_balance),
- GNUNET_PQ_result_spec_timestamp ("expiration_date", expiration_date),
- GNUNET_PQ_result_spec_uint64 ("auditor_reserves_rowid", rowid),
- GNUNET_PQ_result_spec_string ("origin_account", sender_account),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_reserves_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about all reserves. There must not be an
- * existing record for the @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * @param purse_fee_balance amount the exchange gained in purse fees
- * @param history_fee_balance amount the exchange gained in history fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- const struct TALER_Amount *purse_fee_balance,
- const struct TALER_Amount *history_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (reserve_balance),
- TALER_PQ_query_param_amount (withdraw_fee_balance),
- TALER_PQ_query_param_amount (purse_fee_balance),
- TALER_PQ_query_param_amount (history_fee_balance),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (reserve_balance,
- withdraw_fee_balance));
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserve_balance_insert",
- params);
-}
-
-
-/**
- * Update information about all reserves. Destructively updates an
- * existing record, which must already exist.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
- * @param purse_fee_balance amount the exchange gained in purse fees
- * @param history_fee_balance amount the exchange gained in history fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_reserve_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- const struct TALER_Amount *purse_fee_balance,
- const struct TALER_Amount *history_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (reserve_balance),
- TALER_PQ_query_param_amount (withdraw_fee_balance),
- TALER_PQ_query_param_amount (purse_fee_balance),
- TALER_PQ_query_param_amount (history_fee_balance),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_reserve_balance_update",
- params);
-}
-
-
-/**
- * Get summary information about all reserves.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] reserve_balance amount stored in reserves
- * @param[out] withdraw_fee_balance amount the exchange gained in withdraw fees
- * @param[out] purse_fee_balance amount the exchange gained in purse fees
- * @param[out] history_fee_balance amount the exchange gained in history fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *reserve_balance,
- struct TALER_Amount *withdraw_fee_balance,
- struct TALER_Amount *purse_fee_balance,
- struct TALER_Amount *history_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance", reserve_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("withdraw_fee_balance", withdraw_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee_balance", purse_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee_balance", history_fee_balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_reserve_balance_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about exchange's wire fee balance. There must not be an
- * existing record for the same @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param wire_fee_balance amount the exchange gained in wire fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_wire_fee_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (wire_fee_balance),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_wire_fee_balance_insert",
- params);
-}
-
-
-/**
- * Insert information about exchange's wire fee balance. Destructively updates an
- * existing record, which must already exist.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param wire_fee_balance amount the exchange gained in wire fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_wire_fee_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (wire_fee_balance),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_wire_fee_balance_update",
- params);
-}
-
-
-/**
- * Get summary information about an exchanges wire fee balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] wire_fee_balance set amount the exchange gained in wire fees
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_fee_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *wire_fee_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee_balance",
- wire_fee_balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_wire_fee_balance_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about a denomination key's balances. There
- * must not be an existing record for the denomination key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the denomination public key
- * @param denom_balance value of coins outstanding with this denomination key
- * @param denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
- * @param denom_risk value of coins issued with this denomination key
- * @param recoup_loss losses from recoup (if this denomination was revoked)
- * @param num_issued how many coins of this denomination did the exchange blind-sign
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_denomination_balance (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *denom_loss,
- const struct TALER_Amount *denom_risk,
- const struct TALER_Amount *recoup_loss,
- uint64_t num_issued)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- TALER_PQ_query_param_amount (denom_balance),
- TALER_PQ_query_param_amount (denom_loss),
- GNUNET_PQ_query_param_uint64 (&num_issued),
- TALER_PQ_query_param_amount (denom_risk),
- TALER_PQ_query_param_amount (recoup_loss),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_denomination_pending_insert",
- params);
-}
-
-
-/**
- * Update information about a denomination key's balances. There
- * must be an existing record for the denomination key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the denomination public key
- * @param denom_balance value of coins outstanding with this denomination key
- * @param denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
-* @param denom_risk value of coins issued with this denomination key
- * @param recoup_loss losses from recoup (if this denomination was revoked)
- * @param num_issued how many coins of this denomination did the exchange blind-sign
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_denomination_balance (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *denom_loss,
- const struct TALER_Amount *denom_risk,
- const struct TALER_Amount *recoup_loss,
- uint64_t num_issued)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (denom_balance),
- TALER_PQ_query_param_amount (denom_loss),
- GNUNET_PQ_query_param_uint64 (&num_issued),
- TALER_PQ_query_param_amount (denom_risk),
- TALER_PQ_query_param_amount (recoup_loss),
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_denomination_pending_update",
- params);
-}
-
-
-/**
- * Get information about a denomination key's balances.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the denomination public key
- * @param[out] denom_balance value of coins outstanding with this denomination key
- * @param[out] denom_risk value of coins issued with this denomination key
- * @param[out] denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
- * @param[out] recoup_loss losses from recoup (if this denomination was revoked)
- * @param[out] num_issued how many coins of this denomination did the exchange blind-sign
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_denomination_balance (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct TALER_Amount *denom_balance,
- struct TALER_Amount *denom_loss,
- struct TALER_Amount *denom_risk,
- struct TALER_Amount *recoup_loss,
- uint64_t *num_issued)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", denom_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_loss", denom_loss),
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_risk", denom_risk),
- TALER_PQ_RESULT_SPEC_AMOUNT ("recoup_loss", recoup_loss),
- GNUNET_PQ_result_spec_uint64 ("num_issued", num_issued),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_denomination_pending_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about an exchange's denomination balances. There
- * must not be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param denom_balance value of coins outstanding with this denomination key
- * @param deposit_fee_balance total deposit fees collected for this DK
- * @param melt_fee_balance total melt fees collected for this DK
- * @param refund_fee_balance total refund fees collected for this DK
- * @param risk maximum risk exposure of the exchange
- * @param loss materialized @a risk from recoup
- * @param irregular_recoup recoups on non-revoked coins
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk,
- const struct TALER_Amount *loss,
- const struct TALER_Amount *irregular_recoup)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (denom_balance),
- TALER_PQ_query_param_amount (deposit_fee_balance),
- TALER_PQ_query_param_amount (melt_fee_balance),
- TALER_PQ_query_param_amount (refund_fee_balance),
- TALER_PQ_query_param_amount (risk),
- TALER_PQ_query_param_amount (loss),
- TALER_PQ_query_param_amount (irregular_recoup),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (denom_balance,
- deposit_fee_balance));
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (denom_balance,
- melt_fee_balance));
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (denom_balance,
- refund_fee_balance));
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_summary_insert",
- params);
-}
-
-
-/**
- * Update information about an exchange's denomination balances. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param denom_balance value of coins outstanding with this denomination key
- * @param deposit_fee_balance total deposit fees collected for this DK
- * @param melt_fee_balance total melt fees collected for this DK
- * @param refund_fee_balance total refund fees collected for this DK
- * @param risk maximum risk exposure of the exchange
- * @param loss materialized @a risk from recoup
- * @param irregular_recoup recoups made on non-revoked coins
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_balance_summary (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk,
- const struct TALER_Amount *loss,
- const struct TALER_Amount *irregular_recoup)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (denom_balance),
- TALER_PQ_query_param_amount (deposit_fee_balance),
- TALER_PQ_query_param_amount (melt_fee_balance),
- TALER_PQ_query_param_amount (refund_fee_balance),
- TALER_PQ_query_param_amount (risk),
- TALER_PQ_query_param_amount (loss),
- TALER_PQ_query_param_amount (irregular_recoup),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_balance_summary_update",
- params);
-}
-
-
-/**
- * Get information about an exchange's denomination balances.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] denom_balance value of coins outstanding with this denomination key
- * @param[out] deposit_fee_balance total deposit fees collected for this DK
- * @param[out] melt_fee_balance total melt fees collected for this DK
- * @param[out] refund_fee_balance total refund fees collected for this DK
- * @param[out] risk maximum risk exposure of the exchange
- * @param[out] loss losses from recoup (on revoked denominations)
- * @param[out] irregular_recoup recoups on NOT revoked denominations
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_balance_summary (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *denom_balance,
- struct TALER_Amount *deposit_fee_balance,
- struct TALER_Amount *melt_fee_balance,
- struct TALER_Amount *refund_fee_balance,
- struct TALER_Amount *risk,
- struct TALER_Amount *loss,
- struct TALER_Amount *irregular_recoup)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("denom_balance", denom_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee_balance", deposit_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("melt_fee_balance", melt_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("refund_fee_balance", refund_fee_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("risk", risk),
- TALER_PQ_RESULT_SPEC_AMOUNT ("loss", loss),
- TALER_PQ_RESULT_SPEC_AMOUNT ("irregular_recoup", irregular_recoup),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_balance_summary_select",
- params,
- rs);
-}
-
-
-/**
- * Insert information about an exchange's historic
- * revenue about a denomination key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param denom_pub_hash hash of the denomination key
- * @param revenue_timestamp when did this profit get realized
- * @param revenue_balance what was the total profit made from
- * deposit fees, melting fees, refresh fees
- * and coins that were never returned?
- * @param loss_balance total losses suffered by the exchange at the time
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_historic_denom_revenue (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct GNUNET_TIME_Timestamp revenue_timestamp,
- const struct TALER_Amount *revenue_balance,
- const struct TALER_Amount *loss_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_timestamp (&revenue_timestamp),
- TALER_PQ_query_param_amount (revenue_balance),
- TALER_PQ_query_param_amount (loss_balance),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_historic_denomination_revenue_insert",
- params);
-}
-
-
-/**
- * Closure for #historic_denom_revenue_cb().
- */
-struct HistoricDenomRevenueContext
-{
- /**
- * Function to call for each result.
- */
- TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Number of results processed.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #postgres_select_historic_denom_revenue().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct HistoricRevenueContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-historic_denom_revenue_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct HistoricDenomRevenueContext *hrc = cls;
- struct PostgresClosure *pg = hrc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_DenominationHashP denom_pub_hash;
- struct GNUNET_TIME_Timestamp revenue_timestamp;
- struct TALER_Amount revenue_balance;
- struct TALER_Amount loss;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &denom_pub_hash),
- GNUNET_PQ_result_spec_timestamp ("revenue_timestamp",
- &revenue_timestamp),
- TALER_PQ_RESULT_SPEC_AMOUNT ("revenue_balance",
- &revenue_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("loss_balance",
- &loss),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
-
- hrc->qs = i + 1;
- if (GNUNET_OK !=
- hrc->cb (hrc->cb_cls,
- &denom_pub_hash,
- revenue_timestamp,
- &revenue_balance,
- &loss))
- break;
- }
-}
-
-
-/**
- * Obtain all of the historic denomination key revenue
- * of the given @a master_pub.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_historic_denom_revenue (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct HistoricDenomRevenueContext hrc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_historic_denomination_revenue_select",
- params,
- &historic_denom_revenue_cb,
- &hrc);
- if (qs <= 0)
- return qs;
- return hrc.qs;
-}
-
-
-/**
- * Insert information about an exchange's historic revenue from reserves.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param start_time beginning of aggregated time interval
- * @param end_time end of aggregated time interval
- * @param reserve_profits total profits made
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_historic_reserve_revenue (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- const struct TALER_Amount *reserve_profits)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_timestamp (&start_time),
- GNUNET_PQ_query_param_timestamp (&end_time),
- TALER_PQ_query_param_amount (reserve_profits),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_historic_reserve_summary_insert",
- params);
-}
-
-
-/**
- * Closure for #historic_reserve_revenue_cb().
- */
-struct HistoricReserveRevenueContext
-{
- /**
- * Function to call for each result.
- */
- TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Number of results processed.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Helper function for #postgres_select_historic_reserve_revenue().
- * To be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct HistoricRevenueContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-historic_reserve_revenue_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct HistoricReserveRevenueContext *hrc = cls;
- struct PostgresClosure *pg = hrc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_Amount reserve_profits;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_profits",
- &reserve_profits),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- hrc->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- hrc->qs = i + 1;
- if (GNUNET_OK !=
- hrc->cb (hrc->cb_cls,
- start_date,
- end_date,
- &reserve_profits))
- break;
- }
-}
-
-
-/**
- * Return information about an exchange's historic revenue from reserves.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_historic_reserve_revenue (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct HistoricReserveRevenueContext hrc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "auditor_historic_reserve_summary_select",
- params,
- &historic_reserve_revenue_cb,
- &hrc);
- if (0 >= qs)
- return qs;
- return hrc.qs;
-}
-
-
-/**
- * Insert information about the predicted exchange's bank
- * account balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- TALER_PQ_query_param_amount (balance),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_predicted_result_insert",
- params);
-}
-
-
-/**
- * Update information about an exchange's predicted balance. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_predicted_result (
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (balance),
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "auditor_predicted_result_update",
- params);
-}
-
-
-/**
- * Get an exchange's predicted balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] balance expected bank account balance of the exchange
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_predicted_balance (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "auditor_predicted_result_select",
- params,
- rs);
-}
-
-
-/**
* Initialize Postgres database subsystem.
*
* @param cls a configuration instance
@@ -2925,83 +454,81 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
plugin->preflight = &postgres_preflight;
plugin->drop_tables = &postgres_drop_tables;
plugin->create_tables = &postgres_create_tables;
+ plugin->event_listen = &postgres_event_listen;
+ plugin->event_listen_cancel = &postgres_event_listen_cancel;
+ plugin->event_notify = &postgres_event_notify;
plugin->start = &postgres_start;
plugin->commit = &postgres_commit;
plugin->rollback = &postgres_rollback;
plugin->gc = &postgres_gc;
- plugin->insert_exchange = &postgres_insert_exchange;
- plugin->delete_exchange = &postgres_delete_exchange;
- plugin->list_exchanges = &postgres_list_exchanges;
- plugin->insert_exchange_signkey = &postgres_insert_exchange_signkey;
- plugin->insert_deposit_confirmation = &postgres_insert_deposit_confirmation;
- plugin->get_deposit_confirmations = &postgres_get_deposit_confirmations;
-
- plugin->get_auditor_progress_reserve = &postgres_get_auditor_progress_reserve;
- plugin->update_auditor_progress_reserve =
- &postgres_update_auditor_progress_reserve;
- plugin->insert_auditor_progress_reserve =
- &postgres_insert_auditor_progress_reserve;
- plugin->get_auditor_progress_aggregation =
- &postgres_get_auditor_progress_aggregation;
- plugin->update_auditor_progress_aggregation =
- &postgres_update_auditor_progress_aggregation;
- plugin->insert_auditor_progress_aggregation =
- &postgres_insert_auditor_progress_aggregation;
- plugin->get_auditor_progress_deposit_confirmation =
- &postgres_get_auditor_progress_deposit_confirmation;
- plugin->update_auditor_progress_deposit_confirmation =
- &postgres_update_auditor_progress_deposit_confirmation;
- plugin->insert_auditor_progress_deposit_confirmation =
- &postgres_insert_auditor_progress_deposit_confirmation;
- plugin->get_auditor_progress_coin = &postgres_get_auditor_progress_coin;
- plugin->update_auditor_progress_coin = &postgres_update_auditor_progress_coin;
- plugin->insert_auditor_progress_coin = &postgres_insert_auditor_progress_coin;
-
- plugin->get_wire_auditor_account_progress =
- &postgres_get_wire_auditor_account_progress;
- plugin->update_wire_auditor_account_progress =
- &postgres_update_wire_auditor_account_progress;
- plugin->insert_wire_auditor_account_progress =
- &postgres_insert_wire_auditor_account_progress;
- plugin->get_wire_auditor_progress = &postgres_get_wire_auditor_progress;
- plugin->update_wire_auditor_progress = &postgres_update_wire_auditor_progress;
- plugin->insert_wire_auditor_progress = &postgres_insert_wire_auditor_progress;
-
- plugin->del_reserve_info = &postgres_del_reserve_info;
- plugin->get_reserve_info = &postgres_get_reserve_info;
- plugin->update_reserve_info = &postgres_update_reserve_info;
- plugin->insert_reserve_info = &postgres_insert_reserve_info;
-
- plugin->get_reserve_summary = &postgres_get_reserve_summary;
- plugin->update_reserve_summary = &postgres_update_reserve_summary;
- plugin->insert_reserve_summary = &postgres_insert_reserve_summary;
-
- plugin->get_wire_fee_summary = &postgres_get_wire_fee_summary;
- plugin->update_wire_fee_summary = &postgres_update_wire_fee_summary;
- plugin->insert_wire_fee_summary = &postgres_insert_wire_fee_summary;
-
- plugin->get_denomination_balance = &postgres_get_denomination_balance;
- plugin->update_denomination_balance = &postgres_update_denomination_balance;
- plugin->insert_denomination_balance = &postgres_insert_denomination_balance;
-
- plugin->get_balance_summary = &postgres_get_balance_summary;
- plugin->update_balance_summary = &postgres_update_balance_summary;
- plugin->insert_balance_summary = &postgres_insert_balance_summary;
-
- plugin->select_historic_denom_revenue =
- &postgres_select_historic_denom_revenue;
- plugin->insert_historic_denom_revenue =
- &postgres_insert_historic_denom_revenue;
-
- plugin->select_historic_reserve_revenue =
- &postgres_select_historic_reserve_revenue;
- plugin->insert_historic_reserve_revenue =
- &postgres_insert_historic_reserve_revenue;
-
- plugin->get_predicted_balance = &postgres_get_predicted_balance;
- plugin->update_predicted_result = &postgres_update_predicted_result;
- plugin->insert_predicted_result = &postgres_insert_predicted_result;
+ plugin->get_auditor_progress
+ = &TAH_PG_get_auditor_progress;
+ plugin->get_balance
+ = &TAH_PG_get_balance;
+ plugin->insert_auditor_progress
+ = &TAH_PG_insert_auditor_progress;
+ plugin->insert_balance
+ = &TAH_PG_insert_balance;
+ plugin->update_auditor_progress
+ = &TAH_PG_update_auditor_progress;
+ plugin->update_balance
+ = &TAH_PG_update_balance;
+
+ plugin->insert_exchange_signkey
+ = &TAH_PG_insert_exchange_signkey;
+ plugin->insert_deposit_confirmation
+ = &TAH_PG_insert_deposit_confirmation;
+ plugin->get_deposit_confirmations
+ = &TAH_PG_get_deposit_confirmations;
+ plugin->delete_deposit_confirmation
+ = &TAH_PG_delete_deposit_confirmation;
+
+ plugin->insert_reserve_info
+ = &TAH_PG_insert_reserve_info;
+ plugin->update_reserve_info
+ = &TAH_PG_update_reserve_info;
+ plugin->get_reserve_info
+ = &TAH_PG_get_reserve_info;
+ plugin->del_reserve_info
+ = &TAH_PG_del_reserve_info;
+
+ plugin->insert_pending_deposit
+ = &TAH_PG_insert_pending_deposit;
+ plugin->select_pending_deposits
+ = &TAH_PG_select_pending_deposits;
+ plugin->delete_pending_deposit
+ = &TAH_PG_delete_pending_deposit;
+
+ plugin->insert_purse_info
+ = &TAH_PG_insert_purse_info;
+ plugin->update_purse_info
+ = &TAH_PG_update_purse_info;
+ plugin->get_purse_info
+ = &TAH_PG_get_purse_info;
+ plugin->delete_purse_info
+ = &TAH_PG_delete_purse_info;
+ plugin->select_purse_expired
+ = &TAH_PG_select_purse_expired;
+
+ plugin->insert_denomination_balance
+ = &TAH_PG_insert_denomination_balance;
+ plugin->update_denomination_balance
+ = &TAH_PG_update_denomination_balance;
+ plugin->del_denomination_balance
+ = &TAH_PG_del_denomination_balance;
+ plugin->get_denomination_balance
+ = &TAH_PG_get_denomination_balance;
+
+ plugin->insert_historic_denom_revenue
+ = &TAH_PG_insert_historic_denom_revenue;
+ plugin->select_historic_denom_revenue
+ = &TAH_PG_select_historic_denom_revenue;
+
+ plugin->insert_historic_reserve_revenue
+ = &TAH_PG_insert_historic_reserve_revenue;
+ plugin->select_historic_reserve_revenue
+ = &TAH_PG_select_historic_reserve_revenue;
return plugin;
}
diff --git a/src/exchangedb/drop0001-shard-part.sql b/src/auditordb/procedures.sql.in
index 9cf3eeb3a..0c83bdb5e 100644
--- a/src/exchangedb/drop0001-shard-part.sql
+++ b/src/auditordb/procedures.sql.in
@@ -1,6 +1,6 @@
--
-- This file is part of TALER
--- Copyright (C) 2014--2021 Taler Systems SA
+-- Copyright (C) 2024 Taler Systems SA
--
-- TALER is free software; you can redistribute it and/or modify it under the
-- terms of the GNU General Public License as published by the Free Software
@@ -16,12 +16,9 @@
BEGIN;
--- Unregister patch (shard-0001.sql)
-SELECT _v.unregister_patch('shard-0001');
+SET search_path TO auditor;
--- Drops for shard-0001-part.sql
-
-DROP FUNCTION IF EXISTS drop_shard;
-DROP FUNCTION IF EXISTS setup_shard;
+#include "auditor_do_get_auditor_progress.sql"
+#include "auditor_do_get_balance.sql"
COMMIT;
diff --git a/src/auditordb/restart0001.sql b/src/auditordb/restart.sql
index 90bb59551..2dc6864ff 100644
--- a/src/auditordb/restart0001.sql
+++ b/src/auditordb/restart.sql
@@ -17,6 +17,8 @@
-- Everything in one big transaction
BEGIN;
+SET search_path TO auditor;
+
-- This script restart the auditor state as done to RESTART
-- an audit from scratch. It does NOT drop tables and also
-- PRESERVES data that running the auditor would not recover,
@@ -29,20 +31,14 @@ BEGIN;
-- Unlike the other SQL files, it SHOULD be updated to reflect the
-- latest requirements for dropping tables.
-DELETE FROM auditor_predicted_result;
-DELETE FROM auditor_historic_denomination_revenue;
-DELETE FROM auditor_balance_summary;
+DELETE FROM auditor_amount_arithmetic_inconsistency;
+DELETE FROM auditor_balances;
DELETE FROM auditor_denomination_pending;
-DELETE FROM auditor_reserve_balance;
-DELETE FROM auditor_wire_fee_balance;
-DELETE FROM auditor_reserves;
-DELETE FROM auditor_progress_reserve;
-DELETE FROM auditor_progress_aggregation;
-DELETE FROM auditor_progress_deposit_confirmation;
-DELETE FROM auditor_progress_coin;
-DELETE FROM wire_auditor_progress;
-DELETE FROM wire_auditor_account_progress;
+DELETE FROM auditor_historic_denomination_revenue;
DELETE FROM auditor_historic_reserve_summary;
+DELETE FROM auditor_progress;
+DELETE FROM auditor_purses;
+DELETE FROM auditor_reserves;
-- And we're out of here...
COMMIT;
diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c
index f2fad2bc6..5184722f0 100644
--- a/src/auditordb/test_auditordb.c
+++ b/src/auditordb/test_auditordb.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016 Taler Systems SA
+ Copyright (C) 2016--2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -17,17 +17,17 @@
* @file auditordb/test_auditordb.c
* @brief test cases for DB interaction functions
* @author Gabor X Toth
+ * @author Christian Grothoff
*/
#include "platform.h"
#include <gnunet/gnunet_db_lib.h>
#include "taler_auditordb_lib.h"
#include "taler_auditordb_plugin.h"
-
/**
- * Global result from the testcase.
+ * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
*/
-static int result = -1;
+#define CURRENCY "EUR"
/**
* Report line of error if @a cond is true, and jump to label "drop".
@@ -39,7 +39,6 @@ static int result = -1;
goto drop; \
} while (0)
-
/**
* Initializes @a ptr with random data.
*/
@@ -54,15 +53,124 @@ static int result = -1;
/**
- * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
+ * Global result from the testcase.
*/
-#define CURRENCY "EUR"
+static int result = -1;
+
+/**
+ * Hash of denomination public key.
+ */
+static struct TALER_DenominationHashP denom_pub_hash;
+
+/**
+ * Another hash of a denomination public key.
+ */
+static struct TALER_DenominationHashP rnd_hash;
+
+/**
+ * Current time.
+ */
+static struct GNUNET_TIME_Timestamp now;
+
+/**
+ * Timestamp in the past.
+ */
+static struct GNUNET_TIME_Timestamp past;
+
+/**
+ * Timestamp in the future.
+ */
+static struct GNUNET_TIME_Timestamp future;
/**
* Database plugin under test.
*/
static struct TALER_AUDITORDB_Plugin *plugin;
+/**
+ * Historic denomination revenue value.
+ */
+static struct TALER_Amount rbalance;
+
+/**
+ * Historic denomination loss value.
+ */
+static struct TALER_Amount rloss;
+
+/**
+ * Reserve profit value we are using.
+ */
+static struct TALER_Amount reserve_profits;
+
+
+static enum GNUNET_GenericReturnValue
+select_historic_denom_revenue_result (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash2,
+ struct GNUNET_TIME_Timestamp revenue_timestamp2,
+ const struct TALER_Amount *revenue_balance2,
+ const struct TALER_Amount *loss2)
+{
+ static int n = 0;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "select_historic_denom_revenue_result: row %u\n", n);
+
+ if ( (2 <= n++)
+ || (cls != NULL)
+ || ((0 != GNUNET_memcmp (&revenue_timestamp2,
+ &past))
+ && (0 != GNUNET_memcmp (&revenue_timestamp2,
+ &now)))
+ || ((0 != GNUNET_memcmp (denom_pub_hash2,
+ &denom_pub_hash))
+ && (0 != GNUNET_memcmp (denom_pub_hash2,
+ &rnd_hash)))
+ || (0 != TALER_amount_cmp (revenue_balance2,
+ &rbalance))
+ || (0 != TALER_amount_cmp (loss2,
+ &rloss)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "select_historic_denom_revenue_result: result does not match\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+static enum GNUNET_GenericReturnValue
+select_historic_reserve_revenue_result (
+ void *cls,
+ struct GNUNET_TIME_Timestamp start_time2,
+ struct GNUNET_TIME_Timestamp end_time2,
+ const struct TALER_Amount *reserve_profits2)
+{
+ static int n = 0;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "select_historic_reserve_revenue_result: row %u\n", n);
+
+ if ((2 <= n++)
+ || (cls != NULL)
+ || ((0 != GNUNET_memcmp (&start_time2,
+ &past))
+ && (0 != GNUNET_memcmp (&start_time2,
+ &now)))
+ || (0 != GNUNET_memcmp (&end_time2,
+ &future))
+ || (0 != TALER_amount_cmp (reserve_profits2,
+ &reserve_profits)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "select_historic_reserve_revenue_result: result does not match\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
/**
* Main function that will be run by the scheduler.
@@ -88,7 +196,9 @@ run (void *cls)
(void) plugin->drop_tables (plugin->cls,
GNUNET_YES);
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls))
+ plugin->create_tables (plugin->cls,
+ false,
+ 0))
{
result = 77;
goto unload;
@@ -128,24 +238,17 @@ run (void *cls)
TALER_string_to_amount (CURRENCY ":0.000014",
&fee_refund));
- struct TALER_MasterPublicKeyP master_pub;
struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_DenominationHashP rnd_hash;
struct TALER_DenominationPrivateKey denom_priv;
struct TALER_DenominationPublicKey denom_pub;
- struct TALER_DenominationHashP denom_pub_hash;
- struct GNUNET_TIME_Timestamp now;
- struct GNUNET_TIME_Timestamp past;
- struct GNUNET_TIME_Timestamp future;
struct GNUNET_TIME_Timestamp date;
- RND_BLK (&master_pub);
RND_BLK (&reserve_pub);
RND_BLK (&rnd_hash);
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&denom_priv,
&denom_pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
TALER_denom_pub_hash (&denom_pub,
&denom_pub_hash);
@@ -164,512 +267,182 @@ run (void *cls)
GNUNET_TIME_UNIT_HOURS,
4)));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: auditor_insert_exchange\n");
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_exchange (plugin->cls,
- &master_pub,
- "https://exchange/"));
-
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_auditor_progress\n");
-
- struct TALER_AUDITORDB_ProgressPointCoin ppc = {
- .last_deposit_serial_id = 123,
- .last_melt_serial_id = 456,
- .last_refund_serial_id = 789,
- .last_withdraw_serial_id = 555
- };
- struct TALER_AUDITORDB_ProgressPointCoin ppc2 = {
- .last_deposit_serial_id = 0,
- .last_melt_serial_id = 0,
- .last_refund_serial_id = 0,
- .last_withdraw_serial_id = 0
- };
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_auditor_progress\n");
-
- ppc.last_deposit_serial_id++;
- ppc.last_melt_serial_id++;
- ppc.last_refund_serial_id++;
- ppc.last_withdraw_serial_id++;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_auditor_progress\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_auditor_progress_coin (plugin->cls,
- &master_pub,
- &ppc2));
- FAILIF ( (ppc.last_deposit_serial_id != ppc2.last_deposit_serial_id) ||
- (ppc.last_melt_serial_id != ppc2.last_melt_serial_id) ||
- (ppc.last_refund_serial_id != ppc2.last_refund_serial_id) ||
- (ppc.last_withdraw_serial_id != ppc2.last_withdraw_serial_id) );
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_reserve_info\n");
-
- struct TALER_Amount reserve_balance;
- struct TALER_Amount withdraw_fee_balance;
- struct TALER_Amount purse_fee_balance;
- struct TALER_Amount history_fee_balance;
- struct TALER_Amount reserve_balance2 = {};
- struct TALER_Amount withdraw_fee_balance2 = {};
- struct TALER_Amount purse_fee_balance2 = {};
- struct TALER_Amount history_fee_balance2 = {};
-
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":12.345678",
- &reserve_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":23.456789",
- &withdraw_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":23.456789",
- &purse_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":23.456789",
- &history_fee_balance));
-
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_reserve_info (plugin->cls,
- &reserve_pub,
- &master_pub,
- &reserve_balance,
- &withdraw_fee_balance,
- past,
- "payto://bla/blub"));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_reserve_info\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_reserve_info (plugin->cls,
- &reserve_pub,
- &master_pub,
- &reserve_balance,
- &withdraw_fee_balance,
- future));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_reserve_info\n");
-
- char *payto;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_reserve_info (plugin->cls,
- &reserve_pub,
- &master_pub,
- &rowid,
- &reserve_balance2,
- &withdraw_fee_balance2,
- &date,
- &payto));
- FAILIF (0 != strcmp (payto,
- "payto://bla/blub"));
- GNUNET_free (payto);
- FAILIF (0 != GNUNET_memcmp (&date,
- &future)
- || 0 != TALER_amount_cmp (&reserve_balance2,
- &reserve_balance)
- || 0 != TALER_amount_cmp (&withdraw_fee_balance2,
- &withdraw_fee_balance));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_reserve_summary\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_reserve_summary (plugin->cls,
- &master_pub,
- &reserve_balance,
- &withdraw_fee_balance,
- &purse_fee_balance,
- &history_fee_balance));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_reserve_summary\n");
+ {
+ struct TALER_AUDITORDB_ReserveFeeBalance rfb;
+ struct TALER_AUDITORDB_ReserveFeeBalance rfb2;
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_reserve_summary (plugin->cls,
- &master_pub,
- &reserve_balance,
- &withdraw_fee_balance,
- &purse_fee_balance,
- &history_fee_balance));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: insert_reserve_info\n");
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":12.345678",
+ &rfb.reserve_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":11.245678",
+ &rfb.reserve_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":23.456789",
+ &rfb.withdraw_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":23.456719",
+ &rfb.close_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":33.456789",
+ &rfb.purse_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":43.456789",
+ &rfb.open_fee_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":53.456789",
+ &rfb.history_fee_balance));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_reserve_info (plugin->cls,
+ &reserve_pub,
+ &rfb,
+ past,
+ "payto://bla/blub"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: update_reserve_info\n");
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->update_reserve_info (plugin->cls,
+ &reserve_pub,
+ &rfb,
+ future));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: get_reserve_info\n");
+ {
+ char *payto;
+
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_reserve_info (plugin->cls,
+ &reserve_pub,
+ &rowid,
+ &rfb2,
+ &date,
+ &payto));
+ FAILIF (0 != strcmp (payto,
+ "payto://bla/blub"));
+ GNUNET_free (payto);
+ }
+ FAILIF ( (0 != GNUNET_memcmp (&date,
+ &future))
+ || (0 != TALER_amount_cmp (&rfb2.reserve_balance,
+ &rfb.reserve_balance))
+ || (0 != TALER_amount_cmp (&rfb2.withdraw_fee_balance,
+ &rfb.withdraw_fee_balance))
+ || (0 != TALER_amount_cmp (&rfb2.close_fee_balance,
+ &rfb.close_fee_balance))
+ || (0 != TALER_amount_cmp (&rfb2.purse_fee_balance,
+ &rfb.purse_fee_balance))
+ || (0 != TALER_amount_cmp (&rfb2.open_fee_balance,
+ &rfb.open_fee_balance))
+ || (0 != TALER_amount_cmp (&rfb2.history_fee_balance,
+ &rfb.history_fee_balance))
+ );
+ }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_reserve_summary\n");
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: insert_denomination_balance\n");
+
+ struct TALER_AUDITORDB_DenominationCirculationData dcd;
+ struct TALER_AUDITORDB_DenominationCirculationData dcd2;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":12.345678",
+ &dcd.denom_balance));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.1",
+ &dcd.denom_loss));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":13.57986",
+ &dcd.denom_risk));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":12.57986",
+ &dcd.recoup_loss));
+ dcd.num_issued = 62;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_denomination_balance (plugin->cls,
+ &denom_pub_hash,
+ &dcd));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: update_denomination_balance\n");
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->update_denomination_balance (plugin->cls,
+ &denom_pub_hash,
+ &dcd));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Test: get_denomination_balance\n");
- ZR_BLK (&reserve_balance2);
- ZR_BLK (&withdraw_fee_balance2);
- ZR_BLK (&purse_fee_balance2);
- ZR_BLK (&history_fee_balance2);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_denomination_balance (plugin->cls,
+ &denom_pub_hash,
+ &dcd2));
+ FAILIF (0 != TALER_amount_cmp (&dcd2.denom_balance,
+ &dcd.denom_balance));
+ FAILIF (0 != TALER_amount_cmp (&dcd2.denom_loss,
+ &dcd.denom_loss));
+ FAILIF (0 != TALER_amount_cmp (&dcd2.denom_risk,
+ &dcd.denom_risk));
+ FAILIF (0 != TALER_amount_cmp (&dcd2.recoup_loss,
+ &dcd.recoup_loss));
+ FAILIF (dcd2.num_issued != dcd.num_issued);
+ }
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_reserve_summary (plugin->cls,
- &master_pub,
- &reserve_balance2,
- &withdraw_fee_balance2,
- &purse_fee_balance2,
- &history_fee_balance2));
-
- FAILIF ( (0 != TALER_amount_cmp (&reserve_balance2,
- &reserve_balance) ||
- (0 != TALER_amount_cmp (&withdraw_fee_balance2,
- &withdraw_fee_balance)) ||
- (0 != TALER_amount_cmp (&purse_fee_balance2,
- &purse_fee_balance)) ||
- (0 != TALER_amount_cmp (&history_fee_balance2,
- &history_fee_balance))));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_denomination_balance\n");
-
- struct TALER_Amount denom_balance;
- struct TALER_Amount denom_loss;
- struct TALER_Amount denom_loss2;
- struct TALER_Amount deposit_fee_balance;
- struct TALER_Amount melt_fee_balance;
- struct TALER_Amount refund_fee_balance;
- struct TALER_Amount denom_balance2;
- struct TALER_Amount deposit_fee_balance2;
- struct TALER_Amount melt_fee_balance2;
- struct TALER_Amount refund_fee_balance2;
- struct TALER_Amount rbalance;
- struct TALER_Amount rbalance2;
- struct TALER_Amount loss;
- struct TALER_Amount loss2;
- struct TALER_Amount iirp;
- struct TALER_Amount iirp2;
- uint64_t nissued;
-
+ "Test: insert_historic_denom_revenue\n");
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":12.345678",
- &denom_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":0.1",
- &denom_loss));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":23.456789",
- &deposit_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":34.567890",
- &melt_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":45.678901",
- &refund_fee_balance));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":13.57986",
&rbalance));
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.6",
- &loss));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":1.1",
- &iirp));
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_denomination_balance (plugin->cls,
- &denom_pub_hash,
- &denom_balance,
- &denom_loss,
- &rbalance,
- &loss,
- 42));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_denomination_balance\n");
-
- ppc.last_withdraw_serial_id++;
- ppc.last_deposit_serial_id++;
- ppc.last_melt_serial_id++;
- ppc.last_refund_serial_id++;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_denomination_balance (plugin->cls,
- &denom_pub_hash,
- &denom_balance,
- &denom_loss,
- &rbalance,
- &loss,
- 62));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_denomination_balance\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_denomination_balance (plugin->cls,
- &denom_pub_hash,
- &denom_balance2,
- &denom_loss2,
- &rbalance2,
- &loss2,
- &nissued));
-
- FAILIF (0 != GNUNET_memcmp (&denom_balance2, &denom_balance));
- FAILIF (0 != GNUNET_memcmp (&denom_loss2, &denom_loss));
- FAILIF (0 != GNUNET_memcmp (&rbalance2, &rbalance));
- FAILIF (62 != nissued);
-
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_balance_summary\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_balance_summary (plugin->cls,
- &master_pub,
- &refund_fee_balance,
- &melt_fee_balance,
- &deposit_fee_balance,
- &denom_balance,
- &rbalance,
- &loss,
- &iirp));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_balance_summary\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_balance_summary (plugin->cls,
- &master_pub,
- &denom_balance,
- &deposit_fee_balance,
- &melt_fee_balance,
- &refund_fee_balance,
- &rbalance,
- &loss,
- &iirp));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_balance_summary\n");
-
- ZR_BLK (&denom_balance2);
- ZR_BLK (&deposit_fee_balance2);
- ZR_BLK (&melt_fee_balance2);
- ZR_BLK (&refund_fee_balance2);
- ZR_BLK (&rbalance2);
- ZR_BLK (&loss2);
- ZR_BLK (&iirp2);
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_balance_summary (plugin->cls,
- &master_pub,
- &denom_balance2,
- &deposit_fee_balance2,
- &melt_fee_balance2,
- &refund_fee_balance2,
- &rbalance2,
- &loss2,
- &iirp2));
-
- FAILIF ( (0 != GNUNET_memcmp (&denom_balance2,
- &denom_balance) ) ||
- (0 != GNUNET_memcmp (&deposit_fee_balance2,
- &deposit_fee_balance) ) ||
- (0 != GNUNET_memcmp (&melt_fee_balance2,
- &melt_fee_balance) ) ||
- (0 != GNUNET_memcmp (&refund_fee_balance2,
- &refund_fee_balance)) );
- FAILIF (0 != GNUNET_memcmp (&rbalance2,
- &rbalance));
- FAILIF (0 != GNUNET_memcmp (&loss2,
- &loss));
- FAILIF (0 != GNUNET_memcmp (&iirp2,
- &iirp));
-
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_historic_denom_revenue\n");
-
+ TALER_string_to_amount (CURRENCY ":23.456789",
+ &rloss));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_denom_revenue (plugin->cls,
- &master_pub,
&denom_pub_hash,
past,
&rbalance,
- &loss));
-
+ &rloss));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_denom_revenue (plugin->cls,
- &master_pub,
&rnd_hash,
now,
&rbalance,
- &loss));
-
+ &rloss));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: select_historic_denom_revenue\n");
-
- int
- select_historic_denom_revenue_result (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash2,
- struct GNUNET_TIME_Timestamp revenue_timestamp2,
- const struct TALER_Amount *revenue_balance2,
- const struct TALER_Amount *loss2)
- {
- static int n = 0;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "select_historic_denom_revenue_result: row %u\n", n);
-
- if ((2 <= n++)
- || (cls != NULL)
- || ((0 != GNUNET_memcmp (&revenue_timestamp2, &past))
- && (0 != GNUNET_memcmp (&revenue_timestamp2, &now)))
- || ((0 != GNUNET_memcmp (denom_pub_hash2, &denom_pub_hash))
- && (0 != GNUNET_memcmp (denom_pub_hash2, &rnd_hash)))
- || (0 != GNUNET_memcmp (revenue_balance2, &rbalance))
- || (0 != GNUNET_memcmp (loss2, &loss)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "select_historic_denom_revenue_result: result does not match\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
-
-
FAILIF (0 >=
- plugin->select_historic_denom_revenue (plugin->cls,
- &master_pub,
- &
- select_historic_denom_revenue_result,
- NULL));
-
+ plugin->select_historic_denom_revenue (
+ plugin->cls,
+ &select_historic_denom_revenue_result,
+ NULL));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: insert_historic_reserve_revenue\n");
-
- struct TALER_Amount reserve_profits;
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":56.789012",
&reserve_profits));
-
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_reserve_revenue (plugin->cls,
- &master_pub,
past,
future,
&reserve_profits));
-
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_historic_reserve_revenue (plugin->cls,
- &master_pub,
now,
future,
&reserve_profits));
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Test: select_historic_reserve_revenue\n");
-
- int
- select_historic_reserve_revenue_result (
- void *cls,
- struct GNUNET_TIME_Timestamp start_time2,
- struct GNUNET_TIME_Timestamp end_time2,
- const struct TALER_Amount *reserve_profits2)
- {
- static int n = 0;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "select_historic_reserve_revenue_result: row %u\n", n);
-
- if ((2 <= n++)
- || (cls != NULL)
- || ((0 != GNUNET_memcmp (&start_time2, &past))
- && (0 != GNUNET_memcmp (&start_time2, &now)))
- || (0 != GNUNET_memcmp (&end_time2, &future))
- || (0 != GNUNET_memcmp (reserve_profits2, &reserve_profits)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "select_historic_reserve_revenue_result: result does not match\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- }
-
-
FAILIF (0 >=
plugin->select_historic_reserve_revenue (plugin->cls,
- &master_pub,
select_historic_reserve_revenue_result,
NULL));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: insert_predicted_result\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_predicted_result (plugin->cls,
- &master_pub,
- &rbalance));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: update_predicted_result\n");
-
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":78.901234",
- &rbalance));
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_predicted_result (plugin->cls,
- &master_pub,
- &rbalance));
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_wire_fee_summary (plugin->cls,
- &master_pub,
- &rbalance));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->update_wire_fee_summary (plugin->cls,
- &master_pub,
- &reserve_profits));
- {
- struct TALER_Amount rprof;
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_wire_fee_summary (plugin->cls,
- &master_pub,
- &rprof));
- FAILIF (0 !=
- TALER_amount_cmp (&rprof,
- &reserve_profits));
- }
FAILIF (0 >
plugin->commit (plugin->cls));
-
- FAILIF (GNUNET_OK !=
- plugin->start (plugin->cls));
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: get_predicted_balance\n");
-
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_predicted_balance (plugin->cls,
- &master_pub,
- &rbalance2));
-
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->del_reserve_info (plugin->cls,
- &reserve_pub,
- &master_pub));
-
- FAILIF (0 != TALER_amount_cmp (&rbalance2,
- &rbalance));
-
- plugin->rollback (plugin->cls);
+ &reserve_pub));
#if GC_IMPLEMENTED
FAILIF (GNUNET_OK !=
@@ -679,18 +452,7 @@ run (void *cls)
result = 0;
drop:
- {
- plugin->rollback (plugin->cls);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Test: auditor_delete_exchange\n");
- GNUNET_break (GNUNET_OK ==
- plugin->start (plugin->cls));
- GNUNET_break (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
- plugin->delete_exchange (plugin->cls,
- &master_pub));
- GNUNET_break (0 <=
- plugin->commit (plugin->cls));
- }
+ plugin->rollback (plugin->cls);
GNUNET_break (GNUNET_OK ==
plugin->drop_tables (plugin->cls,
GNUNET_YES));
@@ -711,17 +473,20 @@ main (int argc,
(void) argc;
result = -1;
- if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ TALER_OS_init ();
+ if (NULL == (plugin_name = strrchr (argv[0],
+ (int) '-')))
{
GNUNET_break (0);
return -1;
}
- GNUNET_log_setup (argv[0],
- "WARNING",
- NULL);
plugin_name++;
(void) GNUNET_asprintf (&testname,
- "test-auditor-db-%s", plugin_name);
+ "test-auditor-db-%s",
+ plugin_name);
(void) GNUNET_asprintf (&config_filename,
"%s.conf", testname);
cfg = GNUNET_CONFIGURATION_create ();
@@ -734,7 +499,8 @@ main (int argc,
GNUNET_free (testname);
return 2;
}
- GNUNET_SCHEDULER_run (&run, cfg);
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (config_filename);
GNUNET_free (testname);
diff --git a/src/auditordb/test_auditordb_checkpoints.c b/src/auditordb/test_auditordb_checkpoints.c
new file mode 100644
index 000000000..f9bb83142
--- /dev/null
+++ b/src/auditordb/test_auditordb_checkpoints.c
@@ -0,0 +1,386 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2016--2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file auditordb/test_auditordb_checkpoints.c
+ * @brief test cases for DB interaction functions
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_db_lib.h>
+#include "taler_auditordb_lib.h"
+#include "taler_auditordb_plugin.h"
+
+/**
+ * Currency we use, must match CURRENCY in "test-auditor-db-postgres.conf".
+ */
+#define CURRENCY "EUR"
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) { break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, \
+ sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+
+/**
+ * Global result from the testcase.
+ */
+static int result = -1;
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_AUDITORDB_Plugin *plugin;
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+static void
+run (void *cls)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_Amount a1;
+ struct TALER_Amount a2;
+ struct TALER_Amount a3;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":11.245678",
+ &a1));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":2",
+ &a2));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":3",
+ &a3));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "loading database plugin\n");
+ if (NULL ==
+ (plugin = TALER_AUDITORDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to database\n");
+ result = 77;
+ return;
+ }
+
+ (void) plugin->drop_tables (plugin->cls,
+ GNUNET_YES);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ false,
+ 0))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to 'create_tables'\n");
+ result = 77;
+ goto unload;
+ }
+ if (GNUNET_SYSERR ==
+ plugin->preflight (plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed preflight check\n");
+ result = 77;
+ goto drop;
+ }
+
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls));
+
+ /* Test inserting a blank value, should tell us one result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ NULL)
+ );
+ /* Test re-inserting the same value; should yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ NULL)
+ );
+ /* Test inserting multiple values, with one already existing */
+ GNUNET_assert (
+ 2 == plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 69,
+ "Test2",
+ 123,
+ "Test3",
+ 245,
+ NULL)
+ );
+ /* Test re-re-inserting the same key with a different value; should also yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_auditor_progress (plugin->cls,
+ "Test",
+ 42,
+ NULL)
+ );
+ /* Test updating the same key (again) with a different value; should yield a result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->update_auditor_progress (plugin->cls,
+ "Test",
+ 42,
+ NULL)
+ );
+ /* Test updating a key that doesn't exist; should yield 0 */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->update_auditor_progress (plugin->cls,
+ "NonexistentTest",
+ 1,
+ NULL)
+ );
+
+ /* Right now, the state should look like this:
+ * Test = 42
+ * Test2 = 123
+ * Test3 = 245
+ * Let's make sure that's the case! */
+ uint64_t value;
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 42);
+
+ /* Ensure the rest are also at their expected values */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test2",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 123);
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "Test3",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (value == 245);
+
+ /* Try fetching value that does not exist */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_auditor_progress (
+ plugin->cls,
+ "TestNX",
+ &value,
+ NULL)
+ );
+ GNUNET_assert (0 == value);
+
+
+ /* Test inserting a blank value, should tell us one result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ /* Test re-inserting the same value; should yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ /* Test inserting multiple values, with one already existing */
+ GNUNET_assert (
+ 2 == plugin->insert_balance (plugin->cls,
+ "Test",
+ &a1,
+ "Test2",
+ &a2,
+ "Test3",
+ &a3,
+ NULL)
+ );
+ /* Test re-re-inserting the same key with a different value; should also yield no results */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->insert_balance (plugin->cls,
+ "Test",
+ &a2,
+ NULL)
+ );
+ /* Test updating the same key (again) with a different value; should yield a result */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->update_balance (plugin->cls,
+ "Test",
+ &a2,
+ NULL)
+ );
+ /* Test updating a key that doesn't exist; should yield 0 */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
+ plugin->update_balance (plugin->cls,
+ "NonexistentTest",
+ &a2,
+ NULL)
+ );
+
+ /* Right now, the state should look like this:
+ * Test = a2
+ * Test2 = a2
+ * Test3 = a3
+ * Let's make sure that's the case! */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a2));
+
+ /* Ensure the rest are also at their expected values */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test2",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a2));
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "Test3",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (0 ==
+ TALER_amount_cmp (&a1,
+ &a3));
+
+ /* Try fetching value that does not exist */
+ GNUNET_assert (
+ GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
+ plugin->get_balance (
+ plugin->cls,
+ "TestNX",
+ &a1,
+ NULL)
+ );
+ GNUNET_assert (GNUNET_OK !=
+ TALER_amount_is_valid (&a1));
+
+ result = 0;
+ GNUNET_break (0 <=
+ plugin->commit (plugin->cls));
+drop:
+ GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls,
+ GNUNET_YES));
+unload:
+ TALER_AUDITORDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ char *testname;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ (void) argc;
+ result = -1;
+ TALER_OS_init ();
+ GNUNET_log_setup (argv[0],
+ "INFO",
+ NULL);
+ if (NULL == (plugin_name = strrchr (argv[0],
+ (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-auditor-db-%s",
+ plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run, cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
diff --git a/src/exchangedb/exchange-0000.sql b/src/auditordb/versioning.sql
index 116f409b7..444cf95ed 100644
--- a/src/exchangedb/exchange-0000.sql
+++ b/src/auditordb/versioning.sql
@@ -146,12 +146,13 @@
BEGIN;
+
-- This file adds versioning support to database it will be loaded to.
-- It requires that PL/pgSQL is already loaded - will raise exception otherwise.
-- All versioning "stuff" (tables, functions) is in "_v" schema.
-- All functions are defined as 'RETURNS SETOF INT4' to be able to make them to RETURN literally nothing (0 rows).
--- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling.
+-- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling
CREATE SCHEMA IF NOT EXISTS _v;
COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index ffd428a6f..a292dcece 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -51,14 +51,42 @@ libtalerbank_la_LIBADD = \
-lgnunetjson \
-lgnunetutil \
-ljansson \
- $(LIBGNURLCURL_LIBS) \
+ -lcurl \
$(XLIB)
libtalerfakebank_la_LDFLAGS = \
-version-info 0:0:0 \
-no-undefined
libtalerfakebank_la_SOURCES = \
- fakebank.c
+ fakebank.c fakebank.h \
+ fakebank_api_check.c \
+ fakebank_common_lookup.c fakebank_common_lookup.h \
+ fakebank_common_lp.c fakebank_common_lp.h \
+ fakebank_common_make_admin_transfer.c fakebank_common_make_admin_transfer.h \
+ fakebank_common_parser.c fakebank_common_parser.h \
+ fakebank_common_transact.c fakebank_common_transact.h \
+ fakebank_stop.c \
+ fakebank_bank.c fakebank_bank.h \
+ fakebank_bank_accounts_withdrawals.c fakebank_bank_accounts_withdrawals.h \
+ fakebank_bank_get_accounts.c fakebank_bank_get_accounts.h \
+ fakebank_bank_get_withdrawals.c fakebank_bank_get_withdrawals.h \
+ fakebank_bank_get_root.c fakebank_bank_get_root.h \
+ fakebank_bank_post_accounts_withdrawals.c fakebank_bank_post_accounts_withdrawals.h \
+ fakebank_bank_post_withdrawals_abort.c fakebank_bank_post_withdrawals_abort.h \
+ fakebank_bank_post_withdrawals_confirm.c fakebank_bank_post_withdrawals_confirm.h \
+ fakebank_bank_post_withdrawals_id_op.c fakebank_bank_post_withdrawals_id_op.h \
+ fakebank_bank_testing_register.c fakebank_bank_testing_register.h \
+ fakebank_tbr.c fakebank_tbr.h \
+ fakebank_tbr_get_history.c fakebank_tbr_get_history.h \
+ fakebank_tbr_get_root.c fakebank_tbr_get_root.h \
+ fakebank_tbi.c fakebank_tbi.h \
+ fakebank_tbi_get_withdrawal_operation.c fakebank_tbi_get_withdrawal_operation.h \
+ fakebank_tbi_post_withdrawal_operation.c fakebank_tbi_post_withdrawal_operation.h \
+ fakebank_twg.c fakebank_twg.h \
+ fakebank_twg_admin_add_incoming.c fakebank_twg_admin_add_incoming.h \
+ fakebank_twg_get_root.c fakebank_twg_get_root.h \
+ fakebank_twg_history.c fakebank_twg_history.h \
+ fakebank_twg_transfer.c fakebank_twg_transfer.h
libtalerfakebank_la_LIBADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/mhd/libtalermhd.la \
@@ -66,7 +94,7 @@ libtalerfakebank_la_LIBADD = \
-lgnunetjson \
-lgnunetutil \
-ljansson \
- $(LIBGNURLCURL_LIBS) \
+ -lcurl \
-lmicrohttpd \
-lpthread \
$(XLIB)
diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c
index 77b1a38e4..f12ab6ee2 100644
--- a/src/bank-lib/bank_api_admin.c
+++ b/src/bank-lib/bank_api_admin.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015--2020 Taler Systems SA
+ Copyright (C) 2015--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -16,7 +16,7 @@
*/
/**
* @file bank-lib/bank_api_admin.c
- * @brief Implementation of the /admin/ requests of the bank's HTTP API
+ * @brief Implementation of the /admin/add-incoming requests of the bank's HTTP API
* @author Christian Grothoff
*/
#include "platform.h"
@@ -27,7 +27,7 @@
/**
- * @brief An admin/add-incoming Handle
+ * @brief An /admin/add-incoming Handle
*/
struct TALER_BANK_AdminAddIncomingHandle
{
@@ -74,25 +74,25 @@ handle_admin_add_incoming_finished (void *cls,
const void *response)
{
struct TALER_BANK_AdminAddIncomingHandle *aai = cls;
- uint64_t row_id = UINT64_MAX;
- struct GNUNET_TIME_Timestamp timestamp;
- enum TALER_ErrorCode ec;
const json_t *j = response;
+ struct TALER_BANK_AdminAddIncomingResponse ir = {
+ .http_status = response_code,
+ .response = response
+ };
aai->job = NULL;
- timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
switch (response_code)
{
case 0:
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_uint64 ("row_id",
- &row_id),
+ &ir.details.ok.serial_id),
GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
+ &ir.details.ok.timestamp),
GNUNET_JSON_spec_end ()
};
@@ -102,42 +102,41 @@ handle_admin_add_incoming_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ ir.http_status = 0;
+ ir.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- ec = TALER_EC_NONE;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the bank is buggy
(or API version conflict); just pass JSON reply to the application */
GNUNET_break_op (0);
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Access denied */
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_UNAUTHORIZED:
/* Nothing really to verify, bank says the password is invalid; we should
pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, maybe account really does not exist.
We should pass the JSON reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_CONFLICT:
/* Nothing to verify, we used the same wire subject
twice? */
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
default:
/* unexpected response code */
@@ -145,15 +144,11 @@ handle_admin_add_incoming_finished (void *cls,
"Unexpected response code %u\n",
(unsigned int) response_code);
GNUNET_break (0);
- ec = TALER_JSON_get_error_code (j);
+ ir.ec = TALER_JSON_get_error_code (j);
break;
}
aai->cb (aai->cb_cls,
- response_code,
- ec,
- row_id,
- timestamp,
- j);
+ &ir);
TALER_BANK_admin_add_incoming_cancel (aai);
}
@@ -215,9 +210,10 @@ TALER_BANK_admin_add_incoming (
"Requesting administrative transaction at `%s' for reserve %s\n",
aai->request_url,
TALER_B2S (reserve_pub));
- aai->post_ctx.headers = curl_slist_append
- (aai->post_ctx.headers,
- "Content-Type: application/json");
+ aai->post_ctx.headers
+ = curl_slist_append (
+ aai->post_ctx.headers,
+ "Content-Type: application/json");
eh = curl_easy_init ();
if ( (NULL == eh) ||
diff --git a/src/bank-lib/bank_api_common.h b/src/bank-lib/bank_api_common.h
index ac059e9ed..e288a7e6f 100644
--- a/src/bank-lib/bank_api_common.h
+++ b/src/bank-lib/bank_api_common.h
@@ -36,7 +36,7 @@
* @param auth authentication data to use
* @return #GNUNET_OK in success
*/
-int
+enum GNUNET_GenericReturnValue
TALER_BANK_setup_auth_ (CURL *easy,
const struct TALER_BANK_AuthenticationData *auth);
diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c
index 1ea2e269e..124415b80 100644
--- a/src/bank-lib/bank_api_credit.c
+++ b/src/bank-lib/bank_api_credit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017--2021 Taler Systems SA
+ Copyright (C) 2017--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -77,62 +77,67 @@ static enum GNUNET_GenericReturnValue
parse_account_history (struct TALER_BANK_CreditHistoryHandle *hh,
const json_t *history)
{
- json_t *history_array;
+ struct TALER_BANK_CreditHistoryResponse chr = {
+ .http_status = MHD_HTTP_OK,
+ .ec = TALER_EC_NONE,
+ .response = history
+ };
+ const json_t *history_array;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("incoming_transactions",
+ &history_array),
+ GNUNET_JSON_spec_string ("credit_account",
+ &chr.details.ok.credit_account_uri),
+ GNUNET_JSON_spec_end ()
+ };
- if (NULL == (history_array = json_object_get (history,
- "incoming_transactions")))
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (history,
+ spec,
+ NULL,
+ NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (history_array))
{
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- for (unsigned int i = 0; i<json_array_size (history_array); i++)
- {
- struct TALER_BANK_CreditDetails td;
- uint64_t row_id;
- struct GNUNET_JSON_Specification hist_spec[] = {
- TALER_JSON_spec_amount_any ("amount",
- &td.amount),
- GNUNET_JSON_spec_timestamp ("date",
- &td.execution_date),
- GNUNET_JSON_spec_uint64 ("row_id",
- &row_id),
- GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &td.reserve_pub),
- GNUNET_JSON_spec_string ("debit_account",
- &td.debit_account_uri),
- GNUNET_JSON_spec_string ("credit_account",
- &td.credit_account_uri),
- GNUNET_JSON_spec_end ()
- };
- json_t *transaction = json_array_get (history_array,
- i);
+ size_t len = json_array_size (history_array);
+ struct TALER_BANK_CreditDetails cd[GNUNET_NZL (len)];
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- hist_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- hh->hcb (hh->hcb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
- row_id,
- &td,
- transaction))
+ GNUNET_break_op (0 != len);
+ for (size_t i = 0; i<len; i++)
{
- hh->hcb = NULL;
- GNUNET_JSON_parse_free (hist_spec);
- return GNUNET_OK;
+ struct TALER_BANK_CreditDetails *td = &cd[i];
+ struct GNUNET_JSON_Specification hist_spec[] = {
+ TALER_JSON_spec_amount_any ("amount",
+ &td->amount),
+ GNUNET_JSON_spec_timestamp ("date",
+ &td->execution_date),
+ GNUNET_JSON_spec_uint64 ("row_id",
+ &td->serial_id),
+ GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+ &td->reserve_pub),
+ GNUNET_JSON_spec_string ("debit_account",
+ &td->debit_account_uri),
+ GNUNET_JSON_spec_end ()
+ };
+ json_t *transaction = json_array_get (history_array,
+ i);
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ hist_spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
}
- GNUNET_JSON_parse_free (hist_spec);
+ chr.details.ok.details_length = len;
+ chr.details.ok.details = cd;
+ hh->hcb (hh->hcb_cls,
+ &chr);
}
return GNUNET_OK;
}
@@ -152,69 +157,67 @@ handle_credit_history_finished (void *cls,
const void *response)
{
struct TALER_BANK_CreditHistoryHandle *hh = cls;
- const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_BANK_CreditHistoryResponse chr = {
+ .http_status = response_code,
+ .response = response
+ };
hh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ chr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
parse_account_history (hh,
- j))
+ chr.response))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ json_dumpf (chr.response,
+ stderr,
+ JSON_INDENT (2));
+ chr.http_status = 0;
+ chr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- response_code = MHD_HTTP_NO_CONTENT; /* signal end of list */
- ec = TALER_EC_NONE;
- break;
+ TALER_BANK_credit_history_cancel (hh);
+ return;
case MHD_HTTP_NO_CONTENT:
- ec = TALER_EC_NONE;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the bank is buggy
(or API version conflict); just pass JSON reply to the application */
GNUNET_break_op (0);
- ec = TALER_JSON_get_error_code (j);
+ chr.ec = TALER_JSON_get_error_code (chr.response);
break;
case MHD_HTTP_UNAUTHORIZED:
/* Nothing really to verify, bank says the HTTP Authentication
failed. May happen if HTTP authentication is used and the
user supplied a wrong username/password combination. */
- ec = TALER_JSON_get_error_code (j);
+ chr.ec = TALER_JSON_get_error_code (chr.response);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify: the bank is either unaware
of the endpoint (not a bank), or of the account.
We should pass the JSON (?) reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ chr.ec = TALER_JSON_get_error_code (chr.response);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ chr.ec = TALER_JSON_get_error_code (chr.response);
break;
default:
/* unexpected response code */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u\n",
(unsigned int) response_code);
- ec = TALER_JSON_get_error_code (j);
+ chr.ec = TALER_JSON_get_error_code (chr.response);
break;
}
- if (NULL != hh->hcb)
- hh->hcb (hh->hcb_cls,
- response_code,
- ec,
- 0LLU,
- NULL,
- j);
+ hh->hcb (hh->hcb_cls,
+ &chr);
TALER_BANK_credit_history_cancel (hh);
}
@@ -248,12 +251,15 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
{
if ( (0 < num_results) &&
(! GNUNET_TIME_relative_is_zero (timeout)) )
+ /* 0 == start_row is implied, go with timeout into future */
GNUNET_snprintf (url,
sizeof (url),
"history/incoming?delta=%lld&long_poll_ms=%llu",
(long long) num_results,
tms);
else
+ /* Going back from current transaction or have no timeout;
+ hence timeout makes no sense */
GNUNET_snprintf (url,
sizeof (url),
"history/incoming?delta=%lld",
@@ -263,6 +269,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
{
if ( (0 < num_results) &&
(! GNUNET_TIME_relative_is_zero (timeout)) )
+ /* going forward from num_result */
GNUNET_snprintf (url,
sizeof (url),
"history/incoming?delta=%lld&start=%llu&long_poll_ms=%llu",
@@ -270,6 +277,8 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx,
(unsigned long long) start_row,
tms);
else
+ /* going backwards or have no timeout;
+ hence timeout makes no sense */
GNUNET_snprintf (url,
sizeof (url),
"history/incoming?delta=%lld&start=%llu",
diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c
index 2a76495bd..58dc0a736 100644
--- a/src/bank-lib/bank_api_debit.c
+++ b/src/bank-lib/bank_api_debit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017--2021 Taler Systems SA
+ Copyright (C) 2017--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -77,64 +77,69 @@ static enum GNUNET_GenericReturnValue
parse_account_history (struct TALER_BANK_DebitHistoryHandle *hh,
const json_t *history)
{
- json_t *history_array;
+ struct TALER_BANK_DebitHistoryResponse dhr = {
+ .http_status = MHD_HTTP_OK,
+ .ec = TALER_EC_NONE,
+ .response = history
+ };
+ const json_t *history_array;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("outgoing_transactions",
+ &history_array),
+ GNUNET_JSON_spec_string ("debit_account",
+ &dhr.details.ok.debit_account_uri),
+ GNUNET_JSON_spec_end ()
+ };
- if (NULL == (history_array = json_object_get (history,
- "outgoing_transactions")))
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (history,
+ spec,
+ NULL,
+ NULL))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (history_array))
{
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- for (unsigned int i = 0; i<json_array_size (history_array); i++)
- {
- struct TALER_BANK_DebitDetails td;
- uint64_t row_id;
- struct GNUNET_JSON_Specification hist_spec[] = {
- TALER_JSON_spec_amount_any ("amount",
- &td.amount),
- GNUNET_JSON_spec_timestamp ("date",
- &td.execution_date),
- GNUNET_JSON_spec_uint64 ("row_id",
- &row_id),
- GNUNET_JSON_spec_fixed_auto ("wtid",
- &td.wtid),
- GNUNET_JSON_spec_string ("credit_account",
- &td.credit_account_uri),
- GNUNET_JSON_spec_string ("debit_account",
- &td.debit_account_uri),
- GNUNET_JSON_spec_string ("exchange_base_url",
- &td.exchange_base_url),
- GNUNET_JSON_spec_end ()
- };
- json_t *transaction = json_array_get (history_array,
- i);
+ size_t len = json_array_size (history_array);
+ struct TALER_BANK_DebitDetails dd[GNUNET_NZL (len)];
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- hist_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- hh->hcb (hh->hcb_cls,
- MHD_HTTP_OK,
- TALER_EC_NONE,
- row_id,
- &td,
- transaction))
+ GNUNET_break_op (0 != len);
+ for (unsigned int i = 0; i<len; i++)
{
- hh->hcb = NULL;
- GNUNET_JSON_parse_free (hist_spec);
- return GNUNET_OK;
+ struct TALER_BANK_DebitDetails *td = &dd[i];
+ struct GNUNET_JSON_Specification hist_spec[] = {
+ TALER_JSON_spec_amount_any ("amount",
+ &td->amount),
+ GNUNET_JSON_spec_timestamp ("date",
+ &td->execution_date),
+ GNUNET_JSON_spec_uint64 ("row_id",
+ &td->serial_id),
+ GNUNET_JSON_spec_fixed_auto ("wtid",
+ &td->wtid),
+ GNUNET_JSON_spec_string ("credit_account",
+ &td->credit_account_uri),
+ GNUNET_JSON_spec_string ("exchange_base_url",
+ &td->exchange_base_url),
+ GNUNET_JSON_spec_end ()
+ };
+ json_t *transaction = json_array_get (history_array,
+ i);
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ hist_spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
}
- GNUNET_JSON_parse_free (hist_spec);
+ dhr.details.ok.details_length = len;
+ dhr.details.ok.details = dd;
+ hh->hcb (hh->hcb_cls,
+ &dhr);
}
return GNUNET_OK;
}
@@ -154,69 +159,64 @@ handle_debit_history_finished (void *cls,
const void *response)
{
struct TALER_BANK_DebitHistoryHandle *hh = cls;
- const json_t *j = response;
- enum TALER_ErrorCode ec;
+ struct TALER_BANK_DebitHistoryResponse dhr = {
+ .http_status = response_code,
+ .response = response
+ };
hh->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ dhr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
parse_account_history (hh,
- j))
+ dhr.response))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ dhr.http_status = 0;
+ dhr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- response_code = MHD_HTTP_NO_CONTENT; /* signal end of list */
- ec = TALER_EC_NONE;
- break;
+ TALER_BANK_debit_history_cancel (hh);
+ return;
case MHD_HTTP_NO_CONTENT:
- ec = TALER_EC_NONE;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the bank is buggy
(or API version conflict); just pass JSON reply to the application */
GNUNET_break_op (0);
- ec = TALER_JSON_get_error_code (j);
+ dhr.ec = TALER_JSON_get_error_code (dhr.response);
break;
case MHD_HTTP_UNAUTHORIZED:
/* Nothing really to verify, bank says the HTTP Authentication
failed. May happen if HTTP authentication is used and the
user supplied a wrong username/password combination. */
- ec = TALER_JSON_get_error_code (j);
+ dhr.ec = TALER_JSON_get_error_code (dhr.response);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify: the bank is either unaware
of the endpoint (not a bank), or of the account.
We should pass the JSON (?) reply to the application */
- ec = TALER_JSON_get_error_code (j);
+ dhr.ec = TALER_JSON_get_error_code (dhr.response);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ dhr.ec = TALER_JSON_get_error_code (dhr.response);
break;
default:
/* unexpected response code */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u\n",
(unsigned int) response_code);
- ec = TALER_JSON_get_error_code (j);
+ dhr.ec = TALER_JSON_get_error_code (dhr.response);
break;
}
- if (NULL != hh->hcb)
- hh->hcb (hh->hcb_cls,
- response_code,
- ec,
- 0LLU,
- NULL,
- j);
+ hh->hcb (hh->hcb_cls,
+ &dhr);
TALER_BANK_debit_history_cancel (hh);
}
diff --git a/src/bank-lib/bank_api_transfer.c b/src/bank-lib/bank_api_transfer.c
index 3b50018d3..0748a0d7e 100644
--- a/src/bank-lib/bank_api_transfer.c
+++ b/src/bank-lib/bank_api_transfer.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015--2020 Taler Systems SA
+ Copyright (C) 2015--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -99,12 +99,12 @@ TALER_BANK_prepare_transfer (
wp->account_len = htonl ((uint32_t) d_len);
wp->exchange_url_len = htonl ((uint32_t) u_len);
end = (char *) &wp[1];
- memcpy (end,
- destination_account_payto_uri,
- d_len);
- memcpy (end + d_len,
- exchange_base_url,
- u_len);
+ GNUNET_memcpy (end,
+ destination_account_payto_uri,
+ d_len);
+ GNUNET_memcpy (end + d_len,
+ exchange_base_url,
+ u_len);
*buf = (char *) wp;
}
@@ -158,23 +158,24 @@ handle_transfer_finished (void *cls,
{
struct TALER_BANK_TransferHandle *th = cls;
const json_t *j = response;
- uint64_t row_id = UINT64_MAX;
- struct GNUNET_TIME_Timestamp timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
- enum TALER_ErrorCode ec;
+ struct TALER_BANK_TransferResponse tr = {
+ .http_status = response_code,
+ .response = j
+ };
th->job = NULL;
switch (response_code)
{
case 0:
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ tr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_uint64 ("row_id",
- &row_id),
+ &tr.details.ok.row_id),
GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
+ &tr.details.ok.timestamp),
GNUNET_JSON_spec_end ()
};
@@ -184,39 +185,38 @@ handle_transfer_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- response_code = 0;
- ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ tr.http_status = 0;
+ tr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- ec = TALER_EC_NONE;
}
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the bank is buggy
(or API version conflict); just pass JSON reply to the application */
GNUNET_break_op (0);
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_UNAUTHORIZED:
/* Nothing really to verify, bank says our credentials are
invalid. We should pass the JSON reply to the application. */
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, endpoint wrong -- could be user unknown */
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_CONFLICT:
/* Nothing really to verify. Server says we used the same transfer request
UID before, but with different details. Should not happen if the user
properly used #TALER_BANK_prepare_transfer() and our PRNG is not
broken... */
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
default:
/* unexpected response code */
@@ -224,14 +224,11 @@ handle_transfer_finished (void *cls,
"Unexpected response code %u\n",
(unsigned int) response_code);
GNUNET_break (0);
- ec = TALER_JSON_get_error_code (j);
+ tr.ec = TALER_JSON_get_error_code (j);
break;
}
th->cb (th->cb_cls,
- response_code,
- ec,
- row_id,
- timestamp);
+ &tr);
TALER_BANK_transfer_cancel (th);
}
diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c
index 2e066c02c..3a004dc80 100644
--- a/src/bank-lib/fakebank.c
+++ b/src/bank-lib/fakebank.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2016-2021 Taler Systems SA
+ (C) 2016-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@@ -21,8 +21,6 @@
* @brief library that fakes being a Taler bank for testcases
* @author Christian Grothoff <christian@grothoff.org>
*/
-// TODO: support adding WAD transfers
-
#include "platform.h"
#include <pthread.h>
#include <poll.h>
@@ -33,1356 +31,10 @@
#include "taler_bank_service.h"
#include "taler_mhd_lib.h"
#include <gnunet/gnunet_mhd_compat.h>
-
-/**
- * Maximum POST request size (for /admin/add-incoming)
- */
-#define REQUEST_BUFFER_MAX (4 * 1024)
-
-/**
- * How long are exchange base URLs allowed to be at most?
- * Set to a relatively low number as this does contribute
- * significantly to our RAM consumption.
- */
-#define MAX_URL_LEN 64
-
-/**
- * Per account information.
- */
-struct Account;
-
-
-/**
- * Types of long polling activities.
- */
-enum LongPollType
-{
- /**
- * Transfer TO the exchange.
- */
- LP_CREDIT,
-
- /**
- * Transfer FROM the exchange.
- */
- LP_DEBIT
-
-};
-
-/**
- * Client waiting for activity on this account.
- */
-struct LongPoller
-{
-
- /**
- * Kept in a DLL.
- */
- struct LongPoller *next;
-
- /**
- * Kept in a DLL.
- */
- struct LongPoller *prev;
-
- /**
- * Account this long poller is waiting on.
- */
- struct Account *account;
-
- /**
- * Entry in the heap for this long poller.
- */
- struct GNUNET_CONTAINER_HeapNode *hn;
-
- /**
- * Client that is waiting for transactions.
- */
- struct MHD_Connection *conn;
-
- /**
- * When will this long poller time out?
- */
- struct GNUNET_TIME_Absolute timeout;
-
- /**
- * What does the @e connection wait for?
- */
- enum LongPollType type;
-
-};
-
-
-/**
- * Details about a transcation we (as the simulated bank) received.
- */
-struct Transaction;
-
-/**
- * Per account information.
- */
-struct Account
-{
-
- /**
- * Inbound transactions for this account in a MDLL.
- */
- struct Transaction *in_head;
-
- /**
- * Inbound transactions for this account in a MDLL.
- */
- struct Transaction *in_tail;
-
- /**
- * Outbound transactions for this account in a MDLL.
- */
- struct Transaction *out_head;
-
- /**
- * Outbound transactions for this account in a MDLL.
- */
- struct Transaction *out_tail;
-
- /**
- * Kept in a DLL.
- */
- struct LongPoller *lp_head;
-
- /**
- * Kept in a DLL.
- */
- struct LongPoller *lp_tail;
-
- /**
- * Account name (string, not payto!)
- */
- char *account_name;
-
- /**
- * Receiver name for payto:// URIs.
- */
- char *receiver_name;
-
- /**
- * Current account balance.
- */
- struct TALER_Amount balance;
-
- /**
- * true if the balance is negative.
- */
- bool is_negative;
-
-};
-
-
-/**
- * Details about a transcation we (as the simulated bank) received.
- */
-struct Transaction
-{
- /**
- * We store inbound transactions in a MDLL.
- */
- struct Transaction *next_in;
-
- /**
- * We store inbound transactions in a MDLL.
- */
- struct Transaction *prev_in;
-
- /**
- * We store outbound transactions in a MDLL.
- */
- struct Transaction *next_out;
-
- /**
- * We store outbound transactions in a MDLL.
- */
- struct Transaction *prev_out;
-
- /**
- * Amount to be transferred.
- */
- struct TALER_Amount amount;
-
- /**
- * Account to debit.
- */
- struct Account *debit_account;
-
- /**
- * Account to credit.
- */
- struct Account *credit_account;
-
- /**
- * Random unique identifier for the request.
- * Used to detect idempotent requests.
- */
- struct GNUNET_HashCode request_uid;
-
- /**
- * When did the transaction happen?
- */
- struct GNUNET_TIME_Timestamp date;
-
- /**
- * Number of this transaction.
- */
- uint64_t row_id;
-
- /**
- * What does the @e subject contain?
- */
- enum
- {
- /**
- * Transfer TO the exchange.
- */
- T_CREDIT,
-
- /**
- * Transfer FROM the exchange.
- */
- T_DEBIT,
-
- /**
- * Exchange-to-exchange WAD transfer.
- */
- T_WAD,
- } type;
-
- /**
- * Wire transfer subject.
- */
- union
- {
-
- /**
- * Used if @e type is T_DEBIT.
- */
- struct
- {
-
- /**
- * Subject of the transfer.
- */
- struct TALER_WireTransferIdentifierRawP wtid;
-
- /**
- * Base URL of the exchange.
- */
- char exchange_base_url[MAX_URL_LEN];
-
- } debit;
-
- /**
- * Used if @e type is T_CREDIT.
- */
- struct
- {
-
- /**
- * Reserve public key of the credit operation.
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- } credit;
-
- /**
- * Used if @e type is T_WAD.
- */
- struct
- {
-
- /**
- * Subject of the transfer.
- */
- struct TALER_WadIdentifierP wad;
-
- /**
- * Base URL of the originating exchange.
- */
- char origin_base_url[MAX_URL_LEN];
-
- } wad;
-
- } subject;
-
- /**
- * Has this transaction not yet been subjected to
- * #TALER_FAKEBANK_check_credit() or #TALER_FAKEBANK_check_debit() and
- * should thus be counted in #TALER_FAKEBANK_check_empty()?
- */
- bool unchecked;
-};
-
-
-/**
- * Handle for the fake bank.
- */
-struct TALER_FAKEBANK_Handle
-{
- /**
- * We store transactions in a revolving array.
- */
- struct Transaction **transactions;
-
- /**
- * HTTP server we run to pretend to be the "test" bank.
- */
- struct MHD_Daemon *mhd_bank;
-
- /**
- * Task running HTTP server for the "test" bank,
- * unless we are using a thread pool (then NULL).
- */
- struct GNUNET_SCHEDULER_Task *mhd_task;
-
- /**
- * Task for expiring long-polling connections,
- * unless we are using a thread pool (then NULL).
- */
- struct GNUNET_SCHEDULER_Task *lp_task;
-
- /**
- * Task for expiring long-polling connections, unless we are using the
- * GNUnet scheduler (then NULL).
- */
- pthread_t lp_thread;
-
- /**
- * MIN-heap of long pollers, sorted by timeout.
- */
- struct GNUNET_CONTAINER_Heap *lp_heap;
-
- /**
- * Hashmap of reserve public keys to
- * `struct Transaction` with that reserve public
- * key. Used to prevent public-key re-use.
- */
- struct GNUNET_CONTAINER_MultiPeerMap *rpubs;
-
- /**
- * Lock for accessing @a rpubs map.
- */
- pthread_mutex_t rpubs_lock;
-
- /**
- * Hashmap of hashes of account names to `struct Account`.
- */
- struct GNUNET_CONTAINER_MultiHashMap *accounts;
-
- /**
- * Lock for accessing @a accounts hash map.
- */
- pthread_mutex_t accounts_lock;
-
- /**
- * Hashmap of hashes of transaction request_uids to `struct Transaction`.
- */
- struct GNUNET_CONTAINER_MultiHashMap *uuid_map;
-
- /**
- * Lock for accessing @a uuid_map.
- */
- pthread_mutex_t uuid_map_lock;
-
- /**
- * Lock for accessing the internals of
- * accounts and transaction array entries.
- */
- pthread_mutex_t big_lock;
-
- /**
- * Current transaction counter.
- */
- uint64_t serial_counter;
-
- /**
- * Number of transactions we keep in memory (at most).
- */
- uint64_t ram_limit;
-
- /**
- * Currency used by the fakebank.
- */
- char *currency;
-
- /**
- * BaseURL of the fakebank.
- */
- char *my_baseurl;
-
- /**
- * Our port number.
- */
- uint16_t port;
-
-#ifdef __linux__
- /**
- * Event FD to signal @a lp_thread a change in
- * @a lp_heap.
- */
- int lp_event;
-#else
- /**
- * Pipe input to signal @a lp_thread a change in
- * @a lp_heap.
- */
- int lp_event_in;
-
- /**
- * Pipe output to signal @a lp_thread a change in
- * @a lp_heap.
- */
- int lp_event_out;
-#endif
-
- /**
- * Set to true once we are shutting down.
- */
- bool in_shutdown;
-
- /**
- * Should we run MHD immediately again?
- */
- bool mhd_again;
-
-#if EPOLL_SUPPORT
- /**
- * Boxed @e mhd_fd.
- */
- struct GNUNET_NETWORK_Handle *mhd_rfd;
-
- /**
- * File descriptor to use to wait for MHD.
- */
- int mhd_fd;
-#endif
-};
-
-
-/**
- * Special address "con_cls" can point to to indicate that the handler has
- * been called more than once already (was previously suspended).
- */
-static int special_ptr;
-
-
-/**
- * Task run whenever HTTP server operations are pending.
- *
- * @param cls the `struct TALER_FAKEBANK_Handle`
- */
-static void
-run_mhd (void *cls);
-
-
-/**
- * Trigger the @a lp. Frees associated resources,
- * except the entry of @a lp in the timeout heap.
- * Must be called while the ``big lock`` is held.
- *
- * @param[in] lp long poller to trigger
- * @param[in,out] h fakebank handle
- */
-static void
-lp_trigger (struct LongPoller *lp,
- struct TALER_FAKEBANK_Handle *h)
-{
- struct Account *acc = lp->account;
-
- GNUNET_CONTAINER_DLL_remove (acc->lp_head,
- acc->lp_tail,
- lp);
- MHD_resume_connection (lp->conn);
- GNUNET_free (lp);
- h->mhd_again = true;
-#ifdef __linux__
- if (-1 == h->lp_event)
-#else
- if ( (-1 == h->lp_event_in) &&
- (-1 == h->lp_event_out) )
-#endif
- {
- if (NULL != h->mhd_task)
- GNUNET_SCHEDULER_cancel (h->mhd_task);
- h->mhd_task =
- GNUNET_SCHEDULER_add_now (&run_mhd,
- h);
- }
-}
-
-
-/**
- * Thread that is run to wake up connections that have hit their timeout. Runs
- * until in_shutdown is set to true. Must be send signals via lp_event on
- * shutdown and/or whenever the heap changes to an earlier timeout.
- *
- * @param cls a `struct TALER_FAKEBANK_Handle *`
- * @return NULL
- */
-static void *
-lp_expiration_thread (void *cls)
-{
- struct TALER_FAKEBANK_Handle *h = cls;
-
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- while (! h->in_shutdown)
- {
- struct LongPoller *lp;
- int timeout_ms;
-
- lp = GNUNET_CONTAINER_heap_peek (h->lp_heap);
- while ( (NULL != lp) &&
- GNUNET_TIME_absolute_is_past (lp->timeout))
- {
- GNUNET_assert (lp ==
- GNUNET_CONTAINER_heap_remove_root (h->lp_heap));
- lp_trigger (lp,
- h);
- lp = GNUNET_CONTAINER_heap_peek (h->lp_heap);
- }
- if (NULL != lp)
- {
- struct GNUNET_TIME_Relative rem;
- unsigned long long left_ms;
-
- rem = GNUNET_TIME_absolute_get_remaining (lp->timeout);
- left_ms = rem.rel_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
- if (left_ms > INT_MAX)
- timeout_ms = INT_MAX;
- else
- timeout_ms = (int) left_ms;
- }
- else
- {
- timeout_ms = -1; /* infinity */
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- {
- struct pollfd p = {
-#ifdef __linux__
- .fd = h->lp_event,
-#else
- .fd = h->lp_event_out,
-#endif
- .events = POLLIN
- };
- int ret;
-
- ret = poll (&p,
- 1,
- timeout_ms);
- if (-1 == ret)
- {
- if (EINTR != errno)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "poll");
- }
- else if (1 == ret)
- {
- /* clear event */
- uint64_t ev;
- ssize_t iret;
-
-#ifdef __linux__
- iret = read (h->lp_event,
-#else
- iret = read (h->lp_event_out,
-#endif
- &ev,
- sizeof (ev));
- if (-1 == iret)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "read");
- }
- else
- {
- GNUNET_break (sizeof (uint64_t) == iret);
- }
- }
- }
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- return NULL;
-}
-
-
-/**
- * Lookup account with @a name, and if it does not exist, create it.
- *
- * @param[in,out] h bank to lookup account at
- * @param name account name to resolve
- * @param receiver_name receiver name in payto:// URI,
- * NULL if the account must already exist
- * @return account handle, NULL if account does not yet exist
- */
-static struct Account *
-lookup_account (struct TALER_FAKEBANK_Handle *h,
- const char *name,
- const char *receiver_name)
-{
- struct GNUNET_HashCode hc;
- size_t slen;
- struct Account *account;
-
- memset (&hc,
- 0,
- sizeof (hc));
- slen = strlen (name);
- GNUNET_CRYPTO_hash (name,
- slen,
- &hc);
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->accounts_lock));
- account = GNUNET_CONTAINER_multihashmap_get (h->accounts,
- &hc);
- if (NULL == account)
- {
- if (NULL == receiver_name)
- {
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->accounts_lock));
- return NULL;
- }
- account = GNUNET_new (struct Account);
- account->account_name = GNUNET_strdup (name);
- account->receiver_name = GNUNET_strdup (receiver_name);
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (h->currency,
- &account->balance));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (h->accounts,
- &hc,
- account,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->accounts_lock));
- return account;
-}
-
-
-/**
- * Generate log messages for failed check operation.
- *
- * @param h handle to output transaction log for
- */
-static void
-check_log (struct TALER_FAKEBANK_Handle *h)
-{
- for (uint64_t i = 0; i<h->ram_limit; i++)
- {
- struct Transaction *t = h->transactions[i];
-
- if (NULL == t)
- continue;
- if (! t->unchecked)
- continue;
- switch (t->type)
- {
- case T_DEBIT:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s -> %s (%s) %s (%s)\n",
- t->debit_account->account_name,
- t->credit_account->account_name,
- TALER_amount2s (&t->amount),
- t->subject.debit.exchange_base_url,
- "DEBIT");
- break;
- case T_CREDIT:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s -> %s (%s) %s (%s)\n",
- t->debit_account->account_name,
- t->credit_account->account_name,
- TALER_amount2s (&t->amount),
- TALER_B2S (&t->subject.credit.reserve_pub),
- "CREDIT");
- break;
- case T_WAD:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s -> %s (%s) %s[%s] (%s)\n",
- t->debit_account->account_name,
- t->credit_account->account_name,
- TALER_amount2s (&t->amount),
- t->subject.wad.origin_base_url,
- TALER_B2S (&t->subject.wad),
- "WAD");
- break;
- }
- }
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_FAKEBANK_check_debit (struct TALER_FAKEBANK_Handle *h,
- const struct TALER_Amount *want_amount,
- const char *want_debit,
- const char *want_credit,
- const char *exchange_base_url,
- struct TALER_WireTransferIdentifierRawP *wtid)
-{
- struct Account *debit_account;
- struct Account *credit_account;
-
- GNUNET_assert (0 ==
- strcasecmp (want_amount->currency,
- h->currency));
- debit_account = lookup_account (h,
- want_debit,
- NULL);
- credit_account = lookup_account (h,
- want_credit,
- NULL);
- if (NULL == debit_account)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted: %s->%s (%s) from exchange %s (DEBIT), but debit account does not even exist!\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- exchange_base_url);
- return GNUNET_SYSERR;
- }
- if (NULL == credit_account)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted: %s->%s (%s) from exchange %s (DEBIT), but credit account does not even exist!\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- exchange_base_url);
- return GNUNET_SYSERR;
- }
- for (struct Transaction *t = debit_account->out_tail;
- NULL != t;
- t = t->prev_out)
- {
- if ( (t->unchecked) &&
- (credit_account == t->credit_account) &&
- (T_DEBIT == t->type) &&
- (0 == TALER_amount_cmp (want_amount,
- &t->amount)) &&
- (0 == strcasecmp (exchange_base_url,
- t->subject.debit.exchange_base_url)) )
- {
- *wtid = t->subject.debit.wtid;
- t->unchecked = false;
- return GNUNET_OK;
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Did not find matching transaction! I have:\n");
- check_log (h);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted: %s->%s (%s) from exchange %s (DEBIT)\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- exchange_base_url);
- return GNUNET_SYSERR;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle *h,
- const struct TALER_Amount *want_amount,
- const char *want_debit,
- const char *want_credit,
- const struct TALER_ReservePublicKeyP *reserve_pub)
-{
- struct Account *debit_account;
- struct Account *credit_account;
-
- GNUNET_assert (0 == strcasecmp (want_amount->currency,
- h->currency));
- debit_account = lookup_account (h,
- want_debit,
- NULL);
- credit_account = lookup_account (h,
- want_credit,
- NULL);
- if (NULL == debit_account)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted:\n%s -> %s (%s) with subject %s (CREDIT) but debit account is unknown.\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- TALER_B2S (reserve_pub));
- return GNUNET_SYSERR;
- }
- if (NULL == credit_account)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted:\n%s -> %s (%s) with subject %s (CREDIT) but credit account is unknown.\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- TALER_B2S (reserve_pub));
- return GNUNET_SYSERR;
- }
- for (struct Transaction *t = credit_account->in_tail;
- NULL != t;
- t = t->prev_in)
- {
- if ( (t->unchecked) &&
- (debit_account == t->debit_account) &&
- (T_CREDIT == t->type) &&
- (0 == TALER_amount_cmp (want_amount,
- &t->amount)) &&
- (0 == GNUNET_memcmp (reserve_pub,
- &t->subject.credit.reserve_pub)) )
- {
- t->unchecked = false;
- return GNUNET_OK;
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Did not find matching transaction!\nI have:\n");
- check_log (h);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "I wanted:\n%s -> %s (%s) with subject %s (CREDIT)\n",
- want_debit,
- want_credit,
- TALER_amount2s (want_amount),
- TALER_B2S (reserve_pub));
- return GNUNET_SYSERR;
-}
-
-
-/**
- * Update @a account balance by @a amount.
- *
- * The @a big_lock must already be locked when calling
- * this function.
- *
- * @param[in,out] account account to update
- * @param amount balance change
- * @param debit true to subtract, false to add @a amount
- */
-static void
-update_balance (struct Account *account,
- const struct TALER_Amount *amount,
- bool debit)
-{
- if (debit == account->is_negative)
- {
- GNUNET_assert (0 <=
- TALER_amount_add (&account->balance,
- &account->balance,
- amount));
- return;
- }
- if (0 <= TALER_amount_cmp (&account->balance,
- amount))
- {
- GNUNET_assert (0 <=
- TALER_amount_subtract (&account->balance,
- &account->balance,
- amount));
- }
- else
- {
- GNUNET_assert (0 <=
- TALER_amount_subtract (&account->balance,
- amount,
- &account->balance));
- account->is_negative = ! account->is_negative;
- }
-}
-
-
-/**
- * Add transaction to the debit and credit accounts,
- * updating the balances as needed.
- *
- * The transaction @a t must already be locked
- * when calling this function!
- *
- * @param[in,out] h bank handle
- * @param[in,out] t transaction to add to account lists
- */
-static void
-post_transaction (struct TALER_FAKEBANK_Handle *h,
- struct Transaction *t)
-{
- struct Account *debit_acc = t->debit_account;
- struct Account *credit_acc = t->credit_account;
- uint64_t row_id;
- struct Transaction *old;
-
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- row_id = ++h->serial_counter;
- old = h->transactions[row_id % h->ram_limit];
- h->transactions[row_id % h->ram_limit] = t;
- t->row_id = row_id;
- GNUNET_CONTAINER_MDLL_insert_tail (out,
- debit_acc->out_head,
- debit_acc->out_tail,
- t);
- update_balance (debit_acc,
- &t->amount,
- true);
- GNUNET_CONTAINER_MDLL_insert_tail (in,
- credit_acc->in_head,
- credit_acc->in_tail,
- t);
- update_balance (credit_acc,
- &t->amount,
- false);
- if (NULL != old)
- {
- struct Account *da;
- struct Account *ca;
-
- da = old->debit_account;
- ca = old->credit_account;
- /* slot was already in use, must clean out old
- entry first! */
- GNUNET_CONTAINER_MDLL_remove (out,
- da->out_head,
- da->out_tail,
- old);
- GNUNET_CONTAINER_MDLL_remove (in,
- ca->in_head,
- ca->in_tail,
- old);
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- if ( (NULL != old) &&
- (T_DEBIT == old->type) )
- {
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->uuid_map_lock));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
- &old->request_uid,
- old));
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
- }
- GNUNET_free (old);
-}
-
-
-/**
- * Trigger long pollers that might have been waiting
- * for @a t.
- *
- * @param h fakebank handle
- * @param t transaction to notify on
- */
-static void
-notify_transaction (struct TALER_FAKEBANK_Handle *h,
- struct Transaction *t)
-{
- struct Account *debit_acc = t->debit_account;
- struct Account *credit_acc = t->credit_account;
- struct LongPoller *nxt;
-
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- for (struct LongPoller *lp = debit_acc->lp_head;
- NULL != lp;
- lp = nxt)
- {
- nxt = lp->next;
- if (LP_DEBIT == lp->type)
- {
- GNUNET_assert (lp ==
- GNUNET_CONTAINER_heap_remove_node (lp->hn));
- lp_trigger (lp,
- h);
- }
- }
- for (struct LongPoller *lp = credit_acc->lp_head;
- NULL != lp;
- lp = nxt)
- {
- nxt = lp->next;
- if (LP_CREDIT == lp->type)
- {
- GNUNET_assert (lp ==
- GNUNET_CONTAINER_heap_remove_node (lp->hn));
- lp_trigger (lp,
- h);
- }
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
-}
-
-
-/**
- * Tell the fakebank to create another wire transfer *from* an exchange.
- *
- * @param h fake bank handle
- * @param debit_account account to debit
- * @param credit_account account to credit
- * @param amount amount to transfer
- * @param subject wire transfer subject to use
- * @param exchange_base_url exchange URL
- * @param request_uid unique number to make the request unique, or NULL to create one
- * @param[out] ret_row_id pointer to store the row ID of this transaction
- * @param[out] timestamp set to the time of the transfer
- * @return #GNUNET_YES if the transfer was successful,
- * #GNUNET_SYSERR if the request_uid was reused for a different transfer
- */
-static enum GNUNET_GenericReturnValue
-make_transfer (
- struct TALER_FAKEBANK_Handle *h,
- const char *debit_account,
- const char *credit_account,
- const struct TALER_Amount *amount,
- const struct TALER_WireTransferIdentifierRawP *subject,
- const char *exchange_base_url,
- const struct GNUNET_HashCode *request_uid,
- uint64_t *ret_row_id,
- struct GNUNET_TIME_Timestamp *timestamp)
-{
- struct Transaction *t;
- struct Account *debit_acc;
- struct Account *credit_acc;
- size_t url_len;
-
- GNUNET_assert (0 == strcasecmp (amount->currency,
- h->currency));
- GNUNET_assert (NULL != debit_account);
- GNUNET_assert (NULL != credit_account);
- GNUNET_break (0 != strncasecmp ("payto://",
- debit_account,
- strlen ("payto://")));
- GNUNET_break (0 != strncasecmp ("payto://",
- credit_account,
- strlen ("payto://")));
- url_len = strlen (exchange_base_url);
- GNUNET_assert (url_len < MAX_URL_LEN);
- debit_acc = lookup_account (h,
- debit_account,
- debit_account);
- credit_acc = lookup_account (h,
- credit_account,
- credit_account);
- if (NULL != request_uid)
- {
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->uuid_map_lock));
- t = GNUNET_CONTAINER_multihashmap_get (h->uuid_map,
- request_uid);
- if (NULL != t)
- {
- if ( (debit_acc != t->debit_account) ||
- (credit_acc != t->credit_account) ||
- (0 != TALER_amount_cmp (amount,
- &t->amount)) ||
- (T_DEBIT != t->type) ||
- (0 != GNUNET_memcmp (subject,
- &t->subject.debit.wtid)) )
- {
- /* Transaction exists, but with different details. */
- GNUNET_break (0);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
- return GNUNET_SYSERR;
- }
- *ret_row_id = t->row_id;
- *timestamp = t->date;
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
- return GNUNET_OK;
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
- }
- t = GNUNET_new (struct Transaction);
- t->unchecked = true;
- t->debit_account = debit_acc;
- t->credit_account = credit_acc;
- t->amount = *amount;
- t->date = GNUNET_TIME_timestamp_get ();
- if (NULL != timestamp)
- *timestamp = t->date;
- t->type = T_DEBIT;
- memcpy (t->subject.debit.exchange_base_url,
- exchange_base_url,
- url_len);
- t->subject.debit.wtid = *subject;
- if (NULL == request_uid)
- GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE,
- &t->request_uid);
- else
- t->request_uid = *request_uid;
- post_transaction (h,
- t);
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->uuid_map_lock));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_put (
- h->uuid_map,
- &t->request_uid,
- t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->uuid_map_lock));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Making transfer %llu from %s to %s over %s and subject %s; for exchange: %s\n",
- (unsigned long long) t->row_id,
- debit_account,
- credit_account,
- TALER_amount2s (amount),
- TALER_B2S (subject),
- exchange_base_url);
- *ret_row_id = t->row_id;
- notify_transaction (h,
- t);
- return GNUNET_OK;
-}
-
-
-/**
- * Tell the fakebank to create another wire transfer *to* an exchange.
- *
- * @param h fake bank handle
- * @param debit_account account to debit
- * @param credit_account account to credit
- * @param amount amount to transfer
- * @param reserve_pub reserve public key to use in subject
- * @param[out] row_id serial_id of the transfer
- * @param[out] timestamp when was the transfer made
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-make_admin_transfer (
- struct TALER_FAKEBANK_Handle *h,
- const char *debit_account,
- const char *credit_account,
- const struct TALER_Amount *amount,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t *row_id,
- struct GNUNET_TIME_Timestamp *timestamp)
-{
- struct Transaction *t;
- const struct GNUNET_PeerIdentity *pid;
- struct Account *debit_acc;
- struct Account *credit_acc;
-
- GNUNET_static_assert (sizeof (*pid) ==
- sizeof (*reserve_pub));
- pid = (const struct GNUNET_PeerIdentity *) reserve_pub;
- GNUNET_assert (NULL != debit_account);
- GNUNET_assert (NULL != credit_account);
- GNUNET_assert (0 == strcasecmp (amount->currency,
- h->currency));
- GNUNET_break (0 != strncasecmp ("payto://",
- debit_account,
- strlen ("payto://")));
- GNUNET_break (0 != strncasecmp ("payto://",
- credit_account,
- strlen ("payto://")));
- debit_acc = lookup_account (h,
- debit_account,
- debit_account);
- credit_acc = lookup_account (h,
- credit_account,
- credit_account);
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->rpubs_lock));
- t = GNUNET_CONTAINER_multipeermap_get (h->rpubs,
- pid);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->rpubs_lock));
- if (NULL != t)
- {
- /* duplicate reserve public key not allowed */
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
-
- t = GNUNET_new (struct Transaction);
- t->unchecked = true;
- t->debit_account = debit_acc;
- t->credit_account = credit_acc;
- t->amount = *amount;
- t->date = GNUNET_TIME_timestamp_get ();
- if (NULL != timestamp)
- *timestamp = t->date;
- t->type = T_CREDIT;
- t->subject.credit.reserve_pub = *reserve_pub;
- post_transaction (h,
- t);
- if (NULL != row_id)
- *row_id = t->row_id;
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->rpubs_lock));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multipeermap_put (
- h->rpubs,
- pid,
- t,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->rpubs_lock));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Making transfer from %s to %s over %s and subject %s at row %llu\n",
- debit_account,
- credit_account,
- TALER_amount2s (amount),
- TALER_B2S (reserve_pub),
- (unsigned long long) t->row_id);
- notify_transaction (h,
- t);
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h)
-{
- for (uint64_t i = 0; i<h->ram_limit; i++)
- {
- struct Transaction *t = h->transactions[i];
-
- if ( (NULL != t) &&
- (t->unchecked) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected empty transaction set, but I have:\n");
- check_log (h);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
-}
-
-
-static int
-free_account (void *cls,
- const struct GNUNET_HashCode *key,
- void *val)
-{
- struct Account *account = val;
-
- (void) cls;
- (void) key;
- GNUNET_assert (NULL == account->lp_head);
- GNUNET_free (account->account_name);
- GNUNET_free (account->receiver_name);
- GNUNET_free (account);
- return GNUNET_OK;
-}
-
-
-void
-TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
-{
- if (NULL != h->lp_task)
- {
- GNUNET_SCHEDULER_cancel (h->lp_task);
- h->lp_task = NULL;
- }
-#if EPOLL_SUPPORT
- if (NULL != h->mhd_rfd)
- {
- GNUNET_NETWORK_socket_free_memory_only_ (h->mhd_rfd);
- h->mhd_rfd = NULL;
- }
-#endif
-#ifdef __linux__
- if (-1 != h->lp_event)
-#else
- if (-1 != h->lp_event_in && -1 != h->lp_event_out)
-#endif
- {
- uint64_t val = 1;
- void *ret;
- struct LongPoller *lp;
-
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- h->in_shutdown = true;
- while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
- lp_trigger (lp,
- h);
- GNUNET_break (sizeof (val) ==
-#ifdef __linux__
- write (h->lp_event,
-#else
- write (h->lp_event_in,
-#endif
- &val,
- sizeof (val)));
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- GNUNET_break (0 ==
- pthread_join (h->lp_thread,
- &ret));
- GNUNET_break (NULL == ret);
-#ifdef __linux__
- GNUNET_break (0 == close (h->lp_event));
- h->lp_event = -1;
-#else
- GNUNET_break (0 == close (h->lp_event_in));
- GNUNET_break (0 == close (h->lp_event_out));
- h->lp_event_in = -1;
- h->lp_event_out = -1;
-#endif
- }
- else
- {
- struct LongPoller *lp;
-
- while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
- lp_trigger (lp,
- h);
- }
- if (NULL != h->mhd_bank)
- {
- MHD_stop_daemon (h->mhd_bank);
- h->mhd_bank = NULL;
- }
- if (NULL != h->mhd_task)
- {
- GNUNET_SCHEDULER_cancel (h->mhd_task);
- h->mhd_task = NULL;
- }
- if (NULL != h->accounts)
- {
- GNUNET_CONTAINER_multihashmap_iterate (h->accounts,
- &free_account,
- NULL);
- GNUNET_CONTAINER_multihashmap_destroy (h->accounts);
- }
- GNUNET_CONTAINER_multihashmap_destroy (h->uuid_map);
- GNUNET_CONTAINER_multipeermap_destroy (h->rpubs);
- GNUNET_CONTAINER_heap_destroy (h->lp_heap);
- GNUNET_assert (0 ==
- pthread_mutex_destroy (&h->big_lock));
- GNUNET_assert (0 ==
- pthread_mutex_destroy (&h->uuid_map_lock));
- GNUNET_assert (0 ==
- pthread_mutex_destroy (&h->accounts_lock));
- GNUNET_assert (0 ==
- pthread_mutex_destroy (&h->rpubs_lock));
- for (uint64_t i = 0; i<h->ram_limit; i++)
- GNUNET_free (h->transactions[i]);
- GNUNET_free (h->transactions);
- GNUNET_free (h->my_baseurl);
- GNUNET_free (h->currency);
- GNUNET_free (h);
-}
+#include "fakebank.h"
+#include "fakebank_bank.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_tbi.h"
/**
@@ -1391,9 +43,9 @@ TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
* @a con_cls that might still need to be cleaned up. Call the
* respective function to free the memory.
*
- * @param cls client-defined closure
+ * @param cls a `struct TALER_FAKEBANK_Handle *`
* @param connection connection handle
- * @param con_cls value as set by the last call to
+ * @param con_cls a `struct ConnectionContext *`
* the #MHD_AccessHandlerCallback
* @param toe reason for request termination
* @see #MHD_OPTION_NOTIFY_COMPLETED
@@ -1405,1111 +57,16 @@ handle_mhd_completion_callback (void *cls,
void **con_cls,
enum MHD_RequestTerminationCode toe)
{
- /* struct TALER_FAKEBANK_Handle *h = cls; */
- (void) cls;
- (void) connection;
- (void) toe;
- if (NULL == *con_cls)
- return;
- if (&special_ptr == *con_cls)
- return;
- GNUNET_JSON_post_parser_cleanup (*con_cls);
- *con_cls = NULL;
-}
-
-
-/**
- * Handle incoming HTTP request for /admin/add/incoming.
- *
- * @param h the fakebank handle
- * @param connection the connection
- * @param account account into which to deposit the funds (credit)
- * @param upload_data request data
- * @param upload_data_size size of @a upload_data in bytes
- * @param con_cls closure for request (a `struct Buffer *`)
- * @return MHD result code
- */
-static MHD_RESULT
-handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- const char *account,
- const char *upload_data,
- size_t *upload_data_size,
- void **con_cls)
-{
- enum GNUNET_JSON_PostResult pr;
- json_t *json;
- uint64_t row_id;
- struct GNUNET_TIME_Timestamp timestamp;
-
- pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
- connection,
- con_cls,
- upload_data,
- upload_data_size,
- &json);
- switch (pr)
- {
- case GNUNET_JSON_PR_OUT_OF_MEMORY:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_CONTINUE:
- return MHD_YES;
- case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_JSON_INVALID:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_SUCCESS:
- break;
- }
- {
- const char *debit_account;
- struct TALER_Amount amount;
- struct TALER_ReservePublicKeyP reserve_pub;
- char *debit;
- enum GNUNET_GenericReturnValue ret;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &reserve_pub),
- GNUNET_JSON_spec_string ("debit_account",
- &debit_account),
- TALER_JSON_spec_amount ("amount",
- h->currency,
- &amount),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- (ret = TALER_MHD_parse_json_data (connection,
- json,
- spec)))
- {
- GNUNET_break_op (0);
- json_decref (json);
- return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
- }
- if (0 != strcasecmp (amount.currency,
- h->currency))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Currency `%s' does not match our configuration\n",
- amount.currency);
- json_decref (json);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_CONFLICT,
- TALER_EC_GENERIC_CURRENCY_MISMATCH,
- NULL);
- }
- debit = TALER_xtalerbank_account_from_payto (debit_account);
- if (NULL == debit)
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
- debit_account);
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s\n",
- debit,
- account,
- TALER_B2S (&reserve_pub),
- TALER_amount2s (&amount));
- ret = make_admin_transfer (h,
- debit,
- account,
- &amount,
- &reserve_pub,
- &row_id,
- &timestamp);
- GNUNET_free (debit);
- if (GNUNET_OK != ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Reserve public key not unique\n");
- json_decref (json);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_CONFLICT,
- TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
- NULL);
- }
- }
- json_decref (json);
-
- /* Finally build response object */
- return TALER_MHD_REPLY_JSON_PACK (connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_uint64 ("row_id",
- row_id),
- GNUNET_JSON_pack_timestamp ("timestamp",
- timestamp));
-}
-
-
-/**
- * Handle incoming HTTP request for /transfer.
- *
- * @param h the fakebank handle
- * @param connection the connection
- * @param account account making the transfer
- * @param upload_data request data
- * @param upload_data_size size of @a upload_data in bytes
- * @param con_cls closure for request (a `struct Buffer *`)
- * @return MHD result code
- */
-static MHD_RESULT
-handle_transfer (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- const char *account,
- const char *upload_data,
- size_t *upload_data_size,
- void **con_cls)
-{
- enum GNUNET_JSON_PostResult pr;
- json_t *json;
- uint64_t row_id;
- struct GNUNET_TIME_Timestamp ts;
-
- pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
- connection,
- con_cls,
- upload_data,
- upload_data_size,
- &json);
- switch (pr)
- {
- case GNUNET_JSON_PR_OUT_OF_MEMORY:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_CONTINUE:
- return MHD_YES;
- case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_JSON_INVALID:
- GNUNET_break (0);
- return MHD_NO;
- case GNUNET_JSON_PR_SUCCESS:
- break;
- }
- {
- struct GNUNET_HashCode uuid;
- struct TALER_WireTransferIdentifierRawP wtid;
- const char *credit_account;
- char *credit;
- const char *base_url;
- struct TALER_Amount amount;
- enum GNUNET_GenericReturnValue ret;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("request_uid",
- &uuid),
- TALER_JSON_spec_amount ("amount",
- h->currency,
- &amount),
- GNUNET_JSON_spec_string ("exchange_base_url",
- &base_url),
- GNUNET_JSON_spec_fixed_auto ("wtid",
- &wtid),
- GNUNET_JSON_spec_string ("credit_account",
- &credit_account),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- (ret = TALER_MHD_parse_json_data (connection,
- json,
- spec)))
- {
- GNUNET_break_op (0);
- json_decref (json);
- return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
- }
- {
- enum GNUNET_GenericReturnValue ret;
-
- credit = TALER_xtalerbank_account_from_payto (credit_account);
- if (NULL == credit)
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
- credit_account);
- }
- ret = make_transfer (h,
- account,
- credit,
- &amount,
- &wtid,
- base_url,
- &uuid,
- &row_id,
- &ts);
- if (GNUNET_OK != ret)
- {
- MHD_RESULT res;
- char *uids;
-
- GNUNET_break (0);
- uids = GNUNET_STRINGS_data_to_string_alloc (&uuid,
- sizeof (uuid));
- json_decref (json);
- res = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_CONFLICT,
- TALER_EC_BANK_TRANSFER_REQUEST_UID_REUSED,
- uids);
- GNUNET_free (uids);
- return res;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s, from %s\n",
- account,
- credit,
- TALER_B2S (&wtid),
- TALER_amount2s (&amount),
- base_url);
- GNUNET_free (credit);
- }
- }
- json_decref (json);
-
- /* Finally build response object */
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_uint64 ("row_id",
- row_id),
- GNUNET_JSON_pack_timestamp ("timestamp",
- ts));
-}
-
-
-/**
- * Handle incoming HTTP request for / (home page).
- *
- * @param h the fakebank handle
- * @param connection the connection
- * @return MHD result code
- */
-static MHD_RESULT
-handle_home_page (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection)
-{
- MHD_RESULT ret;
- struct MHD_Response *resp;
-#define HELLOMSG "Hello, Fakebank!"
-
- (void) h;
- resp = MHD_create_response_from_buffer (
- strlen (HELLOMSG),
- HELLOMSG,
- MHD_RESPMEM_MUST_COPY);
- ret = MHD_queue_response (connection,
- MHD_HTTP_OK,
- resp);
- MHD_destroy_response (resp);
- return ret;
-}
-
-
-/**
- * This is the "base" structure for both the /history and the
- * /history-range API calls.
- */
-struct HistoryArgs
-{
-
- /**
- * Bank account number of the requesting client.
- */
- uint64_t account_number;
-
- /**
- * Index of the starting transaction, exclusive (!).
- */
- uint64_t start_idx;
-
- /**
- * Requested number of results and order
- * (positive: ascending, negative: descending)
- */
- int64_t delta;
-
- /**
- * Timeout for long polling.
- */
- struct GNUNET_TIME_Relative lp_timeout;
-
- /**
- * true if starting point was given.
- */
- bool have_start;
-
-};
-
-
-/**
- * Parse URL history arguments, of _both_ APIs:
- * /history/incoming and /history/outgoing.
- *
- * @param h bank handle to work on
- * @param connection MHD connection.
- * @param[out] ha will contain the parsed values.
- * @return #GNUNET_OK only if the parsing succeeds,
- * #GNUNET_SYSERR if it failed,
- * #GNUNET_NO if it failed and an error was returned
- */
-static enum GNUNET_GenericReturnValue
-parse_history_common_args (const struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- struct HistoryArgs *ha)
-{
- const char *start;
- const char *delta;
- const char *long_poll_ms;
- unsigned long long lp_timeout;
- unsigned long long sval;
- long long d;
- char dummy;
-
- start = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "start");
- ha->have_start = (NULL != start);
- delta = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "delta");
- long_poll_ms = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
- "long_poll_ms");
- lp_timeout = 0;
- if ( (NULL == delta) ||
- (1 != sscanf (delta,
- "%lld%c",
- &d,
- &dummy)) )
- {
- /* Fail if one of the above failed. */
- /* Invalid request, given that this is fakebank we impolitely
- * just kill the connection instead of returning a nice error.
- */
- GNUNET_break_op (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "delta"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- if ( (NULL != long_poll_ms) &&
- (1 != sscanf (long_poll_ms,
- "%llu%c",
- &lp_timeout,
- &dummy)) )
- {
- /* Fail if one of the above failed. */
- /* Invalid request, given that this is fakebank we impolitely
- * just kill the connection instead of returning a nice error.
- */
- GNUNET_break_op (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "long_poll_ms"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- if ( (NULL != start) &&
- (1 != sscanf (start,
- "%llu%c",
- &sval,
- &dummy)) )
- {
- /* Fail if one of the above failed. */
- /* Invalid request, given that this is fakebank we impolitely
- * just kill the connection instead of returning a nice error.
- */
- GNUNET_break_op (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "start"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- if (NULL == start)
- ha->start_idx = (d > 0) ? 0 : h->serial_counter;
- else
- ha->start_idx = (uint64_t) sval;
- ha->delta = (int64_t) d;
- if (0 == ha->delta)
- {
- GNUNET_break_op (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "delta"))
- ? GNUNET_NO
- : GNUNET_SYSERR;
- }
- ha->lp_timeout
- = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- lp_timeout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Request for %lld records from %llu\n",
- (long long) ha->delta,
- (unsigned long long) ha->start_idx);
- return GNUNET_OK;
-}
-
-
-/**
- * Task run when a long poller is about to time out.
- * Only used in single-threaded mode.
- *
- * @param cls a `struct TALER_FAKEBANK_Handle *`
- */
-static void
-lp_timeout (void *cls)
-{
struct TALER_FAKEBANK_Handle *h = cls;
- struct LongPoller *lp;
+ struct ConnectionContext *cc = *con_cls;
- h->lp_task = NULL;
- while (NULL != (lp = GNUNET_CONTAINER_heap_peek (h->lp_heap)))
- {
- if (GNUNET_TIME_absolute_is_future (lp->timeout))
- break;
- GNUNET_assert (lp ==
- GNUNET_CONTAINER_heap_remove_root (h->lp_heap));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Timeout reached for long poller %p\n",
- lp->conn);
- lp_trigger (lp,
- h);
- }
- if (NULL == lp)
+ (void) h;
+ (void) connection;
+ (void) toe;
+ if (NULL == cc)
return;
- h->lp_task = GNUNET_SCHEDULER_add_at (lp->timeout,
- &lp_timeout,
- h);
-}
-
-
-/**
- * Reschedule the timeout task of @a h for time @a t.
- *
- * @param h fakebank handle
- * @param t when will the next connection timeout expire
- */
-static void
-reschedule_lp_timeout (struct TALER_FAKEBANK_Handle *h,
- struct GNUNET_TIME_Absolute t)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Scheduling timeout task for %s\n",
- GNUNET_STRINGS_absolute_time_to_string (t));
-#ifdef __linux__
- if (-1 != h->lp_event)
-#else
- if (-1 != h->lp_event_in && -1 != h->lp_event_out)
-#endif
- {
- uint64_t num = 1;
-
- GNUNET_break (sizeof (num) ==
-#ifdef __linux__
- write (h->lp_event,
-#else
- write (h->lp_event_in,
-#endif
- &num,
- sizeof (num)));
- }
- else
- {
- if (NULL != h->lp_task)
- GNUNET_SCHEDULER_cancel (h->lp_task);
- h->lp_task = GNUNET_SCHEDULER_add_at (t,
- &lp_timeout,
- h);
- }
-}
-
-
-/**
- * Start long-polling for @a connection and @a acc
- * for transfers in @a dir. Must be called with the
- * "big lock" held.
- *
- * @param[in,out] h fakebank handle
- * @param[in,out] connection to suspend
- * @param[in,out] acc account affected
- * @param lp_timeout how long to suspend
- * @param dir direction of transfers to watch for
- */
-static void
-start_lp (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- struct Account *acc,
- struct GNUNET_TIME_Relative lp_timeout,
- enum LongPollType dir)
-{
- struct LongPoller *lp;
- bool toc;
-
- lp = GNUNET_new (struct LongPoller);
- lp->account = acc;
- lp->conn = connection;
- lp->timeout = GNUNET_TIME_relative_to_absolute (lp_timeout);
- lp->type = dir;
- lp->hn = GNUNET_CONTAINER_heap_insert (h->lp_heap,
- lp,
- lp->timeout.abs_value_us);
- toc = (lp ==
- GNUNET_CONTAINER_heap_peek (h->lp_heap));
- GNUNET_CONTAINER_DLL_insert (acc->lp_head,
- acc->lp_tail,
- lp);
- MHD_suspend_connection (connection);
- if (toc)
- reschedule_lp_timeout (h,
- lp->timeout);
-
-}
-
-
-/**
- * Handle incoming HTTP request for /history/outgoing
- *
- * @param h the fakebank handle
- * @param connection the connection
- * @param account which account the request is about
- * @param con_cls closure for request (NULL or &special_ptr)
- */
-static MHD_RESULT
-handle_debit_history (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- const char *account,
- void **con_cls)
-{
- struct HistoryArgs ha;
- struct Account *acc;
- struct Transaction *pos;
- json_t *history;
- char *debit_payto;
- enum GNUNET_GenericReturnValue ret;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Handling /history/outgoing connection %p\n",
- connection);
- if (GNUNET_OK !=
- (ret = parse_history_common_args (h,
- connection,
- &ha)))
- {
- GNUNET_break_op (0);
- return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
- }
- if (&special_ptr == *con_cls)
- ha.lp_timeout = GNUNET_TIME_UNIT_ZERO;
- acc = lookup_account (h,
- account,
- NULL);
- if (NULL == acc)
- {
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_BANK_UNKNOWN_ACCOUNT,
- account);
- }
- GNUNET_asprintf (&debit_payto,
- "payto://x-taler-bank/localhost/%s?receiver-name=%s",
- account,
- acc->receiver_name);
- history = json_array ();
- if (NULL == history)
- {
- GNUNET_break (0);
- GNUNET_free (debit_payto);
- return MHD_NO;
- }
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- if (! ha.have_start)
- {
- pos = (0 > ha.delta)
- ? acc->out_tail
- : acc->out_head;
- }
- else
- {
- struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit];
- bool overflow;
- uint64_t dir;
- bool skip = true;
-
- dir = (0 > ha.delta) ? (h->ram_limit - 1) : 1;
- overflow = (t->row_id != ha.start_idx);
- /* If account does not match, linear scan for
- first matching account. */
- while ( (! overflow) &&
- (NULL != t) &&
- (t->debit_account != acc) )
- {
- skip = false;
- t = h->transactions[(t->row_id + dir) % h->ram_limit];
- if ( (NULL != t) &&
- (t->row_id == ha.start_idx) )
- overflow = true; /* full circle, give up! */
- }
- if ( (NULL == t) ||
- overflow)
- {
- GNUNET_free (debit_payto);
- if (GNUNET_TIME_relative_is_zero (ha.lp_timeout) &&
- (0 < ha.delta))
- {
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- if (overflow)
- return TALER_MHD_reply_with_ec (
- connection,
- TALER_EC_BANK_ANCIENT_TRANSACTION_GONE,
- NULL);
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal (
- "outgoing_transactions",
- history));
- }
- *con_cls = &special_ptr;
- start_lp (h,
- connection,
- acc,
- ha.lp_timeout,
- LP_DEBIT);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- json_decref (history);
- return MHD_YES;
- }
- if (t->debit_account != acc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid start specified, transaction %llu not with account %s!\n",
- (unsigned long long) ha.start_idx,
- account);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- GNUNET_free (debit_payto);
- json_decref (history);
- return MHD_NO;
- }
- if (skip)
- {
- /* range is exclusive, skip the matching entry */
- if (0 > ha.delta)
- pos = t->prev_out;
- else
- pos = t->next_out;
- }
- else
- {
- pos = t;
- }
- }
- if (NULL != pos)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Returning %lld debit transactions starting (inclusive) from %llu\n",
- (long long) ha.delta,
- (unsigned long long) pos->row_id);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No debit transactions exist after given starting point\n");
- while ( (0 != ha.delta) &&
- (NULL != pos) )
- {
- json_t *trans;
- char *credit_payto;
-
- if (T_DEBIT != pos->type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unexpected CREDIT transaction #%llu for account `%s'\n",
- (unsigned long long) pos->row_id,
- account);
- if (0 > ha.delta)
- pos = pos->prev_in;
- if (0 < ha.delta)
- pos = pos->next_in;
- continue;
- }
- GNUNET_asprintf (&credit_payto,
- "payto://x-taler-bank/localhost/%s?receiver-name=%s",
- pos->credit_account->account_name,
- pos->credit_account->receiver_name);
-
- trans = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_uint64 ("row_id",
- pos->row_id),
- GNUNET_JSON_pack_timestamp ("date",
- pos->date),
- TALER_JSON_pack_amount ("amount",
- &pos->amount),
- GNUNET_JSON_pack_string ("credit_account",
- credit_payto),
- GNUNET_JSON_pack_string ("debit_account",
- debit_payto), // FIXME: inefficient to return this here always!
- GNUNET_JSON_pack_string ("exchange_base_url",
- pos->subject.debit.exchange_base_url),
- GNUNET_JSON_pack_data_auto ("wtid",
- &pos->subject.debit.wtid));
- GNUNET_assert (NULL != trans);
- GNUNET_free (credit_payto);
- GNUNET_assert (0 ==
- json_array_append_new (history,
- trans));
- if (ha.delta > 0)
- ha.delta--;
- else
- ha.delta++;
- if (0 > ha.delta)
- pos = pos->prev_out;
- if (0 < ha.delta)
- pos = pos->next_out;
- }
- if ( (0 == json_array_size (history)) &&
- (! GNUNET_TIME_relative_is_zero (ha.lp_timeout)) &&
- (0 < ha.delta))
- {
- *con_cls = &special_ptr;
- start_lp (h,
- connection,
- acc,
- ha.lp_timeout,
- LP_DEBIT);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- json_decref (history);
- return MHD_YES;
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- GNUNET_free (debit_payto);
- return TALER_MHD_REPLY_JSON_PACK (connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal (
- "outgoing_transactions",
- history));
-}
-
-
-/**
- * Handle incoming HTTP request for /history/incoming
- *
- * @param h the fakebank handle
- * @param connection the connection
- * @param account which account the request is about
- * @param con_cls closure for request (NULL or &special_ptr)
- * @return MHD result code
- */
-static MHD_RESULT
-handle_credit_history (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- const char *account,
- void **con_cls)
-{
- struct HistoryArgs ha;
- struct Account *acc;
- const struct Transaction *pos;
- json_t *history;
- char *credit_payto;
- enum GNUNET_GenericReturnValue ret;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Handling /history/incoming connection %p (%d)\n",
- connection,
- (*con_cls == &special_ptr));
- if (GNUNET_OK !=
- (ret = parse_history_common_args (h,
- connection,
- &ha)))
- {
- GNUNET_break_op (0);
- return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
- }
- if (&special_ptr == *con_cls)
- ha.lp_timeout = GNUNET_TIME_UNIT_ZERO;
- *con_cls = &special_ptr;
- acc = lookup_account (h,
- account,
- NULL);
- if (NULL == acc)
- {
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_BANK_UNKNOWN_ACCOUNT,
- account);
- }
- history = json_array ();
- GNUNET_assert (NULL != history);
- GNUNET_asprintf (&credit_payto,
- "payto://x-taler-bank/localhost/%s?receiver-name=%s",
- account,
- acc->receiver_name);
-
- GNUNET_assert (0 ==
- pthread_mutex_lock (&h->big_lock));
- if (! ha.have_start)
- {
- pos = (0 > ha.delta)
- ? acc->in_tail
- : acc->in_head;
- }
- else
- {
- struct Transaction *t = h->transactions[ha.start_idx % h->ram_limit];
- bool overflow;
- uint64_t dir;
- bool skip = true;
-
- overflow = ( (NULL != t) && (t->row_id != ha.start_idx) );
- dir = (0 > ha.delta) ? (h->ram_limit - 1) : 1;
- /* If account does not match, linear scan for
- first matching account. */
- while ( (! overflow) &&
- (NULL != t) &&
- (t->credit_account != acc) )
- {
- skip = false;
- t = h->transactions[(t->row_id + dir) % h->ram_limit];
- if ( (NULL != t) &&
- (t->row_id == ha.start_idx) )
- overflow = true; /* full circle, give up! */
- }
- if ( (NULL == t) ||
- overflow)
- {
- GNUNET_free (credit_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No transactions available, suspending request\n");
- if (GNUNET_TIME_relative_is_zero (ha.lp_timeout) &&
- (0 < ha.delta))
- {
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- if (overflow)
- return TALER_MHD_reply_with_ec (
- connection,
- TALER_EC_BANK_ANCIENT_TRANSACTION_GONE,
- NULL);
- return TALER_MHD_REPLY_JSON_PACK (connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal (
- "incoming_transactions",
- history));
- }
- *con_cls = &special_ptr;
- start_lp (h,
- connection,
- acc,
- ha.lp_timeout,
- LP_CREDIT);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- json_decref (history);
- return MHD_YES;
- }
- if (skip)
- {
- /* range from application is exclusive, skip the
- matching entry */
- if (0 > ha.delta)
- pos = t->prev_in;
- else
- pos = t->next_in;
- }
- else
- {
- pos = t;
- }
- }
- if (NULL != pos)
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Returning %lld credit transactions starting (inclusive) from %llu\n",
- (long long) ha.delta,
- (unsigned long long) pos->row_id);
- else
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No credit transactions exist after given starting point\n");
- while ( (0 != ha.delta) &&
- (NULL != pos) )
- {
- json_t *trans;
- char *debit_payto;
-
- if (T_CREDIT != pos->type)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Unexpected DEBIT transaction #%llu for account `%s'\n",
- (unsigned long long) pos->row_id,
- account);
- if (0 > ha.delta)
- pos = pos->prev_in;
- if (0 < ha.delta)
- pos = pos->next_in;
- continue;
- }
- GNUNET_asprintf (&debit_payto,
- "payto://x-taler-bank/localhost/%s?receiver-name=%s",
- pos->debit_account->account_name,
- pos->debit_account->receiver_name);
- trans = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_uint64 ("row_id",
- pos->row_id),
- GNUNET_JSON_pack_timestamp ("date",
- pos->date),
- TALER_JSON_pack_amount ("amount",
- &pos->amount),
- GNUNET_JSON_pack_string ("credit_account",
- credit_payto), // FIXME: inefficient to repeat this always here!
- GNUNET_JSON_pack_string ("debit_account",
- debit_payto),
- GNUNET_JSON_pack_data_auto ("reserve_pub",
- &pos->subject.credit.reserve_pub));
- GNUNET_assert (NULL != trans);
- GNUNET_free (debit_payto);
- GNUNET_assert (0 ==
- json_array_append_new (history,
- trans));
- if (ha.delta > 0)
- ha.delta--;
- else
- ha.delta++;
- if (0 > ha.delta)
- pos = pos->prev_in;
- if (0 < ha.delta)
- pos = pos->next_in;
- }
- if ( (0 == json_array_size (history)) &&
- (! GNUNET_TIME_relative_is_zero (ha.lp_timeout)) &&
- (0 < ha.delta))
- {
- *con_cls = &special_ptr;
- start_lp (h,
- connection,
- acc,
- ha.lp_timeout,
- LP_CREDIT);
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- json_decref (history);
- return MHD_YES;
- }
- GNUNET_assert (0 ==
- pthread_mutex_unlock (&h->big_lock));
- GNUNET_free (credit_payto);
- return TALER_MHD_REPLY_JSON_PACK (connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal (
- "incoming_transactions",
- history));
-}
-
-
-/**
- * Handle incoming HTTP request.
- *
- * @param h our handle
- * @param connection the connection
- * @param url the requested url
- * @param method the method (POST, GET, ...)
- * @param account which account should process the request
- * @param upload_data request data
- * @param upload_data_size size of @a upload_data in bytes
- * @param con_cls closure
- * @return MHD result code
- */
-static MHD_RESULT
-serve (struct TALER_FAKEBANK_Handle *h,
- struct MHD_Connection *connection,
- const char *account,
- const char *url,
- const char *method,
- const char *upload_data,
- size_t *upload_data_size,
- void **con_cls)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Fakebank, serving URL `%s' for account `%s'\n",
- url,
- account);
- if (0 == strcasecmp (method,
- MHD_HTTP_METHOD_GET))
- {
- if ( (0 == strcmp (url,
- "/history/incoming")) &&
- (NULL != account) )
- return handle_credit_history (h,
- connection,
- account,
- con_cls);
- if ( (0 == strcmp (url,
- "/history/outgoing")) &&
- (NULL != account) )
- return handle_debit_history (h,
- connection,
- account,
- con_cls);
- if (0 == strcmp (url,
- "/"))
- return handle_home_page (h,
- connection);
- }
- else if (0 == strcasecmp (method,
- MHD_HTTP_METHOD_POST))
- {
- if ( (0 == strcmp (url,
- "/admin/add-incoming")) &&
- (NULL != account) )
- return handle_admin_add_incoming (h,
- connection,
- account,
- upload_data,
- upload_data_size,
- con_cls);
- if ( (0 == strcmp (url,
- "/transfer")) &&
- (NULL != account) )
- return handle_transfer (h,
- connection,
- account,
- upload_data,
- upload_data_size,
- con_cls);
- }
- /* Unexpected URL path, just close the connection. */
- TALER_LOG_ERROR ("Breaking URL: %s %s\n",
- method,
- url);
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
- url);
+ cc->ctx_cleaner (cc->ctx);
+ GNUNET_free (cc);
}
@@ -2537,35 +94,28 @@ handle_mhd_request (void *cls,
void **con_cls)
{
struct TALER_FAKEBANK_Handle *h = cls;
- char *account = NULL;
- char *end;
- MHD_RESULT ret;
(void) version;
if (0 == strncmp (url,
- "/taler-wire-gateway/",
- strlen ("/taler-wire-gateway/")))
- url += strlen ("/taler-wire-gateway");
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Handling request for `%s'\n",
- url);
- if ( (strlen (url) > 1) &&
- (NULL != (end = strchr (url + 1, '/'))) )
- {
- account = GNUNET_strndup (url + 1,
- end - url - 1);
- url = end;
- }
- ret = serve (h,
- connection,
- account,
- url,
- method,
- upload_data,
- upload_data_size,
- con_cls);
- GNUNET_free (account);
- return ret;
+ "/taler-integration/",
+ strlen ("/taler-integration/")))
+ {
+ url += strlen ("/taler-integration");
+ return TALER_FAKEBANK_tbi_main_ (h,
+ connection,
+ url,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ }
+ return TALER_FAKEBANK_bank_main_ (h,
+ connection,
+ url,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
}
@@ -2596,7 +146,7 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h)
h->mhd_task =
GNUNET_SCHEDULER_add_read_net (tv,
h->mhd_rfd,
- &run_mhd,
+ &TALER_FAKEBANK_run_mhd_,
h);
}
@@ -2670,7 +220,7 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h)
tv,
wrs,
wws,
- &run_mhd,
+ &TALER_FAKEBANK_run_mhd_,
h);
if (NULL != wrs)
GNUNET_NETWORK_fdset_destroy (wrs);
@@ -2687,8 +237,8 @@ schedule_httpd (struct TALER_FAKEBANK_Handle *h)
*
* @param cls the `struct TALER_FAKEBANK_Handle`
*/
-static void
-run_mhd (void *cls)
+void
+TALER_FAKEBANK_run_mhd_ (void *cls)
{
struct TALER_FAKEBANK_Handle *h = cls;
@@ -2726,6 +276,34 @@ TALER_FAKEBANK_start2 (uint16_t port,
uint64_t ram_limit,
unsigned int num_threads)
{
+ struct TALER_Amount zero;
+
+ if (GNUNET_OK !=
+ TALER_amount_set_zero (currency,
+ &zero))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ return TALER_FAKEBANK_start3 ("localhost",
+ port,
+ NULL,
+ currency,
+ ram_limit,
+ num_threads,
+ &zero);
+}
+
+
+struct TALER_FAKEBANK_Handle *
+TALER_FAKEBANK_start3 (const char *hostname,
+ uint16_t port,
+ const char *exchange_url,
+ const char *currency,
+ uint64_t ram_limit,
+ unsigned int num_threads,
+ const struct TALER_Amount *signup_bonus)
+{
struct TALER_FAKEBANK_Handle *h;
if (SIZE_MAX / sizeof (struct Transaction *) < ram_limit)
@@ -2736,7 +314,16 @@ TALER_FAKEBANK_start2 (uint16_t port,
return NULL;
}
GNUNET_assert (strlen (currency) < TALER_CURRENCY_LEN);
+ if (0 != strcmp (signup_bonus->currency,
+ currency))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
h = GNUNET_new (struct TALER_FAKEBANK_Handle);
+ h->signup_bonus = *signup_bonus;
+ if (NULL != exchange_url)
+ h->exchange_url = GNUNET_strdup (exchange_url);
#ifdef __linux__
h->lp_event = -1;
#else
@@ -2793,27 +380,30 @@ TALER_FAKEBANK_start2 (uint16_t port,
}
h->lp_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
h->currency = GNUNET_strdup (currency);
+ h->hostname = GNUNET_strdup (hostname);
GNUNET_asprintf (&h->my_baseurl,
- "http://localhost:%u/",
+ "http://%s:%u/",
+ h->hostname,
(unsigned int) port);
if (0 == num_threads)
{
- h->mhd_bank = MHD_start_daemon (MHD_USE_DEBUG
+ h->mhd_bank = MHD_start_daemon (
+ MHD_USE_DEBUG
#if EPOLL_SUPPORT
- | MHD_USE_EPOLL
+ | MHD_USE_EPOLL
#endif
- | MHD_USE_DUAL_STACK
- | MHD_ALLOW_SUSPEND_RESUME,
- port,
- NULL, NULL,
- &handle_mhd_request, h,
- MHD_OPTION_NOTIFY_COMPLETED,
- &handle_mhd_completion_callback, h,
- MHD_OPTION_LISTEN_BACKLOG_SIZE,
- (unsigned int) 1024,
- MHD_OPTION_CONNECTION_LIMIT,
- (unsigned int) 65536,
- MHD_OPTION_END);
+ | MHD_USE_DUAL_STACK
+ | MHD_ALLOW_SUSPEND_RESUME,
+ port,
+ NULL, NULL,
+ &handle_mhd_request, h,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &handle_mhd_completion_callback, h,
+ MHD_OPTION_LISTEN_BACKLOG_SIZE,
+ (unsigned int) 1024,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 65536,
+ MHD_OPTION_END);
if (NULL == h->mhd_bank)
{
TALER_FAKEBANK_stop (h);
@@ -2856,7 +446,7 @@ TALER_FAKEBANK_start2 (uint16_t port,
if (0 !=
pthread_create (&h->lp_thread,
NULL,
- &lp_expiration_thread,
+ &TALER_FAKEBANK_lp_expiration_thread_,
h))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
@@ -2873,24 +463,25 @@ TALER_FAKEBANK_start2 (uint16_t port,
TALER_FAKEBANK_stop (h);
return NULL;
}
- h->mhd_bank = MHD_start_daemon (MHD_USE_DEBUG
- | MHD_USE_AUTO_INTERNAL_THREAD
- | MHD_ALLOW_SUSPEND_RESUME
- | MHD_USE_TURBO
- | MHD_USE_TCP_FASTOPEN
- | MHD_USE_DUAL_STACK,
- port,
- NULL, NULL,
- &handle_mhd_request, h,
- MHD_OPTION_NOTIFY_COMPLETED,
- &handle_mhd_completion_callback, h,
- MHD_OPTION_LISTEN_BACKLOG_SIZE,
- (unsigned int) 1024,
- MHD_OPTION_CONNECTION_LIMIT,
- (unsigned int) 65536,
- MHD_OPTION_THREAD_POOL_SIZE,
- num_threads,
- MHD_OPTION_END);
+ h->mhd_bank = MHD_start_daemon (
+ MHD_USE_DEBUG
+ | MHD_USE_AUTO_INTERNAL_THREAD
+ | MHD_ALLOW_SUSPEND_RESUME
+ | MHD_USE_TURBO
+ | MHD_USE_TCP_FASTOPEN
+ | MHD_USE_DUAL_STACK,
+ port,
+ NULL, NULL,
+ &handle_mhd_request, h,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &handle_mhd_completion_callback, h,
+ MHD_OPTION_LISTEN_BACKLOG_SIZE,
+ (unsigned int) 1024,
+ MHD_OPTION_CONNECTION_LIMIT,
+ (unsigned int) 65536,
+ MHD_OPTION_THREAD_POOL_SIZE,
+ num_threads,
+ MHD_OPTION_END);
if (NULL == h->mhd_bank)
{
GNUNET_break (0);
diff --git a/src/bank-lib/fakebank.h b/src/bank-lib/fakebank.h
new file mode 100644
index 000000000..a9d61d8b1
--- /dev/null
+++ b/src/bank-lib/fakebank.h
@@ -0,0 +1,691 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank.h
+ * @brief general state of the fakebank
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_H
+#define FAKEBANK_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+
+
+/**
+ * How long are exchange base URLs allowed to be at most?
+ * Set to a relatively low number as this does contribute
+ * significantly to our RAM consumption.
+ */
+#define MAX_URL_LEN 64
+
+
+/**
+ * Maximum POST request size.
+ */
+#define REQUEST_BUFFER_MAX (4 * 1024)
+
+
+/**
+ * Per account information.
+ */
+struct Account;
+
+
+/**
+ * Types of long polling activities.
+ */
+enum LongPollType
+{
+ /**
+ * Transfer TO the exchange.
+ */
+ LP_CREDIT,
+
+ /**
+ * Transfer FROM the exchange.
+ */
+ LP_DEBIT,
+
+ /**
+ * Withdraw operation completion/abort.
+ */
+ LP_WITHDRAW
+
+};
+
+/**
+ * Client waiting for activity on this account.
+ */
+struct LongPoller
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct LongPoller *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct LongPoller *prev;
+
+ /**
+ * Fakebank this long poller belongs with.
+ */
+ struct TALER_FAKEBANK_Handle *h;
+
+ /**
+ * Account this long poller is waiting on.
+ */
+ struct Account *account;
+
+ /**
+ * Withdraw operation we are waiting on,
+ * only if @e type is #LP_WITHDRAW, otherwise NULL.
+ */
+ const struct WithdrawalOperation *wo;
+
+ /**
+ * Entry in the heap for this long poller.
+ */
+ struct GNUNET_CONTAINER_HeapNode *hn;
+
+ /**
+ * Client that is waiting for transactions.
+ */
+ struct MHD_Connection *conn;
+
+ /**
+ * When will this long poller time out?
+ */
+ struct GNUNET_TIME_Absolute timeout;
+
+ /**
+ * What does the @e connection wait for?
+ */
+ enum LongPollType type;
+
+};
+
+
+/**
+ * Details about a transcation we (as the simulated bank) received.
+ */
+struct Transaction;
+
+
+/**
+ * Information we keep per withdraw operation.
+ */
+struct WithdrawalOperation
+{
+ /**
+ * Unique (random) operation ID.
+ */
+ struct GNUNET_ShortHashCode wopid;
+
+ /**
+ * Debited account.
+ */
+ struct Account *debit_account;
+
+ /**
+ * Target exchange account, or NULL if unknown.
+ */
+ const struct Account *exchange_account;
+
+ /**
+ * RowID of the resulting transaction, if any. Otherwise 0.
+ */
+ uint64_t row_id;
+
+ /**
+ * Amount transferred.
+ */
+ struct TALER_Amount amount;
+
+ /**
+ * Public key of the reserve, wire transfer subject.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * When was the transaction made? 0 if not yet.
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ /**
+ * Was the withdrawal aborted?
+ */
+ bool aborted;
+
+ /**
+ * Did the bank confirm the withdrawal?
+ */
+ bool confirmation_done;
+
+ /**
+ * Is @e reserve_pub initialized?
+ */
+ bool selection_done;
+
+};
+
+
+/**
+ * Per account information.
+ */
+struct Account
+{
+
+ /**
+ * Inbound transactions for this account in a MDLL.
+ */
+ struct Transaction *in_head;
+
+ /**
+ * Inbound transactions for this account in a MDLL.
+ */
+ struct Transaction *in_tail;
+
+ /**
+ * Outbound transactions for this account in a MDLL.
+ */
+ struct Transaction *out_head;
+
+ /**
+ * Outbound transactions for this account in a MDLL.
+ */
+ struct Transaction *out_tail;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct LongPoller *lp_head;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct LongPoller *lp_tail;
+
+ /**
+ * Account name (string, not payto!)
+ */
+ char *account_name;
+
+ /**
+ * Receiver name for payto:// URIs.
+ */
+ char *receiver_name;
+
+ /**
+ * Payto URI for this account.
+ */
+ char *payto_uri;
+
+ /**
+ * Password set for the account (if any).
+ */
+ char *password;
+
+ /**
+ * Current account balance.
+ */
+ struct TALER_Amount balance;
+
+ /**
+ * true if the balance is negative.
+ */
+ bool is_negative;
+
+};
+
+
+/**
+ * Details about a transcation we (as the simulated bank) received.
+ */
+struct Transaction
+{
+ /**
+ * We store inbound transactions in a MDLL.
+ */
+ struct Transaction *next_in;
+
+ /**
+ * We store inbound transactions in a MDLL.
+ */
+ struct Transaction *prev_in;
+
+ /**
+ * We store outbound transactions in a MDLL.
+ */
+ struct Transaction *next_out;
+
+ /**
+ * We store outbound transactions in a MDLL.
+ */
+ struct Transaction *prev_out;
+
+ /**
+ * Amount to be transferred.
+ */
+ struct TALER_Amount amount;
+
+ /**
+ * Account to debit.
+ */
+ struct Account *debit_account;
+
+ /**
+ * Account to credit.
+ */
+ struct Account *credit_account;
+
+ /**
+ * Random unique identifier for the request.
+ * Used to detect idempotent requests.
+ */
+ struct GNUNET_HashCode request_uid;
+
+ /**
+ * When did the transaction happen?
+ */
+ struct GNUNET_TIME_Timestamp date;
+
+ /**
+ * Number of this transaction.
+ */
+ uint64_t row_id;
+
+ /**
+ * What does the @e subject contain?
+ */
+ enum
+ {
+ /**
+ * Transfer TO the exchange.
+ */
+ T_CREDIT,
+
+ /**
+ * Transfer FROM the exchange.
+ */
+ T_DEBIT,
+
+ /**
+ * Exchange-to-exchange WAD transfer.
+ */
+ T_WAD,
+ } type;
+
+ /**
+ * Wire transfer subject.
+ */
+ union
+ {
+
+ /**
+ * Used if @e type is T_DEBIT.
+ */
+ struct
+ {
+
+ /**
+ * Subject of the transfer.
+ */
+ struct TALER_WireTransferIdentifierRawP wtid;
+
+ /**
+ * Base URL of the exchange.
+ */
+ char exchange_base_url[MAX_URL_LEN];
+
+ } debit;
+
+ /**
+ * Used if @e type is T_CREDIT.
+ */
+ struct
+ {
+
+ /**
+ * Reserve public key of the credit operation.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ } credit;
+
+ /**
+ * Used if @e type is T_WAD.
+ */
+ struct
+ {
+
+ /**
+ * Subject of the transfer.
+ */
+ struct TALER_WadIdentifierP wad;
+
+ /**
+ * Base URL of the originating exchange.
+ */
+ char origin_base_url[MAX_URL_LEN];
+
+ } wad;
+
+ } subject;
+
+ /**
+ * Has this transaction not yet been subjected to
+ * #TALER_FAKEBANK_check_credit() or #TALER_FAKEBANK_check_debit() and
+ * should thus be counted in #TALER_FAKEBANK_check_empty()?
+ */
+ bool unchecked;
+};
+
+
+/**
+ * Function called to clean up context of a connection.
+ *
+ * @param ctx context to clean up
+ */
+typedef void
+(*ConnectionCleaner)(void *ctx);
+
+/**
+ * Universal context we keep per connection.
+ */
+struct ConnectionContext
+{
+ /**
+ * Function we call upon completion to clean up.
+ */
+ ConnectionCleaner ctx_cleaner;
+
+ /**
+ * Request-handler specific context.
+ */
+ void *ctx;
+};
+
+
+/**
+ * This is the "base" structure for both the /history and the
+ * /history-range API calls.
+ */
+struct HistoryArgs
+{
+
+ /**
+ * Bank account number of the requesting client.
+ */
+ uint64_t account_number;
+
+ /**
+ * Index of the starting transaction, exclusive (!).
+ */
+ uint64_t start_idx;
+
+ /**
+ * Requested number of results and order
+ * (positive: ascending, negative: descending)
+ */
+ int64_t delta;
+
+ /**
+ * Timeout for long polling.
+ */
+ struct GNUNET_TIME_Relative lp_timeout;
+
+ /**
+ * true if starting point was given.
+ */
+ bool have_start;
+
+};
+
+
+/**
+ * Context we keep per history request.
+ */
+struct HistoryContext
+{
+ /**
+ * When does this request time out.
+ */
+ struct GNUNET_TIME_Absolute timeout;
+
+ /**
+ * Client arguments for this request.
+ */
+ struct HistoryArgs ha;
+
+ /**
+ * Account the request is about.
+ */
+ struct Account *acc;
+
+ /**
+ * JSON object we are building to return.
+ */
+ json_t *history;
+
+};
+
+
+/**
+ * Context we keep per get withdrawal operation request.
+ */
+struct WithdrawContext
+{
+ /**
+ * When does this request time out.
+ */
+ struct GNUNET_TIME_Absolute timeout;
+
+ /**
+ * The withdrawal operation this is about.
+ */
+ struct WithdrawalOperation *wo;
+
+};
+
+
+/**
+ * Handle for the fake bank.
+ */
+struct TALER_FAKEBANK_Handle
+{
+ /**
+ * We store transactions in a revolving array.
+ */
+ struct Transaction **transactions;
+
+ /**
+ * HTTP server we run to pretend to be the "test" bank.
+ */
+ struct MHD_Daemon *mhd_bank;
+
+ /**
+ * Task running HTTP server for the "test" bank,
+ * unless we are using a thread pool (then NULL).
+ */
+ struct GNUNET_SCHEDULER_Task *mhd_task;
+
+ /**
+ * Task for expiring long-polling connections,
+ * unless we are using a thread pool (then NULL).
+ */
+ struct GNUNET_SCHEDULER_Task *lp_task;
+
+ /**
+ * Task for expiring long-polling connections, unless we are using the
+ * GNUnet scheduler (then NULL).
+ */
+ pthread_t lp_thread;
+
+ /**
+ * MIN-heap of long pollers, sorted by timeout.
+ */
+ struct GNUNET_CONTAINER_Heap *lp_heap;
+
+ /**
+ * Hashmap of reserve public keys to
+ * `struct Transaction` with that reserve public
+ * key. Used to prevent public-key reuse.
+ */
+ struct GNUNET_CONTAINER_MultiPeerMap *rpubs;
+
+ /**
+ * Hashmap of short hashes (wopids) to
+ * `struct WithdrawalOperation`.
+ * Used to lookup withdrawal operations.
+ */
+ struct GNUNET_CONTAINER_MultiShortmap *wops;
+
+ /**
+ * (Base) URL to suggest for the exchange. Can
+ * be NULL if there is no suggestion to be made.
+ */
+ char *exchange_url;
+
+ /**
+ * Lock for accessing @a rpubs map.
+ */
+ pthread_mutex_t rpubs_lock;
+
+ /**
+ * Hashmap of hashes of account names to `struct Account`.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *accounts;
+
+ /**
+ * Lock for accessing @a accounts hash map.
+ */
+ pthread_mutex_t accounts_lock;
+
+ /**
+ * Hashmap of hashes of transaction request_uids to `struct Transaction`.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *uuid_map;
+
+ /**
+ * Lock for accessing @a uuid_map.
+ */
+ pthread_mutex_t uuid_map_lock;
+
+ /**
+ * Lock for accessing the internals of
+ * accounts and transaction array entries.
+ */
+ pthread_mutex_t big_lock;
+
+ /**
+ * How much money should be put into new accounts
+ * on /register.
+ */
+ struct TALER_Amount signup_bonus;
+
+ /**
+ * Current transaction counter.
+ */
+ uint64_t serial_counter;
+
+ /**
+ * Number of transactions we keep in memory (at most).
+ */
+ uint64_t ram_limit;
+
+ /**
+ * Currency used by the fakebank.
+ */
+ char *currency;
+
+ /**
+ * Hostname of the fakebank.
+ */
+ char *hostname;
+
+ /**
+ * BaseURL of the fakebank.
+ */
+ char *my_baseurl;
+
+ /**
+ * Our port number.
+ */
+ uint16_t port;
+
+#ifdef __linux__
+ /**
+ * Event FD to signal @a lp_thread a change in
+ * @a lp_heap.
+ */
+ int lp_event;
+#else
+ /**
+ * Pipe input to signal @a lp_thread a change in
+ * @a lp_heap.
+ */
+ int lp_event_in;
+
+ /**
+ * Pipe output to signal @a lp_thread a change in
+ * @a lp_heap.
+ */
+ int lp_event_out;
+#endif
+
+ /**
+ * Set to true once we are shutting down.
+ */
+ bool in_shutdown;
+
+ /**
+ * Should we run MHD immediately again?
+ */
+ bool mhd_again;
+
+#if EPOLL_SUPPORT
+ /**
+ * Boxed @e mhd_fd.
+ */
+ struct GNUNET_NETWORK_Handle *mhd_rfd;
+
+ /**
+ * File descriptor to use to wait for MHD.
+ */
+ int mhd_fd;
+#endif
+};
+
+
+/**
+ * Task run whenever HTTP server operations are pending.
+ *
+ * @param cls the `struct TALER_FAKEBANK_Handle`
+ */
+void
+TALER_FAKEBANK_run_mhd_ (void *cls);
+
+
+#endif
diff --git a/src/bank-lib/fakebank_api_check.c b/src/bank-lib/fakebank_api_check.c
new file mode 100644
index 000000000..04656ebab
--- /dev/null
+++ b/src/bank-lib/fakebank_api_check.c
@@ -0,0 +1,238 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_api_check.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+
+
+/**
+ * Generate log messages for failed check operation.
+ *
+ * @param h handle to output transaction log for
+ */
+static void
+check_log (struct TALER_FAKEBANK_Handle *h)
+{
+ for (uint64_t i = 0; i<h->ram_limit; i++)
+ {
+ struct Transaction *t = h->transactions[i];
+
+ if (NULL == t)
+ continue;
+ if (! t->unchecked)
+ continue;
+ switch (t->type)
+ {
+ case T_DEBIT:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s -> %s (%s) %s (%s)\n",
+ t->debit_account->account_name,
+ t->credit_account->account_name,
+ TALER_amount2s (&t->amount),
+ t->subject.debit.exchange_base_url,
+ "DEBIT");
+ break;
+ case T_CREDIT:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s -> %s (%s) %s (%s)\n",
+ t->debit_account->account_name,
+ t->credit_account->account_name,
+ TALER_amount2s (&t->amount),
+ TALER_B2S (&t->subject.credit.reserve_pub),
+ "CREDIT");
+ break;
+ case T_WAD:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "%s -> %s (%s) %s[%s] (%s)\n",
+ t->debit_account->account_name,
+ t->credit_account->account_name,
+ TALER_amount2s (&t->amount),
+ t->subject.wad.origin_base_url,
+ TALER_B2S (&t->subject.wad),
+ "WAD");
+ break;
+ }
+ }
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_check_debit (struct TALER_FAKEBANK_Handle *h,
+ const struct TALER_Amount *want_amount,
+ const char *want_debit,
+ const char *want_credit,
+ const char *exchange_base_url,
+ struct TALER_WireTransferIdentifierRawP *wtid)
+{
+ struct Account *debit_account;
+ struct Account *credit_account;
+
+ GNUNET_assert (0 ==
+ strcasecmp (want_amount->currency,
+ h->currency));
+ debit_account = TALER_FAKEBANK_lookup_account_ (h,
+ want_debit,
+ NULL);
+ credit_account = TALER_FAKEBANK_lookup_account_ (h,
+ want_credit,
+ NULL);
+ if (NULL == debit_account)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted: %s->%s (%s) from exchange %s (DEBIT), but debit account does not even exist!\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ exchange_base_url);
+ return GNUNET_SYSERR;
+ }
+ if (NULL == credit_account)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted: %s->%s (%s) from exchange %s (DEBIT), but credit account does not even exist!\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ exchange_base_url);
+ return GNUNET_SYSERR;
+ }
+ for (struct Transaction *t = debit_account->out_tail;
+ NULL != t;
+ t = t->prev_out)
+ {
+ if ( (t->unchecked) &&
+ (credit_account == t->credit_account) &&
+ (T_DEBIT == t->type) &&
+ (0 == TALER_amount_cmp (want_amount,
+ &t->amount)) &&
+ (0 == strcasecmp (exchange_base_url,
+ t->subject.debit.exchange_base_url)) )
+ {
+ *wtid = t->subject.debit.wtid;
+ t->unchecked = false;
+ return GNUNET_OK;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find matching transaction! I have:\n");
+ check_log (h);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted: %s->%s (%s) from exchange %s (DEBIT)\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ exchange_base_url);
+ return GNUNET_SYSERR;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_check_credit (struct TALER_FAKEBANK_Handle *h,
+ const struct TALER_Amount *want_amount,
+ const char *want_debit,
+ const char *want_credit,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
+{
+ struct Account *debit_account;
+ struct Account *credit_account;
+
+ GNUNET_assert (0 == strcasecmp (want_amount->currency,
+ h->currency));
+ debit_account = TALER_FAKEBANK_lookup_account_ (h,
+ want_debit,
+ NULL);
+ credit_account = TALER_FAKEBANK_lookup_account_ (h,
+ want_credit,
+ NULL);
+ if (NULL == debit_account)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted:\n%s -> %s (%s) with subject %s (CREDIT) but debit account is unknown.\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ TALER_B2S (reserve_pub));
+ return GNUNET_SYSERR;
+ }
+ if (NULL == credit_account)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted:\n%s -> %s (%s) with subject %s (CREDIT) but credit account is unknown.\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ TALER_B2S (reserve_pub));
+ return GNUNET_SYSERR;
+ }
+ for (struct Transaction *t = credit_account->in_tail;
+ NULL != t;
+ t = t->prev_in)
+ {
+ if ( (t->unchecked) &&
+ (debit_account == t->debit_account) &&
+ (T_CREDIT == t->type) &&
+ (0 == TALER_amount_cmp (want_amount,
+ &t->amount)) &&
+ (0 == GNUNET_memcmp (reserve_pub,
+ &t->subject.credit.reserve_pub)) )
+ {
+ t->unchecked = false;
+ return GNUNET_OK;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Did not find matching transaction!\nI have:\n");
+ check_log (h);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "I wanted:\n%s -> %s (%s) with subject %s (CREDIT)\n",
+ want_debit,
+ want_credit,
+ TALER_amount2s (want_amount),
+ TALER_B2S (reserve_pub));
+ return GNUNET_SYSERR;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_check_empty (struct TALER_FAKEBANK_Handle *h)
+{
+ for (uint64_t i = 0; i<h->ram_limit; i++)
+ {
+ struct Transaction *t = h->transactions[i];
+
+ if ( (NULL != t) &&
+ (t->unchecked) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected empty transaction set, but I have:\n");
+ check_log (h);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
diff --git a/src/bank-lib/fakebank_bank.c b/src/bank-lib/fakebank_bank.c
new file mode 100644
index 000000000..7c2d39ab4
--- /dev/null
+++ b/src/bank-lib/fakebank_bank.c
@@ -0,0 +1,524 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank.c
+ * @brief Main dispatcher for the Taler Bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank.h"
+#include "fakebank_tbr.h"
+#include "fakebank_twg.h"
+#include "fakebank_bank_get_accounts.h"
+#include "fakebank_bank_get_withdrawals.h"
+#include "fakebank_bank_get_root.h"
+#include "fakebank_bank_post_accounts_withdrawals.h"
+#include "fakebank_bank_post_withdrawals_abort.h"
+#include "fakebank_bank_post_withdrawals_confirm.h"
+#include "fakebank_bank_post_withdrawals_id_op.h"
+#include "fakebank_bank_testing_register.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_main_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_HEAD))
+ method = MHD_HTTP_METHOD_GET;
+
+ if ( (0 == strcmp (url,
+ "/")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET / */
+ return TALER_FAKEBANK_bank_get_root_ (h,
+ connection);
+ }
+
+ if ( (0 == strcmp (url,
+ "/config")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /config */
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("version",
+ "4:0:4"), /* not sure, API versions are not properly marked up! */
+ GNUNET_JSON_pack_string ("currency",
+ h->currency),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:bank:fakebank"),
+ GNUNET_JSON_pack_string ("name",
+ "taler-corebank"));
+ }
+
+ if ( (0 == strcmp (url,
+ "/public-accounts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /public-accounts */
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("public_accounts",
+ json_array ()));
+ }
+
+ /* account registration API */
+ if ( (0 == strcmp (url,
+ "/accounts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST)) )
+ {
+ /* POST /accounts */
+ return TALER_FAKEBANK_bank_testing_register_ (h,
+ connection,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ }
+
+ if ( (0 == strcmp (url,
+ "/accounts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /accounts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (0 == strcmp (url,
+ "/cashout-rate")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /cashout-rate */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (0 == strcmp (url,
+ "/cashouts")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /cashouts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (0 == strncmp (url,
+ "/withdrawals/",
+ strlen ("/withdrawals/"))) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /withdrawals/$WID */
+ const char *wid;
+
+ wid = &url[strlen ("/withdrawals/")];
+ return TALER_FAKEBANK_bank_get_withdrawals_ (h,
+ connection,
+ wid);
+ }
+
+ if ( (0 == strncmp (url,
+ "/withdrawals/",
+ strlen ("/withdrawals/"))) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST)) )
+ {
+ /* POST /withdrawals/$WID* */
+ const char *wid = url + strlen ("/withdrawals/");
+ const char *opid = strchr (wid,
+ '/');
+ char *wi;
+
+ if (NULL == opid)
+ {
+ /* POST /withdrawals/$WID (not defined) */
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+ }
+ wi = GNUNET_strndup (wid,
+ opid - wid);
+ if (0 == strcmp (opid,
+ "/abort"))
+ {
+ /* POST /withdrawals/$WID/abort */
+ MHD_RESULT ret;
+
+ ret = TALER_FAKEBANK_bank_withdrawals_abort_ (h,
+ connection,
+ wi);
+ GNUNET_free (wi);
+ return ret;
+ }
+ if (0 == strcmp (opid,
+ "/confirm"))
+ {
+ /* POST /withdrawals/$WID/confirm */
+ MHD_RESULT ret;
+
+ ret = TALER_FAKEBANK_bank_withdrawals_confirm_ (h,
+ connection,
+ wi);
+ GNUNET_free (wi);
+ return ret;
+ }
+ }
+
+ if (0 == strncmp (url,
+ "/accounts/",
+ strlen ("/accounts/")))
+ {
+ const char *acc_name = &url[strlen ("/accounts/")];
+ const char *end_acc = strchr (acc_name,
+ '/');
+
+ if ( (NULL != end_acc) &&
+ (0 == strncmp (end_acc,
+ "/taler-wire-gateway/",
+ strlen ("/taler-wire-gateway/"))) )
+ {
+ /* $METHOD /accounts/$ACCOUNT/taler-wire-gateway/ */
+ char *acc;
+ MHD_RESULT ret;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ end_acc += strlen ("/taler-wire-gateway");
+ ret = TALER_FAKEBANK_twg_main_ (h,
+ connection,
+ acc,
+ end_acc,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (acc);
+ return ret;
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strncmp (end_acc,
+ "/taler-revenue/",
+ strlen ("/taler-revenue/"))) )
+ {
+ /* $METHOD /accounts/$ACCOUNT/taler-revenue/ */
+ char *acc;
+ MHD_RESULT ret;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ end_acc += strlen ("/taler-revenue");
+ ret = TALER_FAKEBANK_tbr_main_ (h,
+ connection,
+ acc,
+ end_acc,
+ method,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (acc);
+ return ret;
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /accounts/$ACCOUNT */
+ return TALER_FAKEBANK_bank_get_accounts_ (h,
+ connection,
+ acc_name);
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_PATCH)) )
+ {
+ /* PATCH /accounts/$USERNAME */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL == end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_DELETE)) )
+ {
+ /* DELETE /accounts/$USERNAME */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strcmp ("/auth",
+ end_acc)) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_PATCH)) )
+ {
+ /* PATCH /accounts/$USERNAME/auth */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /accounts/$ACCOUNT/+ */
+
+ if (0 == strcmp (end_acc,
+ "/transactions"))
+ {
+ /* GET /accounts/$USERNAME/transactions */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/transactions/",
+ strlen ("/transactions/")))
+ {
+ /* GET /accounts/$USERNAME/transactions/$TID */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strcmp (end_acc,
+ "/withdrawals"))
+ {
+ /* GET /accounts/$USERNAME/withdrawals */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strcmp (end_acc,
+ "/cashouts"))
+ {
+ /* GET /accounts/$USERNAME/cashouts */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/cashouts/",
+ strlen ("/cashouts/")))
+ {
+ /* GET /accounts/$USERNAME/cashouts/$CID */
+ GNUNET_break (0); /* not implemented */
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+
+
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ acc_name);
+ }
+
+ if ( (NULL != end_acc) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST)) )
+ {
+ /* POST /accounts/$ACCOUNT/+ */
+ char *acc;
+
+ acc = GNUNET_strndup (acc_name,
+ end_acc - acc_name);
+ if (0 == strcmp (end_acc,
+ "/cashouts"))
+ {
+ /* POST /accounts/$USERNAME/cashouts */
+ GNUNET_break (0); /* not implemented */
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strncmp (end_acc,
+ "/cashouts/",
+ strlen ("/cashouts/")))
+ {
+ /* POST /accounts/$USERNAME/cashouts/+ */
+ const char *cid = end_acc + strlen ("/cashouts/");
+ const char *opid = strchr (cid,
+ '/');
+ char *ci;
+
+ if (NULL == opid)
+ {
+ /* POST /accounts/$ACCOUNT/cashouts/$CID (not defined) */
+ GNUNET_break_op (0);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ acc_name);
+ }
+ ci = GNUNET_strndup (cid,
+ opid - cid);
+ if (0 == strcmp (opid,
+ "/abort"))
+ {
+ GNUNET_break (0); /* not implemented */
+ GNUNET_free (ci);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ if (0 == strcmp (opid,
+ "/confirm"))
+ {
+ GNUNET_break (0); /* not implemented */
+ GNUNET_free (ci);
+ GNUNET_free (acc);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR,
+ url);
+ }
+ }
+
+ if (0 == strcmp (end_acc,
+ "/withdrawals"))
+ {
+ /* POST /accounts/$ACCOUNT/withdrawals */
+ MHD_RESULT ret;
+
+ ret = TALER_FAKEBANK_bank_post_account_withdrawals_ (
+ h,
+ connection,
+ acc,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (acc);
+ return ret;
+ }
+
+ if (0 == strncmp (end_acc,
+ "/withdrawals/",
+ strlen ("/withdrawals/")))
+ {
+ /* POST /accounts/$ACCOUNT/withdrawals/$WID/$OP */
+ MHD_RESULT ret;
+ const char *pos = &end_acc[strlen ("/withdrawals/")];
+ const char *op = strchr (pos, '/');
+
+ if (NULL != op)
+ {
+ char *wid = GNUNET_strndup (pos,
+ op - pos);
+
+ ret = TALER_FAKEBANK_bank_withdrawals_id_op_ (
+ h,
+ connection,
+ acc,
+ wid,
+ op,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ GNUNET_free (wid);
+ GNUNET_free (acc);
+ return ret;
+ }
+ GNUNET_free (acc);
+ }
+ }
+ }
+
+ GNUNET_break_op (0);
+ TALER_LOG_ERROR ("Breaking URL: %s %s\n",
+ method,
+ url);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+}
diff --git a/src/bank-lib/fakebank_bank.h b/src/bank-lib/fakebank_bank.h
new file mode 100644
index 000000000..1c51f88f8
--- /dev/null
+++ b/src/bank-lib/fakebank_bank.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank.h
+ * @brief Main dispatcher for the Taler Bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_H
+#define FAKEBANK_BANK_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle incoming HTTP request to the Taler bank API.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param url the requested url
+ * @param method the method (POST, GET, ...)
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_main_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_accounts_withdrawals.c b/src/bank-lib/fakebank_bank_accounts_withdrawals.c
new file mode 100644
index 000000000..bb435d975
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_accounts_withdrawals.c
@@ -0,0 +1,101 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_accounts_withdrawals.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_accounts_withdrawals.h"
+#include "fakebank_common_lookup.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_account_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name,
+ const char *withdrawal_id)
+{
+ struct WithdrawalOperation *wo;
+ struct Account *acc;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if (NULL == wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ account_name,
+ NULL);
+ if (NULL == acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account_name);
+ }
+ if (wo->debit_account != acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ account_name);
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_bool ("aborted",
+ wo->aborted),
+ GNUNET_JSON_pack_bool ("selection_done",
+ wo->selection_done),
+ GNUNET_JSON_pack_bool ("transfer_done",
+ wo->confirmation_done),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("selected_exchange_account",
+ wo->exchange_account->payto_uri)),
+ GNUNET_JSON_pack_allow_null (
+ wo->selection_done
+ ? GNUNET_JSON_pack_data_auto ("selected_reserve_pub",
+ &wo->reserve_pub)
+ : GNUNET_JSON_pack_string ("selected_reserve_pub",
+ NULL)),
+ TALER_JSON_pack_amount ("amount",
+ &wo->amount));
+}
diff --git a/src/bank-lib/fakebank_bank_accounts_withdrawals.h b/src/bank-lib/fakebank_bank_accounts_withdrawals.h
new file mode 100644
index 000000000..2a598dee9
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_accounts_withdrawals.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_accounts_withdrawals.h
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_ACCOUNTS_WITHDRAWALS_H
+#define FAKEBANK_BANK_ACCOUNTS_WITHDRAWALS_H
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle GET /accounts/${account_name}/withdrawals/{withdrawal_id} request
+ * to the Taler bank access API.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @param withdrawal_id withdrawal ID to return status of
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_account_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name,
+ const char *withdrawal_id);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_get_accounts.c b/src/bank-lib/fakebank_bank_get_accounts.c
new file mode 100644
index 000000000..e85387d2a
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_accounts.c
@@ -0,0 +1,80 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_accounts.c
+ * @brief implements the Taler Bank API "GET /accounts/" handler
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_get_accounts.h"
+#include "fakebank_common_lookup.h"
+
+/**
+ * Handle GET /accounts/${account_name} request of the Taler bank API.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_accounts_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name)
+{
+ struct Account *acc;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ account_name,
+ NULL);
+ if (NULL == acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account_name);
+ }
+
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("payto_uri",
+ acc->payto_uri),
+ GNUNET_JSON_pack_object_steal (
+ "balance",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("credit_debit_indicator",
+ acc->is_negative
+ ? "debit"
+ : "credit"),
+ TALER_JSON_pack_amount ("amount",
+ &acc->balance))));
+}
diff --git a/src/bank-lib/fakebank_bank_get_accounts.h b/src/bank-lib/fakebank_bank_get_accounts.h
new file mode 100644
index 000000000..7d3872133
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_accounts.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_accounts.h
+ * @brief implements the Taler Bank API "GET /accounts/" handler
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_GET_ACCOUNTS_H
+#define FAKEBANK_BANK_GET_ACCOUNTS_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle GET /accounts/${account_name} request of the Taler bank API.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_accounts_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name);
+
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_get_root.c b/src/bank-lib/fakebank_bank_get_root.c
new file mode 100644
index 000000000..8c34697b4
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_root.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_root.c
+ * @brief handle a GET "/" request for the bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_get_root.h"
+
+
+/**
+ * Handle incoming HTTP request for "/" (home page).
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_root_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection)
+{
+ MHD_RESULT ret;
+ struct MHD_Response *resp;
+#define HELLOMSG "Hello, Fakebank!"
+
+ (void) h;
+ resp = MHD_create_response_from_buffer (
+ strlen (HELLOMSG),
+ HELLOMSG,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_OK,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
+}
diff --git a/src/bank-lib/fakebank_bank_get_root.h b/src/bank-lib/fakebank_bank_get_root.h
new file mode 100644
index 000000000..2eedb94a1
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_root.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_root.c
+ * @brief handle a GET "/" request for the bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_GET_ROOT_H
+#define FAKEBANK_BANK_GET_ROOT_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle incoming HTTP request for "/" (home page).
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_root_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_get_withdrawals.c b/src/bank-lib/fakebank_bank_get_withdrawals.c
new file mode 100644
index 000000000..7f65e8660
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_withdrawals.c
@@ -0,0 +1,87 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_withdrawals.c
+ * @brief implements the Taler Bank API "GET /withdrawals/$WID" handler
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_get_withdrawals.h"
+#include "fakebank_common_lookup.h"
+
+
+/**
+ * Handle GET /withdrawals/{withdrawal_id} request
+ * to the Taler bank access API.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param withdrawal_id withdrawal ID to return status of
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id)
+{
+ struct WithdrawalOperation *wo;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if (NULL == wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_bool ("aborted",
+ wo->aborted),
+ GNUNET_JSON_pack_bool ("selection_done",
+ wo->selection_done),
+ GNUNET_JSON_pack_bool ("transfer_done",
+ wo->confirmation_done),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("selected_exchange_account",
+ wo->exchange_account->payto_uri)),
+ GNUNET_JSON_pack_allow_null (
+ wo->selection_done
+ ? GNUNET_JSON_pack_data_auto ("selected_reserve_pub",
+ &wo->reserve_pub)
+ : GNUNET_JSON_pack_string ("selected_reserve_pub",
+ NULL)),
+ TALER_JSON_pack_amount ("amount",
+ &wo->amount));
+}
diff --git a/src/bank-lib/fakebank_bank_get_withdrawals.h b/src/bank-lib/fakebank_bank_get_withdrawals.h
new file mode 100644
index 000000000..62a96866c
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_get_withdrawals.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_get_withdrawals.h
+ * @brief implements the Taler Bank API "GET /accounts/ACC/withdrawals/WID" handler
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_GET_WITHDRAWALS_H
+#define FAKEBANK_BANK_GET_WITHDRAWALS_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_get_withdrawals.h"
+
+
+/**
+ * Handle GET /withdrawals/{withdrawal_id} request
+ * to the Taler bank access API.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param withdrawal_id withdrawal ID to return status of
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_get_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id);
+
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_post_accounts_withdrawals.c b/src/bank-lib/fakebank_bank_post_accounts_withdrawals.c
new file mode 100644
index 000000000..7fbb93352
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_accounts_withdrawals.c
@@ -0,0 +1,196 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_accounts_withdrawals.c
+ * @brief implementation of the bank API's POST /accounts/AID/withdrawals endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_post_accounts_withdrawals.h"
+#include "fakebank_common_lookup.h"
+
+
+/**
+ * Execute POST /accounts/$account_name/withdrawals request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @param amount amount to withdraw
+ * @return MHD result code
+ */
+static MHD_RESULT
+do_post_account_withdrawals (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name,
+ const struct TALER_Amount *amount)
+{
+ struct Account *acc;
+ struct WithdrawalOperation *wo;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ account_name,
+ NULL);
+ if (NULL == acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account_name);
+ }
+ wo = GNUNET_new (struct WithdrawalOperation);
+ wo->debit_account = acc;
+ wo->amount = *amount;
+ if (NULL == h->wops)
+ {
+ h->wops = GNUNET_CONTAINER_multishortmap_create (32,
+ GNUNET_YES);
+ }
+ while (1)
+ {
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &wo->wopid,
+ sizeof (wo->wopid));
+ if (GNUNET_OK ==
+ GNUNET_CONTAINER_multishortmap_put (h->wops,
+ &wo->wopid,
+ wo,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ break;
+ }
+ {
+ char *wopids;
+ char *uri;
+ MHD_RESULT res;
+
+ wopids = GNUNET_STRINGS_data_to_string_alloc (&wo->wopid,
+ sizeof (wo->wopid));
+ GNUNET_asprintf (&uri,
+ "taler+http://withdraw/%s:%u/taler-integration/%s",
+ h->hostname,
+ (unsigned int) h->port,
+ wopids);
+ GNUNET_free (wopids);
+ res = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("taler_withdraw_uri",
+ uri),
+ GNUNET_JSON_pack_data_auto ("withdrawal_id",
+ &wo->wopid));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ GNUNET_free (uri);
+ return res;
+ }
+}
+
+
+/**
+ * Handle POST /accounts/$account_name/withdrawals request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_post_account_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ enum GNUNET_JSON_PostResult pr;
+ json_t *json;
+ MHD_RESULT res;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &GNUNET_JSON_post_parser_cleanup;
+ *con_cls = cc;
+ }
+ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
+ connection,
+ &cc->ctx,
+ upload_data,
+ upload_data_size,
+ &json);
+ switch (pr)
+ {
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
+ }
+
+ {
+ struct TALER_Amount amount;
+ enum GNUNET_GenericReturnValue ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount ("amount",
+ h->currency,
+ &amount),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ (ret = TALER_MHD_parse_json_data (connection,
+ json,
+ spec)))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+ }
+ res = do_post_account_withdrawals (h,
+ connection,
+ account_name,
+ &amount);
+ }
+ json_decref (json);
+ return res;
+}
diff --git a/src/bank-lib/fakebank_bank_post_accounts_withdrawals.h b/src/bank-lib/fakebank_bank_post_accounts_withdrawals.h
new file mode 100644
index 000000000..1becf1efc
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_accounts_withdrawals.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_accounts_withdrawals.c
+ * @brief implementation of the bank API's POST /accounts/AID/withdrawals endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_POST_ACCOUNTS_WITHDRAWALS_H
+#define FAKEBANK_BANK_POST_ACCOUNTS_WITHDRAWALS_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle POST /accounts/$account_name/withdrawals request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account_name name of the account
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_post_account_withdrawals_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account_name,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_abort.c b/src/bank-lib/fakebank_bank_post_withdrawals_abort.c
new file mode 100644
index 000000000..f8ebf1b93
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_abort.c
@@ -0,0 +1,74 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_abort.c
+ * @brief implement bank API withdrawals /abort endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_post_withdrawals_abort.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_abort_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id)
+{
+ struct WithdrawalOperation *wo;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if (NULL == wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ if (wo->confirmation_done)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_ABORT_CONFIRM_CONFLICT,
+ withdrawal_id);
+ }
+ wo->aborted = true;
+ TALER_FAKEBANK_notify_withdrawal_ (h,
+ wo);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_json (connection,
+ json_object (), /* FIXME: #7301 */
+ MHD_HTTP_OK);
+}
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_abort.h b/src/bank-lib/fakebank_bank_post_withdrawals_abort.h
new file mode 100644
index 000000000..920b0b802
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_abort.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_abort.h
+ * @brief implement bank API withdrawals /abort endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_POST_WITHDRAWALS_ABORT_H
+#define FAKEBANK_BANK_POST_WITHDRAWALS_ABORT_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle POST /withdrawals/{withdrawal_id}/abort request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param withdrawal_id the withdrawal operation identifier
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_abort_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_confirm.c b/src/bank-lib/fakebank_bank_post_withdrawals_confirm.c
new file mode 100644
index 000000000..2fa67c970
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_confirm.c
@@ -0,0 +1,107 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_confirm.c
+ * @brief implement bank API withdrawals /confirm endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_post_withdrawals_confirm.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_make_admin_transfer.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_confirm_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id)
+{
+ struct WithdrawalOperation *wo;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if (NULL == wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ if (NULL == wo->exchange_account)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_BANK_POST_WITHDRAWAL_OPERATION_REQUIRED,
+ NULL);
+ }
+ if (wo->aborted)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_CONFIRM_ABORT_CONFLICT,
+ withdrawal_id);
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (GNUNET_OK !=
+ TALER_FAKEBANK_make_admin_transfer_ (
+ h,
+ wo->debit_account->account_name,
+ wo->exchange_account->account_name,
+ &wo->amount,
+ &wo->reserve_pub,
+ &wo->row_id,
+ &wo->timestamp))
+ {
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
+ NULL);
+ }
+ /* Re-acquiring the lock and continuing to operate on 'wo'
+ is currently (!) acceptable because we NEVER free 'wo'
+ until shutdown. We may want to revise this if keeping
+ all withdraw operations in RAM becomes an issue... */
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo->confirmation_done = true;
+ TALER_FAKEBANK_notify_withdrawal_ (h,
+ wo);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_json (connection,
+ json_object (),
+ MHD_HTTP_OK);
+}
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_confirm.h b/src/bank-lib/fakebank_bank_post_withdrawals_confirm.h
new file mode 100644
index 000000000..56cd2deda
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_confirm.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_confirm.h
+ * @brief implement bank API withdrawals /confirm endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_POST_WITHDRAWALS_CONFIRM_H
+#define FAKEBANK_BANK_POST_WITHDRAWALS_CONFIRM_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle POST /accounts/{account_name}/withdrawals/{withdrawal_id}/confirm request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param withdrawal_id the withdrawal operation identifier
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_confirm_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *withdrawal_id);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_id_op.c b/src/bank-lib/fakebank_bank_post_withdrawals_id_op.c
new file mode 100644
index 000000000..fe5cc982d
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_id_op.c
@@ -0,0 +1,241 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_id_op.c
+ * @brief implement bank API POST /accounts/$ACCOUNT/withdrawals/$WID/$OP endpoint(s)
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_post_withdrawals_id_op.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_make_admin_transfer.h"
+
+
+/**
+ * Handle POST /accounts/$ACC/withdrawals/{withdrawal_id}/confirm request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account name of the account
+ * @param withdrawal_id the withdrawal operation identifier
+ * @return MHD result code
+ */
+static MHD_RESULT
+bank_withdrawals_confirm (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *withdrawal_id)
+{
+ const struct Account *acc;
+ struct WithdrawalOperation *wo;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ account,
+ NULL);
+ if (NULL == acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account %s is unknown\n",
+ account);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account);
+ }
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if ( (NULL == wo) ||
+ (acc != wo->debit_account) )
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ if (NULL == wo->exchange_account)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_BANK_POST_WITHDRAWAL_OPERATION_REQUIRED,
+ NULL);
+ }
+ if (wo->aborted)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_CONFIRM_ABORT_CONFLICT,
+ withdrawal_id);
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (GNUNET_OK !=
+ TALER_FAKEBANK_make_admin_transfer_ (
+ h,
+ wo->debit_account->account_name,
+ wo->exchange_account->account_name,
+ &wo->amount,
+ &wo->reserve_pub,
+ &wo->row_id,
+ &wo->timestamp))
+ {
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
+ NULL);
+ }
+ /* Re-acquiring the lock and continuing to operate on 'wo'
+ is currently (!) acceptable because we NEVER free 'wo'
+ until shutdown. We may want to revise this if keeping
+ all withdraw operations in RAM becomes an issue... */
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo->confirmation_done = true;
+ TALER_FAKEBANK_notify_withdrawal_ (h,
+ wo);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/**
+ * Handle POST /accounts/$ACC/withdrawals/{withdrawal_id}/abort request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account name of the account
+ * @param withdrawal_id the withdrawal operation identifier
+ * @return MHD result code
+ */
+static MHD_RESULT
+bank_withdrawals_abort (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *withdrawal_id)
+{
+ struct WithdrawalOperation *wo;
+ const struct Account *acc;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ account,
+ NULL);
+ if (NULL == acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account %s is unknown\n",
+ account);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account);
+ }
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ withdrawal_id);
+ if ( (NULL == wo) ||
+ (acc != wo->debit_account) )
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ withdrawal_id);
+ }
+ if (wo->confirmation_done)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_ABORT_CONFIRM_CONFLICT,
+ withdrawal_id);
+ }
+ wo->aborted = true;
+ TALER_FAKEBANK_notify_withdrawal_ (h,
+ wo);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_id_op_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *withdrawal_id,
+ const char *op,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ if (0 == strcmp (op,
+ "/confirm"))
+ {
+ return bank_withdrawals_confirm (h,
+ connection,
+ account,
+ withdrawal_id);
+ }
+ if (0 == strcmp (op,
+ "/abort"))
+ {
+ return bank_withdrawals_abort (h,
+ connection,
+ account,
+ withdrawal_id);
+ }
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ op);
+}
diff --git a/src/bank-lib/fakebank_bank_post_withdrawals_id_op.h b/src/bank-lib/fakebank_bank_post_withdrawals_id_op.h
new file mode 100644
index 000000000..a2d40e66f
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_post_withdrawals_id_op.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_post_withdrawals_id_op.h
+ * @brief implement bank API POST /accounts/$ACCOUNT/withdrawals/$WID/$OP endpoint(s)
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_POST_WITHDRAWALS_ID_OP_H
+#define FAKEBANK_BANK_POST_WITHDRAWALS_ID_OP_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle POST /accounts/{account_name}/withdrawals/{withdrawal_id}/${OP} request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param account name of the account
+ * @param withdrawal_id the withdrawal operation identifier
+ * @param op operation to be performed, includes leading "/"
+ * @param upload_data data uploaded
+ * @param[in,out] upload_data_size number of bytes in @a upload_data
+ * @param[in,out] con_cls application context that can be used
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_withdrawals_id_op_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *withdrawal_id,
+ const char *op,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_bank_testing_register.c b/src/bank-lib/fakebank_bank_testing_register.c
new file mode 100644
index 000000000..e5720f1a6
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_testing_register.c
@@ -0,0 +1,128 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_testing_register.c
+ * @brief implementation of /testing/register endpoint for the bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_bank_testing_register.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_bank_testing_register_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ enum GNUNET_JSON_PostResult pr;
+ json_t *json;
+ MHD_RESULT res;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &GNUNET_JSON_post_parser_cleanup;
+ *con_cls = cc;
+ }
+ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
+ connection,
+ &cc->ctx,
+ upload_data,
+ upload_data_size,
+ &json);
+ switch (pr)
+ {
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
+ }
+
+ {
+ const char *username;
+ const char *password;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("username",
+ &username),
+ GNUNET_JSON_spec_string ("password",
+ &password),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue ret;
+ struct Account *acc;
+
+ if (GNUNET_OK !=
+ (ret = TALER_MHD_parse_json_data (connection,
+ json,
+ spec)))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+ }
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ username,
+ NULL);
+ if (NULL != acc)
+ {
+ if (0 != strcmp (password,
+ acc->password))
+ {
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_REGISTER_CONFLICT,
+ "password");
+ }
+ }
+ else
+ {
+ acc = TALER_FAKEBANK_lookup_account_ (h,
+ username,
+ username);
+ GNUNET_assert (NULL != acc);
+ acc->password = GNUNET_strdup (password);
+ acc->balance = h->signup_bonus; /* magic money creation! */
+ }
+ res = TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ json_decref (json);
+ return res;
+}
diff --git a/src/bank-lib/fakebank_bank_testing_register.h b/src/bank-lib/fakebank_bank_testing_register.h
new file mode 100644
index 000000000..d8744ecc2
--- /dev/null
+++ b/src/bank-lib/fakebank_bank_testing_register.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_bank_testing_register.h
+ * @brief implementation of /testing/register endpoint for the bank API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_BANK_TESTING_REGISTER_H
+#define FAKEBANK_BANK_TESTING_REGISTER_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+
+
+/**
+ * Handle POST /testing/register request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_bank_testing_register_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_common_lookup.c b/src/bank-lib/fakebank_common_lookup.c
new file mode 100644
index 000000000..b4f853871
--- /dev/null
+++ b/src/bank-lib/fakebank_common_lookup.c
@@ -0,0 +1,103 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_lookup.c
+ * @brief common helper functions related to lookups
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+
+struct WithdrawalOperation *
+TALER_FAKEBANK_lookup_withdrawal_operation_ (struct TALER_FAKEBANK_Handle *h,
+ const char *wopid)
+{
+ struct GNUNET_ShortHashCode sh;
+
+ if (NULL == h->wops)
+ return NULL;
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (wopid,
+ strlen (wopid),
+ &sh,
+ sizeof (sh)))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ return GNUNET_CONTAINER_multishortmap_get (h->wops,
+ &sh);
+}
+
+
+struct Account *
+TALER_FAKEBANK_lookup_account_ (struct TALER_FAKEBANK_Handle *h,
+ const char *name,
+ const char *receiver_name)
+{
+ struct GNUNET_HashCode hc;
+ size_t slen;
+ struct Account *account;
+
+ memset (&hc,
+ 0,
+ sizeof (hc));
+ slen = strlen (name);
+ GNUNET_CRYPTO_hash (name,
+ slen,
+ &hc);
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->accounts_lock));
+ account = GNUNET_CONTAINER_multihashmap_get (h->accounts,
+ &hc);
+ if (NULL == account)
+ {
+ if (NULL == receiver_name)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->accounts_lock));
+ return NULL;
+ }
+ account = GNUNET_new (struct Account);
+ account->account_name = GNUNET_strdup (name);
+ account->receiver_name = GNUNET_strdup (receiver_name);
+ GNUNET_asprintf (&account->payto_uri,
+ "payto://x-taler-bank/%s/%s?receiver-name=%s",
+ h->hostname,
+ account->account_name,
+ account->receiver_name);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (h->currency,
+ &account->balance));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (h->accounts,
+ &hc,
+ account,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->accounts_lock));
+ return account;
+}
diff --git a/src/bank-lib/fakebank_common_lookup.h b/src/bank-lib/fakebank_common_lookup.h
new file mode 100644
index 000000000..b93447743
--- /dev/null
+++ b/src/bank-lib/fakebank_common_lookup.h
@@ -0,0 +1,62 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_lookup.h
+ * @brief common helper functions related to lookups
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+
+#ifndef FAKEBANK_COMMON_LOOKUP_H
+#define FAKEBANK_COMMON_LOOKUP_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Lookup account with @a name, and if it does not exist, create it.
+ *
+ * @param[in,out] h bank to lookup account at
+ * @param name account name to resolve
+ * @param receiver_name receiver name in payto:// URI,
+ * NULL if the account must already exist
+ * @return account handle, NULL if account does not yet exist
+ */
+struct Account *
+TALER_FAKEBANK_lookup_account_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const char *name,
+ const char *receiver_name);
+
+
+/**
+ * Find withdrawal operation @a wopid in @a h.
+ *
+ * @param h fakebank handle
+ * @param wopid withdrawal operation ID as a string
+ * @return NULL if operation was not found
+ */
+struct WithdrawalOperation *
+TALER_FAKEBANK_lookup_withdrawal_operation_ (struct TALER_FAKEBANK_Handle *h,
+ const char *wopid);
+
+#endif
diff --git a/src/bank-lib/fakebank_common_lp.c b/src/bank-lib/fakebank_common_lp.c
new file mode 100644
index 000000000..22a9e3ab4
--- /dev/null
+++ b/src/bank-lib/fakebank_common_lp.c
@@ -0,0 +1,344 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_lp.c
+ * @brief long-polling support for fakebank
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include <poll.h>
+#ifdef __linux__
+#include <sys/eventfd.h>
+#endif
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+void
+TALER_FAKEBANK_lp_trigger_ (struct LongPoller *lp)
+{
+ struct TALER_FAKEBANK_Handle *h = lp->h;
+ struct Account *acc = lp->account;
+
+ GNUNET_CONTAINER_DLL_remove (acc->lp_head,
+ acc->lp_tail,
+ lp);
+ MHD_resume_connection (lp->conn);
+ GNUNET_free (lp);
+ h->mhd_again = true;
+#ifdef __linux__
+ if (-1 == h->lp_event)
+#else
+ if ( (-1 == h->lp_event_in) &&
+ (-1 == h->lp_event_out) )
+#endif
+ {
+ if (NULL != h->mhd_task)
+ GNUNET_SCHEDULER_cancel (h->mhd_task);
+ h->mhd_task =
+ GNUNET_SCHEDULER_add_now (&TALER_FAKEBANK_run_mhd_,
+ h);
+ }
+}
+
+
+void *
+TALER_FAKEBANK_lp_expiration_thread_ (void *cls)
+{
+ struct TALER_FAKEBANK_Handle *h = cls;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ while (! h->in_shutdown)
+ {
+ struct LongPoller *lp;
+ int timeout_ms;
+
+ lp = GNUNET_CONTAINER_heap_peek (h->lp_heap);
+ while ( (NULL != lp) &&
+ GNUNET_TIME_absolute_is_past (lp->timeout))
+ {
+ GNUNET_assert (lp ==
+ GNUNET_CONTAINER_heap_remove_root (h->lp_heap));
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ lp = GNUNET_CONTAINER_heap_peek (h->lp_heap);
+ }
+ if (NULL != lp)
+ {
+ struct GNUNET_TIME_Relative rem;
+ unsigned long long left_ms;
+
+ rem = GNUNET_TIME_absolute_get_remaining (lp->timeout);
+ left_ms = rem.rel_value_us / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
+ if (left_ms > INT_MAX)
+ timeout_ms = INT_MAX;
+ else
+ timeout_ms = (int) left_ms;
+ }
+ else
+ {
+ timeout_ms = -1; /* infinity */
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ {
+ struct pollfd p = {
+#ifdef __linux__
+ .fd = h->lp_event,
+#else
+ .fd = h->lp_event_out,
+#endif
+ .events = POLLIN
+ };
+ int ret;
+
+ ret = poll (&p,
+ 1,
+ timeout_ms);
+ if (-1 == ret)
+ {
+ if (EINTR != errno)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "poll");
+ }
+ else if (1 == ret)
+ {
+ /* clear event */
+ uint64_t ev;
+ ssize_t iret;
+
+#ifdef __linux__
+ iret = read (h->lp_event,
+ &ev,
+ sizeof (ev));
+#else
+ iret = read (h->lp_event_out,
+ &ev,
+ sizeof (ev));
+#endif
+ if (-1 == iret)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "read");
+ }
+ else
+ {
+ GNUNET_break (sizeof (uint64_t) == iret);
+ }
+ }
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return NULL;
+}
+
+
+/**
+ * Trigger long pollers that might have been waiting
+ * for @a t.
+ *
+ * @param h fakebank handle
+ * @param t transaction to notify on
+ */
+void
+TALER_FAKEBANK_notify_transaction_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct Transaction *t)
+{
+ struct Account *debit_acc = t->debit_account;
+ struct Account *credit_acc = t->credit_account;
+ struct LongPoller *nxt;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ for (struct LongPoller *lp = debit_acc->lp_head;
+ NULL != lp;
+ lp = nxt)
+ {
+ nxt = lp->next;
+ if (LP_DEBIT == lp->type)
+ {
+ GNUNET_assert (lp ==
+ GNUNET_CONTAINER_heap_remove_node (lp->hn));
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ }
+ }
+ for (struct LongPoller *lp = credit_acc->lp_head;
+ NULL != lp;
+ lp = nxt)
+ {
+ nxt = lp->next;
+ if (LP_CREDIT == lp->type)
+ {
+ GNUNET_assert (lp ==
+ GNUNET_CONTAINER_heap_remove_node (lp->hn));
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ }
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+}
+
+
+/**
+ * Notify long pollers that a @a wo was updated.
+ * Must be called with the "big_lock" still held.
+ *
+ * @param h fakebank handle
+ * @param wo withdraw operation that finished
+ */
+void
+TALER_FAKEBANK_notify_withdrawal_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const struct WithdrawalOperation *wo)
+{
+ struct Account *debit_acc = wo->debit_account;
+ struct LongPoller *nxt;
+
+ for (struct LongPoller *lp = debit_acc->lp_head;
+ NULL != lp;
+ lp = nxt)
+ {
+ nxt = lp->next;
+ if ( (LP_WITHDRAW == lp->type) &&
+ (wo == lp->wo) )
+ {
+ GNUNET_assert (lp ==
+ GNUNET_CONTAINER_heap_remove_node (lp->hn));
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ }
+ }
+}
+
+
+/**
+ * Task run when a long poller is about to time out.
+ * Only used in single-threaded mode.
+ *
+ * @param cls a `struct TALER_FAKEBANK_Handle *`
+ */
+static void
+lp_timeout (void *cls)
+{
+ struct TALER_FAKEBANK_Handle *h = cls;
+ struct LongPoller *lp;
+
+ h->lp_task = NULL;
+ while (NULL != (lp = GNUNET_CONTAINER_heap_peek (h->lp_heap)))
+ {
+ if (GNUNET_TIME_absolute_is_future (lp->timeout))
+ break;
+ GNUNET_assert (lp ==
+ GNUNET_CONTAINER_heap_remove_root (h->lp_heap));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Timeout reached for long poller %p\n",
+ lp->conn);
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ }
+ if (NULL == lp)
+ return;
+ h->lp_task = GNUNET_SCHEDULER_add_at (lp->timeout,
+ &lp_timeout,
+ h);
+}
+
+
+/**
+ * Reschedule the timeout task of @a h for time @a t.
+ *
+ * @param h fakebank handle
+ * @param t when will the next connection timeout expire
+ */
+static void
+reschedule_lp_timeout (struct TALER_FAKEBANK_Handle *h,
+ struct GNUNET_TIME_Absolute t)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Scheduling timeout task for %s\n",
+ GNUNET_STRINGS_absolute_time_to_string (t));
+#ifdef __linux__
+ if (-1 != h->lp_event)
+#else
+ if (-1 != h->lp_event_in && -1 != h->lp_event_out)
+#endif
+ {
+ uint64_t num = 1;
+
+ GNUNET_break (sizeof (num) ==
+#ifdef __linux__
+ write (h->lp_event,
+ &num,
+ sizeof (num)));
+#else
+ write (h->lp_event_in,
+ &num,
+ sizeof (num)));
+#endif
+ }
+ else
+ {
+ if (NULL != h->lp_task)
+ GNUNET_SCHEDULER_cancel (h->lp_task);
+ h->lp_task = GNUNET_SCHEDULER_add_at (t,
+ &lp_timeout,
+ h);
+ }
+}
+
+
+void
+TALER_FAKEBANK_start_lp_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ struct Account *acc,
+ struct GNUNET_TIME_Relative lp_timeout,
+ enum LongPollType dir,
+ const struct WithdrawalOperation *wo)
+{
+ struct LongPoller *lp;
+ bool toc;
+
+ lp = GNUNET_new (struct LongPoller);
+ lp->account = acc;
+ lp->h = h;
+ lp->wo = wo;
+ lp->conn = connection;
+ lp->timeout = GNUNET_TIME_relative_to_absolute (lp_timeout);
+ lp->type = dir;
+ lp->hn = GNUNET_CONTAINER_heap_insert (h->lp_heap,
+ lp,
+ lp->timeout.abs_value_us);
+ toc = (lp ==
+ GNUNET_CONTAINER_heap_peek (h->lp_heap));
+ GNUNET_CONTAINER_DLL_insert (acc->lp_head,
+ acc->lp_tail,
+ lp);
+ MHD_suspend_connection (connection);
+ if (toc)
+ reschedule_lp_timeout (h,
+ lp->timeout);
+
+}
diff --git a/src/bank-lib/fakebank_common_lp.h b/src/bank-lib/fakebank_common_lp.h
new file mode 100644
index 000000000..37094e12b
--- /dev/null
+++ b/src/bank-lib/fakebank_common_lp.h
@@ -0,0 +1,100 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_lp.h
+ * @brief long-polling support for fakebank
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_COMMON_LP_H
+#define FAKEBANK_COMMON_LP_H
+#include "taler_fakebank_lib.h"
+
+
+/**
+ * Trigger the @a lp. Frees associated resources, except the entry of @a lp in
+ * the timeout heap. Must be called while the ``big lock`` is held.
+ *
+ * @param[in] lp long poller to trigger
+ */
+void
+TALER_FAKEBANK_lp_trigger_ (struct LongPoller *lp);
+
+
+/**
+ * Trigger long pollers that might have been waiting
+ * for @a t.
+ *
+ * @param h fakebank handle
+ * @param t transaction to notify on
+ */
+void
+TALER_FAKEBANK_notify_transaction_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct Transaction *t);
+
+
+/**
+ * Notify long pollers that a @a wo was updated.
+ * Must be called with the "big_lock" still held.
+ *
+ * @param h fakebank handle
+ * @param wo withdraw operation that finished
+ */
+void
+TALER_FAKEBANK_notify_withdrawal_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const struct WithdrawalOperation *wo);
+
+
+/**
+ * Start long-polling for @a connection and @a acc
+ * for transfers in @a dir. Must be called with the
+ * "big lock" held.
+ *
+ * @param[in,out] h fakebank handle
+ * @param[in,out] connection to suspend
+ * @param[in,out] acc account affected
+ * @param lp_timeout how long to suspend
+ * @param dir direction of transfers to watch for
+ * @param wo withdraw operation to watch, only
+ * if @a dir is #LP_WITHDRAW
+ */
+void
+TALER_FAKEBANK_start_lp_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ struct Account *acc,
+ struct GNUNET_TIME_Relative lp_timeout,
+ enum LongPollType dir,
+ const struct WithdrawalOperation *wo);
+
+
+/**
+ * Main routine of a thread that is run to wake up connections that have hit
+ * their timeout. Runs until in_shutdown is set to true. Must be send signals
+ * via lp_event on shutdown and/or whenever the heap changes to an earlier
+ * timeout.
+ *
+ * @param cls a `struct TALER_FAKEBANK_Handle *`
+ * @return NULL
+ */
+void *
+TALER_FAKEBANK_lp_expiration_thread_ (void *cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_common_make_admin_transfer.c b/src/bank-lib/fakebank_common_make_admin_transfer.c
new file mode 100644
index 000000000..4a11d412c
--- /dev/null
+++ b/src/bank-lib/fakebank_common_make_admin_transfer.c
@@ -0,0 +1,117 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_make_admin_transfer.c
+ * @brief routine to create transfers to the exchange
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_transact.h"
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_make_admin_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const char *debit_account,
+ const char *credit_account,
+ const struct TALER_Amount *amount,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *row_id,
+ struct GNUNET_TIME_Timestamp *timestamp)
+{
+ struct Transaction *t;
+ const struct GNUNET_PeerIdentity *pid;
+ struct Account *debit_acc;
+ struct Account *credit_acc;
+
+ GNUNET_static_assert (sizeof (*pid) ==
+ sizeof (*reserve_pub));
+ pid = (const struct GNUNET_PeerIdentity *) reserve_pub;
+ GNUNET_assert (NULL != debit_account);
+ GNUNET_assert (NULL != credit_account);
+ GNUNET_assert (0 == strcasecmp (amount->currency,
+ h->currency));
+ GNUNET_break (0 != strncasecmp ("payto://",
+ debit_account,
+ strlen ("payto://")));
+ GNUNET_break (0 != strncasecmp ("payto://",
+ credit_account,
+ strlen ("payto://")));
+ debit_acc = TALER_FAKEBANK_lookup_account_ (h,
+ debit_account,
+ debit_account);
+ credit_acc = TALER_FAKEBANK_lookup_account_ (h,
+ credit_account,
+ credit_account);
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->rpubs_lock));
+ t = GNUNET_CONTAINER_multipeermap_get (h->rpubs,
+ pid);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->rpubs_lock));
+ if (NULL != t)
+ {
+ /* duplicate reserve public key not allowed */
+ GNUNET_break_op (0);
+ return GNUNET_NO;
+ }
+
+ t = GNUNET_new (struct Transaction);
+ t->unchecked = true;
+ t->debit_account = debit_acc;
+ t->credit_account = credit_acc;
+ t->amount = *amount;
+ t->date = GNUNET_TIME_timestamp_get ();
+ if (NULL != timestamp)
+ *timestamp = t->date;
+ t->type = T_CREDIT;
+ t->subject.credit.reserve_pub = *reserve_pub;
+ TALER_FAKEBANK_transact_ (h,
+ t);
+ if (NULL != row_id)
+ *row_id = t->row_id;
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->rpubs_lock));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multipeermap_put (
+ h->rpubs,
+ pid,
+ t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->rpubs_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Making transfer from %s to %s over %s and subject %s at row %llu\n",
+ debit_account,
+ credit_account,
+ TALER_amount2s (amount),
+ TALER_B2S (reserve_pub),
+ (unsigned long long) t->row_id);
+ TALER_FAKEBANK_notify_transaction_ (h,
+ t);
+ return GNUNET_OK;
+}
diff --git a/src/bank-lib/fakebank_common_make_admin_transfer.h b/src/bank-lib/fakebank_common_make_admin_transfer.h
new file mode 100644
index 000000000..841cfb481
--- /dev/null
+++ b/src/bank-lib/fakebank_common_make_admin_transfer.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_make_admin_transfer.h
+ * @brief routine to create transfers to the exchange
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_COMMON_MAKE_ADMIN_TRANSFER_H
+#define FAKEBANK_COMMON_MAKE_ADMIN_TRANSFER_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Tell the fakebank to create another wire transfer *to* an exchange.
+ *
+ * @param h fake bank handle
+ * @param debit_account account to debit
+ * @param credit_account account to credit
+ * @param amount amount to transfer
+ * @param reserve_pub reserve public key to use in subject
+ * @param[out] row_id serial_id of the transfer
+ * @param[out] timestamp when was the transfer made
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_make_admin_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const char *debit_account,
+ const char *credit_account,
+ const struct TALER_Amount *amount,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *row_id,
+ struct GNUNET_TIME_Timestamp *timestamp);
+
+#endif
diff --git a/src/bank-lib/fakebank_common_parser.c b/src/bank-lib/fakebank_common_parser.c
new file mode 100644
index 000000000..cf2dc5a74
--- /dev/null
+++ b/src/bank-lib/fakebank_common_parser.c
@@ -0,0 +1,138 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_parser.c
+ * @brief functions to help parse REST requests
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_common_parse_history_args (
+ const struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ struct HistoryArgs *ha)
+{
+ const char *start;
+ const char *delta;
+ const char *long_poll_ms;
+ unsigned long long lp_timeout;
+ unsigned long long sval;
+ long long d;
+ char dummy;
+
+ start = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "start");
+ ha->have_start = (NULL != start);
+ delta = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "delta");
+ long_poll_ms = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "long_poll_ms");
+ lp_timeout = 0;
+ if ( (NULL == delta) ||
+ (1 != sscanf (delta,
+ "%lld%c",
+ &d,
+ &dummy)) )
+ {
+ /* Fail if one of the above failed. */
+ /* Invalid request, given that this is fakebank we impolitely
+ * just kill the connection instead of returning a nice error.
+ */
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "delta"))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ if ( (NULL != long_poll_ms) &&
+ (1 != sscanf (long_poll_ms,
+ "%llu%c",
+ &lp_timeout,
+ &dummy)) )
+ {
+ /* Fail if one of the above failed. */
+ /* Invalid request, given that this is fakebank we impolitely
+ * just kill the connection instead of returning a nice error.
+ */
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "long_poll_ms"))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ if ( (NULL != start) &&
+ (1 != sscanf (start,
+ "%llu%c",
+ &sval,
+ &dummy)) )
+ {
+ /* Fail if one of the above failed. */
+ /* Invalid request, given that this is fakebank we impolitely
+ * just kill the connection instead of returning a nice error.
+ */
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "start"))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ if (NULL == start)
+ ha->start_idx = (d > 0) ? 0 : UINT64_MAX;
+ else
+ ha->start_idx = (uint64_t) sval;
+ ha->delta = (int64_t) d;
+ if (0 == ha->delta)
+ {
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "delta"))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ ha->lp_timeout
+ = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ lp_timeout);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Request for %lld records from %llu\n",
+ (long long) ha->delta,
+ (unsigned long long) ha->start_idx);
+ return GNUNET_OK;
+}
diff --git a/src/bank-lib/fakebank_common_parser.h b/src/bank-lib/fakebank_common_parser.h
new file mode 100644
index 000000000..8e0d14649
--- /dev/null
+++ b/src/bank-lib/fakebank_common_parser.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_parser.h
+ * @brief functions to help parse REST requests
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_COMMON_PARSER_H
+#define FAKEBANK_COMMON_PARSER_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Parse URL history arguments, of _both_ APIs:
+ * /history/incoming and /history/outgoing.
+ *
+ * @param h bank handle to work on
+ * @param connection MHD connection.
+ * @param[out] ha will contain the parsed values.
+ * @return #GNUNET_OK only if the parsing succeeds,
+ * #GNUNET_SYSERR if it failed,
+ * #GNUNET_NO if it failed and an error was returned
+ */
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_common_parse_history_args (
+ const struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ struct HistoryArgs *ha);
+
+#endif
diff --git a/src/bank-lib/fakebank_common_transact.c b/src/bank-lib/fakebank_common_transact.c
new file mode 100644
index 000000000..a099ef966
--- /dev/null
+++ b/src/bank-lib/fakebank_common_transact.c
@@ -0,0 +1,261 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_transact.c
+ * @brief actual transaction logic for FAKEBANK
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_transact.h"
+
+
+/**
+ * Update @a account balance by @a amount.
+ *
+ * The @a big_lock must already be locked when calling
+ * this function.
+ *
+ * @param[in,out] account account to update
+ * @param amount balance change
+ * @param debit true to subtract, false to add @a amount
+ */
+static void
+update_balance (struct Account *account,
+ const struct TALER_Amount *amount,
+ bool debit)
+{
+ if (debit == account->is_negative)
+ {
+ GNUNET_assert (0 <=
+ TALER_amount_add (&account->balance,
+ &account->balance,
+ amount));
+ return;
+ }
+ if (0 <= TALER_amount_cmp (&account->balance,
+ amount))
+ {
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (&account->balance,
+ &account->balance,
+ amount));
+ }
+ else
+ {
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (&account->balance,
+ amount,
+ &account->balance));
+ account->is_negative = ! account->is_negative;
+ }
+}
+
+
+/**
+ * Add transaction to the debit and credit accounts,
+ * updating the balances as needed.
+ *
+ * The transaction @a t must already be locked
+ * when calling this function!
+ *
+ * @param[in,out] h bank handle
+ * @param[in,out] t transaction to add to account lists
+ */
+void
+TALER_FAKEBANK_transact_ (struct TALER_FAKEBANK_Handle *h,
+ struct Transaction *t)
+{
+ struct Account *debit_acc = t->debit_account;
+ struct Account *credit_acc = t->credit_account;
+ uint64_t row_id;
+ struct Transaction *old;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ row_id = ++h->serial_counter;
+ old = h->transactions[row_id % h->ram_limit];
+ h->transactions[row_id % h->ram_limit] = t;
+ t->row_id = row_id;
+ GNUNET_CONTAINER_MDLL_insert_tail (out,
+ debit_acc->out_head,
+ debit_acc->out_tail,
+ t);
+ update_balance (debit_acc,
+ &t->amount,
+ true);
+ GNUNET_CONTAINER_MDLL_insert_tail (in,
+ credit_acc->in_head,
+ credit_acc->in_tail,
+ t);
+ update_balance (credit_acc,
+ &t->amount,
+ false);
+ if (NULL != old)
+ {
+ struct Account *da;
+ struct Account *ca;
+
+ da = old->debit_account;
+ ca = old->credit_account;
+ /* slot was already in use, must clean out old
+ entry first! */
+ GNUNET_CONTAINER_MDLL_remove (out,
+ da->out_head,
+ da->out_tail,
+ old);
+ GNUNET_CONTAINER_MDLL_remove (in,
+ ca->in_head,
+ ca->in_tail,
+ old);
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if ( (NULL != old) &&
+ (T_DEBIT == old->type) )
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->uuid_map_lock));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_remove (h->uuid_map,
+ &old->request_uid,
+ old));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ }
+ GNUNET_free (old);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_make_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const char *debit_account,
+ const char *credit_account,
+ const struct TALER_Amount *amount,
+ const struct TALER_WireTransferIdentifierRawP *subject,
+ const char *exchange_base_url,
+ const struct GNUNET_HashCode *request_uid,
+ uint64_t *ret_row_id,
+ struct GNUNET_TIME_Timestamp *timestamp)
+{
+ struct Transaction *t;
+ struct Account *debit_acc;
+ struct Account *credit_acc;
+ size_t url_len;
+
+ GNUNET_assert (0 == strcasecmp (amount->currency,
+ h->currency));
+ GNUNET_assert (NULL != debit_account);
+ GNUNET_assert (NULL != credit_account);
+ GNUNET_break (0 != strncasecmp ("payto://",
+ debit_account,
+ strlen ("payto://")));
+ GNUNET_break (0 != strncasecmp ("payto://",
+ credit_account,
+ strlen ("payto://")));
+ url_len = strlen (exchange_base_url);
+ GNUNET_assert (url_len < MAX_URL_LEN);
+ debit_acc = TALER_FAKEBANK_lookup_account_ (h,
+ debit_account,
+ debit_account);
+ credit_acc = TALER_FAKEBANK_lookup_account_ (h,
+ credit_account,
+ credit_account);
+ if (NULL != request_uid)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->uuid_map_lock));
+ t = GNUNET_CONTAINER_multihashmap_get (h->uuid_map,
+ request_uid);
+ if (NULL != t)
+ {
+ if ( (debit_acc != t->debit_account) ||
+ (credit_acc != t->credit_account) ||
+ (0 != TALER_amount_cmp (amount,
+ &t->amount)) ||
+ (T_DEBIT != t->type) ||
+ (0 != GNUNET_memcmp (subject,
+ &t->subject.debit.wtid)) )
+ {
+ /* Transaction exists, but with different details. */
+ GNUNET_break (0);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ return GNUNET_SYSERR;
+ }
+ *ret_row_id = t->row_id;
+ *timestamp = t->date;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ return GNUNET_OK;
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ }
+ t = GNUNET_new (struct Transaction);
+ t->unchecked = true;
+ t->debit_account = debit_acc;
+ t->credit_account = credit_acc;
+ t->amount = *amount;
+ t->date = GNUNET_TIME_timestamp_get ();
+ if (NULL != timestamp)
+ *timestamp = t->date;
+ t->type = T_DEBIT;
+ GNUNET_memcpy (t->subject.debit.exchange_base_url,
+ exchange_base_url,
+ url_len);
+ t->subject.debit.wtid = *subject;
+ if (NULL == request_uid)
+ GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_NONCE,
+ &t->request_uid);
+ else
+ t->request_uid = *request_uid;
+ TALER_FAKEBANK_transact_ (h,
+ t);
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->uuid_map_lock));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (
+ h->uuid_map,
+ &t->request_uid,
+ t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->uuid_map_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Making transfer %llu from %s to %s over %s and subject %s; for exchange: %s\n",
+ (unsigned long long) t->row_id,
+ debit_account,
+ credit_account,
+ TALER_amount2s (amount),
+ TALER_B2S (subject),
+ exchange_base_url);
+ *ret_row_id = t->row_id;
+ TALER_FAKEBANK_notify_transaction_ (h,
+ t);
+ return GNUNET_OK;
+}
diff --git a/src/bank-lib/fakebank_common_transact.h b/src/bank-lib/fakebank_common_transact.h
new file mode 100644
index 000000000..0914785e9
--- /dev/null
+++ b/src/bank-lib/fakebank_common_transact.h
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_common_transact.h
+ * @brief actual transaction logic for FAKEBANK
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_COMMON_TRANSACT_H
+#define FAKEBANK_COMMON_TRANSACT_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Add transaction to the debit and credit accounts,
+ * updating the balances as needed.
+ *
+ * The transaction @a t must already be locked
+ * when calling this function!
+ *
+ * @param[in,out] h bank handle
+ * @param[in,out] t transaction to add to account lists
+ */
+void
+TALER_FAKEBANK_transact_ (struct TALER_FAKEBANK_Handle *h,
+ struct Transaction *t);
+
+
+/**
+ * Tell the fakebank to create another wire transfer *from* an exchange.
+ *
+ * @param h fake bank handle
+ * @param debit_account account to debit
+ * @param credit_account account to credit
+ * @param amount amount to transfer
+ * @param subject wire transfer subject to use
+ * @param exchange_base_url exchange URL
+ * @param request_uid unique number to make the request unique, or NULL to create one
+ * @param[out] ret_row_id pointer to store the row ID of this transaction
+ * @param[out] timestamp set to the time of the transfer
+ * @return #GNUNET_YES if the transfer was successful,
+ * #GNUNET_SYSERR if the request_uid was reused for a different transfer
+ */
+enum GNUNET_GenericReturnValue
+TALER_FAKEBANK_make_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ const char *debit_account,
+ const char *credit_account,
+ const struct TALER_Amount *amount,
+ const struct TALER_WireTransferIdentifierRawP *subject,
+ const char *exchange_base_url,
+ const struct GNUNET_HashCode *request_uid,
+ uint64_t *ret_row_id,
+ struct GNUNET_TIME_Timestamp *timestamp);
+
+#endif
diff --git a/src/bank-lib/fakebank_stop.c b/src/bank-lib/fakebank_stop.c
new file mode 100644
index 000000000..e31d47523
--- /dev/null
+++ b/src/bank-lib/fakebank_stop.c
@@ -0,0 +1,192 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_stop.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include <poll.h>
+#ifdef __linux__
+#include <sys/eventfd.h>
+#endif
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lp.h"
+
+
+/**
+ * Helper function to free memory when finished.
+ *
+ * @param cls NULL
+ * @param key key of the account to free (ignored)
+ * @param val a `struct Account` to free.
+ */
+static enum GNUNET_GenericReturnValue
+free_account (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *val)
+{
+ struct Account *account = val;
+
+ (void) cls;
+ (void) key;
+ GNUNET_assert (NULL == account->lp_head);
+ GNUNET_free (account->account_name);
+ GNUNET_free (account->receiver_name);
+ GNUNET_free (account->payto_uri);
+ GNUNET_free (account->password);
+ GNUNET_free (account);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Helper function to free memory when finished.
+ *
+ * @param cls NULL
+ * @param key key of the operation to free (ignored)
+ * @param val a `struct WithdrawalOperation *` to free.
+ */
+static enum GNUNET_GenericReturnValue
+free_withdraw_op (void *cls,
+ const struct GNUNET_ShortHashCode *key,
+ void *val)
+{
+ struct WithdrawalOperation *wo = val;
+
+ (void) cls;
+ (void) key;
+ GNUNET_free (wo);
+ return GNUNET_OK;
+}
+
+
+void
+TALER_FAKEBANK_stop (struct TALER_FAKEBANK_Handle *h)
+{
+ if (NULL != h->lp_task)
+ {
+ GNUNET_SCHEDULER_cancel (h->lp_task);
+ h->lp_task = NULL;
+ }
+#if EPOLL_SUPPORT
+ if (NULL != h->mhd_rfd)
+ {
+ GNUNET_NETWORK_socket_free_memory_only_ (h->mhd_rfd);
+ h->mhd_rfd = NULL;
+ }
+#endif
+#ifdef __linux__
+ if (-1 != h->lp_event)
+#else
+ if (-1 != h->lp_event_in && -1 != h->lp_event_out)
+#endif
+ {
+ uint64_t val = 1;
+ void *ret;
+ struct LongPoller *lp;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ h->in_shutdown = true;
+ while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+#ifdef __linux__
+ GNUNET_break (sizeof (val) ==
+ write (h->lp_event,
+ &val,
+ sizeof (val)));
+#else
+ GNUNET_break (sizeof (val) ==
+ write (h->lp_event_in,
+ &val,
+ sizeof (val)));
+#endif
+ GNUNET_break (0 ==
+ pthread_join (h->lp_thread,
+ &ret));
+ GNUNET_break (NULL == ret);
+#ifdef __linux__
+ GNUNET_break (0 == close (h->lp_event));
+ h->lp_event = -1;
+#else
+ GNUNET_break (0 == close (h->lp_event_in));
+ GNUNET_break (0 == close (h->lp_event_out));
+ h->lp_event_in = -1;
+ h->lp_event_out = -1;
+#endif
+ }
+ else
+ {
+ struct LongPoller *lp;
+
+ while (NULL != (lp = GNUNET_CONTAINER_heap_remove_root (h->lp_heap)))
+ TALER_FAKEBANK_lp_trigger_ (lp);
+ }
+ if (NULL != h->mhd_bank)
+ {
+ MHD_stop_daemon (h->mhd_bank);
+ h->mhd_bank = NULL;
+ }
+ if (NULL != h->mhd_task)
+ {
+ GNUNET_SCHEDULER_cancel (h->mhd_task);
+ h->mhd_task = NULL;
+ }
+ if (NULL != h->accounts)
+ {
+ GNUNET_CONTAINER_multihashmap_iterate (h->accounts,
+ &free_account,
+ NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (h->accounts);
+ }
+ if (NULL != h->wops)
+ {
+ GNUNET_CONTAINER_multishortmap_iterate (h->wops,
+ &free_withdraw_op,
+ NULL);
+ GNUNET_CONTAINER_multishortmap_destroy (h->wops);
+ }
+ GNUNET_CONTAINER_multihashmap_destroy (h->uuid_map);
+ GNUNET_CONTAINER_multipeermap_destroy (h->rpubs);
+ GNUNET_CONTAINER_heap_destroy (h->lp_heap);
+ GNUNET_assert (0 ==
+ pthread_mutex_destroy (&h->big_lock));
+ GNUNET_assert (0 ==
+ pthread_mutex_destroy (&h->uuid_map_lock));
+ GNUNET_assert (0 ==
+ pthread_mutex_destroy (&h->accounts_lock));
+ GNUNET_assert (0 ==
+ pthread_mutex_destroy (&h->rpubs_lock));
+ for (uint64_t i = 0; i<h->ram_limit; i++)
+ GNUNET_free (h->transactions[i]);
+ GNUNET_free (h->transactions);
+ GNUNET_free (h->my_baseurl);
+ GNUNET_free (h->currency);
+ GNUNET_free (h->exchange_url);
+ GNUNET_free (h->hostname);
+ GNUNET_free (h);
+}
diff --git a/src/bank-lib/fakebank_tbi.c b/src/bank-lib/fakebank_tbi.c
new file mode 100644
index 000000000..463ec7d31
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi.c
@@ -0,0 +1,167 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi.c
+ * @brief main entry point to the Taler Bank Integration (TBI) API implementation
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_tbi.h"
+#include "fakebank_tbi_get_withdrawal_operation.h"
+#include "fakebank_tbi_post_withdrawal_operation.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbi_main_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_HEAD))
+ method = MHD_HTTP_METHOD_GET;
+ if ( (0 == strcmp (url,
+ "/config")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ struct TALER_Amount zero;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (h->currency,
+ &zero));
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("version",
+ "1:0:1"),
+ GNUNET_JSON_pack_string ("currency",
+ h->currency),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:bank:fakebank"),
+ GNUNET_JSON_pack_bool ("allow_conversion",
+ false),
+ GNUNET_JSON_pack_bool ("allow_registrations",
+ true),
+ GNUNET_JSON_pack_bool ("allow_deletions",
+ false),
+ GNUNET_JSON_pack_bool ("allow_edit_name",
+ false),
+ GNUNET_JSON_pack_bool ("allow_edit_cashout_payto_uri",
+ false),
+ TALER_JSON_pack_amount ("default_debit_threshold",
+ &zero),
+ GNUNET_JSON_pack_array_steal ("supported_tan_channels",
+ json_array ()),
+ GNUNET_JSON_pack_object_steal (
+ "currency_specification",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("name",
+ h->currency),
+ GNUNET_JSON_pack_string ("currency",
+ h->currency),
+ GNUNET_JSON_pack_uint64 ("num_fractional_input_digits",
+ 2),
+ GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits",
+ 2),
+ GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits",
+ 2),
+ GNUNET_JSON_pack_object_steal (
+ "alt_unit_names",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("0",
+ h->currency))),
+ GNUNET_JSON_pack_string ("name",
+ h->currency))),
+ GNUNET_JSON_pack_string ("name",
+ "taler-bank-integration"));
+ }
+ if ( (0 == strncmp (url,
+ "/withdrawal-operation/",
+ strlen ("/withdrawal-operation/"))) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ const char *wopid = &url[strlen ("/withdrawal-operation/")];
+ const char *lp_s
+ = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "long_poll_ms");
+ struct GNUNET_TIME_Relative lp = GNUNET_TIME_UNIT_ZERO;
+
+ if (NULL != lp_s)
+ {
+ unsigned long long d;
+ char dummy;
+
+ if (1 != sscanf (lp_s,
+ "%llu%c",
+ &d,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "long_poll_ms");
+ }
+ lp = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ d);
+ }
+ return TALER_FAKEBANK_tbi_get_withdrawal_operation_ (h,
+ connection,
+ wopid,
+ lp,
+ con_cls);
+
+ }
+ if ( (0 == strncmp (url,
+ "/withdrawal-operation/",
+ strlen ("/withdrawal-operation/"))) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST)) )
+ {
+ const char *wopid = &url[strlen ("/withdrawal-operation/")];
+
+ return TALER_FAKEBANK_tbi_post_withdrawal (h,
+ connection,
+ wopid,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ }
+
+ TALER_LOG_ERROR ("Breaking URL: %s %s\n",
+ method,
+ url);
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+}
diff --git a/src/bank-lib/fakebank_tbi.h b/src/bank-lib/fakebank_tbi.h
new file mode 100644
index 000000000..ef9f35fa2
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi.c
+ * @brief main entry point to the Taler Bank Integration (TBI) API implementation
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+
+
+#ifndef FAKEBANK_TBI_H
+#define FAKEBANK_TBI_H
+
+/**
+ * Handle incoming HTTP request to the bank integration API.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param url the requested url
+ * @param method the method (POST, GET, ...)
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbi_main_ (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_tbi_get_withdrawal_operation.c b/src/bank-lib/fakebank_tbi_get_withdrawal_operation.c
new file mode 100644
index 000000000..4749bda77
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi_get_withdrawal_operation.c
@@ -0,0 +1,141 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi_get_withdrawal_operation.c
+ * @brief Implementation of the GET /withdrawal-operation/ request of the Taler Bank Integration API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_tbi_get_withdrawal_operation.h"
+
+/**
+ * Function called to clean up a withdraw context.
+ *
+ * @param cls a `struct WithdrawContext *`
+ */
+static void
+withdraw_cleanup (void *cls)
+{
+ struct WithdrawContext *wc = cls;
+
+ GNUNET_free (wc);
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbi_get_withdrawal_operation_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *wopid,
+ struct GNUNET_TIME_Relative lp,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ struct WithdrawContext *wc;
+ const char *status_string;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &withdraw_cleanup;
+ *con_cls = cc;
+ wc = GNUNET_new (struct WithdrawContext);
+ cc->ctx = wc;
+ wc->wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ wopid);
+ if (NULL == wc->wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ wopid);
+ }
+ wc->timeout = GNUNET_TIME_relative_to_absolute (lp);
+ }
+ else
+ {
+ wc = cc->ctx;
+ }
+ if (GNUNET_TIME_absolute_is_past (wc->timeout) ||
+ h->in_shutdown ||
+ wc->wo->confirmation_done ||
+ wc->wo->aborted)
+ {
+ json_t *wt;
+
+ wt = json_array ();
+ GNUNET_assert (NULL != wt);
+ GNUNET_assert (0 ==
+ json_array_append_new (wt,
+ json_string ("x-taler-bank")));
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (wc->wo->aborted)
+ status_string = "aborted";
+ else if (wc->wo->confirmation_done)
+ status_string = "confirmed";
+ else if (wc->wo->selection_done)
+ status_string = "selected";
+ else
+ status_string = "pending";
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ // FIXME: deprecated field, should be removed in the future.
+ GNUNET_JSON_pack_bool ("aborted",
+ wc->wo->aborted),
+ // FIXME: deprecated field, should be removed in the future.
+ GNUNET_JSON_pack_bool ("selection_done",
+ wc->wo->selection_done),
+ // FIXME: deprecated field, should be removed in the future.
+ GNUNET_JSON_pack_bool ("transfer_done",
+ wc->wo->confirmation_done),
+ GNUNET_JSON_pack_string ("status",
+ status_string),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("suggested_exchange",
+ h->exchange_url)),
+ TALER_JSON_pack_amount ("amount",
+ &wc->wo->amount),
+ GNUNET_JSON_pack_array_steal ("wire_types",
+ wt));
+ }
+
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ wc->wo->debit_account,
+ GNUNET_TIME_absolute_get_remaining (wc->timeout),
+ LP_WITHDRAW,
+ wc->wo);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+}
diff --git a/src/bank-lib/fakebank_tbi_get_withdrawal_operation.h b/src/bank-lib/fakebank_tbi_get_withdrawal_operation.h
new file mode 100644
index 000000000..b42e5a768
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi_get_withdrawal_operation.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi_get_withdrawal_operation.h
+ * @brief Implementation of the GET /withdrawal-operation/ request of the Taler Bank Integration API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TBI_GET_WITHDRAWAL_OPERATION_H
+#define FAKEBANK_TBI_GET_WITHDRAWAL_OPERATION_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle GET /withdrawal-operation/{wopid} request.
+ *
+ * @param h the handle
+ * @param connection the connection
+ * @param wopid the withdrawal operation identifier
+ * @param lp how long is the long-polling timeout
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbi_get_withdrawal_operation_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *wopid,
+ struct GNUNET_TIME_Relative lp,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_tbi_post_withdrawal_operation.c b/src/bank-lib/fakebank_tbi_post_withdrawal_operation.c
new file mode 100644
index 000000000..38b92e494
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi_post_withdrawal_operation.c
@@ -0,0 +1,231 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi_post_withdrawal_operation.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_tbi_post_withdrawal_operation.h"
+
+
+/**
+ * Execute POST /withdrawal-operation/ request.
+ *
+ * @param h our handle
+ * @param connection the connection
+ * @param wopid the withdrawal operation identifier
+ * @param reserve_pub public key of the reserve
+ * @param exchange_payto_uri payto://-URI of the exchange
+ * @return MHD result code
+ */
+static MHD_RESULT
+do_post_withdrawal (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *wopid,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const char *exchange_payto_uri)
+{
+ struct WithdrawalOperation *wo;
+ char *credit_name;
+ struct Account *credit_account;
+ const char *status_string;
+
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ wo = TALER_FAKEBANK_lookup_withdrawal_operation_ (h,
+ wopid);
+ if (NULL == wo)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_TRANSACTION_NOT_FOUND,
+ wopid);
+ }
+ if ( (wo->selection_done) &&
+ (0 != GNUNET_memcmp (&wo->reserve_pub,
+ reserve_pub)) )
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_WITHDRAWAL_OPERATION_RESERVE_SELECTION_CONFLICT,
+ "reserve public key changed");
+ }
+ {
+ /* check if reserve_pub is already in use */
+ const struct GNUNET_PeerIdentity *pid;
+
+ pid = (const struct GNUNET_PeerIdentity *) &wo->reserve_pub;
+ if (GNUNET_CONTAINER_multipeermap_contains (h->rpubs,
+ pid))
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
+ NULL);
+ }
+ }
+ credit_name = TALER_xtalerbank_account_from_payto (exchange_payto_uri);
+ if (NULL == credit_name)
+ {
+ GNUNET_break_op (0);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
+ NULL);
+ }
+ credit_account = TALER_FAKEBANK_lookup_account_ (h,
+ credit_name,
+ NULL);
+ if (NULL == credit_account)
+ {
+ MHD_RESULT res;
+
+ GNUNET_break_op (0);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ res = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ credit_name);
+ GNUNET_free (credit_name);
+ return res;
+ }
+ GNUNET_free (credit_name);
+ if ( (NULL != wo->exchange_account) &&
+ (credit_account != wo->exchange_account) )
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_WITHDRAWAL_OPERATION_RESERVE_SELECTION_CONFLICT,
+ "exchange account changed");
+ }
+ wo->exchange_account = credit_account;
+ wo->reserve_pub = *reserve_pub;
+ wo->selection_done = true;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (wo->aborted)
+ status_string = "aborted";
+ else if (wo->confirmation_done)
+ status_string = "confirmed";
+ else
+ status_string = "selected";
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ // FIXME: Deprecated field, should be deleted in the future.
+ GNUNET_JSON_pack_bool ("transfer_done",
+ wo->confirmation_done),
+ GNUNET_JSON_pack_string ("status",
+ status_string));
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbi_post_withdrawal (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *wopid,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ enum GNUNET_JSON_PostResult pr;
+ json_t *json;
+ MHD_RESULT res;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &GNUNET_JSON_post_parser_cleanup;
+ *con_cls = cc;
+ }
+ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
+ connection,
+ &cc->ctx,
+ upload_data,
+ upload_data_size,
+ &json);
+ switch (pr)
+ {
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
+ }
+
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ const char *exchange_payto_url;
+ enum GNUNET_GenericReturnValue ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+ &reserve_pub),
+ GNUNET_JSON_spec_string ("selected_exchange",
+ &exchange_payto_url),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ (ret = TALER_MHD_parse_json_data (connection,
+ json,
+ spec)))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+ }
+ res = do_post_withdrawal (h,
+ connection,
+ wopid,
+ &reserve_pub,
+ exchange_payto_url);
+ }
+ json_decref (json);
+ return res;
+}
diff --git a/src/bank-lib/fakebank_tbi_post_withdrawal_operation.h b/src/bank-lib/fakebank_tbi_post_withdrawal_operation.h
new file mode 100644
index 000000000..8873bb5f6
--- /dev/null
+++ b/src/bank-lib/fakebank_tbi_post_withdrawal_operation.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbi_post_withdrawal_operation.c
+ * @brief Implementation of the Taler Bank Integration API for POAT /withdrawal-operation/ requests
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TBI_POST_WITHDRAWAL_OPERATION_H
+#define FAKEBANK_TBI_POST_WITHDRAWAL_OPERATION_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle POST /withdrawal-operation/ request.
+ *
+ * @param h our fakebank handle
+ * @param connection the connection
+ * @param wopid the withdrawal operation identifier
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbi_post_withdrawal (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *wopid,
+ const void *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_tbr.c b/src/bank-lib/fakebank_tbr.c
new file mode 100644
index 000000000..0f0e5bdc1
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr.c
@@ -0,0 +1,94 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr.c
+ * @brief main entry point for the Taler Bank Revenue API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_tbr_get_history.h"
+#include "fakebank_tbr_get_root.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbr_main_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Fakebank - Anastasis API: serving URL `%s' for account `%s'\n",
+ url,
+ account);
+
+ if ( (0 == strcmp (url,
+ "/config")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /config */
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("version",
+ "0:0:0"),
+ GNUNET_JSON_pack_string ("currency",
+ h->currency),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:bank:fakebank"),
+ GNUNET_JSON_pack_string ("name",
+ "taler-revenue"));
+ }
+
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET))
+ {
+ if ( (0 == strcmp (url,
+ "/history")) &&
+ (NULL != account) )
+ return TALER_FAKEBANK_tbr_get_history (h,
+ connection,
+ account,
+ con_cls);
+ if (0 == strcmp (url,
+ "/"))
+ return TALER_FAKEBANK_tbr_get_root (h,
+ connection);
+ }
+ /* Unexpected URL path, just close the connection. */
+ TALER_LOG_ERROR ("Breaking URL: %s %s\n",
+ method,
+ url);
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+}
diff --git a/src/bank-lib/fakebank_tbr.h b/src/bank-lib/fakebank_tbr.h
new file mode 100644
index 000000000..fb9bdfefc
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr.h
+ * @brief main entry point for the Taler Bank Revenue API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+#ifndef FAKEBANK_TBR_H
+#define FAKEBANK_TBR_H
+
+/**
+ * Handle incoming HTTP request to the Taler Bank Revenue API.
+ *
+ * @param h our handle
+ * @param connection the connection
+ * @param url the requested url
+ * @param method the method (POST, GET, ...)
+ * @param account which account should process the request
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbr_main_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_tbr_get_history.c b/src/bank-lib/fakebank_tbr_get_history.c
new file mode 100644
index 000000000..a6cfaad8d
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr_get_history.c
@@ -0,0 +1,312 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr_get_history.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_parser.h"
+#include "fakebank_tbr_get_history.h"
+
+
+/**
+ * Function called to clean up a history context.
+ *
+ * @param cls a `struct HistoryContext *`
+ */
+static void
+history_cleanup (void *cls)
+{
+ struct HistoryContext *hc = cls;
+
+ json_decref (hc->history);
+ GNUNET_free (hc);
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbr_get_history (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ struct HistoryContext *hc;
+ const struct Transaction *pos;
+ enum GNUNET_GenericReturnValue ret;
+ bool in_shutdown;
+ const char *acc_payto_uri;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &history_cleanup;
+ *con_cls = cc;
+ hc = GNUNET_new (struct HistoryContext);
+ cc->ctx = hc;
+ hc->history = json_array ();
+ if (NULL == hc->history)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling /accounts/%s/taler-revenue/history request\n",
+ account);
+ if (GNUNET_OK !=
+ (ret = TALER_FAKEBANK_common_parse_history_args (h,
+ connection,
+ &hc->ha)))
+ {
+ GNUNET_break_op (0);
+ return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
+ }
+ hc->timeout = GNUNET_TIME_relative_to_absolute (hc->ha.lp_timeout);
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ if (UINT64_MAX == hc->ha.start_idx)
+ hc->ha.start_idx = h->serial_counter;
+ hc->acc = TALER_FAKEBANK_lookup_account_ (h,
+ account,
+ NULL);
+ if (NULL == hc->acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account %s is unknown\n",
+ account);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account);
+ }
+ }
+ else
+ {
+ hc = cc->ctx;
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ }
+
+ if (! hc->ha.have_start)
+ {
+ pos = (0 > hc->ha.delta)
+ ? hc->acc->in_tail
+ : hc->acc->in_head;
+ }
+ else
+ {
+ struct Transaction *t = h->transactions[hc->ha.start_idx % h->ram_limit];
+ bool overflow;
+ uint64_t dir;
+ bool skip = true;
+
+ overflow = ( (NULL != t) && (t->row_id != hc->ha.start_idx) );
+ dir = (0 > hc->ha.delta) ? (h->ram_limit - 1) : 1;
+ /* If account does not match, linear scan for
+ first matching account. */
+ while ( (! overflow) &&
+ (NULL != t) &&
+ (t->credit_account != hc->acc) )
+ {
+ skip = false;
+ t = h->transactions[(t->row_id + dir) % h->ram_limit];
+ if ( (NULL != t) &&
+ (t->row_id == hc->ha.start_idx) )
+ overflow = true; /* full circle, give up! */
+ }
+ if ( (NULL == t) ||
+ overflow)
+ {
+ in_shutdown = h->in_shutdown;
+ /* FIXME: these conditions are unclear to me. */
+ if (GNUNET_TIME_relative_is_zero (hc->ha.lp_timeout) &&
+ (0 < hc->ha.delta))
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (overflow)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Transactions lost due to RAM limits\n");
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_BANK_ANCIENT_TRANSACTION_GONE,
+ NULL);
+ }
+ goto finish;
+ }
+ if (in_shutdown)
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ goto finish;
+ }
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (
+ hc->timeout),
+ LP_CREDIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ if (skip)
+ {
+ /* range from application is exclusive, skip the
+ matching entry */
+ if (0 > hc->ha.delta)
+ pos = t->prev_in;
+ else
+ pos = t->next_in;
+ }
+ else
+ {
+ pos = t;
+ }
+ }
+ if (NULL != pos)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Returning %lld credit transactions starting (inclusive) from %llu\n",
+ (long long) hc->ha.delta,
+ (unsigned long long) pos->row_id);
+ while ( (0 != hc->ha.delta) &&
+ (NULL != pos) )
+ {
+ json_t *trans;
+ char *subject;
+
+ if (T_DEBIT != pos->type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected CREDIT transaction #%llu for account `%s'\n",
+ (unsigned long long) pos->row_id,
+ account);
+ if (0 > hc->ha.delta)
+ pos = pos->prev_in;
+ if (0 < hc->ha.delta)
+ pos = pos->next_in;
+ continue;
+ }
+
+ {
+ char *wtids;
+
+ wtids = GNUNET_STRINGS_data_to_string_alloc (
+ &pos->subject.debit.wtid,
+ sizeof (pos->subject.debit.wtid));
+ GNUNET_asprintf (&subject,
+ "%s %s",
+ wtids,
+ pos->subject.debit.exchange_base_url);
+ GNUNET_free (wtids);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Found transaction over %s with subject %s\n",
+ TALER_amount2s (&pos->amount),
+ subject);
+ trans = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "RESERVE"),
+ GNUNET_JSON_pack_uint64 ("row_id",
+ pos->row_id),
+ GNUNET_JSON_pack_timestamp ("date",
+ pos->date),
+ TALER_JSON_pack_amount ("amount",
+ &pos->amount),
+ GNUNET_JSON_pack_string ("debit_account",
+ pos->debit_account->payto_uri),
+ GNUNET_JSON_pack_string ("subject",
+ subject));
+ GNUNET_free (subject);
+ GNUNET_assert (NULL != trans);
+ GNUNET_assert (0 ==
+ json_array_append_new (hc->history,
+ trans));
+ if (hc->ha.delta > 0)
+ hc->ha.delta--;
+ else
+ hc->ha.delta++;
+ if (0 > hc->ha.delta)
+ pos = pos->prev_in;
+ if (0 < hc->ha.delta)
+ pos = pos->next_in;
+ }
+ if ( (0 == json_array_size (hc->history)) &&
+ (! h->in_shutdown) &&
+ (GNUNET_TIME_absolute_is_future (hc->timeout)) &&
+ (0 < hc->ha.delta))
+ {
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (hc->timeout),
+ LP_CREDIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ in_shutdown = h->in_shutdown;
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+finish:
+ if (0 == json_array_size (hc->history))
+ {
+ GNUNET_break (in_shutdown ||
+ (! GNUNET_TIME_absolute_is_future (hc->timeout)));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Zero transactions found\n");
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ {
+ json_t *h = hc->history;
+
+ hc->history = NULL;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string (
+ "credit_account",
+ acc_payto_uri),
+ GNUNET_JSON_pack_array_steal (
+ "incoming_transactions",
+ h));
+ }
+}
diff --git a/src/bank-lib/fakebank_tbr_get_history.h b/src/bank-lib/fakebank_tbr_get_history.h
new file mode 100644
index 000000000..997c9a86b
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr_get_history.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr_get_history.h
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TBR_GET_HISTORY_H
+#define FAKEBANK_TBR_GET_HISTORY_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for /history
+ * of the taler-revenue API. This one can return transactions
+ * created by debits from the exchange!
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account which account the request is about
+ * @param con_cls closure for request (NULL or &special_ptr)
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbr_get_history (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_tbr_get_root.c b/src/bank-lib/fakebank_tbr_get_root.c
new file mode 100644
index 000000000..6e518d661
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr_get_root.c
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr_get_root.c
+ * @brief return the main "/" page for the Taler Bank Revenue API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_tbr_get_root (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection)
+{
+ MHD_RESULT ret;
+ struct MHD_Response *resp;
+#define HELLOMSG "Hello, Fakebank (Bank Revenue API here)!"
+
+ (void) h;
+ resp = MHD_create_response_from_buffer (
+ strlen (HELLOMSG),
+ HELLOMSG,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_OK,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
+}
diff --git a/src/bank-lib/fakebank_tbr_get_root.h b/src/bank-lib/fakebank_tbr_get_root.h
new file mode 100644
index 000000000..eda8060bf
--- /dev/null
+++ b/src/bank-lib/fakebank_tbr_get_root.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_tbr_get_root.h
+ * @brief return the main "/" page for the Taler Bank Revenue API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TBR_GET_ROOT_H
+#define FAKEBANK_TBR_GET_ROOT_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for "/" (home page).
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_tbr_get_root (struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection);
+
+#endif
diff --git a/src/bank-lib/fakebank_twg.c b/src/bank-lib/fakebank_twg.c
new file mode 100644
index 000000000..9356e69ba
--- /dev/null
+++ b/src/bank-lib/fakebank_twg.c
@@ -0,0 +1,124 @@
+/*
+ This file is part of TALER
+ (C) 2016-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg.c
+ * @brief main entry point for the Taler Wire Gateway API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_twg.h"
+#include "fakebank_twg_admin_add_incoming.h"
+#include "fakebank_twg_get_root.h"
+#include "fakebank_twg_history.h"
+#include "fakebank_twg_transfer.h"
+
+
+MHD_RESULT
+TALER_FAKEBANK_twg_main_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Fakebank TWG, serving URL `%s' for account `%s'\n",
+ url,
+ account);
+ if ( (0 == strcmp (url,
+ "/config")) &&
+ (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET)) )
+ {
+ /* GET /config */
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("version",
+ "0:0:0"),
+ GNUNET_JSON_pack_string ("currency",
+ h->currency),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:bank:fakebank"),
+ GNUNET_JSON_pack_string ("name",
+ "taler-wire-gateway"));
+ }
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_GET))
+ {
+ if ( (0 == strcmp (url,
+ "/history/incoming")) &&
+ (NULL != account) )
+ return TALER_FAKEBANK_twg_get_credit_history_ (h,
+ connection,
+ account,
+ con_cls);
+ if ( (0 == strcmp (url,
+ "/history/outgoing")) &&
+ (NULL != account) )
+ return TALER_FAKEBANK_twg_get_debit_history_ (h,
+ connection,
+ account,
+ con_cls);
+ if (0 == strcmp (url,
+ "/"))
+ return TALER_FAKEBANK_twg_get_root_ (h,
+ connection);
+ }
+ else if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_POST))
+ {
+ if ( (0 == strcmp (url,
+ "/admin/add-incoming")) &&
+ (NULL != account) )
+ return TALER_FAKEBANK_twg_admin_add_incoming_ (h,
+ connection,
+ account,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ if ( (0 == strcmp (url,
+ "/transfer")) &&
+ (NULL != account) )
+ return TALER_FAKEBANK_handle_transfer_ (h,
+ connection,
+ account,
+ upload_data,
+ upload_data_size,
+ con_cls);
+ }
+ /* Unexpected URL path, just close the connection. */
+ TALER_LOG_ERROR ("Breaking URL: %s %s\n",
+ method,
+ url);
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+}
diff --git a/src/bank-lib/fakebank_twg.h b/src/bank-lib/fakebank_twg.h
new file mode 100644
index 000000000..de808a21f
--- /dev/null
+++ b/src/bank-lib/fakebank_twg.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg.h
+ * @brief main entry point for the Taler Wire Gateway API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TWG_H
+#define FAKEBANK_TWG_H
+
+#include "taler_fakebank_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+
+
+/**
+ * Handle incoming HTTP request to the Taler Wire Gateway
+ * API.
+ *
+ * @param h our handle
+ * @param connection the connection
+ * @param url the requested url
+ * @param method the method (POST, GET, ...)
+ * @param account which account should process the request
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_main_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *url,
+ const char *method,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_twg_admin_add_incoming.c b/src/bank-lib/fakebank_twg_admin_add_incoming.c
new file mode 100644
index 000000000..2db4f1fe5
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_admin_add_incoming.c
@@ -0,0 +1,160 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_admin_add_incoming.c
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_make_admin_transfer.h"
+#include "fakebank_twg_admin_add_incoming.h"
+
+MHD_RESULT
+TALER_FAKEBANK_twg_admin_add_incoming_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ enum GNUNET_JSON_PostResult pr;
+ json_t *json;
+ uint64_t row_id;
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &GNUNET_JSON_post_parser_cleanup;
+ *con_cls = cc;
+ }
+ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
+ connection,
+ &cc->ctx,
+ upload_data,
+ upload_data_size,
+ &json);
+ switch (pr)
+ {
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
+ }
+ {
+ const char *debit_account;
+ struct TALER_Amount amount;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ char *debit;
+ enum GNUNET_GenericReturnValue ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+ &reserve_pub),
+ GNUNET_JSON_spec_string ("debit_account",
+ &debit_account),
+ TALER_JSON_spec_amount ("amount",
+ h->currency,
+ &amount),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ (ret = TALER_MHD_parse_json_data (connection,
+ json,
+ spec)))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+ }
+ if (0 != strcasecmp (amount.currency,
+ h->currency))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Currency `%s' does not match our configuration\n",
+ amount.currency);
+ json_decref (json);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_GENERIC_CURRENCY_MISMATCH,
+ NULL);
+ }
+ debit = TALER_xtalerbank_account_from_payto (debit_account);
+ if (NULL == debit)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
+ debit_account);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s\n",
+ debit,
+ account,
+ TALER_B2S (&reserve_pub),
+ TALER_amount2s (&amount));
+ ret = TALER_FAKEBANK_make_admin_transfer_ (h,
+ debit,
+ account,
+ &amount,
+ &reserve_pub,
+ &row_id,
+ &timestamp);
+ GNUNET_free (debit);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Reserve public key not unique\n");
+ json_decref (json);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_DUPLICATE_RESERVE_PUB_SUBJECT,
+ NULL);
+ }
+ }
+ json_decref (json);
+
+ /* Finally build response object */
+ return TALER_MHD_REPLY_JSON_PACK (connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_uint64 ("row_id",
+ row_id),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ timestamp));
+}
diff --git a/src/bank-lib/fakebank_twg_admin_add_incoming.h b/src/bank-lib/fakebank_twg_admin_add_incoming.h
new file mode 100644
index 000000000..220a10fc8
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_admin_add_incoming.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_admin_add_incoming.h
+ * @brief library that fakes being a Taler bank for testcases
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TWG_ADMIN_ADD_INCOMING_H
+#define FAKEBANK_TWG_ADMIN_ADD_INCOMING_H
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+/**
+ * Handle incoming HTTP request for /admin/add/incoming.
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account account into which to deposit the funds (credit)
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request (a `struct ConnectionContext *`)
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_admin_add_incoming_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/fakebank_twg_get_root.c b/src/bank-lib/fakebank_twg_get_root.c
new file mode 100644
index 000000000..09589890e
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_get_root.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_get_root.c
+ * @brief return the "/" page for the taler wire gateway
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for "/" (home page).
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_get_root_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection)
+{
+ MHD_RESULT ret;
+ struct MHD_Response *resp;
+#define HELLOMSG "Hello, Fakebank (Taler Wire Gateway)!"
+
+ (void) h;
+ resp = MHD_create_response_from_buffer (
+ strlen (HELLOMSG),
+ HELLOMSG,
+ MHD_RESPMEM_MUST_COPY);
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_OK,
+ resp);
+ MHD_destroy_response (resp);
+ return ret;
+}
diff --git a/src/bank-lib/fakebank_twg_get_root.h b/src/bank-lib/fakebank_twg_get_root.h
new file mode 100644
index 000000000..8bbcf4192
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_get_root.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_get_root.h
+ * @brief return the "/" page for the taler wire gateway
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TWG_GET_ROOT_H
+#define FAKEBANK_TWG_GET_ROOT_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for "/" (home page).
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_get_root_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection);
+
+#endif
diff --git a/src/bank-lib/fakebank_twg_history.c b/src/bank-lib/fakebank_twg_history.c
new file mode 100644
index 000000000..5dfc160b0
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_history.c
@@ -0,0 +1,537 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_history.c
+ * @brief routines to return account histories for the Taler Wire Gateway API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include <pthread.h>
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_lookup.h"
+#include "fakebank_common_lp.h"
+#include "fakebank_common_parser.h"
+
+/**
+ * Function called to clean up a history context.
+ *
+ * @param cls a `struct HistoryContext *`
+ */
+static void
+history_cleanup (void *cls)
+{
+ struct HistoryContext *hc = cls;
+
+ json_decref (hc->history);
+ GNUNET_free (hc);
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_twg_get_debit_history_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ struct HistoryContext *hc;
+ struct Transaction *pos;
+ enum GNUNET_GenericReturnValue ret;
+ bool in_shutdown;
+ const char *acc_payto_uri;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &history_cleanup;
+ *con_cls = cc;
+ hc = GNUNET_new (struct HistoryContext);
+ cc->ctx = hc;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling /history/outgoing connection %p\n",
+ connection);
+ if (GNUNET_OK !=
+ (ret = TALER_FAKEBANK_common_parse_history_args (h,
+ connection,
+ &hc->ha)))
+ {
+ GNUNET_break_op (0);
+ return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
+ }
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ if (UINT64_MAX == hc->ha.start_idx)
+ hc->ha.start_idx = h->serial_counter;
+ hc->acc = TALER_FAKEBANK_lookup_account_ (h,
+ account,
+ NULL);
+ if (NULL == hc->acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account);
+ }
+ hc->history = json_array ();
+ if (NULL == hc->history)
+ {
+ GNUNET_break (0);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_NO;
+ }
+ hc->timeout = GNUNET_TIME_relative_to_absolute (hc->ha.lp_timeout);
+ }
+ else
+ {
+ hc = cc->ctx;
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ }
+
+ if (! hc->ha.have_start)
+ {
+ pos = (0 > hc->ha.delta)
+ ? hc->acc->out_tail
+ : hc->acc->out_head;
+ }
+ else
+ {
+ struct Transaction *t = h->transactions[hc->ha.start_idx % h->ram_limit];
+ bool overflow;
+ uint64_t dir;
+ bool skip = true;
+
+ dir = (0 > hc->ha.delta) ? (h->ram_limit - 1) : 1;
+ overflow = (t->row_id != hc->ha.start_idx);
+ /* If account does not match, linear scan for
+ first matching account. */
+ while ( (! overflow) &&
+ (NULL != t) &&
+ (t->debit_account != hc->acc) )
+ {
+ skip = false;
+ t = h->transactions[(t->row_id + dir) % h->ram_limit];
+ if ( (NULL != t) &&
+ (t->row_id == hc->ha.start_idx) )
+ overflow = true; /* full circle, give up! */
+ }
+ if ( (NULL == t) ||
+ overflow)
+ {
+ /* FIXME: these conditions are unclear to me. */
+ if ( (GNUNET_TIME_relative_is_zero (hc->ha.lp_timeout)) &&
+ (0 < hc->ha.delta))
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ in_shutdown = h->in_shutdown;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (overflow)
+ {
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_BANK_ANCIENT_TRANSACTION_GONE,
+ NULL);
+ }
+ goto finish;
+ }
+ if (h->in_shutdown)
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ in_shutdown = h->in_shutdown;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ goto finish;
+ }
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (
+ hc->timeout),
+ LP_DEBIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ if (t->debit_account != hc->acc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid start specified, transaction %llu not with account %s!\n",
+ (unsigned long long) hc->ha.start_idx,
+ account);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_NO;
+ }
+ if (skip)
+ {
+ /* range is exclusive, skip the matching entry */
+ if (0 > hc->ha.delta)
+ pos = t->prev_out;
+ else
+ pos = t->next_out;
+ }
+ else
+ {
+ pos = t;
+ }
+ }
+ if (NULL != pos)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Returning %lld debit transactions starting (inclusive) from %llu\n",
+ (long long) hc->ha.delta,
+ (unsigned long long) pos->row_id);
+ while ( (0 != hc->ha.delta) &&
+ (NULL != pos) )
+ {
+ json_t *trans;
+ char *credit_payto;
+
+ if (T_DEBIT != pos->type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected CREDIT transaction #%llu for account `%s'\n",
+ (unsigned long long) pos->row_id,
+ account);
+ if (0 > hc->ha.delta)
+ pos = pos->prev_in;
+ if (0 < hc->ha.delta)
+ pos = pos->next_in;
+ continue;
+ }
+ GNUNET_asprintf (&credit_payto,
+ "payto://x-taler-bank/localhost/%s?receiver-name=%s",
+ pos->credit_account->account_name,
+ pos->credit_account->receiver_name);
+
+ trans = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("row_id",
+ pos->row_id),
+ GNUNET_JSON_pack_timestamp ("date",
+ pos->date),
+ TALER_JSON_pack_amount ("amount",
+ &pos->amount),
+ GNUNET_JSON_pack_string ("credit_account",
+ credit_payto),
+ GNUNET_JSON_pack_string ("exchange_base_url",
+ pos->subject.debit.exchange_base_url),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &pos->subject.debit.wtid));
+ GNUNET_assert (NULL != trans);
+ GNUNET_free (credit_payto);
+ GNUNET_assert (0 ==
+ json_array_append_new (hc->history,
+ trans));
+ if (hc->ha.delta > 0)
+ hc->ha.delta--;
+ else
+ hc->ha.delta++;
+ if (0 > hc->ha.delta)
+ pos = pos->prev_out;
+ if (0 < hc->ha.delta)
+ pos = pos->next_out;
+ }
+ if ( (0 == json_array_size (hc->history)) &&
+ (! h->in_shutdown) &&
+ (GNUNET_TIME_absolute_is_future (hc->timeout)) &&
+ (0 < hc->ha.delta))
+ {
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (hc->timeout),
+ LP_DEBIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ in_shutdown = h->in_shutdown;
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+finish:
+ if (0 == json_array_size (hc->history))
+ {
+ GNUNET_break (in_shutdown ||
+ (! GNUNET_TIME_absolute_is_future (hc->timeout)));
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ {
+ json_t *h = hc->history;
+
+ hc->history = NULL;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string (
+ "debit_account",
+ acc_payto_uri),
+ GNUNET_JSON_pack_array_steal (
+ "outgoing_transactions",
+ h));
+ }
+}
+
+
+MHD_RESULT
+TALER_FAKEBANK_twg_get_credit_history_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ struct HistoryContext *hc;
+ const struct Transaction *pos;
+ enum GNUNET_GenericReturnValue ret;
+ bool in_shutdown;
+ const char *acc_payto_uri;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &history_cleanup;
+ *con_cls = cc;
+ hc = GNUNET_new (struct HistoryContext);
+ cc->ctx = hc;
+ hc->history = json_array ();
+ if (NULL == hc->history)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling /history/incoming connection %p\n",
+ connection);
+ if (GNUNET_OK !=
+ (ret = TALER_FAKEBANK_common_parse_history_args (h,
+ connection,
+ &hc->ha)))
+ {
+ GNUNET_break_op (0);
+ return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
+ }
+ hc->timeout = GNUNET_TIME_relative_to_absolute (hc->ha.lp_timeout);
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ if (UINT64_MAX == hc->ha.start_idx)
+ hc->ha.start_idx = h->serial_counter;
+ hc->acc = TALER_FAKEBANK_lookup_account_ (h,
+ account,
+ NULL);
+ if (NULL == hc->acc)
+ {
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_BANK_UNKNOWN_ACCOUNT,
+ account);
+ }
+ }
+ else
+ {
+ hc = cc->ctx;
+ GNUNET_assert (0 ==
+ pthread_mutex_lock (&h->big_lock));
+ }
+
+ if (! hc->ha.have_start)
+ {
+ pos = (0 > hc->ha.delta)
+ ? hc->acc->in_tail
+ : hc->acc->in_head;
+ }
+ else
+ {
+ struct Transaction *t = h->transactions[hc->ha.start_idx % h->ram_limit];
+ bool overflow;
+ uint64_t dir;
+ bool skip = true;
+
+ overflow = ( (NULL != t) && (t->row_id != hc->ha.start_idx) );
+ dir = (0 > hc->ha.delta) ? (h->ram_limit - 1) : 1;
+ /* If account does not match, linear scan for
+ first matching account. */
+ while ( (! overflow) &&
+ (NULL != t) &&
+ (t->credit_account != hc->acc) )
+ {
+ skip = false;
+ t = h->transactions[(t->row_id + dir) % h->ram_limit];
+ if ( (NULL != t) &&
+ (t->row_id == hc->ha.start_idx) )
+ overflow = true; /* full circle, give up! */
+ }
+ if ( (NULL == t) ||
+ overflow)
+ {
+ in_shutdown = h->in_shutdown;
+ /* FIXME: these conditions are unclear to me. */
+ if (GNUNET_TIME_relative_is_zero (hc->ha.lp_timeout) &&
+ (0 < hc->ha.delta))
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ if (overflow)
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_BANK_ANCIENT_TRANSACTION_GONE,
+ NULL);
+ goto finish;
+ }
+ if (in_shutdown)
+ {
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ goto finish;
+ }
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (
+ hc->timeout),
+ LP_CREDIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ if (skip)
+ {
+ /* range from application is exclusive, skip the
+ matching entry */
+ if (0 > hc->ha.delta)
+ pos = t->prev_in;
+ else
+ pos = t->next_in;
+ }
+ else
+ {
+ pos = t;
+ }
+ }
+ if (NULL != pos)
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Returning %lld credit transactions starting (inclusive) from %llu\n",
+ (long long) hc->ha.delta,
+ (unsigned long long) pos->row_id);
+ while ( (0 != hc->ha.delta) &&
+ (NULL != pos) )
+ {
+ json_t *trans;
+
+ if (T_CREDIT != pos->type)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unexpected DEBIT transaction #%llu for account `%s'\n",
+ (unsigned long long) pos->row_id,
+ account);
+ if (0 > hc->ha.delta)
+ pos = pos->prev_in;
+ if (0 < hc->ha.delta)
+ pos = pos->next_in;
+ continue;
+ }
+ trans = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("row_id",
+ pos->row_id),
+ GNUNET_JSON_pack_timestamp ("date",
+ pos->date),
+ TALER_JSON_pack_amount ("amount",
+ &pos->amount),
+ GNUNET_JSON_pack_string ("debit_account",
+ pos->debit_account->payto_uri),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ &pos->subject.credit.reserve_pub));
+ GNUNET_assert (NULL != trans);
+ GNUNET_assert (0 ==
+ json_array_append_new (hc->history,
+ trans));
+ if (hc->ha.delta > 0)
+ hc->ha.delta--;
+ else
+ hc->ha.delta++;
+ if (0 > hc->ha.delta)
+ pos = pos->prev_in;
+ if (0 < hc->ha.delta)
+ pos = pos->next_in;
+ }
+ if ( (0 == json_array_size (hc->history)) &&
+ (! h->in_shutdown) &&
+ (GNUNET_TIME_absolute_is_future (hc->timeout)) &&
+ (0 < hc->ha.delta))
+ {
+ TALER_FAKEBANK_start_lp_ (h,
+ connection,
+ hc->acc,
+ GNUNET_TIME_absolute_get_remaining (hc->timeout),
+ LP_CREDIT,
+ NULL);
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+ return MHD_YES;
+ }
+ in_shutdown = h->in_shutdown;
+ acc_payto_uri = hc->acc->payto_uri;
+ GNUNET_assert (0 ==
+ pthread_mutex_unlock (&h->big_lock));
+finish:
+ if (0 == json_array_size (hc->history))
+ {
+ GNUNET_break (in_shutdown ||
+ (! GNUNET_TIME_absolute_is_future (hc->timeout)));
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ {
+ json_t *h = hc->history;
+
+ hc->history = NULL;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string (
+ "credit_account",
+ acc_payto_uri),
+ GNUNET_JSON_pack_array_steal (
+ "incoming_transactions",
+ h));
+ }
+}
diff --git a/src/bank-lib/fakebank_twg_history.h b/src/bank-lib/fakebank_twg_history.h
new file mode 100644
index 000000000..c49678aef
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_history.h
@@ -0,0 +1,67 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_history.c
+ * @brief routines to return account histories for the Taler Wire Gateway API
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TWG_HISTORY_H
+#define FAKEBANK_TWG_HISTORY_H
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for /history/outgoing
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account which account the request is about
+ * @param con_cls closure for request
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_get_debit_history_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls);
+
+
+/**
+ * Handle incoming HTTP request for /history/incoming
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account which account the request is about
+ * @param con_cls closure for request (NULL or &special_ptr)
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_twg_get_credit_history_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ void **con_cls);
+
+
+#endif
diff --git a/src/bank-lib/fakebank_twg_transfer.c b/src/bank-lib/fakebank_twg_transfer.c
new file mode 100644
index 000000000..fef314a52
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_transfer.c
@@ -0,0 +1,178 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_transfer.c
+ * @brief implementation of the Taler Wire Gateway "/transfer" endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#include "platform.h"
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+#include "fakebank_common_transact.h"
+#include "fakebank_twg_transfer.h"
+
+
+/**
+ * Handle incoming HTTP request for /transfer.
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account account making the transfer
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request (a `struct ConnectionContext *`)
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_handle_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ struct ConnectionContext *cc = *con_cls;
+ enum GNUNET_JSON_PostResult pr;
+ json_t *json;
+ uint64_t row_id;
+ struct GNUNET_TIME_Timestamp ts;
+
+ if (NULL == cc)
+ {
+ cc = GNUNET_new (struct ConnectionContext);
+ cc->ctx_cleaner = &GNUNET_JSON_post_parser_cleanup;
+ *con_cls = cc;
+ }
+ pr = GNUNET_JSON_post_parser (REQUEST_BUFFER_MAX,
+ connection,
+ &cc->ctx,
+ upload_data,
+ upload_data_size,
+ &json);
+ switch (pr)
+ {
+ case GNUNET_JSON_PR_OUT_OF_MEMORY:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_CONTINUE:
+ return MHD_YES;
+ case GNUNET_JSON_PR_REQUEST_TOO_LARGE:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_JSON_INVALID:
+ GNUNET_break (0);
+ return MHD_NO;
+ case GNUNET_JSON_PR_SUCCESS:
+ break;
+ }
+ {
+ struct GNUNET_HashCode uuid;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ const char *credit_account;
+ char *credit;
+ const char *base_url;
+ struct TALER_Amount amount;
+ enum GNUNET_GenericReturnValue ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("request_uid",
+ &uuid),
+ TALER_JSON_spec_amount ("amount",
+ h->currency,
+ &amount),
+ GNUNET_JSON_spec_string ("exchange_base_url",
+ &base_url),
+ GNUNET_JSON_spec_fixed_auto ("wtid",
+ &wtid),
+ GNUNET_JSON_spec_string ("credit_account",
+ &credit_account),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ (ret = TALER_MHD_parse_json_data (connection,
+ json,
+ spec)))
+ {
+ GNUNET_break_op (0);
+ json_decref (json);
+ return (GNUNET_NO == ret) ? MHD_YES : MHD_NO;
+ }
+ {
+ enum GNUNET_GenericReturnValue ret;
+
+ credit = TALER_xtalerbank_account_from_payto (credit_account);
+ if (NULL == credit)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
+ credit_account);
+ }
+ ret = TALER_FAKEBANK_make_transfer_ (h,
+ account,
+ credit,
+ &amount,
+ &wtid,
+ base_url,
+ &uuid,
+ &row_id,
+ &ts);
+ if (GNUNET_OK != ret)
+ {
+ MHD_RESULT res;
+ char *uids;
+
+ GNUNET_break (0);
+ uids = GNUNET_STRINGS_data_to_string_alloc (&uuid,
+ sizeof (uuid));
+ json_decref (json);
+ res = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_BANK_TRANSFER_REQUEST_UID_REUSED,
+ uids);
+ GNUNET_free (uids);
+ return res;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Receiving incoming wire transfer: %s->%s, subject: %s, amount: %s, from %s\n",
+ account,
+ credit,
+ TALER_B2S (&wtid),
+ TALER_amount2s (&amount),
+ base_url);
+ GNUNET_free (credit);
+ }
+ }
+ json_decref (json);
+
+ /* Finally build response object */
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_uint64 ("row_id",
+ row_id),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ ts));
+}
diff --git a/src/bank-lib/fakebank_twg_transfer.h b/src/bank-lib/fakebank_twg_transfer.h
new file mode 100644
index 000000000..2019565bf
--- /dev/null
+++ b/src/bank-lib/fakebank_twg_transfer.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of TALER
+ (C) 2016-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file bank-lib/fakebank_twg_transfer.h
+ * @brief implementation of the Taler Wire Gateway "/transfer" endpoint
+ * @author Christian Grothoff <christian@grothoff.org>
+ */
+#ifndef FAKEBANK_TWG_TRANSFER_H
+#define FAKEBANK_TWG_TRANSFER_H
+
+
+#include "taler_fakebank_lib.h"
+#include "taler_bank_service.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "fakebank.h"
+
+
+/**
+ * Handle incoming HTTP request for /transfer.
+ *
+ * @param h the fakebank handle
+ * @param connection the connection
+ * @param account account making the transfer
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request (a `struct ConnectionContext *`)
+ * @return MHD result code
+ */
+MHD_RESULT
+TALER_FAKEBANK_handle_transfer_ (
+ struct TALER_FAKEBANK_Handle *h,
+ struct MHD_Connection *connection,
+ const char *account,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls);
+
+#endif
diff --git a/src/bank-lib/taler-exchange-wire-gateway-client.c b/src/bank-lib/taler-exchange-wire-gateway-client.c
index ab16573a7..b0d387b71 100644
--- a/src/bank-lib/taler-exchange-wire-gateway-client.c
+++ b/src/bank-lib/taler-exchange-wire-gateway-client.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017-2021 Taler Systems SA
+ Copyright (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -152,83 +152,72 @@ do_shutdown (void *cls)
/**
- * Callback used to process ONE entry in the transaction
+ * Callback used to process the transaction
* history returned by the bank.
*
* @param cls closure
- * @param http_status HTTP status code from server
- * @param ec taler error code
- * @param serial_id identification of the position at
- * which we are returning data
- * @param details details about the wire transfer
- * @param json original full response from server
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to
- * abort iteration
+ * @param reply response we got from the bank
*/
-static enum GNUNET_GenericReturnValue
+static void
credit_history_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- const struct TALER_BANK_CreditDetails *details,
- const json_t *json)
+ const struct TALER_BANK_CreditHistoryResponse *reply)
{
(void) cls;
chh = NULL;
- if (MHD_HTTP_OK != http_status)
+ switch (reply->http_status)
{
- if ( (MHD_HTTP_NO_CONTENT != http_status) ||
- (TALER_EC_NONE != ec) )
+ case 0:
+ fprintf (stderr,
+ "Failed to obtain HTTP reply from `%s'\n",
+ auth.wire_gateway_url);
+ global_ret = 2;
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ fprintf (stdout,
+ "No transactions.\n");
+ global_ret = 0;
+ break;
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<reply->details.ok.details_length; i++)
{
- if (0 == http_status)
- {
- fprintf (stderr,
- "Failed to obtain HTTP reply from `%s'\n",
- auth.wire_gateway_url);
- }
- else
- {
- fprintf (stderr,
- "Failed to obtain credit history from `%s': HTTP status %u (%s)\n",
- auth.wire_gateway_url,
- http_status,
- TALER_ErrorCode_get_hint (ec));
- }
- if (NULL != json)
- json_dumpf (json,
- stderr,
- JSON_INDENT (2));
- global_ret = 2;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_NO;
+ const struct TALER_BANK_CreditDetails *cd =
+ &reply->details.ok.details[i];
+
+ /* If credit/debit accounts were specified, use as a filter */
+ if ( (NULL != credit_account) &&
+ (0 != strcasecmp (credit_account,
+ reply->details.ok.credit_account_uri) ) )
+ continue;
+ if ( (NULL != debit_account) &&
+ (0 != strcasecmp (debit_account,
+ cd->debit_account_uri) ) )
+ continue;
+ fprintf (stdout,
+ "%llu: %s->%s (%s) over %s at %s\n",
+ (unsigned long long) cd->serial_id,
+ cd->debit_account_uri,
+ reply->details.ok.credit_account_uri,
+ TALER_B2S (&cd->reserve_pub),
+ TALER_amount2s (&cd->amount),
+ GNUNET_TIME_timestamp2s (cd->execution_date));
}
- fprintf (stdout,
- "End of transactions list.\n");
global_ret = 0;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_NO;
+ break;
+ default:
+ fprintf (stderr,
+ "Failed to obtain credit history from `%s': HTTP status %u (%s)\n",
+ auth.wire_gateway_url,
+ reply->http_status,
+ TALER_ErrorCode_get_hint (reply->ec));
+ if (NULL != reply->response)
+ json_dumpf (reply->response,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = 2;
+ break;
}
-
- /* If credit/debit accounts were specified, use as a filter */
- if ( (NULL != credit_account) &&
- (0 != strcasecmp (credit_account,
- details->credit_account_uri) ) )
- return GNUNET_OK;
- if ( (NULL != debit_account) &&
- (0 != strcasecmp (debit_account,
- details->debit_account_uri) ) )
- return GNUNET_OK;
-
- fprintf (stdout,
- "%llu: %s->%s (%s) over %s at %s\n",
- (unsigned long long) serial_id,
- details->debit_account_uri,
- details->credit_account_uri,
- TALER_B2S (&details->reserve_pub),
- TALER_amount2s (&details->amount),
- GNUNET_TIME_timestamp2s (details->execution_date));
- return GNUNET_OK;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -264,84 +253,71 @@ execute_credit_history (void)
/**
- * Function with the debit debit transaction history.
+ * Function with the debit transaction history.
*
* @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
- * 0 if the bank's reply is bogus (fails to follow the protocol),
- * #MHD_HTTP_NO_CONTENT if there are no more results; on success the
- * last callback is always of this status (even if `abs(num_results)` were
- * already returned).
- * @param ec detailed error code
- * @param serial_id monotonically increasing counter corresponding to the transaction
- * @param details details about the wire transfer
- * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param reply response details
*/
-static enum GNUNET_GenericReturnValue
+static void
debit_history_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- const struct TALER_BANK_DebitDetails *details,
- const json_t *json)
+ const struct TALER_BANK_DebitHistoryResponse *reply)
{
(void) cls;
dhh = NULL;
- if (MHD_HTTP_OK != http_status)
+ switch (reply->http_status)
{
- if ( (MHD_HTTP_NO_CONTENT != http_status) ||
- (TALER_EC_NONE != ec) )
+ case 0:
+ fprintf (stderr,
+ "Failed to obtain HTTP reply from `%s'\n",
+ auth.wire_gateway_url);
+ global_ret = 2;
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ fprintf (stdout,
+ "No transactions.\n");
+ global_ret = 0;
+ break;
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<reply->details.ok.details_length; i++)
{
- if (0 == http_status)
- {
- fprintf (stderr,
- "Failed to obtain HTTP reply from `%s'\n",
- auth.wire_gateway_url);
- }
- else
- {
- fprintf (stderr,
- "Failed to obtain debit history from `%s': HTTP status %u (%s)\n",
- auth.wire_gateway_url,
- http_status,
- TALER_ErrorCode_get_hint (ec));
- }
- if (NULL != json)
- json_dumpf (json,
- stderr,
- JSON_INDENT (2));
- global_ret = 2;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_NO;
+ const struct TALER_BANK_DebitDetails *dd =
+ &reply->details.ok.details[i];
+
+ /* If credit/debit accounts were specified, use as a filter */
+ if ( (NULL != credit_account) &&
+ (0 != strcasecmp (credit_account,
+ dd->credit_account_uri) ) )
+ continue;
+ if ( (NULL != debit_account) &&
+ (0 != strcasecmp (debit_account,
+ reply->details.ok.debit_account_uri) ) )
+ continue;
+ fprintf (stdout,
+ "%llu: %s->%s (%s) over %s at %s\n",
+ (unsigned long long) dd->serial_id,
+ reply->details.ok.debit_account_uri,
+ dd->credit_account_uri,
+ TALER_B2S (&dd->wtid),
+ TALER_amount2s (&dd->amount),
+ GNUNET_TIME_timestamp2s (dd->execution_date));
}
- fprintf (stdout,
- "End of transactions list.\n");
global_ret = 0;
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_NO;
+ break;
+ default:
+ fprintf (stderr,
+ "Failed to obtain debit history from `%s': HTTP status %u (%s)\n",
+ auth.wire_gateway_url,
+ reply->http_status,
+ TALER_ErrorCode_get_hint (reply->ec));
+ if (NULL != reply->response)
+ json_dumpf (reply->response,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = 2;
+ break;
}
-
- /* If credit/debit accounts were specified, use as a filter */
- if ( (NULL != credit_account) &&
- (0 != strcasecmp (credit_account,
- details->credit_account_uri) ) )
- return GNUNET_OK;
- if ( (NULL != debit_account) &&
- (0 != strcasecmp (debit_account,
- details->debit_account_uri) ) )
- return GNUNET_OK;
-
- fprintf (stdout,
- "%llu: %s->%s (%s) over %s at %s\n",
- (unsigned long long) serial_id,
- details->debit_account_uri,
- details->credit_account_uri,
- TALER_B2S (&details->wtid),
- TALER_amount2s (&details->amount),
- GNUNET_TIME_timestamp2s (details->execution_date));
- return GNUNET_OK;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -381,34 +357,28 @@ execute_debit_history (void)
* execution.
*
* @param cls closure
- * @param response_code HTTP status code
- * @param ec taler error code
- * @param row_id unique ID of the wire transfer in the bank's records
- * @param timestamp when did the transaction go into effect
+ * @param tr response details
*/
static void
confirmation_cb (void *cls,
- unsigned int response_code,
- enum TALER_ErrorCode ec,
- uint64_t row_id,
- struct GNUNET_TIME_Timestamp timestamp)
+ const struct TALER_BANK_TransferResponse *tr)
{
(void) cls;
eh = NULL;
- if (MHD_HTTP_OK != response_code)
+ if (MHD_HTTP_OK != tr->http_status)
{
fprintf (stderr,
"The wire transfer didn't execute correctly (%u/%d).\n",
- response_code,
- ec);
+ tr->http_status,
+ tr->ec);
GNUNET_SCHEDULER_shutdown ();
return;
}
fprintf (stdout,
"Wire transfer #%llu executed successfully at %s.\n",
- (unsigned long long) row_id,
- GNUNET_TIME_timestamp2s (timestamp));
+ (unsigned long long) tr->details.ok.row_id,
+ GNUNET_TIME_timestamp2s (tr->details.ok.timestamp));
global_ret = 0;
GNUNET_SCHEDULER_shutdown ();
}
@@ -488,39 +458,29 @@ execute_wire_transfer (void)
* Function called with the result of the operation.
*
* @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
- * 0 if the bank's reply is bogus (fails to follow the protocol)
- * @param ec detailed error code
- * @param serial_id unique ID of the wire transfer in the bank's records; UINT64_MAX on error
- * @param timestamp timestamp when the transaction got settled at the bank.
- * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
+ * @param air response details
*/
static void
res_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp timestamp,
- const json_t *json)
+ const struct TALER_BANK_AdminAddIncomingResponse *air)
{
(void) cls;
- (void) timestamp;
op = NULL;
- switch (ec)
+ switch (air->http_status)
{
- case TALER_EC_NONE:
+ case MHD_HTTP_OK:
global_ret = 0;
fprintf (stdout,
"%llu\n",
- (unsigned long long) serial_id);
+ (unsigned long long) air->details.ok.serial_id);
break;
default:
fprintf (stderr,
"Operation failed with status code %u/%u\n",
- (unsigned int) ec,
- http_status);
- if (NULL != json)
- json_dumpf (json,
+ (unsigned int) air->ec,
+ air->http_status);
+ if (NULL != air->response)
+ json_dumpf (air->response,
stderr,
JSON_INDENT (2));
break;
diff --git a/src/bank-lib/taler-fakebank-run.c b/src/bank-lib/taler-fakebank-run.c
index 4e3706071..c15145ecb 100644
--- a/src/bank-lib/taler-fakebank-run.c
+++ b/src/bank-lib/taler-fakebank-run.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016, 2017 Taler Systems SA
+ Copyright (C) 2016-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
@@ -52,6 +52,10 @@ static struct TALER_FAKEBANK_Handle *fb;
*/
static struct GNUNET_SCHEDULER_Task *keepalive;
+/**
+ * Amount to credit an account with on /register.
+ */
+static struct TALER_Amount signup_bonus;
/**
* Stop the process.
@@ -103,6 +107,8 @@ run (void *cls,
unsigned long long port = 8082;
unsigned long long ram = 1024 * 128; /* 128 k entries */
char *currency_string;
+ char *hostname;
+ char *exchange_url;
(void) cls;
(void) args;
@@ -125,6 +131,23 @@ run (void *cls,
port);
}
if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "bank",
+ "SUGGESTED_EXCHANGE",
+ &exchange_url))
+ {
+ /* no suggested exchange */
+ exchange_url = NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "bank",
+ "HOSTNAME",
+ &hostname))
+ {
+ hostname = GNUNET_strdup ("localhost");
+ }
+ if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
"bank",
"RAM_LIMIT",
@@ -142,17 +165,37 @@ run (void *cls,
go |= TALER_MHD_GO_FORCE_CONNECTION_CLOSE;
TALER_MHD_setup (go);
}
- fb = TALER_FAKEBANK_start2 ((uint16_t) port,
+ if (GNUNET_OK !=
+ TALER_amount_is_valid (&signup_bonus))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency_string,
+ &signup_bonus));
+ }
+ if (0 != strcmp (currency_string,
+ signup_bonus.currency))
+ {
+ fprintf (stderr,
+ "Signup bonus and main currency do not match\n");
+ ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ fb = TALER_FAKEBANK_start3 (hostname,
+ (uint16_t) port,
+ exchange_url,
currency_string,
ram,
- num_threads);
+ num_threads,
+ &signup_bonus);
+ GNUNET_free (hostname);
+ GNUNET_free (exchange_url);
+ GNUNET_free (currency_string);
if (NULL == fb)
{
GNUNET_break (0);
ret = EXIT_FAILURE;
return;
}
- GNUNET_free (currency_string);
keepalive = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&keepalive_task,
NULL);
@@ -183,6 +226,11 @@ main (int argc,
"NUM_THREADS",
"size of the thread pool",
&num_threads),
+ TALER_getopt_get_amount ('s',
+ "signup-bonus",
+ "AMOUNT",
+ "amount to credit newly registered account (created out of thin air)",
+ &signup_bonus),
GNUNET_GETOPT_OPTION_END
};
enum GNUNET_GenericReturnValue iret;
diff --git a/src/bank-lib/test_bank.sh b/src/bank-lib/test_bank.sh
index ab76d2bad..5ee2bd836 100755
--- a/src/bank-lib/test_bank.sh
+++ b/src/bank-lib/test_bank.sh
@@ -1,19 +1,20 @@
#!/bin/bash
-
+# This file is in the public domain.
+# shellcheck disable=SC2317
set -eu
# Exit, with status code "skip" (no 'real' failure)
function exit_skip() {
- echo $1
+ echo "$1"
exit 77
}
# Cleanup to run whenever we exit
function cleanup()
{
- for n in `jobs -p`
+ for n in $(jobs -p)
do
- kill $n 2> /dev/null || true
+ kill "$n" 2> /dev/null || true
done
wait
}
@@ -23,21 +24,30 @@ trap cleanup EXIT
echo -n "Launching bank..."
-taler-fakebank-run -c test_bank.conf -L DEBUG &> bank.log &
+taler-fakebank-run \
+ -c test_bank.conf \
+ -L DEBUG &> bank.log &
# Wait for bank to be available (usually the slowest)
-for n in `seq 1 50`
+for n in $(seq 1 50)
do
echo -n "."
sleep 0.2
OK=0
# bank
- wget --tries=1 --timeout=1 http://localhost:8899/ -o /dev/null -O /dev/null >/dev/null || continue
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ http://localhost:8899/ \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null \
+ || continue
OK=1
break
done
-if [ 1 != $OK ]
+if [ 1 != "$OK" ]
then
exit_skip "Failed to launch services (bank)"
fi
@@ -47,7 +57,7 @@ echo "OK"
echo -n "Making wire transfer to exchange ..."
taler-exchange-wire-gateway-client \
- -b http://localhost:8899/exchange/ \
+ -b http://localhost:8899/accounts/exchange/taler-wire-gateway/ \
-S 0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00 \
-D payto://x-taler-bank/localhost:8899/user?receiver-name=user \
-a TESTKUDOS:4 > /dev/null
@@ -55,14 +65,18 @@ echo " OK"
echo -n "Requesting exchange incoming transaction list ..."
-./taler-exchange-wire-gateway-client -b http://localhost:8899/exchange/ -i | grep TESTKUDOS:4 > /dev/null
+./taler-exchange-wire-gateway-client \
+ -b http://localhost:8899/accounts/exchange/taler-wire-gateway/ \
+ -i \
+ | grep TESTKUDOS:4 \
+ > /dev/null
echo " OK"
echo -n "Making wire transfer from exchange..."
./taler-exchange-wire-gateway-client \
- -b http://localhost:8899/exchange/ \
+ -b http://localhost:8899/accounts/exchange/taler-wire-gateway/ \
-S 0ZSX8SH0M30KHX8K3Y1DAMVGDQV82XEF9DG1HC4QMQ3QWYT4AF00 \
-C payto://x-taler-bank/localhost:8899/merchant?receiver-name=merchant \
-a TESTKUDOS:2 \
@@ -72,7 +86,11 @@ echo " OK"
echo -n "Requesting exchange's outgoing transaction list..."
-./taler-exchange-wire-gateway-client -b http://localhost:8899/exchange/ -o | grep TESTKUDOS:2 > /dev/null
+./taler-exchange-wire-gateway-client \
+ -b http://localhost:8899/accounts/exchange/taler-wire-gateway/ \
+ -o \
+ | grep TESTKUDOS:2 \
+ > /dev/null
echo " OK"
diff --git a/src/benchmark/.gitignore b/src/benchmark/.gitignore
index 45e150087..a1b4711e7 100644
--- a/src/benchmark/.gitignore
+++ b/src/benchmark/.gitignore
@@ -1,2 +1,3 @@
taler-bank-benchmark
taler-aggregator-benchmark
+*.edited
diff --git a/src/benchmark/Makefile.am b/src/benchmark/Makefile.am
index b62e88465..c82584626 100644
--- a/src/benchmark/Makefile.am
+++ b/src/benchmark/Makefile.am
@@ -15,6 +15,7 @@ bin_PROGRAMS = \
taler-bank-benchmark \
taler-exchange-benchmark
+
taler_aggregator_benchmark_SOURCES = \
taler-aggregator-benchmark.c
taler_aggregator_benchmark_LDADD = \
@@ -64,6 +65,10 @@ taler_exchange_benchmark_LDADD = \
$(XLIB)
EXTRA_DIST = \
+ benchmark-common.conf \
benchmark-cs.conf \
benchmark-rsa.conf \
- exchange_benchmark_home/.local/share/taler/exchange/offline-keys/master.priv
+ bank-benchmark-cs.conf \
+ bank-benchmark-rsa.conf \
+ coins-cs.conf \
+ coins-rsa.conf
diff --git a/src/benchmark/bank-benchmark-cs.conf b/src/benchmark/bank-benchmark-cs.conf
index d012f0faa..39c82a3fe 100644
--- a/src/benchmark/bank-benchmark-cs.conf
+++ b/src/benchmark/bank-benchmark-cs.conf
@@ -1,128 +1,5 @@
# This file is in the public domain.
-#
-[paths]
-# Persistent data storage for the testcase
-# This value is a default for `taler_config_home'
-taler_test_home = exchange_benchmark_home/
+@INLINE@ benchmark-common.conf
+@INLINE@ coins-cs.conf
-[taler]
-# Currency supported by the exchange (can only be one)
-currency = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-[exchange]
-# how long is one signkey valid?
-signkey_duration = 4 weeks
-signkey_legal_duration = 2 years
-# how long do we provide to clients denomination and signing keys
-# ahead of time?
-# Keep it short so the test runs fast.
-lookahead_sign = 12h
-# HTTP port the exchange listens to
-port = 8081
-# Master public key used to sign the exchange's various keys
-master_public_key = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-# How to access our database
-DB = postgres
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-base_url = "http://localhost:8081/"
-
-WIREWATCH_IDLE_SLEEP_INTERVAL = 1500 ms
-
-[exchange-offline]
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-[exchangedb-postgres]
-config = "postgres:///talercheck"
-
-[benchmark-remote-exchange]
-host = localhost
-# Adjust $HOME to match remote target!
-dir = $HOME/repos/taler/exchange/src/benchmark
-
-[bank]
-HTTP_PORT = 8082
-SERVE = http
-MAX_DEBT = EUR:100000000000.0
-MAX_DEBT_BANK = EUR:1000000000000000.0
-
-[benchmark]
-USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42
-
-[exchange-account-2]
-# What is the payto://-URL of the exchange (to generate wire response)
-PAYTO_URI = "payto://x-taler-bank/localhost:8082/Exchange"
-enable_debit = YES
-enable_credit = YES
-
-[exchange-accountcredentials-2]
-# What is the bank account (with the "Taler Bank" demo system)? Must end with "/".
-WIRE_GATEWAY_URL = http://localhost:8082/Exchange/
-# Authentication information for basic authentication
-WIRE_GATEWAY_AUTH_METHOD = "basic"
-username = Exchange
-password = x
-
-
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
diff --git a/src/benchmark/bank-benchmark-rsa.conf b/src/benchmark/bank-benchmark-rsa.conf
index f2f4dee50..ca5d6b0da 100644
--- a/src/benchmark/bank-benchmark-rsa.conf
+++ b/src/benchmark/bank-benchmark-rsa.conf
@@ -1,133 +1,5 @@
# This file is in the public domain.
-#
-[paths]
-# Persistent data storage for the testcase
-# This value is a default for `taler_config_home'
-taler_test_home = exchange_benchmark_home/
+@INLINE@ benchmark-common.conf
+@INLINE@ coins-rsa.conf
-[taler]
-# Currency supported by the exchange (can only be one)
-currency = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-[exchange]
-# how long is one signkey valid?
-signkey_duration = 4 weeks
-signkey_legal_duration = 2 years
-# how long do we provide to clients denomination and signing keys
-# ahead of time?
-# Keep it short so the test runs fast.
-lookahead_sign = 12h
-# HTTP port the exchange listens to
-port = 8081
-# Master public key used to sign the exchange's various keys
-master_public_key = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-# How to access our database
-DB = postgres
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-base_url = "http://localhost:8081/"
-
-WIREWATCH_IDLE_SLEEP_INTERVAL = 1500 ms
-
-[exchange-offline]
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-[exchangedb-postgres]
-config = "postgres:///talercheck"
-
-[benchmark-remote-exchange]
-host = localhost
-# Adjust $HOME to match remote target!
-dir = $HOME/repos/taler/exchange/src/benchmark
-
-[bank]
-HTTP_PORT = 8082
-SERVE = http
-MAX_DEBT = EUR:100000000000.0
-MAX_DEBT_BANK = EUR:1000000000000000.0
-
-[benchmark]
-USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42
-
-[exchange-account-2]
-# What is the payto://-URL of the exchange (to generate wire response)
-PAYTO_URI = "payto://x-taler-bank/localhost:8082/Exchange"
-enable_debit = YES
-enable_credit = YES
-
-[exchange-accountcredentials-2]
-# What is the bank account (with the "Taler Bank" demo system)? Must end with "/".
-WIRE_GATEWAY_URL = http://localhost:8082/Exchange/
-# Authentication information for basic authentication
-WIRE_GATEWAY_AUTH_METHOD = "basic"
-username = Exchange
-password = x
-
-
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
diff --git a/src/benchmark/benchmark-common.conf b/src/benchmark/benchmark-common.conf
new file mode 100644
index 000000000..e47115a2b
--- /dev/null
+++ b/src/benchmark/benchmark-common.conf
@@ -0,0 +1,106 @@
+# This file is in the public domain.
+[paths]
+TALER_TEST_HOME=exchange_benchmark_home/
+
+[taler]
+CURRENCY=EUR
+CURRENCY_ROUND_UNIT=EUR:0.01
+
+[exchange]
+AML_THRESHOLD=EUR:99999999
+SIGNKEY_LEGAL_DURATION=2 years
+PORT=8081
+MASTER_PUBLIC_KEY=98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+DB=postgres
+BASE_URL="http://localhost:8081/"
+# Only set this option if you are actually running
+# multiple aggregators!
+# AGGREGATOR_SHARD_SIZE=67108864
+WIREWATCH_IDLE_SLEEP_INTERVAL=5 ms
+
+[exchangedb-postgres]
+CONFIG="postgres:///talercheck"
+
+[exchange-offline]
+MASTER_PRIV_FILE=${TALER_TEST_HOME}/.local/share/taler/exchange/offline-keys/master.priv
+
+[taler-exchange-secmod-rsa]
+LOOKAHEAD_SIGN="1 d"
+
+[taler-exchange-secmod-cs]
+LOOKAHEAD_SIGN="1 d"
+
+[taler-exchange-secmod-eddsa]
+DURATION="2 d"
+LOOKAHEAD_SIGN="1 d"
+
+# account-2 is suitable for fakebank
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost/exchange?receiver-name=exchange"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8080/accounts/exchange/taler-wire-gateway/"
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8080/accounts/exchange/taler-wire-gateway/"
+
+# account-2 is suitable for libeufin
+[exchange-account-2]
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+PAYTO_URI = payto://iban/SANDBOXX/DE033310?receiver-name=Exchange+Company
+
+[exchange-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8080/accounts/exchange/taler-wire-gateway/"
+
+[admin-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = admin
+PASSWORD = secret
+WIRE_GATEWAY_URL = "http://localhost:8080/accounts/exchange/taler-wire-gateway/"
+
+
+# Trust local exchange for "EUR" currency
+[merchant-exchange-benchmark]
+EXCHANGE_BASE_URL = http://localhost:8081/
+MASTER_KEY=98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+# If currency does not match [TALER] section, the exchange
+# will be ignored!
+CURRENCY = EUR
+
+
+[merchantdb-postgres]
+CONFIG="postgres:///talercheck"
+
+[auditordb-postgres]
+CONFIG="postgres:///talercheck"
+
+[syncdb-postgres]
+CONFIG="postgres:///talercheck"
+
+[exchange]
+WIREWATCH_IDLE_SLEEP_INTERVAL = 5000 ms
+
+[bank]
+HTTP_PORT=8080
+SERVE=http
+RAM_LIMIT=10000000
+
+[libeufin-bank]
+CURRENCY = EUR
+
+[libeufin-nexus]
+DB_CONNECTION="postgresql:///talercheck"
+
+[libeufin-sandbox]
+DB_CONNECTION="postgresql:///talercheck"
+
+[auditor]
+BASE_URL="http://localhost:8083/"
diff --git a/src/benchmark/benchmark-cs.conf b/src/benchmark/benchmark-cs.conf
index d0d14b8d9..7f660ad31 100644
--- a/src/benchmark/benchmark-cs.conf
+++ b/src/benchmark/benchmark-cs.conf
@@ -1,58 +1,6 @@
# This file is in the public domain.
-#
-[paths]
-# Persistent data storage for the testcase
-# This value is a default for `taler_config_home'
-TALER_TEST_HOME = exchange_benchmark_home/
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[exchange]
-
-SIGNKEY_LEGAL_DURATION = 2 years
-
-# HTTP port the exchange listens to
-PORT = 8081
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-# How to access our database
-DB = postgres
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-AGGREGATOR_SHARD_SIZE = 67108864
-#AGGREGATOR_SHARD_SIZE = 2147483648
-
-
-
-WIREWATCH_IDLE_SLEEP_INTERVAL = 5 ms
-
-[exchange-offline]
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[benchmark-remote-exchange]
-HOST = localhost
-# Adjust $HOME to match remote target!
-DIR = $HOME/repos/taler/exchange/src/benchmark
-
-[bank]
-HTTP_PORT = 8082
-SERVE = http
-MAX_DEBT = EUR:100000000000.0
-MAX_DEBT_BANK = EUR:1000000000000000.0
-
-[benchmark]
-USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42
+@INLINE@ benchmark-common.conf
+@INLINE@ coins-cs.conf
[exchange-account-test]
# What is the bank account (with the "Taler Bank" demo system)? Must end with "/".
@@ -62,65 +10,7 @@ ENABLE_DEBIT = YES
ENABLE_CREDIT = YES
[exchange-accountcredentials-test]
-WIRE_GATEWAY_URL = http://localhost:8082/Exchange/
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/Exchange/taler-wire-gateway/
WIRE_GATEWAY_AUTH_METHOD = "basic"
USERNAME = Exchange
PASSWORD = x
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
diff --git a/src/benchmark/benchmark-rsa.conf b/src/benchmark/benchmark-rsa.conf
index 7b5b0d1f1..a6c1512ee 100644
--- a/src/benchmark/benchmark-rsa.conf
+++ b/src/benchmark/benchmark-rsa.conf
@@ -1,58 +1,6 @@
# This file is in the public domain.
-#
-[paths]
-# Persistent data storage for the testcase
-# This value is a default for `taler_config_home'
-TALER_TEST_HOME = exchange_benchmark_home/
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[exchange]
-
-SIGNKEY_LEGAL_DURATION = 2 years
-
-# HTTP port the exchange listens to
-PORT = 8081
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-# How to access our database
-DB = postgres
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-AGGREGATOR_SHARD_SIZE = 67108864
-#AGGREGATOR_SHARD_SIZE = 2147483648
-
-
-
-WIREWATCH_IDLE_SLEEP_INTERVAL = 5 ms
-
-[exchange-offline]
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange/offline-keys/master.priv
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[benchmark-remote-exchange]
-HOST = localhost
-# Adjust $HOME to match remote target!
-DIR = $HOME/repos/taler/exchange/src/benchmark
-
-[bank]
-HTTP_PORT = 8082
-SERVE = http
-MAX_DEBT = EUR:100000000000.0
-MAX_DEBT_BANK = EUR:1000000000000000.0
-
-[benchmark]
-USER_PAYTO_URI = payto://x-taler-bank/localhost:8082/42
+@INLINE@ benchmark-common.conf
+@INLINE@ coins-rsa.conf
[exchange-account-test]
# What is the bank account (with the "Taler Bank" demo system)? Must end with "/".
@@ -62,70 +10,7 @@ ENABLE_DEBIT = YES
ENABLE_CREDIT = YES
[exchange-accountcredentials-test]
-WIRE_GATEWAY_URL = http://localhost:8082/Exchange/
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/Exchange/taler-wire-gateway/
WIRE_GATEWAY_AUTH_METHOD = "basic"
USERNAME = Exchange
PASSWORD = x
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 2048
diff --git a/src/benchmark/coins-cs.conf b/src/benchmark/coins-cs.conf
new file mode 100644
index 000000000..c4b5a45c1
--- /dev/null
+++ b/src/benchmark/coins-cs.conf
@@ -0,0 +1,58 @@
+# This file is in the public domain.
+#
+# Sections starting with "coin_" specify which denominations
+# the exchange should support (and their respective fee structure)
+[coin_eur_ct_1]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_ct_10]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_1]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_5]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_10]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
diff --git a/src/benchmark/coins-rsa.conf b/src/benchmark/coins-rsa.conf
new file mode 100644
index 000000000..42eb8acfc
--- /dev/null
+++ b/src/benchmark/coins-rsa.conf
@@ -0,0 +1,63 @@
+# This file is in the public domain.
+#
+# Sections starting with "coin_" specify which denominations
+# the exchange should support (and their respective fee structure)
+[coin_eur_ct_1]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 2048
+
+[coin_eur_ct_10]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 2048
+
+[coin_eur_1]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 2048
+
+[coin_eur_5]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 2048
+
+[coin_eur_10]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 2048
diff --git a/src/benchmark/exchange_benchmark_home/.local/share/taler/exchange/offline-keys/master.priv b/src/benchmark/exchange_benchmark_home/.local/share/taler/exchange/offline-keys/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/benchmark/exchange_benchmark_home/.local/share/taler/exchange/offline-keys/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/benchmark/taler-aggregator-benchmark.c b/src/benchmark/taler-aggregator-benchmark.c
index 665077bed..228d050e4 100644
--- a/src/benchmark/taler-aggregator-benchmark.c
+++ b/src/benchmark/taler-aggregator-benchmark.c
@@ -251,7 +251,7 @@ add_refund (const struct Merchant *m,
r.details.rtransaction_id = 42;
make_amount (0, 5000000, &r.details.refund_amount);
make_amount (0, 5, &r.details.refund_fee);
- if (0 <=
+ if (0 >=
plugin->insert_refund (plugin->cls,
&r))
{
@@ -274,7 +274,11 @@ static bool
add_deposit (const struct Merchant *m)
{
struct Deposit d;
- struct TALER_EXCHANGEDB_Deposit deposit;
+ struct TALER_EXCHANGEDB_CoinDepositInformation deposit;
+ struct TALER_EXCHANGEDB_BatchDeposit bd = {
+ .cdis = &deposit,
+ .num_cdis = 1
+ };
uint64_t known_coin_id;
struct TALER_DenominationHashP dph;
struct TALER_AgeCommitmentHash agh;
@@ -283,6 +287,7 @@ add_deposit (const struct Merchant *m)
d.coin.denom_pub_hash = h_denom_pub;
d.coin.denom_sig = denom_sig;
RANDOMIZE (&d.h_contract_terms);
+ d.coin.no_age_commitment = true;
memset (&d.coin.h_age_commitment,
0,
sizeof (d.coin.h_age_commitment));
@@ -301,24 +306,40 @@ add_deposit (const struct Merchant *m)
}
deposit.coin = d.coin;
RANDOMIZE (&deposit.csig);
- deposit.merchant_pub = m->merchant_pub;
- deposit.h_contract_terms = d.h_contract_terms;
- deposit.wire_salt = m->wire_salt;
- deposit.receiver_wire_account = m->payto_uri;
- deposit.timestamp = random_time ();
- deposit.refund_deadline = random_time ();
- deposit.wire_deadline = random_time ();
+ bd.merchant_pub = m->merchant_pub;
+ bd.h_contract_terms = d.h_contract_terms;
+ bd.wire_salt = m->wire_salt;
+ bd.receiver_wire_account = m->payto_uri;
+ bd.wallet_timestamp = random_time ();
+ do {
+ bd.refund_deadline = random_time ();
+ bd.wire_deadline = random_time ();
+ } while (GNUNET_TIME_timestamp_cmp (bd.wire_deadline,
+ <,
+ bd.refund_deadline));
+
make_amount (1, 0, &deposit.amount_with_fee);
- make_amount (0, 5, &deposit.deposit_fee);
- if (0 >=
- plugin->insert_deposit (plugin->cls,
- random_time (),
- &deposit))
+
{
- GNUNET_break (0);
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return false;
+ struct GNUNET_TIME_Timestamp now;
+ bool balance_ok;
+ uint32_t bad_idx;
+ bool conflict;
+
+ now = random_time ();
+ if (0 >=
+ plugin->do_deposit (plugin->cls,
+ &bd,
+ &now,
+ &balance_ok,
+ &bad_idx,
+ &conflict))
+ {
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return false;
+ }
}
if (GNUNET_YES ==
eval_probability (((float) refund_rate) / 100.0))
@@ -445,6 +466,9 @@ run (void *cls,
}
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
+ memset (&issue,
+ 0,
+ sizeof (issue));
RANDOMIZE (&issue.signature);
issue.start
= start;
@@ -465,18 +489,19 @@ run (void *cls,
struct TALER_PlanchetDetail pd;
struct TALER_BlindedDenominationSignature bds;
struct TALER_PlanchetMasterSecretP ps;
- struct TALER_ExchangeWithdrawValues alg_values;
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_AgeCommitmentHash hac;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ const struct TALER_ExchangeWithdrawValues *alg_values;
RANDOMIZE (&coin_pub);
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&pk,
&denom_pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
- alg_values.cipher = TALER_DENOMINATION_RSA;
+ alg_values = TALER_denom_ewv_rsa_singleton ();
+ denom_pub.age_mask = issue.age_mask;
TALER_denom_pub_hash (&denom_pub,
&h_denom_pub);
make_amount (2, 0, &issue.value);
@@ -496,38 +521,35 @@ run (void *cls,
return;
}
-
TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
+ TALER_denom_ewv_rsa_singleton (),
&bks);
{
struct GNUNET_HashCode seed;
struct TALER_AgeMask mask = {
- .bits = 1 || 1 << 8 || 1 << 12 || 1 << 16 || 1 << 18
+ .bits = 1 | (1 << 8) | (1 << 12) | (1 << 16) | (1 << 18)
};
struct TALER_AgeCommitmentProof acp = {0};
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- GNUNET_assert (GNUNET_OK ==
- TALER_age_restriction_commit (
- &mask,
- 13,
- &seed,
- &acp));
-
- TALER_age_commitment_hash (&acp.commitment, &hac);
+ TALER_age_restriction_commit (&mask,
+ 13,
+ &seed,
+ &acp);
+ TALER_age_commitment_hash (&acp.commitment,
+ &hac);
}
GNUNET_assert (GNUNET_OK ==
TALER_denom_blind (&denom_pub,
&bks,
+ NULL,
&hac,
&coin_pub,
- &alg_values,
+ alg_values,
&c_hash,
&pd.blinded_planchet));
GNUNET_assert (GNUNET_OK ==
@@ -541,7 +563,7 @@ run (void *cls,
&bds,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&denom_pub));
TALER_blinded_denom_sig_free (&bds);
TALER_denom_pub_free (&denom_pub);
@@ -561,7 +583,6 @@ run (void *cls,
ws = GNUNET_TIME_absolute_to_timestamp (GNUNET_TIME_year_to_time (y - 1));
we = GNUNET_TIME_absolute_to_timestamp (GNUNET_TIME_year_to_time (y));
make_amount (0, 5, &fees.wire);
- make_amount (0, 5, &fees.wad);
make_amount (0, 5, &fees.closing);
memset (&master_sig,
0,
diff --git a/src/benchmark/taler-bank-benchmark.c b/src/benchmark/taler-bank-benchmark.c
index 75a7434d2..528798424 100644
--- a/src/benchmark/taler-bank-benchmark.c
+++ b/src/benchmark/taler-bank-benchmark.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2021 Taler Systems SA
+ (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as
@@ -38,55 +38,12 @@
#include "taler_testing_lib.h"
#include "taler_error_codes.h"
-
-/* Error codes. */
-enum BenchmarkError
-{
- MISSING_BANK_URL,
- FAILED_TO_LAUNCH_BANK,
- BAD_CLI_ARG,
- BAD_CONFIG_FILE,
- NO_CONFIG_FILE_GIVEN
-};
-
-
-/**
- * What mode should the benchmark run in?
- */
-enum BenchmarkMode
-{
- /**
- * Run as client against the bank.
- */
- MODE_CLIENT = 1,
-
- /**
- * Run the bank.
- */
- MODE_BANK = 2,
-
- /**
- * Run both, for a local benchmark.
- */
- MODE_BOTH = 3,
-};
-
+#define SHARD_SIZE "1024"
/**
- * Hold information regarding which bank has the exchange account.
+ * Credentials to use for the benchmark.
*/
-static const struct TALER_EXCHANGEDB_AccountInfo *exchange_bank_account;
-
-/**
- * Time snapshot taken right before executing the CMDs.
- */
-static struct GNUNET_TIME_Absolute start_time;
-
-/**
- * Benchmark duration time taken right after the CMD interpreter
- * returns.
- */
-static struct GNUNET_TIME_Relative duration;
+static struct TALER_TESTING_Credentials cred;
/**
* Array of all the commands the benchmark is running.
@@ -94,26 +51,14 @@ static struct GNUNET_TIME_Relative duration;
static struct TALER_TESTING_Command *all_commands;
/**
- * Dummy keepalive task.
- */
-static struct GNUNET_SCHEDULER_Task *keepalive;
-
-/**
* Name of our configuration file.
*/
static char *cfg_filename;
/**
* Use the fakebank instead of LibEuFin.
- * NOTE: LibEuFin not yet supported! Set
- * to 0 once we do support it!
*/
-static int use_fakebank = 1;
-
-/**
- * Number of taler-exchange-wirewatchers to launch.
- */
-static unsigned int start_wirewatch;
+static int use_fakebank;
/**
* Verbosity level.
@@ -121,12 +66,6 @@ static unsigned int start_wirewatch;
static unsigned int verbose;
/**
- * Size of the transaction history the fakebank
- * should keep in RAM.
- */
-static unsigned long long history_size = 65536;
-
-/**
* How many reserves we want to create per client.
*/
static unsigned int howmany_reserves = 1;
@@ -137,9 +76,9 @@ static unsigned int howmany_reserves = 1;
static unsigned int howmany_clients = 1;
/**
- * How many bank worker threads do we want to create.
+ * How many wirewatch processes do we want to create.
*/
-static unsigned int howmany_threads;
+static unsigned int start_wirewatch;
/**
* Log level used during the run.
@@ -152,25 +91,15 @@ static char *loglev;
static char *logfile;
/**
- * Benchmarking mode (run as client, exchange, both) as string.
- */
-static char *mode_str;
-
-/**
- * Benchmarking mode (run as client, bank, both).
- */
-static enum BenchmarkMode mode;
-
-/**
- * Don't kill exchange/fakebank/wirewatch until
- * requested by the user explicitly.
+ * Configuration.
*/
-static int linger;
+static struct GNUNET_CONFIGURATION_Handle *cfg;
/**
- * Configuration.
+ * Section with the configuration data for the exchange
+ * bank account.
*/
-static struct GNUNET_CONFIGURATION_Handle *cfg;
+static char *exchange_bank_section;
/**
* Currency used.
@@ -232,10 +161,10 @@ print_stats (void)
total = GNUNET_strdup (
GNUNET_STRINGS_relative_time_to_string (timings[i].total_duration,
- GNUNET_YES));
+ true));
latency = GNUNET_strdup (
GNUNET_STRINGS_relative_time_to_string (timings[i].success_latency,
- GNUNET_YES));
+ true));
fprintf (stderr,
"%s-%d took %s in total with %s for latency for %u executions (%u repeats)\n",
timings[i].prefix,
@@ -265,38 +194,39 @@ run (void *cls,
(void) cls;
len = howmany_reserves + 2;
- all_commands = GNUNET_malloc_large (len
+ all_commands = GNUNET_malloc_large ((1 + len)
* sizeof (struct TALER_TESTING_Command));
GNUNET_assert (NULL != all_commands);
+ all_commands[0]
+ = TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true);
+
GNUNET_asprintf (&total_reserve_amount,
"%s:5",
currency);
for (unsigned int j = 0; j < howmany_reserves; j++)
{
char *create_reserve_label;
- char *user_payto_uri;
-
- // FIXME: vary user accounts more...
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "benchmark",
- "USER_PAYTO_URI",
- &user_payto_uri));
+
GNUNET_asprintf (&create_reserve_label,
"createreserve-%u",
j);
- all_commands[j]
+ // TODO: vary user accounts more...
+ all_commands[1 + j]
= TALER_TESTING_cmd_admin_add_incoming_retry (
TALER_TESTING_cmd_admin_add_incoming (add_label (
create_reserve_label),
total_reserve_amount,
- exchange_bank_account->auth,
- add_label (user_payto_uri)));
+ &cred.ba_admin,
+ cred.user42_payto));
}
GNUNET_free (total_reserve_amount);
- all_commands[howmany_reserves]
+ all_commands[1 + howmany_reserves]
= TALER_TESTING_cmd_stat (timings);
- all_commands[howmany_reserves + 1]
+ all_commands[1 + howmany_reserves + 1]
= TALER_TESTING_cmd_end ();
TALER_TESTING_run2 (is,
all_commands,
@@ -313,15 +243,11 @@ launch_clients (void)
enum GNUNET_GenericReturnValue result = GNUNET_OK;
pid_t cpids[howmany_clients];
- start_time = GNUNET_TIME_absolute_get ();
if (1 == howmany_clients)
{
/* do everything in this process */
- result = TALER_TESTING_setup (&run,
- NULL,
- cfg,
- NULL,
- GNUNET_NO);
+ result = TALER_TESTING_loop (&run,
+ NULL);
if (verbose)
print_stats ();
return result;
@@ -335,11 +261,8 @@ launch_clients (void)
GNUNET_log_setup ("benchmark-worker",
NULL == loglev ? "INFO" : loglev,
logfile);
- result = TALER_TESTING_setup (&run,
- NULL,
- cfg,
- NULL,
- GNUNET_NO);
+ result = TALER_TESTING_loop (&run,
+ NULL);
if (verbose)
print_stats ();
if (GNUNET_OK != result)
@@ -389,78 +312,6 @@ again:
/**
- * Stop the fakebank.
- *
- * @param cls fakebank handle
- */
-static void
-stop_fakebank (void *cls)
-{
- struct TALER_FAKEBANK_Handle *fakebank = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Stopping fakebank\n");
- TALER_FAKEBANK_stop (fakebank);
- GNUNET_SCHEDULER_cancel (keepalive);
- keepalive = NULL;
-}
-
-
-/**
- * Dummy task that is never run.
- */
-static void
-never_task (void *cls)
-{
- (void) cls;
- GNUNET_assert (0);
-}
-
-
-/**
- * Start the fakebank.
- *
- * @param cls NULL
- */
-static void
-launch_fakebank (void *cls)
-{
- struct TALER_FAKEBANK_Handle *fakebank;
- unsigned long long pnum;
-
- (void) cls;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "bank",
- "HTTP_PORT",
- &pnum))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "bank",
- "HTTP_PORT",
- "must be valid port number");
- return;
- }
- fakebank
- = TALER_FAKEBANK_start2 ((uint16_t) pnum,
- currency,
- history_size,
- howmany_threads);
- if (NULL == fakebank)
- {
- GNUNET_break (0);
- return;
- }
- keepalive
- = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &never_task,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&stop_fakebank,
- fakebank);
-}
-
-
-/**
* Run the benchmark in parallel in many (client) processes
* and summarize result.
*
@@ -470,259 +321,100 @@ static enum GNUNET_GenericReturnValue
parallel_benchmark (void)
{
enum GNUNET_GenericReturnValue result = GNUNET_OK;
- pid_t fakebank = -1;
- struct GNUNET_OS_Process *bankd = NULL;
struct GNUNET_OS_Process *wirewatch[GNUNET_NZL (start_wirewatch)];
memset (wirewatch,
0,
sizeof (wirewatch));
- if ( (MODE_BANK == mode) ||
- (MODE_BOTH == mode) )
+ /* start exchange wirewatch */
+ for (unsigned int w = 0; w<start_wirewatch; w++)
{
- if (use_fakebank)
- {
- unsigned long long pnum;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "bank",
- "HTTP_PORT",
- &pnum))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "bank",
- "HTTP_PORT",
- "must be valid port number");
- return GNUNET_SYSERR;
- }
- /* start fakebank */
- fakebank = fork ();
- if (0 == fakebank)
- {
- GNUNET_log_setup ("benchmark-fakebank",
- NULL == loglev ? "INFO" : loglev,
- logfile);
- GNUNET_SCHEDULER_run (&launch_fakebank,
- NULL);
- exit (0);
- }
- if (-1 == fakebank)
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "fork");
- return GNUNET_SYSERR;
- }
- /* wait for fakebank to be ready */
- {
- char *bank_url;
- int ret;
-
- GNUNET_asprintf (&bank_url,
- "http://localhost:%u/",
- (unsigned int) (uint16_t) pnum);
- ret = TALER_TESTING_wait_httpd_ready (bank_url);
- GNUNET_free (bank_url);
- if (0 != ret)
- {
- int wstatus;
-
- kill (fakebank,
- SIGTERM);
- if (fakebank !=
- waitpid (fakebank,
- &wstatus,
- 0))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "waitpid");
- }
- fakebank = -1;
- exit (ret);
- }
- }
- }
- else
+ wirewatch[w] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-wirewatch",
+ "taler-exchange-wirewatch",
+ "-c", cfg_filename,
+ "-a", exchange_bank_section,
+ "-S", SHARD_SIZE,
+ (NULL != loglev) ? "-L" : NULL,
+ loglev,
+ NULL);
+ if (NULL == wirewatch[w])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "FIXME: launching LibEuFin not yet supported\n");
- bankd = NULL; // FIXME
- return GNUNET_SYSERR;
- }
-
- {
- struct GNUNET_OS_Process *dbinit;
-
- dbinit = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-dbinit",
- "taler-exchange-dbinit",
- "-c", cfg_filename,
- "-r",
- NULL);
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (dbinit));
- GNUNET_OS_process_destroy (dbinit);
- }
- /* start exchange wirewatch */
- for (unsigned int w = 0; w<start_wirewatch; w++)
- {
- wirewatch[w] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-wirewatch",
- "taler-exchange-wirewatch",
- "-c", cfg_filename,
- "-L", loglev,
- NULL);
- if (NULL == wirewatch[w])
+ "Failed to launch wirewatch, aborting benchmark\n");
+ for (unsigned int x = 0; x<w; x++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to launch wirewatch, aborting benchmark\n");
- for (unsigned int x = 0; x<w; x++)
- {
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (wirewatch[x],
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch[x]));
- GNUNET_OS_process_destroy (wirewatch[x]);
- wirewatch[x] = NULL;
- }
- if (-1 != fakebank)
- {
- int wstatus;
-
- kill (fakebank,
- SIGTERM);
- if (fakebank !=
- waitpid (fakebank,
- &wstatus,
- 0))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "waitpid");
- }
- fakebank = -1;
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- bankd = NULL;
- }
- return GNUNET_SYSERR;
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (wirewatch[x],
+ SIGTERM));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (wirewatch[x]));
+ GNUNET_OS_process_destroy (wirewatch[x]);
+ wirewatch[x] = NULL;
}
+ return GNUNET_SYSERR;
}
}
-
- if ( (MODE_CLIENT == mode) ||
- (MODE_BOTH == mode) )
- result = launch_clients ();
- if ( (GNUNET_YES == linger) ||
- (MODE_BANK == mode) )
+ result = launch_clients ();
+ /* Ensure wirewatch runs to completion! */
+ if (0 != start_wirewatch)
{
- printf ("Press ENTER to stop!\n");
- if (MODE_BANK != mode)
- duration = GNUNET_TIME_absolute_get_duration (start_time);
- (void) getchar ();
- if (MODE_BANK == mode)
- duration = GNUNET_TIME_absolute_get_duration (start_time);
- }
-
- if ( (MODE_BANK == mode) ||
- (MODE_BOTH == mode) )
- {
- /* Ensure wirewatch runs to completion! */
- if (0 != start_wirewatch)
+ /* replace ONE of the wirewatchers with one that is in test-mode */
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (wirewatch[0],
+ SIGTERM));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (wirewatch[0]));
+ GNUNET_OS_process_destroy (wirewatch[0]);
+ wirewatch[0] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-wirewatch",
+ "taler-exchange-wirewatch",
+ "-c", cfg_filename,
+ "-a", exchange_bank_section,
+ "-S", SHARD_SIZE,
+ "-t",
+ (NULL != loglev) ? "-L" : NULL,
+ loglev,
+ NULL);
+ /* wait for it to finish! */
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (wirewatch[0]));
+ GNUNET_OS_process_destroy (wirewatch[0]);
+ wirewatch[0] = NULL;
+ /* Then stop the rest, which should basically also be finished */
+ for (unsigned int w = 1; w<start_wirewatch; w++)
{
- /* replace ONE of the wirewatchers with one that is in test-mode */
GNUNET_break (0 ==
- GNUNET_OS_process_kill (wirewatch[0],
+ GNUNET_OS_process_kill (wirewatch[w],
SIGTERM));
GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch[0]));
- GNUNET_OS_process_destroy (wirewatch[0]);
- wirewatch[0] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-wirewatch",
- "taler-exchange-wirewatch",
- "-c", cfg_filename,
- "-L", loglev,
- "-t",
- NULL);
- /* wait for it to finish! */
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch[0]));
- GNUNET_OS_process_destroy (wirewatch[0]);
- wirewatch[0] = NULL;
- /* Then stop the rest, which should basically also be finished */
- for (unsigned int w = 1; w<start_wirewatch; w++)
- {
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (wirewatch[w],
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch[w]));
- GNUNET_OS_process_destroy (wirewatch[w]);
- }
-
- /* But be extra sure we did finish all shards by doing one more */
- wirewatch[0] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-wirewatch",
- "taler-exchange-wirewatch",
- "-c", cfg_filename,
- "-L", loglev,
- "-t",
- NULL);
- /* wait for it to finish! */
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch[0]));
- GNUNET_OS_process_destroy (wirewatch[0]);
- wirewatch[0] = NULL;
+ GNUNET_OS_process_wait (wirewatch[w]));
+ GNUNET_OS_process_destroy (wirewatch[w]);
}
- /* Now stop the time, if this was the right mode */
- if ( (GNUNET_YES != linger) &&
- (MODE_BANK != mode) )
- duration = GNUNET_TIME_absolute_get_duration (start_time);
-
- /* stop fakebank */
- if (-1 != fakebank)
- {
- int wstatus;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Telling fakebank to shut down\n");
- kill (fakebank,
- SIGTERM);
- if (fakebank !=
- waitpid (fakebank,
- &wstatus,
- 0))
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "waitpid");
- }
- else
- {
- if ( (! WIFEXITED (wstatus)) ||
- (0 != WEXITSTATUS (wstatus)) )
- {
- GNUNET_break (0);
- result = GNUNET_SYSERR;
- }
- }
- fakebank = -1;
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- }
+ /* But be extra sure we did finish all shards by doing one more */
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "Shard check phase\n");
+ wirewatch[0] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "taler-exchange-wirewatch",
+ "taler-exchange-wirewatch",
+ "-c", cfg_filename,
+ "-a", exchange_bank_section,
+ "-S", SHARD_SIZE,
+ "-t",
+ (NULL != loglev) ? "-L" : NULL,
+ loglev,
+ NULL);
+ /* wait for it to finish! */
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_OS_process_wait (wirewatch[0]));
+ GNUNET_OS_process_destroy (wirewatch[0]);
+ wirewatch[0] = NULL;
}
+
return result;
}
@@ -742,48 +434,34 @@ main (int argc,
struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_option_mandatory (
GNUNET_GETOPT_option_cfgfile (&cfg_filename)),
-#if FIXME_SUPPORT_LIBEUFIN
GNUNET_GETOPT_option_flag ('f',
"fakebank",
- "start a fakebank instead of the Python bank",
+ "we are using fakebank",
&use_fakebank),
-#endif
GNUNET_GETOPT_option_help ("taler-bank benchmark"),
- GNUNET_GETOPT_option_flag ('K',
- "linger",
- "linger around until key press",
- &linger),
GNUNET_GETOPT_option_string ('l',
"logfile",
"LF",
"will log to file LF",
&logfile),
GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_string ('m',
- "mode",
- "MODE",
- "run as bank, client or both",
- &mode_str),
GNUNET_GETOPT_option_uint ('p',
"worker-parallelism",
"NPROCS",
"How many client processes we should run",
&howmany_clients),
- GNUNET_GETOPT_option_uint ('P',
- "service-parallelism",
- "NTHREADS",
- "How many service threads we should create",
- &howmany_threads),
GNUNET_GETOPT_option_uint ('r',
"reserves",
"NRESERVES",
"How many reserves per client we should create",
&howmany_reserves),
- GNUNET_GETOPT_option_ulong ('s',
- "size",
- "HISTORY_SIZE",
- "Maximum history size kept in memory by the fakebank",
- &history_size),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_string (
+ 'u',
+ "exchange-account-section",
+ "SECTION",
+ "use exchange bank account configuration from the given SECTION",
+ &exchange_bank_section)),
GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
GNUNET_GETOPT_option_verbose (&verbose),
GNUNET_GETOPT_option_uint ('w',
@@ -793,6 +471,7 @@ main (int argc,
&start_wirewatch),
GNUNET_GETOPT_OPTION_END
};
+ struct GNUNET_TIME_Relative duration;
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
@@ -805,43 +484,15 @@ main (int argc,
GNUNET_free (cfg_filename);
if (GNUNET_NO == result)
return 0;
- return BAD_CLI_ARG;
+ return EXIT_INVALIDARGUMENT;
}
+ if (NULL == exchange_bank_section)
+ exchange_bank_section = "exchange-account-1";
+ if (NULL == loglev)
+ loglev = "INFO";
GNUNET_log_setup ("taler-bank-benchmark",
- NULL == loglev ? "INFO" : loglev,
+ loglev,
logfile);
- if (history_size < 10)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "History size too small, this can hardly work\n");
- return BAD_CLI_ARG;
- }
- if (NULL == mode_str)
- mode = MODE_BOTH;
- else if (0 == strcasecmp (mode_str,
- "bank"))
- mode = MODE_BANK;
- else if (0 == strcasecmp (mode_str,
- "client"))
- mode = MODE_CLIENT;
- else if (0 == strcasecmp (mode_str,
- "both"))
- mode = MODE_BOTH;
- else
- {
- TALER_LOG_ERROR ("Unknown mode given: '%s'\n",
- mode_str);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
- if (NULL == cfg_filename)
- cfg_filename = GNUNET_CONFIGURATION_default_filename ();
- if (NULL == cfg_filename)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Can't find default configuration file.\n");
- return EXIT_NOTCONFIGURED;
- }
cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK !=
GNUNET_CONFIGURATION_load (cfg,
@@ -849,7 +500,7 @@ main (int argc,
{
TALER_LOG_ERROR ("Could not parse configuration\n");
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_NOTCONFIGURED;
}
if (GNUNET_OK !=
TALER_config_get_currency (cfg,
@@ -857,52 +508,30 @@ main (int argc,
{
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
- if (MODE_BANK != mode)
- {
- if (howmany_clients > 10240)
- {
- TALER_LOG_ERROR ("-p option value given is too large\n");
- return BAD_CLI_ARG;
- }
- if (0 == howmany_clients)
- {
- TALER_LOG_ERROR ("-p option value must not be zero\n");
- GNUNET_free (cfg_filename);
- return BAD_CLI_ARG;
- }
+ return EXIT_NOTCONFIGURED;
}
if (GNUNET_OK !=
- TALER_EXCHANGEDB_load_accounts (cfg,
- TALER_EXCHANGEDB_ALO_AUTHDATA
- | TALER_EXCHANGEDB_ALO_CREDIT))
+ TALER_TESTING_get_credentials (
+ cfg_filename,
+ exchange_bank_section,
+ use_fakebank
+ ? TALER_TESTING_BS_FAKEBANK
+ : TALER_TESTING_BS_IBAN,
+ &cred))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Configuration fails to provide exchange bank details\n");
+ "Required bank credentials not given in configuration\n");
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_NOTCONFIGURED;
}
- exchange_bank_account
- = TALER_EXCHANGEDB_find_account_by_method ("x-taler-bank");
- if (NULL == exchange_bank_account)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No bank account for `x-taler-bank` given in configuration\n");
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
- result = parallel_benchmark ();
- TALER_EXCHANGEDB_unload_accounts ();
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
+ struct GNUNET_TIME_Absolute start_time;
- if (MODE_BANK == mode)
- {
- /* If we're the bank, we're done now. No need to print results. */
- return (GNUNET_OK == result) ? 0 : result;
+ start_time = GNUNET_TIME_absolute_get ();
+ result = parallel_benchmark ();
+ duration = GNUNET_TIME_absolute_get_duration (start_time);
}
if (GNUNET_OK == result)
@@ -930,7 +559,7 @@ main (int argc,
tps);
}
fprintf (stdout,
- "CPU time: sys %llu user %llu\n", \
+ "CPU time: sys %llu user %llu\n",
(unsigned long long) (usage.ru_stime.tv_sec * 1000 * 1000
+ usage.ru_stime.tv_usec),
(unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000
@@ -941,5 +570,7 @@ main (int argc,
GNUNET_array_grow (labels,
label_len,
0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (cfg_filename);
return (GNUNET_OK == result) ? 0 : result;
}
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index 77ef94ebc..75424a358 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2014-2020 Taler Systems SA
+ (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as
@@ -28,25 +28,7 @@
#include <microhttpd.h>
#include <sys/resource.h>
#include "taler_util.h"
-#include "taler_signatures.h"
-#include "taler_exchangedb_lib.h"
-#include "taler_exchange_service.h"
-#include "taler_json_lib.h"
-#include "taler_bank_service.h"
-#include "taler_fakebank_lib.h"
#include "taler_testing_lib.h"
-#include "taler_error_codes.h"
-
-/* Error codes. */
-enum BenchmarkError
-{
- MISSING_BANK_URL,
- FAILED_TO_LAUNCH_BANK,
- BAD_CLI_ARG,
- BAD_CONFIG_FILE,
- NO_CONFIG_FILE_GIVEN
-};
-
/**
* The whole benchmark is a repetition of a "unit". Each
@@ -55,56 +37,11 @@ enum BenchmarkError
*/
#define UNITY_SIZE 6
-#define FIRST_INSTRUCTION -1
-
-
-/**
- * What mode should the benchmark run in?
- */
-enum BenchmarkMode
-{
- /**
- * Run as client (with fakebank), also starts a remote exchange.
- */
- MODE_CLIENT = 1,
-
- /**
- * Run the the exchange.
- */
- MODE_EXCHANGE = 2,
-
- /**
- * Run both, for a local benchmark.
- */
- MODE_BOTH = 3,
-};
-
-
-/**
- * Hold information regarding which bank has the exchange account.
- */
-static const struct TALER_EXCHANGEDB_AccountInfo *exchange_bank_account;
-
-/**
- * Configuration of our exchange.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Hold information about a user at the bank.
- */
-static char *user_payto_uri;
-
-/**
- * Time snapshot taken right before executing the CMDs.
- */
-static struct GNUNET_TIME_Absolute start_time;
/**
- * Benchmark duration time taken right after the CMD interpreter
- * returns.
+ * Credentials to use for the benchmark.
*/
-static struct GNUNET_TIME_Relative duration;
+static struct TALER_TESTING_Credentials cred;
/**
* Array of all the commands the benchmark is running.
@@ -117,16 +54,6 @@ static struct TALER_TESTING_Command *all_commands;
static char *cfg_filename;
/**
- * Exit code.
- */
-static enum GNUNET_GenericReturnValue result;
-
-/**
- * Use the fakebank instead of the Python bank.
- */
-static int use_fakebank;
-
-/**
* How many coins we want to create per client and reserve.
*/
static unsigned int howmany_coins = 1;
@@ -147,11 +74,6 @@ static unsigned int refresh_rate = 10;
static unsigned int howmany_clients = 1;
/**
- * Bank configuration to use.
- */
-static struct TALER_TESTING_BankConfiguration bc;
-
-/**
* Log level used during the run.
*/
static char *loglev;
@@ -162,16 +84,6 @@ static char *loglev;
static char *logfile;
/**
- * Benchmarking mode (run as client, exchange, both) as string.
- */
-static char *mode_str;
-
-/**
- * Benchmarking mode (run as client, exchange, both).
- */
-static enum BenchmarkMode mode;
-
-/**
* Configuration.
*/
static struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -182,19 +94,20 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
static int reserves_first;
/**
- * Currency used.
+ * Are we running against 'fakebank'?
*/
-static char *currency;
+static int use_fakebank;
/**
- * Remote host that runs the exchange.
+ * Section with the configuration data for the exchange
+ * bank account.
*/
-static char *remote_host;
+static char *exchange_bank_section;
/**
- * Remote benchmarking directory.
+ * Currency used.
*/
-static char *remote_dir;
+static char *currency;
/**
* Array of command labels.
@@ -212,12 +125,6 @@ static unsigned int label_len;
static unsigned int label_off;
/**
- * Don't kill exchange/fakebank/wirewatch until
- * requested by the user explicitly.
- */
-static int linger;
-
-/**
* Performance counters.
*/
static struct TALER_TESTING_Timer timings[] = {
@@ -256,14 +163,15 @@ cmd_transfer_to_exchange (const char *label,
return TALER_TESTING_cmd_admin_add_incoming_retry (
TALER_TESTING_cmd_admin_add_incoming (label,
amount,
- exchange_bank_account->auth,
- user_payto_uri));
+ &cred.ba_admin,
+ cred.user42_payto));
}
/**
* Throw a weighted coin with @a probability.
*
+ * @param probability weight of the coin flip
* @return #GNUNET_OK with @a probability,
* #GNUNET_NO with 1 - @a probability
*/
@@ -298,16 +206,26 @@ run (void *cls,
char *amount_1;
(void) cls;
- all_commands = GNUNET_new_array (howmany_reserves * (1 /* Withdraw block */
- + howmany_coins) /* All units */
- + 1 /* stat CMD */
- + 1 /* End CMD */,
- struct TALER_TESTING_Command);
+ all_commands = GNUNET_malloc_large (
+ (1 /* exchange CMD */
+ + howmany_reserves
+ * (1 /* Withdraw block */
+ + howmany_coins) /* All units */
+ + 1 /* stat CMD */
+ + 1 /* End CMD */) * sizeof (struct TALER_TESTING_Command));
+ GNUNET_assert (NULL != all_commands);
+ all_commands[0]
+ = TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true);
GNUNET_asprintf (&amount_5, "%s:5", currency);
GNUNET_asprintf (&amount_4, "%s:4", currency);
GNUNET_asprintf (&amount_1, "%s:1", currency);
- GNUNET_assert (GNUNET_OK == TALER_amount_set_zero (currency,
- &total_reserve_amount));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ &total_reserve_amount));
total_reserve_amount.value = 5 * howmany_coins;
GNUNET_asprintf (&withdraw_fee_str,
"%s:0.1",
@@ -338,9 +256,9 @@ run (void *cls,
GNUNET_asprintf (&batch_label,
"batch-start-%u",
j);
- all_commands[reserves_first
- ? j
- : j * (howmany_coins + 1)]
+ all_commands[1 + (reserves_first
+ ? j
+ : j * (howmany_coins + 1))]
= TALER_TESTING_cmd_batch (add_label (batch_label),
make_reserve);
}
@@ -359,25 +277,25 @@ run (void *cls,
wl = add_label (withdraw_label);
GNUNET_asprintf (&order_enc,
"{\"nonce\": %llu}",
- ((unsigned long long) i) + (howmany_coins
- * (unsigned long long) j));
+ ((unsigned long long) i)
+ + (howmany_coins * (unsigned long long) j));
unit[0] =
- TALER_TESTING_cmd_withdraw_with_retry
- (TALER_TESTING_cmd_withdraw_amount (wl,
- create_reserve_label,
- amount_5,
- 0, /* age restriction off */
- MHD_HTTP_OK));
+ TALER_TESTING_cmd_withdraw_with_retry (
+ TALER_TESTING_cmd_withdraw_amount (wl,
+ create_reserve_label,
+ amount_5,
+ 0, /* age restriction off */
+ MHD_HTTP_OK));
unit[1] =
- TALER_TESTING_cmd_deposit_with_retry
- (TALER_TESTING_cmd_deposit ("deposit",
- wl,
- 0, /* Index of the one withdrawn coin in the traits. */
- user_payto_uri,
- add_label (order_enc),
- GNUNET_TIME_UNIT_ZERO,
- amount_1,
- MHD_HTTP_OK));
+ TALER_TESTING_cmd_deposit_with_retry (
+ TALER_TESTING_cmd_deposit ("deposit",
+ wl,
+ 0, /* Index of the one withdrawn coin in the traits. */
+ cred.user43_payto,
+ add_label (order_enc),
+ GNUNET_TIME_UNIT_ZERO,
+ amount_1,
+ MHD_HTTP_OK));
if (eval_probability (refresh_rate / 100.0))
{
char *melt_label;
@@ -396,21 +314,21 @@ run (void *cls,
j);
rl = add_label (reveal_label);
unit[2] =
- TALER_TESTING_cmd_melt_with_retry
- (TALER_TESTING_cmd_melt (ml,
- wl,
- MHD_HTTP_OK,
- NULL));
+ TALER_TESTING_cmd_melt_with_retry (
+ TALER_TESTING_cmd_melt (ml,
+ wl,
+ MHD_HTTP_OK,
+ NULL));
unit[3] =
- TALER_TESTING_cmd_refresh_reveal_with_retry
- (TALER_TESTING_cmd_refresh_reveal (rl,
- ml,
- MHD_HTTP_OK));
+ TALER_TESTING_cmd_refresh_reveal_with_retry (
+ TALER_TESTING_cmd_refresh_reveal (rl,
+ ml,
+ MHD_HTTP_OK));
unit[4] =
- TALER_TESTING_cmd_refresh_link_with_retry
- (TALER_TESTING_cmd_refresh_link ("link",
- rl,
- MHD_HTTP_OK));
+ TALER_TESTING_cmd_refresh_link_with_retry (
+ TALER_TESTING_cmd_refresh_link ("link",
+ rl,
+ MHD_HTTP_OK));
unit[5] = TALER_TESTING_cmd_end ();
}
else
@@ -420,16 +338,16 @@ run (void *cls,
"unit-%u-%u",
i,
j);
- all_commands[reserves_first
- ? howmany_reserves + j * howmany_coins + i
- : j * (howmany_coins + 1) + (1 + i)]
+ all_commands[1 + (reserves_first
+ ? howmany_reserves + j * howmany_coins + i
+ : j * (howmany_coins + 1) + (1 + i))]
= TALER_TESTING_cmd_batch (add_label (unit_label),
unit);
}
}
- all_commands[howmany_reserves * (1 + howmany_coins)]
+ all_commands[1 + howmany_reserves * (1 + howmany_coins)]
= TALER_TESTING_cmd_stat (timings);
- all_commands[howmany_reserves * (1 + howmany_coins) + 1]
+ all_commands[1 + howmany_reserves * (1 + howmany_coins) + 1]
= TALER_TESTING_cmd_end ();
TALER_TESTING_run2 (is,
all_commands,
@@ -438,7 +356,6 @@ run (void *cls,
GNUNET_free (amount_4);
GNUNET_free (amount_5);
GNUNET_free (withdraw_fee_str);
- result = GNUNET_OK;
}
@@ -455,10 +372,10 @@ print_stats (void)
total = GNUNET_strdup (
GNUNET_STRINGS_relative_time_to_string (timings[i].total_duration,
- GNUNET_YES));
+ true));
latency = GNUNET_strdup (
GNUNET_STRINGS_relative_time_to_string (timings[i].success_latency,
- GNUNET_YES));
+ true));
fprintf (stderr,
"%s-%d took %s in total with %s for latency for %u executions (%u repeats)\n",
timings[i].prefix,
@@ -474,45 +391,6 @@ print_stats (void)
/**
- * Stop the fakebank.
- *
- * @param cls fakebank handle
- */
-static void
-stop_fakebank (void *cls)
-{
- struct TALER_FAKEBANK_Handle *fakebank = cls;
-
- TALER_FAKEBANK_stop (fakebank);
-}
-
-
-/**
- * Start the fakebank.
- *
- * @param cls NULL
- */
-static void
-launch_fakebank (void *cls)
-{
- struct TALER_FAKEBANK_Handle *fakebank;
-
- (void) cls;
- fakebank
- = TALER_TESTING_run_fakebank (
- exchange_bank_account->auth->wire_gateway_url,
- currency);
- if (NULL == fakebank)
- {
- GNUNET_break (0);
- return;
- }
- GNUNET_SCHEDULER_add_shutdown (&stop_fakebank,
- fakebank);
-}
-
-
-/**
* Run the benchmark in parallel in many (client) processes
* and summarize result.
*
@@ -521,363 +399,58 @@ launch_fakebank (void *cls)
* @param config_file configuration file to use
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
parallel_benchmark (TALER_TESTING_Main main_cb,
void *main_cb_cls,
const char *config_file)
{
enum GNUNET_GenericReturnValue result = GNUNET_OK;
pid_t cpids[howmany_clients];
- pid_t fakebank = -1;
- int wstatus;
- struct GNUNET_OS_Process *bankd = NULL;
- struct GNUNET_OS_Process *auditord = NULL;
- struct GNUNET_OS_Process *exchanged = NULL;
- struct GNUNET_OS_Process *wirewatch = NULL;
- struct GNUNET_OS_Process *exchange_slave = NULL;
- struct GNUNET_DISK_PipeHandle *exchange_slave_pipe;
- if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) )
+ if (1 == howmany_clients)
+ {
+ result = TALER_TESTING_loop (main_cb,
+ main_cb_cls);
+ print_stats ();
+ }
+ else
{
- if (use_fakebank)
+ for (unsigned int i = 0; i<howmany_clients; i++)
{
- /* start fakebank */
- fakebank = fork ();
- if (0 == fakebank)
+ if (0 == (cpids[i] = fork ()))
{
- GNUNET_log_setup ("benchmark-fakebank",
- NULL == loglev ? "INFO" : loglev,
+ /* I am the child, do the work! */
+ GNUNET_log_setup ("benchmark-worker",
+ loglev,
logfile);
- GNUNET_SCHEDULER_run (&launch_fakebank,
- NULL);
- exit (0);
+ result = TALER_TESTING_loop (main_cb,
+ main_cb_cls);
+ print_stats ();
+ if (GNUNET_OK != result)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failure in child process %u test suite!\n",
+ i);
+ if (GNUNET_OK == result)
+ exit (0);
+ else
+ exit (1);
}
- if (-1 == fakebank)
+ if (-1 == cpids[i])
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
"fork");
- return GNUNET_SYSERR;
- }
- }
- else
- {
- /* start bank */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_bank (cfg_filename,
- GNUNET_NO,
- "exchange-account-2",
- &bc))
- {
- return 1;
- }
- bankd = TALER_TESTING_run_bank (cfg_filename,
- "http://localhost:8082/");
- if (NULL == bankd)
- return 77;
- }
- }
-
- if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) )
- {
- /* start exchange */
- exchanged = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-httpd",
- "taler-exchange-httpd",
- "-c", config_file,
- "-C",
- NULL);
- if ( (NULL == exchanged) && (MODE_BOTH == mode) )
- {
- if (-1 != fakebank)
- {
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
- &wstatus,
- 0);
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- }
- return 77;
- }
- /* start auditor */
- auditord = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-auditor-httpd",
- "taler-auditor-httpd",
- "-c", config_file,
- NULL);
- if (NULL == auditord)
- {
- GNUNET_OS_process_kill (exchanged,
- SIGTERM);
- if (MODE_BOTH == mode)
- {
- if (-1 != fakebank)
- {
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
- &wstatus,
- 0);
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- }
- }
- GNUNET_OS_process_destroy (exchanged);
- return 77;
- }
- /* start exchange wirewatch */
- wirewatch = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-wirewatch",
- "taler-exchange-wirewatch",
- "-c", config_file,
- NULL);
- if (NULL == wirewatch)
- {
- GNUNET_OS_process_kill (auditord,
- SIGTERM);
- GNUNET_OS_process_kill (exchanged,
- SIGTERM);
- if (MODE_BOTH == mode)
- {
- if (-1 != fakebank)
- {
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
- &wstatus,
- 0);
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- }
- }
- GNUNET_OS_process_destroy (exchanged);
- return 77;
- }
- }
-
- if (MODE_CLIENT == mode)
- {
- char *remote_cmd;
-
- GNUNET_asprintf (&remote_cmd,
- ("cd '%s'; "
- "taler-exchange-benchmark --mode=exchange -c '%s'"),
- remote_dir,
- config_file);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "remote command: %s\n",
- remote_cmd);
-
- GNUNET_assert (NULL != (exchange_slave_pipe =
- GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_RW)));
-
- exchange_slave = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
- exchange_slave_pipe, NULL, NULL,
- "ssh",
- "ssh",
- /* Don't ask for pw/passphrase, rather fail */
- "-oBatchMode=yes",
- remote_host,
- remote_cmd,
- NULL);
- GNUNET_free (remote_cmd);
- }
-
- /* We always wait for the exchange, no matter if it's running locally or
- remotely */
- if (0 != TALER_TESTING_wait_exchange_ready (ec.exchange_url))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to detect running exchange at `%s'\n",
- ec.exchange_url);
- GNUNET_OS_process_kill (exchanged,
- SIGTERM);
- if ( (MODE_BOTH == mode) || (MODE_CLIENT == mode))
- {
- if (-1 != fakebank)
- {
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
- &wstatus,
- 0);
- }
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
+ howmany_clients = i;
+ result = GNUNET_SYSERR;
+ break;
}
+ /* fork() success, continue starting more processes! */
}
- GNUNET_OS_process_wait (exchanged);
- GNUNET_OS_process_destroy (exchanged);
- if (NULL != wirewatch)
- {
- GNUNET_OS_process_kill (wirewatch,
- SIGTERM);
- GNUNET_OS_process_wait (wirewatch);
- GNUNET_OS_process_destroy (wirewatch);
- }
- if (NULL != auditord)
+ /* collect all children */
+ for (unsigned int i = 0; i<howmany_clients; i++)
{
- GNUNET_OS_process_kill (auditord,
- SIGTERM);
- GNUNET_OS_process_wait (auditord);
- GNUNET_OS_process_destroy (auditord);
- }
- return 77;
- }
- if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) )
- {
- if (-1 != fakebank)
- sleep (1); /* make sure fakebank process is ready before continuing */
-
- start_time = GNUNET_TIME_absolute_get ();
- result = GNUNET_OK;
-
- if (1 == howmany_clients)
- {
- result = TALER_TESTING_setup (main_cb,
- main_cb_cls,
- cfg,
- exchanged,
- GNUNET_YES);
- print_stats ();
- }
- else
- {
- for (unsigned int i = 0; i<howmany_clients; i++)
- {
- if (0 == (cpids[i] = fork ()))
- {
- /* I am the child, do the work! */
- GNUNET_log_setup ("benchmark-worker",
- NULL == loglev ? "INFO" : loglev,
- logfile);
-
- result = TALER_TESTING_setup (main_cb,
- main_cb_cls,
- cfg,
- exchanged,
- GNUNET_YES);
- print_stats ();
- if (GNUNET_OK != result)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failure in child process test suite!\n");
- if (GNUNET_OK == result)
- exit (0);
- else
- exit (1);
- }
- if (-1 == cpids[i])
- {
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
- "fork");
- howmany_clients = i;
- result = GNUNET_SYSERR;
- break;
- }
- /* fork() success, continue starting more processes! */
- }
- /* collect all children */
- for (unsigned int i = 0; i<howmany_clients; i++)
- {
- waitpid (cpids[i],
- &wstatus,
- 0);
- if ( (! WIFEXITED (wstatus)) ||
- (0 != WEXITSTATUS (wstatus)) )
- {
- GNUNET_break (0);
- result = GNUNET_SYSERR;
- }
- }
- }
- }
-
- /* Wait for our master to die or to tell us to die */
- if (MODE_EXCHANGE == mode)
- (void) getchar ();
-
- if ( (GNUNET_YES == linger) &&
- ( ((mode == MODE_BOTH) ||
- (mode == MODE_CLIENT) ) ) )
- {
- printf ("press ENTER to stop\n");
- (void) getchar ();
- }
-
- if (MODE_CLIENT == mode)
- {
- char c = 'q';
-
- GNUNET_assert (NULL != exchange_slave);
-
- /* Write a character to the pipe to end the exchange slave.
- * We can't send a signal here, as it would just kill SSH and
- * not necessarily the process on the other machine. */
- GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (exchange_slave_pipe, GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c));
+ int wstatus;
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (exchange_slave));
- GNUNET_OS_process_destroy (exchange_slave);
- }
-
- if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) )
- {
- GNUNET_assert (NULL != wirewatch);
- GNUNET_assert (NULL != exchanged);
- GNUNET_assert (NULL != auditord);
- /* stop wirewatch */
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (wirewatch,
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (wirewatch));
- GNUNET_OS_process_destroy (wirewatch);
- /* stop auditor */
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (auditord,
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (auditord));
- GNUNET_OS_process_destroy (auditord);
- /* stop exchange */
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (exchanged,
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (exchanged));
- GNUNET_OS_process_destroy (exchanged);
- }
-
- if ( (MODE_CLIENT == mode) || (MODE_BOTH == mode) )
- {
- /* stop fakebank */
- if (-1 != fakebank)
- {
- kill (fakebank,
- SIGTERM);
- waitpid (fakebank,
+ waitpid (cpids[i],
&wstatus,
0);
if ( (! WIFEXITED (wstatus)) ||
@@ -887,12 +460,6 @@ parallel_benchmark (TALER_TESTING_Main main_cb,
result = GNUNET_SYSERR;
}
}
- if (NULL != bankd)
- {
- GNUNET_OS_process_kill (bankd,
- SIGTERM);
- GNUNET_OS_process_destroy (bankd);
- }
}
return result;
}
@@ -910,55 +477,65 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_mandatory
- (GNUNET_GETOPT_option_cfgfile (&cfg_filename)),
- GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION),
- GNUNET_GETOPT_option_help ("Exchange benchmark"),
- GNUNET_GETOPT_option_loglevel (&loglev),
- GNUNET_GETOPT_option_uint ('n',
- "coins-number",
- "CN",
- "How many coins we should instantiate per reserve",
- &howmany_coins),
- GNUNET_GETOPT_option_uint ('p',
- "parallelism",
- "NPROCS",
- "How many client processes we should run",
- &howmany_clients),
- GNUNET_GETOPT_option_uint ('r',
- "reserves",
- "NRESERVES",
- "How many reserves per client we should create",
- &howmany_reserves),
- GNUNET_GETOPT_option_uint ('R',
- "refresh-rate",
- "RATE",
- "Probability of refresh per coin (0-100)",
- &refresh_rate),
- GNUNET_GETOPT_option_string ('m',
- "mode",
- "MODE",
- "run as exchange, clients or both",
- &mode_str),
- GNUNET_GETOPT_option_string ('l',
- "logfile",
- "LF",
- "will log to file LF",
- &logfile),
- GNUNET_GETOPT_option_flag ('f',
- "fakebank",
- "start a fakebank instead of the Python bank",
- &use_fakebank),
- GNUNET_GETOPT_option_flag ('F',
- "reserves-first",
- "should all reserves be created first, before starting normal operations",
- &reserves_first),
- GNUNET_GETOPT_option_flag ('K',
- "linger",
- "linger around until key press",
- &linger),
+ GNUNET_GETOPT_option_mandatory (
+ GNUNET_GETOPT_option_cfgfile (
+ &cfg_filename)),
+ GNUNET_GETOPT_option_version (
+ PACKAGE_VERSION " " VCS_VERSION),
+ GNUNET_GETOPT_option_flag (
+ 'f',
+ "fakebank",
+ "use fakebank for the banking system",
+ &use_fakebank),
+ GNUNET_GETOPT_option_flag (
+ 'F',
+ "reserves-first",
+ "should all reserves be created first, before starting normal operations",
+ &reserves_first),
+ GNUNET_GETOPT_option_help (
+ "Exchange benchmark"),
+ GNUNET_GETOPT_option_string (
+ 'l',
+ "logfile",
+ "LF",
+ "will log to file LF",
+ &logfile),
+ GNUNET_GETOPT_option_loglevel (
+ &loglev),
+ GNUNET_GETOPT_option_uint (
+ 'n',
+ "coins-number",
+ "CN",
+ "How many coins we should instantiate per reserve",
+ &howmany_coins),
+ GNUNET_GETOPT_option_uint (
+ 'p',
+ "parallelism",
+ "NPROCS",
+ "How many client processes we should run",
+ &howmany_clients),
+ GNUNET_GETOPT_option_uint (
+ 'r',
+ "reserves",
+ "NRESERVES",
+ "How many reserves per client we should create",
+ &howmany_reserves),
+ GNUNET_GETOPT_option_uint (
+ 'R',
+ "refresh-rate",
+ "RATE",
+ "Probability of refresh per coin (0-100)",
+ &refresh_rate),
+ GNUNET_GETOPT_option_string (
+ 'u',
+ "exchange-account-section",
+ "SECTION",
+ "use exchange bank account configuration from the given SECTION",
+ &exchange_bank_section),
GNUNET_GETOPT_OPTION_END
};
+ enum GNUNET_GenericReturnValue result;
+ struct GNUNET_TIME_Relative duration;
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
@@ -971,25 +548,15 @@ main (int argc,
GNUNET_free (cfg_filename);
if (GNUNET_NO == result)
return 0;
- return BAD_CLI_ARG;
+ return EXIT_INVALIDARGUMENT;
}
+ if (NULL == exchange_bank_section)
+ exchange_bank_section = "exchange-account-1";
+ if (NULL == loglev)
+ loglev = "INFO";
GNUNET_log_setup ("taler-exchange-benchmark",
- NULL == loglev ? "INFO" : loglev,
+ loglev,
logfile);
- if (NULL == mode_str)
- mode = MODE_BOTH;
- else if (0 == strcmp (mode_str, "exchange"))
- mode = MODE_EXCHANGE;
- else if (0 == strcmp (mode_str, "client"))
- mode = MODE_CLIENT;
- else if (0 == strcmp (mode_str, "both"))
- mode = MODE_BOTH;
- else
- {
- TALER_LOG_ERROR ("Unknown mode given: '%s'\n", mode_str);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
if (NULL == cfg_filename)
cfg_filename = GNUNET_CONFIGURATION_default_filename ();
if (NULL == cfg_filename)
@@ -1005,7 +572,7 @@ main (int argc,
{
TALER_LOG_ERROR ("Could not parse configuration\n");
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_NOTCONFIGURED;
}
if (GNUNET_OK !=
TALER_config_get_currency (cfg,
@@ -1013,177 +580,91 @@ main (int argc,
{
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_NOTCONFIGURED;
}
if (howmany_clients > 10240)
{
TALER_LOG_ERROR ("-p option value given is too large\n");
- return BAD_CLI_ARG;
+ return EXIT_INVALIDARGUMENT;
}
if (0 == howmany_clients)
{
TALER_LOG_ERROR ("-p option value must not be zero\n");
GNUNET_free (cfg_filename);
- return BAD_CLI_ARG;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "benchmark",
- "USER_PAYTO_URI",
- &user_payto_uri))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "benchmark",
- "USER_PAYTO_URI");
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_INVALIDARGUMENT;
}
if (GNUNET_OK !=
- TALER_EXCHANGEDB_load_accounts (cfg,
- TALER_EXCHANGEDB_ALO_AUTHDATA
- | TALER_EXCHANGEDB_ALO_CREDIT))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Configuration fails to provide exchange bank details\n");
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
-
- exchange_bank_account
- = TALER_EXCHANGEDB_find_account_by_method ("x-taler-bank");
- if (NULL == exchange_bank_account)
+ TALER_TESTING_get_credentials (
+ cfg_filename,
+ exchange_bank_section,
+ use_fakebank
+ ? TALER_TESTING_BS_FAKEBANK
+ : TALER_TESTING_BS_IBAN,
+ &cred))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No bank account for `x-taler-bank` given in configuration\n");
+ "Required bank credentials not given in configuration\n");
GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
+ return EXIT_NOTCONFIGURED;
}
- if ( (MODE_EXCHANGE == mode) || (MODE_BOTH == mode) )
- {
- struct GNUNET_OS_Process *compute_wire_response;
- compute_wire_response
- = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-wire",
- "taler-exchange-wire",
- "-c", cfg_filename,
- NULL);
- if (NULL == compute_wire_response)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `taler-exchange-wire`, is your PATH correct?\n");
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
- GNUNET_OS_process_wait (compute_wire_response);
- GNUNET_OS_process_destroy (compute_wire_response);
- /* If we use the fakebank, we MUST reset the database as the fakebank
- will have forgotten everything... */
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_prepare_exchange (cfg_filename,
- (GNUNET_YES == use_fakebank)
- ? GNUNET_YES
- : GNUNET_NO,
- &ec));
- }
- else
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange",
- "BASE_URL",
- &ec.exchange_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "base_url");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "benchmark-remote-exchange",
- "host",
- &remote_host))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "benchmark-remote-exchange",
- "host");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
+ struct GNUNET_TIME_Absolute start_time;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "benchmark-remote-exchange",
- "dir",
- &remote_dir))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "benchmark-remote-exchange",
- "dir");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
+ start_time = GNUNET_TIME_absolute_get ();
+ result = parallel_benchmark (&run,
+ NULL,
+ cfg_filename);
+ duration = GNUNET_TIME_absolute_get_duration (start_time);
}
- result = parallel_benchmark (&run,
- NULL,
- cfg_filename);
- TALER_EXCHANGEDB_unload_accounts ();
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
-
- /* If we're the exchange worker, we're done now. No need to print results */
- if (MODE_EXCHANGE == mode)
- {
- return (GNUNET_OK == result) ? 0 : result;
- }
- duration = GNUNET_TIME_absolute_get_duration (start_time);
if (GNUNET_OK == result)
{
struct rusage usage;
- GNUNET_assert (0 == getrusage (RUSAGE_CHILDREN, &usage));
+
+ GNUNET_assert (0 == getrusage (RUSAGE_CHILDREN,
+ &usage));
fprintf (stdout,
- "Executed (Withdraw=%u, Deposit=%u, Refresh~=%5.2f) * Reserve=%u * Parallel=%u, operations in %s\n",
+ "Executed (Withdraw=%u, Deposit=%u, Refresh~=%5.2f)"
+ " * Reserve=%u * Parallel=%u, operations in %s\n",
howmany_coins,
howmany_coins,
(float) howmany_coins * (refresh_rate / 100.0),
howmany_reserves,
howmany_clients,
- GNUNET_STRINGS_relative_time_to_string
- (duration,
- GNUNET_NO));
+ GNUNET_STRINGS_relative_time_to_string (
+ duration,
+ false));
fprintf (stdout,
"(approximately %s/coin)\n",
- GNUNET_STRINGS_relative_time_to_string
- (GNUNET_TIME_relative_divide (duration,
- (unsigned long long) howmany_coins
- * howmany_reserves
- * howmany_clients),
- GNUNET_YES));
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_relative_divide (
+ duration,
+ (unsigned long long) howmany_coins
+ * howmany_reserves
+ * howmany_clients),
+ true));
fprintf (stdout,
"RAW: %04u %04u %04u %16llu\n",
howmany_coins,
howmany_reserves,
howmany_clients,
(unsigned long long) duration.rel_value_us);
- fprintf (stdout, "cpu time: sys %llu user %llu\n", \
+ fprintf (stdout,
+ "cpu time: sys %llu user %llu\n",
(unsigned long long) (usage.ru_stime.tv_sec * 1000 * 1000
+ usage.ru_stime.tv_usec),
(unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000
+ usage.ru_utime.tv_usec));
}
+
for (unsigned int i = 0; i<label_off; i++)
GNUNET_free (labels[i]);
GNUNET_array_grow (labels,
label_len,
0);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (cfg_filename);
return (GNUNET_OK == result) ? 0 : result;
}
diff --git a/src/curl/Makefile.am b/src/curl/Makefile.am
index f60a3806d..c8f8761aa 100644
--- a/src/curl/Makefile.am
+++ b/src/curl/Makefile.am
@@ -17,7 +17,7 @@ libtalercurl_la_SOURCES = \
libtalercurl_la_LIBADD = \
-lgnunetcurl \
-lgnunetutil \
- $(LIBGNURLCURL_LIBS) \
+ -lcurl \
-ljansson \
-lz \
-lm \
diff --git a/src/curl/curl.c b/src/curl/curl.c
index 5009fa3cf..483c9b671 100644
--- a/src/curl/curl.c
+++ b/src/curl/curl.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2019-2021 Taler Systems SA
+ Copyright (C) 2019-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
@@ -30,6 +30,58 @@
#endif
+void
+TALER_curl_set_secure_redirect_policy (CURL *eh,
+ const char *url)
+{
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_FOLLOWLOCATION,
+ 1L));
+ GNUNET_assert ( (0 == strncasecmp (url,
+ "https://",
+ strlen ("https://"))) ||
+ (0 == strncasecmp (url,
+ "http://",
+ strlen ("http://"))) );
+#ifdef CURLOPT_REDIR_PROTOCOLS_STR
+ if (0 == strncasecmp (url,
+ "https://",
+ strlen ("https://")))
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_REDIR_PROTOCOLS_STR,
+ "https"));
+ else
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_REDIR_PROTOCOLS_STR,
+ "http,https"));
+#else
+#ifdef CURLOPT_REDIR_PROTOCOLS
+ if (0 == strncasecmp (url,
+ "https://",
+ strlen ("https://")))
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_REDIR_PROTOCOLS,
+ CURLPROTO_HTTPS));
+ else
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_REDIR_PROTOCOLS,
+ CURLPROTO_HTTP | CURLPROTO_HTTPS));
+#endif
+#endif
+ /* limit MAXREDIRS to 5 as a simple security measure against
+ a potential infinite loop caused by a malicious target */
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 5L));
+}
+
+
enum GNUNET_GenericReturnValue
TALER_curl_easy_post (struct TALER_CURL_PostContext *ctx,
CURL *eh,
@@ -46,7 +98,8 @@ TALER_curl_easy_post (struct TALER_CURL_PostContext *ctx,
return GNUNET_SYSERR;
}
slen = strlen (str);
-#if TALER_CURL_COMPRESS_BODIES
+ if (TALER_CURL_COMPRESS_BODIES &&
+ (! ctx->disable_compression) )
{
Bytef *cbuf;
uLongf cbuf_size;
@@ -68,18 +121,21 @@ TALER_curl_easy_post (struct TALER_CURL_PostContext *ctx,
free (str);
slen = (size_t) cbuf_size;
ctx->json_enc = (char *) cbuf;
+ GNUNET_assert (
+ NULL !=
+ (ctx->headers = curl_slist_append (
+ ctx->headers,
+ "Content-Encoding: deflate")));
}
- GNUNET_assert (NULL != (ctx->headers = curl_slist_append (
- ctx->headers,
- "Content-Encoding: deflate")));
-#else
- ctx->json_enc = str;
-#endif
-
- GNUNET_assert
- (NULL != (ctx->headers = curl_slist_append (
- ctx->headers,
- "Content-Type: application/json")));
+ else
+ {
+ ctx->json_enc = str;
+ }
+ GNUNET_assert (
+ NULL !=
+ (ctx->headers = curl_slist_append (
+ ctx->headers,
+ "Content-Type: application/json")));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
diff --git a/src/exchange-tools/Makefile.am b/src/exchange-tools/Makefile.am
index 8e7790081..955544564 100644
--- a/src/exchange-tools/Makefile.am
+++ b/src/exchange-tools/Makefile.am
@@ -15,8 +15,7 @@ endif
bin_PROGRAMS = \
taler-auditor-offline \
taler-exchange-offline \
- taler-exchange-dbinit \
- taler-crypto-worker
+ taler-exchange-dbinit
taler_exchange_offline_SOURCES = \
taler-exchange-offline.c
@@ -60,19 +59,6 @@ taler_exchange_dbinit_CPPFLAGS = \
-I$(top_srcdir)/src/pq/ \
$(POSTGRESQL_CPPFLAGS)
-taler_crypto_worker_SOURCES = \
- taler-crypto-worker.c
-taler_crypto_worker_LDADD = \
- $(top_builddir)/src/util/libtalerutil.la \
- $(top_builddir)/src/json/libtalerjson.la \
- -lgnunetutil \
- -lgnunetjson \
- -ljansson \
- $(LIBGCRYPT_LIBS) \
- $(XLIB)
-
-
-
# Testcases
diff --git a/src/exchange-tools/exchange-offline.conf b/src/exchange-tools/exchange-offline.conf
index cfd5c98ef..020eb34ba 100644
--- a/src/exchange-tools/exchange-offline.conf
+++ b/src/exchange-tools/exchange-offline.conf
@@ -3,10 +3,10 @@
[exchange-offline]
# Where do we store the offline master private key of the exchange?
-MASTER_PRIV_FILE = ${TALER_DATA_HOME}/exchange-offline/master.priv
+MASTER_PRIV_FILE = ${TALER_DATA_HOME}exchange-offline/master.priv
# Where do we store the TOFU key material?
-SECM_TOFU_FILE = ${TALER_DATA_HOME}/exchange-offline/secm_tofus.pub
+SECM_TOFU_FILE = ${TALER_DATA_HOME}exchange-offline/secm_tofus.pub
# Base32-encoded public key of the RSA helper.
# SECM_DENOM_PUBKEY =
diff --git a/src/exchange-tools/taler-auditor-offline.c b/src/exchange-tools/taler-auditor-offline.c
index 53135d9fa..8c280d46b 100644
--- a/src/exchange-tools/taler-auditor-offline.c
+++ b/src/exchange-tools/taler-auditor-offline.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020-2021 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -174,7 +174,7 @@ static struct DenominationAddRequest *dar_tail;
/**
* Handle to the exchange, used to request /keys.
*/
-static struct TALER_EXCHANGE_Handle *exchange;
+static struct TALER_EXCHANGE_GetKeysHandle *exchange;
/**
@@ -219,7 +219,7 @@ do_shutdown (void *cls)
}
if (NULL != exchange)
{
- TALER_EXCHANGE_disconnect (exchange);
+ TALER_EXCHANGE_get_keys_cancel (exchange);
exchange = NULL;
}
if (NULL != nxt)
@@ -388,14 +388,15 @@ load_offline_key (int do_create)
* add operation result.
*
* @param cls closure with a `struct DenominationAddRequest`
- * @param hr HTTP response data
+ * @param adr response data
*/
static void
denomination_add_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr)
{
struct DenominationAddRequest *dar = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -644,30 +645,24 @@ do_upload (char *const *args)
* a particular exchange and what keys the exchange is using.
*
* @param cls closure with the `char **` remaining args
- * @param hr HTTP response data
- * @param keys information about the various keys used
- * by the exchange, NULL if /keys failed
- * @param compat protocol compatibility information
+ * @param kr response data
+ * @param keys key data from the exchange
*/
static void
keys_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat)
+ const struct TALER_EXCHANGE_KeysResponse *kr,
+ struct TALER_EXCHANGE_Keys *keys)
{
char *const *args = cls;
- (void) keys;
- (void) compat;
- switch (hr->http_status)
+ exchange = NULL;
+ switch (kr->hr.http_status)
{
case MHD_HTTP_OK:
- if (! json_is_object (hr->reply))
+ if (NULL == kr->hr.reply)
{
GNUNET_break (0);
- TALER_EXCHANGE_disconnect (exchange);
- exchange = NULL;
test_shutdown ();
global_ret = EXIT_FAILURE;
return;
@@ -676,11 +671,9 @@ keys_cb (
default:
fprintf (stderr,
"Failed to download keys: %s (HTTP status: %u/%u)\n",
- hr->hint,
- hr->http_status,
- (unsigned int) hr->ec);
- TALER_EXCHANGE_disconnect (exchange);
- exchange = NULL;
+ kr->hr.hint,
+ kr->hr.http_status,
+ (unsigned int) kr->hr.ec);
test_shutdown ();
global_ret = EXIT_FAILURE;
return;
@@ -689,7 +682,7 @@ keys_cb (
GNUNET_JSON_pack_string ("operation",
OP_INPUT_KEYS),
GNUNET_JSON_pack_object_incref ("arguments",
- (json_t *) hr->reply));
+ (json_t *) kr->hr.reply));
if (NULL == args[0])
{
json_dumpf (in,
@@ -698,9 +691,8 @@ keys_cb (
json_decref (in);
in = NULL;
}
- TALER_EXCHANGE_disconnect (exchange);
- exchange = NULL;
next (args);
+ TALER_EXCHANGE_keys_decref (keys);
}
@@ -727,11 +719,11 @@ do_download (char *const *args)
global_ret = EXIT_NOTCONFIGURED;
return;
}
- exchange = TALER_EXCHANGE_connect (ctx,
- exchange_url,
- &keys_cb,
- (void *) args,
- TALER_EXCHANGE_OPTION_END);
+ exchange = TALER_EXCHANGE_get_keys (ctx,
+ exchange_url,
+ NULL,
+ &keys_cb,
+ (void *) args);
GNUNET_free (exchange_url);
}
@@ -742,46 +734,27 @@ do_download (char *const *args)
* @param denomkeys keys to output
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
show_denomkeys (const json_t *denomkeys)
{
size_t index;
json_t *value;
json_array_foreach (denomkeys, index, value) {
+ struct TALER_DenominationGroup group;
+ const json_t *denoms;
const char *err_name;
unsigned int err_line;
- struct TALER_DenominationPublicKey denom_pub;
- struct GNUNET_TIME_Timestamp stamp_start;
- struct GNUNET_TIME_Timestamp stamp_expire_withdraw;
- struct GNUNET_TIME_Timestamp stamp_expire_deposit;
- struct GNUNET_TIME_Timestamp stamp_expire_legal;
- struct TALER_Amount coin_value;
- struct TALER_DenomFeeSet fees;
- struct TALER_MasterSignatureP master_sig;
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_denom_pub ("denom_pub",
- &denom_pub),
- TALER_JSON_spec_amount ("value",
- currency,
- &coin_value),
- TALER_JSON_SPEC_DENOM_FEES ("fee",
- currency,
- &fees),
- GNUNET_JSON_spec_timestamp ("stamp_start",
- &stamp_start),
- GNUNET_JSON_spec_timestamp ("stamp_expire_withdraw",
- &stamp_expire_withdraw),
- GNUNET_JSON_spec_timestamp ("stamp_expire_deposit",
- &stamp_expire_deposit),
- GNUNET_JSON_spec_timestamp ("stamp_expire_legal",
- &stamp_expire_legal),
- GNUNET_JSON_spec_fixed_auto ("master_sig",
- &master_sig),
+ TALER_JSON_spec_denomination_group (NULL,
+ currency,
+ &group),
+ GNUNET_JSON_spec_array_const ("denoms",
+ &denoms),
GNUNET_JSON_spec_end ()
};
- struct GNUNET_TIME_Relative duration;
- struct TALER_DenominationHashP h_denom_pub;
+ size_t index2;
+ json_t *value2;
if (GNUNET_OK !=
GNUNET_JSON_parse (value,
@@ -799,70 +772,116 @@ show_denomkeys (const json_t *denomkeys)
test_shutdown ();
return GNUNET_SYSERR;
}
- duration = GNUNET_TIME_absolute_get_difference (
- stamp_start.abs_time,
- stamp_expire_withdraw.abs_time);
- TALER_denom_pub_hash (&denom_pub,
- &h_denom_pub);
- if (GNUNET_OK !=
- TALER_exchange_offline_denom_validity_verify (
- &h_denom_pub,
- stamp_start,
- stamp_expire_withdraw,
- stamp_expire_deposit,
- stamp_expire_legal,
- &coin_value,
- &fees,
- &master_pub,
- &master_sig))
- {
- fprintf (stderr,
- "Invalid master signature for key %s (aborting)\n",
- TALER_B2S (&h_denom_pub));
- global_ret = EXIT_FAILURE;
- test_shutdown ();
- return GNUNET_SYSERR;
- }
+ json_array_foreach (denoms, index2, value2) {
+ struct GNUNET_TIME_Timestamp stamp_start;
+ struct GNUNET_TIME_Timestamp stamp_expire_withdraw;
+ struct GNUNET_TIME_Timestamp stamp_expire_deposit;
+ struct GNUNET_TIME_Timestamp stamp_expire_legal;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_JSON_Specification ispec[] = {
+ TALER_JSON_spec_denom_pub_cipher (NULL,
+ group.cipher,
+ &denom_pub),
+ GNUNET_JSON_spec_timestamp ("stamp_start",
+ &stamp_start),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_withdraw",
+ &stamp_expire_withdraw),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_deposit",
+ &stamp_expire_deposit),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_legal",
+ &stamp_expire_legal),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ struct GNUNET_TIME_Relative duration;
+ struct TALER_DenominationHashP h_denom_pub;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value2,
+ ispec,
+ &err_name,
+ &err_line))
+ {
+ fprintf (stderr,
+ "Invalid input for denomination key to 'show': %s#%u at %u/%u (skipping)\n",
+ err_name,
+ err_line,
+ (unsigned int) index,
+ (unsigned int) index2);
+ GNUNET_JSON_parse_free (spec);
+ global_ret = EXIT_FAILURE;
+ test_shutdown ();
+ return GNUNET_SYSERR;
+ }
+ duration = GNUNET_TIME_absolute_get_difference (
+ stamp_start.abs_time,
+ stamp_expire_withdraw.abs_time);
+ TALER_denom_pub_hash (&denom_pub,
+ &h_denom_pub);
+ if (GNUNET_OK !=
+ TALER_exchange_offline_denom_validity_verify (
+ &h_denom_pub,
+ stamp_start,
+ stamp_expire_withdraw,
+ stamp_expire_deposit,
+ stamp_expire_legal,
+ &group.value,
+ &group.fees,
+ &master_pub,
+ &master_sig))
+ {
+ fprintf (stderr,
+ "Invalid master signature for key %s (aborting)\n",
+ TALER_B2S (&h_denom_pub));
+ global_ret = EXIT_FAILURE;
+ GNUNET_JSON_parse_free (ispec);
+ GNUNET_JSON_parse_free (spec);
+ test_shutdown ();
+ return GNUNET_SYSERR;
+ }
- {
- char *withdraw_fee_s;
- char *deposit_fee_s;
- char *refresh_fee_s;
- char *refund_fee_s;
- char *deposit_s;
- char *legal_s;
-
- withdraw_fee_s = TALER_amount_to_string (&fees.withdraw);
- deposit_fee_s = TALER_amount_to_string (&fees.deposit);
- refresh_fee_s = TALER_amount_to_string (&fees.refresh);
- refund_fee_s = TALER_amount_to_string (&fees.refund);
- deposit_s = GNUNET_strdup (
- GNUNET_TIME_timestamp2s (stamp_expire_deposit));
- legal_s = GNUNET_strdup (
- GNUNET_TIME_timestamp2s (stamp_expire_legal));
-
- printf (
- "DENOMINATION-KEY %s of value %s starting at %s "
- "(used for: %s, deposit until: %s legal end: %s) with fees %s/%s/%s/%s\n",
- TALER_B2S (&h_denom_pub),
- TALER_amount2s (&coin_value),
- GNUNET_TIME_timestamp2s (stamp_start),
- GNUNET_TIME_relative2s (duration,
- false),
- deposit_s,
- legal_s,
- withdraw_fee_s,
- deposit_fee_s,
- refresh_fee_s,
- refund_fee_s);
- GNUNET_free (withdraw_fee_s);
- GNUNET_free (deposit_fee_s);
- GNUNET_free (refresh_fee_s);
- GNUNET_free (refund_fee_s);
- GNUNET_free (deposit_s);
- GNUNET_free (legal_s);
+ {
+ char *withdraw_fee_s;
+ char *deposit_fee_s;
+ char *refresh_fee_s;
+ char *refund_fee_s;
+ char *deposit_s;
+ char *legal_s;
+
+ withdraw_fee_s = TALER_amount_to_string (&group.fees.withdraw);
+ deposit_fee_s = TALER_amount_to_string (&group.fees.deposit);
+ refresh_fee_s = TALER_amount_to_string (&group.fees.refresh);
+ refund_fee_s = TALER_amount_to_string (&group.fees.refund);
+ deposit_s = GNUNET_strdup (
+ GNUNET_TIME_timestamp2s (stamp_expire_deposit));
+ legal_s = GNUNET_strdup (
+ GNUNET_TIME_timestamp2s (stamp_expire_legal));
+
+ printf (
+ "DENOMINATION-KEY %s of value %s starting at %s "
+ "(used for: %s, deposit until: %s legal end: %s) with fees %s/%s/%s/%s\n",
+ TALER_B2S (&h_denom_pub),
+ TALER_amount2s (&group.value),
+ GNUNET_TIME_timestamp2s (stamp_start),
+ GNUNET_TIME_relative2s (duration,
+ false),
+ deposit_s,
+ legal_s,
+ withdraw_fee_s,
+ deposit_fee_s,
+ refresh_fee_s,
+ refund_fee_s);
+ GNUNET_free (withdraw_fee_s);
+ GNUNET_free (deposit_fee_s);
+ GNUNET_free (refresh_fee_s);
+ GNUNET_free (refund_fee_s);
+ GNUNET_free (deposit_s);
+ GNUNET_free (legal_s);
+ }
+ GNUNET_JSON_parse_free (ispec);
}
-
GNUNET_JSON_parse_free (spec);
}
return GNUNET_OK;
@@ -956,11 +975,11 @@ do_show (char *const *args)
json_t *keys;
const char *err_name;
unsigned int err_line;
- json_t *denomkeys;
+ const json_t *denomkeys;
struct TALER_MasterPublicKeyP mpub;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("denoms",
- &denomkeys),
+ GNUNET_JSON_spec_array_const ("denominations",
+ &denomkeys),
GNUNET_JSON_spec_fixed_auto ("master_public_key",
&mpub),
GNUNET_JSON_spec_end ()
@@ -1004,11 +1023,9 @@ do_show (char *const *args)
{
global_ret = EXIT_FAILURE;
test_shutdown ();
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
return;
}
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
/* do NOT consume input if next argument is '-' */
if ( (NULL != args[0]) &&
@@ -1028,45 +1045,27 @@ do_show (char *const *args)
* @param denomkeys keys to output
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
sign_denomkeys (const json_t *denomkeys)
{
- size_t index;
+ size_t group_idx;
json_t *value;
- json_array_foreach (denomkeys, index, value) {
+ json_array_foreach (denomkeys, group_idx, value) {
+ struct TALER_DenominationGroup group = { 0 };
+ const json_t *denom_keys_array;
const char *err_name;
unsigned int err_line;
- struct TALER_DenominationPublicKey denom_pub;
- struct GNUNET_TIME_Timestamp stamp_start;
- struct GNUNET_TIME_Timestamp stamp_expire_withdraw;
- struct GNUNET_TIME_Timestamp stamp_expire_deposit;
- struct GNUNET_TIME_Timestamp stamp_expire_legal;
- struct TALER_Amount coin_value;
- struct TALER_DenomFeeSet fees;
- struct TALER_MasterSignatureP master_sig;
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_denom_pub ("denom_pub",
- &denom_pub),
- TALER_JSON_spec_amount ("value",
- currency,
- &coin_value),
- TALER_JSON_SPEC_DENOM_FEES ("fee",
- currency,
- &fees),
- GNUNET_JSON_spec_timestamp ("stamp_start",
- &stamp_start),
- GNUNET_JSON_spec_timestamp ("stamp_expire_withdraw",
- &stamp_expire_withdraw),
- GNUNET_JSON_spec_timestamp ("stamp_expire_deposit",
- &stamp_expire_deposit),
- GNUNET_JSON_spec_timestamp ("stamp_expire_legal",
- &stamp_expire_legal),
- GNUNET_JSON_spec_fixed_auto ("master_sig",
- &master_sig),
+ TALER_JSON_spec_denomination_group (NULL,
+ currency,
+ &group),
+ GNUNET_JSON_spec_array_const ("denoms",
+ &denom_keys_array),
GNUNET_JSON_spec_end ()
};
- struct TALER_DenominationHashP h_denom_pub;
+ size_t index;
+ json_t *denom_key_obj;
if (GNUNET_OK !=
GNUNET_JSON_parse (value,
@@ -1078,54 +1077,100 @@ sign_denomkeys (const json_t *denomkeys)
"Invalid input for denomination key to 'sign': %s#%u at %u (skipping)\n",
err_name,
err_line,
- (unsigned int) index);
+ (unsigned int) group_idx);
GNUNET_JSON_parse_free (spec);
global_ret = EXIT_FAILURE;
test_shutdown ();
return GNUNET_SYSERR;
}
- TALER_denom_pub_hash (&denom_pub,
- &h_denom_pub);
- if (GNUNET_OK !=
- TALER_exchange_offline_denom_validity_verify (
- &h_denom_pub,
- stamp_start,
- stamp_expire_withdraw,
- stamp_expire_deposit,
- stamp_expire_legal,
- &coin_value,
- &fees,
- &master_pub,
- &master_sig))
- {
- fprintf (stderr,
- "Invalid master signature for key %s (aborting)\n",
- TALER_B2S (&h_denom_pub));
- global_ret = EXIT_FAILURE;
- test_shutdown ();
- return GNUNET_SYSERR;
- }
+ json_array_foreach (denom_keys_array, index, denom_key_obj) {
+ struct GNUNET_TIME_Timestamp stamp_start;
+ struct GNUNET_TIME_Timestamp stamp_expire_withdraw;
+ struct GNUNET_TIME_Timestamp stamp_expire_deposit;
+ struct GNUNET_TIME_Timestamp stamp_expire_legal;
+ struct TALER_DenominationPublicKey denom_pub = {
+ .age_mask = group.age_mask
+ };
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_JSON_Specification ispec[] = {
+ TALER_JSON_spec_denom_pub_cipher (NULL,
+ group.cipher,
+ &denom_pub),
+ GNUNET_JSON_spec_timestamp ("stamp_start",
+ &stamp_start),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_withdraw",
+ &stamp_expire_withdraw),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_deposit",
+ &stamp_expire_deposit),
+ GNUNET_JSON_spec_timestamp ("stamp_expire_legal",
+ &stamp_expire_legal),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ struct TALER_DenominationHashP h_denom_pub;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (denom_key_obj,
+ ispec,
+ &err_name,
+ &err_line))
+ {
+ fprintf (stderr,
+ "Invalid input for denomination key to 'show': %s#%u at %u/%u (skipping)\n",
+ err_name,
+ err_line,
+ (unsigned int) group_idx,
+ (unsigned int) index);
+ GNUNET_JSON_parse_free (spec);
+ global_ret = EXIT_FAILURE;
+ test_shutdown ();
+ return GNUNET_SYSERR;
+ }
+ TALER_denom_pub_hash (&denom_pub,
+ &h_denom_pub);
+ if (GNUNET_OK !=
+ TALER_exchange_offline_denom_validity_verify (
+ &h_denom_pub,
+ stamp_start,
+ stamp_expire_withdraw,
+ stamp_expire_deposit,
+ stamp_expire_legal,
+ &group.value,
+ &group.fees,
+ &master_pub,
+ &master_sig))
+ {
+ fprintf (stderr,
+ "Invalid master signature for key %s (aborting)\n",
+ TALER_B2S (&h_denom_pub));
+ global_ret = EXIT_FAILURE;
+ test_shutdown ();
+ return GNUNET_SYSERR;
+ }
- {
- struct TALER_AuditorSignatureP auditor_sig;
-
- TALER_auditor_denom_validity_sign (auditor_url,
- &h_denom_pub,
- &master_pub,
- stamp_start,
- stamp_expire_withdraw,
- stamp_expire_deposit,
- stamp_expire_legal,
- &coin_value,
- &fees,
- &auditor_priv,
- &auditor_sig);
- output_operation (OP_SIGN_DENOMINATION,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("h_denom_pub",
- &h_denom_pub),
- GNUNET_JSON_pack_data_auto ("auditor_sig",
- &auditor_sig)));
+ {
+ struct TALER_AuditorSignatureP auditor_sig;
+
+ TALER_auditor_denom_validity_sign (auditor_url,
+ &h_denom_pub,
+ &master_pub,
+ stamp_start,
+ stamp_expire_withdraw,
+ stamp_expire_deposit,
+ stamp_expire_legal,
+ &group.value,
+ &group.fees,
+ &auditor_priv,
+ &auditor_sig);
+ output_operation (OP_SIGN_DENOMINATION,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("h_denom_pub",
+ &h_denom_pub),
+ GNUNET_JSON_pack_data_auto ("auditor_sig",
+ &auditor_sig)));
+ }
+ GNUNET_JSON_parse_free (ispec);
}
GNUNET_JSON_parse_free (spec);
}
@@ -1145,10 +1190,10 @@ do_sign (char *const *args)
const char *err_name;
unsigned int err_line;
struct TALER_MasterPublicKeyP mpub;
- json_t *denomkeys;
+ const json_t *denomkeys;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("denoms",
- &denomkeys),
+ GNUNET_JSON_spec_array_const ("denominations",
+ &denomkeys),
GNUNET_JSON_spec_fixed_auto ("master_public_key",
&mpub),
GNUNET_JSON_spec_end ()
@@ -1203,11 +1248,9 @@ do_sign (char *const *args)
{
global_ret = EXIT_FAILURE;
test_shutdown ();
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
return;
}
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
next (args);
}
diff --git a/src/exchange-tools/taler-crypto-worker.c b/src/exchange-tools/taler-crypto-worker.c
deleted file mode 100644
index a1db1e812..000000000
--- a/src/exchange-tools/taler-crypto-worker.c
+++ /dev/null
@@ -1,461 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file exchange-tools/taler-crypto-worker.c
- * @brief Standalone process to perform various cryptographic operations.
- * @author Florian Dold
- */
-#include "platform.h"
-#include "taler_util.h"
-#include <gnunet/gnunet_json_lib.h>
-#include <gnunet/gnunet_crypto_lib.h>
-#include "taler_error_codes.h"
-#include "taler_json_lib.h"
-#include "taler_signatures.h"
-
-
-/**
- * Return value from main().
- */
-static int global_ret;
-
-
-/**
- * Main function that will be run under the GNUnet scheduler.
- *
- * @param cls closure
- * @param args remaining command-line arguments
- * @param cfgfile name of the configuration file used (for saving, can be NULL!)
- * @param cfg configuration
- */
-static void
-run (void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- (void) cls;
- (void) args;
- (void) cfgfile;
-
- json_t *req;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "started crypto worker\n");
-
- for (;;)
- {
- const char *op;
- const json_t *args;
- req = json_loadf (stdin, JSON_DISABLE_EOF_CHECK, NULL);
- if (NULL == req)
- {
- if (feof (stdin))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "end of input\n");
- global_ret = 0;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "invalid JSON\n");
- global_ret = 1;
- return;
- }
- op = json_string_value (json_object_get (req,
- "op"));
- if (! op)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "no op specified\n");
- global_ret = 1;
- return;
- }
- args = json_object_get (req, "args");
- if (! args)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "no args specified\n");
- global_ret = 1;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "got request\n");
- if (0 == strcmp ("eddsa_get_public",
- op))
- {
- struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
- struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv;
- json_t *resp;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("eddsa_priv",
- &eddsa_priv),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK != GNUNET_JSON_parse (args,
- spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- GNUNET_CRYPTO_eddsa_key_get_public (&eddsa_priv,
- &eddsa_pub);
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("eddsa_pub",
- &eddsa_pub)
- );
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (spec);
- continue;
- }
- if (0 == strcmp ("ecdhe_get_public",
- op))
- {
- struct GNUNET_CRYPTO_EcdhePublicKey ecdhe_pub;
- struct GNUNET_CRYPTO_EcdhePrivateKey ecdhe_priv;
- json_t *resp;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("ecdhe_priv",
- &ecdhe_priv),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK != GNUNET_JSON_parse (args,
- spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- GNUNET_CRYPTO_ecdhe_key_get_public (&ecdhe_priv,
- &ecdhe_pub);
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("ecdhe_pub",
- &ecdhe_pub)
- );
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (spec);
- continue;
- }
- if (0 == strcmp ("eddsa_verify",
- op))
- {
- struct GNUNET_CRYPTO_EddsaPublicKey pub;
- struct GNUNET_CRYPTO_EddsaSignature sig;
- struct GNUNET_CRYPTO_EccSignaturePurpose *msg;
- size_t msg_size;
- enum GNUNET_GenericReturnValue verify_ret;
- json_t *resp;
- struct GNUNET_JSON_Specification eddsa_verify_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("pub",
- &pub),
- GNUNET_JSON_spec_fixed_auto ("sig",
- &sig),
- GNUNET_JSON_spec_varsize ("msg",
- (void **) &msg,
- &msg_size),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK != GNUNET_JSON_parse (args,
- eddsa_verify_spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- verify_ret = GNUNET_CRYPTO_eddsa_verify_ (
- ntohl (msg->purpose),
- msg,
- &sig,
- &pub);
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_bool ("valid",
- GNUNET_OK == verify_ret));
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (eddsa_verify_spec);
- continue;
- }
- if (0 == strcmp ("kx_ecdhe_eddsa",
- op))
- {
- struct GNUNET_CRYPTO_EcdhePrivateKey priv;
- struct GNUNET_CRYPTO_EddsaPublicKey pub;
- struct GNUNET_HashCode key_material;
- json_t *resp;
- struct GNUNET_JSON_Specification kx_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("eddsa_pub",
- &pub),
- GNUNET_JSON_spec_fixed_auto ("ecdhe_priv",
- &priv),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK != GNUNET_JSON_parse (args,
- kx_spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- if (GNUNET_OK != GNUNET_CRYPTO_ecdh_eddsa (&priv,
- &pub,
- &key_material))
- {
- // FIXME: Return as result?
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "kx failed\n");
- global_ret = 1;
- return;
- }
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("h",
- &key_material)
- );
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (kx_spec);
- continue;
- }
- if (0 == strcmp ("eddsa_sign",
- op))
- {
- struct GNUNET_CRYPTO_EddsaSignature sig;
- struct GNUNET_CRYPTO_EccSignaturePurpose *msg;
- struct GNUNET_CRYPTO_EddsaPrivateKey priv;
- size_t msg_size;
- json_t *resp;
- struct GNUNET_JSON_Specification eddsa_sign_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("priv",
- &priv),
- GNUNET_JSON_spec_varsize ("msg",
- (void **) &msg,
- &msg_size),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK !=
- GNUNET_JSON_parse (args,
- eddsa_sign_spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign_ (
- &priv,
- msg,
- &sig));
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("sig", &sig)
- );
- json_dumpf (resp, stdout,
- JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (eddsa_sign_spec);
- continue;
- }
- if (0 == strcmp ("setup_refresh_planchet", op))
- {
- struct TALER_TransferSecretP transfer_secret;
- uint32_t coin_index;
- json_t *resp;
- struct GNUNET_JSON_Specification setup_refresh_planchet_spec[] = {
- GNUNET_JSON_spec_uint32 ("coin_index",
- &coin_index),
- GNUNET_JSON_spec_fixed_auto ("transfer_secret",
- &transfer_secret),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendPrivateKeyP coin_priv;
- struct TALER_PlanchetMasterSecretP ps;
- struct TALER_ExchangeWithdrawValues alg_values = {
- // FIXME: also allow CS
- .cipher = TALER_DENOMINATION_RSA,
- };
- union TALER_DenominationBlindingKeyP dbk;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (args,
- setup_refresh_planchet_spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- TALER_transfer_secret_to_planchet_secret (&transfer_secret,
- coin_index,
- &ps);
- TALER_planchet_setup_coin_priv (&ps,
- &alg_values,
- &coin_priv);
- GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv.eddsa_priv,
- &coin_pub.eddsa_pub);
- TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
- &dbk);
-
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("coin_priv", &coin_priv),
- GNUNET_JSON_pack_data_auto ("coin_pub", &coin_pub),
- GNUNET_JSON_pack_data_auto ("blinding_key", &dbk.rsa_bks)
- );
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (setup_refresh_planchet_spec);
- continue;
- }
- if (0 == strcmp ("rsa_blind", op))
- {
- struct GNUNET_HashCode hm;
- struct GNUNET_CRYPTO_RsaBlindingKeySecret bks;
- void *pub_enc;
- size_t pub_enc_size;
- int success;
- struct GNUNET_CRYPTO_RsaPublicKey *pub;
- void *blinded_buf;
- size_t blinded_size;
- json_t *resp;
- struct GNUNET_JSON_Specification rsa_blind_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("hm",
- &hm),
- GNUNET_JSON_spec_fixed_auto ("bks",
- &bks),
- GNUNET_JSON_spec_varsize ("pub",
- &pub_enc,
- &pub_enc_size),
- GNUNET_JSON_spec_end ()
- };
- if (GNUNET_OK !=
- GNUNET_JSON_parse (args,
- rsa_blind_spec,
- NULL,
- NULL))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "malformed op args\n");
- global_ret = 1;
- return;
- }
- pub = GNUNET_CRYPTO_rsa_public_key_decode (pub_enc,
- pub_enc_size);
- success = GNUNET_CRYPTO_rsa_blind (&hm,
- &bks,
- pub,
- &blinded_buf,
- &blinded_size);
-
- if (GNUNET_YES == success)
- {
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_varsize ("blinded", blinded_buf, blinded_size),
- GNUNET_JSON_pack_bool ("success", true)
- );
- }
- else
- {
- resp = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_bool ("success", false)
- );
- }
- json_dumpf (resp, stdout, JSON_COMPACT);
- printf ("\n");
- fflush (stdout);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "sent response\n");
- GNUNET_JSON_parse_free (rsa_blind_spec);
- GNUNET_free (blinded_buf);
- continue;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "unsupported operation '%s'\n",
- op);
- global_ret = 1;
- return;
- }
-
-}
-
-
-/**
- * The entry point.
- *
- * @param argc number of arguments in @a argv
- * @param argv command-line arguments
- * @return 0 on normal termination
- */
-int
-main (int argc,
- char **argv)
-{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
- int ret;
-
- /* force linker to link against libtalerutil; if we do
- not do this, the linker may "optimize" libtalerutil
- away and skip #TALER_OS_init(), which we do need */
- TALER_OS_init ();
- ret = GNUNET_PROGRAM_run (argc, argv,
- "taler-crypto-worker",
- "Execute cryptographic operations read from stdin",
- options,
- &run,
- NULL);
- if (GNUNET_NO == ret)
- return 0;
- if (GNUNET_SYSERR == ret)
- return 1;
- return global_ret;
-}
diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c
index 818373816..41ff2ab24 100644
--- a/src/exchange-tools/taler-exchange-dbinit.c
+++ b/src/exchange-tools/taler-exchange-dbinit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -30,6 +30,11 @@
static int global_ret;
/**
+ * -a option: inject auditor triggers
+ */
+static int inject_auditor;
+
+/**
* -r option: do full DB reset
*/
static int reset_db;
@@ -50,26 +55,11 @@ static int gc_db;
static uint32_t num_partitions;
/**
- * -F option: setup a sharded database, i.e. create foreign tables/server
- */
-static int shard_db;
-
-/**
* -f option: force partitions to be created when there is only one
*/
static int force_create_partitions;
/**
- * -S option: setup a database on a shard server, creates tables with suffix shard_idx
- */
-static uint32_t shard_idx;
-
-/**
- * -R option: do full shard DB reset
- */
-static uint32_t reset_shard_db;
-
-/**
* Main function that will be run.
*
* @param cls closure
@@ -88,6 +78,7 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
+
if (NULL ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
@@ -98,43 +89,17 @@ run (void *cls,
}
if (reset_db)
{
- if (GNUNET_OK != plugin->drop_tables (plugin->cls))
+ if (GNUNET_OK !=
+ plugin->drop_tables (plugin->cls))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not drop tables as requested. Either database was not yet initialized, or permission denied. Consult the logs. Will still try to create new tables.\n");
}
}
- if (0 <
- reset_shard_db)
- {
- if (GNUNET_OK != plugin->drop_shard_tables (plugin->cls, reset_shard_db))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not drop shard tables as requested. Either database was not yet initialized or permission denied. Consult the logs.\n");
- global_ret = EXIT_FAILURE;
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
- "Dropped shard database, please call taler-exchange-dbinit -S <N> to initialize a new shard database\n");
- return;
- }
- if (0 <
- shard_idx)
- {
- if (GNUNET_OK != plugin->create_shard_tables (plugin->cls,
- shard_idx))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not create shard database\n");
- global_ret = EXIT_NOTINSTALLED;
- }
- /* We do not want to continue if we are on a shard */
- TALER_EXCHANGEDB_plugin_unload (plugin);
- plugin = NULL;
- return;
- }
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls))
+ plugin->create_tables (plugin->cls,
+ force_create_partitions || num_partitions > 0,
+ num_partitions))
{
fprintf (stderr,
"Failed to initialize database.\n");
@@ -143,38 +108,6 @@ run (void *cls,
global_ret = EXIT_NOPERMISSION;
return;
}
- if (1 <
- num_partitions
- || (
- 1 == num_partitions
- && force_create_partitions))
- {
- enum GNUNET_GenericReturnValue r = GNUNET_OK;
- if (shard_db)
- {
- r = plugin->setup_foreign_servers (plugin->cls,
- num_partitions);
- }
- else
- {
- r = plugin->setup_partitions (plugin->cls,
- num_partitions);
- }
- if (GNUNET_OK != r)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not setup partitions. Dropping default ones again\n");
- if (GNUNET_OK != plugin->drop_tables (plugin->cls))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not drop tables after failed partitioning, please delete the DB manually\n");
- }
- TALER_EXCHANGEDB_plugin_unload (plugin);
- plugin = NULL;
- global_ret = EXIT_NOTINSTALLED;
- return;
- }
- }
if (gc_db || clear_shards)
{
if (GNUNET_OK !=
@@ -189,7 +122,7 @@ run (void *cls,
}
if (clear_shards)
{
- if (0 >
+ if (GNUNET_OK !=
plugin->delete_shard_locks (plugin->cls))
{
fprintf (stderr,
@@ -205,6 +138,15 @@ run (void *cls,
}
}
}
+ if (inject_auditor)
+ {
+ if (GNUNET_SYSERR == plugin->inject_auditor_triggers (plugin->cls))
+ {
+ fprintf (stderr,
+ "Injecting auditor triggers failed!\n");
+ global_ret = EXIT_FAILURE;
+ }
+ }
TALER_EXCHANGEDB_plugin_unload (plugin);
plugin = NULL;
}
@@ -223,6 +165,10 @@ main (int argc,
char *const *argv)
{
const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_flag ('a',
+ "inject-auditor",
+ "inject auditor triggers",
+ &inject_auditor),
GNUNET_GETOPT_option_flag ('g',
"gc",
"garbage collect database",
@@ -238,22 +184,8 @@ main (int argc,
GNUNET_GETOPT_option_uint ('P',
"partition",
"NUMBER",
- "Setup a partitioned database where each table which can be partitioned holds NUMBER partitions on a single DB node (NOTE: sharding add -F for sharding)",
+ "Setup a partitioned database where each table which can be partitioned holds NUMBER partitions on a single DB node",
&num_partitions),
- GNUNET_GETOPT_option_flag ('F',
- "foreign",
- "Setup a sharded database with foreign servers (shards) / tables rather than a partitioned one, must be called as DB superuser.",
- &shard_db),
- GNUNET_GETOPT_option_uint ('S',
- "shard",
- "INDEX",
- "Setup a shard server, creates tables with INDEX as suffix",
- &shard_idx),
- GNUNET_GETOPT_option_uint ('R',
- "reset-shard",
- "OLD_SHARD_IDX",
- "reset a shard database, does not reinitialize i.e. call taler-exchange-dbinit -S afterwards (DANGEROUS: all existing data is lost!)",
- &reset_shard_db),
GNUNET_GETOPT_option_flag ('f',
"force",
"Force partitions to be created if there is only one partition",
diff --git a/src/exchange-tools/taler-exchange-offline.c b/src/exchange-tools/taler-exchange-offline.c
index 41cd2597e..1f10c55e3 100644
--- a/src/exchange-tools/taler-exchange-offline.c
+++ b/src/exchange-tools/taler-exchange-offline.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020, 2021, 2022 Taler Systems SA
+ Copyright (C) 2020-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -24,6 +24,8 @@
#include "taler_json_lib.h"
#include "taler_exchange_service.h"
#include "taler_extensions.h"
+#include <regex.h>
+
/**
* Name of the input for the 'sign' and 'show' operation.
@@ -107,6 +109,20 @@
*/
#define OP_EXTENSIONS "exchange-extensions-0"
+/**
+ * Generate message to drain profits.
+ */
+#define OP_DRAIN_PROFITS "exchange-drain-profits-0"
+
+/**
+ * Setup AML staff.
+ */
+#define OP_UPDATE_AML_STAFF "exchange-add-aml-staff-0"
+
+/**
+ * Setup partner exchange for wad transfers.
+ */
+#define OP_ADD_PARTNER "exchange-add-partner-0"
/**
* Our private key, initialized in #load_offline_key().
@@ -134,6 +150,12 @@ static struct GNUNET_CURL_RescheduleContext *rc;
static const struct GNUNET_CONFIGURATION_Handle *kcfg;
/**
+ * Age restriction configuration
+ */
+static bool ar_enabled = false;
+static struct TALER_AgeRestrictionConfig ar_config = {0};
+
+/**
* Return value from main().
*/
static int global_ret;
@@ -160,11 +182,6 @@ static char *currency;
static char *CFG_exchange_url;
/**
- * If age restriction is enabled, the age mask to be used
- */
-static struct TALER_AgeMask age_mask = {0};
-
-/**
* A subcommand supported by this program.
*/
struct SubCommand
@@ -385,6 +402,34 @@ struct WireFeeRequest
/**
+ * Data structure for draining profits.
+ */
+struct DrainProfitsRequest
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct DrainProfitsRequest *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct DrainProfitsRequest *prev;
+
+ /**
+ * Operation handle.
+ */
+ struct TALER_EXCHANGE_ManagementDrainProfitsHandle *h;
+
+ /**
+ * Array index of the associated command.
+ */
+ size_t idx;
+};
+
+
+/**
* Data structure for announcing global fees.
*/
struct GlobalFeeRequest
@@ -466,6 +511,62 @@ struct UploadExtensionsRequest
/**
+ * Data structure for AML staff requests.
+ */
+struct AmlStaffRequest
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct AmlStaffRequest *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct AmlStaffRequest *prev;
+
+ /**
+ * Operation handle.
+ */
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *h;
+
+ /**
+ * Array index of the associated command.
+ */
+ size_t idx;
+};
+
+
+/**
+ * Data structure for partner add requests.
+ */
+struct PartnerAddRequest
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct PartnerAddRequest *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct PartnerAddRequest *prev;
+
+ /**
+ * Operation handle.
+ */
+ struct TALER_EXCHANGE_ManagementAddPartner *h;
+
+ /**
+ * Array index of the associated command.
+ */
+ size_t idx;
+};
+
+
+/**
* Next work item to perform.
*/
static struct GNUNET_SCHEDULER_Task *nxt;
@@ -475,6 +576,27 @@ static struct GNUNET_SCHEDULER_Task *nxt;
*/
static struct TALER_EXCHANGE_ManagementGetKeysHandle *mgkh;
+
+/**
+ * Active AML staff change requests.
+ */
+static struct AmlStaffRequest *asr_head;
+
+/**
+ * Active AML staff change requests.
+ */
+static struct AmlStaffRequest *asr_tail;
+
+/**
+ * Active partner add requests.
+ */
+static struct PartnerAddRequest *par_head;
+
+/**
+ * Active partner add requests.
+ */
+static struct PartnerAddRequest *par_tail;
+
/**
* Active denomiantion revocation requests.
*/
@@ -576,6 +698,17 @@ static struct UploadExtensionsRequest *uer_head;
static struct UploadExtensionsRequest *uer_tail;
/**
+ * Active drain profits requests.
+ */
+struct DrainProfitsRequest *dpr_head;
+
+/**
+ * Active drain profits requests.
+ */
+static struct DrainProfitsRequest *dpr_tail;
+
+
+/**
* Shutdown task. Invoked when the application is being terminated.
*
* @param cls NULL
@@ -586,6 +719,36 @@ do_shutdown (void *cls)
(void) cls;
{
+ struct AmlStaffRequest *asr;
+
+ while (NULL != (asr = asr_head))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Aborting incomplete AML staff update #%u\n",
+ (unsigned int) asr->idx);
+ TALER_EXCHANGE_management_update_aml_officer_cancel (asr->h);
+ GNUNET_CONTAINER_DLL_remove (asr_head,
+ asr_tail,
+ asr);
+ GNUNET_free (asr);
+ }
+ }
+ {
+ struct PartnerAddRequest *par;
+
+ while (NULL != (par = par_head))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Aborting incomplete partner add request #%u\n",
+ (unsigned int) par->idx);
+ TALER_EXCHANGE_management_add_partner_cancel (par->h);
+ GNUNET_CONTAINER_DLL_remove (par_head,
+ par_tail,
+ par);
+ GNUNET_free (par);
+ }
+ }
+ {
struct DenomRevocationRequest *drr;
while (NULL != (drr = drr_head))
@@ -736,11 +899,29 @@ do_shutdown (void *cls)
GNUNET_free (uer);
}
}
+
+ {
+ struct DrainProfitsRequest *dpr;
+
+ while (NULL != (dpr = dpr_head))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Aborting incomplete drain profits request #%u\n",
+ (unsigned int) dpr->idx);
+ TALER_EXCHANGE_management_drain_profits_cancel (dpr->h);
+ GNUNET_CONTAINER_DLL_remove (dpr_head,
+ dpr_tail,
+ dpr);
+ GNUNET_free (dpr);
+ }
+ }
+
if (NULL != out)
{
- json_dumpf (out,
- stdout,
- JSON_INDENT (2));
+ if (EXIT_SUCCESS == global_ret)
+ json_dumpf (out,
+ stdout,
+ JSON_INDENT (2));
json_decref (out);
out = NULL;
}
@@ -781,6 +962,8 @@ static void
test_shutdown (void)
{
if ( (NULL == drr_head) &&
+ (NULL == par_head) &&
+ (NULL == asr_head) &&
(NULL == srr_head) &&
(NULL == aar_head) &&
(NULL == adr_head) &&
@@ -790,6 +973,7 @@ test_shutdown (void)
(NULL == gfr_head) &&
(NULL == ukr_head) &&
(NULL == uer_head) &&
+ (NULL == dpr_head) &&
(NULL == mgkh) &&
(NULL == nxt) )
GNUNET_SCHEDULER_shutdown ();
@@ -926,6 +1110,9 @@ load_offline_key (int do_create)
GNUNET_free (fn);
GNUNET_CRYPTO_eddsa_key_get_public (&master_priv.eddsa_priv,
&master_pub.eddsa_pub);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Using master public key %s\n",
+ TALER_B2S (&master_pub));
done = true;
return GNUNET_OK;
}
@@ -935,14 +1122,15 @@ load_offline_key (int do_create)
* Function called with information about the post revocation operation result.
*
* @param cls closure with a `struct DenomRevocationRequest`
- * @param hr HTTP response data
+ * @param dr response data
*/
static void
denom_revocation_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementRevokeDenominationResponse *dr)
{
struct DenomRevocationRequest *drr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &dr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1002,7 +1190,7 @@ upload_denom_revocation (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
drr = GNUNET_new (struct DenomRevocationRequest);
@@ -1024,14 +1212,15 @@ upload_denom_revocation (const char *exchange_url,
* Function called with information about the post revocation operation result.
*
* @param cls closure with a `struct SignkeyRevocationRequest`
- * @param hr HTTP response data
+ * @param sr response data
*/
static void
signkey_revocation_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementRevokeSigningKeyResponse *sr)
{
struct SignkeyRevocationRequest *srr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &sr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1091,7 +1280,7 @@ upload_signkey_revocation (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
srr = GNUNET_new (struct SignkeyRevocationRequest);
@@ -1113,13 +1302,15 @@ upload_signkey_revocation (const char *exchange_url,
* Function called with information about the post auditor add operation result.
*
* @param cls closure with a `struct AuditorAddRequest`
- * @param hr HTTP response data
+ * @param mer response data
*/
static void
-auditor_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+auditor_add_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *mer)
{
struct AuditorAddRequest *aar = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &mer->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1160,7 +1351,7 @@ upload_auditor_add (const char *exchange_url,
const char *err_name;
unsigned int err_line;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("auditor_url",
+ TALER_JSON_spec_web_url ("auditor_url",
&auditor_url),
GNUNET_JSON_spec_string ("auditor_name",
&auditor_name),
@@ -1188,7 +1379,7 @@ upload_auditor_add (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
aar = GNUNET_new (struct AuditorAddRequest);
@@ -1213,13 +1404,15 @@ upload_auditor_add (const char *exchange_url,
* Function called with information about the post auditor del operation result.
*
* @param cls closure with a `struct AuditorDelRequest`
- * @param hr HTTP response data
+ * @param mdr response data
*/
static void
auditor_del_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct
+ TALER_EXCHANGE_ManagementAuditorDisableResponse *mdr)
{
struct AuditorDelRequest *adr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &mdr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1282,7 +1475,7 @@ upload_auditor_del (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
adr = GNUNET_new (struct AuditorDelRequest);
@@ -1305,13 +1498,14 @@ upload_auditor_del (const char *exchange_url,
* Function called with information about the post wire add operation result.
*
* @param cls closure with a `struct WireAddRequest`
- * @param hr HTTP response data
+ * @param wer response data
*/
static void
wire_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementWireEnableResponse *wer)
{
struct WireAddRequest *war = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &wer->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1349,10 +1543,29 @@ upload_wire_add (const char *exchange_url,
struct GNUNET_TIME_Timestamp start_time;
struct WireAddRequest *war;
const char *err_name;
+ const char *conversion_url = NULL;
+ const char *bank_label = NULL;
+ int64_t priority = 0;
+ const json_t *debit_restrictions;
+ const json_t *credit_restrictions;
unsigned int err_line;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("payto_uri",
- &payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &payto_uri),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_web_url ("conversion_url",
+ &conversion_url),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("bank_label",
+ &bank_label),
+ NULL),
+ GNUNET_JSON_spec_int64 ("priority",
+ &priority),
+ GNUNET_JSON_spec_array_const ("debit_restrictions",
+ &debit_restrictions),
+ GNUNET_JSON_spec_array_const ("credit_restrictions",
+ &credit_restrictions),
GNUNET_JSON_spec_timestamp ("validity_start",
&start_time),
GNUNET_JSON_spec_fixed_auto ("master_sig_add",
@@ -1377,7 +1590,7 @@ upload_wire_add (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
{
@@ -1390,7 +1603,7 @@ upload_wire_add (const char *exchange_url,
"payto:// URI `%s' is malformed\n",
payto_uri);
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_free (wire_method);
@@ -1404,7 +1617,7 @@ upload_wire_add (const char *exchange_url,
"payto URI is malformed: %s\n",
msg);
GNUNET_free (msg);
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -1415,9 +1628,14 @@ upload_wire_add (const char *exchange_url,
TALER_EXCHANGE_management_enable_wire (ctx,
exchange_url,
payto_uri,
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
start_time,
&master_sig_add,
&master_sig_wire,
+ bank_label,
+ priority,
&wire_add_cb,
war);
GNUNET_CONTAINER_DLL_insert (war_head,
@@ -1430,13 +1648,14 @@ upload_wire_add (const char *exchange_url,
* Function called with information about the post wire del operation result.
*
* @param cls closure with a `struct WireDelRequest`
- * @param hr HTTP response data
+ * @param wdres response data
*/
static void
wire_del_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementWireDisableResponse *wdres)
{
struct WireDelRequest *wdr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &wdres->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1475,8 +1694,8 @@ upload_wire_del (const char *exchange_url,
const char *err_name;
unsigned int err_line;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("payto_uri",
- &payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &payto_uri),
GNUNET_JSON_spec_timestamp ("validity_end",
&end_time),
GNUNET_JSON_spec_fixed_auto ("master_sig",
@@ -1499,7 +1718,7 @@ upload_wire_del (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
wdr = GNUNET_new (struct WireDelRequest);
@@ -1522,14 +1741,15 @@ upload_wire_del (const char *exchange_url,
* Function called with information about the post wire fee operation result.
*
* @param cls closure with a `struct WireFeeRequest`
- * @param hr HTTP response data
+ * @param swr response data
*/
static void
wire_fee_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *swr)
{
struct WireFeeRequest *wfr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &swr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1575,9 +1795,6 @@ upload_wire_fee (const char *exchange_url,
TALER_JSON_spec_amount ("wire_fee",
currency,
&fees.wire),
- TALER_JSON_spec_amount ("wad_fee",
- currency,
- &fees.wad),
TALER_JSON_spec_amount ("closing_fee",
currency,
&fees.closing),
@@ -1605,7 +1822,7 @@ upload_wire_fee (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
wfr = GNUNET_new (struct WireFeeRequest);
@@ -1630,14 +1847,15 @@ upload_wire_fee (const char *exchange_url,
* Function called with information about the post global fee operation result.
*
* @param cls closure with a `struct WireFeeRequest`
- * @param hr HTTP response data
+ * @param gr response data
*/
static void
global_fee_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse *gr)
{
struct GlobalFeeRequest *gfr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &gr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1677,16 +1895,12 @@ upload_global_fee (const char *exchange_url,
struct GNUNET_TIME_Timestamp start_time;
struct GNUNET_TIME_Timestamp end_time;
struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
struct GNUNET_TIME_Relative history_expiration;
uint32_t purse_account_limit;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("history_fee",
currency,
&fees.history),
- TALER_JSON_spec_amount ("kyc_fee",
- currency,
- &fees.kyc),
TALER_JSON_spec_amount ("account_fee",
currency,
&fees.account),
@@ -1695,8 +1909,6 @@ upload_global_fee (const char *exchange_url,
&fees.purse),
GNUNET_JSON_spec_relative_time ("purse_timeout",
&purse_timeout),
- GNUNET_JSON_spec_relative_time ("kyc_timeout",
- &kyc_timeout),
GNUNET_JSON_spec_relative_time ("history_expiration",
&history_expiration),
GNUNET_JSON_spec_uint32 ("purse_account_limit",
@@ -1725,7 +1937,7 @@ upload_global_fee (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
gfr = GNUNET_new (struct GlobalFeeRequest);
@@ -1737,7 +1949,6 @@ upload_global_fee (const char *exchange_url,
end_time,
&fees,
purse_timeout,
- kyc_timeout,
history_expiration,
purse_account_limit,
&master_sig,
@@ -1750,17 +1961,125 @@ upload_global_fee (const char *exchange_url,
/**
+ * Function called with information about the drain profits operation.
+ *
+ * @param cls closure with a `struct DrainProfitsRequest`
+ * @param mdr response data
+ */
+static void
+drain_profits_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementDrainResponse *mdr)
+{
+ struct DrainProfitsRequest *dpr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &mdr->hr;
+
+ if (MHD_HTTP_NO_CONTENT != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Upload failed for command %u with status %u: %s (%s)\n",
+ (unsigned int) dpr->idx,
+ hr->http_status,
+ TALER_ErrorCode_get_hint (hr->ec),
+ hr->hint);
+ global_ret = EXIT_FAILURE;
+ }
+ GNUNET_CONTAINER_DLL_remove (dpr_head,
+ dpr_tail,
+ dpr);
+ GNUNET_free (dpr);
+ test_shutdown ();
+}
+
+
+/**
+ * Upload drain profit action.
+ *
+ * @param exchange_url base URL of the exchange
+ * @param idx index of the operation we are performing (for logging)
+ * @param value arguments for drain profits
+ */
+static void
+upload_drain (const char *exchange_url,
+ size_t idx,
+ const json_t *value)
+{
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_MasterSignatureP master_sig;
+ const char *err_name;
+ unsigned int err_line;
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Timestamp date;
+ const char *payto_uri;
+ const char *account_section;
+ struct DrainProfitsRequest *dpr;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("wtid",
+ &wtid),
+ TALER_JSON_spec_amount ("amount",
+ currency,
+ &amount),
+ GNUNET_JSON_spec_timestamp ("date",
+ &date),
+ GNUNET_JSON_spec_string ("account_section",
+ &account_section),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &payto_uri),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value,
+ spec,
+ &err_name,
+ &err_line))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid input to drain profits: %s#%u at %u (skipping)\n",
+ err_name,
+ err_line,
+ (unsigned int) idx);
+ json_dumpf (value,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ dpr = GNUNET_new (struct DrainProfitsRequest);
+ dpr->idx = idx;
+ dpr->h =
+ TALER_EXCHANGE_management_drain_profits (ctx,
+ exchange_url,
+ &wtid,
+ &amount,
+ date,
+ account_section,
+ payto_uri,
+ &master_sig,
+ &drain_profits_cb,
+ dpr);
+ GNUNET_CONTAINER_DLL_insert (dpr_head,
+ dpr_tail,
+ dpr);
+}
+
+
+/**
* Function called with information about the post upload keys operation result.
*
* @param cls closure with a `struct UploadKeysRequest`
- * @param hr HTTP response data
+ * @param mr response data
*/
static void
keys_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementPostKeysResponse *mr)
{
struct UploadKeysRequest *ukr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &mr->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1796,13 +2115,13 @@ upload_keys (const char *exchange_url,
struct UploadKeysRequest *ukr;
const char *err_name;
unsigned int err_line;
- json_t *denom_sigs;
- json_t *signkey_sigs;
+ const json_t *denom_sigs;
+ const json_t *signkey_sigs;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("denom_sigs",
- &denom_sigs),
- GNUNET_JSON_spec_json ("signkey_sigs",
- &signkey_sigs),
+ GNUNET_JSON_spec_array_const ("denom_sigs",
+ &denom_sigs),
+ GNUNET_JSON_spec_array_const ("signkey_sigs",
+ &signkey_sigs),
GNUNET_JSON_spec_end ()
};
bool ok = true;
@@ -1821,7 +2140,7 @@ upload_keys (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
pkd.num_sign_sigs = json_array_size (signkey_sigs);
@@ -1914,11 +2233,10 @@ upload_keys (const char *exchange_url,
else
{
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
}
GNUNET_free (pkd.sign_sigs);
GNUNET_free (pkd.denom_sigs);
- GNUNET_JSON_parse_free (spec);
}
@@ -1926,14 +2244,15 @@ upload_keys (const char *exchange_url,
* Function called with information about the post upload extensions operation result.
*
* @param cls closure with a `struct UploadExtensionsRequest`
- * @param hr HTTP response data
+ * @param er response data
*/
static void
extensions_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementPostExtensionsResponse *er)
{
struct UploadExtensionsRequest *uer = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &er->hr;
if (MHD_HTTP_NO_CONTENT != hr->http_status)
{
@@ -1965,13 +2284,13 @@ upload_extensions (const char *exchange_url,
size_t idx,
const json_t *value)
{
- json_t *extensions;
+ const json_t *extensions;
struct TALER_MasterSignatureP sig;
const char *err_name;
unsigned int err_line;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("extensions",
- &extensions),
+ GNUNET_JSON_spec_object_const ("extensions",
+ &extensions),
GNUNET_JSON_spec_fixed_auto ("extensions_sig",
&sig),
GNUNET_JSON_spec_end ()
@@ -1993,22 +2312,22 @@ upload_extensions (const char *exchange_url,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
/* 2. Verify the signature */
{
- struct TALER_ExtensionConfigHashP h_config;
+ struct TALER_ExtensionManifestsHashP h_manifests;
if (GNUNET_OK !=
- TALER_JSON_extensions_config_hash (extensions, &h_config))
+ TALER_JSON_extensions_manifests_hash (extensions,
+ &h_manifests))
{
- GNUNET_JSON_parse_free (spec);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "couldn't hash extensions\n");
+ "couldn't hash extensions' manifests\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -2016,16 +2335,15 @@ upload_extensions (const char *exchange_url,
load_offline_key (GNUNET_NO))
return;
- if (GNUNET_OK != TALER_exchange_offline_extension_config_hash_verify (
- &h_config,
+ if (GNUNET_OK != TALER_exchange_offline_extension_manifests_hash_verify (
+ &h_manifests,
&master_pub,
&sig))
{
- GNUNET_JSON_parse_free (spec);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"invalid signature for extensions\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
@@ -2036,8 +2354,9 @@ upload_extensions (const char *exchange_url,
.extensions = extensions,
.extensions_sig = sig,
};
- struct UploadExtensionsRequest *uer = GNUNET_new (struct
- UploadExtensionsRequest);
+ struct UploadExtensionsRequest *uer
+ = GNUNET_new (struct UploadExtensionsRequest);
+
uer->idx = idx;
uer->h = TALER_EXCHANGE_management_post_extensions (
ctx,
@@ -2049,7 +2368,223 @@ upload_extensions (const char *exchange_url,
uer_tail,
uer);
}
- GNUNET_JSON_parse_free (spec);
+}
+
+
+/**
+ * Function called with information about the add partner operation.
+ *
+ * @param cls closure with a `struct PartnerAddRequest`
+ * @param apr response data
+ */
+static void
+add_partner_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementAddPartnerResponse *apr)
+{
+ struct PartnerAddRequest *par = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &apr->hr;
+
+ if (MHD_HTTP_NO_CONTENT != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Upload failed for command %u with status %u: %s (%s)\n",
+ (unsigned int) par->idx,
+ hr->http_status,
+ TALER_ErrorCode_get_hint (hr->ec),
+ hr->hint);
+ global_ret = EXIT_FAILURE;
+ }
+ GNUNET_CONTAINER_DLL_remove (par_head,
+ par_tail,
+ par);
+ GNUNET_free (par);
+ test_shutdown ();
+}
+
+
+/**
+ * Add partner action.
+ *
+ * @param exchange_url base URL of the exchange
+ * @param idx index of the operation we are performing (for logging)
+ * @param value arguments for add partner
+ */
+static void
+add_partner (const char *exchange_url,
+ size_t idx,
+ const json_t *value)
+{
+ struct TALER_MasterPublicKeyP partner_pub;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct GNUNET_TIME_Relative wad_frequency;
+ struct TALER_Amount wad_fee;
+ const char *partner_base_url;
+ struct TALER_MasterSignatureP master_sig;
+ struct PartnerAddRequest *par;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("partner_pub",
+ &partner_pub),
+ TALER_JSON_spec_amount ("wad_fee",
+ currency,
+ &wad_fee),
+ GNUNET_JSON_spec_relative_time ("wad_frequency",
+ &wad_frequency),
+ GNUNET_JSON_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_JSON_spec_timestamp ("end_date",
+ &end_date),
+ TALER_JSON_spec_web_url ("partner_base_url",
+ &partner_base_url),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *err_name;
+ unsigned int err_line;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value,
+ spec,
+ &err_name,
+ &err_line))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid input to add partner: %s#%u at %u (skipping)\n",
+ err_name,
+ err_line,
+ (unsigned int) idx);
+ json_dumpf (value,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ par = GNUNET_new (struct PartnerAddRequest);
+ par->idx = idx;
+ par->h =
+ TALER_EXCHANGE_management_add_partner (ctx,
+ exchange_url,
+ &partner_pub,
+ start_date,
+ end_date,
+ wad_frequency,
+ &wad_fee,
+ partner_base_url,
+ &master_sig,
+ &add_partner_cb,
+ par);
+ GNUNET_CONTAINER_DLL_insert (par_head,
+ par_tail,
+ par);
+}
+
+
+/**
+ * Function called with information about the AML officer update operation.
+ *
+ * @param cls closure with a `struct AmlStaffRequest`
+ * @param ar response data
+ */
+static void
+update_aml_officer_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementUpdateAmlOfficerResponse *ar)
+{
+ struct AmlStaffRequest *asr = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &ar->hr;
+
+ if (MHD_HTTP_NO_CONTENT != hr->http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Upload failed for command %u with status %u: %s (%s)\n",
+ (unsigned int) asr->idx,
+ hr->http_status,
+ TALER_ErrorCode_get_hint (hr->ec),
+ hr->hint);
+ global_ret = EXIT_FAILURE;
+ }
+ GNUNET_CONTAINER_DLL_remove (asr_head,
+ asr_tail,
+ asr);
+ GNUNET_free (asr);
+ test_shutdown ();
+}
+
+
+/**
+ * Upload AML staff action.
+ *
+ * @param exchange_url base URL of the exchange
+ * @param idx index of the operation we are performing (for logging)
+ * @param value arguments for AML staff change
+ */
+static void
+update_aml_staff (const char *exchange_url,
+ size_t idx,
+ const json_t *value)
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ const char *officer_name;
+ struct GNUNET_TIME_Timestamp change_date;
+ bool is_active;
+ bool read_only;
+ struct TALER_MasterSignatureP master_sig;
+ struct AmlStaffRequest *asr;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("officer_pub",
+ &officer_pub),
+ GNUNET_JSON_spec_timestamp ("change_date",
+ &change_date),
+ GNUNET_JSON_spec_bool ("is_active",
+ &is_active),
+ GNUNET_JSON_spec_bool ("read_only",
+ &read_only),
+ GNUNET_JSON_spec_string ("officer_name",
+ &officer_name),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *err_name;
+ unsigned int err_line;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value,
+ spec,
+ &err_name,
+ &err_line))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid input to AML staff update: %s#%u at %u (skipping)\n",
+ err_name,
+ err_line,
+ (unsigned int) idx);
+ json_dumpf (value,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ asr = GNUNET_new (struct AmlStaffRequest);
+ asr->idx = idx;
+ asr->h =
+ TALER_EXCHANGE_management_update_aml_officer (ctx,
+ exchange_url,
+ &officer_pub,
+ officer_name,
+ change_date,
+ is_active,
+ read_only,
+ &master_sig,
+ &update_aml_officer_cb,
+ asr);
+ GNUNET_CONTAINER_DLL_insert (asr_head,
+ asr_tail,
+ asr);
}
@@ -2099,9 +2634,21 @@ trigger_upload (const char *exchange_url)
.cb = &upload_keys
},
{
+ .key = OP_DRAIN_PROFITS,
+ .cb = &upload_drain
+ },
+ {
.key = OP_EXTENSIONS,
.cb = &upload_extensions
},
+ {
+ .key = OP_UPDATE_AML_STAFF,
+ .cb = &update_aml_staff
+ },
+ {
+ .key = OP_ADD_PARTNER,
+ .cb = &add_partner
+ },
/* array termination */
{
.key = NULL
@@ -2122,7 +2669,7 @@ trigger_upload (const char *exchange_url)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Malformed JSON input\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
/* block of code that uses key and value */
@@ -2145,7 +2692,7 @@ trigger_upload (const char *exchange_url)
"Upload does not know how to handle `%s'\n",
key);
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
}
@@ -2165,7 +2712,7 @@ do_upload (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, refusing upload\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2184,7 +2731,7 @@ do_upload (char *const *args)
err.line,
err.source,
err.position);
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2193,7 +2740,7 @@ do_upload (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Error: expected JSON array for `upload` command\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2208,7 +2755,7 @@ do_upload (char *const *args)
"exchange",
"BASE_URL");
global_ret = EXIT_NOTCONFIGURED;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
trigger_upload (CFG_exchange_url);
@@ -2233,7 +2780,7 @@ do_revoke_denomination_key (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, refusing revocation\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2246,7 +2793,7 @@ do_revoke_denomination_key (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify a denomination key with this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2282,7 +2829,7 @@ do_revoke_signkey (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, refusing revocation\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2295,7 +2842,7 @@ do_revoke_signkey (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify an exchange signing key with this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2333,7 +2880,7 @@ do_add_auditor (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not adding auditor\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2346,7 +2893,7 @@ do_add_auditor (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify an auditor public key as first argument for this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2359,7 +2906,7 @@ do_add_auditor (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify an auditor URI and auditor name as 2nd and 3rd arguments to this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2405,7 +2952,7 @@ do_del_auditor (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not deleting auditor account\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2418,7 +2965,7 @@ do_del_auditor (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify an auditor public key as first argument for this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2443,6 +2990,96 @@ do_del_auditor (char *const *args)
/**
+ * Parse account restriction.
+ *
+ * @param args the array of command-line arguments to process next
+ * @param[in,out] restrictions JSON array to update
+ * @return -1 on error, otherwise number of arguments from @a args that were used
+ */
+static int
+parse_restriction (char *const *args,
+ json_t *restrictions)
+{
+ if (NULL == args[0])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Restriction TYPE argument missing\n");
+ return -1;
+ }
+ if (0 == strcmp (args[0],
+ "deny"))
+ {
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ restrictions,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "deny"))));
+ return 1;
+ }
+ if (0 == strcmp (args[0],
+ "regex"))
+ {
+ json_t *i18n;
+ json_error_t err;
+
+ if ( (NULL == args[1]) ||
+ (NULL == args[2]) ||
+ (NULL == args[3]) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Mandatory arguments for restriction of type `regex' missing (REGEX, HINT, HINT-I18 required)\n");
+ return -1;
+ }
+ {
+ regex_t ex;
+
+ if (0 != regcomp (&ex,
+ args[1],
+ REG_NOSUB | REG_EXTENDED))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid regular expression `%s'\n",
+ args[1]);
+ return -1;
+ }
+ regfree (&ex);
+ }
+
+ i18n = json_loads (args[3],
+ JSON_REJECT_DUPLICATES,
+ &err);
+ if (NULL == i18n)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid JSON for restriction of type `regex': `%s` at %d\n",
+ args[3],
+ err.position);
+ return -1;
+ }
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ restrictions,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "regex"),
+ GNUNET_JSON_pack_string ("payto_regex",
+ args[1]),
+ GNUNET_JSON_pack_string ("human_hint",
+ args[2]),
+ GNUNET_JSON_pack_object_steal ("human_hint_i18n",
+ i18n)
+ )));
+ return 4;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Restriction TYPE `%s' unsupported\n",
+ args[0]);
+ return -1;
+}
+
+
+/**
* Add wire account.
*
* @param args the array of command-line arguments to process next;
@@ -2454,12 +3091,18 @@ do_add_wire (char *const *args)
struct TALER_MasterSignatureP master_sig_add;
struct TALER_MasterSignatureP master_sig_wire;
struct GNUNET_TIME_Timestamp now;
+ const char *conversion_url = NULL;
+ const char *bank_label = NULL;
+ int64_t priority = 0;
+ json_t *debit_restrictions;
+ json_t *credit_restrictions;
+ unsigned int num_args = 1;
if (NULL != in)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not adding wire account\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2467,7 +3110,7 @@ do_add_wire (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify a payto://-URI with this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2483,7 +3126,7 @@ do_add_wire (char *const *args)
"payto URI is malformed: %s\n",
msg);
GNUNET_free (msg);
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2499,29 +3142,160 @@ do_add_wire (char *const *args)
"payto:// URI `%s' is malformed\n",
args[0]);
global_ret = EXIT_INVALIDARGUMENT;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return;
}
GNUNET_free (wire_method);
}
+ debit_restrictions = json_array ();
+ GNUNET_assert (NULL != debit_restrictions);
+ credit_restrictions = json_array ();
+ GNUNET_assert (NULL != credit_restrictions);
+ while (NULL != args[num_args])
+ {
+ if (0 == strcmp (args[num_args],
+ "conversion-url"))
+ {
+ num_args++;
+ conversion_url = args[num_args];
+ if (NULL == conversion_url)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "'conversion-url' requires an argument\n");
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ if (! TALER_is_web_url (conversion_url))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "'conversion-url' must refer to HTTP(S) endpoint, `%s' is invalid\n",
+ conversion_url);
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ num_args++;
+ continue;
+ }
+ if (0 == strcmp (args[num_args],
+ "credit-restriction"))
+ {
+ int iret;
+
+ num_args++;
+ iret = parse_restriction (&args[num_args],
+ credit_restrictions);
+ if (iret <= 0)
+ {
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ num_args += iret;
+ continue;
+ }
+ if (0 == strcmp (args[num_args],
+ "debit-restriction"))
+ {
+ int iret;
+
+ num_args++;
+ iret = parse_restriction (&args[num_args],
+ debit_restrictions);
+ if (iret <= 0)
+ {
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ num_args += iret;
+ continue;
+ }
+ if (0 == strcmp (args[num_args],
+ "display-hint"))
+ {
+ long long p;
+ char dummy;
+
+ num_args++;
+ if ( (NULL == args[num_args]) ||
+ (NULL == args[num_args + 1]) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "'display-hint' requires at least two arguments (priority and label)\n");
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ if (1 != sscanf (args[num_args],
+ "%lld%c",
+ &p,
+ &dummy))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Priority argument `%s' is not a number\n",
+ args[num_args]);
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ json_decref (debit_restrictions);
+ json_decref (credit_restrictions);
+ return;
+ }
+ priority = (int64_t) p;
+ num_args++;
+ bank_label = args[num_args];
+ num_args++;
+ continue;
+ }
+ break;
+ }
TALER_exchange_offline_wire_add_sign (args[0],
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
now,
&master_priv,
&master_sig_add);
TALER_exchange_wire_signature_make (args[0],
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
&master_priv,
&master_sig_wire);
output_operation (OP_ENABLE_WIRE,
GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("payto_uri",
args[0]),
+ GNUNET_JSON_pack_array_steal ("debit_restrictions",
+ debit_restrictions),
+ GNUNET_JSON_pack_array_steal ("credit_restrictions",
+ credit_restrictions),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("conversion_url",
+ conversion_url)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("bank_label",
+ bank_label)),
+ GNUNET_JSON_pack_int64 ("priority",
+ priority),
GNUNET_JSON_pack_timestamp ("validity_start",
now),
GNUNET_JSON_pack_data_auto ("master_sig_add",
&master_sig_add),
GNUNET_JSON_pack_data_auto ("master_sig_wire",
&master_sig_wire)));
- next (args + 1);
+ next (args + num_args);
}
@@ -2541,7 +3315,7 @@ do_del_wire (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not deleting wire account\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2549,7 +3323,7 @@ do_del_wire (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must specify a payto://-URI with this subcommand\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2578,7 +3352,7 @@ do_del_wire (char *const *args)
*
* @param args the array of command-line arguments to process next;
* args[0] must be the year, args[1] the wire method, args[2] the wire fee and args[3]
- * the closing fee and args[4] the wad fee.
+ * the closing fee.
*/
static void
do_set_wire_fee (char *const *args)
@@ -2594,7 +3368,7 @@ do_set_wire_fee (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not setting wire fee\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2602,7 +3376,6 @@ do_set_wire_fee (char *const *args)
(NULL == args[1]) ||
(NULL == args[2]) ||
(NULL == args[3]) ||
- (NULL == args[4]) ||
( (1 != sscanf (args[0],
"%u%c",
&year,
@@ -2614,14 +3387,11 @@ do_set_wire_fee (char *const *args)
&fees.wire)) ||
(GNUNET_OK !=
TALER_string_to_amount (args[3],
- &fees.closing)) ||
- (GNUNET_OK !=
- TALER_string_to_amount (args[4],
- &fees.wad)) )
+ &fees.closing)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "You must use YEAR, METHOD, WIRE-FEE, CLOSING-FEE and WAD-FEE as arguments for this subcommand\n");
- test_shutdown ();
+ "You must use YEAR, METHOD, WIRE-FEE, and CLOSING-FEE as arguments for this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2652,13 +3422,11 @@ do_set_wire_fee (char *const *args)
end_time),
TALER_JSON_pack_amount ("wire_fee",
&fees.wire),
- TALER_JSON_pack_amount ("wad_fee",
- &fees.wad),
TALER_JSON_pack_amount ("closing_fee",
&fees.closing),
GNUNET_JSON_pack_data_auto ("master_sig",
&master_sig)));
- next (args + 5);
+ next (args + 4);
}
@@ -2666,9 +3434,9 @@ do_set_wire_fee (char *const *args)
* Set global fees for the given year.
*
* @param args the array of command-line arguments to process next;
- * args[0] must be the year, args[1] the history fee, args[2] the kyc fee, args[3]
- * the account fee and args[4] the purse fee. These are followed by args[5] purse timeout,
- * args[6] kyc timeout and args[7] history expiration. Last is args[8] the (free) purse account limit.
+ * args[0] must be the year, args[1] the history fee, args[2]
+ * the account fee and args[3] the purse fee. These are followed by args[4] purse timeout,
+ * args[5] history expiration. Last is args[6] the (free) purse account limit.
*/
static void
do_set_global_fee (char *const *args)
@@ -2678,7 +3446,6 @@ do_set_global_fee (char *const *args)
unsigned int year;
struct TALER_GlobalFeeSet fees;
struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
struct GNUNET_TIME_Relative history_expiration;
unsigned int purse_account_limit;
struct GNUNET_TIME_Timestamp start_time;
@@ -2688,7 +3455,7 @@ do_set_global_fee (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Downloaded data was not consumed, not setting global fee\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2698,44 +3465,64 @@ do_set_global_fee (char *const *args)
(NULL == args[3]) ||
(NULL == args[4]) ||
(NULL == args[5]) ||
- (NULL == args[6]) ||
- (NULL == args[7]) ||
- (NULL == args[8]) ||
- ( (1 != sscanf (args[0],
- "%u%c",
- &year,
- &dummy)) &&
- (0 != strcasecmp ("now",
- args[0])) ) ||
- (GNUNET_OK !=
+ (NULL == args[6]) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must use YEAR, HISTORY-FEE, ACCOUNT-FEE, PURSE-FEE, PURSE-TIMEOUT, HISTORY-EXPIRATION and PURSE-ACCOUNT-LIMIT as arguments for this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (1 != sscanf (args[0],
+ "%u%c",
+ &year,
+ &dummy)) &&
+ (0 != strcasecmp ("now",
+ args[0])) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid YEAR given for 'global-fee' subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (GNUNET_OK !=
TALER_string_to_amount (args[1],
&fees.history)) ||
(GNUNET_OK !=
TALER_string_to_amount (args[2],
- &fees.kyc)) ||
- (GNUNET_OK !=
- TALER_string_to_amount (args[3],
&fees.account)) ||
(GNUNET_OK !=
- TALER_string_to_amount (args[4],
- &fees.purse)) ||
- (GNUNET_OK !=
- GNUNET_STRINGS_fancy_time_to_relative (args[5],
+ TALER_string_to_amount (args[3],
+ &fees.purse)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid amount given for 'global-fee' subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (args[4],
&purse_timeout)) ||
(GNUNET_OK !=
- GNUNET_STRINGS_fancy_time_to_relative (args[6],
- &kyc_timeout)) ||
- (GNUNET_OK !=
- GNUNET_STRINGS_fancy_time_to_relative (args[7],
- &history_expiration)) ||
- (1 != sscanf (args[8],
- "%u%c",
- &purse_account_limit,
- &dummy)) )
+ GNUNET_STRINGS_fancy_time_to_relative (args[5],
+ &history_expiration)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "You must use YEAR, HISTORY-FEE, KYC-FEE, ACCOUNT-FEE, PURSE-FEE, PURSE-TIMEOUT, KYC-TIMEOUT, HISTORY-EXPIRATION and PURSE-ACCOUNT-LIMIT as arguments for this subcommand\n");
- test_shutdown ();
+ "Invalid delay given for 'global-fee' subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if (1 != sscanf (args[6],
+ "%u%c",
+ &purse_account_limit,
+ &dummy))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid purse account limit given for 'global-fee' subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
@@ -2754,7 +3541,6 @@ do_set_global_fee (char *const *args)
end_time,
&fees,
purse_timeout,
- kyc_timeout,
history_expiration,
(uint32_t) purse_account_limit,
&master_priv,
@@ -2767,23 +3553,382 @@ do_set_global_fee (char *const *args)
end_time),
TALER_JSON_pack_amount ("history_fee",
&fees.history),
- TALER_JSON_pack_amount ("kyc_fee",
- &fees.kyc),
TALER_JSON_pack_amount ("account_fee",
&fees.account),
TALER_JSON_pack_amount ("purse_fee",
&fees.purse),
GNUNET_JSON_pack_time_rel ("purse_timeout",
purse_timeout),
- GNUNET_JSON_pack_time_rel ("kyc_timeout",
- kyc_timeout),
GNUNET_JSON_pack_time_rel ("history_expiration",
history_expiration),
GNUNET_JSON_pack_uint64 ("purse_account_limit",
(uint32_t) purse_account_limit),
GNUNET_JSON_pack_data_auto ("master_sig",
&master_sig)));
- next (args + 9);
+ next (args + 7);
+}
+
+
+/**
+ * Drain profits from exchange's escrow account to
+ * regular exchange account.
+ *
+ * @param args the array of command-line arguments to process next;
+ * args[0] must be the amount,
+ * args[1] must be the section of the escrow account to drain
+ * args[2] must be the payto://-URI of the target account
+ */
+static void
+do_drain (char *const *args)
+{
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct GNUNET_TIME_Timestamp date;
+ struct TALER_Amount amount;
+ const char *account_section;
+ const char *payto_uri;
+ struct TALER_MasterSignatureP master_sig;
+ char *err;
+
+ if (NULL != in)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Downloaded data was not consumed, refusing drain\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ if ( (NULL == args[0]) ||
+ (NULL == args[1]) ||
+ (NULL == args[2]) ||
+ (GNUNET_OK !=
+ TALER_string_to_amount (args[0],
+ &amount)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Drain requires an amount, section name and target payto://-URI as arguments\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (NULL == args[0]) ||
+ (NULL == args[1]) ||
+ (NULL == args[2]) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Drain requires an amount, section name and target payto://-URI as arguments\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_string_to_amount (args[0],
+ &amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid amount `%s' specified for drain\n",
+ args[0]);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ account_section = args[1];
+ payto_uri = args[2];
+ err = TALER_payto_validate (payto_uri);
+ if (NULL != err)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid payto://-URI `%s' specified for drain: %s\n",
+ payto_uri,
+ err);
+ GNUNET_free (err);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if (GNUNET_OK !=
+ load_offline_key (GNUNET_NO))
+ return;
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &wtid,
+ sizeof (wtid));
+ date = GNUNET_TIME_timestamp_get ();
+ TALER_exchange_offline_profit_drain_sign (&wtid,
+ date,
+ &amount,
+ account_section,
+ payto_uri,
+ &master_priv,
+ &master_sig);
+ output_operation (OP_DRAIN_PROFITS,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &wtid),
+ GNUNET_JSON_pack_string ("account_section",
+ account_section),
+ GNUNET_JSON_pack_string ("payto_uri",
+ payto_uri),
+ TALER_JSON_pack_amount ("amount",
+ &amount),
+ GNUNET_JSON_pack_timestamp ("date",
+ date),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &master_sig)));
+ next (args + 3);
+}
+
+
+/**
+ * Add partner.
+ *
+ * @param args the array of command-line arguments to process next;
+ * args[0] must be the partner's master public key, args[1] the partner's
+ * API base URL, args[2] the wad fee, args[3] the wad frequency, and
+ * args[4] the year (including possibly 'now')
+ */
+static void
+do_add_partner (char *const *args)
+{
+ struct TALER_MasterPublicKeyP partner_pub;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct GNUNET_TIME_Relative wad_frequency;
+ struct TALER_Amount wad_fee;
+ const char *partner_base_url;
+ struct TALER_MasterSignatureP master_sig;
+ char dummy;
+ unsigned int year;
+
+ if (NULL != in)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Downloaded data was not consumed, not adding partner\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &partner_pub,
+ sizeof (partner_pub))) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must specify the partner master public key as first argument for this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (NULL == args[1]) ||
+ (0 != strncmp ("http",
+ args[1],
+ strlen ("http"))) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must specify the partner's base URL as the 2nd argument to this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ partner_base_url = args[1];
+ if ( (NULL == args[2]) ||
+ (GNUNET_OK !=
+ TALER_string_to_amount (args[2],
+ &wad_fee)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid amount `%s' specified for wad fee of partner\n",
+ args[2]);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (NULL == args[3]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_fancy_time_to_relative (args[3],
+ &wad_frequency)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid wad frequency `%s' specified for add partner\n",
+ args[3]);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if ( (NULL == args[4]) ||
+ ( (1 != sscanf (args[4],
+ "%u%c",
+ &year,
+ &dummy)) &&
+ (0 != strcasecmp ("now",
+ args[4])) ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid year `%s' specified for add partner\n",
+ args[4]);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if (0 == strcasecmp ("now",
+ args[4]))
+ year = GNUNET_TIME_get_current_year ();
+ start_date = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_year_to_time (year));
+ end_date = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_year_to_time (year + 1));
+
+ if (GNUNET_OK !=
+ load_offline_key (GNUNET_NO))
+ return;
+ TALER_exchange_offline_partner_details_sign (&partner_pub,
+ start_date,
+ end_date,
+ wad_frequency,
+ &wad_fee,
+ partner_base_url,
+ &master_priv,
+ &master_sig);
+ output_operation (OP_ADD_PARTNER,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("partner_base_url",
+ partner_base_url),
+ GNUNET_JSON_pack_time_rel ("wad_frequency",
+ wad_frequency),
+ GNUNET_JSON_pack_timestamp ("start_date",
+ start_date),
+ GNUNET_JSON_pack_timestamp ("end_date",
+ end_date),
+ GNUNET_JSON_pack_data_auto ("partner_pub",
+ &partner_pub),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &master_sig)));
+ next (args + 5);
+}
+
+
+/**
+ * Enable or disable AML staff.
+ *
+ * @param is_active true to enable, false to disable
+ * @param args the array of command-line arguments to process next; args[0] must be the AML staff's public key, args[1] the AML staff's legal name, and if @a is_active then args[2] rw (read write) or ro (read only)
+ */
+static void
+do_set_aml_staff (bool is_active,
+ char *const *args)
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ const char *officer_name;
+ bool read_only;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_TIME_Timestamp now
+ = GNUNET_TIME_timestamp_get ();
+
+ if (NULL != in)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Downloaded data was not consumed, not updating AML staff status\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &officer_pub,
+ sizeof (officer_pub))) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must specify the AML officer's public key as first argument for this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ if (NULL == args[1])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must specify the officer's legal name as the 2nd argument to this subcommand\n");
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ officer_name = args[1];
+ if (is_active)
+ {
+ if ( (NULL == args[2]) ||
+ ( (0 != strcmp (args[2],
+ "ro")) &&
+ (0 != strcmp (args[2],
+ "rw")) ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "You must specify 'ro' or 'rw' (and not `%s') for the access level\n",
+ args[2]);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ read_only = (0 == strcmp (args[2],
+ "ro"));
+ }
+ else
+ {
+ read_only = true;
+ }
+ if (GNUNET_OK !=
+ load_offline_key (GNUNET_NO))
+ return;
+ TALER_exchange_offline_aml_officer_status_sign (&officer_pub,
+ officer_name,
+ now,
+ is_active,
+ read_only,
+ &master_priv,
+ &master_sig);
+ output_operation (OP_UPDATE_AML_STAFF,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("officer_name",
+ officer_name),
+ GNUNET_JSON_pack_timestamp ("change_date",
+ now),
+ GNUNET_JSON_pack_bool ("is_active",
+ is_active),
+ GNUNET_JSON_pack_bool ("read_only",
+ read_only),
+ GNUNET_JSON_pack_data_auto ("officer_pub",
+ &officer_pub),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &master_sig)));
+ next (args + (is_active ? 3 : 2));
+}
+
+
+/**
+ * Disable AML staff.
+ *
+ * @param args the array of command-line arguments to process next;
+ * args[0] must be the AML staff's public key, args[1] the AML staff's legal name, args[2] rw (read write) or ro (read only)
+ */
+static void
+disable_aml_staff (char *const *args)
+{
+ do_set_aml_staff (false,
+ args);
+}
+
+
+/**
+ * Enable AML staff.
+ *
+ * @param args the array of command-line arguments to process next;
+ * args[0] must be the AML staff's public key, args[1] the AML staff's legal name, args[2] rw (read write) or ro (read only)
+ */
+static void
+enable_aml_staff (char *const *args)
+{
+ do_set_aml_staff (true,
+ args);
}
@@ -2793,18 +3938,15 @@ do_set_global_fee (char *const *args)
* whether there are subsequent commands).
*
* @param cls closure with the `char **` remaining args
- * @param hr HTTP response data
- * @param keys information about the various keys used
- * by the exchange, NULL if /management/keys failed
+ * @param mgr response data
*/
static void
download_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_FutureKeys *keys)
+ const struct TALER_EXCHANGE_ManagementGetKeysResponse *mgr)
{
char *const *args = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &mgr->hr;
- (void) keys;
mgkh = NULL;
switch (hr->http_status)
{
@@ -2822,7 +3964,7 @@ download_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to download keys from `%s' (no HTTP response)\n",
CFG_exchange_url);
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_FAILURE;
return;
}
@@ -2861,7 +4003,7 @@ do_download (char *const *args)
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchange",
"BASE_URL");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_NOTCONFIGURED;
return;
}
@@ -3069,7 +4211,7 @@ tofu_check (const struct TALER_SecurityModulePublicKeySetP *secmset)
* @param signkeys keys to output
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
show_signkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub,
const json_t *signkeys)
{
@@ -3114,7 +4256,7 @@ show_signkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
duration = GNUNET_TIME_absolute_get_difference (start_time.abs_time,
@@ -3130,7 +4272,7 @@ show_signkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub,
"Invalid security module signature for signing key %s (aborting)\n",
TALER_B2S (&exchange_pub));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
{
@@ -3222,7 +4364,7 @@ show_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
JSON_INDENT (2));
GNUNET_JSON_parse_free (spec);
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
duration = GNUNET_TIME_absolute_get_difference (
@@ -3230,13 +4372,13 @@ show_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
stamp_expire_withdraw.abs_time);
TALER_denom_pub_hash (&denom_pub,
&h_denom_pub);
- switch (denom_pub.cipher)
+ switch (denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct TALER_RsaPubHashP h_rsa;
- TALER_rsa_pub_hash (denom_pub.details.rsa_public_key,
+ TALER_rsa_pub_hash (denom_pub.bsign_pub_key->details.rsa_public_key,
&h_rsa);
ok = TALER_exchange_secmod_rsa_verify (&h_rsa,
section_name,
@@ -3246,11 +4388,11 @@ show_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
&secm_sig);
}
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct TALER_CsPubHashP h_cs;
- TALER_cs_pub_hash (&denom_pub.details.cs_public_key,
+ TALER_cs_pub_hash (&denom_pub.bsign_pub_key->details.cs_public_key,
&h_cs);
ok = TALER_exchange_secmod_cs_verify (&h_cs,
section_name,
@@ -3271,7 +4413,7 @@ show_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
"Invalid security module signature for denomination key %s (aborting)\n",
GNUNET_h2s (&h_denom_pub.hash));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
@@ -3358,7 +4500,7 @@ parse_keys_input (const char *command_name)
err.source,
err.position);
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return NULL;
}
}
@@ -3377,7 +4519,7 @@ parse_keys_input (const char *command_name)
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return NULL;
}
if (0 != strcmp (op_str,
@@ -3408,15 +4550,15 @@ do_show (char *const *args)
json_t *keys;
const char *err_name;
unsigned int err_line;
- json_t *denomkeys;
- json_t *signkeys;
+ const json_t *denomkeys;
+ const json_t *signkeys;
struct TALER_MasterPublicKeyP mpub;
struct TALER_SecurityModulePublicKeySetP secmset;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("future_denoms",
- &denomkeys),
- GNUNET_JSON_spec_json ("future_signkeys",
- &signkeys),
+ GNUNET_JSON_spec_array_const ("future_denoms",
+ &denomkeys),
+ GNUNET_JSON_spec_array_const ("future_signkeys",
+ &signkeys),
GNUNET_JSON_spec_fixed_auto ("master_pub",
&mpub),
GNUNET_JSON_spec_fixed_auto ("denom_secmod_public_key",
@@ -3449,7 +4591,7 @@ do_show (char *const *args)
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3460,8 +4602,7 @@ do_show (char *const *args)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Fatal: exchange uses different master key!\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
- GNUNET_JSON_parse_free (spec);
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3469,8 +4610,7 @@ do_show (char *const *args)
tofu_check (&secmset))
{
global_ret = EXIT_FAILURE;
- test_shutdown ();
- GNUNET_JSON_parse_free (spec);
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3483,13 +4623,11 @@ do_show (char *const *args)
denomkeys)) )
{
global_ret = EXIT_FAILURE;
- test_shutdown ();
- GNUNET_JSON_parse_free (spec);
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
json_decref (keys);
- GNUNET_JSON_parse_free (spec);
next (args);
}
@@ -3548,7 +4686,7 @@ sign_signkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub,
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
@@ -3565,7 +4703,7 @@ sign_signkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub,
"Invalid security module signature for signing key %s (aborting)\n",
TALER_B2S (&exchange_pub));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -3606,7 +4744,7 @@ load_age_mask (const char*section_name)
static const struct TALER_AgeMask null_mask = {0};
enum GNUNET_GenericReturnValue ret;
- if (age_mask.bits == 0)
+ if (! ar_enabled)
return null_mask;
if (GNUNET_OK != (GNUNET_CONFIGURATION_have_value (
@@ -3618,14 +4756,14 @@ load_age_mask (const char*section_name)
ret = GNUNET_CONFIGURATION_get_value_yesno (kcfg,
section_name,
"AGE_RESTRICTED");
- if (GNUNET_YES == ret)
- return age_mask;
-
if (GNUNET_SYSERR == ret)
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
section_name,
"AGE_RESTRICTED",
"Value must be YES or NO\n");
+ if (GNUNET_YES == ret)
+ return ar_config.mask;
+
return null_mask;
}
@@ -3702,7 +4840,7 @@ sign_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
JSON_INDENT (2));
GNUNET_JSON_parse_free (spec);
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
duration = GNUNET_TIME_absolute_get_difference (
@@ -3714,13 +4852,14 @@ sign_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
TALER_denom_pub_hash (&denom_pub,
&h_denom_pub);
- switch (denom_pub.cipher)
+
+ switch (denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct TALER_RsaPubHashP h_rsa;
- TALER_rsa_pub_hash (denom_pub.details.rsa_public_key,
+ TALER_rsa_pub_hash (denom_pub.bsign_pub_key->details.rsa_public_key,
&h_rsa);
if (GNUNET_OK !=
TALER_exchange_secmod_rsa_verify (&h_rsa,
@@ -3734,17 +4873,17 @@ sign_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
"Invalid security module signature for denomination key %s (aborting)\n",
GNUNET_h2s (&h_denom_pub.hash));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
}
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct TALER_CsPubHashP h_cs;
- TALER_cs_pub_hash (&denom_pub.details.cs_public_key,
+ TALER_cs_pub_hash (&denom_pub.bsign_pub_key->details.cs_public_key,
&h_cs);
if (GNUNET_OK !=
TALER_exchange_secmod_cs_verify (&h_cs,
@@ -3758,7 +4897,7 @@ sign_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
"Invalid security module signature for denomination key %s (aborting)\n",
GNUNET_h2s (&h_denom_pub.hash));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -3766,7 +4905,7 @@ sign_denomkeys (const struct TALER_SecurityModulePublicKeyP *secm_pub_rsa,
break;
default:
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -3809,15 +4948,15 @@ do_sign (char *const *args)
json_t *keys;
const char *err_name;
unsigned int err_line;
- json_t *denomkeys;
- json_t *signkeys;
+ const json_t *denomkeys;
+ const json_t *signkeys;
struct TALER_MasterPublicKeyP mpub;
struct TALER_SecurityModulePublicKeySetP secmset;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("future_denoms",
- &denomkeys),
- GNUNET_JSON_spec_json ("future_signkeys",
- &signkeys),
+ GNUNET_JSON_spec_array_const ("future_denoms",
+ &denomkeys),
+ GNUNET_JSON_spec_array_const ("future_signkeys",
+ &signkeys),
GNUNET_JSON_spec_fixed_auto ("master_pub",
&mpub),
GNUNET_JSON_spec_fixed_auto ("denom_secmod_public_key",
@@ -3852,7 +4991,7 @@ do_sign (char *const *args)
stderr,
JSON_INDENT (2));
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3863,8 +5002,7 @@ do_sign (char *const *args)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Fatal: exchange uses different master key!\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
- GNUNET_JSON_parse_free (spec);
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3874,8 +5012,7 @@ do_sign (char *const *args)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Fatal: security module keys changed!\n");
global_ret = EXIT_FAILURE;
- test_shutdown ();
- GNUNET_JSON_parse_free (spec);
+ GNUNET_SCHEDULER_shutdown ();
json_decref (keys);
return;
}
@@ -3896,10 +5033,9 @@ do_sign (char *const *args)
denomkey_sig_array)) )
{
global_ret = EXIT_FAILURE;
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
json_decref (signkey_sig_array);
json_decref (denomkey_sig_array);
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
return;
}
@@ -3911,7 +5047,6 @@ do_sign (char *const *args)
GNUNET_JSON_pack_array_steal ("signkey_sigs",
signkey_sig_array)));
}
- GNUNET_JSON_parse_free (spec);
json_decref (keys);
next (args);
}
@@ -3958,84 +5093,118 @@ do_setup (char *const *args)
}
-/*
+/**
* Print the current extensions as configured
+ *
+ * @param args the array of command-line arguments to process next
*/
static void
do_extensions_show (char *const *args)
{
-
- json_t *obj = json_object ();
+ const struct TALER_Extensions *it;
json_t *exts = json_object ();
- const struct TALER_Extension *it;
+ json_t *obj;
+ GNUNET_assert (NULL != exts);
for (it = TALER_extensions_get_head ();
- NULL != it;
+ NULL != it && NULL != it->extension;
it = it->next)
- json_object_set (exts, it->name, it->config_to_json (it));
-
- json_object_set (obj, "extensions", exts);
+ {
+ const struct TALER_Extension *extension = it->extension;
+ int ret;
- GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "%s\n",
- json_dumps (obj, JSON_INDENT (2)));
+ ret = json_object_set_new (exts,
+ extension->name,
+ extension->manifest (extension));
+ GNUNET_assert (-1 != ret);
+ }
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_steal ("extensions",
+ exts));
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "%s\n",
+ json_dumps (obj,
+ JSON_INDENT (2)));
json_decref (obj);
+ next (args);
}
-/*
+/**
* Sign the configurations of the enabled extensions
*/
static void
do_extensions_sign (char *const *args)
{
- json_t *obj = json_object ();
json_t *extensions = json_object ();
- struct TALER_ExtensionConfigHashP h_config;
+ struct TALER_ExtensionManifestsHashP h_manifests;
struct TALER_MasterSignatureP sig;
- const struct TALER_Extension *it;
+ const struct TALER_Extensions *it;
+ bool found = false;
+ json_t *obj;
- if (GNUNET_OK != TALER_extensions_load_taler_config (kcfg))
+ GNUNET_assert (NULL != extensions);
+ for (it = TALER_extensions_get_head ();
+ NULL != it && NULL != it->extension;
+ it = it->next)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "error while loading taler config for extensions\n");
- return;
+ const struct TALER_Extension *ext = it->extension;
+ GNUNET_assert (ext);
+
+ found = true;
+
+ GNUNET_assert (0 ==
+ json_object_set_new (extensions,
+ ext->name,
+ ext->manifest (ext)));
}
- for (it = TALER_extensions_get_head ();
- NULL != it;
- it = it->next)
- json_object_set (extensions, it->name, it->config_to_json (it));
+ if (! found)
+ return;
if (GNUNET_OK !=
- TALER_JSON_extensions_config_hash (extensions, &h_config))
+ TALER_JSON_extensions_manifests_hash (extensions,
+ &h_manifests))
{
+ json_decref (extensions);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "error while hashing config for extensions\n");
+ "error while hashing manifest for extensions\n");
return;
}
if (GNUNET_OK !=
load_offline_key (GNUNET_NO))
+ {
+ json_decref (extensions);
return;
+ }
-
- TALER_exchange_offline_extension_config_hash_sign (&h_config,
- &master_priv,
- &sig);
- json_object_set (obj, "extensions", extensions);
- json_object_update (obj,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto (
- "extensions_sig",
- &sig)));
-
- output_operation (OP_EXTENSIONS, obj);
+ TALER_exchange_offline_extension_manifests_hash_sign (&h_manifests,
+ &master_priv,
+ &sig);
+ obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_steal ("extensions",
+ extensions),
+ GNUNET_JSON_pack_data_auto (
+ "extensions_sig",
+ &sig));
+
+ output_operation (OP_EXTENSIONS,
+ obj);
+ next (args);
}
+/**
+ * Dispatch @a args in the @a cmds array.
+ *
+ * @param args arguments with subcommand to dispatch
+ * @param cmds array of possible subcommands to call
+ */
static void
-cmd_handler (char *const *args, const struct SubCommand *cmds)
+cmd_handler (char *const *args,
+ const struct SubCommand *cmds)
{
nxt = NULL;
for (unsigned int i = 0; NULL != cmds[i].name; i++)
@@ -4066,6 +5235,9 @@ cmd_handler (char *const *args, const struct SubCommand *cmds)
cmds[i].name,
cmds[i].help);
}
+ json_decref (out);
+ out = NULL;
+ GNUNET_SCHEDULER_shutdown ();
}
@@ -4094,13 +5266,12 @@ do_work_extensions (char *const *args)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"You must provide a subcommand: `show` or `sign`.\n");
- test_shutdown ();
+ GNUNET_SCHEDULER_shutdown ();
global_ret = EXIT_INVALIDARGUMENT;
return;
}
cmd_handler (args, cmds);
- next (args + 1);
}
@@ -4159,7 +5330,7 @@ work (void *cls)
{
.name = "enable-account",
.help =
- "enable wire account of the exchange (payto-URI must be given as argument)",
+ "enable wire account of the exchange (payto-URI must be given as argument; for optional arguments see man page)",
.cb = &do_add_wire
},
{
@@ -4171,16 +5342,40 @@ work (void *cls)
{
.name = "wire-fee",
.help =
- "sign wire fees for the given year (year, wire method, wire fee, closing fee and wad fee must be given as arguments)",
+ "sign wire fees for the given year (year, wire method, wire fee, and closing fee must be given as arguments)",
.cb = &do_set_wire_fee
},
{
.name = "global-fee",
.help =
- "sign global fees for the given year (year, history fee, kyc fee, account fee, purse fee, purse timeout, kyc timeout, history expiration and the maximum number of free purses per account must be given as arguments)",
+ "sign global fees for the given year (year, history fee, account fee, purse fee, purse timeout, history expiration and the maximum number of free purses per account must be given as arguments)",
.cb = &do_set_global_fee
},
{
+ .name = "drain",
+ .help =
+ "drain profits from exchange escrow account to regular exchange operator account (amount, debit account configuration section and credit account payto://-URI must be given as arguments)",
+ .cb = &do_drain
+ },
+ {
+ .name = "add-partner",
+ .help =
+ "add partner exchange for P2P wad transfers (partner master public key, partner base URL, wad fee, wad frequency and validity year must be given as arguments)",
+ .cb = &do_add_partner
+ },
+ {
+ .name = "aml-enable",
+ .help =
+ "enable AML staff member (staff member public key, legal name and rw (read write) or ro (read only) must be given as arguments)",
+ .cb = &enable_aml_staff
+ },
+ {
+ .name = "aml-disable",
+ .help =
+ "disable AML staff member (staff member public key and legal name must be given as arguments)",
+ .cb = &disable_aml_staff
+ },
+ {
.name = "upload",
.help =
"upload operation result to exchange (to be performed online!)",
@@ -4219,25 +5414,31 @@ run (void *cls,
(void) cls;
(void) cfgfile;
kcfg = cfg;
- if (GNUNET_OK !=
- TALER_config_get_currency (kcfg,
- &currency))
+
+ /* load extensions */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_extensions_init (kcfg));
+
+ /* setup age restriction, if applicable */
{
- global_ret = EXIT_NOTCONFIGURED;
- return;
+ const struct TALER_AgeRestrictionConfig *arc;
+
+ if (NULL !=
+ (arc = TALER_extensions_get_age_restriction_config ()))
+ {
+ ar_config = *arc;
+ ar_enabled = true;
+ }
}
- /* load age mask, if age restriction is enabled */
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
- if (GNUNET_OK != TALER_extensions_load_taler_config (kcfg))
+ if (GNUNET_OK !=
+ TALER_config_get_currency (kcfg,
+ &currency))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "error while loading taler config for extensions\n");
+ global_ret = EXIT_NOTCONFIGURED;
return;
}
- age_mask = TALER_extensions_age_restriction_ageMask ();
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
&rc);
diff --git a/src/exchange/Makefile.am b/src/exchange/Makefile.am
index eb607ddfc..1c0c2c684 100644
--- a/src/exchange/Makefile.am
+++ b/src/exchange/Makefile.am
@@ -15,10 +15,13 @@ pkgcfg_DATA = \
exchange.conf
# Programs
+bin_SCRIPTS = \
+ taler-exchange-kyc-aml-pep-trigger.sh
bin_PROGRAMS = \
taler-exchange-aggregator \
taler-exchange-closer \
+ taler-exchange-drain \
taler-exchange-expire \
taler-exchange-httpd \
taler-exchange-router \
@@ -29,6 +32,7 @@ taler_exchange_aggregator_SOURCES = \
taler-exchange-aggregator.c
taler_exchange_aggregator_LDADD = \
$(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/kyclogic/libtalerkyclogic.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
@@ -52,6 +56,19 @@ taler_exchange_closer_LDADD = \
-lgnunetutil \
$(XLIB)
+taler_exchange_drain_SOURCES = \
+ taler-exchange-drain.c
+taler_exchange_drain_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \
+ -ljansson \
+ -lgnunetcurl \
+ -lgnunetutil \
+ $(XLIB)
+
taler_exchange_expire_SOURCES = \
taler-exchange-expire.c
taler_exchange_expire_LDADD = \
@@ -107,27 +124,38 @@ taler_exchange_wirewatch_LDADD = \
taler_exchange_httpd_SOURCES = \
taler-exchange-httpd.c taler-exchange-httpd.h \
+ taler-exchange-httpd_age-withdraw.c taler-exchange-httpd_age-withdraw.h \
+ taler-exchange-httpd_age-withdraw_reveal.c taler-exchange-httpd_age-withdraw_reveal.h \
taler-exchange-httpd_auditors.c taler-exchange-httpd_auditors.h \
+ taler-exchange-httpd_aml-decision.c taler-exchange-httpd_aml-decision.h \
+ taler-exchange-httpd_aml-decision-get.c \
+ taler-exchange-httpd_aml-decisions-get.c \
taler-exchange-httpd_batch-deposit.c taler-exchange-httpd_batch-deposit.h \
taler-exchange-httpd_batch-withdraw.c taler-exchange-httpd_batch-withdraw.h \
+ taler-exchange-httpd_coins_get.c taler-exchange-httpd_coins_get.h \
taler-exchange-httpd_common_deposit.c taler-exchange-httpd_common_deposit.h \
+ taler-exchange-httpd_common_kyc.c taler-exchange-httpd_common_kyc.h \
+ taler-exchange-httpd_config.c taler-exchange-httpd_config.h \
taler-exchange-httpd_contract.c taler-exchange-httpd_contract.h \
taler-exchange-httpd_csr.c taler-exchange-httpd_csr.h \
taler-exchange-httpd_db.c taler-exchange-httpd_db.h \
- taler-exchange-httpd_deposit.c taler-exchange-httpd_deposit.h \
taler-exchange-httpd_deposits_get.c taler-exchange-httpd_deposits_get.h \
taler-exchange-httpd_extensions.c taler-exchange-httpd_extensions.h \
taler-exchange-httpd_keys.c taler-exchange-httpd_keys.h \
taler-exchange-httpd_kyc-check.c taler-exchange-httpd_kyc-check.h \
taler-exchange-httpd_kyc-proof.c taler-exchange-httpd_kyc-proof.h \
taler-exchange-httpd_kyc-wallet.c taler-exchange-httpd_kyc-wallet.h \
+ taler-exchange-httpd_kyc-webhook.c taler-exchange-httpd_kyc-webhook.h \
taler-exchange-httpd_link.c taler-exchange-httpd_link.h \
taler-exchange-httpd_management.h \
+ taler-exchange-httpd_management_aml-officers.c \
taler-exchange-httpd_management_auditors.c \
taler-exchange-httpd_management_auditors_AP_disable.c \
taler-exchange-httpd_management_denominations_HDP_revoke.c \
+ taler-exchange-httpd_management_drain.c \
taler-exchange-httpd_management_extensions.c \
taler-exchange-httpd_management_global_fees.c \
+ taler-exchange-httpd_management_partners.c \
taler-exchange-httpd_management_post_keys.c \
taler-exchange-httpd_management_signkey_EP_revoke.c \
taler-exchange-httpd_management_wire_enable.c \
@@ -138,21 +166,24 @@ taler_exchange_httpd_SOURCES = \
taler-exchange-httpd_mhd.c taler-exchange-httpd_mhd.h \
taler-exchange-httpd_purses_create.c taler-exchange-httpd_purses_create.h \
taler-exchange-httpd_purses_deposit.c taler-exchange-httpd_purses_deposit.h \
+ taler-exchange-httpd_purses_delete.c taler-exchange-httpd_purses_delete.h \
taler-exchange-httpd_purses_get.c taler-exchange-httpd_purses_get.h \
taler-exchange-httpd_purses_merge.c taler-exchange-httpd_purses_merge.h \
taler-exchange-httpd_recoup.c taler-exchange-httpd_recoup.h \
taler-exchange-httpd_recoup-refresh.c taler-exchange-httpd_recoup-refresh.h \
taler-exchange-httpd_refreshes_reveal.c taler-exchange-httpd_refreshes_reveal.h \
taler-exchange-httpd_refund.c taler-exchange-httpd_refund.h \
+ taler-exchange-httpd_reserves_attest.c taler-exchange-httpd_reserves_attest.h \
+ taler-exchange-httpd_reserves_close.c taler-exchange-httpd_reserves_close.h \
taler-exchange-httpd_reserves_get.c taler-exchange-httpd_reserves_get.h \
+ taler-exchange-httpd_reserves_get_attest.c taler-exchange-httpd_reserves_get_attest.h \
taler-exchange-httpd_reserves_history.c taler-exchange-httpd_reserves_history.h \
+ taler-exchange-httpd_reserves_open.c taler-exchange-httpd_reserves_open.h \
taler-exchange-httpd_reserves_purse.c taler-exchange-httpd_reserves_purse.h \
- taler-exchange-httpd_reserves_status.c taler-exchange-httpd_reserves_status.h \
taler-exchange-httpd_responses.c taler-exchange-httpd_responses.h \
+ taler-exchange-httpd_spa.c taler-exchange-httpd_spa.h \
taler-exchange-httpd_terms.c taler-exchange-httpd_terms.h \
- taler-exchange-httpd_transfers_get.c taler-exchange-httpd_transfers_get.h \
- taler-exchange-httpd_wire.c taler-exchange-httpd_wire.h \
- taler-exchange-httpd_withdraw.c taler-exchange-httpd_withdraw.h
+ taler-exchange-httpd_transfers_get.c taler-exchange-httpd_transfers_get.h
taler_exchange_httpd_LDADD = \
$(LIBGCRYPT_LIBS) \
@@ -160,6 +191,8 @@ taler_exchange_httpd_LDADD = \
$(top_builddir)/src/mhd/libtalermhd.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \
+ $(top_builddir)/src/templating/libtalertemplating.la \
+ $(top_builddir)/src/kyclogic/libtalerkyclogic.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
-lmicrohttpd \
@@ -182,7 +215,6 @@ check_SCRIPTS += \
test_taler_exchange_httpd_afl.sh
endif
-.NOTPARALLEL:
TESTS = \
$(check_SCRIPTS)
@@ -195,4 +227,5 @@ EXTRA_DIST = \
test_taler_exchange_httpd.get \
test_taler_exchange_httpd.post \
exchange.conf \
+ $(bin_SCRIPTS) \
$(check_SCRIPTS)
diff --git a/src/exchange/exchange.conf b/src/exchange/exchange.conf
index 58e57c82e..ce471a292 100644
--- a/src/exchange/exchange.conf
+++ b/src/exchange/exchange.conf
@@ -6,6 +6,33 @@
# This must be adjusted to your actual installation.
# MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+# Must be set to the threshold above which transactions
+# are flagged for AML review.
+# AML_THRESHOLD =
+
+# How many digits does the currency use by default on displays.
+# Hint provided to wallets. Should be 2 for EUR/USD/CHF,
+# and 0 for JPY. Default is 2 as that is most common.
+# Maximum value is 8. Note that this is the number of
+# fractions shown in the wallet by default, it is still
+# possible to configure denominations with more digits
+# and those will then be rendered using 'tiny' fraction
+# capitals (like at gas stations) when present.
+CURRENCY_FRACTION_DIGITS = 2
+
+# Specifies a program (binary) to run on KYC attribute data to decide
+# whether we should immediately flag an account for AML review.
+# The KYC attribute data will be passed on standard-input.
+# Return non-zero to trigger AML review of the new user.
+KYC_AML_TRIGGER = true
+
+# Attribute encryption key for storing attributes encrypted
+# in the database. Should be a high-entropy nonce.
+ATTRIBUTE_ENCRYPTION_KEY = SET_ME_PLEASE
+
+# Set to NO to disable rewards.
+ENABLE_REWARDS = YES
+
# How long do we allow /keys to be cached at most? The actual
# limit is the minimum of this value and the first expected
# significant change in /keys based on the expiration times.
@@ -15,7 +42,7 @@ MAX_KEYS_CACHING = forever
# After how many requests should the exchange auto-restart
# (to address potential issues with memory fragmentation)?
# If this option is not specified, auto-restarting is disabled.
-# MAX_REQUESTS = 10000000
+# MAX_REQUESTS = 100000
# How to access our database
DB = postgres
@@ -40,13 +67,17 @@ PORT = 8081
# transfers to enable tracking.
BASE_URL = http://localhost:8081/
-# Maximum number of requests this process should handle before
-# committing suicide.
-# MAX_REQUESTS =
-
# How long should the aggregator sleep if it has nothing to do?
AGGREGATOR_IDLE_SLEEP_INTERVAL = 60 s
+# What type of asset is the exchange managing? Used to adjust
+# the user-interface of the wallet.
+# Possibilities include: "fiat", "regional" and "crypto".
+# In the future (and already permitted but not yet supported by wallets)
+# we also expect to have "stock" and "future" (and more).
+# Default is "fiat".
+ASSET_TYPE = "fiat"
+
# FIXME: document!
ROUTER_IDLE_SLEEP_INTERVAL = 60 s
@@ -54,7 +85,7 @@ ROUTER_IDLE_SLEEP_INTERVAL = 60 s
# by taler-exchange-expire (in time). It may take
# this much time for an expired purse to be really
# cleaned up and the coins refunded.
-EXPIRE_SHARD_SIZE = 1 h
+EXPIRE_SHARD_SIZE = 60 s
# How long should the transfer tool
# sleep if it has nothing to do?
@@ -95,42 +126,13 @@ WIREWATCH_IDLE_SLEEP_INTERVAL = 1 s
SIGNKEY_LEGAL_DURATION = 2 years
# Directory with our terms of service.
-TERMS_DIR = $DATADIR/exchange/tos/
+TERMS_DIR = $TALER_DATA_HOME/terms/
# Etag / filename for the terms of service.
-TERMS_ETAG = 0
+TERMS_ETAG = exchange-tos-v0
# Directory with our privacy policy.
-PRIVACY_DIR = $DATADIR/exchange/pp/
+PRIVACY_DIR = $TALER_DATA_HOME/terms/
# Etag / filename for the privacy policy.
-PRIVACY_ETAG = 0
-
-# Set to NONE to disable KYC checks.
-# Set to "OAUTH2" to use OAuth 2.0 for KYC authorization.
-KYC_MODE = NONE
-
-# Balance threshold above which wallets are told
-# to undergo a KYC check at the exchange. Optional,
-# if not given there is no limit.
-# KYC_WALLET_BALANCE_LIMIT = CURRENCY:150
-#
-# KYC_WITHDRAW_PERIOD = 1 month
-
-[exchange-kyc-oauth2]
-
-# URL of the OAuth endpoint for KYC checks
-# KYC_OAUTH2_URL =
-
-# URL of the "information" endpoint for KYC checks
-# KYC_INFO_URL =
-
-# KYC Oauth client ID.
-# KYC_OAUTH2_CLIENT_ID =
-
-# KYC Client secret used to obtain access tokens.
-# KYC_OAUTH2_CLIENT_SECRET =
-
-# Where to redirect clients after successful
-# authorization?
-# KYC_OAUTH2_POST_URL = https://bank.com/
+PRIVACY_ETAG = exchange-pp-v0
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index 9568f011e..691d65ae3 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2021 Taler Systems SA
+ Copyright (C) 2016-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -26,7 +26,9 @@
#include "taler_exchangedb_lib.h"
#include "taler_exchangedb_plugin.h"
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_bank_service.h"
+#include "taler_dbevents.h"
/**
@@ -43,6 +45,12 @@ struct AggregationUnit
struct TALER_MerchantPublicKeyP merchant_pub;
/**
+ * Transient amount already found aggregated,
+ * set only if @e have_transient is true.
+ */
+ struct TALER_Amount trans;
+
+ /**
* Total amount to be transferred, before subtraction of @e fees.wire and rounding down.
*/
struct TALER_Amount total_amount;
@@ -84,6 +92,25 @@ struct AggregationUnit
*/
const struct TALER_EXCHANGEDB_AccountInfo *wa;
+ /**
+ * Row in KYC table for legitimization requirements
+ * that are pending for this aggregation, or 0 if none.
+ */
+ uint64_t requirement_row;
+
+ /**
+ * Set to #GNUNET_OK during transient checking
+ * while everything is OK. Otherwise see return
+ * value of #do_aggregate().
+ */
+ enum GNUNET_GenericReturnValue ret;
+
+ /**
+ * Do we have an entry in the transient table for
+ * this aggregation?
+ */
+ bool have_transient;
+
};
@@ -123,6 +150,12 @@ struct Shard
static struct TALER_Amount currency_round_unit;
/**
+ * What is the largest amount we transfer before triggering
+ * an AML check?
+ */
+static struct TALER_Amount aml_threshold;
+
+/**
* What is the base URL of this exchange? Used in the
* wire transfer subjects so that merchants and governments
* can ask for the list of aggregated deposits.
@@ -151,7 +184,6 @@ static struct TALER_EXCHANGEDB_Plugin *db_plugin;
*/
static struct GNUNET_SCHEDULER_Task *task;
-
/**
* How long should we sleep when idle before trying to find more work?
*/
@@ -186,12 +218,12 @@ run_aggregation (void *cls);
/**
- * Select a shard to work on.
+ * Work on transactions unlocked by KYC.
*
* @param cls NULL
*/
static void
-run_shard (void *cls);
+drain_kyc_alerts (void *cls);
/**
@@ -226,6 +258,7 @@ shutdown_task (void *cls)
GNUNET_SCHEDULER_cancel (task);
task = NULL;
}
+ TALER_KYCLOGIC_kyc_done ();
TALER_EXCHANGEDB_plugin_unload (db_plugin);
db_plugin = NULL;
TALER_EXCHANGEDB_unload_accounts ();
@@ -234,12 +267,12 @@ shutdown_task (void *cls)
/**
- * Parse the configuration for wirewatch.
+ * Parse the configuration for aggregator.
*
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-parse_wirewatch_config (void)
+parse_aggregator_config (void)
{
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -268,11 +301,20 @@ parse_wirewatch_config (void)
"taler",
"CURRENCY_ROUND_UNIT",
&currency_round_unit)) ||
- ( (0 != currency_round_unit.fraction) &&
- (0 != currency_round_unit.value) ) )
+ (TALER_amount_is_zero (&currency_round_unit)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Need non-zero amount in section `taler' under `CURRENCY_ROUND_UNIT'\n");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ "exchange",
+ "AML_THRESHOLD",
+ &aml_threshold))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Need non-zero value in section `TALER' under `CURRENCY_ROUND_UNIT'\n");
+ "Need amount in section `exchange' under `AML_THRESHOLD'\n");
return GNUNET_SYSERR;
}
@@ -341,6 +383,7 @@ release_shard (struct Shard *s)
case GNUNET_DB_STATUS_SOFT_ERROR:
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
@@ -353,109 +396,286 @@ release_shard (struct Shard *s)
}
+/**
+ * Trigger the wire transfer for the @a au_active
+ * and delete the record of the aggregation.
+ *
+ * @param au_active information about the aggregation
+ */
+static enum GNUNET_DB_QueryStatus
+trigger_wire_transfer (const struct AggregationUnit *au_active)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Preparing wire transfer of %s to %s\n",
+ TALER_amount2s (&au_active->final_amount),
+ TALER_B2S (&au_active->merchant_pub));
+ {
+ void *buf;
+ size_t buf_size;
+
+ TALER_BANK_prepare_transfer (au_active->payto_uri,
+ &au_active->final_amount,
+ exchange_base_url,
+ &au_active->wtid,
+ &buf,
+ &buf_size);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing %u bytes of wire prepare data\n",
+ (unsigned int) buf_size);
+ /* Commit our intention to execute the wire transfer! */
+ qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
+ au_active->wa->method,
+ buf,
+ buf_size);
+ GNUNET_free (buf);
+ }
+ /* Commit the WTID data to 'wire_out' */
+ if (qs >= 0)
+ qs = db_plugin->store_wire_transfer_out (db_plugin->cls,
+ au_active->execution_time,
+ &au_active->wtid,
+ &au_active->h_payto,
+ au_active->wa->section_name,
+ &au_active->final_amount);
+
+ if ( (qs >= 0) &&
+ au_active->have_transient)
+ qs = db_plugin->delete_aggregation_transient (db_plugin->cls,
+ &au_active->h_payto,
+ &au_active->wtid);
+ return qs;
+}
+
+
+/**
+ * Callback to return all applicable amounts for the KYC
+ * decision to @ a cb.
+ *
+ * @param cls a `struct AggregationUnit *`
+ * @param limit time limit for the iteration
+ * @param cb function to call with the amounts
+ * @param cb_cls closure for @a cb
+ */
static void
-run_aggregation (void *cls)
+return_relevant_amounts (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
{
- struct Shard *s = cls;
- struct AggregationUnit au_active;
+ const struct AggregationUnit *au_active = cls;
enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount trans;
- bool have_transient = true; /* squash compiler warning */
- task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Checking for ready deposits to aggregate\n");
- /* make sure we have current fees */
- memset (&au_active,
- 0,
- sizeof (au_active));
- au_active.execution_time = GNUNET_TIME_timestamp_get ();
+ "Returning amount %s in KYC check\n",
+ TALER_amount2s (&au_active->total_amount));
if (GNUNET_OK !=
- db_plugin->start_deferred_wire_out (db_plugin->cls))
+ cb (cb_cls,
+ &au_active->total_amount,
+ GNUNET_TIME_absolute_get ()))
+ return;
+ qs = db_plugin->select_aggregation_amounts_for_kyc_check (
+ db_plugin->cls,
+ &au_active->h_payto,
+ limit,
+ cb,
+ cb_cls);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to start database transaction!\n");
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- release_shard (s);
- return;
+ "Failed to select aggregation amounts for KYC limit check!\n");
}
- qs = db_plugin->get_ready_deposit (
+}
+
+
+/**
+ * Test if KYC is required for a transfer to @a h_payto.
+ *
+ * @param[in,out] au_active aggregation unit to check for
+ * @return true if KYC checks are satisfied
+ */
+static bool
+kyc_satisfied (struct AggregationUnit *au_active)
+{
+ char *requirement;
+ enum GNUNET_DB_QueryStatus qs;
+
+ if (kyc_off)
+ return true;
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT,
+ &au_active->h_payto,
+ db_plugin->select_satisfied_kyc_processes,
db_plugin->cls,
- s->shard_start,
- s->shard_end,
- kyc_off ? true : false,
- &au_active.merchant_pub,
- &au_active.payto_uri);
- switch (qs)
+ &return_relevant_amounts,
+ (void *) au_active,
+ &requirement);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return false;
+ }
+ if (NULL == requirement)
+ return true;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC requirement for %s is %s\n",
+ TALER_amount2s (&au_active->total_amount),
+ requirement);
+ qs = db_plugin->insert_kyc_requirement_for_account (
+ db_plugin->cls,
+ requirement,
+ &au_active->h_payto,
+ NULL, /* not a reserve */
+ &au_active->requirement_row);
+ if (qs < 0)
{
- case GNUNET_DB_STATUS_HARD_ERROR:
- cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to begin deposit iteration!\n");
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- release_shard (s);
- return;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls);
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_aggregation,
- s);
- return;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- {
- uint64_t counter = s->work_counter;
- struct GNUNET_TIME_Relative duration
- = GNUNET_TIME_absolute_get_duration (s->start_time.abs_time);
+ "Failed to persist KYC requirement `%s' in DB!\n",
+ requirement);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Legitimization process %llu started\n",
+ (unsigned long long) au_active->requirement_row);
+ }
+ GNUNET_free (requirement);
+ return false;
+}
- cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Completed shard [%u,%u] after %s with %llu deposits\n",
- (unsigned int) s->shard_start,
- (unsigned int) s->shard_end,
- GNUNET_TIME_relative2s (duration,
- true),
- (unsigned long long) counter);
- release_shard (s);
- if ( (GNUNET_YES == test_mode) &&
- (0 == counter) )
- {
- /* in test mode, shutdown after a shard is done with 0 work */
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
- GNUNET_assert (NULL == task);
- /* If we ended up doing zero work, sleep a bit */
- if (0 == counter)
- task = GNUNET_SCHEDULER_add_delayed (aggregator_idle_sleep_interval,
- &run_shard,
- NULL);
- else
- task = GNUNET_SCHEDULER_add_now (&run_shard,
- NULL);
- return;
+
+/**
+ * Function called on each @a amount that was found to
+ * be relevant for an AML check.
+ *
+ * @param cls closure with the `struct TALER_Amount *` where we store the sum
+ * @param amount encountered transaction amount
+ * @param date when was the amount encountered
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to abort iteration
+ * #GNUNET_SYSERR on internal error (also abort itaration)
+ */
+static enum GNUNET_GenericReturnValue
+sum_for_aml (
+ void *cls,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Absolute date)
+{
+ struct TALER_Amount *sum = cls;
+
+ (void) date;
+ if (0 >
+ TALER_amount_add (sum,
+ sum,
+ amount))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Test if AML is required for a transfer to @a h_payto.
+ *
+ * @param[in,out] au_active aggregation unit to check for
+ * @return true if AML checks are satisfied
+ */
+static bool
+aml_satisfied (struct AggregationUnit *au_active)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_Amount total;
+ struct TALER_Amount threshold;
+ enum TALER_AmlDecisionState decision;
+ struct TALER_EXCHANGEDB_KycStatus kyc;
+
+ total = au_active->final_amount;
+ qs = db_plugin->select_aggregation_amounts_for_kyc_check (
+ db_plugin->cls,
+ &au_active->h_payto,
+ GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (),
+ GNUNET_TIME_UNIT_MONTHS),
+ &sum_for_aml,
+ &total);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return false;
+ }
+ qs = db_plugin->select_aml_threshold (db_plugin->cls,
+ &au_active->h_payto,
+ &decision,
+ &kyc,
+ &threshold);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return false;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ threshold = aml_threshold; /* use default */
+ decision = TALER_AML_NORMAL;
+ }
+ switch (decision)
+ {
+ case TALER_AML_NORMAL:
+ if (0 >= TALER_amount_cmp (&total,
+ &threshold))
+ {
+ /* total <= threshold, do nothing */
+ return true;
}
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- s->work_counter++;
- /* continued below */
- break;
+ qs = db_plugin->trigger_aml_process (db_plugin->cls,
+ &au_active->h_payto,
+ &total);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return false;
+ }
+ return false;
+ case TALER_AML_PENDING:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "AML already pending, doing nothing\n");
+ return false;
+ case TALER_AML_FROZEN:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account frozen, doing nothing\n");
+ return false;
}
- au_active.wa = TALER_EXCHANGEDB_find_account_by_payto_uri (
- au_active.payto_uri);
- if (NULL == au_active.wa)
+ GNUNET_assert (0);
+ return false;
+}
+
+
+/**
+ * Perform the main aggregation work for @a au. Expects to be in
+ * a working transaction, which the caller must also ultimately commit
+ * (or rollback) depending on our return value.
+ *
+ * @param[in,out] au aggregation unit to work on
+ * @return #GNUNET_OK if aggregation succeeded,
+ * #GNUNET_NO to rollback and try again (serialization issue)
+ * #GNUNET_SYSERR hard error, terminate aggregator process
+ */
+static enum GNUNET_GenericReturnValue
+do_aggregate (struct AggregationUnit *au)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ au->wa = TALER_EXCHANGEDB_find_account_by_payto_uri (
+ au->payto_uri);
+ if (NULL == au->wa)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No exchange account configured for `%s', please fix your setup to continue!\n",
- au_active.payto_uri);
+ au->payto_uri);
global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- db_plugin->rollback (db_plugin->cls);
- release_shard (s);
- return;
+ return GNUNET_SYSERR;
}
{
@@ -464,234 +684,301 @@ run_aggregation (void *cls)
struct TALER_MasterSignatureP master_sig;
qs = db_plugin->get_wire_fee (db_plugin->cls,
- au_active.wa->method,
- au_active.execution_time,
+ au->wa->method,
+ au->execution_time,
&start_date,
&end_date,
- &au_active.fees,
+ &au->fees,
&master_sig);
if (0 >= qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not get wire fees for %s at %s. Aborting run.\n",
- au_active.wa->method,
- GNUNET_TIME_timestamp2s (au_active.execution_time));
+ au->wa->method,
+ GNUNET_TIME_timestamp2s (au->execution_time));
global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- db_plugin->rollback (db_plugin->cls);
- release_shard (s);
- return;
+ return GNUNET_SYSERR;
}
}
-
/* Now try to find other deposits to aggregate */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Found ready deposit for %s, aggregating by target %s\n",
- TALER_B2S (&au_active.merchant_pub),
- au_active.payto_uri);
- TALER_payto_hash (au_active.payto_uri,
- &au_active.h_payto);
-
+ TALER_B2S (&au->merchant_pub),
+ au->payto_uri);
qs = db_plugin->select_aggregation_transient (db_plugin->cls,
- &au_active.h_payto,
- au_active.wa->section_name,
- &au_active.wtid,
- &trans);
+ &au->h_payto,
+ &au->merchant_pub,
+ au->wa->section_name,
+ &au->wtid,
+ &au->trans);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to lookup transient aggregates!\n");
- cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- release_shard (s);
- return;
+ return GNUNET_SYSERR;
case GNUNET_DB_STATUS_SOFT_ERROR:
/* serializiability issue, try again */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n");
- db_plugin->rollback (db_plugin->cls);
- cleanup_au (&au_active);
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_aggregation,
- s);
- return;
+ return GNUNET_NO;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
- &au_active.wtid,
- sizeof (au_active.wtid));
- have_transient = false;
+ &au->wtid,
+ sizeof (au->wtid));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No transient aggregation found, starting %s\n",
+ TALER_B2S (&au->wtid));
+ au->have_transient = false;
break;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- have_transient = true;
+ au->have_transient = true;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Transient aggregation found, resuming %s\n",
+ TALER_B2S (&au->wtid));
break;
}
qs = db_plugin->aggregate (db_plugin->cls,
- &au_active.h_payto,
- &au_active.merchant_pub,
- &au_active.wtid,
- &au_active.total_amount);
+ &au->h_payto,
+ &au->merchant_pub,
+ &au->wtid,
+ &au->total_amount);
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to execute aggregation!\n");
- cleanup_au (&au_active);
- db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- release_shard (s);
- return;
+ return GNUNET_SYSERR;
}
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
/* serializiability issue, try again */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Serialization issue, trying again later!\n");
- db_plugin->rollback (db_plugin->cls);
- cleanup_au (&au_active);
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_aggregation,
- s);
- return;
+ return GNUNET_NO;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Aggregation total is %s.\n",
- TALER_amount2s (&au_active.total_amount));
-
+ TALER_amount2s (&au->total_amount));
/* Subtract wire transfer fee and round to the unit supported by the
wire transfer method; Check if after rounding down, we still have
an amount to transfer, and if not mark as 'tiny'. */
- if (have_transient)
+ if (au->have_transient)
GNUNET_assert (0 <=
- TALER_amount_add (&au_active.total_amount,
- &au_active.total_amount,
- &trans));
+ TALER_amount_add (&au->total_amount,
+ &au->total_amount,
+ &au->trans));
+
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Rounding aggregate of %s\n",
- TALER_amount2s (&au_active.total_amount));
+ TALER_amount2s (&au->total_amount));
if ( (0 >=
- TALER_amount_subtract (&au_active.final_amount,
- &au_active.total_amount,
- &au_active.fees.wire)) ||
+ TALER_amount_subtract (&au->final_amount,
+ &au->total_amount,
+ &au->fees.wire)) ||
(GNUNET_SYSERR ==
- TALER_amount_round_down (&au_active.final_amount,
+ TALER_amount_round_down (&au->final_amount,
&currency_round_unit)) ||
- (TALER_amount_is_zero (&au_active.final_amount)) )
+ (TALER_amount_is_zero (&au->final_amount)) ||
+ (! kyc_satisfied (au)) ||
+ (! aml_satisfied (au)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Aggregate value too low for transfer (%d/%s)\n",
+ "Not ready for wire transfer (%d/%s)\n",
qs,
- TALER_amount2s (&au_active.final_amount));
- if (have_transient)
+ TALER_amount2s (&au->final_amount));
+ if (au->have_transient)
qs = db_plugin->update_aggregation_transient (db_plugin->cls,
- &au_active.h_payto,
- &au_active.wtid,
- &au_active.total_amount);
+ &au->h_payto,
+ &au->wtid,
+ au->requirement_row,
+ &au->total_amount);
else
qs = db_plugin->create_aggregation_transient (db_plugin->cls,
- &au_active.h_payto,
- au_active.wa->section_name,
- &au_active.wtid,
- &au_active.total_amount);
+ &au->h_payto,
+ au->wa->section_name,
+ &au->merchant_pub,
+ &au->wtid,
+ au->requirement_row,
+ &au->total_amount);
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Serialization issue, trying again later!\n");
- db_plugin->rollback (db_plugin->cls);
- cleanup_au (&au_active);
- /* start again */
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_aggregation,
- s);
- return;
+ return GNUNET_NO;
}
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls);
- cleanup_au (&au_active);
global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- release_shard (s);
- return;
+ return GNUNET_SYSERR;
}
/* commit */
- (void) commit_or_warn ();
- cleanup_au (&au_active);
+ return GNUNET_OK;
+ }
- /* start again */
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_aggregation,
- s);
- return;
+ qs = trigger_wire_transfer (au);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization issue during aggregation; trying again later!\n")
+ ;
+ return GNUNET_NO;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ return GNUNET_SYSERR;
+ default:
+ break;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Preparing wire transfer of %s to %s\n",
- TALER_amount2s (&au_active.final_amount),
- TALER_B2S (&au_active.merchant_pub));
{
- void *buf;
- size_t buf_size;
-
- TALER_BANK_prepare_transfer (au_active.payto_uri,
- &au_active.final_amount,
- exchange_base_url,
- &au_active.wtid,
- &buf,
- &buf_size);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Storing %u bytes of wire prepare data\n",
- (unsigned int) buf_size);
- /* Commit our intention to execute the wire transfer! */
- qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
- au_active.wa->method,
- buf,
- buf_size);
- GNUNET_free (buf);
+ struct TALER_CoinDepositEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_DEPOSIT_STATUS_CHANGED),
+ .merchant_pub = au->merchant_pub
+ };
+
+ db_plugin->event_notify (db_plugin->cls,
+ &rep.header,
+ NULL,
+ 0);
}
- /* Commit the WTID data to 'wire_out' */
- if (qs >= 0)
- qs = db_plugin->store_wire_transfer_out (db_plugin->cls,
- au_active.execution_time,
- &au_active.wtid,
- &au_active.h_payto,
- au_active.wa->section_name,
- &au_active.final_amount);
+ return GNUNET_OK;
- if ( (qs >= 0) &&
- have_transient)
- qs = db_plugin->delete_aggregation_transient (db_plugin->cls,
- &au_active.h_payto,
- &au_active.wtid);
- cleanup_au (&au_active);
+}
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+
+static void
+run_aggregation (void *cls)
+{
+ struct Shard *s = cls;
+ struct AggregationUnit au_active;
+ enum GNUNET_DB_QueryStatus qs;
+ enum GNUNET_GenericReturnValue ret;
+
+ task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Checking for ready deposits to aggregate\n");
+ /* make sure we have current fees */
+ memset (&au_active,
+ 0,
+ sizeof (au_active));
+ au_active.execution_time = GNUNET_TIME_timestamp_get ();
+ if (GNUNET_OK !=
+ db_plugin->start_deferred_wire_out (db_plugin->cls))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Serialization issue for prepared wire data; trying again later!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start database transaction!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ release_shard (s);
+ return;
+ }
+ qs = db_plugin->get_ready_deposit (
+ db_plugin->cls,
+ s->shard_start,
+ s->shard_end,
+ &au_active.merchant_pub,
+ &au_active.payto_uri);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ cleanup_au (&au_active);
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to begin deposit iteration!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ release_shard (s);
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ cleanup_au (&au_active);
db_plugin->rollback (db_plugin->cls);
- /* start again */
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
s);
return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ {
+ uint64_t counter = s->work_counter;
+ struct GNUNET_TIME_Relative duration
+ = GNUNET_TIME_absolute_get_duration (s->start_time.abs_time);
+
+ cleanup_au (&au_active);
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Completed shard [%u,%u] after %s with %llu deposits\n",
+ (unsigned int) s->shard_start,
+ (unsigned int) s->shard_end,
+ GNUNET_TIME_relative2s (duration,
+ true),
+ (unsigned long long) counter);
+ release_shard (s);
+ if ( (GNUNET_YES == test_mode) &&
+ (0 == counter) )
+ {
+ /* in test mode, shutdown after a shard is done with 0 work */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No work done and in test mode, shutting down\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (NULL == task);
+ /* If we ended up doing zero work, sleep a bit */
+ if (0 == counter)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Going to sleep for %s before trying again\n",
+ GNUNET_TIME_relative2s (aggregator_idle_sleep_interval,
+ true));
+ task = GNUNET_SCHEDULER_add_delayed (aggregator_idle_sleep_interval,
+ &drain_kyc_alerts,
+ NULL);
+ }
+ else
+ {
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ }
+ return;
+ }
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ s->work_counter++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Found ready deposit!\n");
+ /* continued below */
+ break;
}
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+
+ TALER_payto_hash (au_active.payto_uri,
+ &au_active.h_payto);
+ ret = do_aggregate (&au_active);
+ cleanup_au (&au_active);
+ switch (ret)
{
- GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls);
- /* die hard */
+ case GNUNET_SYSERR:
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
+ db_plugin->rollback (db_plugin->cls);
release_shard (s);
return;
+ case GNUNET_NO:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&run_aggregation,
+ s);
+ return;
+ case GNUNET_OK:
+ /* continued below */
+ break;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Stored wire transfer out instructions\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Committing aggregation result\n");
/* Now we can finally commit the overall transaction, as we are
again consistent if all of this passes. */
@@ -699,8 +986,8 @@ run_aggregation (void *cls)
{
case GNUNET_DB_STATUS_SOFT_ERROR:
/* try again */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Commit issue for prepared wire data; trying again later!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization issue on commit; trying again later!\n");
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
s);
@@ -714,7 +1001,7 @@ run_aggregation (void *cls)
return;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Preparation complete, going again\n");
+ "Commit complete, going again\n");
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
s);
@@ -743,6 +1030,8 @@ run_shard (void *cls)
(void) cls;
task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running aggregation shard\n");
if (GNUNET_SYSERR ==
db_plugin->preflight (db_plugin->cls))
{
@@ -769,6 +1058,7 @@ run_shard (void *cls)
GNUNET_free (s);
delay = GNUNET_TIME_randomized_backoff (delay,
GNUNET_TIME_UNIT_SECONDS);
+ GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_delayed (delay,
&run_shard,
NULL);
@@ -786,12 +1076,207 @@ run_shard (void *cls)
"Starting shard [%u:%u]!\n",
(unsigned int) s->shard_start,
(unsigned int) s->shard_end);
+ GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&run_aggregation,
s);
}
/**
+ * Function called on transient aggregations matching
+ * a particular hash of a payto URI.
+ *
+ * @param cls
+ * @param payto_uri corresponding payto URI
+ * @param wtid wire transfer identifier of transient aggregation
+ * @param merchant_pub public key of the merchant
+ * @param total amount aggregated so far
+ * @return true to continue to iterate
+ */
+static bool
+handle_transient_cb (
+ void *cls,
+ const char *payto_uri,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_Amount *total)
+{
+ struct AggregationUnit *au = cls;
+
+ if (GNUNET_OK != au->ret)
+ {
+ GNUNET_break (0);
+ return false;
+ }
+ au->payto_uri = GNUNET_strdup (payto_uri);
+ au->wtid = *wtid;
+ au->merchant_pub = *merchant_pub;
+ au->trans = *total;
+ au->have_transient = true;
+ au->ret = do_aggregate (au);
+ GNUNET_free (au->payto_uri);
+ return (GNUNET_OK == au->ret);
+}
+
+
+static void
+drain_kyc_alerts (void *cls)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct AggregationUnit au;
+
+ (void) cls;
+ task = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Draining KYC alerts\n");
+ memset (&au,
+ 0,
+ sizeof (au));
+ au.execution_time = GNUNET_TIME_timestamp_get ();
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to obtain database connection!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ db_plugin->start (db_plugin->cls,
+ "handle kyc alerts"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start database transaction!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ while (1)
+ {
+ qs = db_plugin->drain_kyc_alert (db_plugin->cls,
+ 1,
+ &au.h_payto);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ qs = db_plugin->commit (db_plugin->cls);
+ if (qs < 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to commit KYC drain\n");
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&run_shard,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* handled below */
+ break;
+ }
+
+ au.ret = GNUNET_OK;
+ qs = db_plugin->find_aggregation_transient (db_plugin->cls,
+ &au.h_payto,
+ &handle_transient_cb,
+ &au);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to lookup transient aggregates!\n");
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ /* serializiability issue, try again */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Serialization issue, trying again later!\n");
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ continue; /* while (1) */
+ default:
+ break;
+ }
+ break;
+ } /* while(1) */
+
+ {
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = au.ret;
+ cleanup_au (&au);
+ switch (ret)
+ {
+ case GNUNET_SYSERR:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ db_plugin->rollback (db_plugin->cls); /* just in case */
+ return;
+ case GNUNET_NO:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_OK:
+ /* continued below */
+ break;
+ }
+ }
+
+ switch (commit_or_warn ())
+ {
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ /* try again */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization issue on commit; trying again later!\n");
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ db_plugin->rollback (db_plugin->cls); /* just in case */
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Commit complete, going again\n");
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
+ NULL);
+ return;
+ default:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ db_plugin->rollback (db_plugin->cls); /* just in case */
+ return;
+ }
+}
+
+
+/**
* First task.
*
* @param cls closure, NULL
@@ -811,7 +1296,8 @@ run (void *cls,
(void) cfgfile;
cfg = c;
- if (GNUNET_OK != parse_wirewatch_config ())
+ if (GNUNET_OK !=
+ parse_aggregator_config ())
{
cfg = NULL;
global_ret = EXIT_NOTCONFIGURED;
@@ -832,11 +1318,18 @@ run (void *cls,
shard_size = 1U + INT32_MAX;
else
shard_size = (uint32_t) ass;
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_kyc_init (cfg))
+ {
+ cfg = NULL;
+ global_ret = EXIT_NOTCONFIGURED;
+ return;
+ }
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ NULL);
GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&run_shard,
+ task = GNUNET_SCHEDULER_add_now (&drain_kyc_alerts,
NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- cls);
}
diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c
index 92ba7babb..779525c4e 100644
--- a/src/exchange/taler-exchange-closer.c
+++ b/src/exchange/taler-exchange-closer.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2021 Taler Systems SA
+ Copyright (C) 2016-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -204,14 +204,19 @@ commit_or_warn (void)
* @param account_payto_uri information about the bank account that initially
* caused the reserve to be created
* @param expiration_date when did the reserve expire
- * @return transaction status code
+ * @param close_request_row row of request asking for
+ * closure, 0 for expired reserves
+ * @return #GNUNET_OK on success (continue)
+ * #GNUNET_NO on non-fatal errors (try again)
+ * #GNUNET_SYSERR on fatal errors (abort)
*/
-static enum GNUNET_DB_QueryStatus
+static enum GNUNET_GenericReturnValue
expired_reserve_cb (void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *left,
const char *account_payto_uri,
- struct GNUNET_TIME_Timestamp expiration_date)
+ struct GNUNET_TIME_Timestamp expiration_date,
+ uint64_t close_request_row)
{
struct GNUNET_TIME_Timestamp now;
struct TALER_WireTransferIdentifierRawP wtid;
@@ -239,7 +244,7 @@ expired_reserve_cb (void *cls,
account_payto_uri);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
- return GNUNET_DB_STATUS_HARD_ERROR;
+ return GNUNET_SYSERR;
}
/* lookup `fees` from time of actual reserve expiration
@@ -257,13 +262,22 @@ expired_reserve_cb (void *cls,
&end_date,
&fees,
&master_sig);
- if (0 >= qs)
+ switch (qs)
{
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not get wire fees for %s at %s. Aborting run.\n",
wa->method,
GNUNET_TIME_timestamp2s (expiration_date));
- return GNUNET_DB_STATUS_HARD_ERROR;
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return GNUNET_NO;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* continued below */
+ break;
}
}
@@ -281,8 +295,8 @@ expired_reserve_cb (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (left->currency,
&amount_without_fee));
+ ret = TALER_AAR_RESULT_ZERO;
}
- GNUNET_assert (TALER_AAR_RESULT_POSITIVE == ret);
/* round down to enable transfer */
if (GNUNET_SYSERR ==
TALER_amount_round_down (&amount_without_fee,
@@ -291,27 +305,25 @@ expired_reserve_cb (void *cls,
GNUNET_break (0);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
- return GNUNET_DB_STATUS_HARD_ERROR;
+ return GNUNET_SYSERR;
}
/* NOTE: sizeof (*reserve_pub) == sizeof (wtid) right now, but to
be future-compatible, we use the memset + min construction */
memset (&wtid,
0,
sizeof (wtid));
- memcpy (&wtid,
- reserve_pub,
- GNUNET_MIN (sizeof (wtid),
- sizeof (*reserve_pub)));
- if (TALER_AAR_INVALID_NEGATIVE_RESULT != ret)
- qs = db_plugin->insert_reserve_closed (db_plugin->cls,
- reserve_pub,
- now,
- account_payto_uri,
- &wtid,
- left,
- &closing_fee);
- else
- qs = GNUNET_DB_STATUS_HARD_ERROR;
+ GNUNET_memcpy (&wtid,
+ reserve_pub,
+ GNUNET_MIN (sizeof (wtid),
+ sizeof (*reserve_pub)));
+ qs = db_plugin->insert_reserve_closed (db_plugin->cls,
+ reserve_pub,
+ now,
+ account_payto_uri,
+ &wtid,
+ left,
+ &closing_fee,
+ close_request_row);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Closing reserve %s over %s (%d, %d)\n",
TALER_B2S (reserve_pub),
@@ -319,22 +331,30 @@ expired_reserve_cb (void *cls,
(int) ret,
qs);
/* Check for hard failure */
- if ( (TALER_AAR_INVALID_NEGATIVE_RESULT == ret) ||
- (GNUNET_DB_STATUS_HARD_ERROR == qs) )
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{
GNUNET_break (0);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
- return GNUNET_DB_STATUS_HARD_ERROR;
+ return GNUNET_SYSERR;
}
- if ( (TALER_AAR_RESULT_ZERO == ret) ||
- (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) )
+ if (TALER_amount_is_zero (&amount_without_fee))
{
/* Reserve balance was zero OR soft error */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Reserve was virtually empty, moving on\n");
- (void) commit_or_warn ();
- return qs;
+ qs = commit_or_warn ();
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return GNUNET_NO;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return GNUNET_OK;
+ }
}
/* success, perform wire transfer */
@@ -355,19 +375,25 @@ expired_reserve_cb (void *cls,
buf_size);
GNUNET_free (buf);
}
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ switch (qs)
{
+ case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- {
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
/* start again */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ return GNUNET_NO;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
}
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ return GNUNET_OK;
}
@@ -409,11 +435,18 @@ run_reserve_closures (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for reserves to close by date %s\n",
GNUNET_TIME_timestamp2s (now));
- qs = db_plugin->get_expired_reserves (db_plugin->cls,
- now,
- &expired_reserve_cb,
- NULL);
- GNUNET_assert (1 >= qs);
+ qs = db_plugin->get_unfinished_close_requests (db_plugin->cls,
+ &expired_reserve_cb,
+ NULL);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ /* Try expired reserves as well */
+ qs = db_plugin->get_expired_reserves (
+ db_plugin->cls,
+ now,
+ &expired_reserve_cb,
+ NULL);
+ }
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -436,13 +469,11 @@ run_reserve_closures (void *cls)
if (GNUNET_YES == test_mode)
{
GNUNET_SCHEDULER_shutdown ();
+ return;
}
- else
- {
- task = GNUNET_SCHEDULER_add_delayed (closer_idle_sleep_interval,
- &run_reserve_closures,
- NULL);
- }
+ task = GNUNET_SCHEDULER_add_delayed (closer_idle_sleep_interval,
+ &run_reserve_closures,
+ NULL);
return;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
(void) commit_or_warn ();
diff --git a/src/exchange/taler-exchange-drain.c b/src/exchange/taler-exchange-drain.c
new file mode 100644
index 000000000..d409487c1
--- /dev/null
+++ b/src/exchange/taler-exchange-drain.c
@@ -0,0 +1,431 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-drain.c
+ * @brief Process that drains exchange profits from the escrow account
+ * and puts them into some regular account of the exchange.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <pthread.h>
+#include "taler_exchangedb_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_json_lib.h"
+#include "taler_bank_service.h"
+
+
+/**
+ * The exchange's configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+/**
+ * Our database plugin.
+ */
+static struct TALER_EXCHANGEDB_Plugin *db_plugin;
+
+/**
+ * Our master public key.
+ */
+static struct TALER_MasterPublicKeyP master_pub;
+
+/**
+ * Next task to run, if any.
+ */
+static struct GNUNET_SCHEDULER_Task *task;
+
+/**
+ * Base URL of this exchange.
+ */
+static char *exchange_base_url;
+
+/**
+ * Value to return from main(). 0 on success, non-zero on errors.
+ */
+static int global_ret;
+
+
+/**
+ * We're being aborted with CTRL-C (or SIGTERM). Shut down.
+ *
+ * @param cls closure
+ */
+static void
+shutdown_task (void *cls)
+{
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Running shutdown\n");
+ if (NULL != task)
+ {
+ GNUNET_SCHEDULER_cancel (task);
+ task = NULL;
+ }
+ db_plugin->rollback (db_plugin->cls); /* just in case */
+ TALER_EXCHANGEDB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ TALER_EXCHANGEDB_unload_accounts ();
+ cfg = NULL;
+}
+
+
+/**
+ * Parse the configuration for drain.
+ *
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_drain_config (void)
+{
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &exchange_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+
+ {
+ char *master_public_key_str;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "MASTER_PUBLIC_KEY",
+ &master_public_key_str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "MASTER_PUBLIC_KEY");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_public_key_from_string (master_public_key_str,
+ strlen (
+ master_public_key_str),
+ &master_pub.eddsa_pub))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "MASTER_PUBLIC_KEY",
+ "invalid base32 encoding for a master public key");
+ GNUNET_free (master_public_key_str);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (master_public_key_str);
+ }
+ if (NULL ==
+ (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize DB subsystem\n");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_EXCHANGEDB_load_accounts (cfg,
+ TALER_EXCHANGEDB_ALO_DEBIT
+ | TALER_EXCHANGEDB_ALO_AUTHDATA))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No wire accounts configured for debit!\n");
+ TALER_EXCHANGEDB_plugin_unload (db_plugin);
+ db_plugin = NULL;
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Perform a database commit. If it fails, print a warning.
+ *
+ * @return status of commit
+ */
+static enum GNUNET_DB_QueryStatus
+commit_or_warn (void)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = db_plugin->commit (db_plugin->cls);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ return qs;
+ GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ ? GNUNET_ERROR_TYPE_INFO
+ : GNUNET_ERROR_TYPE_ERROR,
+ "Failed to commit database transaction!\n");
+ return qs;
+}
+
+
+/**
+ * Execute a wire drain.
+ *
+ * @param cls NULL
+ */
+static void
+run_drain (void *cls)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ uint64_t serial;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *account_section;
+ char *payto_uri;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct TALER_Amount amount;
+ struct TALER_MasterSignatureP master_sig;
+
+ (void) cls;
+ task = NULL;
+ if (GNUNET_OK !=
+ db_plugin->start (db_plugin->cls,
+ "run drain"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start database transaction!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ qs = db_plugin->profit_drains_get_pending (db_plugin->cls,
+ &serial,
+ &wtid,
+ &account_section,
+ &payto_uri,
+ &request_timestamp,
+ &amount,
+ &master_sig);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Serialization failure on simple SELECT!?\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* no profit drains, finished */
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "No profit drains pending. Exiting.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ default:
+ /* continued below */
+ break;
+ }
+ /* Check signature (again, this is a critical operation!) */
+ if (GNUNET_OK !=
+ TALER_exchange_offline_profit_drain_verify (
+ &wtid,
+ request_timestamp,
+ &amount,
+ account_section,
+ payto_uri,
+ &master_pub,
+ &master_sig))
+ {
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+
+ /* Display data for manual human check */
+ fprintf (stdout,
+ "Critical operation. MANUAL CHECK REQUIRED.\n");
+ fprintf (stdout,
+ "We will wire %s to `%s'\n based on instructions from %s.\n",
+ TALER_amount2s (&amount),
+ payto_uri,
+ GNUNET_TIME_timestamp2s (request_timestamp));
+ fprintf (stdout,
+ "Press ENTER to confirm, CTRL-D to abort.\n");
+ while (1)
+ {
+ int key;
+
+ key = getchar ();
+ if (EOF == key)
+ {
+ fprintf (stdout,
+ "Transfer aborted.\n"
+ "Re-run 'taler-exchange-drain' to try it again.\n"
+ "Contact Taler Systems SA to cancel it for good.\n"
+ "Exiting.\n");
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_FAILURE;
+ return;
+ }
+ if ('\n' == key)
+ break;
+ }
+
+ /* Note: account_section ignored for now, we
+ might want to use it here in the future... */
+ (void) account_section;
+ {
+ char *method;
+ void *buf;
+ size_t buf_size;
+
+ TALER_BANK_prepare_transfer (payto_uri,
+ &amount,
+ exchange_base_url,
+ &wtid,
+ &buf,
+ &buf_size);
+ method = TALER_payto_get_method (payto_uri);
+ qs = db_plugin->wire_prepare_data_insert (db_plugin->cls,
+ method,
+ buf,
+ buf_size);
+ GNUNET_free (method);
+ GNUNET_free (buf);
+ }
+ qs = db_plugin->profit_drains_set_finished (db_plugin->cls,
+ serial);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed: database serialization issue\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ db_plugin->rollback (db_plugin->cls);
+ GNUNET_assert (NULL == task);
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ default:
+ /* continued below */
+ break;
+ }
+ /* commit transaction + report success + exit */
+ if (0 >= commit_or_warn ())
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "Profit drain triggered. Exiting.\n");
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * First task.
+ *
+ * @param cls closure, NULL
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
+{
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+
+ cfg = c;
+ if (GNUNET_OK != parse_drain_config ())
+ {
+ cfg = NULL;
+ global_ret = EXIT_NOTCONFIGURED;
+ return;
+ }
+ if (GNUNET_SYSERR ==
+ db_plugin->preflight (db_plugin->cls))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to obtain database connection!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&run_drain,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ cls);
+}
+
+
+/**
+ * The main function of the taler-exchange-drain.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_version (VERSION "-" VCS_VERSION),
+ GNUNET_GETOPT_OPTION_END
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_get_utf8_args (argc, argv,
+ &argc, &argv))
+ return EXIT_INVALIDARGUMENT;
+ TALER_OS_init ();
+ ret = GNUNET_PROGRAM_run (
+ argc, argv,
+ "taler-exchange-drain",
+ gettext_noop (
+ "process that executes a single profit drain"),
+ options,
+ &run, NULL);
+ GNUNET_free_nz ((void *) argv);
+ if (GNUNET_SYSERR == ret)
+ return EXIT_INVALIDARGUMENT;
+ if (GNUNET_NO == ret)
+ return EXIT_SUCCESS;
+ return global_ret;
+}
+
+
+/* end of taler-exchange-drain.c */
diff --git a/src/exchange/taler-exchange-expire.c b/src/exchange/taler-exchange-expire.c
index d99c430e0..b2d34ee1c 100644
--- a/src/exchange/taler-exchange-expire.c
+++ b/src/exchange/taler-exchange-expire.c
@@ -74,11 +74,6 @@ static struct TALER_EXCHANGEDB_Plugin *db_plugin;
static struct GNUNET_SCHEDULER_Task *task;
/**
- * How long should we sleep when idle before trying to find more work?
- */
-static struct GNUNET_TIME_Relative expire_idle_sleep_interval;
-
-/**
* How big are the shards we are processing? Is an inclusive offset, so every
* shard ranges from [X,X+shard_size) exclusive. So a shard covers
* shard_size slots.
@@ -141,17 +136,6 @@ shutdown_task (void *cls)
static enum GNUNET_GenericReturnValue
parse_expire_config (void)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "exchange",
- "EXPIRE_IDLE_SLEEP_INTERVAL",
- &expire_idle_sleep_interval))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "EXPIRE_IDLE_SLEEP_INTERVAL");
- return GNUNET_SYSERR;
- }
if (NULL ==
(db_plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
@@ -223,7 +207,12 @@ release_shard (struct Shard *s)
if ( (0 == wc) &&
(test_mode) &&
(! jump_mode) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "In test-mode without work. Terminating.\n");
GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
}
@@ -283,9 +272,9 @@ run_expire (void *cls)
"expire-purse"))
{
GNUNET_break (0);
- global_ret = EXIT_FAILURE;
db_plugin->rollback (db_plugin->cls);
abort_shard (s);
+ global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -296,9 +285,9 @@ run_expire (void *cls)
{
case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
- global_ret = EXIT_FAILURE;
db_plugin->rollback (db_plugin->cls);
abort_shard (s);
+ global_ret = EXIT_FAILURE;
GNUNET_SCHEDULER_shutdown ();
return;
case GNUNET_DB_STATUS_SOFT_ERROR:
@@ -395,6 +384,13 @@ run_shard (void *cls)
if (GNUNET_TIME_absolute_is_future (s->shard_end))
{
abort_shard (s);
+ if (test_mode)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "In test-mode without work. Terminating.\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_at (s->shard_end,
&run_shard,
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 79db4acd0..36459fbd7 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -25,22 +25,28 @@
#include <jansson.h>
#include <microhttpd.h>
#include <sched.h>
-#include <pthread.h>
#include <sys/resource.h>
#include <limits.h>
+#include "taler_kyclogic_lib.h"
+#include "taler_templating_lib.h"
#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_age-withdraw.h"
+#include "taler-exchange-httpd_age-withdraw_reveal.h"
+#include "taler-exchange-httpd_aml-decision.h"
#include "taler-exchange-httpd_auditors.h"
#include "taler-exchange-httpd_batch-deposit.h"
#include "taler-exchange-httpd_batch-withdraw.h"
+#include "taler-exchange-httpd_coins_get.h"
+#include "taler-exchange-httpd_config.h"
#include "taler-exchange-httpd_contract.h"
#include "taler-exchange-httpd_csr.h"
-#include "taler-exchange-httpd_deposit.h"
#include "taler-exchange-httpd_deposits_get.h"
#include "taler-exchange-httpd_extensions.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_kyc-check.h"
#include "taler-exchange-httpd_kyc-proof.h"
#include "taler-exchange-httpd_kyc-wallet.h"
+#include "taler-exchange-httpd_kyc-webhook.h"
#include "taler-exchange-httpd_link.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_melt.h"
@@ -49,19 +55,22 @@
#include "taler-exchange-httpd_purses_create.h"
#include "taler-exchange-httpd_purses_deposit.h"
#include "taler-exchange-httpd_purses_get.h"
+#include "taler-exchange-httpd_purses_delete.h"
#include "taler-exchange-httpd_purses_merge.h"
#include "taler-exchange-httpd_recoup.h"
#include "taler-exchange-httpd_recoup-refresh.h"
#include "taler-exchange-httpd_refreshes_reveal.h"
#include "taler-exchange-httpd_refund.h"
+#include "taler-exchange-httpd_reserves_attest.h"
+#include "taler-exchange-httpd_reserves_close.h"
#include "taler-exchange-httpd_reserves_get.h"
+#include "taler-exchange-httpd_reserves_get_attest.h"
#include "taler-exchange-httpd_reserves_history.h"
+#include "taler-exchange-httpd_reserves_open.h"
#include "taler-exchange-httpd_reserves_purse.h"
-#include "taler-exchange-httpd_reserves_status.h"
+#include "taler-exchange-httpd_spa.h"
#include "taler-exchange-httpd_terms.h"
#include "taler-exchange-httpd_transfers_get.h"
-#include "taler-exchange-httpd_wire.h"
-#include "taler-exchange-httpd_withdraw.h"
#include "taler_exchangedb_lib.h"
#include "taler_exchangedb_plugin.h"
#include "taler_extensions.h"
@@ -73,6 +82,11 @@
#define UNIX_BACKLOG 50
/**
+ * How often will we try to connect to the database before giving up?
+ */
+#define MAX_DB_RETRIES 5
+
+/**
* Above what request latency do we start to log?
*/
#define WARN_LATENCY GNUNET_TIME_relative_multiply ( \
@@ -97,14 +111,17 @@ static int allow_address_reuse;
const struct GNUNET_CONFIGURATION_Handle *TEH_cfg;
/**
- * Handle to the HTTP server.
+ * Configuration of age restriction
+ *
+ * Set after loading the library, enabled in database event handler.
*/
-static struct MHD_Daemon *mhd;
+bool TEH_age_restriction_enabled = false;
+struct TALER_AgeRestrictionConfig TEH_age_restriction_config = {0};
/**
- * Our KYC configuration.
+ * Handle to the HTTP server.
*/
-struct TEH_KycOptions TEH_kyc_config;
+static struct MHD_Daemon *mhd;
/**
* How long is caching /keys allowed at most? (global)
@@ -123,24 +140,61 @@ struct GNUNET_TIME_Relative TEH_reserve_closing_delay;
struct TALER_MasterPublicKeyP TEH_master_public_key;
/**
+ * Key used to encrypt KYC attribute data in our database.
+ */
+struct TALER_AttributeEncryptionKeyP TEH_attribute_key;
+
+/**
* Our DB plugin. (global)
*/
struct TALER_EXCHANGEDB_Plugin *TEH_plugin;
/**
+ * Absolute STEFAN parameter.
+ */
+struct TALER_Amount TEH_stefan_abs;
+
+/**
+ * Logarithmic STEFAN parameter.
+ */
+struct TALER_Amount TEH_stefan_log;
+
+/**
+ * Linear STEFAN parameter.
+ */
+float TEH_stefan_lin;
+
+/**
+ * Where to redirect users from "/"?
+ */
+static char *toplevel_redirect_url;
+
+/**
* Our currency.
*/
char *TEH_currency;
/**
- * Our base URL.
+ * Name of the KYC-AML-trigger evaluation binary.
*/
-char *TEH_base_url;
+char *TEH_kyc_aml_trigger;
/**
- * Age restriction flags and mask
+ * Option set to #GNUNET_YES if rewards are enabled.
*/
-bool TEH_age_restriction_enabled = true;
+int TEH_enable_rewards;
+
+/**
+ * What is the largest amount we allow a peer to
+ * merge into a reserve before always triggering
+ * an AML check?
+ */
+struct TALER_Amount TEH_aml_threshold;
+
+/**
+ * Our base URL.
+ */
+char *TEH_base_url;
/**
* Default timeout in seconds for HTTP requests.
@@ -169,6 +223,7 @@ bool TEH_suicide;
* TALER_SIGNATURE_MASTER_EXTENSION.
*/
struct TALER_MasterSignatureP TEH_extensions_sig;
+bool TEH_extensions_signed = false;
/**
* Value to return from main()
@@ -198,6 +253,22 @@ static unsigned long long active_connections;
static unsigned long long req_max;
/**
+ * Length of the cspecs array.
+ */
+static unsigned int num_cspecs;
+
+/**
+ * Rendering specs for currencies.
+ */
+static struct TALER_CurrencySpecification *cspecs;
+
+/**
+ * Rendering spec for our currency.
+ */
+const struct TALER_CurrencySpecification *TEH_cspec;
+
+
+/**
* Context for all CURL operations (useful to the event loop)
*/
struct GNUNET_CURL_Context *TEH_curl_ctx;
@@ -269,10 +340,6 @@ handle_post_coins (struct TEH_RequestContext *rc,
} h[] = {
{
- .op = "deposit",
- .handler = &TEH_handler_deposit
- },
- {
.op = "melt",
.handler = &TEH_handler_melt
},
@@ -318,6 +385,317 @@ handle_post_coins (struct TEH_RequestContext *rc,
/**
+ * Handle a GET "/coins/$COIN_PUB[/$OP]" request. Parses the "coin_pub"
+ * EdDSA key of the coin and demultiplexes based on $OP.
+ *
+ * @param rc request context
+ * @param args array of additional options
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_get_coins (struct TEH_RequestContext *rc,
+ const char *const args[2])
+{
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ if (NULL == args[0])
+ {
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ rc->url);
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &coin_pub,
+ sizeof (coin_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_COINS_INVALID_COIN_PUB,
+ args[0]);
+ }
+ if (NULL != args[1])
+ {
+ if (0 == strcmp (args[1],
+ "history"))
+ return TEH_handler_coins_get (rc,
+ &coin_pub);
+ if (0 == strcmp (args[1],
+ "link"))
+ return TEH_handler_link (rc,
+ &coin_pub);
+ }
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ rc->url);
+}
+
+
+/**
+ * Signature of functions that handle operations
+ * authorized by AML officers.
+ *
+ * @param rc request context
+ * @param officer_pub the public key of the AML officer
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*AmlOpPostHandler)(struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const json_t *root);
+
+
+/**
+ * Handle a "/aml/$OFFICER_PUB/$OP" POST request. Parses the "officer_pub"
+ * EdDSA key of the officer and demultiplexes based on $OP.
+ *
+ * @param rc request context
+ * @param root uploaded JSON data
+ * @param args array of additional options
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_post_aml (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[2])
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ static const struct
+ {
+ /**
+ * Name of the operation (args[1])
+ */
+ const char *op;
+
+ /**
+ * Function to call to perform the operation.
+ */
+ AmlOpPostHandler handler;
+
+ } h[] = {
+ {
+ .op = "decision",
+ .handler = &TEH_handler_post_aml_decision
+ },
+ {
+ .op = NULL,
+ .handler = NULL
+ },
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &officer_pub,
+ sizeof (officer_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_AML_OFFICER_PUB_MALFORMED,
+ args[0]);
+ }
+ for (unsigned int i = 0; NULL != h[i].op; i++)
+ if (0 == strcmp (h[i].op,
+ args[1]))
+ return h[i].handler (rc,
+ &officer_pub,
+ root);
+ return r404 (rc->connection,
+ args[1]);
+}
+
+
+/**
+ * Signature of functions that handle operations
+ * authorized by AML officers.
+ *
+ * @param rc request context
+ * @param officer_pub the public key of the AML officer
+ * @param args remaining arguments
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*AmlOpGetHandler)(struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *const args[]);
+
+
+/**
+ * Handle a "/aml/$OFFICER_PUB/$OP" GET request. Parses the "officer_pub"
+ * EdDSA key of the officer, checks the authentication signature, and
+ * demultiplexes based on $OP.
+ *
+ * @param rc request context
+ * @param args array of additional options
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_get_aml (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ static const struct
+ {
+ /**
+ * Name of the operation (args[1])
+ */
+ const char *op;
+
+ /**
+ * Function to call to perform the operation.
+ */
+ AmlOpGetHandler handler;
+
+ } h[] = {
+ {
+ .op = "decisions",
+ .handler = &TEH_handler_aml_decisions_get
+ },
+ {
+ .op = "decision",
+ .handler = &TEH_handler_aml_decision_get
+ },
+ {
+ .op = NULL,
+ .handler = NULL
+ },
+ };
+
+ if (NULL == args[0])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_AML_OFFICER_PUB_MALFORMED,
+ "argument missing");
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &officer_pub,
+ sizeof (officer_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_AML_OFFICER_PUB_MALFORMED,
+ args[0]);
+ }
+ if (NULL == args[1])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_WRONG_NUMBER_OF_SEGMENTS,
+ "AML GET operations must specify an operation identifier");
+ }
+ {
+ const char *sig_hdr;
+ struct TALER_AmlOfficerSignatureP officer_sig;
+
+ sig_hdr = MHD_lookup_connection_value (rc->connection,
+ MHD_HEADER_KIND,
+ TALER_AML_OFFICER_SIGNATURE_HEADER);
+ if ( (NULL == sig_hdr) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (sig_hdr,
+ strlen (sig_hdr),
+ &officer_sig,
+ sizeof (officer_sig))) ||
+ (GNUNET_OK !=
+ TALER_officer_aml_query_verify (&officer_pub,
+ &officer_sig)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_AML_OFFICER_GET_SIGNATURE_INVALID,
+ sig_hdr);
+ }
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ }
+
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->test_aml_officer (TEH_plugin->cls,
+ &officer_pub);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_GENERIC_AML_OFFICER_ACCESS_DENIED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ }
+ for (unsigned int i = 0; NULL != h[i].op; i++)
+ if (0 == strcmp (h[i].op,
+ args[1]))
+ return h[i].handler (rc,
+ &officer_pub,
+ &args[2]);
+ return r404 (rc->connection,
+ args[1]);
+}
+
+
+/**
+ * Handle a "/age-withdraw/$ACH/reveal" POST request. Parses the "ACH"
+ * hash of the commitment from a previous call to
+ * /reserves/$reserve_pub/age-withdraw
+ *
+ * @param rc request context
+ * @param root uploaded JSON data
+ * @param args array of additional options
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_post_age_withdraw (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[2])
+{
+ struct TALER_AgeWithdrawCommitmentHashP ach;
+
+ if (0 != strcmp ("reveal", args[1]))
+ return r404 (rc->connection,
+ args[1]);
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &ach,
+ sizeof (ach)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
+ args[0]);
+ }
+
+ return TEH_handler_age_withdraw_reveal (rc,
+ &ach,
+ root);
+}
+
+
+/**
* Signature of functions that handle operations on reserves.
*
* @param rc request context
@@ -360,26 +738,26 @@ handle_post_reserves (struct TEH_RequestContext *rc,
} h[] = {
{
- .op = "withdraw",
- .handler = &TEH_handler_withdraw
- },
- {
.op = "batch-withdraw",
.handler = &TEH_handler_batch_withdraw
},
{
- .op = "status",
- .handler = &TEH_handler_reserves_status
- },
- {
- .op = "history",
- .handler = &TEH_handler_reserves_history
+ .op = "age-withdraw",
+ .handler = &TEH_handler_age_withdraw
},
{
.op = "purse",
.handler = &TEH_handler_reserves_purse
},
{
+ .op = "open",
+ .handler = &TEH_handler_reserves_open
+ },
+ {
+ .op = "close",
+ .handler = &TEH_handler_reserves_close
+ },
+ {
.op = NULL,
.handler = NULL
},
@@ -394,7 +772,7 @@ handle_post_reserves (struct TEH_RequestContext *rc,
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_RESERVE_PUB_MALFORMED,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
args[0]);
}
for (unsigned int i = 0; NULL != h[i].op; i++)
@@ -409,6 +787,87 @@ handle_post_reserves (struct TEH_RequestContext *rc,
/**
+ * Signature of functions that handle GET operations on reserves.
+ *
+ * @param rc request context
+ * @param reserve_pub the public key of the reserve
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*ReserveGetOpHandler)(struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
+
+
+/**
+ * Handle a "GET /reserves/$RESERVE_PUB[/$OP]" request. Parses the "reserve_pub"
+ * EdDSA key of the reserve and demultiplexes based on $OP.
+ *
+ * @param rc request context
+ * @param args NULL-terminated array of additional options, zero, one or two
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_get_reserves (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ struct TALER_ReservePublicKeyP reserve_pub;
+ static const struct
+ {
+ /**
+ * Name of the operation (args[1]), optional
+ */
+ const char *op;
+
+ /**
+ * Function to call to perform the operation.
+ */
+ ReserveGetOpHandler handler;
+
+ } h[] = {
+ {
+ .op = NULL,
+ .handler = &TEH_handler_reserves_get
+ },
+ {
+ .op = "history",
+ .handler = &TEH_handler_reserves_history
+ },
+ {
+ .op = NULL,
+ .handler = NULL
+ },
+ };
+
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &reserve_pub,
+ sizeof (reserve_pub))) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
+ args[0]);
+ }
+ for (unsigned int i = 0; NULL != h[i].handler; i++)
+ {
+ if ( ( (NULL == args[1]) &&
+ (NULL == h[i].op) ) ||
+ ( (NULL != args[1]) &&
+ (NULL != h[i].op) &&
+ (0 == strcmp (h[i].op,
+ args[1])) ) )
+ return h[i].handler (rc,
+ &reserve_pub);
+ }
+ return r404 (rc->connection,
+ args[1]);
+}
+
+
+/**
* Signature of functions that handle operations on purses.
*
* @param connection HTTP request handle
@@ -562,6 +1021,11 @@ handle_mhd_completion_callback (void *cls,
TEH_check_invariants ();
if (NULL != rc->rh_cleaner)
rc->rh_cleaner (rc);
+ if (NULL != rc->root)
+ {
+ json_decref (rc->root);
+ rc->root = NULL;
+ }
TEH_check_invariants ();
{
#if MHD_VERSION >= 0x00097304
@@ -628,7 +1092,6 @@ proceed_with_handler (struct TEH_RequestContext *rc,
const struct TEH_RequestHandler *rh = rc->rh;
const char *args[rh->nargs + 2];
size_t ulen = strlen (url) + 1;
- json_t *root = NULL;
MHD_RESULT ret;
/* We do check for "ulen" here, because we'll later stack-allocate a buffer
@@ -649,8 +1112,9 @@ proceed_with_handler (struct TEH_RequestContext *rc,
/* All POST endpoints come with a body in JSON format. So we parse
the JSON here. */
- if (0 == strcasecmp (rh->method,
- MHD_HTTP_METHOD_POST))
+ if ( (0 == strcasecmp (rh->method,
+ MHD_HTTP_METHOD_POST)) &&
+ (NULL == rc->root) )
{
enum GNUNET_GenericReturnValue res;
@@ -658,16 +1122,16 @@ proceed_with_handler (struct TEH_RequestContext *rc,
&rc->opaque_post_parsing_context,
upload_data,
upload_data_size,
- &root);
+ &rc->root);
if (GNUNET_SYSERR == res)
{
- GNUNET_assert (NULL == root);
+ GNUNET_assert (NULL == rc->root);
return MHD_NO; /* bad upload, could not even generate error */
}
if ( (GNUNET_NO == res) ||
- (NULL == root) )
+ (NULL == rc->root) )
{
- GNUNET_assert (NULL == root);
+ GNUNET_assert (NULL == rc->root);
return MHD_YES; /* so far incomplete upload or parser error */
}
}
@@ -679,9 +1143,9 @@ proceed_with_handler (struct TEH_RequestContext *rc,
/* Parse command-line arguments */
/* make a copy of 'url' because 'strtok_r()' will modify */
- memcpy (d,
- url,
- ulen);
+ GNUNET_memcpy (d,
+ url,
+ ulen);
i = 0;
args[i++] = strtok_r (d, "/", &sp);
while ( (NULL != args[i - 1]) &&
@@ -704,7 +1168,6 @@ proceed_with_handler (struct TEH_RequestContext *rc,
rh->url,
url);
GNUNET_break_op (0);
- json_decref (root);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_NOT_FOUND,
TALER_EC_EXCHANGE_GENERIC_WRONG_NUMBER_OF_SEGMENTS,
@@ -714,16 +1177,19 @@ proceed_with_handler (struct TEH_RequestContext *rc,
/* Above logic ensures that 'root' is exactly non-NULL for POST operations,
so we test for 'root' to decide which handler to invoke. */
- if (NULL != root)
+ if (0 == strcasecmp (rh->method,
+ MHD_HTTP_METHOD_POST))
ret = rh->handler.post (rc,
- root,
+ rc->root,
args);
- else /* We also only have "POST" or "GET" in the API for at this point
- (OPTIONS/HEAD are taken care of earlier) */
+ else if (0 == strcasecmp (rh->method,
+ MHD_HTTP_METHOD_DELETE))
+ ret = rh->handler.delete (rc,
+ args);
+ else /* Only GET left */
ret = rh->handler.get (rc,
args);
}
- json_decref (root);
return ret;
}
@@ -766,6 +1232,20 @@ handler_seed (struct TEH_RequestContext *rc,
/**
+ * Signature of functions that handle simple
+ * POST operations for the management API.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+typedef MHD_RESULT
+(*ManagementPostHandler)(
+ struct MHD_Connection *connection,
+ const json_t *root);
+
+
+/**
* Handle POST "/management/..." requests.
*
* @param rc request context
@@ -778,6 +1258,55 @@ handle_post_management (struct TEH_RequestContext *rc,
const json_t *root,
const char *const args[])
{
+ static const struct
+ {
+ const char *arg0;
+ const char *arg1;
+ ManagementPostHandler handler;
+ } plain_posts[] = {
+ {
+ .arg0 = "keys",
+ .handler = &TEH_handler_management_post_keys
+ },
+ {
+ .arg0 = "wire",
+ .handler = &TEH_handler_management_post_wire
+ },
+ {
+ .arg0 = "wire",
+ .arg1 = "disable",
+ .handler = &TEH_handler_management_post_wire_disable
+ },
+ {
+ .arg0 = "wire-fee",
+ .handler = &TEH_handler_management_post_wire_fees
+ },
+ {
+ .arg0 = "global-fee",
+ .handler = &TEH_handler_management_post_global_fees
+ },
+ {
+ .arg0 = "extensions",
+ .handler = &TEH_handler_management_post_extensions
+ },
+ {
+ .arg0 = "drain",
+ .handler = &TEH_handler_management_post_drain
+ },
+ {
+ .arg0 = "aml-officers",
+ .handler = &TEH_handler_management_aml_officers
+ },
+ {
+ .arg0 = "partners",
+ .handler = &TEH_handler_management_partners
+ },
+ {
+ NULL,
+ NULL,
+ NULL
+ }
+ };
if (NULL == args[0])
{
GNUNET_break_op (0);
@@ -873,64 +1402,22 @@ handle_post_management (struct TEH_RequestContext *rc,
&exchange_pub,
root);
}
- if (0 == strcmp (args[0],
- "keys"))
- {
- if (NULL != args[1])
- {
- GNUNET_break_op (0);
- return r404 (rc->connection,
- "/management/keys/*");
- }
- return TEH_handler_management_post_keys (rc->connection,
- root);
- }
- if (0 == strcmp (args[0],
- "wire"))
- {
- if (NULL == args[1])
- return TEH_handler_management_post_wire (rc->connection,
- root);
- if ( (0 != strcmp (args[1],
- "disable")) ||
- (NULL != args[2]) )
- {
- GNUNET_break_op (0);
- return r404 (rc->connection,
- "/management/wire/disable");
- }
- return TEH_handler_management_post_wire_disable (rc->connection,
- root);
- }
- if (0 == strcmp (args[0],
- "wire-fee"))
- {
- if (NULL != args[1])
- {
- GNUNET_break_op (0);
- return r404 (rc->connection,
- "/management/wire-fee/*");
+ for (unsigned int i = 0;
+ NULL != plain_posts[i].handler;
+ i++)
+ {
+ if (0 == strcmp (args[0],
+ plain_posts[i].arg0))
+ {
+ if ( ( (NULL == args[1]) &&
+ (NULL == plain_posts[i].arg1) ) ||
+ ( (NULL != args[1]) &&
+ (NULL != plain_posts[i].arg1) &&
+ (0 == strcmp (args[1],
+ plain_posts[i].arg1)) ) )
+ return plain_posts[i].handler (rc->connection,
+ root);
}
- return TEH_handler_management_post_wire_fees (rc->connection,
- root);
- }
- if (0 == strcmp (args[0],
- "global-fee"))
- {
- if (NULL != args[1])
- {
- GNUNET_break_op (0);
- return r404 (rc->connection,
- "/management/global-fee/*");
- }
- return TEH_handler_management_post_global_fees (rc->connection,
- root);
- }
- if (0 == strcmp (args[0],
- "extensions"))
- {
- return TEH_handler_management_post_extensions (rc->connection,
- root);
}
GNUNET_break_op (0);
return r404 (rc->connection,
@@ -939,7 +1426,7 @@ handle_post_management (struct TEH_RequestContext *rc,
/**
- * Handle a get "/management" request.
+ * Handle a GET "/management" request.
*
* @param rc request context
* @param args array of additional options (must be [0] == "keys")
@@ -1020,6 +1507,56 @@ handle_post_auditors (struct TEH_RequestContext *rc,
/**
+ * Generates the response for "/", redirecting the
+ * client to the ``toplevel_redirect_url``.
+ *
+ * @param rc request context
+ * @param args remaining arguments (should be empty)
+ * @return MHD result code
+ */
+static MHD_RESULT
+toplevel_redirect (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ const char *text = "Redirecting to /webui/";
+ struct MHD_Response *response;
+
+ response = MHD_create_response_from_buffer (strlen (text),
+ (void *) text,
+ MHD_RESPMEM_PERSISTENT);
+ if (NULL == response)
+ {
+ GNUNET_break (0);
+ return MHD_NO;
+ }
+ TALER_MHD_add_global_headers (response);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (response,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ "text/plain"));
+ if (MHD_NO ==
+ MHD_add_response_header (response,
+ MHD_HTTP_HEADER_LOCATION,
+ toplevel_redirect_url))
+ {
+ GNUNET_break (0);
+ MHD_destroy_response (response);
+ return MHD_NO;
+ }
+
+ {
+ MHD_RESULT ret;
+
+ ret = MHD_queue_response (rc->connection,
+ MHD_HTTP_FOUND,
+ response);
+ MHD_destroy_response (response);
+ return ret;
+ }
+}
+
+
+/**
* Handle incoming HTTP request.
*
* @param cls closure for MHD daemon (unused)
@@ -1052,15 +1589,11 @@ handle_mhd_request (void *cls,
.data = "User-agent: *\nDisallow: /\n",
.response_code = MHD_HTTP_OK
},
- /* Landing page, tell humans to go away. */
+ /* Landing page, redirect to toplevel_redirect_url */
{
.url = "",
.method = MHD_HTTP_METHOD_GET,
- .handler.get = TEH_handler_static_response,
- .mime_type = "text/plain",
- .data =
- "Hello, I'm the Taler exchange. This HTTP server is not for humans.\n",
- .response_code = MHD_HTTP_OK
+ .handler.get = &toplevel_redirect
},
/* AGPL licensing page, redirect to source. As per the AGPL-license, every
deployment is required to offer the user a download of the source of
@@ -1076,6 +1609,12 @@ handle_mhd_request (void *cls,
.method = MHD_HTTP_METHOD_GET,
.handler.get = &handler_seed
},
+ /* Configuration */
+ {
+ .url = "config",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &TEH_handler_config
+ },
/* Performance metrics */
{
.url = "metrics",
@@ -1100,12 +1639,6 @@ handle_mhd_request (void *cls,
.method = MHD_HTTP_METHOD_GET,
.handler.get = &TEH_keys_get_handler,
},
- /* Requests for wiring information */
- {
- .url = "wire",
- .method = MHD_HTTP_METHOD_GET,
- .handler.get = &TEH_handler_wire
- },
{
.url = "batch-deposit",
.method = MHD_HTTP_METHOD_POST,
@@ -1129,8 +1662,9 @@ handle_mhd_request (void *cls,
{
.url = "reserves",
.method = MHD_HTTP_METHOD_GET,
- .handler.get = &TEH_handler_reserves_get,
- .nargs = 1
+ .handler.get = &handle_get_reserves,
+ .nargs = 2,
+ .nargs_is_upper_bound = true
},
{
.url = "reserves",
@@ -1138,6 +1672,24 @@ handle_mhd_request (void *cls,
.handler.post = &handle_post_reserves,
.nargs = 2
},
+ {
+ .url = "age-withdraw",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &handle_post_age_withdraw,
+ .nargs = 2
+ },
+ {
+ .url = "reserves-attest",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &TEH_handler_reserves_get_attest,
+ .nargs = 1
+ },
+ {
+ .url = "reserves-attest",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &TEH_handler_reserves_attest,
+ .nargs = 1
+ },
/* coins */
{
.url = "coins",
@@ -1148,8 +1700,9 @@ handle_mhd_request (void *cls,
{
.url = "coins",
.method = MHD_HTTP_METHOD_GET,
- .handler.get = TEH_handler_link,
+ .handler.get = &handle_get_coins,
.nargs = 2,
+ .nargs_is_upper_bound = true
},
/* refreshes/$RCH/reveal */
{
@@ -1177,7 +1730,7 @@ handle_mhd_request (void *cls,
.url = "purses",
.method = MHD_HTTP_METHOD_POST,
.handler.post = &handle_post_purses,
- .nargs = 2 // ??
+ .nargs = 2
},
/* Getting purse status */
{
@@ -1186,6 +1739,13 @@ handle_mhd_request (void *cls,
.handler.get = &TEH_handler_purses_get,
.nargs = 2
},
+ /* Deleting purse */
+ {
+ .url = "purses",
+ .method = MHD_HTTP_METHOD_DELETE,
+ .handler.delete = &TEH_handler_purses_delete,
+ .nargs = 1
+ },
/* Getting contracts */
{
.url = "contracts",
@@ -1198,7 +1758,7 @@ handle_mhd_request (void *cls,
.url = "kyc-check",
.method = MHD_HTTP_METHOD_GET,
.handler.get = &TEH_handler_kyc_check,
- .nargs = 1
+ .nargs = 3
},
{
.url = "kyc-proof",
@@ -1212,6 +1772,20 @@ handle_mhd_request (void *cls,
.handler.post = &TEH_handler_kyc_wallet,
.nargs = 0
},
+ {
+ .url = "kyc-webhook",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &TEH_handler_kyc_webhook_get,
+ .nargs = 16, /* more is not plausible */
+ .nargs_is_upper_bound = true
+ },
+ {
+ .url = "kyc-webhook",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &TEH_handler_kyc_webhook_post,
+ .nargs = 16, /* more is not plausible */
+ .nargs_is_upper_bound = true
+ },
/* POST management endpoints */
{
.url = "management",
@@ -1235,6 +1809,28 @@ handle_mhd_request (void *cls,
.nargs = 4,
.nargs_is_upper_bound = true
},
+ /* AML endpoints */
+ {
+ .url = "aml",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &handle_get_aml,
+ .nargs = 4,
+ .nargs_is_upper_bound = true
+ },
+ {
+ .url = "aml",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &handle_post_aml,
+ .nargs = 2
+ },
+ {
+ .url = "webui",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &TEH_handler_spa,
+ .nargs = 1,
+ .nargs_is_upper_bound = true
+ },
+
/* mark end of list */
{
.url = NULL
@@ -1275,30 +1871,8 @@ handle_mhd_request (void *cls,
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_POST))
{
- const char *cl;
-
- /* Maybe check for maximum upload size
- and refuse requests if they are just too big. */
- cl = MHD_lookup_connection_value (connection,
- MHD_HEADER_KIND,
- MHD_HTTP_HEADER_CONTENT_LENGTH);
- if (NULL != cl)
- {
- unsigned long long cv;
- char dummy;
-
- if (1 != sscanf (cl,
- "%llu%c",
- &cv,
- &dummy))
- {
- /* Not valid HTTP request, just close connection. */
- GNUNET_break_op (0);
- return MHD_NO;
- }
- if (cv > TALER_MHD_REQUEST_BUFFER_MAX)
- return TALER_MHD_reply_request_too_large (connection);
- }
+ TALER_MHD_check_content_length (connection,
+ TALER_MHD_REQUEST_BUFFER_MAX);
}
}
@@ -1378,7 +1952,8 @@ handle_mhd_request (void *cls,
continue;
found = true;
/* The URL is a match! What we now do depends on the method. */
- if (0 == strcasecmp (method, MHD_HTTP_METHOD_OPTIONS))
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_OPTIONS))
{
GNUNET_async_scope_restore (&old_scope);
return TALER_MHD_reply_cors_preflight (connection);
@@ -1476,276 +2051,178 @@ handle_mhd_request (void *cls,
/**
- * Load general KYC configuration parameters for the exchange server into the
- * #TEH_kyc_config variable.
+ * Load configuration parameters for the exchange
+ * server into the corresponding global variables.
*
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-parse_kyc_settings (void)
+exchange_serve_process_config (void)
{
+ static struct TALER_CurrencySpecification defspec = {
+ .num_fractional_input_digits = 2,
+ .num_fractional_normal_digits = 2,
+ .num_fractional_trailing_zero_digits = 2
+ };
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
- "exchange",
- "KYC_WITHDRAW_PERIOD",
- &TEH_kyc_config.withdraw_period))
+ TALER_KYCLOGIC_kyc_init (TEH_cfg))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "KYC_WITHDRAW_PERIOD",
- "valid relative time expected");
return GNUNET_SYSERR;
}
- if (GNUNET_TIME_relative_is_zero (TEH_kyc_config.withdraw_period))
- return GNUNET_OK;
if (GNUNET_OK !=
- TALER_config_get_amount (TEH_cfg,
- "exchange",
- "KYC_WITHDRAW_LIMIT",
- &TEH_kyc_config.withdraw_limit))
- return GNUNET_SYSERR;
- if (0 != strcasecmp (TEH_kyc_config.withdraw_limit.currency,
- TEH_currency))
+ GNUNET_CONFIGURATION_get_value_number (TEH_cfg,
+ "exchange",
+ "MAX_REQUESTS",
+ &req_max))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "KYC_WITHDRAW_LIMIT",
- "currency mismatch");
- return GNUNET_SYSERR;
+ req_max = ULLONG_MAX;
}
- return GNUNET_OK;
-}
-
-
-/**
- * Load OAuth2.0 configuration parameters for the exchange server into the
- * #TEH_kyc_config variable.
- *
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_kyc_oauth_cfg (void)
-{
- char *s;
-
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_AUTH_URL",
- &s))
+ GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
+ "exchangedb",
+ "IDLE_RESERVE_EXPIRATION_TIME",
+ &TEH_reserve_closing_delay))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_AUTH_URL");
- return GNUNET_SYSERR;
- }
- if ( (! TALER_url_valid_charset (s)) ||
- ( (0 != strncasecmp (s,
- "http://",
- strlen ("http://"))) &&
- (0 != strncasecmp (s,
- "https://",
- strlen ("https://"))) ) )
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_AUTH_URL",
- "not a valid URL");
- GNUNET_free (s);
- return GNUNET_SYSERR;
+ "exchangedb",
+ "IDLE_RESERVE_EXPIRATION_TIME");
+ /* use default */
+ TEH_reserve_closing_delay
+ = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_WEEKS,
+ 4);
}
- TEH_kyc_config.details.oauth2.auth_url = s;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_LOGIN_URL",
- &s))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_LOGIN_URL");
- return GNUNET_SYSERR;
- }
- if ( (! TALER_url_valid_charset (s)) ||
- ( (0 != strncasecmp (s,
- "http://",
- strlen ("http://"))) &&
- (0 != strncasecmp (s,
- "https://",
- strlen ("https://"))) ) )
+ GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
+ "exchange",
+ "MAX_KEYS_CACHING",
+ &TEH_max_keys_caching))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_LOGIN_URL",
- "not a valid URL");
- GNUNET_free (s);
+ "exchange",
+ "MAX_KEYS_CACHING",
+ "valid relative time expected");
return GNUNET_SYSERR;
}
- TEH_kyc_config.details.oauth2.login_url = s;
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_INFO_URL",
- &s))
+ "exchange",
+ "KYC_AML_TRIGGER",
+ &TEH_kyc_aml_trigger))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_INFO_URL");
- return GNUNET_SYSERR;
- }
- if ( (! TALER_url_valid_charset (s)) ||
- ( (0 != strncasecmp (s,
- "http://",
- strlen ("http://"))) &&
- (0 != strncasecmp (s,
- "https://",
- strlen ("https://"))) ) )
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_INFO_URL",
- "not a valid URL");
- GNUNET_free (s);
+ "exchange",
+ "KYC_AML_TRIGGER");
return GNUNET_SYSERR;
}
- TEH_kyc_config.details.oauth2.info_url = s;
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_CLIENT_ID",
- &s))
+ "exchange",
+ "TOPLEVEL_REDIRECT_URL",
+ &toplevel_redirect_url))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_CLIENT_ID");
- return GNUNET_SYSERR;
+ toplevel_redirect_url = GNUNET_strdup ("/terms");
}
- TEH_kyc_config.details.oauth2.client_id = s;
-
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_CLIENT_SECRET",
- &s))
+ TALER_config_get_currency (TEH_cfg,
+ &TEH_currency))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_CLIENT_SECRET");
+ "taler",
+ "CURRENCY");
return GNUNET_SYSERR;
}
- TEH_kyc_config.details.oauth2.client_secret = s;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_POST_URL",
- &s))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-kyc-oauth2",
- "KYC_OAUTH2_POST_URL");
+ TALER_CONFIG_parse_currencies (TEH_cfg,
+ &num_cspecs,
+ &cspecs))
return GNUNET_SYSERR;
- }
- TEH_kyc_config.details.oauth2.post_kyc_redirect_url = s;
- return GNUNET_OK;
-}
-
-
-/**
- * Load configuration parameters for the exchange
- * server into the corresponding global variables.
- *
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-exchange_serve_process_config (void)
-{
+ for (unsigned int i = 0; i<num_cspecs; i++)
{
- char *kyc_mode;
+ struct TALER_CurrencySpecification *cspec;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
- "exchange",
- "KYC_MODE",
- &kyc_mode))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "KYC_MODE");
- return GNUNET_SYSERR;
- }
- if (0 == strcasecmp (kyc_mode,
- "NONE"))
+ cspec = &cspecs[i];
+ if (0 == strcmp (TEH_currency,
+ cspec->currency))
{
- TEH_kyc_config.mode = TEH_KYC_NONE;
+ TEH_cspec = cspec;
+ break;
}
- else if (0 == strcasecmp (kyc_mode,
- "OAUTH2"))
- {
- TEH_kyc_config.mode = TEH_KYC_OAUTH2;
- if (GNUNET_OK !=
- parse_kyc_oauth_cfg ())
- {
- GNUNET_free (kyc_mode);
- return GNUNET_SYSERR;
- }
- }
- else
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "KYC_MODE",
- "Must be 'NONE' or 'OAUTH2'");
- GNUNET_free (kyc_mode);
- return GNUNET_SYSERR;
- }
- GNUNET_free (kyc_mode);
}
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (TEH_cfg,
- "exchange",
- "MAX_REQUESTS",
- &req_max))
+ if (NULL == TEH_cspec)
{
- req_max = ULLONG_MAX;
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
+ "taler",
+ "CURRENCY",
+ "Lacking enabled currency specification for the given currency, using default");
+ defspec.map_alt_unit_names
+ = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("0",
+ TEH_currency)
+ );
+ defspec.name = TEH_currency;
+ GNUNET_assert (strlen (TEH_currency) <
+ sizeof (defspec.currency));
+ strcpy (defspec.currency,
+ TEH_currency);
+ TEH_cspec = &defspec;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
- "exchangedb",
- "IDLE_RESERVE_EXPIRATION_TIME",
- &TEH_reserve_closing_delay))
+ TALER_config_get_amount (TEH_cfg,
+ "exchange",
+ "AML_THRESHOLD",
+ &TEH_aml_threshold))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchangedb",
- "IDLE_RESERVE_EXPIRATION_TIME");
- /* use default */
- TEH_reserve_closing_delay
- = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_WEEKS,
- 4);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Need amount in section `exchange' under `AML_THRESHOLD'\n");
+ return GNUNET_SYSERR;
}
-
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (TEH_cfg,
- "exchange",
- "MAX_KEYS_CACHING",
- &TEH_max_keys_caching))
+ TALER_config_get_amount (TEH_cfg,
+ "exchange",
+ "STEFAN_ABS",
+ &TEH_stefan_abs))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &TEH_stefan_abs));
+ }
+ if (GNUNET_OK !=
+ TALER_config_get_amount (TEH_cfg,
"exchange",
- "MAX_KEYS_CACHING",
- "valid relative time expected");
- return GNUNET_SYSERR;
+ "STEFAN_LOG",
+ &TEH_stefan_log))
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &TEH_stefan_log));
}
if (GNUNET_OK !=
- TALER_config_get_currency (TEH_cfg,
- &TEH_currency))
+ GNUNET_CONFIGURATION_get_value_float (TEH_cfg,
+ "exchange",
+ "STEFAN_LIN",
+ &TEH_stefan_lin))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
+ TEH_stefan_lin = 0.0f;
+ }
+
+ if (0 != strcmp (TEH_currency,
+ TEH_aml_threshold.currency))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Amount in section `exchange' under `AML_THRESHOLD' uses the wrong currency!\n");
+ return GNUNET_SYSERR;
+ }
+ TEH_enable_rewards
+ = GNUNET_CONFIGURATION_get_value_yesno (
+ TEH_cfg,
+ "exchange",
+ "ENABLE_REWARDS");
+ if (GNUNET_SYSERR == TEH_enable_rewards)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Need YES or NO in section `exchange' under `ENABLE_REWARDS'\n");
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -1768,35 +2245,6 @@ exchange_serve_process_config (void)
return GNUNET_SYSERR;
}
- if (TEH_KYC_NONE != TEH_kyc_config.mode)
- {
- if (GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (TEH_cfg,
- "exchange",
- "KYC_WALLET_BALANCE_LIMIT"))
- {
- if ( (GNUNET_OK !=
- TALER_config_get_amount (TEH_cfg,
- "exchange",
- "KYC_WALLET_BALANCE_LIMIT",
- &TEH_kyc_config.wallet_balance_limit)) ||
- (0 != strcasecmp (TEH_currency,
- TEH_kyc_config.wallet_balance_limit.currency)) )
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "KYC_WALLET_BALANCE_LIMIT",
- "valid amount expected");
- return GNUNET_SYSERR;
- }
- }
- else
- {
- memset (&TEH_kyc_config.wallet_balance_limit,
- 0,
- sizeof (TEH_kyc_config.wallet_balance_limit));
- }
- }
{
char *master_public_key_str;
@@ -1812,34 +2260,58 @@ exchange_serve_process_config (void)
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_public_key_from_string (master_public_key_str,
- strlen (
- master_public_key_str),
- &TEH_master_public_key.
- eddsa_pub))
+ GNUNET_CRYPTO_eddsa_public_key_from_string (
+ master_public_key_str,
+ strlen (master_public_key_str),
+ &TEH_master_public_key.eddsa_pub))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid master public key given in exchange configuration.");
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "MASTER_PUBLIC_KEY",
+ "invalid base32 encoding for a master public key");
GNUNET_free (master_public_key_str);
return GNUNET_SYSERR;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Launching exchange with public key `%s'...\n",
+ master_public_key_str);
GNUNET_free (master_public_key_str);
}
- if (TEH_KYC_NONE != TEH_kyc_config.mode)
+
{
+ char *attr_enc_key_str;
+
if (GNUNET_OK !=
- parse_kyc_settings ())
+ GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
+ "exchange",
+ "ATTRIBUTE_ENCRYPTION_KEY",
+ &attr_enc_key_str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "ATTRIBUTE_ENCRYPTION_KEY");
return GNUNET_SYSERR;
+ }
+ GNUNET_CRYPTO_hash (attr_enc_key_str,
+ strlen (attr_enc_key_str),
+ &TEH_attribute_key.hash);
+ GNUNET_free (attr_enc_key_str);
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Launching exchange with public key `%s'...\n",
- GNUNET_p2s (&TEH_master_public_key.eddsa_pub));
- if (NULL ==
- (TEH_plugin = TALER_EXCHANGEDB_plugin_load (TEH_cfg)))
+ for (unsigned int i = 0; i<MAX_DB_RETRIES; i++)
+ {
+ TEH_plugin = TALER_EXCHANGEDB_plugin_load (TEH_cfg);
+ if (NULL != TEH_plugin)
+ break;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to DB, will try again %u times\n",
+ MAX_DB_RETRIES - i);
+ sleep (1);
+ }
+ if (NULL == TEH_plugin)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to initialize DB subsystem\n");
+ "Failed to initialize DB subsystem. Giving up.\n");
return GNUNET_SYSERR;
}
return GNUNET_OK;
@@ -1984,7 +2456,9 @@ run_single_request (void)
xfork = fork ();
if (-1 == xfork)
{
- global_ret = EXIT_FAILURE;
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "fork");
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -2071,12 +2545,17 @@ do_shutdown (void *cls)
mhd = TALER_MHD_daemon_stop ();
TEH_resume_keys_requests (true);
+ TEH_deposits_get_cleanup ();
TEH_reserves_get_cleanup ();
TEH_purses_get_cleanup ();
TEH_kyc_check_cleanup ();
TEH_kyc_proof_cleanup ();
+ TALER_KYCLOGIC_kyc_done ();
if (NULL != mhd)
+ {
MHD_stop_daemon (mhd);
+ mhd = NULL;
+ }
TEH_wire_done ();
TEH_extensions_done ();
TEH_keys_finished ();
@@ -2095,6 +2574,12 @@ do_shutdown (void *cls)
GNUNET_CURL_gnunet_rc_destroy (exchange_curl_rc);
exchange_curl_rc = NULL;
}
+ TALER_TEMPLATING_done ();
+ TEH_cspec = NULL;
+ TALER_CONFIG_free_currencies (num_cspecs,
+ cspecs);
+ num_cspecs = 0;
+ cspecs = NULL;
}
@@ -2132,31 +2617,48 @@ run (void *cls,
GNUNET_SCHEDULER_shutdown ();
return;
}
+ if (GNUNET_OK !=
+ TEH_spa_init ())
+ {
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TEMPLATING_init ("exchange"))
+ {
+ global_ret = EXIT_NOTINSTALLED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
if (GNUNET_SYSERR ==
TEH_plugin->preflight (TEH_plugin->cls))
{
- global_ret = EXIT_FAILURE;
+ GNUNET_break (0);
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
TEH_extensions_init ())
{
- global_ret = EXIT_FAILURE;
+ global_ret = EXIT_NOTINSTALLED;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
TEH_keys_init ())
{
- global_ret = EXIT_FAILURE;
+ GNUNET_break (0);
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
if (GNUNET_OK !=
TEH_wire_init ())
{
- global_ret = EXIT_FAILURE;
+ GNUNET_break (0);
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -2168,7 +2670,7 @@ run (void *cls,
if (NULL == TEH_curl_ctx)
{
GNUNET_break (0);
- global_ret = EXIT_FAILURE;
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -2221,7 +2723,6 @@ run (void *cls,
global_ret = EXIT_SUCCESS;
TALER_MHD_daemon_start (mhd);
atexit (&write_stats);
-
#if HAVE_DEVELOPER
if (NULL != input_filename)
run_single_request ();
diff --git a/src/exchange/taler-exchange-httpd.h b/src/exchange/taler-exchange-httpd.h
index 278a05be9..25e9e1105 100644
--- a/src/exchange/taler-exchange-httpd.h
+++ b/src/exchange/taler-exchange-httpd.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2020 Taler Systems SA
+ Copyright (C) 2014-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -25,113 +25,13 @@
#include <microhttpd.h>
#include "taler_json_lib.h"
-#include "taler_crypto_lib.h"
+#include "taler_util.h"
+#include "taler_kyclogic_plugin.h"
#include "taler_extensions.h"
#include <gnunet/gnunet_mhd_compat.h>
/**
- * Enumeration for our KYC modes.
- */
-enum TEH_KycMode
-{
- /**
- * KYC is disabled.
- */
- TEH_KYC_NONE = 0,
-
- /**
- * We use Oauth2.0.
- */
- TEH_KYC_OAUTH2 = 1
-};
-
-
-/**
- * Structure describing our KYC configuration.
- */
-struct TEH_KycOptions
-{
- /**
- * What KYC mode are we in?
- */
- enum TEH_KycMode mode;
-
- /**
- * Maximum amount that can be withdrawn in @e withdraw_period without
- * needing KYC.
- * Only valid if @e mode is not #TEH_KYC_NONE and
- * if @e withdraw_period is non-zero.
- */
- struct TALER_Amount withdraw_limit;
-
- /**
- * Maximum balance a wallet can hold without
- * needing KYC.
- * Only valid if @e mode is not #TEH_KYC_NONE and
- * if the amount specified is valid.
- */
- struct TALER_Amount wallet_balance_limit;
-
- /**
- * Time period over which @e withdraw_limit applies.
- * Only valid if @e mode is not #TEH_KYC_NONE.
- */
- struct GNUNET_TIME_Relative withdraw_period;
-
- /**
- * Details depending on @e mode.
- */
- union
- {
-
- /**
- * Configuration details if @e mode is #TEH_KYC_OAUTH2.
- */
- struct
- {
-
- /**
- * URL of the OAuth2.0 endpoint for KYC checks.
- * (token/auth)
- */
- char *auth_url;
-
- /**
- * URL of the OAuth2.0 endpoint for KYC checks.
- */
- char *login_url;
-
- /**
- * URL of the user info access endpoint.
- */
- char *info_url;
-
- /**
- * Our client ID for OAuth2.0.
- */
- char *client_id;
-
- /**
- * Our client secret for OAuth2.0.
- */
- char *client_secret;
-
- /**
- * Where to redirect clients after the
- * Web-based KYC process is done?
- */
- char *post_kyc_redirect_url;
-
- } oauth2;
-
- } details;
-};
-
-
-extern struct TEH_KycOptions TEH_kyc_config;
-
-/**
* How long is caching /keys allowed at most?
*/
extern struct GNUNET_TIME_Relative TEH_max_keys_caching;
@@ -165,6 +65,11 @@ extern int TEH_check_invariants_flag;
extern int TEH_allow_keys_timetravel;
/**
+ * Option set to #GNUNET_YES if rewards are allowed.
+ */
+extern int TEH_enable_rewards;
+
+/**
* Main directory with revocation data.
*/
extern char *TEH_revocation_directory;
@@ -183,19 +88,51 @@ extern bool TEH_suicide;
extern struct TALER_MasterPublicKeyP TEH_master_public_key;
/**
+ * Key used to encrypt KYC attribute data in our database.
+ */
+extern struct TALER_AttributeEncryptionKeyP TEH_attribute_key;
+
+/**
* Our DB plugin.
*/
extern struct TALER_EXCHANGEDB_Plugin *TEH_plugin;
/**
+ * Absolute STEFAN parameter.
+ */
+extern struct TALER_Amount TEH_stefan_abs;
+
+/**
+ * Logarithmic STEFAN parameter.
+ */
+extern struct TALER_Amount TEH_stefan_log;
+
+/**
+ * Linear STEFAN parameter.
+ */
+extern float TEH_stefan_lin;
+
+/**
+ * Default ways how to render #TEH_currency amounts.
+ */
+extern const struct TALER_CurrencySpecification *TEH_cspec;
+
+/**
* Our currency.
*/
extern char *TEH_currency;
-/*
- * Age restriction extension state
+/**
+ * Name of the KYC-AML-trigger evaluation binary.
*/
-extern bool TEH_age_restriction_enabled;
+extern char *TEH_kyc_aml_trigger;
+
+/**
+ * What is the largest amount we allow a peer to
+ * merge into a reserve before always triggering
+ * an AML check?
+ */
+extern struct TALER_Amount TEH_aml_threshold;
/**
* Our (externally visible) base URL.
@@ -216,6 +153,7 @@ extern struct GNUNET_CURL_Context *TEH_curl_ctx;
* Signature of the offline master key of all enabled extensions' configuration
*/
extern struct TALER_MasterSignatureP TEH_extensions_sig;
+extern bool TEH_extensions_signed;
/**
* @brief Struct describing an URL and the handler for it.
@@ -261,6 +199,11 @@ struct TEH_RequestContext
struct MHD_Connection *connection;
/**
+ * JSON root of uploaded data (or NULL, if none).
+ */
+ json_t *root;
+
+ /**
* @e rh-specific cleanup routine. Function called
* upon completion of the request that should
* clean up @a rh_ctx. Can be NULL.
@@ -300,11 +243,10 @@ struct TEH_RequestHandler
union
{
/**
- * Function to call to handle a GET requests (and those
+ * Function to call to handle GET requests (and those
* with @e method NULL).
*
* @param rc context for the request
- * @param mime_type the @e mime_type for the reply (hint, can be NULL)
* @param args array of arguments, needs to be of length @e args_expected
* @return MHD result code
*/
@@ -314,11 +256,11 @@ struct TEH_RequestHandler
/**
- * Function to call to handle a POST request.
+ * Function to call to handle POST requests.
*
* @param rc context for the request
* @param json uploaded JSON data
- * @param args array of arguments, needs to be of length @e args_expected
+ * @param args array of arguments, needs to be of length @e nargs
* @return MHD result code
*/
MHD_RESULT
@@ -326,18 +268,18 @@ struct TEH_RequestHandler
const json_t *root,
const char *const args[]);
- } handler;
-
- /**
- * Number of arguments this handler expects in the @a args array.
- */
- unsigned int nargs;
+ /**
+ * Function to call to handle DELETE requests.
+ *
+ * @param rc context for the request
+ * @param args array of arguments, needs to be of length @e nargs
+ * @return MHD result code
+ */
+ MHD_RESULT
+ (*delete)(struct TEH_RequestContext *rc,
+ const char *const args[]);
- /**
- * Is the number of arguments given in @e nargs only an upper bound,
- * and calling with fewer arguments could be OK?
- */
- bool nargs_is_upper_bound;
+ } handler;
/**
* Mime type to use in reply (hint, can be NULL).
@@ -358,7 +300,22 @@ struct TEH_RequestHandler
* Default response code. 0 for none provided.
*/
unsigned int response_code;
+
+ /**
+ * Number of arguments this handler expects in the @a args array.
+ */
+ unsigned int nargs;
+
+ /**
+ * Is the number of arguments given in @e nargs only an upper bound,
+ * and calling with fewer arguments could be OK?
+ */
+ bool nargs_is_upper_bound;
};
+/* Age restriction configuration */
+extern bool TEH_age_restriction_enabled;
+extern struct TALER_AgeRestrictionConfig TEH_age_restriction_config;
+
#endif
diff --git a/src/exchange/taler-exchange-httpd_age-withdraw.c b/src/exchange/taler-exchange-httpd_age-withdraw.c
new file mode 100644
index 000000000..9276fb191
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_age-withdraw.c
@@ -0,0 +1,1019 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty
+ of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General
+ Public License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_age-withdraw.c
+ * @brief Handle /reserves/$RESERVE_PUB/age-withdraw requests
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+#include "taler_error_codes.h"
+#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_age-withdraw.h"
+#include "taler-exchange-httpd_responses.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler_util.h"
+
+
+/**
+ * Context for #age_withdraw_transaction.
+ */
+struct AgeWithdrawContext
+{
+ /**
+ * KYC status for the operation.
+ */
+ struct TALER_EXCHANGEDB_KycStatus kyc;
+
+ /**
+ * Timestamp
+ */
+ struct GNUNET_TIME_Timestamp now;
+
+ /**
+ * Hash of the wire source URL, needed when kyc is needed.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * The data from the age-withdraw request, as we persist it
+ */
+ struct TALER_EXCHANGEDB_AgeWithdraw commitment;
+
+ /**
+ * Number of coins/denonations in the reveal
+ */
+ uint32_t num_coins;
+
+ /**
+ * #num_coins * #kappa hashes of blinded coin planchets.
+ */
+ struct TALER_BlindedPlanchet (*coin_evs) [ TALER_CNC_KAPPA];
+
+ /**
+ * #num_coins hashes of the denominations from which the coins are withdrawn.
+ * Those must support age restriction.
+ */
+ struct TALER_DenominationHashP *denom_hs;
+
+};
+
+/*
+ * @brief Free the resources within a AgeWithdrawContext
+ *
+ * @param awc the context to free
+ */
+static void
+free_age_withdraw_context_resources (struct AgeWithdrawContext *awc)
+{
+ GNUNET_free (awc->denom_hs);
+ GNUNET_free (awc->coin_evs);
+ GNUNET_free (awc->commitment.denom_serials);
+ /*
+ * Note:
+ * awc->commitment.denom_sigs and .h_coin_evs were stack allocated and
+ * .denom_pub_hashes is NULL for this context.
+ */
+}
+
+
+/**
+ * Parse the denominations and blinded coin data of an '/age-withdraw' request.
+ *
+ * @param connection The MHD connection to handle
+ * @param j_denom_hs Array of n hashes of the denominations for the withdrawal, in JSON format
+ * @param j_blinded_coin_evs Array of n arrays of kappa blinded envelopes of in JSON format for the coins.
+ * @param[out] awc The context of the operation, only partially built at call time
+ * @param[out] mhd_ret The result if a reply is queued for MHD
+ * @return true on success, false on failure, with a reply already queued for MHD
+ */
+static enum GNUNET_GenericReturnValue
+parse_age_withdraw_json (
+ struct MHD_Connection *connection,
+ const json_t *j_denom_hs,
+ const json_t *j_blinded_coin_evs,
+ struct AgeWithdrawContext *awc,
+ MHD_RESULT *mhd_ret)
+{
+ char buf[256] = {0};
+ const char *error = NULL;
+ unsigned int idx = 0;
+ json_t *value = NULL;
+ struct GNUNET_HashContext *hash_context;
+
+
+ /* The age value MUST be on the beginning of an age group */
+ if (awc->commitment.max_age !=
+ TALER_get_lowest_age (&TEH_age_restriction_config.mask,
+ awc->commitment.max_age))
+ {
+ error = "max_age must be the lower edge of an age group";
+ goto EXIT;
+ }
+
+ /* Verify JSON-structure consistency */
+ {
+ uint32_t num_coins = json_array_size (j_denom_hs);
+
+ if (! json_is_array (j_denom_hs))
+ error = "denoms_h must be an array";
+ else if (! json_is_array (j_blinded_coin_evs))
+ error = "coin_evs must be an array";
+ else if (num_coins == 0)
+ error = "denoms_h must not be empty";
+ else if (num_coins != json_array_size (j_blinded_coin_evs))
+ error = "denoms_h and coins_evs must be arrays of the same size";
+ else if (num_coins > TALER_MAX_FRESH_COINS)
+ /**
+ * The wallet had committed to more than the maximum coins allowed, the
+ * reserve has been charged, but now the user can not withdraw any money
+ * from it. Note that the user can't get their money back in this case!
+ **/
+ error = "maximum number of coins that can be withdrawn has been exceeded";
+
+ _Static_assert ((TALER_MAX_FRESH_COINS < INT_MAX / TALER_CNC_KAPPA),
+ "TALER_MAX_FRESH_COINS too large");
+
+ if (NULL != error)
+ goto EXIT;
+
+ awc->num_coins = num_coins;
+ awc->commitment.num_coins = num_coins;
+ }
+
+ /* Continue parsing the parts */
+
+ /* Parse denomination keys */
+ awc->denom_hs = GNUNET_new_array (awc->num_coins,
+ struct TALER_DenominationHashP);
+
+ json_array_foreach (j_denom_hs, idx, value) {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (NULL, &awc->denom_hs[idx]),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value, spec, NULL, NULL))
+ {
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "couldn't parse entry no. %d in array denoms_h",
+ idx + 1);
+ error = buf;
+ goto EXIT;
+ }
+ };
+
+ {
+ typedef struct TALER_BlindedPlanchet
+ _array_of_kappa_planchets[TALER_CNC_KAPPA];
+
+ awc->coin_evs = GNUNET_new_array (awc->num_coins,
+ _array_of_kappa_planchets);
+ }
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+ GNUNET_assert (NULL != hash_context);
+
+ /* Parse blinded envelopes. */
+ json_array_foreach (j_blinded_coin_evs, idx, value) {
+ const json_t *j_kappa_coin_evs = value;
+ if (! json_is_array (j_kappa_coin_evs))
+ {
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "enxtry %d in array blinded_coin_evs is not an array",
+ idx + 1);
+ error = buf;
+ goto EXIT;
+ }
+ else if (TALER_CNC_KAPPA != json_array_size (j_kappa_coin_evs))
+ {
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "array no. %d in coin_evs not of correct size",
+ idx + 1);
+ error = buf;
+ goto EXIT;
+ }
+
+ /* Now parse the individual kappa envelopes and calculate the hash of
+ * the commitment along the way. */
+ {
+ unsigned int kappa = 0;
+
+ json_array_foreach (j_kappa_coin_evs, kappa, value) {
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_blinded_planchet (NULL,
+ &awc->coin_evs[idx][kappa]),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_snprintf (buf,
+ sizeof(buf),
+ "couldn't parse array no. %d in blinded_coin_evs[%d]",
+ kappa + 1,
+ idx + 1);
+ error = buf;
+ goto EXIT;
+ }
+
+ /* Continue to hash of the coin candidates */
+ {
+ struct TALER_BlindedCoinHashP bch;
+
+ TALER_coin_ev_hash (&awc->coin_evs[idx][kappa],
+ &awc->denom_hs[idx],
+ &bch);
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ &bch,
+ sizeof(bch));
+ }
+
+ /* Check for duplicate planchets. Technically a bug on
+ * the client side that is harmless for us, but still
+ * not allowed per protocol */
+ for (unsigned int i = 0; i < idx; i++)
+ {
+ if (0 == TALER_blinded_planchet_cmp (&awc->coin_evs[idx][kappa],
+ &awc->coin_evs[i][kappa]))
+ {
+ GNUNET_JSON_parse_free (spec);
+ error = "duplicate planchet";
+ goto EXIT;
+ }
+ }
+ }
+ }
+ }; /* json_array_foreach over j_blinded_coin_evs */
+
+ /* Finally, calculate the h_commitment from all blinded envelopes */
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ &awc->commitment.h_commitment.hash);
+
+ GNUNET_assert (NULL == error);
+
+
+EXIT:
+ if (NULL != error)
+ {
+ /* Note: resources are freed in caller */
+
+ *mhd_ret = TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ error);
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Check if the given denomination is still or already valid, has not been
+ * revoked and supports age restriction.
+ *
+ * @param connection HTTP-connection to the client
+ * @param ksh The handle to the current state of (denomination) keys in the exchange
+ * @param denom_h Hash of the denomination key to check
+ * @param[out] pdk On success, will contain the denomination key details
+ * @param[out] result On failure, an MHD-response will be queued and result will be set to accordingly
+ * @return true on success (denomination valid), false otherwise
+ */
+static bool
+denomination_is_valid (
+ struct MHD_Connection *connection,
+ struct TEH_KeyStateHandle *ksh,
+ const struct TALER_DenominationHashP *denom_h,
+ struct TEH_DenominationKey **pdk,
+ MHD_RESULT *result)
+{
+ struct TEH_DenominationKey *dk;
+ dk = TEH_keys_denomination_by_hash_from_state (ksh,
+ denom_h,
+ connection,
+ result);
+ if (NULL == dk)
+ {
+ /* The denomination doesn't exist */
+ /* Note: a HTTP-response has been queued and result has been set by
+ * TEH_keys_denominations_by_hash_from_state */
+ return false;
+ }
+
+ if (GNUNET_TIME_absolute_is_past (dk->meta.expire_withdraw.abs_time))
+ {
+ /* This denomination is past the expiration time for withdraws */
+ /* FIXME[oec]: add idempotency check */
+ *result = TEH_RESPONSE_reply_expired_denom_pub_hash (
+ connection,
+ denom_h,
+ TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED,
+ "age-withdraw_reveal");
+ return false;
+ }
+
+ if (GNUNET_TIME_absolute_is_future (dk->meta.start.abs_time))
+ {
+ /* This denomination is not yet valid */
+ *result = TEH_RESPONSE_reply_expired_denom_pub_hash (
+ connection,
+ denom_h,
+ TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE,
+ "age-withdraw_reveal");
+ return false;
+ }
+
+ if (dk->recoup_possible)
+ {
+ /* This denomination has been revoked */
+ *result = TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
+ NULL);
+ return false;
+ }
+
+ if (0 == dk->denom_pub.age_mask.bits)
+ {
+ /* This denomation does not support age restriction */
+ char msg[256] = {0};
+ GNUNET_snprintf (msg,
+ sizeof(msg),
+ "denomination %s does not support age restriction",
+ GNUNET_h2s (&denom_h->hash));
+
+ *result = TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
+ msg);
+ return false;
+ }
+
+ *pdk = dk;
+ return true;
+}
+
+
+/**
+ * Check if the given array of hashes of denomination_keys a) belong
+ * to valid denominations and b) those are marked as age restricted.
+ * Also, calculate the total amount of the denominations including fees
+ * for withdraw.
+ *
+ * @param connection The HTTP connection to the client
+ * @param len The lengths of the array @a denoms_h
+ * @param denom_hs array of hashes of denomination public keys
+ * @param coin_evs array of blinded coin planchet candidates
+ * @param[out] denom_serials On success, will be filled with the serial-id's of the denomination keys. Caller must deallocate.
+ * @param[out] amount_with_fee On success, will contain the committed amount including fees
+ * @param[out] result In the error cases, a response will be queued with MHD and this will be the result.
+ * @return #GNUNET_OK if the denominations are valid and support age-restriction
+ * #GNUNET_SYSERR otherwise
+ */
+static enum GNUNET_GenericReturnValue
+are_denominations_valid (
+ struct MHD_Connection *connection,
+ uint32_t len,
+ const struct TALER_DenominationHashP *denom_hs,
+ const struct TALER_BlindedPlanchet (*coin_evs) [ TALER_CNC_KAPPA],
+ uint64_t **denom_serials,
+ struct TALER_Amount *amount_with_fee,
+ MHD_RESULT *result)
+{
+ struct TALER_Amount total_amount;
+ struct TALER_Amount total_fee;
+ struct TEH_KeyStateHandle *ksh;
+ uint64_t *serials;
+
+ ksh = TEH_keys_get_state ();
+ if (NULL == ksh)
+ {
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+
+ *denom_serials =
+ serials = GNUNET_new_array (len, uint64_t);
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &total_amount));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &total_fee));
+
+ for (uint32_t i = 0; i < len; i++)
+ {
+ struct TEH_DenominationKey *dk;
+ if (! denomination_is_valid (connection,
+ ksh,
+ &denom_hs[i],
+ &dk,
+ result))
+ /* FIXME[oec]: add idempotency check */
+ return GNUNET_SYSERR;
+
+ /* Ensure the ciphers from the planchets match the denominations' */
+ for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
+ {
+ if (dk->denom_pub.bsign_pub_key->cipher !=
+ coin_evs[i][k].blinded_message->cipher)
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_GENERIC_CIPHER_MISMATCH,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+ }
+
+ /* Accumulate the values */
+ if (0 > TALER_amount_add (&total_amount,
+ &total_amount,
+ &dk->meta.value))
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_AMOUNT_OVERFLOW,
+ "amount");
+ return GNUNET_SYSERR;
+ }
+
+ /* Accumulate the withdraw fees */
+ if (0 > TALER_amount_add (&total_fee,
+ &total_fee,
+ &dk->meta.fees.withdraw))
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_AMOUNT_OVERFLOW,
+ "fee");
+ return GNUNET_SYSERR;
+ }
+
+ serials[i] = dk->meta.serial;
+ }
+
+ /* Save the total amount including fees */
+ GNUNET_assert (0 < TALER_amount_add (amount_with_fee,
+ &total_amount,
+ &total_fee));
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * @brief Verify the signature of the request body with the reserve key
+ *
+ * @param connection the connection to the client
+ * @param commitment the age withdraw commitment
+ * @param mhd_ret the response to fill in the error case
+ * @return GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+verify_reserve_signature (
+ struct MHD_Connection *connection,
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ enum MHD_Result *mhd_ret)
+{
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_wallet_age_withdraw_verify (&commitment->h_commitment,
+ &commitment->amount_with_fee,
+ &TEH_age_restriction_config.mask,
+ commitment->max_age,
+ &commitment->reserve_pub,
+ &commitment->reserve_sig))
+ {
+ GNUNET_break_op (0);
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_WITHDRAW_RESERVE_SIGNATURE_INVALID,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Send a response to a "age-withdraw" request.
+ *
+ * @param connection the connection to send the response to
+ * @param ach value the client committed to
+ * @param noreveal_index which index will the client not have to reveal
+ * @return a MHD status code
+ */
+static MHD_RESULT
+reply_age_withdraw_success (
+ struct MHD_Connection *connection,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ uint32_t noreveal_index)
+{
+ struct TALER_ExchangePublicKeyP pub;
+ struct TALER_ExchangeSignatureP sig;
+ enum TALER_ErrorCode ec =
+ TALER_exchange_online_age_withdraw_confirmation_sign (
+ &TEH_keys_exchange_sign_,
+ ach,
+ noreveal_index,
+ &pub,
+ &sig);
+
+ if (TALER_EC_NONE != ec)
+ return TALER_MHD_reply_with_ec (connection,
+ ec,
+ NULL);
+
+ return TALER_MHD_REPLY_JSON_PACK (connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_uint64 ("noreveal_index",
+ noreveal_index),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &pub));
+}
+
+
+/**
+ * Check if the request is replayed and we already have an
+ * answer. If so, replay the existing answer and return the
+ * HTTP response.
+ *
+ * @param con connection to the client
+ * @param[in,out] awc parsed request data
+ * @param[out] mret HTTP status, set if we return true
+ * @return true if the request is idempotent with an existing request
+ * false if we did not find the request in the DB and did not set @a mret
+ */
+static bool
+request_is_idempotent (struct MHD_Connection *con,
+ struct AgeWithdrawContext *awc,
+ MHD_RESULT *mret)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_EXCHANGEDB_AgeWithdraw commitment;
+
+ qs = TEH_plugin->get_age_withdraw (TEH_plugin->cls,
+ &awc->commitment.reserve_pub,
+ &awc->commitment.h_commitment,
+ &commitment);
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mret = TALER_MHD_reply_with_ec (con,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_age_withdraw");
+ return true; /* Well, kind-of. At least we have set mret. */
+ }
+
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ return false;
+
+ /* Generate idempotent reply */
+ TEH_METRICS_num_requests[TEH_MT_REQUEST_IDEMPOTENT_AGE_WITHDRAW]++;
+ *mret = reply_age_withdraw_success (con,
+ &commitment.h_commitment,
+ commitment.noreveal_index);
+ return true;
+}
+
+
+/**
+ * Function called to iterate over KYC-relevant transaction amounts for a
+ * particular time range. Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param cls closure, identifies the event type and account to iterate
+ * over events for
+ * @param limit maximum time-range for which events should be fetched
+ * (timestamp in the past)
+ * @param cb function to call on each event found, events must be returned
+ * in reverse chronological order
+ * @param cb_cls closure for @a cb, of type struct AgeWithdrawContext
+ */
+static void
+age_withdraw_amount_cb (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
+{
+ struct AgeWithdrawContext *awc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Signaling amount %s for KYC check during age-withdrawal\n",
+ TALER_amount2s (&awc->commitment.amount_with_fee));
+ if (GNUNET_OK !=
+ cb (cb_cls,
+ &awc->commitment.amount_with_fee,
+ awc->now.abs_time))
+ return;
+ qs = TEH_plugin->select_withdraw_amounts_for_kyc_check (TEH_plugin->cls,
+ &awc->h_payto,
+ limit,
+ cb,
+ cb_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got %d additional transactions for this age-withdrawal and limit %llu\n",
+ qs,
+ (unsigned long long) limit.abs_value_us);
+ GNUNET_break (qs >= 0);
+}
+
+
+/**
+ * Function implementing age withdraw transaction. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction
+ * logic MUST NOT queue a MHD response. IF it returns an hard error,
+ * the transaction logic MUST queue a MHD response and set @a mhd_ret.
+ * IF it returns the soft error code, the function MAY be called again
+ * to retry and MUST not queue a MHD response.
+ *
+ * @param cls a `struct AgeWithdrawContext *`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+age_withdraw_transaction (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct AgeWithdrawContext *awc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->reserves_get_origin (TEH_plugin->cls,
+ &awc->commitment.reserve_pub,
+ &awc->h_payto);
+ if (qs < 0)
+ return qs;
+
+ /* If _no_ results, reserve was created by merge,
+ in which case no KYC check is required as the
+ merge already did that. */
+
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ char *kyc_required;
+
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_AGE_WITHDRAW,
+ &awc->h_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &age_withdraw_amount_cb,
+ awc,
+ &kyc_required);
+
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "kyc_test_required");
+ }
+ return qs;
+ }
+
+ if (NULL != kyc_required)
+ {
+ /* Mark result and return by inserting KYC requirement into DB! */
+ awc->kyc.ok = false;
+ return TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ kyc_required,
+ &awc->h_payto,
+ &awc->commitment.reserve_pub,
+ &awc->kyc.requirement_row);
+ }
+ }
+
+ awc->kyc.ok = true;
+
+ /* KYC requirement fulfilled, do the age-withdraw transaction */
+ {
+ bool found = false;
+ bool balance_ok = false;
+ bool age_ok = false;
+ bool conflict = false;
+ uint16_t allowed_maximum_age = 0;
+ uint32_t reserve_birthday = 0;
+ struct TALER_Amount reserve_balance;
+
+ qs = TEH_plugin->do_age_withdraw (TEH_plugin->cls,
+ &awc->commitment,
+ awc->now,
+ &found,
+ &balance_ok,
+ &reserve_balance,
+ &age_ok,
+ &allowed_maximum_age,
+ &reserve_birthday,
+ &conflict);
+ if (0 > qs)
+ {
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "do_age_withdraw");
+ return qs;
+ }
+ if (! found)
+ {
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (! age_ok)
+ {
+ enum TALER_ErrorCode ec =
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_MAXIMUM_AGE_TOO_LARGE;
+
+ *mhd_ret =
+ TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_MHD_PACK_EC (ec),
+ GNUNET_JSON_pack_uint64 ("allowed_maximum_age",
+ allowed_maximum_age),
+ GNUNET_JSON_pack_uint64 ("reserve_birthday",
+ reserve_birthday));
+
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (! balance_ok)
+ {
+ TEH_plugin->rollback (TEH_plugin->cls);
+
+ *mhd_ret = TEH_RESPONSE_reply_reserve_insufficient_balance (
+ connection,
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_INSUFFICIENT_FUNDS,
+ &reserve_balance,
+ &awc->commitment.amount_with_fee,
+ &awc->commitment.reserve_pub);
+
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (conflict)
+ {
+ /* do_age_withdraw signaled a conflict, so there MUST be an entry
+ * in the DB. Put that into the response */
+ bool ok = request_is_idempotent (connection,
+ awc,
+ mhd_ret);
+ GNUNET_assert (ok);
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ *mhd_ret = -1;
+ }
+
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ TEH_METRICS_num_success[TEH_MT_SUCCESS_AGE_WITHDRAW]++;
+ return qs;
+}
+
+
+/**
+ * @brief Sign the chosen blinded coins, debit the reserve and persist
+ * the commitment.
+ *
+ * On conflict, the noreveal_index from the previous, existing
+ * commitment is returned to the client, returning success.
+ *
+ * On error (like, insufficient funds), the client is notified.
+ *
+ * Note that on success, there are two possible states:
+ * 1.) KYC is required (awc.kyc.ok == false) or
+ * 2.) age withdraw was successful.
+ *
+ * @param connection HTTP-connection to the client
+ * @param awc The context for the current age withdraw request
+ * @param[out] result On error, a HTTP-response will be queued and result set accordingly
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+static enum GNUNET_GenericReturnValue
+sign_and_do_age_withdraw (
+ struct MHD_Connection *connection,
+ struct AgeWithdrawContext *awc,
+ MHD_RESULT *result)
+{
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
+ struct TALER_BlindedCoinHashP h_coin_evs[awc->num_coins];
+ struct TALER_BlindedDenominationSignature denom_sigs[awc->num_coins];
+ uint8_t noreveal_index;
+
+ awc->now = GNUNET_TIME_timestamp_get ();
+
+ /* Pick the challenge */
+ noreveal_index =
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
+ TALER_CNC_KAPPA);
+
+ awc->commitment.noreveal_index = noreveal_index;
+
+ /* Choose and sign the coins */
+ {
+ struct TEH_CoinSignData csds[awc->num_coins];
+ enum TALER_ErrorCode ec;
+
+ /* Pick the chosen blinded coins */
+ for (uint32_t i = 0; i<awc->num_coins; i++)
+ {
+ csds[i].bp = &awc->coin_evs[i][noreveal_index];
+ csds[i].h_denom_pub = &awc->denom_hs[i];
+ }
+
+ ec = TEH_keys_denomination_batch_sign (awc->num_coins,
+ csds,
+ false,
+ denom_sigs);
+ if (TALER_EC_NONE != ec)
+ {
+ GNUNET_break (0);
+ *result = TALER_MHD_reply_with_ec (connection,
+ ec,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Signatures ready, starting DB interaction\n");
+
+ /* Prepare the hashes of the coins for insertion */
+ for (uint32_t i = 0; i<awc->num_coins; i++)
+ {
+ TALER_coin_ev_hash (&awc->coin_evs[i][noreveal_index],
+ &awc->denom_hs[i],
+ &h_coin_evs[i]);
+ }
+
+ /* Run the transaction */
+ awc->commitment.h_coin_evs = h_coin_evs;
+ awc->commitment.denom_sigs = denom_sigs;
+ ret = TEH_DB_run_transaction (connection,
+ "run age withdraw",
+ TEH_MT_REQUEST_AGE_WITHDRAW,
+ result,
+ &age_withdraw_transaction,
+ awc);
+ /* Free resources */
+ for (unsigned int i = 0; i<awc->num_coins; i++)
+ TALER_blinded_denom_sig_free (&denom_sigs[i]);
+ awc->commitment.h_coin_evs = NULL;
+ awc->commitment.denom_sigs = NULL;
+ return ret;
+}
+
+
+MHD_RESULT
+TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root)
+{
+ MHD_RESULT mhd_ret;
+ const json_t *j_denom_hs;
+ const json_t *j_blinded_coin_evs;
+ struct AgeWithdrawContext awc = {0};
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("denom_hs",
+ &j_denom_hs),
+ GNUNET_JSON_spec_array_const ("blinded_coin_evs",
+ &j_blinded_coin_evs),
+ GNUNET_JSON_spec_uint16 ("max_age",
+ &awc.commitment.max_age),
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &awc.commitment.reserve_sig),
+ GNUNET_JSON_spec_end ()
+ };
+
+ awc.commitment.reserve_pub = *reserve_pub;
+
+
+ /* Parse the JSON body */
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (rc->connection,
+ root,
+ spec);
+ if (GNUNET_OK != res)
+ return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
+ }
+
+ do {
+ /* Note: If we break the statement here at any point,
+ * a response to the client MUST have been populated
+ * with an appropriate answer and mhd_ret MUST have
+ * been set accordingly.
+ */
+
+ /* Parse denoms_h and blinded_coins_evs, partially fill awc */
+ if (GNUNET_OK !=
+ parse_age_withdraw_json (rc->connection,
+ j_denom_hs,
+ j_blinded_coin_evs,
+ &awc,
+ &mhd_ret))
+ break;
+
+ /* Ensure validity of denoms and calculate amounts and fees */
+ if (GNUNET_OK !=
+ are_denominations_valid (rc->connection,
+ awc.num_coins,
+ awc.denom_hs,
+ awc.coin_evs,
+ &awc.commitment.denom_serials,
+ &awc.commitment.amount_with_fee,
+ &mhd_ret))
+ break;
+
+ /* Now that amount_with_fee is calculated, verify the signature of
+ * the request body with the reserve key.
+ */
+ if (GNUNET_OK !=
+ verify_reserve_signature (rc->connection,
+ &awc.commitment,
+ &mhd_ret))
+ break;
+
+ /* Sign the chosen blinded coins, persist the commitment and
+ * charge the reserve.
+ * On error (like, insufficient funds), the client is notified.
+ * On conflict, the noreveal_index from the previous, existing
+ * commitment is returned to the client, returning success.
+ * Note that on success, there are two possible states:
+ * KYC is required (awc.kyc.ok == false) or
+ * age withdraw was successful.
+ */
+ if (GNUNET_OK !=
+ sign_and_do_age_withdraw (rc->connection,
+ &awc,
+ &mhd_ret))
+ break;
+
+ /* Send back final response, depending on the outcome of
+ * the DB-transaction */
+ if (! awc.kyc.ok)
+ mhd_ret = TEH_RESPONSE_reply_kyc_required (rc->connection,
+ &awc.h_payto,
+ &awc.kyc);
+ else
+ mhd_ret = reply_age_withdraw_success (rc->connection,
+ &awc.commitment.h_commitment,
+ awc.commitment.noreveal_index);
+
+ } while (0);
+
+ GNUNET_JSON_parse_free (spec);
+ free_age_withdraw_context_resources (&awc);
+ return mhd_ret;
+
+}
+
+
+/* end of taler-exchange-httpd_age-withdraw.c */
diff --git a/src/exchange/taler-exchange-httpd_withdraw.h b/src/exchange/taler-exchange-httpd_age-withdraw.h
index 2ec76bb92..a76779190 100644
--- a/src/exchange/taler-exchange-httpd_withdraw.h
+++ b/src/exchange/taler-exchange-httpd_age-withdraw.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,25 +14,25 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file taler-exchange-httpd_withdraw.h
- * @brief Handle /reserve/withdraw requests
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
+ * @file taler-exchange-httpd_age-withdraw.h
+ * @brief Handle /reserve/$RESERVE_PUB/age-withdraw requests
+ * @author Özgür Kesim
*/
-#ifndef TALER_EXCHANGE_HTTPD_WITHDRAW_H
-#define TALER_EXCHANGE_HTTPD_WITHDRAW_H
+#ifndef TALER_EXCHANGE_HTTPD_AGE_WITHDRAW_H
+#define TALER_EXCHANGE_HTTPD_AGE_WITHDRAW_H
#include <microhttpd.h>
#include "taler-exchange-httpd.h"
/**
- * Handle a "/reserves/$RESERVE_PUB/withdraw" request. Parses the requested "denom_pub" which
- * specifies the key/value of the coin to be withdrawn, and checks that the
- * signature "reserve_sig" makes this a valid withdrawal request from the
- * specified reserve. If so, the envelope with the blinded coin "coin_ev" is
- * passed down to execute the withdrawal operation.
+ * Handle a "/reserves/$RESERVE_PUB/age-withdraw" request.
+ *
+ * Parses the batch of commitments to withdraw age restricted coins, and checks
+ * that the signature "reserve_sig" makes this a valid withdrawal request from
+ * the specified reserve. If the request is valid, the response contains a
+ * noreveal_index which the client has to use for the subsequent call to
+ * /age-withdraw/$ACH/reveal.
*
* @param rc request context
* @param root uploaded JSON data
@@ -40,8 +40,8 @@
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_withdraw (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root);
+TEH_handler_age_withdraw (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root);
#endif
diff --git a/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c
new file mode 100644
index 000000000..c9aca8e99
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.c
@@ -0,0 +1,610 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_age-withdraw_reveal.c
+ * @brief Handle /age-withdraw/$ACH/reveal requests
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include "taler-exchange-httpd_metrics.h"
+#include "taler_error_codes.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_mhd.h"
+#include "taler-exchange-httpd_age-withdraw_reveal.h"
+#include "taler-exchange-httpd_responses.h"
+#include "taler-exchange-httpd_keys.h"
+
+/**
+ * State for an /age-withdraw/$ACH/reveal operation.
+ */
+struct AgeRevealContext
+{
+
+ /**
+ * Commitment for the age-withdraw operation, previously called by the
+ * client.
+ */
+ struct TALER_AgeWithdrawCommitmentHashP ach;
+
+ /**
+ * Public key of the reserve for with the age-withdraw commitment was
+ * originally made. This parameter is provided by the client again
+ * during the call to reveal in order to save a database-lookup.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Number of coins to reveal. MUST be equal to
+ * @e num_secrets/(kappa -1).
+ */
+ uint32_t num_coins;
+
+ /**
+ * Number of secrets in the reveal. MUST be a multiple of (kappa-1).
+ */
+ uint32_t num_secrets;
+
+ /**
+ * @e num_secrets secrets for disclosed coins.
+ */
+ struct TALER_PlanchetMasterSecretP *disclosed_coin_secrets;
+
+ /**
+ * The data from the original age-withdraw. Will be retrieved from
+ * the DB via @a ach and @a reserve_pub.
+ */
+ struct TALER_EXCHANGEDB_AgeWithdraw commitment;
+};
+
+
+/**
+ * Parse the json body of an '/age-withdraw/$ACH/reveal' request. It extracts
+ * the denomination hashes, blinded coins and disclosed coins and allocates
+ * memory for those.
+ *
+ * @param connection The MHD connection to handle
+ * @param j_disclosed_coin_secrets The n*(kappa-1) disclosed coins' private keys in JSON format, from which all other attributes (age restriction, blinding, nonce) will be derived from
+ * @param[out] actx The context of the operation, only partially built at call time
+ * @param[out] mhd_ret The result if a reply is queued for MHD
+ * @return true on success, false on failure, with a reply already queued for MHD.
+ */
+static enum GNUNET_GenericReturnValue
+parse_age_withdraw_reveal_json (
+ struct MHD_Connection *connection,
+ const json_t *j_disclosed_coin_secrets,
+ struct AgeRevealContext *actx,
+ MHD_RESULT *mhd_ret)
+{
+ enum GNUNET_GenericReturnValue result = GNUNET_SYSERR;
+ size_t num_entries;
+
+ /* Verify JSON-structure consistency */
+ {
+ const char *error = NULL;
+
+ num_entries = json_array_size (j_disclosed_coin_secrets); /* 0, if not an array */
+
+ if (! json_is_array (j_disclosed_coin_secrets))
+ error = "disclosed_coin_secrets must be an array";
+ else if (num_entries == 0)
+ error = "disclosed_coin_secrets must not be empty";
+ else if (num_entries > TALER_MAX_FRESH_COINS)
+ error = "maximum number of coins that can be withdrawn has been exceeded";
+
+ if (NULL != error)
+ {
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ error);
+ return GNUNET_SYSERR;
+ }
+
+ actx->num_secrets = num_entries * (TALER_CNC_KAPPA - 1);
+ actx->num_coins = num_entries;
+
+ }
+
+ /* Continue parsing the parts */
+ {
+ unsigned int idx = 0;
+ unsigned int k = 0;
+ json_t *array = NULL;
+ json_t *value = NULL;
+
+ /* Parse diclosed keys */
+ actx->disclosed_coin_secrets =
+ GNUNET_new_array (actx->num_secrets,
+ struct TALER_PlanchetMasterSecretP);
+
+ json_array_foreach (j_disclosed_coin_secrets, idx, array) {
+ if (! json_is_array (array) ||
+ (TALER_CNC_KAPPA - 1 != json_array_size (array)))
+ {
+ char msg[256] = {0};
+ GNUNET_snprintf (msg,
+ sizeof(msg),
+ "couldn't parse entry no. %d in array disclosed_coin_secrets",
+ idx + 1);
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ msg);
+ goto EXIT;
+
+ }
+
+ json_array_foreach (array, k, value)
+ {
+ struct TALER_PlanchetMasterSecretP *secret =
+ &actx->disclosed_coin_secrets[2 * idx + k];
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (NULL, secret),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (value, spec, NULL, NULL))
+ {
+ char msg[256] = {0};
+ GNUNET_snprintf (msg,
+ sizeof(msg),
+ "couldn't parse entry no. %d in array disclosed_coin_secrets[%d]",
+ k + 1,
+ idx + 1);
+ *mhd_ret = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ msg);
+ goto EXIT;
+ }
+ }
+ };
+ }
+
+ result = GNUNET_OK;
+
+EXIT:
+ return result;
+}
+
+
+/**
+ * Check if the request belongs to an existing age-withdraw request.
+ * If so, sets the commitment object with the request data.
+ * Otherwise, it queues an appropriate MHD response.
+ *
+ * @param connection The HTTP connection to the client
+ * @param h_commitment Original commitment value sent with the age-withdraw request
+ * @param reserve_pub Reserve public key used in the original age-withdraw request
+ * @param[out] commitment Data from the original age-withdraw request
+ * @param[out] result In the error cases, a response will be queued with MHD and this will be the result.
+ * @return #GNUNET_OK if the withdraw request has been found,
+ * #GNUNET_SYSERR if we did not find the request in the DB
+ */
+static enum GNUNET_GenericReturnValue
+find_original_commitment (
+ struct MHD_Connection *connection,
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ MHD_RESULT *result)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ for (unsigned int try = 0; try < 3; try++)
+ {
+ qs = TEH_plugin->get_age_withdraw (TEH_plugin->cls,
+ reserve_pub,
+ h_commitment,
+ commitment);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return GNUNET_OK; /* Only happy case */
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ *result = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_COMMITMENT_UNKNOWN,
+ NULL);
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_age_withdraw_info");
+ return GNUNET_SYSERR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ break; /* try again */
+ default:
+ GNUNET_break (0);
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+ }
+ /* after unsuccessful retries*/
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_age_withdraw_info");
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * @brief Derives a age-restricted planchet from a given secret and calculates the hash
+ *
+ * @param connection Connection to the client
+ * @param keys The denomination keys in memory
+ * @param secret The secret to a planchet
+ * @param denom_pub_h The hash of the denomination for the planchet
+ * @param max_age The maximum age allowed
+ * @param[out] bch Hashcode to write
+ * @param[out] result On error, a HTTP-response will be queued and result set accordingly
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise, with an error message
+ * written to the client and @e result set.
+ */
+static enum GNUNET_GenericReturnValue
+calculate_blinded_hash (
+ struct MHD_Connection *connection,
+ const struct TEH_KeyStateHandle *keys,
+ const struct TALER_PlanchetMasterSecretP *secret,
+ const struct TALER_DenominationHashP *denom_pub_h,
+ uint8_t max_age,
+ struct TALER_BlindedCoinHashP *bch,
+ MHD_RESULT *result)
+{
+ enum GNUNET_GenericReturnValue ret;
+ struct TEH_DenominationKey *denom_key;
+ struct TALER_AgeCommitmentHash ach;
+
+ /* First, retrieve denomination details */
+ denom_key = TEH_keys_denomination_by_hash_from_state (keys,
+ denom_pub_h,
+ connection,
+ result);
+ if (NULL == denom_key)
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+
+ /* calculate age commitment hash */
+ {
+ struct TALER_AgeCommitmentProof acp;
+
+ TALER_age_restriction_from_secret (secret,
+ &denom_key->denom_pub.age_mask,
+ max_age,
+ &acp);
+ TALER_age_commitment_hash (&acp.commitment,
+ &ach);
+ TALER_age_commitment_proof_free (&acp);
+ }
+
+ /* Next: calculate planchet */
+ {
+ struct TALER_CoinPubHashP c_hash;
+ struct TALER_PlanchetDetail detail = {0};
+ struct TALER_CoinSpendPrivateKeyP coin_priv;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = denom_key->denom_pub.bsign_pub_key->cipher
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+ union GNUNET_CRYPTO_BlindSessionNonce *noncep = NULL;
+
+ // FIXME: add logic to denom.c to do this!
+ if (GNUNET_CRYPTO_BSA_CS == bi.cipher)
+ {
+ struct TEH_CsDeriveData cdd = {
+ .h_denom_pub = &denom_key->h_denom_pub,
+ .nonce = &nonce.cs_nonce,
+ };
+
+ TALER_cs_withdraw_nonce_derive (secret,
+ &nonce.cs_nonce);
+ noncep = &nonce;
+ GNUNET_assert (TALER_EC_NONE ==
+ TEH_keys_denomination_cs_r_pub (
+ &cdd,
+ false,
+ &bi.details.cs_values));
+ }
+ TALER_planchet_blinding_secret_create (secret,
+ &alg_values,
+ &bks);
+ TALER_planchet_setup_coin_priv (secret,
+ &alg_values,
+ &coin_priv);
+ ret = TALER_planchet_prepare (&denom_key->denom_pub,
+ &alg_values,
+ &bks,
+ noncep,
+ &coin_priv,
+ &ach,
+ &c_hash,
+ &detail);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_break (0);
+ *result = TALER_MHD_reply_json_pack (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ "{ss}",
+ "details",
+ "failed to prepare planchet from base key");
+ return ret;
+ }
+
+ TALER_coin_ev_hash (&detail.blinded_planchet,
+ &denom_key->h_denom_pub,
+ bch);
+ TALER_blinded_planchet_free (&detail.blinded_planchet);
+ }
+
+ return ret;
+}
+
+
+/**
+ * @brief Checks the validity of the disclosed coins as follows:
+ * - Derives and calculates the disclosed coins'
+ * - public keys,
+ * - nonces (if applicable),
+ * - age commitments,
+ * - blindings
+ * - blinded hashes
+ * - Computes h_commitment with those calculated and the undisclosed hashes
+ * - Compares h_commitment with the value from the original commitment
+ * - Verifies that all public keys in indices larger than the age group
+ * corresponding to max_age are derived from the constant public key.
+ *
+ * The derivation of the blindings, (potential) nonces and age-commitment from
+ * a coin's private keys is defined in
+ * https://docs.taler.net/design-documents/024-age-restriction.html#withdraw
+ *
+ * @param connection HTTP-connection to the client
+ * @param commitment Original commitment
+ * @param disclosed_coin_secrets The secrets of the disclosed coins, (TALER_CNC_KAPPA - 1)*num_coins many
+ * @param num_coins number of coins to reveal via @a disclosed_coin_secrets
+ * @param[out] result On error, a HTTP-response will be queued and result set accordingly
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+static enum GNUNET_GenericReturnValue
+verify_commitment_and_max_age (
+ struct MHD_Connection *connection,
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ const struct TALER_PlanchetMasterSecretP *disclosed_coin_secrets,
+ uint32_t num_coins,
+ MHD_RESULT *result)
+{
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
+ struct GNUNET_HashContext *hash_context;
+ struct TEH_KeyStateHandle *keys;
+
+ if (num_coins != commitment->num_coins)
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "#coins");
+ return GNUNET_SYSERR;
+ }
+
+ /* We need the current keys in memory for the meta-data of the denominations */
+ keys = TEH_keys_get_state ();
+ if (NULL == keys)
+ {
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+
+ for (size_t coin_idx = 0; coin_idx < num_coins; coin_idx++)
+ {
+ size_t i = 0; /* either 0 or 1, to index into coin_evs */
+
+ for (size_t k = 0; k<TALER_CNC_KAPPA; k++)
+ {
+ if (k == (size_t) commitment->noreveal_index)
+ {
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ &commitment->h_coin_evs[coin_idx],
+ sizeof(commitment->h_coin_evs[coin_idx]));
+ }
+ else
+ {
+ /* j is the index into disclosed_coin_secrets[] */
+ size_t j = (TALER_CNC_KAPPA - 1) * coin_idx + i;
+ const struct TALER_PlanchetMasterSecretP *secret;
+ struct TALER_BlindedCoinHashP bch;
+
+ GNUNET_assert (2>i);
+ GNUNET_assert ((TALER_CNC_KAPPA - 1) * num_coins > j);
+
+ secret = &disclosed_coin_secrets[j];
+ i++;
+
+ ret = calculate_blinded_hash (connection,
+ keys,
+ secret,
+ &commitment->denom_pub_hashes[coin_idx],
+ commitment->max_age,
+ &bch,
+ result);
+
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_CRYPTO_hash_context_abort (hash_context);
+ return GNUNET_SYSERR;
+ }
+
+ /* Continue the running hash of all coin hashes with the calculated
+ * hash-value of the current, disclosed coin */
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ &bch,
+ sizeof(bch));
+ }
+ }
+ }
+
+ /* Finally, compare the calculated hash with the original commitment */
+ {
+ struct GNUNET_HashCode calc_hash;
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ &calc_hash);
+
+ if (0 != GNUNET_CRYPTO_hash_cmp (&commitment->h_commitment.hash,
+ &calc_hash))
+ {
+ GNUNET_break_op (0);
+ *result = TALER_MHD_reply_with_ec (connection,
+ TALER_EC_EXCHANGE_AGE_WITHDRAW_REVEAL_INVALID_HASH,
+ NULL);
+ return GNUNET_SYSERR;
+ }
+
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * @brief Send a response for "/age-withdraw/$RCH/reveal"
+ *
+ * @param connection The http connection to the client to send the response to
+ * @param commitment The data from the commitment with signatures
+ * @return a MHD result code
+ */
+static MHD_RESULT
+reply_age_withdraw_reveal_success (
+ struct MHD_Connection *connection,
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment)
+{
+ json_t *list = json_array ();
+ GNUNET_assert (NULL != list);
+
+ for (unsigned int i = 0; i < commitment->num_coins; i++)
+ {
+ json_t *obj = GNUNET_JSON_PACK (
+ TALER_JSON_pack_blinded_denom_sig (NULL,
+ &commitment->denom_sigs[i]));
+ GNUNET_assert (0 ==
+ json_array_append_new (list,
+ obj));
+ }
+
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("ev_sigs",
+ list));
+}
+
+
+MHD_RESULT
+TEH_handler_age_withdraw_reveal (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ const json_t *root)
+{
+ MHD_RESULT result = MHD_NO;
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
+ struct AgeRevealContext actx = {0};
+ const json_t *j_disclosed_coin_secrets;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+ &actx.reserve_pub),
+ GNUNET_JSON_spec_array_const ("disclosed_coin_secrets",
+ &j_disclosed_coin_secrets),
+ GNUNET_JSON_spec_end ()
+ };
+
+ actx.ach = *ach;
+
+ /* Parse JSON body*/
+ ret = TALER_MHD_parse_json_data (rc->connection,
+ root,
+ spec);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_break_op (0);
+ return (GNUNET_SYSERR == ret) ? MHD_NO : MHD_YES;
+ }
+
+
+ do {
+ /* Extract denominations, blinded and disclosed coins */
+ if (GNUNET_OK !=
+ parse_age_withdraw_reveal_json (
+ rc->connection,
+ j_disclosed_coin_secrets,
+ &actx,
+ &result))
+ break;
+
+ /* Find original commitment */
+ if (GNUNET_OK !=
+ find_original_commitment (
+ rc->connection,
+ &actx.ach,
+ &actx.reserve_pub,
+ &actx.commitment,
+ &result))
+ break;
+
+ /* Verify the computed h_commitment equals the committed one and that coins
+ * have a maximum age group corresponding max_age (age-mask dependent) */
+ if (GNUNET_OK !=
+ verify_commitment_and_max_age (
+ rc->connection,
+ &actx.commitment,
+ actx.disclosed_coin_secrets,
+ actx.num_coins,
+ &result))
+ break;
+
+ /* Finally, return the signatures */
+ result = reply_age_withdraw_reveal_success (rc->connection,
+ &actx.commitment);
+
+ } while (0);
+
+ GNUNET_JSON_parse_free (spec);
+ if (NULL != actx.commitment.denom_sigs)
+ for (unsigned int i = 0; i<actx.num_coins; i++)
+ TALER_blinded_denom_sig_free (&actx.commitment.denom_sigs[i]);
+ GNUNET_free (actx.commitment.denom_sigs);
+ GNUNET_free (actx.commitment.denom_pub_hashes);
+ GNUNET_free (actx.commitment.denom_serials);
+ GNUNET_free (actx.disclosed_coin_secrets);
+ return result;
+}
+
+
+/* end of taler-exchange-httpd_age-withdraw_reveal.c */
diff --git a/src/exchange/taler-exchange-httpd_age-withdraw_reveal.h b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.h
new file mode 100644
index 000000000..f7b813fe7
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_age-withdraw_reveal.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_age-withdraw_reveal.h
+ * @brief Handle /age-withdraw/$ACH/reveal requests
+ * @author Özgür Kesim
+ */
+#ifndef TALER_EXCHANGE_HTTPD_AGE_WITHDRAW_REVEAL_H
+#define TALER_EXCHANGE_HTTPD_AGE_WITHDRAW_REVEAL_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Handle a "/age-withdraw/$ACH/reveal" request.
+ *
+ * The client got a noreveal_index in response to a previous request
+ * /reserve/$RESERVE_PUB/age-withdraw. It now has to reveal all n*(kappa-1)
+ * coin's private keys (except for the noreveal_index), from which all other
+ * coin-relevant data (blinding, age restriction, nonce) is derived from.
+ *
+ * The exchange computes those values, ensures that the maximum age is
+ * correctly applied, calculates the hash of the blinded envelopes, and -
+ * together with the non-disclosed blinded envelopes - compares the hash of
+ * those against the original commitment $ACH.
+ *
+ * If all those checks and the used denominations turn out to be correct, the
+ * exchange signs all blinded envelopes with their appropriate denomination
+ * keys.
+ *
+ * @param rc request context
+ * @param root uploaded JSON data
+ * @param ach commitment to the age restricted coints from the age-withdraw request
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_age_withdraw_reveal (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ const json_t *root);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_aml-decision-get.c b/src/exchange/taler-exchange-httpd_aml-decision-get.c
new file mode 100644
index 000000000..b4f337db1
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_aml-decision-get.c
@@ -0,0 +1,233 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_aml-decision-get.c
+ * @brief Return summary information about AML decision
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler-exchange-httpd_aml-decision.h"
+#include "taler-exchange-httpd_metrics.h"
+
+
+/**
+ * Maximum number of records we return per request.
+ */
+#define MAX_RECORDS 1024
+
+/**
+ * Callback with KYC attributes about a particular user.
+ *
+ * @param[in,out] cls closure with a `json_t *` array to update
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+static void
+kyc_attribute_cb (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes)
+{
+ json_t *kyc_attributes = cls;
+ json_t *attributes;
+
+ attributes = TALER_CRYPTO_kyc_attributes_decrypt (&TEH_attribute_key,
+ enc_attributes,
+ enc_attributes_size);
+ GNUNET_break (NULL != attributes);
+ GNUNET_assert (
+ 0 ==
+ json_array_append (
+ kyc_attributes,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("provider_section",
+ provider_section),
+ GNUNET_JSON_pack_timestamp ("collection_time",
+ collection_time),
+ GNUNET_JSON_pack_timestamp ("expiration_time",
+ expiration_time),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("attributes",
+ attributes))
+ )));
+}
+
+
+/**
+ * Return historic AML decision(s).
+ *
+ * @param[in,out] cls closure with a `json_t *` array to update
+ * @param new_threshold new monthly threshold that would trigger an AML check
+ * @param new_state AML decision status
+ * @param decision_time when was the decision made
+ * @param justification human-readable text justifying the decision
+ * @param decider_pub public key of the staff member
+ * @param decider_sig signature of the staff member
+ */
+static void
+aml_history_cb (
+ void *cls,
+ const struct TALER_Amount *new_threshold,
+ enum TALER_AmlDecisionState new_state,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_AmlOfficerSignatureP *decider_sig)
+{
+ json_t *aml_history = cls;
+
+ GNUNET_assert (
+ 0 ==
+ json_array_append (
+ aml_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("decider_pub",
+ decider_pub),
+ GNUNET_JSON_pack_string ("justification",
+ justification),
+ TALER_JSON_pack_amount ("new_threshold",
+ new_threshold),
+ GNUNET_JSON_pack_int64 ("new_state",
+ new_state),
+ GNUNET_JSON_pack_timestamp ("decision_time",
+ decision_time)
+ )));
+}
+
+
+MHD_RESULT
+TEH_handler_aml_decision_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *const args[])
+{
+ struct TALER_PaytoHashP h_payto;
+
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &h_payto,
+ sizeof (h_payto))) )
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "h_payto");
+ }
+
+ if (NULL != args[1])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ args[1]);
+ }
+
+ {
+ json_t *aml_history;
+ json_t *kyc_attributes;
+ enum GNUNET_DB_QueryStatus qs;
+ bool none = false;
+
+ aml_history = json_array ();
+ GNUNET_assert (NULL != aml_history);
+ qs = TEH_plugin->select_aml_history (TEH_plugin->cls,
+ &h_payto,
+ &aml_history_cb,
+ aml_history);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ json_decref (aml_history);
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ none = true;
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ none = false;
+ break;
+ }
+
+ kyc_attributes = json_array ();
+ GNUNET_assert (NULL != kyc_attributes);
+ qs = TEH_plugin->select_kyc_attributes (TEH_plugin->cls,
+ &h_payto,
+ &kyc_attribute_cb,
+ kyc_attributes);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ json_decref (aml_history);
+ json_decref (kyc_attributes);
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ if (none)
+ {
+ json_decref (aml_history);
+ json_decref (kyc_attributes);
+ return TALER_MHD_reply_static (
+ rc->connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("aml_history",
+ aml_history),
+ GNUNET_JSON_pack_array_steal ("kyc_attributes",
+ kyc_attributes));
+ }
+}
+
+
+/* end of taler-exchange-httpd_aml-decision_get.c */
diff --git a/src/exchange/taler-exchange-httpd_aml-decision.c b/src/exchange/taler-exchange-httpd_aml-decision.c
new file mode 100644
index 000000000..bf43fdbf2
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_aml-decision.c
@@ -0,0 +1,358 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_aml-decision.c
+ * @brief Handle request about an AML decision.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Closure for #make_aml_decision()
+ */
+struct DecisionContext
+{
+ /**
+ * Justification given for the decision.
+ */
+ const char *justification;
+
+ /**
+ * When was the decision taken.
+ */
+ struct GNUNET_TIME_Timestamp decision_time;
+
+ /**
+ * New threshold for revising the decision.
+ */
+ struct TALER_Amount new_threshold;
+
+ /**
+ * Hash of payto://-URI of affected account.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * New AML state.
+ */
+ enum TALER_AmlDecisionState new_state;
+
+ /**
+ * Signature affirming the decision.
+ */
+ struct TALER_AmlOfficerSignatureP officer_sig;
+
+ /**
+ * Public key of the AML officer.
+ */
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub;
+
+ /**
+ * KYC requirements imposed, NULL for none.
+ */
+ const json_t *kyc_requirements;
+
+};
+
+
+/**
+ * Function implementing AML decision database transaction.
+ *
+ * Runs the transaction logic; IF it returns a non-error code, the
+ * transaction logic MUST NOT queue a MHD response. IF it returns an hard
+ * error, the transaction logic MUST queue a MHD response and set @a mhd_ret.
+ * IF it returns the soft error code, the function MAY be called again to
+ * retry and MUST not queue a MHD response.
+ *
+ * @param cls closure with a `struct DecisionContext`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+make_aml_decision (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct DecisionContext *dc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp last_date;
+ bool invalid_officer;
+ uint64_t requirement_row = 0;
+
+ if ( (NULL != dc->kyc_requirements) &&
+ (0 != json_array_size (dc->kyc_requirements)) )
+ {
+ char *res = NULL;
+ size_t idx;
+ json_t *req;
+ bool satisfied;
+
+ json_array_foreach (dc->kyc_requirements, idx, req)
+ {
+ const char *r = json_string_value (req);
+
+ if (NULL == res)
+ {
+ res = GNUNET_strdup (r);
+ }
+ else
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp,
+ "%s %s",
+ res,
+ r);
+ GNUNET_free (res);
+ res = tmp;
+ }
+ }
+
+ {
+ json_t *kyc_details = NULL;
+
+ qs = TALER_KYCLOGIC_check_satisfied (
+ &res,
+ &dc->h_payto,
+ &kyc_details,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &satisfied);
+ json_decref (kyc_details);
+ }
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_satisfied_kyc_processes");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+ }
+ if (! satisfied)
+ {
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ res,
+ &dc->h_payto,
+ NULL, /* not a reserve */
+ &requirement_row);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_for_account");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+ }
+ }
+ GNUNET_free (res);
+ }
+
+ qs = TEH_plugin->insert_aml_decision (TEH_plugin->cls,
+ &dc->h_payto,
+ &dc->new_threshold,
+ dc->new_state,
+ dc->decision_time,
+ dc->justification,
+ dc->kyc_requirements,
+ requirement_row,
+ dc->officer_pub,
+ &dc->officer_sig,
+ &invalid_officer,
+ &last_date);
+ if (qs <= 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_aml_decision");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+ }
+ if (invalid_officer)
+ {
+ GNUNET_break_op (0);
+ *mhd_ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_AML_DECISION_INVALID_OFFICER,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (GNUNET_TIME_timestamp_cmp (last_date,
+ >=,
+ dc->decision_time))
+ {
+ GNUNET_break_op (0);
+ *mhd_ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_AML_DECISION_MORE_RECENT_PRESENT,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+MHD_RESULT
+TEH_handler_post_aml_decision (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const json_t *root)
+{
+ struct MHD_Connection *connection = rc->connection;
+ struct DecisionContext dc = {
+ .officer_pub = officer_pub
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("officer_sig",
+ &dc.officer_sig),
+ GNUNET_JSON_spec_fixed_auto ("h_payto",
+ &dc.h_payto),
+ TALER_JSON_spec_amount ("new_threshold",
+ TEH_currency,
+ &dc.new_threshold),
+ GNUNET_JSON_spec_string ("justification",
+ &dc.justification),
+ GNUNET_JSON_spec_timestamp ("decision_time",
+ &dc.decision_time),
+ TALER_JSON_spec_aml_decision ("new_state",
+ &dc.new_state),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const ("kyc_requirements",
+ &dc.kyc_requirements),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO; /* hard failure */
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ return MHD_YES; /* failure */
+ }
+ }
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_officer_aml_decision_verify (dc.justification,
+ dc.decision_time,
+ &dc.new_threshold,
+ &dc.h_payto,
+ dc.new_state,
+ dc.kyc_requirements,
+ dc.officer_pub,
+ &dc.officer_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_AML_DECISION_ADD_SIGNATURE_INVALID,
+ NULL);
+ }
+
+ if (NULL != dc.kyc_requirements)
+ {
+ size_t index;
+ json_t *elem;
+
+ json_array_foreach (dc.kyc_requirements, index, elem)
+ {
+ const char *val;
+
+ if (! json_is_string (elem))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "kyc_requirements array members must be strings");
+ }
+ val = json_string_value (elem);
+ if (GNUNET_SYSERR ==
+ TALER_KYCLOGIC_check_satisfiable (val))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_AML_DECISION_UNKNOWN_CHECK,
+ val);
+ }
+ }
+ }
+
+ {
+ MHD_RESULT mhd_ret;
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (connection,
+ "make-aml-decision",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &make_aml_decision,
+ &dc))
+ {
+ return mhd_ret;
+ }
+ }
+ return TALER_MHD_reply_static (
+ connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/* end of taler-exchange-httpd_aml-decision.c */
diff --git a/src/exchange/taler-exchange-httpd_aml-decision.h b/src/exchange/taler-exchange-httpd_aml-decision.h
new file mode 100644
index 000000000..8af742c0a
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_aml-decision.h
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_aml-decision.h
+ * @brief Handle /aml/$OFFICER_PUB/decision requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_AML_DECISION_H
+#define TALER_EXCHANGE_HTTPD_AML_DECISION_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Handle a POST "/aml/$OFFICER_PUB/decision" request. Parses the decision
+ * details, checks the signatures and if appropriately authorized executes
+ * the decision.
+ *
+ * @param rc request context
+ * @param officer_pub public key of the AML officer who made the request
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_post_aml_decision (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const json_t *root);
+
+
+/**
+ * Handle a GET "/aml/$OFFICER_PUB/decisions/$STATE" request. Parses the request
+ * details, checks the signatures and if appropriately authorized returns
+ * the matching decisions.
+ *
+ * @param rc request context
+ * @param officer_pub public key of the AML officer who made the request
+ * @param args GET arguments (should be the state)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_aml_decisions_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *const args[]);
+
+
+/**
+ * Handle a GET "/aml/$OFFICER_PUB/decision/$H_PAYTO" request. Parses the request
+ * details, checks the signatures and if appropriately authorized returns
+ * the AML history and KYC attributes for the account.
+ *
+ * @param rc request context
+ * @param officer_pub public key of the AML officer who made the request
+ * @param args GET arguments (should be one)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_aml_decision_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *const args[]);
+
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_aml-decisions-get.c b/src/exchange/taler-exchange-httpd_aml-decisions-get.c
new file mode 100644
index 000000000..763817cf6
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_aml-decisions-get.c
@@ -0,0 +1,215 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_aml-decisions-get.c
+ * @brief Return summary information about AML decisions
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler-exchange-httpd_aml-decision.h"
+#include "taler-exchange-httpd_metrics.h"
+
+
+/**
+ * Maximum number of records we return per request.
+ */
+#define MAX_RECORDS 1024
+
+/**
+ * Return AML status.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param h_payto account for which the attribute data is stored
+ * @param threshold currently monthly threshold that would trigger an AML check
+ * @param status what is the current AML decision
+ */
+static void
+record_cb (
+ void *cls,
+ uint64_t row_id,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *threshold,
+ enum TALER_AmlDecisionState status)
+{
+ json_t *records = cls;
+
+ GNUNET_assert (
+ 0 ==
+ json_array_append (
+ records,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("h_payto",
+ h_payto),
+ GNUNET_JSON_pack_int64 ("current_state",
+ status),
+ TALER_JSON_pack_amount ("threshold",
+ threshold),
+ GNUNET_JSON_pack_int64 ("rowid",
+ row_id)
+ )));
+}
+
+
+MHD_RESULT
+TEH_handler_aml_decisions_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *const args[])
+{
+ enum TALER_AmlDecisionState decision;
+ int delta = -20;
+ unsigned long long start;
+ const char *state_str = args[0];
+
+ if (NULL == state_str)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ args[0]);
+ }
+ if (0 == strcmp (state_str,
+ "pending"))
+ decision = TALER_AML_PENDING;
+ else if (0 == strcmp (state_str,
+ "frozen"))
+ decision = TALER_AML_FROZEN;
+ else if (0 == strcmp (state_str,
+ "normal"))
+ decision = TALER_AML_NORMAL;
+ else
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ state_str);
+ }
+ if (NULL != args[1])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ args[1]);
+ }
+
+ {
+ const char *p;
+
+ p = MHD_lookup_connection_value (rc->connection,
+ MHD_GET_ARGUMENT_KIND,
+ "delta");
+ if (NULL != p)
+ {
+ char dummy;
+
+ if (1 != sscanf (p,
+ "%d%c",
+ &delta,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "delta");
+ }
+ }
+ if (delta > 0)
+ start = 0;
+ else
+ start = INT64_MAX;
+ p = MHD_lookup_connection_value (rc->connection,
+ MHD_GET_ARGUMENT_KIND,
+ "start");
+ if (NULL != p)
+ {
+ char dummy;
+
+ if (1 != sscanf (p,
+ "%llu%c",
+ &start,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "start");
+ }
+ }
+ }
+
+ {
+ json_t *records;
+ enum GNUNET_DB_QueryStatus qs;
+
+ records = json_array ();
+ GNUNET_assert (NULL != records);
+ if (INT_MIN == delta)
+ delta = INT_MIN + 1;
+ qs = TEH_plugin->select_aml_process (TEH_plugin->cls,
+ decision,
+ start,
+ GNUNET_MIN (MAX_RECORDS,
+ delta > 0
+ ? delta
+ : -delta),
+ delta > 0,
+ &record_cb,
+ records);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ json_decref (records);
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_static (
+ rc->connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("records",
+ records));
+ }
+}
+
+
+/* end of taler-exchange-httpd_aml-decisions_get.c */
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c
index 154629ed2..84f27dd94 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.c
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -28,9 +28,10 @@
#include <jansson.h>
#include <microhttpd.h>
#include <pthread.h>
+#include "taler_extensions_policy.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
-#include "taler-exchange-httpd_deposit.h"
+#include "taler-exchange-httpd_batch-deposit.h"
#include "taler-exchange-httpd_responses.h"
#include "taler_exchangedb_lib.h"
#include "taler-exchange-httpd_keys.h"
@@ -41,10 +42,11 @@
*/
struct BatchDepositContext
{
+
/**
- * Information about the individual coin deposits.
+ * Array with the individual coin deposit fees.
*/
- struct TALER_EXCHANGEDB_Deposit *deposits;
+ struct TALER_Amount *deposit_fees;
/**
* Our timestamp (when we received the request).
@@ -54,83 +56,52 @@ struct BatchDepositContext
struct GNUNET_TIME_Timestamp exchange_timestamp;
/**
- * Hash over the proposal data between merchant and customer
- * (remains unknown to the Exchange).
- */
- struct TALER_PrivateContractHashP h_contract_terms;
-
- /**
- * Public key of the merchant. Enables later identification
- * of the merchant in case of a need to rollback transactions.
- */
- struct TALER_MerchantPublicKeyP merchant_pub;
-
- /**
- * Salt used by the merchant to compute @e h_wire.
+ * Details about the batch deposit operation.
*/
- struct TALER_WireSaltP wire_salt;
+ struct TALER_EXCHANGEDB_BatchDeposit bd;
- /**
- * Hash over the wire details (with @e wire_salt).
- */
- struct TALER_MerchantWireHashP h_wire;
/**
- * Hash of the payto URI.
+ * Total amount that is accumulated with this deposit,
+ * without fee.
*/
- struct TALER_PaytoHashP h_payto;
+ struct TALER_Amount accumulated_total_without_fee;
/**
- * Information about the receiver for executing the transaction. URI in
- * payto://-format.
+ * True, if no policy was present in the request. Then
+ * @e policy_json is NULL and @e h_policy will be all zero.
*/
- const char *payto_uri;
+ bool has_no_policy;
/**
- * Additional details for extensions relevant for this
+ * Additional details for policy extension relevant for this
* deposit operation, possibly NULL!
*/
- json_t *extension_details;
+ json_t *policy_json;
/**
- * Hash over @e extension_details.
+ * If @e policy_json was present, the corresponding policy extension
+ * calculates these details. These will be persisted in the policy_details
+ * table.
*/
- struct TALER_ExtensionContractHashP h_extensions;
+ struct TALER_PolicyDetails policy_details;
/**
- * Time when this request was generated. Used, for example, to
- * assess when (roughly) the income was achieved for tax purposes.
- * Note that the Exchange will only check that the timestamp is not "too
- * far" into the future (i.e. several days). The fact that the
- * timestamp falls within the validity period of the coin's
- * denomination key is irrelevant for the validity of the deposit
- * request, as obviously the customer and merchant could conspire to
- * set any timestamp. Also, the Exchange must accept very old deposit
- * requests, as the merchant might have been unable to transmit the
- * deposit request in a timely fashion (so back-dating is not
- * prevented).
+ * Hash over @e policy_details, might be all zero
*/
- struct GNUNET_TIME_Timestamp timestamp;
+ struct TALER_ExtensionPolicyHashP h_policy;
/**
- * How much time does the merchant have to issue a refund request?
- * Zero if refunds are not allowed. After this time, the coin
- * cannot be refunded.
+ * Hash over the merchant's payto://-URI with the wire salt.
*/
- struct GNUNET_TIME_Timestamp refund_deadline;
+ struct TALER_MerchantWireHashP h_wire;
/**
- * How much time does the merchant have to execute the wire transfer?
- * This time is advisory for aggregating transactions, not a hard
- * constraint (as the merchant can theoretically pick any time,
- * including one in the past).
+ * When @e policy_details are persisted, this contains the id of the record
+ * in the policy_details table.
*/
- struct GNUNET_TIME_Timestamp wire_deadline;
+ uint64_t policy_details_serial_id;
- /**
- * Number of coins in the batch.
- */
- unsigned int num_coins;
};
@@ -142,84 +113,52 @@ struct BatchDepositContext
* requested batch deposit operation with the given wiring details.
*
* @param connection connection to the client
- * @param bdc information about the batch deposit
+ * @param dc information about the batch deposit
* @return MHD result code
*/
static MHD_RESULT
reply_batch_deposit_success (
struct MHD_Connection *connection,
- const struct BatchDepositContext *bdc)
+ const struct BatchDepositContext *dc)
{
- json_t *arr;
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc->bd;
+ const struct TALER_CoinSpendSignatureP *csigs[GNUNET_NZL (bd->num_cdis)];
+ enum TALER_ErrorCode ec;
struct TALER_ExchangePublicKeyP pub;
-
-again:
- arr = json_array ();
- GNUNET_assert (NULL != arr);
- for (unsigned int i = 0; i<bdc->num_coins; i++)
+ struct TALER_ExchangeSignatureP sig;
+
+ for (unsigned int i = 0; i<bd->num_cdis; i++)
+ csigs[i] = &bd->cdis[i].csig;
+ if (TALER_EC_NONE !=
+ (ec = TALER_exchange_online_deposit_confirmation_sign (
+ &TEH_keys_exchange_sign_,
+ &bd->h_contract_terms,
+ &dc->h_wire,
+ dc->has_no_policy ? NULL : &dc->h_policy,
+ dc->exchange_timestamp,
+ bd->wire_deadline,
+ bd->refund_deadline,
+ &dc->accumulated_total_without_fee,
+ bd->num_cdis,
+ csigs,
+ &dc->bd.merchant_pub,
+ &pub,
+ &sig)))
{
- const struct TALER_EXCHANGEDB_Deposit *deposit = &bdc->deposits[i];
- struct TALER_ExchangePublicKeyP pubi;
- struct TALER_ExchangeSignatureP sig;
- enum TALER_ErrorCode ec;
- struct TALER_Amount amount_without_fee;
-
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &deposit->amount_with_fee,
- &deposit->deposit_fee));
- if (TALER_EC_NONE !=
- (ec = TALER_exchange_online_deposit_confirmation_sign (
- &TEH_keys_exchange_sign_,
- &bdc->h_contract_terms,
- &bdc->h_wire,
- &bdc->h_extensions,
- bdc->exchange_timestamp,
- bdc->wire_deadline,
- bdc->refund_deadline,
- &amount_without_fee,
- &deposit->coin.coin_pub,
- &bdc->merchant_pub,
- &pubi,
- &sig)))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_ec (connection,
- ec,
- NULL);
- }
- if (0 == i)
- pub = pubi;
- if (0 !=
- GNUNET_memcmp (&pub,
- &pubi))
- {
- /* note: in the future, maybe have batch
- sign API to avoid having to handle
- key rollover... */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Exchange public key changed during batch deposit, trying again\n");
- json_decref (arr);
- goto again;
- }
- GNUNET_assert (
- 0 ==
- json_array_append_new (arr,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto (
- "exchange_sig",
- &sig))));
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_ec (connection,
+ ec,
+ NULL);
}
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
GNUNET_JSON_pack_timestamp ("exchange_timestamp",
- bdc->exchange_timestamp),
- GNUNET_JSON_pack_data_auto (
- "exchange_pub",
- &pub),
- GNUNET_JSON_pack_array_steal ("exchange_sigs",
- arr));
+ dc->exchange_timestamp),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &pub),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &sig));
}
@@ -242,62 +181,113 @@ batch_deposit_transaction (void *cls,
MHD_RESULT *mhd_ret)
{
struct BatchDepositContext *dc = cls;
- enum GNUNET_DB_QueryStatus qs;
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc->bd;
+ enum GNUNET_DB_QueryStatus qs = GNUNET_DB_STATUS_HARD_ERROR;
+ uint32_t bad_balance_coin_index = UINT32_MAX;
bool balance_ok;
bool in_conflict;
- for (unsigned int i = 0; i<dc->num_coins; i++)
+ /* If the deposit has a policy associated to it, persist it. This will
+ * insert or update the record. */
+ if (! dc->has_no_policy)
+ {
+ qs = TEH_plugin->persist_policy_details (
+ TEH_plugin->cls,
+ &dc->policy_details,
+ &dc->bd.policy_details_serial_id,
+ &dc->accumulated_total_without_fee,
+ &dc->policy_details.fulfillment_state);
+ if (qs < 0)
+ return qs;
+
+ dc->bd.policy_blocked =
+ dc->policy_details.fulfillment_state != TALER_PolicyFulfillmentSuccess;
+ }
+
+ /* FIXME: replace by batch insert! */
+ for (unsigned int i = 0; i<bd->num_cdis; i++)
{
- const struct TALER_EXCHANGEDB_Deposit *deposit = &dc->deposits[i];
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi
+ = &bd->cdis[i];
uint64_t known_coin_id;
- qs = TEH_make_coin_known (&deposit->coin,
+ qs = TEH_make_coin_known (&cdi->coin,
connection,
&known_coin_id,
mhd_ret);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "make coin known (%s) returned %d\n",
+ TALER_B2S (&cdi->coin.coin_pub),
+ qs);
if (qs < 0)
return qs;
- qs = TEH_plugin->do_deposit (TEH_plugin->cls,
- deposit,
- known_coin_id,
- &dc->h_payto,
- false, /* FIXME-OEC: extension blocked */
- &dc->exchange_timestamp,
- &balance_ok,
- &in_conflict);
- if (qs < 0)
+ }
+
+ qs = TEH_plugin->do_deposit (
+ TEH_plugin->cls,
+ bd,
+ &dc->exchange_timestamp,
+ &balance_ok,
+ &bad_balance_coin_index,
+ &in_conflict);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ TALER_LOG_WARNING (
+ "Failed to store /batch-deposit information in database\n");
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "batch-deposit");
+ return qs;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "do_deposit returned: %d / %s[%u] / %s\n",
+ qs,
+ balance_ok ? "balance ok" : "balance insufficient",
+ (unsigned int) bad_balance_coin_index,
+ in_conflict ? "in conflict" : "no conflict");
+ if (in_conflict)
+ {
+ struct TALER_MerchantWireHashP h_wire;
+
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ TEH_plugin->get_wire_hash_for_contract (
+ TEH_plugin->cls,
+ &bd->merchant_pub,
+ &bd->h_contract_terms,
+ &h_wire))
{
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
TALER_LOG_WARNING (
- "Failed to store /batch-deposit information in database\n");
+ "Failed to retrieve conflicting contract details from database\n");
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_STORE_FAILED,
"batch-deposit");
return qs;
}
- if (in_conflict)
- {
- /* FIXME: conficting contract != insufficient funds */
- *mhd_ret
- = TEH_RESPONSE_reply_coin_insufficient_funds (
- connection,
- TALER_EC_EXCHANGE_DEPOSIT_CONFLICTING_CONTRACT,
- &deposit->coin.denom_pub_hash,
- &deposit->coin.coin_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (! balance_ok)
- {
- *mhd_ret
- = TEH_RESPONSE_reply_coin_insufficient_funds (
- connection,
- TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS,
- &deposit->coin.denom_pub_hash,
- &deposit->coin.coin_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
+
+ *mhd_ret
+ = TEH_RESPONSE_reply_coin_conflicting_contract (
+ connection,
+ TALER_EC_EXCHANGE_DEPOSIT_CONFLICTING_CONTRACT,
+ &h_wire);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (! balance_ok)
+ {
+ GNUNET_assert (bad_balance_coin_index < bd->num_cdis);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "returning history of conflicting coin (%s)\n",
+ TALER_B2S (&bd->cdis[bad_balance_coin_index].coin.coin_pub));
+ *mhd_ret
+ = TEH_RESPONSE_reply_coin_insufficient_funds (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS,
+ &bd->cdis[bad_balance_coin_index].coin.denom_pub_hash,
+ &bd->cdis[bad_balance_coin_index].coin.coin_pub);
+ return GNUNET_DB_STATUS_HARD_ERROR;
}
TEH_METRICS_num_success[TEH_MT_SUCCESS_DEPOSIT]++;
return qs;
@@ -310,34 +300,37 @@ batch_deposit_transaction (void *cls,
* @a ctx.
*
* @param connection connection we are handling
+ * @param dc information about the overall batch
* @param jcoin coin data to parse
- * @param dc overall batch deposit context information to use
- * @param[out] deposit where to store the result
+ * @param[out] cdi where to store the result
+ * @param[out] deposit_fee where to write the deposit fee
* @return #GNUNET_OK on success, #GNUNET_NO if an error was returned,
* #GNUNET_SYSERR on failure and no error could be returned
*/
static enum GNUNET_GenericReturnValue
parse_coin (struct MHD_Connection *connection,
- json_t *jcoin,
const struct BatchDepositContext *dc,
- struct TALER_EXCHANGEDB_Deposit *deposit)
+ json_t *jcoin,
+ struct TALER_EXCHANGEDB_CoinDepositInformation *cdi,
+ struct TALER_Amount *deposit_fee)
{
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc->bd;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("contribution",
TEH_currency,
- &deposit->amount_with_fee),
+ &cdi->amount_with_fee),
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
- &deposit->coin.denom_pub_hash),
+ &cdi->coin.denom_pub_hash),
TALER_JSON_spec_denom_sig ("ub_sig",
- &deposit->coin.denom_sig),
+ &cdi->coin.denom_sig),
GNUNET_JSON_spec_fixed_auto ("coin_pub",
- &deposit->coin.coin_pub),
+ &cdi->coin.coin_pub),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &deposit->coin.h_age_commitment),
- &deposit->coin.no_age_commitment),
+ &cdi->coin.h_age_commitment),
+ &cdi->coin.no_age_commitment),
GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &deposit->csig),
+ &cdi->csig),
GNUNET_JSON_spec_end ()
};
enum GNUNET_GenericReturnValue res;
@@ -352,16 +345,18 @@ parse_coin (struct MHD_Connection *connection,
struct TEH_DenominationKey *dk;
MHD_RESULT mret;
- dk = TEH_keys_denomination_by_hash (&deposit->coin.denom_pub_hash,
+ dk = TEH_keys_denomination_by_hash (&cdi->coin.denom_pub_hash,
connection,
&mret);
if (NULL == dk)
{
GNUNET_JSON_parse_free (spec);
- return mret;
+ return (MHD_YES == mret)
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
}
if (0 > TALER_amount_cmp (&dk->meta.value,
- &deposit->amount_with_fee))
+ &cdi->amount_with_fee))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -380,7 +375,7 @@ parse_coin (struct MHD_Connection *connection,
return (MHD_YES ==
TEH_RESPONSE_reply_expired_denom_pub_hash (
connection,
- &deposit->coin.denom_pub_hash,
+ &cdi->coin.denom_pub_hash,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED,
"DEPOSIT"))
? GNUNET_NO
@@ -393,7 +388,7 @@ parse_coin (struct MHD_Connection *connection,
return (MHD_YES ==
TEH_RESPONSE_reply_expired_denom_pub_hash (
connection,
- &deposit->coin.denom_pub_hash,
+ &cdi->coin.denom_pub_hash,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE,
"DEPOSIT"))
? GNUNET_NO
@@ -406,13 +401,14 @@ parse_coin (struct MHD_Connection *connection,
return (MHD_YES ==
TEH_RESPONSE_reply_expired_denom_pub_hash (
connection,
- &deposit->coin.denom_pub_hash,
+ &cdi->coin.denom_pub_hash,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
"DEPOSIT"))
? GNUNET_NO
: GNUNET_SYSERR;
}
- if (dk->denom_pub.cipher != deposit->coin.denom_sig.cipher)
+ if (dk->denom_pub.bsign_pub_key->cipher !=
+ cdi->coin.denom_sig.unblinded_sig->cipher)
{
/* denomination cipher and denomination signature cipher not the same */
GNUNET_JSON_parse_free (spec);
@@ -425,21 +421,21 @@ parse_coin (struct MHD_Connection *connection,
: GNUNET_SYSERR;
}
- deposit->deposit_fee = dk->meta.fees.deposit;
+ *deposit_fee = dk->meta.fees.deposit;
/* check coin signature */
- switch (dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
break;
default:
break;
}
if (GNUNET_YES !=
- TALER_test_coin_valid (&deposit->coin,
+ TALER_test_coin_valid (&cdi->coin,
&dk->denom_pub))
{
TALER_LOG_WARNING ("Invalid coin passed for /batch-deposit\n");
@@ -453,8 +449,8 @@ parse_coin (struct MHD_Connection *connection,
: GNUNET_SYSERR;
}
}
- if (0 < TALER_amount_cmp (&deposit->deposit_fee,
- &deposit->amount_with_fee))
+ if (0 < TALER_amount_cmp (deposit_fee,
+ &cdi->amount_with_fee))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -469,18 +465,22 @@ parse_coin (struct MHD_Connection *connection,
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
- TALER_wallet_deposit_verify (&deposit->amount_with_fee,
- &deposit->deposit_fee,
- &dc->h_wire,
- &dc->h_contract_terms,
- &deposit->coin.h_age_commitment,
- &dc->h_extensions,
- &deposit->coin.denom_pub_hash,
- dc->timestamp,
- &dc->merchant_pub,
- dc->refund_deadline,
- &deposit->coin.coin_pub,
- &deposit->csig))
+ TALER_wallet_deposit_verify (
+ &cdi->amount_with_fee,
+ deposit_fee,
+ &dc->h_wire,
+ &bd->h_contract_terms,
+ &bd->wallet_data_hash,
+ cdi->coin.no_age_commitment
+ ? NULL
+ : &cdi->coin.h_age_commitment,
+ NULL != dc->policy_json ? &dc->h_policy : NULL,
+ &cdi->coin.denom_pub_hash,
+ bd->wallet_timestamp,
+ &bd->merchant_pub,
+ bd->refund_deadline,
+ &cdi->coin.coin_pub,
+ &cdi->csig))
{
TALER_LOG_WARNING ("Invalid signature on /batch-deposit request\n");
GNUNET_JSON_parse_free (spec);
@@ -488,22 +488,10 @@ parse_coin (struct MHD_Connection *connection,
TALER_MHD_reply_with_error (connection,
MHD_HTTP_FORBIDDEN,
TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID,
- NULL))
+ TALER_B2S (&cdi->coin.coin_pub)))
? GNUNET_NO
: GNUNET_SYSERR;
}
- deposit->merchant_pub = dc->merchant_pub;
- deposit->h_contract_terms = dc->h_contract_terms;
- deposit->wire_salt = dc->wire_salt;
- deposit->receiver_wire_account = (char *) dc->payto_uri;
- /* FIXME-OEC: should NOT insert the extension details N times,
- but rather insert them ONCE and then per-coin only use
- the resulting extension UUID/serial; so the data structure
- here should be changed once we look at extensions in earnest. */
- deposit->extension_details = dc->extension_details;
- deposit->timestamp = dc->timestamp;
- deposit->refund_deadline = dc->refund_deadline;
- deposit->wire_deadline = dc->wire_deadline;
return GNUNET_OK;
}
@@ -514,59 +502,64 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
const char *const args[])
{
struct MHD_Connection *connection = rc->connection;
- struct BatchDepositContext dc;
- json_t *coins;
+ struct BatchDepositContext dc = { 0 };
+ struct TALER_EXCHANGEDB_BatchDeposit *bd = &dc.bd;
+ const json_t *coins;
bool no_refund_deadline = true;
- bool no_extensions = true;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("merchant_payto_uri",
- &dc.payto_uri),
+ TALER_JSON_spec_payto_uri ("merchant_payto_uri",
+ &bd->receiver_wire_account),
GNUNET_JSON_spec_fixed_auto ("wire_salt",
- &dc.wire_salt),
+ &bd->wire_salt),
GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &dc.merchant_pub),
+ &bd->merchant_pub),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &dc.h_contract_terms),
- GNUNET_JSON_spec_json ("coins",
- &coins),
+ &bd->h_contract_terms),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_json ("extension_details",
- &dc.extension_details),
- &no_extensions),
+ GNUNET_JSON_spec_fixed_auto ("wallet_data_hash",
+ &bd->wallet_data_hash),
+ &bd->no_wallet_data_hash),
+ GNUNET_JSON_spec_array_const ("coins",
+ &coins),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json ("policy",
+ &dc.policy_json),
+ &dc.has_no_policy),
GNUNET_JSON_spec_timestamp ("timestamp",
- &dc.timestamp),
+ &bd->wallet_timestamp),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_timestamp ("refund_deadline",
- &dc.refund_deadline),
+ &bd->refund_deadline),
&no_refund_deadline),
GNUNET_JSON_spec_timestamp ("wire_transfer_deadline",
- &dc.wire_deadline),
+ &bd->wire_deadline),
GNUNET_JSON_spec_end ()
};
- enum GNUNET_GenericReturnValue res;
- memset (&dc,
- 0,
- sizeof (dc));
- res = TALER_MHD_parse_json_data (connection,
- root,
- spec);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- return MHD_NO; /* hard failure */
- }
- if (GNUNET_NO == res)
+ (void) args;
{
- GNUNET_break_op (0);
- return MHD_YES; /* failure */
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ return MHD_YES; /* failure */
+ }
}
/* validate merchant's wire details (as far as we can) */
{
char *emsg;
- emsg = TALER_payto_validate (dc.payto_uri);
+ emsg = TALER_payto_validate (bd->receiver_wire_account);
if (NULL != emsg)
{
MHD_RESULT ret;
@@ -581,9 +574,9 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
return ret;
}
}
- if (GNUNET_TIME_timestamp_cmp (dc.refund_deadline,
+ if (GNUNET_TIME_timestamp_cmp (bd->refund_deadline,
>,
- dc.wire_deadline))
+ bd->wire_deadline))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -592,7 +585,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE,
NULL);
}
- if (GNUNET_TIME_absolute_is_never (dc.wire_deadline.abs_time))
+ if (GNUNET_TIME_absolute_is_never (bd->wire_deadline.abs_time))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -601,18 +594,42 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_DEPOSIT_WIRE_DEADLINE_IS_NEVER,
NULL);
}
- TALER_payto_hash (dc.payto_uri,
- &dc.h_payto);
- TALER_merchant_wire_signature_hash (dc.payto_uri,
- &dc.wire_salt,
+ TALER_payto_hash (bd->receiver_wire_account,
+ &bd->wire_target_h_payto);
+ TALER_merchant_wire_signature_hash (bd->receiver_wire_account,
+ &bd->wire_salt,
&dc.h_wire);
- /* FIXME-OEC: hash actual extension JSON object here */
- // if (! no_extensions)
- memset (&dc.h_extensions,
- 0,
- sizeof (dc.h_extensions));
- dc.num_coins = json_array_size (coins);
- if (0 == dc.num_coins)
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &dc.accumulated_total_without_fee));
+
+ /* handle policy, if present */
+ if (! dc.has_no_policy)
+ {
+ const char *error_hint = NULL;
+
+ if (GNUNET_OK !=
+ TALER_extensions_create_policy_details (
+ TEH_currency,
+ dc.policy_json,
+ &dc.policy_details,
+ &error_hint))
+ {
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (spec);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
+ error_hint);
+ }
+
+ TALER_deposit_policy_hash (dc.policy_json,
+ &dc.h_policy);
+ }
+
+ bd->num_cdis = json_array_size (coins);
+ if (0 == bd->num_cdis)
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -621,7 +638,7 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"coins");
}
- if (TALER_MAX_FRESH_COINS < dc.num_coins)
+ if (TALER_MAX_FRESH_COINS < bd->num_cdis)
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -630,70 +647,91 @@ TEH_handler_batch_deposit (struct TEH_RequestContext *rc,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"coins");
}
- dc.deposits = GNUNET_new_array (dc.num_coins,
- struct TALER_EXCHANGEDB_Deposit);
- for (unsigned int i = 0; i<dc.num_coins; i++)
+
{
- if (GNUNET_OK !=
- (res = parse_coin (connection,
- json_array_get (coins,
- i),
- &dc,
- &dc.deposits[i])))
+ struct TALER_EXCHANGEDB_CoinDepositInformation cdis[
+ GNUNET_NZL (bd->num_cdis)];
+ struct TALER_Amount deposit_fees[GNUNET_NZL (bd->num_cdis)];
+ enum GNUNET_GenericReturnValue res;
+ unsigned int i;
+
+ bd->cdis = cdis;
+ dc.deposit_fees = deposit_fees;
+ for (i = 0; i<bd->num_cdis; i++)
+ {
+ struct TALER_Amount amount_without_fee;
+
+ res = parse_coin (connection,
+ &dc,
+ json_array_get (coins,
+ i),
+ &cdis[i],
+ &deposit_fees[i]);
+ if (GNUNET_OK != res)
+ break;
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (
+ &amount_without_fee,
+ &cdis[i].amount_with_fee,
+ &deposit_fees[i]));
+
+ GNUNET_assert (0 <=
+ TALER_amount_add (
+ &dc.accumulated_total_without_fee,
+ &dc.accumulated_total_without_fee,
+ &amount_without_fee));
+ }
+ if (GNUNET_OK != res)
{
for (unsigned int j = 0; j<i; j++)
- TALER_denom_sig_free (&dc.deposits[j].coin.denom_sig);
- GNUNET_free (dc.deposits);
+ TALER_denom_sig_free (&cdis[j].coin.denom_sig);
GNUNET_JSON_parse_free (spec);
return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
- }
- dc.exchange_timestamp = GNUNET_TIME_timestamp_get ();
- if (GNUNET_SYSERR ==
- TEH_plugin->preflight (TEH_plugin->cls))
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_START_FAILED,
- "preflight failure");
- }
+ dc.exchange_timestamp = GNUNET_TIME_timestamp_get ();
+ if (GNUNET_SYSERR ==
+ TEH_plugin->preflight (TEH_plugin->cls))
+ {
+ GNUNET_break (0);
+ GNUNET_JSON_parse_free (spec);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_START_FAILED,
+ "preflight failure");
+ }
- /* execute transaction */
- {
- MHD_RESULT mhd_ret;
+ /* execute transaction */
+ {
+ MHD_RESULT mhd_ret;
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (connection,
+ "execute batch deposit",
+ TEH_MT_REQUEST_BATCH_DEPOSIT,
+ &mhd_ret,
+ &batch_deposit_transaction,
+ &dc))
+ {
+ for (unsigned int j = 0; j<bd->num_cdis; j++)
+ TALER_denom_sig_free (&cdis[j].coin.denom_sig);
+ GNUNET_JSON_parse_free (spec);
+ return mhd_ret;
+ }
+ }
- if (GNUNET_OK !=
- TEH_DB_run_transaction (connection,
- "execute batch deposit",
- TEH_MT_REQUEST_BATCH_DEPOSIT,
- &mhd_ret,
- &batch_deposit_transaction,
- &dc))
+ /* generate regular response */
{
- GNUNET_JSON_parse_free (spec);
- for (unsigned int j = 0; j<dc.num_coins; j++)
- TALER_denom_sig_free (&dc.deposits[j].coin.denom_sig);
- GNUNET_free (dc.deposits);
+ MHD_RESULT mhd_ret;
+
+ mhd_ret = reply_batch_deposit_success (connection,
+ &dc);
+ for (unsigned int j = 0; j<bd->num_cdis; j++)
+ TALER_denom_sig_free (&cdis[j].coin.denom_sig);
GNUNET_JSON_parse_free (spec);
return mhd_ret;
}
}
-
- /* generate regular response */
- {
- MHD_RESULT res;
-
- res = reply_batch_deposit_success (connection,
- &dc);
- for (unsigned int j = 0; j<dc.num_coins; j++)
- TALER_denom_sig_free (&dc.deposits[j].coin.denom_sig);
- GNUNET_free (dc.deposits);
- GNUNET_JSON_parse_free (spec);
- return res;
- }
}
diff --git a/src/exchange/taler-exchange-httpd_batch-withdraw.c b/src/exchange/taler-exchange-httpd_batch-withdraw.c
index d306838bf..2b80c2fc4 100644
--- a/src/exchange/taler-exchange-httpd_batch-withdraw.c
+++ b/src/exchange/taler-exchange-httpd_batch-withdraw.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -26,11 +26,14 @@
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
+#include "taler-exchange-httpd.h"
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_batch-withdraw.h"
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_keys.h"
+#include "taler_util.h"
/**
@@ -72,11 +75,16 @@ struct BatchWithdrawContext
{
/**
- * Public key of the reserv.
+ * Public key of the reserve.
*/
const struct TALER_ReservePublicKeyP *reserve_pub;
/**
+ * request context
+ */
+ const struct TEH_RequestContext *rc;
+
+ /**
* KYC status of the reserve used for the operation.
*/
struct TALER_EXCHANGEDB_KycStatus kyc;
@@ -87,6 +95,17 @@ struct BatchWithdrawContext
struct PlanchetContext *planchets;
/**
+ * Hash of the payto-URI representing the reserve
+ * from which we are withdrawing.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Current time for the DB transaction.
+ */
+ struct GNUNET_TIME_Timestamp now;
+
+ /**
* Total amount from all coins with fees.
*/
struct TALER_Amount batch_total;
@@ -96,10 +115,175 @@ struct BatchWithdrawContext
*/
unsigned int planchets_length;
+ /**
+ * AML decision, #TALER_AML_NORMAL if we may proceed.
+ */
+ enum TALER_AmlDecisionState aml_decision;
+
};
/**
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param cls closure, identifies the event type and
+ * account to iterate over events for
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
+ */
+static void
+batch_withdraw_amount_cb (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
+{
+ struct BatchWithdrawContext *wc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ if (GNUNET_OK !=
+ cb (cb_cls,
+ &wc->batch_total,
+ wc->now.abs_time))
+ return;
+ qs = TEH_plugin->select_withdraw_amounts_for_kyc_check (
+ TEH_plugin->cls,
+ &wc->h_payto,
+ limit,
+ cb,
+ cb_cls);
+ GNUNET_break (qs >= 0);
+}
+
+
+/**
+ * Function called on each @a amount that was found to
+ * be relevant for the AML check as it was merged into
+ * the reserve.
+ *
+ * @param cls `struct TALER_Amount *` to total up the amounts
+ * @param amount encountered transaction amount
+ * @param date when was the amount encountered
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to abort iteration
+ * #GNUNET_SYSERR on internal error (also abort itaration)
+ */
+static enum GNUNET_GenericReturnValue
+aml_amount_cb (
+ void *cls,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Absolute date)
+{
+ struct TALER_Amount *total = cls;
+
+ GNUNET_assert (0 <=
+ TALER_amount_add (total,
+ total,
+ amount));
+ return GNUNET_OK;
+}
+
+
+/**
+ * Generates our final (successful) response.
+ *
+ * @param rc request context
+ * @param wc operation context
+ * @return MHD queue status
+ */
+static MHD_RESULT
+generate_reply_success (const struct TEH_RequestContext *rc,
+ const struct BatchWithdrawContext *wc)
+{
+ json_t *sigs;
+
+ if (! wc->kyc.ok)
+ {
+ /* KYC required */
+ return TEH_RESPONSE_reply_kyc_required (rc->connection,
+ &wc->h_payto,
+ &wc->kyc);
+ }
+ if (TALER_AML_NORMAL != wc->aml_decision)
+ return TEH_RESPONSE_reply_aml_blocked (rc->connection,
+ wc->aml_decision);
+
+ sigs = json_array ();
+ GNUNET_assert (NULL != sigs);
+ for (unsigned int i = 0; i<wc->planchets_length; i++)
+ {
+ struct PlanchetContext *pc = &wc->planchets[i];
+
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ sigs,
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_blinded_denom_sig (
+ "ev_sig",
+ &pc->collectable.sig))));
+ }
+ TEH_METRICS_batch_withdraw_num_coins += wc->planchets_length;
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("ev_sigs",
+ sigs));
+}
+
+
+/**
+ * Check if the @a wc is replayed and we already have an
+ * answer. If so, replay the existing answer and return the
+ * HTTP response.
+ *
+ * @param wc parsed request data
+ * @param[out] mret HTTP status, set if we return true
+ * @return true if the request is idempotent with an existing request
+ * false if we did not find the request in the DB and did not set @a mret
+ */
+static bool
+check_request_idempotent (const struct BatchWithdrawContext *wc,
+ MHD_RESULT *mret)
+{
+ const struct TEH_RequestContext *rc = wc->rc;
+
+ for (unsigned int i = 0; i<wc->planchets_length; i++)
+ {
+ struct PlanchetContext *pc = &wc->planchets[i];
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls,
+ &pc->h_coin_envelope,
+ &pc->collectable);
+ if (0 > qs)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mret = TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_withdraw_info");
+ return true; /* well, kind-of */
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ return false;
+ }
+ /* generate idempotent reply */
+ TEH_METRICS_num_requests[TEH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW]++;
+ *mret = generate_reply_success (rc,
+ wc);
+ return true;
+}
+
+
+/**
* Function implementing withdraw transaction. Runs the
* transaction logic; IF it returns a non-error code, the transaction
* logic MUST NOT queue a MHD response. IF it returns an hard error,
@@ -122,28 +306,191 @@ batch_withdraw_transaction (void *cls,
MHD_RESULT *mhd_ret)
{
struct BatchWithdrawContext *wc = cls;
- struct GNUNET_TIME_Timestamp now;
uint64_t ruuid;
enum GNUNET_DB_QueryStatus qs;
- bool balance_ok = false;
bool found = false;
+ bool balance_ok = false;
+ bool age_ok = false;
+ uint16_t allowed_maximum_age = 0;
+ struct TALER_Amount reserve_balance;
+ char *kyc_required;
+ struct TALER_PaytoHashP reserve_h_payto;
+
+ wc->now = GNUNET_TIME_timestamp_get ();
+ /* Do AML check: compute total merged amount and check
+ against applicable AML threshold */
+ {
+ char *reserve_payto;
+
+ reserve_payto = TALER_reserve_make_payto (TEH_base_url,
+ wc->reserve_pub);
+ TALER_payto_hash (reserve_payto,
+ &reserve_h_payto);
+ GNUNET_free (reserve_payto);
+ }
+ {
+ struct TALER_Amount merge_amount;
+ struct TALER_Amount threshold;
+ struct GNUNET_TIME_Absolute now_minus_one_month;
+
+ now_minus_one_month
+ = GNUNET_TIME_absolute_subtract (wc->now.abs_time,
+ GNUNET_TIME_UNIT_MONTHS);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &merge_amount));
+ qs = TEH_plugin->select_merge_amounts_for_kyc_check (TEH_plugin->cls,
+ &reserve_h_payto,
+ now_minus_one_month,
+ &aml_amount_cb,
+ &merge_amount);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_merge_amounts_for_kyc_check");
+ return qs;
+ }
+ qs = TEH_plugin->select_aml_threshold (TEH_plugin->cls,
+ &reserve_h_payto,
+ &wc->aml_decision,
+ &wc->kyc,
+ &threshold);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_aml_threshold");
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ threshold = TEH_aml_threshold; /* use default */
+ wc->aml_decision = TALER_AML_NORMAL;
+ }
+
+ switch (wc->aml_decision)
+ {
+ case TALER_AML_NORMAL:
+ if (0 >= TALER_amount_cmp (&merge_amount,
+ &threshold))
+ {
+ /* merge_amount <= threshold, continue withdraw below */
+ break;
+ }
+ wc->aml_decision = TALER_AML_PENDING;
+ qs = TEH_plugin->trigger_aml_process (TEH_plugin->cls,
+ &reserve_h_payto,
+ &merge_amount);
+ if (qs <= 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "trigger_aml_process");
+ return qs;
+ }
+ return qs;
+ case TALER_AML_PENDING:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "AML already pending, doing nothing\n");
+ return qs;
+ case TALER_AML_FROZEN:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Account frozen, doing nothing\n");
+ return qs;
+ }
+ }
+
+ /* Check if the money came from a wire transfer */
+ qs = TEH_plugin->reserves_get_origin (TEH_plugin->cls,
+ wc->reserve_pub,
+ &wc->h_payto);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "reserves_get_origin");
+ return qs;
+ }
+ /* If no results, reserve was created by merge, in which case no KYC check
+ is required as the merge already did that. */
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_WITHDRAW,
+ &wc->h_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &batch_withdraw_amount_cb,
+ wc,
+ &kyc_required);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "kyc_test_required");
+ return qs;
+ }
+ if (NULL != kyc_required)
+ {
+ /* insert KYC requirement into DB! */
+ wc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ kyc_required,
+ &wc->h_payto,
+ wc->reserve_pub,
+ &wc->kyc.requirement_row);
+ GNUNET_free (kyc_required);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_for_account");
+ }
+ return qs;
+ }
+ }
+ wc->kyc.ok = true;
- now = GNUNET_TIME_timestamp_get ();
qs = TEH_plugin->do_batch_withdraw (TEH_plugin->cls,
- now,
+ wc->now,
wc->reserve_pub,
&wc->batch_total,
+ TEH_age_restriction_enabled,
&found,
&balance_ok,
- &wc->kyc,
+ &reserve_balance,
+ &age_ok,
+ &allowed_maximum_age,
&ruuid);
if (0 > qs)
{
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
"update_reserve_batch_withdraw");
+ }
return qs;
}
if (! found)
@@ -154,82 +501,59 @@ batch_withdraw_transaction (void *cls,
NULL);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (! balance_ok)
+
+ if (! age_ok)
{
+ /* We respond with the lowest age in the corresponding age group
+ * of the required age */
+ uint16_t lowest_age = TALER_get_lowest_age (
+ &TEH_age_restriction_config.mask,
+ allowed_maximum_age);
+
TEH_plugin->rollback (TEH_plugin->cls);
- *mhd_ret = TEH_RESPONSE_reply_reserve_insufficient_balance (
+ *mhd_ret = TEH_RESPONSE_reply_reserve_age_restriction_required (
connection,
- &wc->batch_total,
- wc->reserve_pub);
+ lowest_age);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if ( (TEH_KYC_NONE != TEH_kyc_config.mode) &&
- (! wc->kyc.ok) &&
- (TALER_EXCHANGEDB_KYC_W2W == wc->kyc.type) )
+ if (! balance_ok)
{
- /* Wallet-to-wallet payments _always_ require KYC */
- *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
+ TEH_plugin->rollback (TEH_plugin->cls);
+ *mhd_ret = TEH_RESPONSE_reply_reserve_insufficient_balance (
connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- wc->kyc.payment_target_uuid));
+ TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS,
+ &reserve_balance,
+ &wc->batch_total,
+ wc->reserve_pub);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if ( (TEH_KYC_NONE != TEH_kyc_config.mode) &&
- (! wc->kyc.ok) &&
- (TALER_EXCHANGEDB_KYC_WITHDRAW == wc->kyc.type) &&
- (! GNUNET_TIME_relative_is_zero (TEH_kyc_config.withdraw_period)) )
- {
- /* Withdraws require KYC if above threshold */
- enum GNUNET_DB_QueryStatus qs2;
- bool below_limit;
-
- qs2 = TEH_plugin->do_withdraw_limit_check (
- TEH_plugin->cls,
- ruuid,
- GNUNET_TIME_absolute_subtract (now.abs_time,
- TEH_kyc_config.withdraw_period),
- &TEH_kyc_config.withdraw_limit,
- &below_limit);
- if (0 > qs2)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs2);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs2)
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "do_withdraw_limit_check");
- return qs2;
- }
- if (! below_limit)
- {
- *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- wc->kyc.payment_target_uuid));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
/* Add information about each planchet in the batch */
for (unsigned int i = 0; i<wc->planchets_length; i++)
{
struct PlanchetContext *pc = &wc->planchets[i];
const struct TALER_BlindedPlanchet *bp = &pc->blinded_planchet;
- const struct TALER_CsNonce *nonce;
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce = NULL;
bool denom_unknown = true;
bool conflict = true;
bool nonce_reuse = true;
- nonce = (TALER_DENOMINATION_CS == bp->cipher)
- ? &bp->details.cs_blinded_planchet.nonce
- : NULL;
+ switch (bp->blinded_message->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ nonce = (const union GNUNET_CRYPTO_BlindSessionNonce *)
+ &bp->blinded_message->details.cs_blinded_message.nonce;
+ break;
+ }
qs = TEH_plugin->do_batch_withdraw_insert (TEH_plugin->cls,
nonce,
&pc->collectable,
- now,
+ wc->now,
ruuid,
&denom_unknown,
&conflict,
@@ -240,7 +564,7 @@ batch_withdraw_transaction (void *cls,
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "do_withdraw");
+ "do_batch_withdraw_insert");
return qs;
}
if (denom_unknown)
@@ -255,12 +579,18 @@ batch_withdraw_transaction (void *cls,
if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) ||
(conflict) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Idempotent coin in batch, not allowed. Aborting.\n");
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_CONFLICT,
- TALER_EC_EXCHANGE_WITHDRAW_BATCH_IDEMPOTENT_PLANCHET,
- NULL);
+ if (! check_request_idempotent (wc,
+ mhd_ret))
+ {
+ /* We do not support *some* of the coins of the request being
+ idempotent while others being fresh. */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Idempotent coin in batch, not allowed. Aborting.\n");
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_WITHDRAW_BATCH_IDEMPOTENT_PLANCHET,
+ NULL);
+ }
return GNUNET_DB_STATUS_HARD_ERROR;
}
if (nonce_reuse)
@@ -279,88 +609,6 @@ batch_withdraw_transaction (void *cls,
/**
- * Generates our final (successful) response.
- *
- * @param rc request context
- * @param wc operation context
- * @return MHD queue status
- */
-static MHD_RESULT
-generate_reply_success (const struct TEH_RequestContext *rc,
- const struct BatchWithdrawContext *wc)
-{
- json_t *sigs;
-
- sigs = json_array ();
- GNUNET_assert (NULL != sigs);
- for (unsigned int i = 0; i<wc->planchets_length; i++)
- {
- struct PlanchetContext *pc = &wc->planchets[i];
-
- GNUNET_assert (
- 0 ==
- json_array_append_new (
- sigs,
- GNUNET_JSON_PACK (
- TALER_JSON_pack_blinded_denom_sig (
- "ev_sig",
- &pc->collectable.sig))));
- }
- TEH_METRICS_batch_withdraw_num_coins += wc->planchets_length;
- return TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_array_steal ("ev_sigs",
- sigs));
-}
-
-
-/**
- * Check if the @a rc is replayed and we already have an
- * answer. If so, replay the existing answer and return the
- * HTTP response.
- *
- * @param rc request context
- * @param wc parsed request data
- * @param[out] mret HTTP status, set if we return true
- * @return true if the request is idempotent with an existing request
- * false if we did not find the request in the DB and did not set @a mret
- */
-static bool
-check_request_idempotent (const struct TEH_RequestContext *rc,
- const struct BatchWithdrawContext *wc,
- MHD_RESULT *mret)
-{
- for (unsigned int i = 0; i<wc->planchets_length; i++)
- {
- struct PlanchetContext *pc = &wc->planchets[i];
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls,
- &pc->h_coin_envelope,
- &pc->collectable);
- if (0 > qs)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- *mret = TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_withdraw_info");
- return true; /* well, kind-of */
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- return false;
- }
- /* generate idempotent reply */
- TEH_METRICS_num_requests[TEH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW]++;
- *mret = generate_reply_success (rc,
- wc);
- return true;
-}
-
-
-/**
* The request was parsed successfully. Prepare
* our side for the main DB transaction.
*
@@ -372,20 +620,24 @@ static MHD_RESULT
prepare_transaction (const struct TEH_RequestContext *rc,
struct BatchWithdrawContext *wc)
{
- /* Note: We could check the reserve balance here,
- just to be reasonably sure that the reserve has
- a sufficient balance before doing the "expensive"
- signatures... */
- /* Sign before transaction! */
+ struct TEH_CoinSignData csds[wc->planchets_length];
+ struct TALER_BlindedDenominationSignature bss[wc->planchets_length];
+
for (unsigned int i = 0; i<wc->planchets_length; i++)
{
struct PlanchetContext *pc = &wc->planchets[i];
+
+ csds[i].h_denom_pub = &pc->collectable.denom_pub_hash;
+ csds[i].bp = &pc->blinded_planchet;
+ }
+ {
enum TALER_ErrorCode ec;
- ec = TEH_keys_denomination_sign_withdraw (
- &pc->collectable.denom_pub_hash,
- &pc->blinded_planchet,
- &pc->collectable.sig);
+ ec = TEH_keys_denomination_batch_sign (
+ wc->planchets_length,
+ csds,
+ false,
+ bss);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
@@ -394,6 +646,12 @@ prepare_transaction (const struct TEH_RequestContext *rc,
NULL);
}
}
+ for (unsigned int i = 0; i<wc->planchets_length; i++)
+ {
+ struct PlanchetContext *pc = &wc->planchets[i];
+
+ pc->collectable.sig = bss[i];
+ }
/* run transaction */
{
@@ -477,8 +735,7 @@ parse_planchets (const struct TEH_RequestContext *rc,
ksh = TEH_keys_get_state ();
if (NULL == ksh)
{
- if (! check_request_idempotent (rc,
- wc,
+ if (! check_request_idempotent (wc,
&mret))
{
return TALER_MHD_reply_with_error (rc->connection,
@@ -493,14 +750,15 @@ parse_planchets (const struct TEH_RequestContext *rc,
struct PlanchetContext *pc = &wc->planchets[i];
struct TEH_DenominationKey *dk;
- dk = TEH_keys_denomination_by_hash2 (ksh,
- &pc->collectable.denom_pub_hash,
- NULL,
- NULL);
+ dk = TEH_keys_denomination_by_hash_from_state (
+ ksh,
+ &pc->collectable.denom_pub_hash,
+ NULL,
+ NULL);
+
if (NULL == dk)
{
- if (! check_request_idempotent (rc,
- wc,
+ if (! check_request_idempotent (wc,
&mret))
{
return TEH_RESPONSE_reply_unknown_denom_pub_hash (
@@ -512,8 +770,7 @@ parse_planchets (const struct TEH_RequestContext *rc,
if (GNUNET_TIME_absolute_is_past (dk->meta.expire_withdraw.abs_time))
{
/* This denomination is past the expiration time for withdraws */
- if (! check_request_idempotent (rc,
- wc,
+ if (! check_request_idempotent (wc,
&mret))
{
return TEH_RESPONSE_reply_expired_denom_pub_hash (
@@ -537,8 +794,7 @@ parse_planchets (const struct TEH_RequestContext *rc,
if (dk->recoup_possible)
{
/* This denomination has been revoked */
- if (! check_request_idempotent (rc,
- wc,
+ if (! check_request_idempotent (wc,
&mret))
{
return TEH_RESPONSE_reply_expired_denom_pub_hash (
@@ -549,7 +805,8 @@ parse_planchets (const struct TEH_RequestContext *rc,
}
return mret;
}
- if (dk->denom_pub.cipher != pc->blinded_planchet.cipher)
+ if (dk->denom_pub.bsign_pub_key->cipher !=
+ pc->blinded_planchet.blinded_message->cipher)
{
/* denomination cipher and blinded planchet cipher not the same */
GNUNET_break_op (0);
@@ -581,17 +838,10 @@ parse_planchets (const struct TEH_RequestContext *rc,
NULL);
}
- if (GNUNET_OK !=
- TALER_coin_ev_hash (&pc->blinded_planchet,
- &pc->collectable.denom_pub_hash,
- &pc->collectable.h_coin_envelope))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- NULL);
- }
+ TALER_coin_ev_hash (&pc->blinded_planchet,
+ &pc->collectable.denom_pub_hash,
+ &pc->collectable.h_coin_envelope);
+
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
TALER_wallet_withdraw_verify (&pc->collectable.denom_pub_hash,
@@ -618,22 +868,20 @@ TEH_handler_batch_withdraw (struct TEH_RequestContext *rc,
const struct TALER_ReservePublicKeyP *reserve_pub,
const json_t *root)
{
- struct BatchWithdrawContext wc;
- json_t *planchets;
+ struct BatchWithdrawContext wc = {
+ .reserve_pub = reserve_pub,
+ .rc = rc
+ };
+ const json_t *planchets;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("planchets",
- &planchets),
+ GNUNET_JSON_spec_array_const ("planchets",
+ &planchets),
GNUNET_JSON_spec_end ()
};
- memset (&wc,
- 0,
- sizeof (wc));
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TEH_currency,
&wc.batch_total));
- wc.reserve_pub = reserve_pub;
-
{
enum GNUNET_GenericReturnValue res;
@@ -643,20 +891,17 @@ TEH_handler_batch_withdraw (struct TEH_RequestContext *rc,
if (GNUNET_OK != res)
return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
}
- if ( (! json_is_array (planchets)) ||
- (0 == json_array_size (planchets)) )
+ wc.planchets_length = json_array_size (planchets);
+ if (0 == wc.planchets_length)
{
- GNUNET_JSON_parse_free (spec);
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"planchets");
}
- wc.planchets_length = json_array_size (planchets);
if (wc.planchets_length > TALER_MAX_FRESH_COINS)
{
- GNUNET_JSON_parse_free (spec);
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
@@ -682,7 +927,6 @@ TEH_handler_batch_withdraw (struct TEH_RequestContext *rc,
TALER_blinded_planchet_free (&pc->blinded_planchet);
TALER_blinded_denom_sig_free (&pc->collectable.sig);
}
- GNUNET_JSON_parse_free (spec);
return ret;
}
}
diff --git a/src/exchange/taler-exchange-httpd_coins_get.c b/src/exchange/taler-exchange-httpd_coins_get.c
new file mode 100644
index 000000000..cd453275e
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_coins_get.c
@@ -0,0 +1,709 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_coins_get.c
+ * @brief Handle GET /coins/$COIN_PUB/history requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include "taler_dbevents.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_coins_get.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Add the headers we want to set for every response.
+ *
+ * @param cls the key state to use
+ * @param[in,out] response the response to modify
+ */
+static void
+add_response_headers (void *cls,
+ struct MHD_Response *response)
+{
+ (void) cls;
+ TALER_MHD_add_global_headers (response);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (response,
+ MHD_HTTP_HEADER_CACHE_CONTROL,
+ "no-cache"));
+}
+
+
+/**
+ * Compile the transaction history of a coin into a JSON object.
+ *
+ * @param coin_pub public key of the coin
+ * @param tl transaction history to JSON-ify
+ * @return json representation of the @a rh, NULL on error
+ */
+static json_t *
+compile_transaction_history (
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_EXCHANGEDB_TransactionList *tl)
+{
+ json_t *history;
+
+ history = json_array ();
+ if (NULL == history)
+ {
+ GNUNET_break (0); /* out of memory!? */
+ return NULL;
+ }
+ for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl;
+ NULL != pos;
+ pos = pos->next)
+ {
+ switch (pos->type)
+ {
+ case TALER_EXCHANGEDB_TT_DEPOSIT:
+ {
+ const struct TALER_EXCHANGEDB_DepositListEntry *deposit =
+ pos->details.deposit;
+ struct TALER_MerchantWireHashP h_wire;
+
+ TALER_merchant_wire_signature_hash (deposit->receiver_wire_account,
+ &deposit->wire_salt,
+ &h_wire);
+#if ENABLE_SANITY_CHECKS
+ /* internal sanity check before we hand out a bogus sig... */
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_wallet_deposit_verify (
+ &deposit->amount_with_fee,
+ &deposit->deposit_fee,
+ &h_wire,
+ &deposit->h_contract_terms,
+ deposit->no_wallet_data_hash
+ ? NULL
+ : &deposit->wallet_data_hash,
+ deposit->no_age_commitment
+ ? NULL
+ : &deposit->h_age_commitment,
+ &deposit->h_policy,
+ &deposit->h_denom_pub,
+ deposit->timestamp,
+ &deposit->merchant_pub,
+ deposit->refund_deadline,
+ coin_pub,
+ &deposit->csig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+#endif
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "DEPOSIT"),
+ TALER_JSON_pack_amount ("amount",
+ &deposit->amount_with_fee),
+ TALER_JSON_pack_amount ("deposit_fee",
+ &deposit->deposit_fee),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ deposit->timestamp),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_timestamp ("refund_deadline",
+ deposit->refund_deadline)),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &deposit->merchant_pub),
+ GNUNET_JSON_pack_data_auto ("h_contract_terms",
+ &deposit->h_contract_terms),
+ GNUNET_JSON_pack_data_auto ("h_wire",
+ &h_wire),
+ GNUNET_JSON_pack_allow_null (
+ deposit->no_age_commitment ?
+ GNUNET_JSON_pack_string (
+ "h_age_commitment", NULL) :
+ GNUNET_JSON_pack_data_auto ("h_age_commitment",
+ &deposit->h_age_commitment)),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &deposit->csig))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ break;
+ }
+ case TALER_EXCHANGEDB_TT_MELT:
+ {
+ const struct TALER_EXCHANGEDB_MeltListEntry *melt =
+ pos->details.melt;
+ const struct TALER_AgeCommitmentHash *phac = NULL;
+
+#if ENABLE_SANITY_CHECKS
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_wallet_melt_verify (
+ &melt->amount_with_fee,
+ &melt->melt_fee,
+ &melt->rc,
+ &melt->h_denom_pub,
+ &melt->h_age_commitment,
+ coin_pub,
+ &melt->coin_sig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+#endif
+
+ /* Age restriction is optional. We communicate a NULL value to
+ * JSON_PACK below */
+ if (! melt->no_age_commitment)
+ phac = &melt->h_age_commitment;
+
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "MELT"),
+ TALER_JSON_pack_amount ("amount",
+ &melt->amount_with_fee),
+ TALER_JSON_pack_amount ("melt_fee",
+ &melt->melt_fee),
+ GNUNET_JSON_pack_data_auto ("rc",
+ &melt->rc),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("h_age_commitment",
+ phac)),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &melt->coin_sig))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_TT_REFUND:
+ {
+ const struct TALER_EXCHANGEDB_RefundListEntry *refund =
+ pos->details.refund;
+ struct TALER_Amount value;
+
+#if ENABLE_SANITY_CHECKS
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_merchant_refund_verify (
+ coin_pub,
+ &refund->h_contract_terms,
+ refund->rtransaction_id,
+ &refund->refund_amount,
+ &refund->merchant_pub,
+ &refund->merchant_sig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+#endif
+ if (0 >
+ TALER_amount_subtract (&value,
+ &refund->refund_amount,
+ &refund->refund_fee))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "REFUND"),
+ TALER_JSON_pack_amount ("amount",
+ &value),
+ TALER_JSON_pack_amount ("refund_fee",
+ &refund->refund_fee),
+ GNUNET_JSON_pack_data_auto ("h_contract_terms",
+ &refund->h_contract_terms),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &refund->merchant_pub),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ refund->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("merchant_sig",
+ &refund->merchant_sig))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
+ {
+ struct TALER_EXCHANGEDB_RecoupRefreshListEntry *pr =
+ pos->details.old_coin_recoup;
+ struct TALER_ExchangePublicKeyP epub;
+ struct TALER_ExchangeSignatureP esig;
+
+ if (TALER_EC_NONE !=
+ TALER_exchange_online_confirm_recoup_refresh_sign (
+ &TEH_keys_exchange_sign_,
+ pr->timestamp,
+ &pr->value,
+ &pr->coin.coin_pub,
+ &pr->old_coin_pub,
+ &epub,
+ &esig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ /* NOTE: we could also provide coin_pub's coin_sig, denomination key hash and
+ the denomination key's RSA signature over coin_pub, but as the
+ wallet should really already have this information (and cannot
+ check or do anything with it anyway if it doesn't), it seems
+ strictly unnecessary. */
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "OLD-COIN-RECOUP"),
+ TALER_JSON_pack_amount ("amount",
+ &pr->value),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &esig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &epub),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &pr->coin.coin_pub),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ pr->timestamp))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ break;
+ }
+ case TALER_EXCHANGEDB_TT_RECOUP:
+ {
+ const struct TALER_EXCHANGEDB_RecoupListEntry *recoup =
+ pos->details.recoup;
+ struct TALER_ExchangePublicKeyP epub;
+ struct TALER_ExchangeSignatureP esig;
+
+ if (TALER_EC_NONE !=
+ TALER_exchange_online_confirm_recoup_sign (
+ &TEH_keys_exchange_sign_,
+ recoup->timestamp,
+ &recoup->value,
+ coin_pub,
+ &recoup->reserve_pub,
+ &epub,
+ &esig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "RECOUP"),
+ TALER_JSON_pack_amount ("amount",
+ &recoup->value),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &esig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &epub),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ &recoup->reserve_pub),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &recoup->coin_sig),
+ GNUNET_JSON_pack_data_auto ("coin_blind",
+ &recoup->coin_blind),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ &recoup->reserve_pub),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ recoup->timestamp))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
+ {
+ struct TALER_EXCHANGEDB_RecoupRefreshListEntry *pr =
+ pos->details.recoup_refresh;
+ struct TALER_ExchangePublicKeyP epub;
+ struct TALER_ExchangeSignatureP esig;
+
+ if (TALER_EC_NONE !=
+ TALER_exchange_online_confirm_recoup_refresh_sign (
+ &TEH_keys_exchange_sign_,
+ pr->timestamp,
+ &pr->value,
+ coin_pub,
+ &pr->old_coin_pub,
+ &epub,
+ &esig))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ /* NOTE: we could also provide coin_pub's coin_sig, denomination key
+ hash and the denomination key's RSA signature over coin_pub, but as
+ the wallet should really already have this information (and cannot
+ check or do anything with it anyway if it doesn't), it seems
+ strictly unnecessary. */
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "RECOUP-REFRESH"),
+ TALER_JSON_pack_amount ("amount",
+ &pr->value),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &esig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &epub),
+ GNUNET_JSON_pack_data_auto ("old_coin_pub",
+ &pr->old_coin_pub),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &pr->coin_sig),
+ GNUNET_JSON_pack_data_auto ("coin_blind",
+ &pr->coin_blind),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ pr->timestamp))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ break;
+ }
+
+ case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
+ {
+ struct TALER_EXCHANGEDB_PurseDepositListEntry *pd
+ = pos->details.purse_deposit;
+ const struct TALER_AgeCommitmentHash *phac = NULL;
+
+ if (! pd->no_age_commitment)
+ phac = &pd->h_age_commitment;
+
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "PURSE-DEPOSIT"),
+ TALER_JSON_pack_amount ("amount",
+ &pd->amount),
+ GNUNET_JSON_pack_string ("exchange_base_url",
+ NULL == pd->exchange_base_url
+ ? TEH_base_url
+ : pd->exchange_base_url),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("h_age_commitment",
+ phac)),
+ GNUNET_JSON_pack_data_auto ("purse_pub",
+ &pd->purse_pub),
+ GNUNET_JSON_pack_bool ("refunded",
+ pd->refunded),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &pd->coin_sig))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ break;
+ }
+
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ {
+ const struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund =
+ pos->details.purse_refund;
+ struct TALER_Amount value;
+ enum TALER_ErrorCode ec;
+ struct TALER_ExchangePublicKeyP epub;
+ struct TALER_ExchangeSignatureP esig;
+
+ if (0 >
+ TALER_amount_subtract (&value,
+ &prefund->refund_amount,
+ &prefund->refund_fee))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ ec = TALER_exchange_online_purse_refund_sign (
+ &TEH_keys_exchange_sign_,
+ &value,
+ &prefund->refund_fee,
+ coin_pub,
+ &prefund->purse_pub,
+ &epub,
+ &esig);
+ if (TALER_EC_NONE != ec)
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "PURSE-REFUND"),
+ TALER_JSON_pack_amount ("amount",
+ &value),
+ TALER_JSON_pack_amount ("refund_fee",
+ &prefund->refund_fee),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &esig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &epub),
+ GNUNET_JSON_pack_data_auto ("purse_pub",
+ &prefund->purse_pub))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ }
+ break;
+
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ {
+ struct TALER_EXCHANGEDB_ReserveOpenListEntry *role
+ = pos->details.reserve_open;
+
+ if (0 !=
+ json_array_append_new (
+ history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "RESERVE-OPEN-DEPOSIT"),
+ TALER_JSON_pack_amount ("coin_contribution",
+ &role->coin_contribution),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &role->reserve_sig),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &role->coin_sig))))
+ {
+ GNUNET_break (0);
+ json_decref (history);
+ return NULL;
+ }
+ break;
+ }
+ }
+ }
+ return history;
+}
+
+
+MHD_RESULT
+TEH_handler_coins_get (struct TEH_RequestContext *rc,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub)
+{
+ struct TALER_EXCHANGEDB_TransactionList *tl = NULL;
+ uint64_t start_off = 0;
+ uint64_t etag_in;
+ uint64_t etag_out;
+ char etagp[24];
+ struct MHD_Response *resp;
+ unsigned int http_status;
+ struct TALER_DenominationHashP h_denom_pub;
+ struct TALER_Amount balance;
+
+ TALER_MHD_parse_request_number (rc->connection,
+ "start",
+ &start_off);
+ /* Check signature */
+ {
+ struct TALER_CoinSpendSignatureP coin_sig;
+ bool required = true;
+
+ TALER_MHD_parse_request_header_auto (rc->connection,
+ TALER_COIN_HISTORY_SIGNATURE_HEADER,
+ &coin_sig,
+ required);
+ if (GNUNET_OK !=
+ TALER_wallet_coin_history_verify (start_off,
+ coin_pub,
+ &coin_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_COIN_HISTORY_BAD_SIGNATURE,
+ NULL);
+ }
+ }
+
+ /* Get etag */
+ {
+ const char *etags;
+
+ etags = MHD_lookup_connection_value (rc->connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_IF_NONE_MATCH);
+ if (NULL != etags)
+ {
+ char dummy;
+ unsigned long long ev;
+
+ if (1 != sscanf (etags,
+ "\"%llu\"%c",
+ &ev,
+ &dummy))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Client send malformed `If-None-Match' header `%s'\n",
+ etags);
+ etag_in = start_off;
+ }
+ else
+ {
+ etag_in = (uint64_t) ev;
+ }
+ }
+ else
+ {
+ etag_in = start_off;
+ }
+ }
+
+ /* Get history from DB between etag and now */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
+ coin_pub,
+ start_off,
+ etag_in,
+ &etag_out,
+ &balance,
+ &h_denom_pub,
+ &tl);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_coin_history");
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "get_coin_history");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_COIN_UNKNOWN,
+ NULL);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* Handled below */
+ break;
+ }
+ }
+
+ GNUNET_snprintf (etagp,
+ sizeof (etagp),
+ "\"%llu\"",
+ (unsigned long long) etag_out);
+ if (etag_in == etag_out)
+ {
+ return TEH_RESPONSE_reply_not_modified (rc->connection,
+ etagp,
+ &add_response_headers,
+ NULL);
+ }
+ if (NULL == tl)
+ {
+ /* 204: empty history */
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ http_status = MHD_HTTP_NO_CONTENT;
+ }
+ else
+ {
+ /* 200: regular history */
+ json_t *history;
+
+ history = compile_transaction_history (coin_pub,
+ tl);
+ TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
+ tl);
+ tl = NULL;
+ if (NULL == history)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
+ "Failed to compile coin history");
+ }
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("h_denom_pub",
+ &h_denom_pub),
+ TALER_JSON_pack_amount ("balance",
+ &balance),
+ GNUNET_JSON_pack_array_steal ("history",
+ history));
+ http_status = MHD_HTTP_OK;
+ }
+ add_response_headers (NULL,
+ resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_ETAG,
+ etagp));
+ {
+ MHD_RESULT ret;
+
+ ret = MHD_queue_response (rc->connection,
+ http_status,
+ resp);
+ GNUNET_break (MHD_YES == ret);
+ MHD_destroy_response (resp);
+ return ret;
+ }
+}
+
+
+/* end of taler-exchange-httpd_coins_get.c */
diff --git a/src/exchange/taler-exchange-httpd_deposit.h b/src/exchange/taler-exchange-httpd_coins_get.h
index a4d598a69..90405b55d 100644
--- a/src/exchange/taler-exchange-httpd_deposit.h
+++ b/src/exchange/taler-exchange-httpd_coins_get.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014 Taler Systems SA
+ Copyright (C) 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,36 +14,40 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file taler-exchange-httpd_deposit.h
- * @brief Handle /deposit requests
+ * @file taler-exchange-httpd_coins_get.h
+ * @brief Handle GET /coins/$COIN_PUB requests
* @author Florian Dold
* @author Benedikt Mueller
* @author Christian Grothoff
*/
-#ifndef TALER_EXCHANGE_HTTPD_DEPOSIT_H
-#define TALER_EXCHANGE_HTTPD_DEPOSIT_H
+#ifndef TALER_EXCHANGE_HTTPD_COINS_GET_H
+#define TALER_EXCHANGE_HTTPD_COINS_GET_H
-#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
#include "taler-exchange-httpd.h"
/**
- * Handle a "/coins/$COIN_PUB/deposit" request. Parses the JSON, and, if
- * successful, passes the JSON data to #deposit_transaction() to
- * further check the details of the operation specified. If everything checks
- * out, this will ultimately lead to the "/deposit" being executed, or
- * rejected.
+ * Shutdown reserves-get subsystem. Resumes all
+ * suspended long-polling clients and cleans up
+ * data structures.
+ */
+void
+TEH_reserves_get_cleanup (void);
+
+
+/**
+ * Handle a GET "/coins/$COIN_PUB/history" request. Parses the
+ * given "coins_pub" in @a args (which should contain the
+ * EdDSA public key of a reserve) and then respond with the
+ * transaction history of the coin.
*
- * @param connection the MHD connection to handle
+ * @param rc request context
* @param coin_pub public key of the coin
- * @param root uploaded JSON data
* @return MHD result code
- */
+ */
MHD_RESULT
-TEH_handler_deposit (struct MHD_Connection *connection,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const json_t *root);
-
+TEH_handler_coins_get (struct TEH_RequestContext *rc,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_common_deposit.c b/src/exchange/taler-exchange-httpd_common_deposit.c
index 92e2469f2..898e23dd9 100644
--- a/src/exchange/taler-exchange-httpd_common_deposit.c
+++ b/src/exchange/taler-exchange-httpd_common_deposit.c
@@ -68,10 +68,6 @@ TEH_common_purse_deposit_parse_coin (
return res;
}
- if (! coin->cpi.no_age_commitment)
- TALER_age_commitment_hash (&coin->age_commitment,
- &coin->cpi.h_age_commitment);
-
/* check denomination exists and is valid */
{
struct TEH_DenominationKey *dk;
@@ -85,6 +81,12 @@ TEH_common_purse_deposit_parse_coin (
GNUNET_JSON_parse_free (spec);
return (MHD_YES == mret) ? GNUNET_NO : GNUNET_SYSERR;
}
+ if (! coin->cpi.no_age_commitment)
+ {
+ coin->age_commitment.mask = dk->meta.age_mask;
+ TALER_age_commitment_hash (&coin->age_commitment,
+ &coin->cpi.h_age_commitment);
+ }
if (0 > TALER_amount_cmp (&dk->meta.value,
&coin->amount))
{
@@ -133,7 +135,8 @@ TEH_common_purse_deposit_parse_coin (
"PURSE CREATE"))
? GNUNET_NO : GNUNET_SYSERR;
}
- if (dk->denom_pub.cipher != coin->cpi.denom_sig.cipher)
+ if (dk->denom_pub.bsign_pub_key->cipher !=
+ coin->cpi.denom_sig.unblinded_sig->cipher)
{
/* denomination cipher and denomination signature cipher not the same */
GNUNET_JSON_parse_free (spec);
@@ -162,12 +165,12 @@ TEH_common_purse_deposit_parse_coin (
&coin->deposit_fee));
/* check coin signature */
- switch (dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
break;
default:
@@ -218,6 +221,9 @@ TEH_common_deposit_check_purse_deposit (
: GNUNET_SYSERR;
}
+ if (0 == min_age)
+ return GNUNET_OK; /* no need to apply age checks */
+
/* Check and verify the age restriction. */
if (coin->no_attest != coin->cpi.no_age_commitment)
{
@@ -240,7 +246,6 @@ TEH_common_deposit_check_purse_deposit (
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
- /* FIXME: other error code? */
TALER_EC_EXCHANGE_PURSE_DEPOSIT_COIN_AGE_ATTESTATION_FAILURE,
"invalid attest for minimum age");
}
@@ -261,51 +266,3 @@ TEH_common_purse_deposit_free_coin (struct TEH_PurseDepositedCoin *coin)
if (! coin->cpi.no_age_commitment)
GNUNET_free (coin->age_commitment.keys); /* Only the keys have been allocated */
}
-
-
-#if LEGACY
-
-if (0 >
- TALER_amount_add (&pcc->deposit_total,
- &pcc->deposit_total,
- &coin->amount_minus_fee))
-{
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_FAILED_COMPUTE_AMOUNT,
- "total deposit contribution");
-}
-
-
-{
- MHD_RESULT mhd_ret = MHD_NO;
- enum GNUNET_DB_QueryStatus qs;
-
- /* make sure coin is 'known' in database */
- for (unsigned int tries = 0; tries<MAX_TRANSACTION_COMMIT_RETRIES; tries++)
- {
- qs = TEH_make_coin_known (&coin->cpi,
- connection,
- &coin->known_coin_id,
- &mhd_ret);
- /* no transaction => no serialization failures should be possible */
- if (GNUNET_DB_STATUS_SOFT_ERROR != qs)
- break;
- }
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- {
- GNUNET_break (0);
- return (MHD_YES ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_COMMIT_FAILED,
- "make_coin_known"))
- ? GNUNET_NO : GNUNET_SYSERR;
- }
- if (qs < 0)
- return (MHD_YES == mhd_ret) ? GNUNET_NO : GNUNET_SYSERR;
-}
-return GNUNET_OK;
-}
-#endif
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.c b/src/exchange/taler-exchange-httpd_common_kyc.c
new file mode 100644
index 000000000..bcee5a0d2
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_common_kyc.c
@@ -0,0 +1,302 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_common_kyc.c
+ * @brief shared logic for finishing a KYC process
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler-exchange-httpd.h"
+#include "taler-exchange-httpd_common_kyc.h"
+#include "taler_attributes.h"
+#include "taler_error_codes.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include <gnunet/gnunet_common.h>
+
+struct TEH_KycAmlTrigger
+{
+
+ /**
+ * Our logging scope.
+ */
+ struct GNUNET_AsyncScopeId scope;
+
+ /**
+ * account the operation is about
+ */
+ struct TALER_PaytoHashP account_id;
+
+ /**
+ * until when is the KYC data valid
+ */
+ struct GNUNET_TIME_Absolute expiration;
+
+ /**
+ * legitimization process the KYC data is about
+ */
+ uint64_t process_row;
+
+ /**
+ * name of the configuration section of the logic that was run
+ */
+ char *provider_section;
+
+ /**
+ * set to user ID at the provider, or NULL if not supported or unknown
+ */
+ char *provider_user_id;
+
+ /**
+ * provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ */
+ char *provider_legitimization_id;
+
+ /**
+ * function to call with the result
+ */
+ TEH_KycAmlTriggerCallback cb;
+
+ /**
+ * closure for @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * user attributes returned by the provider
+ */
+ json_t *attributes;
+
+ /**
+ * response to return to the HTTP client
+ */
+ struct MHD_Response *response;
+
+ /**
+ * Handle to an external process that evaluates the
+ * need to run AML on the account.
+ */
+ struct TALER_JSON_ExternalConversion *kyc_aml;
+
+ /**
+ * HTTP status code of @e response
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure of type `struct TEH_KycAmlTrigger *`
+ * @param status_type how did the process die
+ * @param code termination status code from the process,
+ * non-zero if AML checks are required next
+ * @param result some JSON result, NULL if we failed to get an JSON output
+ */
+static void
+kyc_aml_finished (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *result)
+{
+ struct TEH_KycAmlTrigger *kat = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ size_t eas;
+ void *ea;
+ const char *birthdate;
+ unsigned int birthday = 0;
+ struct GNUNET_ShortHashCode kyc_prox;
+ struct GNUNET_AsyncScopeSave old_scope;
+ unsigned int num_checks;
+ char **provided_checks;
+
+ kat->kyc_aml = NULL;
+ GNUNET_async_scope_enter (&kat->scope,
+ &old_scope);
+ TALER_CRYPTO_attributes_to_kyc_prox (kat->attributes,
+ &kyc_prox);
+ birthdate = json_string_value (json_object_get (kat->attributes,
+ TALER_ATTRIBUTE_BIRTHDATE));
+ if ( (TEH_age_restriction_enabled) &&
+ (NULL != birthdate) )
+ {
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = TALER_parse_coarse_date (birthdate,
+ &TEH_age_restriction_config.mask,
+ &birthday);
+
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to parse birthdate `%s' from KYC attributes\n",
+ birthdate);
+ if (NULL != kat->response)
+ MHD_destroy_response (kat->response);
+ kat->http_status = MHD_HTTP_BAD_REQUEST;
+ kat->response = TALER_MHD_make_error (
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ TALER_ATTRIBUTE_BIRTHDATE);
+ goto RETURN_RESULT;
+ }
+ }
+
+ TALER_CRYPTO_kyc_attributes_encrypt (&TEH_attribute_key,
+ kat->attributes,
+ &ea,
+ &eas);
+ TALER_KYCLOGIC_lookup_checks (kat->provider_section,
+ &num_checks,
+ &provided_checks);
+ qs = TEH_plugin->insert_kyc_attributes (
+ TEH_plugin->cls,
+ kat->process_row,
+ &kat->account_id,
+ &kyc_prox,
+ kat->provider_section,
+ num_checks,
+ (const char **) provided_checks,
+ birthday,
+ GNUNET_TIME_timestamp_get (),
+ kat->provider_user_id,
+ kat->provider_legitimization_id,
+ kat->expiration,
+ eas,
+ ea,
+ 0 != code);
+ for (unsigned int i = 0; i<num_checks; i++)
+ GNUNET_free (provided_checks[i]);
+ GNUNET_free (provided_checks);
+ GNUNET_free (ea);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Stored encrypted KYC process #%llu attributes: %d\n",
+ (unsigned long long) kat->process_row,
+ qs);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ if (NULL != kat->response)
+ MHD_destroy_response (kat->response);
+ kat->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ kat->response = TALER_MHD_make_error (TALER_EC_GENERIC_DB_STORE_FAILED,
+ "do_insert_kyc_attributes");
+ /* Continued below to return the response */
+ }
+RETURN_RESULT:
+ /* Finally, return result to main handler */
+ kat->cb (kat->cb_cls,
+ kat->http_status,
+ kat->response);
+ kat->response = NULL;
+ TEH_kyc_finished_cancel (kat);
+ GNUNET_async_scope_restore (&old_scope);
+}
+
+
+struct TEH_KycAmlTrigger *
+TEH_kyc_finished (const struct GNUNET_AsyncScopeId *scope,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response,
+ TEH_KycAmlTriggerCallback cb,
+ void *cb_cls)
+{
+ struct TEH_KycAmlTrigger *kat;
+
+ kat = GNUNET_new (struct TEH_KycAmlTrigger);
+ kat->scope = *scope;
+ kat->process_row = process_row;
+ kat->account_id = *account_id;
+ kat->provider_section
+ = GNUNET_strdup (provider_section);
+ if (NULL != provider_user_id)
+ kat->provider_user_id
+ = GNUNET_strdup (provider_user_id);
+ if (NULL != provider_legitimization_id)
+ kat->provider_legitimization_id
+ = GNUNET_strdup (provider_legitimization_id);
+ kat->expiration = expiration;
+ kat->attributes = json_incref ((json_t*) attributes);
+ kat->http_status = http_status;
+ kat->response = response;
+ kat->cb = cb;
+ kat->cb_cls = cb_cls;
+ kat->kyc_aml
+ = TALER_JSON_external_conversion_start (
+ attributes,
+ &kyc_aml_finished,
+ kat,
+ TEH_kyc_aml_trigger,
+ TEH_kyc_aml_trigger,
+ NULL);
+ if (NULL == kat->kyc_aml)
+ {
+ GNUNET_break (0);
+ TEH_kyc_finished_cancel (kat);
+ return NULL;
+ }
+ return kat;
+}
+
+
+void
+TEH_kyc_finished_cancel (struct TEH_KycAmlTrigger *kat)
+{
+ if (NULL != kat->kyc_aml)
+ {
+ TALER_JSON_external_conversion_stop (kat->kyc_aml);
+ kat->kyc_aml = NULL;
+ }
+ GNUNET_free (kat->provider_section);
+ GNUNET_free (kat->provider_user_id);
+ GNUNET_free (kat->provider_legitimization_id);
+ json_decref (kat->attributes);
+ if (NULL != kat->response)
+ {
+ MHD_destroy_response (kat->response);
+ kat->response = NULL;
+ }
+ GNUNET_free (kat);
+}
+
+
+bool
+TEH_kyc_failed (uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id)
+{
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->insert_kyc_failure (
+ TEH_plugin->cls,
+ process_row,
+ account_id,
+ provider_section,
+ provider_user_id,
+ provider_legitimization_id);
+ GNUNET_break (qs >= 0);
+ return qs >= 0;
+}
diff --git a/src/exchange/taler-exchange-httpd_common_kyc.h b/src/exchange/taler-exchange-httpd_common_kyc.h
new file mode 100644
index 000000000..8198679c9
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_common_kyc.h
@@ -0,0 +1,117 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_common_kyc.h
+ * @brief shared logic for finishing a KYC process
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_COMMON_KYC_H
+#define TALER_EXCHANGE_HTTPD_COMMON_KYC_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Function called after the KYC-AML trigger is done.
+ *
+ * @param cls closure
+ * @param http_status final HTTP status to return
+ * @param[in] response final HTTP ro return
+ */
+typedef void
+(*TEH_KycAmlTriggerCallback) (
+ void *cls,
+ unsigned int http_status,
+ struct MHD_Response *response);
+
+
+/**
+ * Handle for an asynchronous operation to finish
+ * a KYC process after running the AML trigger.
+ */
+struct TEH_KycAmlTrigger;
+
+// FIXME: also pass async log context and set it!
+/**
+ * We have finished a KYC process and obtained new
+ * @a attributes for a given @a account_id.
+ * Check with the KYC-AML trigger to see if we need
+ * to initiate an AML process, and store the attributes
+ * in the database. Then call @a cb.
+ *
+ * @param scope the HTTP request logging scope
+ * @param process_row legitimization process the webhook was about
+ * @param account_id account the webhook was about
+ * @param provider_section name of the configuration section of the logic that was run
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param expiration until when is the KYC check valid
+ * @param attributes user attributes returned by the provider
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel the operation
+ */
+struct TEH_KycAmlTrigger *
+TEH_kyc_finished (const struct GNUNET_AsyncScopeId *scope,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response,
+ TEH_KycAmlTriggerCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel KYC finish operation.
+ *
+ * @param[in] kat operation to abort
+ */
+void
+TEH_kyc_finished_cancel (struct TEH_KycAmlTrigger *kat);
+
+
+/**
+ * Update state of a legitmization process to 'finished'
+ * (and failed, no attributes were obtained).
+ *
+ * @param process_row legitimization process the webhook was about
+ * @param account_id account the webhook was about
+ * @param provider_section name of the configuration section of the logic that was run
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @return true on success, false if updating the database failed
+ */
+bool
+TEH_kyc_failed (uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_config.c b/src/exchange/taler-exchange-httpd_config.c
new file mode 100644
index 000000000..e17a9a050
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_config.c
@@ -0,0 +1,84 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2015-2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_config.c
+ * @brief Handle /config requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_json_lib.h>
+#include "taler_dbevents.h"
+#include "taler-exchange-httpd_config.h"
+#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_mhd_lib.h"
+#include <jansson.h>
+
+
+MHD_RESULT
+TEH_handler_config (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ static struct MHD_Response *resp;
+
+ if (NULL == resp)
+ {
+ struct GNUNET_TIME_Absolute a;
+ struct GNUNET_TIME_Timestamp km;
+ char dat[128];
+
+ a = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_DAYS);
+ /* Round up to next full day to ensure the expiration
+ time does not become a fingerprint! */
+ a = GNUNET_TIME_absolute_round_down (a,
+ GNUNET_TIME_UNIT_DAYS);
+ a = GNUNET_TIME_absolute_add (a,
+ GNUNET_TIME_UNIT_DAYS);
+ /* => /config response stays at most 48h in caches! */
+ km = GNUNET_TIME_absolute_to_timestamp (a);
+ TALER_MHD_get_date_string (km.abs_time,
+ dat);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("supported_kyc_requirements",
+ TALER_KYCLOGIC_get_satisfiable ()),
+ GNUNET_JSON_pack_object_steal (
+ "currency_specification",
+ TALER_CONFIG_currency_specs_to_json (TEH_cspec)),
+ GNUNET_JSON_pack_string ("currency",
+ TEH_currency),
+ GNUNET_JSON_pack_string ("name",
+ "taler-exchange"),
+ GNUNET_JSON_pack_string ("implementation",
+ "urn:net:taler:specs:taler-exchange:c-reference"),
+ GNUNET_JSON_pack_string ("version",
+ EXCHANGE_PROTOCOL_VERSION));
+
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_EXPIRES,
+ dat));
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_CACHE_CONTROL,
+ "public,max-age=21600")); /* 6h */
+ }
+ return MHD_queue_response (rc->connection,
+ MHD_HTTP_OK,
+ resp);
+}
+
+
+/* end of taler-exchange-httpd_config.c */
diff --git a/src/exchange/taler-exchange-httpd_config.h b/src/exchange/taler-exchange-httpd_config.h
new file mode 100644
index 000000000..c0a14104a
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_config.h
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of EXCHANGEABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_config.h
+ * @brief headers for /config handler
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_CONFIG_H
+#define TALER_EXCHANGE_HTTPD_CONFIG_H
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Taler protocol version in the format CURRENT:REVISION:AGE
+ * as used by GNU libtool. See
+ * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
+ *
+ * Please be very careful when updating and follow
+ * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
+ * precisely. Note that this version has NOTHING to do with the
+ * release version, and the format is NOT the same that semantic
+ * versioning uses either.
+ *
+ * When changing this version, you likely want to also update
+ * #TALER_PROTOCOL_CURRENT and #TALER_PROTOCOL_AGE in
+ * exchange_api_handle.c!
+ *
+ * Returned via both /config and /keys endpoints.
+ */
+#define EXCHANGE_PROTOCOL_VERSION "19:1:2"
+
+
+/**
+ * Manages a /config call.
+ *
+ * @param rc context of the handler
+ * @param[in,out] args remaining arguments (ignored)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_config (struct TEH_RequestContext *rc,
+ const char *const args[]);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_csr.c b/src/exchange/taler-exchange-httpd_csr.c
index 1abe55639..e4fa4f5e4 100644
--- a/src/exchange/taler-exchange-httpd_csr.c
+++ b/src/exchange/taler-exchange-httpd_csr.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
@@ -21,6 +21,7 @@
* @brief Handle /csr requests
* @author Lucien Heuzeveldt
* @author Gian Demarmles
+ * @author Christian Grothoff
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
@@ -39,12 +40,12 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
{
struct TALER_RefreshMasterSecretP rms;
unsigned int csr_requests_num;
- json_t *csr_requests;
+ const json_t *csr_requests;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("rms",
&rms),
- GNUNET_JSON_spec_json ("nks",
- &csr_requests),
+ GNUNET_JSON_spec_array_const ("nks",
+ &csr_requests),
GNUNET_JSON_spec_end ()
};
enum TALER_ErrorCode ec;
@@ -65,7 +66,7 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
if ( (TALER_MAX_FRESH_COINS <= csr_requests_num) ||
(0 == csr_requests_num) )
{
- GNUNET_JSON_parse_free (spec);
+ GNUNET_break_op (0);
return TALER_MHD_reply_with_error (
rc->connection,
MHD_HTTP_BAD_REQUEST,
@@ -74,11 +75,12 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
}
{
- struct TALER_ExchangeWithdrawValues ewvs[csr_requests_num];
-
+ struct GNUNET_CRYPTO_BlindingInputValues ewvs[csr_requests_num];
{
- struct TALER_CsNonce nonces[csr_requests_num];
+ struct GNUNET_CRYPTO_CsSessionNonce nonces[csr_requests_num];
struct TALER_DenominationHashP denom_pub_hashes[csr_requests_num];
+ struct TEH_CsDeriveData cdds[csr_requests_num];
+ struct GNUNET_CRYPTO_CSPublicRPairP r_pubs[csr_requests_num];
for (unsigned int i = 0; i < csr_requests_num; i++)
{
@@ -100,24 +102,20 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
-1);
if (GNUNET_OK != res)
{
- GNUNET_JSON_parse_free (spec);
return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
TALER_cs_refresh_nonce_derive (&rms,
coin_off,
&nonces[i]);
}
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i < csr_requests_num; i++)
{
- const struct TALER_CsNonce *nonce = &nonces[i];
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce = &nonces[i];
const struct TALER_DenominationHashP *denom_pub_hash =
&denom_pub_hashes[i];
- struct TALER_DenominationCSPublicRPairP *r_pub
- = &ewvs[i].details.cs_values;
- ewvs[i].cipher = TALER_DENOMINATION_CS;
+ ewvs[i].cipher = GNUNET_CRYPTO_BSA_CS;
/* check denomination referenced by denom_pub_hash */
{
struct TEH_KeyStateHandle *ksh;
@@ -130,10 +128,10 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
NULL);
}
- dk = TEH_keys_denomination_by_hash2 (ksh,
- denom_pub_hash,
- NULL,
- NULL);
+ dk = TEH_keys_denomination_by_hash_from_state (ksh,
+ denom_pub_hash,
+ NULL,
+ NULL);
if (NULL == dk)
{
return TEH_RESPONSE_reply_unknown_denom_pub_hash (
@@ -168,7 +166,8 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
"csr-melt");
}
- if (TALER_DENOMINATION_CS != dk->denom_pub.cipher)
+ if (GNUNET_CRYPTO_BSA_CS !=
+ dk->denom_pub.bsign_pub_key->cipher)
{
/* denomination is valid but not for CS */
return TEH_RESPONSE_reply_invalid_denom_cipher_for_operation (
@@ -176,21 +175,23 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
denom_pub_hash);
}
}
-
- /* derive r_pub */
- // FIXME: bundle all requests into one derivation request (TEH_keys_..., crypto helper, security module)
- ec = TEH_keys_denomination_cs_r_pub_melt (denom_pub_hash,
- nonce,
- r_pub);
- if (TALER_EC_NONE != ec)
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_ec (rc->connection,
- ec,
- NULL);
- }
+ cdds[i].h_denom_pub = denom_pub_hash;
+ cdds[i].nonce = nonce;
+ } /* for (i) */
+ ec = TEH_keys_denomination_cs_batch_r_pub (csr_requests_num,
+ cdds,
+ true,
+ r_pubs);
+ if (TALER_EC_NONE != ec)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_ec (rc->connection,
+ ec,
+ NULL);
}
- }
+ for (unsigned int i = 0; i < csr_requests_num; i++)
+ ewvs[i].details.cs_values = r_pubs[i];
+ } /* end scope */
/* send response */
{
@@ -201,10 +202,13 @@ TEH_handler_csr_melt (struct TEH_RequestContext *rc,
for (unsigned int i = 0; i < csr_requests_num; i++)
{
json_t *csr_obj;
+ struct TALER_ExchangeWithdrawValues exw = {
+ .blinding_inputs = &ewvs[i]
+ };
csr_obj = GNUNET_JSON_PACK (
TALER_JSON_pack_exchange_withdraw_values ("ewv",
- &ewvs[i]));
+ &exw));
GNUNET_assert (NULL != csr_obj);
GNUNET_assert (0 ==
json_array_append_new (csr_response_ewvs,
@@ -227,18 +231,16 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc,
const json_t *root,
const char *const args[])
{
- struct TALER_CsNonce nonce;
+ struct GNUNET_CRYPTO_CsSessionNonce nonce;
struct TALER_DenominationHashP denom_pub_hash;
- struct TALER_ExchangeWithdrawValues ewv = {
- .cipher = TALER_DENOMINATION_CS
+ struct GNUNET_CRYPTO_BlindingInputValues ewv = {
+ .cipher = GNUNET_CRYPTO_BSA_CS
};
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed ("nonce",
- &nonce,
- sizeof (struct TALER_CsNonce)),
- GNUNET_JSON_spec_fixed ("denom_pub_hash",
- &denom_pub_hash,
- sizeof (struct TALER_DenominationHashP)),
+ GNUNET_JSON_spec_fixed_auto ("nonce",
+ &nonce),
+ GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
+ &denom_pub_hash),
GNUNET_JSON_spec_end ()
};
struct TEH_DenominationKey *dk;
@@ -265,10 +267,10 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
NULL);
}
- dk = TEH_keys_denomination_by_hash2 (ksh,
- &denom_pub_hash,
- NULL,
- NULL);
+ dk = TEH_keys_denomination_by_hash_from_state (ksh,
+ &denom_pub_hash,
+ NULL,
+ NULL);
if (NULL == dk)
{
return TEH_RESPONSE_reply_unknown_denom_pub_hash (
@@ -303,7 +305,8 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc,
TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
"csr-withdraw");
}
- if (TALER_DENOMINATION_CS != dk->denom_pub.cipher)
+ if (GNUNET_CRYPTO_BSA_CS !=
+ dk->denom_pub.bsign_pub_key->cipher)
{
/* denomination is valid but not for CS */
return TEH_RESPONSE_reply_invalid_denom_cipher_for_operation (
@@ -315,10 +318,14 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc,
/* derive r_pub */
{
enum TALER_ErrorCode ec;
+ const struct TEH_CsDeriveData cdd = {
+ .h_denom_pub = &denom_pub_hash,
+ .nonce = &nonce
+ };
- ec = TEH_keys_denomination_cs_r_pub_withdraw (&denom_pub_hash,
- &nonce,
- &ewv.details.cs_values);
+ ec = TEH_keys_denomination_cs_r_pub (&cdd,
+ false,
+ &ewv.details.cs_values);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
@@ -327,17 +334,16 @@ TEH_handler_csr_withdraw (struct TEH_RequestContext *rc,
NULL);
}
}
-
{
- json_t *csr_obj;
+ struct TALER_ExchangeWithdrawValues exw = {
+ .blinding_inputs = &ewv
+ };
- csr_obj = GNUNET_JSON_PACK (
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
TALER_JSON_pack_exchange_withdraw_values ("ewv",
- &ewv));
- GNUNET_assert (NULL != csr_obj);
- return TALER_MHD_reply_json_steal (rc->connection,
- csr_obj,
- MHD_HTTP_OK);
+ &exw));
}
}
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c
index 6f0fc41c9..6fec3fee4 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -19,9 +19,12 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include <gnunet/gnunet_db_lib.h>
#include <pthread.h>
#include <jansson.h>
#include <gnunet/gnunet_json_lib.h>
+#include "taler_error_codes.h"
+#include "taler_exchangedb_plugin.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler_exchangedb_lib.h"
@@ -37,14 +40,14 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
{
enum TALER_EXCHANGEDB_CoinKnownStatus cks;
struct TALER_DenominationHashP h_denom_pub;
- struct TALER_AgeCommitmentHash age_hash;
+ struct TALER_AgeCommitmentHash h_age_commitment = {{{0}}};
/* make sure coin is 'known' in database */
cks = TEH_plugin->ensure_coin_known (TEH_plugin->cls,
coin,
known_coin_id,
&h_denom_pub,
- &age_hash);
+ &h_age_commitment);
switch (cks)
{
case TALER_EXCHANGEDB_CKS_ADDED:
@@ -61,22 +64,50 @@ TEH_make_coin_known (const struct TALER_CoinPublicInfo *coin,
NULL);
return GNUNET_DB_STATUS_HARD_ERROR;
case TALER_EXCHANGEDB_CKS_DENOM_CONFLICT:
- /* FIXME: insufficient_funds != denom conflict! See issue 0007267, need new
- * strategy for evidence gathering */
- *mhd_ret = TEH_RESPONSE_reply_coin_insufficient_funds (
- connection,
- TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY,
- &h_denom_pub,
- &coin->coin_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- case TALER_EXCHANGEDB_CKS_AGE_CONFLICT:
- /* FIXME: insufficient_funds != Age conflict! See issue 0007267, need new
- * strategy for evidence gathering */
- *mhd_ret = TEH_RESPONSE_reply_coin_insufficient_funds (
+ /* The exchange has a seen this coin before, but with a different denomination.
+ * Get the corresponding signature and sent it to the client as proof */
+ {
+ struct
+ {
+ struct TALER_DenominationPublicKey pub;
+ struct TALER_DenominationSignature sig;
+ } prev_denom = {0};
+
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ TEH_plugin->get_signature_for_known_coin (TEH_plugin->cls,
+ &coin->coin_pub,
+ &prev_denom.pub,
+ &prev_denom.sig))
+ {
+ /* There _should_ have been a result, because
+ * we ended here due to a conflict! */
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ *mhd_ret = TEH_RESPONSE_reply_coin_denomination_conflict (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY,
+ &coin->coin_pub,
+ &prev_denom.pub,
+ &prev_denom.sig);
+
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL:
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL:
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS:
+ *mhd_ret = TEH_RESPONSE_reply_coin_age_commitment_conflict (
connection,
TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_AGE_HASH,
+ cks,
&h_denom_pub,
- &coin->coin_pub);
+ &coin->coin_pub,
+ &h_age_commitment);
return GNUNET_DB_STATUS_HARD_ERROR;
}
GNUNET_assert (0);
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
deleted file mode 100644
index 672e7b6ea..000000000
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ /dev/null
@@ -1,497 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_deposit.c
- * @brief Handle /deposit requests; parses the POST and JSON and
- * verifies the coin signature before handing things off
- * to the database.
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <jansson.h>
-#include <microhttpd.h>
-#include <pthread.h>
-#include "taler_json_lib.h"
-#include "taler_mhd_lib.h"
-#include "taler-exchange-httpd_deposit.h"
-#include "taler-exchange-httpd_responses.h"
-#include "taler_exchangedb_lib.h"
-#include "taler-exchange-httpd_keys.h"
-
-
-/**
- * Send confirmation of deposit success to client. This function
- * will create a signed message affirming the given information
- * and return it to the client. By this, the exchange affirms that
- * the coin had sufficient (residual) value for the specified
- * transaction and that it will execute the requested deposit
- * operation with the given wiring details.
- *
- * @param connection connection to the client
- * @param coin_pub public key of the coin
- * @param h_wire hash of wire details
- * @param h_extensions hash of applicable extensions
- * @param h_contract_terms hash of contract details
- * @param exchange_timestamp exchange's timestamp
- * @param refund_deadline until when this deposit be refunded
- * @param wire_deadline until when will the exchange wire the funds
- * @param merchant merchant public key
- * @param amount_without_fee fraction of coin value to deposit, without the fee
- * @return MHD result code
- */
-static MHD_RESULT
-reply_deposit_success (
- struct MHD_Connection *connection,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- struct GNUNET_TIME_Timestamp refund_deadline,
- struct GNUNET_TIME_Timestamp wire_deadline,
- const struct TALER_MerchantPublicKeyP *merchant,
- const struct TALER_Amount *amount_without_fee)
-{
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
- enum TALER_ErrorCode ec;
-
- if (TALER_EC_NONE !=
- (ec = TALER_exchange_online_deposit_confirmation_sign (
- &TEH_keys_exchange_sign_,
- h_contract_terms,
- h_wire,
- h_extensions,
- exchange_timestamp,
- wire_deadline,
- refund_deadline,
- amount_without_fee,
- coin_pub,
- merchant,
- &pub,
- &sig)))
- {
- return TALER_MHD_reply_with_ec (connection,
- ec,
- NULL);
- }
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_timestamp ("exchange_timestamp",
- exchange_timestamp),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &sig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &pub));
-}
-
-
-/**
- * Closure for #deposit_transaction.
- */
-struct DepositContext
-{
- /**
- * Information about the deposit request.
- */
- const struct TALER_EXCHANGEDB_Deposit *deposit;
-
- /**
- * Our timestamp (when we received the request).
- * Possibly updated by the transaction if the
- * request is idempotent (was repeated).
- */
- struct GNUNET_TIME_Timestamp exchange_timestamp;
-
- /**
- * Hash of the payto URI.
- */
- struct TALER_PaytoHashP h_payto;
-
- /**
- * Row of of the coin in the known_coins table.
- */
- uint64_t known_coin_id;
-
-};
-
-
-/**
- * Execute database transaction for /deposit. Runs the transaction
- * logic; IF it returns a non-error code, the transaction logic MUST
- * NOT queue a MHD response. IF it returns an hard error, the
- * transaction logic MUST queue a MHD response and set @a mhd_ret. IF
- * it returns the soft error code, the function MAY be called again to
- * retry and MUST not queue a MHD response.
- *
- * @param cls a `struct DepositContext`
- * @param connection MHD request context
- * @param[out] mhd_ret set to MHD status on error
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-deposit_transaction (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
-{
- struct DepositContext *dc = cls;
- enum GNUNET_DB_QueryStatus qs;
- bool balance_ok;
- bool in_conflict;
-
- qs = TEH_make_coin_known (&dc->deposit->coin,
- connection,
- &dc->known_coin_id,
- mhd_ret);
- if (qs < 0)
- return qs;
- qs = TEH_plugin->do_deposit (TEH_plugin->cls,
- dc->deposit,
- dc->known_coin_id,
- &dc->h_payto,
- false, /* FIXME-OEC: extension blocked */
- &dc->exchange_timestamp,
- &balance_ok,
- &in_conflict);
- if (qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- TALER_LOG_WARNING ("Failed to store /deposit information in database\n");
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "deposit");
- return qs;
- }
- if (in_conflict)
- {
- /* FIXME: conficting contract != insufficient funds */
- *mhd_ret
- = TEH_RESPONSE_reply_coin_insufficient_funds (
- connection,
- TALER_EC_EXCHANGE_DEPOSIT_CONFLICTING_CONTRACT,
- &dc->deposit->coin.denom_pub_hash,
- &dc->deposit->coin.coin_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (! balance_ok)
- {
- *mhd_ret
- = TEH_RESPONSE_reply_coin_insufficient_funds (
- connection,
- TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS,
- &dc->deposit->coin.denom_pub_hash,
- &dc->deposit->coin.coin_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- TEH_METRICS_num_success[TEH_MT_SUCCESS_DEPOSIT]++;
- return qs;
-}
-
-
-MHD_RESULT
-TEH_handler_deposit (struct MHD_Connection *connection,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const json_t *root)
-{
- struct DepositContext dc;
- struct TALER_EXCHANGEDB_Deposit deposit;
- const char *payto_uri;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("merchant_payto_uri",
- &payto_uri),
- GNUNET_JSON_spec_fixed_auto ("wire_salt",
- &deposit.wire_salt),
- TALER_JSON_spec_amount ("contribution",
- TEH_currency,
- &deposit.amount_with_fee),
- GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
- &deposit.coin.denom_pub_hash),
- TALER_JSON_spec_denom_sig ("ub_sig",
- &deposit.coin.denom_sig),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &deposit.merchant_pub),
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &deposit.h_contract_terms),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &deposit.coin.h_age_commitment),
- &deposit.coin.no_age_commitment),
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &deposit.csig),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &deposit.timestamp),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_timestamp ("refund_deadline",
- &deposit.refund_deadline),
- NULL),
- GNUNET_JSON_spec_timestamp ("wire_transfer_deadline",
- &deposit.wire_deadline),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_MerchantWireHashP h_wire;
-
- memset (&deposit,
- 0,
- sizeof (deposit));
- deposit.coin.coin_pub = *coin_pub;
- {
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (connection,
- root,
- spec);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- return MHD_NO; /* hard failure */
- }
- if (GNUNET_NO == res)
- {
- GNUNET_break_op (0);
- return MHD_YES; /* failure */
- }
- }
- /* validate merchant's wire details (as far as we can) */
- {
- char *emsg;
-
- emsg = TALER_payto_validate (payto_uri);
- if (NULL != emsg)
- {
- MHD_RESULT ret;
-
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- emsg);
- GNUNET_free (emsg);
- return ret;
- }
- }
- if (GNUNET_TIME_timestamp_cmp (deposit.refund_deadline,
- >,
- deposit.wire_deadline))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE,
- NULL);
- }
- if (GNUNET_TIME_absolute_is_never (deposit.wire_deadline.abs_time))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSIT_WIRE_DEADLINE_IS_NEVER,
- NULL);
- }
- deposit.receiver_wire_account = (char *) payto_uri;
- TALER_payto_hash (payto_uri,
- &dc.h_payto);
- TALER_merchant_wire_signature_hash (payto_uri,
- &deposit.wire_salt,
- &h_wire);
- dc.deposit = &deposit;
-
- /* new deposit */
- dc.exchange_timestamp = GNUNET_TIME_timestamp_get ();
- /* check denomination exists and is valid */
- {
- struct TEH_DenominationKey *dk;
- MHD_RESULT mret;
-
- dk = TEH_keys_denomination_by_hash (&deposit.coin.denom_pub_hash,
- connection,
- &mret);
- if (NULL == dk)
- {
- GNUNET_JSON_parse_free (spec);
- return mret;
- }
- if (0 > TALER_amount_cmp (&dk->meta.value,
- &deposit.amount_with_fee))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_AMOUNT_EXCEEDS_DENOMINATION_VALUE,
- NULL);
- }
- if (GNUNET_TIME_absolute_is_past (dk->meta.expire_deposit.abs_time))
- {
- /* This denomination is past the expiration time for deposits */
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- connection,
- &deposit.coin.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED,
- "DEPOSIT");
- }
- if (GNUNET_TIME_absolute_is_future (dk->meta.start.abs_time))
- {
- /* This denomination is not yet valid */
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- connection,
- &deposit.coin.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE,
- "DEPOSIT");
- }
- if (dk->recoup_possible)
- {
- /* This denomination has been revoked */
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- connection,
- &deposit.coin.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
- "DEPOSIT");
- }
- if (dk->denom_pub.cipher != deposit.coin.denom_sig.cipher)
- {
- /* denomination cipher and denomination signature cipher not the same */
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_CIPHER_MISMATCH,
- NULL);
- }
-
- deposit.deposit_fee = dk->meta.fees.deposit;
- /* check coin signature */
- switch (dk->denom_pub.cipher)
- {
- case TALER_DENOMINATION_RSA:
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
- break;
- case TALER_DENOMINATION_CS:
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
- break;
- default:
- break;
- }
- if (GNUNET_YES !=
- TALER_test_coin_valid (&deposit.coin,
- &dk->denom_pub))
- {
- TALER_LOG_WARNING ("Invalid coin passed for /deposit\n");
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_DENOMINATION_SIGNATURE_INVALID,
- NULL);
- }
- }
- if (0 < TALER_amount_cmp (&deposit.deposit_fee,
- &deposit.amount_with_fee))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSIT_NEGATIVE_VALUE_AFTER_FEE,
- NULL);
- }
-
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_wallet_deposit_verify (&deposit.amount_with_fee,
- &deposit.deposit_fee,
- &h_wire,
- &deposit.h_contract_terms,
- &deposit.coin.h_age_commitment,
- NULL /* h_extensions! */,
- &deposit.coin.denom_pub_hash,
- deposit.timestamp,
- &deposit.merchant_pub,
- deposit.refund_deadline,
- &deposit.coin.coin_pub,
- &deposit.csig))
- {
- TALER_LOG_WARNING ("Invalid signature on /deposit request\n");
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID,
- NULL);
- }
-
- if (GNUNET_SYSERR ==
- TEH_plugin->preflight (TEH_plugin->cls))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_START_FAILED,
- "preflight failure");
- }
-
- /* execute transaction */
- {
- MHD_RESULT mhd_ret;
-
- if (GNUNET_OK !=
- TEH_DB_run_transaction (connection,
- "execute deposit",
- TEH_MT_REQUEST_DEPOSIT,
- &mhd_ret,
- &deposit_transaction,
- &dc))
- {
- GNUNET_JSON_parse_free (spec);
- return mhd_ret;
- }
- }
-
- /* generate regular response */
- {
- struct TALER_Amount amount_without_fee;
- MHD_RESULT res;
-
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &deposit.amount_with_fee,
- &deposit.deposit_fee));
- res = reply_deposit_success (connection,
- &deposit.coin.coin_pub,
- &h_wire,
- NULL /* h_extensions! */,
- &deposit.h_contract_terms,
- dc.exchange_timestamp,
- deposit.refund_deadline,
- deposit.wire_deadline,
- &deposit.merchant_pub,
- &amount_without_fee);
- GNUNET_JSON_parse_free (spec);
- return res;
- }
-}
-
-
-/* end of taler-exchange-httpd_deposit.c */
diff --git a/src/exchange/taler-exchange-httpd_deposits_get.c b/src/exchange/taler-exchange-httpd_deposits_get.c
index 97618a944..0850d19eb 100644
--- a/src/exchange/taler-exchange-httpd_deposits_get.c
+++ b/src/exchange/taler-exchange-httpd_deposits_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2017, 2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -23,6 +23,7 @@
#include <jansson.h>
#include <microhttpd.h>
#include <pthread.h>
+#include "taler_dbevents.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler_signatures.h"
@@ -38,14 +39,34 @@ struct DepositWtidContext
{
/**
+ * Kept in a DLL.
+ */
+ struct DepositWtidContext *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct DepositWtidContext *prev;
+
+ /**
+ * Context for the request we are processing.
+ */
+ struct TEH_RequestContext *rc;
+
+ /**
+ * Subscription for the database event we are waiting for.
+ */
+ struct GNUNET_DB_EventHandler *eh;
+
+ /**
* Hash over the proposal data of the contract for which this deposit is made.
*/
- struct TALER_PrivateContractHashP h_contract_terms GNUNET_PACKED;
+ struct TALER_PrivateContractHashP h_contract_terms;
/**
* Hash over the wiring information of the merchant.
*/
- struct TALER_MerchantWireHashP h_wire GNUNET_PACKED;
+ struct TALER_MerchantWireHashP h_wire;
/**
* The Merchant's public key. The deposit inquiry request is to be
@@ -65,6 +86,12 @@ struct DepositWtidContext
struct TALER_WireTransferIdentifierRawP wtid;
/**
+ * Signature by the merchant.
+ */
+ struct TALER_MerchantSignatureP merchant_sig;
+
+
+ /**
* Set by #handle_wtid data to the coin's contribution to the wire transfer.
*/
struct TALER_Amount coin_contribution;
@@ -80,6 +107,11 @@ struct DepositWtidContext
struct GNUNET_TIME_Timestamp execution_time;
/**
+ * Timeout of the request, for long-polling.
+ */
+ struct GNUNET_TIME_Absolute timeout;
+
+ /**
* Set by #handle_wtid to the coin contribution to the transaction
* (that is, @e coin_contribution minus @e coin_fee).
*/
@@ -91,15 +123,57 @@ struct DepositWtidContext
struct TALER_EXCHANGEDB_KycStatus kyc;
/**
+ * AML status information for the receiving account.
+ */
+ enum TALER_AmlDecisionState aml_decision;
+
+ /**
* Set to #GNUNET_YES by #handle_wtid if the wire transfer is still pending
* (and the above were not set).
* Set to #GNUNET_SYSERR if there was a serious error.
*/
enum GNUNET_GenericReturnValue pending;
+
+ /**
+ * #GNUNET_YES if we were suspended, #GNUNET_SYSERR
+ * if we were woken up due to shutdown.
+ */
+ enum GNUNET_GenericReturnValue suspended;
};
/**
+ * Head of DLL of suspended requests.
+ */
+static struct DepositWtidContext *dwc_head;
+
+/**
+ * Tail of DLL of suspended requests.
+ */
+static struct DepositWtidContext *dwc_tail;
+
+
+void
+TEH_deposits_get_cleanup ()
+{
+ struct DepositWtidContext *n;
+
+ for (struct DepositWtidContext *ctx = dwc_head;
+ NULL != ctx;
+ ctx = n)
+ {
+ n = ctx->next;
+ GNUNET_assert (GNUNET_YES == ctx->suspended);
+ ctx->suspended = GNUNET_SYSERR;
+ MHD_resume_connection (ctx->rc->connection);
+ GNUNET_CONTAINER_DLL_remove (dwc_head,
+ dwc_tail,
+ ctx);
+ }
+}
+
+
+/**
* A merchant asked for details about a deposit. Provide
* them. Generates the 200 reply.
*
@@ -128,6 +202,7 @@ reply_deposit_details (
&pub,
&sig)))
{
+ GNUNET_break (0);
return TALER_MHD_reply_with_ec (connection,
ec,
NULL);
@@ -184,7 +259,8 @@ deposits_get_transaction (void *cls,
&ctx->execution_time,
&ctx->coin_contribution,
&fee,
- &ctx->kyc);
+ &ctx->kyc,
+ &ctx->aml_decision);
if (0 > qs)
{
if (GNUNET_DB_STATUS_HARD_ERROR == qs)
@@ -221,130 +297,228 @@ deposits_get_transaction (void *cls,
/**
+ * Function called on events received from Postgres.
+ * Wakes up long pollers.
+ *
+ * @param cls the `struct DepositWtidContext *`
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+static void
+db_event_cb (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ struct DepositWtidContext *ctx = cls;
+ struct GNUNET_AsyncScopeSave old_scope;
+
+ (void) extra;
+ (void) extra_size;
+ if (GNUNET_YES != ctx->suspended)
+ return; /* might get multiple wake-up events */
+ GNUNET_CONTAINER_DLL_remove (dwc_head,
+ dwc_tail,
+ ctx);
+ GNUNET_async_scope_enter (&ctx->rc->async_scope_id,
+ &old_scope);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resuming request handling\n");
+ TEH_check_invariants ();
+ ctx->suspended = GNUNET_NO;
+ MHD_resume_connection (ctx->rc->connection);
+ TALER_MHD_daemon_trigger ();
+ TEH_check_invariants ();
+ GNUNET_async_scope_restore (&old_scope);
+}
+
+
+/**
* Lookup and return the wire transfer identifier.
*
- * @param connection the MHD connection to handle
* @param ctx context of the signed request to execute
* @return MHD result code
*/
static MHD_RESULT
handle_track_transaction_request (
- struct MHD_Connection *connection,
struct DepositWtidContext *ctx)
{
- MHD_RESULT mhd_ret;
-
- if (GNUNET_OK !=
- TEH_DB_run_transaction (connection,
- "handle deposits GET",
- TEH_MT_REQUEST_OTHER,
- &mhd_ret,
- &deposits_get_transaction,
- ctx))
- return mhd_ret;
+ struct MHD_Connection *connection = ctx->rc->connection;
+
+ if ( (GNUNET_TIME_absolute_is_future (ctx->timeout)) &&
+ (NULL == ctx->eh) )
+ {
+ struct TALER_CoinDepositEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_DEPOSIT_STATUS_CHANGED),
+ .merchant_pub = ctx->merchant
+ };
+
+ ctx->eh = TEH_plugin->event_listen (
+ TEH_plugin->cls,
+ GNUNET_TIME_absolute_get_remaining (ctx->timeout),
+ &rep.header,
+ &db_event_cb,
+ ctx);
+ GNUNET_break (NULL != ctx->eh);
+ }
+ {
+ MHD_RESULT mhd_ret;
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (connection,
+ "handle deposits GET",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &deposits_get_transaction,
+ ctx))
+ return mhd_ret;
+ }
if (GNUNET_SYSERR == ctx->pending)
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_INVARIANT_FAILURE,
"wire fees exceed aggregate in database");
if (GNUNET_YES == ctx->pending)
+ {
+ if ( (GNUNET_TIME_absolute_is_future (ctx->timeout)) &&
+ (GNUNET_NO == ctx->suspended) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Suspending request handling\n");
+ GNUNET_CONTAINER_DLL_insert (dwc_head,
+ dwc_tail,
+ ctx);
+ ctx->suspended = GNUNET_YES;
+ MHD_suspend_connection (connection);
+ return MHD_YES;
+ }
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_ACCEPTED,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- ctx->kyc.payment_target_uuid),
+ GNUNET_JSON_pack_allow_null (
+ (0 == ctx->kyc.requirement_row)
+ ? GNUNET_JSON_pack_string ("requirement_row",
+ NULL)
+ : GNUNET_JSON_pack_uint64 ("requirement_row",
+ ctx->kyc.requirement_row)),
+ GNUNET_JSON_pack_uint64 ("aml_decision",
+ (uint32_t) ctx->aml_decision),
GNUNET_JSON_pack_bool ("kyc_ok",
ctx->kyc.ok),
GNUNET_JSON_pack_timestamp ("execution_time",
ctx->execution_time));
+ }
return reply_deposit_details (connection,
ctx);
}
+/**
+ * Function called to clean up a context.
+ *
+ * @param rc request context with data to clean up
+ */
+static void
+dwc_cleaner (struct TEH_RequestContext *rc)
+{
+ struct DepositWtidContext *ctx = rc->rh_ctx;
+
+ GNUNET_assert (GNUNET_NO == ctx->suspended);
+ if (NULL != ctx->eh)
+ {
+ TEH_plugin->event_listen_cancel (TEH_plugin->cls,
+ ctx->eh);
+ ctx->eh = NULL;
+ }
+ GNUNET_free (ctx);
+}
+
+
MHD_RESULT
TEH_handler_deposits_get (struct TEH_RequestContext *rc,
const char *const args[4])
{
- enum GNUNET_GenericReturnValue res;
- struct TALER_MerchantSignatureP merchant_sig;
- struct DepositWtidContext ctx;
+ struct DepositWtidContext *ctx = rc->rh_ctx;
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[0],
- strlen (args[0]),
- &ctx.h_wire,
- sizeof (ctx.h_wire)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_H_WIRE,
- args[0]);
- }
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[1],
- strlen (args[1]),
- &ctx.merchant,
- sizeof (ctx.merchant)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_MERCHANT_PUB,
- args[1]);
- }
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[2],
- strlen (args[2]),
- &ctx.h_contract_terms,
- sizeof (ctx.h_contract_terms)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_H_CONTRACT_TERMS,
- args[2]);
- }
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[3],
- strlen (args[3]),
- &ctx.coin_pub,
- sizeof (ctx.coin_pub)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_COIN_PUB,
- args[3]);
- }
- res = TALER_MHD_parse_request_arg_data (rc->connection,
- "merchant_sig",
- &merchant_sig,
- sizeof (merchant_sig));
- if (GNUNET_SYSERR == res)
- return MHD_NO; /* internal error */
- if (GNUNET_NO == res)
- return MHD_YES; /* parse error */
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (NULL == ctx)
{
+ ctx = GNUNET_new (struct DepositWtidContext);
+ ctx->rc = rc;
+ rc->rh_ctx = ctx;
+ rc->rh_cleaner = &dwc_cleaner;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &ctx->h_wire,
+ sizeof (ctx->h_wire)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_H_WIRE,
+ args[0]);
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[1],
+ strlen (args[1]),
+ &ctx->merchant,
+ sizeof (ctx->merchant)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_MERCHANT_PUB,
+ args[1]);
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[2],
+ strlen (args[2]),
+ &ctx->h_contract_terms,
+ sizeof (ctx->h_contract_terms)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_H_CONTRACT_TERMS,
+ args[2]);
+ }
if (GNUNET_OK !=
- TALER_merchant_deposit_verify (&ctx.merchant,
- &ctx.coin_pub,
- &ctx.h_contract_terms,
- &ctx.h_wire,
- &merchant_sig))
+ GNUNET_STRINGS_string_to_data (args[3],
+ strlen (args[3]),
+ &ctx->coin_pub,
+ sizeof (ctx->coin_pub)))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_DEPOSITS_GET_MERCHANT_SIGNATURE_INVALID,
- NULL);
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_COIN_PUB,
+ args[3]);
+ }
+ TALER_MHD_parse_request_arg_auto_t (rc->connection,
+ "merchant_sig",
+ &ctx->merchant_sig);
+ TALER_MHD_parse_request_timeout (rc->connection,
+ &ctx->timeout);
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ {
+ if (GNUNET_OK !=
+ TALER_merchant_deposit_verify (&ctx->merchant,
+ &ctx->coin_pub,
+ &ctx->h_contract_terms,
+ &ctx->h_wire,
+ &ctx->merchant_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_DEPOSITS_GET_MERCHANT_SIGNATURE_INVALID,
+ NULL);
+ }
}
}
- return handle_track_transaction_request (rc->connection,
- &ctx);
+ return handle_track_transaction_request (ctx);
}
diff --git a/src/exchange/taler-exchange-httpd_deposits_get.h b/src/exchange/taler-exchange-httpd_deposits_get.h
index aee7521a5..c7b1698bb 100644
--- a/src/exchange/taler-exchange-httpd_deposits_get.h
+++ b/src/exchange/taler-exchange-httpd_deposits_get.h
@@ -27,6 +27,13 @@
/**
+ * Resume long pollers on GET /deposits.
+ */
+void
+TEH_deposits_get_cleanup (void);
+
+
+/**
* Handle a "/deposits/$H_WIRE/$MERCHANT_PUB/$H_CONTRACT_TERMS/$COIN_PUB"
* request.
*
diff --git a/src/exchange/taler-exchange-httpd_extensions.c b/src/exchange/taler-exchange-httpd_extensions.c
index 5a6137383..d62a618ae 100644
--- a/src/exchange/taler-exchange-httpd_extensions.c
+++ b/src/exchange/taler-exchange-httpd_extensions.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,14 +14,16 @@
*/
/**
* @file taler-exchange-httpd_extensions.c
- * @brief Handle extensions (age-restriction, peer2peer)
+ * @brief Handle extensions (age-restriction, policy extensions)
* @author Özgür Kesim
*/
#include "platform.h"
#include <gnunet/gnunet_json_lib.h>
#include "taler_dbevents.h"
+#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_extensions.h"
+#include "taler_extensions_policy.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler_extensions.h"
@@ -77,80 +79,118 @@ extension_update_event_cb (void *cls,
return;
}
- // Get the config from the database as string
+ // Get the manifest from the database as string
{
- char *config_str = NULL;
+ char *manifest_str = NULL;
enum GNUNET_DB_QueryStatus qs;
json_error_t err;
- json_t *config;
+ json_t *manifest_js;
enum GNUNET_GenericReturnValue ret;
- qs = TEH_plugin->get_extension_config (TEH_plugin->cls,
- extension->name,
- &config_str);
+ qs = TEH_plugin->get_extension_manifest (TEH_plugin->cls,
+ extension->name,
+ &manifest_str);
if (qs < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Couldn't get extension config\n");
+ "Couldn't get extension manifest\n");
GNUNET_break (0);
return;
}
// No config found -> disable extension
- if (NULL == config_str)
+ if (NULL == manifest_str)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No manifest found for extension %s, disabling it\n",
+ extension->name);
extension->disable ((struct TALER_Extension *) extension);
return;
}
// Parse the string as JSON
- config = json_loads (config_str, JSON_DECODE_ANY, &err);
- if (NULL == config)
+ manifest_js = json_loads (manifest_str, JSON_DECODE_ANY, &err);
+ if (NULL == manifest_js)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse config for extension `%s' as JSON: %s (%s)\n",
+ "Failed to parse manifest for extension `%s' as JSON: %s (%s)\n",
extension->name,
err.text,
err.source);
GNUNET_break (0);
+ free (manifest_str);
return;
}
// Call the parser for the extension
- ret = extension->load_json_config (
- (struct TALER_Extension *) extension,
- config);
+ ret = extension->load_config (
+ json_object_get (manifest_js, "config"),
+ (struct TALER_Extension *) extension);
if (GNUNET_OK != ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Couldn't parse configuration for extension %s from the database",
- extension->name);
+ "Couldn't parse configuration for extension %s from the manifest in the database: %s\n",
+ extension->name,
+ manifest_str);
GNUNET_break (0);
}
+
+ free (manifest_str);
+ json_decref (manifest_js);
}
/* Special case age restriction: Update global flag and mask */
if (TALER_Extension_AgeRestriction == type)
{
- TEH_age_restriction_enabled =
- TALER_extensions_age_restriction_is_enabled ();
+ const struct TALER_AgeRestrictionConfig *conf =
+ TALER_extensions_get_age_restriction_config ();
+ TEH_age_restriction_enabled = false;
+ if (NULL != conf)
+ {
+ TEH_age_restriction_enabled = extension->enabled;
+ TEH_age_restriction_config = *conf;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "[age restriction] DB event has changed the config to %s with mask: %s\n",
+ TEH_age_restriction_enabled ? "enabled": "DISABLED",
+ TALER_age_mask_to_string (&conf->mask));
+ }
}
+
+ // Finally, call TEH_keys_update_states in order to refresh the cached
+ // values.
+ TEH_keys_update_states ();
}
enum GNUNET_GenericReturnValue
TEH_extensions_init ()
{
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
-
/* Set the event handler for updates */
struct GNUNET_DB_EventHeaderP ev = {
.size = htons (sizeof (ev)),
.type = htons (TALER_DBEVENT_EXCHANGE_EXTENSIONS_UPDATED),
};
+
+ /* Load the shared libraries first */
+ if (GNUNET_OK !=
+ TALER_extensions_init (TEH_cfg))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "failed to load extensions");
+ return GNUNET_SYSERR;
+ }
+
+ /* Check for age restriction */
+ {
+ const struct TALER_AgeRestrictionConfig *arc;
+
+ if (NULL !=
+ (arc = TALER_extensions_get_age_restriction_config ()))
+ TEH_age_restriction_config = *arc;
+ }
+
extensions_eh = TEH_plugin->event_listen (TEH_plugin->cls,
GNUNET_TIME_UNIT_FOREVER_REL,
&ev,
@@ -162,17 +202,28 @@ TEH_extensions_init ()
return GNUNET_SYSERR;
}
- /* FIXME: shall we load the extensions from the config right away?
- * We do have to for now, as otherwise denominations with age restriction
- * will not have the age mask set right upon initial generation.
- */
- TALER_extensions_load_taler_config (TEH_cfg);
-
/* Trigger the initial load of configuration from the db */
- for (const struct TALER_Extension *it = TALER_extensions_get_head ();
- NULL != it->next;
+ for (const struct TALER_Extensions *it = TALER_extensions_get_head ();
+ NULL != it && NULL != it->extension;
it = it->next)
- extension_update_event_cb (NULL, &it->type, sizeof(it->type));
+ {
+ const struct TALER_Extension *ext = it->extension;
+ uint32_t typ = htonl (ext->type);
+ json_t *jmani;
+ char *manifest;
+
+ jmani = ext->manifest (ext);
+ manifest = json_dumps (jmani,
+ JSON_COMPACT);
+ json_decref (jmani);
+ TEH_plugin->set_extension_manifest (TEH_plugin->cls,
+ ext->name,
+ manifest);
+ free (manifest);
+ extension_update_event_cb (NULL,
+ &typ,
+ sizeof(typ));
+ }
return GNUNET_OK;
}
@@ -190,4 +241,202 @@ TEH_extensions_done ()
}
+/*
+ * @brief Execute database transactions for /extensions/policy_* POST requests.
+ *
+ * @param cls a `struct TALER_PolicyFulfillmentOutcome`
+ * @param connection MHD request context
+ * @param[out] mhd_ret set to MHD status on error
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+policy_fulfillment_transaction (
+ void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct TALER_PolicyFulfillmentTransactionData *fulfillment = cls;
+
+ /* FIXME[oec]: use connection and mhd_ret? */
+ (void) connection;
+ (void) mhd_ret;
+
+ return TEH_plugin->add_policy_fulfillment_proof (TEH_plugin->cls,
+ fulfillment);
+}
+
+
+/* FIXME[oec]-#7999: In this handler: do we transition correctly between states? */
+MHD_RESULT
+TEH_extensions_post_handler (
+ struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[])
+{
+ const struct TALER_Extension *ext = NULL;
+ json_t *output;
+ struct TALER_PolicyDetails *policy_details = NULL;
+ size_t policy_details_count = 0;
+
+
+ if (NULL == args[0])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "/extensions/$EXTENSION");
+ }
+
+ ext = TALER_extensions_get_by_name (args[0]);
+ if (NULL == ext)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "/extensions/$EXTENSION unknown");
+ }
+
+ if (NULL == ext->policy_post_handler)
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_IMPLEMENTED,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "POST /extensions/$EXTENSION not supported");
+
+ /* Extract hash_codes and retrieve related policy_details from the DB */
+ {
+ enum GNUNET_GenericReturnValue ret;
+ enum GNUNET_DB_QueryStatus qs;
+ const char *error_msg;
+ struct GNUNET_HashCode *hcs;
+ size_t len;
+ json_t*val;
+ size_t idx;
+ json_t *jhash_codes = json_object_get (root,
+ "policy_hash_codes");
+ if (! json_is_array (jhash_codes))
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "policy_hash_codes are missing");
+
+ len = json_array_size (jhash_codes);
+ hcs = GNUNET_new_array (len,
+ struct GNUNET_HashCode);
+ policy_details = GNUNET_new_array (len,
+ struct TALER_PolicyDetails);
+
+ json_array_foreach (jhash_codes, idx, val)
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (NULL, &hcs[idx]),
+ GNUNET_JSON_spec_end ()
+ };
+
+ ret = GNUNET_JSON_parse (val,
+ spec,
+ &error_msg,
+ NULL);
+ if (GNUNET_OK != ret)
+ break;
+
+ qs = TEH_plugin->get_policy_details (TEH_plugin->cls,
+ &hcs[idx],
+ &policy_details[idx]);
+ if (0 > qs)
+ {
+ GNUNET_free (hcs);
+ GNUNET_free (policy_details);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "a policy_hash_code couldn't be found");
+ }
+
+ /* We proceed according to the state of fulfillment */
+ switch (policy_details[idx].fulfillment_state)
+ {
+ case TALER_PolicyFulfillmentReady:
+ break;
+ case TALER_PolicyFulfillmentInsufficient:
+ error_msg = "a policy is not yet fully funded";
+ ret = GNUNET_SYSERR;
+ break;
+ case TALER_PolicyFulfillmentTimeout:
+ error_msg = "a policy is has already timed out";
+ ret = GNUNET_SYSERR;
+ break;
+ case TALER_PolicyFulfillmentSuccess:
+ /* FIXME[oec]-#8001: Idempotency handling. */
+ GNUNET_break (0);
+ break;
+ case TALER_PolicyFulfillmentFailure:
+ /* FIXME[oec]-#7999: What to do in the failure case? */
+ GNUNET_break (0);
+ break;
+ default:
+ /* Unknown state */
+ GNUNET_assert (0);
+ }
+
+ if (GNUNET_OK != ret)
+ break;
+ }
+
+ GNUNET_free (hcs);
+
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_free (policy_details);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ error_msg);
+ }
+ }
+
+
+ if (GNUNET_OK !=
+ ext->policy_post_handler (root,
+ &args[1],
+ policy_details,
+ policy_details_count,
+ &output))
+ {
+ return TALER_MHD_reply_json_steal (
+ rc->connection,
+ output,
+ MHD_HTTP_BAD_REQUEST);
+ }
+
+ /* execute fulfillment transaction */
+ {
+ MHD_RESULT mhd_ret;
+ struct TALER_PolicyFulfillmentTransactionData fulfillment = {
+ .proof = root,
+ .timestamp = GNUNET_TIME_timestamp_get (),
+ .details = policy_details,
+ .details_count = policy_details_count
+ };
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (rc->connection,
+ "execute policy fulfillment",
+ TEH_MT_REQUEST_POLICY_FULFILLMENT,
+ &mhd_ret,
+ &policy_fulfillment_transaction,
+ &fulfillment))
+ {
+ json_decref (output);
+ return mhd_ret;
+ }
+ }
+
+ return TALER_MHD_reply_json_steal (rc->connection,
+ output,
+ MHD_HTTP_OK);
+}
+
+
/* end of taler-exchange-httpd_extensions.c */
diff --git a/src/exchange/taler-exchange-httpd_extensions.h b/src/exchange/taler-exchange-httpd_extensions.h
index 4659b653e..e435f8f03 100644
--- a/src/exchange/taler-exchange-httpd_extensions.h
+++ b/src/exchange/taler-exchange-httpd_extensions.h
@@ -40,4 +40,19 @@ TEH_extensions_init (void);
void
TEH_extensions_done (void);
+
+/**
+ * Handle POST "/extensions/..." requests.
+ *
+ * @param rc request context
+ * @param root uploaded JSON data
+ * @param args array of additional options
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_extensions_post_handler (
+ struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[]);
+
#endif
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index b1fa2cbc4..0ec28e950 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020-2022 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -17,12 +17,15 @@
* @file taler-exchange-httpd_keys.c
* @brief management of our various keys
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
#include "platform.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_dbevents.h"
#include "taler-exchange-httpd.h"
+#include "taler-exchange-httpd_config.h"
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_responses.h"
#include "taler_exchangedb_plugin.h"
@@ -43,24 +46,6 @@
/**
- * Taler protocol version in the format CURRENT:REVISION:AGE
- * as used by GNU libtool. See
- * https://www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html
- *
- * Please be very careful when updating and follow
- * https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info
- * precisely. Note that this version has NOTHING to do with the
- * release version, and the format is NOT the same that semantic
- * versioning uses either.
- *
- * When changing this version, you likely want to also update
- * #TALER_PROTOCOL_CURRENT and #TALER_PROTOCOL_AGE in
- * exchange_api_handle.c!
- */
-#define EXCHANGE_PROTOCOL_VERSION "14:0:2"
-
-
-/**
* Information about a denomination on offer by the denomination helper.
*/
struct HelperDenomination
@@ -403,6 +388,113 @@ struct SuspendedKeysRequests
struct GNUNET_TIME_Absolute timeout;
};
+
+/**
+ * Information we track about wire fees.
+ */
+struct WireFeeSet
+{
+
+ /**
+ * Kept in a DLL.
+ */
+ struct WireFeeSet *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct WireFeeSet *prev;
+
+ /**
+ * Actual fees.
+ */
+ struct TALER_WireFeeSet fees;
+
+ /**
+ * Start date of fee validity (inclusive).
+ */
+ struct GNUNET_TIME_Timestamp start_date;
+
+ /**
+ * End date of fee validity (exclusive).
+ */
+ struct GNUNET_TIME_Timestamp end_date;
+
+ /**
+ * Wire method the fees apply to.
+ */
+ char *method;
+};
+
+
+/**
+ * State we keep per thread to cache the /wire response.
+ */
+struct WireStateHandle
+{
+
+ /**
+ * JSON reply for /wire response.
+ */
+ json_t *json_reply;
+
+ /**
+ * ETag for this response (if any).
+ */
+ char *etag;
+
+ /**
+ * head of DLL of wire fees.
+ */
+ struct WireFeeSet *wfs_head;
+
+ /**
+ * Tail of DLL of wire fees.
+ */
+ struct WireFeeSet *wfs_tail;
+
+ /**
+ * Earliest timestamp of all the wire methods when we have no more fees.
+ */
+ struct GNUNET_TIME_Absolute cache_expiration;
+
+ /**
+ * @e cache_expiration time, formatted.
+ */
+ char dat[128];
+
+ /**
+ * For which (global) wire_generation was this data structure created?
+ * Used to check when we are outdated and need to be re-generated.
+ */
+ uint64_t wire_generation;
+
+ /**
+ * Is the wire data ready?
+ */
+ bool ready;
+
+};
+
+
+/**
+ * Stores the latest generation of our wire response.
+ */
+static struct WireStateHandle *wire_state;
+
+/**
+ * Handler listening for wire updates by other exchange
+ * services.
+ */
+static struct GNUNET_DB_EventHandler *wire_eh;
+
+/**
+ * Counter incremented whenever we have a reason to re-build the #wire_state
+ * because something external changed.
+ */
+static uint64_t wire_generation;
+
+
/**
* Stores the latest generation of our key state.
*/
@@ -455,6 +547,11 @@ static struct GNUNET_SCHEDULER_Task *keys_tt;
static struct GNUNET_TIME_Relative signkey_legal_duration;
/**
+ * What type of asset are we dealing with here?
+ */
+static char *asset_type;
+
+/**
* RSA security module public key, all zero if not known.
*/
static struct TALER_SecurityModulePublicKeyP denom_rsa_sm_pub;
@@ -476,6 +573,449 @@ static bool terminating;
/**
+ * Free memory associated with @a wsh
+ *
+ * @param[in] wsh wire state to destroy
+ */
+static void
+destroy_wire_state (struct WireStateHandle *wsh)
+{
+ struct WireFeeSet *wfs;
+
+ while (NULL != (wfs = wsh->wfs_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (wsh->wfs_head,
+ wsh->wfs_tail,
+ wfs);
+ GNUNET_free (wfs->method);
+ GNUNET_free (wfs);
+ }
+ json_decref (wsh->json_reply);
+ GNUNET_free (wsh->etag);
+ GNUNET_free (wsh);
+}
+
+
+/**
+ * Function called whenever another exchange process has updated
+ * the wire data in the database.
+ *
+ * @param cls NULL
+ * @param extra unused
+ * @param extra_size number of bytes in @a extra unused
+ */
+static void
+wire_update_event_cb (void *cls,
+ const void *extra,
+ size_t extra_size)
+{
+ (void) cls;
+ (void) extra;
+ (void) extra_size;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received /wire update event\n");
+ TEH_check_invariants ();
+ wire_generation++;
+ key_generation++;
+ TEH_resume_keys_requests (false);
+}
+
+
+enum GNUNET_GenericReturnValue
+TEH_wire_init ()
+{
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_EXCHANGE_KEYS_UPDATED),
+ };
+
+ wire_eh = TEH_plugin->event_listen (TEH_plugin->cls,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &es,
+ &wire_update_event_cb,
+ NULL);
+ if (NULL == wire_eh)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+void
+TEH_wire_done ()
+{
+ if (NULL != wire_state)
+ {
+ destroy_wire_state (wire_state);
+ wire_state = NULL;
+ }
+ if (NULL != wire_eh)
+ {
+ TEH_plugin->event_listen_cancel (TEH_plugin->cls,
+ wire_eh);
+ wire_eh = NULL;
+ }
+}
+
+
+/**
+ * Add information about a wire account to @a cls.
+ *
+ * @param cls a `json_t *` object to expand with wire account details
+ * @param payto_uri the exchange bank account URI to add
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
+ * @param master_sig master key signature affirming that this is a bank
+ * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
+ * @param bank_label label the wallet should use to display the account, can be NULL
+ * @param priority priority for ordering bank account labels
+ */
+static void
+add_wire_account (void *cls,
+ const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority)
+{
+ json_t *a = cls;
+
+ if (GNUNET_OK !=
+ TALER_exchange_wire_signature_check (
+ payto_uri,
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
+ &TEH_master_public_key,
+ master_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database has wire account with invalid signature. Skipping entry. Did the exchange offline public key change?\n");
+ return;
+ }
+ if (0 !=
+ json_array_append_new (
+ a,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("payto_uri",
+ payto_uri),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("conversion_url",
+ conversion_url)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("bank_label",
+ bank_label)),
+ GNUNET_JSON_pack_int64 ("priority",
+ priority),
+ GNUNET_JSON_pack_array_incref ("debit_restrictions",
+ (json_t *) debit_restrictions),
+ GNUNET_JSON_pack_array_incref ("credit_restrictions",
+ (json_t *) credit_restrictions),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ master_sig))))
+ {
+ GNUNET_break (0); /* out of memory!? */
+ return;
+ }
+}
+
+
+/**
+ * Closure for #add_wire_fee().
+ */
+struct AddContext
+{
+ /**
+ * Wire method the fees are for.
+ */
+ char *wire_method;
+
+ /**
+ * Wire state we are building.
+ */
+ struct WireStateHandle *wsh;
+
+ /**
+ * Array to append the fee to.
+ */
+ json_t *a;
+
+ /**
+ * Set to the maximum end-date seen.
+ */
+ struct GNUNET_TIME_Absolute max_seen;
+};
+
+
+/**
+ * Add information about a wire account to @a cls.
+ *
+ * @param cls a `struct AddContext`
+ * @param fees the wire fees we charge
+ * @param start_date from when are these fees valid (start date)
+ * @param end_date until when are these fees valid (end date, exclusive)
+ * @param master_sig master key signature affirming that this is the correct
+ * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
+ */
+static void
+add_wire_fee (void *cls,
+ const struct TALER_WireFeeSet *fees,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct AddContext *ac = cls;
+ struct WireFeeSet *wfs;
+
+ if (GNUNET_OK !=
+ TALER_exchange_offline_wire_fee_verify (
+ ac->wire_method,
+ start_date,
+ end_date,
+ fees,
+ &TEH_master_public_key,
+ master_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database has wire fee with invalid signature. Skipping entry. Did the exchange offline public key change?\n");
+ return;
+ }
+ ac->max_seen = GNUNET_TIME_absolute_max (ac->max_seen,
+ end_date.abs_time);
+ wfs = GNUNET_new (struct WireFeeSet);
+ wfs->start_date = start_date;
+ wfs->end_date = end_date;
+ wfs->fees = *fees;
+ wfs->method = GNUNET_strdup (ac->wire_method);
+ GNUNET_CONTAINER_DLL_insert (ac->wsh->wfs_head,
+ ac->wsh->wfs_tail,
+ wfs);
+ if (0 !=
+ json_array_append_new (
+ ac->a,
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("wire_fee",
+ &fees->wire),
+ TALER_JSON_pack_amount ("closing_fee",
+ &fees->closing),
+ GNUNET_JSON_pack_timestamp ("start_date",
+ start_date),
+ GNUNET_JSON_pack_timestamp ("end_date",
+ end_date),
+ GNUNET_JSON_pack_data_auto ("sig",
+ master_sig))))
+ {
+ GNUNET_break (0); /* out of memory!? */
+ return;
+ }
+}
+
+
+/**
+ * Create the /wire response from our database state.
+ *
+ * @return NULL on error
+ */
+static struct WireStateHandle *
+build_wire_state (void)
+{
+ json_t *wire_accounts_array;
+ json_t *wire_fee_object;
+ uint64_t wg = wire_generation; /* must be obtained FIRST */
+ enum GNUNET_DB_QueryStatus qs;
+ struct WireStateHandle *wsh;
+ json_t *wads;
+
+ wsh = GNUNET_new (struct WireStateHandle);
+ wsh->wire_generation = wg;
+ wire_accounts_array = json_array ();
+ GNUNET_assert (NULL != wire_accounts_array);
+ qs = TEH_plugin->get_wire_accounts (TEH_plugin->cls,
+ &add_wire_account,
+ wire_accounts_array);
+ if (0 > qs)
+ {
+ GNUNET_break (0);
+ json_decref (wire_accounts_array);
+ wsh->ready = false;
+ return wsh;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Build /wire data with %u accounts\n",
+ (unsigned int) json_array_size (wire_accounts_array));
+ wire_fee_object = json_object ();
+ GNUNET_assert (NULL != wire_fee_object);
+ wsh->cache_expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
+ {
+ json_t *account;
+ size_t index;
+
+ json_array_foreach (wire_accounts_array,
+ index,
+ account)
+ {
+ char *wire_method;
+ const char *payto_uri = json_string_value (json_object_get (account,
+ "payto_uri"));
+
+ GNUNET_assert (NULL != payto_uri);
+ wire_method = TALER_payto_get_method (payto_uri);
+ if (NULL == wire_method)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No wire method in `%s'\n",
+ payto_uri);
+ wsh->ready = false;
+ json_decref (wire_accounts_array);
+ json_decref (wire_fee_object);
+ return wsh;
+ }
+ if (NULL == json_object_get (wire_fee_object,
+ wire_method))
+ {
+ struct AddContext ac = {
+ .wire_method = wire_method,
+ .wsh = wsh,
+ .a = json_array ()
+ };
+
+ GNUNET_assert (NULL != ac.a);
+ qs = TEH_plugin->get_wire_fees (TEH_plugin->cls,
+ wire_method,
+ &add_wire_fee,
+ &ac);
+ if (0 > qs)
+ {
+ GNUNET_break (0);
+ json_decref (ac.a);
+ json_decref (wire_fee_object);
+ json_decref (wire_accounts_array);
+ GNUNET_free (wire_method);
+ wsh->ready = false;
+ return wsh;
+ }
+ if (0 != json_array_size (ac.a))
+ {
+ wsh->cache_expiration
+ = GNUNET_TIME_absolute_min (ac.max_seen,
+ wsh->cache_expiration);
+ GNUNET_assert (0 ==
+ json_object_set_new (wire_fee_object,
+ wire_method,
+ ac.a));
+ }
+ else
+ {
+ json_decref (ac.a);
+ }
+ }
+ GNUNET_free (wire_method);
+ }
+ }
+
+ wads = json_array (); /* #7271 */
+ GNUNET_assert (NULL != wads);
+ wsh->json_reply = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("accounts",
+ wire_accounts_array),
+ GNUNET_JSON_pack_array_steal ("wads",
+ wads),
+ GNUNET_JSON_pack_object_steal ("fees",
+ wire_fee_object));
+ wsh->ready = true;
+ return wsh;
+}
+
+
+void
+TEH_wire_update_state (void)
+{
+ struct GNUNET_DB_EventHeaderP es = {
+ .size = htons (sizeof (es)),
+ .type = htons (TALER_DBEVENT_EXCHANGE_WIRE_UPDATED),
+ };
+
+ TEH_plugin->event_notify (TEH_plugin->cls,
+ &es,
+ NULL,
+ 0);
+ wire_generation++;
+ key_generation++;
+}
+
+
+/**
+ * Return the current key state for this thread. Possibly
+ * re-builds the key state if we have reason to believe
+ * that something changed.
+ *
+ * @return NULL on error
+ */
+struct WireStateHandle *
+get_wire_state (void)
+{
+ struct WireStateHandle *old_wsh;
+
+ old_wsh = wire_state;
+ if ( (NULL == old_wsh) ||
+ (old_wsh->wire_generation < wire_generation) )
+ {
+ struct WireStateHandle *wsh;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Rebuilding /wire, generation upgrade from %llu to %llu\n",
+ (unsigned long long) (NULL == old_wsh) ? 0LL :
+ old_wsh->wire_generation,
+ (unsigned long long) wire_generation);
+ TEH_check_invariants ();
+ wsh = build_wire_state ();
+ wire_state = wsh;
+ if (NULL != old_wsh)
+ destroy_wire_state (old_wsh);
+ TEH_check_invariants ();
+ return wsh;
+ }
+ return old_wsh;
+}
+
+
+const struct TALER_WireFeeSet *
+TEH_wire_fees_by_time (
+ struct GNUNET_TIME_Timestamp ts,
+ const char *method)
+{
+ struct WireStateHandle *wsh = get_wire_state ();
+
+ for (struct WireFeeSet *wfs = wsh->wfs_head;
+ NULL != wfs;
+ wfs = wfs->next)
+ {
+ if (0 != strcmp (method,
+ wfs->method))
+ continue;
+ if ( (GNUNET_TIME_timestamp_cmp (wfs->start_date,
+ >,
+ ts)) ||
+ (GNUNET_TIME_timestamp_cmp (ts,
+ >=,
+ wfs->end_date)) )
+ continue;
+ return &wfs->fees;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No wire fees for method `%s' at %s configured\n",
+ method,
+ GNUNET_TIME_timestamp2s (ts));
+ return NULL;
+}
+
+
+/**
* Function called to forcefully resume suspended keys requests.
*
* @param cls unused, NULL
@@ -575,12 +1115,20 @@ check_dk (void *cls,
(void) cls;
(void) hc;
- GNUNET_assert (TALER_DENOMINATION_INVALID != dk->denom_pub.cipher);
- if (TALER_DENOMINATION_RSA == dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
GNUNET_assert (GNUNET_CRYPTO_rsa_public_key_check (
- dk->denom_pub.details.rsa_public_key));
- // nothing to do for TALER_DENOMINATION_CS
- return GNUNET_OK;
+ dk->denom_pub.bsign_pub_key->details.rsa_public_key));
+ return GNUNET_OK;
+ case GNUNET_CRYPTO_BSA_CS:
+ /* nothing to do for GNUNET_CRYPTO_BSA_CS */
+ return GNUNET_OK;
+ }
+ GNUNET_assert (0);
+ return GNUNET_SYSERR;
}
@@ -748,7 +1296,7 @@ free_denom_cb (void *cls,
* @param value the `struct HelperSignkey` to release
* @return #GNUNET_OK (continue to iterate)
*/
-static int
+static enum GNUNET_GenericReturnValue
free_esign_cb (void *cls,
const struct GNUNET_PeerIdentity *pid,
void *value)
@@ -811,13 +1359,10 @@ destroy_key_helpers (struct HelperState *hs)
* denomination.
*/
static struct TALER_AgeMask
-load_age_mask (const char*section_name)
+load_age_mask (const char *section_name)
{
static const struct TALER_AgeMask null_mask = {0};
- struct TALER_AgeMask age_mask = TALER_extensions_age_restriction_ageMask ();
-
- if (age_mask.bits == 0)
- return null_mask;
+ enum GNUNET_GenericReturnValue ret;
if (GNUNET_OK != (GNUNET_CONFIGURATION_have_value (
TEH_cfg,
@@ -825,22 +1370,29 @@ load_age_mask (const char*section_name)
"AGE_RESTRICTED")))
return null_mask;
+ if (GNUNET_SYSERR ==
+ (ret = GNUNET_CONFIGURATION_get_value_yesno (TEH_cfg,
+ section_name,
+ "AGE_RESTRICTED")))
{
- enum GNUNET_GenericReturnValue ret;
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section_name,
+ "AGE_RESTRICTED",
+ "Value must be YES or NO\n");
+ return null_mask;
+ }
- if (GNUNET_SYSERR ==
- (ret = GNUNET_CONFIGURATION_get_value_yesno (TEH_cfg,
- section_name,
- "AGE_RESTRICTED")))
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- section_name,
- "AGE_RESTRICTED",
- "Value must be YES or NO\n");
- return null_mask;
- }
+ if (GNUNET_OK == ret)
+ {
+ if (! TEH_age_restriction_enabled)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "age restriction set in section %s, yet, age restriction is not enabled\n",
+ section_name);
+ return TEH_age_restriction_config.mask;
}
- return age_mask;
+
+
+ return null_mask;
}
@@ -857,7 +1409,7 @@ load_age_mask (const char*section_name)
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_rsa hash of the @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bs_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -869,7 +1421,7 @@ helper_rsa_cb (
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_RsaPubHashP *h_rsa,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig)
{
@@ -899,10 +1451,9 @@ helper_rsa_cb (
hd->validity_duration = validity_duration;
hd->h_details.h_rsa = *h_rsa;
hd->sm_sig = *sm_sig;
- GNUNET_assert (TALER_DENOMINATION_RSA == denom_pub->cipher);
- TALER_denom_pub_deep_copy (&hd->denom_pub,
- denom_pub);
- GNUNET_assert (TALER_DENOMINATION_RSA == hd->denom_pub.cipher);
+ GNUNET_assert (GNUNET_CRYPTO_BSA_RSA == bs_pub->cipher);
+ hd->denom_pub.bsign_pub_key =
+ GNUNET_CRYPTO_bsign_pub_incref (bs_pub);
/* load the age mask for the denomination, if applicable */
hd->denom_pub.age_mask = load_age_mask (section_name);
TALER_denom_pub_hash (&hd->denom_pub,
@@ -938,7 +1489,7 @@ helper_rsa_cb (
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_cs hash of the @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bs_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -950,7 +1501,7 @@ helper_cs_cb (
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_CsPubHashP *h_cs,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig)
{
@@ -980,9 +1531,9 @@ helper_cs_cb (
hd->validity_duration = validity_duration;
hd->h_details.h_cs = *h_cs;
hd->sm_sig = *sm_sig;
- GNUNET_assert (TALER_DENOMINATION_CS == denom_pub->cipher);
- TALER_denom_pub_deep_copy (&hd->denom_pub,
- denom_pub);
+ GNUNET_assert (GNUNET_CRYPTO_BSA_CS == bs_pub->cipher);
+ hd->denom_pub.bsign_pub_key
+ = GNUNET_CRYPTO_bsign_pub_incref (bs_pub);
/* load the age mask for the denomination, if applicable */
hd->denom_pub.age_mask = load_age_mask (section_name);
TALER_denom_pub_hash (&hd->denom_pub,
@@ -1088,6 +1639,7 @@ setup_key_helpers (struct HelperState *hs)
= GNUNET_CONTAINER_multipeermap_create (32,
GNUNET_NO /* MUST BE NO! */);
hs->rsadh = TALER_CRYPTO_helper_rsa_connect (TEH_cfg,
+ "taler-exchange",
&helper_rsa_cb,
hs);
if (NULL == hs->rsadh)
@@ -1096,6 +1648,7 @@ setup_key_helpers (struct HelperState *hs)
return GNUNET_SYSERR;
}
hs->csdh = TALER_CRYPTO_helper_cs_connect (TEH_cfg,
+ "taler-exchange",
&helper_cs_cb,
hs);
if (NULL == hs->csdh)
@@ -1104,6 +1657,7 @@ setup_key_helpers (struct HelperState *hs)
return GNUNET_SYSERR;
}
hs->esh = TALER_CRYPTO_helper_esign_connect (TEH_cfg,
+ "taler-exchange",
&helper_esign_cb,
hs);
if (NULL == hs->esh)
@@ -1273,6 +1827,17 @@ TEH_keys_init ()
"SIGNKEY_LEGAL_DURATION");
return GNUNET_SYSERR;
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (TEH_cfg,
+ "exchange",
+ "ASSET_TYPE",
+ &asset_type))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "exchange",
+ "ASSET_TYPE");
+ asset_type = GNUNET_strdup ("fiat");
+ }
keys_eh = TEH_plugin->event_listen (TEH_plugin->cls,
GNUNET_TIME_UNIT_FOREVER_REL,
&es,
@@ -1333,7 +1898,25 @@ denomination_info_cb (
struct TEH_KeyStateHandle *ksh = cls;
struct TEH_DenominationKey *dk;
- GNUNET_assert (TALER_DENOMINATION_INVALID != denom_pub->cipher);
+ if (GNUNET_OK !=
+ TALER_exchange_offline_denom_validity_verify (
+ h_denom_pub,
+ meta->start,
+ meta->expire_withdraw,
+ meta->expire_deposit,
+ meta->expire_legal,
+ &meta->value,
+ &meta->fees,
+ &TEH_master_public_key,
+ master_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database has denomination with invalid signature. Skipping entry. Did the exchange offline public key change?\n");
+ return;
+ }
+
+ GNUNET_assert (GNUNET_CRYPTO_BSA_INVALID !=
+ denom_pub->bsign_pub_key->cipher);
if (GNUNET_TIME_absolute_is_zero (meta->start.abs_time) ||
GNUNET_TIME_absolute_is_zero (meta->expire_withdraw.abs_time) ||
GNUNET_TIME_absolute_is_zero (meta->expire_deposit.abs_time) ||
@@ -1345,8 +1928,8 @@ denomination_info_cb (
return;
}
dk = GNUNET_new (struct TEH_DenominationKey);
- TALER_denom_pub_deep_copy (&dk->denom_pub,
- denom_pub);
+ TALER_denom_pub_copy (&dk->denom_pub,
+ denom_pub);
dk->h_denom_pub = *h_denom_pub;
dk->meta = *meta;
dk->master_sig = *master_sig;
@@ -1359,7 +1942,6 @@ denomination_info_cb (
&dk->h_denom_pub.hash,
dk,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-
}
@@ -1382,6 +1964,19 @@ signkey_info_cb (
struct SigningKey *sk;
struct GNUNET_PeerIdentity pid;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_signkey_validity_verify (
+ exchange_pub,
+ meta->start,
+ meta->expire_sign,
+ meta->expire_legal,
+ &TEH_master_public_key,
+ master_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database has signing key with invalid signature. Skipping entry. Did the exchange offline public key change?\n");
+ return;
+ }
sk = GNUNET_new (struct SigningKey);
sk->exchange_pub = *exchange_pub;
sk->meta = *meta;
@@ -1663,14 +2258,14 @@ add_denom_key_cb (void *cls,
/**
* Add the headers we want to set for every /keys response.
*
- * @param ksh the key state to use
+ * @param cls the key state to use
* @param[in,out] response the response to modify
- * @return #GNUNET_OK on success
*/
-static enum GNUNET_GenericReturnValue
-setup_general_response_headers (struct TEH_KeyStateHandle *ksh,
+static void
+setup_general_response_headers (void *cls,
struct MHD_Response *response)
{
+ struct TEH_KeyStateHandle *ksh = cls;
char dat[128];
TALER_MHD_add_global_headers (response);
@@ -1678,27 +2273,38 @@ setup_general_response_headers (struct TEH_KeyStateHandle *ksh,
MHD_add_response_header (response,
MHD_HTTP_HEADER_CONTENT_TYPE,
"application/json"));
- TALER_MHD_get_date_string (ksh->reload_time.abs_time,
- dat);
GNUNET_break (MHD_YES ==
MHD_add_response_header (response,
- MHD_HTTP_HEADER_LAST_MODIFIED,
- dat));
+ MHD_HTTP_HEADER_CACHE_CONTROL,
+ "public,must-revalidate,max-age=86400"));
if (! GNUNET_TIME_relative_is_zero (ksh->rekey_frequency))
{
struct GNUNET_TIME_Relative r;
struct GNUNET_TIME_Absolute a;
+ struct GNUNET_TIME_Timestamp km;
struct GNUNET_TIME_Timestamp m;
+ struct GNUNET_TIME_Timestamp we;
r = GNUNET_TIME_relative_min (TEH_max_keys_caching,
ksh->rekey_frequency);
a = GNUNET_TIME_relative_to_absolute (r);
- m = GNUNET_TIME_absolute_to_timestamp (a);
+ /* Round up to next full day to ensure the expiration
+ time does not become a fingerprint! */
+ a = GNUNET_TIME_absolute_round_down (a,
+ GNUNET_TIME_UNIT_DAYS);
+ a = GNUNET_TIME_absolute_add (a,
+ GNUNET_TIME_UNIT_DAYS);
+ km = GNUNET_TIME_absolute_to_timestamp (a);
+ we = GNUNET_TIME_absolute_to_timestamp (wire_state->cache_expiration);
+ m = GNUNET_TIME_timestamp_min (we,
+ km);
TALER_MHD_get_date_string (m.abs_time,
dat);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting /keys 'Expires' header to '%s'\n",
- dat);
+ "Setting /keys 'Expires' header to '%s' (rekey frequency is %s)\n",
+ dat,
+ GNUNET_TIME_relative2s (ksh->rekey_frequency,
+ false));
GNUNET_break (MHD_YES ==
MHD_add_response_header (response,
MHD_HTTP_HEADER_EXPIRES,
@@ -1712,12 +2318,27 @@ setup_general_response_headers (struct TEH_KeyStateHandle *ksh,
MHD_add_response_header (response,
MHD_HTTP_HEADER_VARY,
MHD_HTTP_HEADER_ACCEPT_ENCODING));
- /* Information is always public, revalidate after 1 hour */
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (response,
- MHD_HTTP_HEADER_CACHE_CONTROL,
- "public,max-age=3600"));
- return GNUNET_OK;
+}
+
+
+/**
+ * Function called with wallet balance thresholds.
+ *
+ * @param[in,out] cls a `json **` where to put the array of json amounts discovered
+ * @param threshold another threshold amount to add
+ */
+static void
+wallet_threshold_cb (void *cls,
+ const struct TALER_Amount *threshold)
+{
+ json_t **ret = cls;
+
+ if (NULL == *ret)
+ *ret = json_array ();
+ GNUNET_assert (0 ==
+ json_array_append_new (*ret,
+ TALER_JSON_from_amount (
+ threshold)));
}
@@ -1727,44 +2348,45 @@ setup_general_response_headers (struct TEH_KeyStateHandle *ksh,
*
* @param[in,out] ksh key state handle we build @a krd for
* @param[in] denom_keys_hash hash over all the denomination keys in @a denoms
- * @param last_cpd timestamp to use
- * @param signkeys list of sign keys to return
- * @param recoup list of revoked keys to return
- * @param denoms list of denominations to return
- * @param grouped_denominations list of grouped denominations to return
- * @param[in] h_grouped XOR of all hashes in @a grouped_demoninations
+ * @param last_cherry_pick_date timestamp to use
+ * @param[in,out] signkeys list of sign keys to return
+ * @param[in,out] recoup list of revoked keys to return
+ * @param[in,out] grouped_denominations list of grouped denominations to return
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
create_krd (struct TEH_KeyStateHandle *ksh,
const struct GNUNET_HashCode *denom_keys_hash,
- struct GNUNET_TIME_Timestamp last_cpd,
+ struct GNUNET_TIME_Timestamp last_cherry_pick_date,
json_t *signkeys,
json_t *recoup,
- json_t *denoms,
- json_t *grouped_denominations,
- const struct GNUNET_HashCode *h_grouped)
+ json_t *grouped_denominations)
{
struct KeysResponseData krd;
struct TALER_ExchangePublicKeyP exchange_pub;
struct TALER_ExchangeSignatureP exchange_sig;
- struct TALER_ExchangePublicKeyP grouped_exchange_pub;
- struct TALER_ExchangeSignatureP grouped_exchange_sig;
+ struct WireStateHandle *wsh;
json_t *keys;
- GNUNET_assert (! GNUNET_TIME_absolute_is_zero (last_cpd.abs_time));
+ wsh = get_wire_state ();
+ if (! wsh->ready)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
+ last_cherry_pick_date.abs_time));
GNUNET_assert (NULL != signkeys);
GNUNET_assert (NULL != recoup);
- GNUNET_assert (NULL != denoms);
GNUNET_assert (NULL != grouped_denominations);
- GNUNET_assert (NULL != h_grouped);
GNUNET_assert (NULL != ksh->auditors);
GNUNET_assert (NULL != TEH_currency);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Creating /keys at cherry pick date %s\n",
- GNUNET_TIME_timestamp2s (last_cpd));
+ GNUNET_TIME_timestamp2s (last_cherry_pick_date));
- /* Sign hash over denomination keys */
+ /* Sign hash over master signatures of all denomination keys until this time
+ (in reverse order). */
{
enum TALER_ErrorCode ec;
@@ -1773,7 +2395,7 @@ create_krd (struct TEH_KeyStateHandle *ksh,
TALER_exchange_online_key_set_sign (
&TEH_keys_exchange_sign2_,
ksh,
- last_cpd,
+ last_cherry_pick_date,
denom_keys_hash,
&exchange_pub,
&exchange_sig)))
@@ -1785,33 +2407,6 @@ create_krd (struct TEH_KeyStateHandle *ksh,
}
}
- /* Sign grouped hash */
- {
- enum TALER_ErrorCode ec;
-
- if (TALER_EC_NONE !=
- (ec =
- TALER_exchange_online_key_set_sign (
- &TEH_keys_exchange_sign2_,
- ksh,
- last_cpd,
- h_grouped,
- &grouped_exchange_pub,
- &grouped_exchange_sig)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Could not create key response data: cannot sign grouped hash (%s)\n",
- TALER_ErrorCode_get_hint (ec));
- return GNUNET_SYSERR;
- }
- }
-
- /* both public keys really must be the same */
- GNUNET_assert (0 ==
- memcmp (&grouped_exchange_pub,
- &exchange_pub,
- sizeof(exchange_pub)));
-
{
const struct SigningKey *sk;
@@ -1822,11 +2417,33 @@ create_krd (struct TEH_KeyStateHandle *ksh,
ksh->signature_expires);
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Build /keys data with %u wire accounts\n",
+ (unsigned int) json_array_size (
+ json_object_get (wsh->json_reply,
+ "accounts")));
+
keys = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("version",
EXCHANGE_PROTOCOL_VERSION),
+ GNUNET_JSON_pack_string ("base_url",
+ TEH_base_url),
GNUNET_JSON_pack_string ("currency",
TEH_currency),
+ GNUNET_JSON_pack_object_steal (
+ "currency_specification",
+ TALER_CONFIG_currency_specs_to_json (TEH_cspec)),
+ TALER_JSON_pack_amount ("stefan_abs",
+ &TEH_stefan_abs),
+ TALER_JSON_pack_amount ("stefan_log",
+ &TEH_stefan_log),
+ GNUNET_JSON_pack_double ("stefan_lin",
+ (double) TEH_stefan_lin),
+ GNUNET_JSON_pack_string ("asset_type",
+ asset_type),
+ GNUNET_JSON_pack_bool ("rewards_allowed",
+ GNUNET_YES ==
+ TEH_enable_rewards),
GNUNET_JSON_pack_data_auto ("master_public_key",
&TEH_master_public_key),
GNUNET_JSON_pack_time_rel ("reserve_closing_delay",
@@ -1835,8 +2452,15 @@ create_krd (struct TEH_KeyStateHandle *ksh,
signkeys),
GNUNET_JSON_pack_array_incref ("recoup",
recoup),
- GNUNET_JSON_pack_array_incref ("denoms",
- denoms),
+ GNUNET_JSON_pack_array_incref ("wads",
+ json_object_get (wsh->json_reply,
+ "wads")),
+ GNUNET_JSON_pack_array_incref ("accounts",
+ json_object_get (wsh->json_reply,
+ "accounts")),
+ GNUNET_JSON_pack_object_incref ("wire_fees",
+ json_object_get (wsh->json_reply,
+ "fees")),
GNUNET_JSON_pack_array_incref ("denominations",
grouped_denominations),
GNUNET_JSON_pack_array_incref ("auditors",
@@ -1844,27 +2468,28 @@ create_krd (struct TEH_KeyStateHandle *ksh,
GNUNET_JSON_pack_array_incref ("global_fees",
ksh->global_fees),
GNUNET_JSON_pack_timestamp ("list_issue_date",
- last_cpd),
- GNUNET_JSON_pack_data_auto ("eddsa_pub",
+ last_cherry_pick_date),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
&exchange_pub),
- GNUNET_JSON_pack_data_auto ("eddsa_sig",
- &exchange_sig),
- GNUNET_JSON_pack_data_auto ("denominations_sig",
- &grouped_exchange_sig));
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &exchange_sig));
GNUNET_assert (NULL != keys);
/* Set wallet limit if KYC is configured */
- if ( (TEH_KYC_NONE != TEH_kyc_config.mode) &&
- (GNUNET_OK ==
- TALER_amount_is_valid (&TEH_kyc_config.wallet_balance_limit)) )
{
- GNUNET_assert (
- 0 ==
- json_object_set_new (
- keys,
- "wallet_balance_limit_without_kyc",
- TALER_JSON_from_amount (
- &TEH_kyc_config.wallet_balance_limit)));
+ json_t *wblwk = NULL;
+
+ TALER_KYCLOGIC_kyc_iterate_thresholds (
+ TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE,
+ &wallet_threshold_cb,
+ &wblwk);
+ if (NULL != wblwk)
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (
+ keys,
+ "wallet_balance_limit_without_kyc",
+ wblwk));
}
/* Signal support for the configured, enabled extensions. */
@@ -1872,42 +2497,31 @@ create_krd (struct TEH_KeyStateHandle *ksh,
json_t *extensions = json_object ();
bool has_extensions = false;
+ GNUNET_assert (NULL != extensions);
/* Fill in the configurations of the enabled extensions */
- for (const struct TALER_Extension *extension = TALER_extensions_get_head ();
- NULL != extension;
- extension = extension->next)
+ for (const struct TALER_Extensions *iter = TALER_extensions_get_head ();
+ NULL != iter && NULL != iter->extension;
+ iter = iter->next)
{
- json_t *ext;
- json_t *config_json;
+ const struct TALER_Extension *extension = iter->extension;
+ json_t *manifest;
int r;
- /* skip if not configured == disabled */
- if (NULL == extension->config ||
- NULL == extension->config_json)
+ /* skip if not enabled */
+ if (! extension->enabled)
continue;
/* flag our findings so far */
has_extensions = true;
- GNUNET_assert (NULL != extension->config_json);
-
- config_json = json_copy (extension->config_json);
- GNUNET_assert (NULL != config_json);
- ext = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_bool ("critical",
- extension->critical),
- GNUNET_JSON_pack_string ("version",
- extension->version),
- GNUNET_JSON_pack_object_steal ("config",
- config_json)
- );
- GNUNET_assert (NULL != ext);
+ manifest = extension->manifest (extension);
+ GNUNET_assert (manifest);
r = json_object_set_new (
extensions,
extension->name,
- ext);
+ manifest);
GNUNET_assert (0 == r);
}
@@ -1917,18 +2531,22 @@ create_krd (struct TEH_KeyStateHandle *ksh,
json_t *sig;
int r;
- r = json_object_set (
+ r = json_object_set_new (
keys,
"extensions",
extensions);
GNUNET_assert (0 == r);
- sig = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("extensions_sig",
- &TEH_extensions_sig));
+ /* Add the signature of the extensions, if it is not zero */
+ if (TEH_extensions_signed)
+ {
+ sig = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("extensions_sig",
+ &TEH_extensions_sig));
- r = json_object_update (keys, sig);
- GNUNET_assert (0 == r);
+ r = json_object_update (keys, sig);
+ GNUNET_assert (0 == r);
+ }
}
else
{
@@ -1975,9 +2593,9 @@ create_krd (struct TEH_KeyStateHandle *ksh,
keys_json,
MHD_RESPMEM_MUST_FREE);
GNUNET_assert (NULL != krd.response_uncompressed);
- GNUNET_assert (GNUNET_OK ==
- setup_general_response_headers (ksh,
- krd.response_uncompressed));
+ setup_general_response_headers (ksh,
+ krd.response_uncompressed);
+ /* Information is always public, revalidate after 1 day */
GNUNET_break (MHD_YES ==
MHD_add_response_header (krd.response_uncompressed,
MHD_HTTP_HEADER_ETAG,
@@ -1997,16 +2615,16 @@ create_krd (struct TEH_KeyStateHandle *ksh,
MHD_add_response_header (krd.response_compressed,
MHD_HTTP_HEADER_CONTENT_ENCODING,
"deflate")) );
- GNUNET_assert (GNUNET_OK ==
- setup_general_response_headers (ksh,
- krd.response_compressed));
+ setup_general_response_headers (ksh,
+ krd.response_compressed);
+ /* Information is always public, revalidate after 1 day */
GNUNET_break (MHD_YES ==
MHD_add_response_header (krd.response_compressed,
MHD_HTTP_HEADER_ETAG,
etag));
krd.etag = GNUNET_strdup (etag);
}
- krd.cherry_pick_date = last_cpd;
+ krd.cherry_pick_date = last_cherry_pick_date;
GNUNET_array_append (ksh->krd_array,
ksh->krd_array_length,
krd);
@@ -2015,6 +2633,194 @@ create_krd (struct TEH_KeyStateHandle *ksh,
/**
+ * Element in the `struct SignatureContext` array.
+ */
+struct SignatureElement
+{
+
+ /**
+ * Offset of the denomination in the group array,
+ * for sorting (2nd rank, ascending).
+ */
+ unsigned int offset;
+
+ /**
+ * Offset of the group in the denominations array,
+ * for sorting (2nd rank, ascending).
+ */
+ unsigned int group_offset;
+
+ /**
+ * Pointer to actual master signature to hash over.
+ */
+ struct TALER_MasterSignatureP master_sig;
+};
+
+/**
+ * Context for collecting the array of master signatures
+ * needed to verify the exchange_sig online signature.
+ */
+struct SignatureContext
+{
+ /**
+ * Array of signatures to hash over.
+ */
+ struct SignatureElement *elements;
+
+ /**
+ * Write offset in the @e elements array.
+ */
+ unsigned int elements_pos;
+
+ /**
+ * Allocated space for @e elements.
+ */
+ unsigned int elements_size;
+};
+
+
+/**
+ * Determine order to sort two elements by before
+ * we hash the master signatures. Used for
+ * sorting with qsort().
+ *
+ * @param a pointer to a `struct SignatureElement`
+ * @param b pointer to a `struct SignatureElement`
+ * @return 0 if equal, -1 if a < b, 1 if a > b.
+ */
+static int
+signature_context_sort_cb (const void *a,
+ const void *b)
+{
+ const struct SignatureElement *sa = a;
+ const struct SignatureElement *sb = b;
+
+ if (sa->group_offset < sb->group_offset)
+ return -1;
+ if (sa->group_offset > sb->group_offset)
+ return 1;
+ if (sa->offset < sb->offset)
+ return -1;
+ if (sa->offset > sb->offset)
+ return 1;
+ /* We should never have two disjoint elements
+ with same time and offset */
+ GNUNET_assert (sa == sb);
+ return 0;
+}
+
+
+/**
+ * Append a @a master_sig to the @a sig_ctx using the
+ * given attributes for (later) sorting.
+ *
+ * @param[in,out] sig_ctx signature context to update
+ * @param group_offset offset for the group
+ * @param offset offset for the entry
+ * @param master_sig master signature for the entry
+ */
+static void
+append_signature (struct SignatureContext *sig_ctx,
+ unsigned int group_offset,
+ unsigned int offset,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct SignatureElement *element;
+ unsigned int new_size;
+
+ if (sig_ctx->elements_pos == sig_ctx->elements_size)
+ {
+ if (0 == sig_ctx->elements_size)
+ new_size = 1024;
+ else
+ new_size = sig_ctx->elements_size * 2;
+ GNUNET_array_grow (sig_ctx->elements,
+ sig_ctx->elements_size,
+ new_size);
+ }
+ element = &sig_ctx->elements[sig_ctx->elements_pos++];
+ element->offset = offset;
+ element->group_offset = group_offset;
+ element->master_sig = *master_sig;
+}
+
+
+/**
+ *GroupData is the value we store for each group meta-data */
+struct GroupData
+{
+ /**
+ * The json blob with the group meta-data and list of denominations
+ */
+ json_t *json;
+
+ /**
+ * List of denominations for the group,
+ * included in @e json, do not free separately!
+ */
+ json_t *list;
+
+ /**
+ * Offset of the group in the final array.
+ */
+ unsigned int group_off;
+
+};
+
+
+/**
+ * Helper function called to clean up the group data
+ * in the denominations_by_group below.
+ *
+ * @param cls unused
+ * @param key unused
+ * @param value a `struct GroupData` to free
+ * @return #GNUNET_OK
+ */
+static int
+free_group (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct GroupData *gd = value;
+
+ (void) cls;
+ (void) key;
+ GNUNET_free (gd);
+ return GNUNET_OK;
+}
+
+
+static void
+compute_msig_hash (struct SignatureContext *sig_ctx,
+ struct GNUNET_HashCode *hc)
+{
+ struct GNUNET_HashContext *hash_context;
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+ qsort (sig_ctx->elements,
+ sig_ctx->elements_pos,
+ sizeof (struct SignatureElement),
+ &signature_context_sort_cb);
+ for (unsigned int i = 0; i<sig_ctx->elements_pos; i++)
+ {
+ struct SignatureElement *element = &sig_ctx->elements[i];
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding %u,%u,%s\n",
+ element->group_offset,
+ element->offset,
+ TALER_B2S (&element->master_sig));
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ &element->master_sig,
+ sizeof (element->master_sig));
+ }
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ hc);
+}
+
+
+/**
* Update the "/keys" responses in @a ksh, computing the detailed replies.
*
* This function is to recompute all (including cherry-picked) responses we
@@ -2026,23 +2832,50 @@ create_krd (struct TEH_KeyStateHandle *ksh,
static enum GNUNET_GenericReturnValue
finish_keys_response (struct TEH_KeyStateHandle *ksh)
{
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
json_t *recoup;
- struct SignKeyCtx sctx;
- json_t *denoms = NULL;
+ struct SignKeyCtx sctx = {
+ .min_sk_frequency = GNUNET_TIME_UNIT_FOREVER_REL
+ };
json_t *grouped_denominations = NULL;
- struct GNUNET_TIME_Timestamp last_cpd;
+ struct GNUNET_TIME_Timestamp last_cherry_pick_date;
struct GNUNET_CONTAINER_Heap *heap;
- struct GNUNET_HashContext *hash_context = NULL;
- struct GNUNET_HashCode grouped_hash_xor = {0};
+ struct SignatureContext sig_ctx = { 0 };
+ /* Remember if we have any denomination with age restriction */
+ bool has_age_restricted_denomination = false;
+ struct WireStateHandle *wsh;
+ wsh = get_wire_state ();
+ if (! wsh->ready)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 ==
+ json_array_size (json_object_get (wsh->json_reply,
+ "accounts")) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No wire accounts available. Refusing to generate /keys response.\n");
+ return GNUNET_NO;
+ }
sctx.signkeys = json_array ();
GNUNET_assert (NULL != sctx.signkeys);
- sctx.min_sk_frequency = GNUNET_TIME_UNIT_FOREVER_REL;
+ recoup = json_array ();
+ GNUNET_assert (NULL != recoup);
+ grouped_denominations = json_array ();
+ GNUNET_assert (NULL != grouped_denominations);
+
GNUNET_CONTAINER_multipeermap_iterate (ksh->signkey_map,
&add_sign_key_cb,
&sctx);
- recoup = json_array ();
- GNUNET_assert (NULL != recoup);
+ if (0 == json_array_size (sctx.signkeys))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No online signing keys available. Refusing to generate /keys response.\n");
+ ret = GNUNET_NO;
+ goto CLEANUP;
+ }
heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
{
struct DenomKeyCtx dkc = {
@@ -2059,121 +2892,52 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
sctx.min_sk_frequency);
}
- denoms = json_array ();
- GNUNET_assert (NULL != denoms);
- hash_context = GNUNET_CRYPTO_hash_context_start ();
-
- grouped_denominations = json_array ();
- GNUNET_assert (NULL != grouped_denominations);
-
- last_cpd = GNUNET_TIME_UNIT_ZERO_TS;
+ last_cherry_pick_date = GNUNET_TIME_UNIT_ZERO_TS;
- // FIXME: This block contains the implementation of the DEPRICATED
- // "denom_pubs" array along with the new grouped "denominations".
- // "denom_pubs" Will be removed sooner or later.
{
struct TEH_DenominationKey *dk;
struct GNUNET_CONTAINER_MultiHashMap *denominations_by_group;
- /* groupData is the value we store for each group meta-data */
- struct groupData
- {
- /**
- * The json blob with the group meta-data and list of denominations
- */
- json_t *json;
-
- /**
- * xor of all hashes of denominations in that group
- */
- struct GNUNET_HashCode hash_xor;
- };
denominations_by_group =
GNUNET_CONTAINER_multihashmap_create (1024,
GNUNET_NO /* NO, because keys are only on the stack */);
-
-
- /* heap = min heap, sorted by start time */
+ /* heap = max heap, sorted by start time */
while (NULL != (dk = GNUNET_CONTAINER_heap_remove_root (heap)))
{
- if (GNUNET_TIME_timestamp_cmp (last_cpd,
+ if (GNUNET_TIME_timestamp_cmp (last_cherry_pick_date,
!=,
dk->meta.start) &&
- (! GNUNET_TIME_absolute_is_zero (last_cpd.abs_time)) )
+ (! GNUNET_TIME_absolute_is_zero (last_cherry_pick_date.abs_time)) )
{
/*
- * This is not the first entry in the heap (because last_cpd !=
+ * This is not the first entry in the heap (because last_cherry_pick_date !=
* GNUNET_TIME_UNIT_ZERO_TS) and the previous entry had a different
* start time. Therefore, we create a new entry in ksh.
*/
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash_context_finish (
- GNUNET_CRYPTO_hash_context_copy (hash_context),
- &hc);
-
+ compute_msig_hash (&sig_ctx,
+ &hc);
if (GNUNET_OK !=
create_krd (ksh,
&hc,
- last_cpd,
+ last_cherry_pick_date,
sctx.signkeys,
recoup,
- denoms,
- grouped_denominations,
- &grouped_hash_xor))
+ grouped_denominations))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to generate key response data for %s\n",
- GNUNET_TIME_timestamp2s (last_cpd));
- GNUNET_CRYPTO_hash_context_abort (hash_context);
+ GNUNET_TIME_timestamp2s (last_cherry_pick_date));
/* drain heap before destroying it */
while (NULL != (dk = GNUNET_CONTAINER_heap_remove_root (heap)))
/* intentionally empty */;
GNUNET_CONTAINER_heap_destroy (heap);
- json_decref (denoms);
- json_decref (grouped_denominations);
- json_decref (sctx.signkeys);
- json_decref (recoup);
- return GNUNET_SYSERR;
+ goto CLEANUP;
}
}
- last_cpd = dk->meta.start;
-
- {
- json_t *denom;
-
- denom =
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("master_sig",
- &dk->master_sig),
- GNUNET_JSON_pack_timestamp ("stamp_start",
- dk->meta.start),
- GNUNET_JSON_pack_timestamp ("stamp_expire_withdraw",
- dk->meta.expire_withdraw),
- GNUNET_JSON_pack_timestamp ("stamp_expire_deposit",
- dk->meta.expire_deposit),
- GNUNET_JSON_pack_timestamp ("stamp_expire_legal",
- dk->meta.expire_legal),
- TALER_JSON_pack_denom_pub ("denom_pub",
- &dk->denom_pub),
- TALER_JSON_pack_amount ("value",
- &dk->meta.value),
- TALER_JSON_PACK_DENOM_FEES ("fee",
- &dk->meta.fees));
-
- GNUNET_CRYPTO_hash_context_read (hash_context,
- &dk->h_denom_pub,
- sizeof (struct GNUNET_HashCode));
-
- GNUNET_assert (
- 0 ==
- json_array_append_new (
- denoms,
- denom));
-
- }
-
+ last_cherry_pick_date = dk->meta.start;
/*
* Group the denominations by {cipher, value, fees, age_mask}.
*
@@ -2182,69 +2946,70 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
* denominations_by_group.
*/
{
- static const char *denoms_key = "denoms";
- struct groupData *group;
- json_t *list;
+ struct GroupData *group;
json_t *entry;
struct GNUNET_HashCode key;
struct TALER_DenominationGroup meta = {
- .cipher = dk->denom_pub.cipher,
+ .cipher = dk->denom_pub.bsign_pub_key->cipher,
.value = dk->meta.value,
.fees = dk->meta.fees,
.age_mask = dk->meta.age_mask,
};
- memset (&meta.hash, 0, sizeof(meta.hash));
-
/* Search the group/JSON-blob for the key */
- GNUNET_CRYPTO_hash (&meta, sizeof(meta), &key);
-
- group =
- (struct groupData *) GNUNET_CONTAINER_multihashmap_get (
- denominations_by_group,
- &key);
-
+ TALER_denomination_group_get_key (&meta,
+ &key);
+ group = GNUNET_CONTAINER_multihashmap_get (
+ denominations_by_group,
+ &key);
if (NULL == group)
{
/* There is no group for this meta-data yet, so we create a new group */
bool age_restricted = meta.age_mask.bits != 0;
- char *cipher;
-
- group = GNUNET_new (struct groupData);
- memset (group, 0, sizeof(*group));
+ const char *cipher;
+ group = GNUNET_new (struct GroupData);
switch (meta.cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
cipher = age_restricted ? "RSA+age_restricted" : "RSA";
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
cipher = age_restricted ? "CS+age_restricted" : "CS";
break;
default:
GNUNET_assert (false);
}
-
+ /* Create a new array for the denominations in this group */
+ group->list = json_array ();
+ GNUNET_assert (NULL != group->list);
group->json = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("cipher", cipher),
- TALER_JSON_PACK_DENOM_FEES ("fee", &meta.fees),
- TALER_JSON_pack_amount ("value", &meta.value));
+ GNUNET_JSON_pack_string ("cipher",
+ cipher),
+ GNUNET_JSON_pack_array_steal ("denoms",
+ group->list),
+ TALER_JSON_PACK_DENOM_FEES ("fee",
+ &meta.fees),
+ TALER_JSON_pack_amount ("value",
+ &meta.value));
GNUNET_assert (NULL != group->json);
-
if (age_restricted)
{
- int r = json_object_set (group->json,
- "age_mask",
- json_integer (meta.age_mask.bits));
- GNUNET_assert (0 == r);
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (group->json,
+ "age_mask",
+ json_integer (
+ meta.age_mask.bits)));
+ /* Remember that we have found at least _one_ age restricted denomination */
+ has_age_restricted_denomination = true;
}
-
- /* Create a new array for the denominations in this group */
- list = json_array ();
- GNUNET_assert (NULL != list);
+ group->group_off
+ = json_array_size (grouped_denominations);
GNUNET_assert (0 ==
- json_object_set (group->json, denoms_key, list));
-
+ json_array_append_new (
+ grouped_denominations,
+ group->json));
GNUNET_assert (
GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (denominations_by_group,
@@ -2256,23 +3021,32 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
/* Now that we have found/created the right group, add the
denomination to the list */
{
+ struct HelperDenomination *hd;
struct GNUNET_JSON_PackSpec key_spec;
-
+ bool private_key_lost;
+
+ hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
+ &dk->h_denom_pub.hash);
+ private_key_lost
+ = (NULL == hd) ||
+ GNUNET_TIME_absolute_is_past (
+ GNUNET_TIME_absolute_add (
+ hd->start_time.abs_time,
+ hd->validity_duration));
switch (meta.cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
key_spec =
- GNUNET_JSON_pack_rsa_public_key ("rsa_pub",
- dk->denom_pub.details.
- rsa_public_key);
+ GNUNET_JSON_pack_rsa_public_key (
+ "rsa_pub",
+ dk->denom_pub.bsign_pub_key->details.rsa_public_key);
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
key_spec =
- GNUNET_JSON_pack_data_varsize ("cs_pub",
- &dk->denom_pub.details.
- cs_public_key,
- sizeof (dk->denom_pub.details.
- cs_public_key));
+ GNUNET_JSON_pack_data_varsize (
+ "cs_pub",
+ &dk->denom_pub.bsign_pub_key->details.cs_public_key,
+ sizeof (dk->denom_pub.bsign_pub_key->details.cs_public_key));
break;
default:
GNUNET_assert (false);
@@ -2281,6 +3055,12 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
entry = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("master_sig",
&dk->master_sig),
+ GNUNET_JSON_pack_allow_null (
+ private_key_lost
+ ? GNUNET_JSON_pack_bool ("lost",
+ true)
+ : GNUNET_JSON_pack_string ("dummy",
+ NULL)),
GNUNET_JSON_pack_timestamp ("stamp_start",
dk->meta.start),
GNUNET_JSON_pack_timestamp ("stamp_expire_withdraw",
@@ -2294,104 +3074,80 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
GNUNET_assert (NULL != entry);
}
- /* Build up the running xor of all hashes of the denominations in this
- group */
- GNUNET_CRYPTO_hash_xor (&dk->h_denom_pub.hash,
- &group->hash_xor,
- &group->hash_xor);
-
+ /* Build up the running hash of all master signatures of the
+ denominations */
+ append_signature (&sig_ctx,
+ group->group_off,
+ (unsigned int) json_array_size (group->list),
+ &dk->master_sig);
/* Finally, add the denomination to the list of denominations in this
group */
- list = json_object_get (group->json, denoms_key);
- GNUNET_assert (NULL != list);
- GNUNET_assert (true == json_is_array (list));
+ GNUNET_assert (json_is_array (group->list));
GNUNET_assert (0 ==
- json_array_append_new (list, entry));
+ json_array_append_new (group->list,
+ entry));
}
} /* loop over heap ends */
- /* Create the JSON-array of grouped denominations */
- if (0 <
- GNUNET_CONTAINER_multihashmap_size (denominations_by_group))
- {
- struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
- struct groupData *group = NULL;
-
- iter =
- GNUNET_CONTAINER_multihashmap_iterator_create (denominations_by_group);
-
- while (GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap_iterator_next (iter,
- NULL,
- (const
- void **) &group))
- {
- /* Add the XOR over all hashes of denominations in this group to the group */
- GNUNET_assert (0 ==
- json_object_set (
- group->json,
- "hash",
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto (NULL,
- &group->hash_xor))));
-
- /* Add this group to the array */
- GNUNET_assert (0 ==
- json_array_append_new (
- grouped_denominations,
- group->json));
-
- /* Build the running XOR over all hash(_xor) */
- GNUNET_CRYPTO_hash_xor (&group->hash_xor,
- &grouped_hash_xor,
- &grouped_hash_xor);
-
- GNUNET_free (group);
- }
-
- GNUNET_CONTAINER_multihashmap_iterator_destroy (iter);
- GNUNET_CONTAINER_multihashmap_destroy (denominations_by_group);
-
- }
+ GNUNET_CONTAINER_multihashmap_iterate (denominations_by_group,
+ &free_group,
+ NULL);
+ GNUNET_CONTAINER_multihashmap_destroy (denominations_by_group);
}
-
GNUNET_CONTAINER_heap_destroy (heap);
- if (! GNUNET_TIME_absolute_is_zero (last_cpd.abs_time))
+
+ if (! GNUNET_TIME_absolute_is_zero (last_cherry_pick_date.abs_time))
{
struct GNUNET_HashCode hc;
- GNUNET_CRYPTO_hash_context_finish (hash_context,
- &hc);
+ compute_msig_hash (&sig_ctx,
+ &hc);
if (GNUNET_OK !=
create_krd (ksh,
&hc,
- last_cpd,
+ last_cherry_pick_date,
sctx.signkeys,
recoup,
- denoms,
- grouped_denominations,
- &grouped_hash_xor))
+ grouped_denominations))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to generate key response data for %s\n",
- GNUNET_TIME_timestamp2s (last_cpd));
- json_decref (denoms);
- json_decref (sctx.signkeys);
- json_decref (recoup);
- return GNUNET_SYSERR;
+ GNUNET_TIME_timestamp2s (last_cherry_pick_date));
+ goto CLEANUP;
}
ksh->management_only = false;
+
+ /* Sanity check: Make sure that age restriction is enabled IFF at least
+ * one age restricted denomination exist */
+ if (! has_age_restricted_denomination && TEH_age_restriction_enabled)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Age restriction is enabled, but NO denominations with age restriction found!\n");
+ goto CLEANUP;
+ }
+ else if (has_age_restricted_denomination && ! TEH_age_restriction_enabled)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Age restriction is NOT enabled, but denominations with age restriction found!\n");
+ goto CLEANUP;
+ }
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"No denomination keys available. Refusing to generate /keys response.\n");
- GNUNET_CRYPTO_hash_context_abort (hash_context);
}
- json_decref (sctx.signkeys);
+ ret = GNUNET_OK;
+
+CLEANUP:
+ GNUNET_array_grow (sig_ctx.elements,
+ sig_ctx.elements_size,
+ 0);
+ json_decref (grouped_denominations);
+ if (NULL != sctx.signkeys)
+ json_decref (sctx.signkeys);
json_decref (recoup);
- json_decref (denoms);
- return GNUNET_OK;
+ return ret;
}
@@ -2401,7 +3157,6 @@ finish_keys_response (struct TEH_KeyStateHandle *ksh)
* @param cls `struct TEH_KeyStateHandle *` we are building
* @param fees the global fees we charge
* @param purse_timeout when do purses time out
- * @param kyc_timeout when do reserves without KYC time out
* @param history_expiration how long are account histories preserved
* @param purse_account_limit how many purses are free per account
* @param start_date from when are these fees valid (start date)
@@ -2414,7 +3169,6 @@ global_fee_info_cb (
void *cls,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
struct GNUNET_TIME_Timestamp start_date,
@@ -2424,6 +3178,21 @@ global_fee_info_cb (
struct TEH_KeyStateHandle *ksh = cls;
struct TEH_GlobalFee *gf;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_global_fee_verify (
+ start_date,
+ end_date,
+ fees,
+ purse_timeout,
+ history_expiration,
+ purse_account_limit,
+ &TEH_master_public_key,
+ master_sig))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database has global fee with invalid signature. Skipping entry. Did the exchange offline public key change?\n");
+ return;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Found global fees with %u purses\n",
purse_account_limit);
@@ -2432,7 +3201,6 @@ global_fee_info_cb (
gf->end_date = end_date;
gf->fees = *fees;
gf->purse_timeout = purse_timeout;
- gf->kyc_timeout = kyc_timeout;
gf->history_expiration = history_expiration;
gf->purse_account_limit = purse_account_limit;
gf->master_sig = *master_sig;
@@ -2451,8 +3219,6 @@ global_fee_info_cb (
TALER_JSON_PACK_GLOBAL_FEES (fees),
GNUNET_JSON_pack_time_rel ("history_expiration",
history_expiration),
- GNUNET_JSON_pack_time_rel ("account_kyc_timeout",
- kyc_timeout),
GNUNET_JSON_pack_time_rel ("purse_timeout",
purse_timeout),
GNUNET_JSON_pack_uint64 ("purse_account_limit",
@@ -2499,9 +3265,9 @@ build_key_state (struct HelperState *hs,
ksh->helpers = hs;
}
ksh->denomkey_map = GNUNET_CONTAINER_multihashmap_create (1024,
- GNUNET_YES);
+ true);
ksh->signkey_map = GNUNET_CONTAINER_multipeermap_create (32,
- GNUNET_NO /* MUST be NO! */);
+ false /* MUST be false! */);
ksh->auditors = json_array ();
GNUNET_assert (NULL != ksh->auditors);
/* NOTE: fetches master-signed signkeys, but ALSO those that were revoked! */
@@ -2577,7 +3343,7 @@ build_key_state (struct HelperState *hs,
finish_keys_response (ksh))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Could not finish /keys response (likely no signing keys available yet)\n");
+ "Could not finish /keys response (required data not configured yet)\n");
destroy_key_state (ksh,
true);
return NULL;
@@ -2604,8 +3370,8 @@ TEH_keys_update_states ()
}
-struct TEH_KeyStateHandle *
-TEH_keys_get_state2 (bool management_only)
+static struct TEH_KeyStateHandle *
+keys_get_state (bool management_only)
{
struct TEH_KeyStateHandle *old_ksh;
struct TEH_KeyStateHandle *ksh;
@@ -2623,7 +3389,7 @@ TEH_keys_get_state2 (bool management_only)
if ( (old_ksh->key_generation < key_generation) ||
(GNUNET_TIME_absolute_is_past (old_ksh->signature_expires.abs_time)) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Rebuilding /keys, generation upgrade from %llu to %llu\n",
(unsigned long long) old_ksh->key_generation,
(unsigned long long) key_generation);
@@ -2641,19 +3407,28 @@ TEH_keys_get_state2 (bool management_only)
struct TEH_KeyStateHandle *
+TEH_keys_get_state_for_management_only (void)
+{
+ return keys_get_state (true);
+}
+
+
+struct TEH_KeyStateHandle *
TEH_keys_get_state (void)
{
struct TEH_KeyStateHandle *ksh;
- ksh = TEH_keys_get_state2 (false);
+ ksh = keys_get_state (false);
if (NULL == ksh)
return NULL;
+
if (ksh->management_only)
{
if (GNUNET_OK !=
finish_keys_response (ksh))
return NULL;
}
+
return ksh;
}
@@ -2696,16 +3471,17 @@ TEH_keys_denomination_by_hash (
NULL);
return NULL;
}
- return TEH_keys_denomination_by_hash2 (ksh,
- h_denom_pub,
- conn,
- mret);
+
+ return TEH_keys_denomination_by_hash_from_state (ksh,
+ h_denom_pub,
+ conn,
+ mret);
}
struct TEH_DenominationKey *
-TEH_keys_denomination_by_hash2 (
- struct TEH_KeyStateHandle *ksh,
+TEH_keys_denomination_by_hash_from_state (
+ const struct TEH_KeyStateHandle *ksh,
const struct TALER_DenominationHashP *h_denom_pub,
struct MHD_Connection *conn,
MHD_RESULT *mret)
@@ -2727,105 +3503,137 @@ TEH_keys_denomination_by_hash2 (
enum TALER_ErrorCode
-TEH_keys_denomination_sign_withdraw (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_BlindedPlanchet *bp,
- struct TALER_BlindedDenominationSignature *bs)
+TEH_keys_denomination_batch_sign (
+ unsigned int csds_length,
+ const struct TEH_CoinSignData csds[static csds_length],
+ bool for_melt,
+ struct TALER_BlindedDenominationSignature bss[static csds_length])
{
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
+ struct TALER_CRYPTO_RsaSignRequest rsrs[csds_length];
+ struct TALER_CRYPTO_CsSignRequest csrs[csds_length];
+ struct TALER_BlindedDenominationSignature rs[csds_length];
+ struct TALER_BlindedDenominationSignature cs[csds_length];
+ unsigned int rsrs_pos = 0;
+ unsigned int csrs_pos = 0;
+ enum TALER_ErrorCode ec;
ksh = TEH_keys_get_state ();
if (NULL == ksh)
return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
- hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
- &h_denom_pub->hash);
- if (NULL == hd)
- return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
- if (bp->cipher != hd->denom_pub.cipher)
- return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
- switch (hd->denom_pub.cipher)
+ for (unsigned int i = 0; i<csds_length; i++)
{
- case TALER_DENOMINATION_RSA:
- TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA]++;
+ const struct TALER_DenominationHashP *h_denom_pub = csds[i].h_denom_pub;
+ const struct TALER_BlindedPlanchet *bp = csds[i].bp;
+
+ hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
+ &h_denom_pub->hash);
+ if (NULL == hd)
+ return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
+ if (bp->blinded_message->cipher !=
+ hd->denom_pub.bsign_pub_key->cipher)
+ return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
+ switch (hd->denom_pub.bsign_pub_key->cipher)
{
- struct TALER_CRYPTO_RsaSignRequest rsr = {
- .h_rsa = &hd->h_details.h_rsa,
- .msg = bp->details.rsa_blinded_planchet.blinded_msg,
- .msg_size = bp->details.rsa_blinded_planchet.blinded_msg_size
- };
-
- return TALER_CRYPTO_helper_rsa_sign (
- ksh->helpers->rsadh,
- &rsr,
- bs);
+ case GNUNET_CRYPTO_BSA_RSA:
+ rsrs[rsrs_pos].h_rsa = &hd->h_details.h_rsa;
+ rsrs[rsrs_pos].msg
+ = bp->blinded_message->details.rsa_blinded_message.blinded_msg;
+ rsrs[rsrs_pos].msg_size
+ = bp->blinded_message->details.rsa_blinded_message.blinded_msg_size;
+ rsrs_pos++;
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ csrs[csrs_pos].h_cs = &hd->h_details.h_cs;
+ csrs[csrs_pos].blinded_planchet
+ = &bp->blinded_message->details.cs_blinded_message;
+ csrs_pos++;
+ break;
+ default:
+ return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
- case TALER_DENOMINATION_CS:
- TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS]++;
- return TALER_CRYPTO_helper_cs_sign_withdraw (
- ksh->helpers->csdh,
- &hd->h_details.h_cs,
- &bp->details.cs_blinded_planchet,
- bs);
- default:
- return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
-}
-
-enum TALER_ErrorCode
-TEH_keys_denomination_sign_melt (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_BlindedPlanchet *bp,
- struct TALER_BlindedDenominationSignature *bs)
-{
- struct TEH_KeyStateHandle *ksh;
- struct HelperDenomination *hd;
+ if ( (0 != csrs_pos) &&
+ (0 != rsrs_pos) )
+ {
+ memset (rs,
+ 0,
+ sizeof (rs));
+ memset (cs,
+ 0,
+ sizeof (cs));
+ }
+ ec = TALER_EC_NONE;
+ if (0 != csrs_pos)
+ {
+ ec = TALER_CRYPTO_helper_cs_batch_sign (
+ ksh->helpers->csdh,
+ csrs_pos,
+ csrs,
+ for_melt,
+ (0 == rsrs_pos) ? bss : cs);
+ if (TALER_EC_NONE != ec)
+ {
+ for (unsigned int i = 0; i<csrs_pos; i++)
+ TALER_blinded_denom_sig_free (&cs[i]);
+ return ec;
+ }
+ TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS] += csrs_pos;
+ }
+ if (0 != rsrs_pos)
+ {
+ ec = TALER_CRYPTO_helper_rsa_batch_sign (
+ ksh->helpers->rsadh,
+ rsrs_pos,
+ rsrs,
+ (0 == csrs_pos) ? bss : rs);
+ if (TALER_EC_NONE != ec)
+ {
+ for (unsigned int i = 0; i<csrs_pos; i++)
+ TALER_blinded_denom_sig_free (&cs[i]);
+ for (unsigned int i = 0; i<rsrs_pos; i++)
+ TALER_blinded_denom_sig_free (&rs[i]);
+ return ec;
+ }
+ TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA] += rsrs_pos;
+ }
- ksh = TEH_keys_get_state ();
- if (NULL == ksh)
- return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
- hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
- &h_denom_pub->hash);
- if (NULL == hd)
- return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
- if (bp->cipher != hd->denom_pub.cipher)
- return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
- switch (hd->denom_pub.cipher)
+ if ( (0 != csrs_pos) &&
+ (0 != rsrs_pos) )
{
- case TALER_DENOMINATION_RSA:
- TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_RSA]++;
+ rsrs_pos = 0;
+ csrs_pos = 0;
+ for (unsigned int i = 0; i<csds_length; i++)
{
- struct TALER_CRYPTO_RsaSignRequest rsr = {
- .h_rsa = &hd->h_details.h_rsa,
- .msg = bp->details.rsa_blinded_planchet.blinded_msg,
- .msg_size = bp->details.rsa_blinded_planchet.blinded_msg_size
- };
-
- return TALER_CRYPTO_helper_rsa_sign (
- ksh->helpers->rsadh,
- &rsr,
- bs);
+ const struct TALER_BlindedPlanchet *bp = csds[i].bp;
+
+ switch (bp->blinded_message->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ bss[i] = rs[rsrs_pos++];
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ bss[i] = cs[csrs_pos++];
+ break;
+ default:
+ GNUNET_assert (0);
+ }
}
- case TALER_DENOMINATION_CS:
- TEH_METRICS_num_signatures[TEH_MT_SIGNATURE_CS]++;
- return TALER_CRYPTO_helper_cs_sign_melt (
- ksh->helpers->csdh,
- &hd->h_details.h_cs,
- &bp->details.cs_blinded_planchet,
- bs);
- default:
- return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
+ return TALER_EC_NONE;
}
enum TALER_ErrorCode
-TEH_keys_denomination_cs_r_pub_melt (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *r_pub)
+TEH_keys_denomination_cs_r_pub (
+ const struct TEH_CsDeriveData *cdd,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP *r_pub)
{
+ const struct TALER_DenominationHashP *h_denom_pub = cdd->h_denom_pub;
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce = cdd->nonce;
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
@@ -2840,47 +3648,66 @@ TEH_keys_denomination_cs_r_pub_melt (
{
return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
}
- if (TALER_DENOMINATION_CS != hd->denom_pub.cipher)
+ if (GNUNET_CRYPTO_BSA_CS !=
+ hd->denom_pub.bsign_pub_key->cipher)
{
return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
}
- return TALER_CRYPTO_helper_cs_r_derive_melt (ksh->helpers->csdh,
- &hd->h_details.h_cs,
- nonce,
- r_pub);
+ {
+ struct TALER_CRYPTO_CsDeriveRequest cdr = {
+ .h_cs = &hd->h_details.h_cs,
+ .nonce = nonce
+ };
+ return TALER_CRYPTO_helper_cs_r_derive (ksh->helpers->csdh,
+ &cdr,
+ for_melt,
+ r_pub);
+ }
}
enum TALER_ErrorCode
-TEH_keys_denomination_cs_r_pub_withdraw (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *r_pub)
+TEH_keys_denomination_cs_batch_r_pub (
+ unsigned int cdds_length,
+ const struct TEH_CsDeriveData cdds[static cdds_length],
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP r_pubs[static cdds_length])
{
struct TEH_KeyStateHandle *ksh;
struct HelperDenomination *hd;
+ struct TALER_CRYPTO_CsDeriveRequest cdrs[cdds_length];
ksh = TEH_keys_get_state ();
if (NULL == ksh)
{
return TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING;
}
- hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
- &h_denom_pub->hash);
- if (NULL == hd)
+ for (unsigned int i = 0; i<cdds_length; i++)
{
- return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
- }
- if (TALER_DENOMINATION_CS != hd->denom_pub.cipher)
- {
- return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
+ const struct TALER_DenominationHashP *h_denom_pub = cdds[i].h_denom_pub;
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce = cdds[i].nonce;
+
+ hd = GNUNET_CONTAINER_multihashmap_get (ksh->helpers->denom_keys,
+ &h_denom_pub->hash);
+ if (NULL == hd)
+ {
+ return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
+ }
+ if (GNUNET_CRYPTO_BSA_CS !=
+ hd->denom_pub.bsign_pub_key->cipher)
+ {
+ return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
+ }
+ cdrs[i].h_cs = &hd->h_details.h_cs;
+ cdrs[i].nonce = nonce;
}
- return TALER_CRYPTO_helper_cs_r_derive_withdraw (ksh->helpers->csdh,
- &hd->h_details.h_cs,
- nonce,
- r_pub);
+ return TALER_CRYPTO_helper_cs_r_batch_derive (ksh->helpers->csdh,
+ cdds_length,
+ cdrs,
+ for_melt,
+ r_pubs);
}
@@ -2903,22 +3730,23 @@ TEH_keys_denomination_revoke (const struct TALER_DenominationHashP *h_denom_pub)
GNUNET_break (0);
return;
}
- switch (hd->denom_pub.cipher)
+ switch (hd->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
TALER_CRYPTO_helper_rsa_revoke (ksh->helpers->rsadh,
&hd->h_details.h_rsa);
TEH_keys_update_states ();
return;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TALER_CRYPTO_helper_cs_revoke (ksh->helpers->csdh,
&hd->h_details.h_cs);
TEH_keys_update_states ();
return;
- default:
- GNUNET_break (0);
- return;
}
+ GNUNET_break (0);
+ return;
}
@@ -3083,7 +3911,8 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
const struct KeysResponseData *krd;
ksh = TEH_keys_get_state ();
- if (NULL == ksh)
+ if ( (NULL == ksh) ||
+ (0 == ksh->krd_array_length) )
{
if ( ( (SKR_LIMIT == skr_size) &&
(rc->connection == skr_connection) ) ||
@@ -3127,28 +3956,11 @@ TEH_keys_get_handler (struct TEH_RequestContext *rc,
if ( (NULL != etag) &&
(0 == strcmp (etag,
krd->etag)) )
- {
- MHD_RESULT ret;
- struct MHD_Response *resp;
-
- resp = MHD_create_response_from_buffer (0,
- NULL,
- MHD_RESPMEM_PERSISTENT);
- TALER_MHD_add_global_headers (resp);
- GNUNET_break (GNUNET_OK ==
- setup_general_response_headers (ksh,
- resp));
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
- MHD_HTTP_HEADER_ETAG,
- krd->etag));
- ret = MHD_queue_response (rc->connection,
- MHD_HTTP_NOT_MODIFIED,
- resp);
- GNUNET_break (MHD_YES == ret);
- MHD_destroy_response (resp);
- return ret;
- }
+ return TEH_RESPONSE_reply_not_modified (rc->connection,
+ krd->etag,
+ &setup_general_response_headers,
+ ksh);
+
return MHD_queue_response (rc->connection,
MHD_HTTP_OK,
(MHD_YES ==
@@ -3264,9 +4076,10 @@ TEH_keys_load_fees (struct TEH_KeyStateHandle *ksh,
meta);
if (GNUNET_OK == ok)
{
- GNUNET_assert (TALER_DENOMINATION_INVALID != hd->denom_pub.cipher);
- TALER_denom_pub_deep_copy (denom_pub,
- &hd->denom_pub);
+ GNUNET_assert (GNUNET_CRYPTO_BSA_INVALID !=
+ hd->denom_pub.bsign_pub_key->cipher);
+ TALER_denom_pub_copy (denom_pub,
+ &hd->denom_pub);
}
else
{
@@ -3289,7 +4102,7 @@ TEH_keys_get_timing (const struct TALER_ExchangePublicKeyP *exchange_pub,
struct HelperSignkey *hsk;
struct GNUNET_PeerIdentity pid;
- ksh = TEH_keys_get_state2 (true);
+ ksh = TEH_keys_get_state_for_management_only ();
if (NULL == ksh)
{
GNUNET_break (0);
@@ -3299,6 +4112,11 @@ TEH_keys_get_timing (const struct TALER_ExchangePublicKeyP *exchange_pub,
pid.public_key = exchange_pub->eddsa_pub;
hsk = GNUNET_CONTAINER_multipeermap_get (ksh->helpers->esign_keys,
&pid);
+ if (NULL == hsk)
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
meta->start = hsk->start_time;
meta->expire_sign = GNUNET_TIME_absolute_to_timestamp (
@@ -3459,7 +4277,7 @@ TEH_keys_management_get_keys_handler (const struct TEH_RequestHandler *rh,
json_t *reply;
(void) rh;
- ksh = TEH_keys_get_state2 (true);
+ ksh = TEH_keys_get_state_for_management_only ();
if (NULL == ksh)
{
return TALER_MHD_reply_with_error (connection,
@@ -3479,6 +4297,7 @@ TEH_keys_management_get_keys_handler (const struct TEH_RequestHandler *rh,
if ( (GNUNET_is_zero (&denom_rsa_sm_pub)) &&
(GNUNET_is_zero (&denom_cs_sm_pub)) )
{
+ /* Either IPC failed, or neither helper had any denominations configured. */
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_GATEWAY,
TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE,
@@ -3491,7 +4310,6 @@ TEH_keys_management_get_keys_handler (const struct TEH_RequestHandler *rh,
TALER_EC_EXCHANGE_SIGNKEY_HELPER_UNAVAILABLE,
NULL);
}
- // then a secmod helper is not yet running and we should return an MHD_HTTP_BAD_GATEWAY!
GNUNET_assert (NULL != fbc.denoms);
GNUNET_assert (NULL != fbc.signkeys);
GNUNET_CONTAINER_multihashmap_iterate (ksh->helpers->denom_keys,
diff --git a/src/exchange/taler-exchange-httpd_keys.h b/src/exchange/taler-exchange-httpd_keys.h
index 6d0cb5b5a..e526385ff 100644
--- a/src/exchange/taler-exchange-httpd_keys.h
+++ b/src/exchange/taler-exchange-httpd_keys.h
@@ -113,11 +113,6 @@ struct TEH_GlobalFee
struct GNUNET_TIME_Relative purse_timeout;
/**
- * How long do we keep accounts without KYC?
- */
- struct GNUNET_TIME_Relative kyc_timeout;
-
- /**
* What is the longest history we return?
*/
struct GNUNET_TIME_Relative history_expiration;
@@ -159,6 +154,48 @@ struct TEH_KeyStateHandle;
void
TEH_check_invariants (void);
+/**
+ * Clean up wire subsystem.
+ */
+void
+TEH_wire_done (void);
+
+
+/**
+ * Look up wire fee structure by @a ts.
+ *
+ * @param ts timestamp to lookup wire fees at
+ * @param method wire method to lookup fees for
+ * @return the wire fee details, or
+ * NULL if none are configured for @a ts and @a method
+ */
+const struct TALER_WireFeeSet *
+TEH_wire_fees_by_time (
+ struct GNUNET_TIME_Timestamp ts,
+ const char *method);
+
+
+/**
+ * Initialize wire subsystem.
+ *
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_wire_init (void);
+
+
+/**
+ * Something changed in the database. Rebuild the wire replies. This function
+ * should be called if the exchange learns about a new signature from our
+ * master key.
+ *
+ * (We do not do so immediately, but merely signal to all threads that they
+ * need to rebuild their wire state upon the next call to
+ * #TEH_keys_get_state()).
+ */
+void
+TEH_wire_update_state (void);
+
/**
* Return the current key state for this thread. Possibly re-builds the key
@@ -173,18 +210,12 @@ TEH_check_invariants (void);
struct TEH_KeyStateHandle *
TEH_keys_get_state (void);
-
/**
- * Obtain the key state. Should ONLY be used
- * directly if @a management_only is true. Otherwise use #TEH_keys_get_state().
- *
- * @param management_only if we should NOT run finish_keys_response()
- * because we only need the state for the /management/keys API
- * @return NULL on error
+ * Obtain the key state if we should NOT run finish_keys_response() because we
+ * only need the state for the /management/keys API
*/
struct TEH_KeyStateHandle *
-TEH_keys_get_state2 (bool management_only);
-
+TEH_keys_get_state_for_management_only (void);
/**
* Something changed in the database. Rebuild all key states. This function
@@ -245,75 +276,94 @@ TEH_keys_denomination_by_hash (
* or NULL if @a h_denom_pub could not be found
*/
struct TEH_DenominationKey *
-TEH_keys_denomination_by_hash2 (
- struct TEH_KeyStateHandle *ksh,
+TEH_keys_denomination_by_hash_from_state (
+ const struct TEH_KeyStateHandle *ksh,
const struct TALER_DenominationHashP *h_denom_pub,
struct MHD_Connection *conn,
MHD_RESULT *mret);
+/**
+ * Information needed to create a blind signature.
+ */
+struct TEH_CoinSignData
+{
+ /**
+ * Hash of key to sign with.
+ */
+ const struct TALER_DenominationHashP *h_denom_pub;
+
+ /**
+ * Blinded planchet to sign over.
+ */
+ const struct TALER_BlindedPlanchet *bp;
+};
+
/**
- * Request to sign @a msg using the public key corresponding to
- * @a h_denom_pub during a withdraw operation.
+ * Request to sign @a csds.
*
- * @param h_denom_pub hash of the public key to use to sign
- * @param bp blinded planchet to sign
- * @param[out] bs set to the blind signature on success
+ * @param csds array with data to blindly sign (and keys to sign with)
+ * @param csds_length length of @a csds array
+ * @param for_melt true if this is for a melt operation
+ * @param[out] bss array set to the blind signature on success; must be of length @a csds_length
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
-TEH_keys_denomination_sign_withdraw (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_BlindedPlanchet *bp,
- struct TALER_BlindedDenominationSignature *bs);
+TEH_keys_denomination_batch_sign (
+ unsigned int csds_length,
+ const struct TEH_CoinSignData csds[static csds_length],
+ bool for_melt,
+ struct TALER_BlindedDenominationSignature bss[static csds_length]);
/**
- * Request to sign @a msg using the public key corresponding to
- * @a h_denom_pub during a refresh operation.
- *
- * @param h_denom_pub hash of the public key to use to sign
- * @param bp blinded planchet to sign
- * @param[out] bs set to the blind signature on success
- * @return #TALER_EC_NONE on success
+ * Information needed to derive the CS r_pub.
*/
-enum TALER_ErrorCode
-TEH_keys_denomination_sign_melt (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_BlindedPlanchet *bp,
- struct TALER_BlindedDenominationSignature *bs);
+struct TEH_CsDeriveData
+{
+ /**
+ * Hash of key to sign with.
+ */
+ const struct TALER_DenominationHashP *h_denom_pub;
+
+ /**
+ * Nonce to use.
+ */
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce;
+};
/**
- * Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub
- * and @a nonce for withdrawing.
+ * Request to derive CS @a r_pub using the denomination and nonce from @a cdd.
*
- * @param h_denom_pub hash of the public key to use to derive r_pub
- * @param nonce withdraw/refresh nonce
+ * @param cdd data to compute @a r_pub from
+ * @param for_melt true if this is for a melt operation
* @param[out] r_pub where to write the result
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
-TEH_keys_denomination_cs_r_pub_withdraw (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *r_pub);
+TEH_keys_denomination_cs_r_pub (
+ const struct TEH_CsDeriveData *cdd,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP *r_pub);
/**
- * Request to derive CS @a r_pub using the denomination corresponding to @a h_denom_pub
- * and @a nonce for melting.
+ * Request to derive a bunch of CS @a r_pubs using the
+ * denominations and nonces from @a cdds.
*
- * @param h_denom_pub hash of the public key to use to derive r_pub
- * @param nonce withdraw/refresh nonce
- * @param[out] r_pub where to write the result
+ * @param cdds array to compute @a r_pubs from
+ * @param cdds_length length of the @a cdds array
+ * @param for_melt true if this is for a melt operation
+ * @param[out] r_pubs array where to write the result; must be of length @a cdds_length
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
-TEH_keys_denomination_cs_r_pub_melt (
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *r_pub);
+TEH_keys_denomination_cs_batch_r_pub (
+ unsigned int cdds_length,
+ const struct TEH_CsDeriveData cdds[static cdds_length],
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP r_pubs[static cdds_length]);
/**
@@ -340,7 +390,7 @@ TEH_keys_finished (void);
/**
- * Resumse all suspended /keys requests, we may now have key material
+ * Resumes all suspended /keys requests, we may now have key material
* (or are shutting down).
*
* @param do_shutdown are we shutting down?
diff --git a/src/exchange/taler-exchange-httpd_kyc-check.c b/src/exchange/taler-exchange-httpd_kyc-check.c
index 4a96d4c81..362c20a2e 100644
--- a/src/exchange/taler-exchange-httpd_kyc-check.c
+++ b/src/exchange/taler-exchange-httpd_kyc-check.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -25,6 +25,7 @@
#include <microhttpd.h>
#include <pthread.h>
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_mhd_lib.h"
#include "taler_signatures.h"
#include "taler_dbevents.h"
@@ -54,20 +55,31 @@ struct KycPoller
struct MHD_Connection *connection;
/**
+ * Logic for @e ih
+ */
+ struct TALER_KYCLOGIC_Plugin *ih_logic;
+
+ /**
+ * Handle to asynchronously running KYC initiation
+ * request.
+ */
+ struct TALER_KYCLOGIC_InitiateHandle *ih;
+
+ /**
* Subscription for the database event we are
* waiting for.
*/
struct GNUNET_DB_EventHandler *eh;
/**
- * UUID being checked.
+ * Row of the requirement being checked.
*/
- uint64_t auth_payment_target_uuid;
+ uint64_t requirement_row;
/**
- * Current KYC status.
+ * Row of KYC process being initiated.
*/
- struct TALER_EXCHANGEDB_KycStatus kyc;
+ uint64_t process_row;
/**
* Hash of the payto:// URI we are confirming to
@@ -76,20 +88,60 @@ struct KycPoller
struct TALER_PaytoHashP h_payto;
/**
- * Payto URL as a string, as given to us by t
+ * When will this request time out?
*/
- const char *hps;
+ struct GNUNET_TIME_Absolute timeout;
/**
- * When will this request time out?
+ * If the KYC complete, what kind of data was collected?
*/
- struct GNUNET_TIME_Absolute timeout;
+ json_t *kyc_details;
+
+ /**
+ * Set to starting URL of KYC process if KYC is required.
+ */
+ char *kyc_url;
+
+ /**
+ * Set to error details, on error (@ec not TALER_EC_NONE).
+ */
+ char *hint;
+
+ /**
+ * Name of the section of the provider in the configuration.
+ */
+ const char *section_name;
+
+ /**
+ * Set to AML status of the account.
+ */
+ enum TALER_AmlDecisionState aml_status;
+
+ /**
+ * Set to error encountered with KYC logic, if any.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * What kind of entity is doing the KYC check?
+ */
+ enum TALER_KYCLOGIC_KycUserType ut;
/**
* True if we are still suspended.
*/
bool suspended;
+ /**
+ * False if KYC is not required.
+ */
+ bool kyc_required;
+
+ /**
+ * True if we once tried the KYC initiation.
+ */
+ bool ih_done;
+
};
@@ -114,6 +166,11 @@ TEH_kyc_check_cleanup ()
GNUNET_CONTAINER_DLL_remove (kyp_head,
kyp_tail,
kyp);
+ if (NULL != kyp->ih)
+ {
+ kyp->ih_logic->initiate_cancel (kyp->ih);
+ kyp->ih = NULL;
+ }
if (kyp->suspended)
{
kyp->suspended = false;
@@ -143,11 +200,86 @@ kyp_cleanup (struct TEH_RequestContext *rc)
kyp->eh);
kyp->eh = NULL;
}
+ if (NULL != kyp->ih)
+ {
+ kyp->ih_logic->initiate_cancel (kyp->ih);
+ kyp->ih = NULL;
+ }
+ json_decref (kyp->kyc_details);
+ GNUNET_free (kyp->kyc_url);
+ GNUNET_free (kyp->hint);
GNUNET_free (kyp);
}
/**
+ * Function called with the result of a KYC initiation
+ * operation.
+ *
+ * @param cls closure with our `struct KycPoller *`
+ * @param ec #TALER_EC_NONE on success
+ * @param redirect_url set to where to redirect the user on success, NULL on failure
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param error_msg_hint set to additional details to return to user, NULL on success
+ */
+static void
+initiate_cb (
+ void *cls,
+ enum TALER_ErrorCode ec,
+ const char *redirect_url,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ const char *error_msg_hint)
+{
+ struct KycPoller *kyp = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ kyp->ih = NULL;
+ kyp->ih_done = true;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC initiation `%s' completed with ec=%d (%s)\n",
+ provider_legitimization_id,
+ ec,
+ (TALER_EC_NONE == ec)
+ ? redirect_url
+ : error_msg_hint);
+ kyp->ec = ec;
+ if (TALER_EC_NONE == ec)
+ {
+ kyp->kyc_url = GNUNET_strdup (redirect_url);
+ }
+ else
+ {
+ kyp->hint = GNUNET_strdup (error_msg_hint);
+ }
+ qs = TEH_plugin->update_kyc_process_by_row (
+ TEH_plugin->cls,
+ kyp->process_row,
+ kyp->section_name,
+ &kyp->h_payto,
+ provider_user_id,
+ provider_legitimization_id,
+ redirect_url,
+ GNUNET_TIME_UNIT_ZERO_ABS);
+ if (qs <= 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYC requirement update failed for %s with status %d at %s:%u\n",
+ TALER_B2S (&kyp->h_payto),
+ qs,
+ __FILE__,
+ __LINE__);
+ GNUNET_assert (kyp->suspended);
+ kyp->suspended = false;
+ GNUNET_CONTAINER_DLL_remove (kyp_head,
+ kyp_tail,
+ kyp);
+ MHD_resume_connection (kyp->connection);
+ TALER_MHD_daemon_trigger ();
+}
+
+
+/**
* Function implementing database transaction to check wallet's KYC status.
* Runs the transaction logic; IF it returns a non-error code, the transaction
* logic MUST NOT queue a MHD response. IF it returns an hard error, the
@@ -168,10 +300,53 @@ kyc_check (void *cls,
{
struct KycPoller *kyp = cls;
enum GNUNET_DB_QueryStatus qs;
-
- qs = TEH_plugin->select_kyc_status (TEH_plugin->cls,
- &kyp->h_payto,
- &kyp->kyc);
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+ enum GNUNET_GenericReturnValue ret;
+ struct TALER_PaytoHashP h_payto;
+ char *requirements;
+ char *redirect_url;
+ bool satisfied;
+
+ qs = TEH_plugin->lookup_kyc_requirement_by_row (
+ TEH_plugin->cls,
+ kyp->requirement_row,
+ &requirements,
+ &kyp->aml_status,
+ &h_payto);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No KYC requirements open for %llu\n",
+ (unsigned long long) kyp->requirement_row);
+ return qs;
+ }
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR != qs);
+ return qs;
+ }
+ if (0 !=
+ GNUNET_memcmp (&kyp->h_payto,
+ &h_payto))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Requirement %llu provided, but h_payto does not match\n",
+ (unsigned long long) kyp->requirement_row);
+ GNUNET_break_op (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_KYC_CHECK_AUTHORIZATION_FAILED,
+ "h_payto");
+ GNUNET_free (requirements);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ qs = TALER_KYCLOGIC_check_satisfied (
+ &requirements,
+ &h_payto,
+ &kyp->kyc_details,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &satisfied);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -180,9 +355,95 @@ kyc_check (void *cls,
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "inselect_wallet_status");
+ "kyc_test_required");
+ GNUNET_free (requirements);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (satisfied)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC requirements `%s' already satisfied\n",
+ requirements);
+ GNUNET_free (requirements);
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+
+ kyp->kyc_required = true;
+ ret = TALER_KYCLOGIC_requirements_to_logic (requirements,
+ kyp->ut,
+ &kyp->ih_logic,
+ &pd,
+ &kyp->section_name);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYC requirements `%s' cannot be checked, but are set as required in database!\n",
+ requirements);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_GONE,
+ requirements);
+ GNUNET_free (requirements);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ GNUNET_free (requirements);
+
+ if (kyp->ih_done)
return qs;
+ qs = TEH_plugin->get_pending_kyc_requirement_process (
+ TEH_plugin->cls,
+ &h_payto,
+ kyp->section_name,
+ &redirect_url);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_process");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (qs > 0) &&
+ (NULL != redirect_url) )
+ {
+ kyp->kyc_url = redirect_url;
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ /* set up new requirement process */
+ qs = TEH_plugin->insert_kyc_requirement_process (
+ TEH_plugin->cls,
+ &h_payto,
+ kyp->section_name,
+ NULL,
+ NULL,
+ &kyp->process_row);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_process");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Initiating KYC check with logic %s\n",
+ kyp->ih_logic->name);
+ kyp->ih = kyp->ih_logic->initiate (kyp->ih_logic->cls,
+ pd,
+ &h_payto,
+ kyp->process_row,
+ &initiate_cb,
+ kyp);
+ GNUNET_break (NULL != kyp->ih);
return qs;
}
@@ -230,7 +491,7 @@ db_event_cb (void *cls,
MHD_RESULT
TEH_handler_kyc_check (
struct TEH_RequestContext *rc,
- const char *const args[])
+ const char *const args[3])
{
struct KycPoller *kyp = rc->rh_ctx;
MHD_RESULT res;
@@ -245,83 +506,62 @@ TEH_handler_kyc_check (
rc->rh_cleaner = &kyp_cleanup;
{
- unsigned long long payment_target_uuid;
+ unsigned long long requirement_row;
char dummy;
if (1 !=
sscanf (args[0],
"%llu%c",
- &payment_target_uuid,
+ &requirement_row,
&dummy))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "payment_target_uuid");
+ "requirement_row");
}
- kyp->auth_payment_target_uuid = (uint64_t) payment_target_uuid;
+ kyp->requirement_row = (uint64_t) requirement_row;
}
- {
- const char *ts;
- ts = MHD_lookup_connection_value (rc->connection,
- MHD_GET_ARGUMENT_KIND,
- "timeout_ms");
- if (NULL != ts)
- {
- char dummy;
- unsigned long long tms;
-
- if (1 !=
- sscanf (ts,
- "%llu%c",
- &tms,
- &dummy))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "timeout_ms");
- }
- kyp->timeout = GNUNET_TIME_relative_to_absolute (
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- tms));
- }
- }
- kyp->hps = MHD_lookup_connection_value (rc->connection,
- MHD_GET_ARGUMENT_KIND,
- "h_payto");
- if (NULL == kyp->hps)
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[1],
+ strlen (args[1]),
+ &kyp->h_payto,
+ sizeof (kyp->h_payto)))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MISSING,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
"h_payto");
}
+
if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (kyp->hps,
- strlen (kyp->hps),
- &kyp->h_payto,
- sizeof (kyp->h_payto)))
+ TALER_KYCLOGIC_kyc_user_type_from_string (args[2],
+ &kyp->ut))
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "h_payto");
+ "usertype");
}
- }
- if (TEH_KYC_NONE == TEH_kyc_config.mode)
- return TALER_MHD_reply_static (
+ TALER_MHD_parse_request_timeout (rc->connection,
+ &kyp->timeout);
+ }
+ /* KYC plugin generated reply? */
+ if (NULL != kyp->kyc_url)
+ {
+ return TALER_MHD_REPLY_JSON_PACK (
rc->connection,
- MHD_HTTP_NO_CONTENT,
- NULL,
- NULL,
- 0);
+ MHD_HTTP_ACCEPTED,
+ GNUNET_JSON_pack_uint64 ("aml_status",
+ kyp->aml_status),
+ GNUNET_JSON_pack_string ("kyc_url",
+ kyp->kyc_url));
+ }
if ( (NULL == kyp->eh) &&
GNUNET_TIME_absolute_is_future (kyp->timeout) )
@@ -350,29 +590,73 @@ TEH_handler_kyc_check (
&kyc_check,
kyp);
if (GNUNET_SYSERR == ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Transaction failed.\n");
return res;
+ }
+ /* KYC plugin generated reply? */
+ if (NULL != kyp->kyc_url)
+ {
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_ACCEPTED,
+ GNUNET_JSON_pack_uint64 ("aml_status",
+ kyp->aml_status),
+ GNUNET_JSON_pack_string ("kyc_url",
+ kyp->kyc_url));
+ }
- if (kyp->auth_payment_target_uuid !=
- kyp->kyc.payment_target_uuid)
+ if ( (NULL == kyp->ih) &&
+ (! kyp->kyc_required) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Account %llu provided, but payto %s is for %llu\n",
- (unsigned long long) kyp->auth_payment_target_uuid,
- kyp->hps,
- (unsigned long long) kyp->kyc.payment_target_uuid);
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_KYC_CHECK_AUTHORIZATION_FAILED,
- "h_payto");
+ if (TALER_AML_NORMAL != kyp->aml_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC is OK, but AML active: %d\n",
+ (int) kyp->aml_status);
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ GNUNET_JSON_pack_uint64 ("aml_status",
+ kyp->aml_status));
+ }
+ /* KYC not required */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC not required %llu\n",
+ (unsigned long long) kyp->requirement_row);
+ return TALER_MHD_reply_static (
+ rc->connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+
+ if (NULL != kyp->ih)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Suspending HTTP request on KYC logic...\n");
+ kyp->suspended = true;
+ GNUNET_CONTAINER_DLL_insert (kyp_head,
+ kyp_tail,
+ kyp);
+ MHD_suspend_connection (kyp->connection);
+ return MHD_YES;
}
/* long polling? */
- if ( (! kyp->kyc.ok) &&
+ if ( (NULL != kyp->section_name) &&
GNUNET_TIME_absolute_is_future (kyp->timeout))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Suspending HTTP request on timeout (%s) now...\n",
+ GNUNET_TIME_relative2s (GNUNET_TIME_absolute_get_remaining (
+ kyp->timeout),
+ true));
GNUNET_assert (NULL != kyp->eh);
kyp->suspended = true;
+ kyp->section_name = NULL;
GNUNET_CONTAINER_DLL_insert (kyp_head,
kyp_tail,
kyp);
@@ -380,37 +664,14 @@ TEH_handler_kyc_check (
return MHD_YES;
}
- /* KYC failed? */
- if (! kyp->kyc.ok)
+ if (TALER_EC_NONE != kyp->ec)
{
- char *url;
- char *redirect_uri;
- char *redirect_uri_encoded;
-
- GNUNET_assert (TEH_KYC_OAUTH2 == TEH_kyc_config.mode);
- GNUNET_asprintf (&redirect_uri,
- "%s/kyc-proof/%s",
- TEH_base_url,
- kyp->hps);
- redirect_uri_encoded = TALER_urlencode (redirect_uri);
- GNUNET_free (redirect_uri);
- GNUNET_asprintf (&url,
- "%s?client_id=%s&redirect_uri=%s",
- TEH_kyc_config.details.oauth2.login_url,
- TEH_kyc_config.details.oauth2.client_id,
- redirect_uri_encoded);
- GNUNET_free (redirect_uri_encoded);
-
- res = TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_ACCEPTED,
- GNUNET_JSON_pack_string ("kyc_url",
- url));
- GNUNET_free (url);
- return res;
+ return TALER_MHD_reply_with_ec (rc->connection,
+ kyp->ec,
+ kyp->hint);
}
- /* KYC succeeded! */
+ /* KYC must have succeeded! */
{
struct TALER_ExchangePublicKeyP pub;
struct TALER_ExchangeSignatureP sig;
@@ -420,6 +681,7 @@ TEH_handler_kyc_check (
(ec = TALER_exchange_online_account_setup_success_sign (
&TEH_keys_exchange_sign_,
&kyp->h_payto,
+ kyp->kyc_details,
now,
&pub,
&sig)))
@@ -435,6 +697,10 @@ TEH_handler_kyc_check (
&sig),
GNUNET_JSON_pack_data_auto ("exchange_pub",
&pub),
+ GNUNET_JSON_pack_uint64 ("aml_status",
+ kyp->aml_status),
+ GNUNET_JSON_pack_object_incref ("kyc_details",
+ kyp->kyc_details),
GNUNET_JSON_pack_timestamp ("now",
now));
}
diff --git a/src/exchange/taler-exchange-httpd_kyc-check.h b/src/exchange/taler-exchange-httpd_kyc-check.h
index b6434b601..f1f2c9e7d 100644
--- a/src/exchange/taler-exchange-httpd_kyc-check.h
+++ b/src/exchange/taler-exchange-httpd_kyc-check.h
@@ -30,7 +30,7 @@
* status of the given account and returns it.
*
* @param rc details about the request to handle
- * @param args one argument with the payment_target_uuid
+ * @param args one argument with the legitimization_uuid
* @return MHD result code
*/
MHD_RESULT
diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.c b/src/exchange/taler-exchange-httpd_kyc-proof.c
index 75ff81e96..bad377a2a 100644
--- a/src/exchange/taler-exchange-httpd_kyc-proof.c
+++ b/src/exchange/taler-exchange-httpd_kyc-proof.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -23,9 +23,12 @@
#include <gnunet/gnunet_json_lib.h>
#include <jansson.h>
#include <microhttpd.h>
-#include <pthread.h>
+#include "taler_attributes.h"
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_mhd_lib.h"
+#include "taler_templating_lib.h"
+#include "taler-exchange-httpd_common_kyc.h"
#include "taler-exchange-httpd_kyc-proof.h"
#include "taler-exchange-httpd_responses.h"
@@ -52,30 +55,36 @@ struct KycProofContext
struct TEH_RequestContext *rc;
/**
- * Handle for the OAuth 2.0 CURL request.
+ * Proof logic to run.
*/
- struct GNUNET_CURL_Job *job;
+ struct TALER_KYCLOGIC_Plugin *logic;
/**
- * OAuth 2.0 authorization code.
+ * Configuration for @a logic.
*/
- const char *authorization_code;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
/**
- * OAuth 2.0 token URL we are using for the
- * request.
+ * Asynchronous operation with the proof system.
*/
- char *token_url;
+ struct TALER_KYCLOGIC_ProofHandle *ph;
/**
- * Body of the POST request.
+ * KYC AML trigger operation.
*/
- char *post_body;
+ struct TEH_KycAmlTrigger *kat;
/**
- * User ID extracted from the OAuth 2.0 service, or NULL.
+ * Process information about the user for the plugin from the database, can
+ * be NULL.
*/
- char *id;
+ char *provider_user_id;
+
+ /**
+ * Process information about the legitimization process for the plugin from the
+ * database, can be NULL.
+ */
+ char *provider_legitimization_id;
/**
* Hash of payment target URI this is about.
@@ -88,16 +97,24 @@ struct KycProofContext
struct MHD_Response *response;
/**
+ * Provider configuration section name of the logic we are running.
+ */
+ const char *provider_section;
+
+ /**
+ * Row in the database for this legitimization operation.
+ */
+ uint64_t process_row;
+
+ /**
* HTTP response code to return.
*/
unsigned int response_code;
/**
- * #GNUNET_YES if we are suspended,
- * #GNUNET_NO if not.
- * #GNUNET_SYSERR if we had some error.
+ * True if we are suspended,
*/
- enum GNUNET_GenericReturnValue suspended;
+ bool suspended;
};
@@ -122,7 +139,7 @@ static void
kpc_resume (struct KycProofContext *kpc)
{
GNUNET_assert (GNUNET_YES == kpc->suspended);
- kpc->suspended = GNUNET_NO;
+ kpc->suspended = false;
GNUNET_CONTAINER_DLL_remove (kpc_head,
kpc_tail,
kpc);
@@ -138,10 +155,10 @@ TEH_kyc_proof_cleanup (void)
while (NULL != (kpc = kpc_head))
{
- if (NULL != kpc->job)
+ if (NULL != kpc->ph)
{
- GNUNET_CURL_job_cancel (kpc->job);
- kpc->job = NULL;
+ kpc->logic->proof_cancel (kpc->ph);
+ kpc->ph = NULL;
}
kpc_resume (kpc);
}
@@ -149,348 +166,232 @@ TEH_kyc_proof_cleanup (void)
/**
- * Function implementing database transaction to check proof's KYC status.
- * Runs the transaction logic; IF it returns a non-error code, the transaction
- * logic MUST NOT queue a MHD response. IF it returns an hard error, the
- * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
- * returns the soft error code, the function MAY be called again to retry and
- * MUST not queue a MHD response.
+ * Function called after the KYC-AML trigger is done.
*
- * @param cls closure with a `struct KycProofContext *`
- * @param connection MHD proof which triggered the transaction
- * @param[out] mhd_ret set to MHD response status for @a connection,
- * if transaction failed (!)
- * @return transaction status
+ * @param cls closure
+ * @param http_status final HTTP status to return
+ * @param[in] response final HTTP ro return
*/
-static enum GNUNET_DB_QueryStatus
-persist_kyc_ok (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
+static void
+proof_finish (
+ void *cls,
+ unsigned int http_status,
+ struct MHD_Response *response)
{
struct KycProofContext *kpc = cls;
- enum GNUNET_DB_QueryStatus qs;
- qs = TEH_plugin->set_kyc_ok (TEH_plugin->cls,
- &kpc->h_payto,
- kpc->id);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret = TALER_MHD_reply_with_ec (connection,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "set_kyc_ok");
- }
- return qs;
+ kpc->kat = NULL;
+ kpc->response_code = http_status;
+ kpc->response = response;
+ kpc_resume (kpc);
}
/**
- * The request for @a kpc failed. We may have gotten a useful error
- * message in @a j. Generate a failure response.
+ * Generate HTML error for @a connection using @a template.
*
- * @param[in,out] kpc request that failed
- * @param j reply from the server (or NULL)
+ * @param connection HTTP client connection
+ * @param template template to expand
+ * @param[in,out] http_status HTTP status of the response
+ * @param ec Taler error code to return
+ * @param message extended message to return
+ * @return MHD response object
*/
-static void
-handle_error (struct KycProofContext *kpc,
- const json_t *j)
+struct MHD_Response *
+make_html_error (struct MHD_Connection *connection,
+ const char *template,
+ unsigned int *http_status,
+ enum TALER_ErrorCode ec,
+ const char *message)
{
- const char *msg;
- const char *desc;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("error",
- &msg),
- GNUNET_JSON_spec_string ("error_description",
- &desc),
- GNUNET_JSON_spec_end ()
- };
-
- {
- enum GNUNET_GenericReturnValue res;
- const char *emsg;
- unsigned int line;
-
- res = GNUNET_JSON_parse (j,
- spec,
- &emsg,
- &line);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Unexpected response from KYC gateway");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- return;
- }
- }
- /* case TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_AUTHORZATION_FAILED,
- we MAY want to in the future look at the requested content type
- and possibly respond in JSON if indicated. */
- {
- char *reply;
-
- GNUNET_asprintf (&reply,
- "<html><head><title>%s</title></head><body><h1>%s</h1><p>%s</p></body></html>",
- msg,
- msg,
- desc);
- kpc->response
- = MHD_create_response_from_buffer (strlen (reply),
- reply,
- MHD_RESPMEM_MUST_COPY);
- GNUNET_assert (NULL != kpc->response);
- GNUNET_free (reply);
- }
- kpc->response_code = MHD_HTTP_FORBIDDEN;
+ struct MHD_Response *response = NULL;
+ json_t *body;
+
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("message",
+ message)),
+ TALER_JSON_pack_ec (
+ ec));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (connection,
+ http_status,
+ template,
+ NULL,
+ NULL,
+ body,
+ &response));
+ json_decref (body);
+ return response;
}
/**
- * The request for @a kpc succeeded (presumably).
- * Parse the user ID and store it in @a kpc (if possible).
+ * Respond with an HTML message on the given @a rc.
*
- * @param[in,out] kpc request that succeeded
- * @param j reply from the server
+ * @param[in,out] rc request to respond to
+ * @param http_status HTTP status code to use
+ * @param template template to fill in
+ * @param ec error code to use for the template
+ * @param message additional message to return
+ * @return MHD result code
*/
-static void
-parse_success_reply (struct KycProofContext *kpc,
- const json_t *j)
+static MHD_RESULT
+respond_html_ec (struct TEH_RequestContext *rc,
+ unsigned int http_status,
+ const char *template,
+ enum TALER_ErrorCode ec,
+ const char *message)
{
- const char *state;
- json_t *data;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("status",
- &state),
- GNUNET_JSON_spec_json ("data",
- &data),
- GNUNET_JSON_spec_end ()
- };
- enum GNUNET_GenericReturnValue res;
- const char *emsg;
- unsigned int line;
-
- res = GNUNET_JSON_parse (j,
- spec,
- &emsg,
- &line);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Unexpected response from KYC gateway");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- return;
- }
- if (0 != strcasecmp (state,
- "success"))
- {
- GNUNET_break_op (0);
- handle_error (kpc,
- j);
- return;
- }
- {
- const char *id;
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_string ("id",
- &id),
- GNUNET_JSON_spec_end ()
- };
-
- res = GNUNET_JSON_parse (data,
- ispec,
- &emsg,
- &line);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Unexpected response from KYC gateway");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- return;
- }
- kpc->id = GNUNET_strdup (id);
- }
+ struct MHD_Response *response;
+ MHD_RESULT res;
+
+ response = make_html_error (rc->connection,
+ template,
+ &http_status,
+ ec,
+ message);
+ res = MHD_queue_response (rc->connection,
+ http_status,
+ response);
+ MHD_destroy_response (response);
+ return res;
}
/**
- * After we are done with the CURL interaction we
- * need to update our database state with the information
- * retrieved.
+ * Function called with the result of a proof check operation.
*
- * @param cls our `struct KycProofContext`
- * @param response_code HTTP response code from server, 0 on hard error
- * @param response in JSON, NULL if response was not in JSON format
- */
-static void
-handle_curl_fetch_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct KycProofContext *kpc = cls;
- const json_t *j = response;
-
- kpc->job = NULL;
- switch (response_code)
- {
- case MHD_HTTP_OK:
- parse_success_reply (kpc,
- j);
- break;
- default:
- handle_error (kpc,
- j);
- break;
- }
- kpc_resume (kpc);
-}
-
-
-/**
- * After we are done with the CURL interaction we
- * need to fetch the user's account details.
+ * Note that the "decref" for the @a response
+ * will be done by the callee and MUST NOT be done by the plugin.
*
- * @param cls our `struct KycProofContext`
- * @param response_code HTTP response code from server, 0 on hard error
- * @param response in JSON, NULL if response was not in JSON format
+ * @param cls closure
+ * @param status KYC status
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param expiration until when is the KYC check valid
+ * @param attributes user attributes returned by the provider
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
*/
static void
-handle_curl_login_finished (void *cls,
- long response_code,
- const void *response)
+proof_cb (
+ void *cls,
+ enum TALER_KYCLOGIC_KycStatus status,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response)
{
struct KycProofContext *kpc = cls;
- const json_t *j = response;
+ struct TEH_RequestContext *rc = kpc->rc;
+ struct GNUNET_AsyncScopeSave old_scope;
- kpc->job = NULL;
- switch (response_code)
+ kpc->ph = NULL;
+ GNUNET_async_scope_enter (&rc->async_scope_id,
+ &old_scope);
+ switch (status)
{
- case MHD_HTTP_OK:
+ case TALER_KYCLOGIC_STATUS_SUCCESS:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC process #%llu succeeded with KYC provider\n",
+ (unsigned long long) kpc->process_row);
+ kpc->kat = TEH_kyc_finished (&rc->async_scope_id,
+ kpc->process_row,
+ &kpc->h_payto,
+ kpc->provider_section,
+ provider_user_id,
+ provider_legitimization_id,
+ expiration,
+ attributes,
+ http_status,
+ response,
+ &proof_finish,
+ kpc);
+ if (NULL == kpc->kat)
{
- const char *access_token;
- const char *token_type;
- uint64_t expires_in_s;
- const char *refresh_token;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("access_token",
- &access_token),
- GNUNET_JSON_spec_string ("token_type",
- &token_type),
- GNUNET_JSON_spec_uint64 ("expires_in",
- &expires_in_s),
- GNUNET_JSON_spec_string ("refresh_token",
- &refresh_token),
- GNUNET_JSON_spec_end ()
- };
- CURL *eh;
-
- {
- enum GNUNET_GenericReturnValue res;
- const char *emsg;
- unsigned int line;
-
- res = GNUNET_JSON_parse (j,
- spec,
- &emsg,
- &line);
- if (GNUNET_OK != res)
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Unexpected response from KYC gateway");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- break;
- }
- }
- if (0 != strcasecmp (token_type,
- "bearer"))
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Unexpected token type in response from KYC gateway");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- break;
- }
-
- /* We guard against a few characters that could
- conceivably be abused to mess with the HTTP header */
- if ( (NULL != strchr (access_token,
- '\n')) ||
- (NULL != strchr (access_token,
- '\r')) ||
- (NULL != strchr (access_token,
- ' ')) ||
- (NULL != strchr (access_token,
- ';')) )
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
- "Illegal character in access token");
- kpc->response_code
- = MHD_HTTP_BAD_GATEWAY;
- break;
- }
-
- eh = curl_easy_init ();
- if (NULL == eh)
- {
- GNUNET_break_op (0);
- kpc->response
- = TALER_MHD_make_error (
- TALER_EC_GENERIC_ALLOCATION_FAILURE,
- "curl_easy_init");
- kpc->response_code
- = MHD_HTTP_INTERNAL_SERVER_ERROR;
- break;
- }
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_URL,
- TEH_kyc_config.details.oauth2.info_url));
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ if (NULL != response)
+ MHD_destroy_response (response);
+ response = make_html_error (kpc->rc->connection,
+ "kyc-proof-internal-error",
+ &http_status,
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ "[exchange] AML_KYC_TRIGGER");
+ }
+ break;
+ case TALER_KYCLOGIC_STATUS_FAILED:
+ case TALER_KYCLOGIC_STATUS_PROVIDER_FAILED:
+ case TALER_KYCLOGIC_STATUS_USER_ABORTED:
+ case TALER_KYCLOGIC_STATUS_ABORTED:
+ GNUNET_assert (NULL == kpc->kat);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC process %s/%s (Row #%llu) failed: %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) kpc->process_row,
+ status);
+ if (5 == http_status / 100)
+ {
+ char *msg;
+
+ /* OAuth2 server had a problem, do NOT log this as a KYC failure */
+ if (NULL != response)
+ MHD_destroy_response (response);
+ GNUNET_asprintf (&msg,
+ "Failure by KYC provider (HTTP status %u)\n",
+ http_status);
+ http_status = MHD_HTTP_BAD_GATEWAY;
+ response = make_html_error (kpc->rc->connection,
+ "kyc-proof-internal-error",
+ &http_status,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ msg);
+ GNUNET_free (msg);
+ }
+ else
+ {
+ if (! TEH_kyc_failed (kpc->process_row,
+ &kpc->h_payto,
+ kpc->provider_section,
+ provider_user_id,
+ provider_legitimization_id))
{
- char *hdr;
- struct curl_slist *slist;
-
- GNUNET_asprintf (&hdr,
- "%s: Bearer %s",
- MHD_HTTP_HEADER_AUTHORIZATION,
- access_token);
- slist = curl_slist_append (NULL,
- hdr);
- kpc->job = GNUNET_CURL_job_add2 (TEH_curl_ctx,
- eh,
- slist,
- &handle_curl_fetch_finished,
- kpc);
- curl_slist_free_all (slist);
- GNUNET_free (hdr);
+ GNUNET_break (0);
+ if (NULL != response)
+ MHD_destroy_response (response);
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ response = make_html_error (kpc->rc->connection,
+ "kyc-proof-internal-error",
+ &http_status,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_failure");
}
- return;
}
+ break;
default:
- handle_error (kpc,
- j);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC status of %s/%s (Row #%llu) is %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) kpc->process_row,
+ (int) status);
break;
}
- kpc_resume (kpc);
+ if (NULL == kpc->kat)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC process #%llu failed with status %d\n",
+ (unsigned long long) kpc->process_row,
+ status);
+ proof_finish (kpc,
+ http_status,
+ response);
+ }
+ GNUNET_async_scope_restore (&old_scope);
}
@@ -504,19 +405,23 @@ clean_kpc (struct TEH_RequestContext *rc)
{
struct KycProofContext *kpc = rc->rh_ctx;
- if (NULL != kpc->job)
+ if (NULL != kpc->ph)
+ {
+ kpc->logic->proof_cancel (kpc->ph);
+ kpc->ph = NULL;
+ }
+ if (NULL != kpc->kat)
{
- GNUNET_CURL_job_cancel (kpc->job);
- kpc->job = NULL;
+ TEH_kyc_finished_cancel (kpc->kat);
+ kpc->kat = NULL;
}
if (NULL != kpc->response)
{
MHD_destroy_response (kpc->response);
kpc->response = NULL;
}
- GNUNET_free (kpc->post_body);
- GNUNET_free (kpc->token_url);
- GNUNET_free (kpc->id);
+ GNUNET_free (kpc->provider_user_id);
+ GNUNET_free (kpc->provider_legitimization_id);
GNUNET_free (kpc);
}
@@ -524,188 +429,137 @@ clean_kpc (struct TEH_RequestContext *rc)
MHD_RESULT
TEH_handler_kyc_proof (
struct TEH_RequestContext *rc,
- const char *const args[])
+ const char *const args[1])
{
struct KycProofContext *kpc = rc->rh_ctx;
+ const char *provider_section_or_logic = args[0];
if (NULL == kpc)
- { /* first time */
+ {
+ /* first time */
+ if (NULL == provider_section_or_logic)
+ {
+ GNUNET_break_op (0);
+ return respond_html_ec (rc,
+ MHD_HTTP_NOT_FOUND,
+ "kyc-proof-endpoint-unknown",
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ "'/kyc-proof/$PROVIDER_SECTION?state=$H_PAYTO' required");
+ }
kpc = GNUNET_new (struct KycProofContext);
kpc->rc = rc;
rc->rh_ctx = kpc;
rc->rh_cleaner = &clean_kpc;
+ TALER_MHD_parse_request_arg_auto_t (rc->connection,
+ "state",
+ &kpc->h_payto);
if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[0],
- strlen (args[0]),
- &kpc->h_payto,
- sizeof (kpc->h_payto)))
+ TALER_KYCLOGIC_lookup_logic (provider_section_or_logic,
+ &kpc->logic,
+ &kpc->pd,
+ &kpc->provider_section))
{
GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "h_payto");
+ return respond_html_ec (rc,
+ MHD_HTTP_NOT_FOUND,
+ "kyc-proof-target-unknown",
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
+ provider_section_or_logic);
}
- kpc->authorization_code
- = MHD_lookup_connection_value (rc->connection,
- MHD_GET_ARGUMENT_KIND,
- "code");
- if (NULL == kpc->authorization_code)
+ if (NULL != kpc->provider_section)
{
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "code");
- }
- if (TEH_KYC_NONE == TEH_kyc_config.mode)
- return TALER_MHD_reply_static (
- rc->connection,
- MHD_HTTP_NO_CONTENT,
- NULL,
- NULL,
- 0);
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute expiration;
- {
- CURL *eh;
+ if (0 != strcmp (provider_section_or_logic,
+ kpc->provider_section))
+ {
+ GNUNET_break_op (0);
+ return respond_html_ec (rc,
+ MHD_HTTP_BAD_REQUEST,
+ "kyc-proof-bad-request",
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "PROVIDER_SECTION");
+ }
- eh = curl_easy_init ();
- if (NULL == eh)
+ qs = TEH_plugin->lookup_kyc_process_by_account (
+ TEH_plugin->cls,
+ kpc->provider_section,
+ &kpc->h_payto,
+ &kpc->process_row,
+ &expiration,
+ &kpc->provider_user_id,
+ &kpc->provider_legitimization_id);
+ switch (qs)
{
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_ALLOCATION_FAILURE,
- "curl_easy_init");
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return respond_html_ec (rc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ "kyc-proof-internal-error",
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "lookup_kyc_process_by_account");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return respond_html_ec (rc,
+ MHD_HTTP_NOT_FOUND,
+ "kyc-proof-target-unknown",
+ TALER_EC_EXCHANGE_KYC_PROOF_REQUEST_UNKNOWN,
+ kpc->provider_section);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
}
- GNUNET_asprintf (&kpc->token_url,
- "%s",
- TEH_kyc_config.details.oauth2.auth_url);
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_URL,
- kpc->token_url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_POST,
- 1));
+ if (GNUNET_TIME_absolute_is_future (expiration))
{
- char *client_id;
- char *redirect_uri;
- char *client_secret;
- char *authorization_code;
-
- client_id = curl_easy_escape (eh,
- TEH_kyc_config.details.oauth2.client_id,
- 0);
- GNUNET_assert (NULL != client_id);
- {
- char *request_uri;
-
- GNUNET_asprintf (&request_uri,
- "%s?client_id=%s",
- TEH_kyc_config.details.oauth2.login_url,
- TEH_kyc_config.details.oauth2.client_id);
- redirect_uri = curl_easy_escape (eh,
- request_uri,
- 0);
- GNUNET_free (request_uri);
- }
- GNUNET_assert (NULL != redirect_uri);
- client_secret = curl_easy_escape (eh,
- TEH_kyc_config.details.oauth2.
- client_secret,
- 0);
- GNUNET_assert (NULL != client_secret);
- authorization_code = curl_easy_escape (eh,
- kpc->authorization_code,
- 0);
- GNUNET_assert (NULL != authorization_code);
- GNUNET_asprintf (&kpc->post_body,
- "client_id=%s&redirect_uri=%s&client_secret=%s&code=%s&grant_type=authorization_code",
- client_id,
- redirect_uri,
- client_secret,
- authorization_code);
- curl_free (authorization_code);
- curl_free (client_secret);
- curl_free (redirect_uri);
- curl_free (client_id);
+ /* KYC not required */
+ return respond_html_ec (rc,
+ MHD_HTTP_OK,
+ "kyc-proof-already-done",
+ TALER_EC_NONE,
+ NULL);
}
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_POSTFIELDS,
- kpc->post_body));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_FOLLOWLOCATION,
- 1L));
- /* limit MAXREDIRS to 5 as a simple security measure against
- a potential infinite loop caused by a malicious target */
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_MAXREDIRS,
- 5L));
-
- kpc->job = GNUNET_CURL_job_add (TEH_curl_ctx,
- eh,
- &handle_curl_login_finished,
- kpc);
- kpc->suspended = GNUNET_YES;
- GNUNET_CONTAINER_DLL_insert (kpc_head,
- kpc_tail,
- kpc);
- MHD_suspend_connection (rc->connection);
- return MHD_YES;
}
- }
+ kpc->ph = kpc->logic->proof (kpc->logic->cls,
+ kpc->pd,
+ rc->connection,
+ &kpc->h_payto,
+ kpc->process_row,
+ kpc->provider_user_id,
+ kpc->provider_legitimization_id,
+ &proof_cb,
+ kpc);
+ if (NULL == kpc->ph)
+ {
+ GNUNET_break (0);
+ return respond_html_ec (rc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ "kyc-proof-internal-error",
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "could not start proof with KYC logic");
+ }
- if (NULL != kpc->response)
- {
- /* handle _failed_ resumed cases */
- return MHD_queue_response (rc->connection,
- kpc->response_code,
- kpc->response);
- }
- /* _successfully_ resumed case */
- {
- MHD_RESULT res;
- enum GNUNET_GenericReturnValue ret;
-
- ret = TEH_DB_run_transaction (kpc->rc->connection,
- "check proof kyc",
- TEH_MT_REQUEST_OTHER,
- &res,
- &persist_kyc_ok,
- kpc);
- if (GNUNET_SYSERR == ret)
- return res;
+ kpc->suspended = true;
+ GNUNET_CONTAINER_DLL_insert (kpc_head,
+ kpc_tail,
+ kpc);
+ MHD_suspend_connection (rc->connection);
+ return MHD_YES;
}
+ if (NULL == kpc->response)
{
- struct MHD_Response *response;
- MHD_RESULT res;
-
- response = MHD_create_response_from_buffer (0,
- "",
- MHD_RESPMEM_PERSISTENT);
- if (NULL == response)
- {
- GNUNET_break (0);
- return MHD_NO;
- }
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (
- response,
- MHD_HTTP_HEADER_LOCATION,
- TEH_kyc_config.details.oauth2.post_kyc_redirect_url));
- res = MHD_queue_response (rc->connection,
- MHD_HTTP_SEE_OTHER,
- response);
- MHD_destroy_response (response);
- return res;
+ GNUNET_break (0);
+ return respond_html_ec (rc,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ "kyc-proof-internal-error",
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "handler resumed without response");
}
+
+ /* return response from KYC logic */
+ return MHD_queue_response (rc->connection,
+ kpc->response_code,
+ kpc->response);
}
diff --git a/src/exchange/taler-exchange-httpd_kyc-proof.h b/src/exchange/taler-exchange-httpd_kyc-proof.h
index c075b2424..d40ea90a9 100644
--- a/src/exchange/taler-exchange-httpd_kyc-proof.h
+++ b/src/exchange/taler-exchange-httpd_kyc-proof.h
@@ -37,13 +37,13 @@ TEH_kyc_proof_cleanup (void);
* Handle a "/kyc-proof" request.
*
* @param rc request to handle
- * @param args one argument with the payment_target_uuid
+ * @param args one argument with the legitimization_uuid
* @return MHD result code
*/
MHD_RESULT
TEH_handler_kyc_proof (
struct TEH_RequestContext *rc,
- const char *const args[]);
+ const char *const args[1]);
#endif
diff --git a/src/exchange/taler-exchange-httpd_kyc-wallet.c b/src/exchange/taler-exchange-httpd_kyc-wallet.c
index 0d92efd3a..21d07422d 100644
--- a/src/exchange/taler-exchange-httpd_kyc-wallet.c
+++ b/src/exchange/taler-exchange-httpd_kyc-wallet.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021, 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -26,6 +26,7 @@
#include <pthread.h>
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler-exchange-httpd_kyc-wallet.h"
#include "taler-exchange-httpd_responses.h"
@@ -38,16 +39,60 @@ struct KycRequestContext
/**
* Public key of the reserve/wallet this is about.
*/
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * The reserve's public key
+ */
struct TALER_ReservePublicKeyP reserve_pub;
/**
- * Current KYC status.
+ * KYC status, with row with the legitimization requirement.
*/
struct TALER_EXCHANGEDB_KycStatus kyc;
+
+ /**
+ * Balance threshold crossed by the wallet.
+ */
+ struct TALER_Amount balance;
+
+ /**
+ * Name of the required check.
+ */
+ char *required;
+
};
/**
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Returns the wallet balance.
+ *
+ * @param cls closure, a `struct KycRequestContext`
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
+ */
+static void
+balance_iterator (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
+{
+ struct KycRequestContext *krc = cls;
+
+ (void) limit;
+ cb (cb_cls,
+ &krc->balance,
+ GNUNET_TIME_absolute_get ());
+}
+
+
+/**
* Function implementing database transaction to check wallet's KYC status.
* Runs the transaction logic; IF it returns a non-error code, the transaction
* logic MUST NOT queue a MHD response. IF it returns an hard error, the
@@ -69,9 +114,40 @@ wallet_kyc_check (void *cls,
struct KycRequestContext *krc = cls;
enum GNUNET_DB_QueryStatus qs;
- qs = TEH_plugin->inselect_wallet_kyc_status (TEH_plugin->cls,
- &krc->reserve_pub,
- &krc->kyc);
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE,
+ &krc->h_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &balance_iterator,
+ krc,
+ &krc->required);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "kyc_test_required");
+ return qs;
+ }
+ if (NULL == krc->required)
+ {
+ krc->kyc.ok = true;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check required at %s is `%s'\n",
+ TALER_amount2s (&krc->balance),
+ krc->required);
+ krc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (TEH_plugin->cls,
+ krc->required,
+ &krc->h_payto,
+ &krc->reserve_pub,
+ &krc->kyc.requirement_row);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -80,9 +156,14 @@ wallet_kyc_check (void *cls,
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_FETCH_FAILED,
- "inselect_wallet_status");
+ "insert_kyc_requirement_for_account");
return qs;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC requirement inserted for wallet %s (%llu, %d)\n",
+ TALER_B2S (&krc->h_payto),
+ (unsigned long long) krc->kyc.requirement_row,
+ qs);
return qs;
}
@@ -100,6 +181,9 @@ TEH_handler_kyc_wallet (
&reserve_sig),
GNUNET_JSON_spec_fixed_auto ("reserve_pub",
&krc.reserve_pub),
+ TALER_JSON_spec_amount ("balance",
+ TEH_currency,
+ &krc.balance),
GNUNET_JSON_spec_end ()
};
MHD_RESULT res;
@@ -117,6 +201,7 @@ TEH_handler_kyc_wallet (
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
TALER_wallet_account_setup_verify (&krc.reserve_pub,
+ &krc.balance,
&reserve_sig))
{
GNUNET_break_op (0);
@@ -126,13 +211,19 @@ TEH_handler_kyc_wallet (
TALER_EC_EXCHANGE_KYC_WALLET_SIGNATURE_INVALID,
NULL);
}
- if (TEH_KYC_NONE == TEH_kyc_config.mode)
- return TALER_MHD_reply_static (
- rc->connection,
- MHD_HTTP_NO_CONTENT,
- NULL,
- NULL,
- 0);
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (TEH_base_url,
+ &krc.reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &krc.h_payto);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "h_payto of wallet %s is %s\n",
+ payto_uri,
+ TALER_B2S (&krc.h_payto));
+ GNUNET_free (payto_uri);
+ }
ret = TEH_DB_run_transaction (rc->connection,
"check wallet kyc",
TEH_MT_REQUEST_OTHER,
@@ -141,11 +232,20 @@ TEH_handler_kyc_wallet (
&krc);
if (GNUNET_SYSERR == ret)
return res;
- return TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_OK,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- krc.kyc.payment_target_uuid));
+ if (NULL == krc.required)
+ {
+ /* KYC not required or already satisfied */
+ return TALER_MHD_reply_static (
+ rc->connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+ }
+ GNUNET_free (krc.required);
+ return TEH_RESPONSE_reply_kyc_required (rc->connection,
+ &krc.h_payto,
+ &krc.kyc);
}
diff --git a/src/exchange/taler-exchange-httpd_kyc-webhook.c b/src/exchange/taler-exchange-httpd_kyc-webhook.c
new file mode 100644
index 000000000..b92b43e69
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_kyc-webhook.c
@@ -0,0 +1,420 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_kyc-webhook.c
+ * @brief Handle notification of KYC completion via webhook.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_attributes.h"
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_kyclogic_lib.h"
+#include "taler-exchange-httpd_common_kyc.h"
+#include "taler-exchange-httpd_kyc-webhook.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Context for the webhook.
+ */
+struct KycWebhookContext
+{
+
+ /**
+ * Kept in a DLL while suspended.
+ */
+ struct KycWebhookContext *next;
+
+ /**
+ * Kept in a DLL while suspended.
+ */
+ struct KycWebhookContext *prev;
+
+ /**
+ * Details about the connection we are processing.
+ */
+ struct TEH_RequestContext *rc;
+
+ /**
+ * Handle for the KYC-AML trigger interaction.
+ */
+ struct TEH_KycAmlTrigger *kat;
+
+ /**
+ * Plugin responsible for the webhook.
+ */
+ struct TALER_KYCLOGIC_Plugin *plugin;
+
+ /**
+ * Section in the configuration of the configured
+ * KYC provider.
+ */
+ const char *provider_section;
+
+ /**
+ * Configuration for the specific action.
+ */
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Webhook activity.
+ */
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+
+ /**
+ * HTTP response to return.
+ */
+ struct MHD_Response *response;
+
+ /**
+ * HTTP response code to return.
+ */
+ unsigned int response_code;
+
+ /**
+ * #GNUNET_YES if we are suspended,
+ * #GNUNET_NO if not.
+ * #GNUNET_SYSERR if we had some error.
+ */
+ enum GNUNET_GenericReturnValue suspended;
+
+};
+
+
+/**
+ * Contexts are kept in a DLL while suspended.
+ */
+static struct KycWebhookContext *kwh_head;
+
+/**
+ * Contexts are kept in a DLL while suspended.
+ */
+static struct KycWebhookContext *kwh_tail;
+
+
+/**
+ * Resume processing the @a kwh request.
+ *
+ * @param kwh request to resume
+ */
+static void
+kwh_resume (struct KycWebhookContext *kwh)
+{
+ GNUNET_assert (GNUNET_YES == kwh->suspended);
+ kwh->suspended = GNUNET_NO;
+ GNUNET_CONTAINER_DLL_remove (kwh_head,
+ kwh_tail,
+ kwh);
+ MHD_resume_connection (kwh->rc->connection);
+ TALER_MHD_daemon_trigger ();
+}
+
+
+void
+TEH_kyc_webhook_cleanup (void)
+{
+ struct KycWebhookContext *kwh;
+
+ while (NULL != (kwh = kwh_head))
+ {
+ if (NULL != kwh->wh)
+ {
+ kwh->plugin->webhook_cancel (kwh->wh);
+ kwh->wh = NULL;
+ }
+ kwh_resume (kwh);
+ }
+}
+
+
+/**
+ * Function called after the KYC-AML trigger is done.
+ *
+ * @param cls closure with a `struct KycWebhookContext *`
+ * @param http_status final HTTP status to return
+ * @param[in] response final HTTP ro return
+ */
+static void
+kyc_aml_webhook_finished (
+ void *cls,
+ unsigned int http_status,
+ struct MHD_Response *response)
+{
+ struct KycWebhookContext *kwh = cls;
+
+ kwh->kat = NULL;
+ kwh->response = response;
+ kwh->response_code = http_status;
+ kwh_resume (kwh);
+}
+
+
+/**
+ * Function called with the result of a KYC webhook operation.
+ *
+ * Note that the "decref" for the @a response
+ * will be done by the plugin.
+ *
+ * @param cls closure
+ * @param process_row legitimization process the webhook was about
+ * @param account_id account the webhook was about
+ * @param provider_section name of the configuration section of the logic that was run
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param status KYC status
+ * @param expiration until when is the KYC check valid
+ * @param attributes user attributes returned by the provider
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ */
+static void
+webhook_finished_cb (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ enum TALER_KYCLOGIC_KycStatus status,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response)
+{
+ struct KycWebhookContext *kwh = cls;
+
+ kwh->wh = NULL;
+ switch (status)
+ {
+ case TALER_KYCLOGIC_STATUS_SUCCESS:
+ kwh->kat = TEH_kyc_finished (
+ &kwh->rc->async_scope_id,
+ process_row,
+ account_id,
+ provider_section,
+ provider_user_id,
+ provider_legitimization_id,
+ expiration,
+ attributes,
+ http_status,
+ response,
+ &kyc_aml_webhook_finished,
+ kwh);
+ if (NULL == kwh->kat)
+ {
+ if (NULL != response)
+ MHD_destroy_response (response);
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ response = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ "[exchange] AML_KYC_TRIGGER");
+ break;
+ }
+ return;
+ case TALER_KYCLOGIC_STATUS_FAILED:
+ case TALER_KYCLOGIC_STATUS_PROVIDER_FAILED:
+ case TALER_KYCLOGIC_STATUS_USER_ABORTED:
+ case TALER_KYCLOGIC_STATUS_ABORTED:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC process %s/%s (Row #%llu) failed: %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) process_row,
+ status);
+ if (! TEH_kyc_failed (process_row,
+ account_id,
+ provider_section,
+ provider_user_id,
+ provider_legitimization_id))
+ {
+ GNUNET_break (0);
+ if (NULL != response)
+ MHD_destroy_response (response);
+ http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ response = TALER_MHD_make_error (
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_failure");
+ }
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC status of %s/%s (Row #%llu) is %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) process_row,
+ (int) status);
+ break;
+ }
+ GNUNET_break (NULL == kwh->kat);
+ kyc_aml_webhook_finished (kwh,
+ http_status,
+ response);
+}
+
+
+/**
+ * Function called to clean up a context.
+ *
+ * @param rc request context
+ */
+static void
+clean_kwh (struct TEH_RequestContext *rc)
+{
+ struct KycWebhookContext *kwh = rc->rh_ctx;
+
+ if (NULL != kwh->wh)
+ {
+ kwh->plugin->webhook_cancel (kwh->wh);
+ kwh->wh = NULL;
+ }
+ if (NULL != kwh->kat)
+ {
+ TEH_kyc_finished_cancel (kwh->kat);
+ kwh->kat = NULL;
+ }
+ if (NULL != kwh->response)
+ {
+ MHD_destroy_response (kwh->response);
+ kwh->response = NULL;
+ }
+ GNUNET_free (kwh);
+}
+
+
+/**
+ * Handle a (GET or POST) "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param method HTTP request method used by the client
+ * @param root uploaded JSON body (can be NULL)
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+static MHD_RESULT
+handler_kyc_webhook_generic (
+ struct TEH_RequestContext *rc,
+ const char *method,
+ const json_t *root,
+ const char *const args[])
+{
+ struct KycWebhookContext *kwh = rc->rh_ctx;
+
+ if (NULL == kwh)
+ { /* first time */
+ kwh = GNUNET_new (struct KycWebhookContext);
+ kwh->rc = rc;
+ rc->rh_ctx = kwh;
+ rc->rh_cleaner = &clean_kwh;
+
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ TALER_KYCLOGIC_lookup_logic (args[0],
+ &kwh->plugin,
+ &kwh->pd,
+ &kwh->provider_section)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYC logic `%s' unknown (check KYC provider configuration)\n",
+ args[0]);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
+ args[0]);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC logic `%s' mapped to section %s\n",
+ args[0],
+ kwh->provider_section);
+ kwh->wh = kwh->plugin->webhook (kwh->plugin->cls,
+ kwh->pd,
+ TEH_plugin->kyc_provider_account_lookup,
+ TEH_plugin->cls,
+ method,
+ &args[1],
+ rc->connection,
+ root,
+ &webhook_finished_cb,
+ kwh);
+ if (NULL == kwh->wh)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "failed to run webhook logic");
+ }
+ kwh->suspended = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (kwh_head,
+ kwh_tail,
+ kwh);
+ MHD_suspend_connection (rc->connection);
+ return MHD_YES;
+ }
+ GNUNET_break (GNUNET_NO == kwh->suspended);
+
+ if (NULL != kwh->response)
+ {
+ MHD_RESULT res;
+
+ res = MHD_queue_response (rc->connection,
+ kwh->response_code,
+ kwh->response);
+ GNUNET_break (MHD_YES == res);
+ return res;
+ }
+
+ /* We resumed, but got no response? This should
+ not happen. */
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "resumed without response");
+}
+
+
+MHD_RESULT
+TEH_handler_kyc_webhook_get (
+ struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ return handler_kyc_webhook_generic (rc,
+ MHD_HTTP_METHOD_GET,
+ NULL,
+ args);
+}
+
+
+MHD_RESULT
+TEH_handler_kyc_webhook_post (
+ struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[])
+{
+ return handler_kyc_webhook_generic (rc,
+ MHD_HTTP_METHOD_POST,
+ root,
+ args);
+}
+
+
+/* end of taler-exchange-httpd_kyc-webhook.c */
diff --git a/src/exchange/taler-exchange-httpd_kyc-webhook.h b/src/exchange/taler-exchange-httpd_kyc-webhook.h
new file mode 100644
index 000000000..ea3821897
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_kyc-webhook.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2021 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_kyc-webhook.h
+ * @brief Handle /kyc-webhook requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_KYC_WEBHOOK_H
+#define TALER_EXCHANGE_HTTPD_KYC_WEBHOOK_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Shutdown kyc-webhook subsystem. Resumes all suspended long-polling clients
+ * and cleans up data structures.
+ */
+void
+TEH_kyc_webhook_cleanup (void);
+
+
+/**
+ * Handle a GET "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_kyc_webhook_get (
+ struct TEH_RequestContext *rc,
+ const char *const args[]);
+
+
+/**
+ * Handle a POST "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param root uploaded JSON body
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_kyc_webhook_post (
+ struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[]);
+
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_link.c b/src/exchange/taler-exchange-httpd_link.c
index 9b7e297bc..3d92a11a3 100644
--- a/src/exchange/taler-exchange-httpd_link.c
+++ b/src/exchange/taler-exchange-httpd_link.c
@@ -39,7 +39,7 @@ struct HTD_Context
/**
* Public key of the coin for which we are running link.
*/
- struct TALER_CoinSpendPublicKeyP coin_pub;
+ const struct TALER_CoinSpendPublicKeyP *coin_pub;
/**
* Json array with transfer data we collect.
@@ -153,7 +153,7 @@ link_transaction (void *cls,
enum GNUNET_DB_QueryStatus qs;
qs = TEH_plugin->get_link_data (TEH_plugin->cls,
- &ctx->coin_pub,
+ ctx->coin_pub,
&handle_link_data,
ctx);
if (NULL == ctx->mlist)
@@ -178,26 +178,13 @@ link_transaction (void *cls,
MHD_RESULT
TEH_handler_link (struct TEH_RequestContext *rc,
- const char *const args[2])
+ const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
- struct HTD_Context ctx;
+ struct HTD_Context ctx = {
+ .coin_pub = coin_pub
+ };
MHD_RESULT mhd_ret;
- memset (&ctx,
- 0,
- sizeof (ctx));
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[0],
- strlen (args[0]),
- &ctx.coin_pub,
- sizeof (ctx.coin_pub)))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_COINS_INVALID_COIN_PUB,
- args[0]);
- }
ctx.mlist = json_array ();
GNUNET_assert (NULL != ctx.mlist);
if (GNUNET_OK !=
diff --git a/src/exchange/taler-exchange-httpd_link.h b/src/exchange/taler-exchange-httpd_link.h
index 01679e877..255c0ca57 100644
--- a/src/exchange/taler-exchange-httpd_link.h
+++ b/src/exchange/taler-exchange-httpd_link.h
@@ -32,12 +32,12 @@
* Handle a "/coins/$COIN_PUB/link" request.
*
* @param rc request context
- * @param args array of additional options (length: 2, first is the coin_pub, second must be "link")
+ * @param coin_pub the coin public key
* @return MHD result code
*/
MHD_RESULT
TEH_handler_link (struct TEH_RequestContext *rc,
- const char *const args[2]);
+ const struct TALER_CoinSpendPublicKeyP *coin_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_management.h b/src/exchange/taler-exchange-httpd_management.h
index 1bae49011..2fc1fe8db 100644
--- a/src/exchange/taler-exchange-httpd_management.h
+++ b/src/exchange/taler-exchange-httpd_management.h
@@ -162,6 +162,45 @@ TEH_handler_management_post_extensions (
/**
+ * Handle a POST "/management/drain" request.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_management_post_drain (
+ struct MHD_Connection *connection,
+ const json_t *root);
+
+
+/**
+ * Handle a POST "/management/aml-officers" request.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_management_aml_officers (
+ struct MHD_Connection *connection,
+ const json_t *root);
+
+
+/**
+ * Handle a POST "/management/partners" request.
+ *
+ * @param connection the MHD connection to handle
+ * @param root uploaded JSON data
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_management_partners (
+ struct MHD_Connection *connection,
+ const json_t *root);
+
+
+/**
* Initialize extension configuration handling.
*
* @return #GNUNET_OK on success
diff --git a/src/exchange/taler-exchange-httpd_management_aml-officers.c b/src/exchange/taler-exchange-httpd_management_aml-officers.c
new file mode 100644
index 000000000..abc7c3d84
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_management_aml-officers.c
@@ -0,0 +1,142 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_management_aml-officers.c
+ * @brief Handle request to update AML officer status
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd_management.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * How often do we try the DB operation at most?
+ */
+#define MAX_RETRIES 10
+
+
+MHD_RESULT
+TEH_handler_management_aml_officers (
+ struct MHD_Connection *connection,
+ const json_t *root)
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ const char *officer_name;
+ struct GNUNET_TIME_Timestamp change_date;
+ bool is_active;
+ bool read_only;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("officer_pub",
+ &officer_pub),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ GNUNET_JSON_spec_bool ("is_active",
+ &is_active),
+ GNUNET_JSON_spec_bool ("read_only",
+ &read_only),
+ GNUNET_JSON_spec_string ("officer_name",
+ &officer_name),
+ GNUNET_JSON_spec_timestamp ("change_date",
+ &change_date),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO; /* hard failure */
+ if (GNUNET_NO == res)
+ return MHD_YES; /* failure */
+ }
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_aml_officer_status_verify (
+ &officer_pub,
+ officer_name,
+ change_date,
+ is_active,
+ read_only,
+ &TEH_master_public_key,
+ &master_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_MANAGEMENT_UPDATE_AML_OFFICER_SIGNATURE_INVALID,
+ NULL);
+ }
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp last_date;
+ unsigned int retries_left = MAX_RETRIES;
+
+ do {
+ qs = TEH_plugin->insert_aml_officer (TEH_plugin->cls,
+ &officer_pub,
+ &master_sig,
+ officer_name,
+ is_active,
+ read_only,
+ change_date,
+ &last_date);
+ if (0 == --retries_left)
+ break;
+ } while (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_aml_officer");
+ }
+ if (GNUNET_TIME_timestamp_cmp (last_date,
+ >,
+ change_date))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_MANAGEMENT_AML_OFFICERS_MORE_RECENT_PRESENT,
+ NULL);
+ }
+ }
+ return TALER_MHD_reply_static (
+ connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/* end of taler-exchange-httpd_management_aml-officers.c */
diff --git a/src/exchange/taler-exchange-httpd_management_auditors.c b/src/exchange/taler-exchange-httpd_management_auditors.c
index 9c7a5c472..7e0593534 100644
--- a/src/exchange/taler-exchange-httpd_management_auditors.c
+++ b/src/exchange/taler-exchange-httpd_management_auditors.c
@@ -153,7 +153,7 @@ TEH_handler_management_auditors (
&aac.master_sig),
GNUNET_JSON_spec_fixed_auto ("auditor_pub",
&aac.auditor_pub),
- GNUNET_JSON_spec_string ("auditor_url",
+ TALER_JSON_spec_web_url ("auditor_url",
&aac.auditor_url),
GNUNET_JSON_spec_string ("auditor_name",
&aac.auditor_name),
diff --git a/src/exchange/taler-exchange-httpd_management_drain.c b/src/exchange/taler-exchange-httpd_management_drain.c
new file mode 100644
index 000000000..1e490d799
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_management_drain.c
@@ -0,0 +1,195 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_management_drain.c
+ * @brief Handle request to drain profits
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_management.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Closure for the #drain transaction.
+ */
+struct DrainContext
+{
+ /**
+ * Fee's signature affirming the #TALER_SIGNATURE_MASTER_DRAIN_PROFITS operation.
+ */
+ struct TALER_MasterSignatureP master_sig;
+
+ /**
+ * Wire transfer identifier to use.
+ */
+ struct TALER_WireTransferIdentifierRawP wtid;
+
+ /**
+ * Account to credit.
+ */
+ const char *payto_uri;
+
+ /**
+ * Configuration section with account to debit.
+ */
+ const char *account_section;
+
+ /**
+ * Signature time.
+ */
+ struct GNUNET_TIME_Timestamp date;
+
+ /**
+ * Amount to transfer.
+ */
+ struct TALER_Amount amount;
+
+};
+
+
+/**
+ * Function implementing database transaction to drain profits. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction logic
+ * MUST NOT queue a MHD response. IF it returns an hard error, the
+ * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
+ * returns the soft error code, the function MAY be called again to retry and
+ * MUST not queue a MHD response.
+ *
+ * @param cls closure with a `struct DrainContext`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+drain (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct DrainContext *dc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->insert_drain_profit (
+ TEH_plugin->cls,
+ &dc->wtid,
+ dc->account_section,
+ dc->payto_uri,
+ dc->date,
+ &dc->amount,
+ &dc->master_sig);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert drain profit");
+ return qs;
+ }
+ return qs;
+}
+
+
+MHD_RESULT
+TEH_handler_management_post_drain (
+ struct MHD_Connection *connection,
+ const json_t *root)
+{
+ struct DrainContext dc;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("debit_account_section",
+ &dc.account_section),
+ TALER_JSON_spec_payto_uri ("credit_payto_uri",
+ &dc.payto_uri),
+ GNUNET_JSON_spec_fixed_auto ("wtid",
+ &dc.wtid),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &dc.master_sig),
+ GNUNET_JSON_spec_timestamp ("date",
+ &dc.date),
+ TALER_JSON_spec_amount ("amount",
+ TEH_currency,
+ &dc.amount),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO; /* hard failure */
+ if (GNUNET_NO == res)
+ return MHD_YES; /* failure */
+ }
+
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_profit_drain_verify (
+ &dc.wtid,
+ dc.date,
+ &dc.amount,
+ dc.account_section,
+ dc.payto_uri,
+ &TEH_master_public_key,
+ &dc.master_sig))
+ {
+ /* signature invalid */
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_MANAGEMENT_DRAIN_PROFITS_SIGNATURE_INVALID,
+ NULL);
+ }
+
+ {
+ enum GNUNET_GenericReturnValue res;
+ MHD_RESULT ret;
+
+ res = TEH_DB_run_transaction (connection,
+ "insert drain profit",
+ TEH_MT_REQUEST_OTHER,
+ &ret,
+ &drain,
+ &dc);
+ if (GNUNET_SYSERR == res)
+ return ret;
+ }
+ return TALER_MHD_reply_static (
+ connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/* end of taler-exchange-httpd_management_drain.c */
diff --git a/src/exchange/taler-exchange-httpd_management_extensions.c b/src/exchange/taler-exchange-httpd_management_extensions.c
index 83a1dfc97..3b24bace7 100644
--- a/src/exchange/taler-exchange-httpd_management_extensions.c
+++ b/src/exchange/taler-exchange-httpd_management_extensions.c
@@ -38,7 +38,7 @@
struct Extension
{
enum TALER_Extension_Type type;
- json_t *config;
+ json_t *manifest;
};
/**
@@ -52,7 +52,7 @@ struct SetExtensionsContext
};
/**
- * Function implementing database transaction to set the configuration of
+ * Function implementing database transaction to set the manifests of
* extensions. It runs the transaction logic.
* - IF it returns a non-error code, the transaction logic MUST NOT queue a
* MHD response.
@@ -74,13 +74,13 @@ set_extensions (void *cls,
{
struct SetExtensionsContext *sec = cls;
- /* save the configurations of all extensions */
+ /* save the manifests of all extensions */
for (uint32_t i = 0; i<sec->num_extensions; i++)
{
struct Extension *ext = &sec->extensions[i];
const struct TALER_Extension *taler_ext;
enum GNUNET_DB_QueryStatus qs;
- char *config;
+ char *manifest;
taler_ext = TALER_extensions_get_by_type (ext->type);
if (NULL == taler_ext)
@@ -90,10 +90,8 @@ set_extensions (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
- GNUNET_assert (NULL != ext->config);
-
- config = json_dumps (ext->config, JSON_COMPACT | JSON_SORT_KEYS);
- if (NULL == config)
+ manifest = json_dumps (ext->manifest, JSON_COMPACT | JSON_SORT_KEYS);
+ if (NULL == manifest)
{
GNUNET_break (0);
*mhd_ret = TALER_MHD_reply_with_error (connection,
@@ -103,10 +101,12 @@ set_extensions (void *cls,
return GNUNET_DB_STATUS_HARD_ERROR;
}
- qs = TEH_plugin->set_extension_config (
+ qs = TEH_plugin->set_extension_manifest (
TEH_plugin->cls,
taler_ext->name,
- config);
+ manifest);
+
+ free (manifest);
if (qs < 0)
{
@@ -137,6 +137,7 @@ set_extensions (void *cls,
/* All extensions configured, update the signature */
TEH_extensions_sig = sec->extensions_sig;
+ TEH_extensions_signed = true;
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; /* only 'success', so >=0, matters here */
}
@@ -144,13 +145,13 @@ set_extensions (void *cls,
static enum GNUNET_GenericReturnValue
verify_extensions_from_json (
- json_t *extensions,
+ const json_t *extensions,
struct SetExtensionsContext *sec)
{
const char*name;
const struct TALER_Extension *extension;
size_t i = 0;
- json_t *blob;
+ json_t *manifest;
GNUNET_assert (NULL != extensions);
GNUNET_assert (json_is_object (extensions));
@@ -159,7 +160,7 @@ verify_extensions_from_json (
sec->extensions = GNUNET_new_array (sec->num_extensions,
struct Extension);
- json_object_foreach (extensions, name, blob)
+ json_object_foreach ((json_t *) extensions, name, manifest)
{
int critical = 0;
json_t *config;
@@ -175,18 +176,18 @@ verify_extensions_from_json (
}
if (GNUNET_OK !=
- TALER_extensions_is_json_config (
- blob, &critical, &version, &config))
+ TALER_extensions_parse_manifest (
+ manifest, &critical, &version, &config))
return GNUNET_SYSERR;
if (critical != extension->critical
- || 0 != strcmp (version, extension->version) // TODO: libtool compare?
+ || 0 != strcmp (version, extension->version) // FIXME-oec: libtool compare
|| NULL == config
- || GNUNET_OK != extension->test_json_config (config))
+ || GNUNET_OK != extension->load_config (config, NULL))
return GNUNET_SYSERR;
sec->extensions[i].type = extension->type;
- sec->extensions[i].config = config;
+ sec->extensions[i].manifest = json_copy (manifest);
}
return GNUNET_OK;
@@ -199,11 +200,11 @@ TEH_handler_management_post_extensions (
const json_t *root)
{
MHD_RESULT ret;
- json_t *extensions;
+ const json_t *extensions;
struct SetExtensionsContext sec = {0};
struct GNUNET_JSON_Specification top_spec[] = {
- GNUNET_JSON_spec_json ("extensions",
- &extensions),
+ GNUNET_JSON_spec_object_const ("extensions",
+ &extensions),
GNUNET_JSON_spec_fixed_auto ("extensions_sig",
&sec.extensions_sig),
GNUNET_JSON_spec_end ()
@@ -222,30 +223,19 @@ TEH_handler_management_post_extensions (
return MHD_YES; /* failure */
}
- /* Ensure we have an object */
- if (! json_is_object (extensions))
- {
- GNUNET_JSON_parse_free (top_spec);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "invalid object");
- }
-
/* Verify the signature */
{
- struct TALER_ExtensionConfigHashP h_config;
+ struct TALER_ExtensionManifestsHashP h_manifests;
if (GNUNET_OK !=
- TALER_JSON_extensions_config_hash (extensions, &h_config) ||
+ TALER_JSON_extensions_manifests_hash (extensions,
+ &h_manifests) ||
GNUNET_OK !=
- TALER_exchange_offline_extension_config_hash_verify (
- &h_config,
+ TALER_exchange_offline_extension_manifests_hash_verify (
+ &h_manifests,
&TEH_master_public_key,
&sec.extensions_sig))
{
- GNUNET_JSON_parse_free (top_spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_BAD_REQUEST,
@@ -261,7 +251,6 @@ TEH_handler_management_post_extensions (
if (GNUNET_OK !=
verify_extensions_from_json (extensions, &sec))
{
- GNUNET_JSON_parse_free (top_spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_BAD_REQUEST,
@@ -298,13 +287,12 @@ TEH_handler_management_post_extensions (
CLEANUP:
for (unsigned int i = 0; i < sec.num_extensions; i++)
{
- if (NULL != sec.extensions[i].config)
+ if (NULL != sec.extensions[i].manifest)
{
- json_decref (sec.extensions[i].config);
+ json_decref (sec.extensions[i].manifest);
}
}
GNUNET_free (sec.extensions);
- GNUNET_JSON_parse_free (top_spec);
return ret;
}
diff --git a/src/exchange/taler-exchange-httpd_management_global_fees.c b/src/exchange/taler-exchange-httpd_management_global_fees.c
index 37bb40d90..8203ddefb 100644
--- a/src/exchange/taler-exchange-httpd_management_global_fees.c
+++ b/src/exchange/taler-exchange-httpd_management_global_fees.c
@@ -103,7 +103,6 @@ add_fee (void *cls,
enum GNUNET_DB_QueryStatus qs;
struct TALER_GlobalFeeSet fees;
struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
struct GNUNET_TIME_Relative history_expiration;
uint32_t purse_account_limit;
@@ -113,7 +112,6 @@ add_fee (void *cls,
afc->end_time,
&fees,
&purse_timeout,
- &kyc_timeout,
&history_expiration,
&purse_account_limit);
if (qs < 0)
@@ -155,7 +153,6 @@ add_fee (void *cls,
afc->end_time,
&afc->fees,
afc->purse_timeout,
- afc->kyc_timeout,
afc->history_expiration,
afc->purse_account_limit,
&afc->master_sig);
@@ -190,9 +187,6 @@ TEH_handler_management_post_global_fees (
TALER_JSON_spec_amount ("history_fee",
TEH_currency,
&afc.fees.history),
- TALER_JSON_spec_amount ("kyc_fee",
- TEH_currency,
- &afc.fees.kyc),
TALER_JSON_spec_amount ("account_fee",
TEH_currency,
&afc.fees.account),
@@ -201,8 +195,6 @@ TEH_handler_management_post_global_fees (
&afc.fees.purse),
GNUNET_JSON_spec_relative_time ("purse_timeout",
&afc.purse_timeout),
- GNUNET_JSON_spec_relative_time ("kyc_timeout",
- &afc.kyc_timeout),
GNUNET_JSON_spec_relative_time ("history_expiration",
&afc.history_expiration),
GNUNET_JSON_spec_uint32 ("purse_account_limit",
@@ -229,7 +221,6 @@ TEH_handler_management_post_global_fees (
afc.end_time,
&afc.fees,
afc.purse_timeout,
- afc.kyc_timeout,
afc.history_expiration,
afc.purse_account_limit,
&TEH_master_public_key,
diff --git a/src/exchange/taler-exchange-httpd_management_partners.c b/src/exchange/taler-exchange-httpd_management_partners.c
new file mode 100644
index 000000000..fc8a4207d
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_management_partners.c
@@ -0,0 +1,132 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_management_partners.c
+ * @brief Handle request to add exchange partner
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <pthread.h>
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_signatures.h"
+#include "taler-exchange-httpd_management.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+MHD_RESULT
+TEH_handler_management_partners (
+ struct MHD_Connection *connection,
+ const json_t *root)
+{
+ struct TALER_MasterPublicKeyP partner_pub;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct GNUNET_TIME_Relative wad_frequency;
+ struct TALER_Amount wad_fee;
+ const char *partner_base_url;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("partner_pub",
+ &partner_pub),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &master_sig),
+ TALER_JSON_spec_web_url ("partner_base_url",
+ &partner_base_url),
+ TALER_JSON_spec_amount ("wad_fee",
+ TEH_currency,
+ &wad_fee),
+ GNUNET_JSON_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_JSON_spec_timestamp ("end_date",
+ &end_date),
+ GNUNET_JSON_spec_relative_time ("wad_frequency",
+ &wad_frequency),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ return MHD_NO; /* hard failure */
+ if (GNUNET_NO == res)
+ return MHD_YES; /* failure */
+ }
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_partner_details_verify (
+ &partner_pub,
+ start_date,
+ end_date,
+ wad_frequency,
+ &wad_fee,
+ partner_base_url,
+ &TEH_master_public_key,
+ &master_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_MANAGEMENT_ADD_PARTNER_SIGNATURE_INVALID,
+ NULL);
+ }
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->insert_partner (TEH_plugin->cls,
+ &partner_pub,
+ start_date,
+ end_date,
+ wad_frequency,
+ &wad_fee,
+ partner_base_url,
+ &master_sig);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "add_partner");
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ /* FIXME-#7271: check for idempotency! */
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_MANAGEMENT_ADD_PARTNER_DATA_CONFLICT,
+ NULL);
+ }
+ }
+ return TALER_MHD_reply_static (
+ connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/* end of taler-exchange-httpd_management_partners.c */
diff --git a/src/exchange/taler-exchange-httpd_management_post_keys.c b/src/exchange/taler-exchange-httpd_management_post_keys.c
index 7d9853e9b..f91f24c41 100644
--- a/src/exchange/taler-exchange-httpd_management_post_keys.c
+++ b/src/exchange/taler-exchange-httpd_management_post_keys.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020, 2021 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -47,6 +47,16 @@ struct DenomSig
*/
struct TALER_MasterSignatureP master_sig;
+ /**
+ * Fee structure for this key, as per our configuration.
+ */
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
+
+ /**
+ * The full public key.
+ */
+ struct TALER_DenominationPublicKey denom_pub;
+
};
@@ -65,6 +75,11 @@ struct SigningSig
*/
struct TALER_MasterSignatureP master_sig;
+ /**
+ * Our meta data on this key.
+ */
+ struct TALER_EXCHANGEDB_SignkeyMetaData meta;
+
};
@@ -128,14 +143,9 @@ add_keys (void *cls,
{
struct DenomSig *d = &akc->d_sigs[i];
enum GNUNET_DB_QueryStatus qs;
- bool is_active = false;
struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
- struct TALER_DenominationPublicKey denom_pub;
/* For idempotency, check if the key is already active */
- memset (&denom_pub,
- 0,
- sizeof (denom_pub));
qs = TEH_plugin->lookup_denomination_key (
TEH_plugin->cls,
&d->h_denom_pub,
@@ -151,66 +161,9 @@ add_keys (void *cls,
"lookup denomination key");
return qs;
}
- if (0 == qs)
- {
- enum GNUNET_GenericReturnValue rv;
-
- rv = TEH_keys_load_fees (akc->ksh,
- &d->h_denom_pub,
- &denom_pub,
- &meta);
- switch (rv)
- {
- case GNUNET_SYSERR:
- *mhd_ret = TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
- GNUNET_h2s (&d->h_denom_pub.hash));
- return GNUNET_DB_STATUS_HARD_ERROR;
- case GNUNET_NO:
- *mhd_ret = TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
- GNUNET_h2s (&d->h_denom_pub.hash));
- return GNUNET_DB_STATUS_HARD_ERROR;
- case GNUNET_OK:
- break;
- }
- }
- else
- {
- is_active = true;
- }
-
- /* check signature is valid */
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_exchange_offline_denom_validity_verify (
- &d->h_denom_pub,
- meta.start,
- meta.expire_withdraw,
- meta.expire_deposit,
- meta.expire_legal,
- &meta.value,
- &meta.fees,
- &TEH_master_public_key,
- &d->master_sig))
- {
- GNUNET_break_op (0);
- *mhd_ret = TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_MANAGEMENT_KEYS_DENOMKEY_ADD_SIGNATURE_INVALID,
- GNUNET_h2s (&d->h_denom_pub.hash));
- if (! is_active)
- TALER_denom_pub_free (&denom_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- if (is_active)
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{
+ /* FIXME: assert meta === d->meta might be good */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Denomination key %s already active, skipping\n",
GNUNET_h2s (&d->h_denom_pub.hash));
@@ -220,10 +173,9 @@ add_keys (void *cls,
qs = TEH_plugin->add_denomination_key (
TEH_plugin->cls,
&d->h_denom_pub,
- &denom_pub,
- &meta,
+ &d->denom_pub,
+ &d->meta,
&d->master_sig);
- TALER_denom_pub_free (&denom_pub);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -245,7 +197,6 @@ add_keys (void *cls,
{
struct SigningSig *s = &akc->s_sigs[i];
enum GNUNET_DB_QueryStatus qs;
- bool is_active = false;
struct TALER_EXCHANGEDB_SignkeyMetaData meta;
qs = TEH_plugin->lookup_signing_key (
@@ -263,47 +214,9 @@ add_keys (void *cls,
"lookup signing key");
return qs;
}
- if (0 == qs)
- {
- if (GNUNET_OK !=
- TEH_keys_get_timing (&s->exchange_pub,
- &meta))
- {
- /* For idempotency, check if the key is already active */
- *mhd_ret = TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_UNKNOWN,
- TALER_B2S (&s->exchange_pub));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- else
- {
- is_active = true; /* if we pass, it's active! */
- }
-
- /* check signature is valid */
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_exchange_offline_signkey_validity_verify (
- &s->exchange_pub,
- meta.start,
- meta.expire_sign,
- meta.expire_legal,
- &TEH_master_public_key,
- &s->master_sig))
- {
- GNUNET_break_op (0);
- *mhd_ret = TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_ADD_SIGNATURE_INVALID,
- TALER_B2S (&s->exchange_pub));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (is_active)
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
{
+ /* FIXME: assert meta === d->meta might be good */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Signing key %s already active, skipping\n",
TALER_B2S (&s->exchange_pub));
@@ -312,7 +225,7 @@ add_keys (void *cls,
qs = TEH_plugin->activate_signing_key (
TEH_plugin->cls,
&s->exchange_pub,
- &meta,
+ &s->meta,
&s->master_sig);
if (qs < 0)
{
@@ -334,22 +247,40 @@ add_keys (void *cls,
}
+/**
+ * Clean up state in @a akc, but do not free @a akc itself
+ *
+ * @param[in,out] akc state to clean up
+ */
+static void
+cleanup_akc (struct AddKeysContext *akc)
+{
+ for (unsigned int i = 0; i<akc->nd_sigs; i++)
+ {
+ struct DenomSig *d = &akc->d_sigs[i];
+
+ TALER_denom_pub_free (&d->denom_pub);
+ }
+ GNUNET_free (akc->d_sigs);
+ GNUNET_free (akc->s_sigs);
+}
+
+
MHD_RESULT
TEH_handler_management_post_keys (
struct MHD_Connection *connection,
const json_t *root)
{
- struct AddKeysContext akc;
- json_t *denom_sigs;
- json_t *signkey_sigs;
+ struct AddKeysContext akc = { 0 };
+ const json_t *denom_sigs;
+ const json_t *signkey_sigs;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("denom_sigs",
- &denom_sigs),
- GNUNET_JSON_spec_json ("signkey_sigs",
- &signkey_sigs),
+ GNUNET_JSON_spec_array_const ("denom_sigs",
+ &denom_sigs),
+ GNUNET_JSON_spec_array_const ("signkey_sigs",
+ &signkey_sigs),
GNUNET_JSON_spec_end ()
};
- bool ok;
MHD_RESULT ret;
{
@@ -363,35 +294,23 @@ TEH_handler_management_post_keys (
if (GNUNET_NO == res)
return MHD_YES; /* failure */
}
- if (! (json_is_array (denom_sigs) &&
- json_is_array (signkey_sigs)) )
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "array expected for denom_sigs and signkey_sigs");
- }
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received /management/keys\n");
- akc.ksh = TEH_keys_get_state2 (true); /* may start its own transaction, thus
- must be done here, before we run ours! */
+ "Received POST /management/keys request\n");
+
+ akc.ksh = TEH_keys_get_state_for_management_only (); /* may start its own transaction, thus must be done here, before we run ours! */
if (NULL == akc.ksh)
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
"no key state (not even for management)");
}
+
akc.nd_sigs = json_array_size (denom_sigs);
akc.d_sigs = GNUNET_new_array (akc.nd_sigs,
struct DenomSig);
- ok = true;
for (unsigned int i = 0; i<akc.nd_sigs; i++)
{
struct DenomSig *d = &akc.d_sigs[i];
@@ -408,27 +327,64 @@ TEH_handler_management_post_keys (
json_array_get (denom_sigs,
i),
ispec);
- if (GNUNET_SYSERR == res)
+ if (GNUNET_OK != res)
{
- ret = MHD_NO; /* hard failure */
- ok = false;
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failure to handle /management/keys\n");
+ cleanup_akc (&akc);
+ return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
- if (GNUNET_NO == res)
+
+ res = TEH_keys_load_fees (akc.ksh,
+ &d->h_denom_pub,
+ &d->denom_pub,
+ &d->meta);
+ switch (res)
{
- ret = MHD_YES;
- ok = false;
+ case GNUNET_SYSERR:
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ GNUNET_h2s (&d->h_denom_pub.hash));
+ cleanup_akc (&akc);
+ return ret;
+ case GNUNET_NO:
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
+ GNUNET_h2s (&d->h_denom_pub.hash));
+ cleanup_akc (&akc);
+ return ret;
+ case GNUNET_OK:
break;
}
+ /* check signature is valid */
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_denom_validity_verify (
+ &d->h_denom_pub,
+ d->meta.start,
+ d->meta.expire_withdraw,
+ d->meta.expire_deposit,
+ d->meta.expire_legal,
+ &d->meta.value,
+ &d->meta.fees,
+ &TEH_master_public_key,
+ &d->master_sig))
+ {
+ GNUNET_break_op (0);
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_MANAGEMENT_KEYS_DENOMKEY_ADD_SIGNATURE_INVALID,
+ GNUNET_h2s (&d->h_denom_pub.hash));
+ cleanup_akc (&akc);
+ return ret;
+ }
}
- if (! ok)
- {
- GNUNET_free (akc.d_sigs);
- GNUNET_JSON_parse_free (spec);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failure to handle /management/keys\n");
- return ret;
- }
+
akc.ns_sigs = json_array_size (signkey_sigs);
akc.s_sigs = GNUNET_new_array (akc.ns_sigs,
struct SigningSig);
@@ -448,27 +404,58 @@ TEH_handler_management_post_keys (
json_array_get (signkey_sigs,
i),
ispec);
- if (GNUNET_SYSERR == res)
+ if (GNUNET_OK != res)
{
- ret = MHD_NO; /* hard failure */
- ok = false;
- break;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failure to handle /management/keys\n");
+ cleanup_akc (&akc);
+ return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
}
- if (GNUNET_NO == res)
+ res = TEH_keys_get_timing (&s->exchange_pub,
+ &s->meta);
+ switch (res)
{
- ret = MHD_YES;
- ok = false;
+ case GNUNET_SYSERR:
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ TALER_B2S (&s->exchange_pub));
+ cleanup_akc (&akc);
+ return ret;
+ case GNUNET_NO:
+ /* For idempotency, check if the key is already active */
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_UNKNOWN,
+ TALER_B2S (&s->exchange_pub));
+ cleanup_akc (&akc);
+ return ret;
+ case GNUNET_OK:
break;
}
- }
- if (! ok)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failure to handle /management/keys\n");
- GNUNET_free (akc.d_sigs);
- GNUNET_free (akc.s_sigs);
- GNUNET_JSON_parse_free (spec);
- return ret;
+
+ /* check signature is valid */
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_exchange_offline_signkey_validity_verify (
+ &s->exchange_pub,
+ s->meta.start,
+ s->meta.expire_sign,
+ s->meta.expire_legal,
+ &TEH_master_public_key,
+ &s->master_sig))
+ {
+ GNUNET_break_op (0);
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_MANAGEMENT_KEYS_SIGNKEY_ADD_SIGNATURE_INVALID,
+ TALER_B2S (&s->exchange_pub));
+ cleanup_akc (&akc);
+ return ret;
+ }
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received %u denomination and %u signing key signatures\n",
@@ -483,9 +470,7 @@ TEH_handler_management_post_keys (
&ret,
&add_keys,
&akc);
- GNUNET_free (akc.d_sigs);
- GNUNET_free (akc.s_sigs);
- GNUNET_JSON_parse_free (spec);
+ cleanup_akc (&akc);
if (GNUNET_SYSERR == res)
return ret;
}
diff --git a/src/exchange/taler-exchange-httpd_management_wire_disable.c b/src/exchange/taler-exchange-httpd_management_wire_disable.c
index 34825eda3..e0b8a3de8 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_disable.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_disable.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -28,7 +28,7 @@
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "taler-exchange-httpd_wire.h"
+#include "taler-exchange-httpd_keys.h"
/**
@@ -103,7 +103,7 @@ del_wire (void *cls,
NULL);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (0 == qs)
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
{
*mhd_ret = TALER_MHD_reply_with_error (
connection,
@@ -114,7 +114,13 @@ del_wire (void *cls,
}
qs = TEH_plugin->update_wire (TEH_plugin->cls,
awc->payto_uri,
+ NULL,
+ NULL,
+ NULL,
awc->validity_end,
+ NULL,
+ NULL,
+ 0,
false);
if (qs < 0)
{
@@ -140,8 +146,8 @@ TEH_handler_management_post_wire_disable (
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("master_sig_del",
&awc.master_sig),
- GNUNET_JSON_spec_string ("payto_uri",
- &awc.payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &awc.payto_uri),
GNUNET_JSON_spec_timestamp ("validity_end",
&awc.validity_end),
GNUNET_JSON_spec_end ()
diff --git a/src/exchange/taler-exchange-httpd_management_wire_enable.c b/src/exchange/taler-exchange-httpd_management_wire_enable.c
index 25ee0eeac..472e19d3e 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_enable.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_enable.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -29,7 +29,7 @@
#include "taler_signatures.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "taler-exchange-httpd_wire.h"
+#include "taler-exchange-httpd_keys.h"
/**
@@ -55,10 +55,35 @@ struct AddWireContext
const char *payto_uri;
/**
+ * (optional) address of a conversion service for this account.
+ */
+ const char *conversion_url;
+
+ /**
+ * Restrictions imposed when crediting this account.
+ */
+ const json_t *credit_restrictions;
+
+ /**
+ * Restrictions imposed when debiting this account.
+ */
+ const json_t *debit_restrictions;
+
+ /**
* Timestamp for checking against replay attacks.
*/
struct GNUNET_TIME_Timestamp validity_start;
+ /**
+ * Label to use for this bank. Default is empty.
+ */
+ const char *bank_label;
+
+ /**
+ * Priority of the bank in the list. Default 0.
+ */
+ int64_t priority;
+
};
@@ -111,15 +136,26 @@ add_wire (void *cls,
NULL);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (0 == qs)
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
qs = TEH_plugin->insert_wire (TEH_plugin->cls,
awc->payto_uri,
+ awc->conversion_url,
+ awc->debit_restrictions,
+ awc->credit_restrictions,
awc->validity_start,
- &awc->master_sig_wire);
+ &awc->master_sig_wire,
+ awc->bank_label,
+ awc->priority);
else
qs = TEH_plugin->update_wire (TEH_plugin->cls,
awc->payto_uri,
+ awc->conversion_url,
+ awc->debit_restrictions,
+ awc->credit_restrictions,
awc->validity_start,
+ &awc->master_sig_wire,
+ awc->bank_label,
+ awc->priority,
true);
if (qs < 0)
{
@@ -141,16 +177,34 @@ TEH_handler_management_post_wire (
struct MHD_Connection *connection,
const json_t *root)
{
- struct AddWireContext awc;
+ struct AddWireContext awc = {
+ .conversion_url = NULL
+ };
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("master_sig_wire",
&awc.master_sig_wire),
GNUNET_JSON_spec_fixed_auto ("master_sig_add",
&awc.master_sig_add),
- GNUNET_JSON_spec_string ("payto_uri",
- &awc.payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &awc.payto_uri),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_web_url ("conversion_url",
+ &awc.conversion_url),
+ NULL),
+ GNUNET_JSON_spec_array_const ("credit_restrictions",
+ &awc.credit_restrictions),
+ GNUNET_JSON_spec_array_const ("debit_restrictions",
+ &awc.debit_restrictions),
GNUNET_JSON_spec_timestamp ("validity_start",
&awc.validity_start),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("bank_label",
+ &awc.bank_label),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_int64 ("priority",
+ &awc.priority),
+ NULL),
GNUNET_JSON_spec_end ()
};
@@ -179,17 +233,23 @@ TEH_handler_management_post_wire (
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PAYTO_URI_MALFORMED,
msg);
+ GNUNET_JSON_parse_free (spec);
GNUNET_free (msg);
return ret;
}
}
if (GNUNET_OK !=
- TALER_exchange_offline_wire_add_verify (awc.payto_uri,
- awc.validity_start,
- &TEH_master_public_key,
- &awc.master_sig_add))
+ TALER_exchange_offline_wire_add_verify (
+ awc.payto_uri,
+ awc.conversion_url,
+ awc.debit_restrictions,
+ awc.credit_restrictions,
+ awc.validity_start,
+ &TEH_master_public_key,
+ &awc.master_sig_add))
{
GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
@@ -198,11 +258,16 @@ TEH_handler_management_post_wire (
}
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
- TALER_exchange_wire_signature_check (awc.payto_uri,
- &TEH_master_public_key,
- &awc.master_sig_wire))
+ TALER_exchange_wire_signature_check (
+ awc.payto_uri,
+ awc.conversion_url,
+ awc.debit_restrictions,
+ awc.credit_restrictions,
+ &TEH_master_public_key,
+ &awc.master_sig_wire))
{
GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
@@ -218,6 +283,7 @@ TEH_handler_management_post_wire (
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"payto:// URI `%s' is malformed\n",
awc.payto_uri);
+ GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_BAD_REQUEST,
@@ -237,6 +303,7 @@ TEH_handler_management_post_wire (
&ret,
&add_wire,
&awc);
+ GNUNET_JSON_parse_free (spec);
if (GNUNET_SYSERR == res)
return ret;
}
diff --git a/src/exchange/taler-exchange-httpd_management_wire_fees.c b/src/exchange/taler-exchange-httpd_management_wire_fees.c
index 2a4262131..cb87592a5 100644
--- a/src/exchange/taler-exchange-httpd_management_wire_fees.c
+++ b/src/exchange/taler-exchange-httpd_management_wire_fees.c
@@ -29,7 +29,7 @@
#include "taler_signatures.h"
#include "taler-exchange-httpd_management.h"
#include "taler-exchange-httpd_responses.h"
-#include "taler-exchange-httpd_wire.h"
+#include "taler-exchange-httpd_keys.h"
/**
@@ -170,9 +170,6 @@ TEH_handler_management_post_wire_fees (
TALER_JSON_spec_amount ("closing_fee",
TEH_currency,
&afc.fees.closing),
- TALER_JSON_spec_amount ("wad_fee",
- TEH_currency,
- &afc.fees.wad),
GNUNET_JSON_spec_end ()
};
diff --git a/src/exchange/taler-exchange-httpd_melt.c b/src/exchange/taler-exchange-httpd_melt.c
index 1e5c92e18..b31078f00 100644
--- a/src/exchange/taler-exchange-httpd_melt.c
+++ b/src/exchange/taler-exchange-httpd_melt.c
@@ -288,7 +288,7 @@ static MHD_RESULT
check_melt_valid (struct MHD_Connection *connection,
struct MeltContext *rmc)
{
- /* Baseline: check if deposits/refreshs are generally
+ /* Baseline: check if deposits/refreshes are generally
simply still allowed for this denomination */
struct TEH_DenominationKey *dk;
MHD_RESULT mret;
@@ -338,12 +338,12 @@ check_melt_valid (struct MHD_Connection *connection,
TALER_EC_EXCHANGE_MELT_FEES_EXCEED_CONTRIBUTION,
NULL);
}
- switch (dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
break;
default:
diff --git a/src/exchange/taler-exchange-httpd_metrics.h b/src/exchange/taler-exchange-httpd_metrics.h
index c1b7326ff..318113c1f 100644
--- a/src/exchange/taler-exchange-httpd_metrics.h
+++ b/src/exchange/taler-exchange-httpd_metrics.h
@@ -34,17 +34,20 @@ enum TEH_MetricTypeRequest
TEH_MT_REQUEST_OTHER = 0,
TEH_MT_REQUEST_DEPOSIT = 1,
TEH_MT_REQUEST_WITHDRAW = 2,
- TEH_MT_REQUEST_MELT = 3,
- TEH_MT_REQUEST_PURSE_CREATE = 4,
- TEH_MT_REQUEST_PURSE_MERGE = 5,
- TEH_MT_REQUEST_RESERVE_PURSE = 6,
- TEH_MT_REQUEST_PURSE_DEPOSIT = 7,
- TEH_MT_REQUEST_IDEMPOTENT_DEPOSIT = 8,
- TEH_MT_REQUEST_IDEMPOTENT_WITHDRAW = 9,
- TEH_MT_REQUEST_IDEMPOTENT_MELT = 10,
- TEH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW = 11,
- TEH_MT_REQUEST_BATCH_DEPOSIT = 12,
- TEH_MT_REQUEST_COUNT = 13 /* MUST BE LAST! */
+ TEH_MT_REQUEST_AGE_WITHDRAW = 3,
+ TEH_MT_REQUEST_MELT = 4,
+ TEH_MT_REQUEST_PURSE_CREATE = 5,
+ TEH_MT_REQUEST_PURSE_MERGE = 6,
+ TEH_MT_REQUEST_RESERVE_PURSE = 7,
+ TEH_MT_REQUEST_PURSE_DEPOSIT = 8,
+ TEH_MT_REQUEST_IDEMPOTENT_DEPOSIT = 9,
+ TEH_MT_REQUEST_IDEMPOTENT_WITHDRAW = 10,
+ TEH_MT_REQUEST_IDEMPOTENT_AGE_WITHDRAW = 11,
+ TEH_MT_REQUEST_IDEMPOTENT_MELT = 12,
+ TEH_MT_REQUEST_IDEMPOTENT_BATCH_WITHDRAW = 13,
+ TEH_MT_REQUEST_BATCH_DEPOSIT = 14,
+ TEH_MT_REQUEST_POLICY_FULFILLMENT = 15,
+ TEH_MT_REQUEST_COUNT = 16 /* MUST BE LAST! */
};
/**
@@ -54,10 +57,12 @@ enum TEH_MetricTypeSuccess
{
TEH_MT_SUCCESS_DEPOSIT = 0,
TEH_MT_SUCCESS_WITHDRAW = 1,
- TEH_MT_SUCCESS_BATCH_WITHDRAW = 2,
- TEH_MT_SUCCESS_MELT = 3,
- TEH_MT_SUCCESS_REFRESH_REVEAL = 4,
- TEH_MT_SUCCESS_COUNT = 5 /* MUST BE LAST! */
+ TEH_MT_SUCCESS_AGE_WITHDRAW = 2,
+ TEH_MT_SUCCESS_BATCH_WITHDRAW = 3,
+ TEH_MT_SUCCESS_MELT = 4,
+ TEH_MT_SUCCESS_REFRESH_REVEAL = 5,
+ TEH_MT_SUCCESS_AGE_WITHDRAW_REVEAL = 6,
+ TEH_MT_SUCCESS_COUNT = 7 /* MUST BE LAST! */
};
/**
diff --git a/src/exchange/taler-exchange-httpd_purses_create.c b/src/exchange/taler-exchange-httpd_purses_create.c
index 9cabdb1a1..2de9468fe 100644
--- a/src/exchange/taler-exchange-httpd_purses_create.c
+++ b/src/exchange/taler-exchange-httpd_purses_create.c
@@ -39,15 +39,6 @@
*/
struct PurseCreateContext
{
- /**
- * Public key of the purse we are creating.
- */
- const struct TALER_PurseContractPublicKeyP *purse_pub;
-
- /**
- * Total amount to be put into the purse.
- */
- struct TALER_Amount amount;
/**
* Total actually deposited by all the coins.
@@ -55,11 +46,6 @@ struct PurseCreateContext
struct TALER_Amount deposit_total;
/**
- * When should the purse expire.
- */
- struct GNUNET_TIME_Timestamp purse_expiration;
-
- /**
* Our current time.
*/
struct GNUNET_TIME_Timestamp exchange_timestamp;
@@ -80,9 +66,9 @@ struct PurseCreateContext
struct TALER_PurseContractSignatureP purse_sig;
/**
- * Hash of the contract terms of the purse.
+ * Fundamental details about the purse.
*/
- struct TALER_PrivateContractHashP h_contract_terms;
+ struct TEH_PurseDetails pd;
/**
* Array of coins being deposited.
@@ -108,52 +94,6 @@ struct PurseCreateContext
/**
- * Send confirmation of purse creation success to client.
- *
- * @param connection connection to the client
- * @param pcc details about the request that succeeded
- * @return MHD result code
- */
-static MHD_RESULT
-reply_create_success (struct MHD_Connection *connection,
- const struct PurseCreateContext *pcc)
-{
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
- enum TALER_ErrorCode ec;
-
- if (TALER_EC_NONE !=
- (ec = TALER_exchange_online_purse_created_sign (
- &TEH_keys_exchange_sign_,
- pcc->exchange_timestamp,
- pcc->purse_expiration,
- &pcc->amount,
- &pcc->deposit_total,
- pcc->purse_pub,
- &pcc->h_contract_terms,
- &pub,
- &sig)))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_ec (connection,
- ec,
- NULL);
- }
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_amount ("total_deposited",
- &pcc->deposit_total),
- GNUNET_JSON_pack_timestamp ("exchange_timestamp",
- pcc->exchange_timestamp),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &sig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &pub));
-}
-
-
-/**
* Execute database transaction for /purses/$PID/create. Runs the transaction
* logic; IF it returns a non-error code, the transaction logic MUST NOT queue
* a MHD response. IF it returns an hard error, the transaction logic MUST
@@ -177,19 +117,19 @@ create_transaction (void *cls,
bool in_conflict = true;
GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pcc->amount.currency,
+ TALER_amount_set_zero (TEH_currency,
&purse_fee));
/* 1) create purse */
qs = TEH_plugin->insert_purse_request (
TEH_plugin->cls,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
&pcc->merge_pub,
- pcc->purse_expiration,
- &pcc->h_contract_terms,
+ pcc->pd.purse_expiration,
+ &pcc->pd.h_contract_terms,
pcc->min_age,
TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE,
&purse_fee,
- &pcc->amount,
+ &pcc->pd.target_amount,
&pcc->purse_sig,
&in_conflict);
if (qs < 0)
@@ -216,15 +156,15 @@ create_transaction (void *cls,
uint32_t min_age;
TEH_plugin->rollback (TEH_plugin->cls);
- qs = TEH_plugin->select_purse_request (TEH_plugin->cls,
- pcc->purse_pub,
- &merge_pub,
- &purse_expiration,
- &h_contract_terms,
- &min_age,
- &target_amount,
- &balance,
- &purse_sig);
+ qs = TEH_plugin->get_purse_request (TEH_plugin->cls,
+ &pcc->pd.purse_pub,
+ &merge_pub,
+ &purse_expiration,
+ &h_contract_terms,
+ &min_age,
+ &target_amount,
+ &balance,
+ &purse_sig);
if (qs < 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
@@ -261,6 +201,7 @@ create_transaction (void *cls,
struct TEH_PurseDepositedCoin *coin = &pcc->coins[i];
bool balance_ok = false;
bool conflict = true;
+ bool too_late = true;
qs = TEH_make_coin_known (&coin->cpi,
connection,
@@ -269,12 +210,13 @@ create_transaction (void *cls,
if (qs < 0)
return qs;
qs = TEH_plugin->do_purse_deposit (TEH_plugin->cls,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
&coin->cpi.coin_pub,
&coin->amount,
&coin->coin_sig,
&coin->amount_minus_fee,
&balance_ok,
+ &too_late,
&conflict);
if (qs <= 0)
{
@@ -291,6 +233,10 @@ create_transaction (void *cls,
}
if (! balance_ok)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Coin %s has insufficient balance for purse deposit of amount %s\n",
+ TALER_B2S (&coin->cpi.coin_pub),
+ TALER_amount2s (&coin->amount));
*mhd_ret
= TEH_RESPONSE_reply_coin_insufficient_funds (
connection,
@@ -299,6 +245,15 @@ create_transaction (void *cls,
&coin->cpi.coin_pub);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ if (too_late)
+ {
+ *mhd_ret
+ = TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "too late to deposit on purse creation");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
if (conflict)
{
struct TALER_Amount amount;
@@ -310,7 +265,7 @@ create_transaction (void *cls,
TEH_plugin->rollback (TEH_plugin->cls);
qs = TEH_plugin->get_purse_deposit (TEH_plugin->cls,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
&coin->cpi.coin_pub,
&amount,
&h_denom_pub,
@@ -357,7 +312,7 @@ create_transaction (void *cls,
{
in_conflict = true;
qs = TEH_plugin->insert_contract (TEH_plugin->cls,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
&pcc->econtract,
&in_conflict);
if (qs < 0)
@@ -378,7 +333,7 @@ create_transaction (void *cls,
qs = TEH_plugin->select_contract_by_purse (
TEH_plugin->cls,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
&econtract);
if (qs <= 0)
{
@@ -444,7 +399,7 @@ parse_coin (struct MHD_Connection *connection,
(iret = TEH_common_deposit_check_purse_deposit (
connection,
coin,
- pcc->purse_pub,
+ &pcc->pd.purse_pub,
pcc->min_age)))
return iret;
if (0 >
@@ -472,16 +427,16 @@ TEH_handler_purses_create (
const json_t *root)
{
struct PurseCreateContext pcc = {
- .purse_pub = purse_pub,
+ .pd.purse_pub = *purse_pub,
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
};
- json_t *deposits;
+ const json_t *deposits;
json_t *deposit;
unsigned int idx;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("amount",
TEH_currency,
- &pcc.amount),
+ &pcc.pd.target_amount),
GNUNET_JSON_spec_uint32 ("min_age",
&pcc.min_age),
GNUNET_JSON_spec_mark_optional (
@@ -493,11 +448,11 @@ TEH_handler_purses_create (
GNUNET_JSON_spec_fixed_auto ("purse_sig",
&pcc.purse_sig),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &pcc.h_contract_terms),
- GNUNET_JSON_spec_json ("deposits",
- &deposits),
+ &pcc.pd.h_contract_terms),
+ GNUNET_JSON_spec_array_const ("deposits",
+ &deposits),
GNUNET_JSON_spec_timestamp ("purse_expiration",
- &pcc.purse_expiration),
+ &pcc.pd.purse_expiration),
GNUNET_JSON_spec_end ()
};
const struct TEH_GlobalFee *gf;
@@ -522,21 +477,19 @@ TEH_handler_purses_create (
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TEH_currency,
&pcc.deposit_total));
- if (GNUNET_TIME_timestamp_cmp (pcc.purse_expiration,
+ if (GNUNET_TIME_timestamp_cmp (pcc.pd.purse_expiration,
<,
pcc.exchange_timestamp))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_PURSE_CREATE_EXPIRATION_BEFORE_NOW,
NULL);
}
- if (GNUNET_TIME_absolute_is_never (pcc.purse_expiration.abs_time))
+ if (GNUNET_TIME_absolute_is_never (pcc.pd.purse_expiration.abs_time))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_EXCHANGE_PURSE_CREATE_EXPIRATION_IS_NEVER,
@@ -547,7 +500,6 @@ TEH_handler_purses_create (
(pcc.num_coins > TALER_MAX_FRESH_COINS) )
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
@@ -560,7 +512,6 @@ TEH_handler_purses_create (
if (NULL == keys)
{
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
@@ -592,7 +543,6 @@ TEH_handler_purses_create (
deposit);
if (GNUNET_OK != res)
{
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<idx; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -604,7 +554,6 @@ TEH_handler_purses_create (
&pcc.deposit_total))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
GNUNET_free (pcc.coins);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
@@ -615,16 +564,15 @@ TEH_handler_purses_create (
if (GNUNET_OK !=
TALER_wallet_purse_create_verify (
- pcc.purse_expiration,
- &pcc.h_contract_terms,
+ pcc.pd.purse_expiration,
+ &pcc.pd.h_contract_terms,
&pcc.merge_pub,
pcc.min_age,
- &pcc.amount,
- pcc.purse_pub,
+ &pcc.pd.target_amount,
+ &pcc.pd.purse_pub,
&pcc.purse_sig))
{
TALER_LOG_WARNING ("Invalid signature on /purses/$PID/create request\n");
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -642,7 +590,6 @@ TEH_handler_purses_create (
&pcc.econtract.econtract_sig)) )
{
TALER_LOG_WARNING ("Invalid signature on /purses/$PID/create request\n");
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -657,7 +604,6 @@ TEH_handler_purses_create (
TEH_plugin->preflight (TEH_plugin->cls))
{
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -679,7 +625,6 @@ TEH_handler_purses_create (
&create_transaction,
&pcc))
{
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -691,12 +636,13 @@ TEH_handler_purses_create (
{
MHD_RESULT res;
- res = reply_create_success (connection,
- &pcc);
+ res = TEH_RESPONSE_reply_purse_created (connection,
+ pcc.exchange_timestamp,
+ &pcc.deposit_total,
+ &pcc.pd);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
- GNUNET_JSON_parse_free (spec);
return res;
}
}
diff --git a/src/exchange/taler-exchange-httpd_purses_delete.c b/src/exchange/taler-exchange-httpd_purses_delete.c
new file mode 100644
index 000000000..5bf7c24c9
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_purses_delete.c
@@ -0,0 +1,141 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_purses_delete.c
+ * @brief Handle DELETE /purses/$PID requests; parses the request and
+ * verifies the signature before handing deletion to the database.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include "taler_dbevents.h"
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_common_deposit.h"
+#include "taler-exchange-httpd_purses_delete.h"
+#include "taler-exchange-httpd_responses.h"
+#include "taler_exchangedb_lib.h"
+#include "taler-exchange-httpd_keys.h"
+
+
+MHD_RESULT
+TEH_handler_purses_delete (
+ struct TEH_RequestContext *rc,
+ const char *const args[1])
+{
+ struct MHD_Connection *connection = rc->connection;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseContractSignatureP purse_sig;
+ bool found;
+ bool decided;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &purse_pub,
+ sizeof (purse_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_PURSE_PUB_MALFORMED,
+ args[0]);
+ }
+ TALER_MHD_parse_request_header_auto_t (connection,
+ "Taler-Purse-Signature",
+ &purse_sig);
+ if (GNUNET_OK !=
+ TALER_wallet_purse_delete_verify (&purse_pub,
+ &purse_sig))
+ {
+ TALER_LOG_WARNING ("Invalid signature on /purses/$PID/delete request\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_PURSE_DELETE_SIGNATURE_INVALID,
+ NULL);
+ }
+ if (GNUNET_SYSERR ==
+ TEH_plugin->preflight (TEH_plugin->cls))
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_START_FAILED,
+ "preflight failure");
+ }
+
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_plugin->do_purse_delete (TEH_plugin->cls,
+ &purse_pub,
+ &purse_sig,
+ &decided,
+ &found);
+ if (qs <= 0)
+ {
+ TALER_LOG_WARNING (
+ "Failed to store delete purse information in database\n");
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "purse delete");
+ }
+ }
+ if (! found)
+ {
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_PURSE_UNKNOWN,
+ NULL);
+ }
+ if (decided)
+ {
+ return TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_EXCHANGE_PURSE_DELETE_ALREADY_DECIDED,
+ NULL);
+ }
+ {
+ /* Possible minor optimization: integrate notification with
+ transaction above... */
+ struct TALER_PurseEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_PURSE_DEPOSITED),
+ .purse_pub = purse_pub
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Notifying about purse deletion %s\n",
+ TALER_B2S (&purse_pub));
+ TEH_plugin->event_notify (TEH_plugin->cls,
+ &rep.header,
+ NULL,
+ 0);
+ }
+ /* success */
+ return TALER_MHD_reply_static (connection,
+ MHD_HTTP_NO_CONTENT,
+ NULL,
+ NULL,
+ 0);
+}
+
+
+/* end of taler-exchange-httpd_purses_delete.c */
diff --git a/src/auditor/taler-auditor-httpd_exchanges.h b/src/exchange/taler-exchange-httpd_purses_delete.h
index c7d8dd5fd..912dd43a8 100644
--- a/src/auditor/taler-auditor-httpd_exchanges.h
+++ b/src/exchange/taler-exchange-httpd_purses_delete.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
+ Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,33 +14,29 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file taler-auditor-httpd_exchanges.h
- * @brief Handle /exchanges requests
+ * @file taler-exchange-httpd_purses_delete.h
+ * @brief Handle DELETE /purses/$PID requests
* @author Christian Grothoff
*/
-#ifndef TALER_AUDITOR_HTTPD_EXCHANGES_H
-#define TALER_AUDITOR_HTTPD_EXCHANGES_H
+#ifndef TALER_EXCHANGE_HTTPD_PURSES_DELETE_H
+#define TALER_EXCHANGE_HTTPD_PURSES_DELETE_H
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
-#include "taler-auditor-httpd.h"
+#include "taler-exchange-httpd.h"
/**
- * Handle a "/exchanges" request.
+ * Handle a DELETE "/purses/$PURSE_PUB" request.
*
- * @param rh context of the handler
- * @param connection the MHD connection to handle
- * @param[in,out] connection_cls the connection's closure (can be updated)
- * @param upload_data upload data
- * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
+ * @param rc request details about the request to handle
+ * @param args argument with the public key of the purse
* @return MHD result code
- */
+ */
MHD_RESULT
-TAH_EXCHANGES_handler (struct TAH_RequestHandler *rh,
- struct MHD_Connection *connection,
- void **connection_cls,
- const char *upload_data,
- size_t *upload_data_size);
+TEH_handler_purses_delete (
+ struct TEH_RequestContext *rc,
+ const char *const args[1]);
+
#endif
diff --git a/src/exchange/taler-exchange-httpd_purses_deposit.c b/src/exchange/taler-exchange-httpd_purses_deposit.c
index 581abe90a..8e4d5e41a 100644
--- a/src/exchange/taler-exchange-httpd_purses_deposit.c
+++ b/src/exchange/taler-exchange-httpd_purses_deposit.c
@@ -166,6 +166,7 @@ deposit_transaction (void *cls,
struct TEH_PurseDepositedCoin *coin = &pcc->coins[i];
bool balance_ok = false;
bool conflict = true;
+ bool too_late = true;
qs = TEH_make_coin_known (&coin->cpi,
connection,
@@ -180,18 +181,20 @@ deposit_transaction (void *cls,
&coin->coin_sig,
&coin->amount_minus_fee,
&balance_ok,
+ &too_late,
&conflict);
if (qs <= 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
return qs;
+ GNUNET_break (0 != qs);
TALER_LOG_WARNING (
"Failed to store purse deposit information in database\n");
*mhd_ret = TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_DB_STORE_FAILED,
"do purse deposit");
- return qs;
+ return GNUNET_DB_STATUS_HARD_ERROR;
}
if (! balance_ok)
{
@@ -203,6 +206,16 @@ deposit_transaction (void *cls,
&coin->cpi.coin_pub);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ if (too_late)
+ {
+ TEH_plugin->rollback (TEH_plugin->cls);
+ *mhd_ret
+ = TALER_MHD_reply_with_ec (
+ connection,
+ TALER_EC_EXCHANGE_PURSE_DEPOSIT_DECIDED_ALREADY,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
if (conflict)
{
struct TALER_Amount amount;
@@ -316,12 +329,12 @@ TEH_handler_purses_deposit (
.purse_pub = purse_pub,
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
};
- json_t *deposits;
+ const json_t *deposits;
json_t *deposit;
unsigned int idx;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("deposits",
- &deposits),
+ GNUNET_JSON_spec_array_const ("deposits",
+ &deposits),
GNUNET_JSON_spec_end ()
};
@@ -350,7 +363,6 @@ TEH_handler_purses_deposit (
(pcc.num_coins > TALER_MAX_FRESH_COINS) )
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (connection,
MHD_HTTP_BAD_REQUEST,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
@@ -359,16 +371,22 @@ TEH_handler_purses_deposit (
{
enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp create_timestamp;
struct GNUNET_TIME_Timestamp merge_timestamp;
+ bool was_deleted;
+ bool was_refunded;
qs = TEH_plugin->select_purse (
TEH_plugin->cls,
pcc.purse_pub,
+ &create_timestamp,
&pcc.purse_expiration,
&pcc.amount,
&pcc.deposit_total,
&pcc.h_contract_terms,
- &merge_timestamp);
+ &merge_timestamp,
+ &was_deleted,
+ &was_refunded);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -391,12 +409,16 @@ TEH_handler_purses_deposit (
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
break; /* handled below */
}
- if (GNUNET_TIME_absolute_is_past (pcc.purse_expiration.abs_time))
+ if (was_refunded ||
+ was_deleted)
{
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_GONE,
- TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
- NULL);
+ return TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_GONE,
+ was_deleted
+ ? TALER_EC_EXCHANGE_GENERIC_PURSE_DELETED
+ : TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
+ GNUNET_TIME_timestamp2s (pcc.purse_expiration));
}
}
@@ -414,7 +436,6 @@ TEH_handler_purses_deposit (
deposit);
if (GNUNET_OK != res)
{
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<idx; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -426,7 +447,6 @@ TEH_handler_purses_deposit (
TEH_plugin->preflight (TEH_plugin->cls))
{
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -448,7 +468,6 @@ TEH_handler_purses_deposit (
&deposit_transaction,
&pcc))
{
- GNUNET_JSON_parse_free (spec);
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
@@ -480,7 +499,6 @@ TEH_handler_purses_deposit (
for (unsigned int i = 0; i<pcc.num_coins; i++)
TEH_common_purse_deposit_free_coin (&pcc.coins[i]);
GNUNET_free (pcc.coins);
- GNUNET_JSON_parse_free (spec);
return res;
}
}
diff --git a/src/exchange/taler-exchange-httpd_purses_get.c b/src/exchange/taler-exchange-httpd_purses_get.c
index e56cfe485..22328fe09 100644
--- a/src/exchange/taler-exchange-httpd_purses_get.c
+++ b/src/exchange/taler-exchange-httpd_purses_get.c
@@ -57,6 +57,12 @@ struct GetContext
struct GNUNET_DB_EventHandler *eh;
/**
+ * Subscription for refund event we are
+ * waiting for.
+ */
+ struct GNUNET_DB_EventHandler *ehr;
+
+ /**
* Public key of our purse.
*/
struct TALER_PurseContractPublicKeyP purse_pub;
@@ -153,6 +159,12 @@ gc_cleanup (struct TEH_RequestContext *rc)
gc->eh);
gc->eh = NULL;
}
+ if (NULL != gc->ehr)
+ {
+ TEH_plugin->event_listen_cancel (TEH_plugin->cls,
+ gc->ehr);
+ gc->ehr = NULL;
+ }
GNUNET_free (gc);
}
@@ -207,6 +219,8 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
const char *const args[2])
{
struct GetContext *gc = rc->rh_ctx;
+ bool purse_deleted;
+ bool purse_refunded;
MHD_RESULT res;
if (NULL == gc)
@@ -242,36 +256,8 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
args[1]);
}
- {
- const char *long_poll_timeout_ms;
-
- long_poll_timeout_ms
- = MHD_lookup_connection_value (rc->connection,
- MHD_GET_ARGUMENT_KIND,
- "timeout_ms");
- if (NULL != long_poll_timeout_ms)
- {
- unsigned int timeout_ms;
- char dummy;
- struct GNUNET_TIME_Relative timeout;
-
- if (1 != sscanf (long_poll_timeout_ms,
- "%u%c",
- &timeout_ms,
- &dummy))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "timeout_ms (must be non-negative number)");
- }
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- timeout_ms);
- gc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- }
- }
-
+ TALER_MHD_parse_request_timeout (rc->connection,
+ &gc->timeout);
if ( (GNUNET_TIME_absolute_is_future (gc->timeout)) &&
(NULL == gc->eh) )
{
@@ -298,19 +284,37 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
GNUNET_break (0);
gc->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
}
+ else
+ {
+ struct GNUNET_DB_EventHeaderP repr = {
+ .size = htons (sizeof (repr)),
+ .type = htons (TALER_DBEVENT_EXCHANGE_PURSE_REFUNDED),
+ };
+
+ gc->ehr = TEH_plugin->event_listen (
+ TEH_plugin->cls,
+ GNUNET_TIME_absolute_get_remaining (gc->timeout),
+ &repr,
+ &db_event_cb,
+ rc);
+ }
}
} /* end first-time initialization */
{
enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp create_timestamp;
qs = TEH_plugin->select_purse (TEH_plugin->cls,
&gc->purse_pub,
+ &create_timestamp,
&gc->purse_expiration,
&gc->amount,
&gc->deposited,
&gc->h_contract,
- &gc->merge_timestamp);
+ &gc->merge_timestamp,
+ &purse_deleted,
+ &purse_refunded);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -333,43 +337,17 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
break; /* handled below */
}
- if (GNUNET_TIME_absolute_cmp (gc->timeout,
- >,
- gc->purse_expiration.abs_time))
- {
- /* Timeout too high, need to replace event handler */
- struct TALER_PurseEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (
- gc->wait_for_merge
- ? TALER_DBEVENT_EXCHANGE_PURSE_MERGED
- : TALER_DBEVENT_EXCHANGE_PURSE_DEPOSITED),
- .purse_pub = gc->purse_pub
- };
- struct GNUNET_DB_EventHandler *eh2;
-
- gc->timeout = gc->purse_expiration.abs_time;
- eh2 = TEH_plugin->event_listen (
- TEH_plugin->cls,
- GNUNET_TIME_absolute_get_remaining (gc->timeout),
- &rep.header,
- &db_event_cb,
- rc);
- if (NULL == eh2)
- {
- GNUNET_break (0);
- gc->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
- }
- TEH_plugin->event_listen_cancel (TEH_plugin->cls,
- gc->eh);
- gc->eh = eh2;
- }
}
- if (GNUNET_TIME_absolute_is_past (gc->purse_expiration.abs_time))
+ if (purse_refunded ||
+ purse_deleted)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Purse refunded or deleted\n");
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_GONE,
- TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
+ purse_deleted
+ ? TALER_EC_EXCHANGE_GENERIC_PURSE_DELETED
+ : TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
GNUNET_TIME_timestamp2s (
gc->purse_expiration));
}
@@ -406,7 +384,10 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
if (0 <
TALER_amount_cmp (&gc->amount,
&gc->deposited))
+ {
+ /* amount > deposited: not yet fully paid */
dt = GNUNET_TIME_UNIT_ZERO_TS;
+ }
if (TALER_EC_NONE !=
(ec = TALER_exchange_online_purse_status_sign (
&TEH_keys_exchange_sign_,
@@ -415,10 +396,16 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
&gc->deposited,
&exchange_pub,
&exchange_sig)))
+ {
res = TALER_MHD_reply_with_ec (rc->connection,
ec,
NULL);
+ }
else
+ {
+ /* Make sure merge_timestamp is omitted if not yet merged */
+ if (GNUNET_TIME_absolute_is_never (gc->merge_timestamp.abs_time))
+ gc->merge_timestamp = GNUNET_TIME_UNIT_ZERO_TS;
res = TALER_MHD_REPLY_JSON_PACK (
rc->connection,
MHD_HTTP_OK,
@@ -428,11 +415,16 @@ TEH_handler_purses_get (struct TEH_RequestContext *rc,
&exchange_sig),
GNUNET_JSON_pack_data_auto ("exchange_pub",
&exchange_pub),
- GNUNET_JSON_pack_timestamp ("merge_timestamp",
- gc->merge_timestamp),
- GNUNET_JSON_pack_timestamp ("deposit_timestamp",
- dt)
+ GNUNET_JSON_pack_timestamp ("purse_expiration",
+ gc->purse_expiration),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_timestamp ("merge_timestamp",
+ gc->merge_timestamp)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_timestamp ("deposit_timestamp",
+ dt))
);
+ }
}
return res;
}
diff --git a/src/exchange/taler-exchange-httpd_purses_merge.c b/src/exchange/taler-exchange-httpd_purses_merge.c
index 144571d22..fb5ce4d90 100644
--- a/src/exchange/taler-exchange-httpd_purses_merge.c
+++ b/src/exchange/taler-exchange-httpd_purses_merge.c
@@ -28,12 +28,12 @@
#include <pthread.h>
#include "taler_dbevents.h"
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_purses_merge.h"
#include "taler-exchange-httpd_responses.h"
#include "taler_exchangedb_lib.h"
#include "taler-exchange-httpd_keys.h"
-#include "taler-exchange-httpd_wire.h"
/**
@@ -103,11 +103,21 @@ struct PurseMergeContext
/**
* URI of the account the purse is to be merged into.
- * Must be of the form 'payto://taler/$EXCHANGE_URL/RESERVE_PUB'.
+ * Must be of the form 'payto://taler-reserve/$EXCHANGE_URL/RESERVE_PUB'.
*/
const char *payto_uri;
/**
+ * Hash of the @e payto_uri.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * KYC status of the operation.
+ */
+ struct TALER_EXCHANGEDB_KycStatus kyc;
+
+ /**
* Base URL of the exchange provider hosting the reserve.
*/
char *provider_url;
@@ -157,15 +167,20 @@ reply_merge_success (struct MHD_Connection *connection,
}
else
{
+#if WAD_NOT_IMPLEMENTED
+ /* FIXME: figure out partner, lookup wad fee by partner! #7271 */
if (0 >
TALER_amount_subtract (&merge_amount,
&pcc->target_amount,
- &pcc->wf->wad))
+ &wad_fee))
{
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TEH_currency,
&merge_amount));
}
+#else
+ merge_amount = pcc->target_amount;
+#endif
}
if (TALER_EC_NONE !=
(ec = TALER_exchange_online_purse_merged_sign (
@@ -202,6 +217,46 @@ reply_merge_success (struct MHD_Connection *connection,
/**
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param cls a `struct PurseMergeContext`
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
+ */
+static void
+amount_iterator (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
+{
+ struct PurseMergeContext *pcc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ cb (cb_cls,
+ &pcc->target_amount,
+ GNUNET_TIME_absolute_get ());
+ qs = TEH_plugin->select_merge_amounts_for_kyc_check (
+ TEH_plugin->cls,
+ &pcc->h_payto,
+ limit,
+ cb,
+ cb_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got %d additional transactions for this merge and limit %llu\n",
+ qs,
+ (unsigned long long) limit.abs_value_us);
+ GNUNET_break (qs >= 0);
+}
+
+
+/**
* Execute database transaction for /purses/$PID/merge. Runs the transaction
* logic; IF it returns a non-error code, the transaction logic MUST NOT queue
* a MHD response. IF it returns an hard error, the transaction logic MUST
@@ -224,9 +279,50 @@ merge_transaction (void *cls,
bool in_conflict = true;
bool no_balance = true;
bool no_partner = true;
- bool no_kyc = true;
- bool no_reserve = true;
+ char *required;
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE,
+ &pcc->h_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &amount_iterator,
+ pcc,
+ &required);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret =
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "kyc_test_required");
+ return qs;
+ }
+ if (NULL != required)
+ {
+ pcc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ required,
+ &pcc->h_payto,
+ &pcc->reserve_pub,
+ &pcc->kyc.requirement_row);
+ GNUNET_free (required);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_for_account");
+ }
+ return qs;
+ }
+ pcc->kyc.ok = true;
qs = TEH_plugin->do_purse_merge (
TEH_plugin->cls,
pcc->purse_pub,
@@ -235,18 +331,14 @@ merge_transaction (void *cls,
&pcc->reserve_sig,
pcc->provider_url,
&pcc->reserve_pub,
- TEH_KYC_NONE != TEH_kyc_config.mode,
&no_partner,
&no_balance,
- &no_reserve,
- &no_kyc,
&in_conflict);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
return qs;
- TALER_LOG_WARNING (
- "Failed to store merge purse information in database\n");
+ GNUNET_break (0);
*mhd_ret =
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -263,26 +355,6 @@ merge_transaction (void *cls,
pcc->provider_url);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (no_reserve)
- {
- *mhd_ret =
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
- NULL);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (no_kyc) &&
- (TEH_KYC_NONE != TEH_kyc_config.mode) )
- {
- *mhd_ret
- = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- TALER_JSON_pack_ec (
- TALER_EC_EXCHANGE_GENERIC_KYC_REQUIRED));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
if (no_balance)
{
*mhd_ret =
@@ -298,13 +370,15 @@ merge_transaction (void *cls,
struct GNUNET_TIME_Timestamp merge_timestamp;
char *partner_url = NULL;
struct TALER_ReservePublicKeyP reserve_pub;
+ bool refunded;
qs = TEH_plugin->select_purse_merge (TEH_plugin->cls,
pcc->purse_pub,
&merge_sig,
&merge_timestamp,
&partner_url,
- &reserve_pub);
+ &reserve_pub,
+ &refunded);
if (qs <= 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
@@ -318,21 +392,43 @@ merge_transaction (void *cls,
"select purse merge");
return qs;
}
- *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_CONFLICT,
- GNUNET_JSON_pack_timestamp ("merge_timestamp",
- merge_timestamp),
- GNUNET_JSON_pack_data_auto ("merge_sig",
- &merge_sig),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_string ("partner_url",
- partner_url)),
- GNUNET_JSON_pack_data_auto ("reserve_pub",
- &reserve_pub));
+ if (refunded)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Purse was already refunded\n");
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_GONE,
+ TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
+ NULL);
+ GNUNET_free (partner_url);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (0 !=
+ GNUNET_memcmp (&merge_sig,
+ &pcc->merge_sig))
+ {
+ *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_CONFLICT,
+ GNUNET_JSON_pack_timestamp ("merge_timestamp",
+ merge_timestamp),
+ GNUNET_JSON_pack_data_auto ("merge_sig",
+ &merge_sig),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("partner_url",
+ partner_url)),
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ &reserve_pub));
+ GNUNET_free (partner_url);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ /* idempotent! */
+ *mhd_ret = reply_merge_success (connection,
+ pcc);
GNUNET_free (partner_url);
return GNUNET_DB_STATUS_HARD_ERROR;
}
+
return qs;
}
@@ -348,8 +444,8 @@ TEH_handler_purses_merge (
.exchange_timestamp = GNUNET_TIME_timestamp_get ()
};
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("payto_uri",
- &pcc.payto_uri),
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &pcc.payto_uri),
GNUNET_JSON_spec_fixed_auto ("reserve_sig",
&pcc.reserve_sig),
GNUNET_JSON_spec_fixed_auto ("merge_sig",
@@ -381,15 +477,15 @@ TEH_handler_purses_merge (
}
/* Fetch purse details */
- qs = TEH_plugin->select_purse_request (TEH_plugin->cls,
- pcc.purse_pub,
- &pcc.merge_pub,
- &pcc.purse_expiration,
- &pcc.h_contract_terms,
- &pcc.min_age,
- &pcc.target_amount,
- &pcc.balance,
- &purse_sig);
+ qs = TEH_plugin->get_purse_request (TEH_plugin->cls,
+ pcc.purse_pub,
+ &pcc.merge_pub,
+ &pcc.purse_expiration,
+ &pcc.h_contract_terms,
+ &pcc.min_age,
+ &pcc.target_amount,
+ &pcc.balance,
+ &purse_sig);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -421,11 +517,11 @@ TEH_handler_purses_merge (
"Received payto: `%s'\n",
pcc.payto_uri);
if ( (0 != strncmp (pcc.payto_uri,
- "payto://taler/",
- strlen ("payto://taler/"))) &&
+ "payto://taler-reserve/",
+ strlen ("payto://taler-reserve/"))) &&
(0 != strncmp (pcc.payto_uri,
- "payto://taler+http/",
- strlen ("payto://taler+http/"))) )
+ "payto://taler-reserve-http/",
+ strlen ("payto://taler-reserve+http/"))) )
{
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (
@@ -434,15 +530,14 @@ TEH_handler_purses_merge (
TALER_EC_GENERIC_PARAMETER_MALFORMED,
"payto_uri");
}
-
http = (0 == strncmp (pcc.payto_uri,
- "payto://taler+http/",
- strlen ("payto://taler+http/")));
+ "payto://taler-reserve-http/",
+ strlen ("payto://taler-reserve-http/")));
{
const char *host = &pcc.payto_uri[http
- ? strlen ("payto://taler+http/")
- : strlen ("payto://taler/")];
+ ? strlen ("payto://taler-reserve-http/")
+ : strlen ("payto://taler-reserve/")];
const char *slash = strchr (host,
'/');
@@ -477,6 +572,8 @@ TEH_handler_purses_merge (
}
slash++;
}
+ TALER_payto_hash (pcc.payto_uri,
+ &pcc.h_payto);
if (0 == strcmp (pcc.provider_url,
TEH_base_url))
{
@@ -485,9 +582,9 @@ TEH_handler_purses_merge (
}
else
{
- char *method = GNUNET_strdup ("FIXME-WAD");
+ char *method = GNUNET_strdup ("FIXME-WAD #7271");
- /* FIXME: lookup wire method by pcc.provider_url! */
+ /* FIXME-#7271: lookup wire method by pcc.provider_url! */
pcc.wf = TEH_wire_fees_by_time (pcc.exchange_timestamp,
method);
if (NULL == pcc.wf)
@@ -551,11 +648,6 @@ TEH_handler_purses_merge (
}
}
- if (GNUNET_TIME_absolute_is_past (pcc.purse_expiration.abs_time))
- {
- // FIXME: idempotency check, otherwise generate 410!
- }
-
/* execute transaction */
{
MHD_RESULT mhd_ret;
@@ -573,6 +665,13 @@ TEH_handler_purses_merge (
}
}
+
+ GNUNET_free (pcc.provider_url);
+ if (! pcc.kyc.ok)
+ return TEH_RESPONSE_reply_kyc_required (connection,
+ &pcc.h_payto,
+ &pcc.kyc);
+
{
struct TALER_PurseEventP rep = {
.header.size = htons (sizeof (rep)),
@@ -588,7 +687,6 @@ TEH_handler_purses_merge (
0);
}
- GNUNET_free (pcc.provider_url);
/* generate regular response */
return reply_merge_success (connection,
&pcc);
diff --git a/src/exchange/taler-exchange-httpd_recoup-refresh.c b/src/exchange/taler-exchange-httpd_recoup-refresh.c
index d52dabda0..a5d5b2ab4 100644
--- a/src/exchange/taler-exchange-httpd_recoup-refresh.c
+++ b/src/exchange/taler-exchange-httpd_recoup-refresh.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017-2021 Taler Systems SA
+ Copyright (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -55,7 +55,7 @@ struct RecoupContext
/**
* Key used to blind the coin.
*/
- const union TALER_DenominationBlindingKeyP *coin_bks;
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks;
/**
* Signature of the coin requesting recoup.
@@ -175,8 +175,8 @@ verify_and_execute_recoup_refresh (
struct MHD_Connection *connection,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_ExchangeWithdrawValues *exchange_vals,
- const union TALER_DenominationBlindingKeyP *coin_bks,
- const struct TALER_CsNonce *nonce,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_CoinSpendSignatureP *coin_sig)
{
struct RecoupContext pc;
@@ -219,12 +219,12 @@ verify_and_execute_recoup_refresh (
}
/* check denomination signature */
- switch (dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
break;
default:
@@ -265,6 +265,7 @@ verify_and_execute_recoup_refresh (
if (GNUNET_OK !=
TALER_denom_blind (&dk->denom_pub,
coin_bks,
+ nonce,
&coin->h_age_commitment,
&coin->coin_pub,
exchange_vals,
@@ -278,9 +279,6 @@ verify_and_execute_recoup_refresh (
TALER_EC_EXCHANGE_RECOUP_REFRESH_BLINDING_FAILED,
NULL);
}
- if (TALER_DENOMINATION_CS == blinded_planchet.cipher)
- blinded_planchet.details.cs_blinded_planchet.nonce
- = *nonce;
TALER_coin_ev_hash (&blinded_planchet,
&coin->denom_pub_hash,
&h_blind);
@@ -375,10 +373,11 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
{
enum GNUNET_GenericReturnValue ret;
struct TALER_CoinPublicInfo coin = {0};
- union TALER_DenominationBlindingKeyP coin_bks;
+ union GNUNET_CRYPTO_BlindingSecretP coin_bks;
struct TALER_CoinSpendSignatureP coin_sig;
struct TALER_ExchangeWithdrawValues exchange_vals;
- struct TALER_CsNonce nonce;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+ bool no_nonce;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
&coin.denom_pub_hash),
@@ -394,19 +393,17 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
&coin.h_age_commitment),
&coin.no_age_commitment),
+ // FIXME: rename to just 'nonce'
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_fixed_auto ("cs_nonce",
&nonce),
- NULL),
+ &no_nonce),
GNUNET_JSON_spec_end ()
};
memset (&coin,
0,
sizeof (coin));
- memset (&nonce,
- 0,
- sizeof (nonce));
coin.coin_pub = *coin_pub;
ret = TALER_MHD_parse_json_data (connection,
root,
@@ -422,7 +419,9 @@ TEH_handler_recoup_refresh (struct MHD_Connection *connection,
&coin,
&exchange_vals,
&coin_bks,
- &nonce,
+ no_nonce
+ ? NULL
+ : &nonce,
&coin_sig);
GNUNET_JSON_parse_free (spec);
return res;
diff --git a/src/exchange/taler-exchange-httpd_recoup.c b/src/exchange/taler-exchange-httpd_recoup.c
index 349c2b94a..afbbd7474 100644
--- a/src/exchange/taler-exchange-httpd_recoup.c
+++ b/src/exchange/taler-exchange-httpd_recoup.c
@@ -58,7 +58,7 @@ struct RecoupContext
/**
* Key used to blind the coin.
*/
- const union TALER_DenominationBlindingKeyP *coin_bks;
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks;
/**
* Signature of the coin requesting recoup.
@@ -178,8 +178,8 @@ verify_and_execute_recoup (
struct MHD_Connection *connection,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_ExchangeWithdrawValues *exchange_vals,
- const union TALER_DenominationBlindingKeyP *coin_bks,
- const struct TALER_CsNonce *nonce,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_CoinSpendSignatureP *coin_sig)
{
struct RecoupContext pc;
@@ -221,12 +221,12 @@ verify_and_execute_recoup (
}
/* check denomination signature */
- switch (dk->denom_pub.cipher)
+ switch (dk->denom_pub.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_RSA]++;
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_CS]++;
break;
default:
@@ -270,6 +270,7 @@ verify_and_execute_recoup (
if (GNUNET_OK !=
TALER_denom_blind (&dk->denom_pub,
coin_bks,
+ nonce,
&coin->h_age_commitment,
&coin->coin_pub,
exchange_vals,
@@ -283,20 +284,9 @@ verify_and_execute_recoup (
TALER_EC_EXCHANGE_RECOUP_BLINDING_FAILED,
NULL);
}
- if (TALER_DENOMINATION_CS == blinded_planchet.cipher)
- blinded_planchet.details.cs_blinded_planchet.nonce
- = *nonce;
- if (GNUNET_OK !=
- TALER_coin_ev_hash (&blinded_planchet,
- &coin->denom_pub_hash,
- &pc.h_coin_ev))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- NULL);
- }
+ TALER_coin_ev_hash (&blinded_planchet,
+ &coin->denom_pub_hash,
+ &pc.h_coin_ev);
TALER_blinded_planchet_free (&blinded_planchet);
}
@@ -388,10 +378,11 @@ TEH_handler_recoup (struct MHD_Connection *connection,
{
enum GNUNET_GenericReturnValue ret;
struct TALER_CoinPublicInfo coin;
- union TALER_DenominationBlindingKeyP coin_bks;
+ union GNUNET_CRYPTO_BlindingSecretP coin_bks;
struct TALER_CoinSpendSignatureP coin_sig;
struct TALER_ExchangeWithdrawValues exchange_vals;
- struct TALER_CsNonce nonce;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+ bool no_nonce;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
&coin.denom_pub_hash),
@@ -407,19 +398,17 @@ TEH_handler_recoup (struct MHD_Connection *connection,
GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
&coin.h_age_commitment),
&coin.no_age_commitment),
+ // FIXME: should be renamed to just 'nonce'!
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_fixed_auto ("cs_nonce",
&nonce),
- NULL),
+ &no_nonce),
GNUNET_JSON_spec_end ()
};
memset (&coin,
0,
sizeof (coin));
- memset (&nonce,
- 0,
- sizeof (nonce));
coin.coin_pub = *coin_pub;
ret = TALER_MHD_parse_json_data (connection,
root,
@@ -435,7 +424,9 @@ TEH_handler_recoup (struct MHD_Connection *connection,
&coin,
&exchange_vals,
&coin_bks,
- &nonce,
+ no_nonce
+ ? NULL
+ : &nonce,
&coin_sig);
GNUNET_JSON_parse_free (spec);
return res;
diff --git a/src/exchange/taler-exchange-httpd_refreshes_reveal.c b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
index a0fd83bfa..5630051cf 100644
--- a/src/exchange/taler-exchange-httpd_refreshes_reveal.c
+++ b/src/exchange/taler-exchange-httpd_refreshes_reveal.c
@@ -111,9 +111,6 @@ struct RevealContext
/**
* Array of information about fresh coins being revealed.
*/
- /* FIXME: const would be nicer here, but we initialize
- the 'alg_values' in the verification
- routine; suboptimal to be fixed... */
struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs;
/**
@@ -159,14 +156,17 @@ check_commitment (struct RevealContext *rctx,
struct MHD_Connection *connection,
MHD_RESULT *mhd_ret)
{
- struct TALER_CsNonce nonces[rctx->num_fresh_coins];
- unsigned int aoff = 0;
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonces[rctx->num_fresh_coins];
+ memset (nonces,
+ 0,
+ sizeof (nonces));
for (unsigned int j = 0; j<rctx->num_fresh_coins; j++)
{
const struct TALER_DenominationPublicKey *dk = &rctx->dks[j]->denom_pub;
- if (dk->cipher != rctx->rcds[j].blinded_planchet.cipher)
+ if (dk->bsign_pub_key->cipher !=
+ rctx->rcds[j].blinded_planchet.blinded_message->cipher)
{
GNUNET_break (0);
*mhd_ret = TALER_MHD_reply_with_error (
@@ -176,9 +176,9 @@ check_commitment (struct RevealContext *rctx,
NULL);
return GNUNET_SYSERR;
}
- switch (dk->cipher)
+ switch (dk->bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_INVALID:
+ case GNUNET_CRYPTO_BSA_INVALID:
GNUNET_break (0);
*mhd_ret = TALER_MHD_reply_with_error (
connection,
@@ -186,40 +186,48 @@ check_commitment (struct RevealContext *rctx,
TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
NULL);
return GNUNET_SYSERR;
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
continue;
- case TALER_DENOMINATION_CS:
- nonces[aoff]
- = rctx->rcds[j].blinded_planchet.details.cs_blinded_planchet.nonce;
- aoff++;
+ case GNUNET_CRYPTO_BSA_CS:
+ nonces[j]
+ = (const union GNUNET_CRYPTO_BlindSessionNonce *)
+ &rctx->rcds[j].blinded_planchet.blinded_message->details.
+ cs_blinded_message.nonce;
break;
}
}
// OPTIMIZE: do this in batch later!
- aoff = 0;
for (unsigned int j = 0; j<rctx->num_fresh_coins; j++)
{
const struct TALER_DenominationPublicKey *dk = &rctx->dks[j]->denom_pub;
struct TALER_ExchangeWithdrawValues *alg_values
= &rctx->rrcs[j].exchange_vals;
+ struct GNUNET_CRYPTO_BlindingInputValues *bi;
- alg_values->cipher = dk->cipher;
- switch (dk->cipher)
+ bi = GNUNET_new (struct GNUNET_CRYPTO_BlindingInputValues);
+ alg_values->blinding_inputs = bi;
+ bi->rc = 1;
+ bi->cipher = dk->bsign_pub_key->cipher;
+ switch (dk->bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_INVALID:
+ case GNUNET_CRYPTO_BSA_INVALID:
GNUNET_assert (0);
return GNUNET_SYSERR;
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
continue;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
enum TALER_ErrorCode ec;
-
- ec = TEH_keys_denomination_cs_r_pub_melt (
- &rctx->rrcs[j].h_denom_pub,
- &nonces[aoff],
- &alg_values->details.cs_values);
+ const struct TEH_CsDeriveData cdd = {
+ .h_denom_pub = &rctx->rrcs[j].h_denom_pub,
+ .nonce = &nonces[j]->cs_nonce
+ };
+
+ ec = TEH_keys_denomination_cs_r_pub (
+ &cdd,
+ true,
+ &bi->details.cs_values);
if (TALER_EC_NONE != ec)
{
*mhd_ret = TALER_MHD_reply_with_error (connection,
@@ -228,7 +236,6 @@ check_commitment (struct RevealContext *rctx,
NULL);
return GNUNET_SYSERR;
}
- aoff++;
}
}
}
@@ -270,14 +277,11 @@ check_commitment (struct RevealContext *rctx,
&ts);
rce->new_coins = GNUNET_new_array (rctx->num_fresh_coins,
struct TALER_RefreshCoinData);
- aoff = 0;
for (unsigned int j = 0; j<rctx->num_fresh_coins; j++)
{
- const struct TALER_DenominationPublicKey *dk
- = &rctx->dks[j]->denom_pub;
struct TALER_RefreshCoinData *rcd = &rce->new_coins[j];
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
const struct TALER_ExchangeWithdrawValues *alg_value
= &rctx->rrcs[j].exchange_vals;
struct TALER_PlanchetDetail pd = {0};
@@ -310,8 +314,9 @@ check_commitment (struct RevealContext *rctx,
&acp,
&ts.key,
&nacp));
-
- TALER_age_commitment_hash (&nacp.commitment, &h);
+ TALER_age_commitment_hash (&nacp.commitment,
+ &h);
+ TALER_age_commitment_proof_free (&nacp);
hac = &h;
}
@@ -319,16 +324,11 @@ check_commitment (struct RevealContext *rctx,
TALER_planchet_prepare (rcd->dk,
alg_value,
&bks,
+ nonces[j],
&coin_priv,
hac,
&c_hash,
&pd));
- if (TALER_DENOMINATION_CS == dk->cipher)
- {
- pd.blinded_planchet.details.cs_blinded_planchet.nonce =
- nonces[aoff];
- aoff++;
- }
rcd->blinded_planchet = pd.blinded_planchet;
}
}
@@ -507,7 +507,7 @@ resolve_refreshes_reveal_denominations (
}
}
- old_dk = TEH_keys_denomination_by_hash2 (
+ old_dk = TEH_keys_denomination_by_hash_from_state (
ksh,
&rctx->melt.session.coin.denom_pub_hash,
connection,
@@ -532,13 +532,14 @@ resolve_refreshes_reveal_denominations (
-1);
if (GNUNET_OK != res)
return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
- dks[i] = TEH_keys_denomination_by_hash2 (ksh,
- &rrcs[i].h_denom_pub,
- connection,
- &ret);
+ dks[i] = TEH_keys_denomination_by_hash_from_state (ksh,
+ &rrcs[i].h_denom_pub,
+ connection,
+ &ret);
if (NULL == dks[i])
return ret;
- if ( (TALER_DENOMINATION_CS == dks[i]->denom_pub.cipher) &&
+ if ( (GNUNET_CRYPTO_BSA_CS ==
+ dks[i]->denom_pub.bsign_pub_key->cipher) &&
(rctx->no_rms) )
{
return TALER_MHD_reply_with_error (
@@ -623,8 +624,7 @@ resolve_refreshes_reveal_denominations (
bool failed = true;
/* Has been checked in handle_refreshes_reveal_json() */
- GNUNET_assert (ng ==
- TALER_extensions_age_restriction_num_groups ());
+ GNUNET_assert (ng == TEH_age_restriction_config.num_groups);
rctx->old_age_commitment = GNUNET_new (struct TALER_AgeCommitment);
oac = rctx->old_age_commitment;
@@ -721,7 +721,8 @@ clean_age:
rcd->blinded_planchet = rrc->blinded_planchet;
rcd->dk = &dks[i]->denom_pub;
- if (rcd->blinded_planchet.cipher != rcd->dk->cipher)
+ if (rcd->blinded_planchet.blinded_message->cipher !=
+ rcd->dk->bsign_pub_key->cipher)
{
GNUNET_break_op (0);
ret = TALER_MHD_REPLY_JSON_PACK (
@@ -747,16 +748,21 @@ clean_age:
(unsigned int) rctx->num_fresh_coins);
/* create fresh coin signatures */
- for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
{
+ struct TEH_CoinSignData csds[rctx->num_fresh_coins];
+ struct TALER_BlindedDenominationSignature bss[rctx->num_fresh_coins];
enum TALER_ErrorCode ec;
- // FIXME: replace with a batch call that
- // passes all coins in once go!
- ec = TEH_keys_denomination_sign_melt (
- &rrcs[i].h_denom_pub,
- &rcds[i].blinded_planchet,
- &rrcs[i].coin_sig);
+ for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
+ {
+ csds[i].h_denom_pub = &rrcs[i].h_denom_pub;
+ csds[i].bp = &rcds[i].blinded_planchet;
+ }
+ ec = TEH_keys_denomination_batch_sign (
+ rctx->num_fresh_coins,
+ csds,
+ true,
+ bss);
if (TALER_EC_NONE != ec)
{
GNUNET_break (0);
@@ -765,11 +771,17 @@ clean_age:
NULL);
goto cleanup;
}
- }
+ for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
+ {
+ rrcs[i].coin_sig = bss[i];
+ rrcs[i].blinded_planchet = rcds[i].blinded_planchet;
+ }
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Signatures ready, starting DB interaction\n");
+
for (unsigned int r = 0; r<MAX_TRANSACTION_COMMIT_RETRIES; r++)
{
bool changed;
@@ -786,12 +798,7 @@ clean_age:
NULL);
goto cleanup;
}
- for (unsigned int i = 0; i<rctx->num_fresh_coins; i++)
- {
- struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
- rrc->blinded_planchet = rcds[i].blinded_planchet;
- }
qs = TEH_plugin->insert_refresh_reveal (
TEH_plugin->cls,
melt_serial_id,
@@ -856,7 +863,10 @@ cleanup:
for (unsigned int i = 0; i<num_fresh_coins; i++)
{
struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
+ struct TALER_ExchangeWithdrawValues *alg_values
+ = &rrcs[i].exchange_vals;
+ GNUNET_free (alg_values->blinding_inputs);
TALER_blinded_denom_sig_free (&rrc->coin_sig);
TALER_blinded_planchet_free (&rrc->blinded_planchet);
}
@@ -931,7 +941,7 @@ handle_refreshes_reveal_json (struct MHD_Connection *connection,
/* Sanity check of age commitment: If it was provided, it _must_ be an array
* of the size the # of age groups */
if (NULL != old_age_commitment_json
- && TALER_extensions_age_restriction_num_groups () !=
+ && TEH_age_restriction_config.num_groups !=
json_array_size (old_age_commitment_json))
{
GNUNET_break_op (0);
@@ -974,26 +984,26 @@ TEH_handler_reveal (struct TEH_RequestContext *rc,
const json_t *root,
const char *const args[2])
{
- json_t *coin_evs;
- json_t *transfer_privs;
- json_t *link_sigs;
- json_t *new_denoms_h;
- json_t *old_age_commitment;
+ const json_t *coin_evs;
+ const json_t *transfer_privs;
+ const json_t *link_sigs;
+ const json_t *new_denoms_h;
+ const json_t *old_age_commitment;
struct RevealContext rctx;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("transfer_pub",
&rctx.gamma_tp),
- GNUNET_JSON_spec_json ("transfer_privs",
- &transfer_privs),
- GNUNET_JSON_spec_json ("link_sigs",
- &link_sigs),
- GNUNET_JSON_spec_json ("coin_evs",
- &coin_evs),
- GNUNET_JSON_spec_json ("new_denoms_h",
- &new_denoms_h),
+ GNUNET_JSON_spec_array_const ("transfer_privs",
+ &transfer_privs),
+ GNUNET_JSON_spec_array_const ("link_sigs",
+ &link_sigs),
+ GNUNET_JSON_spec_array_const ("coin_evs",
+ &coin_evs),
+ GNUNET_JSON_spec_array_const ("new_denoms_h",
+ &new_denoms_h),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_json ("old_age_commitment",
- &old_age_commitment),
+ GNUNET_JSON_spec_array_const ("old_age_commitment",
+ &old_age_commitment),
NULL),
GNUNET_JSON_spec_mark_optional (
GNUNET_JSON_spec_fixed_auto ("rms",
@@ -1044,7 +1054,6 @@ TEH_handler_reveal (struct TEH_RequestContext *rc,
/* Note we do +1 as 1 row (cut-and-choose!) is missing! */
if (TALER_CNC_KAPPA != json_array_size (transfer_privs) + 1)
{
- GNUNET_JSON_parse_free (spec);
GNUNET_break_op (0);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_BAD_REQUEST,
@@ -1052,19 +1061,13 @@ TEH_handler_reveal (struct TEH_RequestContext *rc,
NULL);
}
- {
- MHD_RESULT res;
-
- res = handle_refreshes_reveal_json (rc->connection,
- &rctx,
- transfer_privs,
- link_sigs,
- new_denoms_h,
- old_age_commitment,
- coin_evs);
- GNUNET_JSON_parse_free (spec);
- return res;
- }
+ return handle_refreshes_reveal_json (rc->connection,
+ &rctx,
+ transfer_privs,
+ link_sigs,
+ new_denoms_h,
+ old_age_commitment,
+ coin_evs);
}
diff --git a/src/exchange/taler-exchange-httpd_refund.c b/src/exchange/taler-exchange-httpd_refund.c
index 33ead7c69..b8bcf7c60 100644
--- a/src/exchange/taler-exchange-httpd_refund.c
+++ b/src/exchange/taler-exchange-httpd_refund.c
@@ -158,6 +158,7 @@ refund_transaction (void *cls,
}
if (conflict)
{
+ GNUNET_break_op (0);
*mhd_ret = TEH_RESPONSE_reply_coin_insufficient_funds (
connection,
TALER_EC_EXCHANGE_REFUND_INCONSISTENT_AMOUNT,
diff --git a/src/exchange/taler-exchange-httpd_reserves_attest.c b/src/exchange/taler-exchange-httpd_reserves_attest.c
new file mode 100644
index 000000000..7bbebaad7
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_attest.c
@@ -0,0 +1,385 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_attest.c
+ * @brief Handle /reserves/$RESERVE_PUB/attest requests
+ * @author Florian Dold
+ * @author Benedikt Mueller
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include "taler_dbevents.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_reserves_attest.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * How far do we allow a client's time to be off when
+ * checking the request timestamp?
+ */
+#define TIMESTAMP_TOLERANCE \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+
+/**
+ * Closure for #reserve_attest_transaction.
+ */
+struct ReserveAttestContext
+{
+ /**
+ * Public key of the reserve the inquiry is about.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Hash of the payto URI of this reserve.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Timestamp of the request.
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ /**
+ * Expiration time for the attestation.
+ */
+ struct GNUNET_TIME_Timestamp etime;
+
+ /**
+ * List of requested details.
+ */
+ const json_t *details;
+
+ /**
+ * Client signature approving the request.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Attributes we are affirming. JSON object.
+ */
+ json_t *json_attest;
+
+ /**
+ * Database error codes encountered.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+
+ /**
+ * Set to true if we did not find the reserve.
+ */
+ bool not_found;
+
+};
+
+
+/**
+ * Send reserve attest to client.
+ *
+ * @param connection connection to the client
+ * @param rhc reserve attest to return
+ * @return MHD result code
+ */
+static MHD_RESULT
+reply_reserve_attest_success (struct MHD_Connection *connection,
+ const struct ReserveAttestContext *rhc)
+{
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ enum TALER_ErrorCode ec;
+ struct GNUNET_TIME_Timestamp now;
+
+ if (NULL == rhc->json_attest)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
+ NULL);
+ }
+ now = GNUNET_TIME_timestamp_get ();
+ ec = TALER_exchange_online_reserve_attest_details_sign (
+ &TEH_keys_exchange_sign_,
+ now,
+ rhc->etime,
+ &rhc->reserve_pub,
+ rhc->json_attest,
+ &exchange_pub,
+ &exchange_sig);
+ if (TALER_EC_NONE != ec)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_ec (connection,
+ ec,
+ NULL);
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &exchange_pub),
+ GNUNET_JSON_pack_timestamp ("exchange_timestamp",
+ now),
+ GNUNET_JSON_pack_timestamp ("expiration_time",
+ rhc->etime),
+ GNUNET_JSON_pack_object_steal ("attributes",
+ rhc->json_attest));
+}
+
+
+/**
+ * Function called with information about all applicable
+ * legitimization processes for the given user. Finds the
+ * available attributes and merges them into our result
+ * set based on the details requested by the client.
+ *
+ * @param cls our `struct ReserveAttestContext *`
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+static void
+kyc_process_cb (void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes)
+{
+ struct ReserveAttestContext *rsc = cls;
+ json_t *attrs;
+ json_t *val;
+ const char *name;
+ bool match = false;
+
+ if (GNUNET_TIME_absolute_is_past (expiration_time.abs_time))
+ return;
+ attrs = TALER_CRYPTO_kyc_attributes_decrypt (&TEH_attribute_key,
+ enc_attributes,
+ enc_attributes_size);
+ json_object_foreach (attrs, name, val)
+ {
+ bool requested = false;
+ size_t idx;
+ json_t *str;
+
+ if (NULL != json_object_get (rsc->json_attest,
+ name))
+ continue; /* duplicate */
+ json_array_foreach (rsc->details, idx, str)
+ {
+ if (0 == strcmp (json_string_value (str),
+ name))
+ {
+ requested = true;
+ break;
+ }
+ }
+ if (! requested)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Skipping attribute `%s': not requested\n",
+ name);
+ continue;
+ }
+ match = true;
+ GNUNET_assert (0 ==
+ json_object_set (rsc->json_attest, /* NOT set_new! */
+ name,
+ val));
+ }
+ json_decref (attrs);
+ if (! match)
+ return;
+ rsc->etime = GNUNET_TIME_timestamp_min (expiration_time,
+ rsc->etime);
+}
+
+
+/**
+ * Function implementing /reserves/$RID/attest transaction. Given the public
+ * key of a reserve, return the associated transaction attest. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction logic
+ * MUST NOT queue a MHD response. IF it returns an hard error, the
+ * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
+ * returns the soft error code, the function MAY be called again to retry and
+ * MUST not queue a MHD response.
+ *
+ * @param cls a `struct ReserveAttestContext *`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!); unused
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+reserve_attest_transaction (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct ReserveAttestContext *rsc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ rsc->json_attest = json_object ();
+ GNUNET_assert (NULL != rsc->json_attest);
+ qs = TEH_plugin->select_kyc_attributes (TEH_plugin->cls,
+ &rsc->h_payto,
+ &kyc_process_cb,
+ rsc);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_kyc_attributes");
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ rsc->not_found = true;
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ rsc->not_found = false;
+ break;
+ }
+ return qs;
+}
+
+
+MHD_RESULT
+TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[1])
+{
+ struct ReserveAttestContext rsc = {
+ .etime = GNUNET_TIME_UNIT_FOREVER_TS
+ };
+ MHD_RESULT mhd_ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_timestamp ("request_timestamp",
+ &rsc.timestamp),
+ GNUNET_JSON_spec_array_const ("details",
+ &rsc.details),
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rsc.reserve_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ struct GNUNET_TIME_Timestamp now;
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &rsc.reserve_pub,
+ sizeof (rsc.reserve_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
+ args[0]);
+ }
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (rc->connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ return MHD_YES; /* failure */
+ }
+ }
+ now = GNUNET_TIME_timestamp_get ();
+ if (! GNUNET_TIME_absolute_approx_eq (now.abs_time,
+ rsc.timestamp.abs_time,
+ TIMESTAMP_TOLERANCE))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_CLOCK_SKEW,
+ NULL);
+ }
+
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_attest_request_verify (rsc.timestamp,
+ rsc.details,
+ &rsc.reserve_pub,
+ &rsc.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_RESERVES_ATTEST_BAD_SIGNATURE,
+ NULL);
+ }
+
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (TEH_base_url,
+ &rsc.reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &rsc.h_payto);
+ GNUNET_free (payto_uri);
+ }
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (rc->connection,
+ "post reserve attest",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &reserve_attest_transaction,
+ &rsc))
+ {
+ return mhd_ret;
+ }
+ if (rsc.not_found)
+ {
+ json_decref (rsc.json_attest);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ args[0]);
+ }
+ return reply_reserve_attest_success (rc->connection,
+ &rsc);
+}
+
+
+/* end of taler-exchange-httpd_reserves_attest.c */
diff --git a/src/exchange/taler-exchange-httpd_reserves_attest.h b/src/exchange/taler-exchange-httpd_reserves_attest.h
new file mode 100644
index 000000000..66bbdf712
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_attest.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_attest.h
+ * @brief Handle /reserves/$RESERVE_PUB/attest requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_RESERVES_ATTEST_H
+#define TALER_EXCHANGE_HTTPD_RESERVES_ATTEST_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Handle a POST "/reserves-attest/$RID" request.
+ *
+ * @param rc request context
+ * @param root uploaded body from the client
+ * @param args args[0] has public key of the reserve
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_reserves_attest (struct TEH_RequestContext *rc,
+ const json_t *root,
+ const char *const args[1]);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_close.c b/src/exchange/taler-exchange-httpd_reserves_close.c
new file mode 100644
index 000000000..bbf234428
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_close.c
@@ -0,0 +1,448 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_close.c
+ * @brief Handle /reserves/$RESERVE_PUB/close requests
+ * @author Florian Dold
+ * @author Benedikt Mueller
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include "taler_kyclogic_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include "taler_dbevents.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_reserves_close.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * How far do we allow a client's time to be off when
+ * checking the request timestamp?
+ */
+#define TIMESTAMP_TOLERANCE \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+
+/**
+ * Closure for #reserve_close_transaction.
+ */
+struct ReserveCloseContext
+{
+ /**
+ * Public key of the reserve the inquiry is about.
+ */
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ /**
+ * Timestamp of the request.
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ /**
+ * Client signature approving the request.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Amount that will be wired (after closing fees).
+ */
+ struct TALER_Amount wire_amount;
+
+ /**
+ * Current balance of the reserve.
+ */
+ struct TALER_Amount balance;
+
+ /**
+ * Where to wire the funds, may be NULL.
+ */
+ const char *payto_uri;
+
+ /**
+ * Hash of the @e payto_uri, if given (otherwise zero).
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * KYC status for the request.
+ */
+ struct TALER_EXCHANGEDB_KycStatus kyc;
+
+ /**
+ * Hash of the payto-URI that was used for the KYC decision.
+ */
+ struct TALER_PaytoHashP kyc_payto;
+
+ /**
+ * Query status from the amount_it() helper function.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Send reserve close to client.
+ *
+ * @param connection connection to the client
+ * @param rhc reserve close to return
+ * @return MHD result code
+ */
+static MHD_RESULT
+reply_reserve_close_success (struct MHD_Connection *connection,
+ const struct ReserveCloseContext *rhc)
+{
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ TALER_JSON_pack_amount ("wire_amount",
+ &rhc->wire_amount));
+}
+
+
+/**
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param cls closure, identifies the event type and
+ * account to iterate over events for
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
+ */
+static void
+amount_it (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
+{
+ struct ReserveCloseContext *rcc = cls;
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = cb (cb_cls,
+ &rcc->balance,
+ GNUNET_TIME_absolute_get ());
+ GNUNET_break (GNUNET_SYSERR != ret);
+ if (GNUNET_OK != ret)
+ return;
+ rcc->qs
+ = TEH_plugin->iterate_reserve_close_info (
+ TEH_plugin->cls,
+ &rcc->kyc_payto,
+ limit,
+ cb,
+ cb_cls);
+}
+
+
+/**
+ * Function implementing /reserves/$RID/close transaction. Given the public
+ * key of a reserve, return the associated transaction close. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction logic
+ * MUST NOT queue a MHD response. IF it returns an hard error, the
+ * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
+ * returns the soft error code, the function MAY be called again to retry and
+ * MUST not queue a MHD response.
+ *
+ * @param cls a `struct ReserveCloseContext *`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!); unused
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+reserve_close_transaction (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct ReserveCloseContext *rcc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ char *payto_uri = NULL;
+ const struct TALER_WireFeeSet *wf;
+
+ qs = TEH_plugin->select_reserve_close_info (
+ TEH_plugin->cls,
+ rcc->reserve_pub,
+ &rcc->balance,
+ &payto_uri);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "select_reserve_close_info");
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+
+ if ( (NULL == rcc->payto_uri) &&
+ (NULL == payto_uri) )
+ {
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_CONFLICT,
+ TALER_EC_EXCHANGE_RESERVES_CLOSE_NO_TARGET_ACCOUNT,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ if ( (NULL != rcc->payto_uri) &&
+ ( (NULL == payto_uri) ||
+ (0 != strcmp (payto_uri,
+ rcc->payto_uri)) ) )
+ {
+ /* KYC check may be needed: we're not returning
+ the money to the account that funded the reserve
+ in the first place. */
+ char *kyc_needed;
+
+ TALER_payto_hash (rcc->payto_uri,
+ &rcc->kyc_payto);
+ rcc->qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE,
+ &rcc->kyc_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &amount_it,
+ rcc,
+ &kyc_needed);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "iterate_reserve_close_info");
+ return qs;
+ }
+ if (rcc->qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == rcc->qs)
+ return rcc->qs;
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "iterate_reserve_close_info");
+ return qs;
+ }
+ if (NULL != kyc_needed)
+ {
+ rcc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ kyc_needed,
+ &rcc->kyc_payto,
+ rcc->reserve_pub,
+ &rcc->kyc.requirement_row);
+ GNUNET_free (kyc_needed);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_for_account");
+ }
+ return qs;
+ }
+ }
+
+ rcc->kyc.ok = true;
+ if (NULL == rcc->payto_uri)
+ rcc->payto_uri = payto_uri;
+
+ {
+ char *method;
+
+ method = TALER_payto_get_method (rcc->payto_uri);
+ wf = TEH_wire_fees_by_time (rcc->timestamp,
+ method);
+ if (NULL == wf)
+ {
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_WIRE_FEES_NOT_CONFIGURED,
+ method);
+ GNUNET_free (method);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ GNUNET_free (method);
+ }
+
+ if (0 >
+ TALER_amount_subtract (&rcc->wire_amount,
+ &rcc->balance,
+ &wf->closing))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Client attempted to close reserve with insufficient balance.\n");
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &rcc->wire_amount));
+ *mhd_ret = reply_reserve_close_success (connection,
+ rcc);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ qs = TEH_plugin->insert_close_request (TEH_plugin->cls,
+ rcc->reserve_pub,
+ payto_uri,
+ &rcc->reserve_sig,
+ rcc->timestamp,
+ &rcc->balance,
+ &wf->closing);
+ GNUNET_free (payto_uri);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "insert_close_request");
+ return qs;
+ }
+ if (qs <= 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ return qs;
+}
+
+
+MHD_RESULT
+TEH_handler_reserves_close (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root)
+{
+ struct ReserveCloseContext rcc = {
+ .payto_uri = NULL,
+ .reserve_pub = reserve_pub
+ };
+ MHD_RESULT mhd_ret;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_timestamp ("request_timestamp",
+ &rcc.timestamp),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &rcc.payto_uri),
+ NULL),
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rcc.reserve_sig),
+ GNUNET_JSON_spec_end ()
+ };
+
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (rc->connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ return MHD_YES; /* failure */
+ }
+ }
+
+ {
+ struct GNUNET_TIME_Timestamp now;
+
+ now = GNUNET_TIME_timestamp_get ();
+ if (! GNUNET_TIME_absolute_approx_eq (now.abs_time,
+ rcc.timestamp.abs_time,
+ TIMESTAMP_TOLERANCE))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_CLOCK_SKEW,
+ NULL);
+ }
+ }
+
+ if (NULL != rcc.payto_uri)
+ TALER_payto_hash (rcc.payto_uri,
+ &rcc.h_payto);
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_close_verify (rcc.timestamp,
+ &rcc.h_payto,
+ reserve_pub,
+ &rcc.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_RESERVES_CLOSE_BAD_SIGNATURE,
+ NULL);
+ }
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (rc->connection,
+ "reserve close",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &reserve_close_transaction,
+ &rcc))
+ {
+ return mhd_ret;
+ }
+ if (! rcc.kyc.ok)
+ return TEH_RESPONSE_reply_kyc_required (rc->connection,
+ &rcc.kyc_payto,
+ &rcc.kyc);
+
+ return reply_reserve_close_success (rc->connection,
+ &rcc);
+}
+
+
+/* end of taler-exchange-httpd_reserves_close.c */
diff --git a/src/exchange/taler-exchange-httpd_reserves_status.h b/src/exchange/taler-exchange-httpd_reserves_close.h
index 831b270f7..4c70b17cb 100644
--- a/src/exchange/taler-exchange-httpd_reserves_status.h
+++ b/src/exchange/taler-exchange-httpd_reserves_close.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,21 +14,19 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
/**
- * @file taler-exchange-httpd_reserves_status.h
- * @brief Handle /reserves/$RESERVE_PUB STATUS requests
- * @author Florian Dold
- * @author Benedikt Mueller
+ * @file taler-exchange-httpd_reserves_close.h
+ * @brief Handle /reserves/$RESERVE_PUB/close requests
* @author Christian Grothoff
*/
-#ifndef TALER_EXCHANGE_HTTPD_RESERVES_STATUS_H
-#define TALER_EXCHANGE_HTTPD_RESERVES_STATUS_H
+#ifndef TALER_EXCHANGE_HTTPD_RESERVES_CLOSE_H
+#define TALER_EXCHANGE_HTTPD_RESERVES_CLOSE_H
#include <microhttpd.h>
#include "taler-exchange-httpd.h"
/**
- * Handle a POST "/reserves/$RID/status" request.
+ * Handle a POST "/reserves/$RID/close" request.
*
* @param rc request context
* @param reserve_pub public key of the reserve
@@ -36,8 +34,8 @@
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_reserves_status (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root);
+TEH_handler_reserves_close (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root);
#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_get.c b/src/exchange/taler-exchange-httpd_reserves_get.c
index 27f8faecd..0775a4c65 100644
--- a/src/exchange/taler-exchange-httpd_reserves_get.c
+++ b/src/exchange/taler-exchange-httpd_reserves_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -52,8 +52,12 @@ struct ReservePoller
struct MHD_Connection *connection;
/**
- * Subscription for the database event we are
- * waiting for.
+ * Our request context.
+ */
+ struct TEH_RequestContext *rc;
+
+ /**
+ * Subscription for the database event we are waiting for.
*/
struct GNUNET_DB_EventHandler *eh;
@@ -63,6 +67,16 @@ struct ReservePoller
struct GNUNET_TIME_Absolute timeout;
/**
+ * Public key of the reserve the inquiry is about.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Balance of the reserve, set in the callback.
+ */
+ struct TALER_Amount balance;
+
+ /**
* True if we are still suspended.
*/
bool suspended;
@@ -84,13 +98,10 @@ static struct ReservePoller *rp_tail;
void
TEH_reserves_get_cleanup ()
{
- struct ReservePoller *rp;
-
- while (NULL != (rp = rp_head))
+ for (struct ReservePoller *rp = rp_head;
+ NULL != rp;
+ rp = rp->next)
{
- GNUNET_CONTAINER_DLL_remove (rp_head,
- rp_tail,
- rp);
if (rp->suspended)
{
rp->suspended = false;
@@ -115,11 +126,14 @@ rp_cleanup (struct TEH_RequestContext *rc)
if (NULL != rp->eh)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Cancelling DB event listening\n");
+ "Cancelling DB event listening on cleanup (odd unless during shutdown)\n");
TEH_plugin->event_listen_cancel (TEH_plugin->cls,
rp->eh);
rp->eh = NULL;
}
+ GNUNET_CONTAINER_DLL_remove (rp_head,
+ rp_tail,
+ rp);
GNUNET_free (rp);
}
@@ -137,26 +151,17 @@ db_event_cb (void *cls,
const void *extra,
size_t extra_size)
{
- struct TEH_RequestContext *rc = cls;
- struct ReservePoller *rp = rc->rh_ctx;
+ struct ReservePoller *rp = cls;
struct GNUNET_AsyncScopeSave old_scope;
(void) extra;
(void) extra_size;
- if (NULL == rp)
- return; /* event triggered while main transaction
- was still running */
if (! rp->suspended)
return; /* might get multiple wake-up events */
- rp->suspended = false;
- GNUNET_async_scope_enter (&rc->async_scope_id,
+ GNUNET_async_scope_enter (&rp->rc->async_scope_id,
&old_scope);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Resuming from long-polling on reserve\n");
TEH_check_invariants ();
- GNUNET_CONTAINER_DLL_remove (rp_head,
- rp_tail,
- rp);
+ rp->suspended = false;
MHD_resume_connection (rp->connection);
TALER_MHD_daemon_trigger ();
TEH_check_invariants ();
@@ -164,191 +169,95 @@ db_event_cb (void *cls,
}
-/**
- * Closure for #reserve_history_transaction.
- */
-struct ReserveHistoryContext
-{
- /**
- * Public key of the reserve the inquiry is about.
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- /**
- * Balance of the reserve, set in the callback.
- */
- struct TALER_Amount balance;
-
- /**
- * Set to true if we did not find the reserve.
- */
- bool not_found;
-};
-
-
-/**
- * Function implementing /reserves/ GET transaction.
- * Execute a /reserves/ GET. Given the public key of a reserve,
- * return the associated transaction history. Runs the
- * transaction logic; IF it returns a non-error code, the transaction
- * logic MUST NOT queue a MHD response. IF it returns an hard error,
- * the transaction logic MUST queue a MHD response and set @a mhd_ret.
- * IF it returns the soft error code, the function MAY be called again
- * to retry and MUST not queue a MHD response.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param connection MHD request which triggered the transaction
- * @param[out] mhd_ret set to MHD response status for @a connection,
- * if transaction failed (!)
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-reserve_balance_transaction (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
-{
- struct ReserveHistoryContext *rsc = cls;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TEH_plugin->get_reserve_balance (TEH_plugin->cls,
- &rsc->reserve_pub,
- &rsc->balance);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_reserve_balance");
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- rsc->not_found = true;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- rsc->not_found = false;
- return qs;
-}
-
-
MHD_RESULT
-TEH_handler_reserves_get (struct TEH_RequestContext *rc,
- const char *const args[1])
+TEH_handler_reserves_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
- struct ReserveHistoryContext rsc;
- struct GNUNET_TIME_Relative timeout = GNUNET_TIME_UNIT_ZERO;
- struct GNUNET_DB_EventHandler *eh = NULL;
-
- if (GNUNET_OK !=
- GNUNET_STRINGS_string_to_data (args[0],
- strlen (args[0]),
- &rsc.reserve_pub,
- sizeof (rsc.reserve_pub)))
+ struct ReservePoller *rp = rc->rh_ctx;
+
+ if (NULL == rp)
{
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_MERCHANT_GENERIC_RESERVE_PUB_MALFORMED,
- args[0]);
+ rp = GNUNET_new (struct ReservePoller);
+ rp->connection = rc->connection;
+ rp->rc = rc;
+ rc->rh_ctx = rp;
+ rc->rh_cleaner = &rp_cleanup;
+ GNUNET_CONTAINER_DLL_insert (rp_head,
+ rp_tail,
+ rp);
+ rp->reserve_pub = *reserve_pub;
+ TALER_MHD_parse_request_timeout (rc->connection,
+ &rp->timeout);
}
- {
- const char *long_poll_timeout_ms;
-
- long_poll_timeout_ms
- = MHD_lookup_connection_value (rc->connection,
- MHD_GET_ARGUMENT_KIND,
- "timeout_ms");
- if (NULL != long_poll_timeout_ms)
- {
- unsigned int timeout_ms;
- char dummy;
- if (1 != sscanf (long_poll_timeout_ms,
- "%u%c",
- &timeout_ms,
- &dummy))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MALFORMED,
- "timeout_ms (must be non-negative number)");
- }
- timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- timeout_ms);
- }
- }
- if ( (! GNUNET_TIME_relative_is_zero (timeout)) &&
- (NULL == rc->rh_ctx) )
+ if ( (GNUNET_TIME_absolute_is_future (rp->timeout)) &&
+ (NULL == rp->eh) )
{
struct TALER_ReserveEventP rep = {
.header.size = htons (sizeof (rep)),
.header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
- .reserve_pub = rsc.reserve_pub
+ .reserve_pub = rp->reserve_pub
};
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting DB event listening\n");
- eh = TEH_plugin->event_listen (TEH_plugin->cls,
- timeout,
- &rep.header,
- &db_event_cb,
- rc);
+ "Starting DB event listening until %s\n",
+ GNUNET_TIME_absolute2s (rp->timeout));
+ rp->eh = TEH_plugin->event_listen (
+ TEH_plugin->cls,
+ GNUNET_TIME_absolute_get_remaining (rp->timeout),
+ &rep.header,
+ &db_event_cb,
+ rp);
}
{
- MHD_RESULT mhd_ret;
-
- if (GNUNET_OK !=
- TEH_DB_run_transaction (rc->connection,
- "get reserve balance",
- TEH_MT_REQUEST_OTHER,
- &mhd_ret,
- &reserve_balance_transaction,
- &rsc))
- {
- if (NULL != eh)
- TEH_plugin->event_listen_cancel (TEH_plugin->cls,
- eh);
- return mhd_ret;
- }
- }
- /* generate proper response */
- if (rsc.not_found)
- {
- struct ReservePoller *rp = rc->rh_ctx;
+ enum GNUNET_DB_QueryStatus qs;
- if ( (NULL != rp) ||
- (GNUNET_TIME_relative_is_zero (timeout)) )
+ qs = TEH_plugin->get_reserve_balance (TEH_plugin->cls,
+ &rp->reserve_pub,
+ &rp->balance);
+ switch (qs)
{
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0); /* single-shot query should never have soft-errors */
return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_RESERVES_STATUS_UNKNOWN,
- args[0]);
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "get_reserve_balance");
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_reserve_balance");
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got reserve balance of %s\n",
+ TALER_amount2s (&rp->balance));
+ return TALER_MHD_REPLY_JSON_PACK (rc->connection,
+ MHD_HTTP_OK,
+ TALER_JSON_pack_amount ("balance",
+ &rp->balance));
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ if (! GNUNET_TIME_absolute_is_future (rp->timeout))
+ {
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ NULL);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Long-polling on reserve for %s\n",
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_remaining (rp->timeout),
+ true));
+ rp->suspended = true;
+ MHD_suspend_connection (rc->connection);
+ return MHD_YES;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Long-polling on reserve for %s\n",
- GNUNET_STRINGS_relative_time_to_string (timeout,
- GNUNET_YES));
- rp = GNUNET_new (struct ReservePoller);
- rp->connection = rc->connection;
- rp->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- rp->eh = eh;
- rc->rh_ctx = rp;
- rc->rh_cleaner = &rp_cleanup;
- rp->suspended = true;
- GNUNET_CONTAINER_DLL_insert (rp_head,
- rp_tail,
- rp);
- MHD_suspend_connection (rc->connection);
- return MHD_YES;
}
- if (NULL != eh)
- TEH_plugin->event_listen_cancel (TEH_plugin->cls,
- eh);
- return TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_amount ("balance",
- &rsc.balance));
+ GNUNET_break (0);
+ return MHD_NO;
}
diff --git a/src/exchange/taler-exchange-httpd_reserves_get.h b/src/exchange/taler-exchange-httpd_reserves_get.h
index 30c6559f6..6c453d0cd 100644
--- a/src/exchange/taler-exchange-httpd_reserves_get.h
+++ b/src/exchange/taler-exchange-httpd_reserves_get.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -43,11 +43,12 @@ TEH_reserves_get_cleanup (void);
* status of the reserve.
*
* @param rc request context
- * @param args array of additional options (length: 1, just the reserve_pub)
+ * @param reserve_pub public key of the reserve
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_reserves_get (struct TEH_RequestContext *rc,
- const char *const args[1]);
+TEH_handler_reserves_get (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_get_attest.c b/src/exchange/taler-exchange-httpd_reserves_get_attest.c
new file mode 100644
index 000000000..ae983682a
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_get_attest.c
@@ -0,0 +1,232 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_get_attest.c
+ * @brief Handle GET /reserves/$RESERVE_PUB/attest requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include "taler_kyclogic_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include "taler_dbevents.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_reserves_get_attest.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * Closure for #reserve_attest_transaction.
+ */
+struct ReserveAttestContext
+{
+ /**
+ * Public key of the reserve the inquiry is about.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Hash of the payto URI of this reserve.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Available attributes.
+ */
+ json_t *attributes;
+
+ /**
+ * Set to true if we did not find the reserve.
+ */
+ bool not_found;
+};
+
+
+/**
+ * Function called with information about all applicable
+ * legitimization processes for the given user.
+ *
+ * @param cls our `struct ReserveAttestContext *`
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+static void
+kyc_process_cb (void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes)
+{
+ struct ReserveAttestContext *rsc = cls;
+ json_t *attrs;
+ json_t *val;
+ const char *name;
+
+ if (GNUNET_TIME_absolute_is_past (expiration_time.abs_time))
+ return;
+ attrs = TALER_CRYPTO_kyc_attributes_decrypt (&TEH_attribute_key,
+ enc_attributes,
+ enc_attributes_size);
+ json_object_foreach (attrs, name, val)
+ {
+ bool duplicate = false;
+ size_t idx;
+ json_t *str;
+
+ json_array_foreach (rsc->attributes, idx, str)
+ {
+ if (0 == strcmp (json_string_value (str),
+ name))
+ {
+ duplicate = true;
+ break;
+ }
+ }
+ if (duplicate)
+ continue;
+ GNUNET_assert (0 ==
+ json_array_append (rsc->attributes,
+ json_string (name)));
+ }
+}
+
+
+/**
+ * Function implementing GET /reserves/$RID/attest transaction.
+ * Execute a /reserves/ get attest. Given the public key of a reserve,
+ * return the associated transaction attest. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction
+ * logic MUST NOT queue a MHD response. IF it returns an hard error,
+ * the transaction logic MUST queue a MHD response and set @a mhd_ret.
+ * IF it returns the soft error code, the function MAY be called again
+ * to retry and MUST not queue a MHD response.
+ *
+ * @param cls a `struct ReserveAttestContext *`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+reserve_attest_transaction (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct ReserveAttestContext *rsc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ rsc->attributes = json_array ();
+ GNUNET_assert (NULL != rsc->attributes);
+ qs = TEH_plugin->select_kyc_attributes (TEH_plugin->cls,
+ &rsc->h_payto,
+ &kyc_process_cb,
+ rsc);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "iterate_kyc_reference");
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ rsc->not_found = true;
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ rsc->not_found = false;
+ break;
+ }
+ return qs;
+}
+
+
+MHD_RESULT
+TEH_handler_reserves_get_attest (struct TEH_RequestContext *rc,
+ const char *const args[1])
+{
+ struct ReserveAttestContext rsc = {
+ .attributes = NULL
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (args[0],
+ strlen (args[0]),
+ &rsc.reserve_pub,
+ sizeof (rsc.reserve_pub)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_RESERVE_PUB_MALFORMED,
+ args[0]);
+ }
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (TEH_base_url,
+ &rsc.reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &rsc.h_payto);
+ GNUNET_free (payto_uri);
+ }
+ {
+ MHD_RESULT mhd_ret;
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (rc->connection,
+ "get-attestable",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &reserve_attest_transaction,
+ &rsc))
+ {
+ json_decref (rsc.attributes);
+ rsc.attributes = NULL;
+ return mhd_ret;
+ }
+ }
+ /* generate proper response */
+ if (rsc.not_found)
+ {
+ json_decref (rsc.attributes);
+ rsc.attributes = NULL;
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ args[0]);
+ }
+ return TALER_MHD_REPLY_JSON_PACK (
+ rc->connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_array_steal ("details",
+ rsc.attributes));
+}
+
+
+/* end of taler-exchange-httpd_reserves_get_attest.c */
diff --git a/src/exchange/taler-exchange-httpd_reserves_get_attest.h b/src/exchange/taler-exchange-httpd_reserves_get_attest.h
new file mode 100644
index 000000000..8b5e3aba3
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_get_attest.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_get_attest.h
+ * @brief Handle /reserves/$RESERVE_PUB GET_ATTEST requests
+ * @author Florian Dold
+ * @author Benedikt Mueller
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_RESERVES_GET_ATTEST_H
+#define TALER_EXCHANGE_HTTPD_RESERVES_GET_ATTEST_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Handle a GET "/reserves/$RID/attest" request. Parses the
+ * given "reserve_pub" in @a args (which should contain the
+ * EdDSA public key of a reserve) and then responds with the
+ * available attestations for the reserve.
+ *
+ * @param rc request context
+ * @param args array of additional options (length: 1, just the reserve_pub)
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_reserves_get_attest (struct TEH_RequestContext *rc,
+ const char *const args[1]);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_history.c b/src/exchange/taler-exchange-httpd_reserves_history.c
index 2c9362447..056d4b0ef 100644
--- a/src/exchange/taler-exchange-httpd_reserves_history.c
+++ b/src/exchange/taler-exchange-httpd_reserves_history.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -15,7 +15,7 @@
*/
/**
* @file taler-exchange-httpd_reserves_history.c
- * @brief Handle /reserves/$RESERVE_PUB/history requests
+ * @brief Handle /reserves/$RESERVE_PUB HISTORY requests
* @author Florian Dold
* @author Benedikt Mueller
* @author Christian Grothoff
@@ -23,7 +23,6 @@
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
-#include "taler_mhd_lib.h"
#include "taler_json_lib.h"
#include "taler_dbevents.h"
#include "taler-exchange-httpd_keys.h"
@@ -32,265 +31,486 @@
/**
- * How far do we allow a client's time to be off when
- * checking the request timestamp?
+ * Compile the history of a reserve into a JSON object.
+ *
+ * @param rh reserve history to JSON-ify
+ * @return json representation of the @a rh, NULL on error
*/
-#define TIMESTAMP_TOLERANCE \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+static json_t *
+compile_reserve_history (
+ const struct TALER_EXCHANGEDB_ReserveHistory *rh)
+{
+ json_t *json_history;
+ json_history = json_array ();
+ GNUNET_assert (NULL != json_history);
+ for (const struct TALER_EXCHANGEDB_ReserveHistory *pos = rh;
+ NULL != pos;
+ pos = pos->next)
+ {
+ switch (pos->type)
+ {
+ case TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE:
+ {
+ const struct TALER_EXCHANGEDB_BankTransfer *bank =
+ pos->details.bank;
-/**
- * Closure for #reserve_history_transaction.
- */
-struct ReserveHistoryContext
-{
- /**
- * Public key of the reserve the inquiry is about.
- */
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- /**
- * Timestamp of the request.
- */
- struct GNUNET_TIME_Timestamp timestamp;
-
- /**
- * Client signature approving the request.
- */
- struct TALER_ReserveSignatureP reserve_sig;
-
- /**
- * History of the reserve, set in the callback.
- */
- struct TALER_EXCHANGEDB_ReserveHistory *rh;
-
- /**
- * Global fees applying to the request.
- */
- const struct TEH_GlobalFee *gf;
-
- /**
- * Current reserve balance.
- */
- struct TALER_Amount balance;
-};
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "CREDIT"),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ bank->execution_date),
+ GNUNET_JSON_pack_string ("sender_account_url",
+ bank->sender_account_details),
+ GNUNET_JSON_pack_uint64 ("wire_reference",
+ bank->wire_reference),
+ TALER_JSON_pack_amount ("amount",
+ &bank->amount))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ break;
+ }
+ case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
+ {
+ const struct TALER_EXCHANGEDB_CollectableBlindcoin *withdraw
+ = pos->details.withdraw;
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "WITHDRAW"),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &withdraw->reserve_sig),
+ GNUNET_JSON_pack_data_auto ("h_coin_envelope",
+ &withdraw->h_coin_envelope),
+ GNUNET_JSON_pack_data_auto ("h_denom_pub",
+ &withdraw->denom_pub_hash),
+ TALER_JSON_pack_amount ("withdraw_fee",
+ &withdraw->withdraw_fee),
+ TALER_JSON_pack_amount ("amount",
+ &withdraw->amount_with_fee))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_RO_RECOUP_COIN:
+ {
+ const struct TALER_EXCHANGEDB_Recoup *recoup
+ = pos->details.recoup;
+ struct TALER_ExchangePublicKeyP pub;
+ struct TALER_ExchangeSignatureP sig;
-/**
- * Send reserve history to client.
- *
- * @param connection connection to the client
- * @param rhc reserve history to return
- * @return MHD result code
- */
-static MHD_RESULT
-reply_reserve_history_success (struct MHD_Connection *connection,
- const struct ReserveHistoryContext *rhc)
-{
- const struct TALER_EXCHANGEDB_ReserveHistory *rh = rhc->rh;
- json_t *json_history;
+ if (TALER_EC_NONE !=
+ TALER_exchange_online_confirm_recoup_sign (
+ &TEH_keys_exchange_sign_,
+ recoup->timestamp,
+ &recoup->value,
+ &recoup->coin.coin_pub,
+ &recoup->reserve_pub,
+ &pub,
+ &sig))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "RECOUP"),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &pub),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &sig),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ recoup->timestamp),
+ TALER_JSON_pack_amount ("amount",
+ &recoup->value),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &recoup->coin.coin_pub))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
+ {
+ const struct TALER_EXCHANGEDB_ClosingTransfer *closing =
+ pos->details.closing;
+ struct TALER_ExchangePublicKeyP pub;
+ struct TALER_ExchangeSignatureP sig;
+
+ if (TALER_EC_NONE !=
+ TALER_exchange_online_reserve_closed_sign (
+ &TEH_keys_exchange_sign_,
+ closing->execution_date,
+ &closing->amount,
+ &closing->closing_fee,
+ closing->receiver_account_details,
+ &closing->wtid,
+ &pos->details.closing->reserve_pub,
+ &pub,
+ &sig))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "CLOSING"),
+ GNUNET_JSON_pack_string ("receiver_account_details",
+ closing->receiver_account_details),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ &closing->wtid),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &pub),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &sig),
+ GNUNET_JSON_pack_timestamp ("timestamp",
+ closing->execution_date),
+ TALER_JSON_pack_amount ("amount",
+ &closing->amount),
+ TALER_JSON_pack_amount ("closing_fee",
+ &closing->closing_fee))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_RO_PURSE_MERGE:
+ {
+ const struct TALER_EXCHANGEDB_PurseMerge *merge =
+ pos->details.merge;
+
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "MERGE"),
+ GNUNET_JSON_pack_data_auto ("h_contract_terms",
+ &merge->h_contract_terms),
+ GNUNET_JSON_pack_data_auto ("merge_pub",
+ &merge->merge_pub),
+ GNUNET_JSON_pack_uint64 ("min_age",
+ merge->min_age),
+ GNUNET_JSON_pack_uint64 ("flags",
+ merge->flags),
+ GNUNET_JSON_pack_data_auto ("purse_pub",
+ &merge->purse_pub),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &merge->reserve_sig),
+ GNUNET_JSON_pack_timestamp ("merge_timestamp",
+ merge->merge_timestamp),
+ GNUNET_JSON_pack_timestamp ("purse_expiration",
+ merge->purse_expiration),
+ TALER_JSON_pack_amount ("purse_fee",
+ &merge->purse_fee),
+ TALER_JSON_pack_amount ("amount",
+ &merge->amount_with_fee),
+ GNUNET_JSON_pack_bool ("merged",
+ merge->merged))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+ case TALER_EXCHANGEDB_RO_HISTORY_REQUEST:
+ {
+ const struct TALER_EXCHANGEDB_HistoryRequest *history =
+ pos->details.history;
- json_history = TEH_RESPONSE_compile_reserve_history (rh);
- if (NULL == json_history)
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- NULL);
- /* FIXME: should set explicit cache control headers
- for this response to enable caching! */
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_amount ("balance",
- &rhc->balance),
- GNUNET_JSON_pack_array_steal ("history",
- json_history));
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "HISTORY"),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &history->reserve_sig),
+ GNUNET_JSON_pack_timestamp ("request_timestamp",
+ history->request_timestamp),
+ TALER_JSON_pack_amount ("amount",
+ &history->history_fee))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+
+ case TALER_EXCHANGEDB_RO_OPEN_REQUEST:
+ {
+ const struct TALER_EXCHANGEDB_OpenRequest *orq =
+ pos->details.open_request;
+
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "OPEN"),
+ GNUNET_JSON_pack_uint64 ("requested_min_purses",
+ orq->purse_limit),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &orq->reserve_sig),
+ GNUNET_JSON_pack_timestamp ("request_timestamp",
+ orq->request_timestamp),
+ GNUNET_JSON_pack_timestamp ("requested_expiration",
+ orq->reserve_expiration),
+ TALER_JSON_pack_amount ("open_fee",
+ &orq->open_fee))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+
+ case TALER_EXCHANGEDB_RO_CLOSE_REQUEST:
+ {
+ const struct TALER_EXCHANGEDB_CloseRequest *crq =
+ pos->details.close_request;
+
+ if (0 !=
+ json_array_append_new (
+ json_history,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "CLOSE"),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &crq->reserve_sig),
+ GNUNET_is_zero (&crq->target_account_h_payto)
+ ? GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("h_payto",
+ NULL))
+ : GNUNET_JSON_pack_data_auto ("h_payto",
+ &crq->target_account_h_payto),
+ GNUNET_JSON_pack_timestamp ("request_timestamp",
+ crq->request_timestamp))))
+ {
+ GNUNET_break (0);
+ json_decref (json_history);
+ return NULL;
+ }
+ }
+ break;
+ }
+ }
+
+ return json_history;
}
/**
- * Function implementing /reserves/$RID/history transaction. Given the public
- * key of a reserve, return the associated transaction history. Runs the
- * transaction logic; IF it returns a non-error code, the transaction logic
- * MUST NOT queue a MHD response. IF it returns an hard error, the
- * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
- * returns the soft error code, the function MAY be called again to retry and
- * MUST not queue a MHD response.
+ * Add the headers we want to set for every /keys response.
*
- * @param cls a `struct ReserveHistoryContext *`
- * @param connection MHD request which triggered the transaction
- * @param[out] mhd_ret set to MHD response status for @a connection,
- * if transaction failed (!); unused
- * @return transaction status
+ * @param cls the key state to use
+ * @param[in,out] response the response to modify
*/
-static enum GNUNET_DB_QueryStatus
-reserve_history_transaction (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
+static void
+add_response_headers (void *cls,
+ struct MHD_Response *response)
+{
+ (void) cls;
+ TALER_MHD_add_global_headers (response);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (response,
+ MHD_HTTP_HEADER_CACHE_CONTROL,
+ "no-cache"));
+}
+
+
+MHD_RESULT
+TEH_handler_reserves_history (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
- struct ReserveHistoryContext *rsc = cls;
- enum GNUNET_DB_QueryStatus qs;
+ struct TALER_EXCHANGEDB_ReserveHistory *rh = NULL;
+ uint64_t start_off = 0;
+ struct TALER_Amount balance;
+ uint64_t etag_in;
+ uint64_t etag_out;
+ char etagp[24];
+ struct MHD_Response *resp;
+ unsigned int http_status;
- if (! TALER_amount_is_zero (&rsc->gf->fees.history))
+ TALER_MHD_parse_request_number (rc->connection,
+ "start",
+ &start_off);
{
- bool balance_ok = false;
- bool idempotent = true;
-
- qs = TEH_plugin->insert_history_request (TEH_plugin->cls,
- rsc->reserve_pub,
- &rsc->reserve_sig,
- rsc->timestamp,
- &rsc->gf->fees.history,
- &balance_ok,
- &idempotent);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_reserve_history");
- }
- if (qs <= 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- if (! balance_ok)
+ struct TALER_ReserveSignatureP reserve_sig;
+ bool required = true;
+
+ TALER_MHD_parse_request_header_auto (rc->connection,
+ TALER_RESERVE_HISTORY_SIGNATURE_HEADER,
+ &reserve_sig,
+ required);
+
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_history_verify (start_off,
+ reserve_pub,
+ &reserve_sig))
{
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_CONFLICT,
- TALER_EC_EXCHANGE_WITHDRAW_HISTORY_ERROR_INSUFFICIENT_FUNDS,
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_RESERVE_HISTORY_BAD_SIGNATURE,
NULL);
}
- if (idempotent)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Idempotent /reserves/history request observed. Is caching working?\n");
- }
}
- qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
- rsc->reserve_pub,
- &rsc->balance,
- &rsc->rh);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_reserve_history");
- }
- return qs;
-}
-
-MHD_RESULT
-TEH_handler_reserves_history (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root)
-{
- struct ReserveHistoryContext rsc;
- MHD_RESULT mhd_ret;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("request_timestamp",
- &rsc.timestamp),
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &rsc.reserve_sig),
- GNUNET_JSON_spec_end ()
- };
- struct GNUNET_TIME_Timestamp now;
-
- rsc.reserve_pub = reserve_pub;
+ /* Get etag */
{
- enum GNUNET_GenericReturnValue res;
+ const char *etags;
- res = TALER_MHD_parse_json_data (rc->connection,
- root,
- spec);
- if (GNUNET_SYSERR == res)
+ etags = MHD_lookup_connection_value (rc->connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_IF_NONE_MATCH);
+ if (NULL != etags)
{
- GNUNET_break (0);
- return MHD_NO; /* hard failure */
+ char dummy;
+ unsigned long long ev;
+
+ if (1 != sscanf (etags,
+ "\"%llu\"%c",
+ &ev,
+ &dummy))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Client send malformed `If-None-Match' header `%s'\n",
+ etags);
+ etag_in = 0;
+ }
+ else
+ {
+ etag_in = (uint64_t) ev;
+ }
}
- if (GNUNET_NO == res)
+ else
{
- GNUNET_break_op (0);
- return MHD_YES; /* failure */
+ etag_in = start_off;
}
}
- now = GNUNET_TIME_timestamp_get ();
- if (! GNUNET_TIME_absolute_approx_eq (now.abs_time,
- rsc.timestamp.abs_time,
- TIMESTAMP_TOLERANCE))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_CLOCK_SKEW,
- NULL);
- }
+
{
- struct TEH_KeyStateHandle *keys;
+ enum GNUNET_DB_QueryStatus qs;
- keys = TEH_keys_get_state ();
- if (NULL == keys)
+ qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
+ reserve_pub,
+ start_off,
+ etag_in,
+ &etag_out,
+ &balance,
+ &rh);
+ switch (qs)
{
+ case GNUNET_DB_STATUS_HARD_ERROR:
GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
return TALER_MHD_reply_with_error (rc->connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "get_reserve_history");
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_SOFT_FAILURE,
+ "get_reserve_history");
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
NULL);
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* Handled below */
+ break;
}
- rsc.gf = TEH_keys_global_fee_by_time (keys,
- rsc.timestamp);
}
- if (NULL == rsc.gf)
+
+ GNUNET_snprintf (etagp,
+ sizeof (etagp),
+ "\"%llu\"",
+ (unsigned long long) etag_out);
+ if (etag_in == etag_out)
{
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
- NULL);
+ return TEH_RESPONSE_reply_not_modified (rc->connection,
+ etagp,
+ &add_response_headers,
+ NULL);
}
- if (GNUNET_OK !=
- TALER_wallet_reserve_history_verify (rsc.timestamp,
- &rsc.gf->fees.history,
- reserve_pub,
- &rsc.reserve_sig))
+ if (NULL == rh)
{
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_RESERVES_HISTORY_BAD_SIGNATURE,
- NULL);
+ /* 204: empty history */
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ http_status = MHD_HTTP_NO_CONTENT;
}
- rsc.rh = NULL;
- if (GNUNET_OK !=
- TEH_DB_run_transaction (rc->connection,
- "get reserve history",
- TEH_MT_REQUEST_OTHER,
- &mhd_ret,
- &reserve_history_transaction,
- &rsc))
+ else
{
- return mhd_ret;
+ json_t *history;
+
+ http_status = MHD_HTTP_OK;
+ history = compile_reserve_history (rh);
+ TEH_plugin->free_reserve_history (TEH_plugin->cls,
+ rh);
+ rh = NULL;
+ if (NULL == history)
+ {
+ GNUNET_break (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
+ NULL);
+ }
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_amount ("balance",
+ &balance),
+ GNUNET_JSON_pack_array_steal ("history",
+ history));
}
- if (NULL == rsc.rh)
+ add_response_headers (NULL,
+ resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_ETAG,
+ etagp));
{
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_RESERVES_STATUS_UNKNOWN,
- NULL);
+ MHD_RESULT ret;
+
+ ret = MHD_queue_response (rc->connection,
+ http_status,
+ resp);
+ GNUNET_break (MHD_YES == ret);
+ MHD_destroy_response (resp);
+ return ret;
}
- mhd_ret = reply_reserve_history_success (rc->connection,
- &rsc);
- TEH_plugin->free_reserve_history (TEH_plugin->cls,
- rsc.rh);
- return mhd_ret;
}
diff --git a/src/exchange/taler-exchange-httpd_reserves_history.h b/src/exchange/taler-exchange-httpd_reserves_history.h
index 9a2a93782..e1bd7ae1b 100644
--- a/src/exchange/taler-exchange-httpd_reserves_history.h
+++ b/src/exchange/taler-exchange-httpd_reserves_history.h
@@ -15,7 +15,7 @@
*/
/**
* @file taler-exchange-httpd_reserves_history.h
- * @brief Handle /reserves/$RESERVE_PUB HISTORY requests
+ * @brief Handle /reserves/$RESERVE_PUB/history requests
* @author Florian Dold
* @author Benedikt Mueller
* @author Christian Grothoff
@@ -24,20 +24,20 @@
#define TALER_EXCHANGE_HTTPD_RESERVES_HISTORY_H
#include <microhttpd.h>
+#include "taler_mhd_lib.h"
#include "taler-exchange-httpd.h"
/**
- * Handle a POST "/reserves/$RID/history" request.
+ * Handle a GET "/reserves/$RID/history" request.
*
* @param rc request context
* @param reserve_pub public key of the reserve
- * @param root uploaded body from the client
* @return MHD result code
*/
MHD_RESULT
-TEH_handler_reserves_history (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root);
+TEH_handler_reserves_history (
+ struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub);
#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_open.c b/src/exchange/taler-exchange-httpd_reserves_open.c
new file mode 100644
index 000000000..5aadc9e40
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_open.c
@@ -0,0 +1,471 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_open.c
+ * @brief Handle /reserves/$RESERVE_PUB/open requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include "taler_dbevents.h"
+#include "taler-exchange-httpd_common_deposit.h"
+#include "taler-exchange-httpd_keys.h"
+#include "taler-exchange-httpd_reserves_open.h"
+#include "taler-exchange-httpd_responses.h"
+
+
+/**
+ * How far do we allow a client's time to be off when
+ * checking the request timestamp?
+ */
+#define TIMESTAMP_TOLERANCE \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
+
+
+/**
+ * Closure for #reserve_open_transaction.
+ */
+struct ReserveOpenContext
+{
+ /**
+ * Public key of the reserve the inquiry is about.
+ */
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ /**
+ * Desired (minimum) expiration time for the reserve.
+ */
+ struct GNUNET_TIME_Timestamp desired_expiration;
+
+ /**
+ * Actual expiration time for the reserve.
+ */
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+
+ /**
+ * Timestamp of the request.
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ /**
+ * Client signature approving the request.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Global fees applying to the request.
+ */
+ const struct TEH_GlobalFee *gf;
+
+ /**
+ * Amount to be paid from the reserve.
+ */
+ struct TALER_Amount reserve_payment;
+
+ /**
+ * Actual cost to open the reserve.
+ */
+ struct TALER_Amount open_cost;
+
+ /**
+ * Total amount that was deposited.
+ */
+ struct TALER_Amount total;
+
+ /**
+ * Information about payments by coin.
+ */
+ struct TEH_PurseDepositedCoin *payments;
+
+ /**
+ * Length of the @e payments array.
+ */
+ unsigned int payments_len;
+
+ /**
+ * Desired minimum purse limit.
+ */
+ uint32_t purse_limit;
+
+ /**
+ * Set to true if the reserve balance is too low
+ * for the operation.
+ */
+ bool no_funds;
+
+};
+
+
+/**
+ * Send reserve open to client.
+ *
+ * @param connection connection to the client
+ * @param rsc reserve open data to return
+ * @return MHD result code
+ */
+static MHD_RESULT
+reply_reserve_open_success (struct MHD_Connection *connection,
+ const struct ReserveOpenContext *rsc)
+{
+ struct GNUNET_TIME_Timestamp now;
+ struct GNUNET_TIME_Timestamp re;
+ unsigned int status;
+
+ status = MHD_HTTP_OK;
+ if (GNUNET_TIME_timestamp_cmp (rsc->reserve_expiration,
+ <,
+ rsc->desired_expiration))
+ status = MHD_HTTP_PAYMENT_REQUIRED;
+ now = GNUNET_TIME_timestamp_get ();
+ if (GNUNET_TIME_timestamp_cmp (rsc->reserve_expiration,
+ <,
+ now))
+ re = now;
+ else
+ re = rsc->reserve_expiration;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ status,
+ GNUNET_JSON_pack_timestamp ("reserve_expiration",
+ re),
+ TALER_JSON_pack_amount ("open_cost",
+ &rsc->open_cost));
+}
+
+
+/**
+ * Cleans up information in @a rsc, but does not
+ * free @a rsc itself (allocated on the stack!).
+ *
+ * @param[in] rsc struct with information to clean up
+ */
+static void
+cleanup_rsc (struct ReserveOpenContext *rsc)
+{
+ for (unsigned int i = 0; i<rsc->payments_len; i++)
+ {
+ TEH_common_purse_deposit_free_coin (&rsc->payments[i]);
+ }
+ GNUNET_free (rsc->payments);
+}
+
+
+/**
+ * Function implementing /reserves/$RID/open transaction. Given the public
+ * key of a reserve, return the associated transaction open. Runs the
+ * transaction logic; IF it returns a non-error code, the transaction logic
+ * MUST NOT queue a MHD response. IF it returns an hard error, the
+ * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it
+ * returns the soft error code, the function MAY be called again to retry and
+ * MUST not queue a MHD response.
+ *
+ * @param cls a `struct ReserveOpenContext *`
+ * @param connection MHD request which triggered the transaction
+ * @param[out] mhd_ret set to MHD response status for @a connection,
+ * if transaction failed (!)
+ * @return transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+reserve_open_transaction (void *cls,
+ struct MHD_Connection *connection,
+ MHD_RESULT *mhd_ret)
+{
+ struct ReserveOpenContext *rsc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_Amount reserve_balance;
+
+ for (unsigned int i = 0; i<rsc->payments_len; i++)
+ {
+ struct TEH_PurseDepositedCoin *coin = &rsc->payments[i];
+ bool insufficient_funds = true;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Make coin %u known\n",
+ i);
+ qs = TEH_make_coin_known (&coin->cpi,
+ connection,
+ &coin->known_coin_id,
+ mhd_ret);
+ if (qs < 0)
+ return qs;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Insert open deposit %u known\n",
+ i);
+ qs = TEH_plugin->insert_reserve_open_deposit (
+ TEH_plugin->cls,
+ &coin->cpi,
+ &coin->coin_sig,
+ coin->known_coin_id,
+ &coin->amount,
+ &rsc->reserve_sig,
+ rsc->reserve_pub,
+ &insufficient_funds);
+ /* 0 == qs is fine, then the coin was already
+ spent for this very operation as identified
+ by reserve_sig! */
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_reserve_open_deposit");
+ return qs;
+ }
+ if (insufficient_funds)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handle insufficient funds\n");
+ *mhd_ret
+ = TEH_RESPONSE_reply_coin_insufficient_funds (
+ connection,
+ TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS,
+ &coin->cpi.denom_pub_hash,
+ &coin->cpi.coin_pub);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Do reserve open with reserve payment of %s\n",
+ TALER_amount2s (&rsc->total));
+ qs = TEH_plugin->do_reserve_open (TEH_plugin->cls,
+ /* inputs */
+ rsc->reserve_pub,
+ &rsc->total,
+ &rsc->reserve_payment,
+ rsc->purse_limit,
+ &rsc->reserve_sig,
+ rsc->desired_expiration,
+ rsc->timestamp,
+ &rsc->gf->fees.account,
+ /* outputs */
+ &rsc->no_funds,
+ &reserve_balance,
+ &rsc->open_cost,
+ &rsc->reserve_expiration);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "do_reserve_open");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
+ NULL);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ }
+ if (rsc->no_funds)
+ {
+ TEH_plugin->rollback (TEH_plugin->cls);
+ *mhd_ret
+ = TEH_RESPONSE_reply_reserve_insufficient_balance (
+ connection,
+ TALER_EC_EXCHANGE_RESERVES_OPEN_INSUFFICIENT_FUNDS,
+ &reserve_balance,
+ &rsc->reserve_payment,
+ rsc->reserve_pub);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+}
+
+
+MHD_RESULT
+TEH_handler_reserves_open (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root)
+{
+ struct ReserveOpenContext rsc;
+ const json_t *payments;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_timestamp ("request_timestamp",
+ &rsc.timestamp),
+ GNUNET_JSON_spec_timestamp ("reserve_expiration",
+ &rsc.desired_expiration),
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rsc.reserve_sig),
+ GNUNET_JSON_spec_uint32 ("purse_limit",
+ &rsc.purse_limit),
+ GNUNET_JSON_spec_array_const ("payments",
+ &payments),
+ TALER_JSON_spec_amount ("reserve_payment",
+ TEH_currency,
+ &rsc.reserve_payment),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rsc.reserve_pub = reserve_pub;
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_json_data (rc->connection,
+ root,
+ spec);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ return MHD_YES; /* failure */
+ }
+ }
+
+ {
+ struct GNUNET_TIME_Timestamp now;
+
+ now = GNUNET_TIME_timestamp_get ();
+ if (! GNUNET_TIME_absolute_approx_eq (now.abs_time,
+ rsc.timestamp.abs_time,
+ TIMESTAMP_TOLERANCE))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_CLOCK_SKEW,
+ NULL);
+ }
+ }
+
+ rsc.payments_len = json_array_size (payments);
+ rsc.payments = GNUNET_new_array (rsc.payments_len,
+ struct TEH_PurseDepositedCoin);
+ rsc.total = rsc.reserve_payment;
+ for (unsigned int i = 0; i<rsc.payments_len; i++)
+ {
+ struct TEH_PurseDepositedCoin *coin = &rsc.payments[i];
+ enum GNUNET_GenericReturnValue res;
+
+ res = TEH_common_purse_deposit_parse_coin (
+ rc->connection,
+ coin,
+ json_array_get (payments,
+ i));
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_break (0);
+ cleanup_rsc (&rsc);
+ return MHD_NO; /* hard failure */
+ }
+ if (GNUNET_NO == res)
+ {
+ GNUNET_break_op (0);
+ cleanup_rsc (&rsc);
+ return MHD_YES; /* failure */
+ }
+ if (0 >
+ TALER_amount_add (&rsc.total,
+ &rsc.total,
+ &coin->amount_minus_fee))
+ {
+ GNUNET_break (0);
+ cleanup_rsc (&rsc);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_FAILED_COMPUTE_AMOUNT,
+ NULL);
+ }
+ }
+
+ {
+ struct TEH_KeyStateHandle *keys;
+
+ keys = TEH_keys_get_state ();
+ if (NULL == keys)
+ {
+ GNUNET_break (0);
+ cleanup_rsc (&rsc);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
+ NULL);
+ }
+ rsc.gf = TEH_keys_global_fee_by_time (keys,
+ rsc.timestamp);
+ }
+ if (NULL == rsc.gf)
+ {
+ GNUNET_break (0);
+ cleanup_rsc (&rsc);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
+ NULL);
+ }
+
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_open_verify (&rsc.reserve_payment,
+ rsc.timestamp,
+ rsc.desired_expiration,
+ rsc.purse_limit,
+ reserve_pub,
+ &rsc.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ cleanup_rsc (&rsc);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_RESERVES_OPEN_BAD_SIGNATURE,
+ NULL);
+ }
+
+ {
+ MHD_RESULT mhd_ret;
+
+ if (GNUNET_OK !=
+ TEH_DB_run_transaction (rc->connection,
+ "reserve open",
+ TEH_MT_REQUEST_OTHER,
+ &mhd_ret,
+ &reserve_open_transaction,
+ &rsc))
+ {
+ cleanup_rsc (&rsc);
+ return mhd_ret;
+ }
+ }
+
+ {
+ MHD_RESULT mhd_ret;
+
+ mhd_ret = reply_reserve_open_success (rc->connection,
+ &rsc);
+ cleanup_rsc (&rsc);
+ return mhd_ret;
+ }
+}
+
+
+/* end of taler-exchange-httpd_reserves_open.c */
diff --git a/src/exchange/taler-exchange-httpd_reserves_open.h b/src/exchange/taler-exchange-httpd_reserves_open.h
new file mode 100644
index 000000000..e28c22c0b
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_reserves_open.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_reserves_open.h
+ * @brief Handle /reserves/$RESERVE_PUB/open requests
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_RESERVES_OPEN_H
+#define TALER_EXCHANGE_HTTPD_RESERVES_OPEN_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Handle a POST "/reserves/$RID/open" request.
+ *
+ * @param rc request context
+ * @param reserve_pub public key of the reserve
+ * @param root uploaded body from the client
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_handler_reserves_open (struct TEH_RequestContext *rc,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *root);
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_reserves_purse.c b/src/exchange/taler-exchange-httpd_reserves_purse.c
index fcf688d42..5e06db206 100644
--- a/src/exchange/taler-exchange-httpd_reserves_purse.c
+++ b/src/exchange/taler-exchange-httpd_reserves_purse.c
@@ -27,6 +27,7 @@
#include <microhttpd.h>
#include <pthread.h>
#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_reserves_purse.h"
#include "taler-exchange-httpd_responses.h"
@@ -56,11 +57,6 @@ struct ReservePurseContext
struct TALER_ReserveSignatureP reserve_sig;
/**
- * Total amount to be put into the purse.
- */
- struct TALER_Amount amount;
-
- /**
* Purse fee the client is willing to pay.
*/
struct TALER_Amount purse_fee;
@@ -71,11 +67,6 @@ struct ReservePurseContext
struct TALER_Amount deposit_total;
/**
- * When should the purse expire.
- */
- struct GNUNET_TIME_Timestamp purse_expiration;
-
- /**
* Merge time.
*/
struct GNUNET_TIME_Timestamp merge_timestamp;
@@ -101,19 +92,24 @@ struct ReservePurseContext
struct TALER_PurseMergeSignatureP merge_sig;
/**
- * Public key of the purse we are creating.
+ * Signature of the client affiming this request.
+ */
+ struct TALER_PurseContractSignatureP purse_sig;
+
+ /**
+ * Fundamental details about the purse.
*/
- struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TEH_PurseDetails pd;
/**
- * Signature of the client affiming this request.
+ * Hash of the @e payto_uri.
*/
- struct TALER_PurseContractSignatureP purse_sig;
+ struct TALER_PaytoHashP h_payto;
/**
- * Hash of the contract terms of the purse.
+ * KYC status of the operation.
*/
- struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_EXCHANGEDB_KycStatus kyc;
/**
* Minimum age for deposits into this purse.
@@ -134,49 +130,42 @@ struct ReservePurseContext
/**
- * Send confirmation of purse creation success to client.
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Called within a database transaction, so must
+ * not start a new one.
*
- * @param connection connection to the client
- * @param rpc details about the request that succeeded
- * @return MHD result code
+ * @param cls a `struct ReservePurseContext`
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
*/
-static MHD_RESULT
-reply_purse_success (struct MHD_Connection *connection,
- const struct ReservePurseContext *rpc)
+static void
+amount_iterator (void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls)
{
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
- enum TALER_ErrorCode ec;
-
- if (TALER_EC_NONE !=
- (ec = TALER_exchange_online_purse_created_sign (
- &TEH_keys_exchange_sign_,
- rpc->exchange_timestamp,
- rpc->purse_expiration,
- &rpc->amount,
- &rpc->deposit_total,
- &rpc->purse_pub,
- &rpc->h_contract_terms,
- &pub,
- &sig)))
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_ec (connection,
- ec,
- NULL);
- }
- // FIXME: share logic with /purses/$PID/create API!
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_amount ("total_deposited",
- &rpc->deposit_total),
- GNUNET_JSON_pack_timestamp ("exchange_timestamp",
- rpc->exchange_timestamp),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &sig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &pub));
+ struct ReservePurseContext *rpc = cls;
+ enum GNUNET_DB_QueryStatus qs;
+
+ cb (cb_cls,
+ &rpc->deposit_total,
+ GNUNET_TIME_absolute_get ());
+ qs = TEH_plugin->select_merge_amounts_for_kyc_check (
+ TEH_plugin->cls,
+ &rpc->h_payto,
+ limit,
+ cb,
+ cb_cls);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got %d additional transactions for this merge and limit %llu\n",
+ qs,
+ (unsigned long long) limit.abs_value_us);
+ GNUNET_break (qs >= 0);
}
@@ -200,6 +189,50 @@ purse_transaction (void *cls,
{
struct ReservePurseContext *rpc = cls;
enum GNUNET_DB_QueryStatus qs;
+ char *required;
+
+ qs = TALER_KYCLOGIC_kyc_test_required (
+ TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE,
+ &rpc->h_payto,
+ TEH_plugin->select_satisfied_kyc_processes,
+ TEH_plugin->cls,
+ &amount_iterator,
+ rpc,
+ &required);
+ if (qs < 0)
+ {
+ if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+ return qs;
+ GNUNET_break (0);
+ *mhd_ret =
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "kyc_test_required");
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (NULL != required)
+ {
+ rpc->kyc.ok = false;
+ qs = TEH_plugin->insert_kyc_requirement_for_account (
+ TEH_plugin->cls,
+ required,
+ &rpc->h_payto,
+ rpc->reserve_pub,
+ &rpc->kyc.requirement_row);
+ GNUNET_free (required);
+ if (GNUNET_DB_STATUS_HARD_ERROR == qs)
+ {
+ GNUNET_break (0);
+ *mhd_ret
+ = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_DB_STORE_FAILED,
+ "insert_kyc_requirement_for_account");
+ }
+ return qs;
+ }
+ rpc->kyc.ok = true;
{
bool in_conflict = true;
@@ -207,22 +240,21 @@ purse_transaction (void *cls,
/* 1) store purse */
qs = TEH_plugin->insert_purse_request (
TEH_plugin->cls,
- &rpc->purse_pub,
+ &rpc->pd.purse_pub,
&rpc->merge_pub,
- rpc->purse_expiration,
- &rpc->h_contract_terms,
+ rpc->pd.purse_expiration,
+ &rpc->pd.h_contract_terms,
rpc->min_age,
rpc->flags,
&rpc->purse_fee,
- &rpc->amount,
+ &rpc->pd.target_amount,
&rpc->purse_sig,
&in_conflict);
if (qs < 0)
{
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
return qs;
- TALER_LOG_WARNING (
- "Failed to store purse purse information in database\n");
+ GNUNET_break (0);
*mhd_ret =
TALER_MHD_reply_with_error (connection,
MHD_HTTP_INTERNAL_SERVER_ERROR,
@@ -243,9 +275,9 @@ purse_transaction (void *cls,
uint32_t min_age;
TEH_plugin->rollback (TEH_plugin->cls);
- qs = TEH_plugin->select_purse_request (
+ qs = TEH_plugin->get_purse_request (
TEH_plugin->cls,
- &rpc->purse_pub,
+ &rpc->pd.purse_pub,
&merge_pub,
&purse_expiration,
&h_contract_terms,
@@ -292,14 +324,13 @@ purse_transaction (void *cls,
bool in_conflict = true;
bool insufficient_funds = true;
bool no_reserve = true;
- bool no_kyc = true;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Creating purse with flags %d\n",
rpc->flags);
qs = TEH_plugin->do_reserve_purse (
TEH_plugin->cls,
- &rpc->purse_pub,
+ &rpc->pd.purse_pub,
&rpc->merge_sig,
rpc->merge_timestamp,
&rpc->reserve_sig,
@@ -308,10 +339,8 @@ purse_transaction (void *cls,
? NULL
: &rpc->gf->fees.purse,
rpc->reserve_pub,
- TEH_KYC_NONE != TEH_kyc_config.mode,
&in_conflict,
&no_reserve,
- &no_kyc,
&insufficient_funds);
if (qs < 0)
{
@@ -334,6 +363,7 @@ purse_transaction (void *cls,
struct GNUNET_TIME_Timestamp merge_timestamp;
char *partner_url;
struct TALER_ReservePublicKeyP reserve_pub;
+ bool refunded;
TEH_plugin->rollback (TEH_plugin->cls);
qs = TEH_plugin->select_purse_merge (
@@ -342,7 +372,8 @@ purse_transaction (void *cls,
&merge_sig,
&merge_timestamp,
&partner_url,
- &reserve_pub);
+ &reserve_pub,
+ &refunded);
if (qs <= 0)
{
GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR != qs);
@@ -355,6 +386,18 @@ purse_transaction (void *cls,
"select purse merge");
return GNUNET_DB_STATUS_HARD_ERROR;
}
+ if (refunded)
+ {
+ /* This is a bit of a strange case ... */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Purse was already refunded\n");
+ *mhd_ret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_GONE,
+ TALER_EC_EXCHANGE_GENERIC_PURSE_EXPIRED,
+ NULL);
+ GNUNET_free (partner_url);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
*mhd_ret
= TALER_MHD_REPLY_JSON_PACK (
connection,
@@ -374,7 +417,10 @@ purse_transaction (void *cls,
GNUNET_free (partner_url);
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if (no_reserve)
+ if ( (no_reserve) &&
+ ( (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
+ == rpc->flags) ||
+ (! TALER_amount_is_zero (&rpc->gf->fees.purse)) ) )
{
*mhd_ret
= TALER_MHD_REPLY_JSON_PACK (
@@ -384,17 +430,6 @@ purse_transaction (void *cls,
TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN));
return GNUNET_DB_STATUS_HARD_ERROR;
}
- if ( (no_kyc) &&
- (TEH_KYC_NONE != TEH_kyc_config.mode) )
- {
- *mhd_ret
- = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- TALER_JSON_pack_ec (
- TALER_EC_EXCHANGE_GENERIC_KYC_REQUIRED));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
if (insufficient_funds)
{
*mhd_ret
@@ -412,7 +447,7 @@ purse_transaction (void *cls,
bool in_conflict = true;
qs = TEH_plugin->insert_contract (TEH_plugin->cls,
- &rpc->purse_pub,
+ &rpc->pd.purse_pub,
&rpc->econtract,
&in_conflict);
if (qs < 0)
@@ -433,7 +468,7 @@ purse_transaction (void *cls,
qs = TEH_plugin->select_contract_by_purse (
TEH_plugin->cls,
- &rpc->purse_pub,
+ &rpc->pd.purse_pub,
&econtract);
if (qs <= 0)
{
@@ -486,7 +521,7 @@ TEH_handler_reserves_purse (
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount ("purse_value",
TEH_currency,
- &rpc.amount),
+ &rpc.pd.target_amount),
GNUNET_JSON_spec_uint32 ("min_age",
&rpc.min_age),
GNUNET_JSON_spec_mark_optional (
@@ -505,15 +540,15 @@ TEH_handler_reserves_purse (
GNUNET_JSON_spec_fixed_auto ("reserve_sig",
&rpc.reserve_sig),
GNUNET_JSON_spec_fixed_auto ("purse_pub",
- &rpc.purse_pub),
+ &rpc.pd.purse_pub),
GNUNET_JSON_spec_fixed_auto ("purse_sig",
&rpc.purse_sig),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &rpc.h_contract_terms),
+ &rpc.pd.h_contract_terms),
GNUNET_JSON_spec_timestamp ("merge_timestamp",
&rpc.merge_timestamp),
GNUNET_JSON_spec_timestamp ("purse_expiration",
- &rpc.purse_expiration),
+ &rpc.pd.purse_expiration),
GNUNET_JSON_spec_end ()
};
@@ -534,10 +569,39 @@ TEH_handler_reserves_purse (
return MHD_YES; /* failure */
}
}
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (TEH_base_url,
+ reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &rpc.h_payto);
+ TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
+ if (GNUNET_OK !=
+ TALER_wallet_purse_merge_verify (payto_uri,
+ rpc.merge_timestamp,
+ &rpc.pd.purse_pub,
+ &rpc.merge_pub,
+ &rpc.merge_sig))
+ {
+ MHD_RESULT ret;
+
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (spec);
+ ret = TALER_MHD_reply_with_error (
+ connection,
+ MHD_HTTP_FORBIDDEN,
+ TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID,
+ payto_uri);
+ GNUNET_free (payto_uri);
+ return ret;
+ }
+ GNUNET_free (payto_uri);
+ }
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (TEH_currency,
&rpc.deposit_total));
- if (GNUNET_TIME_timestamp_cmp (rpc.purse_expiration,
+ if (GNUNET_TIME_timestamp_cmp (rpc.pd.purse_expiration,
<,
rpc.exchange_timestamp))
{
@@ -548,7 +612,7 @@ TEH_handler_reserves_purse (
TALER_EC_EXCHANGE_RESERVES_PURSE_EXPIRATION_BEFORE_NOW,
NULL);
}
- if (GNUNET_TIME_absolute_is_never (rpc.purse_expiration.abs_time))
+ if (GNUNET_TIME_absolute_is_never (rpc.pd.purse_expiration.abs_time))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
@@ -586,8 +650,9 @@ TEH_handler_reserves_purse (
if (no_purse_fee)
{
rpc.flags = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
- TALER_amount_set_zero (TEH_currency,
- &rpc.purse_fee);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (TEH_currency,
+ &rpc.purse_fee));
}
else
{
@@ -607,12 +672,12 @@ TEH_handler_reserves_purse (
}
TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
if (GNUNET_OK !=
- TALER_wallet_purse_create_verify (rpc.purse_expiration,
- &rpc.h_contract_terms,
+ TALER_wallet_purse_create_verify (rpc.pd.purse_expiration,
+ &rpc.pd.h_contract_terms,
&rpc.merge_pub,
rpc.min_age,
- &rpc.amount,
- &rpc.purse_pub,
+ &rpc.pd.target_amount,
+ &rpc.pd.purse_pub,
&rpc.purse_sig))
{
GNUNET_break_op (0);
@@ -624,26 +689,11 @@ TEH_handler_reserves_purse (
NULL);
}
if (GNUNET_OK !=
- TALER_wallet_purse_merge_verify (TEH_base_url,
- rpc.merge_timestamp,
- &rpc.purse_pub,
- &rpc.merge_pub,
- &rpc.merge_sig))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID,
- NULL);
- }
- if (GNUNET_OK !=
TALER_wallet_account_merge_verify (rpc.merge_timestamp,
- &rpc.purse_pub,
- rpc.purse_expiration,
- &rpc.h_contract_terms,
- &rpc.amount,
+ &rpc.pd.purse_pub,
+ rpc.pd.purse_expiration,
+ &rpc.pd.h_contract_terms,
+ &rpc.pd.target_amount,
&rpc.purse_fee,
rpc.min_age,
rpc.flags,
@@ -655,7 +705,7 @@ TEH_handler_reserves_purse (
return TALER_MHD_reply_with_error (
connection,
MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_RESERVES_PURSE_MERGE_SIGNATURE_INVALID,
+ TALER_EC_EXCHANGE_RESERVES_RESERVE_MERGE_SIGNATURE_INVALID,
NULL);
}
if ( (! rpc.no_econtract) &&
@@ -663,7 +713,7 @@ TEH_handler_reserves_purse (
TALER_wallet_econtract_upload_verify (rpc.econtract.econtract,
rpc.econtract.econtract_size,
&rpc.econtract.contract_pub,
- &rpc.purse_pub,
+ &rpc.pd.purse_pub,
&rpc.econtract.econtract_sig)) )
{
TALER_LOG_WARNING ("Invalid signature on /reserves/$PID/purse request\n");
@@ -703,12 +753,18 @@ TEH_handler_reserves_purse (
}
}
+ if (! rpc.kyc.ok)
+ return TEH_RESPONSE_reply_kyc_required (connection,
+ &rpc.h_payto,
+ &rpc.kyc);
/* generate regular response */
{
MHD_RESULT res;
- res = reply_purse_success (connection,
- &rpc);
+ res = TEH_RESPONSE_reply_purse_created (connection,
+ rpc.exchange_timestamp,
+ &rpc.deposit_total,
+ &rpc.pd);
GNUNET_JSON_parse_free (spec);
return res;
}
diff --git a/src/exchange/taler-exchange-httpd_reserves_status.c b/src/exchange/taler-exchange-httpd_reserves_status.c
deleted file mode 100644
index 5b7becb94..000000000
--- a/src/exchange/taler-exchange-httpd_reserves_status.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_reserves_status.c
- * @brief Handle /reserves/$RESERVE_PUB STATUS requests
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <jansson.h>
-#include "taler_mhd_lib.h"
-#include "taler_json_lib.h"
-#include "taler_dbevents.h"
-#include "taler-exchange-httpd_keys.h"
-#include "taler-exchange-httpd_reserves_status.h"
-#include "taler-exchange-httpd_responses.h"
-
-/**
- * How far do we allow a client's time to be off when
- * checking the request timestamp?
- */
-#define TIMESTAMP_TOLERANCE \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
-
-
-/**
- * Closure for #reserve_status_transaction.
- */
-struct ReserveStatusContext
-{
- /**
- * Public key of the reserve the inquiry is about.
- */
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- /**
- * History of the reserve, set in the callback.
- */
- struct TALER_EXCHANGEDB_ReserveHistory *rh;
-
- /**
- * Current KYC status.
- */
- struct TALER_EXCHANGEDB_KycStatus kyc;
-
- /**
- * Current reserve balance.
- */
- struct TALER_Amount balance;
-};
-
-
-/**
- * Send reserve status to client.
- *
- * @param connection connection to the client
- * @param rhc reserve history to return
- * @return MHD result code
- */
-static MHD_RESULT
-reply_reserve_status_success (struct MHD_Connection *connection,
- const struct ReserveStatusContext *rhc)
-{
- const struct TALER_EXCHANGEDB_ReserveHistory *rh = rhc->rh;
- json_t *json_history;
-
- json_history = TEH_RESPONSE_compile_reserve_history (rh);
- if (NULL == json_history)
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- NULL);
- return TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_amount ("balance",
- &rhc->balance),
- GNUNET_JSON_pack_bool ("kyc_passed",
- rhc->kyc.ok),
- GNUNET_JSON_pack_array_steal ("history",
- json_history));
-}
-
-
-/**
- * Function implementing /reserves/ STATUS transaction.
- * Execute a /reserves/ STATUS. Given the public key of a reserve,
- * return the associated transaction history. Runs the
- * transaction logic; IF it returns a non-error code, the transaction
- * logic MUST NOT queue a MHD response. IF it returns an hard error,
- * the transaction logic MUST queue a MHD response and set @a mhd_ret.
- * IF it returns the soft error code, the function MAY be called again
- * to retry and MUST not queue a MHD response.
- *
- * @param cls a `struct ReserveStatusContext *`
- * @param connection MHD request which triggered the transaction
- * @param[out] mhd_ret set to MHD response status for @a connection,
- * if transaction failed (!); unused
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-reserve_status_transaction (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
-{
- struct ReserveStatusContext *rsc = cls;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TEH_plugin->inselect_wallet_kyc_status (TEH_plugin->cls,
- rsc->reserve_pub,
- &rsc->kyc);
- if (qs < 0)
- {
- if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
- return qs;
- GNUNET_break (0);
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "inselect_wallet_status");
- return qs;
- }
- qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
- rsc->reserve_pub,
- &rsc->balance,
- &rsc->rh);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- {
- GNUNET_break (0);
- *mhd_ret
- = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_reserve_status");
- }
- return qs;
-}
-
-
-MHD_RESULT
-TEH_handler_reserves_status (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root)
-{
- struct ReserveStatusContext rsc;
- MHD_RESULT mhd_ret;
- struct GNUNET_TIME_Timestamp timestamp;
- struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("request_timestamp",
- &timestamp),
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &reserve_sig),
- GNUNET_JSON_spec_end ()
- };
- struct GNUNET_TIME_Timestamp now;
-
- rsc.reserve_pub = reserve_pub;
- {
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (rc->connection,
- root,
- spec);
- if (GNUNET_SYSERR == res)
- {
- GNUNET_break (0);
- return MHD_NO; /* hard failure */
- }
- if (GNUNET_NO == res)
- {
- GNUNET_break_op (0);
- return MHD_YES; /* failure */
- }
- }
- now = GNUNET_TIME_timestamp_get ();
- if (! GNUNET_TIME_absolute_approx_eq (now.abs_time,
- timestamp.abs_time,
- TIMESTAMP_TOLERANCE))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_CLOCK_SKEW,
- NULL);
- }
- if (GNUNET_OK !=
- TALER_wallet_reserve_status_verify (timestamp,
- reserve_pub,
- &reserve_sig))
- {
- GNUNET_break_op (0);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_RESERVES_STATUS_BAD_SIGNATURE,
- NULL);
- }
- rsc.rh = NULL;
- if (GNUNET_OK !=
- TEH_DB_run_transaction (rc->connection,
- "get reserve status",
- TEH_MT_REQUEST_OTHER,
- &mhd_ret,
- &reserve_status_transaction,
- &rsc))
- {
- return mhd_ret;
- }
- if (NULL == rsc.rh)
- {
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_RESERVES_STATUS_UNKNOWN,
- NULL);
- }
- mhd_ret = reply_reserve_status_success (rc->connection,
- &rsc);
- TEH_plugin->free_reserve_history (TEH_plugin->cls,
- rsc.rh);
- return mhd_ret;
-}
-
-
-/* end of taler-exchange-httpd_reserves_status.c */
diff --git a/src/exchange/taler-exchange-httpd_responses.c b/src/exchange/taler-exchange-httpd_responses.c
index 92c585b4d..8993ea50f 100644
--- a/src/exchange/taler-exchange-httpd_responses.c
+++ b/src/exchange/taler-exchange-httpd_responses.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -23,413 +23,17 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include <gnunet/gnunet_json_lib.h>
+#include <microhttpd.h>
#include <zlib.h>
#include "taler-exchange-httpd_responses.h"
+#include "taler_exchangedb_plugin.h"
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler-exchange-httpd_keys.h"
-/**
- * Compile the transaction history of a coin into a JSON object.
- *
- * @param coin_pub public key of the coin
- * @param tl transaction history to JSON-ify
- * @return json representation of the @a rh, NULL on error
- */
-json_t *
-TEH_RESPONSE_compile_transaction_history (
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_EXCHANGEDB_TransactionList *tl)
-{
- json_t *history;
-
- history = json_array ();
- if (NULL == history)
- {
- GNUNET_break (0); /* out of memory!? */
- return NULL;
- }
- for (const struct TALER_EXCHANGEDB_TransactionList *pos = tl;
- NULL != pos;
- pos = pos->next)
- {
- switch (pos->type)
- {
- case TALER_EXCHANGEDB_TT_DEPOSIT:
- {
- const struct TALER_EXCHANGEDB_DepositListEntry *deposit =
- pos->details.deposit;
- struct TALER_MerchantWireHashP h_wire;
-
- TALER_merchant_wire_signature_hash (deposit->receiver_wire_account,
- &deposit->wire_salt,
- &h_wire);
-#if ENABLE_SANITY_CHECKS
- /* internal sanity check before we hand out a bogus sig... */
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_wallet_deposit_verify (
- &deposit->amount_with_fee,
- &deposit->deposit_fee,
- &h_wire,
- &deposit->h_contract_terms,
- &deposit->h_age_commitment,
- NULL /* h_extensions! */,
- &deposit->h_denom_pub,
- deposit->timestamp,
- &deposit->merchant_pub,
- deposit->refund_deadline,
- coin_pub,
- &deposit->csig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
-#endif
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "DEPOSIT"),
- TALER_JSON_pack_amount ("amount",
- &deposit->amount_with_fee),
- TALER_JSON_pack_amount ("deposit_fee",
- &deposit->deposit_fee),
- GNUNET_JSON_pack_timestamp ("timestamp",
- deposit->timestamp),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_timestamp ("refund_deadline",
- deposit->refund_deadline)),
- GNUNET_JSON_pack_data_auto ("merchant_pub",
- &deposit->merchant_pub),
- GNUNET_JSON_pack_data_auto ("h_contract_terms",
- &deposit->h_contract_terms),
- GNUNET_JSON_pack_data_auto ("h_wire",
- &h_wire),
- GNUNET_JSON_pack_allow_null (
- deposit->no_age_commitment ?
- GNUNET_JSON_pack_string (
- "h_age_commitment", NULL) :
- GNUNET_JSON_pack_data_auto ("h_age_commitment",
- &deposit->h_age_commitment)),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &deposit->csig))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- break;
- }
- case TALER_EXCHANGEDB_TT_MELT:
- {
- const struct TALER_EXCHANGEDB_MeltListEntry *melt =
- pos->details.melt;
- const struct TALER_AgeCommitmentHash *phac = NULL;
-
-#if ENABLE_SANITY_CHECKS
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_wallet_melt_verify (
- &melt->amount_with_fee,
- &melt->melt_fee,
- &melt->rc,
- &melt->h_denom_pub,
- &melt->h_age_commitment,
- coin_pub,
- &melt->coin_sig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
-#endif
-
- /* Age restriction is optional. We communicate a NULL value to
- * JSON_PACK below */
- if (! melt->no_age_commitment)
- phac = &melt->h_age_commitment;
-
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "MELT"),
- TALER_JSON_pack_amount ("amount",
- &melt->amount_with_fee),
- TALER_JSON_pack_amount ("melt_fee",
- &melt->melt_fee),
- GNUNET_JSON_pack_data_auto ("rc",
- &melt->rc),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_data_auto ("h_age_commitment",
- phac)),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &melt->coin_sig))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_TT_REFUND:
- {
- const struct TALER_EXCHANGEDB_RefundListEntry *refund =
- pos->details.refund;
- struct TALER_Amount value;
-
-#if ENABLE_SANITY_CHECKS
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_merchant_refund_verify (
- coin_pub,
- &refund->h_contract_terms,
- refund->rtransaction_id,
- &refund->refund_amount,
- &refund->merchant_pub,
- &refund->merchant_sig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
-#endif
- if (0 >
- TALER_amount_subtract (&value,
- &refund->refund_amount,
- &refund->refund_fee))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "REFUND"),
- TALER_JSON_pack_amount ("amount",
- &value),
- TALER_JSON_pack_amount ("refund_fee",
- &refund->refund_fee),
- GNUNET_JSON_pack_data_auto ("h_contract_terms",
- &refund->h_contract_terms),
- GNUNET_JSON_pack_data_auto ("merchant_pub",
- &refund->merchant_pub),
- GNUNET_JSON_pack_uint64 ("rtransaction_id",
- refund->rtransaction_id),
- GNUNET_JSON_pack_data_auto ("merchant_sig",
- &refund->merchant_sig))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP:
- {
- struct TALER_EXCHANGEDB_RecoupRefreshListEntry *pr =
- pos->details.old_coin_recoup;
- struct TALER_ExchangePublicKeyP epub;
- struct TALER_ExchangeSignatureP esig;
-
- if (TALER_EC_NONE !=
- TALER_exchange_online_confirm_recoup_refresh_sign (
- &TEH_keys_exchange_sign_,
- pr->timestamp,
- &pr->value,
- &pr->coin.coin_pub,
- &pr->old_coin_pub,
- &epub,
- &esig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- /* NOTE: we could also provide coin_pub's coin_sig, denomination key hash and
- the denomination key's RSA signature over coin_pub, but as the
- wallet should really already have this information (and cannot
- check or do anything with it anyway if it doesn't), it seems
- strictly unnecessary. */
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "OLD-COIN-RECOUP"),
- TALER_JSON_pack_amount ("amount",
- &pr->value),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &esig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &epub),
- GNUNET_JSON_pack_data_auto ("coin_pub",
- &pr->coin.coin_pub),
- GNUNET_JSON_pack_timestamp ("timestamp",
- pr->timestamp))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- break;
- }
- case TALER_EXCHANGEDB_TT_RECOUP:
- {
- const struct TALER_EXCHANGEDB_RecoupListEntry *recoup =
- pos->details.recoup;
- struct TALER_ExchangePublicKeyP epub;
- struct TALER_ExchangeSignatureP esig;
-
- if (TALER_EC_NONE !=
- TALER_exchange_online_confirm_recoup_sign (
- &TEH_keys_exchange_sign_,
- recoup->timestamp,
- &recoup->value,
- coin_pub,
- &recoup->reserve_pub,
- &epub,
- &esig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "RECOUP"),
- TALER_JSON_pack_amount ("amount",
- &recoup->value),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &esig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &epub),
- GNUNET_JSON_pack_data_auto ("reserve_pub",
- &recoup->reserve_pub),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &recoup->coin_sig),
- GNUNET_JSON_pack_data_auto ("coin_blind",
- &recoup->coin_blind),
- GNUNET_JSON_pack_data_auto ("reserve_pub",
- &recoup->reserve_pub),
- GNUNET_JSON_pack_timestamp ("timestamp",
- recoup->timestamp))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_TT_RECOUP_REFRESH:
- {
- struct TALER_EXCHANGEDB_RecoupRefreshListEntry *pr =
- pos->details.recoup_refresh;
- struct TALER_ExchangePublicKeyP epub;
- struct TALER_ExchangeSignatureP esig;
-
- if (TALER_EC_NONE !=
- TALER_exchange_online_confirm_recoup_refresh_sign (
- &TEH_keys_exchange_sign_,
- pr->timestamp,
- &pr->value,
- coin_pub,
- &pr->old_coin_pub,
- &epub,
- &esig))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- /* NOTE: we could also provide coin_pub's coin_sig, denomination key
- hash and the denomination key's RSA signature over coin_pub, but as
- the wallet should really already have this information (and cannot
- check or do anything with it anyway if it doesn't), it seems
- strictly unnecessary. */
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "RECOUP-REFRESH"),
- TALER_JSON_pack_amount ("amount",
- &pr->value),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &esig),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &epub),
- GNUNET_JSON_pack_data_auto ("old_coin_pub",
- &pr->old_coin_pub),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &pr->coin_sig),
- GNUNET_JSON_pack_data_auto ("coin_blind",
- &pr->coin_blind),
- GNUNET_JSON_pack_timestamp ("timestamp",
- pr->timestamp))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- break;
- }
-
- case TALER_EXCHANGEDB_TT_PURSE_DEPOSIT:
- {
- struct TALER_EXCHANGEDB_PurseDepositListEntry *pd
- = pos->details.purse_deposit;
- const struct TALER_AgeCommitmentHash *phac = NULL;
-
- if (! pd->no_age_commitment)
- phac = &pd->h_age_commitment;
-
- if (0 !=
- json_array_append_new (
- history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "PURSE-DEPOSIT"),
- TALER_JSON_pack_amount ("amount",
- &pd->amount),
- GNUNET_JSON_pack_string ("exchange_base_url",
- NULL == pd->exchange_base_url
- ? TEH_base_url
- : pd->exchange_base_url),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_data_auto ("h_age_commitment",
- phac)),
- GNUNET_JSON_pack_data_auto ("purse_pub",
- &pd->purse_pub),
- GNUNET_JSON_pack_bool ("refunded",
- pd->refunded),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &pd->coin_sig))))
- {
- GNUNET_break (0);
- json_decref (history);
- return NULL;
- }
- break;
- }
- }
- }
- return history;
-}
-
-
MHD_RESULT
TEH_RESPONSE_reply_unknown_denom_pub_hash (
struct MHD_Connection *connection,
@@ -563,379 +167,242 @@ TEH_RESPONSE_reply_coin_insufficient_funds (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_CoinSpendPublicKeyP *coin_pub)
{
- struct TALER_EXCHANGEDB_TransactionList *tl;
- enum GNUNET_DB_QueryStatus qs;
- json_t *history;
-
- TEH_plugin->rollback (TEH_plugin->cls);
- // FIXME: maybe start read-only transaction here?
- if (GNUNET_OK !=
- TEH_plugin->start_read_committed (TEH_plugin->cls,
- "get_coin_transactions"))
- {
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_START_FAILED,
- NULL);
- }
- // FIXME: simplify, 3rd arg is always 'true' now?
- qs = TEH_plugin->get_coin_transactions (TEH_plugin->cls,
- coin_pub,
- true,
- &tl);
- TEH_plugin->rollback (TEH_plugin->cls);
- if (0 > qs)
- {
- return TALER_MHD_reply_with_error (
- connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- NULL);
- }
-
- history = TEH_RESPONSE_compile_transaction_history (coin_pub,
- tl);
- TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
- tl);
- if (NULL == history)
- {
- GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- "Failed to generated proof of insufficient funds");
- }
return TALER_MHD_REPLY_JSON_PACK (
connection,
TALER_ErrorCode_get_http_status_safe (ec),
TALER_JSON_pack_ec (ec),
GNUNET_JSON_pack_data_auto ("coin_pub",
coin_pub),
+ // FIXME - #7267: to be kept only for some of the error types!
GNUNET_JSON_pack_data_auto ("h_denom_pub",
- h_denom_pub),
- GNUNET_JSON_pack_array_steal ("history",
- history));
+ h_denom_pub));
}
-json_t *
-TEH_RESPONSE_compile_reserve_history (
- const struct TALER_EXCHANGEDB_ReserveHistory *rh)
+MHD_RESULT
+TEH_RESPONSE_reply_coin_conflicting_contract (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ const struct TALER_MerchantWireHashP *h_wire)
{
- json_t *json_history;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ TALER_ErrorCode_get_http_status_safe (ec),
+ GNUNET_JSON_pack_data_auto ("h_wire",
+ h_wire),
+ TALER_JSON_pack_ec (ec));
+}
- json_history = json_array ();
- for (const struct TALER_EXCHANGEDB_ReserveHistory *pos = rh;
- NULL != pos;
- pos = pos->next)
+
+MHD_RESULT
+TEH_RESPONSE_reply_coin_denomination_conflict (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_DenominationPublicKey *prev_denom_pub,
+ const struct TALER_DenominationSignature *prev_denom_sig)
+{
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ TALER_ErrorCode_get_http_status_safe (ec),
+ TALER_JSON_pack_ec (ec),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ coin_pub),
+ TALER_JSON_pack_denom_pub ("prev_denom_pub",
+ prev_denom_pub),
+ TALER_JSON_pack_denom_sig ("prev_denom_sig",
+ prev_denom_sig)
+ );
+
+}
+
+
+MHD_RESULT
+TEH_RESPONSE_reply_coin_age_commitment_conflict (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ enum TALER_EXCHANGEDB_CoinKnownStatus status,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_AgeCommitmentHash *h_age_commitment)
+{
+ const char *conflict_detail;
+
+ switch (status)
{
- switch (pos->type)
- {
- case TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE:
- {
- const struct TALER_EXCHANGEDB_BankTransfer *bank =
- pos->details.bank;
-
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "CREDIT"),
- GNUNET_JSON_pack_timestamp ("timestamp",
- bank->execution_date),
- GNUNET_JSON_pack_string ("sender_account_url",
- bank->sender_account_details),
- GNUNET_JSON_pack_uint64 ("wire_reference",
- bank->wire_reference),
- TALER_JSON_pack_amount ("amount",
- &bank->amount))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- break;
- }
- case TALER_EXCHANGEDB_RO_WITHDRAW_COIN:
- {
- const struct TALER_EXCHANGEDB_CollectableBlindcoin *withdraw
- = pos->details.withdraw;
-
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "WITHDRAW"),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &withdraw->reserve_sig),
- GNUNET_JSON_pack_data_auto ("h_coin_envelope",
- &withdraw->h_coin_envelope),
- GNUNET_JSON_pack_data_auto ("h_denom_pub",
- &withdraw->denom_pub_hash),
- TALER_JSON_pack_amount ("withdraw_fee",
- &withdraw->withdraw_fee),
- TALER_JSON_pack_amount ("amount",
- &withdraw->amount_with_fee))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_RO_RECOUP_COIN:
- {
- const struct TALER_EXCHANGEDB_Recoup *recoup
- = pos->details.recoup;
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
-
- if (TALER_EC_NONE !=
- TALER_exchange_online_confirm_recoup_sign (
- &TEH_keys_exchange_sign_,
- recoup->timestamp,
- &recoup->value,
- &recoup->coin.coin_pub,
- &recoup->reserve_pub,
- &pub,
- &sig))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
-
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "RECOUP"),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &pub),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &sig),
- GNUNET_JSON_pack_timestamp ("timestamp",
- recoup->timestamp),
- TALER_JSON_pack_amount ("amount",
- &recoup->value),
- GNUNET_JSON_pack_data_auto ("coin_pub",
- &recoup->coin.coin_pub))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK:
- {
- const struct TALER_EXCHANGEDB_ClosingTransfer *closing =
- pos->details.closing;
- struct TALER_ExchangePublicKeyP pub;
- struct TALER_ExchangeSignatureP sig;
-
- if (TALER_EC_NONE !=
- TALER_exchange_online_reserve_closed_sign (
- &TEH_keys_exchange_sign_,
- closing->execution_date,
- &closing->amount,
- &closing->closing_fee,
- closing->receiver_account_details,
- &closing->wtid,
- &pos->details.closing->reserve_pub,
- &pub,
- &sig))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "CLOSING"),
- GNUNET_JSON_pack_string ("receiver_account_details",
- closing->receiver_account_details),
- GNUNET_JSON_pack_data_auto ("wtid",
- &closing->wtid),
- GNUNET_JSON_pack_data_auto ("exchange_pub",
- &pub),
- GNUNET_JSON_pack_data_auto ("exchange_sig",
- &sig),
- GNUNET_JSON_pack_timestamp ("timestamp",
- closing->execution_date),
- TALER_JSON_pack_amount ("amount",
- &closing->amount),
- TALER_JSON_pack_amount ("closing_fee",
- &closing->closing_fee))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_RO_PURSE_MERGE:
- {
- const struct TALER_EXCHANGEDB_PurseMerge *merge =
- pos->details.merge;
-
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "MERGE"),
- GNUNET_JSON_pack_data_auto ("h_contract_terms",
- &merge->h_contract_terms),
- GNUNET_JSON_pack_data_auto ("merge_pub",
- &merge->merge_pub),
- GNUNET_JSON_pack_uint64 ("min_age",
- merge->min_age),
- GNUNET_JSON_pack_uint64 ("flags",
- merge->flags),
- GNUNET_JSON_pack_data_auto ("purse_pub",
- &merge->purse_pub),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &merge->reserve_sig),
- GNUNET_JSON_pack_timestamp ("merge_timestamp",
- merge->merge_timestamp),
- GNUNET_JSON_pack_timestamp ("purse_expiration",
- merge->purse_expiration),
- TALER_JSON_pack_amount ("amount",
- &merge->amount_with_fee),
- TALER_JSON_pack_amount ("purse_fee",
- &merge->purse_fee),
- GNUNET_JSON_pack_bool ("merged",
- merge->merged))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- }
- break;
- case TALER_EXCHANGEDB_RO_HISTORY_REQUEST:
- {
- const struct TALER_EXCHANGEDB_HistoryRequest *history =
- pos->details.history;
-
- if (0 !=
- json_array_append_new (
- json_history,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("type",
- "HISTORY"),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &history->reserve_sig),
- GNUNET_JSON_pack_timestamp ("request_timestamp",
- history->request_timestamp),
- TALER_JSON_pack_amount ("amount",
- &history->history_fee))))
- {
- GNUNET_break (0);
- json_decref (json_history);
- return NULL;
- }
- }
- break;
- }
+
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL:
+ conflict_detail = "expected NULL age commitment hash";
+ h_age_commitment = NULL;
+ break;
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL:
+ conflict_detail = "expected non-NULL age commitment hash";
+ break;
+ case TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS:
+ conflict_detail = "expected age commitment hash differs";
+ break;
+ default:
+ GNUNET_assert (0);
}
- return json_history;
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ TALER_ErrorCode_get_http_status_safe (ec),
+ TALER_JSON_pack_ec (ec),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ coin_pub),
+ GNUNET_JSON_pack_data_auto ("h_denom_pub",
+ h_denom_pub),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("expected_age_commitment_hash",
+ h_age_commitment)),
+ GNUNET_JSON_pack_string ("conflict_detail",
+ conflict_detail)
+ );
}
-/**
- * Send reserve history information to client with the
- * message that we have insufficient funds for the
- * requested withdraw operation.
- *
- * @param connection connection to the client
- * @param ebalance expected balance based on our database
- * @param withdraw_amount amount that the client requested to withdraw
- * @param rh reserve history to return
- * @return MHD result code
- */
-static MHD_RESULT
-reply_withdraw_insufficient_funds (
+MHD_RESULT
+TEH_RESPONSE_reply_reserve_insufficient_balance (
struct MHD_Connection *connection,
- const struct TALER_Amount *ebalance,
- const struct TALER_Amount *withdraw_amount,
- const struct TALER_EXCHANGEDB_ReserveHistory *rh)
+ enum TALER_ErrorCode ec,
+ const struct TALER_Amount *reserve_balance,
+ const struct TALER_Amount *balance_required,
+ const struct TALER_ReservePublicKeyP *reserve_pub)
{
- json_t *json_history;
-
- json_history = TEH_RESPONSE_compile_reserve_history (rh);
- if (NULL == json_history)
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_WITHDRAW_HISTORY_ERROR_INSUFFICIENT_FUNDS,
- NULL);
return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_CONFLICT,
- TALER_JSON_pack_ec (TALER_EC_EXCHANGE_WITHDRAW_INSUFFICIENT_FUNDS),
+ TALER_JSON_pack_ec (ec),
TALER_JSON_pack_amount ("balance",
- ebalance),
+ reserve_balance),
TALER_JSON_pack_amount ("requested_amount",
- withdraw_amount),
- GNUNET_JSON_pack_array_steal ("history",
- json_history));
+ balance_required));
}
MHD_RESULT
-TEH_RESPONSE_reply_reserve_insufficient_balance (
+TEH_RESPONSE_reply_reserve_age_restriction_required (
struct MHD_Connection *connection,
- const struct TALER_Amount *balance_required,
- const struct TALER_ReservePublicKeyP *reserve_pub)
+ uint16_t maximum_allowed_age)
{
- struct TALER_EXCHANGEDB_ReserveHistory *rh = NULL;
- struct TALER_Amount balance;
- enum GNUNET_DB_QueryStatus qs;
- MHD_RESULT mhd_ret;
-
- // FIXME: maybe start read-committed here?
- if (GNUNET_OK !=
- TEH_plugin->start (TEH_plugin->cls,
- "get_reserve_history on insufficient balance"))
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_CONFLICT,
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_RESERVES_AGE_RESTRICTION_REQUIRED),
+ GNUNET_JSON_pack_uint64 ("maximum_allowed_age",
+ maximum_allowed_age));
+}
+
+
+MHD_RESULT
+TEH_RESPONSE_reply_purse_created (
+ struct MHD_Connection *connection,
+ struct GNUNET_TIME_Timestamp exchange_timestamp,
+ const struct TALER_Amount *purse_balance,
+ const struct TEH_PurseDetails *pd)
+{
+ struct TALER_ExchangePublicKeyP pub;
+ struct TALER_ExchangeSignatureP sig;
+ enum TALER_ErrorCode ec;
+
+ if (TALER_EC_NONE !=
+ (ec = TALER_exchange_online_purse_created_sign (
+ &TEH_keys_exchange_sign_,
+ exchange_timestamp,
+ pd->purse_expiration,
+ &pd->target_amount,
+ purse_balance,
+ &pd->purse_pub,
+ &pd->h_contract_terms,
+ &pub,
+ &sig)))
{
GNUNET_break (0);
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_START_FAILED,
- NULL);
+ return TALER_MHD_reply_with_ec (connection,
+ ec,
+ NULL);
}
- /* The reserve does not have the required amount (actual
- * amount + withdraw fee) */
- qs = TEH_plugin->get_reserve_history (TEH_plugin->cls,
- reserve_pub,
- &balance,
- &rh);
- TEH_plugin->rollback (TEH_plugin->cls);
- if ( (qs < 0) ||
- (NULL == rh) )
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ TALER_JSON_pack_amount ("total_deposited",
+ purse_balance),
+ GNUNET_JSON_pack_timestamp ("exchange_timestamp",
+ exchange_timestamp),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &pub));
+}
+
+
+MHD_RESULT
+TEH_RESPONSE_reply_kyc_required (struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_EXCHANGEDB_KycStatus *kyc)
+{
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ TALER_JSON_pack_ec (TALER_EC_EXCHANGE_GENERIC_KYC_REQUIRED),
+ GNUNET_JSON_pack_data_auto ("h_payto",
+ h_payto),
+ GNUNET_JSON_pack_uint64 ("requirement_row",
+ kyc->requirement_row));
+}
+
+
+MHD_RESULT
+TEH_RESPONSE_reply_aml_blocked (struct MHD_Connection *connection,
+ enum TALER_AmlDecisionState status)
+{
+ enum TALER_ErrorCode ec = TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
+
+ switch (status)
{
- return TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "reserve history");
+ case TALER_AML_NORMAL:
+ GNUNET_break (0);
+ return MHD_NO;
+ case TALER_AML_PENDING:
+ ec = TALER_EC_EXCHANGE_GENERIC_AML_PENDING;
+ break;
+ case TALER_AML_FROZEN:
+ ec = TALER_EC_EXCHANGE_GENERIC_AML_FROZEN;
+ break;
}
- mhd_ret = reply_withdraw_insufficient_funds (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
- &balance,
- balance_required,
- rh);
- TEH_plugin->free_reserve_history (TEH_plugin->cls,
- rh);
- return mhd_ret;
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ TALER_JSON_pack_ec (ec));
+}
+
+
+MHD_RESULT
+TEH_RESPONSE_reply_not_modified (
+ struct MHD_Connection *connection,
+ const char *etags,
+ TEH_RESPONSE_SetHeaders cb,
+ void *cb_cls)
+{
+ MHD_RESULT ret;
+ struct MHD_Response *resp;
+
+ resp = MHD_create_response_from_buffer (0,
+ NULL,
+ MHD_RESPMEM_PERSISTENT);
+ cb (cb_cls,
+ resp);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_ETAG,
+ etags));
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_NOT_MODIFIED,
+ resp);
+ GNUNET_break (MHD_YES == ret);
+ MHD_destroy_response (resp);
+ return ret;
}
diff --git a/src/exchange/taler-exchange-httpd_responses.h b/src/exchange/taler-exchange-httpd_responses.h
index dde4c2c87..24b24621f 100644
--- a/src/exchange/taler-exchange-httpd_responses.h
+++ b/src/exchange/taler-exchange-httpd_responses.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2019 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -24,24 +24,14 @@
*/
#ifndef TALER_EXCHANGE_HTTPD_RESPONSES_H
#define TALER_EXCHANGE_HTTPD_RESPONSES_H
+
#include <gnunet/gnunet_util_lib.h>
#include <jansson.h>
#include <microhttpd.h>
#include "taler_error_codes.h"
#include "taler-exchange-httpd.h"
#include "taler-exchange-httpd_db.h"
-#include <gnunet/gnunet_mhd_compat.h>
-
-
-/**
- * Compile the history of a reserve into a JSON object.
- *
- * @param rh reserve history to JSON-ify
- * @return json representation of the @a rh, NULL on error
- */
-json_t *
-TEH_RESPONSE_compile_reserve_history (
- const struct TALER_EXCHANGEDB_ReserveHistory *rh);
+#include "taler_exchangedb_plugin.h"
/**
@@ -63,6 +53,8 @@ TEH_RESPONSE_reply_unknown_denom_pub_hash (
* an insufficient balance for the given operation.
*
* @param connection connection to the client
+ * @param ec specific error code to return with the reserve history
+ * @param reserve_balance balance remaining in the reserve
* @param balance_required the balance required for the operation
* @param reserve_pub the reserve with insufficient balance
* @return MHD result code
@@ -70,9 +62,53 @@ TEH_RESPONSE_reply_unknown_denom_pub_hash (
MHD_RESULT
TEH_RESPONSE_reply_reserve_insufficient_balance (
struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ const struct TALER_Amount *reserve_balance,
const struct TALER_Amount *balance_required,
const struct TALER_ReservePublicKeyP *reserve_pub);
+/**
+ * Return error message indicating that a reserve requires age
+ * restriction to be set during withdraw, that is: the age-withdraw
+ * protocol MUST be used with commitment to an admissible age.
+ *
+ * @param connection connection to the client
+ * @param maximum_allowed_age the balance required for the operation
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_reserve_age_restriction_required (
+ struct MHD_Connection *connection,
+ uint16_t maximum_allowed_age);
+
+
+/**
+ * Send information that a KYC check must be
+ * satisfied to proceed to client.
+ *
+ * @param connection connection to the client
+ * @param h_payto account identifier to include in reply
+ * @param kyc details about the KYC requirements
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_kyc_required (struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_EXCHANGEDB_KycStatus *kyc);
+
+
+/**
+ * Send information that an AML process is blocking
+ * the operation right now.
+ *
+ * @param connection connection to the client
+ * @param status current AML status
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_aml_blocked (struct MHD_Connection *connection,
+ enum TALER_AmlDecisionState status);
+
/**
* Send assertion that the given denomination key hash
@@ -124,18 +160,140 @@ TEH_RESPONSE_reply_coin_insufficient_funds (
const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_CoinSpendPublicKeyP *coin_pub);
+/**
+ * Send proof that a request is invalid to client because of
+ * an conflict with the provided denomination (the exchange had seen
+ * this coin before, signed by a different denomination).
+ * This function will create a message with the denomination's public key
+ * that was seen before.
+ *
+ * @param connection connection to the client
+ * @param ec error code to return
+ * @param coin_pub the public key of the coin
+ * @param prev_denom_pub the denomination of the coin, as seen previously
+ * @param prev_denom_sig the signature with the denomination key over the coin
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_coin_denomination_conflict (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_DenominationPublicKey *prev_denom_pub,
+ const struct TALER_DenominationSignature *prev_denom_sig);
/**
- * Compile the transaction history of a coin into a JSON object.
+ * Send the salted hash of the merchant's bank account from conflicting
+ * contract. With this information, the merchant's private key and
+ * the hash of the contract terms, the client can retrieve more details
+ * about the conflicting deposit
*
+ * @param connection connection to the client
+ * @param ec error code to return
+ * @param h_wire the salted hash of the merchant's bank account
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_coin_conflicting_contract (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ const struct TALER_MerchantWireHashP *h_wire);
+
+/**
+ * Send proof that a request is invalid to client because of
+ * a conflicting value for the age commitment hash of a coin.
+ * This function will create a message with the conflicting
+ * hash value for the age commitment of the given coin.
+ *
+ * @param connection connection to the client
+ * @param ec error code to return
+ * @param cks specific conflict type
+ * @param h_denom_pub hash of the denomination of the coin
* @param coin_pub public key of the coin
- * @param tl transaction history to JSON-ify
- * @return json representation of the @a rh, NULL on error
+ * @param h_age_commitment hash of the age commitment as found in the database
+ * @return MHD result code
*/
-json_t *
-TEH_RESPONSE_compile_transaction_history (
+MHD_RESULT
+TEH_RESPONSE_reply_coin_age_commitment_conflict (
+ struct MHD_Connection *connection,
+ enum TALER_ErrorCode ec,
+ enum TALER_EXCHANGEDB_CoinKnownStatus cks,
+ const struct TALER_DenominationHashP *h_denom_pub,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_EXCHANGEDB_TransactionList *tl);
+ const struct TALER_AgeCommitmentHash *h_age_commitment);
+
+/**
+ * Fundamental details about a purse.
+ */
+struct TEH_PurseDetails
+{
+ /**
+ * When should the purse expire.
+ */
+ struct GNUNET_TIME_Timestamp purse_expiration;
+
+ /**
+ * Hash of the contract terms of the purse.
+ */
+ struct TALER_PrivateContractHashP h_contract_terms;
+
+ /**
+ * Public key of the purse we are creating.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Total amount to be put into the purse.
+ */
+ struct TALER_Amount target_amount;
+};
+
+
+/**
+ * Send confirmation that a purse was created with
+ * the current purse balance.
+ *
+ * @param connection connection to the client
+ * @param pd purse details
+ * @param exchange_timestamp our time for purse creation
+ * @param purse_balance current balance in the purse
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_purse_created (
+ struct MHD_Connection *connection,
+ struct GNUNET_TIME_Timestamp exchange_timestamp,
+ const struct TALER_Amount *purse_balance,
+ const struct TEH_PurseDetails *pd);
+
+
+/**
+ * Callback used to set headers in a response.
+ *
+ * @param cls closure
+ * @param[in,out] resp response to modify
+ */
+typedef void
+(*TEH_RESPONSE_SetHeaders)(void *cls,
+ struct MHD_Response *resp);
+
+
+/**
+ * Generate a HTTP "Not modified" response with the
+ * given @a etags.
+ *
+ * @param connection connection to queue response on
+ * @param etags ETag header to set
+ * @param cb callback to modify response headers
+ * @param cb_cls closure for @a cb
+ * @return MHD result code
+ */
+MHD_RESULT
+TEH_RESPONSE_reply_not_modified (
+ struct MHD_Connection *connection,
+ const char *etags,
+ TEH_RESPONSE_SetHeaders cb,
+ void *cb_cls);
#endif
diff --git a/src/exchange/taler-exchange-httpd_spa.c b/src/exchange/taler-exchange-httpd_spa.c
new file mode 100644
index 000000000..60bed3d28
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_spa.c
@@ -0,0 +1,362 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of EXCHANGEABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_spa.c
+ * @brief logic to load the single page app (/)
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_util.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_mhd_compat.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Resource from the WebUi.
+ */
+struct WebuiFile
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct WebuiFile *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct WebuiFile *prev;
+
+ /**
+ * Path this resource matches.
+ */
+ char *path;
+
+ /**
+ * SPA resource, compressed.
+ */
+ struct MHD_Response *zspa;
+
+ /**
+ * SPA resource, vanilla.
+ */
+ struct MHD_Response *spa;
+
+};
+
+
+/**
+ * Resources of the WebuUI, kept in a DLL.
+ */
+static struct WebuiFile *webui_head;
+
+/**
+ * Resources of the WebuUI, kept in a DLL.
+ */
+static struct WebuiFile *webui_tail;
+
+
+MHD_RESULT
+TEH_handler_spa (struct TEH_RequestContext *rc,
+ const char *const args[])
+{
+ struct WebuiFile *w = NULL;
+ const char *infix = args[0];
+
+ if ( (NULL == infix) ||
+ (0 == strcmp (infix,
+ "")) )
+ infix = "index.html";
+ for (struct WebuiFile *pos = webui_head;
+ NULL != pos;
+ pos = pos->next)
+ if (0 == strcmp (infix,
+ pos->path))
+ {
+ w = pos;
+ break;
+ }
+ if (NULL == w)
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ rc->url);
+ if ( (MHD_YES ==
+ TALER_MHD_can_compress (rc->connection)) &&
+ (NULL != w->zspa) )
+ return MHD_queue_response (rc->connection,
+ MHD_HTTP_OK,
+ w->zspa);
+ return MHD_queue_response (rc->connection,
+ MHD_HTTP_OK,
+ w->spa);
+}
+
+
+/**
+ * Function called on each file to load for the WebUI.
+ *
+ * @param cls NULL
+ * @param dn name of the file to load
+ */
+static enum GNUNET_GenericReturnValue
+build_webui (void *cls,
+ const char *dn)
+{
+ static struct
+ {
+ const char *ext;
+ const char *mime;
+ } mime_map[] = {
+ {
+ .ext = "css",
+ .mime = "text/css"
+ },
+ {
+ .ext = "html",
+ .mime = "text/html"
+ },
+ {
+ .ext = "js",
+ .mime = "text/javascript"
+ },
+ {
+ .ext = "jpg",
+ .mime = "image/jpeg"
+ },
+ {
+ .ext = "jpeg",
+ .mime = "image/jpeg"
+ },
+ {
+ .ext = "png",
+ .mime = "image/png"
+ },
+ {
+ .ext = "svg",
+ .mime = "image/svg+xml"
+ },
+ {
+ .ext = NULL,
+ .mime = NULL
+ },
+ };
+ int fd;
+ struct stat sb;
+ struct MHD_Response *zspa = NULL;
+ struct MHD_Response *spa;
+ const char *ext;
+ const char *mime;
+
+ (void) cls;
+ /* finally open template */
+ fd = open (dn,
+ O_RDONLY);
+ if (-1 == fd)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ dn);
+ return GNUNET_SYSERR;
+ }
+ if (0 !=
+ fstat (fd,
+ &sb))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ dn);
+ GNUNET_break (0 == close (fd));
+ return GNUNET_SYSERR;
+ }
+
+ mime = NULL;
+ ext = strrchr (dn, '.');
+ if (NULL == ext)
+ {
+ GNUNET_break (0 == close (fd));
+ return GNUNET_OK;
+ }
+ ext++;
+ for (unsigned int i = 0; NULL != mime_map[i].ext; i++)
+ if (0 == strcasecmp (ext,
+ mime_map[i].ext))
+ {
+ mime = mime_map[i].mime;
+ break;
+ }
+
+ {
+ void *in;
+ ssize_t r;
+ size_t csize;
+
+ in = GNUNET_malloc_large (sb.st_size);
+ if (NULL == in)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "malloc");
+ GNUNET_break (0 == close (fd));
+ return GNUNET_SYSERR;
+ }
+ r = read (fd,
+ in,
+ sb.st_size);
+ if ( (-1 == r) ||
+ (sb.st_size != (size_t) r) )
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "read",
+ dn);
+ GNUNET_free (in);
+ GNUNET_break (0 == close (fd));
+ return GNUNET_SYSERR;
+ }
+ csize = (size_t) r;
+ if (MHD_YES ==
+ TALER_MHD_body_compress (&in,
+ &csize))
+ {
+ zspa = MHD_create_response_from_buffer (csize,
+ in,
+ MHD_RESPMEM_MUST_FREE);
+ if (NULL != zspa)
+ {
+ if (MHD_NO ==
+ MHD_add_response_header (zspa,
+ MHD_HTTP_HEADER_CONTENT_ENCODING,
+ "deflate"))
+ {
+ GNUNET_break (0);
+ MHD_destroy_response (zspa);
+ zspa = NULL;
+ }
+ if (NULL != mime)
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (zspa,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ mime));
+ }
+ }
+ else
+ {
+ GNUNET_free (in);
+ }
+ }
+
+ spa = MHD_create_response_from_fd (sb.st_size,
+ fd);
+ if (NULL == spa)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ dn);
+ GNUNET_break (0 == close (fd));
+ if (NULL != zspa)
+ {
+ MHD_destroy_response (zspa);
+ zspa = NULL;
+ }
+ return GNUNET_SYSERR;
+ }
+ if (NULL != mime)
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (spa,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ mime));
+
+ {
+ struct WebuiFile *w;
+ const char *fn;
+
+ fn = strrchr (dn, '/');
+ GNUNET_assert (NULL != fn);
+ w = GNUNET_new (struct WebuiFile);
+ w->path = GNUNET_strdup (fn + 1);
+ w->spa = spa;
+ w->zspa = zspa;
+ GNUNET_CONTAINER_DLL_insert (webui_head,
+ webui_tail,
+ w);
+ }
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TEH_spa_init ()
+{
+ char *dn;
+
+ {
+ char *path;
+
+ path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ if (NULL == path)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_asprintf (&dn,
+ "%sexchange/spa/",
+ path);
+ GNUNET_free (path);
+ }
+
+ if (-1 ==
+ GNUNET_DISK_directory_scan (dn,
+ &build_webui,
+ NULL))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to load WebUI from `%s'\n",
+ dn);
+ GNUNET_free (dn);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (dn);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Nicely shut down.
+ */
+void __attribute__ ((destructor))
+get_spa_fini ()
+{
+ struct WebuiFile *w;
+
+ while (NULL != (w = webui_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (webui_head,
+ webui_tail,
+ w);
+ if (NULL != w->spa)
+ {
+ MHD_destroy_response (w->spa);
+ w->spa = NULL;
+ }
+ if (NULL != w->zspa)
+ {
+ MHD_destroy_response (w->zspa);
+ w->zspa = NULL;
+ }
+ GNUNET_free (w->path);
+ GNUNET_free (w);
+ }
+}
diff --git a/src/exchange/taler-exchange-httpd_spa.h b/src/exchange/taler-exchange-httpd_spa.h
new file mode 100644
index 000000000..4147a853b
--- /dev/null
+++ b/src/exchange/taler-exchange-httpd_spa.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of EXCHANGEABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler-exchange-httpd_spa.h
+ * @brief logic to preload and serve static files
+ * @author Christian Grothoff
+ */
+#ifndef TALER_EXCHANGE_HTTPD_SPA_H
+#define TALER_EXCHANGE_HTTPD_SPA_H
+
+#include <microhttpd.h>
+#include "taler-exchange-httpd.h"
+
+
+/**
+ * Return our single-page-app user interface (see contrib/wallet-core/).
+ *
+ * @param rc context of the handler
+ * @param[in,out] args remaining arguments (ignored)
+ * @return #MHD_YES on success (reply queued), #MHD_NO on error (close connection)
+ */
+MHD_RESULT
+TEH_handler_spa (struct TEH_RequestContext *rc,
+ const char *const args[]);
+
+
+/**
+ * Preload and compress SPA files.
+ *
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_spa_init (void);
+
+
+#endif
diff --git a/src/exchange/taler-exchange-httpd_transfers_get.c b/src/exchange/taler-exchange-httpd_transfers_get.c
index 0a994d8ec..18d96f955 100644
--- a/src/exchange/taler-exchange-httpd_transfers_get.c
+++ b/src/exchange/taler-exchange-httpd_transfers_get.c
@@ -59,14 +59,20 @@ struct AggregatedDepositDetail
struct TALER_CoinSpendPublicKeyP coin_pub;
/**
- * Total value of the coin in the deposit.
+ * Total value of the coin in the deposit (after
+ * refunds).
*/
struct TALER_Amount deposit_value;
/**
- * Fees charged by the exchange for the deposit of this coin.
+ * Fees charged by the exchange for the deposit of this coin (possibly after reduction due to refunds).
*/
struct TALER_Amount deposit_fee;
+
+ /**
+ * Total amount refunded for this coin.
+ */
+ struct TALER_Amount refund_total;
};
@@ -120,6 +126,13 @@ reply_transfer_details (struct MHD_Connection *connection,
&wdd_pos->h_contract_terms),
GNUNET_JSON_pack_data_auto ("coin_pub",
&wdd_pos->coin_pub),
+
+ GNUNET_JSON_pack_allow_null (
+ TALER_JSON_pack_amount ("refund_total",
+ TALER_amount_is_zero (
+ &wdd_pos->refund_total)
+ ? NULL
+ : &wdd_pos->refund_total)),
TALER_JSON_pack_amount ("deposit_value",
&wdd_pos->deposit_value),
TALER_JSON_pack_amount ("deposit_fee",
@@ -248,6 +261,31 @@ struct WtidTransactionContext
/**
+ * Callback that totals up the applicable refunds.
+ *
+ * @param cls a `struct TALER_Amount` where we keep the total
+ * @param amount_with_fee amount being refunded
+ */
+static enum GNUNET_GenericReturnValue
+add_refunds (void *cls,
+ const struct TALER_Amount *amount_with_fee)
+
+{
+ struct TALER_Amount *total = cls;
+
+ if (0 >
+ TALER_amount_add (total,
+ total,
+ amount_with_fee))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
* Function called with the results of the lookup of the individual deposits
* that were aggregated for the given wire transfer.
*
@@ -260,28 +298,96 @@ struct WtidTransactionContext
* @param h_contract_terms which proposal was this payment about
* @param denom_pub denomination public key of the @a coin_pub (ignored)
* @param coin_pub which public key was this payment about
- * @param deposit_value amount contributed by this coin in total
+ * @param deposit_value amount contributed by this coin in total (including fee)
* @param deposit_fee deposit fee charged by exchange for this coin
*/
static void
-handle_deposit_data (void *cls,
- uint64_t rowid,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const char *account_payto_uri,
- const struct TALER_PaytoHashP *h_payto,
- struct GNUNET_TIME_Timestamp exec_time,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *deposit_value,
- const struct TALER_Amount *deposit_fee)
+handle_deposit_data (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const char *account_payto_uri,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Timestamp exec_time,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *deposit_value,
+ const struct TALER_Amount *deposit_fee)
{
struct WtidTransactionContext *ctx = cls;
+ struct TALER_Amount total_refunds;
+ struct TALER_Amount dval;
+ struct TALER_Amount dfee;
+ enum GNUNET_DB_QueryStatus qs;
(void) rowid;
(void) denom_pub;
+ (void) h_payto;
if (GNUNET_SYSERR == ctx->is_valid)
return;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (deposit_value->currency,
+ &total_refunds));
+ qs = TEH_plugin->select_refunds_by_coin (TEH_plugin->cls,
+ coin_pub,
+ merchant_pub,
+ h_contract_terms,
+ &add_refunds,
+ &total_refunds);
+ if (qs < 0)
+ {
+ GNUNET_break (0);
+ ctx->is_valid = GNUNET_SYSERR;
+ return;
+ }
+ if (1 ==
+ TALER_amount_cmp (&total_refunds,
+ deposit_value))
+ {
+ /* Refunds exceeded total deposit? not OK! */
+ GNUNET_break (0);
+ ctx->is_valid = GNUNET_SYSERR;
+ return;
+ }
+ if (0 ==
+ TALER_amount_cmp (&total_refunds,
+ deposit_value))
+ {
+ /* total_refunds == deposit_value;
+ in this case, the total contributed to the
+ wire transfer is zero (as are fees) */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (deposit_value->currency,
+ &dval));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (deposit_value->currency,
+ &dfee));
+
+ }
+ else
+ {
+ /* Compute deposit value by subtracting refunds */
+ GNUNET_assert (0 <
+ TALER_amount_subtract (&dval,
+ deposit_value,
+ &total_refunds));
+ if (-1 ==
+ TALER_amount_cmp (&dval,
+ deposit_fee))
+ {
+ /* dval < deposit_fee, so after refunds less than
+ the deposit fee remains; reduce deposit fee to
+ the remaining value of the coin */
+ dfee = dval;
+ }
+ else
+ {
+ /* Partial refund, deposit fee remains */
+ dfee = *deposit_fee;
+ }
+ }
+
if (GNUNET_NO == ctx->is_valid)
{
/* First one we encounter, setup general information in 'ctx' */
@@ -291,8 +397,8 @@ handle_deposit_data (void *cls,
ctx->is_valid = GNUNET_YES;
if (0 >
TALER_amount_subtract (&ctx->total,
- deposit_value,
- deposit_fee))
+ &dval,
+ &dfee))
{
GNUNET_break (0);
ctx->is_valid = GNUNET_SYSERR;
@@ -316,8 +422,8 @@ handle_deposit_data (void *cls,
}
if (0 >
TALER_amount_subtract (&delta,
- deposit_value,
- deposit_fee))
+ &dval,
+ &dfee))
{
GNUNET_break (0);
ctx->is_valid = GNUNET_SYSERR;
@@ -338,8 +444,9 @@ handle_deposit_data (void *cls,
struct AggregatedDepositDetail *wdd;
wdd = GNUNET_new (struct AggregatedDepositDetail);
- wdd->deposit_value = *deposit_value;
- wdd->deposit_fee = *deposit_fee;
+ wdd->deposit_value = dval;
+ wdd->deposit_fee = dfee;
+ wdd->refund_total = total_refunds;
wdd->h_contract_terms = *h_contract_terms;
wdd->coin_pub = *coin_pub;
GNUNET_CONTAINER_DLL_insert (ctx->wdd_head,
diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c
deleted file mode 100644
index 7e5f0a915..000000000
--- a/src/exchange/taler-exchange-httpd_wire.c
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2015-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_wire.c
- * @brief Handle /wire requests
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_json_lib.h>
-#include "taler_dbevents.h"
-#include "taler-exchange-httpd_responses.h"
-#include "taler-exchange-httpd_keys.h"
-#include "taler-exchange-httpd_wire.h"
-#include "taler_json_lib.h"
-#include "taler_mhd_lib.h"
-#include <jansson.h>
-
-/**
- * Information we track about wire fees.
- */
-struct WireFeeSet
-{
-
- /**
- * Kept in a DLL.
- */
- struct WireFeeSet *next;
-
- /**
- * Kept in a DLL.
- */
- struct WireFeeSet *prev;
-
- /**
- * Actual fees.
- */
- struct TALER_WireFeeSet fees;
-
- /**
- * Start date of fee validity (inclusive).
- */
- struct GNUNET_TIME_Timestamp start_date;
-
- /**
- * End date of fee validity (exclusive).
- */
- struct GNUNET_TIME_Timestamp end_date;
-
- /**
- * Wire method the fees apply to.
- */
- char *method;
-};
-
-
-/**
- * State we keep per thread to cache the /wire response.
- */
-struct WireStateHandle
-{
- /**
- * Cached reply for /wire response.
- */
- struct MHD_Response *wire_reply;
-
- /**
- * ETag for this response (if any).
- */
- char *etag;
-
- /**
- * head of DLL of wire fees.
- */
- struct WireFeeSet *wfs_head;
-
- /**
- * Tail of DLL of wire fees.
- */
- struct WireFeeSet *wfs_tail;
-
- /**
- * Earliest timestamp of all the wire methods when we have no more fees.
- */
- struct GNUNET_TIME_Absolute cache_expiration;
-
- /**
- * @e cache_expiration time, formatted.
- */
- char dat[128];
-
- /**
- * For which (global) wire_generation was this data structure created?
- * Used to check when we are outdated and need to be re-generated.
- */
- uint64_t wire_generation;
-
- /**
- * HTTP status to return with this response.
- */
- unsigned int http_status;
-
-};
-
-
-/**
- * Stores the latest generation of our wire response.
- */
-static struct WireStateHandle *wire_state;
-
-/**
- * Handler listening for wire updates by other exchange
- * services.
- */
-static struct GNUNET_DB_EventHandler *wire_eh;
-
-/**
- * Counter incremented whenever we have a reason to re-build the #wire_state
- * because something external changed.
- */
-static uint64_t wire_generation;
-
-
-/**
- * Free memory associated with @a wsh
- *
- * @param[in] wsh wire state to destroy
- */
-static void
-destroy_wire_state (struct WireStateHandle *wsh)
-{
- struct WireFeeSet *wfs;
-
- while (NULL != (wfs = wsh->wfs_head))
- {
- GNUNET_CONTAINER_DLL_remove (wsh->wfs_head,
- wsh->wfs_tail,
- wfs);
- GNUNET_free (wfs->method);
- GNUNET_free (wfs);
- }
- MHD_destroy_response (wsh->wire_reply);
- GNUNET_free (wsh->etag);
- GNUNET_free (wsh);
-}
-
-
-/**
- * Function called whenever another exchange process has updated
- * the wire data in the database.
- *
- * @param cls NULL
- * @param extra unused
- * @param extra_size number of bytes in @a extra unused
- */
-static void
-wire_update_event_cb (void *cls,
- const void *extra,
- size_t extra_size)
-{
- (void) cls;
- (void) extra;
- (void) extra_size;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received /wire update event\n");
- TEH_check_invariants ();
- wire_generation++;
-}
-
-
-enum GNUNET_GenericReturnValue
-TEH_wire_init ()
-{
- struct GNUNET_DB_EventHeaderP es = {
- .size = htons (sizeof (es)),
- .type = htons (TALER_DBEVENT_EXCHANGE_KEYS_UPDATED),
- };
-
- wire_eh = TEH_plugin->event_listen (TEH_plugin->cls,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &es,
- &wire_update_event_cb,
- NULL);
- if (NULL == wire_eh)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-void
-TEH_wire_done ()
-{
- if (NULL != wire_state)
- {
- destroy_wire_state (wire_state);
- wire_state = NULL;
- }
- if (NULL != wire_eh)
- {
- TEH_plugin->event_listen_cancel (TEH_plugin->cls,
- wire_eh);
- wire_eh = NULL;
- }
-}
-
-
-/**
- * Add information about a wire account to @a cls.
- *
- * @param cls a `json_t *` object to expand with wire account details
- * @param payto_uri the exchange bank account URI to add
- * @param master_sig master key signature affirming that this is a bank
- * account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
- */
-static void
-add_wire_account (void *cls,
- const char *payto_uri,
- const struct TALER_MasterSignatureP *master_sig)
-{
- json_t *a = cls;
-
- if (0 !=
- json_array_append_new (
- a,
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("payto_uri",
- payto_uri),
- GNUNET_JSON_pack_data_auto ("master_sig",
- master_sig))))
- {
- GNUNET_break (0); /* out of memory!? */
- return;
- }
-}
-
-
-/**
- * Closure for #add_wire_fee().
- */
-struct AddContext
-{
- /**
- * Wire method the fees are for.
- */
- char *wire_method;
-
- /**
- * Wire state we are building.
- */
- struct WireStateHandle *wsh;
-
- /**
- * Array to append the fee to.
- */
- json_t *a;
-
- /**
- * Context we hash "everything" we add into. This is used
- * to compute the etag. Technically, we only hash the
- * master_sigs, as they imply the rest.
- */
- struct GNUNET_HashContext *hc;
-
- /**
- * Set to the maximum end-date seen.
- */
- struct GNUNET_TIME_Absolute max_seen;
-};
-
-
-/**
- * Add information about a wire account to @a cls.
- *
- * @param cls a `struct AddContext`
- * @param fees the wire fees we charge
- * @param start_date from when are these fees valid (start date)
- * @param end_date until when are these fees valid (end date, exclusive)
- * @param master_sig master key signature affirming that this is the correct
- * fee (of purpose #TALER_SIGNATURE_MASTER_WIRE_FEES)
- */
-static void
-add_wire_fee (void *cls,
- const struct TALER_WireFeeSet *fees,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct AddContext *ac = cls;
- struct WireFeeSet *wfs;
-
- GNUNET_CRYPTO_hash_context_read (ac->hc,
- master_sig,
- sizeof (*master_sig));
- ac->max_seen = GNUNET_TIME_absolute_max (ac->max_seen,
- end_date.abs_time);
- wfs = GNUNET_new (struct WireFeeSet);
- wfs->start_date = start_date;
- wfs->end_date = end_date;
- wfs->fees = *fees;
- wfs->method = GNUNET_strdup (ac->wire_method);
- GNUNET_CONTAINER_DLL_insert (ac->wsh->wfs_head,
- ac->wsh->wfs_tail,
- wfs);
- if (0 !=
- json_array_append_new (
- ac->a,
- GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("wire_fee",
- &fees->wire),
- TALER_JSON_pack_amount ("wad_fee",
- &fees->wad),
- TALER_JSON_pack_amount ("closing_fee",
- &fees->closing),
- GNUNET_JSON_pack_timestamp ("start_date",
- start_date),
- GNUNET_JSON_pack_timestamp ("end_date",
- end_date),
- GNUNET_JSON_pack_data_auto ("sig",
- master_sig))))
- {
- GNUNET_break (0); /* out of memory!? */
- return;
- }
-}
-
-
-/**
- * Create the /wire response from our database state.
- *
- * @return NULL on error
- */
-static struct WireStateHandle *
-build_wire_state (void)
-{
- json_t *wire_accounts_array;
- json_t *wire_fee_object;
- uint64_t wg = wire_generation; /* must be obtained FIRST */
- enum GNUNET_DB_QueryStatus qs;
- struct WireStateHandle *wsh;
- struct GNUNET_HashContext *hc;
-
- wsh = GNUNET_new (struct WireStateHandle);
- wsh->wire_generation = wg;
- wire_accounts_array = json_array ();
- GNUNET_assert (NULL != wire_accounts_array);
- qs = TEH_plugin->get_wire_accounts (TEH_plugin->cls,
- &add_wire_account,
- wire_accounts_array);
- if (0 > qs)
- {
- GNUNET_break (0);
- json_decref (wire_accounts_array);
- wsh->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
- wsh->wire_reply
- = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_wire_accounts");
- return wsh;
- }
- if (0 == json_array_size (wire_accounts_array))
- {
- json_decref (wire_accounts_array);
- wsh->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
- wsh->wire_reply
- = TALER_MHD_make_error (TALER_EC_EXCHANGE_WIRE_NO_ACCOUNTS_CONFIGURED,
- NULL);
- return wsh;
- }
- wire_fee_object = json_object ();
- GNUNET_assert (NULL != wire_fee_object);
- wsh->cache_expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
- hc = GNUNET_CRYPTO_hash_context_start ();
- {
- json_t *account;
- size_t index;
-
- json_array_foreach (wire_accounts_array, index, account) {
- char *wire_method;
- const char *payto_uri = json_string_value (json_object_get (account,
- "payto_uri"));
-
- GNUNET_assert (NULL != payto_uri);
- wire_method = TALER_payto_get_method (payto_uri);
- if (NULL == wire_method)
- {
- wsh->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
- wsh->wire_reply
- = TALER_MHD_make_error (
- TALER_EC_EXCHANGE_WIRE_INVALID_PAYTO_CONFIGURED,
- payto_uri);
- json_decref (wire_accounts_array);
- json_decref (wire_fee_object);
- GNUNET_CRYPTO_hash_context_abort (hc);
- return wsh;
- }
- if (NULL == json_object_get (wire_fee_object,
- wire_method))
- {
- struct AddContext ac = {
- .wire_method = wire_method,
- .wsh = wsh,
- .a = json_array (),
- .hc = hc
- };
-
- GNUNET_assert (NULL != ac.a);
- qs = TEH_plugin->get_wire_fees (TEH_plugin->cls,
- wire_method,
- &add_wire_fee,
- &ac);
- if (0 > qs)
- {
- GNUNET_break (0);
- json_decref (ac.a);
- json_decref (wire_fee_object);
- json_decref (wire_accounts_array);
- GNUNET_free (wire_method);
- wsh->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
- wsh->wire_reply
- = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_wire_fees");
- GNUNET_CRYPTO_hash_context_abort (hc);
- return wsh;
- }
- if (0 == json_array_size (ac.a))
- {
- json_decref (ac.a);
- json_decref (wire_accounts_array);
- json_decref (wire_fee_object);
- wsh->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
- wsh->wire_reply
- = TALER_MHD_make_error (TALER_EC_EXCHANGE_WIRE_FEES_NOT_CONFIGURED,
- wire_method);
- GNUNET_free (wire_method);
- GNUNET_CRYPTO_hash_context_abort (hc);
- return wsh;
- }
- wsh->cache_expiration = GNUNET_TIME_absolute_min (ac.max_seen,
- wsh->cache_expiration);
- GNUNET_assert (0 ==
- json_object_set_new (wire_fee_object,
- wire_method,
- ac.a));
- }
- GNUNET_free (wire_method);
- }
- }
-
-
- wsh->wire_reply = TALER_MHD_MAKE_JSON_PACK (
- GNUNET_JSON_pack_array_steal ("accounts",
- wire_accounts_array),
- GNUNET_JSON_pack_object_steal ("fees",
- wire_fee_object),
- GNUNET_JSON_pack_data_auto ("master_public_key",
- &TEH_master_public_key));
- {
- struct GNUNET_TIME_Timestamp m;
-
- m = GNUNET_TIME_absolute_to_timestamp (wsh->cache_expiration);
- TALER_MHD_get_date_string (m.abs_time,
- wsh->dat);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting 'Expires' header for '/wire' to '%s'\n",
- wsh->dat);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (wsh->wire_reply,
- MHD_HTTP_HEADER_EXPIRES,
- wsh->dat));
- }
- /* Set cache control headers: our response varies depending on these headers */
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (wsh->wire_reply,
- MHD_HTTP_HEADER_VARY,
- MHD_HTTP_HEADER_ACCEPT_ENCODING));
- /* Information is always public, revalidate after 1 day */
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (wsh->wire_reply,
- MHD_HTTP_HEADER_CACHE_CONTROL,
- "public,max-age=86400"));
-
- {
- struct GNUNET_HashCode h;
- char etag[sizeof (h) * 2];
- char *end;
-
- GNUNET_CRYPTO_hash_context_finish (hc,
- &h);
- end = GNUNET_STRINGS_data_to_string (&h,
- sizeof (h),
- etag,
- sizeof (etag));
- *end = '\0';
- wsh->etag = GNUNET_strdup (etag);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (wsh->wire_reply,
- MHD_HTTP_HEADER_ETAG,
- etag));
- }
- wsh->http_status = MHD_HTTP_OK;
- return wsh;
-}
-
-
-void
-TEH_wire_update_state (void)
-{
- struct GNUNET_DB_EventHeaderP es = {
- .size = htons (sizeof (es)),
- .type = htons (TALER_DBEVENT_EXCHANGE_WIRE_UPDATED),
- };
-
- TEH_plugin->event_notify (TEH_plugin->cls,
- &es,
- NULL,
- 0);
- wire_generation++;
-}
-
-
-/**
- * Return the current key state for this thread. Possibly
- * re-builds the key state if we have reason to believe
- * that something changed.
- *
- * @return NULL on error
- */
-struct WireStateHandle *
-get_wire_state (void)
-{
- struct WireStateHandle *old_wsh;
-
- old_wsh = wire_state;
- if ( (NULL == old_wsh) ||
- (old_wsh->wire_generation < wire_generation) )
- {
- struct WireStateHandle *wsh;
-
- TEH_check_invariants ();
- wsh = build_wire_state ();
- wire_state = wsh;
- if (NULL != old_wsh)
- destroy_wire_state (old_wsh);
- TEH_check_invariants ();
- return wsh;
- }
- return old_wsh;
-}
-
-
-MHD_RESULT
-TEH_handler_wire (struct TEH_RequestContext *rc,
- const char *const args[])
-{
- struct WireStateHandle *wsh;
-
- (void) args;
- wsh = get_wire_state ();
- if (NULL == wsh)
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_GENERIC_BAD_CONFIGURATION,
- NULL);
- {
- const char *etag;
-
- etag = MHD_lookup_connection_value (rc->connection,
- MHD_HEADER_KIND,
- MHD_HTTP_HEADER_IF_NONE_MATCH);
- if ( (NULL != etag) &&
- (MHD_HTTP_OK == wsh->http_status) &&
- (NULL != wsh->etag) &&
- (0 == strcmp (etag,
- wsh->etag)) )
- {
- MHD_RESULT ret;
- struct MHD_Response *resp;
-
- resp = MHD_create_response_from_buffer (0,
- NULL,
- MHD_RESPMEM_PERSISTENT);
- TALER_MHD_add_global_headers (resp);
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
- MHD_HTTP_HEADER_EXPIRES,
- wsh->dat));
- GNUNET_break (MHD_YES ==
- MHD_add_response_header (resp,
- MHD_HTTP_HEADER_ETAG,
- wsh->etag));
- ret = MHD_queue_response (rc->connection,
- MHD_HTTP_NOT_MODIFIED,
- resp);
- GNUNET_break (MHD_YES == ret);
- MHD_destroy_response (resp);
- return ret;
- }
- }
- return MHD_queue_response (rc->connection,
- wsh->http_status,
- wsh->wire_reply);
-}
-
-
-const struct TALER_WireFeeSet *
-TEH_wire_fees_by_time (
- struct GNUNET_TIME_Timestamp ts,
- const char *method)
-{
- struct WireStateHandle *wsh = get_wire_state ();
-
- for (struct WireFeeSet *wfs = wsh->wfs_head;
- NULL != wfs;
- wfs = wfs->next)
- {
- if (0 != strcmp (method,
- wfs->method))
- continue;
- if ( (GNUNET_TIME_timestamp_cmp (wfs->start_date,
- >,
- ts)) ||
- (GNUNET_TIME_timestamp_cmp (ts,
- >=,
- wfs->end_date)) )
- continue;
- return &wfs->fees;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "No wire fees for method `%s' at %s configured\n",
- method,
- GNUNET_TIME_timestamp2s (ts));
- return NULL;
-}
-
-
-/* end of taler-exchange-httpd_wire.c */
diff --git a/src/exchange/taler-exchange-httpd_wire.h b/src/exchange/taler-exchange-httpd_wire.h
deleted file mode 100644
index 75595fe69..000000000
--- a/src/exchange/taler-exchange-httpd_wire.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014--2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU Affero General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_wire.h
- * @brief Handle /wire requests
- * @author Christian Grothoff
- */
-#ifndef TALER_EXCHANGE_HTTPD_WIRE_H
-#define TALER_EXCHANGE_HTTPD_WIRE_H
-
-#include <gnunet/gnunet_util_lib.h>
-#include <microhttpd.h>
-#include "taler-exchange-httpd.h"
-
-
-/**
- * Clean up wire subsystem.
- */
-void
-TEH_wire_done (void);
-
-
-/**
- * Look up wire fee structure by @a ts.
- *
- * @param ts timestamp to lookup wire fees at
- * @param method wire method to lookup fees for
- * @return the wire fee details, or
- * NULL if none are configured for @a ts and @a method
- */
-const struct TALER_WireFeeSet *
-TEH_wire_fees_by_time (
- struct GNUNET_TIME_Timestamp ts,
- const char *method);
-
-
-/**
- * Initialize wire subsystem.
- *
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TEH_wire_init (void);
-
-
-/**
- * Something changed in the database. Rebuild the wire replies. This function
- * should be called if the exchange learns about a new signature from our
- * master key.
- *
- * (We do not do so immediately, but merely signal to all threads that they
- * need to rebuild their wire state upon the next call to
- * #TEH_handler_wire()).
- */
-void
-TEH_wire_update_state (void);
-
-
-/**
- * Handle a "/wire" request.
- *
- * @param rc request context
- * @param args array of additional options (must be empty for this function)
- * @return MHD result code
- */
-MHD_RESULT
-TEH_handler_wire (struct TEH_RequestContext *rc,
- const char *const args[]);
-
-
-#endif
diff --git a/src/exchange/taler-exchange-httpd_withdraw.c b/src/exchange/taler-exchange-httpd_withdraw.c
deleted file mode 100644
index 86d2c62b0..000000000
--- a/src/exchange/taler-exchange-httpd_withdraw.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation; either version 3,
- or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty
- of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General
- Public License along with TALER; see the file COPYING. If not,
- see <http://www.gnu.org/licenses/>
-*/
-/**
- * @file taler-exchange-httpd_withdraw.c
- * @brief Handle /reserves/$RESERVE_PUB/withdraw requests
- * @author Florian Dold
- * @author Benedikt Mueller
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include <jansson.h>
-#include "taler_json_lib.h"
-#include "taler_mhd_lib.h"
-#include "taler-exchange-httpd_withdraw.h"
-#include "taler-exchange-httpd_responses.h"
-#include "taler-exchange-httpd_keys.h"
-
-
-/**
- * Context for #withdraw_transaction.
- */
-struct WithdrawContext
-{
-
- /**
- * Hash of the (blinded) message to be signed by the Exchange.
- */
- struct TALER_BlindedCoinHashP h_coin_envelope;
-
- /**
- * Value of the coin being exchanged (matching the denomination key)
- * plus the transaction fee. We include this in what is being
- * signed so that we can verify a reserve's remaining total balance
- * without needing to access the respective denomination key
- * information each time.
- */
- struct TALER_Amount amount_with_fee;
-
- /**
- * Blinded planchet.
- */
- struct TALER_BlindedPlanchet blinded_planchet;
-
- /**
- * Set to the resulting signed coin data to be returned to the client.
- */
- struct TALER_EXCHANGEDB_CollectableBlindcoin collectable;
-
- /**
- * KYC status for the operation.
- */
- struct TALER_EXCHANGEDB_KycStatus kyc;
-
-};
-
-
-/**
- * Function implementing withdraw transaction. Runs the
- * transaction logic; IF it returns a non-error code, the transaction
- * logic MUST NOT queue a MHD response. IF it returns an hard error,
- * the transaction logic MUST queue a MHD response and set @a mhd_ret.
- * IF it returns the soft error code, the function MAY be called again
- * to retry and MUST not queue a MHD response.
- *
- * Note that "wc->collectable.sig" is set before entering this function as we
- * signed before entering the transaction.
- *
- * @param cls a `struct WithdrawContext *`
- * @param connection MHD request which triggered the transaction
- * @param[out] mhd_ret set to MHD response status for @a connection,
- * if transaction failed (!)
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-withdraw_transaction (void *cls,
- struct MHD_Connection *connection,
- MHD_RESULT *mhd_ret)
-{
- struct WithdrawContext *wc = cls;
- enum GNUNET_DB_QueryStatus qs;
- bool found = false;
- bool balance_ok = false;
- struct GNUNET_TIME_Timestamp now;
- uint64_t ruuid;
- const struct TALER_CsNonce *nonce;
- const struct TALER_BlindedPlanchet *bp;
-
- now = GNUNET_TIME_timestamp_get ();
- bp = &wc->blinded_planchet;
- nonce =
- (TALER_DENOMINATION_CS == bp->cipher)
- ? &bp->details.cs_blinded_planchet.nonce
- : NULL;
- // FIXME: what error is returned on nonce reuse?
- // Should expand function to return this error
- // specifically, and then we should return a
- // TALER_EC_EXCHANGE_WITHDRAW_NONCE_REUSE,
- qs = TEH_plugin->do_withdraw (TEH_plugin->cls,
- nonce,
- &wc->collectable,
- now,
- &found,
- &balance_ok,
- &wc->kyc,
- &ruuid);
- if (0 > qs)
- {
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "do_withdraw");
- return qs;
- }
- if (! found)
- {
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_NOT_FOUND,
- TALER_EC_EXCHANGE_GENERIC_RESERVE_UNKNOWN,
- NULL);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (! balance_ok)
- {
- TEH_plugin->rollback (TEH_plugin->cls);
- *mhd_ret = TEH_RESPONSE_reply_reserve_insufficient_balance (
- connection,
- &wc->collectable.amount_with_fee,
- &wc->collectable.reserve_pub);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (TEH_KYC_NONE != TEH_kyc_config.mode) &&
- (! wc->kyc.ok) &&
- (TALER_EXCHANGEDB_KYC_W2W == wc->kyc.type) )
- {
- /* Wallet-to-wallet payments _always_ require KYC */
- *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- wc->kyc.payment_target_uuid));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (TEH_KYC_NONE != TEH_kyc_config.mode) &&
- (! wc->kyc.ok) &&
- (TALER_EXCHANGEDB_KYC_WITHDRAW == wc->kyc.type) &&
- (! GNUNET_TIME_relative_is_zero (TEH_kyc_config.withdraw_period)) )
- {
- /* Withdraws require KYC if above threshold */
- enum GNUNET_DB_QueryStatus qs2;
- bool below_limit;
-
- qs2 = TEH_plugin->do_withdraw_limit_check (
- TEH_plugin->cls,
- ruuid,
- GNUNET_TIME_absolute_subtract (now.abs_time,
- TEH_kyc_config.withdraw_period),
- &TEH_kyc_config.withdraw_limit,
- &below_limit);
- if (0 > qs2)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs2);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs2)
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "do_withdraw_limit_check");
- return qs2;
- }
- if (! below_limit)
- {
- *mhd_ret = TALER_MHD_REPLY_JSON_PACK (
- connection,
- MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
- GNUNET_JSON_pack_uint64 ("payment_target_uuid",
- wc->kyc.payment_target_uuid));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- TEH_METRICS_num_success[TEH_MT_SUCCESS_BATCH_WITHDRAW]++;
- return qs;
-}
-
-
-/**
- * Check if the @a rc is replayed and we already have an
- * answer. If so, replay the existing answer and return the
- * HTTP response.
- *
- * @param rc request context
- * @param[in,out] wc parsed request data
- * @param[out] mret HTTP status, set if we return true
- * @return true if the request is idempotent with an existing request
- * false if we did not find the request in the DB and did not set @a mret
- */
-static bool
-check_request_idempotent (struct TEH_RequestContext *rc,
- struct WithdrawContext *wc,
- MHD_RESULT *mret)
-{
- enum GNUNET_DB_QueryStatus qs;
-
- qs = TEH_plugin->get_withdraw_info (TEH_plugin->cls,
- &wc->h_coin_envelope,
- &wc->collectable);
- if (0 > qs)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- if (GNUNET_DB_STATUS_HARD_ERROR == qs)
- *mret = TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_FETCH_FAILED,
- "get_withdraw_info");
- return true; /* well, kind-of */
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- return false;
- /* generate idempotent reply */
- TEH_METRICS_num_requests[TEH_MT_REQUEST_IDEMPOTENT_WITHDRAW]++;
- *mret = TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_blinded_denom_sig ("ev_sig",
- &wc->collectable.sig));
- TALER_blinded_denom_sig_free (&wc->collectable.sig);
- return true;
-}
-
-
-MHD_RESULT
-TEH_handler_withdraw (struct TEH_RequestContext *rc,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const json_t *root)
-{
- struct WithdrawContext wc;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &wc.collectable.reserve_sig),
- GNUNET_JSON_spec_fixed_auto ("denom_pub_hash",
- &wc.collectable.denom_pub_hash),
- TALER_JSON_spec_blinded_planchet ("coin_ev",
- &wc.blinded_planchet),
- GNUNET_JSON_spec_end ()
- };
- enum TALER_ErrorCode ec;
- struct TEH_DenominationKey *dk;
-
- memset (&wc,
- 0,
- sizeof (wc));
- wc.collectable.reserve_pub = *reserve_pub;
-
- {
- enum GNUNET_GenericReturnValue res;
-
- res = TALER_MHD_parse_json_data (rc->connection,
- root,
- spec);
- if (GNUNET_OK != res)
- return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
- }
- {
- MHD_RESULT mret;
- struct TEH_KeyStateHandle *ksh;
-
- ksh = TEH_keys_get_state ();
- if (NULL == ksh)
- {
- if (! check_request_idempotent (rc,
- &wc,
- &mret))
- {
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_GENERIC_KEYS_MISSING,
- NULL);
- }
- GNUNET_JSON_parse_free (spec);
- return mret;
- }
- dk = TEH_keys_denomination_by_hash2 (ksh,
- &wc.collectable.denom_pub_hash,
- NULL,
- NULL);
- if (NULL == dk)
- {
- if (! check_request_idempotent (rc,
- &wc,
- &mret))
- {
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_unknown_denom_pub_hash (
- rc->connection,
- &wc.collectable.denom_pub_hash);
- }
- GNUNET_JSON_parse_free (spec);
- return mret;
- }
- if (GNUNET_TIME_absolute_is_past (dk->meta.expire_withdraw.abs_time))
- {
- /* This denomination is past the expiration time for withdraws */
- if (! check_request_idempotent (rc,
- &wc,
- &mret))
- {
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- rc->connection,
- &wc.collectable.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_EXPIRED,
- "WITHDRAW");
- }
- GNUNET_JSON_parse_free (spec);
- return mret;
- }
- if (GNUNET_TIME_absolute_is_future (dk->meta.start.abs_time))
- {
- /* This denomination is not yet valid, no need to check
- for idempotency! */
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- rc->connection,
- &wc.collectable.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_VALIDITY_IN_FUTURE,
- "WITHDRAW");
- }
- if (dk->recoup_possible)
- {
- /* This denomination has been revoked */
- if (! check_request_idempotent (rc,
- &wc,
- &mret))
- {
- GNUNET_JSON_parse_free (spec);
- return TEH_RESPONSE_reply_expired_denom_pub_hash (
- rc->connection,
- &wc.collectable.denom_pub_hash,
- TALER_EC_EXCHANGE_GENERIC_DENOMINATION_REVOKED,
- "WITHDRAW");
- }
- GNUNET_JSON_parse_free (spec);
- return mret;
- }
- if (dk->denom_pub.cipher != wc.blinded_planchet.cipher)
- {
- /* denomination cipher and blinded planchet cipher not the same */
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_EXCHANGE_GENERIC_CIPHER_MISMATCH,
- NULL);
- }
- }
-
- if (0 >
- TALER_amount_add (&wc.collectable.amount_with_fee,
- &dk->meta.value,
- &dk->meta.fees.withdraw))
- {
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_EXCHANGE_WITHDRAW_AMOUNT_FEE_OVERFLOW,
- NULL);
- }
-
- if (GNUNET_OK !=
- TALER_coin_ev_hash (&wc.blinded_planchet,
- &wc.collectable.denom_pub_hash,
- &wc.collectable.h_coin_envelope))
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
- NULL);
- }
-
- TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
- if (GNUNET_OK !=
- TALER_wallet_withdraw_verify (&wc.collectable.denom_pub_hash,
- &wc.collectable.amount_with_fee,
- &wc.collectable.h_coin_envelope,
- &wc.collectable.reserve_pub,
- &wc.collectable.reserve_sig))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_error (rc->connection,
- MHD_HTTP_FORBIDDEN,
- TALER_EC_EXCHANGE_WITHDRAW_RESERVE_SIGNATURE_INVALID,
- NULL);
- }
-
- /* Sign before transaction! */
- ec = TEH_keys_denomination_sign_withdraw (
- &wc.collectable.denom_pub_hash,
- &wc.blinded_planchet,
- &wc.collectable.sig);
- if (TALER_EC_NONE != ec)
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return TALER_MHD_reply_with_ec (rc->connection,
- ec,
- NULL);
- }
-
- /* run transaction */
- {
- MHD_RESULT mhd_ret;
-
- if (GNUNET_OK !=
- TEH_DB_run_transaction (rc->connection,
- "run withdraw",
- TEH_MT_REQUEST_WITHDRAW,
- &mhd_ret,
- &withdraw_transaction,
- &wc))
- {
- /* Even if #withdraw_transaction() failed, it may have created a signature
- (or we might have done it optimistically above). */
- TALER_blinded_denom_sig_free (&wc.collectable.sig);
- GNUNET_JSON_parse_free (spec);
- return mhd_ret;
- }
- }
-
- /* Clean up and send back final response */
- GNUNET_JSON_parse_free (spec);
-
- {
- MHD_RESULT ret;
-
- ret = TALER_MHD_REPLY_JSON_PACK (
- rc->connection,
- MHD_HTTP_OK,
- TALER_JSON_pack_blinded_denom_sig ("ev_sig",
- &wc.collectable.sig));
- TALER_blinded_denom_sig_free (&wc.collectable.sig);
- return ret;
- }
-}
-
-
-/* end of taler-exchange-httpd_withdraw.c */
diff --git a/src/exchange/taler-exchange-kyc-aml-pep-trigger.sh b/src/exchange/taler-exchange-kyc-aml-pep-trigger.sh
new file mode 100755
index 000000000..9baa32baf
--- /dev/null
+++ b/src/exchange/taler-exchange-kyc-aml-pep-trigger.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+# This file is in the public domain.
+# This is an example of how to trigger AML if the
+# KYC attributes include '{"pep":true}'
+#
+# To be used as a script for the KYC_AML_TRIGGER.
+test "false" = $(jq .pep -)
diff --git a/src/exchange/taler-exchange-router.c b/src/exchange/taler-exchange-router.c
index 0816dfdba..a1a247194 100644
--- a/src/exchange/taler-exchange-router.c
+++ b/src/exchange/taler-exchange-router.c
@@ -32,7 +32,7 @@
#include "taler_bank_service.h"
-// FIXME: revisit how (and if) we do sharding!
+// FIXME #7271: revisit how (and if) we do sharding!
// Maybe use different helpers for wads than
// for local purses?!
/**
@@ -282,7 +282,7 @@ run_routing (void *cls)
task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Checking for ready P2P transfers to route\n");
- // FIXME: do actual work here!
+ // FIXME #7271: do actual work here!
commit_or_warn ();
release_shard (s);
task = GNUNET_SCHEDULER_add_now (&run_shard,
diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c
index 011da6b57..9724b41fc 100644
--- a/src/exchange/taler-exchange-transfer.c
+++ b/src/exchange/taler-exchange-transfer.c
@@ -264,7 +264,7 @@ shutdown_task (void *cls)
/**
- * Parse the configuration for wirewatch.
+ * Parse the configuration for taler-exchange-transfer.
*
* @return #GNUNET_OK on success
*/
@@ -406,25 +406,17 @@ batch_done (void)
* except for irrecoverable errors.
*
* @param cls `struct WirePrepareData` we are working on
- * @param http_status_code #MHD_HTTP_OK on success
- * @param ec taler error code
- * @param row_id unique ID of the wire transfer in the bank's records
- * @param wire_timestamp when did the transfer happen
+ * @param tr transfer response
*/
static void
wire_confirm_cb (void *cls,
- unsigned int http_status_code,
- enum TALER_ErrorCode ec,
- uint64_t row_id,
- struct GNUNET_TIME_Timestamp wire_timestamp)
+ const struct TALER_BANK_TransferResponse *tr)
{
struct WirePrepareData *wpd = cls;
enum GNUNET_DB_QueryStatus qs;
- (void) row_id;
- (void) wire_timestamp;
wpd->eh = NULL;
- switch (http_status_code)
+ switch (tr->http_status)
{
case MHD_HTTP_OK:
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -435,11 +427,12 @@ wire_confirm_cb (void *cls,
/* continued below */
break;
case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Wire transaction %llu failed: %u/%d\n",
(unsigned long long) wpd->row_id,
- http_status_code,
- ec);
+ tr->http_status,
+ tr->ec);
qs = db_plugin->wire_prepare_data_mark_failed (db_plugin->cls,
wpd->row_id);
/* continued below */
@@ -456,7 +449,7 @@ wire_confirm_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Wire transfer %llu failed (%u), trying again\n",
(unsigned long long) wpd->row_id,
- http_status_code);
+ tr->http_status);
wpd->eh = TALER_BANK_transfer (ctx,
wpd->wa->auth,
&wpd[1],
@@ -468,8 +461,8 @@ wire_confirm_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Wire transaction %llu failed: %u/%d\n",
(unsigned long long) wpd->row_id,
- http_status_code,
- ec);
+ tr->http_status,
+ tr->ec);
cleanup_wpd ();
db_plugin->rollback (db_plugin->cls);
global_ret = EXIT_FAILURE;
@@ -479,8 +472,8 @@ wire_confirm_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Wire transfer %llu failed: %u/%d\n",
(unsigned long long) wpd->row_id,
- http_status_code,
- ec);
+ tr->http_status,
+ tr->ec);
db_plugin->rollback (db_plugin->cls);
cleanup_wpd ();
global_ret = EXIT_FAILURE;
@@ -563,9 +556,9 @@ wire_prepare_cb (void *cls,
}
wpd = GNUNET_malloc (sizeof (struct WirePrepareData)
+ buf_size);
- memcpy (&wpd[1],
- buf,
- buf_size);
+ GNUNET_memcpy (&wpd[1],
+ buf,
+ buf_size);
wpd->buf_size = buf_size;
wpd->row_id = rowid;
GNUNET_CONTAINER_DLL_insert (wpd_head,
@@ -582,7 +575,7 @@ wire_prepare_cb (void *cls,
GNUNET_break (0);
cleanup_wpd ();
db_plugin->rollback (db_plugin->cls);
- global_ret = EXIT_NOTCONFIGURED;
+ global_ret = EXIT_NO_RESTART;
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -715,7 +708,7 @@ run_transfers (void *cls)
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"No more pending wire transfers, going idle\n");
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_delayed (transfer_idle_sleep_interval,
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c
index 0231f5100..da5d9c098 100644
--- a/src/exchange/taler-exchange-wirewatch.c
+++ b/src/exchange/taler-exchange-wirewatch.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016--2022 Taler Systems SA
+ Copyright (C) 2016--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -13,7 +13,6 @@
You should have received a copy of the GNU Affero General Public License along with
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-
/**
* @file taler-exchange-wirewatch.c
* @brief Process that watches for wire transfers to the exchange's bank account
@@ -43,122 +42,111 @@
#define MAXIMUM_BATCH_SIZE 1024
/**
- * Information we keep for each supported account.
+ * Information about our account.
*/
-struct WireAccount
-{
- /**
- * Accounts are kept in a DLL.
- */
- struct WireAccount *next;
-
- /**
- * Plugins are kept in a DLL.
- */
- struct WireAccount *prev;
-
- /**
- * Information about this account.
- */
- const struct TALER_EXCHANGEDB_AccountInfo *ai;
-
- /**
- * Active request for history.
- */
- struct TALER_BANK_CreditHistoryHandle *hh;
-
- /**
- * Until when is processing this wire plugin delayed?
- */
- struct GNUNET_TIME_Absolute delayed_until;
-
- /**
- * Encoded offset in the wire transfer list from where
- * to start the next query with the bank.
- */
- uint64_t batch_start;
-
- /**
- * Latest row offset seen in this transaction, becomes
- * the new #batch_start upon commit.
- */
- uint64_t latest_row_off;
-
- /**
- * Maximum row offset this transaction may yield. If we got the
- * maximum number of rows, we must not @e delay before running
- * the next transaction.
- */
- uint64_t max_row_off;
-
- /**
- * Offset where our current shard begins (inclusive).
- */
- uint64_t shard_start;
-
- /**
- * Offset where our current shard ends (exclusive).
- */
- uint64_t shard_end;
-
- /**
- * When did we start with the shard?
- */
- struct GNUNET_TIME_Absolute shard_start_time;
-
- /**
- * For how long did we lock the shard?
- */
- struct GNUNET_TIME_Absolute shard_end_time;
-
- /**
- * How long did we take to finish the last shard
- * for this account?
- */
- struct GNUNET_TIME_Relative shard_delay;
-
- /**
- * Name of our job in the shard table.
- */
- char *job_name;
-
- /**
- * How many transactions do we retrieve per batch?
- */
- unsigned int batch_size;
-
- /**
- * How much do we increment @e batch_size on success?
- */
- unsigned int batch_thresh;
-
- /**
- * Should we delay the next request to the wire plugin a bit? Set to
- * false if we actually did some work.
- */
- bool delay;
-
- /**
- * Did we start a transaction yet?
- */
- bool started_transaction;
-
- /**
- * Is this shard still open for processing.
- */
- bool shard_open;
-};
+static const struct TALER_EXCHANGEDB_AccountInfo *ai;
+
+/**
+ * Active request for history.
+ */
+static struct TALER_BANK_CreditHistoryHandle *hh;
+
+/**
+ * Set to true if the request for history did actually
+ * return transaction items.
+ */
+static bool hh_returned_data;
+
+/**
+ * Set to true if the request for history did not
+ * succeed because the account was unknown.
+ */
+static bool hh_account_404;
+
+/**
+ * When did we start the last @e hh request?
+ */
+static struct GNUNET_TIME_Absolute hh_start_time;
+
+/**
+ * Until when is processing this wire plugin delayed?
+ */
+static struct GNUNET_TIME_Absolute delayed_until;
+
+/**
+ * Encoded offset in the wire transfer list from where
+ * to start the next query with the bank.
+ */
+static uint64_t batch_start;
+
+/**
+ * Latest row offset seen in this transaction, becomes
+ * the new #batch_start upon commit.
+ */
+static uint64_t latest_row_off;
+
+/**
+ * Offset where our current shard begins (inclusive).
+ */
+static uint64_t shard_start;
+
+/**
+ * Offset where our current shard ends (exclusive).
+ */
+static uint64_t shard_end;
+
+/**
+ * When did we start with the shard?
+ */
+static struct GNUNET_TIME_Absolute shard_start_time;
+
+/**
+ * For how long did we lock the shard?
+ */
+static struct GNUNET_TIME_Absolute shard_end_time;
+
+/**
+ * How long did we take to finish the last shard
+ * for this account?
+ */
+static struct GNUNET_TIME_Relative shard_delay;
+
+/**
+ * How long did we take to finish the last shard
+ * for this account?
+ */
+static struct GNUNET_TIME_Relative longpoll_timeout;
+
+/**
+ * Name of our job in the shard table.
+ */
+static char *job_name;
+
+/**
+ * How many transactions do we retrieve per batch?
+ */
+static unsigned int batch_size;
+
+/**
+ * How much do we increment @e batch_size on success?
+ */
+static unsigned int batch_thresh;
+/**
+ * Did work remain in the transaction queue? Set to true
+ * if we did some work and thus there might be more.
+ */
+static bool progress;
/**
- * Head of list of loaded wire plugins.
+ * Did we start a transaction yet?
*/
-static struct WireAccount *wa_head;
+static bool started_transaction;
/**
- * Tail of list of loaded wire plugins.
+ * Is this shard still open for processing.
*/
-static struct WireAccount *wa_tail;
+static bool shard_open;
/**
* Handle to the context for interacting with the bank.
@@ -189,6 +177,11 @@ static struct TALER_EXCHANGEDB_Plugin *db_plugin;
static struct GNUNET_TIME_Relative wirewatch_idle_sleep_interval;
/**
+ * How long do we sleep on serialization conflicts?
+ */
+static struct GNUNET_TIME_Relative wirewatch_conflict_sleep_interval;
+
+/**
* Modulus to apply to group shards. The shard size must ultimately be a
* multiple of the batch size. Thus, if this is not a multiple of the
* #MAXIMUM_BATCH_SIZE, the batch size will be set to the #shard_size.
@@ -227,6 +220,10 @@ static int ignore_account_404;
*/
static struct GNUNET_SCHEDULER_Task *task;
+/**
+ * Name of the configuration section with the account we should watch.
+ */
+static char *account_section;
/**
* We're being aborted with CTRL-C (or SIGTERM). Shut down.
@@ -236,38 +233,32 @@ static struct GNUNET_SCHEDULER_Task *task;
static void
shutdown_task (void *cls)
{
+ enum GNUNET_DB_QueryStatus qs;
(void) cls;
- {
- struct WireAccount *wa;
- while (NULL != (wa = wa_head))
- {
- enum GNUNET_DB_QueryStatus qs;
-
- if (NULL != wa->hh)
- {
- TALER_BANK_credit_history_cancel (wa->hh);
- wa->hh = NULL;
- }
- GNUNET_CONTAINER_DLL_remove (wa_head,
- wa_tail,
- wa);
- if (wa->started_transaction)
- {
- db_plugin->rollback (db_plugin->cls);
- wa->started_transaction = false;
- }
- qs = db_plugin->abort_shard (db_plugin->cls,
- wa->job_name,
- wa->shard_start,
- wa->shard_end);
- if (qs <= 0)
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to abort work shard on shutdown\n");
- GNUNET_free (wa->job_name);
- GNUNET_free (wa);
- }
+ if (NULL != hh)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "History request cancelled on shutdown\n");
+ TALER_BANK_credit_history_cancel (hh);
+ hh = NULL;
}
+ if (started_transaction)
+ {
+ db_plugin->rollback (db_plugin->cls);
+ started_transaction = false;
+ }
+ if (shard_open)
+ {
+ qs = db_plugin->abort_shard (db_plugin->cls,
+ job_name,
+ shard_start,
+ shard_end);
+ if (qs <= 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to abort work shard on shutdown\n");
+ }
+ GNUNET_free (job_name);
if (NULL != ctx)
{
GNUNET_CURL_fini (ctx);
@@ -295,28 +286,36 @@ shutdown_task (void *cls)
* account to our list (if it is enabled and we can load the plugin).
*
* @param cls closure, NULL
- * @param ai account information
+ * @param in_ai account information
*/
static void
add_account_cb (void *cls,
- const struct TALER_EXCHANGEDB_AccountInfo *ai)
+ const struct TALER_EXCHANGEDB_AccountInfo *in_ai)
{
- struct WireAccount *wa;
-
(void) cls;
- if (! ai->credit_enabled)
+ if (! in_ai->credit_enabled)
return; /* not enabled for us, skip */
- wa = GNUNET_new (struct WireAccount);
- wa->ai = ai;
- GNUNET_asprintf (&wa->job_name,
+ if ( (NULL != account_section) &&
+ (0 != strcasecmp (in_ai->section_name,
+ account_section)) )
+ return; /* not enabled for us, skip */
+ if (NULL != ai)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Multiple accounts enabled (%s and %s), use '-a' command-line option to select one!\n",
+ ai->section_name,
+ in_ai->section_name);
+ GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_INVALIDARGUMENT;
+ return;
+ }
+ ai = in_ai;
+ GNUNET_asprintf (&job_name,
"wirewatch-%s",
ai->section_name);
- wa->batch_size = MAXIMUM_BATCH_SIZE;
- if (0 != shard_size % wa->batch_size)
- wa->batch_size = shard_size;
- GNUNET_CONTAINER_DLL_insert (wa_head,
- wa_tail,
- wa);
+ batch_size = MAXIMUM_BATCH_SIZE;
+ if (0 != shard_size % batch_size)
+ batch_size = shard_size;
}
@@ -354,13 +353,17 @@ exchange_serve_process_config (void)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No wire accounts configured for credit!\n");
- TALER_EXCHANGEDB_plugin_unload (db_plugin);
- db_plugin = NULL;
return GNUNET_SYSERR;
}
TALER_EXCHANGEDB_find_accounts (&add_account_cb,
NULL);
- GNUNET_assert (NULL != wa_head);
+ if (NULL == ai)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No accounts enabled for credit!\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -368,449 +371,398 @@ exchange_serve_process_config (void)
/**
* Lock a shard and then begin to query for incoming wire transfers.
*
- * @param cls a `struct WireAccount` to operate on
+ * @param cls NULL
*/
static void
lock_shard (void *cls);
/**
- * Continue with the credit history of the shard
- * reserved as @a wa.
+ * Continue with the credit history of the shard.
*
- * @param[in,out] cls `struct WireAccount *` account with shard to continue processing
+ * @param cls NULL
*/
static void
continue_with_shard (void *cls);
/**
- * We encountered a serialization error.
- * Rollback the transaction and try again
- *
- * @param wa account we are transacting on
+ * We encountered a serialization error. Rollback the transaction and try
+ * again.
*/
static void
-handle_soft_error (struct WireAccount *wa)
+handle_soft_error (void)
{
db_plugin->rollback (db_plugin->cls);
- wa->started_transaction = false;
- if (1 < wa->batch_size)
+ started_transaction = false;
+ if (1 < batch_size)
{
- wa->batch_thresh = wa->batch_size;
- wa->batch_size /= 2;
+ batch_thresh = batch_size;
+ batch_size /= 2;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Reduced batch size to %llu due to serialization issue\n",
- (unsigned long long) wa->batch_size);
+ (unsigned long long) batch_size);
}
/* Reset to beginning of transaction, and go again
from there. */
- wa->latest_row_off = wa->batch_start;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Encountered soft error, resetting start point to batch start\n");
+ latest_row_off = batch_start;
GNUNET_assert (NULL == task);
task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
- wa);
+ NULL);
}
/**
- * Schedule the #lock_shard() operation for
- * @a wa. If @a wa is NULL, start with #wa_head.
- *
- * @param wa account to schedule #lock_shard() for,
- * possibly NULL (!).
+ * Schedule the #lock_shard() operation.
*/
static void
-schedule_transfers (struct WireAccount *wa)
+schedule_transfers (void)
{
- if (NULL == wa)
- {
- wa = wa_head;
- GNUNET_assert (NULL != wa);
- }
- if (wa->shard_open)
+ if (shard_open)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Will retry my shard (%llu,%llu] of %s in %s\n",
- (unsigned long long) wa->shard_start,
- (unsigned long long) wa->shard_end,
- wa->job_name,
+ (unsigned long long) shard_start,
+ (unsigned long long) shard_end,
+ job_name,
GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_remaining (wa->delayed_until),
- GNUNET_YES));
+ GNUNET_TIME_absolute_get_remaining (delayed_until),
+ true));
else
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Will try to lock next shard of %s in %s\n",
- wa->job_name,
+ job_name,
GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_remaining (wa->delayed_until),
- GNUNET_YES));
+ GNUNET_TIME_absolute_get_remaining (delayed_until),
+ true));
GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_at (wa->delayed_until,
+ task = GNUNET_SCHEDULER_add_at (delayed_until,
&lock_shard,
- wa);
+ NULL);
}
/**
- * We are done with the work that is possible on @a wa right now (and the
- * transaction was committed, if there was one to commit). Move on to the next
- * account.
- *
- * @param wa wire account for which we completed a shard
+ * We are done with the work that is possible right now (and the transaction
+ * was committed, if there was one to commit). Move on to the next shard.
*/
static void
-account_completed (struct WireAccount *wa)
+transaction_completed (void)
{
- GNUNET_assert (! wa->started_transaction);
- if ( (wa->batch_start + wa->batch_size ==
- wa->latest_row_off) &&
- (wa->batch_size < MAXIMUM_BATCH_SIZE) )
+ if ( (batch_start + batch_size ==
+ latest_row_off) &&
+ (batch_size < MAXIMUM_BATCH_SIZE) )
{
/* The current batch size worked without serialization
issues, and we are allowed to grow. Do so slowly. */
int delta;
- delta = ((int) wa->batch_thresh - (int) wa->batch_size) / 4;
+ delta = ((int) batch_thresh - (int) batch_size) / 4;
if (delta < 0)
delta = -delta;
- wa->batch_size = GNUNET_MIN (MAXIMUM_BATCH_SIZE,
- wa->batch_size + delta + 1);
+ batch_size = GNUNET_MIN (MAXIMUM_BATCH_SIZE,
+ batch_size + delta + 1);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Increasing batch size to %llu\n",
- (unsigned long long) wa->batch_size);
- }
-
- if (wa->delay)
- {
- /* This account was finished, block this one for the
- #wirewatch_idle_sleep_interval and move on to the next one. */
- wa->delayed_until
- = GNUNET_TIME_relative_to_absolute (wirewatch_idle_sleep_interval);
- wa = wa->next;
+ (unsigned long long) batch_size);
}
- GNUNET_assert (NULL == task);
- schedule_transfers (wa);
-}
-
-
-/**
- * Check if we are finished with the current shard. If so, update the
- * database, marking the shard as finished.
- *
- * @param wa wire account to commit for
- * @return true if we were indeed done with the shard
- */
-static bool
-check_shard_done (struct WireAccount *wa)
-{
- enum GNUNET_DB_QueryStatus qs;
- if (wa->shard_end > wa->latest_row_off)
+ if ( (! progress) && test_mode)
{
+ /* Transaction list was drained and we are in
+ test mode. So we are done. */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Shard %s (%llu,%llu] at %llu\n",
- wa->job_name,
- (unsigned long long) wa->shard_start,
- (unsigned long long) wa->shard_end,
- (unsigned long long) wa->latest_row_off);
- return false; /* actually, not done! */
+ "Transaction list drained and in test mode. Exiting\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
}
- /* shard is complete, mark this as well */
- qs = db_plugin->complete_shard (db_plugin->cls,
- wa->job_name,
- wa->shard_start,
- wa->shard_end);
- switch (qs)
+ if (! (hh_returned_data || hh_account_404) )
{
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls);
- GNUNET_SCHEDULER_shutdown ();
- return false;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Got DB soft error for complete_shard. Rolling back.\n");
- handle_soft_error (wa);
- return false;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- GNUNET_break (0);
- /* Not expected, but let's just continue */
- break;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* normal case */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Completed shard %s (%llu,%llu] after %s\n",
- wa->job_name,
- (unsigned long long) wa->shard_start,
- (unsigned long long) wa->shard_end,
- GNUNET_STRINGS_relative_time_to_string (
- GNUNET_TIME_absolute_get_duration (wa->shard_start_time),
- GNUNET_YES));
- break;
+ /* Enforce long-polling delay even if the server ignored it
+ and returned earlier */
+ struct GNUNET_TIME_Relative latency;
+ struct GNUNET_TIME_Relative left;
+
+ latency = GNUNET_TIME_absolute_get_duration (hh_start_time);
+ left = GNUNET_TIME_relative_subtract (longpoll_timeout,
+ latency);
+ if (! (test_mode ||
+ GNUNET_TIME_relative_is_zero (left)) )
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Server did not respect long-polling, enforcing client-side by sleeping for %s\n",
+ GNUNET_TIME_relative2s (left,
+ true));
+ delayed_until = GNUNET_TIME_relative_to_absolute (left);
}
- return true;
+ if (hh_account_404)
+ delayed_until = GNUNET_TIME_relative_to_absolute (
+ GNUNET_TIME_UNIT_MILLISECONDS);
+ if (test_mode)
+ delayed_until = GNUNET_TIME_UNIT_ZERO_ABS;
+ GNUNET_assert (NULL == task);
+ schedule_transfers ();
}
/**
- * We are finished with the current transaction, try
- * to commit and then schedule the next iteration.
+ * We got incoming transaction details from the bank. Add them
+ * to the database.
*
- * @param wa wire account to commit for
+ * @param details array of transaction details
+ * @param details_length length of the @a details array
*/
static void
-do_commit (struct WireAccount *wa)
+process_reply (const struct TALER_BANK_CreditDetails *details,
+ unsigned int details_length)
{
enum GNUNET_DB_QueryStatus qs;
bool shard_done;
+ uint64_t lroff = latest_row_off;
- GNUNET_assert (NULL == task);
- shard_done = check_shard_done (wa);
- wa->started_transaction = false;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Committing %s progress (%llu,%llu] at %llu\n (%s)",
- wa->job_name,
- (unsigned long long) wa->shard_start,
- (unsigned long long) wa->shard_end,
- (unsigned long long) wa->latest_row_off,
- shard_done
- ? "shard done"
- : "shard incomplete");
- qs = db_plugin->commit (db_plugin->cls);
- switch (qs)
+ if (0 == details_length)
{
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- GNUNET_SCHEDULER_shutdown ();
- return;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- /* reduce transaction size to reduce rollback probability */
- handle_soft_error (wa);
+ /* Server should have used 204, not 200! */
+ GNUNET_break_op (0);
+ transaction_completed ();
return;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* normal case */
- break;
}
- if (shard_done)
- {
- wa->shard_delay = GNUNET_TIME_absolute_get_duration (wa->shard_start_time);
- wa->shard_open = false;
- account_completed (wa);
- }
- else
+ hh_returned_data = true;
+ /* check serial IDs for range constraints */
+ for (unsigned int i = 0; i<details_length; i++)
{
- task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
- wa);
- }
-}
-
-
-/**
- * Callbacks of this type are used to serve the result of asking
- * the bank for the transaction history.
- *
- * @param cls closure with the `struct WioreAccount *` we are processing
- * @param http_status HTTP status code from the server
- * @param ec taler error code
- * @param serial_id identification of the position at which we are querying
- * @param details details about the wire transfer
- * @param json raw JSON response
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
- */
-static enum GNUNET_GenericReturnValue
-history_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- const struct TALER_BANK_CreditDetails *details,
- const json_t *json)
-{
- struct WireAccount *wa = cls;
- enum GNUNET_DB_QueryStatus qs;
+ const struct TALER_BANK_CreditDetails *cd = &details[i];
- (void) json;
- GNUNET_assert (NULL == task);
- if (NULL == details)
- {
- wa->hh = NULL;
- if ( (! ( (MHD_HTTP_NOT_FOUND == http_status) &&
- (ignore_account_404) ) ) &&
- ( (MHD_HTTP_NO_CONTENT != http_status) &&
- ( (TALER_EC_NONE != ec) ||
- (MHD_HTTP_OK != http_status) ) ) )
+ if (cd->serial_id < lroff)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Error fetching history: %s (%u)\n",
- TALER_ErrorCode_get_hint (ec),
- http_status);
- if (! (exit_on_error || test_mode) )
- {
- account_completed (wa);
- return GNUNET_OK;
- }
+ "Serial ID %llu not monotonic (got %llu before). Failing!\n",
+ (unsigned long long) cd->serial_id,
+ (unsigned long long) lroff);
+ db_plugin->rollback (db_plugin->cls);
GNUNET_SCHEDULER_shutdown ();
- return GNUNET_OK;
+ return;
}
- if (wa->started_transaction)
+ if (cd->serial_id > shard_end)
{
+ /* we are *past* the current shard (likely because the serial_id of the
+ shard_end happens to not exist in the DB). So commit and stop this
+ iteration! */
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "End of list. Committing progress on %s of (%llu,%llu]!\n",
- wa->job_name,
- (unsigned long long) wa->batch_start,
- (unsigned long long) wa->latest_row_off);
- do_commit (wa);
- return GNUNET_OK; /* will be ignored anyway */
+ "Serial ID %llu past shard end at %llu, ending iteration early!\n",
+ (unsigned long long) cd->serial_id,
+ (unsigned long long) shard_end);
+ details_length = i;
+ progress = true;
+ lroff = cd->serial_id - 1;
+ break;
}
- /* We did not even start a transaction. */
- if ( (wa->delay) &&
- (test_mode) &&
- (NULL == wa->next) )
- {
- /* We exit on idle */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Shutdown due to test mode!\n");
- GNUNET_SCHEDULER_shutdown ();
- return GNUNET_OK;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No transactions in history response, moving on.\n");
- account_completed (wa);
- return GNUNET_OK; /* will be ignored anyway */
- }
-
- /* We did get 'details' from the bank. Do sanity checks before inserting. */
- if (serial_id < wa->latest_row_off)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Serial ID %llu not monotonic (got %llu before). Failing!\n",
- (unsigned long long) serial_id,
- (unsigned long long) wa->latest_row_off);
- GNUNET_SCHEDULER_shutdown ();
- wa->hh = NULL;
- return GNUNET_SYSERR;
+ lroff = cd->serial_id;
}
- /* If we got 'limit' transactions back from the bank,
- we should not introduce any delay before the next
- call. */
- if (serial_id >= wa->max_row_off)
- wa->delay = false;
- if (serial_id > wa->shard_end)
+ if (0 != details_length)
{
- /* we are *past* the current shard (likely because the serial_id of the
- shard_end happens to not exist in the DB). So commit and stop this
- iteration! */
+ enum GNUNET_DB_QueryStatus qss[details_length];
+ struct TALER_EXCHANGEDB_ReserveInInfo reserves[details_length];
+
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Serial ID %llu past shard end at %llu, ending iteration early!\n",
- (unsigned long long) serial_id,
- (unsigned long long) wa->shard_end);
- wa->latest_row_off = serial_id - 1; /* excluding serial_id! */
- wa->hh = NULL;
- if (wa->started_transaction)
+ "Importing %u transactions\n",
+ details_length);
+ for (unsigned int i = 0; i<details_length; i++)
{
- GNUNET_assert (NULL == task);
- do_commit (wa);
+ const struct TALER_BANK_CreditDetails *cd = &details[i];
+ struct TALER_EXCHANGEDB_ReserveInInfo *res = &reserves[i];
+
+ res->reserve_pub = &cd->reserve_pub;
+ res->balance = &cd->amount;
+ res->execution_time = cd->execution_date;
+ res->sender_account_details = cd->debit_account_uri;
+ res->exchange_account_name = ai->section_name;
+ res->wire_reference = cd->serial_id;
}
- else
+ qs = db_plugin->reserves_in_insert (db_plugin->cls,
+ reserves,
+ details_length,
+ qss);
+ switch (qs)
{
- GNUNET_assert (NULL == task);
- if (check_shard_done (wa))
- account_completed (wa);
- else
- task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
- wa);
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got DB soft error for reserves_in_insert (%u). Rolling back.\n",
+ details_length);
+ handle_soft_error ();
+ return;
+ default:
+ break;
+ }
+ for (unsigned int i = 0; i<details_length; i++)
+ {
+ const struct TALER_BANK_CreditDetails *cd = &details[i];
+
+ switch (qss[i])
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got DB soft error for batch_reserves_in_insert(%u). Rolling back.\n",
+ i);
+ handle_soft_error ();
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* Either wirewatch was freshly started after the system was
+ shutdown and we're going over an incomplete shard again
+ after being restarted, or the shard lock period was too
+ short (number of workers set incorrectly?) and a 2nd
+ wirewatcher has been stealing our work while we are still
+ at it. */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Attempted to import transaction %llu (%s) twice. "
+ "This should happen rarely (if not, ask for support).\n",
+ (unsigned long long) cd->serial_id,
+ job_name);
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Imported transaction %llu.\n",
+ (unsigned long long) cd->serial_id);
+ /* normal case */
+ progress = true;
+ break;
+ }
}
- return GNUNET_SYSERR;
}
- if (! wa->started_transaction)
+
+ latest_row_off = lroff;
+ shard_done = (shard_end <= latest_row_off);
+ if (shard_done)
{
- if (GNUNET_OK !=
- db_plugin->start_read_committed (db_plugin->cls,
- "wirewatch check for incoming wire transfers"))
+ /* shard is complete, mark this as well */
+ qs = db_plugin->complete_shard (db_plugin->cls,
+ job_name,
+ shard_start,
+ shard_end);
+ switch (qs)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to start database transaction!\n");
- global_ret = EXIT_FAILURE;
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
- wa->hh = NULL;
- return GNUNET_SYSERR;
+ return;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Got DB soft error for complete_shard. Rolling back.\n");
+ handle_soft_error ();
+ return;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0);
+ /* Not expected, but let's just continue */
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* normal case */
+ progress = true;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Completed shard %s (%llu,%llu] after %s\n",
+ job_name,
+ (unsigned long long) shard_start,
+ (unsigned long long) shard_end,
+ GNUNET_STRINGS_relative_time_to_string (
+ GNUNET_TIME_absolute_get_duration (shard_start_time),
+ true));
+ break;
}
- wa->started_transaction = true;
+ shard_delay = GNUNET_TIME_absolute_get_duration (shard_start_time);
+ shard_open = false;
+ transaction_completed ();
+ return;
}
+ GNUNET_assert (NULL == task);
+ task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
+ NULL);
+}
+
+
+/**
+ * Callbacks of this type are used to serve the result of asking
+ * the bank for the transaction history.
+ *
+ * @param cls NULL
+ * @param reply response we got from the bank
+ */
+static void
+history_cb (void *cls,
+ const struct TALER_BANK_CreditHistoryResponse *reply)
+{
+ (void) cls;
+ GNUNET_assert (NULL == task);
+ hh = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Adding wire transfer over %s with (hashed) subject `%s'\n",
- TALER_amount2s (&details->amount),
- TALER_B2S (&details->reserve_pub));
- /* FIXME-PERFORMANCE: Consider using Postgres multi-valued insert here,
- for up to 15x speed-up according to
- https://dba.stackexchange.com/questions/224989/multi-row-insert-vs-transactional-single-row-inserts#225006
- (Note: this may require changing both the
- plugin API as well as modifying how this function is called.) */
- qs = db_plugin->reserves_in_insert (db_plugin->cls,
- &details->reserve_pub,
- &details->amount,
- details->execution_date,
- details->debit_account_uri,
- wa->ai->section_name,
- serial_id);
- switch (qs)
+ "History request returned with HTTP status %u\n",
+ reply->http_status);
+ switch (reply->http_status)
{
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- db_plugin->rollback (db_plugin->cls);
- wa->started_transaction = false;
- GNUNET_SCHEDULER_shutdown ();
- wa->hh = NULL;
- return GNUNET_SYSERR;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Got DB soft error for reserves_in_insert. Rolling back.\n");
- handle_soft_error (wa);
- wa->hh = NULL;
- return GNUNET_SYSERR;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* Either wirewatch was freshly started after the system was
- shutdown and we're going over an incomplete shard again
- after being restarted, or the shard lock period was too
- short (number of workers set incorrectly?) and a 2nd
- wirewatcher has been stealing our work while we are still
- at it. */
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Attempted to import transaction %llu (%s) twice. "
- "This should happen rarely (if not, ask for support).\n",
- (unsigned long long) serial_id,
- wa->job_name);
- /* already existed, ok, let's just continue */
+ case MHD_HTTP_OK:
+ process_reply (reply->details.ok.details,
+ reply->details.ok.details_length);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ transaction_completed ();
+ return;
+ case MHD_HTTP_NOT_FOUND:
+ hh_account_404 = true;
+ if (ignore_account_404)
+ {
+ transaction_completed ();
+ return;
+ }
break;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* normal case */
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error fetching history: %s (%u)\n",
+ TALER_ErrorCode_get_hint (reply->ec),
+ reply->http_status);
break;
}
- wa->latest_row_off = serial_id;
- return GNUNET_OK;
+ if (! exit_on_error)
+ {
+ transaction_completed ();
+ return;
+ }
+ GNUNET_SCHEDULER_shutdown ();
}
static void
continue_with_shard (void *cls)
{
- struct WireAccount *wa = cls;
unsigned int limit;
+ (void) cls;
task = NULL;
- limit = GNUNET_MIN (wa->batch_size,
- wa->shard_end - wa->latest_row_off);
- wa->max_row_off = wa->latest_row_off + limit;
- GNUNET_assert (NULL == wa->hh);
- wa->hh = TALER_BANK_credit_history (ctx,
- wa->ai->auth,
- wa->latest_row_off,
- limit,
- test_mode
- ? GNUNET_TIME_UNIT_ZERO
- : LONGPOLL_TIMEOUT,
- &history_cb,
- wa);
- if (NULL == wa->hh)
+ GNUNET_assert (shard_end > latest_row_off);
+ limit = GNUNET_MIN (batch_size,
+ shard_end - latest_row_off);
+ GNUNET_assert (NULL == hh);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting credit history starting from %llu\n",
+ (unsigned long long) latest_row_off);
+ hh_start_time = GNUNET_TIME_absolute_get ();
+ hh_returned_data = false;
+ hh_account_404 = false;
+ hh = TALER_BANK_credit_history (ctx,
+ ai->auth,
+ latest_row_off,
+ limit,
+ test_mode
+ ? GNUNET_TIME_UNIT_ZERO
+ : longpoll_timeout,
+ &history_cb,
+ NULL);
+ if (NULL == hh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to start request for account history!\n");
@@ -821,13 +773,20 @@ continue_with_shard (void *cls)
}
+/**
+ * Reserve a shard for us to work on.
+ *
+ * @param cls NULL
+ */
static void
lock_shard (void *cls)
{
- struct WireAccount *wa = cls;
enum GNUNET_DB_QueryStatus qs;
struct GNUNET_TIME_Relative delay;
+ uint64_t last_shard_start = shard_start;
+ uint64_t last_shard_end = shard_end;
+ (void) cls;
task = NULL;
if (GNUNET_SYSERR ==
db_plugin->preflight (db_plugin->cls))
@@ -838,17 +797,16 @@ lock_shard (void *cls)
GNUNET_SCHEDULER_shutdown ();
return;
}
- if ( (wa->shard_open) &&
- (GNUNET_TIME_absolute_is_future (wa->shard_end_time)) )
+ if ( (shard_open) &&
+ (GNUNET_TIME_absolute_is_future (shard_end_time)) )
{
- wa->delay = true; /* default is to delay, unless
- we find out that we're really busy */
- wa->batch_start = wa->latest_row_off;
+ progress = false;
+ batch_start = latest_row_off;
task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
- wa);
+ NULL);
return;
}
- if (wa->shard_open)
+ if (shard_open)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shard not completed in time, will try to re-acquire\n");
/* How long we lock a shard depends on the number of
@@ -861,15 +819,15 @@ lock_shard (void *cls)
GNUNET_CRYPTO_QUALITY_WEAK,
4 * GNUNET_TIME_relative_max (
wirewatch_idle_sleep_interval,
- GNUNET_TIME_relative_multiply (wa->shard_delay,
+ GNUNET_TIME_relative_multiply (shard_delay,
max_workers)).rel_value_us);
- wa->shard_start_time = GNUNET_TIME_absolute_get ();
+ shard_start_time = GNUNET_TIME_absolute_get ();
qs = db_plugin->begin_shard (db_plugin->cls,
- wa->job_name,
+ job_name,
delay,
shard_size,
- &wa->shard_start,
- &wa->shard_end);
+ &shard_start,
+ &shard_end);
switch (qs)
{
case GNUNET_DB_STATUS_HARD_ERROR:
@@ -883,49 +841,78 @@ lock_shard (void *cls)
{
struct GNUNET_TIME_Relative rdelay;
- rdelay = GNUNET_TIME_randomize (wirewatch_idle_sleep_interval);
+ wirewatch_conflict_sleep_interval
+ = GNUNET_TIME_STD_BACKOFF (wirewatch_conflict_sleep_interval);
+ rdelay = GNUNET_TIME_randomize (wirewatch_conflict_sleep_interval);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Serialization error tying to obtain shard %s, will try again in %s!\n",
- wa->job_name,
+ job_name,
GNUNET_STRINGS_relative_time_to_string (rdelay,
- GNUNET_YES));
- wa->delayed_until = GNUNET_TIME_relative_to_absolute (rdelay);
+ true));
+#if 1
+ if (GNUNET_TIME_relative_cmp (rdelay,
+ >,
+ GNUNET_TIME_UNIT_SECONDS))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Delay would have been for %s\n",
+ GNUNET_TIME_relative2s (rdelay,
+ true));
+ rdelay = GNUNET_TIME_relative_min (rdelay,
+ GNUNET_TIME_UNIT_SECONDS);
+#endif
+ delayed_until = GNUNET_TIME_relative_to_absolute (rdelay);
}
GNUNET_assert (NULL == task);
- schedule_transfers (wa->next);
+ schedule_transfers ();
return;
case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"No shard available, will try again for %s in %s!\n",
- wa->job_name,
+ job_name,
GNUNET_STRINGS_relative_time_to_string (
wirewatch_idle_sleep_interval,
- GNUNET_YES));
- wa->delayed_until = GNUNET_TIME_relative_to_absolute (
+ true));
+ delayed_until = GNUNET_TIME_relative_to_absolute (
wirewatch_idle_sleep_interval);
+ shard_open = false;
GNUNET_assert (NULL == task);
- schedule_transfers (wa->next);
+ schedule_transfers ();
return;
case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
/* continued below */
+ wirewatch_conflict_sleep_interval = GNUNET_TIME_UNIT_ZERO;
break;
}
- wa->shard_end_time = GNUNET_TIME_relative_to_absolute (delay);
- wa->shard_open = true;
+ shard_end_time = GNUNET_TIME_relative_to_absolute (delay);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Starting with shard %s at (%llu,%llu] locked for %s\n",
- wa->job_name,
- (unsigned long long) wa->shard_start,
- (unsigned long long) wa->shard_end,
+ job_name,
+ (unsigned long long) shard_start,
+ (unsigned long long) shard_end,
GNUNET_STRINGS_relative_time_to_string (delay,
- GNUNET_YES));
- wa->delay = true; /* default is to delay, unless
- we find out that we're really busy */
- wa->batch_start = wa->shard_start;
- wa->latest_row_off = wa->batch_start;
+ true));
+ progress = false;
+ batch_start = shard_start;
+ if ( (shard_open) &&
+ (shard_start == last_shard_start) &&
+ (shard_end == last_shard_end) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Continuing from %llu\n",
+ (unsigned long long) latest_row_off);
+ GNUNET_break (latest_row_off >= batch_start); /* resume where we left things */
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Resetting shard start to original start point (%d)\n",
+ shard_open ? 1 : 0);
+ latest_row_off = batch_start;
+ }
+ shard_open = true;
task = GNUNET_SCHEDULER_add_now (&continue_with_shard,
- wa);
+ NULL);
}
@@ -948,26 +935,26 @@ run (void *cls,
(void) cfgfile;
cfg = c;
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+ cls);
if (GNUNET_OK !=
exchange_serve_process_config ())
{
global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
return;
}
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- cls);
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
&rc);
if (NULL == ctx)
{
GNUNET_break (0);
GNUNET_SCHEDULER_shutdown ();
+ global_ret = EXIT_NO_RESTART;
return;
}
rc = GNUNET_CURL_gnunet_rc_create (ctx);
- GNUNET_assert (NULL == task);
- task = GNUNET_SCHEDULER_add_now (&lock_shard,
- wa_head);
+ schedule_transfers ();
}
@@ -983,10 +970,20 @@ main (int argc,
char *const *argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('a',
+ "account",
+ "SECTION_NAME",
+ "name of the configuration section with the account we should watch (needed if more than one is enabled for crediting)",
+ &account_section),
GNUNET_GETOPT_option_flag ('e',
"exit-on-error",
"terminate wirewatch if we failed to download information from the bank",
&exit_on_error),
+ GNUNET_GETOPT_option_relative_time ('f',
+ "longpoll-timeout",
+ "DELAY",
+ "what is the timeout when asking the bank about new transactions, specify with unit (e.g. --longpoll-timeout=30s)",
+ &longpoll_timeout),
GNUNET_GETOPT_option_flag ('I',
"ignore-not-found",
"continue, even if the bank account of the exchange was not found",
@@ -1012,6 +1009,7 @@ main (int argc,
};
enum GNUNET_GenericReturnValue ret;
+ longpoll_timeout = LONGPOLL_TIMEOUT;
if (GNUNET_OK !=
GNUNET_STRINGS_get_utf8_args (argc, argv,
&argc, &argv))
diff --git a/src/exchange/test_taler_exchange_httpd.conf b/src/exchange/test_taler_exchange_httpd.conf
index 9bd4851fb..7e7ff8b45 100644
--- a/src/exchange/test_taler_exchange_httpd.conf
+++ b/src/exchange/test_taler_exchange_httpd.conf
@@ -13,6 +13,8 @@ TINY_AMOUNT = EUR:0.01
[exchange]
+AML_THRESHOLD = EUR:1000000
+
# Directory with our terms of service.
TERMS_DIR = ../../contrib/tos
@@ -67,7 +69,7 @@ ENABLE_CREDIT = YES
WIRE_GATEWAY_AUTH_METHOD = basic
USERNAME = Exchange
PASSWORD = x
-WIRE_GATEWAY_URL = "http://localhost:8082/3/"
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/3/taler-wire-gateway/"
# Coins for the tests.
[coin_eur_ct_1_rsa]
diff --git a/src/exchange/test_taler_exchange_httpd.sh b/src/exchange/test_taler_exchange_httpd.sh
index e8dc46af8..0fe71f3ad 100755
--- a/src/exchange/test_taler_exchange_httpd.sh
+++ b/src/exchange/test_taler_exchange_httpd.sh
@@ -1,7 +1,7 @@
#!/bin/bash
#
# This file is part of TALER
-# Copyright (C) 2015-2020 Taler Systems SA
+# Copyright (C) 2015-2020, 2023 Taler Systems SA
#
# TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free Software
@@ -23,6 +23,8 @@
# Clear environment from variables that override config.
unset XDG_DATA_HOME
unset XDG_CONFIG_HOME
+
+set -eu
#
echo -n "Launching exchange ..."
PREFIX=
@@ -30,7 +32,7 @@ PREFIX=
#PREFIX="valgrind --leak-check=yes --track-fds=yes --error-exitcode=1 --log-file=valgrind.%p"
# Setup database
-taler-exchange-dbinit -c test_taler_exchange_httpd.conf &> /dev/null
+taler-exchange-dbinit -c test_taler_exchange_httpd.conf &> /dev/null || exit 77
# Run Exchange HTTPD (in background)
$PREFIX taler-exchange-httpd -c test_taler_exchange_httpd.conf 2> test-exchange.log &
diff --git a/src/exchangedb/.gitignore b/src/exchangedb/.gitignore
index 881bbe53d..6e67fadb1 100644
--- a/src/exchangedb/.gitignore
+++ b/src/exchangedb/.gitignore
@@ -1,12 +1,16 @@
-test-exchangedb-auditors
-test-exchangedb-denomkeys
-test-exchangedb-fees
test-exchangedb-postgres
-test-exchangedb-signkeys
-test-perf-taler-exchangedb
bench-db-postgres
-exchange-0001.sql
-shard-0000.sql
-shard-0001.sql
-drop0001.sql
-shard-drop0001.sql \ No newline at end of file
+perf_deposits_get_ready-postgres
+perf_get_link_data-postgres
+perf_reserves_in_insert-postgres
+perf_select_refunds_by_coin-postgres
+exchange-0002.sql
+procedures.sql
+exchange-0003.sql
+perf-exchangedb-reserves-in-insert-postgres
+test-exchangedb-batch-reserves-in-insert-postgres
+test-exchangedb-by-j-postgres
+test-exchangedb-populate-link-data-postgres
+test-exchangedb-populate-ready-deposit-postgres
+test-exchangedb-populate-select-refunds-by-coin-postgres
+exchange-0004.sql
diff --git a/src/exchangedb/0002-account_merges.sql b/src/exchangedb/0002-account_merges.sql
new file mode 100644
index 000000000..1dd7e5bf0
--- /dev/null
+++ b/src/exchangedb/0002-account_merges.sql
@@ -0,0 +1,139 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_account_merges(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'account_merges';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I '
+ '(account_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',wallet_h_payto BYTEA NOT NULL CHECK (LENGTH(wallet_h_payto)=32)'
+ ',PRIMARY KEY (purse_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Merge requests where a purse- and account-owner requested merging the purse into the account'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the target reserve'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'signature by the reserve private key affirming the merge, of type TALER_SIGNATURE_WALLET_ACCOUNT_MERGE'
+ ,'reserve_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_account_merges(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'account_merges';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ -- Note: this index *may* be useful in
+ -- pg_get_reserve_history depending on how
+ -- smart the DB is when computing the JOIN.
+ -- Removing it MAY boost performance slightly, at
+ -- the expense of trouble if the "merge_by_reserve"
+ -- query planner goes off the rails. Needs benchmarking
+ -- to be sure.
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve_pub '
+ 'ON ' || table_name || ' '
+ '(reserve_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_account_merge_request_serial_id_key'
+ ' UNIQUE (account_merge_request_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_account_merges()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'account_merges';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub) '
+ ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_purse_pub'
+ ' FOREIGN KEY (purse_pub) '
+ ' REFERENCES purse_requests (purse_pub)'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('account_merges'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('account_merges'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('account_merges'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-age_withdraw.sql b/src/exchangedb/0002-age_withdraw.sql
new file mode 100644
index 000000000..87cac7816
--- /dev/null
+++ b/src/exchangedb/0002-age_withdraw.sql
@@ -0,0 +1,157 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author Özgür Kesim
+
+CREATE FUNCTION create_table_age_withdraw(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'age_withdraw';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(age_withdraw_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_commitment BYTEA NOT NULL CONSTRAINT h_commitment_length CHECK(LENGTH(h_commitment)=64)'
+ ',max_age SMALLINT NOT NULL CONSTRAINT max_age_positive CHECK(max_age>=0)'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',reserve_pub BYTEA NOT NULL CONSTRAINT reserve_pub_length CHECK(LENGTH(reserve_pub)=32)'
+ ',reserve_sig BYTEA NOT NULL CONSTRAINT reserve_sig_length CHECK(LENGTH(reserve_sig)=64)'
+ ',noreveal_index SMALLINT NOT NULL CONSTRAINT noreveal_index_positive CHECK(noreveal_index>=0)'
+ ',h_blind_evs BYTEA[] NOT NULL CONSTRAINT h_blind_evs_length CHECK(cardinality(h_blind_evs)=cardinality(denom_serials))'
+ ',denom_serials INT8[] NOT NULL CONSTRAINT denom_serials_array_length CHECK(cardinality(denom_serials)=cardinality(denom_sigs))'
+ ',denom_sigs BYTEA[] NOT NULL CONSTRAINT denom_sigs_array_length CHECK(cardinality(denom_sigs)=cardinality(denom_serials))'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Commitments made when withdrawing coins with age restriction and the gamma value chosen by the exchange. '
+ 'It also contains the blindly signed coins, their signatures and denominations.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The gamma value chosen by the exchange in the cut-and-choose protocol'
+ ,'noreveal_index'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The maximum age (in years) that the client commits to with this request'
+ ,'max_age'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol'
+ ,'h_commitment'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Reference to the public key of the reserve from which the coins are going to be withdrawn'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature of the reserve''s private key over the age-withdraw request'
+ ,'reserve_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Array of references to the denominations'
+ ,'denom_serials'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Array of the blinded envelopes of the chosen fresh coins, with value as given by the denomination in the corresponding slot in denom_serials'
+ ,'h_blind_evs'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Array of signatures over each blinded envelope'
+ ,'denom_sigs'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_age_withdraw(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'age_withdraw';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD PRIMARY KEY (h_commitment);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_h_commitment_reserve_pub_key'
+ ' UNIQUE (h_commitment, reserve_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_age_withdraw_id_key'
+ ' UNIQUE (age_withdraw_id);'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_age_withdraw()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'age_withdraw';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub)'
+ ' REFERENCES reserves(reserve_pub) ON DELETE CASCADE;'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+VALUES
+ ('age_withdraw', 'exchange-0002', 'create', TRUE ,FALSE),
+ ('age_withdraw', 'exchange-0002', 'constrain',TRUE ,FALSE),
+ ('age_withdraw', 'exchange-0002', 'foreign', TRUE ,FALSE);
+
diff --git a/src/exchangedb/0002-aggregation_tracking.sql b/src/exchangedb/0002-aggregation_tracking.sql
new file mode 100644
index 000000000..d07960247
--- /dev/null
+++ b/src/exchangedb/0002-aggregation_tracking.sql
@@ -0,0 +1,118 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_aggregation_tracking(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aggregation_tracking';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(aggregation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',batch_deposit_serial_id INT8 PRIMARY KEY'
+ ',wtid_raw BYTEA NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (batch_deposit_serial_id)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'mapping from wire transfer identifiers (WTID) to deposits (and back)'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'identifier of the wire transfer'
+ ,'wtid_raw'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_aggregation_tracking(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aggregation_tracking';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_wtid_raw_index '
+ 'ON ' || table_name || ' '
+ '(wtid_raw);'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_wtid_raw_index '
+ 'IS ' || quote_literal('for lookup_transactions') || ';'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_aggregation_serial_id_key'
+ ' UNIQUE (aggregation_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_aggregation_tracking()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aggregation_tracking';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_deposit'
+ ' FOREIGN KEY (batch_deposit_serial_id)'
+ ' REFERENCES batch_deposits (batch_deposit_serial_id)'
+ ' ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('aggregation_tracking'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('aggregation_tracking'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('aggregation_tracking'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-aggregation_transient.sql b/src/exchangedb/0002-aggregation_transient.sql
new file mode 100644
index 000000000..8e46450f0
--- /dev/null
+++ b/src/exchangedb/0002-aggregation_transient.sql
@@ -0,0 +1,71 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_aggregation_transient(
+ IN shard_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aggregation_transient';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(amount taler_amount NOT NULL'
+ ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
+ ',merchant_pub BYTEA CHECK (LENGTH(merchant_pub)=32)'
+ ',exchange_account_section TEXT NOT NULL'
+ ',legitimization_requirement_serial_id INT8 NOT NULL DEFAULT(0)'
+ ',wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=32)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (wire_target_h_payto)'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'aggregations currently happening (lacking wire_out, usually because the amount is too low); this table is not replicated'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Sum of all of the aggregated deposits (without deposit fees)'
+ ,'amount'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'identifier of the wire transfer'
+ ,'wtid_raw'
+ ,table_name
+ ,shard_suffix
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('aggregation_transient'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-aml_history.sql b/src/exchangedb/0002-aml_history.sql
new file mode 100644
index 000000000..af81be9d8
--- /dev/null
+++ b/src/exchangedb/0002-aml_history.sql
@@ -0,0 +1,147 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION create_table_aml_history(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aml_history';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(aml_history_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA CHECK (LENGTH(h_payto)=32)'
+ ',new_threshold taler_amount NOT NULL DEFAULT(0,0)'
+ ',new_status INT4 NOT NULL DEFAULT(0)'
+ ',decision_time INT8 NOT NULL DEFAULT(0)'
+ ',justification TEXT NOT NULL'
+ ',kyc_requirements TEXT'
+ ',kyc_req_row INT8 NOT NULL DEFAULT(0)'
+ ',decider_pub BYTEA CHECK (LENGTH(decider_pub)=32)'
+ ',decider_sig BYTEA CHECK (LENGTH(decider_sig)=64)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'AML decision history for a particular payment destination'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of the payto://-URI this AML history is about'
+ ,'h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'new monthly inbound transaction limit below which we are OK'
+ ,'new_threshold'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ '0 for all OK, 1 for AML decision required, 2 for account is frozen (prevents further transactions)'
+ ,'new_status'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'when was the status changed'
+ ,'decision_time'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'human-readable justification for the status change'
+ ,'justification'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the staff member who made the AML decision'
+ ,'decider_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Additional KYC requirements imposed by the AML staff member. Serialized JSON array of strings.'
+ ,'kyc_requirements'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Row in the KYC table for this KYC requirement, 0 for none.'
+ ,'kyc_req_row'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature key of the staff member affirming the AML decision; of type AML_DECISION'
+ ,'decider_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+COMMENT ON FUNCTION create_table_aml_history
+ IS 'Creates the aml_history table';
+
+
+CREATE OR REPLACE FUNCTION constrain_table_aml_history(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aml_history';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_serial_key '
+ 'UNIQUE (aml_history_serial_id)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_main_index '
+ 'ON ' || table_name || ' '
+ '(h_payto, decision_time DESC);'
+ );
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('aml_history'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('aml_history'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-aml_staff.sql b/src/exchangedb/0002-aml_staff.sql
new file mode 100644
index 000000000..cec18c62b
--- /dev/null
+++ b/src/exchangedb/0002-aml_staff.sql
@@ -0,0 +1,40 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE TABLE aml_staff
+ (aml_staff_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,decider_pub BYTEA PRIMARY KEY CHECK (LENGTH(decider_pub)=32)
+ ,master_sig BYTEA CHECK (LENGTH(master_sig)=64)
+ ,decider_name TEXT NOT NULL
+ ,is_active BOOLEAN NOT NULL
+ ,read_only BOOLEAN NOT NULL
+ ,last_change INT8 NOT NULL
+ );
+COMMENT ON TABLE aml_staff
+ IS 'Table with AML staff members the exchange uses or has used in the past. Entries never expire as we need to remember the last_change column indefinitely.';
+COMMENT ON COLUMN aml_staff.decider_pub
+ IS 'Public key of the AML staff member.';
+COMMENT ON COLUMN aml_staff.master_sig
+ IS 'The master public key signature on the AML staff member status, of type TALER_SIGNATURE_MASTER_AML_KEY.';
+COMMENT ON COLUMN aml_staff.decider_name
+ IS 'Name of the staff member.';
+COMMENT ON COLUMN aml_staff.is_active
+ IS 'true if we are currently supporting the use of this AML staff member.';
+COMMENT ON COLUMN aml_staff.is_active
+ IS 'true if the member has read-only access.';
+COMMENT ON COLUMN aml_staff.last_change
+ IS 'Latest time when active status changed. Used to detect replays of old messages.';
diff --git a/src/exchangedb/0002-aml_status.sql b/src/exchangedb/0002-aml_status.sql
new file mode 100644
index 000000000..a8b567a82
--- /dev/null
+++ b/src/exchangedb/0002-aml_status.sql
@@ -0,0 +1,101 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION create_table_aml_status(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aml_status';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(aml_status_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=32)'
+ ',threshold taler_amount NOT NULL DEFAULT(0,0)'
+ ',status INT4 NOT NULL DEFAULT(0)'
+ ',kyc_requirement INT8 NOT NULL DEFAULT(0)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'AML status for a particular payment destination'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of the payto://-URI this AML status is about'
+ ,'h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'monthly inbound transaction limit below which we are OK (if status is 1)'
+ ,'threshold'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ '0 for all OK, 1 for AML decision required, 2 for account is frozen (prevents further transactions)'
+ ,'status'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+COMMENT ON FUNCTION create_table_aml_status
+ IS 'Creates the aml_status table';
+
+
+CREATE OR REPLACE FUNCTION constrain_table_aml_status(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'aml_status';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_serial_key '
+ 'UNIQUE (aml_status_serial_id)'
+ );
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('aml_status'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('aml_status'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-auditor_denom_sigs.sql b/src/exchangedb/0002-auditor_denom_sigs.sql
new file mode 100644
index 000000000..3ed645af5
--- /dev/null
+++ b/src/exchangedb/0002-auditor_denom_sigs.sql
@@ -0,0 +1,32 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE TABLE auditor_denom_sigs
+ (auditor_denom_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,auditor_uuid INT8 NOT NULL REFERENCES auditors (auditor_uuid) ON DELETE CASCADE
+ ,denominations_serial INT8 NOT NULL REFERENCES denominations (denominations_serial) ON DELETE CASCADE
+ ,auditor_sig BYTEA CHECK (LENGTH(auditor_sig)=64)
+ ,PRIMARY KEY (denominations_serial, auditor_uuid)
+ );
+COMMENT ON TABLE auditor_denom_sigs
+ IS 'Table with auditor signatures on exchange denomination keys.';
+COMMENT ON COLUMN auditor_denom_sigs.auditor_uuid
+ IS 'Identifies the auditor.';
+COMMENT ON COLUMN auditor_denom_sigs.denominations_serial
+ IS 'Denomination the signature is for.';
+COMMENT ON COLUMN auditor_denom_sigs.auditor_sig
+ IS 'Signature of the auditor, of purpose TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS.';
diff --git a/src/exchangedb/0002-auditors.sql b/src/exchangedb/0002-auditors.sql
new file mode 100644
index 000000000..76e43b183
--- /dev/null
+++ b/src/exchangedb/0002-auditors.sql
@@ -0,0 +1,35 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE TABLE auditors
+ (auditor_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,auditor_pub BYTEA PRIMARY KEY CHECK (LENGTH(auditor_pub)=32)
+ ,auditor_name TEXT NOT NULL
+ ,auditor_url TEXT NOT NULL
+ ,is_active BOOLEAN NOT NULL
+ ,last_change INT8 NOT NULL
+ );
+COMMENT ON TABLE auditors
+ IS 'Table with auditors the exchange uses or has used in the past. Entries never expire as we need to remember the last_change column indefinitely.';
+COMMENT ON COLUMN auditors.auditor_pub
+ IS 'Public key of the auditor.';
+COMMENT ON COLUMN auditors.auditor_url
+ IS 'The base URL of the auditor.';
+COMMENT ON COLUMN auditors.is_active
+ IS 'true if we are currently supporting the use of this auditor.';
+COMMENT ON COLUMN auditors.last_change
+ IS 'Latest time when active status changed. Used to detect replays of old messages.';
diff --git a/src/exchangedb/0002-batch_deposits.sql b/src/exchangedb/0002-batch_deposits.sql
new file mode 100644
index 000000000..71a4b4205
--- /dev/null
+++ b/src/exchangedb/0002-batch_deposits.sql
@@ -0,0 +1,172 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_batch_deposits(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'batch_deposits';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(batch_deposit_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
+ ',shard INT8 NOT NULL'
+ ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
+ ',wallet_timestamp INT8 NOT NULL'
+ ',exchange_timestamp INT8 NOT NULL'
+ ',refund_deadline INT8 NOT NULL'
+ ',wire_deadline INT8 NOT NULL'
+ ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
+ ',wallet_data_hash BYTEA CHECK (LENGTH(wallet_data_hash)=64) DEFAULT NULL'
+ ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)'
+ ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
+ ',policy_details_serial_id INT8'
+ ',policy_blocked BOOLEAN NOT NULL DEFAULT FALSE'
+ ',done BOOLEAN NOT NULL DEFAULT FALSE'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (shard)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Information about the contracts for which we have received (batch) deposits.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Used for load sharding in the materialized indices. Should be set based on merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.'
+ ,'shard'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Unsalted hash of the target bank account; also used to lookup the KYC status'
+ ,'wire_target_h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash over data provided by the wallet upon payment to select a more specific contract'
+ ,'wallet_data_hash'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Salt used when hashing the payto://-URI to get the h_wire that was used by the coin deposit signatures; not used to calculate wire_target_h_payto (as that one is unsalted)'
+ ,'wire_salt'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Set to TRUE once we have included this (batch) deposit (and all associated coins) in some aggregate wire transfer to the merchant'
+ ,'done'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'True if the aggregation of the (batch) deposit is currently blocked by some policy extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.'
+ ,'policy_blocked'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'References policy extensions table, NULL if extensions are not used'
+ ,'policy_details_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_batch_deposits(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'batch_deposits';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_batch_deposit_serial_id_pkey'
+ ' PRIMARY KEY (batch_deposit_serial_id) '
+ ',ADD CONSTRAINT ' || table_name || '_merchant_pub_h_contract_terms'
+ ' UNIQUE (shard, merchant_pub, h_contract_terms)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_ready '
+ 'ON ' || table_name || ' '
+ '(shard ASC'
+ ',wire_deadline ASC'
+ ') WHERE NOT (done OR policy_blocked);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_for_matching '
+ 'ON ' || table_name || ' '
+ '(shard ASC'
+ ',refund_deadline ASC'
+ ',wire_target_h_payto'
+ ') WHERE NOT (done OR policy_blocked);'
+ );
+END
+$$;
+
+CREATE OR REPLACE FUNCTION foreign_table_batch_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'batch_deposits';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_policy_details'
+ ' FOREIGN KEY (policy_details_serial_id) '
+ ' REFERENCES policy_details (policy_details_serial_id) ON DELETE RESTRICT'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('batch_deposits'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('batch_deposits'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('batch_deposits'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE)
+ ;
diff --git a/src/exchangedb/0002-close_requests.sql b/src/exchangedb/0002-close_requests.sql
new file mode 100644
index 000000000..6a7028095
--- /dev/null
+++ b/src/exchangedb/0002-close_requests.sql
@@ -0,0 +1,178 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_close_requests(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'close_requests';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(close_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
+ ',close_timestamp INT8 NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',close taler_amount NOT NULL'
+ ',close_fee taler_amount NOT NULL'
+ ',payto_uri TEXT NOT NULL'
+ ',done BOOL NOT NULL DEFAULT(FALSE)'
+ ',PRIMARY KEY (reserve_pub,close_timestamp)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Explicit requests by a reserve owner to close a reserve immediately'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'When the request was created by the client'
+ ,'close_timestamp'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature affirming that the reserve is to be closed'
+ ,'reserve_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Balance of the reserve at the time of closing, to be wired to the associated bank account (minus the closing fee)'
+ ,'close'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the credited bank account. Optional.'
+ ,'payto_uri'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_close_requests(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'close_requests';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_close_request_uuid_index '
+ 'ON ' || table_name || ' '
+ '(close_request_serial_id);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_close_request_done_index '
+ 'ON ' || table_name || ' '
+ '(done);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_close_request_uuid_pkey'
+ ' UNIQUE (close_request_serial_id)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_close_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'close_requests';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub) '
+ ' REFERENCES reserves(reserve_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION close_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'close_requests'
+ ,NEW.close_request_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION close_requests_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_close_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER close_requests_on_insert
+ AFTER INSERT
+ ON close_requests
+ FOR EACH ROW EXECUTE FUNCTION close_requests_insert_trigger();
+END $$;
+
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('close_requests'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('close_requests'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('close_requests'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('close_requests'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-coin_deposits.sql b/src/exchangedb/0002-coin_deposits.sql
new file mode 100644
index 000000000..c3eef6e5a
--- /dev/null
+++ b/src/exchangedb/0002-coin_deposits.sql
@@ -0,0 +1,157 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_coin_deposits(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_deposits';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(coin_deposit_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
+ ',batch_deposit_serial_id INT8 NOT NULL'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
+ ',amount_with_fee taler_amount NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Coins which have been deposited with the respective per-coin signatures.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Link to information about the batch deposit this coin was used for'
+ ,'batch_deposit_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_coin_deposits(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_deposits';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_coin_deposit_serial_id_pkey'
+ ' PRIMARY KEY (coin_deposit_serial_id) '
+ ',ADD CONSTRAINT ' || table_name || '_unique_coin_sig'
+ ' UNIQUE (coin_pub, coin_sig)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_batch '
+ 'ON ' || table_name || ' '
+ '(batch_deposit_serial_id);'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_coin_deposits()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_deposits';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_batch_deposits_id'
+ ' FOREIGN KEY (batch_deposit_serial_id) '
+ ' REFERENCES batch_deposits (batch_deposit_serial_id) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION coin_deposits_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'coin_deposits'
+ ,NEW.coin_deposit_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION coin_deposits_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_coin_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER coin_deposits_on_insert
+ AFTER INSERT
+ ON coin_deposits
+ FOR EACH ROW EXECUTE FUNCTION coin_deposits_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('coin_deposits'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('coin_deposits'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('coin_deposits'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('coin_deposits'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE)
+ ;
diff --git a/src/exchangedb/0002-coin_history.sql b/src/exchangedb/0002-coin_history.sql
new file mode 100644
index 000000000..9b5efdcb6
--- /dev/null
+++ b/src/exchangedb/0002-coin_history.sql
@@ -0,0 +1,138 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_coin_history (
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_history';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(coin_history_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',table_name TEXT NOT NULL'
+ ',serial_id INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Links to tables with entries that affected the transaction history of a coin.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'For which coin is this a history entry'
+ ,'coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'In which table is the history entry'
+ ,'table_name'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Which is the generated serial ID of the entry in the table'
+ ,'serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Monotonic counter, used to generate Etags for caching'
+ ,'coin_history_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_coin_history(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_history';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_coin_history_serial_id_pkey'
+ ' PRIMARY KEY (coin_history_serial_id) '
+ ',ADD CONSTRAINT ' || table_name || '_coin_entry_key'
+ ' UNIQUE (coin_pub, table_name, serial_id)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_coin_by_time'
+ ' ON ' || table_name || ' '
+ '(coin_pub'
+ ',coin_history_serial_id DESC'
+ ');'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_coin_history()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'coin_history';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('coin_history'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('coin_history'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('coin_history'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE)
+ ;
diff --git a/src/exchangedb/0002-contracts.sql b/src/exchangedb/0002-contracts.sql
new file mode 100644
index 000000000..c1f92c9aa
--- /dev/null
+++ b/src/exchangedb/0002-contracts.sql
@@ -0,0 +1,109 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_contracts(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'contracts';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(contract_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',pub_ckey BYTEA NOT NULL CHECK (LENGTH(pub_ckey)=32)'
+ ',contract_sig BYTEA NOT NULL CHECK (LENGTH(contract_sig)=64)'
+ ',e_contract BYTEA NOT NULL'
+ ',purse_expiration INT8 NOT NULL'
+ ',PRIMARY KEY (purse_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'encrypted contracts associated with purses'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the purse that the contract is associated with'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'signature over the encrypted contract by the purse contract key'
+ ,'contract_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public ECDH key used to encrypt the contract, to be used with the purse private key for decryption'
+ ,'pub_ckey'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'AES-GCM encrypted contract terms (contains gzip compressed JSON after decryption)'
+ ,'e_contract'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_contracts(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'contracts';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_contract_serial_id_key'
+ ' UNIQUE (contract_serial_id) '
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('contracts'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('contracts'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-cs_nonce_locks.sql b/src/exchangedb/0002-cs_nonce_locks.sql
new file mode 100644
index 000000000..36c0c7a5f
--- /dev/null
+++ b/src/exchangedb/0002-cs_nonce_locks.sql
@@ -0,0 +1,97 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_cs_nonce_locks(
+ partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)'
+ ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)'
+ ',max_denomination_serial INT8 NOT NULL'
+ ') %s ;'
+ ,'cs_nonce_locks'
+ ,'PARTITION BY HASH (nonce)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'ensures a Clause Schnorr client nonce is locked for use with an operation identified by a hash'
+ ,'cs_nonce_locks'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'actual nonce submitted by the client'
+ ,'nonce'
+ ,'cs_nonce_locks'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash (RC for refresh, blind coin hash for withdraw) the nonce may be used with'
+ ,'op_hash'
+ ,'cs_nonce_locks'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Maximum number of a CS denomination serial the nonce could be used with, for GC'
+ ,'max_denomination_serial'
+ ,'cs_nonce_locks'
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_cs_nonce_locks(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'cs_nonce_locks';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_cs_nonce_lock_serial_id_key'
+ ' UNIQUE (cs_nonce_lock_serial_id)'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('cs_nonce_locks'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('cs_nonce_locks'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-denomination_revocations.sql b/src/exchangedb/0002-denomination_revocations.sql
new file mode 100644
index 000000000..96e13cd15
--- /dev/null
+++ b/src/exchangedb/0002-denomination_revocations.sql
@@ -0,0 +1,23 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE IF NOT EXISTS denomination_revocations
+ (denom_revocations_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,denominations_serial INT8 PRIMARY KEY REFERENCES denominations (denominations_serial) ON DELETE CASCADE
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ );
+COMMENT ON TABLE denomination_revocations
+ IS 'remembering which denomination keys have been revoked';
diff --git a/src/exchangedb/0002-denominations.sql b/src/exchangedb/0002-denominations.sql
new file mode 100644
index 000000000..a3de2b149
--- /dev/null
+++ b/src/exchangedb/0002-denominations.sql
@@ -0,0 +1,45 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE denominations
+ (denominations_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
+ ,denom_type INT4 NOT NULL DEFAULT (1) -- 1 == RSA (for now, remove default later!)
+ ,age_mask INT4 NOT NULL DEFAULT (0)
+ ,denom_pub BYTEA NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,valid_from INT8 NOT NULL
+ ,expire_withdraw INT8 NOT NULL
+ ,expire_deposit INT8 NOT NULL
+ ,expire_legal INT8 NOT NULL
+ ,coin taler_amount NOT NULL
+ ,fee_withdraw taler_amount NOT NULL
+ ,fee_deposit taler_amount NOT NULL
+ ,fee_refresh taler_amount NOT NULL
+ ,fee_refund taler_amount NOT NULL
+ );
+COMMENT ON TABLE denominations
+ IS 'Main denominations table. All the valid denominations the exchange knows about.';
+COMMENT ON COLUMN denominations.denom_type
+ IS 'determines cipher type for blind signatures used with this denomination; 0 is for RSA';
+COMMENT ON COLUMN denominations.age_mask
+ IS 'bitmask with the age restrictions that are being used for this denomination; 0 if denomination does not support the use of age restrictions';
+COMMENT ON COLUMN denominations.denominations_serial
+ IS 'needed for exchange-auditor replication logic';
+
+CREATE INDEX denominations_by_expire_legal_index
+ ON denominations
+ (expire_legal);
diff --git a/src/exchangedb/0002-exchange_sign_keys.sql b/src/exchangedb/0002-exchange_sign_keys.sql
new file mode 100644
index 000000000..d6acc6bb0
--- /dev/null
+++ b/src/exchangedb/0002-exchange_sign_keys.sql
@@ -0,0 +1,36 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE exchange_sign_keys
+ (esk_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32)
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,valid_from INT8 NOT NULL
+ ,expire_sign INT8 NOT NULL
+ ,expire_legal INT8 NOT NULL
+ );
+COMMENT ON TABLE exchange_sign_keys
+ IS 'Table with master public key signatures on exchange online signing keys.';
+COMMENT ON COLUMN exchange_sign_keys.exchange_pub
+ IS 'Public online signing key of the exchange.';
+COMMENT ON COLUMN exchange_sign_keys.master_sig
+ IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
+COMMENT ON COLUMN exchange_sign_keys.valid_from
+ IS 'Time when this online signing key will first be used to sign messages.';
+COMMENT ON COLUMN exchange_sign_keys.expire_sign
+ IS 'Time when this online signing key will no longer be used to sign.';
+COMMENT ON COLUMN exchange_sign_keys.expire_legal
+ IS 'Time when this online signing key legally expires.';
diff --git a/src/exchangedb/0002-extensions.sql b/src/exchangedb/0002-extensions.sql
new file mode 100644
index 000000000..df9e50090
--- /dev/null
+++ b/src/exchangedb/0002-extensions.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE extensions
+ (extension_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,name TEXT NOT NULL UNIQUE
+ ,manifest BYTEA
+ );
+COMMENT ON TABLE extensions
+ IS 'Configurations of the activated extensions';
+COMMENT ON COLUMN extensions.name
+ IS 'Name of the extension';
+COMMENT ON COLUMN extensions.manifest
+ IS 'Manifest of the extension as JSON-blob, maybe NULL. It contains common meta-information and extension-specific configuration.';
diff --git a/src/exchangedb/0002-global_fee.sql b/src/exchangedb/0002-global_fee.sql
new file mode 100644
index 000000000..f6526798d
--- /dev/null
+++ b/src/exchangedb/0002-global_fee.sql
@@ -0,0 +1,37 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE global_fee
+ (global_fee_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,start_date INT8 NOT NULL
+ ,end_date INT8 NOT NULL
+ ,history_fee taler_amount NOT NULL
+ ,account_fee taler_amount NOT NULL
+ ,purse_fee taler_amount NOT NULL
+ ,purse_timeout INT8 NOT NULL
+ ,history_expiration INT8 NOT NULL
+ ,purse_account_limit INT4 NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,PRIMARY KEY (start_date)
+ );
+COMMENT ON TABLE global_fee
+ IS 'list of the global fees of this exchange, by date';
+COMMENT ON COLUMN global_fee.global_fee_serial
+ IS 'needed for exchange-auditor replication logic';
+
+CREATE INDEX global_fee_by_end_date_index
+ ON global_fee
+ (end_date);
diff --git a/src/exchangedb/0002-history_requests.sql b/src/exchangedb/0002-history_requests.sql
new file mode 100644
index 000000000..0714e1bea
--- /dev/null
+++ b/src/exchangedb/0002-history_requests.sql
@@ -0,0 +1,159 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_history_requests(
+ IN shard_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'history_requests';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
+ ',request_timestamp INT8 NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',history_fee taler_amount NOT NULL'
+ ',PRIMARY KEY (reserve_pub,request_timestamp)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Paid history requests issued by a client against a reserve'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'When was the history request made'
+ ,'request_timestamp'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature approving payment for the history request'
+ ,'reserve_sig'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'History fee approved by the signature'
+ ,'history_fee'
+ ,table_name
+ ,shard_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_history_requests(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name TEXT;
+BEGIN
+ partition_name = concat_ws('_', 'history_requests', partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name ||
+ ' ADD CONSTRAINT ' || partition_name || '_serial_id'
+ ' UNIQUE (history_request_serial_id)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_history_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'history_requests';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub) '
+ ' REFERENCES reserves(reserve_pub) ON DELETE CASCADE'
+ );
+END $$;
+
+
+CREATE OR REPLACE FUNCTION history_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'history_requests'
+ ,NEW.history_request_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION history_requests_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_history_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER history_requests_on_insert
+ AFTER INSERT
+ ON history_requests
+ FOR EACH ROW EXECUTE FUNCTION history_requests_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('history_requests'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('history_requests'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('history_requests'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('history_requests'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-known_coins.sql b/src/exchangedb/0002-known_coins.sql
new file mode 100644
index 000000000..a13beff6f
--- /dev/null
+++ b/src/exchangedb/0002-known_coins.sql
@@ -0,0 +1,136 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_known_coins(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'known_coins';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',denominations_serial INT8 NOT NULL'
+ ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
+ ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
+ ',denom_sig BYTEA NOT NULL'
+ ',remaining taler_amount NOT NULL DEFAULT(0,0)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'information about coins and their signatures, so we do not have to store the signatures more than once if a coin is involved in multiple operations'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Denomination of the coin, determines the value of the original coin and applicable fees for coin-specific operations.'
+ ,'denominations_serial'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'EdDSA public key of the coin'
+ ,'coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Value of the coin that remains to be spent'
+ ,'remaining'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Optional hash of the age commitment for age restrictions as per DD 24 (active if denom_type has the respective bit set)'
+ ,'age_commitment_hash'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'This is the signature of the exchange that affirms that the coin is a valid coin. The specific signature type depends on denom_type of the denomination.'
+ ,'denom_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_known_coins(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'known_coins';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_known_coin_id_key'
+ ' UNIQUE (known_coin_id)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_known_coins()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'known_coins';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_denominations'
+ ' FOREIGN KEY (denominations_serial) '
+ ' REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('known_coins'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('known_coins'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('known_coins'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-kyc_alerts.sql b/src/exchangedb/0002-kyc_alerts.sql
new file mode 100644
index 000000000..8e54846cf
--- /dev/null
+++ b/src/exchangedb/0002-kyc_alerts.sql
@@ -0,0 +1,27 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE kyc_alerts
+ (h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=32)
+ ,trigger_type INT4 NOT NULL
+ ,UNIQUE(trigger_type,h_payto)
+ );
+COMMENT ON TABLE kyc_alerts
+ IS 'alerts about completed KYC events reliably notifying other components (even if they are not running)';
+COMMENT ON COLUMN kyc_alerts.h_payto
+ IS 'hash of the payto://-URI for which the KYC status changed';
+COMMENT ON COLUMN kyc_alerts.trigger_type
+ IS 'identifies the receiver of the alert, as the same h_payto may require multiple components to be notified';
diff --git a/src/exchangedb/0002-kyc_attributes.sql b/src/exchangedb/0002-kyc_attributes.sql
new file mode 100644
index 000000000..66f3fc315
--- /dev/null
+++ b/src/exchangedb/0002-kyc_attributes.sql
@@ -0,0 +1,162 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION create_table_kyc_attributes(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'kyc_attributes';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(kyc_attributes_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA PRIMARY KEY CHECK (LENGTH(h_payto)=32)'
+ ',kyc_prox BYTEA NOT NULL CHECK (LENGTH(kyc_prox)=32)'
+ ',provider TEXT NOT NULL'
+ ',satisfied_checks TEXT[] NOT NULL'
+ ',collection_time INT8 NOT NULL'
+ ',expiration_time INT8 NOT NULL'
+ ',encrypted_attributes BYTEA NOT NULL'
+ ',legitimization_serial INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'KYC data about particular payment addresses'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of payto://-URI the attributes are about'
+ ,'h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'short hash of normalized full name and birthdate; used to efficiently find likely duplicate users'
+ ,'kyc_prox'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'time when the attributes were collected by the provider'
+ ,'collection_time'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'time when the attributes should no longer be considered validated'
+ ,'expiration_time'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'configuration section name of the provider that affirmed the attributes'
+ ,'provider'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ '(encrypted) JSON object (as string) with the attributes'
+ ,'encrypted_attributes'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Reference the legitimization process for which these attributes are gathered for.'
+ ,'legitimization_serial'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+COMMENT ON FUNCTION create_table_kyc_attributes
+ IS 'Creates the kyc_attributes table';
+
+
+CREATE OR REPLACE FUNCTION constrain_table_kyc_attributes(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'kyc_attributes';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_serial_key '
+ 'UNIQUE (kyc_attributes_serial_id)'
+ );
+ -- To search similar users (e.g. during AML checks)
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_similarity_index '
+ 'ON ' || table_name || ' '
+ '(kyc_prox);'
+ );
+ -- For garbage collection
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_expiration_time '
+ 'ON ' || table_name || ' '
+ '(expiration_time ASC);'
+ );
+END $$;
+
+
+CREATE OR REPLACE FUNCTION foreign_table_kyc_attributes()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'kyc_attributes';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_legitimization_processes'
+ ' FOREIGN KEY (legitimization_serial) '
+ ' REFERENCES legitimization_processes (legitimization_process_serial_id)' -- ON DELETE CASCADE
+ );
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('kyc_attributes'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('kyc_attributes'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('kyc_attributes'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-legitimization_processes.sql b/src/exchangedb/0002-legitimization_processes.sql
new file mode 100644
index 000000000..3212b1c06
--- /dev/null
+++ b/src/exchangedb/0002-legitimization_processes.sql
@@ -0,0 +1,149 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_legitimization_processes(
+ IN shard_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(legitimization_process_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
+ ',start_time INT8 NOT NULL'
+ ',expiration_time INT8 NOT NULL DEFAULT (0)'
+ ',provider_section TEXT NOT NULL'
+ ',provider_user_id TEXT DEFAULT NULL'
+ ',provider_legitimization_id TEXT DEFAULT NULL'
+ ',redirect_url TEXT DEFAULT NULL'
+ ',finished BOOLEAN DEFAULT (FALSE)'
+ ') %s ;'
+ ,'legitimization_processes'
+ ,'PARTITION BY HASH (h_payto)'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'List of legitimization processes (ongoing and completed) by account and provider'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'unique ID for this legitimization process at the exchange'
+ ,'legitimization_process_serial_id'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per wire target)'
+ ,'h_payto'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'time when the KYC check was initiated, useful for garbage collection'
+ ,'expiration_time'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'URL where the user should go to begin the KYC process'
+ ,'redirect_url'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'in the future if the respective KYC check was passed successfully'
+ ,'expiration_time'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Configuration file section with details about this provider'
+ ,'provider_section'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifier for the user at the provider that was used for the legitimization. NULL if provider is unaware.'
+ ,'provider_user_id'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifier for the specific legitimization process at the provider. NULL if legitimization was not started.'
+ ,'provider_legitimization_id'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Set to TRUE when the specific legitimization process is finished.'
+ ,'finished'
+ ,'legitimization_processes'
+ ,shard_suffix
+ );
+END
+$$;
+
+-- We need a separate function for this, as we call create_table only once but need to add
+-- those constraints to each partition which gets created
+CREATE FUNCTION constrain_table_legitimization_processes(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name TEXT;
+BEGIN
+ partition_name = concat_ws('_', 'legitimization_processes', partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name
+ || ' '
+ 'ADD CONSTRAINT ' || partition_name || '_serial_key '
+ 'UNIQUE (legitimization_process_serial_id)');
+ EXECUTE FORMAT (
+ 'CREATE INDEX IF NOT EXISTS ' || partition_name || '_by_provider_and_legi_index '
+ 'ON '|| partition_name || ' '
+ '(provider_section,provider_legitimization_id)'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || partition_name || '_by_provider_and_legi_index '
+ 'IS ' || quote_literal('used (rarely) in kyc_provider_account_lookup') || ';'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('legitimization_processes'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_processes'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-legitimization_requirements.sql b/src/exchangedb/0002-legitimization_requirements.sql
new file mode 100644
index 000000000..d806eb424
--- /dev/null
+++ b/src/exchangedb/0002-legitimization_requirements.sql
@@ -0,0 +1,104 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_legitimization_requirements(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(legitimization_requirement_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_payto BYTEA NOT NULL CHECK (LENGTH(h_payto)=32)'
+ ',reserve_pub BYTEA'
+ ',required_checks TEXT NOT NULL'
+ ',UNIQUE (h_payto, required_checks)'
+ ') %s ;'
+ ,'legitimization_requirements'
+ ,'PARTITION BY HASH (h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'List of required legitimizations by account'
+ ,'legitimization_requirements'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'unique ID for this legitimization requirement at the exchange'
+ ,'legitimization_requirement_serial_id'
+ ,'legitimization_requirements'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'foreign key linking the entry to the wire_targets table, NOT a primary key (multiple legitimizations are possible per wire target)'
+ ,'h_payto'
+ ,'legitimization_requirements'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'if h_payto refers to a reserve, this is its public key, NULL otherwise. It allows to lookup the corresponding reserve when the KYC process is done.'
+ ,'reserve_pub'
+ ,'legitimization_requirements'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'space-separated list of required checks'
+ ,'required_checks'
+ ,'legitimization_requirements'
+ ,partition_suffix
+ );
+END
+$$;
+
+-- We need a separate function for this, as we call create_table only once but need to add
+-- those constraints to each partition which gets created
+CREATE FUNCTION constrain_table_legitimization_requirements(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name TEXT;
+BEGIN
+ partition_name = concat_ws('_', 'legitimization_requirements', partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name || ' '
+ 'ADD CONSTRAINT ' || partition_name || '_serial_id_key '
+ 'UNIQUE (legitimization_requirement_serial_id)');
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('legitimization_requirements'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('legitimization_requirements'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-partner_accounts.sql b/src/exchangedb/0002-partner_accounts.sql
new file mode 100644
index 000000000..b12dc06e6
--- /dev/null
+++ b/src/exchangedb/0002-partner_accounts.sql
@@ -0,0 +1,33 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE TABLE partner_accounts
+ (payto_uri TEXT PRIMARY KEY
+ ,partner_serial_id INT8 REFERENCES partners(partner_serial_id) ON DELETE CASCADE
+ ,partner_master_sig BYTEA CHECK (LENGTH(partner_master_sig)=64)
+ ,last_seen INT8 NOT NULL
+ );
+CREATE INDEX IF NOT EXISTS partner_accounts_index_by_partner_and_time
+ ON partner_accounts (partner_serial_id,last_seen);
+COMMENT ON TABLE partner_accounts
+ IS 'Table with bank accounts of the partner exchange. Entries never expire as we need to remember the signature for the auditor.';
+COMMENT ON COLUMN partner_accounts.payto_uri
+ IS 'payto URI (RFC 8905) with the bank account of the partner exchange.';
+COMMENT ON COLUMN partner_accounts.partner_master_sig
+ IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS by the partner master public key';
+COMMENT ON COLUMN partner_accounts.last_seen
+ IS 'Last time we saw this account as being active at the partner exchange. Used to select the most recent entry, and to detect when we should check again.';
diff --git a/src/exchangedb/0002-partners.sql b/src/exchangedb/0002-partners.sql
new file mode 100644
index 000000000..ed09378d0
--- /dev/null
+++ b/src/exchangedb/0002-partners.sql
@@ -0,0 +1,49 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE partners
+ (partner_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,partner_master_pub BYTEA NOT NULL CHECK(LENGTH(partner_master_pub)=32)
+ ,start_date INT8 NOT NULL
+ ,end_date INT8 NOT NULL
+ ,next_wad INT8 NOT NULL DEFAULT (0)
+ ,wad_frequency INT8 NOT NULL
+ ,wad_fee taler_amount NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,partner_base_url TEXT NOT NULL
+ ,PRIMARY KEY (partner_master_pub, start_date)
+ );
+COMMENT ON TABLE partners
+ IS 'exchanges we do wad transfers to';
+COMMENT ON COLUMN partners.partner_master_pub
+ IS 'offline master public key of the partner';
+COMMENT ON COLUMN partners.start_date
+ IS 'starting date of the partnership';
+COMMENT ON COLUMN partners.end_date
+ IS 'end date of the partnership';
+COMMENT ON COLUMN partners.next_wad
+ IS 'at what time should we do the next wad transfer to this partner (frequently updated); set to forever after the end_date';
+COMMENT ON COLUMN partners.wad_frequency
+ IS 'how often do we promise to do wad transfers';
+COMMENT ON COLUMN partners.wad_fee
+ IS 'how high is the fee for a wallet to be added to a wad to this partner';
+COMMENT ON COLUMN partners.partner_base_url
+ IS 'base URL of the REST API for this partner';
+COMMENT ON COLUMN partners.master_sig
+ IS 'signature of our master public key affirming the partnership, of purpose TALER_SIGNATURE_MASTER_PARTNER_DETAILS';
+
+CREATE INDEX IF NOT EXISTS partner_by_wad_time
+ ON partners (next_wad ASC);
diff --git a/src/exchangedb/0002-policy_details.sql b/src/exchangedb/0002-policy_details.sql
new file mode 100644
index 000000000..3acbb5c10
--- /dev/null
+++ b/src/exchangedb/0002-policy_details.sql
@@ -0,0 +1,175 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- @author: Özgür Kesim
+
+CREATE FUNCTION create_table_policy_details(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'policy_details';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(policy_details_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',policy_hash_code gnunet_hashcode NOT NULL'
+ ',policy_json TEXT NOT NULL'
+ ',deadline INT8 NOT NULL'
+ ',commitment taler_amount NOT NULL'
+ ',accumulated_total taler_amount NOT NULL'
+ ',fee taler_amount NOT NULL'
+ ',transferable taler_amount NOT NULL'
+ ',fulfillment_state SMALLINT NOT NULL CHECK(fulfillment_state between 0 and 5)'
+ ',h_fulfillment_proof gnunet_hashcode'
+ ') %s;'
+ ,table_name
+ ,'PARTITION BY HASH (h_fulfillment_proof)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Policies that were provided with deposits via policy extensions.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'ID (GNUNET_HashCode) that identifies a policy. Will be calculated by the policy extension based on the content'
+ ,'policy_hash_code'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the policy extensions supported by the exchange.'
+ ,'policy_json'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Deadline until the policy must be marked as fulfilled (maybe "forever")'
+ ,'deadline'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The amount that this policy commits to. Invariant: commitment >= fee'
+ ,'commitment'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The sum of all contributions of all deposit that reference this policy. Invariant: The fulfilment_state must be Insufficient as long as accumulated_total < commitment'
+ ,'accumulated_total'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The fee for this policy, due when the policy is fulfilled or timed out'
+ ,'fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The amount that on fulfillment or timeout will be transferred to the payto-URI''s of the corresponding deposit''s. The policy fees must have been already deducted from it. Invariant: fee+transferable <= accumulated_total. The remaining amount (accumulated_total - fee - transferable) can be refreshed by the owner of the coins when the state is Timeout or Success.'
+ ,'transferable'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'State of the fulfillment:
+ - 0 (Failure)
+ - 1 (Insufficient)
+ - 2 (Ready)
+ - 4 (Success)
+ - 5 (Timeout)'
+ ,'fulfillment_state'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Reference to the proof of the fulfillment of this policy, if it exists. Invariant: If not NULL, this entry''s .hash_code MUST be part of the corresponding policy_fulfillments.policy_hash_codes array.'
+ ,'h_fulfillment_proof'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+COMMENT ON FUNCTION create_table_policy_details
+ IS 'Creates the policy_details table';
+
+
+
+
+CREATE FUNCTION constrain_table_policy_details(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name TEXT;
+BEGIN
+ partition_name = concat_ws('_', 'policy_details', partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name ||
+ ' ADD CONSTRAINT ' || partition_name || '_unique_serial_id '
+ ' UNIQUE (policy_details_serial_id)'
+ );
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name ||
+ ' ADD CONSTRAINT ' || partition_name || '_unique_hash_fulfillment_proof '
+ ' UNIQUE (policy_hash_code, h_fulfillment_proof)'
+ );
+
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || partition_name || '_policy_hash_code'
+ ' ON ' || partition_name ||
+ ' (policy_hash_code);'
+ );
+END
+$$;
+
+CREATE OR REPLACE FUNCTION foreign_table_policy_details()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'policy_details';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_policy_fulfillments'
+ ' FOREIGN KEY (h_fulfillment_proof) '
+ ' REFERENCES policy_fulfillments (h_fulfillment_proof) ON DELETE RESTRICT'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+VALUES
+ ('policy_details', 'exchange-0002', 'create', TRUE ,FALSE),
+ ('policy_details', 'exchange-0002', 'constrain', TRUE ,FALSE),
+ ('policy_details', 'exchange-0002', 'foreign', TRUE ,FALSE);
diff --git a/src/exchangedb/0002-policy_fulfillments.sql b/src/exchangedb/0002-policy_fulfillments.sql
new file mode 100644
index 000000000..c00947019
--- /dev/null
+++ b/src/exchangedb/0002-policy_fulfillments.sql
@@ -0,0 +1,101 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- @author: Özgür Kesim
+
+CREATE FUNCTION create_table_policy_fulfillments(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'policy_fulfillments';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(h_fulfillment_proof gnunet_hashcode PRIMARY KEY'
+ ',fulfillment_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',fulfillment_timestamp INT8 NOT NULL'
+ ',fulfillment_proof TEXT'
+ ',policy_hash_codes gnunet_hashcode[] NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (h_fulfillment_proof)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Proofs of fulfillment of policies that were set in deposits'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Timestamp of the arrival of a proof of fulfillment'
+ ,'fulfillment_timestamp'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'JSON object with a proof of the fulfillment of a policy. Supported details depend on the policy extensions supported by the exchange.'
+ ,'fulfillment_proof'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Hash of the fulfillment_proof'
+ ,'h_fulfillment_proof'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Array of the policy_hash_code''s of all policy_details that are fulfilled by this proof'
+ ,'policy_hash_codes'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+COMMENT ON FUNCTION create_table_policy_fulfillments
+ IS 'Creates the policy_fulfillments table';
+
+CREATE FUNCTION constrain_table_policy_fulfillments(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ partition_name TEXT;
+BEGIN
+ partition_name = concat_ws('_', 'policy_fulfillments', partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || partition_name ||
+ ' ADD CONSTRAINT ' || partition_name || '_serial_id '
+ ' UNIQUE (h_fulfillment_proof, fulfillment_id)'
+ );
+END
+$$;
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+VALUES
+ ('policy_fulfillments', 'exchange-0002', 'create', TRUE ,FALSE),
+ ('policy_fulfillments', 'exchange-0002', 'constrain', TRUE ,FALSE);
diff --git a/src/exchangedb/0002-prewire.sql b/src/exchangedb/0002-prewire.sql
new file mode 100644
index 000000000..396a27608
--- /dev/null
+++ b/src/exchangedb/0002-prewire.sql
@@ -0,0 +1,116 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_prewire(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'prewire';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
+ ',wire_method TEXT NOT NULL'
+ ',finished BOOLEAN NOT NULL DEFAULT FALSE'
+ ',failed BOOLEAN NOT NULL DEFAULT FALSE'
+ ',buf BYTEA NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (prewire_uuid)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'pre-commit data for wire transfers we are about to execute'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'set to TRUE if the bank responded with a non-transient failure to our transfer request'
+ ,'failed'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'set to TRUE once bank confirmed receiving the wire transfer request'
+ ,'finished'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'serialized data to send to the bank to execute the wire transfer'
+ ,'buf'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_prewire(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'prewire';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_finished_index '
+ 'ON ' || table_name || ' '
+ '(finished)'
+ ' WHERE finished;'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_finished_index '
+ 'IS ' || quote_literal('for do_gc') || ';'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_failed_finished_index '
+ 'ON ' || table_name || ' '
+ '(prewire_uuid)'
+ ' WHERE finished=FALSE'
+ ' AND failed=FALSE;'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index '
+ 'IS ' || quote_literal('for wire_prepare_data_get') || ';'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('prewire'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('prewire'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-profit_drains.sql b/src/exchangedb/0002-profit_drains.sql
new file mode 100644
index 000000000..c4f3a7bd0
--- /dev/null
+++ b/src/exchangedb/0002-profit_drains.sql
@@ -0,0 +1,42 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE profit_drains
+ (profit_drain_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,wtid BYTEA PRIMARY KEY CHECK (LENGTH(wtid)=32)
+ ,account_section TEXT NOT NULL
+ ,payto_uri TEXT NOT NULL
+ ,trigger_date INT8 NOT NULL
+ ,amount taler_amount NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,executed BOOLEAN NOT NULL DEFAULT FALSE
+ );
+COMMENT ON TABLE profit_drains
+ IS 'transactions to be performed to move profits from the escrow account of the exchange to a regular account';
+COMMENT ON COLUMN profit_drains.wtid
+ IS 'randomly chosen nonce, unique to prevent double-submission';
+COMMENT ON COLUMN profit_drains.account_section
+ IS 'specifies the configuration section in the taler-exchange-drain configuration with the wire account to drain';
+COMMENT ON COLUMN profit_drains.payto_uri
+ IS 'specifies the account to be credited';
+COMMENT ON COLUMN profit_drains.trigger_date
+ IS 'set by taler-exchange-offline at the time of making the signature; not necessarily the exact date of execution of the wire transfer, just for orientation';
+COMMENT ON COLUMN profit_drains.amount
+ IS 'amount to be transferred';
+COMMENT ON COLUMN profit_drains.master_sig
+ IS 'EdDSA signature of type TALER_SIGNATURE_MASTER_DRAIN_PROFIT';
+COMMENT ON COLUMN profit_drains.executed
+ IS 'set to TRUE by taler-exchange-drain on execution of the transaction, not replicated to auditor';
diff --git a/src/exchangedb/0002-purse_actions.sql b/src/exchangedb/0002-purse_actions.sql
new file mode 100644
index 000000000..0dd6cfc4d
--- /dev/null
+++ b/src/exchangedb/0002-purse_actions.sql
@@ -0,0 +1,121 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE OR REPLACE FUNCTION create_table_purse_actions(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_actions';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(purse_pub BYTEA NOT NULL PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
+ ',action_date INT8 NOT NULL'
+ ',partner_serial_id INT8'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'purses awaiting some action by the router'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public (contract) key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'when is the purse ready for action'
+ ,'action_date'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown'
+ ,'partner_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE OR REPLACE FUNCTION purse_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO
+ purse_actions
+ (purse_pub
+ ,action_date)
+ VALUES
+ (NEW.purse_pub
+ ,NEW.purse_expiration);
+ RETURN NEW;
+END $$;
+
+COMMENT ON FUNCTION purse_requests_insert_trigger()
+ IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
+
+
+CREATE OR REPLACE FUNCTION master_table_purse_actions()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_actions';
+BEGIN
+ -- Create global index
+ CREATE INDEX IF NOT EXISTS purse_action_by_target
+ ON purse_actions
+ (partner_serial_id,action_date);
+
+ -- Setup trigger
+ CREATE TRIGGER purse_requests_on_insert
+ AFTER INSERT
+ ON purse_requests
+ FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
+ COMMENT ON TRIGGER purse_requests_on_insert
+ ON purse_requests
+ IS 'Here we install an entry for the purse expiration.';
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_actions'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_actions'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-purse_decision.sql b/src/exchangedb/0002-purse_decision.sql
new file mode 100644
index 000000000..091bd468b
--- /dev/null
+++ b/src/exchangedb/0002-purse_decision.sql
@@ -0,0 +1,143 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_purse_decision(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_decision';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(purse_decision_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',action_timestamp INT8 NOT NULL'
+ ',refunded BOOL NOT NULL'
+ ',PRIMARY KEY (purse_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Purses that were decided upon (refund or merge)'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+CREATE FUNCTION constrain_table_purse_decision(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_decision';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_purse_action_serial_id_key'
+ ' UNIQUE (purse_decision_serial_id) '
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION purse_decision_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ UPDATE purse_requests
+ SET was_decided=TRUE
+ WHERE purse_pub=NEW.purse_pub;
+ IF NEW.refunded
+ THEN
+ INSERT INTO coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ SELECT
+ pd.coin_pub
+ ,'purse_decision'
+ ,NEW.purse_decision_serial_id
+ FROM purse_deposits pd
+ WHERE purse_pub = NEW.purse_pub;
+ ELSE
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ SELECT
+ reserve_pub
+ ,'purse_decision'
+ ,NEW.purse_decision_serial_id
+ FROM purse_merges
+ WHERE purse_pub=NEW.purse_pub;
+ END IF;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION purse_decision_insert_trigger()
+ IS 'Automatically generate coin history entry and update decision status for the purse.';
+
+
+CREATE FUNCTION master_table_purse_decision()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER purse_decision_on_insert
+ AFTER INSERT
+ ON purse_decision
+ FOR EACH ROW EXECUTE FUNCTION purse_decision_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_decision'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_decision'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('purse_decision'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-purse_deletion.sql b/src/exchangedb/0002-purse_deletion.sql
new file mode 100644
index 000000000..45b2e85a9
--- /dev/null
+++ b/src/exchangedb/0002-purse_deletion.sql
@@ -0,0 +1,110 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION create_table_purse_deletion(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_deletion';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(purse_deletion_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',purse_sig BYTEA CHECK (LENGTH(purse_sig)=64)'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'signatures affirming explicit purse deletions'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'signature of type WALLET_PURSE_DELETE'
+ ,'purse_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+COMMENT ON FUNCTION create_table_purse_deletion
+ IS 'Creates the purse_deletion table';
+
+
+CREATE OR REPLACE FUNCTION constrain_table_purse_deletion(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_deletion';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_delete_serial_key '
+ 'UNIQUE (purse_deletion_serial_id)'
+ );
+END $$;
+
+
+CREATE OR REPLACE FUNCTION master_table_purse_requests_was_deleted (
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_requests';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE exchange.' || table_name ||
+ ' ADD COLUMN'
+ ' was_deleted BOOLEAN NOT NULL DEFAULT(FALSE)'
+ );
+ COMMENT ON COLUMN purse_requests.was_deleted
+ IS 'TRUE if the purse was explicitly deleted (purse must have an entry in the purse_deletion table)';
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_deletion'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_deletion'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('purse_requests_was_deleted'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-purse_deposits.sql b/src/exchangedb/0002-purse_deposits.sql
new file mode 100644
index 000000000..6a07c4b62
--- /dev/null
+++ b/src/exchangedb/0002-purse_deposits.sql
@@ -0,0 +1,176 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_purse_deposits(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_deposits';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(purse_deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',partner_serial_id INT8'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',coin_pub BYTEA NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
+ ',PRIMARY KEY (purse_pub,coin_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Requests depositing coins into a purse'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'identifies the partner exchange, NULL in case the target purse lives at this exchange'
+ ,'partner_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the coin being deposited'
+ ,'coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total amount being deposited'
+ ,'amount_with_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature of the coin affirming the deposit into the purse, of type TALER_SIGNATURE_PURSE_DEPOSIT'
+ ,'coin_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_purse_deposits(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_deposits';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_purse_deposit_serial_id_key'
+ ' UNIQUE (purse_deposit_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_purse_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_deposits';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_partner'
+ ' FOREIGN KEY (partner_serial_id) '
+ ' REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION purse_deposits_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'purse_deposits'
+ ,NEW.purse_deposit_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION purse_deposits_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_purse_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER purse_deposits_on_insert
+ AFTER INSERT
+ ON purse_deposits
+ FOR EACH ROW EXECUTE FUNCTION purse_deposits_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_deposits'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_deposits'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('purse_deposits'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('purse_deposits'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-purse_merges.sql b/src/exchangedb/0002-purse_merges.sql
new file mode 100644
index 000000000..0b4d230b3
--- /dev/null
+++ b/src/exchangedb/0002-purse_merges.sql
@@ -0,0 +1,140 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_purse_merges(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_merges';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(purse_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',partner_serial_id INT8'
+ ',reserve_pub BYTEA NOT NULL CHECK(length(reserve_pub)=32)'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',merge_sig BYTEA NOT NULL CHECK (LENGTH(merge_sig)=64)'
+ ',merge_timestamp INT8 NOT NULL'
+ ',PRIMARY KEY (purse_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Merge requests where a purse-owner requested merging the purse into the account'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'identifies the partner exchange, NULL in case the target reserve lives at this exchange'
+ ,'partner_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the target reserve'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'signature by the purse private key affirming the merge, of type TALER_SIGNATURE_WALLET_PURSE_MERGE'
+ ,'merge_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'when was the merge message signed'
+ ,'merge_timestamp'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_purse_merges(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_merges';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_purse_merge_request_serial_id_key'
+ ' UNIQUE (purse_merge_request_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_purse_merges()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_merges';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_partner_serial_id'
+ ' FOREIGN KEY (partner_serial_id) '
+ ' REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_purse_pub'
+ ' FOREIGN KEY (purse_pub) '
+ ' REFERENCES purse_requests (purse_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_merges'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_merges'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('purse_merges'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-purse_requests.sql b/src/exchangedb/0002-purse_requests.sql
new file mode 100644
index 000000000..0fa076338
--- /dev/null
+++ b/src/exchangedb/0002-purse_requests.sql
@@ -0,0 +1,163 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_purse_requests(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_requests';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(purse_requests_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
+ ',merge_pub BYTEA NOT NULL CHECK (LENGTH(merge_pub)=32)'
+ ',purse_creation INT8 NOT NULL'
+ ',purse_expiration INT8 NOT NULL'
+ ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
+ ',age_limit INT4 NOT NULL'
+ ',flags INT4 NOT NULL'
+ ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
+ ',was_decided BOOLEAN NOT NULL DEFAULT(FALSE)'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',purse_fee taler_amount NOT NULL'
+ ',balance taler_amount NOT NULL DEFAULT (0,0)'
+ ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
+ ',PRIMARY KEY (purse_pub)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Requests establishing purses, associating them with a contract but without a target reserve'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Local time when the purse was created. Determines applicable purse fees.'
+ ,'purse_creation'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'When the purse is set to expire'
+ ,'purse_expiration'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Hash of the contract the parties are to agree to'
+ ,'h_contract_terms'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'see the enum TALER_WalletAccountMergeFlags'
+ ,'flags'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'set to TRUE if this purse currently counts against the number of free purses in the respective reserve'
+ ,'in_reserve_quota'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total amount expected to be in the purse'
+ ,'amount_with_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Purse fee the client agreed to pay from the reserve (accepted by the exchange at the time the purse was created). Zero if in_reserve_quota is TRUE.'
+ ,'purse_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total amount actually in the purse (updated)'
+ ,'balance'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature of the purse affirming the purse parameters, of type TALER_SIGNATURE_PURSE_REQUEST'
+ ,'purse_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+CREATE FUNCTION constrain_table_purse_requests(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_requests';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_merge_pub '
+ 'ON ' || table_name || ' '
+ '(merge_pub);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_purse_expiration '
+ 'ON ' || table_name || ' '
+ '(purse_expiration) ' ||
+ 'WHERE NOT was_decided;'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_purse_requests_serial_id_key'
+ ' UNIQUE (purse_requests_serial_id) '
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_requests'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('purse_requests'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-recoup.sql b/src/exchangedb/0002-recoup.sql
new file mode 100644
index 000000000..4b3452498
--- /dev/null
+++ b/src/exchangedb/0002-recoup.sql
@@ -0,0 +1,267 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_recoup(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(recoup_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
+ ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
+ ',amount taler_amount NOT NULL'
+ ',recoup_timestamp INT8 NOT NULL'
+ ',reserve_out_serial_id INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub);'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Information about recoups that were executed between a coin and a reserve. In this type of recoup, the amount is credited back to the reserve from which the coin originated.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Coin that is being debited in the recoup. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!'
+ ,'coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the h_blind_ev of the recouped coin and provides the link to the credited reserve.'
+ ,'reserve_out_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature by the coin affirming the recoup, of type TALER_SIGNATURE_WALLET_COIN_RECOUP'
+ ,'coin_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the withdraw operation.'
+ ,'coin_blind'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_recoup(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_coin_pub_index '
+ 'ON ' || table_name || ' '
+ '(coin_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_recoup_uuid_key'
+ ' UNIQUE (recoup_uuid) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_recoup()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserves_out'
+ ' FOREIGN KEY (reserve_out_serial_id) '
+ ' REFERENCES reserves_out (reserve_out_serial_id) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION create_table_recoup_by_reserve(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup_by_reserve';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves (reserve_out_serial_id) ON DELETE CASCADE
+ ',coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_out_serial_id)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Information in this table is strictly redundant with that of recoup, but saved by a different primary key for fast lookups by reserve_out_serial_id.'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_recoup_by_reserve(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup_by_reserve';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_main_index '
+ 'ON ' || table_name || ' '
+ '(reserve_out_serial_id);'
+ );
+END
+$$;
+
+
+CREATE FUNCTION recoup_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO recoup_by_reserve
+ (reserve_out_serial_id
+ ,coin_pub)
+ VALUES
+ (NEW.reserve_out_serial_id
+ ,NEW.coin_pub);
+ INSERT INTO coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'recoup'
+ ,NEW.recoup_uuid);
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ SELECT
+ res.reserve_pub
+ ,'recoup'
+ ,NEW.recoup_uuid
+ FROM reserves_out rout
+ JOIN reserves res
+ USING (reserve_uuid)
+ WHERE rout.reserve_out_serial_id = NEW.reserve_out_serial_id;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION recoup_insert_trigger()
+ IS 'Replicates recoup inserts into recoup_by_reserve table and updates the coin_history table.';
+
+
+CREATE FUNCTION recoup_delete_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ DELETE FROM recoup_by_reserve
+ WHERE reserve_out_serial_id = OLD.reserve_out_serial_id
+ AND coin_pub = OLD.coin_pub;
+ RETURN OLD;
+END $$;
+COMMENT ON FUNCTION recoup_delete_trigger()
+ IS 'Replicate recoup deletions into recoup_by_reserve table.';
+
+
+CREATE FUNCTION master_table_recoup()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER recoup_on_insert
+ AFTER INSERT
+ ON recoup
+ FOR EACH ROW EXECUTE FUNCTION recoup_insert_trigger();
+ CREATE TRIGGER recoup_on_delete
+ AFTER DELETE
+ ON recoup
+ FOR EACH ROW EXECUTE FUNCTION recoup_delete_trigger();
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('recoup'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('recoup'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('recoup'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('recoup_by_reserve'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('recoup_by_reserve'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('recoup'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-recoup_refresh.sql b/src/exchangedb/0002-recoup_refresh.sql
new file mode 100644
index 000000000..8b979a49f
--- /dev/null
+++ b/src/exchangedb/0002-recoup_refresh.sql
@@ -0,0 +1,203 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_recoup_refresh(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup_refresh';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(recoup_refresh_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',known_coin_id BIGINT NOT NULL'
+ ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
+ ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
+ ',amount taler_amount NOT NULL'
+ ',recoup_timestamp INT8 NOT NULL'
+ ',rrc_serial INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Table of coins that originated from a refresh operation and that were recouped. Links the (fresh) coin to the melted operation (and thus the old coin). A recoup on a refreshed coin credits the old coin and debits the fresh coin.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Refreshed coin of a revoked denomination where the residual value is credited to the old coin. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!'
+ ,'coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Used for garbage collection (in the absence of foreign constraints, in the future)'
+ ,'known_coin_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Link to the refresh operation. Also identifies the h_blind_ev of the recouped coin (as h_coin_ev).'
+ ,'rrc_serial'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the refresh operation.'
+ ,'coin_blind'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_recoup_refresh(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup_refresh';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_rrc_serial_index'
+ ' ON ' || table_name || ' '
+ '(rrc_serial);'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_rrc_serial_index '
+ 'IS ' || quote_literal('used in exchange_do_melt for zombie coins (rare)') || ';'
+ );
+
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_coin_pub_index'
+ ' ON ' || table_name || ' '
+ '(coin_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_recoup_refresh_uuid_key'
+ ' UNIQUE (recoup_refresh_uuid) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_recoup_refresh()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'recoup_refresh';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub)'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_known_coin_id'
+ ' FOREIGN KEY (known_coin_id) '
+ ' REFERENCES known_coins (known_coin_id) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_rrc_serial'
+ ' FOREIGN KEY (rrc_serial) '
+ ' REFERENCES refresh_revealed_coins (rrc_serial) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION recoup_refresh_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'recoup_refresh::NEW'
+ ,NEW.recoup_refresh_uuid);
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ SELECT
+ melt.old_coin_pub
+ ,'recoup_refresh::OLD'
+ ,NEW.recoup_refresh_uuid
+ FROM refresh_revealed_coins rrc
+ JOIN refresh_commitments melt
+ USING (melt_serial_id)
+ WHERE rrc.rrc_serial = NEW.rrc_serial;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION coin_deposits_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_recoup_refresh()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER recoup_refresh_on_insert
+ AFTER INSERT
+ ON recoup_refresh
+ FOR EACH ROW EXECUTE FUNCTION recoup_refresh_insert_trigger();
+END $$;
+
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('recoup_refresh'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('recoup_refresh'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('recoup_refresh'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('recoup_refresh'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-refresh_commitments.sql b/src/exchangedb/0002-refresh_commitments.sql
new file mode 100644
index 000000000..e577f1e1c
--- /dev/null
+++ b/src/exchangedb/0002-refresh_commitments.sql
@@ -0,0 +1,166 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_refresh_commitments(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_commitments';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(melt_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
+ ',old_coin_pub BYTEA NOT NULL'
+ ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',noreveal_index INT4 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (rc)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Commitments made when melting coins and the gamma value chosen by the exchange.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'The gamma value chosen by the exchange in the cut-and-choose protocol'
+ ,'noreveal_index'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol'
+ ,'rc'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Coin being melted in the refresh process.'
+ ,'old_coin_pub'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_refresh_commitments(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_commitments';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ -- Note: index spans partitions, may need to be materialized.
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_old_coin_pub_index '
+ 'ON ' || table_name || ' '
+ '(old_coin_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_melt_serial_id_key'
+ ' UNIQUE (melt_serial_id)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_refresh_commitments()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_commitments';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (old_coin_pub) '
+ ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION refresh_commitments_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.old_coin_pub
+ ,'refresh_commitments'
+ ,NEW.melt_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION refresh_commitments_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_refresh_commitments()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER refresh_commitments_on_insert
+ AFTER INSERT
+ ON refresh_commitments
+ FOR EACH ROW EXECUTE FUNCTION refresh_commitments_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refresh_commitments'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('refresh_commitments'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('refresh_commitments'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('refresh_commitments'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-refresh_revealed_coins.sql b/src/exchangedb/0002-refresh_revealed_coins.sql
new file mode 100644
index 000000000..ad65c9942
--- /dev/null
+++ b/src/exchangedb/0002-refresh_revealed_coins.sql
@@ -0,0 +1,169 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_refresh_revealed_coins(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_revealed_coins';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(rrc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',melt_serial_id INT8 NOT NULL'
+ ',freshcoin_index INT4 NOT NULL'
+ ',link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)'
+ ',denominations_serial INT8 NOT NULL'
+ ',coin_ev BYTEA NOT NULL'
+ ',h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)'
+ ',ev_sig BYTEA NOT NULL'
+ ',ewv BYTEA NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (melt_serial_id)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Revelations about the new coins that are to be created during a melting session.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'needed for exchange-auditor replication logic'
+ ,'rrc_serial'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the refresh commitment (rc) of the melt operation.'
+ ,'melt_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'index of the fresh coin being created (one melt operation may result in multiple fresh coins)'
+ ,'freshcoin_index'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature of type WALLET_COIN_LINK, proves exchange did not tamper with the link data'
+ ,'link_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'envelope of the new coin to be signed'
+ ,'coin_ev'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'exchange contributed values in the creation of the fresh coin (see /csr)'
+ ,'ewv'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of the envelope of the new coin to be signed (for lookups)'
+ ,'h_coin_ev'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'exchange signature over the envelope'
+ ,'ev_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_refresh_revealed_coins(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_revealed_coins';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_coins_by_melt_serial_id_index '
+ 'ON ' || table_name || ' '
+ '(melt_serial_id);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_rrc_serial_key'
+ ' UNIQUE (rrc_serial) '
+ ',ADD CONSTRAINT ' || table_name || '_coin_ev_key'
+ ' UNIQUE (coin_ev) '
+ ',ADD CONSTRAINT ' || table_name || '_h_coin_ev_key'
+ ' UNIQUE (h_coin_ev) '
+ ',ADD PRIMARY KEY (melt_serial_id, freshcoin_index)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_refresh_revealed_coins()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_revealed_coins';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_melt'
+ ' FOREIGN KEY (melt_serial_id)'
+ ' REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_denom'
+ ' FOREIGN KEY (denominations_serial)'
+ ' REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refresh_revealed_coins'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('refresh_revealed_coins'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('refresh_revealed_coins'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-refresh_transfer_keys.sql b/src/exchangedb/0002-refresh_transfer_keys.sql
new file mode 100644
index 000000000..9bcb912da
--- /dev/null
+++ b/src/exchangedb/0002-refresh_transfer_keys.sql
@@ -0,0 +1,127 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_refresh_transfer_keys(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_transfer_keys';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(rtc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',melt_serial_id INT8 PRIMARY KEY'
+ ',transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)'
+ ',transfer_privs BYTEA NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (melt_serial_id)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Transfer keys of a refresh operation (the data revealed to the exchange).'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'needed for exchange-auditor replication logic'
+ ,'rtc_serial'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the refresh commitment (rc) of the operation.'
+ ,'melt_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'transfer public key for the gamma index'
+ ,'transfer_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'array of TALER_CNC_KAPPA-1 transfer private keys that have been revealed, with the gamma entry being skipped'
+ ,'transfer_privs'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_refresh_transfer_keys(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_transfer_keys';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_rtc_serial_key'
+ ' UNIQUE (rtc_serial)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_refresh_transfer_keys()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refresh_transfer_keys';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || 'foreign_melt_serial_id'
+ ' FOREIGN KEY (melt_serial_id)'
+ ' REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refresh_transfer_keys'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('refresh_transfer_keys'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('refresh_transfer_keys'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-refunds.sql b/src/exchangedb/0002-refunds.sql
new file mode 100644
index 000000000..2a40bc192
--- /dev/null
+++ b/src/exchangedb/0002-refunds.sql
@@ -0,0 +1,162 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_refunds(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refunds';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(refund_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',batch_deposit_serial_id INT8 NOT NULL'
+ ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
+ ',rtransaction_id INT8 NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Data on coins that were refunded. Technically, refunds always apply against specific deposit operations involving a coin. The combination of coin_pub, merchant_pub, h_contract_terms and rtransaction_id MUST be unique, and we usually select by coin_pub so that one goes first.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies ONLY the merchant_pub, h_contract_terms and coin_pub. Multiple deposits may match a refund, this only identifies one of them.'
+ ,'batch_deposit_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'used by the merchant to make refunds unique in case the same coin for the same deposit gets a subsequent (higher) refund'
+ ,'rtransaction_id'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_refunds (
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refunds';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_coin_pub_index '
+ 'ON ' || table_name || ' '
+ '(coin_pub);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_refund_serial_id_key'
+ ' UNIQUE (refund_serial_id) '
+ ',ADD PRIMARY KEY (batch_deposit_serial_id, rtransaction_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_refunds ()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refunds';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_coin_pub'
+ ' FOREIGN KEY (coin_pub) '
+ ' REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_deposit'
+ ' FOREIGN KEY (batch_deposit_serial_id) '
+ ' REFERENCES batch_deposits (batch_deposit_serial_id) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION refunds_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'refunds'
+ ,NEW.refund_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION refunds_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_refunds()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER refunds_on_insert
+ AFTER INSERT
+ ON refunds
+ FOR EACH ROW EXECUTE FUNCTION refunds_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refunds'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('refunds'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('refunds'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('refunds'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserve_history.sql b/src/exchangedb/0002-reserve_history.sql
new file mode 100644
index 000000000..b0c764306
--- /dev/null
+++ b/src/exchangedb/0002-reserve_history.sql
@@ -0,0 +1,138 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserve_history (
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserve_history';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_history_serial_id INT8 GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
+ ',table_name TEXT NOT NULL'
+ ',serial_id INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Links to tables with entries that affected the transaction history of a reserve.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'For which reserve is this a history entry'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'In which table is the history entry'
+ ,'table_name'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Which is the generated serial ID of the entry in the table'
+ ,'serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Monotonic counter, used to generate Etags for caching'
+ ,'reserve_history_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserve_history(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserve_history';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_reserve_history_serial_id_pkey'
+ ' PRIMARY KEY (reserve_history_serial_id) '
+ ',ADD CONSTRAINT ' || table_name || '_reserve_entry_key'
+ ' UNIQUE (reserve_pub, table_name, serial_id)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_reserve_by_time'
+ ' ON ' || table_name || ' '
+ '(reserve_pub'
+ ',reserve_history_serial_id DESC'
+ ');'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_reserve_history()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserve_history';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub) '
+ ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserve_history'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserve_history'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserve_history'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE)
+ ;
diff --git a/src/exchangedb/0002-reserves.sql b/src/exchangedb/0002-reserves.sql
new file mode 100644
index 000000000..d710dd01b
--- /dev/null
+++ b/src/exchangedb/0002-reserves.sql
@@ -0,0 +1,152 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserves';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)'
+ ',current_balance taler_amount NOT NULL DEFAULT (0, 0)'
+ ',purses_active INT8 NOT NULL DEFAULT(0)'
+ ',purses_allowed INT8 NOT NULL DEFAULT(0)'
+ ',birthday INT4 NOT NULL DEFAULT(0)'
+ ',expiration_date INT8 NOT NULL'
+ ',gc_date INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Summarizes the balance of a reserve. Updated when new funds are added or withdrawn.'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'EdDSA public key of the reserve. Knowledge of the private key implies ownership over the balance.'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Current balance remaining with the reserve.'
+ ,'current_balance'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Number of purses that were created by this reserve that are not expired and not fully paid.'
+ ,'purses_active'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Number of purses that this reserve is allowed to have active at most.'
+ ,'purses_allowed'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Used to trigger closing of reserves that have not been drained after some time'
+ ,'expiration_date'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Used to forget all information about a reserve during garbage collection'
+ ,'gc_date'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Birthday of the user in days after 1970, or 0 if user is an adult and is not subject to age restrictions'
+ ,'birthday'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserves(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserves';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_unique_uuid'
+ ' UNIQUE (reserve_uuid)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_expiration_index '
+ 'ON ' || table_name || ' '
+ '(expiration_date'
+ ',current_balance'
+ ');'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_expiration_index '
+ 'IS ' || quote_literal('used in get_expired_reserves') || ';'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve_uuid_index '
+ 'ON ' || table_name || ' '
+ '(reserve_uuid);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_gc_date_index '
+ 'ON ' || table_name || ' '
+ '(gc_date);'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_gc_date_index '
+ 'IS ' || quote_literal('for reserve garbage collection') || ';'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserves_close.sql b/src/exchangedb/0002-reserves_close.sql
new file mode 100644
index 000000000..16669768d
--- /dev/null
+++ b/src/exchangedb/0002-reserves_close.sql
@@ -0,0 +1,151 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves_close(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_close';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL'
+ ',execution_date INT8 NOT NULL'
+ ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
+ ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
+ ',amount taler_amount NOT NULL'
+ ',closing_fee taler_amount NOT NULL'
+ ',close_request_row INT8 NOT NULL DEFAULT(0)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'wire transfers executed by the reserve to close reserves'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.'
+ ,'wire_target_h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserves_close(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_close';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_close_uuid_pkey'
+ ' PRIMARY KEY (close_uuid)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve_pub_index '
+ 'ON ' || table_name || ' (reserve_pub);'
+ );
+END $$;
+
+
+CREATE FUNCTION foreign_table_reserves_close()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_close';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub)'
+ ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
+ );
+END $$;
+
+
+CREATE OR REPLACE FUNCTION reserves_close_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'reserves_close'
+ ,NEW.close_uuid);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION reserves_close_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_reserves_close()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER reserves_close_on_insert
+ AFTER INSERT
+ ON reserves_close
+ FOR EACH ROW EXECUTE FUNCTION reserves_close_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_close'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves_close'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserves_close'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('reserves_close'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserves_in.sql b/src/exchangedb/0002-reserves_in.sql
new file mode 100644
index 000000000..197a815b3
--- /dev/null
+++ b/src/exchangedb/0002-reserves_in.sql
@@ -0,0 +1,175 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves_in(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_in';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA PRIMARY KEY'
+ ',wire_reference INT8 NOT NULL'
+ ',credit taler_amount NOT NULL'
+ ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
+ ',exchange_account_section TEXT NOT NULL'
+ ',execution_date INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'list of transfers of funds into the reserves, one per incoming wire transfer'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the debited bank account and KYC status'
+ ,'wire_source_h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the reserve. Private key signifies ownership of the remaining balance.'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Amount that was transferred into the reserve'
+ ,'credit'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_reserves_in(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_in';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_reserve_in_serial_id_key'
+ ' UNIQUE (reserve_in_serial_id)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve_in_serial_id_index '
+ 'ON ' || table_name || ' '
+ '(reserve_in_serial_id);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_exch_accnt_reserve_in_serial_id_idx '
+ 'ON ' || table_name || ' '
+ '(exchange_account_section'
+ ',reserve_in_serial_id ASC'
+ ');'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_exch_accnt_reserve_in_serial_id_idx '
+ 'IS ' || quote_literal ('for pg_select_reserves_in_above_serial_id_by_account') || ';'
+ );
+
+END
+$$;
+
+CREATE FUNCTION foreign_table_reserves_in()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'reserves_in';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub'
+ ' FOREIGN KEY (reserve_pub) '
+ ' REFERENCES reserves(reserve_pub) ON DELETE CASCADE'
+ );
+END $$;
+
+
+
+CREATE OR REPLACE FUNCTION reserves_in_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'reserves_in'
+ ,NEW.reserve_in_serial_id);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION reserves_in_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_reserves_in()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER reserves_in_on_insert
+ AFTER INSERT
+ ON reserves_in
+ FOR EACH ROW EXECUTE FUNCTION reserves_in_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_in'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves_in'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserves_in'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('reserves_in'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserves_open_deposits.sql b/src/exchangedb/0002-reserves_open_deposits.sql
new file mode 100644
index 000000000..776859df8
--- /dev/null
+++ b/src/exchangedb/0002-reserves_open_deposits.sql
@@ -0,0 +1,135 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves_open_deposits(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_open_deposits';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_open_deposit_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)'
+ ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
+ ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
+ ',contribution taler_amount NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (coin_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'coin contributions paying for a reserve to remain open'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the specific reserve being paid for (possibly together with reserve_sig).'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserves_open_deposits(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_open_deposits';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name || ' '
+ 'ADD CONSTRAINT ' || table_name || '_coin_unique '
+ 'PRIMARY KEY (coin_pub,coin_sig)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_uuid '
+ 'ON ' || table_name || ' '
+ '(reserve_open_deposit_uuid);'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve '
+ 'ON ' || table_name || ' '
+ '(reserve_pub);'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION reserves_open_deposits_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO exchange.coin_history
+ (coin_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.coin_pub
+ ,'reserves_open_deposits'
+ ,NEW.reserve_open_deposit_uuid);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION reserves_open_deposits_insert_trigger()
+ IS 'Automatically generate coin history entry.';
+
+
+CREATE FUNCTION master_table_reserves_open_deposits()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER reserves_open_deposits_on_insert
+ AFTER INSERT
+ ON reserves_open_deposits
+ FOR EACH ROW EXECUTE FUNCTION reserves_open_deposits_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_open_deposits'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves_open_deposits'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserves_open_deposits'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserves_open_requests.sql b/src/exchangedb/0002-reserves_open_requests.sql
new file mode 100644
index 000000000..b51168dc0
--- /dev/null
+++ b/src/exchangedb/0002-reserves_open_requests.sql
@@ -0,0 +1,150 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves_open_requests(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_open_requests';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(open_request_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',reserve_pub BYTEA NOT NULL'
+ ',request_timestamp INT8 NOT NULL'
+ ',expiration_date INT8 NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',reserve_payment taler_amount NOT NULL'
+ ',requested_purse_limit INT4 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (reserve_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table (
+ 'requests to keep a reserve open'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column (
+ 'Fee to pay for the request from the reserve balance itself.'
+ ,'reserve_payment'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserves_open_requests(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_open_requests';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_by_uuid'
+ ' PRIMARY KEY (open_request_uuid)'
+ ',ADD CONSTRAINT ' || table_name || '_by_time'
+ ' UNIQUE (reserve_pub,request_timestamp)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_reserves_open_requests()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_open_requests';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_reserve_pub '
+ ' FOREIGN KEY (reserve_pub)'
+ ' REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE OR REPLACE FUNCTION reserves_open_requests_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ VALUES
+ (NEW.reserve_pub
+ ,'reserves_open_requests'
+ ,NEW.open_request_uuid);
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION reserves_open_requests_insert_trigger()
+ IS 'Automatically generate reserve history entry.';
+
+
+CREATE FUNCTION master_table_reserves_open_requests()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER reserves_open_requests_on_insert
+ AFTER INSERT
+ ON reserves_open_requests
+ FOR EACH ROW EXECUTE FUNCTION reserves_open_requests_insert_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_open_requests'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves_open_requests'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserves_open_requests'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('reserves_open_requests'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-reserves_out.sql b/src/exchangedb/0002-reserves_out.sql
new file mode 100644
index 000000000..f0965d222
--- /dev/null
+++ b/src/exchangedb/0002-reserves_out.sql
@@ -0,0 +1,173 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_reserves_out(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_out';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(reserve_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64) UNIQUE'
+ ',denominations_serial INT8 NOT NULL'
+ ',denom_sig BYTEA NOT NULL'
+ ',reserve_uuid INT8 NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',execution_date INT8 NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
+ ') %s ;'
+ ,'reserves_out'
+ ,'PARTITION BY HASH (h_blind_ev)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table (
+ 'Withdraw operations performed on reserves.'
+ ,'reserves_out'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column (
+ 'Hash of the blinded coin, used as primary key here so that broken clients that use a non-random coin or blinding factor fail to withdraw (otherwise they would fail on deposit when the coin is not unique there).'
+ ,'h_blind_ev'
+ ,'reserves_out'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column (
+ 'We do not CASCADE ON DELETE for the foreign constrain here, as we may keep the denomination data alive'
+ ,'denominations_serial'
+ ,'reserves_out'
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_reserves_out(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_out';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_reserve_out_serial_id_key'
+ ' UNIQUE (reserve_out_serial_id)'
+ );
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_reserve_uuid_and_execution_date_index '
+ 'ON ' || table_name || ' '
+ '(reserve_uuid, execution_date);'
+ );
+ EXECUTE FORMAT (
+ 'COMMENT ON INDEX ' || table_name || '_by_reserve_uuid_and_execution_date_index '
+ 'IS ' || quote_literal('for do_gc, do_recoup_by_reserve, select_kyc_relevant_withdraw_events and a few others') || ';'
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_reserves_out()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT default 'reserves_out';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_denom'
+ ' FOREIGN KEY (denominations_serial)'
+ ' REFERENCES denominations (denominations_serial)'
+ ',ADD CONSTRAINT ' || table_name || '_foreign_reserve '
+ ' FOREIGN KEY (reserve_uuid)'
+ ' REFERENCES reserves (reserve_uuid) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+CREATE FUNCTION reserves_out_insert_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ INSERT INTO reserve_history
+ (reserve_pub
+ ,table_name
+ ,serial_id)
+ SELECT
+ res.reserve_pub
+ ,'reserves_out'
+ ,NEW.reserve_out_serial_id
+ FROM
+ reserves res
+ WHERE res.reserve_uuid = NEW.reserve_uuid;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION reserves_out_insert_trigger()
+ IS 'Replicate reserve_out inserts into reserve_history table.';
+
+
+CREATE FUNCTION master_table_reserves_out()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER reserves_out_on_insert
+ AFTER INSERT
+ ON reserves_out
+ FOR EACH ROW EXECUTE FUNCTION reserves_out_insert_trigger();
+END $$;
+COMMENT ON FUNCTION master_table_reserves_out()
+ IS 'Setup triggers to replicate reserve_out into reserve_history.';
+
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('reserves_out'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('reserves_out'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('reserves_out'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE),
+ ('reserves_out'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-revolving_work_shards.sql b/src/exchangedb/0002-revolving_work_shards.sql
new file mode 100644
index 000000000..8cfff09b4
--- /dev/null
+++ b/src/exchangedb/0002-revolving_work_shards.sql
@@ -0,0 +1,46 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE UNLOGGED TABLE revolving_work_shards
+ (shard_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,last_attempt INT8 NOT NULL
+ ,start_row INT4 NOT NULL
+ ,end_row INT4 NOT NULL
+ ,active BOOLEAN NOT NULL DEFAULT FALSE
+ ,job_name TEXT NOT NULL
+ ,PRIMARY KEY (job_name, start_row)
+ );
+COMMENT ON TABLE revolving_work_shards
+ IS 'coordinates work between multiple processes working on the same job with partitions that need to be repeatedly processed; unlogged because on system crashes the locks represented by this table will have to be cleared anyway, typically using "taler-exchange-dbinit -s"';
+COMMENT ON COLUMN revolving_work_shards.shard_serial_id
+ IS 'unique serial number identifying the shard';
+COMMENT ON COLUMN revolving_work_shards.last_attempt
+ IS 'last time a worker attempted to work on the shard';
+COMMENT ON COLUMN revolving_work_shards.active
+ IS 'set to TRUE when a worker is active on the shard';
+COMMENT ON COLUMN revolving_work_shards.start_row
+ IS 'row at which the shard scope starts, inclusive';
+COMMENT ON COLUMN revolving_work_shards.end_row
+ IS 'row at which the shard scope ends, exclusive';
+COMMENT ON COLUMN revolving_work_shards.job_name
+ IS 'unique name of the job the workers on this shard are performing';
+
+CREATE INDEX revolving_work_shards_by_job_name_active_last_attempt_index
+ ON revolving_work_shards
+ (job_name
+ ,active
+ ,last_attempt
+ );
diff --git a/src/exchangedb/0002-signkey_revocations.sql b/src/exchangedb/0002-signkey_revocations.sql
new file mode 100644
index 000000000..37ab32c67
--- /dev/null
+++ b/src/exchangedb/0002-signkey_revocations.sql
@@ -0,0 +1,23 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE signkey_revocations
+ (signkey_revocations_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,esk_serial INT8 PRIMARY KEY REFERENCES exchange_sign_keys (esk_serial) ON DELETE CASCADE
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ );
+COMMENT ON TABLE signkey_revocations
+ IS 'Table storing which online signing keys have been revoked';
diff --git a/src/exchangedb/0002-wad_in_entries.sql b/src/exchangedb/0002-wad_in_entries.sql
new file mode 100644
index 000000000..3ef1f1b8e
--- /dev/null
+++ b/src/exchangedb/0002-wad_in_entries.sql
@@ -0,0 +1,175 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_wad_in_entries(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_in_entries';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(wad_in_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',wad_in_serial_id INT8'
+ ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
+ ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
+ ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
+ ',purse_expiration INT8 NOT NULL'
+ ',merge_timestamp INT8 NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',wad_fee taler_amount NOT NULL'
+ ',deposit_fees taler_amount NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'list of purses aggregated in a wad according to the sending exchange'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'wad for which the given purse was included in the aggregation'
+ ,'wad_in_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'target account of the purse (must be at the local exchange)'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'public key of the purse that was merged'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'hash of the contract terms of the purse'
+ ,'h_contract'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the purse was set to expire'
+ ,'purse_expiration'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the merge was approved'
+ ,'merge_timestamp'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total amount in the purse'
+ ,'amount_with_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total wad fees paid by the purse'
+ ,'wad_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total deposit fees paid when depositing coins into the purse'
+ ,'deposit_fees'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE'
+ ,'reserve_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE'
+ ,'purse_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_wad_in_entries(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_in_entries';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wad_in_entry_serial_id_key'
+ ' UNIQUE (wad_in_entry_serial_id) '
+ );
+END $$;
+
+
+CREATE FUNCTION foreign_table_wad_in_entries()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_in_entries';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_wad_in'
+ ' FOREIGN KEY(wad_in_serial_id)'
+ ' REFERENCES wads_in (wad_in_serial_id) ON DELETE CASCADE'
+ );
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wad_in_entries'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wad_in_entries'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('wad_in_entries'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-wad_out_entries.sql b/src/exchangedb/0002-wad_out_entries.sql
new file mode 100644
index 000000000..de921637b
--- /dev/null
+++ b/src/exchangedb/0002-wad_out_entries.sql
@@ -0,0 +1,179 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE FUNCTION create_table_wad_out_entries(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_out_entries';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(wad_out_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',wad_out_serial_id INT8'
+ ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
+ ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
+ ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
+ ',purse_expiration INT8 NOT NULL'
+ ',merge_timestamp INT8 NOT NULL'
+ ',amount_with_fee taler_amount NOT NULL'
+ ',wad_fee taler_amount NOT NULL'
+ ',deposit_fees taler_amount NOT NULL'
+ ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
+ ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (purse_pub)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Purses combined into a wad'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Wad the purse was part of'
+ ,'wad_out_serial_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Target reserve for the purse'
+ ,'reserve_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Public key of the purse'
+ ,'purse_pub'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Hash of the contract associated with the purse'
+ ,'h_contract'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the purse expires'
+ ,'purse_expiration'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the merge was approved'
+ ,'merge_timestamp'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total amount in the purse'
+ ,'amount_with_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Wad fee charged to the purse'
+ ,'wad_fee'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Total deposit fees charged to the purse'
+ ,'deposit_fees'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE'
+ ,'reserve_sig'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE'
+ ,'purse_sig'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_wad_out_entries(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_out_entries';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wad_out_entry_serial_id_key'
+ ' UNIQUE (wad_out_entry_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_wad_out_entries()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wad_out_entries';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_wad_out'
+ ' FOREIGN KEY(wad_out_serial_id)'
+ ' REFERENCES wads_out (wad_out_serial_id) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wad_out_entries'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wad_out_entries'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('wad_out_entries'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-wads_in.sql b/src/exchangedb/0002-wads_in.sql
new file mode 100644
index 000000000..479589ba4
--- /dev/null
+++ b/src/exchangedb/0002-wads_in.sql
@@ -0,0 +1,107 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_wads_in(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wads_in';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
+ ',origin_exchange_url TEXT NOT NULL'
+ ',amount taler_amount NOT NULL'
+ ',arrival_time INT8 NOT NULL'
+ ',UNIQUE (wad_id, origin_exchange_url)'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (wad_id)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Incoming exchange-to-exchange wad wire transfers'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Unique identifier of the wad, part of the wire transfer subject'
+ ,'wad_id'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Base URL of the originating URL, also part of the wire transfer subject'
+ ,'origin_exchange_url'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Actual amount that was received by our exchange'
+ ,'amount'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the wad was received'
+ ,'arrival_time'
+ ,table_name
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_wads_in(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wads_in';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wad_in_serial_id_key'
+ ' UNIQUE (wad_in_serial_id) '
+ ',ADD CONSTRAINT ' || table_name || '_wad_is_origin_exchange_url_key'
+ ' UNIQUE (wad_id, origin_exchange_url) '
+ );
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wads_in'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wads_in'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-wads_out.sql b/src/exchangedb/0002-wads_out.sql
new file mode 100644
index 000000000..e52010e96
--- /dev/null
+++ b/src/exchangedb/0002-wads_out.sql
@@ -0,0 +1,128 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_wads_out(
+ IN shard_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wads_out';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I '
+ '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
+ ',partner_serial_id INT8 NOT NULL'
+ ',amount taler_amount NOT NULL'
+ ',execution_time INT8 NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (wad_id)'
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'Wire transfers made to another exchange to transfer purse funds'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Unique identifier of the wad, part of the wire transfer subject'
+ ,'wad_id'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'target exchange of the wad'
+ ,'partner_serial_id'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Amount that was wired'
+ ,'amount'
+ ,table_name
+ ,shard_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Time when the wire transfer was scheduled'
+ ,'execution_time'
+ ,table_name
+ ,shard_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_wads_out(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wads_out';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wad_out_serial_id_key'
+ ' UNIQUE (wad_out_serial_id) '
+ );
+END
+$$;
+
+
+CREATE FUNCTION foreign_table_wads_out()
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wads_out';
+BEGIN
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_foreign_partner'
+ ' FOREIGN KEY(partner_serial_id)'
+ ' REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wads_out'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wads_out'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('wads_out'
+ ,'exchange-0002'
+ ,'foreign'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-wire_accounts.sql b/src/exchangedb/0002-wire_accounts.sql
new file mode 100644
index 000000000..dba522d7b
--- /dev/null
+++ b/src/exchangedb/0002-wire_accounts.sql
@@ -0,0 +1,45 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE wire_accounts
+ (payto_uri TEXT PRIMARY KEY
+ ,master_sig BYTEA CHECK (LENGTH(master_sig)=64)
+ ,is_active BOOLEAN NOT NULL
+ ,last_change INT8 NOT NULL
+ ,conversion_url TEXT DEFAULT (NULL)
+ ,debit_restrictions TEXT DEFAULT (NULL)
+ ,credit_restrictions TEXT DEFAULT (NULL)
+ );
+COMMENT ON TABLE wire_accounts
+ IS 'Table with current and historic bank accounts of the exchange. Entries never expire as we need to remember the last_change column indefinitely.';
+COMMENT ON COLUMN wire_accounts.payto_uri
+ IS 'payto URI (RFC 8905) with the bank account of the exchange.';
+COMMENT ON COLUMN wire_accounts.master_sig
+ IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS';
+COMMENT ON COLUMN wire_accounts.is_active
+ IS 'true if we are currently supporting the use of this account.';
+COMMENT ON COLUMN wire_accounts.last_change
+ IS 'Latest time when active status changed. Used to detect replays of old messages.';
+COMMENT ON COLUMN wire_accounts.conversion_url
+ IS 'URL of a currency conversion service if conversion is needed when this account is used; NULL if there is no conversion.';
+COMMENT ON COLUMN wire_accounts.debit_restrictions
+ IS 'JSON array describing restrictions imposed when debiting this account. Empty for no restrictions, NULL if account was migrated from previous database revision or account is disabled.';
+COMMENT ON COLUMN wire_accounts.credit_restrictions
+ IS 'JSON array describing restrictions imposed when crediting this account. Empty for no restrictions, NULL if account was migrated from previous database revision or account is disabled.';
+
+
+-- "wire_accounts" has no sequence because it is a 'mutable' table
+-- and is of no concern to the auditor
diff --git a/src/exchangedb/0002-wire_fee.sql b/src/exchangedb/0002-wire_fee.sql
new file mode 100644
index 000000000..12cb91b98
--- /dev/null
+++ b/src/exchangedb/0002-wire_fee.sql
@@ -0,0 +1,34 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE wire_fee
+ (wire_fee_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,wire_method TEXT NOT NULL
+ ,start_date INT8 NOT NULL
+ ,end_date INT8 NOT NULL
+ ,wire_fee taler_amount NOT NULL
+ ,closing_fee taler_amount NOT NULL
+ ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
+ ,PRIMARY KEY (wire_method, start_date)
+ );
+COMMENT ON TABLE wire_fee
+ IS 'list of the wire fees of this exchange, by date';
+COMMENT ON COLUMN wire_fee.wire_fee_serial
+ IS 'needed for exchange-auditor replication logic';
+
+CREATE INDEX wire_fee_by_end_date_index
+ ON wire_fee
+ (end_date);
diff --git a/src/exchangedb/0002-wire_out.sql b/src/exchangedb/0002-wire_out.sql
new file mode 100644
index 000000000..c0f471b56
--- /dev/null
+++ b/src/exchangedb/0002-wire_out.sql
@@ -0,0 +1,130 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_wire_out(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wire_out';
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE IF NOT EXISTS %I'
+ '(wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',execution_date INT8 NOT NULL'
+ ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
+ ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
+ ',exchange_account_section TEXT NOT NULL'
+ ',amount taler_amount NOT NULL'
+ ') %s ;'
+ ,table_name
+ ,'PARTITION BY HASH (wtid_raw)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'wire transfers the exchange has executed'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'identifies the configuration section with the debit account of this payment'
+ ,'exchange_account_section'
+ ,table_name
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Identifies the credited bank account and KYC status'
+ ,'wire_target_h_payto'
+ ,table_name
+ ,partition_suffix
+ );
+END
+$$;
+
+
+CREATE FUNCTION constrain_table_wire_out(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wire_out';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'CREATE INDEX ' || table_name || '_by_wire_target_h_payto_index '
+ 'ON ' || table_name || ' '
+ '(wire_target_h_payto);'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wireout_uuid_pkey'
+ ' PRIMARY KEY (wireout_uuid)'
+ );
+END
+$$;
+
+
+CREATE FUNCTION wire_out_delete_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+ AS $$
+BEGIN
+ DELETE FROM exchange.aggregation_tracking
+ WHERE wtid_raw = OLD.wtid_raw;
+ RETURN OLD;
+END $$;
+COMMENT ON FUNCTION wire_out_delete_trigger()
+ IS 'Replicate reserve_out deletions into aggregation_tracking. This replaces an earlier use of an ON DELETE CASCADE that required a DEFERRABLE constraint and conflicted with nice partitioning.';
+
+
+CREATE FUNCTION master_table_wire_out()
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ CREATE TRIGGER wire_out_on_delete
+ AFTER DELETE
+ ON wire_out
+ FOR EACH ROW EXECUTE FUNCTION wire_out_delete_trigger();
+END $$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wire_out'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wire_out'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE),
+ ('wire_out'
+ ,'exchange-0002'
+ ,'master'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-wire_targets.sql b/src/exchangedb/0002-wire_targets.sql
new file mode 100644
index 000000000..88d67d9a5
--- /dev/null
+++ b/src/exchangedb/0002-wire_targets.sql
@@ -0,0 +1,89 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE FUNCTION create_table_wire_targets(
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ PERFORM create_partitioned_table(
+ 'CREATE TABLE %I'
+ '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
+ ',wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)'
+ ',payto_uri TEXT NOT NULL'
+ ') %s ;'
+ ,'wire_targets'
+ ,'PARTITION BY HASH (wire_target_h_payto)'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_table(
+ 'All senders and recipients of money via the exchange'
+ ,'wire_targets'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)'
+ ,'payto_uri'
+ ,'wire_targets'
+ ,partition_suffix
+ );
+ PERFORM comment_partitioned_column(
+ 'Unsalted hash of payto_uri'
+ ,'wire_target_h_payto'
+ ,'wire_targets'
+ ,partition_suffix
+ );
+END $$;
+
+
+CREATE FUNCTION constrain_table_wire_targets(
+ IN partition_suffix TEXT
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'wire_targets';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_wire_target_serial_id_key'
+ ' UNIQUE (wire_target_serial_id)'
+ );
+END
+$$;
+
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('wire_targets'
+ ,'exchange-0002'
+ ,'create'
+ ,TRUE
+ ,FALSE),
+ ('wire_targets'
+ ,'exchange-0002'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0002-work_shards.sql b/src/exchangedb/0002-work_shards.sql
new file mode 100644
index 000000000..6347d42c5
--- /dev/null
+++ b/src/exchangedb/0002-work_shards.sql
@@ -0,0 +1,56 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE TABLE work_shards
+ (shard_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
+ ,last_attempt INT8 NOT NULL
+ ,start_row INT8 NOT NULL
+ ,end_row INT8 NOT NULL
+ ,completed BOOLEAN NOT NULL DEFAULT FALSE
+ ,job_name TEXT NOT NULL
+ ,PRIMARY KEY (job_name, start_row)
+ );
+COMMENT ON TABLE work_shards
+ IS 'coordinates work between multiple processes working on the same job';
+COMMENT ON COLUMN work_shards.shard_serial_id
+ IS 'unique serial number identifying the shard';
+COMMENT ON COLUMN work_shards.last_attempt
+ IS 'last time a worker attempted to work on the shard';
+COMMENT ON COLUMN work_shards.completed
+ IS 'set to TRUE once the shard is finished by a worker';
+COMMENT ON COLUMN work_shards.start_row
+ IS 'row at which the shard scope starts, inclusive';
+COMMENT ON COLUMN work_shards.end_row
+ IS 'row at which the shard scope ends, exclusive';
+COMMENT ON COLUMN work_shards.job_name
+ IS 'unique name of the job the workers on this shard are performing';
+
+CREATE INDEX work_shards_by_job_name_completed_last_attempt_index
+ ON work_shards
+ (job_name
+ ,completed
+ ,last_attempt ASC
+ );
+
+CREATE INDEX work_shards_by_end_row_index
+ ON work_shards
+ (end_row DESC);
+
+CREATE INDEX work_shards_by_rows
+ ON work_shards
+ (job_name
+ ,start_row
+ ,end_row);
diff --git a/src/exchangedb/0003-purse_deletion.sql b/src/exchangedb/0003-purse_deletion.sql
new file mode 100644
index 000000000..66a95ff03
--- /dev/null
+++ b/src/exchangedb/0003-purse_deletion.sql
@@ -0,0 +1,52 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- Adds a 'unique' constraint to the 'purse_pub'.
+-- This is not only semantically correct, but also
+-- creates a dramatic speed-up on the
+-- pg_select_purse query (which otherwise fails to
+-- use indices correctly).
+
+CREATE FUNCTION constrain_table_purse_decision3(
+ IN partition_suffix TEXT
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'purse_decision';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD CONSTRAINT ' || table_name || '_purse_decision_purse_pub'
+ ' UNIQUE (purse_pub) '
+ );
+END
+$$;
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('purse_decision3'
+ ,'exchange-0003'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/0003-wire_accounts.sql b/src/exchangedb/0003-wire_accounts.sql
new file mode 100644
index 000000000..51fc86c80
--- /dev/null
+++ b/src/exchangedb/0003-wire_accounts.sql
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- new columns for #8000
+ALTER TABLE wire_accounts
+ ADD COLUMN priority INT8 NOT NULL DEFAULT (0),
+ ADD COLUMN bank_label TEXT DEFAULT (NULL);
+
+COMMENT ON COLUMN wire_accounts.priority
+ IS 'priority determines the order in which wallets should display wire accounts';
+COMMENT ON COLUMN wire_accounts.bank_label
+ IS 'label to show in the selector for this bank account in the wallet UI';
diff --git a/src/exchangedb/0004-refunds.sql b/src/exchangedb/0004-refunds.sql
new file mode 100644
index 000000000..eb9e7ad6e
--- /dev/null
+++ b/src/exchangedb/0004-refunds.sql
@@ -0,0 +1,35 @@
+
+CREATE FUNCTION constrain_table_refunds4 (
+ IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS void
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ table_name TEXT DEFAULT 'refunds';
+BEGIN
+ table_name = concat_ws('_', table_name, partition_suffix);
+
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' DROP CONSTRAINT ' || table_name || '_pkey'
+ );
+ EXECUTE FORMAT (
+ 'ALTER TABLE ' || table_name ||
+ ' ADD PRIMARY KEY (batch_deposit_serial_id, coin_pub, rtransaction_id) '
+ );
+END
+$$;
+
+INSERT INTO exchange_tables
+ (name
+ ,version
+ ,action
+ ,partitioned
+ ,by_range)
+ VALUES
+ ('refunds4'
+ ,'exchange-0004'
+ ,'constrain'
+ ,TRUE
+ ,FALSE);
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am
index afa2a3ac6..fd993f968 100644
--- a/src/exchangedb/Makefile.am
+++ b/src/exchangedb/Makefile.am
@@ -15,73 +15,70 @@ pkgcfg_DATA = \
sqldir = $(prefix)/share/taler/sql/exchange/
sqlinputs = \
- common-0001.sql \
- drop-common.sql \
- exchange-0001-part.sql \
- drop0001-exchange-part.sql \
- shard-0001-part.sql \
- drop0001-shard-part.sql
+ exchange_do_*.sql \
+ procedures.sql.in \
+ 0002-*.sql \
+ 0003-*.sql \
+ 0004-*.sql \
+ exchange-0002.sql.in \
+ exchange-0003.sql.in \
+ exchange-0004.sql.in
sql_DATA = \
- benchmark-0000.sql \
benchmark-0001.sql \
- exchange-0000.sql \
+ versioning.sql \
+ auditor-triggers-0001.sql \
exchange-0001.sql \
- drop0001.sql \
- shard-0000.sql \
- shard-0001.sql \
- shard-drop0001.sql
-
+ exchange-0002.sql \
+ exchange-0003.sql \
+ exchange-0004.sql \
+ drop.sql \
+ procedures.sql
BUILT_SOURCES = \
- shard-0000.sql \
- shard-0001.sql \
+ benchmark-0001.sql \
+ drop.sql \
exchange-0001.sql \
- drop0001.sql \
- shard-drop0001.sql
+ procedures.sql
CLEANFILES = \
- shard-0000.sql \
- shard-0001.sql \
- exchange-0001.sql \
- drop0001.sql \
- shard-drop0001.sql
+ exchange-0002.sql \
+ exchange-0003.sql \
+ procedures.sql
-exchange-0001.sql: common-0001.sql exchange-0001-part.sql
- chmod +w $@ || true
- cat common-0001.sql exchange-0001-part.sql >$@
+procedures.sql: procedures.sql.in exchange_do_*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < procedures.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
chmod ugo-w $@
-shard-0001.sql: common-0001.sql shard-0001-part.sql
- chmod +w $@ || true
- cat common-0001.sql shard-0001-part.sql >$@
+exchange-0002.sql: exchange-0002.sql.in 0002-*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < exchange-0002.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
chmod ugo-w $@
-shard-0000.sql: exchange-0000.sql
- chmod +w $@ || true
- cp exchange-0000.sql $@
+exchange-0003.sql: exchange-0003.sql.in 0003-*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < exchange-0003.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
chmod ugo-w $@
-drop0001.sql: drop-common.sql drop0001-exchange-part.sql
- chmod +w $@ || true
- cat drop-common.sql drop0001-exchange-part.sql >$@
+exchange-0004.sql: exchange-0004.sql.in 0004-*.sql
+ chmod +w $@ 2> /dev/null || true
+ gcc -E -P -undef - < exchange-0004.sql.in 2>/dev/null | sed -e "s/--.*//" | awk 'NF' - >$@
chmod ugo-w $@
-shard-drop0001.sql: drop-common.sql drop0001-shard-part.sql
- chmod +w $@ || true
- cat drop-common.sql drop0001-shard-part.sql >$@
- chmod ugo-w $@
+check_SCRIPTS = \
+ test_idempotency.sh
EXTRA_DIST = \
exchangedb.conf \
exchangedb-postgres.conf \
- plugin_exchangedb_common.c \
- irbt_callbacks.c \
- lrbt_callbacks.c \
bench-db-postgres.conf \
test-exchange-db-postgres.conf \
$(sqlinputs) \
- $(sql_DATA)
+ $(sql_DATA) \
+ $(check_SCRIPTS) \
+ pg_template.h pg_template.c \
+ pg_template.sh
plugindir = $(libdir)/taler
@@ -91,19 +88,203 @@ plugin_LTLIBRARIES = \
endif
libtaler_plugin_exchangedb_postgres_la_SOURCES = \
- plugin_exchangedb_postgres.c
-libtaler_plugin_exchangedb_postgres_la_LIBADD = \
- $(LTLIBINTL)
+ plugin_exchangedb_common.c plugin_exchangedb_common.h \
+ pg_setup_wire_target.h pg_setup_wire_target.c \
+ pg_compute_shard.h pg_compute_shard.c \
+ plugin_exchangedb_postgres.c pg_helper.h \
+ pg_reserves_update.h pg_reserves_update.c \
+ pg_select_aggregation_amounts_for_kyc_check.h pg_select_aggregation_amounts_for_kyc_check.c \
+ pg_lookup_wire_fee_by_time.h pg_lookup_wire_fee_by_time.c \
+ pg_select_satisfied_kyc_processes.h pg_select_satisfied_kyc_processes.c \
+ pg_get_pending_kyc_requirement_process.h pg_get_pending_kyc_requirement_process.c \
+ pg_kyc_provider_account_lookup.h pg_kyc_provider_account_lookup.c \
+ pg_lookup_kyc_requirement_by_row.h pg_lookup_kyc_requirement_by_row.c \
+ pg_insert_kyc_requirement_for_account.h pg_insert_kyc_requirement_for_account.c \
+ pg_lookup_kyc_process_by_account.h pg_lookup_kyc_process_by_account.c \
+ pg_update_kyc_process_by_row.h pg_update_kyc_process_by_row.c \
+ pg_insert_kyc_requirement_process.h pg_insert_kyc_requirement_process.c \
+ pg_select_withdraw_amounts_for_kyc_check.h pg_select_withdraw_amounts_for_kyc_check.c \
+ pg_select_merge_amounts_for_kyc_check.h pg_select_merge_amounts_for_kyc_check.c \
+ pg_profit_drains_set_finished.h pg_profit_drains_set_finished.c \
+ pg_profit_drains_get_pending.h pg_profit_drains_get_pending.c \
+ pg_get_drain_profit.h pg_get_drain_profit.c \
+ pg_get_purse_deposit.h pg_get_purse_deposit.c \
+ pg_insert_contract.h pg_insert_contract.c \
+ pg_select_aml_threshold.h pg_select_aml_threshold.c \
+ pg_select_contract.h pg_select_contract.c \
+ pg_select_purse_merge.h pg_select_purse_merge.c \
+ pg_select_contract_by_purse.h pg_select_contract_by_purse.c \
+ pg_insert_drain_profit.h pg_insert_drain_profit.c \
+ pg_insert_kyc_failure.h pg_insert_kyc_failure.c \
+ pg_inject_auditor_triggers.h pg_inject_auditor_triggers.c \
+ pg_create_tables.h pg_create_tables.c \
+ pg_event_listen.h pg_event_listen.c \
+ pg_event_listen_cancel.h pg_event_listen_cancel.c \
+ pg_event_notify.h pg_event_notify.c \
+ pg_get_denomination_info.h pg_get_denomination_info.c \
+ pg_iterate_denomination_info.h pg_iterate_denomination_info.c \
+ pg_iterate_denominations.h pg_iterate_denominations.c \
+ pg_iterate_active_auditors.h pg_iterate_active_auditors.c \
+ pg_iterate_auditor_denominations.h pg_iterate_auditor_denominations.c \
+ pg_reserves_get.h pg_reserves_get.c \
+ pg_reserves_get_origin.h pg_reserves_get_origin.c \
+ pg_drain_kyc_alert.h pg_drain_kyc_alert.c \
+ pg_reserves_in_insert.h pg_reserves_in_insert.c \
+ pg_get_withdraw_info.h pg_get_withdraw_info.c \
+ pg_do_age_withdraw.h pg_do_age_withdraw.c \
+ pg_get_age_withdraw.h pg_get_age_withdraw.c \
+ pg_batch_ensure_coin_known.h pg_batch_ensure_coin_known.c \
+ pg_do_batch_withdraw.h pg_do_batch_withdraw.c \
+ pg_get_policy_details.h pg_get_policy_details.c \
+ pg_persist_policy_details.h pg_persist_policy_details.c \
+ pg_do_deposit.h pg_do_deposit.c \
+ pg_get_wire_hash_for_contract.h pg_get_wire_hash_for_contract.c \
+ pg_add_policy_fulfillment_proof.h pg_add_policy_fulfillment_proof.c \
+ pg_do_melt.h pg_do_melt.c \
+ pg_do_refund.h pg_do_refund.c \
+ pg_do_recoup.h pg_do_recoup.c \
+ pg_do_recoup_refresh.h pg_do_recoup_refresh.c \
+ pg_get_reserve_balance.h pg_get_reserve_balance.c \
+ pg_count_known_coins.h pg_count_known_coins.c \
+ pg_ensure_coin_known.h pg_ensure_coin_known.c \
+ pg_get_known_coin.h pg_get_known_coin.c \
+ pg_get_signature_for_known_coin.h pg_get_signature_for_known_coin.c \
+ pg_get_coin_denomination.h pg_get_coin_denomination.c \
+ pg_have_deposit2.h pg_have_deposit2.c \
+ pg_aggregate.h pg_aggregate.c \
+ pg_create_aggregation_transient.h pg_create_aggregation_transient.c \
+ pg_insert_kyc_attributes.h pg_insert_kyc_attributes.c \
+ pg_select_similar_kyc_attributes.h pg_select_similar_kyc_attributes.c \
+ pg_select_kyc_attributes.h pg_select_kyc_attributes.c \
+ pg_insert_aml_officer.h pg_insert_aml_officer.c \
+ pg_test_aml_officer.h pg_test_aml_officer.c \
+ pg_lookup_aml_officer.h pg_lookup_aml_officer.c \
+ pg_trigger_aml_process.h pg_trigger_aml_process.c \
+ pg_select_aml_process.h pg_select_aml_process.c \
+ pg_select_aml_history.h pg_select_aml_history.c \
+ pg_insert_aml_decision.h pg_insert_aml_decision.c \
+ pg_select_aggregation_transient.h pg_select_aggregation_transient.c \
+ pg_find_aggregation_transient.h pg_find_aggregation_transient.c \
+ pg_update_aggregation_transient.h pg_update_aggregation_transient.c \
+ pg_get_ready_deposit.h pg_get_ready_deposit.c \
+ pg_insert_refund.h pg_insert_refund.c \
+ pg_select_refunds_by_coin.h pg_select_refunds_by_coin.c \
+ pg_get_melt.h pg_get_melt.c \
+ pg_insert_refresh_reveal.h pg_insert_refresh_reveal.c \
+ pg_get_refresh_reveal.h pg_get_refresh_reveal.c \
+ pg_lookup_wire_transfer.h pg_lookup_wire_transfer.c \
+ pg_lookup_transfer_by_deposit.h pg_lookup_transfer_by_deposit.c \
+ pg_insert_wire_fee.h pg_insert_wire_fee.c \
+ pg_insert_global_fee.h pg_insert_global_fee.c \
+ pg_get_wire_fee.h pg_get_wire_fee.c \
+ pg_get_global_fee.h pg_get_global_fee.c \
+ pg_get_global_fees.h pg_get_global_fees.c \
+ pg_insert_reserve_closed.h pg_insert_reserve_closed.c \
+ pg_wire_prepare_data_insert.h pg_wire_prepare_data_insert.c \
+ pg_wire_prepare_data_mark_finished.h pg_wire_prepare_data_mark_finished.c \
+ pg_wire_prepare_data_mark_failed.h pg_wire_prepare_data_mark_failed.c \
+ pg_wire_prepare_data_get.h pg_wire_prepare_data_get.c \
+ pg_start_deferred_wire_out.h pg_start_deferred_wire_out.c \
+ pg_store_wire_transfer_out.h pg_store_wire_transfer_out.c \
+ pg_gc.h pg_gc.c \
+ pg_select_coin_deposits_above_serial_id.h pg_select_coin_deposits_above_serial_id.c \
+ pg_select_purse_decisions_above_serial_id.h pg_select_purse_decisions_above_serial_id.c \
+ pg_select_purse_deposits_by_purse.h pg_select_purse_deposits_by_purse.c \
+ pg_select_refreshes_above_serial_id.h pg_select_refreshes_above_serial_id.c \
+ pg_select_refunds_above_serial_id.h pg_select_refunds_above_serial_id.c \
+ pg_select_reserves_in_above_serial_id.h pg_select_reserves_in_above_serial_id.c \
+ pg_select_reserves_in_above_serial_id_by_account.h pg_select_reserves_in_above_serial_id_by_account.c \
+ pg_select_withdrawals_above_serial_id.h pg_select_withdrawals_above_serial_id.c \
+ pg_select_wire_out_above_serial_id.h pg_select_wire_out_above_serial_id.c \
+ pg_select_wire_out_above_serial_id_by_account.h pg_select_wire_out_above_serial_id_by_account.c \
+ pg_select_recoup_above_serial_id.h pg_select_recoup_above_serial_id.c \
+ pg_select_recoup_refresh_above_serial_id.h pg_select_recoup_refresh_above_serial_id.c \
+ pg_get_reserve_by_h_blind.h pg_get_reserve_by_h_blind.c \
+ pg_get_old_coin_by_h_blind.h pg_get_old_coin_by_h_blind.c \
+ pg_insert_denomination_revocation.h pg_insert_denomination_revocation.c \
+ pg_get_denomination_revocation.h pg_get_denomination_revocation.c \
+ pg_select_batch_deposits_missing_wire.h pg_select_batch_deposits_missing_wire.c \
+ pg_select_justification_for_missing_wire.h pg_select_justification_for_missing_wire.c \
+ pg_select_aggregations_above_serial.h pg_select_aggregations_above_serial.c \
+ pg_lookup_auditor_timestamp.h pg_lookup_auditor_timestamp.c \
+ pg_lookup_auditor_status.h pg_lookup_auditor_status.c \
+ pg_insert_auditor.h pg_insert_auditor.c \
+ pg_lookup_wire_timestamp.h pg_lookup_wire_timestamp.c \
+ pg_insert_wire.h pg_insert_wire.c \
+ pg_update_wire.h pg_update_wire.c \
+ pg_get_wire_accounts.h pg_get_wire_accounts.c \
+ pg_get_wire_fees.h pg_get_wire_fees.c \
+ pg_insert_signkey_revocation.h pg_insert_signkey_revocation.c \
+ pg_lookup_signkey_revocation.h pg_lookup_signkey_revocation.c \
+ pg_lookup_denomination_key.h pg_lookup_denomination_key.c \
+ pg_insert_auditor_denom_sig.h pg_insert_auditor_denom_sig.c \
+ pg_select_auditor_denom_sig.h pg_select_auditor_denom_sig.c \
+ pg_add_denomination_key.h pg_add_denomination_key.c \
+ pg_lookup_signing_key.h pg_lookup_signing_key.c \
+ pg_begin_shard.h pg_begin_shard.c \
+ pg_abort_shard.h pg_abort_shard.c \
+ pg_complete_shard.h pg_complete_shard.c \
+ pg_release_revolving_shard.h pg_release_revolving_shard.c \
+ pg_delete_shard_locks.h pg_delete_shard_locks.c \
+ pg_set_extension_manifest.h pg_set_extension_manifest.c \
+ pg_insert_partner.h pg_insert_partner.c \
+ pg_expire_purse.h pg_expire_purse.c \
+ pg_select_purse_by_merge_pub.h pg_select_purse_by_merge_pub.c \
+ pg_set_purse_balance.h pg_set_purse_balance.c \
+ pg_do_reserve_purse.h pg_do_reserve_purse.c \
+ pg_lookup_global_fee_by_time.h pg_lookup_global_fee_by_time.c \
+ pg_do_purse_deposit.h pg_do_purse_deposit.c \
+ pg_activate_signing_key.h pg_activate_signing_key.c \
+ pg_update_auditor.h pg_update_auditor.c \
+ pg_begin_revolving_shard.h pg_begin_revolving_shard.c \
+ pg_get_extension_manifest.h pg_get_extension_manifest.c \
+ pg_do_purse_merge.h pg_do_purse_merge.c \
+ pg_start_read_committed.h pg_start_read_committed.c \
+ pg_start_read_only.h pg_start_read_only.c \
+ pg_insert_denomination_info.h pg_insert_denomination_info.c \
+ pg_do_batch_withdraw_insert.h pg_do_batch_withdraw_insert.c \
+ pg_do_reserve_open.c pg_do_reserve_open.h \
+ pg_do_purse_delete.c pg_do_purse_delete.h \
+ pg_preflight.h pg_preflight.c \
+ pg_iterate_active_signkeys.h pg_iterate_active_signkeys.c \
+ pg_commit.h pg_commit.c \
+ pg_get_coin_transactions.c pg_get_coin_transactions.h \
+ pg_get_expired_reserves.c pg_get_expired_reserves.h \
+ pg_start.h pg_start.c \
+ pg_rollback.h pg_rollback.c \
+ pg_get_purse_request.c pg_get_purse_request.h \
+ pg_get_reserve_history.c pg_get_reserve_history.h \
+ pg_get_unfinished_close_requests.c pg_get_unfinished_close_requests.h \
+ pg_insert_close_request.c pg_insert_close_request.h \
+ pg_delete_aggregation_transient.h pg_delete_aggregation_transient.c \
+ pg_get_link_data.h pg_get_link_data.c \
+ pg_drop_tables.h pg_drop_tables.c \
+ pg_insert_purse_request.h pg_insert_purse_request.c \
+ pg_insert_records_by_table.c pg_insert_records_by_table.h \
+ pg_insert_reserve_open_deposit.c pg_insert_reserve_open_deposit.h \
+ pg_iterate_kyc_reference.c pg_iterate_kyc_reference.h \
+ pg_iterate_reserve_close_info.c pg_iterate_reserve_close_info.h \
+ pg_lookup_records_by_table.c pg_lookup_records_by_table.h \
+ pg_lookup_serial_by_table.c pg_lookup_serial_by_table.h \
+ pg_select_reserve_close_info.c pg_select_reserve_close_info.h \
+ pg_select_reserve_closed_above_serial_id.c pg_select_reserve_closed_above_serial_id.h \
+ pg_select_purse.h pg_select_purse.c \
+ pg_select_purse_requests_above_serial_id.h pg_select_purse_requests_above_serial_id.c \
+ pg_select_purse_merges_above_serial_id.h pg_select_purse_merges_above_serial_id.c \
+ pg_select_purse_deposits_above_serial_id.h pg_select_purse_deposits_above_serial_id.c \
+ pg_select_account_merges_above_serial_id.h pg_select_account_merges_above_serial_id.c \
+ pg_select_all_purse_decisions_above_serial_id.h pg_select_all_purse_decisions_above_serial_id.c \
+ pg_select_reserve_open_above_serial_id.c pg_select_reserve_open_above_serial_id.h
libtaler_plugin_exchangedb_postgres_la_LDFLAGS = \
- $(TALER_PLUGIN_LDFLAGS) \
+ $(TALER_PLUGIN_LDFLAGS)
+libtaler_plugin_exchangedb_postgres_la_LIBADD = \
+ $(LTLIBINTL) \
$(top_builddir)/src/pq/libtalerpq.la \
- $(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lpq \
- -lpthread \
-lgnunetpq \
-lgnunetutil \
-ljansson \
+ -lpq \
$(XLIB)
lib_LTLIBRARIES = \
@@ -125,12 +306,19 @@ libtalerexchangedb_la_LDFLAGS = \
check_PROGRAMS = \
- test-exchangedb-postgres \
- bench-db-postgres
+ test-exchangedb-postgres
+
+noinst_PROGRAMS = \
+ bench-db-postgres\
+ perf_get_link_data-postgres\
+ perf_select_refunds_by_coin-postgres\
+ perf_reserves_in_insert-postgres \
+ perf_deposits_get_ready-postgres
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \
- test-exchangedb-postgres
+ $(check_SCRIPTS) \
+ $(check_PROGRAMS)
test_exchangedb_postgres_SOURCES = \
test_exchangedb.c
@@ -154,5 +342,58 @@ bench_db_postgres_LDADD = \
-lgnunetutil \
$(XLIB)
+perf_reserves_in_insert_postgres_SOURCES = \
+ perf_reserves_in_insert.c
+perf_reserves_in_insert_postgres_LDADD = \
+ libtalerexchangedb.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/pq/libtalerpq.la \
+ -ljansson \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lm \
+ $(XLIB)
+
+perf_select_refunds_by_coin_postgres_SOURCES = \
+ perf_select_refunds_by_coin.c
+perf_select_refunds_by_coin_postgres_LDADD = \
+ libtalerexchangedb.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/pq/libtalerpq.la \
+ -ljansson \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lm \
+ $(XLIB)
+
+perf_get_link_data_postgres_SOURCES = \
+ perf_get_link_data.c
+perf_get_link_data_postgres_LDADD = \
+ libtalerexchangedb.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/pq/libtalerpq.la \
+ -ljansson \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lm \
+ $(XLIB)
+
+perf_deposits_get_ready_postgres_SOURCES = \
+ perf_deposits_get_ready.c
+perf_deposits_get_ready_postgres_LDADD = \
+ libtalerexchangedb.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/pq/libtalerpq.la \
+ -ljansson \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lm \
+ $(XLIB)
+
+
EXTRA_test_exchangedb_postgres_DEPENDENCIES = \
libtaler_plugin_exchangedb_postgres.la
diff --git a/src/exchangedb/auditor-triggers-0001.sql b/src/exchangedb/auditor-triggers-0001.sql
new file mode 100644
index 000000000..4e2ea66ce
--- /dev/null
+++ b/src/exchangedb/auditor-triggers-0001.sql
@@ -0,0 +1,41 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- Everything in one big transaction
+BEGIN;
+
+SELECT _v.register_patch('auditor-triggers-0001');
+
+SET search_path TO exchange;
+
+CREATE OR REPLACE FUNCTION auditor_new_deposits_trigger()
+ RETURNS trigger
+ LANGUAGE plpgsql
+AS $$
+BEGIN
+ NOTIFY XFIXME;
+ RETURN NEW;
+END $$;
+COMMENT ON FUNCTION auditor_new_deposits_trigger()
+ IS 'Call XXX on new entry';
+
+CREATE TRIGGER auditor_notify_helper_insert_deposits
+ AFTER INSERT
+ ON exchange.batch_deposits
+EXECUTE PROCEDURE auditor_new_deposits_trigger();
+
+
+COMMIT;
diff --git a/src/exchangedb/bench-db-postgres.conf b/src/exchangedb/bench-db-postgres.conf
index 837ae41e2..d51cf9175 100644
--- a/src/exchangedb/bench-db-postgres.conf
+++ b/src/exchangedb/bench-db-postgres.conf
@@ -8,3 +8,7 @@ CONFIG = postgres:///talercheck
# Where are the SQL files to setup our tables?
# Important: this MUST end with a "/"!
SQL_DIR = $DATADIR/sql/exchange/
+
+[exchangedb]
+# Number of purses per account by default.
+DEFAULT_PURSE_LIMIT = 1 \ No newline at end of file
diff --git a/src/exchangedb/bench_db.c b/src/exchangedb/bench_db.c
index a8dbfbfa5..302d23062 100644
--- a/src/exchangedb/bench_db.c
+++ b/src/exchangedb/bench_db.c
@@ -51,32 +51,28 @@ prepare (struct GNUNET_PQ_Context *conn)
"(hc"
",expiration_date"
") VALUES "
- "($1, $2);",
- 2),
+ "($1, $2);"),
/* Used in #postgres_iterate_denomination_info() */
GNUNET_PQ_make_prepare (
"bm_select",
"SELECT"
" expiration_date"
" FROM benchmap"
- " WHERE hc=$1;",
- 1),
+ " WHERE hc=$1;"),
GNUNET_PQ_make_prepare (
"bhm_insert",
"INSERT INTO benchhmap "
"(hc"
",expiration_date"
") VALUES "
- "($1, $2);",
- 2),
+ "($1, $2);"),
/* Used in #postgres_iterate_denomination_info() */
GNUNET_PQ_make_prepare (
"bhm_select",
"SELECT"
" expiration_date"
" FROM benchhmap"
- " WHERE hc=$1;",
- 1),
+ " WHERE hc=$1;"),
GNUNET_PQ_make_prepare (
"bem_insert",
"INSERT INTO benchemap "
@@ -84,16 +80,14 @@ prepare (struct GNUNET_PQ_Context *conn)
",ihc"
",expiration_date"
") VALUES "
- "($1, $2, $3);",
- 3),
+ "($1, $2, $3);"),
/* Used in #postgres_iterate_denomination_info() */
GNUNET_PQ_make_prepare (
"bem_select",
"SELECT"
" expiration_date"
" FROM benchemap"
- " WHERE ihc=$1 AND hc=$2;",
- 2),
+ " WHERE ihc=$1 AND hc=$2;"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
enum GNUNET_GenericReturnValue ret;
@@ -175,9 +169,9 @@ bem_insert (struct GNUNET_PQ_Context *conn,
GNUNET_CRYPTO_hash (&b,
sizeof (b),
&hc);
- memcpy (&ihc,
- &hc,
- sizeof (ihc));
+ GNUNET_memcpy (&ihc,
+ &hc,
+ sizeof (ihc));
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (&hc),
@@ -271,9 +265,9 @@ bem_select (struct GNUNET_PQ_Context *conn,
GNUNET_CRYPTO_hash (&b,
sizeof (b),
&hc);
- memcpy (&ihc,
- &hc,
- sizeof (ihc));
+ GNUNET_memcpy (&ihc,
+ &hc,
+ sizeof (ihc));
{
struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_uint32 (&ihc),
diff --git a/src/exchangedb/common-0001.sql b/src/exchangedb/common-0001.sql
deleted file mode 100644
index 5ae67edd1..000000000
--- a/src/exchangedb/common-0001.sql
+++ /dev/null
@@ -1,2747 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--------------------- Tables ----------------------------
-
-CREATE OR REPLACE FUNCTION create_partitioned_table(
- IN table_definition VARCHAR
- ,IN table_name VARCHAR
- ,IN main_table_partition_str VARCHAR -- Used only when it is the main table - we do not partition shard tables
- ,IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- IF shard_suffix IS NOT NULL THEN
- table_name=table_name || '_' || shard_suffix;
- main_table_partition_str = '';
- END IF;
-
- EXECUTE FORMAT(
- table_definition,
- table_name,
- main_table_partition_str
- );
-
-END
-$$;
-
------------------------ wire_targets ---------------------------
-
-CREATE OR REPLACE FUNCTION create_table_wire_targets(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_target_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',wire_target_h_payto BYTEA PRIMARY KEY CHECK (LENGTH(wire_target_h_payto)=32)'
- ',payto_uri VARCHAR NOT NULL'
- ',kyc_ok BOOLEAN NOT NULL DEFAULT (FALSE)'
- ',external_id VARCHAR'
- ') %s ;'
- ,'wire_targets'
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
--- We need a separate function for this, as we call create_table only once but need to add
--- those constraints to each partition which gets created
-CREATE OR REPLACE FUNCTION add_constraints_to_wire_targets_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- EXECUTE FORMAT (
- 'ALTER TABLE wire_targets_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_targets_' || partition_suffix || '_wire_target_serial_id_key '
- 'UNIQUE (wire_target_serial_id)'
- );
-END
-$$;
-
------------------------- reserves -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_reserves(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY'
- ',reserve_pub BYTEA PRIMARY KEY CHECK(LENGTH(reserve_pub)=32)'
- ',current_balance_val INT8 NOT NULL DEFAULT(0)'
- ',current_balance_frac INT4 NOT NULL DEFAULT(0)'
- ',purses_active INT8 NOT NULL DEFAULT(0)'
- ',purses_allowed INT8 NOT NULL DEFAULT(0)'
- ',kyc_required BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',kyc_passed BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',max_age INT4 NOT NULL DEFAULT(120)'
- ',expiration_date INT8 NOT NULL'
- ',gc_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_expiration_index '
- 'ON ' || table_name || ' '
- '(expiration_date'
- ',current_balance_val'
- ',current_balance_frac'
- ');'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_expiration_index '
- 'IS ' || quote_literal('used in get_expired_reserves') || ';'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_gc_date_index '
- 'ON ' || table_name || ' '
- '(gc_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_gc_date_index '
- 'IS ' || quote_literal('for reserve garbage collection') || ';'
- );
-
-END
-$$;
-
------------------------ reserves_in ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_reserves_in(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR default 'reserves_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',reserve_pub BYTEA PRIMARY KEY' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',wire_reference INT8 NOT NULL'
- ',credit_val INT8 NOT NULL'
- ',credit_frac INT4 NOT NULL'
- ',wire_source_h_payto BYTEA CHECK (LENGTH(wire_source_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',execution_date INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_in_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_in_serial_id);'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_section_execution_date_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section '
- ',execution_date'
- ');'
- );
- -- FIXME: where do we need this index? Can we do better?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_exch_accnt_reserve_in_serial_id_idx '
- 'ON ' || table_name || ' '
- '(exchange_account_section,'
- 'reserve_in_serial_id DESC'
- ');'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_in_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_in_' || partition_suffix || '_reserve_in_serial_id_key '
- 'UNIQUE (reserve_in_serial_id)'
- );
-END
-$$;
-
---------------------------- reserves_close -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_reserves_close(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR default 'reserves_close';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(close_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE / PRIMARY KEY'
- ',reserve_pub BYTEA NOT NULL' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE'
- ',execution_date INT8 NOT NULL'
- ',wtid BYTEA NOT NULL CHECK (LENGTH(wtid)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',closing_fee_val INT8 NOT NULL'
- ',closing_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_close_uuid_index '
- 'ON ' || table_name || ' '
- '(close_uuid);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub_index '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_close_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_close_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_close_' || partition_suffix || '_close_uuid_pkey '
- 'PRIMARY KEY (close_uuid)'
- );
-END
-$$;
-
----------------------------- reserves_out -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_reserves_out(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR default 'reserves_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64) UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial)'
- ',denom_sig BYTEA NOT NULL'
- ',reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',execution_date INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ') %s ;'
- ,'reserves_out'
- ,'PARTITION BY HASH (h_blind_ev)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_out_serial_id_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
- -- FIXME: change query to use reserves_out_by_reserve instead and materialize execution_date there as well???
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid, execution_date);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_reserve_uuid_and_execution_date_index '
- 'IS ' || quote_literal('for get_reserves_out and exchange_do_withdraw_limit_check') || ';'
- );
-
-END
-$$;
-
-
-CREATE OR REPLACE FUNCTION add_constraints_to_reserves_out_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE reserves_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT reserves_out_' || partition_suffix || '_reserve_out_serial_id_key '
- 'UNIQUE (reserve_out_serial_id)'
- );
-END
-$$;
-
-CREATE OR REPLACE FUNCTION create_table_reserves_out_by_reserve(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'reserves_out_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_uuid INT8 NOT NULL' -- REFERENCES reserves (reserve_uuid) ON DELETE CASCADE
- ',h_blind_ev BYTEA CHECK (LENGTH(h_blind_ev)=64)'
- ') %s '
- ,table_name
- ,'PARTITION BY HASH (reserve_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_uuid);'
- );
-
-END
-$$;
-
----------------------------- known_coins -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_known_coins(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR default 'known_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(known_coin_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_pub BYTEA NOT NULL PRIMARY KEY CHECK (LENGTH(coin_pub)=32)'
- ',age_commitment_hash BYTEA CHECK (LENGTH(age_commitment_hash)=32)'
- ',denom_sig BYTEA NOT NULL'
- ',remaining_val INT8 NOT NULL DEFAULT(0)'
- ',remaining_frac INT4 NOT NULL DEFAULT(0)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)' -- FIXME: or include denominations_serial? or multi-level partitioning?;
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_known_coins_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE known_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT known_coins_' || partition_suffix || '_known_coin_id_key '
- 'UNIQUE (known_coin_id)'
- );
-END
-$$;
-
----------------------------- refresh_commitments -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_refresh_commitments(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_commitments';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(melt_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',rc BYTEA PRIMARY KEY CHECK (LENGTH(rc)=64)'
- ',old_coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',old_coin_sig BYTEA NOT NULL CHECK(LENGTH(old_coin_sig)=64)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',noreveal_index INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (rc)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- Note: index spans partitions, may need to be materialized.
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_old_coin_pub_index '
- 'ON ' || table_name || ' '
- '(old_coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_commitments_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_commitments_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_commitments_' || partition_suffix || '_melt_serial_id_key '
- 'UNIQUE (melt_serial_id)'
- );
-END
-$$;
-
------------------------------- refresh_revealed_coins --------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_refresh_revealed_coins(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_revealed_coins';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rrc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 NOT NULL' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',freshcoin_index INT4 NOT NULL'
- ',link_sig BYTEA NOT NULL CHECK(LENGTH(link_sig)=64)'
- ',denominations_serial INT8 NOT NULL' -- REFERENCES denominations (denominations_serial) ON DELETE CASCADE'
- ',coin_ev BYTEA NOT NULL' -- UNIQUE'
- ',h_coin_ev BYTEA NOT NULL CHECK(LENGTH(h_coin_ev)=64)' -- UNIQUE'
- ',ev_sig BYTEA NOT NULL'
- ',ewv BYTEA NOT NULL'
- -- ,PRIMARY KEY (melt_serial_id, freshcoin_index) -- done per shard
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_coins_by_melt_serial_id_index '
- 'ON ' || table_name || ' '
- '(melt_serial_id);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_revealed_coins_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_revealed_coins_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_rrc_serial_key '
- 'UNIQUE (rrc_serial) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_coin_ev_key '
- 'UNIQUE (coin_ev) '
- ',ADD CONSTRAINT refresh_revealed_coins_' || partition_suffix || '_h_coin_ev_key '
- 'UNIQUE (h_coin_ev) '
- ',ADD PRIMARY KEY (melt_serial_id, freshcoin_index) '
- );
-END
-$$;
-
------------------------------ refresh_transfer_keys ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_refresh_transfer_keys(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refresh_transfer_keys';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(rtc_serial BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',melt_serial_id INT8 PRIMARY KEY' -- REFERENCES refresh_commitments (melt_serial_id) ON DELETE CASCADE'
- ',transfer_pub BYTEA NOT NULL CHECK(LENGTH(transfer_pub)=32)'
- ',transfer_privs BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (melt_serial_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_refresh_transfer_keys_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refresh_transfer_keys_' || partition_suffix || ' '
- 'ADD CONSTRAINT refresh_transfer_keys_' || partition_suffix || '_rtc_serial_key '
- 'UNIQUE (rtc_serial)'
- );
-END
-$$;
-
----------------------------- deposits -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_deposits(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',known_coin_id INT8 NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE' --- FIXME: column needed???
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wallet_timestamp INT8 NOT NULL'
- ',exchange_timestamp INT8 NOT NULL'
- ',refund_deadline INT8 NOT NULL'
- ',wire_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)'
- ',wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',done BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_blocked BOOLEAN NOT NULL DEFAULT FALSE'
- ',extension_details_serial_id INT8' -- REFERENCES extension_details (extension_details_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_deposits_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT deposits_' || partition_suffix || '_deposit_serial_id_pkey '
- 'PRIMARY KEY (deposit_serial_id) '
- ',ADD CONSTRAINT deposits_' || partition_suffix || '_coin_pub_merchant_pub_h_contract_terms_key '
- 'UNIQUE (coin_pub, merchant_pub, h_contract_terms)'
- );
-END
-$$;
-
-CREATE OR REPLACE FUNCTION create_table_deposits_by_ready(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_by_ready';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wire_deadline INT8 NOT NULL'
- ',shard INT8 NOT NULL'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)'
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (wire_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(wire_deadline ASC, shard ASC, coin_pub);'
- );
-
-END
-$$;
-
-
-CREATE OR REPLACE FUNCTION create_table_deposits_for_matching(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'deposits_for_matching';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_deadline INT8 NOT NULL'
- ',merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8'
- ') %s ;'
- ,table_name
- ,'PARTITION BY RANGE (refund_deadline)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(refund_deadline ASC, merchant_pub, coin_pub);'
- );
-
-END
-$$;
-
------------------------------ refunds ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_refunds(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(refund_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE
- ',deposit_serial_id INT8 NOT NULL' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE'
- ',merchant_sig BYTEA NOT NULL CHECK(LENGTH(merchant_sig)=64)'
- ',rtransaction_id INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- -- ,PRIMARY KEY (deposit_serial_id, rtransaction_id) -- done per shard!
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_refunds_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT refunds_' || partition_suffix || '_refund_serial_id_key '
- 'UNIQUE (refund_serial_id) '
- ',ADD PRIMARY KEY (deposit_serial_id, rtransaction_id) '
- );
-END
-$$;
-
----------------------------- wire_out -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_wire_out(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wire_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(wireout_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- PRIMARY KEY'
- ',execution_date INT8 NOT NULL'
- ',wtid_raw BYTEA UNIQUE NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wtid_raw)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wire_target_h_payto_index '
- 'ON ' || table_name || ' '
- '(wire_target_h_payto);'
- );
-
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_wire_out_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS void
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wire_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wire_out_' || partition_suffix || '_wireout_uuid_pkey '
- 'PRIMARY KEY (wireout_uuid)'
- );
-END
-$$;
-
----------------------------- aggregation_transient ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_aggregation_transient(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_transient';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)'
- ',exchange_account_section TEXT NOT NULL'
- ',wtid_raw BYTEA NOT NULL CHECK (LENGTH(wtid_raw)=32)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wire_target_h_payto)'
- ,shard_suffix
- );
-
-END
-$$;
-
----------------------------- aggregation_tracking -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_aggregation_tracking(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'aggregation_tracking';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(aggregation_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',deposit_serial_id INT8 PRIMARY KEY' -- REFERENCES deposits (deposit_serial_id) ON DELETE CASCADE' -- FIXME change to coin_pub + deposit_serial_id for more efficient depost -- or something else ???
- ',wtid_raw BYTEA NOT NULL' -- CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (deposit_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_wtid_raw_index '
- 'ON ' || table_name || ' '
- '(wtid_raw);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_wtid_raw_index '
- 'IS ' || quote_literal('for lookup_transactions') || ';'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_aggregation_tracking_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE aggregation_tracking_' || partition_suffix || ' '
- 'ADD CONSTRAINT aggregation_tracking_' || partition_suffix || '_aggregation_serial_id_key '
- 'UNIQUE (aggregation_serial_id) '
- );
-END
-$$;
-
------------------------------ recoup ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_recoup(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves_out (reserve_out_serial_id) ON DELETE CASCADE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub);'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_recoup_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_' || partition_suffix || '_recoup_uuid_key '
- 'UNIQUE (recoup_uuid) '
- );
-END
-$$;
-
-CREATE OR REPLACE FUNCTION create_table_recoup_by_reserve(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_by_reserve';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(reserve_out_serial_id INT8 NOT NULL' -- REFERENCES reserves (reserve_out_serial_id) ON DELETE CASCADE
- ',coin_pub BYTEA CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_out_serial_id)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_main_index '
- 'ON ' || table_name || ' '
- '(reserve_out_serial_id);'
- );
-
-END
-$$;
-
----------------------------- recoup_refresh ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_recoup_refresh(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'recoup_refresh';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(recoup_refresh_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)' -- REFERENCES known_coins (coin_pub)
- ',known_coin_id BIGINT NOT NULL' -- REFERENCES known_coins (known_coin_id) ON DELETE CASCADE
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',coin_blind BYTEA NOT NULL CHECK(LENGTH(coin_blind)=32)'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',recoup_timestamp INT8 NOT NULL'
- ',rrc_serial INT8 NOT NULL' -- REFERENCES refresh_revealed_coins (rrc_serial) ON DELETE CASCADE -- UNIQUE'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (coin_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: any query using this index will be slow. Materialize index or change query?
- -- Also: which query uses this index?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_rrc_serial_index '
- 'ON ' || table_name || ' '
- '(rrc_serial);'
- );
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub_index '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_recoup_refresh_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE recoup_refresh_' || partition_suffix || ' '
- 'ADD CONSTRAINT recoup_refresh_' || partition_suffix || '_recoup_refresh_uuid_key '
- 'UNIQUE (recoup_refresh_uuid) '
- );
-END
-$$;
-
------------------------------ prewire ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_prewire(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'prewire';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(prewire_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY'
- ',wire_method TEXT NOT NULL'
- ',finished BOOLEAN NOT NULL DEFAULT false'
- ',failed BOOLEAN NOT NULL DEFAULT false'
- ',buf BYTEA NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (prewire_uuid)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_finished_index '
- 'ON ' || table_name || ' '
- '(finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_finished_index '
- 'IS ' || quote_literal('for gc_prewire') || ';'
- );
- -- FIXME: find a way to combine these two indices?
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_failed_finished_index '
- 'ON ' || table_name || ' '
- '(failed,finished);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_by_failed_finished_index '
- 'IS ' || quote_literal('for wire_prepare_data_get') || ';'
- );
-
-END
-$$;
-
------------------------------ cs_nonce_locks ------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_cs_nonce_locks(
- shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I'
- '(cs_nonce_lock_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE'
- ',nonce BYTEA PRIMARY KEY CHECK (LENGTH(nonce)=32)'
- ',op_hash BYTEA NOT NULL CHECK (LENGTH(op_hash)=64)'
- ',max_denomination_serial INT8 NOT NULL'
- ') %s ;'
- ,'cs_nonce_locks'
- ,'PARTITION BY HASH (nonce)'
- ,shard_suffix
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_cs_nonce_locks_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE cs_nonce_locks_' || partition_suffix || ' '
- 'ADD CONSTRAINT cs_nonce_locks_' || partition_suffix || '_cs_nonce_lock_serial_id_key '
- 'UNIQUE (cs_nonce_lock_serial_id)'
- );
-END
-$$;
-
---------------------------------------------------------------------------
--- Tables for P2P payments
---------------------------------------------------------------------------
-
-------------------------------- purse_requests ----------------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_purse_requests(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_requests_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',merge_pub BYTEA NOT NULL CHECK (LENGTH(merge_pub)=32)'
- ',purse_creation INT8 NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)'
- ',age_limit INT4 NOT NULL'
- ',flags INT4 NOT NULL'
- ',refunded BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',finished BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',in_reserve_quota BOOLEAN NOT NULL DEFAULT(FALSE)'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',purse_fee_val INT8 NOT NULL'
- ',purse_fee_frac INT4 NOT NULL'
- ',balance_val INT8 NOT NULL DEFAULT (0)'
- ',balance_frac INT4 NOT NULL DEFAULT (0)'
- ',purse_sig BYTEA NOT NULL CHECK(LENGTH(purse_sig)=64)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by merge_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_merge_pub '
- 'ON ' || table_name || ' '
- '(merge_pub);'
- );
-
- -- FIXME: drop index on master (crosses shards)?
- -- Or use materialized index? (needed?)
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_purse_expiration '
- 'ON ' || table_name || ' '
- '(purse_expiration);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_requests_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_requests_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_requests_' || partition_suffix || '_purse_requests_serial_id_key '
- 'UNIQUE (purse_requests_serial_id) '
- );
-END
-$$;
-
-
-------------------------------- purse_refunds ----------------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_purse_refunds(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_refunds';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_refunds_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_refunds_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_refunds_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_refunds_' || partition_suffix || '_purse_refunds_serial_id_key '
- 'UNIQUE (purse_refunds_serial_id) '
- );
-END
-$$;
-
-
-
-
-
----------------------------- purse_merges -----------------------------
-
-CREATE OR REPLACE FUNCTION create_table_purse_merges(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY '-- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(length(reserve_pub)=32)'--REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' --REFERENCES purse_requests (purse_pub) ON DELETE CASCADE
- ',merge_sig BYTEA NOT NULL CHECK (LENGTH(merge_sig)=64)'
- ',merge_timestamp INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_merges_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_merges_' || partition_suffix || '_purse_merge_request_serial_id_key '
- 'UNIQUE (purse_merge_request_serial_id) '
- );
-END
-$$;
-
-------------------------- account_merges ----------------------------
-
-CREATE OR REPLACE FUNCTION create_table_account_merges(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'account_merges';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(account_merge_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves (reserve_pub) ON DELETE CASCADE
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)' -- REFERENCES purse_requests (purse_pub)
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_account_merges_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE account_merges_' || partition_suffix || ' '
- 'ADD CONSTRAINT account_merges_' || partition_suffix || '_account_merge_request_serial_id_key '
- 'UNIQUE (account_merge_request_serial_id) '
- );
-END
-$$;
-
-------------------------- contracts -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_contracts(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'contracts';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(contract_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',pub_ckey BYTEA NOT NULL CHECK (LENGTH(pub_ckey)=32)'
- ',contract_sig BYTEA NOT NULL CHECK (LENGTH(contract_sig)=64)'
- ',e_contract BYTEA NOT NULL'
- ',purse_expiration INT8 NOT NULL'
- ',PRIMARY KEY (purse_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_contracts_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE contracts_' || partition_suffix || ' '
- 'ADD CONSTRAINT contracts_' || partition_suffix || '_contract_serial_id_key '
- 'UNIQUE (contract_serial_id) '
- );
-END
-$$;
-
---------------------------- history_requests --------------------------
-
-
-CREATE OR REPLACE FUNCTION create_table_history_requests(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'history_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(history_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',request_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',history_fee_val INT8 NOT NULL'
- ',history_fee_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,request_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
---------------------------- close_requests ---------------------------
-
-CREATE OR REPLACE FUNCTION create_table_close_requests(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'close_requests';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(close_request_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE'
- ',reserve_pub BYTEA NOT NULL CHECK (LENGTH(reserve_pub)=32)' -- REFERENCES reserves(reserve_pub) ON DELETE CASCADE
- ',close_timestamp INT8 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',close_val INT8 NOT NULL'
- ',close_frac INT4 NOT NULL'
- ',PRIMARY KEY (reserve_pub,close_timestamp)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (reserve_pub)'
- ,shard_suffix
- );
-
-END
-$$;
-
-------------------------------- purse_deposits -------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_purse_deposits(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'purse_deposits';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(purse_deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' -- UNIQUE
- ',partner_serial_id INT8' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE'
- ',purse_pub BYTEA NOT NULL CHECK (LENGTH(purse_pub)=32)'
- ',coin_pub BYTEA NOT NULL' -- REFERENCES known_coins (coin_pub) ON DELETE CASCADE'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',coin_sig BYTEA NOT NULL CHECK(LENGTH(coin_sig)=64)'
- ',PRIMARY KEY (purse_pub,coin_pub)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by coin_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_coin_pub '
- 'ON ' || table_name || ' '
- '(coin_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_purse_deposits_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE purse_deposits_' || partition_suffix || ' '
- 'ADD CONSTRAINT purse_deposits_' || partition_suffix || '_purse_deposit_serial_id_key '
- 'UNIQUE (purse_deposit_serial_id) '
- );
-END
-$$;
-
----------------------------- wads_out -------------------------------
-CREATE OR REPLACE FUNCTION create_table_wads_out(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_out';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',partner_serial_id INT8 NOT NULL' -- REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',execution_time INT8 NOT NULL'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_wads_out_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_out_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_out_' || partition_suffix || '_wad_out_serial_id_key '
- 'UNIQUE (wad_out_serial_id) '
- );
-END
-$$;
-
---------------------------- wad_out_entries --------------------------
-
-CREATE OR REPLACE FUNCTION create_table_wad_out_entries(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_out_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_out_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_out_serial_id INT8' -- REFERENCES wads_out (wad_out_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_by_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_wad_out_entries_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_out_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_out_entries_' || partition_suffix || '_wad_out_entry_serial_id_key '
- 'UNIQUE (wad_out_entry_serial_id) '
- );
-END
-$$;
-
--------------------------- wads_in --------------------------------
-
-CREATE OR REPLACE FUNCTION create_table_wads_in(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wads_in';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_id BYTEA PRIMARY KEY CHECK (LENGTH(wad_id)=24)'
- ',origin_exchange_url TEXT NOT NULL'
- ',amount_val INT8 NOT NULL'
- ',amount_frac INT4 NOT NULL'
- ',arrival_time INT8 NOT NULL'
- ',UNIQUE (wad_id, origin_exchange_url)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (wad_id)'
- ,shard_suffix
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_wads_in_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wads_in_' || partition_suffix || ' '
- 'ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_in_serial_id_key '
- 'UNIQUE (wad_in_serial_id) '
- ',ADD CONSTRAINT wads_in_' || partition_suffix || '_wad_is_origin_exchange_url_key '
- 'UNIQUE (wad_id, origin_exchange_url) '
- );
-END
-$$;
-
-
-------------------------- wads_in_entries --------------------------
-
-CREATE OR REPLACE FUNCTION create_table_wad_in_entries(
- IN shard_suffix VARCHAR DEFAULT NULL
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- table_name VARCHAR DEFAULT 'wad_in_entries';
-BEGIN
-
- PERFORM create_partitioned_table(
- 'CREATE TABLE IF NOT EXISTS %I '
- '(wad_in_entry_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' --UNIQUE
- ',wad_in_serial_id INT8' -- REFERENCES wads_in (wad_in_serial_id) ON DELETE CASCADE
- ',reserve_pub BYTEA NOT NULL CHECK(LENGTH(reserve_pub)=32)'
- ',purse_pub BYTEA PRIMARY KEY CHECK(LENGTH(purse_pub)=32)'
- ',h_contract BYTEA NOT NULL CHECK(LENGTH(h_contract)=64)'
- ',purse_expiration INT8 NOT NULL'
- ',merge_timestamp INT8 NOT NULL'
- ',amount_with_fee_val INT8 NOT NULL'
- ',amount_with_fee_frac INT4 NOT NULL'
- ',wad_fee_val INT8 NOT NULL'
- ',wad_fee_frac INT4 NOT NULL'
- ',deposit_fees_val INT8 NOT NULL'
- ',deposit_fees_frac INT4 NOT NULL'
- ',reserve_sig BYTEA NOT NULL CHECK (LENGTH(reserve_sig)=64)'
- ',purse_sig BYTEA NOT NULL CHECK (LENGTH(purse_sig)=64)'
- ') %s ;'
- ,table_name
- ,'PARTITION BY HASH (purse_pub)'
- ,shard_suffix
- );
-
- table_name = concat_ws('_', table_name, shard_suffix);
-
- -- FIXME: change to materialized index by reserve_pub!
- EXECUTE FORMAT (
- 'CREATE INDEX IF NOT EXISTS ' || table_name || '_reserve_pub '
- 'ON ' || table_name || ' '
- '(reserve_pub);'
- );
- EXECUTE FORMAT (
- 'COMMENT ON INDEX ' || table_name || '_reserve_pub '
- 'IS ' || quote_literal('needed in reserve history computation') || ';'
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION add_constraints_to_wad_in_entries_partition(
- IN partition_suffix VARCHAR
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
- EXECUTE FORMAT (
- 'ALTER TABLE wad_in_entries_' || partition_suffix || ' '
- 'ADD CONSTRAINT wad_in_entries_' || partition_suffix || '_wad_in_entry_serial_id_key '
- 'UNIQUE (wad_in_entry_serial_id) '
- );
-END
-$$;
-
--------------------------------------------------------------------
-------------------------- Partitions ------------------------------
--------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION create_hash_partition(
- source_table_name VARCHAR
- ,modulus INTEGER
- ,partition_num INTEGER
- )
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
-
- RAISE NOTICE 'Creating partition %_%', source_table_name, partition_num;
-
- EXECUTE FORMAT(
- 'CREATE TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
- ,source_table_name || '_' || partition_num
- ,source_table_name
- ,modulus
- ,partition_num-1
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION create_range_partition(
- source_table_name VARCHAR
- ,partition_num INTEGER
-)
- RETURNS void
- LANGUAGE plpgsql
-AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-CREATE OR REPLACE FUNCTION detach_default_partitions()
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
-
- RAISE NOTICE 'Detaching all default table partitions';
-
- ALTER TABLE IF EXISTS wire_targets
- DETACH PARTITION wire_targets_default;
-
- ALTER TABLE IF EXISTS reserves
- DETACH PARTITION reserves_default;
-
- ALTER TABLE IF EXISTS reserves_in
- DETACH PARTITION reserves_in_default;
-
- ALTER TABLE IF EXISTS reserves_close
- DETACH PARTITION reserves_close_default;
-
- ALTER TABLE IF EXISTS reserves_out
- DETACH PARTITION reserves_out_default;
-
- ALTER TABLE IF EXISTS reserves_out_by_reserve
- DETACH PARTITION reserves_out_by_reserve_default;
-
- ALTER TABLE IF EXISTS known_coins
- DETACH PARTITION known_coins_default;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DETACH PARTITION refresh_commitments_default;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DETACH PARTITION refresh_revealed_coins_default;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DETACH PARTITION refresh_transfer_keys_default;
-
- ALTER TABLE IF EXISTS deposits
- DETACH PARTITION deposits_default;
-
---- TODO range partitioning
--- ALTER TABLE IF EXISTS deposits_by_ready
--- DETACH PARTITION deposits_by_ready_default;
---
--- ALTER TABLE IF EXISTS deposits_for_matching
--- DETACH PARTITION deposits_default_for_matching_default;
-
- ALTER TABLE IF EXISTS refunds
- DETACH PARTITION refunds_default;
-
- ALTER TABLE IF EXISTS wire_out
- DETACH PARTITION wire_out_default;
-
- ALTER TABLE IF EXISTS aggregation_transient
- DETACH PARTITION aggregation_transient_default;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DETACH PARTITION aggregation_tracking_default;
-
- ALTER TABLE IF EXISTS recoup
- DETACH PARTITION recoup_default;
-
- ALTER TABLE IF EXISTS recoup_by_reserve
- DETACH PARTITION recoup_by_reserve_default;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DETACH PARTITION recoup_refresh_default;
-
- ALTER TABLE IF EXISTS prewire
- DETACH PARTITION prewire_default;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DETACH partition cs_nonce_locks_default;
-
- ALTER TABLE IF EXISTS purse_requests
- DETACH partition purse_requests_default;
-
- ALTER TABLE IF EXISTS purse_refunds
- DETACH partition purse_refunds_default;
-
- ALTER TABLE IF EXISTS purse_merges
- DETACH partition purse_merges_default;
-
- ALTER TABLE IF EXISTS account_merges
- DETACH partition account_merges_default;
-
- ALTER TABLE IF EXISTS contracts
- DETACH partition contracts_default;
-
- ALTER TABLE IF EXISTS history_requests
- DETACH partition history_requests_default;
-
- ALTER TABLE IF EXISTS close_requests
- DETACH partition close_requests_default;
-
- ALTER TABLE IF EXISTS purse_deposits
- DETACH partition purse_deposits_default;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DETACH partition wad_out_entries_default;
-
- ALTER TABLE IF EXISTS wads_in
- DETACH partition wads_in_default;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DETACH partition wad_in_entries_default;
-END
-$$;
-
-COMMENT ON FUNCTION detach_default_partitions
- IS 'We need to drop default and create new one before deleting the default partitions
- otherwise constraints get lost too. Might be needed in shardig too';
-
-
-CREATE OR REPLACE FUNCTION drop_default_partitions()
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
-
- RAISE NOTICE 'Dropping default table partitions';
-
- DROP TABLE IF EXISTS wire_targets_default;
- DROP TABLE IF EXISTS reserves_default;
- DROP TABLE IF EXISTS reserves_in_default;
- DROP TABLE IF EXISTS reserves_close_default;
- DROP TABLE IF EXISTS reserves_out_default;
- DROP TABLE IF EXISTS reserves_out_by_reserve_default;
- DROP TABLE IF EXISTS known_coins_default;
- DROP TABLE IF EXISTS refresh_commitments_default;
- DROP TABLE IF EXISTS refresh_revealed_coins_default;
- DROP TABLE IF EXISTS refresh_transfer_keys_default;
- DROP TABLE IF EXISTS deposits_default;
---DROP TABLE IF EXISTS deposits_by_ready_default;
---DROP TABLE IF EXISTS deposits_for_matching_default;
- DROP TABLE IF EXISTS refunds_default;
- DROP TABLE IF EXISTS wire_out_default;
- DROP TABLE IF EXISTS aggregation_transient_default;
- DROP TABLE IF EXISTS aggregation_tracking_default;
- DROP TABLE IF EXISTS recoup_default;
- DROP TABLE IF EXISTS recoup_by_reserve_default;
- DROP TABLE IF EXISTS recoup_refresh_default;
- DROP TABLE IF EXISTS prewire_default;
- DROP TABLE IF EXISTS cs_nonce_locks_default;
-
- DROP TABLE IF EXISTS purse_requests_default;
- DROP TABLE IF EXISTS purse_refunds_default;
- DROP TABLE IF EXISTS purse_merges_default;
- DROP TABLE IF EXISTS account_merges_default;
- DROP TABLE IF EXISTS contracts_default;
- DROP TABLE IF EXISTS history_requests_default;
- DROP TABLE IF EXISTS close_requests_default;
- DROP TABLE IF EXISTS purse_deposits_default;
- DROP TABLE IF EXISTS wad_out_entries_default;
- DROP TABLE IF EXISTS wads_in_default;
- DROP TABLE IF EXISTS wad_in_entries_default;
-
-END
-$$;
-
-COMMENT ON FUNCTION drop_default_partitions
- IS 'Drop all default partitions once other partitions are attached.
- Might be needed in sharding too.';
-
-CREATE OR REPLACE FUNCTION create_partitions(
- num_partitions INTEGER
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- modulus INTEGER;
-BEGIN
-
- modulus := num_partitions;
-
- PERFORM detach_default_partitions();
-
- LOOP
-
- PERFORM create_hash_partition(
- 'wire_targets'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_targets_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'reserves_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_close'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_close_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_reserves_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'reserves_out_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'known_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_known_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_commitments'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_commitments_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_revealed_coins'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_revealed_coins_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'refresh_transfer_keys'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refresh_transfer_keys_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_deposits_partition(num_partitions::varchar);
-
--- TODO: dynamically (!) creating/deleting deposits partitions:
--- create new partitions 'as needed', drop old ones once the aggregator has made
--- them empty; as 'new' deposits will always have deadlines in the future, this
--- would basically guarantee no conflict between aggregator and exchange service!
--- SEE also: https://www.cybertec-postgresql.com/en/automatic-partition-creation-in-postgresql/
--- (article is slightly wrong, as this works:)
---CREATE TABLE tab (
--- id bigint GENERATED ALWAYS AS IDENTITY,
--- ts timestamp NOT NULL,
--- data text
--- PARTITION BY LIST ((ts::date));
--- CREATE TABLE tab_def PARTITION OF tab DEFAULT;
--- BEGIN
--- CREATE TABLE tab_part2 (LIKE tab);
--- insert into tab_part2 (id,ts, data) values (5,'2022-03-21', 'foo');
--- alter table tab attach partition tab_part2 for values in ('2022-03-21');
--- commit;
--- Naturally, to ensure this is actually 100% conflict-free, we'd
--- need to create tables at the granularity of the wire/refund deadlines;
--- that is right now configurable via AGGREGATOR_SHIFT option.
-
--- FIXME: range partitioning
--- PERFORM create_range_partition(
--- 'deposits_by_ready'
--- ,modulus
--- ,num_partitions
--- );
---
--- PERFORM create_range_partition(
--- 'deposits_for_matching'
--- ,modulus
--- ,num_partitions
--- );
-
- PERFORM create_hash_partition(
- 'refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wire_out'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wire_out_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'aggregation_transient'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'aggregation_tracking'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_aggregation_tracking_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'recoup_by_reserve'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'recoup_refresh'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_recoup_refresh_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'prewire'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'cs_nonce_locks'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_cs_nonce_locks_partition(num_partitions::varchar);
-
- ---------------- P2P ----------------------
-
- PERFORM create_hash_partition(
- 'purse_requests'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_requests_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_refunds'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_refunds_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'purse_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'account_merges'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_account_merges_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'contracts'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_contracts_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'history_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'close_requests'
- ,modulus
- ,num_partitions
- );
-
- PERFORM create_hash_partition(
- 'purse_deposits'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_purse_deposits_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_out_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_out_entries_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wads_in'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wads_in_partition(num_partitions::varchar);
-
- PERFORM create_hash_partition(
- 'wad_in_entries'
- ,modulus
- ,num_partitions
- );
- PERFORM add_constraints_to_wad_in_entries_partition(num_partitions::varchar);
-
- num_partitions=num_partitions-1;
- EXIT WHEN num_partitions=0;
-
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
---------------------- Sharding ---------------------------
-
-CREATE OR REPLACE FUNCTION create_foreign_hash_partition(
- source_table_name VARCHAR
- ,modulus INTEGER
- ,shard_suffix VARCHAR
- ,current_shard_num INTEGER
- ,local_user VARCHAR DEFAULT 'taler-exchange-httpd'
- )
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
-
- RAISE NOTICE 'Creating %_% on %', source_table_name, shard_suffix, shard_suffix;
-
- EXECUTE FORMAT(
- 'CREATE FOREIGN TABLE IF NOT EXISTS %I '
- 'PARTITION OF %I '
- 'FOR VALUES WITH (MODULUS %s, REMAINDER %s) '
- 'SERVER %I'
- ,source_table_name || '_' || shard_suffix
- ,source_table_name
- ,modulus
- ,current_shard_num-1
- ,shard_suffix
- );
-
- EXECUTE FORMAT(
- 'ALTER FOREIGN TABLE %I OWNER TO %I'
- ,source_table_name || '_' || shard_suffix
- ,local_user
- );
-
-END
-$$;
-
-CREATE OR REPLACE FUNCTION create_foreign_range_partition(
- source_table_name VARCHAR
- ,partition_num INTEGER
-)
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
- RAISE NOTICE 'TODO';
-END
-$$;
-
-CREATE OR REPLACE FUNCTION prepare_sharding()
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- CREATE EXTENSION IF NOT EXISTS postgres_fdw;
-
- PERFORM detach_default_partitions();
-
- ALTER TABLE IF EXISTS wire_targets
- DROP CONSTRAINT IF EXISTS wire_targets_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves
- DROP CONSTRAINT IF EXISTS reserves_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_in
- DROP CONSTRAINT IF EXISTS reserves_in_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_close
- DROP CONSTRAINT IF EXISTS reserves_close_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS reserves_out
- DROP CONSTRAINT IF EXISTS reserves_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS reserves_out_denominations_serial_fkey
- ,DROP CONSTRAINT IF EXISTS reserves_out_h_blind_ev_key
- ;
-
- ALTER TABLE IF EXISTS known_coins
- DROP CONSTRAINT IF EXISTS known_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS known_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_commitments
- DROP CONSTRAINT IF EXISTS refresh_commitments_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_old_coin_pub_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_revealed_coins
- DROP CONSTRAINT IF EXISTS refresh_revealed_coins_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS refresh_revealed_coins_denominations_serial_fkey
- ;
-
- ALTER TABLE IF EXISTS refresh_transfer_keys
- DROP CONSTRAINT IF EXISTS refresh_transfer_keys_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS deposits
- DROP CONSTRAINT IF EXISTS deposits_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS deposits_extension_details_serial_id_fkey
- ,DROP CONSTRAINT IF EXISTS deposits_coin_pub_merchant_pub_h_contract_terms_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS refunds
- DROP CONSTRAINT IF EXISTS refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wire_out
- DROP CONSTRAINT IF EXISTS wire_out_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wire_out_wtid_raw_key CASCADE
- ;
-
- ALTER TABLE IF EXISTS aggregation_tracking
- DROP CONSTRAINT IF EXISTS aggregation_tracking_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS aggregation_tracking_wtid_raw_fkey
- ;
-
- ALTER TABLE IF EXISTS recoup
- DROP CONSTRAINT IF EXISTS recoup_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS recoup_refresh
- DROP CONSTRAINT IF EXISTS recoup_refresh_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS prewire
- DROP CONSTRAINT IF EXISTS prewire_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS cs_nonce_locks
- DROP CONSTRAINT IF EXISTS cs_nonce_locks_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_requests
- DROP CONSTRAINT IF EXISTS purse_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_refunds
- DROP CONSTRAINT IF EXISTS purse_refunds_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_merges
- DROP CONSTRAINT IF EXISTS purse_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS account_merges
- DROP CONSTRAINT IF EXISTS account_merges_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS contracts
- DROP CONSTRAINT IF EXISTS contracts_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS history_requests
- DROP CONSTRAINT IF EXISTS history_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS close_requests
- DROP CONSTRAINT IF EXISTS close_requests_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS purse_deposits
- DROP CONSTRAINT IF EXISTS purse_deposits_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_out
- DROP CONSTRAINT IF EXISTS wads_out_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wad_out_entries
- DROP CONSTRAINT IF EXISTS wad_out_entries_pkey CASCADE
- ;
-
- ALTER TABLE IF EXISTS wads_in
- DROP CONSTRAINT IF EXISTS wads_in_pkey CASCADE
- ,DROP CONSTRAINT IF EXISTS wads_in_wad_id_origin_exchange_url_key
- ;
-
- ALTER TABLE IF EXISTS wad_in_entries
- DROP CONSTRAINT IF EXISTS wad_in_entries_pkey CASCADE
- ;
-
-END
-$$;
-
-
-CREATE OR REPLACE FUNCTION create_shard_server(
- shard_suffix VARCHAR
- ,total_num_shards INTEGER
- ,current_shard_num INTEGER
- ,remote_host VARCHAR
- ,remote_user VARCHAR
- ,remote_user_password VARCHAR
- ,remote_db_name VARCHAR DEFAULT 'taler-exchange'
- ,remote_port INTEGER DEFAULT '5432'
- ,local_user VARCHAR DEFAULT 'taler-exchange-httpd'
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- RAISE NOTICE 'Creating server %', remote_host;
-
- EXECUTE FORMAT(
- 'CREATE SERVER IF NOT EXISTS %I '
- 'FOREIGN DATA WRAPPER postgres_fdw '
- 'OPTIONS (dbname %L, host %L, port %L)'
- ,shard_suffix
- ,remote_db_name
- ,remote_host
- ,remote_port
- );
-
- EXECUTE FORMAT(
- 'CREATE USER MAPPING IF NOT EXISTS '
- 'FOR %I SERVER %I '
- 'OPTIONS (user %L, password %L)'
- ,local_user
- ,shard_suffix
- ,remote_user
- ,remote_user_password
- );
-
- EXECUTE FORMAT(
- 'GRANT ALL PRIVILEGES '
- 'ON FOREIGN SERVER %I '
- 'TO %I;'
- ,shard_suffix
- ,local_user
- );
-
- PERFORM create_foreign_hash_partition(
- 'wire_targets'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_out_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'reserves_close'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'known_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_commitments'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_revealed_coins'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'refresh_transfer_keys'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_by_ready'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
--- PERFORM create_foreign_range_partition(
--- 'deposits_for_matching'
--- ,total_num_shards
--- ,shard_suffix
--- ,current_shard_num
--- ,local_user
--- );
- PERFORM create_foreign_hash_partition(
- 'refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wire_out'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_transient'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'aggregation_tracking'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_by_reserve'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'recoup_refresh'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'prewire'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'cs_nonce_locks'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
- ------------------- P2P --------------------
-
- PERFORM create_foreign_hash_partition(
- 'purse_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_refunds'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'account_merges'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'contracts'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'history_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'close_requests'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'purse_deposits'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_out_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wads_in'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
- PERFORM create_foreign_hash_partition(
- 'wad_in_entries'
- ,total_num_shards
- ,shard_suffix
- ,current_shard_num
- ,local_user
- );
-
-END
-$$;
-
-COMMENT ON FUNCTION create_shard_server
- IS 'Create a shard server on the master
- node with all foreign tables and user mappings';
-
-CREATE OR REPLACE FUNCTION create_foreign_servers(
- amount INTEGER
- ,domain VARCHAR
- ,remote_user VARCHAR DEFAULT 'taler'
- ,remote_user_password VARCHAR DEFAULT 'taler'
-)
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-BEGIN
-
- PERFORM prepare_sharding();
-
- FOR i IN 1..amount LOOP
- PERFORM create_shard_server(
- i::varchar
- ,amount
- ,i
- ,'shard-' || i::varchar || '.' || domain
- ,remote_user
- ,remote_user_password
- ,'taler-exchange'
- ,'5432'
- ,'taler-exchange-httpd'
- );
- END LOOP;
-
- PERFORM drop_default_partitions();
-
-END
-$$;
-
-COMMIT;
diff --git a/src/exchangedb/drop-common.sql b/src/exchangedb/drop-common.sql
deleted file mode 100644
index 63628952c..000000000
--- a/src/exchangedb/drop-common.sql
+++ /dev/null
@@ -1,97 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2021 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- This script DROPs all of the common functions we create.
---
--- Unlike the other SQL files, it SHOULD be updated to reflect the
--- latest requirements for dropping tables.
-
-
-DROP FUNCTION IF EXISTS create_table_prewire;
-DROP FUNCTION IF EXISTS create_table_recoup;
-DROP FUNCTION IF EXISTS add_constraints_to_recoup_partition;
-DROP FUNCTION IF EXISTS create_table_recoup_by_reserve;
-DROP FUNCTION IF EXISTS create_table_recoup_refresh;
-DROP FUNCTION IF EXISTS add_constraints_to_recoup_refresh_partition;
-DROP FUNCTION IF EXISTS create_table_aggregation_transient;
-DROP FUNCTION IF EXISTS create_table_aggregation_tracking;
-DROP FUNCTION IF EXISTS add_constraints_to_aggregation_tracking_partition;
-DROP FUNCTION IF EXISTS create_table_wire_out;
-DROP FUNCTION IF EXISTS add_constraints_to_wire_out_partition;
-DROP FUNCTION IF EXISTS create_table_wire_targets;
-DROP FUNCTION IF EXISTS add_constraints_to_wire_targets_partition;
-DROP FUNCTION IF EXISTS create_table_deposits;
-DROP FUNCTION IF EXISTS create_table_deposits_by_ready;
-DROP FUNCTION IF EXISTS create_table_deposits_for_matching;
-DROP FUNCTION IF EXISTS add_constraints_to_deposits_partition;
-DROP FUNCTION IF EXISTS create_table_refunds;
-DROP FUNCTION IF EXISTS add_constraints_to_refunds_partition;
-DROP FUNCTION IF EXISTS create_table_refresh_commitments;
-DROP FUNCTION IF EXISTS add_constraints_to_refresh_commitments_partition;
-DROP FUNCTION IF EXISTS create_table_refresh_revealed_coins;
-DROP FUNCTION IF EXISTS add_constraints_to_refresh_revealed_coins_partition;
-DROP FUNCTION IF EXISTS create_table_refresh_transfer_keys;
-DROP FUNCTION IF EXISTS add_constraints_to_refresh_transfer_keys_partition;
-DROP FUNCTION IF EXISTS create_table_known_coins;
-DROP FUNCTION IF EXISTS add_constraints_to_known_coins_partition;
-DROP FUNCTION IF EXISTS create_table_reserves_close;
-DROP FUNCTION IF EXISTS add_constraints_to_reserves_close_partition;
-DROP FUNCTION IF EXISTS create_table_reserves_out;
-DROP FUNCTION IF EXISTS create_table_reserves_out_by_reserve;
-DROP FUNCTION IF EXISTS add_constraints_to_reserves_out_partition;
-DROP FUNCTION IF EXISTS create_table_reserves_in;
-DROP FUNCTION IF EXISTS add_constraints_to_reserves_in_partition;
-DROP FUNCTION IF EXISTS create_table_reserves;
-DROP FUNCTION IF EXISTS create_table_cs_nonce_locks;
-DROP FUNCTION IF EXISTS add_constraints_to_cs_nonce_locks_partition;
-
-DROP FUNCTION IF EXISTS create_table_purse_requests;
-DROP FUNCTION IF EXISTS add_constraints_to_purse_requests_partition;
-DROP FUNCTION IF EXISTS create_table_purse_refunds;
-DROP FUNCTION IF EXISTS add_constraints_to_purse_refunds_partition;
-DROP FUNCTION IF EXISTS create_table_purse_merges;
-DROP FUNCTION IF EXISTS add_constraints_to_purse_merges_partition;
-DROP FUNCTION IF EXISTS create_table_account_merges;
-DROP FUNCTION IF EXISTS add_constraints_to_account_merges_partition;
-DROP FUNCTION IF EXISTS create_table_contracts;
-DROP FUNCTION IF EXISTS add_constraints_to_contracts_partition;
-DROP FUNCTION IF EXISTS create_table_history_requests;
-DROP FUNCTION IF EXISTS create_table_close_requests;
-DROP FUNCTION IF EXISTS create_table_purse_deposits;
-DROP FUNCTION IF EXISTS add_constraints_to_purse_deposits_partition;
-DROP FUNCTION IF EXISTS create_table_wad_out_entries;
-DROP FUNCTION IF EXISTS add_constraints_to_wad_out_entries_partition;
-DROP FUNCTION IF EXISTS create_table_wads_in;
-DROP FUNCTION IF EXISTS add_constraints_to_wads_in_partition;
-DROP FUNCTION IF EXISTS create_table_wad_in_entries;
-DROP FUNCTION IF EXISTS add_constraints_to_wad_in_entries_partition;
-
-DROP FUNCTION IF EXISTS create_partitioned_table;
-DROP FUNCTION IF EXISTS create_hash_partition;
-DROP FUNCTION IF EXISTS create_range_partition;
-DROP FUNCTION IF EXISTS create_partitions;
-DROP FUNCTION IF EXISTS detach_default_partitions;
-DROP FUNCTION IF EXISTS drop_default_partitions;
-DROP FUNCTION IF EXISTS prepare_sharding;
-DROP FUNCTION IF EXISTS create_foreign_hash_partition;
-DROP FUNCTION IF EXISTS create_foreign_range_partition;
-DROP FUNCTION IF EXISTS create_foreign_servers;
-DROP FUNCTION IF EXISTS create_shard_server;
-
-COMMIT;
diff --git a/src/exchangedb/drop.sql b/src/exchangedb/drop.sql
new file mode 100644
index 000000000..b7583f794
--- /dev/null
+++ b/src/exchangedb/drop.sql
@@ -0,0 +1,39 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+-- Everything in one big transaction
+BEGIN;
+
+WITH xpatches AS (
+ SELECT patch_name
+ FROM _v.patches
+ WHERE starts_with(patch_name,'exchange-')
+)
+ SELECT _v.unregister_patch(xpatches.patch_name)
+ FROM xpatches;
+
+
+WITH xpatches AS (
+ SELECT patch_name
+ FROM _v.patches
+ WHERE starts_with(patch_name,'auditor-triggers-')
+)
+ SELECT _v.unregister_patch(xpatches.patch_name)
+ FROM xpatches;
+
+DROP SCHEMA exchange CASCADE;
+
+COMMIT;
diff --git a/src/exchangedb/drop0001-exchange-part.sql b/src/exchangedb/drop0001-exchange-part.sql
deleted file mode 100644
index 4cf6a72fc..000000000
--- a/src/exchangedb/drop0001-exchange-part.sql
+++ /dev/null
@@ -1,108 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2021 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
-BEGIN;
-
--- Unregister patch (exchange-0001.sql)
-SELECT _v.unregister_patch('exchange-0001');
-
-
--- Drops for exchange-0001-part.sql
-DROP TRIGGER IF EXISTS reserves_out_on_insert ON reserves_out;
-DROP TRIGGER IF EXISTS reserves_out_on_delete ON reserves_out;
-DROP TRIGGER IF EXISTS deposits_on_insert ON deposits;
-DROP TRIGGER IF EXISTS deposits_on_delete ON deposits;
-DROP TRIGGER IF EXISTS recoup_on_insert ON recoup;
-DROP TRIGGER IF EXISTS recoup_on_delete ON recoup;
-
-DROP TABLE IF EXISTS revolving_work_shards CASCADE;
-DROP TABLE IF EXISTS extensions CASCADE;
-DROP TABLE IF EXISTS auditors CASCADE;
-DROP TABLE IF EXISTS auditor_denom_sigs CASCADE;
-DROP TABLE IF EXISTS exchange_sign_keys CASCADE;
-DROP TABLE IF EXISTS wire_accounts CASCADE;
-DROP TABLE IF EXISTS signkey_revocations CASCADE;
-DROP TABLE IF EXISTS work_shards CASCADE;
-DROP TABLE IF EXISTS prewire CASCADE;
-DROP TABLE IF EXISTS recoup CASCADE;
-DROP TABLE IF EXISTS recoup_refresh CASCADE;
-DROP TABLE IF EXISTS aggregation_transient CASCADE;
-DROP TABLE IF EXISTS aggregation_tracking CASCADE;
-DROP TABLE IF EXISTS wire_out CASCADE;
-DROP TABLE IF EXISTS wire_targets CASCADE;
-DROP TABLE IF EXISTS wire_fee CASCADE;
-DROP TABLE IF EXISTS deposits CASCADE;
-DROP TABLE IF EXISTS deposits_by_ready CASCADE;
-DROP TABLE IF EXISTS deposits_for_matching CASCADE;
-DROP TABLE IF EXISTS extension_details CASCADE;
-DROP TABLE IF EXISTS refunds CASCADE;
-DROP TABLE IF EXISTS refresh_commitments CASCADE;
-DROP TABLE IF EXISTS refresh_revealed_coins CASCADE;
-DROP TABLE IF EXISTS refresh_transfer_keys CASCADE;
-DROP TABLE IF EXISTS known_coins CASCADE;
-DROP TABLE IF EXISTS reserves_close CASCADE;
-DROP TABLE IF EXISTS reserves_out CASCADE;
-DROP TABLE IF EXISTS reserves_out_by_reserve CASCADE;
-DROP TABLE IF EXISTS reserves_in CASCADE;
-DROP TABLE IF EXISTS reserves CASCADE;
-DROP TABLE IF EXISTS denomination_revocations CASCADE;
-DROP TABLE IF EXISTS denominations CASCADE;
-DROP TABLE IF EXISTS cs_nonce_locks CASCADE;
-DROP TABLE IF EXISTS global_fee CASCADE;
-DROP TABLE IF EXISTS recoup_by_reserve CASCADE;
-
-
-DROP TABLE IF EXISTS partners CASCADE;
-DROP TABLE IF EXISTS account_merges CASCADE;
-DROP TABLE IF EXISTS purse_merges CASCADE;
-DROP TABLE IF EXISTS purse_deposits CASCADE;
-DROP TABLE IF EXISTS contracts CASCADE;
-DROP TABLE IF EXISTS history_requests CASCADE;
-DROP TABLE IF EXISTS close_requests CASCADE;
-DROP TABLE IF EXISTS purse_requests CASCADE;
-DROP TABLE IF EXISTS purse_refunds CASCADE;
-DROP TABLE IF EXISTS wads_out CASCADE;
-DROP TABLE IF EXISTS wad_out_entries CASCADE;
-DROP TABLE IF EXISTS wads_in CASCADE;
-DROP TABLE IF EXISTS wad_in_entries CASCADE;
-DROP TABLE IF EXISTS partner_accounts CASCADE;
-DROP TABLE IF EXISTS purse_actions CASCADE;
-
-DROP FUNCTION IF EXISTS exchange_do_withdraw;
-DROP FUNCTION IF EXISTS exchange_do_withdraw_limit_check;
-DROP FUNCTION IF EXISTS exchange_do_recoup_by_reserve;
-DROP FUNCTION IF EXISTS recoup_insert_trigger;
-DROP FUNCTION IF EXISTS recoup_delete_trigger;
-DROP FUNCTION IF EXISTS deposits_insert_trigger;
-DROP FUNCTION IF EXISTS deposits_update_trigger;
-DROP FUNCTION IF EXISTS deposits_delete_trigger;
-DROP FUNCTION IF EXISTS reserves_out_by_reserve_insert_trigger;
-DROP FUNCTION IF EXISTS reserves_out_by_reserve_delete_trigger;
-DROP FUNCTION IF EXISTS exchange_do_deposit;
-DROP FUNCTION IF EXISTS exchange_do_melt;
-DROP FUNCTION IF EXISTS exchange_do_refund;
-DROP FUNCTION IF EXISTS exchange_do_recoup_to_coin;
-DROP FUNCTION IF EXISTS exchange_do_recoup_to_reserve;
-DROP FUNCTION IF EXISTS exchange_do_purse_deposit;
-DROP FUNCTION IF EXISTS exchange_do_purse_merge;
-DROP FUNCTION IF EXISTS exchange_do_account_merge;
-DROP FUNCTION IF EXISTS exchange_do_history_request;
-DROP FUNCTION IF EXISTS exchange_do_close_request;
-DROP FUNCTION IF EXISTS exchange_do_reserve_purse;
-
--- And we're out of here...
-
-COMMIT;
diff --git a/src/exchangedb/exchange-0001-part.sql b/src/exchangedb/exchange-0001-part.sql
deleted file mode 100644
index e24129957..000000000
--- a/src/exchangedb/exchange-0001-part.sql
+++ /dev/null
@@ -1,3664 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- Check patch versioning is in place.
-SELECT _v.register_patch('exchange-0001', NULL, NULL);
-
--- ------------------------------ denominations ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS denominations
- (denominations_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,denom_pub_hash BYTEA PRIMARY KEY CHECK (LENGTH(denom_pub_hash)=64)
- ,denom_type INT4 NOT NULL DEFAULT (1) -- 1 == RSA (for now, remove default later!)
- ,age_mask INT4 NOT NULL DEFAULT (0)
- ,denom_pub BYTEA NOT NULL
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,valid_from INT8 NOT NULL
- ,expire_withdraw INT8 NOT NULL
- ,expire_deposit INT8 NOT NULL
- ,expire_legal INT8 NOT NULL
- ,coin_val INT8 NOT NULL
- ,coin_frac INT4 NOT NULL
- ,fee_withdraw_val INT8 NOT NULL
- ,fee_withdraw_frac INT4 NOT NULL
- ,fee_deposit_val INT8 NOT NULL
- ,fee_deposit_frac INT4 NOT NULL
- ,fee_refresh_val INT8 NOT NULL
- ,fee_refresh_frac INT4 NOT NULL
- ,fee_refund_val INT8 NOT NULL
- ,fee_refund_frac INT4 NOT NULL
- );
-COMMENT ON TABLE denominations
- IS 'Main denominations table. All the valid denominations the exchange knows about.';
-COMMENT ON COLUMN denominations.denom_type
- IS 'determines cipher type for blind signatures used with this denomination; 0 is for RSA';
-COMMENT ON COLUMN denominations.age_mask
- IS 'bitmask with the age restrictions that are being used for this denomination; 0 if denomination does not support the use of age restrictions';
-COMMENT ON COLUMN denominations.denominations_serial
- IS 'needed for exchange-auditor replication logic';
-
-CREATE INDEX IF NOT EXISTS denominations_by_expire_legal_index
- ON denominations
- (expire_legal);
-
-
--- ------------------------------ denomination_revocations ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS denomination_revocations
- (denom_revocations_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,denominations_serial INT8 PRIMARY KEY REFERENCES denominations (denominations_serial) ON DELETE CASCADE
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- );
-COMMENT ON TABLE denomination_revocations
- IS 'remembering which denomination keys have been revoked';
-
-
--- ------------------------------ wire_targets ----------------------------------------
-
-SELECT create_table_wire_targets();
-
-COMMENT ON TABLE wire_targets
- IS 'All senders and recipients of money via the exchange';
-COMMENT ON COLUMN wire_targets.payto_uri
- IS 'Can be a regular bank account, or also be a URI identifying a reserve-account (for P2P payments)';
-COMMENT ON COLUMN wire_targets.wire_target_h_payto
- IS 'Unsalted hash of payto_uri';
-COMMENT ON COLUMN wire_targets.kyc_ok
- IS 'true if the KYC check was passed successfully';
-COMMENT ON COLUMN wire_targets.external_id
- IS 'Name of the user that was used for OAuth 2.0-based legitimization';
-
-CREATE TABLE IF NOT EXISTS wire_targets_default
- PARTITION OF wire_targets
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wire_targets_partition('default');
-
--- ------------------------------ reserves ----------------------------------------
-
-SELECT create_table_reserves();
-
-COMMENT ON TABLE reserves
- IS 'Summarizes the balance of a reserve. Updated when new funds are added or withdrawn.';
-COMMENT ON COLUMN reserves.reserve_pub
- IS 'EdDSA public key of the reserve. Knowledge of the private key implies ownership over the balance.';
-COMMENT ON COLUMN reserves.current_balance_val
- IS 'Current balance remaining with the reserve.';
-COMMENT ON COLUMN reserves.purses_active
- IS 'Number of purses that were created by this reserve that are not expired and not fully paid.';
-COMMENT ON COLUMN reserves.purses_allowed
- IS 'Number of purses that this reserve is allowed to have active at most.';
-COMMENT ON COLUMN reserves.kyc_required
- IS 'True if a KYC check must have been passed before withdrawing from this reserve. Set to true once a reserve received a P2P payment.';
-COMMENT ON COLUMN reserves.kyc_passed
- IS 'True once KYC was passed for this reserve. The KYC details are then available via the wire_targets table under the key of wire_target_h_payto which is to be derived from the reserve_pub and the base URL of this exchange.';
-COMMENT ON COLUMN reserves.expiration_date
- IS 'Used to trigger closing of reserves that have not been drained after some time';
-COMMENT ON COLUMN reserves.gc_date
- IS 'Used to forget all information about a reserve during garbage collection';
-
-CREATE TABLE IF NOT EXISTS reserves_default
- PARTITION OF reserves
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
--- ------------------------------ reserves_in ----------------------------------------
-
-SELECT create_table_reserves_in();
-
-COMMENT ON TABLE reserves_in
- IS 'list of transfers of funds into the reserves, one per incoming wire transfer';
-COMMENT ON COLUMN reserves_in.wire_source_h_payto
- IS 'Identifies the debited bank account and KYC status';
-COMMENT ON COLUMN reserves_in.reserve_pub
- IS 'Public key of the reserve. Private key signifies ownership of the remaining balance.';
-COMMENT ON COLUMN reserves_in.credit_val
- IS 'Amount that was transferred into the reserve';
-
-CREATE TABLE IF NOT EXISTS reserves_in_default
- PARTITION OF reserves_in
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_reserves_in_partition('default');
-
--- ------------------------------ reserves_close ----------------------------------------
-
-SELECT create_table_reserves_close();
-
-COMMENT ON TABLE reserves_close
- IS 'wire transfers executed by the reserve to close reserves';
-COMMENT ON COLUMN reserves_close.wire_target_h_payto
- IS 'Identifies the credited bank account (and KYC status). Note that closing does not depend on KYC.';
-
-CREATE TABLE IF NOT EXISTS reserves_close_default
- PARTITION OF reserves_close
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_reserves_close_partition('default');
-
-
--- ------------------------------ reserves_out ----------------------------------------
-
-SELECT create_table_reserves_out();
-
-COMMENT ON TABLE reserves_out
- IS 'Withdraw operations performed on reserves.';
-COMMENT ON COLUMN reserves_out.h_blind_ev
- IS 'Hash of the blinded coin, used as primary key here so that broken clients that use a non-random coin or blinding factor fail to withdraw (otherwise they would fail on deposit when the coin is not unique there).';
-COMMENT ON COLUMN reserves_out.denominations_serial
- IS 'We do not CASCADE ON DELETE here, we may keep the denomination data alive';
-
-CREATE TABLE IF NOT EXISTS reserves_out_default
- PARTITION OF reserves_out
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_reserves_out_partition('default');
-
-
-SELECT create_table_reserves_out_by_reserve();
-
-COMMENT ON TABLE reserves_out_by_reserve
- IS 'Information in this table is strictly redundant with that of reserves_out, but saved by a different primary key for fast lookups by reserve public key/uuid.';
-
-CREATE TABLE IF NOT EXISTS reserves_out_by_reserve_default
- PARTITION OF reserves_out_by_reserve
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-CREATE OR REPLACE FUNCTION reserves_out_by_reserve_insert_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO reserves_out_by_reserve
- (reserve_uuid
- ,h_blind_ev)
- VALUES
- (NEW.reserve_uuid
- ,NEW.h_blind_ev);
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION reserves_out_by_reserve_insert_trigger()
- IS 'Replicate reserve_out inserts into reserve_out_by_reserve table.';
-
-CREATE TRIGGER reserves_out_on_insert
- AFTER INSERT
- ON reserves_out
- FOR EACH ROW EXECUTE FUNCTION reserves_out_by_reserve_insert_trigger();
-
-CREATE OR REPLACE FUNCTION reserves_out_by_reserve_delete_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM reserves_out_by_reserve
- WHERE reserve_uuid = OLD.reserve_uuid;
- RETURN OLD;
-END $$;
-COMMENT ON FUNCTION reserves_out_by_reserve_delete_trigger()
- IS 'Replicate reserve_out deletions into reserve_out_by_reserve table.';
-
-CREATE TRIGGER reserves_out_on_delete
- AFTER DELETE
- ON reserves_out
- FOR EACH ROW EXECUTE FUNCTION reserves_out_by_reserve_delete_trigger();
-
-
--- ------------------------------ auditors ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS auditors
- (auditor_uuid BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,auditor_pub BYTEA PRIMARY KEY CHECK (LENGTH(auditor_pub)=32)
- ,auditor_name VARCHAR NOT NULL
- ,auditor_url VARCHAR NOT NULL
- ,is_active BOOLEAN NOT NULL
- ,last_change INT8 NOT NULL
- );
-COMMENT ON TABLE auditors
- IS 'Table with auditors the exchange uses or has used in the past. Entries never expire as we need to remember the last_change column indefinitely.';
-COMMENT ON COLUMN auditors.auditor_pub
- IS 'Public key of the auditor.';
-COMMENT ON COLUMN auditors.auditor_url
- IS 'The base URL of the auditor.';
-COMMENT ON COLUMN auditors.is_active
- IS 'true if we are currently supporting the use of this auditor.';
-COMMENT ON COLUMN auditors.last_change
- IS 'Latest time when active status changed. Used to detect replays of old messages.';
-
-
--- ------------------------------ auditor_denom_sigs ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS auditor_denom_sigs
- (auditor_denom_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,auditor_uuid INT8 NOT NULL REFERENCES auditors (auditor_uuid) ON DELETE CASCADE
- ,denominations_serial INT8 NOT NULL REFERENCES denominations (denominations_serial) ON DELETE CASCADE
- ,auditor_sig BYTEA CHECK (LENGTH(auditor_sig)=64)
- ,PRIMARY KEY (denominations_serial, auditor_uuid)
- );
-COMMENT ON TABLE auditor_denom_sigs
- IS 'Table with auditor signatures on exchange denomination keys.';
-COMMENT ON COLUMN auditor_denom_sigs.auditor_uuid
- IS 'Identifies the auditor.';
-COMMENT ON COLUMN auditor_denom_sigs.denominations_serial
- IS 'Denomination the signature is for.';
-COMMENT ON COLUMN auditor_denom_sigs.auditor_sig
- IS 'Signature of the auditor, of purpose TALER_SIGNATURE_AUDITOR_EXCHANGE_KEYS.';
-
-
--- ------------------------------ exchange_sign_keys ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS exchange_sign_keys
- (esk_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,exchange_pub BYTEA PRIMARY KEY CHECK (LENGTH(exchange_pub)=32)
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,valid_from INT8 NOT NULL
- ,expire_sign INT8 NOT NULL
- ,expire_legal INT8 NOT NULL
- );
-COMMENT ON TABLE exchange_sign_keys
- IS 'Table with master public key signatures on exchange online signing keys.';
-COMMENT ON COLUMN exchange_sign_keys.exchange_pub
- IS 'Public online signing key of the exchange.';
-COMMENT ON COLUMN exchange_sign_keys.master_sig
- IS 'Signature affirming the validity of the signing key of purpose TALER_SIGNATURE_MASTER_SIGNING_KEY_VALIDITY.';
-COMMENT ON COLUMN exchange_sign_keys.valid_from
- IS 'Time when this online signing key will first be used to sign messages.';
-COMMENT ON COLUMN exchange_sign_keys.expire_sign
- IS 'Time when this online signing key will no longer be used to sign.';
-COMMENT ON COLUMN exchange_sign_keys.expire_legal
- IS 'Time when this online signing key legally expires.';
-
-
--- ------------------------------ signkey_revocations ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS signkey_revocations
- (signkey_revocations_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,esk_serial INT8 PRIMARY KEY REFERENCES exchange_sign_keys (esk_serial) ON DELETE CASCADE
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- );
-COMMENT ON TABLE signkey_revocations
- IS 'Table storing which online signing keys have been revoked';
-
-
--- ------------------------------ extension ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS extensions
- (extension_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,name VARCHAR NOT NULL UNIQUE
- ,config BYTEA
- );
-COMMENT ON TABLE extensions
- IS 'Configurations of the activated extensions';
-COMMENT ON COLUMN extensions.name
- IS 'Name of the extension';
-COMMENT ON COLUMN extensions.config
- IS 'Configuration of the extension as JSON-blob, maybe NULL';
-
-
--- ------------------------------ known_coins ----------------------------------------
-
-SELECT create_table_known_coins();
-
-COMMENT ON TABLE known_coins
- IS 'information about coins and their signatures, so we do not have to store the signatures more than once if a coin is involved in multiple operations';
-COMMENT ON COLUMN known_coins.denominations_serial
- IS 'Denomination of the coin, determines the value of the original coin and applicable fees for coin-specific operations.';
-COMMENT ON COLUMN known_coins.coin_pub
- IS 'EdDSA public key of the coin';
-COMMENT ON COLUMN known_coins.remaining_val
- IS 'Value of the coin that remains to be spent';
-COMMENT ON COLUMN known_coins.age_commitment_hash
- IS 'Optional hash of the age commitment for age restrictions as per DD 24 (active if denom_type has the respective bit set)';
-COMMENT ON COLUMN known_coins.denom_sig
- IS 'This is the signature of the exchange that affirms that the coin is a valid coin. The specific signature type depends on denom_type of the denomination.';
-
-CREATE TABLE IF NOT EXISTS known_coins_default
- PARTITION OF known_coins
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_known_coins_partition('default');
-
-
--- ------------------------------ refresh_commitments ----------------------------------------
-
-SELECT create_table_refresh_commitments();
-
-COMMENT ON TABLE refresh_commitments
- IS 'Commitments made when melting coins and the gamma value chosen by the exchange.';
-COMMENT ON COLUMN refresh_commitments.noreveal_index
- IS 'The gamma value chosen by the exchange in the cut-and-choose protocol';
-COMMENT ON COLUMN refresh_commitments.rc
- IS 'Commitment made by the client, hash over the various client inputs in the cut-and-choose protocol';
-COMMENT ON COLUMN refresh_commitments.old_coin_pub
- IS 'Coin being melted in the refresh process.';
-
-CREATE TABLE IF NOT EXISTS refresh_commitments_default
- PARTITION OF refresh_commitments
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_refresh_commitments_partition('default');
-
-
--- ------------------------------ refresh_revealed_coins ----------------------------------------
-
-SELECT create_table_refresh_revealed_coins();
-
-COMMENT ON TABLE refresh_revealed_coins
- IS 'Revelations about the new coins that are to be created during a melting session.';
-COMMENT ON COLUMN refresh_revealed_coins.rrc_serial
- IS 'needed for exchange-auditor replication logic';
-COMMENT ON COLUMN refresh_revealed_coins.melt_serial_id
- IS 'Identifies the refresh commitment (rc) of the melt operation.';
-COMMENT ON COLUMN refresh_revealed_coins.freshcoin_index
- IS 'index of the fresh coin being created (one melt operation may result in multiple fresh coins)';
-COMMENT ON COLUMN refresh_revealed_coins.coin_ev
- IS 'envelope of the new coin to be signed';
-COMMENT ON COLUMN refresh_revealed_coins.ewv
- IS 'exchange contributed values in the creation of the fresh coin (see /csr)';
-COMMENT ON COLUMN refresh_revealed_coins.h_coin_ev
- IS 'hash of the envelope of the new coin to be signed (for lookups)';
-COMMENT ON COLUMN refresh_revealed_coins.ev_sig
- IS 'exchange signature over the envelope';
-
-CREATE TABLE IF NOT EXISTS refresh_revealed_coins_default
- PARTITION OF refresh_revealed_coins
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_refresh_revealed_coins_partition('default');
-
-
--- ------------------------------ refresh_transfer_keys ----------------------------------------
-
-SELECT create_table_refresh_transfer_keys();
-
-COMMENT ON TABLE refresh_transfer_keys
- IS 'Transfer keys of a refresh operation (the data revealed to the exchange).';
-COMMENT ON COLUMN refresh_transfer_keys.rtc_serial
- IS 'needed for exchange-auditor replication logic';
-COMMENT ON COLUMN refresh_transfer_keys.melt_serial_id
- IS 'Identifies the refresh commitment (rc) of the operation.';
-COMMENT ON COLUMN refresh_transfer_keys.transfer_pub
- IS 'transfer public key for the gamma index';
-COMMENT ON COLUMN refresh_transfer_keys.transfer_privs
- IS 'array of TALER_CNC_KAPPA - 1 transfer private keys that have been revealed, with the gamma entry being skipped';
-
-CREATE TABLE IF NOT EXISTS refresh_transfer_keys_default
- PARTITION OF refresh_transfer_keys
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_refresh_transfer_keys_partition('default');
-
-
--- ------------------------------ extension_details ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS extension_details
- (extension_details_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY
- ,extension_options VARCHAR)
- PARTITION BY HASH (extension_details_serial_id);
-COMMENT ON TABLE extension_details
- IS 'Extensions that were provided with deposits (not yet used).';
-COMMENT ON COLUMN extension_details.extension_options
- IS 'JSON object with options set that the exchange needs to consider when executing a deposit. Supported details depend on the extensions supported by the exchange.';
-
-CREATE TABLE IF NOT EXISTS extension_details_default
- PARTITION OF extension_details
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-
--- ------------------------------ deposits ----------------------------------------
-
-SELECT create_table_deposits();
-
-COMMENT ON TABLE deposits
- IS 'Deposits we have received and for which we need to make (aggregate) wire transfers (and manage refunds).';
-COMMENT ON COLUMN deposits.shard
- IS 'Used for load sharding in the materialized indices. Should be set based on merchant_pub. 64-bit value because we need an *unsigned* 32-bit value.';
-COMMENT ON COLUMN deposits.known_coin_id
- IS 'Used for garbage collection';
-COMMENT ON COLUMN deposits.wire_target_h_payto
- IS 'Identifies the target bank account and KYC status';
-COMMENT ON COLUMN deposits.wire_salt
- IS 'Salt used when hashing the payto://-URI to get the h_wire';
-COMMENT ON COLUMN deposits.done
- IS 'Set to TRUE once we have included this deposit in some aggregate wire transfer to the merchant';
-COMMENT ON COLUMN deposits.extension_blocked
- IS 'True if the aggregation of the deposit is currently blocked by some extension mechanism. Used to filter out deposits that must not be processed by the canonical deposit logic.';
-COMMENT ON COLUMN deposits.extension_details_serial_id
- IS 'References extensions table, NULL if extensions are not used';
-
-CREATE TABLE IF NOT EXISTS deposits_default
- PARTITION OF deposits
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_deposits_partition('default');
-
-
-SELECT create_table_deposits_by_ready();
-
-COMMENT ON TABLE deposits_by_ready
- IS 'Enables fast lookups for deposits_get_ready, auto-populated via TRIGGER below';
-
-CREATE TABLE IF NOT EXISTS deposits_by_ready_default
- PARTITION OF deposits_by_ready
- DEFAULT;
-
-
-SELECT create_table_deposits_for_matching();
-
-COMMENT ON TABLE deposits_for_matching
- IS 'Enables fast lookups for deposits_iterate_matching, auto-populated via TRIGGER below';
-
-CREATE TABLE IF NOT EXISTS deposits_for_matching_default
- PARTITION OF deposits_for_matching
- DEFAULT;
-
-
-CREATE OR REPLACE FUNCTION deposits_insert_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
-
- IF (is_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION deposits_insert_trigger()
- IS 'Replicate deposit inserts into materialized indices.';
-
-CREATE TRIGGER deposits_on_insert
- AFTER INSERT
- ON deposits
- FOR EACH ROW EXECUTE FUNCTION deposits_insert_trigger();
-
-CREATE OR REPLACE FUNCTION deposits_update_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-DECLARE
- is_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
- is_ready = NOT (NEW.done OR NEW.extension_blocked);
- IF (was_ready AND NOT is_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- IF (is_ready AND NOT was_ready)
- THEN
- INSERT INTO deposits_by_ready
- (wire_deadline
- ,shard
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.wire_deadline
- ,NEW.shard
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- INSERT INTO deposits_for_matching
- (refund_deadline
- ,merchant_pub
- ,coin_pub
- ,deposit_serial_id)
- VALUES
- (NEW.refund_deadline
- ,NEW.merchant_pub
- ,NEW.coin_pub
- ,NEW.deposit_serial_id);
- END IF;
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION deposits_update_trigger()
- IS 'Replicate deposits changes into materialized indices.';
-
-CREATE TRIGGER deposits_on_update
- AFTER UPDATE
- ON deposits
- FOR EACH ROW EXECUTE FUNCTION deposits_update_trigger();
-
-CREATE OR REPLACE FUNCTION deposits_delete_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-DECLARE
- was_ready BOOLEAN;
-BEGIN
- was_ready = NOT (OLD.done OR OLD.extension_blocked);
-
- IF (was_ready)
- THEN
- DELETE FROM deposits_by_ready
- WHERE wire_deadline = OLD.wire_deadline
- AND shard = OLD.shard
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- DELETE FROM deposits_for_matching
- WHERE refund_deadline = OLD.refund_deadline
- AND merchant_pub = OLD.merchant_pub
- AND coin_pub = OLD.coin_pub
- AND deposit_serial_id = OLD.deposit_serial_id;
- END IF;
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION deposits_delete_trigger()
- IS 'Replicate deposit deletions into materialized indices.';
-
-CREATE TRIGGER deposits_on_delete
- AFTER DELETE
- ON deposits
- FOR EACH ROW EXECUTE FUNCTION deposits_delete_trigger();
-
-
--- ------------------------------ refunds ----------------------------------------
-
-SELECT create_table_refunds();
-
-COMMENT ON TABLE refunds
- IS 'Data on coins that were refunded. Technically, refunds always apply against specific deposit operations involving a coin. The combination of coin_pub, merchant_pub, h_contract_terms and rtransaction_id MUST be unique, and we usually select by coin_pub so that one goes first.';
-COMMENT ON COLUMN refunds.deposit_serial_id
- IS 'Identifies ONLY the merchant_pub, h_contract_terms and coin_pub. Multiple deposits may match a refund, this only identifies one of them.';
-COMMENT ON COLUMN refunds.rtransaction_id
- IS 'used by the merchant to make refunds unique in case the same coin for the same deposit gets a subsequent (higher) refund';
-
-CREATE TABLE IF NOT EXISTS refunds_default
- PARTITION OF refunds
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_refunds_partition('default');
-
-
--- ------------------------------ wire_out ----------------------------------------
-
-SELECT create_table_wire_out();
-
-COMMENT ON TABLE wire_out
- IS 'wire transfers the exchange has executed';
-COMMENT ON COLUMN wire_out.exchange_account_section
- IS 'identifies the configuration section with the debit account of this payment';
-COMMENT ON COLUMN wire_out.wire_target_h_payto
- IS 'Identifies the credited bank account and KYC status';
-
-CREATE TABLE IF NOT EXISTS wire_out_default
- PARTITION OF wire_out
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wire_out_partition('default');
-
-CREATE OR REPLACE FUNCTION wire_out_delete_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM aggregation_tracking
- WHERE wtid_raw = OLD.wtid_raw;
- RETURN OLD;
-END $$;
-COMMENT ON FUNCTION wire_out_delete_trigger()
- IS 'Replicate reserve_out deletions into aggregation_tracking. This replaces an earlier use of an ON DELETE CASCADE that required a DEFERRABLE constraint and conflicted with nice partitioning.';
-
-CREATE TRIGGER wire_out_on_delete
- AFTER DELETE
- ON wire_out
- FOR EACH ROW EXECUTE FUNCTION wire_out_delete_trigger();
-
-
-
--- ------------------------------ aggregation_transient ----------------------------------------
-
-SELECT create_table_aggregation_transient();
-
-COMMENT ON TABLE aggregation_transient
- IS 'aggregations currently happening (lacking wire_out, usually because the amount is too low); this table is not replicated';
-COMMENT ON COLUMN aggregation_transient.amount_val
- IS 'Sum of all of the aggregated deposits (without deposit fees)';
-COMMENT ON COLUMN aggregation_transient.wtid_raw
- IS 'identifier of the wire transfer';
-
-CREATE TABLE IF NOT EXISTS aggregation_transient_default
- PARTITION OF aggregation_transient
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-
--- ------------------------------ aggregation_tracking ----------------------------------------
-
-SELECT create_table_aggregation_tracking();
-
-COMMENT ON TABLE aggregation_tracking
- IS 'mapping from wire transfer identifiers (WTID) to deposits (and back)';
-COMMENT ON COLUMN aggregation_tracking.wtid_raw
- IS 'identifier of the wire transfer';
-
-CREATE TABLE IF NOT EXISTS aggregation_tracking_default
- PARTITION OF aggregation_tracking
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_aggregation_tracking_partition('default');
-
-
--- ------------------------------ wire_fee ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS wire_fee
- (wire_fee_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,wire_method VARCHAR NOT NULL
- ,start_date INT8 NOT NULL
- ,end_date INT8 NOT NULL
- ,wire_fee_val INT8 NOT NULL
- ,wire_fee_frac INT4 NOT NULL
- ,closing_fee_val INT8 NOT NULL
- ,closing_fee_frac INT4 NOT NULL
- ,wad_fee_val INT8 NOT NULL
- ,wad_fee_frac INT4 NOT NULL
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,PRIMARY KEY (wire_method, start_date)
- );
-COMMENT ON TABLE wire_fee
- IS 'list of the wire fees of this exchange, by date';
-COMMENT ON COLUMN wire_fee.wire_fee_serial
- IS 'needed for exchange-auditor replication logic';
-
-CREATE INDEX IF NOT EXISTS wire_fee_by_end_date_index
- ON wire_fee
- (end_date);
-
-
--- ------------------------------ global_fee ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS global_fee
- (global_fee_serial BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,start_date INT8 NOT NULL
- ,end_date INT8 NOT NULL
- ,history_fee_val INT8 NOT NULL
- ,history_fee_frac INT4 NOT NULL
- ,kyc_fee_val INT8 NOT NULL
- ,kyc_fee_frac INT4 NOT NULL
- ,account_fee_val INT8 NOT NULL
- ,account_fee_frac INT4 NOT NULL
- ,purse_fee_val INT8 NOT NULL
- ,purse_fee_frac INT4 NOT NULL
- ,purse_timeout INT8 NOT NULL
- ,kyc_timeout INT8 NOT NULL
- ,history_expiration INT8 NOT NULL
- ,purse_account_limit INT4 NOT NULL
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,PRIMARY KEY (start_date)
- );
-COMMENT ON TABLE global_fee
- IS 'list of the global fees of this exchange, by date';
-COMMENT ON COLUMN global_fee.global_fee_serial
- IS 'needed for exchange-auditor replication logic';
-
-CREATE INDEX IF NOT EXISTS global_fee_by_end_date_index
- ON global_fee
- (end_date);
-
-
--- ------------------------------ recoup ----------------------------------------
-
-SELECT create_table_recoup();
-
-COMMENT ON TABLE recoup
- IS 'Information about recoups that were executed between a coin and a reserve. In this type of recoup, the amount is credited back to the reserve from which the coin originated.';
-COMMENT ON COLUMN recoup.coin_pub
- IS 'Coin that is being debited in the recoup. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-COMMENT ON COLUMN recoup.reserve_out_serial_id
- IS 'Identifies the h_blind_ev of the recouped coin and provides the link to the credited reserve.';
-COMMENT ON COLUMN recoup.coin_sig
- IS 'Signature by the coin affirming the recoup, of type TALER_SIGNATURE_WALLET_COIN_RECOUP';
-COMMENT ON COLUMN recoup.coin_blind
- IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the withdraw operation.';
-
-CREATE TABLE IF NOT EXISTS recoup_default
- PARTITION OF recoup
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_recoup_partition('default');
-
-
-SELECT create_table_recoup_by_reserve();
-
-COMMENT ON TABLE recoup_by_reserve
- IS 'Information in this table is strictly redundant with that of recoup, but saved by a different primary key for fast lookups by reserve_out_serial_id.';
-
-CREATE TABLE IF NOT EXISTS recoup_by_reserve_default
- PARTITION OF recoup_by_reserve
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-CREATE OR REPLACE FUNCTION recoup_insert_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- INSERT INTO recoup_by_reserve
- (reserve_out_serial_id
- ,coin_pub)
- VALUES
- (NEW.reserve_out_serial_id
- ,NEW.coin_pub);
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION recoup_insert_trigger()
- IS 'Replicate recoup inserts into recoup_by_reserve table.';
-
-CREATE TRIGGER recoup_on_insert
- AFTER INSERT
- ON recoup
- FOR EACH ROW EXECUTE FUNCTION recoup_insert_trigger();
-
-CREATE OR REPLACE FUNCTION recoup_delete_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- DELETE FROM recoup_by_reserve
- WHERE reserve_out_serial_id = OLD.reserve_out_serial_id
- AND coin_pub = OLD.coin_pub;
- RETURN OLD;
-END $$;
-COMMENT ON FUNCTION recoup_delete_trigger()
- IS 'Replicate recoup deletions into recoup_by_reserve table.';
-
-CREATE TRIGGER recoup_on_delete
- AFTER DELETE
- ON recoup
- FOR EACH ROW EXECUTE FUNCTION recoup_delete_trigger();
-
-
--- ------------------------------ recoup_refresh ----------------------------------------
-
-SELECT create_table_recoup_refresh();
-
-COMMENT ON TABLE recoup_refresh
- IS 'Table of coins that originated from a refresh operation and that were recouped. Links the (fresh) coin to the melted operation (and thus the old coin). A recoup on a refreshed coin credits the old coin and debits the fresh coin.';
-COMMENT ON COLUMN recoup_refresh.coin_pub
- IS 'Refreshed coin of a revoked denomination where the residual value is credited to the old coin. Do not CASCADE ON DROP on the coin_pub, as we may keep the coin alive!';
-COMMENT ON COLUMN recoup_refresh.known_coin_id
- IS 'FIXME: (To be) used for garbage collection (in the future)';
-COMMENT ON COLUMN recoup_refresh.rrc_serial
- IS 'Link to the refresh operation. Also identifies the h_blind_ev of the recouped coin (as h_coin_ev).';
-COMMENT ON COLUMN recoup_refresh.coin_blind
- IS 'Denomination blinding key used when creating the blinded coin from the planchet. Secret revealed during the recoup to provide the linkage between the coin and the refresh operation.';
-
-CREATE TABLE IF NOT EXISTS recoup_refresh_default
- PARTITION OF recoup_refresh
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_recoup_refresh_partition('default');
-
-
--- ------------------------------ prewire ----------------------------------------
-
-SELECT create_table_prewire();
-
-COMMENT ON TABLE prewire
- IS 'pre-commit data for wire transfers we are about to execute';
-COMMENT ON COLUMN prewire.failed
- IS 'set to TRUE if the bank responded with a non-transient failure to our transfer request';
-COMMENT ON COLUMN prewire.finished
- IS 'set to TRUE once bank confirmed receiving the wire transfer request';
-COMMENT ON COLUMN prewire.buf
- IS 'serialized data to send to the bank to execute the wire transfer';
-
-CREATE TABLE IF NOT EXISTS prewire_default
- PARTITION OF prewire
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-
--- ------------------------------ wire_accounts ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS wire_accounts
- (payto_uri VARCHAR PRIMARY KEY
- ,master_sig BYTEA CHECK (LENGTH(master_sig)=64)
- ,is_active BOOLEAN NOT NULL
- ,last_change INT8 NOT NULL
- );
-COMMENT ON TABLE wire_accounts
- IS 'Table with current and historic bank accounts of the exchange. Entries never expire as we need to remember the last_change column indefinitely.';
-COMMENT ON COLUMN wire_accounts.payto_uri
- IS 'payto URI (RFC 8905) with the bank account of the exchange.';
-COMMENT ON COLUMN wire_accounts.master_sig
- IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS';
-COMMENT ON COLUMN wire_accounts.is_active
- IS 'true if we are currently supporting the use of this account.';
-COMMENT ON COLUMN wire_accounts.last_change
- IS 'Latest time when active status changed. Used to detect replays of old messages.';
--- "wire_accounts" has no sequence because it is a 'mutable' table
--- and is of no concern to the auditor
-
-
--- ------------------------------ cs_nonce_locks ----------------------------------------
-
-SELECT create_table_cs_nonce_locks();
-
-COMMENT ON TABLE cs_nonce_locks
- IS 'ensures a Clause Schnorr client nonce is locked for use with an operation identified by a hash';
-COMMENT ON COLUMN cs_nonce_locks.nonce
- IS 'actual nonce submitted by the client';
-COMMENT ON COLUMN cs_nonce_locks.op_hash
- IS 'hash (RC for refresh, blind coin hash for withdraw) the nonce may be used with';
-COMMENT ON COLUMN cs_nonce_locks.max_denomination_serial
- IS 'Maximum number of a CS denomination serial the nonce could be used with, for GC';
-
-CREATE TABLE IF NOT EXISTS cs_nonce_locks_default
- PARTITION OF cs_nonce_locks
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_cs_nonce_locks_partition('default');
-
-
--- ------------------------------ work_shards ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS work_shards
- (shard_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,last_attempt INT8 NOT NULL
- ,start_row INT8 NOT NULL
- ,end_row INT8 NOT NULL
- ,completed BOOLEAN NOT NULL DEFAULT FALSE
- ,job_name VARCHAR NOT NULL
- ,PRIMARY KEY (job_name, start_row)
- );
-COMMENT ON TABLE work_shards
- IS 'coordinates work between multiple processes working on the same job';
-COMMENT ON COLUMN work_shards.shard_serial_id
- IS 'unique serial number identifying the shard';
-COMMENT ON COLUMN work_shards.last_attempt
- IS 'last time a worker attempted to work on the shard';
-COMMENT ON COLUMN work_shards.completed
- IS 'set to TRUE once the shard is finished by a worker';
-COMMENT ON COLUMN work_shards.start_row
- IS 'row at which the shard scope starts, inclusive';
-COMMENT ON COLUMN work_shards.end_row
- IS 'row at which the shard scope ends, exclusive';
-COMMENT ON COLUMN work_shards.job_name
- IS 'unique name of the job the workers on this shard are performing';
-
-CREATE INDEX IF NOT EXISTS work_shards_by_job_name_completed_last_attempt_index
- ON work_shards
- (job_name
- ,completed
- ,last_attempt ASC
- );
-
-
--- ------------------------------ revolving_work_shards ----------------------------------------
-
-CREATE UNLOGGED TABLE IF NOT EXISTS revolving_work_shards
- (shard_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,last_attempt INT8 NOT NULL
- ,start_row INT4 NOT NULL
- ,end_row INT4 NOT NULL
- ,active BOOLEAN NOT NULL DEFAULT FALSE
- ,job_name VARCHAR NOT NULL
- ,PRIMARY KEY (job_name, start_row)
- );
-COMMENT ON TABLE revolving_work_shards
- IS 'coordinates work between multiple processes working on the same job with partitions that need to be repeatedly processed; unlogged because on system crashes the locks represented by this table will have to be cleared anyway, typically using "taler-exchange-dbinit -s"';
-COMMENT ON COLUMN revolving_work_shards.shard_serial_id
- IS 'unique serial number identifying the shard';
-COMMENT ON COLUMN revolving_work_shards.last_attempt
- IS 'last time a worker attempted to work on the shard';
-COMMENT ON COLUMN revolving_work_shards.active
- IS 'set to TRUE when a worker is active on the shard';
-COMMENT ON COLUMN revolving_work_shards.start_row
- IS 'row at which the shard scope starts, inclusive';
-COMMENT ON COLUMN revolving_work_shards.end_row
- IS 'row at which the shard scope ends, exclusive';
-COMMENT ON COLUMN revolving_work_shards.job_name
- IS 'unique name of the job the workers on this shard are performing';
-
-CREATE INDEX IF NOT EXISTS revolving_work_shards_by_job_name_active_last_attempt_index
- ON revolving_work_shards
- (job_name
- ,active
- ,last_attempt
- );
-
---------------------------------------------------------------------------
--- Tables for P2P payments
---------------------------------------------------------------------------
-
--- ------------------------------ partners ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS partners
- (partner_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY UNIQUE
- ,partner_master_pub BYTEA NOT NULL CHECK(LENGTH(partner_master_pub)=32)
- ,start_date INT8 NOT NULL
- ,end_date INT8 NOT NULL
- ,next_wad INT8 NOT NULL DEFAULT (0)
- ,wad_frequency INT8 NOT NULL
- ,wad_fee_val INT8 NOT NULL
- ,wad_fee_frac INT4 NOT NULL
- ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64)
- ,partner_base_url TEXT NOT NULL
- );
-COMMENT ON TABLE partners
- IS 'exchanges we do wad transfers to';
-COMMENT ON COLUMN partners.partner_master_pub
- IS 'offline master public key of the partner';
-COMMENT ON COLUMN partners.start_date
- IS 'starting date of the partnership';
-COMMENT ON COLUMN partners.end_date
- IS 'end date of the partnership';
-COMMENT ON COLUMN partners.next_wad
- IS 'at what time should we do the next wad transfer to this partner (frequently updated); set to forever after the end_date';
-COMMENT ON COLUMN partners.wad_frequency
- IS 'how often do we promise to do wad transfers';
-COMMENT ON COLUMN partners.wad_fee_val
- IS 'how high is the fee for a wallet to be added to a wad to this partner';
-COMMENT ON COLUMN partners.partner_base_url
- IS 'base URL of the REST API for this partner';
-COMMENT ON COLUMN partners.master_sig
- IS 'signature of our master public key affirming the partnership, of purpose TALER_SIGNATURE_MASTER_PARTNER_DETAILS';
-
-CREATE INDEX IF NOT EXISTS partner_by_wad_time
- ON partners (next_wad ASC);
-
--- ------------------------------ purse_requests ----------------------------------------
-
-SELECT create_table_purse_requests();
-
-COMMENT ON TABLE purse_requests
- IS 'Requests establishing purses, associating them with a contract but without a target reserve';
-COMMENT ON COLUMN purse_requests.purse_pub
- IS 'Public key of the purse';
-COMMENT ON COLUMN purse_requests.purse_creation
- IS 'Local time when the purse was created. Determines applicable purse fees.';
-COMMENT ON COLUMN purse_requests.purse_expiration
- IS 'When the purse is set to expire';
-COMMENT ON COLUMN purse_requests.h_contract_terms
- IS 'Hash of the contract the parties are to agree to';
-COMMENT ON COLUMN purse_requests.flags
- IS 'see the enum TALER_WalletAccountMergeFlags';
-COMMENT ON COLUMN purse_requests.finished
- IS 'set to TRUE once the purse has been merged (into reserve or wad) or the coins were refunded (transfer aborted)';
-COMMENT ON COLUMN purse_requests.refunded
- IS 'set to TRUE if the purse could not be merged and thus all deposited coins were refunded';
-COMMENT ON COLUMN purse_requests.in_reserve_quota
- IS 'set to TRUE if this purse currently counts against the number of free purses in the respective reserve';
-COMMENT ON COLUMN purse_requests.amount_with_fee_val
- IS 'Total amount expected to be in the purse';
-COMMENT ON COLUMN purse_requests.purse_fee_val
- IS 'Purse fee the client agreed to pay from the reserve (accepted by the exchange at the time the purse was created). Zero if in_reserve_quota is TRUE.';
-COMMENT ON COLUMN purse_requests.balance_val
- IS 'Total amount actually in the purse';
-COMMENT ON COLUMN purse_requests.purse_sig
- IS 'Signature of the purse affirming the purse parameters, of type TALER_SIGNATURE_PURSE_REQUEST';
-
-CREATE TABLE IF NOT EXISTS purse_requests_default
- PARTITION OF purse_requests
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_purse_requests_partition('default');
-
-
--- ------------------------------ purse_refunds ----------------------------------------
-
-SELECT create_table_purse_refunds();
-
-COMMENT ON TABLE purse_refunds
- IS 'Purses that were refunded due to expiration';
-COMMENT ON COLUMN purse_refunds.purse_pub
- IS 'Public key of the purse';
-
-CREATE TABLE IF NOT EXISTS purse_refunds_default
- PARTITION OF purse_refunds
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_purse_refunds_partition('default');
-
-
--- ------------------------------ purse_merges ----------------------------------------
-
-SELECT create_table_purse_merges();
-
-COMMENT ON TABLE purse_merges
- IS 'Merge requests where a purse-owner requested merging the purse into the account';
-COMMENT ON COLUMN purse_merges.partner_serial_id
- IS 'identifies the partner exchange, NULL in case the target reserve lives at this exchange';
-COMMENT ON COLUMN purse_merges.reserve_pub
- IS 'public key of the target reserve';
-COMMENT ON COLUMN purse_merges.purse_pub
- IS 'public key of the purse';
-COMMENT ON COLUMN purse_merges.merge_sig
- IS 'signature by the purse private key affirming the merge, of type TALER_SIGNATURE_WALLET_PURSE_MERGE';
-COMMENT ON COLUMN purse_merges.merge_timestamp
- IS 'when was the merge message signed';
-
-CREATE TABLE IF NOT EXISTS purse_merges_default
- PARTITION OF purse_merges
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_purse_merges_partition('default');
-
-
--- ------------------------------ account_merges ----------------------------------------
-
-SELECT create_table_account_merges();
-
-COMMENT ON TABLE account_merges
- IS 'Merge requests where a purse- and account-owner requested merging the purse into the account';
-COMMENT ON COLUMN account_merges.reserve_pub
- IS 'public key of the target reserve';
-COMMENT ON COLUMN account_merges.purse_pub
- IS 'public key of the purse';
-COMMENT ON COLUMN account_merges.reserve_sig
- IS 'signature by the reserve private key affirming the merge, of type TALER_SIGNATURE_WALLET_ACCOUNT_MERGE';
-
-CREATE TABLE IF NOT EXISTS account_merges_default
- PARTITION OF account_merges
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_account_merges_partition('default');
-
-
--- ------------------------------ contracts ----------------------------------------
-
-SELECT create_table_contracts();
-
-COMMENT ON TABLE contracts
- IS 'encrypted contracts associated with purses';
-COMMENT ON COLUMN contracts.purse_pub
- IS 'public key of the purse that the contract is associated with';
-COMMENT ON COLUMN contracts.contract_sig
- IS 'signature over the encrypted contract by the purse contract key';
-COMMENT ON COLUMN contracts.pub_ckey
- IS 'Public ECDH key used to encrypt the contract, to be used with the purse private key for decryption';
-COMMENT ON COLUMN contracts.e_contract
- IS 'AES-GCM encrypted contract terms (contains gzip compressed JSON after decryption)';
-
-CREATE TABLE IF NOT EXISTS contracts_default
- PARTITION OF contracts
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_contracts_partition('default');
-
-
--- ------------------------------ history_requests ----------------------------------------
-
-SELECT create_table_history_requests();
-
-COMMENT ON TABLE history_requests
- IS 'Paid history requests issued by a client against a reserve';
-COMMENT ON COLUMN history_requests.request_timestamp
- IS 'When was the history request made';
-COMMENT ON COLUMN history_requests.reserve_sig
- IS 'Signature approving payment for the history request';
-COMMENT ON COLUMN history_requests.history_fee_val
- IS 'History fee approved by the signature';
-
-CREATE TABLE IF NOT EXISTS history_requests_default
- PARTITION OF history_requests
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
--- ------------------------------ close_requests ----------------------------------------
-
-SELECT create_table_close_requests();
-
-COMMENT ON TABLE close_requests
- IS 'Explicit requests by a reserve owner to close a reserve immediately';
-COMMENT ON COLUMN close_requests.close_timestamp
- IS 'When the request was created by the client';
-COMMENT ON COLUMN close_requests.reserve_sig
- IS 'Signature affirming that the reserve is to be closed';
-COMMENT ON COLUMN close_requests.close_val
- IS 'Balance of the reserve at the time of closing, to be wired to the associated bank account (minus the closing fee)';
-
-CREATE TABLE IF NOT EXISTS close_requests_default
- PARTITION OF close_requests
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-
--- ------------------------------ purse_deposits ----------------------------------------
-
-SELECT create_table_purse_deposits();
-
-COMMENT ON TABLE purse_deposits
- IS 'Requests depositing coins into a purse';
-COMMENT ON COLUMN purse_deposits.partner_serial_id
- IS 'identifies the partner exchange, NULL in case the target purse lives at this exchange';
-COMMENT ON COLUMN purse_deposits.purse_pub
- IS 'Public key of the purse';
-COMMENT ON COLUMN purse_deposits.coin_pub
- IS 'Public key of the coin being deposited';
-COMMENT ON COLUMN purse_deposits.amount_with_fee_val
- IS 'Total amount being deposited';
-COMMENT ON COLUMN purse_deposits.coin_sig
- IS 'Signature of the coin affirming the deposit into the purse, of type TALER_SIGNATURE_PURSE_DEPOSIT';
-
-CREATE TABLE IF NOT EXISTS purse_deposits_default
- PARTITION OF purse_deposits
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_purse_deposits_partition('default');
-
-
--- ------------------------------ wads_out ----------------------------------------
-
-SELECT create_table_wads_out();
-
-COMMENT ON TABLE wads_out
- IS 'Wire transfers made to another exchange to transfer purse funds';
-COMMENT ON COLUMN wads_out.wad_id
- IS 'Unique identifier of the wad, part of the wire transfer subject';
-COMMENT ON COLUMN wads_out.partner_serial_id
- IS 'target exchange of the wad';
-COMMENT ON COLUMN wads_out.amount_val
- IS 'Amount that was wired';
-COMMENT ON COLUMN wads_out.execution_time
- IS 'Time when the wire transfer was scheduled';
-
-CREATE TABLE IF NOT EXISTS wads_out_default
- PARTITION OF wads_out
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wads_out_partition('default');
-
-
--- ------------------------------ wads_out_entries ----------------------------------------
-
-SELECT create_table_wad_out_entries();
-
-COMMENT ON TABLE wad_out_entries
- IS 'Purses combined into a wad';
-COMMENT ON COLUMN wad_out_entries.wad_out_serial_id
- IS 'Wad the purse was part of';
-COMMENT ON COLUMN wad_out_entries.reserve_pub
- IS 'Target reserve for the purse';
-COMMENT ON COLUMN wad_out_entries.purse_pub
- IS 'Public key of the purse';
-COMMENT ON COLUMN wad_out_entries.h_contract
- IS 'Hash of the contract associated with the purse';
-COMMENT ON COLUMN wad_out_entries.purse_expiration
- IS 'Time when the purse expires';
-COMMENT ON COLUMN wad_out_entries.merge_timestamp
- IS 'Time when the merge was approved';
-COMMENT ON COLUMN wad_out_entries.amount_with_fee_val
- IS 'Total amount in the purse';
-COMMENT ON COLUMN wad_out_entries.wad_fee_val
- IS 'Wat fee charged to the purse';
-COMMENT ON COLUMN wad_out_entries.deposit_fees_val
- IS 'Total deposit fees charged to the purse';
-COMMENT ON COLUMN wad_out_entries.reserve_sig
- IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-COMMENT ON COLUMN wad_out_entries.purse_sig
- IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-CREATE TABLE IF NOT EXISTS wad_out_entries_default
- PARTITION OF wad_out_entries
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wad_out_entries_partition('default');
-
--- ------------------------------ wads_in ----------------------------------------
-
-SELECT create_table_wads_in();
-
-COMMENT ON TABLE wads_in
- IS 'Incoming exchange-to-exchange wad wire transfers';
-COMMENT ON COLUMN wads_in.wad_id
- IS 'Unique identifier of the wad, part of the wire transfer subject';
-COMMENT ON COLUMN wads_in.origin_exchange_url
- IS 'Base URL of the originating URL, also part of the wire transfer subject';
-COMMENT ON COLUMN wads_in.amount_val
- IS 'Actual amount that was received by our exchange';
-COMMENT ON COLUMN wads_in.arrival_time
- IS 'Time when the wad was received';
-
-CREATE TABLE IF NOT EXISTS wads_in_default
- PARTITION OF wads_in
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wads_in_partition('default');
-
-
--- ------------------------------ wads_in_entries ----------------------------------------
-
-SELECT create_table_wad_in_entries();
-
-COMMENT ON TABLE wad_in_entries
- IS 'list of purses aggregated in a wad according to the sending exchange';
-COMMENT ON COLUMN wad_in_entries.wad_in_serial_id
- IS 'wad for which the given purse was included in the aggregation';
-COMMENT ON COLUMN wad_in_entries.reserve_pub
- IS 'target account of the purse (must be at the local exchange)';
-COMMENT ON COLUMN wad_in_entries.purse_pub
- IS 'public key of the purse that was merged';
-COMMENT ON COLUMN wad_in_entries.h_contract
- IS 'hash of the contract terms of the purse';
-COMMENT ON COLUMN wad_in_entries.purse_expiration
- IS 'Time when the purse was set to expire';
-COMMENT ON COLUMN wad_in_entries.merge_timestamp
- IS 'Time when the merge was approved';
-COMMENT ON COLUMN wad_in_entries.amount_with_fee_val
- IS 'Total amount in the purse';
-COMMENT ON COLUMN wad_in_entries.wad_fee_val
- IS 'Total wad fees paid by the purse';
-COMMENT ON COLUMN wad_in_entries.deposit_fees_val
- IS 'Total deposit fees paid when depositing coins into the purse';
-COMMENT ON COLUMN wad_in_entries.reserve_sig
- IS 'Signature by the receiving reserve, of purpose TALER_SIGNATURE_ACCOUNT_MERGE';
-COMMENT ON COLUMN wad_in_entries.purse_sig
- IS 'Signature by the purse of purpose TALER_SIGNATURE_PURSE_MERGE';
-
-CREATE TABLE IF NOT EXISTS wad_in_entries_default
- PARTITION OF wad_in_entries
- FOR VALUES WITH (MODULUS 1, REMAINDER 0);
-
-SELECT add_constraints_to_wad_in_entries_partition('default');
-
-
--- ------------------------------ partner_accounts ----------------------------------------
-
-CREATE TABLE IF NOT EXISTS partner_accounts
- (payto_uri VARCHAR PRIMARY KEY
- ,partner_serial_id INT8 REFERENCES partners(partner_serial_id) ON DELETE CASCADE
- ,partner_master_sig BYTEA CHECK (LENGTH(partner_master_sig)=64)
- ,last_seen INT8 NOT NULL
- );
-CREATE INDEX IF NOT EXISTS partner_accounts_index_by_partner_and_time
- ON partner_accounts (partner_serial_id,last_seen);
-COMMENT ON TABLE partner_accounts
- IS 'Table with bank accounts of the partner exchange. Entries never expire as we need to remember the signature for the auditor.';
-COMMENT ON COLUMN partner_accounts.payto_uri
- IS 'payto URI (RFC 8905) with the bank account of the partner exchange.';
-COMMENT ON COLUMN partner_accounts.partner_master_sig
- IS 'Signature of purpose TALER_SIGNATURE_MASTER_WIRE_DETAILS by the partner master public key';
-COMMENT ON COLUMN partner_accounts.last_seen
- IS 'Last time we saw this account as being active at the partner exchange. Used to select the most recent entry, and to detect when we should check again.';
-
-
------------------------ router helper table (not synchronzied) ------------------------
-
-CREATE TABLE IF NOT EXISTS purse_actions
- (purse_pub BYTEA NOT NULL PRIMARY KEY CHECK(LENGTH(purse_pub)=32)
- ,action_date INT8 NOT NULL
- ,partner_serial_id INT8
- );
-COMMENT ON TABLE purse_actions
- IS 'purses awaiting some action by the router';
-COMMENT ON COLUMN purse_actions.purse_pub
- IS 'public (contract) key of the purse';
-COMMENT ON COLUMN purse_actions.action_date
- IS 'when is the purse ready for action';
-COMMENT ON COLUMN purse_actions.partner_serial_id
- IS 'wad target of an outgoing wire transfer, 0 for local, NULL if the purse is unmerged and thus the target is still unknown';
-
-CREATE INDEX IF NOT EXISTS purse_action_by_target
- ON purse_actions
- (partner_serial_id,action_date);
-
-
-CREATE OR REPLACE FUNCTION purse_requests_insert_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- ASSERT NOT NEW.finished,'Internal invariant violated';
- INSERT INTO
- purse_actions
- (purse_pub
- ,action_date)
- VALUES
- (NEW.purse_pub
- ,NEW.purse_expiration);
- RETURN NEW;
-END $$;
-COMMENT ON FUNCTION purse_requests_insert_trigger()
- IS 'When a purse is created, insert it into the purse_action table to take action when the purse expires.';
-
-CREATE TRIGGER purse_requests_on_insert
- AFTER INSERT
- ON purse_requests
- FOR EACH ROW EXECUTE FUNCTION purse_requests_insert_trigger();
-COMMENT ON TRIGGER purse_requests_on_insert
- ON purse_requests
- IS 'Here we install an entry for the purse expiration.';
-
-
-CREATE OR REPLACE FUNCTION purse_requests_on_update_trigger()
- RETURNS trigger
- LANGUAGE plpgsql
- AS $$
-BEGIN
- IF (NEW.finished AND NOT OLD.finished)
- THEN
- -- If this purse counted against the reserve's
- -- quota of purses, decrement the reserve accounting.
- IF (NEW.in_reserve_quota)
- THEN
- UPDATE reserves
- SET purses_active=purses_active-1
- WHERE reserve_pub IN
- (SELECT reserve_pub
- FROM purse_merges
- WHERE purse_pub=NEW.purse_pub
- LIMIT 1);
- NEW.in_reserve_quota=FALSE;
- END IF;
- -- Delete from the purse_actions table, we are done
- -- with this purse for good.
- DELETE FROM purse_actions
- WHERE purse_pub=NEW.purse_pub;
- RETURN NEW;
- END IF;
-
- RETURN NEW;
-END $$;
-
-COMMENT ON FUNCTION purse_requests_on_update_trigger()
- IS 'Trigger the router if the purse is ready. Also removes the entry from the router watchlist once the purse is finished.';
-
-CREATE TRIGGER purse_requests_on_update
- BEFORE UPDATE
- ON purse_requests
- FOR EACH ROW EXECUTE FUNCTION purse_requests_on_update_trigger();
-COMMENT ON TRIGGER purse_requests_on_update
- ON purse_requests
- IS 'This covers the case where a deposit is made into a purse, which inherently then changes the purse balance via an UPDATE. If the merge is already present and the balance matches the total, we trigger the router. Once the router sets the purse to finished, the trigger will remove the purse from the watchlist of the router.';
-
----------------------------------------------------------------------------
--- Stored procedures
----------------------------------------------------------------------------
-
-CREATE OR REPLACE FUNCTION exchange_do_withdraw(
- IN cs_nonce BYTEA,
- IN amount_val INT8,
- IN amount_frac INT4,
- IN h_denom_pub BYTEA,
- IN rpub BYTEA,
- IN reserve_sig BYTEA,
- IN h_coin_envelope BYTEA,
- IN denom_sig BYTEA,
- IN now INT8,
- IN min_reserve_gc INT8,
- OUT reserve_found BOOLEAN,
- OUT balance_ok BOOLEAN,
- OUT kycok BOOLEAN,
- OUT account_uuid INT8,
- OUT ruuid INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- denom_serial INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=0;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- We optimistically insert, and then on conflict declare
--- the query successful due to idempotency.
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- idempotent query, all constraints must be satisfied
- reserve_found=TRUE;
- balance_ok=TRUE;
- kycok=TRUE;
- account_uuid=0;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
-
--- Special actions needed for a CS withdraw?
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=1; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_withdraw(BYTEA, INT8, INT4, BYTEA, BYTEA, BYTEA, BYTEA, BYTEA, INT8, INT8)
- IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result';
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
- IN amount_val INT8,
- IN amount_frac INT4,
- IN rpub BYTEA,
- IN now INT8,
- IN min_reserve_gc INT8,
- OUT reserve_found BOOLEAN,
- OUT balance_ok BOOLEAN,
- OUT kycok BOOLEAN,
- OUT account_uuid INT8,
- OUT ruuid INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- reserve_gc INT8;
-DECLARE
- reserve_val INT8;
-DECLARE
- reserve_frac INT4;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-SELECT
- current_balance_val
- ,current_balance_frac
- ,gc_date
- ,reserve_uuid
- INTO
- reserve_val
- ,reserve_frac
- ,reserve_gc
- ,ruuid
- FROM reserves
- WHERE reserves.reserve_pub=rpub;
-
-IF NOT FOUND
-THEN
- -- reserve unknown
- reserve_found=FALSE;
- balance_ok=FALSE;
- kycok=FALSE;
- account_uuid=0;
- ruuid=2;
- RETURN;
-END IF;
-
--- Check reserve balance is sufficient.
-IF (reserve_val > amount_val)
-THEN
- IF (reserve_frac >= amount_frac)
- THEN
- reserve_val=reserve_val - amount_val;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_val=reserve_val - amount_val - 1;
- reserve_frac=reserve_frac + 100000000 - amount_frac;
- END IF;
-ELSE
- IF (reserve_val = amount_val) AND (reserve_frac >= amount_frac)
- THEN
- reserve_val=0;
- reserve_frac=reserve_frac - amount_frac;
- ELSE
- reserve_found=TRUE;
- balance_ok=FALSE;
- kycok=FALSE; -- we do not really know or care
- account_uuid=0;
- RETURN;
- END IF;
-END IF;
-
--- Calculate new expiration dates.
-min_reserve_gc=GREATEST(min_reserve_gc,reserve_gc);
-
--- Update reserve balance.
-UPDATE reserves SET
- gc_date=min_reserve_gc
- ,current_balance_val=reserve_val
- ,current_balance_frac=reserve_frac
-WHERE
- reserves.reserve_pub=rpub;
-
-reserve_found=TRUE;
-balance_ok=TRUE;
-
-
--- Obtain KYC status based on the last wire transfer into
--- this reserve. FIXME: likely not adequate for reserves that got P2P transfers!
--- SELECT
--- kyc_ok
--- ,wire_target_serial_id
--- INTO
--- kycok
--- ,account_uuid
--- FROM reserves_in
--- JOIN wire_targets ON (wire_source_h_payto = wire_target_h_payto)
--- WHERE reserve_pub=rpub
--- LIMIT 1; -- limit 1 should not be required (without p2p transfers)
-
-WITH reserves_in AS materialized (
- SELECT wire_source_h_payto
- FROM reserves_in WHERE
- reserve_pub=rpub
-)
-SELECT
- kyc_ok
- ,wire_target_serial_id
-INTO
- kycok
- ,account_uuid
-FROM wire_targets
- WHERE wire_target_h_payto = (
- SELECT wire_source_h_payto
- FROM reserves_in
- );
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_batch_withdraw(INT8, INT4, BYTEA, INT8, INT8)
- IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and if so updates the database with the result. Excludes storing the planchets.';
-
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert(
- IN cs_nonce BYTEA,
- IN amount_val INT8,
- IN amount_frac INT4,
- IN h_denom_pub BYTEA,
- IN ruuid INT8,
- IN reserve_sig BYTEA,
- IN h_coin_envelope BYTEA,
- IN denom_sig BYTEA,
- IN now INT8,
- OUT out_denom_unknown BOOLEAN,
- OUT out_nonce_reuse BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- denom_serial INT8;
-BEGIN
--- Shards: reserves by reserve_pub (SELECT)
--- reserves_out (INSERT, with CONFLICT detection) by wih
--- reserves by reserve_pub (UPDATE)
--- reserves_in by reserve_pub (SELECT)
--- wire_targets by wire_target_h_payto
-
-out_denom_unknown=TRUE;
-out_conflict=TRUE;
-out_nonce_reuse=TRUE;
-
-SELECT denominations_serial
- INTO denom_serial
- FROM denominations
- WHERE denom_pub_hash=h_denom_pub;
-
-IF NOT FOUND
-THEN
- -- denomination unknown, should be impossible!
- out_denom_unknown=TRUE;
- ASSERT false, 'denomination unknown';
- RETURN;
-END IF;
-out_denom_unknown=FALSE;
-
-INSERT INTO reserves_out
- (h_blind_ev
- ,denominations_serial
- ,denom_sig
- ,reserve_uuid
- ,reserve_sig
- ,execution_date
- ,amount_with_fee_val
- ,amount_with_fee_frac)
-VALUES
- (h_coin_envelope
- ,denom_serial
- ,denom_sig
- ,ruuid
- ,reserve_sig
- ,now
- ,amount_val
- ,amount_frac)
-ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- out_conflict=TRUE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
--- Special actions needed for a CS withdraw?
-out_nonce_reuse=FALSE;
-IF NOT NULL cs_nonce
-THEN
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_nonce
- ,denom_serial
- ,h_coin_envelope)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- See if the existing entry is identical.
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_nonce
- AND op_hash=h_coin_envelope;
- IF NOT FOUND
- THEN
- out_nonce_reuse=TRUE;
- ASSERT false, 'nonce reuse attempted by client';
- RETURN;
- END IF;
- END IF;
-END IF;
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_batch_withdraw_insert(BYTEA, INT8, INT4, BYTEA, INT8, BYTEA, BYTEA, BYTEA, INT8)
- IS 'Stores information about a planchet for a batch withdraw operation. Checks if the planchet already exists, and in that case indicates a conflict';
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_withdraw_limit_check(
- IN ruuid INT8,
- IN start_time INT8,
- IN upper_limit_val INT8,
- IN upper_limit_frac INT4,
- OUT below_limit BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- total_val INT8;
-DECLARE
- total_frac INT8; -- INT4 could overflow during accumulation!
-BEGIN
--- NOTE: Read-only, but crosses shards.
--- Shards: reserves by reserve_pub
--- reserves_out by reserve_uuid -- crosses shards!!
-
-
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- total_val
- ,total_frac
- FROM reserves_out
- WHERE reserve_uuid=ruuid
- AND execution_date > start_time;
-
--- normalize result
-total_val = total_val + total_frac / 100000000;
-total_frac = total_frac % 100000000;
-
--- compare to threshold
-below_limit = (total_val < upper_limit_val) OR
- ( (total_val = upper_limit_val) AND
- (total_frac <= upper_limit_frac) );
-END $$;
-
-COMMENT ON FUNCTION exchange_do_withdraw_limit_check(INT8, INT8, INT8, INT4)
- IS 'Check whether the withdrawals from the given reserve since the given time are below the given threshold';
-
-
--- NOTE: experiment, currently dead, see postgres_Start_deferred_wire_out;
--- now done inline. FIXME: Remove code here once inline version is confirmed working nicely!
-CREATE OR REPLACE PROCEDURE defer_wire_out()
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
-IF EXISTS (
- SELECT 1
- FROM information_Schema.constraint_column_usage
- WHERE table_name='wire_out'
- AND constraint_name='wire_out_ref')
-THEN
- SET CONSTRAINTS wire_out_ref DEFERRED;
-END IF;
-
-END $$;
-
-
-CREATE OR REPLACE FUNCTION exchange_do_recoup_by_reserve(
- IN res_pub BYTEA
-)
-RETURNS TABLE
-(
- denom_sig BYTEA,
- denominations_serial BIGINT,
- coin_pub BYTEA,
- coin_sig BYTEA,
- coin_blind BYTEA,
- amount_val BIGINT,
- amount_frac INTEGER,
- recoup_timestamp BIGINT
-)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- res_uuid BIGINT;
- blind_ev BYTEA;
- c_pub BYTEA;
-BEGIN
- SELECT reserve_uuid
- INTO res_uuid
- FROM reserves
- WHERE reserves.reserve_pub = res_pub;
-
- FOR blind_ev IN
- SELECT h_blind_ev
- FROM reserves_out_by_reserve
- WHERE reserves_out_by_reserve.reserve_uuid = res_uuid
- LOOP
- SELECT robr.coin_pub
- INTO c_pub
- FROM recoup_by_reserve robr
- WHERE robr.reserve_out_serial_id = (
- SELECT reserves_out.reserve_out_serial_id
- FROM reserves_out
- WHERE reserves_out.h_blind_ev = blind_ev
- );
- RETURN QUERY
- SELECT kc.denom_sig,
- kc.denominations_serial,
- rc.coin_pub,
- rc.coin_sig,
- rc.coin_blind,
- rc.amount_val,
- rc.amount_frac,
- rc.recoup_timestamp
- FROM (
- SELECT *
- FROM known_coins
- WHERE known_coins.coin_pub = c_pub
- ) kc
- JOIN (
- SELECT *
- FROM recoup
- WHERE recoup.coin_pub = c_pub
- ) rc USING (coin_pub);
- END LOOP;
-END;
-$$;
-
-COMMENT ON FUNCTION exchange_do_recoup_by_reserve
- IS 'Recoup by reserve as a function to make sure we hit only the needed partition and not all when joining as joins on distributed tables fetch ALL rows from the shards';
-
-
-CREATE OR REPLACE FUNCTION exchange_do_deposit(
- IN in_amount_with_fee_val INT8,
- IN in_amount_with_fee_frac INT4,
- IN in_h_contract_terms BYTEA,
- IN in_wire_salt BYTEA,
- IN in_wallet_timestamp INT8,
- IN in_exchange_timestamp INT8,
- IN in_refund_deadline INT8,
- IN in_wire_deadline INT8,
- IN in_merchant_pub BYTEA,
- IN in_receiver_wire_account VARCHAR,
- IN in_h_payto BYTEA,
- IN in_known_coin_id INT8,
- IN in_coin_pub BYTEA,
- IN in_coin_sig BYTEA,
- IN in_shard INT8,
- IN in_extension_blocked BOOLEAN,
- IN in_extension_details VARCHAR,
- OUT out_exchange_timestamp INT8,
- OUT out_balance_ok BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- wtsi INT8; -- wire target serial id
-DECLARE
- xdi INT8; -- eXstension details serial id
-BEGIN
--- Shards: INSERT extension_details (by extension_details_serial_id)
--- INSERT wire_targets (by h_payto), on CONFLICT DO NOTHING;
--- INSERT deposits (by coin_pub, shard), ON CONFLICT DO NOTHING;
--- UPDATE known_coins (by coin_pub)
-
-IF NOT NULL in_extension_details
-THEN
- INSERT INTO extension_details
- (extension_options)
- VALUES
- (in_extension_details)
- RETURNING extension_details_serial_id INTO xdi;
-ELSE
- xdi=NULL;
-END IF;
-
-
-INSERT INTO wire_targets
- (wire_target_h_payto
- ,payto_uri)
- VALUES
- (in_h_payto
- ,in_receiver_wire_account)
-ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto)
- RETURNING wire_target_serial_id INTO wtsi;
-
-IF NOT FOUND
-THEN
- SELECT wire_target_serial_id
- INTO wtsi
- FROM wire_targets
- WHERE wire_target_h_payto=in_h_payto;
-END IF;
-
-
-INSERT INTO deposits
- (shard
- ,coin_pub
- ,known_coin_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,wallet_timestamp
- ,exchange_timestamp
- ,refund_deadline
- ,wire_deadline
- ,merchant_pub
- ,h_contract_terms
- ,coin_sig
- ,wire_salt
- ,wire_target_h_payto
- ,extension_blocked
- ,extension_details_serial_id
- )
- VALUES
- (in_shard
- ,in_coin_pub
- ,in_known_coin_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_wallet_timestamp
- ,in_exchange_timestamp
- ,in_refund_deadline
- ,in_wire_deadline
- ,in_merchant_pub
- ,in_h_contract_terms
- ,in_coin_sig
- ,in_wire_salt
- ,in_h_payto
- ,in_extension_blocked
- ,xdi)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and wire_target_h_payto
- -- primarily here to maximally use the existing index.
- SELECT
- exchange_timestamp
- INTO
- out_exchange_timestamp
- FROM deposits
- WHERE shard=in_shard
- AND merchant_pub=in_merchant_pub
- AND wire_target_h_payto=in_h_payto
- AND coin_pub=in_coin_pub
- AND coin_sig=in_coin_sig;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_balance_ok=TRUE;
- out_conflict=FALSE;
-
- RETURN;
-END IF;
-
-
-out_exchange_timestamp=in_exchange_timestamp;
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_conflict=FALSE;
-
-END $$;
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_melt(
- IN in_cs_rms BYTEA,
- IN in_amount_with_fee_val INT8,
- IN in_amount_with_fee_frac INT4,
- IN in_rc BYTEA,
- IN in_old_coin_pub BYTEA,
- IN in_old_coin_sig BYTEA,
- IN in_known_coin_id INT8, -- not used, but that's OK
- IN in_noreveal_index INT4,
- IN in_zombie_required BOOLEAN,
- OUT out_balance_ok BOOLEAN,
- OUT out_zombie_bad BOOLEAN,
- OUT out_noreveal_index INT4)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- denom_max INT8;
-BEGIN
--- Shards: INSERT refresh_commitments (by rc)
--- (rare:) SELECT refresh_commitments (by old_coin_pub) -- crosses shards!
--- (rare:) SEELCT refresh_revealed_coins (by melt_serial_id)
--- (rare:) PERFORM recoup_refresh (by rrc_serial) -- crosses shards!
--- UPDATE known_coins (by coin_pub)
-
-INSERT INTO refresh_commitments
- (rc
- ,old_coin_pub
- ,old_coin_sig
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,noreveal_index
- )
- VALUES
- (in_rc
- ,in_old_coin_pub
- ,in_old_coin_sig
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_noreveal_index)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- out_noreveal_index=-1;
- SELECT
- noreveal_index
- INTO
- out_noreveal_index
- FROM refresh_commitments
- WHERE rc=in_rc;
- out_balance_ok=FOUND;
- out_zombie_bad=FALSE; -- zombie is OK
- RETURN;
-END IF;
-
-
-IF in_zombie_required
-THEN
- -- Check if this coin was part of a refresh
- -- operation that was subsequently involved
- -- in a recoup operation. We begin by all
- -- refresh operations our coin was involved
- -- with, then find all associated reveal
- -- operations, and then see if any of these
- -- reveal operations was involved in a recoup.
- PERFORM
- FROM recoup_refresh
- WHERE rrc_serial IN
- (SELECT rrc_serial
- FROM refresh_revealed_coins
- WHERE melt_serial_id IN
- (SELECT melt_serial_id
- FROM refresh_commitments
- WHERE old_coin_pub=in_old_coin_pub));
- IF NOT FOUND
- THEN
- out_zombie_bad=TRUE;
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_zombie_bad=FALSE; -- zombie is OK
-
-
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_noreveal_index=-1;
- out_balance_ok=FALSE;
- RETURN;
-END IF;
-
-
-
--- Special actions needed for a CS melt?
-IF NOT NULL in_cs_rms
-THEN
- -- Get maximum denominations serial value in
- -- existence, this will determine how long the
- -- nonce will be locked.
- SELECT
- denominations_serial
- INTO
- denom_max
- FROM denominations
- ORDER BY denominations_serial DESC
- LIMIT 1;
-
- -- Cache CS signature to prevent replays in the future
- -- (and check if cached signature exists at the same time).
- INSERT INTO cs_nonce_locks
- (nonce
- ,max_denomination_serial
- ,op_hash)
- VALUES
- (cs_rms
- ,denom_serial
- ,in_rc)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- -- Record exists, make sure it is the same
- SELECT 1
- FROM cs_nonce_locks
- WHERE nonce=cs_rms
- AND op_hash=in_rc;
-
- IF NOT FOUND
- THEN
- -- Nonce reuse detected
- out_balance_ok=FALSE;
- out_zombie_bad=FALSE;
- out_noreveal_index=42; -- FIXME: return error message more nicely!
- ASSERT false, 'nonce reuse attempted by client';
- END IF;
- END IF;
-END IF;
-
--- Everything fine, return success!
-out_balance_ok=TRUE;
-out_noreveal_index=in_noreveal_index;
-
-END $$;
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_refund(
- IN in_amount_with_fee_val INT8,
- IN in_amount_with_fee_frac INT4,
- IN in_amount_val INT8,
- IN in_amount_frac INT4,
- IN in_deposit_fee_val INT8,
- IN in_deposit_fee_frac INT4,
- IN in_h_contract_terms BYTEA,
- IN in_rtransaction_id INT8,
- IN in_deposit_shard INT8,
- IN in_known_coin_id INT8,
- IN in_coin_pub BYTEA,
- IN in_merchant_pub BYTEA,
- IN in_merchant_sig BYTEA,
- OUT out_not_found BOOLEAN,
- OUT out_refund_ok BOOLEAN,
- OUT out_gone BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- dsi INT8; -- ID of deposit being refunded
-DECLARE
- tmp_val INT8; -- total amount refunded
-DECLARE
- tmp_frac INT8; -- total amount refunded
-DECLARE
- deposit_val INT8; -- amount that was originally deposited
-DECLARE
- deposit_frac INT8; -- amount that was originally deposited
-BEGIN
--- Shards: SELECT deposits (coin_pub, shard, h_contract_terms, merchant_pub)
--- INSERT refunds (by coin_pub, rtransaction_id) ON CONFLICT DO NOTHING
--- SELECT refunds (by coin_pub)
--- UPDATE known_coins (by coin_pub)
-
-SELECT
- deposit_serial_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,done
-INTO
- dsi
- ,deposit_val
- ,deposit_frac
- ,out_gone
-FROM deposits
- WHERE coin_pub=in_coin_pub
- AND shard=in_deposit_shard
- AND merchant_pub=in_merchant_pub
- AND h_contract_terms=in_h_contract_terms;
-
-IF NOT FOUND
-THEN
- -- No matching deposit found!
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=TRUE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-INSERT INTO refunds
- (deposit_serial_id
- ,coin_pub
- ,merchant_sig
- ,rtransaction_id
- ,amount_with_fee_val
- ,amount_with_fee_frac
- )
- VALUES
- (dsi
- ,in_coin_pub
- ,in_merchant_sig
- ,in_rtransaction_id
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'coin_sig', we implicitly check
- -- identity over everything that the signature covers.
- -- We do select over merchant_pub and h_contract_terms
- -- primarily here to maximally use the existing index.
- PERFORM
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi
- AND rtransaction_id=in_rtransaction_id
- AND amount_with_fee_val=in_amount_with_fee_val
- AND amount_with_fee_frac=in_amount_with_fee_frac;
-
- IF NOT FOUND
- THEN
- -- Deposit exists, but have conflicting refund.
- out_refund_ok=FALSE;
- out_conflict=TRUE;
- out_not_found=FALSE;
- RETURN;
- END IF;
-
- -- Idempotent request known, return success.
- out_refund_ok=TRUE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- out_gone=FALSE;
- RETURN;
-END IF;
-
-IF out_gone
-THEN
- -- money already sent to the merchant. Tough luck.
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Check refund balance invariant.
-SELECT
- SUM(amount_with_fee_val) -- overflow here is not plausible
- ,SUM(CAST(amount_with_fee_frac AS INT8)) -- compute using 64 bits
- INTO
- tmp_val
- ,tmp_frac
- FROM refunds
- WHERE coin_pub=in_coin_pub
- AND deposit_serial_id=dsi;
-IF tmp_val IS NULL
-THEN
- RAISE NOTICE 'failed to sum up existing refunds';
- out_refund_ok=FALSE;
- out_conflict=FALSE;
- out_not_found=FALSE;
- RETURN;
-END IF;
-
--- Normalize result before continuing
-tmp_val = tmp_val + tmp_frac / 100000000;
-tmp_frac = tmp_frac % 100000000;
-
--- Actually check if the deposits are sufficient for the refund. Verbosely. ;-)
-IF (tmp_val < deposit_val)
-THEN
- out_refund_ok=TRUE;
-ELSE
- IF (tmp_val = deposit_val) AND (tmp_frac <= deposit_frac)
- THEN
- out_refund_ok=TRUE;
- ELSE
- out_refund_ok=FALSE;
- END IF;
-END IF;
-
-IF (tmp_val = deposit_val) AND (tmp_frac = deposit_frac)
-THEN
- -- Refunds have reached the full value of the original
- -- deposit. Also refund the deposit fee.
- in_amount_frac = in_amount_frac + in_deposit_fee_frac;
- in_amount_val = in_amount_val + in_deposit_fee_val;
-
- -- Normalize result before continuing
- in_amount_val = in_amount_val + in_amount_frac / 100000000;
- in_amount_frac = in_amount_frac % 100000000;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+in_amount_frac
- - CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+in_amount_val
- + CASE
- WHEN remaining_frac+in_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub;
-
-
-out_conflict=FALSE;
-out_not_found=FALSE;
-
-END $$;
-
--- COMMENT ON FUNCTION exchange_do_refund(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
--- IS 'Executes a refund operation, checking that the corresponding deposit was sufficient to cover the refunded amount';
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_recoup_to_reserve(
- IN in_reserve_pub BYTEA,
- IN in_reserve_out_serial_id INT8,
- IN in_coin_blind BYTEA,
- IN in_coin_pub BYTEA,
- IN in_known_coin_id INT8,
- IN in_coin_sig BYTEA,
- IN in_reserve_gc INT8,
- IN in_reserve_expiration INT8,
- IN in_recoup_timestamp INT8,
- OUT out_recoup_ok BOOLEAN,
- OUT out_internal_failure BOOLEAN,
- OUT out_recoup_timestamp INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
--- Shards: SELECT known_coins (by coin_pub)
--- SELECT recoup (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- UPDATE reserves (by reserve_pub)
--- INSERT recoup (by coin_pub)
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup
- WHERE coin_pub=in_coin_pub;
-
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the reserve and update reserve timers.
-UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+tmp_frac
- - CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+tmp_val
- + CASE
- WHEN current_balance_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END,
- gc_date=GREATEST(gc_date, in_reserve_gc),
- expiration_date=GREATEST(expiration_date, in_reserve_expiration)
- WHERE reserve_pub=in_reserve_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase reserve balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup
- (coin_pub
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,reserve_out_serial_id
- )
-VALUES
- (in_coin_pub
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_reserve_out_serial_id);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
--- COMMENT ON FUNCTION exchange_do_recoup_to_reserve(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
--- IS 'Executes a recoup of a coin that was withdrawn from a reserve';
-
-
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
- IN in_old_coin_pub BYTEA,
- IN in_rrc_serial INT8,
- IN in_coin_blind BYTEA,
- IN in_coin_pub BYTEA,
- IN in_known_coin_id INT8,
- IN in_coin_sig BYTEA,
- IN in_recoup_timestamp INT8,
- OUT out_recoup_ok BOOLEAN,
- OUT out_internal_failure BOOLEAN,
- OUT out_recoup_timestamp INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- tmp_val INT8; -- amount recouped
-DECLARE
- tmp_frac INT8; -- amount recouped
-BEGIN
-
--- Shards: UPDATE known_coins (by coin_pub)
--- SELECT recoup_refresh (by coin_pub)
--- UPDATE known_coins (by coin_pub)
--- INSERT recoup_refresh (by coin_pub)
-
-
-out_internal_failure=FALSE;
-
-
--- Check remaining balance of the coin.
-SELECT
- remaining_frac
- ,remaining_val
- INTO
- tmp_frac
- ,tmp_val
-FROM known_coins
- WHERE coin_pub=in_coin_pub;
-
-IF NOT FOUND
-THEN
- out_internal_failure=TRUE;
- out_recoup_ok=FALSE;
- RETURN;
-END IF;
-
-IF tmp_val + tmp_frac = 0
-THEN
- -- Check for idempotency
- SELECT
- recoup_timestamp
- INTO
- out_recoup_timestamp
- FROM recoup_refresh
- WHERE coin_pub=in_coin_pub;
- out_recoup_ok=FOUND;
- RETURN;
-END IF;
-
--- Update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=0
- ,remaining_val=0
- WHERE coin_pub=in_coin_pub;
-
-
--- Credit the old coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac+tmp_frac
- - CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+tmp_val
- + CASE
- WHEN remaining_frac+tmp_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_old_coin_pub;
-
-
-IF NOT FOUND
-THEN
- RAISE NOTICE 'failed to increase old coin balance from recoup';
- out_recoup_ok=TRUE;
- out_internal_failure=TRUE;
- RETURN;
-END IF;
-
-
-INSERT INTO recoup_refresh
- (coin_pub
- ,known_coin_id
- ,coin_sig
- ,coin_blind
- ,amount_val
- ,amount_frac
- ,recoup_timestamp
- ,rrc_serial
- )
-VALUES
- (in_coin_pub
- ,in_known_coin_id
- ,in_coin_sig
- ,in_coin_blind
- ,tmp_val
- ,tmp_frac
- ,in_recoup_timestamp
- ,in_rrc_serial);
-
--- Normal end, everything is fine.
-out_recoup_ok=TRUE;
-out_recoup_timestamp=in_recoup_timestamp;
-
-END $$;
-
-
--- COMMENT ON FUNCTION exchange_do_recoup_to_coin(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
--- IS 'Executes a recoup-refresh of a coin that was obtained from a refresh-reveal process';
-
-
-
-CREATE OR REPLACE PROCEDURE exchange_do_gc(
- IN in_ancient_date INT8,
- IN in_now INT8)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- reserve_uuid_min INT8; -- minimum reserve UUID still alive
-DECLARE
- melt_min INT8; -- minimum melt still alive
-DECLARE
- coin_min INT8; -- minimum known_coin still alive
-DECLARE
- deposit_min INT8; -- minimum deposit still alive
-DECLARE
- reserve_out_min INT8; -- minimum reserve_out still alive
-DECLARE
- denom_min INT8; -- minimum denomination still alive
-BEGIN
-
-DELETE FROM prewire
- WHERE finished=TRUE;
-
-DELETE FROM wire_fee
- WHERE end_date < in_ancient_date;
-
--- TODO: use closing fee as threshold?
-DELETE FROM reserves
- WHERE gc_date < in_now
- AND current_balance_val = 0
- AND current_balance_frac = 0;
-
-SELECT
- reserve_out_serial_id
- INTO
- reserve_out_min
- FROM reserves_out
- ORDER BY reserve_out_serial_id ASC
- LIMIT 1;
-
-DELETE FROM recoup
- WHERE reserve_out_serial_id < reserve_out_min;
--- FIXME: recoup_refresh lacks GC!
-
-SELECT
- reserve_uuid
- INTO
- reserve_uuid_min
- FROM reserves
- ORDER BY reserve_uuid ASC
- LIMIT 1;
-
-DELETE FROM reserves_out
- WHERE reserve_uuid < reserve_uuid_min;
-
--- FIXME: this query will be horribly slow;
--- need to find another way to formulate it...
-DELETE FROM denominations
- WHERE expire_legal < in_now
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM reserves_out)
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup))
- AND denominations_serial NOT IN
- (SELECT DISTINCT denominations_serial
- FROM known_coins
- WHERE coin_pub IN
- (SELECT DISTINCT coin_pub
- FROM recoup_refresh));
-
-SELECT
- melt_serial_id
- INTO
- melt_min
- FROM refresh_commitments
- ORDER BY melt_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refresh_revealed_coins
- WHERE melt_serial_id < melt_min;
-
-DELETE FROM refresh_transfer_keys
- WHERE melt_serial_id < melt_min;
-
-SELECT
- known_coin_id
- INTO
- coin_min
- FROM known_coins
- ORDER BY known_coin_id ASC
- LIMIT 1;
-
-DELETE FROM deposits
- WHERE known_coin_id < coin_min;
-
-SELECT
- deposit_serial_id
- INTO
- deposit_min
- FROM deposits
- ORDER BY deposit_serial_id ASC
- LIMIT 1;
-
-DELETE FROM refunds
- WHERE deposit_serial_id < deposit_min;
-
-DELETE FROM aggregation_tracking
- WHERE deposit_serial_id < deposit_min;
-
-SELECT
- denominations_serial
- INTO
- denom_min
- FROM denominations
- ORDER BY denominations_serial ASC
- LIMIT 1;
-
-DELETE FROM cs_nonce_locks
- WHERE max_denomination_serial <= denom_min;
-
-END $$;
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_purse_deposit(
- IN in_partner_id INT8,
- IN in_purse_pub BYTEA,
- IN in_amount_with_fee_val INT8,
- IN in_amount_with_fee_frac INT4,
- IN in_coin_pub BYTEA,
- IN in_coin_sig BYTEA,
- IN in_amount_without_fee_val INT8,
- IN in_amount_without_fee_frac INT4,
- OUT out_balance_ok BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- was_merged BOOLEAN;
-DECLARE
- psi INT8; -- partner's serial ID (set if merged)
-DECLARE
- my_amount_val INT8; -- total in purse
-DECLARE
- my_amount_frac INT4; -- total in purse
-DECLARE
- was_paid BOOLEAN;
-DECLARE
- my_reserve_pub BYTEA;
-BEGIN
-
--- Store the deposit request.
-INSERT INTO purse_deposits
- (partner_serial_id
- ,purse_pub
- ,coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- ,coin_sig)
- VALUES
- (in_partner_id
- ,in_purse_pub
- ,in_coin_pub
- ,in_amount_with_fee_val
- ,in_amount_with_fee_frac
- ,in_coin_sig)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: check if coin_sig is the same,
- -- if so, success, otherwise conflict!
- PERFORM
- FROM purse_deposits
- WHERE coin_pub = in_coin_pub
- AND purse_pub = in_purse_pub
- AND coin_sig = in_cion_sig;
- IF NOT FOUND
- THEN
- -- Deposit exists, but with differences. Not allowed.
- out_balance_ok=FALSE;
- out_conflict=TRUE;
- RETURN;
- END IF;
-END IF;
-
-
--- Debit the coin
--- Check and update balance of the coin.
-UPDATE known_coins
- SET
- remaining_frac=remaining_frac-in_amount_with_fee_frac
- + CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val-in_amount_with_fee_val
- - CASE
- WHEN remaining_frac < in_amount_with_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE coin_pub=in_coin_pub
- AND ( (remaining_val > in_amount_with_fee_val) OR
- ( (remaining_frac >= in_amount_with_fee_frac) AND
- (remaining_val >= in_amount_with_fee_val) ) );
-
-IF NOT FOUND
-THEN
- -- Insufficient balance.
- out_balance_ok=FALSE;
- out_conflict=FALSE;
- RETURN;
-END IF;
-
-
--- Credit the purse.
-UPDATE purse_requests
- SET
- balance_frac=balance_frac+in_amount_without_fee_frac
- - CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- balance_val=balance_val+in_amount_without_fee_val
- + CASE
- WHEN balance_frac+in_amount_without_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE purse_pub=in_purse_pub;
-
-out_conflict=FALSE;
-out_balance_ok=TRUE;
-
--- See if we can finish the merge or need to update the trigger time and partner.
-SELECT partner_serial_id
- ,reserve_pub
- INTO psi
- ,my_reserve_pub
- FROM purse_merges
- WHERE purse_pub=in_purse_pub;
-
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-SELECT
- amount_with_fee_val
- ,amount_with_fee_frac
- INTO
- my_amount_val
- ,my_amount_frac
- FROM purse_requests
- WHERE (purse_pub=in_purse_pub)
- AND ( ( ( (amount_with_fee_val <= balance_val)
- AND (amount_with_fee_frac <= balance_frac) )
- OR (amount_with_fee_val < balance_val) ) );
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-IF (0 != psi)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=psi
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update balance immediately.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=my_reserve_pub;
-
- -- ... and mark purse as finished.
- -- FIXME: combine with UPDATE above?
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-END $$;
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_purse_merge(
- IN in_purse_pub BYTEA,
- IN in_merge_sig BYTEA,
- IN in_merge_timestamp INT8,
- IN in_reserve_sig BYTEA,
- IN in_partner_url VARCHAR,
- IN in_reserve_pub BYTEA,
- IN in_require_kyc BOOLEAN,
- OUT out_no_partner BOOLEAN,
- OUT out_no_balance BOOLEAN,
- OUT out_no_kyc BOOLEAN,
- OUT out_no_reserve BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- my_amount_val INT8;
-DECLARE
- my_amount_frac INT4;
-DECLARE
- my_purse_fee_val INT8;
-DECLARE
- my_purse_fee_frac INT4;
-DECLARE
- my_partner_serial_id INT8;
-DECLARE
- my_finished BOOLEAN;
-BEGIN
-
-IF in_partner_url IS NULL
-THEN
- my_partner_serial_id=0;
-ELSE
- SELECT
- partner_serial_id
- INTO
- my_partner_serial_id
- FROM partners
- WHERE partner_base_url=in_partner_url
- AND start_date <= in_merge_timestamp
- AND end_date > in_merge_timestamp;
- IF NOT FOUND
- THEN
- out_no_partner=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-END IF;
-
-out_no_partner=FALSE;
-
-
--- Check purse is 'full'.
-SELECT amount_with_fee_val
- ,amount_with_fee_frac
- ,purse_fee_val
- ,purse_fee_frac
- ,finished
- INTO my_amount_val
- ,my_amount_frac
- ,my_purse_fee_val
- ,my_purse_fee_frac
- ,my_finished
- FROM purse_requests
- WHERE purse_pub=in_purse_pub
- AND balance_val >= amount_with_fee_val
- AND ( (balance_frac >= amount_with_fee_frac) OR
- (balance_val > amount_with_fee_val) );
-IF NOT FOUND
-THEN
- out_no_balance=TRUE;
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_no_balance=FALSE;
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (my_partner_serial_id
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-ASSERT NOT my_finished, 'internal invariant failed';
-
-IF ( (in_partner_url IS NULL) AND
- (in_require_kyc) )
-THEN
- -- Need to do KYC check.
- SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
- IF NOT FOUND
- THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- RETURN;
- END IF;
- out_no_reserve=FALSE;
-
- IF (out_no_kyc)
- THEN
- RETURN;
- END IF;
-ELSE
- -- KYC is not our responsibility
- out_no_reserve=FALSE;
- out_no_kyc=FALSE;
-END IF;
-
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
--- If we need a wad transfer, mark purse ready for it.
-IF (0 != my_partner_serial_id)
-THEN
- -- The taler-exchange-router will take care of this.
- UPDATE purse_actions
- SET action_date=0 --- "immediately"
- ,partner_serial_id=my_partner_serial_id
- WHERE purse_pub=in_purse_pub;
-ELSE
- -- This is a local reserve, update reserve balance immediately.
-
- -- Refund the purse fee, by adding it to the purse value:
- my_amount_val = my_amount_val + my_purse_fee_val;
- my_amount_frac = my_amount_frac + my_purse_fee_frac;
- -- normalize result
- my_amount_val = my_amount_val + my_amount_frac / 100000000;
- my_amount_frac = my_amount_frac % 100000000;
-
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac+my_amount_frac
- - CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val+my_amount_val
- + CASE
- WHEN current_balance_frac + my_amount_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE reserve_pub=in_reserve_pub;
-
- -- ... and mark purse as finished.
- UPDATE purse_requests
- SET finished=true
- WHERE purse_pub=in_purse_pub;
-END IF;
-
-
-RETURN;
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, VARCHAR, BYTEA, BOOLEAN)
- IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.';
-
-
-CREATE OR REPLACE FUNCTION exchange_do_reserve_purse(
- IN in_purse_pub BYTEA,
- IN in_merge_sig BYTEA,
- IN in_merge_timestamp INT8,
- IN in_reserve_sig BYTEA,
- IN in_reserve_quota BOOLEAN,
- IN in_purse_fee_val INT8,
- IN in_purse_fee_frac INT4,
- IN in_reserve_pub BYTEA,
- IN in_require_kyc BOOLEAN,
- OUT out_no_funds BOOLEAN,
- OUT out_no_kyc BOOLEAN,
- OUT out_no_reserve BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
--- Store purse merge signature, checks for purse_pub uniqueness
-INSERT INTO purse_merges
- (partner_serial_id
- ,reserve_pub
- ,purse_pub
- ,merge_sig
- ,merge_timestamp)
- VALUES
- (0
- ,in_reserve_pub
- ,in_purse_pub
- ,in_merge_sig
- ,in_merge_timestamp)
- ON CONFLICT DO NOTHING;
-
-IF NOT FOUND
-THEN
- -- Idempotency check: see if an identical record exists.
- -- Note that by checking 'merge_sig', we implicitly check
- -- identity over everything that the signature covers.
- PERFORM
- FROM purse_merges
- WHERE purse_pub=in_purse_pub
- AND merge_sig=in_merge_sig;
- IF NOT FOUND
- THEN
- -- Purse was merged, but to some other reserve. Not allowed.
- out_conflict=TRUE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- out_no_funds=FALSE;
- RETURN;
- END IF;
-
- -- "success"
- out_conflict=FALSE;
- out_no_funds=FALSE;
- out_no_kyc=FALSE;
- out_no_reserve=FALSE;
- RETURN;
-END IF;
-out_conflict=FALSE;
-
-SELECT NOT kyc_passed
- INTO out_no_kyc
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
-IF NOT FOUND
-THEN
- out_no_kyc=TRUE;
- out_no_reserve=TRUE;
- out_no_funds=TRUE;
- RETURN;
-END IF;
-out_no_reserve=FALSE;
-
-IF (out_no_kyc AND in_require_kyc)
-THEN
- out_no_funds=FALSE;
- RETURN;
-END IF;
-
-IF (in_reserve_quota)
-THEN
- -- Increment active purses per reserve (and check this is allowed)
- UPDATE reserves
- SET purses_active=purses_active+1
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND purses_active < purses_allowed;
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-ELSE
- -- UPDATE reserves balance (and check if balance is enough to pay the fee)
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_purse_fee_frac
- + CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_purse_fee_val
- - CASE
- WHEN current_balance_frac < in_purse_fee_frac
- THEN 1
- ELSE 0
- END
- ,kyc_required=TRUE
- WHERE reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_purse_fee_val) OR
- ( (current_balance_frac >= in_purse_fee_frac) AND
- (current_balance_val >= in_purse_fee_val) ) );
- IF NOT FOUND
- THEN
- out_no_funds=TRUE;
- RETURN;
- END IF;
-END IF;
-
-out_no_funds=FALSE;
-
-
--- Store account merge signature.
-INSERT INTO account_merges
- (reserve_pub
- ,reserve_sig
- ,purse_pub)
- VALUES
- (in_reserve_pub
- ,in_reserve_sig
- ,in_purse_pub);
-
-END $$;
-
-COMMENT ON FUNCTION exchange_do_reserve_purse(BYTEA, BYTEA, INT8, BYTEA, BOOLEAN, INT8, INT4, BYTEA, BOOLEAN)
- IS 'Create a purse for a reserve.';
-
-
-
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_account_merge(
- IN in_purse_pub BYTEA,
- IN in_reserve_pub BYTEA,
- IN in_reserve_sig BYTEA,
- OUT out_balance_ok BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-BEGIN
- -- FIXME: function/API is dead! Do DCE?
-END $$;
-
-
-
-CREATE OR REPLACE FUNCTION exchange_do_expire_purse(
- IN in_start_time INT8,
- IN in_end_time INT8,
- OUT out_found BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-DECLARE
- my_purse_pub BYTEA;
-DECLARE
- my_deposit record;
-BEGIN
-
-SELECT purse_pub
- INTO my_purse_pub
- FROM purse_requests
- WHERE (purse_expiration >= in_start_time) AND
- (purse_expiration < in_end_time) AND
- (NOT finished) AND
- (NOT refunded)
- ORDER BY purse_expiration ASC
- LIMIT 1;
-out_found = FOUND;
-IF NOT FOUND
-THEN
- RETURN;
-END IF;
-
-UPDATE purse_requests
- SET refunded=TRUE,
- finished=TRUE
- WHERE purse_pub=my_purse_pub;
-
-INSERT INTO purse_refunds
- (purse_pub)
- VALUES
- (my_purse_pub);
-
--- restore balance to each coin deposited into the purse
-FOR my_deposit IN
- SELECT coin_pub
- ,amount_with_fee_val
- ,amount_with_fee_frac
- FROM purse_deposits
- WHERE purse_pub = my_purse_pub
-LOOP
- UPDATE known_coins SET
- remaining_frac=remaining_frac+my_deposit.amount_with_fee_frac
- - CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 100000000
- ELSE 0
- END,
- remaining_val=remaining_val+my_deposit.amount_with_fee_val
- + CASE
- WHEN remaining_frac+my_deposit.amount_with_fee_frac >= 100000000
- THEN 1
- ELSE 0
- END
- WHERE coin_pub = my_deposit.coin_pub;
- END LOOP;
-END $$;
-
-COMMENT ON FUNCTION exchange_do_expire_purse(INT8,INT8)
- IS 'Finds an expired purse in the given time range and refunds the coins (if any).';
-
-
-CREATE OR REPLACE FUNCTION exchange_do_history_request(
- IN in_reserve_pub BYTEA,
- IN in_reserve_sig BYTEA,
- IN in_request_timestamp INT8,
- IN in_history_fee_val INT8,
- IN in_history_fee_frac INT4,
- OUT out_balance_ok BOOLEAN,
- OUT out_idempotent BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- -- Insert and check for idempotency.
- INSERT INTO history_requests
- (reserve_pub
- ,request_timestamp
- ,reserve_sig
- ,history_fee_val
- ,history_fee_frac)
- VALUES
- (in_reserve_pub
- ,in_request_timestamp
- ,in_reserve_sig
- ,in_history_fee_val
- ,in_history_fee_frac)
- ON CONFLICT DO NOTHING;
-
- IF NOT FOUND
- THEN
- out_balance_ok=TRUE;
- out_idempotent=TRUE;
- RETURN;
- END IF;
-
- out_idempotent=FALSE;
-
- -- Update reserve balance.
- UPDATE reserves
- SET
- current_balance_frac=current_balance_frac-in_history_fee_frac
- + CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 100000000
- ELSE 0
- END,
- current_balance_val=current_balance_val-in_history_fee_val
- - CASE
- WHEN current_balance_frac < in_history_fee_frac
- THEN 1
- ELSE 0
- END
- WHERE
- reserve_pub=in_reserve_pub
- AND ( (current_balance_val > in_history_fee_val) OR
- ( (current_balance_frac >= in_history_fee_frac) AND
- (current_balance_val >= in_history_fee_val) ) );
-
- IF NOT FOUND
- THEN
- -- Either reserve does not exist, or balance insufficient.
- -- Both we treat the same here as balance insufficient.
- out_balance_ok=FALSE;
- RETURN;
- END IF;
-
- out_balance_ok=TRUE;
-END $$;
-
-
-CREATE OR REPLACE FUNCTION exchange_do_close_request(
- IN in_reserve_pub BYTEA,
- IN in_close_timestamp INT8,
- IN in_reserve_sig BYTEA,
- OUT out_final_balance_val INT8,
- OUT out_final_balance_frac INT4,
- OUT out_balance_ok BOOLEAN,
- OUT out_conflict BOOLEAN)
-LANGUAGE plpgsql
-AS $$
-BEGIN
-
- SELECT
- current_balance_val
- ,current_balance_frac
- INTO
- out_final_balance_val
- ,out_final_balance_frac
- FROM reserves
- WHERE reserve_pub=in_reserve_pub;
-
- IF NOT FOUND
- THEN
- out_final_balance_val=0;
- out_final_balance_frac=0;
- out_balance_ok = FALSE;
- out_conflict = FALSE;
- END IF;
-
- INSERT INTO close_requests
- (reserve_pub
- ,close_timestamp
- ,reserve_sig
- ,close_val
- ,close_frac)
- VALUES
- (in_reserve_pub
- ,in_close_timestamp
- ,in_reserve_sig
- ,out_final_balance_val
- ,out_final_balance_frac)
- ON CONFLICT DO NOTHING;
- out_conflict = NOT FOUND;
-
- UPDATE reserves SET
- current_balance_val=0
- ,current_balance_frac=0
- WHERE reserve_pub=in_reserve_pub;
- out_balance_ok = TRUE;
-
-END $$;
-
-
--------------------------------------------------------------
--- THE END
--------------------------------------------------------------
-
--- Complete transaction
-COMMIT;
diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql
new file mode 100644
index 000000000..a4b1c8b9f
--- /dev/null
+++ b/src/exchangedb/exchange-0001.sql
@@ -0,0 +1,296 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0001', NULL, NULL);
+
+CREATE SCHEMA exchange;
+COMMENT ON SCHEMA exchange IS 'taler-exchange data';
+
+SET search_path TO exchange;
+
+---------------------------------------------------------------------------
+-- General procedures for DB setup
+---------------------------------------------------------------------------
+
+CREATE TABLE exchange_tables
+ (table_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY
+ ,name TEXT NOT NULL
+ ,version TEXT NOT NULL
+ ,action TEXT NOT NULL
+ ,partitioned BOOL NOT NULL
+ ,by_range BOOL NOT NULL
+ ,finished BOOL NOT NULL DEFAULT(FALSE));
+COMMENT ON TABLE exchange_tables
+ IS 'Tables of the exchange and their status';
+COMMENT ON COLUMN exchange_tables.name
+ IS 'Base name of the table (without partition/shard)';
+COMMENT ON COLUMN exchange_tables.version
+ IS 'Version of the DB in which the given action happened';
+COMMENT ON COLUMN exchange_tables.action
+ IS 'Action to take on the table (e.g. create, constrain, or foreign). Create is done for the master table and each partition; constrain is only for partitions or for master if there are no partitions; master only on master (takes no argument); foreign only on master if there are no partitions.';
+COMMENT ON COLUMN exchange_tables.partitioned
+ IS 'TRUE if the table is partitioned';
+COMMENT ON COLUMN exchange_tables.by_range
+ IS 'TRUE if the table is partitioned by range';
+COMMENT ON COLUMN exchange_tables.finished
+ IS 'TRUE if the respective migration has been run';
+
+
+CREATE FUNCTION create_partitioned_table(
+ IN table_definition TEXT -- SQL template for table creation
+ ,IN table_name TEXT -- base name of the table
+ ,IN main_table_partition_str TEXT -- declaration for how to partition the table
+ ,IN partition_suffix TEXT DEFAULT NULL -- NULL: no partitioning, 0: yes partitioning, no sharding, >0: sharding
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF (partition_suffix IS NULL)
+ THEN
+ -- no partitioning, disable option
+ main_table_partition_str = '';
+ ELSE
+ IF (partition_suffix::int > 0)
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ END IF;
+ EXECUTE FORMAT(
+ table_definition,
+ table_name,
+ main_table_partition_str
+ );
+END $$;
+
+COMMENT ON FUNCTION create_partitioned_table
+ IS 'Generic function to create a table that is partitioned or sharded.';
+
+
+CREATE FUNCTION comment_partitioned_table(
+ IN table_comment TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON TABLE %s IS %s'
+ ,table_name
+ ,quote_literal(table_comment)
+ );
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_table
+ IS 'Generic function to create a comment on table that is partitioned.';
+
+
+CREATE FUNCTION comment_partitioned_column(
+ IN table_comment TEXT
+ ,IN column_name TEXT
+ ,IN table_name TEXT
+ ,IN partition_suffix TEXT DEFAULT NULL
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ IF ( (partition_suffix IS NOT NULL) AND
+ (partition_suffix::int > 0) )
+ THEN
+ -- sharding, add shard name
+ table_name=table_name || '_' || partition_suffix;
+ END IF;
+ EXECUTE FORMAT(
+ 'COMMENT ON COLUMN %s.%s IS %s'
+ ,table_name
+ ,column_name
+ ,quote_literal(table_comment)
+ );
+END $$;
+
+COMMENT ON FUNCTION comment_partitioned_column
+ IS 'Generic function to create a comment on column of a table that is partitioned.';
+
+
+---------------------------------------------------------------------------
+-- Main DB setup loop
+---------------------------------------------------------------------------
+
+CREATE FUNCTION do_create_tables(
+ num_partitions INTEGER
+-- NULL: no partitions, add foreign constraints
+-- 0: no partitions, no foreign constraints
+-- 1: only 1 default partition
+-- > 1: normal partitions
+)
+ RETURNS VOID
+ LANGUAGE plpgsql
+AS $$
+DECLARE
+ tc CURSOR FOR
+ SELECT table_serial_id
+ ,name
+ ,action
+ ,partitioned
+ ,by_range
+ FROM exchange.exchange_tables
+ WHERE NOT finished
+ ORDER BY table_serial_id ASC;
+BEGIN
+ FOR rec IN tc
+ LOOP
+ CASE rec.action
+ -- "create" actions apply to master and partitions
+ WHEN 'create'
+ THEN
+ IF (rec.partitioned AND
+ (num_partitions IS NOT NULL))
+ THEN
+ -- Create master table with partitioning.
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('0')
+ );
+ IF (rec.by_range OR
+ (num_partitions = 0))
+ THEN
+ -- Create default partition.
+ IF (rec.by_range)
+ THEN
+ -- Range partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE exchange.%s_default'
+ ' PARTITION OF %s'
+ ' DEFAULT'
+ ,rec.name
+ ,rec.name
+ );
+ ELSE
+ -- Hash partition
+ EXECUTE FORMAT(
+ 'CREATE TABLE exchange.%s_default'
+ ' PARTITION OF %s'
+ ' FOR VALUES WITH (MODULUS 1, REMAINDER 0)'
+ ,rec.name
+ ,rec.name
+ );
+ END IF;
+ ELSE
+ FOR i IN 1..num_partitions LOOP
+ -- Create num_partitions
+ EXECUTE FORMAT(
+ 'CREATE TABLE exchange.%I'
+ ' PARTITION OF %I'
+ ' FOR VALUES WITH (MODULUS %s, REMAINDER %s)'
+ ,rec.name || '_' || i
+ ,rec.name
+ ,num_partitions
+ ,i-1
+ );
+ END LOOP;
+ END IF;
+ ELSE
+ -- Only create master table. No partitions.
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ END IF;
+ -- Constrain action apply to master OR each partition
+ WHEN 'constrain'
+ THEN
+ ASSERT rec.partitioned, 'constrain action only applies to partitioned tables';
+ IF (num_partitions IS NULL)
+ THEN
+ -- Constrain master table
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s (NULL)'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ IF ( (num_partitions = 0) OR
+ (rec.by_range) )
+ THEN
+ -- Constrain default table
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal('default')
+ );
+ ELSE
+ -- Constrain each partition
+ FOR i IN 1..num_partitions LOOP
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,quote_literal(i)
+ );
+ END LOOP;
+ END IF;
+ END IF;
+ -- Foreign actions only apply if partitioning is off
+ WHEN 'foreign'
+ THEN
+ IF (num_partitions IS NULL)
+ THEN
+ -- Add foreign constraints
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s (%s)'::text
+ ,rec.action
+ ,rec.name
+ ,NULL
+ );
+ END IF;
+ WHEN 'master'
+ THEN
+ EXECUTE FORMAT(
+ 'SELECT exchange.%s_table_%s ()'::text
+ ,rec.action
+ ,rec.name
+ );
+ ELSE
+ ASSERT FALSE, 'unsupported action type: ' || rec.action;
+ END CASE; -- END CASE (rec.action)
+ -- Mark as finished
+ UPDATE exchange.exchange_tables
+ SET finished=TRUE
+ WHERE table_serial_id=rec.table_serial_id;
+ END LOOP; -- create/alter/drop actions
+END $$;
+
+COMMENT ON FUNCTION do_create_tables
+ IS 'Creates all tables for the given number of partitions that need creating. Does NOT support sharding.';
+
+
+COMMIT;
diff --git a/src/exchangedb/exchange-0002.sql.in b/src/exchangedb/exchange-0002.sql.in
new file mode 100644
index 000000000..ab13b28af
--- /dev/null
+++ b/src/exchangedb/exchange-0002.sql.in
@@ -0,0 +1,118 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0002', NULL, NULL);
+SET search_path TO exchange;
+
+CREATE DOMAIN gnunet_hashcode
+ AS BYTEA
+ CHECK(LENGTH(VALUE) = 32);
+
+CREATE TYPE taler_amount
+ AS
+ (val INT8
+ ,frac INT4
+ );
+COMMENT ON TYPE taler_amount
+ IS 'Stores an amount, fraction is in units of 1/100000000 of the base value';
+
+CREATE TYPE exchange_do_array_reserve_insert_return_type
+ AS
+ (transaction_duplicate BOOLEAN
+ ,ruuid INT8
+ );
+COMMENT ON TYPE exchange_do_array_reserve_insert_return_type
+ IS 'Return type for exchange_do_array_reserves_insert() stored procedure';
+
+CREATE TYPE exchange_do_select_deposits_missing_wire_return_type
+ AS
+ (
+ batch_deposit_serial_id INT8,
+ total_amount taler_amount,
+ wire_target_h_payto BYTEA,
+ deadline INT8
+ );
+COMMENT ON TYPE exchange_do_select_deposits_missing_wire_return_type
+ IS 'Return type for exchange_do_select_deposits_missing_wire';
+
+
+#include "0002-denominations.sql"
+#include "0002-denomination_revocations.sql"
+#include "0002-wire_targets.sql"
+#include "0002-kyc_alerts.sql"
+#include "0002-wire_fee.sql"
+#include "0002-global_fee.sql"
+#include "0002-wire_accounts.sql"
+#include "0002-auditors.sql"
+#include "0002-auditor_denom_sigs.sql"
+#include "0002-exchange_sign_keys.sql"
+#include "0002-signkey_revocations.sql"
+#include "0002-extensions.sql"
+#include "0002-policy_fulfillments.sql"
+#include "0002-policy_details.sql"
+#include "0002-profit_drains.sql"
+#include "0002-legitimization_processes.sql"
+#include "0002-legitimization_requirements.sql"
+#include "0002-reserves.sql"
+#include "0002-reserve_history.sql"
+#include "0002-reserves_in.sql"
+#include "0002-reserves_close.sql"
+#include "0002-close_requests.sql"
+#include "0002-reserves_open_deposits.sql"
+#include "0002-reserves_open_requests.sql"
+#include "0002-reserves_out.sql"
+#include "0002-known_coins.sql"
+#include "0002-coin_history.sql"
+#include "0002-refresh_commitments.sql"
+#include "0002-refresh_revealed_coins.sql"
+#include "0002-refresh_transfer_keys.sql"
+#include "0002-batch_deposits.sql"
+#include "0002-coin_deposits.sql"
+#include "0002-refunds.sql"
+#include "0002-wire_out.sql"
+#include "0002-aggregation_transient.sql"
+#include "0002-aggregation_tracking.sql"
+#include "0002-recoup.sql"
+#include "0002-recoup_refresh.sql"
+#include "0002-prewire.sql"
+#include "0002-cs_nonce_locks.sql"
+#include "0002-purse_requests.sql"
+#include "0002-purse_merges.sql"
+#include "0002-account_merges.sql"
+#include "0002-purse_decision.sql"
+#include "0002-contracts.sql"
+#include "0002-history_requests.sql"
+#include "0002-purse_deposits.sql"
+#include "0002-wads_in.sql"
+#include "0002-wad_in_entries.sql"
+#include "0002-wads_out.sql"
+#include "0002-wad_out_entries.sql"
+#include "0002-work_shards.sql"
+#include "0002-revolving_work_shards.sql"
+#include "0002-partners.sql"
+#include "0002-partner_accounts.sql"
+#include "0002-purse_actions.sql"
+#include "0002-purse_deletion.sql"
+#include "0002-kyc_attributes.sql"
+#include "0002-aml_status.sql"
+#include "0002-aml_staff.sql"
+#include "0002-aml_history.sql"
+#include "0002-age_withdraw.sql"
+
+
+COMMIT;
diff --git a/src/exchangedb/exchange-0003.sql.in b/src/exchangedb/exchange-0003.sql.in
new file mode 100644
index 000000000..c94497531
--- /dev/null
+++ b/src/exchangedb/exchange-0003.sql.in
@@ -0,0 +1,25 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0003', NULL, NULL);
+SET search_path TO exchange;
+
+#include "0003-wire_accounts.sql"
+#include "0003-purse_deletion.sql"
+
+COMMIT;
diff --git a/src/exchangedb/exchange-0004.sql.in b/src/exchangedb/exchange-0004.sql.in
new file mode 100644
index 000000000..c966aedc5
--- /dev/null
+++ b/src/exchangedb/exchange-0004.sql.in
@@ -0,0 +1,24 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2024 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SELECT _v.register_patch('exchange-0004', NULL, NULL);
+SET search_path TO exchange;
+
+#include "0004-refunds.sql"
+
+COMMIT;
diff --git a/src/exchangedb/exchange_do_account_merge.sql b/src/exchangedb/exchange_do_account_merge.sql
new file mode 100644
index 000000000..723154f1d
--- /dev/null
+++ b/src/exchangedb/exchange_do_account_merge.sql
@@ -0,0 +1,15 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
diff --git a/src/exchangedb/exchange_do_age_withdraw.sql b/src/exchangedb/exchange_do_age_withdraw.sql
new file mode 100644
index 000000000..89a291445
--- /dev/null
+++ b/src/exchangedb/exchange_do_age_withdraw.sql
@@ -0,0 +1,165 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author Özgür Kesim
+
+CREATE OR REPLACE FUNCTION exchange_do_age_withdraw(
+ IN amount_with_fee taler_amount,
+ IN rpub BYTEA,
+ IN rsig BYTEA,
+ IN now INT8,
+ IN min_reserve_gc INT8,
+ IN h_commitment BYTEA,
+ IN maximum_age_committed INT2, -- in years ϵ [0,1..)
+ IN noreveal_index INT2,
+ IN blinded_evs BYTEA[],
+ IN denom_serials INT8[],
+ IN denom_sigs BYTEA[],
+ OUT reserve_found BOOLEAN,
+ OUT balance_ok BOOLEAN,
+ OUT reserve_balance taler_amount,
+ OUT age_ok BOOLEAN,
+ OUT required_age INT2, -- in years ϵ [0,1..)
+ OUT reserve_birthday INT4,
+ OUT conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ reserve RECORD;
+ difference RECORD;
+ balance taler_amount;
+ not_before date;
+ earliest_date date;
+BEGIN
+-- Shards: reserves by reserve_pub (SELECT)
+-- reserves_out (INSERT, with CONFLICT detection) by wih
+-- reserves by reserve_pub (UPDATE)
+-- reserves_in by reserve_pub (SELECT)
+-- wire_targets by wire_target_h_payto
+
+SELECT current_balance
+ ,birthday
+ ,gc_date
+ INTO reserve
+ FROM exchange.reserves
+ WHERE reserves.reserve_pub=rpub;
+
+IF NOT FOUND
+THEN
+ reserve_found=FALSE;
+ age_ok = FALSE;
+ required_age=-1;
+ conflict=FALSE;
+ reserve_balance.val = 0;
+ reserve_balance.frac = 0;
+ balance_ok=FALSE;
+ RETURN;
+END IF;
+
+reserve_found = TRUE;
+conflict=FALSE; -- not really yet determined
+
+reserve_balance = reserve.current_balance;
+reserve_birthday = reserve.birthday;
+
+-- Check age requirements
+IF (reserve.birthday <> 0)
+THEN
+ not_before=date '1970-01-01' + reserve.birthday;
+ earliest_date = current_date - make_interval(maximum_age_committed);
+ --
+ -- 1970-01-01 + birthday == not_before now
+ -- | | |
+ -- <.......not allowed......>[<.....allowed range......>]
+ -- | | |
+ -- ____*_____________________*_________*________________* timeline
+ -- |
+ -- earliest_date ==
+ -- now - maximum_age_committed*year
+ --
+ IF (earliest_date < not_before)
+ THEN
+ required_age = extract(year from age(current_date, not_before));
+ age_ok = FALSE;
+ balance_ok=TRUE; -- NOT REALLY
+ RETURN;
+ END IF;
+END IF;
+
+age_ok = TRUE;
+required_age=0;
+
+-- Check reserve balance is sufficient.
+SELECT *
+INTO difference
+FROM amount_left_minus_right(reserve_balance
+ ,amount_with_fee);
+
+balance_ok = difference.ok;
+
+IF NOT balance_ok
+THEN
+ RETURN;
+END IF;
+
+balance = difference.diff;
+
+-- Calculate new expiration dates.
+min_reserve_gc=GREATEST(min_reserve_gc,reserve.gc_date);
+
+-- Update reserve balance.
+UPDATE reserves SET
+ gc_date=min_reserve_gc
+ ,current_balance=balance
+WHERE
+ reserves.reserve_pub=rpub;
+
+-- Write the commitment into the age-withdraw table
+INSERT INTO exchange.age_withdraw
+ (h_commitment
+ ,max_age
+ ,amount_with_fee
+ ,reserve_pub
+ ,reserve_sig
+ ,noreveal_index
+ ,denom_serials
+ ,h_blind_evs
+ ,denom_sigs)
+VALUES
+ (h_commitment
+ ,maximum_age_committed
+ ,amount_with_fee
+ ,rpub
+ ,rsig
+ ,noreveal_index
+ ,denom_serials
+ ,blinded_evs
+ ,denom_sigs)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Signal a conflict so that the caller
+ -- can fetch the actual data from the DB.
+ conflict=TRUE;
+ RETURN;
+ELSE
+ conflict=FALSE;
+END IF;
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_age_withdraw(taler_amount, BYTEA, BYTEA, INT8, INT8, BYTEA, INT2, INT2, BYTEA[], INT8[], BYTEA[])
+ IS 'Checks whether the reserve has sufficient balance for an age-withdraw operation (or the request is repeated and was previously approved) and that age requirements are met. If so updates the database with the result. Includes storing the blinded planchets and denomination signatures, or signaling conflict';
diff --git a/src/exchangedb/exchange_do_amount_specific.sql b/src/exchangedb/exchange_do_amount_specific.sql
new file mode 100644
index 000000000..9b305a3ec
--- /dev/null
+++ b/src/exchangedb/exchange_do_amount_specific.sql
@@ -0,0 +1,92 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+--------------------------------------------------------------
+-- Taler amounts and helper functions
+-------------------------------------------------------------
+
+CREATE OR REPLACE FUNCTION amount_normalize(
+ IN amount taler_amount
+ ,OUT normalized taler_amount
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ normalized.val = amount.val + amount.frac / 100000000;
+ normalized.frac = amount.frac % 100000000;
+END $$;
+
+COMMENT ON FUNCTION amount_normalize
+ IS 'Returns the normalized amount by adding to the .val the value of (.frac / 100000000) and removing the modulus 100000000 from .frac.';
+
+CREATE OR REPLACE FUNCTION amount_add(
+ IN a taler_amount
+ ,IN b taler_amount
+ ,OUT sum taler_amount
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ sum = (a.val + b.val, a.frac + b.frac);
+ CALL amount_normalize(sum ,sum);
+
+ IF (sum.val > (1<<52))
+ THEN
+ RAISE EXCEPTION 'addition overflow';
+ END IF;
+END $$;
+
+COMMENT ON FUNCTION amount_add
+ IS 'Returns the normalized sum of two amounts. It raises an exception when the resulting .val is larger than 2^52';
+
+CREATE OR REPLACE FUNCTION amount_left_minus_right(
+ IN l taler_amount
+ ,IN r taler_amount
+ ,OUT diff taler_amount
+ ,OUT ok BOOLEAN
+)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+
+IF (l.val > r.val)
+THEN
+ ok = TRUE;
+ IF (l.frac >= r.frac)
+ THEN
+ diff.val = l.val - r.val;
+ diff.frac = l.frac - r.frac;
+ ELSE
+ diff.val = l.val - r.val - 1;
+ diff.frac = l.frac + 100000000 - r.frac;
+ END IF;
+ELSE
+ IF (l.val = r.val) AND (l.frac >= r.frac)
+ THEN
+ diff.val = 0;
+ diff.frac = l.frac - r.frac;
+ ok = TRUE;
+ ELSE
+ diff = (-1, -1);
+ ok = FALSE;
+ END IF;
+END IF;
+
+RETURN;
+END $$;
+
+COMMENT ON FUNCTION amount_left_minus_right
+ IS 'Subtracts the right amount from the left and returns the difference and TRUE, if the left amount is larger than the right, or an invalid amount and FALSE otherwise.';
diff --git a/src/exchangedb/exchange_do_batch_coin_known.sql b/src/exchangedb/exchange_do_batch_coin_known.sql
new file mode 100644
index 000000000..db96cb08c
--- /dev/null
+++ b/src/exchangedb/exchange_do_batch_coin_known.sql
@@ -0,0 +1,469 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_batch4_known_coin(
+ IN in_coin_pub1 BYTEA,
+ IN in_denom_pub_hash1 BYTEA,
+ IN in_h_age_commitment1 BYTEA,
+ IN in_denom_sig1 BYTEA,
+ IN in_coin_pub2 BYTEA,
+ IN in_denom_pub_hash2 BYTEA,
+ IN in_h_age_commitment2 BYTEA,
+ IN in_denom_sig2 BYTEA,
+ IN in_coin_pub3 BYTEA,
+ IN in_denom_pub_hash3 BYTEA,
+ IN in_h_age_commitment3 BYTEA,
+ IN in_denom_sig3 BYTEA,
+ IN in_coin_pub4 BYTEA,
+ IN in_denom_pub_hash4 BYTEA,
+ IN in_h_age_commitment4 BYTEA,
+ IN in_denom_sig4 BYTEA,
+ OUT existed1 BOOLEAN,
+ OUT existed2 BOOLEAN,
+ OUT existed3 BOOLEAN,
+ OUT existed4 BOOLEAN,
+ OUT known_coin_id1 INT8,
+ OUT known_coin_id2 INT8,
+ OUT known_coin_id3 INT8,
+ OUT known_coin_id4 INT8,
+ OUT denom_pub_hash1 BYTEA,
+ OUT denom_pub_hash2 BYTEA,
+ OUT denom_pub_hash3 BYTEA,
+ OUT denom_pub_hash4 BYTEA,
+ OUT age_commitment_hash1 BYTEA,
+ OUT age_commitment_hash2 BYTEA,
+ OUT age_commitment_hash3 BYTEA,
+ OUT age_commitment_hash4 BYTEA)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+WITH dd AS (
+SELECT
+ denominations_serial,
+ coin
+ FROM denominations
+ WHERE denom_pub_hash
+ IN
+ (in_denom_pub_hash1,
+ in_denom_pub_hash2,
+ in_denom_pub_hash3,
+ in_denom_pub_hash4)
+ ),--dd
+ input_rows AS (
+ VALUES
+ (in_coin_pub1,
+ in_denom_pub_hash1,
+ in_h_age_commitment1,
+ in_denom_sig1),
+ (in_coin_pub2,
+ in_denom_pub_hash2,
+ in_h_age_commitment2,
+ in_denom_sig2),
+ (in_coin_pub3,
+ in_denom_pub_hash3,
+ in_h_age_commitment3,
+ in_denom_sig3),
+ (in_coin_pub4,
+ in_denom_pub_hash4,
+ in_h_age_commitment4,
+ in_denom_sig4)
+ ),--ir
+ ins AS (
+ INSERT INTO known_coins (
+ coin_pub,
+ denominations_serial,
+ age_commitment_hash,
+ denom_sig,
+ remaining
+ )
+ SELECT
+ ir.coin_pub,
+ dd.denominations_serial,
+ ir.age_commitment_hash,
+ ir.denom_sig,
+ dd.coin
+ FROM input_rows ir
+ JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ ON CONFLICT DO NOTHING
+ RETURNING known_coin_id
+ ),--kc
+ exists AS (
+ SELECT
+ CASE
+ WHEN
+ ins.known_coin_id IS NOT NULL
+ THEN
+ FALSE
+ ELSE
+ TRUE
+ END AS existed,
+ ins.known_coin_id,
+ dd.denom_pub_hash,
+ kc.age_commitment_hash
+ FROM input_rows ir
+ LEFT JOIN ins
+ ON ins.coin_pub = ir.coin_pub
+ LEFT JOIN known_coins kc
+ ON kc.coin_pub = ir.coin_pub
+ LEFT JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ )--exists
+SELECT
+ exists.existed AS existed1,
+ exists.known_coin_id AS known_coin_id1,
+ exists.denom_pub_hash AS denom_pub_hash1,
+ exists.age_commitment_hash AS age_commitment_hash1,
+ (
+ SELECT exists.existed
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS existed2,
+ (
+ SELECT exists.known_coin_id
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS known_coin_id2,
+ (
+ SELECT exists.denom_pub_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS denom_pub_hash2,
+ (
+ SELECT exists.age_commitment_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ )AS age_commitment_hash2,
+ (
+ SELECT exists.existed
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash3
+ ) AS existed3,
+ (
+ SELECT exists.known_coin_id
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash3
+ ) AS known_coin_id3,
+ (
+ SELECT exists.denom_pub_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash3
+ ) AS denom_pub_hash3,
+ (
+ SELECT exists.age_commitment_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash3
+ )AS age_commitment_hash3,
+ (
+ SELECT exists.existed
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash4
+ ) AS existed4,
+ (
+ SELECT exists.known_coin_id
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash4
+ ) AS known_coin_id4,
+ (
+ SELECT exists.denom_pub_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash4
+ ) AS denom_pub_hash4,
+ (
+ SELECT exists.age_commitment_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash4
+ )AS age_commitment_hash4
+FROM exists;
+
+RETURN;
+END $$;
+
+
+CREATE OR REPLACE FUNCTION exchange_do_batch2_known_coin(
+ IN in_coin_pub1 BYTEA,
+ IN in_denom_pub_hash1 BYTEA,
+ IN in_h_age_commitment1 BYTEA,
+ IN in_denom_sig1 BYTEA,
+ IN in_coin_pub2 BYTEA,
+ IN in_denom_pub_hash2 BYTEA,
+ IN in_h_age_commitment2 BYTEA,
+ IN in_denom_sig2 BYTEA,
+ OUT existed1 BOOLEAN,
+ OUT existed2 BOOLEAN,
+ OUT known_coin_id1 INT8,
+ OUT known_coin_id2 INT8,
+ OUT denom_pub_hash1 BYTEA,
+ OUT denom_pub_hash2 BYTEA,
+ OUT age_commitment_hash1 BYTEA,
+ OUT age_commitment_hash2 BYTEA)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+WITH dd AS (
+SELECT
+ denominations_serial,
+ coin
+ FROM denominations
+ WHERE denom_pub_hash
+ IN
+ (in_denom_pub_hash1,
+ in_denom_pub_hash2)
+ ),--dd
+ input_rows AS (
+ VALUES
+ (in_coin_pub1,
+ in_denom_pub_hash1,
+ in_h_age_commitment1,
+ in_denom_sig1),
+ (in_coin_pub2,
+ in_denom_pub_hash2,
+ in_h_age_commitment2,
+ in_denom_sig2)
+ ),--ir
+ ins AS (
+ INSERT INTO known_coins (
+ coin_pub,
+ denominations_serial,
+ age_commitment_hash,
+ denom_sig,
+ remaining
+ )
+ SELECT
+ ir.coin_pub,
+ dd.denominations_serial,
+ ir.age_commitment_hash,
+ ir.denom_sig,
+ dd.coin
+ FROM input_rows ir
+ JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ ON CONFLICT DO NOTHING
+ RETURNING known_coin_id
+ ),--kc
+ exists AS (
+ SELECT
+ CASE
+ WHEN ins.known_coin_id IS NOT NULL
+ THEN
+ FALSE
+ ELSE
+ TRUE
+ END AS existed,
+ ins.known_coin_id,
+ dd.denom_pub_hash,
+ kc.age_commitment_hash
+ FROM input_rows ir
+ LEFT JOIN ins
+ ON ins.coin_pub = ir.coin_pub
+ LEFT JOIN known_coins kc
+ ON kc.coin_pub = ir.coin_pub
+ LEFT JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ )--exists
+SELECT
+ exists.existed AS existed1,
+ exists.known_coin_id AS known_coin_id1,
+ exists.denom_pub_hash AS denom_pub_hash1,
+ exists.age_commitment_hash AS age_commitment_hash1,
+ (
+ SELECT exists.existed
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS existed2,
+ (
+ SELECT exists.known_coin_id
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS known_coin_id2,
+ (
+ SELECT exists.denom_pub_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ ) AS denom_pub_hash2,
+ (
+ SELECT exists.age_commitment_hash
+ FROM exists
+ WHERE exists.denom_pub_hash = in_denom_pub_hash2
+ )AS age_commitment_hash2
+FROM exists;
+
+RETURN;
+END $$;
+
+
+CREATE OR REPLACE FUNCTION exchange_do_batch1_known_coin(
+ IN in_coin_pub1 BYTEA,
+ IN in_denom_pub_hash1 BYTEA,
+ IN in_h_age_commitment1 BYTEA,
+ IN in_denom_sig1 BYTEA,
+ OUT existed1 BOOLEAN,
+ OUT known_coin_id1 INT8,
+ OUT denom_pub_hash1 BYTEA,
+ OUT age_commitment_hash1 BYTEA)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+WITH dd AS (
+SELECT
+ denominations_serial,
+ coin
+ FROM denominations
+ WHERE denom_pub_hash
+ IN
+ (in_denom_pub_hash1,
+ in_denom_pub_hash2)
+ ),--dd
+ input_rows AS (
+ VALUES
+ (in_coin_pub1,
+ in_denom_pub_hash1,
+ in_h_age_commitment1,
+ in_denom_sig1)
+ ),--ir
+ ins AS (
+ INSERT INTO known_coins (
+ coin_pub,
+ denominations_serial,
+ age_commitment_hash,
+ denom_sig,
+ remaining
+ )
+ SELECT
+ ir.coin_pub,
+ dd.denominations_serial,
+ ir.age_commitment_hash,
+ ir.denom_sig,
+ dd.coin
+ FROM input_rows ir
+ JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ ON CONFLICT DO NOTHING
+ RETURNING known_coin_id
+ ),--kc
+ exists AS (
+ SELECT
+ CASE
+ WHEN ins.known_coin_id IS NOT NULL
+ THEN
+ FALSE
+ ELSE
+ TRUE
+ END AS existed,
+ ins.known_coin_id,
+ dd.denom_pub_hash,
+ kc.age_commitment_hash
+ FROM input_rows ir
+ LEFT JOIN ins
+ ON ins.coin_pub = ir.coin_pub
+ LEFT JOIN known_coins kc
+ ON kc.coin_pub = ir.coin_pub
+ LEFT JOIN dd
+ ON dd.denom_pub_hash = ir.denom_pub_hash
+ )--exists
+SELECT
+ exists.existed AS existed1,
+ exists.known_coin_id AS known_coin_id1,
+ exists.denom_pub_hash AS denom_pub_hash1,
+ exists.age_commitment_hash AS age_commitment_hash1
+FROM exists;
+
+RETURN;
+END $$;
+
+/*** Experiment using a loop ***/
+/*
+CREATE OR REPLACE FUNCTION exchange_do_batch2_known_coin(
+ IN in_coin_pub1 BYTEA,
+ IN in_denom_pub_hash1 TEXT,
+ IN in_h_age_commitment1 TEXT,
+ IN in_denom_sig1 TEXT,
+ IN in_coin_pub2 BYTEA,
+ IN in_denom_pub_hash2 TEXT,
+ IN in_h_age_commitment2 TEXT,
+ IN in_denom_sig2 TEXT,
+ OUT existed1 BOOLEAN,
+ OUT existed2 BOOLEAN,
+ OUT known_coin_id1 INT8,
+ OUT known_coin_id2 INT8,
+ OUT denom_pub_hash1 TEXT,
+ OUT denom_pub_hash2 TEXT,
+ OUT age_commitment_hash1 TEXT,
+ OUT age_commitment_hash2 TEXT)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ ins_values RECORD;
+BEGIN
+ FOR i IN 1..2 LOOP
+ ins_values := (
+ SELECT
+ in_coin_pub1 AS coin_pub,
+ in_denom_pub_hash1 AS denom_pub_hash,
+ in_h_age_commitment1 AS age_commitment_hash,
+ in_denom_sig1 AS denom_sig
+ WHERE i = 1
+ UNION
+ SELECT
+ in_coin_pub2 AS coin_pub,
+ in_denom_pub_hash2 AS denom_pub_hash,
+ in_h_age_commitment2 AS age_commitment_hash,
+ in_denom_sig2 AS denom_sig
+ WHERE i = 2
+ );
+ WITH dd (denominations_serial, coin) AS (
+ SELECT denominations_serial, coin
+ FROM denominations
+ WHERE denom_pub_hash = ins_values.denom_pub_hash
+ ),
+ input_rows(coin_pub) AS (
+ VALUES (ins_values.coin_pub)
+ ),
+ ins AS (
+ INSERT INTO known_coins (
+ coin_pub,
+ denominations_serial,
+ age_commitment_hash,
+ denom_sig,
+ remaining
+ ) SELECT
+ input_rows.coin_pub,
+ dd.denominations_serial,
+ ins_values.age_commitment_hash,
+ ins_values.denom_sig,
+ coin
+ FROM dd
+ CROSS JOIN input_rows
+ ON CONFLICT DO NOTHING
+ RETURNING known_coin_id, denom_pub_hash
+ )
+ SELECT
+ CASE i
+ WHEN 1 THEN
+ COALESCE(ins.known_coin_id, 0) <> 0 AS existed1,
+ ins.known_coin_id AS known_coin_id1,
+ ins.denom_pub_hash AS denom_pub_hash1,
+ ins.age_commitment_hash AS age_commitment_hash1
+ WHEN 2 THEN
+ COALESCE(ins.known_coin_id, 0) <> 0 AS existed2,
+ ins.known_coin_id AS known_coin_id2,
+ ins.denom_pub_hash AS denom_pub_hash2,
+ ins.age_commitment_hash AS age_commitment_hash2
+ END
+ FROM ins;
+ END LOOP;
+END;
+$$;*/
diff --git a/src/exchangedb/exchange_do_batch_reserves_update.sql b/src/exchangedb/exchange_do_batch_reserves_update.sql
new file mode 100644
index 000000000..ebb58a149
--- /dev/null
+++ b/src/exchangedb/exchange_do_batch_reserves_update.sql
@@ -0,0 +1,72 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_batch_reserves_update(
+ IN in_reserve_pub BYTEA,
+ IN in_expiration_date INT8,
+ IN in_wire_ref INT8,
+ IN in_credit taler_amount,
+ IN in_exchange_account_name TEXT,
+ IN in_wire_source_h_payto BYTEA,
+ IN in_notify text,
+ OUT out_duplicate BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ INSERT INTO reserves_in
+ (reserve_pub
+ ,wire_reference
+ ,credit
+ ,exchange_account_section
+ ,wire_source_h_payto
+ ,execution_date)
+ VALUES
+ (in_reserve_pub
+ ,in_wire_ref
+ ,in_credit
+ ,in_exchange_account_name
+ ,in_wire_source_h_payto
+ ,in_expiration_date)
+ ON CONFLICT DO NOTHING;
+ IF FOUND
+ THEN
+ --IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
+ out_duplicate = FALSE;
+ UPDATE reserves rs
+ SET
+ current_balance.frac = (rs.current_balance).frac+in_credit.frac
+ - CASE
+ WHEN (rs.current_balance).frac + in_credit.frac >= 100000000
+ THEN 100000000
+ ELSE 1
+ END
+ ,current_balance.val = (rs.current_balance).val+in_credit.val
+ + CASE
+ WHEN (rs.current_balance).frac + in_credit.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ ,expiration_date=GREATEST(expiration_date,in_expiration_date)
+ ,gc_date=GREATEST(gc_date,in_expiration_date)
+ WHERE reserve_pub=in_reserve_pub;
+ EXECUTE FORMAT (
+ 'NOTIFY %s'
+ ,in_notify);
+ ELSE
+ out_duplicate = TRUE;
+ END IF;
+ RETURN;
+END $$;
diff --git a/src/exchangedb/exchange_do_batch_withdraw.sql b/src/exchangedb/exchange_do_batch_withdraw.sql
new file mode 100644
index 000000000..a48561a9a
--- /dev/null
+++ b/src/exchangedb/exchange_do_batch_withdraw.sql
@@ -0,0 +1,126 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author Christian Grothoff
+-- @author Özgür Kesim
+
+CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw(
+ IN amount taler_amount,
+ IN rpub BYTEA,
+ IN now INT8,
+ IN min_reserve_gc INT8,
+ IN do_age_check BOOLEAN,
+ OUT reserve_found BOOLEAN,
+ OUT balance_ok BOOLEAN,
+ OUT reserve_balance taler_amount,
+ OUT age_ok BOOLEAN,
+ OUT allowed_maximum_age INT2, -- in years
+ OUT ruuid INT8)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ reserve RECORD;
+ balance taler_amount;
+ not_before date;
+BEGIN
+-- Shards: reserves by reserve_pub (SELECT)
+-- reserves_out (INSERT, with CONFLICT detection) by wih
+-- reserves by reserve_pub (UPDATE)
+-- reserves_in by reserve_pub (SELECT)
+-- wire_targets by wire_target_h_payto
+
+SELECT current_balance
+ ,reserve_uuid
+ ,birthday
+ ,gc_date
+ INTO reserve
+ FROM exchange.reserves
+ WHERE reserves.reserve_pub=rpub;
+
+IF NOT FOUND
+THEN
+ -- reserve unknown
+ reserve_found=FALSE;
+ balance_ok=FALSE;
+ reserve_balance.frac = 0;
+ reserve_balance.val = 0;
+ age_ok=FALSE;
+ allowed_maximum_age=0;
+ ruuid=2;
+ RETURN;
+END IF;
+reserve_found=TRUE;
+reserve_balance = reserve.current_balance;
+ruuid = reserve.reserve_uuid;
+
+-- Check if age requirements are present
+IF ((NOT do_age_check) OR (reserve.birthday = 0))
+THEN
+ age_ok = TRUE;
+ allowed_maximum_age = -1;
+ELSE
+ -- Age requirements are formally not met: The exchange is setup to support
+ -- age restrictions (do_age_check == TRUE) and the reserve has a
+ -- birthday set (reserve_birthday != 0), but the client called the
+ -- batch-withdraw endpoint instead of the age-withdraw endpoint, which it
+ -- should have.
+ not_before=date '1970-01-01' + reserve.birthday;
+ allowed_maximum_age = extract(year from age(current_date, not_before));
+
+ balance_ok=FALSE;
+ age_ok = FALSE;
+ RETURN;
+END IF;
+
+
+-- Check reserve balance is sufficient.
+IF (reserve_balance.val > amount.val)
+THEN
+ IF (reserve_balance.frac >= amount.frac)
+ THEN
+ balance.val=reserve_balance.val - amount.val;
+ balance.frac=reserve_balance.frac - amount.frac;
+ ELSE
+ balance.val=reserve_balance.val - amount.val - 1;
+ balance.frac=reserve_balance.frac + 100000000 - amount.frac;
+ END IF;
+ELSE
+ IF (reserve_balance.val = amount.val) AND (reserve_balance.frac >= amount.frac)
+ THEN
+ balance.val=0;
+ balance.frac=reserve_balance.frac - amount.frac;
+ ELSE
+ balance_ok=FALSE;
+ RETURN;
+ END IF;
+END IF;
+
+-- Calculate new expiration dates.
+min_reserve_gc=GREATEST(min_reserve_gc,reserve.gc_date);
+
+-- Update reserve balance.
+UPDATE reserves SET
+ gc_date=min_reserve_gc
+ ,current_balance=balance
+WHERE
+ reserves.reserve_pub=rpub;
+
+balance_ok=TRUE;
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_batch_withdraw(taler_amount, BYTEA, INT8, INT8, BOOLEAN)
+ IS 'Checks whether the reserve has sufficient balance for a withdraw operation (or the request is repeated and was previously approved) and that age requirements are formally met. If so updates the database with the result. Excludes storing the planchets.';
+
diff --git a/src/exchangedb/exchange_do_batch_withdraw_insert.sql b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
new file mode 100644
index 000000000..d36181a6b
--- /dev/null
+++ b/src/exchangedb/exchange_do_batch_withdraw_insert.sql
@@ -0,0 +1,120 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_batch_withdraw_insert(
+ IN cs_nonce BYTEA,
+ IN amount taler_amount,
+ IN h_denom_pub BYTEA, -- FIXME: denom_serials should really be a parameter to this FUNCTION.
+ IN ruuid INT8,
+ IN reserve_sig BYTEA,
+ IN h_coin_envelope BYTEA,
+ IN denom_sig BYTEA,
+ IN now INT8,
+ OUT out_denom_unknown BOOLEAN,
+ OUT out_nonce_reuse BOOLEAN,
+ OUT out_conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ denom_serial INT8;
+BEGIN
+-- Shards: reserves by reserve_pub (SELECT)
+-- reserves_out (INSERT, with CONFLICT detection) by wih
+-- reserves by reserve_pub (UPDATE)
+-- reserves_in by reserve_pub (SELECT)
+-- wire_targets by wire_target_h_payto
+
+out_denom_unknown=TRUE;
+out_conflict=TRUE;
+out_nonce_reuse=TRUE;
+
+-- FIXME: denom_serials should really be a parameter to this FUNCTION.
+
+SELECT denominations_serial
+ INTO denom_serial
+ FROM exchange.denominations
+ WHERE denom_pub_hash=h_denom_pub;
+
+IF NOT FOUND
+THEN
+ -- denomination unknown, should be impossible!
+ out_denom_unknown=TRUE;
+ ASSERT false, 'denomination unknown';
+ RETURN;
+END IF;
+out_denom_unknown=FALSE;
+
+INSERT INTO exchange.reserves_out
+ (h_blind_ev
+ ,denominations_serial
+ ,denom_sig
+ ,reserve_uuid
+ ,reserve_sig
+ ,execution_date
+ ,amount_with_fee)
+VALUES
+ (h_coin_envelope
+ ,denom_serial
+ ,denom_sig
+ ,ruuid
+ ,reserve_sig
+ ,now
+ ,amount)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ out_conflict=TRUE;
+ RETURN;
+END IF;
+out_conflict=FALSE;
+
+-- Special actions needed for a CS withdraw?
+out_nonce_reuse=FALSE;
+IF NOT NULL cs_nonce
+THEN
+ -- Cache CS signature to prevent replays in the future
+ -- (and check if cached signature exists at the same time).
+ INSERT INTO exchange.cs_nonce_locks
+ (nonce
+ ,max_denomination_serial
+ ,op_hash)
+ VALUES
+ (cs_nonce
+ ,denom_serial
+ ,h_coin_envelope)
+ ON CONFLICT DO NOTHING;
+
+ IF NOT FOUND
+ THEN
+ -- See if the existing entry is identical.
+ SELECT 1
+ FROM exchange.cs_nonce_locks
+ WHERE nonce=cs_nonce
+ AND op_hash=h_coin_envelope;
+ IF NOT FOUND
+ THEN
+ out_nonce_reuse=TRUE;
+ ASSERT false, 'nonce reuse attempted by client';
+ RETURN;
+ END IF;
+ END IF;
+END IF;
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_batch_withdraw_insert(BYTEA, taler_amount, BYTEA, INT8, BYTEA, BYTEA, BYTEA, INT8)
+ IS 'Stores information about a planchet for a batch withdraw operation. Checks if the planchet already exists, and in that case indicates a conflict';
diff --git a/src/exchangedb/exchange_do_deposit.sql b/src/exchangedb/exchange_do_deposit.sql
new file mode 100644
index 000000000..c89e9e470
--- /dev/null
+++ b/src/exchangedb/exchange_do_deposit.sql
@@ -0,0 +1,206 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+CREATE OR REPLACE FUNCTION exchange_do_deposit(
+ -- For batch_deposits
+ IN in_shard INT8,
+ IN in_merchant_pub BYTEA,
+ IN in_wallet_timestamp INT8,
+ IN in_exchange_timestamp INT8,
+ IN in_refund_deadline INT8,
+ IN in_wire_deadline INT8,
+ IN in_h_contract_terms BYTEA,
+ IN in_wallet_data_hash BYTEA, -- can be NULL
+ IN in_wire_salt BYTEA,
+ IN in_wire_target_h_payto BYTEA,
+ IN in_policy_details_serial_id INT8, -- can be NULL
+ IN in_policy_blocked BOOLEAN,
+ -- For wire_targets
+ IN in_receiver_wire_account TEXT,
+ -- For coin_deposits
+ IN ina_coin_pub BYTEA[],
+ IN ina_coin_sig BYTEA[],
+ IN ina_amount_with_fee taler_amount[],
+ OUT out_exchange_timestamp INT8,
+ OUT out_insufficient_balance_coin_index INT4, -- index of coin with bad balance, NULL if none
+ OUT out_conflict BOOL
+ )
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ wtsi INT8; -- wire target serial id
+ bdsi INT8; -- batch_deposits serial id
+ i INT4;
+ ini_amount_with_fee taler_amount;
+ ini_coin_pub BYTEA;
+ ini_coin_sig BYTEA;
+BEGIN
+-- Shards:
+-- INSERT wire_targets (by h_payto), ON CONFLICT DO NOTHING;
+-- INSERT batch_deposits (by shard, merchant_pub), ON CONFLICT idempotency check;
+-- INSERT[] coin_deposits (by coin_pub), ON CONFLICT idempotency check;
+-- UPDATE[] known_coins (by coin_pub)
+
+
+-- First, get or create the 'wtsi'
+INSERT INTO wire_targets
+ (wire_target_h_payto
+ ,payto_uri)
+ VALUES
+ (in_wire_target_h_payto
+ ,in_receiver_wire_account)
+ ON CONFLICT DO NOTHING -- for CONFLICT ON (wire_target_h_payto)
+ RETURNING
+ wire_target_serial_id
+ INTO
+ wtsi;
+
+IF NOT FOUND
+THEN
+ SELECT
+ wire_target_serial_id
+ INTO
+ wtsi
+ FROM wire_targets
+ WHERE
+ wire_target_h_payto=in_wire_target_h_payto;
+END IF;
+
+
+-- Second, create the batch_deposits entry
+INSERT INTO batch_deposits
+ (shard
+ ,merchant_pub
+ ,wallet_timestamp
+ ,exchange_timestamp
+ ,refund_deadline
+ ,wire_deadline
+ ,h_contract_terms
+ ,wallet_data_hash
+ ,wire_salt
+ ,wire_target_h_payto
+ ,policy_details_serial_id
+ ,policy_blocked
+ )
+ VALUES
+ (in_shard
+ ,in_merchant_pub
+ ,in_wallet_timestamp
+ ,in_exchange_timestamp
+ ,in_refund_deadline
+ ,in_wire_deadline
+ ,in_h_contract_terms
+ ,in_wallet_data_hash
+ ,in_wire_salt
+ ,in_wire_target_h_payto
+ ,in_policy_details_serial_id
+ ,in_policy_blocked)
+ ON CONFLICT DO NOTHING -- for CONFLICT ON (merchant_pub, h_contract_terms)
+ RETURNING
+ batch_deposit_serial_id
+ INTO
+ bdsi;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: see if an identical record exists.
+ -- We do select over merchant_pub, h_contract_terms and wire_target_h_payto
+ -- first to maximally increase the chance of using the existing index.
+ SELECT
+ exchange_timestamp
+ ,batch_deposit_serial_id
+ INTO
+ out_exchange_timestamp
+ ,bdsi
+ FROM batch_deposits
+ WHERE shard=in_shard
+ AND merchant_pub=in_merchant_pub
+ AND h_contract_terms=in_h_contract_terms
+ AND wire_target_h_payto=in_wire_target_h_payto
+ -- now check the rest, too
+ AND ( (wallet_data_hash=in_wallet_data_hash) OR
+ (wallet_data_hash IS NULL AND in_wallet_data_hash IS NULL) )
+ AND wire_salt=in_wire_salt
+ AND wallet_timestamp=in_wallet_timestamp
+ AND refund_deadline=in_refund_deadline
+ AND wire_deadline=in_wire_deadline
+ AND ( (policy_details_serial_id=in_policy_details_serial_id) OR
+ (policy_details_serial_id IS NULL AND in_policy_details_serial_id IS NULL) );
+ IF NOT FOUND
+ THEN
+ -- Deposit exists, but with *strange* differences. Not allowed.
+ out_conflict=TRUE;
+ RETURN;
+ END IF;
+END IF;
+
+out_conflict=FALSE;
+
+-- Deposit each coin
+
+FOR i IN 1..array_length(ina_coin_pub,1)
+LOOP
+ ini_coin_pub = ina_coin_pub[i];
+ ini_coin_sig = ina_coin_sig[i];
+ ini_amount_with_fee = ina_amount_with_fee[i];
+
+ INSERT INTO coin_deposits
+ (batch_deposit_serial_id
+ ,coin_pub
+ ,coin_sig
+ ,amount_with_fee
+ )
+ VALUES
+ (bdsi
+ ,ini_coin_pub
+ ,ini_coin_sig
+ ,ini_amount_with_fee
+ )
+ ON CONFLICT DO NOTHING;
+
+ IF FOUND
+ THEN
+ -- Insert did happen, update balance in known_coins!
+
+ UPDATE known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac-ini_amount_with_fee.frac
+ + CASE
+ WHEN (kc.remaining).frac < ini_amount_with_fee.frac
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val-ini_amount_with_fee.val
+ - CASE
+ WHEN (kc.remaining).frac < ini_amount_with_fee.frac
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=ini_coin_pub
+ AND ( ((kc.remaining).val > ini_amount_with_fee.val) OR
+ ( ((kc.remaining).frac >= ini_amount_with_fee.frac) AND
+ ((kc.remaining).val >= ini_amount_with_fee.val) ) );
+
+ IF NOT FOUND
+ THEN
+ -- Insufficient balance.
+ -- Note: C arrays are 0 indexed, but i started at 1
+ out_insufficient_balance_coin_index=i-1;
+ RETURN;
+ END IF;
+ END IF;
+END LOOP; -- end FOR all coins
+
+END $$;
diff --git a/src/exchangedb/exchange_do_expire_purse.sql b/src/exchangedb/exchange_do_expire_purse.sql
new file mode 100644
index 000000000..ee9757f03
--- /dev/null
+++ b/src/exchangedb/exchange_do_expire_purse.sql
@@ -0,0 +1,98 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_expire_purse(
+ IN in_start_time INT8,
+ IN in_end_time INT8,
+ IN in_now INT8,
+ OUT out_found BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_purse_pub BYTEA;
+DECLARE
+ my_deposit record;
+DECLARE
+ my_in_reserve_quota BOOLEAN;
+BEGIN
+
+-- FIXME: we should probably do this in a loop
+-- and expire all at once, instead of one per query
+SELECT purse_pub
+ ,in_reserve_quota
+ INTO my_purse_pub
+ ,my_in_reserve_quota
+ FROM purse_requests
+ WHERE (purse_expiration >= in_start_time) AND
+ (purse_expiration < in_end_time) AND
+ NOT was_decided
+ ORDER BY purse_expiration ASC
+ LIMIT 1;
+out_found = FOUND;
+IF NOT FOUND
+THEN
+ RETURN;
+END IF;
+
+INSERT INTO purse_decision
+ (purse_pub
+ ,action_timestamp
+ ,refunded)
+VALUES
+ (my_purse_pub
+ ,in_now
+ ,TRUE);
+
+-- Code for 'TALER_DBEVENT_EXCHANGE_PURSE_REFUNDED'
+NOTIFY X8DJSPNYJMNZDAP7GN6YQ4EZVSQXMF3HRP4VAR347WP9SZYP1C200;
+
+IF (my_in_reserve_quota)
+THEN
+ UPDATE reserves
+ SET purses_active=purses_active-1
+ WHERE reserve_pub IN
+ (SELECT reserve_pub
+ FROM exchange.purse_merges
+ WHERE purse_pub=my_purse_pub
+ LIMIT 1);
+END IF;
+
+-- restore balance to each coin deposited into the purse
+FOR my_deposit IN
+ SELECT coin_pub
+ ,amount_with_fee
+ FROM purse_deposits
+ WHERE purse_pub = my_purse_pub
+LOOP
+ UPDATE known_coins kc SET
+ remaining.frac=(kc.remaining).frac+(my_deposit.amount_with_fee).frac
+ - CASE
+ WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val+(my_deposit.amount_with_fee).val
+ + CASE
+ WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub = my_deposit.coin_pub;
+ END LOOP;
+END $$;
+
+COMMENT ON FUNCTION exchange_do_expire_purse(INT8,INT8,INT8)
+ IS 'Finds an expired purse in the given time range and refunds the coins (if any).';
diff --git a/src/exchangedb/exchange_do_gc.sql b/src/exchangedb/exchange_do_gc.sql
new file mode 100644
index 000000000..d4ecb3024
--- /dev/null
+++ b/src/exchangedb/exchange_do_gc.sql
@@ -0,0 +1,140 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE PROCEDURE exchange_do_gc(
+ IN in_ancient_date INT8,
+ IN in_now INT8)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ reserve_uuid_min INT8; -- minimum reserve UUID still alive
+ melt_min INT8; -- minimum melt still alive
+ coin_min INT8; -- minimum known_coin still alive
+ batch_deposit_min INT8; -- minimum deposit still alive
+ reserve_out_min INT8; -- minimum reserve_out still alive
+ denom_min INT8; -- minimum denomination still alive
+BEGIN
+
+DELETE FROM prewire
+ WHERE finished=TRUE;
+
+DELETE FROM wire_fee
+ WHERE end_date < in_ancient_date;
+
+-- FIXME: use closing fee as threshold?
+DELETE FROM reserves
+ WHERE gc_date < in_now
+ AND current_balance = (0, 0);
+
+SELECT
+ reserve_out_serial_id
+ INTO
+ reserve_out_min
+ FROM reserves_out
+ ORDER BY reserve_out_serial_id ASC
+ LIMIT 1;
+
+DELETE FROM recoup
+ WHERE reserve_out_serial_id < reserve_out_min;
+
+SELECT
+ reserve_uuid
+ INTO
+ reserve_uuid_min
+ FROM reserves
+ ORDER BY reserve_uuid ASC
+ LIMIT 1;
+
+DELETE FROM reserves_out
+ WHERE reserve_uuid < reserve_uuid_min;
+
+-- FIXME: this query will be horribly slow;
+-- need to find another way to formulate it...
+DELETE FROM denominations
+ WHERE expire_legal < in_now
+ AND denominations_serial NOT IN
+ (SELECT DISTINCT denominations_serial
+ FROM reserves_out)
+ AND denominations_serial NOT IN
+ (SELECT DISTINCT denominations_serial
+ FROM known_coins
+ WHERE coin_pub IN
+ (SELECT DISTINCT coin_pub
+ FROM recoup))
+ AND denominations_serial NOT IN
+ (SELECT DISTINCT denominations_serial
+ FROM known_coins
+ WHERE coin_pub IN
+ (SELECT DISTINCT coin_pub
+ FROM recoup_refresh));
+
+SELECT
+ melt_serial_id
+ INTO
+ melt_min
+ FROM refresh_commitments
+ ORDER BY melt_serial_id ASC
+ LIMIT 1;
+
+DELETE FROM refresh_revealed_coins
+ WHERE melt_serial_id < melt_min;
+
+DELETE FROM refresh_transfer_keys
+ WHERE melt_serial_id < melt_min;
+
+SELECT
+ known_coin_id
+ INTO
+ coin_min
+ FROM known_coins
+ ORDER BY known_coin_id ASC
+ LIMIT 1;
+
+DELETE FROM recoup_refresh
+ WHERE known_coin_id < coin_min;
+
+DELETE FROM batch_deposits
+ WHERE wire_deadline < in_ancient_date;
+
+SELECT
+ batch_deposit_serial_id
+ INTO
+ batch_deposit_min
+ FROM coin_deposits
+ ORDER BY batch_deposit_serial_id ASC
+ LIMIT 1;
+
+DELETE FROM refunds
+ WHERE batch_deposit_serial_id < batch_deposit_min;
+DELETE FROM aggregation_tracking
+ WHERE batch_deposit_serial_id < batch_deposit_min;
+DELETE FROM coin_deposits
+ WHERE batch_deposit_serial_id < batch_deposit_min;
+
+
+
+SELECT
+ denominations_serial
+ INTO
+ denom_min
+ FROM denominations
+ ORDER BY denominations_serial ASC
+ LIMIT 1;
+
+DELETE FROM cs_nonce_locks
+ WHERE max_denomination_serial <= denom_min;
+
+END $$;
diff --git a/src/exchangedb/exchange_do_get_link_data.sql b/src/exchangedb/exchange_do_get_link_data.sql
new file mode 100644
index 000000000..08611a5ea
--- /dev/null
+++ b/src/exchangedb/exchange_do_get_link_data.sql
@@ -0,0 +1,59 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_get_link_data(
+ IN in_coin_pub BYTEA
+)
+RETURNS SETOF record
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ curs CURSOR
+ FOR
+ SELECT
+ melt_serial_id
+ FROM refresh_commitments
+ WHERE old_coin_pub=in_coin_pub;
+
+DECLARE
+ i RECORD;
+BEGIN
+OPEN curs;
+LOOP
+ FETCH NEXT FROM curs INTO i;
+ EXIT WHEN NOT FOUND;
+ RETURN QUERY
+ SELECT
+ tp.transfer_pub
+ ,denoms.denom_pub
+ ,rrc.ev_sig
+ ,rrc.ewv
+ ,rrc.link_sig
+ ,rrc.freshcoin_index
+ ,rrc.coin_ev
+ FROM refresh_revealed_coins rrc
+ JOIN refresh_transfer_keys tp
+ ON (tp.melt_serial_id=rrc.melt_serial_id)
+ JOIN denominations denoms
+ ON (rrc.denominations_serial=denoms.denominations_serial)
+ WHERE rrc.melt_serial_id =i.melt_serial_id
+/* GROUP BY tp.transfer_pub, denoms.denom_pub, rrc.ev_sig,rrc.ewv,rrc.link_sig,rrc.freshcoin_index, rrc.coin_ev*/
+ ORDER BY tp.transfer_pub,
+ rrc.freshcoin_index ASC
+ ;
+END LOOP;
+CLOSE curs;
+END $$;
diff --git a/src/exchangedb/exchange_do_insert_aml_decision.sql b/src/exchangedb/exchange_do_insert_aml_decision.sql
new file mode 100644
index 000000000..c8ed7e928
--- /dev/null
+++ b/src/exchangedb/exchange_do_insert_aml_decision.sql
@@ -0,0 +1,127 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_insert_aml_decision(
+ IN in_h_payto BYTEA,
+ IN in_new_threshold taler_amount,
+ IN in_new_status INT4,
+ IN in_decision_time INT8,
+ IN in_justification TEXT,
+ IN in_decider_pub BYTEA,
+ IN in_decider_sig BYTEA,
+ IN in_notify_s TEXT,
+ IN in_kyc_requirements TEXT,
+ IN in_requirement_row INT8,
+ OUT out_invalid_officer BOOLEAN,
+ OUT out_last_date INT8)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+-- Check officer is eligible to make decisions.
+PERFORM
+ FROM aml_staff
+ WHERE decider_pub=in_decider_pub
+ AND is_active
+ AND NOT read_only;
+IF NOT FOUND
+THEN
+ out_invalid_officer=TRUE;
+ out_last_date=0;
+ RETURN;
+END IF;
+out_invalid_officer=FALSE;
+
+-- Check no more recent decision exists.
+SELECT decision_time
+ INTO out_last_date
+ FROM aml_history
+ WHERE h_payto=in_h_payto
+ ORDER BY decision_time DESC;
+IF FOUND
+THEN
+ IF out_last_date >= in_decision_time
+ THEN
+ -- Refuse to insert older decision.
+ RETURN;
+ END IF;
+ UPDATE aml_status
+ SET threshold=in_new_threshold
+ ,status=in_new_status
+ ,kyc_requirement=in_requirement_row
+ WHERE h_payto=in_h_payto;
+ ASSERT FOUND, 'cannot have AML decision history but no AML status';
+ELSE
+ out_last_date = 0;
+ INSERT INTO aml_status
+ (h_payto
+ ,threshold
+ ,status
+ ,kyc_requirement)
+ VALUES
+ (in_h_payto
+ ,in_new_threshold
+ ,in_new_status
+ ,in_requirement_row)
+ ON CONFLICT (h_payto) DO
+ UPDATE SET
+ threshold=in_new_threshold
+ ,status=in_new_status;
+END IF;
+
+
+INSERT INTO aml_history
+ (h_payto
+ ,new_threshold
+ ,new_status
+ ,decision_time
+ ,justification
+ ,kyc_requirements
+ ,kyc_req_row
+ ,decider_pub
+ ,decider_sig
+ ) VALUES
+ (in_h_payto
+ ,in_new_threshold
+ ,in_new_status
+ ,in_decision_time
+ ,in_justification
+ ,in_kyc_requirements
+ ,in_requirement_row
+ ,in_decider_pub
+ ,in_decider_sig);
+
+
+-- wake up taler-exchange-aggregator
+IF 0 = in_new_status
+THEN
+ INSERT INTO kyc_alerts
+ (h_payto
+ ,trigger_type)
+ VALUES
+ (in_h_payto,1);
+
+ EXECUTE FORMAT (
+ 'NOTIFY %s'
+ ,in_notify_s);
+
+END IF;
+
+
+END $$;
+
+
+COMMENT ON FUNCTION exchange_do_insert_aml_decision(BYTEA, taler_amount, INT4, INT8, TEXT, BYTEA, BYTEA, TEXT, TEXT, INT8)
+ IS 'Checks whether the AML officer is eligible to make AML decisions and if so inserts the decision into the table';
diff --git a/src/exchangedb/exchange_do_insert_aml_officer.sql b/src/exchangedb/exchange_do_insert_aml_officer.sql
new file mode 100644
index 000000000..429ba11c7
--- /dev/null
+++ b/src/exchangedb/exchange_do_insert_aml_officer.sql
@@ -0,0 +1,74 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_insert_aml_officer(
+ IN in_decider_pub BYTEA,
+ IN in_master_sig BYTEA,
+ IN in_decider_name TEXT,
+ IN in_is_active BOOLEAN,
+ IN in_read_only BOOLEAN,
+ IN in_last_change INT8,
+ OUT out_last_change INT8)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+INSERT INTO exchange.aml_staff
+ (decider_pub
+ ,master_sig
+ ,decider_name
+ ,is_active
+ ,read_only
+ ,last_change
+ ) VALUES
+ (in_decider_pub
+ ,in_master_sig
+ ,in_decider_name
+ ,in_is_active
+ ,in_read_only
+ ,in_last_change)
+ ON CONFLICT DO NOTHING;
+IF FOUND
+THEN
+ out_last_change=0;
+ RETURN;
+END IF;
+
+-- Check update is most recent...
+SELECT last_change
+ INTO out_last_change
+ FROM exchange.aml_staff
+ WHERE decider_pub=in_decider_pub;
+ASSERT FOUND, 'cannot have INSERT conflict but no AML staff record';
+
+IF out_last_change >= in_last_change
+THEN
+ -- Refuse to insert older status
+ RETURN;
+END IF;
+
+-- We are more recent, update existing record.
+UPDATE exchange.aml_staff
+ SET master_sig=in_master_sig
+ ,decider_name=in_decider_name
+ ,is_active=in_is_active
+ ,read_only=in_read_only
+ ,last_change=in_last_change
+ WHERE decider_pub=in_decider_pub;
+END $$;
+
+
+COMMENT ON FUNCTION exchange_do_insert_aml_officer(BYTEA, BYTEA, TEXT, BOOL, BOOL, INT8)
+ IS 'Inserts or updates AML staff record, making sure the update is more recent than the previous change';
diff --git a/src/exchangedb/exchange_do_insert_kyc_attributes.sql b/src/exchangedb/exchange_do_insert_kyc_attributes.sql
new file mode 100644
index 000000000..7db4d80c0
--- /dev/null
+++ b/src/exchangedb/exchange_do_insert_kyc_attributes.sql
@@ -0,0 +1,114 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_insert_kyc_attributes(
+ IN in_process_row INT8,
+ IN in_h_payto BYTEA,
+ IN in_kyc_prox BYTEA,
+ IN in_provider_section TEXT,
+ IN in_satisfied_checks TEXT[],
+ IN in_birthday INT4,
+ IN in_provider_account_id TEXT,
+ IN in_provider_legitimization_id TEXT,
+ IN in_collection_time_ts INT8,
+ IN in_expiration_time INT8,
+ IN in_expiration_time_ts INT8,
+ IN in_enc_attributes BYTEA,
+ IN in_require_aml BOOLEAN,
+ IN in_kyc_completed_notify_s TEXT,
+ OUT out_ok BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ orig_reserve_pub BYTEA;
+ orig_reserve_found BOOLEAN;
+BEGIN
+
+INSERT INTO exchange.kyc_attributes
+ (h_payto
+ ,kyc_prox
+ ,provider
+ ,satisfied_checks
+ ,collection_time
+ ,expiration_time
+ ,encrypted_attributes
+ ,legitimization_serial
+ ) VALUES
+ (in_h_payto
+ ,in_kyc_prox
+ ,in_provider_section
+ ,in_satisfied_checks
+ ,in_collection_time_ts
+ ,in_expiration_time_ts
+ ,in_enc_attributes
+ ,in_process_row);
+
+UPDATE legitimization_processes
+ SET provider_user_id=in_provider_account_id
+ ,provider_legitimization_id=in_provider_legitimization_id
+ ,expiration_time=GREATEST(expiration_time,in_expiration_time)
+ ,finished=TRUE
+ WHERE h_payto=in_h_payto
+ AND legitimization_process_serial_id=in_process_row
+ AND provider_section=in_provider_section;
+out_ok = FOUND;
+
+
+-- If the h_payto refers to a reserve in the original requirements
+-- update the originating reserve's birthday.
+SELECT reserve_pub
+ INTO orig_reserve_pub
+ FROM exchange.legitimization_requirements
+ WHERE h_payto=in_h_payto
+ AND NOT reserve_pub IS NULL;
+orig_reserve_found = FOUND;
+
+IF orig_reserve_found
+THEN
+ UPDATE exchange.reserves
+ SET birthday=in_birthday
+ WHERE reserve_pub=orig_reserve_pub;
+END IF;
+
+IF in_require_aml
+THEN
+ INSERT INTO exchange.aml_status
+ (h_payto
+ ,status)
+ VALUES
+ (in_h_payto
+ ,1)
+ ON CONFLICT (h_payto) DO
+ UPDATE SET status=EXCLUDED.status | 1;
+END IF;
+
+EXECUTE FORMAT (
+ 'NOTIFY %s'
+ ,in_kyc_completed_notify_s);
+
+
+INSERT INTO kyc_alerts
+ (h_payto
+ ,trigger_type)
+ VALUES
+ (in_h_payto,1);
+
+
+END $$;
+
+
+COMMENT ON FUNCTION exchange_do_insert_kyc_attributes(INT8, BYTEA, BYTEA, TEXT, TEXT[], INT4, TEXT, TEXT, INT8, INT8, INT8, BYTEA, BOOL, TEXT)
+ IS 'Inserts new KYC attributes and updates the status of the legitimization process and the AML status for the account';
diff --git a/src/exchangedb/exchange_do_insert_or_update_policy_details.sql b/src/exchangedb/exchange_do_insert_or_update_policy_details.sql
new file mode 100644
index 000000000..85e52d3d3
--- /dev/null
+++ b/src/exchangedb/exchange_do_insert_or_update_policy_details.sql
@@ -0,0 +1,114 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_insert_or_update_policy_details(
+ IN in_policy_hash_code BYTEA,
+ IN in_policy_json TEXT,
+ IN in_deadline INT8,
+ IN in_commitment taler_amount,
+ IN in_accumulated_total taler_amount,
+ IN in_fee taler_amount,
+ IN in_transferable taler_amount,
+ IN in_fulfillment_state SMALLINT,
+ OUT out_policy_details_serial_id INT8,
+ OUT out_accumulated_total taler_amount,
+ OUT out_fulfillment_state SMALLINT)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ cur_commitment taler_amount;
+DECLARE
+ cur_accumulated_total taler_amount;
+DECLARE
+ rval RECORD;
+BEGIN
+ -- First, try to create a new entry.
+ INSERT INTO policy_details
+ (policy_hash_code,
+ policy_json,
+ deadline,
+ commitment,
+ accumulated_total,
+ fee,
+ transferable,
+ fulfillment_state)
+ VALUES (in_policy_hash_code,
+ in_policy_json,
+ in_deadline,
+ in_commitment,
+ in_accumulated_total,
+ in_fee,
+ in_transferable,
+ in_fulfillment_state)
+ ON CONFLICT (policy_hash_code) DO NOTHING
+ RETURNING policy_details_serial_id INTO out_policy_details_serial_id;
+
+ -- If the insert was successful, return
+ -- We assume that the fullfilment_state was correct in first place.
+ IF FOUND THEN
+ out_accumulated_total = in_accumulated_total;
+ out_fulfillment_state = in_fulfillment_state;
+ RETURN;
+ END IF;
+
+ -- We had a conflict, grab the parts we need to update.
+ SELECT policy_details_serial_id
+ ,commitment
+ ,accumulated_total
+ INTO rval
+ FROM policy_details
+ WHERE policy_hash_code = in_policy_hash_code;
+
+ -- We use rval as workaround as we cannot select
+ -- directly into the amount due to Postgres limitations.
+ out_policy_details_serial_id := rval.policy_details_serial_id;
+ cur_commitment := rval.commitment;
+ cur_accumulated_total := rval.accumulated_total;
+
+ -- calculate the new values (overflows throws exception)
+ out_accumulated_total.val = cur_accumulated_total.val + in_accumulated_total.val;
+ out_accumulated_total.frac = cur_accumulated_total.frac + in_accumulated_total.frac;
+ -- normalize
+ out_accumulated_total.val = out_accumulated_total.val + out_accumulated_total.frac / 100000000;
+ out_accumulated_total.frac = out_accumulated_total.frac % 100000000;
+
+ IF (out_accumulated_total.val > (1 << 52))
+ THEN
+ RAISE EXCEPTION 'accumulation overflow';
+ END IF;
+
+
+ -- Set the fulfillment_state according to the values.
+ -- For now, we only update the state when it was INSUFFICIENT.
+ -- FIXME[oec] #7999: What to do in case of Failure or other state?
+ IF (out_fullfillment_state = 2) -- INSUFFICIENT
+ THEN
+ IF (out_accumulated_total.val >= cur_commitment.val OR
+ (out_accumulated_total.val = cur_commitment.val AND
+ out_accumulated_total.frac >= cur_commitment.frac))
+ THEN
+ out_fulfillment_state = 3; -- READY
+ END IF;
+ END IF;
+
+ -- Now, update the record
+ UPDATE exchange.policy_details
+ SET
+ accumulated = out_accumulated_total,
+ fulfillment_state = out_fulfillment_state
+ WHERE
+ policy_details_serial_id = out_policy_details_serial_id;
+END $$;
diff --git a/src/exchangedb/exchange_do_melt.sql b/src/exchangedb/exchange_do_melt.sql
new file mode 100644
index 000000000..0200986fa
--- /dev/null
+++ b/src/exchangedb/exchange_do_melt.sql
@@ -0,0 +1,182 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+
+
+CREATE OR REPLACE FUNCTION exchange_do_melt(
+ IN in_cs_rms BYTEA,
+ IN in_amount_with_fee taler_amount,
+ IN in_rc BYTEA,
+ IN in_old_coin_pub BYTEA,
+ IN in_old_coin_sig BYTEA,
+ IN in_known_coin_id INT8, -- not used, but that's OK
+ IN in_noreveal_index INT4,
+ IN in_zombie_required BOOLEAN,
+ OUT out_balance_ok BOOLEAN,
+ OUT out_zombie_bad BOOLEAN,
+ OUT out_noreveal_index INT4)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ denom_max INT8;
+BEGIN
+-- Shards: INSERT refresh_commitments (by rc)
+-- (rare:) SELECT refresh_commitments (by old_coin_pub) -- crosses shards!
+-- (rare:) SEELCT refresh_revealed_coins (by melt_serial_id)
+-- (rare:) PERFORM recoup_refresh (by rrc_serial) -- crosses shards!
+-- UPDATE known_coins (by coin_pub)
+
+INSERT INTO exchange.refresh_commitments
+ (rc
+ ,old_coin_pub
+ ,old_coin_sig
+ ,amount_with_fee
+ ,noreveal_index
+ )
+ VALUES
+ (in_rc
+ ,in_old_coin_pub
+ ,in_old_coin_sig
+ ,in_amount_with_fee
+ ,in_noreveal_index)
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: see if an identical record exists.
+ out_noreveal_index=-1;
+ SELECT
+ noreveal_index
+ INTO
+ out_noreveal_index
+ FROM exchange.refresh_commitments
+ WHERE rc=in_rc;
+ out_balance_ok=FOUND;
+ out_zombie_bad=FALSE; -- zombie is OK
+ RETURN;
+END IF;
+
+
+IF in_zombie_required
+THEN
+ -- Check if this coin was part of a refresh
+ -- operation that was subsequently involved
+ -- in a recoup operation. We begin by all
+ -- refresh operations our coin was involved
+ -- with, then find all associated reveal
+ -- operations, and then see if any of these
+ -- reveal operations was involved in a recoup.
+ PERFORM
+ FROM recoup_refresh
+ WHERE rrc_serial IN
+ (SELECT rrc_serial
+ FROM refresh_revealed_coins
+ WHERE melt_serial_id IN
+ (SELECT melt_serial_id
+ FROM refresh_commitments
+ WHERE old_coin_pub=in_old_coin_pub));
+ IF NOT FOUND
+ THEN
+ out_zombie_bad=TRUE;
+ out_balance_ok=FALSE;
+ RETURN;
+ END IF;
+END IF;
+
+out_zombie_bad=FALSE; -- zombie is OK
+
+
+-- Check and update balance of the coin.
+UPDATE known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac-in_amount_with_fee.frac
+ + CASE
+ WHEN (kc.remaining).frac < in_amount_with_fee.frac
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val-in_amount_with_fee.val
+ - CASE
+ WHEN (kc.remaining).frac < in_amount_with_fee.frac
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=in_old_coin_pub
+ AND ( ((kc.remaining).val > in_amount_with_fee.val) OR
+ ( ((kc.remaining).frac >= in_amount_with_fee.frac) AND
+ ((kc.remaining).val >= in_amount_with_fee.val) ) );
+
+IF NOT FOUND
+THEN
+ -- Insufficient balance.
+ out_noreveal_index=-1;
+ out_balance_ok=FALSE;
+ RETURN;
+END IF;
+
+
+
+-- Special actions needed for a CS melt?
+IF NOT NULL in_cs_rms
+THEN
+ -- Get maximum denominations serial value in
+ -- existence, this will determine how long the
+ -- nonce will be locked.
+ SELECT
+ denominations_serial
+ INTO
+ denom_max
+ FROM exchange.denominations
+ ORDER BY denominations_serial DESC
+ LIMIT 1;
+
+ -- Cache CS signature to prevent replays in the future
+ -- (and check if cached signature exists at the same time).
+ INSERT INTO exchange.cs_nonce_locks
+ (nonce
+ ,max_denomination_serial
+ ,op_hash)
+ VALUES
+ (cs_rms
+ ,denom_serial
+ ,in_rc)
+ ON CONFLICT DO NOTHING;
+
+ IF NOT FOUND
+ THEN
+ -- Record exists, make sure it is the same
+ SELECT 1
+ FROM exchange.cs_nonce_locks
+ WHERE nonce=cs_rms
+ AND op_hash=in_rc;
+
+ IF NOT FOUND
+ THEN
+ -- Nonce reuse detected
+ out_balance_ok=FALSE;
+ out_zombie_bad=FALSE;
+ out_noreveal_index=42; -- FIXME: return error message more nicely!
+ ASSERT false, 'nonce reuse attempted by client';
+ END IF;
+ END IF;
+END IF;
+
+-- Everything fine, return success!
+out_balance_ok=TRUE;
+out_noreveal_index=in_noreveal_index;
+
+END $$;
diff --git a/src/exchangedb/exchange_do_purse_delete.sql b/src/exchangedb/exchange_do_purse_delete.sql
new file mode 100644
index 000000000..5668f7bec
--- /dev/null
+++ b/src/exchangedb/exchange_do_purse_delete.sql
@@ -0,0 +1,118 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_purse_delete(
+ IN in_purse_pub BYTEA,
+ IN in_purse_sig BYTEA,
+ IN in_now INT8,
+ OUT out_decided BOOLEAN,
+ OUT out_found BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_deposit record;
+DECLARE
+ my_in_reserve_quota BOOLEAN;
+BEGIN
+
+PERFORM refunded FROM purse_decision
+ WHERE purse_pub=in_purse_pub;
+IF FOUND
+THEN
+ out_found=TRUE;
+ out_decided=TRUE;
+ RETURN;
+END IF;
+out_decided=FALSE;
+
+SELECT in_reserve_quota
+ INTO my_in_reserve_quota
+ FROM exchange.purse_requests
+ WHERE purse_pub=in_purse_pub;
+out_found=FOUND;
+IF NOT FOUND
+THEN
+ RETURN;
+END IF;
+
+-- store reserve deletion
+INSERT INTO exchange.purse_deletion
+ (purse_pub
+ ,purse_sig)
+VALUES
+ (in_purse_pub
+ ,in_purse_sig)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ RETURN;
+END IF;
+
+-- Delete contract associated with purse, if it exists.
+DELETE FROM contracts
+ WHERE purse_pub=in_purse_pub;
+
+-- store purse decision
+INSERT INTO purse_decision
+ (purse_pub
+ ,action_timestamp
+ ,refunded)
+VALUES
+ (in_purse_pub
+ ,in_now
+ ,TRUE);
+
+-- update purse quota at reserve
+IF (my_in_reserve_quota)
+THEN
+ UPDATE reserves
+ SET purses_active=purses_active-1
+ WHERE reserve_pub IN
+ (SELECT reserve_pub
+ FROM exchange.purse_merges
+ WHERE purse_pub=in_purse_pub
+ LIMIT 1);
+END IF;
+
+-- restore balance to each coin deposited into the purse
+FOR my_deposit IN
+ SELECT coin_pub
+ ,amount_with_fee
+ FROM exchange.purse_deposits
+ WHERE purse_pub = in_purse_pub
+LOOP
+ UPDATE known_coins kc SET
+ remaining.frac=(kc.remaining).frac+(my_deposit.amount_with_fee).frac
+ - CASE
+ WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val+(my_deposit.amount_with_fee).val
+ + CASE
+ WHEN (kc.remaining).frac+(my_deposit.amount_with_fee).frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub = my_deposit.coin_pub;
+END LOOP;
+
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_purse_delete(BYTEA,BYTEA,INT8)
+ IS 'Delete a previously undecided purse and refund the coins (if any).';
diff --git a/src/exchangedb/exchange_do_purse_deposit.sql b/src/exchangedb/exchange_do_purse_deposit.sql
new file mode 100644
index 000000000..49d3c919b
--- /dev/null
+++ b/src/exchangedb/exchange_do_purse_deposit.sql
@@ -0,0 +1,267 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_purse_deposit(
+ IN in_partner_id INT8,
+ IN in_purse_pub BYTEA,
+ IN in_amount_with_fee taler_amount,
+ IN in_coin_pub BYTEA,
+ IN in_coin_sig BYTEA,
+ IN in_amount_without_fee taler_amount,
+ IN in_reserve_expiration INT8,
+ IN in_now INT8,
+ OUT out_balance_ok BOOLEAN,
+ OUT out_late BOOLEAN,
+ OUT out_conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ was_merged BOOLEAN;
+DECLARE
+ psi INT8; -- partner's serial ID (set if merged)
+DECLARE
+ my_amount taler_amount; -- total in purse
+DECLARE
+ was_paid BOOLEAN;
+DECLARE
+ my_in_reserve_quota BOOLEAN;
+DECLARE
+ my_reserve_pub BYTEA;
+DECLARE
+ rval RECORD;
+BEGIN
+
+-- Store the deposit request.
+INSERT INTO purse_deposits
+ (partner_serial_id
+ ,purse_pub
+ ,coin_pub
+ ,amount_with_fee
+ ,coin_sig)
+ VALUES
+ (in_partner_id
+ ,in_purse_pub
+ ,in_coin_pub
+ ,in_amount_with_fee
+ ,in_coin_sig)
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: check if coin_sig is the same,
+ -- if so, success, otherwise conflict!
+
+ PERFORM
+ FROM purse_deposits
+ WHERE purse_pub = in_purse_pub
+ AND coin_pub = in_coin_pub
+ AND coin_sig = in_coin_sig;
+ IF NOT FOUND
+ THEN
+ -- Deposit exists, but with differences. Not allowed.
+ out_balance_ok=FALSE;
+ out_late=FALSE;
+ out_conflict=TRUE;
+ RETURN;
+ ELSE
+ -- Deposit exists, do not count for balance. Allow.
+ out_late=FALSE;
+ out_balance_ok=TRUE;
+ out_conflict=FALSE;
+ RETURN;
+ END IF;
+END IF;
+
+
+-- Check if purse was deleted, if so, abort and prevent deposit.
+PERFORM
+ FROM exchange.purse_deletion
+ WHERE purse_pub = in_purse_pub;
+IF FOUND
+THEN
+ out_late=TRUE;
+ out_balance_ok=FALSE;
+ out_conflict=FALSE;
+ RETURN;
+END IF;
+
+
+-- Debit the coin
+-- Check and update balance of the coin.
+UPDATE known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac-in_amount_with_fee.frac
+ + CASE
+ WHEN (kc.remaining).frac < in_amount_with_fee.frac
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val-in_amount_with_fee.val
+ - CASE
+ WHEN (kc.remaining).frac < in_amount_with_fee.frac
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=in_coin_pub
+ AND ( ((kc.remaining).val > in_amount_with_fee.val) OR
+ ( ((kc.remaining).frac >= in_amount_with_fee.frac) AND
+ ((kc.remaining).val >= in_amount_with_fee.val) ) );
+
+IF NOT FOUND
+THEN
+ -- Insufficient balance.
+ out_balance_ok=FALSE;
+ out_late=FALSE;
+ out_conflict=FALSE;
+ RETURN;
+END IF;
+
+
+-- Credit the purse.
+UPDATE purse_requests pr
+ SET
+ balance.frac=(pr.balance).frac+in_amount_without_fee.frac
+ - CASE
+ WHEN (pr.balance).frac+in_amount_without_fee.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END,
+ balance.val=(pr.balance).val+in_amount_without_fee.val
+ + CASE
+ WHEN (pr.balance).frac+in_amount_without_fee.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ WHERE purse_pub=in_purse_pub;
+
+out_conflict=FALSE;
+out_balance_ok=TRUE;
+
+-- See if we can finish the merge or need to update the trigger time and partner.
+SELECT COALESCE(partner_serial_id,0)
+ ,reserve_pub
+ INTO psi
+ ,my_reserve_pub
+ FROM purse_merges
+ WHERE purse_pub=in_purse_pub;
+
+IF NOT FOUND
+THEN
+ -- Purse was not yet merged. We are done.
+ out_late=FALSE;
+ RETURN;
+END IF;
+
+SELECT
+ amount_with_fee
+ ,in_reserve_quota
+ INTO
+ rval
+ FROM exchange.purse_requests preq
+ WHERE (purse_pub=in_purse_pub)
+ AND ( ( ( ((preq.amount_with_fee).val <= (preq.balance).val)
+ AND ((preq.amount_with_fee).frac <= (preq.balance).frac) )
+ OR ((preq.amount_with_fee).val < (preq.balance).val) ) );
+IF NOT FOUND
+THEN
+ out_late=FALSE;
+ RETURN;
+END IF;
+
+-- We use rval as workaround as we cannot select
+-- directly into the amount due to Postgres limitations.
+my_amount := rval.amount_with_fee;
+my_in_reserve_quota := rval.in_reserve_quota;
+
+-- Remember how this purse was finished.
+INSERT INTO purse_decision
+ (purse_pub
+ ,action_timestamp
+ ,refunded)
+VALUES
+ (in_purse_pub
+ ,in_now
+ ,FALSE)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Purse already decided, likely expired.
+ out_late=TRUE;
+ RETURN;
+END IF;
+
+out_late=FALSE;
+
+IF (my_in_reserve_quota)
+THEN
+ UPDATE reserves
+ SET purses_active=purses_active-1
+ WHERE reserve_pub IN
+ (SELECT reserve_pub
+ FROM purse_merges
+ WHERE purse_pub=my_purse_pub
+ LIMIT 1);
+END IF;
+
+
+IF (0 != psi)
+THEN
+ -- The taler-exchange-router will take care of this.
+ UPDATE purse_actions
+ SET action_date=0 --- "immediately"
+ ,partner_serial_id=psi
+ WHERE purse_pub=in_purse_pub;
+ELSE
+ -- This is a local reserve, update balance immediately.
+ INSERT INTO reserves
+ (reserve_pub
+ ,current_balance
+ ,expiration_date
+ ,gc_date)
+ VALUES
+ (my_reserve_pub
+ ,my_amount
+ ,in_reserve_expiration
+ ,in_reserve_expiration)
+ ON CONFLICT DO NOTHING;
+
+ IF NOT FOUND
+ THEN
+ -- Reserve existed, thus UPDATE instead of INSERT.
+ UPDATE reserves
+ SET
+ current_balance.frac=(current_balance).frac+my_amount.frac
+ - CASE
+ WHEN (current_balance).frac + my_amount.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END
+ ,current_balance.val=(current_balance).val+my_amount.val
+ + CASE
+ WHEN (current_balance).frac + my_amount.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ ,expiration_date=GREATEST(expiration_date,in_reserve_expiration)
+ ,gc_date=GREATEST(gc_date,in_reserve_expiration)
+ WHERE reserve_pub=my_reserve_pub;
+ END IF;
+
+END IF;
+
+
+END $$;
diff --git a/src/exchangedb/exchange_do_purse_merge.sql b/src/exchangedb/exchange_do_purse_merge.sql
new file mode 100644
index 000000000..946fd7e97
--- /dev/null
+++ b/src/exchangedb/exchange_do_purse_merge.sql
@@ -0,0 +1,237 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_purse_merge(
+ IN in_purse_pub BYTEA,
+ IN in_merge_sig BYTEA,
+ IN in_merge_timestamp INT8,
+ IN in_reserve_sig BYTEA,
+ IN in_partner_url TEXT,
+ IN in_reserve_pub BYTEA,
+ IN in_wallet_h_payto BYTEA,
+ IN in_expiration_date INT8,
+ OUT out_no_partner BOOLEAN,
+ OUT out_no_balance BOOLEAN,
+ OUT out_conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_amount taler_amount;
+DECLARE
+ my_purse_fee taler_amount;
+DECLARE
+ my_partner_serial_id INT8;
+DECLARE
+ my_in_reserve_quota BOOLEAN;
+DECLARE
+ rval RECORD;
+DECLARE
+ reserve RECORD;
+DECLARE
+ balance taler_amount;
+BEGIN
+
+-- Initialize reserve, if not yet exists.
+INSERT INTO reserves
+ (reserve_pub
+ ,expiration_date
+ ,gc_date)
+ VALUES
+ (in_reserve_pub
+ ,in_expiration_date
+ ,in_expiration_date)
+ ON CONFLICT DO NOTHING;
+
+
+IF in_partner_url IS NULL
+THEN
+ my_partner_serial_id=NULL;
+ELSE
+ SELECT
+ partner_serial_id
+ INTO
+ my_partner_serial_id
+ FROM exchange.partners
+ WHERE partner_base_url=in_partner_url
+ AND start_date <= in_merge_timestamp
+ AND end_date > in_merge_timestamp;
+ IF NOT FOUND
+ THEN
+ out_no_partner=TRUE;
+ out_conflict=FALSE;
+ RETURN;
+ END IF;
+END IF;
+
+out_no_partner=FALSE;
+
+-- Check purse is 'full'.
+SELECT amount_with_fee
+ ,purse_fee
+ ,in_reserve_quota
+ INTO rval
+ FROM purse_requests pr
+ WHERE purse_pub=in_purse_pub
+ AND (pr.balance).val >= (pr.amount_with_fee).val
+ AND ( (pr.balance).frac >= (pr.amount_with_fee).frac OR
+ (pr.balance).val > (pr.amount_with_fee).val );
+IF NOT FOUND
+THEN
+ out_no_balance=TRUE;
+ out_conflict=FALSE;
+ RETURN;
+END IF;
+
+-- We use rval as workaround as we cannot select
+-- directly into the amount due to Postgres limitations.
+my_amount := rval.amount_with_fee;
+my_purse_fee := rval.purse_fee;
+my_in_reserve_quota := rval.in_reserve_quota;
+
+out_no_balance=FALSE;
+
+-- Store purse merge signature, checks for purse_pub uniqueness
+INSERT INTO purse_merges
+ (partner_serial_id
+ ,reserve_pub
+ ,purse_pub
+ ,merge_sig
+ ,merge_timestamp)
+ VALUES
+ (my_partner_serial_id
+ ,in_reserve_pub
+ ,in_purse_pub
+ ,in_merge_sig
+ ,in_merge_timestamp)
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: see if an identical record exists.
+ -- Note that by checking 'merge_sig', we implicitly check
+ -- identity over everything that the signature covers.
+ PERFORM
+ FROM purse_merges
+ WHERE purse_pub=in_purse_pub
+ AND merge_sig=in_merge_sig;
+ IF NOT FOUND
+ THEN
+ -- Purse was merged, but to some other reserve. Not allowed.
+ out_conflict=TRUE;
+ RETURN;
+ END IF;
+
+ -- "success"
+ out_conflict=FALSE;
+ RETURN;
+END IF;
+
+
+-- Remember how this purse was finished. This will conflict
+-- if the purse was already decided previously.
+INSERT INTO purse_decision
+ (purse_pub
+ ,action_timestamp
+ ,refunded)
+VALUES
+ (in_purse_pub
+ ,in_merge_timestamp
+ ,FALSE)
+ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Purse was already decided (possibly deleted or merged differently).
+ out_conflict=TRUE;
+ RETURN;
+END IF;
+
+out_conflict=FALSE;
+
+
+
+IF (my_in_reserve_quota)
+THEN
+ UPDATE reserves
+ SET purses_active=purses_active-1
+ WHERE reserve_pub IN
+ (SELECT reserve_pub
+ FROM purse_merges
+ WHERE purse_pub=my_purse_pub
+ LIMIT 1);
+END IF;
+
+-- Store account merge signature.
+INSERT INTO account_merges
+ (reserve_pub
+ ,reserve_sig
+ ,purse_pub
+ ,wallet_h_payto)
+ VALUES
+ (in_reserve_pub
+ ,in_reserve_sig
+ ,in_purse_pub
+ ,in_wallet_h_payto);
+
+-- If we need a wad transfer, mark purse ready for it.
+IF (0 != my_partner_serial_id)
+THEN
+ -- The taler-exchange-router will take care of this.
+ UPDATE purse_actions
+ SET action_date=0 --- "immediately"
+ ,partner_serial_id=my_partner_serial_id
+ WHERE purse_pub=in_purse_pub;
+ELSE
+ -- This is a local reserve, update reserve balance immediately.
+
+ -- Refund the purse fee, by adding it to the purse value:
+ my_amount.val = my_amount.val + my_purse_fee.val;
+ my_amount.frac = my_amount.frac + my_purse_fee.frac;
+ -- normalize result
+ my_amount.val = my_amount.val + my_amount.frac / 100000000;
+ my_amount.frac = my_amount.frac % 100000000;
+
+ SELECT *
+ INTO reserve
+ FROM exchange.reserves
+ WHERE reserve_pub=in_reserve_pub;
+
+ balance = reserve.current_balance;
+ balance.frac=balance.frac+my_amount.frac
+ - CASE
+ WHEN balance.frac + my_amount.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END;
+ balance.val=balance.val+my_amount.val
+ + CASE
+ WHEN balance.frac + my_amount.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END;
+
+ UPDATE exchange.reserves
+ SET current_balance=balance
+ WHERE reserve_pub=in_reserve_pub;
+
+END IF;
+
+RETURN;
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_purse_merge(BYTEA, BYTEA, INT8, BYTEA, TEXT, BYTEA, BYTEA, INT8)
+ IS 'Checks that the partner exists, the purse has not been merged with a different reserve and that the purse is full. If so, persists the merge data and either merges the purse with the reserve or marks it as ready for the taler-exchange-router. Caller MUST abort the transaction on failures so as to not persist data by accident.';
diff --git a/src/exchangedb/exchange_do_recoup_by_reserve.sql b/src/exchangedb/exchange_do_recoup_by_reserve.sql
new file mode 100644
index 000000000..80f953c4a
--- /dev/null
+++ b/src/exchangedb/exchange_do_recoup_by_reserve.sql
@@ -0,0 +1,87 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE OR REPLACE FUNCTION exchange_do_recoup_by_reserve(
+ IN res_pub BYTEA
+)
+RETURNS TABLE
+(
+ denom_sig BYTEA,
+ denominations_serial BIGINT,
+ coin_pub BYTEA,
+ coin_sig BYTEA,
+ coin_blind BYTEA,
+ amount taler_amount,
+ recoup_timestamp BIGINT
+)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ res_uuid BIGINT;
+ blind_ev BYTEA;
+ c_pub BYTEA;
+BEGIN
+ SELECT reserve_uuid
+ INTO res_uuid
+ FROM reserves
+ WHERE reserve_pub = res_pub;
+
+ FOR blind_ev IN
+ SELECT h_blind_ev
+ FROM reserves_out ro
+ JOIN reserve_history rh
+ ON (rh.serial_id = ro.reserve_out_serial_id)
+ WHERE rh.reserve_pub = res_pub
+ AND rh.table_name='reserves_out'
+ LOOP
+ SELECT robr.coin_pub
+ INTO c_pub
+ FROM exchange.recoup_by_reserve robr
+ WHERE robr.reserve_out_serial_id = (
+ SELECT reserve_out_serial_id
+ FROM reserves_out
+ WHERE h_blind_ev = blind_ev
+ );
+ RETURN QUERY
+ SELECT kc.denom_sig,
+ kc.denominations_serial,
+ rc.coin_pub,
+ rc.coin_sig,
+ rc.coin_blind,
+ rc.amount,
+ rc.recoup_timestamp
+ FROM (
+ SELECT denom_sig
+ ,denominations_serial
+ FROM exchange.known_coins
+ WHERE known_coins.coin_pub = c_pub
+ ) kc
+ JOIN (
+ SELECT coin_pub
+ ,coin_sig
+ ,coin_blind
+ ,amount
+ ,recoup_timestamp
+ FROM exchange.recoup
+ WHERE recoup.coin_pub = c_pub
+ ) rc USING (coin_pub);
+ END LOOP;
+END;
+$$;
+
+COMMENT ON FUNCTION exchange_do_recoup_by_reserve
+ IS 'Recoup by reserve as a function to make sure we hit only the needed partition and not all when joining as joins on distributed tables fetch ALL rows from the shards';
diff --git a/src/exchangedb/exchange_do_recoup_to_coin.sql b/src/exchangedb/exchange_do_recoup_to_coin.sql
new file mode 100644
index 000000000..6cecfb7f8
--- /dev/null
+++ b/src/exchangedb/exchange_do_recoup_to_coin.sql
@@ -0,0 +1,135 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+
+
+CREATE OR REPLACE FUNCTION exchange_do_recoup_to_coin(
+ IN in_old_coin_pub BYTEA,
+ IN in_rrc_serial INT8,
+ IN in_coin_blind BYTEA,
+ IN in_coin_pub BYTEA,
+ IN in_known_coin_id INT8,
+ IN in_coin_sig BYTEA,
+ IN in_recoup_timestamp INT8,
+ OUT out_recoup_ok BOOLEAN,
+ OUT out_internal_failure BOOLEAN,
+ OUT out_recoup_timestamp INT8)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ rval RECORD;
+DECLARE
+ tmp taler_amount; -- amount recouped
+BEGIN
+
+-- Shards: UPDATE known_coins (by coin_pub)
+-- SELECT recoup_refresh (by coin_pub)
+-- UPDATE known_coins (by coin_pub)
+-- INSERT recoup_refresh (by coin_pub)
+
+out_internal_failure=FALSE;
+
+-- Check remaining balance of the coin.
+SELECT
+ remaining
+ INTO
+ rval
+FROM exchange.known_coins
+ WHERE coin_pub=in_coin_pub;
+
+IF NOT FOUND
+THEN
+ out_internal_failure=TRUE;
+ out_recoup_ok=FALSE;
+ RETURN;
+END IF;
+
+tmp := rval.remaining;
+
+IF tmp.val + tmp.frac = 0
+THEN
+ -- Check for idempotency
+ SELECT
+ recoup_timestamp
+ INTO
+ out_recoup_timestamp
+ FROM recoup_refresh
+ WHERE coin_pub=in_coin_pub;
+ out_recoup_ok=FOUND;
+ RETURN;
+END IF;
+
+-- Update balance of the coin.
+UPDATE known_coins
+ SET
+ remaining.val = 0
+ ,remaining.frac = 0
+ WHERE coin_pub=in_coin_pub;
+
+-- Credit the old coin.
+UPDATE known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac+tmp.frac
+ - CASE
+ WHEN (kc.remaining).frac+tmp.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val+tmp.val
+ + CASE
+ WHEN (kc.remaining).frac+tmp.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=in_old_coin_pub;
+
+IF NOT FOUND
+THEN
+ RAISE NOTICE 'failed to increase old coin balance from recoup';
+ out_recoup_ok=TRUE;
+ out_internal_failure=TRUE;
+ RETURN;
+END IF;
+
+
+INSERT INTO recoup_refresh
+ (coin_pub
+ ,known_coin_id
+ ,coin_sig
+ ,coin_blind
+ ,amount
+ ,recoup_timestamp
+ ,rrc_serial
+ )
+VALUES
+ (in_coin_pub
+ ,in_known_coin_id
+ ,in_coin_sig
+ ,in_coin_blind
+ ,tmp
+ ,in_recoup_timestamp
+ ,in_rrc_serial);
+
+-- Normal end, everything is fine.
+out_recoup_ok=TRUE;
+out_recoup_timestamp=in_recoup_timestamp;
+
+END $$;
+
+
+-- COMMENT ON FUNCTION exchange_do_recoup_to_coin(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
+-- IS 'Executes a recoup-refresh of a coin that was obtained from a refresh-reveal process';
diff --git a/src/exchangedb/exchange_do_recoup_to_reserve.sql b/src/exchangedb/exchange_do_recoup_to_reserve.sql
new file mode 100644
index 000000000..10ae063bd
--- /dev/null
+++ b/src/exchangedb/exchange_do_recoup_to_reserve.sql
@@ -0,0 +1,150 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE OR REPLACE FUNCTION exchange_do_recoup_to_reserve(
+ IN in_reserve_pub BYTEA,
+ IN in_reserve_out_serial_id INT8,
+ IN in_coin_blind BYTEA,
+ IN in_coin_pub BYTEA,
+ IN in_known_coin_id INT8,
+ IN in_coin_sig BYTEA,
+ IN in_reserve_gc INT8,
+ IN in_reserve_expiration INT8,
+ IN in_recoup_timestamp INT8,
+ OUT out_recoup_ok BOOLEAN,
+ OUT out_internal_failure BOOLEAN,
+ OUT out_recoup_timestamp INT8)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ tmp taler_amount; -- amount recouped
+ balance taler_amount; -- current balance of the reserve
+ new_balance taler_amount; -- new balance of the reserve
+ reserve RECORD;
+ rval RECORD;
+BEGIN
+-- Shards: SELECT known_coins (by coin_pub)
+-- SELECT recoup (by coin_pub)
+-- UPDATE known_coins (by coin_pub)
+-- UPDATE reserves (by reserve_pub)
+-- INSERT recoup (by coin_pub)
+
+out_internal_failure=FALSE;
+
+
+-- Check remaining balance of the coin.
+SELECT
+ remaining
+ INTO
+ rval
+FROM exchange.known_coins
+ WHERE coin_pub=in_coin_pub;
+
+IF NOT FOUND
+THEN
+ out_internal_failure=TRUE;
+ out_recoup_ok=FALSE;
+ RETURN;
+END IF;
+
+tmp := rval.remaining;
+
+IF tmp.val + tmp.frac = 0
+THEN
+ -- Check for idempotency
+ SELECT
+ recoup_timestamp
+ INTO
+ out_recoup_timestamp
+ FROM exchange.recoup
+ WHERE coin_pub=in_coin_pub;
+
+ out_recoup_ok=FOUND;
+ RETURN;
+END IF;
+
+
+-- Update balance of the coin.
+UPDATE known_coins
+ SET
+ remaining.val = 0
+ ,remaining.frac = 0
+ WHERE coin_pub=in_coin_pub;
+
+-- Get current balance
+SELECT current_balance
+ INTO reserve
+ FROM reserves
+ WHERE reserve_pub=in_reserve_pub;
+
+balance = reserve.current_balance;
+new_balance.frac=balance.frac+tmp.frac
+ - CASE
+ WHEN balance.frac+tmp.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END;
+
+new_balance.val=balance.val+tmp.val
+ + CASE
+ WHEN balance.frac+tmp.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END;
+
+-- Credit the reserve and update reserve timers.
+UPDATE reserves
+ SET
+ current_balance = new_balance,
+ gc_date=GREATEST(gc_date, in_reserve_gc),
+ expiration_date=GREATEST(expiration_date, in_reserve_expiration)
+ WHERE reserve_pub=in_reserve_pub;
+
+
+IF NOT FOUND
+THEN
+ RAISE NOTICE 'failed to increase reserve balance from recoup';
+ out_recoup_ok=TRUE;
+ out_internal_failure=TRUE;
+ RETURN;
+END IF;
+
+
+INSERT INTO exchange.recoup
+ (coin_pub
+ ,coin_sig
+ ,coin_blind
+ ,amount
+ ,recoup_timestamp
+ ,reserve_out_serial_id
+ )
+VALUES
+ (in_coin_pub
+ ,in_coin_sig
+ ,in_coin_blind
+ ,tmp
+ ,in_recoup_timestamp
+ ,in_reserve_out_serial_id);
+
+-- Normal end, everything is fine.
+out_recoup_ok=TRUE;
+out_recoup_timestamp=in_recoup_timestamp;
+
+END $$;
+
+-- COMMENT ON FUNCTION exchange_do_recoup_to_reserve(INT8, INT4, BYTEA, BOOLEAN, BOOLEAN)
+-- IS 'Executes a recoup of a coin that was withdrawn from a reserve';
diff --git a/src/exchangedb/exchange_do_refund.sql b/src/exchangedb/exchange_do_refund.sql
new file mode 100644
index 000000000..a95746127
--- /dev/null
+++ b/src/exchangedb/exchange_do_refund.sql
@@ -0,0 +1,205 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_refund(
+ IN in_amount_with_fee taler_amount,
+ IN in_amount taler_amount,
+ IN in_deposit_fee taler_amount,
+ IN in_h_contract_terms BYTEA,
+ IN in_rtransaction_id INT8,
+ IN in_deposit_shard INT8,
+ IN in_known_coin_id INT8,
+ IN in_coin_pub BYTEA,
+ IN in_merchant_pub BYTEA,
+ IN in_merchant_sig BYTEA,
+ OUT out_not_found BOOLEAN,
+ OUT out_refund_ok BOOLEAN,
+ OUT out_gone BOOLEAN,
+ OUT out_conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ bdsi INT8; -- ID of deposit being refunded
+DECLARE
+ tmp_val INT8; -- total amount refunded
+DECLARE
+ tmp_frac INT8; -- total amount refunded, large fraction to deal with overflows!
+DECLARE
+ tmp taler_amount; -- total amount refunded, normalized
+DECLARE
+ deposit taler_amount; -- amount that was originally deposited
+BEGIN
+-- Shards: SELECT deposits (coin_pub, shard, h_contract_terms, merchant_pub)
+-- INSERT refunds (by coin_pub, rtransaction_id) ON CONFLICT DO NOTHING
+-- SELECT refunds (by coin_pub)
+-- UPDATE known_coins (by coin_pub)
+
+SELECT
+ bdep.batch_deposit_serial_id
+ ,(cdep.amount_with_fee).val
+ ,(cdep.amount_with_fee).frac
+ ,bdep.done
+ INTO
+ bdsi
+ ,deposit.val
+ ,deposit.frac
+ ,out_gone
+ FROM batch_deposits bdep
+ JOIN coin_deposits cdep
+ USING (batch_deposit_serial_id)
+ WHERE cdep.coin_pub=in_coin_pub
+ AND shard=in_deposit_shard
+ AND merchant_pub=in_merchant_pub
+ AND h_contract_terms=in_h_contract_terms;
+
+IF NOT FOUND
+THEN
+ -- No matching deposit found!
+ out_refund_ok=FALSE;
+ out_conflict=FALSE;
+ out_not_found=TRUE;
+ out_gone=FALSE;
+ RETURN;
+END IF;
+
+INSERT INTO refunds
+ (batch_deposit_serial_id
+ ,coin_pub
+ ,merchant_sig
+ ,rtransaction_id
+ ,amount_with_fee
+ )
+ VALUES
+ (bdsi
+ ,in_coin_pub
+ ,in_merchant_sig
+ ,in_rtransaction_id
+ ,in_amount_with_fee
+ )
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: see if an identical record exists.
+ -- Note that by checking 'coin_sig', we implicitly check
+ -- identity over everything that the signature covers.
+ -- We do select over merchant_pub and h_contract_terms
+ -- primarily here to maximally use the existing index.
+ PERFORM
+ FROM exchange.refunds
+ WHERE coin_pub=in_coin_pub
+ AND batch_deposit_serial_id=bdsi
+ AND rtransaction_id=in_rtransaction_id
+ AND amount_with_fee=in_amount_with_fee;
+
+ IF NOT FOUND
+ THEN
+ -- Deposit exists, but have conflicting refund.
+ out_refund_ok=FALSE;
+ out_conflict=TRUE;
+ out_not_found=FALSE;
+ RETURN;
+ END IF;
+
+ -- Idempotent request known, return success.
+ out_refund_ok=TRUE;
+ out_conflict=FALSE;
+ out_not_found=FALSE;
+ out_gone=FALSE;
+ RETURN;
+END IF;
+
+IF out_gone
+THEN
+ -- money already sent to the merchant. Tough luck.
+ out_refund_ok=FALSE;
+ out_conflict=FALSE;
+ out_not_found=FALSE;
+ RETURN;
+END IF;
+
+-- Check refund balance invariant.
+SELECT
+ SUM((refs.amount_with_fee).val) -- overflow here is not plausible
+ ,SUM(CAST((refs.amount_with_fee).frac AS INT8)) -- compute using 64 bits
+ INTO
+ tmp_val
+ ,tmp_frac
+ FROM refunds refs
+ WHERE coin_pub=in_coin_pub
+ AND batch_deposit_serial_id=bdsi;
+IF tmp_val IS NULL
+THEN
+ RAISE NOTICE 'failed to sum up existing refunds';
+ out_refund_ok=FALSE;
+ out_conflict=FALSE;
+ out_not_found=FALSE;
+ RETURN;
+END IF;
+
+-- Normalize result before continuing
+tmp.val = tmp_val + tmp_frac / 100000000;
+tmp.frac = tmp_frac % 100000000;
+
+-- Actually check if the deposits are sufficient for the refund. Verbosely. ;-)
+IF (tmp.val < deposit.val)
+THEN
+ out_refund_ok=TRUE;
+ELSE
+ IF (tmp.val = deposit.val) AND (tmp.frac <= deposit.frac)
+ THEN
+ out_refund_ok=TRUE;
+ ELSE
+ out_refund_ok=FALSE;
+ END IF;
+END IF;
+
+IF (tmp.val = deposit.val) AND (tmp.frac = deposit.frac)
+THEN
+ -- Refunds have reached the full value of the original
+ -- deposit. Also refund the deposit fee.
+ in_amount.frac = in_amount.frac + in_deposit_fee.frac;
+ in_amount.val = in_amount.val + in_deposit_fee.val;
+
+ -- Normalize result before continuing
+ in_amount.val = in_amount.val + in_amount.frac / 100000000;
+ in_amount.frac = in_amount.frac % 100000000;
+END IF;
+
+-- Update balance of the coin.
+UPDATE known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac+in_amount.frac
+ - CASE
+ WHEN (kc.remaining).frac+in_amount.frac >= 100000000
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val+in_amount.val
+ + CASE
+ WHEN (kc.remaining).frac+in_amount.frac >= 100000000
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=in_coin_pub;
+
+out_conflict=FALSE;
+out_not_found=FALSE;
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_refund(taler_amount, taler_amount, taler_amount, BYTEA, INT8, INT8, INT8, BYTEA, BYTEA, BYTEA)
+ IS 'Executes a refund operation, checking that the corresponding deposit was sufficient to cover the refunded amount';
diff --git a/src/exchangedb/exchange_do_reserve_open.sql b/src/exchangedb/exchange_do_reserve_open.sql
new file mode 100644
index 000000000..dd7a578ee
--- /dev/null
+++ b/src/exchangedb/exchange_do_reserve_open.sql
@@ -0,0 +1,194 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_reserve_open(
+ IN in_reserve_pub BYTEA,
+ IN in_total_paid taler_amount,
+ IN in_reserve_payment taler_amount,
+ IN in_min_purse_limit INT4,
+ IN in_default_purse_limit INT4,
+ IN in_reserve_sig BYTEA,
+ IN in_desired_expiration INT8,
+ IN in_reserve_gc_delay INT8,
+ IN in_now INT8,
+ IN in_open_fee taler_amount,
+ OUT out_open_cost taler_amount,
+ OUT out_final_expiration INT8,
+ OUT out_no_reserve BOOLEAN,
+ OUT out_no_funds BOOLEAN,
+ OUT out_reserve_balance taler_amount)
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_balance taler_amount;
+ my_cost taler_amount;
+ my_cost_tmp INT8;
+ my_years_tmp INT4;
+ my_years INT4;
+ my_needs_update BOOL;
+ my_expiration_date INT8;
+ reserve RECORD;
+BEGIN
+
+SELECT current_balance
+ ,expiration_date
+ ,purses_allowed
+ INTO reserve
+ FROM reserves
+ WHERE reserve_pub=in_reserve_pub;
+
+IF NOT FOUND
+THEN
+ RAISE NOTICE 'reserve not found';
+ out_no_reserve = TRUE;
+ out_no_funds = TRUE;
+ out_reserve_balance.val = 0;
+ out_reserve_balance.frac = 0;
+ out_open_cost.val = 0;
+ out_open_cost.frac = 0;
+ out_final_expiration = 0;
+ RETURN;
+END IF;
+
+out_no_reserve = FALSE;
+out_reserve_balance = reserve.current_balance;
+
+-- Do not allow expiration time to start in the past already
+IF (reserve.expiration_date < in_now)
+THEN
+ my_expiration_date = in_now;
+ELSE
+ my_expiration_date = reserve.expiration_date;
+END IF;
+
+my_cost.val = 0;
+my_cost.frac = 0;
+my_needs_update = FALSE;
+my_years = 0;
+
+-- Compute years based on desired expiration time
+IF (my_expiration_date < in_desired_expiration)
+THEN
+ my_years = (31535999999999 + in_desired_expiration - my_expiration_date) / 31536000000000;
+ reserve.purses_allowed = in_default_purse_limit;
+ my_expiration_date = my_expiration_date + 31536000000000 * my_years;
+END IF;
+
+-- Increase years based on purses requested
+IF (reserve.purses_allowed < in_min_purse_limit)
+THEN
+ my_years = (31535999999999 + in_desired_expiration - in_now) / 31536000000000;
+ my_expiration_date = in_now + 31536000000000 * my_years;
+ my_years_tmp = (in_min_purse_limit + in_default_purse_limit - reserve.purses_allowed - 1) / in_default_purse_limit;
+ my_years = my_years + my_years_tmp;
+ reserve.purses_allowed = reserve.purses_allowed + (in_default_purse_limit * my_years_tmp);
+END IF;
+
+
+-- Compute cost based on annual fees
+IF (my_years > 0)
+THEN
+ my_cost.val = my_years * in_open_fee.val;
+ my_cost_tmp = my_years * in_open_fee.frac / 100000000;
+ IF (CAST (my_cost.val + my_cost_tmp AS INT8) < my_cost.val)
+ THEN
+ out_open_cost.val=9223372036854775807;
+ out_open_cost.frac=2147483647;
+ out_final_expiration=my_expiration_date;
+ out_no_funds=FALSE;
+ RAISE NOTICE 'arithmetic issue computing amount';
+ RETURN;
+ END IF;
+ my_cost.val = CAST (my_cost.val + my_cost_tmp AS INT8);
+ my_cost.frac = my_years * in_open_fee.frac % 100000000;
+ my_needs_update = TRUE;
+END IF;
+
+-- check if we actually have something to do
+IF NOT my_needs_update
+THEN
+ out_final_expiration = reserve.expiration_date;
+ out_open_cost.val = 0;
+ out_open_cost.frac = 0;
+ out_no_funds=FALSE;
+ RAISE NOTICE 'no change required';
+ RETURN;
+END IF;
+
+-- Check payment (coins and reserve) would be sufficient.
+IF ( (in_total_paid.val < my_cost.val) OR
+ ( (in_total_paid.val = my_cost.val) AND
+ (in_total_paid.frac < my_cost.frac) ) )
+THEN
+ out_open_cost.val = my_cost.val;
+ out_open_cost.frac = my_cost.frac;
+ out_no_funds=FALSE;
+ -- We must return a failure, which is indicated by
+ -- the expiration being below the desired expiration.
+ IF (reserve.expiration_date >= in_desired_expiration)
+ THEN
+ -- This case is relevant especially if the purse
+ -- count was to be increased and the payment was
+ -- insufficient to cover this for the full period.
+ RAISE NOTICE 'forcing low expiration time';
+ out_final_expiration = 0;
+ ELSE
+ out_final_expiration = reserve.expiration_date;
+ END IF;
+ RAISE NOTICE 'amount paid too low';
+ RETURN;
+END IF;
+
+-- Check reserve balance is sufficient.
+IF (out_reserve_balance.val > in_reserve_payment.val)
+THEN
+ IF (out_reserve_balance.frac >= in_reserve_payment.frac)
+ THEN
+ my_balance.val=out_reserve_balance.val - in_reserve_payment.val;
+ my_balance.frac=out_reserve_balance.frac - in_reserve_payment.frac;
+ ELSE
+ my_balance.val=out_reserve_balance.val - in_reserve_payment.val - 1;
+ my_balance.frac=out_reserve_balance.frac + 100000000 - in_reserve_payment.frac;
+ END IF;
+ELSE
+ IF (out_reserve_balance.val = in_reserve_payment.val) AND (out_reserve_balance.frac >= in_reserve_payment.frac)
+ THEN
+ my_balance.val=0;
+ my_balance.frac=out_reserve_balance.frac - in_reserve_payment.frac;
+ ELSE
+ out_final_expiration = reserve.expiration_date;
+ out_open_cost.val = my_cost.val;
+ out_open_cost.frac = my_cost.frac;
+ out_no_funds=TRUE;
+ RAISE NOTICE 'reserve balance too low';
+ RETURN;
+ END IF;
+END IF;
+
+UPDATE reserves SET
+ current_balance=my_balance
+ ,gc_date=reserve.expiration_date + in_reserve_gc_delay
+ ,expiration_date=my_expiration_date
+ ,purses_allowed=reserve.purses_allowed
+WHERE
+ reserve_pub=in_reserve_pub;
+
+out_final_expiration=my_expiration_date;
+out_open_cost = my_cost;
+out_no_funds=FALSE;
+RETURN;
+
+END $$;
diff --git a/src/exchangedb/exchange_do_reserve_open_deposit.sql b/src/exchangedb/exchange_do_reserve_open_deposit.sql
new file mode 100644
index 000000000..aa6f86a9b
--- /dev/null
+++ b/src/exchangedb/exchange_do_reserve_open_deposit.sql
@@ -0,0 +1,84 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE OR REPLACE FUNCTION exchange_do_reserve_open_deposit(
+ IN in_coin_pub BYTEA,
+ IN in_known_coin_id INT8,
+ IN in_coin_sig BYTEA,
+ IN in_reserve_sig BYTEA,
+ IN in_reserve_pub BYTEA,
+ IN in_coin_total taler_amount,
+ OUT out_insufficient_funds BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+
+INSERT INTO exchange.reserves_open_deposits
+ (reserve_sig
+ ,reserve_pub
+ ,coin_pub
+ ,coin_sig
+ ,contribution
+ )
+ VALUES
+ (in_reserve_sig
+ ,in_reserve_pub
+ ,in_coin_pub
+ ,in_coin_sig
+ ,in_coin_total
+ )
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotent request known, return success.
+ out_insufficient_funds=FALSE;
+ RETURN;
+END IF;
+
+
+-- Check and update balance of the coin.
+UPDATE exchange.known_coins kc
+ SET
+ remaining.frac=(kc.remaining).frac-in_coin_total.frac
+ + CASE
+ WHEN (kc.remaining).frac < in_coin_total.frac
+ THEN 100000000
+ ELSE 0
+ END,
+ remaining.val=(kc.remaining).val-in_coin_total.val
+ - CASE
+ WHEN (kc.remaining).frac < in_coin_total.frac
+ THEN 1
+ ELSE 0
+ END
+ WHERE coin_pub=in_coin_pub
+ AND ( ((kc.remaining).val > in_coin_total.val) OR
+ ( ((kc.remaining).frac >= in_coin_total.frac) AND
+ ((kc.remaining).val >= in_coin_total.val) ) );
+
+IF NOT FOUND
+THEN
+ -- Insufficient balance.
+ out_insufficient_funds=TRUE;
+ RETURN;
+END IF;
+
+-- Everything fine, return success!
+out_insufficient_funds=FALSE;
+
+END $$;
diff --git a/src/exchangedb/exchange_do_reserve_purse.sql b/src/exchangedb/exchange_do_reserve_purse.sql
new file mode 100644
index 000000000..8ae652e69
--- /dev/null
+++ b/src/exchangedb/exchange_do_reserve_purse.sql
@@ -0,0 +1,162 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+CREATE OR REPLACE FUNCTION exchange_do_reserve_purse(
+ IN in_purse_pub BYTEA,
+ IN in_merge_sig BYTEA,
+ IN in_merge_timestamp INT8,
+ IN in_reserve_expiration INT8,
+ IN in_reserve_gc INT8,
+ IN in_reserve_sig BYTEA,
+ IN in_reserve_quota BOOLEAN,
+ IN in_purse_fee taler_amount,
+ IN in_reserve_pub BYTEA,
+ IN in_wallet_h_payto BYTEA,
+ OUT out_no_funds BOOLEAN,
+ OUT out_no_reserve BOOLEAN,
+ OUT out_conflict BOOLEAN)
+LANGUAGE plpgsql
+AS $$
+BEGIN
+
+-- Store purse merge signature, checks for purse_pub uniqueness
+INSERT INTO purse_merges
+ (partner_serial_id
+ ,reserve_pub
+ ,purse_pub
+ ,merge_sig
+ ,merge_timestamp)
+ VALUES
+ (NULL
+ ,in_reserve_pub
+ ,in_purse_pub
+ ,in_merge_sig
+ ,in_merge_timestamp)
+ ON CONFLICT DO NOTHING;
+
+IF NOT FOUND
+THEN
+ -- Idempotency check: see if an identical record exists.
+ -- Note that by checking 'merge_sig', we implicitly check
+ -- identity over everything that the signature covers.
+ PERFORM
+ FROM purse_merges
+ WHERE purse_pub=in_purse_pub
+ AND merge_sig=in_merge_sig;
+ IF NOT FOUND
+ THEN
+ -- Purse was merged, but to some other reserve. Not allowed.
+ out_conflict=TRUE;
+ out_no_reserve=FALSE;
+ out_no_funds=FALSE;
+ RETURN;
+ END IF;
+
+ -- "success"
+ out_conflict=FALSE;
+ out_no_funds=FALSE;
+ out_no_reserve=FALSE;
+ RETURN;
+END IF;
+out_conflict=FALSE;
+
+PERFORM
+ FROM exchange.reserves
+ WHERE reserve_pub=in_reserve_pub;
+
+out_no_reserve = NOT FOUND;
+
+IF (in_reserve_quota)
+THEN
+ -- Increment active purses per reserve (and check this is allowed)
+ IF (out_no_reserve)
+ THEN
+ out_no_funds=TRUE;
+ RETURN;
+ END IF;
+ UPDATE exchange.reserves
+ SET purses_active=purses_active+1
+ WHERE reserve_pub=in_reserve_pub
+ AND purses_active < purses_allowed;
+ IF NOT FOUND
+ THEN
+ out_no_funds=TRUE;
+ RETURN;
+ END IF;
+ELSE
+ -- UPDATE reserves balance (and check if balance is enough to pay the fee)
+ IF (out_no_reserve)
+ THEN
+ IF ( (0 != in_purse_fee.val) OR
+ (0 != in_purse_fee.frac) )
+ THEN
+ out_no_funds=TRUE;
+ RETURN;
+ END IF;
+ INSERT INTO exchange.reserves
+ (reserve_pub
+ ,expiration_date
+ ,gc_date)
+ VALUES
+ (in_reserve_pub
+ ,in_reserve_expiration
+ ,in_reserve_gc);
+ ELSE
+ UPDATE exchange.reserves
+ SET
+ current_balance.frac=(current_balance).frac-in_purse_fee.frac
+ + CASE
+ WHEN (current_balance).frac < in_purse_fee.frac
+ THEN 100000000
+ ELSE 0
+ END,
+ current_balance.val=(current_balance).val-in_purse_fee.val
+ - CASE
+ WHEN (current_balance).frac < in_purse_fee.frac
+ THEN 1
+ ELSE 0
+ END
+ WHERE reserve_pub=in_reserve_pub
+ AND ( ((current_balance).val > in_purse_fee.val) OR
+ ( ((current_balance).frac >= in_purse_fee.frac) AND
+ ((current_balance).val >= in_purse_fee.val) ) );
+ IF NOT FOUND
+ THEN
+ out_no_funds=TRUE;
+ RETURN;
+ END IF;
+ END IF;
+END IF;
+
+out_no_funds=FALSE;
+
+
+-- Store account merge signature.
+INSERT INTO account_merges
+ (reserve_pub
+ ,reserve_sig
+ ,purse_pub
+ ,wallet_h_payto)
+ VALUES
+ (in_reserve_pub
+ ,in_reserve_sig
+ ,in_purse_pub
+ ,in_wallet_h_payto);
+
+END $$;
+
+COMMENT ON FUNCTION exchange_do_reserve_purse(BYTEA, BYTEA, INT8, INT8, INT8, BYTEA, BOOLEAN, taler_amount, BYTEA, BYTEA)
+ IS 'Create a purse for a reserve.';
diff --git a/src/exchangedb/exchange_do_reserves_in_insert.sql b/src/exchangedb/exchange_do_reserves_in_insert.sql
new file mode 100644
index 000000000..1be06f063
--- /dev/null
+++ b/src/exchangedb/exchange_do_reserves_in_insert.sql
@@ -0,0 +1,122 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+
+CREATE OR REPLACE FUNCTION exchange_do_array_reserves_insert(
+ IN in_gc_date INT8,
+ IN in_reserve_expiration INT8,
+ IN ina_reserve_pub BYTEA[],
+ IN ina_wire_ref INT8[],
+ IN ina_credit taler_amount[],
+ IN ina_exchange_account_name TEXT[],
+ IN ina_execution_date INT8[],
+ IN ina_wire_source_h_payto BYTEA[],
+ IN ina_payto_uri TEXT[],
+ IN ina_notify TEXT[])
+RETURNS SETOF exchange_do_array_reserve_insert_return_type
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ conflict BOOL;
+ dup BOOL;
+ uuid INT8;
+ i INT4;
+ ini_reserve_pub BYTEA;
+ ini_wire_ref INT8;
+ ini_credit taler_amount;
+ ini_exchange_account_name TEXT;
+ ini_execution_date INT8;
+ ini_wire_source_h_payto BYTEA;
+ ini_payto_uri TEXT;
+ ini_notify TEXT;
+BEGIN
+
+ FOR i IN 1..array_length(ina_reserve_pub,1)
+ LOOP
+ ini_reserve_pub = ina_reserve_pub[i];
+ ini_wire_ref = ina_wire_ref[i];
+ ini_credit = ina_credit[i];
+ ini_exchange_account_name = ina_exchange_account_name[i];
+ ini_execution_date = ina_execution_date[i];
+ ini_wire_source_h_payto = ina_wire_source_h_payto[i];
+ ini_payto_uri = ina_payto_uri[i];
+ ini_notify = ina_notify[i];
+
+-- RAISE WARNING 'Starting loop on %', ini_notify;
+
+ INSERT INTO wire_targets
+ (wire_target_h_payto
+ ,payto_uri
+ ) VALUES (
+ ini_wire_source_h_payto
+ ,ini_payto_uri
+ )
+ ON CONFLICT DO NOTHING;
+
+ INSERT INTO reserves
+ (reserve_pub
+ ,current_balance
+ ,expiration_date
+ ,gc_date
+ ) VALUES (
+ ini_reserve_pub
+ ,ini_credit
+ ,in_reserve_expiration
+ ,in_gc_date
+ )
+ ON CONFLICT DO NOTHING
+ RETURNING reserve_uuid
+ INTO uuid;
+ conflict = NOT FOUND;
+
+ INSERT INTO reserves_in
+ (reserve_pub
+ ,wire_reference
+ ,credit
+ ,exchange_account_section
+ ,wire_source_h_payto
+ ,execution_date
+ ) VALUES (
+ ini_reserve_pub
+ ,ini_wire_ref
+ ,ini_credit
+ ,ini_exchange_account_name
+ ,ini_wire_source_h_payto
+ ,ini_execution_date
+ )
+ ON CONFLICT DO NOTHING;
+
+ IF NOT FOUND
+ THEN
+ IF conflict
+ THEN
+ dup = TRUE;
+ else
+ dup = FALSE;
+ END IF;
+ ELSE
+ IF NOT conflict
+ THEN
+ EXECUTE FORMAT (
+ 'NOTIFY %s'
+ ,ini_notify);
+ END IF;
+ dup = FALSE;
+ END IF;
+ RETURN NEXT (dup,uuid);
+ END LOOP;
+ RETURN;
+END $$;
diff --git a/src/exchangedb/exchange_do_select_deposits_missing_wire.sql b/src/exchangedb/exchange_do_select_deposits_missing_wire.sql
new file mode 100644
index 000000000..3d44a58c9
--- /dev/null
+++ b/src/exchangedb/exchange_do_select_deposits_missing_wire.sql
@@ -0,0 +1,73 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author: Christian Grothoff
+
+CREATE OR REPLACE FUNCTION exchange_do_select_deposits_missing_wire(
+ IN in_min_serial_id INT8)
+RETURNS SETOF exchange_do_select_deposits_missing_wire_return_type
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ missing CURSOR
+ FOR
+ SELECT
+ batch_deposit_serial_id
+ ,wire_target_h_payto
+ ,wire_deadline
+ FROM batch_deposits
+ WHERE batch_deposit_serial_id > in_min_serial_id
+ ORDER BY batch_deposit_serial_id ASC;
+DECLARE
+ my_total_val INT8; -- all deposits without wire
+DECLARE
+ my_total_frac INT8; -- all deposits without wire (fraction, not normalized)
+DECLARE
+ my_total taler_amount; -- amount that was originally deposited
+DECLARE
+ my_batch_record RECORD;
+DECLARE
+ i RECORD;
+BEGIN
+
+OPEN missing;
+LOOP
+ FETCH NEXT FROM missing INTO i;
+ EXIT WHEN NOT FOUND;
+
+ SELECT
+ SUM((cdep.amount_with_fee).val) AS total_val
+ ,SUM((cdep.amount_with_fee).frac::INT8) AS total_frac
+ INTO
+ my_batch_record
+ FROM coin_deposits cdep
+ WHERE cdep.batch_deposit_serial_id = i.batch_deposit_serial_id;
+
+ my_total_val=my_batch_record.total_val;
+ my_total_frac=my_batch_record.total_frac;
+
+ -- Normalize total amount
+ my_total.val = my_total_val + my_total_frac / 100000000;
+ my_total.frac = my_total_frac % 100000000;
+ RETURN NEXT (
+ i.batch_deposit_serial_id
+ ,my_total
+ ,i.wire_target_h_payto
+ ,i.wire_deadline);
+
+END LOOP;
+CLOSE missing;
+RETURN;
+END $$;
diff --git a/src/exchangedb/exchange_do_select_justification_for_missing_wire.sql b/src/exchangedb/exchange_do_select_justification_for_missing_wire.sql
new file mode 100644
index 000000000..f02a51d3d
--- /dev/null
+++ b/src/exchangedb/exchange_do_select_justification_for_missing_wire.sql
@@ -0,0 +1,102 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2023 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+-- @author: Christian Grothoff
+
+CREATE OR REPLACE FUNCTION exchange_do_select_justification_missing_wire(
+ IN in_wire_target_h_payto BYTEA,
+ IN in_current_time INT8,
+ OUT out_payto_uri TEXT, -- NULL allowed
+ OUT out_kyc_pending TEXT, -- NULL allowed
+ OUT out_aml_status INT4, -- NULL allowed
+ OUT out_aml_limit taler_amount) -- NULL allowed!
+LANGUAGE plpgsql
+AS $$
+DECLARE
+ my_required_checks TEXT[];
+DECLARE
+ my_aml_data RECORD;
+DECLARE
+ satisfied CURSOR FOR
+ SELECT satisfied_checks
+ FROM kyc_attributes
+ WHERE h_payto=in_wire_target_h_payto
+ AND expiration_time < in_current_time;
+DECLARE
+ i RECORD;
+BEGIN
+
+ -- Fetch payto URI
+ out_payto_uri = NULL;
+ SELECT payto_uri
+ INTO out_payto_uri
+ FROM wire_targets
+ WHERE wire_target_h_payto=my_wire_target_h_payto;
+
+ -- Check KYC status
+ my_required_checks = NULL;
+ SELECT string_to_array (required_checks, ' ')
+ INTO my_required_checks
+ FROM legitimization_requirements
+ WHERE h_payto=my_wire_target_h_payto;
+
+ -- Get last AML decision
+ SELECT
+ new_threshold
+ ,kyc_requirements
+ ,new_status
+ INTO
+ my_aml_data
+ FROM aml_history
+ WHERE h_payto=in_wire_target_h_payto
+ ORDER BY aml_history_serial_id -- get last decision
+ DESC LIMIT 1;
+ IF FOUND
+ THEN
+ out_aml_limit=my_aml_data.new_threshold;
+ out_aml_status=my_aml_data.kyc_status;
+ -- Combine KYC requirements
+ my_required_checks
+ = array_cat (my_required_checks,
+ my_aml_data.kyc_requirements);
+ ELSE
+ out_aml_limit=NULL;
+ out_aml_status=0; -- or NULL? Style question!
+ END IF;
+
+ OPEN satisfied;
+ LOOP
+ FETCH NEXT FROM satisfied INTO i;
+ EXIT WHEN NOT FOUND;
+
+ -- remove all satisfied checks from the list
+ FOR i in 1..array_length(i.satisfied_checks)
+ LOOP
+ my_required_checks
+ = array_remove (my_required_checks,
+ i.satisfied_checks[i]);
+ END LOOP;
+ END LOOP;
+
+ -- Return remaining required checks as one string
+ IF ( (my_required_checks IS NOT NULL) AND
+ (0 < array_length(my_satisfied_checks)) )
+ THEN
+ out_kyc_pending
+ = array_to_string (my_required_checks, ' ');
+ END IF;
+
+ RETURN;
+END $$;
diff --git a/src/exchangedb/exchangedb-postgres.conf b/src/exchangedb/exchangedb-postgres.conf
index 7d600586f..726d28576 100644
--- a/src/exchangedb/exchangedb-postgres.conf
+++ b/src/exchangedb/exchangedb-postgres.conf
@@ -1,6 +1,9 @@
[exchangedb-postgres]
-CONFIG = "postgres:///taler"
+CONFIG = "postgres:///taler-exchange"
# Where are the SQL files to setup our tables?
# Important: this MUST end with a "/"!
-SQL_DIR = $DATADIR/sql/exchange/
+SQL_DIR = ${DATADIR}sql/exchange/
+
+# Number of purses per account by default.
+DEFAULT_PURSE_LIMIT = 1 \ No newline at end of file
diff --git a/src/exchangedb/exchangedb.conf b/src/exchangedb/exchangedb.conf
index 1c22301ad..2bfcb2ca0 100644
--- a/src/exchangedb/exchangedb.conf
+++ b/src/exchangedb/exchangedb.conf
@@ -30,3 +30,7 @@ LEGAL_RESERVE_EXPIRATION_TIME = 7 years
# What is the desired delay between a transaction being ready and the
# aggregator triggering on it?
AGGREGATOR_SHIFT = 1 s
+
+# How many concurrent purses may be opened by a reserve
+# if the reserve is paid for a year?
+DEFAULT_PURSE_LIMIT = 1 \ No newline at end of file
diff --git a/src/exchangedb/exchangedb_accounts.c b/src/exchangedb/exchangedb_accounts.c
index e41074822..e668134e1 100644
--- a/src/exchangedb/exchangedb_accounts.c
+++ b/src/exchangedb/exchangedb_accounts.c
@@ -199,7 +199,6 @@ add_account_cb (void *cls,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
section,
"PAYTO_URI");
- lc->res = GNUNET_SYSERR;
return;
}
method = TALER_payto_get_method (payto_uri);
diff --git a/src/exchangedb/exchangedb_transactions.c b/src/exchangedb/exchangedb_transactions.c
index ef46bace6..f78393776 100644
--- a/src/exchangedb/exchangedb_transactions.c
+++ b/src/exchangedb/exchangedb_transactions.c
@@ -131,6 +131,37 @@ TALER_EXCHANGEDB_calculate_transaction_list_totals (
}
deposit_fee = pos->details.purse_deposit->deposit_fee;
break;
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ /* refunded += pos->refund_amount - pos->refund_fee */
+ if (0 >
+ TALER_amount_add (&refunded,
+ &refunded,
+ &pos->details.purse_refund->refund_amount))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 >
+ TALER_amount_add (&spent,
+ &spent,
+ &pos->details.purse_refund->refund_fee))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ have_refund = true;
+ break;
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ /* spent += pos->amount_with_fee */
+ if (0 >
+ TALER_amount_add (&spent,
+ &spent,
+ &pos->details.reserve_open->coin_contribution))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ break;
}
}
if (have_refund)
diff --git a/src/exchangedb/irbt_callbacks.c b/src/exchangedb/irbt_callbacks.c
deleted file mode 100644
index 250b167ef..000000000
--- a/src/exchangedb/irbt_callbacks.c
+++ /dev/null
@@ -1,1134 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2020, 2021, 2022 Taler Systems SA
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-/**
- * @file exchangedb/irbt_callbacks.c
- * @brief callbacks used by postgres_insert_records_by_table, to be
- * inlined into the plugin
- * @author Christian Grothoff
- */
-
-
-/**
- * Function called with denominations records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_denominations (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct TALER_DenominationHashP denom_hash;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&denom_hash),
- GNUNET_PQ_query_param_uint32 (
- &td->details.denominations.denom_type),
- GNUNET_PQ_query_param_uint32 (
- &td->details.denominations.age_mask),
- TALER_PQ_query_param_denom_pub (
- &td->details.denominations.denom_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.denominations.master_sig),
- GNUNET_PQ_query_param_timestamp (
- &td->details.denominations.valid_from),
- GNUNET_PQ_query_param_timestamp (
- &td->details.denominations.expire_withdraw),
- GNUNET_PQ_query_param_timestamp (
- &td->details.denominations.expire_deposit),
- GNUNET_PQ_query_param_timestamp (
- &td->details.denominations.expire_legal),
- TALER_PQ_query_param_amount (&td->details.denominations.coin),
- TALER_PQ_query_param_amount (
- &td->details.denominations.fees.withdraw),
- TALER_PQ_query_param_amount (
- &td->details.denominations.fees.deposit),
- TALER_PQ_query_param_amount (
- &td->details.denominations.fees.refresh),
- TALER_PQ_query_param_amount (
- &td->details.denominations.fees.refund),
- GNUNET_PQ_query_param_end
- };
-
- TALER_denom_pub_hash (
- &td->details.denominations.denom_pub,
- &denom_hash);
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_denominations",
- params);
-}
-
-
-/**
- * Function called with denomination_revocations records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_denomination_revocations (
- struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.denomination_revocations.master_sig),
- GNUNET_PQ_query_param_uint64 (
- &td->details.denomination_revocations.denominations_serial),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_denomination_revocations",
- params);
-}
-
-
-/**
- * Function called with denominations records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wire_targets (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct TALER_PaytoHashP payto_hash;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&payto_hash),
- GNUNET_PQ_query_param_string (
- td->details.wire_targets.payto_uri),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wire_targets.kyc_ok),
- NULL == td->details.wire_targets.external_id
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (
- td->details.wire_targets.external_id),
- GNUNET_PQ_query_param_end
- };
-
- TALER_payto_hash (
- td->details.wire_targets.payto_uri,
- &payto_hash);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wire_targets",
- params);
-}
-
-
-/**
- * Function called with reserves records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_reserves (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.reserves.reserve_pub),
- GNUNET_PQ_query_param_timestamp (&td->details.reserves.expiration_date),
- GNUNET_PQ_query_param_timestamp (&td->details.reserves.gc_date),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves",
- params);
-}
-
-
-/**
- * Function called with reserves_in records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_reserves_in (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference),
- TALER_PQ_query_param_amount (&td->details.reserves_in.credit),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_in.sender_account_h_payto),
- GNUNET_PQ_query_param_string (
- td->details.reserves_in.exchange_account_section),
- GNUNET_PQ_query_param_timestamp (
- &td->details.reserves_in.execution_date),
- GNUNET_PQ_query_param_auto_from_type (&td->details.reserves_in.reserve_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_in",
- params);
-}
-
-
-/**
- * Function called with reserves_close records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_reserves_close (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_timestamp (
- &td->details.reserves_close.execution_date),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_close.wtid),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_close.sender_account_h_payto),
- TALER_PQ_query_param_amount (&td->details.reserves_close.amount),
- TALER_PQ_query_param_amount (&td->details.reserves_close.closing_fee),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_close.reserve_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_close",
- params);
-}
-
-
-/**
- * Function called with reserves_out records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_reserves_out (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_out.h_blind_ev),
- GNUNET_PQ_query_param_uint64 (
- &td->details.reserves_out.denominations_serial),
- TALER_PQ_query_param_blinded_denom_sig (
- &td->details.reserves_out.denom_sig),
- GNUNET_PQ_query_param_uint64 (
- &td->details.reserves_out.reserve_uuid),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.reserves_out.reserve_sig),
- GNUNET_PQ_query_param_timestamp (
- &td->details.reserves_out.execution_date),
- TALER_PQ_query_param_amount (
- &td->details.reserves_out.amount_with_fee),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_reserves_out",
- params);
-}
-
-
-/**
- * Function called with auditors records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_auditors (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.auditors.auditor_pub),
- GNUNET_PQ_query_param_string (td->details.auditors.auditor_name),
- GNUNET_PQ_query_param_string (td->details.auditors.auditor_url),
- GNUNET_PQ_query_param_bool (&td->details.auditors.is_active),
- GNUNET_PQ_query_param_timestamp (&td->details.auditors.last_change),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_auditors",
- params);
-}
-
-
-/**
- * Function called with auditor_denom_sigs records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (&td->details.auditor_denom_sigs.auditor_uuid),
- GNUNET_PQ_query_param_uint64 (
- &td->details.auditor_denom_sigs.denominations_serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.auditor_denom_sigs.auditor_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_auditor_denom_sigs",
- params);
-}
-
-
-/**
- * Function called with exchange_sign_keys records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.exchange_sign_keys.exchange_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.exchange_sign_keys.master_sig),
- GNUNET_PQ_query_param_timestamp (
- &td->details.exchange_sign_keys.meta.start),
- GNUNET_PQ_query_param_timestamp (
- &td->details.exchange_sign_keys.meta.expire_sign),
- GNUNET_PQ_query_param_timestamp (
- &td->details.exchange_sign_keys.meta.expire_legal),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_exchange_sign_keys",
- params);
-}
-
-
-/**
- * Function called with signkey_revocations records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_signkey_revocations (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (&td->details.signkey_revocations.esk_serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.signkey_revocations.master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_signkey_revocations",
- params);
-}
-
-
-/**
- * Function called with known_coins records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_known_coins (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.known_coins.coin_pub),
- TALER_PQ_query_param_denom_sig (
- &td->details.known_coins.denom_sig),
- GNUNET_PQ_query_param_uint64 (
- &td->details.known_coins.denominations_serial),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_known_coins",
- params);
-}
-
-
-/**
- * Function called with refresh_commitments records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_refresh_commitments (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.refresh_commitments.rc),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.refresh_commitments.old_coin_sig),
- TALER_PQ_query_param_amount (
- &td->details.refresh_commitments.amount_with_fee),
- GNUNET_PQ_query_param_uint32 (
- &td->details.refresh_commitments.noreveal_index),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.refresh_commitments.old_coin_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refresh_commitments",
- params);
-}
-
-
-/**
- * Function called with refresh_revealed_coins records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_refresh_revealed_coins (
- struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_HashCode h_coin_ev;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint32 (
- &td->details.refresh_revealed_coins.freshcoin_index),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.refresh_revealed_coins.link_sig),
- GNUNET_PQ_query_param_fixed_size (
- td->details.refresh_revealed_coins.coin_ev,
- td->details.refresh_revealed_coins.
- coin_ev_size),
- GNUNET_PQ_query_param_auto_from_type (&h_coin_ev),
- TALER_PQ_query_param_blinded_denom_sig (
- &td->details.refresh_revealed_coins.ev_sig),
- TALER_PQ_query_param_exchange_withdraw_values (
- &td->details.refresh_revealed_coins.ewv),
- GNUNET_PQ_query_param_uint64 (
- &td->details.refresh_revealed_coins.denominations_serial),
- GNUNET_PQ_query_param_uint64 (
- &td->details.refresh_revealed_coins.melt_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_CRYPTO_hash (td->details.refresh_revealed_coins.coin_ev,
- td->details.refresh_revealed_coins.coin_ev_size,
- &h_coin_ev);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refresh_revealed_coins",
- params);
-}
-
-
-/**
- * Function called with refresh_transfer_keys records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_refresh_transfer_keys (
- struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.refresh_transfer_keys.tp),
- GNUNET_PQ_query_param_fixed_size (
- &td->details.refresh_transfer_keys.tprivs[0],
- (TALER_CNC_KAPPA - 1)
- * sizeof (struct TALER_TransferPrivateKeyP)),
- GNUNET_PQ_query_param_uint64 (
- &td->details.refresh_transfer_keys.melt_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refresh_transfer_keys",
- params);
-}
-
-
-/**
- * Function called with deposits records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_deposits (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (&td->details.deposits.shard),
- GNUNET_PQ_query_param_uint64 (&td->details.deposits.known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.deposits.coin_pub),
- TALER_PQ_query_param_amount (&td->details.deposits.amount_with_fee),
- GNUNET_PQ_query_param_timestamp (&td->details.deposits.wallet_timestamp),
- GNUNET_PQ_query_param_timestamp (
- &td->details.deposits.exchange_timestamp),
- GNUNET_PQ_query_param_timestamp (&td->details.deposits.refund_deadline),
- GNUNET_PQ_query_param_timestamp (&td->details.deposits.wire_deadline),
- GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.deposits.h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.coin_sig),
- GNUNET_PQ_query_param_auto_from_type (&td->details.deposits.wire_salt),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.deposits.wire_target_h_payto),
- GNUNET_PQ_query_param_bool (td->details.deposits.extension_blocked),
- 0 == td->details.deposits.extension_details_serial_id
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_uint64 (
- &td->details.deposits.extension_details_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_deposits",
- params);
-}
-
-
-/**
- * Function called with refunds records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_refunds (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.merchant_sig),
- GNUNET_PQ_query_param_uint64 (&td->details.refunds.rtransaction_id),
- TALER_PQ_query_param_amount (&td->details.refunds.amount_with_fee),
- GNUNET_PQ_query_param_uint64 (&td->details.refunds.deposit_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_refunds",
- params);
-}
-
-
-/**
- * Function called with wire_out records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wire_out (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_timestamp (&td->details.wire_out.execution_date),
- GNUNET_PQ_query_param_auto_from_type (&td->details.wire_out.wtid_raw),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wire_out.wire_target_h_payto),
- GNUNET_PQ_query_param_string (
- td->details.wire_out.exchange_account_section),
- TALER_PQ_query_param_amount (&td->details.wire_out.amount),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wire_out",
- params);
-}
-
-
-/**
- * Function called with aggregation_tracking records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (
- &td->details.aggregation_tracking.deposit_serial_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.aggregation_tracking.wtid_raw),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_aggregation_tracking",
- params);
-}
-
-
-/**
- * Function called with wire_fee records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wire_fee (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_string (td->details.wire_fee.wire_method),
- GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.start_date),
- GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.end_date),
- TALER_PQ_query_param_amount (&td->details.wire_fee.fees.wire),
- TALER_PQ_query_param_amount (&td->details.wire_fee.fees.closing),
- TALER_PQ_query_param_amount (&td->details.wire_fee.fees.wad),
- GNUNET_PQ_query_param_auto_from_type (&td->details.wire_fee.master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wire_fee",
- params);
-}
-
-
-/**
- * Function called with wire_fee records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_global_fee (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (
- &td->serial),
- GNUNET_PQ_query_param_timestamp (
- &td->details.global_fee.start_date),
- GNUNET_PQ_query_param_timestamp (
- &td->details.global_fee.end_date),
- TALER_PQ_query_param_amount (
- &td->details.global_fee.fees.history),
- TALER_PQ_query_param_amount (
- &td->details.global_fee.fees.kyc),
- TALER_PQ_query_param_amount (
- &td->details.global_fee.fees.account),
- TALER_PQ_query_param_amount (
- &td->details.global_fee.fees.purse),
- GNUNET_PQ_query_param_relative_time (
- &td->details.global_fee.purse_timeout),
- GNUNET_PQ_query_param_relative_time (
- &td->details.global_fee.kyc_timeout),
- GNUNET_PQ_query_param_relative_time (
- &td->details.global_fee.history_expiration),
- GNUNET_PQ_query_param_uint32 (
- &td->details.global_fee.purse_account_limit),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.global_fee.master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_global_fee",
- params);
-}
-
-
-/**
- * Function called with recoup records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_recoup (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_sig),
- GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_blind),
- TALER_PQ_query_param_amount (&td->details.recoup.amount),
- GNUNET_PQ_query_param_timestamp (&td->details.recoup.timestamp),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.recoup.coin_pub),
- GNUNET_PQ_query_param_uint64 (&td->details.recoup.reserve_out_serial_id),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_recoup",
- params);
-}
-
-
-/**
- * Function called with recoup_refresh records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_recoup_refresh (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.recoup_refresh.coin_sig),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.recoup_refresh.coin_blind),
- TALER_PQ_query_param_amount (&td->details.recoup_refresh.amount),
- GNUNET_PQ_query_param_timestamp (&td->details.recoup_refresh.timestamp),
- GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.recoup.coin_pub),
- GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.rrc_serial),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_recoup_refresh",
- params);
-}
-
-
-/**
- * Function called with extensions records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_extensions (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_string (td->details.extensions.name),
- NULL == td->details.extensions.config ?
- GNUNET_PQ_query_param_null () :
- GNUNET_PQ_query_param_string (td->details.extensions.config),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_extensions",
- params);
-}
-
-
-/**
- * Function called with extension_details records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_extension_details (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- NULL ==
- td->details.extension_details.extension_options ?
- GNUNET_PQ_query_param_null () :
- GNUNET_PQ_query_param_string (
- td->details.extension_details.extension_options),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_extension_details",
- params);
-}
-
-
-/**
- * Function called with purse_requests records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_purse_requests (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_requests.purse_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_requests.merge_pub),
- GNUNET_PQ_query_param_timestamp (
- &td->details.purse_requests.purse_creation),
- GNUNET_PQ_query_param_timestamp (
- &td->details.purse_requests.purse_expiration),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_requests.h_contract_terms),
- GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.age_limit),
- GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.flags),
- TALER_PQ_query_param_amount (&td->details.purse_requests.amount_with_fee),
- TALER_PQ_query_param_amount (&td->details.purse_requests.purse_fee),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_requests.purse_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_requests",
- params);
-}
-
-
-/**
- * Function called with purse_refunds records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_purse_refunds (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_refunds.purse_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_refunds",
- params);
-}
-
-
-/**
- * Function called with purse_merges records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_purse_merges (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (&td->details.purse_merges.partner_serial_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_merges.reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.purse_pub),
- GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.merge_sig),
- GNUNET_PQ_query_param_timestamp (&td->details.purse_merges.merge_timestamp),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_merges",
- params);
-}
-
-
-/**
- * Function called with purse_deposits records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_purse_deposits (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (
- &td->details.purse_deposits.partner_serial_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.purse_deposits.purse_pub),
- GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_pub),
- TALER_PQ_query_param_amount (&td->details.purse_deposits.amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_purse_deposits",
- params);
-}
-
-
-/**
- * Function called with account_mergers records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_account_mergers (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.account_merges.reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.account_merges.reserve_sig),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.account_merges.purse_pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_account_mergers",
- params);
-}
-
-
-/**
- * Function called with history_requests records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_history_requests (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.history_requests.reserve_pub),
- GNUNET_PQ_query_param_timestamp (
- &td->details.history_requests.request_timestamp),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.history_requests.reserve_sig),
- TALER_PQ_query_param_amount (
- &td->details.history_requests.history_fee),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_history_requests",
- params);
-}
-
-
-/**
- * Function called with close_requests records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_close_requests (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.close_requests.reserve_pub),
- GNUNET_PQ_query_param_timestamp (
- &td->details.close_requests.close_timestamp),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.close_requests.reserve_sig),
- TALER_PQ_query_param_amount (
- &td->details.close_requests.close),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_close_requests",
- params);
-}
-
-
-/**
- * Function called with wads_out records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wads_out (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.wads_out.wad_id),
- GNUNET_PQ_query_param_uint64 (&td->details.wads_out.partner_serial_id),
- TALER_PQ_query_param_amount (&td->details.wads_out.amount),
- GNUNET_PQ_query_param_timestamp (&td->details.wads_out.execution_time),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_out",
- params);
-}
-
-
-/**
- * Function called with wads_out_entries records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wads_out_entries (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_uint64 (
- &td->details.wads_out_entries.wad_out_serial_id),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_out_entries.reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_out_entries.purse_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_out_entries.h_contract),
- GNUNET_PQ_query_param_timestamp (
- &td->details.wads_out_entries.purse_expiration),
- GNUNET_PQ_query_param_timestamp (
- &td->details.wads_out_entries.merge_timestamp),
- TALER_PQ_query_param_amount (
- &td->details.wads_out_entries.amount_with_fee),
- TALER_PQ_query_param_amount (
- &td->details.wads_out_entries.wad_fee),
- TALER_PQ_query_param_amount (
- &td->details.wads_out_entries.deposit_fees),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_out_entries.reserve_sig),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_out_entries.purse_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_out_entries",
- params);
-}
-
-
-/**
- * Function called with wads_in records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wads_in (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (&td->details.wads_in.wad_id),
- GNUNET_PQ_query_param_string (td->details.wads_in.origin_exchange_url),
- TALER_PQ_query_param_amount (&td->details.wads_in.amount),
- GNUNET_PQ_query_param_timestamp (&td->details.wads_in.arrival_time),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_in",
- params);
-}
-
-
-/**
- * Function called with wads_in_entries records to insert into table.
- *
- * @param pg plugin context
- * @param td record to insert
- */
-static enum GNUNET_DB_QueryStatus
-irbt_cb_table_wads_in_entries (struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&td->serial),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_in_entries.reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_in_entries.purse_pub),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_in_entries.h_contract),
- GNUNET_PQ_query_param_timestamp (
- &td->details.wads_in_entries.purse_expiration),
- GNUNET_PQ_query_param_timestamp (
- &td->details.wads_in_entries.merge_timestamp),
- TALER_PQ_query_param_amount (
- &td->details.wads_in_entries.amount_with_fee),
- TALER_PQ_query_param_amount (
- &td->details.wads_in_entries.wad_fee),
- TALER_PQ_query_param_amount (
- &td->details.wads_in_entries.deposit_fees),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_in_entries.reserve_sig),
- GNUNET_PQ_query_param_auto_from_type (
- &td->details.wads_in_entries.purse_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_into_table_wads_in_entries",
- params);
-}
-
-
-/* end of irbt_callbacks.c */
diff --git a/src/exchangedb/perf-exchangedb-reserves-in-insert-postgres b/src/exchangedb/perf-exchangedb-reserves-in-insert-postgres
new file mode 100755
index 000000000..8eafde3ce
--- /dev/null
+++ b/src/exchangedb/perf-exchangedb-reserves-in-insert-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# perf-exchangedb-reserves-in-insert-postgres - temporary wrapper script for .libs/perf-exchangedb-reserves-in-insert-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The perf-exchangedb-reserves-in-insert-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "perf-exchangedb-reserves-in-insert-postgres:perf-exchangedb-reserves-in-insert-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "perf-exchangedb-reserves-in-insert-postgres:perf-exchangedb-reserves-in-insert-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "perf-exchangedb-reserves-in-insert-postgres:perf-exchangedb-reserves-in-insert-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='perf-exchangedb-reserves-in-insert-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/perf_deposits_get_ready.c b/src/exchangedb/perf_deposits_get_ready.c
new file mode 100644
index 000000000..005ea6843
--- /dev/null
+++ b/src/exchangedb/perf_deposits_get_ready.c
@@ -0,0 +1,565 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/perf_deposits_get_ready.c
+ * @brief benchmark for deposits_get_ready
+git * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include "math.h"
+
+/**
+ * Global result from the testcase.
+ */
+static int result;
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) {break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, \
+ sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+/**
+ * Currency we use. Must match test-exchange-db-*.conf.
+ */
+#define CURRENCY "EUR"
+#define RSA_KEY_SIZE 1024
+#define NUM_ROWS 1000
+#define ROUNDS 100
+#define MELT_NEW_COINS 5
+#define MELT_NOREVEAL_INDEX 1
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_EXCHANGEDB_Plugin *plugin;
+
+static struct TALER_DenomFeeSet fees;
+
+static struct TALER_MerchantWireHashP h_wire_wt;
+
+/**
+ * Denomination keys used for fresh coins in melt test.
+ */
+static struct DenomKeyPair **new_dkp;
+
+static struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coins;
+
+struct DenomKeyPair
+{
+ struct TALER_DenominationPrivateKey priv;
+ struct TALER_DenominationPublicKey pub;
+};
+
+
+/**
+ * Destroy a denomination key pair. The key is not necessarily removed from the DB.
+ *
+ * @param dkp the key pair to destroy
+ */
+static void
+destroy_denom_key_pair (struct DenomKeyPair *dkp)
+{
+ TALER_denom_pub_free (&dkp->pub);
+ TALER_denom_priv_free (&dkp->priv);
+ GNUNET_free (dkp);
+}
+
+
+/**
+ * Create a denomination key pair by registering the denomination in the DB.
+ *
+ * @param size the size of the denomination key
+ * @param now time to use for key generation, legal expiration will be 3h later.
+ * @param fees fees to use
+ * @return the denominaiton key pair; NULL upon error
+ */
+static struct DenomKeyPair *
+create_denom_key_pair (unsigned int size,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *value,
+ const struct TALER_DenomFeeSet *fees)
+{
+ struct DenomKeyPair *dkp;
+ struct TALER_EXCHANGEDB_DenominationKey dki;
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue2;
+
+ dkp = GNUNET_new (struct DenomKeyPair);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_priv_create (&dkp->priv,
+ &dkp->pub,
+ GNUNET_CRYPTO_BSA_RSA,
+ size));
+ memset (&dki,
+ 0,
+ sizeof (struct TALER_EXCHANGEDB_DenominationKey));
+ dki.denom_pub = dkp->pub;
+ dki.issue.start = now;
+ dki.issue.expire_withdraw
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_UNIT_HOURS));
+ dki.issue.expire_deposit
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 2)));
+ dki.issue.expire_legal
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 3)));
+ dki.issue.value = *value;
+ dki.issue.fees = *fees;
+ TALER_denom_pub_hash (&dkp->pub,
+ &dki.issue.denom_hash);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_denomination_info (plugin->cls,
+ &dki.denom_pub,
+ &dki.issue))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ memset (&issue2, 0, sizeof (issue2));
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_denomination_info (plugin->cls,
+ &dki.issue.denom_hash,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ if (0 != GNUNET_memcmp (&dki.issue,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ return dkp;
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+
+static void
+run (void *cls)
+{
+ struct TALER_EXCHANGEDB_Refresh refresh;
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const uint32_t num_partitions = 10;
+ struct TALER_Amount value;
+ struct TALER_EXCHANGEDB_CollectableBlindcoin cbc;
+ struct TALER_DenominationPublicKey *new_denom_pubs = NULL;
+ struct GNUNET_TIME_Relative times = GNUNET_TIME_UNIT_ZERO;
+ unsigned long long sqrs = 0;
+ struct TALER_EXCHANGEDB_CoinDepositInformation *depos;
+ struct TALER_EXCHANGEDB_BatchDeposit bd;
+ struct TALER_EXCHANGEDB_Refund *ref;
+ unsigned int *perm;
+ unsigned long long duration_sq;
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *ccoin;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA,
+ .rc = 0
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+
+ ref = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_Refund);
+ depos = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_CoinDepositInformation);
+
+ if (NULL ==
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_break (0);
+ result = 77;
+ return;
+ }
+ (void) plugin->drop_tables (plugin->cls);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
+ {
+ GNUNET_break (0);
+ result = 77;
+ goto cleanup;
+ }
+ if (GNUNET_OK !=
+ plugin->preflight (plugin->cls))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.000010",
+ &value));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.withdraw));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.deposit));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refresh));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refund));
+ {
+ ZR_BLK (&cbc);
+ new_dkp = GNUNET_new_array (MELT_NEW_COINS,
+ struct DenomKeyPair *);
+ new_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
+ struct TALER_DenominationPublicKey);
+ revealed_coins
+ = GNUNET_new_array (MELT_NEW_COINS,
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin);
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ struct GNUNET_TIME_Timestamp now;
+ struct GNUNET_CRYPTO_RsaBlindedMessage *rp;
+ struct TALER_BlindedPlanchet *bp;
+
+ now = GNUNET_TIME_timestamp_get ();
+ new_dkp[cnt] = create_denom_key_pair (RSA_KEY_SIZE,
+ now,
+ &value,
+ &fees);
+ GNUNET_assert (NULL != new_dkp[cnt]);
+ new_denom_pubs[cnt] = new_dkp[cnt]->pub;
+ ccoin = &revealed_coins[cnt];
+ bp = &ccoin->blinded_planchet;
+ bp->blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ bp->blinded_message->cipher = GNUNET_CRYPTO_BSA_RSA;
+ bp->blinded_message->rc = 1;
+ rp = &bp->blinded_message->details.rsa_blinded_message;
+ rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ (RSA_KEY_SIZE / 8) - 1);
+ rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ rp->blinded_msg,
+ rp->blinded_msg_size);
+ TALER_denom_pub_hash (&new_dkp[cnt]->pub,
+ &ccoin->h_denom_pub);
+ ccoin->exchange_vals = alg_values;
+ TALER_coin_ev_hash (bp,
+ &ccoin->h_denom_pub,
+ &ccoin->coin_envelope_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sign_blinded (&ccoin->coin_sig,
+ &new_dkp[cnt]->priv,
+ true,
+ bp));
+ TALER_coin_ev_hash (bp,
+ &cbc.denom_pub_hash,
+ &cbc.h_coin_envelope);
+ GNUNET_assert (
+ GNUNET_OK ==
+ TALER_denom_sign_blinded (
+ &cbc.sig,
+ &new_dkp[cnt]->priv,
+ false,
+ bp));
+ }
+ }
+ perm = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_NONCE,
+ NUM_ROWS);
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "Transaction"));
+ for (unsigned int j = 0; j < NUM_ROWS; j++)
+ {
+ /*** NEED TO INSERT REFRESH COMMITMENTS + ENSURECOIN ***/
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_CoinPubHashP c_hash;
+ unsigned int k = (unsigned int) rand () % 5;
+ unsigned int i = perm[j];
+
+ if (i >= ROUNDS)
+ i = ROUNDS; /* throw-away slot, do not keep around */
+ RND_BLK (&coin_pub);
+ RND_BLK (&c_hash);
+ RND_BLK (&reserve_pub);
+ RND_BLK (&cbc.reserve_sig);
+ TALER_denom_pub_hash (&new_dkp[k]->pub,
+ &cbc.denom_pub_hash);
+ deadline = GNUNET_TIME_timestamp_get ();
+ depos[i].coin.coin_pub = coin_pub;
+ TALER_denom_pub_hash (&new_dkp[k]->pub,
+ &depos[i].coin.denom_pub_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sig_unblind (&depos[i].coin.denom_sig,
+ &ccoin->coin_sig,
+ &bks,
+ &c_hash,
+ &alg_values,
+ &new_dkp[k]->pub));
+ RND_BLK (&bd.merchant_pub);
+ RND_BLK (&depos[i].csig);
+ RND_BLK (&bd.h_contract_terms);
+ RND_BLK (&bd.wire_salt);
+ depos[i].amount_with_fee = value;
+ bd.refund_deadline = deadline;
+ bd.wire_deadline = deadline;
+ bd.receiver_wire_account =
+ "payto://iban/DE67830654080004822650?receiver-name=Test";
+ TALER_merchant_wire_signature_hash (
+ bd.receiver_wire_account,
+ &bd.wire_salt,
+ &h_wire_wt);
+ bd.num_cdis = 1;
+ bd.cdis = &depos[i];
+ cbc.reserve_pub = reserve_pub;
+ cbc.amount_with_fee = value;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (CURRENCY,
+ &cbc.withdraw_fee));
+ {
+ bool found;
+ bool nonce_reuse;
+ bool balance_ok;
+ bool age_ok;
+ bool conflict;
+ bool denom_unknown;
+ struct TALER_Amount reserve_balance;
+ uint16_t allowed_minimum_age;
+ uint64_t ruuid;
+ struct GNUNET_TIME_Timestamp now;
+
+ now = GNUNET_TIME_timestamp_get ();
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_batch_withdraw (plugin->cls,
+ now,
+ &reserve_pub,
+ &value,
+ true,
+ &found,
+ &balance_ok,
+ &reserve_balance,
+ &age_ok,
+ &allowed_minimum_age,
+ &ruuid));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_batch_withdraw_insert (plugin->cls,
+ NULL,
+ &cbc,
+ now,
+ ruuid,
+ &denom_unknown,
+ &conflict,
+ &nonce_reuse));
+ }
+ {
+ /* ENSURE_COIN_KNOWN */
+ uint64_t known_coin_id;
+ struct TALER_DenominationHashP dph;
+ struct TALER_AgeCommitmentHash agh;
+ FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
+ plugin->ensure_coin_known (plugin->cls,
+ &depos[i].coin,
+ &known_coin_id,
+ &dph,
+ &agh));
+ refresh.coin = depos[i].coin;
+ RND_BLK (&refresh.coin_sig);
+ RND_BLK (&refresh.rc);
+ refresh.amount_with_fee = value;
+ refresh.noreveal_index = MELT_NOREVEAL_INDEX;
+ }
+ {
+ struct GNUNET_TIME_Timestamp now;
+ bool balance_ok;
+ uint32_t bad_idx;
+ bool ctr_conflict;
+
+ now = GNUNET_TIME_timestamp_get ();
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_deposit (plugin->cls,
+ &bd,
+ &now,
+ &balance_ok,
+ &bad_idx,
+ &ctr_conflict));
+ }
+ if (ROUNDS == i)
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->commit (plugin->cls));
+ GNUNET_free (perm);
+ /* End of benchmark setup */
+
+ /**** CALL GET READY DEPOSIT ****/
+ for (unsigned int r = 0; r< ROUNDS; r++)
+ {
+ struct GNUNET_TIME_Absolute time;
+ struct GNUNET_TIME_Relative duration;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ char *payto_uri;
+ enum GNUNET_DB_QueryStatus qs;
+
+ time = GNUNET_TIME_absolute_get ();
+ qs = plugin->get_ready_deposit (plugin->cls,
+ 0,
+ INT32_MAX,
+ &merchant_pub,
+ &payto_uri);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs);
+ duration = GNUNET_TIME_absolute_get_duration (time);
+ times = GNUNET_TIME_relative_add (times,
+ duration);
+ duration_sq = duration.rel_value_us * duration.rel_value_us;
+ GNUNET_assert (duration_sq / duration.rel_value_us ==
+ duration.rel_value_us);
+ GNUNET_assert (sqrs + duration_sq >= sqrs);
+ sqrs += duration_sq;
+ }
+
+ /* evaluation of performance */
+ {
+ struct GNUNET_TIME_Relative avg;
+ double avg_dbl;
+ double variance;
+
+ avg = GNUNET_TIME_relative_divide (times,
+ ROUNDS);
+ avg_dbl = avg.rel_value_us;
+ variance = sqrs - (avg_dbl * avg_dbl * ROUNDS);
+ fprintf (stdout,
+ "%8llu ± %6.0f\n",
+ (unsigned long long) avg.rel_value_us,
+ sqrt (variance / (ROUNDS - 1)));
+ }
+ result = 0;
+drop:
+ // GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls));
+cleanup:
+ if (NULL != revealed_coins)
+ {
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ TALER_blinded_denom_sig_free (&revealed_coins[cnt].coin_sig);
+ TALER_blinded_planchet_free (&revealed_coins[cnt].blinded_planchet);
+ }
+ GNUNET_free (revealed_coins);
+ revealed_coins = NULL;
+ }
+ GNUNET_free (new_denom_pubs);
+ for (unsigned int cnt = 0;
+ (NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]);
+ cnt++)
+ destroy_denom_key_pair (new_dkp[cnt]);
+ GNUNET_free (new_dkp);
+ for (unsigned int i = 0; i< ROUNDS; i++)
+ {
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ GNUNET_free (depos);
+ GNUNET_free (ref);
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ (void) argc;
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ plugin_name++;
+ {
+ char *testname;
+
+ GNUNET_asprintf (&testname,
+ "test-exchange-db-%s",
+ plugin_name);
+ GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ GNUNET_free (testname);
+ }
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ return result;
+}
+
+
+/* end of perf_deposits_get_ready.c */
diff --git a/src/exchangedb/perf_get_link_data.c b/src/exchangedb/perf_get_link_data.c
new file mode 100644
index 000000000..817789afc
--- /dev/null
+++ b/src/exchangedb/perf_get_link_data.c
@@ -0,0 +1,543 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/perf_get_link_data.c
+ * @brief benchmark for get_link_data
+ * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include "math.h"
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) {break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+#define CURRENCY "EUR"
+#define RSA_KEY_SIZE 1024
+#define ROUNDS 100
+#define NUM_ROWS 1000
+#define MELT_NEW_COINS 5
+#define DENOMINATIONS 5
+#define MELT_NOREVEAL_INDEX 1
+/**
+ * Database plugin under test.
+ */
+static struct TALER_EXCHANGEDB_Plugin *plugin;
+static struct TALER_DenomFeeSet fees;
+/**
+ * Denomination keys used for fresh coins in melt test.
+ */
+static struct DenomKeyPair **new_dkp;
+static int result;
+
+static struct TALER_TransferPrivateKeyP tprivs[TALER_CNC_KAPPA];
+static struct TALER_TransferPublicKeyP tpub;
+struct DenomKeyPair
+{
+ struct TALER_DenominationPrivateKey priv;
+ struct TALER_DenominationPublicKey pub;
+};
+
+
+/**
+ * Destroy a denomination key pair. The key is not necessarily removed from the DB.
+ *
+ * @param dkp the key pair to destroy
+ */
+static void
+destroy_denom_key_pair (struct DenomKeyPair *dkp)
+{
+ TALER_denom_pub_free (&dkp->pub);
+ TALER_denom_priv_free (&dkp->priv);
+ GNUNET_free (dkp);
+}
+
+
+/**
+ * Create a denomination key pair by registering the denomination in the DB.
+ *
+ * @param size the size of the denomination key
+ * @param now time to use for key generation, legal expiration will be 3h later.
+ * @param fees fees to use
+ * @return the denominaiton key pair; NULL upon error
+ */
+static struct DenomKeyPair *
+create_denom_key_pair (unsigned int size,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *value,
+ const struct TALER_DenomFeeSet *fees)
+{
+ struct DenomKeyPair *dkp;
+ struct TALER_EXCHANGEDB_DenominationKey dki;
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue2;
+
+ dkp = GNUNET_new (struct DenomKeyPair);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_priv_create (&dkp->priv,
+ &dkp->pub,
+ GNUNET_CRYPTO_BSA_RSA,
+ size));
+ memset (&dki,
+ 0,
+ sizeof (struct TALER_EXCHANGEDB_DenominationKey));
+ dki.denom_pub = dkp->pub;
+ dki.issue.start = now;
+ dki.issue.expire_withdraw
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_UNIT_HOURS));
+ dki.issue.expire_deposit
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 2)));
+ dki.issue.expire_legal
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 3)));
+ dki.issue.value = *value;
+ dki.issue.fees = *fees;
+ TALER_denom_pub_hash (&dkp->pub,
+ &dki.issue.denom_hash);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_denomination_info (plugin->cls,
+ &dki.denom_pub,
+ &dki.issue))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ memset (&issue2, 0, sizeof (issue2));
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_denomination_info (plugin->cls,
+ &dki.issue.denom_hash,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ if (0 != GNUNET_memcmp (&dki.issue,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ return dkp;
+}
+
+
+/**
+ * Function called with the session hashes and transfer secret
+ * information for a given coin.
+ *
+ * @param cls closure
+ * @param transfer_pub public transfer key for the session
+ * @param ldl link data for @a transfer_pub
+ */
+static void
+handle_link_data_cb (void *cls,
+ const struct TALER_TransferPublicKeyP *transfer_pub,
+ const struct TALER_EXCHANGEDB_LinkList *ldl)
+{
+ (void) cls;
+ (void) transfer_pub;
+ (void) ldl;
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+
+static void
+run (void *cls)
+{
+ struct TALER_EXCHANGEDB_Refresh *refresh;
+ uint64_t melt_serial_id;
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const uint32_t num_partitions = 10;
+ struct DenomKeyPair *dkp = NULL;
+ struct TALER_EXCHANGEDB_Deposit *depos = NULL;
+ struct TALER_Amount value;
+ struct GNUNET_TIME_Relative times = GNUNET_TIME_UNIT_ZERO;
+ unsigned long long sqrs = 0;
+ struct TALER_EXCHANGEDB_Refund *ref = NULL;
+ unsigned int *perm;
+ unsigned long long duration_sq;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA,
+ .rc = 0
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+
+ ref = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_Refund);
+ depos = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_Deposit);
+ refresh = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_Refresh);
+
+ if (NULL ==
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_break (0);
+ result = 77;
+ return;
+ }
+ (void) plugin->drop_tables (plugin->cls);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
+ {
+ GNUNET_break (0);
+ result = 77;
+ goto cleanup;
+ }
+ if (GNUNET_OK !=
+ plugin->preflight (plugin->cls))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.000010",
+ &value));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.withdraw));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.deposit));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refresh));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refund));
+ {
+ new_dkp = GNUNET_new_array (MELT_NEW_COINS,
+ struct DenomKeyPair *);
+
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
+
+ new_dkp[cnt] = create_denom_key_pair (RSA_KEY_SIZE,
+ now,
+ &value,
+ &fees);
+ GNUNET_assert (NULL != new_dkp[cnt]);
+ }
+ }
+ perm = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_NONCE,
+ NUM_ROWS);
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "Transaction"));
+ for (unsigned int j = 0; j < NUM_ROWS; j++)
+ {
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ struct TALER_CoinPubHashP c_hash;
+ unsigned int i = perm[j];
+ uint64_t known_coin_id;
+ struct TALER_EXCHANGEDB_CollectableBlindcoin cbc;
+ if (i >= ROUNDS)
+ i = ROUNDS; /* throw-away slot, do not keep around */
+ RND_BLK (&depos[i].coin.coin_pub);
+ ZR_BLK (&cbc);
+ TALER_denom_pub_hash (&new_dkp[(unsigned int) rand ()
+ % MELT_NEW_COINS]->pub,
+ &depos[i].coin.denom_pub_hash);
+
+
+ {
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin
+ revealed_coins[MELT_NEW_COINS];
+
+ for (unsigned int p = 0; p<MELT_NEW_COINS; p++)
+ {
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coin =
+ &revealed_coins[p];
+ struct TALER_BlindedPlanchet *bp = &revealed_coin->blinded_planchet;
+ bp->blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ struct GNUNET_CRYPTO_RsaBlindedMessage *rp =
+ &bp->blinded_message->details.rsa_blinded_message;
+
+ /* h_coin_ev must be unique, but we only have MELT_NEW_COINS created
+ above for NUM_ROWS iterations; instead of making "all new" coins,
+ we simply randomize the hash here as nobody is checking for consistency
+ anyway ;-) */
+ bp->blinded_message->rc = 1;
+ bp->blinded_message->cipher = GNUNET_CRYPTO_BSA_RSA;
+ rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ (RSA_KEY_SIZE / 8) - 1);
+ rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ rp->blinded_msg,
+ rp->blinded_msg_size);
+ TALER_denom_pub_hash (&new_dkp[(unsigned int) rand ()
+ % MELT_NEW_COINS]->pub,
+ &revealed_coin->h_denom_pub);
+ revealed_coin->exchange_vals = alg_values;
+ TALER_coin_ev_hash (bp,
+ &revealed_coin->h_denom_pub,
+ &revealed_coin->coin_envelope_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sign_blinded (&revealed_coin->coin_sig,
+ &new_dkp[(unsigned
+ int) rand ()
+ % MELT_NEW_COINS]->
+ priv,
+ true,
+ bp));
+ GNUNET_assert (
+ GNUNET_OK ==
+ TALER_denom_sign_blinded (
+ &cbc.sig,
+ &new_dkp[(unsigned int) rand () % MELT_NEW_COINS]->priv,
+ false,
+ bp));
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sig_unblind (&depos[i].coin.denom_sig,
+ &cbc.sig,
+ &bks,
+ &c_hash,
+ &alg_values,
+ &new_dkp[(unsigned int) rand ()
+ % MELT_NEW_COINS]->pub));
+ {
+ /* ENSURE_COIN_KNOWN */
+ struct TALER_DenominationHashP dph;
+ struct TALER_AgeCommitmentHash agh;
+ bool zombie_required = false;
+ bool balance_ok;
+
+ FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
+ plugin->ensure_coin_known (plugin->cls,
+ &depos[i].coin,
+ &known_coin_id,
+ &dph,
+ &agh));
+ /**** INSERT REFRESH COMMITMENTS ****/
+ refresh[i].coin = depos[i].coin;
+ RND_BLK (&refresh[i].coin_sig);
+ RND_BLK (&refresh[i].rc);
+ refresh[i].amount_with_fee = value;
+ refresh[i].noreveal_index = MELT_NOREVEAL_INDEX;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_melt (plugin->cls,
+ NULL,
+ &refresh[i],
+ known_coin_id,
+ &zombie_required,
+ &balance_ok));
+ }
+ /****GET melt_serial_id generated by default****/
+ {
+ struct TALER_EXCHANGEDB_Melt ret_refresh_session;
+
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_melt (plugin->cls,
+ &refresh[i].rc,
+ &ret_refresh_session,
+ &melt_serial_id));
+ }
+ /**** INSERT REFRESH_REVEAL + TRANSFER_KEYS *****/
+ {
+ static unsigned int cnt;
+
+ RND_BLK (&tprivs);
+ RND_BLK (&tpub);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_refresh_reveal (plugin->cls,
+ melt_serial_id,
+ MELT_NEW_COINS,
+ revealed_coins,
+ TALER_CNC_KAPPA - 1,
+ tprivs,
+ &tpub));
+ cnt++;
+ // fprintf (stderr, "CNT: %u - %llu\n", cnt, (unsigned long long) melt_serial_id);
+ }
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ TALER_blinded_denom_sig_free (&revealed_coins[cnt].coin_sig);
+ TALER_blinded_planchet_free (&revealed_coins[cnt].blinded_planchet);
+ }
+
+ /* {
+ struct TALER_CoinSpendPublicKeyP ocp;
+ uint64_t rrc_serial;
+
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_old_coin_by_h_blind (plugin->cls,
+ &revealed_coins->coin_envelope_hash,
+ &ocp,
+ &rrc_serial));
+ }*/
+ }
+ if (ROUNDS == i)
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ /* End of benchmark setup */
+ GNUNET_free (perm);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->commit (plugin->cls));
+ for (unsigned int r = 0; r< ROUNDS; r++)
+ {
+ struct GNUNET_TIME_Absolute time;
+ struct GNUNET_TIME_Relative duration;
+ enum GNUNET_DB_QueryStatus qs;
+ time = GNUNET_TIME_absolute_get ();
+
+ qs = plugin->get_link_data (plugin->cls,
+ &refresh[r].coin.coin_pub,
+ &handle_link_data_cb,
+ NULL);
+ FAILIF (qs < 0);
+
+ duration = GNUNET_TIME_absolute_get_duration (time);
+ times = GNUNET_TIME_relative_add (times,
+ duration);
+ duration_sq = duration.rel_value_us * duration.rel_value_us;
+ GNUNET_assert (duration_sq / duration.rel_value_us ==
+ duration.rel_value_us);
+ GNUNET_assert (sqrs + duration_sq >= sqrs);
+ sqrs += duration_sq;
+ }
+
+ /* evaluation of performance */
+ {
+ struct GNUNET_TIME_Relative avg;
+ double avg_dbl;
+ double variance;
+
+ avg = GNUNET_TIME_relative_divide (times,
+ ROUNDS);
+ avg_dbl = avg.rel_value_us;
+ variance = sqrs - (avg_dbl * avg_dbl * ROUNDS);
+ fprintf (stdout,
+ "%8llu ± %6.0f\n",
+ (unsigned long long) avg.rel_value_us,
+ sqrt (variance / (ROUNDS - 1)));
+ }
+ result = 0;
+drop:
+ // GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls));
+cleanup:
+ if (NULL != dkp)
+ destroy_denom_key_pair (dkp);
+ for (unsigned int cnt = 0;
+ (NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]);
+ cnt++)
+ destroy_denom_key_pair (new_dkp[cnt]);
+ GNUNET_free (new_dkp);
+ for (unsigned int i = 0; i< ROUNDS; i++)
+ {
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ GNUNET_free (depos);
+ GNUNET_free (ref);
+ GNUNET_free (refresh);
+ dkp = NULL;
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ char *testname;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ (void) argc;
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-exchange-db-%s",
+ plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
+
+
+/* end of test_exchangedb_by_j.c */
diff --git a/src/exchangedb/perf_reserves_in_insert.c b/src/exchangedb/perf_reserves_in_insert.c
new file mode 100644
index 000000000..09c4a43c5
--- /dev/null
+++ b/src/exchangedb/perf_reserves_in_insert.c
@@ -0,0 +1,232 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/perf_reserves_in_insert.c
+ * @brief benchmark for 'reserves_in_insert'
+ * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Global result from the testcase.
+ */
+static int result;
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) {break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+/**
+ * How many rounds do we average over?
+ */
+#define ROUNDS 5
+
+/**
+ * Currency we use. Must match test-exchange-db-*.conf.
+ */
+#define CURRENCY "EUR"
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_EXCHANGEDB_Plugin *plugin;
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+static void
+run (void *cls)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const uint32_t num_partitions = 10;
+ static unsigned int batches[] = {1, 1, 2, 3, 4, 16, 32, 64, 128, 256, 512,
+ 1024, 1024, 512, 256, 128, 64, 32,
+ 16, 4, 3, 2, 1 };
+ struct GNUNET_TIME_Relative times[sizeof (batches) / sizeof(*batches)];
+ unsigned long long sqrs[sizeof (batches) / sizeof(*batches)];
+
+ if (NULL ==
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_break (0);
+ result = 77;
+ return;
+ }
+ (void) plugin->drop_tables (plugin->cls);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
+ {
+ GNUNET_break (0);
+ result = 77;
+ goto cleanup;
+ }
+
+ memset (times, 0, sizeof (times));
+ memset (sqrs, 0, sizeof (sqrs));
+ for (unsigned int r = 0; r < ROUNDS; r++)
+ {
+ for (unsigned int i = 0;
+ i< sizeof(batches) / sizeof(*batches);
+ i++)
+ {
+ unsigned int lcm = batches[i];
+ struct TALER_Amount value;
+ struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Timestamp ts;
+ unsigned long long duration_sq;
+ struct GNUNET_TIME_Relative duration;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.000010",
+ &value));
+ now = GNUNET_TIME_absolute_get ();
+ ts = GNUNET_TIME_timestamp_get ();
+ {
+ const char *sndr = "payto://x-taler-bank/localhost:8080/1";
+ struct TALER_ReservePublicKeyP reserve_pubs[lcm];
+ struct TALER_EXCHANGEDB_ReserveInInfo reserves[lcm];
+ enum GNUNET_DB_QueryStatus results[lcm];
+
+ for (unsigned int k = 0; k<lcm; k++)
+ {
+ RND_BLK (&reserve_pubs[k]);
+ reserves[k].reserve_pub = &reserve_pubs[k];
+ reserves[k].balance = &value;
+ reserves[k].execution_time = ts;
+ reserves[k].sender_account_details = sndr;
+ reserves[k].exchange_account_name = "name";
+ reserves[k].wire_reference = k;
+ }
+ FAILIF (lcm !=
+ plugin->reserves_in_insert (plugin->cls,
+ reserves,
+ lcm,
+ results));
+ }
+ duration = GNUNET_TIME_absolute_get_duration (now);
+ times[i] = GNUNET_TIME_relative_add (times[i],
+ duration);
+ duration_sq = duration.rel_value_us * duration.rel_value_us;
+ GNUNET_assert (duration_sq / duration.rel_value_us ==
+ duration.rel_value_us);
+ GNUNET_assert (sqrs[i] + duration_sq >= sqrs[i]);
+ sqrs[i] += duration_sq;
+ } /* for 'i' batch size */
+ } /* for 'r' ROUNDS */
+
+ for (unsigned int i = 0;
+ i< sizeof(batches) / sizeof(*batches);
+ i++)
+ {
+ unsigned int lcm = batches[i];
+ struct GNUNET_TIME_Relative avg;
+ double avg_dbl;
+ double variance;
+
+ avg = GNUNET_TIME_relative_divide (times[i],
+ ROUNDS);
+ avg_dbl = avg.rel_value_us;
+ variance = sqrs[i] - (avg_dbl * avg_dbl * ROUNDS);
+ fprintf (stdout,
+ "Batch[%4u]: %8llu us/entry ± %6.0f\n",
+ batches[i],
+ (unsigned long long) avg.rel_value_us / lcm,
+ sqrt (variance / lcm / (ROUNDS - 1)));
+ }
+ result = 0;
+drop:
+ GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls));
+cleanup:
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ char *testname;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ (void) argc;
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-exchange-db-%s",
+ plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
+
+
+/* end of perf_reserves_in_insert.c */
diff --git a/src/exchangedb/perf_select_refunds_by_coin.c b/src/exchangedb/perf_select_refunds_by_coin.c
new file mode 100644
index 000000000..84825d6d7
--- /dev/null
+++ b/src/exchangedb/perf_select_refunds_by_coin.c
@@ -0,0 +1,619 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/perf_select_refunds_by_coin.c
+ * @brief benchmark for select_refunds_by_coin
+ * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include "math.h"
+
+/**
+ * Global result from the testcase.
+ */
+static int result;
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) {break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, \
+ sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+/**
+ * Currency we use. Must match test-exchange-db-*.conf.
+ */
+#define CURRENCY "EUR"
+#define RSA_KEY_SIZE 1024
+#define ROUNDS 100
+#define NUM_ROWS 1000
+#define MELT_NEW_COINS 5
+#define MELT_NOREVEAL_INDEX 1
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_EXCHANGEDB_Plugin *plugin;
+
+static struct TALER_DenomFeeSet fees;
+
+static struct TALER_MerchantWireHashP h_wire_wt;
+
+static struct DenomKeyPair **new_dkp;
+
+static struct TALER_EXCHANGEDB_RefreshRevealedCoin *revealed_coins;
+
+struct DenomKeyPair
+{
+ struct TALER_DenominationPrivateKey priv;
+ struct TALER_DenominationPublicKey pub;
+};
+
+
+/**
+ * Destroy a denomination key pair. The key is not necessarily removed from the DB.
+ *
+ * @param dkp the key pair to destroy
+ */
+static void
+destroy_denom_key_pair (struct DenomKeyPair *dkp)
+{
+ TALER_denom_pub_free (&dkp->pub);
+ TALER_denom_priv_free (&dkp->priv);
+ GNUNET_free (dkp);
+}
+
+
+/**
+ * Create a denomination key pair by registering the denomination in the DB.
+ *
+ * @param size the size of the denomination key
+ * @param now time to use for key generation, legal expiration will be 3h later.
+ * @param fees fees to use
+ * @return the denominaiton key pair; NULL upon error
+ */
+static struct DenomKeyPair *
+create_denom_key_pair (unsigned int size,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *value,
+ const struct TALER_DenomFeeSet *fees)
+{
+ struct DenomKeyPair *dkp;
+ struct TALER_EXCHANGEDB_DenominationKey dki;
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue2;
+
+ dkp = GNUNET_new (struct DenomKeyPair);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_priv_create (&dkp->priv,
+ &dkp->pub,
+ GNUNET_CRYPTO_BSA_RSA,
+ size));
+ memset (&dki,
+ 0,
+ sizeof (struct TALER_EXCHANGEDB_DenominationKey));
+ dki.denom_pub = dkp->pub;
+ dki.issue.start = now;
+ dki.issue.expire_withdraw
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_UNIT_HOURS));
+ dki.issue.expire_deposit
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 2)));
+ dki.issue.expire_legal
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (
+ now.abs_time,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_HOURS, 3)));
+ dki.issue.value = *value;
+ dki.issue.fees = *fees;
+ TALER_denom_pub_hash (&dkp->pub,
+ &dki.issue.denom_hash);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->insert_denomination_info (plugin->cls,
+ &dki.denom_pub,
+ &dki.issue))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ memset (&issue2, 0, sizeof (issue2));
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->get_denomination_info (plugin->cls,
+ &dki.issue.denom_hash,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ if (0 != GNUNET_memcmp (&dki.issue,
+ &issue2))
+ {
+ GNUNET_break (0);
+ destroy_denom_key_pair (dkp);
+ return NULL;
+ }
+ return dkp;
+}
+
+
+/**
+ * Callback invoked with information about refunds applicable
+ * to a particular coin.
+ *
+ * @param cls closure with the `struct TALER_EXCHANGEDB_Refund *` we expect to get
+ * @param amount_with_fee amount being refunded
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+static enum GNUNET_GenericReturnValue
+check_refund_cb (void *cls,
+ const struct TALER_Amount *amount_with_fee)
+{
+ const struct TALER_EXCHANGEDB_Refund *refund = cls;
+
+ if (0 != TALER_amount_cmp (amount_with_fee,
+ &refund->details.refund_amount))
+ {
+ GNUNET_break (0);
+ result = 66;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+
+static void
+run (void *cls)
+{
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const uint32_t num_partitions = 10;
+ struct GNUNET_TIME_Timestamp ts;
+ struct TALER_EXCHANGEDB_CoinDepositInformation *depos = NULL;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct TALER_Amount value;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ struct TALER_EXCHANGEDB_CollectableBlindcoin cbc;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA,
+ .rc = 0
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+ struct GNUNET_TIME_Relative times = GNUNET_TIME_UNIT_ZERO;
+ unsigned long long sqrs = 0;
+ struct TALER_EXCHANGEDB_Refund *ref = NULL;
+ unsigned int *perm;
+ unsigned long long duration_sq;
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *ccoin;
+ struct TALER_DenominationPublicKey *new_denom_pubs = NULL;
+ unsigned int count = 0;
+
+ ref = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_Refund);
+ depos = GNUNET_new_array (ROUNDS + 1,
+ struct TALER_EXCHANGEDB_CoinDepositInformation);
+ ZR_BLK (&cbc);
+
+ if (NULL ==
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_break (0);
+ result = 77;
+ return;
+ }
+ (void) plugin->drop_tables (plugin->cls);
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
+ {
+ GNUNET_break (0);
+ result = 77;
+ goto cleanup;
+ }
+ if (GNUNET_OK !=
+ plugin->preflight (plugin->cls))
+ {
+ GNUNET_break (0);
+ goto cleanup;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.000010",
+ &value));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.withdraw));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.deposit));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refresh));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":0.000010",
+ &fees.refund));
+ GNUNET_assert (NUM_ROWS >= ROUNDS);
+
+ ts = GNUNET_TIME_timestamp_get ();
+ deadline = GNUNET_TIME_timestamp_get ();
+ {
+ new_dkp = GNUNET_new_array (MELT_NEW_COINS,
+ struct DenomKeyPair *);
+ new_denom_pubs = GNUNET_new_array (MELT_NEW_COINS,
+ struct TALER_DenominationPublicKey);
+ revealed_coins
+ = GNUNET_new_array (MELT_NEW_COINS,
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin);
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ struct GNUNET_TIME_Timestamp now;
+ struct GNUNET_CRYPTO_RsaBlindedMessage *rp;
+ struct TALER_BlindedPlanchet *bp;
+
+ now = GNUNET_TIME_timestamp_get ();
+ new_dkp[cnt] = create_denom_key_pair (RSA_KEY_SIZE,
+ now,
+ &value,
+ &fees);
+ GNUNET_assert (NULL != new_dkp[cnt]);
+ new_denom_pubs[cnt] = new_dkp[cnt]->pub;
+ ccoin = &revealed_coins[cnt];
+ bp = &ccoin->blinded_planchet;
+ bp->blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ bp->blinded_message->rc = 1;
+ bp->blinded_message->cipher = GNUNET_CRYPTO_BSA_RSA;
+ rp = &bp->blinded_message->details.rsa_blinded_message;
+ rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ (RSA_KEY_SIZE / 8) - 1);
+ rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ rp->blinded_msg,
+ rp->blinded_msg_size);
+ TALER_denom_pub_hash (&new_dkp[cnt]->pub,
+ &ccoin->h_denom_pub);
+ ccoin->exchange_vals = alg_values;
+ TALER_coin_ev_hash (bp,
+ &ccoin->h_denom_pub,
+ &ccoin->coin_envelope_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sign_blinded (&ccoin->coin_sig,
+ &new_dkp[cnt]->priv,
+ true,
+ bp));
+ TALER_coin_ev_hash (bp,
+ &cbc.denom_pub_hash,
+ &cbc.h_coin_envelope);
+ GNUNET_assert (
+ GNUNET_OK ==
+ TALER_denom_sign_blinded (
+ &cbc.sig,
+ &new_dkp[cnt]->priv,
+ false,
+ bp));
+ }
+ }
+
+ perm = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_NONCE,
+ NUM_ROWS);
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "Transaction"));
+ for (unsigned int j = 0; j< NUM_ROWS; j++)
+ {
+ unsigned int i = perm[j];
+ unsigned int k = (unsigned int) rand () % 5;
+ struct TALER_CoinPubHashP c_hash;
+ uint64_t known_coin_id;
+ struct TALER_EXCHANGEDB_CoinDepositInformation *cdi
+ = &depos[i];
+ struct TALER_EXCHANGEDB_BatchDeposit bd = {
+ .cdis = cdi,
+ .num_cdis = 1,
+ .wallet_timestamp = ts,
+ .refund_deadline = deadline,
+ .wire_deadline = deadline,
+ .receiver_wire_account
+ = "payto://iban/DE67830654080004822650?receiver-name=Test"
+ };
+
+ if (i >= ROUNDS)
+ i = ROUNDS; /* throw-away slot, do not keep around */
+ RND_BLK (&bd.merchant_pub);
+ RND_BLK (&bd.h_contract_terms);
+ RND_BLK (&bd.wire_salt);
+ TALER_merchant_wire_signature_hash (
+ bd.receiver_wire_account,
+ &bd.wire_salt,
+ &h_wire_wt);
+ RND_BLK (&cdi->coin.coin_pub);
+ RND_BLK (&cdi->csig);
+ RND_BLK (&c_hash);
+ TALER_denom_pub_hash (&new_dkp[k]->pub,
+ &cdi->coin.denom_pub_hash);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sig_unblind (&cdi->coin.denom_sig,
+ &cbc.sig,
+ &bks,
+ &c_hash,
+ &alg_values,
+ &new_dkp[k]->pub));
+ cdi->amount_with_fee = value;
+
+ {
+ struct TALER_DenominationHashP dph;
+ struct TALER_AgeCommitmentHash agh;
+
+ FAILIF (TALER_EXCHANGEDB_CKS_ADDED !=
+ plugin->ensure_coin_known (plugin->cls,
+ &cdi->coin,
+ &known_coin_id,
+ &dph,
+ &agh));
+ }
+ {
+ struct GNUNET_TIME_Timestamp now;
+ bool balance_ok;
+ uint32_t bad_idx;
+ bool in_conflict;
+
+ now = GNUNET_TIME_timestamp_get ();
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_deposit (plugin->cls,
+ &bd,
+ &now,
+ &balance_ok,
+ &bad_idx,
+ &in_conflict));
+ }
+ {
+ bool not_found;
+ bool refund_ok;
+ bool gone;
+ bool conflict;
+ unsigned int refund_percent = 0;
+ switch (refund_percent)
+ {
+ case 2: // 100% refund
+ ref[i].coin = depos[i].coin;
+ ref[i].details.merchant_pub = bd.merchant_pub;
+ RND_BLK (&ref[i].details.merchant_sig);
+ ref[i].details.h_contract_terms = bd.h_contract_terms;
+ ref[i].coin.coin_pub = depos[i].coin.coin_pub;
+ ref[i].details.rtransaction_id = i;
+ ref[i].details.refund_amount = value;
+ ref[i].details.refund_fee = fees.refund;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_refund (plugin->cls,
+ &ref[i],
+ &fees.deposit,
+ known_coin_id,
+ &not_found,
+ &refund_ok,
+ &gone,
+ &conflict));
+ break;
+ case 1:// 10% refund
+ if (count < (NUM_ROWS / 10))
+ {
+ ref[i].coin = depos[i].coin;
+ ref[i].details.merchant_pub = bd.merchant_pub;
+ RND_BLK (&ref[i].details.merchant_sig);
+ ref[i].details.h_contract_terms = bd.h_contract_terms;
+ ref[i].coin.coin_pub = depos[i].coin.coin_pub;
+ ref[i].details.rtransaction_id = i;
+ ref[i].details.refund_amount = value;
+ ref[i].details.refund_fee = fees.refund;
+ }
+ else
+ {
+ ref[i].coin = depos[i].coin;
+ RND_BLK (&ref[i].details.merchant_pub);
+ RND_BLK (&ref[i].details.merchant_sig);
+ RND_BLK (&ref[i].details.h_contract_terms);
+ RND_BLK (&ref[i].coin.coin_pub);
+ ref[i].details.rtransaction_id = i;
+ ref[i].details.refund_amount = value;
+ ref[i].details.refund_fee = fees.refund;
+ }
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_refund (plugin->cls,
+ &ref[i],
+ &fees.deposit,
+ known_coin_id,
+ &not_found,
+ &refund_ok,
+ &gone,
+ &conflict));
+ count++;
+ break;
+ case 0:// no refund
+ ref[i].coin = depos[i].coin;
+ RND_BLK (&ref[i].details.merchant_pub);
+ RND_BLK (&ref[i].details.merchant_sig);
+ RND_BLK (&ref[i].details.h_contract_terms);
+ RND_BLK (&ref[i].coin.coin_pub);
+ ref[i].details.rtransaction_id = i;
+ ref[i].details.refund_amount = value;
+ ref[i].details.refund_fee = fees.refund;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_refund (plugin->cls,
+ &ref[i],
+ &fees.deposit,
+ known_coin_id,
+ &not_found,
+ &refund_ok,
+ &gone,
+ &conflict));
+ break;
+ }/* END OF SWITCH CASE */
+ }
+ if (ROUNDS == i)
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ /* End of benchmark setup */
+ GNUNET_free (perm);
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->commit (plugin->cls));
+ for (unsigned int r = 0; r < ROUNDS; r++)
+ {
+ struct GNUNET_TIME_Absolute time;
+ struct GNUNET_TIME_Relative duration;
+
+ time = GNUNET_TIME_absolute_get ();
+ FAILIF (0 >
+ plugin->select_refunds_by_coin (plugin->cls,
+ &ref[r].coin.coin_pub,
+ &ref[r].details.merchant_pub,
+ &ref[r].details.h_contract_terms,
+ &check_refund_cb,
+ &ref[r]));
+ duration = GNUNET_TIME_absolute_get_duration (time);
+ times = GNUNET_TIME_relative_add (times,
+ duration);
+ duration_sq = duration.rel_value_us * duration.rel_value_us;
+ GNUNET_assert (duration_sq / duration.rel_value_us ==
+ duration.rel_value_us);
+ GNUNET_assert (sqrs + duration_sq >= sqrs);
+ sqrs += duration_sq;
+ }
+ /* evaluation of performance */
+ {
+ struct GNUNET_TIME_Relative avg;
+ double avg_dbl;
+ double variance;
+
+ avg = GNUNET_TIME_relative_divide (times,
+ ROUNDS);
+ avg_dbl = avg.rel_value_us;
+ variance = sqrs - (avg_dbl * avg_dbl * ROUNDS);
+ fprintf (stdout,
+ "%8llu ± %6.0f\n",
+ (unsigned long long) avg.rel_value_us,
+ sqrt (variance / (ROUNDS - 1)));
+ }
+ result = 0;
+drop:
+ GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls));
+cleanup:
+ if (NULL != revealed_coins)
+ {
+ for (unsigned int cnt = 0; cnt < MELT_NEW_COINS; cnt++)
+ {
+ TALER_blinded_denom_sig_free (&revealed_coins[cnt].coin_sig);
+ TALER_blinded_planchet_free (&revealed_coins[cnt].blinded_planchet);
+ }
+ GNUNET_free (revealed_coins);
+ revealed_coins = NULL;
+ }
+ GNUNET_free (new_denom_pubs);
+ for (unsigned int cnt = 0;
+ (NULL != new_dkp) && (cnt < MELT_NEW_COINS) && (NULL != new_dkp[cnt]);
+ cnt++)
+ destroy_denom_key_pair (new_dkp[cnt]);
+ GNUNET_free (new_dkp);
+ for (unsigned int i = 0; i< ROUNDS + 1; i++)
+ {
+ TALER_denom_sig_free (&depos[i].coin.denom_sig);
+ }
+ GNUNET_free (depos);
+ GNUNET_free (ref);
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ (void) argc;
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ plugin_name++;
+ {
+ char *testname;
+
+ GNUNET_asprintf (&testname,
+ "test-exchange-db-%s",
+ plugin_name);
+ GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ GNUNET_free (testname);
+ }
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ return result;
+}
+
+
+/* end of perf_select_refunds_by_coin.c */
diff --git a/src/exchangedb/pg_abort_shard.c b/src/exchangedb/pg_abort_shard.c
new file mode 100644
index 000000000..d04680a81
--- /dev/null
+++ b/src/exchangedb/pg_abort_shard.c
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_abort_shard.c
+ * @brief Implementation of the abort_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_abort_shard.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_abort_shard (void *cls,
+ const char *job_name,
+ uint64_t start_row,
+ uint64_t end_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_uint64 (&start_row),
+ GNUNET_PQ_query_param_uint64 (&end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "abort_shard",
+ "UPDATE work_shards"
+ " SET last_attempt=0"
+ " WHERE job_name=$1"
+ " AND start_row=$2"
+ " AND end_row=$3;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "abort_shard",
+ params);
+}
diff --git a/src/exchangedb/pg_abort_shard.h b/src/exchangedb/pg_abort_shard.h
new file mode 100644
index 000000000..e52ace5f6
--- /dev/null
+++ b/src/exchangedb/pg_abort_shard.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_abort_shard.h
+ * @brief implementation of the abort_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ABORT_SHARD_H
+#define PG_ABORT_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to abort work on a shard.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param job_name name of the operation to abort a word shard for
+ * @param start_row inclusive start row of the shard
+ * @param end_row exclusive end row of the shard
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_abort_shard (void *cls,
+ const char *job_name,
+ uint64_t start_row,
+ uint64_t end_row);
+
+#endif
diff --git a/src/exchangedb/pg_activate_signing_key.c b/src/exchangedb/pg_activate_signing_key.c
new file mode 100644
index 000000000..fab2a0ffe
--- /dev/null
+++ b/src/exchangedb/pg_activate_signing_key.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_activate_signing_key.c
+ * @brief Implementation of the activate_signing_key function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_activate_signing_key.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_activate_signing_key (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam iparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_timestamp (&meta->start),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_sign),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_signkey",
+ "INSERT INTO exchange_sign_keys "
+ "(exchange_pub"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_signkey",
+ iparams);
+}
diff --git a/src/exchangedb/pg_activate_signing_key.h b/src/exchangedb/pg_activate_signing_key.h
new file mode 100644
index 000000000..2d4df0671
--- /dev/null
+++ b/src/exchangedb/pg_activate_signing_key.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_activate_signing_key.h
+ * @brief implementation of the activate_signing_key function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ACTIVATE_SIGNING_KEY_H
+#define PG_ACTIVATE_SIGNING_KEY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Add signing key.
+ *
+ * @param cls closure
+ * @param exchange_pub the exchange online signing public key
+ * @param meta meta data about @a exchange_pub
+ * @param master_sig master signature to add
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_activate_signing_key (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
+ const struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_add_denomination_key.c b/src/exchangedb/pg_add_denomination_key.c
new file mode 100644
index 000000000..eb50304d3
--- /dev/null
+++ b/src/exchangedb/pg_add_denomination_key.c
@@ -0,0 +1,86 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_add_denomination_key.c
+ * @brief Implementation of the add_denomination_key function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_add_denomination_key.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_add_denomination_key (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam iparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ TALER_PQ_query_param_denom_pub (denom_pub),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_timestamp (&meta->start),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_withdraw),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_deposit),
+ GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
+ TALER_PQ_query_param_amount (pg->conn,
+ &meta->value),
+ TALER_PQ_query_param_amount (pg->conn,
+ &meta->fees.withdraw),
+ TALER_PQ_query_param_amount (pg->conn,
+ &meta->fees.deposit),
+ TALER_PQ_query_param_amount (pg->conn,
+ &meta->fees.refresh),
+ TALER_PQ_query_param_amount (pg->conn,
+ &meta->fees.refund),
+ GNUNET_PQ_query_param_uint32 (&meta->age_mask.bits),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* Sanity check: ensure fees match coin currency */
+ GNUNET_assert (GNUNET_YES ==
+ TALER_denom_fee_check_currency (meta->value.currency,
+ &meta->fees));
+ PREPARE (pg,
+ "denomination_insert",
+ "INSERT INTO denominations "
+ "(denom_pub_hash"
+ ",denom_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin" /* value of this denom */
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
+ " $11, $12, $13);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "denomination_insert",
+ iparams);
+}
diff --git a/src/exchangedb/pg_add_denomination_key.h b/src/exchangedb/pg_add_denomination_key.h
new file mode 100644
index 000000000..d131679e8
--- /dev/null
+++ b/src/exchangedb/pg_add_denomination_key.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_add_denomination_key.h
+ * @brief implementation of the add_denomination_key function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ADD_DENOMINATION_KEY_H
+#define PG_ADD_DENOMINATION_KEY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Activate denomination key, turning it into a "current" or "valid"
+ * denomination key by adding the master signature.
+ *
+ * @param cls closure
+ * @param h_denom_pub hash of the denomination public key
+ * @param denom_pub the actual denomination key
+ * @param meta meta data about the denomination
+ * @param master_sig master signature to add
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_add_denomination_key (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
+ const struct TALER_MasterSignatureP *master_sig);
+#endif
diff --git a/src/exchangedb/pg_add_policy_fulfillment_proof.c b/src/exchangedb/pg_add_policy_fulfillment_proof.c
new file mode 100644
index 000000000..93d070712
--- /dev/null
+++ b/src/exchangedb/pg_add_policy_fulfillment_proof.c
@@ -0,0 +1,159 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_add_policy_fulfillment_proof.c
+ * @brief Implementation of the add_policy_fulfillment_proof function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_add_policy_fulfillment_proof.h"
+#include "pg_helper.h"
+
+
+/**
+ * Compares two indices into an array of hash codes according to
+ * GNUNET_CRYPTO_hash_cmp of the content at those index positions.
+ *
+ * Used in a call qsort_t in order to generate sorted policy_hash_codes.
+ */
+static int
+hash_code_cmp (
+ const void *hc1,
+ const void *hc2,
+ void *arg)
+{
+ size_t i1 = *(size_t *) hc1;
+ size_t i2 = *(size_t *) hc2;
+ const struct TALER_PolicyDetails *d = arg;
+
+ return GNUNET_CRYPTO_hash_cmp (&d[i1].hash_code,
+ &d[i2].hash_code);
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_add_policy_fulfillment_proof (
+ void *cls,
+ struct TALER_PolicyFulfillmentTransactionData *fulfillment)
+{
+ enum GNUNET_DB_QueryStatus qs;
+ struct PostgresClosure *pg = cls;
+ size_t count = fulfillment->details_count;
+ /* FIXME: this seems to be prone to VLA attacks */
+ struct GNUNET_HashCode hcs[count];
+
+ /* Create the sorted policy_hash_codes */
+ {
+ size_t idx[count];
+ for (size_t i = 0; i < count; i++)
+ idx[i] = i;
+
+ /* Sort the indices according to the hash codes of the corresponding
+ * details. */
+ qsort_r (idx,
+ count,
+ sizeof(size_t),
+ hash_code_cmp,
+ fulfillment->details);
+
+ /* Finally, concatenate all hash_codes in sorted order */
+ for (size_t i = 0; i < count; i++)
+ hcs[i] = fulfillment->details[idx[i]].hash_code;
+ }
+
+
+ /* Now, add the proof to the policy_fulfillments table, retrieve the
+ * record_id */
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&fulfillment->timestamp),
+ TALER_PQ_query_param_json (fulfillment->proof),
+ GNUNET_PQ_query_param_auto_from_type (&fulfillment->h_proof),
+ TALER_PQ_query_param_array_hash_code (count, hcs, pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("fulfillment_id",
+ &fulfillment->fulfillment_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "insert_proof_into_policy_fulfillments",
+ "INSERT INTO policy_fulfillments"
+ "(fulfillment_timestamp"
+ ",fulfillment_proof"
+ ",h_fulfillment_proof"
+ ",policy_hash_codes"
+ ") VALUES ($1, $2, $3, $4)"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "insert_proof_into_policy_fulfillments",
+ params,
+ rs);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ return qs;
+ }
+
+ /* Now, set the states of each entry corresponding to the hash_codes in
+ * policy_details accordingly */
+ for (size_t i = 0; i < count; i++)
+ {
+ struct TALER_PolicyDetails *pos = &fulfillment->details[i];
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&pos->hash_code),
+ GNUNET_PQ_query_param_timestamp (&pos->deadline),
+ TALER_PQ_query_param_amount (pg->conn,
+ &pos->commitment),
+ TALER_PQ_query_param_amount (pg->conn,
+ &pos->accumulated_total),
+ TALER_PQ_query_param_amount (pg->conn,
+ &pos->policy_fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ &pos->transferable_amount),
+ GNUNET_PQ_query_param_auto_from_type (&pos->fulfillment_state),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_policy_details",
+ "UPDATE policy_details SET"
+ " deadline=$2"
+ ",commitment=$3"
+ ",accumulated_total=$4"
+ ",fee=$5"
+ ",transferable=$6"
+ ",fulfillment_state=$7"
+ " WHERE policy_hash_code=$1;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_policy_details",
+ params);
+ if (qs < 0)
+ return qs;
+ }
+ }
+
+ /*
+ * FIXME[oec]-#7999: When all policies of a deposit are fulfilled,
+ * unblock it and trigger a wire-transfer.
+ */
+
+ return qs;
+}
diff --git a/src/exchangedb/pg_add_policy_fulfillment_proof.h b/src/exchangedb/pg_add_policy_fulfillment_proof.h
new file mode 100644
index 000000000..77bddaf08
--- /dev/null
+++ b/src/exchangedb/pg_add_policy_fulfillment_proof.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_add_policy_fulfillment_proof.h
+ * @brief implementation of the add_policy_fulfillment_proof function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ADD_POLICY_FULFILLMENT_PROOF_H
+#define PG_ADD_POLICY_FULFILLMENT_PROOF_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Add a proof of fulfillment into the policy_fulfillments table
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param fulfillment fullfilment transaction data to be added
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_add_policy_fulfillment_proof (
+ void *cls,
+ struct TALER_PolicyFulfillmentTransactionData *fulfillment);
+
+#endif
diff --git a/src/exchangedb/pg_aggregate.c b/src/exchangedb/pg_aggregate.c
new file mode 100644
index 000000000..ba03e4a9c
--- /dev/null
+++ b/src/exchangedb/pg_aggregate.c
@@ -0,0 +1,205 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_aggregate.c
+ * @brief Implementation of the aggregate function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_compute_shard.h"
+#include "pg_event_notify.h"
+#include "pg_aggregate.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_aggregate (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total)
+{
+ struct PostgresClosure *pg = cls;
+ uint64_t deposit_shard = TEH_PG_compute_shard (merchant_pub);
+ struct GNUNET_TIME_Absolute now = {0};
+ uint64_t sum_deposit_value;
+ uint64_t sum_deposit_frac;
+ uint64_t sum_refund_value;
+ uint64_t sum_refund_frac;
+ uint64_t sum_fee_value;
+ uint64_t sum_fee_frac;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_Amount sum_deposit;
+ struct TALER_Amount sum_refund;
+ struct TALER_Amount sum_fee;
+ struct TALER_Amount delta;
+
+ now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
+ pg->aggregator_shift);
+ PREPARE (pg,
+ "aggregate",
+ "WITH bdep AS (" /* restrict to our merchant and account and mark as done */
+ " UPDATE batch_deposits"
+ " SET done=TRUE"
+ " WHERE NOT (done OR policy_blocked)" /* only actually executable deposits */
+ " AND refund_deadline<$1"
+ " AND shard=$5" /* only for efficiency, merchant_pub is what we really filter by */
+ " AND merchant_pub=$2" /* filter by target merchant */
+ " AND wire_target_h_payto=$3" /* merchant could have a 2nd bank account */
+ " RETURNING"
+ " batch_deposit_serial_id)"
+ " ,cdep AS ("
+ " SELECT"
+ " coin_deposit_serial_id"
+ " ,batch_deposit_serial_id"
+ " ,coin_pub"
+ " ,amount_with_fee AS amount"
+ " FROM coin_deposits"
+ " WHERE batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
+ " ,ref AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " SELECT"
+ " amount_with_fee AS refund"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM refunds"
+ " WHERE coin_pub IN (SELECT coin_pub FROM cdep)"
+ " AND batch_deposit_serial_id IN (SELECT batch_deposit_serial_id FROM bdep))"
+ " ,ref_by_coin AS (" /* total up refunds by coin */
+ " SELECT"
+ " SUM((ref.refund).val) AS sum_refund_val"
+ " ,SUM((ref.refund).frac) AS sum_refund_frac"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM ref"
+ " GROUP BY coin_pub, batch_deposit_serial_id)"
+ " ,norm_ref_by_coin AS (" /* normalize */
+ " SELECT"
+ " sum_refund_val + sum_refund_frac / 100000000 AS norm_refund_val"
+ " ,sum_refund_frac % 100000000 AS norm_refund_frac"
+ " ,coin_pub"
+ " ,batch_deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
+ " FROM ref_by_coin)"
+ " ,fully_refunded_coins AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " SELECT"
+ " cdep.coin_pub"
+ " FROM norm_ref_by_coin norm"
+ " JOIN cdep"
+ " ON (norm.coin_pub = cdep.coin_pub"
+ " AND norm.batch_deposit_serial_id = cdep.batch_deposit_serial_id"
+ " AND norm.norm_refund_val = (cdep.amount).val"
+ " AND norm.norm_refund_frac = (cdep.amount).frac))"
+ " ,fees AS (" /* find deposit fees for not fully refunded deposits */
+ " SELECT"
+ " denom.fee_deposit AS fee"
+ " ,cs.batch_deposit_serial_id" /* ensures we get the fee for each coin, not once per denomination */
+ " FROM cdep cs"
+ " JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE coin_pub NOT IN (SELECT coin_pub FROM fully_refunded_coins))"
+ " ,dummy AS (" /* add deposits to aggregation_tracking */
+ " INSERT INTO aggregation_tracking"
+ " (batch_deposit_serial_id"
+ " ,wtid_raw)"
+ " SELECT batch_deposit_serial_id,$4"
+ " FROM bdep)"
+ "SELECT" /* calculate totals (deposits, refunds and fees) */
+ " CAST(COALESCE(SUM((cdep.amount).val),0) AS INT8) AS sum_deposit_value"
+ /* cast needed, otherwise we get NUMBER */
+ " ,COALESCE(SUM((cdep.amount).frac),0) AS sum_deposit_fraction" /* SUM over INT returns INT8 */
+ " ,CAST(COALESCE(SUM((ref.refund).val),0) AS INT8) AS sum_refund_value"
+ " ,COALESCE(SUM((ref.refund).frac),0) AS sum_refund_fraction"
+ " ,CAST(COALESCE(SUM((fees.fee).val),0) AS INT8) AS sum_fee_value"
+ " ,COALESCE(SUM((fees.fee).frac),0) AS sum_fee_fraction"
+ " FROM cdep "
+ " FULL OUTER JOIN ref ON (FALSE)" /* We just want all sums */
+ " FULL OUTER JOIN fees ON (FALSE);");
+
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_uint64 (&deposit_shard),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("sum_deposit_value",
+ &sum_deposit_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction",
+ &sum_deposit_frac),
+ GNUNET_PQ_result_spec_uint64 ("sum_refund_value",
+ &sum_refund_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction",
+ &sum_refund_frac),
+ GNUNET_PQ_result_spec_uint64 ("sum_fee_value",
+ &sum_fee_value),
+ GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction",
+ &sum_fee_frac),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "aggregate",
+ params,
+ rs);
+ }
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ total));
+ return qs;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_deposit));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_refund));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &sum_fee));
+ sum_deposit.value = sum_deposit_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_deposit_value;
+ sum_deposit.fraction = sum_deposit_frac % TALER_AMOUNT_FRAC_BASE;
+ sum_refund.value = sum_refund_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_refund_value;
+ sum_refund.fraction = sum_refund_frac % TALER_AMOUNT_FRAC_BASE;
+ sum_fee.value = sum_fee_frac / TALER_AMOUNT_FRAC_BASE
+ + sum_fee_value;
+ sum_fee.fraction = sum_fee_frac % TALER_AMOUNT_FRAC_BASE; \
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (&delta,
+ &sum_deposit,
+ &sum_refund));
+ GNUNET_assert (0 <=
+ TALER_amount_subtract (total,
+ &delta,
+ &sum_fee));
+ return qs;
+}
diff --git a/src/exchangedb/pg_aggregate.h b/src/exchangedb/pg_aggregate.h
new file mode 100644
index 000000000..1f986ef9e
--- /dev/null
+++ b/src/exchangedb/pg_aggregate.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_aggregate.h
+ * @brief implementation of the aggregate function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_AGGREGATE_H
+#define PG_AGGREGATE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Aggregate all matching deposits for @a h_payto and
+ * @a merchant_pub, returning the total amounts.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param merchant_pub public key of the merchant
+ * @param wtid wire transfer ID to set for the aggregate
+ * @param[out] total set to the sum of the total deposits minus applicable deposit fees and refunds
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_aggregate (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total);
+
+#endif
diff --git a/src/exchangedb/pg_batch_ensure_coin_known.c b/src/exchangedb/pg_batch_ensure_coin_known.c
new file mode 100644
index 000000000..aca2732c6
--- /dev/null
+++ b/src/exchangedb/pg_batch_ensure_coin_known.c
@@ -0,0 +1,462 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_batch_ensure_coin_known.c
+ * @brief Implementation of the batch_ensure_coin_known function for Postgres
+ * @author Christian Grothoff
+ *
+ * FIXME: use the array support for postgres to simplify this code!
+ *
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_pq_lib.h"
+#include "pg_batch_ensure_coin_known.h"
+#include "pg_helper.h"
+
+
+static enum GNUNET_DB_QueryStatus
+insert1 (struct PostgresClosure *pg,
+ const struct TALER_CoinPublicInfo coin[1],
+ struct TALER_EXCHANGEDB_CoinInfo result[1])
+{
+ enum GNUNET_DB_QueryStatus qs;
+ bool is_denom_pub_hash_null = false;
+ bool is_age_hash_null = false;
+ PREPARE (pg,
+ "batch1_known_coin",
+ "SELECT"
+ " existed1 AS existed"
+ ",known_coin_id1 AS known_coin_id"
+ ",denom_pub_hash1 AS denom_hash"
+ ",age_commitment_hash1 AS h_age_commitment"
+ " FROM exchange_do_batch1_known_coin"
+ " ($1, $2, $3, $4);"
+ );
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[0].denom_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("existed",
+ &result[0].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ &result[0].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &result[0].denom_hash),
+ &is_denom_pub_hash_null),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &result[0].h_age_commitment),
+ &is_age_hash_null),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "batch1_known_coin",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* should be impossible */
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break; /* continued below */
+ }
+
+ if ( (! is_denom_pub_hash_null) &&
+ (0 != GNUNET_memcmp (&result[0].denom_hash,
+ &coin->denom_pub_hash)) )
+ {
+ GNUNET_break_op (0);
+ result[0].denom_conflict = true;
+ }
+
+ if ( (! is_denom_pub_hash_null) &&
+ (0 != GNUNET_memcmp (&result[0].denom_hash,
+ &coin[0].denom_pub_hash)) )
+ {
+ GNUNET_break_op (0);
+ result[0].denom_conflict = true;
+ }
+
+ result[0].age_conflict = TALER_AgeCommitmentHash_NoConflict;
+
+ if (is_age_hash_null != coin[0].no_age_commitment)
+ {
+ if (is_age_hash_null)
+ {
+ GNUNET_break_op (0);
+ result[0].age_conflict = TALER_AgeCommitmentHash_NullExpected;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ result[0].age_conflict = TALER_AgeCommitmentHash_ValueExpected;
+ }
+ }
+ else if ( (! is_age_hash_null) &&
+ (0 != GNUNET_memcmp (&result[0].h_age_commitment,
+ &coin[0].h_age_commitment)) )
+ {
+ GNUNET_break_op (0);
+ result[0].age_conflict = TALER_AgeCommitmentHash_ValueDiffers;
+ }
+
+ return qs;
+}
+
+
+static enum GNUNET_DB_QueryStatus
+insert2 (struct PostgresClosure *pg,
+ const struct TALER_CoinPublicInfo coin[2],
+ struct TALER_EXCHANGEDB_CoinInfo result[2])
+{
+ enum GNUNET_DB_QueryStatus qs;
+ bool is_denom_pub_hash_null[2] = {false, false};
+ bool is_age_hash_null[2] = {false, false};
+
+ PREPARE (pg,
+ "batch2_known_coin",
+ "SELECT"
+ " existed1 AS existed"
+ ",known_coin_id1 AS known_coin_id"
+ ",denom_pub_hash1 AS denom_hash"
+ ",age_commitment_hash1 AS h_age_commitment"
+ ",existed2 AS existed2"
+ ",known_coin_id2 AS known_coin_id2"
+ ",denom_pub_hash2 AS denom_hash2"
+ ",age_commitment_hash2 AS h_age_commitment2"
+ " FROM exchange_do_batch2_known_coin"
+ " ($1, $2, $3, $4, $5, $6, $7, $8);"
+ );
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[0].denom_sig),
+
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[0].denom_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("existed",
+ &result[0].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ &result[0].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &result[0].denom_hash),
+ &is_denom_pub_hash_null[0]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &result[0].h_age_commitment),
+ &is_age_hash_null[0]),
+ GNUNET_PQ_result_spec_bool ("existed2",
+ &result[1].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id2",
+ &result[1].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash2",
+ &result[1].denom_hash),
+ &is_denom_pub_hash_null[1]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash2",
+ &result[1].h_age_commitment),
+ &is_age_hash_null[1]),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "batch2_known_coin",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* should be impossible */
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break; /* continued below */
+ }
+
+ for (int i = 0; i < 2; i++)
+ {
+ if ( (! is_denom_pub_hash_null[i]) &&
+ (0 != GNUNET_memcmp (&result[i].denom_hash,
+ &coin[i].denom_pub_hash)) )
+ {
+ GNUNET_break_op (0);
+ result[i].denom_conflict = true;
+ }
+
+ result[i].age_conflict = TALER_AgeCommitmentHash_NoConflict;
+
+ if (is_age_hash_null[i] != coin[i].no_age_commitment)
+ {
+ if (is_age_hash_null[i])
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_NullExpected;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_ValueExpected;
+ }
+ }
+ else if ( (! is_age_hash_null[i]) &&
+ (0 != GNUNET_memcmp (&result[i].h_age_commitment,
+ &coin[i].h_age_commitment)) )
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_ValueDiffers;
+ }
+ }
+
+ return qs;
+}
+
+
+static enum GNUNET_DB_QueryStatus
+insert4 (struct PostgresClosure *pg,
+ const struct TALER_CoinPublicInfo coin[4],
+ struct TALER_EXCHANGEDB_CoinInfo result[4])
+{
+ enum GNUNET_DB_QueryStatus qs;
+ bool is_denom_pub_hash_null[4] = {false, false, false, false};
+ bool is_age_hash_null[4] = {false, false, false, false};
+ PREPARE (pg,
+ "batch4_known_coin",
+ "SELECT"
+ " existed1 AS existed"
+ ",known_coin_id1 AS known_coin_id"
+ ",denom_pub_hash1 AS denom_hash"
+ ",age_commitment_hash1 AS h_age_commitment"
+ ",existed2 AS existed2"
+ ",known_coin_id2 AS known_coin_id2"
+ ",denom_pub_hash2 AS denom_hash2"
+ ",age_commitment_hash2 AS h_age_commitment2"
+ ",existed3 AS existed3"
+ ",known_coin_id3 AS known_coin_id3"
+ ",denom_pub_hash3 AS denom_hash3"
+ ",age_commitment_hash3 AS h_age_commitment3"
+ ",existed4 AS existed4"
+ ",known_coin_id4 AS known_coin_id4"
+ ",denom_pub_hash4 AS denom_hash4"
+ ",age_commitment_hash4 AS h_age_commitment4"
+ " FROM exchange_do_batch2_known_coin"
+ " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16);"
+ );
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[0].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[0].denom_sig),
+
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[1].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[0].denom_sig),
+
+ GNUNET_PQ_query_param_auto_from_type (&coin[2].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[2].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[2].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[2].denom_sig),
+
+ GNUNET_PQ_query_param_auto_from_type (&coin[3].coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin[3].denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (&coin[3].h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin[3].denom_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("existed",
+ &result[0].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ &result[0].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &result[0].denom_hash),
+ &is_denom_pub_hash_null[0]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &result[0].h_age_commitment),
+ &is_age_hash_null[0]),
+ GNUNET_PQ_result_spec_bool ("existed2",
+ &result[1].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id2",
+ &result[1].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash2",
+ &result[1].denom_hash),
+ &is_denom_pub_hash_null[1]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash2",
+ &result[1].h_age_commitment),
+ &is_age_hash_null[1]),
+ GNUNET_PQ_result_spec_bool ("existed3",
+ &result[2].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id3",
+ &result[2].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash3",
+ &result[2].denom_hash),
+ &is_denom_pub_hash_null[2]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash3",
+ &result[2].h_age_commitment),
+ &is_age_hash_null[2]),
+ GNUNET_PQ_result_spec_bool ("existed4",
+ &result[3].existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id4",
+ &result[3].known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash4",
+ &result[3].denom_hash),
+ &is_denom_pub_hash_null[3]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash4",
+ &result[3].h_age_commitment),
+ &is_age_hash_null[3]),
+ GNUNET_PQ_result_spec_end
+ };
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "batch4_known_coin",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* should be impossible */
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break; /* continued below */
+ }
+
+ for (int i = 0; i < 4; i++)
+ {
+ if ( (! is_denom_pub_hash_null[i]) &&
+ (0 != GNUNET_memcmp (&result[i].denom_hash,
+ &coin[i].denom_pub_hash)) )
+ {
+ GNUNET_break_op (0);
+ result[i].denom_conflict = true;
+ }
+
+ result[i].age_conflict = TALER_AgeCommitmentHash_NoConflict;
+
+ if (is_age_hash_null[i] != coin[i].no_age_commitment)
+ {
+ if (is_age_hash_null[i])
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_NullExpected;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_ValueExpected;
+ }
+ }
+ else if ( (! is_age_hash_null[i]) &&
+ (0 != GNUNET_memcmp (&result[i].h_age_commitment,
+ &coin[i].h_age_commitment)) )
+ {
+ GNUNET_break_op (0);
+ result[i].age_conflict = TALER_AgeCommitmentHash_ValueDiffers;
+ }
+ }
+
+ return qs;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_batch_ensure_coin_known (
+ void *cls,
+ const struct TALER_CoinPublicInfo *coin,
+ struct TALER_EXCHANGEDB_CoinInfo *result,
+ unsigned int coin_length,
+ unsigned int batch_size)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs = 0;
+ unsigned int i = 0;
+
+ while ( (qs >= 0) &&
+ (i < coin_length) )
+ {
+ unsigned int bs = GNUNET_MIN (batch_size,
+ coin_length - i);
+ if (bs >= 4)
+ {
+ qs = insert4 (pg,
+ &coin[i],
+ &result[i]);
+ i += 4;
+ continue;
+ }
+ switch (bs)
+ {
+ case 3:
+ case 2:
+ qs = insert2 (pg,
+ &coin[i],
+ &result[i]);
+ i += 2;
+ break;
+ case 1:
+ qs = insert1 (pg,
+ &coin[i],
+ &result[i]);
+ i += 1;
+ break;
+ case 0:
+ GNUNET_assert (0);
+ break;
+ }
+ } /* end while */
+ if (qs < 0)
+ return qs;
+ return i;
+}
diff --git a/src/exchangedb/pg_batch_ensure_coin_known.h b/src/exchangedb/pg_batch_ensure_coin_known.h
new file mode 100644
index 000000000..2c53676d9
--- /dev/null
+++ b/src/exchangedb/pg_batch_ensure_coin_known.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_batch_ensure_coin_known.h
+ * @brief implementation of the batch_ensure_coin_known function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_BATCH_ENSURE_COIN_KNOWN_H
+#define PG_BATCH_ENSURE_COIN_KNOWN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Make sure the array of given @a coin is known to the database.
+ *
+ * @param cls database connection plugin state
+ * @param coin array of coins that must be made known
+ * @param[out] result array where to store information about each coin
+ * @param coin_length length of the @a coin and @a result arraysf
+ * @param batch_size desired (maximum) batch size
+ * @return database transaction status, non-negative on success
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_batch_ensure_coin_known (
+ void *cls,
+ const struct TALER_CoinPublicInfo *coin,
+ struct TALER_EXCHANGEDB_CoinInfo *result,
+ unsigned int coin_length,
+ unsigned int batch_size);
+
+#endif
diff --git a/src/exchangedb/pg_begin_revolving_shard.c b/src/exchangedb/pg_begin_revolving_shard.c
new file mode 100644
index 000000000..86cdf80fd
--- /dev/null
+++ b/src/exchangedb/pg_begin_revolving_shard.c
@@ -0,0 +1,263 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_begin_revolving_shard.c
+ * @brief Implementation of the begin_revolving_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_begin_revolving_shard.h"
+#include "pg_commit.h"
+#include "pg_helper.h"
+#include "pg_start.h"
+#include "pg_rollback.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_begin_revolving_shard (void *cls,
+ const char *job_name,
+ uint32_t shard_size,
+ uint32_t shard_limit,
+ uint32_t *start_row,
+ uint32_t *end_row)
+{
+ struct PostgresClosure *pg = cls;
+
+ GNUNET_assert (shard_limit <= 1U + (uint32_t) INT_MAX);
+ GNUNET_assert (shard_limit > 0);
+ GNUNET_assert (shard_size > 0);
+ for (unsigned int retries = 0; retries<3; retries++)
+ {
+ if (GNUNET_OK !=
+ TEH_PG_start (pg,
+ "begin_revolving_shard"))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ /* First, find last 'end_row' */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ uint32_t last_end;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("end_row",
+ &last_end),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_begin_revolving_shard() */
+ PREPARE (pg,
+ "get_last_revolving_shard",
+ "SELECT"
+ " end_row"
+ " FROM revolving_work_shards"
+ " WHERE job_name=$1"
+ " ORDER BY end_row DESC"
+ " LIMIT 1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_last_revolving_shard",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ *start_row = 1U + last_end;
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ *start_row = 0; /* base-case: no shards yet */
+ break; /* continued below */
+ }
+ } /* get_last_shard */
+
+ if (*start_row < shard_limit)
+ {
+ /* Claim fresh shard */
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute now;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_uint32 (start_row),
+ GNUNET_PQ_query_param_uint32 (end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ *end_row = GNUNET_MIN (shard_limit,
+ *start_row + shard_size - 1);
+ now = GNUNET_TIME_absolute_get ();
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Trying to claim shard %llu-%llu\n",
+ (unsigned long long) *start_row,
+ (unsigned long long) *end_row);
+
+ /* Used in #postgres_claim_revolving_shard() */
+ PREPARE (pg,
+ "create_revolving_shard",
+ "INSERT INTO revolving_work_shards"
+ "(job_name"
+ ",last_attempt"
+ ",start_row"
+ ",end_row"
+ ",active"
+ ") VALUES "
+ "($1, $2, $3, $4, TRUE);");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "create_revolving_shard",
+ params);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* continued below (with commit) */
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* someone else got this shard already,
+ try again */
+ TEH_PG_rollback (pg);
+ continue;
+ }
+ } /* end create fresh reovlving shard */
+ else
+ {
+ /* claim oldest existing shard */
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint32 ("start_row",
+ start_row),
+ GNUNET_PQ_result_spec_uint32 ("end_row",
+ end_row),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_begin_revolving_shard() */
+ PREPARE (pg,
+ "get_open_revolving_shard",
+ "SELECT"
+ " start_row"
+ ",end_row"
+ " FROM revolving_work_shards"
+ " WHERE job_name=$1"
+ " AND active=FALSE"
+ " ORDER BY last_attempt ASC"
+ " LIMIT 1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_open_revolving_shard",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* no open shards available */
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp now;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_uint32 (start_row),
+ GNUNET_PQ_query_param_uint32 (end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ now = GNUNET_TIME_timestamp_get ();
+
+ /* Used in #postgres_begin_revolving_shard() */
+ PREPARE (pg,
+ "reclaim_revolving_shard",
+ "UPDATE revolving_work_shards"
+ " SET last_attempt=$2"
+ " ,active=TRUE"
+ " WHERE job_name=$1"
+ " AND start_row=$3"
+ " AND end_row=$4");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "reclaim_revolving_shard",
+ params);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break; /* continue with commit */
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* logic error, should be impossible */
+ TEH_PG_rollback (pg);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ }
+ break; /* continue with commit */
+ }
+ } /* end claim oldest existing shard */
+
+ /* commit */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_PG_commit (pg);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ } /* retry 'for' loop */
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+}
diff --git a/src/exchangedb/pg_begin_revolving_shard.h b/src/exchangedb/pg_begin_revolving_shard.h
new file mode 100644
index 000000000..0755f886b
--- /dev/null
+++ b/src/exchangedb/pg_begin_revolving_shard.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_begin_revolving_shard.h
+ * @brief implementation of the begin_revolving_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_BEGIN_REVOLVING_SHARD_H
+#define PG_BEGIN_REVOLVING_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to grab a revolving work shard on an operation @a op. Runs
+ * in its own transaction. Returns the oldest inactive shard.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param job_name name of the operation to grab a revolving shard for
+ * @param shard_size desired shard size
+ * @param shard_limit exclusive end of the shard range
+ * @param[out] start_row inclusive start row of the shard (returned)
+ * @param[out] end_row inclusive end row of the shard (returned)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_begin_revolving_shard (void *cls,
+ const char *job_name,
+ uint32_t shard_size,
+ uint32_t shard_limit,
+ uint32_t *start_row,
+ uint32_t *end_row);
+
+#endif
diff --git a/src/exchangedb/pg_begin_shard.c b/src/exchangedb/pg_begin_shard.c
new file mode 100644
index 000000000..48e077990
--- /dev/null
+++ b/src/exchangedb/pg_begin_shard.c
@@ -0,0 +1,266 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_begin_shard.c
+ * @brief Implementation of the begin_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_begin_shard.h"
+#include "pg_helper.h"
+#include "pg_start.h"
+#include "pg_rollback.h"
+#include "pg_commit.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_begin_shard (void *cls,
+ const char *job_name,
+ struct GNUNET_TIME_Relative delay,
+ uint64_t shard_size,
+ uint64_t *start_row,
+ uint64_t *end_row)
+{
+ struct PostgresClosure *pg = cls;
+
+ for (unsigned int retries = 0; retries<10; retries++)
+ {
+ if (GNUNET_OK !=
+ TEH_PG_start (pg,
+ "begin_shard"))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ {
+ struct GNUNET_TIME_Absolute past;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_absolute_time (&past),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("start_row",
+ start_row),
+ GNUNET_PQ_result_spec_uint64 ("end_row",
+ end_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ past = GNUNET_TIME_absolute_get ();
+ PREPARE (pg,
+ "get_open_shard",
+ "SELECT"
+ " start_row"
+ ",end_row"
+ " FROM work_shards"
+ " WHERE job_name=$1"
+ " AND completed=FALSE"
+ " AND last_attempt<$2"
+ " ORDER BY last_attempt ASC"
+ " LIMIT 1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_open_shard",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization error on getting open shard\n");
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute now;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_uint64 (start_row),
+ GNUNET_PQ_query_param_uint64 (end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ now = GNUNET_TIME_relative_to_absolute (delay);
+ PREPARE (pg,
+ "reclaim_shard",
+ "UPDATE work_shards"
+ " SET last_attempt=$2"
+ " WHERE job_name=$1"
+ " AND start_row=$3"
+ " AND end_row=$4");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "reclaim_shard",
+ params);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization error on claiming open shard\n");
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ goto commit;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* logic error, should be impossible */
+ TEH_PG_rollback (pg);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ }
+ break; /* actually unreachable */
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ break; /* continued below */
+ }
+ } /* get_open_shard */
+
+ /* No open shard, find last 'end_row' */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("end_row",
+ start_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_last_shard",
+ "SELECT"
+ " end_row"
+ " FROM work_shards"
+ " WHERE job_name=$1"
+ " ORDER BY end_row DESC"
+ " LIMIT 1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_last_shard",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization error on getting last shard\n");
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ *start_row = 0; /* base-case: no shards yet */
+ break; /* continued below */
+ }
+ *end_row = *start_row + shard_size;
+ } /* get_last_shard */
+
+ /* Claim fresh shard */
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Absolute now;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_uint64 (start_row),
+ GNUNET_PQ_query_param_uint64 (end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ now = GNUNET_TIME_relative_to_absolute (delay);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Trying to claim shard (%llu-%llu]\n",
+ (unsigned long long) *start_row,
+ (unsigned long long) *end_row);
+
+ PREPARE (pg,
+ "claim_next_shard",
+ "INSERT INTO work_shards"
+ "(job_name"
+ ",last_attempt"
+ ",start_row"
+ ",end_row"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "claim_next_shard",
+ params);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization error on claiming next shard\n");
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ /* continued below */
+ break;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ /* someone else got this shard already,
+ try again */
+ TEH_PG_rollback (pg);
+ continue;
+ }
+ } /* claim_next_shard */
+
+ /* commit */
+commit:
+ {
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_PG_commit (pg);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Serialization error on commit for beginning shard\n");
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Claimed new shard\n");
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ } /* retry 'for' loop */
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+}
diff --git a/src/exchangedb/pg_begin_shard.h b/src/exchangedb/pg_begin_shard.h
new file mode 100644
index 000000000..16f19491d
--- /dev/null
+++ b/src/exchangedb/pg_begin_shard.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_begin_shard.h
+ * @brief implementation of the begin_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_BEGIN_SHARD_H
+#define PG_BEGIN_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to grab a work shard on an operation @a op. Runs in its
+ * own transaction.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param job_name name of the operation to grab a word shard for
+ * @param delay minimum age of a shard to grab
+ * @param shard_size desired shard size
+ * @param[out] start_row inclusive start row of the shard (returned)
+ * @param[out] end_row exclusive end row of the shard (returned)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_begin_shard (void *cls,
+ const char *job_name,
+ struct GNUNET_TIME_Relative delay,
+ uint64_t shard_size,
+ uint64_t *start_row,
+ uint64_t *end_row);
+
+#endif
diff --git a/src/exchangedb/pg_commit.c b/src/exchangedb/pg_commit.c
new file mode 100644
index 000000000..8c4f87c90
--- /dev/null
+++ b/src/exchangedb/pg_commit.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_commit.c
+ * @brief Implementation of the commit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_commit.h"
+#include "pg_helper.h"
+
+
+/**
+ * Commit the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return final transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_commit (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_break (NULL != pg->transaction_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Committing transaction `%s'\n",
+ pg->transaction_name);
+ /* used in #postgres_commit */
+ PREPARE (pg,
+ "do_commit",
+ "COMMIT");
+
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "do_commit",
+ params);
+ pg->transaction_name = NULL;
+ return qs;
+}
diff --git a/src/exchangedb/pg_commit.h b/src/exchangedb/pg_commit.h
new file mode 100644
index 000000000..b1f4f9615
--- /dev/null
+++ b/src/exchangedb/pg_commit.h
@@ -0,0 +1,37 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_commit.h
+ * @brief implementation of the commit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_COMMIT_H
+#define PG_COMMIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Commit the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return final transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_commit (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_complete_shard.c b/src/exchangedb/pg_complete_shard.c
new file mode 100644
index 000000000..8e62809c5
--- /dev/null
+++ b/src/exchangedb/pg_complete_shard.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_complete_shard.c
+ * @brief Implementation of the complete_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_complete_shard.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_complete_shard (void *cls,
+ const char *job_name,
+ uint64_t start_row,
+ uint64_t end_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_uint64 (&start_row),
+ GNUNET_PQ_query_param_uint64 (&end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Completing shard %llu-%llu\n",
+ (unsigned long long) start_row,
+ (unsigned long long) end_row);
+ PREPARE (pg,
+ "complete_shard",
+ "UPDATE work_shards"
+ " SET completed=TRUE"
+ " WHERE job_name=$1"
+ " AND start_row=$2"
+ " AND end_row=$3");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "complete_shard",
+ params);
+}
diff --git a/src/exchangedb/pg_complete_shard.h b/src/exchangedb/pg_complete_shard.h
new file mode 100644
index 000000000..f06c0483b
--- /dev/null
+++ b/src/exchangedb/pg_complete_shard.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_complete_shard.h
+ * @brief implementation of the complete_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_COMPLETE_SHARD_H
+#define PG_COMPLETE_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to persist that work on a shard was completed.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param job_name name of the operation to grab a word shard for
+ * @param start_row inclusive start row of the shard
+ * @param end_row exclusive end row of the shard
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_complete_shard (void *cls,
+ const char *job_name,
+ uint64_t start_row,
+ uint64_t end_row);
+
+#endif
diff --git a/src/exchangedb/pg_compute_shard.c b/src/exchangedb/pg_compute_shard.c
new file mode 100644
index 000000000..1dea591f1
--- /dev/null
+++ b/src/exchangedb/pg_compute_shard.c
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_compute_shard.c
+ * @brief Implementation of the compute_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_compute_shard.h"
+#include "pg_helper.h"
+
+
+uint64_t
+TEH_PG_compute_shard (const struct TALER_MerchantPublicKeyP *merchant_pub)
+{
+ uint32_t res;
+
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (&res,
+ sizeof (res),
+ merchant_pub,
+ sizeof (*merchant_pub),
+ "VOID",
+ 4,
+ NULL, 0));
+ /* interpret hash result as NBO for platform independence,
+ convert to HBO and map to [0..2^31-1] range */
+ res = ntohl (res);
+ if (res > INT32_MAX)
+ res += INT32_MIN;
+ GNUNET_assert (res <= INT32_MAX);
+ return (uint64_t) res;
+}
diff --git a/src/exchangedb/pg_compute_shard.h b/src/exchangedb/pg_compute_shard.h
new file mode 100644
index 000000000..d9bde2d3e
--- /dev/null
+++ b/src/exchangedb/pg_compute_shard.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_compute_shard.h
+ * @brief implementation of the compute_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_COMPUTE_SHARD_H
+#define PG_COMPUTE_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Compute the shard number of a given @a merchant_pub.
+ *
+ * @param merchant_pub merchant public key to compute shard for
+ * @return shard number
+ */
+uint64_t
+TEH_PG_compute_shard (const struct TALER_MerchantPublicKeyP *merchant_pub);
+
+
+#endif
diff --git a/src/exchangedb/pg_count_known_coins.c b/src/exchangedb/pg_count_known_coins.c
new file mode 100644
index 000000000..872965ac9
--- /dev/null
+++ b/src/exchangedb/pg_count_known_coins.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_count_known_coins.c
+ * @brief Implementation of the count_known_coins function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_count_known_coins.h"
+#include "pg_helper.h"
+
+long long
+TEH_PG_count_known_coins (void *cls,
+ const struct
+ TALER_DenominationHashP *denom_pub_hash)
+{
+ struct PostgresClosure *pg = cls;
+ uint64_t count;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("count",
+ &count),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "count_known_coins",
+ "SELECT"
+ " COUNT(*) AS count"
+ " FROM known_coins"
+ " WHERE denominations_serial="
+ " (SELECT denominations_serial"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "count_known_coins",
+ params,
+ rs);
+ if (0 > qs)
+ return (long long) qs;
+ return (long long) count;
+}
diff --git a/src/exchangedb/pg_count_known_coins.h b/src/exchangedb/pg_count_known_coins.h
new file mode 100644
index 000000000..69f07bdf4
--- /dev/null
+++ b/src/exchangedb/pg_count_known_coins.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_count_known_coins.h
+ * @brief implementation of the count_known_coins function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_COUNT_KNOWN_COINS_H
+#define PG_COUNT_KNOWN_COINS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Count the number of known coins by denomination.
+ *
+ * @param cls database connection plugin state
+ * @param denom_pub_hash denomination to count by
+ * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus`
+ */
+long long
+TEH_PG_count_known_coins (void *cls,
+ const struct
+ TALER_DenominationHashP *denom_pub_hash);
+
+#endif
diff --git a/src/exchangedb/pg_create_aggregation_transient.c b/src/exchangedb/pg_create_aggregation_transient.c
new file mode 100644
index 000000000..4ab537d3a
--- /dev/null
+++ b/src/exchangedb/pg_create_aggregation_transient.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_create_aggregation_transient.c
+ * @brief Implementation of the create_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_create_aggregation_transient.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_create_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ total),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "create_aggregation_transient",
+ "INSERT INTO aggregation_transient"
+ " (amount"
+ " ,merchant_pub"
+ " ,wire_target_h_payto"
+ " ,legitimization_requirement_serial_id"
+ " ,exchange_account_section"
+ " ,wtid_raw)"
+ " VALUES ($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "create_aggregation_transient",
+ params);
+}
diff --git a/src/exchangedb/pg_create_aggregation_transient.h b/src/exchangedb/pg_create_aggregation_transient.h
new file mode 100644
index 000000000..2f0a348b2
--- /dev/null
+++ b/src/exchangedb/pg_create_aggregation_transient.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_create_aggregation_transient.h
+ * @brief implementation of the create_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_CREATE_AGGREGATION_TRANSIENT_H
+#define PG_CREATE_AGGREGATION_TRANSIENT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Create a new entry in the transient aggregation table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param exchange_account_section exchange account to use
+ * @param merchant_pub public key of the merchant receiving the transfer
+ * @param wtid the raw wire transfer identifier to be used
+ * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
+ * @param total amount to be wired in the future
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_create_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total);
+
+#endif
diff --git a/src/exchangedb/pg_create_tables.c b/src/exchangedb/pg_create_tables.c
new file mode 100644
index 000000000..f6a061904
--- /dev/null
+++ b/src/exchangedb/pg_create_tables.c
@@ -0,0 +1,72 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_create_tables.c
+ * @brief Implementation of the create_tables function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_create_tables.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_GenericReturnValue
+TEH_PG_create_tables (void *cls,
+ bool support_partitions,
+ uint32_t num_partitions)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_Context *conn;
+ enum GNUNET_GenericReturnValue ret = GNUNET_OK;
+ struct GNUNET_PQ_QueryParam params[] = {
+ support_partitions
+ ? GNUNET_PQ_query_param_uint32 (&num_partitions)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ GNUNET_PQ_make_prepare ("create_tables",
+ "SELECT"
+ " exchange.do_create_tables"
+ " ($1);"),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "exchangedb-postgres",
+ "exchange-",
+ es,
+ ps);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ if (0 >
+ GNUNET_PQ_eval_prepared_non_select (conn,
+ "create_tables",
+ params))
+ ret = GNUNET_SYSERR;
+ if (GNUNET_OK == ret)
+ ret = GNUNET_PQ_exec_sql (conn,
+ "procedures");
+ GNUNET_PQ_disconnect (conn);
+ return ret;
+}
diff --git a/src/exchangedb/pg_create_tables.h b/src/exchangedb/pg_create_tables.h
new file mode 100644
index 000000000..58f5aae73
--- /dev/null
+++ b/src/exchangedb/pg_create_tables.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_create_tables.h
+ * @brief implementation of the create_tables function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_CREATE_TABLES_H
+#define PG_CREATE_TABLES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Create the necessary tables if they are not present
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param support_partitions true to enable partitioning support (disables foreign key constraints)
+ * @param num_partitions number of partitions to create,
+ * (0 to not actually use partitions, 1 to only
+ * setup a default partition, >1 for real partitions)
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_create_tables (void *cls,
+ bool support_partitions,
+ uint32_t num_partitions);
+
+
+#endif
diff --git a/src/exchangedb/pg_delete_aggregation_transient.c b/src/exchangedb/pg_delete_aggregation_transient.c
new file mode 100644
index 000000000..63c5c0a23
--- /dev/null
+++ b/src/exchangedb/pg_delete_aggregation_transient.c
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_delete_aggregation_transient.c
+ * @brief Implementation of the delete_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_aggregation_transient.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_delete_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_WireTransferIdentifierRawP *wtid)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "delete_aggregation_transient",
+ "DELETE FROM aggregation_transient"
+ " WHERE wire_target_h_payto=$1"
+ " AND wtid_raw=$2");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "delete_aggregation_transient",
+ params);
+}
diff --git a/src/exchangedb/pg_delete_aggregation_transient.h b/src/exchangedb/pg_delete_aggregation_transient.h
new file mode 100644
index 000000000..f74b0179e
--- /dev/null
+++ b/src/exchangedb/pg_delete_aggregation_transient.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_delete_aggregation_transient.h
+ * @brief implementation of the delete_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DELETE_AGGREGATION_TRANSIENT_H
+#define PG_DELETE_AGGREGATION_TRANSIENT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Delete existing entry in the transient aggregation table.
+ * @a h_payto is only needed for query performance.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param wtid the raw wire transfer identifier to update
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_delete_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_WireTransferIdentifierRawP *wtid);
+
+#endif
diff --git a/src/exchangedb/pg_delete_shard_locks.c b/src/exchangedb/pg_delete_shard_locks.c
new file mode 100644
index 000000000..dbb0f29ac
--- /dev/null
+++ b/src/exchangedb/pg_delete_shard_locks.c
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_delete_shard_locks.c
+ * @brief Implementation of the delete_shard_locks function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_delete_shard_locks.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_GenericReturnValue
+TEH_PG_delete_shard_locks (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("DELETE FROM work_shards;"),
+ GNUNET_PQ_make_execute ("DELETE FROM revolving_work_shards;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ return GNUNET_PQ_exec_statements (pg->conn,
+ es);
+}
diff --git a/src/exchangedb/pg_delete_shard_locks.h b/src/exchangedb/pg_delete_shard_locks.h
new file mode 100644
index 000000000..e8df2d67d
--- /dev/null
+++ b/src/exchangedb/pg_delete_shard_locks.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_delete_shard_locks.h
+ * @brief implementation of the delete_shard_locks function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DELETE_SHARD_LOCKS_H
+#define PG_DELETE_SHARD_LOCKS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to delete all revolving shards.
+ * To be used after a crash or when the shard size is
+ * changed.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @return transaction status code
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_delete_shard_locks (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_do_age_withdraw.c b/src/exchangedb/pg_do_age_withdraw.c
new file mode 100644
index 000000000..970e65b5d
--- /dev/null
+++ b/src/exchangedb/pg_do_age_withdraw.c
@@ -0,0 +1,108 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_batch_withdraw.c
+ * @brief Implementation of the do_batch_withdraw function for Postgres
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_pq_lib.h"
+#include "taler_pq_lib.h"
+#include "pg_do_batch_withdraw.h"
+#include "pg_helper.h"
+#include <gnunet/gnunet_time_lib.h>
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_age_withdraw (
+ void *cls,
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ struct GNUNET_TIME_Timestamp now,
+ bool *found,
+ bool *balance_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *required_age,
+ uint32_t *reserve_birthday,
+ bool *conflict)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp gc;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ &commitment->amount_with_fee),
+ GNUNET_PQ_query_param_auto_from_type (&commitment->reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (&commitment->reserve_sig),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_timestamp (&gc),
+ GNUNET_PQ_query_param_auto_from_type (&commitment->h_commitment),
+ GNUNET_PQ_query_param_uint16 (&commitment->max_age),
+ GNUNET_PQ_query_param_uint16 (&commitment->noreveal_index),
+ TALER_PQ_query_param_array_blinded_coin_hash (commitment->num_coins,
+ commitment->h_coin_evs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (commitment->num_coins,
+ commitment->denom_serials,
+ pg->conn),
+ TALER_PQ_query_param_array_blinded_denom_sig (commitment->num_coins,
+ commitment->denom_sigs,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("reserve_found",
+ found),
+ GNUNET_PQ_result_spec_bool ("balance_ok",
+ balance_ok),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
+ reserve_balance),
+ GNUNET_PQ_result_spec_bool ("age_ok",
+ age_ok),
+ GNUNET_PQ_result_spec_uint16 ("required_age",
+ required_age),
+ GNUNET_PQ_result_spec_uint32 ("reserve_birthday",
+ reserve_birthday),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ conflict),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ gc = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (now.abs_time,
+ pg->legal_reserve_expiration_time));
+ PREPARE (pg,
+ "call_age_withdraw",
+ "SELECT "
+ " reserve_found"
+ ",balance_ok"
+ ",reserve_balance"
+ ",age_ok"
+ ",required_age"
+ ",reserve_birthday"
+ ",conflict"
+ " FROM exchange_do_age_withdraw"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_age_withdraw",
+ params,
+ rs);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+}
diff --git a/src/exchangedb/pg_do_age_withdraw.h b/src/exchangedb/pg_do_age_withdraw.h
new file mode 100644
index 000000000..fb435a309
--- /dev/null
+++ b/src/exchangedb/pg_do_age_withdraw.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_age_withdraw.h
+ * @brief implementation of the do_age_withdraw function for Postgres
+ * @author Özgür Kesim
+ */
+#ifndef PG_DO_AGE_WITHDRAW_H
+#define PG_DO_AGE_WITHDRAW_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform reserve update as part of an age-withdraw operation, checking for
+ * sufficient balance and fulfillment of age requirements. Finally persisting
+ * the withdrawal details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param commitment the commitment with all parameters
+ * @param now current time (rounded)
+ * @param[out] found set to true if the reserve was found
+ * @param[out] balance_ok set to true if the balance was sufficient
+ * @param[out] reserve_balance set to the original reserve balance (at the start of this transaction)
+ * @param[out] age_ok set to true if no age requirements are present on the reserve
+ * @param[out] required_age if @e age_ok is false, set to the maximum allowed age when withdrawing from this reserve
+ * @param[out] reserve_birthday if @e age_ok is false, set to the birthday of the reserve
+ * @param[out] conflict set to true if there already is an entry in the database for the given pair (h_commitment, reserve_pub)
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_age_withdraw (
+ void *cls,
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ const struct GNUNET_TIME_Timestamp now,
+ bool *found,
+ bool *balance_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *required_age,
+ uint32_t *reserve_birthday,
+ bool *conflict);
+
+#endif
diff --git a/src/exchangedb/pg_do_batch_withdraw.c b/src/exchangedb/pg_do_batch_withdraw.c
new file mode 100644
index 000000000..f5571ddbb
--- /dev/null
+++ b/src/exchangedb/pg_do_batch_withdraw.c
@@ -0,0 +1,89 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_batch_withdraw.c
+ * @brief Implementation of the do_batch_withdraw function for Postgres
+ * @author Christian Grothoff
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_batch_withdraw.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_batch_withdraw (
+ void *cls,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *amount,
+ bool do_age_check,
+ bool *found,
+ bool *balance_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *allowed_maximum_age,
+ uint64_t *ruuid)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp gc;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_timestamp (&gc),
+ GNUNET_PQ_query_param_bool (do_age_check),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("reserve_found",
+ found),
+ GNUNET_PQ_result_spec_bool ("balance_ok",
+ balance_ok),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_balance",
+ reserve_balance),
+ GNUNET_PQ_result_spec_bool ("age_ok",
+ age_ok),
+ GNUNET_PQ_result_spec_uint16 ("allowed_maximum_age",
+ allowed_maximum_age),
+ GNUNET_PQ_result_spec_uint64 ("ruuid",
+ ruuid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ gc = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (now.abs_time,
+ pg->legal_reserve_expiration_time));
+ PREPARE (pg,
+ "call_batch_withdraw",
+ "SELECT "
+ " reserve_found"
+ ",balance_ok"
+ ",reserve_balance"
+ ",age_ok"
+ ",allowed_maximum_age"
+ ",ruuid"
+ " FROM exchange_do_batch_withdraw"
+ " ($1,$2,$3,$4,$5);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_batch_withdraw",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_batch_withdraw.h b/src/exchangedb/pg_do_batch_withdraw.h
new file mode 100644
index 000000000..486f8d1b2
--- /dev/null
+++ b/src/exchangedb/pg_do_batch_withdraw.h
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_batch_withdraw.h
+ * @brief implementation of the do_batch_withdraw function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_BATCH_WITHDRAW_H
+#define PG_DO_BATCH_WITHDRAW_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform reserve update as part of a batch withdraw operation, checking
+ * for sufficient balance. Persisting the withdrawal details is done
+ * separately!
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param now current time (rounded)
+ * @param reserve_pub public key of the reserve to debit
+ * @param amount total amount to withdraw
+ * @param age_check_required if true, fail if age requirements are set on the reserve
+ * @param[out] found set to true if the reserve was found
+ * @param[out] balance_ok set to true if the balance was sufficient
+ * @param[out] reserve_balance set to the original reserve balance (at the start of this transaction)
+ * @param[out] age_ok set to true if no age requirements are present on the reserve
+ * @param[out] allowed_maximum_age if @e age_ok is false, set to the maximum allowed age when withdrawing from this reserve (client needs to call age-withdraw)
+ * @param[out] ruuid set to the reserve's UUID (reserves table row)
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_batch_withdraw (
+ void *cls,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *amount,
+ bool age_check_required,
+ bool *found,
+ bool *balance_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *allowed_maximum_age,
+ uint64_t *ruuid);
+
+#endif
diff --git a/src/exchangedb/pg_do_batch_withdraw_insert.c b/src/exchangedb/pg_do_batch_withdraw_insert.c
new file mode 100644
index 000000000..758f502f2
--- /dev/null
+++ b/src/exchangedb/pg_do_batch_withdraw_insert.c
@@ -0,0 +1,77 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_batch_withdraw_insert.c
+ * @brief Implementation of the do_batch_withdraw_insert function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_batch_withdraw_insert.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_batch_withdraw_insert (
+ void *cls,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
+ const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
+ struct GNUNET_TIME_Timestamp now,
+ uint64_t ruuid,
+ bool *denom_unknown,
+ bool *conflict,
+ bool *nonce_reuse)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ NULL == nonce
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (nonce),
+ TALER_PQ_query_param_amount (pg->conn,
+ &collectable->amount_with_fee),
+ GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash),
+ GNUNET_PQ_query_param_uint64 (&ruuid),
+ GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
+ GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
+ TALER_PQ_query_param_blinded_denom_sig (&collectable->sig),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("denom_unknown",
+ denom_unknown),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ conflict),
+ GNUNET_PQ_result_spec_bool ("nonce_reuse",
+ nonce_reuse),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "call_batch_withdraw_insert",
+ "SELECT "
+ " out_denom_unknown AS denom_unknown"
+ ",out_conflict AS conflict"
+ ",out_nonce_reuse AS nonce_reuse"
+ " FROM exchange_do_batch_withdraw_insert"
+ " ($1,$2,$3,$4,$5,$6,$7,$8);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_batch_withdraw_insert",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_batch_withdraw_insert.h b/src/exchangedb/pg_do_batch_withdraw_insert.h
new file mode 100644
index 000000000..18fcfc9ae
--- /dev/null
+++ b/src/exchangedb/pg_do_batch_withdraw_insert.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_batch_withdraw_insert.h
+ * @brief implementation of the do_batch_withdraw_insert function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_BATCH_WITHDRAW_INSERT_H
+#define PG_DO_BATCH_WITHDRAW_INSERT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform insert as part of a batch withdraw operation, and persisting the
+ * withdrawal details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
+ * @param collectable corresponding collectable coin (blind signature)
+ * @param now current time (rounded)
+ * @param ruuid reserve UUID
+ * @param[out] denom_unknown set if the denomination is unknown in the DB
+ * @param[out] conflict if the envelope was already in the DB
+ * @param[out] nonce_reuse if @a nonce was non-NULL and reused
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_batch_withdraw_insert (
+ void *cls,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
+ const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
+ struct GNUNET_TIME_Timestamp now,
+ uint64_t ruuid,
+ bool *denom_unknown,
+ bool *conflict,
+ bool *nonce_reuse);
+
+#endif
diff --git a/src/exchangedb/pg_do_deposit.c b/src/exchangedb/pg_do_deposit.c
new file mode 100644
index 000000000..0ba45b628
--- /dev/null
+++ b/src/exchangedb/pg_do_deposit.c
@@ -0,0 +1,119 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_deposit.c
+ * @brief Implementation of the do_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_deposit.h"
+#include "pg_helper.h"
+#include "pg_compute_shard.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_deposit (
+ void *cls,
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd,
+ struct GNUNET_TIME_Timestamp *exchange_timestamp,
+ bool *balance_ok,
+ uint32_t *bad_balance_index,
+ bool *ctr_conflict)
+{
+ struct PostgresClosure *pg = cls;
+ uint64_t deposit_shard = TEH_PG_compute_shard (&bd->merchant_pub);
+ const struct TALER_CoinSpendPublicKeyP *coin_pubs[GNUNET_NZL (bd->num_cdis)];
+ const struct TALER_CoinSpendSignatureP *coin_sigs[GNUNET_NZL (bd->num_cdis)];
+ struct TALER_Amount amounts_with_fee[GNUNET_NZL (bd->num_cdis)];
+ struct GNUNET_PQ_QueryParam params[] = {
+ /* data for batch_deposits */
+ GNUNET_PQ_query_param_uint64 (&deposit_shard),
+ GNUNET_PQ_query_param_auto_from_type (&bd->merchant_pub),
+ GNUNET_PQ_query_param_timestamp (&bd->wallet_timestamp),
+ GNUNET_PQ_query_param_timestamp (exchange_timestamp),
+ GNUNET_PQ_query_param_timestamp (&bd->refund_deadline),
+ GNUNET_PQ_query_param_timestamp (&bd->wire_deadline),
+ GNUNET_PQ_query_param_auto_from_type (&bd->h_contract_terms),
+ (bd->no_wallet_data_hash)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&bd->wallet_data_hash),
+ GNUNET_PQ_query_param_auto_from_type (&bd->wire_salt),
+ GNUNET_PQ_query_param_auto_from_type (&bd->wire_target_h_payto),
+ (0 == bd->policy_details_serial_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&bd->policy_details_serial_id),
+ GNUNET_PQ_query_param_bool (bd->policy_blocked),
+ /* to create entry in wire_targets */
+ GNUNET_PQ_query_param_string (bd->receiver_wire_account),
+ /* arrays for coin_deposits */
+ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
+ coin_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_auto_from_type (bd->num_cdis,
+ coin_sigs,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (bd->num_cdis,
+ amounts_with_fee,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ bool no_time;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ exchange_timestamp),
+ &no_time),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("insufficient_balance_coin_index",
+ bad_balance_index),
+ balance_ok),
+ GNUNET_PQ_result_spec_bool ("conflicted",
+ ctr_conflict),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ for (unsigned int i = 0; i < bd->num_cdis; i++)
+ {
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *cdi
+ = &bd->cdis[i];
+
+ amounts_with_fee[i] = cdi->amount_with_fee;
+ coin_pubs[i] = &cdi->coin.coin_pub;
+ coin_sigs[i] = &cdi->csig;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Do deposit %u = %s\n",
+ i,
+ TALER_B2S (&cdi->coin.coin_pub));
+ }
+ PREPARE (pg,
+ "call_deposit",
+ "SELECT "
+ " out_exchange_timestamp AS exchange_timestamp"
+ ",out_insufficient_balance_coin_index AS insufficient_balance_coin_index"
+ ",out_conflict AS conflicted"
+ " FROM exchange_do_deposit"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_deposit",
+ params,
+ rs);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ return qs;
+}
diff --git a/src/exchangedb/pg_do_deposit.h b/src/exchangedb/pg_do_deposit.h
new file mode 100644
index 000000000..449ec04be
--- /dev/null
+++ b/src/exchangedb/pg_do_deposit.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_deposit.h
+ * @brief implementation of the do_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_DEPOSIT_H
+#define PG_DO_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Perform deposit operation, checking for sufficient balance
+ * of the coins and possibly persisting the deposit details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param bd batch deposit operation details
+ * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated)
+ * @param[out] balance_ok set to true if the balance was sufficient
+ * @param[out] bad_balance_index set to the first index of a coin for which the balance was insufficient,
+ * only used if @a balance_ok is set to false.
+ * @param[out] in_conflict set to true if the deposit conflicted
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_deposit (
+ void *cls,
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd,
+ struct GNUNET_TIME_Timestamp *exchange_timestamp,
+ bool *balance_ok,
+ uint32_t *bad_balance_index,
+ bool *in_conflict);
+
+#endif
diff --git a/src/exchangedb/pg_do_melt.c b/src/exchangedb/pg_do_melt.c
new file mode 100644
index 000000000..0b26386d8
--- /dev/null
+++ b/src/exchangedb/pg_do_melt.c
@@ -0,0 +1,82 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_melt.c
+ * @brief Implementation of the do_melt function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_melt.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_melt (
+ void *cls,
+ const struct TALER_RefreshMasterSecretP *rms,
+ struct TALER_EXCHANGEDB_Refresh *refresh,
+ uint64_t known_coin_id,
+ bool *zombie_required,
+ bool *balance_ok)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ NULL == rms
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (rms),
+ TALER_PQ_query_param_amount (pg->conn,
+ &refresh->amount_with_fee),
+ GNUNET_PQ_query_param_auto_from_type (&refresh->rc),
+ GNUNET_PQ_query_param_auto_from_type (&refresh->coin.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig),
+ GNUNET_PQ_query_param_uint64 (&known_coin_id),
+ GNUNET_PQ_query_param_uint32 (&refresh->noreveal_index),
+ GNUNET_PQ_query_param_bool (*zombie_required),
+ GNUNET_PQ_query_param_end
+ };
+ bool is_null;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("balance_ok",
+ balance_ok),
+ GNUNET_PQ_result_spec_bool ("zombie_required",
+ zombie_required),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("noreveal_index",
+ &refresh->noreveal_index),
+ &is_null),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "call_melt",
+ "SELECT "
+ " out_balance_ok AS balance_ok"
+ ",out_zombie_bad AS zombie_required"
+ ",out_noreveal_index AS noreveal_index"
+ " FROM exchange_do_melt"
+ " ($1,$2,$3,$4,$5,$6,$7,$8);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_melt",
+ params,
+ rs);
+ if (is_null)
+ refresh->noreveal_index = UINT32_MAX; /* set to very invalid value */
+ return qs;
+}
diff --git a/src/exchangedb/pg_do_melt.h b/src/exchangedb/pg_do_melt.h
new file mode 100644
index 000000000..554ce08b2
--- /dev/null
+++ b/src/exchangedb/pg_do_melt.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_melt.h
+ * @brief implementation of the do_melt function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_MELT_H
+#define PG_DO_MELT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform melt operation, checking for sufficient balance
+ * of the coin and possibly persisting the melt details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param rms client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
+ * @param[in,out] refresh refresh operation details; the noreveal_index
+ * is set in case the coin was already melted before
+ * @param known_coin_id row of the coin in the known_coins table
+ * @param[in,out] zombie_required true if the melt must only succeed if the coin is a zombie, set to false if the requirement was satisfied
+ * @param[out] balance_ok set to true if the balance was sufficient
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_melt (
+ void *cls,
+ const struct TALER_RefreshMasterSecretP *rms,
+ struct TALER_EXCHANGEDB_Refresh *refresh,
+ uint64_t known_coin_id,
+ bool *zombie_required,
+ bool *balance_ok);
+
+#endif
diff --git a/src/exchangedb/pg_do_purse_delete.c b/src/exchangedb/pg_do_purse_delete.c
new file mode 100644
index 000000000..27b81cab9
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_delete.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_delete.c
+ * @brief Implementation of the do_purse_delete function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_purse_delete.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_delete (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig,
+ bool *decided,
+ bool *found)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (purse_sig),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("decided",
+ decided),
+ GNUNET_PQ_result_spec_bool ("found",
+ found),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "call_purse_delete",
+ "SELECT "
+ " out_decided AS decided"
+ ",out_found AS found"
+ " FROM exchange_do_purse_delete"
+ " ($1,$2,$3);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_purse_delete",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_purse_delete.h b/src/exchangedb/pg_do_purse_delete.h
new file mode 100644
index 000000000..01c7dd91b
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_delete.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_delete.h
+ * @brief implementation of the do_purse_delete function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_PURSE_DELETE_H
+#define PG_DO_PURSE_DELETE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to explicitly delete a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to delete
+ * @param purse_sig signature affirming the deletion
+ * @param[out] decided set to true if the purse was
+ * already decided and thus could not be deleted
+ * @param[out] found set to true if the purse was found
+ * (if false, purse could not be deleted)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_delete (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig,
+ bool *decided,
+ bool *found);
+
+#endif
diff --git a/src/exchangedb/pg_do_purse_deposit.c b/src/exchangedb/pg_do_purse_deposit.c
new file mode 100644
index 000000000..bdb1f4749
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_deposit.c
@@ -0,0 +1,90 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_deposit.c
+ * @brief Implementation of the do_purse_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_purse_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_deposit (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *amount,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const struct TALER_Amount *amount_minus_fee,
+ bool *balance_ok,
+ bool *too_late,
+ bool *conflict)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+ uint64_t partner_id = 0; /* FIXME #7271: WAD support... */
+ struct GNUNET_PQ_QueryParam params[] = {
+ (0 == partner_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&partner_id),
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ amount),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (coin_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ amount_minus_fee),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("balance_ok",
+ balance_ok),
+ GNUNET_PQ_result_spec_bool ("too_late",
+ too_late),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ conflict),
+ GNUNET_PQ_result_spec_end
+ };
+
+ reserve_expiration
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ pg->legal_reserve_expiration_time));
+
+ PREPARE (pg,
+ "call_purse_deposit",
+ "SELECT "
+ " out_balance_ok AS balance_ok"
+ ",out_conflict AS conflict"
+ ",out_late AS too_late"
+ " FROM exchange_do_purse_deposit"
+ " ($1,$2,$3,$4,$5,$6,$7,$8);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_purse_deposit",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_purse_deposit.h b/src/exchangedb/pg_do_purse_deposit.h
new file mode 100644
index 000000000..779b6c0c8
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_deposit.h
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_deposit.h
+ * @brief implementation of the do_purse_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_PURSE_DEPOSIT_H
+#define PG_DO_PURSE_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to execute a transaction crediting
+ * a purse with @a amount from @a coin_pub. Reduces the
+ * value of @a coin_pub and increase the balance of
+ * the @a purse_pub purse. If the balance reaches the
+ * target amount and the purse has been merged, triggers
+ * the updates of the reserve/account balance.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to credit
+ * @param coin_pub coin to deposit (debit)
+ * @param amount fraction of the coin's value to deposit
+ * @param coin_sig signature affirming the operation
+ * @param amount_minus_fee amount to add to the purse
+ * @param[out] balance_ok set to false if the coin's
+ * remaining balance is below @a amount;
+ * in this case, the return value will be
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
+ * @param[out] too_late set to true if it is too late to deposit into the purse
+ * @param[out] conflict set to true if the deposit failed due to a conflict (coin already spent,
+ * or deposited into this purse with a different amount)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_deposit (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *amount,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const struct TALER_Amount *amount_minus_fee,
+ bool *balance_ok,
+ bool *too_late,
+ bool *conflict);
+
+#endif
diff --git a/src/exchangedb/pg_do_purse_merge.c b/src/exchangedb/pg_do_purse_merge.c
new file mode 100644
index 000000000..5a174ed02
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_merge.c
@@ -0,0 +1,91 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_merge.c
+ * @brief Implementation of the do_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_purse_merge.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_merge (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const char *partner_url,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *no_partner,
+ bool *no_balance,
+ bool *in_conflict)
+{
+ struct PostgresClosure *pg = cls;
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp expiration
+ = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (merge_sig),
+ GNUNET_PQ_query_param_timestamp (&merge_timestamp),
+ GNUNET_PQ_query_param_auto_from_type (reserve_sig),
+ (NULL == partner_url)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (partner_url),
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (&h_payto),
+ GNUNET_PQ_query_param_timestamp (&expiration),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("no_partner",
+ no_partner),
+ GNUNET_PQ_result_spec_bool ("no_balance",
+ no_balance),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ in_conflict),
+ GNUNET_PQ_result_spec_end
+ };
+
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (pg->exchange_url,
+ reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ GNUNET_free (payto_uri);
+ }
+ PREPARE (pg,
+ "call_purse_merge",
+ "SELECT"
+ " out_no_partner AS no_partner"
+ ",out_no_balance AS no_balance"
+ ",out_conflict AS conflict"
+ " FROM exchange_do_purse_merge"
+ " ($1, $2, $3, $4, $5, $6, $7, $8);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_purse_merge",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_purse_merge.h b/src/exchangedb/pg_do_purse_merge.h
new file mode 100644
index 000000000..a51de47bf
--- /dev/null
+++ b/src/exchangedb/pg_do_purse_merge.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_purse_merge.h
+ * @brief implementation of the do_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_PURSE_MERGE_H
+#define PG_DO_PURSE_MERGE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to approve merging a purse into a
+ * reserve by the respective purse merge key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to merge
+ * @param merge_sig signature affirming the merge
+ * @param merge_timestamp time of the merge
+ * @param reserve_sig signature of the reserve affirming the merge
+ * @param partner_url URL of the partner exchange, can be NULL if the reserves lives with us
+ * @param reserve_pub public key of the reserve to credit
+ * @param[out] no_partner set to true if @a partner_url is unknown
+ * @param[out] no_balance set to true if the @a purse_pub is not paid up yet
+ * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_purse_merge (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const char *partner_url,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *no_partner,
+ bool *no_balance,
+ bool *in_conflict);
+
+#endif
diff --git a/src/exchangedb/pg_do_recoup.c b/src/exchangedb/pg_do_recoup.c
new file mode 100644
index 000000000..07566a607
--- /dev/null
+++ b/src/exchangedb/pg_do_recoup.c
@@ -0,0 +1,85 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_recoup.c
+ * @brief Implementation of the do_recoup function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_recoup.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_recoup (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t reserve_out_serial_id,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t known_coin_id,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ struct GNUNET_TIME_Timestamp *recoup_timestamp,
+ bool *recoup_ok,
+ bool *internal_failure)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp reserve_gc
+ = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
+ struct GNUNET_TIME_Timestamp reserve_expiration
+ = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_uint64 (&reserve_out_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (coin_bks),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_uint64 (&known_coin_id),
+ GNUNET_PQ_query_param_auto_from_type (coin_sig),
+ GNUNET_PQ_query_param_timestamp (&reserve_gc),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_timestamp (recoup_timestamp),
+ GNUNET_PQ_query_param_end
+ };
+ bool is_null;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ recoup_timestamp),
+ &is_null),
+ GNUNET_PQ_result_spec_bool ("recoup_ok",
+ recoup_ok),
+ GNUNET_PQ_result_spec_bool ("internal_failure",
+ internal_failure),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "call_recoup",
+ "SELECT "
+ " out_recoup_timestamp AS recoup_timestamp"
+ ",out_recoup_ok AS recoup_ok"
+ ",out_internal_failure AS internal_failure"
+ " FROM exchange_do_recoup_to_reserve"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_recoup",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_recoup.h b/src/exchangedb/pg_do_recoup.h
new file mode 100644
index 000000000..2cf3eb976
--- /dev/null
+++ b/src/exchangedb/pg_do_recoup.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_recoup.h
+ * @brief implementation of the do_recoup function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_RECOUP_H
+#define PG_DO_RECOUP_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform recoup operation, checking for sufficient deposits
+ * of the coin and possibly persisting the recoup details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve_pub public key of the reserve to credit
+ * @param reserve_out_serial_id row in the reserves_out table justifying the recoup
+ * @param coin_bks coin blinding key secret to persist
+ * @param coin_pub public key of the coin being recouped
+ * @param known_coin_id row of the @a coin_pub in the known_coins table
+ * @param coin_sig signature of the coin requesting the recoup
+ * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed
+ * @param[out] recoup_ok set if the recoup succeeded (balance ok)
+ * @param[out] internal_failure set on internal failures
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_recoup (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t reserve_out_serial_id,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t known_coin_id,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ struct GNUNET_TIME_Timestamp *recoup_timestamp,
+ bool *recoup_ok,
+ bool *internal_failure);
+
+#endif
diff --git a/src/exchangedb/pg_do_recoup_refresh.c b/src/exchangedb/pg_do_recoup_refresh.c
new file mode 100644
index 000000000..7d099bcd5
--- /dev/null
+++ b/src/exchangedb/pg_do_recoup_refresh.c
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_recoup_refresh.c
+ * @brief Implementation of the do_recoup_refresh function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_recoup_refresh.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_recoup_refresh (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ uint64_t rrc_serial,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t known_coin_id,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ struct GNUNET_TIME_Timestamp *recoup_timestamp,
+ bool *recoup_ok,
+ bool *internal_failure)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (old_coin_pub),
+ GNUNET_PQ_query_param_uint64 (&rrc_serial),
+ GNUNET_PQ_query_param_auto_from_type (coin_bks),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_uint64 (&known_coin_id),
+ GNUNET_PQ_query_param_auto_from_type (coin_sig),
+ GNUNET_PQ_query_param_timestamp (recoup_timestamp),
+ GNUNET_PQ_query_param_end
+ };
+ bool is_null;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ recoup_timestamp),
+ &is_null),
+ GNUNET_PQ_result_spec_bool ("recoup_ok",
+ recoup_ok),
+ GNUNET_PQ_result_spec_bool ("internal_failure",
+ internal_failure),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "call_recoup_refresh",
+ "SELECT "
+ " out_recoup_timestamp AS recoup_timestamp"
+ ",out_recoup_ok AS recoup_ok"
+ ",out_internal_failure AS internal_failure"
+ " FROM exchange_do_recoup_to_coin"
+ " ($1,$2,$3,$4,$5,$6,$7);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_recoup_refresh",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_recoup_refresh.h b/src/exchangedb/pg_do_recoup_refresh.h
new file mode 100644
index 000000000..16b0fd208
--- /dev/null
+++ b/src/exchangedb/pg_do_recoup_refresh.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_recoup_refresh.h
+ * @brief implementation of the do_recoup_refresh function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_RECOUP_REFRESH_H
+#define PG_DO_RECOUP_REFRESH_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Perform recoup-refresh operation, checking for sufficient deposits of the
+ * coin and possibly persisting the recoup-refresh details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param old_coin_pub public key of the old coin to credit
+ * @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
+ * @param coin_bks coin blinding key secret to persist
+ * @param coin_pub public key of the coin being recouped
+ * @param known_coin_id row of the @a coin_pub in the known_coins table
+ * @param coin_sig signature of the coin requesting the recoup
+ * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed
+ * @param[out] recoup_ok set if the recoup-refresh succeeded (balance ok)
+ * @param[out] internal_failure set on internal failures
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_recoup_refresh (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ uint64_t rrc_serial,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t known_coin_id,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ struct GNUNET_TIME_Timestamp *recoup_timestamp,
+ bool *recoup_ok,
+ bool *internal_failure);
+
+#endif
diff --git a/src/exchangedb/pg_do_refund.c b/src/exchangedb/pg_do_refund.c
new file mode 100644
index 000000000..194dab18d
--- /dev/null
+++ b/src/exchangedb/pg_do_refund.c
@@ -0,0 +1,93 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_refund.c
+ * @brief Implementation of the do_refund function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_refund.h"
+#include "pg_helper.h"
+#include "pg_compute_shard.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_refund (
+ void *cls,
+ const struct TALER_EXCHANGEDB_Refund *refund,
+ const struct TALER_Amount *deposit_fee,
+ uint64_t known_coin_id,
+ bool *not_found,
+ bool *refund_ok,
+ bool *gone,
+ bool *conflict)
+{
+ struct PostgresClosure *pg = cls;
+ uint64_t deposit_shard = TEH_PG_compute_shard (&refund->details.merchant_pub);
+ struct TALER_Amount amount_without_fee;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ &refund->details.refund_amount),
+ TALER_PQ_query_param_amount (pg->conn,
+ &amount_without_fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ deposit_fee),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
+ GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
+ GNUNET_PQ_query_param_uint64 (&deposit_shard),
+ GNUNET_PQ_query_param_uint64 (&known_coin_id),
+ GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("not_found",
+ not_found),
+ GNUNET_PQ_result_spec_bool ("refund_ok",
+ refund_ok),
+ GNUNET_PQ_result_spec_bool ("gone",
+ gone),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ conflict),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (0 >
+ TALER_amount_subtract (&amount_without_fee,
+ &refund->details.refund_amount,
+ &refund->details.refund_fee))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ PREPARE (pg,
+ "call_refund",
+ "SELECT "
+ " out_not_found AS not_found"
+ ",out_refund_ok AS refund_ok"
+ ",out_gone AS gone"
+ ",out_conflict AS conflict"
+ " FROM exchange_do_refund"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_refund",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_refund.h b/src/exchangedb/pg_do_refund.h
new file mode 100644
index 000000000..7118858dc
--- /dev/null
+++ b/src/exchangedb/pg_do_refund.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_refund.h
+ * @brief implementation of the do_refund function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_REFUND_H
+#define PG_DO_REFUND_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Perform refund operation, checking for sufficient deposits
+ * of the coin and possibly persisting the refund details.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param refund refund operation details
+ * @param deposit_fee deposit fee applicable for the coin, possibly refunded
+ * @param known_coin_id row of the coin in the known_coins table
+ * @param[out] not_found set if the deposit was not found
+ * @param[out] refund_ok set if the refund succeeded (below deposit amount)
+ * @param[out] gone if the merchant was already paid
+ * @param[out] conflict set if the refund ID was re-used
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_refund (
+ void *cls,
+ const struct TALER_EXCHANGEDB_Refund *refund,
+ const struct TALER_Amount *deposit_fee,
+ uint64_t known_coin_id,
+ bool *not_found,
+ bool *refund_ok,
+ bool *gone,
+ bool *conflict);
+
+#endif
diff --git a/src/exchangedb/pg_do_reserve_open.c b/src/exchangedb/pg_do_reserve_open.c
new file mode 100644
index 000000000..b15c96dd1
--- /dev/null
+++ b/src/exchangedb/pg_do_reserve_open.c
@@ -0,0 +1,101 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_do_reserve_open.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_reserve_open.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_reserve_open (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *total_paid,
+ const struct TALER_Amount *reserve_payment,
+ uint32_t min_purse_limit,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp desired_expiration,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *open_fee,
+ bool *no_funds,
+ struct TALER_Amount *reserve_balance,
+ struct TALER_Amount *open_cost,
+ struct GNUNET_TIME_Timestamp *final_expiration)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ total_paid),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ reserve_payment),
+ GNUNET_PQ_query_param_uint32 (&min_purse_limit),
+ GNUNET_PQ_query_param_uint32 (&pg->def_purse_limit),
+ GNUNET_PQ_query_param_auto_from_type (reserve_sig),
+ GNUNET_PQ_query_param_timestamp (&desired_expiration),
+ GNUNET_PQ_query_param_relative_time (&pg->legal_reserve_expiration_time),
+ GNUNET_PQ_query_param_timestamp (&now),
+ TALER_PQ_query_param_amount (pg->conn,
+ open_fee),
+ GNUNET_PQ_query_param_end
+ };
+ bool no_reserve = true;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("out_open_cost",
+ pg->currency,
+ open_cost),
+ TALER_PQ_result_spec_amount ("out_reserve_balance",
+ pg->currency,
+ reserve_balance),
+ GNUNET_PQ_result_spec_timestamp ("out_final_expiration",
+ final_expiration),
+ GNUNET_PQ_result_spec_bool ("out_no_reserve",
+ &no_reserve),
+ GNUNET_PQ_result_spec_bool ("out_no_funds",
+ no_funds),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "do_reserve_open",
+ "SELECT "
+ " out_open_cost"
+ ",out_final_expiration"
+ ",out_no_funds"
+ ",out_no_reserve"
+ ",out_reserve_balance"
+ " FROM exchange_do_reserve_open"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_reserve_open",
+ params,
+ rs);
+ if (qs <= 0)
+ return qs;
+ if (no_reserve)
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ return qs;
+}
diff --git a/src/exchangedb/pg_do_reserve_open.h b/src/exchangedb/pg_do_reserve_open.h
new file mode 100644
index 000000000..432f3f664
--- /dev/null
+++ b/src/exchangedb/pg_do_reserve_open.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_do_reserve_open.h
+ * @brief implementation of the do_reserve_open function
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_RESERVE_OPEN_H
+#define PG_DO_RESERVE_OPEN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Perform reserve open operation on database.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param total_paid total amount paid (coins and reserve)
+ * @param reserve_payment amount to be paid from the reserve
+ * @param min_purse_limit minimum number of purses we should be able to open
+ * @param reserve_sig signature by the reserve for the operation
+ * @param desired_expiration when should the reserve expire (earliest time)
+ * @param now when did we the client initiate the action
+ * @param open_fee annual fee to be charged for the open operation by the exchange
+ * @param[out] no_funds set to true if reserve balance is insufficient
+ * @param[out] reserve_balance set to the original reserve balance (at the start of this transaction)
+ * @param[out] open_cost set to the actual cost
+ * @param[out] final_expiration when will the reserve expire now
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_reserve_open (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *total_paid,
+ const struct TALER_Amount *reserve_payment,
+ uint32_t min_purse_limit,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp desired_expiration,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *open_fee,
+ bool *no_funds,
+ struct TALER_Amount *reserve_balance,
+ struct TALER_Amount *open_cost,
+ struct GNUNET_TIME_Timestamp *final_expiration);
+
+
+#endif
diff --git a/src/exchangedb/pg_do_reserve_purse.c b/src/exchangedb/pg_do_reserve_purse.c
new file mode 100644
index 000000000..e03e23fec
--- /dev/null
+++ b/src/exchangedb/pg_do_reserve_purse.c
@@ -0,0 +1,121 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_reserve_purse.c
+ * @brief Implementation of the do_reserve_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_do_reserve_purse.h"
+#include "pg_helper.h"
+/**
+ * Function called insert request to merge a purse into a reserve by the
+ * respective purse merge key. The purse must not have been merged into a
+ * different reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to merge
+ * @param merge_sig signature affirming the merge
+ * @param merge_timestamp time of the merge
+ * @param reserve_sig signature of the reserve affirming the merge
+ * @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota
+ * @param reserve_pub public key of the reserve to credit
+ * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
+ * @param[out] no_reserve set to true if @a reserve_pub is not a known reserve
+ * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_reserve_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_Amount *purse_fee,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *in_conflict,
+ bool *no_reserve,
+ bool *insufficient_funds)
+{
+ struct PostgresClosure *pg = cls;
+ struct TALER_Amount zero_fee;
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp reserve_expiration
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ pg->idle_reserve_expiration_time));
+ struct GNUNET_TIME_Timestamp reserve_gc
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
+ pg->legal_reserve_expiration_time));
+
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (merge_sig),
+ GNUNET_PQ_query_param_timestamp (&merge_timestamp),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_timestamp (&reserve_gc),
+ GNUNET_PQ_query_param_auto_from_type (reserve_sig),
+ GNUNET_PQ_query_param_bool (NULL == purse_fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ NULL == purse_fee
+ ? &zero_fee
+ : purse_fee),
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (&h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("insufficient_funds",
+ insufficient_funds),
+ GNUNET_PQ_result_spec_bool ("conflict",
+ in_conflict),
+ GNUNET_PQ_result_spec_bool ("no_reserve",
+ no_reserve),
+ GNUNET_PQ_result_spec_end
+ };
+
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (pg->exchange_url,
+ reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ GNUNET_free (payto_uri);
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &zero_fee));
+ /* Used in #postgres_do_reserve_purse() */
+ PREPARE (pg,
+ "call_reserve_purse",
+ "SELECT"
+ " out_no_funds AS insufficient_funds"
+ ",out_no_reserve AS no_reserve"
+ ",out_conflict AS conflict"
+ " FROM exchange_do_reserve_purse"
+ " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_reserve_purse",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_do_reserve_purse.h b/src/exchangedb/pg_do_reserve_purse.h
new file mode 100644
index 000000000..dde2d6ce1
--- /dev/null
+++ b/src/exchangedb/pg_do_reserve_purse.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_do_reserve_purse.h
+ * @brief implementation of the do_reserve_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DO_RESERVE_PURSE_H
+#define PG_DO_RESERVE_PURSE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called insert request to merge a purse into a reserve by the
+ * respective purse merge key. The purse must not have been merged into a
+ * different reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to merge
+ * @param merge_sig signature affirming the merge
+ * @param merge_timestamp time of the merge
+ * @param reserve_sig signature of the reserve affirming the merge
+ * @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota
+ * @param reserve_pub public key of the reserve to credit
+ * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
+ * @param[out] no_reserve set to true if @a reserve_pub is not a known reserve
+ * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_do_reserve_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergeSignatureP *merge_sig,
+ const struct GNUNET_TIME_Timestamp merge_timestamp,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_Amount *purse_fee,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *in_conflict,
+ bool *no_reserve,
+ bool *insufficient_funds);
+
+#endif
diff --git a/src/exchangedb/pg_drain_kyc_alert.c b/src/exchangedb/pg_drain_kyc_alert.c
new file mode 100644
index 000000000..4388334e9
--- /dev/null
+++ b/src/exchangedb/pg_drain_kyc_alert.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_drain_kyc_alert.c
+ * @brief Implementation of the drain_kyc_alert function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_drain_kyc_alert.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_drain_kyc_alert (void *cls,
+ uint32_t trigger_type,
+ struct TALER_PaytoHashP *h_payto)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint32 (&trigger_type),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "drain_kyc_alert",
+ "DELETE FROM kyc_alerts"
+ " WHERE trigger_type=$1"
+ " AND h_payto = "
+ " (SELECT h_payto "
+ " FROM kyc_alerts"
+ " WHERE trigger_type=$1"
+ " LIMIT 1)"
+ " RETURNING h_payto;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "drain_kyc_alert",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_drain_kyc_alert.h b/src/exchangedb/pg_drain_kyc_alert.h
new file mode 100644
index 000000000..7425f472d
--- /dev/null
+++ b/src/exchangedb/pg_drain_kyc_alert.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_drain_kyc_alert.h
+ * @brief implementation of the drain_kyc_alert function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DRAIN_KYC_ALERT_H
+#define PG_DRAIN_KYC_ALERT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Extract next KYC alert. Deletes the alert.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param trigger_type which type of alert to drain
+ * @param[out] h_payto set to hash of payto-URI where KYC status changed
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_drain_kyc_alert (void *cls,
+ uint32_t trigger_type,
+ struct TALER_PaytoHashP *h_payto);
+
+#endif
diff --git a/src/exchangedb/pg_drop_tables.c b/src/exchangedb/pg_drop_tables.c
new file mode 100644
index 000000000..55857018b
--- /dev/null
+++ b/src/exchangedb/pg_drop_tables.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_drop_tables.c
+ * @brief Implementation of the drop_tables function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_drop_tables.h"
+#include "pg_helper.h"
+
+
+/**
+ * Drop all Taler tables. This should only be used by testcases.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_drop_tables (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_Context *conn;
+ enum GNUNET_GenericReturnValue ret;
+
+ if (NULL != pg->conn)
+ {
+ GNUNET_PQ_disconnect (pg->conn);
+ pg->conn = NULL;
+ }
+ conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "exchangedb-postgres",
+ NULL,
+ NULL,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ ret = GNUNET_PQ_exec_sql (conn,
+ "drop");
+ GNUNET_PQ_disconnect (conn);
+ return ret;
+}
diff --git a/src/exchangedb/pg_drop_tables.h b/src/exchangedb/pg_drop_tables.h
new file mode 100644
index 000000000..58729d5ec
--- /dev/null
+++ b/src/exchangedb/pg_drop_tables.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_drop_tables.h
+ * @brief implementation of the drop_tables function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_DROP_TABLES_H
+#define PG_DROP_TABLES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Drop all Taler tables. This should only be used by testcases.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_drop_tables (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_ensure_coin_known.c b/src/exchangedb/pg_ensure_coin_known.c
new file mode 100644
index 000000000..307b8df52
--- /dev/null
+++ b/src/exchangedb/pg_ensure_coin_known.c
@@ -0,0 +1,169 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_ensure_coin_known.c
+ * @brief Implementation of the ensure_coin_known function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_pq_lib.h"
+#include "pg_ensure_coin_known.h"
+#include "pg_helper.h"
+
+
+enum TALER_EXCHANGEDB_CoinKnownStatus
+TEH_PG_ensure_coin_known (void *cls,
+ const struct TALER_CoinPublicInfo *coin,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash,
+ struct TALER_AgeCommitmentHash *h_age_commitment)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ bool existed;
+ bool is_denom_pub_hash_null = false;
+ bool is_age_hash_null = false;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&coin->denom_pub_hash),
+ coin->no_age_commitment
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
+ TALER_PQ_query_param_denom_sig (&coin->denom_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("existed",
+ &existed),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ known_coin_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ denom_hash),
+ &is_denom_pub_hash_null),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ h_age_commitment),
+ &is_age_hash_null),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /*
+ See also:
+ https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
+ */
+ PREPARE (pg,
+ "insert_known_coin",
+ "WITH dd"
+ " (denominations_serial"
+ " ,coin"
+ " ) AS ("
+ " SELECT "
+ " denominations_serial"
+ " ,coin"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$2"
+ " ), input_rows"
+ " (coin_pub) AS ("
+ " VALUES ($1::BYTEA)"
+ " ), ins AS ("
+ " INSERT INTO known_coins "
+ " (coin_pub"
+ " ,denominations_serial"
+ " ,age_commitment_hash"
+ " ,denom_sig"
+ " ,remaining"
+ " ) SELECT "
+ " $1"
+ " ,denominations_serial"
+ " ,$3"
+ " ,$4"
+ " ,coin"
+ " FROM dd"
+ " ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
+ " RETURNING "
+ " known_coin_id"
+ " ) "
+ "SELECT "
+ " FALSE AS existed"
+ " ,known_coin_id"
+ " ,NULL AS denom_pub_hash"
+ " ,NULL AS age_commitment_hash"
+ " FROM ins "
+ "UNION ALL "
+ "SELECT "
+ " TRUE AS existed"
+ " ,known_coin_id"
+ " ,denom_pub_hash"
+ " ,kc.age_commitment_hash"
+ " FROM input_rows"
+ " JOIN known_coins kc USING (coin_pub)"
+ " JOIN denominations USING (denominations_serial)"
+ " LIMIT 1");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "insert_known_coin",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ GNUNET_break (0);
+ return TALER_EXCHANGEDB_CKS_HARD_FAIL;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ return TALER_EXCHANGEDB_CKS_SOFT_FAIL;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ GNUNET_break (0); /* should be impossible */
+ return TALER_EXCHANGEDB_CKS_HARD_FAIL;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ if (! existed)
+ return TALER_EXCHANGEDB_CKS_ADDED;
+ break; /* continued below */
+ }
+
+ if ( (! is_denom_pub_hash_null) &&
+ (0 != GNUNET_memcmp (&denom_hash->hash,
+ &coin->denom_pub_hash.hash)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_DENOM_CONFLICT;
+ }
+
+ if (is_age_hash_null != coin->no_age_commitment)
+ {
+ if (is_age_hash_null)
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL;
+ }
+ else
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL;
+ }
+ }
+ else if ( (! is_age_hash_null) &&
+ (0 != GNUNET_memcmp (h_age_commitment,
+ &coin->h_age_commitment)) )
+ {
+ GNUNET_break_op (0);
+ return TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS;
+ }
+
+ return TALER_EXCHANGEDB_CKS_PRESENT;
+}
diff --git a/src/exchangedb/pg_ensure_coin_known.h b/src/exchangedb/pg_ensure_coin_known.h
new file mode 100644
index 000000000..68c101735
--- /dev/null
+++ b/src/exchangedb/pg_ensure_coin_known.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_ensure_coin_known.h
+ * @brief implementation of the ensure_coin_known function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ENSURE_COIN_KNOWN_H
+#define PG_ENSURE_COIN_KNOWN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Make sure the given @a coin is known to the database.
+ *
+ * @param cls database connection plugin state
+ * @param coin the coin that must be made known
+ * @param[out] known_coin_id set to the unique row of the coin
+ * @param[out] denom_hash set to the denomination hash of the existing
+ * coin (for conflict error reporting)
+ * @param[out] h_age_commitment set to the conflicting age commitment hash on conflict
+ * @return database transaction status, non-negative on success
+ */
+enum TALER_EXCHANGEDB_CoinKnownStatus
+TEH_PG_ensure_coin_known (void *cls,
+ const struct TALER_CoinPublicInfo *coin,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash,
+ struct TALER_AgeCommitmentHash *h_age_commitment);
+
+#endif
diff --git a/src/exchangedb/pg_event_listen.c b/src/exchangedb/pg_event_listen.c
new file mode 100644
index 000000000..6e1d32843
--- /dev/null
+++ b/src/exchangedb/pg_event_listen.c
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_listen.c
+ * @brief Implementation of the event_listen function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_event_listen.h"
+#include "pg_helper.h"
+
+/**
+ * Register callback to be invoked on events of type @a es.
+ *
+ * @param cls database context to use
+ * @param timeout how long until to generate a timeout event
+ * @param es specification of the event to listen for
+ * @param cb function to call when the event happens, possibly
+ * multiple times (until cancel is invoked)
+ * @param cb_cls closure for @a cb
+ * @return handle useful to cancel the listener
+ */
+struct GNUNET_DB_EventHandler *
+TEH_PG_event_listen (void *cls,
+ struct GNUNET_TIME_Relative timeout,
+ const struct GNUNET_DB_EventHeaderP *es,
+ GNUNET_DB_EventCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+
+ return GNUNET_PQ_event_listen (pg->conn,
+ es,
+ timeout,
+ cb,
+ cb_cls);
+}
diff --git a/src/exchangedb/pg_event_listen.h b/src/exchangedb/pg_event_listen.h
new file mode 100644
index 000000000..7e1e83a0e
--- /dev/null
+++ b/src/exchangedb/pg_event_listen.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_listen.h
+ * @brief implementation of the event_listen function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_EVENT_LISTEN_H
+#define PG_EVENT_LISTEN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Register callback to be invoked on events of type @a es.
+ *
+ * @param cls database context to use
+ * @param timeout how long until to generate a timeout event
+ * @param es specification of the event to listen for
+ * @param cb function to call when the event happens, possibly
+ * multiple times (until cancel is invoked)
+ * @param cb_cls closure for @a cb
+ * @return handle useful to cancel the listener
+ */
+struct GNUNET_DB_EventHandler *
+TEH_PG_event_listen (void *cls,
+ struct GNUNET_TIME_Relative timeout,
+ const struct GNUNET_DB_EventHeaderP *es,
+ GNUNET_DB_EventCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_event_listen_cancel.c b/src/exchangedb/pg_event_listen_cancel.c
new file mode 100644
index 000000000..9d776684d
--- /dev/null
+++ b/src/exchangedb/pg_event_listen_cancel.c
@@ -0,0 +1,36 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_listen_cancel.c
+ * @brief Implementation of the event_listen_cancel function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_event_listen_cancel.h"
+#include "pg_helper.h"
+
+
+void
+TEH_PG_event_listen_cancel (void *cls,
+ struct GNUNET_DB_EventHandler *eh)
+
+{
+ (void) cls;
+ GNUNET_PQ_event_listen_cancel (eh);
+}
diff --git a/src/exchangedb/pg_event_listen_cancel.h b/src/exchangedb/pg_event_listen_cancel.h
new file mode 100644
index 000000000..258d7a58b
--- /dev/null
+++ b/src/exchangedb/pg_event_listen_cancel.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_listen_cancel.h
+ * @brief implementation of the event_listen_cancel function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_EVENT_LISTEN_CANCEL_H
+#define PG_EVENT_LISTEN_CANCEL_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Stop notifications.
+ *
+ * @param cls the plugin's `struct PostgresClosure`
+ * @param eh handle to unregister.
+ */
+void
+TEH_PG_event_listen_cancel (void *cls,
+ struct GNUNET_DB_EventHandler *eh);
+#endif
diff --git a/src/exchangedb/pg_event_notify.c b/src/exchangedb/pg_event_notify.c
new file mode 100644
index 000000000..188855775
--- /dev/null
+++ b/src/exchangedb/pg_event_notify.c
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_notify.c
+ * @brief Implementation of the event_notify function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_event_notify.h"
+#include "pg_helper.h"
+
+
+void
+TEH_PG_event_notify (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ const void *extra,
+ size_t extra_size)
+{
+ struct PostgresClosure *pg = cls;
+
+ GNUNET_PQ_event_notify (pg->conn,
+ es,
+ extra,
+ extra_size);
+}
diff --git a/src/exchangedb/pg_event_notify.h b/src/exchangedb/pg_event_notify.h
new file mode 100644
index 000000000..85069659b
--- /dev/null
+++ b/src/exchangedb/pg_event_notify.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_event_notify.h
+ * @brief implementation of the event_notify function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_EVENT_NOTIFY_H
+#define PG_EVENT_NOTIFY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Notify all that listen on @a es of an event.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to generate
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+void
+TEH_PG_event_notify (void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ const void *extra,
+ size_t extra_size);
+
+#endif
diff --git a/src/exchangedb/pg_expire_purse.c b/src/exchangedb/pg_expire_purse.c
new file mode 100644
index 000000000..6ef7a2779
--- /dev/null
+++ b/src/exchangedb/pg_expire_purse.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_expire_purse.c
+ * @brief Implementation of the expire_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_expire_purse.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_expire_purse (
+ void *cls,
+ struct GNUNET_TIME_Absolute start_time,
+ struct GNUNET_TIME_Absolute end_time)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&start_time),
+ GNUNET_PQ_query_param_absolute_time (&end_time),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ bool found = false;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("found",
+ &found),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "call_expire_purse",
+ "SELECT "
+ " out_found AS found"
+ " FROM exchange_do_expire_purse"
+ " ($1,$2,$3);");
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_expire_purse",
+ params,
+ rs);
+ if (qs < 0)
+ return qs;
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
+ return found
+ ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
+ : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+}
diff --git a/src/exchangedb/pg_expire_purse.h b/src/exchangedb/pg_expire_purse.h
new file mode 100644
index 000000000..fe05fd52c
--- /dev/null
+++ b/src/exchangedb/pg_expire_purse.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_expire_purse.h
+ * @brief implementation of the expire_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_EXPIRE_PURSE_H
+#define PG_EXPIRE_PURSE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to clean up one expired purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_time select purse expired after this time
+ * @param end_time select purse expired before this time
+ * @return transaction status code (#GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no purse expired in the given time interval).
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_expire_purse (
+ void *cls,
+ struct GNUNET_TIME_Absolute start_time,
+ struct GNUNET_TIME_Absolute end_time);
+
+#endif
diff --git a/src/exchangedb/pg_find_aggregation_transient.c b/src/exchangedb/pg_find_aggregation_transient.c
new file mode 100644
index 000000000..b931188a8
--- /dev/null
+++ b/src/exchangedb/pg_find_aggregation_transient.c
@@ -0,0 +1,150 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_find_aggregation_transient.c
+ * @brief Implementation of the find_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_find_aggregation_transient.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_refunds_cb().
+ */
+struct FindAggregationTransientContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_TransientAggregationCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct SelectRefundContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+get_transients_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct FindAggregationTransientContext *srctx = cls;
+ struct PostgresClosure *pg = srctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount;
+ char *payto_uri;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ bool cont;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ srctx->status = GNUNET_SYSERR;
+ return;
+ }
+ cont = srctx->cb (srctx->cb_cls,
+ payto_uri,
+ &wtid,
+ &merchant_pub,
+ &amount);
+ GNUNET_free (payto_uri);
+ if (! cont)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_find_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_TransientAggregationCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct FindAggregationTransientContext srctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+
+ PREPARE (pg,
+ "find_transient_aggregations",
+ "SELECT"
+ " amount"
+ " ,wtid_raw"
+ " ,merchant_pub"
+ " ,payto_uri"
+ " FROM aggregation_transient atr"
+ " JOIN wire_targets wt USING (wire_target_h_payto)"
+ " WHERE atr.wire_target_h_payto=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "find_transient_aggregations",
+ params,
+ &get_transients_cb,
+ &srctx);
+ if (GNUNET_SYSERR == srctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_find_aggregation_transient.h b/src/exchangedb/pg_find_aggregation_transient.h
new file mode 100644
index 000000000..c7ba4ea38
--- /dev/null
+++ b/src/exchangedb/pg_find_aggregation_transient.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_find_aggregation_transient.h
+ * @brief implementation of the find_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_FIND_AGGREGATION_TRANSIENT_H
+#define PG_FIND_AGGREGATION_TRANSIENT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Find existing entry in the transient aggregation table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param cb function to call on each matching entry
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_find_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_TransientAggregationCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_gc.c b/src/exchangedb/pg_gc.c
new file mode 100644
index 000000000..e01c1e101
--- /dev/null
+++ b/src/exchangedb/pg_gc.c
@@ -0,0 +1,80 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_gc.c
+ * @brief Implementation of the gc function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_gc.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_GenericReturnValue
+TEH_PG_gc (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
+ struct GNUNET_TIME_Absolute long_ago;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&long_ago),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_Context *conn;
+ enum GNUNET_GenericReturnValue ret;
+
+ /* Keep wire fees for 10 years, that should always
+ be enough _and_ they are tiny so it does not
+ matter to make this tight */
+ long_ago = GNUNET_TIME_absolute_subtract (
+ now,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_YEARS,
+ 10));
+ {
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+ struct GNUNET_PQ_PreparedStatement ps[] = {
+ /* Used in #postgres_gc() */
+ GNUNET_PQ_make_prepare ("run_gc",
+ "CALL"
+ " exchange_do_gc"
+ " ($1,$2);"),
+ GNUNET_PQ_PREPARED_STATEMENT_END
+ };
+
+ conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "exchangedb-postgres",
+ NULL,
+ es,
+ ps);
+ }
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ ret = GNUNET_OK;
+ if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
+ "run_gc",
+ params))
+ ret = GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
+ return ret;
+}
diff --git a/src/exchangedb/pg_gc.h b/src/exchangedb/pg_gc.h
new file mode 100644
index 000000000..803581488
--- /dev/null
+++ b/src/exchangedb/pg_gc.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_gc.h
+ * @brief implementation of the gc function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GC_H
+#define PG_GC_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to perform "garbage collection" on the
+ * database, expiring records we no longer require.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_gc (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_age_withdraw.c b/src/exchangedb/pg_get_age_withdraw.c
new file mode 100644
index 000000000..ea4d3b909
--- /dev/null
+++ b/src/exchangedb/pg_get_age_withdraw.c
@@ -0,0 +1,119 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_age_withdraw.c
+ * @brief Implementation of the get_age_withdraw function for Postgres
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_age_withdraw.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_age_withdraw (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ struct TALER_EXCHANGEDB_AgeWithdraw *aw)
+{
+ enum GNUNET_DB_QueryStatus ret;
+ struct PostgresClosure *pg = cls;
+ size_t num_sigs;
+ size_t num_hashes;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (ach),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_commitment",
+ &aw->h_commitment),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &aw->reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &aw->reserve_pub),
+ GNUNET_PQ_result_spec_uint16 ("max_age",
+ &aw->max_age),
+ TALER_PQ_result_spec_amount ("amount_with_fee",
+ pg->currency,
+ &aw->amount_with_fee),
+ GNUNET_PQ_result_spec_uint16 ("noreveal_index",
+ &aw->noreveal_index),
+ TALER_PQ_result_spec_array_blinded_coin_hash (
+ pg->conn,
+ "h_blind_evs",
+ &aw->num_coins,
+ &aw->h_coin_evs),
+ TALER_PQ_result_spec_array_blinded_denom_sig (
+ pg->conn,
+ "denom_sigs",
+ &num_sigs,
+ &aw->denom_sigs),
+ TALER_PQ_result_spec_array_denom_hash (
+ pg->conn,
+ "denom_pub_hashes",
+ &num_hashes,
+ &aw->denom_pub_hashes),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_age_withdraw",
+ "SELECT"
+ " h_commitment"
+ ",reserve_sig"
+ ",reserve_pub"
+ ",max_age"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",h_blind_evs"
+ ",denom_sigs"
+ ",ARRAY("
+ " SELECT denominations.denom_pub_hash FROM ("
+ " SELECT UNNEST(denom_serials) AS id,"
+ " generate_subscripts(denom_serials, 1) AS nr" /* for order */
+ " ) AS denoms"
+ " LEFT JOIN denominations ON denominations.denominations_serial=denoms.id"
+ ") AS denom_pub_hashes"
+ " FROM age_withdraw"
+ " WHERE reserve_pub=$1 and h_commitment=$2;");
+
+ ret = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_age_withdraw",
+ params,
+ rs);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != ret)
+ return ret;
+
+ if ((aw->num_coins != num_sigs) ||
+ (aw->num_coins != num_hashes))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "got inconsistent number of entries from DB: "
+ "num_coins=%ld, num_sigs=%ld, num_hashes=%ld\n",
+ aw->num_coins,
+ num_sigs,
+ num_hashes);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ return ret;
+}
diff --git a/src/exchangedb/pg_get_age_withdraw.h b/src/exchangedb/pg_get_age_withdraw.h
new file mode 100644
index 000000000..2257aa43c
--- /dev/null
+++ b/src/exchangedb/pg_get_age_withdraw.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_age_withdraw.h
+ * @brief implementation of the get_age_withdraw function for Postgres
+ * @author Özgür KESIM
+ */
+#ifndef PG_GET_AGE_WITHDRAW_H
+#define PG_GET_AGE_WITHDRAW_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Locate the response for a age-withdraw request under a hash that uniquely
+ * identifies the age-withdraw operation. Used to ensure idempotency of the
+ * request.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve for which the age-withdraw request is made
+ * @param ach hash that uniquely identifies the age-withdraw operation
+ * @param[out] aw corresponding details of the previous age-withdraw request if an entry was found
+ * @return statement execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_age_withdraw (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ struct TALER_EXCHANGEDB_AgeWithdraw *aw);
+#endif
diff --git a/src/exchangedb/pg_get_coin_denomination.c b/src/exchangedb/pg_get_coin_denomination.c
new file mode 100644
index 000000000..9f9256f6f
--- /dev/null
+++ b/src/exchangedb/pg_get_coin_denomination.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_coin_denomination.c
+ * @brief Implementation of the get_coin_denomination function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_coin_denomination.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_coin_denomination (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ denom_hash),
+ GNUNET_PQ_result_spec_uint64 ("known_coin_id",
+ known_coin_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting coin denomination of coin %s\n",
+ TALER_B2S (coin_pub));
+
+ /* Used in #postgres_get_coin_denomination() to fetch
+ the denomination public key hash for
+ a coin known to the exchange. */
+ PREPARE (pg,
+ "get_coin_denomination",
+ "SELECT"
+ " denominations.denom_pub_hash"
+ ",known_coin_id"
+ " FROM known_coins"
+ " JOIN denominations USING (denominations_serial)"
+ " WHERE coin_pub=$1"
+ " FOR SHARE;");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_coin_denomination",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_coin_denomination.h b/src/exchangedb/pg_get_coin_denomination.h
new file mode 100644
index 000000000..3b9f03f31
--- /dev/null
+++ b/src/exchangedb/pg_get_coin_denomination.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_coin_denomination.h
+ * @brief implementation of the get_coin_denomination function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_COIN_DENOMINATION_H
+#define PG_GET_COIN_DENOMINATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Retrieve the denomination of a known coin.
+ *
+ * @param cls the plugin closure
+ * @param coin_pub the public key of the coin to search for
+ * @param[out] known_coin_id set to the ID of the coin in the known_coins table
+ * @param[out] denom_hash where to store the hash of the coins denomination
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_coin_denomination (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t *known_coin_id,
+ struct TALER_DenominationHashP *denom_hash);
+
+#endif
diff --git a/src/exchangedb/pg_get_coin_transactions.c b/src/exchangedb/pg_get_coin_transactions.c
new file mode 100644
index 000000000..fef33a486
--- /dev/null
+++ b/src/exchangedb/pg_get_coin_transactions.c
@@ -0,0 +1,1144 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_coin_transactions.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_pq_lib.h"
+#include "pg_get_coin_transactions.h"
+#include "pg_helper.h"
+#include "pg_start_read_committed.h"
+#include "pg_commit.h"
+#include "pg_rollback.h"
+#include "plugin_exchangedb_common.h"
+
+/**
+ * How often do we re-try when encountering DB serialization issues?
+ * (We are read-only, so can only happen due to concurrent insert,
+ * which should be very rare.)
+ */
+#define RETRIES 3
+
+/**
+ * Closure for callbacks called from #postgres_get_coin_transactions()
+ */
+struct CoinHistoryContext
+{
+ /**
+ * Head of the coin's history list.
+ */
+ struct TALER_EXCHANGEDB_TransactionList *head;
+
+ /**
+ * Public key of the coin we are building the history for.
+ */
+ const struct TALER_CoinSpendPublicKeyP *coin_pub;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to 'true' if the transaction failed.
+ */
+ bool failed;
+
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_deposit (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_DepositListEntry *deposit;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ deposit = GNUNET_new (struct TALER_EXCHANGEDB_DepositListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit->amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit->deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &deposit->h_denom_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit->h_age_commitment),
+ &deposit->no_age_commitment),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("wallet_data_hash",
+ &deposit->wallet_data_hash),
+ &deposit->no_wallet_data_hash),
+ GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
+ &deposit->timestamp),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &deposit->refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &deposit->wire_deadline),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &deposit->merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &deposit->h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &deposit->wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &deposit->receiver_wire_account),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit->csig),
+ GNUNET_PQ_result_spec_uint64 ("coin_deposit_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("done",
+ &deposit->done),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (deposit);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_DEPOSIT;
+ tl->details.deposit = deposit;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_purse_deposit (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_PurseDepositListEntry *deposit;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ deposit = GNUNET_new (struct TALER_EXCHANGEDB_PurseDepositListEntry);
+ {
+ bool not_finished;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit->amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit->deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &deposit->purse_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ &deposit->exchange_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit->coin_sig),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit->h_age_commitment),
+ &deposit->no_age_commitment),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_bool ("refunded",
+ &deposit->refunded),
+ &not_finished),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (deposit);
+ chc->failed = true;
+ return;
+ }
+ if (not_finished)
+ deposit->refunded = false;
+ deposit->no_age_commitment = GNUNET_is_zero (&deposit->h_age_commitment);
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_PURSE_DEPOSIT;
+ tl->details.purse_deposit = deposit;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_melt (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_MeltListEntry *melt;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ melt = GNUNET_new (struct TALER_EXCHANGEDB_MeltListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("rc",
+ &melt->rc),
+ /* oldcoin_index not needed */
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &melt->h_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
+ &melt->coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &melt->amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &melt->melt_fee),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &melt->h_age_commitment),
+ &melt->no_age_commitment),
+ GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (melt);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_MELT;
+ tl->details.melt = melt;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_refund (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_RefundListEntry *refund;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ refund = GNUNET_new (struct TALER_EXCHANGEDB_RefundListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &refund->merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
+ &refund->merchant_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &refund->h_contract_terms),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &refund->rtransaction_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &refund->refund_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &refund->refund_fee),
+ GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (refund);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_REFUND;
+ tl->details.refund = refund;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_purse_decision (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ prefund = GNUNET_new (struct TALER_EXCHANGEDB_PurseRefundListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &prefund->purse_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &prefund->refund_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &prefund->refund_fee),
+ GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (prefund);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_PURSE_REFUND;
+ tl->details.purse_refund = prefund;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_old_coin_recoup (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_RecoupRefreshListEntry *recoup;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupRefreshListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &recoup->coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &recoup->coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &recoup->coin_blind),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &recoup->value),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &recoup->timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &recoup->coin.denom_pub_hash),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &recoup->coin.denom_sig),
+ GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (recoup);
+ chc->failed = true;
+ return;
+ }
+ recoup->old_coin_pub = *chc->coin_pub;
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP;
+ tl->details.old_coin_recoup = recoup;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_recoup (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_RecoupListEntry *recoup;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &recoup->reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &recoup->coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &recoup->h_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &recoup->coin_blind),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &recoup->value),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &recoup->timestamp),
+ GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (recoup);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_RECOUP;
+ tl->details.recoup = recoup;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_recoup_refresh (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_RecoupRefreshListEntry *recoup;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupRefreshListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &recoup->old_coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &recoup->coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &recoup->coin_blind),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &recoup->value),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &recoup->timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &recoup->coin.denom_pub_hash),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &recoup->coin.denom_sig),
+ GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (recoup);
+ chc->failed = true;
+ return;
+ }
+ recoup->coin.coin_pub = *chc->coin_pub;
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_RECOUP_REFRESH;
+ tl->details.recoup_refresh = recoup;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinHistoryContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_coin_reserve_open (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_ReserveOpenListEntry *role;
+ struct TALER_EXCHANGEDB_TransactionList *tl;
+ uint64_t serial_id;
+
+ role = GNUNET_new (struct TALER_EXCHANGEDB_ReserveOpenListEntry);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &role->reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &role->coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("contribution",
+ &role->coin_contribution),
+ GNUNET_PQ_result_spec_uint64 ("reserve_open_deposit_uuid",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (role);
+ chc->failed = true;
+ return;
+ }
+ }
+ tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
+ tl->next = chc->head;
+ tl->type = TALER_EXCHANGEDB_TT_RESERVE_OPEN;
+ tl->details.reserve_open = role;
+ tl->serial_id = serial_id;
+ chc->head = tl;
+ }
+}
+
+
+/**
+ * Work we need to do.
+ */
+struct Work
+{
+ /**
+ * Name of the table.
+ */
+ const char *table;
+
+ /**
+ * SQL prepared statement name.
+ */
+ const char *statement;
+
+ /**
+ * Function to call to handle the result(s).
+ */
+ GNUNET_PQ_PostgresResultHandler cb;
+};
+
+
+/**
+ * We found a coin history entry. Lookup details
+ * from the respective table and store in @a cls.
+ *
+ * @param[in,out] cls a `struct CoinHistoryContext`
+ * @param result a coin history entry result set
+ * @param num_results total number of results in @a results
+ */
+static void
+handle_history_entry (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinHistoryContext *chc = cls;
+ struct PostgresClosure *pg = chc->pg;
+ static const struct Work work[] = {
+ [TALER_EXCHANGEDB_TT_DEPOSIT] =
+ { "coin_deposits",
+ "get_deposit_with_coin_pub",
+ &add_coin_deposit },
+ [TALER_EXCHANGEDB_TT_MELT] =
+ { "refresh_commitments",
+ "get_refresh_session_by_coin",
+ &add_coin_melt },
+ [TALER_EXCHANGEDB_TT_PURSE_DEPOSIT] =
+ { "purse_deposits",
+ "get_purse_deposit_by_coin_pub",
+ &add_coin_purse_deposit },
+ [TALER_EXCHANGEDB_TT_PURSE_REFUND] =
+ { "purse_decision",
+ "get_purse_decision_by_coin_pub",
+ &add_coin_purse_decision },
+ [TALER_EXCHANGEDB_TT_REFUND] =
+ { "refunds",
+ "get_refunds_by_coin",
+ &add_coin_refund },
+ [TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP] =
+ { "recoup_refresh::OLD",
+ "recoup_by_old_coin",
+ &add_old_coin_recoup },
+ [TALER_EXCHANGEDB_TT_RECOUP] =
+ { "recoup",
+ "recoup_by_coin",
+ &add_coin_recoup },
+ [TALER_EXCHANGEDB_TT_RECOUP_REFRESH] =
+ { "recoup_refresh::NEW",
+ "recoup_by_refreshed_coin",
+ &add_coin_recoup_refresh },
+ [TALER_EXCHANGEDB_TT_RESERVE_OPEN] =
+ { "reserves_open_deposits",
+ "reserve_open_by_coin",
+ &add_coin_reserve_open },
+ { NULL, NULL, NULL }
+ };
+ char *table_name;
+ uint64_t serial_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("table_name",
+ &table_name),
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (chc->coin_pub),
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ bool found = false;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ chc->failed = true;
+ return;
+ }
+
+ for (unsigned int s = 0;
+ NULL != work[s].statement;
+ s++)
+ {
+ if (0 != strcmp (table_name,
+ work[s].table))
+ continue;
+ found = true;
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ work[s].statement,
+ params,
+ work[s].cb,
+ chc);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Coin %s had %d transactions at %llu in table %s\n",
+ TALER_B2S (chc->coin_pub),
+ (int) qs,
+ (unsigned long long) serial_id,
+ table_name);
+ if (0 >= qs)
+ chc->failed = true;
+ break;
+ }
+ if (! found)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Coin history includes unsupported table `%s`\n",
+ table_name);
+ chc->failed = true;
+ }
+ GNUNET_PQ_cleanup_result (rs);
+ if (chc->failed)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_coin_transactions (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
+ struct TALER_Amount *balance,
+ struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_TransactionList **tlp)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_QueryParam lparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_uint64 (&start_off),
+ GNUNET_PQ_query_param_end
+ };
+ struct CoinHistoryContext chc = {
+ .head = NULL,
+ .coin_pub = coin_pub,
+ .pg = pg
+ };
+
+ *tlp = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting transactions for coin %s\n",
+ TALER_B2S (coin_pub));
+ PREPARE (pg,
+ "get_coin_history_etag_balance",
+ "SELECT"
+ " ch.coin_history_serial_id"
+ ",kc.remaining"
+ ",denom.denom_pub_hash"
+ " FROM coin_history ch"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE coin_pub=$1"
+ " ORDER BY coin_history_serial_id DESC"
+ " LIMIT 1;");
+ PREPARE (pg,
+ "get_coin_history",
+ "SELECT"
+ " table_name"
+ ",serial_id"
+ " FROM coin_history"
+ " WHERE coin_pub=$1"
+ " AND coin_history_serial_id > $2"
+ " ORDER BY coin_history_serial_id DESC;");
+ PREPARE (pg,
+ "get_deposit_with_coin_pub",
+ "SELECT"
+ " cdep.amount_with_fee"
+ ",denoms.fee_deposit"
+ ",denoms.denom_pub_hash"
+ ",kc.age_commitment_hash"
+ ",bdep.wallet_timestamp"
+ ",bdep.refund_deadline"
+ ",bdep.wire_deadline"
+ ",bdep.merchant_pub"
+ ",bdep.h_contract_terms"
+ ",bdep.wallet_data_hash"
+ ",bdep.wire_salt"
+ ",wt.payto_uri"
+ ",cdep.coin_sig"
+ ",cdep.coin_deposit_serial_id"
+ ",bdep.done"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE cdep.coin_pub=$1"
+ " AND cdep.coin_deposit_serial_id=$2;");
+ PREPARE (pg,
+ "get_refresh_session_by_coin",
+ "SELECT"
+ " rc"
+ ",old_coin_sig"
+ ",amount_with_fee"
+ ",denoms.denom_pub_hash"
+ ",denoms.fee_refresh"
+ ",kc.age_commitment_hash"
+ ",melt_serial_id"
+ " FROM refresh_commitments"
+ " JOIN known_coins kc"
+ " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE old_coin_pub=$1"
+ " AND melt_serial_id=$2;");
+ PREPARE (pg,
+ "get_purse_deposit_by_coin_pub",
+ "SELECT"
+ " partner_base_url"
+ ",pd.amount_with_fee"
+ ",denoms.fee_deposit"
+ ",pd.purse_pub"
+ ",kc.age_commitment_hash"
+ ",pd.coin_sig"
+ ",pd.purse_deposit_serial_id"
+ ",pdes.refunded"
+ " FROM purse_deposits pd"
+ " LEFT JOIN partners"
+ " USING (partner_serial_id)"
+ " JOIN purse_requests pr"
+ " USING (purse_pub)"
+ " LEFT JOIN purse_decision pdes"
+ " USING (purse_pub)"
+ " JOIN known_coins kc"
+ " ON (pd.coin_pub = kc.coin_pub)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE pd.purse_deposit_serial_id=$2"
+ " AND pd.coin_pub=$1;");
+ PREPARE (pg,
+ "get_purse_decision_by_coin_pub",
+ "SELECT"
+ " pdes.purse_pub"
+ ",pd.amount_with_fee"
+ ",denom.fee_refund"
+ ",pdes.purse_decision_serial_id"
+ " FROM purse_decision pdes"
+ " JOIN purse_deposits pd"
+ " USING (purse_pub)"
+ " JOIN known_coins kc"
+ " ON (pd.coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE pd.coin_pub=$1"
+ " AND pdes.purse_decision_serial_id=$2"
+ " AND pdes.refunded;");
+ PREPARE (pg,
+ "get_refunds_by_coin",
+ "SELECT"
+ " bdep.merchant_pub"
+ ",ref.merchant_sig"
+ ",bdep.h_contract_terms"
+ ",ref.rtransaction_id"
+ ",ref.amount_with_fee"
+ ",denom.fee_refund"
+ ",ref.refund_serial_id"
+ " FROM refunds ref"
+ " JOIN coin_deposits cdep"
+ " ON (ref.coin_pub = cdep.coin_pub AND ref.batch_deposit_serial_id = cdep.batch_deposit_serial_id)"
+ " JOIN batch_deposits bdep"
+ " ON (ref.batch_deposit_serial_id = bdep.batch_deposit_serial_id)"
+ " JOIN known_coins kc"
+ " ON (ref.coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE ref.coin_pub=$1"
+ " AND ref.refund_serial_id=$2;");
+ PREPARE (pg,
+ "recoup_by_old_coin",
+ "SELECT"
+ " coins.coin_pub"
+ ",rr.coin_sig"
+ ",rr.coin_blind"
+ ",rr.amount"
+ ",rr.recoup_timestamp"
+ ",denoms.denom_pub_hash"
+ ",coins.denom_sig"
+ ",rr.recoup_refresh_uuid"
+ " FROM recoup_refresh rr"
+ " JOIN known_coins coins"
+ " USING (coin_pub)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE recoup_refresh_uuid=$2"
+ " AND rrc_serial IN"
+ " (SELECT rrc.rrc_serial"
+ " FROM refresh_commitments melt"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (melt_serial_id)"
+ " WHERE melt.old_coin_pub=$1);");
+ PREPARE (pg,
+ "recoup_by_coin",
+ "SELECT"
+ " res.reserve_pub"
+ ",denoms.denom_pub_hash"
+ ",rcp.coin_sig"
+ ",rcp.coin_blind"
+ ",rcp.amount"
+ ",rcp.recoup_timestamp"
+ ",rcp.recoup_uuid"
+ " FROM recoup rcp"
+ " JOIN reserves_out ro"
+ " USING (reserve_out_serial_id)"
+ " JOIN reserves res"
+ " USING (reserve_uuid)"
+ " JOIN known_coins coins"
+ " USING (coin_pub)"
+ " JOIN denominations denoms"
+ " ON (denoms.denominations_serial = coins.denominations_serial)"
+ " WHERE rcp.recoup_uuid=$2"
+ " AND coins.coin_pub=$1;");
+ /* Used in #postgres_get_coin_transactions() to obtain recoup transactions
+ for a refreshed coin */
+ PREPARE (pg,
+ "recoup_by_refreshed_coin",
+ "SELECT"
+ " old_coins.coin_pub AS old_coin_pub"
+ ",rr.coin_sig"
+ ",rr.coin_blind"
+ ",rr.amount"
+ ",rr.recoup_timestamp"
+ ",denoms.denom_pub_hash"
+ ",coins.denom_sig"
+ ",recoup_refresh_uuid"
+ " FROM recoup_refresh rr"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (rrc_serial)"
+ " JOIN refresh_commitments rfc"
+ " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
+ " JOIN known_coins old_coins"
+ " ON (rfc.old_coin_pub = old_coins.coin_pub)"
+ " JOIN known_coins coins"
+ " ON (rr.coin_pub = coins.coin_pub)"
+ " JOIN denominations denoms"
+ " ON (denoms.denominations_serial = coins.denominations_serial)"
+ " WHERE rr.recoup_refresh_uuid=$2"
+ " AND coins.coin_pub=$1;");
+ PREPARE (pg,
+ "reserve_open_by_coin",
+ "SELECT"
+ " reserve_open_deposit_uuid"
+ ",coin_sig"
+ ",reserve_sig"
+ ",contribution"
+ " FROM reserves_open_deposits"
+ " WHERE coin_pub=$1"
+ " AND reserve_open_deposit_uuid=$2;");
+
+ for (unsigned int i = 0; i<RETRIES; i++)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ uint64_t end;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("coin_history_serial_id",
+ &end),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ h_denom_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("remaining",
+ balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ TEH_PG_start_read_committed (pg,
+ "get-coin-transactions"))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ /* First only check the last item, to see if
+ we even need to iterate */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_coin_history_etag_balance",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ *etag_out = end;
+ if (end == etag_in)
+ return qs;
+ }
+ /* We indeed need to iterate over the history */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Current ETag for coin %s is %llu\n",
+ TALER_B2S (coin_pub),
+ (unsigned long long) end);
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "get_coin_history",
+ lparams,
+ &handle_history_entry,
+ &chc);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ default:
+ break;
+ }
+ if (chc.failed)
+ {
+ TEH_PG_rollback (pg);
+ TEH_COMMON_free_coin_transaction_list (pg,
+ chc.head);
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ }
+ qs = TEH_PG_commit (pg);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_COMMON_free_coin_transaction_list (pg,
+ chc.head);
+ chc.head = NULL;
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_COMMON_free_coin_transaction_list (pg,
+ chc.head);
+ chc.head = NULL;
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ *tlp = chc.head;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+}
diff --git a/src/exchangedb/pg_get_coin_transactions.h b/src/exchangedb/pg_get_coin_transactions.h
new file mode 100644
index 000000000..46e32e094
--- /dev/null
+++ b/src/exchangedb/pg_get_coin_transactions.h
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_coin_transactions.h
+ * @brief implementation of the get_coin_transactions function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_COIN_TRANSACTIONS_H
+#define PG_GET_COIN_TRANSACTIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Compile a list of (historic) transactions performed with the given coin
+ * (melt, refund, recoup and deposit operations). Should return 0 if the @a
+ * coin_pub is unknown, otherwise determine @a etag_out and if it is past @a
+ * etag_in return the history after @a start_off. @a etag_out should be set
+ * to the last row ID of the given @a coin_pub in the coin history table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param coin_pub coin to investigate
+ * @param start_off starting offset from which on to return entries
+ * @param etag_in up to this offset the client already has a response, do not
+ * return anything unless @a etag_out will be larger
+ * @param[out] etag_out set to the latest history offset known for this @a coin_pub
+ * @param[out] balance set to current balance of the coin
+ * @param[out] h_denom_pub set to denomination public key of the coin
+ * @param[out] tlp set to list of transactions, set to NULL if coin has no
+ * transaction history past @a start_off or if @a etag_in is equal
+ * to the value written to @a etag_out.
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_coin_transactions (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
+ struct TALER_Amount *balance,
+ struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_TransactionList **tlp);
+
+
+#endif
diff --git a/src/exchangedb/pg_get_denomination_info.c b/src/exchangedb/pg_get_denomination_info.c
new file mode 100644
index 000000000..4bae29795
--- /dev/null
+++ b/src/exchangedb/pg_get_denomination_info.c
@@ -0,0 +1,91 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_denomination_info.c
+ * @brief Implementation of the get_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_denomination_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_denomination_info (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_EXCHANGEDB_DenominationKeyInformation *issue)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &issue->signature),
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &issue->start),
+ GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
+ &issue->expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp ("expire_deposit",
+ &issue->expire_deposit),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &issue->expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &issue->value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &issue->fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &issue->fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &issue->fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &issue->fees.refund),
+ GNUNET_PQ_result_spec_uint32 ("age_mask",
+ &issue->age_mask.bits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "denomination_get",
+ "SELECT"
+ " master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin" /* value of this denom */
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "denomination_get",
+ params,
+ rs);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ return qs;
+ issue->denom_hash = *denom_pub_hash;
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_denomination_info.h b/src/exchangedb/pg_get_denomination_info.h
new file mode 100644
index 000000000..843227759
--- /dev/null
+++ b/src/exchangedb/pg_get_denomination_info.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_denomination_info.h
+ * @brief implementation of the get_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_DENOMINATION_INFO_H
+#define PG_GET_DENOMINATION_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Fetch information about a denomination key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub_hash hash of the public key used for signing coins of this denomination
+ * @param[out] issue set to issue information with value, fees and other info about the coin
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_denomination_info (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_EXCHANGEDB_DenominationKeyInformation *issue);
+
+#endif
diff --git a/src/exchangedb/pg_get_denomination_revocation.c b/src/exchangedb/pg_get_denomination_revocation.c
new file mode 100644
index 000000000..5e7a3a322
--- /dev/null
+++ b/src/exchangedb/pg_get_denomination_revocation.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_denomination_revocation.c
+ * @brief Implementation of the get_denomination_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_denomination_revocation.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_denomination_revocation (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_MasterSignatureP *master_sig,
+ uint64_t *rowid)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_uint64 ("denom_revocations_serial_id",
+ rowid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "denomination_revocation_get",
+ "SELECT"
+ " master_sig"
+ ",denom_revocations_serial_id"
+ " FROM denomination_revocations"
+ " WHERE denominations_serial="
+ " (SELECT denominations_serial"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "denomination_revocation_get",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_denomination_revocation.h b/src/exchangedb/pg_get_denomination_revocation.h
new file mode 100644
index 000000000..5f7f27227
--- /dev/null
+++ b/src/exchangedb/pg_get_denomination_revocation.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_denomination_revocation.h
+ * @brief implementation of the get_denomination_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_DENOMINATION_REVOCATION_H
+#define PG_GET_DENOMINATION_REVOCATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain information about a denomination key's revocation from
+ * the database.
+ *
+ * @param cls closure
+ * @param denom_pub_hash hash of the revoked denomination key
+ * @param[out] master_sig signature affirming the revocation
+ * @param[out] rowid row where the information is stored
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_denomination_revocation (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_MasterSignatureP *master_sig,
+ uint64_t *rowid);
+
+#endif
diff --git a/src/exchangedb/pg_get_drain_profit.c b/src/exchangedb/pg_get_drain_profit.c
new file mode 100644
index 000000000..75fccefcd
--- /dev/null
+++ b/src/exchangedb/pg_get_drain_profit.c
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_drain_profit.c
+ * @brief Implementation of the get_drain_profit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_drain_profit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
+ serial),
+ GNUNET_PQ_result_spec_string ("account_section",
+ account_section),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ GNUNET_PQ_result_spec_timestamp ("trigger_date",
+ request_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ amount),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_profit_drain",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE wtid=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_profit_drain",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_drain_profit.h b/src/exchangedb/pg_get_drain_profit.h
new file mode 100644
index 000000000..dd05d8afd
--- /dev/null
+++ b/src/exchangedb/pg_get_drain_profit.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_drain_profit.h
+ * @brief implementation of the get_drain_profit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_DRAIN_PROFIT_H
+#define PG_GET_DRAIN_PROFIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to get information about a profit drain event.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to look up drain event for
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_get_expired_reserves.c b/src/exchangedb/pg_get_expired_reserves.c
new file mode 100644
index 000000000..be9ece98a
--- /dev/null
+++ b/src/exchangedb/pg_get_expired_reserves.c
@@ -0,0 +1,174 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_expired_reserves.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_expired_reserves.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #reserve_expired_cb().
+ */
+struct ExpiredReserveContext
+{
+ /**
+ * Function to call for each expired reserve.
+ */
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *rec_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_expired_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ExpiredReserveContext *erc = cls;
+ struct PostgresClosure *pg = erc->pg;
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = GNUNET_OK;
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp exp_date;
+ char *account_details;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount remaining_balance;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &exp_date),
+ GNUNET_PQ_result_spec_string ("account_details",
+ &account_details),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ &remaining_balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ ret = erc->rec (erc->rec_cls,
+ &reserve_pub,
+ &remaining_balance,
+ account_details,
+ exp_date,
+ 0);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+ erc->status = ret;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_expired_reserves (void *cls,
+ struct GNUNET_TIME_Timestamp now,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct ExpiredReserveContext ectx = {
+ .rec = rec,
+ .rec_cls = rec_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "get_expired_reserves",
+ "WITH ed AS MATERIALIZED ( "
+ " SELECT * "
+ " FROM reserves "
+ " WHERE expiration_date <= $1 "
+ " AND ((current_balance).val != 0 OR (current_balance).frac != 0) "
+ " ORDER BY expiration_date ASC "
+ " LIMIT 1 "
+ ") "
+ "SELECT "
+ " ed.expiration_date "
+ " ,payto_uri AS account_details "
+ " ,ed.reserve_pub "
+ " ,current_balance "
+ "FROM ( "
+ " SELECT "
+ " * "
+ " FROM reserves_in "
+ " WHERE reserve_pub = ( "
+ " SELECT reserve_pub FROM ed) "
+ " ) ri "
+ "JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto) "
+ "JOIN ed ON (ri.reserve_pub = ed.reserve_pub);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_expired_reserves",
+ params,
+ &reserve_expired_cb,
+ &ectx);
+ switch (ectx.status)
+ {
+ case GNUNET_SYSERR:
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_NO:
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ case GNUNET_OK:
+ break;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_expired_reserves.h b/src/exchangedb/pg_get_expired_reserves.h
new file mode 100644
index 000000000..0874b531a
--- /dev/null
+++ b/src/exchangedb/pg_get_expired_reserves.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_expired_reserves.h
+ * @brief implementation of the get_expired_reserves function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_EXPIRED_RESERVES_H
+#define PG_GET_EXPIRED_RESERVES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Obtain information about expired reserves and their
+ * remaining balances.
+ *
+ * @param cls closure of the plugin
+ * @param now timestamp based on which we decide expiration
+ * @param rec function to call on expired reserves
+ * @param rec_cls closure for @a rec
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_expired_reserves (void *cls,
+ struct GNUNET_TIME_Timestamp now,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_extension_manifest.c b/src/exchangedb/pg_get_extension_manifest.c
new file mode 100644
index 000000000..c6b5948cf
--- /dev/null
+++ b/src/exchangedb/pg_get_extension_manifest.c
@@ -0,0 +1,67 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_extension_manifest.c
+ * @brief Implementation of the get_extension_manifest function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_extension_manifest.h"
+#include "pg_helper.h"
+
+/**
+ * Function called to get the manifest of an extension
+ * (age-restriction, policy_extension_...)
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param extension_name the name of the extension
+ * @param[out] manifest JSON object of the manifest as string
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_extension_manifest (void *cls,
+ const char *extension_name,
+ char **manifest)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (extension_name),
+ GNUNET_PQ_query_param_end
+ };
+ bool is_null;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("manifest",
+ manifest),
+ &is_null),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *manifest = NULL;
+ PREPARE (pg,
+ "get_extension_manifest",
+ "SELECT"
+ " manifest"
+ " FROM extensions"
+ " WHERE name=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_extension_manifest",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_extension_manifest.h b/src/exchangedb/pg_get_extension_manifest.h
new file mode 100644
index 000000000..e8331ad9b
--- /dev/null
+++ b/src/exchangedb/pg_get_extension_manifest.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_extension_manifest.h
+ * @brief implementation of the get_extension_manifest function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_EXTENSION_MANIFEST_H
+#define PG_GET_EXTENSION_MANIFEST_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to get the manifest of an extension
+ * (age-restriction, policy_extension_...)
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param extension_name the name of the extension
+ * @param[out] manifest JSON object of the manifest as string
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_extension_manifest (void *cls,
+ const char *extension_name,
+ char **manifest);
+
+#endif
diff --git a/src/exchangedb/pg_get_global_fee.c b/src/exchangedb/pg_get_global_fee.c
new file mode 100644
index 000000000..46addfa17
--- /dev/null
+++ b/src/exchangedb/pg_get_global_fee.c
@@ -0,0 +1,86 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_global_fee.c
+ * @brief Implementation of the get_global_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_global_fee.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_global_fee (void *cls,
+ struct GNUNET_TIME_Timestamp date,
+ struct GNUNET_TIME_Timestamp *start_date,
+ struct GNUNET_TIME_Timestamp *end_date,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *purse_timeout,
+ struct GNUNET_TIME_Relative *history_expiration,
+ uint32_t *purse_account_limit,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
+ &fees->history),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
+ &fees->account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &fees->purse),
+ GNUNET_PQ_result_spec_relative_time ("purse_timeout",
+ purse_timeout),
+ GNUNET_PQ_result_spec_relative_time ("history_expiration",
+ history_expiration),
+ GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
+ purse_account_limit),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_global_fee",
+ "SELECT "
+ " start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ " FROM global_fee"
+ " WHERE start_date <= $1"
+ " AND end_date > $1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_global_fee",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_global_fee.h b/src/exchangedb/pg_get_global_fee.h
new file mode 100644
index 000000000..1e7c9e94b
--- /dev/null
+++ b/src/exchangedb/pg_get_global_fee.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_global_fee.h
+ * @brief implementation of the get_global_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_GLOBAL_FEE_H
+#define PG_GET_GLOBAL_FEE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Obtain global fees from database.
+ *
+ * @param cls closure
+ * @param date for which date do we want the fee?
+ * @param[out] start_date when does the fee go into effect
+ * @param[out] end_date when does the fee end being valid
+ * @param[out] fees how high are the wire fees
+ * @param[out] purse_timeout set to how long we keep unmerged purses
+ * @param[out] history_expiration set to how long we keep account histories
+ * @param[out] purse_account_limit set to the number of free purses per account
+ * @param[out] master_sig signature over the above by the exchange master key
+ * @return status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_global_fee (void *cls,
+ struct GNUNET_TIME_Timestamp date,
+ struct GNUNET_TIME_Timestamp *start_date,
+ struct GNUNET_TIME_Timestamp *end_date,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *purse_timeout,
+ struct GNUNET_TIME_Relative *history_expiration,
+ uint32_t *purse_account_limit,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_get_global_fees.c b/src/exchangedb/pg_get_global_fees.c
new file mode 100644
index 000000000..21be35989
--- /dev/null
+++ b/src/exchangedb/pg_get_global_fees.c
@@ -0,0 +1,165 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_global_fees.c
+ * @brief Implementation of the get_global_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_global_fees.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #global_fees_cb().
+ */
+struct GlobalFeeContext
+{
+ /**
+ * Function to call for each global fee block.
+ */
+ TALER_EXCHANGEDB_GlobalFeeCallback cb;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+global_fees_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GlobalFeeContext *gctx = cls;
+ struct PostgresClosure *pg = gctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_GlobalFeeSet fees;
+ struct GNUNET_TIME_Relative purse_timeout;
+ struct GNUNET_TIME_Relative history_expiration;
+ uint32_t purse_account_limit;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
+ &fees.history),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
+ &fees.account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &fees.purse),
+ GNUNET_PQ_result_spec_relative_time ("purse_timeout",
+ &purse_timeout),
+ GNUNET_PQ_result_spec_relative_time ("history_expiration",
+ &history_expiration),
+ GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
+ &purse_account_limit),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ gctx->status = GNUNET_SYSERR;
+ break;
+ }
+ gctx->cb (gctx->cb_cls,
+ &fees,
+ purse_timeout,
+ history_expiration,
+ purse_account_limit,
+ start_date,
+ end_date,
+ &master_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_global_fees (void *cls,
+ TALER_EXCHANGEDB_GlobalFeeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp date
+ = GNUNET_TIME_absolute_to_timestamp (
+ GNUNET_TIME_absolute_subtract (
+ GNUNET_TIME_absolute_get (),
+ GNUNET_TIME_UNIT_YEARS));
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_end
+ };
+ struct GlobalFeeContext gctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+
+ PREPARE (pg,
+ "get_global_fees",
+ "SELECT "
+ " start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ " FROM global_fee"
+ " WHERE start_date >= $1");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_global_fees",
+ params,
+ &global_fees_cb,
+ &gctx);
+}
diff --git a/src/exchangedb/pg_get_global_fees.h b/src/exchangedb/pg_get_global_fees.h
new file mode 100644
index 000000000..80c9b812f
--- /dev/null
+++ b/src/exchangedb/pg_get_global_fees.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_global_fees.h
+ * @brief implementation of the get_global_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_GLOBAL_FEES_H
+#define PG_GET_GLOBAL_FEES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain global fees from database.
+ *
+ * @param cls closure
+ * @param cb function to call on each fee entry
+ * @param cb_cls closure for @a cb
+ * @return status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_global_fees (void *cls,
+ TALER_EXCHANGEDB_GlobalFeeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_known_coin.c b/src/exchangedb/pg_get_known_coin.c
new file mode 100644
index 000000000..2c4a82d67
--- /dev/null
+++ b/src/exchangedb/pg_get_known_coin.c
@@ -0,0 +1,67 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_known_coin.c
+ * @brief Implementation of the get_known_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_known_coin.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_known_coin (void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_CoinPublicInfo *coin_info)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &coin_info->denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &coin_info->h_age_commitment),
+ &coin_info->no_age_commitment),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &coin_info->denom_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting known coin data for coin %s\n",
+ TALER_B2S (coin_pub));
+ coin_info->coin_pub = *coin_pub;
+ PREPARE (pg,
+ "get_known_coin",
+ "SELECT"
+ " denominations.denom_pub_hash"
+ ",age_commitment_hash"
+ ",denom_sig"
+ " FROM known_coins"
+ " JOIN denominations USING (denominations_serial)"
+ " WHERE coin_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_known_coin",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_known_coin.h b/src/exchangedb/pg_get_known_coin.h
new file mode 100644
index 000000000..c34bd2a97
--- /dev/null
+++ b/src/exchangedb/pg_get_known_coin.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_known_coin.h
+ * @brief implementation of the get_known_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_KNOWN_COIN_H
+#define PG_GET_KNOWN_COIN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Retrieve the record for a known coin.
+ *
+ * @param cls the plugin closure
+ * @param coin_pub the public key of the coin to search for
+ * @param coin_info place holder for the returned coin information object
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_known_coin (void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_CoinPublicInfo *coin_info);
+
+#endif
diff --git a/src/exchangedb/pg_get_link_data.c b/src/exchangedb/pg_get_link_data.c
new file mode 100644
index 000000000..1b0cb3e20
--- /dev/null
+++ b/src/exchangedb/pg_get_link_data.c
@@ -0,0 +1,367 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_link_data.c
+ * @brief Implementation of the get_link_data function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_link_data.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #add_ldl().
+ */
+struct LinkDataContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_LinkCallback ldc;
+
+ /**
+ * Closure for @e ldc.
+ */
+ void *ldc_cls;
+
+ /**
+ * Last transfer public key for which we have information in @e last.
+ * Only valid if @e last is non-NULL.
+ */
+ struct TALER_TransferPublicKeyP transfer_pub;
+
+ /**
+ * Status, set to #GNUNET_SYSERR on errors,
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Free memory of the link data list.
+ *
+ * @param ldl link data list to release
+ */
+static void
+free_link_data_list (struct TALER_EXCHANGEDB_LinkList *ldl)
+{
+ struct TALER_EXCHANGEDB_LinkList *next;
+
+ while (NULL != ldl)
+ {
+ next = ldl->next;
+ TALER_denom_pub_free (&ldl->denom_pub);
+ TALER_blinded_denom_sig_free (&ldl->ev_sig);
+ TALER_denom_ewv_free (&ldl->alg_values);
+ GNUNET_free (ldl);
+ ldl = next;
+ }
+}
+
+
+struct Results
+{
+ struct TALER_EXCHANGEDB_LinkList *pos;
+ struct TALER_TransferPublicKeyP transfer_pub;
+};
+
+
+static int
+transfer_pub_cmp (const void *a,
+ const void *b)
+{
+ const struct Results *ra = a;
+ const struct Results *rb = b;
+
+ return GNUNET_memcmp (&ra->transfer_pub,
+ &rb->transfer_pub);
+}
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct LinkDataContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_ldl (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LinkDataContext *ldctx = cls;
+ struct Results *temp = GNUNET_new_array (num_results,
+ struct Results);
+ unsigned int temp_off = 0;
+
+ for (int i = num_results - 1; i >= 0; i--)
+ {
+ struct TALER_EXCHANGEDB_LinkList *pos;
+
+ pos = GNUNET_new (struct TALER_EXCHANGEDB_LinkList);
+ {
+ struct TALER_BlindedPlanchet bp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
+ &temp[temp_off].transfer_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("link_sig",
+ &pos->orig_coin_link_sig),
+ TALER_PQ_result_spec_blinded_denom_sig ("ev_sig",
+ &pos->ev_sig),
+ GNUNET_PQ_result_spec_uint32 ("freshcoin_index",
+ &pos->coin_refresh_offset),
+ TALER_PQ_result_spec_exchange_withdraw_values ("ewv",
+ &pos->alg_values),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &pos->denom_pub),
+ TALER_PQ_result_spec_blinded_planchet ("coin_ev",
+ &bp),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ GNUNET_free (pos);
+ ldctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (GNUNET_CRYPTO_BSA_CS == bp.blinded_message->cipher)
+ {
+ pos->nonce.cs_nonce
+ = bp.blinded_message->details.cs_blinded_message.nonce;
+ pos->have_nonce = true;
+ }
+ TALER_blinded_planchet_free (&bp);
+ }
+ temp[temp_off].pos = pos;
+ temp_off++;
+ }
+ qsort (temp,
+ temp_off,
+ sizeof (struct Results),
+ &transfer_pub_cmp);
+ if (temp_off > 0)
+ {
+ struct TALER_EXCHANGEDB_LinkList *head = NULL;
+
+ head = temp[0].pos;
+ for (unsigned int i = 1; i < temp_off; i++)
+ {
+ struct TALER_EXCHANGEDB_LinkList *pos = temp[i].pos;
+ const struct TALER_TransferPublicKeyP *tp = &temp[i].transfer_pub;
+
+ if (0 == GNUNET_memcmp (tp,
+ &temp[i - 1].transfer_pub))
+ {
+ pos->next = head;
+ head = pos;
+ }
+ else
+ {
+ ldctx->ldc (ldctx->ldc_cls,
+ &temp[i - 1].transfer_pub,
+ head);
+ free_link_data_list (head);
+ head = pos;
+ }
+ }
+ ldctx->ldc (ldctx->ldc_cls,
+ &temp[temp_off - 1].transfer_pub,
+ head);
+ free_link_data_list (head);
+ }
+ GNUNET_free (temp);
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_link_data (void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ TALER_EXCHANGEDB_LinkCallback ldc,
+ void *ldc_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct LinkDataContext ldctx;
+ static int percent_refund = -2;
+ const char *query;
+
+ if (-2 == percent_refund)
+ {
+ const char *mode = getenv ("TALER_POSTGRES_GET_LINK_DATA_LOGIC");
+ char dummy;
+
+ if ( (NULL==mode) ||
+ (1 != sscanf (mode,
+ "%d%c",
+ &percent_refund,
+ &dummy)) )
+ {
+ if (NULL != mode)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Bad mode `%s' specified\n",
+ mode);
+ percent_refund = 4; /* Fastest known */
+ }
+ }
+ switch (percent_refund)
+ {
+ case 0:
+ query = "get_link";
+ PREPARE (pg,
+ query,
+ "SELECT "
+ " tp.transfer_pub"
+ ",denoms.denom_pub"
+ ",rrc.ev_sig"
+ ",rrc.ewv"
+ ",rrc.link_sig"
+ ",rrc.freshcoin_index"
+ ",rrc.coin_ev"
+ " FROM refresh_commitments"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (melt_serial_id)"
+ " JOIN refresh_transfer_keys tp"
+ " USING (melt_serial_id)"
+ " JOIN denominations denoms"
+ " ON (rrc.denominations_serial = denoms.denominations_serial)"
+ " WHERE old_coin_pub=$1"
+ " ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC");
+ break;
+ case 1:
+ query = "get_link_v1";
+ PREPARE (pg,
+ query,
+ "WITH rc AS MATERIALIZED ("
+ "SELECT"
+ " melt_serial_id"
+ " FROM refresh_commitments"
+ " WHERE old_coin_pub=$1"
+ ")"
+ "SELECT "
+ " tp.transfer_pub"
+ ",denoms.denom_pub"
+ ",rrc.ev_sig"
+ ",rrc.ewv"
+ ",rrc.link_sig"
+ ",rrc.freshcoin_index"
+ ",rrc.coin_ev "
+ "FROM "
+ "refresh_revealed_coins rrc"
+ " JOIN refresh_transfer_keys tp"
+ " USING (melt_serial_id)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE rrc.melt_serial_id = (SELECT melt_serial_id FROM rc)"
+ " ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC");
+ break;
+ case 2:
+ query = "get_link_v2";
+ PREPARE (pg,
+ query,
+ "SELECT"
+ " *"
+ " FROM"
+ " exchange_do_get_link_data"
+ " ($1) "
+ " AS "
+ " (transfer_pub BYTEA"
+ " ,denom_pub BYTEA"
+ " ,ev_sig BYTEA"
+ " ,ewv BYTEA"
+ " ,link_sig BYTEA"
+ " ,freshcoin_index INT4"
+ " ,coin_ev BYTEA);");
+ break;
+ case 3:
+ query = "get_link_v3";
+ PREPARE (pg,
+ query,
+ "SELECT "
+ " tp.transfer_pub"
+ ",denoms.denom_pub"
+ ",rrc.ev_sig"
+ ",rrc.ewv"
+ ",rrc.link_sig"
+ ",rrc.freshcoin_index"
+ ",rrc.coin_ev"
+ " FROM refresh_commitments"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (melt_serial_id)"
+ " JOIN refresh_transfer_keys tp"
+ " USING (melt_serial_id)"
+ " JOIN denominations denoms"
+ " ON (rrc.denominations_serial = denoms.denominations_serial)"
+ " WHERE old_coin_pub=$1");
+ break;
+ case 4:
+ query = "get_link_v4";
+ PREPARE (pg,
+ query,
+ "WITH rc AS MATERIALIZED ("
+ "SELECT"
+ " melt_serial_id"
+ " FROM refresh_commitments"
+ " WHERE old_coin_pub=$1"
+ ")"
+ "SELECT "
+ " tp.transfer_pub"
+ ",denoms.denom_pub"
+ ",rrc.ev_sig"
+ ",rrc.ewv"
+ ",rrc.link_sig"
+ ",rrc.freshcoin_index"
+ ",rrc.coin_ev "
+ "FROM "
+ "refresh_revealed_coins rrc"
+ " JOIN refresh_transfer_keys tp"
+ " USING (melt_serial_id)"
+ " JOIN denominations denoms"
+ " USING (denominations_serial)"
+ " WHERE rrc.melt_serial_id = (SELECT melt_serial_id FROM rc)"
+ );
+ break;
+ default:
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ ldctx.ldc = ldc;
+ ldctx.ldc_cls = ldc_cls;
+ ldctx.status = GNUNET_OK;
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ query,
+ params,
+ &add_ldl,
+ &ldctx);
+ if (GNUNET_OK != ldctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_link_data.h b/src/exchangedb/pg_get_link_data.h
new file mode 100644
index 000000000..09d3a69fc
--- /dev/null
+++ b/src/exchangedb/pg_get_link_data.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_link_data.h
+ * @brief implementation of the get_link_data function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_LINK_DATA_H
+#define PG_GET_LINK_DATA_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Obtain the link data of a coin, that is the encrypted link
+ * information, the denomination keys and the signatures.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param coin_pub public key of the coin
+ * @param ldc function to call for each session the coin was melted into
+ * @param ldc_cls closure for @a tdc
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_link_data (void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ TALER_EXCHANGEDB_LinkCallback ldc,
+ void *ldc_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_melt.c b/src/exchangedb/pg_get_melt.c
new file mode 100644
index 000000000..2221054ba
--- /dev/null
+++ b/src/exchangedb/pg_get_melt.c
@@ -0,0 +1,124 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_melt.c
+ * @brief Implementation of the get_melt function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_melt.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_melt (void *cls,
+ const struct TALER_RefreshCommitmentP *rc,
+ struct TALER_EXCHANGEDB_Melt *melt,
+ uint64_t *melt_serial_id)
+{
+ struct PostgresClosure *pg = cls;
+ bool h_age_commitment_is_null;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (rc),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &melt->session.coin.
+ denom_pub_hash),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &melt->melt_fee),
+ GNUNET_PQ_result_spec_uint32 ("noreveal_index",
+ &melt->session.noreveal_index),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &melt->session.coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
+ &melt->session.coin_sig),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &melt->session.coin.h_age_commitment),
+ &h_age_commitment_is_null),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &melt->session.amount_with_fee),
+ GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
+ melt_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ memset (&melt->session.coin.denom_sig,
+ 0,
+ sizeof (melt->session.coin.denom_sig));
+
+ /* Used in #postgres_get_melt() to fetch
+ high-level information about a melt operation */
+ PREPARE (pg,
+ "get_melt",
+ /* "SELECT"
+ " denoms.denom_pub_hash"
+ ",denoms.fee_refresh"
+ ",old_coin_pub"
+ ",old_coin_sig"
+ ",kc.age_commitment_hash"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",melt_serial_id"
+ " FROM refresh_commitments"
+ " JOIN known_coins kc"
+ " ON (old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denoms"
+ " ON (kc.denominations_serial = denoms.denominations_serial)"
+ " WHERE rc=$1;", */
+ "WITH rc AS MATERIALIZED ( "
+ " SELECT"
+ " * FROM refresh_commitments"
+ " WHERE rc=$1"
+ ")"
+ "SELECT"
+ " denoms.denom_pub_hash"
+ ",denoms.fee_refresh"
+ ",rc.old_coin_pub"
+ ",rc.old_coin_sig"
+ ",kc.age_commitment_hash"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",melt_serial_id "
+ "FROM ("
+ " SELECT"
+ " * "
+ " FROM known_coins"
+ " WHERE coin_pub=(SELECT old_coin_pub from rc)"
+ ") kc "
+ "JOIN rc"
+ " ON (kc.coin_pub=rc.old_coin_pub) "
+ "JOIN denominations denoms"
+ " USING (denominations_serial);");
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_melt",
+ params,
+ rs);
+ if (h_age_commitment_is_null)
+ memset (&melt->session.coin.h_age_commitment,
+ 0,
+ sizeof(melt->session.coin.h_age_commitment));
+
+ melt->session.rc = *rc;
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_melt.h b/src/exchangedb/pg_get_melt.h
new file mode 100644
index 000000000..269960bad
--- /dev/null
+++ b/src/exchangedb/pg_get_melt.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_melt.h
+ * @brief implementation of the get_melt function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_MELT_H
+#define PG_GET_MELT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Lookup refresh melt commitment data under the given @a rc.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param rc commitment hash to use to locate the operation
+ * @param[out] melt where to store the result; note that
+ * melt->session.coin.denom_sig will be set to NULL
+ * and is not fetched by this routine (as it is not needed by the client)
+ * @param[out] melt_serial_id set to the row ID of @a rc in the refresh_commitments table
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_melt (void *cls,
+ const struct TALER_RefreshCommitmentP *rc,
+ struct TALER_EXCHANGEDB_Melt *melt,
+ uint64_t *melt_serial_id);
+
+#endif
diff --git a/src/exchangedb/pg_get_old_coin_by_h_blind.c b/src/exchangedb/pg_get_old_coin_by_h_blind.c
new file mode 100644
index 000000000..dcce7b32f
--- /dev/null
+++ b/src/exchangedb/pg_get_old_coin_by_h_blind.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_old_coin_by_h_blind.c
+ * @brief Implementation of the get_old_coin_by_h_blind function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_old_coin_by_h_blind.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_old_coin_by_h_blind (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *h_blind_ev,
+ struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ uint64_t *rrc_serial)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_blind_ev),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ old_coin_pub),
+ GNUNET_PQ_result_spec_uint64 ("rrc_serial",
+ rrc_serial),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_get_old_coin_by_h_blind() */
+ PREPARE (pg,
+ "old_coin_by_h_blind",
+ "SELECT"
+ " okc.coin_pub AS old_coin_pub"
+ ",rrc_serial"
+ " FROM refresh_revealed_coins rrc"
+ " JOIN refresh_commitments rcom USING (melt_serial_id)"
+ " JOIN known_coins okc ON (rcom.old_coin_pub = okc.coin_pub)"
+ " WHERE h_coin_ev=$1"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "old_coin_by_h_blind",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_old_coin_by_h_blind.h b/src/exchangedb/pg_get_old_coin_by_h_blind.h
new file mode 100644
index 000000000..93ed541b6
--- /dev/null
+++ b/src/exchangedb/pg_get_old_coin_by_h_blind.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_old_coin_by_h_blind.h
+ * @brief implementation of the get_old_coin_by_h_blind function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_OLD_COIN_BY_H_BLIND_H
+#define PG_GET_OLD_COIN_BY_H_BLIND_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain information about which old coin a coin was refreshed
+ * given the hash of the blinded (fresh) coin.
+ *
+ * @param cls closure
+ * @param h_blind_ev hash of the blinded coin
+ * @param[out] old_coin_pub set to information about the old coin (on success only)
+ * @param[out] rrc_serial set to serial number of the entry in the database
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_old_coin_by_h_blind (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *h_blind_ev,
+ struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ uint64_t *rrc_serial);
+
+#endif
diff --git a/src/exchangedb/pg_get_pending_kyc_requirement_process.c b/src/exchangedb/pg_get_pending_kyc_requirement_process.c
new file mode 100644
index 000000000..b9acddad1
--- /dev/null
+++ b/src/exchangedb/pg_get_pending_kyc_requirement_process.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_pending_kyc_requirement_process.c
+ * @brief Implementation of the get_pending_kyc_requirement_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_pending_kyc_requirement_process.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_pending_kyc_requirement_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ char **redirect_url)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("redirect_url",
+ redirect_url),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *redirect_url = NULL;
+ PREPARE (pg,
+ "get_pending_kyc_requirement_process",
+ "SELECT"
+ " redirect_url"
+ " FROM legitimization_processes"
+ " WHERE provider_section=$1"
+ " AND h_payto=$2"
+ " AND NOT finished"
+ " ORDER BY start_time DESC"
+ " LIMIT 1");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_pending_kyc_requirement_process",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_pending_kyc_requirement_process.h b/src/exchangedb/pg_get_pending_kyc_requirement_process.h
new file mode 100644
index 000000000..738c4d65b
--- /dev/null
+++ b/src/exchangedb/pg_get_pending_kyc_requirement_process.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_pending_kyc_requirement_process.h
+ * @brief implementation of the get_pending_kyc_requirement_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_PENDING_KYC_REQUIREMENT_PROCESS_H
+#define PG_GET_PENDING_KYC_REQUIREMENT_PROCESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Fetch information about pending KYC requirement process.
+ *
+ * @param cls closure
+ * @param h_payto account that must be KYC'ed
+ * @param provider_section provider that must be checked
+ * @param[out] redirect_url set to redirect URL for the process
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_pending_kyc_requirement_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ char **redirect_url);
+
+#endif
diff --git a/src/exchangedb/pg_get_policy_details.c b/src/exchangedb/pg_get_policy_details.c
new file mode 100644
index 000000000..6e1b5c5dc
--- /dev/null
+++ b/src/exchangedb/pg_get_policy_details.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_policy_details.c
+ * @brief Implementation of the get_policy_details function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_policy_details.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_policy_details (
+ void *cls,
+ const struct GNUNET_HashCode *hc,
+ struct TALER_PolicyDetails *details)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (hc),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &details->deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("commitment",
+ &details->commitment),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("accumulated_total",
+ &details->accumulated_total),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("policy_fee",
+ &details->policy_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("transferable_amount",
+ &details->transferable_amount),
+ GNUNET_PQ_result_spec_auto_from_type ("state",
+ &details->fulfillment_state),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("policy_fulfillment_id",
+ &details->policy_fulfillment_id),
+ &details->no_policy_fulfillment_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_policy_details",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_policy_details.h b/src/exchangedb/pg_get_policy_details.h
new file mode 100644
index 000000000..e3d2b0a2c
--- /dev/null
+++ b/src/exchangedb/pg_get_policy_details.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_policy_details.h
+ * @brief implementation of the get_policy_details function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_POLICY_DETAILS_H
+#define PG_GET_POLICY_DETAILS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/* Get the details of a policy, referenced by its hash code
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param hc The hash code under which the details to a particular policy should be found
+ * @param[out] details The found details
+ * @return query execution status
+ * */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_policy_details (
+ void *cls,
+ const struct GNUNET_HashCode *hc,
+ struct TALER_PolicyDetails *details);
+
+#endif
diff --git a/src/exchangedb/pg_get_purse_deposit.c b/src/exchangedb/pg_get_purse_deposit.c
new file mode 100644
index 000000000..cb24855a1
--- /dev/null
+++ b/src/exchangedb/pg_get_purse_deposit.c
@@ -0,0 +1,84 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_purse_deposit.c
+ * @brief Implementation of the get_purse_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_purse_deposit.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_purse_deposit (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount *amount,
+ struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_AgeCommitmentHash *phac,
+ struct TALER_CoinSpendSignatureP *coin_sig,
+ char **partner_url)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ bool is_null;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ h_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ phac),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ partner_url),
+ &is_null),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *partner_url = NULL;
+ PREPARE (pg,
+ "select_purse_deposit_by_coin_pub",
+ "SELECT "
+ " coin_sig"
+ ",amount_with_fee"
+ ",denom_pub_hash"
+ ",age_commitment_hash"
+ ",partner_base_url"
+ " FROM purse_deposits"
+ " LEFT JOIN partners"
+ " USING (partner_serial_id)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations"
+ " USING (denominations_serial)"
+ " WHERE purse_pub=$1"
+ " AND coin_pub=$2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_purse_deposit_by_coin_pub",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_purse_deposit.h b/src/exchangedb/pg_get_purse_deposit.h
new file mode 100644
index 000000000..b9c9947f4
--- /dev/null
+++ b/src/exchangedb/pg_get_purse_deposit.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_purse_deposit.h
+ * @brief implementation of the get_purse_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_PURSE_DEPOSIT_H
+#define PG_GET_PURSE_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to obtain a coin deposit data from
+ * depositing the coin into a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to credit
+ * @param coin_pub coin to deposit (debit)
+ * @param[out] amount set fraction of the coin's value that was deposited (with fee)
+ * @param[out] h_denom_pub set to hash of denomination of the coin
+ * @param[out] phac set to hash of age restriction on the coin
+ * @param[out] coin_sig set to signature affirming the operation
+ * @param[out] partner_url set to the URL of the partner exchange, or NULL for ourselves, must be freed by caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_purse_deposit (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount *amount,
+ struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_AgeCommitmentHash *phac,
+ struct TALER_CoinSpendSignatureP *coin_sig,
+ char **partner_url);
+
+#endif
diff --git a/src/exchangedb/pg_get_purse_request.c b/src/exchangedb/pg_get_purse_request.c
new file mode 100644
index 000000000..9d2ee5654
--- /dev/null
+++ b/src/exchangedb/pg_get_purse_request.c
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_template.c
+ * @brief Implementation of the template function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_purse_request.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_purse_request (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *target_amount,
+ struct TALER_Amount *balance,
+ struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ merge_pub),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ h_contract_terms),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ age_limit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ target_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ balance),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_purse_request",
+ "SELECT "
+ " merge_pub"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",amount_with_fee"
+ ",balance"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE purse_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_purse_request",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_purse_request.h b/src/exchangedb/pg_get_purse_request.h
new file mode 100644
index 000000000..24620e1b8
--- /dev/null
+++ b/src/exchangedb/pg_get_purse_request.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+
+/**
+ * @file exchangedb/pg_get_purse_request.h
+ * @brief implementation of the get_purse_request function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_PURSE_REQUEST_H
+#define PG_GET_PURSE_REQUEST_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to return meta data about a purse by the
+ * purse public key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the purse
+ * @param[out] merge_pub public key representing the merge capability
+ * @param[out] purse_expiration when would an unmerged purse expire
+ * @param[out] h_contract_terms contract associated with the purse
+ * @param[out] age_limit the age limit for deposits into the purse
+ * @param[out] target_amount amount to be put into the purse
+ * @param[out] balance amount put so far into the purse
+ * @param[out] purse_sig signature of the purse over the initialization data
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_purse_request (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *target_amount,
+ struct TALER_Amount *balance,
+ struct TALER_PurseContractSignatureP *purse_sig);
+
+#endif
diff --git a/src/exchangedb/pg_get_ready_deposit.c b/src/exchangedb/pg_get_ready_deposit.c
new file mode 100644
index 000000000..d8344faf1
--- /dev/null
+++ b/src/exchangedb/pg_get_ready_deposit.c
@@ -0,0 +1,74 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_ready_deposit.c
+ * @brief Implementation of the get_ready_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_ready_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_ready_deposit (void *cls,
+ uint64_t start_shard_row,
+ uint64_t end_shard_row,
+ struct TALER_MerchantPublicKeyP *merchant_pub,
+ char **payto_uri)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_uint64 (&start_shard_row),
+ GNUNET_PQ_query_param_uint64 (&end_shard_row),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ merchant_pub),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ GNUNET_PQ_result_spec_end
+ };
+ const char *query = "deposits_get_ready";
+
+ PREPARE (pg,
+ query,
+ "SELECT"
+ " wts.payto_uri"
+ ",bdep.merchant_pub"
+ " FROM batch_deposits bdep"
+ " JOIN wire_targets wts"
+ " USING (wire_target_h_payto)"
+ " WHERE NOT (bdep.done OR bdep.policy_blocked)"
+ " AND bdep.wire_deadline<=$1"
+ " AND bdep.shard >= $2"
+ " AND bdep.shard <= $3"
+ " ORDER BY "
+ " bdep.wire_deadline ASC"
+ " ,bdep.shard ASC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ query,
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_ready_deposit.h b/src/exchangedb/pg_get_ready_deposit.h
new file mode 100644
index 000000000..b1dd7a968
--- /dev/null
+++ b/src/exchangedb/pg_get_ready_deposit.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_ready_deposit.h
+ * @brief implementation of the get_ready_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_READY_DEPOSIT_H
+#define PG_GET_READY_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Obtain information about deposits that are ready to be executed. Such
+ * deposits must not be marked as "done", the execution time must be
+ * in the past, and the KYC status must be 'ok'.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param start_shard_row minimum shard row to select
+ * @param end_shard_row maximum shard row to select (inclusive)
+ * @param[out] merchant_pub set to the public key of a merchant with a ready deposit
+ * @param[out] payto_uri set to the account of the merchant, to be freed by caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_ready_deposit (void *cls,
+ uint64_t start_shard_row,
+ uint64_t end_shard_row,
+ struct TALER_MerchantPublicKeyP *merchant_pub,
+ char **payto_uri);
+
+#endif
diff --git a/src/exchangedb/pg_get_refresh_reveal.c b/src/exchangedb/pg_get_refresh_reveal.c
new file mode 100644
index 000000000..08d4b21a5
--- /dev/null
+++ b/src/exchangedb/pg_get_refresh_reveal.c
@@ -0,0 +1,213 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_refresh_reveal.c
+ * @brief Implementation of the get_refresh_reveal function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_refresh_reveal.h"
+#include "pg_helper.h"
+
+
+/**
+ * Context where we aggregate data from the database.
+ * Closure for #add_revealed_coins().
+ */
+struct GetRevealContext
+{
+ /**
+ * Array of revealed coins we obtained from the DB.
+ */
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs;
+
+ /**
+ * Length of the @a rrcs array.
+ */
+ unsigned int rrcs_len;
+
+ /**
+ * Set to an error code if we ran into trouble.
+ */
+ enum GNUNET_DB_QueryStatus qs;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct GetRevealContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+add_revealed_coins (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetRevealContext *grctx = cls;
+
+ if (0 == num_results)
+ return;
+ grctx->rrcs = GNUNET_new_array (num_results,
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin);
+ grctx->rrcs_len = num_results;
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint32_t off;
+ struct GNUNET_PQ_ResultSpec rso[] = {
+ GNUNET_PQ_result_spec_uint32 ("freshcoin_index",
+ &off),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rso,
+ i))
+ {
+ GNUNET_break (0);
+ grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if (off >= num_results)
+ {
+ GNUNET_break (0);
+ grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ {
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx->rrcs[off];
+ struct GNUNET_PQ_ResultSpec rsi[] = {
+ /* NOTE: freshcoin_index selected and discarded here... */
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &rrc->h_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("link_sig",
+ &rrc->orig_coin_link_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("h_coin_ev",
+ &rrc->coin_envelope_hash),
+ TALER_PQ_result_spec_blinded_planchet ("coin_ev",
+ &rrc->blinded_planchet),
+ TALER_PQ_result_spec_exchange_withdraw_values ("ewv",
+ &rrc->exchange_vals),
+ TALER_PQ_result_spec_blinded_denom_sig ("ev_sig",
+ &rrc->coin_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (NULL !=
+ rrc->blinded_planchet.blinded_message)
+ {
+ /* duplicate offset, not allowed */
+ GNUNET_break (0);
+ grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rsi,
+ i))
+ {
+ GNUNET_break (0);
+ grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return;
+ }
+ }
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_refresh_reveal (void *cls,
+ const struct TALER_RefreshCommitmentP *rc,
+ TALER_EXCHANGEDB_RefreshCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GetRevealContext grctx;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (rc),
+ GNUNET_PQ_query_param_end
+ };
+
+ memset (&grctx,
+ 0,
+ sizeof (grctx));
+
+ /* Obtain information about the coins created in a refresh
+ operation, used in #postgres_get_refresh_reveal() */
+ PREPARE (pg,
+ "get_refresh_revealed_coins",
+ "SELECT "
+ " rrc.freshcoin_index"
+ ",denom.denom_pub_hash"
+ ",rrc.h_coin_ev"
+ ",rrc.link_sig"
+ ",rrc.coin_ev"
+ ",rrc.ewv"
+ ",rrc.ev_sig"
+ " FROM refresh_commitments"
+ " JOIN refresh_revealed_coins rrc"
+ " USING (melt_serial_id)"
+ " JOIN denominations denom "
+ " USING (denominations_serial)"
+ " WHERE rc=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_refresh_revealed_coins",
+ params,
+ &add_revealed_coins,
+ &grctx);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ goto cleanup;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ default: /* can have more than one result */
+ break;
+ }
+ switch (grctx.qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ goto cleanup;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: /* should be impossible */
+ break;
+ }
+
+ /* Pass result back to application */
+ cb (cb_cls,
+ grctx.rrcs_len,
+ grctx.rrcs);
+cleanup:
+ for (unsigned int i = 0; i < grctx.rrcs_len; i++)
+ {
+ struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx.rrcs[i];
+
+ TALER_blinded_denom_sig_free (&rrc->coin_sig);
+ TALER_blinded_planchet_free (&rrc->blinded_planchet);
+ TALER_denom_ewv_free (&rrc->exchange_vals);
+ }
+ GNUNET_free (grctx.rrcs);
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_refresh_reveal.h b/src/exchangedb/pg_get_refresh_reveal.h
new file mode 100644
index 000000000..15b57b343
--- /dev/null
+++ b/src/exchangedb/pg_get_refresh_reveal.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_refresh_reveal.h
+ * @brief implementation of the get_refresh_reveal function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_REFRESH_REVEAL_H
+#define PG_GET_REFRESH_REVEAL_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Lookup in the database the coins that we want to
+ * create in the given refresh operation.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param rc identify commitment and thus refresh operation
+ * @param cb function to call with the results
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_refresh_reveal (void *cls,
+ const struct TALER_RefreshCommitmentP *rc,
+ TALER_EXCHANGEDB_RefreshCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_reserve_balance.c b/src/exchangedb/pg_get_reserve_balance.c
new file mode 100644
index 000000000..140bf3b70
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_balance.c
@@ -0,0 +1,55 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_reserve_balance.c
+ * @brief Implementation of the get_reserve_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_reserve_balance.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_balance (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_reserve_balance",
+ "SELECT"
+ " current_balance"
+ " FROM reserves"
+ " WHERE reserve_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_reserve_balance",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_reserve_balance.h b/src/exchangedb/pg_get_reserve_balance.h
new file mode 100644
index 000000000..6dc88d906
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_balance.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_reserve_balance.h
+ * @brief implementation of the get_reserve_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_RESERVE_BALANCE_H
+#define PG_GET_RESERVE_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Get the balance of the specified reserve.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param[out] balance set to the reserve balance
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_balance (void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance);
+
+#endif
diff --git a/src/exchangedb/pg_get_reserve_by_h_blind.c b/src/exchangedb/pg_get_reserve_by_h_blind.c
new file mode 100644
index 000000000..f87fe6cd4
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_by_h_blind.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_reserve_by_h_blind.c
+ * @brief Implementation of the get_reserve_by_h_blind function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_reserve_by_h_blind.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_by_h_blind (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *bch,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *reserve_out_serial_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (bch),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("reserve_out_serial_id",
+ reserve_out_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_get_reserve_by_h_blind() */
+ PREPARE (pg,
+ "reserve_by_h_blind",
+ "SELECT"
+ " reserves.reserve_pub"
+ ",reserve_out_serial_id"
+ " FROM reserves_out"
+ " JOIN reserves"
+ " USING (reserve_uuid)"
+ " WHERE h_blind_ev=$1"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "reserve_by_h_blind",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_reserve_by_h_blind.h b/src/exchangedb/pg_get_reserve_by_h_blind.h
new file mode 100644
index 000000000..49c1c8403
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_by_h_blind.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_reserve_by_h_blind.h
+ * @brief implementation of the get_reserve_by_h_blind function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_RESERVE_BY_H_BLIND_H
+#define PG_GET_RESERVE_BY_H_BLIND_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Obtain information about which reserve a coin was generated
+ * from given the hash of the blinded coin.
+ *
+ * @param cls closure
+ * @param bch hash that uniquely identifies the withdraw request
+ * @param[out] reserve_pub set to information about the reserve (on success only)
+ * @param[out] reserve_out_serial_id set to row of the @a h_blind_ev in reserves_out
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_by_h_blind (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *bch,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *reserve_out_serial_id);
+
+#endif
diff --git a/src/exchangedb/pg_get_reserve_history.c b/src/exchangedb/pg_get_reserve_history.c
new file mode 100644
index 000000000..1f1ca95b5
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_history.c
@@ -0,0 +1,936 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_reserve_history.c
+ * @brief Obtain (parts of) the history of a reserve.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_reserve_history.h"
+#include "pg_start_read_committed.h"
+#include "pg_commit.h"
+#include "pg_rollback.h"
+#include "plugin_exchangedb_common.h"
+#include "pg_helper.h"
+
+/**
+ * How often do we re-try when encountering DB serialization issues?
+ * (We are read-only, so can only happen due to concurrent insert,
+ * which should be very rare.)
+ */
+#define RETRIES 3
+
+
+/**
+ * Closure for callbacks invoked via #TEH_PG_get_reserve_history().
+ */
+struct ReserveHistoryContext
+{
+
+ /**
+ * Which reserve are we building the history for?
+ */
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ /**
+ * Where we build the history.
+ */
+ struct TALER_EXCHANGEDB_ReserveHistory *rh;
+
+ /**
+ * Tail of @e rh list.
+ */
+ struct TALER_EXCHANGEDB_ReserveHistory *rh_tail;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Sum of all credit transactions.
+ */
+ struct TALER_Amount balance_in;
+
+ /**
+ * Sum of all debit transactions.
+ */
+ struct TALER_Amount balance_out;
+
+ /**
+ * Set to true on serious internal errors during
+ * the callbacks.
+ */
+ bool failed;
+};
+
+
+/**
+ * Append and return a fresh element to the reserve
+ * history kept in @a rhc.
+ *
+ * @param rhc where the history is kept
+ * @return the fresh element that was added
+ */
+static struct TALER_EXCHANGEDB_ReserveHistory *
+append_rh (struct ReserveHistoryContext *rhc)
+{
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ tail = GNUNET_new (struct TALER_EXCHANGEDB_ReserveHistory);
+ if (NULL != rhc->rh_tail)
+ {
+ rhc->rh_tail->next = tail;
+ rhc->rh_tail = tail;
+ }
+ else
+ {
+ rhc->rh_tail = tail;
+ rhc->rh = tail;
+ }
+ return tail;
+}
+
+
+/**
+ * Add bank transfers to result set for #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_bank_to_exchange (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_BankTransfer *bt;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ &bt->wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
+ &bt->amount),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &bt->execution_date),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &bt->sender_account_details),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (bt);
+ rhc->failed = true;
+ return;
+ }
+ }
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_in,
+ &rhc->balance_in,
+ &bt->amount));
+ bt->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE;
+ tail->details.bank = bt;
+ } /* end of 'while (0 < rows)' */
+}
+
+
+/**
+ * Add coin withdrawals to result set for #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_withdraw_coin (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_CollectableBlindcoin *cbc;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ cbc = GNUNET_new (struct TALER_EXCHANGEDB_CollectableBlindcoin);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &cbc->h_coin_envelope),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &cbc->denom_pub_hash),
+ TALER_PQ_result_spec_blinded_denom_sig ("denom_sig",
+ &cbc->sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &cbc->reserve_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &cbc->amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &cbc->withdraw_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (cbc);
+ rhc->failed = true;
+ return;
+ }
+ }
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_out,
+ &rhc->balance_out,
+ &cbc->amount_with_fee));
+ cbc->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_WITHDRAW_COIN;
+ tail->details.withdraw = cbc;
+ }
+}
+
+
+/**
+ * Add recoups to result set for #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_recoup (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_Recoup *recoup;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ recoup = GNUNET_new (struct TALER_EXCHANGEDB_Recoup);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &recoup->value),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &recoup->coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &recoup->coin_blind),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &recoup->coin_sig),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &recoup->timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &recoup->coin.denom_pub_hash),
+ TALER_PQ_result_spec_denom_sig (
+ "denom_sig",
+ &recoup->coin.denom_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (recoup);
+ rhc->failed = true;
+ return;
+ }
+ }
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_in,
+ &rhc->balance_in,
+ &recoup->value));
+ recoup->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_RECOUP_COIN;
+ tail->details.recoup = recoup;
+ } /* end of 'while (0 < rows)' */
+}
+
+
+/**
+ * Add exchange-to-bank transfers to result set for
+ * #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_exchange_to_bank (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_ClosingTransfer *closing;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ closing = GNUNET_new (struct TALER_EXCHANGEDB_ClosingTransfer);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &closing->amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &closing->closing_fee),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &closing->execution_date),
+ GNUNET_PQ_result_spec_string ("receiver_account",
+ &closing->receiver_account_details),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ &closing->wtid),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (closing);
+ rhc->failed = true;
+ return;
+ }
+ }
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_out,
+ &rhc->balance_out,
+ &closing->amount));
+ closing->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK;
+ tail->details.closing = closing;
+ } /* end of 'while (0 < rows)' */
+}
+
+
+/**
+ * Add purse merge transfers to result set for
+ * #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_p2p_merge (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_PurseMerge *merge;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ merge = GNUNET_new (struct TALER_EXCHANGEDB_PurseMerge);
+ {
+ uint32_t flags32;
+ struct TALER_Amount balance;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &merge->purse_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &merge->amount_with_fee),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ &merge->merge_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ &merge->purse_expiration),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ &merge->min_age),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &merge->h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ &merge->merge_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &merge->purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &merge->reserve_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (merge);
+ rhc->failed = true;
+ return;
+ }
+ merge->flags = (enum TALER_WalletAccountMergeFlags) flags32;
+ if ( (! GNUNET_TIME_absolute_is_future (
+ merge->merge_timestamp.abs_time)) &&
+ (-1 != TALER_amount_cmp (&balance,
+ &merge->amount_with_fee)) )
+ merge->merged = true;
+ }
+ if (merge->merged)
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_in,
+ &rhc->balance_in,
+ &merge->amount_with_fee));
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_out,
+ &rhc->balance_out,
+ &merge->purse_fee));
+ merge->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_PURSE_MERGE;
+ tail->details.merge = merge;
+ }
+}
+
+
+/**
+ * Add paid for history requests to result set for
+ * #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_open_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+ struct PostgresClosure *pg = rhc->pg;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_OpenRequest *orq;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ orq = GNUNET_new (struct TALER_EXCHANGEDB_OpenRequest);
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("open_fee",
+ &orq->open_fee),
+ GNUNET_PQ_result_spec_timestamp ("request_timestamp",
+ &orq->request_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &orq->reserve_expiration),
+ GNUNET_PQ_result_spec_uint32 ("requested_purse_limit",
+ &orq->purse_limit),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &orq->reserve_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (orq);
+ rhc->failed = true;
+ return;
+ }
+ }
+ GNUNET_assert (0 <=
+ TALER_amount_add (&rhc->balance_out,
+ &rhc->balance_out,
+ &orq->open_fee));
+ orq->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_OPEN_REQUEST;
+ tail->details.open_request = orq;
+ }
+}
+
+
+/**
+ * Add paid for history requests to result set for
+ * #TEH_PG_get_reserve_history.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+add_close_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveHistoryContext *rhc = cls;
+
+ while (0 < num_results)
+ {
+ struct TALER_EXCHANGEDB_CloseRequest *crq;
+ struct TALER_EXCHANGEDB_ReserveHistory *tail;
+
+ crq = GNUNET_new (struct TALER_EXCHANGEDB_CloseRequest);
+ {
+ char *payto_uri;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("close_timestamp",
+ &crq->request_timestamp),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &crq->reserve_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ --num_results))
+ {
+ GNUNET_break (0);
+ GNUNET_free (crq);
+ rhc->failed = true;
+ return;
+ }
+ TALER_payto_hash (payto_uri,
+ &crq->target_account_h_payto);
+ GNUNET_free (payto_uri);
+ }
+ crq->reserve_pub = *rhc->reserve_pub;
+ tail = append_rh (rhc);
+ tail->type = TALER_EXCHANGEDB_RO_CLOSE_REQUEST;
+ tail->details.close_request = crq;
+ }
+}
+
+
+/**
+ * Add reserve history entries found.
+ *
+ * @param cls a `struct ReserveHistoryContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+handle_history_entry (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ static const struct
+ {
+ /**
+ * Table with reserve history entry we are responsible for.
+ */
+ const char *table;
+ /**
+ * Name of the prepared statement to run.
+ */
+ const char *statement;
+ /**
+ * Function to use to process the results.
+ */
+ GNUNET_PQ_PostgresResultHandler cb;
+ } work[] = {
+ /** #TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE */
+ { "reserves_in",
+ "reserves_in_get_transactions",
+ add_bank_to_exchange },
+ /** #TALER_EXCHANGEDB_RO_WITHDRAW_COIN */
+ { "reserves_out",
+ "get_reserves_out",
+ &add_withdraw_coin },
+ /** #TALER_EXCHANGEDB_RO_RECOUP_COIN */
+ { "recoup",
+ "recoup_by_reserve",
+ &add_recoup },
+ /** #TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK */
+ { "reserves_close",
+ "close_by_reserve",
+ &add_exchange_to_bank },
+ /** #TALER_EXCHANGEDB_RO_PURSE_MERGE */
+ { "purse_decision",
+ "merge_by_reserve",
+ &add_p2p_merge },
+ /** #TALER_EXCHANGEDB_RO_OPEN_REQUEST */
+ { "reserves_open_requests",
+ "open_request_by_reserve",
+ &add_open_requests },
+ /** #TALER_EXCHANGEDB_RO_CLOSE_REQUEST */
+ { "close_requests",
+ "close_request_by_reserve",
+ &add_close_requests },
+ /* List terminator */
+ { NULL, NULL, NULL }
+ };
+ struct ReserveHistoryContext *rhc = cls;
+ char *table_name;
+ uint64_t serial_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("table_name",
+ &table_name),
+ GNUNET_PQ_result_spec_uint64 ("serial_id",
+ &serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (rhc->reserve_pub),
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ while (0 < num_results--)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ bool found = false;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ num_results))
+ {
+ GNUNET_break (0);
+ rhc->failed = true;
+ return;
+ }
+
+ for (unsigned int i = 0;
+ NULL != work[i].cb;
+ i++)
+ {
+ if (0 != strcmp (table_name,
+ work[i].table))
+ continue;
+ found = true;
+ qs = GNUNET_PQ_eval_prepared_multi_select (rhc->pg->conn,
+ work[i].statement,
+ params,
+ work[i].cb,
+ rhc);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reserve %s had %d transactions at %llu in table %s\n",
+ TALER_B2S (rhc->reserve_pub),
+ (int) qs,
+ (unsigned long long) serial_id,
+ table_name);
+ if (0 >= qs)
+ rhc->failed = true;
+ break;
+ }
+ if (! found)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Coin history includes unsupported table `%s`\n",
+ table_name);
+ rhc->failed = true;
+ }
+ GNUNET_PQ_cleanup_result (rs);
+ if (rhc->failed)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_history (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
+ struct TALER_Amount *balance,
+ struct TALER_EXCHANGEDB_ReserveHistory **rhp)
+{
+ struct PostgresClosure *pg = cls;
+ struct ReserveHistoryContext rhc = {
+ .pg = pg,
+ .reserve_pub = reserve_pub
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_QueryParam lparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_uint64 (&start_off),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &rhc.balance_in));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (pg->currency,
+ &rhc.balance_out));
+
+ *rhp = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting transactions for reserve %s\n",
+ TALER_B2S (reserve_pub));
+ PREPARE (pg,
+ "get_reserve_history_etag",
+ "SELECT"
+ " hist.reserve_history_serial_id"
+ ",r.current_balance"
+ " FROM reserve_history hist"
+ " JOIN reserves r USING (reserve_pub)"
+ " WHERE hist.reserve_pub=$1"
+ " ORDER BY reserve_history_serial_id DESC"
+ " LIMIT 1;");
+ PREPARE (pg,
+ "get_reserve_history",
+ "SELECT"
+ " table_name"
+ ",serial_id"
+ " FROM reserve_history"
+ " WHERE reserve_pub=$1"
+ " AND reserve_history_serial_id > $2"
+ " ORDER BY reserve_history_serial_id DESC;");
+
+ PREPARE (pg,
+ "reserves_in_get_transactions",
+ "SELECT"
+ " ri.wire_reference"
+ ",ri.credit"
+ ",ri.execution_date"
+ ",wt.payto_uri AS sender_account_details"
+ " FROM reserves_in ri"
+ " JOIN wire_targets wt"
+ " ON (wire_source_h_payto = wire_target_h_payto)"
+ " WHERE ri.reserve_pub=$1"
+ " AND ri.reserve_in_serial_id=$2;");
+ PREPARE (pg,
+ "get_reserves_out",
+ "SELECT"
+ " ro.h_blind_ev"
+ ",denom.denom_pub_hash"
+ ",ro.denom_sig"
+ ",ro.reserve_sig"
+ ",ro.execution_date"
+ ",ro.amount_with_fee"
+ ",denom.fee_withdraw"
+ " FROM reserves_out ro"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " JOIN reserves res"
+ " USING (reserve_uuid)"
+ " WHERE ro.reserve_out_serial_id=$2"
+ " AND res.reserve_pub=$1;");
+ PREPARE (pg,
+ "recoup_by_reserve",
+ "SELECT"
+ " rec.coin_pub"
+ ",rec.coin_sig"
+ ",rec.coin_blind"
+ ",rec.amount"
+ ",rec.recoup_timestamp"
+ ",denom.denom_pub_hash"
+ ",kc.denom_sig"
+ " FROM recoup rec"
+ " JOIN reserves_out ro"
+ " USING (reserve_out_serial_id)"
+ " JOIN reserves res"
+ " USING (reserve_uuid)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " ON (denom.denominations_serial = kc.denominations_serial)"
+ " WHERE rec.recoup_uuid=$2"
+ " AND res.reserve_pub=$1;");
+ PREPARE (pg,
+ "close_by_reserve",
+ "SELECT"
+ " rc.amount"
+ ",rc.closing_fee"
+ ",rc.execution_date"
+ ",wt.payto_uri AS receiver_account"
+ ",rc.wtid"
+ " FROM reserves_close rc"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE reserve_pub=$1"
+ " AND close_uuid=$2;");
+ PREPARE (pg,
+ "merge_by_reserve",
+ "SELECT"
+ " pr.amount_with_fee"
+ ",pr.balance"
+ ",pr.purse_fee"
+ ",pr.h_contract_terms"
+ ",pr.merge_pub"
+ ",am.reserve_sig"
+ ",pm.purse_pub"
+ ",pm.merge_timestamp"
+ ",pr.purse_expiration"
+ ",pr.age_limit"
+ ",pr.flags"
+ " FROM purse_decision pdes"
+ " JOIN purse_requests pr"
+ " ON (pr.purse_pub = pdes.purse_pub)"
+ " JOIN purse_merges pm"
+ " ON (pm.purse_pub = pdes.purse_pub)"
+ " JOIN account_merges am"
+ " ON (am.purse_pub = pm.purse_pub AND"
+ " am.reserve_pub = pm.reserve_pub)"
+ " WHERE pdes.purse_decision_serial_id=$2"
+ " AND pm.reserve_pub=$1"
+ " AND COALESCE(pm.partner_serial_id,0)=0" /* must be local! */
+ " AND NOT pdes.refunded;");
+ PREPARE (pg,
+ "open_request_by_reserve",
+ "SELECT"
+ " reserve_payment"
+ ",request_timestamp"
+ ",expiration_date"
+ ",requested_purse_limit"
+ ",reserve_sig"
+ " FROM reserves_open_requests"
+ " WHERE reserve_pub=$1"
+ " AND open_request_uuid=$2;");
+ PREPARE (pg,
+ "close_request_by_reserve",
+ "SELECT"
+ " close_timestamp"
+ ",payto_uri"
+ ",reserve_sig"
+ " FROM close_requests"
+ " WHERE reserve_pub=$1"
+ " AND close_request_serial_id=$2;");
+
+ for (unsigned int i = 0; i<RETRIES; i++)
+ {
+ enum GNUNET_DB_QueryStatus qs;
+ uint64_t end;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("reserve_history_serial_id",
+ &end),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
+ balance),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ TEH_PG_start_read_committed (pg,
+ "get-reserve-transactions"))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ /* First only check the last item, to see if
+ we even need to iterate */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_reserve_history_etag",
+ params,
+ rs);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ *etag_out = end;
+ if (end == etag_in)
+ return qs;
+ }
+ /* We indeed need to iterate over the history */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Current ETag for reserve %s is %llu\n",
+ TALER_B2S (reserve_pub),
+ (unsigned long long) end);
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "get_reserve_history",
+ lparams,
+ &handle_history_entry,
+ &rhc);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_PG_rollback (pg);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_PG_rollback (pg);
+ continue;
+ default:
+ break;
+ }
+ if (rhc.failed)
+ {
+ TEH_PG_rollback (pg);
+ TEH_COMMON_free_reserve_history (pg,
+ rhc.rh);
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ }
+ qs = TEH_PG_commit (pg);
+ switch (qs)
+ {
+ case GNUNET_DB_STATUS_HARD_ERROR:
+ TEH_COMMON_free_reserve_history (pg,
+ rhc.rh);
+ return qs;
+ case GNUNET_DB_STATUS_SOFT_ERROR:
+ TEH_COMMON_free_reserve_history (pg,
+ rhc.rh);
+ rhc.rh = NULL;
+ continue;
+ case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
+ case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
+ *rhp = rhc.rh;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+}
diff --git a/src/exchangedb/pg_get_reserve_history.h b/src/exchangedb/pg_get_reserve_history.h
new file mode 100644
index 000000000..15765f127
--- /dev/null
+++ b/src/exchangedb/pg_get_reserve_history.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_reserve_history.h
+ * @brief implementation of the get_reserve_history function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_RESERVE_HISTORY_H
+#define PG_GET_RESERVE_HISTORY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Compile a list of (historic) transactions performed with the given reserve
+ * (withdraw, incoming wire, open, close operations). Should return 0 if the @a
+ * reserve_pub is unknown, otherwise determine @a etag_out and if it is past @a
+ * etag_in return the history after @a start_off. @a etag_out should be set
+ * to the last row ID of the given @a reserve_pub in the reserve history table.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param start_off maximum starting offset in history to exclude from returning
+ * @param etag_in up to this offset the client already has a response, do not
+ * return anything unless @a etag_out will be larger
+ * @param[out] etag_out set to the latest history offset known for this @a coin_pub
+ * @param[out] balance set to the reserve balance
+ * @param[out] rhp set to known transaction history (NULL if reserve is unknown)
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_reserve_history (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
+ struct TALER_Amount *balance,
+ struct TALER_EXCHANGEDB_ReserveHistory **rhp);
+
+
+#endif
diff --git a/src/exchangedb/pg_get_signature_for_known_coin.c b/src/exchangedb/pg_get_signature_for_known_coin.c
new file mode 100644
index 000000000..06074312f
--- /dev/null
+++ b/src/exchangedb/pg_get_signature_for_known_coin.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_signature_for_known_coin.c
+ * @brief Implementation of the get_signature_for_known_coin function for Postgres
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_signature_for_known_coin.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_signature_for_known_coin (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_DenominationPublicKey *denom_pub,
+ struct TALER_DenominationSignature *denom_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ denom_pub),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ denom_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting denomination and signature for (potentially) known coin %s\n",
+ TALER_B2S (coin_pub));
+ PREPARE (pg,
+ "get_signature_for_known_coin",
+ "SELECT"
+ " denominations.denom_pub"
+ ",denom_sig"
+ " FROM known_coins"
+ " JOIN denominations USING (denominations_serial)"
+ " WHERE coin_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_signature_for_known_coin",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_signature_for_known_coin.h b/src/exchangedb/pg_get_signature_for_known_coin.h
new file mode 100644
index 000000000..ec389176b
--- /dev/null
+++ b/src/exchangedb/pg_get_signature_for_known_coin.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_signature_for_known_coin.h
+ * @brief implementation of the get_signature_for_known_coin function for Postgres
+ * @author Özgür Kesim
+ */
+#ifndef PG_GET_SIGNATURE_FOR_KNOWN_COIN_H
+#define PG_GET_SIGNATURE_FOR_KNOWN_COIN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Retrieve the denomination and the corresponding signature for a known coin.
+ *
+ * @param cls the plugin closure
+ * @param coin_pub the public key of the coin to search for
+ * @param[out] denom_pub the denomination of the public key, if coin was present
+ * @param[out] denom_sig the signature with the denomination key of the coin, if coin was present
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_signature_for_known_coin (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_DenominationPublicKey *denom_pub,
+ struct TALER_DenominationSignature *denom_sig);
+
+#endif
diff --git a/src/exchangedb/pg_get_unfinished_close_requests.c b/src/exchangedb/pg_get_unfinished_close_requests.c
new file mode 100644
index 000000000..990e8e00e
--- /dev/null
+++ b/src/exchangedb/pg_get_unfinished_close_requests.c
@@ -0,0 +1,166 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_unfinished_close_requests.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_unfinished_close_requests.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #reserve_close_cb().
+ */
+struct CloseReserveContext
+{
+ /**
+ * Function to call for each to be closed reserve.
+ */
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec;
+
+ /**
+ * Closure to give to @e rec.
+ */
+ void *rec_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CloseReserveContext *erc = cls;
+ struct PostgresClosure *pg = erc->pg;
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = GNUNET_OK;
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp exp_date;
+ char *account_details;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount remaining_balance;
+ uint64_t close_request_row;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &exp_date),
+ GNUNET_PQ_result_spec_string ("account_details",
+ &account_details),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("close",
+ &remaining_balance),
+ GNUNET_PQ_result_spec_uint64 ("close_request_serial_id",
+ &close_request_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ret = GNUNET_SYSERR;
+ break;
+ }
+ ret = erc->rec (erc->rec_cls,
+ &reserve_pub,
+ &remaining_balance,
+ account_details,
+ exp_date,
+ close_request_row);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+ erc->status = ret;
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_unfinished_close_requests (
+ void *cls,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct CloseReserveContext ectx = {
+ .rec = rec,
+ .rec_cls = rec_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "get_unfinished_close_requests",
+ "UPDATE close_requests AS rc"
+ " SET done=TRUE"
+ " WHERE done=FALSE"
+ " RETURNING"
+ " reserve_pub"
+ " ,close_request_serial_id"
+ " ,close_timestamp AS expiration_date"
+ " ,close"
+ " ,(SELECT payto_uri"
+ " FROM reserves_in ri"
+ " JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE ri.reserve_pub=rc.reserve_pub)"
+ " AS account_details;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_unfinished_close_requests",
+ params,
+ &reserve_cb,
+ &ectx);
+ switch (ectx.status)
+ {
+ case GNUNET_SYSERR:
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ case GNUNET_NO:
+ return GNUNET_DB_STATUS_SOFT_ERROR;
+ case GNUNET_OK:
+ break;
+ }
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_unfinished_close_requests.h b/src/exchangedb/pg_get_unfinished_close_requests.h
new file mode 100644
index 000000000..4c5aa0d1d
--- /dev/null
+++ b/src/exchangedb/pg_get_unfinished_close_requests.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_get_unfinished_close_requests.h
+ * @brief implementation of the get_unfinished_close_requests function
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_UNFINISHED_CLOSE_REQUESTS_H
+#define PG_GET_UNFINISHED_CLOSE_REQUESTS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Obtain information about force-closed reserves
+ * where the close was not yet done (and their remaining
+ * balances). Updates the returned reserve's close
+ * status to "done".
+ *
+ * @param cls closure of the plugin
+ * @param rec function to call on expired reserves
+ * @param rec_cls closure for @a rec
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_unfinished_close_requests (
+ void *cls,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_wire_accounts.c b/src/exchangedb/pg_get_wire_accounts.c
new file mode 100644
index 000000000..9770be719
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_accounts.c
@@ -0,0 +1,169 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_accounts.c
+ * @brief Implementation of the get_wire_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_wire_accounts.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_wire_accounts_cb().
+ */
+struct GetWireAccountsContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireAccountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_wire_accounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetWireAccountsContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ char *payto_uri;
+ char *conversion_url = NULL;
+ json_t *debit_restrictions = NULL;
+ json_t *credit_restrictions = NULL;
+ struct TALER_MasterSignatureP master_sig;
+ char *bank_label = NULL;
+ int64_t priority;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("conversion_url",
+ &conversion_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("bank_label",
+ &bank_label),
+ NULL),
+ GNUNET_PQ_result_spec_int64 ("priority",
+ &priority),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("debit_restrictions",
+ &debit_restrictions),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("credit_restrictions",
+ &credit_restrictions),
+ NULL),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (NULL == debit_restrictions)
+ {
+ debit_restrictions = json_array ();
+ GNUNET_assert (NULL != debit_restrictions);
+ }
+ if (NULL == credit_restrictions)
+ {
+ credit_restrictions = json_array ();
+ GNUNET_assert (NULL != credit_restrictions);
+ }
+ ctx->cb (ctx->cb_cls,
+ payto_uri,
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
+ &master_sig,
+ bank_label,
+ priority);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_accounts (void *cls,
+ TALER_EXCHANGEDB_WireAccountCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GetWireAccountsContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "get_wire_accounts",
+ "SELECT"
+ " payto_uri"
+ ",conversion_url"
+ ",debit_restrictions"
+ ",credit_restrictions"
+ ",master_sig"
+ ",bank_label"
+ ",priority"
+ " FROM wire_accounts"
+ " WHERE is_active");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_wire_accounts",
+ params,
+ &get_wire_accounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_wire_accounts.h b/src/exchangedb/pg_get_wire_accounts.h
new file mode 100644
index 000000000..f4dc97ce0
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_accounts.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_accounts.h
+ * @brief implementation of the get_wire_accounts function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_WIRE_ACCOUNTS_H
+#define PG_GET_WIRE_ACCOUNTS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Obtain information about the enabled wire accounts of the exchange.
+ *
+ * @param cls closure
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_accounts (void *cls,
+ TALER_EXCHANGEDB_WireAccountCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_wire_fee.c b/src/exchangedb/pg_get_wire_fee.c
new file mode 100644
index 000000000..40f517f28
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_fee.c
@@ -0,0 +1,73 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_fee.c
+ * @brief Implementation of the get_wire_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_wire_fee.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_fee (void *cls,
+ const char *type,
+ struct GNUNET_TIME_Timestamp date,
+ struct GNUNET_TIME_Timestamp *start_date,
+ struct GNUNET_TIME_Timestamp *end_date,
+ struct TALER_WireFeeSet *fees,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (type),
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ end_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &fees->wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &fees->closing),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_wire_fee",
+ "SELECT "
+ " start_date"
+ ",end_date"
+ ",wire_fee"
+ ",closing_fee"
+ ",master_sig"
+ " FROM wire_fee"
+ " WHERE wire_method=$1"
+ " AND start_date <= $2"
+ " AND end_date > $2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_wire_fee",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_wire_fee.h b/src/exchangedb/pg_get_wire_fee.h
new file mode 100644
index 000000000..409a5c48b
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_fee.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_fee.h
+ * @brief implementation of the get_wire_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_WIRE_FEE_H
+#define PG_GET_WIRE_FEE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain wire fee from database.
+ *
+ * @param cls closure
+ * @param type type of wire transfer the fee applies for
+ * @param date for which date do we want the fee?
+ * @param[out] start_date when does the fee go into effect
+ * @param[out] end_date when does the fee end being valid
+ * @param[out] fees how high are the wire fees
+ * @param[out] master_sig signature over the above by the exchange master key
+ * @return status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_fee (void *cls,
+ const char *type,
+ struct GNUNET_TIME_Timestamp date,
+ struct GNUNET_TIME_Timestamp *start_date,
+ struct GNUNET_TIME_Timestamp *end_date,
+ struct TALER_WireFeeSet *fees,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_get_wire_fees.c b/src/exchangedb/pg_get_wire_fees.c
new file mode 100644
index 000000000..193ccff6a
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_fees.c
@@ -0,0 +1,147 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_fees.c
+ * @brief Implementation of the get_wire_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_wire_fees.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #get_wire_fees_cb().
+ */
+struct GetWireFeesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireFeeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct GetWireFeesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_wire_fees_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetWireFeesContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_MasterSignatureP master_sig;
+ struct TALER_WireFeeSet fees;
+ struct GNUNET_TIME_Timestamp start_date;
+ struct GNUNET_TIME_Timestamp end_date;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &fees.wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &fees.closing),
+ GNUNET_PQ_result_spec_timestamp ("start_date",
+ &start_date),
+ GNUNET_PQ_result_spec_timestamp ("end_date",
+ &end_date),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &fees,
+ start_date,
+ end_date,
+ &master_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_fees (void *cls,
+ const char *wire_method,
+ TALER_EXCHANGEDB_WireFeeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (wire_method),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetWireFeesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "get_wire_fees",
+ "SELECT"
+ " wire_fee"
+ ",closing_fee"
+ ",start_date"
+ ",end_date"
+ ",master_sig"
+ " FROM wire_fee"
+ " WHERE wire_method=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "get_wire_fees",
+ params,
+ &get_wire_fees_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_wire_fees.h b/src/exchangedb/pg_get_wire_fees.h
new file mode 100644
index 000000000..798a514db
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_fees.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_fees.h
+ * @brief implementation of the get_wire_fees function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_WIRE_FEES_H
+#define PG_GET_WIRE_FEES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain information about the fee structure of the exchange for
+ * a given @a wire_method
+ *
+ * @param cls closure
+ * @param wire_method which wire method to obtain fees for
+ * @param cb function to call on each account
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_fees (void *cls,
+ const char *wire_method,
+ TALER_EXCHANGEDB_WireFeeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_get_wire_hash_for_contract.c b/src/exchangedb/pg_get_wire_hash_for_contract.c
new file mode 100644
index 000000000..afd659b18
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_hash_for_contract.c
@@ -0,0 +1,81 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_hash_for_contract.c
+ * @brief Implementation of the get_wire_hash_for_contract function for Postgres
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_exchangedb_plugin.h"
+#include "taler_pq_lib.h"
+#include "pg_get_wire_hash_for_contract.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_hash_for_contract (
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct TALER_MerchantWireHashP *h_wire)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_end
+ };
+ char *payto_uri;
+ struct TALER_WireSaltP wire_salt;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* check if the necessary records exist and get them */
+ PREPARE (pg,
+ "get_wire_hash_for_contract",
+ "SELECT"
+ " bdep.wire_salt"
+ ",wt.payto_uri"
+ " FROM coin_deposits"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " WHERE bdep.merchant_pub=$1"
+ " AND bdep.h_contract_terms=$2");
+ /* NOTE: above query might be more efficient if we computed the shard
+ from the merchant_pub and included that in the query */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_wire_hash_for_contract",
+ params,
+ rs);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ TALER_merchant_wire_signature_hash (payto_uri,
+ &wire_salt,
+ h_wire);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+ return qs;
+}
diff --git a/src/exchangedb/pg_get_wire_hash_for_contract.h b/src/exchangedb/pg_get_wire_hash_for_contract.h
new file mode 100644
index 000000000..f95cd29c1
--- /dev/null
+++ b/src/exchangedb/pg_get_wire_hash_for_contract.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_wire_hash_for_contract.h
+ * @brief implementation of the get_wire_hash_for_contract function for Postgres
+ * @author Özgür Kesim
+ */
+#ifndef PG_GET_WIRE_HASH_FOR_CONTRACT_H
+#define PG_GET_WIRE_HASH_FOR_CONTRACT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Try to get the salted hash of a merchant's bank account to a deposit
+ * contract. This is necessary in the event of a conflict with a given
+ * (merchant_pub, h_contract_terms) during deposit.
+ *
+ * @param cls closure
+ * @param merchant_pub merchant public key
+ * @param h_contract_terms hash of the proposal data
+ * @param[out] h_wire salted hash of a merchant's bank account
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_wire_hash_for_contract (
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct TALER_MerchantWireHashP *h_wire);
+
+#endif
diff --git a/src/exchangedb/pg_get_withdraw_info.c b/src/exchangedb/pg_get_withdraw_info.c
new file mode 100644
index 000000000..e06fa3764
--- /dev/null
+++ b/src/exchangedb/pg_get_withdraw_info.c
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_withdraw_info.c
+ * @brief Implementation of the get_withdraw_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_withdraw_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_withdraw_info (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *bch,
+ struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (bch),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &collectable->denom_pub_hash),
+ TALER_PQ_result_spec_blinded_denom_sig ("denom_sig",
+ &collectable->sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &collectable->reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &collectable->reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &collectable->h_coin_envelope),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &collectable->amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &collectable->withdraw_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_withdraw_info",
+ "SELECT"
+ " denom.denom_pub_hash"
+ ",denom_sig"
+ ",reserve_sig"
+ ",reserves.reserve_pub"
+ ",execution_date"
+ ",h_blind_ev"
+ ",amount_with_fee"
+ ",denom.fee_withdraw"
+ " FROM reserves_out"
+ " JOIN reserves"
+ " USING (reserve_uuid)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE h_blind_ev=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_withdraw_info",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_get_withdraw_info.h b/src/exchangedb/pg_get_withdraw_info.h
new file mode 100644
index 000000000..7c3e06a02
--- /dev/null
+++ b/src/exchangedb/pg_get_withdraw_info.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_get_withdraw_info.h
+ * @brief implementation of the get_withdraw_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_GET_WITHDRAW_INFO_H
+#define PG_GET_WITHDRAW_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Locate the response for a /reserve/withdraw request under the
+ * key of the hash of the blinded message.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param bch hash that uniquely identifies the withdraw operation
+ * @param collectable corresponding collectable coin (blind signature)
+ * if a coin is found
+ * @return statement execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_get_withdraw_info (
+ void *cls,
+ const struct TALER_BlindedCoinHashP *bch,
+ struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable);
+
+#endif
diff --git a/src/exchangedb/pg_have_deposit2.c b/src/exchangedb/pg_have_deposit2.c
new file mode 100644
index 000000000..e00ad7490
--- /dev/null
+++ b/src/exchangedb/pg_have_deposit2.c
@@ -0,0 +1,117 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_have_deposit2.c
+ * @brief Implementation of the have_deposit2 function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_have_deposit2.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_have_deposit2 (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct TALER_Amount *deposit_fee,
+ struct GNUNET_TIME_Timestamp *exchange_timestamp)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (merchant),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_EXCHANGEDB_Deposit deposit2;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit2.amount_with_fee),
+ GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
+ &deposit2.timestamp),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ exchange_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &deposit2.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &deposit2.wire_deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &deposit2.wire_salt),
+ GNUNET_PQ_result_spec_string ("receiver_wire_account",
+ &deposit2.receiver_wire_account),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_MerchantWireHashP h_wire2;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Getting deposits for coin %s\n",
+ TALER_B2S (coin_pub));
+ PREPARE (pg,
+ "get_deposit",
+ "SELECT"
+ " cdep.amount_with_fee"
+ ",denominations.fee_deposit"
+ ",bdep.wallet_timestamp"
+ ",bdep.exchange_timestamp"
+ ",bdep.refund_deadline"
+ ",bdep.wire_deadline"
+ ",bdep.h_contract_terms"
+ ",bdep.wire_salt"
+ ",wt.payto_uri AS receiver_wire_account"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep USING (batch_deposit_serial_id)"
+ " JOIN known_coins kc ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations USING (denominations_serial)"
+ " JOIN wire_targets wt USING (wire_target_h_payto)"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2;");
+ /* Note: query might be made more efficient if we computed the 'shard'
+ from merchant_pub and included that as a constraint on bdep! */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_deposit",
+ params,
+ rs);
+ if (0 >= qs)
+ return qs;
+ TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account,
+ &deposit2.wire_salt,
+ &h_wire2);
+ GNUNET_free (deposit2.receiver_wire_account);
+ /* Now we check that the other information in @a deposit
+ also matches, and if not report inconsistencies. */
+ if ( (GNUNET_TIME_timestamp_cmp (refund_deadline,
+ !=,
+ deposit2.refund_deadline)) ||
+ (0 != GNUNET_memcmp (h_wire,
+ &h_wire2) ) )
+ {
+ /* Inconsistencies detected! Does not match! */
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
diff --git a/src/exchangedb/pg_have_deposit2.h b/src/exchangedb/pg_have_deposit2.h
new file mode 100644
index 000000000..0e8119c20
--- /dev/null
+++ b/src/exchangedb/pg_have_deposit2.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_have_deposit2.h
+ * @brief implementation of the have_deposit2 function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_HAVE_DEPOSIT2_H
+#define PG_HAVE_DEPOSIT2_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Check if we have the specified deposit already in the database.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param h_contract_terms contract to check for
+ * @param h_wire wire hash to check for
+ * @param coin_pub public key of the coin to check for
+ * @param merchant merchant public key to check for
+ * @param refund_deadline expected refund deadline
+ * @param[out] deposit_fee set to the deposit fee the exchange charged
+ * @param[out] exchange_timestamp set to the time when the exchange received the deposit
+ * @return 1 if we know this operation,
+ * 0 if this exact deposit is unknown to us,
+ * otherwise transaction error status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_have_deposit2 (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ struct TALER_Amount *deposit_fee,
+ struct GNUNET_TIME_Timestamp *exchange_timestamp);
+#endif
diff --git a/src/exchangedb/pg_helper.h b/src/exchangedb/pg_helper.h
new file mode 100644
index 000000000..c63c9111d
--- /dev/null
+++ b/src/exchangedb/pg_helper.h
@@ -0,0 +1,149 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_helper.h
+ * @brief shared internal definitions for postgres DB plugin
+ * @author Christian Grothoff
+ */
+#ifndef PG_HELPER_H
+#define PG_HELPER_H
+
+
+/**
+ * Type of the "cls" argument given to each of the functions in
+ * our API.
+ */
+struct PostgresClosure
+{
+
+ /**
+ * Our configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Directory with SQL statements to run to create tables.
+ */
+ char *sql_dir;
+
+ /**
+ * After how long should idle reserves be closed?
+ */
+ struct GNUNET_TIME_Relative idle_reserve_expiration_time;
+
+ /**
+ * After how long should reserves that have seen withdraw operations
+ * be garbage collected?
+ */
+ struct GNUNET_TIME_Relative legal_reserve_expiration_time;
+
+ /**
+ * What delay should we introduce before ready transactions
+ * are actually aggregated?
+ */
+ struct GNUNET_TIME_Relative aggregator_shift;
+
+ /**
+ * Which currency should we assume all amounts to be in?
+ */
+ char *currency;
+
+ /**
+ * Our base URL.
+ */
+ char *exchange_url;
+
+ /**
+ * Postgres connection handle.
+ */
+ struct GNUNET_PQ_Context *conn;
+
+ /**
+ * Name of the current transaction, for debugging.
+ */
+ const char *transaction_name;
+
+ /**
+ * Counts how often we have established a fresh @e conn
+ * to the database. Used to re-prepare statements.
+ */
+ unsigned long long prep_gen;
+
+ /**
+ * Number of purses we allow to be opened concurrently
+ * for one year per annual fee payment.
+ */
+ uint32_t def_purse_limit;
+
+};
+
+
+/**
+ * Prepares SQL statement @a sql under @a name for
+ * connection @a pg once.
+ * Returns with #GNUNET_DB_STATUS_HARD_ERROR on failure.
+ *
+ * @param pg a `struct PostgresClosure`
+ * @param name name to prepare the statement under
+ * @param sql actual SQL text
+ */
+#define PREPARE(pg,name,sql) \
+ do { \
+ static struct { \
+ unsigned long long cnt; \
+ struct PostgresClosure *pg; \
+ } preps[2]; /* 2 ctrs for taler-auditor-sync*/ \
+ unsigned int off = 0; \
+ \
+ while ( (NULL != preps[off].pg) && \
+ (pg != preps[off].pg) && \
+ (off < sizeof(preps) / sizeof(*preps)) ) \
+ off++; \
+ GNUNET_assert (off < \
+ sizeof(preps) / sizeof(*preps)); \
+ if (preps[off].cnt < pg->prep_gen) \
+ { \
+ struct GNUNET_PQ_PreparedStatement ps[] = { \
+ GNUNET_PQ_make_prepare (name, sql), \
+ GNUNET_PQ_PREPARED_STATEMENT_END \
+ }; \
+ \
+ if (GNUNET_OK != \
+ GNUNET_PQ_prepare_statements (pg->conn, \
+ ps)) \
+ { \
+ GNUNET_break (0); \
+ return GNUNET_DB_STATUS_HARD_ERROR; \
+ } \
+ preps[off].pg = pg; \
+ preps[off].cnt = pg->prep_gen; \
+ } \
+ } while (0)
+
+
+/**
+ * Wrapper macro to add the currency from the plugin's state
+ * when fetching amounts from the database.
+ *
+ * @param field name of the database field to fetch amount from
+ * @param[out] amountp pointer to amount to set
+ */
+#define TALER_PQ_RESULT_SPEC_AMOUNT(field, \
+ amountp) TALER_PQ_result_spec_amount ( \
+ field,pg->currency,amountp)
+
+
+#endif
diff --git a/src/exchangedb/pg_inject_auditor_triggers.c b/src/exchangedb/pg_inject_auditor_triggers.c
new file mode 100644
index 000000000..562a1a22c
--- /dev/null
+++ b/src/exchangedb/pg_inject_auditor_triggers.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_inject_auditor_triggers.c
+ * @brief Implementation of the inject_auditor_triggers function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_gc.h"
+#include "pg_helper.h"
+
+
+/**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_inject_auditor_triggers (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_Context *conn;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
+ "exchangedb-postgres",
+ "auditor-triggers-",
+ es,
+ NULL);
+ if (NULL == conn)
+ return GNUNET_SYSERR;
+ GNUNET_PQ_disconnect (conn);
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_inject_auditor_triggers.h b/src/exchangedb/pg_inject_auditor_triggers.h
new file mode 100644
index 000000000..2dfa9468c
--- /dev/null
+++ b/src/exchangedb/pg_inject_auditor_triggers.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_inject_auditor_triggers.h
+ * @brief implementation of the inject_auditor_triggers function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INJECT_AUDITOR_TRIGGERS_H
+#define PG_INJECT_AUDITOR_TRIGGERS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_inject_auditor_triggers (void *cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_aml_decision.c b/src/exchangedb/pg_insert_aml_decision.c
new file mode 100644
index 000000000..39419be59
--- /dev/null
+++ b/src/exchangedb/pg_insert_aml_decision.c
@@ -0,0 +1,97 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_aml_decision.c
+ * @brief Implementation of the insert_aml_decision function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_aml_decision.h"
+#include "pg_helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_aml_decision (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *new_threshold,
+ enum TALER_AmlDecisionState new_status,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const json_t *kyc_requirements,
+ uint64_t requirements_row,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_AmlOfficerSignatureP *decider_sig,
+ bool *invalid_officer,
+ struct GNUNET_TIME_Timestamp *last_date)
+{
+ struct PostgresClosure *pg = cls;
+ uint32_t ns = (uint32_t) new_status;
+ struct TALER_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ char *notify_s = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ char *kyc_s = (NULL != kyc_requirements)
+ ? json_dumps (kyc_requirements, JSON_COMPACT)
+ : NULL;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ TALER_PQ_query_param_amount (pg->conn,
+ new_threshold),
+ GNUNET_PQ_query_param_uint32 (&ns),
+ GNUNET_PQ_query_param_timestamp (&decision_time),
+ GNUNET_PQ_query_param_string (justification),
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_auto_from_type (decider_sig),
+ GNUNET_PQ_query_param_string (notify_s),
+ NULL != kyc_requirements
+ ? GNUNET_PQ_query_param_string (kyc_s)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_uint64 (&requirements_row),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("out_invalid_officer",
+ invalid_officer),
+ GNUNET_PQ_result_spec_timestamp ("out_last_date",
+ last_date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "do_insert_aml_decision",
+ "SELECT"
+ " out_invalid_officer"
+ ",out_last_date"
+ " FROM exchange_do_insert_aml_decision"
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_insert_aml_decision",
+ params,
+ rs);
+ GNUNET_free (notify_s);
+ GNUNET_PQ_event_do_poll (pg->conn);
+ if (NULL != kyc_s)
+ free (kyc_s);
+ return qs;
+}
diff --git a/src/exchangedb/pg_insert_aml_decision.h b/src/exchangedb/pg_insert_aml_decision.h
new file mode 100644
index 000000000..073a2f50a
--- /dev/null
+++ b/src/exchangedb/pg_insert_aml_decision.h
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_aml_decision.h
+ * @brief implementation of the insert_aml_decision function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_AML_DECISION_H
+#define PG_INSERT_AML_DECISION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert an AML decision. Inserts into AML history and insert or updates AML
+ * status.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param new_threshold new monthly threshold that would trigger an AML check
+ * @param new_status AML decision status
+ * @param decision_time when was the decision made
+ * @param justification human-readable text justifying the decision
+ * @param kyc_requirements JSON array with KYC requirements
+ * @param requirements_row row in the KYC table for this process, 0 for none
+ * @param decider_pub public key of the staff member
+ * @param decider_sig signature of the staff member
+ * @param[out] invalid_officer set to TRUE if @a decider_pub is not allowed to make decisions right now
+ * @param[out] last_date set to the previous decision time;
+ * the INSERT is not performed if @a last_date is not before @a decision_time
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_aml_decision (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *new_threshold,
+ enum TALER_AmlDecisionState new_status,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const json_t *kyc_requirements,
+ uint64_t requirements_row,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_AmlOfficerSignatureP *decider_sig,
+ bool *invalid_officer,
+ struct GNUNET_TIME_Timestamp *last_date);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_aml_officer.c b/src/exchangedb/pg_insert_aml_officer.c
new file mode 100644
index 000000000..c1f635a64
--- /dev/null
+++ b/src/exchangedb/pg_insert_aml_officer.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_aml_officer.c
+ * @brief Implementation of the insert_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_aml_officer.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *decider_name,
+ bool is_active,
+ bool read_only,
+ struct GNUNET_TIME_Timestamp last_change,
+ struct GNUNET_TIME_Timestamp *previous_change)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_string (decider_name),
+ GNUNET_PQ_query_param_bool (is_active),
+ GNUNET_PQ_query_param_bool (read_only),
+ GNUNET_PQ_query_param_timestamp (&last_change),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("out_last_change",
+ previous_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "do_insert_aml_staff",
+ "SELECT"
+ " out_last_change"
+ " FROM exchange_do_insert_aml_officer"
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "do_insert_aml_staff",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_insert_aml_officer.h b/src/exchangedb/pg_insert_aml_officer.h
new file mode 100644
index 000000000..3c6f5d82e
--- /dev/null
+++ b/src/exchangedb/pg_insert_aml_officer.h
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_aml_officer.h
+ * @brief implementation of the insert_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_AML_OFFICER_H
+#define PG_INSERT_AML_OFFICER_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert AML staff record. If the time given in
+ * @a last_change is before the previous change in the
+ * database, only @e previous_change is returned and
+ * no actual change is committed to the database.
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @param master_sig offline signature affirming the AML officer
+ * @param decider_name full name of the staff member
+ * @param is_active true to enable, false to set as inactive
+ * @param read_only true to set read-only access
+ * @param last_change when was the change made effective
+ * @param[out] previous_change set to the time of the previous change
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *decider_name,
+ bool is_active,
+ bool read_only,
+ struct GNUNET_TIME_Timestamp last_change,
+ struct GNUNET_TIME_Timestamp *previous_change);
+
+#endif
diff --git a/src/exchangedb/pg_insert_auditor.c b/src/exchangedb/pg_insert_auditor.c
new file mode 100644
index 000000000..2f1de7ba7
--- /dev/null
+++ b/src/exchangedb/pg_insert_auditor.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_auditor.c
+ * @brief Implementation of the insert_auditor function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_auditor.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_auditor (void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp start_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_string (auditor_name),
+ GNUNET_PQ_query_param_string (auditor_url),
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* used in #postgres_insert_auditor() */
+ PREPARE (pg,
+ "insert_auditor",
+ "INSERT INTO auditors "
+ "(auditor_pub"
+ ",auditor_name"
+ ",auditor_url"
+ ",is_active"
+ ",last_change"
+ ") VALUES "
+ "($1, $2, $3, true, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_auditor",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_auditor.h b/src/exchangedb/pg_insert_auditor.h
new file mode 100644
index 000000000..8de388f23
--- /dev/null
+++ b/src/exchangedb/pg_insert_auditor.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_auditor.h
+ * @brief implementation of the insert_auditor function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_AUDITOR_H
+#define PG_INSERT_AUDITOR_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Insert information about an auditor that will audit this exchange.
+ *
+ * @param cls closure
+ * @param auditor_pub key of the auditor
+ * @param auditor_url base URL of the auditor's REST service
+ * @param auditor_name name of the auditor (for humans)
+ * @param start_date date when the auditor was added by the offline system
+ * (only to be used for replay detection)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_auditor (void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp start_date);
+#endif
diff --git a/src/exchangedb/pg_insert_auditor_denom_sig.c b/src/exchangedb/pg_insert_auditor_denom_sig.c
new file mode 100644
index 000000000..3643a87f2
--- /dev/null
+++ b/src/exchangedb/pg_insert_auditor_denom_sig.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_auditor_denom_sig.c
+ * @brief Implementation of the insert_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_auditor_denom_sig.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_auditor_denom_sig (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const struct TALER_AuditorSignatureP *auditor_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_auto_from_type (auditor_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_auditor_denom_sig",
+ "WITH ax AS"
+ " (SELECT auditor_uuid"
+ " FROM auditors"
+ " WHERE auditor_pub=$1)"
+ "INSERT INTO auditor_denom_sigs "
+ "(auditor_uuid"
+ ",denominations_serial"
+ ",auditor_sig"
+ ") SELECT ax.auditor_uuid, denominations_serial, $3 "
+ " FROM denominations"
+ " CROSS JOIN ax"
+ " WHERE denom_pub_hash=$2;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_auditor_denom_sig",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_auditor_denom_sig.h b/src/exchangedb/pg_insert_auditor_denom_sig.h
new file mode 100644
index 000000000..baa67cfe8
--- /dev/null
+++ b/src/exchangedb/pg_insert_auditor_denom_sig.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_auditor_denom_sig.h
+ * @brief implementation of the insert_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_AUDITOR_DENOM_SIG_H
+#define PG_INSERT_AUDITOR_DENOM_SIG_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Insert information about an auditor auditing a denomination key.
+ *
+ * @param cls closure
+ * @param h_denom_pub the audited denomination
+ * @param auditor_pub the auditor's key
+ * @param auditor_sig signature affirming the auditor's audit activity
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_auditor_denom_sig (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const struct TALER_AuditorSignatureP *auditor_sig);
+#endif
diff --git a/src/exchangedb/pg_insert_close_request.c b/src/exchangedb/pg_insert_close_request.c
new file mode 100644
index 000000000..b4bc5f4a7
--- /dev/null
+++ b/src/exchangedb/pg_insert_close_request.c
@@ -0,0 +1,68 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_close_request.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_close_request.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_close_request (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const char *payto_uri,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *closing_fee)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_timestamp (&request_timestamp),
+ GNUNET_PQ_query_param_auto_from_type (reserve_sig),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
+ TALER_PQ_query_param_amount (pg->conn,
+ closing_fee),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_account_close",
+ "INSERT INTO close_requests"
+ "(reserve_pub"
+ ",close_timestamp"
+ ",reserve_sig"
+ ",close"
+ ",close_fee"
+ ",payto_uri"
+ ")"
+ "VALUES "
+ "($1, $2, $3, $4, $5, $6)"
+ " ON CONFLICT DO NOTHING;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_account_close",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_close_request.h b/src/exchangedb/pg_insert_close_request.h
new file mode 100644
index 000000000..c014a10b9
--- /dev/null
+++ b/src/exchangedb/pg_insert_close_request.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_close_request.h
+ * @brief implementation of the insert_close_request function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_CLOSE_REQUEST_H
+#define PG_INSERT_CLOSE_REQUEST_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to initiate closure of an account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the account to close
+ * @param payto_uri where to wire the funds
+ * @param reserve_sig signature affiming that the account is to be closed
+ * @param request_timestamp time of the close request (client-side?)
+ * @param balance final balance in the reserve
+ * @param closing_fee closing fee to charge
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_close_request (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const char *payto_uri,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *closing_fee);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_contract.c b/src/exchangedb/pg_insert_contract.c
new file mode 100644
index 000000000..0274f8d93
--- /dev/null
+++ b/src/exchangedb/pg_insert_contract.c
@@ -0,0 +1,93 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_contract.c
+ * @brief Implementation of the insert_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_contract.h"
+#include "pg_select_contract_by_purse.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_contract (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_EncryptedContract *econtract,
+ bool *in_conflict)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (&econtract->contract_pub),
+ GNUNET_PQ_query_param_fixed_size (econtract->econtract,
+ econtract->econtract_size),
+ GNUNET_PQ_query_param_auto_from_type (&econtract->econtract_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ *in_conflict = false;
+ /* Used in #postgres_insert_contract() */
+ PREPARE (pg,
+ "insert_contract",
+ "INSERT INTO contracts"
+ " (purse_pub"
+ " ,pub_ckey"
+ " ,e_contract"
+ " ,contract_sig"
+ " ,purse_expiration"
+ " ) SELECT "
+ " $1, $2, $3, $4, purse_expiration"
+ " FROM purse_requests"
+ " WHERE purse_pub=$1"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_contract",
+ params);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
+ return qs;
+ {
+ struct TALER_EncryptedContract econtract2;
+
+ qs = TEH_PG_select_contract_by_purse (pg,
+ purse_pub,
+ &econtract2);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (0 == GNUNET_memcmp (&econtract->contract_pub,
+ &econtract2.contract_pub)) &&
+ (econtract2.econtract_size ==
+ econtract->econtract_size) &&
+ (0 == memcmp (econtract2.econtract,
+ econtract->econtract,
+ econtract->econtract_size)) )
+ {
+ GNUNET_free (econtract2.econtract);
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ GNUNET_free (econtract2.econtract);
+ *in_conflict = true;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+}
diff --git a/src/exchangedb/pg_insert_contract.h b/src/exchangedb/pg_insert_contract.h
new file mode 100644
index 000000000..e2e6b5ee9
--- /dev/null
+++ b/src/exchangedb/pg_insert_contract.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_contract.h
+ * @brief implementation of the insert_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_CONTRACT_H
+#define PG_INSERT_CONTRACT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to persist an encrypted contract associated with a reserve.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub the purse the contract is associated with (must exist)
+ * @param econtract the encrypted contract
+ * @param[out] in_conflict set to true if @a econtract
+ * conflicts with an existing contract;
+ * in this case, the return value will be
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_contract (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_EncryptedContract *econtract,
+ bool *in_conflict);
+
+#endif
diff --git a/src/exchangedb/pg_insert_denomination_info.c b/src/exchangedb/pg_insert_denomination_info.c
new file mode 100644
index 000000000..878bc5d81
--- /dev/null
+++ b/src/exchangedb/pg_insert_denomination_info.c
@@ -0,0 +1,101 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_denomination_info.c
+ * @brief Implementation of the insert_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_denomination_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_denomination_info (
+ void *cls,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue)
+{
+ struct PostgresClosure *pg = cls;
+ struct TALER_DenominationHashP denom_hash;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&issue->denom_hash),
+ TALER_PQ_query_param_denom_pub (denom_pub),
+ GNUNET_PQ_query_param_auto_from_type (&issue->signature),
+ GNUNET_PQ_query_param_timestamp (&issue->start),
+ GNUNET_PQ_query_param_timestamp (&issue->expire_withdraw),
+ GNUNET_PQ_query_param_timestamp (&issue->expire_deposit),
+ GNUNET_PQ_query_param_timestamp (&issue->expire_legal),
+ TALER_PQ_query_param_amount (pg->conn,
+ &issue->value),
+ TALER_PQ_query_param_amount (pg->conn,
+ &issue->fees.withdraw),
+ TALER_PQ_query_param_amount (pg->conn,
+ &issue->fees.deposit),
+ TALER_PQ_query_param_amount (pg->conn,
+ &issue->fees.refresh),
+ TALER_PQ_query_param_amount (pg->conn,
+ &issue->fees.refund),
+ GNUNET_PQ_query_param_uint32 (&denom_pub->age_mask.bits),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_assert (denom_pub->age_mask.bits ==
+ issue->age_mask.bits);
+ TALER_denom_pub_hash (denom_pub,
+ &denom_hash);
+ GNUNET_assert (0 ==
+ GNUNET_memcmp (&denom_hash,
+ &issue->denom_hash));
+ GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
+ issue->start.abs_time));
+ GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
+ issue->expire_withdraw.abs_time));
+ GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
+ issue->expire_deposit.abs_time));
+ GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
+ issue->expire_legal.abs_time));
+ /* check fees match denomination currency */
+ GNUNET_assert (GNUNET_YES ==
+ TALER_denom_fee_check_currency (
+ issue->value.currency,
+ &issue->fees));
+ PREPARE (pg,
+ "denomination_insert",
+ "INSERT INTO denominations "
+ "(denom_pub_hash"
+ ",denom_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin" /* value of this denom */
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
+ " $11, $12, $13);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "denomination_insert",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_denomination_info.h b/src/exchangedb/pg_insert_denomination_info.h
new file mode 100644
index 000000000..663f45bd4
--- /dev/null
+++ b/src/exchangedb/pg_insert_denomination_info.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_denomination_info.h
+ * @brief implementation of the insert_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_DENOMINATION_INFO_H
+#define PG_INSERT_DENOMINATION_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Insert a denomination key's public information into the database for
+ * reference by auditors and other consistency checks.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param denom_pub the public key used for signing coins of this denomination
+ * @param issue issuing information with value, fees and other info about the coin
+ * @return status of the query
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_denomination_info (
+ void *cls,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue);
+
+#endif
diff --git a/src/exchangedb/pg_insert_denomination_revocation.c b/src/exchangedb/pg_insert_denomination_revocation.c
new file mode 100644
index 000000000..49445f262
--- /dev/null
+++ b/src/exchangedb/pg_insert_denomination_revocation.c
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_denomination_revocation.c
+ * @brief Implementation of the insert_denomination_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_denomination_revocation.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_denomination_revocation (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* Used in #postgres_insert_denomination_revocation() */
+ PREPARE (pg,
+ "denomination_revocation_insert",
+ "INSERT INTO denomination_revocations "
+ "(denominations_serial"
+ ",master_sig"
+ ") SELECT denominations_serial,$2"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "denomination_revocation_insert",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_denomination_revocation.h b/src/exchangedb/pg_insert_denomination_revocation.h
new file mode 100644
index 000000000..e3da87666
--- /dev/null
+++ b/src/exchangedb/pg_insert_denomination_revocation.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_denomination_revocation.h
+ * @brief implementation of the insert_denomination_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_DENOMINATION_REVOCATION_H
+#define PG_INSERT_DENOMINATION_REVOCATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Store information that a denomination key was revoked
+ * in the database.
+ *
+ * @param cls closure
+ * @param denom_pub_hash hash of the revoked denomination key
+ * @param master_sig signature affirming the revocation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_denomination_revocation (
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_MasterSignatureP *master_sig);
+#endif
diff --git a/src/exchangedb/pg_insert_drain_profit.c b/src/exchangedb/pg_insert_drain_profit.c
new file mode 100644
index 000000000..a0de02e9b
--- /dev/null
+++ b/src/exchangedb/pg_insert_drain_profit.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_drain_profit.c
+ * @brief Implementation of the insert_drain_profit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_drain_profit.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_string (account_section),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_timestamp (&request_timestamp),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "drain_profit_insert",
+ "INSERT INTO profit_drains "
+ "(wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ ") VALUES ($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "drain_profit_insert",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_drain_profit.h b/src/exchangedb/pg_insert_drain_profit.h
new file mode 100644
index 000000000..90183d850
--- /dev/null
+++ b/src/exchangedb/pg_insert_drain_profit.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_drain_profit.h
+ * @brief implementation of the insert_drain_profit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_DRAIN_PROFIT_H
+#define PG_INSERT_DRAIN_PROFIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to persist a request to drain profits.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to use
+ * @param account_section account to drain
+ * @param payto_uri account to wire funds to
+ * @param request_timestamp when was the request made
+ * @param amount amount to wire
+ * @param master_sig signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_drain_profit (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_insert_global_fee.c b/src/exchangedb/pg_insert_global_fee.c
new file mode 100644
index 000000000..e78cd0b83
--- /dev/null
+++ b/src/exchangedb/pg_insert_global_fee.c
@@ -0,0 +1,137 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_global_fee.c
+ * @brief Implementation of the insert_global_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_global_fee.h"
+#include "pg_helper.h"
+#include "pg_get_global_fee.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_global_fee (void *cls,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative purse_timeout,
+ struct GNUNET_TIME_Relative history_expiration,
+ uint32_t purse_account_limit,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ GNUNET_PQ_query_param_timestamp (&end_date),
+ TALER_PQ_query_param_amount (pg->conn,
+ &fees->history),
+ TALER_PQ_query_param_amount (pg->conn,
+ &fees->account),
+ TALER_PQ_query_param_amount (pg->conn,
+ &fees->purse),
+ GNUNET_PQ_query_param_relative_time (&purse_timeout),
+ GNUNET_PQ_query_param_relative_time (&history_expiration),
+ GNUNET_PQ_query_param_uint32 (&purse_account_limit),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_GlobalFeeSet wx;
+ struct TALER_MasterSignatureP sig;
+ struct GNUNET_TIME_Timestamp sd;
+ struct GNUNET_TIME_Timestamp ed;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Relative pt;
+ struct GNUNET_TIME_Relative he;
+ uint32_t pal;
+
+ qs = TEH_PG_get_global_fee (pg,
+ start_date,
+ &sd,
+ &ed,
+ &wx,
+ &pt,
+ &he,
+ &pal,
+ &sig);
+ if (qs < 0)
+ return qs;
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ if (0 != GNUNET_memcmp (&sig,
+ master_sig))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (0 !=
+ TALER_global_fee_set_cmp (fees,
+ &wx))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (GNUNET_TIME_timestamp_cmp (sd,
+ !=,
+ start_date)) ||
+ (GNUNET_TIME_timestamp_cmp (ed,
+ !=,
+ end_date)) )
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (GNUNET_TIME_relative_cmp (purse_timeout,
+ !=,
+ pt)) ||
+ (GNUNET_TIME_relative_cmp (history_expiration,
+ !=,
+ he)) )
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (purse_account_limit != pal)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ /* equal record already exists */
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+
+ /* Used in #postgres_insert_global_fee */
+ PREPARE (pg,
+ "insert_global_fee",
+ "INSERT INTO global_fee "
+ "(start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_global_fee",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_global_fee.h b/src/exchangedb/pg_insert_global_fee.h
new file mode 100644
index 000000000..411345dc4
--- /dev/null
+++ b/src/exchangedb/pg_insert_global_fee.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_global_fee.h
+ * @brief implementation of the insert_global_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_GLOBAL_FEE_H
+#define PG_INSERT_GLOBAL_FEE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Insert global fee data into database.
+ *
+ * @param cls closure
+ * @param start_date when does the fees go into effect
+ * @param end_date when does the fees end being valid
+ * @param fees how high is are the global fees
+ * @param purse_timeout when do purses time out
+ * @param history_expiration how long are account histories preserved
+ * @param purse_account_limit how many purses are free per account
+ * @param master_sig signature over the above by the exchange master key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_global_fee (void *cls,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative purse_timeout,
+ struct GNUNET_TIME_Relative history_expiration,
+ uint32_t purse_account_limit,
+ const struct TALER_MasterSignatureP *master_sig);
+#endif
diff --git a/src/exchangedb/pg_insert_kyc_attributes.c b/src/exchangedb/pg_insert_kyc_attributes.c
new file mode 100644
index 000000000..3c94abb85
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_attributes.c
@@ -0,0 +1,110 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_attributes.c
+ * @brief Implementation of the insert_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_kyc_attributes.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_attributes (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ const char *provider_section,
+ unsigned int num_checks,
+ const char *satisfied_checks[static num_checks],
+ uint32_t birthday,
+ struct GNUNET_TIME_Timestamp collection_time,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes,
+ bool require_aml)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Timestamp expiration
+ = GNUNET_TIME_absolute_to_timestamp (expiration_time);
+ struct TALER_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ char *kyc_completed_notify_s
+ = GNUNET_PQ_get_event_notify_channel (&rep.header);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&process_row),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (kyc_prox),
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_array_ptrs_string (num_checks,
+ satisfied_checks,
+ pg->conn),
+ GNUNET_PQ_query_param_uint32 (&birthday),
+ (NULL == provider_account_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (provider_account_id),
+ (NULL == provider_legitimization_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (provider_legitimization_id),
+ GNUNET_PQ_query_param_timestamp (&collection_time),
+ GNUNET_PQ_query_param_absolute_time (&expiration_time),
+ GNUNET_PQ_query_param_timestamp (&expiration),
+ GNUNET_PQ_query_param_fixed_size (enc_attributes,
+ enc_attributes_size),
+ GNUNET_PQ_query_param_bool (require_aml),
+ GNUNET_PQ_query_param_string (kyc_completed_notify_s),
+ GNUNET_PQ_query_param_end
+ };
+ bool ok;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("out_ok",
+ &ok),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Inserting KYC attributes, wake up on %s\n",
+ kyc_completed_notify_s);
+ PREPARE (pg,
+ "insert_kyc_attributes",
+ "SELECT "
+ " out_ok"
+ " FROM exchange_do_insert_kyc_attributes "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14);");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "insert_kyc_attributes",
+ params,
+ rs);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ GNUNET_free (kyc_completed_notify_s);
+ GNUNET_PQ_event_do_poll (pg->conn);
+ if (qs < 0)
+ return qs;
+ if (! ok)
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ return qs;
+}
diff --git a/src/exchangedb/pg_insert_kyc_attributes.h b/src/exchangedb/pg_insert_kyc_attributes.h
new file mode 100644
index 000000000..35b25bdc8
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_attributes.h
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_attributes.h
+ * @brief implementation of the insert_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_KYC_ATTRIBUTES_H
+#define PG_INSERT_KYC_ATTRIBUTES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Store KYC attribute data, update KYC process status and
+ * AML status for the given account.
+ *
+ * @param cls closure
+ * @param process_row KYC process row to update
+ * @param h_payto account for which the attribute data is stored
+ * @param kyc_prox key for similarity search
+ * @param provider_section provider that must be checked
+ * @param num_checks how many checks do these attributes satisfy
+ * @param satisfied_checks array of checks satisfied by these attributes
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param birthday birthdate of user, in days after 1990, or 0 if unknown or definitively adult
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ * @param require_aml true to trigger AML
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_attributes (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ const char *provider_section,
+ unsigned int num_checks,
+ const char *satisfied_checks[static num_checks],
+ uint32_t birthday,
+ struct GNUNET_TIME_Timestamp collection_time,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes,
+ bool require_aml);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_kyc_failure.c b/src/exchangedb/pg_insert_kyc_failure.c
new file mode 100644
index 000000000..568c39ca8
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_failure.c
@@ -0,0 +1,82 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_failure.c
+ * @brief Implementation of the insert_kyc_failure function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_kyc_failure.h"
+#include "pg_helper.h"
+#include "pg_event_notify.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_failure (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&process_row),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (provider_section),
+ NULL != provider_account_id
+ ? GNUNET_PQ_query_param_string (provider_account_id)
+ : GNUNET_PQ_query_param_null (),
+ NULL != provider_legitimization_id
+ ? GNUNET_PQ_query_param_string (provider_legitimization_id)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "insert_kyc_failure",
+ "UPDATE legitimization_processes"
+ " SET"
+ " finished=TRUE"
+ " ,provider_user_id=$4"
+ " ,provider_legitimization_id=$5"
+ " WHERE h_payto=$2"
+ " AND legitimization_process_serial_id=$1"
+ " AND provider_section=$3;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_kyc_failure",
+ params);
+ if (qs > 0)
+ {
+ /* FIXME: might want to do this eventually in the same transaction... */
+ struct TALER_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+
+ TEH_PG_event_notify (pg,
+ &rep.header,
+ NULL,
+ 0);
+ }
+ return qs;
+}
diff --git a/src/exchangedb/pg_insert_kyc_failure.h b/src/exchangedb/pg_insert_kyc_failure.h
new file mode 100644
index 000000000..46d08df9c
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_failure.h
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_failure.h
+ * @brief implementation of the insert_kyc_failure function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_KYC_FAILURE_H
+#define PG_INSERT_KYC_FAILURE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Update KYC process status to finished (and failed).
+ *
+ * @param cls closure
+ * @param process_row KYC process row to update
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_failure (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_kyc_requirement_for_account.c b/src/exchangedb/pg_insert_kyc_requirement_for_account.c
new file mode 100644
index 000000000..95f695297
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_requirement_for_account.c
@@ -0,0 +1,67 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_requirement_for_account.c
+ * @brief Implementation of the insert_kyc_requirement_for_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_kyc_requirement_for_account.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_requirement_for_account (
+ void *cls,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *requirement_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ (NULL == reserve_pub)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("legitimization_requirement_serial_id",
+ requirement_row),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_insert_kyc_requirement_for_account() */
+ PREPARE (pg,
+ "insert_legitimization_requirement",
+ "INSERT INTO legitimization_requirements"
+ " (h_payto"
+ " ,reserve_pub"
+ " ,required_checks"
+ " ) VALUES "
+ " ($1, $2, $3)"
+ " ON CONFLICT (h_payto,required_checks) "
+ " DO UPDATE SET h_payto=$1" /* syntax requirement: dummy op */
+ " RETURNING legitimization_requirement_serial_id");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "insert_legitimization_requirement",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_insert_kyc_requirement_for_account.h b/src/exchangedb/pg_insert_kyc_requirement_for_account.h
new file mode 100644
index 000000000..331c8ba0c
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_requirement_for_account.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_requirement_for_account.h
+ * @brief implementation of the insert_kyc_requirement_for_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_KYC_REQUIREMENT_FOR_ACCOUNT_H
+#define PG_INSERT_KYC_REQUIREMENT_FOR_ACCOUNT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert KYC requirement for @a h_payto account into table.
+ *
+ * @param cls closure
+ * @param provider_section provider that must be checked
+ * @param h_payto account that must be KYC'ed
+ * @param reserve_pub if the account is a reserve, its public key. Maybe NULL
+ * @param[out] requirement_row set to legitimization requirement row for this check
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_requirement_for_account (
+ void *cls,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *requirement_row);
+
+#endif
diff --git a/src/exchangedb/pg_insert_kyc_requirement_process.c b/src/exchangedb/pg_insert_kyc_requirement_process.c
new file mode 100644
index 000000000..a20db3388
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_requirement_process.c
@@ -0,0 +1,75 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_requirement_process.c
+ * @brief Implementation of the insert_kyc_requirement_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_kyc_requirement_process.h"
+#include "pg_helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_requirement_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ uint64_t *process_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_string (provider_section),
+ (NULL != provider_account_id)
+ ? GNUNET_PQ_query_param_string (provider_account_id)
+ : GNUNET_PQ_query_param_null (),
+ (NULL != provider_legitimization_id)
+ ? GNUNET_PQ_query_param_string (provider_legitimization_id)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "insert_legitimization_process",
+ "INSERT INTO legitimization_processes"
+ " (h_payto"
+ " ,start_time"
+ " ,provider_section"
+ " ,provider_user_id"
+ " ,provider_legitimization_id"
+ " ) VALUES "
+ " ($1, $2, $3, $4, $5)"
+ " RETURNING legitimization_process_serial_id");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "insert_legitimization_process",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_insert_kyc_requirement_process.h b/src/exchangedb/pg_insert_kyc_requirement_process.h
new file mode 100644
index 000000000..df21db8cd
--- /dev/null
+++ b/src/exchangedb/pg_insert_kyc_requirement_process.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_kyc_requirement_process.h
+ * @brief implementation of the insert_kyc_requirement_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_KYC_REQUIREMENT_PROCESS_H
+#define PG_INSERT_KYC_REQUIREMENT_PROCESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Begin KYC requirement process.
+ *
+ * @param cls closure
+ * @param h_payto account that must be KYC'ed
+ * @param provider_section provider that must be checked
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param[out] process_row row the process is stored under
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_kyc_requirement_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ uint64_t *process_row);
+
+#endif
diff --git a/src/exchangedb/pg_insert_partner.c b/src/exchangedb/pg_insert_partner.c
new file mode 100644
index 000000000..d1d6069de
--- /dev/null
+++ b/src/exchangedb/pg_insert_partner.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_partner.c
+ * @brief Implementation of the insert_partner function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_partner.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_partner (void *cls,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ struct GNUNET_TIME_Relative wad_frequency,
+ const struct TALER_Amount *wad_fee,
+ const char *partner_base_url,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (master_pub),
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ GNUNET_PQ_query_param_timestamp (&end_date),
+ GNUNET_PQ_query_param_relative_time (&wad_frequency),
+ TALER_PQ_query_param_amount (pg->conn,
+ wad_fee),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_string (partner_base_url),
+ GNUNET_PQ_query_param_end
+ };
+
+
+ PREPARE (pg,
+ "insert_partner",
+ "INSERT INTO partners"
+ " (partner_master_pub"
+ " ,start_date"
+ " ,end_date"
+ " ,wad_frequency"
+ " ,wad_fee"
+ " ,master_sig"
+ " ,partner_base_url"
+ " ) VALUES "
+ " ($1, $2, $3, $4, $5, $6, $7)"
+ " ON CONFLICT DO NOTHING;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_partner",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_partner.h b/src/exchangedb/pg_insert_partner.h
new file mode 100644
index 000000000..3ebae786c
--- /dev/null
+++ b/src/exchangedb/pg_insert_partner.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_partner.h
+ * @brief implementation of the insert_partner function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_PARTNER_H
+#define PG_INSERT_PARTNER_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to store configuration data about a partner
+ * exchange that we are federated with.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param master_pub public offline signing key of the partner exchange
+ * @param start_date when does the following data start to be valid
+ * @param end_date when does the validity end (exclusive)
+ * @param wad_frequency how often do we do exchange-to-exchange settlements?
+ * @param wad_fee how much do we charge for transfers to the partner
+ * @param partner_base_url base URL of the partner exchange
+ * @param master_sig signature with our offline signing key affirming the above
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_partner (void *cls,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ struct GNUNET_TIME_Relative wad_frequency,
+ const struct TALER_Amount *wad_fee,
+ const char *partner_base_url,
+ const struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_insert_purse_request.c b/src/exchangedb/pg_insert_purse_request.c
new file mode 100644
index 000000000..d8d68abe8
--- /dev/null
+++ b/src/exchangedb/pg_insert_purse_request.c
@@ -0,0 +1,126 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_purse_request.c
+ * @brief Implementation of the insert_purse_request function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_purse_request.h"
+#include "pg_get_purse_request.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_purse_request (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ const struct TALER_Amount *amount,
+ const struct TALER_PurseContractSignatureP *purse_sig,
+ bool *in_conflict)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
+ uint32_t flags32 = (uint32_t) flags;
+ bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
+ == (flags & TALER_WAMF_MERGE_MODE_MASK));
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (merge_pub),
+ GNUNET_PQ_query_param_timestamp (&now),
+ GNUNET_PQ_query_param_timestamp (&purse_expiration),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_uint32 (&age_limit),
+ GNUNET_PQ_query_param_uint32 (&flags32),
+ GNUNET_PQ_query_param_bool (in_reserve_quota),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ TALER_PQ_query_param_amount (pg->conn,
+ purse_fee),
+ GNUNET_PQ_query_param_auto_from_type (purse_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ *in_conflict = false;
+ PREPARE (pg,
+ "insert_purse_request",
+ "INSERT INTO purse_requests"
+ " (purse_pub"
+ " ,merge_pub"
+ " ,purse_creation"
+ " ,purse_expiration"
+ " ,h_contract_terms"
+ " ,age_limit"
+ " ,flags"
+ " ,in_reserve_quota"
+ " ,amount_with_fee"
+ " ,purse_fee"
+ " ,purse_sig"
+ " ) VALUES "
+ " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)"
+ " ON CONFLICT DO NOTHING;");
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_purse_request",
+ params);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
+ return qs;
+ {
+ struct TALER_PurseMergePublicKeyP merge_pub2;
+ struct GNUNET_TIME_Timestamp purse_expiration2;
+ struct TALER_PrivateContractHashP h_contract_terms2;
+ uint32_t age_limit2;
+ struct TALER_Amount amount2;
+ struct TALER_Amount balance;
+ struct TALER_PurseContractSignatureP purse_sig2;
+
+ qs = TEH_PG_get_purse_request (pg,
+ purse_pub,
+ &merge_pub2,
+ &purse_expiration2,
+ &h_contract_terms2,
+ &age_limit2,
+ &amount2,
+ &balance,
+ &purse_sig2);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (age_limit2 == age_limit) &&
+ (0 == TALER_amount_cmp (amount,
+ &amount2)) &&
+ (0 == GNUNET_memcmp (&h_contract_terms2,
+ h_contract_terms)) &&
+ (0 == GNUNET_memcmp (&merge_pub2,
+ merge_pub)) )
+ {
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ *in_conflict = true;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+}
diff --git a/src/exchangedb/pg_insert_purse_request.h b/src/exchangedb/pg_insert_purse_request.h
new file mode 100644
index 000000000..37cce2a96
--- /dev/null
+++ b/src/exchangedb/pg_insert_purse_request.h
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_purse_request.h
+ * @brief implementation of the insert_purse_request function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_PURSE_REQUEST_H
+#define PG_INSERT_PURSE_REQUEST_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to create a new purse with certain meta data.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the new purse
+ * @param merge_pub public key providing the merge capability
+ * @param purse_expiration time when the purse will expire
+ * @param h_contract_terms hash of the contract for the purse
+ * @param age_limit age limit to enforce for payments into the purse
+ * @param flags flags for the operation
+ * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags)
+ * @param amount target amount (with fees) to be put into the purse
+ * @param purse_sig signature with @a purse_pub's private key affirming the above
+ * @param[out] in_conflict set to true if the meta data
+ * conflicts with an existing purse;
+ * in this case, the return value will be
+ * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_purse_request (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ enum TALER_WalletAccountMergeFlags flags,
+ const struct TALER_Amount *purse_fee,
+ const struct TALER_Amount *amount,
+ const struct TALER_PurseContractSignatureP *purse_sig,
+ bool *in_conflict);
+
+#endif
diff --git a/src/exchangedb/pg_insert_records_by_table.c b/src/exchangedb/pg_insert_records_by_table.c
new file mode 100644
index 000000000..6ecec5bcf
--- /dev/null
+++ b/src/exchangedb/pg_insert_records_by_table.c
@@ -0,0 +1,2334 @@
+/*
+ This file is part of GNUnet
+ Copyright (C) 2020-2023 Taler Systems SA
+
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: AGPL3.0-or-later
+ */
+/**
+ * @file exchangedb/pg_insert_records_by_table.c
+ * @brief replicate_records_by_table implementation
+ * @author Christian Grothoff
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_records_by_table.h"
+#include "pg_helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+
+/**
+ * Signature of helper functions of #TEH_PG_insert_records_by_table().
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ * @return transaction status code
+ */
+typedef enum GNUNET_DB_QueryStatus
+(*InsertRecordCallback)(struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td);
+
+
+/**
+ * Function called with denominations records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_denominations (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct TALER_DenominationHashP denom_hash;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&denom_hash),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.denominations.denom_type),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.denominations.age_mask),
+ TALER_PQ_query_param_denom_pub (
+ &td->details.denominations.denom_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.denominations.master_sig),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.denominations.valid_from),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.denominations.expire_withdraw),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.denominations.expire_deposit),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.denominations.expire_legal),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.denominations.coin),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.denominations.fees.withdraw),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.denominations.fees.deposit),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.denominations.fees.refresh),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.denominations.fees.refund),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_denominations",
+ "INSERT INTO denominations"
+ "(denominations_serial"
+ ",denom_pub_hash"
+ ",denom_type"
+ ",age_mask"
+ ",denom_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin"
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
+ " $11, $12, $13, $14, $15);");
+
+ TALER_denom_pub_hash (
+ &td->details.denominations.denom_pub,
+ &denom_hash);
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_denominations",
+ params);
+}
+
+
+/**
+ * Function called with denomination_revocations records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_denomination_revocations (
+ struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.denomination_revocations.master_sig),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.denomination_revocations.denominations_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_denomination_revocations",
+ "INSERT INTO denomination_revocations"
+ "(denom_revocations_serial_id"
+ ",master_sig"
+ ",denominations_serial"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_denomination_revocations",
+ params);
+}
+
+
+/**
+ * Function called with denominations records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wire_targets (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct TALER_PaytoHashP payto_hash;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&payto_hash),
+ GNUNET_PQ_query_param_string (
+ td->details.wire_targets.payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wire_targets",
+ "INSERT INTO wire_targets"
+ "(wire_target_serial_id"
+ ",wire_target_h_payto"
+ ",payto_uri"
+ ") VALUES "
+ "($1, $2, $3);");
+ TALER_payto_hash (
+ td->details.wire_targets.payto_uri,
+ &payto_hash);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wire_targets",
+ params);
+}
+
+
+/**
+ * Function called with records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_legitimization_processes (struct PostgresClosure *pg,
+ const struct
+ TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.legitimization_processes.h_payto),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.legitimization_processes.expiration_time),
+ GNUNET_PQ_query_param_string (
+ td->details.legitimization_processes.provider_section),
+ GNUNET_PQ_query_param_string (
+ td->details.legitimization_processes.provider_user_id),
+ GNUNET_PQ_query_param_string (
+ td->details.legitimization_processes.provider_legitimization_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_legitimization_processes",
+ "INSERT INTO legitimization_processes"
+ "(legitimization_process_serial_id"
+ ",h_payto"
+ ",expiration_time"
+ ",provider_section"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ ") VALUES "
+ "($1, $3, $4, $5, $6, %7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_legitimization_processes",
+ params);
+}
+
+
+/**
+ * Function called with records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_legitimization_requirements (struct PostgresClosure *pg,
+ const struct
+ TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.legitimization_requirements.h_payto),
+ td->details.legitimization_requirements.no_reserve_pub
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (
+ &td->details.legitimization_requirements.reserve_pub),
+ GNUNET_PQ_query_param_string (
+ td->details.legitimization_requirements.required_checks),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_legitimization_requirements",
+ "INSERT INTO legitimization_requirements"
+ "(legitimization_requirement_serial_id"
+ ",h_payto"
+ ",reserve_pub"
+ ",required_checks"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_legitimization_requirements",
+ params);
+}
+
+
+/**
+ * Function called with reserves records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.reserves.reserve_pub),
+ GNUNET_PQ_query_param_timestamp (&td->details.reserves.expiration_date),
+ GNUNET_PQ_query_param_timestamp (&td->details.reserves.gc_date),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves",
+ "INSERT INTO reserves"
+ "(reserve_uuid"
+ ",reserve_pub"
+ ",expiration_date"
+ ",gc_date"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves",
+ params);
+}
+
+
+/**
+ * Function called with reserves_in records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves_in (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (&td->details.reserves_in.wire_reference),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_in.credit),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_in.sender_account_h_payto),
+ GNUNET_PQ_query_param_string (
+ td->details.reserves_in.exchange_account_section),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.reserves_in.execution_date),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.reserves_in.reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves_in",
+ "INSERT INTO reserves_in"
+ "(reserve_in_serial_id"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ ",reserve_pub"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves_in",
+ params);
+}
+
+
+/**
+ * Function called with reserves_open_requests records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves_open_requests (struct PostgresClosure *pg,
+ const struct
+ TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.reserves_open_requests.expiration_date),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_open_requests.reserve_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_open_requests.reserve_payment),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.reserves_open_requests.requested_purse_limit),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves_open_requests",
+ "INSERT INTO reserves_open_requests"
+ "(open_request_uuid"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",expiration_date"
+ ",reserve_sig"
+ ",reserve_payment"
+ ",requested_purse_limit"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves_open_requests",
+ params);
+}
+
+
+/**
+ * Function called with reserves_open_requests records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves_open_deposits (
+ struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_open_deposits.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_open_deposits.coin_sig),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_open_deposits.reserve_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_open_deposits.contribution),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves_open_deposits",
+ "INSERT INTO reserves_open_deposits"
+ "(reserve_open_deposit_uuid"
+ ",reserve_sig"
+ ",reserve_pub"
+ ",coin_pub"
+ ",coin_sig"
+ ",contribution"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves_open_deposits",
+ params);
+}
+
+
+/**
+ * Function called with reserves_close records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves_close (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.reserves_close.execution_date),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_close.wtid),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_close.sender_account_h_payto),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_close.amount),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_close.closing_fee),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_close.reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves_close",
+ "INSERT INTO reserves_close"
+ "(close_uuid"
+ ",execution_date"
+ ",wtid"
+ ",wire_target_h_payto"
+ ",amount"
+ ",closing_fee"
+ ",reserve_pub"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves_close",
+ params);
+}
+
+
+/**
+ * Function called with reserves_out records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_reserves_out (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_out.h_blind_ev),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.reserves_out.denominations_serial),
+ TALER_PQ_query_param_blinded_denom_sig (
+ &td->details.reserves_out.denom_sig),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.reserves_out.reserve_uuid),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.reserves_out.reserve_sig),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.reserves_out.execution_date),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.reserves_out.amount_with_fee),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_reserves_out",
+ "INSERT INTO reserves_out"
+ "(reserve_out_serial_id"
+ ",h_blind_ev"
+ ",denominations_serial"
+ ",denom_sig"
+ ",reserve_uuid"
+ ",reserve_sig"
+ ",execution_date"
+ ",amount_with_fee"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_reserves_out",
+ params);
+}
+
+
+/**
+ * Function called with auditors records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_auditors (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.auditors.auditor_pub),
+ GNUNET_PQ_query_param_string (td->details.auditors.auditor_name),
+ GNUNET_PQ_query_param_string (td->details.auditors.auditor_url),
+ GNUNET_PQ_query_param_bool (td->details.auditors.is_active),
+ GNUNET_PQ_query_param_timestamp (&td->details.auditors.last_change),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_auditors",
+ "INSERT INTO auditors"
+ "(auditor_uuid"
+ ",auditor_pub"
+ ",auditor_name"
+ ",auditor_url"
+ ",is_active"
+ ",last_change"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_auditors",
+ params);
+}
+
+
+/**
+ * Function called with auditor_denom_sigs records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_auditor_denom_sigs (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (&td->details.auditor_denom_sigs.auditor_uuid),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.auditor_denom_sigs.denominations_serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.auditor_denom_sigs.auditor_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_auditor_denom_sigs",
+ "INSERT INTO auditor_denom_sigs"
+ "(auditor_denom_serial"
+ ",auditor_uuid"
+ ",denominations_serial"
+ ",auditor_sig"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_auditor_denom_sigs",
+ params);
+}
+
+
+/**
+ * Function called with exchange_sign_keys records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_exchange_sign_keys (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.exchange_sign_keys.exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.exchange_sign_keys.master_sig),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.exchange_sign_keys.meta.start),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.exchange_sign_keys.meta.expire_sign),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.exchange_sign_keys.meta.expire_legal),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_exchange_sign_keys",
+ "INSERT INTO exchange_sign_keys"
+ "(esk_serial"
+ ",exchange_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_exchange_sign_keys",
+ params);
+}
+
+
+/**
+ * Function called with signkey_revocations records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_signkey_revocations (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (&td->details.signkey_revocations.esk_serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.signkey_revocations.master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_signkey_revocations",
+ "INSERT INTO signkey_revocations"
+ "(signkey_revocations_serial_id"
+ ",esk_serial"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_signkey_revocations",
+ params);
+}
+
+
+/**
+ * Function called with known_coins records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_known_coins (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.known_coins.coin_pub),
+ TALER_PQ_query_param_denom_sig (
+ &td->details.known_coins.denom_sig),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.known_coins.denominations_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_known_coins",
+ "INSERT INTO known_coins"
+ "(known_coin_id"
+ ",coin_pub"
+ ",denom_sig"
+ ",denominations_serial"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_known_coins",
+ params);
+}
+
+
+/**
+ * Function called with refresh_commitments records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_refresh_commitments (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.refresh_commitments.rc),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.refresh_commitments.old_coin_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.refresh_commitments.amount_with_fee),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.refresh_commitments.noreveal_index),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.refresh_commitments.old_coin_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_refresh_commitments",
+ "INSERT INTO refresh_commitments"
+ "(melt_serial_id"
+ ",rc"
+ ",old_coin_sig"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",old_coin_pub"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_refresh_commitments",
+ params);
+}
+
+
+/**
+ * Function called with refresh_revealed_coins records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_refresh_revealed_coins (
+ struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_HashCode h_coin_ev;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.refresh_revealed_coins.freshcoin_index),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.refresh_revealed_coins.link_sig),
+ GNUNET_PQ_query_param_fixed_size (
+ td->details.refresh_revealed_coins.coin_ev,
+ td->details.refresh_revealed_coins.
+ coin_ev_size),
+ GNUNET_PQ_query_param_auto_from_type (&h_coin_ev),
+ TALER_PQ_query_param_blinded_denom_sig (
+ &td->details.refresh_revealed_coins.ev_sig),
+ TALER_PQ_query_param_exchange_withdraw_values (
+ &td->details.refresh_revealed_coins.ewv),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.refresh_revealed_coins.denominations_serial),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.refresh_revealed_coins.melt_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_refresh_revealed_coins",
+ "INSERT INTO refresh_revealed_coins"
+ "(rrc_serial"
+ ",freshcoin_index"
+ ",link_sig"
+ ",coin_ev"
+ ",h_coin_ev"
+ ",ev_sig"
+ ",ewv"
+ ",denominations_serial"
+ ",melt_serial_id"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+ GNUNET_CRYPTO_hash (td->details.refresh_revealed_coins.coin_ev,
+ td->details.refresh_revealed_coins.coin_ev_size,
+ &h_coin_ev);
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_refresh_revealed_coins",
+ params);
+}
+
+
+/**
+ * Function called with refresh_transfer_keys records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_refresh_transfer_keys (
+ struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.refresh_transfer_keys.tp),
+ GNUNET_PQ_query_param_fixed_size (
+ &td->details.refresh_transfer_keys.tprivs[0],
+ (TALER_CNC_KAPPA - 1)
+ * sizeof (struct TALER_TransferPrivateKeyP)),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.refresh_transfer_keys.melt_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_refresh_transfer_keys",
+ "INSERT INTO refresh_transfer_keys"
+ "(rtc_serial"
+ ",transfer_pub"
+ ",transfer_privs"
+ ",melt_serial_id"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_refresh_transfer_keys",
+ params);
+}
+
+
+/**
+ * Function called with batch deposits records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_batch_deposits (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (&td->details.batch_deposits.shard),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.batch_deposits.merchant_pub),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.batch_deposits.wallet_timestamp),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.batch_deposits.exchange_timestamp),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.batch_deposits.refund_deadline),
+ GNUNET_PQ_query_param_timestamp (&td->details.batch_deposits.wire_deadline),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.batch_deposits.h_contract_terms),
+ td->details.batch_deposits.no_wallet_data_hash
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (
+ &td->details.batch_deposits.wallet_data_hash),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.batch_deposits.wire_salt),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.batch_deposits.wire_target_h_payto),
+ GNUNET_PQ_query_param_bool (td->details.batch_deposits.policy_blocked),
+ td->details.batch_deposits.no_policy_details
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (
+ &td->details.batch_deposits.policy_details_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_batch_deposits",
+ "INSERT INTO batch_deposits"
+ "(batch_deposit_serial_id"
+ ",shard"
+ ",merchant_pub"
+ ",wallet_timestamp"
+ ",exchange_timestamp"
+ ",refund_deadline"
+ ",wire_deadline"
+ ",h_contract_terms"
+ ",wallet_data_hash"
+ ",wire_salt"
+ ",wire_target_h_payto"
+ ",policy_details_serial_id"
+ ",policy_blocked"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
+ " $11, $12, $13);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_batch_deposits",
+ params);
+}
+
+
+/**
+ * Function called with deposits records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_coin_deposits (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.coin_deposits.batch_deposit_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.coin_deposits.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.coin_deposits.coin_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.coin_deposits.amount_with_fee),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_coin_deposits",
+ "INSERT INTO coin_deposits"
+ "(coin_deposit_serial_id"
+ ",batch_deposit_serial_id"
+ ",coin_pub"
+ ",coin_sig"
+ ",amount_with_fee"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_coin_deposits",
+ params);
+}
+
+
+/**
+ * Function called with refunds records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_refunds (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.refunds.merchant_sig),
+ GNUNET_PQ_query_param_uint64 (&td->details.refunds.rtransaction_id),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.refunds.amount_with_fee),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.refunds.batch_deposit_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_refunds",
+ "INSERT INTO refunds"
+ "(refund_serial_id"
+ ",coin_pub"
+ ",merchant_sig"
+ ",rtransaction_id"
+ ",amount_with_fee"
+ ",batch_deposit_serial_id"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_refunds",
+ params);
+}
+
+
+/**
+ * Function called with wire_out records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wire_out (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_timestamp (&td->details.wire_out.execution_date),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.wire_out.wtid_raw),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wire_out.wire_target_h_payto),
+ GNUNET_PQ_query_param_string (
+ td->details.wire_out.exchange_account_section),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wire_out.amount),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wire_out",
+ "INSERT INTO wire_out"
+ "(wireout_uuid"
+ ",execution_date"
+ ",wtid_raw"
+ ",wire_target_h_payto"
+ ",exchange_account_section"
+ ",amount"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wire_out",
+ params);
+}
+
+
+/**
+ * Function called with aggregation_tracking records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_aggregation_tracking (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.aggregation_tracking.batch_deposit_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aggregation_tracking.wtid_raw),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_aggregation_tracking",
+ "INSERT INTO aggregation_tracking"
+ "(aggregation_serial_id"
+ ",batch_deposit_serial_id"
+ ",wtid_raw"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_aggregation_tracking",
+ params);
+}
+
+
+/**
+ * Function called with wire_fee records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wire_fee (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_string (td->details.wire_fee.wire_method),
+ GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.start_date),
+ GNUNET_PQ_query_param_timestamp (&td->details.wire_fee.end_date),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wire_fee.fees.wire),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wire_fee.fees.closing),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.wire_fee.master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wire_fee",
+ "INSERT INTO wire_fee"
+ "(wire_fee_serial"
+ ",wire_method"
+ ",start_date"
+ ",end_date"
+ ",wire_fee"
+ ",closing_fee"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wire_fee",
+ params);
+}
+
+
+/**
+ * Function called with wire_fee records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_global_fee (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (
+ &td->serial),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.global_fee.start_date),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.global_fee.end_date),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.global_fee.fees.history),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.global_fee.fees.account),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.global_fee.fees.purse),
+ GNUNET_PQ_query_param_relative_time (
+ &td->details.global_fee.purse_timeout),
+ GNUNET_PQ_query_param_relative_time (
+ &td->details.global_fee.history_expiration),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.global_fee.purse_account_limit),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.global_fee.master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_global_fee",
+ "INSERT INTO global_fee"
+ "(global_fee_serial"
+ ",start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_global_fee",
+ params);
+}
+
+
+/**
+ * Function called with recoup records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_recoup (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_sig),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.recoup.coin_blind),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.recoup.amount),
+ GNUNET_PQ_query_param_timestamp (&td->details.recoup.timestamp),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.recoup.coin_pub),
+ GNUNET_PQ_query_param_uint64 (&td->details.recoup.reserve_out_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_recoup",
+ "INSERT INTO recoup"
+ "(recoup_uuid"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",coin_pub"
+ ",reserve_out_serial_id"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_recoup",
+ params);
+}
+
+
+/**
+ * Function called with recoup_refresh records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_recoup_refresh (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.recoup_refresh.coin_sig),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.recoup_refresh.coin_blind),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.recoup_refresh.amount),
+ GNUNET_PQ_query_param_timestamp (&td->details.recoup_refresh.timestamp),
+ GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.known_coin_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.recoup.coin_pub),
+ GNUNET_PQ_query_param_uint64 (&td->details.recoup_refresh.rrc_serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_recoup_refresh",
+ "INSERT INTO recoup_refresh"
+ "(recoup_refresh_uuid"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",known_coin_id"
+ ",coin_pub"
+ ",rrc_serial"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_recoup_refresh",
+ params);
+}
+
+
+/**
+ * Function called with extensions records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_extensions (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_string (td->details.extensions.name),
+ NULL == td->details.extensions.manifest ?
+ GNUNET_PQ_query_param_null () :
+ GNUNET_PQ_query_param_string (td->details.extensions.manifest),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_extensions",
+ "INSERT INTO extensions"
+ "(extension_id"
+ ",name"
+ ",manifest"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_extensions",
+ params);
+}
+
+
+/**
+ * Function called with policy_details records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_policy_details (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.policy_details.hash_code),
+ (td->details.policy_details.no_policy_json)
+ ? GNUNET_PQ_query_param_null ()
+ : TALER_PQ_query_param_json (td->details.policy_details.policy_json),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.policy_details.commitment),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.policy_details.accumulated_total),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.policy_details.fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ &td->details.policy_details.transferable),
+ GNUNET_PQ_query_param_timestamp (&td->details.policy_details.deadline),
+ GNUNET_PQ_query_param_uint16 (
+ &td->details.policy_details.fulfillment_state),
+ (td->details.policy_details.no_fulfillment_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (
+ &td->details.policy_details.fulfillment_id),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_policy_details",
+ "INSERT INTO policy_details"
+ "(policy_details_serial_id"
+ ",policy_hash_code"
+ ",policy_json"
+ ",deadline"
+ ",commitment"
+ ",accumulated_total"
+ ",fee"
+ ",transferable"
+ ",fulfillment_state"
+ ",fulfillment_id"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_policy_details",
+ params);
+}
+
+
+/**
+ * Function called with policy_fulfillment records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_policy_fulfillments (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.policy_fulfillments.fulfillment_timestamp),
+ (NULL == td->details.policy_fulfillments.fulfillment_proof)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (
+ td->details.policy_fulfillments.fulfillment_proof),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.policy_fulfillments.h_fulfillment_proof),
+ GNUNET_PQ_query_param_fixed_size (
+ td->details.policy_fulfillments.policy_hash_codes,
+ td->details.policy_fulfillments.policy_hash_codes_count),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_policy_fulfillments",
+ "INSERT INTO policy_fulfillments "
+ "(fulfillment_id"
+ ",fulfillment_timestamp"
+ ",fulfillment_proof"
+ ",h_fulfillment_proof"
+ ",policy_hash_codes"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_policy_fulfillments",
+ params);
+}
+
+
+/**
+ * Function called with purse_requests records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_purse_requests (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_requests.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_requests.merge_pub),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.purse_requests.purse_creation),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.purse_requests.purse_expiration),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_requests.h_contract_terms),
+ GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.age_limit),
+ GNUNET_PQ_query_param_uint32 (&td->details.purse_requests.flags),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.purse_requests.amount_with_fee),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.purse_requests.purse_fee),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_requests.purse_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_purse_requests",
+ "INSERT INTO purse_requests"
+ "(purse_requests_serial_id"
+ ",purse_pub"
+ ",merge_pub"
+ ",purse_creation"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",flags"
+ ",amount_with_fee"
+ ",purse_fee"
+ ",purse_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_purse_requests",
+ params);
+}
+
+
+/**
+ * Function called with purse_decision records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_purse_decision (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_decision.purse_pub),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.purse_decision.action_timestamp),
+ GNUNET_PQ_query_param_bool (
+ td->details.purse_decision.refunded),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_purse_refunds",
+ "INSERT INTO purse_refunds"
+ "(purse_refunds_serial_id"
+ ",purse_pub"
+ ",action_timestamp"
+ ",refunded"
+ ") VALUES "
+ "($1, $2, $3, $4);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_purse_decision",
+ params);
+}
+
+
+/**
+ * Function called with purse_merges records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_purse_merges (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (&td->details.purse_merges.partner_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_merges.reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.purse_merges.merge_sig),
+ GNUNET_PQ_query_param_timestamp (&td->details.purse_merges.merge_timestamp),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_purse_merges",
+ "INSERT INTO purse_merges"
+ "(purse_merge_request_serial_id"
+ ",partner_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",merge_sig"
+ ",merge_timestamp"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_purse_merges",
+ params);
+}
+
+
+/**
+ * Function called with purse_deposits records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_purse_deposits (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.purse_deposits.partner_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_deposits.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_pub),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.purse_deposits.amount_with_fee),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.purse_deposits.coin_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_purse_deposits",
+ "INSERT INTO purse_deposits"
+ "(purse_deposit_serial_id"
+ ",partner_serial_id"
+ ",purse_pub"
+ ",coin_pub"
+ ",amount_with_fee"
+ ",coin_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_purse_deposits",
+ params);
+}
+
+
+/**
+x * Function called with account_mergers records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_account_mergers (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.account_merges.reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.account_merges.reserve_sig),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.account_merges.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.account_merges.wallet_h_payto),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_account_merges",
+ "INSERT INTO account_merges"
+ "(account_merge_request_serial_id"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",purse_pub"
+ ",wallet_h_payto"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_account_merges",
+ params);
+}
+
+
+/**
+ * Function called with history_requests records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_history_requests (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.history_requests.reserve_pub),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.history_requests.request_timestamp),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.history_requests.reserve_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.history_requests.history_fee),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_history_requests",
+ "INSERT INTO history_requests"
+ "(history_request_serial_id"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",reserve_sig"
+ ",history_fee"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_history_requests",
+ params);
+}
+
+
+/**
+ * Function called with close_requests records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_close_requests (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.close_requests.reserve_pub),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.close_requests.close_timestamp),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.close_requests.reserve_sig),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.close_requests.close),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.close_requests.close_fee),
+ GNUNET_PQ_query_param_string (
+ td->details.close_requests.payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_close_requests",
+ "INSERT INTO close_requests"
+ "(close_request_serial_id"
+ ",reserve_pub"
+ ",close_timestamp"
+ ",reserve_sig"
+ ",close"
+ ",close_fee"
+ ",payto_uri"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_close_requests",
+ params);
+}
+
+
+/**
+ * Function called with wads_out records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wads_out (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.wads_out.wad_id),
+ GNUNET_PQ_query_param_uint64 (&td->details.wads_out.partner_serial_id),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_out.amount),
+ GNUNET_PQ_query_param_timestamp (&td->details.wads_out.execution_time),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wads_out",
+ "INSERT INTO wads_out"
+ "(wad_out_serial_id"
+ ",wad_id"
+ ",partner_serial_id"
+ ",amount"
+ ",execution_time"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wads_out",
+ params);
+}
+
+
+/**
+ * Function called with wads_out_entries records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wads_out_entries (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.wads_out_entries.wad_out_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_out_entries.reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_out_entries.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_out_entries.h_contract),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.wads_out_entries.purse_expiration),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.wads_out_entries.merge_timestamp),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_out_entries.amount_with_fee),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_out_entries.wad_fee),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_out_entries.deposit_fees),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_out_entries.reserve_sig),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_out_entries.purse_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wad_out_entries",
+ "INSERT INTO wad_out_entries"
+ "(wad_out_entry_serial_id"
+ ",wad_out_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wads_out_entries",
+ params);
+}
+
+
+/**
+ * Function called with wads_in records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wads_in (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (&td->details.wads_in.wad_id),
+ GNUNET_PQ_query_param_string (td->details.wads_in.origin_exchange_url),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_in.amount),
+ GNUNET_PQ_query_param_timestamp (&td->details.wads_in.arrival_time),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wads_in",
+ "INSERT INTO wads_in"
+ "(wad_in_serial_id"
+ ",wad_id"
+ ",origin_exchange_url"
+ ",amount"
+ ",arrival_time"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wads_in",
+ params);
+}
+
+
+/**
+ * Function called with wads_in_entries records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_wads_in_entries (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_in_entries.reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_in_entries.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_in_entries.h_contract),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.wads_in_entries.purse_expiration),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.wads_in_entries.merge_timestamp),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_in_entries.amount_with_fee),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_in_entries.wad_fee),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.wads_in_entries.deposit_fees),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_in_entries.reserve_sig),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.wads_in_entries.purse_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_wad_in_entries",
+ "INSERT INTO wad_in_entries"
+ "(wad_in_entry_serial_id"
+ ",wad_in_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_wads_in_entries",
+ params);
+}
+
+
+/**
+ * Function called with profit_drains records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_profit_drains (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.profit_drains.wtid),
+ GNUNET_PQ_query_param_string (
+ td->details.profit_drains.account_section),
+ GNUNET_PQ_query_param_string (
+ td->details.profit_drains.payto_uri),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.profit_drains.trigger_date),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.profit_drains.amount),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.profit_drains.master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_profit_drains",
+ "INSERT INTO profit_drains"
+ "(profit_drain_serial_id"
+ ",wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_profit_drains",
+ params);
+}
+
+
+/**
+ * Function called with aml_staff records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_aml_staff (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aml_staff.decider_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aml_staff.master_sig),
+ GNUNET_PQ_query_param_string (
+ td->details.aml_staff.decider_name),
+ GNUNET_PQ_query_param_bool (
+ td->details.aml_staff.is_active),
+ GNUNET_PQ_query_param_bool (
+ td->details.aml_staff.read_only),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.aml_staff.last_change),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_aml_staff",
+ "INSERT INTO aml_staff"
+ "(aml_staff_uuid"
+ ",decider_pub"
+ ",master_sig"
+ ",decider_name"
+ ",is_active"
+ ",read_only"
+ ",last_change"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_aml_staff",
+ params);
+}
+
+
+/**
+ * Function called with aml_history records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_aml_history (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ uint32_t status32 = td->details.aml_history.new_status;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aml_history.h_payto),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.aml_history.new_threshold),
+ GNUNET_PQ_query_param_uint32 (
+ &status32),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.aml_history.decision_time),
+ GNUNET_PQ_query_param_string (
+ td->details.aml_history.justification),
+ (NULL == td->details.aml_history.kyc_requirements)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (
+ td->details.aml_history.kyc_requirements),
+ GNUNET_PQ_query_param_uint64 (
+ &td->details.aml_history.kyc_req_row),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aml_history.decider_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.aml_history.decider_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_aml_history",
+ "INSERT INTO aml_history"
+ "(aml_history_serial_id"
+ ",h_payto"
+ ",new_threshold"
+ ",new_status"
+ ",decision_time"
+ ",justification"
+ ",kyc_requirements"
+ ",kyc_req_row"
+ ",decider_pub"
+ ",decider_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_aml_history",
+ params);
+}
+
+
+/**
+ * Function called with kyc_attributes records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_kyc_attributes (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.kyc_attributes.h_payto),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.kyc_attributes.kyc_prox),
+ GNUNET_PQ_query_param_string (
+ td->details.kyc_attributes.provider),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.kyc_attributes.collection_time),
+ GNUNET_PQ_query_param_timestamp (
+ &td->details.kyc_attributes.expiration_time),
+ GNUNET_PQ_query_param_fixed_size (
+ &td->details.kyc_attributes.encrypted_attributes,
+ td->details.kyc_attributes.encrypted_attributes_size),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_kyc_attributes",
+ "INSERT INTO kyc_attributes"
+ "(kyc_attributes_serial_id"
+ ",h_payto"
+ ",kyc_prox"
+ ",provider"
+ ",collection_time"
+ ",expiration_time"
+ ",encrypted_attributes"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_kyc_attributes",
+ params);
+}
+
+
+/**
+ * Function called with purse_deletion records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_purse_deletion (struct PostgresClosure *pg,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_deletion.purse_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.purse_deletion.purse_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_purse_deletion",
+ "INSERT INTO purse_deletion"
+ "(purse_deletion_serial_id"
+ ",purse_pub"
+ ",purse_sig"
+ ") VALUES "
+ "($1, $2, $3);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_purse_deletion",
+ params);
+}
+
+
+/**
+ * Function called with age_withdraw records to insert into table.
+ *
+ * @param pg plugin context
+ * @param td record to insert
+ */
+static enum GNUNET_DB_QueryStatus
+irbt_cb_table_age_withdraw (struct PostgresClosure *pg,
+ const struct
+ TALER_EXCHANGEDB_TableData *td)
+{
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&td->serial),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.age_withdraw.h_commitment),
+ TALER_PQ_query_param_amount (
+ pg->conn,
+ &td->details.age_withdraw.amount_with_fee),
+ GNUNET_PQ_query_param_uint16 (
+ &td->details.age_withdraw.max_age),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.age_withdraw.reserve_pub),
+ GNUNET_PQ_query_param_auto_from_type (
+ &td->details.age_withdraw.reserve_sig),
+ GNUNET_PQ_query_param_uint32 (
+ &td->details.age_withdraw.noreveal_index),
+ /* TODO: other fields, too! */
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_into_table_age_withdraw",
+ "INSERT INTO age_withdraw"
+ "(age_withdraw_commitment_id"
+ ",h_commitment"
+ ",amount_with_fee"
+ ",max_age"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",noreveal_index"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6, $7, $8);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_into_table_age_withdraw",
+ params);
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_records_by_table (void *cls,
+ const struct TALER_EXCHANGEDB_TableData *td)
+{
+ struct PostgresClosure *pg = cls;
+ InsertRecordCallback rh = NULL;
+
+ switch (td->table)
+ {
+ case TALER_EXCHANGEDB_RT_DENOMINATIONS:
+ rh = &irbt_cb_table_denominations;
+ break;
+ case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
+ rh = &irbt_cb_table_denomination_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
+ rh = &irbt_cb_table_wire_targets;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
+ rh = &irbt_cb_table_legitimization_processes;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS:
+ rh = &irbt_cb_table_legitimization_requirements;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES:
+ rh = &irbt_cb_table_reserves;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_IN:
+ rh = &irbt_cb_table_reserves_in;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
+ rh = &irbt_cb_table_reserves_close;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
+ rh = &irbt_cb_table_reserves_open_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
+ rh = &irbt_cb_table_reserves_open_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OUT:
+ rh = &irbt_cb_table_reserves_out;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITORS:
+ rh = &irbt_cb_table_auditors;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
+ rh = &irbt_cb_table_auditor_denom_sigs;
+ break;
+ case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
+ rh = &irbt_cb_table_exchange_sign_keys;
+ break;
+ case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
+ rh = &irbt_cb_table_signkey_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_KNOWN_COINS:
+ rh = &irbt_cb_table_known_coins;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
+ rh = &irbt_cb_table_refresh_commitments;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
+ rh = &irbt_cb_table_refresh_revealed_coins;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
+ rh = &irbt_cb_table_refresh_transfer_keys;
+ break;
+ case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
+ rh = &irbt_cb_table_batch_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
+ rh = &irbt_cb_table_coin_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_REFUNDS:
+ rh = &irbt_cb_table_refunds;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_OUT:
+ rh = &irbt_cb_table_wire_out;
+ break;
+ case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
+ rh = &irbt_cb_table_aggregation_tracking;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_FEE:
+ rh = &irbt_cb_table_wire_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
+ rh = &irbt_cb_table_global_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP:
+ rh = &irbt_cb_table_recoup;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
+ rh = &irbt_cb_table_recoup_refresh;
+ break;
+ case TALER_EXCHANGEDB_RT_EXTENSIONS:
+ rh = &irbt_cb_table_extensions;
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_DETAILS:
+ rh = &irbt_cb_table_policy_details;
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS:
+ rh = &irbt_cb_table_policy_fulfillments;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
+ rh = &irbt_cb_table_purse_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DECISION:
+ rh = &irbt_cb_table_purse_decision;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_MERGES:
+ rh = &irbt_cb_table_purse_merges;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
+ rh = &irbt_cb_table_purse_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
+ rh = &irbt_cb_table_account_mergers;
+ break;
+ case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
+ rh = &irbt_cb_table_history_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
+ rh = &irbt_cb_table_close_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT:
+ rh = &irbt_cb_table_wads_out;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
+ rh = &irbt_cb_table_wads_out_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN:
+ rh = &irbt_cb_table_wads_in;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
+ rh = &irbt_cb_table_wads_in_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
+ rh = &irbt_cb_table_profit_drains;
+ break;
+ case TALER_EXCHANGEDB_RT_AML_STAFF:
+ rh = &irbt_cb_table_aml_staff;
+ break;
+ case TALER_EXCHANGEDB_RT_AML_HISTORY:
+ rh = &irbt_cb_table_aml_history;
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
+ rh = &irbt_cb_table_kyc_attributes;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DELETION:
+ rh = &irbt_cb_table_purse_deletion;
+ break;
+ case TALER_EXCHANGEDB_RT_AGE_WITHDRAW:
+ rh = &irbt_cb_table_age_withdraw;
+ break;
+ }
+ if (NULL == rh)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return rh (pg,
+ td);
+}
+
+
+/* end of pg_insert_records_by_table.c */
diff --git a/src/exchangedb/pg_insert_records_by_table.h b/src/exchangedb/pg_insert_records_by_table.h
new file mode 100644
index 000000000..d9817e0ec
--- /dev/null
+++ b/src/exchangedb/pg_insert_records_by_table.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_records_by_table.h
+ * @brief implementation of the insert_records_by_table function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_RECORDS_BY_TABLE_H
+#define PG_INSERT_RECORDS_BY_TABLE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert record set into @a table. Used in exchange-auditor database
+ * replication.
+ *
+ * @param cls closure
+ * @param td table data to insert
+ * @return transaction status code, #GNUNET_DB_STATUS_HARD_ERROR if
+ * @e table in @a tr is not supported
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_records_by_table (void *cls,
+ const struct TALER_EXCHANGEDB_TableData *td);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_refresh_reveal.c b/src/exchangedb/pg_insert_refresh_reveal.c
new file mode 100644
index 000000000..bddca472b
--- /dev/null
+++ b/src/exchangedb/pg_insert_refresh_reveal.c
@@ -0,0 +1,109 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_refresh_reveal.c
+ * @brief Implementation of the insert_refresh_reveal function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_refresh_reveal.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_refresh_reveal (
+ void *cls,
+ uint64_t melt_serial_id,
+ uint32_t num_rrcs,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivs,
+ const struct TALER_TransferPublicKeyP *tp)
+{
+ struct PostgresClosure *pg = cls;
+
+ if (TALER_CNC_KAPPA != num_tprivs + 1)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ PREPARE (pg,
+ "insert_refresh_revealed_coin",
+ "INSERT INTO refresh_revealed_coins "
+ "(melt_serial_id "
+ ",freshcoin_index "
+ ",link_sig "
+ ",denominations_serial "
+ ",coin_ev"
+ ",ewv"
+ ",h_coin_ev"
+ ",ev_sig"
+ ") SELECT $1, $2, $3, "
+ " denominations_serial, $5, $6, $7, $8"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$4"
+ " ON CONFLICT DO NOTHING;");
+ for (uint32_t i = 0; i<num_rrcs; i++)
+ {
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&melt_serial_id),
+ GNUNET_PQ_query_param_uint32 (&i),
+ GNUNET_PQ_query_param_auto_from_type (&rrc->orig_coin_link_sig),
+ GNUNET_PQ_query_param_auto_from_type (&rrc->h_denom_pub),
+ TALER_PQ_query_param_blinded_planchet (&rrc->blinded_planchet),
+ TALER_PQ_query_param_exchange_withdraw_values (&rrc->exchange_vals),
+ GNUNET_PQ_query_param_auto_from_type (&rrc->coin_envelope_hash),
+ TALER_PQ_query_param_blinded_denom_sig (&rrc->coin_sig),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_refresh_revealed_coin",
+ params);
+ if (0 > qs)
+ return qs;
+ }
+
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&melt_serial_id),
+ GNUNET_PQ_query_param_auto_from_type (tp),
+ GNUNET_PQ_query_param_fixed_size (
+ tprivs,
+ num_tprivs * sizeof (struct TALER_TransferPrivateKeyP)),
+ GNUNET_PQ_query_param_end
+ };
+
+ /* Used in #postgres_insert_refresh_reveal() to store the transfer
+ keys we learned */
+ PREPARE (pg,
+ "insert_refresh_transfer_keys",
+ "INSERT INTO refresh_transfer_keys "
+ "(melt_serial_id"
+ ",transfer_pub"
+ ",transfer_privs"
+ ") VALUES ($1, $2, $3)"
+ " ON CONFLICT DO NOTHING;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_refresh_transfer_keys",
+ params);
+ }
+}
diff --git a/src/exchangedb/pg_insert_refresh_reveal.h b/src/exchangedb/pg_insert_refresh_reveal.h
new file mode 100644
index 000000000..ad53ab197
--- /dev/null
+++ b/src/exchangedb/pg_insert_refresh_reveal.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_refresh_reveal.h
+ * @brief implementation of the insert_refresh_reveal function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_REFRESH_REVEAL_H
+#define PG_INSERT_REFRESH_REVEAL_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Store in the database which coin(s) the wallet wanted to create
+ * in a given refresh operation and all of the other information
+ * we learned or created in the /refresh/reveal step.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param melt_serial_id row ID of the commitment / melt operation in refresh_commitments
+ * @param num_rrcs number of coins to generate, size of the @a rrcs array
+ * @param rrcs information about the new coins
+ * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
+ * @param tprivs transfer private keys to store
+ * @param tp public key to store
+ * @return query status for the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_refresh_reveal (
+ void *cls,
+ uint64_t melt_serial_id,
+ uint32_t num_rrcs,
+ const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
+ unsigned int num_tprivs,
+ const struct TALER_TransferPrivateKeyP *tprivs,
+ const struct TALER_TransferPublicKeyP *tp);
+
+#endif
diff --git a/src/exchangedb/pg_insert_refund.c b/src/exchangedb/pg_insert_refund.c
new file mode 100644
index 000000000..e989c91bc
--- /dev/null
+++ b/src/exchangedb/pg_insert_refund.c
@@ -0,0 +1,65 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_refund.c
+ * @brief Implementation of the insert_refund function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_refund.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_refund (void *cls,
+ const struct TALER_EXCHANGEDB_Refund *refund)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
+ GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
+ GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
+ TALER_PQ_query_param_amount (pg->conn,
+ &refund->details.refund_amount),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_assert (GNUNET_YES ==
+ TALER_amount_cmp_currency (&refund->details.refund_amount,
+ &refund->details.refund_fee));
+ PREPARE (pg,
+ "insert_refund",
+ "INSERT INTO refunds "
+ "(coin_pub"
+ ",batch_deposit_serial_id"
+ ",merchant_sig"
+ ",rtransaction_id"
+ ",amount_with_fee"
+ ") SELECT $1, cdep.batch_deposit_serial_id, $3, $5, $6"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep USING (batch_deposit_serial_id)"
+ " WHERE coin_pub=$1"
+ " AND h_contract_terms=$4"
+ " AND merchant_pub=$2");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_refund",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_refund.h b/src/exchangedb/pg_insert_refund.h
new file mode 100644
index 000000000..02190bcc9
--- /dev/null
+++ b/src/exchangedb/pg_insert_refund.h
@@ -0,0 +1,38 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_refund.h
+ * @brief implementation of the insert_refund function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_REFUND_H
+#define PG_INSERT_REFUND_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Insert information about refunded coin into the database.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param refund refund information to store
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_refund (void *cls,
+ const struct TALER_EXCHANGEDB_Refund *refund);
+
+#endif
diff --git a/src/exchangedb/pg_insert_reserve_closed.c b/src/exchangedb/pg_insert_reserve_closed.c
new file mode 100644
index 000000000..6644fb892
--- /dev/null
+++ b/src/exchangedb/pg_insert_reserve_closed.c
@@ -0,0 +1,113 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_reserve_closed.c
+ * @brief Implementation of the insert_reserve_closed function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_reserve_closed.h"
+#include "pg_helper.h"
+#include "pg_reserves_get.h"
+#include "pg_reserves_update.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_reserve_closed (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const char *receiver_account,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *closing_fee,
+ uint64_t close_request_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct TALER_EXCHANGEDB_Reserve reserve;
+ enum GNUNET_DB_QueryStatus qs;
+ struct TALER_PaytoHashP h_payto;
+
+ TALER_payto_hash (receiver_account,
+ &h_payto);
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_timestamp (&execution_date),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_auto_from_type (&h_payto),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount_with_fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ closing_fee),
+ GNUNET_PQ_query_param_uint64 (&close_request_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "reserves_close_insert",
+ "INSERT INTO reserves_close "
+ "(reserve_pub"
+ ",execution_date"
+ ",wtid"
+ ",wire_target_h_payto"
+ ",amount"
+ ",closing_fee"
+ ",close_request_row"
+ ") VALUES ($1, $2, $3, $4, $5, $6, $7);");
+
+ qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "reserves_close_insert",
+ params);
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
+ return qs;
+
+ /* update reserve balance */
+ reserve.pub = *reserve_pub;
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ (qs = TEH_PG_reserves_get (cls,
+ &reserve)))
+ {
+ /* Existence should have been checked before we got here... */
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+ }
+ {
+ enum TALER_AmountArithmeticResult ret;
+
+ ret = TALER_amount_subtract (&reserve.balance,
+ &reserve.balance,
+ amount_with_fee);
+ if (ret < 0)
+ {
+ /* The reserve history was checked to make sure there is enough of a balance
+ left before we tried this; however, concurrent operations may have changed
+ the situation by now. We should re-try the transaction. */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Closing of reserve `%s' refused due to balance mismatch. Retrying.\n",
+ TALER_B2S (reserve_pub));
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ GNUNET_break (TALER_AAR_RESULT_ZERO == ret);
+ }
+ return TEH_PG_reserves_update (cls,
+ &reserve);
+}
diff --git a/src/exchangedb/pg_insert_reserve_closed.h b/src/exchangedb/pg_insert_reserve_closed.h
new file mode 100644
index 000000000..2ac1a6e30
--- /dev/null
+++ b/src/exchangedb/pg_insert_reserve_closed.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_reserve_closed.h
+ * @brief implementation of the insert_reserve_closed function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_RESERVE_CLOSED_H
+#define PG_INSERT_RESERVE_CLOSED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Insert reserve close operation into database.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param execution_date when did we perform the transfer?
+ * @param receiver_account to which account do we transfer?
+ * @param wtid wire transfer details
+ * @param amount_with_fee amount we charged to the reserve
+ * @param closing_fee how high is the closing fee
+ * @param close_request_row identifies explicit close request, 0 for none
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_reserve_closed (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct GNUNET_TIME_Timestamp execution_date,
+ const char *receiver_account,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_Amount *closing_fee,
+ uint64_t close_request_row);
+
+#endif
diff --git a/src/exchangedb/pg_insert_reserve_open_deposit.c b/src/exchangedb/pg_insert_reserve_open_deposit.c
new file mode 100644
index 000000000..f9cedcbe7
--- /dev/null
+++ b/src/exchangedb/pg_insert_reserve_open_deposit.c
@@ -0,0 +1,67 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_reserve_open_deposit.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_reserve_open_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_reserve_open_deposit (
+ void *cls,
+ const struct TALER_CoinPublicInfo *cpi,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ uint64_t known_coin_id,
+ const struct TALER_Amount *coin_total,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *insufficient_funds)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&cpi->coin_pub),
+ GNUNET_PQ_query_param_uint64 (&known_coin_id),
+ GNUNET_PQ_query_param_auto_from_type (coin_sig),
+ GNUNET_PQ_query_param_auto_from_type (reserve_sig),
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ coin_total),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("out_insufficient_funds",
+ insufficient_funds),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "insert_reserve_open_deposit",
+ "SELECT "
+ " out_insufficient_funds"
+ " FROM exchange_do_reserve_open_deposit"
+ " ($1,$2,$3,$4,$5,$6);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "insert_reserve_open_deposit",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_insert_reserve_open_deposit.h b/src/exchangedb/pg_insert_reserve_open_deposit.h
new file mode 100644
index 000000000..7eb2fe093
--- /dev/null
+++ b/src/exchangedb/pg_insert_reserve_open_deposit.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_insert_reserve_open_deposit.h
+ * @brief implementation of the insert_reserve_open_deposit function
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_RESERVE_OPEN_DEPOSIT_H
+#define PG_INSERT_RESERVE_OPEN_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert reserve open coin deposit data into database.
+ * Subtracts the @a coin_total from the coin's balance.
+ *
+ * @param cls closure
+ * @param cpi public information about the coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT
+ * @param known_coin_id ID of the coin in the known_coins table
+ * @param coin_total amount to be spent of the coin (including deposit fee)
+ * @param reserve_sig signature by the reserve affirming the open operation
+ * @param reserve_pub public key of the reserve being opened
+ * @param[out] insufficient_funds set to true if the coin's balance is insufficient, otherwise to false
+ * @return transaction status code, 0 if operation is already in the DB
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_reserve_open_deposit (
+ void *cls,
+ const struct TALER_CoinPublicInfo *cpi,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ uint64_t known_coin_id,
+ const struct TALER_Amount *coin_total,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *insufficient_funds);
+
+#endif
diff --git a/src/exchangedb/pg_insert_signkey_revocation.c b/src/exchangedb/pg_insert_signkey_revocation.c
new file mode 100644
index 000000000..9197be6ad
--- /dev/null
+++ b/src/exchangedb/pg_insert_signkey_revocation.c
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_signkey_revocation.c
+ * @brief Implementation of the insert_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_signkey_revocation.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_signkey_revocation (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+
+
+ PREPARE (pg,
+ "insert_signkey_revocation",
+ "INSERT INTO signkey_revocations "
+ "(esk_serial"
+ ",master_sig"
+ ") SELECT esk_serial, $2 "
+ " FROM exchange_sign_keys"
+ " WHERE exchange_pub=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_signkey_revocation",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_signkey_revocation.h b/src/exchangedb/pg_insert_signkey_revocation.h
new file mode 100644
index 000000000..534e6d451
--- /dev/null
+++ b/src/exchangedb/pg_insert_signkey_revocation.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_signkey_revocation.h
+ * @brief implementation of the insert_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_SIGNKEY_REVOCATION_H
+#define PG_INSERT_SIGNKEY_REVOCATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Store information about a revoked online signing key.
+ *
+ * @param cls closure
+ * @param exchange_pub exchange online signing key that was revoked
+ * @param master_sig signature affirming the revocation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_signkey_revocation (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_MasterSignatureP *master_sig);
+#endif
diff --git a/src/exchangedb/pg_insert_wire.c b/src/exchangedb/pg_insert_wire.c
new file mode 100644
index 000000000..b1364cbb3
--- /dev/null
+++ b/src/exchangedb/pg_insert_wire.c
@@ -0,0 +1,74 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_wire.c
+ * @brief Implementation of the insert_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_wire.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_wire (void *cls,
+ const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ struct GNUNET_TIME_Timestamp start_date,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (payto_uri),
+ NULL == conversion_url
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (conversion_url),
+ TALER_PQ_query_param_json (debit_restrictions),
+ TALER_PQ_query_param_json (credit_restrictions),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ NULL == bank_label
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (bank_label),
+ GNUNET_PQ_query_param_int64 (&priority),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_wire",
+ "INSERT INTO wire_accounts "
+ "(payto_uri"
+ ",conversion_url"
+ ",debit_restrictions"
+ ",credit_restrictions"
+ ",master_sig"
+ ",is_active"
+ ",last_change"
+ ",bank_label"
+ ",priority"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, true, $6, $7, $8);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_wire.h b/src/exchangedb/pg_insert_wire.h
new file mode 100644
index 000000000..7a5e4caca
--- /dev/null
+++ b/src/exchangedb/pg_insert_wire.h
@@ -0,0 +1,55 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_wire.h
+ * @brief implementation of the insert_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_WIRE_H
+#define PG_INSERT_WIRE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Insert information about an wire account used by this exchange.
+ *
+ * @param cls closure
+ * @param payto_uri wire account of the exchange
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
+ * @param start_date date when the account was added by the offline system
+ * (only to be used for replay detection)
+ * @param master_sig public signature affirming the existence of the account,
+ * must be of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS
+ * @param bank_label label to show this entry under in the UI, can be NULL
+ * @param priority determines order in which entries are shown in the UI
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_wire (void *cls,
+ const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ struct GNUNET_TIME_Timestamp start_date,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority);
+
+
+#endif
diff --git a/src/exchangedb/pg_insert_wire_fee.c b/src/exchangedb/pg_insert_wire_fee.c
new file mode 100644
index 000000000..af818bcca
--- /dev/null
+++ b/src/exchangedb/pg_insert_wire_fee.c
@@ -0,0 +1,108 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_wire_fee.c
+ * @brief Implementation of the insert_wire_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_wire_fee.h"
+#include "pg_helper.h"
+#include "pg_get_wire_fee.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_wire_fee (void *cls,
+ const char *type,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_WireFeeSet *fees,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (type),
+ GNUNET_PQ_query_param_timestamp (&start_date),
+ GNUNET_PQ_query_param_timestamp (&end_date),
+ TALER_PQ_query_param_amount (pg->conn,
+ &fees->wire),
+ TALER_PQ_query_param_amount (pg->conn,
+ &fees->closing),
+ GNUNET_PQ_query_param_auto_from_type (master_sig),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_WireFeeSet wx;
+ struct TALER_MasterSignatureP sig;
+ struct GNUNET_TIME_Timestamp sd;
+ struct GNUNET_TIME_Timestamp ed;
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = TEH_PG_get_wire_fee (pg,
+ type,
+ start_date,
+ &sd,
+ &ed,
+ &wx,
+ &sig);
+ if (qs < 0)
+ return qs;
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ if (0 != GNUNET_memcmp (&sig,
+ master_sig))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if (0 !=
+ TALER_wire_fee_set_cmp (fees,
+ &wx))
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ if ( (GNUNET_TIME_timestamp_cmp (sd,
+ !=,
+ start_date)) ||
+ (GNUNET_TIME_timestamp_cmp (ed,
+ !=,
+ end_date)) )
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ /* equal record already exists */
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+
+ PREPARE (pg,
+ "insert_wire_fee",
+ "INSERT INTO wire_fee "
+ "(wire_method"
+ ",start_date"
+ ",end_date"
+ ",wire_fee"
+ ",closing_fee"
+ ",master_sig"
+ ") VALUES "
+ "($1, $2, $3, $4, $5, $6);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire_fee",
+ params);
+}
diff --git a/src/exchangedb/pg_insert_wire_fee.h b/src/exchangedb/pg_insert_wire_fee.h
new file mode 100644
index 000000000..15c1a39f8
--- /dev/null
+++ b/src/exchangedb/pg_insert_wire_fee.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_insert_wire_fee.h
+ * @brief implementation of the insert_wire_fee function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_INSERT_WIRE_FEE_H
+#define PG_INSERT_WIRE_FEE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Insert wire transfer fee into database.
+ *
+ * @param cls closure
+ * @param type type of wire transfer this fee applies for
+ * @param start_date when does the fee go into effect
+ * @param end_date when does the fee end being valid
+ * @param fees how high are the wire fees
+ * @param master_sig signature over the above by the exchange master key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_insert_wire_fee (void *cls,
+ const char *type,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ const struct TALER_WireFeeSet *fees,
+ const struct TALER_MasterSignatureP *master_sig);
+#endif
diff --git a/src/exchangedb/pg_iterate_active_auditors.c b/src/exchangedb/pg_iterate_active_auditors.c
new file mode 100644
index 000000000..4f1c6ec66
--- /dev/null
+++ b/src/exchangedb/pg_iterate_active_auditors.c
@@ -0,0 +1,123 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_active_auditors.c
+ * @brief Implementation of the iterate_active_auditors function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_active_auditors.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #auditors_cb_helper()
+ */
+struct AuditorsIteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_AuditorsCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_active_auditors().
+ * Calls the callback with each auditor.
+ *
+ * @param cls a `struct SignkeysIteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+auditors_cb_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AuditorsIteratorContext *dic = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_AuditorPublicKeyP auditor_pub;
+ char *auditor_url;
+ char *auditor_name;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
+ &auditor_pub),
+ GNUNET_PQ_result_spec_string ("auditor_url",
+ &auditor_url),
+ GNUNET_PQ_result_spec_string ("auditor_name",
+ &auditor_name),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ dic->cb (dic->cb_cls,
+ &auditor_pub,
+ auditor_url,
+ auditor_name);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_active_auditors (void *cls,
+ TALER_EXCHANGEDB_AuditorsCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct AuditorsIteratorContext dic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ };
+
+ PREPARE (pg,
+ "select_auditors",
+ "SELECT"
+ " auditor_pub"
+ ",auditor_url"
+ ",auditor_name"
+ " FROM auditors"
+ " WHERE"
+ " is_active;");
+
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "select_auditors",
+ params,
+ &auditors_cb_helper,
+ &dic);
+}
diff --git a/src/exchangedb/pg_iterate_active_auditors.h b/src/exchangedb/pg_iterate_active_auditors.h
new file mode 100644
index 000000000..f0e2808e9
--- /dev/null
+++ b/src/exchangedb/pg_iterate_active_auditors.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_active_auditors.h
+ * @brief implementation of the iterate_active_auditors function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_ACTIVE_AUDITORS_H
+#define PG_ITERATE_ACTIVE_AUDITORS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to invoke @a cb on every active auditor. Disabled
+ * auditors are skipped. Runs in its own read-only transaction.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each active auditor
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_active_auditors (void *cls,
+ TALER_EXCHANGEDB_AuditorsCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_active_signkeys.c b/src/exchangedb/pg_iterate_active_signkeys.c
new file mode 100644
index 000000000..9c280c95d
--- /dev/null
+++ b/src/exchangedb/pg_iterate_active_signkeys.c
@@ -0,0 +1,144 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_active_signkeys.c
+ * @brief Implementation of the iterate_active_signkeys function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_active_signkeys.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #signkeys_cb_helper()
+ */
+struct SignkeysIteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_ActiveSignkeysCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_active_signkeys().
+ * Calls the callback with each signkey.
+ *
+ * @param cls a `struct SignkeysIteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+signkeys_cb_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SignkeysIteratorContext *dic = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_SignkeyMetaData meta;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_MasterSignatureP master_sig;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
+ &exchange_pub),
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta.start),
+ GNUNET_PQ_result_spec_timestamp ("expire_sign",
+ &meta.expire_sign),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta.expire_legal),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ dic->cb (dic->cb_cls,
+ &exchange_pub,
+ &meta,
+ &master_sig);
+ }
+}
+
+
+/**
+ * Function called to invoke @a cb on every non-revoked exchange signing key
+ * that has been signed by the master key. Revoked and (for signing!)
+ * expired keys are skipped. Runs in its own read-only transaction.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each signing key
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_active_signkeys (void *cls,
+ TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now = {0};
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct SignkeysIteratorContext dic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ };
+
+ PREPARE (pg,
+ "select_signkeys",
+ "SELECT"
+ " master_sig"
+ ",exchange_pub"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ " FROM exchange_sign_keys esk"
+ " WHERE"
+ " expire_sign > $1"
+ " AND NOT EXISTS "
+ " (SELECT esk_serial "
+ " FROM signkey_revocations skr"
+ " WHERE esk.esk_serial = skr.esk_serial);");
+ now = GNUNET_TIME_absolute_get ();
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "select_signkeys",
+ params,
+ &signkeys_cb_helper,
+ &dic);
+}
diff --git a/src/exchangedb/pg_iterate_active_signkeys.h b/src/exchangedb/pg_iterate_active_signkeys.h
new file mode 100644
index 000000000..5ebba9f5a
--- /dev/null
+++ b/src/exchangedb/pg_iterate_active_signkeys.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_active_signkeys.h
+ * @brief implementation of the iterate_active_signkeys function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_ACTIVE_SIGNKEYS_H
+#define PG_ITERATE_ACTIVE_SIGNKEYS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to invoke @a cb on every non-revoked exchange signing key
+ * that has been signed by the master key. Revoked and (for signing!)
+ * expired keys are skipped. Runs in its own read-only transaction.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each signing key
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_active_signkeys (void *cls,
+ TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_auditor_denominations.c b/src/exchangedb/pg_iterate_auditor_denominations.c
new file mode 100644
index 000000000..1fd4cdea6
--- /dev/null
+++ b/src/exchangedb/pg_iterate_auditor_denominations.c
@@ -0,0 +1,121 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_auditor_denominations.c
+ * @brief Implementation of the iterate_auditor_denominations function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_auditor_denominations.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #auditor_denoms_cb_helper()
+ */
+struct AuditorDenomsIteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_AuditorDenominationsCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_auditor_denominations().
+ * Calls the callback with each auditor and denomination pair.
+ *
+ * @param cls a `struct AuditorDenomsIteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+auditor_denoms_cb_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AuditorDenomsIteratorContext *dic = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_AuditorPublicKeyP auditor_pub;
+ struct TALER_DenominationHashP h_denom_pub;
+ struct TALER_AuditorSignatureP auditor_sig;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
+ &auditor_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &h_denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
+ &auditor_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ dic->cb (dic->cb_cls,
+ &auditor_pub,
+ &h_denom_pub,
+ &auditor_sig);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_auditor_denominations (
+ void *cls,
+ TALER_EXCHANGEDB_AuditorDenominationsCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct AuditorDenomsIteratorContext dic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ };
+ /* Used in #postgres_iterate_auditor_denominations() */
+ PREPARE (pg,
+ "select_auditor_denoms",
+ "SELECT"
+ " auditors.auditor_pub"
+ ",denominations.denom_pub_hash"
+ ",auditor_denom_sigs.auditor_sig"
+ " FROM auditor_denom_sigs"
+ " JOIN auditors USING (auditor_uuid)"
+ " JOIN denominations USING (denominations_serial)"
+ " WHERE auditors.is_active;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "select_auditor_denoms",
+ params,
+ &auditor_denoms_cb_helper,
+ &dic);
+}
diff --git a/src/exchangedb/pg_iterate_auditor_denominations.h b/src/exchangedb/pg_iterate_auditor_denominations.h
new file mode 100644
index 000000000..1278e8a9f
--- /dev/null
+++ b/src/exchangedb/pg_iterate_auditor_denominations.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_auditor_denominations.h
+ * @brief implementation of the iterate_auditor_denominations function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_AUDITOR_DENOMINATIONS_H
+#define PG_ITERATE_AUDITOR_DENOMINATIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to invoke @a cb on every denomination with an active
+ * auditor. Disabled auditors and denominations without auditor are
+ * skipped. Runs in its own read-only transaction.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each active auditor
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_auditor_denominations (
+ void *cls,
+ TALER_EXCHANGEDB_AuditorDenominationsCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_denomination_info.c b/src/exchangedb/pg_iterate_denomination_info.c
new file mode 100644
index 000000000..cab51d5ce
--- /dev/null
+++ b/src/exchangedb/pg_iterate_denomination_info.c
@@ -0,0 +1,180 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_denomination_info.c
+ * @brief Implementation of the iterate_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_denomination_info.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #domination_cb_helper()
+ */
+struct DenomIteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_DenominationCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_denomination_info().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct DenomIteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+domination_cb_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DenomIteratorContext *dic = cls;
+ struct PostgresClosure *pg = dic->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_DenominationKeyInformation issue;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_DenominationHashP denom_hash;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &issue.signature),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &denom_hash),
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &issue.start),
+ GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
+ &issue.expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp ("expire_deposit",
+ &issue.expire_deposit),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &issue.expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &issue.value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &issue.fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &issue.fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &issue.fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &issue.fees.refund),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_uint32 ("age_mask",
+ &issue.age_mask.bits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* Unfortunately we have to carry the age mask in both, the
+ * TALER_DenominationPublicKey and
+ * TALER_EXCHANGEDB_DenominationKeyInformation at different times.
+ * Here we use _both_ so let's make sure the values are the same. */
+ denom_pub.age_mask = issue.age_mask;
+ TALER_denom_pub_hash (&denom_pub,
+ &issue.denom_hash);
+ if (0 !=
+ GNUNET_memcmp (&issue.denom_hash,
+ &denom_hash))
+ {
+ GNUNET_break (0);
+ }
+ else
+ {
+ dic->cb (dic->cb_cls,
+ &denom_pub,
+ &issue);
+ }
+ TALER_denom_pub_free (&denom_pub);
+ }
+}
+
+
+/**
+ * Fetch information about all known denomination keys.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each denomination key
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_denomination_info (void *cls,
+ TALER_EXCHANGEDB_DenominationCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct DenomIteratorContext dic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "denomination_iterate",
+ "SELECT"
+ " master_sig"
+ ",denom_pub_hash"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin" /* value of this denom */
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",denom_pub"
+ ",age_mask"
+ " FROM denominations;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "denomination_iterate",
+ params,
+ &domination_cb_helper,
+ &dic);
+}
diff --git a/src/exchangedb/pg_iterate_denomination_info.h b/src/exchangedb/pg_iterate_denomination_info.h
new file mode 100644
index 000000000..27c08d0a9
--- /dev/null
+++ b/src/exchangedb/pg_iterate_denomination_info.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_denomination_info.h
+ * @brief implementation of the iterate_denomination_info function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_DENOMINATION_INFO_H
+#define PG_ITERATE_DENOMINATION_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Fetch information about all known denomination keys.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each denomination key
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_denomination_info (void *cls,
+ TALER_EXCHANGEDB_DenominationCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_denominations.c b/src/exchangedb/pg_iterate_denominations.c
new file mode 100644
index 000000000..684aa165a
--- /dev/null
+++ b/src/exchangedb/pg_iterate_denominations.c
@@ -0,0 +1,172 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_denominations.c
+ * @brief Implementation of the iterate_denominations function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_denominations.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #dominations_cb_helper()
+ */
+struct DenomsIteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_DenominationsCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_denominations().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct DenomsIteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+dominations_cb_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct DenomsIteratorContext *dic = cls;
+ struct PostgresClosure *pg = dic->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData meta = {0};
+ struct TALER_DenominationPublicKey denom_pub = {0};
+ struct TALER_MasterSignatureP master_sig = {0};
+ struct TALER_DenominationHashP h_denom_pub = {0};
+ bool revoked;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("denominations_serial",
+ &meta.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ &master_sig),
+ GNUNET_PQ_result_spec_bool ("revoked",
+ &revoked),
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta.start),
+ GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
+ &meta.expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp ("expire_deposit",
+ &meta.expire_deposit),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta.expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &meta.value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &meta.fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &meta.fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &meta.fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &meta.fees.refund),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_uint32 ("age_mask",
+ &meta.age_mask.bits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+
+ /* make sure the mask information is the same */
+ denom_pub.age_mask = meta.age_mask;
+
+ TALER_denom_pub_hash (&denom_pub,
+ &h_denom_pub);
+ dic->cb (dic->cb_cls,
+ &denom_pub,
+ &h_denom_pub,
+ &meta,
+ &master_sig,
+ revoked);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_denominations (void *cls,
+ TALER_EXCHANGEDB_DenominationsCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct DenomsIteratorContext dic = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "select_denominations",
+ "SELECT"
+ " denominations_serial"
+ ",denominations.master_sig"
+ ",denom_revocations_serial_id IS NOT NULL AS revoked"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin" /* value of this denom */
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",denom_type"
+ ",age_mask"
+ ",denom_pub"
+ " FROM denominations"
+ " LEFT JOIN "
+ " denomination_revocations USING (denominations_serial);");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "select_denominations",
+ params,
+ &dominations_cb_helper,
+ &dic);
+}
diff --git a/src/exchangedb/pg_iterate_denominations.h b/src/exchangedb/pg_iterate_denominations.h
new file mode 100644
index 000000000..9f59fc803
--- /dev/null
+++ b/src/exchangedb/pg_iterate_denominations.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_iterate_denominations.h
+ * @brief implementation of the iterate_denominations function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_DENOMINATIONS_H
+#define PG_ITERATE_DENOMINATIONS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to invoke @a cb on every known denomination key (revoked
+ * and non-revoked) that has been signed by the master key. Runs in its own
+ * read-only transaction.
+ *
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param cb function to call on each denomination key
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_denominations (void *cls,
+ TALER_EXCHANGEDB_DenominationsCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_kyc_reference.c b/src/exchangedb/pg_iterate_kyc_reference.c
new file mode 100644
index 000000000..772c51e2c
--- /dev/null
+++ b/src/exchangedb/pg_iterate_kyc_reference.c
@@ -0,0 +1,129 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_iterate_kyc_reference.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_iterate_kyc_reference.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #iterate_kyc_reference_cb()
+ */
+struct IteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_LegitimizationProcessCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_kyc_reference().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct IteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+iterate_kyc_reference_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct IteratorContext *ic = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ char *kyc_provider_section_name;
+ char *provider_user_id;
+ char *legitimization_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider_section",
+ &kyc_provider_section_name),
+ GNUNET_PQ_result_spec_string ("provider_user_id",
+ &provider_user_id),
+ GNUNET_PQ_result_spec_string ("provider_legitimization_id",
+ &legitimization_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ic->cb (ic->cb_cls,
+ kyc_provider_section_name,
+ provider_user_id,
+ legitimization_id);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_kyc_reference (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_LegitimizationProcessCallback lpc,
+ void *lpc_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct IteratorContext ic = {
+ .cb = lpc,
+ .cb_cls = lpc_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "iterate_kyc_reference",
+ "SELECT "
+ " provider_section"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ " FROM legitimization_processes"
+ " WHERE h_payto=$1;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "iterate_kyc_reference",
+ params,
+ &iterate_kyc_reference_cb,
+ &ic);
+}
diff --git a/src/exchangedb/pg_iterate_kyc_reference.h b/src/exchangedb/pg_iterate_kyc_reference.h
new file mode 100644
index 000000000..0242fdcf1
--- /dev/null
+++ b/src/exchangedb/pg_iterate_kyc_reference.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_iterate_kyc_reference.h
+ * @brief implementation of the iterate_kyc_reference function
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_KYC_REFERENCE_H
+#define PG_ITERATE_KYC_REFERENCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Call us on KYC legitimization processes satisfied and not expired for the
+ * given account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param lpc function to call for each satisfied KYC legitimization process
+ * @param lpc_cls closure for @a lpc
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_kyc_reference (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_LegitimizationProcessCallback lpc,
+ void *lpc_cls);
+
+#endif
diff --git a/src/exchangedb/pg_iterate_reserve_close_info.c b/src/exchangedb/pg_iterate_reserve_close_info.c
new file mode 100644
index 000000000..ff0a813c3
--- /dev/null
+++ b/src/exchangedb/pg_iterate_reserve_close_info.c
@@ -0,0 +1,128 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_iterate_reserve_close_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_insert_reserve_open_deposit.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #iterate_reserve_close_info_cb()
+ */
+struct IteratorContext
+{
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_KycAmountCallback cb;
+
+ /**
+ * Closure to pass to @e cb
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_iterate_reserve_close_info().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct IteratorContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+iterate_reserve_close_info_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct IteratorContext *ic = cls;
+ struct PostgresClosure *pg = ic->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount;
+ struct GNUNET_TIME_Absolute ts;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_absolute_time ("execution_date",
+ &ts),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ic->cb (ic->cb_cls,
+ &amount,
+ ts);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_reserve_close_info (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct IteratorContext ic = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "iterate_reserve_close_info",
+ "SELECT"
+ " amount"
+ ",execution_date"
+ " FROM reserves_close"
+ " WHERE wire_target_h_payto=$1"
+ " AND execution_date >= $2"
+ " ORDER BY execution_date DESC");
+ return GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "iterate_reserve_close_info",
+ params,
+ &iterate_reserve_close_info_cb,
+ &ic);
+}
diff --git a/src/exchangedb/pg_iterate_reserve_close_info.h b/src/exchangedb/pg_iterate_reserve_close_info.h
new file mode 100644
index 000000000..34692e656
--- /dev/null
+++ b/src/exchangedb/pg_iterate_reserve_close_info.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_iterate_reserve_close_info.h
+ * @brief implementation of the iterate_reserve_close_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_ITERATE_RESERVE_CLOSE_INFO_H
+#define PG_ITERATE_RESERVE_CLOSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select information needed for KYC checks on reserve close: historic
+ * reserve closures going to the same account.
+ *
+ * @param cls closure
+ * @param h_payto which target account is this about?
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_iterate_reserve_close_info (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_kyc_provider_account_lookup.c b/src/exchangedb/pg_kyc_provider_account_lookup.c
new file mode 100644
index 000000000..f9db2cbc1
--- /dev/null
+++ b/src/exchangedb/pg_kyc_provider_account_lookup.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_kyc_provider_account_lookup.c
+ * @brief Implementation of the kyc_provider_account_lookup function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_kyc_provider_account_lookup.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_kyc_provider_account_lookup (
+ void *cls,
+ const char *provider_section,
+ const char *provider_legitimization_id,
+ struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (provider_legitimization_id),
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_wire_target_by_legitimization_id",
+ "SELECT "
+ " h_payto"
+ ",legitimization_process_serial_id"
+ " FROM legitimization_processes"
+ " WHERE provider_legitimization_id=$1"
+ " AND provider_section=$2;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "get_wire_target_by_legitimization_id",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_kyc_provider_account_lookup.h b/src/exchangedb/pg_kyc_provider_account_lookup.h
new file mode 100644
index 000000000..74f90d88d
--- /dev/null
+++ b/src/exchangedb/pg_kyc_provider_account_lookup.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_kyc_provider_account_lookup.h
+ * @brief implementation of the kyc_provider_account_lookup function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_KYC_PROVIDER_ACCOUNT_LOOKUP_H
+#define PG_KYC_PROVIDER_ACCOUNT_LOOKUP_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup an
+ * @a h_payto by @a provider_legitimization_id.
+ *
+ * @param cls closure
+ * @param provider_section
+ * @param provider_legitimization_id legi to look up
+ * @param[out] h_payto where to write the result
+ * @param[out] process_row where to write the row of the entry
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_kyc_provider_account_lookup (
+ void *cls,
+ const char *provider_section,
+ const char *provider_legitimization_id,
+ struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_aml_officer.c b/src/exchangedb/pg_lookup_aml_officer.c
new file mode 100644
index 000000000..c18e47eaf
--- /dev/null
+++ b/src/exchangedb/pg_lookup_aml_officer.c
@@ -0,0 +1,71 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_aml_officer.c
+ * @brief Implementation of the lookup_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_aml_officer.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ struct TALER_MasterSignatureP *master_sig,
+ char **decider_name,
+ bool *is_active,
+ bool *read_only,
+ struct GNUNET_TIME_Absolute *last_change)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_string ("decider_name",
+ decider_name),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ is_active),
+ GNUNET_PQ_result_spec_bool ("read_only",
+ read_only),
+ GNUNET_PQ_result_spec_absolute_time ("last_change",
+ last_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "lookup_aml_officer",
+ "SELECT "
+ " master_sig"
+ ",decider_name"
+ ",is_active"
+ ",read_only"
+ ",last_change"
+ " FROM aml_staff"
+ " WHERE decider_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_aml_officer",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_aml_officer.h b/src/exchangedb/pg_lookup_aml_officer.h
new file mode 100644
index 000000000..161d2e7e7
--- /dev/null
+++ b/src/exchangedb/pg_lookup_aml_officer.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_aml_officer.h
+ * @brief implementation of the lookup_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_AML_OFFICER_H
+#define PG_LOOKUP_AML_OFFICER_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Fetch AML staff record.
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @param[out] master_sig offline signature affirming the AML officer
+ * @param[out] decider_name full name of the staff member
+ * @param[out] is_active true to enable, false to set as inactive
+ * @param[out] read_only true to set read-only access
+ * @param[out] last_change when was the change made effective
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ struct TALER_MasterSignatureP *master_sig,
+ char **decider_name,
+ bool *is_active,
+ bool *read_only,
+ struct GNUNET_TIME_Absolute *last_change);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_auditor_status.c b/src/exchangedb/pg_lookup_auditor_status.c
new file mode 100644
index 000000000..91afe6eaa
--- /dev/null
+++ b/src/exchangedb/pg_lookup_auditor_status.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_auditor_status.c
+ * @brief Implementation of the lookup_auditor_status function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_auditor_status.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_auditor_status (
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ char **auditor_url,
+ bool *enabled)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("auditor_url",
+ auditor_url),
+ GNUNET_PQ_result_spec_bool ("is_active",
+ enabled),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_lookup_auditor_status() */
+ PREPARE (pg,
+ "lookup_auditor_status",
+ "SELECT"
+ " auditor_url"
+ ",is_active"
+ " FROM auditors"
+ " WHERE auditor_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_auditor_status",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_auditor_status.h b/src/exchangedb/pg_lookup_auditor_status.h
new file mode 100644
index 000000000..b75788e11
--- /dev/null
+++ b/src/exchangedb/pg_lookup_auditor_status.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_auditor_status.h
+ * @brief implementation of the lookup_auditor_status function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_AUDITOR_STATUS_H
+#define PG_LOOKUP_AUDITOR_STATUS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Lookup current state of an auditor.
+ *
+ * @param cls closure
+ * @param auditor_pub key to look up information for
+ * @param[out] auditor_url set to the base URL of the auditor's REST API; memory to be
+ * released by the caller!
+ * @param[out] enabled set if the auditor is currently in use
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_auditor_status (
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ char **auditor_url,
+ bool *enabled);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_auditor_timestamp.c b/src/exchangedb/pg_lookup_auditor_timestamp.c
new file mode 100644
index 000000000..eb85876fe
--- /dev/null
+++ b/src/exchangedb/pg_lookup_auditor_timestamp.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_auditor_timestamp.c
+ * @brief Implementation of the lookup_auditor_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_auditor_timestamp.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_auditor_timestamp (
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct GNUNET_TIME_Timestamp *last_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("last_change",
+ last_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_lookup_auditor_timestamp() */
+ PREPARE (pg,
+ "lookup_auditor_timestamp",
+ "SELECT"
+ " last_change"
+ " FROM auditors"
+ " WHERE auditor_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_auditor_timestamp",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_auditor_timestamp.h b/src/exchangedb/pg_lookup_auditor_timestamp.h
new file mode 100644
index 000000000..5674ba225
--- /dev/null
+++ b/src/exchangedb/pg_lookup_auditor_timestamp.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_auditor_timestamp.h
+ * @brief implementation of the lookup_auditor_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_AUDITOR_TIMESTAMP_H
+#define PG_LOOKUP_AUDITOR_TIMESTAMP_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Check the last date an auditor was modified.
+ *
+ * @param cls closure
+ * @param auditor_pub key to look up information for
+ * @param[out] last_date last modification date to auditor status
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_auditor_timestamp (
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct GNUNET_TIME_Timestamp *last_date);
+#endif
diff --git a/src/exchangedb/pg_lookup_denomination_key.c b/src/exchangedb/pg_lookup_denomination_key.c
new file mode 100644
index 000000000..a358528ad
--- /dev/null
+++ b/src/exchangedb/pg_lookup_denomination_key.c
@@ -0,0 +1,82 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_denomination_key.c
+ * @brief Implementation of the lookup_denomination_key function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_denomination_key.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_denomination_key (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta->start),
+ GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
+ &meta->expire_withdraw),
+ GNUNET_PQ_result_spec_timestamp ("expire_deposit",
+ &meta->expire_deposit),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta->expire_legal),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
+ &meta->value),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
+ &meta->fees.withdraw),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &meta->fees.deposit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
+ &meta->fees.refresh),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
+ &meta->fees.refund),
+ GNUNET_PQ_result_spec_uint32 ("age_mask",
+ &meta->age_mask.bits),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "lookup_denomination_key",
+ "SELECT"
+ " valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin"
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_denomination_key",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_denomination_key.h b/src/exchangedb/pg_lookup_denomination_key.h
new file mode 100644
index 000000000..b7317ac4a
--- /dev/null
+++ b/src/exchangedb/pg_lookup_denomination_key.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_denomination_key.h
+ * @brief implementation of the lookup_denomination_key function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_DENOMINATION_KEY_H
+#define PG_LOOKUP_DENOMINATION_KEY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Lookup information about current denomination key.
+ *
+ * @param cls closure
+ * @param h_denom_pub hash of the denomination public key
+ * @param[out] meta set to various meta data about the key
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_denomination_key (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_global_fee_by_time.c b/src/exchangedb/pg_lookup_global_fee_by_time.c
new file mode 100644
index 000000000..c3a6ec8b7
--- /dev/null
+++ b/src/exchangedb/pg_lookup_global_fee_by_time.c
@@ -0,0 +1,182 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_global_fee_by_time.c
+ * @brief Implementation of the lookup_global_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_global_fee_by_time.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #global_fee_by_time_helper()
+ */
+struct GlobalFeeLookupContext
+{
+
+ /**
+ * Set to the wire fees. Set to invalid if fees conflict over
+ * the given time period.
+ */
+ struct TALER_GlobalFeeSet *fees;
+
+ /**
+ * Set to timeout of unmerged purses
+ */
+ struct GNUNET_TIME_Relative *purse_timeout;
+
+ /**
+ * Set to history expiration for reserves.
+ */
+ struct GNUNET_TIME_Relative *history_expiration;
+
+ /**
+ * Set to number of free purses per account.
+ */
+ uint32_t *purse_account_limit;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_lookup_global_fee_by_time().
+ * Calls the callback with each denomination key.
+ *
+ * @param cls a `struct GlobalFeeLookupContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+global_fee_by_time_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GlobalFeeLookupContext *wlc = cls;
+ struct PostgresClosure *pg = wlc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_GlobalFeeSet fs;
+ struct GNUNET_TIME_Relative purse_timeout;
+ struct GNUNET_TIME_Relative history_expiration;
+ uint32_t purse_account_limit;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
+ &fs.history),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
+ &fs.account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &fs.purse),
+ GNUNET_PQ_result_spec_relative_time ("purse_timeout",
+ &purse_timeout),
+ GNUNET_PQ_result_spec_relative_time ("history_expiration",
+ &history_expiration),
+ GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
+ &purse_account_limit),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_GlobalFeeSet));
+ return;
+ }
+ if (0 == i)
+ {
+ *wlc->fees = fs;
+ *wlc->purse_timeout = purse_timeout;
+ *wlc->history_expiration = history_expiration;
+ *wlc->purse_account_limit = purse_account_limit;
+ continue;
+ }
+ if ( (0 !=
+ TALER_global_fee_set_cmp (&fs,
+ wlc->fees)) ||
+ (purse_account_limit != *wlc->purse_account_limit) ||
+ (GNUNET_TIME_relative_cmp (purse_timeout,
+ !=,
+ *wlc->purse_timeout)) ||
+ (GNUNET_TIME_relative_cmp (history_expiration,
+ !=,
+ *wlc->history_expiration)) )
+ {
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_GlobalFeeSet));
+ return;
+ }
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_global_fee_by_time (
+ void *cls,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *purse_timeout,
+ struct GNUNET_TIME_Relative *history_expiration,
+ uint32_t *purse_account_limit)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&start_time),
+ GNUNET_PQ_query_param_timestamp (&end_time),
+ GNUNET_PQ_query_param_end
+ };
+ struct GlobalFeeLookupContext wlc = {
+ .fees = fees,
+ .purse_timeout = purse_timeout,
+ .history_expiration = history_expiration,
+ .purse_account_limit = purse_account_limit,
+ .pg = pg
+ };
+
+ PREPARE (pg,
+ "lookup_global_fee_by_time",
+ "SELECT"
+ " history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ " FROM global_fee"
+ " WHERE end_date > $1"
+ " AND start_date < $2;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_global_fee_by_time",
+ params,
+ &global_fee_by_time_helper,
+ &wlc);
+}
diff --git a/src/exchangedb/pg_lookup_global_fee_by_time.h b/src/exchangedb/pg_lookup_global_fee_by_time.h
new file mode 100644
index 000000000..c5ff95fc6
--- /dev/null
+++ b/src/exchangedb/pg_lookup_global_fee_by_time.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_global_fee_by_time.h
+ * @brief implementation of the lookup_global_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_GLOBAL_FEE_BY_TIME_H
+#define PG_LOOKUP_GLOBAL_FEE_BY_TIME_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Lookup information about known global fees.
+ *
+ * @param cls closure
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees set to wire fees for that time period; if
+ * different global fee exists within this time
+ * period, an 'invalid' amount is returned.
+ * @param[out] purse_timeout set to when unmerged purses expire
+ * @param[out] history_expiration set to when we expire reserve histories
+ * @param[out] purse_account_limit set to number of free purses
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_global_fee_by_time (
+ void *cls,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_GlobalFeeSet *fees,
+ struct GNUNET_TIME_Relative *purse_timeout,
+ struct GNUNET_TIME_Relative *history_expiration,
+ uint32_t *purse_account_limit);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_kyc_process_by_account.c b/src/exchangedb/pg_lookup_kyc_process_by_account.c
new file mode 100644
index 000000000..b077661c5
--- /dev/null
+++ b/src/exchangedb/pg_lookup_kyc_process_by_account.c
@@ -0,0 +1,83 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_kyc_process_by_account.c
+ * @brief Implementation of the lookup_kyc_process_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_kyc_process_by_account.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_kyc_process_by_account (
+ void *cls,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row,
+ struct GNUNET_TIME_Absolute *expiration,
+ char **provider_account_id,
+ char **provider_legitimization_id)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("legitimization_process_serial_id",
+ process_row),
+ GNUNET_PQ_result_spec_absolute_time ("expiration_time",
+ expiration),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("provider_user_id",
+ provider_account_id),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("provider_legitimization_id",
+ provider_legitimization_id),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *provider_account_id = NULL;
+ *provider_legitimization_id = NULL;
+ PREPARE (pg,
+ "lookup_process_by_account",
+ "SELECT "
+ " legitimization_process_serial_id"
+ ",expiration_time"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ " FROM legitimization_processes"
+ " WHERE h_payto=$1"
+ " AND provider_section=$2"
+ " AND NOT finished"
+ /* Note: there *should* only be one unfinished
+ match, so this is just to be safe(r): */
+ " ORDER BY expiration_time DESC"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "lookup_process_by_account",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_kyc_process_by_account.h b/src/exchangedb/pg_lookup_kyc_process_by_account.h
new file mode 100644
index 000000000..0300b498c
--- /dev/null
+++ b/src/exchangedb/pg_lookup_kyc_process_by_account.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_kyc_process_by_account.h
+ * @brief implementation of the lookup_kyc_process_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_KYC_PROCESS_BY_ACCOUNT_H
+#define PG_LOOKUP_KYC_PROCESS_BY_ACCOUNT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup KYC provider meta data.
+ *
+ * @param cls closure
+ * @param provider_section provider that must be checked
+ * @param h_payto account that must be KYC'ed
+ * @param[out] process_row row with the legitimization data
+ * @param[out] expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @param[out] provider_account_id provider account ID
+ * @param[out] provider_legitimization_id provider legitimization ID
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_kyc_process_by_account (
+ void *cls,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row,
+ struct GNUNET_TIME_Absolute *expiration,
+ char **provider_account_id,
+ char **provider_legitimization_id);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_kyc_requirement_by_row.c b/src/exchangedb/pg_lookup_kyc_requirement_by_row.c
new file mode 100644
index 000000000..6f9d76786
--- /dev/null
+++ b/src/exchangedb/pg_lookup_kyc_requirement_by_row.c
@@ -0,0 +1,71 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_kyc_requirement_by_row.c
+ * @brief Implementation of the lookup_kyc_requirement_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_kyc_requirement_by_row.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_kyc_requirement_by_row (
+ void *cls,
+ uint64_t requirement_row,
+ char **requirements,
+ enum TALER_AmlDecisionState *aml_status,
+ struct TALER_PaytoHashP *h_payto)
+{
+ struct PostgresClosure *pg = cls;
+ uint32_t status = TALER_AML_NORMAL;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&requirement_row),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("required_checks",
+ requirements),
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("status",
+ &status),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "lookup_legitimization_requirement_by_row",
+ "SELECT "
+ " lr.required_checks"
+ ",lr.h_payto"
+ ",aml.status"
+ " FROM legitimization_requirements lr"
+ " LEFT JOIN aml_status aml USING (h_payto)"
+ " WHERE legitimization_requirement_serial_id=$1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "lookup_legitimization_requirement_by_row",
+ params,
+ rs);
+ *aml_status = (enum TALER_AmlDecisionState) status;
+ return qs;
+}
diff --git a/src/exchangedb/pg_lookup_kyc_requirement_by_row.h b/src/exchangedb/pg_lookup_kyc_requirement_by_row.h
new file mode 100644
index 000000000..3d223c985
--- /dev/null
+++ b/src/exchangedb/pg_lookup_kyc_requirement_by_row.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_kyc_requirement_by_row.h
+ * @brief implementation of the lookup_kyc_requirement_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_KYC_REQUIREMENT_BY_ROW_H
+#define PG_LOOKUP_KYC_REQUIREMENT_BY_ROW_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup KYC requirement.
+ *
+ * @param cls closure
+ * @param requirement_row identifies requirement to look up
+ * @param[out] requirements provider that must be checked
+ * @param[out] aml_status set to the AML status of the account
+ * @param[out] h_payto account that must be KYC'ed
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_kyc_requirement_by_row (
+ void *cls,
+ uint64_t requirement_row,
+ char **requirements,
+ enum TALER_AmlDecisionState *aml_status,
+ struct TALER_PaytoHashP *h_payto);
+
+#endif
diff --git a/src/exchangedb/lrbt_callbacks.c b/src/exchangedb/pg_lookup_records_by_table.c
index b8ab49cf1..fc4af32a8 100644
--- a/src/exchangedb/lrbt_callbacks.c
+++ b/src/exchangedb/pg_lookup_records_by_table.c
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet
- Copyright (C) 2020, 2021, 2022 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
GNUnet is free software: you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published
@@ -18,11 +18,45 @@
SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
- * @file exchangedb/lrbt_callbacks.c
- * @brief callbacks used by postgres_lookup_records_by_table, to be
- * inlined into the plugin
+ * @file exchangedb/pg_lookup_records_by_table.c
+ * @brief implementation of lookup_records_by_table
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_records_by_table.h"
+#include "pg_helper.h"
+#include <gnunet/gnunet_pq_lib.h>
+
+
+/**
+ * Closure for callbacks used by #postgres_lookup_records_by_table.
+ */
+struct LookupRecordsByTableContext
+{
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Function to call with the results.
+ */
+ TALER_EXCHANGEDB_ReplicationCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Set to true on errors.
+ */
+ bool error;
+};
/**
@@ -175,18 +209,119 @@ lrbt_cb_table_wire_targets (void *cls,
for (unsigned int i = 0; i<num_results; i++)
{
- bool no_xid;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 ("serial",
&td.serial),
GNUNET_PQ_result_spec_string ("payto_uri",
&td.details.wire_targets.payto_uri),
- GNUNET_PQ_result_spec_auto_from_type ("kyc_ok",
- &td.details.wire_targets.kyc_ok),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with legitimization_processes table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_legitimization_processes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.legitimization_processes.h_payto),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_time",
+ &td.details.legitimization_processes.expiration_time),
+ GNUNET_PQ_result_spec_string (
+ "provider_section",
+ &td.details.legitimization_processes.provider_section),
+ GNUNET_PQ_result_spec_string (
+ "provider_user_id",
+ &td.details.legitimization_processes.provider_user_id),
+ GNUNET_PQ_result_spec_string (
+ "provider_legitimization_id",
+ &td.details.legitimization_processes.provider_legitimization_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with legitimization_requirements table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_legitimization_requirements (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.legitimization_requirements.h_payto),
GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("external_id",
- &td.details.wire_targets.external_id),
- &no_xid),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.legitimization_requirements.reserve_pub),
+ &td.details.legitimization_requirements.no_reserve_pub),
+ GNUNET_PQ_result_spec_string (
+ "required_checks",
+ &td.details.legitimization_requirements.required_checks),
GNUNET_PQ_result_spec_end
};
@@ -376,6 +511,123 @@ lrbt_cb_table_reserves_close (void *cls,
/**
+ * Function called with reserves_open_requests table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_open_requests (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_open_requests.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "request_timestamp",
+ &td.details.reserves_open_requests.request_timestamp),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_date",
+ &td.details.reserves_open_requests.expiration_date),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.reserves_open_requests.reserve_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "reserve_payment",
+ &td.details.reserves_open_requests.reserve_payment),
+ GNUNET_PQ_result_spec_uint32 (
+ "requested_purse_limit",
+ &td.details.reserves_open_requests.requested_purse_limit),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with reserves_open_deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_reserves_open_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.reserves_open_deposits.reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.reserves_open_deposits.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.reserves_open_deposits.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.reserves_open_deposits.coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "contribution",
+ &td.details.reserves_open_deposits.contribution),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
* Function called with reserves_out table entries.
*
* @param cls closure
@@ -872,9 +1124,9 @@ lrbt_cb_table_refresh_transfer_keys (void *cls,
ctx->error = true;
return;
}
- memcpy (&td.details.refresh_transfer_keys.tprivs[0],
- tpriv,
- tpriv_size);
+ GNUNET_memcpy (&td.details.refresh_transfer_keys.tprivs[0],
+ tpriv,
+ tpriv_size);
ctx->cb (ctx->cb_cls,
&td);
GNUNET_PQ_cleanup_result (rs);
@@ -883,77 +1135,124 @@ lrbt_cb_table_refresh_transfer_keys (void *cls,
/**
- * Function called with deposits table entries.
+ * Function called with batch deposits table entries.
*
* @param cls closure
* @param result the postgres result
* @param num_results the number of results in @a result
*/
static void
-lrbt_cb_table_deposits (void *cls,
- PGresult *result,
- unsigned int num_results)
+lrbt_cb_table_batch_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
{
struct LookupRecordsByTableContext *ctx = cls;
- struct PostgresClosure *pg = ctx->pg;
struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_DEPOSITS
+ .table = TALER_EXCHANGEDB_RT_BATCH_DEPOSITS
};
for (unsigned int i = 0; i<num_results; i++)
{
- bool no_extension;
struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_uint64 (
"serial",
&td.serial),
GNUNET_PQ_result_spec_uint64 (
"shard",
- &td.details.deposits.shard),
- GNUNET_PQ_result_spec_uint64 (
- "known_coin_id",
- &td.details.deposits.known_coin_id),
+ &td.details.batch_deposits.shard),
GNUNET_PQ_result_spec_auto_from_type (
- "coin_pub",
- &td.details.deposits.coin_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT (
- "amount_with_fee",
- &td.details.deposits.amount_with_fee),
+ "merchant_pub",
+ &td.details.batch_deposits.merchant_pub),
GNUNET_PQ_result_spec_timestamp (
"wallet_timestamp",
- &td.details.deposits.wallet_timestamp),
+ &td.details.batch_deposits.wallet_timestamp),
GNUNET_PQ_result_spec_timestamp (
"exchange_timestamp",
- &td.details.deposits.exchange_timestamp),
+ &td.details.batch_deposits.exchange_timestamp),
GNUNET_PQ_result_spec_timestamp (
"refund_deadline",
- &td.details.deposits.refund_deadline),
+ &td.details.batch_deposits.refund_deadline),
GNUNET_PQ_result_spec_timestamp (
"wire_deadline",
- &td.details.deposits.wire_deadline),
- GNUNET_PQ_result_spec_auto_from_type (
- "merchant_pub",
- &td.details.deposits.merchant_pub),
+ &td.details.batch_deposits.wire_deadline),
GNUNET_PQ_result_spec_auto_from_type (
"h_contract_terms",
- &td.details.deposits.h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type (
- "coin_sig",
- &td.details.deposits.coin_sig),
+ &td.details.batch_deposits.h_contract_terms),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wallet_data_hash",
+ &td.details.batch_deposits.wallet_data_hash),
+ &td.details.batch_deposits.no_wallet_data_hash),
GNUNET_PQ_result_spec_auto_from_type (
"wire_salt",
- &td.details.deposits.wire_salt),
+ &td.details.batch_deposits.wire_salt),
GNUNET_PQ_result_spec_auto_from_type (
"wire_target_h_payto",
- &td.details.deposits.wire_target_h_payto),
+ &td.details.batch_deposits.wire_target_h_payto),
GNUNET_PQ_result_spec_auto_from_type (
- "extension_blocked",
- &td.details.deposits.extension_blocked),
+ "policy_blocked",
+ &td.details.batch_deposits.policy_blocked),
GNUNET_PQ_result_spec_allow_null (
GNUNET_PQ_result_spec_uint64 (
- "extension_details_serial_id",
- &td.details.deposits.extension_details_serial_id),
- &no_extension),
+ "policy_details_serial_id",
+ &td.details.batch_deposits.policy_details_serial_id),
+ &td.details.batch_deposits.no_policy_details),
+ GNUNET_PQ_result_spec_end
+ };
+
+ td.details.batch_deposits.policy_details_serial_id = 0;
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with coin deposits table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_coin_deposits (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_COIN_DEPOSITS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "serial",
+ &td.serial),
+ GNUNET_PQ_result_spec_uint64 (
+ "batch_deposit_serial_id",
+ &td.details.coin_deposits.batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_pub",
+ &td.details.coin_deposits.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "coin_sig",
+ &td.details.coin_deposits.coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.coin_deposits.amount_with_fee),
GNUNET_PQ_result_spec_end
};
@@ -1010,8 +1309,8 @@ lrbt_cb_table_refunds (void *cls,
"amount_with_fee",
&td.details.refunds.amount_with_fee),
GNUNET_PQ_result_spec_uint64 (
- "deposit_serial_id",
- &td.details.refunds.deposit_serial_id),
+ "batch_deposit_serial_id",
+ &td.details.refunds.batch_deposit_serial_id),
GNUNET_PQ_result_spec_end
};
@@ -1112,8 +1411,8 @@ lrbt_cb_table_aggregation_tracking (void *cls,
"serial",
&td.serial),
GNUNET_PQ_result_spec_uint64 (
- "deposit_serial_id",
- &td.details.aggregation_tracking.deposit_serial_id),
+ "batch_deposit_serial_id",
+ &td.details.aggregation_tracking.batch_deposit_serial_id),
GNUNET_PQ_result_spec_auto_from_type (
"wtid_raw",
&td.details.aggregation_tracking.wtid_raw),
@@ -1169,8 +1468,6 @@ lrbt_cb_table_wire_fee (void *cls,
&td.details.wire_fee.fees.wire),
TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
&td.details.wire_fee.fees.closing),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wad_fee",
- &td.details.wire_fee.fees.wad),
GNUNET_PQ_result_spec_auto_from_type ("master_sig",
&td.details.wire_fee.master_sig),
GNUNET_PQ_result_spec_end
@@ -1226,9 +1523,6 @@ lrbt_cb_table_global_fee (void *cls,
"history_fee",
&td.details.global_fee.fees.history),
TALER_PQ_RESULT_SPEC_AMOUNT (
- "kyc_fee",
- &td.details.global_fee.fees.kyc),
- TALER_PQ_RESULT_SPEC_AMOUNT (
"account_fee",
&td.details.global_fee.fees.account),
TALER_PQ_RESULT_SPEC_AMOUNT (
@@ -1238,9 +1532,6 @@ lrbt_cb_table_global_fee (void *cls,
"purse_timeout",
&td.details.global_fee.purse_timeout),
GNUNET_PQ_result_spec_relative_time (
- "kyc_timeout",
- &td.details.global_fee.kyc_timeout),
- GNUNET_PQ_result_spec_relative_time (
"history_expiration",
&td.details.global_fee.history_expiration),
GNUNET_PQ_result_spec_uint32 (
@@ -1397,7 +1688,7 @@ lrbt_cb_table_extensions (void *cls,
struct TALER_EXCHANGEDB_TableData td = {
.table = TALER_EXCHANGEDB_RT_EXTENSIONS
};
- bool no_config = false;
+ bool no_manifest = false;
for (unsigned int i = 0; i<num_results; i++)
{
@@ -1407,9 +1698,82 @@ lrbt_cb_table_extensions (void *cls,
GNUNET_PQ_result_spec_string ("name",
&td.details.extensions.name),
GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("config",
- &td.details.extensions.config),
- &no_config),
+ GNUNET_PQ_result_spec_string ("manifest",
+ &td.details.extensions.manifest),
+ &no_manifest),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with policy_details table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_policy_details (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_POLICY_DETAILS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("policy_details_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type ("hash_code",
+ &td.details.policy_details.
+ hash_code),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_result_spec_json ("policy_json",
+ &td.details.policy_details.
+ policy_json),
+ &td.details.policy_details.no_policy_json),
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &td.details.policy_details.
+ deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("commitment",
+ &td.details.policy_details.
+ commitment),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("accumulated_total",
+ &td.details.policy_details.
+ accumulated_total),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee",
+ &td.details.policy_details.
+ fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("transferable",
+ &td.details.policy_details.
+ transferable),
+ GNUNET_PQ_result_spec_uint16 ("fulfillment_state",
+ &td.details.policy_details.
+ fulfillment_state),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("fulfillment_id",
+ &td.details.policy_details.
+ fulfillment_id),
+ &td.details.policy_details.no_fulfillment_id),
GNUNET_PQ_result_spec_end
};
@@ -1430,33 +1794,39 @@ lrbt_cb_table_extensions (void *cls,
/**
- * Function called with extension_details table entries.
+ * Function called with policy_fulfillments table entries.
*
* @param cls closure
* @param result the postgres result
* @param num_results the number of results in @a result
*/
static void
-lrbt_cb_table_extension_details (void *cls,
- PGresult *result,
- unsigned int num_results)
+lrbt_cb_table_policy_fulfillments (void *cls,
+ PGresult *result,
+ unsigned int num_results)
{
struct LookupRecordsByTableContext *ctx = cls;
struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_EXTENSION_DETAILS
+ .table = TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS
};
for (unsigned int i = 0; i<num_results; i++)
{
- bool no_config = false;
+ bool no_proof = false;
+ bool no_timestamp = false;
struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("extension_details_serial_id",
+ GNUNET_PQ_result_spec_uint64 ("fulfillment_id",
&td.serial),
GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("extension_options",
- &td.details.extension_details.
- extension_options),
- &no_config),
+ GNUNET_PQ_result_spec_timestamp ("fulfillment_timestamp",
+ &td.details.policy_fulfillments.
+ fulfillment_timestamp),
+ &no_timestamp),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("fulfillment_proof",
+ &td.details.policy_fulfillments.
+ fulfillment_proof),
+ &no_proof),
GNUNET_PQ_result_spec_end
};
@@ -1550,20 +1920,20 @@ lrbt_cb_table_purse_requests (void *cls,
/**
- * Function called with purse_refunds table entries.
+ * Function called with purse_decision table entries.
*
* @param cls closure
* @param result the postgres result
* @param num_results the number of results in @a result
*/
static void
-lrbt_cb_table_purse_refunds (void *cls,
- PGresult *result,
- unsigned int num_results)
+lrbt_cb_table_purse_decision (void *cls,
+ PGresult *result,
+ unsigned int num_results)
{
struct LookupRecordsByTableContext *ctx = cls;
struct TALER_EXCHANGEDB_TableData td = {
- .table = TALER_EXCHANGEDB_RT_PURSE_REFUNDS
+ .table = TALER_EXCHANGEDB_RT_PURSE_DECISION
};
for (unsigned int i = 0; i<num_results; i++)
@@ -1574,7 +1944,13 @@ lrbt_cb_table_purse_refunds (void *cls,
&td.serial),
GNUNET_PQ_result_spec_auto_from_type (
"purse_pub",
- &td.details.purse_refunds.purse_pub),
+ &td.details.purse_decision.purse_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "action_timestamp",
+ &td.details.purse_decision.action_timestamp),
+ GNUNET_PQ_result_spec_bool (
+ "refunded",
+ &td.details.purse_decision.refunded),
GNUNET_PQ_result_spec_end
};
@@ -1741,6 +2117,9 @@ lrbt_cb_table_account_merges (void *cls,
GNUNET_PQ_result_spec_auto_from_type (
"purse_pub",
&td.details.account_merges.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wallet_h_payto",
+ &td.details.account_merges.wallet_h_payto),
GNUNET_PQ_result_spec_end
};
@@ -1839,12 +2218,21 @@ lrbt_cb_table_close_requests (void *cls,
GNUNET_PQ_result_spec_auto_from_type (
"reserve_pub",
&td.details.close_requests.reserve_pub),
+ GNUNET_PQ_result_spec_timestamp (
+ "close_timestamp",
+ &td.details.close_requests.close_timestamp),
GNUNET_PQ_result_spec_auto_from_type (
"reserve_sig",
&td.details.close_requests.reserve_sig),
TALER_PQ_RESULT_SPEC_AMOUNT (
"close",
&td.details.close_requests.close),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "close_fee",
+ &td.details.close_requests.close_fee),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &td.details.close_requests.payto_uri),
GNUNET_PQ_result_spec_end
};
@@ -2120,4 +2508,1100 @@ lrbt_cb_table_wads_in_entries (void *cls,
}
-/* end of lrbt_callbacks.c */
+/**
+ * Function called with profit_drains table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_profit_drains (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PROFIT_DRAINS
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "profit_drain_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "wtid",
+ &td.details.profit_drains.wtid),
+ GNUNET_PQ_result_spec_string (
+ "account_section",
+ &td.details.profit_drains.account_section),
+ GNUNET_PQ_result_spec_string (
+ "payto_uri",
+ &td.details.profit_drains.payto_uri),
+ GNUNET_PQ_result_spec_timestamp (
+ "trigger_date",
+ &td.details.profit_drains.trigger_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount",
+ &td.details.profit_drains.amount),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.profit_drains.master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with aml_staff table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_aml_staff (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AML_STAFF
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "aml_staff_uuid",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_pub",
+ &td.details.aml_staff.decider_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "master_sig",
+ &td.details.aml_staff.master_sig),
+ GNUNET_PQ_result_spec_string (
+ "decider_name",
+ &td.details.aml_staff.decider_name),
+ GNUNET_PQ_result_spec_bool (
+ "is_active",
+ &td.details.aml_staff.is_active),
+ GNUNET_PQ_result_spec_bool (
+ "read_only",
+ &td.details.aml_staff.read_only),
+ GNUNET_PQ_result_spec_timestamp (
+ "last_change",
+ &td.details.aml_staff.last_change),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with aml_history table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_aml_history (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AML_HISTORY
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint32_t status32;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "aml_history_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.aml_history.h_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "new_threshold",
+ &td.details.aml_history.new_threshold),
+ GNUNET_PQ_result_spec_uint32 (
+ "new_status",
+ &status32),
+ GNUNET_PQ_result_spec_timestamp (
+ "decision_time",
+ &td.details.aml_history.decision_time),
+ GNUNET_PQ_result_spec_string (
+ "justification",
+ &td.details.aml_history.justification),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string (
+ "kyc_requirements",
+ &td.details.aml_history.kyc_requirements),
+ NULL),
+ GNUNET_PQ_result_spec_uint64 (
+ "kyc_req_row",
+ &td.details.aml_history.kyc_req_row),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_pub",
+ &td.details.aml_history.decider_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "decider_sig",
+ &td.details.aml_history.decider_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ td.details.aml_history.kyc_requirements = NULL;
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ td.details.aml_history.new_status
+ = (enum TALER_AmlDecisionState) status32;
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with kyc_attributes table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_kyc_attributes (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "kyc_attributes_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_payto",
+ &td.details.kyc_attributes.h_payto),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "kyc_prox",
+ &td.details.kyc_attributes.kyc_prox),
+ GNUNET_PQ_result_spec_string (
+ "provider",
+ &td.details.kyc_attributes.provider),
+ GNUNET_PQ_result_spec_timestamp (
+ "collection_time",
+ &td.details.kyc_attributes.collection_time),
+ GNUNET_PQ_result_spec_timestamp (
+ "expiration_time",
+ &td.details.kyc_attributes.expiration_time),
+ GNUNET_PQ_result_spec_variable_size (
+ "encrypted_attributes",
+ &td.details.kyc_attributes.encrypted_attributes,
+ &td.details.kyc_attributes.encrypted_attributes_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with purse_deletion table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_purse_deletion (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_PURSE_DELETION
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "purse_deletion_serial_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_sig",
+ &td.details.purse_deletion.purse_sig),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "purse_pub",
+ &td.details.purse_deletion.purse_pub),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Function called with age_withdraw table entries.
+ *
+ * @param cls closure
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+lrbt_cb_table_age_withdraw (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct LookupRecordsByTableContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+ struct TALER_EXCHANGEDB_TableData td = {
+ .table = TALER_EXCHANGEDB_RT_AGE_WITHDRAW
+ };
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 (
+ "age_withdraw_id",
+ &td.serial),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "h_commitment",
+ &td.details.age_withdraw.h_commitment),
+ GNUNET_PQ_result_spec_uint16 (
+ "max_age",
+ &td.details.age_withdraw.max_age),
+ TALER_PQ_RESULT_SPEC_AMOUNT (
+ "amount_with_fee",
+ &td.details.age_withdraw.amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_pub",
+ &td.details.age_withdraw.reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type (
+ "reserve_sig",
+ &td.details.age_withdraw.reserve_sig),
+ GNUNET_PQ_result_spec_uint32 (
+ "noreveal_index",
+ &td.details.age_withdraw.noreveal_index),
+ /* TODO[oec]: more fields! */
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->error = true;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &td);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+/**
+ * Assign statement to @a n and PREPARE
+ * @a sql under name @a n.
+ */
+#define XPREPARE(n,sql) \
+ statement = n; \
+ PREPARE (pg, n, sql);
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_records_by_table (void *cls,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t serial,
+ TALER_EXCHANGEDB_ReplicationCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial),
+ GNUNET_PQ_query_param_end
+ };
+ struct LookupRecordsByTableContext ctx = {
+ .pg = pg,
+ .cb = cb,
+ .cb_cls = cb_cls
+ };
+ GNUNET_PQ_PostgresResultHandler rh = NULL;
+ const char *statement = NULL;
+ enum GNUNET_DB_QueryStatus qs;
+
+ switch (table)
+ {
+ case TALER_EXCHANGEDB_RT_DENOMINATIONS:
+ XPREPARE ("select_above_serial_by_table_denominations",
+ "SELECT"
+ " denominations_serial AS serial"
+ ",denom_type"
+ ",denom_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_withdraw"
+ ",expire_deposit"
+ ",expire_legal"
+ ",coin"
+ ",fee_withdraw"
+ ",fee_deposit"
+ ",fee_refresh"
+ ",fee_refund"
+ ",age_mask"
+ " FROM denominations"
+ " WHERE denominations_serial > $1"
+ " ORDER BY denominations_serial ASC;");
+ rh = &lrbt_cb_table_denominations;
+ break;
+ case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
+ XPREPARE ("select_above_serial_by_table_denomination_revocations",
+ "SELECT"
+ " denom_revocations_serial_id AS serial"
+ ",master_sig"
+ ",denominations_serial"
+ " FROM denomination_revocations"
+ " WHERE denom_revocations_serial_id > $1"
+ " ORDER BY denom_revocations_serial_id ASC;");
+ rh = &lrbt_cb_table_denomination_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
+ XPREPARE ("select_above_serial_by_table_wire_targets",
+ "SELECT"
+ " wire_target_serial_id AS serial"
+ ",payto_uri"
+ " FROM wire_targets"
+ " WHERE wire_target_serial_id > $1"
+ " ORDER BY wire_target_serial_id ASC;");
+ rh = &lrbt_cb_table_wire_targets;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
+ XPREPARE ("select_above_serial_by_table_legitimization_processes",
+ "SELECT"
+ " legitimization_process_serial_id AS serial"
+ ",h_payto"
+ ",reserve_pub"
+ ",expiration_time"
+ ",provider_section"
+ ",provider_user_id"
+ ",provider_legitimization_id"
+ " FROM legitimization_processes"
+ " WHERE legitimization_process_serial_id > $1"
+ " ORDER BY legitimization_process_serial_id ASC;");
+ rh = &lrbt_cb_table_legitimization_processes;
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS:
+ XPREPARE ("select_above_serial_by_table_legitimization_requirements",
+ "SELECT"
+ " legitimization_requirement_serial_id AS serial"
+ ",h_payto"
+ ",reserve_pub"
+ ",required_checks"
+ " FROM legitimization_requirements"
+ " WHERE legitimization_requirement_serial_id > $1"
+ " ORDER BY legitimization_requirement_serial_id ASC;");
+ rh = &lrbt_cb_table_legitimization_requirements;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES:
+ XPREPARE ("select_above_serial_by_table_reserves",
+ "SELECT"
+ " reserve_uuid AS serial"
+ ",reserve_pub"
+ ",expiration_date"
+ ",gc_date"
+ " FROM reserves"
+ " WHERE reserve_uuid > $1"
+ " ORDER BY reserve_uuid ASC;");
+ rh = &lrbt_cb_table_reserves;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_IN:
+ XPREPARE ("select_above_serial_by_table_reserves_in",
+ "SELECT"
+ " reserve_in_serial_id AS serial"
+ ",reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",wire_source_h_payto"
+ ",exchange_account_section"
+ ",execution_date"
+ " FROM reserves_in"
+ " WHERE reserve_in_serial_id > $1"
+ " ORDER BY reserve_in_serial_id ASC;");
+ rh = &lrbt_cb_table_reserves_in;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
+ XPREPARE ("select_above_serial_by_table_reserves_close",
+ "SELECT"
+ " close_uuid AS serial"
+ ",reserve_pub"
+ ",execution_date"
+ ",wtid"
+ ",wire_target_h_payto"
+ ",amount"
+ ",closing_fee"
+ " FROM reserves_close"
+ " WHERE close_uuid > $1"
+ " ORDER BY close_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_close;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_reserves_open_requests",
+ "SELECT"
+ " open_request_uuid AS serial"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",expiration_date"
+ ",reserve_sig"
+ ",reserve_payment"
+ ",requested_purse_limit"
+ " FROM reserves_open_requests"
+ " WHERE open_request_uuid > $1"
+ " ORDER BY open_request_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_open_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_reserves_open_deposits",
+ "SELECT"
+ " reserves_open_deposit_uuid AS serial"
+ ",reserve_sig"
+ ",reserve_pub"
+ ",coin_pub"
+ ",coin_sig"
+ ",contribution"
+ " FROM reserves_open_deposits"
+ " WHERE reserves_open_deposit_uuid > $1"
+ " ORDER BY reserves_open_deposit_uuid ASC;");
+ rh = &lrbt_cb_table_reserves_open_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OUT:
+ XPREPARE ("select_above_serial_by_table_reserves_out",
+ "SELECT"
+ " reserve_out_serial_id AS serial"
+ ",h_blind_ev"
+ ",denominations_serial"
+ ",denom_sig"
+ ",reserve_uuid"
+ ",reserve_sig"
+ ",execution_date"
+ ",amount_with_fee"
+ " FROM reserves_out"
+ " JOIN reserves USING (reserve_uuid)"
+ " WHERE reserve_out_serial_id > $1"
+ " ORDER BY reserve_out_serial_id ASC;");
+ rh = &lrbt_cb_table_reserves_out;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITORS:
+ XPREPARE ("select_above_serial_by_table_auditors",
+ "SELECT"
+ " auditor_uuid AS serial"
+ ",auditor_pub"
+ ",auditor_name"
+ ",auditor_url"
+ ",is_active"
+ ",last_change"
+ " FROM auditors"
+ " WHERE auditor_uuid > $1"
+ " ORDER BY auditor_uuid ASC;");
+ rh = &lrbt_cb_table_auditors;
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
+ XPREPARE ("select_above_serial_by_table_auditor_denom_sigs",
+ "SELECT"
+ " auditor_denom_serial AS serial"
+ ",auditor_uuid"
+ ",denominations_serial"
+ ",auditor_sig"
+ " FROM auditor_denom_sigs"
+ " WHERE auditor_denom_serial > $1"
+ " ORDER BY auditor_denom_serial ASC;");
+ rh = &lrbt_cb_table_auditor_denom_sigs;
+ break;
+ case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
+ XPREPARE ("select_above_serial_by_table_exchange_sign_keys",
+ "SELECT"
+ " esk_serial AS serial"
+ ",exchange_pub"
+ ",master_sig"
+ ",valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ " FROM exchange_sign_keys"
+ " WHERE esk_serial > $1"
+ " ORDER BY esk_serial ASC;");
+ rh = &lrbt_cb_table_exchange_sign_keys;
+ break;
+ case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
+ XPREPARE ("select_above_serial_by_table_signkey_revocations",
+ "SELECT"
+ " signkey_revocations_serial_id AS serial"
+ ",esk_serial"
+ ",master_sig"
+ " FROM signkey_revocations"
+ " WHERE signkey_revocations_serial_id > $1"
+ " ORDER BY signkey_revocations_serial_id ASC;");
+ rh = &lrbt_cb_table_signkey_revocations;
+ break;
+ case TALER_EXCHANGEDB_RT_KNOWN_COINS:
+ XPREPARE ("select_above_serial_by_table_known_coins",
+ "SELECT"
+ " known_coin_id AS serial"
+ ",coin_pub"
+ ",denom_sig"
+ ",denominations_serial"
+ " FROM known_coins"
+ " WHERE known_coin_id > $1"
+ " ORDER BY known_coin_id ASC;");
+ rh = &lrbt_cb_table_known_coins;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
+ XPREPARE ("select_above_serial_by_table_refresh_commitments",
+ "SELECT"
+ " melt_serial_id AS serial"
+ ",rc"
+ ",old_coin_sig"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",old_coin_pub"
+ " FROM refresh_commitments"
+ " WHERE melt_serial_id > $1"
+ " ORDER BY melt_serial_id ASC;");
+ rh = &lrbt_cb_table_refresh_commitments;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
+ XPREPARE ("select_above_serial_by_table_refresh_revealed_coins",
+ "SELECT"
+ " rrc_serial AS serial"
+ ",freshcoin_index"
+ ",link_sig"
+ ",coin_ev"
+ ",ev_sig"
+ ",ewv"
+ ",denominations_serial"
+ ",melt_serial_id"
+ " FROM refresh_revealed_coins"
+ " WHERE rrc_serial > $1"
+ " ORDER BY rrc_serial ASC;");
+ rh = &lrbt_cb_table_refresh_revealed_coins;
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
+ XPREPARE ("select_above_serial_by_table_refresh_transfer_keys",
+ "SELECT"
+ " rtc_serial AS serial"
+ ",transfer_pub"
+ ",transfer_privs"
+ ",melt_serial_id"
+ " FROM refresh_transfer_keys"
+ " WHERE rtc_serial > $1"
+ " ORDER BY rtc_serial ASC;");
+ rh = &lrbt_cb_table_refresh_transfer_keys;
+ break;
+ case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_batch_deposits",
+ "SELECT"
+ " batch_deposit_serial_id AS serial"
+ ",shard"
+ ",merchant_pub"
+ ",wallet_timestamp"
+ ",exchange_timestamp"
+ ",refund_deadline"
+ ",wire_deadline"
+ ",h_contract_terms"
+ ",wallet_data_hash"
+ ",wire_salt"
+ ",wire_target_h_payto"
+ ",done"
+ ",policy_blocked"
+ ",policy_details_serial_id"
+ " FROM batch_deposits"
+ " WHERE batch_deposit_serial_id > $1"
+ " ORDER BY batch_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_batch_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_coin_deposits",
+ "SELECT"
+ " coin_deposit_serial_id AS serial"
+ ",batch_deposit_serial_id"
+ ",coin_pub"
+ ",coin_sig"
+ ",amount_with_fee"
+ " FROM coin_deposits"
+ " WHERE coin_deposit_serial_id > $1"
+ " ORDER BY coin_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_coin_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_REFUNDS:
+ XPREPARE ("select_above_serial_by_table_refunds",
+ "SELECT"
+ " refund_serial_id AS serial"
+ ",coin_pub"
+ ",merchant_sig"
+ ",rtransaction_id"
+ ",amount_with_fee"
+ ",batch_deposit_serial_id"
+ " FROM refunds"
+ " WHERE refund_serial_id > $1"
+ " ORDER BY refund_serial_id ASC;");
+ rh = &lrbt_cb_table_refunds;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_OUT:
+ XPREPARE ("select_above_serial_by_table_wire_out",
+ "SELECT"
+ " wireout_uuid AS serial"
+ ",execution_date"
+ ",wtid_raw"
+ ",wire_target_h_payto"
+ ",exchange_account_section"
+ ",amount"
+ " FROM wire_out"
+ " WHERE wireout_uuid > $1"
+ " ORDER BY wireout_uuid ASC;");
+ rh = &lrbt_cb_table_wire_out;
+ break;
+ case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
+ XPREPARE ("select_above_serial_by_table_aggregation_tracking",
+ "SELECT"
+ " aggregation_serial_id AS serial"
+ ",batch_deposit_serial_id"
+ ",wtid_raw"
+ " FROM aggregation_tracking"
+ " WHERE aggregation_serial_id > $1"
+ " ORDER BY aggregation_serial_id ASC;");
+ rh = &lrbt_cb_table_aggregation_tracking;
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_FEE:
+ XPREPARE ("select_above_serial_by_table_wire_fee",
+ "SELECT"
+ " wire_fee_serial AS serial"
+ ",wire_method"
+ ",start_date"
+ ",end_date"
+ ",wire_fee"
+ ",closing_fee"
+ ",master_sig"
+ " FROM wire_fee"
+ " WHERE wire_fee_serial > $1"
+ " ORDER BY wire_fee_serial ASC;");
+ rh = &lrbt_cb_table_wire_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
+ XPREPARE ("select_above_serial_by_table_global_fee",
+ "SELECT"
+ " global_fee_serial AS serial"
+ ",start_date"
+ ",end_date"
+ ",history_fee"
+ ",account_fee"
+ ",purse_fee"
+ ",purse_timeout"
+ ",history_expiration"
+ ",purse_account_limit"
+ ",master_sig"
+ " FROM global_fee"
+ " WHERE global_fee_serial > $1"
+ " ORDER BY global_fee_serial ASC;");
+ rh = &lrbt_cb_table_global_fee;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP:
+ XPREPARE ("select_above_serial_by_table_recoup",
+ "SELECT"
+ " recoup_uuid AS serial"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",coin_pub"
+ ",reserve_out_serial_id"
+ " FROM recoup"
+ " WHERE recoup_uuid > $1"
+ " ORDER BY recoup_uuid ASC;");
+ rh = &lrbt_cb_table_recoup;
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
+ XPREPARE ("select_above_serial_by_table_recoup_refresh",
+ "SELECT"
+ " recoup_refresh_uuid AS serial"
+ ",coin_sig"
+ ",coin_blind"
+ ",amount"
+ ",recoup_timestamp"
+ ",coin_pub"
+ ",known_coin_id"
+ ",rrc_serial"
+ " FROM recoup_refresh"
+ " WHERE recoup_refresh_uuid > $1"
+ " ORDER BY recoup_refresh_uuid ASC;");
+ rh = &lrbt_cb_table_recoup_refresh;
+ break;
+ case TALER_EXCHANGEDB_RT_EXTENSIONS:
+ statement = "select_above_serial_by_table_extensions";
+ rh = &lrbt_cb_table_extensions;
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_DETAILS:
+ statement = "select_above_serial_by_table_policy_details";
+ rh = &lrbt_cb_table_policy_details;
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS:
+ statement = "select_above_serial_by_table_policy_fulfillments";
+ rh = &lrbt_cb_table_policy_fulfillments;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_purse_requests",
+ "SELECT"
+ " purse_requests_serial_id"
+ ",purse_pub"
+ ",merge_pub"
+ ",purse_creation"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",flags"
+ ",amount_with_fee"
+ ",purse_fee"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE purse_requests_serial_id > $1"
+ " ORDER BY purse_requests_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DECISION:
+ XPREPARE ("select_above_serial_by_table_purse_decision",
+ "SELECT"
+ " purse_decision_serial_id"
+ ",action_timestamp"
+ ",refunded"
+ ",purse_pub"
+ " FROM purse_decision"
+ " WHERE purse_decision_serial_id > $1"
+ " ORDER BY purse_decision_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_decision;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_MERGES:
+ XPREPARE ("select_above_serial_by_table_purse_merges",
+ "SELECT"
+ " purse_merge_request_serial_id"
+ ",partner_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",merge_sig"
+ ",merge_timestamp"
+ " FROM purse_merges"
+ " WHERE purse_merge_request_serial_id > $1"
+ " ORDER BY purse_merge_request_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_merges;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
+ XPREPARE ("select_above_serial_by_table_purse_deposits",
+ "SELECT"
+ " purse_deposit_serial_id"
+ ",partner_serial_id"
+ ",purse_pub"
+ ",coin_pub"
+ ",amount_with_fee"
+ ",coin_sig"
+ " FROM purse_deposits"
+ " WHERE purse_deposit_serial_id > $1"
+ " ORDER BY purse_deposit_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_deposits;
+ break;
+ case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
+ XPREPARE ("select_above_serial_by_table_account_merges",
+ "SELECT"
+ " account_merge_request_serial_id"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",purse_pub"
+ ",wallet_h_payto"
+ " FROM account_merges"
+ " WHERE account_merge_request_serial_id > $1"
+ " ORDER BY account_merge_request_serial_id ASC;");
+ rh = &lrbt_cb_table_account_merges;
+ break;
+ case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_history_requests",
+ "SELECT"
+ " history_request_serial_id"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",reserve_sig"
+ ",history_fee"
+ " FROM history_requests"
+ " WHERE history_request_serial_id > $1"
+ " ORDER BY history_request_serial_id ASC;");
+ rh = &lrbt_cb_table_history_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
+ XPREPARE ("select_above_serial_by_table_close_requests",
+ "SELECT"
+ " close_request_serial_id"
+ ",reserve_pub"
+ ",close_timestamp"
+ ",reserve_sig"
+ ",close"
+ " FROM close_requests"
+ " WHERE close_request_serial_id > $1"
+ " ORDER BY close_request_serial_id ASC;");
+ rh = &lrbt_cb_table_close_requests;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT:
+ XPREPARE ("select_above_serial_by_table_wads_out",
+ "SELECT"
+ " wad_out_serial_id"
+ ",wad_id"
+ ",partner_serial_id"
+ ",amount"
+ ",execution_time"
+ " FROM wads_out"
+ " WHERE wad_out_serial_id > $1"
+ " ORDER BY wad_out_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_out;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
+ XPREPARE ("select_above_serial_by_table_wads_out_entries",
+ "SELECT"
+ " wad_out_entry_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ " FROM wad_out_entries"
+ " WHERE wad_out_entry_serial_id > $1"
+ " ORDER BY wad_out_entry_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_out_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN:
+ XPREPARE ("select_above_serial_by_table_wads_in",
+ "SELECT"
+ " wad_in_serial_id"
+ ",wad_id"
+ ",origin_exchange_url"
+ ",amount"
+ ",arrival_time"
+ " FROM wads_in"
+ " WHERE wad_in_serial_id > $1"
+ " ORDER BY wad_in_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_in;
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
+ XPREPARE ("select_above_serial_by_table_wads_in_entries",
+ "SELECT"
+ " wad_in_entry_serial_id"
+ ",reserve_pub"
+ ",purse_pub"
+ ",h_contract"
+ ",purse_expiration"
+ ",merge_timestamp"
+ ",amount_with_fee"
+ ",wad_fee"
+ ",deposit_fees"
+ ",reserve_sig"
+ ",purse_sig"
+ " FROM wad_in_entries"
+ " WHERE wad_in_entry_serial_id > $1"
+ " ORDER BY wad_in_entry_serial_id ASC;");
+ rh = &lrbt_cb_table_wads_in_entries;
+ break;
+ case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
+ XPREPARE ("select_above_serial_by_table_profit_drains",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE profit_drain_serial_id > $1"
+ " ORDER BY profit_drain_serial_id ASC;");
+ rh = &lrbt_cb_table_profit_drains;
+ break;
+
+ case TALER_EXCHANGEDB_RT_AML_STAFF:
+ XPREPARE ("select_above_serial_by_table_aml_staff",
+ "SELECT"
+ " aml_staff_uuid"
+ ",decider_pub"
+ ",master_sig"
+ ",decider_name"
+ ",is_active"
+ ",read_only"
+ ",last_change"
+ " FROM aml_staff"
+ " WHERE aml_staff_uuid > $1"
+ " ORDER BY aml_staff_uuid ASC;");
+ rh = &lrbt_cb_table_aml_staff;
+ break;
+ case TALER_EXCHANGEDB_RT_AML_HISTORY:
+ XPREPARE ("select_above_serial_by_table_aml_history",
+ "SELECT"
+ " aml_history_serial_id"
+ ",h_payto"
+ ",new_threshold"
+ ",new_status"
+ ",decision_time"
+ ",justification"
+ ",kyc_requirements"
+ ",kyc_req_row"
+ ",decider_pub"
+ ",decider_sig"
+ " FROM aml_history"
+ " WHERE aml_history_serial_id > $1"
+ " ORDER BY aml_history_serial_id ASC;");
+ rh = &lrbt_cb_table_aml_history;
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
+ XPREPARE ("select_above_serial_by_table_kyc_attributes",
+ "SELECT"
+ " kyc_attributes_serial_id"
+ ",h_payto"
+ ",kyc_prox"
+ ",provider"
+ ",collection_time"
+ ",expiration_time"
+ ",encrypted_attributes"
+ " FROM kyc_attributes"
+ " WHERE kyc_attributes_serial_id > $1"
+ " ORDER BY kyc_attributes_serial_id ASC;");
+ rh = &lrbt_cb_table_kyc_attributes;
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DELETION:
+ XPREPARE ("select_above_serial_by_table_purse_deletion",
+ "SELECT"
+ " purse_deletion_serial_id"
+ ",purse_pub"
+ ",purse_sig"
+ " FROM purse_deletion"
+ " WHERE purse_deletion_serial_id > $1"
+ " ORDER BY purse_deletion_serial_id ASC;");
+ rh = &lrbt_cb_table_purse_deletion;
+ break;
+ case TALER_EXCHANGEDB_RT_AGE_WITHDRAW:
+ XPREPARE ("select_above_serial_by_table_age_withdraw",
+ "SELECT"
+ " age_withdraw_id"
+ ",h_commitment"
+ ",amount_with_fee"
+ ",max_age"
+ ",reserve_pub"
+ ",reserve_sig"
+ ",noreveal_index"
+ " FROM age_withdraw"
+ " WHERE age_withdraw_id > $1"
+ " ORDER BY age_withdraw_id ASC;");
+ /* TODO[oec]: MORE FIELDS! */
+ rh = &lrbt_cb_table_age_withdraw;
+ break;
+ }
+ if (NULL == rh)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ statement,
+ params,
+ rh,
+ &ctx);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to run `%s'\n",
+ statement);
+ return qs;
+ }
+ if (ctx.error)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return qs;
+}
+
+
+#undef XPREPARE
+
+/* end of pg_lookup_records_by_table.c */
diff --git a/src/exchangedb/pg_lookup_records_by_table.h b/src/exchangedb/pg_lookup_records_by_table.h
new file mode 100644
index 000000000..9dc25fff4
--- /dev/null
+++ b/src/exchangedb/pg_lookup_records_by_table.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_lookup_records_by_table.h
+ * @brief implementation of the lookup_records_by_table function
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_RECORDS_BY_TABLE_H
+#define PG_LOOKUP_RECORDS_BY_TABLE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup records above @a serial number in @a table. Used in
+ * exchange-auditor database replication.
+ *
+ * @param cls closure
+ * @param table table for which we should return the serial
+ * @param serial largest serial number to exclude
+ * @param cb function to call on the records
+ * @param cb_cls closure for @a cb
+ * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
+ * @a table does not have a serial number
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_records_by_table (void *cls,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t serial,
+ TALER_EXCHANGEDB_ReplicationCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_lookup_serial_by_table.c b/src/exchangedb/pg_lookup_serial_by_table.c
new file mode 100644
index 000000000..9fda7ddf8
--- /dev/null
+++ b/src/exchangedb/pg_lookup_serial_by_table.c
@@ -0,0 +1,459 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_lookup_serial_by_table.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_serial_by_table.h"
+#include "pg_helper.h"
+
+
+/**
+ * Assign statement to @a n and PREPARE
+ * @a sql under name @a n.
+ */
+#define XPREPARE(n,sql) \
+ statement = n; \
+ PREPARE (pg, n, sql);
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_serial_by_table (void *cls,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t *serial)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("serial",
+ serial),
+ GNUNET_PQ_result_spec_end
+ };
+ const char *statement = NULL;
+
+ switch (table)
+ {
+ case TALER_EXCHANGEDB_RT_DENOMINATIONS:
+ XPREPARE ("select_serial_by_table_denominations",
+ "SELECT"
+ " denominations_serial AS serial"
+ " FROM denominations"
+ " ORDER BY denominations_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
+ XPREPARE ("select_serial_by_table_denomination_revocations",
+ "SELECT"
+ " denom_revocations_serial_id AS serial"
+ " FROM denomination_revocations"
+ " ORDER BY denom_revocations_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
+ XPREPARE ("select_serial_by_table_wire_targets",
+ "SELECT"
+ " wire_target_serial_id AS serial"
+ " FROM wire_targets"
+ " ORDER BY wire_target_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES:
+ XPREPARE ("select_serial_by_table_legitimization_processes",
+ "SELECT"
+ " legitimization_process_serial_id AS serial"
+ " FROM legitimization_processes"
+ " ORDER BY legitimization_process_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS:
+ XPREPARE ("select_serial_by_table_legitimization_requiremetns",
+ "SELECT"
+ " legitimization_requirement_serial_id AS serial"
+ " FROM legitimization_requirements"
+ " ORDER BY legitimization_requirement_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES:
+ XPREPARE ("select_serial_by_table_reserves",
+ "SELECT"
+ " reserve_uuid AS serial"
+ " FROM reserves"
+ " ORDER BY reserve_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_IN:
+ XPREPARE ("select_serial_by_table_reserves_in",
+ "SELECT"
+ " reserve_in_serial_id AS serial"
+ " FROM reserves_in"
+ " ORDER BY reserve_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
+ XPREPARE ("select_serial_by_table_reserves_close",
+ "SELECT"
+ " close_uuid AS serial"
+ " FROM reserves_close"
+ " ORDER BY close_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS:
+ XPREPARE ("select_serial_by_table_reserves_open_requests",
+ "SELECT"
+ " open_request_uuid AS serial"
+ " FROM reserves_open_requests"
+ " ORDER BY open_request_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS:
+ XPREPARE ("select_serial_by_table_reserves_open_deposits",
+ "SELECT"
+ " reserve_open_deposit_uuid AS serial"
+ " FROM reserves_open_deposits"
+ " ORDER BY reserve_open_deposit_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RESERVES_OUT:
+ XPREPARE ("select_serial_by_table_reserves_out",
+ "SELECT"
+ " reserve_out_serial_id AS serial"
+ " FROM reserves_out"
+ " ORDER BY reserve_out_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITORS:
+ XPREPARE ("select_serial_by_table_auditors",
+ "SELECT"
+ " auditor_uuid AS serial"
+ " FROM auditors"
+ " ORDER BY auditor_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
+ XPREPARE ("select_serial_by_table_auditor_denom_sigs",
+ "SELECT"
+ " auditor_denom_serial AS serial"
+ " FROM auditor_denom_sigs"
+ " ORDER BY auditor_denom_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
+ XPREPARE ("select_serial_by_table_exchange_sign_keys",
+ "SELECT"
+ " esk_serial AS serial"
+ " FROM exchange_sign_keys"
+ " ORDER BY esk_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
+ XPREPARE ("select_serial_by_table_signkey_revocations",
+ "SELECT"
+ " signkey_revocations_serial_id AS serial"
+ " FROM signkey_revocations"
+ " ORDER BY signkey_revocations_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_KNOWN_COINS:
+ XPREPARE ("select_serial_by_table_known_coins",
+ "SELECT"
+ " known_coin_id AS serial"
+ " FROM known_coins"
+ " ORDER BY known_coin_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
+ XPREPARE ("select_serial_by_table_refresh_commitments",
+ "SELECT"
+ " melt_serial_id AS serial"
+ " FROM refresh_commitments"
+ " ORDER BY melt_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
+ XPREPARE ("select_serial_by_table_refresh_revealed_coins",
+ "SELECT"
+ " rrc_serial AS serial"
+ " FROM refresh_revealed_coins"
+ " ORDER BY rrc_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
+ XPREPARE ("select_serial_by_table_refresh_transfer_keys",
+ "SELECT"
+ " rtc_serial AS serial"
+ " FROM refresh_transfer_keys"
+ " ORDER BY rtc_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_BATCH_DEPOSITS:
+ XPREPARE ("select_serial_by_table_batch_deposits",
+ "SELECT"
+ " batch_deposit_serial_id AS serial"
+ " FROM batch_deposits"
+ " ORDER BY batch_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_COIN_DEPOSITS:
+ XPREPARE ("select_serial_by_table_coin_deposits",
+ "SELECT"
+ " coin_deposit_serial_id AS serial"
+ " FROM coin_deposits"
+ " ORDER BY coin_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_REFUNDS:
+ XPREPARE ("select_serial_by_table_refunds",
+ "SELECT"
+ " refund_serial_id AS serial"
+ " FROM refunds"
+ " ORDER BY refund_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_OUT:
+ XPREPARE ("select_serial_by_table_wire_out",
+ "SELECT"
+ " wireout_uuid AS serial"
+ " FROM wire_out"
+ " ORDER BY wireout_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
+ XPREPARE ("select_serial_by_table_aggregation_tracking",
+ "SELECT"
+ " aggregation_serial_id AS serial"
+ " FROM aggregation_tracking"
+ " ORDER BY aggregation_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WIRE_FEE:
+ XPREPARE ("select_serial_by_table_wire_fee",
+ "SELECT"
+ " wire_fee_serial AS serial"
+ " FROM wire_fee"
+ " ORDER BY wire_fee_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
+ XPREPARE ("select_serial_by_table_global_fee",
+ "SELECT"
+ " global_fee_serial AS serial"
+ " FROM global_fee"
+ " ORDER BY global_fee_serial DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP:
+ XPREPARE ("select_serial_by_table_recoup",
+ "SELECT"
+ " recoup_uuid AS serial"
+ " FROM recoup"
+ " ORDER BY recoup_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
+ XPREPARE ("select_serial_by_table_recoup_refresh",
+ "SELECT"
+ " recoup_refresh_uuid AS serial"
+ " FROM recoup_refresh"
+ " ORDER BY recoup_refresh_uuid DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_EXTENSIONS:
+ XPREPARE ("select_serial_by_table_extensions",
+ "SELECT"
+ " extension_id AS serial"
+ " FROM extensions"
+ " ORDER BY extension_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_DETAILS:
+ XPREPARE ("select_serial_by_table_policy_details",
+ "SELECT"
+ " policy_details_serial_id AS serial"
+ " FROM policy_details"
+ " ORDER BY policy_details_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS:
+ XPREPARE ("select_serial_by_table_policy_fulfillments",
+ "SELECT"
+ " fulfillment_id AS serial"
+ " FROM policy_fulfillments"
+ " ORDER BY fulfillment_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
+ XPREPARE ("select_serial_by_table_purse_requests",
+ "SELECT"
+ " purse_requests_serial_id AS serial"
+ " FROM purse_requests"
+ " ORDER BY purse_requests_serial_id DESC"
+ " LIMIT 1;")
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DECISION:
+ XPREPARE ("select_serial_by_table_purse_decision",
+ "SELECT"
+ " purse_decision_serial_id AS serial"
+ " FROM purse_decision"
+ " ORDER BY purse_decision_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_MERGES:
+ XPREPARE ("select_serial_by_table_purse_merges",
+ "SELECT"
+ " purse_merge_request_serial_id AS serial"
+ " FROM purse_merges"
+ " ORDER BY purse_merge_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
+ XPREPARE ("select_serial_by_table_purse_deposits",
+ "SELECT"
+ " purse_deposit_serial_id AS serial"
+ " FROM purse_deposits"
+ " ORDER BY purse_deposit_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
+ XPREPARE ("select_serial_by_table_account_merges",
+ "SELECT"
+ " account_merge_request_serial_id AS serial"
+ " FROM account_merges"
+ " ORDER BY account_merge_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
+ XPREPARE ("select_serial_by_table_history_requests",
+ "SELECT"
+ " history_request_serial_id AS serial"
+ " FROM history_requests"
+ " ORDER BY history_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
+ XPREPARE ("select_serial_by_table_close_requests",
+ "SELECT"
+ " close_request_serial_id AS serial"
+ " FROM close_requests"
+ " ORDER BY close_request_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT:
+ XPREPARE ("select_serial_by_table_wads_out",
+ "SELECT"
+ " wad_out_serial_id AS serial"
+ " FROM wads_out"
+ " ORDER BY wad_out_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
+ XPREPARE ("select_serial_by_table_wads_out_entries",
+ "SELECT"
+ " wad_out_entry_serial_id AS serial"
+ " FROM wad_out_entries"
+ " ORDER BY wad_out_entry_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN:
+ XPREPARE ("select_serial_by_table_wads_in",
+ "SELECT"
+ " wad_in_serial_id AS serial"
+ " FROM wads_in"
+ " ORDER BY wad_in_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
+ XPREPARE ("select_serial_by_table_wads_in_entries",
+ "SELECT"
+ " wad_in_entry_serial_id AS serial"
+ " FROM wad_in_entries"
+ " ORDER BY wad_in_entry_serial_id DESC"
+ " LIMIT 1;");
+ break;
+ case TALER_EXCHANGEDB_RT_PROFIT_DRAINS:
+ XPREPARE ("select_serial_by_table_profit_drains",
+ "SELECT"
+ " profit_drain_serial_id AS serial"
+ " FROM profit_drains"
+ " ORDER BY profit_drain_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_profit_drains";
+ break;
+ case TALER_EXCHANGEDB_RT_AML_STAFF:
+ XPREPARE ("select_serial_by_table_aml_staff",
+ "SELECT"
+ " aml_staff_uuid AS serial"
+ " FROM aml_staff"
+ " ORDER BY aml_staff_uuid DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_aml_staff";
+ break;
+ case TALER_EXCHANGEDB_RT_AML_HISTORY:
+ XPREPARE ("select_serial_by_table_aml_history",
+ "SELECT"
+ " aml_history_serial_id AS serial"
+ " FROM aml_history"
+ " ORDER BY aml_history_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_aml_history";
+ break;
+ case TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES:
+ XPREPARE ("select_serial_by_table_kyc_attributes",
+ "SELECT"
+ " kyc_attributes_serial_id AS serial"
+ " FROM kyc_attributes"
+ " ORDER BY kyc_attributes_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_kyc_attributes";
+ break;
+ case TALER_EXCHANGEDB_RT_PURSE_DELETION:
+ XPREPARE ("select_serial_by_table_purse_deletion",
+ "SELECT"
+ " purse_deletion_serial_id AS serial"
+ " FROM purse_deletion"
+ " ORDER BY purse_deletion_serial_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_purse_deletion";
+ break;
+ case TALER_EXCHANGEDB_RT_AGE_WITHDRAW:
+ XPREPARE ("select_serial_by_table_age_withdraw",
+ "SELECT"
+ " age_withdraw_id AS serial"
+ " FROM age_withdraw"
+ " ORDER BY age_withdraw_id DESC"
+ " LIMIT 1;");
+ statement = "select_serial_by_table_age_withdraw";
+ break;
+ }
+ if (NULL == statement)
+ {
+ GNUNET_break (0);
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ }
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ statement,
+ params,
+ rs);
+}
+
+
+#undef XPREPARE
diff --git a/src/exchangedb/pg_lookup_serial_by_table.h b/src/exchangedb/pg_lookup_serial_by_table.h
new file mode 100644
index 000000000..815b6477d
--- /dev/null
+++ b/src/exchangedb/pg_lookup_serial_by_table.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_lookup_serial_by_table.h
+ * @brief implementation of the lookup_serial_by_table function
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_SERIAL_BY_TABLE_H
+#define PG_LOOKUP_SERIAL_BY_TABLE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup the latest serial number of @a table. Used in
+ * exchange-auditor database replication.
+ *
+ * @param cls closure
+ * @param table table for which we should return the serial
+ * @param[out] serial latest serial number in use
+ * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
+ * @a table does not have a serial number
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_serial_by_table (void *cls,
+ enum TALER_EXCHANGEDB_ReplicatedTable table,
+ uint64_t *serial);
+
+
+#endif
diff --git a/src/exchangedb/pg_lookup_signing_key.c b/src/exchangedb/pg_lookup_signing_key.c
new file mode 100644
index 000000000..3803d114f
--- /dev/null
+++ b/src/exchangedb/pg_lookup_signing_key.c
@@ -0,0 +1,64 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_signing_key.c
+ * @brief Implementation of the lookup_signing_key function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_signing_key.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_signing_key (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_EXCHANGEDB_SignkeyMetaData *meta)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("valid_from",
+ &meta->start),
+ GNUNET_PQ_result_spec_timestamp ("expire_sign",
+ &meta->expire_sign),
+ GNUNET_PQ_result_spec_timestamp ("expire_legal",
+ &meta->expire_legal),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "lookup_signing_key",
+ "SELECT"
+ " valid_from"
+ ",expire_sign"
+ ",expire_legal"
+ " FROM exchange_sign_keys"
+ " WHERE exchange_pub=$1");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_signing_key",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_signing_key.h b/src/exchangedb/pg_lookup_signing_key.h
new file mode 100644
index 000000000..487d60d2b
--- /dev/null
+++ b/src/exchangedb/pg_lookup_signing_key.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_signing_key.h
+ * @brief implementation of the lookup_signing_key function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_SIGNING_KEY_H
+#define PG_LOOKUP_SIGNING_KEY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup signing key meta data.
+ *
+ * @param cls closure
+ * @param exchange_pub the exchange online signing public key
+ * @param[out] meta meta data about @a exchange_pub
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_signing_key (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_EXCHANGEDB_SignkeyMetaData *meta);
+#endif
diff --git a/src/exchangedb/pg_lookup_signkey_revocation.c b/src/exchangedb/pg_lookup_signkey_revocation.c
new file mode 100644
index 000000000..056ecddc4
--- /dev/null
+++ b/src/exchangedb/pg_lookup_signkey_revocation.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_signkey_revocation.c
+ * @brief Implementation of the lookup_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_signkey_revocation.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_signkey_revocation (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (exchange_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "lookup_signkey_revocation",
+ "SELECT "
+ " master_sig"
+ " FROM signkey_revocations"
+ " WHERE esk_serial="
+ " (SELECT esk_serial"
+ " FROM exchange_sign_keys"
+ " WHERE exchange_pub=$1);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_signkey_revocation",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_signkey_revocation.h b/src/exchangedb/pg_lookup_signkey_revocation.h
new file mode 100644
index 000000000..de0fb1d74
--- /dev/null
+++ b/src/exchangedb/pg_lookup_signkey_revocation.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_signkey_revocation.h
+ * @brief implementation of the lookup_signkey_revocation function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_SIGNKEY_REVOCATION_H
+#define PG_LOOKUP_SIGNKEY_REVOCATION_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Obtain information about a revoked online signing key.
+ *
+ * @param cls closure
+ * @param exchange_pub exchange online signing key
+ * @param[out] master_sig set to signature affirming the revocation (if revoked)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_signkey_revocation (
+ void *cls,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_transfer_by_deposit.c b/src/exchangedb/pg_lookup_transfer_by_deposit.c
new file mode 100644
index 000000000..192556130
--- /dev/null
+++ b/src/exchangedb/pg_lookup_transfer_by_deposit.c
@@ -0,0 +1,239 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_transfer_by_deposit.c
+ * @brief Implementation of the lookup_transfer_by_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_transfer_by_deposit.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_transfer_by_deposit (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ bool *pending,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp *exec_time,
+ struct TALER_Amount *amount_with_fee,
+ struct TALER_Amount *deposit_fee,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ enum TALER_AmlDecisionState *aml_decision)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_end
+ };
+ char *payto_uri;
+ struct TALER_WireSaltP wire_salt;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ wtid),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ exec_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ memset (kyc,
+ 0,
+ sizeof (*kyc));
+ /* check if the aggregation record exists and get it */
+ PREPARE (pg,
+ "lookup_deposit_wtid",
+ "SELECT"
+ " atr.wtid_raw"
+ ",wire_out.execution_date"
+ ",cdep.amount_with_fee"
+ ",bdep.wire_salt"
+ ",wt.payto_uri"
+ ",denom.fee_deposit"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN aggregation_tracking atr"
+ " ON (cdep.batch_deposit_serial_id = atr.batch_deposit_serial_id)"
+ " JOIN known_coins kc"
+ " ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " JOIN wire_out"
+ " USING (wtid_raw)"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2");
+ /* NOTE: above query might be more efficient if we computed the shard
+ from the merchant_pub and included that in the query */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_deposit_wtid",
+ params,
+ rs);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ struct TALER_MerchantWireHashP wh;
+
+ TALER_merchant_wire_signature_hash (payto_uri,
+ &wire_salt,
+ &wh);
+ if (0 ==
+ GNUNET_memcmp (&wh,
+ h_wire))
+ {
+ *pending = false;
+ kyc->ok = true;
+ *aml_decision = TALER_AML_NORMAL;
+ GNUNET_PQ_cleanup_result (rs);
+ return qs;
+ }
+ qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ GNUNET_PQ_cleanup_result (rs);
+ }
+ if (0 > qs)
+ return qs;
+ *pending = true;
+ memset (wtid,
+ 0,
+ sizeof (*wtid));
+ GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "lookup_deposit_wtid returned 0 matching rows\n");
+ {
+ /* Check if transaction exists in deposits, so that we just
+ do not have a WTID yet. In that case, return without wtid
+ (by setting 'pending' true). */
+ uint32_t status32 = TALER_AML_NORMAL;
+ uint64_t aml_kyc_row = 0;
+ struct GNUNET_PQ_ResultSpec rs2[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &wire_salt),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ /* See Postgresql bug #18380 */
+#define BUG 1
+#if BUG
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("legitimization_requirement_serial_id",
+ &kyc->requirement_row),
+ NULL),
+#endif
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("kyc_requirement",
+ &aml_kyc_row),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("status",
+ &status32),
+ NULL),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ deposit_fee),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ exec_time),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "get_deposit_without_wtid",
+ "SELECT"
+ " bdep.wire_salt"
+ ",wt.payto_uri"
+ ",cdep.amount_with_fee"
+ ",denom.fee_deposit"
+ ",bdep.wire_deadline"
+#if BUG
+ ",agt.legitimization_requirement_serial_id"
+#endif
+ ",aml.status"
+ ",aml.kyc_requirement"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " ON (kc.coin_pub = cdep.coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+#if BUG
+ " LEFT JOIN aggregation_transient agt "
+ " ON ( (bdep.wire_target_h_payto = agt.wire_target_h_payto) AND"
+ " (bdep.merchant_pub = agt.merchant_pub) )"
+#endif
+ " LEFT JOIN aml_status aml"
+ " ON (wt.wire_target_h_payto = aml.h_payto)"
+ " WHERE cdep.coin_pub=$1"
+ " AND bdep.merchant_pub=$3"
+ " AND bdep.h_contract_terms=$2"
+ " LIMIT 1;");
+ /* NOTE: above query might be more efficient if we computed the shard
+ from the merchant_pub and included that in the query */
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_deposit_without_wtid",
+ params,
+ rs2);
+ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
+ {
+ struct TALER_MerchantWireHashP wh;
+
+ *aml_decision = (enum TALER_AmlDecisionState) status32;
+ if (0 == kyc->requirement_row)
+ kyc->ok = true; /* technically: unknown */
+ if ( (kyc->ok) &&
+ (TALER_AML_FROZEN == *aml_decision) &&
+ (0 != aml_kyc_row) )
+ {
+ /* KYC required via AML */
+ kyc->ok = false;
+ kyc->requirement_row = aml_kyc_row;
+ }
+ TALER_merchant_wire_signature_hash (payto_uri,
+ &wire_salt,
+ &wh);
+ if (0 !=
+ GNUNET_memcmp (&wh,
+ h_wire))
+ {
+ GNUNET_PQ_cleanup_result (rs2);
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ GNUNET_PQ_cleanup_result (rs2);
+ }
+ *aml_decision = TALER_AML_NORMAL;
+ return qs;
+ }
+}
diff --git a/src/exchangedb/pg_lookup_transfer_by_deposit.h b/src/exchangedb/pg_lookup_transfer_by_deposit.h
new file mode 100644
index 000000000..83782d5a0
--- /dev/null
+++ b/src/exchangedb/pg_lookup_transfer_by_deposit.h
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_transfer_by_deposit.h
+ * @brief implementation of the lookup_transfer_by_deposit function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_TRANSFER_BY_DEPOSIT_H
+#define PG_LOOKUP_TRANSFER_BY_DEPOSIT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Try to find the wire transfer details for a deposit operation.
+ * If we did not execute the deposit yet, return when it is supposed
+ * to be executed.
+ *
+ * @param cls closure
+ * @param h_contract_terms hash of the proposal data
+ * @param h_wire hash of merchant wire details
+ * @param coin_pub public key of deposited coin
+ * @param merchant_pub merchant public key
+ * @param[out] pending set to true if the transaction is still pending
+ * @param[out] wtid wire transfer identifier, only set if @a pending is false
+ * @param[out] exec_time when was the transaction done, or
+ * when we expect it to be done (if @a pending is false)
+ * @param[out] amount_with_fee set to the total deposited amount
+ * @param[out] deposit_fee set to how much the exchange did charge for the deposit
+ * @param[out] kyc set to the kyc status of the receiver (if @a pending)
+ * @param[out] aml_decision set to the AML status of the receiver
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_transfer_by_deposit (
+ void *cls,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ bool *pending,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp *exec_time,
+ struct TALER_Amount *amount_with_fee,
+ struct TALER_Amount *deposit_fee,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ enum TALER_AmlDecisionState *aml_decision);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_wire_fee_by_time.c b/src/exchangedb/pg_lookup_wire_fee_by_time.c
new file mode 100644
index 000000000..775232a48
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_fee_by_time.c
@@ -0,0 +1,156 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_fee_by_time.c
+ * @brief Implementation of the lookup_wire_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_wire_fee_by_time.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #wire_fee_by_time_helper()
+ */
+struct WireFeeLookupContext
+{
+
+ /**
+ * Set to the wire fees. Set to invalid if fees conflict over
+ * the given time period.
+ */
+ struct TALER_WireFeeSet *fees;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+};
+
+
+/**
+ * Helper function for #TEH_PG_lookup_wire_fee_by_time().
+ * Calls the callback with the wire fee structure.
+ *
+ * @param cls a `struct WireFeeLookupContext`
+ * @param result db results
+ * @param num_results number of results in @a result
+ */
+static void
+wire_fee_by_time_helper (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireFeeLookupContext *wlc = cls;
+ struct PostgresClosure *pg = wlc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_WireFeeSet fs;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
+ &fs.wire),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &fs.closing),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_WireFeeSet));
+ return;
+ }
+ if (0 == i)
+ {
+ *wlc->fees = fs;
+ continue;
+ }
+ if (0 !=
+ TALER_wire_fee_set_cmp (&fs,
+ wlc->fees))
+ {
+ /* invalidate */
+ memset (wlc->fees,
+ 0,
+ sizeof (struct TALER_WireFeeSet));
+ return;
+ }
+ }
+}
+
+
+/**
+ * Lookup information about known wire fees. Finds all applicable
+ * fees in the given range. If they are identical, returns the
+ * respective @a fees. If any of the fees
+ * differ between @a start_time and @a end_time, the transaction
+ * succeeds BUT returns an invalid amount for both fees.
+ *
+ * @param cls closure
+ * @param wire_method the wire method to lookup fees for
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees wire fees for that time period; if
+ * different fees exists within this time
+ * period, an 'invalid' amount is returned.
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_fee_by_time (
+ void *cls,
+ const char *wire_method,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_WireFeeSet *fees)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (wire_method),
+ GNUNET_PQ_query_param_timestamp (&start_time),
+ GNUNET_PQ_query_param_timestamp (&end_time),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireFeeLookupContext wlc = {
+ .fees = fees,
+ .pg = pg
+ };
+ /* used in #postgres_lookup_wire_fee_by_time() */
+ PREPARE (pg,
+ "lookup_wire_fee_by_time",
+ "SELECT"
+ " wire_fee"
+ ",closing_fee"
+ " FROM wire_fee"
+ " WHERE wire_method=$1"
+ " AND end_date > $2"
+ " AND start_date < $3;");
+ return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_wire_fee_by_time",
+ params,
+ &wire_fee_by_time_helper,
+ &wlc);
+}
diff --git a/src/exchangedb/pg_lookup_wire_fee_by_time.h b/src/exchangedb/pg_lookup_wire_fee_by_time.h
new file mode 100644
index 000000000..cbfc36e76
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_fee_by_time.h
@@ -0,0 +1,76 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_fee_by_time.h
+ * @brief implementation of the lookup_wire_fee_by_time function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_WIRE_FEE_BY_TIME_H
+#define PG_LOOKUP_WIRE_FEE_BY_TIME_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup information about known wire fees. Finds all applicable
+ * fees in the given range. If they are identical, returns the
+ * respective @a fees. If any of the fees
+ * differ between @a start_time and @a end_time, the transaction
+ * succeeds BUT returns an invalid amount for both fees.
+ *
+ * @param cls closure
+ * @param wire_method the wire method to lookup fees for
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees wire fees for that time period; if
+ * different fees exists within this time
+ * period, an 'invalid' amount is returned.
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_fee_by_time (
+ void *cls,
+ const char *wire_method,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_WireFeeSet *fees);
+
+/**
+ * Lookup information about known wire fees. Finds all applicable
+ * fees in the given range. If they are identical, returns the
+ * respective @a fees. If any of the fees
+ * differ between @a start_time and @a end_time, the transaction
+ * succeeds BUT returns an invalid amount for both fees.
+ *
+ * @param cls closure
+ * @param wire_method the wire method to lookup fees for
+ * @param start_time starting time of fee
+ * @param end_time end time of fee
+ * @param[out] fees wire fees for that time period; if
+ * different fees exists within this time
+ * period, an 'invalid' amount is returned.
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_fee_by_time (
+ void *cls,
+ const char *wire_method,
+ struct GNUNET_TIME_Timestamp start_time,
+ struct GNUNET_TIME_Timestamp end_time,
+ struct TALER_WireFeeSet *fees);
+#endif
diff --git a/src/exchangedb/pg_lookup_wire_timestamp.c b/src/exchangedb/pg_lookup_wire_timestamp.c
new file mode 100644
index 000000000..17dffc706
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_timestamp.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_timestamp.c
+ * @brief Implementation of the lookup_wire_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_wire_timestamp.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_timestamp (void *cls,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp *last_date)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("last_change",
+ last_date),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "lookup_wire_timestamp",
+ "SELECT"
+ " last_change"
+ " FROM wire_accounts"
+ " WHERE payto_uri=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "lookup_wire_timestamp",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_lookup_wire_timestamp.h b/src/exchangedb/pg_lookup_wire_timestamp.h
new file mode 100644
index 000000000..f2ee117de
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_timestamp.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_timestamp.h
+ * @brief implementation of the lookup_wire_timestamp function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_WIRE_TIMESTAMP_H
+#define PG_LOOKUP_WIRE_TIMESTAMP_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Check the last date an exchange wire account was modified.
+ *
+ * @param cls closure
+ * @param payto_uri key to look up information for
+ * @param[out] last_date last modification date to auditor status
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_timestamp (void *cls,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp *last_date);
+
+#endif
diff --git a/src/exchangedb/pg_lookup_wire_transfer.c b/src/exchangedb/pg_lookup_wire_transfer.c
new file mode 100644
index 000000000..7ab023fe7
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_transfer.c
@@ -0,0 +1,188 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_transfer.c
+ * @brief Implementation of the lookup_wire_transfer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_lookup_wire_transfer.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #handle_wt_result.
+ */
+struct WireTransferResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AggregationDataCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TEH_PG_lookup_wire_transfer().
+ *
+ * @param cls closure of type `struct WireTransferResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_wt_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireTransferResultContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_PaytoHashP h_payto;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Timestamp exec_time;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount deposit_fee;
+ struct TALER_DenominationPublicKey denom_pub;
+ char *payto_uri;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &h_payto),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &merchant_pub),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &exec_time),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
+ &deposit_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ rowid,
+ &merchant_pub,
+ payto_uri,
+ &h_payto,
+ exec_time,
+ &h_contract_terms,
+ &denom_pub,
+ &coin_pub,
+ &amount_with_fee,
+ &deposit_fee);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_transfer (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ TALER_EXCHANGEDB_AggregationDataCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireTransferResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "lookup_transactions",
+ "SELECT"
+ " aggregation_serial_id"
+ ",bdep.h_contract_terms"
+ ",payto_uri"
+ ",wire_targets.wire_target_h_payto"
+ ",kc.coin_pub"
+ ",bdep.merchant_pub"
+ ",wire_out.execution_date"
+ ",cdep.amount_with_fee"
+ ",denom.fee_deposit"
+ ",denom.denom_pub"
+ " FROM aggregation_tracking"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN coin_deposits cdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " JOIN wire_out"
+ " USING (wtid_raw)"
+ " WHERE wtid_raw=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_transactions",
+ params,
+ &handle_wt_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_lookup_wire_transfer.h b/src/exchangedb/pg_lookup_wire_transfer.h
new file mode 100644
index 000000000..ae5355f40
--- /dev/null
+++ b/src/exchangedb/pg_lookup_wire_transfer.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_lookup_wire_transfer.h
+ * @brief implementation of the lookup_wire_transfer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_LOOKUP_WIRE_TRANSFER_H
+#define PG_LOOKUP_WIRE_TRANSFER_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Lookup the list of Taler transactions that were aggregated
+ * into a wire transfer by the respective @a wtid.
+ *
+ * @param cls closure
+ * @param wtid the raw wire transfer identifier we used
+ * @param cb function to call on each transaction found
+ * @param cb_cls closure for @a cb
+ * @return query status of the transaction
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_lookup_wire_transfer (
+ void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ TALER_EXCHANGEDB_AggregationDataCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_persist_policy_details.c b/src/exchangedb/pg_persist_policy_details.c
new file mode 100644
index 000000000..d97b92eac
--- /dev/null
+++ b/src/exchangedb/pg_persist_policy_details.c
@@ -0,0 +1,78 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_persist_policy_details.c
+ * @brief Implementation of the persist_policy_details function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_persist_policy_details.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_persist_policy_details (
+ void *cls,
+ const struct TALER_PolicyDetails *details,
+ uint64_t *policy_details_serial_id,
+ struct TALER_Amount *accumulated_total,
+ enum TALER_PolicyFulfillmentState *fulfillment_state)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&details->hash_code),
+ TALER_PQ_query_param_json (details->policy_json),
+ GNUNET_PQ_query_param_timestamp (&details->deadline),
+ TALER_PQ_query_param_amount (pg->conn,
+ &details->commitment),
+ TALER_PQ_query_param_amount (pg->conn,
+ &details->accumulated_total),
+ TALER_PQ_query_param_amount (pg->conn,
+ &details->policy_fee),
+ TALER_PQ_query_param_amount (pg->conn,
+ &details->transferable_amount),
+ GNUNET_PQ_query_param_auto_from_type (&details->fulfillment_state),
+ (details->no_policy_fulfillment_id)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_uint64 (&details->policy_fulfillment_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("policy_details_serial_id",
+ policy_details_serial_id),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("accumulated_total",
+ accumulated_total),
+ GNUNET_PQ_result_spec_uint32 ("fulfillment_state",
+ fulfillment_state),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "call_insert_or_update_policy_details",
+ "SELECT"
+ " out_policy_details_serial_id AS policy_details_serial_id"
+ ",out_accumulated_total AS accumulated_total"
+ ",out_fulfillment_state AS fulfillment_state"
+ " FROM exchange_do_insert_or_update_policy_details"
+ "($1, $2, $3, $4, $5, $6, $7, $8, $9);");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "call_insert_or_update_policy_details",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_persist_policy_details.h b/src/exchangedb/pg_persist_policy_details.h
new file mode 100644
index 000000000..4fe709d92
--- /dev/null
+++ b/src/exchangedb/pg_persist_policy_details.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_persist_policy_details.h
+ * @brief implementation of the persist_policy_details function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_PERSIST_POLICY_DETAILS_H
+#define PG_PERSIST_POLICY_DETAILS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/* Persist the details to a policy in the policy_details table. If there
+ * already exists a policy, update the fields accordingly.
+ *
+ * @param details The policy details that should be persisted. If an entry for
+ * the given details->hash_code exists, the values will be updated.
+ * @param[out] policy_details_serial_id The row ID of the policy details
+ * @param[out] accumulated_total The total amount accumulated in that policy
+ * @param[out] fulfillment_state The state of policy. If the state was Insufficient prior to the call and the provided deposit raises the accumulated_total above the commitment, it will be set to Ready.
+ * @return query execution status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_persist_policy_details (
+ void *cls,
+ const struct TALER_PolicyDetails *details,
+ uint64_t *policy_details_serial_id,
+ struct TALER_Amount *accumulated_total,
+ enum TALER_PolicyFulfillmentState *fulfillment_state);
+
+#endif
diff --git a/src/exchangedb/pg_preflight.c b/src/exchangedb/pg_preflight.c
new file mode 100644
index 000000000..4533c9a97
--- /dev/null
+++ b/src/exchangedb/pg_preflight.c
@@ -0,0 +1,69 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_preflight.c
+ * @brief Implementation of the preflight function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_preflight.h"
+#include "pg_helper.h"
+
+
+/**
+ * Connect to the database if the connection does not exist yet.
+ *
+ * @param pg the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_internal_setup (struct PostgresClosure *pg);
+
+
+enum GNUNET_GenericReturnValue
+TEH_PG_preflight (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("ROLLBACK"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ if (GNUNET_OK !=
+ TEH_PG_internal_setup (pg))
+ return GNUNET_SYSERR;
+ if (NULL == pg->transaction_name)
+ return GNUNET_OK; /* all good */
+ if (GNUNET_OK ==
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "BUG: Preflight check rolled back transaction `%s'!\n",
+ pg->transaction_name);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "BUG: Preflight check failed to rollback transaction `%s'!\n",
+ pg->transaction_name);
+ }
+ pg->transaction_name = NULL;
+ return GNUNET_NO;
+}
diff --git a/src/exchangedb/pg_preflight.h b/src/exchangedb/pg_preflight.h
new file mode 100644
index 000000000..ba994f1e6
--- /dev/null
+++ b/src/exchangedb/pg_preflight.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_preflight.h
+ * @brief implementation of the preflight function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_PREFLIGTH_H
+#define PG_PREFLIGTH_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Do a pre-flight check that we are not in an uncommitted transaction.
+ * If we are, try to commit the previous transaction and output a warning.
+ * Does not return anything, as we will continue regardless of the outcome.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return #GNUNET_OK if everything is fine
+ * #GNUNET_NO if a transaction was rolled back
+ * #GNUNET_SYSERR on hard errors
+ */
+
+
+enum GNUNET_GenericReturnValue
+TEH_PG_preflight (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_profit_drains_get_pending.c b/src/exchangedb/pg_profit_drains_get_pending.c
new file mode 100644
index 000000000..c844a3f38
--- /dev/null
+++ b/src/exchangedb/pg_profit_drains_get_pending.c
@@ -0,0 +1,78 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_profit_drains_get_pending.c
+ * @brief Implementation of the profit_drains_get_pending function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_profit_drains_get_pending.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_profit_drains_get_pending (
+ void *cls,
+ uint64_t *serial,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("profit_drain_serial_id",
+ serial),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ wtid),
+ GNUNET_PQ_result_spec_string ("account_section",
+ account_section),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ GNUNET_PQ_result_spec_timestamp ("trigger_date",
+ request_timestamp),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ amount),
+ GNUNET_PQ_result_spec_auto_from_type ("master_sig",
+ master_sig),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_profit_drains_get_pending() */
+ PREPARE (pg,
+ "get_ready_profit_drain",
+ "SELECT"
+ " profit_drain_serial_id"
+ ",wtid"
+ ",account_section"
+ ",payto_uri"
+ ",trigger_date"
+ ",amount"
+ ",master_sig"
+ " FROM profit_drains"
+ " WHERE NOT executed"
+ " ORDER BY trigger_date ASC;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_ready_profit_drain",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_profit_drains_get_pending.h b/src/exchangedb/pg_profit_drains_get_pending.h
new file mode 100644
index 000000000..cd793a129
--- /dev/null
+++ b/src/exchangedb/pg_profit_drains_get_pending.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_profit_drains_get_pending.h
+ * @brief implementation of the profit_drains_get_pending function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_PROFIT_DRAINS_GET_PENDING_H
+#define PG_PROFIT_DRAINS_GET_PENDING_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Get profit drain operation ready to execute.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] wtid set set to wire transfer ID to use
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_profit_drains_get_pending (
+ void *cls,
+ uint64_t *serial,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+#endif
diff --git a/src/exchangedb/pg_profit_drains_set_finished.c b/src/exchangedb/pg_profit_drains_set_finished.c
new file mode 100644
index 000000000..f0de27945
--- /dev/null
+++ b/src/exchangedb/pg_profit_drains_set_finished.c
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_profit_drains_set_finished.c
+ * @brief Implementation of the profit_drains_set_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_profit_drains_set_finished.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_profit_drains_set_finished (
+ void *cls,
+ uint64_t serial)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "drain_profit_set_finished",
+ "UPDATE profit_drains"
+ " SET"
+ " executed=TRUE"
+ " WHERE profit_drain_serial_id=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "drain_profit_set_finished",
+ params);
+}
diff --git a/src/exchangedb/pg_profit_drains_set_finished.h b/src/exchangedb/pg_profit_drains_set_finished.h
new file mode 100644
index 000000000..b0878b5b8
--- /dev/null
+++ b/src/exchangedb/pg_profit_drains_set_finished.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_profit_drains_set_finished.h
+ * @brief implementation of the profit_drains_set_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_PROFIT_DRAINS_SET_FINISHED_H
+#define PG_PROFIT_DRAINS_SET_FINISHED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Set profit drain operation to finished.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param serial serial ID of the entry to mark finished
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_profit_drains_set_finished (
+ void *cls,
+ uint64_t serial);
+
+#endif
diff --git a/src/exchangedb/pg_release_revolving_shard.c b/src/exchangedb/pg_release_revolving_shard.c
new file mode 100644
index 000000000..43e45c4bc
--- /dev/null
+++ b/src/exchangedb/pg_release_revolving_shard.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_release_revolving_shard.c
+ * @brief Implementation of the release_revolving_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_release_revolving_shard.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_release_revolving_shard (void *cls,
+ const char *job_name,
+ uint32_t start_row,
+ uint32_t end_row)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (job_name),
+ GNUNET_PQ_query_param_uint32 (&start_row),
+ GNUNET_PQ_query_param_uint32 (&end_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Releasing revolving shard %s %u-%u\n",
+ job_name,
+ (unsigned int) start_row,
+ (unsigned int) end_row);
+
+
+ PREPARE (pg,
+ "release_revolving_shard",
+ "UPDATE revolving_work_shards"
+ " SET active=FALSE"
+ " WHERE job_name=$1"
+ " AND start_row=$2"
+ " AND end_row=$3");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "release_revolving_shard",
+ params);
+}
diff --git a/src/exchangedb/pg_release_revolving_shard.h b/src/exchangedb/pg_release_revolving_shard.h
new file mode 100644
index 000000000..ea65ab605
--- /dev/null
+++ b/src/exchangedb/pg_release_revolving_shard.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_release_revolving_shard.h
+ * @brief implementation of the release_revolving_shard function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_RELEASE_REVOLVING_SHARD_H
+#define PG_RELEASE_REVOLVING_SHARD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to release a revolving shard
+ * back into the work pool. Clears the
+ * "completed" flag.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param job_name name of the operation to grab a word shard for
+ * @param start_row inclusive start row of the shard
+ * @param end_row exclusive end row of the shard
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_release_revolving_shard (void *cls,
+ const char *job_name,
+ uint32_t start_row,
+ uint32_t end_row);
+
+#endif
diff --git a/src/exchangedb/pg_reserves_get.c b/src/exchangedb/pg_reserves_get.c
new file mode 100644
index 000000000..cae4764a5
--- /dev/null
+++ b/src/exchangedb/pg_reserves_get.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_get.c
+ * @brief Implementation of the reserves_get function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_reserves_get.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_get (void *cls,
+ struct TALER_EXCHANGEDB_Reserve *reserve)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ &reserve->balance),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &reserve->expiry),
+ GNUNET_PQ_result_spec_timestamp ("gc_date",
+ &reserve->gc),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_reserves_get() */
+ PREPARE (pg,
+ "reserves_get",
+ "SELECT"
+ " current_balance"
+ ",expiration_date"
+ ",gc_date"
+ " FROM reserves"
+ " WHERE reserve_pub=$1"
+ " LIMIT 1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "reserves_get",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_reserves_get.h b/src/exchangedb/pg_reserves_get.h
new file mode 100644
index 000000000..8a96d53ed
--- /dev/null
+++ b/src/exchangedb/pg_reserves_get.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_get.h
+ * @brief implementation of the reserves_get function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_RESERVES_GET_H
+#define PG_RESERVES_GET_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Get the summary of a reserve.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param[in,out] reserve the reserve data. The public key of the reserve should be
+ * set in this structure; it is used to query the database. The balance
+ * and expiration are then filled accordingly.
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_get (void *cls,
+ struct TALER_EXCHANGEDB_Reserve *reserve);
+
+#endif
diff --git a/src/exchangedb/pg_reserves_get_origin.c b/src/exchangedb/pg_reserves_get_origin.c
new file mode 100644
index 000000000..55d3179d1
--- /dev/null
+++ b/src/exchangedb/pg_reserves_get_origin.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_get_origin.c
+ * @brief Implementation of the reserves_get_origin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_reserves_get_origin.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_get_origin (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_PaytoHashP *h_payto)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("wire_source_h_payto",
+ h_payto),
+ GNUNET_PQ_result_spec_end
+ };
+
+
+ PREPARE (pg,
+ "get_h_wire_source_of_reserve",
+ "SELECT"
+ " wire_source_h_payto"
+ " FROM reserves_in"
+ " WHERE reserve_pub=$1");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "get_h_wire_source_of_reserve",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_reserves_get_origin.h b/src/exchangedb/pg_reserves_get_origin.h
new file mode 100644
index 000000000..22085d8f0
--- /dev/null
+++ b/src/exchangedb/pg_reserves_get_origin.h
@@ -0,0 +1,41 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_get_origin.h
+ * @brief implementation of the reserves_get_origin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_RESERVES_GET_ORIGIN_H
+#define PG_RESERVES_GET_ORIGIN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Get the origin of funds of a reserve.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param[out] h_payto set to hash of the wire source payto://-URI
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_get_origin (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_PaytoHashP *h_payto);
+
+#endif
diff --git a/src/exchangedb/pg_reserves_in_insert.c b/src/exchangedb/pg_reserves_in_insert.c
new file mode 100644
index 000000000..21734942a
--- /dev/null
+++ b/src/exchangedb/pg_reserves_in_insert.c
@@ -0,0 +1,373 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_in_insert.c
+ * @brief Implementation of the reserves_in_insert function for Postgres
+ * @author Christian Grothoff
+ * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_reserves_in_insert.h"
+#include "pg_helper.h"
+#include "pg_start.h"
+#include "pg_start_read_committed.h"
+#include "pg_commit.h"
+#include "pg_preflight.h"
+#include "pg_rollback.h"
+#include "pg_reserves_get.h"
+#include "pg_reserves_update.h"
+#include "pg_setup_wire_target.h"
+#include "pg_event_notify.h"
+
+
+/**
+ * Generate event notification for the reserve change.
+ *
+ * @param reserve_pub reserve to notfiy on
+ * @return string to pass to postgres for the notification
+ */
+static char *
+compute_notify_on_reserve (const struct TALER_ReservePublicKeyP *reserve_pub)
+{
+ struct TALER_ReserveEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
+ .reserve_pub = *reserve_pub
+ };
+
+ return GNUNET_PQ_get_event_notify_channel (&rep.header);
+}
+
+
+/**
+ * Closure for our helper_cb()
+ */
+struct Context
+{
+ /**
+ * Array of reserve UUIDs to initialize.
+ */
+ uint64_t *reserve_uuids;
+
+ /**
+ * Array with entries set to 'true' for duplicate transactions.
+ */
+ bool *transaction_duplicates;
+
+ /**
+ * Array with entries set to 'true' for rows with conflicts.
+ */
+ bool *conflicts;
+
+ /**
+ * Set to #GNUNET_SYSERR on failures.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+ /**
+ * Single value (no array) set to true if we need
+ * to follow-up with an update.
+ */
+ bool needs_update;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct Context *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct Context *ctx = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool (
+ "transaction_duplicate",
+ &ctx->transaction_duplicates[i]),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint64 ("ruuid",
+ &ctx->reserve_uuids[i]),
+ &ctx->conflicts[i]),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (! ctx->transaction_duplicates[i])
+ ctx->needs_update |= ctx->conflicts[i];
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_in_insert (
+ void *cls,
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserves,
+ unsigned int reserves_length,
+ enum GNUNET_DB_QueryStatus *results)
+{
+ struct PostgresClosure *pg = cls;
+ unsigned int dups = 0;
+
+ struct TALER_PaytoHashP h_paytos[GNUNET_NZL (reserves_length)];
+ char *notify_s[GNUNET_NZL (reserves_length)];
+ struct TALER_ReservePublicKeyP reserve_pubs[GNUNET_NZL (reserves_length)];
+ struct TALER_Amount balances[GNUNET_NZL (reserves_length)];
+ struct GNUNET_TIME_Timestamp execution_times[GNUNET_NZL (reserves_length)];
+ const char *sender_account_details[GNUNET_NZL (reserves_length)];
+ const char *exchange_account_names[GNUNET_NZL (reserves_length)];
+ uint64_t wire_references[GNUNET_NZL (reserves_length)];
+ uint64_t reserve_uuids[GNUNET_NZL (reserves_length)];
+ bool transaction_duplicates[GNUNET_NZL (reserves_length)];
+ bool conflicts[GNUNET_NZL (reserves_length)];
+ struct GNUNET_TIME_Timestamp reserve_expiration
+ = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
+ struct GNUNET_TIME_Timestamp gc
+ = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
+ enum GNUNET_DB_QueryStatus qs;
+ bool need_update;
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i];
+
+ TALER_payto_hash (reserve->sender_account_details,
+ &h_paytos[i]);
+ notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub);
+ reserve_pubs[i] = *reserve->reserve_pub;
+ balances[i] = *reserve->balance;
+ execution_times[i] = reserve->execution_time;
+ sender_account_details[i] = reserve->sender_account_details;
+ exchange_account_names[i] = reserve->exchange_account_name;
+ wire_references[i] = reserve->wire_reference;
+ }
+
+ /* NOTE: kind-of pointless to explicitly start a transaction here... */
+ if (GNUNET_OK !=
+ TEH_PG_preflight (pg))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+ if (GNUNET_OK !=
+ TEH_PG_start_read_committed (pg,
+ "READ_COMMITED"))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+ PREPARE (pg,
+ "reserves_insert_with_array",
+ "SELECT"
+ " transaction_duplicate"
+ ",ruuid"
+ " FROM exchange_do_array_reserves_insert"
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);");
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&gc),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_array_auto_from_type (reserves_length,
+ reserve_pubs,
+ pg->conn),
+ GNUNET_PQ_query_param_array_uint64 (reserves_length,
+ wire_references,
+ pg->conn),
+ TALER_PQ_query_param_array_amount (
+ reserves_length,
+ balances,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) exchange_account_names,
+ pg->conn),
+ GNUNET_PQ_query_param_array_timestamp (
+ reserves_length,
+ execution_times,
+ pg->conn),
+ GNUNET_PQ_query_param_array_auto_from_type (
+ reserves_length,
+ h_paytos,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) sender_account_details,
+ pg->conn),
+ GNUNET_PQ_query_param_array_ptrs_string (
+ reserves_length,
+ (const char **) notify_s,
+ pg->conn),
+ GNUNET_PQ_query_param_end
+ };
+ struct Context ctx = {
+ .reserve_uuids = reserve_uuids,
+ .transaction_duplicates = transaction_duplicates,
+ .conflicts = conflicts,
+ .needs_update = false,
+ .status = GNUNET_OK
+ };
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "reserves_insert_with_array",
+ params,
+ &helper_cb,
+ &ctx);
+ GNUNET_PQ_cleanup_query_params_closures (params);
+ if ( (qs < 0) ||
+ (GNUNET_OK != ctx.status) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to insert into reserves (%d)\n",
+ qs);
+ goto finished;
+ }
+ need_update = ctx.needs_update;
+ }
+
+ {
+ enum GNUNET_DB_QueryStatus cs;
+
+ cs = TEH_PG_commit (pg);
+ if (cs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to commit\n");
+ qs = cs;
+ goto finished;
+ }
+ }
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ if (transaction_duplicates[i])
+ dups++;
+ results[i] = transaction_duplicates[i]
+ ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+
+ if (! need_update)
+ {
+ qs = reserves_length;
+ goto finished;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Reserve update needed for some reserves in the batch\n");
+ PREPARE (pg,
+ "reserves_update",
+ "SELECT"
+ " out_duplicate AS duplicate "
+ "FROM exchange_do_batch_reserves_update"
+ " ($1,$2,$3,$4,$5,$6,$7);");
+
+ if (GNUNET_OK !=
+ TEH_PG_start (pg,
+ "reserve-insert-continued"))
+ {
+ GNUNET_break (0);
+ qs = GNUNET_DB_STATUS_HARD_ERROR;
+ goto finished;
+ }
+
+ for (unsigned int i = 0; i<reserves_length; i++)
+ {
+ if (transaction_duplicates[i])
+ continue;
+ if (! conflicts[i])
+ continue;
+ {
+ bool duplicate;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (&reserve_pubs[i]),
+ GNUNET_PQ_query_param_timestamp (&reserve_expiration),
+ GNUNET_PQ_query_param_uint64 (&wire_references[i]),
+ TALER_PQ_query_param_amount (pg->conn,
+ &balances[i]),
+ GNUNET_PQ_query_param_string (exchange_account_names[i]),
+ GNUNET_PQ_query_param_auto_from_type (&h_paytos[i]),
+ GNUNET_PQ_query_param_string (notify_s[i]),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_bool ("duplicate",
+ &duplicate),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "reserves_update",
+ params,
+ rs);
+ if (qs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update reserves (%d)\n",
+ qs);
+ results[i] = qs;
+ goto finished;
+ }
+ results[i] = duplicate
+ ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
+ : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+ }
+ }
+ {
+ enum GNUNET_DB_QueryStatus cs;
+
+ cs = TEH_PG_commit (pg);
+ if (cs < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to commit\n");
+ qs = cs;
+ goto finished;
+ }
+ }
+finished:
+ for (unsigned int i = 0; i<reserves_length; i++)
+ GNUNET_free (notify_s[i]);
+ if (qs < 0)
+ return qs;
+ GNUNET_PQ_event_do_poll (pg->conn);
+ if (0 != dups)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "%u/%u duplicates among incoming transactions. Try increasing WIREWATCH_IDLE_SLEEP_INTERVAL in the [exchange] configuration section (if this happens a lot).\n",
+ dups,
+ reserves_length);
+ return qs;
+}
diff --git a/src/exchangedb/pg_reserves_in_insert.h b/src/exchangedb/pg_reserves_in_insert.h
new file mode 100644
index 000000000..938df3adb
--- /dev/null
+++ b/src/exchangedb/pg_reserves_in_insert.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_in_insert.h
+ * @brief implementation of the reserves_in_insert function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_RESERVES_IN_INSERT_H
+#define PG_RESERVES_IN_INSERT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Insert an incoming transaction into reserves. New reserves are also
+ * created through this function. Runs its own transaction(s).
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserves array of reserves to insert
+ * @param reserves_length length of the @a reserves array
+ * @param[out] results set to query status per reserve, must be of length @a reserves_length
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_in_insert (
+ void *cls,
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserves,
+ unsigned int reserves_length,
+ enum GNUNET_DB_QueryStatus *results);
+
+
+#endif
diff --git a/src/exchangedb/pg_reserves_update.c b/src/exchangedb/pg_reserves_update.c
new file mode 100644
index 000000000..bfd32c6ce
--- /dev/null
+++ b/src/exchangedb/pg_reserves_update.c
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_update.c
+ * @brief Implementation of the reserves_update function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_reserves_update.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_update (void *cls,
+ const struct TALER_EXCHANGEDB_Reserve *reserve)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&reserve->expiry),
+ GNUNET_PQ_query_param_timestamp (&reserve->gc),
+ TALER_PQ_query_param_amount (pg->conn,
+ &reserve->balance),
+ GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "reserve_update",
+ "UPDATE reserves"
+ " SET"
+ " expiration_date=$1"
+ ",gc_date=$2"
+ ",current_balance=$3"
+ " WHERE reserve_pub=$4;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "reserve_update",
+ params);
+}
diff --git a/src/exchangedb/pg_reserves_update.h b/src/exchangedb/pg_reserves_update.h
new file mode 100644
index 000000000..24cf671da
--- /dev/null
+++ b/src/exchangedb/pg_reserves_update.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_reserves_update.h
+ * @brief implementation of the reserves_update function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_RESERVES_UPDATE_H
+#define PG_RESERVES_UPDATE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Updates a reserve with the data from the given reserve structure.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve the reserve structure whose data will be used to update the
+ * corresponding record in the database.
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_reserves_update (void *cls,
+ const struct TALER_EXCHANGEDB_Reserve *reserve);
+
+#endif
diff --git a/src/exchangedb/pg_rollback.c b/src/exchangedb/pg_rollback.c
new file mode 100644
index 000000000..3610487f3
--- /dev/null
+++ b/src/exchangedb/pg_rollback.c
@@ -0,0 +1,50 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_rollback.c
+ * @brief Implementation of the rollback function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_rollback.h"
+#include "pg_helper.h"
+
+
+void
+TEH_PG_rollback (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("ROLLBACK"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ if (NULL == pg->transaction_name)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Skipping rollback, no transaction active\n");
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Rolling back transaction\n");
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_PQ_exec_statements (pg->conn,
+ es));
+ pg->transaction_name = NULL;
+}
diff --git a/src/exchangedb/pg_rollback.h b/src/exchangedb/pg_rollback.h
new file mode 100644
index 000000000..ddb9e4111
--- /dev/null
+++ b/src/exchangedb/pg_rollback.h
@@ -0,0 +1,36 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_rollback.h
+ * @brief implementation of the rollback function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_ROLLBACK_H
+#define PG_ROLLBACK_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Roll back the current transaction of a database connection.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ */
+void
+TEH_PG_rollback (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_account_merges_above_serial_id.c b/src/exchangedb/pg_select_account_merges_above_serial_id.c
new file mode 100644
index 000000000..6c3c81121
--- /dev/null
+++ b/src/exchangedb/pg_select_account_merges_above_serial_id.c
@@ -0,0 +1,192 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_account_merges_above_serial_id.c
+ * @brief Implementation of the select_account_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_account_merges_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #account_merge_serial_helper_cb().
+ */
+struct AccountMergeSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AccountMergeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AccountMergeSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+account_merge_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AccountMergeSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct TALER_Amount amount;
+ uint32_t min_age;
+ uint32_t flags32;
+ enum TALER_WalletAccountMergeFlags flags;
+ struct TALER_Amount purse_fee;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
+ &purse_fee),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ &min_age),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ &purse_expiration),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ &merge_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("account_merge_request_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ flags = (enum TALER_WalletAccountMergeFlags) flags32;
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &purse_pub,
+ &h_contract_terms,
+ purse_expiration,
+ &amount,
+ min_age,
+ flags,
+ &purse_fee,
+ merge_timestamp,
+ &reserve_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_account_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AccountMergeSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_account_merge_incr",
+ "SELECT"
+ " am.account_merge_request_serial_id"
+ ",am.reserve_pub"
+ ",am.purse_pub"
+ ",pr.h_contract_terms"
+ ",pr.purse_expiration"
+ ",pr.amount_with_fee"
+ ",pr.age_limit"
+ ",pr.flags"
+ ",pr.purse_fee"
+ ",pm.merge_timestamp"
+ ",am.reserve_sig"
+ " FROM account_merges am"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " JOIN purse_merges pm USING (purse_pub)"
+ " WHERE ("
+ " (account_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY account_merge_request_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_account_merge_incr",
+ params,
+ &account_merge_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_account_merges_above_serial_id.h b/src/exchangedb/pg_select_account_merges_above_serial_id.h
new file mode 100644
index 000000000..be3bd7124
--- /dev/null
+++ b/src/exchangedb/pg_select_account_merges_above_serial_id.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_account_merges_above_serial_id.h
+ * @brief implementation of the select_account_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
+#define PG_SELECT_ACCOUNT_MERGES_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select account merges above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_account_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AccountMergeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
new file mode 100644
index 000000000..0d5d0ee25
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregation_amounts_for_kyc_check.c
+ * @brief Implementation of the select_aggregation_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aggregation_amounts_for_kyc_check.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregation_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "select_kyc_relevant_aggregation_events",
+ "SELECT"
+ " amount"
+ ",execution_date AS date"
+ " FROM wire_out"
+ " WHERE wire_target_h_payto=$1"
+ " AND execution_date >= $2"
+ " ORDER BY execution_date DESC");
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "select_kyc_relevant_aggregation_events",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.h b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.h
new file mode 100644
index 000000000..b91740581
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregation_amounts_for_kyc_check.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregation_amounts_for_kyc_check.h
+ * @brief implementation of the select_aggregation_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
+#define PG_SELECT_AGGREGATION_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Call @a kac on deposited amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the (credited) account identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregation_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_aggregation_transient.c b/src/exchangedb/pg_select_aggregation_transient.c
new file mode 100644
index 000000000..f9b6193ed
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregation_transient.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregation_transient.c
+ * @brief Implementation of the select_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aggregation_transient.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const char *exchange_account_section,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ total),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ wtid),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_select_aggregation_transient() */
+ PREPARE (pg,
+ "select_aggregation_transient",
+ "SELECT"
+ " amount"
+ " ,wtid_raw"
+ " FROM aggregation_transient"
+ " WHERE wire_target_h_payto=$1"
+ " AND merchant_pub=$2"
+ " AND exchange_account_section=$3;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_aggregation_transient",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_aggregation_transient.h b/src/exchangedb/pg_select_aggregation_transient.h
new file mode 100644
index 000000000..fd82a97aa
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregation_transient.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregation_transient.h
+ * @brief implementation of the select_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AGGREGATION_TRANSIENT_H
+#define PG_SELECT_AGGREGATION_TRANSIENT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Find existing entry in the transient aggregation table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param merchant_pub public key of the merchant receiving the transfer
+ * @param exchange_account_section exchange account to use
+ * @param[out] wtid set to the raw wire transfer identifier to be used
+ * @param[out] total existing amount to be wired in the future
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const char *exchange_account_section,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ struct TALER_Amount *total);
+#endif
diff --git a/src/exchangedb/pg_select_aggregations_above_serial.c b/src/exchangedb/pg_select_aggregations_above_serial.c
new file mode 100644
index 000000000..52d202702
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregations_above_serial.c
@@ -0,0 +1,137 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregations_above_serial.c
+ * @brief Implementation of the select_aggregations_above_serial function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aggregations_above_serial.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #aggregation_serial_helper_cb().
+ */
+struct AggregationSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AggregationCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct AggregationSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+aggregation_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AggregationSerialContext *dsc = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t tracking_rowid;
+ uint64_t batch_deposit_serial_id;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id",
+ &tracking_rowid),
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ dsc->cb (dsc->cb_cls,
+ tracking_rowid,
+ batch_deposit_serial_id);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregations_above_serial (
+ void *cls,
+ uint64_t min_tracking_serial_id,
+ TALER_EXCHANGEDB_AggregationCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&min_tracking_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AggregationSerialContext asc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch aggregations with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "select_aggregations_above_serial",
+ "SELECT"
+ " aggregation_serial_id"
+ ",batch_deposit_serial_id"
+ " FROM aggregation_tracking"
+ " WHERE aggregation_serial_id>=$1"
+ " ORDER BY aggregation_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "select_aggregations_above_serial",
+ params,
+ &aggregation_serial_helper_cb,
+ &asc);
+ if (GNUNET_OK != asc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_aggregations_above_serial.h b/src/exchangedb/pg_select_aggregations_above_serial.h
new file mode 100644
index 000000000..2883b19f2
--- /dev/null
+++ b/src/exchangedb/pg_select_aggregations_above_serial.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aggregations_above_serial.h
+ * @brief implementation of the select_aggregations_above_serial function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AGGREGATIONS_ABOVE_SERIAL_H
+#define PG_SELECT_AGGREGATIONS_ABOVE_SERIAL_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select all aggregation tracking IDs in the database
+ * above a given @a min_tracking_serial_id.
+ *
+ * @param cls closure
+ * @param min_tracking_serial_id only return entries strictly above this row (and in order)
+ * @param cb function to call on all such aggregations
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aggregations_above_serial (
+ void *cls,
+ uint64_t min_tracking_serial_id,
+ TALER_EXCHANGEDB_AggregationCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.c b/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.c
new file mode 100644
index 000000000..ba3307690
--- /dev/null
+++ b/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.c
@@ -0,0 +1,146 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_all_purse_decisions_above_serial_id.c
+ * @brief Implementation of the select_all_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_all_purse_decisions_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #all_purse_decision_serial_helper_cb().
+ */
+struct AllPurseDecisionSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+all_purse_decision_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AllPurseDecisionSerialContext *dsc = cls;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ bool refunded;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_bool ("refunded",
+ &refunded),
+ GNUNET_PQ_result_spec_uint64 ("purse_decision_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ refunded);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_all_purse_decisions_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct AllPurseDecisionSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_all_purse_decision_incr",
+ "SELECT"
+ " purse_pub"
+ ",refunded"
+ ",purse_decision_serial_id"
+ " FROM purse_decision"
+ " WHERE purse_decision_serial_id>=$1"
+ " ORDER BY purse_decision_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "audit_get_all_purse_decision_incr",
+ params,
+ &all_purse_decision_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.h b/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.h
new file mode 100644
index 000000000..634be4965
--- /dev/null
+++ b/src/exchangedb/pg_select_all_purse_decisions_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_all_purse_decisions_above_serial_id.h
+ * @brief implementation of the select_all_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_ALL_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select purse decisions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_all_purse_decisions_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_aml_history.c b/src/exchangedb/pg_select_aml_history.c
new file mode 100644
index 000000000..0461e0d9b
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_history.c
@@ -0,0 +1,157 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_history.c
+ * @brief Implementation of the select_aml_history function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aml_history.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlHistoryResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlHistoryCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TEH_PG_select_aml_history().
+ *
+ * @param cls closure of type `struct AmlHistoryResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmlHistoryResultContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount new_threshold;
+ uint32_t ns;
+ struct GNUNET_TIME_Timestamp decision_time;
+ char *justification;
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ struct TALER_AmlOfficerSignatureP decider_sig;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("new_threshold",
+ &new_threshold),
+ GNUNET_PQ_result_spec_uint32 ("new_status",
+ &ns),
+ GNUNET_PQ_result_spec_timestamp ("decision_time",
+ &decision_time),
+ GNUNET_PQ_result_spec_string ("justification",
+ &justification),
+ GNUNET_PQ_result_spec_auto_from_type ("decider_pub",
+ &decider_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("decider_sig",
+ &decider_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &new_threshold,
+ (enum TALER_AmlDecisionState) ns,
+ decision_time,
+ justification,
+ &decider_pub,
+ &decider_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_history (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlHistoryCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct AmlHistoryResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "lookup_aml_history",
+ "SELECT"
+ " new_threshold"
+ ",new_status"
+ ",decision_time"
+ ",justification"
+ ",decider_pub"
+ ",decider_sig"
+ " FROM aml_history"
+ " WHERE h_payto=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "lookup_aml_history",
+ params,
+ &handle_aml_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_aml_history.h b/src/exchangedb/pg_select_aml_history.h
new file mode 100644
index 000000000..78569947f
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_history.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_history.h
+ * @brief implementation of the select_aml_history function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AML_HISTORY_H
+#define PG_SELECT_AML_HISTORY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup AML decision history for a particular account.
+ *
+ * @param cls closure
+ * @param h_payto which account should we return the AML decision history for
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_history (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlHistoryCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_aml_process.c b/src/exchangedb/pg_select_aml_process.c
new file mode 100644
index 000000000..c34cae4bb
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_process.c
@@ -0,0 +1,170 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_process.c
+ * @brief Implementation of the select_aml_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aml_process.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #handle_aml_result.
+ */
+struct AmlProcessResultContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_AmlStatusCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on serious errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results. Helper function
+ * for #TEH_PG_select_aml_process().
+ *
+ * @param cls closure of type `struct AmlProcessResultContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+handle_aml_result (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct AmlProcessResultContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PaytoHashP h_payto;
+ struct TALER_Amount threshold;
+ uint64_t rowid;
+ uint32_t sv;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("aml_status_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ &h_payto),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("threshold",
+ &threshold),
+ GNUNET_PQ_result_spec_uint32 ("status",
+ &sv),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ rowid,
+ &h_payto,
+ &threshold,
+ (enum TALER_AmlDecisionState) sv);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_process (
+ void *cls,
+ enum TALER_AmlDecisionState decision,
+ uint64_t row_off,
+ uint64_t limit,
+ bool forward,
+ TALER_EXCHANGEDB_AmlStatusCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint32 (&decision),
+ GNUNET_PQ_query_param_uint64 (&row_off),
+ GNUNET_PQ_query_param_uint64 (&limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct AmlProcessResultContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ const char *stmt = forward
+ ? "select_aml_process_inc"
+ : "select_aml_process_dec";
+
+ PREPARE (pg,
+ "select_aml_process_inc",
+ "SELECT"
+ " aml_status_serial_id"
+ ",h_payto"
+ ",threshold"
+ ",status"
+ " FROM aml_status"
+ " WHERE aml_status_serial_id > $2"
+ " AND status = $1"
+ " ORDER BY aml_status_serial_id ASC"
+ " LIMIT $3");
+ PREPARE (pg,
+ "select_aml_process_dec",
+ "SELECT"
+ " aml_status_serial_id"
+ ",h_payto"
+ ",threshold"
+ ",status"
+ " FROM aml_status"
+ " WHERE aml_status_serial_id < $2"
+ " AND status = $1"
+ " ORDER BY aml_status_serial_id DESC"
+ " LIMIT $3");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ stmt,
+ params,
+ &handle_aml_result,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_aml_process.h b/src/exchangedb/pg_select_aml_process.h
new file mode 100644
index 000000000..648cace2e
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_process.h
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_process.h
+ * @brief implementation of the select_aml_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AML_PROCESS_H
+#define PG_SELECT_AML_PROCESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup AML decisions that have a particular state.
+ *
+ * @param cls closure
+ * @param decision which decision states to filter by
+ * @param row_off offset to start from
+ * @param limit how many rows to return at most
+ * @param forward true to go forward in time, false to go backwards
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_process (
+ void *cls,
+ enum TALER_AmlDecisionState decision,
+ uint64_t row_off,
+ uint64_t limit,
+ bool forward,
+ TALER_EXCHANGEDB_AmlStatusCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_aml_threshold.c b/src/exchangedb/pg_select_aml_threshold.c
new file mode 100644
index 000000000..23286f029
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_threshold.c
@@ -0,0 +1,70 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_threshold.c
+ * @brief Implementation of the select_aml_threshold function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_aml_threshold.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_threshold (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState *decision,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ struct TALER_Amount *threshold)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ uint32_t status32 = TALER_AML_NORMAL;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("threshold",
+ threshold),
+ GNUNET_PQ_result_spec_uint32 ("status",
+ &status32),
+ GNUNET_PQ_result_spec_uint64 ("kyc_requirement",
+ &kyc->requirement_row),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "select_aml_threshold",
+ "SELECT"
+ " threshold"
+ ",status"
+ ",kyc_requirement"
+ " FROM aml_status"
+ " WHERE h_payto=$1;");
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_aml_threshold",
+ params,
+ rs);
+ *decision = (enum TALER_AmlDecisionState) status32;
+ kyc->ok = (TALER_AML_FROZEN != *decision)
+ || (0 != kyc->requirement_row);
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_aml_threshold.h b/src/exchangedb/pg_select_aml_threshold.h
new file mode 100644
index 000000000..8f0e3bcfc
--- /dev/null
+++ b/src/exchangedb/pg_select_aml_threshold.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_aml_threshold.h
+ * @brief implementation of the select_aml_threshold function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AML_THRESHOLD_H
+#define PG_SELECT_AML_THRESHOLD_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Obtain the current AML threshold set for an account.
+ *
+ * @param cls closure
+ * @param h_payto account for which the AML threshold is stored
+ * @param[out] decision set to current AML decision
+ * @param[out] kyc set to KYC requirements imposed by AML, if any
+ * @param[out] threshold set to the existing threshold
+ * @return database transaction status, 0 if no threshold was set
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_aml_threshold (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState *decision,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ struct TALER_Amount *threshold);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_auditor_denom_sig.c b/src/exchangedb/pg_select_auditor_denom_sig.c
new file mode 100644
index 000000000..1dd6bd3d1
--- /dev/null
+++ b/src/exchangedb/pg_select_auditor_denom_sig.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_auditor_denom_sig.c
+ * @brief Implementation of the select_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_auditor_denom_sig.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_auditor_denom_sig (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct TALER_AuditorSignatureP *auditor_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
+ auditor_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "select_auditor_denom_sig",
+ "SELECT"
+ " auditor_sig"
+ " FROM auditor_denom_sigs"
+ " WHERE auditor_uuid="
+ " (SELECT auditor_uuid"
+ " FROM auditors"
+ " WHERE auditor_pub=$1)"
+ " AND denominations_serial="
+ " (SELECT denominations_serial"
+ " FROM denominations"
+ " WHERE denom_pub_hash=$2);");
+
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_auditor_denom_sig",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_auditor_denom_sig.h b/src/exchangedb/pg_select_auditor_denom_sig.h
new file mode 100644
index 000000000..0f635cf42
--- /dev/null
+++ b/src/exchangedb/pg_select_auditor_denom_sig.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_auditor_denom_sig.h
+ * @brief implementation of the select_auditor_denom_sig function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_AUDITOR_DENOM_SIG_H
+#define PG_SELECT_AUDITOR_DENOM_SIG_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Select information about an auditor auditing a denomination key.
+ *
+ * @param cls closure
+ * @param h_denom_pub the audited denomination
+ * @param auditor_pub the auditor's key
+ * @param[out] auditor_sig set to signature affirming the auditor's audit activity
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_auditor_denom_sig (
+ void *cls,
+ const struct TALER_DenominationHashP *h_denom_pub,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct TALER_AuditorSignatureP *auditor_sig);
+
+#endif
diff --git a/src/exchangedb/pg_select_batch_deposits_missing_wire.c b/src/exchangedb/pg_select_batch_deposits_missing_wire.c
new file mode 100644
index 000000000..8f966326a
--- /dev/null
+++ b/src/exchangedb/pg_select_batch_deposits_missing_wire.c
@@ -0,0 +1,144 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_batch_deposits_missing_wire.c
+ * @brief Implementation of the select_batch_deposits_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_batch_deposits_missing_wire.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #missing_wire_cb().
+ */
+struct MissingWireContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_WireMissingCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+missing_wire_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct MissingWireContext *mwc = cls;
+ struct PostgresClosure *pg = mwc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t batch_deposit_serial_id;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct TALER_PaytoHashP wire_target_h_payto;
+ struct TALER_Amount total_amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("batch_deposit_serial_id",
+ &batch_deposit_serial_id),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
+ &wire_target_h_payto),
+ GNUNET_PQ_result_spec_timestamp ("deadline",
+ &deadline),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total_amount",
+ &total_amount),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ mwc->status = GNUNET_SYSERR;
+ return;
+ }
+ mwc->cb (mwc->cb_cls,
+ batch_deposit_serial_id,
+ &total_amount,
+ &wire_target_h_payto,
+ deadline);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_batch_deposits_missing_wire (
+ void *cls,
+ uint64_t min_batch_deposit_serial_id,
+ TALER_EXCHANGEDB_WireMissingCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&min_batch_deposit_serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct MissingWireContext mwc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "deposits_get_deposits_missing_wire",
+ "SELECT"
+ " batch_deposit_serial_id"
+ ",wire_target_h_payto"
+ ",deadline"
+ ",total_amount"
+ " FROM exchange_do_select_deposits_missing_wire"
+ " ($1);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "deposits_get_deposits_missing_wire",
+ params,
+ &missing_wire_cb,
+ &mwc);
+ if (GNUNET_OK != mwc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_batch_deposits_missing_wire.h b/src/exchangedb/pg_select_batch_deposits_missing_wire.h
new file mode 100644
index 000000000..16f1d0cb3
--- /dev/null
+++ b/src/exchangedb/pg_select_batch_deposits_missing_wire.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_batch_deposits_missing_wire.h
+ * @brief implementation of the select_batch_deposits_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_DEPOSITS_MISSING_WIRE_H
+#define PG_SELECT_DEPOSITS_MISSING_WIRE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Select all of those batch deposits in the database
+ * above the given serial ID.
+ *
+ * @param cls closure
+ * @param min_batch_deposit_serial_id select all batch deposits above this ID
+ * @param cb function to call on all such deposits
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_batch_deposits_missing_wire (
+ void *cls,
+ uint64_t min_batch_deposit_serial_id,
+ TALER_EXCHANGEDB_WireMissingCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_coin_deposits_above_serial_id.c b/src/exchangedb/pg_select_coin_deposits_above_serial_id.c
new file mode 100644
index 000000000..000b908ed
--- /dev/null
+++ b/src/exchangedb/pg_select_coin_deposits_above_serial_id.c
@@ -0,0 +1,204 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_coin_deposits_above_serial_id.c
+ * @brief Implementation of the select_coin_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_coin_deposits_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #deposit_serial_helper_cb().
+ */
+struct CoinDepositSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_DepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct CoinDepositSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+coin_deposit_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct CoinDepositSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_Deposit deposit;
+ struct GNUNET_TIME_Timestamp exchange_timestamp;
+ struct TALER_DenominationPublicKey denom_pub;
+ bool done;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit.amount_with_fee),
+ GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
+ &deposit.timestamp),
+ GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
+ &exchange_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &deposit.merchant_pub),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &deposit.coin.coin_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit.coin.h_age_commitment),
+ &deposit.coin.no_age_commitment),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("wallet_data_hash",
+ &deposit.wallet_data_hash),
+ &deposit.no_wallet_data_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit.csig),
+ GNUNET_PQ_result_spec_timestamp ("refund_deadline",
+ &deposit.refund_deadline),
+ GNUNET_PQ_result_spec_timestamp ("wire_deadline",
+ &deposit.wire_deadline),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &deposit.h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
+ &deposit.wire_salt),
+ GNUNET_PQ_result_spec_string ("receiver_wire_account",
+ &deposit.receiver_wire_account),
+ GNUNET_PQ_result_spec_bool ("done",
+ &done),
+ GNUNET_PQ_result_spec_uint64 ("coin_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ memset (&deposit,
+ 0,
+ sizeof (deposit));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ exchange_timestamp,
+ &deposit,
+ &denom_pub,
+ done);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_coin_deposits_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_DepositCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct CoinDepositSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch deposits with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "audit_get_coin_deposits_incr",
+ "SELECT"
+ " cdep.amount_with_fee"
+ ",bdep.wallet_timestamp"
+ ",bdep.exchange_timestamp"
+ ",bdep.merchant_pub"
+ ",bdep.wallet_data_hash"
+ ",denom.denom_pub"
+ ",kc.coin_pub"
+ ",kc.age_commitment_hash"
+ ",cdep.coin_sig"
+ ",bdep.refund_deadline"
+ ",bdep.wire_deadline"
+ ",bdep.h_contract_terms"
+ ",bdep.wire_salt"
+ ",wt.payto_uri AS receiver_wire_account"
+ ",bdep.done"
+ ",cdep.coin_deposit_serial_id"
+ " FROM coin_deposits cdep"
+ " JOIN batch_deposits bdep"
+ " USING (batch_deposit_serial_id)"
+ " JOIN wire_targets wt"
+ " USING (wire_target_h_payto)"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE (coin_deposit_serial_id>=$1)"
+ " ORDER BY coin_deposit_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_coin_deposits_incr",
+ params,
+ &coin_deposit_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_coin_deposits_above_serial_id.h b/src/exchangedb/pg_select_coin_deposits_above_serial_id.h
new file mode 100644
index 000000000..5202336a4
--- /dev/null
+++ b/src/exchangedb/pg_select_coin_deposits_above_serial_id.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_coin_deposits_above_serial_id.h
+ * @brief implementation of the select_coin_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_DEPOSITS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_DEPOSITS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Select deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_coin_deposits_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_DepositCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_contract.c b/src/exchangedb/pg_select_contract.c
new file mode 100644
index 000000000..3e6bf22bc
--- /dev/null
+++ b/src/exchangedb/pg_select_contract.c
@@ -0,0 +1,66 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_contract.c
+ * @brief Implementation of the select_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_contract.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_contract (void *cls,
+ const struct TALER_ContractDiffiePublicP *pub_ckey,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseContractSignatureP *econtract_sig,
+ size_t *econtract_size,
+ void **econtract)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (pub_ckey),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
+ econtract_sig),
+ GNUNET_PQ_result_spec_variable_size ("e_contract",
+ econtract,
+ econtract_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ /* Used in #postgres_select_contract */
+ PREPARE (pg,
+ "select_contract",
+ "SELECT "
+ " purse_pub"
+ ",e_contract"
+ ",contract_sig"
+ " FROM contracts"
+ " WHERE pub_ckey=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_contract",
+ params,
+ rs);
+
+}
diff --git a/src/exchangedb/pg_select_contract.h b/src/exchangedb/pg_select_contract.h
new file mode 100644
index 000000000..747a82753
--- /dev/null
+++ b/src/exchangedb/pg_select_contract.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_contract.h
+ * @brief implementation of the select_contract function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_CONTRACT_H
+#define PG_SELECT_CONTRACT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to retrieve an encrypted contract.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub key to lookup the contract by
+ * @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
+ * @param[out] econtract_sig set to the signature over the encrypted contract
+ * @param[out] econtract_size set to the number of bytes in @a econtract
+ * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_contract (void *cls,
+ const struct TALER_ContractDiffiePublicP *pub_ckey,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseContractSignatureP *econtract_sig,
+ size_t *econtract_size,
+ void **econtract);
+
+#endif
diff --git a/src/exchangedb/pg_select_contract_by_purse.c b/src/exchangedb/pg_select_contract_by_purse.c
new file mode 100644
index 000000000..8d29b3954
--- /dev/null
+++ b/src/exchangedb/pg_select_contract_by_purse.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_contract_by_purse.c
+ * @brief Implementation of the select_contract_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_contract_by_purse.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_contract_by_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_EncryptedContract *econtract)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("pub_ckey",
+ &econtract->contract_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
+ &econtract->econtract_sig),
+ GNUNET_PQ_result_spec_variable_size ("e_contract",
+ &econtract->econtract,
+ &econtract->econtract_size),
+ GNUNET_PQ_result_spec_end
+ };
+ /* Used in #postgres_select_contract_by_purse */
+ PREPARE (pg,
+ "select_contract_by_purse",
+ "SELECT "
+ " pub_ckey"
+ ",e_contract"
+ ",contract_sig"
+ " FROM contracts"
+ " WHERE purse_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_contract_by_purse",
+ params,
+ rs);
+
+}
diff --git a/src/exchangedb/pg_select_contract_by_purse.h b/src/exchangedb/pg_select_contract_by_purse.h
new file mode 100644
index 000000000..0e33a6ba1
--- /dev/null
+++ b/src/exchangedb/pg_select_contract_by_purse.h
@@ -0,0 +1,42 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_contract_by_purse.h
+ * @brief implementation of the select_contract_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_CONTRACT_BY_PURSE_H
+#define PG_SELECT_CONTRACT_BY_PURSE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to retrieve an encrypted contract.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub key to lookup the contract by
+ * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_contract_by_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_EncryptedContract *econtract);
+#endif
diff --git a/src/exchangedb/pg_select_justification_for_missing_wire.c b/src/exchangedb/pg_select_justification_for_missing_wire.c
new file mode 100644
index 000000000..77d5b4de7
--- /dev/null
+++ b/src/exchangedb/pg_select_justification_for_missing_wire.c
@@ -0,0 +1,89 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_batch_deposits_missing_wire.c
+ * @brief Implementation of the select_batch_deposits_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_batch_deposits_missing_wire.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_justification_for_missing_wire (
+ void *cls,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ char **payto_uri,
+ char **kyc_pending,
+ enum TALER_AmlDecisionState *status,
+ struct TALER_Amount *aml_limit)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (wire_target_h_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ uint32_t aml_status32;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("kyc_pending",
+ kyc_pending),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_uint32 ("aml_status",
+ &aml_status32),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ TALER_PQ_RESULT_SPEC_AMOUNT ("aml_limit",
+ aml_limit),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "deposits_get_overdue",
+ "SELECT"
+ " out_payto_uri AS payto_uri"
+ ",out_kyc_pending AS kyc_pending"
+ ",out_deadline AS deadline"
+ ",out_aml_status AS aml_status"
+ ",out_aml_limit AS aml_limit"
+ " FROM exchange_do_select_justification_missing_wire"
+ " ($1, $2);");
+ memset (aml_limit,
+ 0,
+ sizeof (*aml_limit));
+ qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "",
+ params,
+ rs);
+ if (qs <= 0)
+ return qs;
+ *status = (enum TALER_AmlDecisionState) aml_status32;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_justification_for_missing_wire.h b/src/exchangedb/pg_select_justification_for_missing_wire.h
new file mode 100644
index 000000000..7f73eb511
--- /dev/null
+++ b/src/exchangedb/pg_select_justification_for_missing_wire.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_justification_for_missing_wire.h
+ * @brief implementation of the select_justification_for_missing_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_JUSTIFICATION_FOR_MISSING_WIRE_H
+#define PG_SELECT_JUSTIFICATION_FOR_MISSING_WIRE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select all of those justifications for why we might not have
+ * done a wire transfer from in the database for a particular target account.
+ *
+ * @param cls closure
+ * @param wire_target_h_payto effected target account
+ * @param[out] payto_uri target account URI, set to NULL if unknown
+ * @param[out] kyc_pending set to string describing missing KYC data
+ * @param[out] status set to AML status
+ * @param[out] aml_limit set to AML limit, or invalid amount for none
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_justification_for_missing_wire (
+ void *cls,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ char **payto_uri,
+ char **kyc_pending,
+ enum TALER_AmlDecisionState *status,
+ struct TALER_Amount *aml_limit);
+
+#endif
diff --git a/src/exchangedb/pg_select_kyc_attributes.c b/src/exchangedb/pg_select_kyc_attributes.c
new file mode 100644
index 000000000..99ac43b3e
--- /dev/null
+++ b/src/exchangedb/pg_select_kyc_attributes.c
@@ -0,0 +1,156 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_kyc_attributes.c
+ * @brief Implementation of the select_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_kyc_attributes.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_attributes_cb().
+ */
+struct GetAttributesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_AttributeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Key of our query.
+ */
+ const struct TALER_PaytoHashP *h_payto;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct GetAttributesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_attributes_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetAttributesContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ size_t enc_attributes_size;
+ void *enc_attributes;
+ char *provider;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider",
+ &provider),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_timestamp ("expiration_time",
+ &expiration_time),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &enc_attributes,
+ &enc_attributes_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ ctx->h_payto,
+ provider,
+ collection_time,
+ expiration_time,
+ enc_attributes_size,
+ enc_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_kyc_attributes (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetAttributesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .h_payto = h_payto,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "select_kyc_attributes",
+ "SELECT "
+ " provider"
+ ",collection_time"
+ ",expiration_time"
+ ",encrypted_attributes"
+ " FROM kyc_attributes"
+ " WHERE h_payto=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "select_kyc_attributes",
+ params,
+ &get_attributes_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_kyc_attributes.h b/src/exchangedb/pg_select_kyc_attributes.h
new file mode 100644
index 000000000..7458aefe8
--- /dev/null
+++ b/src/exchangedb/pg_select_kyc_attributes.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_kyc_attributes.h
+ * @brief implementation of the select_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_KYC_ATTRIBUTES_H
+#define PG_SELECT_KYC_ATTRIBUTES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup KYC attribute data for a specific account.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_kyc_attributes (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c
new file mode 100644
index 000000000..417d78ec7
--- /dev/null
+++ b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.c
@@ -0,0 +1,157 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_merge_amounts_for_kyc_check.c
+ * @brief Implementation of the select_merge_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_merge_amounts_for_kyc_check.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_merge_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+
+ PREPARE (pg,
+ "select_kyc_relevant_merge_events",
+ "SELECT"
+ " amount_with_fee AS amount"
+ ",merge_timestamp AS date"
+ " FROM account_merges"
+ " JOIN purse_merges USING (purse_pub)"
+ " JOIN purse_requests USING (purse_pub)"
+ " JOIN purse_decision USING (purse_pub)"
+ " WHERE wallet_h_payto=$1"
+ " AND merge_timestamp >= $2"
+ " AND NOT refunded"
+ " ORDER BY merge_timestamp DESC");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "select_kyc_relevant_merge_events",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_merge_amounts_for_kyc_check.h b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.h
new file mode 100644
index 000000000..5d0a96359
--- /dev/null
+++ b/src/exchangedb/pg_select_merge_amounts_for_kyc_check.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_merge_amounts_for_kyc_check.h
+ * @brief implementation of the select_merge_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_MERGE_AMOUNTS_FOR_KYC_CHECK_H
+#define PG_SELECT_MERGE_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Call @a kac on merged reserve amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the wallet identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_merge_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse.c b/src/exchangedb/pg_select_purse.c
new file mode 100644
index 000000000..ffccb905c
--- /dev/null
+++ b/src/exchangedb/pg_select_purse.c
@@ -0,0 +1,94 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse.c
+ * @brief Implementation of the select_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_creation,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_Amount *amount,
+ struct TALER_Amount *deposited,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ bool *purse_deleted,
+ bool *purse_refunded)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ purse_expiration),
+ GNUNET_PQ_result_spec_timestamp ("purse_creation",
+ purse_creation),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ deposited),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ h_contract_terms),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ merge_timestamp),
+ NULL),
+ GNUNET_PQ_result_spec_bool ("purse_deleted",
+ purse_deleted),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_bool ("purse_refunded",
+ purse_refunded),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "select_purse",
+ "SELECT "
+ " pr.merge_pub"
+ ",pr.purse_creation"
+ ",pr.purse_expiration"
+ ",pr.h_contract_terms"
+ ",pr.amount_with_fee"
+ ",pr.balance"
+ ",pm.merge_timestamp"
+ ",pd.purse_sig IS NOT NULL AS purse_deleted"
+ ",pc.refunded AS purse_refunded"
+ " FROM purse_requests pr"
+ " LEFT JOIN purse_merges pm ON (pm.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_decision pc ON (pc.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_deletion pd ON (pd.purse_pub = pr.purse_pub)"
+ " WHERE pr.purse_pub=$1;");
+ *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
+ *purse_refunded = false;
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_purse",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_purse.h b/src/exchangedb/pg_select_purse.h
new file mode 100644
index 000000000..8f88c5cf7
--- /dev/null
+++ b/src/exchangedb/pg_select_purse.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse.h
+ * @brief implementation of the select_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_H
+#define PG_SELECT_PURSE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to obtain information about a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the new purse
+ * @param[out] purse_creation set to time when the purse was created
+ * @param[out] purse_expiration set to time when the purse will expire
+ * @param[out] amount set to target amount (with fees) to be put into the purse
+ * @param[out] deposited set to actual amount put into the purse so far
+ * @param[out] h_contract_terms set to hash of the contract for the purse
+ * @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
+ * @param[out] purse_deleted set to true if purse was deleted
+ * @param[out] purse_refunded set to true if purse was refunded
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_creation,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_Amount *amount,
+ struct TALER_Amount *deposited,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ bool *purse_deleted,
+ bool *purse_refunded);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_by_merge_pub.c b/src/exchangedb/pg_select_purse_by_merge_pub.c
new file mode 100644
index 000000000..d035b3255
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_by_merge_pub.c
@@ -0,0 +1,79 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_by_merge_pub.c
+ * @brief Implementation of the select_purse_by_merge_pub function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_by_merge_pub.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_by_merge_pub (
+ void *cls,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *target_amount,
+ struct TALER_Amount *balance,
+ struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (merge_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ purse_pub),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ h_contract_terms),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ age_limit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ target_amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ balance),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ purse_sig),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "select_purse_by_merge_pub",
+ "SELECT "
+ " purse_pub"
+ ",purse_expiration"
+ ",h_contract_terms"
+ ",age_limit"
+ ",amount_with_fee"
+ ",balance"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE merge_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_purse_by_merge_pub",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_purse_by_merge_pub.h b/src/exchangedb/pg_select_purse_by_merge_pub.h
new file mode 100644
index 000000000..2a7667132
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_by_merge_pub.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_by_merge_pub.h
+ * @brief implementation of the select_purse_by_merge_pub function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_BY_MERGE_PUB_H
+#define PG_SELECT_PURSE_BY_MERGE_PUB_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to return meta data about a purse by the
+ * merge capability key.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param merge_pub public key representing the merge capability
+ * @param[out] purse_pub public key of the purse
+ * @param[out] purse_expiration when would an unmerged purse expire
+ * @param[out] h_contract_terms contract associated with the purse
+ * @param[out] age_limit the age limit for deposits into the purse
+ * @param[out] target_amount amount to be put into the purse
+ * @param[out] balance amount put so far into the purse
+ * @param[out] purse_sig signature of the purse over the initialization data
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_by_merge_pub (
+ void *cls,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_expiration,
+ struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t *age_limit,
+ struct TALER_Amount *target_amount,
+ struct TALER_Amount *balance,
+ struct TALER_PurseContractSignatureP *purse_sig);
+#endif
diff --git a/src/exchangedb/pg_select_purse_decisions_above_serial_id.c b/src/exchangedb/pg_select_purse_decisions_above_serial_id.c
new file mode 100644
index 000000000..f301ea78a
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_decisions_above_serial_id.c
@@ -0,0 +1,162 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_decisions_above_serial_id.c
+ * @brief Implementation of the select_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_decisions_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #purse_decision_serial_helper_cb().
+ */
+struct PurseDecisionSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseDecisionCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_decision_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseDecisionSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ bool no_reserve = true;
+ uint64_t rowid;
+ struct TALER_Amount val;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ &no_reserve),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &val),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ no_reserve ? NULL : &reserve_pub,
+ &val);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_decisions_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ bool refunded,
+ TALER_EXCHANGEDB_PurseDecisionCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_bool (refunded),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseDecisionSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_purse_decisions_incr",
+ "SELECT"
+ " pd.purse_pub"
+ ",pm.reserve_pub"
+ ",pd.purse_decision_serial_id"
+ ",pr.amount_with_fee"
+ " FROM purse_decision pd"
+ " JOIN purse_requests pr ON (pd.purse_pub = pr.purse_pub)"
+ " LEFT JOIN purse_merges pm ON (pm.purse_pub = pd.purse_pub)"
+ " WHERE ("
+ " (purse_decision_serial_id>=$1) AND "
+ " (refunded=$2)"
+ " )"
+ " ORDER BY purse_decision_serial_id ASC;");
+
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_purse_decisions_incr",
+ params,
+ &purse_decision_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_purse_decisions_above_serial_id.h b/src/exchangedb/pg_select_purse_decisions_above_serial_id.h
new file mode 100644
index 000000000..83168d546
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_decisions_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_decisions_above_serial_id.h
+ * @brief implementation of the select_purse_decisions_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_PURSE_DECISIONS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select purse decisions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param refunded which refund status to select for
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_decisions_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ bool refunded,
+ TALER_EXCHANGEDB_PurseDecisionCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_deposits_above_serial_id.c b/src/exchangedb/pg_select_purse_deposits_above_serial_id.c
new file mode 100644
index 000000000..bb4320663
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_deposits_above_serial_id.c
@@ -0,0 +1,201 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_deposits_above_serial_id.c
+ * @brief Implementation of the select_purse_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_deposits_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseDepositSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseDepositCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct DepositSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_deposit_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseDepositSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_PurseDeposit deposit = {
+ .exchange_base_url = NULL
+ };
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ uint32_t flags32;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ bool not_merged = false;
+ struct TALER_Amount purse_balance;
+ struct TALER_Amount purse_total;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &deposit.amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &purse_balance),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("total",
+ &purse_total),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee",
+ &deposit.deposit_fee),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ &deposit.exchange_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ &not_merged),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &deposit.purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &deposit.coin_sig),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &deposit.coin_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &deposit.h_age_commitment),
+ &deposit.no_age_commitment),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ memset (&deposit,
+ 0,
+ sizeof (deposit));
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &deposit,
+ not_merged ? NULL : &reserve_pub,
+ (enum TALER_WalletAccountMergeFlags) flags32,
+ &purse_balance,
+ &purse_total,
+ &denom_pub);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_deposits_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseDepositCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseDepositSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_purse_deposits_incr",
+ "SELECT"
+ " pd.amount_with_fee"
+ ",pr.amount_with_fee AS total"
+ ",pr.balance"
+ ",pr.flags"
+ ",pd.purse_pub"
+ ",pd.coin_sig"
+ ",partner_base_url"
+ ",denom.denom_pub"
+ ",pm.reserve_pub"
+ ",kc.coin_pub"
+ ",kc.age_commitment_hash"
+ ",pd.purse_deposit_serial_id"
+ " FROM purse_deposits pd"
+ " LEFT JOIN partners USING (partner_serial_id)"
+ " LEFT JOIN purse_merges pm USING (purse_pub)"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " JOIN known_coins kc USING (coin_pub)"
+ " JOIN denominations denom USING (denominations_serial)"
+ " WHERE ("
+ " (purse_deposit_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_deposit_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_purse_deposits_incr",
+ params,
+ &purse_deposit_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_purse_deposits_above_serial_id.h b/src/exchangedb/pg_select_purse_deposits_above_serial_id.h
new file mode 100644
index 000000000..34d50b2ab
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_deposits_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_deposits_above_serial_id.h
+ * @brief implementation of the select_purse_deposits_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_PURSE_DEPOSITS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_deposits_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseDepositCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_deposits_by_purse.c b/src/exchangedb/pg_select_purse_deposits_by_purse.c
new file mode 100644
index 000000000..94b935cb4
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_deposits_by_purse.c
@@ -0,0 +1,153 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_deposits_by_purse.c
+ * @brief Implementation of the select_purse_deposits_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_deposits_by_purse.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #purse_refund_coin_helper_cb().
+ */
+struct PurseRefundCoinContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseRefundCoinCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRefundCoinContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_refund_coin_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseRefundCoinContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount_with_fee;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &amount_with_fee,
+ &coin_pub,
+ &denom_pub);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_deposits_by_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ TALER_EXCHANGEDB_PurseRefundCoinCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseRefundCoinContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_purse_deposits_by_purse",
+ "SELECT"
+ " pd.purse_deposit_serial_id"
+ ",pd.amount_with_fee"
+ ",pd.coin_pub"
+ ",denom.denom_pub"
+ " FROM purse_deposits pd"
+ " JOIN known_coins kc"
+ " USING (coin_pub)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE purse_pub=$1;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_purse_deposits_by_purse",
+ params,
+ &purse_refund_coin_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_purse_deposits_by_purse.h b/src/exchangedb/pg_select_purse_deposits_by_purse.h
new file mode 100644
index 000000000..203f9a151
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_deposits_by_purse.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_deposits_by_purse.h
+ * @brief implementation of the select_purse_deposits_by_purse function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_DEPOSITS_BY_PURSE_H
+#define PG_SELECT_PURSE_DEPOSITS_BY_PURSE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select coin affected by purse refund.
+ *
+ * @param cls closure
+ * @param purse_pub purse that was refunded
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_deposits_by_purse (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ TALER_EXCHANGEDB_PurseRefundCoinCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_merge.c b/src/exchangedb/pg_select_purse_merge.c
new file mode 100644
index 000000000..ecc047cc5
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_merge.c
@@ -0,0 +1,80 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_merge.c
+ * @brief Implementation of the select_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_merge.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_merge (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseMergeSignatureP *merge_sig,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ char **partner_url,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *refunded)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
+ merge_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ reserve_pub),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ merge_timestamp),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ partner_url),
+ NULL),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_bool ("refunded",
+ refunded),
+ NULL),
+ GNUNET_PQ_result_spec_end
+ };
+
+ *partner_url = NULL;
+ *refunded = false;
+ PREPARE (pg,
+ "select_purse_merge",
+ "SELECT "
+ " pm.reserve_pub"
+ ",pm.merge_sig"
+ ",pm.merge_timestamp"
+ ",pr.partner_base_url"
+ ",pd.refunded"
+ " FROM purse_merges pm"
+ " LEFT JOIN purse_decision pd USING (purse_pub)"
+ " LEFT JOIN partners pr USING (partner_serial_id)"
+ " WHERE pm.purse_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_purse_merge",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_purse_merge.h b/src/exchangedb/pg_select_purse_merge.h
new file mode 100644
index 000000000..8054974aa
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_merge.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_purse_merge.h
+ * @brief implementation of the select_purse_merge function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_MERGE_H
+#define PG_SELECT_PURSE_MERGE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to approve merging of a purse with
+ * an account, made by the receiving account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub public key of the purse
+ * @param[out] merge_sig set to the signature confirming the merge
+ * @param[out] merge_timestamp set to the time of the merge
+ * @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller.
+ * @param[out] reserve_pub set to the public key of the reserve/account being credited
+ * @param[out] refunded set to true if purse was refunded
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_merge (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_PurseMergeSignatureP *merge_sig,
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ char **partner_url,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *refunded);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_merges_above_serial_id.c b/src/exchangedb/pg_select_purse_merges_above_serial_id.c
new file mode 100644
index 000000000..cd06d65e9
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_merges_above_serial_id.c
@@ -0,0 +1,190 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_merges_above_serial_id.c
+ * @brief Implementation of the select_purse_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_merges_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseMergeSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseMergeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseMergeSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_merges_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseMergeSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ char *partner_base_url = NULL;
+ struct TALER_Amount amount;
+ struct TALER_Amount balance;
+ uint32_t flags32;
+ enum TALER_WalletAccountMergeFlags flags;
+ struct TALER_PurseMergePublicKeyP merge_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_PurseMergeSignatureP merge_sig;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct GNUNET_TIME_Timestamp merge_timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
+ &balance),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_string ("partner_base_url",
+ &partner_base_url),
+ NULL),
+ GNUNET_PQ_result_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
+ &merge_timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
+ &merge_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ &merge_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_merge_request_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ flags = (enum TALER_WalletAccountMergeFlags) flags32;
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ partner_base_url,
+ &amount,
+ &balance,
+ flags,
+ &merge_pub,
+ &reserve_pub,
+ &merge_sig,
+ &purse_pub,
+ merge_timestamp);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseMergeSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_purse_merge_incr",
+ "SELECT"
+ " pm.purse_merge_request_serial_id"
+ ",partner_base_url"
+ ",pr.amount_with_fee"
+ ",pr.balance"
+ ",pr.flags"
+ ",pr.merge_pub"
+ ",pm.reserve_pub"
+ ",pm.merge_sig"
+ ",pm.purse_pub"
+ ",pm.merge_timestamp"
+ " FROM purse_merges pm"
+ " JOIN purse_requests pr USING (purse_pub)"
+ " LEFT JOIN partners USING (partner_serial_id)"
+ " WHERE ("
+ " (purse_merge_request_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_merge_request_serial_id ASC;");
+
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_purse_merge_incr",
+ params,
+ &purse_merges_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_purse_merges_above_serial_id.h b/src/exchangedb/pg_select_purse_merges_above_serial_id.h
new file mode 100644
index 000000000..d63db55dd
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_merges_above_serial_id.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_merges_above_serial_id.h
+ * @brief implementation of the select_purse_merges_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_MERGES_ABOVE_SERIAL_ID_H
+#define PG_SELECT_PURSE_MERGES_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select purse merges deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_merges_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseMergeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_purse_requests_above_serial_id.c b/src/exchangedb/pg_select_purse_requests_above_serial_id.c
new file mode 100644
index 000000000..61a4f2041
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_requests_above_serial_id.c
@@ -0,0 +1,178 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_requests_above_serial_id.c
+ * @brief Implementation of the select_purse_requests_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_purse_requests_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #purse_deposit_serial_helper_cb().
+ */
+struct PurseRequestsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_PurseRequestCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct PurseRequestsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+purse_requests_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PurseRequestsSerialContext *dsc = cls;
+ struct PostgresClosure *pg = dsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_Amount target_amount;
+ uint32_t age_limit;
+ struct TALER_PurseMergePublicKeyP merge_pub;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_PurseContractSignatureP purse_sig;
+ struct GNUNET_TIME_Timestamp purse_creation;
+ struct GNUNET_TIME_Timestamp purse_expiration;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &target_amount),
+ GNUNET_PQ_result_spec_uint32 ("age_limit",
+ &age_limit),
+ GNUNET_PQ_result_spec_timestamp ("purse_creation",
+ &purse_creation),
+ GNUNET_PQ_result_spec_timestamp ("purse_expiration",
+ &purse_expiration),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
+ &purse_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &h_contract_terms),
+ GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
+ &purse_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
+ &merge_pub),
+ GNUNET_PQ_result_spec_uint64 ("purse_requests_request_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ dsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = dsc->cb (dsc->cb_cls,
+ rowid,
+ &purse_pub,
+ &merge_pub,
+ purse_creation,
+ purse_expiration,
+ &h_contract_terms,
+ age_limit,
+ &target_amount,
+ &purse_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_requests_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseRequestCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct PurseRequestsSerialContext dsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_purse_requests_incr",
+ "SELECT"
+ " purse_requests_serial_id"
+ ",purse_pub"
+ ",amount_with_fee"
+ ",age_limit"
+ ",h_contract_terms"
+ ",purse_creation"
+ ",purse_expiration"
+ ",merge_pub"
+ ",purse_sig"
+ " FROM purse_requests"
+ " WHERE ("
+ " (purse_requests_serial_id>=$1)"
+ " )"
+ " ORDER BY purse_requests_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_purse_requests_incr",
+ params,
+ &purse_requests_serial_helper_cb,
+ &dsc);
+ if (GNUNET_OK != dsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_purse_requests_above_serial_id.h b/src/exchangedb/pg_select_purse_requests_above_serial_id.h
new file mode 100644
index 000000000..25323e3d0
--- /dev/null
+++ b/src/exchangedb/pg_select_purse_requests_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_purse_requests_above_serial_id.h
+ * @brief implementation of the select_purse_requests_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_PURSE_REQUESTS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select purse requestss deposits above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_purse_requests_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseRequestCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_recoup_above_serial_id.c b/src/exchangedb/pg_select_recoup_above_serial_id.c
new file mode 100644
index 000000000..5791ee500
--- /dev/null
+++ b/src/exchangedb/pg_select_recoup_above_serial_id.c
@@ -0,0 +1,194 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_recoup_above_serial_id.c
+ * @brief Implementation of the select_recoup_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_recoup_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #recoup_serial_helper_cb().
+ */
+struct RecoupSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RecoupCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RecoupSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+recoup_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RecoupSerialContext *psc = cls;
+ struct PostgresClosure *pg = psc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_CoinPublicInfo coin;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_Amount amount;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_BlindedCoinHashP h_blind_ev;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin.coin_pub),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &coin_blind),
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &h_blind_ev),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &coin.denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &coin.h_age_commitment),
+ &coin.no_age_commitment),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &coin.denom_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ psc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = psc->cb (psc->cb_cls,
+ rowid,
+ timestamp,
+ &amount,
+ &reserve_pub,
+ &coin,
+ &denom_pub,
+ &coin_sig,
+ &coin_blind);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_recoup_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RecoupSerialContext psc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "recoup_get_incr",
+ "SELECT"
+ " recoup_uuid"
+ ",recoup_timestamp"
+ ",reserves.reserve_pub"
+ ",coins.coin_pub"
+ ",coin_sig"
+ ",coin_blind"
+ ",ro.h_blind_ev"
+ ",denoms.denom_pub_hash"
+ ",coins.denom_sig"
+ ",coins.age_commitment_hash"
+ ",denoms.denom_pub"
+ ",amount"
+ " FROM recoup"
+ " JOIN known_coins coins"
+ " USING (coin_pub)"
+ " JOIN reserves_out ro"
+ " USING (reserve_out_serial_id)"
+ " JOIN reserves"
+ " USING (reserve_uuid)"
+ " JOIN denominations denoms"
+ " ON (coins.denominations_serial = denoms.denominations_serial)"
+ " WHERE recoup_uuid>=$1"
+ " ORDER BY recoup_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "recoup_get_incr",
+ params,
+ &recoup_serial_helper_cb,
+ &psc);
+ if (GNUNET_OK != psc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_recoup_above_serial_id.h b/src/exchangedb/pg_select_recoup_above_serial_id.h
new file mode 100644
index 000000000..9be0b5c35
--- /dev/null
+++ b/src/exchangedb/pg_select_recoup_above_serial_id.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_recoup_above_serial_id.h
+ * @brief implementation of the select_recoup_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RECOUP_ABOVE_SERIAL_ID_H
+#define PG_SELECT_RECOUP_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Function called to select recoup requests the exchange
+ * received, ordered by serial ID (monotonically increasing).
+ *
+ * @param cls closure
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_recoup_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c
new file mode 100644
index 000000000..22f906738
--- /dev/null
+++ b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.c
@@ -0,0 +1,203 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_recoup_refresh_above_serial_id.c
+ * @brief Implementation of the select_recoup_refresh_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_recoup_refresh_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #recoup_refresh_serial_helper_cb().
+ */
+struct RecoupRefreshSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RecoupRefreshCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RecoupRefreshSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+recoup_refresh_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RecoupRefreshSerialContext *psc = cls;
+ struct PostgresClosure *pg = psc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_CoinSpendPublicKeyP old_coin_pub;
+ struct TALER_CoinPublicInfo coin;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_DenominationHashP old_denom_pub_hash;
+ struct TALER_Amount amount;
+ struct TALER_BlindedCoinHashP h_blind_ev;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
+ &timestamp),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &old_coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_denom_pub_hash",
+ &old_denom_pub_hash),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &coin.coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
+ &coin_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
+ &coin_blind),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &h_blind_ev),
+ GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
+ &coin.denom_pub_hash),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &coin.h_age_commitment),
+ &coin.no_age_commitment),
+ TALER_PQ_result_spec_denom_sig ("denom_sig",
+ &coin.denom_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ psc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = psc->cb (psc->cb_cls,
+ rowid,
+ timestamp,
+ &amount,
+ &old_coin_pub,
+ &old_denom_pub_hash,
+ &coin,
+ &denom_pub,
+ &coin_sig,
+ &coin_blind);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_recoup_refresh_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupRefreshCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RecoupRefreshSerialContext psc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "recoup_refresh_get_incr",
+ "SELECT"
+ " recoup_refresh_uuid"
+ ",recoup_timestamp"
+ ",old_coins.coin_pub AS old_coin_pub"
+ ",new_coins.age_commitment_hash"
+ ",old_denoms.denom_pub_hash AS old_denom_pub_hash"
+ ",new_coins.coin_pub As coin_pub"
+ ",coin_sig"
+ ",coin_blind"
+ ",new_denoms.denom_pub AS denom_pub"
+ ",rrc.h_coin_ev AS h_blind_ev"
+ ",new_denoms.denom_pub_hash"
+ ",new_coins.denom_sig AS denom_sig"
+ ",amount"
+ " FROM recoup_refresh"
+ " INNER JOIN refresh_revealed_coins rrc"
+ " USING (rrc_serial)"
+ " INNER JOIN refresh_commitments rfc"
+ " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
+ " INNER JOIN known_coins old_coins"
+ " ON (rfc.old_coin_pub = old_coins.coin_pub)"
+ " INNER JOIN known_coins new_coins"
+ " ON (new_coins.coin_pub = recoup_refresh.coin_pub)"
+ " INNER JOIN denominations new_denoms"
+ " ON (new_coins.denominations_serial = new_denoms.denominations_serial)"
+ " INNER JOIN denominations old_denoms"
+ " ON (old_coins.denominations_serial = old_denoms.denominations_serial)"
+ " WHERE recoup_refresh_uuid>=$1"
+ " ORDER BY recoup_refresh_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "recoup_refresh_get_incr",
+ params,
+ &recoup_refresh_serial_helper_cb,
+ &psc);
+ if (GNUNET_OK != psc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_recoup_refresh_above_serial_id.h b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.h
new file mode 100644
index 000000000..0d7b72fc3
--- /dev/null
+++ b/src/exchangedb/pg_select_recoup_refresh_above_serial_id.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_recoup_refresh_above_serial_id.h
+ * @brief implementation of the select_recoup_refresh_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RECOUP_REFRESH_ABOVE_SERIAL_ID_H
+#define PG_SELECT_RECOUP_REFRESH_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to select recoup requests the exchange received for
+ * refreshed coins, ordered by serial ID (monotonically increasing).
+ *
+ * @param cls closure
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_recoup_refresh_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RecoupRefreshCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_refreshes_above_serial_id.c b/src/exchangedb/pg_select_refreshes_above_serial_id.c
new file mode 100644
index 000000000..db432269c
--- /dev/null
+++ b/src/exchangedb/pg_select_refreshes_above_serial_id.c
@@ -0,0 +1,179 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refreshes_above_serial_id.c
+ * @brief Implementation of the select_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_refreshes_above_serial_id.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #refreshs_serial_helper_cb().
+ */
+struct RefreshsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RefreshesCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RefreshsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+refreshs_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RefreshsSerialContext *rsc = cls;
+ struct PostgresClosure *pg = rsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_AgeCommitmentHash h_age_commitment;
+ bool ac_isnull;
+ struct TALER_Amount amount_with_fee;
+ uint32_t noreveal_index;
+ uint64_t rowid;
+ struct TALER_RefreshCommitmentP rc;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_allow_null (
+ GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
+ &h_age_commitment),
+ &ac_isnull),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
+ &coin_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
+ &coin_sig),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_uint32 ("noreveal_index",
+ &noreveal_index),
+ GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("rc",
+ &rc),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+
+ ret = rsc->cb (rsc->cb_cls,
+ rowid,
+ &denom_pub,
+ ac_isnull ? NULL : &h_age_commitment,
+ &coin_pub,
+ &coin_sig,
+ &amount_with_fee,
+ noreveal_index,
+ &rc);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refreshes_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefreshesCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RefreshsSerialContext rsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_refresh_commitments_incr",
+ "SELECT"
+ " denom.denom_pub"
+ ",kc.coin_pub AS old_coin_pub"
+ ",kc.age_commitment_hash"
+ ",old_coin_sig"
+ ",amount_with_fee"
+ ",noreveal_index"
+ ",melt_serial_id"
+ ",rc"
+ " FROM refresh_commitments"
+ " JOIN known_coins kc"
+ " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denominations_serial = denom.denominations_serial)"
+ " WHERE melt_serial_id>=$1"
+ " ORDER BY melt_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_refresh_commitments_incr",
+ params,
+ &refreshs_serial_helper_cb,
+ &rsc);
+ if (GNUNET_OK != rsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_refreshes_above_serial_id.h b/src/exchangedb/pg_select_refreshes_above_serial_id.h
new file mode 100644
index 000000000..2d1db275c
--- /dev/null
+++ b/src/exchangedb/pg_select_refreshes_above_serial_id.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refreshes_above_serial_id.h
+ * @brief implementation of the select_refreshes_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_REFRESHES_ABOVE_SERIAL_ID_H
+#define PG_SELECT_REFRESHES_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select refresh sessions above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refreshes_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefreshesCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_refunds_above_serial_id.c b/src/exchangedb/pg_select_refunds_above_serial_id.c
new file mode 100644
index 000000000..396e8d3d5
--- /dev/null
+++ b/src/exchangedb/pg_select_refunds_above_serial_id.c
@@ -0,0 +1,223 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refunds_above_serial_id.c
+ * @brief Implementation of the select_refunds_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_refunds_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #refunds_serial_helper_cb().
+ */
+struct RefundsSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_RefundCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct RefundsSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+refunds_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct RefundsSerialContext *rsc = cls;
+ struct PostgresClosure *pg = rsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_EXCHANGEDB_Refund refund;
+ struct TALER_DenominationPublicKey denom_pub;
+ uint64_t rowid;
+ bool full_refund;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
+ &refund.details.merchant_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
+ &refund.details.merchant_sig),
+ GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
+ &refund.details.h_contract_terms),
+ GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
+ &refund.details.rtransaction_id),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
+ &refund.coin.coin_pub),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &refund.details.refund_amount),
+ GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+ {
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+ struct TALER_Amount amount_with_fee;
+ uint64_t s_f;
+ uint64_t s_v;
+ struct GNUNET_PQ_ResultSpec rs2[] = {
+ GNUNET_PQ_result_spec_uint64 ("s_v",
+ &s_v),
+ GNUNET_PQ_result_spec_uint64 ("s_f",
+ &s_f),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ qs = GNUNET_PQ_eval_prepared_singleton_select (
+ pg->conn,
+ "test_refund_full",
+ params,
+ rs2);
+ if (qs <= 0)
+ {
+ GNUNET_break (0);
+ rsc->status = GNUNET_SYSERR;
+ return;
+ }
+ /* normalize */
+ s_v += s_f / TALER_AMOUNT_FRAC_BASE;
+ s_f %= TALER_AMOUNT_FRAC_BASE;
+ full_refund = (s_v >= amount_with_fee.value) &&
+ (s_f >= amount_with_fee.fraction);
+ }
+ ret = rsc->cb (rsc->cb_cls,
+ rowid,
+ &denom_pub,
+ &refund.coin.coin_pub,
+ &refund.details.merchant_pub,
+ &refund.details.merchant_sig,
+ &refund.details.h_contract_terms,
+ refund.details.rtransaction_id,
+ full_refund,
+ &refund.details.refund_amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refunds_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefundCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct RefundsSerialContext rsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch refunds with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "audit_get_refunds_incr",
+ "SELECT"
+ " bdep.merchant_pub"
+ ",ref.merchant_sig"
+ ",bdep.h_contract_terms"
+ ",ref.rtransaction_id"
+ ",denom.denom_pub"
+ ",kc.coin_pub"
+ ",ref.amount_with_fee"
+ ",ref.refund_serial_id"
+ " FROM refunds ref"
+ " JOIN batch_deposits bdep"
+ " ON (ref.batch_deposit_serial_id=bdep.batch_deposit_serial_id)"
+ " JOIN coin_deposits cdep"
+ " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
+ " JOIN known_coins kc"
+ " ON (cdep.coin_pub=kc.coin_pub)"
+ " JOIN denominations denom"
+ " ON (kc.denominations_serial=denom.denominations_serial)"
+ " WHERE ref.refund_serial_id>=$1"
+ " ORDER BY ref.refund_serial_id ASC;");
+ PREPARE (pg,
+ "test_refund_full",
+ "SELECT"
+ " CAST(SUM(CAST((ref.amount_with_fee).frac AS INT8)) AS INT8) AS s_f"
+ ",CAST(SUM((ref.amount_with_fee).val) AS INT8) AS s_v"
+ ",cdep.amount_with_fee"
+ " FROM refunds ref"
+ " JOIN coin_deposits cdep"
+ " ON (ref.coin_pub=cdep.coin_pub AND ref.batch_deposit_serial_id=cdep.batch_deposit_serial_id)"
+ " WHERE ref.refund_serial_id=$1"
+ " GROUP BY (cdep.amount_with_fee);");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_refunds_incr",
+ params,
+ &refunds_serial_helper_cb,
+ &rsc);
+ if (GNUNET_OK != rsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_refunds_above_serial_id.h b/src/exchangedb/pg_select_refunds_above_serial_id.h
new file mode 100644
index 000000000..b33816a94
--- /dev/null
+++ b/src/exchangedb/pg_select_refunds_above_serial_id.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refunds_above_serial_id.h
+ * @brief implementation of the select_refunds_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_REFUNDS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_REFUNDS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select refunds above @a serial_id in monotonically increasing
+ * order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refunds_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_RefundCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_refunds_by_coin.c b/src/exchangedb/pg_select_refunds_by_coin.c
new file mode 100644
index 000000000..d9cd6dd3c
--- /dev/null
+++ b/src/exchangedb/pg_select_refunds_by_coin.c
@@ -0,0 +1,143 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refunds_by_coin.c
+ * @brief Implementation of the select_refunds_by_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_refunds_by_coin.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_refunds_cb().
+ */
+struct SelectRefundContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_RefundCoinCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Set to #GNUNET_SYSERR on error.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct SelectRefundContext *`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+get_refunds_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct SelectRefundContext *srctx = cls;
+ struct PostgresClosure *pg = srctx->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_Amount amount_with_fee;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ srctx->status = GNUNET_SYSERR;
+ return;
+ }
+ if (GNUNET_OK !=
+ srctx->cb (srctx->cb_cls,
+ &amount_with_fee))
+ return;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refunds_by_coin (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract,
+ TALER_EXCHANGEDB_RefundCoinCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ enum GNUNET_DB_QueryStatus qs;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (coin_pub),
+ GNUNET_PQ_query_param_auto_from_type (merchant_pub),
+ GNUNET_PQ_query_param_auto_from_type (h_contract),
+ GNUNET_PQ_query_param_end
+ };
+ struct SelectRefundContext srctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ const char *query = "get_refunds_by_coin_and_contract";
+
+ PREPARE (pg,
+ query,
+ "SELECT"
+ " ref.amount_with_fee"
+ " FROM refunds ref"
+ " JOIN coin_deposits cdep"
+ " USING (coin_pub,batch_deposit_serial_id)"
+ " JOIN batch_deposits bdep"
+ " ON (ref.batch_deposit_serial_id = bdep.batch_deposit_serial_id)"
+ " WHERE ref.coin_pub=$1"
+ " AND bdep.merchant_pub=$2"
+ " AND bdep.h_contract_terms=$3;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ query,
+ params,
+ &get_refunds_cb,
+ &srctx);
+ if (GNUNET_SYSERR == srctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_refunds_by_coin.h b/src/exchangedb/pg_select_refunds_by_coin.h
new file mode 100644
index 000000000..72df13fda
--- /dev/null
+++ b/src/exchangedb/pg_select_refunds_by_coin.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_refunds_by_coin.h
+ * @brief implementation of the select_refunds_by_coin function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_REFUNDS_BY_COIN_H
+#define PG_SELECT_REFUNDS_BY_COIN_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract.
+ *
+ * @param cls closure of plugin
+ * @param coin_pub coin to get refunds for
+ * @param merchant_pub merchant to get refunds for
+ * @param h_contract contract (hash) to get refunds for
+ * @param cb function to call for each refund found
+ * @param cb_cls closure for @a cb
+ * @return query result status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_refunds_by_coin (
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract,
+ TALER_EXCHANGEDB_RefundCoinCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_reserve_close_info.c b/src/exchangedb/pg_select_reserve_close_info.c
new file mode 100644
index 000000000..eccba8e4c
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_close_info.c
@@ -0,0 +1,63 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_close_info.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_reserve_close_info.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_close_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance,
+ char **payto_uri)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (reserve_pub),
+ GNUNET_PQ_query_param_end
+ };
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_result_spec_amount ("current_balance",
+ pg->currency,
+ balance),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ payto_uri),
+ GNUNET_PQ_result_spec_end
+ };
+
+ PREPARE (pg,
+ "select_reserve_close_info",
+ "SELECT "
+ " r.current_balance"
+ ",wt.payto_uri"
+ " FROM reserves r"
+ " LEFT JOIN reserves_in ri USING (reserve_pub)"
+ " LEFT JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
+ " WHERE reserve_pub=$1;");
+ return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
+ "select_reserve_close_info",
+ params,
+ rs);
+}
diff --git a/src/exchangedb/pg_select_reserve_close_info.h b/src/exchangedb/pg_select_reserve_close_info.h
new file mode 100644
index 000000000..2b90ffd05
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_close_info.h
@@ -0,0 +1,49 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_close_info.h
+ * @brief implementation of the select_reserve_close_info function
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RESERVE_CLOSE_INFO_H
+#define PG_SELECT_RESERVE_CLOSE_INFO_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Select information needed to see if we can close
+ * a reserve.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param[out] balance current reserve balance
+ * @param[out] payto_uri set to URL of account that
+ * originally funded the reserve;
+ * could be set to NULL if not known
+ * @return transaction status code, 0 if reserve unknown
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_close_info (
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance,
+ char **payto_uri);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_reserve_closed_above_serial_id.c b/src/exchangedb/pg_select_reserve_closed_above_serial_id.c
new file mode 100644
index 000000000..d24d6a600
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_closed_above_serial_id.c
@@ -0,0 +1,178 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_closed_above_serial_id.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_get_reserve_history.h"
+#include "plugin_exchangedb_common.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #reserve_closed_serial_helper_cb().
+ */
+struct ReserveClosedSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveClosedCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin's context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveClosedSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_closed_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveClosedSerialContext *rcsc = cls;
+ struct PostgresClosure *pg = rcsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ char *receiver_account;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct TALER_Amount amount_with_fee;
+ struct TALER_Amount closing_fee;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t close_request_row;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("close_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("receiver_account",
+ &receiver_account),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount_with_fee),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
+ &closing_fee),
+ GNUNET_PQ_result_spec_uint64 ("close_request_row",
+ &close_request_row),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rcsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = rcsc->cb (rcsc->cb_cls,
+ rowid,
+ execution_date,
+ &amount_with_fee,
+ &closing_fee,
+ &reserve_pub,
+ receiver_account,
+ &wtid,
+ close_request_row);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_closed_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveClosedCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveClosedSerialContext rcsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Used in #postgres_select_reserve_closed_above_serial_id() to
+ obtain information about closed reserves */
+ PREPARE (
+ pg,
+ "reserves_close_get_incr",
+ "SELECT"
+ " close_uuid"
+ ",reserves.reserve_pub"
+ ",execution_date"
+ ",wtid"
+ ",payto_uri AS receiver_account"
+ ",amount"
+ ",closing_fee"
+ ",close_request_row"
+ " FROM reserves_close"
+ " JOIN wire_targets"
+ " USING (wire_target_h_payto)"
+ " JOIN reserves"
+ " USING (reserve_pub)"
+ " WHERE close_uuid>=$1"
+ " ORDER BY close_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "reserves_close_get_incr",
+ params,
+ &reserve_closed_serial_helper_cb,
+ &rcsc);
+ if (GNUNET_OK != rcsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_reserve_closed_above_serial_id.h b/src/exchangedb/pg_select_reserve_closed_above_serial_id.h
new file mode 100644
index 000000000..af3c8631e
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_closed_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_closed_above_serial_id.h
+ * @brief implementation of the select_reserve_closed_above_serial_id function
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
+#define PG_SELECT_RESERVE_CLOSED_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to select reserve close operations the aggregator
+ * triggered, ordered by serial ID (monotonically increasing).
+ *
+ * @param cls closure
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_closed_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveClosedCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_reserve_open_above_serial_id.c b/src/exchangedb/pg_select_reserve_open_above_serial_id.c
new file mode 100644
index 000000000..1675e71a7
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_open_above_serial_id.c
@@ -0,0 +1,168 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_open_above_serial_id.c
+ * @brief Low-level (statement-level) Postgres database access for the exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_reserve_open_above_serial_id.h"
+#include "plugin_exchangedb_common.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #reserve_open_serial_helper_cb().
+ */
+struct ReserveOpenSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveOpenCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin's context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReserveOpenSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserve_open_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReserveOpenSerialContext *rcsc = cls;
+ struct PostgresClosure *pg = rcsc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint32_t requested_purse_limit;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+ struct TALER_Amount reserve_payment;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("open_request_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_timestamp ("request_timestamp",
+ &request_timestamp),
+ GNUNET_PQ_result_spec_timestamp ("expiration_date",
+ &reserve_expiration),
+ GNUNET_PQ_result_spec_uint32 ("requested_purse_limit",
+ &requested_purse_limit),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("reserve_payment",
+ &reserve_payment),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rcsc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = rcsc->cb (rcsc->cb_cls,
+ rowid,
+ &reserve_payment,
+ request_timestamp,
+ reserve_expiration,
+ requested_purse_limit,
+ &reserve_pub,
+ &reserve_sig);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_open_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveOpenCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReserveOpenSerialContext rcsc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (
+ pg,
+ "reserves_open_get_incr",
+ "SELECT"
+ " open_request_uuid"
+ ",reserve_pub"
+ ",request_timestamp"
+ ",expiration_date"
+ ",reserve_sig"
+ ",reserve_payment"
+ ",requested_purse_limit"
+ " FROM reserves_open_requests"
+ " WHERE open_request_uuid>=$1"
+ " ORDER BY open_request_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "reserves_open_get_incr",
+ params,
+ &reserve_open_serial_helper_cb,
+ &rcsc);
+ if (GNUNET_OK != rcsc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_reserve_open_above_serial_id.h b/src/exchangedb/pg_select_reserve_open_above_serial_id.h
new file mode 100644
index 000000000..4ec5b705a
--- /dev/null
+++ b/src/exchangedb/pg_select_reserve_open_above_serial_id.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file pg_select_reserve_open_above_serial_id.h
+ * @brief implementation of the select_reserve_open_above_serial_id function
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RESERVE_OPEN_ABOVE_SERIAL_ID_H
+#define PG_SELECT_RESERVE_OPEN_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Function called to select reserve open operations, ordered by serial ID
+ * (monotonically increasing).
+ *
+ * @param cls closure
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserve_open_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveOpenCallback cb,
+ void *cb_cls);
+
+
+#endif
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id.c b/src/exchangedb/pg_select_reserves_in_above_serial_id.c
new file mode 100644
index 000000000..21033e80d
--- /dev/null
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id.c
@@ -0,0 +1,164 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_reserves_in_above_serial_id.c
+ * @brief Implementation of the select_reserves_in_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_reserves_in_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #reserves_in_serial_helper_cb().
+ */
+struct ReservesInSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveInCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesInSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_in_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesInSerialContext *risc = cls;
+ struct PostgresClosure *pg = risc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount credit;
+ char *sender_account_details;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t rowid;
+ uint64_t wire_reference;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ &wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
+ &credit),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &sender_account_details),
+ GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ risc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = risc->cb (risc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &credit,
+ sender_account_details,
+ wire_reference,
+ execution_date);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserves_in_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesInSerialContext risc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_reserves_in_get_transactions_incr",
+ "SELECT"
+ " reserves.reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",execution_date"
+ ",payto_uri AS sender_account_details"
+ ",reserve_in_serial_id"
+ " FROM reserves_in"
+ " JOIN reserves"
+ " USING (reserve_pub)"
+ " JOIN wire_targets"
+ " ON (wire_source_h_payto = wire_target_h_payto)"
+ " WHERE reserve_in_serial_id>=$1"
+ " ORDER BY reserve_in_serial_id;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_reserves_in_get_transactions_incr",
+ params,
+ &reserves_in_serial_helper_cb,
+ &risc);
+ if (GNUNET_OK != risc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id.h b/src/exchangedb/pg_select_reserves_in_above_serial_id.h
new file mode 100644
index 000000000..5f5dd2ecc
--- /dev/null
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id.h
@@ -0,0 +1,44 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_reserves_in_above_serial_id.h
+ * @brief implementation of the select_reserves_in_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_H
+#define PG_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Select inbound wire transfers into reserves_in above @a serial_id
+ * in monotonically increasing order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserves_in_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
new file mode 100644
index 000000000..1c7bc15a0
--- /dev/null
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
@@ -0,0 +1,168 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_reserves_in_above_serial_id_by_account.c
+ * @brief Implementation of the select_reserves_in_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_reserves_in_above_serial_id_by_account.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #reserves_in_serial_helper_cb().
+ */
+struct ReservesInSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_ReserveInCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesInSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_in_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesInSerialContext *risc = cls;
+ struct PostgresClosure *pg = risc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_Amount credit;
+ char *sender_account_details;
+ struct GNUNET_TIME_Timestamp execution_date;
+ uint64_t rowid;
+ uint64_t wire_reference;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_uint64 ("wire_reference",
+ &wire_reference),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
+ &credit),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ GNUNET_PQ_result_spec_string ("sender_account_details",
+ &sender_account_details),
+ GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ risc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = risc->cb (risc->cb_cls,
+ rowid,
+ &reserve_pub,
+ &credit,
+ sender_account_details,
+ wire_reference,
+ execution_date);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserves_in_above_serial_id_by_account (
+ void *cls,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_string (account_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesInSerialContext risc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_reserves_in_get_transactions_incr_by_account",
+ "SELECT"
+ " reserves.reserve_pub"
+ ",wire_reference"
+ ",credit"
+ ",execution_date"
+ ",payto_uri AS sender_account_details"
+ ",reserve_in_serial_id"
+ " FROM reserves_in"
+ " JOIN reserves "
+ " USING (reserve_pub)"
+ " JOIN wire_targets"
+ " ON (wire_source_h_payto = wire_target_h_payto)"
+ " WHERE reserve_in_serial_id>=$1"
+ " AND exchange_account_section=$2"
+ " ORDER BY reserve_in_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_reserves_in_get_transactions_incr_by_account",
+ params,
+ &reserves_in_serial_helper_cb,
+ &risc);
+ if (GNUNET_OK != risc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.h b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.h
new file mode 100644
index 000000000..81855ede9
--- /dev/null
+++ b/src/exchangedb/pg_select_reserves_in_above_serial_id_by_account.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_reserves_in_above_serial_id_by_account.h
+ * @brief implementation of the select_reserves_in_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+#define PG_SELECT_RESERVES_IN_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Select inbound wire transfers into reserves_in above @a serial_id
+ * in monotonically increasing order by account.
+ *
+ * @param cls closure
+ * @param account_name name of the account to select by
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_reserves_in_above_serial_id_by_account (
+ void *cls,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveInCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_satisfied_kyc_processes.c b/src/exchangedb/pg_select_satisfied_kyc_processes.c
new file mode 100644
index 000000000..e0d884ef1
--- /dev/null
+++ b/src/exchangedb/pg_select_satisfied_kyc_processes.c
@@ -0,0 +1,141 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_satisfied_kyc_processes.c
+ * @brief Implementation of the select_satisfied_kyc_processes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_satisfied_kyc_processes.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_legitimizations_cb().
+ */
+struct GetLegitimizationsContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_SatisfiedProviderCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct GetLegitimizationsContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_legitimizations_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetLegitimizationsContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ char *provider_section;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_string ("provider_section",
+ &provider_section),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Found satisfied LEGI: %s\n",
+ provider_section);
+ ctx->cb (ctx->cb_cls,
+ provider_section);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_satisfied_kyc_processes (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_SatisfiedProviderCallback spc,
+ void *spc_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_TIME_Absolute now
+ = GNUNET_TIME_absolute_get ();
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&now),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetLegitimizationsContext ctx = {
+ .cb = spc,
+ .cb_cls = spc_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "get_satisfied_legitimizations",
+ "SELECT "
+ " provider_section"
+ " FROM legitimization_processes"
+ " WHERE h_payto=$1"
+ " AND expiration_time>=$2;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "get_satisfied_legitimizations",
+ params,
+ &get_legitimizations_cb,
+ &ctx);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Satisfied LEGI check returned %d\n",
+ qs);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_satisfied_kyc_processes.h b/src/exchangedb/pg_select_satisfied_kyc_processes.h
new file mode 100644
index 000000000..bc1639ff9
--- /dev/null
+++ b/src/exchangedb/pg_select_satisfied_kyc_processes.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_satisfied_kyc_processes.h
+ * @brief implementation of the select_satisfied_kyc_processes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_SATISFIED_KYC_PROCESSES_H
+#define PG_SELECT_SATISFIED_KYC_PROCESSES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Call us on KYC processes satisfied for the given
+ * account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param spc function to call for each satisfied KYC process
+ * @param spc_cls closure for @a spc
+ * @return transaction status code
+ */
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_satisfied_kyc_processes (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_SatisfiedProviderCallback spc,
+ void *spc_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_similar_kyc_attributes.c b/src/exchangedb/pg_select_similar_kyc_attributes.c
new file mode 100644
index 000000000..342f9ef33
--- /dev/null
+++ b/src/exchangedb/pg_select_similar_kyc_attributes.c
@@ -0,0 +1,154 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_similar_kyc_attributes.c
+ * @brief Implementation of the select_similar_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_similar_kyc_attributes.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_similar_attributes_cb().
+ */
+struct GetAttributesContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_AttributeCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct GetAttributesContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_attributes_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct GetAttributesContext *ctx = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ size_t enc_attributes_size;
+ void *enc_attributes;
+ char *provider;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_payto",
+ &h_payto),
+ GNUNET_PQ_result_spec_string ("provider",
+ &provider),
+ GNUNET_PQ_result_spec_timestamp ("collection_time",
+ &collection_time),
+ GNUNET_PQ_result_spec_timestamp ("expiration_time",
+ &expiration_time),
+ GNUNET_PQ_result_spec_variable_size ("encrypted_attributes",
+ &enc_attributes,
+ &enc_attributes_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ctx->cb (ctx->cb_cls,
+ &h_payto,
+ provider,
+ collection_time,
+ expiration_time,
+ enc_attributes_size,
+ enc_attributes);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_similar_kyc_attributes (
+ void *cls,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (kyc_prox),
+ GNUNET_PQ_query_param_end
+ };
+ struct GetAttributesContext ctx = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "select_similar_kyc_attributes",
+ "SELECT "
+ " h_payto"
+ ",provider"
+ ",collection_time"
+ ",expiration_time"
+ ",encrypted_attributes"
+ " FROM kyc_attributes"
+ " WHERE kyc_prox=$1");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "select_similar_kyc_attributes",
+ params,
+ &get_attributes_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_similar_kyc_attributes.h b/src/exchangedb/pg_select_similar_kyc_attributes.h
new file mode 100644
index 000000000..72f2407e8
--- /dev/null
+++ b/src/exchangedb/pg_select_similar_kyc_attributes.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_similar_kyc_attributes.h
+ * @brief implementation of the select_similar_kyc_attributes function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_SIMILAR_KYC_ATTRIBUTES_H
+#define PG_SELECT_SIMILAR_KYC_ATTRIBUTES_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Lookup similar KYC attribute data.
+ *
+ * @param cls closure
+ * @param kyc_prox key for similarity search
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_similar_kyc_attributes (
+ void *cls,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id.c b/src/exchangedb/pg_select_wire_out_above_serial_id.c
new file mode 100644
index 000000000..8668c429d
--- /dev/null
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id.c
@@ -0,0 +1,157 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_wire_out_above_serial_id.c
+ * @brief Implementation of the select_wire_out_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_wire_out_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #wire_out_serial_helper_cb().
+ */
+struct WireOutSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WireTransferOutCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ int status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireOutSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_out_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireOutSerialContext *wosc = cls;
+ struct PostgresClosure *pg = wosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp date;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *payto_uri;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ wosc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = wosc->cb (wosc->cb_cls,
+ rowid,
+ date,
+ &wtid,
+ payto_uri,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_wire_out_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireOutSerialContext wosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+ /* Used in #postgres_select_wire_out_above_serial_id() */
+ PREPARE (pg,
+ "audit_get_wire_incr",
+ "SELECT"
+ " wireout_uuid"
+ ",execution_date"
+ ",wtid_raw"
+ ",payto_uri"
+ ",amount"
+ " FROM wire_out"
+ " JOIN wire_targets"
+ " USING (wire_target_h_payto)"
+ " WHERE wireout_uuid>=$1"
+ " ORDER BY wireout_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_wire_incr",
+ params,
+ &wire_out_serial_helper_cb,
+ &wosc);
+ if (GNUNET_OK != wosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id.h b/src/exchangedb/pg_select_wire_out_above_serial_id.h
new file mode 100644
index 000000000..e42cb9b0f
--- /dev/null
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_wire_out_above_serial_id.h
+ * @brief implementation of the select_wire_out_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_H
+#define PG_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to select all wire transfers the exchange
+ * executed.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_wire_out_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c
new file mode 100644
index 000000000..3448c5a49
--- /dev/null
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.c
@@ -0,0 +1,161 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_wire_out_above_serial_id_by_account.c
+ * @brief Implementation of the select_wire_out_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_wire_out_above_serial_id_by_account.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #wire_out_serial_helper_cb().
+ */
+struct WireOutSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WireTransferOutCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ int status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct WireOutSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+wire_out_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct WireOutSerialContext *wosc = cls;
+ struct PostgresClosure *pg = wosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ uint64_t rowid;
+ struct GNUNET_TIME_Timestamp date;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *payto_uri;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
+ &rowid),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &date),
+ GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
+ &wtid),
+ GNUNET_PQ_result_spec_string ("payto_uri",
+ &payto_uri),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_end
+ };
+ int ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ wosc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = wosc->cb (wosc->cb_cls,
+ rowid,
+ date,
+ &wtid,
+ payto_uri,
+ &amount);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_wire_out_above_serial_id_by_account (
+ void *cls,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_string (account_name),
+ GNUNET_PQ_query_param_end
+ };
+ struct WireOutSerialContext wosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "audit_get_wire_incr_by_account",
+ "SELECT"
+ " wireout_uuid"
+ ",execution_date"
+ ",wtid_raw"
+ ",payto_uri"
+ ",amount"
+ " FROM wire_out"
+ " JOIN wire_targets"
+ " USING (wire_target_h_payto)"
+ " WHERE "
+ " wireout_uuid>=$1 "
+ " AND exchange_account_section=$2"
+ " ORDER BY wireout_uuid ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_wire_incr_by_account",
+ params,
+ &wire_out_serial_helper_cb,
+ &wosc);
+ if (GNUNET_OK != wosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.h b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.h
new file mode 100644
index 000000000..04c6a62b2
--- /dev/null
+++ b/src/exchangedb/pg_select_wire_out_above_serial_id_by_account.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_wire_out_above_serial_id_by_account.h
+ * @brief implementation of the select_wire_out_above_serial_id_by_account function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+#define PG_SELECT_WIRE_OUT_ABOVE_SERIAL_ID_BY_ACCOUNT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to select all wire transfers the exchange
+ * executed by account.
+ *
+ * @param cls closure
+ * @param account_name account to select
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_wire_out_above_serial_id_by_account (
+ void *cls,
+ const char *account_name,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
new file mode 100644
index 000000000..71ed81833
--- /dev/null
+++ b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
@@ -0,0 +1,158 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_withdraw_amounts_for_kyc_check.c
+ * @brief Implementation of the select_withdraw_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_withdraw_amounts_for_kyc_check.h"
+#include "pg_select_aggregation_amounts_for_kyc_check.h"
+#include "pg_helper.h"
+
+
+/**
+ * Closure for #get_kyc_amounts_cb().
+ */
+struct KycAmountCheckContext
+{
+ /**
+ * Function to call per result.
+ */
+ TALER_EXCHANGEDB_KycAmountCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Flag set to #GNUNET_OK as long as everything is fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+
+};
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct KycAmountCheckContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+get_kyc_amounts_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct KycAmountCheckContext *ctx = cls;
+ struct PostgresClosure *pg = ctx->pg;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ struct GNUNET_TIME_Absolute date;
+ struct TALER_Amount amount;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
+ &amount),
+ GNUNET_PQ_result_spec_absolute_time ("date",
+ &date),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ ctx->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = ctx->cb (ctx->cb_cls,
+ &amount,
+ date);
+ GNUNET_PQ_cleanup_result (rs);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ continue;
+ case GNUNET_NO:
+ break;
+ case GNUNET_SYSERR:
+ ctx->status = GNUNET_SYSERR;
+ break;
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_withdraw_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_absolute_time (&time_limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct KycAmountCheckContext ctx = {
+ .cb = kac,
+ .cb_cls = kac_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "select_kyc_relevant_withdraw_events",
+ "SELECT"
+ " ro.amount_with_fee AS amount"
+ ",ro.execution_date AS date"
+ " FROM reserves_in ri"
+ " JOIN reserve_history rh"
+ " ON (rh.reserve_pub = ri.reserve_pub)"
+ " JOIN reserves_out ro"
+ " ON (ro.reserve_out_serial_id = rh.serial_id)"
+ " WHERE ri.wire_source_h_payto=$1"
+ " AND rh.table_name='reserves_out'"
+ " AND ro.execution_date >= $2"
+ " ORDER BY rh.reserve_history_serial_id DESC");
+ qs = GNUNET_PQ_eval_prepared_multi_select (
+ pg->conn,
+ "select_kyc_relevant_withdraw_events",
+ params,
+ &get_kyc_amounts_cb,
+ &ctx);
+ if (GNUNET_OK != ctx.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.h b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.h
new file mode 100644
index 000000000..9a780adbe
--- /dev/null
+++ b/src/exchangedb/pg_select_withdraw_amounts_for_kyc_check.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_withdraw_amounts_for_kyc_check.h
+ * @brief implementation of the select_withdraw_amounts_for_kyc_check function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
+#define PG_SELECT_WITHDRAW_AMOUNTS_FOR_KYC_CHECK_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Call @a kac on withdrawn amounts after @a time_limit which are relevant
+ * for a KYC trigger for a the (debited) account identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_withdraw_amounts_for_kyc_check (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+#endif
diff --git a/src/exchangedb/pg_select_withdrawals_above_serial_id.c b/src/exchangedb/pg_select_withdrawals_above_serial_id.c
new file mode 100644
index 000000000..9beb0f936
--- /dev/null
+++ b/src/exchangedb/pg_select_withdrawals_above_serial_id.c
@@ -0,0 +1,170 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_withdrawals_above_serial_id.c
+ * @brief Implementation of the select_withdrawals_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_select_withdrawals_above_serial_id.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #reserves_out_serial_helper_cb().
+ */
+struct ReservesOutSerialContext
+{
+
+ /**
+ * Callback to call.
+ */
+ TALER_EXCHANGEDB_WithdrawCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Plugin context.
+ */
+ struct PostgresClosure *pg;
+
+ /**
+ * Status code, set to #GNUNET_SYSERR on hard errors.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Helper function to be called with the results of a SELECT statement
+ * that has returned @a num_results results.
+ *
+ * @param cls closure of type `struct ReservesOutSerialContext`
+ * @param result the postgres result
+ * @param num_results the number of results in @a result
+ */
+static void
+reserves_out_serial_helper_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct ReservesOutSerialContext *rosc = cls;
+ struct PostgresClosure *pg = rosc->pg;
+
+ for (unsigned int i = 0; i<num_results; i++)
+ {
+ struct TALER_BlindedCoinHashP h_blind_ev;
+ struct TALER_DenominationPublicKey denom_pub;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct GNUNET_TIME_Timestamp execution_date;
+ struct TALER_Amount amount_with_fee;
+ uint64_t rowid;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
+ &h_blind_ev),
+ TALER_PQ_result_spec_denom_pub ("denom_pub",
+ &denom_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
+ &reserve_pub),
+ GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
+ &reserve_sig),
+ GNUNET_PQ_result_spec_timestamp ("execution_date",
+ &execution_date),
+ TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
+ &amount_with_fee),
+ GNUNET_PQ_result_spec_uint64 ("reserve_out_serial_id",
+ &rowid),
+ GNUNET_PQ_result_spec_end
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ rosc->status = GNUNET_SYSERR;
+ return;
+ }
+ ret = rosc->cb (rosc->cb_cls,
+ rowid,
+ &h_blind_ev,
+ &denom_pub,
+ &reserve_pub,
+ &reserve_sig,
+ execution_date,
+ &amount_with_fee);
+ GNUNET_PQ_cleanup_result (rs);
+ if (GNUNET_OK != ret)
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_withdrawals_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WithdrawCallback cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&serial_id),
+ GNUNET_PQ_query_param_end
+ };
+ struct ReservesOutSerialContext rosc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .pg = pg,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Fetch deposits with rowid '\geq' the given parameter */
+ PREPARE (pg,
+ "audit_get_reserves_out_incr",
+ "SELECT"
+ " h_blind_ev"
+ ",denom.denom_pub"
+ ",reserve_sig"
+ ",reserves.reserve_pub"
+ ",execution_date"
+ ",amount_with_fee"
+ ",reserve_out_serial_id"
+ " FROM reserves_out"
+ " JOIN reserves"
+ " USING (reserve_uuid)"
+ " JOIN denominations denom"
+ " USING (denominations_serial)"
+ " WHERE reserve_out_serial_id>=$1"
+ " ORDER BY reserve_out_serial_id ASC;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "audit_get_reserves_out_incr",
+ params,
+ &reserves_out_serial_helper_cb,
+ &rosc);
+ if (GNUNET_OK != rosc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_select_withdrawals_above_serial_id.h b/src/exchangedb/pg_select_withdrawals_above_serial_id.h
new file mode 100644
index 000000000..2b741a3b4
--- /dev/null
+++ b/src/exchangedb/pg_select_withdrawals_above_serial_id.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_select_withdrawals_above_serial_id.h
+ * @brief implementation of the select_withdrawals_above_serial_id function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SELECT_WITHDRAWALS_ABOVE_SERIAL_ID_H
+#define PG_SELECT_WITHDRAWALS_ABOVE_SERIAL_ID_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Select withdraw operations from reserves_out above @a serial_id
+ * in monotonically increasing order.
+ *
+ * @param cls closure
+ * @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param cb function to call on each result
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_select_withdrawals_above_serial_id (
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_WithdrawCallback cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_set_extension_manifest.c b/src/exchangedb/pg_set_extension_manifest.c
new file mode 100644
index 000000000..c7db04312
--- /dev/null
+++ b/src/exchangedb/pg_set_extension_manifest.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_set_extension_manifest.c
+ * @brief Implementation of the set_extension_manifest function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_set_extension_manifest.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_set_extension_manifest (void *cls,
+ const char *extension_name,
+ const char *manifest)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam pcfg =
+ (NULL == manifest || 0 == *manifest)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (manifest);
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (extension_name),
+ pcfg,
+ GNUNET_PQ_query_param_end
+ };
+
+
+ PREPARE (pg,
+ "set_extension_manifest",
+ "INSERT INTO extensions (name, manifest) VALUES ($1, $2) "
+ "ON CONFLICT (name) "
+ "DO UPDATE SET manifest=$2");
+
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "set_extension_manifest",
+ params);
+}
diff --git a/src/exchangedb/pg_set_extension_manifest.h b/src/exchangedb/pg_set_extension_manifest.h
new file mode 100644
index 000000000..0befeedd8
--- /dev/null
+++ b/src/exchangedb/pg_set_extension_manifest.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_set_extension_manifest.h
+ * @brief implementation of the set_extension_manifest function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SET_EXTENSION_MANIFEST_H
+#define PG_SET_EXTENSION_MANIFEST_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to save the manifest of an extension
+ * (age-restriction, policy_extension_...) After successful storage of the
+ * configuration it triggers the corresponding event.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param extension_name the name of the extension
+ * @param manifest JSON object of the configuration as string
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_set_extension_manifest (void *cls,
+ const char *extension_name,
+ const char *manifest);
+
+#endif
diff --git a/src/exchangedb/pg_set_purse_balance.c b/src/exchangedb/pg_set_purse_balance.c
new file mode 100644
index 000000000..1e34ea6ed
--- /dev/null
+++ b/src/exchangedb/pg_set_purse_balance.c
@@ -0,0 +1,52 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_set_purse_balance.c
+ * @brief Implementation of the set_purse_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_set_purse_balance.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_set_purse_balance (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (purse_pub),
+ TALER_PQ_query_param_amount (pg->conn,
+ balance),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "set_purse_balance",
+ "UPDATE purse_requests"
+ " SET balance=$2"
+ " WHERE purse_pub=$1;");
+
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "set_purse_balance",
+ params);
+}
diff --git a/src/exchangedb/pg_set_purse_balance.h b/src/exchangedb/pg_set_purse_balance.h
new file mode 100644
index 000000000..44b765568
--- /dev/null
+++ b/src/exchangedb/pg_set_purse_balance.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_set_purse_balance.h
+ * @brief implementation of the set_purse_balance function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SET_PURSE_BALANCE_H
+#define PG_SET_PURSE_BALANCE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Set the current @a balance in the purse
+ * identified by @a purse_pub. Used by the auditor
+ * to update the balance as calculated by the auditor.
+ *
+ * @param cls closure
+ * @param purse_pub public key of a purse
+ * @param balance new balance to store under the purse
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_set_purse_balance (
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance);
+
+#endif
diff --git a/src/exchangedb/pg_setup_wire_target.c b/src/exchangedb/pg_setup_wire_target.c
new file mode 100644
index 000000000..ed6fbe338
--- /dev/null
+++ b/src/exchangedb/pg_setup_wire_target.c
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_setup_wire_target.c
+ * @brief Implementation of the setup_wire_target function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_setup_wire_target.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_setup_wire_target (
+ struct PostgresClosure *pg,
+ const char *payto_uri,
+ struct TALER_PaytoHashP *h_payto)
+{
+ struct GNUNET_PQ_QueryParam iparams[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_end
+ };
+
+ TALER_payto_hash (payto_uri,
+ h_payto);
+
+ PREPARE (pg,
+ "insert_kyc_status",
+ "INSERT INTO wire_targets"
+ " (wire_target_h_payto"
+ " ,payto_uri"
+ " ) VALUES "
+ " ($1, $2)"
+ " ON CONFLICT DO NOTHING");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_kyc_status",
+ iparams);
+}
diff --git a/src/exchangedb/pg_setup_wire_target.h b/src/exchangedb/pg_setup_wire_target.h
new file mode 100644
index 000000000..77512a600
--- /dev/null
+++ b/src/exchangedb/pg_setup_wire_target.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_setup_wire_target.h
+ * @brief implementation of the setup_wire_target function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_SETUP_WIRE_TARGET_H
+#define PG_SETUP_WIRE_TARGET_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "pg_helper.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Setup new wire target for @a payto_uri.
+ *
+ * @param pg the plugin-specific state
+ * @param payto_uri the payto URI to check
+ * @param[out] h_payto set to the hash of @a payto_uri
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_setup_wire_target (
+ struct PostgresClosure *pg,
+ const char *payto_uri,
+ struct TALER_PaytoHashP *h_payto);
+
+#endif
diff --git a/src/exchangedb/pg_start.c b/src/exchangedb/pg_start.c
new file mode 100644
index 000000000..de5d698f6
--- /dev/null
+++ b/src/exchangedb/pg_start.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start.c
+ * @brief Implementation of the start function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_preflight.h"
+#include "pg_start.h"
+#include "pg_helper.h"
+
+enum GNUNET_GenericReturnValue
+TEH_PG_start (void *cls,
+ const char *name)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ GNUNET_assert (NULL != name);
+ if (GNUNET_SYSERR ==
+ TEH_PG_preflight (pg))
+ return GNUNET_SYSERR;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting transaction `%s'\n",
+ name);
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR ("Failed to start transaction\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ pg->transaction_name = name;
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_start.h b/src/exchangedb/pg_start.h
new file mode 100644
index 000000000..0a3bb9e43
--- /dev/null
+++ b/src/exchangedb/pg_start.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start.h
+ * @brief implementation of the start function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_START_H
+#define PG_START_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Start a transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param name unique name identifying the transaction (for debugging)
+ * must point to a constant
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_start (void *cls,
+ const char *name);
+
+#endif
diff --git a/src/exchangedb/pg_start_deferred_wire_out.c b/src/exchangedb/pg_start_deferred_wire_out.c
new file mode 100644
index 000000000..abdc16028
--- /dev/null
+++ b/src/exchangedb/pg_start_deferred_wire_out.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_deferred_wire_out.c
+ * @brief Implementation of the start_deferred_wire_out function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_start_deferred_wire_out.h"
+#include "pg_helper.h"
+#include "pg_preflight.h"
+#include "pg_rollback.h"
+
+enum GNUNET_GenericReturnValue
+TEH_PG_start_deferred_wire_out (void *cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute (
+ "START TRANSACTION ISOLATION LEVEL READ COMMITTED;"),
+ GNUNET_PQ_make_execute ("SET CONSTRAINTS ALL DEFERRED;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ if (GNUNET_SYSERR ==
+ TEH_PG_preflight (pg))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR (
+ "Failed to defer wire_out_ref constraint on transaction\n");
+ GNUNET_break (0);
+ TEH_PG_rollback (pg);
+ return GNUNET_SYSERR;
+ }
+ pg->transaction_name = "deferred wire out";
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting READ COMMITTED DEFERRED transaction `%s'\n",
+ pg->transaction_name);
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_start_deferred_wire_out.h b/src/exchangedb/pg_start_deferred_wire_out.h
new file mode 100644
index 000000000..ed444ef70
--- /dev/null
+++ b/src/exchangedb/pg_start_deferred_wire_out.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_deferred_wire_out.h
+ * @brief implementation of the start_deferred_wire_out function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_START_DEFERRED_WIRE_OUT_H
+#define PG_START_DEFERRED_WIRE_OUT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Starts a READ COMMITTED transaction where we transiently violate the foreign
+ * constraints on the "wire_out" table as we insert aggregations
+ * and only add the wire transfer out at the end.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_start_deferred_wire_out (void *cls);
+
+#endif
diff --git a/src/exchangedb/pg_start_read_committed.c b/src/exchangedb/pg_start_read_committed.c
new file mode 100644
index 000000000..1c8248ab0
--- /dev/null
+++ b/src/exchangedb/pg_start_read_committed.c
@@ -0,0 +1,56 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_read_committed.c
+ * @brief Implementation of the start_read_committed function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_start_read_committed.h"
+#include "pg_preflight.h"
+#include "pg_helper.h"
+
+enum GNUNET_GenericReturnValue
+TEH_PG_start_read_committed (void *cls,
+ const char *name)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ GNUNET_assert (NULL != name);
+ if (GNUNET_SYSERR ==
+ TEH_PG_preflight (pg))
+ return GNUNET_SYSERR;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting READ COMMITTED transaction `%s`\n",
+ name);
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR ("Failed to start transaction\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ pg->transaction_name = name;
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_start_read_committed.h b/src/exchangedb/pg_start_read_committed.h
new file mode 100644
index 000000000..08b60e688
--- /dev/null
+++ b/src/exchangedb/pg_start_read_committed.h
@@ -0,0 +1,39 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_read_committed.h
+ * @brief implementation of the start_read_committed function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_START_READ_COMMITTED_H
+#define PG_START_READ_COMMITTED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Start a READ COMMITTED transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param name unique name identifying the transaction (for debugging)
+ * must point to a constant
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_start_read_committed (void *cls,
+ const char *name);
+
+#endif
diff --git a/src/exchangedb/pg_start_read_only.c b/src/exchangedb/pg_start_read_only.c
new file mode 100644
index 000000000..741d94ba1
--- /dev/null
+++ b/src/exchangedb/pg_start_read_only.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_read_only.c
+ * @brief Implementation of the start_read_only function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_start_read_only.h"
+#include "pg_preflight.h"
+#include "pg_helper.h"
+
+enum GNUNET_GenericReturnValue
+TEH_PG_start_read_only (void *cls,
+ const char *name)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute (
+ "START TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+
+ GNUNET_assert (NULL != name);
+ if (GNUNET_SYSERR ==
+ TEH_PG_preflight (pg))
+ return GNUNET_SYSERR;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting READ ONLY transaction `%s`\n",
+ name);
+ if (GNUNET_OK !=
+ GNUNET_PQ_exec_statements (pg->conn,
+ es))
+ {
+ TALER_LOG_ERROR ("Failed to start transaction\n");
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ pg->transaction_name = name;
+ return GNUNET_OK;
+}
diff --git a/src/exchangedb/pg_start_read_only.h b/src/exchangedb/pg_start_read_only.h
new file mode 100644
index 000000000..bf639c19b
--- /dev/null
+++ b/src/exchangedb/pg_start_read_only.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_start_read_only.h
+ * @brief implementation of the start_read_only function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_START_READ_ONLY_H
+#define PG_START_READ_ONLY_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Start a READ ONLY serializable transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param name unique name identifying the transaction (for debugging)
+ * must point to a constant
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TEH_PG_start_read_only (void *cls,
+ const char *name);
+
+#endif
diff --git a/src/exchangedb/pg_store_wire_transfer_out.c b/src/exchangedb/pg_store_wire_transfer_out.c
new file mode 100644
index 000000000..337dc5855
--- /dev/null
+++ b/src/exchangedb/pg_store_wire_transfer_out.c
@@ -0,0 +1,61 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_store_wire_transfer_out.c
+ * @brief Implementation of the store_wire_transfer_out function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_store_wire_transfer_out.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_store_wire_transfer_out (
+ void *cls,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_Amount *amount)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_timestamp (&date),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_string (exchange_account_section),
+ TALER_PQ_query_param_amount (pg->conn,
+ amount),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "insert_wire_out",
+ "INSERT INTO wire_out "
+ "(execution_date"
+ ",wtid_raw"
+ ",wire_target_h_payto"
+ ",exchange_account_section"
+ ",amount"
+ ") VALUES "
+ "($1, $2, $3, $4, $5);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "insert_wire_out",
+ params);
+}
diff --git a/src/exchangedb/pg_store_wire_transfer_out.h b/src/exchangedb/pg_store_wire_transfer_out.h
new file mode 100644
index 000000000..79950e65a
--- /dev/null
+++ b/src/exchangedb/pg_store_wire_transfer_out.h
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_store_wire_transfer_out.h
+ * @brief implementation of the store_wire_transfer_out function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_STORE_WIRE_TRANSFER_OUT_H
+#define PG_STORE_WIRE_TRANSFER_OUT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Store information about an outgoing wire transfer that was executed.
+ *
+ * @param cls closure
+ * @param date time of the wire transfer
+ * @param wtid subject of the wire transfer
+ * @param h_payto identifies the receiver account of the wire transfer
+ * @param exchange_account_section configuration section of the exchange specifying the
+ * exchange's bank account being used
+ * @param amount amount that was transmitted
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_store_wire_transfer_out (
+ void *cls,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *exchange_account_section,
+ const struct TALER_Amount *amount);
+
+#endif
diff --git a/src/exchangedb/pg_template.c b/src/exchangedb/pg_template.c
new file mode 100644
index 000000000..69cd45035
--- /dev/null
+++ b/src/exchangedb/pg_template.c
@@ -0,0 +1,26 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_template.c
+ * @brief Implementation of the template function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_template.h"
+#include "pg_helper.h"
diff --git a/src/exchangedb/pg_template.h b/src/exchangedb/pg_template.h
new file mode 100644
index 000000000..d858689fb
--- /dev/null
+++ b/src/exchangedb/pg_template.h
@@ -0,0 +1,29 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_template.h
+ * @brief implementation of the template function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_TEMPLATE_H
+#define PG_TEMPLATE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+#endif
diff --git a/src/exchangedb/pg_template.sh b/src/exchangedb/pg_template.sh
new file mode 100755
index 000000000..73bd7e989
--- /dev/null
+++ b/src/exchangedb/pg_template.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# This file is in the public domain.
+#
+# Instantiates pg_template for a particular function.
+
+for n in $*
+do
+ NCAPS=`echo $n | tr a-z A-Z`
+ if test ! -e pg_$n.c
+ then
+ cat pg_template.c | sed -e s/template/$n/g -e s/TEMPLATE/$NCAPS/g > pg_$n.c
+ cat pg_template.h | sed -e s/template/$n/g -e s/TEMPLATE/$NCAPS/g > pg_$n.h
+ echo " plugin->$n\n = &TEH_PG_$n;" >> tmpl.c
+ echo "#include \"pg_$n.h\"" >> tmpl.inc
+ echo " pg_$n.h pg_$n.c \\" >> tmpl.am
+ fi
+done
+
+echo "Add lines from tmpl.am to Makefile.am"
+echo "Add lines from tmpl.inc to plugin_exchangedb_postgres.c at the beginning"
+echo "Add lines from tmpl.c to plugin_exchangedb_postgres.c at the end"
diff --git a/src/exchangedb/pg_test_aml_officer.c b/src/exchangedb/pg_test_aml_officer.c
new file mode 100644
index 000000000..b00828244
--- /dev/null
+++ b/src/exchangedb/pg_test_aml_officer.c
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_test_aml_officer.c
+ * @brief Implementation of the test_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_test_aml_officer.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_test_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (decider_pub),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "test_aml_staff",
+ "SELECT 1 FROM aml_staff"
+ " WHERE decider_pub=$1"
+ " AND is_active;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "test_aml_staff",
+ params);
+}
diff --git a/src/exchangedb/pg_test_aml_officer.h b/src/exchangedb/pg_test_aml_officer.h
new file mode 100644
index 000000000..e034007bd
--- /dev/null
+++ b/src/exchangedb/pg_test_aml_officer.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_test_aml_officer.h
+ * @brief implementation of the test_aml_officer function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_TEST_AML_OFFICER_H
+#define PG_TEST_AML_OFFICER_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Test if the given AML staff member is active
+ * (at least read-only).
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @return database transaction status, if member is unknown or not active, 1 if member is active
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_test_aml_officer (
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub);
+
+
+#endif
diff --git a/src/exchangedb/pg_trigger_aml_process.c b/src/exchangedb/pg_trigger_aml_process.c
new file mode 100644
index 000000000..7534fe3df
--- /dev/null
+++ b/src/exchangedb/pg_trigger_aml_process.c
@@ -0,0 +1,58 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_trigger_aml_process.c
+ * @brief Implementation of the trigger_aml_process function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_trigger_aml_process.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_trigger_aml_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *threshold_crossed)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ TALER_PQ_query_param_amount (pg->conn,
+ threshold_crossed),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "trigger_aml_process",
+ "INSERT INTO aml_status"
+ "(h_payto"
+ ",threshold"
+ ",status)"
+ " VALUES"
+ " ($1, $2, 1)" // 1: decision needed
+ " ON CONFLICT (h_payto) DO"
+ " UPDATE SET"
+ " threshold=$2"
+ " ,status=aml_status.status | 1;"); // do not clear 'frozen' status
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "trigger_aml_process",
+ params);
+}
diff --git a/src/exchangedb/pg_trigger_aml_process.h b/src/exchangedb/pg_trigger_aml_process.h
new file mode 100644
index 000000000..2283571af
--- /dev/null
+++ b/src/exchangedb/pg_trigger_aml_process.h
@@ -0,0 +1,45 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_trigger_aml_process.h
+ * @brief implementation of the trigger_aml_process function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_TRIGGER_AML_PROCESS_H
+#define PG_TRIGGER_AML_PROCESS_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Trigger AML process, an account has crossed the threshold. Inserts or
+ * updates the AML status.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param threshold_crossed existing threshold that was crossed
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_trigger_aml_process (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *threshold_crossed);
+
+
+#endif
diff --git a/src/exchangedb/pg_update_aggregation_transient.c b/src/exchangedb/pg_update_aggregation_transient.c
new file mode 100644
index 000000000..38b65316e
--- /dev/null
+++ b/src/exchangedb/pg_update_aggregation_transient.c
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_aggregation_transient.c
+ * @brief Implementation of the update_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_aggregation_transient.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ TALER_PQ_query_param_amount (pg->conn,
+ total),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_auto_from_type (wtid),
+ GNUNET_PQ_query_param_uint64 (&kyc_requirement_row),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_aggregation_transient",
+ "UPDATE aggregation_transient"
+ " SET amount=$1"
+ " ,legitimization_requirement_serial_id=$4"
+ " WHERE wire_target_h_payto=$2"
+ " AND wtid_raw=$3");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_aggregation_transient",
+ params);
+}
diff --git a/src/exchangedb/pg_update_aggregation_transient.h b/src/exchangedb/pg_update_aggregation_transient.h
new file mode 100644
index 000000000..c444e85bb
--- /dev/null
+++ b/src/exchangedb/pg_update_aggregation_transient.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_aggregation_transient.h
+ * @brief implementation of the update_aggregation_transient function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_AGGREGATION_TRANSIENT_H
+#define PG_UPDATE_AGGREGATION_TRANSIENT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Update existing entry in the transient aggregation table.
+ * @a h_payto is only needed for query performance.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param wtid the raw wire transfer identifier to update
+ * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
+ * @param total new total amount to be wired in the future
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_aggregation_transient (
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
+ const struct TALER_Amount *total);
+
+#endif
diff --git a/src/exchangedb/pg_update_auditor.c b/src/exchangedb/pg_update_auditor.c
new file mode 100644
index 000000000..167a270b9
--- /dev/null
+++ b/src/exchangedb/pg_update_auditor.c
@@ -0,0 +1,59 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_auditor.c
+ * @brief Implementation of the update_auditor function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_auditor.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_auditor (void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool enabled)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_auto_from_type (auditor_pub),
+ GNUNET_PQ_query_param_string (auditor_url),
+ GNUNET_PQ_query_param_string (auditor_name),
+ GNUNET_PQ_query_param_bool (enabled),
+ GNUNET_PQ_query_param_timestamp (&change_date),
+ GNUNET_PQ_query_param_end
+ };
+ /* used in #postgres_update_auditor() */
+ PREPARE (pg,
+ "update_auditor",
+ "UPDATE auditors"
+ " SET"
+ " auditor_url=$2"
+ " ,auditor_name=$3"
+ " ,is_active=$4"
+ " ,last_change=$5"
+ " WHERE auditor_pub=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_auditor",
+ params);
+}
diff --git a/src/exchangedb/pg_update_auditor.h b/src/exchangedb/pg_update_auditor.h
new file mode 100644
index 000000000..ee869f8b7
--- /dev/null
+++ b/src/exchangedb/pg_update_auditor.h
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_auditor.h
+ * @brief implementation of the update_auditor function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_AUDITOR_H
+#define PG_UPDATE_AUDITOR_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+/**
+ * Update information about an auditor that will audit this exchange.
+ *
+ * @param cls closure
+ * @param auditor_pub key of the auditor (primary key for the existing record)
+ * @param auditor_url base URL of the auditor's REST service, to be updated
+ * @param auditor_name name of the auditor (for humans)
+ * @param change_date date when the auditor status was last changed
+ * (only to be used for replay detection)
+ * @param enabled true to enable, false to disable
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_auditor (void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool enabled);
+
+#endif
diff --git a/src/exchangedb/pg_update_kyc_process_by_row.c b/src/exchangedb/pg_update_kyc_process_by_row.c
new file mode 100644
index 000000000..c339436a8
--- /dev/null
+++ b/src/exchangedb/pg_update_kyc_process_by_row.c
@@ -0,0 +1,122 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_kyc_process_by_row.c
+ * @brief Implementation of the update_kyc_process_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_kyc_process_by_row.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_kyc_process_by_row (
+ void *cls,
+ uint64_t process_row,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ const char *redirect_url,
+ struct GNUNET_TIME_Absolute expiration)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&process_row),
+ GNUNET_PQ_query_param_string (provider_section),
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ (NULL != provider_account_id)
+ ? GNUNET_PQ_query_param_string (provider_account_id)
+ : GNUNET_PQ_query_param_null (),
+ (NULL != provider_legitimization_id)
+ ? GNUNET_PQ_query_param_string (provider_legitimization_id)
+ : GNUNET_PQ_query_param_null (),
+ (NULL != redirect_url)
+ ? GNUNET_PQ_query_param_string (redirect_url)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_absolute_time (&expiration),
+ GNUNET_PQ_query_param_end
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Updating KYC data for %llu (%s)\n",
+ (unsigned long long) process_row,
+ provider_section);
+ PREPARE (pg,
+ "update_legitimization_process",
+ "UPDATE legitimization_processes"
+ " SET provider_user_id=$4"
+ " ,provider_legitimization_id=$5"
+ " ,redirect_url=$6"
+ " ,expiration_time=GREATEST(expiration_time,$7)"
+ " WHERE"
+ " h_payto=$3"
+ " AND legitimization_process_serial_id=$1"
+ " AND provider_section=$2;");
+ qs = GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "update_legitimization_process",
+ params);
+ if (qs <= 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to update legitimization process %llu: %d\n",
+ (unsigned long long) process_row,
+ qs);
+ return qs;
+ }
+ if (GNUNET_TIME_absolute_is_future (expiration))
+ {
+ enum GNUNET_DB_QueryStatus qs2;
+ struct TALER_KycCompletedEventP rep = {
+ .header.size = htons (sizeof (rep)),
+ .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED),
+ .h_payto = *h_payto
+ };
+ uint32_t trigger_type = 1;
+ struct GNUNET_PQ_QueryParam params2[] = {
+ GNUNET_PQ_query_param_auto_from_type (h_payto),
+ GNUNET_PQ_query_param_uint32 (&trigger_type),
+ GNUNET_PQ_query_param_end
+ };
+
+ GNUNET_PQ_event_notify (pg->conn,
+ &rep.header,
+ NULL,
+ 0);
+ PREPARE (pg,
+ "alert_kyc_status_change",
+ "INSERT INTO kyc_alerts"
+ " (h_payto"
+ " ,trigger_type)"
+ " VALUES"
+ " ($1,$2);");
+ qs2 = GNUNET_PQ_eval_prepared_non_select (
+ pg->conn,
+ "alert_kyc_status_change",
+ params2);
+ if (qs2 < 0)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to store KYC alert: %d\n",
+ qs2);
+ }
+ return qs;
+}
diff --git a/src/exchangedb/pg_update_kyc_process_by_row.h b/src/exchangedb/pg_update_kyc_process_by_row.h
new file mode 100644
index 000000000..7ef5285e9
--- /dev/null
+++ b/src/exchangedb/pg_update_kyc_process_by_row.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_kyc_process_by_row.h
+ * @brief implementation of the update_kyc_process_by_row function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_KYC_PROCESS_BY_ROW_H
+#define PG_UPDATE_KYC_PROCESS_BY_ROW_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Update KYC requirement check with provider-linkage and/or
+ * expiration data.
+ *
+ * @param cls closure
+ * @param process_row row to select by
+ * @param provider_section provider that must be checked (technically redundant)
+ * @param h_payto account that must be KYC'ed (helps access by shard, otherwise also redundant)
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param redirect_url where the user should be redirected to start the KYC process
+ * @param expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @return database transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_kyc_process_by_row (
+ void *cls,
+ uint64_t process_row,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ const char *redirect_url,
+ struct GNUNET_TIME_Absolute expiration);
+
+#endif
diff --git a/src/exchangedb/pg_update_wire.c b/src/exchangedb/pg_update_wire.c
new file mode 100644
index 000000000..5c4bb9045
--- /dev/null
+++ b/src/exchangedb/pg_update_wire.c
@@ -0,0 +1,81 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022, 2023, 2024 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_wire.c
+ * @brief Implementation of the update_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_update_wire.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_wire (void *cls,
+ const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ struct GNUNET_TIME_Timestamp change_date,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority,
+ bool enabled)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (payto_uri),
+ GNUNET_PQ_query_param_bool (enabled),
+ NULL == conversion_url
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (conversion_url),
+ enabled
+ ? TALER_PQ_query_param_json (debit_restrictions)
+ : GNUNET_PQ_query_param_null (),
+ enabled
+ ? TALER_PQ_query_param_json (credit_restrictions)
+ : GNUNET_PQ_query_param_null (),
+ GNUNET_PQ_query_param_timestamp (&change_date),
+ NULL == master_sig
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (master_sig),
+ NULL == bank_label
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_string (bank_label),
+ GNUNET_PQ_query_param_int64 (&priority),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "update_wire",
+ "UPDATE wire_accounts"
+ " SET"
+ " is_active=$2"
+ " ,conversion_url=$3"
+ " ,debit_restrictions=$4"
+ " ,credit_restrictions=$5"
+ " ,last_change=$6"
+ " ,master_sig=$7"
+ " ,bank_label=$8"
+ " ,priority=$9"
+ " WHERE payto_uri=$1");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "update_wire",
+ params);
+}
diff --git a/src/exchangedb/pg_update_wire.h b/src/exchangedb/pg_update_wire.h
new file mode 100644
index 000000000..a596a0802
--- /dev/null
+++ b/src/exchangedb/pg_update_wire.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_update_wire.h
+ * @brief implementation of the update_wire function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_UPDATE_WIRE_H
+#define PG_UPDATE_WIRE_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+
+/**
+ * Update information about a wire account of the exchange.
+ *
+ * @param cls closure
+ * @param payto_uri account the update is about
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account; NULL allowed if not @a enabled
+ * @param credit_restrictions JSON array with credit restrictions on the account; NULL allowed if not @a enabled
+ * @param change_date date when the account status was last changed
+ * (only to be used for replay detection)
+ * @param master_sig master signature to store, can be NULL (if @a enabled is false)
+ * @param bank_label label to show this entry under in the UI, can be NULL
+ * @param priority determines order in which entries are shown in the UI
+ * @param enabled true to enable, false to disable (the actual change)
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_update_wire (void *cls,
+ const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ struct GNUNET_TIME_Timestamp change_date,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority,
+ bool enabled);
+
+#endif
diff --git a/src/exchangedb/pg_wire_prepare_data_get.c b/src/exchangedb/pg_wire_prepare_data_get.c
new file mode 100644
index 000000000..0cc57e41f
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_get.c
@@ -0,0 +1,140 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_get.c
+ * @brief Implementation of the wire_prepare_data_get function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_wire_prepare_data_get.h"
+#include "pg_helper.h"
+
+/**
+ * Closure for #prewire_cb().
+ */
+struct PrewireContext
+{
+ /**
+ * Function to call on each result.
+ */
+ TALER_EXCHANGEDB_WirePreparationIterator cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * #GNUNET_OK if everything went fine.
+ */
+ enum GNUNET_GenericReturnValue status;
+};
+
+
+/**
+ * Invoke the callback for each result.
+ *
+ * @param cls a `struct MissingWireContext *`
+ * @param result SQL result
+ * @param num_results number of rows in @a result
+ */
+static void
+prewire_cb (void *cls,
+ PGresult *result,
+ unsigned int num_results)
+{
+ struct PrewireContext *pc = cls;
+
+ for (unsigned int i = 0; i < num_results; i++)
+ {
+ uint64_t prewire_uuid;
+ char *wire_method;
+ void *buf = NULL;
+ size_t buf_size;
+ struct GNUNET_PQ_ResultSpec rs[] = {
+ GNUNET_PQ_result_spec_uint64 ("prewire_uuid",
+ &prewire_uuid),
+ GNUNET_PQ_result_spec_string ("wire_method",
+ &wire_method),
+ GNUNET_PQ_result_spec_variable_size ("buf",
+ &buf,
+ &buf_size),
+ GNUNET_PQ_result_spec_end
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_PQ_extract_result (result,
+ rs,
+ i))
+ {
+ GNUNET_break (0);
+ pc->status = GNUNET_SYSERR;
+ return;
+ }
+ pc->cb (pc->cb_cls,
+ prewire_uuid,
+ wire_method,
+ buf,
+ buf_size);
+ GNUNET_PQ_cleanup_result (rs);
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_get (void *cls,
+ uint64_t start_row,
+ uint64_t limit,
+ TALER_EXCHANGEDB_WirePreparationIterator cb,
+ void *cb_cls)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&start_row),
+ GNUNET_PQ_query_param_uint64 (&limit),
+ GNUNET_PQ_query_param_end
+ };
+ struct PrewireContext pc = {
+ .cb = cb,
+ .cb_cls = cb_cls,
+ .status = GNUNET_OK
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ PREPARE (pg,
+ "wire_prepare_data_get",
+ "SELECT"
+ " prewire_uuid"
+ ",wire_method"
+ ",buf"
+ " FROM prewire"
+ " WHERE prewire_uuid >= $1"
+ " AND finished=FALSE"
+ " AND failed=FALSE"
+ " ORDER BY prewire_uuid ASC"
+ " LIMIT $2;");
+ qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
+ "wire_prepare_data_get",
+ params,
+ &prewire_cb,
+ &pc);
+ if (GNUNET_OK != pc.status)
+ return GNUNET_DB_STATUS_HARD_ERROR;
+ return qs;
+}
diff --git a/src/exchangedb/pg_wire_prepare_data_get.h b/src/exchangedb/pg_wire_prepare_data_get.h
new file mode 100644
index 000000000..815c14bdf
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_get.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_get.h
+ * @brief implementation of the wire_prepare_data_get function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_WIRE_PREPARE_DATA_GET_H
+#define PG_WIRE_PREPARE_DATA_GET_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to get an unfinished wire transfer
+ * preparation data. Fetches at most one item.
+ *
+ * @param cls closure
+ * @param start_row offset to query table at
+ * @param limit maximum number of results to return
+ * @param cb function to call for ONE unfinished item
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_get (void *cls,
+ uint64_t start_row,
+ uint64_t limit,
+ TALER_EXCHANGEDB_WirePreparationIterator cb,
+ void *cb_cls);
+
+#endif
diff --git a/src/exchangedb/pg_wire_prepare_data_insert.c b/src/exchangedb/pg_wire_prepare_data_insert.c
new file mode 100644
index 000000000..919fccdaf
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_insert.c
@@ -0,0 +1,54 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_insert.c
+ * @brief Implementation of the wire_prepare_data_insert function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_wire_prepare_data_insert.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_insert (void *cls,
+ const char *type,
+ const char *buf,
+ size_t buf_size)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_string (type),
+ GNUNET_PQ_query_param_fixed_size (buf, buf_size),
+ GNUNET_PQ_query_param_end
+ };
+
+
+ /* Used in #postgres_wire_prepare_data_insert() to store
+ wire transfer information before actually committing it with the bank */
+ PREPARE (pg,
+ "wire_prepare_data_insert",
+ "INSERT INTO prewire "
+ "(wire_method"
+ ",buf"
+ ") VALUES "
+ "($1, $2);");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "wire_prepare_data_insert",
+ params);
+}
diff --git a/src/exchangedb/pg_wire_prepare_data_insert.h b/src/exchangedb/pg_wire_prepare_data_insert.h
new file mode 100644
index 000000000..e73ee152d
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_insert.h
@@ -0,0 +1,43 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_insert.h
+ * @brief implementation of the wire_prepare_data_insert function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_WIRE_PREPARE_DATA_INSERT_H
+#define PG_WIRE_PREPARE_DATA_INSERT_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to insert wire transfer commit data into the DB.
+ *
+ * @param cls closure
+ * @param type type of the wire transfer (i.e. "iban")
+ * @param buf buffer with wire transfer preparation data
+ * @param buf_size number of bytes in @a buf
+ * @return query status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_insert (void *cls,
+ const char *type,
+ const char *buf,
+ size_t buf_size);
+
+#endif
diff --git a/src/exchangedb/pg_wire_prepare_data_mark_failed.c b/src/exchangedb/pg_wire_prepare_data_mark_failed.c
new file mode 100644
index 000000000..1d46c84d4
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_mark_failed.c
@@ -0,0 +1,48 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_mark_failed.c
+ * @brief Implementation of the wire_prepare_data_mark_failed function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_wire_prepare_data_mark_failed.h"
+#include "pg_helper.h"
+
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_mark_failed (
+ void *cls,
+ uint64_t rowid)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "wire_prepare_data_mark_failed",
+ "UPDATE prewire"
+ " SET failed=TRUE"
+ " WHERE prewire_uuid=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "wire_prepare_data_mark_failed",
+ params);
+}
diff --git a/src/exchangedb/pg_wire_prepare_data_mark_failed.h b/src/exchangedb/pg_wire_prepare_data_mark_failed.h
new file mode 100644
index 000000000..98846b284
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_mark_failed.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_mark_failed.h
+ * @brief implementation of the wire_prepare_data_mark_failed function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_WIRE_PREPARE_DATA_MARK_FAILED_H
+#define PG_WIRE_PREPARE_DATA_MARK_FAILED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to mark wire transfer commit data as failed.
+ *
+ * @param cls closure
+ * @param rowid which entry to mark as failed
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_mark_failed (
+ void *cls,
+ uint64_t rowid);
+
+#endif
diff --git a/src/exchangedb/pg_wire_prepare_data_mark_finished.c b/src/exchangedb/pg_wire_prepare_data_mark_finished.c
new file mode 100644
index 000000000..998b9d731
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_mark_finished.c
@@ -0,0 +1,47 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_mark_finished.c
+ * @brief Implementation of the wire_prepare_data_mark_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_error_codes.h"
+#include "taler_dbevents.h"
+#include "taler_pq_lib.h"
+#include "pg_wire_prepare_data_mark_finished.h"
+#include "pg_helper.h"
+
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_mark_finished (
+ void *cls,
+ uint64_t rowid)
+{
+ struct PostgresClosure *pg = cls;
+ struct GNUNET_PQ_QueryParam params[] = {
+ GNUNET_PQ_query_param_uint64 (&rowid),
+ GNUNET_PQ_query_param_end
+ };
+
+ PREPARE (pg,
+ "wire_prepare_data_mark_done",
+ "UPDATE prewire"
+ " SET finished=TRUE"
+ " WHERE prewire_uuid=$1;");
+ return GNUNET_PQ_eval_prepared_non_select (pg->conn,
+ "wire_prepare_data_mark_done",
+ params);
+}
diff --git a/src/exchangedb/pg_wire_prepare_data_mark_finished.h b/src/exchangedb/pg_wire_prepare_data_mark_finished.h
new file mode 100644
index 000000000..ba2e384cd
--- /dev/null
+++ b/src/exchangedb/pg_wire_prepare_data_mark_finished.h
@@ -0,0 +1,40 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file exchangedb/pg_wire_prepare_data_mark_finished.h
+ * @brief implementation of the wire_prepare_data_mark_finished function for Postgres
+ * @author Christian Grothoff
+ */
+#ifndef PG_WIRE_PREPARE_DATA_MARK_FINISHED_H
+#define PG_WIRE_PREPARE_DATA_MARK_FINISHED_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Function called to mark wire transfer commit data as finished.
+ *
+ * @param cls closure
+ * @param rowid which entry to mark as finished
+ * @return transaction status code
+ */
+enum GNUNET_DB_QueryStatus
+TEH_PG_wire_prepare_data_mark_finished (
+ void *cls,
+ uint64_t rowid);
+
+#endif
diff --git a/src/exchangedb/plugin_exchangedb_common.c b/src/exchangedb/plugin_exchangedb_common.c
index ca5903501..562710eaa 100644
--- a/src/exchangedb/plugin_exchangedb_common.c
+++ b/src/exchangedb/plugin_exchangedb_common.c
@@ -19,16 +19,14 @@
* included in each plugin.
* @author Christian Grothoff
*/
+#include "platform.h"
+#include "plugin_exchangedb_common.h"
-/**
- * Free memory associated with the given reserve history.
- *
- * @param cls the @e cls of this struct with the plugin-specific state (unused)
- * @param rh history to free.
- */
-static void
-common_free_reserve_history (void *cls,
- struct TALER_EXCHANGEDB_ReserveHistory *rh)
+
+void
+TEH_COMMON_free_reserve_history (
+ void *cls,
+ struct TALER_EXCHANGEDB_ReserveHistory *rh)
{
(void) cls;
while (NULL != rh)
@@ -87,6 +85,22 @@ common_free_reserve_history (void *cls,
GNUNET_free (history);
break;
}
+ case TALER_EXCHANGEDB_RO_OPEN_REQUEST:
+ {
+ struct TALER_EXCHANGEDB_OpenRequest *or;
+
+ or = rh->details.open_request;
+ GNUNET_free (or);
+ break;
+ }
+ case TALER_EXCHANGEDB_RO_CLOSE_REQUEST:
+ {
+ struct TALER_EXCHANGEDB_CloseRequest *cr;
+
+ cr = rh->details.close_request;
+ GNUNET_free (cr);
+ break;
+ }
}
{
struct TALER_EXCHANGEDB_ReserveHistory *next;
@@ -99,15 +113,10 @@ common_free_reserve_history (void *cls,
}
-/**
- * Free linked list of transactions.
- *
- * @param cls the @e cls of this struct with the plugin-specific state (unused)
- * @param tl list to free
- */
-static void
-common_free_coin_transaction_list (void *cls,
- struct TALER_EXCHANGEDB_TransactionList *tl)
+void
+TEH_COMMON_free_coin_transaction_list (
+ void *cls,
+ struct TALER_EXCHANGEDB_TransactionList *tl)
{
(void) cls;
while (NULL != tl)
@@ -159,6 +168,22 @@ common_free_coin_transaction_list (void *cls,
GNUNET_free (deposit);
break;
}
+ case TALER_EXCHANGEDB_TT_PURSE_REFUND:
+ {
+ struct TALER_EXCHANGEDB_PurseRefundListEntry *prefund;
+
+ prefund = tl->details.purse_refund;
+ GNUNET_free (prefund);
+ break;
+ }
+ case TALER_EXCHANGEDB_TT_RESERVE_OPEN:
+ {
+ struct TALER_EXCHANGEDB_ReserveOpenListEntry *role;
+
+ role = tl->details.reserve_open;
+ GNUNET_free (role);
+ break;
+ }
}
{
struct TALER_EXCHANGEDB_TransactionList *next;
diff --git a/src/exchangedb/plugin_exchangedb_common.h b/src/exchangedb/plugin_exchangedb_common.h
new file mode 100644
index 000000000..0355c44ab
--- /dev/null
+++ b/src/exchangedb/plugin_exchangedb_common.h
@@ -0,0 +1,51 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file plugin_exchangedb_common.h
+ * @brief implementation of database-independent functions
+ * @author Christian Grothoff
+ */
+#ifndef PLUGIN_EXCHANGEDB_COMMON_H
+#define PLUGIN_EXCHANGEDB_COMMON_H
+
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+
+/**
+ * Free memory associated with the given reserve history.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state (unused)
+ * @param[in] rh history to free.
+ */
+void
+TEH_COMMON_free_reserve_history (
+ void *cls,
+ struct TALER_EXCHANGEDB_ReserveHistory *rh);
+
+
+/**
+ * Free linked list of transactions.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state (unused)
+ * @param[in] tl list to free
+ */
+void
+TEH_COMMON_free_coin_transaction_list (
+ void *cls,
+ struct TALER_EXCHANGEDB_TransactionList *tl);
+
+#endif
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index cbacebbd6..108b55219 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014--2022 Taler Systems SA
+ Copyright (C) 2014--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,47 +21,213 @@
* @author Christian Grothoff
* @author Sree Harsha Totakura
* @author Marcello Stanisci
+ * @author Özgür Kesim
*/
#include "platform.h"
+#include <poll.h>
+#include <pthread.h>
+#include <libpq-fe.h>
#include "taler_error_codes.h"
#include "taler_dbevents.h"
#include "taler_pq_lib.h"
#include "taler_util.h"
#include "taler_json_lib.h"
#include "taler_exchangedb_plugin.h"
-#include <poll.h>
-#include <pthread.h>
-#include <libpq-fe.h>
-
-#include "plugin_exchangedb_common.c"
+#include "plugin_exchangedb_common.h"
+#include "pg_delete_aggregation_transient.h"
+#include "pg_get_link_data.h"
+#include "pg_helper.h"
+#include "pg_do_reserve_open.h"
+#include "pg_get_coin_transactions.h"
+#include "pg_get_expired_reserves.h"
+#include "pg_get_purse_request.h"
+#include "pg_get_reserve_history.h"
+#include "pg_get_unfinished_close_requests.h"
+#include "pg_insert_close_request.h"
+#include "pg_insert_records_by_table.h"
+#include "pg_insert_reserve_open_deposit.h"
+#include "pg_get_pending_kyc_requirement_process.h"
+#include "pg_iterate_kyc_reference.h"
+#include "pg_iterate_reserve_close_info.h"
+#include "pg_lookup_records_by_table.h"
+#include "pg_lookup_serial_by_table.h"
+#include "pg_select_account_merges_above_serial_id.h"
+#include "pg_select_aml_threshold.h"
+#include "pg_select_all_purse_decisions_above_serial_id.h"
+#include "pg_select_purse.h"
+#include "pg_select_purse_deposits_above_serial_id.h"
+#include "pg_select_purse_merges_above_serial_id.h"
+#include "pg_select_purse_requests_above_serial_id.h"
+#include "pg_select_reserve_close_info.h"
+#include "pg_select_reserve_closed_above_serial_id.h"
+#include "pg_select_reserve_open_above_serial_id.h"
+#include "pg_insert_purse_request.h"
+#include "pg_iterate_active_signkeys.h"
+#include "pg_preflight.h"
+#include "pg_commit.h"
+#include "pg_drop_tables.h"
+#include "pg_select_satisfied_kyc_processes.h"
+#include "pg_select_aggregation_amounts_for_kyc_check.h"
+#include "pg_kyc_provider_account_lookup.h"
+#include "pg_lookup_kyc_requirement_by_row.h"
+#include "pg_insert_kyc_requirement_for_account.h"
+#include "pg_lookup_kyc_process_by_account.h"
+#include "pg_update_kyc_process_by_row.h"
+#include "pg_insert_kyc_requirement_process.h"
+#include "pg_select_withdraw_amounts_for_kyc_check.h"
+#include "pg_select_merge_amounts_for_kyc_check.h"
+#include "pg_profit_drains_set_finished.h"
+#include "pg_profit_drains_get_pending.h"
+#include "pg_get_drain_profit.h"
+#include "pg_get_purse_deposit.h"
+#include "pg_insert_contract.h"
+#include "pg_insert_kyc_failure.h"
+#include "pg_select_contract.h"
+#include "pg_select_purse_merge.h"
+#include "pg_select_contract_by_purse.h"
+#include "pg_insert_drain_profit.h"
+#include "pg_do_reserve_purse.h"
+#include "pg_lookup_global_fee_by_time.h"
+#include "pg_do_purse_deposit.h"
+#include "pg_activate_signing_key.h"
+#include "pg_update_auditor.h"
+#include "pg_begin_revolving_shard.h"
+#include "pg_get_extension_manifest.h"
+#include "pg_do_purse_delete.h"
+#include "pg_do_purse_merge.h"
+#include "pg_start_read_committed.h"
+#include "pg_start_read_only.h"
+#include "pg_insert_denomination_info.h"
+#include "pg_do_batch_withdraw_insert.h"
+#include "pg_lookup_wire_fee_by_time.h"
+#include "pg_start.h"
+#include "pg_rollback.h"
+#include "pg_create_tables.h"
+#include "pg_event_listen.h"
+#include "pg_event_listen_cancel.h"
+#include "pg_event_notify.h"
+#include "pg_get_denomination_info.h"
+#include "pg_iterate_denomination_info.h"
+#include "pg_iterate_denominations.h"
+#include "pg_iterate_active_auditors.h"
+#include "pg_iterate_auditor_denominations.h"
+#include "pg_reserves_get.h"
+#include "pg_reserves_get_origin.h"
+#include "pg_drain_kyc_alert.h"
+#include "pg_reserves_in_insert.h"
+#include "pg_get_withdraw_info.h"
+#include "pg_get_age_withdraw.h"
+#include "pg_do_batch_withdraw.h"
+#include "pg_do_age_withdraw.h"
+#include "pg_get_policy_details.h"
+#include "pg_persist_policy_details.h"
+#include "pg_do_deposit.h"
+#include "pg_get_wire_hash_for_contract.h"
+#include "pg_add_policy_fulfillment_proof.h"
+#include "pg_do_melt.h"
+#include "pg_do_refund.h"
+#include "pg_do_recoup.h"
+#include "pg_do_recoup_refresh.h"
+#include "pg_get_reserve_balance.h"
+#include "pg_count_known_coins.h"
+#include "pg_ensure_coin_known.h"
+#include "pg_get_known_coin.h"
+#include "pg_get_signature_for_known_coin.h"
+#include "pg_get_coin_denomination.h"
+#include "pg_have_deposit2.h"
+#include "pg_aggregate.h"
+#include "pg_create_aggregation_transient.h"
+#include "pg_select_aggregation_transient.h"
+#include "pg_find_aggregation_transient.h"
+#include "pg_update_aggregation_transient.h"
+#include "pg_get_ready_deposit.h"
+#include "pg_insert_refund.h"
+#include "pg_select_refunds_by_coin.h"
+#include "pg_get_melt.h"
+#include "pg_insert_refresh_reveal.h"
+#include "pg_get_refresh_reveal.h"
+#include "pg_lookup_wire_transfer.h"
+#include "pg_lookup_transfer_by_deposit.h"
+#include "pg_insert_wire_fee.h"
+#include "pg_insert_global_fee.h"
+#include "pg_get_wire_fee.h"
+#include "pg_get_global_fee.h"
+#include "pg_get_global_fees.h"
+#include "pg_insert_reserve_closed.h"
+#include "pg_wire_prepare_data_insert.h"
+#include "pg_wire_prepare_data_mark_finished.h"
+#include "pg_wire_prepare_data_mark_failed.h"
+#include "pg_wire_prepare_data_get.h"
+#include "pg_start_deferred_wire_out.h"
+#include "pg_store_wire_transfer_out.h"
+#include "pg_gc.h"
+#include "pg_inject_auditor_triggers.h"
+#include "pg_select_coin_deposits_above_serial_id.h"
+#include "pg_select_purse_decisions_above_serial_id.h"
+#include "pg_select_purse_deposits_by_purse.h"
+#include "pg_select_refreshes_above_serial_id.h"
+#include "pg_select_refunds_above_serial_id.h"
+#include "pg_select_reserves_in_above_serial_id.h"
+#include "pg_select_reserves_in_above_serial_id_by_account.h"
+#include "pg_select_withdrawals_above_serial_id.h"
+#include "pg_select_wire_out_above_serial_id.h"
+#include "pg_select_wire_out_above_serial_id_by_account.h"
+#include "pg_select_recoup_above_serial_id.h"
+#include "pg_select_recoup_refresh_above_serial_id.h"
+#include "pg_get_reserve_by_h_blind.h"
+#include "pg_get_old_coin_by_h_blind.h"
+#include "pg_insert_denomination_revocation.h"
+#include "pg_get_denomination_revocation.h"
+#include "pg_select_batch_deposits_missing_wire.h"
+#include "pg_select_justification_for_missing_wire.h"
+#include "pg_select_aggregations_above_serial.h"
+#include "pg_lookup_auditor_timestamp.h"
+#include "pg_lookup_auditor_status.h"
+#include "pg_insert_auditor.h"
+#include "pg_lookup_wire_timestamp.h"
+#include "pg_insert_wire.h"
+#include "pg_update_wire.h"
+#include "pg_get_wire_accounts.h"
+#include "pg_get_wire_fees.h"
+#include "pg_insert_signkey_revocation.h"
+#include "pg_lookup_signkey_revocation.h"
+#include "pg_lookup_denomination_key.h"
+#include "pg_insert_auditor_denom_sig.h"
+#include "pg_select_auditor_denom_sig.h"
+#include "pg_add_denomination_key.h"
+#include "pg_lookup_signing_key.h"
+#include "pg_begin_shard.h"
+#include "pg_abort_shard.h"
+#include "pg_complete_shard.h"
+#include "pg_release_revolving_shard.h"
+#include "pg_delete_shard_locks.h"
+#include "pg_set_extension_manifest.h"
+#include "pg_insert_partner.h"
+#include "pg_expire_purse.h"
+#include "pg_select_purse_by_merge_pub.h"
+#include "pg_set_purse_balance.h"
+#include "pg_reserves_update.h"
+#include "pg_setup_wire_target.h"
+#include "pg_compute_shard.h"
+#include "pg_insert_kyc_attributes.h"
+#include "pg_select_similar_kyc_attributes.h"
+#include "pg_select_kyc_attributes.h"
+#include "pg_insert_aml_officer.h"
+#include "pg_test_aml_officer.h"
+#include "pg_lookup_aml_officer.h"
+#include "pg_trigger_aml_process.h"
+#include "pg_select_aml_process.h"
+#include "pg_select_aml_history.h"
+#include "pg_insert_aml_decision.h"
+#include "pg_batch_ensure_coin_known.h"
/**
* Set to 1 to enable Postgres auto_explain module. This will
* slow down things a _lot_, but also provide extensive logging
* in the Postgres database logger for performance analysis.
*/
-#define AUTO_EXPLAIN 1
-
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT(field,amountp) TALER_PQ_result_spec_amount ( \
- field,pg->currency,amountp)
+#define AUTO_EXPLAIN 0
-/**
- * Wrapper macro to add the currency from the plugin's state
- * when fetching amounts from the database. NBO variant.
- *
- * @param field name of the database field to fetch amount from
- * @param[out] amountp pointer to amount to set
- */
-#define TALER_PQ_RESULT_SPEC_AMOUNT_NBO(field, \
- amountp) TALER_PQ_result_spec_amount_nbo ( \
- field,pg->currency,amountp)
/**
* Log a really unexpected PQ error with all the details we can get hold of.
@@ -82,4201 +248,13 @@
/**
- * Type of the "cls" argument given to each of the functions in
- * our API.
- */
-struct PostgresClosure
-{
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Directory with SQL statements to run to create tables.
- */
- char *sql_dir;
-
- /**
- * After how long should idle reserves be closed?
- */
- struct GNUNET_TIME_Relative idle_reserve_expiration_time;
-
- /**
- * After how long should reserves that have seen withdraw operations
- * be garbage collected?
- */
- struct GNUNET_TIME_Relative legal_reserve_expiration_time;
-
- /**
- * What delay should we introduce before ready transactions
- * are actually aggregated?
- */
- struct GNUNET_TIME_Relative aggregator_shift;
-
- /**
- * Which currency should we assume all amounts to be in?
- */
- char *currency;
-
- /**
- * Our base URL.
- */
- char *exchange_url;
-
- /**
- * Postgres connection handle.
- */
- struct GNUNET_PQ_Context *conn;
-
- /**
- * Name of the current transaction, for debugging.
- */
- const char *transaction_name;
-
- /**
- * Did we initialize the prepared statements
- * for this session?
- */
- bool init;
-
-};
-
-
-/**
- * Drop all Taler tables. This should only be used by testcases.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_drop_tables (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- "drop",
- NULL,
- NULL);
- if (NULL == conn)
- return GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- if (NULL != pg->conn)
- {
- GNUNET_PQ_disconnect (pg->conn);
- pg->conn = NULL;
- pg->init = false;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Drop all Taler shard tables. This should only be used by testcases.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param old_idx the index which was used when the shard database was initialized
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_drop_shard_tables (void *cls,
- uint32_t old_idx)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint32 (&old_idx),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("drop_shard_tables",
- "SELECT"
- " drop_shard"
- " ($1);",
- 1),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- NULL,
- NULL,
- ps);
- if (NULL == conn)
- return GNUNET_SYSERR;
- if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
- "drop_shard_tables",
- params))
- ret = GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- "shard-drop",
- NULL,
- NULL);
- if (NULL == conn)
- return GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- if (NULL != pg->conn)
- {
- GNUNET_PQ_disconnect (pg->conn);
- pg->conn = NULL;
- pg->init = false;
- }
- return ret;
-}
-
-
-/**
- * Create the necessary tables if they are not present
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_create_tables (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- "exchange-",
- NULL,
- NULL);
- if (NULL == conn)
- return GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- return GNUNET_OK;
-}
-
-
-/**
- * Create tables of a shard node with index idx
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param idx the shards index, will be appended as suffix to all tables
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_create_shard_tables (void *cls,
- uint32_t idx)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint32 (&idx),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("create_shard_tables",
- "SELECT"
- " setup_shard"
- " ($1);",
- 1),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- "shard-",
- NULL,
- ps);
- if (NULL == conn)
- return GNUNET_SYSERR;
- if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
- "create_shard_tables",
- params))
- ret = GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- return ret;
-}
-
-
-/**
- * Setup partitions of already existing tables
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param num the number of partitions to create for each partitioned table
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_setup_partitions (void *cls,
- uint32_t num)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint32 (&num),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("setup_partitions",
- "SELECT"
- " create_partitions"
- " ($1);",
- 1),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- NULL,
- NULL,
- ps);
- if (NULL == conn)
- return GNUNET_SYSERR;
- ret = GNUNET_OK;
- if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
- "setup_partitions",
- params))
- ret = GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- return ret;
-}
-
-
-/**
- * Setup foreign servers (shards) for already existing tables
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param num the number of foreign servers (shards) to create for each partitioned table
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
-static enum GNUNET_GenericReturnValue
-postgres_setup_foreign_servers (void *cls,
- uint32_t num)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret = GNUNET_OK;
- char *shard_domain = NULL;
- char *remote_user = NULL;
- char *remote_user_pw = NULL;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (pg->cfg,
- "exchange",
- "SHARD_DOMAIN",
- &shard_domain))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "SHARD_DOMAIN");
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (pg->cfg,
- "exchangedb-postgres",
- "SHARD_REMOTE_USER",
- &remote_user))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchangedb-postgres",
- "SHARD_REMOTE_USER");
- GNUNET_free (shard_domain);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (pg->cfg,
- "exchangedb-postgres",
- "SHARD_REMOTE_USER_PW",
- &remote_user_pw))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchangedb-postgres",
- "SHARD_REMOTE_USER_PW");
- GNUNET_free (shard_domain);
- GNUNET_free (remote_user);
- return GNUNET_SYSERR;
- }
-
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint32 (&num),
- GNUNET_PQ_query_param_string (shard_domain),
- GNUNET_PQ_query_param_string (remote_user),
- GNUNET_PQ_query_param_string (remote_user_pw),
- GNUNET_PQ_query_param_end
- };
-
- struct GNUNET_PQ_PreparedStatement ps[] = {
- GNUNET_PQ_make_prepare ("create_foreign_servers",
- "SELECT"
- " create_foreign_servers"
- " ($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- NULL,
- NULL,
- ps);
- if (NULL == conn)
- {
- ret = GNUNET_SYSERR;
- }
- else if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
- "create_foreign_servers",
- params))
- {
- ret = GNUNET_SYSERR;
- }
- GNUNET_free (shard_domain);
- GNUNET_free (remote_user);
- GNUNET_free (remote_user_pw);
- GNUNET_PQ_disconnect (conn);
- return ret;
-}
-
-
-/**
- * Initialize prepared statements for @a pg.
- *
- * @param[in,out] pg connection to initialize
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-prepare_statements (struct PostgresClosure *pg)
-{
- enum GNUNET_GenericReturnValue ret;
- struct GNUNET_PQ_PreparedStatement ps[] = {
- /* Used in #postgres_insert_denomination_info() and
- #postgres_add_denomination_key() */
- GNUNET_PQ_make_prepare (
- "denomination_insert",
- "INSERT INTO denominations "
- "(denom_pub_hash"
- ",denom_pub"
- ",master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val" /* value of this denom */
- ",coin_frac" /* fractional value of this denom */
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",age_mask"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
- " $11, $12, $13, $14, $15, $16, $17, $18);",
- 18),
- /* Used in #postgres_iterate_denomination_info() */
- GNUNET_PQ_make_prepare (
- "denomination_iterate",
- "SELECT"
- " master_sig"
- ",denom_pub_hash"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val" /* value of this denom */
- ",coin_frac" /* fractional value of this denom */
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",denom_pub"
- ",age_mask"
- " FROM denominations;",
- 0),
- /* Used in #postgres_iterate_denominations() */
- GNUNET_PQ_make_prepare (
- "select_denominations",
- "SELECT"
- " denominations.master_sig"
- ",denom_revocations_serial_id IS NOT NULL AS revoked"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val" /* value of this denom */
- ",coin_frac" /* fractional value of this denom */
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",denom_type"
- ",age_mask"
- ",denom_pub"
- " FROM denominations"
- " LEFT JOIN "
- " denomination_revocations USING (denominations_serial);",
- 0),
- /* Used in #postgres_iterate_active_signkeys() */
- GNUNET_PQ_make_prepare (
- "select_signkeys",
- "SELECT"
- " master_sig"
- ",exchange_pub"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- " FROM exchange_sign_keys esk"
- " WHERE"
- " expire_sign > $1"
- " AND NOT EXISTS "
- " (SELECT esk_serial "
- " FROM signkey_revocations skr"
- " WHERE esk.esk_serial = skr.esk_serial);",
- 1),
- /* Used in #postgres_iterate_auditor_denominations() */
- GNUNET_PQ_make_prepare (
- "select_auditor_denoms",
- "SELECT"
- " auditors.auditor_pub"
- ",denominations.denom_pub_hash"
- ",auditor_denom_sigs.auditor_sig"
- " FROM auditor_denom_sigs"
- " JOIN auditors USING (auditor_uuid)"
- " JOIN denominations USING (denominations_serial)"
- " WHERE auditors.is_active;",
- 0),
- /* Used in #postgres_iterate_active_auditors() */
- GNUNET_PQ_make_prepare (
- "select_auditors",
- "SELECT"
- " auditor_pub"
- ",auditor_url"
- ",auditor_name"
- " FROM auditors"
- " WHERE"
- " is_active;",
- 0),
- /* Used in #postgres_get_denomination_info() */
- GNUNET_PQ_make_prepare (
- "denomination_get",
- "SELECT"
- " master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val" /* value of this denom */
- ",coin_frac" /* fractional value of this denom */
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",age_mask"
- " FROM denominations"
- " WHERE denom_pub_hash=$1;",
- 1),
- /* Used in #postgres_insert_denomination_revocation() */
- GNUNET_PQ_make_prepare (
- "denomination_revocation_insert",
- "INSERT INTO denomination_revocations "
- "(denominations_serial"
- ",master_sig"
- ") SELECT denominations_serial,$2"
- " FROM denominations"
- " WHERE denom_pub_hash=$1;",
- 2),
- /* Used in #postgres_get_denomination_revocation() */
- GNUNET_PQ_make_prepare (
- "denomination_revocation_get",
- "SELECT"
- " master_sig"
- ",denom_revocations_serial_id"
- " FROM denomination_revocations"
- " WHERE denominations_serial="
- " (SELECT denominations_serial"
- " FROM denominations"
- " WHERE denom_pub_hash=$1);",
- 1),
- /* Used in #postgres_reserves_get() */
- GNUNET_PQ_make_prepare (
- "reserves_get_with_kyc",
- "SELECT"
- " current_balance_val"
- ",current_balance_frac"
- ",expiration_date"
- ",gc_date"
- ",kyc_ok"
- ",wire_target_serial_id AS payment_target_uuid"
- " FROM reserves"
- " JOIN reserves_in ri USING (reserve_pub)"
- " JOIN wire_targets wt "
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE reserve_pub=$1"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_set_kyc_ok() */
- GNUNET_PQ_make_prepare (
- "set_kyc_ok",
- "UPDATE wire_targets"
- " SET kyc_ok=TRUE"
- ",external_id=$2"
- " WHERE wire_target_h_payto=$1",
- 2),
- GNUNET_PQ_make_prepare (
- "get_kyc_h_payto",
- "SELECT"
- " wire_target_h_payto"
- " FROM wire_targets"
- " WHERE wire_target_h_payto=$1"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_insert_partner() */
- GNUNET_PQ_make_prepare (
- "insert_partner",
- "INSERT INTO partners"
- " (partner_master_pub"
- " ,start_date"
- " ,end_date"
- " ,wad_frequency"
- " ,wad_fee_val"
- " ,wad_fee_frac"
- " ,master_sig"
- " ,partner_base_url"
- " ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
- /* Used in #postgres_inselect_wallet_kyc_status() */
- GNUNET_PQ_make_prepare (
- "insert_kyc_status",
- "INSERT INTO wire_targets"
- " (wire_target_h_payto"
- " ,payto_uri"
- " ) VALUES "
- " ($1, $2)"
- " RETURNING wire_target_serial_id",
- 2),
- GNUNET_PQ_make_prepare (
- "select_kyc_status_by_payto",
- "SELECT "
- " kyc_ok"
- ",wire_target_serial_id"
- " FROM wire_targets"
- " WHERE wire_target_h_payto=$1;",
- 1),
- /* Used in #reserves_get() */
- GNUNET_PQ_make_prepare (
- "reserves_get",
- "SELECT"
- " current_balance_val"
- ",current_balance_frac"
- ",expiration_date"
- ",gc_date"
- " FROM reserves"
- " WHERE reserve_pub=$1"
- " LIMIT 1;",
- 1),
- GNUNET_PQ_make_prepare (
- "reserve_create",
- "INSERT INTO reserves "
- "(reserve_pub"
- ",current_balance_val"
- ",current_balance_frac"
- ",expiration_date"
- ",gc_date"
- ") VALUES "
- "($1, $2, $3, $4, $5)"
- " ON CONFLICT DO NOTHING"
- " RETURNING reserve_uuid;",
- 5),
- /* Used in #postgres_insert_reserve_closed() */
- GNUNET_PQ_make_prepare (
- "reserves_close_insert",
- "INSERT INTO reserves_close "
- "(reserve_pub"
- ",execution_date"
- ",wtid"
- ",wire_target_h_payto"
- ",amount_val"
- ",amount_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
- /* Used in #reserves_update() when the reserve is updated */
- GNUNET_PQ_make_prepare (
- "reserve_update",
- "UPDATE reserves"
- " SET"
- " expiration_date=$1"
- ",gc_date=$2"
- ",current_balance_val=$3"
- ",current_balance_frac=$4"
- " WHERE reserve_pub=$5;",
- 5),
- /* Used in #postgres_reserves_in_insert() to store transaction details */
- GNUNET_PQ_make_prepare (
- "reserves_in_add_transaction",
- "INSERT INTO reserves_in "
- "(reserve_pub"
- ",wire_reference"
- ",credit_val"
- ",credit_frac"
- ",exchange_account_section"
- ",wire_source_h_payto"
- ",execution_date"
- ") VALUES ($1, $2, $3, $4, $5, $6, $7)"
- " ON CONFLICT DO NOTHING;",
- 7),
- /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
- transactions for reserves with serial id '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_reserves_in_get_transactions_incr",
- "SELECT"
- " reserves.reserve_pub"
- ",wire_reference"
- ",credit_val"
- ",credit_frac"
- ",execution_date"
- ",payto_uri AS sender_account_details"
- ",reserve_in_serial_id"
- " FROM reserves_in"
- " JOIN reserves"
- " USING (reserve_pub)"
- " JOIN wire_targets"
- " ON (wire_source_h_payto = wire_target_h_payto)"
- " WHERE reserve_in_serial_id>=$1"
- " ORDER BY reserve_in_serial_id;",
- 1),
- /* Used in postgres_select_reserves_in_above_serial_id() to obtain inbound
- transactions for reserves with serial id '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_reserves_in_get_transactions_incr_by_account",
- "SELECT"
- " reserves.reserve_pub"
- ",wire_reference"
- ",credit_val"
- ",credit_frac"
- ",execution_date"
- ",payto_uri AS sender_account_details"
- ",reserve_in_serial_id"
- " FROM reserves_in"
- " JOIN reserves "
- " USING (reserve_pub)"
- " JOIN wire_targets"
- " ON (wire_source_h_payto = wire_target_h_payto)"
- " WHERE reserve_in_serial_id>=$1 AND exchange_account_section=$2"
- " ORDER BY reserve_in_serial_id;",
- 2),
- /* Used in #postgres_get_reserve_history() to obtain inbound transactions
- for a reserve */
- GNUNET_PQ_make_prepare (
- "reserves_in_get_transactions",
- /*
- "SELECT"
- " wire_reference"
- ",credit_val"
- ",credit_frac"
- ",execution_date"
- ",payto_uri AS sender_account_details"
- " FROM reserves_in"
- " JOIN wire_targets"
- " ON (wire_source_h_payto = wire_target_h_payto)"
- " WHERE reserve_pub=$1;",
- */
- "WITH ri AS MATERIALIZED ( "
- " SELECT * "
- " FROM reserves_in "
- " WHERE reserve_pub = $1 "
- ") "
- "SELECT "
- " wire_reference "
- " ,credit_val "
- " ,credit_frac "
- " ,execution_date "
- " ,payto_uri AS sender_account_details "
- "FROM wire_targets "
- "JOIN ri "
- " ON (wire_target_h_payto = wire_source_h_payto) "
- "WHERE wire_target_h_payto = ( "
- " SELECT wire_source_h_payto FROM ri "
- "); ",
- 1),
- /* Used in #postgres_do_withdraw() to store
- the signature of a blinded coin with the blinded coin's
- details before returning it during /reserve/withdraw. We store
- the coin's denomination information (public key, signature)
- and the blinded message as well as the reserve that the coin
- is being withdrawn from and the signature of the message
- authorizing the withdrawal. */
- GNUNET_PQ_make_prepare (
- "call_withdraw",
- "SELECT "
- " reserve_found"
- ",balance_ok"
- ",kycok AS kyc_ok"
- ",account_uuid AS payment_target_uuid"
- ",ruuid"
- " FROM exchange_do_withdraw"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10);",
- 10),
- /* Used in #postgres_do_batch_withdraw() to
- update the reserve balance and check its status */
- GNUNET_PQ_make_prepare (
- "call_batch_withdraw",
- "SELECT "
- " reserve_found"
- ",balance_ok"
- ",kycok AS kyc_ok"
- ",account_uuid AS payment_target_uuid"
- ",ruuid"
- " FROM exchange_do_batch_withdraw"
- " ($1,$2,$3,$4,$5);",
- 5),
- /* Used in #postgres_do_batch_withdraw_insert() to store
- the signature of a blinded coin with the blinded coin's
- details. */
- GNUNET_PQ_make_prepare (
- "call_batch_withdraw_insert",
- "SELECT "
- " out_denom_unknown AS denom_unknown"
- ",out_conflict AS conflict"
- ",out_nonce_reuse AS nonce_reuse"
- " FROM exchange_do_batch_withdraw_insert"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
- 9),
- /* Used in #postgres_do_withdraw_limit_check() to check
- if the withdrawals remain below the limit under which
- KYC is not required. */
- GNUNET_PQ_make_prepare (
- "call_withdraw_limit_check",
- "SELECT "
- " below_limit"
- " FROM exchange_do_withdraw_limit_check"
- " ($1,$2,$3,$4);",
- 4),
- /* Used in #postgres_do_deposit() to execute a deposit,
- checking the coin's balance in the process as needed. */
- GNUNET_PQ_make_prepare (
- "call_deposit",
- "SELECT "
- " out_exchange_timestamp AS exchange_timestamp"
- ",out_balance_ok AS balance_ok"
- ",out_conflict AS conflicted"
- " FROM exchange_do_deposit"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);",
- 17),
- /* used in postgres_do_purse_deposit() */
- GNUNET_PQ_make_prepare (
- "call_purse_deposit",
- "SELECT "
- " out_balance_ok AS balance_ok"
- ",out_conflict AS conflict"
- " FROM exchange_do_purse_deposit"
- " ($1,$2,$3,$4,$5,$6,$7,$8);",
- 8),
- /* Used in #postgres_update_aggregation_transient() */
- GNUNET_PQ_make_prepare (
- "set_purse_balance",
- "UPDATE purse_requests"
- " SET balance_val=$2"
- " ,balance_frac=$3"
- " WHERE purse_pub=$1;",
- 3),
- /* used in #postgres_expire_purse() */
- GNUNET_PQ_make_prepare (
- "call_expire_purse",
- "SELECT "
- " out_found AS found"
- " FROM exchange_do_expire_purse"
- " ($1,$2);",
- 2),
- /* Used in #postgres_do_melt() to melt a coin. */
- GNUNET_PQ_make_prepare (
- "call_melt",
- "SELECT "
- " out_balance_ok AS balance_ok"
- ",out_zombie_bad AS zombie_required"
- ",out_noreveal_index AS noreveal_index"
- " FROM exchange_do_melt"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
- 9),
- /* Used in #postgres_do_refund() to refund a deposit. */
- GNUNET_PQ_make_prepare (
- "call_refund",
- "SELECT "
- " out_not_found AS not_found"
- ",out_refund_ok AS refund_ok"
- ",out_gone AS gone"
- ",out_conflict AS conflict"
- " FROM exchange_do_refund"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13);",
- 13),
- /* Used in #postgres_do_recoup() to recoup a coin to a reserve. */
- GNUNET_PQ_make_prepare (
- "call_recoup",
- "SELECT "
- " out_recoup_timestamp AS recoup_timestamp"
- ",out_recoup_ok AS recoup_ok"
- ",out_internal_failure AS internal_failure"
- " FROM exchange_do_recoup_to_reserve"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9);",
- 9),
- /* Used in #postgres_do_recoup_refresh() to recoup a coin to a zombie coin. */
- GNUNET_PQ_make_prepare (
- "call_recoup_refresh",
- "SELECT "
- " out_recoup_timestamp AS recoup_timestamp"
- ",out_recoup_ok AS recoup_ok"
- ",out_internal_failure AS internal_failure"
- " FROM exchange_do_recoup_to_coin"
- " ($1,$2,$3,$4,$5,$6,$7);",
- 7),
- /* Used in #postgres_get_withdraw_info() to
- locate the response for a /reserve/withdraw request
- using the hash of the blinded message. Used to
- make sure /reserve/withdraw requests are idempotent. */
- GNUNET_PQ_make_prepare (
- "get_withdraw_info",
- "SELECT"
- " denom.denom_pub_hash"
- ",denom_sig"
- ",reserve_sig"
- ",reserves.reserve_pub"
- ",execution_date"
- ",h_blind_ev"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",denom.fee_withdraw_val"
- ",denom.fee_withdraw_frac"
- " FROM reserves_out"
- " JOIN reserves"
- " USING (reserve_uuid)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE h_blind_ev=$1;",
- 1),
- /* Used during #postgres_get_reserve_history() to
- obtain all of the /reserve/withdraw operations that
- have been performed on a given reserve. (i.e. to
- demonstrate double-spending) */
- GNUNET_PQ_make_prepare (
- "get_reserves_out",
- /*
- "SELECT"
- " ro.h_blind_ev"
- ",denom.denom_pub_hash"
- ",ro.denom_sig"
- ",ro.reserve_sig"
- ",ro.execution_date"
- ",ro.amount_with_fee_val"
- ",ro.amount_with_fee_frac"
- ",denom.fee_withdraw_val"
- ",denom.fee_withdraw_frac"
- " FROM reserves res"
- " JOIN reserves_out_by_reserve ror"
- " ON (res.reserve_uuid = ror.reserve_uuid)"
- " JOIN reserves_out ro"
- " ON (ro.h_blind_ev = ror.h_blind_ev)"
- " JOIN denominations denom"
- " ON (ro.denominations_serial = denom.denominations_serial)"
- " WHERE res.reserve_pub=$1;",
- */
- "WITH robr AS MATERIALIZED ( "
- " SELECT h_blind_ev "
- " FROM reserves_out_by_reserve "
- " WHERE reserve_uuid= ( "
- " SELECT reserve_uuid "
- " FROM reserves "
- " WHERE reserve_pub = $1 "
- " ) "
- ") SELECT "
- " ro.h_blind_ev "
- " ,denom.denom_pub_hash "
- " ,ro.denom_sig "
- " ,ro.reserve_sig "
- " ,ro.execution_date "
- " ,ro.amount_with_fee_val "
- " ,ro.amount_with_fee_frac "
- " ,denom.fee_withdraw_val "
- " ,denom.fee_withdraw_frac "
- "FROM robr "
- "JOIN reserves_out ro "
- " ON (ro.h_blind_ev = robr.h_blind_ev) "
- "JOIN denominations denom "
- " ON (ro.denominations_serial = denom.denominations_serial); ",
- 1),
- /* Used in #postgres_select_withdrawals_above_serial_id() */
-
- GNUNET_PQ_make_prepare (
- "get_reserve_balance",
- "SELECT"
- " current_balance_val"
- ",current_balance_frac"
- " FROM reserves"
- " WHERE reserve_pub=$1;",
- 1),
- /* Fetch deposits with rowid '\geq' the given parameter */
-
- GNUNET_PQ_make_prepare (
- "audit_get_reserves_out_incr",
- "SELECT"
- " h_blind_ev"
- ",denom.denom_pub"
- ",reserve_sig"
- ",reserves.reserve_pub"
- ",execution_date"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",reserve_out_serial_id"
- " FROM reserves_out"
- " JOIN reserves"
- " USING (reserve_uuid)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE reserve_out_serial_id>=$1"
- " ORDER BY reserve_out_serial_id ASC;",
- 1),
-
- /* Used in #postgres_count_known_coins() */
- GNUNET_PQ_make_prepare (
- "count_known_coins",
- "SELECT"
- " COUNT(*) AS count"
- " FROM known_coins"
- " WHERE denominations_serial="
- " (SELECT denominations_serial"
- " FROM denominations"
- " WHERE denom_pub_hash=$1);",
- 1),
- /* Used in #postgres_get_known_coin() to fetch
- the denomination public key and signature for
- a coin known to the exchange. */
- GNUNET_PQ_make_prepare (
- "get_known_coin",
- "SELECT"
- " denominations.denom_pub_hash"
- ",age_commitment_hash"
- ",denom_sig"
- " FROM known_coins"
- " JOIN denominations USING (denominations_serial)"
- " WHERE coin_pub=$1;",
- 1),
- /* Used in #postgres_ensure_coin_known() */
- GNUNET_PQ_make_prepare (
- "get_known_coin_dh",
- "SELECT"
- " denominations.denom_pub_hash"
- " FROM known_coins"
- " JOIN denominations USING (denominations_serial)"
- " WHERE coin_pub=$1;",
- 1),
- /* Used in #postgres_get_coin_denomination() to fetch
- the denomination public key hash for
- a coin known to the exchange. */
- GNUNET_PQ_make_prepare (
- "get_coin_denomination",
- "SELECT"
- " denominations.denom_pub_hash"
- ",known_coin_id"
- " FROM known_coins"
- " JOIN denominations USING (denominations_serial)"
- " WHERE coin_pub=$1"
- " FOR SHARE;",
- 1),
- /* Used in #postgres_insert_known_coin() to store the denomination public
- key and signature for a coin known to the exchange.
-
- See also:
- https://stackoverflow.com/questions/34708509/how-to-use-returning-with-on-conflict-in-postgresql/37543015#37543015
- */
- GNUNET_PQ_make_prepare (
- "insert_known_coin",
- "WITH dd"
- " (denominations_serial"
- " ,coin_val"
- " ,coin_frac"
- " ) AS ("
- " SELECT "
- " denominations_serial"
- " ,coin_val"
- " ,coin_frac"
- " FROM denominations"
- " WHERE denom_pub_hash=$2"
- " ), input_rows"
- " (coin_pub) AS ("
- " VALUES ($1::BYTEA)"
- " ), ins AS ("
- " INSERT INTO known_coins "
- " (coin_pub"
- " ,denominations_serial"
- " ,age_commitment_hash"
- " ,denom_sig"
- " ,remaining_val"
- " ,remaining_frac"
- " ) SELECT "
- " $1"
- " ,denominations_serial"
- " ,$3"
- " ,$4"
- " ,coin_val"
- " ,coin_frac"
- " FROM dd"
- " ON CONFLICT DO NOTHING" /* CONFLICT on (coin_pub) */
- " RETURNING "
- " known_coin_id"
- " ) "
- "SELECT "
- " FALSE AS existed"
- " ,known_coin_id"
- " ,NULL AS denom_pub_hash"
- " ,NULL AS age_commitment_hash"
- " FROM ins "
- "UNION ALL "
- "SELECT "
- " TRUE AS existed"
- " ,known_coin_id"
- " ,denom_pub_hash"
- " ,kc.age_commitment_hash"
- " FROM input_rows"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations USING (denominations_serial)"
- " LIMIT 1",
- 4),
-
- /* Used in #postgres_get_melt() to fetch
- high-level information about a melt operation */
- GNUNET_PQ_make_prepare (
- "get_melt",
- /* "SELECT"
- " denoms.denom_pub_hash"
- ",denoms.fee_refresh_val"
- ",denoms.fee_refresh_frac"
- ",old_coin_pub"
- ",old_coin_sig"
- ",kc.age_commitment_hash"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",noreveal_index"
- ",melt_serial_id"
- " FROM refresh_commitments"
- " JOIN known_coins kc"
- " ON (old_coin_pub = kc.coin_pub)"
- " JOIN denominations denoms"
- " ON (kc.denominations_serial = denoms.denominations_serial)"
- " WHERE rc=$1;", */
- "WITH rc AS MATERIALIZED ( "
- " SELECT"
- " * FROM refresh_commitments"
- " WHERE rc=$1"
- ")"
- "SELECT"
- " denoms.denom_pub_hash"
- ",denoms.fee_refresh_val"
- ",denoms.fee_refresh_frac"
- ",rc.old_coin_pub"
- ",rc.old_coin_sig"
- ",kc.age_commitment_hash"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",noreveal_index"
- ",melt_serial_id "
- "FROM ("
- " SELECT"
- " * "
- " FROM known_coins"
- " WHERE coin_pub=(SELECT old_coin_pub from rc)"
- ") kc "
- "JOIN rc"
- " ON (kc.coin_pub=rc.old_coin_pub) "
- "JOIN denominations denoms"
- " USING (denominations_serial);",
- 1),
- /* Used in #postgres_select_refreshes_above_serial_id() to fetch
- refresh session with id '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_get_refresh_commitments_incr",
- "SELECT"
- " denom.denom_pub"
- ",kc.coin_pub AS old_coin_pub"
- ",kc.age_commitment_hash"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",noreveal_index"
- ",melt_serial_id"
- ",rc"
- " FROM refresh_commitments"
- " JOIN known_coins kc"
- " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
- " JOIN denominations denom"
- " ON (kc.denominations_serial = denom.denominations_serial)"
- " WHERE melt_serial_id>=$1"
- " ORDER BY melt_serial_id ASC;",
- 1),
- /* Query the 'refresh_commitments' by coin public key,
- used in #postgres_get_coin_transactions() */
- GNUNET_PQ_make_prepare (
- "get_refresh_session_by_coin",
- "SELECT"
- " rc"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",denoms.denom_pub_hash"
- ",denoms.fee_refresh_val"
- ",denoms.fee_refresh_frac"
- ",kc.age_commitment_hash"
- ",melt_serial_id"
- " FROM refresh_commitments"
- " JOIN known_coins kc"
- " ON (refresh_commitments.old_coin_pub = kc.coin_pub)"
- " JOIN denominations denoms"
- " USING (denominations_serial)"
- " WHERE old_coin_pub=$1;",
- 1),
- /* Find purse deposits by coin,
- used in #postgres_get_coin_transactions() */
- GNUNET_PQ_make_prepare (
- "get_purse_deposit_by_coin_pub",
- "SELECT"
- " partner_base_url"
- ",pd.amount_with_fee_val"
- ",pd.amount_with_fee_frac"
- ",denoms.fee_deposit_val"
- ",denoms.fee_deposit_frac"
- ",pd.purse_pub"
- ",kc.age_commitment_hash"
- ",pd.coin_sig"
- ",pd.purse_deposit_serial_id"
- ",pr.refunded"
- " FROM purse_deposits pd"
- " LEFT JOIN partners"
- " USING (partner_serial_id)"
- " JOIN purse_requests pr"
- " USING (purse_pub)"
- " JOIN known_coins kc"
- " ON (pd.coin_pub = kc.coin_pub)"
- " JOIN denominations denoms"
- " USING (denominations_serial)"
- // FIXME: use to-be-created materialized index
- // on coin_pub (query crosses partitions!)
- " WHERE pd.coin_pub=$1;",
- 1),
- /* Store information about the desired denominations for a
- refresh operation, used in #postgres_insert_refresh_reveal() */
- GNUNET_PQ_make_prepare (
- "insert_refresh_revealed_coin",
- "INSERT INTO refresh_revealed_coins "
- "(melt_serial_id "
- ",freshcoin_index "
- ",link_sig "
- ",denominations_serial "
- ",coin_ev"
- ",ewv"
- ",h_coin_ev"
- ",ev_sig"
- ") SELECT $1, $2, $3, "
- " denominations_serial, $5, $6, $7, $8"
- " FROM denominations"
- " WHERE denom_pub_hash=$4"
- " ON CONFLICT DO NOTHING;",
- 8),
- /* Obtain information about the coins created in a refresh
- operation, used in #postgres_get_refresh_reveal() */
- GNUNET_PQ_make_prepare (
- "get_refresh_revealed_coins",
- "SELECT "
- " rrc.freshcoin_index"
- ",denom.denom_pub_hash"
- ",rrc.h_coin_ev"
- ",rrc.link_sig"
- ",rrc.coin_ev"
- ",rrc.ewv"
- ",rrc.ev_sig"
- " FROM refresh_commitments"
- " JOIN refresh_revealed_coins rrc"
- " USING (melt_serial_id)"
- " JOIN denominations denom "
- " USING (denominations_serial)"
- " WHERE rc=$1;",
- 1),
-
- /* Used in #postgres_insert_refresh_reveal() to store the transfer
- keys we learned */
- GNUNET_PQ_make_prepare (
- "insert_refresh_transfer_keys",
- "INSERT INTO refresh_transfer_keys "
- "(melt_serial_id"
- ",transfer_pub"
- ",transfer_privs"
- ") VALUES ($1, $2, $3)"
- " ON CONFLICT DO NOTHING;",
- 3),
- /* Used in #postgres_insert_refund() to store refund information */
- GNUNET_PQ_make_prepare (
- "insert_refund",
- "INSERT INTO refunds "
- "(coin_pub "
- ",deposit_serial_id"
- ",merchant_sig "
- ",rtransaction_id "
- ",amount_with_fee_val "
- ",amount_with_fee_frac "
- ") SELECT $1, deposit_serial_id, $3, $5, $6, $7"
- " FROM deposits"
- " WHERE coin_pub=$1"
- " AND h_contract_terms=$4"
- " AND merchant_pub=$2",
- 7),
- /* Query the 'refunds' by coin public key */
- GNUNET_PQ_make_prepare (
- "get_refunds_by_coin",
- "SELECT"
- " dep.merchant_pub"
- ",ref.merchant_sig"
- ",dep.h_contract_terms"
- ",ref.rtransaction_id"
- ",ref.amount_with_fee_val"
- ",ref.amount_with_fee_frac"
- ",denom.fee_refund_val "
- ",denom.fee_refund_frac "
- ",ref.refund_serial_id"
- " FROM refunds ref"
- " JOIN deposits dep"
- " ON (ref.coin_pub = dep.coin_pub AND ref.deposit_serial_id = dep.deposit_serial_id)"
- " JOIN known_coins kc"
- " ON (ref.coin_pub = kc.coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " WHERE ref.coin_pub=$1;",
- 1),
- /* Query the 'refunds' by coin public key, merchant_pub and contract hash */
- GNUNET_PQ_make_prepare (
- "get_refunds_by_coin_and_contract",
- "SELECT"
- " ref.amount_with_fee_val"
- ",ref.amount_with_fee_frac"
- " FROM refunds ref"
- " JOIN deposits dep"
- " USING (coin_pub,deposit_serial_id)"
- " WHERE ref.coin_pub=$1"
- " AND dep.merchant_pub=$2"
- " AND dep.h_contract_terms=$3;",
- 3),
- /* Fetch refunds with rowid '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_get_refunds_incr",
- "SELECT"
- " dep.merchant_pub"
- ",ref.merchant_sig"
- ",dep.h_contract_terms"
- ",ref.rtransaction_id"
- ",denom.denom_pub"
- ",kc.coin_pub"
- ",ref.amount_with_fee_val"
- ",ref.amount_with_fee_frac"
- ",ref.refund_serial_id"
- " FROM refunds ref"
- " JOIN deposits dep"
- " ON (ref.coin_pub=dep.coin_pub AND ref.deposit_serial_id=dep.deposit_serial_id)"
- " JOIN known_coins kc"
- " ON (dep.coin_pub=kc.coin_pub)"
- " JOIN denominations denom"
- " ON (kc.denominations_serial=denom.denominations_serial)"
- " WHERE ref.refund_serial_id>=$1"
- " ORDER BY ref.refund_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "test_refund_full",
- "SELECT"
- " CAST(SUM(CAST(ref.amount_with_fee_frac AS INT8)) AS INT8) AS s_f"
- ",CAST(SUM(ref.amount_with_fee_val) AS INT8) AS s_v"
- ",dep.amount_with_fee_val"
- ",dep.amount_with_fee_frac"
- " FROM refunds ref"
- " JOIN deposits dep"
- " ON (ref.coin_pub=dep.coin_pub AND ref.deposit_serial_id=dep.deposit_serial_id)"
- " WHERE ref.refund_serial_id=$1"
- " GROUP BY (dep.amount_with_fee_val, dep.amount_with_fee_frac);",
- 1),
-
- /* Store information about a /deposit the exchange is to execute.
- Used in #postgres_insert_deposit(). Only used in test cases. */
- GNUNET_PQ_make_prepare (
- "insert_deposit",
- "INSERT INTO deposits "
- "(known_coin_id"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wallet_timestamp"
- ",refund_deadline"
- ",wire_deadline"
- ",merchant_pub"
- ",h_contract_terms"
- ",wire_salt"
- ",wire_target_h_payto"
- ",coin_sig"
- ",exchange_timestamp"
- ",shard"
- ") SELECT known_coin_id, $1, $2, $3, $4, $5, $6, "
- " $7, $8, $9, $10, $11, $12, $13"
- " FROM known_coins"
- " WHERE coin_pub=$1"
- " ON CONFLICT DO NOTHING;",
- 13),
- /* Fetch an existing deposit request, used to ensure idempotency
- during /deposit processing. Used in #postgres_have_deposit(). */
- GNUNET_PQ_make_prepare (
- "get_deposit",
- "SELECT"
- " dep.amount_with_fee_val"
- ",dep.amount_with_fee_frac"
- ",denominations.fee_deposit_val"
- ",denominations.fee_deposit_frac"
- ",dep.wallet_timestamp"
- ",dep.exchange_timestamp"
- ",dep.refund_deadline"
- ",dep.wire_deadline"
- ",dep.h_contract_terms"
- ",dep.wire_salt"
- ",wt.payto_uri AS receiver_wire_account"
- " FROM deposits dep"
- " JOIN known_coins kc ON (kc.coin_pub = dep.coin_pub)"
- " JOIN denominations USING (denominations_serial)"
- " JOIN wire_targets wt USING (wire_target_h_payto)"
- " WHERE dep.coin_pub=$1"
- " AND dep.merchant_pub=$3"
- " AND dep.h_contract_terms=$2;",
- 3),
- /* Fetch deposits with rowid '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_get_deposits_incr",
- "SELECT"
- " amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wallet_timestamp"
- ",exchange_timestamp"
- ",merchant_pub"
- ",denom.denom_pub"
- ",kc.coin_pub"
- ",kc.age_commitment_hash"
- ",coin_sig"
- ",refund_deadline"
- ",wire_deadline"
- ",h_contract_terms"
- ",wire_salt"
- ",payto_uri AS receiver_wire_account"
- ",done"
- ",deposit_serial_id"
- " FROM deposits"
- " JOIN wire_targets USING (wire_target_h_payto)"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations denom USING (denominations_serial)"
- " WHERE ("
- " (deposit_serial_id>=$1)"
- " )"
- " ORDER BY deposit_serial_id ASC;",
- 1),
- /* Fetch purse deposits with rowid '\geq' the given parameter */
- GNUNET_PQ_make_prepare (
- "audit_get_purse_deposits_incr",
- "SELECT"
- " pd.amount_with_fee_val"
- ",pd.amount_with_fee_frac"
- ",pr.amount_with_fee_val AS total_val"
- ",pr.amount_with_fee_frac AS total_frac"
- ",pr.balance_val"
- ",pr.balance_frac"
- ",pr.flags"
- ",pd.purse_pub"
- ",pd.coin_sig"
- ",partner_base_url"
- ",denom.denom_pub"
- ",pm.reserve_pub"
- ",kc.coin_pub"
- ",kc.age_commitment_hash"
- ",pd.purse_deposit_serial_id"
- " FROM purse_deposits pd"
- " LEFT JOIN partners USING (partner_serial_id)"
- " LEFT JOIN purse_merges pm USING (purse_pub)"
- " JOIN purse_requests pr USING (purse_pub)"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations denom USING (denominations_serial)"
- " WHERE ("
- " (purse_deposit_serial_id>=$1)"
- " )"
- " ORDER BY purse_deposit_serial_id ASC;",
- 1),
-
- GNUNET_PQ_make_prepare (
- "audit_get_account_merge_incr",
- "SELECT"
- " am.account_merge_request_serial_id"
- ",am.reserve_pub"
- ",am.purse_pub"
- ",pr.h_contract_terms"
- ",pr.purse_expiration"
- ",pr.amount_with_fee_val"
- ",pr.amount_with_fee_frac"
- ",pr.age_limit"
- ",pr.flags"
- ",pr.purse_fee_val"
- ",pr.purse_fee_frac"
- ",pm.merge_timestamp"
- ",am.reserve_sig"
- " FROM account_merges am"
- " JOIN purse_requests pr USING (purse_pub)"
- " JOIN purse_merges pm USING (purse_pub)"
- " WHERE ("
- " (account_merge_request_serial_id>=$1)"
- " )"
- " ORDER BY account_merge_request_serial_id ASC;",
- 1),
-
- GNUNET_PQ_make_prepare (
- "audit_get_purse_merge_incr",
- "SELECT"
- " pm.purse_merge_request_serial_id"
- ",partner_base_url"
- ",pr.amount_with_fee_val"
- ",pr.amount_with_fee_frac"
- ",pr.balance_val"
- ",pr.balance_frac"
- ",pr.flags"
- ",pr.merge_pub"
- ",pm.reserve_pub"
- ",pm.merge_sig"
- ",pm.purse_pub"
- ",pm.merge_timestamp"
- " FROM purse_merges pm"
- " JOIN purse_requests pr USING (purse_pub)"
- " LEFT JOIN partners USING (partner_serial_id)"
- " WHERE ("
- " (purse_merge_request_serial_id>=$1)"
- " )"
- " ORDER BY purse_merge_request_serial_id ASC;",
- 1),
-
- GNUNET_PQ_make_prepare (
- "audit_get_history_requests_incr",
- "SELECT"
- " history_request_serial_id"
- ",history_fee_val"
- ",history_fee_frac"
- ",request_timestamp"
- ",reserve_pub"
- ",reserve_sig"
- " FROM history_requests"
- " WHERE ("
- " (history_request_serial_id>=$1)"
- " )"
- " ORDER BY history_request_serial_id ASC;",
- 1),
-
-
- GNUNET_PQ_make_prepare (
- "audit_get_purse_deposits_by_purse",
- "SELECT"
- " pd.purse_deposit_serial_id"
- ",pd.amount_with_fee_val"
- ",pd.amount_with_fee_frac"
- ",pd.coin_pub"
- ",denom.denom_pub"
- " FROM purse_deposits pd"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations denom USING (denominations_serial)"
- " WHERE purse_pub=$1;",
- 1),
- GNUNET_PQ_make_prepare (
- "audit_get_purse_refunds_incr",
- "SELECT"
- " purse_pub"
- ",purse_refunds_serial_id"
- " FROM purse_refunds"
- " WHERE ("
- " (purse_refunds_serial_id>=$1)"
- " )"
- " ORDER BY purse_refunds_serial_id ASC;",
- 1),
- /* Fetch an existing deposit request.
- Used in #postgres_lookup_transfer_by_deposit(). */
- GNUNET_PQ_make_prepare (
- "get_deposit_without_wtid",
- "SELECT"
- " wt.kyc_ok"
- ",wt.wire_target_serial_id AS payment_target_uuid"
- ",dep.wire_salt"
- ",wt.payto_uri"
- ",dep.amount_with_fee_val"
- ",dep.amount_with_fee_frac"
- ",denom.fee_deposit_val"
- ",denom.fee_deposit_frac"
- ",dep.wire_deadline"
- " FROM deposits dep"
- " JOIN wire_targets wt USING (wire_target_h_payto)"
- " JOIN known_coins kc ON (kc.coin_pub = dep.coin_pub)"
- " JOIN denominations denom USING (denominations_serial)"
- " WHERE dep.coin_pub=$1"
- " AND dep.merchant_pub=$3"
- " AND dep.h_contract_terms=$2;",
- 3),
- /* Used in #postgres_get_ready_deposit() */
- GNUNET_PQ_make_prepare (
- "deposits_get_ready",
- "SELECT"
- " payto_uri"
- ",merchant_pub"
- " FROM deposits_by_ready dbr"
- " JOIN deposits dep"
- " ON (dbr.coin_pub = dep.coin_pub AND dbr.deposit_serial_id = dep.deposit_serial_id)"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " WHERE dbr.wire_deadline<=$1"
- " AND dbr.shard >= $2"
- " AND dbr.shard <= $3"
- " AND (wt.kyc_ok OR $4)"
- " ORDER BY "
- " dbr.wire_deadline ASC"
- " ,dbr.shard ASC"
- " LIMIT 1;",
- 4),
- /* Used in #postgres_aggregate() */
- GNUNET_PQ_make_prepare (
- "aggregate",
- "WITH rdy AS (" /* find deposits ready by merchant */
- " SELECT"
- " coin_pub"
- " FROM deposits_for_matching"
- " WHERE refund_deadline<$1" /* filter by shard, only actually executable deposits */
- " AND merchant_pub=$2" /* filter by target merchant */
- " ORDER BY refund_deadline ASC" /* ordering is not critical */
- " LIMIT "
- TALER_QUOTE (TALER_EXCHANGEDB_MATCHING_DEPOSITS_LIMIT) /* limits transaction size */
- " )"
- " ,dep AS (" /* restrict to our merchant and account and mark as done */
- " UPDATE deposits"
- " SET done=TRUE"
- " WHERE coin_pub IN (SELECT coin_pub FROM rdy)"
- " AND merchant_pub=$2" /* theoretically, same coin could be spent at another merchant */
- " AND wire_target_h_payto=$3" /* merchant could have a 2nd bank account */
- " AND done=FALSE" /* theoretically, same coin could be spend at the same merchant a 2nd time */
- " RETURNING"
- " deposit_serial_id"
- " ,coin_pub"
- " ,amount_with_fee_val AS amount_val"
- " ,amount_with_fee_frac AS amount_frac)"
- " ,ref AS (" /* find applicable refunds -- NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
- " SELECT"
- " amount_with_fee_val AS refund_val"
- " ,amount_with_fee_frac AS refund_frac"
- " ,coin_pub"
- " ,deposit_serial_id" /* theoretically, coin could be in multiple refunded transactions */
- " FROM refunds"
- " WHERE coin_pub IN (SELECT coin_pub FROM dep)"
- " AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep))"
- " ,coins_with_fees AS (" /* find coins for which deposit fees apply */
- " SELECT"
- " coin_pub"
- " ,deposit_serial_id" /* ensures that if the same coin is deposited twice, it is in the list twice */
- " FROM dep"
- " WHERE deposit_serial_id NOT IN (SELECT deposit_serial_id FROM ref))"
- " ,fees AS (" /* find deposit fees for non-refunded deposits */
- " SELECT"
- " denom.fee_deposit_val AS fee_val"
- " ,denom.fee_deposit_frac AS fee_frac"
- " ,cs.deposit_serial_id" /* ensures we get the fee for each coin, not once per denomination */
- " FROM coins_with_fees cs"
- " JOIN known_coins kc" /* NOTE: may do a full join on the master, maybe find a left-join way to integrate with query above to push it to the shards? */
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial))"
- " ,dummy AS (" /* add deposits to aggregation_tracking */
- " INSERT INTO aggregation_tracking"
- " (deposit_serial_id"
- " ,wtid_raw)"
- " SELECT deposit_serial_id,$4"
- " FROM dep)"
- "SELECT" /* calculate totals (deposits, refunds and fees) */
- " CAST(COALESCE(SUM(dep.amount_val),0) AS INT8) AS sum_deposit_value" /* cast needed, otherwise we get NUMBER */
- " ,COALESCE(SUM(dep.amount_frac),0) AS sum_deposit_fraction" /* SUM over INT returns INT8 */
- " ,CAST(COALESCE(SUM(ref.refund_val),0) AS INT8) AS sum_refund_value"
- " ,COALESCE(SUM(ref.refund_frac),0) AS sum_refund_fraction"
- " ,CAST(COALESCE(SUM(fees.fee_val),0) AS INT8) AS sum_fee_value"
- " ,COALESCE(SUM(fees.fee_frac),0) AS sum_fee_fraction"
- " FROM dep "
- " FULL OUTER JOIN ref ON (FALSE)" /* We just want all sums */
- " FULL OUTER JOIN fees ON (FALSE);",
- 4),
-
-
- /* Used in #postgres_create_aggregation_transient() */
- GNUNET_PQ_make_prepare (
- "create_aggregation_transient",
- "INSERT INTO aggregation_transient"
- " (amount_val"
- " ,amount_frac"
- " ,wire_target_h_payto"
- " ,exchange_account_section"
- " ,wtid_raw)"
- " VALUES ($1, $2, $3, $4, $5);",
- 5),
- /* Used in #postgres_select_aggregation_transient() */
- GNUNET_PQ_make_prepare (
- "select_aggregation_transient",
- "SELECT"
- " amount_val"
- " ,amount_frac"
- " ,wtid_raw"
- " FROM aggregation_transient"
- " WHERE wire_target_h_payto=$1"
- " AND exchange_account_section=$2;",
- 2),
- /* Used in #postgres_update_aggregation_transient() */
- GNUNET_PQ_make_prepare (
- "update_aggregation_transient",
- "UPDATE aggregation_transient"
- " SET amount_val=$1"
- " ,amount_frac=$2"
- " WHERE wire_target_h_payto=$3"
- " AND wtid_raw=$4",
- 4),
- /* Used in #postgres_delete_aggregation_transient() */
- GNUNET_PQ_make_prepare (
- "delete_aggregation_transient",
- "DELETE FROM aggregation_transient"
- " WHERE wire_target_h_payto=$1"
- " AND wtid_raw=$2",
- 2),
-
- /* Used in #postgres_get_coin_transactions() to obtain information
- about how a coin has been spend with /deposit requests. */
- GNUNET_PQ_make_prepare (
- "get_deposit_with_coin_pub",
- "SELECT"
- " dep.amount_with_fee_val"
- ",dep.amount_with_fee_frac"
- ",denoms.fee_deposit_val"
- ",denoms.fee_deposit_frac"
- ",denoms.denom_pub_hash"
- ",kc.age_commitment_hash"
- ",dep.wallet_timestamp"
- ",dep.refund_deadline"
- ",dep.wire_deadline"
- ",dep.merchant_pub"
- ",dep.h_contract_terms"
- ",dep.wire_salt"
- ",wt.payto_uri"
- ",dep.coin_sig"
- ",dep.deposit_serial_id"
- ",dep.done"
- " FROM deposits dep"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " JOIN known_coins kc"
- " ON (kc.coin_pub = dep.coin_pub)"
- " JOIN denominations denoms"
- " USING (denominations_serial)"
- " WHERE dep.coin_pub=$1;",
- 1),
-
- /* Used in #postgres_get_link_data(). */
- GNUNET_PQ_make_prepare (
- "get_link",
- "SELECT "
- " tp.transfer_pub"
- ",denoms.denom_pub"
- ",rrc.ev_sig"
- ",rrc.ewv"
- ",rrc.link_sig"
- ",rrc.freshcoin_index"
- ",rrc.coin_ev"
- " FROM refresh_commitments"
- " JOIN refresh_revealed_coins rrc"
- " USING (melt_serial_id)"
- " JOIN refresh_transfer_keys tp"
- " USING (melt_serial_id)"
- " JOIN denominations denoms"
- " ON (rrc.denominations_serial = denoms.denominations_serial)"
- " WHERE old_coin_pub=$1"
- " ORDER BY tp.transfer_pub, rrc.freshcoin_index ASC",
- 1),
- /* Used in #postgres_lookup_wire_transfer */
- GNUNET_PQ_make_prepare (
- "lookup_transactions",
- "SELECT"
- " aggregation_serial_id"
- ",deposits.h_contract_terms"
- ",payto_uri"
- ",wire_targets.wire_target_h_payto"
- ",kc.coin_pub"
- ",deposits.merchant_pub"
- ",wire_out.execution_date"
- ",deposits.amount_with_fee_val"
- ",deposits.amount_with_fee_frac"
- ",denom.fee_deposit_val"
- ",denom.fee_deposit_frac"
- ",denom.denom_pub"
- " FROM aggregation_tracking"
- " JOIN deposits"
- " USING (deposit_serial_id)"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " JOIN known_coins kc"
- " USING (coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " JOIN wire_out"
- " USING (wtid_raw)"
- " WHERE wtid_raw=$1;",
- 1),
- /* Used in #postgres_lookup_transfer_by_deposit */
- GNUNET_PQ_make_prepare (
- "lookup_deposit_wtid",
- "SELECT"
- " aggregation_tracking.wtid_raw"
- ",wire_out.execution_date"
- ",dep.amount_with_fee_val"
- ",dep.amount_with_fee_frac"
- ",dep.wire_salt"
- ",wt.payto_uri"
- ",denom.fee_deposit_val"
- ",denom.fee_deposit_frac"
- " FROM deposits dep"
- " JOIN wire_targets wt"
- " USING (wire_target_h_payto)"
- " JOIN aggregation_tracking"
- " USING (deposit_serial_id)"
- " JOIN known_coins kc"
- " ON (kc.coin_pub = dep.coin_pub)"
- " JOIN denominations denom"
- " USING (denominations_serial)"
- " JOIN wire_out"
- " USING (wtid_raw)"
- " WHERE dep.coin_pub=$1"
- " AND dep.merchant_pub=$3"
- " AND dep.h_contract_terms=$2",
- 3),
- /* Used in #postgres_insert_aggregation_tracking */
- GNUNET_PQ_make_prepare (
- "insert_aggregation_tracking",
- "INSERT INTO aggregation_tracking "
- "(deposit_serial_id"
- ",wtid_raw"
- ") VALUES "
- "($1, $2);",
- 2),
- /* Used in #postgres_get_wire_fee() */
- GNUNET_PQ_make_prepare (
- "get_wire_fee",
- "SELECT "
- " start_date"
- ",end_date"
- ",wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",master_sig"
- " FROM wire_fee"
- " WHERE wire_method=$1"
- " AND start_date <= $2"
- " AND end_date > $2;",
- 2),
- /* Used in #postgres_get_global_fee() */
- GNUNET_PQ_make_prepare (
- "get_global_fee",
- "SELECT "
- " start_date"
- ",end_date"
- ",history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- " FROM global_fee"
- " WHERE start_date <= $1"
- " AND end_date > $1;",
- 1),
- /* Used in #postgres_get_global_fees() */
- GNUNET_PQ_make_prepare (
- "get_global_fees",
- "SELECT "
- " start_date"
- ",end_date"
- ",history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- " FROM global_fee"
- " WHERE start_date >= $1",
- 1),
- /* Used in #postgres_insert_wire_fee */
- GNUNET_PQ_make_prepare (
- "insert_wire_fee",
- "INSERT INTO wire_fee "
- "(wire_method"
- ",start_date"
- ",end_date"
- ",wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);",
- 10),
- /* Used in #postgres_insert_global_fee */
- GNUNET_PQ_make_prepare (
- "insert_global_fee",
- "INSERT INTO global_fee "
- "(start_date"
- ",end_date"
- ",history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);",
- 15),
- /* Used in #postgres_store_wire_transfer_out */
- GNUNET_PQ_make_prepare (
- "insert_wire_out",
- "INSERT INTO wire_out "
- "(execution_date"
- ",wtid_raw"
- ",wire_target_h_payto"
- ",exchange_account_section"
- ",amount_val"
- ",amount_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wire_out",
- "INSERT INTO wire_out"
- "(wireout_uuid"
- ",execution_date"
- ",wtid_raw"
- ",wire_target_h_payto"
- ",exchange_account_section"
- ",amount_val"
- ",amount_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7);",
- 7),
- /* Used in #postgres_wire_prepare_data_insert() to store
- wire transfer information before actually committing it with the bank */
- GNUNET_PQ_make_prepare (
- "wire_prepare_data_insert",
- "INSERT INTO prewire "
- "(wire_method"
- ",buf"
- ") VALUES "
- "($1, $2);",
- 2),
- /* Used in #postgres_wire_prepare_data_mark_finished() */
- GNUNET_PQ_make_prepare (
- "wire_prepare_data_mark_done",
- "UPDATE prewire"
- " SET finished=TRUE"
- " WHERE prewire_uuid=$1;",
- 1),
- /* Used in #postgres_wire_prepare_data_mark_failed() */
- GNUNET_PQ_make_prepare (
- "wire_prepare_data_mark_failed",
- "UPDATE prewire"
- " SET failed=TRUE"
- " WHERE prewire_uuid=$1;",
- 1),
- /* Used in #postgres_wire_prepare_data_get() */
- GNUNET_PQ_make_prepare (
- "wire_prepare_data_get",
- "SELECT"
- " prewire_uuid"
- ",wire_method"
- ",buf"
- " FROM prewire"
- " WHERE prewire_uuid >= $1"
- " AND finished=FALSE"
- " AND failed=FALSE"
- " ORDER BY prewire_uuid ASC"
- " LIMIT $2;",
- 2),
- /* Used in #postgres_select_deposits_missing_wire */
- // FIXME: used by the auditor; can probably be done
- // smarter by checking if 'done' or 'blocked'
- // are set correctly when going over deposits, instead
- // of JOINing with refunds.
- GNUNET_PQ_make_prepare (
- "deposits_get_overdue",
- "SELECT"
- " deposit_serial_id"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",payto_uri"
- ",wire_deadline"
- ",done"
- " FROM deposits d"
- " JOIN known_coins"
- " USING (coin_pub)"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " WHERE wire_deadline >= $1"
- " AND wire_deadline < $2"
- " AND NOT (EXISTS (SELECT 1"
- " FROM refunds r"
- " WHERE (r.coin_pub = d.coin_pub) AND (r.deposit_serial_id = d.deposit_serial_id))"
- " OR EXISTS (SELECT 1"
- " FROM aggregation_tracking"
- " WHERE (aggregation_tracking.deposit_serial_id = d.deposit_serial_id)))"
- " ORDER BY wire_deadline ASC",
- 2),
- /* Used in #postgres_select_wire_out_above_serial_id() */
- GNUNET_PQ_make_prepare (
- "audit_get_wire_incr",
- "SELECT"
- " wireout_uuid"
- ",execution_date"
- ",wtid_raw"
- ",payto_uri"
- ",amount_val"
- ",amount_frac"
- " FROM wire_out"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " WHERE wireout_uuid>=$1"
- " ORDER BY wireout_uuid ASC;",
- 1),
- /* Used in #postgres_select_wire_out_above_serial_id_by_account() */
- GNUNET_PQ_make_prepare (
- "audit_get_wire_incr_by_account",
- "SELECT"
- " wireout_uuid"
- ",execution_date"
- ",wtid_raw"
- ",payto_uri"
- ",amount_val"
- ",amount_frac"
- " FROM wire_out"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " WHERE "
- " wireout_uuid>=$1 "
- " AND exchange_account_section=$2"
- " ORDER BY wireout_uuid ASC;",
- 2),
- /* Used in #postgres_select_recoup_above_serial_id() to obtain recoup transactions */
- GNUNET_PQ_make_prepare (
- "recoup_get_incr",
- "SELECT"
- " recoup_uuid"
- ",recoup_timestamp"
- ",reserves.reserve_pub"
- ",coins.coin_pub"
- ",coin_sig"
- ",coin_blind"
- ",ro.h_blind_ev"
- ",denoms.denom_pub_hash"
- ",coins.denom_sig"
- ",coins.age_commitment_hash"
- ",denoms.denom_pub"
- ",amount_val"
- ",amount_frac"
- " FROM recoup"
- " JOIN known_coins coins"
- " USING (coin_pub)"
- " JOIN reserves_out ro"
- " USING (reserve_out_serial_id)"
- " JOIN reserves"
- " USING (reserve_uuid)"
- " JOIN denominations denoms"
- " ON (coins.denominations_serial = denoms.denominations_serial)"
- " WHERE recoup_uuid>=$1"
- " ORDER BY recoup_uuid ASC;",
- 1),
- /* Used in #postgres_select_recoup_refresh_above_serial_id() to obtain
- recoup-refresh transactions */
- GNUNET_PQ_make_prepare (
- "recoup_refresh_get_incr",
- "SELECT"
- " recoup_refresh_uuid"
- ",recoup_timestamp"
- ",old_coins.coin_pub AS old_coin_pub"
- ",new_coins.age_commitment_hash"
- ",old_denoms.denom_pub_hash AS old_denom_pub_hash"
- ",new_coins.coin_pub As coin_pub"
- ",coin_sig"
- ",coin_blind"
- ",new_denoms.denom_pub AS denom_pub"
- ",rrc.h_coin_ev AS h_blind_ev"
- ",new_denoms.denom_pub_hash"
- ",new_coins.denom_sig AS denom_sig"
- ",amount_val"
- ",amount_frac"
- " FROM recoup_refresh"
- " INNER JOIN refresh_revealed_coins rrc"
- " USING (rrc_serial)"
- " INNER JOIN refresh_commitments rfc"
- " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
- " INNER JOIN known_coins old_coins"
- " ON (rfc.old_coin_pub = old_coins.coin_pub)"
- " INNER JOIN known_coins new_coins"
- " ON (new_coins.coin_pub = recoup_refresh.coin_pub)"
- " INNER JOIN denominations new_denoms"
- " ON (new_coins.denominations_serial = new_denoms.denominations_serial)"
- " INNER JOIN denominations old_denoms"
- " ON (old_coins.denominations_serial = old_denoms.denominations_serial)"
- " WHERE recoup_refresh_uuid>=$1"
- " ORDER BY recoup_refresh_uuid ASC;",
- 1),
- /* Used in #postgres_select_reserve_closed_above_serial_id() to
- obtain information about closed reserves */
- GNUNET_PQ_make_prepare (
- "reserves_close_get_incr",
- "SELECT"
- " close_uuid"
- ",reserves.reserve_pub"
- ",execution_date"
- ",wtid"
- ",payto_uri AS receiver_account"
- ",amount_val"
- ",amount_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- " FROM reserves_close"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " JOIN reserves"
- " USING (reserve_pub)"
- " WHERE close_uuid>=$1"
- " ORDER BY close_uuid ASC;",
- 1),
- /* Used in #postgres_get_reserve_history() to obtain recoup transactions
- for a reserve - query optimization should be disabled i.e.
- BEGIN; SET LOCAL join_collapse_limit=1; query; COMMIT; */
- GNUNET_PQ_make_prepare (
- "recoup_by_reserve",
- /*
- "SELECT"
- " recoup.coin_pub"
- ",recoup.coin_sig"
- ",recoup.coin_blind"
- ",recoup.amount_val"
- ",recoup.amount_frac"
- ",recoup.recoup_timestamp"
- ",denominations.denom_pub_hash"
- ",known_coins.denom_sig"
- " FROM denominations"
- " JOIN (known_coins"
- " JOIN recoup "
- " ON (recoup.coin_pub = known_coins.coin_pub))"
- " ON (known_coins.denominations_serial = denominations.denominations_serial)"
- " WHERE recoup.coin_pub"
- " IN (SELECT coin_pub"
- " FROM recoup_by_reserve"
- " JOIN (reserves_out"
- " JOIN (reserves_out_by_reserve"
- " JOIN reserves"
- " ON (reserves.reserve_uuid = reserves_out_by_reserve.reserve_uuid))"
- " ON (reserves_out_by_reserve.h_blind_ev = reserves_out.h_blind_ev))"
- " ON (recoup_by_reserve.reserve_out_serial_id = reserves_out.reserve_out_serial_id)"
- " WHERE reserves.reserve_pub=$1);",
- */
- "SELECT robr.coin_pub "
- " ,robr.coin_sig "
- " ,robr.coin_blind "
- " ,robr.amount_val "
- " ,robr.amount_frac "
- " ,robr.recoup_timestamp "
- " ,denominations.denom_pub_hash "
- " ,robr.denom_sig "
- "FROM denominations "
- " JOIN exchange_do_recoup_by_reserve($1) robr"
- " USING (denominations_serial);",
- 1),
- /* Used in #postgres_get_coin_transactions() to obtain recoup transactions
- affecting old coins of refreshed coins */
- GNUNET_PQ_make_prepare (
- "recoup_by_old_coin",
- "SELECT"
- " coins.coin_pub"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",denoms.denom_pub_hash"
- ",coins.denom_sig"
- ",recoup_refresh_uuid"
- " FROM recoup_refresh"
- " JOIN known_coins coins"
- " USING (coin_pub)"
- " JOIN denominations denoms"
- " USING (denominations_serial)"
- " WHERE rrc_serial IN"
- " (SELECT rrc.rrc_serial"
- " FROM refresh_commitments"
- " JOIN refresh_revealed_coins rrc"
- " USING (melt_serial_id)"
- " WHERE old_coin_pub=$1);",
- 1),
- /* Used in #postgres_get_reserve_history() */
- GNUNET_PQ_make_prepare (
- "close_by_reserve",
- "SELECT"
- " amount_val"
- ",amount_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",execution_date"
- ",payto_uri AS receiver_account"
- ",wtid"
- " FROM reserves_close"
- " JOIN wire_targets"
- " USING (wire_target_h_payto)"
- " WHERE reserve_pub=$1;",
- 1),
- /* Used in #postgres_get_reserve_history() */
- GNUNET_PQ_make_prepare (
- "merge_by_reserve",
- "SELECT"
- " pr.amount_with_fee_val"
- ",pr.amount_with_fee_frac"
- ",pr.balance_val"
- ",pr.balance_frac"
- ",pr.purse_fee_val"
- ",pr.purse_fee_frac"
- ",pr.h_contract_terms"
- ",pr.merge_pub"
- ",am.reserve_sig"
- ",pm.purse_pub"
- ",pm.merge_timestamp"
- ",pr.purse_expiration"
- ",pr.age_limit"
- ",pr.flags"
- " FROM purse_merges pm"
- " JOIN purse_requests pr"
- " USING (purse_pub)"
- " JOIN account_merges am"
- " ON (am.purse_pub = pm.purse_pub AND"
- " am.reserve_pub = pm.reserve_pub)"
- " WHERE pm.reserve_pub=$1"
- " AND pm.partner_serial_id=0" /* must be local! */
- " AND pr.finished"
- " AND NOT pr.refunded;",
- 1),
- /* Used in #postgres_get_reserve_history() */
- GNUNET_PQ_make_prepare (
- "history_by_reserve",
- "SELECT"
- " history_fee_val"
- ",history_fee_frac"
- ",request_timestamp"
- ",reserve_sig"
- " FROM history_requests"
- " WHERE reserve_pub=$1;",
- 1),
- /* Used in #postgres_get_expired_reserves() */
- GNUNET_PQ_make_prepare (
- "get_expired_reserves",
- /*
- "SELECT"
- " expiration_date"
- ",payto_uri AS account_details"
- ",reserve_pub"
- ",current_balance_val"
- ",current_balance_frac"
- " FROM reserves"
- " JOIN reserves_in ri"
- " USING (reserve_pub)"
- " JOIN wire_targets wt"
- " ON (ri.wire_source_h_payto = wt.wire_target_h_payto)"
- " WHERE expiration_date<=$1"
- " AND (current_balance_val != 0 "
- " OR current_balance_frac != 0)"
- " ORDER BY expiration_date ASC"
- " LIMIT 1;",
- */
- "WITH ed AS MATERIALIZED ( "
- " SELECT * "
- " FROM reserves "
- " WHERE expiration_date <= $1 "
- " AND (current_balance_val != 0 OR current_balance_frac != 0) "
- " ORDER BY expiration_date ASC "
- " LIMIT 1 "
- ") "
- "SELECT "
- " ed.expiration_date "
- " ,payto_uri AS account_details "
- " ,ed.reserve_pub "
- " ,current_balance_val "
- " ,current_balance_frac "
- "FROM ( "
- " SELECT "
- " * "
- " FROM reserves_in "
- " WHERE reserve_pub = ( "
- " SELECT reserve_pub FROM ed) "
- " ) ri "
- "JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto) "
- "JOIN ed ON (ri.reserve_pub = ed.reserve_pub); ",
- 1),
- /* Used in #postgres_get_coin_transactions() to obtain recoup transactions
- for a coin */
- GNUNET_PQ_make_prepare (
- "recoup_by_coin",
- "SELECT"
- " reserves.reserve_pub"
- ",denoms.denom_pub_hash"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",recoup_uuid"
- " FROM recoup rcp"
- /* NOTE: suboptimal JOIN follows: crosses shards!
- Could theoretically be improved via a materialized
- index. But likely not worth it (query is rare and
- number of reserve shards might be limited) */
- " JOIN reserves_out ro"
- " USING (reserve_out_serial_id)"
- " JOIN reserves"
- " USING (reserve_uuid)"
- " JOIN known_coins coins"
- " USING (coin_pub)"
- " JOIN denominations denoms"
- " ON (denoms.denominations_serial = coins.denominations_serial)"
- " WHERE coins.coin_pub=$1;",
- 1),
- /* Used in #postgres_get_coin_transactions() to obtain recoup transactions
- for a refreshed coin */
- GNUNET_PQ_make_prepare (
- "recoup_by_refreshed_coin",
- "SELECT"
- " old_coins.coin_pub AS old_coin_pub"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",denoms.denom_pub_hash"
- ",coins.denom_sig"
- ",recoup_refresh_uuid"
- " FROM recoup_refresh"
- " JOIN refresh_revealed_coins rrc"
- " USING (rrc_serial)"
- " JOIN refresh_commitments rfc"
- " ON (rrc.melt_serial_id = rfc.melt_serial_id)"
- " JOIN known_coins old_coins"
- " ON (rfc.old_coin_pub = old_coins.coin_pub)"
- " JOIN known_coins coins"
- " ON (recoup_refresh.coin_pub = coins.coin_pub)"
- " JOIN denominations denoms"
- " ON (denoms.denominations_serial = coins.denominations_serial)"
- " WHERE coins.coin_pub=$1;",
- 1),
- /* Used in #postgres_get_reserve_by_h_blind() */
- GNUNET_PQ_make_prepare (
- "reserve_by_h_blind",
- "SELECT"
- " reserves.reserve_pub"
- ",reserve_out_serial_id"
- " FROM reserves_out"
- " JOIN reserves"
- " USING (reserve_uuid)"
- " WHERE h_blind_ev=$1"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_get_old_coin_by_h_blind() */
- GNUNET_PQ_make_prepare (
- "old_coin_by_h_blind",
- "SELECT"
- " okc.coin_pub AS old_coin_pub"
- ",rrc_serial"
- " FROM refresh_revealed_coins rrc"
- " JOIN refresh_commitments rcom USING (melt_serial_id)"
- " JOIN known_coins okc ON (rcom.old_coin_pub = okc.coin_pub)"
- " WHERE h_coin_ev=$1"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_lookup_auditor_timestamp() */
- GNUNET_PQ_make_prepare (
- "lookup_auditor_timestamp",
- "SELECT"
- " last_change"
- " FROM auditors"
- " WHERE auditor_pub=$1;",
- 1),
- /* Used in #postgres_lookup_auditor_status() */
- GNUNET_PQ_make_prepare (
- "lookup_auditor_status",
- "SELECT"
- " auditor_url"
- ",is_active"
- " FROM auditors"
- " WHERE auditor_pub=$1;",
- 1),
- /* Used in #postgres_lookup_wire_timestamp() */
- GNUNET_PQ_make_prepare (
- "lookup_wire_timestamp",
- "SELECT"
- " last_change"
- " FROM wire_accounts"
- " WHERE payto_uri=$1;",
- 1),
- /* used in #postgres_insert_auditor() */
- GNUNET_PQ_make_prepare (
- "insert_auditor",
- "INSERT INTO auditors "
- "(auditor_pub"
- ",auditor_name"
- ",auditor_url"
- ",is_active"
- ",last_change"
- ") VALUES "
- "($1, $2, $3, true, $4);",
- 4),
- /* used in #postgres_update_auditor() */
- GNUNET_PQ_make_prepare (
- "update_auditor",
- "UPDATE auditors"
- " SET"
- " auditor_url=$2"
- " ,auditor_name=$3"
- " ,is_active=$4"
- " ,last_change=$5"
- " WHERE auditor_pub=$1",
- 5),
- /* used in #postgres_insert_wire() */
- GNUNET_PQ_make_prepare (
- "insert_wire",
- "INSERT INTO wire_accounts "
- "(payto_uri"
- ",master_sig"
- ",is_active"
- ",last_change"
- ") VALUES "
- "($1, $2, true, $3);",
- 3),
- /* used in #postgres_update_wire() */
- GNUNET_PQ_make_prepare (
- "update_wire",
- "UPDATE wire_accounts"
- " SET"
- " is_active=$2"
- " ,last_change=$3"
- " WHERE payto_uri=$1",
- 3),
- /* used in #postgres_update_wire() */
- GNUNET_PQ_make_prepare (
- "get_wire_accounts",
- "SELECT"
- " payto_uri"
- ",master_sig"
- " FROM wire_accounts"
- " WHERE is_active",
- 0),
- /* used in #postgres_update_wire() */
- GNUNET_PQ_make_prepare (
- "get_wire_fees",
- "SELECT"
- " wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",start_date"
- ",end_date"
- ",master_sig"
- " FROM wire_fee"
- " WHERE wire_method=$1",
- 1),
- /* used in #postgres_insert_signkey_revocation() */
- GNUNET_PQ_make_prepare (
- "insert_signkey_revocation",
- "INSERT INTO signkey_revocations "
- "(esk_serial"
- ",master_sig"
- ") SELECT esk_serial, $2 "
- " FROM exchange_sign_keys"
- " WHERE exchange_pub=$1;",
- 2),
- /* used in #postgres_insert_signkey_revocation() */
- GNUNET_PQ_make_prepare (
- "lookup_signkey_revocation",
- "SELECT "
- " master_sig"
- " FROM signkey_revocations"
- " WHERE esk_serial="
- " (SELECT esk_serial"
- " FROM exchange_sign_keys"
- " WHERE exchange_pub=$1);",
- 1),
- /* used in #postgres_insert_signkey() */
- GNUNET_PQ_make_prepare (
- "insert_signkey",
- "INSERT INTO exchange_sign_keys "
- "(exchange_pub"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
- /* used in #postgres_lookup_signing_key() */
- GNUNET_PQ_make_prepare (
- "lookup_signing_key",
- "SELECT"
- " valid_from"
- ",expire_sign"
- ",expire_legal"
- " FROM exchange_sign_keys"
- " WHERE exchange_pub=$1",
- 1),
- /* used in #postgres_lookup_denomination_key() */
- GNUNET_PQ_make_prepare (
- "lookup_denomination_key",
- "SELECT"
- " valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val"
- ",coin_frac"
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",age_mask"
- " FROM denominations"
- " WHERE denom_pub_hash=$1;",
- 1),
- /* used in #postgres_insert_auditor_denom_sig() */
- GNUNET_PQ_make_prepare (
- "insert_auditor_denom_sig",
- "WITH ax AS"
- " (SELECT auditor_uuid"
- " FROM auditors"
- " WHERE auditor_pub=$1)"
- "INSERT INTO auditor_denom_sigs "
- "(auditor_uuid"
- ",denominations_serial"
- ",auditor_sig"
- ") SELECT ax.auditor_uuid, denominations_serial, $3 "
- " FROM denominations"
- " CROSS JOIN ax"
- " WHERE denom_pub_hash=$2;",
- 3),
- /* used in #postgres_select_auditor_denom_sig() */
- GNUNET_PQ_make_prepare (
- "select_auditor_denom_sig",
- "SELECT"
- " auditor_sig"
- " FROM auditor_denom_sigs"
- " WHERE auditor_uuid="
- " (SELECT auditor_uuid"
- " FROM auditors"
- " WHERE auditor_pub=$1)"
- " AND denominations_serial="
- " (SELECT denominations_serial"
- " FROM denominations"
- " WHERE denom_pub_hash=$2);",
- 2),
- /* used in #postgres_lookup_wire_fee_by_time() */
- GNUNET_PQ_make_prepare (
- "lookup_wire_fee_by_time",
- "SELECT"
- " wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- " FROM wire_fee"
- " WHERE wire_method=$1"
- " AND end_date > $2"
- " AND start_date < $3;",
- 1),
- /* used in #postgres_lookup_wire_fee_by_time() */
- GNUNET_PQ_make_prepare (
- "lookup_global_fee_by_time",
- "SELECT"
- " history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- " FROM global_fee"
- " WHERE end_date > $1"
- " AND start_date < $2;",
- 1),
- /* used in #postgres_commit */
- GNUNET_PQ_make_prepare (
- "do_commit",
- "COMMIT",
- 0),
- /* used in #postgres_lookup_serial_by_table() */
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_denominations",
- "SELECT"
- " denominations_serial AS serial"
- " FROM denominations"
- " ORDER BY denominations_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_denomination_revocations",
- "SELECT"
- " denom_revocations_serial_id AS serial"
- " FROM denomination_revocations"
- " ORDER BY denom_revocations_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wire_targets",
- "SELECT"
- " wire_target_serial_id AS serial"
- " FROM wire_targets"
- " ORDER BY wire_target_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_reserves",
- "SELECT"
- " reserve_uuid AS serial"
- " FROM reserves"
- " ORDER BY reserve_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_reserves_in",
- "SELECT"
- " reserve_in_serial_id AS serial"
- " FROM reserves_in"
- " ORDER BY reserve_in_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_reserves_close",
- "SELECT"
- " close_uuid AS serial"
- " FROM reserves_close"
- " ORDER BY close_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_reserves_out",
- "SELECT"
- " reserve_out_serial_id AS serial"
- " FROM reserves_out"
- " ORDER BY reserve_out_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_auditors",
- "SELECT"
- " auditor_uuid AS serial"
- " FROM auditors"
- " ORDER BY auditor_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_auditor_denom_sigs",
- "SELECT"
- " auditor_denom_serial AS serial"
- " FROM auditor_denom_sigs"
- " ORDER BY auditor_denom_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_exchange_sign_keys",
- "SELECT"
- " esk_serial AS serial"
- " FROM exchange_sign_keys"
- " ORDER BY esk_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_signkey_revocations",
- "SELECT"
- " signkey_revocations_serial_id AS serial"
- " FROM signkey_revocations"
- " ORDER BY signkey_revocations_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_known_coins",
- "SELECT"
- " known_coin_id AS serial"
- " FROM known_coins"
- " ORDER BY known_coin_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_refresh_commitments",
- "SELECT"
- " melt_serial_id AS serial"
- " FROM refresh_commitments"
- " ORDER BY melt_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_refresh_revealed_coins",
- "SELECT"
- " rrc_serial AS serial"
- " FROM refresh_revealed_coins"
- " ORDER BY rrc_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_refresh_transfer_keys",
- "SELECT"
- " rtc_serial AS serial"
- " FROM refresh_transfer_keys"
- " ORDER BY rtc_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_deposits",
- "SELECT"
- " deposit_serial_id AS serial"
- " FROM deposits"
- " ORDER BY deposit_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_refunds",
- "SELECT"
- " refund_serial_id AS serial"
- " FROM refunds"
- " ORDER BY refund_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wire_out",
- "SELECT"
- " wireout_uuid AS serial"
- " FROM wire_out"
- " ORDER BY wireout_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_aggregation_tracking",
- "SELECT"
- " aggregation_serial_id AS serial"
- " FROM aggregation_tracking"
- " ORDER BY aggregation_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wire_fee",
- "SELECT"
- " wire_fee_serial AS serial"
- " FROM wire_fee"
- " ORDER BY wire_fee_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_global_fee",
- "SELECT"
- " global_fee_serial AS serial"
- " FROM global_fee"
- " ORDER BY global_fee_serial DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_recoup",
- "SELECT"
- " recoup_uuid AS serial"
- " FROM recoup"
- " ORDER BY recoup_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_recoup_refresh",
- "SELECT"
- " recoup_refresh_uuid AS serial"
- " FROM recoup_refresh"
- " ORDER BY recoup_refresh_uuid DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_extensions",
- "SELECT"
- " extension_id AS serial"
- " FROM extensions"
- " ORDER BY extension_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_extension_details",
- "SELECT"
- " extension_details_serial_id AS serial"
- " FROM extension_details"
- " ORDER BY extension_details_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_purse_requests",
- "SELECT"
- " purse_requests_serial_id AS serial"
- " FROM purse_requests"
- " ORDER BY purse_requests_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_purse_refunds",
- "SELECT"
- " purse_refunds_serial_id AS serial"
- " FROM purse_refunds"
- " ORDER BY purse_refunds_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_purse_merges",
- "SELECT"
- " purse_merge_request_serial_id AS serial"
- " FROM purse_merges"
- " ORDER BY purse_merge_request_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_purse_deposits",
- "SELECT"
- " purse_deposit_serial_id AS serial"
- " FROM purse_deposits"
- " ORDER BY purse_deposit_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_account_merges",
- "SELECT"
- " account_merge_request_serial_id AS serial"
- " FROM account_merges"
- " ORDER BY account_merge_request_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_history_requests",
- "SELECT"
- " history_request_serial_id AS serial"
- " FROM history_requests"
- " ORDER BY history_request_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_close_requests",
- "SELECT"
- " close_request_serial_id AS serial"
- " FROM close_requests"
- " ORDER BY close_request_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wads_out",
- "SELECT"
- " wad_out_serial_id AS serial"
- " FROM wads_out"
- " ORDER BY wad_out_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wads_out_entries",
- "SELECT"
- " wad_out_entry_serial_id AS serial"
- " FROM wad_out_entries"
- " ORDER BY wad_out_entry_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wads_in",
- "SELECT"
- " wad_in_serial_id AS serial"
- " FROM wads_in"
- " ORDER BY wad_in_serial_id DESC"
- " LIMIT 1;",
- 0),
- GNUNET_PQ_make_prepare (
- "select_serial_by_table_wads_in_entries",
- "SELECT"
- " wad_in_entry_serial_id AS serial"
- " FROM wad_in_entries"
- " ORDER BY wad_in_entry_serial_id DESC"
- " LIMIT 1;",
- 0),
- /* For postgres_lookup_records_by_table */
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_denominations",
- "SELECT"
- " denominations_serial AS serial"
- ",denom_type"
- ",denom_pub"
- ",master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val"
- ",coin_frac"
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ",age_mask"
- " FROM denominations"
- " WHERE denominations_serial > $1"
- " ORDER BY denominations_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_denomination_revocations",
- "SELECT"
- " denom_revocations_serial_id AS serial"
- ",master_sig"
- ",denominations_serial"
- " FROM denomination_revocations"
- " WHERE denom_revocations_serial_id > $1"
- " ORDER BY denom_revocations_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wire_targets",
- "SELECT"
- " wire_target_serial_id AS serial"
- ",payto_uri"
- ",kyc_ok"
- ",external_id"
- " FROM wire_targets"
- " WHERE wire_target_serial_id > $1"
- " ORDER BY wire_target_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_reserves",
- "SELECT"
- " reserve_uuid AS serial"
- ",reserve_pub"
- ",expiration_date"
- ",gc_date"
- " FROM reserves"
- " WHERE reserve_uuid > $1"
- " ORDER BY reserve_uuid ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_reserves_in",
- "SELECT"
- " reserve_in_serial_id AS serial"
- ",reserve_pub"
- ",wire_reference"
- ",credit_val"
- ",credit_frac"
- ",wire_source_h_payto"
- ",exchange_account_section"
- ",execution_date"
- " FROM reserves_in"
- " WHERE reserve_in_serial_id > $1"
- " ORDER BY reserve_in_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_reserves_close",
- "SELECT"
- " close_uuid AS serial"
- ",reserve_pub"
- ",execution_date"
- ",wtid"
- ",wire_target_h_payto"
- ",amount_val"
- ",amount_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- " FROM reserves_close"
- " WHERE close_uuid > $1"
- " ORDER BY close_uuid ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_reserves_out",
- "SELECT"
- " reserve_out_serial_id AS serial"
- ",h_blind_ev"
- ",denominations_serial"
- ",denom_sig"
- ",reserve_uuid"
- ",reserve_sig"
- ",execution_date"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- " FROM reserves_out"
- " JOIN reserves USING (reserve_uuid)"
- " WHERE reserve_out_serial_id > $1"
- " ORDER BY reserve_out_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_auditors",
- "SELECT"
- " auditor_uuid AS serial"
- ",auditor_pub"
- ",auditor_name"
- ",auditor_url"
- ",is_active"
- ",last_change"
- " FROM auditors"
- " WHERE auditor_uuid > $1"
- " ORDER BY auditor_uuid ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_auditor_denom_sigs",
- "SELECT"
- " auditor_denom_serial AS serial"
- ",auditor_uuid"
- ",denominations_serial"
- ",auditor_sig"
- " FROM auditor_denom_sigs"
- " WHERE auditor_denom_serial > $1"
- " ORDER BY auditor_denom_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_exchange_sign_keys",
- "SELECT"
- " esk_serial AS serial"
- ",exchange_pub"
- ",master_sig"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- " FROM exchange_sign_keys"
- " WHERE esk_serial > $1"
- " ORDER BY esk_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_signkey_revocations",
- "SELECT"
- " signkey_revocations_serial_id AS serial"
- ",esk_serial"
- ",master_sig"
- " FROM signkey_revocations"
- " WHERE signkey_revocations_serial_id > $1"
- " ORDER BY signkey_revocations_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_known_coins",
- "SELECT"
- " known_coin_id AS serial"
- ",coin_pub"
- ",denom_sig"
- ",denominations_serial"
- " FROM known_coins"
- " WHERE known_coin_id > $1"
- " ORDER BY known_coin_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_refresh_commitments",
- "SELECT"
- " melt_serial_id AS serial"
- ",rc"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",noreveal_index"
- ",old_coin_pub"
- " FROM refresh_commitments"
- " WHERE melt_serial_id > $1"
- " ORDER BY melt_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_refresh_revealed_coins",
- "SELECT"
- " rrc_serial AS serial"
- ",freshcoin_index"
- ",link_sig"
- ",coin_ev"
- ",ev_sig"
- ",ewv"
- ",denominations_serial"
- ",melt_serial_id"
- " FROM refresh_revealed_coins"
- " WHERE rrc_serial > $1"
- " ORDER BY rrc_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_refresh_transfer_keys",
- "SELECT"
- " rtc_serial AS serial"
- ",transfer_pub"
- ",transfer_privs"
- ",melt_serial_id"
- " FROM refresh_transfer_keys"
- " WHERE rtc_serial > $1"
- " ORDER BY rtc_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_deposits",
- "SELECT"
- " deposit_serial_id AS serial"
- ",shard"
- ",coin_pub"
- ",known_coin_id"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wallet_timestamp"
- ",exchange_timestamp"
- ",refund_deadline"
- ",wire_deadline"
- ",merchant_pub"
- ",h_contract_terms"
- ",coin_sig"
- ",wire_salt"
- ",wire_target_h_payto"
- ",done"
- ",extension_blocked"
- ",extension_details_serial_id"
- " FROM deposits"
- " WHERE deposit_serial_id > $1"
- " ORDER BY deposit_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_refunds",
- "SELECT"
- " refund_serial_id AS serial"
- ",coin_pub"
- ",merchant_sig"
- ",rtransaction_id"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",deposit_serial_id"
- " FROM refunds"
- " WHERE refund_serial_id > $1"
- " ORDER BY refund_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wire_out",
- "SELECT"
- " wireout_uuid AS serial"
- ",execution_date"
- ",wtid_raw"
- ",wire_target_h_payto"
- ",exchange_account_section"
- ",amount_val"
- ",amount_frac"
- " FROM wire_out"
- " WHERE wireout_uuid > $1"
- " ORDER BY wireout_uuid ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_aggregation_tracking",
- "SELECT"
- " aggregation_serial_id AS serial"
- ",deposit_serial_id"
- ",wtid_raw"
- " FROM aggregation_tracking"
- " WHERE aggregation_serial_id > $1"
- " ORDER BY aggregation_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wire_fee",
- "SELECT"
- " wire_fee_serial AS serial"
- ",wire_method"
- ",start_date"
- ",end_date"
- ",wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",master_sig"
- " FROM wire_fee"
- " WHERE wire_fee_serial > $1"
- " ORDER BY wire_fee_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_global_fee",
- "SELECT"
- " global_fee_serial AS serial"
- ",start_date"
- ",end_date"
- ",history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- " FROM global_fee"
- " WHERE global_fee_serial > $1"
- " ORDER BY global_fee_serial ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_recoup",
- "SELECT"
- " recoup_uuid AS serial"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",coin_pub"
- ",reserve_out_serial_id"
- " FROM recoup"
- " WHERE recoup_uuid > $1"
- " ORDER BY recoup_uuid ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_recoup_refresh",
- "SELECT"
- " recoup_refresh_uuid AS serial"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",coin_pub"
- ",known_coin_id"
- ",rrc_serial"
- " FROM recoup_refresh"
- " WHERE recoup_refresh_uuid > $1"
- " ORDER BY recoup_refresh_uuid ASC;",
- 1),
-
-
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_purse_requests",
- "SELECT"
- " purse_requests_serial_id"
- ",purse_pub"
- ",merge_pub"
- ",purse_creation"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",flags"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE purse_requests_serial_id > $1"
- " ORDER BY purse_requests_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_purse_refunds",
- "SELECT"
- " purse_refunds_serial_id"
- ",purse_pub"
- " FROM purse_refunds"
- " WHERE purse_refunds_serial_id > $1"
- " ORDER BY purse_refunds_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_purse_merges",
- "SELECT"
- " purse_merge_request_serial_id"
- ",partner_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",merge_sig"
- ",merge_timestamp"
- " FROM purse_merges"
- " WHERE purse_merge_request_serial_id > $1"
- " ORDER BY purse_merge_request_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_purse_deposits",
- "SELECT"
- " purse_deposit_serial_id"
- ",partner_serial_id"
- ",purse_pub"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",coin_sig"
- " FROM purse_deposits"
- " WHERE purse_deposit_serial_id > $1"
- " ORDER BY purse_deposit_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_account_merges",
- "SELECT"
- " account_merge_request_serial_id"
- ",reserve_pub"
- ",reserve_sig"
- ",purse_pub"
- " FROM account_merges"
- " WHERE account_merge_request_serial_id > $1"
- " ORDER BY account_merge_request_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_history_requests",
- "SELECT"
- " history_request_serial_id"
- ",reserve_pub"
- ",request_timestamp"
- ",reserve_sig"
- ",history_fee_val"
- ",history_fee_frac"
- " FROM history_requests"
- " WHERE history_request_serial_id > $1"
- " ORDER BY history_request_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_close_requests",
- "SELECT"
- " close_request_serial_id"
- ",reserve_pub"
- ",close_timestamp"
- ",reserve_sig"
- ",close_val"
- ",close_frac"
- " FROM close_requests"
- " WHERE close_request_serial_id > $1"
- " ORDER BY close_request_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wads_out",
- "SELECT"
- " wad_out_serial_id"
- ",wad_id"
- ",partner_serial_id"
- ",amount_val"
- ",amount_frac"
- ",execution_time"
- " FROM wads_out"
- " WHERE wad_out_serial_id > $1"
- " ORDER BY wad_out_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wads_out_entries",
- "SELECT"
- " wad_out_entry_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",deposit_fees_val"
- ",deposit_fees_frac"
- ",reserve_sig"
- ",purse_sig"
- " FROM wad_out_entries"
- " WHERE wad_out_entry_serial_id > $1"
- " ORDER BY wad_out_entry_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wads_in",
- "SELECT"
- " wad_in_serial_id"
- ",wad_id"
- ",origin_exchange_url"
- ",amount_val"
- ",amount_frac"
- ",arrival_time"
- " FROM wads_in"
- " WHERE wad_in_serial_id > $1"
- " ORDER BY wad_in_serial_id ASC;",
- 1),
- GNUNET_PQ_make_prepare (
- "select_above_serial_by_table_wads_in_entries",
- "SELECT"
- " wad_in_entry_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",deposit_fees_val"
- ",deposit_fees_frac"
- ",reserve_sig"
- ",purse_sig"
- " FROM wad_in_entries"
- " WHERE wad_in_entry_serial_id > $1"
- " ORDER BY wad_in_entry_serial_id ASC;",
- 1),
- /* For postgres_insert_records_by_table */
- GNUNET_PQ_make_prepare (
- "insert_into_table_denominations",
- "INSERT INTO denominations"
- "(denominations_serial"
- ",denom_pub_hash"
- ",denom_type"
- ",age_mask"
- ",denom_pub"
- ",master_sig"
- ",valid_from"
- ",expire_withdraw"
- ",expire_deposit"
- ",expire_legal"
- ",coin_val"
- ",coin_frac"
- ",fee_withdraw_val"
- ",fee_withdraw_frac"
- ",fee_deposit_val"
- ",fee_deposit_frac"
- ",fee_refresh_val"
- ",fee_refresh_frac"
- ",fee_refund_val"
- ",fee_refund_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
- " $11, $12, $13, $14, $15, $16, $17, $18, $19, $20);",
- 20),
- GNUNET_PQ_make_prepare (
- "insert_into_table_denomination_revocations",
- "INSERT INTO denomination_revocations"
- "(denom_revocations_serial_id"
- ",master_sig"
- ",denominations_serial"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wire_targets",
- "INSERT INTO wire_targets"
- "(wire_target_serial_id"
- ",wire_target_h_payto"
- ",payto_uri"
- ",kyc_ok"
- ",external_id"
- ") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
- GNUNET_PQ_make_prepare (
- "insert_into_table_reserves",
- "INSERT INTO reserves"
- "(reserve_uuid"
- ",reserve_pub"
- ",expiration_date"
- ",gc_date"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare (
- "insert_into_table_reserves_in",
- "INSERT INTO reserves_in"
- "(reserve_in_serial_id"
- ",wire_reference"
- ",credit_val"
- ",credit_frac"
- ",wire_source_h_payto"
- ",exchange_account_section"
- ",execution_date"
- ",reserve_pub"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
- GNUNET_PQ_make_prepare (
- "insert_into_table_reserves_close",
- "INSERT INTO reserves_close"
- "(close_uuid"
- ",execution_date"
- ",wtid"
- ",wire_target_h_payto"
- ",amount_val"
- ",amount_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",reserve_pub"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9);",
- 9),
- GNUNET_PQ_make_prepare (
- "insert_into_table_reserves_out",
- "INSERT INTO reserves_out"
- "(reserve_out_serial_id"
- ",h_blind_ev"
- ",denominations_serial"
- ",denom_sig"
- ",reserve_uuid"
- ",reserve_sig"
- ",execution_date"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9);",
- 9),
- GNUNET_PQ_make_prepare (
- "insert_into_table_auditors",
- "INSERT INTO auditors"
- "(auditor_uuid"
- ",auditor_pub"
- ",auditor_name"
- ",auditor_url"
- ",is_active"
- ",last_change"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_auditor_denom_sigs",
- "INSERT INTO auditor_denom_sigs"
- "(auditor_denom_serial"
- ",auditor_uuid"
- ",denominations_serial"
- ",auditor_sig"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare (
- "insert_into_table_exchange_sign_keys",
- "INSERT INTO exchange_sign_keys"
- "(esk_serial"
- ",exchange_pub"
- ",master_sig"
- ",valid_from"
- ",expire_sign"
- ",expire_legal"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_signkey_revocations",
- "INSERT INTO signkey_revocations"
- "(signkey_revocations_serial_id"
- ",esk_serial"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- GNUNET_PQ_make_prepare (
- "insert_into_table_known_coins",
- "INSERT INTO known_coins"
- "(known_coin_id"
- ",coin_pub"
- ",denom_sig"
- ",denominations_serial"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare (
- "insert_into_table_refresh_commitments",
- "INSERT INTO refresh_commitments"
- "(melt_serial_id"
- ",rc"
- ",old_coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",noreveal_index"
- ",old_coin_pub"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7);",
- 7),
- GNUNET_PQ_make_prepare (
- "insert_into_table_refresh_revealed_coins",
- "INSERT INTO refresh_revealed_coins"
- "(rrc_serial"
- ",freshcoin_index"
- ",link_sig"
- ",coin_ev"
- ",h_coin_ev"
- ",ev_sig"
- ",ewv"
- ",denominations_serial"
- ",melt_serial_id"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9);",
- 9),
- GNUNET_PQ_make_prepare (
- "insert_into_table_refresh_transfer_keys",
- "INSERT INTO refresh_transfer_keys"
- "(rtc_serial"
- ",transfer_pub"
- ",transfer_privs"
- ",melt_serial_id"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare (
- "insert_into_table_deposits",
- "INSERT INTO deposits"
- "(deposit_serial_id"
- ",shard"
- ",known_coin_id"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wallet_timestamp"
- ",exchange_timestamp"
- ",refund_deadline"
- ",wire_deadline"
- ",merchant_pub"
- ",h_contract_terms"
- ",coin_sig"
- ",wire_salt"
- ",wire_target_h_payto"
- ",extension_blocked"
- ",extension_details_serial_id"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10,"
- " $11, $12, $13, $14, $15, $16, $17);",
- 17),
- GNUNET_PQ_make_prepare (
- "insert_into_table_refunds",
- "INSERT INTO refunds"
- "(refund_serial_id"
- ",coin_pub"
- ",merchant_sig"
- ",rtransaction_id"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",deposit_serial_id"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7);",
- 7),
- GNUNET_PQ_make_prepare (
- "insert_into_table_aggregation_tracking",
- "INSERT INTO aggregation_tracking"
- "(aggregation_serial_id"
- ",deposit_serial_id"
- ",wtid_raw"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wire_fee",
- "INSERT INTO wire_fee"
- "(wire_fee_serial"
- ",wire_method"
- ",start_date"
- ",end_date"
- ",wire_fee_val"
- ",wire_fee_frac"
- ",closing_fee_val"
- ",closing_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11);",
- 11),
- GNUNET_PQ_make_prepare (
- "insert_into_table_global_fee",
- "INSERT INTO global_fee"
- "(global_fee_serial"
- ",start_date"
- ",end_date"
- ",history_fee_val"
- ",history_fee_frac"
- ",kyc_fee_val"
- ",kyc_fee_frac"
- ",account_fee_val"
- ",account_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_timeout"
- ",kyc_timeout"
- ",history_expiration"
- ",purse_account_limit"
- ",master_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16);",
- 16),
- GNUNET_PQ_make_prepare (
- "insert_into_table_recoup",
- "INSERT INTO recoup"
- "(recoup_uuid"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",coin_pub"
- ",reserve_out_serial_id"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8);",
- 8),
- GNUNET_PQ_make_prepare (
- "insert_into_table_recoup_refresh",
- "INSERT INTO recoup_refresh"
- "(recoup_refresh_uuid"
- ",coin_sig"
- ",coin_blind"
- ",amount_val"
- ",amount_frac"
- ",recoup_timestamp"
- ",known_coin_id"
- ",coin_pub"
- ",rrc_serial"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9);",
- 9),
- GNUNET_PQ_make_prepare (
- "insert_into_table_extensions",
- "INSERT INTO extensions"
- "(extension_id"
- ",name"
- ",config"
- ") VALUES "
- "($1, $2, $3);",
- 3),
- GNUNET_PQ_make_prepare (
- "insert_into_table_extension_details",
- "INSERT INTO extension_details"
- "(extension_details_serial_id"
- ",extension_options"
- ") VALUES "
- "($1, $2);",
- 2),
-
- GNUNET_PQ_make_prepare (
- "insert_into_table_purse_requests",
- "INSERT INTO purse_requests"
- "(purse_requests_serial_id"
- ",purse_pub"
- ",merge_pub"
- ",purse_creation"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",flags"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",purse_fee_val"
- ",purse_fee_frac"
- ",purse_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13);",
- 13),
- GNUNET_PQ_make_prepare (
- "insert_into_table_purse_refunds",
- "INSERT INTO purse_refunds"
- "(purse_refunds_serial_id"
- ",purse_pub"
- ") VALUES "
- "($1, $2);",
- 2),
- GNUNET_PQ_make_prepare (
- "insert_into_table_purse_merges",
- "INSERT INTO purse_merges"
- "(purse_merge_request_serial_id"
- ",partner_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",merge_sig"
- ",merge_timestamp"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_purse_deposits",
- "INSERT INTO purse_deposits"
- "(purse_deposit_serial_id"
- ",partner_serial_id"
- ",purse_pub"
- ",coin_pub"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",coin_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7);",
- 7),
- GNUNET_PQ_make_prepare (
- "insert_into_table_account_merges",
- "INSERT INTO account_merges"
- "(account_merge_request_serial_id"
- ",reserve_pub"
- ",reserve_sig"
- ",purse_pub"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- GNUNET_PQ_make_prepare (
- "insert_into_table_history_requests",
- "INSERT INTO history_requests"
- "(history_request_serial_id"
- ",reserve_pub"
- ",request_timestamp"
- ",reserve_sig"
- ",history_fee_val"
- ",history_fee_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_close_requests",
- "INSERT INTO close_requests"
- "(close_request_serial_id"
- ",reserve_pub"
- ",close_timestamp"
- ",reserve_sig"
- ",close_val"
- ",close_frac"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wads_out",
- "INSERT INTO wads_out"
- "(wad_out_serial_id"
- ",wad_id"
- ",partner_serial_id"
- ",amount_val"
- ",amount_frac"
- ",execution_time"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wad_out_entries",
- "INSERT INTO wad_out_entries"
- "(wad_out_entry_serial_id"
- ",wad_out_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",deposit_fees_val"
- ",deposit_fees_frac"
- ",reserve_sig"
- ",purse_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);",
- 15),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wads_in",
- "INSERT INTO wads_in"
- "(wad_in_serial_id"
- ",wad_id"
- ",origin_exchange_url"
- ",amount_val"
- ",amount_frac"
- ",arrival_time"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6);",
- 6),
- GNUNET_PQ_make_prepare (
- "insert_into_table_wad_in_entries",
- "INSERT INTO wad_in_entries"
- "(wad_in_entry_serial_id"
- ",wad_in_serial_id"
- ",reserve_pub"
- ",purse_pub"
- ",h_contract"
- ",purse_expiration"
- ",merge_timestamp"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",wad_fee_val"
- ",wad_fee_frac"
- ",deposit_fees_val"
- ",deposit_fees_frac"
- ",reserve_sig"
- ",purse_sig"
- ") VALUES "
- "($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15);",
- 3),
-
- /* Used in #postgres_begin_shard() */
- GNUNET_PQ_make_prepare (
- "get_open_shard",
- "SELECT"
- " start_row"
- ",end_row"
- " FROM work_shards"
- " WHERE job_name=$1"
- " AND completed=FALSE"
- " AND last_attempt<$2"
- " ORDER BY last_attempt ASC"
- " LIMIT 1;",
- 2),
- /* Used in #postgres_begin_revolving_shard() */
- GNUNET_PQ_make_prepare (
- "get_open_revolving_shard",
- "SELECT"
- " start_row"
- ",end_row"
- " FROM revolving_work_shards"
- " WHERE job_name=$1"
- " AND active=FALSE"
- " ORDER BY last_attempt ASC"
- " LIMIT 1;",
- 2),
- /* Used in #postgres_begin_shard() */
- GNUNET_PQ_make_prepare (
- "reclaim_shard",
- "UPDATE work_shards"
- " SET last_attempt=$2"
- " WHERE job_name=$1"
- " AND start_row=$3"
- " AND end_row=$4",
- 4),
- /* Used in #postgres_begin_revolving_shard() */
- GNUNET_PQ_make_prepare (
- "reclaim_revolving_shard",
- "UPDATE revolving_work_shards"
- " SET last_attempt=$2"
- " ,active=TRUE"
- " WHERE job_name=$1"
- " AND start_row=$3"
- " AND end_row=$4",
- 4),
- /* Used in #postgres_begin_shard() */
- GNUNET_PQ_make_prepare (
- "get_last_shard",
- "SELECT"
- " end_row"
- " FROM work_shards"
- " WHERE job_name=$1"
- " ORDER BY end_row DESC"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_begin_revolving_shard() */
- GNUNET_PQ_make_prepare (
- "get_last_revolving_shard",
- "SELECT"
- " end_row"
- " FROM revolving_work_shards"
- " WHERE job_name=$1"
- " ORDER BY end_row DESC"
- " LIMIT 1;",
- 1),
- /* Used in #postgres_abort_shard() */
- GNUNET_PQ_make_prepare (
- "abort_shard",
- "UPDATE work_shards"
- " SET last_attempt=0"
- " WHERE job_name = $1 "
- " AND start_row = $2 "
- " AND end_row = $3;",
- 3),
- /* Used in #postgres_begin_shard() */
- GNUNET_PQ_make_prepare (
- "claim_next_shard",
- "INSERT INTO work_shards"
- "(job_name"
- ",last_attempt"
- ",start_row"
- ",end_row"
- ") VALUES "
- "($1, $2, $3, $4);",
- 4),
- /* Used in #postgres_claim_revolving_shard() */
- GNUNET_PQ_make_prepare (
- "create_revolving_shard",
- "INSERT INTO revolving_work_shards"
- "(job_name"
- ",last_attempt"
- ",start_row"
- ",end_row"
- ",active"
- ") VALUES "
- "($1, $2, $3, $4, TRUE);",
- 4),
- /* Used in #postgres_complete_shard() */
- GNUNET_PQ_make_prepare (
- "complete_shard",
- "UPDATE work_shards"
- " SET completed=TRUE"
- " WHERE job_name=$1"
- " AND start_row=$2"
- " AND end_row=$3",
- 3),
- /* Used in #postgres_complete_shard() */
- GNUNET_PQ_make_prepare (
- "release_revolving_shard",
- "UPDATE revolving_work_shards"
- " SET active=FALSE"
- " WHERE job_name=$1"
- " AND start_row=$2"
- " AND end_row=$3",
- 3),
- /* Used in #postgres_set_extension_config */
- GNUNET_PQ_make_prepare (
- "set_extension_config",
- "INSERT INTO extensions (name, config) VALUES ($1, $2) "
- "ON CONFLICT (name) "
- "DO UPDATE SET config=$2",
- 2),
- /* Used in #postgres_get_extension_config */
- GNUNET_PQ_make_prepare (
- "get_extension_config",
- "SELECT "
- " config "
- "FROM extensions"
- " WHERE name=$1;",
- 1),
- /* Used in #postgres_insert_contract() */
- GNUNET_PQ_make_prepare (
- "insert_contract",
- "INSERT INTO contracts"
- " (purse_pub"
- " ,pub_ckey"
- " ,e_contract"
- " ,contract_sig"
- " ,purse_expiration"
- " ) SELECT "
- " $1, $2, $3, $4, purse_expiration"
- " FROM purse_requests"
- " WHERE purse_pub=$1"
- " ON CONFLICT DO NOTHING;",
- 4),
- /* Used in #postgres_select_contract */
- GNUNET_PQ_make_prepare (
- "select_contract",
- "SELECT "
- " purse_pub"
- ",e_contract"
- ",contract_sig"
- " FROM contracts"
- " WHERE pub_ckey=$1;",
- 1),
- /* Used in #postgres_select_contract_by_purse */
- GNUNET_PQ_make_prepare (
- "select_contract_by_purse",
- "SELECT "
- " pub_ckey"
- ",e_contract"
- ",contract_sig"
- " FROM contracts"
- " WHERE purse_pub=$1;",
- 1),
- /* Used in #postgres_insert_purse_request() */
- GNUNET_PQ_make_prepare (
- "insert_purse_request",
- "INSERT INTO purse_requests"
- " (purse_pub"
- " ,merge_pub"
- " ,purse_creation"
- " ,purse_expiration"
- " ,h_contract_terms"
- " ,age_limit"
- " ,flags"
- " ,in_reserve_quota"
- " ,amount_with_fee_val"
- " ,amount_with_fee_frac"
- " ,purse_fee_val"
- " ,purse_fee_frac"
- " ,purse_sig"
- " ) VALUES "
- " ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)"
- " ON CONFLICT DO NOTHING;",
- 13),
- /* Used in #postgres_select_purse */
- GNUNET_PQ_make_prepare (
- "select_purse",
- "SELECT "
- " merge_pub"
- ",purse_expiration"
- ",h_contract_terms"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",balance_val"
- ",balance_frac"
- ",merge_timestamp"
- " FROM purse_requests"
- " LEFT JOIN purse_merges USING (purse_pub)"
- " WHERE purse_pub=$1;",
- 1),
- /* Used in #postgres_select_purse_request */
- GNUNET_PQ_make_prepare (
- "select_purse_request",
- "SELECT "
- " merge_pub"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",balance_val"
- ",balance_frac"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE purse_pub=$1;",
- 1),
- /* Used in #postgres_select_purse_by_merge_pub */
- GNUNET_PQ_make_prepare (
- "select_purse_by_merge_pub",
- "SELECT "
- " purse_pub"
- ",purse_expiration"
- ",h_contract_terms"
- ",age_limit"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",balance_val"
- ",balance_frac"
- ",purse_sig"
- " FROM purse_requests"
- " WHERE merge_pub=$1;",
- 1),
- /* Used in #postgres_get_purse_deposit */
- GNUNET_PQ_make_prepare (
- "select_purse_deposit_by_coin_pub",
- "SELECT "
- " coin_sig"
- ",amount_with_fee_val"
- ",amount_with_fee_frac"
- ",denom_pub_hash"
- ",age_commitment_hash"
- ",partner_base_url"
- " FROM purse_deposits"
- " LEFT JOIN partners USING (partner_serial_id)"
- " JOIN known_coins kc USING (coin_pub)"
- " JOIN denominations USING (denominations_serial)"
- " WHERE coin_pub=$2"
- " AND purse_pub=$1;",
- 2),
- /* Used in #postgres_do_purse_merge() */
- GNUNET_PQ_make_prepare (
- "call_purse_merge",
- "SELECT"
- " out_no_partner AS no_partner"
- ",out_no_balance AS no_balance"
- ",out_no_kyc AS no_kyc"
- ",out_no_reserve AS no_reserve"
- ",out_conflict AS conflict"
- " FROM exchange_do_purse_merge"
- " ($1, $2, $3, $4, $5, $6, $7);",
- 7),
- /* Used in #postgres_do_reserve_purse() */
- GNUNET_PQ_make_prepare (
- "call_reserve_purse",
- "SELECT"
- " out_no_funds AS insufficient_funds"
- ",out_no_reserve AS no_reserve"
- ",out_no_kyc AS no_kyc"
- ",out_conflict AS conflict"
- " FROM exchange_do_reserve_purse"
- " ($1, $2, $3, $4, $5, $6, $7, $8, $9);",
- 9),
- /* Used in #postgres_select_purse_merge */
- GNUNET_PQ_make_prepare (
- "select_purse_merge",
- "SELECT "
- " reserve_pub"
- ",merge_sig"
- ",merge_timestamp"
- ",partner_base_url"
- " FROM purse_merges"
- " LEFT JOIN partners USING (partner_serial_id)"
- " WHERE purse_pub=$1;",
- 1),
- /* Used in #postgres_do_account_merge() */
- GNUNET_PQ_make_prepare (
- "call_account_merge",
- "SELECT 1"
- " FROM exchange_do_account_merge"
- " ($1, $2, $3);",
- 3),
- /* Used in #postgres_insert_history_request() */
- GNUNET_PQ_make_prepare (
- "call_history_request",
- "SELECT"
- " out_balance_ok AS balance_ok"
- " ,out_idempotent AS idempotent"
- " FROM exchange_do_history_request"
- " ($1, $2, $3, $4, $5)",
- 5),
- /* Used in #postgres_insert_close_request() */
- GNUNET_PQ_make_prepare (
- "call_account_close",
- "SELECT "
- " out_final_balance_val"
- ",out_final_balance_frac"
- " FROM exchange_do_close_request"
- " ($1, $2, $3)",
- 3),
-
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- ret = GNUNET_PQ_prepare_statements (pg->conn,
- ps);
- if (GNUNET_OK != ret)
- return ret;
- pg->init = true;
- return GNUNET_OK;
-}
-
-
-/**
* Connect to the database if the connection does not exist yet.
*
* @param pg the plugin-specific state
- * @param skip_prepare true if we should skip prepared statement setup
* @return #GNUNET_OK on success
*/
-static enum GNUNET_GenericReturnValue
-internal_setup (struct PostgresClosure *pg,
- bool skip_prepare)
+enum GNUNET_GenericReturnValue
+TEH_PG_internal_setup (struct PostgresClosure *pg)
{
if (NULL == pg->conn)
{
@@ -4294,6 +272,9 @@ internal_setup (struct PostgresClosure *pg,
"SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ /* Mergejoin causes issues, see Postgres #18380 */
+ GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
#else
@@ -4302,7 +283,9 @@ internal_setup (struct PostgresClosure *pg,
"SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
- GNUNET_PQ_make_try_execute ("SET autocommit=OFF;"),
+ /* Mergejoin causes issues, see Postgres #18380 */
+ GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
#endif
@@ -4315,11630 +298,17 @@ internal_setup (struct PostgresClosure *pg,
NULL);
if (NULL == db_conn)
return GNUNET_SYSERR;
+
+ pg->prep_gen++;
pg->conn = db_conn;
}
if (NULL == pg->transaction_name)
GNUNET_PQ_reconnect_if_down (pg->conn);
- if (pg->init)
- return GNUNET_OK;
- if (skip_prepare)
- return GNUNET_OK;
- return prepare_statements (pg);
-}
-
-
-/**
- * Do a pre-flight check that we are not in an uncommitted transaction.
- * If we are, try to commit the previous transaction and output a warning.
- * Does not return anything, as we will continue regardless of the outcome.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return #GNUNET_OK if everything is fine
- * #GNUNET_NO if a transaction was rolled back
- * #GNUNET_SYSERR on hard errors
- */
-static enum GNUNET_GenericReturnValue
-postgres_preflight (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("ROLLBACK"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- if (! pg->init)
- {
- if (GNUNET_OK !=
- internal_setup (pg,
- false))
- return GNUNET_SYSERR;
- }
- if (NULL == pg->transaction_name)
- return GNUNET_OK; /* all good */
- if (GNUNET_OK ==
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BUG: Preflight check rolled back transaction `%s'!\n",
- pg->transaction_name);
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BUG: Preflight check failed to rollback transaction `%s'!\n",
- pg->transaction_name);
- }
- pg->transaction_name = NULL;
- return GNUNET_NO;
-}
-
-
-/**
- * Start a transaction.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param name unique name identifying the transaction (for debugging)
- * must point to a constant
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-postgres_start (void *cls,
- const char *name)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL SERIALIZABLE"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- GNUNET_assert (NULL != name);
- if (GNUNET_SYSERR ==
- postgres_preflight (pg))
- return GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting transaction `%s'\n",
- name);
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR ("Failed to start transaction\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pg->transaction_name = name;
- return GNUNET_OK;
-}
-
-
-/**
- * Start a READ COMMITTED transaction.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param name unique name identifying the transaction (for debugging)
- * must point to a constant
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-postgres_start_read_committed (void *cls,
- const char *name)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("START TRANSACTION ISOLATION LEVEL READ COMMITTED"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- GNUNET_assert (NULL != name);
- if (GNUNET_SYSERR ==
- postgres_preflight (pg))
- return GNUNET_SYSERR;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting READ COMMITTED transaction `%s`\n",
- name);
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR ("Failed to start transaction\n");
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- pg->transaction_name = name;
- return GNUNET_OK;
-}
-
-
-/**
- * Roll back the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- */
-static void
-postgres_rollback (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("ROLLBACK"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- if (NULL == pg->transaction_name)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Skipping rollback, no transaction active\n");
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Rolling back transaction\n");
- GNUNET_break (GNUNET_OK ==
- GNUNET_PQ_exec_statements (pg->conn,
- es));
- pg->transaction_name = NULL;
-}
-
-
-/**
- * Commit the current transaction of a database connection.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @return final transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_commit (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- GNUNET_break (NULL != pg->transaction_name);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Committing transaction `%s'\n",
- pg->transaction_name);
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "do_commit",
- params);
- pg->transaction_name = NULL;
- return qs;
-}
-
-
-/**
- * Register callback to be invoked on events of type @a es.
- *
- * @param cls database context to use
- * @param timeout how long until to generate a timeout event
- * @param es specification of the event to listen for
- * @param cb function to call when the event happens, possibly
- * multiple times (until cancel is invoked)
- * @param cb_cls closure for @a cb
- * @return handle useful to cancel the listener
- */
-static struct GNUNET_DB_EventHandler *
-postgres_event_listen (void *cls,
- struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_DB_EventHeaderP *es,
- GNUNET_DB_EventCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
-
- return GNUNET_PQ_event_listen (pg->conn,
- es,
- timeout,
- cb,
- cb_cls);
-}
-
-
-/**
- * Stop notifications.
- *
- * @param cls the plugin's `struct PostgresClosure`
- * @param eh handle to unregister.
- */
-static void
-postgres_event_listen_cancel (void *cls,
- struct GNUNET_DB_EventHandler *eh)
-{
- (void) cls;
- GNUNET_PQ_event_listen_cancel (eh);
-}
-
-
-/**
- * Notify all that listen on @a es of an event.
- *
- * @param cls database context to use
- * @param es specification of the event to generate
- * @param extra additional event data provided
- * @param extra_size number of bytes in @a extra
- */
-static void
-postgres_event_notify (void *cls,
- const struct GNUNET_DB_EventHeaderP *es,
- const void *extra,
- size_t extra_size)
-{
- struct PostgresClosure *pg = cls;
-
- GNUNET_PQ_event_notify (pg->conn,
- es,
- extra,
- extra_size);
-}
-
-
-/**
- * Insert a denomination key's public information into the database for
- * reference by auditors and other consistency checks.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub the public key used for signing coins of this denomination
- * @param issue issuing information with value, fees and other info about the coin
- * @return status of the query
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_denomination_info (
- void *cls,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyInformation *issue)
-{
- struct PostgresClosure *pg = cls;
- struct TALER_DenominationHashP denom_hash;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&issue->denom_hash),
- TALER_PQ_query_param_denom_pub (denom_pub),
- GNUNET_PQ_query_param_auto_from_type (&issue->signature),
- GNUNET_PQ_query_param_timestamp (&issue->start),
- GNUNET_PQ_query_param_timestamp (&issue->expire_withdraw),
- GNUNET_PQ_query_param_timestamp (&issue->expire_deposit),
- GNUNET_PQ_query_param_timestamp (&issue->expire_legal),
- TALER_PQ_query_param_amount (&issue->value),
- TALER_PQ_query_param_amount (&issue->fees.withdraw),
- TALER_PQ_query_param_amount (&issue->fees.deposit),
- TALER_PQ_query_param_amount (&issue->fees.refresh),
- TALER_PQ_query_param_amount (&issue->fees.refund),
- GNUNET_PQ_query_param_uint32 (&denom_pub->age_mask.bits),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (denom_pub->age_mask.bits ==
- issue->age_mask.bits);
- TALER_denom_pub_hash (denom_pub,
- &denom_hash);
- GNUNET_assert (0 ==
- GNUNET_memcmp (&denom_hash,
- &issue->denom_hash));
- GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
- issue->start.abs_time));
- GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
- issue->expire_withdraw.abs_time));
- GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
- issue->expire_deposit.abs_time));
- GNUNET_assert (! GNUNET_TIME_absolute_is_zero (
- issue->expire_legal.abs_time));
- /* check fees match denomination currency */
- GNUNET_assert (GNUNET_YES ==
- TALER_denom_fee_check_currency (
- issue->value.currency,
- &issue->fees));
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_insert",
- params);
-}
-
-
-/**
- * Fetch information about a denomination key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the public key used for signing coins of this denomination
- * @param[out] issue set to issue information with value, fees and other info about the coin
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_denomination_info (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct TALER_EXCHANGEDB_DenominationKeyInformation *issue)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &issue->signature),
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &issue->start),
- GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
- &issue->expire_withdraw),
- GNUNET_PQ_result_spec_timestamp ("expire_deposit",
- &issue->expire_deposit),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &issue->expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
- &issue->value),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &issue->fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &issue->fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &issue->fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &issue->fees.refund),
- GNUNET_PQ_result_spec_uint32 ("age_mask",
- &issue->age_mask.bits),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "denomination_get",
- params,
- rs);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- return qs;
- issue->denom_hash = *denom_pub_hash;
- return qs;
-}
-
-
-/**
- * Closure for #domination_cb_helper()
- */
-struct DenomIteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_DenominationCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-};
-
-
-/**
- * Helper function for #postgres_iterate_denomination_info().
- * Calls the callback with each denomination key.
- *
- * @param cls a `struct DenomIteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-domination_cb_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DenomIteratorContext *dic = cls;
- struct PostgresClosure *pg = dic->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_DenominationKeyInformation issue;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_DenominationHashP denom_hash;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &issue.signature),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &denom_hash),
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &issue.start),
- GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
- &issue.expire_withdraw),
- GNUNET_PQ_result_spec_timestamp ("expire_deposit",
- &issue.expire_deposit),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &issue.expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
- &issue.value),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &issue.fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &issue.fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &issue.fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &issue.fees.refund),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_uint32 ("age_mask",
- &issue.age_mask.bits),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
-
- /* Unfortunately we have to carry the age mask in both, the
- * TALER_DenominationPublicKey and
- * TALER_EXCHANGEDB_DenominationKeyInformation at different times.
- * Here we use _both_ so let's make sure the values are the same. */
- denom_pub.age_mask = issue.age_mask;
- TALER_denom_pub_hash (&denom_pub,
- &issue.denom_hash);
- if (0 !=
- GNUNET_memcmp (&issue.denom_hash,
- &denom_hash))
- {
- GNUNET_break (0);
- }
- else
- {
- dic->cb (dic->cb_cls,
- &denom_pub,
- &issue);
- }
- TALER_denom_pub_free (&denom_pub);
- }
-}
-
-
-/**
- * Fetch information about all known denomination keys.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call on each denomination key
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_iterate_denomination_info (void *cls,
- TALER_EXCHANGEDB_DenominationCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct DenomIteratorContext dic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "denomination_iterate",
- params,
- &domination_cb_helper,
- &dic);
-}
-
-
-/**
- * Closure for #dominations_cb_helper()
- */
-struct DenomsIteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_DenominationsCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-};
-
-
-/**
- * Helper function for #postgres_iterate_denominations().
- * Calls the callback with each denomination key.
- *
- * @param cls a `struct DenomsIteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-dominations_cb_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DenomsIteratorContext *dic = cls;
- struct PostgresClosure *pg = dic->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_DenominationKeyMetaData meta = {0};
- struct TALER_DenominationPublicKey denom_pub = {0};
- struct TALER_MasterSignatureP master_sig = {0};
- struct TALER_DenominationHashP h_denom_pub = {0};
- bool revoked;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_bool ("revoked",
- &revoked),
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta.start),
- GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
- &meta.expire_withdraw),
- GNUNET_PQ_result_spec_timestamp ("expire_deposit",
- &meta.expire_deposit),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta.expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
- &meta.value),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &meta.fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &meta.fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &meta.fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &meta.fees.refund),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_uint32 ("age_mask",
- &meta.age_mask.bits),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
-
- /* make sure the mask information is the same */
- denom_pub.age_mask = meta.age_mask;
-
- TALER_denom_pub_hash (&denom_pub,
- &h_denom_pub);
- dic->cb (dic->cb_cls,
- &denom_pub,
- &h_denom_pub,
- &meta,
- &master_sig,
- revoked);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called to invoke @a cb on every known denomination key (revoked
- * and non-revoked) that has been signed by the master key. Runs in its own
- * read-only transaction.
- *
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call on each denomination key
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_iterate_denominations (void *cls,
- TALER_EXCHANGEDB_DenominationsCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct DenomsIteratorContext dic = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_denominations",
- params,
- &dominations_cb_helper,
- &dic);
-}
-
-
-/**
- * Closure for #signkeys_cb_helper()
- */
-struct SignkeysIteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_ActiveSignkeysCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-
-};
-
-
-/**
- * Helper function for #postgres_iterate_active_signkeys().
- * Calls the callback with each signkey.
- *
- * @param cls a `struct SignkeysIteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-signkeys_cb_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SignkeysIteratorContext *dic = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_SignkeyMetaData meta;
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_auto_from_type ("exchange_pub",
- &exchange_pub),
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta.start),
- GNUNET_PQ_result_spec_timestamp ("expire_sign",
- &meta.expire_sign),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta.expire_legal),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
- dic->cb (dic->cb_cls,
- &exchange_pub,
- &meta,
- &master_sig);
- }
-}
-
-
-/**
- * Function called to invoke @a cb on every non-revoked exchange signing key
- * that has been signed by the master key. Revoked and (for signing!)
- * expired keys are skipped. Runs in its own read-only transaction.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call on each signing key
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_iterate_active_signkeys (void *cls,
- TALER_EXCHANGEDB_ActiveSignkeysCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = {0};
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_end
- };
- struct SignkeysIteratorContext dic = {
- .cb = cb,
- .cb_cls = cb_cls,
- };
-
- now = GNUNET_TIME_absolute_get ();
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_signkeys",
- params,
- &signkeys_cb_helper,
- &dic);
-}
-
-
-/**
- * Closure for #auditors_cb_helper()
- */
-struct AuditorsIteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_AuditorsCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-
-};
-
-
-/**
- * Helper function for #postgres_iterate_active_auditors().
- * Calls the callback with each auditor.
- *
- * @param cls a `struct SignkeysIteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-auditors_cb_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AuditorsIteratorContext *dic = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_AuditorPublicKeyP auditor_pub;
- char *auditor_url;
- char *auditor_name;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
- &auditor_pub),
- GNUNET_PQ_result_spec_string ("auditor_url",
- &auditor_url),
- GNUNET_PQ_result_spec_string ("auditor_name",
- &auditor_name),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
- dic->cb (dic->cb_cls,
- &auditor_pub,
- auditor_url,
- auditor_name);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called to invoke @a cb on every active auditor. Disabled
- * auditors are skipped. Runs in its own read-only transaction.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call on each active auditor
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_iterate_active_auditors (void *cls,
- TALER_EXCHANGEDB_AuditorsCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct AuditorsIteratorContext dic = {
- .cb = cb,
- .cb_cls = cb_cls,
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_auditors",
- params,
- &auditors_cb_helper,
- &dic);
-}
-
-
-/**
- * Closure for #auditor_denoms_cb_helper()
- */
-struct AuditorDenomsIteratorContext
-{
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_AuditorDenominationsCallback cb;
-
- /**
- * Closure to pass to @e cb
- */
- void *cb_cls;
-};
-
-
-/**
- * Helper function for #postgres_iterate_auditor_denominations().
- * Calls the callback with each auditor and denomination pair.
- *
- * @param cls a `struct AuditorDenomsIteratorContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-auditor_denoms_cb_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AuditorDenomsIteratorContext *dic = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_AuditorPublicKeyP auditor_pub;
- struct TALER_DenominationHashP h_denom_pub;
- struct TALER_AuditorSignatureP auditor_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("auditor_pub",
- &auditor_pub),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &h_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
- &auditor_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- return;
- }
- dic->cb (dic->cb_cls,
- &auditor_pub,
- &h_denom_pub,
- &auditor_sig);
- }
-}
-
-
-/**
- * Function called to invoke @a cb on every denomination with an active
- * auditor. Disabled auditors and denominations without auditor are
- * skipped. Runs in its own read-only transaction.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call on each active auditor
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_iterate_auditor_denominations (
- void *cls,
- TALER_EXCHANGEDB_AuditorDenominationsCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct AuditorDenomsIteratorContext dic = {
- .cb = cb,
- .cb_cls = cb_cls,
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "select_auditor_denoms",
- params,
- &auditor_denoms_cb_helper,
- &dic);
-}
-
-
-/**
- * Get the summary of a reserve.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param[in,out] reserve the reserve data. The public key of the reserve should be
- * set in this structure; it is used to query the database. The balance
- * and expiration are then filled accordingly.
- * @param[out] kyc set to the KYC status of the reserve
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_reserves_get (void *cls,
- struct TALER_EXCHANGEDB_Reserve *reserve,
- struct TALER_EXCHANGEDB_KycStatus *kyc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
- &reserve->balance),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &reserve->expiry),
- GNUNET_PQ_result_spec_timestamp ("gc_date",
- &reserve->gc),
- GNUNET_PQ_result_spec_uint64 ("payment_target_uuid",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_bool ("kyc_ok",
- &kyc->ok),
- GNUNET_PQ_result_spec_end
- };
-
- kyc->type = TALER_EXCHANGEDB_KYC_WITHDRAW;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserves_get_with_kyc",
- params,
- rs);
-}
-
-
-/**
- * Set the KYC status to "OK" for a bank account.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto which account has been checked
- * @param id external ID to persist
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_set_kyc_ok (void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const char *id)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_QueryParam params2[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (id),
- GNUNET_PQ_query_param_end
- };
- struct TALER_KycCompletedEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_KYC_COMPLETED)
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
- &rep.h_payto),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "set_kyc_ok",
- params2);
- if (qs <= 0)
- return qs;
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_kyc_h_payto",
- params,
- rs);
- if (qs <= 0)
- return qs;
- postgres_event_notify (pg,
- &rep.header,
- NULL,
- 0);
- return qs;
-}
-
-
-/**
- * Get the @a kyc status and @a h_payto by UUID.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto set to the hash of the account's payto URI (unsalted)
- * @param[out] kyc set to the KYC status of the account
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_kyc_status (void *cls,
- const struct TALER_PaytoHashP *h_payto,
- struct TALER_EXCHANGEDB_KycStatus *kyc)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wire_target_serial_id",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_bool ("kyc_ok",
- &kyc->ok),
- GNUNET_PQ_result_spec_end
- };
-
- kyc->type = TALER_EXCHANGEDB_KYC_UNKNOWN;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_kyc_status_by_payto",
- params,
- rs);
-}
-
-
-/**
- * Compute the hash of the @a payto_uri and use it to get the KYC status for a
- * wallet. If the status is unknown, inserts a new status record (hence
- * INsertSELECT).
- *
- * @param pg the plugin-specific state
- * @param payto_uri the payto URI to check
- * @param[out] h_payto set to the hash of @a payto_uri
- * @param[out] kyc set to the KYC status of the wallet
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-inselect_account_kyc_status (
- struct PostgresClosure *pg,
- const char *payto_uri,
- struct TALER_PaytoHashP *h_payto,
- struct TALER_EXCHANGEDB_KycStatus *kyc)
-{
- enum GNUNET_DB_QueryStatus qs;
-
- TALER_payto_hash (payto_uri,
- h_payto);
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wire_target_serial_id",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_bool ("kyc_ok",
- &kyc->ok),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_kyc_status_by_payto",
- params,
- rs);
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec irs[] = {
- GNUNET_PQ_result_spec_uint64 ("wire_target_serial_id",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "insert_kyc_status",
- iparams,
- irs);
- if (qs < 0)
- return qs;
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- return GNUNET_DB_STATUS_SOFT_ERROR;
- kyc->ok = false;
- }
- }
- kyc->type = TALER_EXCHANGEDB_KYC_BALANCE;
- return qs;
-}
-
-
-/**
- * Get the KYC status for a wallet. If the status is unknown,
- * inserts a new status record (hence INsertSELECT).
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the wallet
- * @param[out] kyc set to the KYC status of the wallet
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_inselect_wallet_kyc_status (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_EXCHANGEDB_KycStatus *kyc)
-{
- struct PostgresClosure *pg = cls;
- char *payto_uri;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_PaytoHashP h_payto;
-
- payto_uri = TALER_payto_from_reserve (pg->exchange_url,
- reserve_pub);
- qs = inselect_account_kyc_status (pg,
- payto_uri,
- &h_payto,
- kyc);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Wire account for `%s' is %llu\n",
- payto_uri,
- (unsigned long long) kyc->payment_target_uuid);
- GNUNET_free (payto_uri);
- return qs;
-}
-
-
-/**
- * Get the summary of a reserve.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param[in,out] reserve the reserve data. The public key of the reserve should be
- * set in this structure; it is used to query the database. The balance
- * and expiration are then filled accordingly.
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-reserves_get_internal (void *cls,
- struct TALER_EXCHANGEDB_Reserve *reserve)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
- &reserve->balance),
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &reserve->expiry),
- GNUNET_PQ_result_spec_timestamp ("gc_date",
- &reserve->gc),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserves_get",
- params,
- rs);
-}
-
-
-/**
- * Updates a reserve with the data from the given reserve structure.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve the reserve structure whose data will be used to update the
- * corresponding record in the database.
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-reserves_update (void *cls,
- const struct TALER_EXCHANGEDB_Reserve *reserve)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&reserve->expiry),
- GNUNET_PQ_query_param_timestamp (&reserve->gc),
- TALER_PQ_query_param_amount (&reserve->balance),
- GNUNET_PQ_query_param_auto_from_type (&reserve->pub),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reserve_update",
- params);
-}
-
-
-/**
- * Generate event notification for the reserve
- * change.
- *
- * @param pg plugin state
- * @param reserve_pub reserve to notfiy on
- */
-static void
-notify_on_reserve (struct PostgresClosure *pg,
- const struct TALER_ReservePublicKeyP *reserve_pub)
-{
- struct TALER_ReserveEventP rep = {
- .header.size = htons (sizeof (rep)),
- .header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
- .reserve_pub = *reserve_pub
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Notifying on reserve!\n");
- postgres_event_notify (pg,
- &rep.header,
- NULL,
- 0);
-}
-
-
-/**
- * Insert an incoming transaction into reserves. New reserves are also
- * created through this function. Started within the scope of an ongoing
- * transaction.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param balance the amount that has to be added to the reserve
- * @param execution_time when was the amount added
- * @param sender_account_details account information for the sender (payto://-URL)
- * @param exchange_account_section name of the section in the configuration for the exchange's
- * account into which the deposit was made
- * @param wire_ref unique reference identifying the wire transfer
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_reserves_in_insert (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *balance,
- struct GNUNET_TIME_Timestamp execution_time,
- const char *sender_account_details,
- const char *exchange_account_section,
- uint64_t wire_ref)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs1;
- struct TALER_EXCHANGEDB_Reserve reserve;
- struct GNUNET_TIME_Timestamp expiry;
- struct GNUNET_TIME_Timestamp gc;
- uint64_t reserve_uuid;
-
- reserve.pub = *reserve_pub;
- expiry = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_add (execution_time.abs_time,
- pg->idle_reserve_expiration_time));
- gc = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
- pg->legal_reserve_expiration_time));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Creating reserve %s with expiration in %s\n",
- TALER_B2S (reserve_pub),
- GNUNET_STRINGS_relative_time_to_string (
- pg->idle_reserve_expiration_time,
- GNUNET_NO));
- /* Optimistically assume this is a new reserve, create balance for the first
- time; we do this before adding the actual transaction to "reserves_in",
- as for a new reserve it can't be a duplicate 'add' operation, and as
- the 'add' operation needs the reserve entry as a foreign key. */
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- TALER_PQ_query_param_amount (balance),
- GNUNET_PQ_query_param_timestamp (&expiry),
- GNUNET_PQ_query_param_timestamp (&gc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("reserve_uuid",
- &reserve_uuid),
- GNUNET_PQ_result_spec_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Reserve does not exist; creating a new one\n");
- /* Note: query uses 'on conflict do nothing' */
- qs1 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserve_create",
- params,
- rs);
- if (qs1 < 0)
- return qs1;
- }
-
- /* Create new incoming transaction, "ON CONFLICT DO NOTHING"
- is again used to guard against duplicates. */
- {
- enum GNUNET_DB_QueryStatus qs2;
- struct TALER_EXCHANGEDB_KycStatus kyc;
- enum GNUNET_DB_QueryStatus qs3;
- struct TALER_PaytoHashP h_payto;
-
- memset (&kyc,
- 0,
- sizeof (kyc));
- qs3 = inselect_account_kyc_status (pg,
- sender_account_details,
- &h_payto,
- &kyc);
- if (qs3 <= 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs3);
- return qs3;
- }
- GNUNET_assert (0 != kyc.payment_target_uuid);
- /* We do not have the UUID, so insert by public key */
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&reserve.pub),
- GNUNET_PQ_query_param_uint64 (&wire_ref),
- TALER_PQ_query_param_amount (balance),
- GNUNET_PQ_query_param_string (exchange_account_section),
- GNUNET_PQ_query_param_auto_from_type (&h_payto),
- GNUNET_PQ_query_param_timestamp (&execution_time),
- GNUNET_PQ_query_param_end
- };
-
- qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reserves_in_add_transaction",
- params);
- /* qs2 could be 0 as statement used 'ON CONFLICT DO NOTHING' */
- if (0 >= qs2)
- {
- if ( (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs2) &&
- (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs1) )
- {
- /* Conflict for the transaction, but the reserve was
- just now created, that should be impossible. */
- GNUNET_break (0); /* should be impossible: reserve was fresh,
- but transaction already known */
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- /* Transaction was already known or error. We are finished. */
- return qs2;
- }
- }
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs1)
- {
- /* New reserve, we are finished */
- notify_on_reserve (pg,
- reserve_pub);
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
-
- /* we were wrong with our optimistic assumption:
- reserve did already exist, need to do an update instead */
- {
- /* We need to move away from 'read committed' to serializable.
- Also, we know that it should be safe to commit at this point.
- (We are only run in a larger transaction for performance.) */
- enum GNUNET_DB_QueryStatus cs;
-
- cs = postgres_commit (pg);
- if (cs < 0)
- return cs;
- if (GNUNET_OK !=
- postgres_start (pg,
- "reserve-update-serializable"))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- {
- enum GNUNET_DB_QueryStatus reserve_exists;
-
- reserve_exists = reserves_get_internal (pg,
- &reserve);
- switch (reserve_exists)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- return reserve_exists;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- return reserve_exists;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* First we got a conflict, but then we cannot select? Very strange. */
- GNUNET_break (0);
- return GNUNET_DB_STATUS_SOFT_ERROR;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* continued below */
- break;
- }
- }
-
- {
- struct TALER_EXCHANGEDB_Reserve updated_reserve;
- enum GNUNET_DB_QueryStatus qs3;
-
- /* If the reserve already existed, we need to still update the
- balance; we do this after checking for duplication, as
- otherwise we might have to actually pay the cost to roll this
- back for duplicate transactions; like this, we should virtually
- never actually have to rollback anything. */
- updated_reserve.pub = reserve.pub;
- if (0 >
- TALER_amount_add (&updated_reserve.balance,
- &reserve.balance,
- balance))
- {
- /* currency overflow or incompatible currency */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Attempt to deposit incompatible amount into reserve\n");
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- updated_reserve.expiry = GNUNET_TIME_timestamp_max (expiry,
- reserve.expiry);
- updated_reserve.gc = GNUNET_TIME_timestamp_max (gc,
- reserve.gc);
- qs3 = reserves_update (pg,
- &updated_reserve);
- switch (qs3)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- return qs3;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- return qs3;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* How can the UPDATE not work here? Very strange. */
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* continued below */
- break;
- }
- }
- notify_on_reserve (pg,
- reserve_pub);
- /* Go back to original transaction mode */
- {
- enum GNUNET_DB_QueryStatus cs;
-
- cs = postgres_commit (pg);
- if (cs < 0)
- return cs;
- if (GNUNET_OK !=
- postgres_start_read_committed (pg,
- "reserve-insert-continued"))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-
-/**
- * Locate the response for a /reserve/withdraw request under the
- * key of the hash of the blinded message.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param bch hash that uniquely identifies the withdraw operation
- * @param collectable corresponding collectable coin (blind signature)
- * if a coin is found
- * @return statement execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_withdraw_info (
- void *cls,
- const struct TALER_BlindedCoinHashP *bch,
- struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (bch),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &collectable->denom_pub_hash),
- TALER_PQ_result_spec_blinded_denom_sig ("denom_sig",
- &collectable->sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &collectable->reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &collectable->reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &collectable->h_coin_envelope),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &collectable->amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &collectable->withdraw_fee),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_withdraw_info",
- params,
- rs);
-}
-
-
-/**
- * Perform withdraw operation, checking for sufficient balance
- * and possibly persisting the withdrawal details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
- * @param[in,out] collectable corresponding collectable coin (blind signature) if a coin is found; possibly updated if a (different) signature exists already
- * @param now current time (rounded)
- * @param[out] found set to true if the reserve was found
- * @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] kyc set to true if the kyc status of the reserve is satisfied
- * @param[out] ruuid set to the reserve's UUID (reserves table row)
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_withdraw (
- void *cls,
- const struct TALER_CsNonce *nonce,
- const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
- struct GNUNET_TIME_Timestamp now,
- bool *found,
- bool *balance_ok,
- struct TALER_EXCHANGEDB_KycStatus *kyc,
- uint64_t *ruuid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Timestamp gc;
- struct GNUNET_PQ_QueryParam params[] = {
- NULL == nonce
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (nonce),
- TALER_PQ_query_param_amount (&collectable->amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash),
- GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
- GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
- TALER_PQ_query_param_blinded_denom_sig (&collectable->sig),
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_timestamp (&gc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("reserve_found",
- found),
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("kyc_ok",
- &kyc->ok),
- GNUNET_PQ_result_spec_uint64 ("payment_target_uuid",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_uint64 ("ruuid",
- ruuid),
- GNUNET_PQ_result_spec_end
- };
-
- gc = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_add (now.abs_time,
- pg->legal_reserve_expiration_time));
- kyc->type = TALER_EXCHANGEDB_KYC_WITHDRAW;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_withdraw",
- params,
- rs);
-}
-
-
-/**
- * Perform reserve update as part of a batch withdraw operation, checking
- * for sufficient balance. Persisting the withdrawal details is done
- * separately!
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param now current time (rounded)
- * @param reserve_pub public key of the reserve to debit
- * @param amount total amount to withdraw
- * @param[out] found set to true if the reserve was found
- * @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] kyc set to the KYC status of the reserve
- * @param[out] ruuid set to the reserve's UUID (reserves table row)
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_batch_withdraw (
- void *cls,
- struct GNUNET_TIME_Timestamp now,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *amount,
- bool *found,
- bool *balance_ok,
- struct TALER_EXCHANGEDB_KycStatus *kyc,
- uint64_t *ruuid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Timestamp gc;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (amount),
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_timestamp (&gc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("reserve_found",
- found),
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("kyc_ok",
- &kyc->ok),
- GNUNET_PQ_result_spec_uint64 ("payment_target_uuid",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_uint64 ("ruuid",
- ruuid),
- GNUNET_PQ_result_spec_end
- };
-
- gc = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_add (now.abs_time,
- pg->legal_reserve_expiration_time));
- kyc->type = TALER_EXCHANGEDB_KYC_WITHDRAW;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_batch_withdraw",
- params,
- rs);
-}
-
-
-/**
- * Perform insert as part of a batch withdraw operation, and persisting the
- * withdrawal details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
- * @param collectable corresponding collectable coin (blind signature)
- * @param now current time (rounded)
- * @param ruuid reserve UUID
- * @param[out] denom_unknown set if the denomination is unknown in the DB
- * @param[out] conflict if the envelope was already in the DB
- * @param[out] nonce_reuse if @a nonce was non-NULL and reused
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_batch_withdraw_insert (
- void *cls,
- const struct TALER_CsNonce *nonce,
- const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
- struct GNUNET_TIME_Timestamp now,
- uint64_t ruuid,
- bool *denom_unknown,
- bool *conflict,
- bool *nonce_reuse)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- NULL == nonce
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (nonce),
- TALER_PQ_query_param_amount (&collectable->amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&collectable->denom_pub_hash),
- GNUNET_PQ_query_param_uint64 (&ruuid),
- GNUNET_PQ_query_param_auto_from_type (&collectable->reserve_sig),
- GNUNET_PQ_query_param_auto_from_type (&collectable->h_coin_envelope),
- TALER_PQ_query_param_blinded_denom_sig (&collectable->sig),
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("denom_unknown",
- denom_unknown),
- GNUNET_PQ_result_spec_bool ("conflict",
- conflict),
- GNUNET_PQ_result_spec_bool ("nonce_reuse",
- nonce_reuse),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_batch_withdraw_insert",
- params,
- rs);
-}
-
-
-/**
- * Check that reserve remains below threshold for KYC
- * checks after withdraw operation.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param ruuid reserve to check
- * @param withdraw_start starting point to accumulate from
- * @param upper_limit maximum amount allowed
- * @param[out] below_limit set to true if the limit was not exceeded
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_withdraw_limit_check (
- void *cls,
- uint64_t ruuid,
- struct GNUNET_TIME_Absolute withdraw_start,
- const struct TALER_Amount *upper_limit,
- bool *below_limit)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&ruuid),
- GNUNET_PQ_query_param_absolute_time (&withdraw_start),
- TALER_PQ_query_param_amount (upper_limit),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("below_limit",
- below_limit),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_withdraw_limit_check",
- params,
- rs);
-}
-
-
-/**
- * Compute the shard number of a given @a merchant_pub.
- *
- * @param merchant_pub merchant public key to compute shard for
- * @return shard number
- */
-static uint64_t
-compute_shard (const struct TALER_MerchantPublicKeyP *merchant_pub)
-{
- uint32_t res;
-
- GNUNET_assert (GNUNET_YES ==
- GNUNET_CRYPTO_kdf (&res,
- sizeof (res),
- merchant_pub,
- sizeof (*merchant_pub),
- "VOID",
- 4,
- NULL, 0));
- /* interpret hash result as NBO for platform independence,
- convert to HBO and map to [0..2^31-1] range */
- res = ntohl (res);
- if (res > INT32_MAX)
- res += INT32_MIN;
- GNUNET_assert (res <= INT32_MAX);
- return (uint64_t) res;
-}
-
-
-/**
- * Perform deposit operation, checking for sufficient balance
- * of the coin and possibly persisting the deposit details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param deposit deposit operation details
- * @param known_coin_id row of the coin in the known_coins table
- * @param h_payto hash of the merchant's bank account details
- * @param extension_blocked true if an extension is blocking the wire transfer
- * @param[in,out] exchange_timestamp time to use for the deposit (possibly updated)
- * @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] in_conflict set to true if the deposit conflicted
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_deposit (
- void *cls,
- const struct TALER_EXCHANGEDB_Deposit *deposit,
- uint64_t known_coin_id,
- const struct TALER_PaytoHashP *h_payto,
- bool extension_blocked,
- struct GNUNET_TIME_Timestamp *exchange_timestamp,
- bool *balance_ok,
- bool *in_conflict)
-{
- struct PostgresClosure *pg = cls;
- uint64_t deposit_shard = compute_shard (&deposit->merchant_pub);
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&deposit->amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt),
- GNUNET_PQ_query_param_timestamp (&deposit->timestamp),
- GNUNET_PQ_query_param_timestamp (exchange_timestamp),
- GNUNET_PQ_query_param_timestamp (&deposit->refund_deadline),
- GNUNET_PQ_query_param_timestamp (&deposit->wire_deadline),
- GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),
- GNUNET_PQ_query_param_string (deposit->receiver_wire_account),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
- GNUNET_PQ_query_param_uint64 (&deposit_shard),
- GNUNET_PQ_query_param_bool (extension_blocked),
- (NULL == deposit->extension_details)
- ? GNUNET_PQ_query_param_null ()
- : TALER_PQ_query_param_json (deposit->extension_details),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("conflicted",
- in_conflict),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- exchange_timestamp),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_deposit",
- params,
- rs);
-}
-
-
-/**
- * Perform melt operation, checking for sufficient balance
- * of the coin and possibly persisting the melt details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param rms client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
- * @param[in,out] refresh refresh operation details; the noreveal_index
- * is set in case the coin was already melted before
- * @param known_coin_id row of the coin in the known_coins table
- * @param[in,out] zombie_required true if the melt must only succeed if the coin is a zombie, set to false if the requirement was satisfied
- * @param[out] balance_ok set to true if the balance was sufficient
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_melt (
- void *cls,
- const struct TALER_RefreshMasterSecretP *rms,
- struct TALER_EXCHANGEDB_Refresh *refresh,
- uint64_t known_coin_id,
- bool *zombie_required,
- bool *balance_ok)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- NULL == rms
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_auto_from_type (rms),
- TALER_PQ_query_param_amount (&refresh->amount_with_fee),
- GNUNET_PQ_query_param_auto_from_type (&refresh->rc),
- GNUNET_PQ_query_param_auto_from_type (&refresh->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&refresh->coin_sig),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_uint32 (&refresh->noreveal_index),
- GNUNET_PQ_query_param_bool (*zombie_required),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("zombie_required",
- zombie_required),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_uint32 ("noreveal_index",
- &refresh->noreveal_index),
- &is_null),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_melt",
- params,
- rs);
- if (is_null)
- refresh->noreveal_index = UINT32_MAX; /* set to very invalid value */
- return qs;
-}
-
-
-/**
- * Perform refund operation, checking for sufficient deposits
- * of the coin and possibly persisting the refund details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param refund refund operation details
- * @param deposit_fee deposit fee applicable for the coin, possibly refunded
- * @param known_coin_id row of the coin in the known_coins table
- * @param[out] not_found set if the deposit was not found
- * @param[out] refund_ok set if the refund succeeded (below deposit amount)
- * @param[out] gone if the merchant was already paid
- * @param[out] conflict set if the refund ID was re-used
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_refund (
- void *cls,
- const struct TALER_EXCHANGEDB_Refund *refund,
- const struct TALER_Amount *deposit_fee,
- uint64_t known_coin_id,
- bool *not_found,
- bool *refund_ok,
- bool *gone,
- bool *conflict)
-{
- struct PostgresClosure *pg = cls;
- uint64_t deposit_shard = compute_shard (&refund->details.merchant_pub);
- struct TALER_Amount amount_without_fee;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (&refund->details.refund_amount),
- TALER_PQ_query_param_amount (&amount_without_fee),
- TALER_PQ_query_param_amount (deposit_fee),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
- GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
- GNUNET_PQ_query_param_uint64 (&deposit_shard),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("not_found",
- not_found),
- GNUNET_PQ_result_spec_bool ("refund_ok",
- refund_ok),
- GNUNET_PQ_result_spec_bool ("gone",
- gone),
- GNUNET_PQ_result_spec_bool ("conflict",
- conflict),
- GNUNET_PQ_result_spec_end
- };
-
- if (0 >
- TALER_amount_subtract (&amount_without_fee,
- &refund->details.refund_amount,
- &refund->details.refund_fee))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_refund",
- params,
- rs);
-}
-
-
-/**
- * Perform recoup operation, checking for sufficient deposits
- * of the coin and possibly persisting the recoup details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve_pub public key of the reserve to credit
- * @param reserve_out_serial_id row in the reserves_out table justifying the recoup
- * @param coin_bks coin blinding key secret to persist
- * @param coin_pub public key of the coin being recouped
- * @param known_coin_id row of the @a coin_pub in the known_coins table
- * @param coin_sig signature of the coin requesting the recoup
- * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed
- * @param[out] recoup_ok set if the recoup succeeded (balance ok)
- * @param[out] internal_failure set on internal failures
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_recoup (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t reserve_out_serial_id,
- const union TALER_DenominationBlindingKeyP *coin_bks,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t known_coin_id,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- struct GNUNET_TIME_Timestamp *recoup_timestamp,
- bool *recoup_ok,
- bool *internal_failure)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Timestamp reserve_gc
- = GNUNET_TIME_relative_to_timestamp (pg->legal_reserve_expiration_time);
- struct GNUNET_TIME_Timestamp reserve_expiration
- = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_uint64 (&reserve_out_serial_id),
- GNUNET_PQ_query_param_auto_from_type (coin_bks),
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (coin_sig),
- GNUNET_PQ_query_param_timestamp (&reserve_gc),
- GNUNET_PQ_query_param_timestamp (&reserve_expiration),
- GNUNET_PQ_query_param_timestamp (recoup_timestamp),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- recoup_timestamp),
- &is_null),
- GNUNET_PQ_result_spec_bool ("recoup_ok",
- recoup_ok),
- GNUNET_PQ_result_spec_bool ("internal_failure",
- internal_failure),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_recoup",
- params,
- rs);
-}
-
-
-/**
- * Perform recoup-refresh operation, checking for sufficient deposits of the
- * coin and possibly persisting the recoup-refresh details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param old_coin_pub public key of the old coin to credit
- * @param rrc_serial row in the refresh_revealed_coins table justifying the recoup-refresh
- * @param coin_bks coin blinding key secret to persist
- * @param coin_pub public key of the coin being recouped
- * @param known_coin_id row of the @a coin_pub in the known_coins table
- * @param coin_sig signature of the coin requesting the recoup
- * @param[in,out] recoup_timestamp recoup timestamp, set if recoup existed
- * @param[out] recoup_ok set if the recoup-refresh succeeded (balance ok)
- * @param[out] internal_failure set on internal failures
- * @return query execution status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_recoup_refresh (
- void *cls,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- uint64_t rrc_serial,
- const union TALER_DenominationBlindingKeyP *coin_bks,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t known_coin_id,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- struct GNUNET_TIME_Timestamp *recoup_timestamp,
- bool *recoup_ok,
- bool *internal_failure)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (old_coin_pub),
- GNUNET_PQ_query_param_uint64 (&rrc_serial),
- GNUNET_PQ_query_param_auto_from_type (coin_bks),
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_uint64 (&known_coin_id),
- GNUNET_PQ_query_param_auto_from_type (coin_sig),
- GNUNET_PQ_query_param_timestamp (recoup_timestamp),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- recoup_timestamp),
- &is_null),
- GNUNET_PQ_result_spec_bool ("recoup_ok",
- recoup_ok),
- GNUNET_PQ_result_spec_bool ("internal_failure",
- internal_failure),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_recoup_refresh",
- params,
- rs);
-}
-
-
-/**
- * Closure for callbacks invoked via #postgres_get_reserve_history.
- */
-struct ReserveHistoryContext
-{
-
- /**
- * Which reserve are we building the history for?
- */
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- /**
- * Where we build the history.
- */
- struct TALER_EXCHANGEDB_ReserveHistory *rh;
-
- /**
- * Tail of @e rh list.
- */
- struct TALER_EXCHANGEDB_ReserveHistory *rh_tail;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Sum of all credit transactions.
- */
- struct TALER_Amount balance_in;
-
- /**
- * Sum of all debit transactions.
- */
- struct TALER_Amount balance_out;
-
- /**
- * Set to #GNUNET_SYSERR on serious internal errors during
- * the callbacks.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Append and return a fresh element to the reserve
- * history kept in @a rhc.
- *
- * @param rhc where the history is kept
- * @return the fresh element that was added
- */
-static struct TALER_EXCHANGEDB_ReserveHistory *
-append_rh (struct ReserveHistoryContext *rhc)
-{
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- tail = GNUNET_new (struct TALER_EXCHANGEDB_ReserveHistory);
- if (NULL != rhc->rh_tail)
- {
- rhc->rh_tail->next = tail;
- rhc->rh_tail = tail;
- }
- else
- {
- rhc->rh_tail = tail;
- rhc->rh = tail;
- }
- return tail;
-}
-
-
-/**
- * Add bank transfers to result set for #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_bank_to_exchange (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_BankTransfer *bt;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- bt = GNUNET_new (struct TALER_EXCHANGEDB_BankTransfer);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wire_reference",
- &bt->wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
- &bt->amount),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &bt->execution_date),
- GNUNET_PQ_result_spec_string ("sender_account_details",
- &bt->sender_account_details),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (bt);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- }
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_in,
- &rhc->balance_in,
- &bt->amount));
- bt->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE;
- tail->details.bank = bt;
- } /* end of 'while (0 < rows)' */
-}
-
-
-/**
- * Add coin withdrawals to result set for #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_withdraw_coin (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_CollectableBlindcoin *cbc;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- cbc = GNUNET_new (struct TALER_EXCHANGEDB_CollectableBlindcoin);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &cbc->h_coin_envelope),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &cbc->denom_pub_hash),
- TALER_PQ_result_spec_blinded_denom_sig ("denom_sig",
- &cbc->sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &cbc->reserve_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &cbc->amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &cbc->withdraw_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (cbc);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- }
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_out,
- &rhc->balance_out,
- &cbc->amount_with_fee));
- cbc->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_WITHDRAW_COIN;
- tail->details.withdraw = cbc;
- }
-}
-
-
-/**
- * Add recoups to result set for #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_recoup (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_Recoup *recoup;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- recoup = GNUNET_new (struct TALER_EXCHANGEDB_Recoup);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &recoup->value),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &recoup->coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &recoup->coin_blind),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &recoup->coin_sig),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &recoup->timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &recoup->coin.denom_pub_hash),
- TALER_PQ_result_spec_denom_sig (
- "denom_sig",
- &recoup->coin.denom_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (recoup);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- }
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_in,
- &rhc->balance_in,
- &recoup->value));
- recoup->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_RECOUP_COIN;
- tail->details.recoup = recoup;
- } /* end of 'while (0 < rows)' */
-}
-
-
-/**
- * Add exchange-to-bank transfers to result set for
- * #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_exchange_to_bank (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_ClosingTransfer *closing;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- closing = GNUNET_new (struct TALER_EXCHANGEDB_ClosingTransfer);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &closing->amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &closing->closing_fee),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &closing->execution_date),
- GNUNET_PQ_result_spec_string ("receiver_account",
- &closing->receiver_account_details),
- GNUNET_PQ_result_spec_auto_from_type ("wtid",
- &closing->wtid),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (closing);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- }
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_out,
- &rhc->balance_out,
- &closing->amount));
- closing->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK;
- tail->details.closing = closing;
- } /* end of 'while (0 < rows)' */
-}
-
-
-/**
- * Add purse merge transfers to result set for
- * #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_p2p_merge (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_PurseMerge *merge;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- merge = GNUNET_new (struct TALER_EXCHANGEDB_PurseMerge);
- {
- uint32_t flags32;
- struct TALER_Amount balance;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &merge->purse_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &merge->amount_with_fee),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- &merge->merge_timestamp),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- &merge->purse_expiration),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- &merge->min_age),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &merge->h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
- &merge->merge_pub),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &merge->purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &merge->reserve_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (merge);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- merge->flags = (enum TALER_WalletAccountMergeFlags) flags32;
- if ( (! GNUNET_TIME_absolute_is_future (
- merge->merge_timestamp.abs_time)) &&
- (-1 != TALER_amount_cmp (&balance,
- &merge->amount_with_fee)) )
- merge->merged = true;
- }
- if (merge->merged)
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_in,
- &rhc->balance_in,
- &merge->amount_with_fee));
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_out,
- &rhc->balance_out,
- &merge->purse_fee));
- merge->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_PURSE_MERGE;
- tail->details.merge = merge;
- }
-}
-
-
-/**
- * Add paid for history requests to result set for
- * #postgres_get_reserve_history.
- *
- * @param cls a `struct ReserveHistoryContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-add_history_requests (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveHistoryContext *rhc = cls;
- struct PostgresClosure *pg = rhc->pg;
-
- while (0 < num_results)
- {
- struct TALER_EXCHANGEDB_HistoryRequest *history;
- struct TALER_EXCHANGEDB_ReserveHistory *tail;
-
- history = GNUNET_new (struct TALER_EXCHANGEDB_HistoryRequest);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &history->history_fee),
- GNUNET_PQ_result_spec_timestamp ("request_timestamp",
- &history->request_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &history->reserve_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- GNUNET_free (history);
- rhc->status = GNUNET_SYSERR;
- return;
- }
- }
- GNUNET_assert (0 <=
- TALER_amount_add (&rhc->balance_out,
- &rhc->balance_out,
- &history->history_fee));
- history->reserve_pub = *rhc->reserve_pub;
- tail = append_rh (rhc);
- tail->type = TALER_EXCHANGEDB_RO_HISTORY_REQUEST;
- tail->details.history = history;
- }
-}
-
-
-/**
- * Get all of the transaction history associated with the specified
- * reserve.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param[out] balance set to the reserve balance
- * @param[out] rhp set to known transaction history (NULL if reserve is unknown)
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_history (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance,
- struct TALER_EXCHANGEDB_ReserveHistory **rhp)
-{
- struct PostgresClosure *pg = cls;
- struct ReserveHistoryContext rhc;
- struct
- {
- /**
- * Name of the prepared statement to run.
- */
- const char *statement;
- /**
- * Function to use to process the results.
- */
- GNUNET_PQ_PostgresResultHandler cb;
- } work[] = {
- /** #TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE */
- { "reserves_in_get_transactions",
- add_bank_to_exchange },
- /** #TALER_EXCHANGEDB_RO_WITHDRAW_COIN */
- { "get_reserves_out",
- &add_withdraw_coin },
- /** #TALER_EXCHANGEDB_RO_RECOUP_COIN */
- { "recoup_by_reserve",
- &add_recoup },
- /** #TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK */
- { "close_by_reserve",
- &add_exchange_to_bank },
- /** #TALER_EXCHANGEDB_RO_PURSE_MERGE */
- { "merge_by_reserve",
- &add_p2p_merge },
- /** #TALER_EXCHANGEDB_RO_HISTORY_REQUEST */
- { "history_by_reserve",
- &add_history_requests },
- /* List terminator */
- { NULL,
- NULL }
- };
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
-
- rhc.reserve_pub = reserve_pub;
- rhc.rh = NULL;
- rhc.rh_tail = NULL;
- rhc.pg = pg;
- rhc.status = GNUNET_OK;
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &rhc.balance_in));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &rhc.balance_out));
- qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */
- for (unsigned int i = 0; NULL != work[i].cb; i++)
- {
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- work[i].statement,
- params,
- work[i].cb,
- &rhc);
- if ( (0 > qs) ||
- (GNUNET_OK != rhc.status) )
- break;
- }
- if ( (qs < 0) ||
- (rhc.status != GNUNET_OK) )
- {
- common_free_reserve_history (cls,
- rhc.rh);
- rhc.rh = NULL;
- if (qs >= 0)
- {
- /* status == SYSERR is a very hard error... */
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- *rhp = rhc.rh;
- GNUNET_assert (0 <=
- TALER_amount_subtract (balance,
- &rhc.balance_in,
- &rhc.balance_out));
- return qs;
-}
-
-
-/**
- * Get a truncated transaction history associated with the specified
- * reserve.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param[out] balance set to the reserve balance
- * @param[out] rhp set to known transaction history (NULL if reserve is unknown)
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_status (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance,
- struct TALER_EXCHANGEDB_ReserveHistory **rhp)
-{
- struct PostgresClosure *pg = cls;
- struct ReserveHistoryContext rhc;
- struct
- {
- /**
- * Name of the prepared statement to run.
- */
- const char *statement;
- /**
- * Function to use to process the results.
- */
- GNUNET_PQ_PostgresResultHandler cb;
- } work[] = {
- /** #TALER_EXCHANGEDB_RO_BANK_TO_EXCHANGE */
- { "reserves_in_get_transactions",
- add_bank_to_exchange },
- /** #TALER_EXCHANGEDB_RO_WITHDRAW_COIN */
- { "get_reserves_out",
- &add_withdraw_coin },
- /** #TALER_EXCHANGEDB_RO_RECOUP_COIN */
- { "recoup_by_reserve",
- &add_recoup },
- /** #TALER_EXCHANGEDB_RO_EXCHANGE_TO_BANK */
- { "close_by_reserve",
- &add_exchange_to_bank },
- /** #TALER_EXCHANGEDB_RO_PURSE_MERGE */
- { "merge_by_reserve",
- &add_p2p_merge },
- /** #TALER_EXCHANGEDB_RO_HISTORY_REQUEST */
- { "history_by_reserve",
- &add_history_requests },
- /* List terminator */
- { NULL,
- NULL }
- };
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
-
- /* FIXME: actually implement reserve history truncation logic! */
- rhc.reserve_pub = reserve_pub;
- rhc.rh = NULL;
- rhc.rh_tail = NULL;
- rhc.pg = pg;
- rhc.status = GNUNET_OK;
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &rhc.balance_in));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &rhc.balance_out));
- qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS; /* make static analysis happy */
- for (unsigned int i = 0; NULL != work[i].cb; i++)
- {
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- work[i].statement,
- params,
- work[i].cb,
- &rhc);
- if ( (0 > qs) ||
- (GNUNET_OK != rhc.status) )
- break;
- }
- if ( (qs < 0) ||
- (rhc.status != GNUNET_OK) )
- {
- common_free_reserve_history (cls,
- rhc.rh);
- rhc.rh = NULL;
- if (qs >= 0)
- {
- /* status == SYSERR is a very hard error... */
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- *rhp = rhc.rh;
- GNUNET_assert (0 <=
- TALER_amount_subtract (balance,
- &rhc.balance_in,
- &rhc.balance_out));
- return qs;
-}
-
-
-/**
- * Get the balance of the specified reserve.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param[out] balance set to the reserve balance
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_balance (void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
- balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_reserve_balance",
- params,
- rs);
-}
-
-
-/**
- * Check if we have the specified deposit already in the database.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param h_contract_terms contract to check for
- * @param h_wire wire hash to check for
- * @param coin_pub public key of the coin to check for
- * @param merchant merchant public key to check for
- * @param refund_deadline expected refund deadline
- * @param[out] deposit_fee set to the deposit fee the exchange charged
- * @param[out] exchange_timestamp set to the time when the exchange received the deposit
- * @return 1 if we know this operation,
- * 0 if this exact deposit is unknown to us,
- * otherwise transaction error status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_have_deposit2 (
- void *cls,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant,
- struct GNUNET_TIME_Timestamp refund_deadline,
- struct TALER_Amount *deposit_fee,
- struct GNUNET_TIME_Timestamp *exchange_timestamp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (merchant),
- GNUNET_PQ_query_param_end
- };
- struct TALER_EXCHANGEDB_Deposit deposit2;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit2.amount_with_fee),
- GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
- &deposit2.timestamp),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- exchange_timestamp),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &deposit2.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deposit2.wire_deadline),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &deposit2.wire_salt),
- GNUNET_PQ_result_spec_string ("receiver_wire_account",
- &deposit2.receiver_wire_account),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_MerchantWireHashP h_wire2;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting deposits for coin %s\n",
- TALER_B2S (coin_pub));
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_deposit",
- params,
- rs);
- if (0 >= qs)
- return qs;
- TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account,
- &deposit2.wire_salt,
- &h_wire2);
- GNUNET_free (deposit2.receiver_wire_account);
- /* Now we check that the other information in @a deposit
- also matches, and if not report inconsistencies. */
- if ( (GNUNET_TIME_timestamp_cmp (refund_deadline,
- !=,
- deposit2.refund_deadline)) ||
- (0 != GNUNET_memcmp (h_wire,
- &h_wire2) ) )
- {
- /* Inconsistencies detected! Does not match! (We might want to
- expand the API with a 'get_deposit' function to return the
- original transaction details to be used for an error message
- in the future!) FIXME #3838 */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-
-/**
- * Aggregate all matching deposits for @a h_payto and
- * @a merchant_pub, returning the total amounts.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto destination of the wire transfer
- * @param merchant_pub public key of the merchant
- * @param wtid wire transfer ID to set for the aggregate
- * @param[out] total set to the sum of the total deposits minus applicable deposit fees and refunds
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_aggregate (
- void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_Amount *total)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = {0};
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
- uint64_t sum_deposit_value;
- uint64_t sum_deposit_frac;
- uint64_t sum_refund_value;
- uint64_t sum_refund_frac;
- uint64_t sum_fee_value;
- uint64_t sum_fee_frac;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("sum_deposit_value",
- &sum_deposit_value),
- GNUNET_PQ_result_spec_uint64 ("sum_deposit_fraction",
- &sum_deposit_frac),
- GNUNET_PQ_result_spec_uint64 ("sum_refund_value",
- &sum_refund_value),
- GNUNET_PQ_result_spec_uint64 ("sum_refund_fraction",
- &sum_refund_frac),
- GNUNET_PQ_result_spec_uint64 ("sum_fee_value",
- &sum_fee_value),
- GNUNET_PQ_result_spec_uint64 ("sum_fee_fraction",
- &sum_fee_frac),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_Amount sum_deposit;
- struct TALER_Amount sum_refund;
- struct TALER_Amount sum_fee;
- struct TALER_Amount delta;
-
- now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
- pg->aggregator_shift);
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "aggregate",
- params,
- rs);
- if (qs < 0)
- {
- GNUNET_assert (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- {
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- total));
- return qs;
- }
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_deposit));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_refund));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &sum_fee));
- sum_deposit.value = sum_deposit_frac / TALER_AMOUNT_FRAC_BASE
- + sum_deposit_value;
- sum_deposit.fraction = sum_deposit_frac % TALER_AMOUNT_FRAC_BASE;
- sum_refund.value = sum_refund_frac / TALER_AMOUNT_FRAC_BASE
- + sum_refund_value;
- sum_refund.fraction = sum_refund_frac % TALER_AMOUNT_FRAC_BASE;
- sum_fee.value = sum_fee_frac / TALER_AMOUNT_FRAC_BASE
- + sum_fee_value;
- sum_fee.fraction = sum_fee_frac % TALER_AMOUNT_FRAC_BASE; \
- GNUNET_assert (0 <=
- TALER_amount_subtract (&delta,
- &sum_deposit,
- &sum_refund));
- GNUNET_assert (0 <=
- TALER_amount_subtract (total,
- &delta,
- &sum_fee));
- return qs;
-}
-
-
-/**
- * Create a new entry in the transient aggregation table.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto destination of the wire transfer
- * @param exchange_account_section exchange account to use
- * @param wtid the raw wire transfer identifier to be used
- * @param total amount to be wired in the future
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_create_aggregation_transient (
- void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const char *exchange_account_section,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_Amount *total)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (total),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (exchange_account_section),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "create_aggregation_transient",
- params);
-}
-
-
-/**
- * Find existing entry in the transient aggregation table.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto destination of the wire transfer
- * @param exchange_account_section exchange account to use
- * @param[out] wtid set to the raw wire transfer identifier to be used
- * @param[out] total existing amount to be wired in the future
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_aggregation_transient (
- void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const char *exchange_account_section,
- struct TALER_WireTransferIdentifierRawP *wtid,
- struct TALER_Amount *total)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (exchange_account_section),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- total),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- wtid),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_aggregation_transient",
- params,
- rs);
-}
-
-
-/**
- * Update existing entry in the transient aggregation table.
- * @a h_payto is only needed for query performance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto destination of the wire transfer
- * @param wtid the raw wire transfer identifier to update
- * @param total new total amount to be wired in the future
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_aggregation_transient (
- void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_Amount *total)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- TALER_PQ_query_param_amount (total),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_aggregation_transient",
- params);
-}
-
-
-/**
- * Delete existing entry in the transient aggregation table.
- * @a h_payto is only needed for query performance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto destination of the wire transfer
- * @param wtid the raw wire transfer identifier to update
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_delete_aggregation_transient (
- void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const struct TALER_WireTransferIdentifierRawP *wtid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "delete_aggregation_transient",
- params);
-}
-
-
-/**
- * Obtain information about deposits that are ready to be executed. Such
- * deposits must not be marked as "done", the execution time must be
- * in the past, and the KYC status must be 'ok'.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param start_shard_row minimum shard row to select
- * @param end_shard_row maximum shard row to select (inclusive)
- * @param kyc_off true if we should not check the KYC status because
- * this exchange does not need/support KYC checks.
- * @param[out] merchant_pub set to the public key of a merchant with a ready deposit
- * @param[out] payto_uri set to the account of the merchant, to be freed by caller
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_ready_deposit (void *cls,
- uint64_t start_shard_row,
- uint64_t end_shard_row,
- bool kyc_off,
- struct TALER_MerchantPublicKeyP *merchant_pub,
- char **payto_uri)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = {0};
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_uint64 (&start_shard_row),
- GNUNET_PQ_query_param_uint64 (&end_shard_row),
- GNUNET_PQ_query_param_bool (kyc_off),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- merchant_pub),
- GNUNET_PQ_result_spec_string ("payto_uri",
- payto_uri),
- GNUNET_PQ_result_spec_end
- };
-
- now = GNUNET_TIME_absolute_round_down (GNUNET_TIME_absolute_get (),
- pg->aggregator_shift);
- GNUNET_assert (start_shard_row < end_shard_row);
- GNUNET_assert (end_shard_row <= INT32_MAX);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Finding ready deposits by deadline %s (%llu)\n",
- GNUNET_TIME_absolute2s (now),
- (unsigned long long) now.abs_value_us);
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "deposits_get_ready",
- params,
- rs);
-}
-
-
-/**
- * Retrieve the record for a known coin.
- *
- * @param cls the plugin closure
- * @param coin_pub the public key of the coin to search for
- * @param coin_info place holder for the returned coin information object
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_known_coin (void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- struct TALER_CoinPublicInfo *coin_info)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &coin_info->denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &coin_info->h_age_commitment),
- &coin_info->no_age_commitment),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &coin_info->denom_sig),
- GNUNET_PQ_result_spec_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting known coin data for coin %s\n",
- TALER_B2S (coin_pub));
- coin_info->coin_pub = *coin_pub;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_known_coin",
- params,
- rs);
-}
-
-
-/**
- * Retrieve the denomination of a known coin.
- *
- * @param cls the plugin closure
- * @param coin_pub the public key of the coin to search for
- * @param[out] known_coin_id set to the ID of the coin in the known_coins table
- * @param[out] denom_hash where to store the hash of the coins denomination
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_coin_denomination (
- void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t *known_coin_id,
- struct TALER_DenominationHashP *denom_hash)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- denom_hash),
- GNUNET_PQ_result_spec_uint64 ("known_coin_id",
- known_coin_id),
- GNUNET_PQ_result_spec_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting coin denomination of coin %s\n",
- TALER_B2S (coin_pub));
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_coin_denomination",
- params,
- rs);
-}
-
-
-/**
- * Count the number of known coins by denomination.
- *
- * @param cls database connection plugin state
- * @param denom_pub_hash denomination to count by
- * @return number of coins if non-negative, otherwise an `enum GNUNET_DB_QueryStatus`
- */
-static long long
-postgres_count_known_coins (void *cls,
- const struct
- TALER_DenominationHashP *denom_pub_hash)
-{
- struct PostgresClosure *pg = cls;
- uint64_t count;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("count",
- &count),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "count_known_coins",
- params,
- rs);
- if (0 > qs)
- return (long long) qs;
- return (long long) count;
-}
-
-
-/**
- * Make sure the given @a coin is known to the database.
- *
- * @param cls database connection plugin state
- * @param coin the coin that must be made known
- * @param[out] known_coin_id set to the unique row of the coin
- * @param[out] denom_hash set to the denomination hash of the existing
- * coin (for conflict error reporting)
- * @param[out] h_age_commitment set to the conflicting age commitment hash on conflict
- * @return database transaction status, non-negative on success
- */
-static enum TALER_EXCHANGEDB_CoinKnownStatus
-postgres_ensure_coin_known (void *cls,
- const struct TALER_CoinPublicInfo *coin,
- uint64_t *known_coin_id,
- struct TALER_DenominationHashP *denom_hash,
- struct TALER_AgeCommitmentHash *h_age_commitment)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- bool existed;
- bool is_denom_pub_hash_null = false;
- bool is_age_hash_null = false;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&coin->coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&coin->denom_pub_hash),
- GNUNET_PQ_query_param_auto_from_type (&coin->h_age_commitment),
- TALER_PQ_query_param_denom_sig (&coin->denom_sig),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("existed",
- &existed),
- GNUNET_PQ_result_spec_uint64 ("known_coin_id",
- known_coin_id),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- denom_hash),
- &is_denom_pub_hash_null),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- h_age_commitment),
- &is_age_hash_null),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "insert_known_coin",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- return TALER_EXCHANGEDB_CKS_HARD_FAIL;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- return TALER_EXCHANGEDB_CKS_SOFT_FAIL;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- GNUNET_break (0); /* should be impossible */
- return TALER_EXCHANGEDB_CKS_HARD_FAIL;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- if (! existed)
- return TALER_EXCHANGEDB_CKS_ADDED;
- break; /* continued below */
- }
-
- if ( (! is_denom_pub_hash_null) &&
- (0 != GNUNET_memcmp (&denom_hash->hash,
- &coin->denom_pub_hash.hash)) )
- {
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_DENOM_CONFLICT;
- }
-
- if ( (! is_age_hash_null) &&
- (0 != GNUNET_memcmp (h_age_commitment,
- &coin->h_age_commitment)) )
- {
- GNUNET_break (GNUNET_is_zero (h_age_commitment));
- GNUNET_break_op (0);
- return TALER_EXCHANGEDB_CKS_AGE_CONFLICT;
- }
-
- return TALER_EXCHANGEDB_CKS_PRESENT;
-}
-
-
-/**
- * Insert information about deposited coin into the database.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param exchange_timestamp time the exchange received the deposit request
- * @param deposit deposit information to store
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_deposit (void *cls,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- const struct TALER_EXCHANGEDB_Deposit *deposit)
-{
- struct PostgresClosure *pg = cls;
- struct TALER_EXCHANGEDB_KycStatus kyc;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_PaytoHashP h_payto;
-
- qs = inselect_account_kyc_status (pg,
- deposit->receiver_wire_account,
- &h_payto,
- &kyc);
- if (qs <= 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- if (GNUNET_TIME_timestamp_cmp (deposit->wire_deadline,
- <,
- deposit->refund_deadline))
- {
- GNUNET_break (0);
- }
- {
- uint64_t shard = compute_shard (&deposit->merchant_pub);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
- TALER_PQ_query_param_amount (&deposit->amount_with_fee),
- GNUNET_PQ_query_param_timestamp (&deposit->timestamp),
- GNUNET_PQ_query_param_timestamp (&deposit->refund_deadline),
- GNUNET_PQ_query_param_timestamp (&deposit->wire_deadline),
- GNUNET_PQ_query_param_auto_from_type (&deposit->merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (&deposit->h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (&deposit->wire_salt),
- GNUNET_PQ_query_param_auto_from_type (&h_payto),
- GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
- GNUNET_PQ_query_param_timestamp (&exchange_timestamp),
- GNUNET_PQ_query_param_uint64 (&shard),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (shard <= INT32_MAX);
- GNUNET_log (
- GNUNET_ERROR_TYPE_INFO,
- "Inserting deposit to be executed at %s (%llu/%llu)\n",
- GNUNET_TIME_timestamp2s (deposit->wire_deadline),
- (unsigned long long) deposit->wire_deadline.abs_time.abs_value_us,
- (unsigned long long) deposit->refund_deadline.abs_time.abs_value_us);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_deposit",
- params);
- }
-}
-
-
-/**
- * Insert information about refunded coin into the database.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param refund refund information to store
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_refund (void *cls,
- const struct TALER_EXCHANGEDB_Refund *refund)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (&refund->coin.coin_pub),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.merchant_sig),
- GNUNET_PQ_query_param_auto_from_type (&refund->details.h_contract_terms),
- GNUNET_PQ_query_param_uint64 (&refund->details.rtransaction_id),
- TALER_PQ_query_param_amount (&refund->details.refund_amount),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_assert (GNUNET_YES ==
- TALER_amount_cmp_currency (&refund->details.refund_amount,
- &refund->details.refund_fee));
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_refund",
- params);
-}
-
-
-/**
- * Closure for #get_refunds_cb().
- */
-struct SelectRefundContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_RefundCoinCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- int status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct SelectRefundContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-get_refunds_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct SelectRefundContext *srctx = cls;
- struct PostgresClosure *pg = srctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_Amount amount_with_fee;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- srctx->status = GNUNET_SYSERR;
- return;
- }
- if (GNUNET_OK !=
- srctx->cb (srctx->cb_cls,
- &amount_with_fee))
- return;
- }
-}
-
-
-/**
- * Select refunds by @a coin_pub, @a merchant_pub and @a h_contract.
- *
- * @param cls closure of plugin
- * @param coin_pub coin to get refunds for
- * @param merchant_pub merchant to get refunds for
- * @param h_contract contract (hash) to get refunds for
- * @param cb function to call for each refund found
- * @param cb_cls closure for @a cb
- * @return query result status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_refunds_by_coin (
- void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_PrivateContractHashP *h_contract,
- TALER_EXCHANGEDB_RefundCoinCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract),
- GNUNET_PQ_query_param_end
- };
- struct SelectRefundContext srctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_refunds_by_coin_and_contract",
- params,
- &get_refunds_cb,
- &srctx);
- if (GNUNET_SYSERR == srctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Lookup refresh melt commitment data under the given @a rc.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param rc commitment hash to use to locate the operation
- * @param[out] melt where to store the result; note that
- * melt->session.coin.denom_sig will be set to NULL
- * and is not fetched by this routine (as it is not needed by the client)
- * @param[out] melt_serial_id set to the row ID of @a rc in the refresh_commitments table
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_melt (void *cls,
- const struct TALER_RefreshCommitmentP *rc,
- struct TALER_EXCHANGEDB_Melt *melt,
- uint64_t *melt_serial_id)
-{
- struct PostgresClosure *pg = cls;
- bool h_age_commitment_is_null;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (rc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &melt->session.coin.
- denom_pub_hash),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &melt->melt_fee),
- GNUNET_PQ_result_spec_uint32 ("noreveal_index",
- &melt->session.noreveal_index),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &melt->session.coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &melt->session.coin_sig),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &melt->session.coin.h_age_commitment),
- &h_age_commitment_is_null),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &melt->session.amount_with_fee),
- GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
- melt_serial_id),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- memset (&melt->session.coin.denom_sig,
- 0,
- sizeof (melt->session.coin.denom_sig));
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_melt",
- params,
- rs);
- if (h_age_commitment_is_null)
- memset (&melt->session.coin.h_age_commitment,
- 0,
- sizeof(melt->session.coin.h_age_commitment));
-
- melt->session.rc = *rc;
- return qs;
-}
-
-
-/**
- * Store in the database which coin(s) the wallet wanted to create
- * in a given refresh operation and all of the other information
- * we learned or created in the /refresh/reveal step.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param melt_serial_id row ID of the commitment / melt operation in refresh_commitments
- * @param num_rrcs number of coins to generate, size of the @a rrcs array
- * @param rrcs information about the new coins
- * @param num_tprivs number of entries in @a tprivs, should be #TALER_CNC_KAPPA - 1
- * @param tprivs transfer private keys to store
- * @param tp public key to store
- * @return query status for the transaction
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_refresh_reveal (
- void *cls,
- uint64_t melt_serial_id,
- uint32_t num_rrcs,
- const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs,
- unsigned int num_tprivs,
- const struct TALER_TransferPrivateKeyP *tprivs,
- const struct TALER_TransferPublicKeyP *tp)
-{
- struct PostgresClosure *pg = cls;
-
- if (TALER_CNC_KAPPA != num_tprivs + 1)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- for (uint32_t i = 0; i<num_rrcs; i++)
- {
- const struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &rrcs[i];
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&melt_serial_id),
- GNUNET_PQ_query_param_uint32 (&i),
- GNUNET_PQ_query_param_auto_from_type (&rrc->orig_coin_link_sig),
- GNUNET_PQ_query_param_auto_from_type (&rrc->h_denom_pub),
- TALER_PQ_query_param_blinded_planchet (&rrc->blinded_planchet),
- TALER_PQ_query_param_exchange_withdraw_values (&rrc->exchange_vals),
- GNUNET_PQ_query_param_auto_from_type (&rrc->coin_envelope_hash),
- TALER_PQ_query_param_blinded_denom_sig (&rrc->coin_sig),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_refresh_revealed_coin",
- params);
- if (0 > qs)
- return qs;
- }
-
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&melt_serial_id),
- GNUNET_PQ_query_param_auto_from_type (tp),
- GNUNET_PQ_query_param_fixed_size (
- tprivs,
- num_tprivs * sizeof (struct TALER_TransferPrivateKeyP)),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_refresh_transfer_keys",
- params);
- }
-}
-
-
-/**
- * Context where we aggregate data from the database.
- * Closure for #add_revealed_coins().
- */
-struct GetRevealContext
-{
- /**
- * Array of revealed coins we obtained from the DB.
- */
- struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrcs;
-
- /**
- * Length of the @a rrcs array.
- */
- unsigned int rrcs_len;
-
- /**
- * Set to an error code if we ran into trouble.
- */
- enum GNUNET_DB_QueryStatus qs;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct GetRevealContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_revealed_coins (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetRevealContext *grctx = cls;
-
- if (0 == num_results)
- return;
- grctx->rrcs = GNUNET_new_array (num_results,
- struct TALER_EXCHANGEDB_RefreshRevealedCoin);
- grctx->rrcs_len = num_results;
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint32_t off;
- struct GNUNET_PQ_ResultSpec rso[] = {
- GNUNET_PQ_result_spec_uint32 ("freshcoin_index",
- &off),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rso,
- i))
- {
- GNUNET_break (0);
- grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- if (off >= num_results)
- {
- GNUNET_break (0);
- grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- {
- struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx->rrcs[off];
- struct GNUNET_PQ_ResultSpec rsi[] = {
- /* NOTE: freshcoin_index selected and discarded here... */
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &rrc->h_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("link_sig",
- &rrc->orig_coin_link_sig),
- GNUNET_PQ_result_spec_auto_from_type ("h_coin_ev",
- &rrc->coin_envelope_hash),
- TALER_PQ_result_spec_blinded_planchet ("coin_ev",
- &rrc->blinded_planchet),
- TALER_PQ_result_spec_exchange_withdraw_values ("ewv",
- &rrc->exchange_vals),
- TALER_PQ_result_spec_blinded_denom_sig ("ev_sig",
- &rrc->coin_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (TALER_DENOMINATION_INVALID != rrc->blinded_planchet.cipher)
- {
- /* duplicate offset, not allowed */
- GNUNET_break (0);
- grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rsi,
- i))
- {
- GNUNET_break (0);
- grctx->qs = GNUNET_DB_STATUS_HARD_ERROR;
- return;
- }
- }
- }
-}
-
-
-/**
- * Lookup in the database the coins that we want to
- * create in the given refresh operation.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param rc identify commitment and thus refresh operation
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_refresh_reveal (void *cls,
- const struct TALER_RefreshCommitmentP *rc,
- TALER_EXCHANGEDB_RefreshCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GetRevealContext grctx;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (rc),
- GNUNET_PQ_query_param_end
- };
-
- memset (&grctx,
- 0,
- sizeof (grctx));
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_refresh_revealed_coins",
- params,
- &add_revealed_coins,
- &grctx);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- case GNUNET_DB_STATUS_SOFT_ERROR:
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- goto cleanup;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- default: /* can have more than one result */
- break;
- }
- switch (grctx.qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- case GNUNET_DB_STATUS_SOFT_ERROR:
- goto cleanup;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: /* should be impossible */
- break;
- }
-
- /* Pass result back to application */
- cb (cb_cls,
- grctx.rrcs_len,
- grctx.rrcs);
-cleanup:
- for (unsigned int i = 0; i < grctx.rrcs_len; i++)
- {
- struct TALER_EXCHANGEDB_RefreshRevealedCoin *rrc = &grctx.rrcs[i];
-
- TALER_blinded_denom_sig_free (&rrc->coin_sig);
- TALER_blinded_planchet_free (&rrc->blinded_planchet);
- }
- GNUNET_free (grctx.rrcs);
- return qs;
-}
-
-
-/**
- * Closure for #add_ldl().
- */
-struct LinkDataContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_LinkCallback ldc;
-
- /**
- * Closure for @e ldc.
- */
- void *ldc_cls;
-
- /**
- * Last transfer public key for which we have information in @e last.
- * Only valid if @e last is non-NULL.
- */
- struct TALER_TransferPublicKeyP transfer_pub;
-
- /**
- * Link data for @e transfer_pub
- */
- struct TALER_EXCHANGEDB_LinkList *last;
-
- /**
- * Status, set to #GNUNET_SYSERR on errors,
- */
- int status;
-};
-
-
-/**
- * Free memory of the link data list.
- *
- * @param cls the @e cls of this struct with the plugin-specific state (unused)
- * @param ldl link data list to release
- */
-static void
-free_link_data_list (void *cls,
- struct TALER_EXCHANGEDB_LinkList *ldl)
-{
- struct TALER_EXCHANGEDB_LinkList *next;
-
- (void) cls;
- while (NULL != ldl)
- {
- next = ldl->next;
- TALER_denom_pub_free (&ldl->denom_pub);
- TALER_blinded_denom_sig_free (&ldl->ev_sig);
- GNUNET_free (ldl);
- ldl = next;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct LinkDataContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_ldl (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct LinkDataContext *ldctx = cls;
-
- for (int i = num_results - 1; i >= 0; i--)
- {
- struct TALER_EXCHANGEDB_LinkList *pos;
- struct TALER_TransferPublicKeyP transfer_pub;
-
- pos = GNUNET_new (struct TALER_EXCHANGEDB_LinkList);
- {
- struct TALER_BlindedPlanchet bp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("transfer_pub",
- &transfer_pub),
- GNUNET_PQ_result_spec_auto_from_type ("link_sig",
- &pos->orig_coin_link_sig),
- TALER_PQ_result_spec_blinded_denom_sig ("ev_sig",
- &pos->ev_sig),
- GNUNET_PQ_result_spec_uint32 ("freshcoin_index",
- &pos->coin_refresh_offset),
- TALER_PQ_result_spec_exchange_withdraw_values ("ewv",
- &pos->alg_values),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &pos->denom_pub),
- TALER_PQ_result_spec_blinded_planchet ("coin_ev",
- &bp),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (pos);
- ldctx->status = GNUNET_SYSERR;
- return;
- }
- if (TALER_DENOMINATION_CS == bp.cipher)
- {
- pos->nonce = bp.details.cs_blinded_planchet.nonce;
- pos->have_nonce = true;
- }
- TALER_blinded_planchet_free (&bp);
- }
- if ( (NULL != ldctx->last) &&
- (0 == GNUNET_memcmp (&transfer_pub,
- &ldctx->transfer_pub)) )
- {
- pos->next = ldctx->last;
- }
- else
- {
- if (NULL != ldctx->last)
- {
- ldctx->ldc (ldctx->ldc_cls,
- &ldctx->transfer_pub,
- ldctx->last);
- free_link_data_list (cls,
- ldctx->last);
- }
- ldctx->transfer_pub = transfer_pub;
- }
- ldctx->last = pos;
- }
-}
-
-
-/**
- * Obtain the link data of a coin, that is the encrypted link
- * information, the denomination keys and the signatures.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param coin_pub public key of the coin
- * @param ldc function to call for each session the coin was melted into
- * @param ldc_cls closure for @a tdc
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_link_data (void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- TALER_EXCHANGEDB_LinkCallback ldc,
- void *ldc_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
- struct LinkDataContext ldctx;
-
- ldctx.ldc = ldc;
- ldctx.ldc_cls = ldc_cls;
- ldctx.last = NULL;
- ldctx.status = GNUNET_OK;
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_link",
- params,
- &add_ldl,
- &ldctx);
- if (NULL != ldctx.last)
- {
- if (GNUNET_OK == ldctx.status)
- {
- /* call callback one more time! */
- ldc (ldc_cls,
- &ldctx.transfer_pub,
- ldctx.last);
- }
- free_link_data_list (cls,
- ldctx.last);
- ldctx.last = NULL;
- }
- if (GNUNET_OK != ldctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for callbacks called from #postgres_get_coin_transactions()
- */
-struct CoinHistoryContext
-{
- /**
- * Head of the coin's history list.
- */
- struct TALER_EXCHANGEDB_TransactionList *head;
-
- /**
- * Public key of the coin we are building the history for.
- */
- const struct TALER_CoinSpendPublicKeyP *coin_pub;
-
- /**
- * Closure for all callbacks of this database plugin.
- */
- void *db_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to 'true' if the transaction failed.
- */
- bool failed;
-
- /**
- * Set to 'true' if we found a deposit or melt (for invariant check).
- */
- bool have_deposit_or_melt;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_deposit (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_EXCHANGEDB_DepositListEntry *deposit;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- chc->have_deposit_or_melt = true;
- deposit = GNUNET_new (struct TALER_EXCHANGEDB_DepositListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit->amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &deposit->deposit_fee),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &deposit->h_denom_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit->h_age_commitment),
- &deposit->no_age_commitment),
- GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
- &deposit->timestamp),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &deposit->refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deposit->wire_deadline),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &deposit->merchant_pub),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &deposit->h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &deposit->wire_salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &deposit->receiver_wire_account),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit->csig),
- GNUNET_PQ_result_spec_uint64 ("deposit_serial_id",
- &serial_id),
- GNUNET_PQ_result_spec_auto_from_type ("done",
- &deposit->done),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (deposit);
- chc->failed = true;
- return;
- }
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_DEPOSIT;
- tl->details.deposit = deposit;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_purse_deposit (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_EXCHANGEDB_PurseDepositListEntry *deposit;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- chc->have_deposit_or_melt = true;
- deposit = GNUNET_new (struct TALER_EXCHANGEDB_PurseDepositListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit->amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &deposit->deposit_fee),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &deposit->purse_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &serial_id),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- &deposit->exchange_base_url),
- NULL),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit->coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit->h_age_commitment),
- GNUNET_PQ_result_spec_bool ("refunded",
- &deposit->refunded),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (deposit);
- chc->failed = true;
- return;
- }
- deposit->no_age_commitment = GNUNET_is_zero (&deposit->h_age_commitment);
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_PURSE_DEPOSIT;
- tl->details.purse_deposit = deposit;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_melt (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_MeltListEntry *melt;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- chc->have_deposit_or_melt = true;
- melt = GNUNET_new (struct TALER_EXCHANGEDB_MeltListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("rc",
- &melt->rc),
- /* oldcoin_index not needed */
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &melt->h_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &melt->coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &melt->amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &melt->melt_fee),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &melt->h_age_commitment),
- &melt->no_age_commitment),
- GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
- &serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (melt);
- chc->failed = true;
- return;
- }
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_MELT;
- tl->details.melt = melt;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_refund (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_RefundListEntry *refund;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- refund = GNUNET_new (struct TALER_EXCHANGEDB_RefundListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &refund->merchant_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
- &refund->merchant_sig),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &refund->h_contract_terms),
- GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
- &refund->rtransaction_id),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &refund->refund_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &refund->refund_fee),
- GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
- &serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (refund);
- chc->failed = true;
- return;
- }
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_REFUND;
- tl->details.refund = refund;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_old_coin_recoup (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_RecoupRefreshListEntry *recoup;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupRefreshListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &recoup->coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &recoup->coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &recoup->coin_blind),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &recoup->value),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &recoup->timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &recoup->coin.denom_pub_hash),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &recoup->coin.denom_sig),
- GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
- &serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (recoup);
- chc->failed = true;
- return;
- }
- recoup->old_coin_pub = *chc->coin_pub;
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP;
- tl->details.old_coin_recoup = recoup;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_recoup (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_RecoupListEntry *recoup;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &recoup->reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &recoup->coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &recoup->h_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &recoup->coin_blind),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &recoup->value),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &recoup->timestamp),
- GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
- &serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (recoup);
- chc->failed = true;
- return;
- }
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_RECOUP;
- tl->details.recoup = recoup;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct CoinHistoryContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-add_coin_recoup_refresh (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct CoinHistoryContext *chc = cls;
- struct PostgresClosure *pg = chc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_RecoupRefreshListEntry *recoup;
- struct TALER_EXCHANGEDB_TransactionList *tl;
- uint64_t serial_id;
-
- recoup = GNUNET_new (struct TALER_EXCHANGEDB_RecoupRefreshListEntry);
- {
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &recoup->old_coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &recoup->coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &recoup->coin_blind),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &recoup->value),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &recoup->timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &recoup->coin.denom_pub_hash),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &recoup->coin.denom_sig),
- GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
- &serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- GNUNET_free (recoup);
- chc->failed = true;
- return;
- }
- recoup->coin.coin_pub = *chc->coin_pub;
- }
- tl = GNUNET_new (struct TALER_EXCHANGEDB_TransactionList);
- tl->next = chc->head;
- tl->type = TALER_EXCHANGEDB_TT_RECOUP_REFRESH;
- tl->details.recoup_refresh = recoup;
- tl->serial_id = serial_id;
- chc->head = tl;
- }
-}
-
-
-/**
- * Work we need to do.
- */
-struct Work
-{
- /**
- * SQL prepared statement name.
- */
- const char *statement;
-
- /**
- * Function to call to handle the result(s).
- */
- GNUNET_PQ_PostgresResultHandler cb;
-};
-
-
-/**
- * Compile a list of all (historic) transactions performed with the given coin
- * (/refresh/melt, /deposit, /refund and /recoup operations).
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param coin_pub coin to investigate
- * @param include_recoup should recoup transactions be included in the @a tlp
- * @param[out] tlp set to list of transactions, NULL if coin is fresh
- * @return database transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_coin_transactions (
- void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- bool include_recoup,
- struct TALER_EXCHANGEDB_TransactionList **tlp)
-{
- struct PostgresClosure *pg = cls;
- static const struct Work work_op[] = {
- /** #TALER_EXCHANGEDB_TT_DEPOSIT */
- { "get_deposit_with_coin_pub",
- &add_coin_deposit },
- /** #TALER_EXCHANGEDB_TT_MELT */
- { "get_refresh_session_by_coin",
- &add_coin_melt },
- /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
- { "get_purse_deposit_by_coin_pub",
- &add_coin_purse_deposit },
- /** #TALER_EXCHANGEDB_TT_REFUND */
- { "get_refunds_by_coin",
- &add_coin_refund },
- { NULL, NULL }
- };
- static const struct Work work_wp[] = {
- /** #TALER_EXCHANGEDB_TT_DEPOSIT */
- { "get_deposit_with_coin_pub",
- &add_coin_deposit },
- /** #TALER_EXCHANGEDB_TT_MELT */
- { "get_refresh_session_by_coin",
- &add_coin_melt },
- /** #TALER_EXCHANGEDB_TT_PURSE_DEPOSIT */
- { "get_purse_deposit_by_coin_pub",
- &add_coin_purse_deposit },
- /** #TALER_EXCHANGEDB_TT_REFUND */
- { "get_refunds_by_coin",
- &add_coin_refund },
- /** #TALER_EXCHANGEDB_TT_OLD_COIN_RECOUP */
- { "recoup_by_old_coin",
- &add_old_coin_recoup },
- /** #TALER_EXCHANGEDB_TT_RECOUP */
- { "recoup_by_coin",
- &add_coin_recoup },
- /** #TALER_EXCHANGEDB_TT_RECOUP_REFRESH */
- { "recoup_by_refreshed_coin",
- &add_coin_recoup_refresh },
- { NULL, NULL }
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
- const struct Work *work;
- struct CoinHistoryContext chc = {
- .head = NULL,
- .coin_pub = coin_pub,
- .pg = pg,
- .db_cls = cls
- };
-
- work = (GNUNET_YES == include_recoup) ? work_wp : work_op;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting transactions for coin %s\n",
- TALER_B2S (coin_pub));
- for (unsigned int i = 0; NULL != work[i].statement; i++)
- {
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- work[i].statement,
- params,
- work[i].cb,
- &chc);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Coin %s yielded %d transactions of type %s\n",
- TALER_B2S (coin_pub),
- qs,
- work[i].statement);
- if ( (0 > qs) ||
- (chc.failed) )
- {
- if (NULL != chc.head)
- common_free_coin_transaction_list (cls,
- chc.head);
- *tlp = NULL;
- if (chc.failed)
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
- }
- }
- *tlp = chc.head;
- if (NULL == chc.head)
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
-}
-
-
-/**
- * Closure for #handle_wt_result.
- */
-struct WireTransferResultContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_AggregationDataCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to #GNUNET_SYSERR on serious errors.
- */
- int status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results. Helper function
- * for #postgres_lookup_wire_transfer().
- *
- * @param cls closure of type `struct WireTransferResultContext *`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-handle_wt_result (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireTransferResultContext *ctx = cls;
- struct PostgresClosure *pg = ctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_PaytoHashP h_payto;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_TIME_Timestamp exec_time;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount deposit_fee;
- struct TALER_DenominationPublicKey denom_pub;
- char *payto_uri;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("aggregation_serial_id", &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &h_contract_terms),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_auto_from_type ("wire_target_h_payto",
- &h_payto),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &merchant_pub),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &exec_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &deposit_fee),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ctx->cb (ctx->cb_cls,
- rowid,
- &merchant_pub,
- payto_uri,
- &h_payto,
- exec_time,
- &h_contract_terms,
- &denom_pub,
- &coin_pub,
- &amount_with_fee,
- &deposit_fee);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Lookup the list of Taler transactions that were aggregated
- * into a wire transfer by the respective @a wtid.
- *
- * @param cls closure
- * @param wtid the raw wire transfer identifier we used
- * @param cb function to call on each transaction found
- * @param cb_cls closure for @a cb
- * @return query status of the transaction
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_wire_transfer (
- void *cls,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- TALER_EXCHANGEDB_AggregationDataCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
- struct WireTransferResultContext ctx;
- enum GNUNET_DB_QueryStatus qs;
-
- ctx.cb = cb;
- ctx.cb_cls = cb_cls;
- ctx.pg = pg;
- ctx.status = GNUNET_OK;
- /* check if the melt record exists and get it */
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_transactions",
- params,
- &handle_wt_result,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Try to find the wire transfer details for a deposit operation.
- * If we did not execute the deposit yet, return when it is supposed
- * to be executed.
- *
- * @param cls closure
- * @param h_contract_terms hash of the proposal data
- * @param h_wire hash of merchant wire details
- * @param coin_pub public key of deposited coin
- * @param merchant_pub merchant public key
- * @param[out] pending set to true if the transaction is still pending
- * @param[out] wtid wire transfer identifier, only set if @a pending is false
- * @param[out] exec_time when was the transaction done, or
- * when we expect it to be done (if @a pending is false)
- * @param[out] amount_with_fee set to the total deposited amount
- * @param[out] deposit_fee set to how much the exchange did charge for the deposit
- * @param[out] kyc set to the kyc status of the receiver (if @a pending)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_transfer_by_deposit (
- void *cls,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- bool *pending,
- struct TALER_WireTransferIdentifierRawP *wtid,
- struct GNUNET_TIME_Timestamp *exec_time,
- struct TALER_Amount *amount_with_fee,
- struct TALER_Amount *deposit_fee,
- struct TALER_EXCHANGEDB_KycStatus *kyc)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_auto_from_type (merchant_pub),
- GNUNET_PQ_query_param_end
- };
- char *payto_uri;
- struct TALER_WireSaltP wire_salt;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- wtid),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &wire_salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- exec_time),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_end
- };
-
- /* check if the aggregation record exists and get it */
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_deposit_wtid",
- params,
- rs);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- struct TALER_MerchantWireHashP wh;
-
- TALER_merchant_wire_signature_hash (payto_uri,
- &wire_salt,
- &wh);
- GNUNET_PQ_cleanup_result (rs);
- if (0 ==
- GNUNET_memcmp (&wh,
- h_wire))
- {
- *pending = false;
- memset (kyc,
- 0,
- sizeof (*kyc));
- kyc->type = TALER_EXCHANGEDB_KYC_DEPOSIT;
- kyc->ok = true;
- return qs;
- }
- qs = GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- if (0 > qs)
- return qs;
- *pending = true;
- memset (wtid,
- 0,
- sizeof (*wtid));
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "lookup_deposit_wtid returned 0 matching rows\n");
- {
- /* Check if transaction exists in deposits, so that we just
- do not have a WTID yet. In that case, return without wtid
- (by setting 'pending' true). */
- struct GNUNET_PQ_ResultSpec rs2[] = {
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &wire_salt),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_uint64 ("payment_target_uuid",
- &kyc->payment_target_uuid),
- GNUNET_PQ_result_spec_auto_from_type ("kyc_ok",
- &kyc->ok),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- deposit_fee),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- exec_time),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_deposit_without_wtid",
- params,
- rs2);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- struct TALER_MerchantWireHashP wh;
-
- TALER_merchant_wire_signature_hash (payto_uri,
- &wire_salt,
- &wh);
- GNUNET_PQ_cleanup_result (rs);
- if (0 !=
- GNUNET_memcmp (&wh,
- h_wire))
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- kyc->type = TALER_EXCHANGEDB_KYC_DEPOSIT;
- return qs;
- }
-}
-
-
-/**
- * Function called to insert aggregation information into the DB.
- *
- * @param cls closure
- * @param wtid the raw wire transfer identifier we used
- * @param deposit_serial_id row in the deposits table for which this is aggregation data
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_aggregation_tracking (
- void *cls,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- unsigned long long deposit_serial_id)
-{
- struct PostgresClosure *pg = cls;
- uint64_t rid = deposit_serial_id;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rid),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_aggregation_tracking",
- params);
-}
-
-
-/**
- * Obtain wire fee from database.
- *
- * @param cls closure
- * @param type type of wire transfer the fee applies for
- * @param date for which date do we want the fee?
- * @param[out] start_date when does the fee go into effect
- * @param[out] end_date when does the fee end being valid
- * @param[out] fees how high are the wire fees
- * @param[out] master_sig signature over the above by the exchange master key
- * @return status of the transaction
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_fee (void *cls,
- const char *type,
- struct GNUNET_TIME_Timestamp date,
- struct GNUNET_TIME_Timestamp *start_date,
- struct GNUNET_TIME_Timestamp *end_date,
- struct TALER_WireFeeSet *fees,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (type),
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("start_date",
- start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &fees->wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wad_fee",
- &fees->wad),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &fees->closing),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_wire_fee",
- params,
- rs);
-}
-
-
-/**
- * Obtain global fees from database.
- *
- * @param cls closure
- * @param date for which date do we want the fee?
- * @param[out] start_date when does the fee go into effect
- * @param[out] end_date when does the fee end being valid
- * @param[out] fees how high are the wire fees
- * @param[out] purse_timeout set to how long we keep unmerged purses
- * @param[out] kyc_timeout set to how long we keep accounts without KYC
- * @param[out] history_expiration set to how long we keep account histories
- * @param[out] purse_account_limit set to the number of free purses per account
- * @param[out] master_sig signature over the above by the exchange master key
- * @return status of the transaction
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_global_fee (void *cls,
- struct GNUNET_TIME_Timestamp date,
- struct GNUNET_TIME_Timestamp *start_date,
- struct GNUNET_TIME_Timestamp *end_date,
- struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative *purse_timeout,
- struct GNUNET_TIME_Relative *kyc_timeout,
- struct GNUNET_TIME_Relative *history_expiration,
- uint32_t *purse_account_limit,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("start_date",
- start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &fees->history),
- TALER_PQ_RESULT_SPEC_AMOUNT ("kyc_fee",
- &fees->kyc),
- TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
- &fees->account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &fees->purse),
- GNUNET_PQ_result_spec_relative_time ("purse_timeout",
- purse_timeout),
- GNUNET_PQ_result_spec_relative_time ("kyc_timeout",
- kyc_timeout),
- GNUNET_PQ_result_spec_relative_time ("history_expiration",
- history_expiration),
- GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
- purse_account_limit),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_global_fee",
- params,
- rs);
-}
-
-
-/**
- * Closure for #global_fees_cb().
- */
-struct GlobalFeeContext
-{
- /**
- * Function to call for each global fee block.
- */
- TALER_EXCHANGEDB_GlobalFeeCallback cb;
-
- /**
- * Closure to give to @e rec.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-global_fees_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GlobalFeeContext *gctx = cls;
- struct PostgresClosure *pg = gctx->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_GlobalFeeSet fees;
- struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
- struct GNUNET_TIME_Relative history_expiration;
- uint32_t purse_account_limit;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &fees.history),
- TALER_PQ_RESULT_SPEC_AMOUNT ("kyc_fee",
- &fees.kyc),
- TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
- &fees.account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &fees.purse),
- GNUNET_PQ_result_spec_relative_time ("purse_timeout",
- &purse_timeout),
- GNUNET_PQ_result_spec_relative_time ("kyc_timeout",
- &kyc_timeout),
- GNUNET_PQ_result_spec_relative_time ("history_expiration",
- &history_expiration),
- GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
- &purse_account_limit),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_end
- };
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- gctx->status = GNUNET_SYSERR;
- break;
- }
- gctx->cb (gctx->cb_cls,
- &fees,
- purse_timeout,
- kyc_timeout,
- history_expiration,
- purse_account_limit,
- start_date,
- end_date,
- &master_sig);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Obtain global fees from database.
- *
- * @param cls closure
- * @param cb function to call on each fee entry
- * @param cb_cls closure for @a cb
- * @return status of the transaction
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_global_fees (void *cls,
- TALER_EXCHANGEDB_GlobalFeeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Timestamp date
- = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_subtract (
- GNUNET_TIME_absolute_get (),
- GNUNET_TIME_UNIT_YEARS));
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_end
- };
- struct GlobalFeeContext gctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_global_fees",
- params,
- &global_fees_cb,
- &gctx);
-}
-
-
-/**
- * Insert wire transfer fee into database.
- *
- * @param cls closure
- * @param type type of wire transfer this fee applies for
- * @param start_date when does the fee go into effect
- * @param end_date when does the fee end being valid
- * @param fees how high are the wire fees
- * @param master_sig signature over the above by the exchange master key
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_wire_fee (void *cls,
- const char *type,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_WireFeeSet *fees,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (type),
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_timestamp (&end_date),
- TALER_PQ_query_param_amount (&fees->wire),
- TALER_PQ_query_param_amount (&fees->closing),
- TALER_PQ_query_param_amount (&fees->wad),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
- struct TALER_WireFeeSet wx;
- struct TALER_MasterSignatureP sig;
- struct GNUNET_TIME_Timestamp sd;
- struct GNUNET_TIME_Timestamp ed;
- enum GNUNET_DB_QueryStatus qs;
-
- qs = postgres_get_wire_fee (pg,
- type,
- start_date,
- &sd,
- &ed,
- &wx,
- &sig);
- if (qs < 0)
- return qs;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- if (0 != GNUNET_memcmp (&sig,
- master_sig))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (0 !=
- TALER_wire_fee_set_cmp (fees,
- &wx))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (GNUNET_TIME_timestamp_cmp (sd,
- !=,
- start_date)) ||
- (GNUNET_TIME_timestamp_cmp (ed,
- !=,
- end_date)) )
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- /* equal record already exists */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_wire_fee",
- params);
-}
-
-
-/**
- * Insert global fee data into database.
- *
- * @param cls closure
- * @param start_date when does the fees go into effect
- * @param end_date when does the fees end being valid
- * @param fees how high is are the global fees
- * @param purse_timeout when do purses time out
- * @param kyc_timeout when do reserves without KYC time out
- * @param history_expiration how long are account histories preserved
- * @param purse_account_limit how many purses are free per account
- * @param master_sig signature over the above by the exchange master key
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_global_fee (void *cls,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- const struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
- struct GNUNET_TIME_Relative history_expiration,
- uint32_t purse_account_limit,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_timestamp (&end_date),
- TALER_PQ_query_param_amount (&fees->history),
- TALER_PQ_query_param_amount (&fees->kyc),
- TALER_PQ_query_param_amount (&fees->account),
- TALER_PQ_query_param_amount (&fees->purse),
- GNUNET_PQ_query_param_relative_time (&purse_timeout),
- GNUNET_PQ_query_param_relative_time (&kyc_timeout),
- GNUNET_PQ_query_param_relative_time (&history_expiration),
- GNUNET_PQ_query_param_uint32 (&purse_account_limit),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
- struct TALER_GlobalFeeSet wx;
- struct TALER_MasterSignatureP sig;
- struct GNUNET_TIME_Timestamp sd;
- struct GNUNET_TIME_Timestamp ed;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Relative pt;
- struct GNUNET_TIME_Relative kt;
- struct GNUNET_TIME_Relative he;
- uint32_t pal;
-
- qs = postgres_get_global_fee (pg,
- start_date,
- &sd,
- &ed,
- &wx,
- &pt,
- &kt,
- &he,
- &pal,
- &sig);
- if (qs < 0)
- return qs;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs)
- {
- if (0 != GNUNET_memcmp (&sig,
- master_sig))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (0 !=
- TALER_global_fee_set_cmp (fees,
- &wx))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (GNUNET_TIME_timestamp_cmp (sd,
- !=,
- start_date)) ||
- (GNUNET_TIME_timestamp_cmp (ed,
- !=,
- end_date)) )
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (GNUNET_TIME_relative_cmp (purse_timeout,
- !=,
- pt)) ||
- (GNUNET_TIME_relative_cmp (kyc_timeout,
- !=,
- kt)) ||
- (GNUNET_TIME_relative_cmp (history_expiration,
- !=,
- he)) )
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if (purse_account_limit != pal)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- /* equal record already exists */
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_global_fee",
- params);
-}
-
-
-/**
- * Closure for #reserve_expired_cb().
- */
-struct ExpiredReserveContext
-{
- /**
- * Function to call for each expired reserve.
- */
- TALER_EXCHANGEDB_ReserveExpiredCallback rec;
-
- /**
- * Closure to give to @e rec.
- */
- void *rec_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_expired_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ExpiredReserveContext *erc = cls;
- struct PostgresClosure *pg = erc->pg;
- enum GNUNET_GenericReturnValue ret;
-
- ret = GNUNET_OK;
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct GNUNET_TIME_Timestamp exp_date;
- char *account_details;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount remaining_balance;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("expiration_date",
- &exp_date),
- GNUNET_PQ_result_spec_string ("account_details",
- &account_details),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("current_balance",
- &remaining_balance),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ret = GNUNET_SYSERR;
- break;
- }
- ret = erc->rec (erc->rec_cls,
- &reserve_pub,
- &remaining_balance,
- account_details,
- exp_date);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
- erc->status = ret;
-}
-
-
-/**
- * Obtain information about expired reserves and their
- * remaining balances.
- *
- * @param cls closure of the plugin
- * @param now timestamp based on which we decide expiration
- * @param rec function to call on expired reserves
- * @param rec_cls closure for @a rec
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_expired_reserves (void *cls,
- struct GNUNET_TIME_Timestamp now,
- TALER_EXCHANGEDB_ReserveExpiredCallback rec,
- void *rec_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_end
- };
- struct ExpiredReserveContext ectx = {
- .rec = rec,
- .rec_cls = rec_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_expired_reserves",
- params,
- &reserve_expired_cb,
- &ectx);
- if (GNUNET_OK != ectx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Insert reserve close operation into database.
- *
- * @param cls closure
- * @param reserve_pub which reserve is this about?
- * @param execution_date when did we perform the transfer?
- * @param receiver_account to which account do we transfer?
- * @param wtid wire transfer details
- * @param amount_with_fee amount we charged to the reserve
- * @param closing_fee how high is the closing fee
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_reserve_closed (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct GNUNET_TIME_Timestamp execution_date,
- const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_Amount *amount_with_fee,
- const struct TALER_Amount *closing_fee)
-{
- struct PostgresClosure *pg = cls;
- struct TALER_EXCHANGEDB_Reserve reserve;
- struct TALER_EXCHANGEDB_KycStatus kyc;
- enum GNUNET_DB_QueryStatus qs;
- struct TALER_PaytoHashP h_payto;
-
- qs = inselect_account_kyc_status (pg,
- receiver_account,
- &h_payto,
- &kyc);
- if (qs <= 0)
- {
- GNUNET_break (GNUNET_DB_STATUS_HARD_ERROR == qs);
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- return qs;
- }
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_timestamp (&execution_date),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_auto_from_type (&h_payto),
- TALER_PQ_query_param_amount (amount_with_fee),
- TALER_PQ_query_param_amount (closing_fee),
- GNUNET_PQ_query_param_end
- };
-
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reserves_close_insert",
- params);
- }
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- return qs;
-
- /* update reserve balance */
- reserve.pub = *reserve_pub;
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- (qs = reserves_get_internal (cls,
- &reserve)))
- {
- /* Existence should have been checked before we got here... */
- GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
- qs = GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
- }
- {
- enum TALER_AmountArithmeticResult ret;
-
- ret = TALER_amount_subtract (&reserve.balance,
- &reserve.balance,
- amount_with_fee);
- if (ret < 0)
- {
- /* The reserve history was checked to make sure there is enough of a balance
- left before we tried this; however, concurrent operations may have changed
- the situation by now. We should re-try the transaction. */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Closing of reserve `%s' refused due to balance mismatch. Retrying.\n",
- TALER_B2S (reserve_pub));
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- GNUNET_break (TALER_AAR_RESULT_ZERO == ret);
- }
- return reserves_update (cls,
- &reserve);
-}
-
-
-/**
- * Function called to insert wire transfer commit data into the DB.
- *
- * @param cls closure
- * @param type type of the wire transfer (i.e. "iban")
- * @param buf buffer with wire transfer preparation data
- * @param buf_size number of bytes in @a buf
- * @return query status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_wire_prepare_data_insert (void *cls,
- const char *type,
- const char *buf,
- size_t buf_size)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (type),
- GNUNET_PQ_query_param_fixed_size (buf, buf_size),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_insert",
- params);
-}
-
-
-/**
- * Function called to mark wire transfer commit data as finished.
- *
- * @param cls closure
- * @param rowid which entry to mark as finished
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_wire_prepare_data_mark_finished (
- void *cls,
- uint64_t rowid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_mark_done",
- params);
-}
-
-
-/**
- * Function called to mark wire transfer commit data as failed.
- *
- * @param cls closure
- * @param rowid which entry to mark as failed
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_wire_prepare_data_mark_failed (
- void *cls,
- uint64_t rowid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "wire_prepare_data_mark_failed",
- params);
-}
-
-
-/**
- * Closure for #prewire_cb().
- */
-struct PrewireContext
-{
- /**
- * Function to call on each result.
- */
- TALER_EXCHANGEDB_WirePreparationIterator cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * #GNUNET_OK if everything went fine.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-prewire_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PrewireContext *pc = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- uint64_t prewire_uuid;
- char *wire_method;
- void *buf = NULL;
- size_t buf_size;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("prewire_uuid",
- &prewire_uuid),
- GNUNET_PQ_result_spec_string ("wire_method",
- &wire_method),
- GNUNET_PQ_result_spec_variable_size ("buf",
- &buf,
- &buf_size),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- pc->status = GNUNET_SYSERR;
- return;
- }
- pc->cb (pc->cb_cls,
- prewire_uuid,
- wire_method,
- buf,
- buf_size);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Function called to get an unfinished wire transfer
- * preparation data. Fetches at most one item.
- *
- * @param cls closure
- * @param start_row offset to query table at
- * @param limit maximum number of results to return
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_wire_prepare_data_get (void *cls,
- uint64_t start_row,
- uint64_t limit,
- TALER_EXCHANGEDB_WirePreparationIterator cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&start_row),
- GNUNET_PQ_query_param_uint64 (&limit),
- GNUNET_PQ_query_param_end
- };
- struct PrewireContext pc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "wire_prepare_data_get",
- params,
- &prewire_cb,
- &pc);
- if (GNUNET_OK != pc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Starts a READ COMMITTED transaction where we transiently violate the foreign
- * constraints on the "wire_out" table as we insert aggregations
- * and only add the wire transfer out at the end.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-postgres_start_deferred_wire_out (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute (
- "START TRANSACTION ISOLATION LEVEL READ COMMITTED;"),
- GNUNET_PQ_make_execute ("SET CONSTRAINTS ALL DEFERRED;"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- if (GNUNET_SYSERR ==
- postgres_preflight (pg))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- GNUNET_PQ_exec_statements (pg->conn,
- es))
- {
- TALER_LOG_ERROR (
- "Failed to defer wire_out_ref constraint on transaction\n");
- GNUNET_break (0);
- postgres_rollback (pg);
- return GNUNET_SYSERR;
- }
- pg->transaction_name = "deferred wire out";
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting READ COMMITTED DEFERRED transaction `%s'\n",
- pg->transaction_name);
return GNUNET_OK;
}
/**
- * Store information about an outgoing wire transfer that was executed.
- *
- * @param cls closure
- * @param date time of the wire transfer
- * @param wtid subject of the wire transfer
- * @param h_payto identifies the receiver account of the wire transfer
- * @param exchange_account_section configuration section of the exchange specifying the
- * exchange's bank account being used
- * @param amount amount that was transmitted
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_store_wire_transfer_out (
- void *cls,
- struct GNUNET_TIME_Timestamp date,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- const struct TALER_PaytoHashP *h_payto,
- const char *exchange_account_section,
- const struct TALER_Amount *amount)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&date),
- GNUNET_PQ_query_param_auto_from_type (wtid),
- GNUNET_PQ_query_param_auto_from_type (h_payto),
- GNUNET_PQ_query_param_string (exchange_account_section),
- TALER_PQ_query_param_amount (amount),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_wire_out",
- params);
-}
-
-
-/**
- * Function called to perform "garbage collection" on the
- * database, expiring records we no longer require.
- *
- * @param cls closure
- * @return #GNUNET_OK on success,
- * #GNUNET_SYSERR on DB errors
- */
-static enum GNUNET_GenericReturnValue
-postgres_gc (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- struct GNUNET_TIME_Absolute long_ago;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&long_ago),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_Context *conn;
- enum GNUNET_GenericReturnValue ret;
-
- /* Keep wire fees for 10 years, that should always
- be enough _and_ they are tiny so it does not
- matter to make this tight */
- long_ago = GNUNET_TIME_absolute_subtract (
- now,
- GNUNET_TIME_relative_multiply (
- GNUNET_TIME_UNIT_YEARS,
- 10));
- {
- struct GNUNET_PQ_PreparedStatement ps[] = {
- /* Used in #postgres_gc() */
- GNUNET_PQ_make_prepare ("run_gc",
- "CALL"
- " exchange_do_gc"
- " ($1,$2);",
- 2),
- GNUNET_PQ_PREPARED_STATEMENT_END
- };
-
- conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- NULL,
- NULL,
- ps);
- }
- if (NULL == conn)
- return GNUNET_SYSERR;
- ret = GNUNET_OK;
- if (0 > GNUNET_PQ_eval_prepared_non_select (conn,
- "run_gc",
- params))
- ret = GNUNET_SYSERR;
- GNUNET_PQ_disconnect (conn);
- return ret;
-}
-
-
-/**
- * Closure for #deposit_serial_helper_cb().
- */
-struct DepositSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_DepositCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-deposit_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct DepositSerialContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_Deposit deposit;
- struct GNUNET_TIME_Timestamp exchange_timestamp;
- struct TALER_DenominationPublicKey denom_pub;
- bool done;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit.amount_with_fee),
- GNUNET_PQ_result_spec_timestamp ("wallet_timestamp",
- &deposit.timestamp),
- GNUNET_PQ_result_spec_timestamp ("exchange_timestamp",
- &exchange_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &deposit.merchant_pub),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &deposit.coin.coin_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit.coin.h_age_commitment),
- &deposit.coin.no_age_commitment),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit.csig),
- GNUNET_PQ_result_spec_timestamp ("refund_deadline",
- &deposit.refund_deadline),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deposit.wire_deadline),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &deposit.h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("wire_salt",
- &deposit.wire_salt),
- GNUNET_PQ_result_spec_string ("receiver_wire_account",
- &deposit.receiver_wire_account),
- GNUNET_PQ_result_spec_bool ("done",
- &done),
- GNUNET_PQ_result_spec_uint64 ("deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- memset (&deposit,
- 0,
- sizeof (deposit));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- exchange_timestamp,
- &deposit,
- &denom_pub,
- done);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_deposits_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_DepositCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct DepositSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_deposits_incr",
- params,
- &deposit_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct PurseDepositSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseDepositCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct DepositSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_deposit_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseDepositSerialContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_PurseDeposit deposit = {
- .exchange_base_url = NULL
- };
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- uint32_t flags32;
- struct TALER_ReservePublicKeyP reserve_pub;
- bool not_merged = false;
- struct TALER_Amount purse_balance;
- struct TALER_Amount purse_total;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &deposit.amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &purse_balance),
- TALER_PQ_RESULT_SPEC_AMOUNT ("total",
- &purse_total),
- TALER_PQ_RESULT_SPEC_AMOUNT ("deposit_fee",
- &deposit.deposit_fee),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- &deposit.exchange_base_url),
- NULL),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- &not_merged),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &deposit.purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &deposit.coin_sig),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &deposit.coin_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &deposit.h_age_commitment),
- &deposit.no_age_commitment),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- memset (&deposit,
- 0,
- sizeof (deposit));
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &deposit,
- not_merged ? NULL : &reserve_pub,
- (enum TALER_WalletAccountMergeFlags) flags32,
- &purse_balance,
- &purse_total,
- &denom_pub);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_deposits_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseDepositCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseDepositSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_deposits_incr",
- params,
- &purse_deposit_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #account_merge_serial_helper_cb().
- */
-struct AccountMergeSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_AccountMergeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct AccountMergeSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-account_merge_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct AccountMergeSerialContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct GNUNET_TIME_Timestamp purse_expiration;
- struct TALER_Amount amount;
- uint32_t min_age;
- uint32_t flags32;
- enum TALER_WalletAccountMergeFlags flags;
- struct TALER_Amount purse_fee;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct TALER_ReserveSignatureP reserve_sig;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &purse_fee),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- &min_age),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- &purse_expiration),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- &merge_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &h_contract_terms),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("account_merge_request_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- flags = (enum TALER_WalletAccountMergeFlags) flags32;
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &reserve_pub,
- &purse_pub,
- &h_contract_terms,
- purse_expiration,
- &amount,
- min_age,
- flags,
- &purse_fee,
- merge_timestamp,
- &reserve_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select account merges above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_account_merges_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_AccountMergeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct AccountMergeSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_account_merge_incr",
- params,
- &account_merge_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct PurseMergeSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseMergeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseMergeSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_merges_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseMergeSerialContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- char *partner_base_url = NULL;
- struct TALER_Amount amount;
- struct TALER_Amount balance;
- uint32_t flags32;
- enum TALER_WalletAccountMergeFlags flags;
- struct TALER_PurseMergePublicKeyP merge_pub;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_PurseMergeSignatureP merge_sig;
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct GNUNET_TIME_Timestamp merge_timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- &balance),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- &partner_base_url),
- NULL),
- GNUNET_PQ_result_spec_uint32 ("flags",
- &flags32),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- &merge_timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
- &merge_sig),
- GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
- &merge_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_merge_request_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- flags = (enum TALER_WalletAccountMergeFlags) flags32;
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- partner_base_url,
- &amount,
- &balance,
- flags,
- &merge_pub,
- &reserve_pub,
- &merge_sig,
- &purse_pub,
- merge_timestamp);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select purse merges deposits above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_merges_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseMergeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseMergeSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_merge_incr",
- params,
- &purse_merges_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #purse_deposit_serial_helper_cb().
- */
-struct HistoryRequestSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_HistoryRequestCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct HistoryRequestSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-history_request_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct HistoryRequestSerialContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_Amount history_fee;
- struct GNUNET_TIME_Timestamp ts;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &history_fee),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_uint64 ("history_request_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("request_timestamp",
- &ts),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &history_fee,
- ts,
- &reserve_pub,
- &reserve_sig);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select history requests above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_history_requests_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_HistoryRequestCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct HistoryRequestSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_history_requests_incr",
- params,
- &history_request_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #purse_refund_serial_helper_cb().
- */
-struct PurseRefundSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseRefundCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_refund_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseRefundSerialContext *dsc = cls;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_PurseContractPublicKeyP purse_pub;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- &purse_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &purse_pub);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select purse refunds above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_refunds_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_PurseRefundCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct PurseRefundSerialContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_refunds_incr",
- params,
- &purse_refund_serial_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #purse_refund_coin_helper_cb().
- */
-struct PurseRefundCoinContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_PurseRefundCoinCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct PurseRefundCoinContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-purse_refund_coin_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct PurseRefundCoinContext *dsc = cls;
- struct PostgresClosure *pg = dsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_Amount amount_with_fee;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_uint64 ("purse_deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- dsc->status = GNUNET_SYSERR;
- return;
- }
- ret = dsc->cb (dsc->cb_cls,
- rowid,
- &amount_with_fee,
- &coin_pub,
- &denom_pub);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select coin affected by purse refund.
- *
- * @param cls closure
- * @param purse_pub purse that was refunded
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_deposits_by_purse (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- TALER_EXCHANGEDB_PurseRefundCoinCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct PurseRefundCoinContext dsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_purse_deposits_by_purse",
- params,
- &purse_refund_coin_helper_cb,
- &dsc);
- if (GNUNET_OK != dsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #refreshs_serial_helper_cb().
- */
-struct RefreshsSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RefreshesCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RefreshsSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-refreshs_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RefreshsSerialContext *rsc = cls;
- struct PostgresClosure *pg = rsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct TALER_AgeCommitmentHash h_age_commitment;
- bool ac_isnull;
- struct TALER_Amount amount_with_fee;
- uint32_t noreveal_index;
- uint64_t rowid;
- struct TALER_RefreshCommitmentP rc;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &h_age_commitment),
- &ac_isnull),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_sig",
- &coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_uint32 ("noreveal_index",
- &noreveal_index),
- GNUNET_PQ_result_spec_uint64 ("melt_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("rc",
- &rc),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
-
- ret = rsc->cb (rsc->cb_cls,
- rowid,
- &denom_pub,
- ac_isnull ? NULL : &h_age_commitment,
- &coin_pub,
- &coin_sig,
- &amount_with_fee,
- noreveal_index,
- &rc);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select refresh sessions above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_refreshes_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefreshesCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RefreshsSerialContext rsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_refresh_commitments_incr",
- params,
- &refreshs_serial_helper_cb,
- &rsc);
- if (GNUNET_OK != rsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #refunds_serial_helper_cb().
- */
-struct RefundsSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RefundCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RefundsSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-refunds_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RefundsSerialContext *rsc = cls;
- struct PostgresClosure *pg = rsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_EXCHANGEDB_Refund refund;
- struct TALER_DenominationPublicKey denom_pub;
- uint64_t rowid;
- bool full_refund;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merchant_pub",
- &refund.details.merchant_pub),
- GNUNET_PQ_result_spec_auto_from_type ("merchant_sig",
- &refund.details.merchant_sig),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- &refund.details.h_contract_terms),
- GNUNET_PQ_result_spec_uint64 ("rtransaction_id",
- &refund.details.rtransaction_id),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &refund.coin.coin_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &refund.details.refund_amount),
- GNUNET_PQ_result_spec_uint64 ("refund_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
- {
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&rowid),
- GNUNET_PQ_query_param_end
- };
- struct TALER_Amount amount_with_fee;
- uint64_t s_f;
- uint64_t s_v;
- struct GNUNET_PQ_ResultSpec rs2[] = {
- GNUNET_PQ_result_spec_uint64 ("s_v",
- &s_v),
- GNUNET_PQ_result_spec_uint64 ("s_f",
- &s_f),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (
- pg->conn,
- "test_refund_full",
- params,
- rs2);
- if (qs <= 0)
- {
- GNUNET_break (0);
- rsc->status = GNUNET_SYSERR;
- return;
- }
- /* normalize */
- s_v += s_f / TALER_AMOUNT_FRAC_BASE;
- s_f %= TALER_AMOUNT_FRAC_BASE;
- full_refund = (s_v >= amount_with_fee.value) &&
- (s_f >= amount_with_fee.fraction);
- }
- ret = rsc->cb (rsc->cb_cls,
- rowid,
- &denom_pub,
- &refund.coin.coin_pub,
- &refund.details.merchant_pub,
- &refund.details.merchant_sig,
- &refund.details.h_contract_terms,
- refund.details.rtransaction_id,
- full_refund,
- &refund.details.refund_amount);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select refunds above @a serial_id in monotonically increasing
- * order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_refunds_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RefundCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RefundsSerialContext rsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_refunds_incr",
- params,
- &refunds_serial_helper_cb,
- &rsc);
- if (GNUNET_OK != rsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #reserves_in_serial_helper_cb().
- */
-struct ReservesInSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveInCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReservesInSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserves_in_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReservesInSerialContext *risc = cls;
- struct PostgresClosure *pg = risc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_Amount credit;
- char *sender_account_details;
- struct GNUNET_TIME_Timestamp execution_date;
- uint64_t rowid;
- uint64_t wire_reference;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("wire_reference",
- &wire_reference),
- TALER_PQ_RESULT_SPEC_AMOUNT ("credit",
- &credit),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- GNUNET_PQ_result_spec_string ("sender_account_details",
- &sender_account_details),
- GNUNET_PQ_result_spec_uint64 ("reserve_in_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- risc->status = GNUNET_SYSERR;
- return;
- }
- ret = risc->cb (risc->cb_cls,
- rowid,
- &reserve_pub,
- &credit,
- sender_account_details,
- wire_reference,
- execution_date);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select inbound wire transfers into reserves_in above @a serial_id
- * in monotonically increasing order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_reserves_in_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveInCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReservesInSerialContext risc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_reserves_in_get_transactions_incr",
- params,
- &reserves_in_serial_helper_cb,
- &risc);
- if (GNUNET_OK != risc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Select inbound wire transfers into reserves_in above @a serial_id
- * in monotonically increasing order by account.
- *
- * @param cls closure
- * @param account_name name of the account to select by
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_reserves_in_above_serial_id_by_account (
- void *cls,
- const char *account_name,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveInCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct ReservesInSerialContext risc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_reserves_in_get_transactions_incr_by_account",
- params,
- &reserves_in_serial_helper_cb,
- &risc);
- if (GNUNET_OK != risc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #reserves_out_serial_helper_cb().
- */
-struct ReservesOutSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_WithdrawCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReservesOutSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserves_out_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReservesOutSerialContext *rosc = cls;
- struct PostgresClosure *pg = rosc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_BlindedCoinHashP h_blind_ev;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_TIME_Timestamp execution_date;
- struct TALER_Amount amount_with_fee;
- uint64_t rowid;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &h_blind_ev),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_sig",
- &reserve_sig),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount_with_fee),
- GNUNET_PQ_result_spec_uint64 ("reserve_out_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rosc->status = GNUNET_SYSERR;
- return;
- }
- ret = rosc->cb (rosc->cb_cls,
- rowid,
- &h_blind_ev,
- &denom_pub,
- &reserve_pub,
- &reserve_sig,
- execution_date,
- &amount_with_fee);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Select withdraw operations from reserves_out above @a serial_id
- * in monotonically increasing order.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call on each result
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_withdrawals_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WithdrawCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReservesOutSerialContext rosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_reserves_out_incr",
- params,
- &reserves_out_serial_helper_cb,
- &rosc);
- if (GNUNET_OK != rosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #wire_out_serial_helper_cb().
- */
-struct WireOutSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_WireTransferOutCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- int status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct WireOutSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-wire_out_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireOutSerialContext *wosc = cls;
- struct PostgresClosure *pg = wosc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct GNUNET_TIME_Timestamp date;
- struct TALER_WireTransferIdentifierRawP wtid;
- char *payto_uri;
- struct TALER_Amount amount;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("wireout_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &date),
- GNUNET_PQ_result_spec_auto_from_type ("wtid_raw",
- &wtid),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- int ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- wosc->status = GNUNET_SYSERR;
- return;
- }
- ret = wosc->cb (wosc->cb_cls,
- rowid,
- date,
- &wtid,
- payto_uri,
- &amount);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Function called to select all wire transfers the exchange
- * executed.
- *
- * @param cls closure
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_wire_out_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct WireOutSerialContext wosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_wire_incr",
- params,
- &wire_out_serial_helper_cb,
- &wosc);
- if (GNUNET_OK != wosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Function called to select all wire transfers the exchange
- * executed by account.
- *
- * @param cls closure
- * @param account_name account to select
- * @param serial_id highest serial ID to exclude (select strictly larger)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_wire_out_above_serial_id_by_account (
- void *cls,
- const char *account_name,
- uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_string (account_name),
- GNUNET_PQ_query_param_end
- };
- struct WireOutSerialContext wosc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "audit_get_wire_incr_by_account",
- params,
- &wire_out_serial_helper_cb,
- &wosc);
- if (GNUNET_OK != wosc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #recoup_serial_helper_cb().
- */
-struct RecoupSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RecoupCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RecoupSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-recoup_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RecoupSerialContext *psc = cls;
- struct PostgresClosure *pg = psc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- struct TALER_CoinPublicInfo coin;
- struct TALER_CoinSpendSignatureP coin_sig;
- union TALER_DenominationBlindingKeyP coin_blind;
- struct TALER_Amount amount;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_BlindedCoinHashP h_blind_ev;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("recoup_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin.coin_pub),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &coin_blind),
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &h_blind_ev),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &coin.denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &coin.h_age_commitment),
- &coin.no_age_commitment),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &coin.denom_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- int ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- psc->status = GNUNET_SYSERR;
- return;
- }
- ret = psc->cb (psc->cb_cls,
- rowid,
- timestamp,
- &amount,
- &reserve_pub,
- &coin,
- &denom_pub,
- &coin_sig,
- &coin_blind);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Function called to select recoup requests the exchange
- * received, ordered by serial ID (monotonically increasing).
- *
- * @param cls closure
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_recoup_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RecoupSerialContext psc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "recoup_get_incr",
- params,
- &recoup_serial_helper_cb,
- &psc);
- if (GNUNET_OK != psc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #recoup_refresh_serial_helper_cb().
- */
-struct RecoupRefreshSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_RecoupRefreshCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct RecoupRefreshSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-recoup_refresh_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct RecoupRefreshSerialContext *psc = cls;
- struct PostgresClosure *pg = psc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_CoinSpendPublicKeyP old_coin_pub;
- struct TALER_CoinPublicInfo coin;
- struct TALER_CoinSpendSignatureP coin_sig;
- union TALER_DenominationBlindingKeyP coin_blind;
- struct TALER_DenominationPublicKey denom_pub;
- struct TALER_DenominationHashP old_denom_pub_hash;
- struct TALER_Amount amount;
- struct TALER_BlindedCoinHashP h_blind_ev;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("recoup_refresh_uuid",
- &rowid),
- GNUNET_PQ_result_spec_timestamp ("recoup_timestamp",
- &timestamp),
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- &old_coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("old_denom_pub_hash",
- &old_denom_pub_hash),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin.coin_pub),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- &coin_sig),
- GNUNET_PQ_result_spec_auto_from_type ("coin_blind",
- &coin_blind),
- TALER_PQ_result_spec_denom_pub ("denom_pub",
- &denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("h_blind_ev",
- &h_blind_ev),
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- &coin.denom_pub_hash),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- &coin.h_age_commitment),
- &coin.no_age_commitment),
- TALER_PQ_result_spec_denom_sig ("denom_sig",
- &coin.denom_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- psc->status = GNUNET_SYSERR;
- return;
- }
- ret = psc->cb (psc->cb_cls,
- rowid,
- timestamp,
- &amount,
- &old_coin_pub,
- &old_denom_pub_hash,
- &coin,
- &denom_pub,
- &coin_sig,
- &coin_blind);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Function called to select recoup requests the exchange received for
- * refreshed coins, ordered by serial ID (monotonically increasing).
- *
- * @param cls closure
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_recoup_refresh_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_RecoupRefreshCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct RecoupRefreshSerialContext psc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "recoup_refresh_get_incr",
- params,
- &recoup_refresh_serial_helper_cb,
- &psc);
- if (GNUNET_OK != psc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Closure for #reserve_closed_serial_helper_cb().
- */
-struct ReserveClosedSerialContext
-{
-
- /**
- * Callback to call.
- */
- TALER_EXCHANGEDB_ReserveClosedCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin's context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Status code, set to #GNUNET_SYSERR on hard errors.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Helper function to be called with the results of a SELECT statement
- * that has returned @a num_results results.
- *
- * @param cls closure of type `struct ReserveClosedSerialContext`
- * @param result the postgres result
- * @param num_results the number of results in @a result
- */
-static void
-reserve_closed_serial_helper_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct ReserveClosedSerialContext *rcsc = cls;
- struct PostgresClosure *pg = rcsc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- uint64_t rowid;
- struct TALER_ReservePublicKeyP reserve_pub;
- char *receiver_account;
- struct TALER_WireTransferIdentifierRawP wtid;
- struct TALER_Amount amount_with_fee;
- struct TALER_Amount closing_fee;
- struct GNUNET_TIME_Timestamp execution_date;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("close_uuid",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- &reserve_pub),
- GNUNET_PQ_result_spec_timestamp ("execution_date",
- &execution_date),
- GNUNET_PQ_result_spec_auto_from_type ("wtid",
- &wtid),
- GNUNET_PQ_result_spec_string ("receiver_account",
- &receiver_account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount",
- &amount_with_fee),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &closing_fee),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_GenericReturnValue ret;
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- rcsc->status = GNUNET_SYSERR;
- return;
- }
- ret = rcsc->cb (rcsc->cb_cls,
- rowid,
- execution_date,
- &amount_with_fee,
- &closing_fee,
- &reserve_pub,
- receiver_account,
- &wtid);
- GNUNET_PQ_cleanup_result (rs);
- if (GNUNET_OK != ret)
- break;
- }
-}
-
-
-/**
- * Function called to select reserve close operations the aggregator
- * triggered, ordered by serial ID (monotonically increasing).
- *
- * @param cls closure
- * @param serial_id lowest serial ID to include (select larger or equal)
- * @param cb function to call for ONE unfinished item
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_reserve_closed_above_serial_id (
- void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_ReserveClosedCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial_id),
- GNUNET_PQ_query_param_end
- };
- struct ReserveClosedSerialContext rcsc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "reserves_close_get_incr",
- params,
- &reserve_closed_serial_helper_cb,
- &rcsc);
- if (GNUNET_OK != rcsc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Obtain information about which reserve a coin was generated
- * from given the hash of the blinded coin.
- *
- * @param cls closure
- * @param bch hash that uniquely identifies the withdraw request
- * @param[out] reserve_pub set to information about the reserve (on success only)
- * @param[out] reserve_out_serial_id set to row of the @a h_blind_ev in reserves_out
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_reserve_by_h_blind (
- void *cls,
- const struct TALER_BlindedCoinHashP *bch,
- struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t *reserve_out_serial_id)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (bch),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- reserve_pub),
- GNUNET_PQ_result_spec_uint64 ("reserve_out_serial_id",
- reserve_out_serial_id),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "reserve_by_h_blind",
- params,
- rs);
-}
-
-
-/**
- * Obtain information about which old coin a coin was refreshed
- * given the hash of the blinded (fresh) coin.
- *
- * @param cls closure
- * @param h_blind_ev hash of the blinded coin
- * @param[out] old_coin_pub set to information about the old coin (on success only)
- * @param[out] rrc_serial set to serial number of the entry in the database
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_old_coin_by_h_blind (
- void *cls,
- const struct TALER_BlindedCoinHashP *h_blind_ev,
- struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- uint64_t *rrc_serial)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_blind_ev),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("old_coin_pub",
- old_coin_pub),
- GNUNET_PQ_result_spec_uint64 ("rrc_serial",
- rrc_serial),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "old_coin_by_h_blind",
- params,
- rs);
-}
-
-
-/**
- * Store information that a denomination key was revoked
- * in the database.
- *
- * @param cls closure
- * @param denom_pub_hash hash of the revoked denomination key
- * @param master_sig signature affirming the revocation
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_denomination_revocation (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_revocation_insert",
- params);
-}
-
-
-/**
- * Obtain information about a denomination key's revocation from
- * the database.
- *
- * @param cls closure
- * @param denom_pub_hash hash of the revoked denomination key
- * @param[out] master_sig signature affirming the revocation
- * @param[out] rowid row where the information is stored
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_denomination_revocation (
- void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- struct TALER_MasterSignatureP *master_sig,
- uint64_t *rowid)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (denom_pub_hash),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_uint64 ("denom_revocations_serial_id",
- rowid),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "denomination_revocation_get",
- params,
- rs);
-}
-
-
-/**
- * Closure for #missing_wire_cb().
- */
-struct MissingWireContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireMissingCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Set to #GNUNET_SYSERR on error.
- */
- enum GNUNET_GenericReturnValue status;
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-missing_wire_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct MissingWireContext *mwc = cls;
- struct PostgresClosure *pg = mwc->pg;
-
- while (0 < num_results)
- {
- uint64_t rowid;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount amount;
- char *payto_uri;
- struct GNUNET_TIME_Timestamp deadline;
- bool done;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("deposit_serial_id",
- &rowid),
- GNUNET_PQ_result_spec_auto_from_type ("coin_pub",
- &coin_pub),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- &amount),
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_timestamp ("wire_deadline",
- &deadline),
- GNUNET_PQ_result_spec_bool ("done",
- &done),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- --num_results))
- {
- GNUNET_break (0);
- mwc->status = GNUNET_SYSERR;
- return;
- }
- mwc->cb (mwc->cb_cls,
- rowid,
- &coin_pub,
- &amount,
- payto_uri,
- deadline,
- done);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Select all of those deposits in the database for which we do
- * not have a wire transfer (or a refund) and which should have
- * been deposited between @a start_date and @a end_date.
- *
- * @param cls closure
- * @param start_date lower bound on the requested wire execution date
- * @param end_date upper bound on the requested wire execution date
- * @param cb function to call on all such deposits
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_deposits_missing_wire (void *cls,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- TALER_EXCHANGEDB_WireMissingCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_timestamp (&end_date),
- GNUNET_PQ_query_param_end
- };
- struct MissingWireContext mwc = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "deposits_get_overdue",
- params,
- &missing_wire_cb,
- &mwc);
- if (GNUNET_OK != mwc.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Check the last date an auditor was modified.
- *
- * @param cls closure
- * @param auditor_pub key to look up information for
- * @param[out] last_date last modification date to auditor status
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_auditor_timestamp (
- void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- struct GNUNET_TIME_Timestamp *last_date)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_change",
- last_date),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_auditor_timestamp",
- params,
- rs);
-}
-
-
-/**
- * Lookup current state of an auditor.
- *
- * @param cls closure
- * @param auditor_pub key to look up information for
- * @param[out] auditor_url set to the base URL of the auditor's REST API; memory to be
- * released by the caller!
- * @param[out] enabled set if the auditor is currently in use
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_auditor_status (
- void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- char **auditor_url,
- bool *enabled)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("auditor_url",
- auditor_url),
- GNUNET_PQ_result_spec_bool ("is_active",
- enabled),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_auditor_status",
- params,
- rs);
-}
-
-
-/**
- * Insert information about an auditor that will audit this exchange.
- *
- * @param cls closure
- * @param auditor_pub key of the auditor
- * @param auditor_url base URL of the auditor's REST service
- * @param auditor_name name of the auditor (for humans)
- * @param start_date date when the auditor was added by the offline system
- * (only to be used for replay detection)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor (void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- const char *auditor_url,
- const char *auditor_name,
- struct GNUNET_TIME_Timestamp start_date)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_string (auditor_name),
- GNUNET_PQ_query_param_string (auditor_url),
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_auditor",
- params);
-}
-
-
-/**
- * Update information about an auditor that will audit this exchange.
- *
- * @param cls closure
- * @param auditor_pub key of the auditor (primary key for the existing record)
- * @param auditor_url base URL of the auditor's REST service, to be updated
- * @param auditor_name name of the auditor (for humans)
- * @param change_date date when the auditor status was last changed
- * (only to be used for replay detection)
- * @param enabled true to enable, false to disable
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_auditor (void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- const char *auditor_url,
- const char *auditor_name,
- struct GNUNET_TIME_Timestamp change_date,
- bool enabled)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_string (auditor_url),
- GNUNET_PQ_query_param_string (auditor_name),
- GNUNET_PQ_query_param_bool (enabled),
- GNUNET_PQ_query_param_timestamp (&change_date),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_auditor",
- params);
-}
-
-
-/**
- * Check the last date an exchange wire account was modified.
- *
- * @param cls closure
- * @param payto_uri key to look up information for
- * @param[out] last_date last modification date to auditor status
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_wire_timestamp (void *cls,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp *last_date)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("last_change",
- last_date),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_wire_timestamp",
- params,
- rs);
-}
-
-
-/**
- * Insert information about an wire account used by this exchange.
- *
- * @param cls closure
- * @param payto_uri wire account of the exchange
- * @param start_date date when the account was added by the offline system
- * (only to be used for replay detection)
- * @param master_sig public signature affirming the existence of the account,
- * must be of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_wire (void *cls,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp start_date,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_wire",
- params);
-}
-
-
-/**
- * Update information about a wire account of the exchange.
- *
- * @param cls closure
- * @param payto_uri account the update is about
- * @param change_date date when the account status was last changed
- * (only to be used for replay detection)
- * @param enabled true to enable, false to disable (the actual change)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_update_wire (void *cls,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp change_date,
- bool enabled)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (payto_uri),
- GNUNET_PQ_query_param_bool (enabled),
- GNUNET_PQ_query_param_timestamp (&change_date),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "update_wire",
- params);
-}
-
-
-/**
- * Closure for #get_wire_accounts_cb().
- */
-struct GetWireAccountsContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireAccountCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Flag set to #GNUNET_OK as long as everything is fine.
- */
- enum GNUNET_GenericReturnValue status;
-
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_wire_accounts_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetWireAccountsContext *ctx = cls;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- char *payto_uri;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ctx->cb (ctx->cb_cls,
- payto_uri,
- &master_sig);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Obtain information about the enabled wire accounts of the exchange.
- *
- * @param cls closure
- * @param cb function to call on each account
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_accounts (void *cls,
- TALER_EXCHANGEDB_WireAccountCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GetWireAccountsContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .status = GNUNET_OK
- };
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_wire_accounts",
- params,
- &get_wire_accounts_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-
-}
-
-
-/**
- * Closure for #get_wire_fees_cb().
- */
-struct GetWireFeesContext
-{
- /**
- * Function to call per result.
- */
- TALER_EXCHANGEDB_WireFeeCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Flag set to #GNUNET_OK as long as everything is fine.
- */
- enum GNUNET_GenericReturnValue status;
-
-};
-
-
-/**
- * Invoke the callback for each result.
- *
- * @param cls a `struct MissingWireContext *`
- * @param result SQL result
- * @param num_results number of rows in @a result
- */
-static void
-get_wire_fees_cb (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GetWireFeesContext *ctx = cls;
- struct PostgresClosure *pg = ctx->pg;
-
- for (unsigned int i = 0; i < num_results; i++)
- {
- struct TALER_MasterSignatureP master_sig;
- struct TALER_WireFeeSet fees;
- struct GNUNET_TIME_Timestamp start_date;
- struct GNUNET_TIME_Timestamp end_date;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &fees.wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &fees.closing),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wad_fee",
- &fees.wad),
- GNUNET_PQ_result_spec_timestamp ("start_date",
- &start_date),
- GNUNET_PQ_result_spec_timestamp ("end_date",
- &end_date),
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- &master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- ctx->status = GNUNET_SYSERR;
- return;
- }
- ctx->cb (ctx->cb_cls,
- &fees,
- start_date,
- end_date,
- &master_sig);
- GNUNET_PQ_cleanup_result (rs);
- }
-}
-
-
-/**
- * Obtain information about the fee structure of the exchange for
- * a given @a wire_method
- *
- * @param cls closure
- * @param wire_method which wire method to obtain fees for
- * @param cb function to call on each account
- * @param cb_cls closure for @a cb
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_wire_fees (void *cls,
- const char *wire_method,
- TALER_EXCHANGEDB_WireFeeCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (wire_method),
- GNUNET_PQ_query_param_end
- };
- struct GetWireFeesContext ctx = {
- .cb = cb,
- .cb_cls = cb_cls,
- .pg = pg,
- .status = GNUNET_OK
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "get_wire_fees",
- params,
- &get_wire_fees_cb,
- &ctx);
- if (GNUNET_OK != ctx.status)
- return GNUNET_DB_STATUS_HARD_ERROR;
- return qs;
-}
-
-
-/**
- * Store information about a revoked online signing key.
- *
- * @param cls closure
- * @param exchange_pub exchange online signing key that was revoked
- * @param master_sig signature affirming the revocation
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_signkey_revocation (
- void *cls,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_signkey_revocation",
- params);
-}
-
-
-/**
- * Obtain information about a revoked online signing key.
- *
- * @param cls closure
- * @param exchange_pub exchange online signing key
- * @param[out] master_sig set to signature affirming the revocation (if revoked)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_signkey_revocation (
- void *cls,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("master_sig",
- master_sig),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_signkey_revocation",
- params,
- rs);
-}
-
-
-/**
- * Lookup information about current denomination key.
- *
- * @param cls closure
- * @param h_denom_pub hash of the denomination public key
- * @param[out] meta set to various meta data about the key
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_denomination_key (
- void *cls,
- const struct TALER_DenominationHashP *h_denom_pub,
- struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta->start),
- GNUNET_PQ_result_spec_timestamp ("expire_withdraw",
- &meta->expire_withdraw),
- GNUNET_PQ_result_spec_timestamp ("expire_deposit",
- &meta->expire_deposit),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta->expire_legal),
- TALER_PQ_RESULT_SPEC_AMOUNT ("coin",
- &meta->value),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_withdraw",
- &meta->fees.withdraw),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_deposit",
- &meta->fees.deposit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refresh",
- &meta->fees.refresh),
- TALER_PQ_RESULT_SPEC_AMOUNT ("fee_refund",
- &meta->fees.refund),
- GNUNET_PQ_result_spec_uint32 ("age_mask",
- &meta->age_mask.bits),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_denomination_key",
- params,
- rs);
-}
-
-
-/**
- * Activate denomination key, turning it into a "current" or "valid"
- * denomination key by adding the master signature.
- *
- * @param cls closure
- * @param h_denom_pub hash of the denomination public key
- * @param denom_pub the actual denomination key
- * @param meta meta data about the denomination
- * @param master_sig master signature to add
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_add_denomination_key (
- void *cls,
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct TALER_EXCHANGEDB_DenominationKeyMetaData *meta,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- TALER_PQ_query_param_denom_pub (denom_pub),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_timestamp (&meta->start),
- GNUNET_PQ_query_param_timestamp (&meta->expire_withdraw),
- GNUNET_PQ_query_param_timestamp (&meta->expire_deposit),
- GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
- TALER_PQ_query_param_amount (&meta->value),
- TALER_PQ_query_param_amount (&meta->fees.withdraw),
- TALER_PQ_query_param_amount (&meta->fees.deposit),
- TALER_PQ_query_param_amount (&meta->fees.refresh),
- TALER_PQ_query_param_amount (&meta->fees.refund),
- GNUNET_PQ_query_param_uint32 (&meta->age_mask.bits),
- GNUNET_PQ_query_param_end
- };
-
- /* Sanity check: ensure fees match coin currency */
- GNUNET_assert (GNUNET_YES ==
- TALER_denom_fee_check_currency (meta->value.currency,
- &meta->fees));
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "denomination_insert",
- iparams);
-}
-
-
-/**
- * Add signing key.
- *
- * @param cls closure
- * @param exchange_pub the exchange online signing public key
- * @param meta meta data about @a exchange_pub
- * @param master_sig master signature to add
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_activate_signing_key (
- void *cls,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_EXCHANGEDB_SignkeyMetaData *meta,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam iparams[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_timestamp (&meta->start),
- GNUNET_PQ_query_param_timestamp (&meta->expire_sign),
- GNUNET_PQ_query_param_timestamp (&meta->expire_legal),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_signkey",
- iparams);
-}
-
-
-/**
- * Lookup signing key meta data.
- *
- * @param cls closure
- * @param exchange_pub the exchange online signing public key
- * @param[out] meta meta data about @a exchange_pub
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_signing_key (
- void *cls,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- struct TALER_EXCHANGEDB_SignkeyMetaData *meta)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (exchange_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("valid_from",
- &meta->start),
- GNUNET_PQ_result_spec_timestamp ("expire_sign",
- &meta->expire_sign),
- GNUNET_PQ_result_spec_timestamp ("expire_legal",
- &meta->expire_legal),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "lookup_signing_key",
- params,
- rs);
-}
-
-
-/**
- * Insert information about an auditor auditing a denomination key.
- *
- * @param cls closure
- * @param h_denom_pub the audited denomination
- * @param auditor_pub the auditor's key
- * @param auditor_sig signature affirming the auditor's audit activity
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_auditor_denom_sig (
- void *cls,
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- const struct TALER_AuditorSignatureP *auditor_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- GNUNET_PQ_query_param_auto_from_type (auditor_sig),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_auditor_denom_sig",
- params);
-}
-
-
-/**
- * Select information about an auditor auditing a denomination key.
- *
- * @param cls closure
- * @param h_denom_pub the audited denomination
- * @param auditor_pub the auditor's key
- * @param[out] auditor_sig set to signature affirming the auditor's audit activity
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_auditor_denom_sig (
- void *cls,
- const struct TALER_DenominationHashP *h_denom_pub,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- struct TALER_AuditorSignatureP *auditor_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (auditor_pub),
- GNUNET_PQ_query_param_auto_from_type (h_denom_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("auditor_sig",
- auditor_sig),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_auditor_denom_sig",
- params,
- rs);
-}
-
-
-/**
- * Closure for #wire_fee_by_time_helper()
- */
-struct WireFeeLookupContext
-{
-
- /**
- * Set to the wire fees. Set to invalid if fees conflict over
- * the given time period.
- */
- struct TALER_WireFeeSet *fees;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-};
-
-
-/**
- * Helper function for #postgres_lookup_wire_fee_by_time().
- * Calls the callback with the wire fee structure.
- *
- * @param cls a `struct WireFeeLookupContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-wire_fee_by_time_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct WireFeeLookupContext *wlc = cls;
- struct PostgresClosure *pg = wlc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_WireFeeSet fs;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("wire_fee",
- &fs.wire),
- TALER_PQ_RESULT_SPEC_AMOUNT ("closing_fee",
- &fs.closing),
- TALER_PQ_RESULT_SPEC_AMOUNT ("wad_fee",
- &fs.wad),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_WireFeeSet));
- return;
- }
- if (0 == i)
- {
- *wlc->fees = fs;
- continue;
- }
- if (0 !=
- TALER_wire_fee_set_cmp (&fs,
- wlc->fees))
- {
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_WireFeeSet));
- return;
- }
- }
-}
-
-
-/**
- * Lookup information about known wire fees. Finds all applicable
- * fees in the given range. If they are identical, returns the
- * respective @a fees. If any of the fees
- * differ between @a start_time and @a end_time, the transaction
- * succeeds BUT returns an invalid amount for both fees.
- *
- * @param cls closure
- * @param wire_method the wire method to lookup fees for
- * @param start_time starting time of fee
- * @param end_time end time of fee
- * @param[out] fees wire fees for that time period; if
- * different fees exists within this time
- * period, an 'invalid' amount is returned.
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_wire_fee_by_time (
- void *cls,
- const char *wire_method,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- struct TALER_WireFeeSet *fees)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (wire_method),
- GNUNET_PQ_query_param_timestamp (&start_time),
- GNUNET_PQ_query_param_timestamp (&end_time),
- GNUNET_PQ_query_param_end
- };
- struct WireFeeLookupContext wlc = {
- .fees = fees,
- .pg = pg
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_wire_fee_by_time",
- params,
- &wire_fee_by_time_helper,
- &wlc);
-}
-
-
-/**
- * Closure for #global_fee_by_time_helper()
- */
-struct GlobalFeeLookupContext
-{
-
- /**
- * Set to the wire fees. Set to invalid if fees conflict over
- * the given time period.
- */
- struct TALER_GlobalFeeSet *fees;
-
- /**
- * Set to timeout of unmerged purses
- */
- struct GNUNET_TIME_Relative *purse_timeout;
-
- /**
- * Set to timeout of accounts without kyc.
- */
- struct GNUNET_TIME_Relative *kyc_timeout;
-
- /**
- * Set to history expiration for reserves.
- */
- struct GNUNET_TIME_Relative *history_expiration;
-
- /**
- * Set to number of free purses per account.
- */
- uint32_t *purse_account_limit;
-
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-};
-
-
-/**
- * Helper function for #postgres_lookup_global_fee_by_time().
- * Calls the callback with each denomination key.
- *
- * @param cls a `struct GlobalFeeLookupContext`
- * @param result db results
- * @param num_results number of results in @a result
- */
-static void
-global_fee_by_time_helper (void *cls,
- PGresult *result,
- unsigned int num_results)
-{
- struct GlobalFeeLookupContext *wlc = cls;
- struct PostgresClosure *pg = wlc->pg;
-
- for (unsigned int i = 0; i<num_results; i++)
- {
- struct TALER_GlobalFeeSet fs;
- struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
- struct GNUNET_TIME_Relative history_expiration;
- uint32_t purse_account_limit;
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("history_fee",
- &fs.history),
- TALER_PQ_RESULT_SPEC_AMOUNT ("kyc_fee",
- &fs.kyc),
- TALER_PQ_RESULT_SPEC_AMOUNT ("account_fee",
- &fs.account),
- TALER_PQ_RESULT_SPEC_AMOUNT ("purse_fee",
- &fs.purse),
- GNUNET_PQ_result_spec_relative_time ("purse_timeout",
- &purse_timeout),
- GNUNET_PQ_result_spec_relative_time ("kyc_timeout",
- &kyc_timeout),
- GNUNET_PQ_result_spec_relative_time ("history_expiration",
- &history_expiration),
- GNUNET_PQ_result_spec_uint32 ("purse_account_limit",
- &purse_account_limit),
- GNUNET_PQ_result_spec_end
- };
-
- if (GNUNET_OK !=
- GNUNET_PQ_extract_result (result,
- rs,
- i))
- {
- GNUNET_break (0);
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_GlobalFeeSet));
- return;
- }
- if (0 == i)
- {
- *wlc->fees = fs;
- *wlc->purse_timeout = purse_timeout;
- *wlc->kyc_timeout = kyc_timeout;
- *wlc->history_expiration = history_expiration;
- *wlc->purse_account_limit = purse_account_limit;
- continue;
- }
- if ( (0 !=
- TALER_global_fee_set_cmp (&fs,
- wlc->fees)) ||
- (purse_account_limit != *wlc->purse_account_limit) ||
- (GNUNET_TIME_relative_cmp (purse_timeout,
- !=,
- *wlc->purse_timeout)) ||
- (GNUNET_TIME_relative_cmp (kyc_timeout,
- !=,
- *wlc->kyc_timeout)) ||
- (GNUNET_TIME_relative_cmp (history_expiration,
- !=,
- *wlc->history_expiration)) )
- {
- /* invalidate */
- memset (wlc->fees,
- 0,
- sizeof (struct TALER_GlobalFeeSet));
- return;
- }
- }
-}
-
-
-/**
- * Lookup information about known global fees.
- *
- * @param cls closure
- * @param start_time starting time of fee
- * @param end_time end time of fee
- * @param[out] fees set to wire fees for that time period; if
- * different global fee exists within this time
- * period, an 'invalid' amount is returned.
- * @param[out] purse_timeout set to when unmerged purses expire
- * @param[out] kyc_timeout set to when reserves without kyc expire
- * @param[out] history_expiration set to when we expire reserve histories
- * @param[out] purse_account_limit set to number of free purses
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_global_fee_by_time (
- void *cls,
- struct GNUNET_TIME_Timestamp start_time,
- struct GNUNET_TIME_Timestamp end_time,
- struct TALER_GlobalFeeSet *fees,
- struct GNUNET_TIME_Relative *purse_timeout,
- struct GNUNET_TIME_Relative *kyc_timeout,
- struct GNUNET_TIME_Relative *history_expiration,
- uint32_t *purse_account_limit)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_timestamp (&start_time),
- GNUNET_PQ_query_param_timestamp (&end_time),
- GNUNET_PQ_query_param_end
- };
- struct GlobalFeeLookupContext wlc = {
- .fees = fees,
- .purse_timeout = purse_timeout,
- .kyc_timeout = kyc_timeout,
- .history_expiration = history_expiration,
- .purse_account_limit = purse_account_limit,
- .pg = pg
- };
-
- return GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- "lookup_global_fee_by_time",
- params,
- &global_fee_by_time_helper,
- &wlc);
-}
-
-
-/**
- * Lookup the latest serial number of @a table. Used in
- * exchange-auditor database replication.
- *
- * @param cls closure
- * @param table table for which we should return the serial
- * @param[out] serial latest serial number in use
- * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
- * @a table does not have a serial number
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_serial_by_table (void *cls,
- enum TALER_EXCHANGEDB_ReplicatedTable table,
- uint64_t *serial)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("serial",
- serial),
- GNUNET_PQ_result_spec_end
- };
- const char *statement;
-
- switch (table)
- {
- case TALER_EXCHANGEDB_RT_DENOMINATIONS:
- statement = "select_serial_by_table_denominations";
- break;
- case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
- statement = "select_serial_by_table_denomination_revocations";
- break;
- case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
- statement = "select_serial_by_table_wire_targets";
- break;
- case TALER_EXCHANGEDB_RT_RESERVES:
- statement = "select_serial_by_table_reserves";
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_IN:
- statement = "select_serial_by_table_reserves_in";
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
- statement = "select_serial_by_table_reserves_close";
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OUT:
- statement = "select_serial_by_table_reserves_out";
- break;
- case TALER_EXCHANGEDB_RT_AUDITORS:
- statement = "select_serial_by_table_auditors";
- break;
- case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
- statement = "select_serial_by_table_auditor_denom_sigs";
- break;
- case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
- statement = "select_serial_by_table_exchange_sign_keys";
- break;
- case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
- statement = "select_serial_by_table_signkey_revocations";
- break;
- case TALER_EXCHANGEDB_RT_KNOWN_COINS:
- statement = "select_serial_by_table_known_coins";
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
- statement = "select_serial_by_table_refresh_commitments";
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
- statement = "select_serial_by_table_refresh_revealed_coins";
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
- statement = "select_serial_by_table_refresh_transfer_keys";
- break;
- case TALER_EXCHANGEDB_RT_DEPOSITS:
- statement = "select_serial_by_table_deposits";
- break;
- case TALER_EXCHANGEDB_RT_REFUNDS:
- statement = "select_serial_by_table_refunds";
- break;
- case TALER_EXCHANGEDB_RT_WIRE_OUT:
- statement = "select_serial_by_table_wire_out";
- break;
- case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
- statement = "select_serial_by_table_aggregation_tracking";
- break;
- case TALER_EXCHANGEDB_RT_WIRE_FEE:
- statement = "select_serial_by_table_wire_fee";
- break;
- case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
- statement = "select_serial_by_table_global_fee";
- break;
- case TALER_EXCHANGEDB_RT_RECOUP:
- statement = "select_serial_by_table_recoup";
- break;
- case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
- statement = "select_serial_by_table_recoup_refresh";
- break;
- case TALER_EXCHANGEDB_RT_EXTENSIONS:
- statement = "select_serial_by_table_extensions";
- break;
- case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS:
- statement = "select_serial_by_table_extension_details";
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
- statement = "select_serial_by_table_purse_requests";
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REFUNDS:
- statement = "select_serial_by_table_purse_refunds";
- break;
- case TALER_EXCHANGEDB_RT_PURSE_MERGES:
- statement = "select_serial_by_table_purse_merges";
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
- statement = "select_serial_by_table_purse_deposits";
- break;
- case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
- statement = "select_serial_by_table_account_merges";
- break;
- case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
- statement = "select_serial_by_table_history_requests";
- break;
- case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
- statement = "select_serial_by_table_close_requests";
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT:
- statement = "select_serial_by_table_wads_out";
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
- statement = "select_serial_by_table_wads_out_entries";
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN:
- statement = "select_serial_by_table_wads_in";
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
- statement = "select_serial_by_table_wads_in_entries";
- break;
- default:
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- statement,
- params,
- rs);
-}
-
-
-/**
- * Closure for callbacks used by #postgres_lookup_records_by_table.
- */
-struct LookupRecordsByTableContext
-{
- /**
- * Plugin context.
- */
- struct PostgresClosure *pg;
-
- /**
- * Function to call with the results.
- */
- TALER_EXCHANGEDB_ReplicationCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Set to true on errors.
- */
- bool error;
-};
-
-
-#include "lrbt_callbacks.c"
-
-
-/**
- * Lookup records above @a serial number in @a table. Used in
- * exchange-auditor database replication.
- *
- * @param cls closure
- * @param table table for which we should return the serial
- * @param serial largest serial number to exclude
- * @param cb function to call on the records
- * @param cb_cls closure for @a cb
- * @return transaction status code, GNUNET_DB_STATUS_HARD_ERROR if
- * @a table does not have a serial number
- */
-static enum GNUNET_DB_QueryStatus
-postgres_lookup_records_by_table (void *cls,
- enum TALER_EXCHANGEDB_ReplicatedTable table,
- uint64_t serial,
- TALER_EXCHANGEDB_ReplicationCallback cb,
- void *cb_cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&serial),
- GNUNET_PQ_query_param_end
- };
- struct LookupRecordsByTableContext ctx = {
- .pg = pg,
- .cb = cb,
- .cb_cls = cb_cls
- };
- GNUNET_PQ_PostgresResultHandler rh;
- const char *statement;
- enum GNUNET_DB_QueryStatus qs;
-
- switch (table)
- {
- case TALER_EXCHANGEDB_RT_DENOMINATIONS:
- statement = "select_above_serial_by_table_denominations";
- rh = &lrbt_cb_table_denominations;
- break;
- case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
- statement = "select_above_serial_by_table_denomination_revocations";
- rh = &lrbt_cb_table_denomination_revocations;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
- statement = "select_above_serial_by_table_wire_targets";
- rh = &lrbt_cb_table_wire_targets;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES:
- statement = "select_above_serial_by_table_reserves";
- rh = &lrbt_cb_table_reserves;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_IN:
- statement = "select_above_serial_by_table_reserves_in";
- rh = &lrbt_cb_table_reserves_in;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
- statement = "select_above_serial_by_table_reserves_close";
- rh = &lrbt_cb_table_reserves_close;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OUT:
- statement = "select_above_serial_by_table_reserves_out";
- rh = &lrbt_cb_table_reserves_out;
- break;
- case TALER_EXCHANGEDB_RT_AUDITORS:
- statement = "select_above_serial_by_table_auditors";
- rh = &lrbt_cb_table_auditors;
- break;
- case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
- statement = "select_above_serial_by_table_auditor_denom_sigs";
- rh = &lrbt_cb_table_auditor_denom_sigs;
- break;
- case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
- statement = "select_above_serial_by_table_exchange_sign_keys";
- rh = &lrbt_cb_table_exchange_sign_keys;
- break;
- case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
- statement = "select_above_serial_by_table_signkey_revocations";
- rh = &lrbt_cb_table_signkey_revocations;
- break;
- case TALER_EXCHANGEDB_RT_KNOWN_COINS:
- statement = "select_above_serial_by_table_known_coins";
- rh = &lrbt_cb_table_known_coins;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
- statement = "select_above_serial_by_table_refresh_commitments";
- rh = &lrbt_cb_table_refresh_commitments;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
- statement = "select_above_serial_by_table_refresh_revealed_coins";
- rh = &lrbt_cb_table_refresh_revealed_coins;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
- statement = "select_above_serial_by_table_refresh_transfer_keys";
- rh = &lrbt_cb_table_refresh_transfer_keys;
- break;
- case TALER_EXCHANGEDB_RT_DEPOSITS:
- statement = "select_above_serial_by_table_deposits";
- rh = &lrbt_cb_table_deposits;
- break;
- case TALER_EXCHANGEDB_RT_REFUNDS:
- statement = "select_above_serial_by_table_refunds";
- rh = &lrbt_cb_table_refunds;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_OUT:
- statement = "select_above_serial_by_table_wire_out";
- rh = &lrbt_cb_table_wire_out;
- break;
- case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
- statement = "select_above_serial_by_table_aggregation_tracking";
- rh = &lrbt_cb_table_aggregation_tracking;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_FEE:
- statement = "select_above_serial_by_table_wire_fee";
- rh = &lrbt_cb_table_wire_fee;
- break;
- case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
- statement = "select_above_serial_by_table_global_fee";
- rh = &lrbt_cb_table_global_fee;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP:
- statement = "select_above_serial_by_table_recoup";
- rh = &lrbt_cb_table_recoup;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
- statement = "select_above_serial_by_table_recoup_refresh";
- rh = &lrbt_cb_table_recoup_refresh;
- break;
- case TALER_EXCHANGEDB_RT_EXTENSIONS:
- statement = "select_above_serial_by_table_extensions";
- rh = &lrbt_cb_table_extensions;
- break;
- case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS:
- statement = "select_above_serial_by_table_extension_details";
- rh = &lrbt_cb_table_extension_details;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
- statement = "select_above_serial_by_table_purse_requests";
- rh = &lrbt_cb_table_purse_requests;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REFUNDS:
- statement = "select_above_serial_by_table_purse_refunds";
- rh = &lrbt_cb_table_purse_refunds;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_MERGES:
- statement = "select_above_serial_by_table_purse_merges";
- rh = &lrbt_cb_table_purse_merges;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
- statement = "select_above_serial_by_table_purse_deposits";
- rh = &lrbt_cb_table_purse_deposits;
- break;
- case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
- statement = "select_above_serial_by_table_account_merges";
- rh = &lrbt_cb_table_account_merges;
- break;
- case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
- statement = "select_above_serial_by_table_history_requests";
- rh = &lrbt_cb_table_history_requests;
- break;
- case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
- statement = "select_above_serial_by_table_close_requests";
- rh = &lrbt_cb_table_close_requests;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT:
- statement = "select_above_serial_by_table_wads_out";
- rh = &lrbt_cb_table_wads_out;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
- statement = "select_above_serial_by_table_wads_out_entries";
- rh = &lrbt_cb_table_wads_out_entries;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN:
- statement = "select_above_serial_by_table_wads_in";
- rh = &lrbt_cb_table_wads_in;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
- statement = "select_above_serial_by_table_wads_in_entries";
- rh = &lrbt_cb_table_wads_in_entries;
- break;
- default:
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn,
- statement,
- params,
- rh,
- &ctx);
- if (qs < 0)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `%s'\n",
- statement);
- return qs;
- }
- if (ctx.error)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return qs;
-}
-
-
-/**
- * Signature of helper functions of #postgres_insert_records_by_table.
- *
- * @param pg plugin context
- * @param td record to insert
- * @return transaction status code
- */
-typedef enum GNUNET_DB_QueryStatus
-(*InsertRecordCallback)(struct PostgresClosure *pg,
- const struct TALER_EXCHANGEDB_TableData *td);
-
-
-#include "irbt_callbacks.c"
-
-
-/**
- * Insert record set into @a table. Used in exchange-auditor database
- * replication.
- *
- * @param cls closure
- * @param td table data to insert
- * @return transaction status code, #GNUNET_DB_STATUS_HARD_ERROR if
- * @e table in @a tr is not supported
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_records_by_table (void *cls,
- const struct TALER_EXCHANGEDB_TableData *td)
-{
- struct PostgresClosure *pg = cls;
- InsertRecordCallback rh;
-
- switch (td->table)
- {
- case TALER_EXCHANGEDB_RT_DENOMINATIONS:
- rh = &irbt_cb_table_denominations;
- break;
- case TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS:
- rh = &irbt_cb_table_denomination_revocations;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_TARGETS:
- rh = &irbt_cb_table_wire_targets;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES:
- rh = &irbt_cb_table_reserves;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_IN:
- rh = &irbt_cb_table_reserves_in;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_CLOSE:
- rh = &irbt_cb_table_reserves_close;
- break;
- case TALER_EXCHANGEDB_RT_RESERVES_OUT:
- rh = &irbt_cb_table_reserves_out;
- break;
- case TALER_EXCHANGEDB_RT_AUDITORS:
- rh = &irbt_cb_table_auditors;
- break;
- case TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS:
- rh = &irbt_cb_table_auditor_denom_sigs;
- break;
- case TALER_EXCHANGEDB_RT_EXCHANGE_SIGN_KEYS:
- rh = &irbt_cb_table_exchange_sign_keys;
- break;
- case TALER_EXCHANGEDB_RT_SIGNKEY_REVOCATIONS:
- rh = &irbt_cb_table_signkey_revocations;
- break;
- case TALER_EXCHANGEDB_RT_KNOWN_COINS:
- rh = &irbt_cb_table_known_coins;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS:
- rh = &irbt_cb_table_refresh_commitments;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS:
- rh = &irbt_cb_table_refresh_revealed_coins;
- break;
- case TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS:
- rh = &irbt_cb_table_refresh_transfer_keys;
- break;
- case TALER_EXCHANGEDB_RT_DEPOSITS:
- rh = &irbt_cb_table_deposits;
- break;
- case TALER_EXCHANGEDB_RT_REFUNDS:
- rh = &irbt_cb_table_refunds;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_OUT:
- rh = &irbt_cb_table_wire_out;
- break;
- case TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING:
- rh = &irbt_cb_table_aggregation_tracking;
- break;
- case TALER_EXCHANGEDB_RT_WIRE_FEE:
- rh = &irbt_cb_table_wire_fee;
- break;
- case TALER_EXCHANGEDB_RT_GLOBAL_FEE:
- rh = &irbt_cb_table_global_fee;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP:
- rh = &irbt_cb_table_recoup;
- break;
- case TALER_EXCHANGEDB_RT_RECOUP_REFRESH:
- rh = &irbt_cb_table_recoup_refresh;
- break;
- case TALER_EXCHANGEDB_RT_EXTENSIONS:
- rh = &irbt_cb_table_extensions;
- break;
- case TALER_EXCHANGEDB_RT_EXTENSION_DETAILS:
- rh = &irbt_cb_table_extension_details;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REQUESTS:
- rh = &irbt_cb_table_purse_requests;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_REFUNDS:
- rh = &irbt_cb_table_purse_refunds;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_MERGES:
- rh = &irbt_cb_table_purse_merges;
- break;
- case TALER_EXCHANGEDB_RT_PURSE_DEPOSITS:
- rh = &irbt_cb_table_purse_deposits;
- break;
- case TALER_EXCHANGEDB_RT_ACCOUNT_MERGES:
- rh = &irbt_cb_table_account_mergers;
- break;
- case TALER_EXCHANGEDB_RT_HISTORY_REQUESTS:
- rh = &irbt_cb_table_history_requests;
- break;
- case TALER_EXCHANGEDB_RT_CLOSE_REQUESTS:
- rh = &irbt_cb_table_close_requests;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT:
- rh = &irbt_cb_table_wads_out;
- break;
- case TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES:
- rh = &irbt_cb_table_wads_out_entries;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN:
- rh = &irbt_cb_table_wads_in;
- break;
- case TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES:
- rh = &irbt_cb_table_wads_in_entries;
- break;
- default:
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- return rh (pg,
- td);
-}
-
-
-/**
- * Function called to grab a work shard on an operation @a op. Runs in its
- * own transaction.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param job_name name of the operation to grab a word shard for
- * @param delay minimum age of a shard to grab
- * @param shard_size desired shard size
- * @param[out] start_row inclusive start row of the shard (returned)
- * @param[out] end_row exclusive end row of the shard (returned)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_begin_shard (void *cls,
- const char *job_name,
- struct GNUNET_TIME_Relative delay,
- uint64_t shard_size,
- uint64_t *start_row,
- uint64_t *end_row)
-{
- struct PostgresClosure *pg = cls;
-
- for (unsigned int retries = 0; retries<10; retries++)
- {
- if (GNUNET_OK !=
- postgres_start (pg,
- "begin_shard"))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- {
- struct GNUNET_TIME_Absolute past;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_absolute_time (&past),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("start_row",
- start_row),
- GNUNET_PQ_result_spec_uint64 ("end_row",
- end_row),
- GNUNET_PQ_result_spec_end
- };
-
- past = GNUNET_TIME_absolute_get ();
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_open_shard",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- {
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Absolute now;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_uint64 (start_row),
- GNUNET_PQ_query_param_uint64 (end_row),
- GNUNET_PQ_query_param_end
- };
-
- now = GNUNET_TIME_relative_to_absolute (delay);
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reclaim_shard",
- params);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- goto commit;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- GNUNET_break (0); /* logic error, should be impossible */
- postgres_rollback (pg);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- break; /* actually unreachable */
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- break; /* continued below */
- }
- } /* get_open_shard */
-
- /* No open shard, find last 'end_row' */
- {
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint64 ("end_row",
- start_row),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_last_shard",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- break;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- *start_row = 0; /* base-case: no shards yet */
- break; /* continued below */
- }
- *end_row = *start_row + shard_size;
- } /* get_last_shard */
-
- /* Claim fresh shard */
- {
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Absolute now;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_uint64 (start_row),
- GNUNET_PQ_query_param_uint64 (end_row),
- GNUNET_PQ_query_param_end
- };
-
- now = GNUNET_TIME_relative_to_absolute (delay);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Trying to claim shard (%llu-%llu]\n",
- (unsigned long long) *start_row,
- (unsigned long long) *end_row);
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "claim_next_shard",
- params);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* continued below */
- break;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* someone else got this shard already,
- try again */
- postgres_rollback (pg);
- continue;
- }
- } /* claim_next_shard */
-
- /* commit */
-commit:
- {
- enum GNUNET_DB_QueryStatus qs;
-
- qs = postgres_commit (pg);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
- }
- } /* retry 'for' loop */
- return GNUNET_DB_STATUS_SOFT_ERROR;
-}
-
-
-/**
- * Function called to abort work on a shard.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param job_name name of the operation to abort a word shard for
- * @param start_row inclusive start row of the shard
- * @param end_row exclusive end row of the shard
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_abort_shard (void *cls,
- const char *job_name,
- uint64_t start_row,
- uint64_t end_row)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_uint64 (&start_row),
- GNUNET_PQ_query_param_uint64 (&end_row),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "abort_shard",
- params);
-}
-
-
-/**
- * Function called to persist that work on a shard was completed.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param job_name name of the operation to grab a word shard for
- * @param start_row inclusive start row of the shard
- * @param end_row exclusive end row of the shard
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-postgres_complete_shard (void *cls,
- const char *job_name,
- uint64_t start_row,
- uint64_t end_row)
-{
- struct PostgresClosure *pg = cls;
-
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_uint64 (&start_row),
- GNUNET_PQ_query_param_uint64 (&end_row),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Completing shard %llu-%llu\n",
- (unsigned long long) start_row,
- (unsigned long long) end_row);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "complete_shard",
- params);
-}
-
-
-/**
- * Function called to grab a revolving work shard on an operation @a op. Runs
- * in its own transaction. Returns the oldest inactive shard.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param job_name name of the operation to grab a revolving shard for
- * @param shard_size desired shard size
- * @param shard_limit exclusive end of the shard range
- * @param[out] start_row inclusive start row of the shard (returned)
- * @param[out] end_row inclusive end row of the shard (returned)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_begin_revolving_shard (void *cls,
- const char *job_name,
- uint32_t shard_size,
- uint32_t shard_limit,
- uint32_t *start_row,
- uint32_t *end_row)
-{
- struct PostgresClosure *pg = cls;
-
- GNUNET_assert (shard_limit <= 1U + (uint32_t) INT_MAX);
- GNUNET_assert (shard_limit > 0);
- GNUNET_assert (shard_size > 0);
- for (unsigned int retries = 0; retries<3; retries++)
- {
- if (GNUNET_OK !=
- postgres_start (pg,
- "begin_revolving_shard"))
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
-
- /* First, find last 'end_row' */
- {
- enum GNUNET_DB_QueryStatus qs;
- uint32_t last_end;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint32 ("end_row",
- &last_end),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_last_revolving_shard",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- *start_row = 1U + last_end;
- break;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- *start_row = 0; /* base-case: no shards yet */
- break; /* continued below */
- }
- } /* get_last_shard */
-
- if (*start_row < shard_limit)
- {
- /* Claim fresh shard */
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Absolute now;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_absolute_time (&now),
- GNUNET_PQ_query_param_uint32 (start_row),
- GNUNET_PQ_query_param_uint32 (end_row),
- GNUNET_PQ_query_param_end
- };
-
- *end_row = GNUNET_MIN (shard_limit,
- *start_row + shard_size - 1);
- now = GNUNET_TIME_absolute_get ();
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Trying to claim shard %llu-%llu\n",
- (unsigned long long) *start_row,
- (unsigned long long) *end_row);
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "create_revolving_shard",
- params);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- /* continued below (with commit) */
- break;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* someone else got this shard already,
- try again */
- postgres_rollback (pg);
- continue;
- }
- } /* end create fresh reovlving shard */
- else
- {
- /* claim oldest existing shard */
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_uint32 ("start_row",
- start_row),
- GNUNET_PQ_result_spec_uint32 ("end_row",
- end_row),
- GNUNET_PQ_result_spec_end
- };
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_open_revolving_shard",
- params,
- rs);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- /* no open shards available */
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- {
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Timestamp now;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_uint32 (start_row),
- GNUNET_PQ_query_param_uint32 (end_row),
- GNUNET_PQ_query_param_end
- };
-
- now = GNUNET_TIME_timestamp_get ();
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "reclaim_revolving_shard",
- params);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- break; /* continue with commit */
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- GNUNET_break (0); /* logic error, should be impossible */
- postgres_rollback (pg);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- }
- break; /* continue with commit */
- }
- } /* end claim oldest existing shard */
-
- /* commit */
- {
- enum GNUNET_DB_QueryStatus qs;
-
- qs = postgres_commit (pg);
- switch (qs)
- {
- case GNUNET_DB_STATUS_HARD_ERROR:
- GNUNET_break (0);
- postgres_rollback (pg);
- return qs;
- case GNUNET_DB_STATUS_SOFT_ERROR:
- postgres_rollback (pg);
- continue;
- case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS:
- case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT:
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
- }
- } /* retry 'for' loop */
- return GNUNET_DB_STATUS_SOFT_ERROR;
-}
-
-
-/**
- * Function called to release a revolving shard
- * back into the work pool. Clears the
- * "completed" flag.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param job_name name of the operation to grab a word shard for
- * @param start_row inclusive start row of the shard
- * @param end_row exclusive end row of the shard
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-postgres_release_revolving_shard (void *cls,
- const char *job_name,
- uint32_t start_row,
- uint32_t end_row)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (job_name),
- GNUNET_PQ_query_param_uint32 (&start_row),
- GNUNET_PQ_query_param_uint32 (&end_row),
- GNUNET_PQ_query_param_end
- };
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Releasing revolving shard %s %u-%u\n",
- job_name,
- (unsigned int) start_row,
- (unsigned int) end_row);
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "release_revolving_shard",
- params);
-}
-
-
-/**
- * Function called to delete all revolving shards.
- * To be used after a crash or when the shard size is
- * changed.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-postgres_delete_shard_locks (void *cls)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_execute ("DELETE FROM work_shards;"),
- GNUNET_PQ_make_execute ("DELETE FROM revolving_work_shards;"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- return GNUNET_PQ_exec_statements (pg->conn,
- es);
-}
-
-
-/**
- * Function called to save the configuration of an extension
- * (age-restriction, peer2peer, ...). After successful storage of the
- * configuration it triggers the corresponding event.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param extension_name the name of the extension
- * @param config JSON object of the configuration as string
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-postgres_set_extension_config (void *cls,
- const char *extension_name,
- const char *config)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam pcfg =
- (NULL == config || 0 == *config)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (config);
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (extension_name),
- pcfg,
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "set_extension_config",
- params);
-}
-
-
-/**
- * Function called to get the configuration of an extension
- * (age-restriction, peer2peer, ...)
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param extension_name the name of the extension
- * @param[out] config JSON object of the configuration as string
- * @return transaction status code
- */
-enum GNUNET_DB_QueryStatus
-postgres_get_extension_config (void *cls,
- const char *extension_name,
- char **config)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_string (extension_name),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("config",
- config),
- &is_null),
- GNUNET_PQ_result_spec_end
- };
-
- *config = NULL;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "get_extension_config",
- params,
- rs);
-}
-
-
-/**
- * Function called to store configuration data about a partner
- * exchange that we are federated with.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub public offline signing key of the partner exchange
- * @param start_date when does the following data start to be valid
- * @param end_date when does the validity end (exclusive)
- * @param wad_frequency how often do we do exchange-to-exchange settlements?
- * @param wad_fee how much do we charge for transfers to the partner
- * @param partner_base_url base URL of the partner exchange
- * @param master_sig signature with our offline signing key affirming the above
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_partner (void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- struct GNUNET_TIME_Relative wad_frequency,
- const struct TALER_Amount *wad_fee,
- const char *partner_base_url,
- const struct TALER_MasterSignatureP *master_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (master_pub),
- GNUNET_PQ_query_param_timestamp (&start_date),
- GNUNET_PQ_query_param_timestamp (&end_date),
- GNUNET_PQ_query_param_relative_time (&wad_frequency),
- TALER_PQ_query_param_amount (wad_fee),
- GNUNET_PQ_query_param_auto_from_type (master_sig),
- GNUNET_PQ_query_param_string (partner_base_url),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_partner",
- params);
-}
-
-
-/**
- * Function called to retrieve an encrypted contract.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub key to lookup the contract by
- * @param[out] pub_ckey set to the ephemeral DH used to encrypt the contract
- * @param[out] econtract_sig set to the signature over the encrypted contract
- * @param[out] econtract_size set to the number of bytes in @a econtract
- * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_contract (void *cls,
- const struct TALER_ContractDiffiePublicP *pub_ckey,
- struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_PurseContractSignatureP *econtract_sig,
- size_t *econtract_size,
- void **econtract)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (pub_ckey),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- purse_pub),
- GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
- econtract_sig),
- GNUNET_PQ_result_spec_variable_size ("e_contract",
- econtract,
- econtract_size),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_contract",
- params,
- rs);
-
-}
-
-
-/**
- * Function called to retrieve an encrypted contract.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub key to lookup the contract by
- * @param[out] econtract set to the encrypted contract on success, to be freed by the caller
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_contract_by_purse (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_EncryptedContract *econtract)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("pub_ckey",
- &econtract->contract_pub),
- GNUNET_PQ_result_spec_auto_from_type ("contract_sig",
- &econtract->econtract_sig),
- GNUNET_PQ_result_spec_variable_size ("e_contract",
- &econtract->econtract,
- &econtract->econtract_size),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_contract_by_purse",
- params,
- rs);
-
-}
-
-
-/**
- * Function called to persist an encrypted contract associated with a reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub the purse the contract is associated with (must exist)
- * @param econtract the encrypted contract
- * @param[out] in_conflict set to true if @a econtract
- * conflicts with an existing contract;
- * in this case, the return value will be
- * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_contract (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_EncryptedContract *econtract,
- bool *in_conflict)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (&econtract->contract_pub),
- GNUNET_PQ_query_param_fixed_size (econtract->econtract,
- econtract->econtract_size),
- GNUNET_PQ_query_param_auto_from_type (&econtract->econtract_sig),
- GNUNET_PQ_query_param_end
- };
-
- *in_conflict = false;
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_contract",
- params);
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
- return qs;
- {
- struct TALER_EncryptedContract econtract2;
-
- qs = postgres_select_contract_by_purse (pg,
- purse_pub,
- &econtract2);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (0 == GNUNET_memcmp (&econtract->contract_pub,
- &econtract2.contract_pub)) &&
- (econtract2.econtract_size ==
- econtract->econtract_size) &&
- (0 == memcmp (econtract2.econtract,
- econtract->econtract,
- econtract->econtract_size)) )
- {
- GNUNET_free (econtract2.econtract);
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- GNUNET_free (econtract2.econtract);
- *in_conflict = true;
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
-}
-
-
-/**
- * Function called to return meta data about a purse by the
- * purse public key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub public key of the purse
- * @param[out] merge_pub public key representing the merge capability
- * @param[out] purse_expiration when would an unmerged purse expire
- * @param[out] h_contract_terms contract associated with the purse
- * @param[out] age_limit the age limit for deposits into the purse
- * @param[out] target_amount amount to be put into the purse
- * @param[out] balance amount put so far into the purse
- * @param[out] purse_sig signature of the purse over the initialization data
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_request (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_PurseMergePublicKeyP *merge_pub,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t *age_limit,
- struct TALER_Amount *target_amount,
- struct TALER_Amount *balance,
- struct TALER_PurseContractSignatureP *purse_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merge_pub",
- merge_pub),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- purse_expiration),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- h_contract_terms),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- age_limit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- target_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- balance),
- GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
- purse_sig),
- GNUNET_PQ_result_spec_end
- };
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_request",
- params,
- rs);
-}
-
-
-/**
- * Function called to create a new purse with certain meta data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub public key of the new purse
- * @param merge_pub public key providing the merge capability
- * @param purse_expiration time when the purse will expire
- * @param h_contract_terms hash of the contract for the purse
- * @param age_limit age limit to enforce for payments into the purse
- * @param flags flags for the operation
- * @param purse_fee fee we are allowed to charge to the reserve (depending on @a flags)
- * @param amount target amount (with fees) to be put into the purse
- * @param purse_sig signature with @a purse_pub's private key affirming the above
- * @param[out] in_conflict set to true if the meta data
- * conflicts with an existing purse;
- * in this case, the return value will be
- * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_purse_request (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- struct GNUNET_TIME_Timestamp purse_expiration,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t age_limit,
- enum TALER_WalletAccountMergeFlags flags,
- const struct TALER_Amount *purse_fee,
- const struct TALER_Amount *amount,
- const struct TALER_PurseContractSignatureP *purse_sig,
- bool *in_conflict)
-{
- struct PostgresClosure *pg = cls;
- enum GNUNET_DB_QueryStatus qs;
- struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get ();
- uint32_t flags32 = (uint32_t) flags;
- bool in_reserve_quota = (TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA
- == (flags & TALER_WAMF_MERGE_MODE_MASK));
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (merge_pub),
- GNUNET_PQ_query_param_timestamp (&now),
- GNUNET_PQ_query_param_timestamp (&purse_expiration),
- GNUNET_PQ_query_param_auto_from_type (h_contract_terms),
- GNUNET_PQ_query_param_uint32 (&age_limit),
- GNUNET_PQ_query_param_uint32 (&flags32),
- GNUNET_PQ_query_param_bool (in_reserve_quota),
- TALER_PQ_query_param_amount (amount),
- TALER_PQ_query_param_amount (purse_fee),
- GNUNET_PQ_query_param_auto_from_type (purse_sig),
- GNUNET_PQ_query_param_end
- };
-
- *in_conflict = false;
- qs = GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "insert_purse_request",
- params);
- if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs)
- return qs;
- {
- struct TALER_PurseMergePublicKeyP merge_pub2;
- struct GNUNET_TIME_Timestamp purse_expiration2;
- struct TALER_PrivateContractHashP h_contract_terms2;
- uint32_t age_limit2;
- struct TALER_Amount amount2;
- struct TALER_Amount balance;
- struct TALER_PurseContractSignatureP purse_sig2;
-
- qs = postgres_select_purse_request (pg,
- purse_pub,
- &merge_pub2,
- &purse_expiration2,
- &h_contract_terms2,
- &age_limit2,
- &amount2,
- &balance,
- &purse_sig2);
- if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs)
- {
- GNUNET_break (0);
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- if ( (age_limit2 == age_limit) &&
- (0 == TALER_amount_cmp (amount,
- &amount2)) &&
- (0 == GNUNET_memcmp (&h_contract_terms2,
- h_contract_terms)) &&
- (0 == GNUNET_memcmp (&merge_pub2,
- merge_pub)) )
- {
- return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
- }
- *in_conflict = true;
- return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
- }
-}
-
-
-/**
- * Function called to clean up one expired purse.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param start_time select purse expired after this time
- * @param end_time select purse expired before this time
- * @return transaction status code (#GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no purse expired in the given time interval).
- */
-static enum GNUNET_DB_QueryStatus
-postgres_expire_purse (
- void *cls,
- struct GNUNET_TIME_Absolute start_time,
- struct GNUNET_TIME_Absolute end_time)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_absolute_time (&start_time),
- GNUNET_PQ_query_param_absolute_time (&end_time),
- GNUNET_PQ_query_param_end
- };
- bool found = false;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("found",
- &found),
- GNUNET_PQ_result_spec_end
- };
- enum GNUNET_DB_QueryStatus qs;
-
- qs = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_expire_purse",
- params,
- rs);
- if (qs < 0)
- return qs;
- GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
- return found
- ? GNUNET_DB_STATUS_SUCCESS_ONE_RESULT
- : GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
-}
-
-
-/**
- * Function called to obtain information about a purse.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub public key of the new purse
- * @param[out] purse_expiration set to time when the purse will expire
- * @param[out] amount set to target amount (with fees) to be put into the purse
- * @param[out] deposited set to actual amount put into the purse so far
- * @param[out] h_contract_terms set to hash of the contract for the purse
- * @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_Amount *amount,
- struct TALER_Amount *deposited,
- struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp *merge_timestamp)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- purse_expiration),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- deposited),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- h_contract_terms),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- merge_timestamp),
- NULL),
- GNUNET_PQ_result_spec_end
- };
-
- *merge_timestamp = GNUNET_TIME_UNIT_FOREVER_TS;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse",
- params,
- rs);
-}
-
-
-/**
- * Function called to return meta data about a purse by the
- * merge capability key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param merge_pub public key representing the merge capability
- * @param[out] purse_pub public key of the purse
- * @param[out] purse_expiration when would an unmerged purse expire
- * @param[out] h_contract_terms contract associated with the purse
- * @param[out] age_limit the age limit for deposits into the purse
- * @param[out] target_amount amount to be put into the purse
- * @param[out] balance amount put so far into the purse
- * @param[out] purse_sig signature of the purse over the initialization data
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_by_merge_pub (
- void *cls,
- const struct TALER_PurseMergePublicKeyP *merge_pub,
- struct TALER_PurseContractPublicKeyP *purse_pub,
- struct GNUNET_TIME_Timestamp *purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
- uint32_t *age_limit,
- struct TALER_Amount *target_amount,
- struct TALER_Amount *balance,
- struct TALER_PurseContractSignatureP *purse_sig)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (merge_pub),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("purse_pub",
- purse_pub),
- GNUNET_PQ_result_spec_timestamp ("purse_expiration",
- purse_expiration),
- GNUNET_PQ_result_spec_auto_from_type ("h_contract_terms",
- h_contract_terms),
- GNUNET_PQ_result_spec_uint32 ("age_limit",
- age_limit),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- target_amount),
- TALER_PQ_RESULT_SPEC_AMOUNT ("balance",
- balance),
- GNUNET_PQ_result_spec_auto_from_type ("purse_sig",
- purse_sig),
- GNUNET_PQ_result_spec_end
- };
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_by_merge_pub",
- params,
- rs);
-}
-
-
-/**
- * Function called to execute a transaction crediting
- * a purse with @a amount from @a coin_pub. Reduces the
- * value of @a coin_pub and increase the balance of
- * the @a purse_pub purse. If the balance reaches the
- * target amount and the purse has been merged, triggers
- * the updates of the reserve/account balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub purse to credit
- * @param coin_pub coin to deposit (debit)
- * @param amount fraction of the coin's value to deposit
- * @param coin_sig signature affirming the operation
- * @param amount_minus_fee amount to add to the purse
- * @param[out] balance_ok set to false if the coin's
- * remaining balance is below @a amount;
- * in this case, the return value will be
- * #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
- * @param[out] conflict set to true if the deposit failed due to a conflict (coin already spent,
- * or deposited into this purse with a different amount)
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_purse_deposit (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *amount,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_Amount *amount_minus_fee,
- bool *balance_ok,
- bool *conflict)
-{
- struct PostgresClosure *pg = cls;
- uint64_t partner_id = 0; /* FIXME: WAD support... */
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_uint64 (&partner_id),
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- TALER_PQ_query_param_amount (amount),
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_auto_from_type (coin_sig),
- TALER_PQ_query_param_amount (amount_minus_fee),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("conflict",
- conflict),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_purse_deposit",
- params,
- rs);
-}
-
-
-/**
- * Set the current @a balance in the purse
- * identified by @a purse_pub. Used by the auditor
- * to update the balance as calculated by the auditor.
- *
- * @param cls closure
- * @param purse_pub public key of a purse
- * @param balance new balance to store under the purse
- * @return transaction status
- */
-static enum GNUNET_DB_QueryStatus
-postgres_set_purse_balance (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_Amount *balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- TALER_PQ_query_param_amount (balance),
- GNUNET_PQ_query_param_end
- };
-
- return GNUNET_PQ_eval_prepared_non_select (pg->conn,
- "set_purse_balance",
- params);
-}
-
-
-/**
- * Function called to obtain a coin deposit data from
- * depositing the coin into a purse.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub purse to credit
- * @param coin_pub coin to deposit (debit)
- * @param[out] amount set fraction of the coin's value that was deposited (with fee)
- * @param[out] h_denom_pub set to hash of denomination of the coin
- * @param[out] phac set to hash of age restriction on the coin
- * @param[out] coin_sig set to signature affirming the operation
- * @param[out] partner_url set to the URL of the partner exchange, or NULL for ourselves, must be freed by caller
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_get_purse_deposit (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- struct TALER_Amount *amount,
- struct TALER_DenominationHashP *h_denom_pub,
- struct TALER_AgeCommitmentHash *phac,
- struct TALER_CoinSpendSignatureP *coin_sig,
- char **partner_url)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (coin_pub),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("denom_pub_hash",
- h_denom_pub),
- GNUNET_PQ_result_spec_auto_from_type ("age_commitment_hash",
- phac),
- GNUNET_PQ_result_spec_auto_from_type ("coin_sig",
- coin_sig),
- TALER_PQ_RESULT_SPEC_AMOUNT ("amount_with_fee",
- amount),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- partner_url),
- &is_null),
- GNUNET_PQ_result_spec_end
- };
-
- *partner_url = NULL;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_deposit_by_coin_pub",
- params,
- rs);
-}
-
-
-/**
- * Function called to approve merging a purse into a
- * reserve by the respective purse merge key.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub purse to merge
- * @param merge_sig signature affirming the merge
- * @param merge_timestamp time of the merge
- * @param reserve_sig signature of the reserve affirming the merge
- * @param partner_url URL of the partner exchange, can be NULL if the reserves lives with us
- * @param reserve_pub public key of the reserve to credit
- * @param require_kyc true if we should check for KYC
- * @param[out] no_partner set to true if @a partner_url is unknown
- * @param[out] no_balance set to true if the @a purse_pub is not paid up yet
- * @param[out] no_reserve set to true if the @a reserve_pub is not known
- * @param[out] no_kyc set to true if the @a reserve_pub lacks KYC
- * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_purse_merge (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct GNUNET_TIME_Timestamp merge_timestamp,
- const struct TALER_ReserveSignatureP *reserve_sig,
- const char *partner_url,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- bool require_kyc,
- bool *no_partner,
- bool *no_balance,
- bool *no_reserve,
- bool *no_kyc,
- bool *in_conflict)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (merge_sig),
- GNUNET_PQ_query_param_timestamp (&merge_timestamp),
- GNUNET_PQ_query_param_auto_from_type (reserve_sig),
- (NULL == partner_url)
- ? GNUNET_PQ_query_param_null ()
- : GNUNET_PQ_query_param_string (partner_url),
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_bool (require_kyc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("no_partner",
- no_partner),
- GNUNET_PQ_result_spec_bool ("no_balance",
- no_balance),
- GNUNET_PQ_result_spec_bool ("no_kyc",
- no_kyc),
- GNUNET_PQ_result_spec_bool ("no_reserve",
- no_reserve),
- GNUNET_PQ_result_spec_bool ("conflict",
- in_conflict),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_purse_merge",
- params,
- rs);
-}
-
-
-/**
- * Function called insert request to merge a purse into a reserve by the
- * respective purse merge key. The purse must not have been merged into a
- * different reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub purse to merge
- * @param merge_sig signature affirming the merge
- * @param merge_timestamp time of the merge
- * @param reserve_sig signature of the reserve affirming the merge
- * @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota
- * @param reserve_pub public key of the reserve to credit
- * @param require_kyc true if we should check for KYC
- * @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
- * @param[out] no_reserve set to true if @a reserve_pub is not a known reserve
- * @param[out] no_kyc set to true if @a reserve_pub has not passed KYC checks
- * @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_do_reserve_purse (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- const struct TALER_PurseMergeSignatureP *merge_sig,
- const struct GNUNET_TIME_Timestamp merge_timestamp,
- const struct TALER_ReserveSignatureP *reserve_sig,
- const struct TALER_Amount *purse_fee,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- bool require_kyc,
- bool *in_conflict,
- bool *no_reserve,
- bool *no_kyc,
- bool *insufficient_funds)
-{
- struct PostgresClosure *pg = cls;
- struct TALER_Amount zero_fee;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_auto_from_type (merge_sig),
- GNUNET_PQ_query_param_timestamp (&merge_timestamp),
- GNUNET_PQ_query_param_auto_from_type (reserve_sig),
- GNUNET_PQ_query_param_bool (NULL == purse_fee),
- TALER_PQ_query_param_amount (NULL == purse_fee
- ? &zero_fee
- : purse_fee),
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_bool (require_kyc),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("insufficient_funds",
- insufficient_funds),
- GNUNET_PQ_result_spec_bool ("conflict",
- in_conflict),
- GNUNET_PQ_result_spec_bool ("no_kyc",
- no_kyc),
- GNUNET_PQ_result_spec_bool ("no_reserve",
- no_reserve),
- GNUNET_PQ_result_spec_end
- };
-
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (pg->currency,
- &zero_fee));
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_reserve_purse",
- params,
- rs);
-}
-
-
-/**
- * Function called to approve merging of a purse with
- * an account, made by the receiving account.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param purse_pub public key of the purse
- * @param[out] merge_sig set to the signature confirming the merge
- * @param[out] merge_timestamp set to the time of the merge
- * @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller.
- * @param[out] reserve_pub set to the public key of the reserve/account being credited
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_select_purse_merge (
- void *cls,
- const struct TALER_PurseContractPublicKeyP *purse_pub,
- struct TALER_PurseMergeSignatureP *merge_sig,
- struct GNUNET_TIME_Timestamp *merge_timestamp,
- char **partner_url,
- struct TALER_ReservePublicKeyP *reserve_pub)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (purse_pub),
- GNUNET_PQ_query_param_end
- };
- bool is_null;
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_auto_from_type ("merge_sig",
- merge_sig),
- GNUNET_PQ_result_spec_auto_from_type ("reserve_pub",
- reserve_pub),
- GNUNET_PQ_result_spec_timestamp ("merge_timestamp",
- merge_timestamp),
- GNUNET_PQ_result_spec_allow_null (
- GNUNET_PQ_result_spec_string ("partner_base_url",
- partner_url),
- &is_null),
- GNUNET_PQ_result_spec_end
- };
-
- *partner_url = NULL;
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "select_purse_merge",
- params,
- rs);
-}
-
-
-/**
- * Function called to persist a signature that
- * prove that the client requested an
- * account history. Debits the @a history_fee from
- * the reserve (if possible).
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub account that the history was requested for
- * @param reserve_sig signature affirming the request
- * @param request_timestamp when was the request made
- * @param history_fee how much should the @a reserve_pub be charged for the request
- * @param[out] balance_ok set to TRUE if the reserve balance
- * was sufficient
- * @param[out] idempotent set to TRUE if the request is already in the DB
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_history_request (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp request_timestamp,
- const struct TALER_Amount *history_fee,
- bool *balance_ok,
- bool *idempotent)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_auto_from_type (reserve_sig),
- GNUNET_PQ_query_param_timestamp (&request_timestamp),
- TALER_PQ_query_param_amount (history_fee),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- GNUNET_PQ_result_spec_bool ("balance_ok",
- balance_ok),
- GNUNET_PQ_result_spec_bool ("idempotent",
- idempotent),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_history_request",
- params,
- rs);
-}
-
-
-/**
- * Function called to initiate closure of an account.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the account to close
- * @param reserve_sig signature affiming that the account is to be closed
- * @param[out] final_balance set to the final balance in the account that will be wired back to the origin account
- * @return transaction status code
- */
-static enum GNUNET_DB_QueryStatus
-postgres_insert_close_request (
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp request_timestamp,
- struct TALER_Amount *final_balance)
-{
- struct PostgresClosure *pg = cls;
- struct GNUNET_PQ_QueryParam params[] = {
- GNUNET_PQ_query_param_auto_from_type (reserve_pub),
- GNUNET_PQ_query_param_timestamp (&request_timestamp),
- GNUNET_PQ_query_param_auto_from_type (reserve_sig),
- GNUNET_PQ_query_param_end
- };
- struct GNUNET_PQ_ResultSpec rs[] = {
- TALER_PQ_RESULT_SPEC_AMOUNT ("out_final_balance",
- final_balance),
- GNUNET_PQ_result_spec_end
- };
-
- return GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
- "call_account_close",
- params,
- rs);
-}
-
-
-/**
* Initialize Postgres database subsystem.
*
* @param cls a configuration instance
@@ -15951,6 +321,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg;
struct TALER_EXCHANGEDB_Plugin *plugin;
+ unsigned long long dpl;
pg = GNUNET_new (struct PostgresClosure);
pg->cfg = cfg;
@@ -15962,7 +333,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchangedb-postgres",
- "CONFIG");
+ "SQL_DIR");
GNUNET_free (pg);
return NULL;
}
@@ -15979,21 +350,29 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
GNUNET_free (pg);
return NULL;
}
- if ( (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "exchangedb",
- "IDLE_RESERVE_EXPIRATION_TIME",
- &pg->idle_reserve_expiration_time))
- ||
- (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (cfg,
- "exchangedb",
- "LEGAL_RESERVE_EXPIRATION_TIME",
- &pg->legal_reserve_expiration_time)) )
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "exchangedb",
+ "IDLE_RESERVE_EXPIRATION_TIME",
+ &pg->idle_reserve_expiration_time))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"exchangedb",
- "LEGAL/IDLE_RESERVE_EXPIRATION_TIME");
+ "IDLE_RESERVE_EXPIRATION_TIME");
+ GNUNET_free (pg->exchange_url);
+ GNUNET_free (pg->sql_dir);
+ GNUNET_free (pg);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ "exchangedb",
+ "LEGAL_RESERVE_EXPIRATION_TIME",
+ &pg->legal_reserve_expiration_time))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchangedb",
+ "LEGAL_RESERVE_EXPIRATION_TIME");
GNUNET_free (pg->exchange_url);
GNUNET_free (pg->sql_dir);
GNUNET_free (pg);
@@ -16009,6 +388,21 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
"exchangedb",
"AGGREGATOR_SHIFT");
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "exchangedb",
+ "DEFAULT_PURSE_LIMIT",
+ &dpl))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+ "exchangedb",
+ "DEFAULT_PURSE_LIMIT");
+ pg->def_purse_limit = 1;
+ }
+ else
+ {
+ pg->def_purse_limit = (uint32_t) dpl;
+ }
if (GNUNET_OK !=
TALER_config_get_currency (cfg,
@@ -16020,8 +414,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
return NULL;
}
if (GNUNET_OK !=
- internal_setup (pg,
- true))
+ TEH_PG_internal_setup (pg))
{
GNUNET_free (pg->exchange_url);
GNUNET_free (pg->currency);
@@ -16029,231 +422,378 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
GNUNET_free (pg);
return NULL;
}
-
plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin);
plugin->cls = pg;
- plugin->drop_tables = &postgres_drop_tables;
- plugin->drop_shard_tables = &postgres_drop_shard_tables;
- plugin->create_tables = &postgres_create_tables;
- plugin->create_shard_tables = &postgres_create_shard_tables;
- plugin->setup_partitions = &postgres_setup_partitions;
- plugin->setup_foreign_servers = &postgres_setup_foreign_servers;
- plugin->start = &postgres_start;
- plugin->start_read_committed = &postgres_start_read_committed;
- plugin->commit = &postgres_commit;
- plugin->preflight = &postgres_preflight;
- plugin->rollback = &postgres_rollback;
- plugin->event_listen = &postgres_event_listen;
- plugin->event_listen_cancel = &postgres_event_listen_cancel;
- plugin->event_notify = &postgres_event_notify;
- plugin->insert_denomination_info = &postgres_insert_denomination_info;
- plugin->get_denomination_info = &postgres_get_denomination_info;
- plugin->iterate_denomination_info = &postgres_iterate_denomination_info;
- plugin->iterate_denominations = &postgres_iterate_denominations;
- plugin->iterate_active_signkeys = &postgres_iterate_active_signkeys;
- plugin->iterate_active_auditors = &postgres_iterate_active_auditors;
- plugin->iterate_auditor_denominations =
- &postgres_iterate_auditor_denominations;
- plugin->select_kyc_status = &postgres_select_kyc_status;
- plugin->reserves_get = &postgres_reserves_get;
- plugin->set_kyc_ok = &postgres_set_kyc_ok;
- plugin->inselect_wallet_kyc_status = &postgres_inselect_wallet_kyc_status;
- plugin->reserves_in_insert = &postgres_reserves_in_insert;
- plugin->get_withdraw_info = &postgres_get_withdraw_info;
- plugin->do_withdraw = &postgres_do_withdraw;
- plugin->do_batch_withdraw = &postgres_do_batch_withdraw;
- plugin->do_batch_withdraw_insert = &postgres_do_batch_withdraw_insert;
- plugin->do_withdraw_limit_check = &postgres_do_withdraw_limit_check;
- plugin->do_deposit = &postgres_do_deposit;
- plugin->do_melt = &postgres_do_melt;
- plugin->do_refund = &postgres_do_refund;
- plugin->do_recoup = &postgres_do_recoup;
- plugin->do_recoup_refresh = &postgres_do_recoup_refresh;
- plugin->get_reserve_balance = &postgres_get_reserve_balance;
- plugin->get_reserve_history = &postgres_get_reserve_history;
- plugin->get_reserve_status = &postgres_get_reserve_status;
- plugin->free_reserve_history = &common_free_reserve_history;
- plugin->count_known_coins = &postgres_count_known_coins;
- plugin->ensure_coin_known = &postgres_ensure_coin_known;
- plugin->get_known_coin = &postgres_get_known_coin;
- plugin->get_coin_denomination = &postgres_get_coin_denomination;
- plugin->have_deposit2 = &postgres_have_deposit2;
- plugin->aggregate = &postgres_aggregate;
- plugin->create_aggregation_transient
- = &postgres_create_aggregation_transient;
- plugin->select_aggregation_transient
- = &postgres_select_aggregation_transient;
- plugin->update_aggregation_transient
- = &postgres_update_aggregation_transient;
+ plugin->do_reserve_open
+ = &TEH_PG_do_reserve_open;
+ plugin->drop_tables
+ = &TEH_PG_drop_tables;
+ plugin->free_coin_transaction_list
+ = &TEH_COMMON_free_coin_transaction_list;
+ plugin->free_reserve_history
+ = &TEH_COMMON_free_reserve_history;
+ plugin->get_coin_transactions
+ = &TEH_PG_get_coin_transactions;
+ plugin->get_expired_reserves
+ = &TEH_PG_get_expired_reserves;
+ plugin->get_purse_request
+ = &TEH_PG_get_purse_request;
+ plugin->get_reserve_history
+ = &TEH_PG_get_reserve_history;
+ plugin->get_unfinished_close_requests
+ = &TEH_PG_get_unfinished_close_requests;
+ plugin->insert_records_by_table
+ = &TEH_PG_insert_records_by_table;
+ plugin->insert_reserve_open_deposit
+ = &TEH_PG_insert_reserve_open_deposit;
+ plugin->insert_close_request
+ = &TEH_PG_insert_close_request;
plugin->delete_aggregation_transient
- = &postgres_delete_aggregation_transient;
- plugin->get_ready_deposit = &postgres_get_ready_deposit;
- plugin->insert_deposit = &postgres_insert_deposit;
- plugin->insert_refund = &postgres_insert_refund;
- plugin->select_refunds_by_coin = &postgres_select_refunds_by_coin;
- plugin->get_melt = &postgres_get_melt;
- plugin->insert_refresh_reveal = &postgres_insert_refresh_reveal;
- plugin->get_refresh_reveal = &postgres_get_refresh_reveal;
- plugin->get_link_data = &postgres_get_link_data;
- plugin->get_coin_transactions = &postgres_get_coin_transactions;
- plugin->free_coin_transaction_list = &common_free_coin_transaction_list;
- plugin->lookup_wire_transfer = &postgres_lookup_wire_transfer;
- plugin->lookup_transfer_by_deposit = &postgres_lookup_transfer_by_deposit;
- plugin->insert_aggregation_tracking = &postgres_insert_aggregation_tracking;
- plugin->insert_wire_fee = &postgres_insert_wire_fee;
- plugin->insert_global_fee = &postgres_insert_global_fee;
- plugin->get_wire_fee = &postgres_get_wire_fee;
- plugin->get_global_fee = &postgres_get_global_fee;
- plugin->get_global_fees = &postgres_get_global_fees;
- plugin->get_expired_reserves = &postgres_get_expired_reserves;
- plugin->insert_reserve_closed = &postgres_insert_reserve_closed;
- plugin->wire_prepare_data_insert = &postgres_wire_prepare_data_insert;
- plugin->wire_prepare_data_mark_finished =
- &postgres_wire_prepare_data_mark_finished;
- plugin->wire_prepare_data_mark_failed =
- &postgres_wire_prepare_data_mark_failed;
- plugin->wire_prepare_data_get = &postgres_wire_prepare_data_get;
- plugin->start_deferred_wire_out = &postgres_start_deferred_wire_out;
- plugin->store_wire_transfer_out = &postgres_store_wire_transfer_out;
- plugin->gc = &postgres_gc;
- plugin->select_deposits_above_serial_id
- = &postgres_select_deposits_above_serial_id;
- plugin->select_purse_deposits_above_serial_id
- = &postgres_select_purse_deposits_above_serial_id;
+ = &TEH_PG_delete_aggregation_transient;
+ plugin->get_link_data
+ = &TEH_PG_get_link_data;
+ plugin->iterate_reserve_close_info
+ = &TEH_PG_iterate_reserve_close_info;
+ plugin->iterate_kyc_reference
+ = &TEH_PG_iterate_kyc_reference;
+ plugin->lookup_records_by_table
+ = &TEH_PG_lookup_records_by_table;
+ plugin->lookup_serial_by_table
+ = &TEH_PG_lookup_serial_by_table;
plugin->select_account_merges_above_serial_id
- = &postgres_select_account_merges_above_serial_id;
+ = &TEH_PG_select_account_merges_above_serial_id;
+ plugin->select_all_purse_decisions_above_serial_id
+ = &TEH_PG_select_all_purse_decisions_above_serial_id;
+ plugin->select_aml_threshold
+ = &TEH_PG_select_aml_threshold;
+ plugin->select_purse
+ = &TEH_PG_select_purse;
+ plugin->select_purse_deposits_above_serial_id
+ = &TEH_PG_select_purse_deposits_above_serial_id;
plugin->select_purse_merges_above_serial_id
- = &postgres_select_purse_merges_above_serial_id;
- plugin->select_history_requests_above_serial_id
- = &postgres_select_history_requests_above_serial_id;
- plugin->select_purse_refunds_above_serial_id
- = &postgres_select_purse_refunds_above_serial_id;
+ = &TEH_PG_select_purse_merges_above_serial_id;
+ plugin->select_purse_requests_above_serial_id
+ = &TEH_PG_select_purse_requests_above_serial_id;
+ plugin->select_reserve_close_info
+ = &TEH_PG_select_reserve_close_info;
+ plugin->select_reserve_closed_above_serial_id
+ = &TEH_PG_select_reserve_closed_above_serial_id;
+ plugin->select_reserve_open_above_serial_id
+ = &TEH_PG_select_reserve_open_above_serial_id;
+ plugin->insert_purse_request
+ = &TEH_PG_insert_purse_request;
+ plugin->iterate_active_signkeys
+ = &TEH_PG_iterate_active_signkeys;
+ plugin->commit
+ = &TEH_PG_commit;
+ plugin->preflight
+ = &TEH_PG_preflight;
+ plugin->select_aggregation_amounts_for_kyc_check
+ = &TEH_PG_select_aggregation_amounts_for_kyc_check;
+ plugin->select_satisfied_kyc_processes
+ = &TEH_PG_select_satisfied_kyc_processes;
+ plugin->kyc_provider_account_lookup
+ = &TEH_PG_kyc_provider_account_lookup;
+ plugin->lookup_kyc_requirement_by_row
+ = &TEH_PG_lookup_kyc_requirement_by_row;
+ plugin->insert_kyc_requirement_for_account
+ = &TEH_PG_insert_kyc_requirement_for_account;
+ plugin->lookup_kyc_process_by_account
+ = &TEH_PG_lookup_kyc_process_by_account;
+ plugin->update_kyc_process_by_row
+ = &TEH_PG_update_kyc_process_by_row;
+ plugin->insert_kyc_requirement_process
+ = &TEH_PG_insert_kyc_requirement_process;
+ plugin->select_withdraw_amounts_for_kyc_check
+ = &TEH_PG_select_withdraw_amounts_for_kyc_check;
+ plugin->select_merge_amounts_for_kyc_check
+ = &TEH_PG_select_merge_amounts_for_kyc_check;
+ plugin->profit_drains_set_finished
+ = &TEH_PG_profit_drains_set_finished;
+ plugin->profit_drains_get_pending
+ = &TEH_PG_profit_drains_get_pending;
+ plugin->get_drain_profit
+ = &TEH_PG_get_drain_profit;
+ plugin->get_purse_deposit
+ = &TEH_PG_get_purse_deposit;
+ plugin->insert_contract
+ = &TEH_PG_insert_contract;
+ plugin->select_contract
+ = &TEH_PG_select_contract;
+ plugin->select_purse_merge
+ = &TEH_PG_select_purse_merge;
+ plugin->select_contract_by_purse
+ = &TEH_PG_select_contract_by_purse;
+ plugin->insert_drain_profit
+ = &TEH_PG_insert_drain_profit;
+ plugin->do_reserve_purse
+ = &TEH_PG_do_reserve_purse;
+ plugin->lookup_global_fee_by_time
+ = &TEH_PG_lookup_global_fee_by_time;
+ plugin->do_purse_deposit
+ = &TEH_PG_do_purse_deposit;
+ plugin->activate_signing_key
+ = &TEH_PG_activate_signing_key;
+ plugin->update_auditor
+ = &TEH_PG_update_auditor;
+ plugin->begin_revolving_shard
+ = &TEH_PG_begin_revolving_shard;
+ plugin->get_extension_manifest
+ = &TEH_PG_get_extension_manifest;
+ plugin->do_purse_merge
+ = &TEH_PG_do_purse_merge;
+ plugin->do_purse_delete
+ = &TEH_PG_do_purse_delete;
+ plugin->start_read_committed
+ = &TEH_PG_start_read_committed;
+ plugin->start_read_only
+ = &TEH_PG_start_read_only;
+ plugin->insert_denomination_info
+ = &TEH_PG_insert_denomination_info;
+ plugin->do_batch_withdraw_insert
+ = &TEH_PG_do_batch_withdraw_insert;
+ plugin->lookup_wire_fee_by_time
+ = &TEH_PG_lookup_wire_fee_by_time;
+ plugin->start
+ = &TEH_PG_start;
+ plugin->rollback
+ = &TEH_PG_rollback;
+ plugin->create_tables
+ = &TEH_PG_create_tables;
+ plugin->event_listen
+ = &TEH_PG_event_listen;
+ plugin->event_listen_cancel
+ = &TEH_PG_event_listen_cancel;
+ plugin->event_notify
+ = &TEH_PG_event_notify;
+ plugin->get_denomination_info
+ = &TEH_PG_get_denomination_info;
+ plugin->iterate_denomination_info
+ = &TEH_PG_iterate_denomination_info;
+ plugin->iterate_denominations
+ = &TEH_PG_iterate_denominations;
+ plugin->iterate_active_auditors
+ = &TEH_PG_iterate_active_auditors;
+ plugin->iterate_auditor_denominations
+ = &TEH_PG_iterate_auditor_denominations;
+ plugin->reserves_get
+ = &TEH_PG_reserves_get;
+ plugin->reserves_get_origin
+ = &TEH_PG_reserves_get_origin;
+ plugin->drain_kyc_alert
+ = &TEH_PG_drain_kyc_alert;
+ plugin->reserves_in_insert
+ = &TEH_PG_reserves_in_insert;
+ plugin->get_withdraw_info
+ = &TEH_PG_get_withdraw_info;
+ plugin->do_batch_withdraw
+ = &TEH_PG_do_batch_withdraw;
+ plugin->do_age_withdraw
+ = &TEH_PG_do_age_withdraw;
+ plugin->get_age_withdraw
+ = &TEH_PG_get_age_withdraw;
+ plugin->get_policy_details
+ = &TEH_PG_get_policy_details;
+ plugin->persist_policy_details
+ = &TEH_PG_persist_policy_details;
+ plugin->do_deposit
+ = &TEH_PG_do_deposit;
+ plugin->get_wire_hash_for_contract
+ = &TEH_PG_get_wire_hash_for_contract;
+ plugin->add_policy_fulfillment_proof
+ = &TEH_PG_add_policy_fulfillment_proof;
+ plugin->do_melt
+ = &TEH_PG_do_melt;
+ plugin->do_refund
+ = &TEH_PG_do_refund;
+ plugin->do_recoup
+ = &TEH_PG_do_recoup;
+ plugin->do_recoup_refresh
+ = &TEH_PG_do_recoup_refresh;
+ plugin->get_reserve_balance
+ = &TEH_PG_get_reserve_balance;
+ plugin->count_known_coins
+ = &TEH_PG_count_known_coins;
+ plugin->ensure_coin_known
+ = &TEH_PG_ensure_coin_known;
+ plugin->get_known_coin
+ = &TEH_PG_get_known_coin;
+ plugin->get_signature_for_known_coin
+ = &TEH_PG_get_signature_for_known_coin;
+ plugin->get_coin_denomination
+ = &TEH_PG_get_coin_denomination;
+ plugin->have_deposit2
+ = &TEH_PG_have_deposit2;
+ plugin->aggregate
+ = &TEH_PG_aggregate;
+ plugin->create_aggregation_transient
+ = &TEH_PG_create_aggregation_transient;
+ plugin->select_aggregation_transient
+ = &TEH_PG_select_aggregation_transient;
+ plugin->find_aggregation_transient
+ = &TEH_PG_find_aggregation_transient;
+ plugin->update_aggregation_transient
+ = &TEH_PG_update_aggregation_transient;
+ plugin->get_ready_deposit
+ = &TEH_PG_get_ready_deposit;
+ plugin->insert_refund
+ = &TEH_PG_insert_refund;
+ plugin->select_refunds_by_coin
+ = &TEH_PG_select_refunds_by_coin;
+ plugin->get_melt
+ = &TEH_PG_get_melt;
+ plugin->insert_refresh_reveal
+ = &TEH_PG_insert_refresh_reveal;
+ plugin->get_refresh_reveal
+ = &TEH_PG_get_refresh_reveal;
+ plugin->lookup_wire_transfer
+ = &TEH_PG_lookup_wire_transfer;
+ plugin->lookup_transfer_by_deposit
+ = &TEH_PG_lookup_transfer_by_deposit;
+ plugin->insert_wire_fee
+ = &TEH_PG_insert_wire_fee;
+ plugin->insert_global_fee
+ = &TEH_PG_insert_global_fee;
+ plugin->get_wire_fee
+ = &TEH_PG_get_wire_fee;
+ plugin->get_global_fee
+ = &TEH_PG_get_global_fee;
+ plugin->get_global_fees
+ = &TEH_PG_get_global_fees;
+ plugin->insert_reserve_closed
+ = &TEH_PG_insert_reserve_closed;
+ plugin->wire_prepare_data_insert
+ = &TEH_PG_wire_prepare_data_insert;
+ plugin->wire_prepare_data_mark_finished
+ = &TEH_PG_wire_prepare_data_mark_finished;
+ plugin->wire_prepare_data_mark_failed
+ = &TEH_PG_wire_prepare_data_mark_failed;
+ plugin->wire_prepare_data_get
+ = &TEH_PG_wire_prepare_data_get;
+ plugin->start_deferred_wire_out
+ = &TEH_PG_start_deferred_wire_out;
+ plugin->store_wire_transfer_out
+ = &TEH_PG_store_wire_transfer_out;
+ plugin->gc
+ = &TEH_PG_gc;
+ plugin->select_coin_deposits_above_serial_id
+ = &TEH_PG_select_coin_deposits_above_serial_id;
+ plugin->select_purse_decisions_above_serial_id
+ = &TEH_PG_select_purse_decisions_above_serial_id;
plugin->select_purse_deposits_by_purse
- = &postgres_select_purse_deposits_by_purse;
+ = &TEH_PG_select_purse_deposits_by_purse;
plugin->select_refreshes_above_serial_id
- = &postgres_select_refreshes_above_serial_id;
+ = &TEH_PG_select_refreshes_above_serial_id;
plugin->select_refunds_above_serial_id
- = &postgres_select_refunds_above_serial_id;
+ = &TEH_PG_select_refunds_above_serial_id;
plugin->select_reserves_in_above_serial_id
- = &postgres_select_reserves_in_above_serial_id;
+ = &TEH_PG_select_reserves_in_above_serial_id;
plugin->select_reserves_in_above_serial_id_by_account
- = &postgres_select_reserves_in_above_serial_id_by_account;
+ = &TEH_PG_select_reserves_in_above_serial_id_by_account;
plugin->select_withdrawals_above_serial_id
- = &postgres_select_withdrawals_above_serial_id;
+ = &TEH_PG_select_withdrawals_above_serial_id;
plugin->select_wire_out_above_serial_id
- = &postgres_select_wire_out_above_serial_id;
+ = &TEH_PG_select_wire_out_above_serial_id;
plugin->select_wire_out_above_serial_id_by_account
- = &postgres_select_wire_out_above_serial_id_by_account;
+ = &TEH_PG_select_wire_out_above_serial_id_by_account;
plugin->select_recoup_above_serial_id
- = &postgres_select_recoup_above_serial_id;
+ = &TEH_PG_select_recoup_above_serial_id;
plugin->select_recoup_refresh_above_serial_id
- = &postgres_select_recoup_refresh_above_serial_id;
- plugin->select_reserve_closed_above_serial_id
- = &postgres_select_reserve_closed_above_serial_id;
+ = &TEH_PG_select_recoup_refresh_above_serial_id;
plugin->get_reserve_by_h_blind
- = &postgres_get_reserve_by_h_blind;
+ = &TEH_PG_get_reserve_by_h_blind;
plugin->get_old_coin_by_h_blind
- = &postgres_get_old_coin_by_h_blind;
+ = &TEH_PG_get_old_coin_by_h_blind;
plugin->insert_denomination_revocation
- = &postgres_insert_denomination_revocation;
+ = &TEH_PG_insert_denomination_revocation;
plugin->get_denomination_revocation
- = &postgres_get_denomination_revocation;
- plugin->select_deposits_missing_wire
- = &postgres_select_deposits_missing_wire;
+ = &TEH_PG_get_denomination_revocation;
+ plugin->select_batch_deposits_missing_wire
+ = &TEH_PG_select_batch_deposits_missing_wire;
+ plugin->select_justification_for_missing_wire
+ = &TEH_PG_select_justification_for_missing_wire;
+ plugin->select_aggregations_above_serial
+ = &TEH_PG_select_aggregations_above_serial;
plugin->lookup_auditor_timestamp
- = &postgres_lookup_auditor_timestamp;
+ = &TEH_PG_lookup_auditor_timestamp;
plugin->lookup_auditor_status
- = &postgres_lookup_auditor_status;
+ = &TEH_PG_lookup_auditor_status;
plugin->insert_auditor
- = &postgres_insert_auditor;
- plugin->update_auditor
- = &postgres_update_auditor;
+ = &TEH_PG_insert_auditor;
plugin->lookup_wire_timestamp
- = &postgres_lookup_wire_timestamp;
+ = &TEH_PG_lookup_wire_timestamp;
plugin->insert_wire
- = &postgres_insert_wire;
+ = &TEH_PG_insert_wire;
plugin->update_wire
- = &postgres_update_wire;
+ = &TEH_PG_update_wire;
plugin->get_wire_accounts
- = &postgres_get_wire_accounts;
+ = &TEH_PG_get_wire_accounts;
plugin->get_wire_fees
- = &postgres_get_wire_fees;
+ = &TEH_PG_get_wire_fees;
plugin->insert_signkey_revocation
- = &postgres_insert_signkey_revocation;
+ = &TEH_PG_insert_signkey_revocation;
plugin->lookup_signkey_revocation
- = &postgres_lookup_signkey_revocation;
+ = &TEH_PG_lookup_signkey_revocation;
plugin->lookup_denomination_key
- = &postgres_lookup_denomination_key;
+ = &TEH_PG_lookup_denomination_key;
plugin->insert_auditor_denom_sig
- = &postgres_insert_auditor_denom_sig;
+ = &TEH_PG_insert_auditor_denom_sig;
plugin->select_auditor_denom_sig
- = &postgres_select_auditor_denom_sig;
- plugin->lookup_wire_fee_by_time
- = &postgres_lookup_wire_fee_by_time;
- plugin->lookup_global_fee_by_time
- = &postgres_lookup_global_fee_by_time;
+ = &TEH_PG_select_auditor_denom_sig;
plugin->add_denomination_key
- = &postgres_add_denomination_key;
- plugin->activate_signing_key
- = &postgres_activate_signing_key;
+ = &TEH_PG_add_denomination_key;
plugin->lookup_signing_key
- = &postgres_lookup_signing_key;
- plugin->lookup_serial_by_table
- = &postgres_lookup_serial_by_table;
- plugin->lookup_records_by_table
- = &postgres_lookup_records_by_table;
- plugin->insert_records_by_table
- = &postgres_insert_records_by_table;
+ = &TEH_PG_lookup_signing_key;
plugin->begin_shard
- = &postgres_begin_shard;
+ = &TEH_PG_begin_shard;
plugin->abort_shard
- = &postgres_abort_shard;
+ = &TEH_PG_abort_shard;
+ plugin->insert_kyc_failure
+ = &TEH_PG_insert_kyc_failure;
plugin->complete_shard
- = &postgres_complete_shard;
- plugin->begin_revolving_shard
- = &postgres_begin_revolving_shard;
+ = &TEH_PG_complete_shard;
plugin->release_revolving_shard
- = &postgres_release_revolving_shard;
+ = &TEH_PG_release_revolving_shard;
plugin->delete_shard_locks
- = &postgres_delete_shard_locks;
- plugin->set_extension_config
- = &postgres_set_extension_config;
- plugin->get_extension_config
- = &postgres_get_extension_config;
+ = &TEH_PG_delete_shard_locks;
+ plugin->set_extension_manifest
+ = &TEH_PG_set_extension_manifest;
plugin->insert_partner
- = &postgres_insert_partner;
- plugin->insert_contract
- = &postgres_insert_contract;
- plugin->select_contract
- = &postgres_select_contract;
- plugin->select_contract_by_purse
- = &postgres_select_contract_by_purse;
- plugin->insert_purse_request
- = &postgres_insert_purse_request;
- plugin->select_purse_request
- = &postgres_select_purse_request;
+ = &TEH_PG_insert_partner;
plugin->expire_purse
- = &postgres_expire_purse;
- plugin->select_purse
- = &postgres_select_purse;
+ = &TEH_PG_expire_purse;
plugin->select_purse_by_merge_pub
- = &postgres_select_purse_by_merge_pub;
- plugin->do_purse_deposit
- = &postgres_do_purse_deposit;
+ = &TEH_PG_select_purse_by_merge_pub;
plugin->set_purse_balance
- = &postgres_set_purse_balance;
- plugin->get_purse_deposit
- = &postgres_get_purse_deposit;
- plugin->do_purse_merge
- = &postgres_do_purse_merge;
- plugin->do_reserve_purse
- = &postgres_do_reserve_purse;
- plugin->select_purse_merge
- = &postgres_select_purse_merge;
- plugin->insert_history_request
- = &postgres_insert_history_request;
- plugin->insert_close_request
- = &postgres_insert_close_request;
+ = &TEH_PG_set_purse_balance;
+ plugin->get_pending_kyc_requirement_process
+ = &TEH_PG_get_pending_kyc_requirement_process;
+ plugin->insert_kyc_attributes
+ = &TEH_PG_insert_kyc_attributes;
+ plugin->select_similar_kyc_attributes
+ = &TEH_PG_select_similar_kyc_attributes;
+ plugin->select_kyc_attributes
+ = &TEH_PG_select_kyc_attributes;
+ plugin->insert_aml_officer
+ = &TEH_PG_insert_aml_officer;
+ plugin->test_aml_officer
+ = &TEH_PG_test_aml_officer;
+ plugin->lookup_aml_officer
+ = &TEH_PG_lookup_aml_officer;
+ plugin->trigger_aml_process
+ = &TEH_PG_trigger_aml_process;
+ plugin->select_aml_process
+ = &TEH_PG_select_aml_process;
+ plugin->select_aml_history
+ = &TEH_PG_select_aml_history;
+ plugin->insert_aml_decision
+ = &TEH_PG_insert_aml_decision;
+
+ plugin->batch_ensure_coin_known
+ = &TEH_PG_batch_ensure_coin_known;
+ plugin->inject_auditor_triggers
+ = &TEH_PG_inject_auditor_triggers;
+
return plugin;
}
diff --git a/src/exchangedb/procedures.sql.in b/src/exchangedb/procedures.sql.in
new file mode 100644
index 000000000..7afb01f0b
--- /dev/null
+++ b/src/exchangedb/procedures.sql.in
@@ -0,0 +1,49 @@
+--
+-- This file is part of TALER
+-- Copyright (C) 2014--2022 Taler Systems SA
+--
+-- TALER is free software; you can redistribute it and/or modify it under the
+-- terms of the GNU General Public License as published by the Free Software
+-- Foundation; either version 3, or (at your option) any later version.
+--
+-- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+-- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+--
+
+BEGIN;
+
+SET search_path TO exchange;
+
+#include "exchange_do_amount_specific.sql"
+#include "exchange_do_batch_withdraw.sql"
+#include "exchange_do_batch_withdraw_insert.sql"
+#include "exchange_do_age_withdraw.sql"
+#include "exchange_do_deposit.sql"
+#include "exchange_do_melt.sql"
+#include "exchange_do_select_deposits_missing_wire.sql"
+#include "exchange_do_select_justification_for_missing_wire.sql"
+#include "exchange_do_refund.sql"
+#include "exchange_do_recoup_to_reserve.sql"
+#include "exchange_do_recoup_to_coin.sql"
+#include "exchange_do_gc.sql"
+#include "exchange_do_purse_delete.sql"
+#include "exchange_do_purse_deposit.sql"
+#include "exchange_do_purse_merge.sql"
+#include "exchange_do_reserve_purse.sql"
+#include "exchange_do_expire_purse.sql"
+#include "exchange_do_reserve_open_deposit.sql"
+#include "exchange_do_reserve_open.sql"
+#include "exchange_do_insert_or_update_policy_details.sql"
+#include "exchange_do_insert_aml_decision.sql"
+#include "exchange_do_insert_aml_officer.sql"
+#include "exchange_do_insert_kyc_attributes.sql"
+#include "exchange_do_reserves_in_insert.sql"
+#include "exchange_do_batch_reserves_update.sql"
+#include "exchange_do_get_link_data.sql"
+#include "exchange_do_batch_coin_known.sql"
+
+COMMIT;
diff --git a/src/exchangedb/shard-0001-part.sql b/src/exchangedb/shard-0001-part.sql
deleted file mode 100644
index e642fe65e..000000000
--- a/src/exchangedb/shard-0001-part.sql
+++ /dev/null
@@ -1,273 +0,0 @@
---
--- This file is part of TALER
--- Copyright (C) 2014--2022 Taler Systems SA
---
--- TALER is free software; you can redistribute it and/or modify it under the
--- terms of the GNU General Public License as published by the Free Software
--- Foundation; either version 3, or (at your option) any later version.
---
--- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
--- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
--- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
---
--- You should have received a copy of the GNU General Public License along with
--- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
---
-
--- Everything in one big transaction
-BEGIN;
-
--- Check patch versioning is in place.
-SELECT _v.register_patch('shard-0001', NULL, NULL);
-
-CREATE OR REPLACE FUNCTION setup_shard(
- shard_idx INTEGER
-)
-RETURNS VOID
-LANGUAGE plpgsql
-AS $$
-DECLARE
- shard_suffix VARCHAR;
-BEGIN
-
- shard_suffix = shard_idx::varchar;
-
- PERFORM create_table_wire_targets(shard_suffix);
- PERFORM add_constraints_to_wire_targets_partition(shard_suffix);
-
- PERFORM create_table_reserves(shard_suffix);
-
- PERFORM create_table_reserves_in(shard_suffix);
- PERFORM add_constraints_to_reserves_in_partition(shard_suffix);
-
- PERFORM create_table_reserves_close(shard_suffix);
-
- PERFORM create_table_reserves_out(shard_suffix);
-
- PERFORM create_table_reserves_out_by_reserve(shard_suffix);
-
- PERFORM create_table_known_coins(shard_suffix);
- PERFORM add_constraints_to_known_coins_partition(shard_suffix);
-
- PERFORM create_table_refresh_commitments(shard_suffix);
- PERFORM add_constraints_to_refresh_commitments_partition(shard_suffix);
-
- PERFORM create_table_refresh_revealed_coins(shard_suffix);
- PERFORM add_constraints_to_refresh_revealed_coins_partition(shard_suffix);
-
- PERFORM create_table_refresh_transfer_keys(shard_suffix);
- PERFORM add_constraints_to_refresh_transfer_keys_partition(shard_suffix);
-
- PERFORM create_table_deposits(shard_suffix);
- PERFORM add_constraints_to_deposits_partition(shard_suffix);
-
- PERFORM create_table_deposits_by_ready(shard_suffix);
-
- PERFORM create_table_deposits_for_matching(shard_suffix);
-
- PERFORM create_table_refunds(shard_suffix);
- PERFORM add_constraints_to_refunds_partition(shard_suffix);
-
- PERFORM create_table_wire_out(shard_suffix);
- PERFORM add_constraints_to_wire_out_partition(shard_suffix);
-
- PERFORM create_table_aggregation_transient(shard_suffix);
-
- PERFORM create_table_aggregation_tracking(shard_suffix);
- PERFORM add_constraints_to_aggregation_tracking_partition(shard_suffix);
-
- PERFORM create_table_recoup(shard_suffix);
- PERFORM add_constraints_to_recoup_partition(shard_suffix);
-
- PERFORM create_table_recoup_by_reserve(shard_suffix);
-
- PERFORM create_table_recoup_refresh(shard_suffix);
- PERFORM add_constraints_to_recoup_refresh_partition(shard_suffix);
-
- PERFORM create_table_prewire(shard_suffix);
-
- PERFORM create_table_cs_nonce_locks(shard_suffix);
- PERFORM add_constraints_to_cs_nonce_locks_partition(shard_suffix);
-
- PERFORM create_table_purse_requests(shard_suffix);
- PERFORM add_constraints_to_purse_requests_partition(shard_suffix);
-
- PERFORM create_table_purse_refunds(shard_suffix);
- PERFORM add_constraints_to_purse_refunds_partition(shard_suffix);
-
- PERFORM create_table_purse_merges(shard_suffix);
- PERFORM add_constraints_to_purse_merges_partition(shard_suffix);
-
- PERFORM create_table_account_merges(shard_suffix);
- PERFORM add_constraints_to_account_merges_partition(shard_suffix);
-
- PERFORM create_table_contracts(shard_suffix);
- PERFORM add_constraints_to_contracts_partition(shard_suffix);
-
- PERFORM create_table_history_requests(shard_suffix);
-
- PERFORM create_table_close_requests(shard_suffix);
-
- PERFORM create_table_purse_deposits(shard_suffix);
- PERFORM add_constraints_to_purse_deposits_partition(shard_suffix);
-
- PERFORM create_table_wad_out_entries(shard_suffix);
- PERFORM add_constraints_to_wad_out_entries_partition(shard_suffix);
-
- PERFORM create_table_wads_in(shard_suffix);
- PERFORM add_constraints_to_wads_in_partition(shard_suffix);
-
- PERFORM create_table_wad_in_entries(shard_suffix);
- PERFORM add_constraints_to_wad_in_entries_partition(shard_suffix);
-END
-$$;
-
-
-CREATE OR REPLACE FUNCTION drop_shard(
- shard_idx INTEGER
-)
- RETURNS VOID
- LANGUAGE plpgsql
-AS $$
-DECLARE
- shard_suffix VARCHAR;
-BEGIN
-
- shard_suffix = shard_idx::varchar;
-
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'wire_targets_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'reserves_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'reserves_in_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'reserves_out_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'reserves_close_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'known_coins_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'refresh_commitments_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'refresh_revealed_coins_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'refresh_transfer_keys_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'deposits_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'deposits_by_ready_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'deposits_for_matching_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'refunds_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'wire_out_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'aggregation_transient_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'aggregation_tracking_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'recoup_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'recoup_by_reserve_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'reserves_out_by_reserve_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'recoup_refresh_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'prewire_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'cs_nonce_locks_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'purse_requests_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'purse_refunds_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'purse_merges_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'account_merges_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'contracts_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'history_requests_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'close_requests_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'purse_deposits_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'wad_out_entries_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'wads_in_' || shard_suffix
- );
- EXECUTE FORMAT(
- 'DROP TABLE IF EXISTS %I CASCADE'
- ,'wad_in_entries_' || shard_suffix
- );
-END
-$$;
-
-COMMIT;
diff --git a/src/exchangedb/spi/Makefile b/src/exchangedb/spi/Makefile
new file mode 100644
index 000000000..d654d91e9
--- /dev/null
+++ b/src/exchangedb/spi/Makefile
@@ -0,0 +1,9 @@
+EXTENSION = own_test
+MODULES = own_test
+DATA = own_test.sql
+PG_CPPFLAGS = -I /usr/include/postgresql
+
+# postgresql build stuff
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
+include $(PGXS)
diff --git a/src/exchangedb/spi/README.md b/src/exchangedb/spi/README.md
new file mode 100644
index 000000000..47eb37b94
--- /dev/null
+++ b/src/exchangedb/spi/README.md
@@ -0,0 +1,37 @@
+ Server Programming Interface (SPI)
+
+
+Overview
+========
+
+This folder contains results from an experiment by Joseph Xu
+to use the Postgres SPI. They are not currently used at all
+by the GNU Taler exchange.
+
+
+Dependencies
+============
+
+These are the direct dependencies for compiling the code:
+
+# apt-get install libpq-dev postgresql-server-dev-13
+# apt-get install libkrb5-dev
+# apt-get install libssl-dev
+
+
+Compilation
+===========
+
+$ make
+
+Loading functions
+=================
+
+# make install
+$ psql "$DB_NAME" < own_test.sql
+
+
+Calling functions
+==================
+
+$ psql -c "SELECT $FUNCTION_NAME($ARGS);" "$DB_NAME"
diff --git a/src/exchangedb/spi/own_test.c b/src/exchangedb/spi/own_test.c
new file mode 100644
index 000000000..ac72fad7b
--- /dev/null
+++ b/src/exchangedb/spi/own_test.c
@@ -0,0 +1,873 @@
+#include "postgres.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <postgresql/libpq-fe.h>
+#include <libpq-int.h>
+#include <catalog/pg_type.h>
+#include <executor/spi.h>
+#include <funcapi.h>
+#include <fmgr.h>
+#include <utils/builtins.h>
+#include <utils/array.h>
+#include <sys/time.h>
+#include <utils/numeric.h>
+#include <utils/timestamp.h>
+#include <utils/bytea.h>
+
+#ifdef PG_MODULE_MAGIC
+PG_MODULE_MAGIC;
+#endif
+
+typedef struct
+{
+ Datum col1;
+ Datum col2;
+} valuest;
+
+void _PG_init (void);
+
+void _PG_fini (void);
+
+void
+_PG_init (void)
+{
+}
+
+
+PG_FUNCTION_INFO_V1 (pg_spi_insert_int);
+PG_FUNCTION_INFO_V1 (pg_spi_select_from_x);
+PG_FUNCTION_INFO_V1 (pg_spi_select_pair_from_y);
+// PG_FUNCTION_INFO_V1(pg_spi_select_with_cond);
+PG_FUNCTION_INFO_V1 (pg_spi_update_y);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_example);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_example_without_saveplan);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_insert);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_insert_without_saveplan);
+// PG_FUNCTION_INFO_V1(pg_spi_prepare_select_with_cond);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_select_with_cond_without_saveplan);
+PG_FUNCTION_INFO_V1 (pg_spi_prepare_update);
+PG_FUNCTION_INFO_V1 (pg_spi_get_dep_ref_fees);
+// SIMPLE SELECT
+Datum
+pg_spi_prepare_example (PG_FUNCTION_ARGS)
+{
+ static SPIPlanPtr prepared_plan;
+ int ret;
+ int64 result;
+ char *value;
+ SPIPlanPtr new_plan;
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "DB connection failed ! \n");
+ }
+ {
+ if (prepared_plan == NULL)
+ {
+ new_plan = SPI_prepare ("SELECT 1 FROM X", 0, NULL);
+ prepared_plan = SPI_saveplan (new_plan);
+
+ if (prepared_plan == NULL)
+ {
+ elog (ERROR, "FAIL TO SAVE !\n");
+ }
+ }
+
+ ret = SPI_execute_plan (prepared_plan, NULL, 0,false, 0);
+ if (ret != SPI_OK_SELECT)
+ {
+ elog (ERROR, "SELECT FAILED %d !\n", ret);
+ }
+
+ if (SPI_tuptable != NULL && SPI_tuptable->vals != NULL &&
+ SPI_tuptable->tupdesc != NULL)
+ {
+ value = SPI_getvalue (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
+ result = atoi (value);
+ }
+ else
+ {
+ elog (ERROR, "EMPTY TABLE !\n");
+ }
+ }
+ SPI_finish ();
+ PG_RETURN_INT64 (result);
+}
+
+
+Datum
+pg_spi_prepare_example_without_saveplan (PG_FUNCTION_ARGS)
+{
+ int ret;
+ int64 result;
+ char *value;
+ SPIPlanPtr new_plan;
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "DB connection failed ! \n");
+ }
+
+ {
+ new_plan = SPI_prepare ("SELECT 1 FROM X", 0, NULL);
+ ret = SPI_execute_plan (new_plan, NULL, 0,false, 0);
+ if (ret != SPI_OK_SELECT)
+ {
+ elog (ERROR, "SELECT FAILED %d !\n", ret);
+ }
+
+ if (SPI_tuptable != NULL
+ && SPI_tuptable->vals != NULL
+ && SPI_tuptable->tupdesc != NULL)
+ {
+ value = SPI_getvalue (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1);
+ result = atoi (value);
+ }
+ else
+ {
+ elog (ERROR, "EMPTY TABLE !\n");
+ }
+ }
+ SPI_finish ();
+ PG_RETURN_INT64 (result);// PG_RETURN_INT64(result);
+}
+
+
+// SELECT 1 FROM X
+// V1
+Datum
+pg_spi_select_from_x (PG_FUNCTION_ARGS)
+{
+ int ret;
+ char *query = "SELECT 1 FROM X";
+ uint64 proc;
+ ret = SPI_connect ();
+
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed");
+ }
+
+ ret = SPI_exec (query, 10);
+ proc = SPI_processed;
+ if (ret != SPI_OK_SELECT)
+ {
+ elog (ERROR, "SPI_exec failed");
+ }
+
+ SPI_finish ();
+
+ PG_RETURN_INT64 (proc);
+}
+
+
+// INSERT INTO X VALUES (1)
+Datum
+pg_spi_insert_int (PG_FUNCTION_ARGS)
+{
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ char *query = "INSERT INTO X (a) VALUES ($1)";
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed");
+ }
+
+ nargs = 1;
+ argtypes[0] = INT4OID;
+ values[0] = Int32GetDatum (3);
+
+ ret = SPI_execute_with_args (query, nargs, argtypes, values, NULL, false, 0);
+ if (ret != SPI_OK_INSERT)
+ {
+ elog (ERROR, "SPI_execute_with_args failed");
+ }
+
+ SPI_finish ();
+
+ PG_RETURN_VOID ();
+}
+
+
+Datum
+pg_spi_prepare_insert (PG_FUNCTION_ARGS)
+{
+ static SPIPlanPtr prepared_plan = NULL;
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ const char *query = "INSERT INTO X (a) VALUES ($1)";
+ SPIPlanPtr new_plan;
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed ! \n");
+ }
+ if (prepared_plan == NULL)
+ {
+
+ argtypes[0] = INT4OID;
+ nargs = 1;
+ values[0] = Int32GetDatum (3);
+ new_plan = SPI_prepare (query, nargs, argtypes);
+ if (new_plan== NULL)
+ {
+ elog (ERROR, "SPI_prepare failed ! \n");
+ }
+ prepared_plan = SPI_saveplan (new_plan);
+ if (prepared_plan == NULL)
+ {
+ elog (ERROR, "SPI_saveplan failed ! \n");
+ }
+ }
+
+ ret = SPI_execute_plan (prepared_plan, values, NULL, false, 0);
+ if (ret != SPI_OK_INSERT)
+ {
+ elog (ERROR, "SPI_execute_plan failed ! \n");
+ }
+
+ SPI_finish ();
+
+ PG_RETURN_VOID ();
+}
+
+
+/*
+Datum
+pg_spi_prepare_insert_bytea(PG_FUNCTION_ARGS)
+{
+ static SPIPlanPtr prepared_plan = NULL;
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ Oid argtypes2[1];
+ Datum val[1];
+ char *query = "INSERT INTO X (a) VALUES ($1)";
+ SPIPlanPtr new_plan;
+ ret = SPI_connect();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog(ERROR, "SPI_connect failed ! \n");
+ }
+ if (prepared_plan == NULL) {
+ argtypes2[0] = BOOLOID;
+ val[0] = BoolGetDatum();
+ argtypes[0] = BYTEAOID;
+ nargs = 1;
+ values[0] = Int32GetDatum(3);
+ new_plan = SPI_prepare(query, nargs, argtypes);
+ if (new_plan== NULL)
+ {
+ elog(ERROR, "SPI_prepare failed ! \n");
+ }
+ prepared_plan = SPI_saveplan(new_plan);
+ if (prepared_plan == NULL)
+ {
+ elog(ERROR, "SPI_saveplan failed ! \n");
+ }
+ }
+
+ ret = SPI_execute_plan(prepared_plan, values, NULL, false, 0);
+ if (ret != SPI_OK_INSERT)
+ {
+ elog(ERROR, "SPI_execute_plan failed ! \n");
+ }
+
+ SPI_finish();
+
+ PG_RETURN_VOID();
+}
+*/
+
+Datum
+pg_spi_prepare_insert_without_saveplan (PG_FUNCTION_ARGS)
+{
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ const char *query = "INSERT INTO X (a) VALUES ($1)";
+ SPIPlanPtr new_plan;
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed");
+ }
+ {
+ argtypes[0] = INT4OID;
+ nargs = 1;
+ values[0] = Int32GetDatum (3);
+ new_plan = SPI_prepare (query, nargs, argtypes);
+ if (new_plan== NULL)
+ {
+ elog (ERROR, "SPI_prepare failed");
+ }
+ }
+
+ ret = SPI_execute_plan (new_plan, values, NULL, false, 0);
+ if (ret != SPI_OK_INSERT)
+ {
+ elog (ERROR, "SPI_execute_plan failed");
+ }
+
+ SPI_finish ();
+
+ PG_RETURN_VOID ();
+}
+
+
+/*
+Datum
+pg_spi_select_pair_from_y(PG_FUNCTION_ARGS)
+{
+ int ret;
+ valuest result;
+ bool isnull;
+ char *query = "SELECT 1,1 FROM Y";
+ result.col1 = 0;
+ result.col2 = 0;
+
+ if ((ret = SPI_connect()) < 0) {
+ fprintf(stderr, "SPI_connect returned %d\n", ret);
+ exit(1);
+ }
+ ret = SPI_exec(query, 0);
+ if (ret == SPI_OK_SELECT && SPI_processed > 0) {
+ int i;
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+ for (i = 0; i < SPI_processed; i++) {
+ HeapTuple tuple = tuptable->vals[i];
+ result.col1 = SPI_getbinval(tuple, tupdesc, 1, &isnull);
+ result.col2 = SPI_getbinval(tuple, tupdesc, 2, &isnull);
+ }
+ }
+ SPI_finish();
+ PG_RETURN_TEXT_P(result);
+}
+*/
+
+// SELECT X FROM Y WHERE Z=$1
+/*
+Datum
+pg_spi_select_with_cond(PG_FUNCTION_ARGS)
+{
+ int ret;
+ char *query;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ uint64 proc;
+ query = "SELECT col1 FROM Y WHERE col2 = $1";
+
+ ret = SPI_connect();
+ if (ret != SPI_OK_CONNECT) {
+ elog(ERROR, "SPI_connect failed: %d", ret);
+ }
+ nargs = 1;
+ argtypes[0] = INT4OID;
+ values[0] = Int32GetDatum(2);
+
+ ret = SPI_execute_with_args(query, nargs, argtypes, values, NULL, false, 0);
+ proc = SPI_processed;
+ if (ret != SPI_OK_SELECT)
+ {
+ elog(ERROR, "SPI_execute_with_args failed");
+ }
+
+ SPI_finish();
+
+
+ PG_RETURN_INT64(proc);
+ }*/
+
+////////SELECT WITH COND
+/*
+Datum pg_spi_prepare_select_with_cond(PG_FUNCTION_ARGS) {
+ static SPIPlanPtr prepared_plan = NULL;
+ SPIPlanPtr new_plan;
+ int ret;
+ Datum values[1];
+ uint64 proc;
+ int nargs;
+ Oid argtypes[1];
+ char *query = "SELECT col1 FROM Y WHERE col1 = $1";
+ int result = 0;
+
+ ret = SPI_connect();
+ if (ret != SPI_OK_CONNECT)
+ elog(ERROR, "SPI_connect failed ! \n");
+
+ if (prepared_plan == NULL) {
+
+ argtypes[0] = INT4OID;
+ nargs = 1;
+ values[0] = DatumGetByteaP(SPI_getbinval(tuptable->vals[0], tupdesc, 1, &isnull)); //Value col2
+
+ new_plan = SPI_prepare(query, nargs, argtypes);
+ if (new_plan == NULL)
+ elog(ERROR, "SPI_prepare failed ! \n");
+
+ prepared_plan = SPI_saveplan(new_plan);
+ if (prepared_plan == NULL)
+ elog(ERROR, "SPI_saveplan failed ! \n");
+ }
+
+
+ ret = SPI_execute_plan(prepared_plan, values, NULL, false, 0);
+
+ if (ret != SPI_OK_SELECT) {
+ elog(ERROR, "SPI_execute_plan failed: %d \n", ret);
+ }
+
+ proc = SPI_processed;
+
+ if (proc > 0) {
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+ HeapTuple tuple;
+ int i;
+
+ for (i = 0; i < proc; i++) {
+ tuple = tuptable->vals[i];
+ for (int j = 1; j <= tupdesc->natts; j++) {
+ char * value = SPI_getvalue(tuple, tupdesc, j);
+ result += atoi(value);
+ }
+ }
+ }
+ SPI_finish();
+ PG_RETURN_INT64(result);
+}
+*/
+
+Datum
+pg_spi_prepare_select_with_cond_without_saveplan (PG_FUNCTION_ARGS)
+{
+
+ SPIPlanPtr new_plan;
+ int ret;
+ Datum values[1];
+ uint64 proc;
+ int nargs;
+ Oid argtypes[1];
+ char *query = "SELECT col1 FROM Y WHERE col2 = $1";
+ int result = 0;
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ elog (ERROR, "SPI_connect failed ! \n");
+
+ {
+
+ argtypes[0] = INT4OID;
+ nargs = 1;
+ values[0] = Int32GetDatum (2); // Value col2
+
+ new_plan = SPI_prepare (query, nargs, argtypes);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare failed ! \n");
+
+ }
+
+
+ ret = SPI_execute_plan (new_plan, values, NULL, false, 0);
+
+ if (ret != SPI_OK_SELECT)
+ {
+ elog (ERROR, "SPI_execute_plan failed: %d \n", ret);
+ }
+
+ proc = SPI_processed;
+
+ if (proc > 0)
+ {
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+ HeapTuple tuple;
+ int i;
+
+ for (i = 0; i < proc; i++)
+ {
+ tuple = tuptable->vals[i];
+ for (int j = 1; j <= tupdesc->natts; j++)
+ {
+ char *value = SPI_getvalue (tuple, tupdesc, j);
+ result += atoi (value);
+ }
+ }
+ }
+ SPI_finish ();
+ PG_RETURN_INT64 (result);
+}
+
+
+Datum
+pg_spi_update_y (PG_FUNCTION_ARGS)
+{
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ const char *query = "UPDATE Y SET col1 = 4 WHERE (col2 = $1)";
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed ! \n");
+ }
+
+ nargs = 1;
+ argtypes[0] = INT4OID;
+ values[0] = Int32GetDatum (0);
+
+ ret = SPI_execute_with_args (query, nargs, argtypes, values, NULL, false, 0);
+ if (ret != SPI_OK_UPDATE)
+ {
+ elog (ERROR, "SPI_execute_with_args failed ! \n");
+ }
+
+ SPI_finish ();
+
+ PG_RETURN_VOID ();
+}
+
+
+Datum
+pg_spi_prepare_update (PG_FUNCTION_ARGS)
+{
+ static SPIPlanPtr prepared_plan = NULL;
+ SPIPlanPtr new_plan;
+ int ret;
+ int nargs;
+ Oid argtypes[1];
+ Datum values[1];
+ const char *query = "UPDATE Y SET col1 = 4 WHERE (col2 = $1)";
+
+ ret = SPI_connect ();
+ if (ret != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "SPI_connect failed ! \n");
+ }
+
+ if (prepared_plan == NULL)
+ {
+ argtypes[0] = INT4OID;
+ nargs = 1;
+ values[0] = Int32GetDatum (3);
+ // PREPARE
+ new_plan = SPI_prepare (query, nargs, argtypes);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare failed ! \n");
+ // SAVEPLAN
+ prepared_plan = SPI_saveplan (new_plan);
+ if (prepared_plan == NULL)
+ elog (ERROR, "SPI_saveplan failed ! \n");
+ }
+ ret = SPI_execute_plan (prepared_plan, values, NULL, false, 0);
+ if (ret != SPI_OK_UPDATE)
+ elog (ERROR, "SPI_execute_plan failed ! \n");
+
+ SPI_finish ();
+ PG_RETURN_VOID ();
+}
+
+
+/*
+Datum
+pg_spi_prepare_update_without_saveplan(PG_FUNCTION_ARGS)
+{}*/
+void
+_PG_fini (void)
+{
+}
+
+
+/*
+
+*/
+
+
+Datum
+pg_spi_get_dep_ref_fees (PG_FUNCTION_ARGS)
+{
+ /* Define plan to save */
+ static SPIPlanPtr deposit_plan;
+ static SPIPlanPtr ref_plan;
+ static SPIPlanPtr fees_plan;
+ static SPIPlanPtr dummy_plan;
+ /* Define variables to update */
+ Timestamp refund_deadline = PG_GETARG_TIMESTAMP (0);
+ bytea *merchant_pub = PG_GETARG_BYTEA_P (1);
+ bytea *wire_target_h_payto = PG_GETARG_BYTEA_P (2);
+ bytea *wtid_raw = PG_GETARG_BYTEA_P (3);
+ bool is_null;
+ /* Define variables to store the results of each SPI query */
+ uint64_t sum_deposit_val = 0;
+ uint32_t sum_deposit_frac = 0;
+ uint64_t s_refund_val = 0;
+ uint32_t s_refund_frac = 0;
+ uint64_t sum_dep_fee_val = 0;
+ uint32_t sum_dep_fee_frac = 0;
+ uint64_t norm_refund_val = 0;
+ uint32_t norm_refund_frac = 0;
+ uint64_t sum_refund_val = 0;
+ uint32_t sum_refund_frac = 0;
+ /* Define variables to store the Tuptable */
+ SPITupleTable *dep_res;
+ SPITupleTable *ref_res;
+ SPITupleTable *ref_by_coin_res;
+ SPITupleTable *norm_ref_by_coin_res;
+ SPITupleTable *fully_refunded_coins_res;
+ SPITupleTable *fees_res;
+ SPITupleTable *dummys_res;
+ /* Define variable to update */
+ Datum values_refund[2];
+ Datum values_deposit[3];
+ Datum values_fees[2];
+ Datum values_dummys[2];
+ TupleDesc tupdesc;
+ /* Define variables to replace some tables */
+ bytea *ref_by_coin_coin_pub;
+ int64 ref_by_coin_deposit_serial_id = 0;
+ bytea *norm_ref_by_coin_coin_pub;
+ int64_t norm_ref_by_coin_deposit_serial_id = 0;
+ bytea *new_dep_coin_pub = NULL;
+ int res = SPI_connect ();
+
+ /* Connect to SPI */
+ if (res < 0)
+ {
+ elog (ERROR, "Could not connect to SPI manager");
+ }
+ if (deposit_plan == NULL)
+ {
+ const char *dep_sql;
+ SPIPlanPtr new_plan;
+
+ // Execute first query and store results in variables
+ dep_sql =
+ "UPDATE deposits SET done=TRUE "
+ "WHERE NOT (done OR policy_blocked) "
+ "AND refund_deadline=$1 "
+ "AND merchant_pub=$2 "
+ "AND wire_target_h_payto=$3 "
+ "RETURNING "
+ "deposit_serial_id,"
+ "coin_pub,"
+ "amount_with_fee_val,"
+ "amount_with_fee_frac;";
+ fprintf (stderr, "dep sql %d\n", 1);
+ new_plan =
+ SPI_prepare (dep_sql, 4,(Oid[]){INT8OID, BYTEAOID, BYTEAOID});
+ fprintf (stderr, "dep sql %d\n", 2);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare failed for dep \n");
+ deposit_plan = SPI_saveplan (new_plan);
+ if (deposit_plan == NULL)
+ elog (ERROR, "SPI_saveplan failed for dep \n");
+ }
+ fprintf (stdout, "dep sql %d\n", 3);
+
+ values_deposit[0] = Int64GetDatum (refund_deadline);
+ values_deposit[1] = PointerGetDatum (merchant_pub);
+ values_deposit[2] = PointerGetDatum (wire_target_h_payto);
+
+ res = SPI_execute_plan (deposit_plan,
+ values_deposit,
+ NULL,
+ true,
+ 0);
+ fprintf (stdout, "dep sql %d\n", 4);
+ if (res != SPI_OK_UPDATE)
+ {
+ elog (ERROR, "Failed to execute subquery 1 \n");
+ }
+ // STORE TUPTABLE deposit
+ dep_res = SPI_tuptable;
+
+ for (unsigned int i = 0; i < SPI_processed; i++)
+ {
+ int64 dep_deposit_serial_ids = DatumGetInt64 (SPI_getbinval (
+ SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc, 1,
+ &is_null));
+ bytea *dep_coin_pub = DatumGetByteaP (SPI_getbinval (SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc,
+ 2, &is_null));
+ int64 dep_amount_val = DatumGetInt64 (SPI_getbinval (SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc,
+ 3, &is_null));
+ int32 dep_amount_frac = DatumGetInt32 (SPI_getbinval (SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc,
+ 4, &is_null));
+
+ if (is_null)
+ elog (ERROR, "Failed to retrieve data from deposit \n");
+ if (ref_plan == NULL)
+ {
+ // Execute second query with parameters from first query and store results in variables
+ const char *ref_sql =
+ "SELECT amount_with_fee_val, amount_with_fee_frac, coin_pub, deposit_serial_id "
+ "FROM refunds "
+ "WHERE coin_pub=$1 "
+ "AND deposit_serial_id=$2;";
+ SPIPlanPtr new_plan = SPI_prepare (ref_sql, 3, (Oid[]){BYTEAOID,
+ INT8OID});
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare failed for refund\n");
+ ref_plan = SPI_saveplan (new_plan);
+ if (ref_plan == NULL)
+ elog (ERROR, "SPI_saveplan failed for refund\n");
+ }
+ values_refund[0] = PointerGetDatum (dep_coin_pub);
+ values_refund[1] = Int64GetDatum (dep_deposit_serial_ids);
+ res = SPI_execute_plan (ref_plan,
+ values_refund,
+ NULL,
+ false,
+ 0);
+ if (res != SPI_OK_SELECT)
+ elog (ERROR, "Failed to execute subquery 2\n");
+ // STORE TUPTABLE refund
+ ref_res = SPI_tuptable;
+ for (unsigned int j = 0; j < SPI_processed; j++)
+ {
+ int64 ref_refund_val = DatumGetInt64 (SPI_getbinval (
+ SPI_tuptable->vals[j],
+ SPI_tuptable->tupdesc, 1,
+ &is_null));
+ int32 ref_refund_frac = DatumGetInt32 (SPI_getbinval (
+ SPI_tuptable->vals[j],
+ SPI_tuptable->tupdesc, 2,
+ &is_null));
+ bytea *ref_coin_pub = DatumGetByteaP (SPI_getbinval (
+ SPI_tuptable->vals[j],
+ SPI_tuptable->tupdesc, 3,
+ &is_null));
+ int64 ref_deposit_serial_id = DatumGetInt64 (SPI_getbinval (
+ SPI_tuptable->vals[j],
+ SPI_tuptable->tupdesc, 4,
+ &is_null));
+ // Execute third query with parameters from second query and store results in variables
+ ref_by_coin_coin_pub = ref_coin_pub;
+ ref_by_coin_deposit_serial_id = ref_deposit_serial_id;
+ // LOOP TO GET THE SUM FROM REFUND BY COIN
+ for (unsigned int i = 0; i<SPI_processed; i++)
+ {
+ if ((ref_by_coin_coin_pub ==
+ DatumGetByteaP (SPI_getbinval (SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc, 1,
+ &is_null)))
+ &&
+ (ref_by_coin_deposit_serial_id ==
+ DatumGetUInt64 (SPI_getbinval (SPI_tuptable->vals[i],
+ SPI_tuptable->tupdesc, 2,
+ &is_null)))
+ )
+ {
+ sum_refund_val += ref_refund_val;
+ sum_refund_frac += ref_refund_frac;
+ norm_ref_by_coin_coin_pub = ref_by_coin_coin_pub;
+ norm_ref_by_coin_deposit_serial_id = ref_by_coin_deposit_serial_id;
+ }
+ }// END SUM CALCULATION
+ // NORMALIZE REFUND VAL FRAC
+ norm_refund_val =
+ (sum_refund_val + sum_refund_frac) / 100000000;
+ norm_refund_frac =
+ sum_refund_frac % 100000000;
+ // Get refund values
+ s_refund_val += sum_refund_val;
+ s_refund_frac = sum_refund_frac;
+ }// END REFUND
+ if (norm_ref_by_coin_coin_pub == dep_coin_pub
+ && ref_by_coin_deposit_serial_id == dep_deposit_serial_ids
+ && norm_refund_val == dep_amount_val
+ && norm_refund_frac == dep_amount_frac)
+ {
+ new_dep_coin_pub = dep_coin_pub;
+ }
+ // Ensure we get the fee for each coin and not only once per denomination
+ if (fees_plan == NULL)
+ {
+ const char *fees_sql =
+ "SELECT "
+ " denom.fee_deposit_val AS fee_val, "
+ " denom.fee_deposit_frac AS fee_frac, "
+ "FROM known_coins kc"
+ "JOIN denominations denom USING (denominations_serial) "
+ "WHERE kc.coin_pub = $1 AND kc.coin_pub != $2;";
+ SPIPlanPtr new_plan = SPI_prepare (fees_sql, 3, (Oid[]){BYTEAOID,
+ BYTEAOID});
+ if (new_plan == NULL)
+ {
+ elog (ERROR, "SPI_prepare for fees failed ! \n");
+ }
+ fees_plan = SPI_saveplan (new_plan);
+ if (fees_plan == NULL)
+ {
+ elog (ERROR, "SPI_saveplan for fees failed ! \n");
+ }
+ }
+ values_fees[0] = PointerGetDatum (dep_coin_pub);
+ values_fees[1] = PointerGetDatum (new_dep_coin_pub);
+ res = SPI_execute_plan (fees_plan, values_fees, NULL, false, 0);
+ if (res != SPI_OK_SELECT)
+ elog (ERROR, "SPI_execute_plan failed for fees \n");
+ fees_res = SPI_tuptable;
+ tupdesc = fees_res->tupdesc;
+ for (unsigned int i = 0; i<SPI_processed; i++)
+ {
+ HeapTuple tuple = fees_res->vals[i];
+ bool is_null;
+ uint64_t fee_val = DatumGetUInt64 (SPI_getbinval (tuple, tupdesc, 1,
+ &is_null));
+ uint32_t fee_frac = DatumGetUInt32 (SPI_getbinval (tuple, tupdesc, 2,
+ &is_null));
+ uint64_t fees_deposit_serial_id = DatumGetUInt64 (SPI_getbinval (tuple,
+ tupdesc,
+ 3,
+ &is_null));
+ if (dummy_plan == NULL)
+ {
+ const char *insert_dummy_sql =
+ "INSERT INTO "
+ "aggregation_tracking(deposit_serial_id, wtid_raw)"
+ " VALUES ($1, $2)";
+
+ SPIPlanPtr new_plan = SPI_prepare (insert_dummy_sql, 2, (Oid[]){INT8OID,
+ BYTEAOID});
+ if (new_plan == NULL)
+ elog (ERROR, "FAILED to prepare aggregation tracking \n");
+ dummy_plan = SPI_saveplan (new_plan);
+ if (dummy_plan == NULL)
+ elog (ERROR, "FAILED to saveplan aggregation tracking\n");
+ }
+ values_dummys[0] = Int64GetDatum (dep_deposit_serial_ids);
+ values_dummys[1] = PointerGetDatum (wtid_raw);
+ res = SPI_execute_plan (dummy_plan, values_dummys, NULL, false, 0);
+ if (res != SPI_OK_INSERT)
+ elog (ERROR, "Failed to insert dummy\n");
+ dummys_res = SPI_tuptable;
+ // Calculation of deposit fees for not fully refunded deposits
+ sum_dep_fee_val += fee_val;
+ sum_dep_fee_frac += fee_frac;
+ }
+ // Get deposit values
+ sum_deposit_val += dep_amount_val;
+ sum_deposit_frac += dep_amount_frac;
+ }// END DEPOSIT
+ SPI_finish ();
+ PG_RETURN_VOID ();
+}
diff --git a/src/exchangedb/spi/own_test.control b/src/exchangedb/spi/own_test.control
new file mode 100644
index 000000000..4e73e207f
--- /dev/null
+++ b/src/exchangedb/spi/own_test.control
@@ -0,0 +1,4 @@
+comment = 'Example extension for testing purposes'
+default_version = '1.0'
+module_pathname = '$libdir/own_test'
+relocatable = true
diff --git a/src/exchangedb/spi/own_test.sql b/src/exchangedb/spi/own_test.sql
new file mode 100644
index 000000000..12729d068
--- /dev/null
+++ b/src/exchangedb/spi/own_test.sql
@@ -0,0 +1,201 @@
+DROP TABLE IF EXISTS X;
+CREATE TABLE X (
+ a integer
+);
+
+INSERT INTO X (a)
+ VALUES (1), (2), (3), (4), (5), (6), (7);
+
+DROP TABLE IF EXISTS Y;
+CREATE TABLE Y (col1 INT, col2 INT);
+INSERT INTO Y (col1,col2)
+ VALUES (1,2), (2,0), (0,4), (4,0), (0,6), (6,7), (7,8);
+
+DROP TABLE IF EXISTS Z;
+CREATE TABLE Z (col1 BYTEA);
+
+DROP TABLE IF EXISTS deposits;
+CREATE TABLE deposits(
+ deposit_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY
+ ,shard INT8 NOT NULL
+ ,coin_pub BYTEA NOT NULL CHECK (LENGTH(coin_pub)=32)
+ ,known_coin_id INT8 NOT NULL
+ ,amount_with_fee_val INT8 NOT NULL
+ ,amount_with_fee_frac INT4 NOT NULL
+ ,wallet_timestamp INT8 NOT NULL
+ ,exchange_timestamp INT8 NOT NULL
+ ,refund_deadline INT8 NOT NULL
+ ,wire_deadline INT8 NOT NULL
+ ,merchant_pub BYTEA NOT NULL CHECK (LENGTH(merchant_pub)=32)
+ ,h_contract_terms BYTEA NOT NULL CHECK (LENGTH(h_contract_terms)=64)
+ ,coin_sig BYTEA NOT NULL CHECK (LENGTH(coin_sig)=64)
+ ,wire_salt BYTEA NOT NULL CHECK (LENGTH(wire_salt)=16)
+ ,wire_target_h_payto BYTEA CHECK (LENGTH(wire_target_h_payto)=32)
+ ,done BOOLEAN NOT NULL DEFAULT FALSE
+ ,policy_blocked BOOLEAN NOT NULL DEFAULT FALSE
+ ,policy_details_serial_id INT8);
+
+
+DROP FUNCTION IF EXISTS pg_spi_insert_int;
+CREATE FUNCTION pg_spi_insert_int()
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_insert_int';
+
+DROP FUNCTION IF EXISTS pg_spi_select_from_x;
+CREATE FUNCTION pg_spi_select_from_x()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_select_from_x';
+
+/*
+CREATE FUNCTION pg_spi_select_pair_from_y()
+ RETURNS valuest
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_select_pair_from_y';
+*/
+/*CREATE FUNCTION pg_spi_select_with_cond()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_select_with_cond';
+*/
+
+DROP FUNCTION IF EXISTS pg_spi_update_y;
+CREATE FUNCTION pg_spi_update_y()
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_update_y';
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_example;
+CREATE FUNCTION pg_spi_prepare_example()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_example';
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_example_without_saveplan;
+CREATE FUNCTION pg_spi_prepare_example_without_saveplan()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_example_without_saveplan';
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_insert;
+CREATE FUNCTION pg_spi_prepare_insert()
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_insert';
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_insert_without_saveplan;
+CREATE FUNCTION pg_spi_prepare_insert_without_saveplan()
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_insert_without_saveplan';
+
+/*
+CREATE FUNCTION pg_spi_prepare_select_with_cond()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_select_with_cond';
+*/
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_select_with_cond_without_saveplan;
+CREATE FUNCTION pg_spi_prepare_select_with_cond_without_saveplan()
+ RETURNS INT8
+ LANGUAGE c COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_select_with_cond_without_saveplan';
+
+DROP FUNCTION IF EXISTS pg_spi_prepare_update;
+CREATE FUNCTION pg_spi_prepare_update()
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_prepare_update';
+
+DROP FUNCTION IF EXISTS pg_spi_get_dep_ref_fees;
+CREATE FUNCTION pg_spi_get_dep_ref_fees(
+ IN in_timestamp INT8
+ ,IN merchant_pub BYTEA
+ ,IN wire_target_h_payto BYTEA
+ ,IN wtid BYTEA
+)
+ RETURNS VOID
+ LANGUAGE c VOLATILE COST 100
+AS '$libdir/own_test', 'pg_spi_get_dep_ref_fees';
+
+DROP FUNCTION IF EXISTS update_pg_spi_get_dep_ref_fees;
+CREATE FUNCTION update_pg_spi_get_dep_ref_fees(
+ IN in_refund_deadline INT8,
+ IN in_merchant_pub BYTEA,
+ IN in_wire_target_h_payto BYTEA
+)
+RETURNS SETOF record
+LANGUAGE plpgsql VOLATILE
+AS $$
+DECLARE
+
+BEGIN
+RETURN QUERY
+ UPDATE deposits
+ SET done = TRUE
+ WHERE NOT (done OR policy_blocked)
+ AND refund_deadline < in_refund_deadline
+ AND merchant_pub = in_merchant_pub
+ AND wire_target_h_payto = in_wire_target_h_payto
+ RETURNING
+ deposit_serial_id,
+ coin_pub,
+ amount_with_fee_val,
+ amount_with_fee_frac;
+END $$;
+
+DROP FUNCTION IF EXISTS stored_procedure_update;
+CREATE FUNCTION stored_procedure_update(
+IN in_number INT8
+)
+RETURNS VOID
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ UPDATE Y
+ SET col1 = 4
+ WHERE col2 = in_number;
+END $$;
+
+DROP FUNCTION IF EXISTS stored_procedure_select;
+CREATE FUNCTION stored_procedure_select(OUT out_value INT8)
+RETURNS INT8
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ SELECT 1
+ INTO out_value
+ FROM X;
+ RETURN;
+END $$;
+
+
+DROP FUNCTION IF EXISTS stored_procedure_insert;
+CREATE FUNCTION stored_procedure_insert(
+IN in_number INT8,
+OUT out_number INT8)
+RETURNS INT8
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ INSERT INTO X (a)
+ VALUES (in_number)
+ RETURNING a INTO out_number;
+END $$;
+
+DROP FUNCTION IF EXISTS stored_procedure_select_with_cond;
+CREATE FUNCTION stored_procedure_select_with_cond(
+IN in_number INT8,
+OUT out_number INT8
+)
+RETURNS INT8
+LANGUAGE plpgsql
+AS $$
+BEGIN
+ SELECT col1 INTO out_number
+ FROM Y
+ WHERE col2 = in_number;
+ RETURN;
+END $$;
diff --git a/src/exchangedb/spi/perf_own_test.c b/src/exchangedb/spi/perf_own_test.c
new file mode 100644
index 000000000..92be2235e
--- /dev/null
+++ b/src/exchangedb/spi/perf_own_test.c
@@ -0,0 +1,25 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/spi/perf_own_test.c
+ * @brief benchmark for 'own_test'
+ * @author Joseph Xu
+ */
+#include "exchangedb/platform.h"
+#include "exchangedb/taler_exchangedb_lib.h"
+#include "exchangedb/taler_json_lib.h"
+#include "exchangedb/taler_exchangedb_plugin.h"
+#include "own_test.sql"
diff --git a/src/exchangedb/spi/pg_aggregate.c b/src/exchangedb/spi/pg_aggregate.c
new file mode 100644
index 000000000..721f247c7
--- /dev/null
+++ b/src/exchangedb/spi/pg_aggregate.c
@@ -0,0 +1,411 @@
+#include "postgres.h"
+#include "fmgr.h"
+#include "utils/numeric.h"
+#include "utils/builtins.h"
+#include "executor/spi.h"
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1 (get_deposit_summary);
+
+Datum
+get_deposit_summary (PG_FUNCTION_ARGS)
+{
+
+ static SPIPlanPtr deposit_plan;
+ static SPIPlanPtr refund_plan;
+ static SPIPlanPtr refund_by_coin_plan;
+ static SPIPlanPtr norm_refund_by_coin_plan;
+ static SPIPlanPtr fully_refunded_by_coins_plan;
+ static SPIPlanPtr fees_plan;
+
+ int shard = PG_GETARG_INT32 (0);
+ char *sql;
+ char *merchant_pub = text_to_cstring (PG_GETARG_TEXT_P (1));
+ char *wire_target_h_payto = text_to_cstring (PG_GETARG_TEXT_P (2));
+ char *wtid_raw = text_to_cstring (PG_GETARG_TEXT_P (3));
+ int refund_deadline = PG_GETARG_INT32 (4);
+ int conn = SPI_connect ();
+ if (conn != SPI_OK_CONNECT)
+ {
+ elog (ERROR, "DB connection failed ! \n");
+ }
+
+ if (deposit_plan == NULL
+ || refund_plan == NULL
+ || refund_by_coin_plan == NULL
+ || norm_refund_by_coin_plan = NULL
+ || fully_refunded_coins_plan = NULL
+ || fees_plan
+ == NULL)
+ {
+ if (deposit_plan == NULL)
+ {
+ int nargs = 3;
+ Oid argtypes[3];
+ argtypes[0] = INT8OID;
+ argtypes[1] = BYTEAOID;
+ argtypes[2] = BYTEAOID;
+ const char *dep_sql =
+ " UPDATE deposits"
+ " SET done=TRUE"
+ " WHERE NOT (done OR policy_blocked)"
+ " AND refund_deadline < $1"
+ " AND merchant_pub = $2"
+ " AND wire_target_h_payto = $3"
+ " RETURNING"
+ " deposit_serial_id"
+ " ,coin_pub"
+ " ,amount_with_fee_val AS amount_val"
+ " ,amount_with_fee_frac AS amount_frac";
+ SPIPlanPtr new_plan =
+ SPI_prepare (dep_sql, 4, argtypes);
+ if (new_plan == NULL)
+ {
+ elog (ERROR, "SPI_prepare for deposit failed ! \n");
+ }
+ deposit_plan = SPI_saveplan (new_plan);
+ if (deposit_plan == NULL)
+ {
+ elog (ERROR, "SPI_saveplan for deposit failed ! \n");
+ }
+ }
+
+ Datum values[4];
+ values[0] = Int64GetDatum (refund_deadline);
+ values[1] = CStringGetDatum (merchant_pub);
+ values[2] = CStringGetDatum (wire_target_h_payto);
+ int ret = SPI_execute_plan (deposit_plan,
+ values,
+ NULL,
+ true,
+ 0);
+ if (ret != SPI_OK_UPDATE)
+ {
+ elog (ERROR, "Failed to execute subquery 1\n");
+ }
+ uint64_t *dep_deposit_serial_ids = palloc (sizeof(uint64_t)
+ * SPI_processed);
+ BYTEA **dep_coin_pubs = palloc (sizeof(BYTEA *) * SPI_processed);
+ uint64_t *dep_amount_vals = palloc (sizeof(uint64_t) * SPI_processed);
+ uint32_t *dep_amount_fracs = palloc (sizeof(uint32_t) * SPI_processed);
+ for (unsigned int i = 0; i < SPI_processed; i++)
+ {
+ HeapTuple tuple = SPI_tuptable->vals[i];
+ dep_deposit_serial_ids[i] =
+ DatumGetInt64 (SPI_getbinval (tuple, SPI_tuptable->tupdesc, 1, &ret));
+ dep_coin_pubs[i] =
+ DatumGetByteaP (SPI_getbinval (tuple, SPI_tuptable->tupdesc, 2, &ret));
+ dep_amount_vals[i] =
+ DatumGetInt64 (SPI_getbinval (tuple, SPI_tuptable->tupdesc, 3, &ret));
+ dep_amount_fracs[i] =
+ DatumGetInt32 (SPI_getbinval (tuple, SPI_tuptable->tupdesc, 4, &ret));
+ }
+
+
+ if (refund_plan == NULL)
+ {
+ const char *ref_sql =
+ "ref AS ("
+ " SELECT"
+ " amount_with_fee_val AS refund_val"
+ " ,amount_with_fee_frac AS refund_frac"
+ " ,coin_pub"
+ " ,deposit_serial_id"
+ " FROM refunds"
+ " WHERE coin_pub IN (SELECT coin_pub FROM dep)"
+ " AND deposit_serial_id IN (SELECT deposit_serial_id FROM dep)) ";
+ SPIPlanPtr new_plan = SPI_prepare (ref_sql, 0, NULL);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare for refund failed ! \n");
+ refund_plan = SPI_saveplan (new_plan);
+ if (refund_plan == NULL)
+ {
+ elog (ERROR, "SPI_saveplan for refund failed ! \n");
+ }
+ }
+
+ int64t_t *ref_deposit_serial_ids = palloc (sizeof(int64_t) * SPI_processed);
+
+ int res = SPI_execute_plan (refund_plan, NULL, NULL, false, 0);
+ if (res != SPI_OK_SELECT)
+ {
+ elog (ERROR, "Failed to execute subquery 2\n");
+ }
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+ for (unsigned int i = 0; i < SPI_processed; i++)
+ {
+ HeapTuple tuple = tuptable->vals[i];
+ Datum refund_val = SPI_getbinval (tuple, tupdesc, 1, &refund_val_isnull);
+ Datum refund_frac = SPI_getbinval (tuple, tupdesc, 2,
+ &refund_frac_isnull);
+ Datum coin_pub = SPI_getbinval (tuple, tupdesc, 3, &coin_pub_isnull);
+ Datum deposit_serial_id = SPI_getbinval (tuple, tupdesc, 4,
+ &deposit_serial_id_isnull);
+ if (refund_val_isnull
+ || refund_frac_isnull
+ || coin_pub_isnull
+ || deposit_serial_id_isnull)
+ {
+ elog (ERROR, "Failed to retrieve data from subquery 2");
+ }
+ uint64_t refund_val_int = DatumGetUInt64 (refund_val);
+ uint32_t refund_frac_int = DatumGetUInt32 (refund_frac);
+ BYTEA coin_pub = DatumGetByteaP (coin_pub);
+ ref_deposit_serial_ids = DatumGetInt64 (deposit_serial_id);
+
+ refund *new_refund = (refund*) palloc (sizeof(refund));
+ new_refund->coin_pub = coin_pub_str;
+ new_refund->deposit_serial_id = deposit_serial_id_int;
+ new_refund->amount_with_fee_val = refund_val_int;
+ new_refund->amount_with_fee_frac = refund_frac_int;
+ }
+
+
+ if (refund_by_coin_plan == NULL)
+ {
+ const char *ref_by_coin_sql =
+ "ref_by_coin AS ("
+ " SELECT"
+ " SUM(refund_val) AS sum_refund_val"
+ " ,SUM(refund_frac) AS sum_refund_frac"
+ " ,coin_pub"
+ " ,deposit_serial_id"
+ " FROM ref"
+ " GROUP BY coin_pub, deposit_serial_id) ";
+ SPIPlanPtr new_plan = SPI_prepare (ref_by_coin_sql, 0, NULL);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare for refund by coin failed ! \n");
+ refund_by_coin_plan = SPI_saveplan (new_plan);
+ if (refund_by_coin_plan == NULL)
+ elog (ERROR, "SPI_saveplan for refund failed");
+ }
+
+
+ int res = SPI_execute_plan (refund_by_coin_plan, NULL, NULL, false, 0);
+ if (res != SPI_OK_SELECT)
+ {
+ elog (ERROR, "Failed to execute subquery 2\n");
+ }
+
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+ for (unsigned int i = 0; i < SPI_processed; i++)
+ {
+ HeapTuple tuple = tuptable->vals[i];
+ Datum sum_refund_val = SPI_getbinval (tuple, tupdesc, 1,
+ &refund_val_isnull);
+ Datum sum_refund_frac = SPI_getbinval (tuple, tupdesc, 2,
+ &refund_frac_isnull);
+ Datum coin_pub = SPI_getbinval (tuple, tupdesc, 3, &coin_pub_isnull);
+ Datum deposit_serial_id_int = SPI_getbinval (tuple, tupdesc, 4,
+ &deposit_serial_id_isnull);
+ if (refund_val_isnull
+ || refund_frac_isnull
+ || coin_pub_isnull
+ || deposit_serial_id_isnull)
+ {
+ elog (ERROR, "Failed to retrieve data from subquery 2");
+ }
+ uint64_t s_refund_val_int = DatumGetUInt64 (sum_refund_val);
+ uint32_t s_refund_frac_int = DatumGetUInt32 (sum_refund_frac);
+ BYTEA coin_pub = DatumGetByteaP (coin_pub);
+ uint64_t deposit_serial_id_int = DatumGetInt64 (deposit_serial_id_int);
+ refund *new_refund_by_coin = (refund*) palloc (sizeof(refund));
+ new_refund_by_coin->coin_pub = coin_pub;
+ new_refund_by_coin->deposit_serial_id = deposit_serial_id_int;
+ new_refund_by_coin->refund_amount_with_fee_val = s_refund_val_int;
+ new_refund_by_coin->refund_amount_with_fee_frac = s_refund_frac_int;
+ }
+
+
+ if (norm_refund_by_coin_plan == NULL)
+ {
+ const char *norm_ref_by_coin_sql =
+ "norm_ref_by_coin AS ("
+ " SELECT"
+ " coin_pub"
+ " ,deposit_serial_id"
+ " FROM ref_by_coin) ";
+ SPIPlanPtr new_plan = SPI_prepare (norm_ref_by_coin_sql, 0, NULL);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare for norm refund by coin failed ! \n");
+ norm_refund_by_coin_plan = SPI_saveplan (new_plan);
+ if (norm_refund_by_coin_plan == NULL)
+ elog (ERROR, "SPI_saveplan for norm refund by coin failed ! \n");
+ }
+
+ double norm_refund_val =
+ ((double) new_refund_by_coin->refund_amount_with_fee_val
+ + (double) new_refund_by_coin->refund_amount_with_fee_frac) / 100000000;
+ double norm_refund_frac =
+ (double) new_refund_by_coin->refund_amount_with_fee_frac % 100000000;
+
+ if (fully_refunded_coins_plan == NULL)
+ {
+ const char *fully_refunded_coins_sql =
+ "fully_refunded_coins AS ("
+ " SELECT"
+ " dep.coin_pub"
+ " FROM norm_ref_by_coin norm"
+ " JOIN dep"
+ " ON (norm.coin_pub = dep.coin_pub"
+ " AND norm.deposit_serial_id = dep.deposit_serial_id"
+ " AND norm.norm_refund_val = dep.amount_val"
+ " AND norm.norm_refund_frac = dep.amount_frac)) ";
+ SPIPlanPtr new_plan =
+ SPI_prepare (fully_refunded_coins_sql, 0, NULL);
+ if (new_plan == NULL)
+ elog (ERROR, "SPI_prepare for fully refunded coins failed ! \n");
+ fully_refunded_coins_plan = SPI_saveplan (new_plan);
+ if (fully_refunded_coins_plan == NULL)
+ elog (ERROR, "SPI_saveplan for fully refunded coins failed ! \n");
+ }
+
+ int res = SPI_execute_plan (fully_refunded_coins_sql);
+ if (res != SPI_OK_SELECT)
+ elog (ERROR, "Failed to execute subquery 4\n");
+ SPITupleTable *tuptable = SPI_tuptable;
+ TupleDesc tupdesc = tuptable->tupdesc;
+
+ BYTEA coin_pub = SPI_getbinval (tuple, tupdesc, 1, &coin_pub_isnull);
+ if (fees_plan == NULL)
+ {
+ const char *fees_sql =
+ "SELECT "
+ " denom.fee_deposit_val AS fee_val, "
+ " denom.fee_deposit_frac AS fee_frac, "
+ " cs.deposit_serial_id "
+ "FROM dep cs "
+ "JOIN known_coins kc USING (coin_pub) "
+ "JOIN denominations denom USING (denominations_serial) "
+ "WHERE coin_pub NOT IN (SELECT coin_pub FROM fully_refunded_coins)";
+ SPIPlanPtr new_plan =
+ SPI_prepare (fees_sql, 0, NULL);
+ if (new_plan == NULL)
+ {
+ elog (ERROR, "SPI_prepare for fees failed ! \n");
+ }
+ fees_plan = SPI_saveplan (new_plan);
+ if (fees_plan == NULL)
+ {
+ elog (ERROR, "SPI_saveplan for fees failed ! \n");
+ }
+ }
+ }
+ int fees_ntuples;
+ SPI_execute (fees_sql, true, 0);
+ if (SPI_result_code () != SPI_OK_SELECT)
+ {
+ ereport (
+ ERROR,
+ (errcode (ERRCODE_INTERNAL_ERROR),
+ errmsg ("deposit fee query failed: error code %d \n",
+ SPI_result_code ())));
+ }
+ fees_ntuples = SPI_processed;
+
+ if (fees_ntuples > 0)
+ {
+ for (i = 0; i < fees_ntuples; i++)
+ {
+ Datum fee_val_datum =
+ SPI_getbinval (SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 1,
+ &fee_null);
+ Datum fee_frac_datum =
+ SPI_getbinval (SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 2,
+ &fee_null);
+ Datum deposit_id_datum =
+ SPI_getbinval (SPI_tuptable->vals[i], SPI_tuptable->tupdesc, 3,
+ &deposit_null);
+ if (! fee_null && ! deposit_null)
+ {
+ int64 fee_val = DatumGetInt64 (fee_val_datum);
+ int32 fee_frac = DatumGetInt32 (fee_frac_datum);
+ int64 deposit_id = DatumGetInt64 (deposit_id_datum);
+ sum_fee_value += fee_val;
+ sum_fee_fraction += fee_frac;
+ char *insert_agg_sql =
+ psprintf (
+ "INSERT INTO "
+ "aggregation_tracking(deposit_serial_id, wtid_raw)"
+ " VALUES (%lld, '%s')",
+ deposit_id, wtid_raw);
+ SPI_execute (insert_agg_sql, false, 0);
+ }
+ }
+ }
+
+ TupleDesc tupdesc;
+ SPITupleTable *tuptable = SPI_tuptable;
+ HeapTuple tuple;
+ Datum result;
+
+ if (tuptable == NULL || SPI_processed != 1)
+ {
+ ereport (
+ ERROR,
+ (errcode (ERRCODE_INTERNAL_ERROR),
+ errmsg ("Unexpected result \n")));
+ }
+ tupdesc = SPI_tuptable->tupdesc;
+ tuple = SPI_tuptable->vals[0];
+ result = HeapTupleGetDatum (tuple);
+
+ TupleDesc result_desc = CreateTemplateTupleDesc (6, false);
+ TupleDescInitEntry (result_desc, (AttrNumber) 1, "sum_deposit_value", INT8OID,
+ -1, 0);
+ TupleDescInitEntry (result_desc, (AttrNumber) 2, "sum_deposit_fraction",
+ INT4OID, -1, 0);
+ TupleDescInitEntry (result_desc, (AttrNumber) 3, "sum_refund_value", INT8OID,
+ -1, 0);
+ TupleDescInitEntry (result_desc, (AttrNumber) 4, "sum_refund_fraction",
+ INT4OID, -1, 0);
+ TupleDescInitEntry (result_desc, (AttrNumber) 5, "sum_fee_value", INT8OID, -1,
+ 0);
+ TupleDescInitEntry (result_desc, (AttrNumber) 6, "sum_fee_fraction", INT4OID,
+ -1, 0);
+
+ int ret = SPI_prepare (sql, 4, argtypes);
+ if (ret != SPI_OK_PREPARE)
+ {
+ elog (ERROR, "Failed to prepare statement: %s \n", sql);
+ }
+
+ ret = SPI_execute_plan (plan, args, nulls, true, 0);
+ if (ret != SPI_OK_SELECT)
+ {
+ elog (ERROR, "Failed to execute statement: %s \n", sql);
+ }
+
+ if (SPI_processed > 0)
+ {
+ HeapTuple tuple;
+ Datum values[6];
+ bool nulls[6] = {false};
+ values[0] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 1,
+ &nulls[0]);
+ values[1] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 2,
+ &nulls[1]);
+ values[2] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 3,
+ &nulls[2]);
+ values[3] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 4,
+ &nulls[3]);
+ values[4] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 5,
+ &nulls[4]);
+ values[5] =
+ SPI_getbinval (SPI_tuptable->vals[0], SPI_tuptable->tupdesc, 6,
+ &nulls[5]);
+ tuple = heap_form_tuple (result_desc, values, nulls);
+ PG_RETURN_DATUM (HeapTupleGetDatum (tuple));
+ }
+ SPI_finish ();
+
+ PG_RETURN_NULL ();
+}
diff --git a/src/exchangedb/test-exchange-db-postgres.conf b/src/exchangedb/test-exchange-db-postgres.conf
index ab70bcfce..7f0332686 100644
--- a/src/exchangedb/test-exchange-db-postgres.conf
+++ b/src/exchangedb/test-exchange-db-postgres.conf
@@ -30,4 +30,7 @@ IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
LEGAL_RESERVE_EXPIRATION_TIME = 7 years
# Shift to apply before aggregating.
-AGGREGATOR_SHIFT = 1s \ No newline at end of file
+AGGREGATOR_SHIFT = 1s
+
+# Number of purses per account by default.
+DEFAULT_PURSE_LIMIT = 1
diff --git a/src/exchangedb/test-exchangedb-batch-reserves-in-insert-postgres b/src/exchangedb/test-exchangedb-batch-reserves-in-insert-postgres
new file mode 100755
index 000000000..bc044232a
--- /dev/null
+++ b/src/exchangedb/test-exchangedb-batch-reserves-in-insert-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# test-exchangedb-batch-reserves-in-insert-postgres - temporary wrapper script for .libs/test-exchangedb-batch-reserves-in-insert-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The test-exchangedb-batch-reserves-in-insert-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "test-exchangedb-batch-reserves-in-insert-postgres:test-exchangedb-batch-reserves-in-insert-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "test-exchangedb-batch-reserves-in-insert-postgres:test-exchangedb-batch-reserves-in-insert-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "test-exchangedb-batch-reserves-in-insert-postgres:test-exchangedb-batch-reserves-in-insert-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='test-exchangedb-batch-reserves-in-insert-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/test-exchangedb-by-j-postgres b/src/exchangedb/test-exchangedb-by-j-postgres
new file mode 100755
index 000000000..11d295cc2
--- /dev/null
+++ b/src/exchangedb/test-exchangedb-by-j-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# test-exchangedb-by-j-postgres - temporary wrapper script for .libs/test-exchangedb-by-j-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The test-exchangedb-by-j-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "test-exchangedb-by-j-postgres:test-exchangedb-by-j-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "test-exchangedb-by-j-postgres:test-exchangedb-by-j-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "test-exchangedb-by-j-postgres:test-exchangedb-by-j-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='test-exchangedb-by-j-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/test-exchangedb-populate-link-data-postgres b/src/exchangedb/test-exchangedb-populate-link-data-postgres
new file mode 100755
index 000000000..f3d673519
--- /dev/null
+++ b/src/exchangedb/test-exchangedb-populate-link-data-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# test-exchangedb-populate-link-data-postgres - temporary wrapper script for .libs/test-exchangedb-populate-link-data-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The test-exchangedb-populate-link-data-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "test-exchangedb-populate-link-data-postgres:test-exchangedb-populate-link-data-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "test-exchangedb-populate-link-data-postgres:test-exchangedb-populate-link-data-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "test-exchangedb-populate-link-data-postgres:test-exchangedb-populate-link-data-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='test-exchangedb-populate-link-data-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/test-exchangedb-populate-ready-deposit-postgres b/src/exchangedb/test-exchangedb-populate-ready-deposit-postgres
new file mode 100755
index 000000000..7747f381c
--- /dev/null
+++ b/src/exchangedb/test-exchangedb-populate-ready-deposit-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# test-exchangedb-populate-ready-deposit-postgres - temporary wrapper script for .libs/test-exchangedb-populate-ready-deposit-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The test-exchangedb-populate-ready-deposit-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "test-exchangedb-populate-ready-deposit-postgres:test-exchangedb-populate-ready-deposit-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "test-exchangedb-populate-ready-deposit-postgres:test-exchangedb-populate-ready-deposit-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "test-exchangedb-populate-ready-deposit-postgres:test-exchangedb-populate-ready-deposit-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='test-exchangedb-populate-ready-deposit-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/test-exchangedb-populate-select-refunds-by-coin-postgres b/src/exchangedb/test-exchangedb-populate-select-refunds-by-coin-postgres
new file mode 100755
index 000000000..ce7ebb712
--- /dev/null
+++ b/src/exchangedb/test-exchangedb-populate-select-refunds-by-coin-postgres
@@ -0,0 +1,210 @@
+#! /bin/bash
+
+# test-exchangedb-populate-select-refunds-by-coin-postgres - temporary wrapper script for .libs/test-exchangedb-populate-select-refunds-by-coin-postgres
+# Generated by libtool (GNU libtool) 2.4.6 Debian-2.4.6-15
+#
+# The test-exchangedb-populate-select-refunds-by-coin-postgres program cannot be directly executed until all the libtool
+# libraries that it depends on are installed.
+#
+# This wrapper script should never be moved out of the build directory.
+# If it is, it will not operate correctly.
+
+# Sed substitution that helps us do robust quoting. It backslashifies
+# metacharacters that are still active within double-quoted strings.
+sed_quote_subst='s|\([`"$\\]\)|\\\1|g'
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+ setopt NO_GLOB_SUBST
+else
+ case `(set -o) 2>/dev/null` in *posix*) set -o posix;; esac
+fi
+BIN_SH=xpg4; export BIN_SH # for Tru64
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# The HP-UX ksh and POSIX shell print the target directory to stdout
+# if CDPATH is set.
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
+
+relink_command=""
+
+# This environment variable determines our operation mode.
+if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
+ # install mode needs the following variables:
+ generated_by_libtool_version='2.4.6'
+ notinst_deplibs=' libtalerexchangedb.la ../../src/json/libtalerjson.la ../../src/util/libtalerutil.la ../../src/pq/libtalerpq.la'
+else
+ # When we are sourced in execute mode, $file and $ECHO are already set.
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ file="$0"
+
+# A function that is used when there is no print builtin or printf.
+func_fallback_echo ()
+{
+ eval 'cat <<_LTECHO_EOF
+$1
+_LTECHO_EOF'
+}
+ ECHO="printf %s\\n"
+ fi
+
+# Very basic option parsing. These options are (a) specific to
+# the libtool wrapper, (b) are identical between the wrapper
+# /script/ and the wrapper /executable/ that is used only on
+# windows platforms, and (c) all begin with the string --lt-
+# (application programs are unlikely to have options that match
+# this pattern).
+#
+# There are only two supported options: --lt-debug and
+# --lt-dump-script. There is, deliberately, no --lt-help.
+#
+# The first argument to this parsing function should be the
+# script's ../../libtool value, followed by no.
+lt_option_debug=
+func_parse_lt_options ()
+{
+ lt_script_arg0=$0
+ shift
+ for lt_opt
+ do
+ case "$lt_opt" in
+ --lt-debug) lt_option_debug=1 ;;
+ --lt-dump-script)
+ lt_dump_D=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%/[^/]*$%%'`
+ test "X$lt_dump_D" = "X$lt_script_arg0" && lt_dump_D=.
+ lt_dump_F=`$ECHO "X$lt_script_arg0" | /usr/bin/sed -e 's/^X//' -e 's%^.*/%%'`
+ cat "$lt_dump_D/$lt_dump_F"
+ exit 0
+ ;;
+ --lt-*)
+ $ECHO "Unrecognized --lt- option: '$lt_opt'" 1>&2
+ exit 1
+ ;;
+ esac
+ done
+
+ # Print the debug banner immediately:
+ if test -n "$lt_option_debug"; then
+ echo "test-exchangedb-populate-select-refunds-by-coin-postgres:test-exchangedb-populate-select-refunds-by-coin-postgres:$LINENO: libtool wrapper (GNU libtool) 2.4.6 Debian-2.4.6-15" 1>&2
+ fi
+}
+
+# Used when --lt-debug. Prints its arguments to stdout
+# (redirection is the responsibility of the caller)
+func_lt_dump_args ()
+{
+ lt_dump_args_N=1;
+ for lt_arg
+ do
+ $ECHO "test-exchangedb-populate-select-refunds-by-coin-postgres:test-exchangedb-populate-select-refunds-by-coin-postgres:$LINENO: newargv[$lt_dump_args_N]: $lt_arg"
+ lt_dump_args_N=`expr $lt_dump_args_N + 1`
+ done
+}
+
+# Core function for launching the target application
+func_exec_program_core ()
+{
+
+ if test -n "$lt_option_debug"; then
+ $ECHO "test-exchangedb-populate-select-refunds-by-coin-postgres:test-exchangedb-populate-select-refunds-by-coin-postgres:$LINENO: newargv[0]: $progdir/$program" 1>&2
+ func_lt_dump_args ${1+"$@"} 1>&2
+ fi
+ exec "$progdir/$program" ${1+"$@"}
+
+ $ECHO "$0: cannot exec $program $*" 1>&2
+ exit 1
+}
+
+# A function to encapsulate launching the target application
+# Strips options in the --lt-* namespace from $@ and
+# launches target application with the remaining arguments.
+func_exec_program ()
+{
+ case " $* " in
+ *\ --lt-*)
+ for lt_wr_arg
+ do
+ case $lt_wr_arg in
+ --lt-*) ;;
+ *) set x "$@" "$lt_wr_arg"; shift;;
+ esac
+ shift
+ done ;;
+ esac
+ func_exec_program_core ${1+"$@"}
+}
+
+ # Parse options
+ func_parse_lt_options "$0" ${1+"$@"}
+
+ # Find the directory that this script lives in.
+ thisdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+ test "x$thisdir" = "x$file" && thisdir=.
+
+ # Follow symbolic links until we get to the real thisdir.
+ file=`ls -ld "$file" | /usr/bin/sed -n 's/.*-> //p'`
+ while test -n "$file"; do
+ destdir=`$ECHO "$file" | /usr/bin/sed 's%/[^/]*$%%'`
+
+ # If there was a directory component, then change thisdir.
+ if test "x$destdir" != "x$file"; then
+ case "$destdir" in
+ [\\/]* | [A-Za-z]:[\\/]*) thisdir="$destdir" ;;
+ *) thisdir="$thisdir/$destdir" ;;
+ esac
+ fi
+
+ file=`$ECHO "$file" | /usr/bin/sed 's%^.*/%%'`
+ file=`ls -ld "$thisdir/$file" | /usr/bin/sed -n 's/.*-> //p'`
+ done
+
+ # Usually 'no', except on cygwin/mingw when embedded into
+ # the cwrapper.
+ WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=no
+ if test "$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR" = "yes"; then
+ # special case for '.'
+ if test "$thisdir" = "."; then
+ thisdir=`pwd`
+ fi
+ # remove .libs from thisdir
+ case "$thisdir" in
+ *[\\/].libs ) thisdir=`$ECHO "$thisdir" | /usr/bin/sed 's%[\\/][^\\/]*$%%'` ;;
+ .libs ) thisdir=. ;;
+ esac
+ fi
+
+ # Try to get the absolute directory name.
+ absdir=`cd "$thisdir" && pwd`
+ test -n "$absdir" && thisdir="$absdir"
+
+ program='test-exchangedb-populate-select-refunds-by-coin-postgres'
+ progdir="$thisdir/.libs"
+
+
+ if test -f "$progdir/$program"; then
+ # Add our own library path to LD_LIBRARY_PATH
+ LD_LIBRARY_PATH="/home/priscilla/exchange/src/exchangedb/.libs:/home/priscilla/exchange/src/json/.libs:/home/priscilla/exchange/src/util/.libs:/home/priscilla/exchange/src/pq/.libs:$LD_LIBRARY_PATH"
+
+ # Some systems cannot cope with colon-terminated LD_LIBRARY_PATH
+ # The second colon is a workaround for a bug in BeOS R4 sed
+ LD_LIBRARY_PATH=`$ECHO "$LD_LIBRARY_PATH" | /usr/bin/sed 's/::*$//'`
+
+ export LD_LIBRARY_PATH
+
+ if test "$libtool_execute_magic" != "%%%MAGIC variable%%%"; then
+ # Run the actual program with our arguments.
+ func_exec_program ${1+"$@"}
+ fi
+ else
+ # The program doesn't exist.
+ $ECHO "$0: error: '$progdir/$program' does not exist" 1>&2
+ $ECHO "This script is just a wrapper for $program." 1>&2
+ $ECHO "See the libtool documentation for more information." 1>&2
+ exit 1
+ fi
+fi
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 54601c48d..22788a562 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -33,9 +33,9 @@ static int result;
/**
* Report line of error if @a cond is true, and jump to label "drop".
*/
-#define FAILIF(cond) \
+#define FAILIF(cond) \
do { \
- if (! (cond)) { break;} \
+ if (! (cond)) { break;} \
GNUNET_break (0); \
goto drop; \
} while (0)
@@ -45,7 +45,8 @@ static int result;
* Initializes @a ptr with random data.
*/
#define RND_BLK(ptr) \
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, \
+ sizeof (*ptr))
/**
* Initializes @a ptr with zeros.
@@ -112,53 +113,53 @@ mark_prepare_cb (void *cls,
* Simple check that config retrieval and setting for extensions work
*/
static enum GNUNET_GenericReturnValue
-test_extension_config (void)
+test_extension_manifest (void)
{
- char *config;
+ char *manifest;
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
- plugin->get_extension_config (plugin->cls,
- "fnord",
- &config));
+ plugin->get_extension_manifest (plugin->cls,
+ "fnord",
+ &manifest));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->set_extension_config (plugin->cls,
- "fnord",
- "bar"));
+ plugin->set_extension_manifest (plugin->cls,
+ "fnord",
+ "bar"));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_extension_config (plugin->cls,
- "fnord",
- &config));
+ plugin->get_extension_manifest (plugin->cls,
+ "fnord",
+ &manifest));
- FAILIF (0 != strcmp ("bar", config));
- GNUNET_free (config);
+ FAILIF (0 != strcmp ("bar", manifest));
+ GNUNET_free (manifest);
/* let's do this again! */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->set_extension_config (plugin->cls,
- "fnord",
- "buzz"));
+ plugin->set_extension_manifest (plugin->cls,
+ "fnord",
+ "buzz"));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_extension_config (plugin->cls,
- "fnord",
- &config));
+ plugin->get_extension_manifest (plugin->cls,
+ "fnord",
+ &manifest));
- FAILIF (0 != strcmp ("buzz", config));
- GNUNET_free (config);
+ FAILIF (0 != strcmp ("buzz", manifest));
+ GNUNET_free (manifest);
/* let's do this again, with NULL */
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->set_extension_config (plugin->cls,
- "fnord",
- NULL));
+ plugin->set_extension_manifest (plugin->cls,
+ "fnord",
+ NULL));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->get_extension_config (plugin->cls,
- "fnord",
- &config));
+ plugin->get_extension_manifest (plugin->cls,
+ "fnord",
+ &manifest));
- FAILIF (NULL != config);
+ FAILIF (NULL != manifest);
return GNUNET_OK;
drop:
@@ -220,18 +221,15 @@ check_reserve (const struct TALER_ReservePublicKeyP *pub,
const char *currency)
{
struct TALER_EXCHANGEDB_Reserve reserve;
- struct TALER_EXCHANGEDB_KycStatus kyc;
reserve.pub = *pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &reserve,
- &kyc));
+ &reserve));
FAILIF (value != reserve.balance.value);
FAILIF (fraction != reserve.balance.fraction);
FAILIF (0 != strcmp (currency,
reserve.balance.currency));
- FAILIF (kyc.ok);
return GNUNET_OK;
drop:
return GNUNET_SYSERR;
@@ -281,7 +279,7 @@ create_denom_key_pair (unsigned int size,
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dkp->priv,
&dkp->pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
size));
/* Using memset() as fields like master key and signature
are not properly initialized for this test. */
@@ -321,7 +319,6 @@ create_denom_key_pair (unsigned int size,
return NULL;
}
memset (&issue2, 0, sizeof (issue2));
- plugin->commit (plugin->cls);
if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_denomination_info (plugin->cls,
&dki.issue.denom_hash,
@@ -449,16 +446,16 @@ static unsigned int auditor_row_cnt;
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
static enum GNUNET_GenericReturnValue
-audit_refresh_session_cb (void *cls,
- uint64_t rowid,
- const struct TALER_DenominationPublicKey *denom_pub,
- const struct
- TALER_AgeCommitmentHash *h_age_commitment,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_Amount *amount_with_fee,
- uint32_t noreveal_index,
- const struct TALER_RefreshCommitmentP *rc)
+audit_refresh_session_cb (
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_DenominationPublicKey *denom_pub,
+ const struct TALER_AgeCommitmentHash *h_age_commitment,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ const struct TALER_Amount *amount_with_fee,
+ uint32_t noreveal_index,
+ const struct TALER_RefreshCommitmentP *rc)
{
(void) cls;
(void) rowid;
@@ -468,6 +465,7 @@ audit_refresh_session_cb (void *cls,
(void) amount_with_fee;
(void) noreveal_index;
(void) rc;
+ (void) h_age_commitment;
auditor_row_cnt++;
return GNUNET_OK;
}
@@ -539,6 +537,7 @@ cb_wt_never (void *cls,
(void) serial_id;
(void) merchant_pub;
(void) account_payto_uri;
+ (void) h_payto;
(void) exec_time;
(void) h_contract_terms;
(void) denom_pub;
@@ -578,6 +577,7 @@ cb_wt_check (void *cls,
{
(void) rowid;
(void) denom_pub;
+ (void) h_payto;
GNUNET_assert (cls == &cb_wt_never);
GNUNET_assert (0 == GNUNET_memcmp (merchant_pub,
&merchant_pub_wt));
@@ -604,7 +604,7 @@ static struct TALER_PaytoHashP wire_target_h_payto;
/**
- * Callback for #select_deposits_above_serial_id ()
+ * Callback for #select_coin_deposits_above_serial_id ()
*
* @param cls closure
* @param rowid unique serial ID for the deposit in our DB
@@ -820,9 +820,6 @@ test_wire_fees (void)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":2.424242",
&fees.closing));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (CURRENCY ":3.424242",
- &fees.wad));
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&master_sig,
sizeof (master_sig));
@@ -934,14 +931,17 @@ audit_wire_cb (void *cls,
/**
* Test API relating to wire_out handling.
*
+ * @param bd batch deposit to test
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
+test_wire_out (const struct TALER_EXCHANGEDB_BatchDeposit *bd)
{
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *deposit = &bd->cdis[0];
struct TALER_PaytoHashP h_payto;
- TALER_payto_hash (deposit->receiver_wire_account,
+ GNUNET_assert (0 < bd->num_cdis);
+ TALER_payto_hash (bd->receiver_wire_account,
&h_payto);
auditor_row_cnt = 0;
memset (&wire_out_wtid,
@@ -959,8 +959,8 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
plugin->start_deferred_wire_out (plugin->cls));
/* setup values for wire transfer aggregation data */
- merchant_pub_wt = deposit->merchant_pub;
- h_contract_terms_wt = deposit->h_contract_terms;
+ merchant_pub_wt = bd->merchant_pub;
+ h_contract_terms_wt = bd->h_contract_terms;
coin_pub_wt = deposit->coin.coin_pub;
coin_value_wt = deposit->amount_with_fee;
@@ -984,6 +984,7 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
struct TALER_Amount coin_fee2;
struct GNUNET_TIME_Timestamp execution_time2;
struct TALER_EXCHANGEDB_KycStatus kyc;
+ enum TALER_AmlDecisionState aml;
h_contract_terms_wt2.hash.bits[0]++;
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
@@ -997,20 +998,16 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
&execution_time2,
&coin_contribution2,
&coin_fee2,
- &kyc));
+ &kyc,
+ &aml));
}
{
struct TALER_ReservePublicKeyP rpub;
- struct TALER_EXCHANGEDB_KycStatus kyc;
memset (&rpub,
44,
sizeof (rpub));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->inselect_wallet_kyc_status (plugin->cls,
- &rpub,
- &kyc));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->store_wire_transfer_out (plugin->cls,
wire_out_date,
&wire_out_wtid,
@@ -1034,6 +1031,7 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
struct TALER_Amount coin_fee2;
struct GNUNET_TIME_Timestamp execution_time2;
struct TALER_EXCHANGEDB_KycStatus kyc;
+ enum TALER_AmlDecisionState aml = TALER_AML_FROZEN;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->lookup_transfer_by_deposit (plugin->cls,
@@ -1046,7 +1044,9 @@ test_wire_out (const struct TALER_EXCHANGEDB_Deposit *deposit)
&execution_time2,
&coin_contribution2,
&coin_fee2,
- &kyc));
+ &kyc,
+ &aml));
+ FAILIF (TALER_AML_NORMAL != aml);
GNUNET_assert (0 == GNUNET_memcmp (&wtid2,
&wire_out_wtid));
GNUNET_assert (GNUNET_TIME_timestamp_cmp (execution_time2,
@@ -1093,9 +1093,9 @@ recoup_cb (void *cls,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind)
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind)
{
- const union TALER_DenominationBlindingKeyP *cb = cls;
+ const union GNUNET_CRYPTO_BlindingSecretP *cb = cls;
(void) rowid;
(void) timestamp;
@@ -1114,48 +1114,32 @@ drop:
/**
- * Function called on deposits that are past their due date
- * and have not yet seen a wire transfer.
+ * Function called on batch deposits that may require a
+ * wire transfer.
*
* @param cls closure a `struct TALER_EXCHANGEDB_Deposit *`
- * @param rowid deposit table row of the coin's deposit
- * @param coin_pub public key of the coin
- * @param amount value of the deposit, including fee
- * @param payto_uri where should the funds be wired
- * @param deadline what was the requested wire transfer deadline
- * @param done did the exchange claim that it made a transfer?
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
*/
static void
-wire_missing_cb (void *cls,
- uint64_t rowid,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *amount,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp deadline,
- bool done)
+wire_missing_cb (
+ void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline)
{
- const struct TALER_EXCHANGEDB_Deposit *deposit = cls;
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *deposit = cls;
- (void) payto_uri;
+ (void) batch_deposit_serial_id;
(void) deadline;
- (void) rowid;
- if (done)
- {
- GNUNET_break (0);
- result = 66;
- }
- if (0 != TALER_amount_cmp (amount,
- &deposit->amount_with_fee))
- {
- GNUNET_break (0);
- result = 66;
- }
- if (0 != GNUNET_memcmp (coin_pub,
- &deposit->coin.coin_pub))
- {
- GNUNET_break (0);
- result = 66;
- }
+ (void) wire_target_h_payto;
+ if (0 ==
+ TALER_amount_cmp (total_amount,
+ &deposit->amount_with_fee))
+ result = 8;
}
@@ -1194,7 +1178,7 @@ run (void *cls)
struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct TALER_CoinSpendSignatureP coin_sig;
struct GNUNET_TIME_Timestamp deadline;
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_ReservePublicKeyP reserve_pub2;
struct TALER_ReservePublicKeyP reserve_pub3;
@@ -1206,8 +1190,10 @@ run (void *cls)
struct TALER_EXCHANGEDB_ReserveHistory *rh_head;
struct TALER_EXCHANGEDB_BankTransfer *bt;
struct TALER_EXCHANGEDB_CollectableBlindcoin *withdraw;
- struct TALER_EXCHANGEDB_Deposit deposit;
- struct TALER_EXCHANGEDB_Deposit deposit2;
+ struct TALER_EXCHANGEDB_CoinDepositInformation deposit;
+ struct TALER_EXCHANGEDB_BatchDeposit bd;
+ struct TALER_CoinSpendPublicKeyP cpub2;
+ struct TALER_MerchantPublicKeyP mpub2;
struct TALER_EXCHANGEDB_Refund refund;
struct TALER_EXCHANGEDB_TransactionList *tl;
struct TALER_EXCHANGEDB_TransactionList *tlp;
@@ -1227,17 +1213,19 @@ run (void *cls)
uint64_t reserve_out_serial_id;
uint64_t melt_serial_id;
struct TALER_PlanchetMasterSecretP ps;
- union TALER_DenominationBlindingKeyP bks;
- struct TALER_ExchangeWithdrawValues alg_values = {
- /* RSA is simpler, and for the DB there is no real difference between
- CS and RSA, just one should be used, so we use RSA */
- .cipher = TALER_DENOMINATION_RSA
- };
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ const struct TALER_ExchangeWithdrawValues *alg_values
+ = TALER_denom_ewv_rsa_singleton ();
memset (&deposit,
0,
sizeof (deposit));
- deposit.receiver_wire_account = (char *) rcvr;
+ memset (&bd,
+ 0,
+ sizeof (bd));
+ bd.receiver_wire_account = (char *) rcvr;
+ bd.cdis = &deposit;
+ bd.num_cdis = 1;
memset (&salt,
45,
sizeof (salt));
@@ -1254,13 +1242,9 @@ run (void *cls)
}
(void) plugin->drop_tables (plugin->cls);
if (GNUNET_OK !=
- plugin->create_tables (plugin->cls))
- {
- result = 77;
- goto cleanup;
- }
- if (GNUNET_OK !=
- plugin->setup_partitions (plugin->cls, num_partitions))
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
{
result = 77;
goto cleanup;
@@ -1278,7 +1262,7 @@ run (void *cls)
NULL));
/* simple extension check */
FAILIF (GNUNET_OK !=
- test_extension_config ());
+ test_extension_manifest ());
RND_BLK (&reserve_pub);
GNUNET_assert (GNUNET_OK ==
@@ -1290,7 +1274,6 @@ run (void *cls)
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":0.000010",
&fees.deposit));
- deposit.deposit_fee = fees.deposit;
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (CURRENCY ":0.000010",
&fees.refresh));
@@ -1301,15 +1284,28 @@ run (void *cls)
TALER_string_to_amount (CURRENCY ":1.000010",
&amount_with_fee));
result = 4;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->commit (plugin->cls));
now = GNUNET_TIME_timestamp_get ();
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->reserves_in_insert (plugin->cls,
- &reserve_pub,
- &value,
- now,
- sndr,
- "exchange-account-1",
- 4));
+ {
+ struct TALER_EXCHANGEDB_ReserveInInfo reserve = {
+ .reserve_pub = &reserve_pub,
+ .balance = &value,
+ .execution_time = now,
+ .sender_account_details = sndr,
+ .exchange_account_name = "exchange-account-1",
+ .wire_reference = 4
+ };
+ enum GNUNET_DB_QueryStatus qsr;
+
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->reserves_in_insert (plugin->cls,
+ &reserve,
+ 1,
+ &qsr));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ qsr);
+ }
FAILIF (GNUNET_OK !=
check_reserve (&reserve_pub,
value.value,
@@ -1317,14 +1313,28 @@ run (void *cls)
value.currency));
now = GNUNET_TIME_timestamp_get ();
RND_BLK (&reserve_pub2);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->reserves_in_insert (plugin->cls,
- &reserve_pub2,
- &value,
- now,
- sndr,
- "exchange-account-1",
- 5));
+ {
+ struct TALER_EXCHANGEDB_ReserveInInfo reserve = {
+ .reserve_pub = &reserve_pub2,
+ .balance = &value,
+ .execution_time = now,
+ .sender_account_details = sndr,
+ .exchange_account_name = "exchange-account-1",
+ .wire_reference = 5
+ };
+ enum GNUNET_DB_QueryStatus qsr;
+
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->reserves_in_insert (plugin->cls,
+ &reserve,
+ 1,
+ &qsr));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ qsr);
+ }
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "test-2"));
FAILIF (GNUNET_OK !=
check_reserve (&reserve_pub,
value.value,
@@ -1347,7 +1357,7 @@ run (void *cls)
RND_BLK (&cbc.reserve_sig);
RND_BLK (&ps);
TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
+ alg_values,
&bks);
{
struct TALER_PlanchetDetail pd;
@@ -1363,19 +1373,20 @@ run (void *cls)
RND_BLK (&age_hash);
for (size_t i = 0; i < sizeof(p_ah) / sizeof(p_ah[0]); i++)
{
+
RND_BLK (&coin_pub);
GNUNET_assert (GNUNET_OK ==
TALER_denom_blind (&dkp->pub,
&bks,
+ NULL,
p_ah[i],
&coin_pub,
- &alg_values,
+ alg_values,
&c_hash,
&pd.blinded_planchet));
- GNUNET_assert (GNUNET_OK ==
- TALER_coin_ev_hash (&pd.blinded_planchet,
- &cbc.denom_pub_hash,
- &cbc.h_coin_envelope));
+ TALER_coin_ev_hash (&pd.blinded_planchet,
+ &cbc.denom_pub_hash,
+ &cbc.h_coin_envelope);
if (i != 0)
TALER_blinded_denom_sig_free (&cbc.sig);
GNUNET_assert (
@@ -1397,23 +1408,43 @@ run (void *cls)
{
bool found;
+ bool nonce_reuse;
bool balance_ok;
- struct TALER_EXCHANGEDB_KycStatus kyc;
+ bool age_ok;
+ bool conflict;
+ bool denom_unknown;
+ uint16_t maximum_age;
uint64_t ruuid;
+ struct TALER_Amount reserve_balance;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->do_withdraw (plugin->cls,
- NULL,
- &cbc,
- now,
- &found,
- &balance_ok,
- &kyc,
- &ruuid));
+ plugin->do_batch_withdraw (plugin->cls,
+ now,
+ &reserve_pub,
+ &value,
+ true,
+ &found,
+ &balance_ok,
+ &reserve_balance,
+ &age_ok,
+ &maximum_age,
+ &ruuid));
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
+ plugin->do_batch_withdraw_insert (plugin->cls,
+ NULL,
+ &cbc,
+ now,
+ ruuid,
+ &denom_unknown,
+ &conflict,
+ &nonce_reuse));
GNUNET_assert (found);
+ GNUNET_assert (! nonce_reuse);
+ GNUNET_assert (! denom_unknown);
GNUNET_assert (balance_ok);
- GNUNET_assert (! kyc.ok);
}
+
+
FAILIF (GNUNET_OK !=
check_reserve (&reserve_pub,
0,
@@ -1450,7 +1481,7 @@ run (void *cls)
&cbc2.sig,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&dkp->pub));
FAILIF (GNUNET_OK !=
TALER_denom_pub_verify (&dkp->pub,
@@ -1469,7 +1500,7 @@ run (void *cls)
&cbc.sig,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&dkp->pub));
deadline = GNUNET_TIME_timestamp_get ();
{
@@ -1489,23 +1520,22 @@ run (void *cls)
struct GNUNET_TIME_Timestamp deposit_timestamp
= GNUNET_TIME_timestamp_get ();
bool balance_ok;
+ uint32_t bad_balance_idx;
bool in_conflict;
struct TALER_PaytoHashP h_payto;
RND_BLK (&h_payto);
- deposit.refund_deadline
+ bd.refund_deadline
= GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_MONTHS);
- deposit.wire_deadline
+ bd.wire_deadline
= GNUNET_TIME_relative_to_timestamp (GNUNET_TIME_UNIT_MONTHS);
deposit.amount_with_fee = value;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->do_deposit (plugin->cls,
- &deposit,
- known_coin_id,
- &h_payto,
- false,
+ &bd,
&deposit_timestamp,
&balance_ok,
+ &bad_balance_idx,
&in_conflict));
FAILIF (! balance_ok);
FAILIF (in_conflict);
@@ -1518,9 +1548,9 @@ run (void *cls)
bool conflict;
refund.coin = deposit.coin;
- refund.details.merchant_pub = deposit.merchant_pub;
+ refund.details.merchant_pub = bd.merchant_pub;
RND_BLK (&refund.details.merchant_sig);
- refund.details.h_contract_terms = deposit.h_contract_terms;
+ refund.details.h_contract_terms = bd.h_contract_terms;
refund.details.rtransaction_id = 1;
refund.details.refund_amount = value;
refund.details.refund_fee = fees.refund;
@@ -1623,7 +1653,8 @@ run (void *cls)
{
struct TALER_EXCHANGEDB_RefreshRevealedCoin *ccoin;
struct GNUNET_TIME_Timestamp now;
- struct TALER_BlindedRsaPlanchet *rp;
+ struct GNUNET_CRYPTO_BlindedMessage *rp;
+ struct GNUNET_CRYPTO_RsaBlindedMessage *rsa;
struct TALER_BlindedPlanchet *bp;
now = GNUNET_TIME_timestamp_get ();
@@ -1635,18 +1666,22 @@ run (void *cls)
new_denom_pubs[cnt] = new_dkp[cnt]->pub;
ccoin = &revealed_coins[cnt];
bp = &ccoin->blinded_planchet;
- bp->cipher = TALER_DENOMINATION_RSA;
- rp = &bp->details.rsa_blinded_planchet;
- rp->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
+ rp = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ bp->blinded_message = rp;
+ rp->cipher = GNUNET_CRYPTO_BSA_RSA;
+ rp->rc = 1;
+ rsa = &rp->details.rsa_blinded_message;
+ rsa->blinded_msg_size = 1 + (size_t) GNUNET_CRYPTO_random_u64 (
GNUNET_CRYPTO_QUALITY_WEAK,
(RSA_KEY_SIZE / 8) - 1);
- rp->blinded_msg = GNUNET_malloc (rp->blinded_msg_size);
+ rsa->blinded_msg = GNUNET_malloc (rsa->blinded_msg_size);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- rp->blinded_msg,
- rp->blinded_msg_size);
+ rsa->blinded_msg,
+ rsa->blinded_msg_size);
TALER_denom_pub_hash (&new_dkp[cnt]->pub,
&ccoin->h_denom_pub);
- ccoin->exchange_vals = alg_values;
+ TALER_denom_ewv_copy (&ccoin->exchange_vals,
+ alg_values);
TALER_coin_ev_hash (bp,
&ccoin->h_denom_pub,
&ccoin->coin_envelope_hash);
@@ -1704,12 +1739,20 @@ run (void *cls)
/* Just to test fetching a coin with melt history */
struct TALER_EXCHANGEDB_TransactionList *tl;
enum GNUNET_DB_QueryStatus qs;
+ uint64_t etag;
+ struct TALER_Amount balance;
+ struct TALER_DenominationHashP h_denom_pub;
qs = plugin->get_coin_transactions (plugin->cls,
&refresh.coin.coin_pub,
- GNUNET_YES,
+ 0,
+ 0,
+ &etag,
+ &balance,
+ &h_denom_pub,
&tl);
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs);
+ FAILIF (0 >= qs);
+ FAILIF (NULL == tl);
plugin->free_coin_transaction_list (plugin->cls,
tl);
}
@@ -1719,7 +1762,7 @@ run (void *cls)
{
struct GNUNET_TIME_Timestamp recoup_timestamp
= GNUNET_TIME_timestamp_get ();
- union TALER_DenominationBlindingKeyP coin_bks;
+ union GNUNET_CRYPTO_BlindingSecretP coin_bks;
uint64_t new_known_coin_id;
struct TALER_CoinPublicInfo new_coin;
struct TALER_DenominationHashP dph;
@@ -1756,7 +1799,6 @@ run (void *cls)
struct TALER_EXCHANGEDB_Reserve pre_reserve;
struct TALER_EXCHANGEDB_Reserve post_reserve;
struct TALER_Amount delta;
- struct TALER_EXCHANGEDB_KycStatus kyc;
bool recoup_ok;
bool internal_failure;
struct GNUNET_TIME_Timestamp recoup_timestamp
@@ -1765,8 +1807,7 @@ run (void *cls)
pre_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &pre_reserve,
- &kyc));
+ &pre_reserve));
FAILIF (! TALER_amount_is_zero (&pre_reserve.balance));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->do_recoup (plugin->cls,
@@ -1784,8 +1825,7 @@ run (void *cls)
post_reserve.pub = reserve_pub;
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->reserves_get (plugin->cls,
- &post_reserve,
- &kyc));
+ &post_reserve));
FAILIF (0 >=
TALER_amount_subtract (&delta,
&post_reserve.balance,
@@ -1816,7 +1856,8 @@ run (void *cls)
sndr,
&wire_out_wtid,
&amount_with_fee,
- &fee_closing));
+ &fee_closing,
+ 0));
FAILIF (GNUNET_OK !=
check_reserve (&reserve_pub2,
0,
@@ -1830,20 +1871,27 @@ run (void *cls)
sndr,
&wire_out_wtid,
&value,
- &fee_closing));
+ &fee_closing,
+ 0));
FAILIF (GNUNET_OK !=
check_reserve (&reserve_pub,
0,
0,
value.currency));
result = 7;
+ FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
+ plugin->commit (plugin->cls));
/* check reserve history */
{
struct TALER_Amount balance;
+ uint64_t etag_out;
qs = plugin->get_reserve_history (plugin->cls,
&reserve_pub,
+ 0,
+ 0,
+ &etag_out,
&balance,
&rh);
}
@@ -1919,8 +1967,19 @@ run (void *cls)
/* FIXME: not yet tested */
break;
}
+ case TALER_EXCHANGEDB_RO_OPEN_REQUEST:
+ {
+ /* FIXME: not yet tested */
+ break;
+ }
+ case TALER_EXCHANGEDB_RO_CLOSE_REQUEST:
+ {
+ /* FIXME: not yet tested */
+ break;
+ }
}
}
+ GNUNET_assert (4 == cnt);
FAILIF (4 != cnt);
auditor_row_cnt = 0;
@@ -1944,10 +2003,20 @@ run (void *cls)
&audit_refund_cb,
NULL));
FAILIF (1 != auditor_row_cnt);
- qs = plugin->get_coin_transactions (plugin->cls,
- &refund.coin.coin_pub,
- GNUNET_YES,
- &tl);
+ {
+ uint64_t etag = 0;
+ struct TALER_Amount balance;
+ struct TALER_DenominationHashP h_denom_pub;
+
+ qs = plugin->get_coin_transactions (plugin->cls,
+ &refund.coin.coin_pub,
+ 0,
+ 0,
+ &etag,
+ &balance,
+ &h_denom_pub,
+ &tl);
+ }
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs);
GNUNET_assert (NULL != tl);
matched = 0;
@@ -1967,26 +2036,24 @@ run (void *cls)
&deposit.csig));
FAILIF (0 !=
GNUNET_memcmp (&have->merchant_pub,
- &deposit.merchant_pub));
+ &bd.merchant_pub));
FAILIF (0 !=
GNUNET_memcmp (&have->h_contract_terms,
- &deposit.h_contract_terms));
+ &bd.h_contract_terms));
FAILIF (0 !=
GNUNET_memcmp (&have->wire_salt,
- &deposit.wire_salt));
+ &bd.wire_salt));
FAILIF (GNUNET_TIME_timestamp_cmp (have->timestamp,
!=,
- deposit.timestamp));
+ bd.wallet_timestamp));
FAILIF (GNUNET_TIME_timestamp_cmp (have->refund_deadline,
!=,
- deposit.refund_deadline));
+ bd.refund_deadline));
FAILIF (GNUNET_TIME_timestamp_cmp (have->wire_deadline,
!=,
- deposit.wire_deadline));
+ bd.wire_deadline));
FAILIF (0 != TALER_amount_cmp (&have->amount_with_fee,
&deposit.amount_with_fee));
- FAILIF (0 != TALER_amount_cmp (&have->deposit_fee,
- &deposit.deposit_fee));
matched |= 1;
break;
}
@@ -2057,7 +2124,6 @@ run (void *cls)
memset (&deposit,
0,
sizeof (deposit));
- deposit.deposit_fee = fees.deposit;
RND_BLK (&deposit.coin.coin_pub);
TALER_denom_pub_hash (&dkp->pub,
&deposit.coin.denom_pub_hash);
@@ -2066,24 +2132,25 @@ run (void *cls)
&cbc.sig,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&dkp->pub));
RND_BLK (&deposit.csig);
- RND_BLK (&deposit.merchant_pub);
- RND_BLK (&deposit.h_contract_terms);
- RND_BLK (&deposit.wire_salt);
- deposit.receiver_wire_account =
+ RND_BLK (&bd.merchant_pub);
+ RND_BLK (&bd.h_contract_terms);
+ RND_BLK (&bd.wire_salt);
+ bd.receiver_wire_account =
"payto://iban/DE67830654080004822650?receiver-name=Test";
TALER_merchant_wire_signature_hash (
"payto://iban/DE67830654080004822650?receiver-name=Test",
- &deposit.wire_salt,
+ &bd.wire_salt,
&h_wire_wt);
deposit.amount_with_fee = value;
- deposit.deposit_fee = fees.deposit;
-
- deposit.refund_deadline = deadline;
- deposit.wire_deadline = deadline;
+ bd.refund_deadline = deadline;
+ bd.wire_deadline = deadline;
result = 8;
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "test-3"));
{
uint64_t known_coin_id;
struct TALER_DenominationHashP dph;
@@ -2101,22 +2168,30 @@ run (void *cls)
struct GNUNET_TIME_Timestamp r;
struct TALER_Amount deposit_fee;
struct TALER_MerchantWireHashP h_wire;
+ bool balance_ok;
+ uint32_t bad_idx;
+ bool ctr_conflict;
now = GNUNET_TIME_timestamp_get ();
+ TALER_payto_hash (bd.receiver_wire_account,
+ &bd.wire_target_h_payto);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->insert_deposit (plugin->cls,
- now,
- &deposit));
- TALER_merchant_wire_signature_hash (deposit.receiver_wire_account,
- &deposit.wire_salt,
+ plugin->do_deposit (plugin->cls,
+ &bd,
+ &now,
+ &balance_ok,
+ &bad_idx,
+ &ctr_conflict));
+ TALER_merchant_wire_signature_hash (bd.receiver_wire_account,
+ &bd.wire_salt,
&h_wire);
FAILIF (1 !=
plugin->have_deposit2 (plugin->cls,
- &deposit.h_contract_terms,
+ &bd.h_contract_terms,
&h_wire,
&deposit.coin.coin_pub,
- &deposit.merchant_pub,
- deposit.refund_deadline,
+ &bd.merchant_pub,
+ bd.refund_deadline,
&deposit_fee,
&r));
FAILIF (GNUNET_TIME_timestamp_cmp (now,
@@ -2124,29 +2199,20 @@ run (void *cls)
r));
}
{
- struct GNUNET_TIME_Timestamp start_range;
- struct GNUNET_TIME_Timestamp end_range;
-
- start_range = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_subtract (deadline.abs_time,
- GNUNET_TIME_UNIT_SECONDS));
- end_range = GNUNET_TIME_absolute_to_timestamp (
- GNUNET_TIME_absolute_add (deadline.abs_time,
- GNUNET_TIME_UNIT_SECONDS));
- FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- plugin->select_deposits_missing_wire (plugin->cls,
- start_range,
- end_range,
- &wire_missing_cb,
- &deposit));
+ result = 66;
+ FAILIF (0 >=
+ plugin->select_batch_deposits_missing_wire (plugin->cls,
+ 0,
+ &wire_missing_cb,
+ &deposit));
FAILIF (8 != result);
}
auditor_row_cnt = 0;
FAILIF (0 >=
- plugin->select_deposits_above_serial_id (plugin->cls,
- 0,
- &audit_deposit_cb,
- NULL));
+ plugin->select_coin_deposits_above_serial_id (plugin->cls,
+ 0,
+ &audit_deposit_cb,
+ NULL));
FAILIF (0 == auditor_row_cnt);
result = 8;
sleep (2); /* give deposit time to be ready */
@@ -2158,13 +2224,12 @@ run (void *cls)
plugin->get_ready_deposit (plugin->cls,
0,
INT32_MAX,
- true,
&merchant_pub2,
&payto_uri2));
FAILIF (0 != GNUNET_memcmp (&merchant_pub2,
- &deposit.merchant_pub));
+ &bd.merchant_pub));
FAILIF (0 != strcmp (payto_uri2,
- deposit.receiver_wire_account));
+ bd.receiver_wire_account));
TALER_payto_hash (payto_uri2,
&wire_target_h_payto);
GNUNET_free (payto_uri2);
@@ -2180,7 +2245,7 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->aggregate (plugin->cls,
&wire_target_h_payto,
- &deposit.merchant_pub,
+ &bd.merchant_pub,
&wtid,
&total));
}
@@ -2204,6 +2269,7 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->select_aggregation_transient (plugin->cls,
&wire_target_h_payto,
+ &bd.merchant_pub,
"x-bank",
&wtid2,
&total2));
@@ -2211,11 +2277,14 @@ run (void *cls)
plugin->create_aggregation_transient (plugin->cls,
&wire_target_h_payto,
"x-bank",
+ &bd.merchant_pub,
&wtid,
+ 0,
&total));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_aggregation_transient (plugin->cls,
&wire_target_h_payto,
+ &bd.merchant_pub,
"x-bank",
&wtid2,
&total2));
@@ -2232,10 +2301,12 @@ run (void *cls)
plugin->update_aggregation_transient (plugin->cls,
&wire_target_h_payto,
&wtid,
+ 0,
&total));
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->select_aggregation_transient (plugin->cls,
&wire_target_h_payto,
+ &bd.merchant_pub,
"x-bank",
&wtid2,
&total2));
@@ -2252,6 +2323,7 @@ run (void *cls)
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->select_aggregation_transient (plugin->cls,
&wire_target_h_payto,
+ &bd.merchant_pub,
"x-bank",
&wtid2,
&total2));
@@ -2260,37 +2332,35 @@ run (void *cls)
plugin->commit (plugin->cls));
result = 10;
- deposit2 = deposit;
FAILIF (GNUNET_OK !=
plugin->start (plugin->cls,
"test-2"));
- RND_BLK (&deposit2.merchant_pub); /* should fail if merchant is different */
+ RND_BLK (&mpub2); /* should fail if merchant is different */
{
struct TALER_MerchantWireHashP h_wire;
struct GNUNET_TIME_Timestamp r;
struct TALER_Amount deposit_fee;
- TALER_merchant_wire_signature_hash (deposit2.receiver_wire_account,
- &deposit2.wire_salt,
+ TALER_merchant_wire_signature_hash (bd.receiver_wire_account,
+ &bd.wire_salt,
&h_wire);
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->have_deposit2 (plugin->cls,
- &deposit2.h_contract_terms,
+ &bd.h_contract_terms,
&h_wire,
- &deposit2.coin.coin_pub,
- &deposit2.merchant_pub,
- deposit2.refund_deadline,
+ &deposit.coin.coin_pub,
+ &mpub2,
+ bd.refund_deadline,
&deposit_fee,
&r));
- deposit2.merchant_pub = deposit.merchant_pub;
- RND_BLK (&deposit2.coin.coin_pub); /* should fail if coin is different */
+ RND_BLK (&cpub2); /* should fail if coin is different */
FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->have_deposit2 (plugin->cls,
- &deposit2.h_contract_terms,
+ &bd.h_contract_terms,
&h_wire,
- &deposit2.coin.coin_pub,
- &deposit2.merchant_pub,
- deposit2.refund_deadline,
+ &cpub2,
+ &bd.merchant_pub,
+ bd.refund_deadline,
&deposit_fee,
&r));
}
@@ -2299,6 +2369,9 @@ run (void *cls)
/* test revocation */
+ FAILIF (GNUNET_OK !=
+ plugin->start (plugin->cls,
+ "test-3b"));
RND_BLK (&master_sig);
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->insert_denomination_revocation (plugin->cls,
@@ -2337,7 +2410,7 @@ run (void *cls)
FAILIF (GNUNET_OK !=
test_wire_prepare ());
FAILIF (GNUNET_OK !=
- test_wire_out (&deposit));
+ test_wire_out (&bd));
FAILIF (GNUNET_OK !=
test_gc ());
FAILIF (GNUNET_OK !=
@@ -2401,8 +2474,9 @@ main (int argc,
return -1;
}
GNUNET_log_setup (argv[0],
- "WARNING",
+ "INFO",
NULL);
+ TALER_OS_init ();
plugin_name++;
(void) GNUNET_asprintf (&testname,
"test-exchange-db-%s",
diff --git a/src/exchangedb/test_exchangedb_by_j.c b/src/exchangedb/test_exchangedb_by_j.c
new file mode 100644
index 000000000..24b24d5b0
--- /dev/null
+++ b/src/exchangedb/test_exchangedb_by_j.c
@@ -0,0 +1,232 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchangedb/test_exchangedb_by_j.c
+ * @brief test cases for DB interaction functions
+ * @author Joseph Xu
+ */
+#include "platform.h"
+#include "taler_exchangedb_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchangedb_plugin.h"
+#include "math.h"
+#define ROUNDS 10
+
+/**
+ * Global result from the testcase.
+ */
+static int result;
+
+/**
+ * Report line of error if @a cond is true, and jump to label "drop".
+ */
+#define FAILIF(cond) \
+ do { \
+ if (! (cond)) {break;} \
+ GNUNET_break (0); \
+ goto drop; \
+ } while (0)
+
+
+/**
+ * Initializes @a ptr with random data.
+ */
+#define RND_BLK(ptr) \
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr))
+
+/**
+ * Initializes @a ptr with zeros.
+ */
+#define ZR_BLK(ptr) \
+ memset (ptr, 0, sizeof (*ptr))
+
+
+/**
+ * Currency we use. Must match test-exchange-db-*.conf.
+ */
+#define CURRENCY "EUR"
+
+/**
+ * Database plugin under test.
+ */
+static struct TALER_EXCHANGEDB_Plugin *plugin;
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure with config
+ */
+static void
+run (void *cls)
+{
+ static const unsigned int batches[] = {1, 2, 3, 4, 8, 16 };
+ struct GNUNET_TIME_Relative times[sizeof (batches) / sizeof(*batches)];
+ unsigned long long sqrs[sizeof (batches) / sizeof(*batches)];
+ struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const uint32_t num_partitions = 10;
+
+ if (NULL ==
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ {
+ GNUNET_break (0);
+ result = 77;
+ return;
+ }
+
+
+ if (GNUNET_OK !=
+ plugin->create_tables (plugin->cls,
+ true,
+ num_partitions))
+ {
+ GNUNET_break (0);
+ result = 77;
+ goto cleanup;
+ }
+
+ memset (times, 0, sizeof (times));
+ memset (sqrs, 0, sizeof (sqrs));
+ for (unsigned int r = 0; r < ROUNDS; r++)
+ {
+ for (unsigned int i = 0; i< 6; i++)
+ {
+ const char *sndr = "payto://x-taler-bank/localhost:8080/1";
+ struct TALER_Amount value;
+ unsigned int batch_size = batches[i];
+ unsigned int iterations = 16; // 1024*10;
+ struct TALER_ReservePublicKeyP reserve_pubs[iterations];
+ struct GNUNET_TIME_Absolute now;
+ struct GNUNET_TIME_Timestamp ts;
+ struct GNUNET_TIME_Relative duration;
+ struct TALER_EXCHANGEDB_ReserveInInfo reserves[iterations];
+ enum GNUNET_DB_QueryStatus results[iterations];
+ unsigned long long duration_sq;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (CURRENCY ":1.000010",
+ &value));
+ now = GNUNET_TIME_absolute_get ();
+ ts = GNUNET_TIME_timestamp_get ();
+ for (unsigned int r = 0; r<iterations; r++)
+ {
+ RND_BLK (&reserve_pubs[r]);
+ reserves[r].reserve_pub = &reserve_pubs[r];
+ reserves[r].balance = &value;
+ reserves[r].execution_time = ts;
+ reserves[r].sender_account_details = sndr;
+ reserves[r].exchange_account_name = "name";
+ reserves[r].wire_reference = r;
+ }
+ FAILIF (iterations !=
+ plugin->batch2_reserves_in_insert (plugin->cls,
+ reserves,
+ iterations,
+ batch_size,
+ results));
+ duration = GNUNET_TIME_absolute_get_duration (now);
+ times[i] = GNUNET_TIME_relative_add (times[i],
+ duration);
+ duration_sq = duration.rel_value_us * duration.rel_value_us;
+ GNUNET_assert (duration_sq / duration.rel_value_us ==
+ duration.rel_value_us);
+ GNUNET_assert (sqrs[i] + duration_sq >= sqrs[i]);
+ sqrs[i] += duration_sq;
+ fprintf (stdout,
+ "for a batchsize equal to %d it took %s\n",
+ batch_size,
+ GNUNET_STRINGS_relative_time_to_string (duration,
+ GNUNET_NO) );
+
+ system ("./test.sh"); // DELETE AFTER TIMER
+ }
+ }
+ for (unsigned int i = 0; i< 6; i++)
+ {
+ struct GNUNET_TIME_Relative avg;
+ double avg_dbl;
+ double variance;
+
+ avg = GNUNET_TIME_relative_divide (times[i],
+ ROUNDS);
+ avg_dbl = avg.rel_value_us;
+ variance = sqrs[i] - (avg_dbl * avg_dbl * ROUNDS);
+ fprintf (stdout,
+ "Batch[%2u]: %8llu ± %6.0f\n",
+ batches[i],
+ (unsigned long long) avg.rel_value_us,
+ sqrt (variance / (ROUNDS - 1)));
+ }
+
+ result = 0;
+drop:
+ GNUNET_break (GNUNET_OK ==
+ plugin->drop_tables (plugin->cls));
+cleanup:
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ plugin = NULL;
+}
+
+
+int
+main (int argc,
+ char *const argv[])
+{
+ const char *plugin_name;
+ char *config_filename;
+ char *testname;
+ struct GNUNET_CONFIGURATION_Handle *cfg;
+ (void) argc;
+ result = -1;
+ if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+
+ GNUNET_log_setup (argv[0],
+ "WARNING",
+ NULL);
+ plugin_name++;
+ (void) GNUNET_asprintf (&testname,
+ "test-exchange-db-%s",
+ plugin_name);
+ (void) GNUNET_asprintf (&config_filename,
+ "%s.conf",
+ testname);
+ fprintf (stdout,
+ "Using config: %s\n",
+ config_filename);
+ cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_filename))
+ {
+ GNUNET_break (0);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return 2;
+ }
+ GNUNET_SCHEDULER_run (&run,
+ cfg);
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free (config_filename);
+ GNUNET_free (testname);
+ return result;
+}
+
+
+/* end of test_exchangedb_by_j.c */
diff --git a/src/exchangedb/test_idempotency.sh b/src/exchangedb/test_idempotency.sh
new file mode 100755
index 000000000..7314b8c3f
--- /dev/null
+++ b/src/exchangedb/test_idempotency.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+# This file is in the public domain.
+set -eu
+psql talercheck < /dev/null || exit 77
+echo "Initializing DB"
+taler-exchange-dbinit -r -c test-exchange-db-postgres.conf
+echo "Re-initializing DB"
+taler-exchange-dbinit -c test-exchange-db-postgres.conf
+echo "Re-loading procedures"
+psql talercheck < procedures.sql
+echo "Test PASSED"
+exit 0
diff --git a/src/exchangedb/benchmark-0000.sql b/src/exchangedb/versioning.sql
index 116f409b7..444cf95ed 100644
--- a/src/exchangedb/benchmark-0000.sql
+++ b/src/exchangedb/versioning.sql
@@ -146,12 +146,13 @@
BEGIN;
+
-- This file adds versioning support to database it will be loaded to.
-- It requires that PL/pgSQL is already loaded - will raise exception otherwise.
-- All versioning "stuff" (tables, functions) is in "_v" schema.
-- All functions are defined as 'RETURNS SETOF INT4' to be able to make them to RETURN literally nothing (0 rows).
--- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling.
+-- >> RETURNS VOID<< IS similar, but it still outputs "empty line" in psql when calling
CREATE SCHEMA IF NOT EXISTS _v;
COMMENT ON SCHEMA _v IS 'Schema for versioning data and functionality.';
diff --git a/src/extensions/Makefile.am b/src/extensions/Makefile.am
index 5d4ed128e..c867a9512 100644
--- a/src/extensions/Makefile.am
+++ b/src/extensions/Makefile.am
@@ -11,7 +11,7 @@ if USE_COVERAGE
endif
-# Libraries
+# Basic extension handling library
lib_LTLIBRARIES = \
libtalerextensions.la
@@ -22,7 +22,7 @@ libtalerextensions_la_LDFLAGS = \
libtalerextensions_la_SOURCES = \
extensions.c \
- extension_age_restriction.c
+ age_restriction_helper.c
libtalerextensions_la_LIBADD = \
$(top_builddir)/src/json/libtalerjson.la \
@@ -31,3 +31,4 @@ libtalerextensions_la_LIBADD = \
-lgnunetutil \
-ljansson \
$(XLIB)
+
diff --git a/src/extensions/age_restriction/Makefile.am b/src/extensions/age_restriction/Makefile.am
new file mode 100644
index 000000000..bf5b2f5f5
--- /dev/null
+++ b/src/extensions/age_restriction/Makefile.am
@@ -0,0 +1,32 @@
+# This Makefile.am is in the public domain
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/include \
+ $(LIBGCRYPT_CFLAGS) \
+ $(POSTGRESQL_CPPFLAGS)
+
+if USE_COVERAGE
+ AM_CFLAGS = --coverage -O0
+ XLIB = -lgcov
+endif
+
+# Age restriction as extension library
+
+plugindir = $(libdir)/taler
+
+plugin_LTLIBRARIES = \
+ libtaler_extension_age_restriction.la
+
+libtaler_extension_age_restriction_la_LDFLAGS = \
+ $(TALER_PLUGIN_LDFLAGS) \
+ -no-undefined
+
+libtaler_extension_age_restriction_la_SOURCES = \
+ age_restriction.c
+libtaler_extension_age_restriction_la_LIBADD = \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetjson \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
diff --git a/src/extensions/age_restriction/age_restriction.c b/src/extensions/age_restriction/age_restriction.c
new file mode 100644
index 000000000..08b598d50
--- /dev/null
+++ b/src/extensions/age_restriction/age_restriction.c
@@ -0,0 +1,256 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2021-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file age_restriction.c
+ * @brief Utility functions regarding age restriction
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_extensions.h"
+#include "stdint.h"
+
+/* ==================================================
+ *
+ * Age Restriction TALER_Extension implementation
+ *
+ * ==================================================
+ */
+
+/**
+ * @brief local configuration
+ */
+
+static struct TALER_AgeRestrictionConfig AR_config = {0};
+
+/**
+ * @brief implements the TALER_Extension.disable interface.
+ *
+ * @param ext Pointer to the current extension
+ */
+static void
+age_restriction_disable (
+ struct TALER_Extension *ext)
+{
+ if (NULL == ext)
+ return;
+
+ ext->enabled = false;
+ ext->config = NULL;
+
+ AR_config.mask.bits = 0;
+ AR_config.num_groups = 0;
+}
+
+
+/**
+ * @brief implements the TALER_Extension.load_config interface.
+ *
+ * @param ext if NULL, only tests the configuration
+ * @param jconfig the configuration as json
+ */
+static enum GNUNET_GenericReturnValue
+age_restriction_load_config (
+ const json_t *jconfig,
+ struct TALER_Extension *ext)
+{
+ struct TALER_AgeMask mask = {0};
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = TALER_JSON_parse_age_groups (jconfig, &mask);
+ if (GNUNET_OK != ret)
+ return ret;
+
+ /* only testing the parser */
+ if (ext == NULL)
+ return GNUNET_OK;
+
+ if (TALER_Extension_AgeRestriction != ext->type)
+ return GNUNET_SYSERR;
+
+ if (mask.bits > 0)
+ {
+ /* if the mask is not zero, the first bit MUST be set */
+ if (0 == (mask.bits & 1))
+ return GNUNET_SYSERR;
+
+ AR_config.mask.bits = mask.bits;
+ AR_config.num_groups = __builtin_popcount (mask.bits) - 1;
+ }
+
+ ext->config = &AR_config;
+ ext->enabled = true;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "loaded new age restriction config with age groups: %s\n",
+ TALER_age_mask_to_string (&mask));
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * @brief implements the TALER_Extension.manifest interface.
+ *
+ * @param ext if NULL, only tests the configuration
+ * @return configuration as json_t* object, maybe NULL
+ */
+static json_t *
+age_restriction_manifest (
+ const struct TALER_Extension *ext)
+{
+ json_t *conf;
+
+ GNUNET_assert (NULL != ext);
+
+ if (NULL == ext->config)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "age restriction not configured");
+ return json_null ();
+ }
+
+ conf = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("age_groups",
+ TALER_age_mask_to_string (&AR_config.mask))
+ );
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_bool ("critical",
+ ext->critical),
+ GNUNET_JSON_pack_string ("version",
+ ext->version),
+ GNUNET_JSON_pack_object_steal ("config",
+ conf)
+ );
+}
+
+
+/* The extension for age restriction */
+struct TALER_Extension TE_age_restriction = {
+ .type = TALER_Extension_AgeRestriction,
+ .name = "age_restriction",
+ .critical = false,
+ .version = "1",
+ .enabled = false, /* disabled per default */
+ .config = NULL,
+ .disable = &age_restriction_disable,
+ .load_config = &age_restriction_load_config,
+ .manifest = &age_restriction_manifest,
+
+ /* This extension is not a policy extension */
+ .create_policy_details = NULL,
+ .policy_get_handler = NULL,
+ .policy_post_handler = NULL,
+};
+
+
+/**
+ * @brief implements the init() function for GNUNET_PLUGIN_load
+ *
+ * @param arg Pointer to the GNUNET_CONFIGURATION_Handle
+ * @return pointer to TALER_Extension on success or NULL otherwise.
+ */
+void *
+libtaler_extension_age_restriction_init (void *arg)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = arg;
+ char *groups = NULL;
+ struct TALER_AgeMask mask = {0};
+
+ if ((GNUNET_YES !=
+ GNUNET_CONFIGURATION_have_value (cfg,
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION,
+ "ENABLED"))
+ ||
+ (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION,
+ "ENABLED")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "[age restriction] no section %s found in configuration\n",
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION);
+
+ return NULL;
+ }
+
+ /* Age restriction is enabled, extract age groups */
+ if ((GNUNET_YES ==
+ GNUNET_CONFIGURATION_have_value (cfg,
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION,
+ "AGE_GROUPS"))
+ &&
+ (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION,
+ "AGE_GROUPS",
+ &groups)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "[age restriction] AGE_GROUPS in %s is not a string\n",
+ TALER_EXTENSION_SECTION_AGE_RESTRICTION);
+
+ return NULL;
+ }
+
+ if (NULL == groups)
+ groups = GNUNET_strdup (TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_GROUPS);
+
+ if (GNUNET_OK != TALER_parse_age_group_string (groups, &mask))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "[age restriction] couldn't parse age groups: '%s'\n",
+ groups);
+ return NULL;
+ }
+
+ AR_config.mask = mask;
+ AR_config.num_groups = __builtin_popcount (mask.bits) - 1; /* no underflow, first bit always set */
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "[age restriction] setting age mask to %s with #groups: %d\n",
+ TALER_age_mask_to_string (&AR_config.mask),
+ __builtin_popcount (AR_config.mask.bits) - 1);
+
+ TE_age_restriction.config = &AR_config;
+
+ /* Note: we do now have TE_age_restriction_config set, however the extension
+ * is not yet enabled! For age restriction to become active, load_config must
+ * have been called. */
+
+ GNUNET_free (groups);
+ return &TE_age_restriction;
+}
+
+
+/**
+ * @brief implements the done() function for GNUNET_PLUGIN_load
+ *
+ * @param arg unused
+ * @return pointer to TALER_Extension on success or NULL otherwise.
+ */
+void *
+libtaler_extension_age_restriction_done (void *arg)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "[age restriction] disabling and unloading");
+ AR_config.mask.bits = 0;
+ AR_config.num_groups = 0;
+ return NULL;
+}
+
+
+/* end of age_restriction.c */
diff --git a/src/extensions/age_restriction_helper.c b/src/extensions/age_restriction_helper.c
new file mode 100644
index 000000000..8ba835117
--- /dev/null
+++ b/src/extensions/age_restriction_helper.c
@@ -0,0 +1,73 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022- Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file age_restriction_helper.c
+ * @brief Helper functions for age restriction
+ * @author Özgür Kesim
+ */
+
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+#include "taler_extensions.h"
+#include "stdint.h"
+
+
+const struct TALER_AgeRestrictionConfig *
+TALER_extensions_get_age_restriction_config ()
+{
+ const struct TALER_Extension *ext;
+
+ ext = TALER_extensions_get_by_type (TALER_Extension_AgeRestriction);
+ if (NULL == ext)
+ return NULL;
+
+ return ext->config;
+}
+
+
+bool
+TALER_extensions_is_age_restriction_enabled ()
+{
+ const struct TALER_Extension *ext;
+
+ ext = TALER_extensions_get_by_type (TALER_Extension_AgeRestriction);
+ if (NULL == ext)
+ return false;
+
+ return ext->enabled;
+}
+
+
+struct TALER_AgeMask
+TALER_extensions_get_age_restriction_mask ()
+{
+ const struct TALER_Extension *ext;
+ const struct TALER_AgeRestrictionConfig *conf;
+
+ ext = TALER_extensions_get_by_type (TALER_Extension_AgeRestriction);
+
+ if ((NULL == ext) ||
+ (NULL == ext->config))
+ return (struct TALER_AgeMask) {0}
+ ;
+
+ conf = ext->config;
+ return conf->mask;
+}
+
+
+/* end age_restriction_helper.c */
diff --git a/src/extensions/extension_age_restriction.c b/src/extensions/extension_age_restriction.c
deleted file mode 100644
index fedf12d44..000000000
--- a/src/extensions/extension_age_restriction.c
+++ /dev/null
@@ -1,411 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2021-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
- */
-/**
- * @file extension_age_restriction.c
- * @brief Utility functions regarding age restriction
- * @author Özgür Kesim
- */
-#include "platform.h"
-#include "taler_util.h"
-#include "taler_extensions.h"
-#include "stdint.h"
-
-/**
- * Carries all the information we need for age restriction
- */
-struct age_restriction_config
-{
- struct TALER_AgeMask mask;
- size_t num_groups;
-};
-
-/**
- * Global config for this extension
- */
-static struct age_restriction_config TE_age_restriction_config = {0};
-
-/**
- * @param groups String representation of the age groups. Must be of the form
- * a:b:...:n:m
- * with
- * 0 < a < b <...< n < m < 32
- * @param[out] mask Bit representation of the age groups.
- * @return Error if string was invalid, OK otherwise.
- */
-enum GNUNET_GenericReturnValue
-TALER_parse_age_group_string (
- const char *groups,
- struct TALER_AgeMask *mask)
-{
-
- const char *pos = groups;
- unsigned int prev = 0;
- unsigned int val = 0;
- char c;
-
- while (*pos)
- {
- c = *pos++;
- if (':' == c)
- {
- if (prev >= val)
- return GNUNET_SYSERR;
-
- mask->bits |= 1 << val;
- prev = val;
- val = 0;
- continue;
- }
-
- if ('0'>c || '9'<c)
- return GNUNET_SYSERR;
-
- val = 10 * val + c - '0';
-
- if (0>=val || 32<=val)
- return GNUNET_SYSERR;
- }
-
- if (32<=val || prev>=val)
- return GNUNET_SYSERR;
-
- mask->bits |= (1 << val);
- mask->bits |= 1; // mark zeroth group, too
-
- return GNUNET_OK;
-}
-
-
-/**
- * Encodes the age mask into a string, like "8:10:12:14:16:18:21"
- *
- * @param mask Age mask
- * @return String representation of the age mask, allocated by GNUNET_malloc.
- * Can be used as value in the TALER config.
- */
-char *
-TALER_age_mask_to_string (
- const struct TALER_AgeMask *m)
-{
- uint32_t bits = m->bits;
- unsigned int n = 0;
- char *buf = GNUNET_malloc (32 * 3); // max characters possible
- char *pos = buf;
-
- if (NULL == buf)
- {
- return buf;
- }
-
- while (bits != 0)
- {
- bits >>= 1;
- n++;
- if (0 == (bits & 1))
- {
- continue;
- }
-
- if (n > 9)
- {
- *(pos++) = '0' + n / 10;
- }
- *(pos++) = '0' + n % 10;
-
- if (0 != (bits >> 1))
- {
- *(pos++) = ':';
- }
- }
- return buf;
-}
-
-
-/* ==================================================
- *
- * Age Restriction TALER_Extension implementation
- *
- * ==================================================
- */
-
-/**
- * @brief implements the TALER_Extension.disable interface.
- */
-void
-age_restriction_disable (
- struct TALER_Extension *ext)
-{
- if (NULL == ext)
- return;
-
- ext->config = NULL;
-
- if (NULL != ext->config_json)
- {
- json_decref (ext->config_json);
- ext->config_json = NULL;
- }
-
- TE_age_restriction_config.mask.bits = 0;
- TE_age_restriction_config.num_groups = 0;
-}
-
-
-/**
- * @brief implements the TALER_Extension.load_taler_config interface.
- * @param cfg Handle to the GNUNET configuration
- * @param[out] enabled Set to true if age restriction is enabled in the config, false otherwise.
- * @param[out] mask Mask for age restriction. Will be 0 if age restriction was not enabled in the config.
- * @return Error if extension for age restriction was set, but age groups were
- * invalid, OK otherwise.
- */
-static enum GNUNET_GenericReturnValue
-age_restriction_load_taler_config (
- struct TALER_Extension *ext,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- char *groups = NULL;
- enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
- struct TALER_AgeMask mask = {0};
-
- if ((GNUNET_YES !=
- GNUNET_CONFIGURATION_have_value (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "ENABLED"))
- ||
- (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "ENABLED")))
- {
- /* Age restriction is not enabled */
- ext->config = NULL;
- ext->config_json = NULL;
- return GNUNET_OK;
- }
-
- /* Age restriction is enabled, extract age groups */
- if ((GNUNET_YES ==
- GNUNET_CONFIGURATION_have_value (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "AGE_GROUPS"))
- &&
- (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- TALER_EXTENSION_SECTION_AGE_RESTRICTION,
- "AGE_GROUPS",
- &groups)))
- return GNUNET_SYSERR;
-
-
- mask.bits = TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_MASK;
- ret = GNUNET_OK;
-
- if (groups != NULL)
- {
- ret = TALER_parse_age_group_string (groups, &mask);
- if (GNUNET_OK != ret)
- mask.bits = TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_MASK;
- }
-
- if (GNUNET_OK == ret)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "setting age mask to %x with #groups: %d\n", mask.bits,
- __builtin_popcount (mask.bits) - 1);
- TE_age_restriction_config.mask.bits = mask.bits;
- TE_age_restriction_config.num_groups = __builtin_popcount (mask.bits) - 1; /* no underflow, first bit always set */
- ext->config = &TE_age_restriction_config;
-
- /* Note: we do now have TE_age_restriction_config set, however
- * ext->config_json is NOT set, i.e. the extension is not yet active! For
- * age restriction to become active, load_json_config must have been
- * called. */
- }
-
-
- GNUNET_free (groups);
- return ret;
-}
-
-
-/**
- * @brief implements the TALER_Extension.load_json_config interface.
- * @param ext if NULL, only tests the configuration
- * @param config the configuration as json
- */
-static enum GNUNET_GenericReturnValue
-age_restriction_load_json_config (
- struct TALER_Extension *ext,
- json_t *jconfig)
-{
- struct TALER_AgeMask mask = {0};
- enum GNUNET_GenericReturnValue ret;
-
- ret = TALER_JSON_parse_age_groups (jconfig, &mask);
- if (GNUNET_OK != ret)
- return ret;
-
- /* only testing the parser */
- if (ext == NULL)
- return GNUNET_OK;
-
- if (TALER_Extension_AgeRestriction != ext->type)
- return GNUNET_SYSERR;
-
- TE_age_restriction_config.mask.bits = mask.bits;
- TE_age_restriction_config.num_groups = 0;
-
- if (mask.bits > 0)
- {
- /* if the mask is not zero, the first bit MUST be set */
- if (0 == (mask.bits & 1))
- return GNUNET_SYSERR;
-
- TE_age_restriction_config.num_groups = __builtin_popcount (mask.bits) - 1;
- }
-
- ext->config = &TE_age_restriction_config;
-
- if (NULL != ext->config_json)
- json_decref (ext->config_json);
-
- ext->config_json = jconfig;
-
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "loaded new age restriction config with age groups: %s\n",
- TALER_age_mask_to_string (&mask));
-
- return GNUNET_OK;
-}
-
-
-/**
- * @brief implements the TALER_Extension.load_json_config interface.
- * @param ext if NULL, only tests the configuration
- * @param config the configuration as json
- */
-json_t *
-age_restriction_config_to_json (
- const struct TALER_Extension *ext)
-{
- char *mask_str;
- json_t *conf;
-
- GNUNET_assert (NULL != ext);
- GNUNET_assert (NULL != ext->config);
-
- if (NULL != ext->config_json)
- {
- return json_copy (ext->config_json);
- }
-
- mask_str = TALER_age_mask_to_string (&TE_age_restriction_config.mask);
- conf = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("age_groups", mask_str)
- );
-
- return GNUNET_JSON_PACK (
- GNUNET_JSON_pack_bool ("critical", ext->critical),
- GNUNET_JSON_pack_string ("version", ext->version),
- GNUNET_JSON_pack_object_steal ("config", conf)
- );
-}
-
-
-/**
- * @brief implements the TALER_Extension.test_json_config interface.
- */
-static enum GNUNET_GenericReturnValue
-age_restriction_test_json_config (
- const json_t *config)
-{
- struct TALER_AgeMask mask = {0};
-
- return TALER_JSON_parse_age_groups (config, &mask);
-}
-
-
-/* The extension for age restriction */
-struct TALER_Extension TE_age_restriction = {
- .next = NULL,
- .type = TALER_Extension_AgeRestriction,
- .name = "age_restriction",
- .critical = false,
- .version = "1",
- .config = NULL, // disabled per default
- .config_json = NULL,
- .disable = &age_restriction_disable,
- .test_json_config = &age_restriction_test_json_config,
- .load_json_config = &age_restriction_load_json_config,
- .config_to_json = &age_restriction_config_to_json,
- .load_taler_config = &age_restriction_load_taler_config,
-};
-
-enum GNUNET_GenericReturnValue
-TALER_extension_age_restriction_register ()
-{
- return TALER_extensions_add (&TE_age_restriction);
-}
-
-
-bool
-TALER_extensions_age_restriction_is_configured ()
-{
- return (0 != TE_age_restriction_config.mask.bits);
-}
-
-
-struct TALER_AgeMask
-TALER_extensions_age_restriction_ageMask ()
-{
- return TE_age_restriction_config.mask;
-}
-
-
-size_t
-TALER_extensions_age_restriction_num_groups ()
-{
- return TE_age_restriction_config.num_groups;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_JSON_parse_age_groups (const json_t *root,
- struct TALER_AgeMask *mask)
-{
- enum GNUNET_GenericReturnValue ret;
- const char *str;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("age_groups",
- &str),
- GNUNET_JSON_spec_end ()
- };
-
- ret = GNUNET_JSON_parse (root,
- spec,
- NULL,
- NULL);
- if (GNUNET_OK == ret)
- TALER_parse_age_group_string (str, mask);
-
- GNUNET_JSON_parse_free (spec);
-
- return ret;
-}
-
-
-/* end of extension_age_restriction.c */
diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c
index 0df0bae36..999e9317a 100644
--- a/src/extensions/extensions.c
+++ b/src/extensions/extensions.c
@@ -19,56 +19,59 @@
* @author Özgür Kesim
*/
#include "platform.h"
+#include "taler_extensions_policy.h"
#include "taler_util.h"
#include "taler_signatures.h"
#include "taler_extensions.h"
#include "stdint.h"
-
/* head of the list of all registered extensions */
-static struct TALER_Extension *TE_extensions = NULL;
-
+static struct TALER_Extensions TE_extensions = {
+ .next = NULL,
+ .extension = NULL,
+};
-const struct TALER_Extension *
+const struct TALER_Extensions *
TALER_extensions_get_head ()
{
- return TE_extensions;
+ return &TE_extensions;
}
-enum GNUNET_GenericReturnValue
-TALER_extensions_add (
- struct TALER_Extension *extension)
+static enum GNUNET_GenericReturnValue
+add_extension (
+ const struct TALER_Extension *extension)
{
/* Sanity checks */
if ((NULL == extension) ||
(NULL == extension->name) ||
(NULL == extension->version) ||
(NULL == extension->disable) ||
- (NULL == extension->test_json_config) ||
- (NULL == extension->load_json_config) ||
- (NULL == extension->config_to_json) ||
- (NULL == extension->load_taler_config))
+ (NULL == extension->load_config) ||
+ (NULL == extension->manifest))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"invalid extension\n");
return GNUNET_SYSERR;
}
- if (NULL == TE_extensions) /* first extension ?*/
- TE_extensions = (struct TALER_Extension *) extension;
+ if (NULL == TE_extensions.extension) /* first extension ?*/
+ TE_extensions.extension = extension;
else
{
- struct TALER_Extension *iter;
- struct TALER_Extension *last;
+ struct TALER_Extensions *iter;
+ struct TALER_Extensions *last;
/* Check for collisions */
- for (iter = TE_extensions; NULL != iter; iter = iter->next)
+ for (iter = &TE_extensions;
+ NULL != iter && NULL != iter->extension;
+ iter = iter->next)
{
+ const struct TALER_Extension *ext = iter->extension;
last = iter;
- if (extension->type == iter->type ||
+ if (extension->type == ext->type ||
0 == strcasecmp (extension->name,
- iter->name))
+ ext->name))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"extension collision for `%s'\n",
@@ -78,7 +81,11 @@ TALER_extensions_add (
}
/* No collisions found, so add this extension to the list */
- last->next = extension;
+ {
+ struct TALER_Extensions *extn = GNUNET_new (struct TALER_Extensions);
+ extn->extension = extension;
+ last->next = extn;
+ }
}
return GNUNET_OK;
@@ -89,12 +96,12 @@ const struct TALER_Extension *
TALER_extensions_get_by_type (
enum TALER_Extension_Type type)
{
- for (const struct TALER_Extension *it = TE_extensions;
- NULL != it;
+ for (const struct TALER_Extensions *it = &TE_extensions;
+ NULL != it && NULL != it->extension;
it = it->next)
{
- if (it->type == type)
- return it;
+ if (it->extension->type == type)
+ return it->extension;
}
/* No extension found. */
@@ -109,8 +116,7 @@ TALER_extensions_is_enabled_type (
const struct TALER_Extension *ext =
TALER_extensions_get_by_type (type);
- return (NULL != ext &&
- TALER_extensions_is_enabled (ext));
+ return (NULL != ext && ext->enabled);
}
@@ -118,33 +124,34 @@ const struct TALER_Extension *
TALER_extensions_get_by_name (
const char *name)
{
- for (const struct TALER_Extension *it = TE_extensions;
+ for (const struct TALER_Extensions *it = &TE_extensions;
NULL != it;
it = it->next)
{
- if (0 == strcasecmp (name, it->name))
- return it;
+ if (0 == strcasecmp (name, it->extension->name))
+ return it->extension;
}
- /* No extension found. */
+ /* No extension found, try to load it. */
+
return NULL;
}
enum GNUNET_GenericReturnValue
-TALER_extensions_verify_json_config_signature (
- json_t *extensions,
+TALER_extensions_verify_manifests_signature (
+ const json_t *manifests,
struct TALER_MasterSignatureP *extensions_sig,
struct TALER_MasterPublicKeyP *master_pub)
{
- struct TALER_ExtensionConfigHashP h_config;
+ struct TALER_ExtensionManifestsHashP h_manifests;
if (GNUNET_OK !=
- TALER_JSON_extensions_config_hash (extensions,
- &h_config))
+ TALER_JSON_extensions_manifests_hash (manifests,
+ &h_manifests))
return GNUNET_SYSERR;
if (GNUNET_OK !=
- TALER_exchange_offline_extension_config_hash_verify (
- &h_config,
+ TALER_exchange_offline_extension_manifests_hash_verify (
+ &h_manifests,
master_pub,
extensions_sig))
return GNUNET_NO;
@@ -178,7 +185,8 @@ configure_extension (
{
struct LoadConfClosure *col = cls;
const char *name;
- const struct TALER_Extension *extension;
+ char lib_name[1024] = {0};
+ struct TALER_Extension *extension;
if (GNUNET_OK != col->error)
return;
@@ -190,33 +198,53 @@ configure_extension (
name = section + sizeof(TALER_EXTENSION_SECTION_PREFIX) - 1;
- if (NULL ==
- (extension = TALER_extensions_get_by_name (name)))
+
+ /* Load the extension library */
+ GNUNET_snprintf (lib_name,
+ sizeof(lib_name),
+ "libtaler_extension_%s",
+ name);
+ /* Lower-case extension name, config is case-insensitive */
+ for (unsigned int i = 0; i < strlen (lib_name); i++)
+ lib_name[i] = tolower (lib_name[i]);
+
+ extension = GNUNET_PLUGIN_load (lib_name,
+ (void *) col->cfg);
+ if (NULL == extension)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unsupported extension `%s` (section [%s]).\n", name,
+ "Couldn't load extension library to `%s` (section [%s]).\n",
+ name,
section);
col->error = GNUNET_SYSERR;
return;
}
- if (GNUNET_OK !=
- extension->load_taler_config (
- (struct TALER_Extension *) extension,
- col->cfg))
+
+ if (GNUNET_OK != add_extension (extension))
{
+ /* TODO: Ignoring return values here */
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Couldn't parse configuration for extension `%s` (section [%s]).\n",
+ "Couldn't add extension `%s` (section [%s]).\n",
name,
section);
col->error = GNUNET_SYSERR;
+ GNUNET_PLUGIN_unload (
+ lib_name,
+ (void *) col->cfg);
return;
}
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "extension library '%s' loaded\n",
+ lib_name);
}
+static bool extensions_loaded = false;
+
enum GNUNET_GenericReturnValue
-TALER_extensions_load_taler_config (
+TALER_extensions_init (
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
struct LoadConfClosure col = {
@@ -224,112 +252,200 @@ TALER_extensions_load_taler_config (
.error = GNUNET_OK,
};
+ if (extensions_loaded)
+ return GNUNET_OK;
+
GNUNET_CONFIGURATION_iterate_sections (cfg,
&configure_extension,
&col);
+
+ if (GNUNET_OK == col.error)
+ extensions_loaded = true;
+
return col.error;
}
enum GNUNET_GenericReturnValue
-TALER_extensions_is_json_config (
+TALER_extensions_parse_manifest (
json_t *obj,
int *critical,
const char **version,
json_t **config)
{
enum GNUNET_GenericReturnValue ret;
- json_t *cfg;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_boolean ("critical",
critical),
GNUNET_JSON_spec_string ("version",
version),
GNUNET_JSON_spec_json ("config",
- &cfg),
+ config),
GNUNET_JSON_spec_end ()
};
+ *config = NULL;
if (GNUNET_OK !=
(ret = GNUNET_JSON_parse (obj,
spec,
NULL,
NULL)))
return ret;
-
- *config = json_copy (cfg);
- GNUNET_JSON_parse_free (spec);
-
return GNUNET_OK;
}
enum GNUNET_GenericReturnValue
-TALER_extensions_load_json_config (
- json_t *extensions)
+TALER_extensions_load_manifests (
+ const json_t *extensions)
{
- const char*name;
- json_t *blob;
+ const char *name;
+ json_t *manifest;
GNUNET_assert (NULL != extensions);
GNUNET_assert (json_is_object (extensions));
- json_object_foreach (extensions, name, blob)
+ json_object_foreach ((json_t *) extensions, name, manifest)
{
int critical;
const char *version;
json_t *config;
- const struct TALER_Extension *extension =
- TALER_extensions_get_by_name (name);
+ struct TALER_Extension *extension
+ = (struct TALER_Extension *)
+ TALER_extensions_get_by_name (name);
if (NULL == extension)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "no such extension: %s\n", name);
+ "no such extension: %s\n",
+ name);
return GNUNET_SYSERR;
}
/* load and verify criticality, version, etc. */
if (GNUNET_OK !=
- TALER_extensions_is_json_config (
- blob, &critical, &version, &config))
+ TALER_extensions_parse_manifest (
+ manifest,
+ &critical,
+ &version,
+ &config))
return GNUNET_SYSERR;
if (critical != extension->critical
- || 0 != strcmp (version, extension->version) // TODO: libtool compare?
+ || 0 != strcmp (version,
+ extension->version) // TODO: libtool compare?
|| NULL == config
- || GNUNET_OK != extension->test_json_config (config))
+ || (GNUNET_OK !=
+ extension->load_config (config,
+ NULL)) )
return GNUNET_SYSERR;
/* This _should_ work now */
if (GNUNET_OK !=
- extension->load_json_config ((struct TALER_Extension *) extension,
- config))
+ extension->load_config (config,
+ extension))
return GNUNET_SYSERR;
+
+ extension->enabled = true;
}
/* make sure to disable all extensions that weren't mentioned in the json */
- for (const struct TALER_Extension *it = TALER_extensions_get_head ();
+ for (const struct TALER_Extensions *it = TALER_extensions_get_head ();
NULL != it;
it = it->next)
{
- if (NULL == json_object_get (extensions, it->name))
- it->disable ((struct TALER_Extension *) it);
+ if (NULL == json_object_get (extensions, it->extension->name))
+ it->extension->disable ((struct TALER_Extension *) it);
}
return GNUNET_OK;
}
-bool
-TALER_extensions_age_restriction_is_enabled ()
+/*
+ * Policy related
+ */
+
+static char *fulfillment2str[] = {
+ [TALER_PolicyFulfillmentInitial] = "<init>",
+ [TALER_PolicyFulfillmentReady] = "Ready",
+ [TALER_PolicyFulfillmentSuccess] = "Success",
+ [TALER_PolicyFulfillmentFailure] = "Failure",
+ [TALER_PolicyFulfillmentTimeout] = "Timeout",
+ [TALER_PolicyFulfillmentInsufficient] = "Insufficient",
+};
+
+const char *
+TALER_policy_fulfillment_state_str (
+ enum TALER_PolicyFulfillmentState state)
+{
+ GNUNET_assert (TALER_PolicyFulfillmentStateCount > state);
+ return fulfillment2str[state];
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_extensions_create_policy_details (
+ const char *currency,
+ const json_t *policy_options,
+ struct TALER_PolicyDetails *details,
+ const char **error_hint)
{
- const struct TALER_Extension *age =
- TALER_extensions_get_by_type (TALER_Extension_AgeRestriction);
+ enum GNUNET_GenericReturnValue ret;
+ const struct TALER_Extension *extension;
+ const json_t *jtype;
+ const char *type;
+
+ *error_hint = NULL;
+
+ if ((NULL == policy_options) ||
+ (! json_is_object (policy_options)))
+ {
+ *error_hint = "invalid policy object";
+ return GNUNET_SYSERR;
+ }
+
+ jtype = json_object_get (policy_options, "type");
+ if (NULL == jtype)
+ {
+ *error_hint = "no type in policy object";
+ return GNUNET_SYSERR;
+ }
+
+ type = json_string_value (jtype);
+ if (NULL == type)
+ {
+ *error_hint = "invalid type in policy object";
+ return GNUNET_SYSERR;
+ }
+
+ extension = TALER_extensions_get_by_name (type);
+ if ((NULL == extension) ||
+ (NULL == extension->create_policy_details))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Unsupported extension policy '%s' requested\n",
+ type);
+ return GNUNET_NO;
+ }
+
+ /* Set state fields in the policy details to initial values. */
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ &details->accumulated_total));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ &details->policy_fee));
+ details->deadline = GNUNET_TIME_UNIT_FOREVER_TS;
+ details->fulfillment_state = TALER_PolicyFulfillmentInitial;
+ details->no_policy_fulfillment_id = true;
+ ret = extension->create_policy_details (currency,
+ policy_options,
+ details,
+ error_hint);
+ return ret;
- return (NULL != age &&
- NULL != age->config_json &&
- TALER_extensions_age_restriction_is_configured ());
}
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 13b9a1444..45d74ab8e 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -5,6 +5,7 @@ talerinclude_HEADERS = \
platform.h gettext.h \
taler_auditor_service.h \
taler_amount_lib.h \
+ taler_attributes.h \
taler_auditordb_lib.h \
taler_auditordb_plugin.h \
taler_bank_service.h \
@@ -16,7 +17,10 @@ talerinclude_HEADERS = \
taler_exchangedb_lib.h \
taler_exchangedb_plugin.h \
taler_extensions.h \
+ taler_extensions_policy.h \
taler_fakebank_lib.h \
+ taler_kyclogic_lib.h \
+ taler_kyclogic_plugin.h \
taler_json_lib.h \
taler_testing_lib.h \
taler_util.h \
@@ -24,6 +28,7 @@ talerinclude_HEADERS = \
taler_pq_lib.h \
taler_signatures.h \
taler_sq_lib.h \
+ taler_templating_lib.h \
taler_twister_testing_lib.h
EXTRA_DIST = \
diff --git a/src/include/platform.h b/src/include/platform.h
index b2c286b74..db04cb972 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -15,22 +15,22 @@
*/
/**
- * @file exchange/src/include/platform.h
+ * @file include/platform.h
* @brief This file contains the includes and definitions which are used by the
* rest of the modules
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
-
#ifndef PLATFORM_H_
#define PLATFORM_H_
/* Include our configuration header */
#ifndef HAVE_USED_CONFIG_H
-# define HAVE_USED_CONFIG_H
-# ifdef HAVE_CONFIG_H
-# include "taler_config.h"
-# endif
+#define HAVE_USED_CONFIG_H
+#ifdef HAVE_CONFIG_H
+#include "taler_config.h"
+#endif
#endif
+
/* For the exchange build, we do NOT want gettext, even
if it is available! */
#undef ENABLE_NLS
@@ -45,9 +45,6 @@
/* Include the features available for GNU source */
#define _GNU_SOURCE
-/* Include GNUnet's platform file */
-#include <gnunet/platform.h>
-
/* Do not use shortcuts for gcrypt mpi */
#define GCRYPT_NO_MPI_MACROS 1
@@ -67,24 +64,209 @@
#define ENABLE_SANITY_CHECKS 1
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#if HAVE_NETINET_IN_SYSTM_H
+#include <netinet/in_systm.h>
+#endif
+#if HAVE_NETINET_IP_H
+#include <netinet/ip.h> /* superset of previous */
+#endif
+#include <arpa/inet.h>
+#include <netinet/tcp.h>
+#include <pwd.h>
+#include <sys/ioctl.h>
+#include <sys/wait.h>
+#include <grp.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <signal.h>
+#include <libgen.h>
+#ifdef HAVE_MALLOC_H
+#include <malloc.h> /* for mallinfo on GNU */
+#endif
+#include <unistd.h> /* KLB_FIX */
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h> /* KLB_FIX */
+#include <fcntl.h>
+#include <math.h>
+#if HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <time.h>
+#ifdef BSD
+#include <net/if.h>
+#endif
+#if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
+#include <semaphore.h>
+#endif
+#ifdef DARWIN
+#include <dlfcn.h>
+#include <semaphore.h>
+#include <net/if.h>
+#endif
+#if defined(__linux__) || defined(GNU)
+#include <net/if.h>
+#endif
+#ifdef SOLARIS
+#include <sys/sockio.h>
+#include <sys/filio.h>
+#include <sys/loadavg.h>
+#include <semaphore.h>
+#endif
+#if HAVE_UCRED_H
+#include <ucred.h>
+#endif
+#if HAVE_SYS_UCRED_H
+#include <sys/ucred.h>
+#endif
+#if HAVE_IFADDRS_H
+#include <ifaddrs.h>
+#endif
+#include <errno.h>
+#include <limits.h>
+
+#if HAVE_VFORK_H
+#include <vfork.h>
+#endif
+
+#include <ctype.h>
+#if HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#if HAVE_ENDIAN_H
+#include <endian.h>
+#endif
+#if HAVE_SYS_ENDIAN_H
+#include <sys/endian.h>
+#endif
+
+#define DIR_SEPARATOR '/'
+#define DIR_SEPARATOR_STR "/"
+#define PATH_SEPARATOR ':'
+#define PATH_SEPARATOR_STR ":"
+#define NEWLINE "\n"
+
+
+#include <locale.h>
+#include "gettext.h"
+/**
+ * GNU gettext support macro.
+ */
+#define _(String) dgettext (PACKAGE, String)
+
+
+#include <sys/mman.h>
+
+/* FreeBSD_kernel is not defined on the now discontinued kFreeBSD */
+#if defined(BSD) && defined(__FreeBSD__) && defined(__FreeBSD_kernel__)
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+#endif
+
+#ifdef DARWIN
+#define __BYTE_ORDER BYTE_ORDER
+#define __BIG_ENDIAN BIG_ENDIAN
+/* not available on darwin, override configure */
+#undef HAVE_STAT64
+#undef HAVE_MREMAP
+#endif
+
+#if ! HAVE_ATOLL
+long long
+atoll (const char *nptr);
+
+#endif
+
+#if ENABLE_NLS
+#include "langinfo.h"
+#endif
+
+#ifndef SIZE_MAX
+#define SIZE_MAX ((size_t) (-1))
+#endif
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
+
+#if defined(__sparc__)
+#define MAKE_UNALIGNED(val) ({ __typeof__((val)) __tmp; memmove (&__tmp, &(val), \
+ sizeof((val))); \
+ __tmp; })
+#else
+#define MAKE_UNALIGNED(val) val
+#endif
+
+
+#ifndef PATH_MAX
+/**
+ * Assumed maximum path length.
+ */
+#define PATH_MAX 4096
+#endif
+
+#if HAVE_THREAD_LOCAL_GCC
+#define TALER_THREAD_LOCAL __thread
+#else
+#define TALER_THREAD_LOCAL
+#endif
+
+
/* LSB-style exit status codes */
#ifndef EXIT_INVALIDARGUMENT
+/**
+ * Command-line arguments are invalid.
+ * Restarting useless.
+ */
#define EXIT_INVALIDARGUMENT 2
#endif
#ifndef EXIT_NOTIMPLEMENTED
+/**
+ * The requested operation is not implemented.
+ * Restarting useless.
+ */
#define EXIT_NOTIMPLEMENTED 3
#endif
#ifndef EXIT_NOPERMISSION
+/**
+ * Permissions needed to run are not available.
+ * Restarting useless.
+ */
#define EXIT_NOPERMISSION 4
#endif
#ifndef EXIT_NOTINSTALLED
+/**
+ * Key resources are not installed.
+ * Restarting useless.
+ */
#define EXIT_NOTINSTALLED 5
#endif
#ifndef EXIT_NOTCONFIGURED
+/**
+ * Key configuration settings are missing or invalid.
+ * Restarting useless.
+ */
#define EXIT_NOTCONFIGURED 6
#endif
@@ -93,6 +275,25 @@
#endif
+#ifndef EXIT_NO_RESTART
+/**
+ * Exit code from 'main' if we do not want to be restarted,
+ * except by manual intervention (hard failure).
+ */
+#define EXIT_NO_RESTART 9
+#endif
+
+
+/**
+ * clang et al do not have such an attribute
+ */
+#if __has_attribute (__nonstring__)
+# define __nonstring __attribute__((__nonstring__))
+#else
+# define __nonstring
+#endif
+
+
#endif /* PLATFORM_H_ */
/* end of platform.h */
diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h
index a529cfb84..937238d15 100644
--- a/src/include/taler_amount_lib.h
+++ b/src/include/taler_amount_lib.h
@@ -18,6 +18,10 @@
* @brief amount-representation utility functions
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
*/
+#if ! defined (__TALER_UTIL_LIB_H_INSIDE__)
+#error "Only <taler_util.h> can be included directly."
+#endif
+
#ifndef TALER_AMOUNT_LIB_H
#define TALER_AMOUNT_LIB_H
@@ -124,6 +128,16 @@ struct TALER_Amount
/**
+ * Check that the currency code in @a str is well-formed.
+ *
+ * @param str currency code name to validate
+ * @return #GNUNET_OK if @a str is a valid currency code
+ */
+enum GNUNET_GenericReturnValue
+TALER_check_currency (const char *str);
+
+
+/**
* Parse monetary amount, in the format "T:V.F".
*
* @param str amount string
@@ -398,7 +412,7 @@ TALER_amount_multiply (struct TALER_Amount *result,
* #GNUNET_NO if value was already normalized
* #GNUNET_SYSERR if value was invalid or could not be normalized
*/
-int
+enum GNUNET_GenericReturnValue
TALER_amount_normalize (struct TALER_Amount *amount);
diff --git a/src/include/taler_attributes.h b/src/include/taler_attributes.h
new file mode 100644
index 000000000..862a26928
--- /dev/null
+++ b/src/include/taler_attributes.h
@@ -0,0 +1,129 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2023 Taler Systems SA
+
+ GNU Taler is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ SPDX-License-Identifier: LGPL3.0-or-later
+
+ Note: the LGPL does not apply to all components of GNU Taler,
+ but it does apply to this file.
+ */
+/**
+ * @file src/include/taler_attributes.h
+ * @brief GNU Taler database event types, TO BE generated via https://gana.gnunet.org/
+ */
+#ifndef GNU_TALER_ATTRIBUTES_H
+#define GNU_TALER_ATTRIBUTES_H
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+/**
+ * Legal name of the business/company.
+ */
+#define TALER_ATTRIBUTE_COMPANY_NAME "company_name"
+
+/**
+ * Legal country of registration of the business/company,
+ * 2-letter country code using ISO 3166-2.
+ */
+#define TALER_ATTRIBUTE_REGISTRATION_COUNTRY "registration_country"
+
+/**
+ * Full name, when known/possible using "Lastname, Firstname(s)" format,
+ * but "Firstname(s) Lastname" or "Firstname M. Lastname" should also be
+ * tolerated (as is "Name", especially if the person only has one name).
+ * If the person has no name, an empty string must be given.
+ * NULL for not collected.
+ */
+#define TALER_ATTRIBUTE_FULL_NAME "full_name"
+
+/**
+ * True/false indicator if the individual is a politically
+ * exposed person.
+ */
+#define TALER_ATTRIBUTE_PEP "pep"
+
+/**
+ * Street-level address. Usually includes the street and the house number. May
+ * consist of multiple lines (separated by '\n'). Identifies a house in a city. The city is not
+ * part of the street.
+ */
+#define TALER_ATTRIBUTE_ADDRESS_STREET "street"
+
+/**
+ * City including postal code. If available, a 2-letter country-code prefixes
+ * the postal code, which is before the city (e.g. "DE-42289 Wuppertal"). If
+ * the country code is unknown, the "CC-" prefix is missing. If the ZIP code
+ * is unknown, the hyphen is followed by a space ("DE- Wuppertal"). If only
+ * the city name is known, it is prefixed by a space (" ").
+ * If the city name is unknown, a space is at the end of the value.
+ */
+#define TALER_ATTRIBUTE_ADDRESS_CITY "city"
+
+/**
+ * Phone number (of business or individual). Should come with the "+CC"
+ * prefix including the country code.
+ */
+#define TALER_ATTRIBUTE_PHONE "phone"
+
+/**
+ * Email address (of business or individual). Should be
+ * in the format "user@hostname".
+ */
+#define TALER_ATTRIBUTE_EMAIL "email"
+
+/**
+ * Birthdate of the person, as far as known. YYYY-MM-DD, a value
+ * of 0 (for DD, MM or even YYYY) is to be used for 'unknown'
+ * according to official records.
+ * Thus, 1950-00-00 stands for a birthdate in 1950 with unknown
+ * day and month. If official documents record January 1st or
+ * some other date instead, that day may also be specified.
+ * NULL for not collected.
+ */
+#define TALER_ATTRIBUTE_BIRTHDATE "birthdate"
+
+/**
+ * Citizenship(s) of the person using 2-letter country codes ("US", "DE",
+ * "FR", "IT", etc.) separated by commas if multiple citizenships are
+ * confirmed ("EN,US,DE"). Note that in the latter case it is not guaranteed
+ * that all nationalities were necessarily recorded. Empty string for
+ * stateless persons. NULL for not collected.
+ */
+#define TALER_ATTRIBUTE_NATIONALITIES "nationalities"
+
+/**
+ * Residence countries(s) of the person using 2-letter country codes ("US",
+ * "DE", "FR", "IT", etc.) separated by commas if multiple residences are
+ * confirmed ("EN,US,DE"). Note that in the latter case it is not guaranteed
+ * that all residences were necessarily recorded. Empty string for
+ * international nomads. NULL for not collected.
+ */
+#define TALER_ATTRIBUTE_RESIDENCES "residences"
+
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/include/taler_auditor_service.h b/src/include/taler_auditor_service.h
index 30d18e6e9..36ea781b1 100644
--- a/src/include/taler_auditor_service.h
+++ b/src/include/taler_auditor_service.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -16,6 +16,8 @@
/**
* @file include/taler_auditor_service.h
* @brief C interface of libtalerauditor, a C library to use auditor's HTTP API
+ * This library is not thread-safe, all APIs must only be used from a single thread.
+ * This library calls abort() if it runs out of memory. Be aware of these limitations.
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff
*/
@@ -28,12 +30,12 @@
#include <gnunet/gnunet_curl_lib.h>
-/* ********************* /version *********************** */
+/* ********************* /config *********************** */
/**
- * @brief Information we get from the auditor about auditors.
+ * @brief Information we get from the auditor about itself.
*/
-struct TALER_AUDITOR_VersionInformation
+struct TALER_AUDITOR_ConfigInformation
{
/**
* Public key of the auditing institution. Wallets and merchants
@@ -44,6 +46,11 @@ struct TALER_AUDITOR_VersionInformation
struct TALER_AuditorPublicKeyP auditor_pub;
/**
+ * Master public key of the audited exchange.
+ */
+ struct TALER_MasterPublicKeyP exchange_master_public_key;
+
+ /**
* Supported Taler protocol version by the auditor.
* String in the format current:revision:age using the
* semantics of GNU libtool. See
@@ -147,56 +154,90 @@ struct TALER_AUDITOR_HttpResponse
/**
+ * Response to /config request.
+ */
+struct TALER_AUDITOR_ConfigResponse
+{
+ /**
+ * HTTP response.
+ */
+ struct TALER_AUDITOR_HttpResponse hr;
+
+ /**
+ * Details depending on HTTP status.
+ */
+ union
+ {
+
+ /**
+ * Details for #MHD_HTTP_OK.
+ */
+ struct
+ {
+
+ /**
+ * Protocol compatibility evaluation.
+ */
+ enum TALER_AUDITOR_VersionCompatibility compat;
+
+ /**
+ * Config data returned by /config.
+ */
+ struct TALER_AUDITOR_ConfigInformation vi;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
* Function called with information about the auditor.
*
* @param cls closure
- * @param hr HTTP response data
- * @param vi basic information about the auditor
- * @param compat protocol compatibility information
+ * @param vr response data
*/
typedef void
-(*TALER_AUDITOR_VersionCallback) (
+(*TALER_AUDITOR_ConfigCallback) (
void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- const struct TALER_AUDITOR_VersionInformation *vi,
- enum TALER_AUDITOR_VersionCompatibility compat);
+ const struct TALER_AUDITOR_ConfigResponse *vr);
/**
* @brief Handle to the auditor. This is where we interact with
* a particular auditor and keep the per-auditor information.
*/
-struct TALER_AUDITOR_Handle;
+struct TALER_AUDITOR_GetConfigHandle;
/**
- * Initialise a connection to the auditor. Will connect to the
+ * Obtain meta data about an auditor. Will connect to the
* auditor and obtain information about the auditor's master public
* key and the auditor's auditor. The respective information will
- * be passed to the @a version_cb once available, and all future
- * interactions with the auditor will be checked to be signed
- * (where appropriate) by the respective master key.
+ * be passed to the @a config_cb once available.
*
- * @param ctx the context
+ * @param ctx the context for CURL requests
* @param url HTTP base URL for the auditor
- * @param version_cb function to call with the auditor's version information
- * @param version_cb_cls closure for @a version_cb
+ * @param config_cb function to call with the auditor's config information
+ * @param config_cb_cls closure for @a config_cb
* @return the auditor handle; NULL upon error
*/
-struct TALER_AUDITOR_Handle *
-TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx,
- const char *url,
- TALER_AUDITOR_VersionCallback version_cb,
- void *version_cb_cls);
+struct TALER_AUDITOR_GetConfigHandle *
+TALER_AUDITOR_get_config (struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ TALER_AUDITOR_ConfigCallback config_cb,
+ void *config_cb_cls);
/**
- * Disconnect from the auditor.
+ * Cancel auditor config request.
*
- * @param auditor the auditor handle
+ * @param[in] auditor the auditor handle
*/
void
-TALER_AUDITOR_disconnect (struct TALER_AUDITOR_Handle *auditor);
+TALER_AUDITOR_get_config_cancel (
+ struct TALER_AUDITOR_GetConfigHandle *auditor);
/**
@@ -206,16 +247,28 @@ struct TALER_AUDITOR_DepositConfirmationHandle;
/**
+ * Response to /deposit-confirmation request.
+ */
+struct TALER_AUDITOR_DepositConfirmationResponse
+{
+ /**
+ * HTTP response.
+ */
+ struct TALER_AUDITOR_HttpResponse hr;
+};
+
+
+/**
* Signature of functions called with the result from our call to the
* auditor's /deposit-confirmation handler.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param dcr response data
*/
typedef void
(*TALER_AUDITOR_DepositConfirmationResultCallback)(
void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr);
+ const struct TALER_AUDITOR_DepositConfirmationResponse *dcr);
/**
@@ -225,21 +278,23 @@ typedef void
* that the response is well-formed. If the auditor's reply is not
* well-formed, we return an HTTP status code of zero to @a cb.
*
- * We also verify that the @a exchange_sig is valid for this deposit-confirmation
- * request, and that the @a master_sig is a valid signature for @a
- * exchange_pub. Also, the @a auditor must be ready to operate (i.e. have
- * finished processing the /version reply). If either check fails, we do
- * NOT initiate the transaction with the auditor and instead return NULL.
+ * We also verify that the @a exchange_sig is valid for this
+ * deposit-confirmation request, and that the @a master_sig is a valid
+ * signature for @a exchange_pub. If the check fails, we do NOT initiate the
+ * transaction with the auditor and instead return NULL.
*
- * @param auditor the auditor handle; the auditor must be ready to operate
+ * @param ctx the context for CURL requests
+ * @param url HTTP base URL for the auditor
* @param h_wire hash of merchant wire details
- * @param h_extensions hash over the extensions, if any
+ * @param h_policy hash over the policy, if any
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the auditor)
* @param exchange_timestamp timestamp when the contract was finalized, must not be too far in the future
* @param wire_deadline date until which the exchange should wire the funds
* @param refund_deadline date until which the merchant can issue a refund to the customer via the auditor (can be zero if refunds are not allowed); must not be after the @a wire_deadline
- * @param amount_without_fee the amount confirmed to be wired by the exchange to the merchant
- * @param coin_pub coin’s public key
+ * @param total_without_fee the amount confirmed to be wired by the exchange to the merchant
+ * @param num_coins number of coins involved in the batch deposit
+ * @param coin_pubs array of the coin’s public keys
+ * @param coin_sigs array of the original deposit signatures of the coins in the batch
* @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests)
* @param exchange_sig the signature made with purpose #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT
* @param exchange_pub the public key of the exchange that matches @a exchange_sig
@@ -255,15 +310,18 @@ typedef void
*/
struct TALER_AUDITOR_DepositConfirmationHandle *
TALER_AUDITOR_deposit_confirmation (
- struct TALER_AUDITOR_Handle *auditor,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_PrivateContractHashP *h_contract_terms,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendPublicKeyP *coin_pubs[static num_coins],
+ const struct TALER_CoinSpendSignatureP *coin_sigs[static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const struct TALER_ExchangeSignatureP *exchange_sig,
@@ -287,72 +345,4 @@ TALER_AUDITOR_deposit_confirmation_cancel (
struct TALER_AUDITOR_DepositConfirmationHandle *deposit_confirmation);
-/**
- * Handle for /exchanges API returned by
- * #TALER_AUDITOR_list_exchanges() so that the operation can be
- * cancelled with #TALER_AUDITOR_list_exchanges_cancel()
- */
-struct TALER_AUDITOR_ListExchangesHandle;
-
-
-/**
- * Information about an exchange kept by the auditor.
- */
-struct TALER_AUDITOR_ExchangeInfo
-{
- /**
- * Master public key of the exchange.
- */
- struct TALER_MasterPublicKeyP master_pub;
-
- /**
- * Base URL of the exchange's API.
- */
- const char *exchange_url;
-};
-
-
-/**
- * Function called with the result from /exchanges.
- *
- * @param cls closure
- * @param hr HTTP response data
- * @param num_exchanges length of array at @a ei
- * @param ei information about exchanges returned by the auditor
- */
-typedef void
-(*TALER_AUDITOR_ListExchangesResultCallback)(
- void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- unsigned int num_exchanges,
- const struct TALER_AUDITOR_ExchangeInfo *ei);
-
-/**
- * Submit an /exchanges request to the auditor and get the
- * auditor's response. If the auditor's reply is not
- * well-formed, we return an HTTP status code of zero to @a cb.
- *
- * @param auditor the auditor handle; the auditor must be ready to operate
- * @param cb the callback to call when a reply for this request is available
- * @param cb_cls closure for the above callback
- * @return a handle for this request; NULL if the inputs are invalid (i.e.
- * signatures fail to verify). In this case, the callback is not called.
- */
-struct TALER_AUDITOR_ListExchangesHandle *
-TALER_AUDITOR_list_exchanges (struct TALER_AUDITOR_Handle *auditor,
- TALER_AUDITOR_ListExchangesResultCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a list exchanges request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param leh the list exchanges request handle
- */
-void
-TALER_AUDITOR_list_exchanges_cancel (
- struct TALER_AUDITOR_ListExchangesHandle *leh);
-
-
#endif /* _TALER_AUDITOR_SERVICE_H */
diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h
index b0677739b..c0a771343 100644
--- a/src/include/taler_auditordb_plugin.h
+++ b/src/include/taler_auditordb_plugin.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -25,26 +25,12 @@
#include <jansson.h>
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_db_lib.h>
+#include "taler_util.h"
#include "taler_auditordb_lib.h"
#include "taler_signatures.h"
/**
- * Function called with information about exchanges this
- * auditor is monitoring.
- *
- * @param cls closure
- * @param master_pub master public key of the exchange
- * @param exchange_url base URL of the exchange's API
- */
-typedef void
-(*TALER_AUDITORDB_ExchangeCallback)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url);
-
-
-/**
* Function called with the results of select_historic_denom_revenue()
*
* @param cls closure
@@ -90,302 +76,201 @@ typedef enum GNUNET_GenericReturnValue
/**
- * Structure for remembering the wire auditor's progress over the
- * various tables and (auditor) transactions.
- */
-struct TALER_AUDITORDB_WireProgressPoint
-{
-
- /**
- * Time until which we have confirmed that all wire transactions
- * that the exchange should do, have indeed been done.
- */
- struct GNUNET_TIME_Timestamp last_timestamp;
-
- /**
- * reserves_close uuid until which we have checked
- * reserve closures.
- */
- uint64_t last_reserve_close_uuid;
-};
-
-
-/**
- * Structure for remembering the wire auditor's progress over the
- * various tables and (auditor) transactions per wire account.
- */
-struct TALER_AUDITORDB_WireAccountProgressPoint
-{
- /**
- * serial ID of the last reserve_in transfer the wire auditor processed
- */
- uint64_t last_reserve_in_serial_id;
-
- /**
- * serial ID of the last wire_out the wire auditor processed
- */
- uint64_t last_wire_out_serial_id;
-
-};
-
-
-/**
- * Structure for remembering the auditor's progress over the various
- * tables and (auditor) transactions when analyzing reserves.
+ * Information about a signing key of an exchange.
*/
-struct TALER_AUDITORDB_ProgressPointReserve
+struct TALER_AUDITORDB_ExchangeSigningKey
{
- /**
- * serial ID of the last reserve_in transfer the auditor processed
- */
- uint64_t last_reserve_in_serial_id;
-
- /**
- * serial ID of the last reserve_out the auditor processed
- */
- uint64_t last_reserve_out_serial_id;
-
- /**
- * serial ID of the last recoup entry the auditor processed when
- * considering reserves.
- */
- uint64_t last_reserve_recoup_serial_id;
-
- /**
- * serial ID of the last reserve_close
- * entry the auditor processed.
- */
- uint64_t last_reserve_close_serial_id;
/**
- * serial ID of the last purse_merges
- * entry the auditor processed.
- */
- uint64_t last_purse_merges_serial_id;
-
- /**
- * Serial ID of the last purse_deposits
- * entry the auditor processed.
+ * When does @e exchange_pub start to be used?
*/
- uint64_t last_purse_deposits_serial_id;
+ struct GNUNET_TIME_Timestamp ep_start;
/**
- * serial ID of the last account_merges
- * entry the auditor processed.
+ * When will the exchange stop signing with @e exchange_pub?
*/
- uint64_t last_account_merges_serial_id;
+ struct GNUNET_TIME_Timestamp ep_expire;
/**
- * serial ID of the last history_requests
- * entry the auditor processed.
+ * When does the signing key expire (for legal disputes)?
*/
- uint64_t last_history_requests_serial_id;
+ struct GNUNET_TIME_Timestamp ep_end;
/**
- * serial ID of the last close_requests
- * entry the auditor processed.
+ * What is the public offline signing key this is all about?
*/
- uint64_t last_close_requests_serial_id;
-
-};
-
+ struct TALER_ExchangePublicKeyP exchange_pub;
-/**
- * Structure for remembering the auditor's progress over the various
- * tables and (auditor) transactions when analyzing reserves.
- */
-struct TALER_AUDITORDB_ProgressPointDepositConfirmation
-{
/**
- * serial ID of the last deposit_confirmation the auditor processed
+ * Signature by the offline master key affirming the above.
*/
- uint64_t last_deposit_confirmation_serial_id;
-
+ struct TALER_MasterSignatureP master_sig;
};
/**
- * Structure for remembering the auditor's progress over the various
- * tables and (auditor) transactions when analyzing aggregations.
+ * Information about a deposit confirmation we received from
+ * a merchant.
*/
-struct TALER_AUDITORDB_ProgressPointAggregation
+struct TALER_AUDITORDB_DepositConfirmation
{
/**
- * serial ID of the last prewire transfer the auditor processed
- */
- uint64_t last_wire_out_serial_id;
-};
-
-
-/**
- * Structure for remembering the auditor's progress over the various
- * tables and (auditor) transactions when analyzing coins.
- */
-struct TALER_AUDITORDB_ProgressPointCoin
-{
- /**
- * serial ID of the last withdraw the auditor processed
+ * Hash over the contract for which this deposit is made.
*/
- uint64_t last_withdraw_serial_id;
+ struct TALER_PrivateContractHashP h_contract_terms;
/**
- * serial ID of the last deposit the auditor processed
+ * Hash over the policy extension for the deposit.
*/
- uint64_t last_deposit_serial_id;
+ struct TALER_ExtensionPolicyHashP h_policy;
/**
- * serial ID of the last refresh the auditor processed
+ * Hash over the wiring information of the merchant.
*/
- uint64_t last_melt_serial_id;
+ struct TALER_MerchantWireHashP h_wire;
/**
- * serial ID of the last refund the auditor processed
+ * Time when this deposit confirmation was generated by the exchange.
*/
- uint64_t last_refund_serial_id;
+ struct GNUNET_TIME_Timestamp exchange_timestamp;
/**
- * Serial ID of the last recoup operation the auditor processed.
+ * How much time does the @e merchant have to issue a refund
+ * request? Zero if refunds are not allowed. After this time, the
+ * coin cannot be refunded. Note that the wire transfer will not be
+ * performed by the exchange until the refund deadline. This value
+ * is taken from the original deposit request.
*/
- uint64_t last_recoup_serial_id;
+ struct GNUNET_TIME_Timestamp refund_deadline;
/**
- * Serial ID of the last recoup-of-refresh operation the auditor processed.
+ * How much time does the @e exchange have to wire the funds?
*/
- uint64_t last_recoup_refresh_serial_id;
+ struct GNUNET_TIME_Timestamp wire_deadline;
/**
- * Serial ID of the last purse_deposits operation the auditor processed.
+ * Amount to be deposited, excluding fee. Calculated from the
+ * amount with fee and the fee from the deposit request.
*/
- uint64_t last_purse_deposits_serial_id;
+ struct TALER_Amount total_without_fee;
/**
- * Serial ID of the last purse_refunds operation the auditor processed.
+ * Length of the @e coin_pubs and @e coin_sigs arrays.
*/
- uint64_t last_purse_refunds_serial_id;
-
-};
-
+ unsigned int num_coins;
-/**
- * Information about a signing key of an exchange.
- */
-struct TALER_AUDITORDB_ExchangeSigningKey
-{
/**
- * Public master key of the exchange that certified @e master_sig.
+ * Array of the coin public keys involved in the
+ * batch deposit operation.
*/
- struct TALER_MasterPublicKeyP master_public_key;
+ const struct TALER_CoinSpendPublicKeyP *coin_pubs;
/**
- * When does @e exchange_pub start to be used?
+ * Array of coin deposit signatures from the deposit operation.
*/
- struct GNUNET_TIME_Timestamp ep_start;
+ const struct TALER_CoinSpendSignatureP *coin_sigs;
/**
- * When will the exchange stop signing with @e exchange_pub?
+ * The Merchant's public key. Allows the merchant to later refund
+ * the transaction or to inquire about the wire transfer identifier.
*/
- struct GNUNET_TIME_Timestamp ep_expire;
+ struct TALER_MerchantPublicKeyP merchant;
/**
- * When does the signing key expire (for legal disputes)?
+ * Signature from the exchange of type
+ * #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT.
*/
- struct GNUNET_TIME_Timestamp ep_end;
+ struct TALER_ExchangeSignatureP exchange_sig;
/**
- * What is the public offline signing key this is all about?
+ * Public signing key from the exchange matching @e exchange_sig.
*/
struct TALER_ExchangePublicKeyP exchange_pub;
/**
- * Signature by the offline master key affirming the above.
+ * Exchange master signature over @e exchange_sig.
*/
struct TALER_MasterSignatureP master_sig;
+
};
/**
- * Information about a deposit confirmation we received from
- * a merchant.
+ * Balance values for a reserve (or all reserves).
*/
-struct TALER_AUDITORDB_DepositConfirmation
+struct TALER_AUDITORDB_ReserveFeeBalance
{
-
/**
- * Hash over the contract for which this deposit is made.
+ * Remaining funds.
*/
- struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_Amount reserve_balance;
/**
- * Hash over the extensions for the deposit.
+ * Losses from operations that should not have
+ * happened (e.g. negative balance).
*/
- struct TALER_ExtensionContractHashP h_extensions;
+ struct TALER_Amount reserve_loss;
/**
- * Hash over the wiring information of the merchant.
+ * Fees charged for withdraw.
*/
- struct TALER_MerchantWireHashP h_wire;
+ struct TALER_Amount withdraw_fee_balance;
/**
- * Time when this deposit confirmation was generated by the exchange.
+ * Fees charged for closing.
*/
- struct GNUNET_TIME_Timestamp exchange_timestamp;
+ struct TALER_Amount close_fee_balance;
/**
- * How much time does the @e merchant have to issue a refund
- * request? Zero if refunds are not allowed. After this time, the
- * coin cannot be refunded. Note that the wire transfer will not be
- * performed by the exchange until the refund deadline. This value
- * is taken from the original deposit request.
+ * Fees charged for purse creation.
*/
- struct GNUNET_TIME_Timestamp refund_deadline;
+ struct TALER_Amount purse_fee_balance;
/**
- * How much time does the @e exchange have to wire the funds?
+ * Opening fees charged.
*/
- struct GNUNET_TIME_Timestamp wire_deadline;
+ struct TALER_Amount open_fee_balance;
/**
- * Amount to be deposited, excluding fee. Calculated from the
- * amount with fee and the fee from the deposit request.
+ * History fees charged.
*/
- struct TALER_Amount amount_without_fee;
+ struct TALER_Amount history_fee_balance;
+};
- /**
- * The coin's public key. This is the value that must have been
- * signed (blindly) by the Exchange. The deposit request is to be
- * signed by the corresponding private key (using EdDSA).
- */
- struct TALER_CoinSpendPublicKeyP coin_pub;
+/**
+ * Balance data for denominations in circulation.
+ */
+struct TALER_AUDITORDB_DenominationCirculationData
+{
/**
- * The Merchant's public key. Allows the merchant to later refund
- * the transaction or to inquire about the wire transfer identifier.
+ * Amount of outstanding coins in circulation.
*/
- struct TALER_MerchantPublicKeyP merchant;
+ struct TALER_Amount denom_balance;
/**
- * Signature from the exchange of type
- * #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT.
+ * Amount lost due coins illicitly accepted (effectively, a
+ * negative @a denom_balance).
*/
- struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_Amount denom_loss;
/**
- * Public signing key from the exchange matching @e exchange_sig.
+ * Total amount that could still be theoretically lost in the future due to
+ * recoup operations. (Total put into circulation minus @e recoup_loss).
*/
- struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_Amount denom_risk;
/**
- * Exchange master signature over @e exchange_sig.
+ * Amount lost due to recoups.
*/
- struct TALER_MasterSignatureP master_sig;
+ struct TALER_Amount recoup_loss;
/**
- * Master public key of the exchange corresponding to @e master_sig.
- * Identifies the exchange this is about.
+ * Number of coins of this denomination that the exchange signed into
+ * existence.
*/
- struct TALER_MasterPublicKeyP master_public_key;
-
+ uint64_t num_issued;
};
@@ -406,6 +291,42 @@ typedef enum GNUNET_GenericReturnValue
/**
+ * Function called on deposits that are past their due date
+ * and have not yet seen a wire transfer.
+ *
+ * @param cls closure
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
+ */
+typedef void
+(*TALER_AUDITORDB_WireMissingCallback)(
+ void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline);
+
+
+/**
+ * Function called on expired purses.
+ *
+ * @param cls closure
+ * @param purse_pub public key of the purse
+ * @param balance amount of money in the purse
+ * @param expiration_date when did the purse expire?
+ * @return #GNUNET_OK to continue to iterate
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_AUDITORDB_ExpiredPurseCallback)(
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date);
+
+
+/**
* @brief The plugin API, returned from the plugin's "init" function.
* The argument given to "init" is simply a configuration handle.
*
@@ -440,6 +361,48 @@ struct TALER_AUDITORDB_Plugin
/**
+ * Register callback to be invoked on events of type @a es.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to listen for
+ * @param timeout how long to wait for the event
+ * @param cb function to call when the event happens, possibly
+ * mulrewardle times (until cancel is invoked)
+ * @param cb_cls closure for @a cb
+ * @return handle useful to cancel the listener
+ */
+ struct GNUNET_DB_EventHandler *
+ (*event_listen)(void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ struct GNUNET_TIME_Relative timeout,
+ GNUNET_DB_EventCallback cb,
+ void *cb_cls);
+
+ /**
+ * Stop notifications.
+ *
+ * @param eh handle to unregister.
+ */
+ void
+ (*event_listen_cancel)(struct GNUNET_DB_EventHandler *eh);
+
+
+ /**
+ * Notify all that listen on @a es of an event.
+ *
+ * @param cls database context to use
+ * @param es specification of the event to generate
+ * @param extra additional event data provided
+ * @param extra_size number of bytes in @a extra
+ */
+ void
+ (*event_notify)(void *cls,
+ const struct GNUNET_DB_EventHeaderP *es,
+ const void *extra,
+ size_t extra_size);
+
+
+ /**
* Drop all auditor tables OR deletes recoverable auditor state.
* This should only be used by testcases or when restarting the
* auditor from scratch.
@@ -452,17 +415,21 @@ struct TALER_AUDITORDB_Plugin
*/
enum GNUNET_GenericReturnValue
(*drop_tables)(void *cls,
- int drop_exchangelist);
+ bool drop_exchangelist);
/**
* Create the necessary tables if they are not present
*
* @param cls the @e cls of this struct with the plugin-specific state
+ * @param support_partitions true to support partitioning
+ * @param num_partitions number of partitions to use
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*create_tables)(void *cls);
+ (*create_tables)(void *cls,
+ bool support_partitions,
+ uint32_t num_partitions);
/**
@@ -507,106 +474,21 @@ struct TALER_AUDITORDB_Plugin
/**
- * Insert information about an exchange this auditor will be auditing.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param exchange_url public (base) URL of the API of the exchange
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*insert_exchange)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *exchange_url);
-
-
- /**
- * Delete an exchange from the list of exchanges this auditor is auditing.
- * Warning: this will cascade and delete all knowledge of this auditor related
- * to this exchange!
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*delete_exchange)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub);
-
-
- /**
- * Obtain information about exchanges this auditor is auditing.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param cb function to call with the results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*list_exchanges)(void *cls,
- TALER_AUDITORDB_ExchangeCallback cb,
- void *cb_cls);
-
- /**
- * Insert information about a signing key of the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param sk signing key information to store
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*insert_exchange_signkey)(
- void *cls,
- const struct TALER_AUDITORDB_ExchangeSigningKey *sk);
-
-
- /**
- * Insert information about a deposit confirmation into the database.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param dc deposit confirmation information to store
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*insert_deposit_confirmation)(
- void *cls,
- const struct TALER_AUDITORDB_DepositConfirmation *dc);
-
-
- /**
- * Get information about deposit confirmations from the database.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_public_key for which exchange do we want to get deposit confirmations
- * @param start_id row/serial ID where to start the iteration (0 from
- * the start, exclusive, i.e. serial_ids must start from 1)
- * @param cb function to call with results
- * @param cb_cls closure for @a cb
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*get_deposit_confirmations)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_public_key,
- uint64_t start_id,
- TALER_AUDITORDB_DepositConfirmationCallback cb,
- void *cb_cls);
-
-
- /**
* Insert information about the auditor's progress with an exchange's
* data.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to insert
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_auditor_progress_coin)(
+ (*insert_auditor_progress)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc);
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
/**
@@ -614,282 +496,142 @@ struct TALER_AUDITORDB_Plugin
* must be an existing record for the exchange.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppc where is the auditor in processing
+ * @param progress_key name of the progress indicator
+ * @param progress_offset offset until which we have made progress
+ * @param ... NULL terminated list of additional key-value pairs to update
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_auditor_progress_coin)(
+ (*update_auditor_progress)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointCoin *ppc);
+ const char *progress_key,
+ uint64_t progress_offset,
+ ...);
/**
* Get information about the progress of the auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppc set to where the auditor is in processing
+ * @param progress_key name of the progress indicator
+ * @param[out] progress_offset set to offset until which we have made progress, set to 0 if key was not found
+ * @param ... NULL terminated list of additional key-value pairs to fetch
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_auditor_progress_coin)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointCoin *ppc);
-
- /**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_auditor_progress_reserve)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr);
+ (*get_auditor_progress)(void *cls,
+ const char *progress_key,
+ uint64_t *progress_offset,
+ ...);
/**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
+ * Insert information about a balance tracked by the auditor. There must not be an
+ * existing record.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppr where is the auditor in processing
+ * @param balance_key key of the balance to store
+ * @param balance_value value to store
+ * @param ... NULL terminated list of additional key-value pairs to insert
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_auditor_progress_reserve)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointReserve *ppr);
+ (*insert_balance)(void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_value,
+ ...);
/**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppr set to where the auditor is in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*get_auditor_progress_reserve)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointReserve *ppr);
-
- /**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_auditor_progress_deposit_confirmation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
-
-
- /**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppdc where is the auditor in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*update_auditor_progress_deposit_confirmation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
-
-
- /**
- * Get information about the progress of the auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppdc set to where the auditor is in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*get_auditor_progress_deposit_confirmation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointDepositConfirmation *ppdc);
-
-
- /**
- * Insert information about the auditor's progress with an exchange's
- * data.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_auditor_progress_aggregation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
-
-
- /**
- * Update information about the progress of the auditor. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param ppa where is the auditor in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*update_auditor_progress_aggregation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
-
-
- /**
- * Get information about the progress of the auditor.
+ * Insert information about a balance tracked by the auditor. Destructively updates an
+ * existing record, which must already exist.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] ppa set to where the auditor is in processing
+ * @param balance_key key of the balance to store
+ * @param balance_amount value to store
+ * @param ... NULL terminated list of additional key-value pairs to update
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_auditor_progress_aggregation)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_ProgressPointAggregation *ppa);
+ (*update_balance)(void *cls,
+ const char *balance_key,
+ const struct TALER_Amount *balance_amount,
+ ...);
/**
- * Insert information about the wire auditor's progress with an exchange's
- * data.
+ * Get summary information about balance tracked by the auditor.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @param in_wire_off how far are we in the incoming wire transaction history
- * @param out_wire_off how far are we in the outgoing wire transaction history
+ * @param balance_key key of the balance to store
+ * @param[out] balance_value set to amount stored under @a balance_key, set to invalid amount (all zero) if key was not found
+ * @param ... NULL terminated list of additional key-value pairs to fetch
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_wire_auditor_account_progress)(
- void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t in_wire_off,
- uint64_t out_wire_off);
+ (*get_balance)(void *cls,
+ const char *balance_key,
+ struct TALER_Amount *balance_value,
+ ...);
/**
- * Update information about the progress of the wire auditor. There
- * must be an existing record for the exchange.
+ * Insert information about a signing key of the exchange.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @param in_wire_off how far are we in the incoming wire transaction history
- * @param out_wire_off how far are we in the outgoing wire transaction history
- * @return transaction status code
+ * @param sk signing key information to store
+ * @return query result status
*/
enum GNUNET_DB_QueryStatus
- (*update_wire_auditor_account_progress)(
+ (*insert_exchange_signkey)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- const struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t in_wire_off,
- uint64_t out_wire_off);
+ const struct TALER_AUDITORDB_ExchangeSigningKey *sk);
/**
- * Get information about the progress of the wire auditor.
+ * Insert information about a deposit confirmation into the database.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param[out] pp where is the auditor in processing
- * @param[out] in_wire_off how far are we in the incoming wire transaction history
- * @param[out] out_wire_off how far are we in the outgoing wire transaction history
- * @return transaction status code
+ * @param dc deposit confirmation information to store
+ * @return query result status
*/
enum GNUNET_DB_QueryStatus
- (*get_wire_auditor_account_progress)(
+ (*insert_deposit_confirmation)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const char *account_name,
- struct TALER_AUDITORDB_WireAccountProgressPoint *pp,
- uint64_t *in_wire_off,
- uint64_t *out_wire_off);
+ const struct TALER_AUDITORDB_DepositConfirmation *dc);
/**
- * Insert information about the wire auditor's progress with an exchange's
- * data.
+ * Get information about deposit confirmations from the database.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @return transaction status code
+ * @param start_id row/serial ID where to start the iteration (0 from
+ * the start, exclusive, i.e. serial_ids must start from 1)
+ * @param return_suppressed should suppressed rows be returned anyway?
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return query result status
*/
enum GNUNET_DB_QueryStatus
- (*insert_wire_auditor_progress)(
+ (*get_deposit_confirmations)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp);
+ uint64_t start_id,
+ bool return_suppressed,
+ TALER_AUDITORDB_DepositConfirmationCallback cb,
+ void *cb_cls);
/**
- * Update information about the progress of the wire auditor. There
- * must be an existing record for the exchange.
+ * Delete information about a deposit confirmation from the database.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param pp where is the auditor in processing
- * @return transaction status code
+ * @param row_id row to delete
+ * @return query result status
*/
enum GNUNET_DB_QueryStatus
- (*update_wire_auditor_progress)(
+ (*delete_deposit_confirmation)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_AUDITORDB_WireProgressPoint *pp);
-
-
- /**
- * Get information about the progress of the wire auditor.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param account_name name of the wire account we are auditing
- * @param[out] pp set to where the auditor is in processing
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*get_wire_auditor_progress)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_AUDITORDB_WireProgressPoint *pp);
+ uint64_t row_id);
/**
@@ -898,22 +640,18 @@ struct TALER_AUDITORDB_Plugin
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
+ * @param rfb balance amounts for the reserve
* @param expiration_date expiration date of the reserve
* @param origin_account where did the money in the reserve originally come from
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_reserve_info)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp expiration_date,
- const char *origin_account);
+ (*insert_reserve_info)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date,
+ const char *origin_account);
/**
@@ -922,20 +660,16 @@ struct TALER_AUDITORDB_Plugin
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
+ * @param rfb balance amounts for the reserve
* @param expiration_date expiration date of the reserve
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_reserve_info)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp expiration_date);
+ (*update_reserve_info)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp expiration_date);
/**
@@ -943,24 +677,20 @@ struct TALER_AUDITORDB_Plugin
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @param[out] rowid which row did we get the information from
- * @param[out] reserve_balance amount stored in the reserve
- * @param[out] withdraw_fee_balance amount the exchange gained in withdraw fees
- * due to withdrawals from this reserve
+ * @param[out] rfb set to balances associated with the reserve
* @param[out] expiration_date expiration date of the reserve
* @param[out] sender_account from where did the money in the reserve originally come from
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_reserve_info)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub,
- uint64_t *rowid,
- struct TALER_Amount *reserve_balance,
- struct TALER_Amount *withdraw_fee_balance,
- struct GNUNET_TIME_Timestamp *expiration_date,
- char **sender_account);
+ (*get_reserve_info)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *rowid,
+ struct TALER_AUDITORDB_ReserveFeeBalance *rfb,
+ struct GNUNET_TIME_Timestamp *expiration_date,
+ char **sender_account);
/**
@@ -968,286 +698,202 @@ struct TALER_AUDITORDB_Plugin
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
- * @param master_pub master public key of the exchange
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*del_reserve_info)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_MasterPublicKeyP *master_pub);
+ const struct TALER_ReservePublicKeyP *reserve_pub);
/**
- * Insert information about all reserves. There must not be an
- * existing record for the @a master_pub.
+ * Insert new row into the pending deposits table.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * @param purse_fee_balance amount the exchange gained in purse fees
- * @param history_fee_balance amount the exchange gained in history fees
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the requested wire transfer deadline
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_reserve_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- const struct TALER_Amount *purse_fee_balance,
- const struct TALER_Amount *history_fee_balance);
+ (*insert_pending_deposit)(
+ void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ const struct TALER_Amount *total_amount,
+ struct GNUNET_TIME_Timestamp deadline);
/**
- * Update information about all reserves. Destructively updates an
- * existing record, which must already exist.
+ * Delete a row from the pending deposit table.
+ * Usually done when the respective wire transfer
+ * was finally detected.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param reserve_balance amount stored in the reserve
- * @param withdraw_fee_balance amount the exchange gained in withdraw fees
- * @param purse_fee_balance amount the exchange gained in purse fees
- * @param history_fee_balance amount the exchange gained in history fees
+ * @param batch_deposit_serial_id which entry to delete
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_reserve_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *reserve_balance,
- const struct TALER_Amount *withdraw_fee_balance,
- const struct TALER_Amount *purse_fee_balance,
- const struct TALER_Amount *history_fee_balance);
+ (*delete_pending_deposit)(
+ void *cls,
+ uint64_t batch_deposit_serial_id);
/**
- * Get summary information about all reserves.
+ * Return (batch) deposits for which we have not yet
+ * seen the required wire transfer.
*
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] reserve_balance amount stored in reserves
- * @param[out] withdraw_fee_balance amount the exchange gained in withdraw fees
- * @param[out] purse_fee_balance amount the exchange gained in purse fees
- * @param[out] history_fee_balance amount the exchange gained in history fees
+ * @param deadline only return up to this deadline
+ * @param cb function to call on each entry
+ * @param cb_cls closure for @a cb
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_reserve_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *reserve_balance,
- struct TALER_Amount *withdraw_fee_balance,
- struct TALER_Amount *purse_fee_balance,
- struct TALER_Amount *history_fee_balance);
+ (*select_pending_deposits)(
+ void *cls,
+ struct GNUNET_TIME_Absolute deadline,
+ TALER_AUDITORDB_WireMissingCallback cb,
+ void *cb_cls);
/**
- * Insert information about exchange's wire fee balance. There must not be an
- * existing record for the same @a master_pub.
+ * Insert information about a purse. There must not be an
+ * existing record for the purse.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param wire_fee_balance amount the exchange gained in wire fees
+ * @param purse_pub public key of the purse
+ * @param balance balance of the purse
+ * @param expiration_date expiration date of the purse
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_wire_fee_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance);
+ (*insert_purse_info)(
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp expiration_date);
/**
- * Insert information about exchange's wire fee balance. Destructively updates an
+ * Update information about a purse. Destructively updates an
* existing record, which must already exist.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param wire_fee_balance amount the exchange gained in wire fees
+ * @param purse_pub public key of the purse
+ * @param balance new balance for the purse
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_wire_fee_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *wire_fee_balance);
+ (*update_purse_info)(
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_Amount *balance);
/**
- * Get summary information about an exchanges wire fee balance.
+ * Get information about a purse.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master public key of the exchange
- * @param[out] wire_fee_balance set amount the exchange gained in wire fees
+ * @param purse_pub public key of the purse
+ * @param[out] rowid which row did we get the information from
+ * @param[out] balance set to balance of the purse
+ * @param[out] expiration_date expiration date of the purse
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_wire_fee_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *wire_fee_balance);
+ (*get_purse_info)(
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ uint64_t *rowid,
+ struct TALER_Amount *balance,
+ struct GNUNET_TIME_Timestamp *expiration_date);
/**
- * Insert information about a denomination key's balances. There
- * must not be an existing record for the denomination key.
+ * Delete information about a purse.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the denomination public key
- * @param denom_balance value of coins outstanding with this denomination key
- * @param denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
- * @param denom_risk value of coins issued with this denomination key
- * @param denom_recoup value of coins paid back if this denomination key was revoked
- * @param num_issued how many coins of this denomination did the exchange blind-sign
+ * @param purse_pub public key of the reserve
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_denomination_balance)(
+ (*delete_purse_info)(
void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *denom_loss,
- const struct TALER_Amount *denom_risk,
- const struct TALER_Amount *recoup_loss,
- uint64_t num_issued);
+ const struct TALER_PurseContractPublicKeyP *purse_pub);
/**
- * Update information about a denomination key's balances. There
- * must be an existing record for the denomination key.
+ * Get information about expired purses.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param denom_pub_hash hash of the denomination public key
- * @param denom_balance value of coins outstanding with this denomination key
- * @param denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
- * @param denom_risk value of coins issued with this denomination key
- * @param denom_recoup value of coins paid back if this denomination key was revoked
- * @param num_issued how many coins of this denomination did the exchange blind-sign
+ * @param cb function to call on expired purses
+ * @param cb_cls closure for @a cb
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_denomination_balance)(
+ (*select_purse_expired)(
void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *denom_loss,
- const struct TALER_Amount *denom_risk,
- const struct TALER_Amount *recoup_loss,
- uint64_t num_issued);
+ TALER_AUDITORDB_ExpiredPurseCallback cb,
+ void *cb_cls);
/**
- * Get information about a denomination key's balances.
+ * Insert information about a denomination key's balances. There
+ * must not be an existing record for the denomination key.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param denom_pub_hash hash of the denomination public key
- * @param[out] denom_balance value of coins outstanding with this denomination key
- * @param[out] denom_loss value of coins redeemed that were not outstanding (effectively, negative @a denom_balance)
- * @param[out] denom_risk value of coins issued with this denomination key
- * @param[out] denom_recoup value of coins paid back if this denomination key was revoked
- * @param[out] num_issued how many coins of this denomination did the exchange blind-sign
+ * @param dcd denomination circulation data to store
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_denomination_balance)(
+ (*insert_denomination_balance)(
void *cls,
const struct TALER_DenominationHashP *denom_pub_hash,
- struct TALER_Amount *denom_balance,
- struct TALER_Amount *denom_loss,
- struct TALER_Amount *denom_risk,
- struct TALER_Amount *recoup_loss,
- uint64_t *num_issued);
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd);
/**
- * Delete information about a denomination key's balances.
+ * Update information about a denomination key's balances. There
+ * must be an existing record for the denomination key.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param denom_pub_hash hash of the denomination public key
+ * @param dcd denomination circulation data to store
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*del_denomination_balance)(
+ (*update_denomination_balance)(
void *cls,
- const struct TALER_DenominationHashP *denom_pub_hash);
-
-
- /**
- * Insert information about an exchange's denomination balances. There
- * must not be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param denom_balance value of coins outstanding with this denomination key
- * @param deposit_fee_balance total deposit fees collected for this DK
- * @param melt_fee_balance total melt fees collected for this DK
- * @param refund_fee_balance total refund fees collected for this DK
- * @param risk maximum risk exposure of the exchange
- * @param recoup_loss actual losses from recoup (actualized @a risk)
- * @param irregular_recoups recoups made of non-revoked coins (reduces
- * risk, but should never happen)
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_balance_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk,
- const struct TALER_Amount *recoup_loss,
- const struct TALER_Amount *irregular_recoups);
-
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ const struct TALER_AUDITORDB_DenominationCirculationData *dcd);
/**
- * Update information about an exchange's denomination balances. There
- * must be an existing record for the exchange.
+ * Delete information about a denomination key's balances.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param denom_balance value of coins outstanding with this denomination key
- * @param deposit_fee_balance total deposit fees collected for this DK
- * @param melt_fee_balance total melt fees collected for this DK
- * @param refund_fee_balance total refund fees collected for this DK
- * @param risk maximum risk exposure of the exchange
- * @param recoup_loss actual losses from recoup (actualized @a risk)
- * @param irregular_recoups recoups made of non-revoked coins (reduces
- * risk, but should never happen)
+ * @param denom_pub_hash hash of the denomination public key
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_balance_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *denom_balance,
- const struct TALER_Amount *deposit_fee_balance,
- const struct TALER_Amount *melt_fee_balance,
- const struct TALER_Amount *refund_fee_balance,
- const struct TALER_Amount *risk,
- const struct TALER_Amount *recoup_loss,
- const struct TALER_Amount *irregular_recoups);
+ (*del_denomination_balance)(
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash);
/**
- * Get information about an exchange's denomination balances.
+ * Get information about a denomination key's balances.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] denom_balance value of coins outstanding with this denomination key
- * @param[out] deposit_fee_balance total deposit fees collected for this DK
- * @param[out] melt_fee_balance total melt fees collected for this DK
- * @param[out] refund_fee_balance total refund fees collected for this DK
- * @param[out] risk maximum risk exposure of the exchange
- * @param[out] recoup_loss actual losses from recoup (actualized @a risk)
- * @param[out] irregular_recoups recoups made of non-revoked coins (reduces
- * risk, but should never happen)
+ * @param denom_pub_hash hash of the denomination public key
+ * @param[out] dcd denomination circulation data to initialize
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_balance_summary)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *denom_balance,
- struct TALER_Amount *deposit_fee_balance,
- struct TALER_Amount *melt_fee_balance,
- struct TALER_Amount *refund_fee_balance,
- struct TALER_Amount *risk,
- struct TALER_Amount *recoup_loss,
- struct TALER_Amount *irregular_recoup);
+ (*get_denomination_balance)(
+ void *cls,
+ const struct TALER_DenominationHashP *denom_pub_hash,
+ struct TALER_AUDITORDB_DenominationCirculationData *dcd);
/**
@@ -1255,7 +901,6 @@ struct TALER_AUDITORDB_Plugin
* revenue about a denomination key.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param denom_pub_hash hash of the denomination key
* @param revenue_timestamp when did this profit get realized
* @param revenue_balance what was the total profit made from
@@ -1267,7 +912,6 @@ struct TALER_AUDITORDB_Plugin
enum GNUNET_DB_QueryStatus
(*insert_historic_denom_revenue)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_DenominationHashP *denom_pub_hash,
struct GNUNET_TIME_Timestamp revenue_timestamp,
const struct TALER_Amount *revenue_balance,
@@ -1275,11 +919,9 @@ struct TALER_AUDITORDB_Plugin
/**
- * Obtain all of the historic denomination key revenue
- * of the given @a master_pub.
+ * Obtain all of the historic denomination key revenue.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param cb function to call with the results
* @param cb_cls closure for @a cb
* @return transaction status code
@@ -1287,7 +929,6 @@ struct TALER_AUDITORDB_Plugin
enum GNUNET_DB_QueryStatus
(*select_historic_denom_revenue)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricDenominationRevenueDataCallback cb,
void *cb_cls);
@@ -1296,7 +937,6 @@ struct TALER_AUDITORDB_Plugin
* Insert information about an exchange's historic revenue from reserves.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param start_time beginning of aggregated time interval
* @param end_time end of aggregated time interval
* @param reserve_profits total profits made
@@ -1305,7 +945,6 @@ struct TALER_AUDITORDB_Plugin
enum GNUNET_DB_QueryStatus
(*insert_historic_reserve_revenue)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_Amount *reserve_profits);
@@ -1315,7 +954,6 @@ struct TALER_AUDITORDB_Plugin
* Return information about an exchange's historic revenue from reserves.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
* @param cb function to call with results
* @param cb_cls closure for @a cb
* @return transaction status code
@@ -1323,55 +961,9 @@ struct TALER_AUDITORDB_Plugin
enum GNUNET_DB_QueryStatus
(*select_historic_reserve_revenue)(
void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
TALER_AUDITORDB_HistoricReserveRevenueDataCallback cb,
void *cb_cls);
-
- /**
- * Insert information about the predicted exchange's bank
- * account balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_predicted_result)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance);
-
-
- /**
- * Update information about an exchange's predicted balance. There
- * must be an existing record for the exchange.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param balance what the bank account balance of the exchange should show
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*update_predicted_result)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- const struct TALER_Amount *balance);
-
-
- /**
- * Get an exchange's predicted balance.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param master_pub master key of the exchange
- * @param[out] balance expected bank account balance of the exchange
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*get_predicted_balance)(void *cls,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct TALER_Amount *balance);
-
-
};
diff --git a/src/include/taler_bank_service.h b/src/include/taler_bank_service.h
index bb7f3d33b..e8e32947b 100644
--- a/src/include/taler_bank_service.h
+++ b/src/include/taler_bank_service.h
@@ -100,25 +100,64 @@ struct TALER_BANK_AdminAddIncomingHandle;
/**
+ * Response details for a history request.
+ */
+struct TALER_BANK_AdminAddIncomingResponse
+{
+
+ /**
+ * HTTP status.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+ /**
+ * Details returned depending on the @e http_status.
+ */
+ union
+ {
+
+ /**
+ * Details if status was #MHD_HTTP_OK
+ */
+ struct
+ {
+ /**
+ * unique ID of the wire transfer in the bank's records
+ */
+ uint64_t serial_id;
+
+ /**
+ * time when the transaction was made.
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ } ok;
+
+ } details;
+
+};
+
+/**
* Callbacks of this type are used to return the result of submitting
* a request to transfer funds to the exchange.
*
* @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
- * 0 if the bank's reply is bogus (fails to follow the protocol)
- * @param ec detailed error code
- * @param serial_id unique ID of the wire transfer in the bank's records; UINT64_MAX on error
- * @param timestamp time when the transaction was made.
- * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
+ * @param air response details
*/
typedef void
(*TALER_BANK_AdminAddIncomingCallback) (
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp timestamp,
- const json_t *json);
+ const struct TALER_BANK_AdminAddIncomingResponse *air);
/**
@@ -191,21 +230,64 @@ struct TALER_BANK_TransferHandle;
/**
+ * Response details for a history request.
+ */
+struct TALER_BANK_TransferResponse
+{
+
+ /**
+ * HTTP status.
+ */
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+ /**
+ * Details returned depending on the @e http_status.
+ */
+ union
+ {
+
+ /**
+ * Details if status was #MHD_HTTP_OK
+ */
+ struct
+ {
+
+
+ /**
+ * unique ID of the wire transfer in the bank's records
+ */
+ uint64_t row_id;
+
+ /**
+ * when did the transaction go into effect
+ */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ } ok;
+ } details;
+};
+
+
+/**
* Function called with the result from the execute step.
*
* @param cls closure
- * @param response_code HTTP status code
- * @param ec taler error code
- * @param row_id unique ID of the wire transfer in the bank's records
- * @param timestamp when did the transaction go into effect
+ * @param tr response details
*/
typedef void
(*TALER_BANK_TransferCallback)(
void *cls,
- unsigned int response_code,
- enum TALER_ErrorCode ec,
- uint64_t row_id,
- struct GNUNET_TIME_Timestamp timestamp);
+ const struct TALER_BANK_TransferResponse *tr);
/**
@@ -261,6 +343,11 @@ struct TALER_BANK_CreditHistoryHandle;
struct TALER_BANK_CreditDetails
{
/**
+ * Serial ID of the wire transfer.
+ */
+ uint64_t serial_id;
+
+ /**
* Amount that was transferred
*/
struct TALER_Amount amount;
@@ -271,22 +358,72 @@ struct TALER_BANK_CreditDetails
struct GNUNET_TIME_Timestamp execution_date;
/**
- * Reserve public key encoded in the wire
- * transfer subject.
+ * Reserve public key encoded in the wire transfer subject.
*/
struct TALER_ReservePublicKeyP reserve_pub;
/**
- * payto://-URL of the source account that
- * send the funds.
+ * payto://-URL of the source account that send the funds.
*/
const char *debit_account_uri;
+};
+
+
+/**
+ * Response details for a history request.
+ */
+struct TALER_BANK_CreditHistoryResponse
+{
+
/**
- * payto://-URL of the target account that
- * received the funds.
+ * HTTP status. Note that #MHD_HTTP_OK and #MHD_HTTP_NO_CONTENT are both
+ * successful replies, but @e details will only contain @e success information
+ * if this is set to #MHD_HTTP_OK.
*/
- const char *credit_account_uri;
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+ /**
+ * Details returned depending on the @e http_status.
+ */
+ union
+ {
+
+ /**
+ * Details if status was #MHD_HTTP_OK
+ */
+ struct
+ {
+
+ /**
+ * payto://-URL of the target account that received the funds.
+ */
+ const char *credit_account_uri;
+
+ /**
+ * Array of transactions received.
+ */
+ const struct TALER_BANK_CreditDetails *details;
+
+ /**
+ * Length of the @e details array.
+ */
+ unsigned int details_length;
+
+ } ok;
+
+ } details;
+
};
@@ -295,25 +432,12 @@ struct TALER_BANK_CreditDetails
* the bank for the credit transaction history.
*
* @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
- * 0 if the bank's reply is bogus (fails to follow the protocol),
- * #MHD_HTTP_NO_CONTENT if there are no more results; on success the
- * last callback is always of this status (even if `abs(num_results)` were
- * already returned).
- * @param ec detailed error code
- * @param serial_id monotonically increasing counter corresponding to the transaction
- * @param details details about the wire transfer
- * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param reply details about the response
*/
-typedef enum GNUNET_GenericReturnValue
+typedef void
(*TALER_BANK_CreditHistoryCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- const struct TALER_BANK_CreditDetails *details,
- const json_t *json);
+ const struct TALER_BANK_CreditHistoryResponse *reply);
/**
@@ -370,6 +494,11 @@ struct TALER_BANK_DebitHistoryHandle;
struct TALER_BANK_DebitDetails
{
/**
+ * Serial ID of the wire transfer.
+ */
+ uint64_t serial_id;
+
+ /**
* Amount that was transferred
*/
struct TALER_Amount amount;
@@ -390,16 +519,66 @@ struct TALER_BANK_DebitDetails
const char *exchange_base_url;
/**
- * payto://-URI of the source account that
- * send the funds.
+ * payto://-URI of the target account that received the funds.
*/
- const char *debit_account_uri;
+ const char *credit_account_uri;
+
+};
+
+
+/**
+ * Response details for a history request.
+ */
+struct TALER_BANK_DebitHistoryResponse
+{
/**
- * payto://-URI of the target account that
- * received the funds.
+ * HTTP status. Note that #MHD_HTTP_OK and #MHD_HTTP_NO_CONTENT are both
+ * successful replies, but @e details will only contain @e success information
+ * if this is set to #MHD_HTTP_OK.
*/
- const char *credit_account_uri;
+ unsigned int http_status;
+
+ /**
+ * Taler error code, #TALER_EC_NONE on success.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Full response, NULL if body was not in JSON format.
+ */
+ const json_t *response;
+
+ /**
+ * Details returned depending on the @e http_status.
+ */
+ union
+ {
+
+ /**
+ * Details if status was #MHD_HTTP_OK
+ */
+ struct
+ {
+
+ /**
+ * payto://-URI of the source account that send the funds.
+ */
+ const char *debit_account_uri;
+
+ /**
+ * Array of transactions initiated.
+ */
+ const struct TALER_BANK_DebitDetails *details;
+
+ /**
+ * Length of the @e details array.
+ */
+ unsigned int details_length;
+
+ } ok;
+
+ } details;
};
@@ -409,25 +588,12 @@ struct TALER_BANK_DebitDetails
* the bank for the debit transaction history.
*
* @param cls closure
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for successful status request
- * 0 if the bank's reply is bogus (fails to follow the protocol),
- * #MHD_HTTP_NO_CONTENT if there are no more results; on success the
- * last callback is always of this status (even if `abs(num_results)` were
- * already returned).
- * @param ec detailed error code
- * @param serial_id monotonically increasing counter corresponding to the transaction
- * @param details details about the wire transfer
- * @param json detailed response from the HTTPD, or NULL if reply was not in JSON
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param reply details about the response
*/
-typedef enum GNUNET_GenericReturnValue
+typedef void
(*TALER_BANK_DebitHistoryCallback)(
void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- const struct TALER_BANK_DebitDetails *details,
- const json_t *json);
+ const struct TALER_BANK_DebitHistoryResponse *reply);
/**
diff --git a/src/include/taler_crypto_lib.h b/src/include/taler_crypto_lib.h
index fa13a29ca..b941316b5 100644
--- a/src/include/taler_crypto_lib.h
+++ b/src/include/taler_crypto_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -18,7 +18,12 @@
* @brief taler-specific crypto functions
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff <christian@grothoff.org>
+ * @author Özgür Kesim <oec-taler@kesim.org>
*/
+#if ! defined (__TALER_UTIL_LIB_H_INSIDE__)
+#error "Only <taler_util.h> can be included directly."
+#endif
+
#ifndef TALER_CRYPTO_LIB_H
#define TALER_CRYPTO_LIB_H
@@ -42,6 +47,59 @@
* fixed and part of the protocol.
*/
#define TALER_CNC_KAPPA 3
+#define TALER_CNC_KAPPA_MINUS_ONE_STR "2"
+
+
+/**
+ * Possible AML decision states.
+ */
+enum TALER_AmlDecisionState
+{
+
+ /**
+ * All AML requirements are currently satisfied.
+ */
+ TALER_AML_NORMAL = 0,
+
+ /**
+ * An AML investigation is pending.
+ */
+ TALER_AML_PENDING = 1,
+
+ /**
+ * An AML decision has concluded that the funds must be frozen.
+ */
+ TALER_AML_FROZEN = 2,
+
+ /**
+ * Maximum allowed numeric value for AML status.
+ */
+ TALER_AML_MAX = 2
+};
+
+
+/**
+ * Possible algorithms for confirmation code generation.
+ */
+enum TALER_MerchantConfirmationAlgorithm
+{
+
+ /**
+ * No purchase confirmation.
+ */
+ TALER_MCA_NONE = 0,
+
+ /**
+ * Purchase confirmation without payment
+ */
+ TALER_MCA_WITHOUT_PRICE = 1,
+
+ /**
+ * Purchase confirmation with payment
+ */
+ TALER_MCA_WITH_PRICE = 2
+
+};
/* ****************** Coin crypto primitives ************* */
@@ -143,6 +201,18 @@ struct TALER_ReserveSignatureP
/**
+ * (Symmetric) key used to encrypt KYC attribute data in the database.
+ */
+struct TALER_AttributeKeyP
+{
+ /**
+ * Actual key material.
+ */
+ struct GNUNET_HashCode key;
+};
+
+
+/**
* @brief Type of public keys to for merchant authorizations.
* Merchants can issue refunds using the corresponding
* private key.
@@ -420,6 +490,17 @@ struct TALER_AgeCommitmentPublicKeyP
};
+/*
+ * @brief Hash to represent the commitment to n*kappa blinded keys during a
+ * age-withdrawal. It is the running SHA512 hash over the hashes of the blinded
+ * envelopes of n*kappa coins.
+ */
+struct TALER_AgeWithdrawCommitmentHashP
+{
+ struct GNUNET_HashCode hash;
+};
+
+
/**
* @brief Type of online public keys used by the wallet to establish a purse and the associated contract meta data.
*/
@@ -496,20 +577,39 @@ struct TALER_PurseMergeSignatureP
/**
- * @brief Type of blinding keys for Taler.
- * must be 32 bytes (DB)
+ * @brief Type of online public keys used by AML officers.
*/
-union TALER_DenominationBlindingKeyP
+struct TALER_AmlOfficerPublicKeyP
{
/**
- * Clause Schnorr Signatures have 2 blinding secrets, each containing two unpredictable values. (must be 32 bytes)
+ * Taler uses EdDSA for AML decision signing.
*/
- struct GNUNET_CRYPTO_CsNonce nonce;
+ struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub;
+};
+
+/**
+ * @brief Type of online private keys used to identify
+ * AML officers.
+ */
+struct TALER_AmlOfficerPrivateKeyP
+{
/**
- * Taler uses RSA for blind signatures.
+ * Taler uses EdDSA for AML decision signing.
*/
- struct GNUNET_CRYPTO_RsaBlindingKeySecret rsa_bks;
+ struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv;
+};
+
+
+/**
+ * @brief Type of signatures used by AML officers.
+ */
+struct TALER_AmlOfficerSignatureP
+{
+ /**
+ * Taler uses EdDSA for AML decision signing.
+ */
+ struct GNUNET_CRYPTO_EddsaSignature eddsa_signature;
};
@@ -527,6 +627,19 @@ struct TALER_RefreshCommitmentP
/**
+ * Symmetric key we use to encrypt KYC attributes
+ * in our database.
+ */
+struct TALER_AttributeEncryptionKeyP
+{
+ /**
+ * The key is a hash code.
+ */
+ struct GNUNET_HashCode hash;
+};
+
+
+/**
* Token used for access control to the merchant's unclaimed
* orders.
*/
@@ -638,10 +751,9 @@ struct TALER_PrivateContractHashP
/**
- * Hash used to represent the "public" extensions to
- * a contract that is shared with the exchange.
+ * Hash used to represent the policy extension to a deposit
*/
-struct TALER_ExtensionContractHashP
+struct TALER_ExtensionPolicyHashP
{
/**
* Actual hash value.
@@ -703,9 +815,9 @@ struct TALER_CoinPubHashP
/**
- * @brief Value that uniquely identifies a tip.
+ * @brief Value that uniquely identifies a reward.
*/
-struct TALER_TipIdentifierP
+struct TALER_RewardIdentifierP
{
/**
* The tip identifier is a SHA-512 hash code.
@@ -727,10 +839,10 @@ struct TALER_PickupIdentifierP
/**
- * @brief Salted hash over the JSON object representing the configuration of an
- * extension.
+ * @brief Salted hash over the JSON object representing the manifests of
+ * extensions.
*/
-struct TALER_ExtensionConfigHashP
+struct TALER_ExtensionManifestsHashP
{
/**
* Actual hash value.
@@ -792,12 +904,6 @@ struct TALER_WireFeeSetNBOP
*/
struct TALER_AmountNBO closing;
- /**
- * The fee the exchange charges for cross-exchange
- * P2P payments.
- */
- struct TALER_AmountNBO wad;
-
};
@@ -809,28 +915,20 @@ struct TALER_GlobalFeeSetNBOP
{
/**
- * The fee the exchange charges for returning the
- * history of a reserve or account.
+ * The fee the exchange charges for returning the history of a reserve or
+ * account.
*/
struct TALER_AmountNBO history;
/**
- * The fee the exchange charges for performing a
- * KYC check on a reserve to turn it into an account
- * that can be used for P2P payments.
- */
- struct TALER_AmountNBO kyc;
-
- /**
- * The fee the exchange charges for keeping
- * an account or reserve open for a year.
+ * The fee the exchange charges for keeping an account or reserve open for a
+ * year.
*/
struct TALER_AmountNBO account;
/**
- * The fee the exchange charges if a purse
- * is abandoned and this was not covered by
- * the account limit.
+ * The fee the exchange charges if a purse is abandoned and this was not
+ * covered by the account limit.
*/
struct TALER_AmountNBO purse;
};
@@ -840,6 +938,38 @@ GNUNET_NETWORK_STRUCT_END
/**
+ * Compute RFC 3548 base32 decoding of @a val and write
+ * result to @a udata.
+ *
+ * @param val value to decode
+ * @param val_size number of bytes in @a val
+ * @param key is the val in bits
+ * @param key_len is the size of @a key
+ */
+int
+TALER_rfc3548_base32decode (const char *val,
+ size_t val_size,
+ void *key,
+ size_t key_len);
+
+
+/**
+ * @brief Builds POS confirmation token to verify payment.
+ *
+ * @param pos_key encoded key for verification payment
+ * @param pos_alg algorithm to compute the payment verification
+ * @param total of the order paid
+ * @param ts is the time given
+ * @return POS token on success, NULL otherwise
+ */
+char *
+TALER_build_pos_confirmation (const char *pos_key,
+ enum TALER_MerchantConfirmationAlgorithm pos_alg,
+ const struct TALER_Amount *total,
+ struct GNUNET_TIME_Timestamp ts);
+
+
+/**
* Set of the fees applying to a denomination.
*/
struct TALER_DenomFeeSet
@@ -874,15 +1004,13 @@ struct TALER_DenomFeeSet
/**
- * Set of the fees applying for a given
- * time-range and wire method.
+ * Set of the fees applying for a given time-range and wire method.
*/
struct TALER_WireFeeSet
{
/**
- * The fee the exchange charges for wiring funds
- * to a merchant.
+ * The fee the exchange charges for wiring funds to a merchant.
*/
struct TALER_Amount wire;
@@ -892,12 +1020,6 @@ struct TALER_WireFeeSet
*/
struct TALER_Amount closing;
- /**
- * The fee the exchange charges for cross-exchange
- * P2P payments.
- */
- struct TALER_Amount wad;
-
};
@@ -915,13 +1037,6 @@ struct TALER_GlobalFeeSet
struct TALER_Amount history;
/**
- * The fee the exchange charges for performing a
- * KYC check on a reserve to turn it into an account
- * that can be used for P2P payments.
- */
- struct TALER_Amount kyc;
-
- /**
* The fee the exchange charges for keeping
* an account or reserve open for a year.
*/
@@ -1036,6 +1151,7 @@ void
TALER_rsa_pub_hash (const struct GNUNET_CRYPTO_RsaPublicKey *rsa,
struct TALER_RsaPubHashP *h_rsa);
+
/**
* Hash @a cs.
*
@@ -1048,75 +1164,16 @@ TALER_cs_pub_hash (const struct GNUNET_CRYPTO_CsPublicKey *cs,
/**
- * Types of public keys used for denominations in Taler.
- */
-enum TALER_DenominationCipher
-{
-
- /**
- * Invalid type of signature.
- */
- TALER_DENOMINATION_INVALID = 0,
-
- /**
- * RSA blind signature.
- */
- TALER_DENOMINATION_RSA = 1,
-
- /**
- * Clause Blind Schnorr signature.
- */
- TALER_DENOMINATION_CS = 2
-};
-
-
-/**
* @brief Type of (unblinded) coin signatures for Taler.
*/
struct TALER_DenominationSignature
{
-
- /**
- * Type of the signature.
- */
- enum TALER_DenominationCipher cipher;
-
/**
- * Details, depending on @e cipher.
+ * Denominations use blind signatures.
*/
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- */
- struct GNUNET_CRYPTO_CsSignature cs_signature;
-
- /**
- * If we use #TALER_DENOMINATION_RSA in @a cipher.
- */
- struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
-
- } details;
-
+ struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
};
-/**
- * The Sign Answer for Clause Blind Schnorr signature.
- * The sign operation returns a parameter @param b and the signature
- * scalar @param s_scalar.
- */
-struct TALER_BlindedDenominationCsSignAnswer
-{
- /**
- * To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_b
- */
- unsigned int b;
-
- /**
- * The blinded s scalar calculated from c_b
- */
- struct GNUNET_CRYPTO_CsBlindS s_scalar;
-};
/**
* @brief Type for *blinded* denomination signatures for Taler.
@@ -1124,33 +1181,13 @@ struct TALER_BlindedDenominationCsSignAnswer
*/
struct TALER_BlindedDenominationSignature
{
-
/**
- * Type of the signature.
+ * Denominations use blind signatures.
*/
- enum TALER_DenominationCipher cipher;
-
- /**
- * Details, depending on @e cipher.
- */
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- * At this point only the blinded s scalar is used.
- * The final signature consisting of r,s is built after unblinding.
- */
- struct TALER_BlindedDenominationCsSignAnswer blinded_cs_answer;
-
- /**
- * If we use #TALER_DENOMINATION_RSA in @a cipher.
- */
- struct GNUNET_CRYPTO_RsaSignature *blinded_rsa_signature;
-
- } details;
-
+ struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
};
+
/* *************** Age Restriction *********************************** */
/*
@@ -1167,6 +1204,9 @@ struct TALER_BlindedDenominationSignature
*
* A value of 0 means that the exchange does not support the extension for
* age-restriction.
+ *
+ * For a non-0 age mask, the 0th bit always must be set, otherwise the age
+ * mask is considered invalid.
*/
struct TALER_AgeMask
{
@@ -1196,13 +1236,8 @@ struct TALER_AgeAttestation
#endif
};
-extern const struct TALER_AgeCommitmentHash TALER_ZeroAgeCommitmentHash;
#define TALER_AgeCommitmentHash_isNullOrZero(ph) ((NULL == ph) || \
- (0 == memcmp (ph, \
- & \
- TALER_ZeroAgeCommitmentHash, \
- sizeof(struct \
- TALER_AgeCommitmentHash))))
+ GNUNET_is_zero (ph))
/**
* @brief Type of public signing keys for verifying blindly signed coins.
@@ -1211,31 +1246,15 @@ struct TALER_DenominationPublicKey
{
/**
- * Type of the public key.
- */
- enum TALER_DenominationCipher cipher;
-
- /**
* Age restriction mask used for the key.
*/
struct TALER_AgeMask age_mask;
/**
- * Details, depending on @e cipher.
+ * Type of the public key.
*/
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- */
- struct GNUNET_CRYPTO_CsPublicKey cs_public_key;
-
- /**
- * If we use #TALER_DENOMINATION_RSA in @a cipher.
- */
- struct GNUNET_CRYPTO_RsaPublicKey *rsa_public_key;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub_key;
- } details;
};
@@ -1245,121 +1264,21 @@ struct TALER_DenominationPublicKey
struct TALER_DenominationPrivateKey
{
- /**
- * Type of the public key.
- */
- enum TALER_DenominationCipher cipher;
-
- /**
- * Details, depending on @e cipher.
- */
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- */
- struct GNUNET_CRYPTO_CsPrivateKey cs_private_key;
-
- /**
- * If we use #TALER_DENOMINATION_RSA in @a cipher.
- */
- struct GNUNET_CRYPTO_RsaPrivateKey *rsa_private_key;
+ struct GNUNET_CRYPTO_BlindSignPrivateKey *bsign_priv_key;
- } details;
-};
-
-/**
- * @brief RSA Parameters to create blinded signature
- *
- */
-struct TALER_BlindedRsaPlanchet
-{
- /**
- * Blinded message to be signed
- * Note: is malloc()'ed!
- */
- void *blinded_msg;
-
- /**
- * Size of the @e blinded_msg to be signed.
- */
- size_t blinded_msg_size;
-};
-
-
-/**
- * Withdraw nonce for CS denominations
- */
-struct TALER_CsNonce
-{
- /**
- * 32 bit nonce to include in withdrawals when using CS.
- */
- struct GNUNET_CRYPTO_CsNonce nonce;
};
/**
- * @brief CS Parameters to create blinded signature
- */
-struct TALER_BlindedCsPlanchet
-{
- /**
- * The Clause Schnorr c_0 and c_1 containing the blinded message
- */
- struct GNUNET_CRYPTO_CsC c[2];
-
- /**
- * Public nonce.
- */
- struct TALER_CsNonce nonce;
-};
-
-
-/**
- * @brief Type including Parameters to create blinded signature
+ * @brief Blinded planchet send to exchange for blind signing.
*/
struct TALER_BlindedPlanchet
{
/**
- * Type of the sign blinded message
- */
- enum TALER_DenominationCipher cipher;
-
- /**
- * Details, depending on @e cipher.
+ * A blinded message.
*/
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- */
- struct TALER_BlindedCsPlanchet cs_blinded_planchet;
+ struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
- /**
- * If we use #TALER_DENOMINATION_RSA in @a cipher.
- */
- struct TALER_BlindedRsaPlanchet rsa_blinded_planchet;
-
- } details;
-};
-
-
-/**
- * Pair of Public R values for Cs denominations
- */
-struct TALER_DenominationCSPublicRPairP
-{
- struct GNUNET_CRYPTO_CsRPublic r_pub[2];
-};
-
-
-/**
- * Secret r for Cs denominations
- */
-struct TALER_DenominationCSPrivateRPairP
-{
- struct GNUNET_CRYPTO_CsRSecret r[2];
};
@@ -1417,51 +1336,58 @@ struct TALER_TrackTransferDetails
struct TALER_CoinSpendPublicKeyP coin_pub;
/**
- * Value of the deposit (including fee).
+ * Value of the deposit (including fee), after refunds.
*/
struct TALER_Amount coin_value;
/**
- * Fee charged by the exchange for the deposit.
+ * Fee charged by the exchange for the deposit,
+ * possibly reduced (or waived) due to refunds.
*/
struct TALER_Amount coin_fee;
+ /**
+ * Total amount of refunds applied to this coin.
+ */
+ struct TALER_Amount refund_total;
+
};
/**
- * @brief Type of algorithm specific Values for withdrawal
+ * @brief Inputs needed from the exchange for blind signing.
*/
struct TALER_ExchangeWithdrawValues
{
/**
- * Type of the signature.
- */
- enum TALER_DenominationCipher cipher;
-
- /**
- * Details, depending on @e cipher.
+ * Input values.
*/
- union
- {
- /**
- * If we use #TALER_DENOMINATION_CS in @a cipher.
- */
- struct TALER_DenominationCSPublicRPairP cs_values;
+ struct GNUNET_CRYPTO_BlindingInputValues *blinding_inputs;
+};
- } details;
-};
+/**
+ * Return the alg value singleton for creation of
+ * blinding secrets for RSA.
+ *
+ * @return singleton to use for RSA blinding
+ */
+const struct TALER_ExchangeWithdrawValues *
+TALER_denom_ewv_rsa_singleton (void);
/**
- * Free internals of @a denom_pub, but not @a denom_pub itself.
+ * Make a (deep) copy of the given @a bi_src to
+ * @a bi_dst.
*
- * @param[in] denom_pub key to free
+ * @param[out] bi_dst target to copy to
+ * @param bi_src blinding input values to copy
*/
void
-TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub);
+TALER_denom_ewv_copy (
+ struct TALER_ExchangeWithdrawValues *bi_dst,
+ const struct TALER_ExchangeWithdrawValues *bi_src);
/**
@@ -1486,7 +1412,7 @@ TALER_planchet_setup_coin_priv (
void
TALER_cs_withdraw_nonce_derive (
const struct TALER_PlanchetMasterSecretP *ps,
- struct TALER_CsNonce *nonce);
+ struct GNUNET_CRYPTO_CsSessionNonce *nonce);
/**
@@ -1501,13 +1427,13 @@ void
TALER_cs_refresh_nonce_derive (
const struct TALER_RefreshMasterSecretP *rms,
uint32_t idx,
- struct TALER_CsNonce *nonce);
+ struct GNUNET_CRYPTO_CsSessionNonce *nonce);
/**
* Initialize denomination public-private key pair.
*
- * For #TALER_DENOMINATION_RSA, an additional "unsigned int"
+ * For #GNUNET_CRYPTO_BSA_RSA, an additional "unsigned int"
* argument with the number of bits for 'n' (e.g. 2048) must
* be passed.
*
@@ -1520,11 +1446,29 @@ TALER_cs_refresh_nonce_derive (
enum GNUNET_GenericReturnValue
TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
struct TALER_DenominationPublicKey *denom_pub,
- enum TALER_DenominationCipher cipher,
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
...);
/**
+ * Free internals of @a denom_pub, but not @a denom_pub itself.
+ *
+ * @param[in] denom_pub key to free
+ */
+void
+TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub);
+
+
+/**
+ * Free internals of @a ewv, but not @a ewv itself.
+ *
+ * @param[in] ewv input values to free
+ */
+void
+TALER_denom_ewv_free (struct TALER_ExchangeWithdrawValues *ewv);
+
+
+/**
* Free internals of @a denom_priv, but not @a denom_priv itself.
*
* @param[in] denom_priv key to free
@@ -1551,6 +1495,8 @@ TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig);
*
* @param dk denomination public key to blind for
* @param coin_bks blinding secret to use
+ * @param nonce nonce used to derive session values,
+ * could be NULL for ciphers that do not use it
* @param age_commitment_hash hash of the age commitment to be used for the coin. NULL if no commitment is made.
* @param coin_pub public key of the coin to blind
* @param alg_values algorithm specific values to blind the planchet
@@ -1560,7 +1506,8 @@ TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig);
*/
enum GNUNET_GenericReturnValue
TALER_denom_blind (const struct TALER_DenominationPublicKey *dk,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_AgeCommitmentHash *age_commitment_hash,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_ExchangeWithdrawValues *alg_values,
@@ -1599,7 +1546,7 @@ enum GNUNET_GenericReturnValue
TALER_denom_sig_unblind (
struct TALER_DenominationSignature *denom_sig,
const struct TALER_BlindedDenominationSignature *bdenom_sig,
- const union TALER_DenominationBlindingKeyP *bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
const struct TALER_CoinPubHashP *c_hash,
const struct TALER_ExchangeWithdrawValues *alg_values,
const struct TALER_DenominationPublicKey *denom_pub);
@@ -1634,8 +1581,8 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub,
* @param denom_src public key to copy
*/
void
-TALER_denom_pub_deep_copy (struct TALER_DenominationPublicKey *denom_dst,
- const struct TALER_DenominationPublicKey *denom_src);
+TALER_denom_pub_copy (struct TALER_DenominationPublicKey *denom_dst,
+ const struct TALER_DenominationPublicKey *denom_src);
/**
@@ -1646,8 +1593,8 @@ TALER_denom_pub_deep_copy (struct TALER_DenominationPublicKey *denom_dst,
* @param denom_src public key to copy
*/
void
-TALER_denom_sig_deep_copy (struct TALER_DenominationSignature *denom_dst,
- const struct TALER_DenominationSignature *denom_src);
+TALER_denom_sig_copy (struct TALER_DenominationSignature *denom_dst,
+ const struct TALER_DenominationSignature *denom_src);
/**
@@ -1658,7 +1605,7 @@ TALER_denom_sig_deep_copy (struct TALER_DenominationSignature *denom_dst,
* @param denom_src public key to copy
*/
void
-TALER_blinded_denom_sig_deep_copy (
+TALER_blinded_denom_sig_copy (
struct TALER_BlindedDenominationSignature *denom_dst,
const struct TALER_BlindedDenominationSignature *denom_src);
@@ -1714,19 +1661,6 @@ TALER_blinded_planchet_cmp (
/**
- * Obtain denomination public key from a denomination private key.
- *
- * @param denom_priv private key to convert
- * @param age_mask age mask to be applied
- * @param[out] denom_pub where to return the public key
- */
-void
-TALER_denom_priv_to_pub (const struct TALER_DenominationPrivateKey *denom_priv,
- const struct TALER_AgeMask age_mask,
- struct TALER_DenominationPublicKey *denom_pub);
-
-
-/**
* Verify signature made with a denomination public key
* over a coin.
*
@@ -1742,6 +1676,51 @@ TALER_denom_pub_verify (const struct TALER_DenominationPublicKey *denom_pub,
/**
+ * Encrypts KYC attributes for storage in the database.
+ *
+ * @param key encryption key to use
+ * @param attr set of attributes to encrypt
+ * @param[out] enc_attr encrypted attribute data
+ * @param[out] enc_attr_size number of bytes in @a enc_attr
+ */
+void
+TALER_CRYPTO_kyc_attributes_encrypt (
+ const struct TALER_AttributeEncryptionKeyP *key,
+ const json_t *attr,
+ void **enc_attr,
+ size_t *enc_attr_size);
+
+
+/**
+ * Encrypts KYC attributes for storage in the database.
+ *
+ * @param key encryption key to use
+ * @param enc_attr encrypted attribute data
+ * @param enc_attr_size number of bytes in @a enc_attr
+ * @return set of decrypted attributes, NULL on failure
+ */
+json_t *
+TALER_CRYPTO_kyc_attributes_decrypt (
+ const struct TALER_AttributeEncryptionKeyP *key,
+ const void *enc_attr,
+ size_t enc_attr_size);
+
+
+/**
+ * Takes a set of KYC attributes and extracts key
+ * data that we use to detect similar / duplicate
+ * entries in the database.
+ *
+ * @param attr set of KYC attributes
+ * @param[out] kyc_prox set to the proximity hash
+ */
+void
+TALER_CRYPTO_attributes_to_kyc_prox (
+ const json_t *attr,
+ struct GNUNET_ShortHashCode *kyc_prox);
+
+
+/**
* Check if a coin is valid; that is, whether the denomination key exists,
* is not expired, and the signature is correct.
*
@@ -1760,11 +1739,10 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info,
* Compute the hash of a blinded coin.
*
* @param blinded_planchet blinded planchet
- * @param denom_hash hash of the denomination publick key
+ * @param denom_hash hash of the denomination public key
* @param[out] bch where to write the hash
- * @return #GNUNET_OK when successful, #GNUNET_SYSERR if an internal error occurred
*/
-enum GNUNET_GenericReturnValue
+void
TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
const struct TALER_DenominationHashP *denom_hash,
struct TALER_BlindedCoinHashP *bch);
@@ -1793,6 +1771,7 @@ void
TALER_payto_hash (const char *payto,
struct TALER_PaytoHashP *h_payto);
+
/**
* Details about a planchet that the customer wants to obtain
* a withdrawal authorization. This is the information that
@@ -1995,7 +1974,7 @@ void
TALER_planchet_blinding_secret_create (
const struct TALER_PlanchetMasterSecretP *ps,
const struct TALER_ExchangeWithdrawValues *alg_values,
- union TALER_DenominationBlindingKeyP *bks);
+ union GNUNET_CRYPTO_BlindingSecretP *bks);
/**
@@ -2004,6 +1983,7 @@ TALER_planchet_blinding_secret_create (
* @param dk denomination key for the coin to be created
* @param alg_values algorithm specific values
* @param bks blinding secrets
+ * @param nonce session nonce used to get @a alg_values
* @param coin_priv coin private key
* @param ach hash of age commitment to bind to this coin, maybe NULL
* @param[out] c_hash set to the hash of the public key of the coin (needed later)
@@ -2013,13 +1993,15 @@ TALER_planchet_blinding_secret_create (
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
-TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
- const struct TALER_ExchangeWithdrawValues *alg_values,
- const union TALER_DenominationBlindingKeyP *bks,
- const struct TALER_CoinSpendPrivateKeyP *coin_priv,
- const struct TALER_AgeCommitmentHash *ach,
- struct TALER_CoinPubHashP *c_hash,
- struct TALER_PlanchetDetail *pd);
+TALER_planchet_prepare (
+ const struct TALER_DenominationPublicKey *dk,
+ const struct TALER_ExchangeWithdrawValues *alg_values,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ const struct TALER_AgeCommitmentHash *ach,
+ struct TALER_CoinPubHashP *c_hash,
+ struct TALER_PlanchetDetail *pd);
/**
@@ -2059,7 +2041,7 @@ enum GNUNET_GenericReturnValue
TALER_planchet_to_coin (
const struct TALER_DenominationPublicKey *dk,
const struct TALER_BlindedDenominationSignature *blind_sig,
- const union TALER_DenominationBlindingKeyP *bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
const struct TALER_AgeCommitmentHash *ach,
const struct TALER_CoinPubHashP *c_hash,
@@ -2260,6 +2242,89 @@ TALER_CRYPTO_contract_decrypt_for_deposit (
size_t econtract_size);
+/* **************** AML officer signatures **************** */
+
+/**
+ * Sign AML query. Simple authentication, doesn't actually
+ * sign anything.
+ *
+ * @param officer_priv private key of AML officer
+ * @param[out] officer_sig where to write the signature
+ */
+void
+TALER_officer_aml_query_sign (
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ struct TALER_AmlOfficerSignatureP *officer_sig);
+
+
+/**
+ * Verify AML query authorization.
+ *
+ * @param officer_pub public key of AML officer
+ * @param officer_sig signature to verify
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_officer_aml_query_verify (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const struct TALER_AmlOfficerSignatureP *officer_sig);
+
+
+/**
+ * Sign AML decision.
+ *
+ * @param justification human-readable justification
+ * @param decision_time when was the decision made
+ * @param new_threshold at what monthly amount threshold
+ * should a revision be triggered
+ * @param h_payto payto URI hash of the account the
+ * decision is about
+ * @param new_state updated AML state
+ * @param kyc_requirements additional KYC requirements to
+ * impose, can be NULL
+ * @param officer_priv private key of AML officer
+ * @param[out] officer_sig where to write the signature
+ */
+void
+TALER_officer_aml_decision_sign (
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ struct TALER_AmlOfficerSignatureP *officer_sig);
+
+
+/**
+ * Verify AML decision.
+ *
+ * @param justification human-readable justification
+ * @param decision_time when was the decision made
+ * @param new_threshold at what monthly amount threshold
+ * should a revision be triggered
+ * @param h_payto payto URI hash of the account the
+ * decision is about
+ * @param new_state updated AML state
+ * @param kyc_requirements additional KYC requirements to
+ * impose, can be NULL
+ * @param officer_pub public key of AML officer
+ * @param officer_sig signature to verify
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_officer_aml_decision_verify (
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const struct TALER_AmlOfficerSignatureP *officer_sig);
+
+
/* **************** Helper-based RSA operations **************** */
/**
@@ -2280,7 +2345,7 @@ struct TALER_CRYPTO_RsaDenominationHelper;
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_rsa hash of the RSA @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bs_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -2292,7 +2357,7 @@ typedef void
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_RsaPubHashP *h_rsa,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig);
@@ -2301,6 +2366,7 @@ typedef void
* Initiate connection to an denomination key helper.
*
* @param cfg configuration to use
+ * @param section configuration section prefix to use, usually 'taler' or 'donau'
* @param dkc function to call with key information
* @param dkc_cls closure for @a dkc
* @return NULL on error (such as bad @a cfg).
@@ -2308,6 +2374,7 @@ typedef void
struct TALER_CRYPTO_RsaDenominationHelper *
TALER_CRYPTO_helper_rsa_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc,
void *dkc_cls);
@@ -2379,6 +2446,11 @@ TALER_CRYPTO_helper_rsa_sign (
* that it created the signature. Thus, signals may result in a small
* differences in the signature counters. Retrying in this case may work.
*
+ * Note that in case of errors, the @a bss array may still have been partially
+ * filled with signatures, which in this case must be freed by the caller
+ * (this is in contrast to the #TALER_CRYPTO_helper_rsa_sign() API which never
+ * returns any signatures if there was an error).
+ *
* @param dh helper process connection
* @param rsrs array with details about the requested signatures
* @param rsrs_length length of the @a rsrs array
@@ -2388,9 +2460,9 @@ TALER_CRYPTO_helper_rsa_sign (
enum TALER_ErrorCode
TALER_CRYPTO_helper_rsa_batch_sign (
struct TALER_CRYPTO_RsaDenominationHelper *dh,
- const struct TALER_CRYPTO_RsaSignRequest *rsrs,
unsigned int rsrs_length,
- struct TALER_BlindedDenominationSignature *bss);
+ const struct TALER_CRYPTO_RsaSignRequest rsrs[static rsrs_length],
+ struct TALER_BlindedDenominationSignature bss[static rsrs_length]);
/**
@@ -2423,6 +2495,7 @@ void
TALER_CRYPTO_helper_rsa_disconnect (
struct TALER_CRYPTO_RsaDenominationHelper *dh);
+
/* **************** Helper-based CS operations **************** */
/**
@@ -2443,7 +2516,7 @@ struct TALER_CRYPTO_CsDenominationHelper;
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_cs hash of the CS @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bsign_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -2455,7 +2528,7 @@ typedef void
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_CsPubHashP *h_cs,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig);
@@ -2464,6 +2537,7 @@ typedef void
* Initiate connection to an denomination key helper.
*
* @param cfg configuration to use
+ * @param section configuration section prefix to use, usually 'taler' or 'donau'
* @param dkc function to call with key information
* @param dkc_cls closure for @a dkc
* @return NULL on error (such as bad @a cfg).
@@ -2471,6 +2545,7 @@ typedef void
struct TALER_CRYPTO_CsDenominationHelper *
TALER_CRYPTO_helper_cs_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_CsDenominationKeyStatusCallback dkc,
void *dkc_cls);
@@ -2489,8 +2564,25 @@ TALER_CRYPTO_helper_cs_poll (struct TALER_CRYPTO_CsDenominationHelper *dh);
/**
- * Request helper @a dh to sign @a msg using the public key corresponding to
- * @a h_denom_pub.
+ * Information about what we should sign over.
+ */
+struct TALER_CRYPTO_CsSignRequest
+{
+ /**
+ * Hash of the CS public key to use to sign.
+ */
+ const struct TALER_CsPubHashP *h_cs;
+
+ /**
+ * Blinded planchet containing c and the nonce.
+ */
+ const struct GNUNET_CRYPTO_CsBlindedMessage *blinded_planchet;
+
+};
+
+
+/**
+ * Request helper @a dh to sign @a req.
*
* This operation will block until the signature has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is
@@ -2499,22 +2591,21 @@ TALER_CRYPTO_helper_cs_poll (struct TALER_CRYPTO_CsDenominationHelper *dh);
* differences in the signature counters. Retrying in this case may work.
*
* @param dh helper process connection
- * @param h_cs hash of the CS public key to use to sign
- * @param blinded_planchet blinded planchet containing c and nonce
+ * @param req information about the key to sign with and the value to sign
+ * @param for_melt true if for melt operation
* @param[out] bs set to the blind signature
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_sign_melt (
+TALER_CRYPTO_helper_cs_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_BlindedCsPlanchet *blinded_planchet,
+ const struct TALER_CRYPTO_CsSignRequest *req,
+ bool for_melt,
struct TALER_BlindedDenominationSignature *bs);
/**
- * Request helper @a dh to sign @a msg using the public key corresponding to
- * @a h_denom_pub.
+ * Request helper @a dh to sign batch of @a reqs requests.
*
* This operation will block until the signature has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is
@@ -2523,17 +2614,19 @@ TALER_CRYPTO_helper_cs_sign_melt (
* differences in the signature counters. Retrying in this case may work.
*
* @param dh helper process connection
- * @param h_cs hash of the CS public key to use to sign
- * @param blinded_planchet blinded planchet containing c and nonce
- * @param[out] bs set to the blind signature
+ * @param reqs information about the keys to sign with and the values to sign
+ * @param reqs_length length of the @a reqs array
+ * @param for_melt true if this is for a melt operation
+ * @param[out] bss array set to the blind signatures, must be of length @a reqs_length!
* @return #TALER_EC_NONE on success
*/
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_sign_withdraw (
+TALER_CRYPTO_helper_cs_batch_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_BlindedCsPlanchet *blinded_planchet,
- struct TALER_BlindedDenominationSignature *bs);
+ unsigned int reqs_length,
+ const struct TALER_CRYPTO_CsSignRequest reqs[static reqs_length],
+ bool for_melt,
+ struct TALER_BlindedDenominationSignature bss[static reqs_length]);
/**
@@ -2558,8 +2651,25 @@ TALER_CRYPTO_helper_cs_revoke (
/**
- * Ask the helper to derive R using the @a nonce and denomination key
- * associated with @a h_cs.
+ * Information about what we should derive for.
+ */
+struct TALER_CRYPTO_CsDeriveRequest
+{
+ /**
+ * Hash of the CS public key to use to sign.
+ */
+ const struct TALER_CsPubHashP *h_cs;
+
+ /**
+ * Nonce to use for the /csr request.
+ */
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce;
+};
+
+
+/**
+ * Ask the helper to derive R using the information
+ * from @a cdr.
*
* This operation will block until the R has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is
@@ -2568,22 +2678,21 @@ TALER_CRYPTO_helper_cs_revoke (
* differences in the signature counters. Retrying in this case may work.
*
* @param dh helper to process connection
- * @param h_cs hash of the CS public key to revoke
- * @param nonce witdhraw nonce
+ * @param cdr derivation input data
+ * @param for_melt true if this is for a melt operation
* @param[out] crp set to the pair of R values
* @return set to the error code (or #TALER_EC_NONE on success)
*/
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_r_derive_withdraw (
+TALER_CRYPTO_helper_cs_r_derive (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *crp);
+ const struct TALER_CRYPTO_CsDeriveRequest *cdr,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP *crp);
/**
- * Ask the helper to derive R using the @a nonce and denomination key
- * associated with @a h_cs.
+ * Ask the helper to derive R using the information from @a cdrs.
*
* This operation will block until the R has been obtained. Should
* this process receive a signal (that is not ignored) while the operation is
@@ -2592,17 +2701,19 @@ TALER_CRYPTO_helper_cs_r_derive_withdraw (
* differences in the signature counters. Retrying in this case may work.
*
* @param dh helper to process connection
- * @param h_cs hash of the CS public key to revoke
- * @param nonce witdhraw nonce
- * @param[out] crp set to the pair of R values
+ * @param cdrs_length length of the @a cdrs array
+ * @param cdrs array with derivation input data
+ * @param for_melt true if this is for a melt operation
+ * @param[out] crps array set to the pair of R values, must be of length @a cdrs_length
* @return set to the error code (or #TALER_EC_NONE on success)
*/
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_r_derive_melt (
+TALER_CRYPTO_helper_cs_r_batch_derive (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *crp);
+ unsigned int cdrs_length,
+ const struct TALER_CRYPTO_CsDeriveRequest cdrs[static cdrs_length],
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP crps[static cdrs_length]);
/**
@@ -2648,6 +2759,7 @@ typedef void
* Initiate connection to an online signing key helper.
*
* @param cfg configuration to use
+ * @param section configuration section prefix to use, usually 'taler' or 'donau'
* @param ekc function to call with key information
* @param ekc_cls closure for @a ekc
* @return NULL on error (such as bad @a cfg).
@@ -2655,6 +2767,7 @@ typedef void
struct TALER_CRYPTO_ExchangeSignHelper *
TALER_CRYPTO_helper_esign_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_ExchangeKeyStatusCallback ekc,
void *ekc_cls);
@@ -2771,7 +2884,7 @@ TALER_CRYPTO_helper_esign_disconnect (
void
TALER_wallet_purse_create_sign (
struct GNUNET_TIME_Timestamp purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_PurseMergePublicKeyP *merge_pub,
uint32_t min_age,
const struct TALER_Amount *amount,
@@ -2794,7 +2907,7 @@ TALER_wallet_purse_create_sign (
enum GNUNET_GenericReturnValue
TALER_wallet_purse_create_verify (
struct GNUNET_TIME_Timestamp purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_PurseMergePublicKeyP *merge_pub,
uint32_t min_age,
const struct TALER_Amount *amount,
@@ -2803,6 +2916,31 @@ TALER_wallet_purse_create_verify (
/**
+ * Sign a request to delete a purse.
+ *
+ * @param purse_priv key identifying the purse
+ * @param[out] purse_sig resulting signature
+ */
+void
+TALER_wallet_purse_delete_sign (
+ const struct TALER_PurseContractPrivateKeyP *purse_priv,
+ struct TALER_PurseContractSignatureP *purse_sig);
+
+
+/**
+ * Verify a purse deletion request.
+ *
+ * @param purse_pub purse’s public key
+ * @param purse_sig the signature made with purpose #TALER_SIGNATURE_WALLET_PURSE_DELETE
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_purse_delete_verify (
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig);
+
+
+/**
* Sign a request to upload an encrypted contract.
*
* @param econtract encrypted contract
@@ -2929,7 +3067,7 @@ TALER_wallet_purse_deposit_verify (
/**
* Sign a request by a purse to merge it into an account.
*
- * @param reserve_url identifies the location of the reserve
+ * @param reserve_uri identifies the location of the reserve
* @param merge_timestamp time when the merge happened
* @param purse_pub key identifying the purse
* @param merge_priv key identifying the merge capability
@@ -2937,7 +3075,7 @@ TALER_wallet_purse_deposit_verify (
*/
void
TALER_wallet_purse_merge_sign (
- const char *reserve_url,
+ const char *reserve_uri,
struct GNUNET_TIME_Timestamp merge_timestamp,
const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
@@ -2947,7 +3085,7 @@ TALER_wallet_purse_merge_sign (
/**
* Verify a purse merge request.
*
- * @param reserve_url identifies the location of the reserve
+ * @param reserve_uri identifies the location of the reserve
* @param merge_timestamp time when the merge happened
* @param purse_pub public key of the purse to merge
* @param merge_pub public key of the merge capability
@@ -2956,7 +3094,7 @@ TALER_wallet_purse_merge_sign (
*/
enum GNUNET_GenericReturnValue
TALER_wallet_purse_merge_verify (
- const char *reserve_url,
+ const char *reserve_uri,
struct GNUNET_TIME_Timestamp merge_timestamp,
const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_PurseMergePublicKeyP *merge_pub,
@@ -3059,13 +3197,96 @@ TALER_wallet_account_merge_verify (
/**
- * Sign a request to delete/close an account.
+ * Sign a request to keep a reserve open.
+ *
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_priv key identifying the reserve
+ * @param[out] reserve_sig resulting signature
+ */
+void
+TALER_wallet_reserve_open_sign (
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
+ * Verify a request to keep a reserve open.
+ *
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub key identifying the reserve
+ * @param reserve_sig resulting signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_open_verify (
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
+ * Sign to deposit coin to pay for keeping a reserve open.
+ *
+ * @param coin_contribution how much the coin should contribute
+ * @param reserve_sig signature over the reserve open operation
+ * @param coin_priv private key of the coin
+ * @param[out] coin_sig signature by the coin
+ */
+void
+TALER_wallet_reserve_open_deposit_sign (
+ const struct TALER_Amount *coin_contribution,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ struct TALER_CoinSpendSignatureP *coin_sig);
+
+
+/**
+ * Verify signature that deposits coin to pay for keeping a reserve open.
+ *
+ * @param coin_contribution how much the coin should contribute
+ * @param reserve_sig signature over the reserve open operation
+ * @param coin_pub public key of the coin
+ * @param coin_sig signature by the coin
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_open_deposit_verify (
+ const struct TALER_Amount *coin_contribution,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig);
+
+
+/**
+ * Sign a request to close a reserve.
*
+ * @param request_timestamp when was the request created
+ * @param h_payto where to send the funds (NULL allowed to send
+ * to origin of the reserve)
* @param reserve_priv key identifying the reserve
* @param[out] reserve_sig resulting signature
*/
void
-TALER_wallet_account_close_sign (
+TALER_wallet_reserve_close_sign (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_PaytoHashP *h_payto,
const struct TALER_ReservePrivateKeyP *reserve_priv,
struct TALER_ReserveSignatureP *reserve_sig);
@@ -3073,12 +3294,17 @@ TALER_wallet_account_close_sign (
/**
* Verify wallet request to close an account.
*
+ * @param request_timestamp when was the request created
+ * @param h_payto where to send the funds (NULL/all zeros
+ * allowed to send to origin of the reserve)
* @param reserve_pub account’s public key
* @param reserve_sig the signature made with purpose #TALER_SIGNATURE_WALLET_RESERVE_CLOSE
* @return #GNUNET_OK if the signature is valid
*/
enum GNUNET_GenericReturnValue
-TALER_wallet_account_close_verify (
+TALER_wallet_reserve_close_verify (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_PaytoHashP *h_payto,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_ReserveSignatureP *reserve_sig);
@@ -3087,11 +3313,13 @@ TALER_wallet_account_close_verify (
* Sign a request by a wallet to perform a KYC check.
*
* @param reserve_priv key identifying the wallet/account
+ * @param balance_threshold the balance threshold the wallet is about to cross
* @param[out] reserve_sig resulting signature
*/
void
TALER_wallet_account_setup_sign (
const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *balance_threshold,
struct TALER_ReserveSignatureP *reserve_sig);
@@ -3099,12 +3327,49 @@ TALER_wallet_account_setup_sign (
* Verify account setup request.
*
* @param reserve_pub reserve the setup request was for
+ * @param balance_threshold the balance threshold the wallet is about to cross
* @param reserve_sig resulting signature
* @return #GNUNET_OK if the signature is valid
*/
enum GNUNET_GenericReturnValue
TALER_wallet_account_setup_verify (
const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *balance_threshold,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
+ * Sign request to the exchange to confirm certain
+ * @a details about the owner of a reserve.
+ *
+ * @param request_timestamp when was the request created
+ * @param details which attributes are requested
+ * @param reserve_priv private key of the reserve
+ * @param[out] reserve_sig where to store the signature
+ */
+void
+TALER_wallet_reserve_attest_request_sign (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const json_t *details,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig);
+
+
+/**
+ * Verify request to the exchange to confirm certain
+ * @a details about the owner of a reserve.
+ *
+ * @param request_timestamp when was the request created
+ * @param details which attributes are requested
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig where to store the signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_attest_request_verify (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const json_t *details,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_ReserveSignatureP *reserve_sig);
@@ -3115,8 +3380,9 @@ TALER_wallet_account_setup_verify (
* @param deposit_fee the deposit fee we expect to pay
* @param h_wire hash of the merchant’s account details
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange)
+ * @param wallet_data_hash hash over wallet inputs into the contract (maybe NULL)
* @param h_age_commitment hash over the age commitment, if applicable to the denomination (maybe NULL)
- * @param h_extensions hash over the extensions
+ * @param h_policy hash over the policy extension
* @param h_denom_pub hash of the coin denomination's public key
* @param coin_priv coin’s private key
* @param wallet_timestamp timestamp when the contract was finalized, must not be too far in the future
@@ -3130,8 +3396,9 @@ TALER_wallet_deposit_sign (
const struct TALER_Amount *deposit_fee,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct GNUNET_HashCode *wallet_data_hash,
const struct TALER_AgeCommitmentHash *h_age_commitment,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_DenominationHashP *h_denom_pub,
struct GNUNET_TIME_Timestamp wallet_timestamp,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -3147,8 +3414,9 @@ TALER_wallet_deposit_sign (
* @param deposit_fee the deposit fee we expect to pay
* @param h_wire hash of the merchant’s account details
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange)
+ * @param wallet_data_hash hash over wallet inputs into the contract (maybe NULL)
* @param h_age_commitment hash over the age commitment (maybe all zeroes, if not applicable to the denomination)
- * @param h_extensions hash over the extensions
+ * @param h_policy hash over the policy extension
* @param h_denom_pub hash of the coin denomination's public key
* @param wallet_timestamp timestamp when the contract was finalized, must not be too far in the future
* @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests)
@@ -3163,8 +3431,9 @@ TALER_wallet_deposit_verify (
const struct TALER_Amount *deposit_fee,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct GNUNET_HashCode *wallet_data_hash,
const struct TALER_AgeCommitmentHash *h_age_commitment,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_DenominationHashP *h_denom_pub,
struct GNUNET_TIME_Timestamp wallet_timestamp,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -3293,6 +3562,45 @@ TALER_wallet_withdraw_verify (
/**
+ * Sign age-withdraw request.
+ *
+ * @param h_commitment hash over all n*kappa blinded coins in the commitment for the age-withdraw
+ * @param amount_with_fee amount to debit the reserve for
+ * @param mask the mask that defines the age groups
+ * @param max_age maximum age from which the age group is derived, that the withdrawn coins must be restricted to.
+ * @param reserve_priv private key to sign with
+ * @param[out] reserve_sig resulting signature
+ */
+void
+TALER_wallet_age_withdraw_sign (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_AgeMask *mask,
+ uint8_t max_age,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig);
+
+/**
+ * Verify an age-withdraw request.
+ *
+ * @param h_commitment hash all n*kappa blinded coins in the commitment for the age-withdraw
+ * @param amount_with_fee amount to debit the reserve for
+ * @param mask the mask that defines the age groups
+ * @param max_age maximum age from which the age group is derived, that the withdrawn coins must be restricted to.
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig resulting signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_wallet_age_withdraw_verify (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_AgeMask *mask,
+ uint8_t max_age,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
+
+/**
* Verify exchange melt confirmation.
*
* @param rc refresh session this is about
@@ -3321,7 +3629,7 @@ TALER_exchange_melt_confirmation_verify (
enum GNUNET_GenericReturnValue
TALER_wallet_recoup_verify (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig);
@@ -3337,7 +3645,7 @@ TALER_wallet_recoup_verify (
void
TALER_wallet_recoup_sign (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_CoinSpendSignatureP *coin_sig);
@@ -3354,7 +3662,7 @@ TALER_wallet_recoup_sign (
enum GNUNET_GenericReturnValue
TALER_wallet_recoup_refresh_verify (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig);
@@ -3370,7 +3678,7 @@ TALER_wallet_recoup_refresh_verify (
void
TALER_wallet_recoup_refresh_sign (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_CoinSpendSignatureP *coin_sig);
@@ -3378,63 +3686,59 @@ TALER_wallet_recoup_refresh_sign (
/**
* Verify reserve history request signature.
*
- * @param ts timestamp used
- * @param history_fee how much did the wallet say it would pay
+ * @param start_off start of the requested range
* @param reserve_pub reserve the history request was for
* @param reserve_sig resulting signature
* @return #GNUNET_OK if the signature is valid
*/
enum GNUNET_GenericReturnValue
TALER_wallet_reserve_history_verify (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_Amount *history_fee,
+ uint64_t start_off,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_ReserveSignatureP *reserve_sig);
/**
- * Create reserve history request signature.
+ * Create reserve status request signature.
*
- * @param ts timestamp used
- * @param history_fee how much do we expect to pay
+ * @param start_off start of the requested range
* @param reserve_priv private key of the reserve the history request is for
* @param[out] reserve_sig resulting signature
*/
void
TALER_wallet_reserve_history_sign (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_Amount *history_fee,
+ uint64_t start_off,
const struct TALER_ReservePrivateKeyP *reserve_priv,
struct TALER_ReserveSignatureP *reserve_sig);
/**
- * Verify reserve status request signature.
+ * Verify coin history request signature.
*
- * @param ts timestamp used
- * @param reserve_pub reserve the status request was for
- * @param reserve_sig resulting signature
+ * @param start_off start of the requested range
+ * @param coin_pub coin the history request was for
+ * @param coin_sig resulting signature
* @return #GNUNET_OK if the signature is valid
*/
enum GNUNET_GenericReturnValue
-TALER_wallet_reserve_status_verify (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig);
+TALER_wallet_coin_history_verify (
+ uint64_t start_off,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig);
/**
- * Create reserve status request signature.
+ * Create coin status request signature.
*
- * @param ts timestamp used
- * @param reserve_priv private key of the reserve the status request is for
- * @param[out] reserve_sig resulting signature
+ * @param start_off start of the requested range
+ * @param coin_priv private key of the coin the history request is for
+ * @param[out] coin_sig resulting signature
*/
void
-TALER_wallet_reserve_status_sign (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- struct TALER_ReserveSignatureP *reserve_sig);
+TALER_wallet_coin_history_sign (
+ uint64_t start_off,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ struct TALER_CoinSpendSignatureP *coin_sig);
/* ********************* merchant signing ************************** */
@@ -3569,12 +3873,13 @@ typedef enum TALER_ErrorCode
* @param scb function to call to create the signature
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange)
* @param h_wire hash of the merchant’s account details
- * @param h_extensions hash over the extensions, can be NULL
+ * @param h_policy hash over the policy extension, can be NULL
* @param exchange_timestamp timestamp when the contract was finalized, must not be too far off
* @param wire_deadline date until which the exchange should wire the funds
* @param refund_deadline date until which the merchant can issue a refund to the customer via the exchange (can be zero if refunds are not allowed); must not be after the @a wire_deadline
- * @param amount_without_fee the amount to be deposited after fees
- * @param coin_pub public key of the deposited coin
+ * @param total_without_fee the total amount to be deposited after fees over all coins
+ * @param num_coins length of @a coin_sigs array
+ * @param coin_sigs signatures of the deposited coins
* @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests)
* @param[out] pub where to write the public key
* @param[out] sig where to write the signature
@@ -3585,12 +3890,13 @@ TALER_exchange_online_deposit_confirmation_sign (
TALER_ExchangeSignCallback scb,
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendSignatureP *coin_sigs[static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
struct TALER_ExchangePublicKeyP *pub,
struct TALER_ExchangeSignatureP *sig);
@@ -3601,12 +3907,13 @@ TALER_exchange_online_deposit_confirmation_sign (
*
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the exchange)
* @param h_wire hash of the merchant’s account details
- * @param h_extensions hash over the extensions, can be NULL
+ * @param h_policy hash over the policy extension, can be NULL
* @param exchange_timestamp timestamp when the contract was finalized, must not be too far off
* @param wire_deadline date until which the exchange should wire the funds
* @param refund_deadline date until which the merchant can issue a refund to the customer via the exchange (can be zero if refunds are not allowed); must not be after the @a wire_deadline
- * @param amount_without_fee the amount to be deposited after fees
- * @param coin_pub public key of the deposited coin
+ * @param total_without_fee the total amount to be deposited after fees over all coins
+ * @param num_coins length of @a coin_sigs array
+ * @param coin_sigs signatures of the deposited coins
* @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests)
* @param pub where to write the public key
* @param sig where to write the signature
@@ -3616,12 +3923,13 @@ enum GNUNET_GenericReturnValue
TALER_exchange_online_deposit_confirmation_verify (
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendSignatureP *coin_sigs[static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_ExchangePublicKeyP *pub,
const struct TALER_ExchangeSignatureP *sig);
@@ -3712,6 +4020,51 @@ TALER_exchange_online_melt_confirmation_verify (
/**
+ * Create exchange purse refund confirmation signature.
+ *
+ * @param scb function to call to create the signature
+ * @param amount_without_fee refunded amount
+ * @param refund_fee refund fee charged
+ * @param coin_pub coin that was refunded
+ * @param purse_pub public key of the expired purse
+ * @param[out] pub where to write the public key
+ * @param[out] sig where to write the signature
+ * @return #TALER_EC_NONE on success
+ */
+enum TALER_ErrorCode
+TALER_exchange_online_purse_refund_sign (
+ TALER_ExchangeSignCallback scb,
+ const struct TALER_Amount *amount_without_fee,
+ const struct TALER_Amount *refund_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig);
+
+
+/**
+ * Verify signature of exchange affirming purse refund
+ * from purse expiration.
+ *
+ * @param amount_without_fee refunded amount
+ * @param refund_fee refund fee charged
+ * @param coin_pub coin that was refunded
+ * @param purse_pub public key of the expired purse
+ * @param pub public key to verify signature against
+ * @param sig signature to verify
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_purse_refund_verify (
+ const struct TALER_Amount *amount_without_fee,
+ const struct TALER_Amount *refund_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ExchangePublicKeyP *pub,
+ const struct TALER_ExchangeSignatureP *sig);
+
+
+/**
* Create exchange key set signature.
*
* @param scb function to call to create the signature
@@ -3737,8 +4090,8 @@ TALER_exchange_online_key_set_sign (
*
* @param timestamp time when the key set was issued
* @param hc hash over all the keys
- * @param pub where to write the public key
- * @param sig where to write the signature
+ * @param pub public key to verify signature against
+ * @param sig signature to verify
* @return #GNUNET_OK if the signature is valid
*/
enum GNUNET_GenericReturnValue
@@ -3750,10 +4103,12 @@ TALER_exchange_online_key_set_verify (
/**
- * Create account setup success signature.
+ * Create account KYC setup success signature.
*
* @param scb function to call to create the signature
* @param h_payto target of the KYC account
+ * @param kyc JSON data describing which KYC checks
+ * were satisfied
* @param timestamp time when the KYC was confirmed
* @param[out] pub where to write the public key
* @param[out] sig where to write the signature
@@ -3763,15 +4118,18 @@ enum TALER_ErrorCode
TALER_exchange_online_account_setup_success_sign (
TALER_ExchangeSignCallback scb,
const struct TALER_PaytoHashP *h_payto,
+ const json_t *kyc,
struct GNUNET_TIME_Timestamp timestamp,
struct TALER_ExchangePublicKeyP *pub,
struct TALER_ExchangeSignatureP *sig);
/**
- * Verify account setup success signature.
+ * Verify account KYC setup success signature.
*
* @param h_payto target of the KYC account
+ * @param kyc JSON data describing which KYC checks
+ * were satisfied
* @param timestamp time when the KYC was confirmed
* @param pub where to write the public key
* @param sig where to write the signature
@@ -3780,12 +4138,25 @@ TALER_exchange_online_account_setup_success_sign (
enum GNUNET_GenericReturnValue
TALER_exchange_online_account_setup_success_verify (
const struct TALER_PaytoHashP *h_payto,
+ const json_t *kyc,
struct GNUNET_TIME_Timestamp timestamp,
const struct TALER_ExchangePublicKeyP *pub,
const struct TALER_ExchangeSignatureP *sig);
/**
+ * Hash normalized @a j JSON object or array and
+ * store the result in @a hc.
+ *
+ * @param j JSON to hash
+ * @param[out] hc where to write the hash
+ */
+void
+TALER_json_hash (const json_t *j,
+ struct GNUNET_HashCode *hc);
+
+
+/**
* Update the @a hash_context in the computation of the
* h_details for a wire status signature.
*
@@ -4125,6 +4496,52 @@ TALER_exchange_online_reserve_closed_verify (
/**
+ * Create signature by exchange affirming that a reserve
+ * has had certain attributes verified via KYC.
+ *
+ * @param scb function to call to create the signature
+ * @param attest_timestamp our time
+ * @param expiration_time when does the KYC data expire
+ * @param reserve_pub for which reserve are attributes attested
+ * @param attributes JSON object with attributes being attested to
+ * @param[out] pub where to write the public key
+ * @param[out] sig where to write the signature
+ * @return #TALER_EC_NONE on success
+ */
+enum TALER_ErrorCode
+TALER_exchange_online_reserve_attest_details_sign (
+ TALER_ExchangeSignCallback scb,
+ struct GNUNET_TIME_Timestamp attest_timestamp,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *attributes,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig);
+
+
+/**
+ * Verify signature by exchange affirming that a reserve
+ * has had certain attributes verified via KYC.
+ *
+ * @param attest_timestamp our time
+ * @param expiration_time when does the KYC data expire
+ * @param reserve_pub for which reserve are attributes attested
+ * @param attributes JSON object with attributes being attested to
+ * @param pub exchange public key
+ * @param sig exchange signature to verify
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_reserve_attest_details_verify (
+ struct GNUNET_TIME_Timestamp attest_timestamp,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *attributes,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig);
+
+
+/**
* Create signature by exchange affirming that a purse was created.
*
* @param scb function to call to create the signature
@@ -4272,10 +4689,90 @@ TALER_exchange_online_purse_status_verify (
const struct TALER_ExchangeSignatureP *exchange_sig);
+/**
+ * Create age-withdraw confirmation signature.
+ *
+ * @param scb function to call to create the signature
+ * @param h_commitment age-withdraw commitment that identifies the n*kappa blinded coins
+ * @param noreveal_index gamma cut-and-choose value chosen by the exchange
+ * @param[out] pub where to write the exchange public key
+ * @param[out] sig where to write the exchange signature
+ * @return #TALER_EC_NONE on success
+ */
+enum TALER_ErrorCode
+TALER_exchange_online_age_withdraw_confirmation_sign (
+ TALER_ExchangeSignCallback scb,
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ uint32_t noreveal_index,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig);
+
+
+/**
+ * Verify an exchange age-withdraw confirmation
+ *
+ * @param h_commitment Commitment over all n*kappa coin candidates from the original request to age-withdraw
+ * @param noreveal_index The index returned by the exchange
+ * @param exchange_pub The public key used for signing
+ * @param exchange_sig The signature from the exchange
+ */
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_age_withdraw_confirmation_verify (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ uint32_t noreveal_index,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig);
+
+
/* ********************* offline signing ************************** */
/**
+ * Create AML officer status change signature.
+ *
+ * @param officer_pub public key of the AML officer
+ * @param officer_name name of the officer
+ * @param change_date when to affect the status change
+ * @param is_active true to enable the officer
+ * @param read_only true to only allow read-only access
+ * @param master_priv private key to sign with
+ * @param[out] master_sig where to write the signature
+ */
+void
+TALER_exchange_offline_aml_officer_status_sign (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterPrivateKeyP *master_priv,
+ struct TALER_MasterSignatureP *master_sig);
+
+
+/**
+ * Verify AML officer status change signature.
+ *
+ * @param officer_pub public key of the AML officer
+ * @param officer_name name of the officer
+ * @param change_date when to affect the status change
+ * @param is_active true to enable the officer
+ * @param read_only true to only allow read-only access
+ * @param master_pub public key to verify against
+ * @param master_sig the signature the signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_exchange_offline_aml_officer_status_verify (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
+/**
* Create auditor addition signature.
*
* @param auditor_pub public key of the auditor
@@ -4547,6 +5044,55 @@ TALER_exchange_offline_partner_details_verify (
/**
+ * Create offline signature about wiring profits to a
+ * regular non-escrowed account of the exchange.
+ *
+ * @param wtid (random) wire transfer ID to be used
+ * @param date when was the profit drain approved (not exact time of execution)
+ * @param amount how much should be wired
+ * @param account_section configuration section of the
+ * exchange specifying the account to be debited
+ * @param payto_uri target account to be credited
+ * @param master_priv private key to sign with
+ * @param[out] master_sig where to write the signature
+ */
+void
+TALER_exchange_offline_profit_drain_sign (
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_Amount *amount,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterPrivateKeyP *master_priv,
+ struct TALER_MasterSignatureP *master_sig);
+
+
+/**
+ * Verify offline signature about wiring profits to a
+ * regular non-escrowed account of the exchange.
+ *
+ * @param wtid (random) wire transfer ID to be used
+ * @param date when was the profit drain approved (not exact time of execution)
+ * @param amount how much should be wired
+ * @param account_section configuration section of the
+ * exchange specifying the account to be debited
+ * @param payto_uri target account to be credited
+ * @param master_pub public key to verify signature against
+ * @param master_sig the signature
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_exchange_offline_profit_drain_verify (
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_Amount *amount,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_MasterSignatureP *master_sig);
+
+
+/**
* Create security module EdDSA signature.
*
* @param exchange_pub public signing key to validate
@@ -4777,7 +5323,6 @@ TALER_exchange_offline_wire_fee_verify (
* @param end_time when do the fees start to apply
* @param fees the global fees
* @param purse_timeout how long do unmerged purses stay around
- * @param kyc_timeout how long do we keep funds in a reserve without KYC?
* @param history_expiration how long do we keep the history of an account
* @param purse_account_limit how many concurrent purses are free per account holder
* @param master_priv private key to sign with
@@ -4789,7 +5334,6 @@ TALER_exchange_offline_global_fee_sign (
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterPrivateKeyP *master_priv,
@@ -4803,7 +5347,6 @@ TALER_exchange_offline_global_fee_sign (
* @param end_time when do the fees start to apply
* @param fees the global fees
* @param purse_timeout how long do unmerged purses stay around
- * @param kyc_timeout how long do we keep funds in a reserve without KYC?
* @param history_expiration how long do we keep the history of an account
* @param purse_account_limit how many concurrent purses are free per account holder
* @param master_pub public key to verify against
@@ -4816,7 +5359,6 @@ TALER_exchange_offline_global_fee_verify (
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterPublicKeyP *master_pub,
@@ -4827,6 +5369,9 @@ TALER_exchange_offline_global_fee_verify (
* Create wire account addition signature.
*
* @param payto_uri bank account
+ * @param conversion_url URL of the conversion service, or NULL if none
+ * @param debit_restrictions JSON encoding of debit restrictions on the account; see AccountRestriction in the spec
+ * @param credit_restrictions JSON encoding of credit restrictions on the account; see AccountRestriction in the spec
* @param now timestamp to use for the signature (rounded)
* @param master_priv private key to sign with
* @param[out] master_sig where to write the signature
@@ -4834,6 +5379,9 @@ TALER_exchange_offline_global_fee_verify (
void
TALER_exchange_offline_wire_add_sign (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp now,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig);
@@ -4843,6 +5391,9 @@ TALER_exchange_offline_wire_add_sign (
* Verify wire account addition signature.
*
* @param payto_uri bank account
+ * @param conversion_url URL of the conversion service, or NULL if none
+ * @param debit_restrictions JSON encoding of debit restrictions on the account; see AccountRestriction in the spec
+ * @param credit_restrictions JSON encoding of credit restrictions on the account; see AccountRestriction in the spec
* @param sign_time timestamp when signature was created
* @param master_pub public key to verify against
* @param master_sig the signature the signature
@@ -4851,6 +5402,9 @@ TALER_exchange_offline_wire_add_sign (
enum GNUNET_GenericReturnValue
TALER_exchange_offline_wire_add_verify (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp sign_time,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig);
@@ -4893,6 +5447,9 @@ TALER_exchange_offline_wire_del_verify (
* Check the signature in @a master_sig.
*
* @param payto_uri URI that is signed
+ * @param conversion_url URL of the conversion service, or NULL if none
+ * @param debit_restrictions JSON encoding of debit restrictions on the account; see AccountRestriction in the spec
+ * @param credit_restrictions JSON encoding of credit restrictions on the account; see AccountRestriction in the spec
* @param master_pub master public key of the exchange
* @param master_sig signature of the exchange
* @return #GNUNET_OK if signature is valid
@@ -4900,6 +5457,9 @@ TALER_exchange_offline_wire_del_verify (
enum GNUNET_GenericReturnValue
TALER_exchange_wire_signature_check (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig);
@@ -4908,12 +5468,18 @@ TALER_exchange_wire_signature_check (
* Create a signed wire statement for the given account.
*
* @param payto_uri account specification
+ * @param conversion_url URL of the conversion service, or NULL if none
+ * @param debit_restrictions JSON encoding of debit restrictions on the account; see AccountRestriction in the spec
+ * @param credit_restrictions JSON encoding of credit restrictions on the account; see AccountRestriction in the spec
* @param master_priv private key to sign with
* @param[out] master_sig where to write the signature
*/
void
TALER_exchange_wire_signature_make (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig);
@@ -4977,7 +5543,7 @@ void
TALER_merchant_pay_sign (
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantPrivateKeyP *merch_priv,
- struct GNUNET_CRYPTO_EddsaSignature *merch_sig);
+ struct TALER_MerchantSignatureP *merch_sig);
/**
@@ -5012,31 +5578,31 @@ TALER_merchant_contract_sign (
/* **************** /management/extensions offline signing **************** */
/**
- * Create a signature for the hash of the configuration of an extension
+ * Create a signature for the hash of the manifests of extensions
*
- * @param h_config hash of the JSON object representing the configuration
+ * @param h_manifests hash of the JSON object representing the manifests
* @param master_priv private key to sign with
* @param[out] master_sig where to write the signature
*/
void
-TALER_exchange_offline_extension_config_hash_sign (
- const struct TALER_ExtensionConfigHashP *h_config,
+TALER_exchange_offline_extension_manifests_hash_sign (
+ const struct TALER_ExtensionManifestsHashP *h_manifests,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig);
/**
* Verify the signature in @a master_sig of the given hash, taken over the JSON
- * blob representing the configuration of an extension
+ * blob representing the manifests of extensions
*
- * @param h_config hash of the JSON blob of a configuration of an extension
+ * @param h_manifest hash of the JSON blob of manifests of extensions
* @param master_pub master public key of the exchange
* @param master_sig signature of the exchange
* @return #GNUNET_OK if signature is valid
*/
enum GNUNET_GenericReturnValue
-TALER_exchange_offline_extension_config_hash_verify (
- const struct TALER_ExtensionConfigHashP *h_config,
+TALER_exchange_offline_extension_manifests_hash_verify (
+ const struct TALER_ExtensionManifestsHashP *h_manifest,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig
);
@@ -5082,8 +5648,8 @@ struct TALER_AgeCommitment
*
* This struct is used in a call to TALER_age_commitment_attest to create an
* attestation for a minimum age (if that minimum age is less or equal to the
- * commited age for this proof). It consists of a list private keys, one per
- * age group, for which the commited age is either lager or within that
+ * committed age for this proof). It consists of a list private keys, one per
+ * age group, for which the committed age is either lager or within that
* particular group.
*/
struct TALER_AgeProof
@@ -5159,12 +5725,11 @@ TALER_age_commitment_hash (
* @param age The actual age for which an age commitment is generated
* @param seed The seed that goes into the key generation. MUST be chosen uniformly random.
* @param[out] comm_proof The generated age commitment, ->priv and ->pub allocated via GNUNET_malloc() on success
- * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
*/
-enum GNUNET_GenericReturnValue
+void
TALER_age_restriction_commit (
const struct TALER_AgeMask *mask,
- const uint8_t age,
+ uint8_t age,
const struct GNUNET_HashCode *seed,
struct TALER_AgeCommitmentProof *comm_proof);
@@ -5189,7 +5754,7 @@ TALER_age_commitment_derive (
*
* @param comm_proof The age commitment to be used for attestation. For successful attestation, it must contain the private key for the corresponding age group.
* @param age Age (not age group) for which the an attestation should be done
- * @param[out] attest Signature of the age with the appropriate key from the age commitment for the corresponding age group, if applicaple.
+ * @param[out] attest Signature of the age with the appropriate key from the age commitment for the corresponding age group, if applicable.
* @return #GNUNET_OK on success, #GNUNET_NO when no attestation can be made for that age with the given commitment, #GNUNET_SYSERR otherwise
*/
enum GNUNET_GenericReturnValue
@@ -5204,7 +5769,7 @@ TALER_age_commitment_attest (
*
* @param commitment The age commitment that went into the attestation. Only the public keys are needed.
* @param age Age (not age group) for which the an attestation should be done
- * @param attest Signature of the age with the appropriate key from the age commitment for the corresponding age group, if applicaple.
+ * @param attest Signature of the age with the appropriate key from the age commitment for the corresponding age group, if applicable.
* @return #GNUNET_OK when the attestation was successful, #GNUNET_NO no attestation couldn't be verified, #GNUNET_SYSERR otherwise
*/
enum GNUNET_GenericReturnValue
@@ -5217,30 +5782,189 @@ TALER_age_commitment_verify (
/**
* @brief helper function to free memory of a struct TALER_AgeCommitment
*
- * @param p the commitment from which all memory should be freed.
+ * @param ac the commitment from which all memory should be freed.
*/
void
TALER_age_commitment_free (
- struct TALER_AgeCommitment *p);
+ struct TALER_AgeCommitment *ac);
/**
* @brief helper function to free memory of a struct TALER_AgeProof
*
- * @param p the proof of commitment from which all memory should be freed.
+ * @param ap the proof of commitment from which all memory should be freed.
*/
void
TALER_age_proof_free (
- struct TALER_AgeProof *p);
+ struct TALER_AgeProof *ap);
/**
* @brief helper function to free memory of a struct TALER_AgeCommitmentProof
*
- * @param p the commitment and its proof from which all memory should be freed.
+ * @param acp the commitment and its proof from which all memory should be freed.
*/
void
TALER_age_commitment_proof_free (
- struct TALER_AgeCommitmentProof *p);
+ struct TALER_AgeCommitmentProof *acp);
+
+
+/**
+ * @brief helper function to allocate and copy a struct TALER_AgeCommitmentProof
+ *
+ * @param[in] acp The original age commitment proof
+ * @return The deep copy of @e acp, allocated
+ */
+struct TALER_AgeCommitmentProof *
+TALER_age_commitment_proof_duplicate (
+ const struct TALER_AgeCommitmentProof *acp);
+
+/**
+ * @brief helper function to copy a struct TALER_AgeCommitmentProof
+ *
+ * @param[in] acp The original age commitment proof
+ * @param[out] nacp The struct to copy the data into, with freshly allocated and copied keys.
+ */
+void
+TALER_age_commitment_proof_deep_copy (
+ const struct TALER_AgeCommitmentProof *acp,
+ struct TALER_AgeCommitmentProof *nacp);
+
+/**
+ * @brief For age-withdraw, clients have to prove that the public keys for all
+ * age groups larger than the allowed maximum age group are derived by scalar
+ * multiplication from this Edx25519 public key (in Crockford Base32 encoding):
+ *
+ * DZJRF6HXN520505XDAWM8NMH36QV9J3VH77265WQ09EBQ76QSKCG
+ *
+ * Its private key was chosen randomly and then deleted.
+ */
+extern struct
+#ifndef AGE_RESTRICTION_WITH_ECDSA
+GNUNET_CRYPTO_Edx25519PublicKey
+#else
+GNUNET_CRYPTO_EcdsaPublicKey
+#endif
+TALER_age_commitment_base_public_key;
+
+/**
+ * @brief Similar to TALER_age_restriction_commit, but takes the coin's
+ * private key as seed input and calculates the public keys in the slots larger
+ * than the given age as derived from TALER_age_commitment_base_public_key.
+ *
+ * See https://docs.taler.net/core/api-exchange.html#withdraw-with-age-restriction
+ *
+ * @param secret The master secret of the coin from which we derive the age restriction
+ * @param mask The age mask, defining the age groups
+ * @param max_age The maximum age for this coin.
+ * @param[out] comm_proof The commitment and proof for age restriction for age @a max_age
+ */
+void
+TALER_age_restriction_from_secret (
+ const struct TALER_PlanchetMasterSecretP *secret,
+ const struct TALER_AgeMask *mask,
+ const uint8_t max_age,
+ struct TALER_AgeCommitmentProof *comm_proof);
+
+
+/**
+ * Group of Denominations. These are the common fields of an array of
+ * denominations.
+ *
+ * The corresponding JSON-blob will also contain an array of particular
+ * denominations with only the timestamps, cipher-specific public key and the
+ * master signature.
+ */
+struct TALER_DenominationGroup
+{
+
+ /**
+ * Value of coins in this denomination group.
+ */
+ struct TALER_Amount value;
+
+ /**
+ * Fee structure for all coins in the group.
+ */
+ struct TALER_DenomFeeSet fees;
+
+ /**
+ * Cipher used for the denomination.
+ */
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher;
+
+ /**
+ * Age mask for the denomination.
+ */
+ struct TALER_AgeMask age_mask;
+
+};
+
+
+/**
+ * Compute a unique key for the meta data of a denomination group.
+ *
+ * @param dg denomination group to evaluate
+ * @param[out] key key to set
+ */
+void
+TALER_denomination_group_get_key (
+ const struct TALER_DenominationGroup *dg,
+ struct GNUNET_HashCode *key);
+
+
+/**
+ * Token family public key.
+ */
+struct TALER_TokenFamilyPublicKey
+{
+ /**
+ * Type of the signature.
+ */
+ struct GNUNET_CRYPTO_BlindSignPublicKey public_key;
+};
+
+/**
+ * Hash of a public key of a token family.
+ */
+struct TALER_TokenFamilyPublicKeyHash
+{
+ /**
+ * Hash of the token public key.
+ */
+ struct GNUNET_HashCode hash;
+};
+
+/**
+ * Token family private key.
+ */
+struct TALER_TokenFamilyPrivateKey
+{
+ struct GNUNET_CRYPTO_BlindSignPrivateKey private_key;
+};
+
+/**
+ * Token public key.
+ */
+struct TALER_TokenPublicKey
+{
+ struct GNUNET_CRYPTO_EddsaPublicKey public_key;
+};
+
+/**
+ * Signature made using a token private key.
+ */
+struct TALER_TokenSignature
+{
+ struct GNUNET_CRYPTO_EddsaSignature signature;
+};
+
+/**
+ * Blind signature for a token (signed by merchant).
+ */
+struct TALER_TokenBlindSignature
+{
+ struct GNUNET_CRYPTO_BlindedSignature signature;
+};
#endif
diff --git a/src/include/taler_curl_lib.h b/src/include/taler_curl_lib.h
index 5151f4cf6..f108e6158 100644
--- a/src/include/taler_curl_lib.h
+++ b/src/include/taler_curl_lib.h
@@ -47,6 +47,11 @@ struct TALER_CURL_PostContext
* Custom headers.
*/
struct curl_slist *headers;
+
+ /**
+ * Set to true to disable compression of the body.
+ */
+ bool disable_compression;
};
@@ -74,4 +79,17 @@ void
TALER_curl_easy_post_finished (struct TALER_CURL_PostContext *ctx);
+/**
+ * Set a secure redirection policy, allowing a limited
+ * number of redirects and only going from HTTP to HTTPS
+ * but not from HTTPS to HTTP.
+ *
+ * @param[in,out] eh easy handle to modify
+ * @param url URL to base the redirect policy on;
+ * must start with "http://" or "https://"
+ */
+void
+TALER_curl_set_secure_redirect_policy (CURL *eh,
+ const char *url);
+
#endif
diff --git a/src/include/taler_exchange_service.h b/src/include/taler_exchange_service.h
index 6c3ad7a01..0597799b5 100644
--- a/src/include/taler_exchange_service.h
+++ b/src/include/taler_exchange_service.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -16,8 +16,11 @@
/**
* @file include/taler_exchange_service.h
* @brief C interface of libtalerexchange, a C library to use exchange's HTTP API
+ * This library is not thread-safe, all APIs must only be used from a single thread.
+ * This library calls abort() if it runs out of memory. Be aware of these limitations.
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
#ifndef _TALER_EXCHANGE_SERVICE_H
#define _TALER_EXCHANGE_SERVICE_H
@@ -25,31 +28,17 @@
#include <jansson.h>
#include "taler_util.h"
#include "taler_error_codes.h"
+#include "taler_kyclogic_lib.h"
#include <gnunet/gnunet_curl_lib.h>
-/* ********************* /keys *********************** */
-
/**
- * List of possible options to be passed to
- * #TALER_EXCHANGE_connect().
+ * Version of the Taler Exchange API, in hex.
+ * Thus 0.8.4-1 = 0x00080401.
*/
-enum TALER_EXCHANGE_Option
-{
- /**
- * Terminator (end of option list).
- */
- TALER_EXCHANGE_OPTION_END = 0,
+#define TALER_EXCHANGE_API_VERSION 0x00100000
- /**
- * Followed by a "const json_t *" that was previously returned for
- * this exchange URL by #TALER_EXCHANGE_serialize_data(). Used to
- * resume a connection to an exchange without having to re-download
- * /keys data (or at least only download the deltas).
- */
- TALER_EXCHANGE_OPTION_DATA
-
-};
+/* ********************* /keys *********************** */
/**
@@ -140,10 +129,18 @@ struct TALER_EXCHANGE_DenomPublicKey
struct TALER_DenomFeeSet fees;
/**
+ * Set to true if the private denomination key has been
+ * lost by the exchange and thus the key cannot be
+ * used for withdrawing at this time.
+ */
+ bool lost;
+
+ /**
* Set to true if this denomination key has been
* revoked by the exchange.
*/
bool revoked;
+
};
@@ -230,11 +227,6 @@ struct TALER_EXCHANGE_GlobalFee
struct GNUNET_TIME_Relative purse_timeout;
/**
- * Accounts without KYC will be closed after this time.
- */
- struct GNUNET_TIME_Relative kyc_timeout;
-
- /**
* Account history is limited to this timeframe.
*/
struct GNUNET_TIME_Relative history_expiration;
@@ -253,6 +245,183 @@ struct TALER_EXCHANGE_GlobalFee
/**
+ * List sorted by @a start_date with fees to be paid for aggregate wire transfers.
+ */
+struct TALER_EXCHANGE_WireAggregateFees
+{
+ /**
+ * This is a linked list.
+ */
+ struct TALER_EXCHANGE_WireAggregateFees *next;
+
+ /**
+ * Fee to be paid whenever the exchange wires funds to the merchant.
+ */
+ struct TALER_WireFeeSet fees;
+
+ /**
+ * Time when this fee goes into effect (inclusive)
+ */
+ struct GNUNET_TIME_Timestamp start_date;
+
+ /**
+ * Time when this fee stops being in effect (exclusive).
+ */
+ struct GNUNET_TIME_Timestamp end_date;
+
+ /**
+ * Signature affirming the above fee structure.
+ */
+ struct TALER_MasterSignatureP master_sig;
+};
+
+
+/**
+ * Information about wire fees by wire method.
+ */
+struct TALER_EXCHANGE_WireFeesByMethod
+{
+ /**
+ * Wire method with the given @e fees.
+ */
+ char *method;
+
+ /**
+ * Linked list of wire fees the exchange charges for
+ * accounts of the wire @e method.
+ */
+ struct TALER_EXCHANGE_WireAggregateFees *fees_head;
+
+};
+
+
+/**
+ * Type of an account restriction.
+ */
+enum TALER_EXCHANGE_AccountRestrictionType
+{
+ /**
+ * Invalid restriction.
+ */
+ TALER_EXCHANGE_AR_INVALID = 0,
+
+ /**
+ * Account must not be used for this operation.
+ */
+ TALER_EXCHANGE_AR_DENY = 1,
+
+ /**
+ * Other account must match given regular expression.
+ */
+ TALER_EXCHANGE_AR_REGEX = 2
+};
+
+/**
+ * Restrictions that apply to using a given exchange bank account.
+ */
+struct TALER_EXCHANGE_AccountRestriction
+{
+
+ /**
+ * Type of the account restriction.
+ */
+ enum TALER_EXCHANGE_AccountRestrictionType type;
+
+ /**
+ * Restriction details depending on @e type.
+ */
+ union
+ {
+ /**
+ * Details if type is #TALER_EXCHANGE_AR_REGEX.
+ */
+ struct
+ {
+ /**
+ * Regular expression that the payto://-URI of the partner account must
+ * follow. The regular expression should follow posix-egrep, but
+ * without support for character classes, GNU extensions,
+ * back-references or intervals. See
+ * https://www.gnu.org/software/findutils/manual/html_node/find_html/posix_002degrep-regular-expression-syntax.html
+ * for a description of the posix-egrep syntax. Applications may support
+ * regexes with additional features, but exchanges must not use such
+ * regexes.
+ */
+ char *posix_egrep;
+
+ /**
+ * Hint for a human to understand the restriction.
+ */
+ char *human_hint;
+
+ /**
+ * Internationalizations for the @e human_hint. Map from IETF BCP 47
+ * language tax to localized human hints.
+ */
+ json_t *human_hint_i18n;
+ } regex;
+ } details;
+
+};
+
+
+/**
+ * Information about a wire account of the exchange.
+ */
+struct TALER_EXCHANGE_WireAccount
+{
+ /**
+ * payto://-URI of the exchange.
+ */
+ char *payto_uri;
+
+ /**
+ * URL of a conversion service in case using this account is subject to
+ * currency conversion. NULL for no conversion needed.
+ */
+ char *conversion_url;
+
+ /**
+ * Array of restrictions that apply when crediting
+ * this account.
+ */
+ struct TALER_EXCHANGE_AccountRestriction *credit_restrictions;
+
+ /**
+ * Array of restrictions that apply when debiting
+ * this account.
+ */
+ struct TALER_EXCHANGE_AccountRestriction *debit_restrictions;
+
+ /**
+ * Length of the @e credit_restrictions array.
+ */
+ unsigned int credit_restrictions_length;
+
+ /**
+ * Length of the @e debit_restrictions array.
+ */
+ unsigned int debit_restrictions_length;
+
+ /**
+ * Signature of the exchange over the account (was checked by the API).
+ */
+ struct TALER_MasterSignatureP master_sig;
+
+ /**
+ * Display label for the account, can be NULL.
+ */
+ char *bank_label;
+
+ /**
+ * Priority for ordering the account in the display.
+ */
+ int64_t priority;
+
+};
+
+
+/**
* @brief Information about keys from the exchange.
*/
struct TALER_EXCHANGE_Keys
@@ -264,6 +433,11 @@ struct TALER_EXCHANGE_Keys
struct TALER_MasterPublicKeyP master_pub;
/**
+ * Signature over extension configuration data, if any.
+ */
+ struct TALER_MasterSignatureP extensions_sig;
+
+ /**
* Array of the exchange's online signing keys.
*/
struct TALER_EXCHANGE_SigningPublicKey *sign_keys;
@@ -284,6 +458,11 @@ struct TALER_EXCHANGE_Keys
struct TALER_EXCHANGE_GlobalFee *global_fees;
/**
+ * Configuration data for extensions.
+ */
+ json_t *extensions;
+
+ /**
* Supported Taler protocol version by the exchange.
* String in the format current:revision:age using the
* semantics of GNU libtool. See
@@ -297,6 +476,41 @@ struct TALER_EXCHANGE_Keys
char *currency;
/**
+ * What is the base URL of the exchange that returned
+ * these keys?
+ */
+ char *exchange_url;
+
+ /**
+ * Asset type used by the exchange. Typical values
+ * are "fiat" or "crypto" or "regional" or "stock".
+ * Wallets should adjust their UI/UX based on this
+ * value.
+ */
+ char *asset_type;
+
+ /**
+ * Array of amounts a wallet is allowed to hold from
+ * this exchange before it must undergo further KYC checks.
+ */
+ struct TALER_Amount *wallet_balance_limit_without_kyc;
+
+ /**
+ * Array of accounts of the exchange.
+ */
+ struct TALER_EXCHANGE_WireAccount *accounts;
+
+ /**
+ * Array of wire fees by wire method.
+ */
+ struct TALER_EXCHANGE_WireFeesByMethod *fees;
+
+ /**
+ * Currency rendering specification for this exchange.
+ */
+ struct TALER_CurrencySpecification cspec;
+
+ /**
* How long after a reserve went idle will the exchange close it?
* This is an approximate number, not cryptographically signed by
* the exchange (advisory-only, may change anytime).
@@ -304,15 +518,14 @@ struct TALER_EXCHANGE_Keys
struct GNUNET_TIME_Relative reserve_closing_delay;
/**
- * Maximum amount a wallet is allowed to hold from
- * this exchange before it must undergo a KYC check.
+ * Timestamp indicating the /keys generation.
*/
- struct TALER_Amount wallet_balance_limit_without_kyc;
+ struct GNUNET_TIME_Timestamp list_issue_date;
/**
- * Timestamp indicating the /keys generation.
+ * When does this keys data expire?
*/
- struct GNUNET_TIME_Timestamp list_issue_date;
+ struct GNUNET_TIME_Timestamp key_data_expiration;
/**
* Timestamp indicating the creation time of the last
@@ -327,6 +540,37 @@ struct TALER_EXCHANGE_Keys
struct TALER_AgeMask age_mask;
/**
+ * Absolute STEFAN parameter.
+ */
+ struct TALER_Amount stefan_abs;
+
+ /**
+ * Logarithmic STEFAN parameter.
+ */
+ struct TALER_Amount stefan_log;
+
+ /**
+ * Linear STEFAN parameter.
+ */
+ double stefan_lin;
+
+ /**
+ * Length of @e accounts array.
+ */
+ unsigned int accounts_len;
+
+ /**
+ * Length of @e fees array.
+ */
+ unsigned int fees_len;
+
+ /**
+ * Length of the @e wallet_balance_limit_without_kyc
+ * array.
+ */
+ unsigned int wblwk_length;
+
+ /**
* Length of the @e global_fees array.
*/
unsigned int num_global_fees;
@@ -356,6 +600,16 @@ struct TALER_EXCHANGE_Keys
*/
unsigned int denom_keys_size;
+ /**
+ * Reference counter for this structure.
+ * Freed when it reaches 0.
+ */
+ unsigned int rc;
+
+ /**
+ * Set to true if rewards are allowed at this exchange.
+ */
+ bool rewards_allowed;
};
@@ -423,6 +677,7 @@ struct TALER_EXCHANGE_HttpResponse
* reply (too big, invalid JSON).
*/
const json_t *reply;
+
/**
* Set to the human-readable 'hint' that is optionally
* provided by the exchange together with errors. NULL
@@ -451,151 +706,195 @@ struct TALER_EXCHANGE_HttpResponse
/**
+ * Response from /keys.
+ */
+struct TALER_EXCHANGE_KeysResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on the HTTP status code.
+ */
+ union
+ {
+
+ /**
+ * Details on #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Information about the various keys used by the exchange.
+ */
+ const struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * Protocol compatibility information
+ */
+ enum TALER_EXCHANGE_VersionCompatibility compat;
+ } ok;
+ } details;
+
+};
+
+
+/**
* Function called with information about who is auditing
* a particular exchange and what keys the exchange is using.
+ * The ownership over the @a keys object is passed to
+ * the callee, thus it is given explicitly and not
+ * (only) via @a kr.
*
* @param cls closure
- * @param hr HTTP response data
- * @param keys information about the various keys used
- * by the exchange, NULL if /keys failed
- * @param compat protocol compatibility information
+ * @param kr response from /keys
+ * @param[in] keys keys object passed to callback with
+ * reference counter of 1. Must be freed by callee
+ * using #TALER_EXCHANGE_keys_decref(). NULL on failure.
*/
typedef void
-(*TALER_EXCHANGE_CertificationCallback) (
+(*TALER_EXCHANGE_GetKeysCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat);
+ const struct TALER_EXCHANGE_KeysResponse *kr,
+ struct TALER_EXCHANGE_Keys *keys);
/**
- * @brief Handle to the exchange. This is where we interact with
- * a particular exchange and keep the per-exchange information.
+ * @brief Handle for a GET /keys request.
*/
-struct TALER_EXCHANGE_Handle;
+struct TALER_EXCHANGE_GetKeysHandle;
/**
- * Initialise a connection to the exchange. Will connect to the
- * exchange and obtain information about the exchange's master public
- * key and the exchange's auditor. The respective information will
- * be passed to the @a cert_cb once available, and all future
- * interactions with the exchange will be checked to be signed
- * (where appropriate) by the respective master key.
+ * Fetch the main /keys resources from an exchange. Does an incremental
+ * fetch if @a last_keys is given. The obtained information will be passed to
+ * the @a cert_cb (possibly after first merging it with @a last_keys to
+ * produce a full picture; expired keys (for deposit) will be removed from @a
+ * last_keys if there are any).
*
* @param ctx the context
* @param url HTTP base URL for the exchange
+ * @param[in,out] last_keys previous keys object, NULL for none
* @param cert_cb function to call with the exchange's certification information,
* possibly called repeatedly if the information changes
* @param cert_cb_cls closure for @a cert_cb
- * @param ... list of additional arguments, terminated by #TALER_EXCHANGE_OPTION_END.
* @return the exchange handle; NULL upon error
*/
-struct TALER_EXCHANGE_Handle *
-TALER_EXCHANGE_connect (struct GNUNET_CURL_Context *ctx,
- const char *url,
- TALER_EXCHANGE_CertificationCallback cert_cb,
- void *cert_cb_cls,
- ...);
+struct TALER_EXCHANGE_GetKeysHandle *
+TALER_EXCHANGE_get_keys (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *last_keys,
+ TALER_EXCHANGE_GetKeysCallback cert_cb,
+ void *cert_cb_cls);
/**
- * Serialize the latest key data from @a exchange to be persisted
- * on disk (to be used with #TALER_EXCHANGE_OPTION_DATA to more
- * efficiently recover the state).
+ * Serialize the latest data from @a keys to be persisted
+ * (for example, to be used as @a last_keys later).
*
- * @param exchange which exchange's key and wire data should be serialized
- * @return NULL on error (i.e. no current data available); otherwise
- * json object owned by the caller
+ * @param kd the key data to serialize
+ * @return NULL on error; otherwise JSON object owned by the caller
*/
json_t *
-TALER_EXCHANGE_serialize_data (struct TALER_EXCHANGE_Handle *exchange);
+TALER_EXCHANGE_keys_to_json (const struct TALER_EXCHANGE_Keys *kd);
/**
- * Disconnect from the exchange.
+ * Deserialize keys data stored in @a j.
*
- * @param exchange the exchange handle
+ * @param j JSON keys data previously returned from #TALER_EXCHANGE_keys_to_json()
+ * @return NULL on error (i.e. invalid JSON); otherwise
+ * keys object with reference counter 1 owned by the caller
*/
-void
-TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange);
+struct TALER_EXCHANGE_Keys *
+TALER_EXCHANGE_keys_from_json (const json_t *j);
/**
- * Obtain the keys from the exchange.
+ * Cancel GET /keys operation.
*
- * @param exchange the exchange handle
- * @return the exchange's key set
+ * @param[in] gkh the GET /keys handle
*/
-const struct TALER_EXCHANGE_Keys *
-TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange);
+void
+TALER_EXCHANGE_get_keys_cancel (struct TALER_EXCHANGE_GetKeysHandle *gkh);
/**
- * Let the user set the last valid denomination time manually.
+ * Increment reference counter for @a keys
*
- * @param exchange the exchange handle.
- * @param last_denom_new new last denomination time.
+ * @param[in,out] keys object to increment reference counter for
+ * @return keys, with incremented reference counter
*/
-void
-TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
- struct GNUNET_TIME_Timestamp last_denom_new);
+struct TALER_EXCHANGE_Keys *
+TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys);
/**
- * Flags for #TALER_EXCHANGE_check_keys_current().
+ * Decrement reference counter for @a keys.
+ * Frees @a keys if reference counter becomes zero.
+ *
+ * @param[in,out] keys object to decrement reference counter for
*/
-enum TALER_EXCHANGE_CheckKeysFlags
-{
- /**
- * No special options.
- */
- TALER_EXCHANGE_CKF_NONE,
-
- /**
- * Force downloading /keys now, even if /keys is still valid
- * (that is, the period advertised by the exchange for re-downloads
- * has not yet expired).
- */
- TALER_EXCHANGE_CKF_FORCE_DOWNLOAD = 1,
-
- /**
- * Pull all keys again, resetting the client state to the original state.
- * Using this flag disables the incremental download, and also prevents using
- * the context until the re-download has completed.
- */
- TALER_EXCHANGE_CKF_PULL_ALL_KEYS = 2,
+void
+TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys);
- /**
- * Force downloading all keys now.
- */
- TALER_EXCHANGE_CKF_FORCE_ALL_NOW = TALER_EXCHANGE_CKF_FORCE_DOWNLOAD
- | TALER_EXCHANGE_CKF_PULL_ALL_KEYS
-};
+/**
+ * Use STEFAN curve in @a keys to convert @a brut to @a net. Computes the
+ * expected minimum (!) @a net amount that should for sure arrive in the
+ * target amount at cost of @a brut to the wallet. Note that STEFAN curves by
+ * design over-estimate actual fees and a wallet may be able to achieve the
+ * same @a net amount with less fees --- or if the available coins are
+ * abnormal in structure, it may take more.
+ *
+ * @param keys exchange key data
+ * @param brut gross amount (actual cost including fees)
+ * @param[out] net net amount (effective amount)
+ * @return #GNUNET_OK on success, #GNUNET_NO if the
+ * resulting @a net is zero (or lower)
+ */
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_keys_stefan_b2n (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *brut,
+ struct TALER_Amount *net);
/**
- * Check if our current response for /keys is valid, and if
- * not, trigger /keys download.
+ * Use STEFAN curve in @a keys to convert @a net to @a brut. Computes the
+ * expected maximum (!) @a brut amount that should be needed in the wallet to
+ * transfer @a net amount to the target account. Note that STEFAN curves by
+ * design over-estimate actual fees and a wallet may be able to achieve the
+ * same @a net amount with less fees --- or if the available coins are
+ * abnormal in structure, it may take more.
*
- * @param exchange exchange to check keys for
- * @param flags options controlling when to download what
- * @return until when the existing response is current, 0 if we are re-downloading now
+ * @param keys exchange key data
+ * @param net net amount (effective amount)
+ * @param[out] brut gross amount (actual cost including fees)
+ * @return #GNUNET_OK on success, #GNUNET_NO if the
+ * resulting @a brut is zero (only if @a net was zero)
*/
-struct GNUNET_TIME_Timestamp
-TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
- enum TALER_EXCHANGE_CheckKeysFlags flags);
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_keys_stefan_n2b (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *net,
+ struct TALER_Amount *brut);
/**
- * Obtain the keys from the exchange in the raw JSON format.
+ * Round brutto or netto value computed via STEFAN
+ * curve to decimal places commonly used at the exchange.
*
- * @param exchange the exchange handle
- * @return the exchange's keys in raw JSON
+ * @param keys exchange keys response data
+ * @param[in,out] val value to round
*/
-json_t *
-TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange);
+void
+TALER_EXCHANGE_keys_stefan_round (
+ const struct TALER_EXCHANGE_Keys *keys,
+ struct TALER_Amount *val);
/**
@@ -607,18 +906,9 @@ TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange);
* @return #GNUNET_OK if @a pub is (according to /keys) a current signing key
*/
enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_ExchangePublicKeyP *pub);
-
-
-/**
- * Get exchange's base URL.
- *
- * @param exchange exchange handle.
- * @return the base URL from the handle.
- */
-const char *
-TALER_EXCHANGE_get_base_url (const struct TALER_EXCHANGE_Handle *exchange);
+TALER_EXCHANGE_test_signing_key (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_ExchangePublicKeyP *pub);
/**
@@ -652,7 +942,8 @@ TALER_EXCHANGE_get_global_fee (
* Create a copy of a denomination public key.
*
* @param key key to copy
- * @returns a copy, must be freed with #TALER_EXCHANGE_destroy_denomination_key
+ * @returns a copy, must be freed with #TALER_EXCHANGE_destroy_denomination_key()
+ * @deprecated
*/
struct TALER_EXCHANGE_DenomPublicKey *
TALER_EXCHANGE_copy_denomination_key (
@@ -661,9 +952,10 @@ TALER_EXCHANGE_copy_denomination_key (
/**
* Destroy a denomination public key.
- * Should only be called with keys created by #TALER_EXCHANGE_copy_denomination_key.
+ * Should only be called with keys created by #TALER_EXCHANGE_copy_denomination_key().
*
* @param key key to destroy.
+ * @deprecated
*/
void
TALER_EXCHANGE_destroy_denomination_key (
@@ -697,124 +989,36 @@ TALER_EXCHANGE_get_signing_key_info (
const struct TALER_ExchangePublicKeyP *exchange_pub);
-/* ********************* /wire *********************** */
-
-
-/**
- * Sorted list of fees to be paid for aggregate wire transfers.
- */
-struct TALER_EXCHANGE_WireAggregateFees
-{
- /**
- * This is a linked list.
- */
- struct TALER_EXCHANGE_WireAggregateFees *next;
-
- /**
- * Fee to be paid whenever the exchange wires funds to the merchant.
- */
- struct TALER_WireFeeSet fees;
-
- /**
- * Time when this fee goes into effect (inclusive)
- */
- struct GNUNET_TIME_Timestamp start_date;
-
- /**
- * Time when this fee stops being in effect (exclusive).
- */
- struct GNUNET_TIME_Timestamp end_date;
-
- /**
- * Signature affirming the above fee structure.
- */
- struct TALER_MasterSignatureP master_sig;
-};
-
-
-/**
- * Information about a wire account of the exchange.
- */
-struct TALER_EXCHANGE_WireAccount
-{
- /**
- * payto://-URI of the exchange.
- */
- const char *payto_uri;
-
- /**
- * Signature of the exchange over the account (was checked by the API).
- */
- struct TALER_MasterSignatureP master_sig;
-
- /**
- * Linked list of wire fees the exchange charges for
- * accounts of the wire method matching @e payto_uri.
- */
- const struct TALER_EXCHANGE_WireAggregateFees *fees;
-
-};
-
-
-/**
- * Callbacks of this type are used to serve the result of submitting a
- * wire format inquiry request to a exchange.
- *
- * If the request fails to generate a valid response from the
- * exchange, @a http_status will also be zero.
- *
- * @param cls closure
- * @param hr HTTP response data
- * @param accounts_len length of the @a accounts array
- * @param accounts list of wire accounts of the exchange, NULL on error
- */
-typedef void
-(*TALER_EXCHANGE_WireCallback) (
- void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- unsigned int accounts_len,
- const struct TALER_EXCHANGE_WireAccount *accounts);
-
-
-/**
- * @brief A Wire format inquiry handle
- */
-struct TALER_EXCHANGE_WireHandle;
+/* ********************* wire helpers *********************** */
/**
- * Obtain information about a exchange's wire instructions. A
- * exchange may provide wire instructions for creating a reserve. The
- * wire instructions also indicate which wire formats merchants may
- * use with the exchange. This API is typically used by a wallet for
- * wiring funds, and possibly by a merchant to determine supported
- * wire formats.
+ * Parse array of @a accounts of the exchange into @a was.
*
- * Note that while we return the (main) response verbatim to the
- * caller for further processing, we do already verify that the
- * response is well-formed (i.e. that signatures included in the
- * response are all valid). If the exchange's reply is not
- * well-formed, we return an HTTP status code of zero to @a cb.
- *
- * @param exchange the exchange handle; the exchange must be ready to operate
- * @param wire_cb the callback to call when a reply for this request is available
- * @param wire_cb_cls closure for the above callback
- * @return a handle for this request
+ * @param master_pub master public key of the exchange, NULL to not verify signatures
+ * @param accounts array of accounts to parse
+ * @param[out] was where to write the result (already allocated)
+ * @param was_length length of the @a was array, must match the length of @a accounts
+ * @return #GNUNET_OK if parsing @a accounts succeeded
*/
-struct TALER_EXCHANGE_WireHandle *
-TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
- TALER_EXCHANGE_WireCallback wire_cb,
- void *wire_cb_cls);
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_parse_accounts (
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const json_t *accounts,
+ unsigned int was_length,
+ struct TALER_EXCHANGE_WireAccount was[static was_length]);
/**
- * Cancel a wire information request. This function cannot be used
- * on a request handle if a response is already served for it.
+ * Free data within @a was, but not @a was itself.
*
- * @param wh the wire information request handle
+ * @param was array of wire account data
+ * @param was_len length of the @a was array
*/
void
-TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh);
+TALER_EXCHANGE_free_accounts (
+ unsigned int was_len,
+ struct TALER_EXCHANGE_WireAccount was[static was_len]);
/* ********************* /coins/$COIN_PUB/deposit *********************** */
@@ -867,18 +1071,16 @@ struct TALER_EXCHANGE_DepositContractDetail
{
/**
- * Execution date, until which the merchant would like the exchange to
- * settle the balance (advisory, the exchange cannot be forced to settle in
- * the past or upon very short notice, but of course a well-behaved exchange
- * will limit aggregation based on the advice received).
+ * Hash of the contact of the merchant with the customer (further details
+ * are never disclosed to the exchange)
*/
- struct GNUNET_TIME_Timestamp wire_deadline;
+ struct TALER_PrivateContractHashP h_contract_terms;
/**
- * The merchant’s account details, in the payto://-format supported by the
- * exchange.
+ * The public key of the merchant (used to identify the merchant for refund
+ * requests).
*/
- const char *merchant_payto_uri;
+ struct TALER_MerchantPublicKeyP merchant_pub;
/**
* Salt used to hash the @e merchant_payto_uri.
@@ -886,168 +1088,47 @@ struct TALER_EXCHANGE_DepositContractDetail
struct TALER_WireSaltP wire_salt;
/**
- * Hash of the contact of the merchant with the customer (further details
- * are never disclosed to the exchange)
+ * Hash over data provided by the wallet to customize the contract.
+ * All zero if not used.
*/
- struct TALER_PrivateContractHashP h_contract_terms;
+ struct GNUNET_HashCode wallet_data_hash;
/**
- * Extension-specific details about the deposit relevant to the exchange.
+ * Date until which the merchant can issue a refund to the customer via the
+ * exchange (can be zero if refunds are not allowed); must not be after the
+ * @e wire_deadline.
*/
- const json_t *extension_details;
+ struct GNUNET_TIME_Timestamp refund_deadline;
/**
- * Timestamp when the contract was finalized, must match approximately the
- * current time of the exchange.
+ * Execution date, until which the merchant would like the exchange to
+ * settle the balance (advisory, the exchange cannot be forced to settle in
+ * the past or upon very short notice, but of course a well-behaved exchange
+ * will limit aggregation based on the advice received).
*/
- struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_TIME_Timestamp wire_deadline;
/**
- * The public key of the merchant (used to identify the merchant for refund
- * requests).
+ * Timestamp when the contract was finalized, must match approximately the
+ * current time of the exchange.
*/
- struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Timestamp wallet_timestamp;
/**
- * Date until which the merchant can issue a refund to the customer via the
- * exchange (can be zero if refunds are not allowed); must not be after the
- * @e wire_deadline.
+ * The merchant’s account details, in the payto://-format supported by the
+ * exchange.
*/
- struct GNUNET_TIME_Timestamp refund_deadline;
-
-};
-
-
-/**
- * @brief A Deposit Handle
- */
-struct TALER_EXCHANGE_DepositHandle;
-
+ const char *merchant_payto_uri;
-/**
- * Structure with information about a deposit
- * operation's result.
- */
-struct TALER_EXCHANGE_DepositResult
-{
/**
- * HTTP response data
+ * Policy extension specific details about the deposit relevant to the exchange.
*/
- struct TALER_EXCHANGE_HttpResponse hr;
-
- union
- {
-
- /**
- * Information returned if the HTTP status is
- * #MHD_HTTP_OK.
- */
- struct
- {
- /**
- * Time when the exchange generated the deposit confirmation
- */
- struct GNUNET_TIME_Timestamp deposit_timestamp;
-
- /**
- * signature provided by the exchange
- */
- const struct TALER_ExchangeSignatureP *exchange_sig;
-
- /**
- * exchange key used to sign @a exchange_sig.
- */
- const struct TALER_ExchangePublicKeyP *exchange_pub;
-
- /**
- * Base URL for looking up wire transfers, or
- * NULL to use the default base URL.
- */
- const char *transaction_base_url;
-
- } success;
-
- /**
- * Information returned if the HTTP status is
- * #MHD_HTTP_CONFLICT.
- */
- struct
- {
- /* TODO: returning full details is not implemented */
- } conflict;
+ const json_t *policy_details;
- } details;
};
/**
- * Callbacks of this type are used to serve the result of submitting a
- * deposit permission request to a exchange.
- *
- * @param cls closure
- * @param dr deposit response details
- */
-typedef void
-(*TALER_EXCHANGE_DepositResultCallback) (
- void *cls,
- const struct TALER_EXCHANGE_DepositResult *dr);
-
-
-/**
- * Submit a deposit permission to the exchange and get the exchange's
- * response. This API is typically used by a merchant. Note that
- * while we return the response verbatim to the caller for further
- * processing, we do already verify that the response is well-formed
- * (i.e. that signatures included in the response are all valid). If
- * the exchange's reply is not well-formed, we return an HTTP status code
- * of zero to @a cb.
- *
- * We also verify that the @a cdd.coin_sig is valid for this deposit
- * request, and that the @a cdd.ub_sig is a valid signature for @a
- * coin_pub. Also, the @a exchange must be ready to operate (i.e. have
- * finished processing the /keys reply). If either check fails, we do
- * NOT initiate the transaction with the exchange and instead return NULL.
- *
- * @param exchange the exchange handle; the exchange must be ready to operate
- * @param dcd details about the contract the deposit is for
- * @param cdd details about the coin to be deposited
- * @param cb the callback to call when a reply for this request is available
- * @param cb_cls closure for the above callback
- * @param[out] ec if NULL is returned, set to the error code explaining why the operation failed
- * @return a handle for this request; NULL if the inputs are invalid (i.e.
- * signatures fail to verify). In this case, the callback is not called.
- */
-struct TALER_EXCHANGE_DepositHandle *
-TALER_EXCHANGE_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DepositContractDetail *dcd,
- const struct TALER_EXCHANGE_CoinDepositDetail *cdd,
- TALER_EXCHANGE_DepositResultCallback cb,
- void *cb_cls,
- enum TALER_ErrorCode *ec);
-
-
-/**
- * Change the chance that our deposit confirmation will be given to the
- * auditor to 100%.
- *
- * @param deposit the deposit permission request handle
- */
-void
-TALER_EXCHANGE_deposit_force_dc (struct TALER_EXCHANGE_DepositHandle *deposit);
-
-
-/**
- * Cancel a deposit permission request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param deposit the deposit permission request handle
- */
-void
-TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit);
-
-
-/**
* @brief A Batch Deposit Handle
*/
struct TALER_EXCHANGE_BatchDepositHandle;
@@ -1079,9 +1160,9 @@ struct TALER_EXCHANGE_BatchDepositResult
struct GNUNET_TIME_Timestamp deposit_timestamp;
/**
- * Array of signatures provided by the exchange
+ * Deposit confirmation signature provided by the exchange
*/
- const struct TALER_ExchangeSignatureP *exchange_sigs;
+ const struct TALER_ExchangeSignatureP *exchange_sig;
/**
* exchange key used to sign @a exchange_sig.
@@ -1094,12 +1175,7 @@ struct TALER_EXCHANGE_BatchDepositResult
*/
const char *transaction_base_url;
- /**
- * Length of the @e exchange_sigs array.
- */
- unsigned int num_signatures;
-
- } success;
+ } ok;
/**
* Information returned if the HTTP status is
@@ -1107,7 +1183,11 @@ struct TALER_EXCHANGE_BatchDepositResult
*/
struct
{
- /* TODO: returning full details is not implemented */
+ /**
+ * The coin that had a conflict.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
} conflict;
} details;
@@ -1141,7 +1221,9 @@ typedef void
* finished processing the /keys reply). If either check fails, we do
* NOT initiate the transaction with the exchange and instead return NULL.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param dcd details about the contract the deposit is for
* @param num_cdds length of the @a cdds array
* @param cdds array with details about the coins to be deposited
@@ -1153,10 +1235,12 @@ typedef void
*/
struct TALER_EXCHANGE_BatchDepositHandle *
TALER_EXCHANGE_batch_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_EXCHANGE_DepositContractDetail *dcd,
unsigned int num_cdds,
- const struct TALER_EXCHANGE_CoinDepositDetail *cdds,
+ const struct TALER_EXCHANGE_CoinDepositDetail cdds[static num_cdds],
TALER_EXCHANGE_BatchDepositResultCallback cb,
void *cb_cls,
enum TALER_ErrorCode *ec);
@@ -1166,23 +1250,22 @@ TALER_EXCHANGE_batch_deposit (
* Change the chance that our deposit confirmation will be given to the
* auditor to 100%.
*
- * @param deposit the batch deposit permission request handle
+ * @param[in,out] deposit the batch deposit permission request handle
*/
void
-TALER_EXCHANGE_batch_deposit_force_dc (struct
- TALER_EXCHANGE_BatchDepositHandle *
- deposit);
+TALER_EXCHANGE_batch_deposit_force_dc (
+ struct TALER_EXCHANGE_BatchDepositHandle *deposit);
/**
* Cancel a batch deposit permission request. This function cannot be used
* on a request handle if a response is already served for it.
*
- * @param deposit the deposit permission request handle
+ * @param[in] deposit the deposit permission request handle
*/
void
-TALER_EXCHANGE_batch_deposit_cancel (struct
- TALER_EXCHANGE_BatchDepositHandle *deposit);
+TALER_EXCHANGE_batch_deposit_cancel (
+ struct TALER_EXCHANGE_BatchDepositHandle *deposit);
/* ********************* /coins/$COIN_PUB/refund *********************** */
@@ -1192,23 +1275,51 @@ TALER_EXCHANGE_batch_deposit_cancel (struct
*/
struct TALER_EXCHANGE_RefundHandle;
+/**
+ * Response from the /refund API.
+ */
+struct TALER_EXCHANGE_RefundResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status code.
+ */
+ union
+ {
+ /**
+ * Details on #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Exchange key used to sign.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+
+ /**
+ * The actual signature
+ */
+ struct TALER_ExchangeSignatureP exchange_sig;
+ } ok;
+ } details;
+};
+
/**
* Callbacks of this type are used to serve the result of submitting a
* refund request to an exchange.
*
* @param cls closure
- * @param hr HTTP response data
- * @param sign_key exchange key used to sign @a obj, or NULL
- * @param signature the actual signature, or NULL on error
+ * @param rr refund response
*/
typedef void
(*TALER_EXCHANGE_RefundCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_ExchangePublicKeyP *sign_key,
- const struct TALER_ExchangeSignatureP *signature);
-
+ const struct TALER_EXCHANGE_RefundResponse *rr);
/**
* Submit a refund request to the exchange and get the exchange's response.
@@ -1222,7 +1333,9 @@ typedef void
* finished processing the /keys reply). If this check fails, we do
* NOT initiate the transaction with the exchange and instead return NULL.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param amount the amount to be refunded; must be larger than the refund fee
* (as that fee is still being subtracted), and smaller than the amount
* (with deposit fee) of the original deposit contribution of this coin
@@ -1239,15 +1352,17 @@ typedef void
* signatures fail to verify). In this case, the callback is not called.
*/
struct TALER_EXCHANGE_RefundHandle *
-TALER_EXCHANGE_refund (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_Amount *amount,
- const struct
- TALER_PrivateContractHashP *h_contract_terms,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- uint64_t rtransaction_id,
- const struct TALER_MerchantPrivateKeyP *merchant_priv,
- TALER_EXCHANGE_RefundCallback cb,
- void *cb_cls);
+TALER_EXCHANGE_refund (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *amount,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t rtransaction_id,
+ const struct TALER_MerchantPrivateKeyP *merchant_priv,
+ TALER_EXCHANGE_RefundCallback cb,
+ void *cb_cls);
/**
@@ -1301,14 +1416,14 @@ struct TALER_EXCHANGE_CsRMeltResponse
* respective coin's withdraw operation.
*/
const struct TALER_ExchangeWithdrawValues *alg_values;
- } success;
+ } ok;
/**
* Details if the status is #MHD_HTTP_GONE.
*/
struct
{
- /* TODO: returning full details is not implemented */
+ /* FIXME: returning full details is not implemented */
} gone;
} details;
@@ -1349,7 +1464,8 @@ struct TALER_EXCHANGE_NonceKey
/**
* Get a set of CS R values using a /csr-melt request.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
* @param rms master key used for the derivation of the CS values
* @param nks_len length of the @a nks array
* @param nks array of denominations and nonces
@@ -1360,12 +1476,14 @@ struct TALER_EXCHANGE_NonceKey
* In this case, the callback is not called.
*/
struct TALER_EXCHANGE_CsRMeltHandle *
-TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_RefreshMasterSecretP *rms,
- unsigned int nks_len,
- struct TALER_EXCHANGE_NonceKey *nks,
- TALER_EXCHANGE_CsRMeltCallback res_cb,
- void *res_cb_cls);
+TALER_EXCHANGE_csr_melt (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_RefreshMasterSecretP *rms,
+ unsigned int nks_len,
+ struct TALER_EXCHANGE_NonceKey nks[static nks_len],
+ TALER_EXCHANGE_CsRMeltCallback res_cb,
+ void *res_cb_cls);
/**
@@ -1413,7 +1531,8 @@ struct TALER_EXCHANGE_CsRWithdrawResponse
* respective coin's withdraw operation.
*/
struct TALER_ExchangeWithdrawValues alg_values;
- } success;
+
+ } ok;
/**
* Details if the status is #MHD_HTTP_GONE.
@@ -1443,7 +1562,8 @@ typedef void
/**
* Get a CS R using a /csr-withdraw request.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param curl_ctx The curl context to use for the requests
+ * @param exchange_url Base-URL to the excnange
* @param pk Which denomination key is the /csr request for
* @param nonce client nonce for the request
* @param res_cb the callback to call when the final result for this request is available
@@ -1453,11 +1573,13 @@ typedef void
* In this case, the callback is not called.
*/
struct TALER_EXCHANGE_CsRWithdrawHandle *
-TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DenomPublicKey *pk,
- const struct TALER_CsNonce *nonce,
- TALER_EXCHANGE_CsRWithdrawCallback res_cb,
- void *res_cb_cls);
+TALER_EXCHANGE_csr_withdraw (
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_DenomPublicKey *pk,
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
+ TALER_EXCHANGE_CsRWithdrawCallback res_cb,
+ void *res_cb_cls);
/**
@@ -1472,6 +1594,329 @@ TALER_EXCHANGE_csr_withdraw_cancel (
struct TALER_EXCHANGE_CsRWithdrawHandle *csrh);
+/* ********************* GET /coins/$COIN_PUB *********************** */
+
+/**
+ * Ways how a coin's balance may change.
+ */
+enum TALER_EXCHANGE_CoinTransactionType
+{
+
+ /**
+ * Reserved for uninitialized / none.
+ */
+ TALER_EXCHANGE_CTT_NONE,
+
+ /**
+ * Deposit into a contract.
+ */
+ TALER_EXCHANGE_CTT_DEPOSIT,
+
+ /**
+ * Spent on melt.
+ */
+ TALER_EXCHANGE_CTT_MELT,
+
+ /**
+ * Refunded by merchant.
+ */
+ TALER_EXCHANGE_CTT_REFUND,
+
+ /**
+ * Debited in recoup (to reserve) operation.
+ */
+ TALER_EXCHANGE_CTT_RECOUP,
+
+ /**
+ * Debited in recoup-and-refresh operation.
+ */
+ TALER_EXCHANGE_CTT_RECOUP_REFRESH,
+
+ /**
+ * Credited in recoup-refresh.
+ */
+ TALER_EXCHANGE_CTT_OLD_COIN_RECOUP,
+
+ /**
+ * Deposited into purse.
+ */
+ TALER_EXCHANGE_CTT_PURSE_DEPOSIT,
+
+ /**
+ * Refund from purse.
+ */
+ TALER_EXCHANGE_CTT_PURSE_REFUND,
+
+ /**
+ * Reserve open payment operation.
+ */
+ TALER_EXCHANGE_CTT_RESERVE_OPEN_DEPOSIT
+
+};
+
+
+/**
+ * @brief Entry in the coin's transaction history.
+ */
+struct TALER_EXCHANGE_CoinHistoryEntry
+{
+
+ /**
+ * Type of the transaction.
+ */
+ enum TALER_EXCHANGE_CoinTransactionType type;
+
+ /**
+ * Amount transferred (in or out).
+ */
+ struct TALER_Amount amount;
+
+ /**
+ * Details depending on @e type.
+ */
+ union
+ {
+
+ struct
+ {
+ struct TALER_MerchantWireHashP h_wire;
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_ExtensionPolicyHashP h_policy;
+ bool no_h_policy;
+ struct GNUNET_HashCode wallet_data_hash;
+ bool no_wallet_data_hash;
+ struct GNUNET_TIME_Timestamp wallet_timestamp;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct GNUNET_TIME_Timestamp refund_deadline;
+ struct TALER_CoinSpendSignatureP sig;
+ struct TALER_AgeCommitmentHash hac;
+ bool no_hac;
+ struct TALER_Amount deposit_fee;
+ } deposit;
+
+ struct
+ {
+ struct TALER_CoinSpendSignatureP sig;
+ struct TALER_RefreshCommitmentP rc;
+ struct TALER_AgeCommitmentHash h_age_commitment;
+ bool no_hac;
+ struct TALER_Amount melt_fee;
+ } melt;
+
+ struct
+ {
+ struct TALER_PrivateContractHashP h_contract_terms;
+ struct TALER_MerchantPublicKeyP merchant_pub;
+ struct TALER_MerchantSignatureP sig;
+ struct TALER_Amount refund_fee;
+ struct TALER_Amount sig_amount;
+ uint64_t rtransaction_id;
+ } refund;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp timestamp;
+ union GNUNET_CRYPTO_BlindingSecretP coin_bks;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ } recoup;
+
+ struct
+ {
+ struct TALER_CoinSpendPublicKeyP old_coin_pub;
+ union GNUNET_CRYPTO_BlindingSecretP coin_bks;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ } recoup_refresh;
+
+ struct
+ {
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_CoinSpendPublicKeyP new_coin_pub;
+ struct GNUNET_TIME_Timestamp timestamp;
+ } old_coin_recoup;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ const char *exchange_base_url;
+ bool refunded;
+ struct TALER_AgeCommitmentHash phac;
+ } purse_deposit;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_Amount refund_fee;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ struct TALER_ExchangeSignatureP exchange_sig;
+ } purse_refund;
+
+ struct
+ {
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ } reserve_open_deposit;
+
+ } details;
+
+};
+
+
+/**
+ * @brief A /coins/$RID/history Handle
+ */
+struct TALER_EXCHANGE_CoinsHistoryHandle;
+
+
+/**
+ * Parses and verifies a coin's transaction history as
+ * returned by the exchange. Note that in case of
+ * incremental histories, the client must first combine
+ * the incremental histories into one complete history.
+ *
+ * @param keys /keys data of the exchange
+ * @param dk denomination key of the coin
+ * @param history JSON array with the coin's history
+ * @param coin_pub public key of the coin
+ * @param[out] total_in set to total amount credited to the coin in @a history
+ * @param[out] total_out set to total amount debited to the coin in @a history
+ * @param rlen length of the @a rhistory array
+ * @param[out] rhistory array where to write the parsed @a history
+ * @return #GNUNET_OK if @a history is valid,
+ * #GNUNET_SYSERR if not
+ */
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_parse_coin_history (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_EXCHANGE_DenomPublicKey *dk,
+ const json_t *history,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount *total_in,
+ struct TALER_Amount *total_out,
+ unsigned int rlen,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen]);
+
+
+/**
+ * Verify that @a coin_sig does NOT appear in the @a history of a coin's
+ * transactions and thus whatever transaction is authorized by @a coin_sig is
+ * a conflict with @a proof.
+ *
+ * @param history coin history to check
+ * @param coin_sig signature that must not be in @a history
+ * @return #GNUNET_OK if @a coin_sig is not in @a history
+ */
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_check_coin_signature_conflict (
+ const json_t *history,
+ const struct TALER_CoinSpendSignatureP *coin_sig);
+
+
+/**
+ * Response to a GET /coins/$COIN_PUB/history request.
+ */
+struct TALER_EXCHANGE_CoinHistory
+{
+ /**
+ * High-level HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on @e hr.http_status.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success, if
+ * @e hr.http_status is #MHD_HTTP_OK
+ */
+ struct
+ {
+
+ /**
+ * Coin transaction history (possibly partial).
+ * Not yet validated, combine with other already
+ * known history data for this coin and then use
+ * #TALER_EXCHANGE_parse_coin_history() to validate
+ * the complete history and obtain it in binary
+ * format.
+ */
+ const json_t *history;
+
+ /**
+ * The hash of the coin denomination's public key
+ */
+ struct TALER_DenominationHashP h_denom_pub;
+
+ /**
+ * Coin balance.
+ */
+ struct TALER_Amount balance;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
+ * Signature of functions called with the result of
+ * a coin transaction history request.
+ *
+ * @param cls closure
+ * @param ch transaction history for the coin
+ */
+typedef void
+(*TALER_EXCHANGE_CoinsHistoryCallback)(
+ void *cls,
+ const struct TALER_EXCHANGE_CoinHistory *ch);
+
+
+/**
+ * Parses and verifies a coin's transaction history as
+ * returned by the exchange. Note that a client may
+ * have to combine multiple partial coin histories
+ * into one coherent history before calling this function.
+ *
+ * @param ctx context for managing request
+ * @param url base URL of the exchange
+ * @param coin_priv private key of the coin
+ * @param start_off offset from which on to request history
+ * @param cb function to call with results
+ * @param cb_cls closure for @a cb
+ * @return #GNUNET_OK if @a history is valid,
+ * #GNUNET_SYSERR if not
+ */
+struct TALER_EXCHANGE_CoinsHistoryHandle *
+TALER_EXCHANGE_coins_history (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ uint64_t start_off,
+ TALER_EXCHANGE_CoinsHistoryCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_coins_history() operation.
+ *
+ * @param[in] rsh operation to cancel
+ */
+void
+TALER_EXCHANGE_coins_history_cancel (
+ struct TALER_EXCHANGE_CoinsHistoryHandle *rsh);
+
+
/* ********************* GET /reserves/$RESERVE_PUB *********************** */
/**
@@ -1491,6 +1936,11 @@ enum TALER_EXCHANGE_ReserveTransactionType
TALER_EXCHANGE_RTT_WITHDRAWAL,
/**
+ * Age-Withdrawal from the reserve.
+ */
+ TALER_EXCHANGE_RTT_AGEWITHDRAWAL,
+
+ /**
* /recoup operation.
*/
TALER_EXCHANGE_RTT_RECOUP,
@@ -1498,17 +1948,22 @@ enum TALER_EXCHANGE_ReserveTransactionType
/**
* Reserve closed operation.
*/
- TALER_EXCHANGE_RTT_CLOSE,
+ TALER_EXCHANGE_RTT_CLOSING,
/**
- * Reserve history request.
+ * Reserve purse merge operation.
*/
- TALER_EXCHANGE_RTT_HISTORY,
+ TALER_EXCHANGE_RTT_MERGE,
/**
- * Reserve purese merge operation.
+ * Reserve open request operation.
*/
- TALER_EXCHANGE_RTT_MERGE
+ TALER_EXCHANGE_RTT_OPEN,
+
+ /**
+ * Reserve close request operation.
+ */
+ TALER_EXCHANGE_RTT_CLOSE
};
@@ -1576,6 +2031,28 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
} withdraw;
/**
+ * Information about withdraw operation.
+ * @e type is #TALER_EXCHANGE_RTT_AGEWITHDRAWAL.
+ */
+ struct
+ {
+ /**
+ * Signature authorizing the withdrawal for outgoing transaction.
+ */
+ json_t *out_authorization_sig;
+
+ /**
+ * Maximum age committed
+ */
+ uint8_t max_age;
+
+ /**
+ * Fee that was charged for the withdrawal.
+ */
+ struct TALER_Amount fee;
+ } age_withdraw;
+
+ /**
* Information provided if the reserve was filled via /recoup.
* @e type is #TALER_EXCHANGE_RTT_RECOUP.
*/
@@ -1612,7 +2089,7 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
struct
{
/**
- * Receiver account information for the outgoing wire transfer.
+ * Receiver account information for the outgoing wire transfer as a payto://-URI.
*/
const char *receiver_account_details;
@@ -1645,25 +2122,6 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
} close_details;
/**
- * Information about a history operation of the reserve.
- * @e type is #TALER_EXCHANGE_RTT_HISTORY.
- */
- struct
- {
-
- /**
- * When was the request made.
- */
- struct GNUNET_TIME_Timestamp request_timestamp;
-
- /**
- * Signature by the reserve approving the history request.
- */
- struct TALER_ReserveSignatureP reserve_sig;
-
- } history_details;
-
- /**
* Information about a merge operation on the reserve.
* @e type is #TALER_EXCHANGE_RTT_MERGE.
*/
@@ -1723,6 +2181,71 @@ struct TALER_EXCHANGE_ReserveHistoryEntry
} merge_details;
+ /**
+ * Information about an open request operation on the reserve.
+ * @e type is #TALER_EXCHANGE_RTT_OPEN.
+ */
+ struct
+ {
+
+ /**
+ * Signature by the reserve approving the open.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Amount to be paid from the reserve balance to open
+ * the reserve.
+ */
+ struct TALER_Amount reserve_payment;
+
+ /**
+ * When was the request created.
+ */
+ struct GNUNET_TIME_Timestamp request_timestamp;
+
+ /**
+ * For how long should the reserve be kept open.
+ * (Determines amount to be paid.)
+ */
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+
+ /**
+ * How many open purses should be included with the
+ * open reserve?
+ * (Determines amount to be paid.)
+ */
+ uint32_t purse_limit;
+
+ } open_request;
+
+ /**
+ * Information about an close request operation on the reserve.
+ * @e type is #TALER_EXCHANGE_RTT_CLOSE.
+ */
+ struct
+ {
+
+ /**
+ * Signature by the reserve approving the close.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * When was the request created.
+ */
+ struct GNUNET_TIME_Timestamp request_timestamp;
+
+ /**
+ * Hash of the payto://-URI of the target account
+ * for the closure, or all zeros for the reserve
+ * origin account.
+ */
+ struct TALER_PaytoHashP target_account_h_payto;
+
+ } close_request;
+
+
} details;
};
@@ -1792,7 +2315,8 @@ typedef void
* reply is not well-formed, we return an HTTP status code of zero to
* @a cb.
*
- * @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 inspect
* @param timeout how long to wait for an affirmative reply
* (enables long polling if the reserve does not yet exist)
@@ -1803,7 +2327,8 @@ typedef void
*/
struct TALER_EXCHANGE_ReservesGetHandle *
TALER_EXCHANGE_reserves_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_ReservePublicKeyP *reserve_pub,
struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_ReservesGetCallback cb,
@@ -1822,15 +2347,15 @@ TALER_EXCHANGE_reserves_get_cancel (
/**
- * @brief A /reserves/$RID/status Handle
+ * @brief A /reserves/$RID/history Handle
*/
-struct TALER_EXCHANGE_ReservesStatusHandle;
+struct TALER_EXCHANGE_ReservesHistoryHandle;
/**
- * @brief Reserve status details.
+ * @brief Reserve history details.
*/
-struct TALER_EXCHANGE_ReserveStatus
+struct TALER_EXCHANGE_ReserveHistory
{
/**
@@ -1839,14 +2364,14 @@ struct TALER_EXCHANGE_ReserveStatus
struct TALER_EXCHANGE_HttpResponse hr;
/**
- * Details depending on @e hr.http_status.
+ * Details depending on @e hr.http_history.
*/
union
{
/**
* Information returned on success, if
- * @e hr.http_status is #MHD_HTTP_OK
+ * @e hr.http_history is #MHD_HTTP_OK
*/
struct
{
@@ -1868,127 +2393,11 @@ struct TALER_EXCHANGE_ReserveStatus
struct TALER_Amount total_out;
/**
- * Reserve history.
+ * Current etag / last entry in the history.
+ * Useful to filter requests by starting offset.
+ * Offsets are not necessarily contiguous.
*/
- const struct TALER_EXCHANGE_ReserveHistoryEntry *history;
-
- /**
- * Length of the @e history array.
- */
- unsigned int history_len;
-
- /**
- * KYC passed?
- */
- bool kyc_ok;
-
- } ok;
-
- } details;
-
-};
-
-
-/**
- * Callbacks of this type are used to serve the result of submitting a
- * reserve status request to a exchange.
- *
- * @param cls closure
- * @param rs HTTP response data
- */
-typedef void
-(*TALER_EXCHANGE_ReservesStatusCallback) (
- void *cls,
- const struct TALER_EXCHANGE_ReserveStatus *rs);
-
-
-/**
- * Submit a request to obtain the reserve status.
- *
- * @param exchange the exchange handle; the exchange must be ready to operate
- * @param reserve_priv private key of the reserve to inspect
- * @param cb the callback to call when a reply for this request is available
- * @param cb_cls closure for the above callback
- * @return a handle for this request; NULL if the inputs are invalid (i.e.
- * signatures fail to verify). In this case, the callback is not called.
- */
-struct TALER_EXCHANGE_ReservesStatusHandle *
-TALER_EXCHANGE_reserves_status (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_ReservesStatusCallback cb,
- void *cb_cls);
-
-
-/**
- * Cancel a reserve status request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param rsh the reserve request handle
- */
-void
-TALER_EXCHANGE_reserves_status_cancel (
- struct TALER_EXCHANGE_ReservesStatusHandle *rsh);
-
-
-/**
- * @brief A /reserves/$RID/history Handle
- */
-struct TALER_EXCHANGE_ReservesHistoryHandle;
-
-
-/**
- * @brief Reserve history details.
- */
-struct TALER_EXCHANGE_ReserveHistory
-{
-
- /**
- * High-level HTTP response details.
- */
- struct TALER_EXCHANGE_HttpResponse hr;
-
- /**
- * Timestamp of when we made the history request
- * (client-side).
- */
- struct GNUNET_TIME_Timestamp ts;
-
- /**
- * Reserve signature affirming the history request
- * (generated as part of the request).
- */
- const struct TALER_ReserveSignatureP *reserve_sig;
-
- /**
- * Details depending on @e hr.http_status.
- */
- union
- {
-
- /**
- * Information returned on success, if
- * @e hr.http_status is #MHD_HTTP_OK
- */
- struct
- {
-
- /**
- * Reserve balance. May not be the difference between
- * @e total_in and @e total_out because the @e may be truncated
- * due to expiration.
- */
- struct TALER_Amount balance;
-
- /**
- * Total of all inbound transactions in @e history.
- */
- struct TALER_Amount total_in;
-
- /**
- * Total of all outbound transactions in @e history.
- */
- struct TALER_Amount total_out;
+ uint64_t etag;
/**
* Reserve history.
@@ -2023,8 +2432,11 @@ typedef void
/**
* Submit a request to obtain the reserve history.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param reserve_priv private key of the reserve to inspect
+ * @param start_off offset of the oldest history entry to exclude from the response
* @param cb the callback to call when a reply for this request is available
* @param cb_cls closure for the above callback
* @return a handle for this request; NULL if the inputs are invalid (i.e.
@@ -2032,8 +2444,11 @@ typedef void
*/
struct TALER_EXCHANGE_ReservesHistoryHandle *
TALER_EXCHANGE_reserves_history (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
+ uint64_t start_off,
TALER_EXCHANGE_ReservesHistoryCallback cb,
void *cb_cls);
@@ -2049,15 +2464,6 @@ TALER_EXCHANGE_reserves_history_cancel (
struct TALER_EXCHANGE_ReservesHistoryHandle *rsh);
-/* ********************* POST /reserves/$RESERVE_PUB/withdraw *********************** */
-
-
-/**
- * @brief A /reserves/$RESERVE_PUB/withdraw Handle
- */
-struct TALER_EXCHANGE_WithdrawHandle;
-
-
/**
* Information input into the withdraw process per coin.
*/
@@ -2096,7 +2502,7 @@ struct TALER_EXCHANGE_PrivateCoinDetails
* Value used to blind the key for the signature.
* Needed for recoup operations.
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
/**
* Signature over the coin.
@@ -2112,109 +2518,6 @@ struct TALER_EXCHANGE_PrivateCoinDetails
/**
- * Details about a response for a withdraw request.
- */
-struct TALER_EXCHANGE_WithdrawResponse
-{
- /**
- * HTTP response data.
- */
- struct TALER_EXCHANGE_HttpResponse hr;
-
- /**
- * Details about the response.
- */
- union
- {
- /**
- * Details if the status is #MHD_HTTP_OK.
- */
- struct TALER_EXCHANGE_PrivateCoinDetails success;
-
- /**
- * Details if the status is #MHD_HTTP_ACCEPTED.
- */
- struct
- {
- /**
- * Payment target that the merchant should use
- * to check for its KYC status.
- */
- uint64_t payment_target_uuid;
- } accepted;
-
- /**
- * Details if the status is #MHD_HTTP_CONFLICT.
- */
- struct
- {
- /* TODO: returning full details is not implemented */
- } conflict;
-
- /**
- * Details if the status is #MHD_HTTP_GONE.
- */
- struct
- {
- /* TODO: returning full details is not implemented */
- } gone;
-
- } details;
-};
-
-
-/**
- * Callbacks of this type are used to serve the result of submitting a
- * withdraw request to a exchange.
- *
- * @param cls closure
- * @param wr response details
- */
-typedef void
-(*TALER_EXCHANGE_WithdrawCallback) (
- void *cls,
- const struct TALER_EXCHANGE_WithdrawResponse *wr);
-
-
-/**
- * Withdraw a coin from the exchange using a /reserves/$RESERVE_PUB/withdraw
- * request. This API is typically used by a wallet to withdraw from a
- * reserve.
- *
- * Note that to ensure that no money is lost in case of hardware
- * failures, the caller must have committed (most of) the arguments to
- * disk before calling, and be ready to repeat the request with the
- * same arguments in case of failures.
- *
- * @param exchange the exchange handle; the exchange must be ready to operate
- * @param reserve_priv private key of the reserve to withdraw from
- * @param wci inputs that determine the planchet
- * @param res_cb the callback to call when the final result for this request is available
- * @param res_cb_cls closure for @a res_cb
- * @return NULL
- * if the inputs are invalid (i.e. denomination key not with this exchange).
- * In this case, the callback is not called.
- */
-struct TALER_EXCHANGE_WithdrawHandle *
-TALER_EXCHANGE_withdraw (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_EXCHANGE_WithdrawCoinInput *wci,
- TALER_EXCHANGE_WithdrawCallback res_cb,
- void *res_cb_cls);
-
-
-/**
- * Cancel a withdraw status request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param wh the withdraw handle
- */
-void
-TALER_EXCHANGE_withdraw_cancel (struct TALER_EXCHANGE_WithdrawHandle *wh);
-
-
-/**
* @brief A /reserves/$RESERVE_PUB/batch-withdraw Handle
*/
struct TALER_EXCHANGE_BatchWithdrawHandle;
@@ -2250,19 +2553,25 @@ struct TALER_EXCHANGE_BatchWithdrawResponse
* Length of the @e coins array.
*/
unsigned int num_coins;
- } success;
+ } ok;
/**
- * Details if the status is #MHD_HTTP_ACCEPTED.
+ * Details if the status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
*/
struct
{
+
/**
- * Payment target that the merchant should use
- * to check for its KYC status.
+ * Hash of the payto-URI of the account to KYC;
*/
- uint64_t payment_target_uuid;
- } accepted;
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Legitimization requirement that the merchant should use
+ * to check for its KYC status, 0 if not known.
+ */
+ uint64_t requirement_row;
+ } unavailable_for_legal_reasons;
/**
* Details if the status is #MHD_HTTP_CONFLICT.
@@ -2300,17 +2609,20 @@ typedef void
/**
* Withdraw multiple coins from the exchange using a /reserves/$RESERVE_PUB/batch-withdraw
* request. This API is typically used by a wallet to withdraw many coins from a
- * reserve.
+ * reserve. The blind signatures are unblinded and verified before being returned
+ * to the caller at @a res_cb.
*
* Note that to ensure that no money is lost in case of hardware
* failures, the caller must have committed (most of) the arguments to
* disk before calling, and be ready to repeat the request with the
* same arguments in case of failures.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param curl_ctx The curl context to use
+ * @param exchange_url The base-URL of the exchange
+ * @param keys The /keys material from the exchange
* @param reserve_priv private key of the reserve to withdraw from
- * @param wcis inputs that determine the planchets
* @param wci_length number of entries in @a wcis
+ * @param wcis inputs that determine the planchets
* @param res_cb the callback to call when the final result for this request is available
* @param res_cb_cls closure for @a res_cb
* @return NULL
@@ -2319,10 +2631,12 @@ typedef void
*/
struct TALER_EXCHANGE_BatchWithdrawHandle *
TALER_EXCHANGE_batch_withdraw (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_EXCHANGE_WithdrawCoinInput *wcis,
unsigned int wci_length,
+ const struct TALER_EXCHANGE_WithdrawCoinInput wcis[static wci_length],
TALER_EXCHANGE_BatchWithdrawCallback res_cb,
void *res_cb_cls);
@@ -2339,18 +2653,45 @@ TALER_EXCHANGE_batch_withdraw_cancel (
/**
+ * Response from a withdraw2 request.
+ */
+struct TALER_EXCHANGE_Withdraw2Response
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * blind signature over the coin
+ */
+ struct TALER_BlindedDenominationSignature blind_sig;
+ } ok;
+ } details;
+
+};
+
+/**
* Callbacks of this type are used to serve the result of submitting a
* withdraw request to a exchange without the (un)blinding factor.
*
* @param cls closure
- * @param hr HTTP response data
- * @param blind_sig blind signature over the coin, NULL on error
+ * @param w2r response data
*/
typedef void
(*TALER_EXCHANGE_Withdraw2Callback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_BlindedDenominationSignature *blind_sig);
+ const struct TALER_EXCHANGE_Withdraw2Response *w2r);
/**
@@ -2366,14 +2707,20 @@ struct TALER_EXCHANGE_Withdraw2Handle;
/**
* Withdraw a coin from the exchange using a /reserves/$RESERVE_PUB/withdraw
* request. This API is typically used by a merchant to withdraw a tip
- * where the blinding factor is unknown to the merchant.
+ * where the blinding factor is unknown to the merchant. Note that unlike
+ * the #TALER_EXCHANGE_batch_withdraw() API, this API neither unblinds the signatures
+ * nor can it verify that the exchange signatures are valid, so these tasks
+ * are left to the caller. Wallets probably should use #TALER_EXCHANGE_batch_withdraw()
+ * which integrates these steps.
*
* Note that to ensure that no money is lost in case of hardware
* failures, the caller must have committed (most of) the arguments to
* disk before calling, and be ready to repeat the request with the
* same arguments in case of failures.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param curl_ctx The curl-context to use
+ * @param exchange_url The base-URL of the exchange
+ * @param keys The /keys material from the exchange
* @param pd planchet details of the planchet to withdraw
* @param reserve_priv private key of the reserve to withdraw from
* @param res_cb the callback to call when the final result for this request is available
@@ -2383,11 +2730,14 @@ struct TALER_EXCHANGE_Withdraw2Handle;
* In this case, the callback is not called.
*/
struct TALER_EXCHANGE_Withdraw2Handle *
-TALER_EXCHANGE_withdraw2 (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_PlanchetDetail *pd,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_Withdraw2Callback res_cb,
- void *res_cb_cls);
+TALER_EXCHANGE_withdraw2 (
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_PlanchetDetail *pd,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ TALER_EXCHANGE_Withdraw2Callback res_cb,
+ void *res_cb_cls);
/**
@@ -2401,20 +2751,67 @@ TALER_EXCHANGE_withdraw2_cancel (struct TALER_EXCHANGE_Withdraw2Handle *wh);
/**
+ * Response from a batch-withdraw request (2nd variant).
+ */
+struct TALER_EXCHANGE_BatchWithdraw2Response
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * array of blind signatures over the coins.
+ */
+ const struct TALER_BlindedDenominationSignature *blind_sigs;
+
+ /**
+ * length of @e blind_sigs
+ */
+ unsigned int blind_sigs_length;
+
+ } ok;
+
+ struct
+ {
+ /**
+ * Hash of the payto-URI of the account to KYC;
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * ID identifying the KYC requirement to withdraw.
+ */
+ uint64_t kyc_requirement_id;
+
+ } unavailable_for_legal_reasons;
+
+ } details;
+
+};
+
+
+/**
* Callbacks of this type are used to serve the result of submitting a batch
* withdraw request to a exchange without the (un)blinding factor.
*
* @param cls closure
- * @param hr HTTP response data
- * @param blind_sigs array of blind signatures over the coins, NULL on error
- * @param blind_sigs_length length of @a blind_sigs
+ * @param bw2r response data
*/
typedef void
(*TALER_EXCHANGE_BatchWithdraw2Callback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_BlindedDenominationSignature *blind_sigs,
- unsigned int blind_sigs_length);
+ const struct TALER_EXCHANGE_BatchWithdraw2Response *bw2r);
/**
@@ -2437,7 +2834,9 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle;
* disk before calling, and be ready to repeat the request with the
* same arguments in case of failures.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param curl_ctx The curl context to use
+ * @param exchange_url The base-URL of the exchange
+ * @param keys The /keys material from the exchange
* @param pds array of planchet details of the planchet to withdraw
* @param pds_length number of entries in the @a pds array
* @param reserve_priv private key of the reserve to withdraw from
@@ -2449,10 +2848,12 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle;
*/
struct TALER_EXCHANGE_BatchWithdraw2Handle *
TALER_EXCHANGE_batch_withdraw2 (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_PlanchetDetail *pds,
unsigned int pds_length,
+ const struct TALER_PlanchetDetail pds[static pds_length],
TALER_EXCHANGE_BatchWithdraw2Callback res_cb,
void *res_cb_cls);
@@ -2468,13 +2869,425 @@ TALER_EXCHANGE_batch_withdraw2_cancel (
struct TALER_EXCHANGE_BatchWithdraw2Handle *wh);
+/* ********************* /reserve/$RESERVE_PUB/age-withdraw *************** */
+
+/**
+ * @brief Information needed to withdraw (and reveal) age restricted coins.
+ */
+struct TALER_EXCHANGE_AgeWithdrawCoinInput
+{
+ /**
+ * The master secret from which we derive all other relevant values for
+ * the coin: private key, nonces (if applicable) and age restriction
+ */
+ struct TALER_PlanchetMasterSecretP secrets[TALER_CNC_KAPPA];
+
+ /**
+ * The denomination of the coin. Must support age restriction, i.e
+ * its .keys.age_mask MUST not be 0
+ */
+ struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+};
+
+
+/**
+ * All the details about a coin that are generated during age-withdrawal and
+ * that may be needed for future operations on the coin.
+ */
+struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails
+{
+ /**
+ * Private key of the coin.
+ */
+ struct TALER_CoinSpendPrivateKeyP coin_priv;
+
+ /**
+ * Hash of the public key of the coin.
+ */
+ struct TALER_CoinPubHashP h_coin_pub;
+
+ /**
+ * Value used to blind the key for the signature.
+ * Needed for recoup operations.
+ */
+ union GNUNET_CRYPTO_BlindingSecretP blinding_key;
+
+ /**
+ * The age commitment, proof for the coin, derived from the
+ * Master secret and maximum age in the originating request
+ */
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+
+ /**
+ * The hash of the age commitment
+ */
+ struct TALER_AgeCommitmentHash h_age_commitment;
+
+ /**
+ * Values contributed from the exchange during the
+ * withdraw protocol.
+ */
+ struct TALER_ExchangeWithdrawValues alg_values;
+
+ /**
+ * The planchet constructed
+ */
+ struct TALER_PlanchetDetail planchet;
+};
+
+/**
+ * @brief A handle to a /reserves/$RESERVE_PUB/age-withdraw request
+ */
+struct TALER_EXCHANGE_AgeWithdrawHandle;
+
+/**
+ * @brief Details about the response for a age withdraw request.
+ */
+struct TALER_EXCHANGE_AgeWithdrawResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details about the response
+ */
+ union
+ {
+ /**
+ * Details if the status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Index that should not be revealed during the age-withdraw reveal
+ * phase.
+ */
+ uint8_t noreveal_index;
+
+ /**
+ * The commitment of the age-withdraw request, needed for the
+ * subsequent call to /age-withdraw/$ACH/reveal
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * The number of elements in @e coins, each referring to
+ * TALER_CNC_KAPPA elements
+ */
+ size_t num_coins;
+
+ /**
+ * The computed details of the non-revealed @e num_coins coins to keep.
+ */
+ const struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails *coin_details;
+
+ /**
+ * The array of blinded hashes of the non-revealed
+ * @e num_coins coins, needed for the reveal step;
+ */
+ const struct TALER_BlindedCoinHashP *blinded_coin_hs;
+
+ /**
+ * Key used by the exchange to sign the response.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ } ok;
+ } details;
+};
+
+
+typedef void
+(*TALER_EXCHANGE_AgeWithdrawCallback)(
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawResponse *awr);
+
+/**
+ * Submit an age-withdraw request to the exchange and get the exchange's
+ * response.
+ *
+ * This API is typically used by a wallet. Note that to ensure that
+ * no money is lost in case of hardware failures, the provided
+ * argument @a rd should be committed to persistent storage
+ * prior to calling this function.
+ *
+ * @param curl_ctx The curl context
+ * @param exchange_url The base url of the exchange
+ * @param keys The denomination keys from the exchange
+ * @param reserve_priv The private key to the reserve
+ * @param num_coins The number of elements in @e coin_inputs
+ * @param coin_inputs The input for the coins to withdraw
+ * @param max_age The maximum age we commit to.
+ * @param res_cb A callback for the result, maybe NULL
+ * @param res_cb_cls A closure for @e res_cb, maybe NULL
+ * @return a handle for this request; NULL if the argument was invalid.
+ * In this case, the callback will not be called.
+ */
+struct TALER_EXCHANGE_AgeWithdrawHandle *
+TALER_EXCHANGE_age_withdraw (
+ struct GNUNET_CURL_Context *curl_ctx,
+ struct TALER_EXCHANGE_Keys *keys,
+ const char *exchange_url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ size_t num_coins,
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[static
+ num_coins],
+ uint8_t max_age,
+ TALER_EXCHANGE_AgeWithdrawCallback res_cb,
+ void *res_cb_cls);
+
+/**
+ * Cancel a age-withdraw request. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param awh the age-withdraw handle
+ */
+void
+TALER_EXCHANGE_age_withdraw_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh);
+
+
+/**++++++ age-withdraw with pre-blinded planchets ***************************/
+
+/**
+ * @brief Information needed to withdraw (and reveal) age restricted coins.
+ */
+struct TALER_EXCHANGE_AgeWithdrawBlindedInput
+{
+ /**
+ * The denomination of the coin. Must support age restriction, i.e
+ * its .keys.age_mask MUST not be 0
+ */
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+
+ /**
+ * Blinded Planchets
+ */
+ struct TALER_PlanchetDetail planchet_details[TALER_CNC_KAPPA];
+};
+
+/**
+ * Response from an age-withdraw request with pre-blinded planchets
+ */
+struct TALER_EXCHANGE_AgeWithdrawBlindedResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Index that should not be revealed during the age-withdraw reveal phase.
+ * The struct TALER_PlanchetMasterSecretP * from the request
+ * with this index are the ones to keep.
+ */
+ uint8_t noreveal_index;
+
+ /**
+ * The commitment of the call to age-withdraw, needed for the subsequent
+ * call to /age-withdraw/$ACH/reveal.
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * Key used by the exchange to sign the response.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+
+ } ok;
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to serve the result of submitting an
+ * age-withdraw request to a exchange with pre-blinded planchets
+ * without the (un)blinding factor.
+ *
+ * @param cls closure
+ * @param awbr response data
+ */
+typedef void
+(*TALER_EXCHANGE_AgeWithdrawBlindedCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawBlindedResponse *awbr);
+
+
+/**
+ * @brief A /reserves/$RESERVE_PUB/age-withdraw Handle, 2nd variant with
+ * pre-blinded planchets.
+ *
+ * This variant does not do the blinding/unblinding and only
+ * fetches the blind signatures on the already blinded planchets.
+ * Used internally by the `struct TALER_EXCHANGE_BatchWithdrawHandle`
+ * implementation as well as for the reward logic of merchants.
+ */
+struct TALER_EXCHANGE_AgeWithdrawBlindedHandle;
+
+/**
+ * Withdraw age-restricted coins from the exchange using a
+ * /reserves/$RESERVE_PUB/age-withdraw request. This API is typically used
+ * by a merchant to withdraw a reward where the planchets are pre-blinded and
+ * the blinding factor is unknown to the merchant.
+ *
+ * Note that to ensure that no money is lost in case of hardware
+ * failures, the caller must have committed (most of) the arguments to
+ * disk before calling, and be ready to repeat the request with the
+ * same arguments in case of failures.
+ *
+ * @param curl_ctx The curl context to use
+ * @param exchange_url The base-URL of the exchange
+ * @param keys The /keys material from the exchange
+ * @param max_age The maximum age that the coins are committed to.
+ * @param num_input number of entries in the @a blinded_input array
+ * @param blinded_input array of planchet details of the planchet to withdraw
+ * @param reserve_priv private key of the reserve to withdraw from
+ * @param res_cb the callback to call when the final result for this request is available
+ * @param res_cb_cls closure for @a res_cb
+ * @return NULL
+ * if the inputs are invalid (i.e. denomination key not with this exchange).
+ * In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *
+TALER_EXCHANGE_age_withdraw_blinded (
+ struct GNUNET_CURL_Context *curl_ctx,
+ struct TALER_EXCHANGE_Keys *keys,
+ const char *exchange_url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ uint8_t max_age,
+ unsigned int num_input,
+ const struct TALER_EXCHANGE_AgeWithdrawBlindedInput blinded_input[static
+ num_input],
+ TALER_EXCHANGE_AgeWithdrawBlindedCallback res_cb,
+ void *res_cb_cls);
+
+
+/**
+ * Cancel an age-withdraw request. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param awbh the age-withdraw handle
+ */
+void
+TALER_EXCHANGE_age_withdraw_blinded_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh);
+
+
+/* ********************* /age-withdraw/$ACH/reveal ************************ */
+
+/**
+ * @brief A handle to a /age-withdraw/$ACH/reveal request
+ */
+struct TALER_EXCHANGE_AgeWithdrawRevealHandle;
+
+/**
+ * The response from a /age-withdraw/$ACH/reveal request
+ */
+struct TALER_EXCHANGE_AgeWithdrawRevealResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details about the response
+ */
+ union
+ {
+ /**
+ * Details if the status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * Number of signatures returned.
+ */
+ unsigned int num_sigs;
+
+ /**
+ * Array of @e num_coins blinded denomination signatures, giving each
+ * coin its value and validity. The array give these coins in the same
+ * order (and should have the same length) in which the original
+ * age-withdraw request specified the respective denomination keys.
+ */
+ const struct TALER_BlindedDenominationSignature *blinded_denom_sigs;
+
+ } ok;
+ } details;
+
+};
+
+typedef void
+(*TALER_EXCHANGE_AgeWithdrawRevealCallback)(
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawRevealResponse *awr);
+
+/**
+ * Submit an age-withdraw-reveal request to the exchange and get the exchange's
+ * response.
+ *
+ * This API is typically used by a wallet. Note that to ensure that
+ * no money is lost in case of hardware failures, the provided
+ * argument @a rd should be committed to persistent storage
+ * prior to calling this function.
+ *
+ * @param curl_ctx The curl context
+ * @param exchange_url The base url of the exchange
+ * @param num_coins The number of elements in @e coin_inputs and @e alg_values
+ * @param coin_inputs The input for the coins to withdraw, same as in the previous call to /age-withdraw
+ * @param noreveal_index The index into each of the kappa coin candidates, that should not be revealed to the exchange
+ * @param h_commitment The commmitment from the previous call to /age-withdraw
+ * @param reserve_pub The public key of the reserve the original call to /age-withdraw was made to
+ * @param res_cb A callback for the result, maybe NULL
+ * @param res_cb_cls A closure for @e res_cb, maybe NULL
+ * @return a handle for this request; NULL if the argument was invalid.
+ * In this case, the callback will not be called.
+ */
+struct TALER_EXCHANGE_AgeWithdrawRevealHandle *
+TALER_EXCHANGE_age_withdraw_reveal (
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ size_t num_coins,
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[static
+ num_coins],
+ uint8_t noreveal_index,
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ TALER_EXCHANGE_AgeWithdrawRevealCallback res_cb,
+ void *res_cb_cls);
+
+
+/**
+ * @brief Cancel an age-withdraw-reveal request
+ *
+ * @param awrh Handle to an age-withdraw-reqveal request
+ */
+void
+TALER_EXCHANGE_age_withdraw_reveal_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh);
+
+
/* ********************* /refresh/melt+reveal ***************************** */
/**
* Information needed to melt (partially spent) coins to obtain fresh coins
* that are unlinkable to the original coin(s). Note that melting more than
- * one coin in a single request will make those coins linkable, so we only melt one coin at a time.
+ * one coin in a single request will make those coins linkable, so we only melt
+ * one coin at a time.
*/
struct TALER_EXCHANGE_RefreshData
{
@@ -2483,11 +3296,16 @@ struct TALER_EXCHANGE_RefreshData
*/
struct TALER_CoinSpendPrivateKeyP melt_priv;
- /*
- * age commitment and proof and its hash that went into the original coin,
+ /**
+ * age commitment and proof that went into the original coin,
* might be NULL.
*/
const struct TALER_AgeCommitmentProof *melt_age_commitment_proof;
+
+ /**
+ * Hash of age commitment and proof that went into the original coin,
+ * might be NULL.
+ */
const struct TALER_AgeCommitmentHash *melt_h_age_commitment;
/**
@@ -2583,7 +3401,7 @@ struct TALER_EXCHANGE_MeltResponse
* Gamma value chosen by the exchange.
*/
uint32_t noreveal_index;
- } success;
+ } ok;
} details;
};
@@ -2613,7 +3431,9 @@ typedef void
* argument @a rd should be committed to persistent storage
* prior to calling this function.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param rms the fresh secret that defines the refresh operation
* @param rd the refresh data specifying the characteristics of the operation
* @param melt_cb the callback to call with the result
@@ -2622,11 +3442,14 @@ typedef void
* In this case, neither callback will be called.
*/
struct TALER_EXCHANGE_MeltHandle *
-TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_RefreshMasterSecretP *rms,
- const struct TALER_EXCHANGE_RefreshData *rd,
- TALER_EXCHANGE_MeltCallback melt_cb,
- void *melt_cb_cls);
+TALER_EXCHANGE_melt (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_RefreshMasterSecretP *rms,
+ const struct TALER_EXCHANGE_RefreshData *rd,
+ TALER_EXCHANGE_MeltCallback melt_cb,
+ void *melt_cb_cls);
/**
@@ -2661,12 +3484,12 @@ struct TALER_EXCHANGE_RevealedCoinInfo
* Age commitment and its hash of the coin, might be NULL.
*/
struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Blinding keys used to blind the fresh coin.
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
/**
* Signature affirming the validity of the coin.
@@ -2709,7 +3532,7 @@ struct TALER_EXCHANGE_RevealResult
* Number of coins returned.
*/
unsigned int num_coins;
- } success;
+ } ok;
} details;
@@ -2746,7 +3569,8 @@ struct TALER_EXCHANGE_RefreshesRevealHandle;
* arguments should have been committed to persistent storage
* prior to calling this function.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
* @param rms the fresh secret that defines the refresh operation
* @param rd the refresh data that characterizes the refresh operation
* @param num_coins number of fresh coins to be created, length of the @a exchange_vals array, must match value in @a rd
@@ -2761,11 +3585,12 @@ struct TALER_EXCHANGE_RefreshesRevealHandle;
*/
struct TALER_EXCHANGE_RefreshesRevealHandle *
TALER_EXCHANGE_refreshes_reveal (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_RefreshMasterSecretP *rms,
const struct TALER_EXCHANGE_RefreshData *rd,
unsigned int num_coins,
- const struct TALER_ExchangeWithdrawValues *alg_values,
+ const struct TALER_ExchangeWithdrawValues alg_values[static num_coins],
uint32_t noreveal_index,
TALER_EXCHANGE_RefreshesRevealCallback reveal_cb,
void *reveal_cb_cls);
@@ -2802,10 +3627,11 @@ struct TALER_EXCHANGE_LinkedCoinInfo
struct TALER_CoinSpendPrivateKeyP coin_priv;
/**
- * Age commitment and its hash, if applicable. Might be NULL.
+ * Age commitment and its hash, if applicable.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ bool has_age_commitment;
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Master secret of this coin.
@@ -2855,7 +3681,7 @@ struct TALER_EXCHANGE_LinkResult
* Number of coins returned.
*/
unsigned int num_coins;
- } success;
+ } ok;
} details;
@@ -2883,7 +3709,8 @@ typedef void
* This API is typically not used by anyone, it is more a threat against those
* trying to receive a funds transfer by abusing the refresh protocol.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx CURL context
+ * @param url exchange base URL
* @param coin_priv private key to request link data for
* @param age_commitment_proof age commitment to the corresponding coin, might be NULL
* @param link_cb the callback to call with the useful result of the
@@ -2893,7 +3720,8 @@ typedef void
*/
struct TALER_EXCHANGE_LinkHandle *
TALER_EXCHANGE_link (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
const struct TALER_AgeCommitmentProof *age_commitment_proof,
TALER_EXCHANGE_LinkCallback link_cb,
@@ -2968,25 +3796,52 @@ struct TALER_EXCHANGE_TransferData
/**
+ * Response for a GET /transfers request.
+ */
+struct TALER_EXCHANGE_TransfersGetResponse
+{
+ /**
+ * HTTP response.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on HTTP status code.
+ */
+ union
+ {
+ /**
+ * Details if status code is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ struct TALER_EXCHANGE_TransferData td;
+ } ok;
+
+ } details;
+};
+
+
+/**
* Function called with detailed wire transfer data, including all
* of the coin transactions that were combined into the wire transfer.
*
* @param cls closure
- * @param hr HTTP response data
- * @param ta transfer data, (set only if @a http_status is #MHD_HTTP_OK, otherwise NULL)
+ * @param tgr response data
*/
typedef void
(*TALER_EXCHANGE_TransfersGetCallback)(
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_TransferData *ta);
+ const struct TALER_EXCHANGE_TransfersGetResponse *tgr);
/**
* Query the exchange about which transactions were combined
* to create a wire transfer.
*
- * @param exchange exchange to query
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param wtid raw wire transfer identifier to get information about
* @param cb callback to call
* @param cb_cls closure for @a cb
@@ -2994,7 +3849,9 @@ typedef void
*/
struct TALER_EXCHANGE_TransfersGetHandle *
TALER_EXCHANGE_transfers_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_WireTransferIdentifierRawP *wtid,
TALER_EXCHANGE_TransfersGetCallback cb,
void *cb_cls);
@@ -3071,12 +3928,7 @@ struct TALER_EXCHANGE_GetDepositResponse
*/
struct TALER_Amount coin_contribution;
- /**
- * Payment target that the merchant should use
- * to check for its KYC status.
- */
- uint64_t payment_target_uuid;
- } success;
+ } ok;
/**
* Response if the status was #MHD_HTTP_ACCEPTED
@@ -3090,10 +3942,16 @@ struct TALER_EXCHANGE_GetDepositResponse
struct GNUNET_TIME_Timestamp execution_time;
/**
- * Payment target that the merchant should use
- * to check for its KYC status.
+ * KYC legitimization requirement that the merchant should use to check
+ * for its KYC status.
*/
- uint64_t payment_target_uuid;
+ uint64_t requirement_row;
+
+ /**
+ * Current AML state for the account. May explain why transfers are
+ * not happening.
+ */
+ enum TALER_AmlDecisionState aml_decision;
/**
* Set to 'true' if the KYC check is already finished and
@@ -3123,22 +3981,28 @@ typedef void
* which aggregate wire transfer the deposit operation identified by @a coin_pub,
* @a merchant_priv and @a h_contract_terms contributed to.
*
- * @param exchange the exchange to query
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param merchant_priv the merchant's private key
* @param h_wire hash of merchant's wire transfer details
* @param h_contract_terms hash of the proposal data
* @param coin_pub public key of the coin
+ * @param timeout timeout to use for long-polling, 0 for no long polling
* @param cb function to call with the result
* @param cb_cls closure for @a cb
* @return handle to abort request
*/
struct TALER_EXCHANGE_DepositGetHandle *
TALER_EXCHANGE_deposits_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_MerchantPrivateKeyP *merchant_priv,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_DepositGetCallback cb,
void *cb_cls);
@@ -3154,72 +4018,44 @@ TALER_EXCHANGE_deposits_get_cancel (
struct TALER_EXCHANGE_DepositGetHandle *dwh);
-/**
- * Convenience function. Verifies a coin's transaction history as
- * returned by the exchange.
- *
- * @param dk fee structure for the coin
- * @param coin_pub public key of the coin
- * @param history history of the coin in json encoding
- * @param[out] total how much of the coin has been spent according to @a history
- * @return #GNUNET_OK if @a history is valid, #GNUNET_SYSERR if not
- */
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_verify_coin_history (
- const struct TALER_EXCHANGE_DenomPublicKey *dk,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- json_t *history,
- struct TALER_Amount *total);
+/* ********************* /recoup *********************** */
/**
- * Parse history given in JSON format and return it in binary
- * format.
- *
- * @param exchange connection to the exchange we can use
- * @param history JSON array with the history
- * @param reserve_pub public key of the reserve to inspect
- * @param currency currency we expect the balance to be in
- * @param[out] total_in set to value of credits to reserve
- * @param[out] total_out set to value of debits from reserve
- * @param history_length number of entries in @a history
- * @param[out] rhistory array of length @a history_length, set to the
- * parsed history entries
- * @return #GNUNET_OK if history was valid and @a rhistory and @a balance
- * were set,
- * #GNUNET_SYSERR if there was a protocol violation in @a history
+ * @brief A /recoup Handle
*/
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_parse_reserve_history (
- struct TALER_EXCHANGE_Handle *exchange,
- const json_t *history,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const char *currency,
- struct TALER_Amount *total_in,
- struct TALER_Amount *total_out,
- unsigned int history_length,
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory);
+struct TALER_EXCHANGE_RecoupHandle;
/**
- * Free memory (potentially) allocated by #TALER_EXCHANGE_parse_reserve_history().
- *
- * @param rhistory result to free
- * @param len number of entries in @a rhistory
+ * Response from a recoup request.
*/
-void
-TALER_EXCHANGE_free_reserve_history (
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory,
- unsigned int len);
-
+struct TALER_EXCHANGE_RecoupResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
-/* ********************* /recoup *********************** */
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * public key of the reserve receiving the recoup
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+ } ok;
+ } details;
-/**
- * @brief A /recoup Handle
- */
-struct TALER_EXCHANGE_RecoupHandle;
+};
/**
@@ -3229,14 +4065,12 @@ struct TALER_EXCHANGE_RecoupHandle;
* reserve that was credited.
*
* @param cls closure
- * @param hr HTTP response data
- * @param reserve_pub public key of the reserve receiving the recoup
+ * @param rr response data
*/
typedef void
(*TALER_EXCHANGE_RecoupResultCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_ReservePublicKeyP *reserve_pub);
+ const struct TALER_EXCHANGE_RecoupResponse *rr);
/**
@@ -3244,7 +4078,9 @@ typedef void
* the emergency recoup protocol for a given denomination. The value
* of the coin will be refunded to the original customer (without fees).
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param pk kind of coin to pay back
* @param denom_sig signature over the coin by the exchange using @a pk
* @param exchange_vals contribution from the exchange on the withdraw
@@ -3256,13 +4092,16 @@ typedef void
* In this case, the callback is not called.
*/
struct TALER_EXCHANGE_RecoupHandle *
-TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DenomPublicKey *pk,
- const struct TALER_DenominationSignature *denom_sig,
- const struct TALER_ExchangeWithdrawValues *exchange_vals,
- const struct TALER_PlanchetMasterSecretP *ps,
- TALER_EXCHANGE_RecoupResultCallback recoup_cb,
- void *recoup_cb_cls);
+TALER_EXCHANGE_recoup (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_EXCHANGE_DenomPublicKey *pk,
+ const struct TALER_DenominationSignature *denom_sig,
+ const struct TALER_ExchangeWithdrawValues *exchange_vals,
+ const struct TALER_PlanchetMasterSecretP *ps,
+ TALER_EXCHANGE_RecoupResultCallback recoup_cb,
+ void *recoup_cb_cls);
/**
@@ -3285,18 +4124,47 @@ struct TALER_EXCHANGE_RecoupRefreshHandle;
/**
+ * Response from a /recoup-refresh request.
+ */
+struct TALER_EXCHANGE_RecoupRefreshResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * public key of the dirty coin that was credited
+ */
+ struct TALER_CoinSpendPublicKeyP old_coin_pub;
+
+ } ok;
+ } details;
+
+};
+
+
+/**
* Callbacks of this type are used to return the final result of
* submitting a recoup-refresh request to a exchange.
*
* @param cls closure
- * @param hr HTTP response data
- * @param old_coin_pub public key of the dirty coin that was credited
+ * @param rrr response data
*/
typedef void
(*TALER_EXCHANGE_RecoupRefreshResultCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub);
+ const struct TALER_EXCHANGE_RecoupRefreshResponse *rrr);
/**
@@ -3306,7 +4174,9 @@ typedef void
* revoked coin was refreshed from. The original coin is then
* considered a zombie.
*
- * @param exchange the exchange handle; the exchange must be ready to operate
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param pk kind of coin to pay back
* @param denom_sig signature over the coin by the exchange using @a pk
* @param exchange_vals contribution from the exchange on the withdraw
@@ -3321,7 +4191,9 @@ typedef void
*/
struct TALER_EXCHANGE_RecoupRefreshHandle *
TALER_EXCHANGE_recoup_refresh (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_EXCHANGE_DenomPublicKey *pk,
const struct TALER_DenominationSignature *denom_sig,
const struct TALER_ExchangeWithdrawValues *exchange_vals,
@@ -3376,6 +4248,11 @@ struct TALER_EXCHANGE_KycStatus
{
/**
+ * Details about which KYC check(s) were passed.
+ */
+ const json_t *kyc_details;
+
+ /**
* Time of the affirmation.
*/
struct GNUNET_TIME_Timestamp timestamp;
@@ -3392,14 +4269,45 @@ struct TALER_EXCHANGE_KycStatus
*/
struct TALER_ExchangeSignatureP exchange_sig;
- } kyc_ok;
+ /**
+ * AML status for the account.
+ */
+ enum TALER_AmlDecisionState aml_status;
+
+ } ok;
/**
- * URL the user should open in a browser if
- * the KYC process is to be run. Returned if
- * @e http_status is #MHD_HTTP_ACCEPTED.
+ * KYC is required.
*/
- const char *kyc_url;
+ struct
+ {
+
+ /**
+ * URL the user should open in a browser if
+ * the KYC process is to be run. Returned if
+ * @e http_status is #MHD_HTTP_ACCEPTED.
+ */
+ const char *kyc_url;
+
+ /**
+ * AML status for the account.
+ */
+ enum TALER_AmlDecisionState aml_status;
+
+ } accepted;
+
+ /**
+ * KYC is OK, but account needs positive AML decision.
+ */
+ struct
+ {
+
+ /**
+ * AML status for the account.
+ */
+ enum TALER_AmlDecisionState aml_status;
+
+ } unavailable_for_legal_reasons;
} details;
@@ -3421,21 +4329,28 @@ typedef void
* Run interaction with exchange to check KYC status
* of a merchant.
*
- * @param eh exchange handle to use
- * @param payment_target number identifying the target
+ * @param ctx CURL context
+ * @param url exchange base URL
+ * @param keys keys of the exchange
+ * @param requirement_row number identifying the KYC requirement
* @param h_payto hash of the payto:// URI at @a payment_target
+ * @param ut type of the entity performing the KYC check
* @param timeout how long to wait for a positive KYC status
* @param cb function to call with the result
* @param cb_cls closure for @a cb
* @return NULL on error
*/
struct TALER_EXCHANGE_KycCheckHandle *
-TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *eh,
- uint64_t payment_target,
- const struct TALER_PaytoHashP *h_payto,
- struct GNUNET_TIME_Relative timeout,
- TALER_EXCHANGE_KycStatusCallback cb,
- void *cb_cls);
+TALER_EXCHANGE_kyc_check (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ uint64_t requirement_row,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_KYCLOGIC_KycUserType ut,
+ struct GNUNET_TIME_Relative timeout,
+ TALER_EXCHANGE_KycStatusCallback cb,
+ void *cb_cls);
/**
@@ -3498,21 +4413,25 @@ struct TALER_EXCHANGE_KycProofHandle;
/**
* Run interaction with exchange to provide proof of KYC status.
*
- * @param eh exchange handle to use
+ * @param ctx CURL context
+ * @param url exchange base URL
* @param h_payto hash of payto URI identifying the target account
- * @param code OAuth 2.0 code argument
- * @param state OAuth 2.0 state argument
+ * @param logic name of the KYC logic to run
+ * @param args additional args to pass, can be NULL
+ * or a string to append to the URL. Must then begin with '&'.
* @param cb function to call with the result
* @param cb_cls closure for @a cb
* @return NULL on error
*/
struct TALER_EXCHANGE_KycProofHandle *
-TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *eh,
- const struct TALER_PaytoHashP *h_payto,
- const char *code,
- const char *state,
- TALER_EXCHANGE_KycProofCallback cb,
- void *cb_cls);
+TALER_EXCHANGE_kyc_proof (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *logic,
+ const char *args,
+ TALER_EXCHANGE_KycProofCallback cb,
+ void *cb_cls);
/**
@@ -3547,10 +4466,29 @@ struct TALER_EXCHANGE_WalletKycResponse
enum TALER_ErrorCode ec;
/**
- * Wallet's payment target UUID. Only valid if
- * @e http_status is #MHD_HTTP_OK
+ * Variants depending on @e http_status.
*/
- uint64_t payment_target_uuid;
+ union
+ {
+
+ /**
+ * In case @e http_status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
+ */
+ struct
+ {
+ /**
+ * Wallet's KYC requirement row.
+ */
+ uint64_t requirement_row;
+
+ /**
+ * Hash of the payto-URI identifying the wallet to KYC.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ } unavailable_for_legal_reasons;
+
+ } details;
};
@@ -3571,17 +4509,22 @@ typedef void
* Run interaction with exchange to find out the wallet's KYC
* identifier.
*
- * @param eh exchange handle to use
+ * @param ctx CURL context
+ * @param url exchange base URL
* @param reserve_priv wallet private key to check
+ * @param balance balance (or balance threshold) crossed by the wallet
* @param cb function to call with the result
* @param cb_cls closure for @a cb
* @return NULL on error
*/
struct TALER_EXCHANGE_KycWalletHandle *
-TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *eh,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_KycWalletCallback cb,
- void *cb_cls);
+TALER_EXCHANGE_kyc_wallet (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *balance,
+ TALER_EXCHANGE_KycWalletCallback cb,
+ void *cb_cls);
/**
@@ -3746,18 +4689,47 @@ struct TALER_EXCHANGE_FutureKeys
/**
+ * Response from a /management/keys request.
+ */
+struct TALER_EXCHANGE_ManagementGetKeysResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Response details depending on the HTTP status.
+ */
+ union
+ {
+ /**
+ * Details if HTTP status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * information about the various keys used
+ * by the exchange
+ */
+ struct TALER_EXCHANGE_FutureKeys keys;
+
+ } ok;
+ } details;
+
+};
+
+
+/**
* Function called with information about future keys.
*
* @param cls closure
- * @param hr HTTP response data
- * @param keys information about the various keys used
- * by the exchange, NULL if /management/keys failed
+ * @param mgr HTTP response data
*/
typedef void
(*TALER_EXCHANGE_ManagementGetKeysCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_FutureKeys *keys);
+ const struct TALER_EXCHANGE_ManagementGetKeysResponse *mgr);
/**
@@ -3777,10 +4749,11 @@ struct TALER_EXCHANGE_ManagementGetKeysHandle;
* @return the request handle; NULL upon error
*/
struct TALER_EXCHANGE_ManagementGetKeysHandle *
-TALER_EXCHANGE_get_management_keys (struct GNUNET_CURL_Context *ctx,
- const char *url,
- TALER_EXCHANGE_ManagementGetKeysCallback cb,
- void *cb_cls);
+TALER_EXCHANGE_get_management_keys (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ TALER_EXCHANGE_ManagementGetKeysCallback cb,
+ void *cb_cls);
/**
@@ -3860,15 +4833,28 @@ struct TALER_EXCHANGE_ManagementPostKeysData
/**
+ * Response from a POST /management/keys request.
+ */
+struct TALER_EXCHANGE_ManagementPostKeysResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+
+/**
* Function called with information about the post keys operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param mr response data
*/
typedef void
(*TALER_EXCHANGE_ManagementPostKeysCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementPostKeysResponse *mr);
/**
@@ -3914,10 +4900,24 @@ TALER_EXCHANGE_post_management_keys_cancel (
*/
struct TALER_EXCHANGE_ManagementPostExtensionsData
{
- json_t *extensions;
+ const json_t *extensions;
struct TALER_MasterSignatureP extensions_sig;
};
+
+/**
+ * Response from a POST /management/extensions request.
+ */
+struct TALER_EXCHANGE_ManagementPostExtensionsResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+
/**
* Function called with information about the post extensions operation result.
*
@@ -3927,7 +4927,7 @@ struct TALER_EXCHANGE_ManagementPostExtensionsData
typedef void
(*TALER_EXCHANGE_ManagementPostExtensionsCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementPostExtensionsResponse *hr);
/**
* @brief Handle for a POST /management/extensions request.
@@ -3950,7 +4950,7 @@ struct TALER_EXCHANGE_ManagementPostExtensionsHandle *
TALER_EXCHANGE_management_post_extensions (
struct GNUNET_CURL_Context *ctx,
const char *url,
- struct TALER_EXCHANGE_ManagementPostExtensionsData *ped,
+ const struct TALER_EXCHANGE_ManagementPostExtensionsData *ped,
TALER_EXCHANGE_ManagementPostExtensionsCallback cb,
void *cb_cls);
@@ -3966,6 +4966,89 @@ TALER_EXCHANGE_management_post_extensions_cancel (
/**
+ * Response from a POST /management/drain request.
+ */
+struct TALER_EXCHANGE_ManagementDrainResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+
+/**
+ * Function called with information about the drain profits result.
+ *
+ * @param cls closure
+ * @param hr HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ManagementDrainProfitsCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementDrainResponse *hr);
+
+
+/**
+ * @brief Handle for a POST /management/drain request.
+ */
+struct TALER_EXCHANGE_ManagementDrainProfitsHandle;
+
+
+/**
+ * Uploads the drain profits request.
+ *
+ * @param ctx the context
+ * @param url HTTP base URL for the exchange
+ * @param wtid wire transfer identifier to use
+ * @param amount total to transfer
+ * @param date when was the request created
+ * @param account_section configuration section identifying account to debit
+ * @param payto_uri RFC 8905 URI of the account to credit
+ * @param master_sig signature affirming the operation
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_ManagementDrainProfitsHandle *
+TALER_EXCHANGE_management_drain_profits (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Timestamp date,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementDrainProfitsCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_management_drain_profits() operation.
+ *
+ * @param dp handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_management_drain_profits_cancel (
+ struct TALER_EXCHANGE_ManagementDrainProfitsHandle *dp);
+
+
+/**
+ * Response from a POST /management/denominations/$DENOM/revoke request.
+ */
+struct TALER_EXCHANGE_ManagementRevokeDenominationResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+
+/**
* Function called with information about the post revocation operation result.
*
* @param cls closure
@@ -3974,7 +5057,7 @@ TALER_EXCHANGE_management_post_extensions_cancel (
typedef void
(*TALER_EXCHANGE_ManagementRevokeDenominationKeyCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementRevokeDenominationResponse *hr);
/**
@@ -4015,6 +5098,18 @@ TALER_EXCHANGE_management_revoke_denomination_key_cancel (
/**
+ * Response from a POST /management/signkeys/$SK/revoke request.
+ */
+struct TALER_EXCHANGE_ManagementRevokeSigningKeyResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+/**
* Function called with information about the post revocation operation result.
*
* @param cls closure
@@ -4023,7 +5118,7 @@ TALER_EXCHANGE_management_revoke_denomination_key_cancel (
typedef void
(*TALER_EXCHANGE_ManagementRevokeSigningKeyCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementRevokeSigningKeyResponse *hr);
/**
@@ -4064,15 +5159,515 @@ TALER_EXCHANGE_management_revoke_signing_key_cancel (
/**
- * Function called with information about the auditor setup operation result.
+ * Response from a POST /management/aml-officers request.
+ */
+struct TALER_EXCHANGE_ManagementUpdateAmlOfficerResponse
+{
+ /**
+ * HTTP response data
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+};
+
+/**
+ * Function called with information about the change to
+ * an AML officer status.
*
* @param cls closure
* @param hr HTTP response data
*/
typedef void
+(*TALER_EXCHANGE_ManagementUpdateAmlOfficerCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementUpdateAmlOfficerResponse *hr);
+
+
+/**
+ * @brief Handle for a POST /management/aml-officers/$OFFICER_PUB request.
+ */
+struct TALER_EXCHANGE_ManagementUpdateAmlOfficer;
+
+
+/**
+ * Inform the exchange that the status of an AML officer has changed.
+ *
+ * @param ctx the context
+ * @param url HTTP base URL for the exchange
+ * @param officer_pub the public signing key of the officer
+ * @param officer_name name of the officer
+ * @param change_date when to affect the status change
+ * @param is_active true to enable the officer
+ * @param read_only true to only allow read-only access
+ * @param master_sig signature affirming the change
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *
+TALER_EXCHANGE_management_update_aml_officer (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementUpdateAmlOfficerCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_management_update_aml_officer() operation.
+ *
+ * @param rh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_management_update_aml_officer_cancel (
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *rh);
+
+
+/**
+ * Summary data about an AML decision.
+ */
+struct TALER_EXCHANGE_AmlDecisionSummary
+{
+ /**
+ * What is the current monthly threshold.
+ */
+ struct TALER_Amount threshold;
+
+ /**
+ * Account the decision was made for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * RowID of this decision.
+ */
+ uint64_t rowid;
+
+ /**
+ * Current decision state.
+ */
+ enum TALER_AmlDecisionState current_state;
+};
+
+
+/**
+ * Information about AML decisions returned by the exchange.
+ */
+struct TALER_EXCHANGE_AmlDecisionsResponse
+{
+ /**
+ * HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on the HTTP response code.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success (#MHD_HTTP_OK).
+ */
+ struct
+ {
+
+ /**
+ * Array of AML decision summaries returned by the exchange.
+ */
+ const struct TALER_EXCHANGE_AmlDecisionSummary *decisions;
+
+ /**
+ * Length of the @e decisions array.
+ */
+ unsigned int decisions_length;
+
+ } ok;
+
+ } details;
+};
+
+
+/**
+ * Function called with summary information about
+ * AML decisions.
+ *
+ * @param cls closure
+ * @param adr response data
+ */
+typedef void
+(*TALER_EXCHANGE_LookupAmlDecisionsCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_AmlDecisionsResponse *adr);
+
+
+/**
+ * @brief Handle for a POST /aml/$OFFICER_PUB/decisions/$STATUS request.
+ */
+struct TALER_EXCHANGE_LookupAmlDecisions;
+
+
+/**
+ * Inform the exchange that an AML decision has been taken.
+ *
+ * @param ctx the context
+ * @param exchange_url HTTP base URL for the exchange
+ * @param start row number starting point (exclusive rowid)
+ * @param delta number of records to return, negative for descending, positive for ascending from start
+ * @param state type of AML decisions to return
+ * @param officer_priv private key of the deciding AML officer
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_LookupAmlDecisions *
+TALER_EXCHANGE_lookup_aml_decisions (
+ struct GNUNET_CURL_Context *ctx,
+ const char *exchange_url,
+ uint64_t start,
+ int delta,
+ enum TALER_AmlDecisionState state,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ TALER_EXCHANGE_LookupAmlDecisionsCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_lookup_aml_decisions() operation.
+ *
+ * @param lh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_lookup_aml_decisions_cancel (
+ struct TALER_EXCHANGE_LookupAmlDecisions *lh);
+
+
+/**
+ * Detailed data about an AML decision.
+ */
+struct TALER_EXCHANGE_AmlDecisionDetail
+{
+ /**
+ * When was the decision made.
+ */
+ struct GNUNET_TIME_Timestamp decision_time;
+
+ /**
+ * New threshold set by this decision.
+ */
+ struct TALER_Amount new_threshold;
+
+ /**
+ * Who made the decision?
+ */
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+
+ /**
+ * Justification given for the decision.
+ */
+ const char *justification;
+
+ /**
+ * New decision state.
+ */
+ enum TALER_AmlDecisionState new_state;
+};
+
+
+/**
+ * Detailed data collected during a KYC process for the account.
+ */
+struct TALER_EXCHANGE_KycHistoryDetail
+{
+ /**
+ * Configuration section name of the KYC provider that contributed the data.
+ */
+ const char *provider_section;
+
+ /**
+ * The collected KYC data.
+ */
+ const json_t *attributes;
+
+ /**
+ * When was the data collection made.
+ */
+ struct GNUNET_TIME_Timestamp collection_time;
+
+};
+
+
+/**
+ * Information about AML decision details returned by the exchange.
+ */
+struct TALER_EXCHANGE_AmlDecisionResponse
+{
+ /**
+ * HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on the HTTP response code.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success (#MHD_HTTP_OK).
+ */
+ struct
+ {
+
+ /**
+ * Array of AML decision details returned by the exchange.
+ */
+ const struct TALER_EXCHANGE_AmlDecisionDetail *aml_history;
+
+ /**
+ * Length of the @e aml_history array.
+ */
+ unsigned int aml_history_length;
+
+ /**
+ * Array of KYC data collections returned by the exchange.
+ */
+ const struct TALER_EXCHANGE_KycHistoryDetail *kyc_attributes;
+
+ /**
+ * Length of the @e kyc_attributes array.
+ */
+ unsigned int kyc_attributes_length;
+
+ } ok;
+
+ } details;
+};
+
+
+/**
+ * Function called with summary information about
+ * AML decisions.
+ *
+ * @param cls closure
+ * @param adr response data
+ */
+typedef void
+(*TALER_EXCHANGE_LookupAmlDecisionCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_AmlDecisionResponse *adr);
+
+
+/**
+ * @brief Handle for a POST /aml/$OFFICER_PUB/decision/$H_PAYTO request.
+ */
+struct TALER_EXCHANGE_LookupAmlDecision;
+
+
+/**
+ * Inform the exchange that an AML decision has been taken.
+ *
+ * @param ctx the context
+ * @param exchange_url HTTP base URL for the exchange
+ * @param h_payto which account to return the decision history for
+ * @param officer_priv private key of the deciding AML officer
+ * @param history true to return the full history, otherwise only the last decision
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_LookupAmlDecision *
+TALER_EXCHANGE_lookup_aml_decision (
+ struct GNUNET_CURL_Context *ctx,
+ const char *exchange_url,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ bool history,
+ TALER_EXCHANGE_LookupAmlDecisionCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_lookup_aml_decision() operation.
+ *
+ * @param rh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_lookup_aml_decision_cancel (
+ struct TALER_EXCHANGE_LookupAmlDecision *rh);
+
+
+/**
+ * @brief Handle for a POST /aml-decision/$OFFICER_PUB request.
+ */
+struct TALER_EXCHANGE_AddAmlDecision;
+
+
+/**
+ * Response when making an AML decision.
+ */
+struct TALER_EXCHANGE_AddAmlDecisionResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+
+/**
+ * Function called with information about storing an
+ * an AML decision.
+ *
+ * @param cls closure
+ * @param adr response data
+ */
+typedef void
+(*TALER_EXCHANGE_AddAmlDecisionCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_AddAmlDecisionResponse *adr);
+
+/**
+ * Inform the exchange that an AML decision has been taken.
+ *
+ * @param ctx the context
+ * @param url HTTP base URL for the exchange
+ * @param justification human-readable justification
+ * @param decision_time when was the decision made
+ * @param new_threshold at what monthly amount threshold
+ * should a revision be triggered
+ * @param h_payto payto URI hash of the account the
+ * decision is about
+ * @param new_state updated AML state
+ * @param kyc_requirements JSON array of KYC requirements being imposed, NULL for none
+ * @param officer_priv private key of the deciding AML officer
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_AddAmlDecision *
+TALER_EXCHANGE_add_aml_decision (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ TALER_EXCHANGE_AddAmlDecisionCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_add_aml_decision() operation.
+ *
+ * @param rh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_add_aml_decision_cancel (
+ struct TALER_EXCHANGE_AddAmlDecision *rh);
+
+
+/**
+ * Response when adding a partner exchange.
+ */
+struct TALER_EXCHANGE_ManagementAddPartnerResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+/**
+ * Function called with information about the change to
+ * an AML officer status.
+ *
+ * @param cls closure
+ * @param apr response data
+ */
+typedef void
+(*TALER_EXCHANGE_ManagementAddPartnerCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementAddPartnerResponse *apr);
+
+
+/**
+ * @brief Handle for a POST /management/partners/$PARTNER_PUB request.
+ */
+struct TALER_EXCHANGE_ManagementAddPartner;
+
+
+/**
+ * Inform the exchange that the status of a partnering
+ * exchange was defined.
+ *
+ * @param ctx the context
+ * @param url HTTP base URL for the exchange
+ * @param partner_pub the offline signing key of the partner
+ * @param start_date validity period start
+ * @param end_date validity period end
+ * @param wad_frequency how often will we do wad transfers to this partner
+ * @param wad_fee what is the wad fee to this partner
+ * @param partner_base_url what is the base URL of the @a partner_pub exchange
+ * @param master_sig the signature the signature
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_ManagementAddPartner *
+TALER_EXCHANGE_management_add_partner (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_MasterPublicKeyP *partner_pub,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ struct GNUNET_TIME_Relative wad_frequency,
+ const struct TALER_Amount *wad_fee,
+ const char *partner_base_url,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementAddPartnerCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_management_add_partner() operation.
+ *
+ * @param rh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_management_add_partner_cancel (
+ struct TALER_EXCHANGE_ManagementAddPartner *rh);
+
+
+/**
+ * Response when enabling an auditor.
+ */
+struct TALER_EXCHANGE_ManagementAuditorEnableResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+/**
+ * Function called with information about the auditor setup operation result.
+ *
+ * @param cls closure
+ * @param aer response data
+ */
+typedef void
(*TALER_EXCHANGE_ManagementAuditorEnableCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *aer);
/**
@@ -4117,17 +5712,27 @@ void
TALER_EXCHANGE_management_enable_auditor_cancel (
struct TALER_EXCHANGE_ManagementAuditorEnableHandle *ah);
+/**
+ * Response when disabling an auditor.
+ */
+struct TALER_EXCHANGE_ManagementAuditorDisableResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
/**
* Function called with information about the auditor disable operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param adr HTTP response data
*/
typedef void
(*TALER_EXCHANGE_ManagementAuditorDisableCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementAuditorDisableResponse *adr);
/**
@@ -4170,15 +5775,27 @@ TALER_EXCHANGE_management_disable_auditor_cancel (
/**
+ * Response from an exchange account/enable operation.
+ */
+struct TALER_EXCHANGE_ManagementWireEnableResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+
+/**
* Function called with information about the wire enable operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param wer HTTP response data
*/
typedef void
(*TALER_EXCHANGE_ManagementWireEnableCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementWireEnableResponse *wer);
/**
@@ -4193,11 +5810,16 @@ struct TALER_EXCHANGE_ManagementWireEnableHandle;
* @param ctx the context
* @param url HTTP base URL for the exchange
* @param payto_uri RFC 8905 URI of the exchange's bank account
+ * @param conversion_url URL of the conversion service, or NULL if none
+ * @param debit_restrictions JSON encoding of debit restrictions on the account; see AccountRestriction in the spec
+ * @param credit_restrictions JSON encoding of credit restrictions on the account; see AccountRestriction in the spec
* @param validity_start when was this decided?
* @param master_sig1 signature affirming the wire addition
* of purpose #TALER_SIGNATURE_MASTER_ADD_WIRE
* @param master_sig2 signature affirming the validity of the account for clients;
* of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS.
+ * @param bank_label label to use when showing the account, can be NULL
+ * @param priority priority for ordering the bank accounts
* @param cb function to call with the exchange's result
* @param cb_cls closure for @a cb
* @return the request handle; NULL upon error
@@ -4207,9 +5829,14 @@ TALER_EXCHANGE_management_enable_wire (
struct GNUNET_CURL_Context *ctx,
const char *url,
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp validity_start,
const struct TALER_MasterSignatureP *master_sig1,
const struct TALER_MasterSignatureP *master_sig2,
+ const char *bank_label,
+ int64_t priority,
TALER_EXCHANGE_ManagementWireEnableCallback cb,
void *cb_cls);
@@ -4225,15 +5852,26 @@ TALER_EXCHANGE_management_enable_wire_cancel (
/**
+ * Response from an exchange account/disable operation.
+ */
+struct TALER_EXCHANGE_ManagementWireDisableResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+/**
* Function called with information about the wire disable operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param wdr response data
*/
typedef void
(*TALER_EXCHANGE_ManagementWireDisableCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementWireDisableResponse *wdr);
/**
@@ -4277,15 +5915,26 @@ TALER_EXCHANGE_management_disable_wire_cancel (
/**
+ * Response when setting wire fees.
+ */
+struct TALER_EXCHANGE_ManagementSetWireFeeResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+/**
* Function called with information about the wire enable operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param wfr response data
*/
typedef void
(*TALER_EXCHANGE_ManagementSetWireFeeCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *wfr);
/**
@@ -4333,15 +5982,27 @@ TALER_EXCHANGE_management_set_wire_fees_cancel (
/**
+ * Response when setting global fees.
+ */
+struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+
+/**
* Function called with information about the global fee setting operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param gfr HTTP response data
*/
typedef void
(*TALER_EXCHANGE_ManagementSetGlobalFeeCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse *gfr);
/**
@@ -4359,7 +6020,6 @@ struct TALER_EXCHANGE_ManagementSetGlobalFeeHandle;
* @param validity_end end date for the provided wire fees
* @param fees the wire fees for this time period
* @param purse_timeout when do purses time out
- * @param kyc_timeout when do reserves without KYC time out
* @param history_expiration how long are account histories preserved
* @param purse_account_limit how many purses are free per account
* @param master_sig signature affirming the wire fees;
@@ -4376,7 +6036,6 @@ TALER_EXCHANGE_management_set_global_fees (
struct GNUNET_TIME_Timestamp validity_end,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterSignatureP *master_sig,
@@ -4395,16 +6054,28 @@ TALER_EXCHANGE_management_set_global_fees_cancel (
/**
+ * Response when adding denomination signature by auditor.
+ */
+struct TALER_EXCHANGE_AuditorAddDenominationResponse
+{
+ /**
+ * HTTP response data.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+
+/**
* Function called with information about the POST
* /auditor/$AUDITOR_PUB/$H_DENOM_PUB operation result.
*
* @param cls closure
- * @param hr HTTP response data
+ * @param adr HTTP response data
*/
typedef void
(*TALER_EXCHANGE_AuditorAddDenominationCallback) (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr);
+ const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr);
/**
@@ -4486,7 +6157,7 @@ struct TALER_EXCHANGE_ContractGetResponse
*/
size_t econtract_size;
- } success;
+ } ok;
} details;
@@ -4513,7 +6184,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
@@ -4521,7 +6193,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);
@@ -4557,6 +6230,7 @@ struct TALER_EXCHANGE_PurseGetResponse
*/
struct
{
+
/**
* Time when the purse was merged (or zero if it
* was not merged).
@@ -4576,7 +6250,12 @@ struct TALER_EXCHANGE_PurseGetResponse
*/
struct TALER_Amount balance;
- } success;
+ /**
+ * Time when the purse will expire.
+ */
+ struct GNUNET_TIME_Timestamp purse_expiration;
+
+ } ok;
} details;
@@ -4604,7 +6283,9 @@ struct TALER_EXCHANGE_PurseGetHandle;
/**
* Request information about a purse from the exchange.
*
- * @param exchange exchange handle
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param purse_pub public key of the purse
* @param timeout how long to wait for a change to happen
* @param wait_for_merge true to wait for a merge event, otherwise wait for a deposit event
@@ -4614,7 +6295,9 @@ struct TALER_EXCHANGE_PurseGetHandle;
*/
struct TALER_EXCHANGE_PurseGetHandle *
TALER_EXCHANGE_purse_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPublicKeyP *purse_pub,
struct GNUNET_TIME_Relative timeout,
bool wait_for_merge,
@@ -4666,7 +6349,7 @@ struct TALER_EXCHANGE_PurseCreateDepositResponse
struct TALER_ExchangeSignatureP exchange_sig;
- } success;
+ } ok;
} details;
@@ -4692,7 +6375,7 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle;
/**
- * Information about a coin to be deposited into a purse.
+ * Information about a coin to be deposited into a purse or reserve.
*/
struct TALER_EXCHANGE_PurseDeposit
{
@@ -4728,7 +6411,9 @@ struct TALER_EXCHANGE_PurseDeposit
* Inform the exchange that a purse should be created
* and coins deposited into it.
*
- * @param exchange the exchange to interact with
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param purse_priv private key of the purse
* @param merge_priv the merge credential
* @param contract_priv key needed to obtain and decrypt the contract
@@ -4744,13 +6429,15 @@ struct TALER_EXCHANGE_PurseDeposit
*/
struct TALER_EXCHANGE_PurseCreateDepositHandle *
TALER_EXCHANGE_purse_create_with_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
bool upload_contract,
TALER_EXCHANGE_PurseCreateDepositCallback cb,
void *cb_cls);
@@ -4767,6 +6454,67 @@ TALER_EXCHANGE_purse_create_with_deposit_cancel (
/**
+ * Response generated for a purse deletion request.
+ */
+struct TALER_EXCHANGE_PurseDeleteResponse
+{
+ /**
+ * Full HTTP response.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+};
+
+
+/**
+ * Function called with information about the deletion
+ * of a purse.
+ *
+ * @param cls closure
+ * @param pdr HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_PurseDeleteCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_PurseDeleteResponse *pdr);
+
+
+/**
+ * @brief Handle for a DELETE /purses/$PID request.
+ */
+struct TALER_EXCHANGE_PurseDeleteHandle;
+
+
+/**
+ * Asks the exchange to delete a purse. Will only succeed if
+ * the purse was not yet merged and did not yet time out.
+ *
+ * @param ctx CURL context
+ * @param url exchange base URL
+ * @param purse_priv private key of the purse
+ * @param cb function to call with the exchange's result
+ * @param cb_cls closure for @a cb
+ * @return the request handle; NULL upon error
+ */
+struct TALER_EXCHANGE_PurseDeleteHandle *
+TALER_EXCHANGE_purse_delete (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_PurseContractPrivateKeyP *purse_priv,
+ TALER_EXCHANGE_PurseDeleteCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel #TALER_EXCHANGE_purse_delete() operation.
+ *
+ * @param pdh handle of the operation to cancel
+ */
+void
+TALER_EXCHANGE_purse_delete_cancel (
+ struct TALER_EXCHANGE_PurseDeleteHandle *pdh);
+
+
+/**
* Response generated for an account merge request.
*/
struct TALER_EXCHANGE_AccountMergeResponse
@@ -4806,7 +6554,19 @@ struct TALER_EXCHANGE_AccountMergeResponse
*/
struct GNUNET_TIME_Timestamp etime;
- } success;
+ } ok;
+
+ /**
+ * Details if the status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
+ */
+ struct
+ {
+ /**
+ * Requirement row target that the merchant should use
+ * to check for its KYC status.
+ */
+ uint64_t requirement_row;
+ } unavailable_for_legal_reasons;
} details;
@@ -4835,7 +6595,9 @@ struct TALER_EXCHANGE_AccountMergeHandle;
* Inform the exchange that a purse should be merged
* with a reserve.
*
- * @param exchange the exchange hosting the purse
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param reserve_exchange_url base URL of the exchange with the reserve
* @param reserve_priv private key of the reserve to merge into
* @param purse_pub public key of the purse to merge
@@ -4851,7 +6613,9 @@ struct TALER_EXCHANGE_AccountMergeHandle;
*/
struct TALER_EXCHANGE_AccountMergeHandle *
TALER_EXCHANGE_account_merge (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const char *reserve_exchange_url,
const struct TALER_ReservePrivateKeyP *reserve_priv,
const struct TALER_PurseContractPublicKeyP *purse_pub,
@@ -4897,12 +6661,25 @@ struct TALER_EXCHANGE_PurseCreateMergeResponse
union
{
/**
- * Detailed returned on #MHD_HTTP_OK.
+ * Details returned on #MHD_HTTP_OK.
*/
struct
{
- } success;
+ } ok;
+
+ /**
+ * Details if the status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
+ */
+ struct
+ {
+ /**
+ * Requirement row that the merchant should use
+ * to check for its KYC status.
+ */
+ uint64_t requirement_row;
+ } unavailable_for_legal_reasons;
+
} details;
};
@@ -4930,7 +6707,9 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle;
* Inform the exchange that a purse should be created
* and merged with a reserve.
*
- * @param exchange the exchange hosting the reserve
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param reserve_priv private key of the reserve
* @param purse_priv private key of the purse
* @param merge_priv private key of the merge capability
@@ -4945,7 +6724,9 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle;
*/
struct TALER_EXCHANGE_PurseCreateMergeHandle *
TALER_EXCHANGE_purse_create_with_merge (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
@@ -5009,7 +6790,7 @@ struct TALER_EXCHANGE_PurseDepositResponse
*/
struct TALER_PrivateContractHashP h_contract_terms;
- } success;
+ } ok;
} details;
};
@@ -5037,7 +6818,9 @@ struct TALER_EXCHANGE_PurseDepositHandle;
* Inform the exchange that a deposit should be made into
* a purse.
*
- * @param exchange the exchange that issued the coins
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
* @param purse_exchange_url base URL of the exchange hosting the purse
* @param purse_pub public key of the purse to merge
* @param min_age minimum age we need to prove for the purse
@@ -5049,12 +6832,14 @@ struct TALER_EXCHANGE_PurseDepositHandle;
*/
struct TALER_EXCHANGE_PurseDepositHandle *
TALER_EXCHANGE_purse_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const char *purse_exchange_url,
const struct TALER_PurseContractPublicKeyP *purse_pub,
uint8_t min_age,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
TALER_EXCHANGE_PurseDepositCallback cb,
void *cb_cls);
@@ -5069,4 +6854,474 @@ TALER_EXCHANGE_purse_deposit_cancel (
struct TALER_EXCHANGE_PurseDepositHandle *amh);
+/* ********************* /reserves/$RID/open *********************** */
+
+
+/**
+ * @brief A /reserves/$RID/open Handle
+ */
+struct TALER_EXCHANGE_ReservesOpenHandle;
+
+
+/**
+ * @brief Reserve open result details.
+ */
+struct TALER_EXCHANGE_ReserveOpenResult
+{
+
+ /**
+ * High-level HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on @e hr.http_status.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success, if
+ * @e hr.http_status is #MHD_HTTP_OK
+ */
+ struct
+ {
+ /**
+ * New expiration time
+ */
+ struct GNUNET_TIME_Timestamp expiration_time;
+
+ /**
+ * Actual cost of the open operation.
+ */
+ struct TALER_Amount open_cost;
+
+ } ok;
+
+
+ /**
+ * Information returned if the payment provided is insufficient, if
+ * @e hr.http_status is #MHD_HTTP_PAYMENT_REQUIRED
+ */
+ struct
+ {
+ /**
+ * Current expiration time of the reserve.
+ */
+ struct GNUNET_TIME_Timestamp expiration_time;
+
+ /**
+ * Actual cost of the open operation that should have been paid.
+ */
+ struct TALER_Amount open_cost;
+
+ } payment_required;
+
+ /**
+ * Information returned if status is
+ * #MHD_HTTP_CONFLICT.
+ */
+ struct
+ {
+ /**
+ * Public key of the coin that caused the conflict.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ } conflict;
+
+ /**
+ * Information returned if KYC is required to proceed, set if
+ * @e hr.http_status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
+ */
+ struct
+ {
+ /**
+ * Requirement row that the merchant should use
+ * to check for its KYC status.
+ */
+ uint64_t requirement_row;
+
+ /**
+ * Hash of the payto-URI of the account to KYC;
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ } unavailable_for_legal_reasons;
+
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to serve the result of submitting a
+ * reserve open request to a exchange.
+ *
+ * @param cls closure
+ * @param ror HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ReservesOpenCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ReserveOpenResult *ror);
+
+
+/**
+ * Submit a request to open a reserve.
+ *
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param keys exchange keys
+ * @param reserve_priv private key of the reserve to open
+ * @param reserve_contribution amount to pay from the reserve's balance for the operation
+ * @param coin_payments_length length of the @a coin_payments array
+ * @param coin_payments array of coin payments to use for opening the reserve
+ * @param expiration_time desired new expiration time for the reserve
+ * @param min_purses minimum number of purses to allow being concurrently opened per reserve
+ * @param cb the callback to call when a reply for this request is available
+ * @param cb_cls closure for the above callback
+ * @return a handle for this request; NULL if the inputs are invalid (i.e.
+ * signatures fail to verify). In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_ReservesOpenHandle *
+TALER_EXCHANGE_reserves_open (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *reserve_contribution,
+ unsigned int coin_payments_length,
+ const struct TALER_EXCHANGE_PurseDeposit coin_payments[
+ static coin_payments_length],
+ struct GNUNET_TIME_Timestamp expiration_time,
+ uint32_t min_purses,
+ TALER_EXCHANGE_ReservesOpenCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel a reserve status request. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param[in] roh the reserve open request handle
+ */
+void
+TALER_EXCHANGE_reserves_open_cancel (
+ struct TALER_EXCHANGE_ReservesOpenHandle *roh);
+
+
+/* ********************* /reserves/$RID/attest *********************** */
+
+
+/**
+ * @brief A Get /reserves/$RID/attest Handle
+ */
+struct TALER_EXCHANGE_ReservesGetAttestHandle;
+
+
+/**
+ * @brief Reserve GET attest result details.
+ */
+struct TALER_EXCHANGE_ReserveGetAttestResult
+{
+
+ /**
+ * High-level HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on @e hr.http_status.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success, if
+ * @e hr.http_status is #MHD_HTTP_OK
+ */
+ struct
+ {
+
+ /**
+ * Length of the @e attributes array.
+ */
+ unsigned int attributes_length;
+
+ /**
+ * Array of attributes available about the user.
+ */
+ const char **attributes;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to serve the result of submitting a
+ * reserve attest request to a exchange.
+ *
+ * @param cls closure
+ * @param ror HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ReservesGetAttestCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ReserveGetAttestResult *ror);
+
+
+/**
+ * Submit a request to get the list of attestable attributes for a reserve.
+ *
+ * @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
+ * @return a handle for this request; NULL if the inputs are invalid (i.e.
+ * signatures fail to verify). In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_ReservesGetAttestHandle *
+TALER_EXCHANGE_reserves_get_attestable (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ TALER_EXCHANGE_ReservesGetAttestCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel a request to get attestable attributes. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param rgah the reserve get attestable request handle
+ */
+void
+TALER_EXCHANGE_reserves_get_attestable_cancel (
+ struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah);
+
+
+/**
+ * @brief A POST /reserves/$RID/attest Handle
+ */
+struct TALER_EXCHANGE_ReservesPostAttestHandle;
+
+
+/**
+ * @brief Reserve attest result details.
+ */
+struct TALER_EXCHANGE_ReservePostAttestResult
+{
+
+ /**
+ * High-level HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on @e hr.http_status.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success, if
+ * @e hr.http_status is #MHD_HTTP_OK
+ */
+ struct
+ {
+ /**
+ * Time when the exchange made the signature.
+ */
+ struct GNUNET_TIME_Timestamp exchange_time;
+
+ /**
+ * Expiration time of the attested attributes.
+ */
+ struct GNUNET_TIME_Timestamp expiration_time;
+
+ /**
+ * Signature by the exchange affirming the attributes.
+ */
+ struct TALER_ExchangeSignatureP exchange_sig;
+
+ /**
+ * Online signing key used by the exchange.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+
+ /**
+ * Attributes being confirmed by the exchange.
+ */
+ const json_t *attributes;
+
+ } ok;
+
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to serve the result of submitting a
+ * reserve attest request to a exchange.
+ *
+ * @param cls closure
+ * @param ror HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ReservesPostAttestCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ReservePostAttestResult *ror);
+
+
+/**
+ * Submit a request to attest attributes about the owner of a reserve.
+ *
+ * @param ctx CURL context
+ * @param url exchange base URL
+ * @param keys exchange key data
+ * @param reserve_priv private key of the reserve to attest
+ * @param attributes_length length of the @a attributes array
+ * @param attributes array of names of attributes to get attestations for
+ * @param cb the callback to call when a reply for this request is available
+ * @param cb_cls closure for the above callback
+ * @return a handle for this request; NULL if the inputs are invalid (i.e.
+ * signatures fail to verify). In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_ReservesAttestHandle *
+TALER_EXCHANGE_reserves_attest (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ unsigned int attributes_length,
+ const char *attributes[const static attributes_length],
+ TALER_EXCHANGE_ReservesPostAttestCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel a reserve attestation request. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param rah the reserve attest request handle
+ */
+void
+TALER_EXCHANGE_reserves_attest_cancel (
+ struct TALER_EXCHANGE_ReservesAttestHandle *rah);
+
+
+/* ********************* /reserves/$RID/close *********************** */
+
+
+/**
+ * @brief A /reserves/$RID/close Handle
+ */
+struct TALER_EXCHANGE_ReservesCloseHandle;
+
+
+/**
+ * @brief Reserve close result details.
+ */
+struct TALER_EXCHANGE_ReserveCloseResult
+{
+
+ /**
+ * High-level HTTP response details.
+ */
+ struct TALER_EXCHANGE_HttpResponse hr;
+
+ /**
+ * Details depending on @e hr.http_status.
+ */
+ union
+ {
+
+ /**
+ * Information returned on success, if
+ * @e hr.http_status is #MHD_HTTP_OK
+ */
+ struct
+ {
+
+ /**
+ * Amount wired to the target account.
+ */
+ struct TALER_Amount wire_amount;
+ } ok;
+
+ /**
+ * Information returned if KYC is required to proceed, set if
+ * @e hr.http_status is #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS.
+ */
+ struct
+ {
+ /**
+ * Requirement row that the merchant should use
+ * to check for its KYC status.
+ */
+ uint64_t requirement_row;
+
+ /**
+ * Hash of the payto-URI of the account to KYC;
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ } unavailable_for_legal_reasons;
+
+ } details;
+
+};
+
+
+/**
+ * Callbacks of this type are used to serve the result of submitting a
+ * reserve close request to a exchange.
+ *
+ * @param cls closure
+ * @param ror HTTP response data
+ */
+typedef void
+(*TALER_EXCHANGE_ReservesCloseCallback) (
+ void *cls,
+ const struct TALER_EXCHANGE_ReserveCloseResult *ror);
+
+
+/**
+ * Submit a request to close a reserve.
+ *
+ * @param ctx curl context
+ * @param url exchange base URL
+ * @param reserve_priv private key of the reserve to close
+ * @param target_payto_uri where to send the payment, NULL to send to reserve origin
+ * @param cb the callback to call when a reply for this request is available
+ * @param cb_cls closure for the above callback
+ * @return a handle for this request; NULL if the inputs are invalid (i.e.
+ * signatures fail to verify). In this case, the callback is not called.
+ */
+struct TALER_EXCHANGE_ReservesCloseHandle *
+TALER_EXCHANGE_reserves_close (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const char *target_payto_uri,
+ TALER_EXCHANGE_ReservesCloseCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Cancel a reserve status request. This function cannot be used
+ * on a request handle if a response is already served for it.
+ *
+ * @param rch the reserve request handle
+ */
+void
+TALER_EXCHANGE_reserves_close_cancel (
+ struct TALER_EXCHANGE_ReservesCloseHandle *rch);
+
#endif /* _TALER_EXCHANGE_SERVICE_H */
diff --git a/src/include/taler_exchangedb_lib.h b/src/include/taler_exchangedb_lib.h
index 7f466728a..d93cf9d6c 100644
--- a/src/include/taler_exchangedb_lib.h
+++ b/src/include/taler_exchangedb_lib.h
@@ -46,7 +46,6 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg);
void
TALER_EXCHANGEDB_plugin_unload (struct TALER_EXCHANGEDB_Plugin *plugin);
-
/**
* Information about an account from the configuration.
*/
@@ -70,13 +69,13 @@ struct TALER_EXCHANGEDB_AccountInfo
const char *method;
/**
- * true if this account is enabed to be debited
+ * true if this account is enabled to be debited
* by the taler-exchange-aggregator.
*/
bool debit_enabled;
/**
- * true if this account is enabed to be credited by wallets
+ * true if this account is enabled to be credited by wallets
* and needs to be watched by the taler-exchange-wirewatch.
* Also, the account will only be included in /wire if credit
* is enabled.
@@ -95,7 +94,7 @@ struct TALER_EXCHANGEDB_AccountInfo
* @param[out] ret where the resulting total is to be stored
* @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
*/
-int
+enum GNUNET_GenericReturnValue
TALER_EXCHANGEDB_calculate_transaction_list_totals (
struct TALER_EXCHANGEDB_TransactionList *tl,
const struct TALER_Amount *off,
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index 23b2702ed..2d5857677 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -18,6 +18,7 @@
* @brief Low-level (statement-level) database access for the exchange
* @author Florian Dold
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
#ifndef TALER_EXCHANGEDB_PLUGIN_H
#define TALER_EXCHANGEDB_PLUGIN_H
@@ -26,6 +27,74 @@
#include <gnunet/gnunet_db_lib.h>
#include "taler_json_lib.h"
#include "taler_signatures.h"
+#include "taler_extensions_policy.h"
+
+/**
+ * The conflict that can occur for the age restriction
+ */
+enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict
+{
+ /**
+ * Value OK, no conflict
+ */
+ TALER_AgeCommitmentHash_NoConflict = 0,
+
+ /**
+ * Given hash had a value, but NULL (or zero) was expected
+ */
+ TALER_AgeCommitmentHash_NullExpected = 1,
+
+ /**
+ * Given hash was NULL, but value was expected
+ */
+ TALER_AgeCommitmentHash_ValueExpected = 2,
+
+ /**
+ * Given hash differs from value in the known coin
+ */
+ TALER_AgeCommitmentHash_ValueDiffers = 3,
+};
+
+/**
+ * Per-coin information returned when doing a batch insert.
+ */
+struct TALER_EXCHANGEDB_CoinInfo
+{
+ /**
+ * Row of the coin in the known_coins table.
+ */
+ uint64_t known_coin_id;
+
+ /**
+ * Hash of the denomination, relevant on @e denom_conflict.
+ */
+ struct TALER_DenominationHashP denom_hash;
+
+ /**
+ * Hash of the age commitment, relevant on @e age_conflict.
+ */
+ struct TALER_AgeCommitmentHash h_age_commitment;
+
+ /**
+ * True if the coin was known previously.
+ */
+ bool existed;
+
+ /**
+ * True if the known coin has a different denomination;
+ * application will find denomination of the already
+ * known coin in @e denom_hash.
+ */
+ bool denom_conflict;
+
+ /**
+ * Indicates if and what kind of conflict with the age
+ * restriction of the known coin was present;
+ * application will find age commitment of the already
+ * known coin in @e h_age_commitment.
+ */
+ enum TALER_EXCHANGEDB_AgeCommitmentHash_Conflict age_conflict;
+};
/**
@@ -106,7 +175,25 @@ struct TALER_EXCHANGEDB_DenominationKeyInformation
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * Signature of events signalling a reserve got funding.
+ * Events signalling that a coin deposit status
+ * changed.
+ */
+struct TALER_CoinDepositEventP
+{
+ /**
+ * Of type #TALER_DBEVENT_EXCHANGE_DEPOSIT_STATUS_CHANGED.
+ */
+ struct GNUNET_DB_EventHeaderP header;
+
+ /**
+ * Public key of the merchant.
+ */
+ struct TALER_MerchantPublicKeyP merchant_pub;
+
+};
+
+/**
+ * Events signalling a reserve got funding.
*/
struct TALER_ReserveEventP
{
@@ -192,12 +279,17 @@ struct TALER_EXCHANGEDB_SignkeyMetaData
*/
enum TALER_EXCHANGEDB_ReplicatedTable
{
+ /* From exchange-0002.sql: */
TALER_EXCHANGEDB_RT_DENOMINATIONS,
TALER_EXCHANGEDB_RT_DENOMINATION_REVOCATIONS,
TALER_EXCHANGEDB_RT_WIRE_TARGETS,
+ TALER_EXCHANGEDB_RT_LEGITIMIZATION_PROCESSES,
+ TALER_EXCHANGEDB_RT_LEGITIMIZATION_REQUIREMENTS,
TALER_EXCHANGEDB_RT_RESERVES,
TALER_EXCHANGEDB_RT_RESERVES_IN,
TALER_EXCHANGEDB_RT_RESERVES_CLOSE,
+ TALER_EXCHANGEDB_RT_RESERVES_OPEN_REQUESTS,
+ TALER_EXCHANGEDB_RT_RESERVES_OPEN_DEPOSITS,
TALER_EXCHANGEDB_RT_RESERVES_OUT,
TALER_EXCHANGEDB_RT_AUDITORS,
TALER_EXCHANGEDB_RT_AUDITOR_DENOM_SIGS,
@@ -207,7 +299,8 @@ enum TALER_EXCHANGEDB_ReplicatedTable
TALER_EXCHANGEDB_RT_REFRESH_COMMITMENTS,
TALER_EXCHANGEDB_RT_REFRESH_REVEALED_COINS,
TALER_EXCHANGEDB_RT_REFRESH_TRANSFER_KEYS,
- TALER_EXCHANGEDB_RT_DEPOSITS,
+ TALER_EXCHANGEDB_RT_BATCH_DEPOSITS,
+ TALER_EXCHANGEDB_RT_COIN_DEPOSITS,
TALER_EXCHANGEDB_RT_REFUNDS,
TALER_EXCHANGEDB_RT_WIRE_OUT,
TALER_EXCHANGEDB_RT_AGGREGATION_TRACKING,
@@ -216,9 +309,10 @@ enum TALER_EXCHANGEDB_ReplicatedTable
TALER_EXCHANGEDB_RT_RECOUP,
TALER_EXCHANGEDB_RT_RECOUP_REFRESH,
TALER_EXCHANGEDB_RT_EXTENSIONS,
- TALER_EXCHANGEDB_RT_EXTENSION_DETAILS,
+ TALER_EXCHANGEDB_RT_POLICY_DETAILS,
+ TALER_EXCHANGEDB_RT_POLICY_FULFILLMENTS,
TALER_EXCHANGEDB_RT_PURSE_REQUESTS,
- TALER_EXCHANGEDB_RT_PURSE_REFUNDS,
+ TALER_EXCHANGEDB_RT_PURSE_DECISION,
TALER_EXCHANGEDB_RT_PURSE_MERGES,
TALER_EXCHANGEDB_RT_PURSE_DEPOSITS,
TALER_EXCHANGEDB_RT_ACCOUNT_MERGES,
@@ -228,6 +322,13 @@ enum TALER_EXCHANGEDB_ReplicatedTable
TALER_EXCHANGEDB_RT_WADS_OUT_ENTRIES,
TALER_EXCHANGEDB_RT_WADS_IN,
TALER_EXCHANGEDB_RT_WADS_IN_ENTRIES,
+ TALER_EXCHANGEDB_RT_PROFIT_DRAINS,
+ /* From exchange-0003.sql: */
+ TALER_EXCHANGEDB_RT_AML_STAFF,
+ TALER_EXCHANGEDB_RT_AML_HISTORY,
+ TALER_EXCHANGEDB_RT_KYC_ATTRIBUTES,
+ TALER_EXCHANGEDB_RT_PURSE_DELETION,
+ TALER_EXCHANGEDB_RT_AGE_WITHDRAW,
};
@@ -278,12 +379,27 @@ struct TALER_EXCHANGEDB_TableData
struct
{
char *payto_uri;
- bool kyc_ok;
- char *external_id;
} wire_targets;
struct
{
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ char *provider_section;
+ char *provider_user_id;
+ char *provider_legitimization_id;
+ } legitimization_processes;
+
+ struct
+ {
+ struct TALER_PaytoHashP h_payto;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ bool no_reserve_pub;
+ char *required_checks;
+ } legitimization_requirements;
+
+ struct
+ {
struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Timestamp expiration_date;
struct GNUNET_TIME_Timestamp gc_date;
@@ -302,6 +418,25 @@ struct TALER_EXCHANGEDB_TableData
struct
{
struct TALER_ReservePublicKeyP reserve_pub;
+ struct GNUNET_TIME_Timestamp request_timestamp;
+ struct GNUNET_TIME_Timestamp expiration_date;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_Amount reserve_payment;
+ uint32_t requested_purse_limit;
+ } reserves_open_requests;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_ReserveSignatureP reserve_sig;
+ struct TALER_Amount contribution;
+ } reserves_open_deposits;
+
+ struct
+ {
+ struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_TIME_Timestamp execution_date;
struct TALER_WireTransferIdentifierRawP wtid;
struct TALER_PaytoHashP sender_account_h_payto;
@@ -389,26 +524,33 @@ struct TALER_EXCHANGEDB_TableData
struct
{
uint64_t shard;
- uint64_t known_coin_id;
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount amount_with_fee;
+ struct TALER_MerchantPublicKeyP merchant_pub;
struct GNUNET_TIME_Timestamp wallet_timestamp;
struct GNUNET_TIME_Timestamp exchange_timestamp;
struct GNUNET_TIME_Timestamp refund_deadline;
struct GNUNET_TIME_Timestamp wire_deadline;
- struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_CoinSpendSignatureP coin_sig;
+ struct GNUNET_HashCode wallet_data_hash;
+ bool no_wallet_data_hash;
struct TALER_WireSaltP wire_salt;
struct TALER_PaytoHashP wire_target_h_payto;
- bool extension_blocked;
- uint64_t extension_details_serial_id;
- } deposits;
+ bool policy_blocked;
+ uint64_t policy_details_serial_id;
+ bool no_policy_details;
+ } batch_deposits;
+
+ struct
+ {
+ uint64_t batch_deposit_serial_id;
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendSignatureP coin_sig;
+ struct TALER_Amount amount_with_fee;
+ } coin_deposits;
struct
{
struct TALER_CoinSpendPublicKeyP coin_pub;
- uint64_t deposit_serial_id;
+ uint64_t batch_deposit_serial_id;
struct TALER_MerchantSignatureP merchant_sig;
uint64_t rtransaction_id;
struct TALER_Amount amount_with_fee;
@@ -425,7 +567,7 @@ struct TALER_EXCHANGEDB_TableData
struct
{
- uint64_t deposit_serial_id;
+ uint64_t batch_deposit_serial_id;
struct TALER_WireTransferIdentifierRawP wtid_raw;
} aggregation_tracking;
@@ -444,7 +586,6 @@ struct TALER_EXCHANGEDB_TableData
struct GNUNET_TIME_Timestamp end_date;
struct TALER_GlobalFeeSet fees;
struct GNUNET_TIME_Relative purse_timeout;
- struct GNUNET_TIME_Relative kyc_timeout;
struct GNUNET_TIME_Relative history_expiration;
uint32_t purse_account_limit;
struct TALER_MasterSignatureP master_sig;
@@ -454,7 +595,7 @@ struct TALER_EXCHANGEDB_TableData
{
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_CoinSpendSignatureP coin_sig;
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
struct TALER_Amount amount;
struct GNUNET_TIME_Timestamp timestamp;
uint64_t reserve_out_serial_id;
@@ -465,7 +606,7 @@ struct TALER_EXCHANGEDB_TableData
uint64_t known_coin_id;
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_CoinSpendSignatureP coin_sig;
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
struct TALER_Amount amount;
struct GNUNET_TIME_Timestamp timestamp;
uint64_t rrc_serial;
@@ -474,13 +615,32 @@ struct TALER_EXCHANGEDB_TableData
struct
{
char *name;
- char *config;
+ char *manifest;
} extensions;
struct
{
- char *extension_options;
- } extension_details;
+ struct GNUNET_HashCode hash_code;
+ json_t *policy_json;
+ bool no_policy_json;
+ struct GNUNET_TIME_Timestamp deadline;
+ struct TALER_Amount commitment;
+ struct TALER_Amount accumulated_total;
+ struct TALER_Amount fee;
+ struct TALER_Amount transferable;
+ uint16_t fulfillment_state; /* will also be recomputed */
+ uint64_t fulfillment_id;
+ bool no_fulfillment_id;
+ } policy_details;
+
+ struct
+ {
+ struct GNUNET_TIME_Timestamp fulfillment_timestamp;
+ char *fulfillment_proof;
+ struct GNUNET_HashCode h_fulfillment_proof;
+ struct GNUNET_HashCode *policy_hash_codes;
+ size_t policy_hash_codes_count;
+ } policy_fulfillments;
struct
{
@@ -499,7 +659,9 @@ struct TALER_EXCHANGEDB_TableData
struct
{
struct TALER_PurseContractPublicKeyP purse_pub;
- } purse_refunds;
+ struct GNUNET_TIME_Timestamp action_timestamp;
+ bool refunded;
+ } purse_decision;
struct
{
@@ -524,6 +686,7 @@ struct TALER_EXCHANGEDB_TableData
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_ReserveSignatureP reserve_sig;
struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PaytoHashP wallet_h_payto;
} account_merges;
struct
@@ -540,6 +703,8 @@ struct TALER_EXCHANGEDB_TableData
struct GNUNET_TIME_Timestamp close_timestamp;
struct TALER_ReserveSignatureP reserve_sig;
struct TALER_Amount close;
+ struct TALER_Amount close_fee;
+ char *payto_uri;
} close_requests;
struct
@@ -588,6 +753,70 @@ struct TALER_EXCHANGEDB_TableData
struct TALER_PurseContractSignatureP purse_sig;
} wads_in_entries;
+ struct
+ {
+ struct TALER_WireTransferIdentifierRawP wtid;
+ char *account_section;
+ char *payto_uri;
+ struct GNUNET_TIME_Timestamp trigger_date;
+ struct TALER_Amount amount;
+ struct TALER_MasterSignatureP master_sig;
+ } profit_drains;
+
+ struct
+ {
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ struct TALER_MasterSignatureP master_sig;
+ char *decider_name;
+ bool is_active;
+ bool read_only;
+ struct GNUNET_TIME_Timestamp last_change;
+ } aml_staff;
+
+ struct
+ {
+ struct TALER_PaytoHashP h_payto;
+ struct TALER_Amount new_threshold;
+ enum TALER_AmlDecisionState new_status;
+ struct GNUNET_TIME_Timestamp decision_time;
+ char *justification;
+ char *kyc_requirements; /* NULL allowed! */
+ uint64_t kyc_req_row;
+ struct TALER_AmlOfficerPublicKeyP decider_pub;
+ struct TALER_AmlOfficerSignatureP decider_sig;
+ } aml_history;
+
+ struct
+ {
+ struct TALER_PaytoHashP h_payto;
+ struct GNUNET_ShortHashCode kyc_prox;
+ char *provider;
+ struct GNUNET_TIME_Timestamp collection_time;
+ struct GNUNET_TIME_Timestamp expiration_time;
+ void *encrypted_attributes;
+ size_t encrypted_attributes_size;
+ } kyc_attributes;
+
+ struct
+ {
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseContractSignatureP purse_sig;
+ } purse_deletion;
+
+ struct
+ {
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+ struct TALER_Amount amount_with_fee;
+ uint16_t max_age;
+ uint32_t noreveal_index;
+ struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_ReserveSignatureP reserve_sig;
+ uint64_t num_coins;
+ uint64_t *denominations_serials;
+ void *h_blind_evs;
+ struct TALER_BlindedDenominationSignature denom_sigs;
+ } age_withdraw;
+
} details;
};
@@ -747,6 +976,13 @@ struct TALER_EXCHANGEDB_Reserve
struct TALER_EXCHANGEDB_DenominationKeyMetaData
{
/**
+ * Serial of the denomination key as in the DB.
+ * Can be used in calls to stored procedures in order to spare
+ * additional lookups.
+ */
+ uint64_t serial;
+
+ /**
* Start time of the validity period for this key.
*/
struct GNUNET_TIME_Timestamp start;
@@ -855,6 +1091,39 @@ typedef void
/**
+ * Function called on all KYC process names that the given
+ * account has already passed.
+ *
+ * @param cls closure
+ * @param kyc_provider_section_name configuration section
+ * of the respective KYC process
+ */
+typedef void
+(*TALER_EXCHANGEDB_SatisfiedProviderCallback)(
+ void *cls,
+ const char *kyc_provider_section_name);
+
+
+/**
+ * Function called on all legitimization operations
+ * we have performed for the given account so far
+ * (and that have not yet expired).
+ *
+ * @param cls closure
+ * @param kyc_provider_section_name configuration section
+ * of the respective KYC process
+ * @param provider_user_id UID at a provider (can be NULL)
+ * @param legi_id legitimization process ID (can be NULL)
+ */
+typedef void
+(*TALER_EXCHANGEDB_LegitimizationProcessCallback)(
+ void *cls,
+ const char *kyc_provider_section_name,
+ const char *provider_user_id,
+ const char *legi_id);
+
+
+/**
* Function called with information about the exchange's auditors.
*
* @param cls closure with a `struct TEH_KeyStateHandle *`
@@ -947,6 +1216,79 @@ struct TALER_EXCHANGEDB_CollectableBlindcoin
/**
+ * @brief Information we keep for an age-withdraw request
+ * to reproduce the /age-withdraw operation if needed, and to have proof
+ * that a reserve was drained by this amount.
+ */
+struct TALER_EXCHANGEDB_AgeWithdraw
+{
+ /**
+ * Total amount (with fee) committed to withdraw
+ */
+ struct TALER_Amount amount_with_fee;
+
+ /**
+ * Maximum age (in years) that the coins are restricted to.
+ */
+ uint16_t max_age;
+
+ /**
+ * The hash of the commitment of all n*kappa coins
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * Index (smaller #TALER_CNC_KAPPA) which the exchange has chosen to not have
+ * revealed during cut and choose. This value applies to all n coins in the
+ * commitment.
+ */
+ uint16_t noreveal_index;
+
+ /**
+ * Public key of the reserve that was drained.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Signature confirming the age withdrawal commitment, matching @e
+ * reserve_pub, @e max_age and @e h_commitment and @e amount_with_fee.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Number of coins to be withdrawn.
+ */
+ size_t num_coins;
+
+ /**
+ * Array of @a num_coins blinded coins. These are the chosen coins
+ * (according to @a noreveal_index) from the request, which contained
+ * kappa*num_coins blinded coins.
+ */
+ struct TALER_BlindedCoinHashP *h_coin_evs;
+
+ /**
+ * Array of @a num_coins denomination signatures of the blinded coins @a
+ * h_coin_evs.
+ */
+ struct TALER_BlindedDenominationSignature *denom_sigs;
+
+ /**
+ * Array of @a num_coins serial id's of the denominations, corresponding to
+ * the coins in @a h_coin_evs.
+ */
+ uint64_t *denom_serials;
+
+ /**
+ * [out]-Array of @a num_coins hashes of the public keys of the denominations
+ * identified by @e denom_serials. This field is set when calling
+ * get_age_withdraw
+ */
+ struct TALER_DenominationHashP *denom_pub_hashes;
+};
+
+
+/**
* Information the exchange records about a recoup request
* in a reserve history.
*/
@@ -962,7 +1304,7 @@ struct TALER_EXCHANGEDB_Recoup
* Blinding factor supplied to prove to the exchange that
* the coin came from this reserve.
*/
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
/**
* Signature of the coin of type
@@ -1016,7 +1358,7 @@ struct TALER_EXCHANGEDB_RecoupListEntry
* Blinding factor supplied to prove to the exchange that
* the coin came from this reserve.
*/
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
/**
* Signature of the coin of type
@@ -1064,7 +1406,7 @@ struct TALER_EXCHANGEDB_RecoupRefreshListEntry
* Blinding factor supplied to prove to the exchange that
* the coin came from this @e old_coin_pub.
*/
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
/**
* Signature of the coin of type
@@ -1188,6 +1530,76 @@ struct TALER_EXCHANGEDB_HistoryRequest
/**
+ * Details about a (paid for) reserve open request.
+ */
+struct TALER_EXCHANGEDB_OpenRequest
+{
+ /**
+ * Public key of the reserve the open request was for.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Fee paid for the request from the reserve.
+ */
+ struct TALER_Amount open_fee;
+
+ /**
+ * When was the request made.
+ */
+ struct GNUNET_TIME_Timestamp request_timestamp;
+
+ /**
+ * How long was the reserve supposed to be open.
+ */
+ struct GNUNET_TIME_Timestamp reserve_expiration;
+
+ /**
+ * Signature by the reserve approving the open request,
+ * with purpose #TALER_SIGNATURE_WALLET_RESERVE_OPEN.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * How many open purses should be included with the
+ * open reserve?
+ */
+ uint32_t purse_limit;
+
+};
+
+
+/**
+ * Details about an (explicit) reserve close request.
+ */
+struct TALER_EXCHANGEDB_CloseRequest
+{
+ /**
+ * Public key of the reserve the history request was for.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * When was the request made.
+ */
+ struct GNUNET_TIME_Timestamp request_timestamp;
+
+ /**
+ * Hash of the payto://-URI of the target account
+ * for the closure, or all zeros for the reserve
+ * origin account.
+ */
+ struct TALER_PaytoHashP target_account_h_payto;
+
+ /**
+ * Signature by the reserve approving the history request.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+};
+
+
+/**
* @brief Types of operations on a reserve.
*/
enum TALER_EXCHANGEDB_ReserveOperation
@@ -1223,7 +1635,17 @@ enum TALER_EXCHANGEDB_ReserveOperation
/**
* Event where a wallet paid for a full reserve history.
*/
- TALER_EXCHANGEDB_RO_HISTORY_REQUEST = 5
+ TALER_EXCHANGEDB_RO_HISTORY_REQUEST = 5,
+
+ /**
+ * Event where a wallet paid to open a reserve for longer.
+ */
+ TALER_EXCHANGEDB_RO_OPEN_REQUEST = 6,
+
+ /**
+ * Event where a wallet requested a reserve to be closed.
+ */
+ TALER_EXCHANGEDB_RO_CLOSE_REQUEST = 7
};
@@ -1284,12 +1706,146 @@ struct TALER_EXCHANGEDB_ReserveHistory
*/
struct TALER_EXCHANGEDB_HistoryRequest *history;
+ /**
+ * Details about a (paid for) open reserve request.
+ */
+ struct TALER_EXCHANGEDB_OpenRequest *open_request;
+
+ /**
+ * Details about an (explicit) reserve close request.
+ */
+ struct TALER_EXCHANGEDB_CloseRequest *close_request;
+
} details;
};
/**
+ * @brief Data about a coin for a deposit operation.
+ */
+struct TALER_EXCHANGEDB_CoinDepositInformation
+{
+ /**
+ * Information about the coin that is being deposited.
+ */
+ struct TALER_CoinPublicInfo coin;
+
+ /**
+ * ECDSA signature affirming that the customer intends
+ * this coin to be deposited at the merchant identified
+ * by @e h_wire in relation to the proposal data identified
+ * by @e h_contract_terms.
+ */
+ struct TALER_CoinSpendSignatureP csig;
+
+ /**
+ * Fraction of the coin's remaining value to be deposited, including
+ * depositing fee (if any). The coin is identified by @e coin_pub.
+ */
+ struct TALER_Amount amount_with_fee;
+
+};
+
+
+/**
+ * @brief Data from a batch deposit operation.
+ */
+struct TALER_EXCHANGEDB_BatchDeposit
+{
+
+ /**
+ * Public key of the merchant. Enables later identification
+ * of the merchant in case of a need to rollback transactions.
+ */
+ struct TALER_MerchantPublicKeyP merchant_pub;
+
+ /**
+ * Hash over the proposal data between merchant and customer
+ * (remains unknown to the Exchange).
+ */
+ struct TALER_PrivateContractHashP h_contract_terms;
+
+ /**
+ * Hash over additional inputs by the wallet.
+ */
+ struct GNUNET_HashCode wallet_data_hash;
+
+ /**
+ * Unsalted hash over @e receiver_wire_account.
+ */
+ struct TALER_PaytoHashP wire_target_h_payto;
+
+ /**
+ * Salt used by the merchant to compute "h_wire".
+ */
+ struct TALER_WireSaltP wire_salt;
+
+ /**
+ * Time when this request was generated. Used, for example, to
+ * assess when (roughly) the income was achieved for tax purposes.
+ * Note that the Exchange will only check that the timestamp is not "too
+ * far" into the future (i.e. several days). The fact that the
+ * timestamp falls within the validity period of the coin's
+ * denomination key is irrelevant for the validity of the deposit
+ * request, as obviously the customer and merchant could conspire to
+ * set any timestamp. Also, the Exchange must accept very old deposit
+ * requests, as the merchant might have been unable to transmit the
+ * deposit request in a timely fashion (so back-dating is not
+ * prevented).
+ */
+ struct GNUNET_TIME_Timestamp wallet_timestamp;
+
+ /**
+ * How much time does the merchant have to issue a refund request?
+ * Zero if refunds are not allowed. After this time, the coin
+ * cannot be refunded.
+ */
+ struct GNUNET_TIME_Timestamp refund_deadline;
+
+ /**
+ * How much time does the merchant have to execute the wire transfer?
+ * This time is advisory for aggregating transactions, not a hard
+ * constraint (as the merchant can theoretically pick any time,
+ * including one in the past).
+ */
+ struct GNUNET_TIME_Timestamp wire_deadline;
+
+ /**
+ * Row ID of the policy details; 0 if no policy applies.
+ */
+ uint64_t policy_details_serial_id;
+
+ /**
+ * Information about the receiver for executing the transaction. URI in
+ * payto://-format.
+ */
+ const char *receiver_wire_account;
+
+ /**
+ * Array about the coins that are being deposited.
+ */
+ const struct TALER_EXCHANGEDB_CoinDepositInformation *cdis;
+
+ /**
+ * Length of the @e cdis array.
+ */
+ unsigned int num_cdis;
+
+ /**
+ * False if @e wallet_data_hash was provided
+ */
+ bool no_wallet_data_hash;
+
+ /**
+ * True if further processing is blocked by policy.
+ */
+ bool policy_blocked;
+
+};
+
+
+/**
* @brief Data from a deposit operation. The combination of
* the coin's public key, the merchant's public key and the
* transaction ID must be unique. While a coin can (theoretically) be
@@ -1332,16 +1888,15 @@ struct TALER_EXCHANGEDB_Deposit
struct TALER_WireSaltP wire_salt;
/**
- * Information about the receiver for executing the transaction. URI in
- * payto://-format.
+ * Hash over inputs from the wallet to customize the contract.
*/
- char *receiver_wire_account;
+ struct GNUNET_HashCode wallet_data_hash;
/**
- * Additional details for extensions relevant for this
- * deposit operation, possibly NULL!
+ * Hash over the policy data for this deposit (remains unknown to the
+ * Exchange). Needed for the verification of the deposit's signature
*/
- json_t *extension_details;
+ struct TALER_ExtensionPolicyHashP h_policy;
/**
* Time when this request was generated. Used, for example, to
@@ -1384,6 +1939,22 @@ struct TALER_EXCHANGEDB_Deposit
*/
struct TALER_Amount deposit_fee;
+ /**
+ * Information about the receiver for executing the transaction. URI in
+ * payto://-format.
+ */
+ char *receiver_wire_account;
+
+ /**
+ * True if @e policy_json was provided
+ */
+ bool has_policy;
+
+ /**
+ * True if @e wallet_data_hash is not in use.
+ */
+ bool no_wallet_data_hash;
+
};
@@ -1415,6 +1986,11 @@ struct TALER_EXCHANGEDB_DepositListEntry
struct TALER_PrivateContractHashP h_contract_terms;
/**
+ * Hash over inputs from the wallet to customize the contract.
+ */
+ struct GNUNET_HashCode wallet_data_hash;
+
+ /**
* Hash of the public denomination key used to sign the coin.
*/
struct TALER_DenominationHashP h_denom_pub;
@@ -1426,20 +2002,26 @@ struct TALER_EXCHANGEDB_DepositListEntry
struct TALER_AgeCommitmentHash h_age_commitment;
/**
- * true, if age commitment is not applicable
+ * Salt used to compute h_wire from the @e receiver_wire_account.
*/
- bool no_age_commitment;
+ struct TALER_WireSaltP wire_salt;
/**
- * Detailed information about the receiver for executing the transaction.
- * URL in payto://-format.
+ * Hash over the policy data for this deposit (remains unknown to the
+ * Exchange). Needed for the verification of the deposit's signature
*/
- char *receiver_wire_account;
+ struct TALER_ExtensionPolicyHashP h_policy;
/**
- * Salt used to compute h_wire from the @e receiver_wire_account.
+ * Fraction of the coin's remaining value to be deposited, including
+ * depositing fee (if any). The coin is identified by @e coin_pub.
*/
- struct TALER_WireSaltP wire_salt;
+ struct TALER_Amount amount_with_fee;
+
+ /**
+ * Depositing fee.
+ */
+ struct TALER_Amount deposit_fee;
/**
* Time when this request was generated. Used, for example, to
@@ -1472,15 +2054,25 @@ struct TALER_EXCHANGEDB_DepositListEntry
struct GNUNET_TIME_Timestamp wire_deadline;
/**
- * Fraction of the coin's remaining value to be deposited, including
- * depositing fee (if any). The coin is identified by @e coin_pub.
+ * Detailed information about the receiver for executing the transaction.
+ * URL in payto://-format.
*/
- struct TALER_Amount amount_with_fee;
+ char *receiver_wire_account;
/**
- * Depositing fee.
+ * true, if age commitment is not applicable
*/
- struct TALER_Amount deposit_fee;
+ bool no_age_commitment;
+
+ /**
+ * true, if wallet data hash is not present
+ */
+ bool no_wallet_data_hash;
+
+ /**
+ * True if a policy was provided with the deposit request
+ */
+ bool has_policy;
/**
* Has the deposit been wired?
@@ -1706,6 +2298,56 @@ struct TALER_EXCHANGEDB_PurseDepositListEntry
/**
+ * @brief Specification for a purse refund operation in a coin's transaction list.
+ */
+struct TALER_EXCHANGEDB_PurseRefundListEntry
+{
+
+ /**
+ * Public key of the purse.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Fraction of the original deposit's value to be refunded, including
+ * refund fee (if any). The coin is identified by @e coin_pub.
+ */
+ struct TALER_Amount refund_amount;
+
+ /**
+ * Refund fee to be covered by the customer.
+ */
+ struct TALER_Amount refund_fee;
+
+};
+
+
+/**
+ * Information about a /reserves/$RID/open operation in a coin transaction history.
+ */
+struct TALER_EXCHANGEDB_ReserveOpenListEntry
+{
+
+ /**
+ * Signature of the reserve.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Contribution of the coin to the open fee, including
+ * deposit fee.
+ */
+ struct TALER_Amount coin_contribution;
+
+ /**
+ * Signature by the coin affirming the open deposit.
+ */
+ struct TALER_CoinSpendSignatureP coin_sig;
+
+};
+
+
+/**
* Information about a /purses/$PID/deposit operation.
*/
struct TALER_EXCHANGEDB_PurseDeposit
@@ -1807,9 +2449,9 @@ struct TALER_EXCHANGEDB_LinkList
struct TALER_CoinSpendSignatureP orig_coin_link_sig;
/**
- * CS nonce, if cipher is CS.
+ * Session nonce, if cipher has one.
*/
- struct TALER_CsNonce nonce;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
/**
* Offset that generated this coin in the refresh
@@ -1864,7 +2506,17 @@ enum TALER_EXCHANGEDB_TransactionType
/**
* Purse deposit operation.
*/
- TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6
+ TALER_EXCHANGEDB_TT_PURSE_DEPOSIT = 6,
+
+ /**
+ * Purse deposit operation.
+ */
+ TALER_EXCHANGEDB_TT_PURSE_REFUND = 7,
+
+ /**
+ * Reserve open deposit operation.
+ */
+ TALER_EXCHANGEDB_TT_RESERVE_OPEN = 8
};
@@ -1940,6 +2592,18 @@ struct TALER_EXCHANGEDB_TransactionList
*/
struct TALER_EXCHANGEDB_PurseDepositListEntry *purse_deposit;
+ /**
+ * Coin was refunded upon purse expiration
+ * (#TALER_EXCHANGEDB_TT_PURSE_REFUND)
+ */
+ struct TALER_EXCHANGEDB_PurseRefundListEntry *purse_refund;
+
+ /**
+ * Coin was used to pay to open a reserve.
+ * (#TALER_EXCHANGEDB_TT_RESERVE_OPEN)
+ */
+ struct TALER_EXCHANGEDB_ReserveOpenListEntry *reserve_open;
+
} details;
};
@@ -1963,6 +2627,28 @@ typedef void
/**
+ * Callback with KYC attributes about a particular user.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ */
+typedef void
+(*TALER_EXCHANGEDB_AttributeCallback)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ struct GNUNET_TIME_Timestamp collection_time,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes);
+
+
+/**
* Function called with details about deposits that have been made,
* with the goal of auditing the deposit's execution.
*
@@ -2080,42 +2766,41 @@ typedef enum GNUNET_GenericReturnValue
/**
- * Function called with details about
- * history requests that have been made, with
- * the goal of auditing the history request execution.
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
*
* @param cls closure
* @param rowid unique serial ID for the deposit in our DB
- * @param history_fee fee paid for the request
- * @param ts timestamp of the request
- * @param reserve_pub reserve history was requested for
- * @param reserve_sig signature approving the @a history_fee
+ * @param purse_pub public key of the purse
+ * @param reserve_pub public key of the target reserve, NULL if not known / refunded
+ * @param purse_value what is the (target) value of the purse
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_HistoryRequestCallback)(
+(*TALER_EXCHANGEDB_PurseDecisionCallback)(
void *cls,
uint64_t rowid,
- const struct TALER_Amount *history_fee,
- const struct GNUNET_TIME_Timestamp ts,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig);
+ const struct TALER_Amount *purse_value);
/**
- * Function called with details about purse refunds that have been made, with
- * the goal of auditing the purse refund's execution.
+ * Function called with details about purse decisions that have been made, with
+ * the goal of auditing the purse's execution.
*
* @param cls closure
* @param rowid unique serial ID for the deposit in our DB
- * @param purse_pub public key of the refunded purse
+ * @param purse_pub public key of the purse
+ * @param refunded true if decision was to refund
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
typedef enum GNUNET_GenericReturnValue
-(*TALER_EXCHANGEDB_PurseRefundCallback)(
+(*TALER_EXCHANGEDB_AllPurseDecisionCallback)(
void *cls,
uint64_t rowid,
- const struct TALER_PurseContractPublicKeyP *purse_pub);
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ bool refunded);
/**
@@ -2249,70 +2934,52 @@ struct TALER_EXCHANGEDB_CsRevealFreshCoinData
/**
- * Types of operations that require KYC checks.
+ * Generic KYC status for some operation.
*/
-enum TALER_EXCHANGEDB_KycType
+struct TALER_EXCHANGEDB_KycStatus
{
-
/**
- * It is unclear for which type of KYC operation
- * this information is.
+ * Number that identifies the KYC requirement the operation
+ * was about.
*/
- TALER_EXCHANGEDB_KYC_UNKNOWN = 0,
+ uint64_t requirement_row;
/**
- * KYC to be applied for simple withdraws without
- * the involvement of wallet-to-wallet payments.
- * Tied to the payto:// of the debited account.
+ * True if the KYC status is "satisfied".
*/
- TALER_EXCHANGEDB_KYC_WITHDRAW = 1,
+ bool ok;
- /**
- * KYC to be applied for simple deposits to a
- * merchant's bank account. Tied to the payto://
- * of the credited account.
- */
- TALER_EXCHANGEDB_KYC_DEPOSIT = 2,
+};
- /**
- * KYC that is self-applied by a wallet that is exceeding the amount
- * threshold. Tied to the reserve-account public key that identifies the
- * funds-holding wallet.
- */
- TALER_EXCHANGEDB_KYC_BALANCE = 3,
- /**
- * KYC that is triggered upon wallet-to-wallet
- * payments for the recipient of funds. Tied to the
- * reserve public key that identifies the receiving
- * wallet.
- */
- TALER_EXCHANGEDB_KYC_W2W = 4
+struct TALER_EXCHANGEDB_ReserveInInfo
+{
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+ const struct TALER_Amount *balance;
+ struct GNUNET_TIME_Timestamp execution_time;
+ const char *sender_account_details;
+ const char *exchange_account_name;
+ uint64_t wire_reference;
};
/**
- * Generic KYC status for some operation.
+ * Function called on each @a amount that was found to
+ * be relevant for a KYC check.
+ *
+ * @param cls closure to allow the KYC module to
+ * total up amounts and evaluate rules
+ * @param amount encountered transaction amount
+ * @param date when was the amount encountered
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to abort iteration
+ * #GNUNET_SYSERR on internal error (also abort itaration)
*/
-struct TALER_EXCHANGEDB_KycStatus
-{
- /**
- * Number that identifies the KYC target the operation
- * was about.
- */
- uint64_t payment_target_uuid;
-
- /**
- * What kind of KYC operation is this?
- */
- enum TALER_EXCHANGEDB_KycType type;
-
- /**
- * True if the KYC status is "satisfied".
- */
- bool ok;
-
-};
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_KycAmountCallback)(
+ void *cls,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Absolute date);
/**
@@ -2387,14 +3054,24 @@ typedef enum GNUNET_GenericReturnValue
*
* @param cls closure
* @param payto_uri the exchange bank account URI
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
* @param master_sig master key signature affirming that this is a bank
* account of the exchange (of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS)
+ * @param bank_label label the wallet should use to display the account, can be NULL
+ * @param priority priority for ordering bank account labels
*/
typedef void
(*TALER_EXCHANGEDB_WireAccountCallback)(
void *cls,
const char *payto_uri,
- const struct TALER_MasterSignatureP *master_sig);
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority);
/**
@@ -2422,7 +3099,6 @@ typedef void
* @param cls closure
* @param fees the global fees we charge
* @param purse_timeout when do purses time out
- * @param kyc_timeout when do reserves without KYC time out
* @param history_expiration how long are account histories preserved
* @param purse_account_limit how many purses are free per account
* @param start_date from when are these fees valid (start date)
@@ -2435,7 +3111,6 @@ typedef void
void *cls,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
struct GNUNET_TIME_Timestamp start_date,
@@ -2537,6 +3212,26 @@ typedef enum GNUNET_GenericReturnValue
/**
+ * Function called on transient aggregations matching
+ * a particular hash of a payto URI.
+ *
+ * @param cls
+ * @param payto_uri corresponding payto URI
+ * @param wtid wire transfer identifier of transient aggregation
+ * @param merchant_pub public key of the merchant
+ * @param total amount aggregated so far
+ * @return true to continue iterating
+ */
+typedef bool
+(*TALER_EXCHANGEDB_TransientAggregationCallback)(
+ void *cls,
+ const char *payto_uri,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_Amount *total);
+
+
+/**
* Callback with data about a prepared wire transfer.
*
* @param cls closure
@@ -2580,7 +3275,7 @@ typedef enum GNUNET_GenericReturnValue
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind);
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
/**
@@ -2610,7 +3305,34 @@ typedef enum GNUNET_GenericReturnValue
const struct TALER_CoinPublicInfo *coin,
const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind);
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind);
+
+
+/**
+ * Function called about reserve opening operations.
+ *
+ * @param cls closure
+ * @param rowid row identifier used to uniquely identify the reserve closing operation
+ * @param reserve_payment how much to pay from the
+ * reserve's own balance for opening the reserve
+ * @param request_timestamp when was the request created
+ * @param reserve_expiration desired expiration time for the reserve
+ * @param purse_limit minimum number of purses the client
+ * wants to have concurrently open for this reserve
+ * @param reserve_pub public key of the reserve
+ * @param reserve_sig signature affirming the operation
+ * @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_ReserveOpenCallback)(
+ void *cls,
+ uint64_t rowid,
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig);
/**
@@ -2625,6 +3347,8 @@ typedef enum GNUNET_GenericReturnValue
* @param reserve_pub public key of the reserve
* @param receiver_account where did we send the funds, in payto://-format
* @param wtid identifier used for the wire transfer
+ * @param close_request_row row with the responsible close
+ * request, 0 if regular expiration triggered close
* @return #GNUNET_OK to continue to iterate, #GNUNET_SYSERR to stop
*/
typedef enum GNUNET_GenericReturnValue
@@ -2636,7 +3360,8 @@ typedef enum GNUNET_GenericReturnValue
const struct TALER_Amount *closing_fee,
const struct TALER_ReservePublicKeyP *reserve_pub,
const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid);
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t close_request_row);
/**
@@ -2659,15 +3384,20 @@ typedef void
* @param left amount left in the reserve
* @param account_details information about the reserve's bank account, in payto://-format
* @param expiration_date when did the reserve expire
- * @return transaction status code to pass on
+ * @param close_request_row row that caused the reserve
+ * to be closed, 0 if it expired without request
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO to retry
+ * #GNUNET_SYSERR on hard failures (exit)
*/
-typedef enum GNUNET_DB_QueryStatus
+typedef enum GNUNET_GenericReturnValue
(*TALER_EXCHANGEDB_ReserveExpiredCallback)(
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *left,
const char *account_details,
- struct GNUNET_TIME_Timestamp expiration_date);
+ struct GNUNET_TIME_Timestamp expiration_date,
+ uint64_t close_request_row);
/**
@@ -2688,32 +3418,72 @@ typedef void
uint64_t rowid,
const struct TALER_CoinPublicInfo *coin,
const struct TALER_CoinSpendSignatureP *coin_sig,
- const union TALER_DenominationBlindingKeyP *coin_blind,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_blind,
const struct TALER_BlindedCoinHashP *h_blinded_ev,
const struct TALER_Amount *amount);
/**
- * Function called on deposits that are past their due date
- * and have not yet seen a wire transfer.
+ * Function called on (batch) deposits will need a wire
+ * transfer.
*
* @param cls closure
- * @param rowid deposit table row of the coin's deposit
- * @param coin_pub public key of the coin
- * @param amount value of the deposit, including fee
- * @param payto_uri where should the funds be wired; URI in payto://-format
- * @param deadline what was the requested wire transfer deadline
- * @param done did the exchange claim that it made a transfer?
+ * @param batch_deposit_serial_id where in the table are we
+ * @param total_amount value of all missing deposits, including fees
+ * @param wire_target_h_payto hash of the recipient account's payto URI
+ * @param deadline what was the earliest requested wire transfer deadline
*/
typedef void
(*TALER_EXCHANGEDB_WireMissingCallback)(
void *cls,
+ uint64_t batch_deposit_serial_id,
+ const struct TALER_Amount *total_amount,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ struct GNUNET_TIME_Timestamp deadline);
+
+
+/**
+ * Function called on aggregations that were done for
+ * a (batch) deposit.
+ *
+ * @param cls closure
+ * @param tracking_serial_id where in the table are we
+ * @param batch_deposit_serial_id which batch deposit was aggregated
+ */
+typedef void
+(*TALER_EXCHANGEDB_AggregationCallback)(
+ void *cls,
+ uint64_t tracking_serial_id,
+ uint64_t batch_deposit_serial_id);
+
+
+/**
+ * Function called on purse requests.
+ *
+ * @param cls closure
+ * @param rowid purse request table row of the purse
+ * @param purse_pub public key of the purse
+ * @param merge_pub public key representing the merge capability
+ * @param purse_creation when was the purse created?
+ * @param purse_expiration when would an unmerged purse expire
+ * @param h_contract_terms contract associated with the purse
+ * @param age_limit the age limit for deposits into the purse
+ * @param target_amount amount to be put into the purse
+ * @param purse_sig signature of the purse over the initialization data
+ * @return #GNUNET_OK to continue to iterate
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_EXCHANGEDB_PurseRequestCallback)(
+ void *cls,
uint64_t rowid,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_Amount *amount,
- const char *payto_uri,
- struct GNUNET_TIME_Timestamp deadline,
- bool done);
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseMergePublicKeyP *merge_pub,
+ struct GNUNET_TIME_Timestamp purse_creation,
+ struct GNUNET_TIME_Timestamp purse_expiration,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ uint32_t age_limit,
+ const struct TALER_Amount *target_amount,
+ const struct TALER_PurseContractSignatureP *purse_sig);
/**
@@ -2733,6 +3503,46 @@ typedef void
/**
+ * Return AML status.
+ *
+ * @param cls closure
+ * @param row_id current row in AML status table
+ * @param h_payto account for which the attribute data is stored
+ * @param threshold currently monthly threshold that would trigger an AML check
+ * @param status what is the current AML decision
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlStatusCallback)(
+ void *cls,
+ uint64_t row_id,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *threshold,
+ enum TALER_AmlDecisionState status);
+
+
+/**
+ * Return historic AML decision.
+ *
+ * @param cls closure
+ * @param new_threshold new monthly threshold that would trigger an AML check
+ * @param new_status AML decision status
+ * @param decision_time when was the decision made
+ * @param justification human-readable text justifying the decision
+ * @param decider_pub public key of the staff member
+ * @param decider_sig signature of the staff member
+ */
+typedef void
+(*TALER_EXCHANGEDB_AmlHistoryCallback)(
+ void *cls,
+ const struct TALER_Amount *new_threshold,
+ enum TALER_AmlDecisionState new_status,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_AmlOfficerSignatureP *decider_sig);
+
+
+/**
* @brief The plugin API, returned from the plugin's "init" function.
* The argument given to "init" is simply a configuration handle.
*/
@@ -2761,63 +3571,20 @@ struct TALER_EXCHANGEDB_Plugin
(*drop_tables)(void *cls);
/**
- * Drop the Taler tables on a shard. This should only be used in testcases.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param old_idx the index which was used then the database was initialized.
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
- enum GNUNET_GenericReturnValue
- (*drop_shard_tables)(void *cls,
- uint32_t old_idx);
-
- /**
* Create the necessary tables if they are not present
*
* @param cls the @e cls of this struct with the plugin-specific state
+ * @param support_partitions true to enable partitioning support (disables foreign key constraints)
+ * @param num_partitions number of partitions to create,
+ * (0 to not actually use partitions, 1 to only
+ * setup a default partition, >1 for real partitions)
* @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
*/
enum GNUNET_GenericReturnValue
- (*create_tables)(void *cls);
-
- /**
- * Initialize the database of a shard node
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param idx the current shard index, will be appended to tables as suffix
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
- enum GNUNET_GenericReturnValue
- (*create_shard_tables)(void *cls,
- uint32_t idx);
+ (*create_tables)(void *cls,
+ bool support_partitions,
+ uint32_t num_partitions);
- /**
- * Change already present tables of the database to num partitions
- * Only has an effect if there are default partitions only
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param num the number of partitions to create for each partitioned table
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
- enum GNUNET_GenericReturnValue
- (*setup_partitions)(void *cls,
- uint32_t num);
-
- /**
- * Change already present tables of the database to num foreign tables on
- * num foreign servers (shards).
- * Only has an effect if there are default partitions only
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param num the number of shard servers to create. The shard servers
- * must follow the numbering of 1-N, have the same user as
- * the master and have tables named <table>_n where n is the same
- * as the servers index of N.
- * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure
- */
- enum GNUNET_GenericReturnValue
- (*setup_foreign_servers)(void *cls,
- uint32_t num);
/**
* Start a transaction.
@@ -2844,6 +3611,18 @@ struct TALER_EXCHANGEDB_Plugin
(*start_read_committed)(void *cls,
const char *name);
+ /**
+ * Start a READ ONLY serializable transaction.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param name unique name identifying the transaction (for debugging)
+ * must point to a constant
+ * @return #GNUNET_OK on success
+ */
+ enum GNUNET_GenericReturnValue
+ (*start_read_only)(void *cls,
+ const char *name);
+
/**
* Commit a transaction.
@@ -3041,79 +3820,58 @@ struct TALER_EXCHANGEDB_Plugin
* @param[in,out] reserve the reserve data. The public key of the reserve should be set
* in this structure; it is used to query the database. The balance
* and expiration are then filled accordingly.
- * @param[out] kyc set to the KYC status of the reserve
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
(*reserves_get)(void *cls,
- struct TALER_EXCHANGEDB_Reserve *reserve,
- struct TALER_EXCHANGEDB_KycStatus *kyc);
-
-
- /**
- * Set the KYC status to "OK" for a bank account.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto which account has been checked
- * @param id ID data to persist
- * @return transaction status
- */
- enum GNUNET_DB_QueryStatus
- (*set_kyc_ok)(void *cls,
- const struct TALER_PaytoHashP *h_payto,
- const char *id);
+ struct TALER_EXCHANGEDB_Reserve *reserve);
/**
- * Get the @a kyc status and @a h_payto by UUID.
+ * Get the origin of funds of a reserve.
*
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param h_payto set to the hash of the account's payto URI (unsalted)
- * @param[out] kyc set to the KYC status of the account
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param reserve_pub public key of the reserve
+ * @param[out] h_payto set to hash of the wire source payto://-URI
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
- (*select_kyc_status)(void *cls,
- const struct TALER_PaytoHashP *h_payto,
- struct TALER_EXCHANGEDB_KycStatus *kyc);
+ (*reserves_get_origin)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_PaytoHashP *h_payto);
/**
- * Get the KYC status for a wallet. If the status is unknown,
- * inserts a new status record (hence INsertSELECT).
+ * Extract next KYC alert. Deletes the alert.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the wallet
- * @param[out] kyc set to the KYC status of the wallet
+ * @param trigger_type which type of alert to drain
+ * @param[out] h_payto set to hash of payto-URI where KYC status changed
* @return transaction status
*/
enum GNUNET_DB_QueryStatus
- (*inselect_wallet_kyc_status)(
- void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_EXCHANGEDB_KycStatus *kyc);
+ (*drain_kyc_alert)(void *cls,
+ uint32_t trigger_type,
+ struct TALER_PaytoHashP *h_payto);
/**
- * Insert a incoming transaction into reserves. New reserves are
+ * Insert a batch of incoming transaction into reserves. New reserves are
* also created through this function.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param balance the amount that has to be added to the reserve
- * @param execution_time when was the amount added
- * @param sender_account_details information about the sender's bank account, in payto://-format
- * @param wire_reference unique reference identifying the wire transfer
- * @return transaction status code
+ * @param reserves
+ * @param reserves_length length of the @a reserves array
+ * @param[out] results array of transaction status codes of length @a reserves_length,
+ * set to the status of the
*/
enum GNUNET_DB_QueryStatus
- (*reserves_in_insert)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_Amount *balance,
- struct GNUNET_TIME_Timestamp execution_time,
- const char *sender_account_details,
- const char *exchange_account_name,
- uint64_t wire_reference);
+ (*reserves_in_insert)(
+ void *cls,
+ const struct TALER_EXCHANGEDB_ReserveInInfo *reserves,
+ unsigned int reserves_length,
+ enum GNUNET_DB_QueryStatus *results);
/**
@@ -3127,7 +3885,7 @@ struct TALER_EXCHANGEDB_Plugin
*/
enum GNUNET_DB_QueryStatus
(*lock_nonce)(void *cls,
- const struct TALER_CsNonce *nonce,
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
const struct TALER_DenominationHashP *denom_pub_hash,
const union TALER_EXCHANGEDB_NonceLockTargetP *target);
@@ -3146,34 +3904,18 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus
(*get_withdraw_info)(void *cls,
const struct TALER_BlindedCoinHashP *bch,
- struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable);
+ struct TALER_EXCHANGEDB_CollectableBlindcoin *
+ collectable);
/**
- * Perform withdraw operation, checking for sufficient balance
- * and possibly persisting the withdrawal details.
- *
- * @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param nonce client-contributed input for CS denominations that must be checked for idempotency, or NULL for non-CS withdrawals
- * @param collectable corresponding collectable coin (blind signature)
- * @param now current time (rounded)
- * @param[out] found set to true if the reserve was found
- * @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] kyc set to the KYC status of the reserve
- * @param[out] ruuid set to the reserve's UUID (reserves table row)
- * @return query execution status
+ * FIXME: merge do_batch_withdraw and do_batch_withdraw_insert into one API,
+ * which takes as input (among others)
+ * - denom_serial[]
+ * - blinded_coin_evs[]
+ * - denom_sigs[]
+ * The implementation should persist the data as _arrays_ in the DB.
*/
- enum GNUNET_DB_QueryStatus
- (*do_withdraw)(
- void *cls,
- const struct TALER_CsNonce *nonce,
- const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
- struct GNUNET_TIME_Timestamp now,
- bool *found,
- bool *balance_ok,
- struct TALER_EXCHANGEDB_KycStatus *kyc_ok,
- uint64_t *ruuid);
-
/**
* Perform reserve update as part of a batch withdraw operation, checking
@@ -3184,9 +3926,12 @@ struct TALER_EXCHANGEDB_Plugin
* @param now current time (rounded)
* @param reserve_pub public key of the reserve to debit
* @param amount total amount to withdraw
+ * @param do_age_check if set, the batch-withdrawal can only succeed when the reserve has no age restriction (birthday) set.
* @param[out] found set to true if the reserve was found
* @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] kyc set to the KYC status of the reserve
+ * @param[out] reserve_balance set to original balance of the reserve
+ * @param[out] age_ok set to true if no age requirements were defined on the reserve or @e do_age_check was false
+ * @param[out] allowed_maximum_age when @e age_ok is false, set to the allowed maximum age for withdrawal from the reserve. The client MUST then use the age-withdraw endpoint
* @param[out] ruuid set to the reserve's UUID (reserves table row)
* @return query execution status
*/
@@ -3196,9 +3941,12 @@ struct TALER_EXCHANGEDB_Plugin
struct GNUNET_TIME_Timestamp now,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_Amount *amount,
+ bool do_age_check,
bool *found,
bool *balance_ok,
- struct TALER_EXCHANGEDB_KycStatus *kyc_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *allowed_maximum_age,
uint64_t *ruuid);
@@ -3219,7 +3967,7 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus
(*do_batch_withdraw_insert)(
void *cls,
- const struct TALER_CsNonce *nonce,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_EXCHANGEDB_CollectableBlindcoin *collectable,
struct GNUNET_TIME_Timestamp now,
uint64_t ruuid,
@@ -3227,25 +3975,85 @@ struct TALER_EXCHANGEDB_Plugin
bool *conflict,
bool *nonce_reuse);
+ /**
+ * Locate the response for a age-withdraw request under a hash of the
+ * commitment and reserve_pub that uniquely identifies the age-withdraw
+ * operation. Used to ensure idempotency of the request.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the reserve for which the age-withdraw request is made
+ * @param ach hash that uniquely identifies the age-withdraw operation
+ * @param[out] aw corresponding details of the previous age-withdraw request if an entry was found
+ * @return statement execution status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_age_withdraw)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_AgeWithdrawCommitmentHashP *ach,
+ struct TALER_EXCHANGEDB_AgeWithdraw *aw);
/**
- * Check that reserve remains below threshold for KYC
- * checks after withdraw operation.
+ * Perform an age-withdraw operation, checking for sufficient balance and
+ * fulfillment of age requirements and possibly persisting the withdrawal
+ * details.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param ruuid identifies the reserve to check
- * @param withdraw_start starting point to accumulate from
- * @param upper_limit maximum amount allowed
- * @param[out] below_limit set to true if the limit was not exceeded
+ * @param commitment corresponding commitment for the age-withdraw
+ * @param[out] found set to true if the reserve was found
+ * @param[out] balance_ok set to true if the balance was sufficient
+ * @param[out] reserve_balance set to original balance of the reserve
+ * @param[out] age_ok set to true if age requirements were met
+ * @param[out] allowed_maximum_age if @e age_ok is FALSE, this is set to the allowed maximum age
+ * @param[out] reserve_birthday if @e age_ok is FALSE, this is set to the reserve's birthday
* @return query execution status
*/
enum GNUNET_DB_QueryStatus
- (*do_withdraw_limit_check)(
+ (*do_age_withdraw)(
void *cls,
- uint64_t ruuid,
- struct GNUNET_TIME_Absolute withdraw_start,
- const struct TALER_Amount *upper_limit,
- bool *below_limit);
+ const struct TALER_EXCHANGEDB_AgeWithdraw *commitment,
+ struct GNUNET_TIME_Timestamp now,
+ bool *found,
+ bool *balance_ok,
+ struct TALER_Amount *reserve_balance,
+ bool *age_ok,
+ uint16_t *allowed_maximum_age,
+ uint32_t *reserve_birthday,
+ bool *conflict);
+
+ /**
+ * Retrieve the details to a policy given by its hash_code
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param hc Hash code that identifies the policy
+ * @param[out] detail retrieved policy details
+ * @return query execution status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_policy_details)(
+ void *cls,
+ const struct GNUNET_HashCode *hc,
+ struct TALER_PolicyDetails *detail);
+
+ /**
+ * Persist the policy details that extends a deposit. The particular policy
+ * - referenced by details->hash_code - might already exist in the table, in
+ * which case the call will update the contents of the record with @e details
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @param details The parsed `struct TALER_PolicyDetails` according to the responsible policy extension.
+ * @param[out] policy_details_serial_id The ID of the entry in the policy_details table
+ * @param[out] accumulated_total The total amount accumulated in that policy
+ * @param[out] fulfillment_state The state of policy. If the state was Insufficient prior to the call and the provided deposit raises the accumulated_total above the commitment, it will be set to Ready.
+ * @return query execution status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*persist_policy_details)(
+ void *cls,
+ const struct TALER_PolicyDetails *details,
+ uint64_t *policy_details_serial_id,
+ struct TALER_Amount *accumulated_total,
+ enum TALER_PolicyFulfillmentState *fulfillment_state);
/**
@@ -3253,25 +4061,22 @@ struct TALER_EXCHANGEDB_Plugin
* of the coin and possibly persisting the deposit details.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
- * @param deposit deposit operation details
- * @param known_coin_id row of the coin in the known_coins table
- * @param h_payto hash of the merchant's payto URI
- * @param extension_blocked true if an extension is blocking the wire transfer
+ * @param bd batch deposit operation details
* @param[in,out] exchange_timestamp time to use for the deposit (possibly updated)
* @param[out] balance_ok set to true if the balance was sufficient
- * @param[out] in_conflict set to true if the deposit conflicted
+ * @param[out] bad_balance_index set to the first index of a coin for which the balance was insufficient,
+ * only used if @a balance_ok is set to false.
+ * @param[out] ctr_conflict set to true if the same contract terms hash was previously submitted with other meta data (deadlines, wallet_data_hash, wire data etc.)
* @return query execution status
*/
enum GNUNET_DB_QueryStatus
(*do_deposit)(
void *cls,
- const struct TALER_EXCHANGEDB_Deposit *deposit,
- uint64_t known_coin_id,
- const struct TALER_PaytoHashP *h_payto,
- bool extension_blocked,
+ const struct TALER_EXCHANGEDB_BatchDeposit *bd,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
- bool *in_conflict);
+ uint32_t *bad_balance_index,
+ bool *ctr_conflict);
/**
@@ -3298,6 +4103,19 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Add a proof of fulfillment of an policy
+ *
+ * @param cls the plugin-specific state
+ * @param[in,out] fulfillment The proof of fulfillment and serial_ids of the policy_details along with their new state and potential new amounts.
+ * @return query execution status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*add_policy_fulfillment_proof)(
+ void *cls,
+ struct TALER_PolicyFulfillmentTransactionData *fulfillment);
+
+
+ /**
* Check if the given @a nonce was properly locked to the given @a old_coin_pub. If so, check if we already
* created CS signatures for the given @a nonce and @a new_denom_pub_hashes,
* and if so, return them in @a s_scalars. Otherwise, persist the
@@ -3313,7 +4131,7 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus
(*cs_refreshes_reveal)(
void *cls,
- const struct TALER_CsNonce *nonce,
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
unsigned int num_fresh_coins,
struct TALER_EXCHANGEDB_CsRevealFreshCoinData *crfcds);
@@ -3366,7 +4184,7 @@ struct TALER_EXCHANGEDB_Plugin
void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
uint64_t reserve_out_serial_id,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
uint64_t known_coin_id,
const struct TALER_CoinSpendSignatureP *coin_sig,
@@ -3396,7 +4214,7 @@ struct TALER_EXCHANGEDB_Plugin
void *cls,
const struct TALER_CoinSpendPublicKeyP *old_coin_pub,
uint64_t rrc_serial,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
uint64_t known_coin_id,
const struct TALER_CoinSpendSignatureP *coin_sig,
@@ -3406,11 +4224,18 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Get all of the transaction history associated with the specified
- * reserve.
+ * Compile a list of (historic) transactions performed with the given reserve
+ * (withdraw, incoming wire, open, close operations). Should return 0 if the @a
+ * reserve_pub is unknown, otherwise determine @a etag_out and if it is past @a
+ * etag_in return the history after @a start_off. @a etag_out should be set
+ * to the last row ID of the given @a reserve_pub in the reserve history table.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param reserve_pub public key of the reserve
+ * @param start_off maximum starting offset in history to exclude from returning
+ * @param etag_in up to this offset the client already has a response, do not
+ * return anything unless @a etag_out will be larger
+ * @param[out] etag_out set to the latest history offset known for this @a coin_pub
* @param[out] balance set to the reserve balance
* @param[out] rhp set to known transaction history (NULL if reserve is unknown)
* @return transaction status
@@ -3418,28 +4243,14 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus
(*get_reserve_history)(void *cls,
const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
struct TALER_Amount *balance,
struct TALER_EXCHANGEDB_ReserveHistory **rhp);
/**
- * Get truncated transaction history associated with the specified
- * reserve.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the reserve
- * @param[out] balance set to the reserve balance
- * @param[out] rhp set to known transaction history (NULL if reserve is unknown)
- * @return transaction status
- */
- enum GNUNET_DB_QueryStatus
- (*get_reserve_status)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- struct TALER_Amount *balance,
- struct TALER_EXCHANGEDB_ReserveHistory **rhp);
-
-
- /**
* The current reserve balance of the specified reserve.
*
* @param cls the @e cls of this struct with the plugin-specific state
@@ -3514,9 +4325,20 @@ struct TALER_EXCHANGEDB_Plugin
TALER_EXCHANGEDB_CKS_DENOM_CONFLICT = -3,
/**
+ * Conflicting coin (expected NULL age hash) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NULL = -4,
+
+ /**
+ * Conflicting coin (unexpected NULL age hash) already in database.
+ */
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_EXPECTED_NON_NULL = -5,
+
+ /**
* Conflicting coin (different age hash) already in database.
*/
- TALER_EXCHANGEDB_CKS_AGE_CONFLICT = -4,
+ TALER_EXCHANGEDB_CKS_AGE_CONFLICT_VALUE_DIFFERS = -6,
+
}
(*ensure_coin_known)(void *cls,
const struct TALER_CoinPublicInfo *coin,
@@ -3526,10 +4348,30 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Make sure the array of given @a coin is known to the database.
+ *
+ * @param cls database connection plugin state
+ * @param coin array of coins that must be made known
+ * @param[out] result array where to store information about each coin
+ * @param coin_length length of the @a coin and @a result arraysf
+ * @param batch_size desired (maximum) batch size
+ * @return database transaction status, non-negative on success
+ */
+ enum GNUNET_DB_QueryStatus
+ (*batch_ensure_coin_known)(
+ void *cls,
+ const struct TALER_CoinPublicInfo *coin,
+ struct TALER_EXCHANGEDB_CoinInfo *result,
+ unsigned int coin_length,
+ unsigned int batch_size);
+
+
+ /**
* Retrieve information about the given @a coin from the database.
*
* @param cls database connection plugin state
- * @param coin the coin that must be made known
+ * @param coin_pub the coin that must be made known
+ * @param[out] coin_info detailed information about the coin
* @return database transaction status, non-negative on success
*/
enum GNUNET_DB_QueryStatus
@@ -3537,6 +4379,21 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_CoinSpendPublicKeyP *coin_pub,
struct TALER_CoinPublicInfo *coin_info);
+ /**
+ * Retrieve the signature and corresponding denomination for a given @a coin
+ * from the database
+ *
+ * @param cls database connection plugin state
+ * @param coin_pub the public key of the coin we search for
+ * @param[out] denom_pub the public key of the denomination that the coin was signed with
+ * @param[out] denom_sig the signature with the denomination's private key over the coin_pub
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_signature_for_known_coin)(
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_DenominationPublicKey *denom_pub,
+ struct TALER_DenominationSignature *denom_sig);
/**
* Retrieve the denomination of a known coin.
@@ -3555,6 +4412,25 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Try to retrieve the salted hash of the merchant's bank account to a
+ * deposit contract. Used in case of conflicts for a given (merchant_pub,
+ * h_contract_terms) to provide the client the necessary input to retrieve
+ * more details about the conflict.
+ *
+ * @param cls the plugin closure
+ * @param merchant_pub public key of the merchant
+ * @param h_contract_terms contract to check for
+ * @param[out] h_wire hash of the wire details
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_wire_hash_for_contract)(
+ void *cls,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct TALER_MerchantWireHashP *h_wire);
+
+
+ /**
* Check if we have the specified deposit already in the database.
*
* @param cls the `struct PostgresClosure` with the plugin-specific state
@@ -3583,21 +4459,6 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Insert information about deposited coin into the database.
- * Used in tests and for benchmarking.
- *
- * @param cls the @e cls of this struct with the plugin-specific state
- * @param exchange_timestamp time the exchange received the deposit request
- * @param deposit deposit information to store
- * @return query result status
- */
- enum GNUNET_DB_QueryStatus
- (*insert_deposit)(void *cls,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- const struct TALER_EXCHANGEDB_Deposit *deposit);
-
-
- /**
* Insert information about refunded coin into the database.
* Used in tests and for benchmarking.
*
@@ -3622,12 +4483,13 @@ struct TALER_EXCHANGEDB_Plugin
* @return query result status
*/
enum GNUNET_DB_QueryStatus
- (*select_refunds_by_coin)(void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_PrivateContractHashP *h_contract,
- TALER_EXCHANGEDB_RefundCoinCallback cb,
- void *cb_cls);
+ (*select_refunds_by_coin)(
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_PrivateContractHashP *h_contract,
+ TALER_EXCHANGEDB_RefundCoinCallback cb,
+ void *cb_cls);
/**
@@ -3639,8 +4501,6 @@ struct TALER_EXCHANGEDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param start_shard_row minimum shard row to select
* @param end_shard_row maximum shard row to select (inclusive)
- * @param kyc_off true if we should not check the KYC status because
- * this exchange does not need/support KYC checks.
* @param[out] merchant_pub set to the public key of a merchant with a ready deposit
* @param[out] payto_uri set to the account of the merchant, to be freed by caller
* @return transaction status code
@@ -3649,18 +4509,10 @@ struct TALER_EXCHANGEDB_Plugin
(*get_ready_deposit)(void *cls,
uint64_t start_shard_row,
uint64_t end_shard_row,
- bool kyc_off,
struct TALER_MerchantPublicKeyP *merchant_pub,
char **payto_uri);
-/**
- * Maximum number of results we return from iterate_matching_deposits().
- *
- * Limit on the number of transactions we aggregate at once.
- */
-#define TALER_EXCHANGEDB_MATCHING_DEPOSITS_LIMIT 10000
-
/**
* Aggregate all matching deposits for @a h_payto and
* @a merchant_pub, returning the total amounts.
@@ -3687,7 +4539,9 @@ struct TALER_EXCHANGEDB_Plugin
* @param cls the @e cls of this struct with the plugin-specific state
* @param h_payto destination of the wire transfer
* @param exchange_account_section exchange account to use
+ * @param merchant_pub public key of the merchant
* @param wtid the raw wire transfer identifier to be used
+ * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
* @param total amount to be wired in the future
* @return transaction status
*/
@@ -3696,15 +4550,18 @@ struct TALER_EXCHANGEDB_Plugin
void *cls,
const struct TALER_PaytoHashP *h_payto,
const char *exchange_account_section,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
const struct TALER_Amount *total);
/**
- * Find existing entry in the transient aggregation table.
+ * Select existing entry in the transient aggregation table.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param h_payto destination of the wire transfer
+ * @param merchant_pub public key of the merchant
* @param exchange_account_section exchange account to use
* @param[out] wtid set to the raw wire transfer identifier to be used
* @param[out] total existing amount to be wired in the future
@@ -3714,18 +4571,37 @@ struct TALER_EXCHANGEDB_Plugin
(*select_aggregation_transient)(
void *cls,
const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
const char *exchange_account_section,
struct TALER_WireTransferIdentifierRawP *wtid,
struct TALER_Amount *total);
/**
+ * Find existing entry in the transient aggregation table.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto destination of the wire transfer
+ * @param cb function to call on each matching entry
+ * @param cb_cls closure for @a cb
+ * @return transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*find_aggregation_transient)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_TransientAggregationCallback cb,
+ void *cb_cls);
+
+
+ /**
* Update existing entry in the transient aggregation table.
* @a h_payto is only needed for query performance.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param h_payto destination of the wire transfer
* @param wtid the raw wire transfer identifier to update
+ * @param kyc_requirement_row row in legitimization_requirements that need to be satisfied to continue, or 0 for none
* @param total new total amount to be wired in the future
* @return transaction status
*/
@@ -3734,6 +4610,7 @@ struct TALER_EXCHANGEDB_Plugin
void *cls,
const struct TALER_PaytoHashP *h_payto,
const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t kyc_requirement_row,
const struct TALER_Amount *total);
@@ -3833,20 +4710,35 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Compile a list of all (historic) transactions performed
- * with the given coin (melt, refund, recoup and deposit operations).
+ * Compile a list of (historic) transactions performed with the given coin
+ * (melt, refund, recoup and deposit operations). Should return 0 if the @a
+ * coin_pub is unknown, otherwise determine @a etag_out and if it is past @a
+ * etag_in return the history after @a start_off. @a etag_out should be set
+ * to the last row ID of the given @a coin_pub in the coin history table.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param coin_pub coin to investigate
- * @param include_recoup include recoup transactions of the coin?
- * @param[out] tlp set to list of transactions, NULL if coin is fresh
+ * @param start_off starting offset from which on to return entries
+ * @param etag_in up to this offset the client already has a response, do not
+ * return anything unless @a etag_out will be larger
+ * @param[out] etag_out set to the latest history offset known for this @a coin_pub
+ * @param[out] balance set to current balance of the coin
+ * @param[out] h_denom_pub set to denomination public key of the coin
+ * @param[out] tlp set to list of transactions, set to NULL if coin has no
+ * transaction history past @a start_off or if @a etag_in is equal
+ * to the value written to @a etag_out.
* @return database transaction status
*/
enum GNUNET_DB_QueryStatus
- (*get_coin_transactions)(void *cls,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- bool include_recoup,
- struct TALER_EXCHANGEDB_TransactionList **tlp);
+ (*get_coin_transactions)(
+ void *cls,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ uint64_t start_off,
+ uint64_t etag_in,
+ uint64_t *etag_out,
+ struct TALER_Amount *balance,
+ struct TALER_DenominationHashP *h_denom_pub,
+ struct TALER_EXCHANGEDB_TransactionList **tlp);
/**
@@ -3895,6 +4787,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param[out] execution_time when was the transaction done, or
* when we expect it to be done (if @a pending is false)
* @param[out] kyc set to the kyc status of the receiver (if @a pending)
+ * @param[out] aml_decision set to the current AML status for the target account
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@@ -3909,22 +4802,8 @@ struct TALER_EXCHANGEDB_Plugin
struct GNUNET_TIME_Timestamp *exec_time,
struct TALER_Amount *amount_with_fee,
struct TALER_Amount *deposit_fee,
- struct TALER_EXCHANGEDB_KycStatus *kyc);
-
-
- /**
- * Function called to insert aggregation information into the DB.
- *
- * @param cls closure
- * @param wtid the raw wire transfer identifier we used
- * @param deposit_serial_id row in the deposits table for which this is aggregation data
- * @return transaction status code
- */
- enum GNUNET_DB_QueryStatus
- (*insert_aggregation_tracking)(
- void *cls,
- const struct TALER_WireTransferIdentifierRawP *wtid,
- unsigned long long deposit_serial_id);
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ enum TALER_AmlDecisionState *aml_decision);
/**
@@ -3955,7 +4834,6 @@ struct TALER_EXCHANGEDB_Plugin
* @param end_date when does the fees end being valid
* @param fees how high is are the global fees
* @param purse_timeout when do purses time out
- * @param kyc_timeout when do reserves without KYC time out
* @param history_expiration how long are account histories preserved
* @param purse_account_limit how many purses are free per account
* @param master_sig signature over the above by the exchange master key
@@ -3967,7 +4845,6 @@ struct TALER_EXCHANGEDB_Plugin
struct GNUNET_TIME_Timestamp end_date,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
@@ -4005,7 +4882,6 @@ struct TALER_EXCHANGEDB_Plugin
* @param[out] end_date when does the fee end being valid
* @param[out] fees how high are the global fees
* @param[out] purse_timeout when do purses time out
- * @param[out] kyc_timeout when do reserves without KYC time out
* @param[out] history_expiration how long are account histories preserved
* @param[out] purse_account_limit how many purses are free per account
* @param[out] master_sig signature over the above by the exchange master key
@@ -4018,7 +4894,6 @@ struct TALER_EXCHANGEDB_Plugin
struct GNUNET_TIME_Timestamp *end_date,
struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative *purse_timeout,
- struct GNUNET_TIME_Relative *kyc_timeout,
struct GNUNET_TIME_Relative *history_expiration,
uint32_t *purse_account_limit,
struct TALER_MasterSignatureP *master_sig);
@@ -4042,6 +4917,152 @@ struct TALER_EXCHANGEDB_Plugin
/**
+ * Obtain information about force-closed reserves
+ * where the close was not yet done (and their remaining
+ * balances). Updates the returned reserve's close
+ * status to "done".
+ *
+ * @param cls closure of the plugin
+ * @param rec function to call on (to be) closed reserves
+ * @param rec_cls closure for @a rec
+ * @return transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_unfinished_close_requests)(
+ void *cls,
+ TALER_EXCHANGEDB_ReserveExpiredCallback rec,
+ void *rec_cls);
+
+
+ /**
+ * Insert reserve open coin deposit data into database.
+ * Subtracts the @a coin_total from the coin's balance.
+ *
+ * @param cls closure
+ * @param cpi public information about the coin
+ * @param coin_sig signature with @e coin_pub of type #TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT
+ * @param known_coin_id ID of the coin in the known_coins table
+ * @param coin_total amount to be spent of the coin (including deposit fee)
+ * @param reserve_sig signature by the reserve affirming the open operation
+ * @param reserve_pub public key of the reserve being opened
+ * @param[out] insufficient_funds set to true if the coin's balance is insufficient, otherwise to false
+ * @return transaction status code, 0 if operation is already in the DB
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_reserve_open_deposit)(
+ void *cls,
+ const struct TALER_CoinPublicInfo *cpi,
+ const struct TALER_CoinSpendSignatureP *coin_sig,
+ uint64_t known_coin_id,
+ const struct TALER_Amount *coin_total,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *insufficient_funds);
+
+
+ /**
+ * Insert reserve close operation into database.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param total_paid total amount paid (coins and reserve)
+ * @param reserve_payment amount to be paid from the reserve
+ * @param min_purse_limit minimum number of purses we should be able to open
+ * @param reserve_sig signature by the reserve for the operation
+ * @param desired_expiration when should the reserve expire (earliest time)
+ * @param now when did we the client initiate the action
+ * @param open_fee annual fee to be charged for the open operation by the exchange
+ * @param[out] no_funds set to true if reserve balance is insufficient
+ * @param[out] reserve_balance set to original balance of the reserve
+ * @param[out] open_cost set to the actual cost
+ * @param[out] final_expiration when will the reserve expire now
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*do_reserve_open)(void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *total_paid,
+ const struct TALER_Amount *reserve_payment,
+ uint32_t min_purse_limit,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp desired_expiration,
+ struct GNUNET_TIME_Timestamp now,
+ const struct TALER_Amount *open_fee,
+ bool *no_funds,
+ struct TALER_Amount *reserve_balance,
+ struct TALER_Amount *open_cost,
+ struct GNUNET_TIME_Timestamp *final_expiration);
+
+
+ /**
+ * Select information needed to see if we can close
+ * a reserve.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param[out] balance current reserve balance
+ * @param[out] payto_uri set to URL of account that
+ * originally funded the reserve;
+ * could be set to NULL if not known
+ * @return transaction status code, 0 if reserve unknown
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_reserve_close_info)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ struct TALER_Amount *balance,
+ char **payto_uri);
+
+
+ /**
+ * Select information about reserve close requests.
+ *
+ * @param cls closure
+ * @param reserve_pub which reserve is this about?
+ * @param rowid row ID of the close request
+ * @param[out] reserve_sig reserve signature affirming
+ * @param[out] request_timestamp when was the request made
+ * @param[out] close_balance reserve balance at close time
+ * @param[out] close_fee closing fee to be charged
+ * @param[out] payto_uri set to URL of account that
+ * should receive the money;
+ * could be set to NULL for origin
+ * @return transaction status code, 0 if reserve unknown
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_reserve_close_request_info)(
+ void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t rowid,
+ struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *close_balance,
+ struct TALER_Amount *close_fee,
+ char **payto_uri);
+
+
+ /**
+ * Select information needed for KYC checks on reserve close: historic
+ * reserve closures going to the same account.
+ *
+ * @param cls closure
+ * @param h_payto which target account is this about?
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+ enum GNUNET_DB_QueryStatus
+ (*iterate_reserve_close_info)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+
+ /**
* Insert reserve close operation into database.
*
* @param cls closure
@@ -4051,6 +5072,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param wtid identifier for the wire transfer
* @param amount_with_fee amount we charged to the reserve
* @param closing_fee how high is the closing fee
+ * @param close_request_row identifies explicit close request, 0 for none
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@@ -4058,9 +5080,11 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_ReservePublicKeyP *reserve_pub,
struct GNUNET_TIME_Timestamp execution_date,
const char *receiver_account,
- const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct
+ TALER_WireTransferIdentifierRawP *wtid,
const struct TALER_Amount *amount_with_fee,
- const struct TALER_Amount *closing_fee);
+ const struct TALER_Amount *closing_fee,
+ uint64_t close_request_row);
/**
@@ -4180,10 +5204,29 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*select_deposits_above_serial_id)(void *cls,
- uint64_t serial_id,
- TALER_EXCHANGEDB_DepositCallback cb,
- void *cb_cls);
+ (*select_coin_deposits_above_serial_id)(void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_DepositCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Function called to return meta data about a purses
+ * above a certain serial ID.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param serial_id number to select requests by
+ * @param cb function to call on each request
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_purse_requests_above_serial_id)(
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_PurseRequestCallback cb,
+ void *cb_cls);
+
/**
* Select purse deposits above @a serial_id in monotonically increasing
@@ -4240,25 +5283,27 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Select history requests above @a serial_id in monotonically increasing
+ * Select purse refunds above @a serial_id in monotonically increasing
* order.
*
* @param cls closure
* @param serial_id highest serial ID to exclude (select strictly larger)
+ * @param refunded which refund status to select for
* @param cb function to call on each result
* @param cb_cls closure for @a cb
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*select_history_requests_above_serial_id)(
+ (*select_purse_decisions_above_serial_id)(
void *cls,
uint64_t serial_id,
- TALER_EXCHANGEDB_HistoryRequestCallback cb,
+ bool refunded,
+ TALER_EXCHANGEDB_PurseDecisionCallback cb,
void *cb_cls);
/**
- * Select purse refunds above @a serial_id in monotonically increasing
+ * Select all purse refunds above @a serial_id in monotonically increasing
* order.
*
* @param cls closure
@@ -4268,10 +5313,10 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*select_purse_refunds_above_serial_id)(
+ (*select_all_purse_decisions_above_serial_id)(
void *cls,
uint64_t serial_id,
- TALER_EXCHANGEDB_PurseRefundCallback cb,
+ TALER_EXCHANGEDB_AllPurseDecisionCallback cb,
void *cb_cls);
@@ -4395,7 +5440,8 @@ struct TALER_EXCHANGEDB_Plugin
enum GNUNET_DB_QueryStatus
(*select_wire_out_above_serial_id)(void *cls,
uint64_t serial_id,
- TALER_EXCHANGEDB_WireTransferOutCallback cb,
+ TALER_EXCHANGEDB_WireTransferOutCallback
+ cb,
void *cb_cls);
/**
@@ -4454,8 +5500,8 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Function called to select reserve close operations the aggregator
- * triggered, ordered by serial ID (monotonically increasing).
+ * Function called to select reserve open operations, ordered by serial ID
+ * (monotonically increasing).
*
* @param cls closure
* @param serial_id lowest serial ID to include (select larger or equal)
@@ -4464,6 +5510,24 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
+ (*select_reserve_open_above_serial_id)(
+ void *cls,
+ uint64_t serial_id,
+ TALER_EXCHANGEDB_ReserveOpenCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Function called to select reserve close operations the aggregator
+ * triggered, ordered by serial ID (monotonically increasing).
+ *
+ * @param cls closure
+ * @param serial_id lowest serial ID to include (select larger or equal)
+ * @param cb function to call
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
(*select_reserve_closed_above_serial_id)(
void *cls,
uint64_t serial_id,
@@ -4482,10 +5546,11 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_reserve_by_h_blind)(void *cls,
- const struct TALER_BlindedCoinHashP *bch,
- struct TALER_ReservePublicKeyP *reserve_pub,
- uint64_t *reserve_out_serial_id);
+ (*get_reserve_by_h_blind)(
+ void *cls,
+ const struct TALER_BlindedCoinHashP *bch,
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ uint64_t *reserve_out_serial_id);
/**
@@ -4499,10 +5564,11 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_old_coin_by_h_blind)(void *cls,
- const struct TALER_BlindedCoinHashP *h_blind_ev,
- struct TALER_CoinSpendPublicKeyP *old_coin_pub,
- uint64_t *rrc_serial);
+ (*get_old_coin_by_h_blind)(
+ void *cls,
+ const struct TALER_BlindedCoinHashP *h_blind_ev,
+ struct TALER_CoinSpendPublicKeyP *old_coin_pub,
+ uint64_t *rrc_serial);
/**
@@ -4540,23 +5606,63 @@ struct TALER_EXCHANGEDB_Plugin
/**
- * Select all of those deposits in the database for which we do
- * not have a wire transfer (or a refund) and which should have
- * been deposited between @a start_date and @a end_date.
+ * Select all (batch) deposits in the database
+ * above a given @a min_batch_deposit_serial_id.
*
* @param cls closure
- * @param start_date lower bound on the requested wire execution date
- * @param end_date upper bound on the requested wire execution date
+ * @param min_batch_deposit_serial_id only return entries strictly above this row (and in order)
* @param cb function to call on all such deposits
* @param cb_cls closure for @a cb
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*select_deposits_missing_wire)(void *cls,
- struct GNUNET_TIME_Timestamp start_date,
- struct GNUNET_TIME_Timestamp end_date,
- TALER_EXCHANGEDB_WireMissingCallback cb,
- void *cb_cls);
+ (*select_batch_deposits_missing_wire)(
+ void *cls,
+ uint64_t min_batch_deposit_serial_id,
+ TALER_EXCHANGEDB_WireMissingCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Select all aggregation tracking IDs in the database
+ * above a given @a min_tracking_serial_id.
+ *
+ * @param cls closure
+ * @param min_tracking_serial_id only return entries strictly above this row (and in order)
+ * @param cb function to call on all such aggregations
+ * @param cb_cls closure for @a cb
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_aggregations_above_serial)(
+ void *cls,
+ uint64_t min_tracking_serial_id,
+ TALER_EXCHANGEDB_AggregationCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Return any applicable justification as to why
+ * a wire transfer might have been held. Used
+ * by the auditor to determine if a wire transfer
+ * is legitimately stalled.
+ *
+ * @param cls closure
+ * @param wire_target_h_payto effected target account
+ * @param[out] payto_uri target account URI, set to NULL if unknown
+ * @param[out] kyc_pending set to string describing missing KYC data
+ * @param[out] status set to AML status
+ * @param[out] aml_limit set to AML limit, or invalid amount for none
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_justification_for_missing_wire)(
+ void *cls,
+ const struct TALER_PaytoHashP *wire_target_h_payto,
+ char **payto_uri,
+ char **kyc_pending,
+ enum TALER_AmlDecisionState *status,
+ struct TALER_Amount *aml_limit);
/**
@@ -4568,9 +5674,10 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_auditor_timestamp)(void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- struct GNUNET_TIME_Timestamp *last_date);
+ (*lookup_auditor_timestamp)(
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ struct GNUNET_TIME_Timestamp *last_date);
/**
@@ -4584,10 +5691,11 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*lookup_auditor_status)(void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- char **auditor_url,
- bool *enabled);
+ (*lookup_auditor_status)(
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ char **auditor_url,
+ bool *enabled);
/**
@@ -4602,11 +5710,12 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_auditor)(void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- const char *auditor_url,
- const char *auditor_name,
- struct GNUNET_TIME_Timestamp start_date);
+ (*insert_auditor)(
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp start_date);
/**
@@ -4622,12 +5731,13 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*update_auditor)(void *cls,
- const struct TALER_AuditorPublicKeyP *auditor_pub,
- const char *auditor_url,
- const char *auditor_name,
- struct GNUNET_TIME_Timestamp change_date,
- bool enabled);
+ (*update_auditor)(
+ void *cls,
+ const struct TALER_AuditorPublicKeyP *auditor_pub,
+ const char *auditor_url,
+ const char *auditor_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool enabled);
/**
@@ -4649,17 +5759,27 @@ struct TALER_EXCHANGEDB_Plugin
*
* @param cls closure
* @param payto_uri wire account of the exchange
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account
+ * @param credit_restrictions JSON array with credit restrictions on the account
* @param start_date date when the account was added by the offline system
* (only to be used for replay detection)
* @param master_sig public signature affirming the existence of the account,
* must be of purpose #TALER_SIGNATURE_MASTER_WIRE_DETAILS
+ * @param bank_label label to show this entry under in the UI, can be NULL
+ * @param priority determines order in which entries are shown in the UI
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*insert_wire)(void *cls,
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp start_date,
- const struct TALER_MasterSignatureP *master_sig);
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority);
/**
@@ -4667,15 +5787,27 @@ struct TALER_EXCHANGEDB_Plugin
*
* @param cls closure
* @param payto_uri account the update is about
+ * @param conversion_url URL of a conversion service, NULL if there is no conversion
+ * @param debit_restrictions JSON array with debit restrictions on the account; NULL allowed if not @a enabled
+ * @param credit_restrictions JSON array with credit restrictions on the account; NULL allowed if not @a enabled
* @param change_date date when the account status was last changed
* (only to be used for replay detection)
+ * @param master_sig master signature to store, can be NULL (if @a enabled is false)
+ * @param bank_label label to show this entry under in the UI, can be NULL
+ * @param priority determines order in which entries are shown in the UI
* @param enabled true to enable, false to disable (the actual change)
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*update_wire)(void *cls,
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp change_date,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *bank_label,
+ int64_t priority,
bool enabled);
@@ -4886,7 +6018,6 @@ struct TALER_EXCHANGEDB_Plugin
* different global fee exists within this time
* period, an 'invalid' amount is returned.
* @param[out] purse_timeout set to when unmerged purses expire
- * @param[out] kyc_timeout set to when reserves without kyc expire
* @param[out] history_expiration set to when we expire reserve histories
* @param[out] purse_account_limit set to number of free purses
* @return transaction status code
@@ -4898,7 +6029,6 @@ struct TALER_EXCHANGEDB_Plugin
struct GNUNET_TIME_Timestamp end_time,
struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative *purse_timeout,
- struct GNUNET_TIME_Relative *kyc_timeout,
struct GNUNET_TIME_Relative *history_expiration,
uint32_t *purse_account_limit);
@@ -4942,6 +6072,7 @@ struct TALER_EXCHANGEDB_Plugin
* Insert record set into @a table. Used in exchange-auditor database
* replication.
*
+ memset (&awc, 0, sizeof (awc));
* @param cls closure
* @param tb table data to insert
* @return transaction status code, #GNUNET_DB_STATUS_HARD_ERROR if
@@ -5047,40 +6178,41 @@ struct TALER_EXCHANGEDB_Plugin
* changed.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @return transaction status code
+ * @return #GNUNET_OK on success
+ * #GNUNET_SYSERR on failure
*/
- enum GNUNET_DB_QueryStatus
+ enum GNUNET_GenericReturnValue
(*delete_shard_locks)(void *cls);
/**
- * Function called to save the configuration of an extension
- * (age-restriction, peer2peer, ...)
+ * Function called to save the manifest of an extension
+ * (age-restriction, policy-extension, ...)
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param extension_name the name of the extension
- * @param config JSON object of the configuration as string, maybe NULL (== disabled extension)
+ * @param manifest JSON object of the Manifest as string, maybe NULL (== disabled extension)
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*set_extension_config)(void *cls,
- const char *extension_name,
- const char *config);
+ (*set_extension_manifest)(void *cls,
+ const char *extension_name,
+ const char *manifest);
/**
- * Function called to retrieve the configuration of an extension
- * (age-restriction, peer2peer, ...)
+ * Function called to retrieve the manifest of an extension
+ * (age-restriction, policy-extension, ...)
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param extension_name the name of the extension
- * @param[out] config JSON object of the configuration as string, maybe NULL (== disabled extension)
+ * @param[out] manifest Manifest of the extension in JSON encoding, maybe NULL (== disabled extension)
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*get_extension_config)(void *cls,
- const char *extension_name,
- char **config);
+ (*get_extension_manifest)(void *cls,
+ const char *extension_name,
+ char **manifest);
/**
@@ -5217,22 +6349,28 @@ struct TALER_EXCHANGEDB_Plugin
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param purse_pub public key of the new purse
+ * @param[out] purse_creation set to time when the purse was created
* @param[out] purse_expiration set to time when the purse will expire
* @param[out] amount set to target amount (with fees) to be put into the purse
* @param[out] deposited set to actual amount put into the purse so far
* @param[out] h_contract_terms set to hash of the contract for the purse
* @param[out] merge_timestamp set to time when the purse was merged, or NEVER if not
+ * @param[out] purse_deleted set to true if purse was deleted
+ * @param[out] purse_refunded set to true if purse was refunded (after expiration)
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
(*select_purse)(
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct GNUNET_TIME_Timestamp *purse_creation,
struct GNUNET_TIME_Timestamp *purse_expiration,
struct TALER_Amount *amount,
struct TALER_Amount *deposited,
struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp *merge_timestamp);
+ struct GNUNET_TIME_Timestamp *merge_timestamp,
+ bool *purse_deleted,
+ bool *purse_refunded);
/**
@@ -5251,7 +6389,7 @@ struct TALER_EXCHANGEDB_Plugin
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*select_purse_request)(
+ (*get_purse_request)(
void *cls,
const struct TALER_PurseContractPublicKeyP *purse_pub,
struct TALER_PurseMergePublicKeyP *merge_pub,
@@ -5309,6 +6447,7 @@ struct TALER_EXCHANGEDB_Plugin
* remaining balance is below @a amount;
* in this case, the return value will be
* #GNUNET_DB_STATUS_SUCCESS_ONE_RESULT despite the failure
+ * @param[out] too_late it is too late to deposit into this purse
* @param[out] conflict the same coin was deposited into
* this purse with a different amount already
* @return transaction status code
@@ -5322,10 +6461,32 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_CoinSpendSignatureP *coin_sig,
const struct TALER_Amount *amount_minus_fee,
bool *balance_ok,
+ bool *too_late,
bool *conflict);
/**
+ * Function called to explicitly delete a purse.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param purse_pub purse to delete
+ * @param purse_sig signature affirming the deletion
+ * @param[out] decided set to true if the purse was
+ * already decided and thus could not be deleted
+ * @param[out] found set to true if the purse was found
+ * (if false, purse could not be deleted)
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*do_purse_delete)(
+ void *cls,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig,
+ bool *decided,
+ bool *found);
+
+
+ /**
* Set the current @a balance in the purse
* identified by @a purse_pub. Used by the auditor
* to update the balance as calculated by the auditor.
@@ -5380,11 +6541,9 @@ struct TALER_EXCHANGEDB_Plugin
* @param reserve_sig signature of the reserve affirming the merge
* @param partner_url URL of the partner exchange, can be NULL if the reserves lives with us
* @param reserve_pub public key of the reserve to credit
- * @param require_kyc true if we should check for KYC
* @param[out] no_partner set to true if @a partner_url is unknown
* @param[out] no_balance set to true if the @a purse_pub is not paid up yet
* @param[out] no_reserve set to true if the @a reserve_pub is not known
- * @param[out] no_kyc set to true if the @a reserve_pub lacks KYC
* @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
* @return transaction status code
*/
@@ -5397,11 +6556,8 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_ReserveSignatureP *reserve_sig,
const char *partner_url,
const struct TALER_ReservePublicKeyP *reserve_pub,
- bool require_kyc,
bool *no_partner,
bool *no_balance,
- bool *no_reserve,
- bool *no_kyc,
bool *in_conflict);
@@ -5417,10 +6573,8 @@ struct TALER_EXCHANGEDB_Plugin
* @param reserve_sig signature of the reserve affirming the merge
* @param purse_fee amount to charge the reserve for the purse creation, NULL to use the quota
* @param reserve_pub public key of the reserve to credit
- * @param require_kyc true if we should check for KYC
* @param[out] in_conflict set to true if @a purse_pub was merged into a different reserve already
* @param[out] no_reserve set to true if @a reserve_pub is not a known reserve
- * @param[out] no_kyc set to true if @a reserve_pub has not passed KYC checks
* @param[out] insufficient_funds set to true if @a reserve_pub has insufficient capacity to create another purse
* @return transaction status code
*/
@@ -5433,10 +6587,8 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_ReserveSignatureP *reserve_sig,
const struct TALER_Amount *purse_fee,
const struct TALER_ReservePublicKeyP *reserve_pub,
- bool require_kyc,
bool *in_conflict,
bool *no_reserve,
- bool *no_kyc,
bool *insufficient_funds);
@@ -5450,6 +6602,7 @@ struct TALER_EXCHANGEDB_Plugin
* @param[out] merge_timestamp set to the time of the merge
* @param[out] partner_url set to the URL of the target exchange, or NULL if the target exchange is us. To be freed by the caller.
* @param[out] reserve_pub set to the public key of the reserve/account being credited
+ * @param[out] refunded set to true if purse was refunded
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
@@ -5459,54 +6612,633 @@ struct TALER_EXCHANGEDB_Plugin
struct TALER_PurseMergeSignatureP *merge_sig,
struct GNUNET_TIME_Timestamp *merge_timestamp,
char **partner_url,
- struct TALER_ReservePublicKeyP *reserve_pub);
+ struct TALER_ReservePublicKeyP *reserve_pub,
+ bool *refunded);
+
+
+ /**
+ * Function called to initiate closure of an account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param reserve_pub public key of the account to close
+ * @param payto_uri where to wire the funds
+ * @param reserve_sig signature affiming that the account is to be closed
+ * @param request_timestamp timestamp of the close request
+ * @param balance balance at the time of closing
+ * @param closing_fee closing fee to charge
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_close_request)(void *cls,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const char *payto_uri,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *balance,
+ const struct TALER_Amount *closing_fee);
+
+
+ /**
+ * Function called to persist a request to drain profits.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param wtid wire transfer ID to use
+ * @param account_section account to drain
+ * @param payto_uri account to wire funds to
+ * @param request_timestamp time of the signature
+ * @param amount amount to wire
+ * @param master_sig signature affirming the operation
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_drain_profit)(void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const char *account_section,
+ const char *payto_uri,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_Amount *amount,
+ const struct TALER_MasterSignatureP *master_sig);
/**
- * Function called to persist a signature that
- * prove that the client requested an
- * account history. Debits the @a history_fee from
- * the reserve (if possible).
+ * Function called to get information about a profit drain event.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub account that the history was requested for
- * @param reserve_sig signature affirming the request
- * @param request_timestamp when was the request made
- * @param history_fee how much should the @a reserve_pub be charged for the request
- * @param[out] balance_ok set to TRUE if the reserve balance
- * was sufficient
- * @param[out] idempotent set to TRUE if the request is already in the DB
+ * @param wtid wire transfer ID to look up drain event for
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_history_request)(
+ (*get_drain_profit)(void *cls,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ uint64_t *serial,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+
+ /**
+ * Get profit drain operation ready to execute.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param[out] serial set to serial ID of the entry
+ * @param[out] wtid set set to wire transfer ID to use
+ * @param[out] account_section set to account to drain
+ * @param[out] payto_uri set to account to wire funds to
+ * @param[out] request_timestamp set to time of the signature
+ * @param[out] amount set to amount to wire
+ * @param[out] master_sig set to signature affirming the operation
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*profit_drains_get_pending)(
+ void *cls,
+ uint64_t *serial,
+ struct TALER_WireTransferIdentifierRawP *wtid,
+ char **account_section,
+ char **payto_uri,
+ struct GNUNET_TIME_Timestamp *request_timestamp,
+ struct TALER_Amount *amount,
+ struct TALER_MasterSignatureP *master_sig);
+
+
+ /**
+ * Set profit drain operation to finished.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param serial serial ID of the entry to mark finished
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*profit_drains_set_finished)(
+ void *cls,
+ uint64_t serial);
+
+
+ /**
+ * Insert KYC requirement for @a h_payto account into table.
+ *
+ * @param cls closure
+ * @param requirements requirements that must be checked
+ * @param h_payto account that must be KYC'ed
+ * @param reserve_pub if account is a reserve, its public key, NULL otherwise
+ * @param[out] requirement_row set to legitimization requirement row for this check
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_kyc_requirement_for_account)(
void *cls,
+ const char *requirements,
+ const struct TALER_PaytoHashP *h_payto,
const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp request_timestamp,
- const struct TALER_Amount *history_fee,
- bool *balance_ok,
- bool *idempotent);
+ uint64_t *requirement_row);
/**
- * Function called to initiate closure of an account.
+ * Begin KYC requirement process.
+ *
+ * @param cls closure
+ * @param h_payto account that must be KYC'ed
+ * @param provider_section provider that must be checked
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param[out] process_row row the process is stored under
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_kyc_requirement_process)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ uint64_t *process_row);
+
+
+ /**
+ * Fetch information about pending KYC requirement process.
+ *
+ * @param cls closure
+ * @param h_payto account that must be KYC'ed
+ * @param provider_section provider that must be checked
+ * @param[out] redirect_url set to redirect URL for the process
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*get_pending_kyc_requirement_process)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ char **redirect_url);
+
+
+ /**
+ * Update KYC process with updated provider-linkage and/or
+ * expiration data.
+ *
+ * @param cls closure
+ * @param process_row row to select by
+ * @param provider_section provider that must be checked (technically redundant)
+ * @param h_payto account that must be KYC'ed (helps access by shard, otherwise also redundant)
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param redirect_url where the user should be redirected to start the KYC process
+ * @param expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*update_kyc_process_by_row)(
+ void *cls,
+ uint64_t process_row,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ const char *redirect_url,
+ struct GNUNET_TIME_Absolute expiration);
+
+
+ /**
+ * Lookup KYC requirement.
+ *
+ * @param cls closure
+ * @param legi_row identifies requirement to look up
+ * @param[out] requirements space-separated list of requirements
+ * @param[out] aml_status set to the AML status of the account
+ * @param[out] h_payto account that must be KYC'ed
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*lookup_kyc_requirement_by_row)(
+ void *cls,
+ uint64_t requirement_row,
+ char **requirements,
+ enum TALER_AmlDecisionState *aml_status,
+ struct TALER_PaytoHashP *h_payto);
+
+
+ /**
+ * Lookup KYC process meta data.
+ *
+ * @param cls closure
+ * @param provider_section provider that must be checked
+ * @param h_payto account that must be KYC'ed
+ * @param[out] process_row set to row with the legitimization data
+ * @param[out] expiration how long is this KYC check set to be valid (in the past if invalid)
+ * @param[out] provider_account_id provider account ID
+ * @param[out] provider_legitimization_id provider legitimization ID
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*lookup_kyc_process_by_account)(
+ void *cls,
+ const char *provider_section,
+ const struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row,
+ struct GNUNET_TIME_Absolute *expiration,
+ char **provider_account_id,
+ char **provider_legitimization_id);
+
+
+ /**
+ * Lookup an
+ * @a h_payto by @a provider_legitimization_id.
+ *
+ * @param cls closure
+ * @param provider_section
+ * @param provider_legitimization_id legi to look up
+ * @param[out] h_payto where to write the result
+ * @param[out] process_row identifies the legitimization process on our end
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*kyc_provider_account_lookup)(
+ void *cls,
+ const char *provider_section,
+ const char *provider_legitimization_id,
+ struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row);
+
+
+ /**
+ * Call us on KYC processes satisfied for the given
+ * account.
*
* @param cls the @e cls of this struct with the plugin-specific state
- * @param reserve_pub public key of the account to close
- * @param reserve_sig signature affiming that the account is to be closed
- * @param request_timestamp timestamp of the close request
- * @param[out] final_balance set to the final balance in the account that will be wired back to the origin account
+ * @param h_payto account identifier
+ * @param spc function to call for each satisfied KYC process
+ * @param spc_cls closure for @a spc
* @return transaction status code
*/
enum GNUNET_DB_QueryStatus
- (*insert_close_request)(void *cls,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig,
- struct GNUNET_TIME_Timestamp request_timestamp,
- struct TALER_Amount *final_balance);
+ (*select_satisfied_kyc_processes)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_SatisfiedProviderCallback spc,
+ void *spc_cls);
+ /**
+ * Call us on KYC legitimization processes satisfied and not expired for the
+ * given account.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param lpc function to call for each satisfied KYC legitimization process
+ * @param lpc_cls closure for @a lpc
+ * @return transaction status code
+ */
+ enum GNUNET_DB_QueryStatus
+ (*iterate_kyc_reference)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_LegitimizationProcessCallback lpc,
+ void *lpc_cls);
+
+
+ /**
+ * Call @a kac on withdrawn amounts after @a time_limit which are relevant
+ * for a KYC trigger for a the (debited) account identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_withdraw_amounts_for_kyc_check)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+
+ /**
+ * Call @a kac on aggregated amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the (credited) account identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_aggregation_amounts_for_kyc_check)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+
+ /**
+ * Call @a kac on merged reserve amounts after @a time_limit which are relevant for a
+ * KYC trigger for a the wallet identified by @a h_payto.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param time_limit oldest transaction that could be relevant
+ * @param kac function to call for each applicable amount, in reverse chronological order (or until @a kac aborts by returning anything except #GNUNET_OK).
+ * @param kac_cls closure for @a kac
+ * @return transaction status code, @a kac aborting with #GNUNET_NO is not an error
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_merge_amounts_for_kyc_check)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ struct GNUNET_TIME_Absolute time_limit,
+ TALER_EXCHANGEDB_KycAmountCallback kac,
+ void *kac_cls);
+
+
+ /**
+ * Store KYC attribute data, update KYC process status and
+ * AML status for the given account.
+ *
+ * @param cls closure
+ * @param process_row KYC process row to update
+ * @param h_payto account for which the attribute data is stored
+ * @param kyc_prox key for similarity search
+ * @param provider_section provider that must be checked
+ * @param num_checks how many checks do these attributes satisfy
+ * @param satisfied_checks array of checks satisfied by these attributes
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @param birthday birthdate of user, in days after 1990, or 0 if unknown or definitively adult
+ * @param collection_time when was the data collected
+ * @param expiration_time when does the data expire
+ * @param enc_attributes_size number of bytes in @a enc_attributes
+ * @param enc_attributes encrypted attribute data
+ * @param require_aml true to trigger AML
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_kyc_attributes)(
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ const char *provider_section,
+ unsigned int num_checks,
+ const char *satisfied_checks[static num_checks],
+ uint32_t birthday,
+ struct GNUNET_TIME_Timestamp collection_time,
+ const char *provider_account_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration_time,
+ size_t enc_attributes_size,
+ const void *enc_attributes,
+ bool require_aml);
+
+
+ /**
+ * Lookup similar KYC attribute data.
+ *
+ * @param cls closure
+ * @param kyc_prox key for similarity search
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_similar_kyc_attributes)(
+ void *cls,
+ const struct GNUNET_ShortHashCode *kyc_prox,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Lookup KYC attribute data for a specific account.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_kyc_attributes)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AttributeCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Insert AML staff record.
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @param master_sig offline signature affirming the AML officer
+ * @param decider_name full name of the staff member
+ * @param is_active true to enable, false to set as inactive
+ * @param read_only true to set read-only access
+ * @param last_change when was the change made effective
+ * @param[out] previous_change when was the previous change made
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_aml_officer)(
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_MasterSignatureP *master_sig,
+ const char *decider_name,
+ bool is_active,
+ bool read_only,
+ struct GNUNET_TIME_Timestamp last_change,
+ struct GNUNET_TIME_Timestamp *previous_change);
+
+
+ /**
+ * Test if the given AML staff member is active
+ * (at least read-only).
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @return database transaction status, if member is unknown or not active, 1 if member is active
+ */
+ enum GNUNET_DB_QueryStatus
+ (*test_aml_officer)(
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub);
+
+
+ /**
+ * Fetch AML staff record.
+ *
+ * @param cls closure
+ * @param decider_pub public key of the staff member
+ * @param[out] master_sig offline signature affirming the AML officer
+ * @param[out] decider_name full name of the staff member
+ * @param[out] is_active true to enable, false to set as inactive
+ * @param[out] read_only true to set read-only access
+ * @param[out] last_change when was the change made effective
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*lookup_aml_officer)(
+ void *cls,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ struct TALER_MasterSignatureP *master_sig,
+ char **decider_name,
+ bool *is_active,
+ bool *read_only,
+ struct GNUNET_TIME_Absolute *last_change);
+
+
+ /**
+ * Obtain the current AML threshold set for an account.
+ *
+ * @param cls closure
+ * @param h_payto account for which the AML threshold is stored
+ * @param[out] decision set to current AML decision
+ * @param[out] threshold set to the existing threshold
+ * @return database transaction status, 0 if no threshold was set
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_aml_threshold)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState *decision,
+ struct TALER_EXCHANGEDB_KycStatus *kyc,
+ struct TALER_Amount *threshold);
+
+
+ /**
+ * Trigger AML process, an account has crossed the threshold. Inserts or
+ * updates the AML status.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param threshold_crossed existing threshold that was crossed
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*trigger_aml_process)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *threshold_crossed);
+
+
+ /**
+ * Lookup AML decisions that have a particular state.
+ *
+ * @param cls closure
+ * @param decision which decision states to filter by
+ * @param row_off offset to start from
+ * @param forward true to go forward in time, false to go backwards
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_aml_process)(
+ void *cls,
+ enum TALER_AmlDecisionState decision,
+ uint64_t row_off,
+ uint64_t limit,
+ bool forward,
+ TALER_EXCHANGEDB_AmlStatusCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Lookup AML decision history for a particular account.
+ *
+ * @param cls closure
+ * @param h_payto which account should we return the AML decision history for
+ * @param cb callback to invoke on each match
+ * @param cb_cls closure for @a cb
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*select_aml_history)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_AmlHistoryCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Insert an AML decision. Inserts into AML history and insert or updates AML
+ * status.
+ *
+ * @param cls closure
+ * @param h_payto account for which the attribute data is stored
+ * @param new_threshold new monthly threshold that would trigger an AML check
+ * @param new_status AML decision status
+ * @param decision_time when was the decision made
+ * @param justification human-readable text justifying the decision
+ * @param kyc_requirements specific KYC requirements being imposed
+ * @param requirements_row row in the KYC table for this process, 0 for none
+ * @param decider_pub public key of the staff member
+ * @param decider_sig signature of the staff member
+ * @param[out] invalid_officer set to TRUE if @a decider_pub is not allowed to make decisions right now
+ * @param[out] last_date set to the previous decision time;
+ * the INSERT is not performed if @a last_date is not before @a decision_time
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_aml_decision)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_Amount *new_threshold,
+ enum TALER_AmlDecisionState new_status,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const char *justification,
+ const json_t *kyc_requirements,
+ uint64_t requirements_row,
+ const struct TALER_AmlOfficerPublicKeyP *decider_pub,
+ const struct TALER_AmlOfficerSignatureP *decider_sig,
+ bool *invalid_officer,
+ struct GNUNET_TIME_Timestamp *last_date);
+
+
+ /**
+ * Update KYC process status to finished (and failed).
+ *
+ * @param cls closure
+ * @param process_row KYC process row to update
+ * @param h_payto account for which the attribute data is stored
+ * @param provider_section provider that must be checked
+ * @param provider_account_id provider account ID
+ * @param provider_legitimization_id provider legitimization ID
+ * @return database transaction status
+ */
+ enum GNUNET_DB_QueryStatus
+ (*insert_kyc_failure)(
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *provider_section,
+ const char *provider_account_id,
+ const char *provider_legitimization_id);
+
+ /**
+ * Function called to inject auditor triggers into the
+ * database, triggering the real-time auditor upon
+ * relevant INSERTs.
+ *
+ * @param cls closure
+ * @return #GNUNET_OK on success,
+ * #GNUNET_SYSERR on DB errors
+ */
+ enum GNUNET_GenericReturnValue
+ (*inject_auditor_triggers)(void *cls);
+
};
#endif /* _TALER_EXCHANGE_DB_H */
diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h
index 342faad2a..1eb567f72 100644
--- a/src/include/taler_extensions.h
+++ b/src/include/taler_extensions.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -22,113 +22,257 @@
#define TALER_EXTENSIONS_H
#include <gnunet/gnunet_util_lib.h>
-#include "taler_crypto_lib.h"
+#include "taler_util.h"
#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+#include "taler_extensions_policy.h"
#define TALER_EXTENSION_SECTION_PREFIX "exchange-extension-"
enum TALER_Extension_Type
{
- TALER_Extension_AgeRestriction = 0,
- TALER_Extension_MaxPredefined = 1 // Must be last of the predefined
+ TALER_Extension_PolicyNull = 0,
+
+ TALER_Extension_AgeRestriction = 1,
+ TALER_Extension_PolicyMerchantRefund = 2,
+ TALER_Extension_PolicyBrandtVickeryAuction = 3,
+ TALER_Extension_PolicyEscrowedPayment = 4,
+
+ TALER_Extension_MaxPredefined = 5 // Must be last of the predefined
};
+
+/* Forward declarations */
+enum TALER_PolicyFulfillmentState;
+struct TALER_PolicyFulfillmentOutcome;
+
/*
- * Represents the implementation of an extension.
- * TODO: add documentation
+ * @brief Represents the implementation of an extension.
+ *
+ * An "Extension" is an optional feature for the Exchange.
+ * There are only two types of extensions:
+ *
+ * a) Age restriction: This is a special feature that directly interacts with
+ * denominations and coins, but is not define policies during deposits, see b).
+ * The implementation of this extension doesn't have to implement any of the
+ * http- or depost-handlers in the struct.
+ *
+ * b) Policies for deposits: These are extensions that define policies (such
+ * as refund, escrow or auctions) for deposit requests. These extensions have
+ * to implement at least the deposit- and post-http-handler in the struct to be
+ * functional.
+ *
+ * In addition to the handlers defined in this struct, an extension must also
+ * be a plugin in the GNUNET_Plugin sense. That is, it must implement the
+ * functions
+ * 1: (void *ext)libtaler_extension_<name>_init(void *cfg)
+ * and
+ * 2: (void *)libtaler_extension_<name>_done(void *)
+ *
+ * In 1:, the input will be the GNUNET_CONFIGURATION_Handle to the TALER
+ * configuration and the output must be the struct TALER_Extension * on
+ * success, NULL otherwise.
+ *
+ * In 2:, no arguments are passed and NULL is expected to be returned.
*/
struct TALER_Extension
{
- /* simple linked list */
- struct TALER_Extension *next;
-
+ /**
+ * Type of the extension. Only one extension of a type can be loaded
+ * at any time.
+ */
enum TALER_Extension_Type type;
+
+ /**
+ * The name of the extension, must be unique among all loaded extensions. It
+ * is used in URLs for /extension/$NAME as well.
+ */
char *name;
+
+ /**
+ * Criticality of the extension. It has the same semantics as "critical" has
+ * for extensions in X.509:
+ * - if "true", the client must "understand" the extension before proceeding,
+ * - if "false", clients can safely skip extensions they do not understand.
+ * (see https://datatracker.ietf.org/doc/html/rfc5280#section-4.2)
+ */
bool critical;
+
+ /**
+ * Version of the extension must be provided in Taler's protocol version ranges notation, see
+ * https://docs.taler.net/core/api-common.html#protocol-version-ranges
+ */
char *version;
+
+ /**
+ * If the extension is marked as enabled, it will be listed in the
+ * "extensions" field in the "/keys" response.
+ */
+ bool enabled;
+
+ /**
+ * Opaque (public) configuration object, set by the extension.
+ */
void *config;
- json_t *config_json;
- void (*disable)(struct TALER_Extension *this);
- enum GNUNET_GenericReturnValue (*test_json_config)(
- const json_t *config);
+ /**
+ * @brief Handler to to disable the extension.
+ *
+ * @param ext The current extension object
+ */
+ void (*disable)(struct TALER_Extension *ext);
+
+ /**
+ * @brief Handler to read an extension-specific configuration in JSON
+ * encoding and enable the extension. Must be implemented by the extension.
+ *
+ * @param[in] ext The extension object. If NULL, the configuration will only be checked.
+ * @param[in,out] config A JSON blob
+ * @return GNUNET_OK if the json was a valid configuration for the extension.
+ */
+ enum GNUNET_GenericReturnValue (*load_config)(
+ const json_t *config,
+ struct TALER_Extension *ext);
+
+ /**
+ * @brief Handler to return the manifest of the extension in JSON encoding.
+ *
+ * See
+ * https://docs.taler.net/design-documents/006-extensions.html#tsref-type-Extension
+ * for the definition.
+ *
+ * @param ext The extension object
+ * @return The JSON encoding of the extension, if enabled, NULL otherwise.
+ */
+ json_t *(*manifest)(
+ const struct TALER_Extension *ext);
+
+ /* =========================
+ * Policy related handlers
+ * =========================
+ */
+
+ /**
+ * @brief Handler to check an incoming policy and create a
+ * TALER_PolicyDetails. Can be NULL;
+ *
+ * When a deposit request refers to this extension in its policy
+ * (see https://docs.taler.net/core/api-exchange.html#deposit), this handler
+ * will be called before the deposit transaction.
+ *
+ * @param[in] currency Currency used in the exchange
+ * @param[in] policy_json Details about the policy, provided by the client
+ * during a deposit request.
+ * @param[out] details On success, will contain the details to the policy,
+ * evaluated by the corresponding policy handler.
+ * @param[out] error_hint On error, will contain a hint
+ * @return GNUNET_OK if the data was accepted by the extension.
+ */
+ enum GNUNET_GenericReturnValue (*create_policy_details)(
+ const char *currency,
+ const json_t *policy_json,
+ struct TALER_PolicyDetails *details,
+ const char **error_hint);
+
+ /**
+ * @brief Handler for POST-requests to the /extensions/$name endpoint. Can be NULL.
+ *
+ * @param[in] root The JSON body from the request
+ * @param[in] args Additional query parameters of the request.
+ * @param[in,out] details List of policy details related to the incoming fulfillment proof
+ * @param[in] details_len Size of the list @e details
+ * @param[out] output JSON output to return to the client
+ * @return GNUNET_OK on success.
+ */
+ enum GNUNET_GenericReturnValue (*policy_post_handler)(
+ const json_t *root,
+ const char *const args[],
+ struct TALER_PolicyDetails *details,
+ size_t details_len,
+ json_t **output);
+
+ /**
+ * @brief Handler for GET-requests to the /extensions/$name endpoint. Can be NULL.
+ *
+ * @param connection The current connection
+ * @param root The JSON body from the request
+ * @param args Additional query parameters of the request.
+ * @return MDH result
+ */
+ MHD_RESULT (*policy_get_handler)(
+ struct MHD_Connection *connection,
+ const char *const args[]);
+};
- enum GNUNET_GenericReturnValue (*load_json_config)(
- struct TALER_Extension *this,
- json_t *config);
- json_t *(*config_to_json)(
- const struct TALER_Extension *this);
+/*
+ * @brief simply linked list of extensions
+ */
- enum GNUNET_GenericReturnValue (*load_taler_config)(
- struct TALER_Extension *this,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+struct TALER_Extensions
+{
+ struct TALER_Extensions *next;
+ const struct TALER_Extension *extension;
};
/**
* Generic functions for extensions
*/
-/*
- * Sets the configuration of the extensions from the given TALER configuration
+/**
+ * @brief Loads the extensions as shared libraries, as specified in the given
+ * TALER configuration.
*
* @param cfg Handle to the TALER configuration
- * @return GNUNET_OK on success, GNUNET_SYSERR if unknown extensions were found
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if unknown extensions were found
* or any particular configuration couldn't be parsed.
*/
enum GNUNET_GenericReturnValue
-TALER_extensions_load_taler_config (
+TALER_extensions_init (
const struct GNUNET_CONFIGURATION_Handle *cfg);
/*
- * Check the given obj to be a valid extension object and fill the fields
- * accordingly.
+ * @brief Parses a given JSON object as an extension manifest.
+ *
+ * @param[in] obj JSON object to parse as an extension manifest
+ * @param{out] critical will be set to 1 if the extension is critical according to obj
+ * @param[out] version will be set to the version of the extension according to obj
+ * @param[out] config will be set to the configuration of the extension according to obj
+ * @return OK on success, Error otherwise
*/
enum GNUNET_GenericReturnValue
-TALER_extensions_is_json_config (
+TALER_extensions_parse_manifest (
json_t *obj,
int *critical,
const char **version,
json_t **config);
/*
- * Sets the configuration of the extensions from a given JSON object.
+ * @brief Loads extensions according to the manifests.
*
- * he JSON object must be of type ExchangeKeysResponse as described in
- * https://docs.taler.net/design-documents/006-extensions.html#exchange
+ * The JSON object must be of type ExtensionsManifestsResponse as described
+ * in https://docs.taler.net/design-documents/006-extensions.html#exchange
*
- * @param cfg JSON object containing the configuration for all extensions
- * @return #GNUNET_OK on success, #GNUNET_SYSERR if unknown extensions were found
- * or any particular configuration couldn't be parsed.
+ * @param cfg JSON object containing the manifests for all extensions
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR if unknown extensions were
+ * found or any particular configuration couldn't be parsed.
*/
enum GNUNET_GenericReturnValue
-TALER_extensions_load_json_config (
- json_t *cfg);
+TALER_extensions_load_manifests (
+ const json_t *manifests);
/*
- * Returns the head of the linked list of extensions
+ * @brief Returns the head of the linked list of extensions.
*/
-const struct TALER_Extension *
-TALER_extensions_get_head ();
-
-/*
- * Adds an extension to the linked list of extensions
- *
- * @param new_extension the new extension to be added
- * @return GNUNET_OK on success, GNUNET_SYSERR if the extension is invalid
- * (missing fields), GNUNET_NO if there is already an extension with that name
- * or type.
- */
-enum GNUNET_GenericReturnValue
-TALER_extensions_add (
- struct TALER_Extension *new_extension);
+const struct TALER_Extensions *
+TALER_extensions_get_head (void);
/**
- * Finds and returns a supported extension by a given type.
+ * @brief Finds and returns a supported extension by a given type.
*
- * @param type type of the extension to lookup
+ * @param type of the extension to lookup
* @return extension found, or NULL (should not happen!)
*/
const struct TALER_Extension *
@@ -137,7 +281,7 @@ TALER_extensions_get_by_type (
/**
- * Finds and returns a supported extension by a given name.
+ * @brief Finds and returns a supported extension by a given name.
*
* @param name name of the extension to lookup
* @return the extension, if found, NULL otherwise
@@ -146,10 +290,8 @@ const struct TALER_Extension *
TALER_extensions_get_by_name (
const char *name);
-#define TALER_extensions_is_enabled(ext) (NULL != (ext)->config)
-
/**
- * Check if a given type of an extension is enabled
+ * @brief Check if a given type of an extension is enabled
*
* @param type type of to check
* @return true enabled, false if not enabled, will assert if type is not found.
@@ -158,12 +300,21 @@ bool
TALER_extensions_is_enabled_type (
enum TALER_Extension_Type type);
+/**
+ * @brief Check if an extension is enabled
+ *
+ * @param extension The extension handler.
+ * @return true enabled, false if not enabled, will assert if type is not found.
+ */
+bool
+TALER_extensions_is_enabled (
+ const struct TALER_Extension *extension);
/*
* Verify the signature of a given JSON object for extensions with the master
* key of the exchange.
*
- * The JSON object must be of type ExchangeKeysResponse as described in
+ * The JSON object must be of type ExtensionsManifestsResponse as described in
* https://docs.taler.net/design-documents/006-extensions.html#exchange
*
* @param extensions JSON object with the extension configuration
@@ -173,14 +324,19 @@ TALER_extensions_is_enabled_type (
* and GNUNET_NO if the signature couldn't be verified.
*/
enum GNUNET_GenericReturnValue
-TALER_extensions_verify_json_config_signature (
- json_t *extensions,
+TALER_extensions_verify_manifests_signature (
+ const json_t *manifests,
struct TALER_MasterSignatureP *extensions_sig,
struct TALER_MasterPublicKeyP *master_pub);
/*
* TALER Age Restriction Extension
+ *
+ * This extension is special insofar as it directly interacts with coins and
+ * denominations.
+ *
+ * At the same time, it doesn't implement and http- or deposit-handlers.
*/
#define TALER_EXTENSION_SECTION_AGE_RESTRICTION (TALER_EXTENSION_SECTION_PREFIX \
@@ -190,93 +346,41 @@ TALER_extensions_verify_json_config_signature (
* The default age mask represents the age groups
* 0-7, 8-9, 10-11, 12-13, 14-15, 16-17, 18-20, 21-...
*/
-#define TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_MASK (1 | 1 << 8 | 1 << 10 \
- | 1 << 12 | 1 << 14 \
- | 1 << 16 | 1 << 18 \
- | 1 << 21)
#define TALER_EXTENSION_AGE_RESTRICTION_DEFAULT_AGE_GROUPS "8:10:12:14:16:18:21"
-/**
- * @brief Registers the extension for age restriction to the list extensions
- */
-enum GNUNET_GenericReturnValue
-TALER_extension_age_restriction_register ();
-/**
- * @brief Parses a string as a list of age groups.
- *
- * The string must consist of a colon-separated list of increasing integers
- * between 0 and 31. Each entry represents the beginning of a new age group.
- * F.e. the string "8:10:12:14:16:18:21" parses into the following list of age
- * groups
- * 0-7, 8-9, 10-11, 12-13, 14-15, 16-17, 18-20, 21-...
- * which then is represented as bit mask with the corresponding bits set:
- * 31 24 16 8 0
- * | | | | |
- * oooooooo oo1oo1o1 o1o1o1o1 ooooooo1
- *
- * @param groups String representation of age groups
- * @param[out] mask Mask representation for age restriction.
- * @return Error, if age groups were invalid, OK otherwise.
+/*
+ * @brief Configuration for Age Restriction
*/
-enum GNUNET_GenericReturnValue
-TALER_parse_age_group_string (
- const char *groups,
- struct TALER_AgeMask *mask);
+struct TALER_AgeRestrictionConfig
+{
+ struct TALER_AgeMask mask;
+ uint8_t num_groups;
+};
-/**
- * Encodes the age mask into a string, like "8:10:12:14:16:18:21"
- *
- * @param mask Age mask
- * @return String representation of the age mask, allocated by GNUNET_malloc.
- * Can be used as value in the TALER config.
- */
-char *
-TALER_age_mask_to_string (
- const struct TALER_AgeMask *mask);
/**
- * Returns true when age restriction is configured and enabled.
+ * @brief Retrieve the age restriction configuration
+ *
+ * @return age restriction configuration if present, otherwise NULL.
*/
-bool
-TALER_extensions_age_restriction_is_enabled ();
+const struct TALER_AgeRestrictionConfig *
+TALER_extensions_get_age_restriction_config (void);
/**
- * Returns true when age restriction is configured (might not be _enabled_,
- * though).
+ * @brief Check if age restriction is enabled
+ *
+ * @return true, if age restriction is loaded, configured and enabled; otherwise false.
*/
bool
-TALER_extensions_age_restriction_is_configured ();
+TALER_extensions_is_age_restriction_enabled (void);
/**
- * Returns the currently set age mask. Note that even if age restriction is
- * not enabled, the age mask might be have a non-zero value.
- */
-struct TALER_AgeMask
-TALER_extensions_age_restriction_ageMask ();
-
-
-/**
- * Returns the amount of age groups defined. 0 means no age restriction
- * enabled.
- */
-size_t
-TALER_extensions_age_restriction_num_groups ();
-
-/**
- * Parses a JSON object { "age_groups": "a:b:...y:z" }.
+ * @brief Return the age mask for age restriction
*
- * @param root is the json object
- * @param[out] mask on success, will contain the age mask
- * @return #GNUNET_OK on success and #GNUNET_SYSERR on failure.
- */
-enum GNUNET_GenericReturnValue
-TALER_JSON_parse_age_groups (const json_t *root,
- struct TALER_AgeMask *mask);
-
-
-/*
- * TODO: Add Peer2Peer Extension
+ * @return configured age mask, if age restriction is loaded, configured and enabled; otherwise zero mask.
*/
+struct TALER_AgeMask
+TALER_extensions_get_age_restriction_mask (void);
#endif
diff --git a/src/include/taler_extensions_policy.h b/src/include/taler_extensions_policy.h
new file mode 100644
index 000000000..b10c0d8a2
--- /dev/null
+++ b/src/include/taler_extensions_policy.h
@@ -0,0 +1,205 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file include/taler_extensions_policy.h
+ * @brief Interface for policy extensions
+ * @author Özgür Kesim
+ */
+#ifndef TALER_EXTENSIONS_POLICY_H
+#define TALER_EXTENSIONS_POLICY_H
+
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_util.h"
+#include "taler_json_lib.h"
+#include "taler_mhd_lib.h"
+
+/*
+ * @brief Describes the states of fulfillment of a policy bound to a deposit
+ * NOTE: These values must be in sync with their use in stored procedures, f.e.
+ * exchange_do_insert_or_update_policy_details.
+ */
+enum TALER_PolicyFulfillmentState
+{
+ /* Initial state of an fulfillment, before any other state. */
+ TALER_PolicyFulfillmentInitial = 0,
+
+ /* General error state of an fulfillment. */
+ TALER_PolicyFulfillmentFailure = 1,
+
+ /* The policy is not yet ready due to insufficient funding. More deposits are
+ * necessary for it to become ready . */
+ TALER_PolicyFulfillmentInsufficient = 2,
+
+ /* The policy is funded and ready, pending */
+ TALER_PolicyFulfillmentReady = 3,
+
+ /* Policy is provably fulfilled. */
+ TALER_PolicyFulfillmentSuccess = 4,
+
+ /* Policy fulfillment has timed out */
+ TALER_PolicyFulfillmentTimeout = 5,
+
+ TALER_PolicyFulfillmentStateCount = TALER_PolicyFulfillmentTimeout + 1
+};
+
+
+/*
+ * @brief Returns a string representation of the state of a policy fulfillment
+ */
+const char *
+TALER_policy_fulfillment_state_str (enum TALER_PolicyFulfillmentState state);
+
+
+/* @brief Details of a policy for a deposit request */
+struct TALER_PolicyDetails
+{
+ /* Hash code that should be used for the .policy_hash_code field when
+ * this policy is saved in the policy_details table. */
+ struct GNUNET_HashCode hash_code;
+
+ /* Content of the policy in its original JSON form */
+ json_t *policy_json;
+
+ /* When the deadline is met and the policy is still in "Ready" state,
+ * a timeout-handler will transfer the amount
+ * (total_amount - policy_fee - refreshable_amount)
+ * to the payto-URI from the corresponding deposit. The value
+ * amount_refreshable will be refreshable by the owner of the
+ * associated deposits's coins */
+ struct GNUNET_TIME_Timestamp deadline;
+
+ /* The amount to which this policy commits to. It must be at least as
+ * large as @e policy_fee. */
+ struct TALER_Amount commitment;
+
+ /* The total sum of contributions from coins so far to fund this
+ * policy. It must be at least as large as @commitment in order to be
+ * sufficiently funded. */
+ struct TALER_Amount accumulated_total;
+
+ /* The fee from the exchange for handling the policy. It is due when
+ * the state changes to Timeout or Success. */
+ struct TALER_Amount policy_fee;
+
+ /* The amount that will be transferred to the payto-URIs from the
+ * corresponding deposits when the fulfillment state changes to Timeout
+ * or Success. Note that a fulfillment handler can alter this upon
+ * arrival of a proof of fulfillment. The remaining amount
+ * (accumulated_amount - policy_amount - transferable_amount) */
+ struct TALER_Amount transferable_amount;
+
+ /* The state of fulfillment of a policy.
+ * - If the state is Insufficient, the client is required to call
+ * /deposit -maybe multiple times- with enough coins and the same
+ * policy details in order to reach the required amount. The state is
+ * then changed to Ready.
+ * - If the state changes to Timeout or Success, a handler will transfer
+ * the amount (total_amount - policy_fee - refreshable_amount) to the
+ * payto-URI from the corresponding deposit. The value
+ * amount_refreshable will be refreshable by the owner of the
+ * associated deposits's coins. */
+ enum TALER_PolicyFulfillmentState fulfillment_state;
+
+ /* If there is a proof of fulfillment, the row ID from the
+ * policy_fulfillment table */
+ uint64_t policy_fulfillment_id;
+ bool no_policy_fulfillment_id;
+};
+
+/*
+ * @brief All information required for the database transaction when handling a
+ * proof of fulfillment request.
+ */
+struct TALER_PolicyFulfillmentTransactionData
+{
+ /* The incoming proof, provided by a client */
+ const json_t *proof;
+
+ /* The Hash of the proof */
+ struct GNUNET_HashCode h_proof;
+
+ /* The timestamp of retrieval of the proof */
+ struct GNUNET_TIME_Timestamp timestamp;
+
+ /* The ID of the proof in the policy_fulfillment table. Will be set
+ * during the transaction. Needed to fill the table
+ * policy_details_fulfillments. */
+ uint64_t fulfillment_id;
+
+ /* The list of policy details. Will be updated by the policy handler */
+ struct TALER_PolicyDetails *details;
+ size_t details_count;
+};
+
+
+/*
+ * @brief Extracts policy details from the deposit's policy options and the policy extensions
+ *
+ * @param[in] currency Currency used in the exchange
+ * @param[in] policy_options JSON of the policy options from a deposit request
+ * @param[out] details On GNUNET_OK, the parsed details
+ * @param[out] error_hint On GNUNET_SYSERR, will contain a hint for the reason why it failed
+ * @return GNUNET_OK on success, GNUNET_NO, when no extension was found. GNUNET_SYSERR when the JSON was
+ * invalid, with *error_hint maybe non-NULL.
+ */
+enum GNUNET_GenericReturnValue
+TALER_extensions_create_policy_details (
+ const char *currency,
+ const json_t *policy_options,
+ struct TALER_PolicyDetails *details,
+ const char **error_hint);
+
+
+/*
+ * ================================
+ * Merchant refund policy
+ * ================================
+ */
+struct TALER_ExtensionPolicyMerchantRefundPolicyConfig
+{
+ struct GNUNET_TIME_Relative max_timeout;
+};
+
+/*
+ * ================================
+ * Brandt-Vickrey Auctions policy
+ * ================================
+ */
+/*
+ * @brief Configuration for Brandt-Vickrey auctions policy
+ */
+struct TALER_ExtensionPolicyBrandtVickreyAuctionConfig
+{
+ uint16_t max_bidders;
+ uint16_t max_prices;
+ struct TALER_Amount auction_fee;
+};
+
+
+/*
+ * ================================
+ * Escrowed Payments policy
+ * ================================
+ */
+/*
+ * @brief Configuration for escrowed payments policy
+ */
+struct TALER_ExtensionPolicyEscrowedPaymentsConfig
+{
+ struct GNUNET_TIME_Relative max_timeout;
+};
+
+#endif
diff --git a/src/include/taler_fakebank_lib.h b/src/include/taler_fakebank_lib.h
index 16135a4d7..6b34f4730 100644
--- a/src/include/taler_fakebank_lib.h
+++ b/src/include/taler_fakebank_lib.h
@@ -76,6 +76,35 @@ TALER_FAKEBANK_start2 (uint16_t port,
/**
+ * Start the fake bank. The fake bank will, like the normal bank, listen for
+ * requests for /admin/add/incoming and /transfer. However, instead of
+ * executing or storing those requests, it will simply allow querying whether
+ * such a request has been made via #TALER_FAKEBANK_check_debit() and
+ * #TALER_FAKEBANK_check_credit() as well as the history API.
+ *
+ * This is useful for writing testcases to check whether the exchange
+ * would have issued the correct wire transfer orders.
+ *
+ * @param hostname hostname to use in URLs and URIs.
+ * @param port port to listen to
+ * @param exchange_url suggested exchange base URL
+ * @param currency which currency should the bank offer
+ * @param ram_limit how much memory do we use at most
+ * @param num_threads size of the thread pool, 0 to use the GNUnet scheduler
+ * @param signup_bonus how much to credit new users
+ * @return NULL on error
+ */
+struct TALER_FAKEBANK_Handle *
+TALER_FAKEBANK_start3 (const char *hostname,
+ uint16_t port,
+ const char *exchange_url,
+ const char *currency,
+ uint64_t ram_limit,
+ unsigned int num_threads,
+ const struct TALER_Amount *signup_bonus);
+
+
+/**
* Check that no wire transfers were ordered (or at least none
* that have not been taken care of via #TALER_FAKEBANK_check_debit()
* or #TALER_FAKEBANK_check_credit()).
diff --git a/src/include/taler_json_lib.h b/src/include/taler_json_lib.h
index d8912e52e..98e565f0c 100644
--- a/src/include/taler_json_lib.h
+++ b/src/include/taler_json_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2021, 2022 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -28,6 +28,10 @@
#include "taler_util.h"
#include "taler_error_codes.h"
+/**
+ * Version of this API, for compatibility tests.
+ */
+#define TALER_JSON_LIB_VERSION 0x00020000
/**
* Details about an encrypted contract.
@@ -55,7 +59,6 @@ struct TALER_EncryptedContract
*/
size_t econtract_size;
-
};
@@ -92,18 +95,6 @@ TALER_JSON_pack_time_abs_human (const char *name,
GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec)), \
GNUNET_JSON_pack_uint64 ("code", ec)
-/**
- * Generate packer instruction for a JSON field of type
- * absolute time creating a human-readable timestamp.
- *
- * @param name name of the field to add to the object
- * @param at absolute time to pack
- * @return json pack specification
- */
-struct GNUNET_JSON_PackSpec
-TALER_JSON_pack_time_abs_nbo_human (const char *name,
- struct GNUNET_TIME_AbsoluteNBO at);
-
/**
* Generate packer instruction for a JSON field of type
@@ -191,19 +182,6 @@ TALER_JSON_pack_amount (const char *name,
/**
* Generate packer instruction for a JSON field of type
- * amount.
- *
- * @param name name of the field to add to the object
- * @param amount valid amount to pack
- * @return json pack specification
- */
-struct GNUNET_JSON_PackSpec
-TALER_JSON_pack_amount_nbo (const char *name,
- const struct TALER_AmountNBO *amount);
-
-
-/**
- * Generate packer instruction for a JSON field of type
* encrypted contract.
*
* @param name name of the field to add to the object
@@ -239,16 +217,6 @@ TALER_JSON_from_amount (const struct TALER_Amount *amount);
/**
- * Convert a TALER amount to a JSON object.
- *
- * @param amount the amount
- * @return a json object describing the amount
- */
-json_t *
-TALER_JSON_from_amount_nbo (const struct TALER_AmountNBO *amount);
-
-
-/**
* Provide specification to parse given JSON object to an amount.
* The @a currency must be a valid pointer while the
* parsing is done, a copy is not made.
@@ -265,20 +233,19 @@ TALER_JSON_spec_amount (const char *name,
/**
- * Provide specification to parse given JSON object to an amount
- * in network byte order.
- * The @a currency must be a valid pointer while the
- * parsing is done, a copy is not made.
+ * Provide specification to parse given JSON object to
+ * a currency specification.
*
* @param name name of the amount field in the JSON
- * @param currency the currency the amount must be in
- * @param[out] r_amount where the amount has to be written
+ * @param currency_code currency code to parse
+ * @param[out] r_cspec where the currency spec has to be written
* @return spec for parsing an amount
*/
struct GNUNET_JSON_Specification
-TALER_JSON_spec_amount_nbo (const char *name,
- const char *currency,
- struct TALER_AmountNBO *r_amount);
+TALER_JSON_spec_currency_specification (
+ const char *name,
+ const char *currency_code,
+ struct TALER_CurrencySpecification *r_cspec);
/**
@@ -317,17 +284,33 @@ struct GNUNET_JSON_Specification
TALER_JSON_spec_age_commitment (const char *name,
struct TALER_AgeCommitment *age_commitment);
+
/**
- * Provide specification to parse given JSON object to an amount
- * in any currency in network byte order.
+ * Provide specification to parse an OTP key.
+ * An OTP key must be an RFC 3548 base32-encoded
+ * value (so NOT our usual Crockford-base32 encoding!).
*
- * @param name name of the amount field in the JSON
- * @param[out] r_amount where the amount has to be written
- * @return spec for parsing an amount
+ * @param name name of the OTP key field in the JSON
+ * @param[out] otp_key where to store the OTP key
+ * @return spec for parsing an age commitment
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_otp_key (const char *name,
+ const char **otp_key);
+
+
+/**
+ * Provide specification to parse an OTP method type.
+ * The value could be provided as an integer or
+ * as a descriptive string.
+ *
+ * @param name name of the OTP method type in the JSON
+ * @param[out] mca where to store the method type
+ * @return spec for parsing an age commitment
*/
struct GNUNET_JSON_Specification
-TALER_JSON_spec_amount_any_nbo (const char *name,
- struct TALER_AmountNBO *r_amount);
+TALER_JSON_spec_otp_type (const char *name,
+ enum TALER_MerchantConfirmationAlgorithm *mca);
/**
@@ -366,7 +349,6 @@ TALER_JSON_spec_amount_any_nbo (const char *name,
* @param[out] gfs a `struct TALER_GlobalFeeSet` to initialize
*/
#define TALER_JSON_SPEC_GLOBAL_FEES(currency,gfs) \
- TALER_JSON_spec_amount ("kyc_fee", (currency), &(gfs)->kyc), \
TALER_JSON_spec_amount ("history_fee", (currency), &(gfs)->history), \
TALER_JSON_spec_amount ("account_fee", (currency), &(gfs)->account), \
TALER_JSON_spec_amount ("purse_fee", (currency), &(gfs)->purse)
@@ -377,31 +359,10 @@ TALER_JSON_spec_amount_any_nbo (const char *name,
* @param gfs a `struct TALER_GlobalFeeSet` to pack
*/
#define TALER_JSON_PACK_GLOBAL_FEES(gfs) \
- TALER_JSON_pack_amount ("kyc_fee", &(gfs)->kyc), \
TALER_JSON_pack_amount ("history_fee", &(gfs)->history), \
TALER_JSON_pack_amount ("account_fee", &(gfs)->account), \
TALER_JSON_pack_amount ("purse_fee", &(gfs)->purse)
-/**
- * Group of Denominations. These are the common fields of an array of
- * denominations.
- *
- * The corresponding JSON-blob will also contain an array of particular
- * denominations with only the timestamps, cipher-specific public key and the
- * master signature.
- *
- **/
-struct TALER_DenominationGroup
-{
- enum TALER_DenominationCipher cipher;
- struct TALER_Amount value;
- struct TALER_DenomFeeSet fees;
- struct TALER_AgeMask age_mask;
-
- // hash is/should be the XOR of all SHA-512 hashes of the public keys in this
- // group
- struct GNUNET_HashCode hash;
-};
/**
* Generate a parser for a group of denominations.
@@ -427,19 +388,111 @@ struct GNUNET_JSON_Specification
TALER_JSON_spec_denom_pub (const char *field,
struct TALER_DenominationPublicKey *pk);
+
+/**
+ * Generate line in parser specification for error codes.
+ *
+ * @param field name of the field
+ * @param[out] ec error code to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_ec (const char *field,
+ enum TALER_ErrorCode *ec);
+
+
+/**
+ * Generate line in parser specification for
+ * HTTP/HTTPS URLs.
+ *
+ * @param field name of the field
+ * @param[out] url web URL to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_web_url (const char *field,
+ const char **url);
+
+
+/**
+ * Generate line in parser specification for
+ * "payto://" URIs.
+ *
+ * @param field name of the field
+ * @param[out] payto_uri RFC 8905 URI to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_payto_uri (const char *field,
+ const char **payto_uri);
+
+
+/**
+ * Generate line in parser specification for AML decision states.
+ *
+ * @param field name of the field
+ * @param[out] aml_state AML state to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_aml_decision (const char *field,
+ enum TALER_AmlDecisionState *aml_state);
+
+
+/**
+ * Representation of a protocol version.
+ */
+struct TALER_JSON_ProtocolVersion
+{
+ /**
+ * Current version of the protocol.
+ */
+ unsigned int current;
+
+ /**
+ * Implementation revision for the @e current
+ * version.
+ */
+ unsigned int revision;
+
+ /**
+ * Number of protocol versions this @e revision is
+ * backwards-compatible with. Subtract this number
+ * from @e current to get the minimum protocol version
+ * required from the client.
+ */
+ unsigned int age;
+};
+
+
+/**
+ * Generate line in parser specification for protocol
+ * versions (``/config``). The field must be a string
+ * encoding the version as "$CURRENT:$REVISION:$AGE".
+ *
+ * @param field name of the field (usually "version")
+ * @param[out] ver protocol versions to initialize
+ * @return corresponding field spec
+ */
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_version (const char *field,
+ struct TALER_JSON_ProtocolVersion *ver);
+
+
/**
* Generate a parser specification for a denomination public key of a given
* cipher.
*
* @param field name of the field
- * @parm cipher which cipher type to parse for
+ * @param cipher which cipher type to parse for
* @param[out] pk key to fill
* @return corresponding field spec
*/
struct GNUNET_JSON_Specification
-TALER_JSON_spec_denom_pub_cipher (const char *field,
- const enum TALER_DenominationCipher cipher,
- struct TALER_DenominationPublicKey *pk);
+TALER_JSON_spec_denom_pub_cipher (
+ const char *field,
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
+ struct TALER_DenominationPublicKey *pk);
/**
@@ -555,16 +608,18 @@ TALER_JSON_contract_hash (const json_t *json,
/**
- * Take a given contract with "forgettable" fields marked
- * but with 'True' instead of a real salt. Replaces all
- * 'True' values with proper random salts. Fails if any
- * forgettable markers are neither 'True' nor valid salts.
+ * Take a given @a contract with "forgettable" fields marked in the @a spec
+ * with 'True' instead of a real salt. Replaces all 'True' values with proper
+ * random salts in the actual @a contract. Fails if any forgettable markers
+ * are neither 'True' nor valid salts.
*
- * @param[in,out] json JSON to transform
+ * @param spec specification with forgettable fields
+ * @param[in,out] contract JSON contract to transform
* @return #GNUNET_OK on success
*/
enum GNUNET_GenericReturnValue
-TALER_JSON_contract_seed_forgettable (json_t *json);
+TALER_JSON_contract_seed_forgettable (const json_t *spec,
+ json_t *contract);
/**
@@ -677,33 +732,6 @@ TALER_JSON_merchant_wire_signature_hash (const json_t *wire_s,
/**
- * Check the signature in @a wire_s. Also performs rudimentary
- * checks on the account data *if* supported.
- *
- * @param wire_s signed wire information of an exchange
- * @param master_pub master public key of the exchange
- * @return #GNUNET_OK if signature is valid
- */
-enum GNUNET_GenericReturnValue
-TALER_JSON_exchange_wire_signature_check (
- const json_t *wire_s,
- const struct TALER_MasterPublicKeyP *master_pub);
-
-
-/**
- * Create a signed wire statement for the given account.
- *
- * @param payto_uri account specification
- * @param master_priv private key to sign with
- * @return NULL if @a payto_uri is malformed
- */
-json_t *
-TALER_JSON_exchange_wire_signature_make (
- const char *payto_uri,
- const struct TALER_MasterPrivateKeyP *master_priv);
-
-
-/**
* Extract a string from @a object under the field @a field, but respecting
* the Taler i18n rules and the language preferences expressed in @a
* language_pattern.
@@ -767,25 +795,25 @@ TALER_JSON_wire_to_payto (const json_t *wire_s);
/**
- * Hash @a extensions in deposits.
+ * Hash @a policy extensions in deposits.
*
- * @param extensions contract extensions to hash
- * @param[out] ech where to write the extension hash
+ * @param policy contract policy extension to hash
+ * @param[out] ech where to write the policy hash
*/
void
-TALER_deposit_extension_hash (const json_t *extensions,
- struct TALER_ExtensionContractHashP *ech);
+TALER_deposit_policy_hash (const json_t *policy,
+ struct TALER_ExtensionPolicyHashP *ech);
/**
- * Hash the @a config of an extension, given as JSON
+ * Hash the @a manifests of extensions, given as JSON
*
- * @param config configuration of the extension
- * @param[out] eh where to write the extension hash
+ * @param manifests Manifests of the extensions
+ * @param[out] eh where to write the hash
* @return GNUNET_OK on success, GNUNET_SYSERR on failure
*/
enum GNUNET_GenericReturnValue
-TALER_JSON_extensions_config_hash (const json_t *config,
- struct TALER_ExtensionConfigHashP *eh);
+TALER_JSON_extensions_manifests_hash (const json_t *manifests,
+ struct TALER_ExtensionManifestsHashP *eh);
/**
* Canonicalize a JSON input to a string according to RFC 8785.
diff --git a/src/include/taler_kyclogic_lib.h b/src/include/taler_kyclogic_lib.h
new file mode 100644
index 000000000..4d0c18fa4
--- /dev/null
+++ b/src/include/taler_kyclogic_lib.h
@@ -0,0 +1,374 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler_kyclogic_lib.h
+ * @brief server-side KYC API
+ * @author Christian Grothoff
+ */
+#ifndef TALER_KYCLOGIC_LIB_H
+#define TALER_KYCLOGIC_LIB_H
+
+#include <microhttpd.h>
+#include "taler_exchangedb_plugin.h"
+#include "taler_kyclogic_plugin.h"
+
+
+/**
+ * Enumeration for our KYC user types.
+ */
+enum TALER_KYCLOGIC_KycUserType
+{
+ /**
+ * KYC rule is for an individual.
+ */
+ TALER_KYCLOGIC_KYC_UT_INDIVIDUAL = 0,
+
+ /**
+ * KYC rule is for a business.
+ */
+ TALER_KYCLOGIC_KYC_UT_BUSINESS = 1
+};
+
+
+/**
+ * Enumeration of possible events that may trigger
+ * KYC requirements.
+ */
+enum TALER_KYCLOGIC_KycTriggerEvent
+{
+
+ /**
+ * Customer withdraws coins.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_WITHDRAW = 0,
+
+ /**
+ * Merchant deposits coins.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT = 1,
+
+ /**
+ * Wallet receives P2P payment.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE = 2,
+
+ /**
+ * Wallet balance exceeds threshold.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE = 3,
+
+ /**
+ * Reserve is being closed by force.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE = 4,
+
+ /**
+ * Customer withdraws coins via age-withdraw.
+ */
+ TALER_KYCLOGIC_KYC_TRIGGER_AGE_WITHDRAW = 5,
+};
+
+
+/**
+ * Parse KYC trigger string value from a string
+ * into enumeration value.
+ *
+ * @param trigger_s string to parse
+ * @param[out] trigger set to the value found
+ * @return #GNUNET_OK on success, #GNUNET_NO if option
+ * does not exist, #GNUNET_SYSERR if option is
+ * malformed
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_trigger_from_string (
+ const char *trigger_s,
+ enum TALER_KYCLOGIC_KycTriggerEvent *trigger);
+
+
+/**
+ * Convert KYC trigger value to human-readable string.
+ *
+ * @param trigger value to convert
+ * @return human-readable representation of the @a trigger
+ */
+const char *
+TALER_KYCLOGIC_kyc_trigger2s (enum TALER_KYCLOGIC_KycTriggerEvent trigger);
+
+
+/**
+ * Parse user type string into enumeration value.
+ *
+ * @param ut_s string to parse
+ * @param[out] ut set to the value found
+ * @return #GNUNET_OK on success, #GNUNET_NO if option
+ * does not exist, #GNUNET_SYSERR if option is
+ * malformed
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_user_type_from_string (const char *ut_s,
+ enum TALER_KYCLOGIC_KycUserType *ut);
+
+
+/**
+ * Convert KYC user type to human-readable string.
+ *
+ * @param ut value to convert
+ * @return human-readable representation of the @a ut
+ */
+const char *
+TALER_KYCLOGIC_kyc_user_type2s (enum TALER_KYCLOGIC_KycUserType ut);
+
+
+/**
+ * Initialize KYC subsystem. Loads the KYC configuration.
+ *
+ * @param cfg configuration to parse
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
+
+
+/**
+ * Shut down the KYC subsystem.
+ */
+void
+TALER_KYCLOGIC_kyc_done (void);
+
+
+/**
+ * Function called to iterate over KYC-relevant
+ * transaction amounts for a particular time range.
+ * Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param cls closure, identifies the event type and
+ * account to iterate over events for
+ * @param limit maximum time-range for which events
+ * should be fetched (timestamp in the past)
+ * @param cb function to call on each event found,
+ * events must be returned in reverse chronological
+ * order
+ * @param cb_cls closure for @a cb
+ */
+typedef void
+(*TALER_KYCLOGIC_KycAmountIterator)(void *cls,
+ struct GNUNET_TIME_Absolute limit,
+ TALER_EXCHANGEDB_KycAmountCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Function called to iterate over KYC-relevant
+ * transaction thresholds amounts.
+ *
+ * @param cls closure, identifies the event type and
+ * account to iterate over events for
+ * @param threshold a relevant threshold amount
+ */
+typedef void
+(*TALER_KYCLOGIC_KycThresholdIterator)(void *cls,
+ const struct TALER_Amount *threshold);
+
+
+/**
+ * Call us on KYC processes satisfied for the given
+ * account. Must match the ``select_satisfied_kyc_processes`` of the exchange database plugin.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param h_payto account identifier
+ * @param spc function to call for each satisfied KYC process
+ * @param spc_cls closure for @a spc
+ * @return transaction status code
+ */
+typedef enum GNUNET_DB_QueryStatus
+(*TALER_KYCLOGIC_KycSatisfiedIterator)(
+ void *cls,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_EXCHANGEDB_SatisfiedProviderCallback spc,
+ void *spc_cls);
+
+
+/**
+ * Check if KYC is provided for a particular operation. Returns the set of checks that still need to be satisfied.
+ *
+ * Called within a database transaction, so must
+ * not start a new one.
+ *
+ * @param event what type of operation is triggering the
+ * test if KYC is required
+ * @param h_payto account the event is about
+ * @param ki callback that returns list of already
+ * satisfied KYC checks, implemented by ``select_satisfied_kyc_processes`` of the exchangedb
+ * @param ki_cls closure for @a ki
+ * @param ai callback offered to inquire about historic
+ * amounts involved in this type of operation
+ * at the given account
+ * @param ai_cls closure for @a ai
+ * @param[out] required set to NULL if no check is needed,
+ * otherwise space-separated list of required checks
+ * @return transaction status
+ */
+enum GNUNET_DB_QueryStatus
+TALER_KYCLOGIC_kyc_test_required (enum TALER_KYCLOGIC_KycTriggerEvent event,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_KYCLOGIC_KycSatisfiedIterator ki,
+ void *ki_cls,
+ TALER_KYCLOGIC_KycAmountIterator ai,
+ void *ai_cls,
+ char **required);
+
+
+/**
+ * Check if the @a requirements are now satsified for
+ * @a h_payto account.
+ *
+ * @param[in,out] requirements space-spearated list of requirements,
+ * already satisfied requirements are removed from the list
+ * @param h_payto hash over the account
+ * @param[out] kyc_details if satisfied, set to what kind of
+ * KYC information was collected
+ * @param ki iterator over satisfied providers
+ * @param ki_cls closure for @a ki
+ * @param[out] satisfied set to true if the KYC check was satisfied
+ * @return transaction status (from @a ki)
+ */
+enum GNUNET_DB_QueryStatus
+TALER_KYCLOGIC_check_satisfied (char **requirements,
+ const struct TALER_PaytoHashP *h_payto,
+ json_t **kyc_details,
+ TALER_KYCLOGIC_KycSatisfiedIterator ki,
+ void *ki_cls,
+ bool *satisfied);
+
+
+/**
+ * Iterate over all thresholds that are applicable
+ * to a particular type of @a event
+ *
+ * @param event thresholds to look up
+ * @param it function to call on each
+ * @param it_cls closure for @a it
+ */
+void
+TALER_KYCLOGIC_kyc_iterate_thresholds (
+ enum TALER_KYCLOGIC_KycTriggerEvent event,
+ TALER_KYCLOGIC_KycThresholdIterator it,
+ void *it_cls);
+
+
+/**
+ * Function called with the provider details and
+ * associated plugin closures for matching logics.
+ *
+ * @param cls closure
+ * @param pd provider details of a matching logic
+ * @param plugin_cls closure of the plugin
+ * @return #GNUNET_OK to continue to iterate
+ */
+typedef enum GNUNET_GenericReturnValue
+(*TALER_KYCLOGIC_DetailsCallback)(
+ void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ void *plugin_cls);
+
+
+/**
+ * Call @a cb for all logics with name @a logic_name,
+ * providing the plugin closure and the @a pd configurations.
+ *
+ * @param logic_name name of the logic to match
+ * @param cb function to call on matching results
+ * @param cb_cls closure for @a cb
+ */
+void
+TALER_KYCLOGIC_kyc_get_details (
+ const char *logic_name,
+ TALER_KYCLOGIC_DetailsCallback cb,
+ void *cb_cls);
+
+
+/**
+ * Check if a given @a check_name is a legal name (properly
+ * configured) and can be satisfied in principle.
+ *
+ * @param check_name name of the check to see if it is configured
+ * @return #GNUNET_OK if the check can be satisfied,
+ * #GNUNET_NO if the check can never be satisfied,
+ * #GNUNET_SYSERR if the type of the check is unknown
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_check_satisfiable (
+ const char *check_name);
+
+
+/**
+ * Return list of all KYC checks that are possible.
+ *
+ * @return JSON array of strings with the allowed KYC checks
+ */
+json_t *
+TALER_KYCLOGIC_get_satisfiable (void);
+
+
+/**
+ * Obtain the provider logic for a given set of @a requirements.
+ *
+ * @param requirements space-separated list of required checks
+ * @param ut type of the entity performing the check
+ * @param[out] plugin set to the KYC logic API
+ * @param[out] pd set to the specific operation context
+ * @param[out] configuration_section set to the name of the KYC logic configuration section * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_requirements_to_logic (const char *requirements,
+ enum TALER_KYCLOGIC_KycUserType ut,
+ struct TALER_KYCLOGIC_Plugin **plugin,
+ struct TALER_KYCLOGIC_ProviderDetails **pd,
+ const char **configuration_section);
+
+
+/**
+ * Obtain the provider logic for a given @a name.
+ *
+ * @param name name of the logic or provider section
+ * @param[out] plugin set to the KYC logic API
+ * @param[out] pd set to the specific operation context
+ * @param[out] configuration_section set to the name of the KYC logic configuration section
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_lookup_logic (const char *name,
+ struct TALER_KYCLOGIC_Plugin **plugin,
+ struct TALER_KYCLOGIC_ProviderDetails **pd,
+ const char **configuration_section);
+
+
+/**
+ * Obtain array of KYC checks provided by the provider
+ * configured in @a section_name.
+ *
+ * @param section_name configuration section name
+ * @param[out] num_checks set to the length of the array
+ * @param[out] provided_checks set to an array with the
+ * names of the checks provided by this KYC provider
+ */
+void
+TALER_KYCLOGIC_lookup_checks (const char *section_name,
+ unsigned int *num_checks,
+ char ***provided_checks);
+
+#endif
diff --git a/src/include/taler_kyclogic_plugin.h b/src/include/taler_kyclogic_plugin.h
new file mode 100644
index 000000000..a9a4dd97a
--- /dev/null
+++ b/src/include/taler_kyclogic_plugin.h
@@ -0,0 +1,384 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file include/taler_kyclogic_plugin.h
+ * @brief KYC API specific logic C interface
+ * @author Christian Grothoff
+ */
+#ifndef TALER_KYCLOGIC_PLUGIN_H
+#define TALER_KYCLOGIC_PLUGIN_H
+
+#include <jansson.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_db_lib.h>
+#include "taler_util.h"
+
+
+/**
+ * Possible states of a KYC check.
+ */
+enum TALER_KYCLOGIC_KycStatus
+{
+
+ /**
+ * The provider has passed the customer.
+ */
+ TALER_KYCLOGIC_STATUS_SUCCESS = 0,
+
+ /**
+ * Something to do with the user (bit!).
+ */
+ TALER_KYCLOGIC_STATUS_USER = 1,
+
+ /**
+ * Something to do with the provider (bit!).
+ */
+ TALER_KYCLOGIC_STATUS_PROVIDER = 2,
+
+ /**
+ * The interaction ended in definitive failure.
+ * (kind of with both parties).
+ */
+ TALER_KYCLOGIC_STATUS_FAILED
+ = TALER_KYCLOGIC_STATUS_USER
+ | TALER_KYCLOGIC_STATUS_PROVIDER,
+
+ /**
+ * The interaction is still ongoing.
+ */
+ TALER_KYCLOGIC_STATUS_PENDING = 4,
+
+ /**
+ * One of the parties hat a temporary failure.
+ */
+ TALER_KYCLOGIC_STATUS_ABORTED = 8,
+
+ /**
+ * The interaction with the user is ongoing.
+ */
+ TALER_KYCLOGIC_STATUS_USER_PENDING
+ = TALER_KYCLOGIC_STATUS_USER
+ | TALER_KYCLOGIC_STATUS_PENDING,
+
+ /**
+ * The provider is still checking.
+ */
+ TALER_KYCLOGIC_STATUS_PROVIDER_PENDING
+ = TALER_KYCLOGIC_STATUS_PROVIDER
+ | TALER_KYCLOGIC_STATUS_PENDING,
+
+ /**
+ * The user aborted the check (possibly recoverable)
+ * or made some other type of (recoverable) mistake.
+ */
+ TALER_KYCLOGIC_STATUS_USER_ABORTED
+ = TALER_KYCLOGIC_STATUS_USER
+ | TALER_KYCLOGIC_STATUS_ABORTED,
+
+ /**
+ * The provider had an (internal) failure.
+ */
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED
+ = TALER_KYCLOGIC_STATUS_PROVIDER
+ | TALER_KYCLOGIC_STATUS_ABORTED,
+
+ /**
+ * Return code set to not update the KYC status
+ * at all.
+ */
+ TALER_KYCLOGIC_STATUS_KEEP = 16,
+
+ /**
+ * We had an internal logic failure.
+ */
+ TALER_KYCLOGIC_STATUS_INTERNAL_ERROR = 32
+
+};
+
+
+/**
+ * Plugin-internal specification of the configuration
+ * of the plugin for a given KYC provider.
+ */
+struct TALER_KYCLOGIC_ProviderDetails;
+
+/**
+ * Handle for an initiation operation.
+ */
+struct TALER_KYCLOGIC_InitiateHandle;
+
+/**
+ * Handle for an KYC proof operation.
+ */
+struct TALER_KYCLOGIC_ProofHandle;
+
+/**
+ * Handle for an KYC Web hook operation.
+ */
+struct TALER_KYCLOGIC_WebhookHandle;
+
+
+/**
+ * Function called with the result of a KYC initiation
+ * operation.
+ *
+ * @param cls closure
+ * @param ec #TALER_EC_NONE on success
+ * @param redirect_url set to where to redirect the user on success, NULL on failure
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param error_msg_hint set to additional details to return to user, NULL on success
+ */
+typedef void
+(*TALER_KYCLOGIC_InitiateCallback)(
+ void *cls,
+ enum TALER_ErrorCode ec,
+ const char *redirect_url,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ const char *error_msg_hint);
+
+
+/**
+ * Function called with the result of a proof check operation.
+ *
+ * Note that the "decref" for the @a response
+ * will be done by the callee and MUST NOT be done by the plugin.
+ *
+ * @param cls closure
+ * @param status KYC status
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param attributes user attributes returned by the provider
+ * @param expiration until when is the KYC check valid
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ */
+typedef void
+(*TALER_KYCLOGIC_ProofCallback)(
+ void *cls,
+ enum TALER_KYCLOGIC_KycStatus status,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response);
+
+
+/**
+ * Function called with the result of a webhook operation.
+ *
+ * Note that the "decref" for the @a response will be done by the callee and
+ * MUST NOT be done by the plugin!
+ *
+ * @param cls closure
+ * @param process_row legitimization process the webhook was about
+ * @param account_id account the webhook was about
+ * @param provider_section name of the configuration section of the logic that was run
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param status KYC status
+ * @param expiration until when is the KYC check valid
+ * @param attributes user attributes returned by the provider
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ */
+typedef void
+(*TALER_KYCLOGIC_WebhookCallback)(
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ enum TALER_KYCLOGIC_KycStatus status,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response);
+
+
+/**
+ * Function the plugin can use to lookup an @a h_payto by @a
+ * provider_legitimization_id. Must match the `kyc_provider_account_lookup`
+ * of the exchange's database plugin.
+ *
+ * @param cls closure
+ * @param provider_section
+ * @param provider_legitimization_id legi to look up
+ * @param[out] h_payto where to write the result
+ * @param[out] process_row where to write the row of the entry
+ * @return database transaction status
+ */
+typedef enum GNUNET_DB_QueryStatus
+(*TALER_KYCLOGIC_ProviderLookupCallback)(
+ void *cls,
+ const char *provider_section,
+ const char *provider_legitimization_id,
+ struct TALER_PaytoHashP *h_payto,
+ uint64_t *process_row);
+
+
+/**
+ * @brief The plugin API, returned from the plugin's "init" function.
+ * The argument given to "init" is simply a configuration handle.
+ */
+struct TALER_KYCLOGIC_Plugin
+{
+
+ /**
+ * Closure for all callbacks.
+ */
+ void *cls;
+
+ /**
+ * Name of the library which generated this plugin. Set by the
+ * plugin loader.
+ */
+ char *library_name;
+
+ /**
+ * Name of the logic, for webhook matching. Set by the
+ * plugin loader.
+ */
+ char *name;
+
+ /**
+ * Load the configuration of the KYC provider.
+ *
+ * @param cls closure
+ * @param provider_section_name configuration section to parse
+ * @return NULL if configuration is invalid
+ */
+ struct TALER_KYCLOGIC_ProviderDetails *
+ (*load_configuration)(void *cls,
+ const char *provider_section_name);
+
+ /**
+ * Release configuration resources previously loaded
+ *
+ * @param[in] pd configuration to release
+ */
+ void
+ (*unload_configuration)(struct TALER_KYCLOGIC_ProviderDetails *pd);
+
+
+ /**
+ * Initiate KYC check.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param account_id which account to trigger process for
+ * @param process_row unique ID for the legitimization process
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+ struct TALER_KYCLOGIC_InitiateHandle *
+ (*initiate)(void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ TALER_KYCLOGIC_InitiateCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Cancel KYC check initiation.
+ *
+ * @param[in] ih handle of operation to cancel
+ */
+ void
+ (*initiate_cancel) (struct TALER_KYCLOGIC_InitiateHandle *ih);
+
+
+ /**
+ * Check KYC status and return status to human.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param connection MHD connection object (for HTTP headers)
+ * @param account_id which account to trigger process for
+ * @param process_row row in the legitimization processes table the legitimization is for
+ * @param provider_user_id user ID (or NULL) the proof is for
+ * @param provider_legitimization_id legitimization ID the proof is for
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+ struct TALER_KYCLOGIC_ProofHandle *
+ (*proof)(void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ TALER_KYCLOGIC_ProofCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+ void
+ (*proof_cancel) (struct TALER_KYCLOGIC_ProofHandle *ph);
+
+
+ /**
+ * Check KYC status and return result for Webhook.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param plc callback to lookup accounts with
+ * @param plc_cls closure for @a plc
+ * @param http_method HTTP method used for the webhook
+ * @param url_path rest of the URL after `/kyc-webhook/$LOGIC/`
+ * @param connection MHD connection object (for HTTP headers)
+ * @param body_size number of bytes in @a body
+ * @param body HTTP request body
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+ struct TALER_KYCLOGIC_WebhookHandle *
+ (*webhook)(void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ TALER_KYCLOGIC_ProviderLookupCallback plc,
+ void *plc_cls,
+ const char *http_method,
+ const char *const url_path[],
+ struct MHD_Connection *connection,
+ const json_t *upload,
+ TALER_KYCLOGIC_WebhookCallback cb,
+ void *cb_cls);
+
+
+ /**
+ * Cancel KYC webhook execution.
+ *
+ * @param[in] wh handle of operation to cancel
+ */
+ void
+ (*webhook_cancel) (struct TALER_KYCLOGIC_WebhookHandle *wh);
+
+};
+
+
+#endif /* _TALER_KYCLOGIC_PLUGIN_H */
diff --git a/src/include/taler_mhd_lib.h b/src/include/taler_mhd_lib.h
index b64231352..57d041758 100644
--- a/src/include/taler_mhd_lib.h
+++ b/src/include/taler_mhd_lib.h
@@ -27,6 +27,7 @@
#include <jansson.h>
#include <microhttpd.h>
#include "taler_error_codes.h"
+#include "taler_util.h"
#include <gnunet/gnunet_mhd_compat.h>
@@ -172,8 +173,8 @@ TALER_MHD_reply_json_pack (struct MHD_Connection *connection,
* @return MHD result code
*/
#define TALER_MHD_REPLY_JSON_PACK(connection,response_code,...) \
- TALER_MHD_reply_json_steal (connection, GNUNET_JSON_PACK (__VA_ARGS__), \
- response_code)
+ TALER_MHD_reply_json_steal (connection, GNUNET_JSON_PACK (__VA_ARGS__), \
+ response_code)
/**
@@ -258,7 +259,7 @@ TALER_MHD_make_json_pack (const char *fmt,
* @return MHD response object
*/
#define TALER_MHD_MAKE_JSON_PACK(...) \
- TALER_MHD_make_json_steal (GNUNET_JSON_PACK (__VA_ARGS__))
+ TALER_MHD_make_json_steal (GNUNET_JSON_PACK (__VA_ARGS__))
/**
@@ -269,8 +270,8 @@ TALER_MHD_make_json_pack (const char *fmt,
* @return packer array entries (two!)
*/
#define TALER_MHD_PACK_EC(ec) \
- GNUNET_JSON_pack_uint64 ("code", ec), \
- GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec))
+ GNUNET_JSON_pack_uint64 ("code", ec), \
+ GNUNET_JSON_pack_string ("hint", TALER_ErrorCode_get_hint (ec))
/**
* Create a response indicating an internal error.
@@ -437,7 +438,201 @@ TALER_MHD_parse_json_array (struct MHD_Connection *connection,
/**
- * Extract fixed-size base32crockford encoded data from request.
+ * Extract optional "timeout_ms" argument from request.
+ *
+ * @param connection the MHD connection
+ * @param[out] expiration set to #GNUNET_TIME_UNIT_ZERO_ABS if there was no timeout,
+ * the current time plus the value given under "timeout_ms" otherwise
+ * @return #GNUNET_OK on success, #GNUNET_NO if an
+ * error was returned on @a connection (caller should return #MHD_YES) and
+ * #GNUNET_SYSERR if we failed to return an error (caller should return #MHD_NO)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_timeout (struct MHD_Connection *connection,
+ struct GNUNET_TIME_Absolute *expiration);
+
+
+/**
+ * Extract optional "timeout_ms" argument from request.
+ * Macro that *returns* #MHD_YES/#MHD_NO if the "timeout_ms"
+ * argument existed but failed to parse.
+ *
+ * @param connection the MHD connection
+ * @param[out] expiration set to #GNUNET_TIME_UNIT_ZERO_ABS if there was no timeout,
+ * the current time plus the value given under "timeout_ms" otherwise
+ */
+#define TALER_MHD_parse_request_timeout(connection,expiration) \
+ do { \
+ switch (TALER_MHD_parse_request_arg_timeout (connection, \
+ expiration)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ case GNUNET_OK: \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Extract optional numeric limit argument from request.
+ *
+ * @param connection the MHD connection
+ * @param name name of the query parameter
+ * @param[out] off set to the offset, unchanged if the
+ * option was not given
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if an error was returned on @a connection (caller should return #MHD_YES) and
+ * #GNUNET_SYSERR if we failed to return an error (caller should return #MHD_NO)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_number (struct MHD_Connection *connection,
+ const char *name,
+ uint64_t *off);
+
+
+/**
+ * Extract optional numeric argument from request.
+ * Macro that *returns* #MHD_YES/#MHD_NO if the
+ * requested argument existed but failed to parse.
+ *
+ * @param connection the MHD connection
+ * @param name name of the argument to parse
+ * @param[out] off set to the given numeric value,
+ * unchanged if value was not specified
+ */
+#define TALER_MHD_parse_request_number(connection,name,off) \
+ do { \
+ switch (TALER_MHD_parse_request_arg_number (connection, \
+ name, \
+ off)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ case GNUNET_OK: \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Extract optional signed numeric limit argument from request.
+ *
+ * @param connection the MHD connection
+ * @param name name of the query parameter
+ * @param[out] val set to the signed value, unchanged if the
+ * option was not given
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if an error was returned on @a connection (caller should return #MHD_YES) and
+ * #GNUNET_SYSERR if we failed to return an error (caller should return #MHD_NO)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_snumber (struct MHD_Connection *connection,
+ const char *name,
+ int64_t *val);
+
+
+/**
+ * Extract optional numeric argument from request.
+ * Macro that *returns* #MHD_YES/#MHD_NO if the
+ * requested argument existed but failed to parse.
+ *
+ * @param connection the MHD connection
+ * @param name name of the argument to parse
+ * @param[out] val set to the given numeric value,
+ * unchanged if value was not specified
+ */
+#define TALER_MHD_parse_request_snumber(connection,name,val) \
+ do { \
+ switch (TALER_MHD_parse_request_arg_snumber (connection, \
+ name, \
+ val)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ case GNUNET_OK: \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Extract optional amount argument from request.
+ *
+ * @param connection the MHD connection
+ * @param name name of the query parameter
+ * @param[out] val set to the amount, unchanged if the
+ * option was not given
+ * @return #GNUNET_OK on success,
+ * #GNUNET_NO if an error was returned on @a connection (caller should return #MHD_YES) and
+ * #GNUNET_SYSERR if we failed to return an error (caller should return #MHD_NO)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_amount (struct MHD_Connection *connection,
+ const char *name,
+ struct TALER_Amount *val);
+
+
+/**
+ * Extract optional amount argument from request.
+ * Macro that *returns* #MHD_YES/#MHD_NO if the
+ * requested argument existed but failed to parse.
+ *
+ * @param connection the MHD connection
+ * @param name name of the argument to parse
+ * @param[out] val set to the given amount,
+ * unchanged if value was not specified
+ */
+#define TALER_MHD_parse_request_amount(connection,name,val) \
+ do { \
+ switch (TALER_MHD_parse_request_arg_amount (connection, \
+ name, \
+ val)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ case GNUNET_OK: \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Determines which of the given choices is preferred
+ * by the client. Parses an HTTP header such as
+ * "Accept:" or "Language:" to find entries matching
+ * the list of strings given in the variadic argument
+ * list. Returns the index of the preferred choice.
+ *
+ * @param connection HTTP request handle
+ * @param header type of HTTP header to evaluate
+ * @param ... NULL-terminated list of choices to
+ * check for in the header
+ * @return -1 if none of the given choices is in
+ * the header, -2 if the header is missing,
+ * otherwise index of preferred choice in
+ * the varargs list
+ */
+int
+TALER_MHD_check_accept (struct MHD_Connection *connection,
+ const char *header,
+ ...);
+
+
+/**
+ * Extract fixed-size base32crockford encoded data from request argument.
*
* Queues an error response to the connection if the parameter is missing or
* invalid.
@@ -446,16 +641,195 @@ TALER_MHD_parse_json_array (struct MHD_Connection *connection,
* @param param_name the name of the parameter with the key
* @param[out] out_data pointer to store the result
* @param out_size expected size of @a out_data
+ * @param[out] present set to true if argument was found
* @return
* #GNUNET_YES if the the argument is present
- * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_NO if the argument is malformed
* #GNUNET_SYSERR on internal error (error response could not be sent)
*/
enum GNUNET_GenericReturnValue
TALER_MHD_parse_request_arg_data (struct MHD_Connection *connection,
const char *param_name,
void *out_data,
- size_t out_size);
+ size_t out_size,
+ bool *present);
+
+
+/**
+ * Extract fixed-size base32crockford encoded data from request header.
+ *
+ * Queues an error response to the connection if the parameter is missing or
+ * invalid.
+ *
+ * @param connection the MHD connection
+ * @param header_name the name of the HTTP header with the value
+ * @param[out] out_data pointer to store the result
+ * @param out_size expected size of @a out_data
+ * @param[out] present set to true if argument was found
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_header_data (struct MHD_Connection *connection,
+ const char *header_name,
+ void *out_data,
+ size_t out_size,
+ bool *present);
+
+/**
+ * Extract fixed-size base32crockford encoded data from request.
+ *
+ * @param connection the MHD connection
+ * @param name the name of the parameter with the key
+ * @param[out] val pointer to store the result, type must determine size
+ * @param[in,out] required pass true to require presence of this argument; if 'false'
+ * set to true if the argument was found
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+#define TALER_MHD_parse_request_arg_auto(connection,name,val,required) \
+ do { \
+ bool p; \
+ switch (TALER_MHD_parse_request_arg_data (connection, name, \
+ val, sizeof (*val), &p)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ return MHD_YES; \
+ case GNUNET_OK: \
+ if (required & (! p)) \
+ return TALER_MHD_reply_with_error ( \
+ connection, \
+ MHD_HTTP_BAD_REQUEST, \
+ TALER_EC_GENERIC_PARAMETER_MISSING, \
+ name); \
+ required = p; \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Extract required fixed-size base32crockford encoded data from request.
+ *
+ * @param connection the MHD connection
+ * @param name the name of the parameter with the key
+ * @param[out] val pointer to store the result, type must determine size
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+#define TALER_MHD_parse_request_arg_auto_t(connection,name,val) \
+ do { \
+ bool b = true; \
+ TALER_MHD_parse_request_arg_auto (connection,name,val,b); \
+ } while (0)
+
+/**
+ * Extract fixed-size base32crockford encoded data from request.
+ *
+ * @param connection the MHD connection
+ * @param name the name of the header with the key
+ * @param[out] val pointer to store the result, type must determine size
+ * @param[in,out] required pass true to require presence of this argument; if 'false'
+ * set to true if the argument was found
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+#define TALER_MHD_parse_request_header_auto(connection,name,val,required) \
+ do { \
+ bool p; \
+ switch (TALER_MHD_parse_request_header_data (connection, name, \
+ val, sizeof (*val), &p)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ return MHD_YES; \
+ case GNUNET_OK: \
+ if (required & (! p)) \
+ return TALER_MHD_reply_with_error ( \
+ connection, \
+ MHD_HTTP_BAD_REQUEST, \
+ TALER_EC_GENERIC_PARAMETER_MISSING, \
+ name); \
+ required = p; \
+ break; \
+ } \
+ } while (0)
+
+
+/**
+ * Extract required fixed-size base32crockford encoded data from request.
+ *
+ * @param connection the MHD connection
+ * @param name the name of the header with the key
+ * @param[out] val pointer to store the result, type must determine size
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+#define TALER_MHD_parse_request_header_auto_t(connection,name,val) \
+ do { \
+ bool b = true; \
+ TALER_MHD_parse_request_header_auto (connection,name,val,b); \
+ } while (0)
+
+
+/**
+ * Check that the 'Content-Length' header is giving
+ * a length below @a max_len. If not, return an
+ * appropriate error response and return the
+ * correct #MHD_YES/#MHD_NO value from this function.
+ *
+ * @param connection the MHD connection
+ * @param max_len maximum allowed content length
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+enum GNUNET_GenericReturnValue
+TALER_MHD_check_content_length_ (struct MHD_Connection *connection,
+ unsigned long long max_len);
+
+
+/**
+ * Check that the 'Content-Length' header is giving
+ * a length below @a max_len. If not, return an
+ * appropriate error response and return the
+ * correct #MHD_YES/#MHD_NO value from this function.
+ *
+ * @param connection the MHD connection
+ * @param max_len maximum allowed content length
+ */
+#define TALER_MHD_check_content_length(connection,max_len) \
+ do { \
+ switch (TALER_MHD_check_content_length_ (connection, max_len)) \
+ { \
+ case GNUNET_SYSERR: \
+ GNUNET_break (0); \
+ return MHD_NO; \
+ case GNUNET_NO: \
+ GNUNET_break_op (0); \
+ return MHD_YES; \
+ case GNUNET_OK: \
+ break; \
+ } \
+ } while (0)
/**
diff --git a/src/include/taler_pq_lib.h b/src/include/taler_pq_lib.h
index fdc17ca55..f45de61d9 100644
--- a/src/include/taler_pq_lib.h
+++ b/src/include/taler_pq_lib.h
@@ -19,37 +19,50 @@
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Florian Dold
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
#ifndef TALER_PQ_LIB_H_
#define TALER_PQ_LIB_H_
#include <libpq-fe.h>
#include <jansson.h>
+#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_pq_lib.h>
#include "taler_util.h"
/**
- * Generate query parameter for a currency, consisting of the three
- * components "value", "fraction" and "currency" in this order. The
- * types must be a 64-bit integer, 32-bit integer and a
- * #TALER_CURRENCY_LEN-sized BLOB/VARCHAR respectively.
+ * API version. Bump on every change.
+ */
+#define TALER_PQ_VERSION 0x09040000
+
+/**
+ * Generate query parameter (as record tuple) for an amount, consisting
+ * of the two components "value" and "fraction" in this order. The
+ * types must be a 64-bit integer and a 32-bit integer
+ * respectively. The currency is dropped.
*
- * @param x pointer to the query parameter to pass
+ * @param db The database context for OID lookup
+ * @param amount pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x);
+TALER_PQ_query_param_amount (
+ const struct GNUNET_PQ_Context *db,
+ const struct TALER_Amount *amount);
/**
- * Generate query parameter for an amount, consisting of the two
- * components "value" and "fraction" in this order. The
- * types must be a 64-bit integer and a 32-bit integer
- * respectively. The currency is dropped.
+ * Generate query parameter (as record tuple) for an amount, consisting of the
+ * three components "value", "fraction" and "currency" in this order. The
+ * types must be a 64-bit integer, a 32-bit integer and a TEXT field of 12
+ * characters respectively.
*
- * @param x pointer to the query parameter to pass
+ * @param db The database context for OID lookup
+ * @param amount pointer to the query parameter to pass
*/
struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_amount (const struct TALER_Amount *x);
+TALER_PQ_query_param_amount_with_currency (
+ const struct GNUNET_PQ_Context *db,
+ const struct TALER_Amount *amount);
/**
@@ -127,21 +140,115 @@ TALER_PQ_query_param_json (const json_t *x);
/**
- * Currency amount expected.
+ * Generate query parameter for an array of blinded denomination signatures
+ *
+ * @param num number of elements in @e denom_sigs
+ * @param denom_sigs array of blinded denomination signatures
+ * @param db context for the db-connection
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_blinded_denom_sig (
+ size_t num,
+ const struct TALER_BlindedDenominationSignature *denom_sigs,
+ struct GNUNET_PQ_Context *db
+ );
+
+
+/**
+ * Generate query parameter for an array of blinded hashes of coin envelopes
+ *
+ * @param num number of elements in @e denom_sigs
+ * @param coin_evs array of blinded hashes of coin envelopes
+ * @param db context for the db-connection
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_blinded_coin_hash (
+ size_t num,
+ const struct TALER_BlindedCoinHashP *coin_evs,
+ struct GNUNET_PQ_Context *db);
+
+
+/**
+ * Generate query parameter for an array of GNUNET_HashCode
+ *
+ * @param num number of elements in @e hash_codes
+ * @param hashes array of GNUNET_HashCode
+ * @param db context for the db-connection
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_hash_code (
+ size_t num,
+ const struct GNUNET_HashCode *hashes,
+ struct GNUNET_PQ_Context *db);
+
+
+/**
+ * Generate query parameter for an array of amounts
+ *
+ * @param num of elements in @e amounts
+ * @param amounts continuous array of amounts
+ * @param db context for db-connection, needed for OID-lookup
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount (
+ size_t num,
+ const struct TALER_Amount *amounts,
+ struct GNUNET_PQ_Context *db);
+
+
+/**
+ * Generate query parameter for an array of amounts
+ *
+ * @param num of elements in @e amounts
+ * @param amounts continuous array of amounts
+ * @param db context for db-connection, needed for OID-lookup
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount_with_currency (
+ size_t num,
+ const struct TALER_Amount *amounts,
+ struct GNUNET_PQ_Context *db);
+
+
+/**
+ * Generate query parameter for a blind sign public key of variable size.
+ *
+ * @param public_key pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_blind_sign_pub (
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *public_key);
+
+
+/**
+ * Generate query parameter for a blind sign private key of variable size.
+ *
+ * @param private_key pointer to the query parameter to pass
+ */
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_blind_sign_priv (
+ const struct GNUNET_CRYPTO_BlindSignPrivateKey *private_key);
+
+
+/**
+ * Currency amount expected, from a record-field of (DB)
+ * taler_amount_with_currency type. The currency must be stored in the
+ * database when using this function.
*
* @param name name of the field in the table
- * @param currency currency to use for @a amount
* @param[out] amount where to store the result
* @return array entry for the result specification to use
*/
struct GNUNET_PQ_ResultSpec
-TALER_PQ_result_spec_amount_nbo (const char *name,
- const char *currency,
- struct TALER_AmountNBO *amount);
+TALER_PQ_result_spec_amount_with_currency (
+ const char *name,
+ struct TALER_Amount *amount);
/**
- * Currency amount expected.
+ * Currency amount expected, from a record-field of (DB) taler_amount type.
+ * The currency is NOT stored in the database when using this function, but
+ * instead passed as the @a currency argument.
*
* @param name name of the field in the table
* @param currency currency to use for @a amount
@@ -229,6 +336,92 @@ TALER_PQ_result_spec_json (const char *name,
json_t **jp);
+/**
+ * Array of blinded denomination signature expected
+ *
+ * @param db context of the database connection
+ * @param name name of the field in the table
+ * @param[out] num number of elements in @e denom_sigs
+ * @param[out] denom_sigs where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_blinded_denom_sig (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_BlindedDenominationSignature **denom_sigs);
+
+
+/**
+ * Array of blinded hashes of coin envelopes
+ *
+ * @param db context of the database connection
+ * @param name name of the field in the table
+ * @param[out] num number of elements in @e denom_sigs
+ * @param[out] h_coin_evs where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_blinded_coin_hash (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_BlindedCoinHashP **h_coin_evs);
+
+
+/**
+ * Array of hashes of denominations
+ *
+ * @param db context of the database connection
+ * @param name name of the field in the table
+ * @param[out] num number of elements in @e denom_sigs
+ * @param[out] denom_hs where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_denom_hash (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_DenominationHashP **denom_hs);
+
+
+/**
+ * Array of GNUNET_HashCode
+ *
+ * @param db context of the database connection
+ * @param name name of the field in the table
+ * @param[out] num number of elements in @e denom_sigs
+ * @param[out] hashes where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_hash_code (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct GNUNET_HashCode **hashes);
+
+/**
+ * Array of amounts
+ *
+ * @param db context of the database connection
+ * @param name name of the field in the table
+ * @param currency The currency
+ * @param[out] num number of elements in @e amounts
+ * @param[out] amounts where to store the result
+ * @return array entry for the result specification to use
+ */
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_amount (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ const char *currency,
+ size_t *num,
+ struct TALER_Amount **amounts);
+
+
#endif /* TALER_PQ_LIB_H_ */
/* end of include/taler_pq_lib.h */
diff --git a/src/include/taler_templating_lib.h b/src/include/taler_templating_lib.h
new file mode 100644
index 000000000..6af6db715
--- /dev/null
+++ b/src/include/taler_templating_lib.h
@@ -0,0 +1,130 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020, 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file taler_templating_lib.h
+ * @brief logic to load and complete HTML templates
+ * @author Christian Grothoff
+ */
+#ifndef TALER_TEMPLATING_LIB_H
+#define TALER_TEMPLATING_LIB_H
+
+#include <microhttpd.h>
+#include "taler_mhd_lib.h"
+
+/**
+ * Fill in Mustach template @a tmpl using the data from @a root
+ * and return the result in @a result.
+ *
+ * @param tmpl 0-terminated string with Mustach template
+ * @param root JSON data to fill into the template
+ * @param[out] result where to write the result
+ * @param[out] result_size where to write the length of the result
+ * @return 0 on success, otherwise Mustach-specific error code
+ */
+int
+TALER_TEMPLATING_fill (const char *tmpl,
+ const json_t *root,
+ void **result,
+ size_t *result_size);
+
+
+/**
+ * Load a @a template and substitute using @a root, returning the result in a
+ * @a reply encoded suitable for the @a connection with the given @a
+ * http_status code. On errors, the @a http_status code
+ * is updated to reflect the type of error encoded in the
+ * @a reply.
+ *
+ * @param connection the connection we act upon
+ * @param[in,out] http_status code to use on success,
+ * set to alternative code on failure
+ * @param template basename of the template to load
+ * @param instance_id instance ID, used to compute static files URL
+ * @param taler_uri value for "Taler:" header to set, or NULL
+ * @param root JSON object to pass as the root context
+ * @param[out] reply where to write the response object
+ * @return #GNUNET_OK on success (reply queued), #GNUNET_NO if an error was queued,
+ * #GNUNET_SYSERR on failure (to queue an error)
+ */
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_build (struct MHD_Connection *connection,
+ unsigned int *http_status,
+ const char *template,
+ const char *instance_id,
+ const char *taler_uri,
+ const json_t *root,
+ struct MHD_Response **reply);
+
+
+/**
+ * Load a @a template and substitute using @a root, returning
+ * the result to the @a connection with the given
+ * @a http_status code.
+ *
+ * @param connection the connection we act upon
+ * @param http_status code to use on success
+ * @param template basename of the template to load
+ * @param instance_id instance ID, used to compute static files URL
+ * @param taler_uri value for "Taler:" header to set, or NULL
+ * @param root JSON object to pass as the root context
+ * @return #GNUNET_OK on success (reply queued), #GNUNET_NO if an error was queued,
+ * #GNUNET_SYSERR on failure (to queue an error)
+ */
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_reply (struct MHD_Connection *connection,
+ unsigned int http_status,
+ const char *template,
+ const char *instance_id,
+ const char *taler_uri,
+ const json_t *root);
+
+
+/**
+ * Load a @a template and substitute an error message based on @a ec and @a
+ * detail, returning the result to the @a connection with the given @a
+ * http_status code.
+ *
+ * @param connection the connection we act upon
+ * @param template_basename basename of the template to load
+ * @param http_status code to use on success
+ * @param ec error code to return
+ * @param detail optional text to add to the template
+ * @return #MHD_YES on success, #MHD_NO to just close the connection
+ */
+MHD_RESULT
+TALER_TEMPLATING_reply_error (struct MHD_Connection *connection,
+ const char *template_basename,
+ unsigned int http_status,
+ enum TALER_ErrorCode ec,
+ const char *detail);
+
+/**
+ * Preload templates.
+ *
+ * @param subsystem name of the subsystem, "merchant" or "exchange"
+ * @return #GNUNET_OK on success
+ */
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_init (const char *subsystem);
+
+
+/**
+ * Nicely shut down templating subsystem.
+ */
+void
+TALER_TEMPLATING_done (void);
+
+#endif
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 0f94e1c29..f07d9be20 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2018-2022 Taler Systems SA
+ (C) 2018-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -20,6 +20,8 @@
/**
* @file include/taler_testing_lib.h
* @brief API for writing an interpreter to test Taler components
+ * This library is not thread-safe, all APIs must only be used from a single thread.
+ * This library calls abort() if it runs out of memory. Be aware of these limitations.
* @author Christian Grothoff <christian@grothoff.org>
* @author Marcello Stanisci
*/
@@ -27,11 +29,13 @@
#define TALER_TESTING_LIB_H
#include "taler_util.h"
-#include "taler_exchange_service.h"
+#include <microhttpd.h>
#include <gnunet/gnunet_json_lib.h>
#include "taler_json_lib.h"
+#include "taler_auditor_service.h"
#include "taler_bank_service.h"
-#include <microhttpd.h>
+#include "taler_exchange_service.h"
+#include "taler_fakebank_lib.h"
/* ********************* Helper functions ********************* */
@@ -50,157 +54,156 @@
/**
- * Allocate and return a piece of wire-details. Combines
- * a @a payto -URL and adds some salt to create the JSON.
+ * Log an error message about us receiving an unexpected HTTP
+ * status code at the current command and fail the test.
*
- * @param payto payto://-URL to encapsulate
- * @return JSON describing the account, including the
- * payto://-URL of the account, must be manually decref'd
+ * @param is interpreter to fail
+ * @param status unexpected HTTP status code received
+ * @param expected expected HTTP status code
*/
-json_t *
-TALER_TESTING_make_wire_details (const char *payto);
+#define TALER_TESTING_unexpected_status(is,status,expected) \
+ do { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
+ "Unexpected response code %u (expected: %u) to command %s in %s:%u\n", \
+ status, \
+ expected, \
+ TALER_TESTING_interpreter_get_current_label (is), \
+ __FILE__, \
+ __LINE__); \
+ TALER_TESTING_interpreter_fail (is); \
+ } while (0)
+
+/**
+ * Log an error message about us receiving an unexpected HTTP
+ * status code at the current command and fail the test and print the response
+ * body (expected as json).
+ *
+ * @param is interpreter to fail
+ * @param status unexpected HTTP status code received
+ * @param expected expected HTTP status code
+ * @param body received JSON-reply
+ */
+#define TALER_TESTING_unexpected_status_with_body(is,status,expected,body) \
+ do { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
+ "Unexpected response code %u (expected: %u) to " \
+ "command %s in %s:%u\nwith body:\n>>%s<<\n", \
+ status, \
+ expected, \
+ TALER_TESTING_interpreter_get_current_label (is), \
+ __FILE__, \
+ __LINE__, \
+ json_dumps (body, JSON_INDENT (2))); \
+ TALER_TESTING_interpreter_fail (is); \
+ } while (0)
/**
- * Find denomination key matching the given amount.
+ * Log an error message about a command not having
+ * run to completion.
*
- * @param keys array of keys to search
- * @param amount coin value to look for
- * @param age_restricted must the denomination be age restricted?
- * @return NULL if no matching key was found
+ * @param is interpreter
+ * @param label command label of the incomplete command
*/
-const struct TALER_EXCHANGE_DenomPublicKey *
-TALER_TESTING_find_pk (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_Amount *amount,
- bool age_restricted);
+#define TALER_TESTING_command_incomplete(is,label) \
+ do { \
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, \
+ "Command %s (%s:%u) did not complete (at %s)\n", \
+ label, \
+ __FILE__, \
+ __LINE__, \
+ TALER_TESTING_interpreter_get_current_label (is)); \
+ } while (0)
/**
- * Configuration data for an exchange.
+ * Common credentials used in a test.
*/
-struct TALER_TESTING_ExchangeConfiguration
+struct TALER_TESTING_Credentials
{
/**
- * Exchange base URL as it appears in the configuration. Note
- * that it might differ from the one where the exchange actually
- * listens from.
+ * Bank authentication details for the exchange bank
+ * account.
*/
- char *exchange_url;
+ struct TALER_BANK_AuthenticationData ba;
/**
- * Auditor base URL as it appears in the configuration. Note
- * that it might differ from the one where the auditor actually
- * listens from.
+ * Bank authentication details for the admin bank
+ * account.
*/
- char *auditor_url;
+ struct TALER_BANK_AuthenticationData ba_admin;
-};
+ /**
+ * Configuration file data.
+ */
+ struct GNUNET_CONFIGURATION_Handle *cfg;
-/**
- * Connection to the database: aggregates
- * plugin and session handles.
- */
-struct TALER_TESTING_DatabaseConnection
-{
/**
- * Database plugin.
+ * Base URL of the exchange.
*/
- struct TALER_EXCHANGEDB_Plugin *plugin;
+ char *exchange_url;
-};
+ /**
+ * Base URL of the auditor.
+ */
+ char *auditor_url;
-struct TALER_TESTING_LibeufinServices
-{
/**
- * Nexus
+ * RFC 8905 URI of the exchange.
*/
- struct GNUNET_OS_Process *nexus;
+ char *exchange_payto;
/**
- * Sandbox
+ * RFC 8905 URI of a user.
*/
- struct GNUNET_OS_Process *sandbox;
+ char *user42_payto;
+ /**
+ * RFC 8905 URI of a user.
+ */
+ char *user43_payto;
};
-/**
- * Prepare launching an exchange. Checks that the configured
- * port is available, runs taler-exchange-keyup,
- * taler-auditor-sign and taler-exchange-dbinit. Does not
- * launch the exchange process itself.
- *
- * @param config_filename configuration file to use
- * @param reset_db should we reset the database
- * @param[out] ec will be set to the exchange configuration data
- * @return #GNUNET_OK on success, #GNUNET_NO if test should be
- * skipped, #GNUNET_SYSERR on test failure
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_exchange (const char *config_filename,
- int reset_db,
- struct TALER_TESTING_ExchangeConfiguration *ec);
-
/**
- * "Canonical" cert_cb used when we are connecting to the
- * Exchange.
- *
- * @param cls closure, typically, the "run" method containing
- * all the commands to be run, and a closure for it.
- * @param hr http response details
- * @param keys the exchange's keys.
- * @param compat protocol compatibility information.
+ * What type of bank are we using?
*/
-void
-TALER_TESTING_cert_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat);
-
-
-/**
- * Wait for the exchange to have started. Waits for at
- * most 10s, after that returns 77 to indicate an error.
- *
- * @param base_url what URL should we expect the exchange
- * to be running at
- * @return 0 on success
- */
-int
-TALER_TESTING_wait_exchange_ready (const char *base_url);
-
-
-/**
- * Wait for an HTTPD service to have started. Waits for at
- * most 10s, after that returns 77 to indicate an error.
- *
- * @param base_url what URL should we expect the exchange
- * to be running at
- * @return 0 on success
- */
-int
-TALER_TESTING_wait_httpd_ready (const char *base_url);
+enum TALER_TESTING_BankSystem
+{
+ TALER_TESTING_BS_FAKEBANK = 1,
+ TALER_TESTING_BS_IBAN = 2
+};
/**
- * Wait for the auditor to have started. Waits for at
- * most 10s, after that returns 77 to indicate an error.
+ * Obtain bank credentials for a given @a cfg_file using
+ * @a exchange_account_section as the basis for the
+ * exchange account.
*
- * @param base_url what URL should we expect the auditor
- * to be running at
- * @return 0 on success
+ * @param cfg_file name of configuration to parse
+ * @param exchange_account_section configuration section name for the exchange account to use
+ * @param bs type of bank to use
+ * @param[out] ua where to write user account details
+ * and other credentials
*/
-int
-TALER_TESTING_wait_auditor_ready (const char *base_url);
+enum GNUNET_GenericReturnValue
+TALER_TESTING_get_credentials (
+ const char *cfg_file,
+ const char *exchange_account_section,
+ enum TALER_TESTING_BankSystem bs,
+ struct TALER_TESTING_Credentials *ua);
/**
- * Remove files from previous runs
+ * Allocate and return a piece of wire-details. Combines
+ * a @a payto -URL and adds some salt to create the JSON.
*
- * @param config_name configuration file to use+
+ * @param payto payto://-URL to encapsulate
+ * @return JSON describing the account, including the
+ * payto://-URL of the account, must be manually decref'd
*/
-void
-TALER_TESTING_cleanup_files (const char *config_name);
+json_t *
+TALER_TESTING_make_wire_details (const char *payto);
/**
@@ -216,65 +219,17 @@ TALER_TESTING_cleanup_files_cfg (void *cls,
/**
- * Run `taler-exchange-offline`.
- *
- * @param config_filename configuration file to use
- * @param payto_uri bank account to enable, can be NULL
- * @param auditor_pub public key of auditor to enable, can be NULL
- * @param auditor_url URL of auditor to enable, can be NULL
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_run_exchange_offline (const char *config_filename,
- const char *payto_uri,
- const char *auditor_pub,
- const char *auditor_url);
-
-
-/**
- * Run `taler-auditor-dbinit -r` (reset auditor database).
- *
- * @param config_filename configuration file to use
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_auditor_db_reset (const char *config_filename);
-
-
-/**
- * Run `taler-exchange-dbinit -r` (reset exchange database).
- *
- * @param config_filename configuration file to use
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_exchange_db_reset (const char *config_filename);
-
-
-/**
- * Run `taler-auditor-offline` tool.
- *
- * @param config_filename configuration file to use
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_run_auditor_offline (const char *config_filename);
-
-
-/**
- * Run `taler-auditor-exchange`.
+ * Find denomination key matching the given amount.
*
- * @param config_filename configuration file to use
- * @param exchange_master_pub master public key of the exchange
- * @param exchange_base_url what is the base URL of the exchange
- * @param do_remove #GNUNET_NO to add exchange, #GNUNET_YES to remove
- * @return #GNUNET_OK on success
+ * @param keys array of keys to search
+ * @param amount coin value to look for
+ * @param age_restricted must the denomination be age restricted?
+ * @return NULL if no matching key was found
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_run_auditor_exchange (const char *config_filename,
- const char *exchange_master_pub,
- const char *exchange_base_url,
- int do_remove);
+const struct TALER_EXCHANGE_DenomPublicKey *
+TALER_TESTING_find_pk (const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *amount,
+ bool age_restricted);
/**
@@ -287,194 +242,13 @@ enum GNUNET_GenericReturnValue
TALER_TESTING_url_port_free (const char *url);
-/**
- * Configuration data for a bank.
- */
-struct TALER_TESTING_BankConfiguration
-{
-
- /**
- * Authentication data for the exchange user at the bank.
- */
- struct TALER_BANK_AuthenticationData exchange_auth;
-
- /**
- * Payto URL of the exchange's account ("2")
- */
- char *exchange_payto;
-
- /**
- * Payto URL of a user account ("42")
- */
- char *user42_payto;
-
- /**
- * Payto URL of another user's account ("43")
- */
- char *user43_payto;
-
-};
-
-/**
- * Prepare launching a fakebank. Check that the configuration
- * file has the right option, and that the port is available.
- * If everything is OK, return the configuration data of the fakebank.
- *
- * @param config_filename configuration file to use
- * @param config_section which account to use
- * (must match x-taler-bank)
- * @param[out] bc set to the bank's configuration data
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_fakebank (const char *config_filename,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc);
-
-
/* ******************* Generic interpreter logic ************ */
/**
* Global state of the interpreter, used by a command
* to access information about other commands.
*/
-struct TALER_TESTING_Interpreter
-{
-
- /**
- * Commands the interpreter will run.
- */
- struct TALER_TESTING_Command *commands;
-
- /**
- * Interpreter task (if one is scheduled).
- */
- struct GNUNET_SCHEDULER_Task *task;
-
- /**
- * ID of task called whenever we get a SIGCHILD.
- * Used for #TALER_TESTING_wait_for_sigchld().
- */
- struct GNUNET_SCHEDULER_Task *child_death_task;
-
- /**
- * Main execution context for the main loop.
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * Our configuration.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Context for running the CURL event loop.
- */
- struct GNUNET_CURL_RescheduleContext *rc;
-
- /**
- * Handle to our fakebank, if #TALER_TESTING_run_with_fakebank()
- * was used. Otherwise NULL.
- */
- struct TALER_FAKEBANK_Handle *fakebank;
-
- /**
- * Task run on timeout.
- */
- struct GNUNET_SCHEDULER_Task *timeout_task;
-
- /**
- * Function to call for cleanup at the end. Can be NULL.
- */
- GNUNET_SCHEDULER_TaskCallback final_cleanup_cb;
-
- /**
- * Closure for #final_cleanup_cb().
- */
- void *final_cleanup_cb_cls;
-
- /**
- * Instruction pointer. Tells #interpreter_run() which instruction to run
- * next. Need (signed) int because it gets -1 when rewinding the
- * interpreter to the first CMD.
- */
- int ip;
-
- /**
- * Result of the testcases, #GNUNET_OK on success
- */
- int result;
-
- /**
- * Handle to the exchange.
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * Handle to the auditor. NULL unless specifically initialized
- * as part of #TALER_TESTING_auditor_setup().
- */
- struct TALER_AUDITOR_Handle *auditor;
-
- /**
- * Handle to exchange process; some commands need it
- * to send signals. E.g. to trigger the key state reload.
- */
- struct GNUNET_OS_Process *exchanged;
-
- /**
- * Public key of the auditor.
- */
- struct TALER_AuditorPublicKeyP auditor_pub;
-
- /**
- * Private key of the auditor.
- */
- struct TALER_AuditorPrivateKeyP auditor_priv;
-
- /**
- * Private offline signing key.
- */
- struct TALER_MasterPrivateKeyP master_priv;
-
- /**
- * Public offline signing key.
- */
- struct TALER_MasterPublicKeyP master_pub;
-
- /**
- * URL of the auditor (as per configuration).
- */
- char *auditor_url;
-
- /**
- * URL of the exchange (as per configuration).
- */
- char *exchange_url;
-
- /**
- * Is the interpreter running (#GNUNET_YES) or waiting
- * for /keys (#GNUNET_NO)?
- */
- int working;
-
- /**
- * Is the auditor running (#GNUNET_YES) or waiting
- * for /version (#GNUNET_NO)?
- */
- int auditor_working;
-
- /**
- * How often have we gotten a /keys response so far?
- */
- unsigned int key_generation;
-
- /**
- * Exchange keys from last download.
- */
- const struct TALER_EXCHANGE_Keys *keys;
-
-};
+struct TALER_TESTING_Interpreter;
/**
@@ -495,6 +269,11 @@ struct TALER_TESTING_Command
const char *label;
/**
+ * Variable name for the command, NULL for none.
+ */
+ const char *name;
+
+ /**
* Runs the command. Note that upon return, the interpreter
* will not automatically run the next command, as the command
* may continue asynchronously in other scheduler tasks. Thus,
@@ -504,12 +283,12 @@ struct TALER_TESTING_Command
*
* @param cls closure
* @param cmd command being run
- * @param i interpreter state
+ * @param is interpreter state
*/
void
(*run)(void *cls,
const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *i);
+ struct TALER_TESTING_Interpreter *is);
/**
@@ -578,7 +357,41 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is,
/**
- * Obtain main execution context for the main loop.
+ * Get command from hash map by variable name.
+ *
+ * @param is interpreter state.
+ * @param name name of the variable to get command by
+ * @return the command, if it is found, or NULL.
+ */
+const struct TALER_TESTING_Command *
+TALER_TESTING_interpreter_get_command (struct TALER_TESTING_Interpreter *is,
+ const char *name);
+
+
+/**
+ * Update the last request time of the current command
+ * to the current time.
+ *
+ * @param[in,out] is interpreter state where to show
+ * that we are doing something
+ */
+void
+TALER_TESTING_touch_cmd (struct TALER_TESTING_Interpreter *is);
+
+
+/**
+ * Increment the 'num_tries' counter for the current
+ * command.
+ *
+ * @param[in,out] is interpreter state where to
+ * increment the counter
+ */
+void
+TALER_TESTING_inc_tries (struct TALER_TESTING_Interpreter *is);
+
+
+/**
+ * Obtain CURL context for the main loop.
*
* @param is interpreter state.
* @return CURL execution context.
@@ -599,15 +412,6 @@ TALER_TESTING_interpreter_get_current_label (
/**
- * Get connection handle to the fakebank.
- *
- * @param is interpreter state.
- * @return the handle.
- */
-struct TALER_FAKEBANK_Handle *
-TALER_TESTING_interpreter_get_fakebank (struct TALER_TESTING_Interpreter *is);
-
-/**
* Current command is done, run the next one.
*
* @param is interpreter state.
@@ -623,14 +427,6 @@ TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *is);
void
TALER_TESTING_interpreter_fail (struct TALER_TESTING_Interpreter *is);
-/**
- * Create command array terminator.
- *
- * @return a end-command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_end (void);
-
/**
* Make the instruction pointer point to @a target_label
@@ -687,20 +483,6 @@ TALER_TESTING_run2 (struct TALER_TESTING_Interpreter *is,
/**
- * First launch the fakebank, then schedule the first CMD
- * in the array of all the CMDs to execute.
- *
- * @param is interpreter state.
- * @param commands array of all the commands to execute.
- * @param bank_url base URL of the fake bank.
- */
-void
-TALER_TESTING_run_with_fakebank (struct TALER_TESTING_Interpreter *is,
- struct TALER_TESTING_Command *commands,
- const char *bank_url);
-
-
-/**
* The function that contains the array of all the CMDs to run,
* which is then on charge to call some fashion of
* TALER_TESTING_run*. In all the test cases, this function is
@@ -715,261 +497,197 @@ typedef void
/**
- * Install signal handlers plus schedules the main wrapper
- * around the "run" method.
+ * Run Taler testing loop. Starts the GNUnet SCHEDULER (event loop).
*
- * @param main_cb the "run" method which coontains all the
- * commands.
- * @param main_cb_cls a closure for "run", typically NULL.
- * @param cfg configuration to use
- * @param exchanged exchange process handle: will be put in the
- * state as some commands - e.g. revoke - need to send
- * signal to it, for example to let it know to reload the
- * key state. If NULL, the interpreter will run without
- * trying to connect to the exchange first.
- * @param exchange_connect #GNUNET_YES if the test should connect
- * to the exchange, #GNUNET_NO otherwise
- * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
- * non-#GNUNET_OK codes are #GNUNET_SYSERR most of the
- * times.
+ * @param main_cb main function to run
+ * @param main_cb_cls closure for @a main_cb
*/
enum GNUNET_GenericReturnValue
-TALER_TESTING_setup (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_OS_Process *exchanged,
- int exchange_connect);
+TALER_TESTING_loop (TALER_TESTING_Main main_cb,
+ void *main_cb_cls);
/**
- * Install signal handlers plus schedules the main wrapper
- * around the "run" method.
+ * Convenience function to run a test.
*
- * @param main_cb the "run" method which contains all the
- * commands.
- * @param main_cb_cls a closure for "run", typically NULL.
- * @param config_filename configuration filename.
- * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
- * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
- * times.
+ * @param argv command-line arguments given
+ * @param loglevel log level to use
+ * @param cfg_file configuration file to use
+ * @param exchange_account_section configuration section
+ * with exchange bank account to use
+ * @param bs bank system to use
+ * @param[in,out] cred global credentials to initialize
+ * @param main_cb main test function to run
+ * @param main_cb_cls closure for @a main_cb
+ * @return 0 on success, 77 on setup trouble, non-zero process status code otherwise
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_auditor_setup (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_filename);
+int
+TALER_TESTING_main (char *const *argv,
+ const char *loglevel,
+ const char *cfg_file,
+ const char *exchange_account_section,
+ enum TALER_TESTING_BankSystem bs,
+ struct TALER_TESTING_Credentials *cred,
+ TALER_TESTING_Main main_cb,
+ void *main_cb_cls);
/**
- * Closure for #TALER_TESTING_setup_with_exchange_cfg().
+ * Callback over commands of an interpreter.
+ *
+ * @param cls closure
+ * @param cmd a command to process
*/
-struct TALER_TESTING_SetupContext
-{
- /**
- * Main function of the test to run.
- */
- TALER_TESTING_Main main_cb;
-
- /**
- * Closure for @e main_cb.
- */
- void *main_cb_cls;
-
- /**
- * Name of the configuration file.
- */
- const char *config_filename;
-};
+typedef void
+(*TALER_TESTING_CommandIterator)(
+ void *cls,
+ const struct TALER_TESTING_Command *cmd);
/**
- * Initialize scheduler loop and curl context for the test case
- * including starting and stopping the exchange using the given
- * configuration file.
+ * Iterates over all of the top-level commands of an
+ * interpreter.
*
- * @param cls must be a `struct TALER_TESTING_SetupContext *`
- * @param cfg configuration to use.
- * @return #GNUNET_OK if no errors occurred.
+ * @param[in] is interpreter to iterate over
+ * @param asc true in execution order, false for reverse execution order
+ * @param cb function to call on each command
+ * @param cb_cls closure for cb
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_exchange_cfg (
- void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+void
+TALER_TESTING_iterate (struct TALER_TESTING_Interpreter *is,
+ bool asc,
+ TALER_TESTING_CommandIterator cb,
+ void *cb_cls);
/**
- * Initialize scheduler loop and curl context for the test case
- * including starting and stopping the exchange using the given
- * configuration file.
+ * Look for substring in a programs' name.
*
- * @param main_cb main method.
- * @param main_cb_cls main method closure.
- * @param config_file configuration file name. Is is used
- * by both this function and the exchange itself. In the
- * first case it gives out the exchange port number and
- * the exchange base URL so as to check whether the port
- * is available and the exchange responds when requested
- * at its base URL.
- * @return #GNUNET_OK if no errors occurred.
+ * @param prog program's name to look into
+ * @param marker chunk to find in @a prog
+ * @return true if @a marker is in @a prog
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_exchange (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_file);
+bool
+TALER_TESTING_has_in_name (const char *prog,
+ const char *marker);
/**
- * Initialize scheduler loop and curl context for the test case
- * including starting and stopping the auditor and exchange using
- * the given configuration file.
+ * Wait for an HTTPD service to have started. Waits for at
+ * most 10s, after that returns 77 to indicate an error.
*
- * @param cls must be a `struct TALER_TESTING_SetupContext *`
- * @param cfg configuration to use.
- * @return #GNUNET_OK if no errors occurred.
+ * @param base_url what URL should we expect the exchange
+ * to be running at
+ * @return 0 on success
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_auditor_and_exchange_cfg (
- void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg);
+int
+TALER_TESTING_wait_httpd_ready (const char *base_url);
/**
- * Initialize scheduler loop and curl context for the test case
- * including starting and stopping the auditor and exchange using
- * the given configuration file.
+ * Parse reference to a coin.
*
- * @param main_cb main method.
- * @param main_cb_cls main method closure.
- * @param config_file configuration file name. Is is used
- * by both this function and the exchange itself. In the
- * first case it gives out the exchange port number and
- * the exchange base URL so as to check whether the port
- * is available and the exchange responds when requested
- * at its base URL.
- * @return #GNUNET_OK if no errors occurred.
+ * @param coin_reference of format $LABEL['#' $INDEX]?
+ * @param[out] cref where we return a copy of $LABEL
+ * @param[out] idx where we set $INDEX
+ * @return #GNUNET_SYSERR if $INDEX is present but not numeric
*/
enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_auditor_and_exchange (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_file);
+TALER_TESTING_parse_coin_reference (
+ const char *coin_reference,
+ char **cref,
+ unsigned int *idx);
-/**
- * Start the (Python) bank process. Assume the port
- * is available and the database is clean. Use the "prepare
- * bank" function to do such tasks.
- *
- * @param config_filename configuration filename.
- * @param bank_url base URL of the bank, used by `wget' to check
- * that the bank was started right.
- * @return the process, or NULL if the process could not
- * be started.
- */
-struct GNUNET_OS_Process *
-TALER_TESTING_run_bank (const char *config_filename,
- const char *bank_url);
+/* ************** Specific interpreter commands ************ */
+
/**
- * Start the (nexus) bank process. Assume the port
- * is available and the database is clean. Use the "prepare
- * bank" function to do such tasks. This function is also
- * responsible to create the exchange EBICS subscriber at
- * the nexus.
+ * Create command array terminator.
*
- * @param bc bank configuration of the bank
- * @return the process, or NULL if the process could not
- * be started.
+ * @return a end-command.
*/
-struct TALER_TESTING_LibeufinServices
-TALER_TESTING_run_libeufin (const struct TALER_TESTING_BankConfiguration *bc);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_end (void);
/**
- * Runs the Fakebank by guessing / extracting the portnumber
- * from the base URL.
+ * Set variable to command as side-effect of
+ * running a command.
*
- * @param bank_url bank's base URL.
- * @param currency currency the bank uses
- * @return the fakebank process handle, or NULL if any
- * error occurs.
+ * @param name name of the variable to set
+ * @param cmd command to set to variable when run
+ * @return modified command
*/
-struct TALER_FAKEBANK_Handle *
-TALER_TESTING_run_fakebank (const char *bank_url,
- const char *currency);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_set_var (const char *name,
+ struct TALER_TESTING_Command cmd);
/**
- * Prepare the bank execution. Check if the port is available
- * and reset database.
+ * Launch GNU Taler setup.
*
- * @param config_filename configuration file name.
- * @param reset_db should we reset the bank's database
- * @param config_section which configuration section should be used
- * @param[out] bc set to the bank's configuration data
- * @return #GNUNET_OK on success
+ * @param label command label.
+ * @param config_file configuration file to use
+ * @param ... NULL-terminated (const char *) arguments to pass to taler-benchmark-setup.sh
+ * @return the command.
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_bank (const char *config_filename,
- int reset_db,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_system_start (
+ const char *label,
+ const char *config_file,
+ ...);
-/**
- * Prepare the Nexus execution. Check if the port is available
- * and delete old database.
- *
- * @param config_filename configuration file name.
- * @param reset_db should we reset the bank's database
- * @param config_section section of the configuration with the exchange's account
- * @param[out] bc set to the bank's configuration data
- * @return the base url, or NULL upon errors. Must be freed
- * by the caller.
- */
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_nexus (const char *config_filename,
- int reset_db,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc);
/**
- * Look for substring in a programs' name.
+ * Connects to the exchange.
*
- * @param prog program's name to look into
- * @param marker chunk to find in @a prog
+ * @param label command label
+ * @param cfg configuration to use
+ * @param last_keys_ref reference to command with prior /keys response, NULL for none
+ * @param wait_for_keys block until we got /keys
+ * @param load_private_key obtain private key from file indicated in @a cfg
+ * @return the command.
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_has_in_name (const char *prog,
- const char *marker);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_exchange (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *last_keys_ref,
+ bool wait_for_keys,
+ bool load_private_key);
/**
- * Parse reference to a coin.
+ * Connects to the auditor.
*
- * @param coin_reference of format $LABEL['#' $INDEX]?
- * @param[out] cref where we return a copy of $LABEL
- * @param[out] idx where we set $INDEX
- * @return #GNUNET_SYSERR if $INDEX is present but not numeric
+ * @param label command label
+ * @param cfg configuration to use
+ * @param load_auditor_keys obtain auditor keys from file indicated in @a cfg
+ * @return the command.
*/
-enum GNUNET_GenericReturnValue
-TALER_TESTING_parse_coin_reference (
- const char *coin_reference,
- char **cref,
- unsigned int *idx);
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_auditor (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool load_auditor_keys);
/**
- * Compare @a h1 and @a h2.
+ * Runs the Fakebank in-process by guessing / extracting the portnumber
+ * from the base URL.
*
- * @param h1 a history entry
- * @param h2 a history entry
- * @return 0 if @a h1 and @a h2 are equal
+ * @param label command label
+ * @param cfg configuration to use
+ * @param exchange_account_section configuration section
+ * to use to determine bank account of the exchange
+ * @return the command.
*/
-int
-TALER_TESTING_history_entry_cmp (
- const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
- const struct TALER_EXCHANGE_ReserveHistoryEntry *h2);
-
-
-/* ************** Specific interpreter commands ************ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_run_fakebank (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *exchange_account_section);
/**
@@ -1086,24 +804,20 @@ TALER_TESTING_cmd_exec_auditor_dbinit (const char *label,
* Create a "deposit-confirmation" command.
*
* @param label command label.
- * @param auditor auditor connection.
* @param deposit_reference reference to any operation that can
* provide a coin.
- * @param coin_index if @a deposit_reference offers an array of
- * coins, this parameter selects which one in that array.
- * This value is currently ignored, as only one-coin
- * deposits are implemented.
+ * @param num_coins number of coins expected in the batch deposit
* @param amount_without_fee deposited amount without the fee
* @param expected_response_code expected HTTP response code.
* @return the command.
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_deposit_confirmation (const char *label,
- struct TALER_AUDITOR_Handle *auditor,
- const char *deposit_reference,
- unsigned int coin_index,
- const char *amount_without_fee,
- unsigned int expected_response_code);
+TALER_TESTING_cmd_deposit_confirmation (
+ const char *label,
+ const char *deposit_reference,
+ unsigned int num_coins,
+ const char *amount_without_fee,
+ unsigned int expected_response_code);
/**
@@ -1119,46 +833,6 @@ TALER_TESTING_cmd_deposit_confirmation_with_retry (
/**
- * Create a "list exchanges" command.
- *
- * @param label command label.
- * @param auditor auditor connection.
- * @param expected_response_code expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges (const char *label,
- struct TALER_AUDITOR_Handle *auditor,
- unsigned int expected_response_code);
-
-
-/**
- * Create a "list exchanges" command and check whether
- * a particular exchange belongs to the returned bundle.
- *
- * @param label command label.
- * @param expected_response_code expected HTTP response code.
- * @param exchange_url URL of the exchange supposed to
- * be included in the response.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges_with_url (const char *label,
- unsigned int expected_response_code,
- const char *exchange_url);
-
-/**
- * Modify an exchanges command to enable retries when we get
- * transient errors from the auditor.
- *
- * @param cmd a deposit confirmation command
- * @return the command with retries enabled
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges_with_retry (struct TALER_TESTING_Command cmd);
-
-
-/**
* Create /admin/add-incoming command.
*
* @param label command label.
@@ -1225,6 +899,32 @@ TALER_TESTING_cmd_exec_wirewatch (const char *label,
/**
+ * Make a "wirewatch" CMD.
+ *
+ * @param label command label.
+ * @param config_filename configuration filename.
+ * @param account_section section to run wirewatch against
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_wirewatch2 (const char *label,
+ const char *config_filename,
+ const char *account_section);
+
+
+/**
+ * Request URL via "wget".
+ *
+ * @param label command label.
+ * @param url URL to fetch
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_wget (const char *label,
+ const char *url);
+
+
+/**
* Make a "expire" CMD.
*
* @param label command label.
@@ -1345,10 +1045,39 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
/**
+ * Create a batch withdraw command, letting the caller specify the type of
+ * conflict between the coins and the desired amounts as string.
+ *
+ * Takes a variable, non-empty list of the denomination amounts via VARARGS,
+ * similar to #TALER_TESTING_cmd_withdraw_amount(), just using a batch
+ * withdraw.
+ *
+ * @param label command label.
+ * @param reserve_reference command providing us with a reserve to withdraw from
+ * @param conflict if true, enforce a conflict (same priv key, different denom and age commiment)
+ * @param age if > 0, age restriction applies (same for all coins)
+ * @param expected_response_code which HTTP response code
+ * we expect from the exchange.
+ * @param amount how much we withdraw for the first coin
+ * @param ... NULL-terminated list of additional amounts to withdraw (one per coin)
+ * @return the withdraw command to be executed by the interpreter.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_batch_withdraw_with_conflict (
+ const char *label,
+ const char *reserve_reference,
+ bool conflict,
+ uint8_t age,
+ unsigned int expected_response_code,
+ const char *amount,
+ ...);
+
+/**
* Create a batch withdraw command, letting the caller specify
* the desired amounts as string. Takes a variable, non-empty
* list of the denomination amounts via VARARGS, similar to
* #TALER_TESTING_cmd_withdraw_amount(), just using a batch withdraw.
+ * The coins are generated without a conflict (different private keys).
*
* @param label command label.
* @param reserve_reference command providing us with a reserve to withdraw from
@@ -1359,14 +1088,57 @@ TALER_TESTING_cmd_withdraw_amount (const char *label,
* @param ... NULL-terminated list of additional amounts to withdraw (one per coin)
* @return the withdraw command to be executed by the interpreter.
*/
+#define TALER_TESTING_cmd_batch_withdraw(label, \
+ reserve_reference, \
+ age, \
+ expected_response_code, \
+ amount, \
+ ...) \
+ TALER_TESTING_cmd_batch_withdraw_with_conflict ( \
+ (label), \
+ (reserve_reference), \
+ false, \
+ (age), \
+ (expected_response_code), \
+ (amount), \
+ __VA_ARGS__)
+
+/**
+ * Create an age-withdraw command, letting the caller specify
+ * the maximum agend and desired amounts as string. Takes a variable,
+ * non-empty list of the denomination amounts via VARARGS, similar to
+ * #TALER_TESTING_cmd_withdraw_amount(), just using a batch withdraw.
+ *
+ * @param label command label.
+ * @param reserve_reference command providing us with a reserve to withdraw from
+ * @param max_age maximum allowed age, same for each coin
+ * @param expected_response_code which HTTP response code
+ * we expect from the exchange.
+ * @param amount how much we withdraw for the first coin
+ * @param ... NULL-terminated list of additional amounts to withdraw (one per coin)
+ * @return the withdraw command to be executed by the interpreter.
+ */
struct TALER_TESTING_Command
-TALER_TESTING_cmd_batch_withdraw (const char *label,
- const char *reserve_reference,
- uint8_t age,
- unsigned int expected_response_code,
- const char *amount,
- ...);
+TALER_TESTING_cmd_age_withdraw (const char *label,
+ const char *reserve_reference,
+ uint8_t max_age,
+ unsigned int expected_response_code,
+ const char *amount,
+ ...);
+/**
+ * Create a "age-withdraw reveal" command.
+ *
+ * @param label command label.
+ * @param age_withdraw_reference reference to a "age-withdraw" command.
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_age_withdraw_reveal (
+ const char *label,
+ const char *age_withdraw_reference,
+ unsigned int expected_response_code);
/**
* Create a withdraw command, letting the caller specify
@@ -1379,7 +1151,7 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
* @param amount how much we withdraw.
* @param age if > 0, age restriction applies.
* @param coin_ref reference to (withdraw/reveal) command of a coin
- * from which we should re-use the private key
+ * from which we should reuse the private key
* @param expected_response_code which HTTP response code
* we expect from the exchange.
* @return the withdraw command to be executed by the interpreter.
@@ -1426,24 +1198,6 @@ TALER_TESTING_cmd_withdraw_with_retry (struct TALER_TESTING_Command cmd);
/**
- * Create a "wire" command.
- *
- * @param label the command label.
- * @param expected_method which wire-transfer method is expected
- * to be offered by the exchange.
- * @param expected_fee the fee the exchange should charge.
- * @param expected_response_code the HTTP response the exchange
- * should return.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_wire (const char *label,
- const char *expected_method,
- const char *expected_fee,
- unsigned int expected_response_code);
-
-
-/**
* Create a GET "reserves" command.
*
* @param label the command label.
@@ -1493,7 +1247,7 @@ TALER_TESTING_cmd_reserve_poll_finish (const char *label,
/**
- * Create a POST "/reserves/$RID/history" command.
+ * Create a GET "/reserves/$RID/history" command.
*
* @param label the command label.
* @param reserve_reference reference to the reserve to check.
@@ -1509,19 +1263,89 @@ TALER_TESTING_cmd_reserve_history (const char *label,
/**
- * Create a POST "/reserves/$RID/status" command.
+ * Create a GET "/coins/$COIN_PUB/history" command.
*
* @param label the command label.
- * @param reserve_reference reference to the reserve to check.
- * @param expected_balance expected balance for the reserve.
+ * @param coin_reference reference to the coin to check.
+ * @param expected_balance expected balance for the coin.
* @param expected_response_code expected HTTP response code.
* @return the command.
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_reserve_status (const char *label,
+TALER_TESTING_cmd_coin_history (const char *label,
+ const char *coin_reference,
+ const char *expected_balance,
+ unsigned int expected_response_code);
+
+
+/**
+ * Create a POST "/reserves/$RID/open" command.
+ *
+ * @param label the command label.
+ * @param reserve_reference reference to the reserve to open.
+ * @param reserve_pay amount to pay from the reserve balance
+ * @param expiration_time how long into the future should the reserve remain open
+ * @param min_purses minimum number of purses to allow
+ * @param expected_response_code expected HTTP response code.
+ * @param ... NULL terminated list of pairs of coin references and amounts
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_open (const char *label,
+ const char *reserve_reference,
+ const char *reserve_pay,
+ struct GNUNET_TIME_Relative expiration_time,
+ uint32_t min_purses,
+ unsigned int expected_response_code,
+ ...);
+
+
+/**
+ * Create a GET "/reserves/$RID/attest" command.
+ *
+ * @param label the command label.
+ * @param reserve_reference reference to the reserve to get attestable attributes of.
+ * @param expected_response_code expected HTTP response code.
+ * @param ... NULL-terminated list of attributes expected
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_get_attestable (const char *label,
+ const char *reserve_reference,
+ unsigned int expected_response_code,
+ ...);
+
+
+/**
+ * Create a POST "/reserves/$RID/attest" command.
+ *
+ * @param label the command label.
+ * @param reserve_reference reference to the reserve to get attests for
+ * @param expected_response_code expected HTTP response code.
+ * @param ... NULL-terminated list of attributes that should be attested
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_attest (const char *label,
const char *reserve_reference,
- const char *expected_balance,
- unsigned int expected_response_code);
+ unsigned int expected_response_code,
+ ...);
+
+
+/**
+ * Create a POST "/reserves/$RID/close" command.
+ *
+ * @param label the command label.
+ * @param reserve_reference reference to the reserve to close.
+ * @param target_account where to wire funds remaining, can be NULL
+ * @param expected_response_code expected HTTP response code.
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_close (const char *label,
+ const char *reserve_reference,
+ const char *target_account,
+ unsigned int expected_response_code);
/**
@@ -1623,7 +1447,6 @@ TALER_TESTING_cmd_deposit_replay (const char *label,
* @param contract_terms contract terms to be signed over by the
* coin.
* @param refund_deadline refund deadline, zero means 'no refunds'.
- * @param amount how much is going to be deposited.
* @param expected_response_code expected HTTP response code.
* @param ... NULL-terminated list with an even number of
* strings that alternate referring to coins
@@ -1996,60 +1819,6 @@ struct TALER_TESTING_Command
TALER_TESTING_cmd_wait_service (const char *label,
const char *url);
-
-/**
- * Make a "check keys" command.
- *
- * @param label command label
- * @param generation how many /keys responses are expected to
- * have been returned when this CMD will be run.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys (const char *label,
- unsigned int generation);
-
-
-/**
- * Make a "check keys" command that forcedly does NOT cherry pick;
- * just redownload the whole /keys.
- *
- * @param label command label
- * @param generation when this command is run, exactly @a
- * generation /keys downloads took place. If the number
- * of downloads is less than @a generation, the logic will
- * first make sure that @a generation downloads are done,
- * and _then_ execute the rest of the command.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys_pull_all_keys (const char *label,
- unsigned int generation);
-
-
-/**
- * Make a "check keys" command. It lets the user set a last denom issue date to be
- * used in the request for /keys.
- *
- * @param label command label
- * @param generation when this command is run, exactly @a
- * generation /keys downloads took place. If the number
- * of downloads is less than @a generation, the logic will
- * first make sure that @a generation downloads are done,
- * and _then_ execute the rest of the command.
- * @param last_denom_date_ref previous /keys command to use to
- * obtain the "last_denom_date" value from; "zero" can be used
- * as a special value to force an absolute time of zero to be
- * given to as an argument
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys_with_last_denom (
- const char *label,
- unsigned int generation,
- const char *last_denom_date_ref);
-
-
/**
* Create a "batch" command. Such command takes a
* end_CMD-terminated array of CMDs and executed them.
@@ -2075,13 +1844,18 @@ TALER_TESTING_cmd_batch (const char *label,
bool
TALER_TESTING_cmd_is_batch (const struct TALER_TESTING_Command *cmd);
+
/**
* Advance internal pointer to next command.
*
* @param is interpreter state.
+ * @param[in,out] cls closure of the batch
+ * @return true to advance IP in parent
*/
-void
-TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is);
+bool
+TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is,
+ void *cls);
+
/**
* Obtain what command the batch is at.
@@ -2104,34 +1878,10 @@ TALER_TESTING_cmd_batch_set_current (const struct TALER_TESTING_Command *cmd,
/**
- * Make a serialize-keys CMD.
- *
- * @param label CMD label
- * @return the CMD.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_serialize_keys (const char *label);
-
-
-/**
- * Make a connect-with-state CMD. This command
- * will use a serialized key state to reconnect
- * to the exchange.
- *
- * @param label command label
- * @param state_reference label of a CMD offering
- * a serialized key state.
- * @return the CMD.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_connect_with_state (const char *label,
- const char *state_reference);
-
-/**
* Make the "insert-deposit" CMD.
*
* @param label command label.
- * @param dbc collects plugin and session handles
+ * @param db_cfg configuration to talk to the DB
* @param merchant_name Human-readable name of the merchant.
* @param merchant_account merchant's account name (NOT a payto:// URI)
* @param exchange_timestamp when did the exchange receive the deposit
@@ -2144,7 +1894,7 @@ TALER_TESTING_cmd_connect_with_state (const char *label,
struct TALER_TESTING_Command
TALER_TESTING_cmd_insert_deposit (
const char *label,
- const struct TALER_TESTING_DatabaseConnection *dbc,
+ const struct GNUNET_CONFIGURATION_Handle *db_cfg,
const char *merchant_name,
const char *merchant_account,
struct GNUNET_TIME_Timestamp exchange_timestamp,
@@ -2169,7 +1919,7 @@ struct TALER_TESTING_Timer
struct GNUNET_TIME_Relative total_duration;
/**
- * Total time spend waiting for the *successful* exeuction
+ * Total time spend waiting for the *successful* execution
* in all commands of this type.
*/
struct GNUNET_TIME_Relative success_latency;
@@ -2255,7 +2005,6 @@ TALER_TESTING_cmd_auditor_add_denom_sig (const char *label,
* @param wire_method wire method to set wire fees for
* @param wire_fee the wire fee to affirm
* @param closing_fee the closing fee to affirm
- * @param wad_fee wad fee to charge
* @param expected_http_status expected HTTP status from exchange
* @param bad_sig should we use a bogus signature?
* @return the command
@@ -2265,7 +2014,6 @@ TALER_TESTING_cmd_set_wire_fee (const char *label,
const char *wire_method,
const char *wire_fee,
const char *closing_fee,
- const char *wad_fee,
unsigned int expected_http_status,
bool bad_sig);
@@ -2339,15 +2087,13 @@ TALER_TESTING_cmd_exec_offline_sign_keys (const char *label,
* @param config_filename configuration filename.
* @param wire_fee the wire fee to affirm (for the current year)
* @param closing_fee the closing fee to affirm (for the current year)
- * @param wad_fee the wad fee to affirm
* @return the command
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
const char *config_filename,
const char *wire_fee,
- const char *closing_fee,
- const char *wad_fee);
+ const char *closing_fee);
/**
@@ -2356,11 +2102,9 @@ TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
* @param label command label.
* @param config_filename configuration filename.
* @param history_fee the history fee to charge (for the current year)
- * @param kyc_fee the KYC fee to charge (for the current year)
* @param account_fee the account fee to charge (for the current year)
* @param purse_fee the purse fee to charge (for the current year)
* @param purse_timeout when do purses time out
- * @param kyc_timeout when does the KYC time out
* @param history_expiration when does an account history expire
* @param num_purses number of (free) active purses per account
* @return the command
@@ -2370,11 +2114,9 @@ TALER_TESTING_cmd_exec_offline_sign_global_fees (
const char *label,
const char *config_filename,
const char *history_fee,
- const char *kyc_fee,
const char *account_fee,
const char *purse_fee,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
unsigned int num_purses);
@@ -2422,12 +2164,14 @@ TALER_TESTING_cmd_revoke_sign_key (
*
* @param label command label.
* @param reserve_reference command with reserve private key to use (or NULL to create a fresh reserve key).
+ * @param threshold_balance balance amount to pass to the exchange
* @param expected_response_code expected HTTP status
* @return the command
*/
struct TALER_TESTING_Command
TALER_TESTING_cmd_wallet_kyc_get (const char *label,
const char *reserve_reference,
+ const char *threshold_balance,
unsigned int expected_response_code);
@@ -2446,33 +2190,48 @@ TALER_TESTING_cmd_check_kyc_get (const char *label,
/**
- * Create a KYC proof request.
+ * Create a KYC proof request. Only useful in conjunction with the OAuth2.0
+ * logic, as it generates an OAuth2.0-specific request.
*
* @param label command label.
* @param payment_target_reference command with a payment target to query
+ * @param logic_section name of the KYC provider section
+ * in the exchange configuration for this proof
* @param code OAuth 2.0 code to use
- * @param state OAuth 2.0 state to use
* @param expected_response_code expected HTTP status
* @return the command
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_proof_kyc (const char *label,
- const char *payment_target_reference,
- const char *code,
- const char *state,
- unsigned int expected_response_code);
+TALER_TESTING_cmd_proof_kyc_oauth2 (
+ const char *label,
+ const char *payment_target_reference,
+ const char *logic_section,
+ const char *code,
+ unsigned int expected_response_code);
/**
* Starts a fake OAuth 2.0 service on @a port for testing
- * KYC processes.
+ * KYC processes which also provides a @a birthdate in a response
*
* @param label command label
+ * @param birthdate fixed birthdate, such as "2022-03-04", "2022-03-00", "2022-00-00"
* @param port the TCP port to listen on
*/
struct TALER_TESTING_Command
-TALER_TESTING_cmd_oauth (const char *label,
- uint16_t port);
+TALER_TESTING_cmd_oauth_with_birthdate (const char *label,
+ const char *birthdate,
+ uint16_t port);
+
+/**
+ * Starts a fake OAuth 2.0 service on @a port for testing
+ * KYC processes.
+ *
+ * @param label command label
+ * @param port the TCP port to listen on
+ */
+#define TALER_TESTING_cmd_oauth(label, port) \
+ TALER_TESTING_cmd_oauth_with_birthdate ((label), NULL, (port))
/* ****************** P2P payment commands ****************** */
@@ -2500,6 +2259,21 @@ TALER_TESTING_cmd_purse_create_with_deposit (
/**
+ * Deletes a purse.
+ *
+ * @param label command label
+ * @param expected_http_status what HTTP status do we expect to get returned from the exchange
+ * @param purse_cmd command that created the purse
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_purse_delete (
+ const char *label,
+ unsigned int expected_http_status,
+ const char *purse_cmd);
+
+
+/**
* Retrieve contract (also checks that the contract matches
* the upload command).
*
@@ -2576,6 +2350,7 @@ TALER_TESTING_cmd_purse_poll_finish (const char *label,
* @param expected_http_status what HTTP status do we expect to get returned from the exchange
* @param contract_terms contract, JSON string
* @param upload_contract should we upload the contract
+ * @param pay_purse_fee should we pay a fee to create the purse
* @param expiration when should the purse expire
* @param reserve_ref reference to reserve key, or NULL to create a new reserve
* @return the command
@@ -2586,6 +2361,7 @@ TALER_TESTING_cmd_purse_create_with_reserve (
unsigned int expected_http_status,
const char *contract_terms,
bool upload_contract,
+ bool pay_purse_fee,
struct GNUNET_TIME_Relative expiration,
const char *reserve_ref);
@@ -2609,6 +2385,114 @@ TALER_TESTING_cmd_purse_deposit_coins (
...);
+/**
+ * Setup AML officer.
+ *
+ * @param label command label
+ * @param ref_cmd command that previously created the
+ * officer, NULL to create one this time
+ * @param name full legal name of the officer to use
+ * @param is_active true to set the officer to active
+ * @param read_only true to restrict the officer to read-only
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_set_officer (
+ const char *label,
+ const char *ref_cmd,
+ const char *name,
+ bool is_active,
+ bool read_only);
+
+
+/**
+ * Make AML decision.
+ *
+ * @param label command label
+ * @param ref_officer command that previously created an
+ * officer
+ * @param ref_operation command that previously created an
+ * h_payto which to make an AML decision about
+ * @param new_threshold new threshold to set
+ * @param justification justification given for the decision
+ * @param new_state new AML state for the account
+ * @param kyc_requirement KYC requirement to impose
+ * @param expected_response expected HTTP return status
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_take_aml_decision (
+ const char *label,
+ const char *ref_officer,
+ const char *ref_operation,
+ const char *new_threshold,
+ const char *justification,
+ enum TALER_AmlDecisionState new_state,
+ const char *kyc_requirement,
+ unsigned int expected_response);
+
+
+/**
+ * Fetch AML decision.
+ *
+ * @param label command label
+ * @param ref_officer command that previously created an
+ * officer
+ * @param ref_operation command that previously created an
+ * h_payto which to make an AML decision about
+ * @param expected_http_status expected HTTP response status
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_check_aml_decision (
+ const char *label,
+ const char *ref_officer,
+ const char *ref_operation,
+ unsigned int expected_http_status);
+
+
+/**
+ * Fetch AML decisions.
+ *
+ * @param label command label
+ * @param ref_officer command that previously created an
+ * officer
+ * @param filter AML state to filter by
+ * @param expected_http_status expected HTTP response status
+ * @return the command
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_check_aml_decisions (
+ const char *label,
+ const char *ref_officer,
+ enum TALER_AmlDecisionState filter,
+ unsigned int expected_http_status);
+
+
+/* ****************** convenience functions ************** */
+
+/**
+ * Get exchange URL from interpreter. Convenience function.
+ *
+ * @param is interpreter state.
+ * @return the exchange URL, or NULL on error
+ */
+const char *
+TALER_TESTING_get_exchange_url (
+ struct TALER_TESTING_Interpreter *is);
+
+
+/**
+ * Get exchange keys from interpreter. Convenience function.
+ *
+ * @param is interpreter state.
+ * @return the exchange keys, or NULL on error
+ */
+struct TALER_EXCHANGE_Keys *
+TALER_TESTING_get_keys (
+ struct TALER_TESTING_Interpreter *is);
+
+
/* *** Generic trait logic for implementing traits ********* */
@@ -2765,6 +2649,15 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
*/
#define TALER_TESTING_SIMPLE_TRAITS(op) \
op (bank_row, const uint64_t) \
+ op (officer_pub, const struct TALER_AmlOfficerPublicKeyP) \
+ op (officer_priv, const struct TALER_AmlOfficerPrivateKeyP) \
+ op (officer_name, const char) \
+ op (aml_decision, enum TALER_AmlDecisionState) \
+ op (aml_justification, const char) \
+ op (auditor_priv, const struct TALER_AuditorPrivateKeyP) \
+ op (auditor_pub, const struct TALER_AuditorPublicKeyP) \
+ op (master_priv, const struct TALER_MasterPrivateKeyP) \
+ op (master_pub, const struct TALER_MasterPublicKeyP) \
op (purse_priv, const struct TALER_PurseContractPrivateKeyP) \
op (purse_pub, const struct TALER_PurseContractPublicKeyP) \
op (merge_priv, const struct TALER_PurseMergePrivateKeyP) \
@@ -2780,56 +2673,61 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
op (merchant_pub, const struct TALER_MerchantPublicKeyP) \
op (merchant_sig, const struct TALER_MerchantSignatureP) \
op (wtid, const struct TALER_WireTransferIdentifierRawP) \
+ op (bank_auth_data, const struct TALER_BANK_AuthenticationData) \
op (contract_terms, const json_t) \
op (wire_details, const json_t) \
- op (exchange_keys, const json_t) \
- op (exchange_url, const char *) \
- op (exchange_bank_account_url, const char *) \
- op (taler_uri, const char *) \
- op (payto_uri, const char *) \
- op (kyc_url, const char *) \
- op (web_url, const char *) \
+ op (exchange_url, const char) \
+ op (auditor_url, const char) \
+ op (exchange_bank_account_url, const char) \
+ op (taler_uri, const char) \
+ op (payto_uri, const char) \
+ op (kyc_url, const char) \
+ op (web_url, const char) \
op (row, const uint64_t) \
- op (payment_target_uuid, const uint64_t) \
+ op (legi_requirement_row, const uint64_t) \
op (array_length, const unsigned int) \
- op (credit_payto_uri, const char *) \
- op (debit_payto_uri, const char *) \
- op (order_id, const char *) \
+ op (credit_payto_uri, const char) \
+ op (debit_payto_uri, const char) \
+ op (order_id, const char) \
op (amount, const struct TALER_Amount) \
op (amount_with_fee, const struct TALER_Amount) \
- op (batch_cmds, struct TALER_TESTING_Command *) \
+ op (batch_cmds, struct TALER_TESTING_Command) \
op (uuid, const struct GNUNET_Uuid) \
op (fresh_coins, const struct TALER_TESTING_FreshCoinData *) \
op (claim_token, const struct TALER_ClaimTokenP) \
op (relative_time, const struct GNUNET_TIME_Relative) \
+ op (fakebank, struct TALER_FAKEBANK_Handle) \
+ op (keys, struct TALER_EXCHANGE_Keys) \
op (process, struct GNUNET_OS_Process *)
/**
* Call #op on all indexed traits.
*/
-#define TALER_TESTING_INDEXED_TRAITS(op) \
- op (denom_pub, const struct TALER_EXCHANGE_DenomPublicKey) \
- op (denom_sig, const struct TALER_DenominationSignature) \
- op (amounts, const struct TALER_Amount) \
- op (deposit_amount, const struct TALER_Amount) \
- op (deposit_fee_amount, const struct TALER_Amount) \
- op (age_commitment, const struct TALER_AgeCommitment) \
- op (age_commitment_proof, const struct TALER_AgeCommitmentProof) \
- op (h_age_commitment, const struct TALER_AgeCommitmentHash) \
+#define TALER_TESTING_INDEXED_TRAITS(op) \
+ op (denom_pub, const struct TALER_EXCHANGE_DenomPublicKey) \
+ op (denom_sig, const struct TALER_DenominationSignature) \
+ op (amounts, const struct TALER_Amount) \
+ op (deposit_amount, const struct TALER_Amount) \
+ op (deposit_fee_amount, const struct TALER_Amount) \
+ op (age_commitment, const struct TALER_AgeCommitment) \
+ op (age_commitment_proof, const struct TALER_AgeCommitmentProof) \
+ op (h_age_commitment, const struct TALER_AgeCommitmentHash) \
op (reserve_history, const struct TALER_EXCHANGE_ReserveHistoryEntry) \
- op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \
- op (exchange_wd_value, const struct TALER_ExchangeWithdrawValues) \
- op (coin_priv, const struct TALER_CoinSpendPrivateKeyP) \
- op (coin_pub, const struct TALER_CoinSpendPublicKeyP) \
- op (absolute_time, const struct GNUNET_TIME_Absolute) \
- op (timestamp, const struct GNUNET_TIME_Timestamp) \
- op (wire_deadline, const struct GNUNET_TIME_Timestamp) \
- op (refund_deadline, const struct GNUNET_TIME_Timestamp) \
- op (exchange_pub, const struct TALER_ExchangePublicKeyP) \
- op (exchange_sig, const struct TALER_ExchangeSignatureP) \
- op (blinding_key, const union TALER_DenominationBlindingKeyP)
-
+ op (coin_history, const struct TALER_EXCHANGE_CoinHistoryEntry) \
+ op (planchet_secrets, const struct TALER_PlanchetMasterSecretP) \
+ op (exchange_wd_value, const struct TALER_ExchangeWithdrawValues) \
+ op (coin_priv, const struct TALER_CoinSpendPrivateKeyP) \
+ op (coin_pub, const struct TALER_CoinSpendPublicKeyP) \
+ op (coin_sig, const struct TALER_CoinSpendSignatureP) \
+ op (absolute_time, const struct GNUNET_TIME_Absolute) \
+ op (timestamp, const struct GNUNET_TIME_Timestamp) \
+ op (wire_deadline, const struct GNUNET_TIME_Timestamp) \
+ op (refund_deadline, const struct GNUNET_TIME_Timestamp) \
+ op (exchange_pub, const struct TALER_ExchangePublicKeyP) \
+ op (exchange_sig, const struct TALER_ExchangeSignatureP) \
+ op (blinding_key, const union GNUNET_CRYPTO_BlindingSecretP) \
+ op (h_blinded_coin, const struct TALER_BlindedCoinHashP)
TALER_TESTING_SIMPLE_TRAITS (TALER_TESTING_MAKE_DECL_SIMPLE_TRAIT)
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index afc8ebada..8feb8451c 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -16,11 +16,17 @@
/**
* @file include/taler_util.h
* @brief Interface for common utility functions
+ * This library is not thread-safe, all APIs must only be used from a single thread.
+ * This library calls abort() if it runs out of memory. Be aware of these limitations.
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Christian Grothoff
*/
#ifndef TALER_UTIL_H
#define TALER_UTIL_H
+#include <gnunet/gnunet_common.h>
+#define __TALER_UTIL_LIB_H_INSIDE__
+
#include <gnunet/gnunet_util_lib.h>
#include <microhttpd.h>
#include "taler_amount_lib.h"
@@ -30,7 +36,7 @@
* Version of the Taler API, in hex.
* Thus 0.8.4-1 = 0x00080401.
*/
-#define TALER_API_VERSION 0x00080401
+#define TALER_API_VERSION 0x00090401
/**
* Stringify operator.
@@ -79,6 +85,22 @@
/**
+ * HTTP header with an AML officer signature to approve the inquiry.
+ * Used only in GET Requests.
+ */
+#define TALER_AML_OFFICER_SIGNATURE_HEADER "Taler-AML-Officer-Signature"
+
+/**
+ * Header with signature for reserve history requests.
+ */
+#define TALER_RESERVE_HISTORY_SIGNATURE_HEADER "Taler-Reserve-History-Signature"
+
+/**
+ * Header with signature for coin history requests.
+ */
+#define TALER_COIN_HISTORY_SIGNATURE_HEADER "Taler-Coin-History-Signature"
+
+/**
* Log an error message at log-level 'level' that indicates
* a failure of the command 'cmd' with the message given
* by gcry_strerror(rc).
@@ -191,6 +213,101 @@ TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
/**
+ * Details about how to render a currency.
+ */
+struct TALER_CurrencySpecification
+{
+ /**
+ * Currency code of the currency.
+ */
+ char currency[TALER_CURRENCY_LEN];
+
+ /**
+ * Human-readable long name of the currency, e.g.
+ * "Japanese Yen".
+ */
+ char *name;
+
+ /**
+ * how many digits the user may enter at most after the @e decimal_separator
+ */
+ unsigned int num_fractional_input_digits;
+
+ /**
+ * how many digits we render in normal scale after the @e decimal_separator
+ */
+ unsigned int num_fractional_normal_digits;
+
+ /**
+ * how many digits we render in after the @e decimal_separator even if all
+ * remaining digits are zero.
+ */
+ unsigned int num_fractional_trailing_zero_digits;
+
+ /**
+ * Mapping of powers of 10 to alternative currency names or symbols.
+ * Keys are the decimal powers, values the currency symbol to use.
+ * Map MUST contain an entry for "0" to the default currency symbol.
+ */
+ json_t *map_alt_unit_names;
+
+};
+
+
+/**
+ * Parse information about supported currencies from
+ * our configuration.
+ *
+ * @param cfg configuration to parse
+ * @param[out] num_currencies set to number of enabled currencies, length of @e cspecs
+ * @param[out] cspecs set to currency specification array
+ * @return #GNUNET_OK on success, #GNUNET_NO if zero
+ * currency specifications were enabled,
+ * #GNUNET_SYSERR if the configuration was malformed
+ */
+enum GNUNET_GenericReturnValue
+TALER_CONFIG_parse_currencies (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int *num_currencies,
+ struct TALER_CurrencySpecification **cspecs);
+
+
+/**
+ * Free @a cspecs array.
+ *
+ * @param num_currencies length of @a cspecs array
+ * @param[in] cspecs array to free
+ */
+void
+TALER_CONFIG_free_currencies (
+ unsigned int num_currencies,
+ struct TALER_CurrencySpecification cspecs[static num_currencies]);
+
+
+/**
+ * Convert a currency specification to the
+ * respective JSON object.
+ *
+ * @param cspec currency specification
+ * @return JSON object encoding @a cspec for `/config`.
+ */
+json_t *
+TALER_CONFIG_currency_specs_to_json (
+ const struct TALER_CurrencySpecification *cspec);
+
+
+/**
+ * Check that @a map contains a valid currency scale
+ * map that maps integers from [-12,24] to currency
+ * symbols given as strings.
+ *
+ * @param map map to check
+ * @return #GNUNET_OK if @a map is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_check_currency_scale_map (const json_t *map);
+
+
+/**
* Allow user to specify an amount on the command line.
*
* @param shortName short name of the option
@@ -222,6 +339,16 @@ TALER_OS_init (void);
/**
+ * Re-encode string at @a inp to match RFC 8785 (section 3.2.2.2).
+ *
+ * @param[in,out] inp pointer to string to re-encode
+ * @return number of bytes in resulting @a inp
+ */
+size_t
+TALER_rfc8785encode (char **inp);
+
+
+/**
* URL-encode a string according to rfc3986.
*
* @param s string to encode
@@ -243,6 +370,17 @@ TALER_url_valid_charset (const char *url);
/**
+ * Test if the URL is a valid "http" (or "https")
+ * URL (includes test for #TALER_url_valid_charset()).
+ *
+ * @param url a string to test if it could be a valid URL
+ * @return true if @a url is well-formed
+ */
+bool
+TALER_is_web_url (const char *url);
+
+
+/**
* Check if @a lang matches the @a language_pattern, and if so with
* which preference.
* See also: https://tools.ietf.org/html/rfc7231#section-5.3.1
@@ -278,8 +416,9 @@ TALER_mhd_is_https (struct MHD_Connection *connection);
* that a NULL value does not terminate the list, only a NULL key signals the
* end of the list of arguments.
*
- * @param base_url absolute base URL to use
- * @param path path of the url
+ * @param base_url absolute base URL to use, must either
+ * end with '/' *or* @a path must be the empty string
+ * @param path path of the url to append to the @a base_url
* @param ... NULL-terminated key-value pairs (char *) for query parameters,
* only the value will be url-encoded
* @returns the URL, must be freed with #GNUNET_free
@@ -362,16 +501,17 @@ TALER_payto_get_method (const char *payto_uri);
/**
- * Construct a payto://-URI from a Taler @a reserve_pub at
- * @a exchange_base_url
+ * Normalize payto://-URI to make "strcmp()" sufficient
+ * to check if two payto-URIs refer to the same bank
+ * account. Removes optional arguments (everything after
+ * "?") and applies method-specific normalizations to
+ * the main part of the URI.
*
- * @param exchange_base_url the URL of the exchange
- * @param reserve_pub public key of the reserve
- * @return payto:// URI encoding the reserve's address
+ * @param input a payto://-URI
+ * @return normalized URI, or NULL if @a input was not well-formed
*/
char *
-TALER_payto_from_reserve (const char *exchange_base_url,
- const struct TALER_ReservePublicKeyP *reserve_pub);
+TALER_payto_normalize (const char *input);
/**
@@ -505,5 +645,185 @@ char *strchrnul (const char *s, int c);
#endif
+/**
+ * @brief Parses a date information into days after 1970-01-01 (or 0)
+ *
+ * The input MUST be of the form
+ *
+ * 1) YYYY-MM-DD, representing a valid date
+ * 2) YYYY-MM-00, representing a valid month in a particular year
+ * 3) YYYY-00-00, representing a valid year.
+ *
+ * In the cases 2) and 3) the out parameter is set to the beginning of the
+ * time, f.e. 1950-00-00 == 1950-01-01 and 1888-03-00 == 1888-03-01
+ *
+ * The output will set to the number of days after 1970-01-01 or 0, if the input
+ * represents a date belonging to the largest allowed age group.
+ *
+ * @param in Input string representation of the date
+ * @param mask Age mask
+ * @param[out] out Where to write the result
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
+ */
+enum GNUNET_GenericReturnValue
+TALER_parse_coarse_date (
+ const char *in,
+ const struct TALER_AgeMask *mask,
+ uint32_t *out);
+
+
+/**
+ * @brief Parses a string as a list of age groups.
+ *
+ * The string must consist of a colon-separated list of increasing integers
+ * between 0 and 31. Each entry represents the beginning of a new age group.
+ * F.e. the string
+ *
+ * "8:10:12:14:16:18:21"
+ *
+ * represents the following list of eight age groups:
+ *
+ * | Group | Ages |
+ * | -----:|:------------- |
+ * | 0 | 0, 1, ..., 7 |
+ * | 1 | 8, 9 |
+ * | 2 | 10, 11 |
+ * | 3 | 12, 13 |
+ * | 4 | 14, 15 |
+ * | 5 | 16, 17 |
+ * | 6 | 18, 19, 20 |
+ * | 7 | 21, ... |
+ *
+ * which is then encoded as a bit mask with the corresponding bits set:
+ *
+ * 31 24 16 8 0
+ * | | | | |
+ * oooooooo oo1oo1o1 o1o1o1o1 ooooooo1
+ *
+ * @param groups String representation of age groups
+ * @param[out] mask Mask representation for age restriction.
+ * @return Error, if age groups were invalid, OK otherwise.
+ */
+enum GNUNET_GenericReturnValue
+TALER_parse_age_group_string (
+ const char *groups,
+ struct TALER_AgeMask *mask);
+
+
+/**
+ * @brief Encodes the age mask into a string, like "8:10:12:14:16:18:21"
+ *
+ * NOTE: This function uses a static buffer. It is not safe to call this
+ * function concurrently.
+ *
+ * @param mask Age mask
+ * @return String representation of the age mask.
+ * Can be used as value in the TALER config.
+ */
+const char *
+TALER_age_mask_to_string (
+ const struct TALER_AgeMask *mask);
+
+
+/**
+ * @brief returns the age group of a given age for a given age mask
+ *
+ * @param mask Age mask
+ * @param age The given age
+ * @return age group
+ */
+uint8_t
+TALER_get_age_group (
+ const struct TALER_AgeMask *mask,
+ uint8_t age);
+
+
+/**
+ * @brief Parses a JSON object { "age_groups": "a:b:...y:z" }.
+ *
+ * @param root is the json object
+ * @param[out] mask on success, will contain the age mask
+ * @return #GNUNET_OK on success and #GNUNET_SYSERR on failure.
+ */
+enum GNUNET_GenericReturnValue
+TALER_JSON_parse_age_groups (const json_t *root,
+ struct TALER_AgeMask *mask);
+
+
+/**
+ * @brief Return the lowest age in the corresponding group for a given age
+ * according the given age mask.
+ *
+ * @param mask age mask
+ * @param age age to check
+ * @return lowest age in corresponding age group
+ */
+uint8_t
+TALER_get_lowest_age (
+ const struct TALER_AgeMask *mask,
+ uint8_t age);
+
+
+/**
+ * @brief Get the lowest age for the largest age group
+ *
+ * @param mask the age mask
+ * @return lowest age for the largest age group
+ */
+#define TALER_adult_age(mask) \
+ sizeof((mask)->bits) * 8 - __builtin_clz ((mask)->bits) - 1
+
+/**
+ * Handle to an external process that will assist
+ * with some JSON-to-JSON conversion.
+ */
+struct TALER_JSON_ExternalConversion;
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure
+ * @param status_type how did the process die
+ * @param code termination status code from the process
+ * @param result some JSON result, NULL if we failed to get an JSON output
+ */
+typedef void
+(*TALER_JSON_JsonCallback) (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *result);
+
+
+/**
+ * Launch some external helper @a binary to convert some @a input
+ * and eventually call @a cb with the result.
+ *
+ * @param input JSON to serialize and pass to the helper process
+ * @param cb function to call on the result
+ * @param cb_cls closure for @a cb
+ * @param binary name of the binary to execute
+ * @param ... NULL-terminated list of arguments for the @a binary,
+ * usually starting with again the name of the binary
+ * @return handle to cancel the operation (and kill the helper)
+ */
+struct TALER_JSON_ExternalConversion *
+TALER_JSON_external_conversion_start (const json_t *input,
+ TALER_JSON_JsonCallback cb,
+ void *cb_cls,
+ const char *binary,
+ ...);
+
+/**
+ * Abort external conversion, killing the process and preventing
+ * the callback from being called. Must not be called after the
+ * callback was invoked.
+ *
+ * @param[in] ec external conversion handle to cancel
+ */
+void
+TALER_JSON_external_conversion_stop (
+ struct TALER_JSON_ExternalConversion *ec);
+
+#undef __TALER_UTIL_LIB_H_INSIDE__
#endif
diff --git a/src/json/Makefile.am b/src/json/Makefile.am
index 2f5ec3f17..ce863cb7e 100644
--- a/src/json/Makefile.am
+++ b/src/json/Makefile.am
@@ -16,7 +16,7 @@ libtalerjson_la_SOURCES = \
json_pack.c \
json_wire.c
libtalerjson_la_LDFLAGS = \
- -version-info 1:0:1 \
+ -version-info 3:0:1 \
-no-undefined
libtalerjson_la_LIBADD = \
$(top_builddir)/src/util/libtalerutil.la \
@@ -28,12 +28,10 @@ libtalerjson_la_LIBADD = \
$(XLIB)
TESTS = \
- test_json \
- test_json_wire
+ test_json
check_PROGRAMS= \
- test_json \
- test_json_wire
+ test_json
test_json_SOURCES = \
test_json.c
@@ -43,13 +41,3 @@ test_json_LDADD = \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetutil \
-ljansson
-
-
-test_json_wire_SOURCES = \
- test_json_wire.c
-test_json_wire_LDADD = \
- $(top_builddir)/src/json/libtalerjson.la \
- -lgnunetjson \
- $(top_builddir)/src/util/libtalerutil.la \
- -lgnunetutil \
- -ljansson
diff --git a/src/json/json.c b/src/json/json.c
index d4ac37489..639bd530c 100644
--- a/src/json/json.c
+++ b/src/json/json.c
@@ -62,170 +62,6 @@ contains_real (const json_t *json)
/**
- * Dump character in the low range into @a buf
- * following RFC 8785.
- *
- * @param[in,out] buf buffer to modify
- * @param val value to dump
- */
-static void
-lowdump (struct GNUNET_Buffer *buf,
- unsigned char val)
-{
- char scratch[7];
-
- switch (val)
- {
- case 0x8:
- GNUNET_buffer_write (buf,
- "\\b",
- 2);
- break;
- case 0x9:
- GNUNET_buffer_write (buf,
- "\\t",
- 2);
- break;
- case 0xA:
- GNUNET_buffer_write (buf,
- "\\n",
- 2);
- break;
- case 0xC:
- GNUNET_buffer_write (buf,
- "\\f",
- 2);
- break;
- case 0xD:
- GNUNET_buffer_write (buf,
- "\\r",
- 2);
- break;
- default:
- GNUNET_snprintf (scratch,
- sizeof (scratch),
- "\\u%04x",
- (unsigned int) val);
- GNUNET_buffer_write (buf,
- scratch,
- 6);
- break;
- }
-}
-
-
-/**
- * Re-encode string at @a inp to match RFC 8785 (section 3.2.2.2).
- *
- * @param[in,out] inp pointer to string to re-encode
- * @return number of bytes in resulting @a inp
- */
-static size_t
-rfc8785encode (char **inp)
-{
- struct GNUNET_Buffer buf = { 0 };
- size_t left = strlen (*inp) + 1;
- size_t olen;
- char *in = *inp;
- const char *pos = in;
-
- GNUNET_buffer_prealloc (&buf,
- left + 40);
- buf.warn_grow = 0; /* disable, + 40 is just a wild guess */
- while (1)
- {
- int mbl = u8_mblen ((unsigned char *) pos,
- left);
- unsigned char val;
-
- if (0 == mbl)
- break;
- val = (unsigned char) *pos;
- if ( (1 == mbl) &&
- (val <= 0x1F) )
- {
- /* Should not happen, as input is produced by
- * JSON stringification */
- GNUNET_break (0);
- lowdump (&buf,
- val);
- }
- else if ( (1 == mbl) && ('\\' == *pos) )
- {
- switch (*(pos + 1))
- {
- case '\\':
- mbl = 2;
- GNUNET_buffer_write (&buf,
- pos,
- mbl);
- break;
- case 'u':
- {
- unsigned int num;
- uint32_t n32;
- unsigned char res[8];
- size_t rlen;
-
- GNUNET_assert ( (1 ==
- sscanf (pos + 2,
- "%4x",
- &num)) ||
- (1 ==
- sscanf (pos + 2,
- "%4X",
- &num)) );
- mbl = 6;
- n32 = (uint32_t) num;
- rlen = sizeof (res);
- u32_to_u8 (&n32,
- 1,
- res,
- &rlen);
- if ( (1 == rlen) &&
- (res[0] <= 0x1F) )
- {
- lowdump (&buf,
- res[0]);
- }
- else
- {
- GNUNET_buffer_write (&buf,
- (const char *) res,
- rlen);
- }
- }
- break;
- default:
- mbl = 2;
- GNUNET_buffer_write (&buf,
- pos,
- mbl);
- break;
- }
- }
- else
- {
- GNUNET_buffer_write (&buf,
- pos,
- mbl);
- }
- left -= mbl;
- pos += mbl;
- }
-
- /* 0-terminate buffer */
- GNUNET_buffer_write (&buf,
- "",
- 1);
- GNUNET_free (in);
- *inp = GNUNET_buffer_reap (&buf,
- &olen);
- return olen;
-}
-
-
-/**
* Dump the @a json to a string and hash it.
*
* @param json value to hash
@@ -262,7 +98,7 @@ dump_and_hash (const json_t *json,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- len = rfc8785encode (&wire_enc);
+ len = TALER_rfc8785encode (&wire_enc);
if (NULL == salt)
{
GNUNET_CRYPTO_hash (wire_enc,
@@ -697,7 +533,7 @@ TALER_JSON_contract_part_forget (json_t *json,
/**
- * Look over all of the values of a '$forgettable' object. Replace 'True'
+ * Loop over all of the values of a '$forgettable' object. Replace 'True'
* values with proper random salts. Fails if any forgettable values are
* neither 'True' nor valid salts (strings).
*
@@ -742,51 +578,64 @@ seed_forgettable (json_t *f)
}
-/**
- * Take a given contract with "forgettable" fields marked
- * but with 'True' instead of a real salt. Replaces all
- * 'True' values with proper random salts. Fails if any
- * forgettable markers are neither 'True' nor valid salts.
- *
- * @param[in,out] json JSON to transform
- * @return #GNUNET_OK on success
- */
enum GNUNET_GenericReturnValue
-TALER_JSON_contract_seed_forgettable (json_t *json)
+TALER_JSON_contract_seed_forgettable (const json_t *spec,
+ json_t *contract)
{
- if (json_is_object (json))
+ if (json_is_object (spec))
{
const char *key;
json_t *val;
- json_object_foreach (json,
+ json_object_foreach ((json_t *) spec,
key,
val)
{
+ json_t *cval = json_object_get (contract,
+ key);
+
if (0 == strcmp ("$forgettable",
key))
{
+ json_t *xval = json_deep_copy (val);
+
if (GNUNET_OK !=
- seed_forgettable (val))
+ seed_forgettable (xval))
+ {
+ json_decref (xval);
return GNUNET_SYSERR;
+ }
+ GNUNET_assert (0 ==
+ json_object_set_new (contract,
+ "$forgettable",
+ xval));
continue;
}
+ if (NULL == cval)
+ continue;
if (GNUNET_OK !=
- TALER_JSON_contract_seed_forgettable (val))
+ TALER_JSON_contract_seed_forgettable (val,
+ cval))
return GNUNET_SYSERR;
}
}
- if (json_is_array (json))
+ if (json_is_array (spec))
{
size_t index;
json_t *val;
- json_array_foreach (json,
+ json_array_foreach ((json_t *) spec,
index,
val)
{
+ json_t *ival = json_array_get (contract,
+ index);
+
+ if (NULL == ival)
+ continue;
if (GNUNET_OK !=
- TALER_JSON_contract_seed_forgettable (val))
+ TALER_JSON_contract_seed_forgettable (val,
+ ival))
return GNUNET_SYSERR;
}
}
@@ -819,6 +668,7 @@ parse_path (json_t *obj,
json_t *next_obj = NULL;
char *next_dot;
+ GNUNET_assert (NULL != id); /* make stupid compiler happy */
if (NULL == next_id)
{
cb (cb_cls,
@@ -1008,12 +858,12 @@ TALER_JSON_get_error_code2 (const void *data,
void
-TALER_deposit_extension_hash (const json_t *extensions,
- struct TALER_ExtensionContractHashP *ech)
+TALER_deposit_policy_hash (const json_t *policy,
+ struct TALER_ExtensionPolicyHashP *ech)
{
GNUNET_assert (GNUNET_OK ==
- dump_and_hash (extensions,
- "taler-contract-extensions",
+ dump_and_hash (policy,
+ "taler-extensions-policy",
&ech->hash));
}
@@ -1031,17 +881,17 @@ TALER_JSON_canonicalize (const json_t *input)
GNUNET_break (0);
return NULL;
}
- rfc8785encode (&wire_enc);
+ TALER_rfc8785encode (&wire_enc);
return wire_enc;
}
enum GNUNET_GenericReturnValue
-TALER_JSON_extensions_config_hash (const json_t *config,
- struct TALER_ExtensionConfigHashP *ech)
+TALER_JSON_extensions_manifests_hash (const json_t *manifests,
+ struct TALER_ExtensionManifestsHashP *ech)
{
- return dump_and_hash (config,
- "taler-extension-configuration",
+ return dump_and_hash (manifests,
+ "taler-extensions-manifests",
&ech->hash);
}
diff --git a/src/json/json_helper.c b/src/json/json_helper.c
index cf169384e..0a533610b 100644
--- a/src/json/json_helper.c
+++ b/src/json/json_helper.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -32,20 +32,20 @@
* @param cipher_s input string
* @return numeric cipher value
*/
-static enum TALER_DenominationCipher
+static enum GNUNET_CRYPTO_BlindSignatureAlgorithm
string_to_cipher (const char *cipher_s)
{
if ((0 == strcasecmp (cipher_s,
"RSA")) ||
(0 == strcasecmp (cipher_s,
"RSA+age_restricted")))
- return TALER_DENOMINATION_RSA;
+ return GNUNET_CRYPTO_BSA_RSA;
if ((0 == strcasecmp (cipher_s,
"CS")) ||
(0 == strcasecmp (cipher_s,
"CS+age_restricted")))
- return TALER_DENOMINATION_CS;
- return TALER_DENOMINATION_INVALID;
+ return GNUNET_CRYPTO_BSA_CS;
+ return GNUNET_CRYPTO_BSA_INVALID;
}
@@ -64,17 +64,6 @@ TALER_JSON_from_amount (const struct TALER_Amount *amount)
}
-json_t *
-TALER_JSON_from_amount_nbo (const struct TALER_AmountNBO *amount)
-{
- struct TALER_Amount a;
-
- TALER_amount_ntoh (&a,
- amount);
- return TALER_JSON_from_amount (&a);
-}
-
-
/**
* Parse given JSON object to Amount
*
@@ -160,7 +149,7 @@ TALER_JSON_spec_amount_any (const char *name,
/**
- * Parse given JSON object to Amount in NBO.
+ * Parse given JSON object to currency spec.
*
* @param cls closure, NULL
* @param root the json object representing data
@@ -168,77 +157,119 @@ TALER_JSON_spec_amount_any (const char *name,
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
*/
static enum GNUNET_GenericReturnValue
-parse_amount_nbo (void *cls,
- json_t *root,
- struct GNUNET_JSON_Specification *spec)
+parse_cspec (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
{
- const char *currency = cls;
- struct TALER_AmountNBO *r_amount = spec->ptr;
- const char *sv;
+ struct TALER_CurrencySpecification *r_cspec = spec->ptr;
+ const char *currency = spec->cls;
+ const char *name;
+ uint32_t fid;
+ uint32_t fnd;
+ uint32_t ftzd;
+ const json_t *map;
+ struct GNUNET_JSON_Specification gspec[] = {
+ GNUNET_JSON_spec_string ("name",
+ &name),
+ GNUNET_JSON_spec_uint32 ("num_fractional_input_digits",
+ &fid),
+ GNUNET_JSON_spec_uint32 ("num_fractional_normal_digits",
+ &fnd),
+ GNUNET_JSON_spec_uint32 ("num_fractional_trailing_zero_digits",
+ &ftzd),
+ GNUNET_JSON_spec_object_const ("alt_unit_names",
+ &map),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int eline;
- (void) cls;
- if (! json_is_string (root))
+ memset (r_cspec->currency,
+ 0,
+ sizeof (r_cspec->currency));
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (root,
+ gspec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to parse %s at %u: %s\n",
+ spec[eline].field,
+ eline,
+ emsg);
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (strlen (currency) >= TALER_CURRENCY_LEN)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ( (fid > TALER_AMOUNT_FRAC_LEN) ||
+ (fnd > TALER_AMOUNT_FRAC_LEN) ||
+ (ftzd > TALER_AMOUNT_FRAC_LEN) )
{
- GNUNET_break (0);
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- sv = json_string_value (root);
if (GNUNET_OK !=
- TALER_string_to_amount_nbo (sv,
- r_amount))
+ TALER_check_currency (currency))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "`%s' is not a valid amount\n",
- sv);
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if ( (NULL != currency) &&
- (0 !=
- strcasecmp (currency,
- r_amount->currency)) )
+ strcpy (r_cspec->currency,
+ currency);
+ if (GNUNET_OK !=
+ TALER_check_currency_scale_map (map))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
+ r_cspec->name = GNUNET_strdup (name);
+ r_cspec->map_alt_unit_names = json_incref ((json_t *) map);
return GNUNET_OK;
}
-struct GNUNET_JSON_Specification
-TALER_JSON_spec_amount_nbo (const char *name,
- const char *currency,
- struct TALER_AmountNBO *r_amount)
+/**
+ * Cleanup data left from parsing encrypted contract.
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_cspec (void *cls,
+ struct GNUNET_JSON_Specification *spec)
{
- struct GNUNET_JSON_Specification ret = {
- .parser = &parse_amount_nbo,
- .cleaner = NULL,
- .cls = (void *) currency,
- .field = name,
- .ptr = r_amount,
- .ptr_size = 0,
- .size_ptr = NULL
- };
+ struct TALER_CurrencySpecification *cspec = spec->ptr;
- GNUNET_assert (NULL != currency);
- return ret;
+ (void) cls;
+ GNUNET_free (cspec->name);
+ json_decref (cspec->map_alt_unit_names);
}
struct GNUNET_JSON_Specification
-TALER_JSON_spec_amount_any_nbo (const char *name,
- struct TALER_AmountNBO *r_amount)
+TALER_JSON_spec_currency_specification (
+ const char *name,
+ const char *currency,
+ struct TALER_CurrencySpecification *r_cspec)
{
struct GNUNET_JSON_Specification ret = {
- .parser = &parse_amount_nbo,
- .cleaner = NULL,
- .cls = NULL,
+ .parser = &parse_cspec,
+ .cleaner = &clean_cspec,
+ .cls = (void *) currency,
.field = name,
- .ptr = r_amount,
- .ptr_size = 0,
+ .ptr = r_cspec,
+ .ptr_size = sizeof (*r_cspec),
.size_ptr = NULL
};
+ memset (r_cspec,
+ 0,
+ sizeof (*r_cspec));
return ret;
}
@@ -266,8 +297,6 @@ parse_denomination_group (void *cls,
GNUNET_JSON_spec_uint32 ("age_mask",
&group->age_mask.bits),
&age_mask_missing),
- GNUNET_JSON_spec_fixed_auto ("hash",
- &group->hash),
GNUNET_JSON_spec_end ()
};
const char *emsg;
@@ -279,12 +308,17 @@ parse_denomination_group (void *cls,
&emsg,
&eline))
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to parse %s at %u: %s\n",
+ spec[eline].field,
+ eline,
+ emsg);
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
group->cipher = string_to_cipher (cipher);
- if (TALER_DENOMINATION_INVALID == group->cipher)
+ if (GNUNET_CRYPTO_BSA_INVALID == group->cipher)
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -314,11 +348,9 @@ TALER_JSON_spec_denomination_group (const char *name,
struct GNUNET_JSON_Specification ret = {
.cls = (void *) currency,
.parser = &parse_denomination_group,
- .cleaner = NULL,
.field = name,
.ptr = group,
- .ptr_size = sizeof(*group),
- .size_ptr = NULL,
+ .ptr_size = sizeof(*group)
};
return ret;
@@ -390,11 +422,8 @@ TALER_JSON_spec_econtract (const char *name,
struct GNUNET_JSON_Specification ret = {
.parser = &parse_econtract,
.cleaner = &clean_econtract,
- .cls = NULL,
.field = name,
- .ptr = econtract,
- .ptr_size = 0,
- .size_ptr = NULL
+ .ptr = econtract
};
return ret;
@@ -419,7 +448,9 @@ parse_age_commitment (void *cls,
unsigned int idx;
size_t num;
- if (NULL == root || ! json_is_array (root))
+ (void) cls;
+ if ( (NULL == root) ||
+ (! json_is_array (root)))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -464,7 +495,7 @@ parse_age_commitment (void *cls,
/**
- * Cleanup data left fom parsing age commitment
+ * Cleanup data left from parsing age commitment
*
* @param cls closure, NULL
* @param[out] spec where to free the data
@@ -493,11 +524,8 @@ TALER_JSON_spec_age_commitment (const char *name,
struct GNUNET_JSON_Specification ret = {
.parser = &parse_age_commitment,
.cleaner = &clean_age_commitment,
- .cls = NULL,
.field = name,
- .ptr = age_commitment,
- .ptr_size = 0,
- .size_ptr = NULL
+ .ptr = age_commitment
};
return ret;
@@ -518,6 +546,7 @@ parse_denom_pub (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_DenominationPublicKey *denom_pub = spec->ptr;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub;
const char *cipher;
bool age_mask_missing = false;
struct GNUNET_JSON_Specification dspec[] = {
@@ -545,16 +574,19 @@ parse_denom_pub (void *cls,
if (age_mask_missing)
denom_pub->age_mask.bits = 0;
-
- denom_pub->cipher = string_to_cipher (cipher);
- switch (denom_pub->cipher)
+ bsign_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bsign_pub->rc = 1;
+ bsign_pub->cipher = string_to_cipher (cipher);
+ switch (bsign_pub->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_rsa_public_key (
"rsa_public_key",
- &denom_pub->details.rsa_public_key),
+ &bsign_pub->details.rsa_public_key),
GNUNET_JSON_spec_end ()
};
@@ -565,16 +597,18 @@ parse_denom_pub (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
return GNUNET_SYSERR;
}
+ denom_pub->bsign_pub_key = bsign_pub;
return GNUNET_OK;
}
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed ("cs_public_key",
- &denom_pub->details.cs_public_key,
- sizeof (denom_pub->details.cs_public_key)),
+ &bsign_pub->details.cs_public_key,
+ sizeof (bsign_pub->details.cs_public_key)),
GNUNET_JSON_spec_end ()
};
@@ -585,14 +619,16 @@ parse_denom_pub (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
return GNUNET_SYSERR;
}
+ denom_pub->bsign_pub_key = bsign_pub;
return GNUNET_OK;
}
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
+ return GNUNET_SYSERR;
}
@@ -624,7 +660,7 @@ TALER_JSON_spec_denom_pub (const char *field,
.ptr = pk
};
- pk->cipher = TALER_DENOMINATION_INVALID;
+ pk->bsign_pub_key = NULL;
return ret;
}
@@ -634,8 +670,7 @@ TALER_JSON_spec_denom_pub (const char *field,
*
* Depending on the cipher in cls, it parses the corresponding public key type.
*
- * @param cls closure, enum TALER_DenominationCipher
- * @param cipher cipher to parse for
+ * @param cls closure, enum GNUNET_CRYPTO_BlindSignatureAlgorithm
* @param root the json object representing data
* @param[out] spec where to write the data
* @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
@@ -646,18 +681,25 @@ parse_denom_pub_cipher (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_DenominationPublicKey *denom_pub = spec->ptr;
- enum TALER_DenominationCipher cipher = (enum TALER_DenominationCipher) cls;
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher =
+ (enum GNUNET_CRYPTO_BlindSignatureAlgorithm) (long) cls;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub;
const char *emsg;
unsigned int eline;
+ bsign_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bsign_pub->cipher = cipher;
+ bsign_pub->rc = 1;
switch (cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_rsa_public_key (
"rsa_pub",
- &denom_pub->details.rsa_public_key),
+ &bsign_pub->details.rsa_public_key),
GNUNET_JSON_spec_end ()
};
@@ -668,16 +710,18 @@ parse_denom_pub_cipher (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
return GNUNET_SYSERR;
}
+ denom_pub->bsign_pub_key = bsign_pub;
return GNUNET_OK;
}
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed ("cs_pub",
- &denom_pub->details.cs_public_key,
- sizeof (denom_pub->details.cs_public_key)),
+ &bsign_pub->details.cs_public_key,
+ sizeof (bsign_pub->details.cs_public_key)),
GNUNET_JSON_spec_end ()
};
@@ -688,20 +732,23 @@ parse_denom_pub_cipher (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
return GNUNET_SYSERR;
}
+ denom_pub->bsign_pub_key = bsign_pub;
return GNUNET_OK;
}
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ GNUNET_free (bsign_pub);
+ return GNUNET_SYSERR;
}
struct GNUNET_JSON_Specification
TALER_JSON_spec_denom_pub_cipher (const char *field,
- enum TALER_DenominationCipher cipher,
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm
+ cipher,
struct TALER_DenominationPublicKey *pk)
{
struct GNUNET_JSON_Specification ret = {
@@ -730,6 +777,7 @@ parse_denom_sig (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_DenominationSignature *denom_sig = spec->ptr;
+ struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
const char *cipher;
struct GNUNET_JSON_Specification dspec[] = {
GNUNET_JSON_spec_string ("cipher",
@@ -749,15 +797,19 @@ parse_denom_sig (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- denom_sig->cipher = string_to_cipher (cipher);
- switch (denom_sig->cipher)
+ unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
+ unblinded_sig->cipher = string_to_cipher (cipher);
+ unblinded_sig->rc = 1;
+ switch (unblinded_sig->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_rsa_signature (
"rsa_signature",
- &denom_sig->details.rsa_signature),
+ &unblinded_sig->details.rsa_signature),
GNUNET_JSON_spec_end ()
};
@@ -768,17 +820,21 @@ parse_denom_sig (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (unblinded_sig);
return GNUNET_SYSERR;
}
+ denom_sig->unblinded_sig = unblinded_sig;
return GNUNET_OK;
}
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
- &denom_sig->details.cs_signature.r_point),
+ &unblinded_sig->details.cs_signature.
+ r_point),
GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
- &denom_sig->details.cs_signature.s_scalar),
+ &unblinded_sig->details.cs_signature.
+ s_scalar),
GNUNET_JSON_spec_end ()
};
@@ -789,14 +845,16 @@ parse_denom_sig (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (unblinded_sig);
return GNUNET_SYSERR;
}
+ denom_sig->unblinded_sig = unblinded_sig;
return GNUNET_OK;
}
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ GNUNET_free (unblinded_sig);
+ return GNUNET_SYSERR;
}
@@ -828,7 +886,7 @@ TALER_JSON_spec_denom_sig (const char *field,
.ptr = sig
};
- sig->cipher = TALER_DENOMINATION_INVALID;
+ sig->unblinded_sig = NULL;
return ret;
}
@@ -847,6 +905,7 @@ parse_blinded_denom_sig (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_BlindedDenominationSignature *denom_sig = spec->ptr;
+ struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
const char *cipher;
struct GNUNET_JSON_Specification dspec[] = {
GNUNET_JSON_spec_string ("cipher",
@@ -866,15 +925,19 @@ parse_blinded_denom_sig (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- denom_sig->cipher = string_to_cipher (cipher);
- switch (denom_sig->cipher)
+ blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ blinded_sig->cipher = string_to_cipher (cipher);
+ blinded_sig->rc = 1;
+ switch (blinded_sig->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_rsa_signature (
"blinded_rsa_signature",
- &denom_sig->details.blinded_rsa_signature),
+ &blinded_sig->details.blinded_rsa_signature),
GNUNET_JSON_spec_end ()
};
@@ -885,17 +948,19 @@ parse_blinded_denom_sig (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (blinded_sig);
return GNUNET_SYSERR;
}
+ denom_sig->blinded_sig = blinded_sig;
return GNUNET_OK;
}
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_uint32 ("b",
- &denom_sig->details.blinded_cs_answer.b),
+ &blinded_sig->details.blinded_cs_answer.b),
GNUNET_JSON_spec_fixed_auto ("s",
- &denom_sig->details.blinded_cs_answer.
+ &blinded_sig->details.blinded_cs_answer.
s_scalar),
GNUNET_JSON_spec_end ()
};
@@ -907,15 +972,16 @@ parse_blinded_denom_sig (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (blinded_sig);
return GNUNET_SYSERR;
}
+ denom_sig->blinded_sig = blinded_sig;
return GNUNET_OK;
}
- break;
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ GNUNET_free (blinded_sig);
+ return GNUNET_SYSERR;
}
@@ -948,7 +1014,7 @@ TALER_JSON_spec_blinded_denom_sig (
.ptr = sig
};
- sig->cipher = TALER_DENOMINATION_INVALID;
+ sig->blinded_sig = NULL;
return ret;
}
@@ -967,6 +1033,7 @@ parse_blinded_planchet (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_BlindedPlanchet *blinded_planchet = spec->ptr;
+ struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
const char *cipher;
struct GNUNET_JSON_Specification dspec[] = {
GNUNET_JSON_spec_string ("cipher",
@@ -986,16 +1053,20 @@ parse_blinded_planchet (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- blinded_planchet->cipher = string_to_cipher (cipher);
- switch (blinded_planchet->cipher)
+ blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ blinded_message->rc = 1;
+ blinded_message->cipher = string_to_cipher (cipher);
+ switch (blinded_message->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_varsize (
"rsa_blinded_planchet",
- &blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- &blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size),
+ &blinded_message->details.rsa_blinded_message.blinded_msg,
+ &blinded_message->details.rsa_blinded_message.blinded_msg_size),
GNUNET_JSON_spec_end ()
};
@@ -1006,22 +1077,24 @@ parse_blinded_planchet (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (blinded_message);
return GNUNET_SYSERR;
}
+ blinded_planchet->blinded_message = blinded_message;
return GNUNET_OK;
}
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed_auto (
"cs_nonce",
- &blinded_planchet->details.cs_blinded_planchet.nonce),
+ &blinded_message->details.cs_blinded_message.nonce),
GNUNET_JSON_spec_fixed_auto (
"cs_blinded_c0",
- &blinded_planchet->details.cs_blinded_planchet.c[0]),
+ &blinded_message->details.cs_blinded_message.c[0]),
GNUNET_JSON_spec_fixed_auto (
"cs_blinded_c1",
- &blinded_planchet->details.cs_blinded_planchet.c[1]),
+ &blinded_message->details.cs_blinded_message.c[1]),
GNUNET_JSON_spec_end ()
};
@@ -1032,15 +1105,16 @@ parse_blinded_planchet (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (blinded_message);
return GNUNET_SYSERR;
}
+ blinded_planchet->blinded_message = blinded_message;
return GNUNET_OK;
}
- break;
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ GNUNET_free (blinded_message);
+ return GNUNET_SYSERR;
}
@@ -1072,7 +1146,7 @@ TALER_JSON_spec_blinded_planchet (const char *field,
.ptr = blinded_planchet
};
- blinded_planchet->cipher = TALER_DENOMINATION_INVALID;
+ blinded_planchet->blinded_message = NULL;
return ret;
}
@@ -1091,6 +1165,7 @@ parse_exchange_withdraw_values (void *cls,
struct GNUNET_JSON_Specification *spec)
{
struct TALER_ExchangeWithdrawValues *ewv = spec->ptr;
+ struct GNUNET_CRYPTO_BlindingInputValues *bi;
const char *cipher;
struct GNUNET_JSON_Specification dspec[] = {
GNUNET_JSON_spec_string ("cipher",
@@ -1099,6 +1174,7 @@ parse_exchange_withdraw_values (void *cls,
};
const char *emsg;
unsigned int eline;
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm ci;
(void) cls;
if (GNUNET_OK !=
@@ -1110,21 +1186,27 @@ parse_exchange_withdraw_values (void *cls,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- ewv->cipher = string_to_cipher (cipher);
- switch (ewv->cipher)
+ ci = string_to_cipher (cipher);
+ switch (ci)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ ewv->blinding_inputs = TALER_denom_ewv_rsa_singleton ()->blinding_inputs;
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
+ bi = GNUNET_new (struct GNUNET_CRYPTO_BlindingInputValues);
+ bi->cipher = GNUNET_CRYPTO_BSA_CS;
+ bi->rc = 1;
{
struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed (
"r_pub_0",
- &ewv->details.cs_values.r_pub[0],
+ &bi->details.cs_values.r_pub[0],
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
GNUNET_JSON_spec_fixed (
"r_pub_1",
- &ewv->details.cs_values.r_pub[1],
+ &bi->details.cs_values.r_pub[1],
sizeof (struct GNUNET_CRYPTO_CsRPublic)),
GNUNET_JSON_spec_end ()
};
@@ -1136,14 +1218,33 @@ parse_exchange_withdraw_values (void *cls,
&eline))
{
GNUNET_break_op (0);
+ GNUNET_free (bi);
return GNUNET_SYSERR;
}
+ ewv->blinding_inputs = bi;
return GNUNET_OK;
}
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
}
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+}
+
+
+/**
+ * Cleanup data left from parsing withdraw values
+ *
+ * @param cls closure, NULL
+ * @param[out] spec where to free the data
+ */
+static void
+clean_exchange_withdraw_values (
+ void *cls,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_ExchangeWithdrawValues *ewv = spec->ptr;
+
+ (void) cls;
+ TALER_denom_ewv_free (ewv);
}
@@ -1154,11 +1255,12 @@ TALER_JSON_spec_exchange_withdraw_values (
{
struct GNUNET_JSON_Specification ret = {
.parser = &parse_exchange_withdraw_values,
+ .cleaner = &clean_exchange_withdraw_values,
.field = field,
.ptr = ewv
};
- ewv->cipher = TALER_DENOMINATION_INVALID;
+ ewv->blinding_inputs = NULL;
return ret;
}
@@ -1235,11 +1337,6 @@ parse_i18n_string (void *cls,
const char *str;
str = json_string_value (val);
- if (NULL == str)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
*(const char **) spec->ptr = str;
}
return GNUNET_OK;
@@ -1259,8 +1356,11 @@ i18n_cleaner (void *cls,
struct I18nContext *ctx = cls;
(void) spec;
- GNUNET_free (ctx->lp);
- GNUNET_free (ctx);
+ if (NULL != ctx)
+ {
+ GNUNET_free (ctx->lp);
+ GNUNET_free (ctx);
+ }
}
@@ -1280,8 +1380,9 @@ TALER_JSON_spec_i18n_string (const char *name,
.size_ptr = NULL
};
- ctx->lp = (NULL != language_pattern) ? GNUNET_strdup (language_pattern) :
- NULL;
+ ctx->lp = (NULL != language_pattern)
+ ? GNUNET_strdup (language_pattern)
+ : NULL;
ctx->field = name;
*strptr = NULL;
return ret;
@@ -1319,4 +1420,400 @@ TALER_JSON_spec_i18n_str (const char *name,
}
+/**
+ * Parse given JSON object with Taler error code.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_ec (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ enum TALER_ErrorCode *ec = spec->ptr;
+ json_int_t num;
+
+ (void) cls;
+ if (! json_is_integer (root))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ num = json_integer_value (root);
+ if (num < 0)
+ {
+ GNUNET_break_op (0);
+ *ec = TALER_EC_INVALID;
+ return GNUNET_SYSERR;
+ }
+ *ec = (enum TALER_ErrorCode) num;
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_ec (const char *field,
+ enum TALER_ErrorCode *ec)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_ec,
+ .field = field,
+ .ptr = ec
+ };
+
+ *ec = TALER_EC_NONE;
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object with AML decision.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_aml_decision (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ enum TALER_AmlDecisionState *aml = spec->ptr;
+ json_int_t num;
+
+ (void) cls;
+ if (! json_is_integer (root))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ num = json_integer_value (root);
+ if ( (num > TALER_AML_MAX) ||
+ (num < 0) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ *aml = (enum TALER_AmlDecisionState) num;
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_aml_decision (const char *field,
+ enum TALER_AmlDecisionState *aml_state)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_aml_decision,
+ .field = field,
+ .ptr = aml_state
+ };
+
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object to web URL.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_web_url (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ const char *str;
+
+ (void) cls;
+ str = json_string_value (root);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (! TALER_is_web_url (str))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ *(const char **) spec->ptr = str;
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_web_url (const char *field,
+ const char **url)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_web_url,
+ .field = field,
+ .ptr = url
+ };
+
+ *url = NULL;
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object to payto:// URI.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_payto_uri (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ const char *str;
+ char *err;
+
+ (void) cls;
+ str = json_string_value (root);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ err = TALER_payto_validate (str);
+ if (NULL != err)
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (err);
+ return GNUNET_SYSERR;
+ }
+ *(const char **) spec->ptr = str;
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_payto_uri (const char *field,
+ const char **payto_uri)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_payto_uri,
+ .field = field,
+ .ptr = payto_uri
+ };
+
+ *payto_uri = NULL;
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object with protocol version.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_protocol_version (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ struct TALER_JSON_ProtocolVersion *pv = spec->ptr;
+ const char *ver;
+ char dummy;
+
+ (void) cls;
+ if (! json_is_string (root))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ ver = json_string_value (root);
+ if (3 != sscanf (ver,
+ "%u:%u:%u%c",
+ &pv->current,
+ &pv->revision,
+ &pv->age,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_version (const char *field,
+ struct TALER_JSON_ProtocolVersion *ver)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_protocol_version,
+ .field = field,
+ .ptr = ver
+ };
+
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object to an OTP key.
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_otp_key (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ const char *pos_key;
+
+ (void) cls;
+ pos_key = json_string_value (root);
+ if (NULL == pos_key)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ {
+ size_t pos_key_length = strlen (pos_key);
+ void *key; /* pos_key in binary */
+ size_t key_len; /* length of the key */
+ int dret;
+
+ key_len = pos_key_length * 5 / 8;
+ key = GNUNET_malloc (key_len);
+ dret = TALER_rfc3548_base32decode (pos_key,
+ pos_key_length,
+ key,
+ key_len);
+ if (-1 == dret)
+ {
+ GNUNET_free (key);
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (key);
+ }
+ *(const char **) spec->ptr = pos_key;
+ return GNUNET_OK;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_otp_key (const char *name,
+ const char **otp_key)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_otp_key,
+ .field = name,
+ .ptr = otp_key
+ };
+
+ *otp_key = NULL;
+ return ret;
+}
+
+
+/**
+ * Parse given JSON object to `enum TALER_MerchantConfirmationAlgorithm`
+ *
+ * @param cls closure, NULL
+ * @param root the json object representing data
+ * @param[out] spec where to write the data
+ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
+ */
+static enum GNUNET_GenericReturnValue
+parse_otp_type (void *cls,
+ json_t *root,
+ struct GNUNET_JSON_Specification *spec)
+{
+ static const struct Entry
+ {
+ const char *name;
+ enum TALER_MerchantConfirmationAlgorithm val;
+ } lt [] = {
+ { .name = "NONE",
+ .val = TALER_MCA_NONE },
+ { .name = "TOTP_WITHOUT_PRICE",
+ .val = TALER_MCA_WITHOUT_PRICE },
+ { .name = "TOTP_WITH_PRICE",
+ .val = TALER_MCA_WITH_PRICE },
+ { .name = NULL,
+ .val = TALER_MCA_NONE },
+ };
+ enum TALER_MerchantConfirmationAlgorithm *res
+ = (enum TALER_MerchantConfirmationAlgorithm *) spec->ptr;
+
+ (void) cls;
+ if (json_is_string (root))
+ {
+ const char *str;
+
+ str = json_string_value (root);
+ if (NULL == str)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ for (unsigned int i = 0; NULL != lt[i].name; i++)
+ {
+ if (0 == strcasecmp (str,
+ lt[i].name))
+ {
+ *res = lt[i].val;
+ return GNUNET_OK;
+ }
+ }
+ GNUNET_break_op (0);
+ }
+ if (json_is_integer (root))
+ {
+ json_int_t val;
+
+ val = json_integer_value (root);
+ for (unsigned int i = 0; NULL != lt[i].name; i++)
+ {
+ if (val == lt[i].val)
+ {
+ *res = lt[i].val;
+ return GNUNET_OK;
+ }
+ }
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+}
+
+
+struct GNUNET_JSON_Specification
+TALER_JSON_spec_otp_type (const char *name,
+ enum TALER_MerchantConfirmationAlgorithm *mca)
+{
+ struct GNUNET_JSON_Specification ret = {
+ .parser = &parse_otp_type,
+ .field = name,
+ .ptr = mca
+ };
+
+ *mca = TALER_MCA_NONE;
+ return ret;
+}
+
+
/* end of json/json_helper.c */
diff --git a/src/json/json_pack.c b/src/json/json_pack.c
index 834e8104b..71c8db9d2 100644
--- a/src/json/json_pack.c
+++ b/src/json/json_pack.c
@@ -39,15 +39,6 @@ TALER_JSON_pack_time_abs_human (const char *name,
struct GNUNET_JSON_PackSpec
-TALER_JSON_pack_time_abs_nbo_human (const char *name,
- struct GNUNET_TIME_AbsoluteNBO at)
-{
- return TALER_JSON_pack_time_abs_human (name,
- GNUNET_TIME_absolute_ntoh (at));
-}
-
-
-struct GNUNET_JSON_PackSpec
TALER_JSON_pack_econtract (
const char *name,
const struct TALER_EncryptedContract *econtract)
@@ -110,37 +101,41 @@ TALER_JSON_pack_denom_pub (
const char *name,
const struct TALER_DenominationPublicKey *pk)
{
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *bsp;
struct GNUNET_JSON_PackSpec ps = {
.field_name = name,
};
if (NULL == pk)
return ps;
- switch (pk->cipher)
+ bsp = pk->bsign_pub_key;
+ switch (bsp->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
ps.object
= GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("cipher", "RSA"),
+ GNUNET_JSON_pack_string ("cipher",
+ "RSA"),
GNUNET_JSON_pack_uint64 ("age_mask",
pk->age_mask.bits),
GNUNET_JSON_pack_rsa_public_key ("rsa_public_key",
- pk->details.rsa_public_key));
- break;
- case TALER_DENOMINATION_CS:
+ bsp->details.rsa_public_key));
+ return ps;
+ case GNUNET_CRYPTO_BSA_CS:
ps.object
= GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("cipher", "CS"),
+ GNUNET_JSON_pack_string ("cipher",
+ "CS"),
GNUNET_JSON_pack_uint64 ("age_mask",
pk->age_mask.bits),
GNUNET_JSON_pack_data_varsize ("cs_public_key",
- &pk->details.cs_public_key,
- sizeof (pk->details.cs_public_key)));
- break;
- default:
- GNUNET_assert (0);
+ &bsp->details.cs_public_key,
+ sizeof (bsp->details.cs_public_key)));
+ return ps;
}
-
+ GNUNET_assert (0);
return ps;
}
@@ -150,33 +145,36 @@ TALER_JSON_pack_denom_sig (
const char *name,
const struct TALER_DenominationSignature *sig)
{
+ const struct GNUNET_CRYPTO_UnblindedSignature *bs;
struct GNUNET_JSON_PackSpec ps = {
.field_name = name,
};
if (NULL == sig)
return ps;
- switch (sig->cipher)
+ bs = sig->unblinded_sig;
+ switch (bs->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"RSA"),
GNUNET_JSON_pack_rsa_signature ("rsa_signature",
- sig->details.rsa_signature));
- break;
- case TALER_DENOMINATION_CS:
+ bs->details.rsa_signature));
+ return ps;
+ case GNUNET_CRYPTO_BSA_CS:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"CS"),
GNUNET_JSON_pack_data_auto ("cs_signature_r",
- &sig->details.cs_signature.r_point),
+ &bs->details.cs_signature.r_point),
GNUNET_JSON_pack_data_auto ("cs_signature_s",
- &sig->details.cs_signature.s_scalar));
- break;
- default:
- GNUNET_assert (0);
+ &bs->details.cs_signature.s_scalar));
+ return ps;
}
+ GNUNET_assert (0);
return ps;
}
@@ -186,36 +184,39 @@ TALER_JSON_pack_exchange_withdraw_values (
const char *name,
const struct TALER_ExchangeWithdrawValues *ewv)
{
+ const struct GNUNET_CRYPTO_BlindingInputValues *biv;
struct GNUNET_JSON_PackSpec ps = {
.field_name = name,
};
if (NULL == ewv)
return ps;
- switch (ewv->cipher)
+ biv = ewv->blinding_inputs;
+ switch (biv->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"RSA"));
- break;
- case TALER_DENOMINATION_CS:
+ return ps;
+ case GNUNET_CRYPTO_BSA_CS:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"CS"),
GNUNET_JSON_pack_data_varsize (
"r_pub_0",
- &ewv->details.cs_values.r_pub[0],
+ &biv->details.cs_values.r_pub[0],
sizeof(struct GNUNET_CRYPTO_CsRPublic)),
GNUNET_JSON_pack_data_varsize (
"r_pub_1",
- &ewv->details.cs_values.r_pub[1],
+ &biv->details.cs_values.r_pub[1],
sizeof(struct GNUNET_CRYPTO_CsRPublic))
);
- break;
- default:
- GNUNET_assert (0);
+ return ps;
}
+ GNUNET_assert (0);
return ps;
}
@@ -225,33 +226,36 @@ TALER_JSON_pack_blinded_denom_sig (
const char *name,
const struct TALER_BlindedDenominationSignature *sig)
{
+ const struct GNUNET_CRYPTO_BlindedSignature *bs;
struct GNUNET_JSON_PackSpec ps = {
.field_name = name,
};
if (NULL == sig)
return ps;
- switch (sig->cipher)
+ bs = sig->blinded_sig;
+ switch (bs->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"RSA"),
GNUNET_JSON_pack_rsa_signature ("blinded_rsa_signature",
- sig->details.blinded_rsa_signature));
- break;
- case TALER_DENOMINATION_CS:
+ bs->details.blinded_rsa_signature));
+ return ps;
+ case GNUNET_CRYPTO_BSA_CS:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"CS"),
GNUNET_JSON_pack_uint64 ("b",
- sig->details.blinded_cs_answer.b),
+ bs->details.blinded_cs_answer.b),
GNUNET_JSON_pack_data_auto ("s",
- &sig->details.blinded_cs_answer.s_scalar));
- break;
- default:
- GNUNET_assert (0);
+ &bs->details.blinded_cs_answer.s_scalar));
+ return ps;
}
+ GNUNET_assert (0);
return ps;
}
@@ -261,40 +265,43 @@ TALER_JSON_pack_blinded_planchet (
const char *name,
const struct TALER_BlindedPlanchet *blinded_planchet)
{
+ const struct GNUNET_CRYPTO_BlindedMessage *bm;
struct GNUNET_JSON_PackSpec ps = {
.field_name = name,
};
if (NULL == blinded_planchet)
return ps;
- switch (blinded_planchet->cipher)
+ bm = blinded_planchet->blinded_message;
+ switch (bm->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"RSA"),
GNUNET_JSON_pack_data_varsize (
"rsa_blinded_planchet",
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size));
- break;
- case TALER_DENOMINATION_CS:
+ bm->details.rsa_blinded_message.blinded_msg,
+ bm->details.rsa_blinded_message.blinded_msg_size));
+ return ps;
+ case GNUNET_CRYPTO_BSA_CS:
ps.object = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("cipher",
"CS"),
GNUNET_JSON_pack_data_auto (
"cs_nonce",
- &blinded_planchet->details.cs_blinded_planchet.nonce),
+ &bm->details.cs_blinded_message.nonce),
GNUNET_JSON_pack_data_auto (
"cs_blinded_c0",
- &blinded_planchet->details.cs_blinded_planchet.c[0]),
+ &bm->details.cs_blinded_message.c[0]),
GNUNET_JSON_pack_data_auto (
"cs_blinded_c1",
- &blinded_planchet->details.cs_blinded_planchet.c[1]));
- break;
- default:
- GNUNET_assert (0);
+ &bm->details.cs_blinded_message.c[1]));
+ return ps;
}
+ GNUNET_assert (0);
return ps;
}
@@ -314,19 +321,4 @@ TALER_JSON_pack_amount (const char *name,
}
-struct GNUNET_JSON_PackSpec
-TALER_JSON_pack_amount_nbo (const char *name,
- const struct TALER_AmountNBO *amount)
-{
- struct GNUNET_JSON_PackSpec ps = {
- .field_name = name,
- .object = (NULL != amount)
- ? TALER_JSON_from_amount_nbo (amount)
- : NULL
- };
-
- return ps;
-}
-
-
/* End of json/json_pack.c */
diff --git a/src/json/json_wire.c b/src/json/json_wire.c
index 544b56453..9d22d28ea 100644
--- a/src/json/json_wire.c
+++ b/src/json/json_wire.c
@@ -70,80 +70,6 @@ TALER_JSON_merchant_wire_signature_hash (const json_t *wire_s,
}
-enum GNUNET_GenericReturnValue
-TALER_JSON_exchange_wire_signature_check (
- const json_t *wire_s,
- const struct TALER_MasterPublicKeyP *master_pub)
-{
- const char *payto_uri;
- struct TALER_MasterSignatureP master_sig;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("payto_uri",
- &payto_uri),
- GNUNET_JSON_spec_fixed_auto ("master_sig",
- &master_sig),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (wire_s,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- {
- char *err;
-
- err = TALER_payto_validate (payto_uri);
- if (NULL != err)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "URI `%s' ill-formed: %s\n",
- payto_uri,
- err);
- GNUNET_free (err);
- return GNUNET_SYSERR;
- }
- }
-
- return TALER_exchange_wire_signature_check (payto_uri,
- master_pub,
- &master_sig);
-}
-
-
-json_t *
-TALER_JSON_exchange_wire_signature_make (
- const char *payto_uri,
- const struct TALER_MasterPrivateKeyP *master_priv)
-{
- struct TALER_MasterSignatureP master_sig;
- char *err;
-
- if (NULL !=
- (err = TALER_payto_validate (payto_uri)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Invalid payto URI `%s': %s\n",
- payto_uri,
- err);
- GNUNET_free (err);
- return NULL;
- }
- TALER_exchange_wire_signature_make (payto_uri,
- master_priv,
- &master_sig);
- return GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("payto_uri",
- payto_uri),
- GNUNET_JSON_pack_data_auto ("master_sig",
- &master_sig));
-}
-
-
char *
TALER_JSON_wire_to_payto (const json_t *wire_s)
{
diff --git a/src/json/test_json.c b/src/json/test_json.c
index d37f66eaf..fba72f84b 100644
--- a/src/json/test_json.c
+++ b/src/json/test_json.c
@@ -103,7 +103,8 @@ test_contract (void)
"k2", "n1", "n2",
/***/ "$forgettable", "n1", true);
GNUNET_assert (GNUNET_OK ==
- TALER_JSON_contract_seed_forgettable (c1));
+ TALER_JSON_contract_seed_forgettable (c1,
+ c1));
GNUNET_assert (GNUNET_OK ==
TALER_JSON_contract_hash (c1,
&h1));
diff --git a/src/json/test_json_wire.c b/src/json/test_json_wire.c
deleted file mode 100644
index b417b25fe..000000000
--- a/src/json/test_json_wire.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- This file is part of TALER
- (C) 2015, 2016 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file json/test_json_wire.c
- * @brief Tests for Taler-specific crypto logic
- * @author Christian Grothoff <christian@grothoff.org>
- */
-#include "platform.h"
-#include "taler_util.h"
-#include "taler_json_lib.h"
-
-
-int
-main (int argc,
- const char *const argv[])
-{
- struct TALER_MasterPublicKeyP master_pub;
- struct TALER_MasterPrivateKeyP master_priv;
- json_t *wire_xtalerbank;
- json_t *wire_iban;
- const char *payto_xtalerbank = "payto://x-taler-bank/42";
- const char *payto_iban =
- "payto://iban/BIC-TO-BE-SKIPPED/DE89370400440532013000?receiver-name=Test";
- char *p_xtalerbank;
- char *p_iban;
-
- (void) argc;
- (void) argv;
- GNUNET_log_setup ("test-json-wire",
- "WARNING",
- NULL);
- GNUNET_CRYPTO_eddsa_key_create (&master_priv.eddsa_priv);
- GNUNET_CRYPTO_eddsa_key_get_public (&master_priv.eddsa_priv,
- &master_pub.eddsa_pub);
- wire_xtalerbank = TALER_JSON_exchange_wire_signature_make (payto_xtalerbank,
- &master_priv);
- wire_iban = TALER_JSON_exchange_wire_signature_make (payto_iban,
- &master_priv);
- if (NULL == wire_iban)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not parse payto/IBAN (%s) into 'wire object'\n",
- payto_iban);
- return 1;
- }
- p_xtalerbank = TALER_JSON_wire_to_payto (wire_xtalerbank);
- p_iban = TALER_JSON_wire_to_payto (wire_iban);
- GNUNET_assert (0 == strcmp (p_xtalerbank, payto_xtalerbank));
- GNUNET_assert (0 == strcmp (p_iban, payto_iban));
- GNUNET_free (p_xtalerbank);
- GNUNET_free (p_iban);
-
- GNUNET_assert (GNUNET_OK ==
- TALER_JSON_exchange_wire_signature_check (wire_xtalerbank,
- &master_pub));
- GNUNET_assert (GNUNET_OK ==
- TALER_JSON_exchange_wire_signature_check (wire_iban,
- &master_pub));
- json_decref (wire_xtalerbank);
- json_decref (wire_iban);
-
- return 0;
-}
-
-
-/* end of test_json_wire.c */
diff --git a/src/kyclogic/Makefile.am b/src/kyclogic/Makefile.am
new file mode 100644
index 000000000..0281553fc
--- /dev/null
+++ b/src/kyclogic/Makefile.am
@@ -0,0 +1,144 @@
+# This Makefile.am is in the public domain
+AM_CPPFLAGS = -I$(top_srcdir)/src/include
+
+if USE_COVERAGE
+ AM_CFLAGS = --coverage -O0
+ XLIB = -lgcov
+endif
+
+pkgcfgdir = $(prefix)/share/taler/config.d/
+
+pkgcfg_DATA = \
+ kyclogic.conf \
+ kyclogic-kycaid.conf \
+ kyclogic-oauth2.conf \
+ kyclogic-persona.conf
+
+bin_SCRIPTS = \
+ taler-exchange-kyc-kycaid-converter.sh \
+ taler-exchange-kyc-persona-converter.sh \
+ taler-exchange-kyc-oauth2-test-converter.sh \
+ taler-exchange-kyc-oauth2-challenger.sh \
+ taler-exchange-kyc-oauth2-nda.sh
+
+EXTRA_DIST = \
+ $(pkgcfg_DATA) \
+ $(bin_SCRIPTS) \
+ sample.conf
+
+lib_LTLIBRARIES = \
+ libtalerkyclogic.la
+
+libtalerkyclogic_la_SOURCES = \
+ kyclogic_api.c
+libtalerkyclogic_la_LIBADD = \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -ljansson \
+ -lgnunetutil \
+ $(XLIB)
+libtalerkyclogic_la_LDFLAGS = \
+ -version-info 0:0:0 \
+ -no-undefined
+
+
+bin_PROGRAMS = \
+ taler-exchange-kyc-tester
+
+taler_exchange_kyc_tester_SOURCES = \
+ taler-exchange-kyc-tester.c
+taler_exchange_kyc_tester_LDADD = \
+ $(LIBGCRYPT_LIBS) \
+ libtalerkyclogic.la \
+ $(top_builddir)/src/mhd/libtalermhd.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/templating/libtalertemplating.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lmicrohttpd \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -lgnunetjson \
+ -ljansson \
+ -lcurl \
+ -lz \
+ $(XLIB)
+
+
+
+plugindir = $(libdir)/taler
+
+plugin_LTLIBRARIES = \
+ libtaler_plugin_kyclogic_kycaid.la \
+ libtaler_plugin_kyclogic_oauth2.la \
+ libtaler_plugin_kyclogic_persona.la \
+ libtaler_plugin_kyclogic_template.la
+
+libtaler_plugin_kyclogic_template_la_SOURCES = \
+ plugin_kyclogic_template.c
+libtaler_plugin_kyclogic_template_la_LIBADD = \
+ $(LTLIBINTL)
+libtaler_plugin_kyclogic_template_la_LDFLAGS = \
+ $(TALER_PLUGIN_LDFLAGS) \
+ -lgnunetcurl \
+ -lgnunetutil \
+ $(XLIB)
+
+libtaler_plugin_kyclogic_oauth2_la_SOURCES = \
+ plugin_kyclogic_oauth2.c
+libtaler_plugin_kyclogic_oauth2_la_LIBADD = \
+ $(LTLIBINTL)
+libtaler_plugin_kyclogic_oauth2_la_LDFLAGS = \
+ $(TALER_PLUGIN_LDFLAGS) \
+ $(top_builddir)/src/templating/libtalertemplating.la \
+ $(top_builddir)/src/mhd/libtalermhd.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lmicrohttpd \
+ -ljansson \
+ -lcurl \
+ $(XLIB)
+
+libtaler_plugin_kyclogic_kycaid_la_SOURCES = \
+ plugin_kyclogic_kycaid.c
+libtaler_plugin_kyclogic_kycaid_la_LIBADD = \
+ $(LTLIBINTL)
+libtaler_plugin_kyclogic_kycaid_la_LDFLAGS = \
+ $(TALER_PLUGIN_LDFLAGS) \
+ $(top_builddir)/src/templating/libtalertemplating.la \
+ $(top_builddir)/src/mhd/libtalermhd.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/curl/libtalercurl.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lmicrohttpd \
+ -ljansson \
+ -lcurl \
+ $(XLIB)
+
+libtaler_plugin_kyclogic_persona_la_SOURCES = \
+ plugin_kyclogic_persona.c
+libtaler_plugin_kyclogic_persona_la_LIBADD = \
+ $(LTLIBINTL)
+libtaler_plugin_kyclogic_persona_la_DEPENDENCIES = \
+ libtalerkyclogic.la
+libtaler_plugin_kyclogic_persona_la_LDFLAGS = \
+ $(TALER_PLUGIN_LDFLAGS) \
+ libtalerkyclogic.la \
+ $(top_builddir)/src/mhd/libtalermhd.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/curl/libtalercurl.la \
+ $(top_builddir)/src/templating/libtalertemplating.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetcurl \
+ -lgnunetjson \
+ -lgnunetutil \
+ -lmicrohttpd \
+ -ljansson \
+ -lcurl \
+ $(XLIB)
+
+AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
diff --git a/src/kyclogic/kyclogic-kycaid.conf b/src/kyclogic/kyclogic-kycaid.conf
new file mode 100644
index 000000000..753fb689d
--- /dev/null
+++ b/src/kyclogic/kyclogic-kycaid.conf
@@ -0,0 +1,26 @@
+# This file is in the public domain.
+
+# Example kycaid provider configuration.
+
+[kyc-provider-example-kycaid]
+
+COST = 42
+LOGIC = kycaid
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = EXAMPLE_DO_NOT_USE
+
+# How long is the KYC check valid?
+KYC_KYCAID_VALIDITY = forever
+
+# Program that converts Persona KYC data into the
+# GNU Taler format.
+KYC_KYCAID_CONVERTER_HELPER = taler-exchange-kyc-kycaid-converter.sh
+
+# Authentication token to use.
+KYC_KYCAID_AUTH_TOKEN = XXX
+
+# Form to use.
+KYC_KYCAID_FORM_ID = XXX
+
+# URL to go to after the process is complete.
+KYC_KYCAID_POST_URL = https://example.com/
diff --git a/src/kyclogic/kyclogic-oauth2.conf b/src/kyclogic/kyclogic-oauth2.conf
new file mode 100644
index 000000000..57e1fc13a
--- /dev/null
+++ b/src/kyclogic/kyclogic-oauth2.conf
@@ -0,0 +1,35 @@
+# This file is in the public domain.
+
+# Example Oauth2.0 provider configuration.
+
+[kyc-provider-example-oauth2]
+
+COST = 42
+LOGIC = oauth2
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = EXAMPLE_DO_NOT_USE
+
+# How long is the KYC check valid?
+KYC_OAUTH2_VALIDITY = forever
+
+# URL where we initiate the user's login process
+KYC_OAUTH2_AUTHORIZE_URL = https://kyc.example.com/authorize
+# URL where we send the user's authentication information
+KYC_OAUTH2_TOKEN_URL = https://kyc.example.com/token
+# URL of the user info access point.
+KYC_OAUTH2_INFO_URL = https://kyc.example.com/info
+
+# Where does the client get redirected upon completion?
+KYC_OAUTH2_POST_URL = http://example.com/thank-you
+
+# For authentication to the OAuth2.0 service
+KYC_OAUTH2_CLIENT_ID = testcase
+KYC_OAUTH2_CLIENT_SECRET = password
+
+# Mustach template that converts OAuth2.0 data about the user
+# into GNU Taler standardized attribute data.
+#
+# This is just an example, you need to pick the right converter
+# for the provider!
+#
+KYC_OAUTH2_CONVERTER_HELPER = taler-exchange-kyc-oauth2-converter.sh
diff --git a/src/kyclogic/kyclogic-persona.conf b/src/kyclogic/kyclogic-persona.conf
new file mode 100644
index 000000000..2d52a9ee0
--- /dev/null
+++ b/src/kyclogic/kyclogic-persona.conf
@@ -0,0 +1,44 @@
+# This file is in the public domain.
+
+# FIXME: add to taler.conf man page!
+
+# Example persona provider configuration.
+
+[kyclogic-persona]
+
+# Optional authorization token for the webhook.
+# This must be the same for all uses of the
+# Persona provider, and is thus not in a
+# template-specific section.
+#WEBHOOK_AUTH_TOKEN = wbhsec_698b5a19-c790-47f6-b396-deb572ec82f9
+
+
+[kyc-provider-example-persona]
+
+COST = 42
+LOGIC = persona
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = EXAMPLE_DO_NOT_USE
+
+# How long is the KYC check valid?
+KYC_PERSONA_VALIDITY = forever
+
+# Which subdomain is used for our API?
+KYC_PERSONA_SUBDOMAIN = taler
+
+# Authentication token to use.
+KYC_PERSONA_AUTH_TOKEN = persona_sandbox_42
+
+# Program that converts Persona KYC data into the
+# GNU Taler format.
+KYC_PERSONA_CONVERTER_HELPER = taler-exchange-kyc-persona-converter.sh
+
+# Form to use.
+KYC_PERSONA_TEMPLATE_ID = itempl_Uj6Xxxxx
+
+# Where do we redirect to after KYC finished successfully.
+KYC_PERSONA_POST_URL = https://taler.net/
+
+# Salt to give to requests for idempotency.
+# Optional.
+# KYC_PERSONA_SALT = salt \ No newline at end of file
diff --git a/src/kyclogic/kyclogic.conf b/src/kyclogic/kyclogic.conf
new file mode 100644
index 000000000..eca3b24c2
--- /dev/null
+++ b/src/kyclogic/kyclogic.conf
@@ -0,0 +1,15 @@
+# This file is in the public domain.
+#
+# Sample legitimization rule set.
+
+#[kyc-legitimization-withdraw-high]
+# KYC hook is this rule is about.
+#OPERATION_TYPE = WITHDRAW
+# Which checks must be done. Give names used by providers.
+#REQUIRED_CHECKS = PHONE GOVID SSN
+# Threshold amount above which the checks are required.
+#THRESHOLD = KUDOS:100
+# Timeframe over which amounts involved in the
+# operation type are accumulated to test against
+# the threshold.
+#TIMEFRAME = 1a
diff --git a/src/kyclogic/kyclogic_api.c b/src/kyclogic/kyclogic_api.c
new file mode 100644
index 000000000..186799dbb
--- /dev/null
+++ b/src/kyclogic/kyclogic_api.c
@@ -0,0 +1,1512 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file kyclogic_api.c
+ * @brief server-side KYC API
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_kyclogic_lib.h"
+
+/**
+ * Name of the KYC check that may never be passed. Useful if some
+ * operations/amounts are categorically forbidden.
+ */
+#define KYC_CHECK_IMPOSSIBLE "impossible"
+
+/**
+ * Information about a KYC provider.
+ */
+struct TALER_KYCLOGIC_KycProvider;
+
+
+/**
+ * Abstract representation of a KYC check.
+ */
+struct TALER_KYCLOGIC_KycCheck
+{
+ /**
+ * Human-readable name given to the KYC check.
+ */
+ char *name;
+
+ /**
+ * Array of @e num_providers providers that offer this type of KYC check.
+ */
+ struct TALER_KYCLOGIC_KycProvider **providers;
+
+ /**
+ * Length of the @e providers array.
+ */
+ unsigned int num_providers;
+
+};
+
+
+struct TALER_KYCLOGIC_KycProvider
+{
+ /**
+ * Name of the provider (configuration section name).
+ */
+ const char *provider_section_name;
+
+ /**
+ * Array of @e num_checks checks performed by this provider.
+ */
+ struct TALER_KYCLOGIC_KycCheck **provided_checks;
+
+ /**
+ * Logic to run for this provider.
+ */
+ struct TALER_KYCLOGIC_Plugin *logic;
+
+ /**
+ * @e provider_section_name specific details to
+ * pass to the @e logic functions.
+ */
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Cost of running this provider's KYC.
+ */
+ unsigned long long cost;
+
+ /**
+ * Length of the @e checks array.
+ */
+ unsigned int num_checks;
+
+ /**
+ * Type of user this provider supports.
+ */
+ enum TALER_KYCLOGIC_KycUserType user_type;
+};
+
+
+/**
+ * Condition that triggers a need to perform KYC.
+ */
+struct TALER_KYCLOGIC_KycTrigger
+{
+
+ /**
+ * Timeframe to consider for computing the amount
+ * to compare against the @e limit. Zero for the
+ * wallet balance trigger (as not applicable).
+ */
+ struct GNUNET_TIME_Relative timeframe;
+
+ /**
+ * Maximum amount that can be transacted until
+ * the rule triggers.
+ */
+ struct TALER_Amount threshold;
+
+ /**
+ * Array of @e num_checks checks to apply on this trigger.
+ */
+ struct TALER_KYCLOGIC_KycCheck **required_checks;
+
+ /**
+ * Length of the @e checks array.
+ */
+ unsigned int num_checks;
+
+ /**
+ * What event is this trigger for?
+ */
+ enum TALER_KYCLOGIC_KycTriggerEvent trigger;
+
+};
+
+
+/**
+ * Array of @e num_kyc_logics KYC logic plugins we have loaded.
+ */
+static struct TALER_KYCLOGIC_Plugin **kyc_logics;
+
+/**
+ * Length of the #kyc_logics array.
+ */
+static unsigned int num_kyc_logics;
+
+/**
+ * Array of @e num_kyc_checks known types of
+ * KYC checks.
+ */
+static struct TALER_KYCLOGIC_KycCheck **kyc_checks;
+
+/**
+ * Length of the #kyc_checks array.
+ */
+static unsigned int num_kyc_checks;
+
+/**
+ * Array of configured triggers.
+ */
+static struct TALER_KYCLOGIC_KycTrigger **kyc_triggers;
+
+/**
+ * Length of the #kyc_triggers array.
+ */
+static unsigned int num_kyc_triggers;
+
+/**
+ * Array of configured providers.
+ */
+static struct TALER_KYCLOGIC_KycProvider **kyc_providers;
+
+/**
+ * Length of the #kyc_providers array.
+ */
+static unsigned int num_kyc_providers;
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_trigger_from_string (const char *trigger_s,
+ enum TALER_KYCLOGIC_KycTriggerEvent *
+ trigger)
+{
+ struct
+ {
+ const char *in;
+ enum TALER_KYCLOGIC_KycTriggerEvent out;
+ } map [] = {
+ { "withdraw", TALER_KYCLOGIC_KYC_TRIGGER_WITHDRAW },
+ { "age-withdraw", TALER_KYCLOGIC_KYC_TRIGGER_AGE_WITHDRAW },
+ { "deposit", TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT },
+ { "merge", TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE },
+ { "balance", TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE },
+ { "close", TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE },
+ { NULL, 0 }
+ };
+
+ for (unsigned int i = 0; NULL != map[i].in; i++)
+ if (0 == strcasecmp (map[i].in,
+ trigger_s))
+ {
+ *trigger = map[i].out;
+ return GNUNET_OK;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid KYC trigger `%s'\n",
+ trigger_s);
+ return GNUNET_SYSERR;
+}
+
+
+const char *
+TALER_KYCLOGIC_kyc_trigger2s (enum TALER_KYCLOGIC_KycTriggerEvent trigger)
+{
+ switch (trigger)
+ {
+ case TALER_KYCLOGIC_KYC_TRIGGER_WITHDRAW:
+ return "withdraw";
+ case TALER_KYCLOGIC_KYC_TRIGGER_AGE_WITHDRAW:
+ return "age-withdraw";
+ case TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT:
+ return "deposit";
+ case TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE:
+ return "merge";
+ case TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE:
+ return "balance";
+ case TALER_KYCLOGIC_KYC_TRIGGER_RESERVE_CLOSE:
+ return "close";
+ }
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_user_type_from_string (const char *ut_s,
+ enum TALER_KYCLOGIC_KycUserType *ut)
+{
+ struct
+ {
+ const char *in;
+ enum TALER_KYCLOGIC_KycUserType out;
+ } map [] = {
+ { "individual", TALER_KYCLOGIC_KYC_UT_INDIVIDUAL },
+ { "business", TALER_KYCLOGIC_KYC_UT_BUSINESS },
+ { NULL, 0 }
+ };
+
+ for (unsigned int i = 0; NULL != map[i].in; i++)
+ if (0 == strcasecmp (map[i].in,
+ ut_s))
+ {
+ *ut = map[i].out;
+ return GNUNET_OK;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid user type `%s'\n",
+ ut_s);
+ return GNUNET_SYSERR;
+}
+
+
+const char *
+TALER_KYCLOGIC_kyc_user_type2s (enum TALER_KYCLOGIC_KycUserType ut)
+{
+ switch (ut)
+ {
+ case TALER_KYCLOGIC_KYC_UT_INDIVIDUAL:
+ return "individual";
+ case TALER_KYCLOGIC_KYC_UT_BUSINESS:
+ return "business";
+ }
+ GNUNET_break (0);
+ return NULL;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_check_satisfiable (
+ const char *check_name)
+{
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ if (0 == strcmp (check_name,
+ kyc_checks[i]->name))
+ return GNUNET_OK;
+ if (0 == strcmp (check_name,
+ KYC_CHECK_IMPOSSIBLE))
+ return GNUNET_NO;
+ return GNUNET_SYSERR;
+}
+
+
+json_t *
+TALER_KYCLOGIC_get_satisfiable ()
+{
+ json_t *requirements;
+
+ requirements = json_array ();
+ GNUNET_assert (NULL != requirements);
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ requirements,
+ json_string (kyc_checks[i]->name)));
+ return requirements;
+}
+
+
+/**
+ * Load KYC logic plugin.
+ *
+ * @param cfg configuration to use
+ * @param name name of the plugin
+ * @return NULL on error
+ */
+static struct TALER_KYCLOGIC_Plugin *
+load_logic (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *name)
+{
+ char *lib_name;
+ struct TALER_KYCLOGIC_Plugin *plugin;
+
+ GNUNET_asprintf (&lib_name,
+ "libtaler_plugin_kyclogic_%s",
+ name);
+ for (unsigned int i = 0; i<num_kyc_logics; i++)
+ if (0 == strcmp (lib_name,
+ kyc_logics[i]->library_name))
+ {
+ GNUNET_free (lib_name);
+ return kyc_logics[i];
+ }
+ plugin = GNUNET_PLUGIN_load (lib_name,
+ (void *) cfg);
+ if (NULL == plugin)
+ {
+ GNUNET_free (lib_name);
+ return NULL;
+ }
+ plugin->library_name = lib_name;
+ plugin->name = GNUNET_strdup (name);
+ GNUNET_array_append (kyc_logics,
+ num_kyc_logics,
+ plugin);
+ return plugin;
+}
+
+
+/**
+ * Add check type to global array of checks. First checks if the type already
+ * exists, otherwise adds a new one.
+ *
+ * @param check name of the check
+ * @return pointer into the global list
+ */
+static struct TALER_KYCLOGIC_KycCheck *
+add_check (const char *check)
+{
+ struct TALER_KYCLOGIC_KycCheck *kc;
+
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ if (0 == strcasecmp (check,
+ kyc_checks[i]->name))
+ return kyc_checks[i];
+ kc = GNUNET_new (struct TALER_KYCLOGIC_KycCheck);
+ kc->name = GNUNET_strdup (check);
+ GNUNET_array_append (kyc_checks,
+ num_kyc_checks,
+ kc);
+ return kc;
+}
+
+
+/**
+ * Parse list of checks from @a checks and build an array of aliases into the
+ * global checks array in @a provided_checks.
+ *
+ * @param[in,out] checks list of checks; clobbered
+ * @param[out] p_checks where to put array of aliases
+ * @param[out] num_p_checks set to length of @a p_checks array
+ */
+static void
+add_checks (char *checks,
+ struct TALER_KYCLOGIC_KycCheck ***p_checks,
+ unsigned int *num_p_checks)
+{
+ char *sptr;
+ struct TALER_KYCLOGIC_KycCheck **rchecks = NULL;
+ unsigned int num_rchecks = 0;
+
+ for (char *tok = strtok_r (checks, " ", &sptr);
+ NULL != tok;
+ tok = strtok_r (NULL, " ", &sptr))
+ {
+ struct TALER_KYCLOGIC_KycCheck *kc;
+
+ kc = add_check (tok);
+ GNUNET_array_append (rchecks,
+ num_rchecks,
+ kc);
+ }
+ *p_checks = rchecks;
+ *num_p_checks = num_rchecks;
+}
+
+
+/**
+ * Parse configuration of a KYC provider.
+ *
+ * @param cfg configuration to parse
+ * @param section name of the section to analyze
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+add_provider (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section)
+{
+ unsigned long long cost;
+ char *logic;
+ char *ut_s;
+ enum TALER_KYCLOGIC_KycUserType ut;
+ char *checks;
+ struct TALER_KYCLOGIC_Plugin *lp;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ section,
+ "COST",
+ &cost))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "COST",
+ "number required");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "USER_TYPE",
+ &ut_s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "USER_TYPE");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_kyc_user_type_from_string (ut_s,
+ &ut))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "USER_TYPE",
+ "valid user type required");
+ GNUNET_free (ut_s);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (ut_s);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "LOGIC",
+ &logic))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "LOGIC");
+ return GNUNET_SYSERR;
+ }
+ lp = load_logic (cfg,
+ logic);
+ if (NULL == lp)
+ {
+ GNUNET_free (logic);
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "LOGIC",
+ "logic plugin could not be loaded");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (logic);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "PROVIDED_CHECKS",
+ &checks))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "PROVIDED_CHECKS");
+ return GNUNET_SYSERR;
+ }
+ {
+ struct TALER_KYCLOGIC_KycProvider *kp;
+
+ kp = GNUNET_new (struct TALER_KYCLOGIC_KycProvider);
+ kp->provider_section_name = section;
+ kp->user_type = ut;
+ kp->logic = lp;
+ kp->cost = cost;
+ add_checks (checks,
+ &kp->provided_checks,
+ &kp->num_checks);
+ GNUNET_free (checks);
+ kp->pd = lp->load_configuration (lp->cls,
+ section);
+ if (NULL == kp->pd)
+ {
+ GNUNET_free (kp);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_array_append (kyc_providers,
+ num_kyc_providers,
+ kp);
+ for (unsigned int i = 0; i<kp->num_checks; i++)
+ {
+ struct TALER_KYCLOGIC_KycCheck *kc = kp->provided_checks[i];
+
+ GNUNET_array_append (kc->providers,
+ kc->num_providers,
+ kp);
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse configuration @a cfg in section @a section for
+ * the specification of a KYC trigger.
+ *
+ * @param cfg configuration to parse
+ * @param section configuration section to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+add_trigger (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section)
+{
+ char *ot_s;
+ struct TALER_Amount threshold;
+ struct GNUNET_TIME_Relative timeframe;
+ char *checks;
+ enum TALER_KYCLOGIC_KycTriggerEvent ot;
+
+ if (GNUNET_OK !=
+ TALER_config_get_amount (cfg,
+ section,
+ "THRESHOLD",
+ &threshold))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "THRESHOLD",
+ "amount required");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "OPERATION_TYPE",
+ &ot_s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "OPERATION_TYPE");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_kyc_trigger_from_string (ot_s,
+ &ot))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "OPERATION_TYPE",
+ "valid trigger type required");
+ GNUNET_free (ot_s);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (ot_s);
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg,
+ section,
+ "TIMEFRAME",
+ &timeframe))
+ {
+ if (TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE == ot)
+ {
+ timeframe = GNUNET_TIME_UNIT_ZERO;
+ }
+ else
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "TIMEFRAME",
+ "duration required");
+ return GNUNET_SYSERR;
+ }
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ section,
+ "REQUIRED_CHECKS",
+ &checks))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "REQUIRED_CHECKS");
+ return GNUNET_SYSERR;
+ }
+
+ {
+ struct TALER_KYCLOGIC_KycTrigger *kt;
+
+ kt = GNUNET_new (struct TALER_KYCLOGIC_KycTrigger);
+ kt->timeframe = timeframe;
+ kt->threshold = threshold;
+ kt->trigger = ot;
+ add_checks (checks,
+ &kt->required_checks,
+ &kt->num_checks);
+ GNUNET_free (checks);
+ GNUNET_array_append (kyc_triggers,
+ num_kyc_triggers,
+ kt);
+ for (unsigned int i = 0; i<kt->num_checks; i++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *ck = kt->required_checks[i];
+
+ if (0 != ck->num_providers)
+ continue;
+ if (0 == strcmp (ck->name,
+ KYC_CHECK_IMPOSSIBLE))
+ continue;
+ {
+ char *msg;
+
+ GNUNET_asprintf (&msg,
+ "Required check `%s' cannot be satisfied: not provided by any provider",
+ ck->name);
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "REQUIRED_CHECKS",
+ msg);
+ GNUNET_free (msg);
+ }
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Closure for #handle_section().
+ */
+struct SectionContext
+{
+ /**
+ * Configuration to handle.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Result to return, set to false on failures.
+ */
+ bool result;
+};
+
+
+/**
+ * Function to iterate over configuration sections.
+ *
+ * @param cls a `struct SectionContext *`
+ * @param section name of the section
+ */
+static void
+handle_provider_section (void *cls,
+ const char *section)
+{
+ struct SectionContext *sc = cls;
+
+ if (0 == strncasecmp (section,
+ "kyc-provider-",
+ strlen ("kyc-provider-")))
+ {
+ if (GNUNET_OK !=
+ add_provider (sc->cfg,
+ section))
+ sc->result = false;
+ return;
+ }
+}
+
+
+/**
+ * Function to iterate over configuration sections.
+ *
+ * @param cls a `struct SectionContext *`
+ * @param section name of the section
+ */
+static void
+handle_trigger_section (void *cls,
+ const char *section)
+{
+ struct SectionContext *sc = cls;
+
+ if (0 == strncasecmp (section,
+ "kyc-legitimization-",
+ strlen ("kyc-legitimization-")))
+ {
+ if (GNUNET_OK !=
+ add_trigger (sc->cfg,
+ section))
+ sc->result = false;
+ return;
+ }
+}
+
+
+/**
+ * Comparator for qsort. Compares two triggers
+ * by timeframe to sort triggers by time.
+ *
+ * @param p1 first trigger to compare
+ * @param p2 second trigger to compare
+ * @return -1 if p1 < p2, 0 if p1==p2, 1 if p1 > p2.
+ */
+static int
+sort_by_timeframe (const void *p1,
+ const void *p2)
+{
+ struct TALER_KYCLOGIC_KycTrigger **t1 = (struct
+ TALER_KYCLOGIC_KycTrigger **) p1;
+ struct TALER_KYCLOGIC_KycTrigger **t2 = (struct
+ TALER_KYCLOGIC_KycTrigger **) p2;
+
+ if (GNUNET_TIME_relative_cmp ((*t1)->timeframe,
+ <,
+ (*t2)->timeframe))
+ return -1;
+ if (GNUNET_TIME_relative_cmp ((*t1)->timeframe,
+ >,
+ (*t2)->timeframe))
+ return 1;
+ return 0;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_kyc_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ struct SectionContext sc = {
+ .cfg = cfg,
+ .result = true
+ };
+
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &handle_provider_section,
+ &sc);
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &handle_trigger_section,
+ &sc);
+ if (! sc.result)
+ {
+ TALER_KYCLOGIC_kyc_done ();
+ return GNUNET_SYSERR;
+ }
+
+ /* sanity check: ensure at least one provider exists
+ for any trigger and indidivual or business. */
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ if (0 == kyc_checks[i]->num_providers)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No provider available for required KYC check `%s'\n",
+ kyc_checks[i]->name);
+ TALER_KYCLOGIC_kyc_done ();
+ return GNUNET_SYSERR;
+ }
+ if (0 != num_kyc_triggers)
+ qsort (kyc_triggers,
+ num_kyc_triggers,
+ sizeof (struct TALER_KYCLOGIC_KycTrigger *),
+ &sort_by_timeframe);
+ return GNUNET_OK;
+}
+
+
+void
+TALER_KYCLOGIC_kyc_done (void)
+{
+ for (unsigned int i = 0; i<num_kyc_triggers; i++)
+ {
+ struct TALER_KYCLOGIC_KycTrigger *kt = kyc_triggers[i];
+
+ GNUNET_array_grow (kt->required_checks,
+ kt->num_checks,
+ 0);
+ GNUNET_free (kt);
+ }
+ GNUNET_array_grow (kyc_triggers,
+ num_kyc_triggers,
+ 0);
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+
+ kp->logic->unload_configuration (kp->pd);
+ GNUNET_array_grow (kp->provided_checks,
+ kp->num_checks,
+ 0);
+ GNUNET_free (kp);
+ }
+ GNUNET_array_grow (kyc_providers,
+ num_kyc_providers,
+ 0);
+ for (unsigned int i = 0; i<num_kyc_logics; i++)
+ {
+ struct TALER_KYCLOGIC_Plugin *lp = kyc_logics[i];
+ char *lib_name = lp->library_name;
+
+ GNUNET_free (lp->name);
+ GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name,
+ lp));
+ GNUNET_free (lib_name);
+ }
+ GNUNET_array_grow (kyc_logics,
+ num_kyc_logics,
+ 0);
+ for (unsigned int i = 0; i<num_kyc_checks; i++)
+ {
+ struct TALER_KYCLOGIC_KycCheck *kc = kyc_checks[i];
+
+ GNUNET_array_grow (kc->providers,
+ kc->num_providers,
+ 0);
+ GNUNET_free (kc->name);
+ GNUNET_free (kc);
+ }
+ GNUNET_array_grow (kyc_checks,
+ num_kyc_checks,
+ 0);
+}
+
+
+/**
+ * Closure for the #eval_trigger().
+ */
+struct ThresholdTestContext
+{
+ /**
+ * Total amount so far.
+ */
+ struct TALER_Amount total;
+
+ /**
+ * Trigger event to evaluate triggers of.
+ */
+ enum TALER_KYCLOGIC_KycTriggerEvent event;
+
+ /**
+ * Offset in the triggers array where we need to start
+ * checking for triggers. All trigges below this
+ * offset were already hit.
+ */
+ unsigned int start;
+
+ /**
+ * Array of checks needed so far.
+ */
+ struct TALER_KYCLOGIC_KycCheck **needed;
+
+ /**
+ * Pointer to number of entries used in @a needed.
+ */
+ unsigned int *needed_cnt;
+
+ /**
+ * Has @e total been initialized yet?
+ */
+ bool have_total;
+};
+
+
+/**
+ * Function called on each @a amount that was found to
+ * be relevant for a KYC check.
+ *
+ * @param cls closure to allow the KYC module to
+ * total up amounts and evaluate rules
+ * @param amount encountered transaction amount
+ * @param date when was the amount encountered
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to abort iteration
+ * #GNUNET_SYSERR on internal error (also abort itaration)
+ */
+static enum GNUNET_GenericReturnValue
+eval_trigger (void *cls,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Absolute date)
+{
+ struct ThresholdTestContext *ttc = cls;
+ struct GNUNET_TIME_Relative duration;
+ bool bump = true;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check with new amount %s\n",
+ TALER_amount2s (amount));
+ duration = GNUNET_TIME_absolute_get_duration (date);
+ if (ttc->have_total)
+ {
+ if (0 >
+ TALER_amount_add (&ttc->total,
+ &ttc->total,
+ amount))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ else
+ {
+ ttc->total = *amount;
+ ttc->have_total = true;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check: new total is %s\n",
+ TALER_amount2s (&ttc->total));
+ for (unsigned int i = ttc->start; i<num_kyc_triggers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycTrigger *kt = kyc_triggers[i];
+
+ if (ttc->event != kt->trigger)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check #%u: trigger type does not match\n",
+ i);
+ continue;
+ }
+ duration = GNUNET_TIME_relative_max (duration,
+ kt->timeframe);
+ if (GNUNET_TIME_relative_cmp (kt->timeframe,
+ >,
+ duration))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check #%u: amount is beyond time limit\n",
+ i);
+ if (bump)
+ ttc->start = i;
+ return GNUNET_OK;
+ }
+ if (-1 ==
+ TALER_amount_cmp (&ttc->total,
+ &kt->threshold))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check #%u: amount is below threshold\n",
+ i);
+ if (bump)
+ ttc->start = i;
+ bump = false;
+ continue; /* amount too low to trigger */
+ }
+ /* add check to list of required checks, unless
+ already present... */
+ for (unsigned int j = 0; j<kt->num_checks; j++)
+ {
+ struct TALER_KYCLOGIC_KycCheck *rc = kt->required_checks[j];
+ bool found = false;
+
+ for (unsigned int k = 0; k<*ttc->needed_cnt; k++)
+ if (ttc->needed[k] == rc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC rule #%u already listed\n",
+ j);
+ found = true;
+ break;
+ }
+ if (! found)
+ {
+ ttc->needed[*ttc->needed_cnt] = rc;
+ (*ttc->needed_cnt)++;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC check #%u (%s) is applicable, %u checks needed so far\n",
+ i,
+ ttc->needed[(*ttc->needed_cnt) - 1]->name,
+ *ttc->needed_cnt);
+ }
+ if (bump)
+ return GNUNET_NO; /* we hit all possible triggers! */
+ return GNUNET_OK;
+}
+
+
+/**
+ * Closure for the #remove_satisfied().
+ */
+struct RemoveContext
+{
+
+ /**
+ * Array of checks needed so far.
+ */
+ struct TALER_KYCLOGIC_KycCheck **needed;
+
+ /**
+ * Pointer to number of entries used in @a needed.
+ */
+ unsigned int *needed_cnt;
+
+ /**
+ * Object with information about collected KYC data.
+ */
+ json_t *kyc_details;
+};
+
+
+/**
+ * Remove all checks satisfied by @a provider_name from
+ * our list of checks.
+ *
+ * @param cls a `struct RemoveContext`
+ * @param provider_name section name of provider that was already run previously
+ */
+static void
+remove_satisfied (void *cls,
+ const char *provider_name)
+{
+ struct RemoveContext *rc = cls;
+
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+
+ if (0 != strcasecmp (provider_name,
+ kp->provider_section_name))
+ continue;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Provider `%s' satisfied\n",
+ provider_name);
+ for (unsigned int j = 0; j<kp->num_checks; j++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *kc = kp->provided_checks[j];
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Provider satisfies check `%s'\n",
+ kc->name);
+ if (NULL != rc->kyc_details)
+ {
+ GNUNET_assert (0 ==
+ json_object_set_new (
+ rc->kyc_details,
+ kc->name,
+ json_object ()));
+ }
+ for (unsigned int k = 0; k<*rc->needed_cnt; k++)
+ if (kc == rc->needed[k])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Removing check `%s' from list\n",
+ kc->name);
+ rc->needed[k] = rc->needed[*rc->needed_cnt - 1];
+ (*rc->needed_cnt)--;
+ if (0 == *rc->needed_cnt)
+ return; /* for sure finished */
+ break;
+ }
+ }
+ break;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_KYCLOGIC_kyc_test_required (enum TALER_KYCLOGIC_KycTriggerEvent event,
+ const struct TALER_PaytoHashP *h_payto,
+ TALER_KYCLOGIC_KycSatisfiedIterator ki,
+ void *ki_cls,
+ TALER_KYCLOGIC_KycAmountIterator ai,
+ void *ai_cls,
+ char **required)
+{
+ struct TALER_KYCLOGIC_KycCheck *needed[num_kyc_checks];
+ unsigned int needed_cnt = 0;
+ char *ret;
+ struct GNUNET_TIME_Relative timeframe;
+
+ timeframe = GNUNET_TIME_UNIT_ZERO;
+ for (unsigned int i = 0; i<num_kyc_triggers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycTrigger *kt = kyc_triggers[i];
+
+ if (event != kt->trigger)
+ continue;
+ timeframe = GNUNET_TIME_relative_max (timeframe,
+ kt->timeframe);
+ }
+ {
+ struct GNUNET_TIME_Absolute now;
+ struct ThresholdTestContext ttc = {
+ .event = event,
+ .needed = needed,
+ .needed_cnt = &needed_cnt
+ };
+
+ now = GNUNET_TIME_absolute_get ();
+ ai (ai_cls,
+ GNUNET_TIME_absolute_subtract (now,
+ timeframe),
+ &eval_trigger,
+ &ttc);
+ }
+ if (0 == needed_cnt)
+ {
+ *required = NULL;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ timeframe = GNUNET_TIME_UNIT_ZERO;
+ for (unsigned int i = 0; i<num_kyc_triggers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycTrigger *kt = kyc_triggers[i];
+
+ if (event != kt->trigger)
+ continue;
+ timeframe = GNUNET_TIME_relative_max (timeframe,
+ kt->timeframe);
+ }
+ {
+ struct GNUNET_TIME_Absolute now;
+ struct ThresholdTestContext ttc = {
+ .event = event,
+ .needed = needed,
+ .needed_cnt = &needed_cnt
+ };
+
+ now = GNUNET_TIME_absolute_get ();
+ ai (ai_cls,
+ GNUNET_TIME_absolute_subtract (now,
+ timeframe),
+ &eval_trigger,
+ &ttc);
+ }
+ if (0 == needed_cnt)
+ {
+ *required = NULL;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ {
+ struct RemoveContext rc = {
+ .needed = needed,
+ .needed_cnt = &needed_cnt
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Check what provider checks are already satisfied for h_payto (with
+ database), remove those from the 'needed' array. */
+ qs = ki (ki_cls,
+ h_payto,
+ &remove_satisfied,
+ &rc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ }
+ if (0 == needed_cnt)
+ {
+ *required = NULL;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ {
+ struct RemoveContext rc = {
+ .needed = needed,
+ .needed_cnt = &needed_cnt
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ /* Check what provider checks are already satisfied for h_payto (with
+ database), remove those from the 'needed' array. */
+ qs = ki (ki_cls,
+ h_payto,
+ &remove_satisfied,
+ &rc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ return qs;
+ }
+ }
+ if (0 == needed_cnt)
+ {
+ *required = NULL;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ ret = NULL;
+ for (unsigned int k = 0; k<needed_cnt; k++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *kc = needed[k];
+
+ if (NULL == ret)
+ {
+ ret = GNUNET_strdup (kc->name);
+ }
+ else /* append */
+ {
+ char *tmp = ret;
+
+ GNUNET_asprintf (&ret,
+ "%s %s",
+ tmp,
+ kc->name);
+ GNUNET_free (tmp);
+ }
+ }
+ *required = ret;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+void
+TALER_KYCLOGIC_kyc_get_details (
+ const char *logic_name,
+ TALER_KYCLOGIC_DetailsCallback cb,
+ void *cb_cls)
+{
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+
+ if (0 !=
+ strcmp (kp->logic->name,
+ logic_name))
+ continue;
+ if (GNUNET_OK !=
+ cb (cb_cls,
+ kp->pd,
+ kp->logic->cls))
+ return;
+ }
+}
+
+
+enum GNUNET_DB_QueryStatus
+TALER_KYCLOGIC_check_satisfied (char **requirements,
+ const struct TALER_PaytoHashP *h_payto,
+ json_t **kyc_details,
+ TALER_KYCLOGIC_KycSatisfiedIterator ki,
+ void *ki_cls,
+ bool *satisfied)
+{
+ struct TALER_KYCLOGIC_KycCheck *needed[num_kyc_checks];
+ unsigned int needed_cnt = 0;
+
+ if (NULL == requirements)
+ {
+ *satisfied = true;
+ return GNUNET_DB_STATUS_SUCCESS_NO_RESULTS;
+ }
+ {
+ char *req = *requirements;
+
+ for (const char *tok = strtok (req, " ");
+ NULL != tok;
+ tok = strtok (NULL, " "))
+ needed[needed_cnt++] = add_check (tok);
+ GNUNET_free (req);
+ *requirements = NULL;
+ }
+
+ {
+ struct RemoveContext rc = {
+ .needed = needed,
+ .needed_cnt = &needed_cnt,
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ rc.kyc_details = json_object ();
+ GNUNET_assert (NULL != rc.kyc_details);
+
+ /* Check what provider checks are already satisfied for h_payto (with
+ database), remove those from the 'needed' array. */
+ qs = ki (ki_cls,
+ h_payto,
+ &remove_satisfied,
+ &rc);
+ if (qs < 0)
+ {
+ GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+ *satisfied = false;
+ return qs;
+ }
+ if (0 != needed_cnt)
+ {
+ json_decref (rc.kyc_details);
+ *kyc_details = NULL;
+ }
+ else
+ {
+ *kyc_details = rc.kyc_details;
+ }
+ }
+ *satisfied = (0 == needed_cnt);
+
+ {
+ char *res = NULL;
+
+ for (unsigned int i = 0; i<needed_cnt; i++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *need = needed[i];
+
+ if (NULL == res)
+ {
+ res = GNUNET_strdup (need->name);
+ }
+ else
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp,
+ "%s %s",
+ res,
+ need->name);
+ GNUNET_free (res);
+ res = tmp;
+ }
+ }
+ *requirements = res;
+ }
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_requirements_to_logic (const char *requirements,
+ enum TALER_KYCLOGIC_KycUserType ut,
+ struct TALER_KYCLOGIC_Plugin **plugin,
+ struct TALER_KYCLOGIC_ProviderDetails **pd,
+ const char **configuration_section)
+{
+ struct TALER_KYCLOGIC_KycCheck *needed[num_kyc_checks];
+ unsigned int needed_cnt = 0;
+ unsigned long long min_cost = ULLONG_MAX;
+ unsigned int max_checks = 0;
+ const struct TALER_KYCLOGIC_KycProvider *kp_best = NULL;
+
+ if (NULL == requirements)
+ return GNUNET_NO;
+ {
+ char *req = GNUNET_strdup (requirements);
+
+ for (const char *tok = strtok (req, " ");
+ NULL != tok;
+ tok = strtok (NULL, " "))
+ needed[needed_cnt++] = add_check (tok);
+ GNUNET_free (req);
+ }
+
+ /* Count maximum number of remaining checks covered by any
+ provider */
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+ unsigned int matched = 0;
+
+ if (kp->user_type != ut)
+ continue;
+ for (unsigned int j = 0; j<kp->num_checks; j++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *kc = kp->provided_checks[j];
+
+ for (unsigned int k = 0; k<needed_cnt; k++)
+ if (kc == needed[k])
+ {
+ matched++;
+ break;
+ }
+ }
+ max_checks = GNUNET_MAX (max_checks,
+ matched);
+ }
+ if (0 == max_checks)
+ return GNUNET_SYSERR;
+
+ /* Find min-cost provider covering max_checks. */
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+ unsigned int matched = 0;
+
+ if (kp->user_type != ut)
+ continue;
+ for (unsigned int j = 0; j<kp->num_checks; j++)
+ {
+ const struct TALER_KYCLOGIC_KycCheck *kc = kp->provided_checks[j];
+
+ for (unsigned int k = 0; k<needed_cnt; k++)
+ if (kc == needed[k])
+ {
+ matched++;
+ break;
+ }
+ }
+ if ( (max_checks == matched) &&
+ (kp->cost < min_cost) )
+ {
+ min_cost = kp->cost;
+ kp_best = kp;
+ }
+ }
+ GNUNET_assert (NULL != kp_best);
+ *plugin = kp_best->logic;
+ *pd = kp_best->pd;
+ *configuration_section = kp_best->provider_section_name;
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_KYCLOGIC_lookup_logic (const char *name,
+ struct TALER_KYCLOGIC_Plugin **plugin,
+ struct TALER_KYCLOGIC_ProviderDetails **pd,
+ const char **provider_section)
+{
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+
+ if (0 !=
+ strcasecmp (name,
+ kp->provider_section_name))
+ continue;
+ *plugin = kp->logic;
+ *pd = kp->pd;
+ *provider_section = kp->provider_section_name;
+ return GNUNET_OK;
+ }
+ for (unsigned int i = 0; i<num_kyc_logics; i++)
+ {
+ struct TALER_KYCLOGIC_Plugin *logic = kyc_logics[i];
+
+ if (0 !=
+ strcasecmp (logic->name,
+ name))
+ continue;
+ *plugin = logic;
+ *pd = NULL;
+ *provider_section = NULL;
+ return GNUNET_OK;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Provider `%s' unknown\n",
+ name);
+ return GNUNET_SYSERR;
+}
+
+
+void
+TALER_KYCLOGIC_kyc_iterate_thresholds (
+ enum TALER_KYCLOGIC_KycTriggerEvent event,
+ TALER_KYCLOGIC_KycThresholdIterator it,
+ void *it_cls)
+{
+ for (unsigned int i = 0; i<num_kyc_triggers; i++)
+ {
+ const struct TALER_KYCLOGIC_KycTrigger *kt = kyc_triggers[i];
+
+ if (event != kt->trigger)
+ continue;
+ it (it_cls,
+ &kt->threshold);
+ }
+}
+
+
+void
+TALER_KYCLOGIC_lookup_checks (const char *section_name,
+ unsigned int *num_checks,
+ char ***provided_checks)
+{
+ *num_checks = 0;
+ *provided_checks = NULL;
+ for (unsigned int i = 0; i<num_kyc_providers; i++)
+ {
+ struct TALER_KYCLOGIC_KycProvider *kp = kyc_providers[i];
+
+ if (0 !=
+ strcasecmp (section_name,
+ kp->provider_section_name))
+ continue;
+ *num_checks = kp->num_checks;
+ if (0 != kp->num_checks)
+ {
+ char **pc = GNUNET_new_array (kp->num_checks,
+ char *);
+ for (unsigned int i = 0; i<kp->num_checks; i++)
+ pc[i] = GNUNET_strdup (kp->provided_checks[i]->name);
+ *provided_checks = pc;
+ }
+ return;
+ }
+}
+
+
+/* end of taler-exchange-httpd_kyc.c */
diff --git a/src/kyclogic/plugin_kyclogic_kycaid.c b/src/kyclogic/plugin_kyclogic_kycaid.c
new file mode 100644
index 000000000..243ff7c34
--- /dev/null
+++ b/src/kyclogic/plugin_kyclogic_kycaid.c
@@ -0,0 +1,1480 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2022--2024 Taler Systems SA
+
+ Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Taler; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file plugin_kyclogic_kycaid.c
+ * @brief kycaid for an authentication flow logic
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_attributes.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_kyclogic_plugin.h"
+#include "taler_mhd_lib.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+#include "taler_templating_lib.h"
+#include <regex.h>
+#include "taler_util.h"
+
+
+/**
+ * Saves the state of a plugin.
+ */
+struct PluginState
+{
+
+ /**
+ * Our base URL.
+ */
+ char *exchange_base_url;
+
+ /**
+ * Our global configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Context for CURL operations (useful to the event loop)
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * Context for integrating @e curl_ctx with the
+ * GNUnet event loop.
+ */
+ struct GNUNET_CURL_RescheduleContext *curl_rc;
+
+};
+
+
+/**
+ * Keeps the plugin-specific state for
+ * a given configuration section.
+ */
+struct TALER_KYCLOGIC_ProviderDetails
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Configuration section that configured us.
+ */
+ char *section;
+
+ /**
+ * Authorization token to use when talking
+ * to the service.
+ */
+ char *auth_token;
+
+ /**
+ * Form ID for the KYC check to perform.
+ */
+ char *form_id;
+
+ /**
+ * Helper binary to convert attributes returned by
+ * KYCAID into our internal format.
+ */
+ char *conversion_helper;
+
+ /**
+ * Validity time for a successful KYC process.
+ */
+ struct GNUNET_TIME_Relative validity;
+
+ /**
+ * Curl-ready authentication header to use.
+ */
+ struct curl_slist *slist;
+
+};
+
+
+/**
+ * Handle for an initiation operation.
+ */
+struct TALER_KYCLOGIC_InitiateHandle
+{
+
+ /**
+ * Hash of the payto:// URI we are initiating
+ * the KYC for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * UUID being checked.
+ */
+ uint64_t legitimization_uuid;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_InitiateCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Context for #TEH_curl_easy_post(). Keeps the data that must
+ * persist for Curl to make the upload.
+ */
+ struct TALER_CURL_PostContext ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * URL of the cURL request.
+ */
+ char *url;
+
+};
+
+
+/**
+ * Handle for an KYC proof operation.
+ */
+struct TALER_KYCLOGIC_ProofHandle
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_ProofCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+};
+
+
+/**
+ * Handle for an KYC Web hook operation.
+ */
+struct TALER_KYCLOGIC_WebhookHandle
+{
+
+ /**
+ * Continuation to call when done.
+ */
+ TALER_KYCLOGIC_WebhookCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Handle to helper process to extract attributes
+ * we care about.
+ */
+ struct TALER_JSON_ExternalConversion *econ;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * JSON response we got back, or NULL for none.
+ */
+ json_t *json_response;
+
+ /**
+ * Verification ID from the service.
+ */
+ char *verification_id;
+
+ /**
+ * Applicant ID from the service.
+ */
+ char *applicant_id;
+
+ /**
+ * URL of the cURL request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Response to return asynchronously.
+ */
+ struct MHD_Response *resp;
+
+ /**
+ * Our account ID.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Row in legitimizations for the given
+ * @e verification_id.
+ */
+ uint64_t process_row;
+
+ /**
+ * HTTP response code we got from KYCAID.
+ */
+ unsigned int kycaid_response_code;
+
+ /**
+ * HTTP response code to return asynchronously.
+ */
+ unsigned int response_code;
+};
+
+
+/**
+ * Release configuration resources previously loaded
+ *
+ * @param[in] pd configuration to release
+ */
+static void
+kycaid_unload_configuration (struct TALER_KYCLOGIC_ProviderDetails *pd)
+{
+ curl_slist_free_all (pd->slist);
+ GNUNET_free (pd->conversion_helper);
+ GNUNET_free (pd->auth_token);
+ GNUNET_free (pd->form_id);
+ GNUNET_free (pd->section);
+ GNUNET_free (pd);
+}
+
+
+/**
+ * Load the configuration of the KYC provider.
+ *
+ * @param cls closure
+ * @param provider_section_name configuration section to parse
+ * @return NULL if configuration is invalid
+ */
+static struct TALER_KYCLOGIC_ProviderDetails *
+kycaid_load_configuration (void *cls,
+ const char *provider_section_name)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ pd = GNUNET_new (struct TALER_KYCLOGIC_ProviderDetails);
+ pd->ps = ps;
+ pd->section = GNUNET_strdup (provider_section_name);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (ps->cfg,
+ provider_section_name,
+ "KYC_KYCAID_VALIDITY",
+ &pd->validity))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_KYCAID_VALIDITY");
+ kycaid_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_KYCAID_AUTH_TOKEN",
+ &pd->auth_token))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_KYCAID_AUTH_TOKEN");
+ kycaid_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_KYCAID_FORM_ID",
+ &pd->form_id))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_KYCAID_FORM_ID");
+ kycaid_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_KYCAID_CONVERTER_HELPER",
+ &pd->conversion_helper))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_KYCAID_CONVERTER_HELPER");
+ kycaid_unload_configuration (pd);
+ return NULL;
+ }
+ {
+ char *auth;
+
+ GNUNET_asprintf (&auth,
+ "%s: Token %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ pd->auth_token);
+ pd->slist = curl_slist_append (NULL,
+ auth);
+ GNUNET_free (auth);
+ }
+ return pd;
+}
+
+
+/**
+ * Cancel KYC check initiation.
+ *
+ * @param[in] ih handle of operation to cancel
+ */
+static void
+kycaid_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih)
+{
+ if (NULL != ih->job)
+ {
+ GNUNET_CURL_job_cancel (ih->job);
+ ih->job = NULL;
+ }
+ GNUNET_free (ih->url);
+ TALER_curl_easy_post_finished (&ih->ctx);
+ GNUNET_free (ih);
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP "/forms/{form_id}/urls" request.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_InitiateHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_initiate_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih = cls;
+ const json_t *j = response;
+
+ ih->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char *verification_id;
+ const char *form_url;
+ const char *form_id;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("verification_id",
+ &verification_id),
+ GNUNET_JSON_spec_string ("form_url",
+ &form_url),
+ GNUNET_JSON_spec_string ("form_id",
+ &form_id),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Started new verification `%s' using form %s\n",
+ verification_id,
+ form_id);
+ ih->cb (ih->cb_cls,
+ TALER_EC_NONE,
+ form_url,
+ NULL, /* no provider_user_id */
+ verification_id,
+ NULL /* no error */);
+ GNUNET_JSON_parse_free (spec);
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYCAID failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_BUG,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_ACCESS_REFUSED,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ case MHD_HTTP_REQUEST_TIMEOUT:
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_TIMEOUT,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ case MHD_HTTP_UNPROCESSABLE_ENTITY: /* validation */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYCAID failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ case MHD_HTTP_TOO_MANY_REQUESTS:
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_RATE_LIMIT_EXCEEDED,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected KYCAID response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ json_string_value (json_object_get (j,
+ "type")));
+ break;
+ }
+ kycaid_initiate_cancel (ih);
+}
+
+
+/**
+ * Initiate KYC check.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param account_id which account to trigger process for
+ * @param legitimization_uuid unique ID for the legitimization process
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_InitiateHandle *
+kycaid_initiate (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t legitimization_uuid,
+ TALER_KYCLOGIC_InitiateCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_InitiateHandle *ih;
+ json_t *body;
+ CURL *eh;
+
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ ih = GNUNET_new (struct TALER_KYCLOGIC_InitiateHandle);
+ ih->legitimization_uuid = legitimization_uuid;
+ ih->cb = cb;
+ ih->cb_cls = cb_cls;
+ ih->h_payto = *account_id;
+ ih->pd = pd;
+ GNUNET_asprintf (&ih->url,
+ "https://api.kycaid.com/forms/%s/urls",
+ pd->form_id);
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data64_auto ("external_applicant_id",
+ account_id)
+ );
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 0));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 1L));
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ ih->url));
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&ih->ctx,
+ eh,
+ body))
+ {
+ GNUNET_break (0);
+ GNUNET_free (ih->url);
+ GNUNET_free (ih);
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ return NULL;
+ }
+ json_decref (body);
+ ih->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ ih->ctx.headers,
+ &handle_initiate_finished,
+ ih);
+ GNUNET_CURL_extend_headers (ih->job,
+ pd->slist);
+ return ih;
+}
+
+
+/**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+static void
+kycaid_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
+{
+ if (NULL != ph->task)
+ {
+ GNUNET_SCHEDULER_cancel (ph->task);
+ ph->task = NULL;
+ }
+ GNUNET_free (ph);
+}
+
+
+/**
+ * Call @a ph callback with HTTP error response.
+ *
+ * @param cls proof handle to generate reply for
+ */
+static void
+proof_reply (void *cls)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ struct MHD_Response *resp;
+ enum GNUNET_GenericReturnValue ret;
+ json_t *body;
+ unsigned int http_status;
+
+ http_status = MHD_HTTP_BAD_REQUEST;
+ body = GNUNET_JSON_PACK (
+ TALER_JSON_pack_ec (TALER_EC_GENERIC_ENDPOINT_UNKNOWN));
+ GNUNET_assert (NULL != body);
+ ret = TALER_TEMPLATING_build (ph->connection,
+ &http_status,
+ "kycaid-invalid-request",
+ NULL,
+ NULL,
+ body,
+ &resp);
+ json_decref (body);
+ GNUNET_break (GNUNET_SYSERR != ret);
+ ph->cb (ph->cb_cls,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ NULL, /* user id */
+ NULL, /* provider legi ID */
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL, /* attributes */
+ http_status,
+ resp);
+}
+
+
+/**
+ * Check KYC status and return status to human. Not
+ * used by KYC AID!
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param connection MHD connection object (for HTTP headers)
+ * @param account_id which account to trigger process for
+ * @param process_row row in the legitimization processes table the legitimization is for
+ * @param provider_user_id user ID (or NULL) the proof is for
+ * @param provider_legitimization_id legitimization ID the proof is for
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_ProofHandle *
+kycaid_proof (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ TALER_KYCLOGIC_ProofCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProofHandle *ph;
+
+ ph = GNUNET_new (struct TALER_KYCLOGIC_ProofHandle);
+ ph->ps = ps;
+ ph->pd = pd;
+ ph->cb = cb;
+ ph->cb_cls = cb_cls;
+ ph->connection = connection;
+ ph->task = GNUNET_SCHEDULER_add_now (&proof_reply,
+ ph);
+ return ph;
+}
+
+
+/**
+ * Cancel KYC webhook execution.
+ *
+ * @param[in] wh handle of operation to cancel
+ */
+static void
+kycaid_webhook_cancel (struct TALER_KYCLOGIC_WebhookHandle *wh)
+{
+ if (NULL != wh->task)
+ {
+ GNUNET_SCHEDULER_cancel (wh->task);
+ wh->task = NULL;
+ }
+ if (NULL != wh->econ)
+ {
+ TALER_JSON_external_conversion_stop (wh->econ);
+ wh->econ = NULL;
+ }
+ if (NULL != wh->job)
+ {
+ GNUNET_CURL_job_cancel (wh->job);
+ wh->job = NULL;
+ }
+ if (NULL != wh->json_response)
+ {
+ json_decref (wh->json_response);
+ wh->json_response = NULL;
+ }
+ GNUNET_free (wh->verification_id);
+ GNUNET_free (wh->applicant_id);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+}
+
+
+/**
+ * Extract KYC failure reasons and log those
+ *
+ * @param verifications JSON object with failure details
+ */
+static void
+log_failure (const json_t *verifications)
+{
+ const json_t *member;
+ const char *name;
+
+ json_object_foreach ((json_t *) verifications, name, member)
+ {
+ bool iverified;
+ const char *comment;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_bool ("verified",
+ &iverified),
+ GNUNET_JSON_spec_string ("comment",
+ &comment),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (member,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (member,
+ stderr,
+ JSON_INDENT (2));
+ continue;
+ }
+ if (iverified)
+ continue;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC verification of attribute `%s' failed: %s\n",
+ name,
+ comment);
+ }
+}
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure our `struct TALER_KYCLOGIC_WebhookHandle *`
+ * @param status_type how did the process die
+ * @param code termination status code from the process
+ * @param result converted attribute data, NULL on failure
+ */
+static void
+webhook_conversion_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *result)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+ struct GNUNET_TIME_Absolute expiration;
+ struct MHD_Response *resp;
+
+ wh->econ = NULL;
+ if ( (0 == code) &&
+ (NULL == result) )
+ {
+ /* No result, but *our helper* was OK => bad input */
+ GNUNET_break_op (0);
+ json_dumpf (wh->json_response,
+ stderr,
+ JSON_INDENT (2));
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ wh->kycaid_response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) wh->json_response));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_BAD_GATEWAY,
+ resp);
+ kycaid_webhook_cancel (wh);
+ return;
+ }
+ if (NULL == result)
+ {
+ /* Failure in our helper */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Helper exited with status code %d\n",
+ (int) code);
+ json_dumpf (wh->json_response,
+ stderr,
+ JSON_INDENT (2));
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ wh->kycaid_response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) wh->json_response));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_BAD_GATEWAY,
+ resp);
+ kycaid_webhook_cancel (wh);
+ return;
+ }
+ expiration = GNUNET_TIME_relative_to_absolute (wh->pd->validity);
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_SUCCESS,
+ expiration,
+ result,
+ MHD_HTTP_NO_CONTENT,
+ resp);
+ kycaid_webhook_cancel (wh);
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP "/applicants/{verification_id}" request.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_WebhookHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_webhook_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+ const json_t *j = response;
+ struct MHD_Response *resp;
+
+ wh->job = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Webhook returned with HTTP status %u\n",
+ (unsigned int) response_code);
+ wh->kycaid_response_code = response_code;
+ wh->json_response = json_incref ((json_t *) j);
+ switch (response_code)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char *profile_status;
+
+ profile_status = json_string_value (
+ json_object_get (
+ j,
+ "profile_status"));
+ if (0 != strcasecmp ("valid",
+ profile_status))
+ {
+ enum TALER_KYCLOGIC_KycStatus ks;
+
+ ks = (0 == strcasecmp ("pending",
+ profile_status))
+ ? TALER_KYCLOGIC_STATUS_PENDING
+ : TALER_KYCLOGIC_STATUS_USER_ABORTED;
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ ks,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ NULL,
+ MHD_HTTP_NO_CONTENT,
+ resp);
+ break;
+ }
+ wh->econ
+ = TALER_JSON_external_conversion_start (
+ j,
+ &webhook_conversion_cb,
+ wh,
+ wh->pd->conversion_helper,
+ wh->pd->conversion_helper,
+ "-a",
+ wh->pd->auth_token,
+ NULL);
+ if (NULL == wh->econ)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start KYCAID conversion helper `%s'\n",
+ wh->pd->conversion_helper);
+ resp = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_GENERIC_KYC_CONVERTER_FAILED,
+ NULL);
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_INTERNAL_ERROR,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ resp);
+ break;
+ }
+ return;
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYCAID failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ resp);
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_NETWORK_AUTHENTICATION_REQUIRED,
+ resp);
+ break;
+ case MHD_HTTP_REQUEST_TIMEOUT:
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_GATEWAY_TIMEOUT,
+ resp);
+ break;
+ case MHD_HTTP_UNPROCESSABLE_ENTITY: /* validation */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYCAID failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_BAD_GATEWAY,
+ resp);
+ break;
+ case MHD_HTTP_TOO_MANY_REQUESTS:
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_SERVICE_UNAVAILABLE,
+ resp);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_BAD_GATEWAY,
+ resp);
+ break;
+ default:
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("kycaid_http_status",
+ response_code),
+ GNUNET_JSON_pack_object_incref ("kycaid_body",
+ (json_t *) j));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected KYCAID response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id,
+ wh->verification_id,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ MHD_HTTP_BAD_GATEWAY,
+ resp);
+ break;
+ }
+ kycaid_webhook_cancel (wh);
+}
+
+
+/**
+ * Asynchronously return a reply for the webhook.
+ *
+ * @param cls a `struct TALER_KYCLOGIC_WebhookHandle *`
+ */
+static void
+async_webhook_reply (void *cls)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+
+ wh->task = NULL;
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ (0 == wh->process_row)
+ ? NULL
+ : &wh->h_payto,
+ wh->pd->section,
+ wh->applicant_id, /* provider user ID */
+ wh->verification_id, /* provider legi ID */
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ wh->response_code,
+ wh->resp);
+ kycaid_webhook_cancel (wh);
+}
+
+
+/**
+ * Check KYC status and return result for Webhook. We do NOT implement the
+ * authentication check proposed by the KYCAID documentation, as it would
+ * allow an attacker who learns the access token to easily bypass the KYC
+ * checks. Instead, we insist on explicitly requesting the KYC status from the
+ * provider (at least on success).
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param plc callback to lookup accounts with
+ * @param plc_cls closure for @a plc
+ * @param http_method HTTP method used for the webhook
+ * @param url_path rest of the URL after `/kyc-webhook/`
+ * @param connection MHD connection object (for HTTP headers)
+ * @param body HTTP request body
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_WebhookHandle *
+kycaid_webhook (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ TALER_KYCLOGIC_ProviderLookupCallback plc,
+ void *plc_cls,
+ const char *http_method,
+ const char *const url_path[],
+ struct MHD_Connection *connection,
+ const json_t *body,
+ TALER_KYCLOGIC_WebhookCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+ CURL *eh;
+ const char *request_id;
+ const char *type;
+ const char *verification_id; /* = provider_legitimization_id */
+ const char *applicant_id;
+ const char *form_id;
+ const char *status = NULL;
+ bool verified = false;
+ bool no_verified = true;
+ const json_t *verifications = NULL;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("request_id",
+ &request_id),
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_string ("verification_id",
+ &verification_id),
+ GNUNET_JSON_spec_string ("applicant_id",
+ &applicant_id),
+ GNUNET_JSON_spec_string ("form_id",
+ &form_id),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("status",
+ &status),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("verified",
+ &verified),
+ &no_verified),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_object_const ("verifications",
+ &verifications),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_DB_QueryStatus qs;
+
+ wh = GNUNET_new (struct TALER_KYCLOGIC_WebhookHandle);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ps = ps;
+ wh->pd = pd;
+ wh->connection = connection;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYCAID webhook of `%s' triggered with %s\n",
+ pd->section,
+ http_method);
+#if 1
+ if (NULL != body)
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+#endif
+ if (NULL == pd)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+ wh->resp = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
+ "kycaid");
+ wh->response_code = MHD_HTTP_NOT_FOUND;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (body,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+ wh->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_object_incref ("webhook_body",
+ (json_t *) body));
+ wh->response_code = MHD_HTTP_BAD_REQUEST;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ qs = plc (plc_cls,
+ pd->section,
+ verification_id,
+ &wh->h_payto,
+ &wh->process_row);
+ if (qs < 0)
+ {
+ wh->resp = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "provider-legitimization-lookup");
+ wh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received webhook for unknown verification ID `%s' and section `%s'\n",
+ verification_id,
+ pd->section);
+ wh->resp = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_KYC_PROOF_REQUEST_UNKNOWN,
+ verification_id);
+ wh->response_code = MHD_HTTP_NOT_FOUND;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ wh->verification_id = GNUNET_strdup (verification_id);
+ wh->applicant_id = GNUNET_strdup (applicant_id);
+ if ( (0 != strcasecmp (type,
+ "VERIFICATION_COMPLETED")) ||
+ (no_verified) ||
+ (! verified) )
+ {
+ /* We don't need to re-confirm the failure by
+ asking the API again. */
+ log_failure (verifications);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Webhook called with non-completion status: %s\n",
+ type);
+ wh->response_code = MHD_HTTP_NO_CONTENT;
+ wh->resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ wh->resp = TALER_MHD_make_error (
+ TALER_EC_GENERIC_ALLOCATION_FAILURE,
+ NULL);
+ wh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ GNUNET_asprintf (&wh->url,
+ "https://api.kycaid.com/applicants/%s",
+ applicant_id);
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 0));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 1L));
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ wh->url));
+ wh->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ pd->slist,
+ &handle_webhook_finished,
+ wh);
+ return wh;
+}
+
+
+/**
+ * Initialize kycaid logic plugin
+ *
+ * @param cls a configuration instance
+ * @return NULL on error, otherwise a `struct TALER_KYCLOGIC_Plugin`
+ */
+void *
+libtaler_plugin_kyclogic_kycaid_init (void *cls)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_KYCLOGIC_Plugin *plugin;
+ struct PluginState *ps;
+
+ ps = GNUNET_new (struct PluginState);
+ ps->cfg = cfg;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &ps->exchange_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ GNUNET_free (ps);
+ return NULL;
+ }
+
+ ps->curl_ctx
+ = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &ps->curl_rc);
+ if (NULL == ps->curl_ctx)
+ {
+ GNUNET_break (0);
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ return NULL;
+ }
+ ps->curl_rc = GNUNET_CURL_gnunet_rc_create (ps->curl_ctx);
+
+ plugin = GNUNET_new (struct TALER_KYCLOGIC_Plugin);
+ plugin->cls = ps;
+ plugin->load_configuration
+ = &kycaid_load_configuration;
+ plugin->unload_configuration
+ = &kycaid_unload_configuration;
+ plugin->initiate
+ = &kycaid_initiate;
+ plugin->initiate_cancel
+ = &kycaid_initiate_cancel;
+ plugin->proof
+ = &kycaid_proof;
+ plugin->proof_cancel
+ = &kycaid_proof_cancel;
+ plugin->webhook
+ = &kycaid_webhook;
+ plugin->webhook_cancel
+ = &kycaid_webhook_cancel;
+ return plugin;
+}
+
+
+/**
+ * Unload authorization plugin
+ *
+ * @param cls a `struct TALER_KYCLOGIC_Plugin`
+ * @return NULL (always)
+ */
+void *
+libtaler_plugin_kyclogic_kycaid_done (void *cls)
+{
+ struct TALER_KYCLOGIC_Plugin *plugin = cls;
+ struct PluginState *ps = plugin->cls;
+
+ if (NULL != ps->curl_ctx)
+ {
+ GNUNET_CURL_fini (ps->curl_ctx);
+ ps->curl_ctx = NULL;
+ }
+ if (NULL != ps->curl_rc)
+ {
+ GNUNET_CURL_gnunet_rc_destroy (ps->curl_rc);
+ ps->curl_rc = NULL;
+ }
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ GNUNET_free (plugin);
+ return NULL;
+}
diff --git a/src/kyclogic/plugin_kyclogic_oauth2.c b/src/kyclogic/plugin_kyclogic_oauth2.c
new file mode 100644
index 000000000..3a1f50bcf
--- /dev/null
+++ b/src/kyclogic/plugin_kyclogic_oauth2.c
@@ -0,0 +1,1780 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2022-2024 Taler Systems SA
+
+ Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Taler; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file plugin_kyclogic_oauth2.c
+ * @brief oauth2.0 based authentication flow logic
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_kyclogic_plugin.h"
+#include "taler_mhd_lib.h"
+#include "taler_templating_lib.h"
+#include "taler_json_lib.h"
+#include <regex.h>
+#include "taler_util.h"
+
+
+/**
+ * Saves the state of a plugin.
+ */
+struct PluginState
+{
+
+ /**
+ * Our global configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Our base URL.
+ */
+ char *exchange_base_url;
+
+ /**
+ * Context for CURL operations (useful to the event loop)
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * Context for integrating @e curl_ctx with the
+ * GNUnet event loop.
+ */
+ struct GNUNET_CURL_RescheduleContext *curl_rc;
+
+};
+
+
+/**
+ * Keeps the plugin-specific state for
+ * a given configuration section.
+ */
+struct TALER_KYCLOGIC_ProviderDetails
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Configuration section that configured us.
+ */
+ char *section;
+
+ /**
+ * URL of the Challenger ``/setup`` endpoint for
+ * approving address validations. NULL if not used.
+ */
+ char *setup_url;
+
+ /**
+ * URL of the OAuth2.0 endpoint for KYC checks.
+ */
+ char *authorize_url;
+
+ /**
+ * URL of the OAuth2.0 endpoint for KYC checks.
+ * (token/auth)
+ */
+ char *token_url;
+
+ /**
+ * URL of the user info access endpoint.
+ */
+ char *info_url;
+
+ /**
+ * Our client ID for OAuth2.0.
+ */
+ char *client_id;
+
+ /**
+ * Our client secret for OAuth2.0.
+ */
+ char *client_secret;
+
+ /**
+ * Where to redirect clients after the
+ * Web-based KYC process is done?
+ */
+ char *post_kyc_redirect_url;
+
+ /**
+ * Name of the program we use to convert outputs
+ * from Persona into our JSON inputs.
+ */
+ char *conversion_binary;
+
+ /**
+ * Validity time for a successful KYC process.
+ */
+ struct GNUNET_TIME_Relative validity;
+
+ /**
+ * Set to true if we are operating in DEBUG
+ * mode and may return private details in HTML
+ * responses to make diagnostics easier.
+ */
+ bool debug_mode;
+};
+
+
+/**
+ * Handle for an initiation operation.
+ */
+struct TALER_KYCLOGIC_InitiateHandle
+{
+
+ /**
+ * Hash of the payto:// URI we are initiating
+ * the KYC for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * UUID being checked.
+ */
+ uint64_t legitimization_uuid;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * The task for asynchronous response generation.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Handle for the OAuth 2.0 setup request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_InitiateCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+};
+
+
+/**
+ * Handle for an KYC proof operation.
+ */
+struct TALER_KYCLOGIC_ProofHandle
+{
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * HTTP connection we are processing.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * Handle to an external process that converts the
+ * Persona response to our internal format.
+ */
+ struct TALER_JSON_ExternalConversion *ec;
+
+ /**
+ * Hash of the payto URI that this is about.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_ProofCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Curl request we are running to the OAuth 2.0 service.
+ */
+ CURL *eh;
+
+ /**
+ * Body for the @e eh POST request.
+ */
+ char *post_body;
+
+ /**
+ * KYC attributes returned about the user by the OAuth 2.0 server.
+ */
+ json_t *attributes;
+
+ /**
+ * Response to return.
+ */
+ struct MHD_Response *response;
+
+ /**
+ * The task for asynchronous response generation.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Handle for the OAuth 2.0 CURL request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * User ID to return, the 'id' from OAuth.
+ */
+ char *provider_user_id;
+
+ /**
+ * Legitimization ID to return, the 64-bit row ID
+ * as a string.
+ */
+ char provider_legitimization_id[32];
+
+ /**
+ * KYC status to return.
+ */
+ enum TALER_KYCLOGIC_KycStatus status;
+
+ /**
+ * HTTP status to return.
+ */
+ unsigned int http_status;
+
+
+};
+
+
+/**
+ * Handle for an KYC Web hook operation.
+ */
+struct TALER_KYCLOGIC_WebhookHandle
+{
+
+ /**
+ * Continuation to call when done.
+ */
+ TALER_KYCLOGIC_WebhookCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+};
+
+
+/**
+ * Release configuration resources previously loaded
+ *
+ * @param[in] pd configuration to release
+ */
+static void
+oauth2_unload_configuration (struct TALER_KYCLOGIC_ProviderDetails *pd)
+{
+ GNUNET_free (pd->section);
+ GNUNET_free (pd->token_url);
+ GNUNET_free (pd->setup_url);
+ GNUNET_free (pd->authorize_url);
+ GNUNET_free (pd->info_url);
+ GNUNET_free (pd->client_id);
+ GNUNET_free (pd->client_secret);
+ GNUNET_free (pd->post_kyc_redirect_url);
+ GNUNET_free (pd->conversion_binary);
+ GNUNET_free (pd);
+}
+
+
+/**
+ * Load the configuration of the KYC provider.
+ *
+ * @param cls closure
+ * @param provider_section_name configuration section to parse
+ * @return NULL if configuration is invalid
+ */
+static struct TALER_KYCLOGIC_ProviderDetails *
+oauth2_load_configuration (void *cls,
+ const char *provider_section_name)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+ char *s;
+
+ pd = GNUNET_new (struct TALER_KYCLOGIC_ProviderDetails);
+ pd->ps = ps;
+ pd->section = GNUNET_strdup (provider_section_name);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_VALIDITY",
+ &pd->validity))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_VALIDITY");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_CLIENT_ID",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_CLIENT_ID");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ pd->client_id = s;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_TOKEN_URL",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_TOKEN_URL");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ if ( (! TALER_url_valid_charset (s)) ||
+ ( (0 != strncasecmp (s,
+ "http://",
+ strlen ("http://"))) &&
+ (0 != strncasecmp (s,
+ "https://",
+ strlen ("https://"))) ) )
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_TOKEN_URL",
+ "not a valid URL");
+ GNUNET_free (s);
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ pd->token_url = s;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_AUTHORIZE_URL",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_AUTHORIZE_URL");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ if ( (! TALER_url_valid_charset (s)) ||
+ ( (0 != strncasecmp (s,
+ "http://",
+ strlen ("http://"))) &&
+ (0 != strncasecmp (s,
+ "https://",
+ strlen ("https://"))) ) )
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_AUTHORIZE_URL",
+ "not a valid URL");
+ oauth2_unload_configuration (pd);
+ GNUNET_free (s);
+ return NULL;
+ }
+ if (NULL != strchr (s, '#'))
+ {
+ const char *extra = strchr (s, '#');
+ const char *slash = strrchr (s, '/');
+
+ if ( (0 != strcmp (extra,
+ "#setup")) ||
+ (NULL == slash) )
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_AUTHORIZE_URL",
+ "not a valid authorze URL (bad fragment)");
+ oauth2_unload_configuration (pd);
+ GNUNET_free (s);
+ return NULL;
+ }
+ pd->authorize_url = GNUNET_strndup (s,
+ extra - s);
+ GNUNET_asprintf (&pd->setup_url,
+ "%.*s/setup/%s",
+ (int) (slash - s),
+ s,
+ pd->client_id);
+ GNUNET_free (s);
+ }
+ else
+ {
+ pd->authorize_url = s;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_INFO_URL",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_INFO_URL");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ if ( (! TALER_url_valid_charset (s)) ||
+ ( (0 != strncasecmp (s,
+ "http://",
+ strlen ("http://"))) &&
+ (0 != strncasecmp (s,
+ "https://",
+ strlen ("https://"))) ) )
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_INFO_URL",
+ "not a valid URL");
+ GNUNET_free (s);
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ pd->info_url = s;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_CLIENT_SECRET",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_CLIENT_SECRET");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ pd->client_secret = s;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_POST_URL",
+ &s))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_POST_URL");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ pd->post_kyc_redirect_url = s;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_CONVERTER_HELPER",
+ &pd->conversion_binary))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_OAUTH2_CONVERTER_HELPER");
+ oauth2_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK ==
+ GNUNET_CONFIGURATION_get_value_yesno (ps->cfg,
+ provider_section_name,
+ "KYC_OAUTH2_DEBUG_MODE"))
+ pd->debug_mode = true;
+
+ return pd;
+}
+
+
+/**
+ * Logic to asynchronously return the response for
+ * how to begin the OAuth2.0 checking process to
+ * the client.
+ *
+ * @param ih process to redirect for
+ * @param authorize_url authorization URL to use
+ */
+static void
+initiate_with_url (struct TALER_KYCLOGIC_InitiateHandle *ih,
+ const char *authorize_url)
+{
+
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ih->pd;
+ struct PluginState *ps = pd->ps;
+ char *hps;
+ char *url;
+ char legi_s[42];
+
+ GNUNET_snprintf (legi_s,
+ sizeof (legi_s),
+ "%llu",
+ (unsigned long long) ih->legitimization_uuid);
+ hps = GNUNET_STRINGS_data_to_string_alloc (&ih->h_payto,
+ sizeof (ih->h_payto));
+ {
+ char *redirect_uri_encoded;
+
+ {
+ char *redirect_uri;
+
+ GNUNET_asprintf (&redirect_uri,
+ "%skyc-proof/%s",
+ ps->exchange_base_url,
+ pd->section);
+ redirect_uri_encoded = TALER_urlencode (redirect_uri);
+ GNUNET_free (redirect_uri);
+ }
+ GNUNET_asprintf (&url,
+ "%s?response_type=code&client_id=%s&redirect_uri=%s&state=%s",
+ authorize_url,
+ pd->client_id,
+ redirect_uri_encoded,
+ hps);
+ GNUNET_free (redirect_uri_encoded);
+ }
+ ih->cb (ih->cb_cls,
+ TALER_EC_NONE,
+ url,
+ NULL /* unknown user_id here */,
+ legi_s,
+ NULL /* no error */);
+ GNUNET_free (url);
+ GNUNET_free (hps);
+ GNUNET_free (ih);
+}
+
+
+/**
+ * After we are done with the CURL interaction we
+ * need to update our database state with the information
+ * retrieved.
+ *
+ * @param cls a `struct TALER_KYCLOGIC_InitiateHandle *`
+ * @param response_code HTTP response code from server, 0 on hard error
+ * @param response in JSON, NULL if response was not in JSON format
+ */
+static void
+handle_curl_setup_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih = cls;
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ih->pd;
+ const json_t *j = response;
+
+ ih->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "/setup URL failed to return HTTP response\n");
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
+ NULL,
+ NULL,
+ NULL,
+ "/setup request to OAuth 2.0 backend returned no response");
+ GNUNET_free (ih);
+ return;
+ case MHD_HTTP_OK:
+ {
+ const char *nonce;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("nonce",
+ &nonce),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue res;
+ const char *emsg;
+ unsigned int line;
+ char *url;
+
+ res = GNUNET_JSON_parse (j,
+ spec,
+ &emsg,
+ &line);
+ if (GNUNET_OK != res)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
+ NULL,
+ NULL,
+ NULL,
+ "Unexpected response from KYC gateway: setup must return a nonce");
+ GNUNET_free (ih);
+ return;
+ }
+ GNUNET_asprintf (&url,
+ "%s/%s",
+ pd->authorize_url,
+ nonce);
+ initiate_with_url (ih,
+ url);
+ GNUNET_free (url);
+ return;
+ }
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "/setup URL returned HTTP status %u\n",
+ (unsigned int) response_code);
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE,
+ NULL,
+ NULL,
+ NULL,
+ "/setup request to OAuth 2.0 backend returned unexpected HTTP status code");
+ GNUNET_free (ih);
+ return;
+ }
+}
+
+
+/**
+ * Logic to asynchronously return the response for how to begin the OAuth2.0
+ * checking process to the client. May first request a dynamic URL via
+ * ``/setup`` if configured to use a client-authenticated setup process.
+ *
+ * @param cls a `struct TALER_KYCLOGIC_InitiateHandle *`
+ */
+static void
+initiate_task (void *cls)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih = cls;
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ih->pd;
+ struct PluginState *ps = pd->ps;
+ char *hdr;
+ struct curl_slist *slist;
+ CURL *eh;
+
+ ih->task = NULL;
+ if (NULL == pd->setup_url)
+ {
+ initiate_with_url (ih,
+ pd->authorize_url);
+ return;
+ }
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ ih->cb (ih->cb_cls,
+ TALER_EC_GENERIC_ALLOCATION_FAILURE,
+ NULL,
+ NULL,
+ NULL,
+ "curl_easy_init() failed");
+ GNUNET_free (ih);
+ return;
+ }
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ pd->setup_url));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_POST,
+ 1));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_POSTFIELDS,
+ ""));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_FOLLOWLOCATION,
+ 1L));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 5L));
+ GNUNET_asprintf (&hdr,
+ "%s: Bearer %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ pd->client_secret);
+ slist = curl_slist_append (NULL,
+ hdr);
+ ih->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ slist,
+ &handle_curl_setup_finished,
+ ih);
+ curl_slist_free_all (slist);
+ GNUNET_free (hdr);
+}
+
+
+/**
+ * Initiate KYC check.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param account_id which account to trigger process for
+ * @param legitimization_uuid unique ID for the legitimization process
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_InitiateHandle *
+oauth2_initiate (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t legitimization_uuid,
+ TALER_KYCLOGIC_InitiateCallback cb,
+ void *cb_cls)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih;
+
+ (void) cls;
+ ih = GNUNET_new (struct TALER_KYCLOGIC_InitiateHandle);
+ ih->legitimization_uuid = legitimization_uuid;
+ ih->cb = cb;
+ ih->cb_cls = cb_cls;
+ ih->h_payto = *account_id;
+ ih->pd = pd;
+ ih->task = GNUNET_SCHEDULER_add_now (&initiate_task,
+ ih);
+ return ih;
+}
+
+
+/**
+ * Cancel KYC check initiation.
+ *
+ * @param[in] ih handle of operation to cancel
+ */
+static void
+oauth2_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih)
+{
+ if (NULL != ih->task)
+ {
+ GNUNET_SCHEDULER_cancel (ih->task);
+ ih->task = NULL;
+ }
+ if (NULL != ih->job)
+ {
+ GNUNET_CURL_job_cancel (ih->job);
+ ih->job = NULL;
+ }
+ GNUNET_free (ih);
+}
+
+
+/**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+static void
+oauth2_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
+{
+ if (NULL != ph->ec)
+ {
+ TALER_JSON_external_conversion_stop (ph->ec);
+ ph->ec = NULL;
+ }
+ if (NULL != ph->task)
+ {
+ GNUNET_SCHEDULER_cancel (ph->task);
+ ph->task = NULL;
+ }
+ if (NULL != ph->job)
+ {
+ GNUNET_CURL_job_cancel (ph->job);
+ ph->job = NULL;
+ }
+ if (NULL != ph->response)
+ {
+ MHD_destroy_response (ph->response);
+ ph->response = NULL;
+ }
+ GNUNET_free (ph->provider_user_id);
+ if (NULL != ph->attributes)
+ json_decref (ph->attributes);
+ GNUNET_free (ph->post_body);
+ GNUNET_free (ph);
+}
+
+
+/**
+ * Function called to asynchronously return the final
+ * result to the callback.
+ *
+ * @param cls a `struct TALER_KYCLOGIC_ProofHandle`
+ */
+static void
+return_proof_response (void *cls)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+
+ ph->task = NULL;
+ ph->cb (ph->cb_cls,
+ ph->status,
+ ph->provider_user_id,
+ ph->provider_legitimization_id,
+ GNUNET_TIME_relative_to_absolute (ph->pd->validity),
+ ph->attributes,
+ ph->http_status,
+ ph->response);
+ ph->response = NULL; /*Ownership passed to 'ph->cb'!*/
+ oauth2_proof_cancel (ph);
+}
+
+
+/**
+ * The request for @a ph failed. We may have gotten a useful error
+ * message in @a j. Generate a failure response.
+ *
+ * @param[in,out] ph request that failed
+ * @param j reply from the server (or NULL)
+ */
+static void
+handle_proof_error (struct TALER_KYCLOGIC_ProofHandle *ph,
+ const json_t *j)
+{
+ enum GNUNET_GenericReturnValue res;
+
+ {
+ const char *msg;
+ const char *desc;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("error",
+ &msg),
+ GNUNET_JSON_spec_string ("error_description",
+ &desc),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int line;
+
+ res = GNUNET_JSON_parse (j,
+ spec,
+ &emsg,
+ &line);
+ }
+
+ if (GNUNET_OK != res)
+ {
+ json_t *body;
+
+ GNUNET_break_op (0);
+ ph->status = TALER_KYCLOGIC_STATUS_PROVIDER_FAILED;
+ ph->http_status
+ = MHD_HTTP_BAD_GATEWAY;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("server_response",
+ (json_t *) j)),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_assert (NULL != body);
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-authorization-failure-malformed",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ return;
+ }
+ ph->status = TALER_KYCLOGIC_STATUS_USER_ABORTED;
+ ph->http_status = MHD_HTTP_FORBIDDEN;
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-authorization-failure",
+ NULL,
+ NULL,
+ j,
+ &ph->response));
+}
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure with a `struct TALER_KYCLOGIC_ProofHandle *`
+ * @param status_type how did the process die
+ * @param code termination status code from the process
+ * @param attr result some JSON result, NULL if we failed to get an JSON output
+ */
+static void
+converted_proof_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *attr)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ph->pd;
+
+ ph->ec = NULL;
+ if ( (NULL == attr) ||
+ (0 != code) )
+ {
+ json_t *body;
+ char *msg;
+
+ GNUNET_break_op (0);
+ ph->status = TALER_KYCLOGIC_STATUS_PROVIDER_FAILED;
+ ph->http_status = MHD_HTTP_BAD_GATEWAY;
+ if (0 != code)
+ GNUNET_asprintf (&msg,
+ "Attribute converter exited with status %ld",
+ code);
+ else
+ msg = GNUNET_strdup (
+ "Attribute converter response was not in JSON format");
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("converter",
+ pd->conversion_binary),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("attributes",
+ (json_t *) attr)),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_string ("message",
+ msg),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_free (msg);
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-conversion-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+ return;
+ }
+
+ {
+ const char *id;
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("id",
+ &id),
+ GNUNET_JSON_spec_end ()
+ };
+ enum GNUNET_GenericReturnValue res;
+ const char *emsg;
+ unsigned int line;
+
+ res = GNUNET_JSON_parse (attr,
+ ispec,
+ &emsg,
+ &line);
+ if (GNUNET_OK != res)
+ {
+ json_t *body;
+
+ GNUNET_break_op (0);
+ ph->status = TALER_KYCLOGIC_STATUS_PROVIDER_FAILED;
+ ph->http_status = MHD_HTTP_BAD_GATEWAY;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("converter",
+ pd->conversion_binary),
+ GNUNET_JSON_pack_string ("message",
+ "Unexpected response from KYC attribute converter: returned JSON data must contain 'id' field"),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_object_incref ("attributes",
+ (json_t *) attr),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-conversion-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+ return;
+ }
+ ph->provider_user_id = GNUNET_strdup (id);
+ }
+ ph->status = TALER_KYCLOGIC_STATUS_SUCCESS;
+ ph->response = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ GNUNET_assert (NULL != ph->response);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (
+ ph->response,
+ MHD_HTTP_HEADER_LOCATION,
+ ph->pd->post_kyc_redirect_url));
+ ph->http_status = MHD_HTTP_SEE_OTHER;
+ ph->attributes = json_incref ((json_t *) attr);
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+}
+
+
+/**
+ * The request for @a ph succeeded (presumably).
+ * Call continuation with the result.
+ *
+ * @param[in,out] ph request that succeeded
+ * @param j reply from the server
+ */
+static void
+parse_proof_success_reply (struct TALER_KYCLOGIC_ProofHandle *ph,
+ const json_t *j)
+{
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ph->pd;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Calling converter `%s' with JSON\n",
+ pd->conversion_binary);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ph->ec = TALER_JSON_external_conversion_start (
+ j,
+ &converted_proof_cb,
+ ph,
+ pd->conversion_binary,
+ pd->conversion_binary,
+ NULL);
+ if (NULL != ph->ec)
+ return;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start KYCAID conversion helper `%s'\n",
+ pd->conversion_binary);
+ ph->status = TALER_KYCLOGIC_STATUS_INTERNAL_ERROR;
+ ph->http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ {
+ json_t *body;
+
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("converter",
+ pd->conversion_binary),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_string ("message",
+ "Failed to launch KYC conversion helper process."),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_GENERIC_KYC_CONVERTER_FAILED));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-conversion-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ }
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+}
+
+
+/**
+ * After we are done with the CURL interaction we
+ * need to update our database state with the information
+ * retrieved.
+ *
+ * @param cls our `struct TALER_KYCLOGIC_ProofHandle`
+ * @param response_code HTTP response code from server, 0 on hard error
+ * @param response in JSON, NULL if response was not in JSON format
+ */
+static void
+handle_curl_proof_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ const json_t *j = response;
+
+ ph->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ {
+ json_t *body;
+
+ ph->status = TALER_KYCLOGIC_STATUS_PROVIDER_FAILED;
+ ph->http_status = MHD_HTTP_BAD_GATEWAY;
+
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("message",
+ "No response from KYC gateway"),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-provider-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ }
+ break;
+ case MHD_HTTP_OK:
+ parse_proof_success_reply (ph,
+ j);
+ return;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "OAuth2.0 info URL returned HTTP status %u\n",
+ (unsigned int) response_code);
+ handle_proof_error (ph,
+ j);
+ break;
+ }
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+}
+
+
+/**
+ * After we are done with the CURL interaction we
+ * need to fetch the user's account details.
+ *
+ * @param cls our `struct KycProofContext`
+ * @param response_code HTTP response code from server, 0 on hard error
+ * @param response in JSON, NULL if response was not in JSON format
+ */
+static void
+handle_curl_login_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ const json_t *j = response;
+
+ ph->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char *access_token;
+ const char *token_type;
+ uint64_t expires_in_s;
+ const char *refresh_token;
+ bool no_expires;
+ bool no_refresh;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("access_token",
+ &access_token),
+ GNUNET_JSON_spec_string ("token_type",
+ &token_type),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint64 ("expires_in",
+ &expires_in_s),
+ &no_expires),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("refresh_token",
+ &refresh_token),
+ &no_refresh),
+ GNUNET_JSON_spec_end ()
+ };
+ CURL *eh;
+
+ {
+ enum GNUNET_GenericReturnValue res;
+ const char *emsg;
+ unsigned int line;
+
+ res = GNUNET_JSON_parse (j,
+ spec,
+ &emsg,
+ &line);
+ if (GNUNET_OK != res)
+ {
+ json_t *body;
+
+ GNUNET_break_op (0);
+ ph->http_status
+ = MHD_HTTP_BAD_GATEWAY;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_incref ("server_response",
+ (json_t *) j),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_string ("message",
+ "Unexpected response from KYC gateway: required fields missing or malformed"),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-provider-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ break;
+ }
+ }
+ if (0 != strcasecmp (token_type,
+ "bearer"))
+ {
+ json_t *body;
+
+ GNUNET_break_op (0);
+ ph->http_status = MHD_HTTP_BAD_GATEWAY;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_incref ("server_response",
+ (json_t *) j),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_string ("message",
+ "Unexpected 'token_type' in response from KYC gateway: 'bearer' token required"),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-provider-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ break;
+ }
+
+ /* We guard against a few characters that could
+ conceivably be abused to mess with the HTTP header */
+ if ( (NULL != strchr (access_token,
+ '\n')) ||
+ (NULL != strchr (access_token,
+ '\r')) ||
+ (NULL != strchr (access_token,
+ ' ')) ||
+ (NULL != strchr (access_token,
+ ';')) )
+ {
+ json_t *body;
+
+ GNUNET_break_op (0);
+ ph->http_status = MHD_HTTP_BAD_GATEWAY;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_incref ("server_response",
+ (json_t *) j),
+ GNUNET_JSON_pack_bool ("debug",
+ ph->pd->debug_mode),
+ GNUNET_JSON_pack_string ("message",
+ "Illegal character in access token"),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_INVALID_RESPONSE));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-provider-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ break;
+ }
+
+ eh = curl_easy_init ();
+ GNUNET_assert (NULL != eh);
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ ph->pd->info_url));
+ {
+ char *hdr;
+ struct curl_slist *slist;
+
+ GNUNET_asprintf (&hdr,
+ "%s: Bearer %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ access_token);
+ slist = curl_slist_append (NULL,
+ hdr);
+ ph->job = GNUNET_CURL_job_add2 (ph->pd->ps->curl_ctx,
+ eh,
+ slist,
+ &handle_curl_proof_finished,
+ ph);
+ curl_slist_free_all (slist);
+ GNUNET_free (hdr);
+ }
+ return;
+ }
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "OAuth2.0 login URL returned HTTP status %u\n",
+ (unsigned int) response_code);
+ handle_proof_error (ph,
+ j);
+ break;
+ }
+ return_proof_response (ph);
+}
+
+
+/**
+ * Check KYC status and return status to human.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param connection MHD connection object (for HTTP headers)
+ * @param account_id which account to trigger process for
+ * @param process_row row in the legitimization processes table the legitimization is for
+ * @param provider_user_id user ID (or NULL) the proof is for
+ * @param provider_legitimization_id legitimization ID the proof is for
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_ProofHandle *
+oauth2_proof (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ TALER_KYCLOGIC_ProofCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProofHandle *ph;
+ const char *code;
+
+ GNUNET_break (NULL == provider_user_id);
+ ph = GNUNET_new (struct TALER_KYCLOGIC_ProofHandle);
+ GNUNET_snprintf (ph->provider_legitimization_id,
+ sizeof (ph->provider_legitimization_id),
+ "%llu",
+ (unsigned long long) process_row);
+ if ( (NULL != provider_legitimization_id) &&
+ (0 != strcmp (provider_legitimization_id,
+ ph->provider_legitimization_id)))
+ {
+ GNUNET_break (0);
+ GNUNET_free (ph);
+ return NULL;
+ }
+
+ ph->pd = pd;
+ ph->connection = connection;
+ ph->h_payto = *account_id;
+ ph->cb = cb;
+ ph->cb_cls = cb_cls;
+ code = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "code");
+ if (NULL == code)
+ {
+ const char *err;
+ const char *desc;
+ const char *euri;
+ json_t *body;
+
+ err = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "error");
+ if (NULL == err)
+ {
+ GNUNET_break_op (0);
+ ph->status = TALER_KYCLOGIC_STATUS_USER_PENDING;
+ ph->http_status = MHD_HTTP_BAD_REQUEST;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("message",
+ "'code' parameter malformed"),
+ TALER_JSON_pack_ec (
+ TALER_EC_GENERIC_PARAMETER_MALFORMED));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-bad-request",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+ return ph;
+ }
+ desc = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "error_description");
+ euri = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "error_uri");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "OAuth2 process %llu failed with error `%s'\n",
+ (unsigned long long) process_row,
+ err);
+ if (0 == strcmp (err,
+ "server_error"))
+ ph->status = TALER_KYCLOGIC_STATUS_PROVIDER_FAILED;
+ else if (0 == strcmp (err,
+ "unauthorized_client"))
+ ph->status = TALER_KYCLOGIC_STATUS_FAILED;
+ else if (0 == strcmp (err,
+ "temporarily_unavailable"))
+ ph->status = TALER_KYCLOGIC_STATUS_PENDING;
+ else
+ ph->status = TALER_KYCLOGIC_STATUS_INTERNAL_ERROR;
+ ph->http_status = MHD_HTTP_FORBIDDEN;
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("error",
+ err),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("error_details",
+ desc)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("error_uri",
+ euri)));
+ GNUNET_break (
+ GNUNET_SYSERR !=
+ TALER_TEMPLATING_build (ph->connection,
+ &ph->http_status,
+ "oauth2-authentication-failure",
+ NULL,
+ NULL,
+ body,
+ &ph->response));
+ json_decref (body);
+ ph->task = GNUNET_SCHEDULER_add_now (&return_proof_response,
+ ph);
+ return ph;
+
+ }
+
+ ph->eh = curl_easy_init ();
+ GNUNET_assert (NULL != ph->eh);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting OAuth 2.0 data via HTTP POST `%s'\n",
+ pd->token_url);
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_URL,
+ pd->token_url));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_VERBOSE,
+ 1));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_POST,
+ 1));
+ {
+ char *client_id;
+ char *client_secret;
+ char *authorization_code;
+ char *redirect_uri_encoded;
+ char *hps;
+
+ hps = GNUNET_STRINGS_data_to_string_alloc (&ph->h_payto,
+ sizeof (ph->h_payto));
+ {
+ char *redirect_uri;
+
+ GNUNET_asprintf (&redirect_uri,
+ "%skyc-proof/%s",
+ ps->exchange_base_url,
+ pd->section);
+ redirect_uri_encoded = TALER_urlencode (redirect_uri);
+ GNUNET_free (redirect_uri);
+ }
+ GNUNET_assert (NULL != redirect_uri_encoded);
+ client_id = curl_easy_escape (ph->eh,
+ pd->client_id,
+ 0);
+ GNUNET_assert (NULL != client_id);
+ client_secret = curl_easy_escape (ph->eh,
+ pd->client_secret,
+ 0);
+ GNUNET_assert (NULL != client_secret);
+ authorization_code = curl_easy_escape (ph->eh,
+ code,
+ 0);
+ GNUNET_assert (NULL != authorization_code);
+ GNUNET_asprintf (&ph->post_body,
+ "client_id=%s&redirect_uri=%s&state=%s&client_secret=%s&code=%s&grant_type=authorization_code",
+ client_id,
+ redirect_uri_encoded,
+ hps,
+ client_secret,
+ authorization_code);
+ curl_free (authorization_code);
+ curl_free (client_secret);
+ GNUNET_free (redirect_uri_encoded);
+ GNUNET_free (hps);
+ curl_free (client_id);
+ }
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_POSTFIELDS,
+ ph->post_body));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_FOLLOWLOCATION,
+ 1L));
+ /* limit MAXREDIRS to 5 as a simple security measure against
+ a potential infinite loop caused by a malicious target */
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (ph->eh,
+ CURLOPT_MAXREDIRS,
+ 5L));
+
+ ph->job = GNUNET_CURL_job_add (ps->curl_ctx,
+ ph->eh,
+ &handle_curl_login_finished,
+ ph);
+ return ph;
+}
+
+
+/**
+ * Function to asynchronously return the 404 not found
+ * page for the webhook.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_WebhookHandle *`
+ */
+static void
+wh_return_not_found (void *cls)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+ struct MHD_Response *response;
+
+ wh->task = NULL;
+ response = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ wh->cb (wh->cb_cls,
+ 0LLU,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ TALER_KYCLOGIC_STATUS_KEEP,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ NULL,
+ MHD_HTTP_NOT_FOUND,
+ response);
+ GNUNET_free (wh);
+}
+
+
+/**
+ * Check KYC status and return result for Webhook.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param plc callback to lookup accounts with
+ * @param plc_cls closure for @a plc
+ * @param http_method HTTP method used for the webhook
+ * @param url_path rest of the URL after `/kyc-webhook/$LOGIC/`, as NULL-terminated array
+ * @param connection MHD connection object (for HTTP headers)
+ * @param body HTTP request body, or NULL if not available
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_WebhookHandle *
+oauth2_webhook (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ TALER_KYCLOGIC_ProviderLookupCallback plc,
+ void *plc_cls,
+ const char *http_method,
+ const char *const url_path[],
+ struct MHD_Connection *connection,
+ const json_t *body,
+ TALER_KYCLOGIC_WebhookCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+
+ (void) pd;
+ (void) plc;
+ (void) plc_cls;
+ (void) http_method;
+ (void) url_path;
+ (void) connection;
+ (void) body;
+ wh = GNUNET_new (struct TALER_KYCLOGIC_WebhookHandle);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ps = ps;
+ wh->task = GNUNET_SCHEDULER_add_now (&wh_return_not_found,
+ wh);
+ return wh;
+}
+
+
+/**
+ * Cancel KYC webhook execution.
+ *
+ * @param[in] wh handle of operation to cancel
+ */
+static void
+oauth2_webhook_cancel (struct TALER_KYCLOGIC_WebhookHandle *wh)
+{
+ GNUNET_SCHEDULER_cancel (wh->task);
+ GNUNET_free (wh);
+}
+
+
+/**
+ * Initialize OAuth2.0 KYC logic plugin
+ *
+ * @param cls a configuration instance
+ * @return NULL on error, otherwise a `struct TALER_KYCLOGIC_Plugin`
+ */
+void *
+libtaler_plugin_kyclogic_oauth2_init (void *cls)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_KYCLOGIC_Plugin *plugin;
+ struct PluginState *ps;
+
+ ps = GNUNET_new (struct PluginState);
+ ps->cfg = cfg;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &ps->exchange_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ GNUNET_free (ps);
+ return NULL;
+ }
+ ps->curl_ctx
+ = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &ps->curl_rc);
+ if (NULL == ps->curl_ctx)
+ {
+ GNUNET_break (0);
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ return NULL;
+ }
+ ps->curl_rc = GNUNET_CURL_gnunet_rc_create (ps->curl_ctx);
+
+ plugin = GNUNET_new (struct TALER_KYCLOGIC_Plugin);
+ plugin->cls = ps;
+ plugin->load_configuration
+ = &oauth2_load_configuration;
+ plugin->unload_configuration
+ = &oauth2_unload_configuration;
+ plugin->initiate
+ = &oauth2_initiate;
+ plugin->initiate_cancel
+ = &oauth2_initiate_cancel;
+ plugin->proof
+ = &oauth2_proof;
+ plugin->proof_cancel
+ = &oauth2_proof_cancel;
+ plugin->webhook
+ = &oauth2_webhook;
+ plugin->webhook_cancel
+ = &oauth2_webhook_cancel;
+ return plugin;
+}
+
+
+/**
+ * Unload authorization plugin
+ *
+ * @param cls a `struct TALER_KYCLOGIC_Plugin`
+ * @return NULL (always)
+ */
+void *
+libtaler_plugin_kyclogic_oauth2_done (void *cls)
+{
+ struct TALER_KYCLOGIC_Plugin *plugin = cls;
+ struct PluginState *ps = plugin->cls;
+
+ if (NULL != ps->curl_ctx)
+ {
+ GNUNET_CURL_fini (ps->curl_ctx);
+ ps->curl_ctx = NULL;
+ }
+ if (NULL != ps->curl_rc)
+ {
+ GNUNET_CURL_gnunet_rc_destroy (ps->curl_rc);
+ ps->curl_rc = NULL;
+ }
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ GNUNET_free (plugin);
+ return NULL;
+}
diff --git a/src/kyclogic/plugin_kyclogic_persona.c b/src/kyclogic/plugin_kyclogic_persona.c
new file mode 100644
index 000000000..c68b7f881
--- /dev/null
+++ b/src/kyclogic/plugin_kyclogic_persona.c
@@ -0,0 +1,2268 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2022, 2023 Taler Systems SA
+
+ Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Taler; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file plugin_kyclogic_persona.c
+ * @brief persona for an authentication flow logic
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_attributes.h"
+#include "taler_kyclogic_plugin.h"
+#include "taler_mhd_lib.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_templating_lib.h"
+#include <regex.h>
+#include "taler_util.h"
+
+
+/**
+ * Which version of the persona API are we implementing?
+ */
+#define PERSONA_VERSION "2021-07-05"
+
+/**
+ * Saves the state of a plugin.
+ */
+struct PluginState
+{
+
+ /**
+ * Our base URL.
+ */
+ char *exchange_base_url;
+
+ /**
+ * Our global configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Context for CURL operations (useful to the event loop)
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * Context for integrating @e curl_ctx with the
+ * GNUnet event loop.
+ */
+ struct GNUNET_CURL_RescheduleContext *curl_rc;
+
+ /**
+ * Authorization token to use when receiving webhooks from the Persona
+ * service. Optional. Note that webhooks are *global* and not per
+ * template.
+ */
+ char *webhook_token;
+
+
+};
+
+
+/**
+ * Keeps the plugin-specific state for
+ * a given configuration section.
+ */
+struct TALER_KYCLOGIC_ProviderDetails
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Configuration section that configured us.
+ */
+ char *section;
+
+ /**
+ * Salt to use for idempotency.
+ */
+ char *salt;
+
+ /**
+ * Authorization token to use when talking
+ * to the service.
+ */
+ char *auth_token;
+
+ /**
+ * Template ID for the KYC check to perform.
+ */
+ char *template_id;
+
+ /**
+ * Subdomain to use.
+ */
+ char *subdomain;
+
+ /**
+ * Name of the program we use to convert outputs
+ * from Persona into our JSON inputs.
+ */
+ char *conversion_binary;
+
+ /**
+ * Where to redirect the client upon completion.
+ */
+ char *post_kyc_redirect_url;
+
+ /**
+ * Validity time for a successful KYC process.
+ */
+ struct GNUNET_TIME_Relative validity;
+
+ /**
+ * Curl-ready authentication header to use.
+ */
+ struct curl_slist *slist;
+
+};
+
+
+/**
+ * Handle for an initiation operation.
+ */
+struct TALER_KYCLOGIC_InitiateHandle
+{
+
+ /**
+ * Hash of the payto:// URI we are initiating the KYC for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * UUID being checked.
+ */
+ uint64_t legitimization_uuid;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_InitiateCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Context for #TEH_curl_easy_post(). Keeps the data that must
+ * persist for Curl to make the upload.
+ */
+ struct TALER_CURL_PostContext ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * URL of the cURL request.
+ */
+ char *url;
+
+ /**
+ * Request-specific headers to use.
+ */
+ struct curl_slist *slist;
+
+};
+
+
+/**
+ * Handle for an KYC proof operation.
+ */
+struct TALER_KYCLOGIC_ProofHandle
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_ProofCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * URL of the cURL request.
+ */
+ char *url;
+
+ /**
+ * Handle to an external process that converts the
+ * Persona response to our internal format.
+ */
+ struct TALER_JSON_ExternalConversion *ec;
+
+ /**
+ * Hash of the payto:// URI we are checking the KYC for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Row in the legitimization processes of the
+ * legitimization proof that is being checked.
+ */
+ uint64_t process_row;
+
+ /**
+ * Account ID at the provider.
+ */
+ char *provider_user_id;
+
+ /**
+ * Account ID from the service.
+ */
+ char *account_id;
+
+ /**
+ * Inquiry ID at the provider.
+ */
+ char *inquiry_id;
+};
+
+
+/**
+ * Handle for an KYC Web hook operation.
+ */
+struct TALER_KYCLOGIC_WebhookHandle
+{
+
+ /**
+ * Continuation to call when done.
+ */
+ TALER_KYCLOGIC_WebhookCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * Verification ID from the service.
+ */
+ char *inquiry_id;
+
+ /**
+ * Account ID from the service.
+ */
+ char *account_id;
+
+ /**
+ * URL of the cURL request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Response to return asynchronously.
+ */
+ struct MHD_Response *resp;
+
+ /**
+ * ID of the template the webhook is about,
+ * according to the service.
+ */
+ const char *template_id;
+
+ /**
+ * Handle to an external process that converts the
+ * Persona response to our internal format.
+ */
+ struct TALER_JSON_ExternalConversion *ec;
+
+ /**
+ * Our account ID.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * UUID being checked.
+ */
+ uint64_t process_row;
+
+ /**
+ * HTTP response code to return asynchronously.
+ */
+ unsigned int response_code;
+};
+
+
+/**
+ * Release configuration resources previously loaded
+ *
+ * @param[in] pd configuration to release
+ */
+static void
+persona_unload_configuration (struct TALER_KYCLOGIC_ProviderDetails *pd)
+{
+ curl_slist_free_all (pd->slist);
+ GNUNET_free (pd->auth_token);
+ GNUNET_free (pd->template_id);
+ GNUNET_free (pd->subdomain);
+ GNUNET_free (pd->conversion_binary);
+ GNUNET_free (pd->salt);
+ GNUNET_free (pd->section);
+ GNUNET_free (pd->post_kyc_redirect_url);
+ GNUNET_free (pd);
+}
+
+
+/**
+ * Load the configuration of the KYC provider.
+ *
+ * @param cls closure
+ * @param provider_section_name configuration section to parse
+ * @return NULL if configuration is invalid
+ */
+static struct TALER_KYCLOGIC_ProviderDetails *
+persona_load_configuration (void *cls,
+ const char *provider_section_name)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ pd = GNUNET_new (struct TALER_KYCLOGIC_ProviderDetails);
+ pd->ps = ps;
+ pd->section = GNUNET_strdup (provider_section_name);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_VALIDITY",
+ &pd->validity))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_VALIDITY");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_AUTH_TOKEN",
+ &pd->auth_token))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_AUTH_TOKEN");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_SALT",
+ &pd->salt))
+ {
+ uint32_t salt[8];
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ salt,
+ sizeof (salt));
+ pd->salt = GNUNET_STRINGS_data_to_string_alloc (salt,
+ sizeof (salt));
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_SUBDOMAIN",
+ &pd->subdomain))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_SUBDOMAIN");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_CONVERTER_HELPER",
+ &pd->conversion_binary))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_CONVERTER_HELPER");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_POST_URL",
+ &pd->post_kyc_redirect_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_POST_URL");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ provider_section_name,
+ "KYC_PERSONA_TEMPLATE_ID",
+ &pd->template_id))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ provider_section_name,
+ "KYC_PERSONA_TEMPLATE_ID");
+ persona_unload_configuration (pd);
+ return NULL;
+ }
+ {
+ char *auth;
+
+ GNUNET_asprintf (&auth,
+ "%s: Bearer %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ pd->auth_token);
+ pd->slist = curl_slist_append (NULL,
+ auth);
+ GNUNET_free (auth);
+ GNUNET_asprintf (&auth,
+ "%s: %s",
+ MHD_HTTP_HEADER_ACCEPT,
+ "application/json");
+ pd->slist = curl_slist_append (pd->slist,
+ "Persona-Version: "
+ PERSONA_VERSION);
+ GNUNET_free (auth);
+ }
+ return pd;
+}
+
+
+/**
+ * Cancel KYC check initiation.
+ *
+ * @param[in] ih handle of operation to cancel
+ */
+static void
+persona_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih)
+{
+ if (NULL != ih->job)
+ {
+ GNUNET_CURL_job_cancel (ih->job);
+ ih->job = NULL;
+ }
+ GNUNET_free (ih->url);
+ TALER_curl_easy_post_finished (&ih->ctx);
+ curl_slist_free_all (ih->slist);
+ GNUNET_free (ih);
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP POST "/api/v1/inquiries" request.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_InitiateHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_initiate_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih = cls;
+ const struct TALER_KYCLOGIC_ProviderDetails *pd = ih->pd;
+ const json_t *j = response;
+ char *url;
+ json_t *data;
+ const char *type;
+ const char *inquiry_id;
+ const char *persona_account_id;
+ const char *ename;
+ unsigned int eline;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_string ("id",
+ &inquiry_id),
+ GNUNET_JSON_spec_end ()
+ };
+
+ ih->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_CREATED:
+ /* handled below */
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ case MHD_HTTP_FORBIDDEN:
+ {
+ const char *msg;
+
+ msg = json_string_value (
+ json_object_get (
+ json_array_get (
+ json_object_get (j,
+ "errors"),
+ 0),
+ "title"));
+
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_CHECK_AUTHORIZATION_FAILED,
+ NULL,
+ NULL,
+ NULL,
+ msg);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
+ {
+ const char *msg;
+
+ msg = json_string_value (
+ json_object_get (
+ json_array_get (
+ json_object_get (j,
+ "errors"),
+ 0),
+ "title"));
+
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ msg);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ case MHD_HTTP_BAD_REQUEST:
+ case MHD_HTTP_UNPROCESSABLE_ENTITY:
+ {
+ const char *msg;
+
+ GNUNET_break (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ msg = json_string_value (
+ json_object_get (
+ json_array_get (
+ json_object_get (j,
+ "errors"),
+ 0),
+ "title"));
+
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_BUG,
+ NULL,
+ NULL,
+ NULL,
+ msg);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ case MHD_HTTP_TOO_MANY_REQUESTS:
+ {
+ const char *msg;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Rate limiting requested:\n");
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ msg = json_string_value (
+ json_object_get (
+ json_array_get (
+ json_object_get (j,
+ "errors"),
+ 0),
+ "title"));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_RATE_LIMIT_EXCEEDED,
+ NULL,
+ NULL,
+ NULL,
+ msg);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ default:
+ {
+ char *err;
+
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ GNUNET_asprintf (&err,
+ "Unexpected HTTP status %u from Persona\n",
+ (unsigned int) response_code);
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ err);
+ GNUNET_free (err);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ }
+ data = json_object_get (j,
+ "data");
+ if (NULL == data)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ persona_initiate_cancel (ih);
+ return;
+ }
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (data,
+ spec,
+ &ename,
+ &eline))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ ih->cb (ih->cb_cls,
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY,
+ NULL,
+ NULL,
+ NULL,
+ ename);
+ persona_initiate_cancel (ih);
+ return;
+ }
+ persona_account_id
+ = json_string_value (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (data,
+ "relationships"),
+ "account"),
+ "data"),
+ "id"));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting inquiry %s for Persona account %s\n",
+ inquiry_id,
+ persona_account_id);
+ GNUNET_asprintf (&url,
+ "https://%s.withpersona.com/verify"
+ "?inquiry-id=%s",
+ pd->subdomain,
+ inquiry_id);
+ ih->cb (ih->cb_cls,
+ TALER_EC_NONE,
+ url,
+ persona_account_id,
+ inquiry_id,
+ NULL);
+ GNUNET_free (url);
+ persona_initiate_cancel (ih);
+}
+
+
+/**
+ * Initiate KYC check.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param account_id which account to trigger process for
+ * @param legitimization_uuid unique ID for the legitimization process
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_InitiateHandle *
+persona_initiate (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t legitimization_uuid,
+ TALER_KYCLOGIC_InitiateCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_InitiateHandle *ih;
+ json_t *body;
+ CURL *eh;
+
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ ih = GNUNET_new (struct TALER_KYCLOGIC_InitiateHandle);
+ ih->legitimization_uuid = legitimization_uuid;
+ ih->cb = cb;
+ ih->cb_cls = cb_cls;
+ ih->h_payto = *account_id;
+ ih->pd = pd;
+ GNUNET_asprintf (&ih->url,
+ "https://withpersona.com/api/v1/inquiries");
+ {
+ char *payto_s;
+ char *proof_url;
+ char ref_s[24];
+
+ GNUNET_snprintf (ref_s,
+ sizeof (ref_s),
+ "%llu",
+ (unsigned long long) ih->legitimization_uuid);
+ payto_s = GNUNET_STRINGS_data_to_string_alloc (&ih->h_payto,
+ sizeof (ih->h_payto));
+ GNUNET_break ('/' ==
+ pd->ps->exchange_base_url[strlen (
+ pd->ps->exchange_base_url) - 1]);
+ GNUNET_asprintf (&proof_url,
+ "%skyc-proof/%s?state=%s",
+ pd->ps->exchange_base_url,
+ pd->section,
+ payto_s);
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_steal (
+ "data",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_object_steal (
+ "attributes",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("inquiry_template_id",
+ pd->template_id),
+ GNUNET_JSON_pack_string ("reference_id",
+ ref_s),
+ GNUNET_JSON_pack_string ("redirect_uri",
+ proof_url)
+ )))));
+ GNUNET_assert (NULL != body);
+ GNUNET_free (payto_s);
+ GNUNET_free (proof_url);
+ }
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 0));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 1L));
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ ih->url));
+ ih->ctx.disable_compression = true;
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&ih->ctx,
+ eh,
+ body))
+ {
+ GNUNET_break (0);
+ GNUNET_free (ih->url);
+ GNUNET_free (ih);
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ return NULL;
+ }
+ json_decref (body);
+ ih->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ ih->ctx.headers,
+ &handle_initiate_finished,
+ ih);
+ GNUNET_CURL_extend_headers (ih->job,
+ pd->slist);
+ {
+ char *ikh;
+
+ GNUNET_asprintf (&ikh,
+ "Idempotency-Key: %llu-%s",
+ (unsigned long long) ih->legitimization_uuid,
+ pd->salt);
+ ih->slist = curl_slist_append (NULL,
+ ikh);
+ GNUNET_free (ikh);
+ }
+ GNUNET_CURL_extend_headers (ih->job,
+ ih->slist);
+ return ih;
+}
+
+
+/**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+static void
+persona_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
+{
+ if (NULL != ph->job)
+ {
+ GNUNET_CURL_job_cancel (ph->job);
+ ph->job = NULL;
+ }
+ if (NULL != ph->ec)
+ {
+ TALER_JSON_external_conversion_stop (ph->ec);
+ ph->ec = NULL;
+ }
+ GNUNET_free (ph->url);
+ GNUNET_free (ph->provider_user_id);
+ GNUNET_free (ph->account_id);
+ GNUNET_free (ph->inquiry_id);
+ GNUNET_free (ph);
+}
+
+
+/**
+ * Call @a ph callback with the operation result.
+ *
+ * @param ph proof handle to generate reply for
+ * @param status status to return
+ * @param account_id account to return
+ * @param inquiry_id inquiry ID to supply
+ * @param http_status HTTP status to use
+ * @param template template to instantiate
+ * @param[in] body body for the template to use (reference
+ * is consumed)
+ */
+static void
+proof_generic_reply (struct TALER_KYCLOGIC_ProofHandle *ph,
+ enum TALER_KYCLOGIC_KycStatus status,
+ const char *account_id,
+ const char *inquiry_id,
+ unsigned int http_status,
+ const char *template,
+ json_t *body)
+{
+ struct MHD_Response *resp;
+ enum GNUNET_GenericReturnValue ret;
+
+ /* This API is not usable for successful replies */
+ GNUNET_assert (TALER_KYCLOGIC_STATUS_SUCCESS != status);
+ ret = TALER_TEMPLATING_build (ph->connection,
+ &http_status,
+ template,
+ NULL,
+ NULL,
+ body,
+ &resp);
+ json_decref (body);
+ if (GNUNET_SYSERR == ret)
+ {
+ GNUNET_break (0);
+ resp = NULL; /* good luck */
+ }
+ ph->cb (ph->cb_cls,
+ status,
+ account_id,
+ inquiry_id,
+ GNUNET_TIME_UNIT_ZERO_ABS,
+ NULL,
+ http_status,
+ resp);
+}
+
+
+/**
+ * Call @a ph callback with HTTP error response.
+ *
+ * @param ph proof handle to generate reply for
+ * @param inquiry_id inquiry ID to supply
+ * @param http_status HTTP status to use
+ * @param template template to instantiate
+ * @param[in] body body for the template to use (reference
+ * is consumed)
+ */
+static void
+proof_reply_error (struct TALER_KYCLOGIC_ProofHandle *ph,
+ const char *inquiry_id,
+ unsigned int http_status,
+ const char *template,
+ json_t *body)
+{
+ proof_generic_reply (ph,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ NULL, /* user id */
+ inquiry_id,
+ http_status,
+ template,
+ body);
+}
+
+
+/**
+ * Return a response for the @a ph request indicating a
+ * protocol violation by the Persona server.
+ *
+ * @param[in,out] ph request we are processing
+ * @param response_code HTTP status returned by Persona
+ * @param inquiry_id ID of the inquiry this is about
+ * @param detail where the response was wrong
+ * @param data full response data to output
+ */
+static void
+return_invalid_response (struct TALER_KYCLOGIC_ProofHandle *ph,
+ unsigned int response_code,
+ const char *inquiry_id,
+ const char *detail,
+ const json_t *data)
+{
+ proof_reply_error (
+ ph,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-invalid-response",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ GNUNET_JSON_pack_string ("persona_inquiry_id",
+ inquiry_id),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY),
+ GNUNET_JSON_pack_string ("detail",
+ detail),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+}
+
+
+/**
+ * Start the external conversion helper.
+ *
+ * @param pd configuration details
+ * @param attr attributes to give to the helper
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle for the helper
+ */
+static struct TALER_JSON_ExternalConversion *
+start_conversion (const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const json_t *attr,
+ TALER_JSON_JsonCallback cb,
+ void *cb_cls)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Calling converter `%s' with JSON\n",
+ pd->conversion_binary);
+ json_dumpf (attr,
+ stderr,
+ JSON_INDENT (2));
+ return TALER_JSON_external_conversion_start (
+ attr,
+ cb,
+ cb_cls,
+ pd->conversion_binary,
+ pd->conversion_binary,
+ "-a",
+ pd->auth_token,
+ NULL
+ );
+}
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure with a `struct TALER_KYCLOGIC_ProofHandle *`
+ * @param status_type how did the process die
+ * @param code termination status code from the process
+ * @param attr result some JSON result, NULL if we failed to get an JSON output
+ */
+static void
+proof_post_conversion_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *attr)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ struct MHD_Response *resp;
+ struct GNUNET_TIME_Absolute expiration;
+
+ ph->ec = NULL;
+ if ( (NULL == attr) ||
+ (0 != code) )
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ MHD_HTTP_OK,
+ ph->inquiry_id,
+ "converter",
+ NULL);
+ persona_proof_cancel (ph);
+ return;
+ }
+ expiration = GNUNET_TIME_relative_to_absolute (ph->pd->validity);
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_LOCATION,
+ ph->pd->post_kyc_redirect_url));
+ TALER_MHD_add_global_headers (resp);
+ ph->cb (ph->cb_cls,
+ TALER_KYCLOGIC_STATUS_SUCCESS,
+ ph->account_id,
+ ph->inquiry_id,
+ expiration,
+ attr,
+ MHD_HTTP_SEE_OTHER,
+ resp);
+ persona_proof_cancel (ph);
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP "/api/v1/inquiries/{inquiry-id}" request.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_InitiateHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_proof_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_ProofHandle *ph = cls;
+ const json_t *j = response;
+ const json_t *data = json_object_get (j,
+ "data");
+
+ ph->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char *inquiry_id;
+ const char *account_id;
+ const char *type = NULL;
+ const json_t *attributes;
+ const json_t *relationships;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_string ("id",
+ &inquiry_id),
+ GNUNET_JSON_spec_object_const ("attributes",
+ &attributes),
+ GNUNET_JSON_spec_object_const ("relationships",
+ &relationships),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if ( (NULL == data) ||
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (data,
+ spec,
+ NULL, NULL)) ||
+ (0 != strcmp (type,
+ "inquiry")) )
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ response_code,
+ inquiry_id,
+ "data",
+ data);
+ break;
+ }
+
+ {
+ const char *status; /* "completed", what else? */
+ const char *reference_id; /* or legitimization number */
+ const char *expired_at = NULL; /* often 'null' format: "2022-08-18T10:14:26.000Z" */
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("status",
+ &status),
+ GNUNET_JSON_spec_string ("reference-id",
+ &reference_id),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("expired-at",
+ &expired_at),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (attributes,
+ ispec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ response_code,
+ inquiry_id,
+ "data-attributes",
+ data);
+ break;
+ }
+ {
+ unsigned long long idr;
+ char dummy;
+
+ if ( (1 != sscanf (reference_id,
+ "%llu%c",
+ &idr,
+ &dummy)) ||
+ (idr != ph->process_row) )
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ response_code,
+ inquiry_id,
+ "data-attributes-reference_id",
+ data);
+ break;
+ }
+ }
+
+ if (0 != strcmp (inquiry_id,
+ ph->inquiry_id))
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ response_code,
+ inquiry_id,
+ "data-id",
+ data);
+ break;
+ }
+
+ account_id = json_string_value (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ relationships,
+ "account"),
+ "data"),
+ "id"));
+
+ if (0 != strcmp (status,
+ "completed"))
+ {
+ proof_generic_reply (
+ ph,
+ TALER_KYCLOGIC_STATUS_FAILED,
+ account_id,
+ inquiry_id,
+ MHD_HTTP_OK,
+ "persona-kyc-failed",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ GNUNET_JSON_pack_string ("persona_inquiry_id",
+ inquiry_id),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ }
+
+ if (NULL == account_id)
+ {
+ GNUNET_break_op (0);
+ return_invalid_response (ph,
+ response_code,
+ inquiry_id,
+ "data-relationships-account-data-id",
+ data);
+ break;
+ }
+ ph->account_id = GNUNET_strdup (account_id);
+ ph->ec = start_conversion (ph->pd,
+ j,
+ &proof_post_conversion_cb,
+ ph);
+ if (NULL == ph->ec)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start Persona conversion helper\n");
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-logic-failure",
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_GENERIC_KYC_CONVERTER_FAILED)));
+ break;
+ }
+ }
+ return; /* continued in proof_post_conversion_cb */
+ }
+ case MHD_HTTP_BAD_REQUEST:
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
+ case MHD_HTTP_UNPROCESSABLE_ENTITY:
+ /* These are errors with this code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-logic-failure",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY),
+
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* These are failures of the exchange operator */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-exchange-unauthorized",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_ACCESS_REFUSED),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ /* These are failures of the exchange operator */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_SERVICE_UNAVAILABLE,
+ "persona-exchange-unpaid",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_ACCESS_REFUSED),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ case MHD_HTTP_REQUEST_TIMEOUT:
+ /* These are networking issues */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_GATEWAY_TIMEOUT,
+ "persona-network-timeout",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_TIMEOUT),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ case MHD_HTTP_TOO_MANY_REQUESTS:
+ /* This is a load issue */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_SERVICE_UNAVAILABLE,
+ "persona-load-failure",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_RATE_LIMIT_EXCEEDED),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* This is an issue with Persona */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-provider-failure",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_PROOF_BACKEND_ERROR),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ default:
+ /* This is an issue with Persona */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ proof_reply_error (
+ ph,
+ ph->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY,
+ "persona-invalid-response",
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("persona_http_status",
+ response_code),
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("data",
+ (json_t *)
+ data))));
+ break;
+ }
+ persona_proof_cancel (ph);
+}
+
+
+/**
+ * Check KYC status and return final result to human.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param connection MHD connection object (for HTTP headers)
+ * @param account_id which account to trigger process for
+ * @param process_row row in the legitimization processes table the legitimization is for
+ * @param provider_user_id user ID (or NULL) the proof is for
+ * @param inquiry_id legitimization ID the proof is for
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_ProofHandle *
+persona_proof (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ const char *provider_user_id,
+ const char *inquiry_id,
+ TALER_KYCLOGIC_ProofCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProofHandle *ph;
+ CURL *eh;
+
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ ph = GNUNET_new (struct TALER_KYCLOGIC_ProofHandle);
+ ph->ps = ps;
+ ph->pd = pd;
+ ph->cb = cb;
+ ph->cb_cls = cb_cls;
+ ph->connection = connection;
+ ph->process_row = process_row;
+ ph->h_payto = *account_id;
+ /* Note: we do not expect this to be non-NULL */
+ if (NULL != provider_user_id)
+ ph->provider_user_id = GNUNET_strdup (provider_user_id);
+ if (NULL != inquiry_id)
+ ph->inquiry_id = GNUNET_strdup (inquiry_id);
+ GNUNET_asprintf (&ph->url,
+ "https://withpersona.com/api/v1/inquiries/%s",
+ inquiry_id);
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 0));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 1L));
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ ph->url));
+ ph->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ pd->slist,
+ &handle_proof_finished,
+ ph);
+ return ph;
+}
+
+
+/**
+ * Cancel KYC webhook execution.
+ *
+ * @param[in] wh handle of operation to cancel
+ */
+static void
+persona_webhook_cancel (struct TALER_KYCLOGIC_WebhookHandle *wh)
+{
+ if (NULL != wh->task)
+ {
+ GNUNET_SCHEDULER_cancel (wh->task);
+ wh->task = NULL;
+ }
+ if (NULL != wh->job)
+ {
+ GNUNET_CURL_job_cancel (wh->job);
+ wh->job = NULL;
+ }
+ if (NULL != wh->ec)
+ {
+ TALER_JSON_external_conversion_stop (wh->ec);
+ wh->ec = NULL;
+ }
+ GNUNET_free (wh->account_id);
+ GNUNET_free (wh->inquiry_id);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+}
+
+
+/**
+ * Call @a wh callback with the operation result.
+ *
+ * @param wh proof handle to generate reply for
+ * @param status status to return
+ * @param account_id account to return
+ * @param inquiry_id inquiry ID to supply
+ * @param attr KYC attribute data for the client
+ * @param http_status HTTP status to use
+ */
+static void
+webhook_generic_reply (struct TALER_KYCLOGIC_WebhookHandle *wh,
+ enum TALER_KYCLOGIC_KycStatus status,
+ const char *account_id,
+ const char *inquiry_id,
+ const json_t *attr,
+ unsigned int http_status)
+{
+ struct MHD_Response *resp;
+ struct GNUNET_TIME_Absolute expiration;
+
+ if (TALER_KYCLOGIC_STATUS_SUCCESS == status)
+ expiration = GNUNET_TIME_relative_to_absolute (wh->pd->validity);
+ else
+ expiration = GNUNET_TIME_UNIT_ZERO_ABS;
+ resp = MHD_create_response_from_buffer (0,
+ "",
+ MHD_RESPMEM_PERSISTENT);
+ TALER_MHD_add_global_headers (resp);
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ &wh->h_payto,
+ wh->pd->section,
+ account_id,
+ inquiry_id,
+ status,
+ expiration,
+ attr,
+ http_status,
+ resp);
+}
+
+
+/**
+ * Call @a wh callback with HTTP error response.
+ *
+ * @param wh proof handle to generate reply for
+ * @param inquiry_id inquiry ID to supply
+ * @param http_status HTTP status to use
+ */
+static void
+webhook_reply_error (struct TALER_KYCLOGIC_WebhookHandle *wh,
+ const char *inquiry_id,
+ unsigned int http_status)
+{
+ webhook_generic_reply (wh,
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ NULL, /* user id */
+ inquiry_id,
+ NULL, /* attributes */
+ http_status);
+}
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure with a `struct TALER_KYCLOGIC_WebhookHandle *`
+ * @param status_type how did the process die
+ * @param code termination status code from the process
+ * @param attr some JSON result, NULL if we failed to get an JSON output
+ */
+static void
+webhook_post_conversion_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *attr)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+
+ wh->ec = NULL;
+ webhook_generic_reply (wh,
+ TALER_KYCLOGIC_STATUS_SUCCESS,
+ wh->account_id,
+ wh->inquiry_id,
+ attr,
+ MHD_HTTP_OK);
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP "/api/v1/inquiries/{inquiry_id}" request.
+ *
+ * @param cls the `struct TALER_KYCLOGIC_WebhookHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_webhook_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+ const json_t *j = response;
+ const json_t *data = json_object_get (j,
+ "data");
+
+ wh->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_OK:
+ {
+ const char *inquiry_id;
+ const char *account_id;
+ const char *type = NULL;
+ const json_t *attributes;
+ const json_t *relationships;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_string ("id",
+ &inquiry_id),
+ GNUNET_JSON_spec_object_const ("attributes",
+ &attributes),
+ GNUNET_JSON_spec_object_const ("relationships",
+ &relationships),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if ( (NULL == data) ||
+ (GNUNET_OK !=
+ GNUNET_JSON_parse (data,
+ spec,
+ NULL, NULL)) ||
+ (0 != strcmp (type,
+ "inquiry")) )
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+
+ {
+ const char *status; /* "completed", what else? */
+ const char *reference_id; /* or legitimization number */
+ const char *expired_at = NULL; /* often 'null' format: "2022-08-18T10:14:26.000Z" */
+ struct GNUNET_JSON_Specification ispec[] = {
+ GNUNET_JSON_spec_string ("status",
+ &status),
+ GNUNET_JSON_spec_string ("reference-id",
+ &reference_id),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("expired-at",
+ &expired_at),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (attributes,
+ ispec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+ {
+ unsigned long long idr;
+ char dummy;
+
+ if ( (1 != sscanf (reference_id,
+ "%llu%c",
+ &idr,
+ &dummy)) ||
+ (idr != wh->process_row) )
+ {
+ GNUNET_break_op (0);
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+ }
+
+ if (0 != strcmp (inquiry_id,
+ wh->inquiry_id))
+ {
+ GNUNET_break_op (0);
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+
+ account_id = json_string_value (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ relationships,
+ "account"),
+ "data"),
+ "id"));
+
+ if (0 != strcmp (status,
+ "completed"))
+ {
+ webhook_generic_reply (wh,
+ TALER_KYCLOGIC_STATUS_FAILED,
+ account_id,
+ inquiry_id,
+ NULL,
+ MHD_HTTP_OK);
+ break;
+ }
+
+ if (NULL == account_id)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (data,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+ wh->account_id = GNUNET_strdup (account_id);
+ wh->ec = start_conversion (wh->pd,
+ j,
+ &webhook_post_conversion_cb,
+ wh);
+ if (NULL == wh->ec)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start Persona conversion helper\n");
+ webhook_reply_error (wh,
+ inquiry_id,
+ MHD_HTTP_INTERNAL_SERVER_ERROR);
+ break;
+ }
+ }
+ return; /* continued in webhook_post_conversion_cb */
+ }
+ case MHD_HTTP_BAD_REQUEST:
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_CONFLICT:
+ case MHD_HTTP_UNPROCESSABLE_ENTITY:
+ /* These are errors with this code */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ case MHD_HTTP_UNAUTHORIZED:
+ /* These are failures of the exchange operator */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_INTERNAL_SERVER_ERROR);
+ break;
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ /* These are failures of the exchange operator */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Refused access with HTTP status code %u\n",
+ (unsigned int) response_code);
+
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_INTERNAL_SERVER_ERROR);
+ break;
+ case MHD_HTTP_REQUEST_TIMEOUT:
+ /* These are networking issues */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_GATEWAY_TIMEOUT);
+ break;
+ case MHD_HTTP_TOO_MANY_REQUESTS:
+ /* This is a load issue */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_SERVICE_UNAVAILABLE);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* This is an issue with Persona */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ default:
+ /* This is an issue with Persona */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "PERSONA failed with response %u:\n",
+ (unsigned int) response_code);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ webhook_reply_error (wh,
+ wh->inquiry_id,
+ MHD_HTTP_BAD_GATEWAY);
+ break;
+ }
+
+ persona_webhook_cancel (wh);
+}
+
+
+/**
+ * Asynchronously return a reply for the webhook.
+ *
+ * @param cls a `struct TALER_KYCLOGIC_WebhookHandle *`
+ */
+static void
+async_webhook_reply (void *cls)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+
+ wh->task = NULL;
+ wh->cb (wh->cb_cls,
+ wh->process_row,
+ (0 == wh->process_row)
+ ? NULL
+ : &wh->h_payto,
+ wh->pd->section,
+ NULL,
+ wh->inquiry_id, /* provider legi ID */
+ TALER_KYCLOGIC_STATUS_PROVIDER_FAILED,
+ GNUNET_TIME_UNIT_ZERO_ABS, /* expiration */
+ NULL,
+ wh->response_code,
+ wh->resp);
+ persona_webhook_cancel (wh);
+}
+
+
+/**
+ * Function called with the provider details and
+ * associated plugin closures for matching logics.
+ *
+ * @param cls closure
+ * @param pd provider details of a matching logic
+ * @param plugin_cls closure of the plugin
+ * @return #GNUNET_OK to continue to iterate
+ */
+static enum GNUNET_GenericReturnValue
+locate_details_cb (
+ void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ void *plugin_cls)
+{
+ struct TALER_KYCLOGIC_WebhookHandle *wh = cls;
+
+ /* This type-checks 'pd' */
+ GNUNET_assert (plugin_cls == wh->ps);
+ if (0 == strcmp (pd->template_id,
+ wh->template_id))
+ {
+ wh->pd = pd;
+ return GNUNET_NO;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Check KYC status and return result for Webhook. We do NOT implement the
+ * authentication check proposed by the PERSONA documentation, as it would
+ * allow an attacker who learns the access token to easily bypass the KYC
+ * checks. Instead, we insist on explicitly requesting the KYC status from the
+ * provider (at least on success).
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param plc callback to lookup accounts with
+ * @param plc_cls closure for @a plc
+ * @param http_method HTTP method used for the webhook
+ * @param url_path rest of the URL after `/kyc-webhook/`
+ * @param connection MHD connection object (for HTTP headers)
+ * @param body HTTP request body
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_WebhookHandle *
+persona_webhook (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ TALER_KYCLOGIC_ProviderLookupCallback plc,
+ void *plc_cls,
+ const char *http_method,
+ const char *const url_path[],
+ struct MHD_Connection *connection,
+ const json_t *body,
+ TALER_KYCLOGIC_WebhookCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+ CURL *eh;
+ enum GNUNET_DB_QueryStatus qs;
+ const char *persona_inquiry_id;
+ const char *auth_header;
+
+ /* Persona webhooks are expected by logic, not by template */
+ GNUNET_break_op (NULL == pd);
+ wh = GNUNET_new (struct TALER_KYCLOGIC_WebhookHandle);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ps = ps;
+ wh->connection = connection;
+ wh->pd = pd;
+ auth_header = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_AUTHORIZATION);
+ if ( (NULL != ps->webhook_token) &&
+ ( (NULL == auth_header) ||
+ (0 != strcmp (ps->webhook_token,
+ auth_header)) ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid authorization header `%s' received for Persona webhook\n",
+ auth_header);
+ wh->resp = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_WEBHOOK_UNAUTHORIZED),
+ GNUNET_JSON_pack_string ("detail",
+ "unexpected 'Authorization' header"));
+ wh->response_code = MHD_HTTP_UNAUTHORIZED;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ wh->template_id
+ = json_string_value (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ body,
+ "data"),
+ "attributes"),
+ "payload"),
+ "data"),
+ "relationships"),
+ "inquiry-template"),
+ "data"),
+ "id"));
+ if (NULL == wh->template_id)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+ wh->resp = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY),
+ GNUNET_JSON_pack_string ("detail",
+ "data-attributes-payload-data-id"),
+ GNUNET_JSON_pack_object_incref ("webhook_body",
+ (json_t *) body));
+ wh->response_code = MHD_HTTP_BAD_REQUEST;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ TALER_KYCLOGIC_kyc_get_details ("persona",
+ &locate_details_cb,
+ wh);
+ if (NULL == wh->pd)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+ wh->resp = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN),
+ GNUNET_JSON_pack_string ("detail",
+ wh->template_id),
+ GNUNET_JSON_pack_object_incref ("webhook_body",
+ (json_t *) body));
+ wh->response_code = MHD_HTTP_BAD_REQUEST;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ persona_inquiry_id
+ = json_string_value (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ json_object_get (
+ body,
+ "data"),
+ "attributes"),
+ "payload"),
+ "data"),
+ "id"));
+ if (NULL == persona_inquiry_id)
+ {
+ GNUNET_break_op (0);
+ json_dumpf (body,
+ stderr,
+ JSON_INDENT (2));
+ wh->resp = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_EXCHANGE_KYC_GENERIC_PROVIDER_UNEXPECTED_REPLY),
+ GNUNET_JSON_pack_string ("detail",
+ "data-attributes-payload-data-id"),
+ GNUNET_JSON_pack_object_incref ("webhook_body",
+ (json_t *) body));
+ wh->response_code = MHD_HTTP_BAD_REQUEST;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ qs = plc (plc_cls,
+ wh->pd->section,
+ persona_inquiry_id,
+ &wh->h_payto,
+ &wh->process_row);
+ if (qs < 0)
+ {
+ wh->resp = TALER_MHD_make_error (TALER_EC_GENERIC_DB_FETCH_FAILED,
+ "provider-legitimization-lookup");
+ wh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received Persona kyc-webhook for unknown verification ID `%s'\n",
+ persona_inquiry_id);
+ wh->resp = TALER_MHD_make_error (
+ TALER_EC_EXCHANGE_KYC_PROOF_REQUEST_UNKNOWN,
+ persona_inquiry_id);
+ wh->response_code = MHD_HTTP_NOT_FOUND;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+ wh->inquiry_id = GNUNET_strdup (persona_inquiry_id);
+
+ eh = curl_easy_init ();
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ wh->resp = TALER_MHD_make_error (
+ TALER_EC_GENERIC_ALLOCATION_FAILURE,
+ NULL);
+ wh->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ wh->task = GNUNET_SCHEDULER_add_now (&async_webhook_reply,
+ wh);
+ return wh;
+ }
+
+ GNUNET_asprintf (&wh->url,
+ "https://withpersona.com/api/v1/inquiries/%s",
+ persona_inquiry_id);
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_VERBOSE,
+ 0));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_MAXREDIRS,
+ 1L));
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_URL,
+ wh->url));
+ wh->job = GNUNET_CURL_job_add2 (ps->curl_ctx,
+ eh,
+ wh->pd->slist,
+ &handle_webhook_finished,
+ wh);
+ return wh;
+}
+
+
+/**
+ * Initialize persona logic plugin
+ *
+ * @param cls a configuration instance
+ * @return NULL on error, otherwise a `struct TALER_KYCLOGIC_Plugin`
+ */
+void *
+libtaler_plugin_kyclogic_persona_init (void *cls)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_KYCLOGIC_Plugin *plugin;
+ struct PluginState *ps;
+
+ ps = GNUNET_new (struct PluginState);
+ ps->cfg = cfg;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &ps->exchange_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ GNUNET_free (ps);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ps->cfg,
+ "kyclogic-persona",
+ "WEBHOOK_AUTH_TOKEN",
+ &ps->webhook_token))
+ {
+ /* optional */
+ ps->webhook_token = NULL;
+ }
+
+ ps->curl_ctx
+ = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &ps->curl_rc);
+ if (NULL == ps->curl_ctx)
+ {
+ GNUNET_break (0);
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ return NULL;
+ }
+ ps->curl_rc = GNUNET_CURL_gnunet_rc_create (ps->curl_ctx);
+
+ plugin = GNUNET_new (struct TALER_KYCLOGIC_Plugin);
+ plugin->cls = ps;
+ plugin->load_configuration
+ = &persona_load_configuration;
+ plugin->unload_configuration
+ = &persona_unload_configuration;
+ plugin->initiate
+ = &persona_initiate;
+ plugin->initiate_cancel
+ = &persona_initiate_cancel;
+ plugin->proof
+ = &persona_proof;
+ plugin->proof_cancel
+ = &persona_proof_cancel;
+ plugin->webhook
+ = &persona_webhook;
+ plugin->webhook_cancel
+ = &persona_webhook_cancel;
+ return plugin;
+}
+
+
+/**
+ * Unload authorization plugin
+ *
+ * @param cls a `struct TALER_KYCLOGIC_Plugin`
+ * @return NULL (always)
+ */
+void *
+libtaler_plugin_kyclogic_persona_done (void *cls)
+{
+ struct TALER_KYCLOGIC_Plugin *plugin = cls;
+ struct PluginState *ps = plugin->cls;
+
+ if (NULL != ps->curl_ctx)
+ {
+ GNUNET_CURL_fini (ps->curl_ctx);
+ ps->curl_ctx = NULL;
+ }
+ if (NULL != ps->curl_rc)
+ {
+ GNUNET_CURL_gnunet_rc_destroy (ps->curl_rc);
+ ps->curl_rc = NULL;
+ }
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps->webhook_token);
+ GNUNET_free (ps);
+ GNUNET_free (plugin);
+ return NULL;
+}
+
+
+/* end of plugin_kyclogic_persona.c */
diff --git a/src/kyclogic/plugin_kyclogic_template.c b/src/kyclogic/plugin_kyclogic_template.c
new file mode 100644
index 000000000..54f36e6f2
--- /dev/null
+++ b/src/kyclogic/plugin_kyclogic_template.c
@@ -0,0 +1,468 @@
+/*
+ This file is part of GNU Taler
+ Copyright (C) 2022 Taler Systems SA
+
+ Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ Taler; see the file COPYING.GPL. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file plugin_kyclogic_template.c
+ * @brief template for an authentication flow logic
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_kyclogic_plugin.h"
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include <regex.h>
+#include "taler_util.h"
+
+
+/**
+ * Saves the state of a plugin.
+ */
+struct PluginState
+{
+
+ /**
+ * Our base URL.
+ */
+ char *exchange_base_url;
+
+ /**
+ * Our global configuration.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Context for CURL operations (useful to the event loop)
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * Context for integrating @e curl_ctx with the
+ * GNUnet event loop.
+ */
+ struct GNUNET_CURL_RescheduleContext *curl_rc;
+
+};
+
+
+/**
+ * Keeps the plugin-specific state for
+ * a given configuration section.
+ */
+struct TALER_KYCLOGIC_ProviderDetails
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Configuration section that configured us.
+ */
+ char *section;
+
+};
+
+
+/**
+ * Handle for an initiation operation.
+ */
+struct TALER_KYCLOGIC_InitiateHandle
+{
+
+ /**
+ * Hash of the payto:// URI we are initiating
+ * the KYC for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * UUID being checked.
+ */
+ uint64_t legitimization_uuid;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_InitiateCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+};
+
+
+/**
+ * Handle for an KYC proof operation.
+ */
+struct TALER_KYCLOGIC_ProofHandle
+{
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Continuation to call.
+ */
+ TALER_KYCLOGIC_ProofCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+};
+
+
+/**
+ * Handle for an KYC Web hook operation.
+ */
+struct TALER_KYCLOGIC_WebhookHandle
+{
+
+ /**
+ * Continuation to call when done.
+ */
+ TALER_KYCLOGIC_WebhookCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Task for asynchronous execution.
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Overall plugin state.
+ */
+ struct PluginState *ps;
+
+ /**
+ * Our configuration details.
+ */
+ const struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Connection we are handling.
+ */
+ struct MHD_Connection *connection;
+};
+
+
+/**
+ * Release configuration resources previously loaded
+ *
+ * @param[in] pd configuration to release
+ */
+static void
+template_unload_configuration (struct TALER_KYCLOGIC_ProviderDetails *pd)
+{
+ GNUNET_free (pd);
+}
+
+
+/**
+ * Load the configuration of the KYC provider.
+ *
+ * @param cls closure
+ * @param provider_section_name configuration section to parse
+ * @return NULL if configuration is invalid
+ */
+static struct TALER_KYCLOGIC_ProviderDetails *
+template_load_configuration (void *cls,
+ const char *provider_section_name)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ pd = GNUNET_new (struct TALER_KYCLOGIC_ProviderDetails);
+ pd->ps = ps;
+ pd->section = GNUNET_strdup (provider_section_name);
+ GNUNET_break (0); // FIXME: parse config here!
+ return pd;
+}
+
+
+/**
+ * Cancel KYC check initiation.
+ *
+ * @param[in] ih handle of operation to cancel
+ */
+static void
+template_initiate_cancel (struct TALER_KYCLOGIC_InitiateHandle *ih)
+{
+ GNUNET_break (0); // FIXME: add cancel logic here
+ GNUNET_free (ih);
+}
+
+
+/**
+ * Initiate KYC check.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param account_id which account to trigger process for
+ * @param legitimization_uuid unique ID for the legitimization process
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_InitiateHandle *
+template_initiate (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t legitimization_uuid,
+ TALER_KYCLOGIC_InitiateCallback cb,
+ void *cb_cls)
+{
+ struct TALER_KYCLOGIC_InitiateHandle *ih;
+
+ (void) cls;
+ ih = GNUNET_new (struct TALER_KYCLOGIC_InitiateHandle);
+ ih->legitimization_uuid = legitimization_uuid;
+ ih->cb = cb;
+ ih->cb_cls = cb_cls;
+ ih->h_payto = *account_id;
+ ih->pd = pd;
+ GNUNET_break (0); // FIXME: add actual initiation logic!
+ return ih;
+}
+
+
+/**
+ * Cancel KYC proof.
+ *
+ * @param[in] ph handle of operation to cancel
+ */
+static void
+template_proof_cancel (struct TALER_KYCLOGIC_ProofHandle *ph)
+{
+ GNUNET_break (0); // FIXME: stop activities...
+ GNUNET_free (ph);
+}
+
+
+/**
+ * Check KYC status and return status to human.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param connection MHD connection object (for HTTP headers)
+ * @param account_id which account to trigger process for
+ * @param process_row row in the legitimization processes table the legitimization is for
+ * @param provider_user_id user ID (or NULL) the proof is for
+ * @param provider_legitimization_id legitimization ID the proof is for
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_ProofHandle *
+template_proof (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ struct MHD_Connection *connection,
+ const struct TALER_PaytoHashP *account_id,
+ uint64_t process_row,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ TALER_KYCLOGIC_ProofCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_ProofHandle *ph;
+
+ (void) account_id;
+ (void) process_row;
+ (void) provider_user_id;
+ (void) provider_legitimization_id;
+ ph = GNUNET_new (struct TALER_KYCLOGIC_ProofHandle);
+ ph->ps = ps;
+ ph->pd = pd;
+ ph->cb = cb;
+ ph->cb_cls = cb_cls;
+ ph->connection = connection;
+
+ GNUNET_break (0); // FIXME: start check!
+ return ph;
+}
+
+
+/**
+ * Cancel KYC webhook execution.
+ *
+ * @param[in] wh handle of operation to cancel
+ */
+static void
+template_webhook_cancel (struct TALER_KYCLOGIC_WebhookHandle *wh)
+{
+ GNUNET_break (0); /* FIXME: stop activity */
+ GNUNET_free (wh);
+}
+
+
+/**
+ * Check KYC status and return result for Webhook.
+ *
+ * @param cls the @e cls of this struct with the plugin-specific state
+ * @param pd provider configuration details
+ * @param plc callback to lookup accounts with
+ * @param plc_cls closure for @a plc
+ * @param http_method HTTP method used for the webhook
+ * @param url_path rest of the URL after `/kyc-webhook/`
+ * @param connection MHD connection object (for HTTP headers)
+ * @param body HTTP request body
+ * @param cb function to call with the result
+ * @param cb_cls closure for @a cb
+ * @return handle to cancel operation early
+ */
+static struct TALER_KYCLOGIC_WebhookHandle *
+template_webhook (void *cls,
+ const struct TALER_KYCLOGIC_ProviderDetails *pd,
+ TALER_KYCLOGIC_ProviderLookupCallback plc,
+ void *plc_cls,
+ const char *http_method,
+ const char *const url_path[],
+ struct MHD_Connection *connection,
+ const json_t *body,
+ TALER_KYCLOGIC_WebhookCallback cb,
+ void *cb_cls)
+{
+ struct PluginState *ps = cls;
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+
+ (void) plc;
+ (void) plc_cls;
+ (void) http_method;
+ (void) url_path;
+ (void) body;
+ wh = GNUNET_new (struct TALER_KYCLOGIC_WebhookHandle);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ps = ps;
+ wh->pd = pd;
+ wh->connection = connection;
+ GNUNET_break (0); /* FIXME: start activity */
+ return wh;
+}
+
+
+/**
+ * Initialize Template.0 KYC logic plugin
+ *
+ * @param cls a configuration instance
+ * @return NULL on error, otherwise a `struct TALER_KYCLOGIC_Plugin`
+ */
+void *
+libtaler_plugin_kyclogic_template_init (void *cls)
+{
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ struct TALER_KYCLOGIC_Plugin *plugin;
+ struct PluginState *ps;
+
+ ps = GNUNET_new (struct PluginState);
+ ps->cfg = cfg;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &ps->exchange_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ GNUNET_free (ps);
+ return NULL;
+ }
+
+ ps->curl_ctx
+ = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &ps->curl_rc);
+ if (NULL == ps->curl_ctx)
+ {
+ GNUNET_break (0);
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ return NULL;
+ }
+ ps->curl_rc = GNUNET_CURL_gnunet_rc_create (ps->curl_ctx);
+
+ plugin = GNUNET_new (struct TALER_KYCLOGIC_Plugin);
+ plugin->cls = ps;
+ plugin->load_configuration
+ = &template_load_configuration;
+ plugin->unload_configuration
+ = &template_unload_configuration;
+ plugin->initiate
+ = &template_initiate;
+ plugin->initiate_cancel
+ = &template_initiate_cancel;
+ plugin->proof
+ = &template_proof;
+ plugin->proof_cancel
+ = &template_proof_cancel;
+ plugin->webhook
+ = &template_webhook;
+ plugin->webhook_cancel
+ = &template_webhook_cancel;
+ return plugin;
+}
+
+
+/**
+ * Unload authorization plugin
+ *
+ * @param cls a `struct TALER_KYCLOGIC_Plugin`
+ * @return NULL (always)
+ */
+void *
+libtaler_plugin_kyclogic_template_done (void *cls)
+{
+ struct TALER_KYCLOGIC_Plugin *plugin = cls;
+ struct PluginState *ps = plugin->cls;
+
+ if (NULL != ps->curl_ctx)
+ {
+ GNUNET_CURL_fini (ps->curl_ctx);
+ ps->curl_ctx = NULL;
+ }
+ if (NULL != ps->curl_rc)
+ {
+ GNUNET_CURL_gnunet_rc_destroy (ps->curl_rc);
+ ps->curl_rc = NULL;
+ }
+ GNUNET_free (ps->exchange_base_url);
+ GNUNET_free (ps);
+ GNUNET_free (plugin);
+ return NULL;
+}
diff --git a/src/kyclogic/sample.conf b/src/kyclogic/sample.conf
new file mode 100644
index 000000000..b9a88c292
--- /dev/null
+++ b/src/kyclogic/sample.conf
@@ -0,0 +1,33 @@
+# This file is in the public domain.
+#
+
+[exchange]
+
+# HTTP port the exchange listens to
+PORT = 8081
+
+# Base URL of the exchange. Must be set to a URL where the
+# exchange (or the twister) is actually listening.
+BASE_URL = "http://localhost:8081/"
+
+[kyc-provider-test-oauth2]
+
+COST = 0
+LOGIC = oauth2
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = DUMMY
+
+KYC_OAUTH2_VALIDITY = forever
+KYC_OAUTH2_AUTH_URL = http://kyc.taler.net/auth
+KYC_OAUTH2_LOGIN_URL = http://kyc.taler.net/login
+KYC_OAUTH2_INFO_URL = http://kyc.taler.net/info
+KYC_OAUTH2_POST_URL = http://kyc.taler.net/thank-you
+KYC_OAUTH2_CLIENT_ID = testcase
+KYC_OAUTH2_CLIENT_SECRET = password
+
+[kyc-legitimization-withdraw-high]
+
+OPERATION_TYPE = WITHDRAW
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = KUDOS:100
+TIMEFRAME = 1a
diff --git a/src/kyclogic/taler-exchange-kyc-kycaid-converter.sh b/src/kyclogic/taler-exchange-kyc-kycaid-converter.sh
new file mode 100755
index 000000000..68a1b6a0d
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-kycaid-converter.sh
@@ -0,0 +1,90 @@
+#!/bin/bash
+# This file is in the public domain.
+#
+# This code converts (some of) the JSON output from KYCAID into the GNU Taler
+# specific KYC attribute data (again in JSON format). We may need to download
+# and inline file data in the process, for authorization pass "-a" with the
+# respective bearer token.
+#
+
+# Die if anything goes wrong.
+set -eu
+
+# Parse command-line options
+while getopts ':a:' OPTION; do
+ case "$OPTION" in
+ a)
+ TOKEN="$OPTARG"
+ ;;
+ ?)
+ echo "Unrecognized command line option"
+ exit 1
+ ;;
+ esac
+done
+
+# First, extract everything from stdin.
+J=$(jq '{"type":.type,"email":.email,"phone":.phone,"first_name":.first_name,"name-middle":.middle_name,"last_name":.last_name,"dob":.dob,"residence_country":.residence_country,"gender":.gender,"pep":.pep,"addresses":.addresses,"documents":.documents,"company_name":.company_name,"business_activity_id":.business_activity_id,"registration_country":.registration_country,"documents":.documents,"decline_reasons":.decline_reasons}')
+
+# TODO:
+# log_failure (json_object_get (j, "decline_reasons"));
+
+TYPE=$(echo "$J" | jq -r '.type')
+
+N=0
+DOCS_RAW=""
+DOCS_JSON=""
+for ID in $(jq -r '.documents[]|select(.status=="valid")|.id')
+do
+ TYPE=$(jq -r ".documents[]|select(.id==\"$ID\")|.type")
+ EXPIRY=$(jq -r ".documents[]|select(.id==\"$ID\")|.expiry_date")
+ DOCUMENT_FILE=$(mktemp -t tmp.XXXXXXXXXX)
+ # Authorization: Token $TOKEN
+ DOCUMENT_URL="https://api.kycaid.com/documents/$ID"
+ if [ -z "${TOKEN:-}" ]
+ then
+ wget -q --output-document=- "$DOCUMENT_URL" \
+ | gnunet-base32 > ${DOCUMENT_FILE}
+ else
+ wget -q --output-document=- "$DOCUMENT_URL" \
+ --header "Authorization: Token $TOKEN" \
+ | gnunet-base32 > ${DOCUMENT_FILE}
+ fi
+ DOCS_RAW="$DOCS_RAW --rawfile photo$N \"${DOCUMENT_FILE}\""
+ if [ "$N" = 0 ]
+ then
+ DOCS_JSON="{\"type\":\"$TYPE\",\"image\":\$photo$N}"
+ else
+ DOCS_JSON="{\"type\":\"$TYPE\",\"image\":\$photo$N},$DOCS_JSON"
+ fi
+ N=$(expr $N + 1)
+done
+
+
+if [ "PERSON" = "${TYPE}" ]
+then
+
+ # Next, combine some fields into larger values.
+ FULLNAME=$(echo "$J" | jq -r '[.first_name,.middle_name,.last_name]|join(" ")')
+# STREET=$(echo $J | jq -r '[."street-1",."street-2"]|join(" ")')
+# CITY=$(echo $J | jq -r '[.postcode,.city,."address-subdivision,.cc"]|join(" ")')
+
+ # Combine into final result for individual.
+ echo "$J" \
+ | jq \
+ --arg full_name "${FULLNAME}" \
+ '{$full_name,"birthdate":.dob,"pep":.pep,"phone":.phone,"email":.email,"residences":.residence_country}' \
+ | jq \
+ 'del(..|select(.==null))'
+
+else
+ # Combine into final result for business.
+ echo "$J" \
+ | jq \
+ $DOCS_RAW \
+ "{\"company_name\":.company_name,\"phone\":.phone,\"email\":.email,\"registration_country\":.registration_country,\"documents\":[${DOCS_JSON}]}" \
+ | jq \
+ 'del(..|select(.==null))'
+fi
+
+exit 0
diff --git a/src/kyclogic/taler-exchange-kyc-oauth2-challenger.sh b/src/kyclogic/taler-exchange-kyc-oauth2-challenger.sh
new file mode 100755
index 000000000..729abc504
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-oauth2-challenger.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+# This file is in the public domain.
+#
+# This code converts (some of) the JSON output from
+# Challenger into the GNU Taler
+# specific KYC attribute data (again in JSON format).
+#
+
+# Die if anything goes wrong.
+set -eu
+
+# First, extract everything from stdin.
+J=$(jq '{"id":.id,"email":.address,"type":.address_type,"expires":.address_expiration}')
+
+ADDRESS_TYPE=$(echo "$J" | jq -r '.type')
+ROWID=$(echo "$J" | jq -r '.id')
+if [ "$ADDRESS_TYPE" != "email" ]
+then
+ return 1
+fi
+
+echo "$J" \
+ | jq \
+ --arg id "${ROWID}" \
+ '{$id,"email":.email,"expires":.expires}'
+
+exit 0
diff --git a/src/kyclogic/taler-exchange-kyc-oauth2-nda.sh b/src/kyclogic/taler-exchange-kyc-oauth2-nda.sh
new file mode 100755
index 000000000..5af785f19
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-oauth2-nda.sh
@@ -0,0 +1,30 @@
+#!/bin/bash
+# This file is in the public domain.
+#
+# This code converts (some of) the JSON output from NDA into the GNU Taler
+# specific KYC attribute data (again in JSON format).
+#
+
+# Die if anything goes wrong.
+set -eu
+
+# First, extract everything from stdin.
+J=$(jq '{"status":.status,"id":.data.id,"last":.data.last_name,"first":.data.first_name,"phone":.data.phone}')
+
+STATUS=$(echo "$J" | jq -r '.status')
+if [ "$STATUS" != "success" ]
+then
+ return 1
+fi
+
+# Next, combine some fields into larger values.
+FULLNAME=$(echo "$J" | jq -r '[.first_name,.last_name]|join(" ")')
+
+echo "$J" \
+ | jq \
+ --arg full_name "${FULLNAME}" \
+ '{$full_name,"phone":.phone,"id":.id}' \
+ | jq \
+ 'del(..|select(.==null))'
+
+exit 0
diff --git a/src/kyclogic/taler-exchange-kyc-oauth2-test-converter.sh b/src/kyclogic/taler-exchange-kyc-oauth2-test-converter.sh
new file mode 100755
index 000000000..76f9f16c4
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-oauth2-test-converter.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+# This file is in the public domain.
+#
+# This code converts (some of) the JSON output from
+# Challenger into the GNU Taler
+# specific KYC attribute data (again in JSON format).
+#
+
+# Die if anything goes wrong.
+set -eu
+
+
+# First, extract everything from stdin.
+J=$(jq '{"id":.data.id,"first":.data.first_name,"last":.data.last_name,"birthdate":.data.birthdate,"status":.status}')
+
+# Next, combine some fields into larger values.
+STATUS=$(echo "$J" | jq -r '.status')
+if [ "$STATUS" != "success" ]
+then
+ exit 1
+fi
+
+FULLNAME=$(echo "$J" | jq -r '[.first,.last]|join(" ")')
+
+echo $J \
+ | jq \
+ --arg full_name "${FULLNAME}" \
+ '{$full_name,"birthdate":.birthdate,"id":.id}' \
+ | jq \
+ 'del(..|select(.==null))'
+exit 0
diff --git a/src/kyclogic/taler-exchange-kyc-persona-converter.sh b/src/kyclogic/taler-exchange-kyc-persona-converter.sh
new file mode 100755
index 000000000..13142d0e5
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-persona-converter.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+# This file is in the public domain.
+#
+# This code converts (some of) the JSON output from Persona into the GNU Taler
+# specific KYC attribute data (again in JSON format). We may need to download
+# and inline file data in the process, for authorization pass "-a" with the
+# respective bearer token.
+#
+
+# Die if anything goes wrong.
+set -eu
+
+# Parse command-line options
+while getopts ':a:' OPTION; do
+ case "$OPTION" in
+ a)
+ TOKEN="$OPTARG"
+ ;;
+ ?)
+ echo "Unrecognized command line option"
+ exit 1
+ ;;
+ esac
+done
+
+
+# First, extract everything from stdin.
+J=$(jq '{"first":.data.attributes."name-first","middle":.data.attributes."name-middle","last":.data.attributes."name-last","cc":.data.attributes.fields."address-country-code".value,"birthdate":.data.attributes.birthdate,"city":.data.attributes."address-city","postcode":.data.attributes."address-postal-code","street-1":.data.attributes."address-street-1","street-2":.data.attributes."address-street-2","address-subdivision":.data.attributes."address-subdivision","identification-number":.data.attributes."identification-number","photo":.included[]|select(.type=="verification/government-id")|.attributes|select(.status=="passed")|."front-photo-url"}')
+
+
+# Next, combine some fields into larger values.
+FULLNAME=$(echo "$J" | jq -r '[.first,.middle,.last]|join(" ")')
+STREET=$(echo $J | jq -r '[."street-1",."street-2"]|join(" ")')
+CITY=$(echo $J | jq -r '[.postcode,.city,."address-subdivision,.cc"]|join(" ")')
+
+# Download and base32-encode the photo
+PHOTO_URL=$(echo "$J" | jq -r '.photo')
+PHOTO_FILE=$(mktemp -t tmp.XXXXXXXXXX)
+if [ -z "${TOKEN:-}" ]
+then
+ wget -q --output-document=- "$PHOTO_URL" | gnunet-base32 > ${PHOTO_FILE}
+else
+ wget -q --output-document=- --header "Authorization: Bearer $TOKEN" "$PHOTO_URL" | gnunet-base32 > ${PHOTO_FILE}
+fi
+
+# Combine into final result.
+echo "$J" \
+ | jq \
+ --arg full_name "${FULLNAME}" \
+ --arg street "${STREET}" \
+ --arg city "${CITY}" \
+ --rawfile photo "${PHOTO_FILE}" \
+ '{$full_name,$street,$city,"birthdate":.birthdate,"residences":.cc,"identification_number":."identification-number",$photo}' \
+ | jq \
+ 'del(..|select(.==null))'
+
+exit 0
diff --git a/src/kyclogic/taler-exchange-kyc-tester.c b/src/kyclogic/taler-exchange-kyc-tester.c
new file mode 100644
index 000000000..c2efafd72
--- /dev/null
+++ b/src/kyclogic/taler-exchange-kyc-tester.c
@@ -0,0 +1,1646 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU Affero General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file taler-exchange-kyc-tester.c
+ * @brief tool to test KYC integrations
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <jansson.h>
+#include <microhttpd.h>
+#include <sched.h>
+#include <sys/resource.h>
+#include <limits.h>
+#include "taler_mhd_lib.h"
+#include "taler_json_lib.h"
+#include "taler_templating_lib.h"
+#include "taler_util.h"
+#include "taler_kyclogic_lib.h"
+#include "taler_kyclogic_plugin.h"
+#include <gnunet/gnunet_mhd_compat.h>
+
+
+/**
+ * @brief Context in which the exchange is processing
+ * all requests
+ */
+struct TEKT_RequestContext
+{
+
+ /**
+ * Opaque parsing context.
+ */
+ void *opaque_post_parsing_context;
+
+ /**
+ * Request handler responsible for this request.
+ */
+ const struct TEKT_RequestHandler *rh;
+
+ /**
+ * Request URL (for logging).
+ */
+ const char *url;
+
+ /**
+ * Connection we are processing.
+ */
+ struct MHD_Connection *connection;
+
+ /**
+ * HTTP response to return (or NULL).
+ */
+ struct MHD_Response *response;
+
+ /**
+ * @e rh-specific cleanup routine. Function called
+ * upon completion of the request that should
+ * clean up @a rh_ctx. Can be NULL.
+ */
+ void
+ (*rh_cleaner)(struct TEKT_RequestContext *rc);
+
+ /**
+ * @e rh-specific context. Place where the request
+ * handler can associate state with this request.
+ * Can be NULL.
+ */
+ void *rh_ctx;
+
+ /**
+ * Uploaded JSON body, if any.
+ */
+ json_t *root;
+
+ /**
+ * HTTP status to return upon resume if @e response
+ * is non-NULL.
+ */
+ unsigned int http_status;
+
+};
+
+
+/**
+ * @brief Struct describing an URL and the handler for it.
+ */
+struct TEKT_RequestHandler
+{
+
+ /**
+ * URL the handler is for (first part only).
+ */
+ const char *url;
+
+ /**
+ * Method the handler is for.
+ */
+ const char *method;
+
+ /**
+ * Callbacks for handling of the request. Which one is used
+ * depends on @e method.
+ */
+ union
+ {
+ /**
+ * Function to call to handle a GET requests (and those
+ * with @e method NULL).
+ *
+ * @param rc context for the request
+ * @param mime_type the @e mime_type for the reply (hint, can be NULL)
+ * @param args array of arguments, needs to be of length @e args_expected
+ * @return MHD result code
+ */
+ MHD_RESULT
+ (*get)(struct TEKT_RequestContext *rc,
+ const char *const args[]);
+
+
+ /**
+ * Function to call to handle a POST request.
+ *
+ * @param rc context for the request
+ * @param json uploaded JSON data
+ * @param args array of arguments, needs to be of length @e args_expected
+ * @return MHD result code
+ */
+ MHD_RESULT
+ (*post)(struct TEKT_RequestContext *rc,
+ const json_t *root,
+ const char *const args[]);
+
+ } handler;
+
+ /**
+ * Number of arguments this handler expects in the @a args array.
+ */
+ unsigned int nargs;
+
+ /**
+ * Is the number of arguments given in @e nargs only an upper bound,
+ * and calling with fewer arguments could be OK?
+ */
+ bool nargs_is_upper_bound;
+
+ /**
+ * Mime type to use in reply (hint, can be NULL).
+ */
+ const char *mime_type;
+
+ /**
+ * Raw data for the @e handler, can be NULL for none provided.
+ */
+ const void *data;
+
+ /**
+ * Number of bytes in @e data, 0 for data is 0-terminated (!).
+ */
+ size_t data_size;
+
+ /**
+ * Default response code. 0 for none provided.
+ */
+ unsigned int response_code;
+};
+
+
+/**
+ * Information we track per ongoing kyc-proof request.
+ */
+struct ProofRequestState
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct ProofRequestState *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct ProofRequestState *prev;
+
+ /**
+ * Handle for operation with the plugin.
+ */
+ struct TALER_KYCLOGIC_ProofHandle *ph;
+
+ /**
+ * Logic plugin we are using.
+ */
+ struct TALER_KYCLOGIC_Plugin *logic;
+
+ /**
+ * HTTP request details.
+ */
+ struct TEKT_RequestContext *rc;
+
+};
+
+/**
+ * Head of DLL.
+ */
+static struct ProofRequestState *rs_head;
+
+/**
+ * Tail of DLL.
+ */
+static struct ProofRequestState *rs_tail;
+
+/**
+ * The exchange's configuration (global)
+ */
+static const struct GNUNET_CONFIGURATION_Handle *TEKT_cfg;
+
+/**
+ * Handle to the HTTP server.
+ */
+static struct MHD_Daemon *mhd;
+
+/**
+ * Our base URL.
+ */
+static char *TEKT_base_url;
+
+/**
+ * Payto set via command-line (or otherwise random).
+ */
+static struct TALER_PaytoHashP cmd_line_h_payto;
+
+/**
+ * Provider user ID to use.
+ */
+static char *cmd_provider_user_id;
+
+/**
+ * Provider legitimization ID to use.
+ */
+static char *cmd_provider_legitimization_id;
+
+/**
+ * Name of the configuration section with the
+ * configuration data of the selected provider.
+ */
+static const char *provider_section_name;
+
+/**
+ * Row ID to use, override with '-r'
+ */
+static unsigned int kyc_row_id = 42;
+
+/**
+ * -P command-line option.
+ */
+static int print_h_payto;
+
+/**
+ * -w command-line option.
+ */
+static int run_webservice;
+
+/**
+ * Value to return from main()
+ */
+static int global_ret;
+
+/**
+ * -r command-line flag.
+ */
+static char *requirements;
+
+/**
+ * -i command-line flag.
+ */
+static char *ut_s = "individual";
+
+/**
+ * Handle for ongoing initiation operation.
+ */
+static struct TALER_KYCLOGIC_InitiateHandle *ih;
+
+/**
+ * KYC logic running for @e ih.
+ */
+static struct TALER_KYCLOGIC_Plugin *ih_logic;
+
+/**
+ * Port to run the daemon on.
+ */
+static uint16_t serve_port;
+
+/**
+ * Context for all CURL operations (useful to the event loop)
+ */
+static struct GNUNET_CURL_Context *TEKT_curl_ctx;
+
+/**
+ * Context for integrating #TEKT_curl_ctx with the
+ * GNUnet event loop.
+ */
+static struct GNUNET_CURL_RescheduleContext *exchange_curl_rc;
+
+
+/**
+ * Context for the webhook.
+ */
+struct KycWebhookContext
+{
+
+ /**
+ * Kept in a DLL while suspended.
+ */
+ struct KycWebhookContext *next;
+
+ /**
+ * Kept in a DLL while suspended.
+ */
+ struct KycWebhookContext *prev;
+
+ /**
+ * Details about the connection we are processing.
+ */
+ struct TEKT_RequestContext *rc;
+
+ /**
+ * Plugin responsible for the webhook.
+ */
+ struct TALER_KYCLOGIC_Plugin *plugin;
+
+ /**
+ * Configuration for the specific action.
+ */
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+
+ /**
+ * Webhook activity.
+ */
+ struct TALER_KYCLOGIC_WebhookHandle *wh;
+
+ /**
+ * HTTP response to return.
+ */
+ struct MHD_Response *response;
+
+ /**
+ * Name of the configuration
+ * section defining the KYC logic.
+ */
+ const char *section_name;
+
+ /**
+ * HTTP response code to return.
+ */
+ unsigned int response_code;
+
+ /**
+ * #GNUNET_YES if we are suspended,
+ * #GNUNET_NO if not.
+ * #GNUNET_SYSERR if we had some error.
+ */
+ enum GNUNET_GenericReturnValue suspended;
+
+};
+
+
+/**
+ * Contexts are kept in a DLL while suspended.
+ */
+static struct KycWebhookContext *kwh_head;
+
+/**
+ * Contexts are kept in a DLL while suspended.
+ */
+static struct KycWebhookContext *kwh_tail;
+
+
+/**
+ * Resume processing the @a kwh request.
+ *
+ * @param kwh request to resume
+ */
+static void
+kwh_resume (struct KycWebhookContext *kwh)
+{
+ GNUNET_assert (GNUNET_YES == kwh->suspended);
+ kwh->suspended = GNUNET_NO;
+ GNUNET_CONTAINER_DLL_remove (kwh_head,
+ kwh_tail,
+ kwh);
+ MHD_resume_connection (kwh->rc->connection);
+}
+
+
+static void
+kyc_webhook_cleanup (void)
+{
+ struct KycWebhookContext *kwh;
+
+ while (NULL != (kwh = kwh_head))
+ {
+ if (NULL != kwh->wh)
+ {
+ kwh->plugin->webhook_cancel (kwh->wh);
+ kwh->wh = NULL;
+ }
+ kwh_resume (kwh);
+ }
+}
+
+
+/**
+ * Function called with the result of a webhook
+ * operation.
+ *
+ * Note that the "decref" for the @a response
+ * will be done by the plugin.
+ *
+ * @param cls closure
+ * @param process_row legitimization process request the webhook was about
+ * @param account_id account the webhook was about
+ * @param provider_section configuration section of the logic
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param status KYC status
+ * @param expiration until when is the KYC check valid
+ * @param attributes user attributes returned by the provider
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ */
+static void
+webhook_finished_cb (
+ void *cls,
+ uint64_t process_row,
+ const struct TALER_PaytoHashP *account_id,
+ const char *provider_section,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ enum TALER_KYCLOGIC_KycStatus status,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response)
+{
+ struct KycWebhookContext *kwh = cls;
+
+ (void) expiration;
+ (void) provider_section;
+ kwh->wh = NULL;
+ if ( (NULL != account_id) &&
+ (0 != GNUNET_memcmp (account_id,
+ &cmd_line_h_payto)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received webhook for unexpected account\n");
+ }
+ if ( (NULL != provider_user_id) &&
+ (NULL != cmd_provider_user_id) &&
+ (0 != strcmp (provider_user_id,
+ cmd_provider_user_id)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received webhook for unexpected provider user ID (%s)\n",
+ provider_user_id);
+ }
+ if ( (NULL != provider_legitimization_id) &&
+ (NULL != cmd_provider_legitimization_id) &&
+ (0 != strcmp (provider_legitimization_id,
+ cmd_provider_legitimization_id)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Received webhook for unexpected provider legitimization ID (%s)\n",
+ provider_legitimization_id);
+ }
+ switch (status)
+ {
+ case TALER_KYCLOGIC_STATUS_SUCCESS:
+ /* _successfully_ resumed case */
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "KYC successful for user `%s' (legi: %s)\n",
+ provider_user_id,
+ provider_legitimization_id);
+ GNUNET_break (NULL != attributes);
+ fprintf (stderr,
+ "Extracted attributes:\n");
+ json_dumpf (attributes,
+ stderr,
+ JSON_INDENT (2));
+ break;
+ default:
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "KYC status of %s/%s (process #%llu) is %d\n",
+ provider_user_id,
+ provider_legitimization_id,
+ (unsigned long long) process_row,
+ status);
+ break;
+ }
+ kwh->response = response;
+ kwh->response_code = http_status;
+ kwh_resume (kwh);
+ TALER_MHD_daemon_trigger ();
+}
+
+
+/**
+ * Function called to clean up a context.
+ *
+ * @param rc request context
+ */
+static void
+clean_kwh (struct TEKT_RequestContext *rc)
+{
+ struct KycWebhookContext *kwh = rc->rh_ctx;
+
+ if (NULL != kwh->wh)
+ {
+ kwh->plugin->webhook_cancel (kwh->wh);
+ kwh->wh = NULL;
+ }
+ if (NULL != kwh->response)
+ {
+ MHD_destroy_response (kwh->response);
+ kwh->response = NULL;
+ }
+ GNUNET_free (kwh);
+}
+
+
+/**
+ * Function the plugin can use to lookup an
+ * @a h_payto by @a provider_legitimization_id.
+ *
+ * @param cls closure, NULL
+ * @param provider_section
+ * @param provider_legitimization_id legi to look up
+ * @param[out] h_payto where to write the result
+ * @param[out] legi_row where to write the row ID for the legitimization ID
+ * @return database transaction status
+ */
+static enum GNUNET_DB_QueryStatus
+kyc_provider_account_lookup (
+ void *cls,
+ const char *provider_section,
+ const char *provider_legitimization_id,
+ struct TALER_PaytoHashP *h_payto,
+ uint64_t *legi_row)
+{
+ (void) cls;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Simulated account lookup using `%s/%s'\n",
+ provider_section,
+ provider_legitimization_id);
+ *h_payto = cmd_line_h_payto;
+ *legi_row = kyc_row_id;
+ return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+}
+
+
+/**
+ * Handle a (GET or POST) "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param method HTTP request method used by the client
+ * @param root uploaded JSON body (can be NULL)
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+static MHD_RESULT
+handler_kyc_webhook_generic (
+ struct TEKT_RequestContext *rc,
+ const char *method,
+ const json_t *root,
+ const char *const args[])
+{
+ struct KycWebhookContext *kwh = rc->rh_ctx;
+
+ if (NULL == kwh)
+ { /* first time */
+ kwh = GNUNET_new (struct KycWebhookContext);
+ kwh->rc = rc;
+ rc->rh_ctx = kwh;
+ rc->rh_cleaner = &clean_kwh;
+
+ if ( (NULL == args[0]) ||
+ (GNUNET_OK !=
+ TALER_KYCLOGIC_lookup_logic (args[0],
+ &kwh->plugin,
+ &kwh->pd,
+ &kwh->section_name)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "KYC logic `%s' unknown (check KYC provider configuration)\n",
+ args[0]);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
+ args[0]);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Calling KYC provider specific webhook\n");
+ kwh->wh = kwh->plugin->webhook (kwh->plugin->cls,
+ kwh->pd,
+ &kyc_provider_account_lookup,
+ NULL,
+ method,
+ &args[1],
+ rc->connection,
+ root,
+ &webhook_finished_cb,
+ kwh);
+ if (NULL == kwh->wh)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "failed to run webhook logic");
+ }
+ kwh->suspended = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (kwh_head,
+ kwh_tail,
+ kwh);
+ MHD_suspend_connection (rc->connection);
+ return MHD_YES;
+ }
+
+ if (NULL != kwh->response)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Returning queued reply for KWH\n");
+ /* handle _failed_ resumed cases */
+ return MHD_queue_response (rc->connection,
+ kwh->response_code,
+ kwh->response);
+ }
+
+ /* We resumed, but got no response? This should
+ not happen. */
+ GNUNET_assert (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_INTERNAL_SERVER_ERROR,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE,
+ "resumed without response");
+}
+
+
+/**
+ * Handle a GET "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+static MHD_RESULT
+handler_kyc_webhook_get (
+ struct TEKT_RequestContext *rc,
+ const char *const args[])
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Webhook GET triggered\n");
+ return handler_kyc_webhook_generic (rc,
+ MHD_HTTP_METHOD_GET,
+ NULL,
+ args);
+}
+
+
+/**
+ * Handle a POST "/kyc-webhook" request.
+ *
+ * @param rc request to handle
+ * @param root uploaded JSON body (can be NULL)
+ * @param args one argument with the legitimization_uuid
+ * @return MHD result code
+ */
+static MHD_RESULT
+handler_kyc_webhook_post (
+ struct TEKT_RequestContext *rc,
+ const json_t *root,
+ const char *const args[])
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Webhook POST triggered\n");
+ return handler_kyc_webhook_generic (rc,
+ MHD_HTTP_METHOD_POST,
+ root,
+ args);
+}
+
+
+/**
+ * Function called with the result of a proof check operation.
+ *
+ * Note that the "decref" for the @a response
+ * will be done by the callee and MUST NOT be done by the plugin.
+ *
+ * @param cls closure with the `struct ProofRequestState`
+ * @param status KYC status
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param expiration until when is the KYC check valid
+ * @param attributes attributes about the user
+ * @param http_status HTTP status code of @a response
+ * @param[in] response to return to the HTTP client
+ */
+static void
+proof_cb (
+ void *cls,
+ enum TALER_KYCLOGIC_KycStatus status,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ struct GNUNET_TIME_Absolute expiration,
+ const json_t *attributes,
+ unsigned int http_status,
+ struct MHD_Response *response)
+{
+ struct ProofRequestState *rs = cls;
+
+ (void) expiration;
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "KYC legitimization %s completed with status %d (%u) for %s\n",
+ provider_legitimization_id,
+ status,
+ http_status,
+ provider_user_id);
+ if (TALER_KYCLOGIC_STATUS_SUCCESS == status)
+ {
+ GNUNET_break (NULL != attributes);
+ fprintf (stderr,
+ "Extracted attributes:\n");
+ json_dumpf (attributes,
+ stderr,
+ JSON_INDENT (2));
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Returning response %p with status %u\n",
+ response,
+ http_status);
+ rs->rc->response = response;
+ rs->rc->http_status = http_status;
+ GNUNET_CONTAINER_DLL_remove (rs_head,
+ rs_tail,
+ rs);
+ MHD_resume_connection (rs->rc->connection);
+ TALER_MHD_daemon_trigger ();
+ GNUNET_free (rs);
+}
+
+
+/**
+ * Function called when we receive a 'GET' to the
+ * '/kyc-proof' endpoint.
+ *
+ * @param rc request context
+ * @param args remaining URL arguments;
+ * args[0] should be the logic plugin name
+ */
+static MHD_RESULT
+handler_kyc_proof_get (
+ struct TEKT_RequestContext *rc,
+ const char *const args[1])
+{
+ struct TALER_PaytoHashP h_payto;
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+ struct TALER_KYCLOGIC_Plugin *logic;
+ struct ProofRequestState *rs;
+ const char *section_name;
+ const char *h_paytos;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "GET /kyc-proof triggered\n");
+ if (NULL == args[0])
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ "'/kyc-proof/$PROVIDER_SECTION?state=$H_PAYTO' required");
+ }
+ h_paytos = MHD_lookup_connection_value (rc->connection,
+ MHD_GET_ARGUMENT_KIND,
+ "state");
+ if (NULL == h_paytos)
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MISSING,
+ "h_payto");
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (h_paytos,
+ strlen (h_paytos),
+ &h_payto,
+ sizeof (h_payto)))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "h_payto");
+ }
+ if (0 !=
+ GNUNET_memcmp (&h_payto,
+ &cmd_line_h_payto))
+ {
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_KYC_PROOF_REQUEST_UNKNOWN,
+ "h_payto");
+ }
+
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_lookup_logic (args[0],
+ &logic,
+ &pd,
+ &section_name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not initiate KYC with provider `%s' (configuration error?)\n",
+ args[0]);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_KYC_GENERIC_LOGIC_UNKNOWN,
+ args[0]);
+ }
+ rs = GNUNET_new (struct ProofRequestState);
+ rs->rc = rc;
+ rs->logic = logic;
+ MHD_suspend_connection (rc->connection);
+ GNUNET_CONTAINER_DLL_insert (rs_head,
+ rs_tail,
+ rs);
+ rs->ph = logic->proof (logic->cls,
+ pd,
+ rc->connection,
+ &h_payto,
+ kyc_row_id,
+ cmd_provider_user_id,
+ cmd_provider_legitimization_id,
+ &proof_cb,
+ rs);
+ GNUNET_assert (NULL != rs->ph);
+ return MHD_YES;
+}
+
+
+/**
+ * Function called whenever MHD is done with a request. If the
+ * request was a POST, we may have stored a `struct Buffer *` in the
+ * @a con_cls that might still need to be cleaned up. Call the
+ * respective function to free the memory.
+ *
+ * @param cls client-defined closure
+ * @param connection connection handle
+ * @param con_cls value as set by the last call to
+ * the #MHD_AccessHandlerCallback
+ * @param toe reason for request termination
+ * @see #MHD_OPTION_NOTIFY_COMPLETED
+ * @ingroup request
+ */
+static void
+handle_mhd_completion_callback (void *cls,
+ struct MHD_Connection *connection,
+ void **con_cls,
+ enum MHD_RequestTerminationCode toe)
+{
+ struct TEKT_RequestContext *rc = *con_cls;
+
+ (void) cls;
+ if (NULL == rc)
+ return;
+ if (NULL != rc->rh_cleaner)
+ rc->rh_cleaner (rc);
+ {
+#if MHD_VERSION >= 0x00097304
+ const union MHD_ConnectionInfo *ci;
+ unsigned int http_status = 0;
+
+ ci = MHD_get_connection_info (connection,
+ MHD_CONNECTION_INFO_HTTP_STATUS);
+ if (NULL != ci)
+ http_status = ci->http_status;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Request for `%s' completed with HTTP status %u (%d)\n",
+ rc->url,
+ http_status,
+ toe);
+#else
+ (void) connection;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Request for `%s' completed (%d)\n",
+ rc->url,
+ toe);
+#endif
+ }
+
+ TALER_MHD_parse_post_cleanup_callback (rc->opaque_post_parsing_context);
+ /* Sanity-check that we didn't leave any transactions hanging */
+ if (NULL != rc->root)
+ json_decref (rc->root);
+ GNUNET_free (rc);
+ *con_cls = NULL;
+}
+
+
+/**
+ * We found a request handler responsible for handling a request. Parse the
+ * @a upload_data (if applicable) and the @a url and call the
+ * handler.
+ *
+ * @param rc request context
+ * @param url rest of the URL to parse
+ * @param upload_data upload data to parse (if available)
+ * @param[in,out] upload_data_size number of bytes in @a upload_data
+ * @return MHD result code
+ */
+static MHD_RESULT
+proceed_with_handler (struct TEKT_RequestContext *rc,
+ const char *url,
+ const char *upload_data,
+ size_t *upload_data_size)
+{
+ const struct TEKT_RequestHandler *rh = rc->rh;
+ const char *args[rh->nargs + 2];
+ size_t ulen = strlen (url) + 1;
+ MHD_RESULT ret;
+
+ /* We do check for "ulen" here, because we'll later stack-allocate a buffer
+ of that size and don't want to enable malicious clients to cause us
+ huge stack allocations. */
+ if (ulen > 512)
+ {
+ /* 512 is simply "big enough", as it is bigger than "6 * 54",
+ which is the longest URL format we ever get (for
+ /deposits/). The value should be adjusted if we ever define protocol
+ endpoints with plausibly longer inputs. */
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_URI_TOO_LONG,
+ TALER_EC_GENERIC_URI_TOO_LONG,
+ url);
+ }
+
+ /* All POST endpoints come with a body in JSON format. So we parse
+ the JSON here. */
+ if ( (NULL == rc->root) &&
+ (0 == strcasecmp (rh->method,
+ MHD_HTTP_METHOD_POST)) )
+ {
+ enum GNUNET_GenericReturnValue res;
+
+ res = TALER_MHD_parse_post_json (rc->connection,
+ &rc->opaque_post_parsing_context,
+ upload_data,
+ upload_data_size,
+ &rc->root);
+ if (GNUNET_SYSERR == res)
+ {
+ GNUNET_assert (NULL == rc->root);
+ GNUNET_break (0);
+ return MHD_NO; /* bad upload, could not even generate error */
+ }
+ if ( (GNUNET_NO == res) ||
+ (NULL == rc->root) )
+ {
+ GNUNET_assert (NULL == rc->root);
+ return MHD_YES; /* so far incomplete upload or parser error */
+ }
+ }
+
+ {
+ char d[ulen];
+ unsigned int i;
+ char *sp;
+
+ /* Parse command-line arguments */
+ /* make a copy of 'url' because 'strtok_r()' will modify */
+ GNUNET_memcpy (d,
+ url,
+ ulen);
+ i = 0;
+ args[i++] = strtok_r (d, "/", &sp);
+ while ( (NULL != args[i - 1]) &&
+ (i <= rh->nargs + 1) )
+ args[i++] = strtok_r (NULL, "/", &sp);
+ /* make sure above loop ran nicely until completion, and also
+ that there is no excess data in 'd' afterwards */
+ if ( ( (rh->nargs_is_upper_bound) &&
+ (i - 1 > rh->nargs) ) ||
+ ( (! rh->nargs_is_upper_bound) &&
+ (i - 1 != rh->nargs) ) )
+ {
+ char emsg[128 + 512];
+
+ GNUNET_snprintf (emsg,
+ sizeof (emsg),
+ "Got %u+/%u segments for `%s' request (`%s')",
+ i - 1,
+ rh->nargs,
+ rh->url,
+ url);
+ GNUNET_break_op (0);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_EXCHANGE_GENERIC_WRONG_NUMBER_OF_SEGMENTS,
+ emsg);
+ }
+ GNUNET_assert (NULL == args[i - 1]);
+
+ /* Above logic ensures that 'root' is exactly non-NULL for POST operations,
+ so we test for 'root' to decide which handler to invoke. */
+ if (NULL != rc->root)
+ ret = rh->handler.post (rc,
+ rc->root,
+ args);
+ else /* We also only have "POST" or "GET" in the API for at this point
+ (OPTIONS/HEAD are taken care of earlier) */
+ ret = rh->handler.get (rc,
+ args);
+ }
+ return ret;
+}
+
+
+static void
+rh_cleaner_cb (struct TEKT_RequestContext *rc)
+{
+ if (NULL != rc->response)
+ {
+ MHD_destroy_response (rc->response);
+ rc->response = NULL;
+ }
+ if (NULL != rc->root)
+ {
+ json_decref (rc->root);
+ rc->root = NULL;
+ }
+}
+
+
+/**
+ * Handle incoming HTTP request.
+ *
+ * @param cls closure for MHD daemon (unused)
+ * @param connection the connection
+ * @param url the requested url
+ * @param method the method (POST, GET, ...)
+ * @param version HTTP version (ignored)
+ * @param upload_data request data
+ * @param upload_data_size size of @a upload_data in bytes
+ * @param con_cls closure for request (a `struct TEKT_RequestContext *`)
+ * @return MHD result code
+ */
+static MHD_RESULT
+handle_mhd_request (void *cls,
+ struct MHD_Connection *connection,
+ const char *url,
+ const char *method,
+ const char *version,
+ const char *upload_data,
+ size_t *upload_data_size,
+ void **con_cls)
+{
+ static struct TEKT_RequestHandler handlers[] = {
+ /* simulated KYC endpoints */
+ {
+ .url = "kyc-proof",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &handler_kyc_proof_get,
+ .nargs = 1
+ },
+ {
+ .url = "kyc-webhook",
+ .method = MHD_HTTP_METHOD_POST,
+ .handler.post = &handler_kyc_webhook_post,
+ .nargs = 128,
+ .nargs_is_upper_bound = true
+ },
+ {
+ .url = "kyc-webhook",
+ .method = MHD_HTTP_METHOD_GET,
+ .handler.get = &handler_kyc_webhook_get,
+ .nargs = 128,
+ .nargs_is_upper_bound = true
+ },
+ /* mark end of list */
+ {
+ .url = NULL
+ }
+ };
+ struct TEKT_RequestContext *rc = *con_cls;
+
+ (void) cls;
+ (void) version;
+ if (NULL == rc)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling new request\n");
+ /* We're in a new async scope! */
+ rc = *con_cls = GNUNET_new (struct TEKT_RequestContext);
+ rc->url = url;
+ rc->connection = connection;
+ rc->rh_cleaner = &rh_cleaner_cb;
+ }
+ if (NULL != rc->response)
+ {
+ return MHD_queue_response (rc->connection,
+ rc->http_status,
+ rc->response);
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling request (%s) for URL '%s'\n",
+ method,
+ url);
+ /* on repeated requests, check our cache first */
+ if (NULL != rc->rh)
+ {
+ const char *start;
+
+ if ('\0' == url[0])
+ /* strange, should start with '/', treat as just "/" */
+ url = "/";
+ start = strchr (url + 1, '/');
+ if (NULL == start)
+ start = "";
+ return proceed_with_handler (rc,
+ start,
+ upload_data,
+ upload_data_size);
+ }
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_HEAD))
+ method = MHD_HTTP_METHOD_GET; /* treat HEAD as GET here, MHD will do the rest */
+
+ /* parse first part of URL */
+ {
+ bool found = false;
+ size_t tok_size;
+ const char *tok;
+ const char *rest;
+
+ if ('\0' == url[0])
+ /* strange, should start with '/', treat as just "/" */
+ url = "/";
+ tok = url + 1;
+ rest = strchr (tok, '/');
+ if (NULL == rest)
+ {
+ tok_size = strlen (tok);
+ }
+ else
+ {
+ tok_size = rest - tok;
+ rest++; /* skip over '/' */
+ }
+ for (unsigned int i = 0; NULL != handlers[i].url; i++)
+ {
+ struct TEKT_RequestHandler *rh = &handlers[i];
+
+ if ( (0 != strncmp (tok,
+ rh->url,
+ tok_size)) ||
+ (tok_size != strlen (rh->url) ) )
+ continue;
+ found = true;
+ /* The URL is a match! What we now do depends on the method. */
+ if (0 == strcasecmp (method,
+ MHD_HTTP_METHOD_OPTIONS))
+ {
+ return TALER_MHD_reply_cors_preflight (connection);
+ }
+ GNUNET_assert (NULL != rh->method);
+ if (0 != strcasecmp (method,
+ rh->method))
+ {
+ found = true;
+ continue;
+ }
+ /* cache to avoid the loop next time */
+ rc->rh = rh;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handler found for %s '%s'\n",
+ method,
+ url);
+ return MHD_YES;
+ }
+
+ if (found)
+ {
+ /* we found a matching address, but the method is wrong */
+ struct MHD_Response *reply;
+ MHD_RESULT ret;
+ char *allowed = NULL;
+
+ GNUNET_break_op (0);
+ for (unsigned int i = 0; NULL != handlers[i].url; i++)
+ {
+ struct TEKT_RequestHandler *rh = &handlers[i];
+
+ if ( (0 != strncmp (tok,
+ rh->url,
+ tok_size)) ||
+ (tok_size != strlen (rh->url) ) )
+ continue;
+ if (NULL == allowed)
+ {
+ allowed = GNUNET_strdup (rh->method);
+ }
+ else
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp,
+ "%s, %s",
+ allowed,
+ rh->method);
+ GNUNET_free (allowed);
+ allowed = tmp;
+ }
+ if (0 == strcasecmp (rh->method,
+ MHD_HTTP_METHOD_GET))
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp,
+ "%s, %s",
+ allowed,
+ MHD_HTTP_METHOD_HEAD);
+ GNUNET_free (allowed);
+ allowed = tmp;
+ }
+ }
+ reply = TALER_MHD_make_error (TALER_EC_GENERIC_METHOD_INVALID,
+ method);
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (reply,
+ MHD_HTTP_HEADER_ALLOW,
+ allowed));
+ GNUNET_free (allowed);
+ ret = MHD_queue_response (connection,
+ MHD_HTTP_METHOD_NOT_ALLOWED,
+ reply);
+ MHD_destroy_response (reply);
+ return ret;
+ }
+ }
+
+ /* No handler matches, generate not found */
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_NOT_FOUND,
+ TALER_EC_GENERIC_ENDPOINT_UNKNOWN,
+ url);
+}
+
+
+/**
+ * Load configuration parameters for the exchange
+ * server into the corresponding global variables.
+ *
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+exchange_serve_process_config (void)
+{
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (TEKT_cfg,
+ "exchange",
+ "BASE_URL",
+ &TEKT_base_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+ if (! TALER_url_valid_charset (TEKT_base_url))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL",
+ "invalid URL");
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function run on shutdown.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+ struct MHD_Daemon *mhd;
+ struct ProofRequestState *rs;
+
+ (void) cls;
+ while (NULL != (rs = rs_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (rs_head,
+ rs_tail,
+ rs);
+ rs->logic->proof_cancel (rs->ph);
+ MHD_resume_connection (rs->rc->connection);
+ GNUNET_free (rs);
+ }
+ if (NULL != ih)
+ {
+ ih_logic->initiate_cancel (ih);
+ ih = NULL;
+ }
+ kyc_webhook_cleanup ();
+ TALER_KYCLOGIC_kyc_done ();
+ mhd = TALER_MHD_daemon_stop ();
+ if (NULL != mhd)
+ MHD_stop_daemon (mhd);
+ if (NULL != TEKT_curl_ctx)
+ {
+ GNUNET_CURL_fini (TEKT_curl_ctx);
+ TEKT_curl_ctx = NULL;
+ }
+ if (NULL != exchange_curl_rc)
+ {
+ GNUNET_CURL_gnunet_rc_destroy (exchange_curl_rc);
+ exchange_curl_rc = NULL;
+ }
+ TALER_TEMPLATING_done ();
+}
+
+
+/**
+ * Function called with the result of a KYC initiation
+ * operation.
+ *
+ * @param cls closure
+ * @param ec #TALER_EC_NONE on success
+ * @param redirect_url set to where to redirect the user on success, NULL on failure
+ * @param provider_user_id set to user ID at the provider, or NULL if not supported or unknown
+ * @param provider_legitimization_id set to legitimization process ID at the provider, or NULL if not supported or unknown
+ * @param error_msg_hint set to additional details to return to user, NULL on success
+ */
+static void
+initiate_cb (
+ void *cls,
+ enum TALER_ErrorCode ec,
+ const char *redirect_url,
+ const char *provider_user_id,
+ const char *provider_legitimization_id,
+ const char *error_msg_hint)
+{
+ (void) cls;
+ ih = NULL;
+ if (TALER_EC_NONE != ec)
+ {
+ fprintf (stderr,
+ "Failed to start KYC process: %s (#%d)\n",
+ error_msg_hint,
+ ec);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ {
+ char *s;
+
+ s = GNUNET_STRINGS_data_to_string_alloc (&cmd_line_h_payto,
+ sizeof (cmd_line_h_payto));
+ if (NULL != provider_user_id)
+ {
+ fprintf (stdout,
+ "Visit `%s' to begin KYC process.\nAlso use: taler-exchange-kyc-tester -w -u '%s' -U '%s' -p %s\n",
+ redirect_url,
+ provider_user_id,
+ provider_legitimization_id,
+ s);
+ }
+ else
+ {
+ fprintf (stdout,
+ "Visit `%s' to begin KYC process.\nAlso use: taler-exchange-kyc-tester -w -U '%s' -p %s\n",
+ redirect_url,
+ provider_legitimization_id,
+ s);
+ }
+ GNUNET_free (s);
+ }
+ GNUNET_free (cmd_provider_user_id);
+ GNUNET_free (cmd_provider_legitimization_id);
+ if (NULL != provider_user_id)
+ cmd_provider_user_id = GNUNET_strdup (provider_user_id);
+ if (NULL != provider_legitimization_id)
+ cmd_provider_legitimization_id = GNUNET_strdup (provider_legitimization_id);
+ if (! run_webservice)
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be
+ * NULL!)
+ * @param config configuration
+ */
+static void
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *config)
+{
+ int fh;
+
+ (void) cls;
+ (void) args;
+ (void ) cfgfile;
+ if (GNUNET_OK !=
+ TALER_TEMPLATING_init ("exchange"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not load templates. Installation broken.\n");
+ return;
+ }
+ if (print_h_payto)
+ {
+ char *s;
+
+ s = GNUNET_STRINGS_data_to_string_alloc (&cmd_line_h_payto,
+ sizeof (cmd_line_h_payto));
+ fprintf (stdout,
+ "%s\n",
+ s);
+ GNUNET_free (s);
+ }
+ TALER_MHD_setup (TALER_MHD_GO_NONE);
+ TEKT_cfg = config;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_kyc_init (config))
+ {
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ exchange_serve_process_config ())
+ {
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ global_ret = EXIT_SUCCESS;
+ if (NULL != requirements)
+ {
+ struct TALER_KYCLOGIC_ProviderDetails *pd;
+ enum TALER_KYCLOGIC_KycUserType ut;
+
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_kyc_user_type_from_string (ut_s,
+ &ut))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid user type specified ('-i')\n");
+ global_ret = EXIT_INVALIDARGUMENT;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_KYCLOGIC_requirements_to_logic (requirements,
+ ut,
+ &ih_logic,
+ &pd,
+ &provider_section_name))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not initiate KYC for requirements `%s' (configuration error?)\n",
+ requirements);
+ global_ret = EXIT_NOTCONFIGURED;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ ih = ih_logic->initiate (ih_logic->cls,
+ pd,
+ &cmd_line_h_payto,
+ kyc_row_id,
+ &initiate_cb,
+ NULL);
+ GNUNET_break (NULL != ih);
+ }
+ if (run_webservice)
+ {
+ TEKT_curl_ctx
+ = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &exchange_curl_rc);
+ if (NULL == TEKT_curl_ctx)
+ {
+ GNUNET_break (0);
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ exchange_curl_rc = GNUNET_CURL_gnunet_rc_create (TEKT_curl_ctx);
+ fh = TALER_MHD_bind (TEKT_cfg,
+ "exchange",
+ &serve_port);
+ if ( (0 == serve_port) &&
+ (-1 == fh) )
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Starting daemon on port %u\n",
+ (unsigned int) serve_port);
+ mhd = MHD_start_daemon (MHD_USE_SUSPEND_RESUME
+ | MHD_USE_PIPE_FOR_SHUTDOWN
+ | MHD_USE_DEBUG | MHD_USE_DUAL_STACK
+ | MHD_USE_TCP_FASTOPEN,
+ (-1 == fh) ? serve_port : 0,
+ NULL, NULL,
+ &handle_mhd_request, NULL,
+ MHD_OPTION_LISTEN_SOCKET,
+ fh,
+ MHD_OPTION_EXTERNAL_LOGGER,
+ &TALER_MHD_handle_logs,
+ NULL,
+ MHD_OPTION_NOTIFY_COMPLETED,
+ &handle_mhd_completion_callback,
+ NULL,
+ MHD_OPTION_END);
+ if (NULL == mhd)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to launch HTTP service. Is the port in use?\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ TALER_MHD_daemon_start (mhd);
+ }
+}
+
+
+/**
+ * The main function of the taler-exchange-httpd server ("the exchange").
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return 0 ok, 1 on error
+ */
+int
+main (int argc,
+ char *const *argv)
+{
+ const struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_help (
+ "tool to test KYC provider integrations"),
+ GNUNET_GETOPT_option_flag (
+ 'P',
+ "print-payto-hash",
+ "output the hash of the payto://-URI",
+ &print_h_payto),
+ GNUNET_GETOPT_option_uint (
+ 'r',
+ "rowid",
+ "NUMBER",
+ "override row ID to use in simulation (default: 42)",
+ &kyc_row_id),
+ GNUNET_GETOPT_option_flag (
+ 'w',
+ "run-webservice",
+ "run the integrated HTTP service",
+ &run_webservice),
+ GNUNET_GETOPT_option_string (
+ 'R',
+ "requirements",
+ "CHECKS",
+ "initiate KYC check for the given list of (space-separated) checks",
+ &requirements),
+ GNUNET_GETOPT_option_string (
+ 'i',
+ "identify",
+ "USERTYPE",
+ "self-identify as USERTYPE 'business' or 'individual' (defaults to 'individual')",
+ &requirements),
+ GNUNET_GETOPT_option_string (
+ 'u',
+ "user",
+ "ID",
+ "use the given provider user ID (overridden if -i is also used)",
+ &cmd_provider_user_id),
+ GNUNET_GETOPT_option_string (
+ 'U',
+ "legitimization",
+ "ID",
+ "use the given provider legitimization ID (overridden if -i is also used)",
+ &cmd_provider_legitimization_id),
+ GNUNET_GETOPT_option_base32_fixed_size (
+ 'p',
+ "payto-hash",
+ "HASH",
+ "base32 encoding of the hash of a payto://-URI to use for the account (otherwise a random value will be used)",
+ &cmd_line_h_payto,
+ sizeof (cmd_line_h_payto)),
+ GNUNET_GETOPT_OPTION_END
+ };
+ enum GNUNET_GenericReturnValue ret;
+
+ TALER_OS_init ();
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &cmd_line_h_payto,
+ sizeof (cmd_line_h_payto));
+ ret = GNUNET_PROGRAM_run (argc, argv,
+ "taler-exchange-kyc-tester",
+ "tool to test KYC provider integrations",
+ options,
+ &run, NULL);
+ if (GNUNET_SYSERR == ret)
+ return EXIT_INVALIDARGUMENT;
+ if (GNUNET_NO == ret)
+ return EXIT_SUCCESS;
+ return global_ret;
+}
+
+
+/* end of taler-exchange-kyc-tester.c */
diff --git a/src/lib/.gitignore b/src/lib/.gitignore
new file mode 100644
index 000000000..6664876f2
--- /dev/null
+++ b/src/lib/.gitignore
@@ -0,0 +1 @@
+test_stefan
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 76157c43a..63dab7c80 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -18,27 +18,34 @@ lib_LTLIBRARIES = \
libtalerexchange.la
libtalerexchange_la_LDFLAGS = \
- -version-info 5:0:0 \
+ -version-info 7:0:0 \
-no-undefined
libtalerexchange_la_SOURCES = \
+ exchange_api_add_aml_decision.c \
+ exchange_api_age_withdraw.c \
+ exchange_api_age_withdraw_reveal.c \
exchange_api_auditor_add_denomination.c \
exchange_api_batch_deposit.c \
exchange_api_batch_withdraw.c \
exchange_api_batch_withdraw2.c \
exchange_api_curl_defaults.c exchange_api_curl_defaults.h \
+ exchange_api_coins_history.c \
exchange_api_common.c exchange_api_common.h \
exchange_api_contracts_get.c \
exchange_api_csr_melt.c \
exchange_api_csr_withdraw.c \
exchange_api_handle.c exchange_api_handle.h \
- exchange_api_deposit.c \
exchange_api_deposits_get.c \
exchange_api_kyc_check.c \
exchange_api_kyc_proof.c \
exchange_api_kyc_wallet.c \
exchange_api_link.c \
+ exchange_api_lookup_aml_decision.c \
+ exchange_api_lookup_aml_decisions.c \
+ exchange_api_management_add_partner.c \
exchange_api_management_auditor_disable.c \
exchange_api_management_auditor_enable.c \
+ exchange_api_management_drain_profits.c \
exchange_api_management_get_keys.c \
exchange_api_management_post_keys.c \
exchange_api_management_post_extensions.c \
@@ -46,11 +53,13 @@ libtalerexchange_la_SOURCES = \
exchange_api_management_revoke_signing_key.c \
exchange_api_management_set_global_fee.c \
exchange_api_management_set_wire_fee.c \
+ exchange_api_management_update_aml_officer.c \
exchange_api_management_wire_disable.c \
exchange_api_management_wire_enable.c \
exchange_api_melt.c \
exchange_api_purse_create_with_deposit.c \
exchange_api_purse_create_with_merge.c \
+ exchange_api_purse_delete.c \
exchange_api_purse_deposit.c \
exchange_api_purse_merge.c \
exchange_api_purses_get.c \
@@ -59,16 +68,18 @@ libtalerexchange_la_SOURCES = \
exchange_api_refresh_common.c exchange_api_refresh_common.h \
exchange_api_refreshes_reveal.c \
exchange_api_refund.c \
+ exchange_api_reserves_attest.c \
+ exchange_api_reserves_close.c \
exchange_api_reserves_get.c \
+ exchange_api_reserves_get_attestable.c \
exchange_api_reserves_history.c \
- exchange_api_reserves_status.c \
- exchange_api_transfers_get.c \
- exchange_api_withdraw.c \
- exchange_api_withdraw2.c \
- exchange_api_wire.c
+ exchange_api_reserves_open.c \
+ exchange_api_stefan.c \
+ exchange_api_transfers_get.c
libtalerexchange_la_LIBADD = \
libtalerauditor.la \
$(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/kyclogic/libtalerkyclogic.la \
$(top_builddir)/src/curl/libtalercurl.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
@@ -76,7 +87,8 @@ libtalerexchange_la_LIBADD = \
-lgnunetjson \
-lgnunetutil \
-ljansson \
- $(LIBGNURLCURL_LIBS) \
+ -lcurl \
+ -lm \
$(XLIB)
libtalerauditor_la_LDFLAGS = \
@@ -84,9 +96,8 @@ libtalerauditor_la_LDFLAGS = \
-no-undefined
libtalerauditor_la_SOURCES = \
auditor_api_curl_defaults.c auditor_api_curl_defaults.h \
- auditor_api_handle.c auditor_api_handle.h \
- auditor_api_deposit_confirmation.c \
- auditor_api_exchanges.c
+ auditor_api_get_config.c \
+ auditor_api_deposit_confirmation.c
libtalerauditor_la_LIBADD = \
$(top_builddir)/src/curl/libtalercurl.la \
$(top_builddir)/src/json/libtalerjson.la \
@@ -95,5 +106,21 @@ libtalerauditor_la_LIBADD = \
-lgnunetjson \
-lgnunetutil \
-ljansson \
- $(LIBGNURLCURL_LIBS) \
+ -lcurl \
+ -lm \
$(XLIB)
+
+
+check_PROGRAMS = \
+ test_stefan
+
+TESTS = \
+ $(check_PROGRAMS)
+
+
+test_stefan_SOURCES = \
+ test_stefan.c
+test_stefan_LDADD = \
+ $(top_builddir)/src/lib/libtalerexchange.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetutil
diff --git a/src/lib/auditor_api_curl_defaults.c b/src/lib/auditor_api_curl_defaults.c
index 81fcd7bac..972f28ca6 100644
--- a/src/lib/auditor_api_curl_defaults.c
+++ b/src/lib/auditor_api_curl_defaults.c
@@ -19,6 +19,8 @@
* @brief curl easy handle defaults
* @author Florian Dold
*/
+#include "platform.h"
+#include "taler_curl_lib.h"
#include "auditor_api_curl_defaults.h"
@@ -37,22 +39,14 @@ TALER_AUDITOR_curl_easy_get_ (const char *url)
curl_easy_setopt (eh,
CURLOPT_URL,
url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_FOLLOWLOCATION,
- 1L));
+ TALER_curl_set_secure_redirect_policy (eh,
+ url);
/* Enable compression (using whatever curl likes), see
https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html */
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ACCEPT_ENCODING,
""));
- /* limit MAXREDIRS to 5 as a simple security measure against
- a potential infinite loop caused by a malicious target */
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_MAXREDIRS,
- 5L));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_TCP_FASTOPEN,
diff --git a/src/lib/auditor_api_deposit_confirmation.c b/src/lib/auditor_api_deposit_confirmation.c
index c4542d0eb..172a12ece 100644
--- a/src/lib/auditor_api_deposit_confirmation.c
+++ b/src/lib/auditor_api_deposit_confirmation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -25,9 +25,10 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include <gnunet/gnunet_curl_lib.h>
+#include "taler_util.h"
+#include "taler_curl_lib.h"
#include "taler_json_lib.h"
#include "taler_auditor_service.h"
-#include "auditor_api_handle.h"
#include "taler_signatures.h"
#include "auditor_api_curl_defaults.h"
@@ -39,11 +40,6 @@ struct TALER_AUDITOR_DepositConfirmationHandle
{
/**
- * The connection to auditor this request handle will use
- */
- struct TALER_AUDITOR_Handle *auditor;
-
- /**
* The url for this request.
*/
char *url;
@@ -87,64 +83,64 @@ handle_deposit_confirmation_finished (void *cls,
{
const json_t *json = djson;
struct TALER_AUDITOR_DepositConfirmationHandle *dh = cls;
- struct TALER_AUDITOR_HttpResponse hr = {
- .reply = json,
- .http_status = (unsigned int) response_code
+ struct TALER_AUDITOR_DepositConfirmationResponse dcr = {
+ .hr.reply = json,
+ .hr.http_status = (unsigned int) response_code
};
dh->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ dcr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
- hr.ec = TALER_EC_NONE;
+ dcr.hr.ec = TALER_EC_NONE;
break;
case MHD_HTTP_BAD_REQUEST:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
/* This should never happen, either us or the auditor is buggy
(or API version conflict); just pass JSON reply to the application */
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, auditor says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
break;
case MHD_HTTP_GONE:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
/* Nothing really to verify, auditor says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ dcr.hr.ec = TALER_JSON_get_error_code (json);
+ dcr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for auditor deposit confirmation\n",
(unsigned int) response_code,
- hr.ec);
+ dcr.hr.ec);
break;
}
dh->cb (dh->cb_cls,
- &hr);
+ &dcr);
TALER_AUDITOR_deposit_confirmation_cancel (dh);
}
@@ -153,13 +149,14 @@ handle_deposit_confirmation_finished (void *cls,
* Verify signature information about the deposit-confirmation.
*
* @param h_wire hash of merchant wire details
- * @param h_extensions hash over the extensions, if any
+ * @param h_policy hash over the policy extension, if any
* @param h_contract_terms hash of the contact of the merchant with the customer (further details are never disclosed to the auditor)
* @param exchange_timestamp timestamp when the deposit was received by the wallet
* @param wire_deadline by what time must the amount be wired to the merchant
* @param refund_deadline date until which the merchant can issue a refund to the customer via the auditor (can be zero if refunds are not allowed); must not be after the @a wire_deadline
* @param amount_without_fee the amount confirmed to be wired by the exchange to the merchant
- * @param coin_pub coin’s public key
+ * @param num_coins number of coins involved
+ * @param coin_sigs array of @a num_coins coin signatures
* @param merchant_pub the public key of the merchant (used to identify the merchant for refund requests)
* @param exchange_sig the signature made with purpose #TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT
* @param exchange_pub the public key of the exchange that matches @a exchange_sig
@@ -171,33 +168,37 @@ handle_deposit_confirmation_finished (void *cls,
* @return #GNUNET_OK if signatures are OK, #GNUNET_SYSERR if not
*/
static enum GNUNET_GenericReturnValue
-verify_signatures (const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
- const struct TALER_PrivateContractHashP *h_contract_terms,
- struct GNUNET_TIME_Timestamp exchange_timestamp,
- struct GNUNET_TIME_Timestamp wire_deadline,
- struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_MerchantPublicKeyP *merchant_pub,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_ExchangeSignatureP *exchange_sig,
- const struct TALER_MasterPublicKeyP *master_pub,
- struct GNUNET_TIME_Timestamp ep_start,
- struct GNUNET_TIME_Timestamp ep_expire,
- struct GNUNET_TIME_Timestamp ep_end,
- const struct TALER_MasterSignatureP *master_sig)
+verify_signatures (
+ const struct TALER_MerchantWireHashP *h_wire,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
+ struct GNUNET_TIME_Timestamp exchange_timestamp,
+ struct GNUNET_TIME_Timestamp wire_deadline,
+ struct GNUNET_TIME_Timestamp refund_deadline,
+ const struct TALER_Amount *amount_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendSignatureP *coin_sigs[
+ static num_coins],
+ const struct TALER_MerchantPublicKeyP *merchant_pub,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ struct GNUNET_TIME_Timestamp ep_start,
+ struct GNUNET_TIME_Timestamp ep_expire,
+ struct GNUNET_TIME_Timestamp ep_end,
+ const struct TALER_MasterSignatureP *master_sig)
{
if (GNUNET_OK !=
TALER_exchange_online_deposit_confirmation_verify (
h_contract_terms,
h_wire,
- h_extensions,
+ h_policy,
exchange_timestamp,
wire_deadline,
refund_deadline,
amount_without_fee,
- coin_pub,
+ num_coins,
+ coin_sigs,
merchant_pub,
exchange_pub,
exchange_sig))
@@ -237,15 +238,20 @@ verify_signatures (const struct TALER_MerchantWireHashP *h_wire,
struct TALER_AUDITOR_DepositConfirmationHandle *
TALER_AUDITOR_deposit_confirmation (
- struct TALER_AUDITOR_Handle *auditor,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_PrivateContractHashP *h_contract_terms,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendPublicKeyP *coin_pubs[
+ static num_coins],
+ const struct TALER_CoinSpendSignatureP *coin_sigs[
+ static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const struct TALER_ExchangeSignatureP *exchange_sig,
@@ -258,21 +264,26 @@ TALER_AUDITOR_deposit_confirmation (
void *cb_cls)
{
struct TALER_AUDITOR_DepositConfirmationHandle *dh;
- struct GNUNET_CURL_Context *ctx;
json_t *deposit_confirmation_obj;
CURL *eh;
+ json_t *jcoin_sigs;
+ json_t *jcoin_pubs;
- GNUNET_assert (GNUNET_YES ==
- TALER_AUDITOR_handle_is_ready_ (auditor));
+ if (0 == num_coins)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
if (GNUNET_OK !=
verify_signatures (h_wire,
- h_extensions,
+ h_policy,
h_contract_terms,
exchange_timestamp,
wire_deadline,
refund_deadline,
- amount_without_fee,
- coin_pub,
+ total_without_fee,
+ num_coins,
+ coin_sigs,
merchant_pub,
exchange_pub,
exchange_sig,
@@ -285,25 +296,42 @@ TALER_AUDITOR_deposit_confirmation (
GNUNET_break_op (0);
return NULL;
}
-
+ jcoin_sigs = json_array ();
+ GNUNET_assert (NULL != jcoin_sigs);
+ jcoin_pubs = json_array ();
+ GNUNET_assert (NULL != jcoin_pubs);
+ for (unsigned int i = 0; i<num_coins; i++)
+ {
+ GNUNET_assert (0 ==
+ json_array_append_new (jcoin_sigs,
+ GNUNET_JSON_from_data_auto (
+ coin_sigs[i])));
+ GNUNET_assert (0 ==
+ json_array_append_new (jcoin_pubs,
+ GNUNET_JSON_from_data_auto (
+ coin_pubs[i])));
+ }
deposit_confirmation_obj
= GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_auto ("h_wire",
h_wire),
- GNUNET_JSON_pack_data_auto ("h_extensions",
- h_extensions),
+ GNUNET_JSON_pack_data_auto ("h_policy",
+ h_policy),
GNUNET_JSON_pack_data_auto ("h_contract_terms",
h_contract_terms),
GNUNET_JSON_pack_timestamp ("exchange_timestamp",
exchange_timestamp),
- GNUNET_JSON_pack_timestamp ("refund_deadline",
- refund_deadline),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_timestamp ("refund_deadline",
+ refund_deadline)),
GNUNET_JSON_pack_timestamp ("wire_deadline",
wire_deadline),
- TALER_JSON_pack_amount ("amount_without_fee",
- amount_without_fee),
- GNUNET_JSON_pack_data_auto ("coin_pub",
- coin_pub),
+ TALER_JSON_pack_amount ("total_without_fee",
+ total_without_fee),
+ GNUNET_JSON_pack_array_steal ("coin_pubs",
+ jcoin_pubs),
+ GNUNET_JSON_pack_array_steal ("coin_sigs",
+ jcoin_sigs),
GNUNET_JSON_pack_data_auto ("merchant_pub",
merchant_pub),
GNUNET_JSON_pack_data_auto ("exchange_sig",
@@ -321,18 +349,17 @@ TALER_AUDITOR_deposit_confirmation (
GNUNET_JSON_pack_data_auto ("exchange_pub",
exchange_pub));
dh = GNUNET_new (struct TALER_AUDITOR_DepositConfirmationHandle);
- dh->auditor = auditor;
dh->cb = cb;
dh->cb_cls = cb_cls;
- dh->url = TALER_AUDITOR_path_to_url_ (auditor,
- "/deposit-confirmation");
+ dh->url = TALER_url_join (url,
+ "deposit-confirmation",
+ NULL);
if (NULL == dh->url)
{
GNUNET_free (dh);
return NULL;
}
eh = TALER_AUDITOR_curl_easy_get_ (dh->url);
-
if ( (NULL == eh) ||
(CURLE_OK !=
curl_easy_setopt (eh,
@@ -355,16 +382,21 @@ TALER_AUDITOR_deposit_confirmation (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit-confirmation: `%s'\n",
dh->url);
- ctx = TALER_AUDITOR_handle_to_context_ (auditor);
dh->job = GNUNET_CURL_job_add2 (ctx,
eh,
dh->ctx.headers,
&handle_deposit_confirmation_finished,
dh);
- /* Disable 100 continue processing */
- GNUNET_CURL_extend_headers (dh->job,
- curl_slist_append (NULL,
- "Expect:"));
+ {
+ /* Disable 100 continue processing */
+ struct curl_slist *x_headers;
+
+ x_headers = curl_slist_append (NULL,
+ "Expect:");
+ GNUNET_CURL_extend_headers (dh->job,
+ x_headers);
+ curl_slist_free_all (x_headers);
+ }
return dh;
}
diff --git a/src/lib/auditor_api_exchanges.c b/src/lib/auditor_api_exchanges.c
deleted file mode 100644
index 7327f11b2..000000000
--- a/src/lib/auditor_api_exchanges.c
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/auditor_api_exchanges.c
- * @brief Implementation of the /exchanges request of the auditor's HTTP API
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_json_lib.h"
-#include "taler_auditor_service.h"
-#include "auditor_api_handle.h"
-#include "taler_signatures.h"
-#include "auditor_api_curl_defaults.h"
-
-/**
- * How many exchanges do we allow a single auditor to
- * audit at most?
- */
-#define MAX_EXCHANGES 1024
-
-
-/**
- * @brief A ListExchanges Handle
- */
-struct TALER_AUDITOR_ListExchangesHandle
-{
-
- /**
- * The connection to auditor this request handle will use
- */
- struct TALER_AUDITOR_Handle *auditor;
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_AUDITOR_ListExchangesResultCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP /exchanges request.
- *
- * @param cls the `struct TALER_AUDITOR_ListExchangesHandle`
- * @param response_code HTTP response code, 0 on error
- * @param djson parsed JSON result, NULL on error
- */
-static void
-handle_exchanges_finished (void *cls,
- long response_code,
- const void *djson)
-{
- const json_t *json = djson;
- const json_t *ja;
- unsigned int ja_len;
- struct TALER_AUDITOR_ListExchangesHandle *leh = cls;
- struct TALER_AUDITOR_HttpResponse hr = {
- .reply = json,
- .http_status = (unsigned int) response_code
- };
-
- leh->job = NULL;
- switch (response_code)
- {
- case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- ja = json_object_get (json,
- "exchanges");
- if ( (NULL == ja) ||
- (! json_is_array (ja)) )
- {
- GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
-
- ja_len = json_array_size (ja);
- if (ja_len > MAX_EXCHANGES)
- {
- GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
- {
- struct TALER_AUDITOR_ExchangeInfo ei[ja_len];
- bool ok;
-
- ok = true;
- for (unsigned int i = 0; i<ja_len; i++)
- {
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("master_pub", &ei[i].master_pub),
- GNUNET_JSON_spec_string ("exchange_url", &ei[i].exchange_url),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json_array_get (ja,
- i),
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- ok = false;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
- }
- if (! ok)
- break;
- leh->cb (leh->cb_cls,
- &hr,
- ja_len,
- ei);
- TALER_AUDITOR_list_exchanges_cancel (leh);
- return;
- }
- case MHD_HTTP_BAD_REQUEST:
- /* This should never happen, either us or the auditor is buggy
- (or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- break;
- default:
- /* unexpected response code */
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for auditor list-exchanges request\n",
- (unsigned int) response_code,
- (int) hr.ec);
- GNUNET_break_op (0);
- break;
- }
- if (NULL != leh->cb)
- leh->cb (leh->cb_cls,
- &hr,
- 0,
- NULL);
- TALER_AUDITOR_list_exchanges_cancel (leh);
-}
-
-
-struct TALER_AUDITOR_ListExchangesHandle *
-TALER_AUDITOR_list_exchanges (struct TALER_AUDITOR_Handle *auditor,
- TALER_AUDITOR_ListExchangesResultCallback cb,
- void *cb_cls)
-{
- struct TALER_AUDITOR_ListExchangesHandle *leh;
- struct GNUNET_CURL_Context *ctx;
- CURL *eh;
-
- GNUNET_assert (GNUNET_YES ==
- TALER_AUDITOR_handle_is_ready_ (auditor));
-
- leh = GNUNET_new (struct TALER_AUDITOR_ListExchangesHandle);
- leh->auditor = auditor;
- leh->cb = cb;
- leh->cb_cls = cb_cls;
- leh->url = TALER_AUDITOR_path_to_url_ (auditor,
- "/exchanges");
- if (NULL == leh->url)
- {
- GNUNET_free (leh);
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "URL for list-exchanges: `%s'\n",
- leh->url);
- eh = TALER_AUDITOR_curl_easy_get_ (leh->url);
- if (NULL == eh)
- {
- GNUNET_break (0);
- GNUNET_free (leh->url);
- GNUNET_free (leh);
- return NULL;
- }
- ctx = TALER_AUDITOR_handle_to_context_ (auditor);
- leh->job = GNUNET_CURL_job_add (ctx,
- eh,
- &handle_exchanges_finished,
- leh);
- return leh;
-}
-
-
-void
-TALER_AUDITOR_list_exchanges_cancel (
- struct TALER_AUDITOR_ListExchangesHandle *leh)
-{
- if (NULL != leh->job)
- {
- GNUNET_CURL_job_cancel (leh->job);
- leh->job = NULL;
- }
- GNUNET_free (leh->url);
- GNUNET_free (leh);
-}
-
-
-/* end of auditor_api_exchanges.c */
diff --git a/src/lib/auditor_api_get_config.c b/src/lib/auditor_api_get_config.c
new file mode 100644
index 000000000..1e8e0bb30
--- /dev/null
+++ b/src/lib/auditor_api_get_config.c
@@ -0,0 +1,278 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/auditor_api_get_config.c
+ * @brief Implementation of /config for the auditor's HTTP API
+ * @author Sree Harsha Totakura <sreeharsha@totakura.in>
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <microhttpd.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_json_lib.h"
+#include "taler_auditor_service.h"
+#include "taler_signatures.h"
+#include "auditor_api_curl_defaults.h"
+
+
+/**
+ * Which revision of the Taler auditor protocol is implemented
+ * by this library? Used to determine compatibility.
+ */
+#define TALER_PROTOCOL_CURRENT 1
+
+/**
+ * How many revisions back are we compatible to?
+ */
+#define TALER_PROTOCOL_AGE 0
+
+
+/**
+ * Log error related to CURL operations.
+ *
+ * @param type log level
+ * @param function which function failed to run
+ * @param code what was the curl error code
+ */
+#define CURL_STRERROR(type, function, code) \
+ GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \
+ function, __FILE__, __LINE__, curl_easy_strerror (code));
+
+
+/**
+ * Handle for the get config request.
+ */
+struct TALER_AUDITOR_GetConfigHandle
+{
+ /**
+ * The context of this handle
+ */
+ struct GNUNET_CURL_Context *ctx;
+
+ /**
+ * Function to call with the auditor's certification data,
+ * NULL if this has already been done.
+ */
+ TALER_AUDITOR_ConfigCallback config_cb;
+
+ /**
+ * Closure to pass to @e config_cb.
+ */
+ void *config_cb_cls;
+
+ /**
+ * Data for the request to get the /config of a auditor,
+ * NULL once we are past stage #MHS_INIT.
+ */
+ struct GNUNET_CURL_Job *vr;
+
+ /**
+ * The url for the @e vr job.
+ */
+ char *vr_url;
+
+};
+
+
+/* ***************** Internal /config fetching ************* */
+
+/**
+ * Decode the JSON in @a resp_obj from the /config response and store the data
+ * in the @a key_data.
+ *
+ * @param[in] resp_obj JSON object to parse
+ * @param[in,out] vi where to store the results we decoded
+ * @param[out] vc where to store config compatibility data
+ * @return #TALER_EC_NONE on success
+ */
+static enum TALER_ErrorCode
+decode_config_json (const json_t *resp_obj,
+ struct TALER_AUDITOR_ConfigInformation *vi,
+ enum TALER_AUDITOR_VersionCompatibility *vc)
+{
+ struct TALER_JSON_ProtocolVersion pv;
+ const char *ver;
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_version ("version",
+ &pv),
+ GNUNET_JSON_spec_string ("version",
+ &ver),
+ GNUNET_JSON_spec_fixed_auto ("exchange_master_public_key",
+ &vi->exchange_master_public_key),
+ GNUNET_JSON_spec_fixed_auto ("auditor_public_key",
+ &vi->auditor_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (JSON_OBJECT != json_typeof (resp_obj))
+ {
+ GNUNET_break_op (0);
+ return TALER_EC_GENERIC_JSON_INVALID;
+ }
+ /* check the config */
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (resp_obj,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return TALER_EC_GENERIC_JSON_INVALID;
+ }
+ vi->version = ver;
+ *vc = TALER_AUDITOR_VC_MATCH;
+ if (TALER_PROTOCOL_CURRENT < pv.current)
+ {
+ *vc |= TALER_AUDITOR_VC_NEWER;
+ if (TALER_PROTOCOL_CURRENT < pv.current - pv.age)
+ *vc |= TALER_AUDITOR_VC_INCOMPATIBLE;
+ }
+ if (TALER_PROTOCOL_CURRENT > pv.current)
+ {
+ *vc |= TALER_AUDITOR_VC_OLDER;
+ if (TALER_PROTOCOL_CURRENT - TALER_PROTOCOL_AGE > pv.current)
+ *vc |= TALER_AUDITOR_VC_INCOMPATIBLE;
+ }
+ return TALER_EC_NONE;
+}
+
+
+/**
+ * Callback used when downloading the reply to a /config request
+ * is complete.
+ *
+ * @param cls the `struct TALER_AUDITOR_GetConfigHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param gresp_obj parsed JSON result, NULL on error, must be a `const json_t *`
+ */
+static void
+config_completed_cb (void *cls,
+ long response_code,
+ const void *gresp_obj)
+{
+ struct TALER_AUDITOR_GetConfigHandle *auditor = cls;
+ const json_t *resp_obj = gresp_obj;
+ struct TALER_AUDITOR_ConfigResponse vr = {
+ .hr.reply = resp_obj,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ auditor->vr = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received config from URL `%s' with status %ld.\n",
+ auditor->vr_url,
+ response_code);
+ switch (response_code)
+ {
+ case 0:
+ GNUNET_break_op (0);
+ vr.hr.ec = TALER_EC_INVALID;
+ break;
+ case MHD_HTTP_OK:
+ if (NULL == resp_obj)
+ {
+ GNUNET_break_op (0);
+ vr.hr.http_status = 0;
+ vr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ }
+ vr.hr.ec = decode_config_json (resp_obj,
+ &vr.details.ok.vi,
+ &vr.details.ok.compat);
+ if (TALER_EC_NONE != vr.hr.ec)
+ {
+ GNUNET_break_op (0);
+ vr.hr.http_status = 0;
+ break;
+ }
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ vr.hr.ec = TALER_JSON_get_error_code (resp_obj);
+ vr.hr.hint = TALER_JSON_get_error_hint (resp_obj);
+ break;
+ default:
+ vr.hr.ec = TALER_JSON_get_error_code (resp_obj);
+ vr.hr.hint = TALER_JSON_get_error_hint (resp_obj);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d\n",
+ (unsigned int) response_code,
+ (int) vr.hr.ec);
+ break;
+ }
+ auditor->config_cb (auditor->config_cb_cls,
+ &vr);
+ TALER_AUDITOR_get_config_cancel (auditor);
+}
+
+
+struct TALER_AUDITOR_GetConfigHandle *
+TALER_AUDITOR_get_config (struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ TALER_AUDITOR_ConfigCallback config_cb,
+ void *config_cb_cls)
+{
+ struct TALER_AUDITOR_GetConfigHandle *auditor;
+ CURL *eh;
+
+ auditor = GNUNET_new (struct TALER_AUDITOR_GetConfigHandle);
+ auditor->config_cb = config_cb;
+ auditor->config_cb_cls = config_cb_cls;
+ auditor->ctx = ctx;
+ auditor->vr_url = TALER_url_join (url,
+ "config",
+ NULL);
+ if (NULL == auditor->vr_url)
+ {
+ GNUNET_break (0);
+ GNUNET_free (auditor);
+ return NULL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting auditor config with URL `%s'.\n",
+ auditor->vr_url);
+ eh = TALER_AUDITOR_curl_easy_get_ (auditor->vr_url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ TALER_AUDITOR_get_config_cancel (auditor);
+ return NULL;
+ }
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_TIMEOUT,
+ (long) 300));
+ auditor->vr = GNUNET_CURL_job_add (auditor->ctx,
+ eh,
+ &config_completed_cb,
+ auditor);
+ return auditor;
+}
+
+
+void
+TALER_AUDITOR_get_config_cancel (struct TALER_AUDITOR_GetConfigHandle *auditor)
+{
+ if (NULL != auditor->vr)
+ {
+ GNUNET_CURL_job_cancel (auditor->vr);
+ auditor->vr = NULL;
+ }
+ GNUNET_free (auditor->vr_url);
+ GNUNET_free (auditor);
+}
+
+
+/* end of auditor_api_get_config.c */
diff --git a/src/lib/auditor_api_handle.c b/src/lib/auditor_api_handle.c
deleted file mode 100644
index 9edb1115e..000000000
--- a/src/lib/auditor_api_handle.c
+++ /dev/null
@@ -1,449 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/auditor_api_handle.c
- * @brief Implementation of the "handle" component of the auditor's HTTP API
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <microhttpd.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_json_lib.h"
-#include "taler_auditor_service.h"
-#include "taler_signatures.h"
-#include "auditor_api_handle.h"
-#include "auditor_api_curl_defaults.h"
-#include "backoff.h"
-
-/**
- * Which revision of the Taler auditor protocol is implemented
- * by this library? Used to determine compatibility.
- */
-#define TALER_PROTOCOL_CURRENT 0
-
-/**
- * How many revisions back are we compatible to?
- */
-#define TALER_PROTOCOL_AGE 0
-
-
-/**
- * Log error related to CURL operations.
- *
- * @param type log level
- * @param function which function failed to run
- * @param code what was the curl error code
- */
-#define CURL_STRERROR(type, function, code) \
- GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \
- function, __FILE__, __LINE__, curl_easy_strerror (code));
-
-/**
- * Stages of initialization for the `struct TALER_AUDITOR_Handle`
- */
-enum AuditorHandleState
-{
- /**
- * Just allocated.
- */
- MHS_INIT = 0,
-
- /**
- * Obtained the auditor's versioning data and version.
- */
- MHS_VERSION = 1,
-
- /**
- * Failed to initialize (fatal).
- */
- MHS_FAILED = 2
-};
-
-
-/**
- * Handle to the auditor
- */
-struct TALER_AUDITOR_Handle
-{
- /**
- * The context of this handle
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * The URL of the auditor (i.e. "http://auditor.taler.net/")
- */
- char *url;
-
- /**
- * Function to call with the auditor's certification data,
- * NULL if this has already been done.
- */
- TALER_AUDITOR_VersionCallback version_cb;
-
- /**
- * Closure to pass to @e version_cb.
- */
- void *version_cb_cls;
-
- /**
- * Data for the request to get the /version of a auditor,
- * NULL once we are past stage #MHS_INIT.
- */
- struct GNUNET_CURL_Job *vr;
-
- /**
- * The url for the @e vr job.
- */
- char *vr_url;
-
- /**
- * Task for retrying /version request.
- */
- struct GNUNET_SCHEDULER_Task *retry_task;
-
- /**
- * /version data of the auditor, only valid if
- * @e handshake_complete is past stage #MHS_VERSION.
- */
- char *version;
-
- /**
- * Version information for the callback.
- */
- struct TALER_AUDITOR_VersionInformation vi;
-
- /**
- * Retry /version frequency.
- */
- struct GNUNET_TIME_Relative retry_delay;
-
- /**
- * Stage of the auditor's initialization routines.
- */
- enum AuditorHandleState state;
-
-};
-
-
-/* ***************** Internal /version fetching ************* */
-
-/**
- * Decode the JSON in @a resp_obj from the /version response and store the data
- * in the @a key_data.
- *
- * @param[in] resp_obj JSON object to parse
- * @param[in,out] auditor where to store the results we decoded
- * @param[out] vc where to store version compatibility data
- * @return #TALER_EC_NONE on success
- */
-static enum TALER_ErrorCode
-decode_version_json (const json_t *resp_obj,
- struct TALER_AUDITOR_Handle *auditor,
- enum TALER_AUDITOR_VersionCompatibility *vc)
-{
- struct TALER_AUDITOR_VersionInformation *vi = &auditor->vi;
- unsigned int age;
- unsigned int revision;
- unsigned int current;
- char dummy;
- const char *ver;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("version",
- &ver),
- GNUNET_JSON_spec_fixed_auto ("auditor_public_key",
- &vi->auditor_pub),
- GNUNET_JSON_spec_end ()
- };
-
- if (JSON_OBJECT != json_typeof (resp_obj))
- {
- GNUNET_break_op (0);
- return TALER_EC_GENERIC_JSON_INVALID;
- }
- /* check the version */
- if (GNUNET_OK !=
- GNUNET_JSON_parse (resp_obj,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return TALER_EC_GENERIC_JSON_INVALID;
- }
- if (3 != sscanf (ver,
- "%u:%u:%u%c",
- &current,
- &revision,
- &age,
- &dummy))
- {
- GNUNET_break_op (0);
- return TALER_EC_GENERIC_VERSION_MALFORMED;
- }
- GNUNET_free (auditor->version);
- auditor->version = GNUNET_strdup (ver);
- vi->version = auditor->version;
- *vc = TALER_AUDITOR_VC_MATCH;
- if (TALER_PROTOCOL_CURRENT < current)
- {
- *vc |= TALER_AUDITOR_VC_NEWER;
- if (TALER_PROTOCOL_CURRENT < current - age)
- *vc |= TALER_AUDITOR_VC_INCOMPATIBLE;
- }
- if (TALER_PROTOCOL_CURRENT > current)
- {
- *vc |= TALER_AUDITOR_VC_OLDER;
- if (TALER_PROTOCOL_CURRENT - TALER_PROTOCOL_AGE > current)
- *vc |= TALER_AUDITOR_VC_INCOMPATIBLE;
- }
- return TALER_EC_NONE;
-}
-
-
-/**
- * Initiate download of /version from the auditor.
- *
- * @param cls auditor where to download /version from
- */
-static void
-request_version (void *cls);
-
-
-/**
- * Callback used when downloading the reply to a /version request
- * is complete.
- *
- * @param cls the `struct TALER_AUDITOR_Handle`
- * @param response_code HTTP response code, 0 on error
- * @param gresp_obj parsed JSON result, NULL on error, must be a `const json_t *`
- */
-static void
-version_completed_cb (void *cls,
- long response_code,
- const void *gresp_obj)
-{
- struct TALER_AUDITOR_Handle *auditor = cls;
- const json_t *resp_obj = gresp_obj;
- enum TALER_AUDITOR_VersionCompatibility vc;
- struct TALER_AUDITOR_HttpResponse hr = {
- .reply = resp_obj,
- .http_status = (unsigned int) response_code
- };
-
- auditor->vr = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received version from URL `%s' with status %ld.\n",
- auditor->url,
- response_code);
- vc = TALER_AUDITOR_VC_PROTOCOL_ERROR;
- switch (response_code)
- {
- case 0:
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* NOTE: this design is debatable. We MAY want to throw this error at the
- client. We may then still additionally internally re-try. */
- GNUNET_assert (NULL == auditor->retry_task);
- auditor->retry_delay = EXCHANGE_LIB_BACKOFF (auditor->retry_delay);
- auditor->retry_task = GNUNET_SCHEDULER_add_delayed (auditor->retry_delay,
- &request_version,
- auditor);
- return;
- case MHD_HTTP_OK:
- if (NULL == resp_obj)
- {
- GNUNET_break_op (0);
- TALER_LOG_WARNING ("NULL body for a 200-OK /version\n");
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- }
- hr.ec = decode_version_json (resp_obj,
- auditor,
- &vc);
- if (TALER_EC_NONE != hr.ec)
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- break;
- }
- auditor->retry_delay = GNUNET_TIME_UNIT_ZERO; /* restart quickly */
- break;
- default:
- hr.ec = TALER_JSON_get_error_code (resp_obj);
- hr.hint = TALER_JSON_get_error_hint (resp_obj);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d\n",
- (unsigned int) response_code,
- (int) hr.ec);
- break;
- }
- if (MHD_HTTP_OK != response_code)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "/version failed for auditor %s: %u!\n",
- auditor->url,
- (unsigned int) response_code);
- auditor->state = MHS_FAILED;
- /* notify application that we failed */
- auditor->version_cb (auditor->version_cb_cls,
- &hr,
- NULL,
- vc);
- return;
- }
- TALER_LOG_DEBUG ("Switching auditor state to 'version'\n");
- auditor->state = MHS_VERSION;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Auditor %s is now READY!\n",
- auditor->url);
- /* notify application about the key information */
- auditor->version_cb (auditor->version_cb_cls,
- &hr,
- &auditor->vi,
- vc);
-}
-
-
-/**
- * Initiate download of /version from the auditor.
- *
- * @param cls auditor where to download /version from
- */
-static void
-request_version (void *cls)
-{
- struct TALER_AUDITOR_Handle *auditor = cls;
- CURL *eh;
-
- auditor->retry_task = NULL;
- GNUNET_assert (NULL == auditor->vr);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Requesting auditor version with URL `%s'.\n",
- auditor->vr_url);
- eh = TALER_AUDITOR_curl_easy_get_ (auditor->vr_url);
- if (NULL == eh)
- {
- GNUNET_break (0);
- auditor->retry_delay = EXCHANGE_LIB_BACKOFF (auditor->retry_delay);
- auditor->retry_task = GNUNET_SCHEDULER_add_delayed (auditor->retry_delay,
- &request_version,
- auditor);
- return;
- }
- GNUNET_break (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_TIMEOUT,
- (long) 300));
- auditor->vr = GNUNET_CURL_job_add (auditor->ctx,
- eh,
- &version_completed_cb,
- auditor);
-}
-
-
-/* ********************* library internal API ********* */
-
-
-struct GNUNET_CURL_Context *
-TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h)
-{
- return h->ctx;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Checking if auditor at `%s` is now ready: %s\n",
- h->url,
- (MHD_VERSION == h->state) ? "yes" : "no");
- return (MHS_VERSION == h->state) ? GNUNET_YES : GNUNET_NO;
-}
-
-
-char *
-TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
- const char *path)
-{
- GNUNET_assert ('/' == path[0]);
- return TALER_url_join (h->url,
- path + 1,
- NULL);
-}
-
-
-/* ********************* public API ******************* */
-
-
-struct TALER_AUDITOR_Handle *
-TALER_AUDITOR_connect (struct GNUNET_CURL_Context *ctx,
- const char *url,
- TALER_AUDITOR_VersionCallback version_cb,
- void *version_cb_cls)
-{
- struct TALER_AUDITOR_Handle *auditor;
-
- auditor = GNUNET_new (struct TALER_AUDITOR_Handle);
- auditor->version_cb = version_cb;
- auditor->version_cb_cls = version_cb_cls;
- auditor->retry_delay = GNUNET_TIME_UNIT_SECONDS; /* start slowly */
- auditor->ctx = ctx;
- auditor->url = GNUNET_strdup (url);
- auditor->vr_url = TALER_AUDITOR_path_to_url_ (auditor,
- "/version");
- if (NULL == auditor->vr_url)
- {
- GNUNET_break (0);
- GNUNET_free (auditor->url);
- GNUNET_free (auditor);
- return NULL;
- }
- auditor->retry_task = GNUNET_SCHEDULER_add_now (&request_version,
- auditor);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Connecting to auditor at URL `%s'.\n",
- url);
- return auditor;
-}
-
-
-void
-TALER_AUDITOR_disconnect (struct TALER_AUDITOR_Handle *auditor)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Disconnecting from auditor at URL `%s'.\n",
- auditor->url);
- if (NULL != auditor->vr)
- {
- GNUNET_CURL_job_cancel (auditor->vr);
- auditor->vr = NULL;
- }
- if (NULL != auditor->retry_task)
- {
- GNUNET_SCHEDULER_cancel (auditor->retry_task);
- auditor->retry_task = NULL;
- }
- GNUNET_free (auditor->version);
- GNUNET_free (auditor->vr_url);
- GNUNET_free (auditor->url);
- GNUNET_free (auditor);
-}
-
-
-/* end of auditor_api_handle.c */
diff --git a/src/lib/auditor_api_handle.h b/src/lib/auditor_api_handle.h
deleted file mode 100644
index 7ff5bfcdb..000000000
--- a/src/lib/auditor_api_handle.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014, 2015 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/auditor_api_handle.h
- * @brief Internal interface to the handle part of the auditor's HTTP API
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_auditor_service.h"
-#include "taler_curl_lib.h"
-
-/**
- * Get the context of a auditor.
- *
- * @param h the auditor handle to query
- * @return ctx context to execute jobs in
- */
-struct GNUNET_CURL_Context *
-TALER_AUDITOR_handle_to_context_ (struct TALER_AUDITOR_Handle *h);
-
-
-/**
- * Check if the handle is ready to process requests.
- *
- * @param h the auditor handle to query
- * @return #GNUNET_YES if we are ready, #GNUNET_NO if not
- */
-int
-TALER_AUDITOR_handle_is_ready_ (struct TALER_AUDITOR_Handle *h);
-
-
-/**
- * Obtain the URL to use for an API request.
- *
- * @param h the auditor handle to query
- * @param path Taler API path (i.e. "/deposit-confirmation")
- * @return the full URL to use with cURL
- */
-char *
-TALER_AUDITOR_path_to_url_ (struct TALER_AUDITOR_Handle *h,
- const char *path);
-
-
-/* end of auditor_api_handle.h */
diff --git a/src/lib/exchange_api_add_aml_decision.c b/src/lib/exchange_api_add_aml_decision.c
new file mode 100644
index 000000000..342e1e3dc
--- /dev/null
+++ b/src/lib/exchange_api_add_aml_decision.c
@@ -0,0 +1,246 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_add_aml_decision.c
+ * @brief functions to add an AML decision by an AML officer
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "exchange_api_curl_defaults.h"
+#include "taler_signatures.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+
+
+struct TALER_EXCHANGE_AddAmlDecision
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Minor context that holds body and headers.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_AddAmlDecisionCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Reference to the execution context.
+ */
+ struct GNUNET_CURL_Context *ctx;
+};
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP POST /aml/$OFFICER_PUB/decision request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_AddAmlDecision *`
+ * @param response_code HTTP response code, 0 on error
+ * @param response response body, NULL if not in JSON
+ */
+static void
+handle_add_aml_decision_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_AddAmlDecision *wh = cls;
+ const json_t *json = response;
+ struct TALER_EXCHANGE_AddAmlDecisionResponse adr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
+ };
+
+ wh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ /* no reply */
+ adr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ adr.hr.hint = "server offline?";
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_CONFLICT:
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange AML decision\n",
+ (unsigned int) response_code,
+ (int) adr.hr.ec);
+ break;
+ }
+ if (NULL != wh->cb)
+ {
+ wh->cb (wh->cb_cls,
+ &adr);
+ wh->cb = NULL;
+ }
+ TALER_EXCHANGE_add_aml_decision_cancel (wh);
+}
+
+
+struct TALER_EXCHANGE_AddAmlDecision *
+TALER_EXCHANGE_add_aml_decision (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ TALER_EXCHANGE_AddAmlDecisionCallback cb,
+ void *cb_cls)
+{
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ struct TALER_AmlOfficerSignatureP officer_sig;
+ struct TALER_EXCHANGE_AddAmlDecision *wh;
+ CURL *eh;
+ json_t *body;
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&officer_priv->eddsa_priv,
+ &officer_pub.eddsa_pub);
+ TALER_officer_aml_decision_sign (justification,
+ decision_time,
+ new_threshold,
+ h_payto,
+ new_state,
+ kyc_requirements,
+ officer_priv,
+ &officer_sig);
+ wh = GNUNET_new (struct TALER_EXCHANGE_AddAmlDecision);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ctx = ctx;
+ {
+ char *path;
+ char opus[sizeof (officer_pub) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &officer_pub,
+ sizeof (officer_pub),
+ opus,
+ sizeof (opus));
+ *end = '\0';
+ GNUNET_asprintf (&path,
+ "aml/%s/decision",
+ opus);
+ wh->url = TALER_url_join (url,
+ path,
+ NULL);
+ GNUNET_free (path);
+ }
+ if (NULL == wh->url)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not construct request URL.\n");
+ GNUNET_free (wh);
+ return NULL;
+ }
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("justification",
+ justification),
+ GNUNET_JSON_pack_data_auto ("officer_sig",
+ &officer_sig),
+ GNUNET_JSON_pack_data_auto ("h_payto",
+ h_payto),
+ GNUNET_JSON_pack_uint64 ("new_state",
+ (uint32_t) new_state),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_array_incref ("kyc_requirements",
+ (json_t *) kyc_requirements)),
+ TALER_JSON_pack_amount ("new_threshold",
+ new_threshold),
+ GNUNET_JSON_pack_timestamp ("decision_time",
+ decision_time));
+ eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&wh->post_ctx,
+ eh,
+ body)) )
+ {
+ GNUNET_break (0);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ GNUNET_free (wh->url);
+ return NULL;
+ }
+ json_decref (body);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting URL '%s'\n",
+ wh->url);
+ wh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ wh->post_ctx.headers,
+ &handle_add_aml_decision_finished,
+ wh);
+ if (NULL == wh->job)
+ {
+ TALER_EXCHANGE_add_aml_decision_cancel (wh);
+ return NULL;
+ }
+ return wh;
+}
+
+
+void
+TALER_EXCHANGE_add_aml_decision_cancel (
+ struct TALER_EXCHANGE_AddAmlDecision *wh)
+{
+ if (NULL != wh->job)
+ {
+ GNUNET_CURL_job_cancel (wh->job);
+ wh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&wh->post_ctx);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+}
diff --git a/src/lib/exchange_api_age_withdraw.c b/src/lib/exchange_api_age_withdraw.c
new file mode 100644
index 000000000..ca1a11cb8
--- /dev/null
+++ b/src/lib/exchange_api_age_withdraw.c
@@ -0,0 +1,1125 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_age_withdraw.c
+ * @brief Implementation of /reserves/$RESERVE_PUB/age-withdraw requests
+ * @author Özgür Kesim
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include <sys/wait.h>
+#include "taler_curl_lib.h"
+#include "taler_error_codes.h"
+#include "taler_json_lib.h"
+#include "taler_exchange_service.h"
+#include "exchange_api_common.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+#include "taler_util.h"
+
+/**
+ * A CoinCandidate is populated from a master secret
+ */
+struct CoinCandidate
+{
+ /**
+ * Master key material for the coin candidates.
+ */
+ struct TALER_PlanchetMasterSecretP secret;
+
+ /**
+ * The details derived form the master secrets
+ */
+ struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails details;
+
+ /**
+ * Blinded hash of the coin
+ **/
+ struct TALER_BlindedCoinHashP blinded_coin_h;
+
+};
+
+
+/**
+ * Closure for a call to /csr-withdraw, contains data that is needed to process
+ * the result.
+ */
+struct CSRClosure
+{
+ /**
+ * Points to the actual candidate in CoinData.coin_candidates, to continue
+ * to build its contents based on the results from /csr-withdraw
+ */
+ struct CoinCandidate *candidate;
+
+ /**
+ * The planchet to finally generate. Points to the corresponding candidate
+ * in CoindData.planchet_details
+ */
+ struct TALER_PlanchetDetail *planchet;
+
+ /**
+ * Handler to the originating call to /age-withdraw, needed to either
+ * cancel the running age-withdraw request (on failure of the current call
+ * to /csr-withdraw), or to eventually perform the protocol, once all
+ * csr-withdraw requests have successfully finished.
+ */
+ struct TALER_EXCHANGE_AgeWithdrawHandle *age_withdraw_handle;
+
+ /**
+ * Session nonce.
+ */
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+
+ /**
+ * Denomination information, needed for CS coins for the
+ * step after /csr-withdraw
+ */
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+
+ /**
+ * Handler for the CS R request
+ */
+ struct TALER_EXCHANGE_CsRWithdrawHandle *csr_withdraw_handle;
+};
+
+/**
+ * Data we keep per coin in the batch.
+ */
+struct CoinData
+{
+ /**
+ * The denomination of the coin. Must support age restriction, i.e
+ * its .keys.age_mask MUST not be 0
+ */
+ struct TALER_EXCHANGE_DenomPublicKey denom_pub;
+
+ /**
+ * The Candidates for the coin
+ */
+ struct CoinCandidate coin_candidates[TALER_CNC_KAPPA];
+
+ /**
+ * Details of the planchet(s).
+ */
+ struct TALER_PlanchetDetail planchet_details[TALER_CNC_KAPPA];
+
+ /**
+ * Closure for each candidate of type CS for the preflight request to
+ * /csr-withdraw
+ */
+ struct CSRClosure csr_cls[TALER_CNC_KAPPA];
+};
+
+/**
+ * A /reserves/$RESERVE_PUB/age-withdraw request-handle for calls with
+ * pre-blinded planchets. Returned by TALER_EXCHANGE_age_withdraw_blinded.
+ */
+struct TALER_EXCHANGE_AgeWithdrawBlindedHandle
+{
+
+ /**
+ * Reserve private key.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
+ * Reserve public key, calculated
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Signature of the reserve for the request, calculated after all
+ * parameters for the coins are collected.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /*
+ * The denomination keys of the exchange
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * The age mask, extracted from the denominations.
+ * MUST be the same for all denominations
+ *
+ */
+ struct TALER_AgeMask age_mask;
+
+ /**
+ * Maximum age to commit to.
+ */
+ uint8_t max_age;
+
+ /**
+ * The commitment calculated as SHA512 hash over all blinded_coin_h
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * Total amount requested (value plus withdraw fee).
+ */
+ struct TALER_Amount amount_with_fee;
+
+ /**
+ * Length of the @e blinded_input Array
+ */
+ size_t num_input;
+
+ /**
+ * The blinded planchet input for the call to /age-withdraw via
+ * TALER_EXCHANGE_age_withdraw_blinded
+ */
+ const struct TALER_EXCHANGE_AgeWithdrawBlindedInput *blinded_input;
+
+ /**
+ * The url for this request.
+ */
+ char *request_url;
+
+ /**
+ * Context for curl.
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * CURL handle for the request job.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Post Context
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Function to call with age-withdraw response results.
+ */
+ TALER_EXCHANGE_AgeWithdrawBlindedCallback callback;
+
+ /**
+ * Closure for @e blinded_callback
+ */
+ void *callback_cls;
+};
+
+/**
+ * A /reserves/$RESERVE_PUB/age-withdraw request-handle for calls from
+ * a wallet, i. e. when blinding data is available.
+ */
+struct TALER_EXCHANGE_AgeWithdrawHandle
+{
+
+ /**
+ * Length of the @e coin_data Array
+ */
+ size_t num_coins;
+
+ /**
+ * The base-URL of the exchange.
+ */
+ const char *exchange_url;
+
+ /**
+ * Reserve private key.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
+ * Reserve public key, calculated
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Signature of the reserve for the request, calculated after all
+ * parameters for the coins are collected.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /*
+ * The denomination keys of the exchange
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * The age mask, extracted from the denominations.
+ * MUST be the same for all denominations
+ *
+ */
+ struct TALER_AgeMask age_mask;
+
+ /**
+ * Maximum age to commit to.
+ */
+ uint8_t max_age;
+
+ /**
+ * Array of per-coin data
+ */
+ struct CoinData *coin_data;
+
+ /**
+ * Context for curl.
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ struct
+ {
+ /**
+ * Number of /csr-withdraw requests still pending.
+ */
+ unsigned int pending;
+
+ /**
+ * CURL handle for the request job.
+ */
+ struct GNUNET_CURL_Job *job;
+ } csr;
+
+
+ /**
+ * Function to call with age-withdraw response results.
+ */
+ TALER_EXCHANGE_AgeWithdrawCallback callback;
+
+ /**
+ * Closure for @e age_withdraw_cb
+ */
+ void *callback_cls;
+
+ /* The Handler for the actual call to the exchange */
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *procotol_handle;
+};
+
+/**
+ * We got a 200 OK response for the /reserves/$RESERVE_PUB/age-withdraw operation.
+ * Extract the noreveal_index and return it to the caller.
+ *
+ * @param awbh operation handle
+ * @param j_response reply from the exchange
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
+ */
+static enum GNUNET_GenericReturnValue
+reserve_age_withdraw_ok (
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh,
+ const json_t *j_response)
+{
+ struct TALER_EXCHANGE_AgeWithdrawBlindedResponse response = {
+ .hr.reply = j_response,
+ .hr.http_status = MHD_HTTP_OK,
+ .details.ok.h_commitment = awbh->h_commitment
+ };
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint8 ("noreveal_index",
+ &response.details.ok.noreveal_index),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &response.details.ok.exchange_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK!=
+ GNUNET_JSON_parse (j_response,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ if (GNUNET_OK !=
+ TALER_exchange_online_age_withdraw_confirmation_verify (
+ &awbh->h_commitment,
+ response.details.ok.noreveal_index,
+ &response.details.ok.exchange_pub,
+ &exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+
+ }
+
+ awbh->callback (awbh->callback_cls,
+ &response);
+ /* make sure the callback isn't called again */
+ awbh->callback = NULL;
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /reserves/$RESERVE_PUB/age-withdraw request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_AgeWithdrawHandle`
+ * @param response_code The HTTP response code
+ * @param response response data
+ */
+static void
+handle_reserve_age_withdraw_blinded_finished (
+ void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh = cls;
+ const json_t *j_response = response;
+ struct TALER_EXCHANGE_AgeWithdrawBlindedResponse awbr = {
+ .hr.reply = j_response,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ awbh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ awbr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ reserve_age_withdraw_ok (awbh,
+ j_response))
+ {
+ GNUNET_break_op (0);
+ awbr.hr.http_status = 0;
+ awbr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ GNUNET_assert (NULL == awbh->callback);
+ TALER_EXCHANGE_age_withdraw_blinded_cancel (awbh);
+ return;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ GNUNET_break_op (0);
+ /* Nothing really to verify, exchange says one of the signatures is
+ invalid; as we checked them, this should never happen, we
+ should pass the JSON reply to the application */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, the exchange basically just says
+ that it doesn't know this reserve. Can happen if we
+ query before the wire transfer went through.
+ We should simply pass the JSON reply to the application. */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* The age requirements might not have been met */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_GONE:
+ /* could happen if denomination was revoked */
+ /* Note: one might want to check /keys for revocation
+ signature here, alas tricky in case our /keys
+ is outdated => left to clients */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* only validate reply is well-formed */
+ {
+ uint64_t ptu;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 ("requirement_row",
+ &ptu),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j_response,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ awbr.hr.http_status = 0;
+ awbr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ }
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ awbr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awbr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange age-withdraw\n",
+ (unsigned int) response_code,
+ (int) awbr.hr.ec);
+ break;
+ }
+ awbh->callback (awbh->callback_cls,
+ &awbr);
+ TALER_EXCHANGE_age_withdraw_blinded_cancel (awbh);
+}
+
+
+/**
+ * Runs the actual age-withdraw operation with the blinded planchets.
+ *
+ * @param[in,out] awbh age withdraw handler
+ */
+static void
+perform_protocol (
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh)
+{
+#define FAIL_IF(cond) \
+ do { \
+ if ((cond)) \
+ { \
+ GNUNET_break (! (cond)); \
+ goto ERROR; \
+ } \
+ } while (0)
+
+ struct GNUNET_HashContext *coins_hctx = NULL;
+ json_t *j_denoms = NULL;
+ json_t *j_array_candidates = NULL;
+ json_t *j_request_body = NULL;
+ CURL *curlh = NULL;
+
+ GNUNET_assert (0 < awbh->num_input);
+ awbh->age_mask = awbh->blinded_input[0].denom_pub->key.age_mask;
+
+ FAIL_IF (GNUNET_OK !=
+ TALER_amount_set_zero (awbh->keys->currency,
+ &awbh->amount_with_fee));
+ /* Accumulate total value with fees */
+ for (size_t i = 0; i < awbh->num_input; i++)
+ {
+ struct TALER_Amount coin_total;
+ const struct TALER_EXCHANGE_DenomPublicKey *dpub =
+ awbh->blinded_input[i].denom_pub;
+
+ FAIL_IF (0 >
+ TALER_amount_add (&coin_total,
+ &dpub->fees.withdraw,
+ &dpub->value));
+ FAIL_IF (0 >
+ TALER_amount_add (&awbh->amount_with_fee,
+ &awbh->amount_with_fee,
+ &coin_total));
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Attempting to age-withdraw from reserve %s with maximum age %d\n",
+ TALER_B2S (&awbh->reserve_pub),
+ awbh->max_age);
+
+ coins_hctx = GNUNET_CRYPTO_hash_context_start ();
+ FAIL_IF (NULL == coins_hctx);
+
+
+ j_denoms = json_array ();
+ j_array_candidates = json_array ();
+ FAIL_IF ((NULL == j_denoms) ||
+ (NULL == j_array_candidates));
+
+ for (size_t i = 0; i< awbh->num_input; i++)
+ {
+ /* Build the denomination array */
+ {
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub =
+ awbh->blinded_input[i].denom_pub;
+ const struct TALER_DenominationHashP *denom_h = &denom_pub->h_key;
+ json_t *jdenom;
+
+ /* The mask must be the same for all coins */
+ FAIL_IF (awbh->age_mask.bits != denom_pub->key.age_mask.bits);
+
+ jdenom = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto (NULL,
+ denom_h));
+ FAIL_IF (NULL == jdenom);
+ FAIL_IF (0 > json_array_append_new (j_denoms,
+ jdenom));
+
+ /* Build the candidate array */
+ {
+ json_t *j_can = json_array ();
+ FAIL_IF (NULL == j_can);
+
+ for (size_t k = 0; k < TALER_CNC_KAPPA; k++)
+ {
+ struct TALER_BlindedCoinHashP bch;
+ const struct TALER_PlanchetDetail *planchet =
+ &awbh->blinded_input[i].planchet_details[k];
+ json_t *jc = GNUNET_JSON_PACK (
+ TALER_JSON_pack_blinded_planchet (
+ NULL,
+ &planchet->blinded_planchet));
+
+ FAIL_IF (NULL == jc);
+ FAIL_IF (0 > json_array_append_new (j_can,
+ jc));
+
+ TALER_coin_ev_hash (&planchet->blinded_planchet,
+ &planchet->denom_pub_hash,
+ &bch);
+
+ GNUNET_CRYPTO_hash_context_read (coins_hctx,
+ &bch,
+ sizeof(bch));
+ }
+
+ FAIL_IF (0 > json_array_append_new (j_array_candidates,
+ j_can));
+ }
+ }
+ }
+
+ /* Build the hash of the commitment */
+ GNUNET_CRYPTO_hash_context_finish (coins_hctx,
+ &awbh->h_commitment.hash);
+ coins_hctx = NULL;
+
+ /* Sign the request */
+ TALER_wallet_age_withdraw_sign (&awbh->h_commitment,
+ &awbh->amount_with_fee,
+ &awbh->age_mask,
+ awbh->max_age,
+ awbh->reserve_priv,
+ &awbh->reserve_sig);
+
+ /* Initiate the POST-request */
+ j_request_body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("denom_hs", j_denoms),
+ GNUNET_JSON_pack_array_steal ("blinded_coin_evs", j_array_candidates),
+ GNUNET_JSON_pack_uint64 ("max_age", awbh->max_age),
+ GNUNET_JSON_pack_data_auto ("reserve_sig", &awbh->reserve_sig));
+ FAIL_IF (NULL == j_request_body);
+
+ curlh = TALER_EXCHANGE_curl_easy_get_ (awbh->request_url);
+ FAIL_IF (NULL == curlh);
+ FAIL_IF (GNUNET_OK !=
+ TALER_curl_easy_post (&awbh->post_ctx,
+ curlh,
+ j_request_body));
+ json_decref (j_request_body);
+ j_request_body = NULL;
+
+ awbh->job = GNUNET_CURL_job_add2 (
+ awbh->curl_ctx,
+ curlh,
+ awbh->post_ctx.headers,
+ &handle_reserve_age_withdraw_blinded_finished,
+ awbh);
+ FAIL_IF (NULL == awbh->job);
+
+ /* No errors, return */
+ return;
+
+ERROR:
+ if (NULL != j_denoms)
+ json_decref (j_denoms);
+ if (NULL != j_array_candidates)
+ json_decref (j_array_candidates);
+ if (NULL != j_request_body)
+ json_decref (j_request_body);
+ if (NULL != curlh)
+ curl_easy_cleanup (curlh);
+ if (NULL != coins_hctx)
+ GNUNET_CRYPTO_hash_context_abort (coins_hctx);
+ TALER_EXCHANGE_age_withdraw_blinded_cancel (awbh);
+ return;
+#undef FAIL_IF
+}
+
+
+/**
+ * @brief Callback to copy the results from the call to TALER_age_withdraw_blinded
+ * to the result for the originating call from TALER_age_withdraw.
+ *
+ * @param cls struct TALER_AgeWithdrawHandle
+ * @param awbr The response
+ */
+static void
+copy_results (
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawBlindedResponse *awbr)
+{
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh = cls;
+ uint8_t k = awbr->details.ok.noreveal_index;
+ struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails details[awh->num_coins];
+ struct TALER_BlindedCoinHashP blinded_coin_hs[awh->num_coins];
+ struct TALER_EXCHANGE_AgeWithdrawResponse resp = {
+ .hr = awbr->hr,
+ .details = {
+ .ok = {
+ .noreveal_index = awbr->details.ok.noreveal_index,
+ .h_commitment = awbr->details.ok.h_commitment,
+ .exchange_pub = awbr->details.ok.exchange_pub,
+ .num_coins = awh->num_coins,
+ .coin_details = details,
+ .blinded_coin_hs = blinded_coin_hs
+ },
+ },
+ };
+
+ for (size_t n = 0; n< awh->num_coins; n++)
+ {
+ details[n] = awh->coin_data[n].coin_candidates[k].details;
+ details[n].planchet = awh->coin_data[n].planchet_details[k];
+ blinded_coin_hs[n] = awh->coin_data[n].coin_candidates[k].blinded_coin_h;
+ }
+ awh->callback (awh->callback_cls,
+ &resp);
+ awh->callback = NULL;
+}
+
+
+/**
+ * @brief Prepares and executes TALER_EXCHANGE_age_withdraw_blinded.
+ * If there were CS-denominations involved, started once the all calls
+ * to /csr-withdraw are done.
+ */
+static void
+call_age_withdraw_blinded (
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh)
+{
+ struct TALER_EXCHANGE_AgeWithdrawBlindedInput blinded_input[awh->num_coins];
+
+ /* Prepare the blinded planchets as input */
+ for (size_t n = 0; n < awh->num_coins; n++)
+ {
+ blinded_input[n].denom_pub = &awh->coin_data[n].denom_pub;
+ for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
+ blinded_input[n].planchet_details[k] =
+ awh->coin_data[n].planchet_details[k];
+ }
+
+ awh->procotol_handle =
+ TALER_EXCHANGE_age_withdraw_blinded (
+ awh->curl_ctx,
+ awh->keys,
+ awh->exchange_url,
+ awh->reserve_priv,
+ awh->max_age,
+ awh->num_coins,
+ blinded_input,
+ copy_results,
+ awh);
+}
+
+
+/**
+ * Prepares the request URL for the age-withdraw request
+ *
+ * @param awbh The handler
+ * @param exchange_url The base-URL to the exchange
+ */
+static
+enum GNUNET_GenericReturnValue
+prepare_url (
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh,
+ const char *exchange_url)
+{
+ char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
+ char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &awbh->reserve_pub,
+ sizeof (awbh->reserve_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves/%s/age-withdraw",
+ pub_str);
+
+ awbh->request_url = TALER_url_join (exchange_url,
+ arg_str,
+ NULL);
+ if (NULL == awbh->request_url)
+ {
+ GNUNET_break (0);
+ TALER_EXCHANGE_age_withdraw_blinded_cancel (awbh);
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * @brief Function called when CSR withdraw retrieval is finished
+ *
+ * @param cls the `struct CSRClosure *`
+ * @param csrr replies from the /csr-withdraw request
+ */
+static void
+csr_withdraw_done (
+ void *cls,
+ const struct TALER_EXCHANGE_CsRWithdrawResponse *csrr)
+{
+ struct CSRClosure *csr = cls;
+ struct CoinCandidate *can;
+ struct TALER_PlanchetDetail *planchet;
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh;
+
+ GNUNET_assert (NULL != csr);
+ awh = csr->age_withdraw_handle;
+ planchet = csr->planchet;
+ can = csr->candidate;
+
+ GNUNET_assert (NULL != can);
+ GNUNET_assert (NULL != planchet);
+ GNUNET_assert (NULL != awh);
+
+ csr->csr_withdraw_handle = NULL;
+
+ switch (csrr->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ {
+ bool success = false;
+ /* Complete the initialization of the coin with CS denomination */
+
+ TALER_denom_ewv_copy (&can->details.alg_values,
+ &csrr->details.ok.alg_values);
+ GNUNET_assert (can->details.alg_values.blinding_inputs->cipher
+ == GNUNET_CRYPTO_BSA_CS);
+ TALER_planchet_setup_coin_priv (&can->secret,
+ &can->details.alg_values,
+ &can->details.coin_priv);
+ TALER_planchet_blinding_secret_create (&can->secret,
+ &can->details.alg_values,
+ &can->details.blinding_key);
+ /* This initializes the 2nd half of the
+ can->planchet_detail.blinded_planchet! */
+ do {
+ if (GNUNET_OK !=
+ TALER_planchet_prepare (&csr->denom_pub->key,
+ &can->details.alg_values,
+ &can->details.blinding_key,
+ &csr->nonce,
+ &can->details.coin_priv,
+ &can->details.h_age_commitment,
+ &can->details.h_coin_pub,
+ planchet))
+ {
+ GNUNET_break (0);
+ break;
+ }
+
+ TALER_coin_ev_hash (&planchet->blinded_planchet,
+ &planchet->denom_pub_hash,
+ &can->blinded_coin_h);
+ success = true;
+ } while (0);
+
+ awh->csr.pending--;
+
+ /* No more pending requests to /csr-withdraw, we can now perform the
+ * actual age-withdraw operation */
+ if (0 == awh->csr.pending && success)
+ call_age_withdraw_blinded (awh);
+ return;
+ }
+ default:
+ break;
+ }
+ TALER_EXCHANGE_age_withdraw_cancel (awh);
+}
+
+
+/**
+ * @brief Prepare the coins for the call to age-withdraw and calculates
+ * the total amount with fees.
+ *
+ * For denomination with CS as cipher, initiates the preflight to retrieve the
+ * csr-parameter via /csr-withdraw.
+ *
+ * @param awh The handler to the age-withdraw
+ * @param num_coins The number of coins in @e coin_inputs
+ * @param coin_inputs The input for the individual coin(-candidates)
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+static
+enum GNUNET_GenericReturnValue
+prepare_coins (
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh,
+ size_t num_coins,
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[
+ static num_coins])
+{
+#define FAIL_IF(cond) \
+ do { \
+ if ((cond)) \
+ { \
+ GNUNET_break (! (cond)); \
+ goto ERROR; \
+ } \
+ } while (0)
+
+ GNUNET_assert (0 < num_coins);
+ awh->age_mask = coin_inputs[0].denom_pub->key.age_mask;
+
+ awh->coin_data = GNUNET_new_array (awh->num_coins,
+ struct CoinData);
+
+ for (size_t i = 0; i < num_coins; i++)
+ {
+ struct CoinData *cd = &awh->coin_data[i];
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput *input = &coin_inputs[i];
+
+ cd->denom_pub = *input->denom_pub;
+ /* The mask must be the same for all coins */
+ FAIL_IF (awh->age_mask.bits != input->denom_pub->key.age_mask.bits);
+ TALER_denom_pub_copy (&cd->denom_pub.key,
+ &input->denom_pub->key);
+
+ for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
+ {
+ struct CoinCandidate *can = &cd->coin_candidates[k];
+ struct TALER_PlanchetDetail *planchet = &cd->planchet_details[k];
+
+ can->secret = input->secrets[k];
+ /* Derive the age restriction from the given secret and
+ * the maximum age */
+ TALER_age_restriction_from_secret (
+ &can->secret,
+ &input->denom_pub->key.age_mask,
+ awh->max_age,
+ &can->details.age_commitment_proof);
+
+ TALER_age_commitment_hash (&can->details.age_commitment_proof.commitment,
+ &can->details.h_age_commitment);
+
+ switch (input->denom_pub->key.bsign_pub_key->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ TALER_denom_ewv_copy (&can->details.alg_values,
+ TALER_denom_ewv_rsa_singleton ());
+ TALER_planchet_setup_coin_priv (&can->secret,
+ &can->details.alg_values,
+ &can->details.coin_priv);
+ TALER_planchet_blinding_secret_create (&can->secret,
+ &can->details.alg_values,
+ &can->details.blinding_key);
+ FAIL_IF (GNUNET_OK !=
+ TALER_planchet_prepare (&cd->denom_pub.key,
+ &can->details.alg_values,
+ &can->details.blinding_key,
+ NULL,
+ &can->details.coin_priv,
+ &can->details.h_age_commitment,
+ &can->details.h_coin_pub,
+ planchet));
+ TALER_coin_ev_hash (&planchet->blinded_planchet,
+ &planchet->denom_pub_hash,
+ &can->blinded_coin_h);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ {
+ struct CSRClosure *cls = &cd->csr_cls[k];
+ /**
+ * Save the handler and the denomination for the callback
+ * after the call to csr-withdraw */
+ cls->age_withdraw_handle = awh;
+ cls->candidate = can;
+ cls->planchet = planchet;
+ cls->denom_pub = &cd->denom_pub;
+ TALER_cs_withdraw_nonce_derive (
+ &can->secret,
+ &cls->nonce.cs_nonce);
+ cls->csr_withdraw_handle =
+ TALER_EXCHANGE_csr_withdraw (
+ awh->curl_ctx,
+ awh->exchange_url,
+ &cd->denom_pub,
+ &cls->nonce.cs_nonce,
+ &csr_withdraw_done,
+ cls);
+ FAIL_IF (NULL == cls->csr_withdraw_handle);
+
+ awh->csr.pending++;
+ break;
+ }
+ default:
+ FAIL_IF (1);
+ }
+ }
+ }
+ return GNUNET_OK;
+
+ERROR:
+ TALER_EXCHANGE_age_withdraw_cancel (awh);
+ return GNUNET_SYSERR;
+#undef FAIL_IF
+};
+
+struct TALER_EXCHANGE_AgeWithdrawHandle *
+TALER_EXCHANGE_age_withdraw (
+ struct GNUNET_CURL_Context *curl_ctx,
+ struct TALER_EXCHANGE_Keys *keys,
+ const char *exchange_url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ size_t num_coins,
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coin_inputs[const static
+ num_coins],
+ uint8_t max_age,
+ TALER_EXCHANGE_AgeWithdrawCallback res_cb,
+ void *res_cb_cls)
+{
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh;
+
+ awh = GNUNET_new (struct TALER_EXCHANGE_AgeWithdrawHandle);
+ awh->exchange_url = exchange_url;
+ awh->keys = TALER_EXCHANGE_keys_incref (keys);
+ awh->curl_ctx = curl_ctx;
+ awh->reserve_priv = reserve_priv;
+ awh->callback = res_cb;
+ awh->callback_cls = res_cb_cls;
+ awh->num_coins = num_coins;
+ awh->max_age = max_age;
+
+
+ if (GNUNET_OK != prepare_coins (awh,
+ num_coins,
+ coin_inputs))
+ {
+ GNUNET_free (awh);
+ return NULL;
+ }
+
+ /* If there were no CS denominations, we can now perform the actual
+ * age-withdraw protocol. Otherwise, there are calls to /csr-withdraw
+ * in flight and once they finish, the age-withdraw-protocol will be
+ * called from within the csr_withdraw_done-function.
+ */
+ if (0 == awh->csr.pending)
+ call_age_withdraw_blinded (awh);
+
+ return awh;
+}
+
+
+void
+TALER_EXCHANGE_age_withdraw_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawHandle *awh)
+{
+ /* Cleanup coin data */
+ for (unsigned int i = 0; i<awh->num_coins; i++)
+ {
+ struct CoinData *cd = &awh->coin_data[i];
+
+ for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
+ {
+ struct TALER_PlanchetDetail *planchet = &cd->planchet_details[k];
+ struct CSRClosure *cls = &cd->csr_cls[k];
+ struct CoinCandidate *can = &cd->coin_candidates[k];
+
+ if (NULL != cls->csr_withdraw_handle)
+ {
+ TALER_EXCHANGE_csr_withdraw_cancel (cls->csr_withdraw_handle);
+ cls->csr_withdraw_handle = NULL;
+ }
+ TALER_blinded_planchet_free (&planchet->blinded_planchet);
+ TALER_denom_ewv_free (&can->details.alg_values);
+ }
+ TALER_denom_pub_free (&cd->denom_pub.key);
+ }
+ GNUNET_free (awh->coin_data);
+ TALER_EXCHANGE_keys_decref (awh->keys);
+ TALER_EXCHANGE_age_withdraw_blinded_cancel (awh->procotol_handle);
+ awh->procotol_handle = NULL;
+ GNUNET_free (awh);
+}
+
+
+struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *
+TALER_EXCHANGE_age_withdraw_blinded (
+ struct GNUNET_CURL_Context *curl_ctx,
+ struct TALER_EXCHANGE_Keys *keys,
+ const char *exchange_url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ uint8_t max_age,
+ unsigned int num_input,
+ const struct TALER_EXCHANGE_AgeWithdrawBlindedInput blinded_input[static
+ num_input],
+ TALER_EXCHANGE_AgeWithdrawBlindedCallback res_cb,
+ void *res_cb_cls)
+{
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh =
+ GNUNET_new (struct TALER_EXCHANGE_AgeWithdrawBlindedHandle);
+
+ awbh->num_input = num_input;
+ awbh->blinded_input = blinded_input;
+ awbh->keys = TALER_EXCHANGE_keys_incref (keys);
+ awbh->curl_ctx = curl_ctx;
+ awbh->reserve_priv = reserve_priv;
+ awbh->callback = res_cb;
+ awbh->callback_cls = res_cb_cls;
+ awbh->max_age = max_age;
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&awbh->reserve_priv->eddsa_priv,
+ &awbh->reserve_pub.eddsa_pub);
+
+ if (GNUNET_OK != prepare_url (awbh,
+ exchange_url))
+ return NULL;
+
+ perform_protocol (awbh);
+ return awbh;
+}
+
+
+void
+TALER_EXCHANGE_age_withdraw_blinded_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawBlindedHandle *awbh)
+{
+ if (NULL == awbh)
+ return;
+
+ if (NULL != awbh->job)
+ {
+ GNUNET_CURL_job_cancel (awbh->job);
+ awbh->job = NULL;
+ }
+ GNUNET_free (awbh->request_url);
+ TALER_EXCHANGE_keys_decref (awbh->keys);
+ TALER_curl_easy_post_finished (&awbh->post_ctx);
+ GNUNET_free (awbh);
+}
+
+
+/* exchange_api_age_withdraw.c */
diff --git a/src/lib/exchange_api_age_withdraw_reveal.c b/src/lib/exchange_api_age_withdraw_reveal.c
new file mode 100644
index 000000000..cade528d2
--- /dev/null
+++ b/src/lib/exchange_api_age_withdraw_reveal.c
@@ -0,0 +1,477 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_age_withdraw_reveal.c
+ * @brief Implementation of /age-withdraw/$ACH/reveal requests
+ * @author Özgür Kesim
+ */
+
+#include "platform.h"
+#include <gnunet/gnunet_common.h>
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+#include "taler_exchange_service.h"
+#include "exchange_api_common.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+/**
+ * Handler for a running age-withdraw-reveal request
+ */
+struct TALER_EXCHANGE_AgeWithdrawRevealHandle
+{
+
+ /* The index not to be disclosed */
+ uint8_t noreveal_index;
+
+ /* The age-withdraw commitment */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /* The reserve's public key */
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ /* Number of coins */
+ size_t num_coins;
+
+ /* The @e num_coins * kappa coin secrets from the age-withdraw commitment */
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput *coins_input;
+
+ /* The url for the reveal request */
+ char *request_url;
+
+ /**
+ * CURL handle for the request job.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Post Context
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /* Callback */
+ TALER_EXCHANGE_AgeWithdrawRevealCallback callback;
+
+ /* Reveal */
+ void *callback_cls;
+};
+
+
+/**
+ * We got a 200 OK response for the /age-withdraw/$ACH/reveal operation.
+ * Extract the signed blindedcoins and return it to the caller.
+ *
+ * @param awrh operation handle
+ * @param j_response reply from the exchange
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
+ */
+static enum GNUNET_GenericReturnValue
+age_withdraw_reveal_ok (
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh,
+ const json_t *j_response)
+{
+ struct TALER_EXCHANGE_AgeWithdrawRevealResponse response = {
+ .hr.reply = j_response,
+ .hr.http_status = MHD_HTTP_OK,
+ };
+ const json_t *j_sigs;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("ev_sigs",
+ &j_sigs),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK != GNUNET_JSON_parse (j_response,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ if (awrh->num_coins != json_array_size (j_sigs))
+ {
+ /* Number of coins generated does not match our expectation */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ {
+ struct TALER_BlindedDenominationSignature denom_sigs[awrh->num_coins];
+ json_t *j_sig;
+ size_t n;
+
+ /* Reconstruct the coins and unblind the signatures */
+ json_array_foreach (j_sigs, n, j_sig)
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_blinded_denom_sig (NULL,
+ &denom_sigs[n]),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK != GNUNET_JSON_parse (j_sig,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ }
+
+ response.details.ok.num_sigs = awrh->num_coins;
+ response.details.ok.blinded_denom_sigs = denom_sigs;
+ awrh->callback (awrh->callback_cls,
+ &response);
+ /* Make sure the callback isn't called again */
+ awrh->callback = NULL;
+ /* Free resources */
+ for (size_t i = 0; i < awrh->num_coins; i++)
+ TALER_blinded_denom_sig_free (&denom_sigs[i]);
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /age-withdraw/$ACH/reveal request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_AgeWithdrawRevealHandle`
+ * @param response_code The HTTP response code
+ * @param response response data
+ */
+static void
+handle_age_withdraw_reveal_finished (
+ void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh = cls;
+ const json_t *j_response = response;
+ struct TALER_EXCHANGE_AgeWithdrawRevealResponse awr = {
+ .hr.reply = j_response,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ awrh->job = NULL;
+ /* FIXME[oec]: Only handle response-codes that are in the spec */
+ switch (response_code)
+ {
+ case 0:
+ awr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ {
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = age_withdraw_reveal_ok (awrh,
+ j_response);
+ if (GNUNET_OK != ret)
+ {
+ GNUNET_break_op (0);
+ awr.hr.http_status = 0;
+ awr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ GNUNET_assert (NULL == awrh->callback);
+ TALER_EXCHANGE_age_withdraw_reveal_cancel (awrh);
+ return;
+ }
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* only validate reply is well-formed */
+ {
+ uint64_t ptu;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 ("legitimization_uuid",
+ &ptu),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j_response,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ awr.hr.http_status = 0;
+ awr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ }
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ GNUNET_break_op (0);
+ /**
+ * This should never happen, as we don't sent any signatures
+ * to the exchange to verify. We should simply pass the JSON reply
+ * to the application
+ **/
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, the exchange basically just says
+ that it doesn't know this age-withdraw commitment. */
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* An age commitment for one of the coins did not fulfill
+ * the required maximum age requirement of the corresponding
+ * reserve.
+ * Error code: TALER_EC_EXCHANGE_GENERIC_COIN_AGE_REQUIREMENT_FAILURE.
+ */
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_GONE:
+ /* could happen if denomination was revoked */
+ /* Note: one might want to check /keys for revocation
+ signature here, alas tricky in case our /keys
+ is outdated => left to clients */
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ awr.hr.ec = TALER_JSON_get_error_code (j_response);
+ awr.hr.hint = TALER_JSON_get_error_hint (j_response);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange age-withdraw\n",
+ (unsigned int) response_code,
+ (int) awr.hr.ec);
+ break;
+ }
+ awrh->callback (awrh->callback_cls,
+ &awr);
+ TALER_EXCHANGE_age_withdraw_reveal_cancel (awrh);
+}
+
+
+/**
+ * Prepares the request URL for the age-withdraw-reveal request
+ *
+ * @param exchange_url The base-URL to the exchange
+ * @param[in,out] awrh The handler
+ * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
+ */
+static
+enum GNUNET_GenericReturnValue
+prepare_url (
+ const char *exchange_url,
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh)
+{
+ char arg_str[sizeof (struct TALER_AgeWithdrawCommitmentHashP) * 2 + 32];
+ char pub_str[sizeof (struct TALER_AgeWithdrawCommitmentHashP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (&awrh->h_commitment,
+ sizeof (awrh->h_commitment),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "age-withdraw/%s/reveal",
+ pub_str);
+
+ awrh->request_url = TALER_url_join (exchange_url,
+ arg_str,
+ NULL);
+ if (NULL == awrh->request_url)
+ {
+ GNUNET_break (0);
+ TALER_EXCHANGE_age_withdraw_reveal_cancel (awrh);
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+/**
+ * Call /age-withdraw/$ACH/reveal
+ *
+ * @param curl_ctx The context for CURL
+ * @param awrh The handler
+ */
+static
+void
+perform_protocol (
+ struct GNUNET_CURL_Context *curl_ctx,
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh)
+{
+ CURL *curlh = NULL;
+ json_t *j_request_body = NULL;
+ json_t *j_array_of_secrets = NULL;
+ json_t *j_secrets = NULL;
+ json_t *j_sec = NULL;
+
+#define FAIL_IF(cond) \
+ do { \
+ if ((cond)) \
+ { \
+ GNUNET_break (! (cond)); \
+ goto ERROR; \
+ } \
+ } while (0)
+
+ j_array_of_secrets = json_array ();
+ FAIL_IF (NULL == j_array_of_secrets);
+
+ for (size_t n = 0; n < awrh->num_coins; n++)
+ {
+ const struct TALER_PlanchetMasterSecretP *secrets =
+ awrh->coins_input[n].secrets;
+
+ j_secrets = json_array ();
+ FAIL_IF (NULL == j_secrets);
+
+ for (uint8_t k = 0; k < TALER_CNC_KAPPA; k++)
+ {
+ const struct TALER_PlanchetMasterSecretP *secret = &secrets[k];
+ if (awrh->noreveal_index == k)
+ continue;
+
+ j_sec = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto (NULL, secret));
+
+ FAIL_IF (NULL == j_sec);
+ FAIL_IF (0 < json_array_append_new (j_secrets,
+ j_sec));
+ }
+
+ FAIL_IF (0 < json_array_append_new (j_array_of_secrets,
+ j_secrets));
+ }
+ j_request_body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("reserve_pub",
+ awrh->reserve_pub),
+ GNUNET_JSON_pack_array_steal ("disclosed_coin_secrets",
+ j_array_of_secrets));
+ FAIL_IF (NULL == j_request_body);
+
+ curlh = TALER_EXCHANGE_curl_easy_get_ (awrh->request_url);
+ FAIL_IF (NULL == curlh);
+ FAIL_IF (GNUNET_OK !=
+ TALER_curl_easy_post (&awrh->post_ctx,
+ curlh,
+ j_request_body));
+ json_decref (j_request_body);
+ j_request_body = NULL;
+
+ awrh->job = GNUNET_CURL_job_add2 (curl_ctx,
+ curlh,
+ awrh->post_ctx.headers,
+ &handle_age_withdraw_reveal_finished,
+ awrh);
+ FAIL_IF (NULL == awrh->job);
+
+ /* No error, return */
+ return;
+
+ERROR:
+ if (NULL != j_sec)
+ json_decref (j_sec);
+ if (NULL != j_secrets)
+ json_decref (j_secrets);
+ if (NULL != j_array_of_secrets)
+ json_decref (j_array_of_secrets);
+ if (NULL != j_request_body)
+ json_decref (j_request_body);
+ if (NULL != curlh)
+ curl_easy_cleanup (curlh);
+ TALER_EXCHANGE_age_withdraw_reveal_cancel (awrh);
+ return;
+#undef FAIL_IF
+}
+
+
+struct TALER_EXCHANGE_AgeWithdrawRevealHandle *
+TALER_EXCHANGE_age_withdraw_reveal (
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ size_t num_coins,
+ const struct TALER_EXCHANGE_AgeWithdrawCoinInput coins_input[static
+ num_coins],
+ uint8_t noreveal_index,
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ TALER_EXCHANGE_AgeWithdrawRevealCallback reveal_cb,
+ void *reveal_cb_cls)
+{
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh =
+ GNUNET_new (struct TALER_EXCHANGE_AgeWithdrawRevealHandle);
+ awrh->noreveal_index = noreveal_index;
+ awrh->h_commitment = *h_commitment;
+ awrh->num_coins = num_coins;
+ awrh->coins_input = coins_input;
+ awrh->callback = reveal_cb;
+ awrh->callback_cls = reveal_cb_cls;
+ awrh->reserve_pub = reserve_pub;
+
+ if (GNUNET_OK !=
+ prepare_url (exchange_url,
+ awrh))
+ return NULL;
+
+ perform_protocol (curl_ctx, awrh);
+
+ return awrh;
+}
+
+
+void
+TALER_EXCHANGE_age_withdraw_reveal_cancel (
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *awrh)
+{
+ if (NULL != awrh->job)
+ {
+ GNUNET_CURL_job_cancel (awrh->job);
+ awrh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&awrh->post_ctx);
+
+ if (NULL != awrh->request_url)
+ GNUNET_free (awrh->request_url);
+
+ GNUNET_free (awrh);
+}
+
+
+/* exchange_api_age_withdraw_reveal.c */
diff --git a/src/lib/exchange_api_auditor_add_denomination.c b/src/lib/exchange_api_auditor_add_denomination.c
index 71f421d4d..89de0d7f1 100644
--- a/src/lib/exchange_api_auditor_add_denomination.c
+++ b/src/lib/exchange_api_auditor_add_denomination.c
@@ -79,9 +79,9 @@ handle_auditor_add_denomination_finished (void *cls,
{
struct TALER_EXCHANGE_AuditorAddDenominationHandle *ah = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_AuditorAddDenominationResponse adr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
ah->job = NULL;
@@ -90,37 +90,37 @@ handle_auditor_add_denomination_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_GONE:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_PRECONDITION_FAILED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
if (NULL != json)
{
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange auditor-add-denomination at URL `%s'\n",
(unsigned int) response_code,
- (int) hr.ec,
+ (int) adr.hr.ec,
ah->url);
}
else
{
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = NULL;
+ adr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ adr.hr.hint = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected HTTP response code %u (no JSON returned) at URL `%s'\n",
(unsigned int) response_code,
@@ -131,7 +131,7 @@ handle_auditor_add_denomination_finished (void *cls,
if (NULL != ah->cb)
{
ah->cb (ah->cb_cls,
- &hr);
+ &adr);
ah->cb = NULL;
}
TALER_EXCHANGE_add_auditor_denomination_cancel (ah);
diff --git a/src/lib/exchange_api_batch_deposit.c b/src/lib/exchange_api_batch_deposit.c
index 043aa0619..3dab64526 100644
--- a/src/lib/exchange_api_batch_deposit.c
+++ b/src/lib/exchange_api_batch_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -44,6 +44,39 @@
*/
#define AUDITOR_CHANCE 20
+
+/**
+ * Entry in list of ongoing interactions with an auditor.
+ */
+struct TEAH_AuditorInteractionEntry
+{
+ /**
+ * DLL entry.
+ */
+ struct TEAH_AuditorInteractionEntry *next;
+
+ /**
+ * DLL entry.
+ */
+ struct TEAH_AuditorInteractionEntry *prev;
+
+ /**
+ * URL of our auditor. For logging.
+ */
+ const char *auditor_url;
+
+ /**
+ * Interaction state.
+ */
+ struct TALER_AUDITOR_DepositConfirmationHandle *dch;
+
+ /**
+ * Batch deposit this is for.
+ */
+ struct TALER_EXCHANGE_BatchDepositHandle *dh;
+};
+
+
/**
* @brief A Deposit Handle
*/
@@ -51,9 +84,14 @@ struct TALER_EXCHANGE_BatchDepositHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange.
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * Context for our curl request(s).
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct GNUNET_CURL_Context *ctx;
/**
* The url for this request.
@@ -64,7 +102,7 @@ struct TALER_EXCHANGE_BatchDepositHandle
* Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/
- struct TALER_CURL_PostContext ctx;
+ struct TALER_CURL_PostContext post_ctx;
/**
* Handle for the request.
@@ -99,7 +137,7 @@ struct TALER_EXCHANGE_BatchDepositHandle
/**
* Hash over the extensions, or all zero.
*/
- struct TALER_ExtensionContractHashP h_extensions;
+ struct TALER_ExtensionPolicyHashP h_policy;
/**
* Time when this confirmation was generated / when the exchange received
@@ -108,9 +146,24 @@ struct TALER_EXCHANGE_BatchDepositHandle
struct GNUNET_TIME_Timestamp exchange_timestamp;
/**
- * Exchange signatures, set for #auditor_cb.
+ * Exchange signature, set for #auditor_cb.
*/
- struct TALER_ExchangeSignatureP *exchange_sigs;
+ struct TALER_ExchangeSignatureP exchange_sig;
+
+ /**
+ * Head of DLL of interactions with this auditor.
+ */
+ struct TEAH_AuditorInteractionEntry *ai_head;
+
+ /**
+ * Tail of DLL of interactions with this auditor.
+ */
+ struct TEAH_AuditorInteractionEntry *ai_tail;
+
+ /**
+ * Result to return to the application once @e ai_head is empty.
+ */
+ struct TALER_EXCHANGE_BatchDepositResult dr;
/**
* Exchange signing public key, set for #auditor_cb.
@@ -118,6 +171,16 @@ struct TALER_EXCHANGE_BatchDepositHandle
struct TALER_ExchangePublicKeyP exchange_pub;
/**
+ * Total amount deposited without fees as calculated by us.
+ */
+ struct TALER_Amount total_without_fee;
+
+ /**
+ * Response object to free at the end.
+ */
+ json_t *response;
+
+ /**
* Chance that we will inform the auditor about the deposit
* is 1:n, where the value of this field is "n".
*/
@@ -132,26 +195,79 @@ struct TALER_EXCHANGE_BatchDepositHandle
/**
+ * Finish batch deposit operation by calling the callback.
+ *
+ * @param[in] dh handle to finished batch deposit operation
+ */
+static void
+finish_dh (struct TALER_EXCHANGE_BatchDepositHandle *dh)
+{
+ dh->cb (dh->cb_cls,
+ &dh->dr);
+ TALER_EXCHANGE_batch_deposit_cancel (dh);
+}
+
+
+/**
+ * Function called with the result from our call to the
+ * auditor's /deposit-confirmation handler.
+ *
+ * @param cls closure of type `struct TEAH_AuditorInteractionEntry *`
+ * @param dcr response
+ */
+static void
+acc_confirmation_cb (
+ void *cls,
+ const struct TALER_AUDITOR_DepositConfirmationResponse *dcr)
+{
+ struct TEAH_AuditorInteractionEntry *aie = cls;
+ struct TALER_EXCHANGE_BatchDepositHandle *dh = aie->dh;
+
+ if (MHD_HTTP_OK != dcr->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n",
+ aie->auditor_url,
+ dcr->hr.http_status,
+ dcr->hr.ec);
+ }
+ GNUNET_CONTAINER_DLL_remove (dh->ai_head,
+ dh->ai_tail,
+ aie);
+ GNUNET_free (aie);
+ if (NULL == dh->ai_head)
+ finish_dh (dh);
+}
+
+
+/**
* Function called for each auditor to give us a chance to possibly
* launch a deposit confirmation interaction.
*
* @param cls closure
- * @param ah handle to the auditor
+ * @param auditor_url base URL of the auditor
* @param auditor_pub public key of the auditor
- * @return NULL if no deposit confirmation interaction was launched
*/
-static struct TEAH_AuditorInteractionEntry *
+static void
auditor_cb (void *cls,
- struct TALER_AUDITOR_Handle *ah,
+ const char *auditor_url,
const struct TALER_AuditorPublicKeyP *auditor_pub)
{
struct TALER_EXCHANGE_BatchDepositHandle *dh = cls;
- const struct TALER_EXCHANGE_Keys *key_state;
const struct TALER_EXCHANGE_SigningPublicKey *spk;
struct TEAH_AuditorInteractionEntry *aie;
- struct TALER_Amount amount_without_fee;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
- unsigned int coin;
+ const struct TALER_CoinSpendSignatureP *csigs[GNUNET_NZL (
+ dh->num_cdds)];
+ const struct TALER_CoinSpendPublicKeyP *cpubs[GNUNET_NZL (
+ dh->num_cdds)];
+
+ for (unsigned int i = 0; i<dh->num_cdds; i++)
+ {
+ const struct TALER_EXCHANGE_CoinDepositDetail *cdd = &dh->cdds[i];
+
+ csigs[i] = &cdd->coin_sig;
+ cpubs[i] = &cdd->coin_pub;
+ }
if (0 !=
GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
@@ -159,50 +275,47 @@ auditor_cb (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Not providing deposit confirmation to auditor\n");
- return NULL;
+ return;
}
- coin = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- dh->num_cdds);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Will provide deposit confirmation to auditor `%s'\n",
TALER_B2S (auditor_pub));
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdds[coin].h_denom_pub);
- GNUNET_assert (NULL != dki);
- spk = TALER_EXCHANGE_get_signing_key_info (key_state,
+ spk = TALER_EXCHANGE_get_signing_key_info (dh->keys,
&dh->exchange_pub);
if (NULL == spk)
{
GNUNET_break_op (0);
- return NULL;
+ return;
}
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &dh->cdds[coin].amount,
- &dki->fees.deposit));
aie = GNUNET_new (struct TEAH_AuditorInteractionEntry);
+ aie->dh = dh;
+ aie->auditor_url = auditor_url;
aie->dch = TALER_AUDITOR_deposit_confirmation (
- ah,
+ dh->ctx,
+ auditor_url,
&dh->h_wire,
- &dh->h_extensions,
+ &dh->h_policy,
&dh->dcd.h_contract_terms,
dh->exchange_timestamp,
dh->dcd.wire_deadline,
dh->dcd.refund_deadline,
- &amount_without_fee,
- &dh->cdds[coin].coin_pub,
+ &dh->total_without_fee,
+ dh->num_cdds,
+ cpubs,
+ csigs,
&dh->dcd.merchant_pub,
&dh->exchange_pub,
- &dh->exchange_sigs[coin],
- &key_state->master_pub,
+ &dh->exchange_sig,
+ &dh->keys->master_pub,
spk->valid_from,
spk->valid_until,
spk->valid_legal,
&spk->master_sig,
- &TEAH_acc_confirmation_cb,
+ &acc_confirmation_cb,
aie);
- return aie;
+ GNUNET_CONTAINER_DLL_insert (dh->ai_head,
+ dh->ai_tail,
+ aie);
}
@@ -221,33 +334,27 @@ handle_deposit_finished (void *cls,
{
struct TALER_EXCHANGE_BatchDepositHandle *dh = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_BatchDepositResult dr = {
- .hr.reply = j,
- .hr.http_status = (unsigned int) response_code
- };
- const struct TALER_EXCHANGE_Keys *keys;
+ struct TALER_EXCHANGE_BatchDepositResult *dr = &dh->dr;
dh->job = NULL;
- keys = TALER_EXCHANGE_get_keys (dh->exchange);
+ dh->response = json_incref ((json_t*) j);
+ dr->hr.reply = dh->response;
+ dr->hr.http_status = (unsigned int) response_code;
switch (response_code)
{
case 0:
- dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ dr->hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
{
- const struct TALER_EXCHANGE_Keys *key_state;
- json_t *sigs;
- json_t *sig;
- unsigned int idx;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("exchange_sigs",
- &sigs),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &dh->exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&dh->exchange_pub),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("transaction_base_url",
- &dr.details.success.transaction_base_url),
+ TALER_JSON_spec_web_url ("transaction_base_url",
+ &dr->details.ok.transaction_base_url),
NULL),
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
&dh->exchange_timestamp),
@@ -260,118 +367,80 @@ handle_deposit_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ dr->hr.http_status = 0;
+ dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- if (json_array_size (sigs) != dh->num_cdds)
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- dh->exchange_sigs = GNUNET_new_array (dh->num_cdds,
- struct TALER_ExchangeSignatureP);
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (dh->keys,
&dh->exchange_pub))
{
GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
+ dr->hr.http_status = 0;
+ dr->hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
break;
}
- json_array_foreach (sigs, idx, sig)
{
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &dh->exchange_sigs[idx]),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_Amount amount_without_fee;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (sig,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- GNUNET_JSON_parse_free (spec);
- break;
- }
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdds[idx].
- h_denom_pub);
- GNUNET_assert (NULL != dki);
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &dh->cdds[idx].amount,
- &dki->fees.deposit));
+ const struct TALER_CoinSpendSignatureP *csigs[
+ GNUNET_NZL (dh->num_cdds)];
+ for (unsigned int i = 0; i<dh->num_cdds; i++)
+ csigs[i] = &dh->cdds[i].coin_sig;
if (GNUNET_OK !=
TALER_exchange_online_deposit_confirmation_verify (
&dh->dcd.h_contract_terms,
&dh->h_wire,
- &dh->h_extensions,
+ &dh->h_policy,
dh->exchange_timestamp,
dh->dcd.wire_deadline,
dh->dcd.refund_deadline,
- &amount_without_fee,
- &dh->cdds[idx].coin_pub,
+ &dh->total_without_fee,
+ dh->num_cdds,
+ csigs,
&dh->dcd.merchant_pub,
&dh->exchange_pub,
- &dh->exchange_sigs[idx]))
+ &dh->exchange_sig))
{
GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
+ dr->hr.http_status = 0;
+ dr->hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
break;
}
}
- TEAH_get_auditors_for_dc (dh->exchange,
+ TEAH_get_auditors_for_dc (dh->keys,
&auditor_cb,
dh);
}
- dr.details.success.exchange_sigs = dh->exchange_sigs;
- dr.details.success.exchange_pub = &dh->exchange_pub;
- dr.details.success.deposit_timestamp = dh->exchange_timestamp;
- dr.details.success.num_signatures = dh->num_cdds;
+ dr->details.ok.exchange_sig = &dh->exchange_sig;
+ dr->details.ok.exchange_pub = &dh->exchange_pub;
+ dr->details.ok.deposit_timestamp = dh->exchange_timestamp;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
break;
case MHD_HTTP_NOT_FOUND:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
break;
case MHD_HTTP_CONFLICT:
{
- const struct TALER_EXCHANGE_Keys *key_state;
- struct TALER_CoinSpendPublicKeyP coin_pub;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("coin_pub",
- &coin_pub),
+ &dr->details.conflict.coin_pub),
GNUNET_JSON_spec_end ()
};
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
- bool found = false;
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -379,47 +448,12 @@ handle_deposit_finished (void *cls,
NULL, NULL))
{
GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ dr->hr.http_status = 0;
+ dr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- for (unsigned int i = 0; i<dh->num_cdds; i++)
- {
- if (0 !=
- GNUNET_memcmp (&coin_pub,
- &dh->cdds[i].coin_pub))
- continue;
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdds[i].
- h_denom_pub);
- GNUNET_assert (NULL != dki);
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_conflict_ (
- keys,
- j,
- dki,
- &dh->cdds[i].coin_pub,
- &dh->cdds[i].coin_sig,
- &dh->cdds[i].amount))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- found = true;
- break;
- }
- if (! found)
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
}
break;
case MHD_HTTP_GONE:
@@ -427,52 +461,55 @@ handle_deposit_finished (void *cls,
/* Note: one might want to check /keys for revocation
signature here, alas tricky in case our /keys
is outdated => left to clients */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
break;
default:
/* unexpected response code */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ dr->hr.ec = TALER_JSON_get_error_code (j);
+ dr->hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange deposit\n",
(unsigned int) response_code,
- dr.hr.ec);
+ dr->hr.ec);
GNUNET_break_op (0);
break;
}
- dh->cb (dh->cb_cls,
- &dr);
- TALER_EXCHANGE_batch_deposit_cancel (dh);
+ if (NULL != dh->ai_head)
+ return;
+ finish_dh (dh);
}
struct TALER_EXCHANGE_BatchDepositHandle *
TALER_EXCHANGE_batch_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_EXCHANGE_DepositContractDetail *dcd,
unsigned int num_cdds,
- const struct TALER_EXCHANGE_CoinDepositDetail *cdds,
+ const struct TALER_EXCHANGE_CoinDepositDetail cdds[static num_cdds],
TALER_EXCHANGE_BatchDepositResultCallback cb,
void *cb_cls,
enum TALER_ErrorCode *ec)
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct TALER_EXCHANGE_BatchDepositHandle *dh;
- struct GNUNET_CURL_Context *ctx;
json_t *deposit_obj;
json_t *deposits;
CURL *eh;
- struct TALER_Amount amount_without_fee;
+ const struct GNUNET_HashCode *wallet_data_hashp;
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
+ if (0 == num_cdds)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
if (GNUNET_TIME_timestamp_cmp (dcd->refund_deadline,
>,
dcd->wire_deadline))
@@ -481,36 +518,39 @@ TALER_EXCHANGE_batch_deposit (
*ec = TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE;
return NULL;
}
- key_state = TALER_EXCHANGE_get_keys (exchange);
dh = GNUNET_new (struct TALER_EXCHANGE_BatchDepositHandle);
dh->auditor_chance = AUDITOR_CHANCE;
- dh->exchange = exchange;
dh->cb = cb;
dh->cb_cls = cb_cls;
dh->cdds = GNUNET_memdup (cdds,
- num_cdds
- * sizeof (*cdds));
+ num_cdds * sizeof (*cdds));
dh->num_cdds = num_cdds;
dh->dcd = *dcd;
- if (NULL != dcd->extension_details)
- TALER_deposit_extension_hash (dcd->extension_details,
- &dh->h_extensions);
+ if (NULL != dcd->policy_details)
+ TALER_deposit_policy_hash (dcd->policy_details,
+ &dh->h_policy);
TALER_merchant_wire_signature_hash (dcd->merchant_payto_uri,
&dcd->wire_salt,
&dh->h_wire);
deposits = json_array ();
GNUNET_assert (NULL != deposits);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (cdds[0].amount.currency,
+ &dh->total_without_fee));
for (unsigned int i = 0; i<num_cdds; i++)
{
const struct TALER_EXCHANGE_CoinDepositDetail *cdd = &cdds[i];
const struct TALER_EXCHANGE_DenomPublicKey *dki;
+ const struct TALER_AgeCommitmentHash *h_age_commitmentp;
+ struct TALER_Amount amount_without_fee;
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
+ dki = TALER_EXCHANGE_get_denomination_key_by_hash (keys,
&cdd->h_denom_pub);
if (NULL == dki)
{
*ec = TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
GNUNET_break_op (0);
+ json_decref (deposits);
return NULL;
}
if (0 >
@@ -520,20 +560,18 @@ TALER_EXCHANGE_batch_deposit (
{
*ec = TALER_EC_EXCHANGE_DEPOSIT_FEE_ABOVE_AMOUNT;
GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Amount: %s\n",
- TALER_amount2s (&cdd->amount));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Fee: %s\n",
- TALER_amount2s (&dki->fees.deposit));
GNUNET_free (dh->cdds);
GNUNET_free (dh);
+ json_decref (deposits);
return NULL;
}
-
+ GNUNET_assert (0 <=
+ TALER_amount_add (&dh->total_without_fee,
+ &dh->total_without_fee,
+ &amount_without_fee));
if (GNUNET_OK !=
TALER_EXCHANGE_verify_deposit_signature_ (dcd,
- &dh->h_extensions,
+ &dh->h_policy,
&dh->h_wire,
cdd,
dki))
@@ -542,8 +580,13 @@ TALER_EXCHANGE_batch_deposit (
GNUNET_break_op (0);
GNUNET_free (dh->cdds);
GNUNET_free (dh);
+ json_decref (deposits);
return NULL;
}
+ if (GNUNET_is_zero (&cdd->h_age_commitment))
+ h_age_commitmentp = NULL;
+ else
+ h_age_commitmentp = &cdd->h_age_commitment;
GNUNET_assert (
0 ==
json_array_append_new (
@@ -559,13 +602,14 @@ TALER_EXCHANGE_batch_deposit (
&cdd->coin_pub),
GNUNET_JSON_pack_allow_null (
GNUNET_JSON_pack_data_auto ("h_age_commitment",
- &cdd->h_age_commitment)),
+ h_age_commitmentp)),
GNUNET_JSON_pack_data_auto ("coin_sig",
&cdd->coin_sig)
)));
}
- dh->url = TEAH_path_to_url (exchange,
- "/batch-deposit");
+ dh->url = TALER_url_join (url,
+ "batch-deposit",
+ NULL);
if (NULL == dh->url)
{
GNUNET_break (0);
@@ -573,9 +617,15 @@ TALER_EXCHANGE_batch_deposit (
GNUNET_free (dh->url);
GNUNET_free (dh->cdds);
GNUNET_free (dh);
+ json_decref (deposits);
return NULL;
}
+ if (GNUNET_is_zero (&dcd->wallet_data_hash))
+ wallet_data_hashp = NULL;
+ else
+ wallet_data_hashp = &dcd->wallet_data_hash;
+
deposit_obj = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("merchant_payto_uri",
dcd->merchant_payto_uri),
@@ -586,10 +636,13 @@ TALER_EXCHANGE_batch_deposit (
GNUNET_JSON_pack_array_steal ("coins",
deposits),
GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_object_steal ("extension_details",
- NULL)), /* FIXME-Oec */
+ GNUNET_JSON_pack_data_auto ("wallet_data_hash",
+ wallet_data_hashp)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("policy_details",
+ (json_t *) dcd->policy_details)),
GNUNET_JSON_pack_timestamp ("timestamp",
- dcd->timestamp),
+ dcd->wallet_timestamp),
GNUNET_JSON_pack_data_auto ("merchant_pub",
&dcd->merchant_pub),
GNUNET_JSON_pack_allow_null (
@@ -601,7 +654,7 @@ TALER_EXCHANGE_batch_deposit (
eh = TALER_EXCHANGE_curl_easy_get_ (dh->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
- TALER_curl_easy_post (&dh->ctx,
+ TALER_curl_easy_post (&dh->post_ctx,
eh,
deposit_obj)) )
{
@@ -619,10 +672,11 @@ TALER_EXCHANGE_batch_deposit (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for deposit: `%s'\n",
dh->url);
- ctx = TEAH_handle_to_context (exchange);
+ dh->ctx = ctx;
+ dh->keys = TALER_EXCHANGE_keys_incref (keys);
dh->job = GNUNET_CURL_job_add2 (ctx,
eh,
- dh->ctx.headers,
+ dh->post_ctx.headers,
&handle_deposit_finished,
dh);
return dh;
@@ -641,15 +695,30 @@ void
TALER_EXCHANGE_batch_deposit_cancel (
struct TALER_EXCHANGE_BatchDepositHandle *deposit)
{
+ struct TEAH_AuditorInteractionEntry *aie;
+
+ while (NULL != (aie = deposit->ai_head))
+ {
+ GNUNET_assert (aie->dh == deposit);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Not sending deposit confirmation to auditor `%s' due to cancellation\n",
+ aie->auditor_url);
+ TALER_AUDITOR_deposit_confirmation_cancel (aie->dch);
+ GNUNET_CONTAINER_DLL_remove (deposit->ai_head,
+ deposit->ai_tail,
+ aie);
+ GNUNET_free (aie);
+ }
if (NULL != deposit->job)
{
GNUNET_CURL_job_cancel (deposit->job);
deposit->job = NULL;
}
+ TALER_EXCHANGE_keys_decref (deposit->keys);
GNUNET_free (deposit->url);
GNUNET_free (deposit->cdds);
- GNUNET_free (deposit->exchange_sigs);
- TALER_curl_easy_post_finished (&deposit->ctx);
+ TALER_curl_easy_post_finished (&deposit->post_ctx);
+ json_decref (deposit->response);
GNUNET_free (deposit);
}
diff --git a/src/lib/exchange_api_batch_withdraw.c b/src/lib/exchange_api_batch_withdraw.c
index 4e0d6abcf..a1b21f347 100644
--- a/src/lib/exchange_api_batch_withdraw.c
+++ b/src/lib/exchange_api_batch_withdraw.c
@@ -54,9 +54,14 @@ struct CoinData
const struct TALER_AgeCommitmentHash *ach;
/**
- * blinding secret
+ * blinding secret
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+
+ /**
+ * Session nonce.
+ */
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
/**
* Private key of the coin we are withdrawing.
@@ -69,7 +74,7 @@ struct CoinData
struct TALER_PlanchetDetail pd;
/**
- * Values of the @cipher selected
+ * Values of the cipher selected
*/
struct TALER_ExchangeWithdrawValues alg_values;
@@ -79,7 +84,7 @@ struct CoinData
struct TALER_CoinPubHashP c_hash;
/**
- * Handler for the CS R request (only used for TALER_DENOMINATION_CS denominations)
+ * Handler for the CS R request (only used for GNUNET_CRYPTO_BSA_CS denominations)
*/
struct TALER_EXCHANGE_CsRWithdrawHandle *csrh;
@@ -97,9 +102,19 @@ struct TALER_EXCHANGE_BatchWithdrawHandle
{
/**
- * The connection to exchange this request handle will use
+ * The curl context to use
+ */
+ struct GNUNET_CURL_Context *curl_ctx;
+
+ /**
+ * The base URL to the exchange
+ */
+ const char *exchange_url;
+
+ /**
+ * The /keys information from the exchange
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ const struct TALER_EXCHANGE_Keys *keys;
/**
* Handle for the actual (internal) batch withdraw operation.
@@ -144,37 +159,34 @@ struct TALER_EXCHANGE_BatchWithdrawHandle
* HTTP /reserves/$RESERVE_PUB/batch-withdraw request.
*
* @param cls the `struct TALER_EXCHANGE_BatchWithdrawHandle`
- * @param hr HTTP response data
- * @param blind_sigs array of blind signatures over the coins, NULL on error
- * @param blind_sigs_length length of the @a blind_sigs array
+ * @param bw2r response data
*/
static void
handle_reserve_batch_withdraw_finished (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_BlindedDenominationSignature *blind_sigs,
- unsigned int blind_sigs_length)
+ const struct TALER_EXCHANGE_BatchWithdraw2Response *bw2r)
{
struct TALER_EXCHANGE_BatchWithdrawHandle *wh = cls;
struct TALER_EXCHANGE_BatchWithdrawResponse wr = {
- .hr = *hr
+ .hr = bw2r->hr
};
- struct TALER_EXCHANGE_PrivateCoinDetails coins[wh->num_coins];
+ struct TALER_EXCHANGE_PrivateCoinDetails coins[GNUNET_NZL (wh->num_coins)];
wh->wh2 = NULL;
memset (coins,
0,
sizeof (coins));
- if (blind_sigs_length != wh->num_coins)
- {
- GNUNET_break_op (0);
- wr.hr.http_status = 0;
- wr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- switch (hr->http_status)
+ switch (bw2r->hr.http_status)
{
case MHD_HTTP_OK:
{
+ if (bw2r->details.ok.blind_sigs_length != wh->num_coins)
+ {
+ GNUNET_break_op (0);
+ wr.hr.http_status = 0;
+ wr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
for (unsigned int i = 0; i<wh->num_coins; i++)
{
struct CoinData *cd = &wh->coins[i];
@@ -183,7 +195,7 @@ handle_reserve_batch_withdraw_finished (
if (GNUNET_OK !=
TALER_planchet_to_coin (&cd->pk.key,
- &blind_sigs[i],
+ &bw2r->details.ok.blind_sigs[i],
&cd->bks,
&cd->priv,
cd->ach,
@@ -200,20 +212,24 @@ handle_reserve_batch_withdraw_finished (
coin->sig = fc.sig;
coin->exchange_vals = cd->alg_values;
}
- wr.details.success.coins = coins;
- wr.details.success.num_coins = wh->num_coins;
+ wr.details.ok.coins = coins;
+ wr.details.ok.num_coins = wh->num_coins;
break;
}
case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &wr.details.accepted.payment_target_uuid),
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &wr.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &wr.details.unavailable_for_legal_reasons.requirement_row),
GNUNET_JSON_spec_end ()
};
if (GNUNET_OK !=
- GNUNET_JSON_parse (hr->reply,
+ GNUNET_JSON_parse (bw2r->hr.reply,
spec,
NULL, NULL))
{
@@ -254,10 +270,12 @@ phase_two (struct TALER_EXCHANGE_BatchWithdrawHandle *wh)
pds[i] = cd->pd;
}
wh->wh2 = TALER_EXCHANGE_batch_withdraw2 (
- wh->exchange,
+ wh->curl_ctx,
+ wh->exchange_url,
+ wh->keys,
wh->reserve_priv,
- pds,
wh->num_coins,
+ pds,
&handle_reserve_batch_withdraw_finished,
wh);
}
@@ -281,30 +299,38 @@ withdraw_cs_stage_two_callback (
};
cd->csrh = NULL;
- GNUNET_assert (TALER_DENOMINATION_CS == cd->pk.key.cipher);
+ GNUNET_assert (GNUNET_CRYPTO_BSA_CS ==
+ cd->pk.key.bsign_pub_key->cipher);
switch (csrr->hr.http_status)
{
case MHD_HTTP_OK:
- cd->alg_values = csrr->details.success.alg_values;
+ GNUNET_assert (NULL ==
+ cd->alg_values.blinding_inputs);
+ TALER_denom_ewv_copy (&cd->alg_values,
+ &csrr->details.ok.alg_values);
TALER_planchet_setup_coin_priv (&cd->ps,
&cd->alg_values,
&cd->priv);
TALER_planchet_blinding_secret_create (&cd->ps,
&cd->alg_values,
&cd->bks);
- /* This initializes the 2nd half of the
- wh->pd.blinded_planchet! */
if (GNUNET_OK !=
TALER_planchet_prepare (&cd->pk.key,
&cd->alg_values,
&cd->bks,
+ &cd->nonce,
&cd->priv,
cd->ach,
&cd->c_hash,
&cd->pd))
{
GNUNET_break (0);
+ wr.hr.http_status = 0;
+ wr.hr.ec = TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR;
+ wh->cb (wh->cb_cls,
+ &wr);
TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return;
}
wh->cs_pending--;
if (0 == wh->cs_pending)
@@ -321,17 +347,21 @@ withdraw_cs_stage_two_callback (
struct TALER_EXCHANGE_BatchWithdrawHandle *
TALER_EXCHANGE_batch_withdraw (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_EXCHANGE_WithdrawCoinInput *wcis,
unsigned int wci_length,
+ const struct TALER_EXCHANGE_WithdrawCoinInput wcis[static wci_length],
TALER_EXCHANGE_BatchWithdrawCallback res_cb,
void *res_cb_cls)
{
struct TALER_EXCHANGE_BatchWithdrawHandle *wh;
wh = GNUNET_new (struct TALER_EXCHANGE_BatchWithdrawHandle);
- wh->exchange = exchange;
+ wh->curl_ctx = curl_ctx;
+ wh->exchange_url = exchange_url;
+ wh->keys = keys;
wh->cb = res_cb;
wh->cb_cls = res_cb_cls;
wh->reserve_priv = reserve_priv;
@@ -347,58 +377,53 @@ TALER_EXCHANGE_batch_withdraw (
cd->ps = *wci->ps;
cd->ach = wci->ach;
cd->pk = *wci->pk;
- TALER_denom_pub_deep_copy (&cd->pk.key,
- &wci->pk->key);
- switch (wci->pk->key.cipher)
+ TALER_denom_pub_copy (&cd->pk.key,
+ &wci->pk->key);
+ switch (wci->pk->key.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
+ TALER_denom_ewv_copy (&cd->alg_values,
+ TALER_denom_ewv_rsa_singleton ());
+ TALER_planchet_setup_coin_priv (&cd->ps,
+ &cd->alg_values,
+ &cd->priv);
+ TALER_planchet_blinding_secret_create (&cd->ps,
+ &cd->alg_values,
+ &cd->bks);
+ if (GNUNET_OK !=
+ TALER_planchet_prepare (&cd->pk.key,
+ &cd->alg_values,
+ &cd->bks,
+ NULL,
+ &cd->priv,
+ cd->ach,
+ &cd->c_hash,
+ &cd->pd))
{
- cd->alg_values.cipher = TALER_DENOMINATION_RSA;
- TALER_planchet_setup_coin_priv (&cd->ps,
- &cd->alg_values,
- &cd->priv);
- TALER_planchet_blinding_secret_create (&cd->ps,
- &cd->alg_values,
- &cd->bks);
- if (GNUNET_OK !=
- TALER_planchet_prepare (&cd->pk.key,
- &cd->alg_values,
- &cd->bks,
- &cd->priv,
- cd->ach,
- &cd->c_hash,
- &cd->pd))
- {
- GNUNET_break (0);
- TALER_EXCHANGE_batch_withdraw_cancel (wh);
- return NULL;
- }
- break;
+ GNUNET_break (0);
+ TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return NULL;
}
- case TALER_DENOMINATION_CS:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ TALER_cs_withdraw_nonce_derive (
+ &cd->ps,
+ &cd->nonce.cs_nonce);
+ cd->csrh = TALER_EXCHANGE_csr_withdraw (
+ curl_ctx,
+ exchange_url,
+ &cd->pk,
+ &cd->nonce.cs_nonce,
+ &withdraw_cs_stage_two_callback,
+ cd);
+ if (NULL == cd->csrh)
{
- TALER_cs_withdraw_nonce_derive (
- &cd->ps,
- &cd->pd.blinded_planchet.details.cs_blinded_planchet.nonce);
- /* Note that we only initialize the first half
- of the blinded_planchet here; the other part
- will be done after the /csr-withdraw request! */
- cd->pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
- cd->csrh = TALER_EXCHANGE_csr_withdraw (
- exchange,
- &cd->pk,
- &cd->pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &withdraw_cs_stage_two_callback,
- cd);
- if (NULL == cd->csrh)
- {
- GNUNET_break (0);
- TALER_EXCHANGE_batch_withdraw_cancel (wh);
- return NULL;
- }
- wh->cs_pending++;
- break;
+ GNUNET_break (0);
+ TALER_EXCHANGE_batch_withdraw_cancel (wh);
+ return NULL;
}
+ wh->cs_pending++;
+ break;
default:
GNUNET_break (0);
TALER_EXCHANGE_batch_withdraw_cancel (wh);
@@ -424,6 +449,7 @@ TALER_EXCHANGE_batch_withdraw_cancel (
TALER_EXCHANGE_csr_withdraw_cancel (cd->csrh);
cd->csrh = NULL;
}
+ TALER_denom_ewv_free (&cd->alg_values);
TALER_blinded_planchet_free (&cd->pd.blinded_planchet);
TALER_denom_pub_free (&cd->pk.key);
}
diff --git a/src/lib/exchange_api_batch_withdraw2.c b/src/lib/exchange_api_batch_withdraw2.c
index e9da21992..ff1496466 100644
--- a/src/lib/exchange_api_batch_withdraw2.c
+++ b/src/lib/exchange_api_batch_withdraw2.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -39,14 +39,14 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle
{
/**
- * The connection to exchange this request handle will use
+ * The url for this request.
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ char *url;
/**
- * The url for this request.
+ * The /keys material from the exchange
*/
- char *url;
+ const struct TALER_EXCHANGE_Keys *keys;
/**
* Handle for the request.
@@ -89,8 +89,8 @@ struct TALER_EXCHANGE_BatchWithdraw2Handle
/**
* We got a 200 OK response for the /reserves/$RESERVE_PUB/batch-withdraw operation.
* Extract the coin's signature and return it to the caller. The signature we
- * get from the exchange is for the blinded value. Thus, we first must
- * unblind it and then should verify its validity against our coin's hash.
+ * get from the exchange is for the blinded value. As we do not have the
+ * blinding factor, the signature CANNOT be verified.
*
* If everything checks out, we return the unblinded signature
* to the application via the callback.
@@ -103,14 +103,15 @@ static enum GNUNET_GenericReturnValue
reserve_batch_withdraw_ok (struct TALER_EXCHANGE_BatchWithdraw2Handle *wh,
const json_t *json)
{
- struct TALER_BlindedDenominationSignature blind_sigs[wh->num_coins];
+ struct TALER_BlindedDenominationSignature blind_sigs[GNUNET_NZL (
+ wh->num_coins)];
const json_t *ja = json_object_get (json,
"ev_sigs");
const json_t *j;
- unsigned int index;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = json,
- .http_status = MHD_HTTP_OK
+ size_t index;
+ struct TALER_EXCHANGE_BatchWithdraw2Response bwr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
};
if ( (NULL == ja) ||
@@ -134,17 +135,17 @@ reserve_batch_withdraw_ok (struct TALER_EXCHANGE_BatchWithdraw2Handle *wh,
NULL, NULL))
{
GNUNET_break_op (0);
- for (unsigned int i = 0; i<index; i++)
+ for (size_t i = 0; i<index; i++)
TALER_blinded_denom_sig_free (&blind_sigs[i]);
return GNUNET_SYSERR;
}
}
/* signature is valid, return it to the application */
+ bwr.details.ok.blind_sigs = blind_sigs;
+ bwr.details.ok.blind_sigs_length = wh->num_coins;
wh->cb (wh->cb_cls,
- &hr,
- blind_sigs,
- wh->num_coins);
+ &bwr);
/* make sure callback isn't called again after return */
wh->cb = NULL;
for (unsigned int i = 0; i<wh->num_coins; i++)
@@ -155,101 +156,6 @@ reserve_batch_withdraw_ok (struct TALER_EXCHANGE_BatchWithdraw2Handle *wh,
/**
- * We got a 409 CONFLICT response for the /reserves/$RESERVE_PUB/batch-withdraw operation.
- * Check the signatures on the batch withdraw transactions in the provided
- * history and that the balances add up. We don't do anything directly
- * with the information, as the JSON will be returned to the application.
- * However, our job is ensuring that the exchange followed the protocol, and
- * this in particular means checking all of the signatures in the history.
- *
- * @param wh operation handle
- * @param json reply from the exchange
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
- */
-static enum GNUNET_GenericReturnValue
-reserve_batch_withdraw_payment_required (
- struct TALER_EXCHANGE_BatchWithdraw2Handle *wh,
- const json_t *json)
-{
- struct TALER_Amount balance;
- struct TALER_Amount total_in_from_history;
- struct TALER_Amount total_out_from_history;
- json_t *history;
- size_t len;
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("balance",
- &balance),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- history = json_object_get (json,
- "history");
- if (NULL == history)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- /* go over transaction history and compute
- total incoming and outgoing amounts */
- len = json_array_size (history);
- {
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory;
-
- /* Use heap allocation as "len" may be very big and thus this may
- not fit on the stack. Use "GNUNET_malloc_large" as a malicious
- exchange may theoretically try to crash us by giving a history
- that does not fit into our memory. */
- rhistory = GNUNET_malloc_large (
- sizeof (struct TALER_EXCHANGE_ReserveHistoryEntry)
- * len);
- if (NULL == rhistory)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_parse_reserve_history (wh->exchange,
- history,
- &wh->reserve_pub,
- balance.currency,
- &total_in_from_history,
- &total_out_from_history,
- len,
- rhistory))
- {
- GNUNET_break_op (0);
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
- return GNUNET_SYSERR;
- }
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
- }
-
- /* Check that funds were really insufficient */
- if (0 >= TALER_amount_cmp (&wh->requested_amount,
- &balance))
- {
- /* Requested amount is smaller or equal to reported balance,
- so this should not have failed. */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
* Function called when we're done processing the
* HTTP /reserves/$RESERVE_PUB/batch-withdraw request.
*
@@ -264,16 +170,16 @@ handle_reserve_batch_withdraw_finished (void *cls,
{
struct TALER_EXCHANGE_BatchWithdraw2Handle *wh = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_BatchWithdraw2Response bwr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
};
wh->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ bwr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -281,105 +187,91 @@ handle_reserve_batch_withdraw_finished (void *cls,
j))
{
GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ bwr.hr.http_status = 0;
+ bwr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
GNUNET_assert (NULL == wh->cb);
TALER_EXCHANGE_batch_withdraw2_cancel (wh);
return;
- case MHD_HTTP_ACCEPTED:
- /* only validate reply is well-formed */
- {
- uint64_t ptu;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &ptu),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (j,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- }
- break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
GNUNET_break_op (0);
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, the exchange basically just says
that it doesn't know this reserve. Can happen if we
query before the wire transfer went through.
We should simply pass the JSON reply to the application. */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
- /* The exchange says that the reserve has insufficient funds;
- check the signatures in the history... */
- if (GNUNET_OK !=
- reserve_batch_withdraw_payment_required (wh,
- j))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- else
- {
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- }
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_GONE:
/* could happen if denomination was revoked */
/* Note: one might want to check /keys for revocation
signature here, alas tricky in case our /keys
is outdated => left to clients */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &bwr.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 ("requirement_row",
+ &bwr.details.unavailable_for_legal_reasons.
+ kyc_requirement_id),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ bwr.hr.http_status = 0;
+ bwr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ }
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ bwr.hr.ec = TALER_JSON_get_error_code (j);
+ bwr.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange batch withdraw\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) bwr.hr.ec);
break;
}
if (NULL != wh->cb)
{
wh->cb (wh->cb_cls,
- &hr,
- NULL,
- 0);
+ &bwr);
wh->cb = NULL;
}
TALER_EXCHANGE_batch_withdraw2_cancel (wh);
@@ -388,29 +280,25 @@ handle_reserve_batch_withdraw_finished (void *cls,
struct TALER_EXCHANGE_BatchWithdraw2Handle *
TALER_EXCHANGE_batch_withdraw2 (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_PlanchetDetail *pds,
unsigned int pds_length,
+ const struct TALER_PlanchetDetail pds[static pds_length],
TALER_EXCHANGE_BatchWithdraw2Callback res_cb,
void *res_cb_cls)
{
struct TALER_EXCHANGE_BatchWithdraw2Handle *wh;
- const struct TALER_EXCHANGE_Keys *keys;
const struct TALER_EXCHANGE_DenomPublicKey *dk;
struct TALER_ReserveSignatureP reserve_sig;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
struct TALER_BlindedCoinHashP bch;
json_t *jc;
- keys = TALER_EXCHANGE_get_keys (exchange);
- if (NULL == keys)
- {
- GNUNET_break (0);
- return NULL;
- }
+ GNUNET_assert (NULL != keys);
wh = GNUNET_new (struct TALER_EXCHANGE_BatchWithdraw2Handle);
- wh->exchange = exchange;
+ wh->keys = keys;
wh->cb = res_cb;
wh->cb_cls = res_cb_cls;
wh->num_coins = pds_length;
@@ -431,14 +319,15 @@ TALER_EXCHANGE_batch_withdraw2 (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s/batch-withdraw",
+ "reserves/%s/batch-withdraw",
pub_str);
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Attempting to batch-withdraw from reserve %s\n",
TALER_B2S (&wh->reserve_pub));
- wh->url = TEAH_path_to_url (exchange,
- arg_str);
+ wh->url = TALER_url_join (exchange_url,
+ arg_str,
+ NULL);
if (NULL == wh->url)
{
GNUNET_break (0);
@@ -485,16 +374,9 @@ TALER_EXCHANGE_batch_withdraw2 (
json_decref (jc);
return NULL;
}
- if (GNUNET_OK !=
- TALER_coin_ev_hash (&pd->blinded_planchet,
- &pd->denom_pub_hash,
- &bch))
- {
- GNUNET_break (0);
- TALER_EXCHANGE_batch_withdraw2_cancel (wh);
- json_decref (jc);
- return NULL;
- }
+ TALER_coin_ev_hash (&pd->blinded_planchet,
+ &pd->denom_pub_hash,
+ &bch);
TALER_wallet_withdraw_sign (&pd->denom_pub_hash,
&coin_total,
&bch,
@@ -514,13 +396,11 @@ TALER_EXCHANGE_batch_withdraw2 (
}
{
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
json_t *req;
req = GNUNET_JSON_PACK (
GNUNET_JSON_pack_array_steal ("planchets",
jc));
- ctx = TEAH_handle_to_context (exchange);
eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
@@ -536,7 +416,7 @@ TALER_EXCHANGE_batch_withdraw2 (
return NULL;
}
json_decref (req);
- wh->job = GNUNET_CURL_job_add2 (ctx,
+ wh->job = GNUNET_CURL_job_add2 (curl_ctx,
eh,
wh->post_ctx.headers,
&handle_reserve_batch_withdraw_finished,
diff --git a/src/lib/exchange_api_coins_history.c b/src/lib/exchange_api_coins_history.c
new file mode 100644
index 000000000..0999e185e
--- /dev/null
+++ b/src/lib/exchange_api_coins_history.c
@@ -0,0 +1,1230 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_coins_history.c
+ * @brief Implementation of the POST /coins/$COIN_PUB/history requests
+ * @author Christian Grothoff
+ *
+ * NOTE: this is an incomplete draft, never finished!
+ */
+#include "platform.h"
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP history codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A /coins/$RID/history Handle
+ */
+struct TALER_EXCHANGE_CoinsHistoryHandle
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Context for #TEH_curl_easy_post(). Keeps the data that must
+ * persist for Curl to make the upload.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_CoinsHistoryCallback cb;
+
+ /**
+ * Public key of the coin we are querying.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+};
+
+
+/**
+ * Context for coin helpers.
+ */
+struct CoinHistoryParseContext
+{
+
+ /**
+ * Keys of the exchange.
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * Denomination of the coin.
+ */
+ const struct TALER_EXCHANGE_DenomPublicKey *dk;
+
+ /**
+ * Our coin public key.
+ */
+ const struct TALER_CoinSpendPublicKeyP *coin_pub;
+
+ /**
+ * Where to sum up total refunds.
+ */
+ struct TALER_Amount *total_in;
+
+ /**
+ * Total amount encountered.
+ */
+ struct TALER_Amount *total_out;
+
+};
+
+
+/**
+ * Signature of functions that operate on one of
+ * the coin's history entries.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh where to write the history entry
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+typedef enum GNUNET_GenericReturnValue
+(*CoinCheckHelper)(struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction);
+
+
+/**
+ * Handle deposit entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_deposit (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.deposit.sig),
+ GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
+ &rh->details.deposit.h_contract_terms),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("wallet_data_hash",
+ &rh->details.deposit.wallet_data_hash),
+ &rh->details.deposit.no_wallet_data_hash),
+ GNUNET_JSON_spec_fixed_auto ("h_wire",
+ &rh->details.deposit.h_wire),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
+ &rh->details.deposit.hac),
+ &rh->details.deposit.no_hac),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("h_policy",
+ &rh->details.deposit.h_policy),
+ &rh->details.deposit.no_h_policy),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.deposit.wallet_timestamp),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("refund_deadline",
+ &rh->details.deposit.refund_deadline),
+ NULL),
+ TALER_JSON_spec_amount_any ("deposit_fee",
+ &rh->details.deposit.deposit_fee),
+ GNUNET_JSON_spec_fixed_auto ("merchant_pub",
+ &rh->details.deposit.merchant_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->details.deposit.refund_deadline = GNUNET_TIME_UNIT_ZERO_TS;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_deposit_verify (
+ amount,
+ &rh->details.deposit.deposit_fee,
+ &rh->details.deposit.h_wire,
+ &rh->details.deposit.h_contract_terms,
+ rh->details.deposit.no_wallet_data_hash
+ ? NULL
+ : &rh->details.deposit.wallet_data_hash,
+ rh->details.deposit.no_hac
+ ? NULL
+ : &rh->details.deposit.hac,
+ rh->details.deposit.no_h_policy
+ ? NULL
+ : &rh->details.deposit.h_policy,
+ &pc->dk->h_key,
+ rh->details.deposit.wallet_timestamp,
+ &rh->details.deposit.merchant_pub,
+ rh->details.deposit.refund_deadline,
+ pc->coin_pub,
+ &rh->details.deposit.sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ /* check that deposit fee matches our expectations from /keys! */
+ if ( (GNUNET_YES !=
+ TALER_amount_cmp_currency (&rh->details.deposit.deposit_fee,
+ &pc->dk->fees.deposit)) ||
+ (0 !=
+ TALER_amount_cmp (&rh->details.deposit.deposit_fee,
+ &pc->dk->fees.deposit)) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handle melt entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_melt (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.melt.sig),
+ GNUNET_JSON_spec_fixed_auto ("rc",
+ &rh->details.melt.rc),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
+ &rh->details.melt.h_age_commitment),
+ &rh->details.melt.no_hac),
+ TALER_JSON_spec_amount_any ("melt_fee",
+ &rh->details.melt.melt_fee),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ /* check that melt fee matches our expectations from /keys! */
+ if ( (GNUNET_YES !=
+ TALER_amount_cmp_currency (&rh->details.melt.melt_fee,
+ &pc->dk->fees.refresh)) ||
+ (0 !=
+ TALER_amount_cmp (&rh->details.melt.melt_fee,
+ &pc->dk->fees.refresh)) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_melt_verify (
+ amount,
+ &rh->details.melt.melt_fee,
+ &rh->details.melt.rc,
+ &pc->dk->h_key,
+ rh->details.melt.no_hac
+ ? NULL
+ : &rh->details.melt.h_age_commitment,
+ pc->coin_pub,
+ &rh->details.melt.sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handle refund entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_refund (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("refund_fee",
+ &rh->details.refund.refund_fee),
+ GNUNET_JSON_spec_fixed_auto ("merchant_sig",
+ &rh->details.refund.sig),
+ GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
+ &rh->details.refund.h_contract_terms),
+ GNUNET_JSON_spec_fixed_auto ("merchant_pub",
+ &rh->details.refund.merchant_pub),
+ GNUNET_JSON_spec_uint64 ("rtransaction_id",
+ &rh->details.refund.rtransaction_id),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 >
+ TALER_amount_add (&rh->details.refund.sig_amount,
+ &rh->details.refund.refund_fee,
+ amount))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_merchant_refund_verify (pc->coin_pub,
+ &rh->details.refund.h_contract_terms,
+ rh->details.refund.rtransaction_id,
+ &rh->details.refund.sig_amount,
+ &rh->details.refund.merchant_pub,
+ &rh->details.refund.sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ /* NOTE: theoretically, we could also check that the given
+ merchant_pub and h_contract_terms appear in the
+ history under deposits. However, there is really no benefit
+ for the exchange to lie here, so not checking is probably OK
+ (an auditor ought to check, though). Then again, we similarly
+ had no reason to check the merchant's signature (other than a
+ well-formendess check). */
+
+ /* check that refund fee matches our expectations from /keys! */
+ if ( (GNUNET_YES !=
+ TALER_amount_cmp_currency (&rh->details.refund.refund_fee,
+ &pc->dk->fees.refund)) ||
+ (0 !=
+ TALER_amount_cmp (&rh->details.refund.refund_fee,
+ &pc->dk->fees.refund)) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Handle recoup entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_recoup (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.recoup.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.recoup.exchange_pub),
+ GNUNET_JSON_spec_fixed_auto ("reserve_pub",
+ &rh->details.recoup.reserve_pub),
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.recoup.coin_sig),
+ GNUNET_JSON_spec_fixed_auto ("coin_blind",
+ &rh->details.recoup.coin_bks),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.recoup.timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_confirm_recoup_verify (
+ rh->details.recoup.timestamp,
+ amount,
+ pc->coin_pub,
+ &rh->details.recoup.reserve_pub,
+ &rh->details.recoup.exchange_pub,
+ &rh->details.recoup.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_recoup_verify (&pc->dk->h_key,
+ &rh->details.recoup.coin_bks,
+ pc->coin_pub,
+ &rh->details.recoup.coin_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handle recoup-refresh entry in the coin's history.
+ * This is the coin that was subjected to a recoup,
+ * the value being credited to the old coin.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_recoup_refresh (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.recoup_refresh.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.recoup_refresh.exchange_pub),
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.recoup_refresh.coin_sig),
+ GNUNET_JSON_spec_fixed_auto ("old_coin_pub",
+ &rh->details.recoup_refresh.old_coin_pub),
+ GNUNET_JSON_spec_fixed_auto ("coin_blind",
+ &rh->details.recoup_refresh.coin_bks),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.recoup_refresh.timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_confirm_recoup_refresh_verify (
+ rh->details.recoup_refresh.timestamp,
+ amount,
+ pc->coin_pub,
+ &rh->details.recoup_refresh.old_coin_pub,
+ &rh->details.recoup_refresh.exchange_pub,
+ &rh->details.recoup_refresh.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_recoup_verify (&pc->dk->h_key,
+ &rh->details.recoup_refresh.coin_bks,
+ pc->coin_pub,
+ &rh->details.recoup_refresh.coin_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handle old coin recoup entry in the coin's history.
+ * This is the coin that was credited in a recoup,
+ * the value being credited to the this coin.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_old_coin_recoup (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.old_coin_recoup.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.old_coin_recoup.exchange_pub),
+ GNUNET_JSON_spec_fixed_auto ("coin_pub",
+ &rh->details.old_coin_recoup.new_coin_pub),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.old_coin_recoup.timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_confirm_recoup_refresh_verify (
+ rh->details.old_coin_recoup.timestamp,
+ amount,
+ &rh->details.old_coin_recoup.new_coin_pub,
+ pc->coin_pub,
+ &rh->details.old_coin_recoup.exchange_pub,
+ &rh->details.old_coin_recoup.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Handle purse deposit entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_purse_deposit (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("purse_pub",
+ &rh->details.purse_deposit.purse_pub),
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.purse_deposit.coin_sig),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
+ &rh->details.purse_deposit.phac),
+ NULL),
+ TALER_JSON_spec_web_url ("exchange_base_url",
+ &rh->details.purse_deposit.exchange_base_url),
+ GNUNET_JSON_spec_bool ("refunded",
+ &rh->details.purse_deposit.refunded),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_purse_deposit_verify (
+ rh->details.purse_deposit.exchange_base_url,
+ &rh->details.purse_deposit.purse_pub,
+ amount,
+ &pc->dk->h_key,
+ &rh->details.purse_deposit.phac,
+ pc->coin_pub,
+ &rh->details.purse_deposit.coin_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (rh->details.purse_deposit.refunded)
+ {
+ /* We wave the deposit fee. */
+ if (0 >
+ TALER_amount_add (pc->total_in,
+ pc->total_in,
+ &pc->dk->fees.deposit))
+ {
+ /* overflow in refund history? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Handle purse refund entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_purse_refund (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("refund_fee",
+ &rh->details.purse_refund.refund_fee),
+ GNUNET_JSON_spec_fixed_auto ("purse_pub",
+ &rh->details.purse_refund.purse_pub),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.purse_refund.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.purse_refund.exchange_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_purse_refund_verify (
+ amount,
+ &rh->details.purse_refund.refund_fee,
+ pc->coin_pub,
+ &rh->details.purse_refund.purse_pub,
+ &rh->details.purse_refund.exchange_pub,
+ &rh->details.purse_refund.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ( (GNUNET_YES !=
+ TALER_amount_cmp_currency (&rh->details.purse_refund.refund_fee,
+ &pc->dk->fees.refund)) ||
+ (0 !=
+ TALER_amount_cmp (&rh->details.purse_refund.refund_fee,
+ &pc->dk->fees.refund)) )
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
+ * Handle reserve deposit entry in the coin's history.
+ *
+ * @param[in,out] pc overall context
+ * @param[out] rh history entry to initialize
+ * @param amount main amount of this operation
+ * @param transaction JSON details for the operation
+ * @return #GNUNET_SYSERR on error,
+ * #GNUNET_OK to add, #GNUNET_NO to subtract
+ */
+static enum GNUNET_GenericReturnValue
+help_reserve_open_deposit (struct CoinHistoryParseContext *pc,
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh,
+ const struct TALER_Amount *amount,
+ json_t *transaction)
+{
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rh->details.reserve_open_deposit.reserve_sig),
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &rh->details.reserve_open_deposit.coin_sig),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_open_deposit_verify (
+ amount,
+ &rh->details.reserve_open_deposit.reserve_sig,
+ pc->coin_pub,
+ &rh->details.reserve_open_deposit.coin_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_YES;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_parse_coin_history (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_EXCHANGE_DenomPublicKey *dk,
+ const json_t *history,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct TALER_Amount *total_in,
+ struct TALER_Amount *total_out,
+ unsigned int rlen,
+ struct TALER_EXCHANGE_CoinHistoryEntry rhistory[static rlen])
+{
+ const struct
+ {
+ const char *type;
+ CoinCheckHelper helper;
+ enum TALER_EXCHANGE_CoinTransactionType ctt;
+ } map[] = {
+ { "DEPOSIT",
+ &help_deposit,
+ TALER_EXCHANGE_CTT_DEPOSIT },
+ { "MELT",
+ &help_melt,
+ TALER_EXCHANGE_CTT_MELT },
+ { "REFUND",
+ &help_refund,
+ TALER_EXCHANGE_CTT_REFUND },
+ { "RECOUP",
+ &help_recoup,
+ TALER_EXCHANGE_CTT_RECOUP },
+ { "RECOUP-REFRESH",
+ &help_recoup_refresh,
+ TALER_EXCHANGE_CTT_RECOUP_REFRESH },
+ { "OLD-COIN-RECOUP",
+ &help_old_coin_recoup,
+ TALER_EXCHANGE_CTT_OLD_COIN_RECOUP },
+ { "PURSE-DEPOSIT",
+ &help_purse_deposit,
+ TALER_EXCHANGE_CTT_PURSE_DEPOSIT },
+ { "PURSE-REFUND",
+ &help_purse_refund,
+ TALER_EXCHANGE_CTT_PURSE_REFUND },
+ { "RESERVE-OPEN-DEPOSIT",
+ &help_reserve_open_deposit,
+ TALER_EXCHANGE_CTT_RESERVE_OPEN_DEPOSIT },
+ { NULL, NULL, TALER_EXCHANGE_CTT_NONE }
+ };
+ struct CoinHistoryParseContext pc = {
+ .dk = dk,
+ .coin_pub = coin_pub,
+ .total_out = total_out,
+ .total_in = total_in
+ };
+ size_t len;
+
+ if (NULL == history)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ len = json_array_size (history);
+ if (0 == len)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ *total_in = dk->value;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (total_in->currency,
+ total_out));
+ for (size_t off = 0; off<len; off++)
+ {
+ struct TALER_EXCHANGE_CoinHistoryEntry *rh = &rhistory[off];
+ json_t *transaction = json_array_get (history,
+ off);
+ enum GNUNET_GenericReturnValue add;
+ const char *type;
+ struct GNUNET_JSON_Specification spec_glob[] = {
+ TALER_JSON_spec_amount_any ("amount",
+ &rh->amount),
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ spec_glob,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_YES !=
+ TALER_amount_cmp_currency (&rh->amount,
+ total_in))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Operation of type %s with amount %s\n",
+ type,
+ TALER_amount2s (&rh->amount));
+ add = GNUNET_SYSERR;
+ for (unsigned int i = 0; NULL != map[i].type; i++)
+ {
+ if (0 == strcasecmp (type,
+ map[i].type))
+ {
+ rh->type = map[i].ctt;
+ add = map[i].helper (&pc,
+ rh,
+ &rh->amount,
+ transaction);
+ break;
+ }
+ }
+ switch (add)
+ {
+ case GNUNET_SYSERR:
+ /* entry type not supported, new version on server? */
+ rh->type = TALER_EXCHANGE_CTT_NONE;
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected type `%s' in response\n",
+ type);
+ return GNUNET_SYSERR;
+ case GNUNET_YES:
+ /* This amount should be debited from the coin */
+ if (0 >
+ TALER_amount_add (total_out,
+ total_out,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ break;
+ case GNUNET_NO:
+ /* This amount should be credited to the coin. */
+ if (0 >
+ TALER_amount_add (total_in,
+ total_in,
+ &rh->amount))
+ {
+ /* overflow in refund history? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ break;
+ } /* end of switch(add) */
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * We received an #MHD_HTTP_OK history code. Handle the JSON
+ * response.
+ *
+ * @param rsh handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_coins_history_ok (struct TALER_EXCHANGE_CoinsHistoryHandle *rsh,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_CoinHistory rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_OK
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("balance",
+ &rs.details.ok.balance),
+ GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
+ &rs.details.ok.h_denom_pub),
+ GNUNET_JSON_spec_array_const ("history",
+ &rs.details.ok.history),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (NULL != rsh->cb)
+ {
+ rsh->cb (rsh->cb_cls,
+ &rs);
+ rsh->cb = NULL;
+ }
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /coins/$RID/history request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_CoinsHistoryHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_coins_history_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_CoinsHistoryHandle *rsh = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_CoinHistory rs = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ rsh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ handle_coins_history_ok (rsh,
+ j))
+ {
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for coins history\n",
+ (unsigned int) response_code,
+ (int) rs.hr.ec);
+ break;
+ }
+ if (NULL != rsh->cb)
+ {
+ rsh->cb (rsh->cb_cls,
+ &rs);
+ rsh->cb = NULL;
+ }
+ TALER_EXCHANGE_coins_history_cancel (rsh);
+}
+
+
+struct TALER_EXCHANGE_CoinsHistoryHandle *
+TALER_EXCHANGE_coins_history (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ uint64_t start_off,
+ TALER_EXCHANGE_CoinsHistoryCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_CoinsHistoryHandle *rsh;
+ CURL *eh;
+ char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 64];
+ struct curl_slist *job_headers;
+
+ rsh = GNUNET_new (struct TALER_EXCHANGE_CoinsHistoryHandle);
+ rsh->cb = cb;
+ rsh->cb_cls = cb_cls;
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
+ &rsh->coin_pub.eddsa_pub);
+ {
+ char pub_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &rsh->coin_pub,
+ sizeof (rsh->coin_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ if (0 != start_off)
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "coins/%s/history?start=%llu",
+ pub_str,
+ (unsigned long long) start_off);
+ else
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "coins/%s/history",
+ pub_str);
+ }
+ rsh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
+ if (NULL == rsh->url)
+ {
+ GNUNET_free (rsh);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (rsh->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (rsh->url);
+ GNUNET_free (rsh);
+ return NULL;
+ }
+
+ {
+ struct TALER_CoinSpendSignatureP coin_sig;
+ char *sig_hdr;
+ char *hdr;
+
+ TALER_wallet_coin_history_sign (start_off,
+ coin_priv,
+ &coin_sig);
+
+ sig_hdr = GNUNET_STRINGS_data_to_string_alloc (
+ &coin_sig,
+ sizeof (coin_sig));
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ TALER_COIN_HISTORY_SIGNATURE_HEADER,
+ sig_hdr);
+ GNUNET_free (sig_hdr);
+ job_headers = curl_slist_append (NULL,
+ hdr);
+ GNUNET_free (hdr);
+ if (NULL == job_headers)
+ {
+ GNUNET_break (0);
+ curl_easy_cleanup (eh);
+ return NULL;
+ }
+ }
+
+ rsh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ job_headers,
+ &handle_coins_history_finished,
+ rsh);
+ curl_slist_free_all (job_headers);
+ return rsh;
+}
+
+
+void
+TALER_EXCHANGE_coins_history_cancel (
+ struct TALER_EXCHANGE_CoinsHistoryHandle *rsh)
+{
+ if (NULL != rsh->job)
+ {
+ GNUNET_CURL_job_cancel (rsh->job);
+ rsh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&rsh->post_ctx);
+ GNUNET_free (rsh->url);
+ GNUNET_free (rsh);
+}
+
+
+/**
+ * Verify that @a coin_sig does NOT appear in the @a history of a coin's
+ * transactions and thus whatever transaction is authorized by @a coin_sig is
+ * a conflict with @a proof.
+ *
+ * @param history coin history to check
+ * @param coin_sig signature that must not be in @a history
+ * @return #GNUNET_OK if @a coin_sig is not in @a history
+ */
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_check_coin_signature_conflict (
+ const json_t *history,
+ const struct TALER_CoinSpendSignatureP *coin_sig)
+{
+ size_t off;
+ json_t *entry;
+
+ json_array_foreach (history, off, entry)
+ {
+ struct TALER_CoinSpendSignatureP cs;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("coin_sig",
+ &cs),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (entry,
+ spec,
+ NULL, NULL))
+ continue; /* entry without coin signature */
+ if (0 ==
+ GNUNET_memcmp (&cs,
+ coin_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+#if FIXME_IMPLEMENT
+/**
+ * FIXME-Oec: we need some specific routines that show
+ * that certain coin operations are indeed in conflict,
+ * for example that the coin is of a different denomination
+ * or different age restrictions.
+ * This relates to unimplemented error handling for
+ * coins in the exchange!
+ *
+ * Check that the provided @a proof indeeds indicates
+ * a conflict for @a coin_pub.
+ *
+ * @param keys exchange keys
+ * @param proof provided conflict proof
+ * @param dk denomination of @a coin_pub that the client
+ * used
+ * @param coin_pub public key of the coin
+ * @param required balance required on the coin for the operation
+ * @return #GNUNET_OK if @a proof holds
+ */
+// FIXME: should be properly defined and implemented!
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_check_coin_conflict_ (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const json_t *proof,
+ const struct TALER_EXCHANGE_DenomPublicKey *dk,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *required)
+{
+ enum TALER_ErrorCode ec;
+
+ ec = TALER_JSON_get_error_code (proof);
+ switch (ec)
+ {
+ case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
+ /* Nothing to check anymore here, proof needs to be
+ checked in the GET /coins/$COIN_PUB handler */
+ break;
+ case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY:
+ // FIXME: write check!
+ break;
+ default:
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+#endif
+
+
+/* end of exchange_api_coins_history.c */
diff --git a/src/lib/exchange_api_common.c b/src/lib/exchange_api_common.c
index 739b215f6..bd731ad37 100644
--- a/src/lib/exchange_api_common.c
+++ b/src/lib/exchange_api_common.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2022 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -27,1359 +27,6 @@
#include "taler_signatures.h"
-/**
- * Context for history entry helpers.
- */
-struct HistoryParseContext
-{
-
- /**
- * Exchange we use.
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * Our reserve public key.
- */
- const struct TALER_ReservePublicKeyP *reserve_pub;
-
- /**
- * Array of UUIDs.
- */
- struct GNUNET_HashCode *uuids;
-
- /**
- * Where to sum up total inbound amounts.
- */
- struct TALER_Amount *total_in;
-
- /**
- * Where to sum up total outbound amounts.
- */
- struct TALER_Amount *total_out;
-
- /**
- * Number of entries already used in @e uuids.
- */
- unsigned int uuid_off;
-};
-
-
-/**
- * Type of a function called to parse a reserve history
- * entry @a rh.
- *
- * @param[in,out] rh where to write the result
- * @param[in,out] uc UUID context for duplicate detection
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-typedef enum GNUNET_GenericReturnValue
-(*ParseHelper)(struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction);
-
-
-/**
- * Parse "credit" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_credit (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- const char *wire_url;
- uint64_t wire_reference;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_JSON_Specification withdraw_spec[] = {
- GNUNET_JSON_spec_uint64 ("wire_reference",
- &wire_reference),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
- GNUNET_JSON_spec_string ("sender_account_url",
- &wire_url),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_CREDIT;
- if (0 >
- TALER_amount_add (uc->total_in,
- uc->total_in,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- withdraw_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- rh->details.in_details.sender_url = GNUNET_strdup (wire_url);
- rh->details.in_details.wire_reference = wire_reference;
- rh->details.in_details.timestamp = timestamp;
- return GNUNET_OK;
-}
-
-
-/**
- * Parse "credit" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- struct TALER_ReserveSignatureP sig;
- struct TALER_DenominationHashP h_denom_pub;
- struct TALER_BlindedCoinHashP bch;
- struct TALER_Amount withdraw_fee;
- struct GNUNET_JSON_Specification withdraw_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &sig),
- TALER_JSON_spec_amount_any ("withdraw_fee",
- &withdraw_fee),
- GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &h_denom_pub),
- GNUNET_JSON_spec_fixed_auto ("h_coin_envelope",
- &bch),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_WITHDRAWAL;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- withdraw_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- /* Check that the signature is a valid withdraw request */
- if (GNUNET_OK !=
- TALER_wallet_withdraw_verify (&h_denom_pub,
- &rh->amount,
- &bch,
- uc->reserve_pub,
- &sig))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (withdraw_spec);
- return GNUNET_SYSERR;
- }
- /* check that withdraw fee matches expectations! */
- {
- const struct TALER_EXCHANGE_Keys *key_state;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
-
- key_state = TALER_EXCHANGE_get_keys (uc->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &h_denom_pub);
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&withdraw_fee,
- &dki->fees.withdraw)) ||
- (0 !=
- TALER_amount_cmp (&withdraw_fee,
- &dki->fees.withdraw)) )
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (withdraw_spec);
- return GNUNET_SYSERR;
- }
- rh->details.withdraw.fee = withdraw_fee;
- }
- rh->details.withdraw.out_authorization_sig
- = json_object_get (transaction,
- "signature");
- /* Check check that the same withdraw transaction
- isn't listed twice by the exchange. We use the
- "uuid" array to remember the hashes of all
- signatures, and compare the hashes to find
- duplicates. */
- GNUNET_CRYPTO_hash (&sig,
- sizeof (sig),
- &uc->uuids[uc->uuid_off]);
- for (unsigned int i = 0; i<uc->uuid_off; i++)
- {
- if (0 == GNUNET_memcmp (&uc->uuids[uc->uuid_off],
- &uc->uuids[i]))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (withdraw_spec);
- return GNUNET_SYSERR;
- }
- }
- uc->uuid_off++;
-
- if (0 >
- TALER_amount_add (uc->total_out,
- uc->total_out,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (withdraw_spec);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Parse "recoup" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_recoup (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- const struct TALER_EXCHANGE_Keys *key_state;
- struct GNUNET_JSON_Specification recoup_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_pub",
- &rh->details.recoup_details.coin_pub),
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &rh->details.recoup_details.exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &rh->details.recoup_details.exchange_pub),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &rh->details.recoup_details.timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_RECOUP;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- recoup_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- key_state = TALER_EXCHANGE_get_keys (uc->exchange);
- if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- &rh->details.
- recoup_details.exchange_pub))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_confirm_recoup_verify (
- rh->details.recoup_details.timestamp,
- &rh->amount,
- &rh->details.recoup_details.coin_pub,
- uc->reserve_pub,
- &rh->details.recoup_details.exchange_pub,
- &rh->details.recoup_details.exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (uc->total_in,
- uc->total_in,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Parse "closing" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_closing (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- const struct TALER_EXCHANGE_Keys *key_state;
- struct GNUNET_JSON_Specification closing_spec[] = {
- GNUNET_JSON_spec_string (
- "receiver_account_details",
- &rh->details.close_details.receiver_account_details),
- GNUNET_JSON_spec_fixed_auto ("wtid",
- &rh->details.close_details.wtid),
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &rh->details.close_details.exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &rh->details.close_details.exchange_pub),
- TALER_JSON_spec_amount_any ("closing_fee",
- &rh->details.close_details.fee),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &rh->details.close_details.timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_CLOSE;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- closing_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- key_state = TALER_EXCHANGE_get_keys (uc->exchange);
- if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (
- key_state,
- &rh->details.close_details.exchange_pub))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_reserve_closed_verify (
- rh->details.close_details.timestamp,
- &rh->amount,
- &rh->details.close_details.fee,
- rh->details.close_details.receiver_account_details,
- &rh->details.close_details.wtid,
- uc->reserve_pub,
- &rh->details.close_details.exchange_pub,
- &rh->details.close_details.exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (uc->total_out,
- uc->total_out,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Parse "merge" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- uint32_t flags32;
- struct GNUNET_JSON_Specification merge_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &rh->details.merge_details.h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("merge_pub",
- &rh->details.merge_details.merge_pub),
- GNUNET_JSON_spec_fixed_auto ("purse_pub",
- &rh->details.merge_details.purse_pub),
- GNUNET_JSON_spec_uint32 ("min_age",
- &rh->details.merge_details.min_age),
- GNUNET_JSON_spec_uint32 ("flags",
- &flags32),
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &rh->details.merge_details.reserve_sig),
- TALER_JSON_spec_amount_any ("purse_fee",
- &rh->details.merge_details.purse_fee),
- GNUNET_JSON_spec_timestamp ("merge_timestamp",
- &rh->details.merge_details.merge_timestamp),
- GNUNET_JSON_spec_timestamp ("purse_expiration",
- &rh->details.merge_details.purse_expiration),
- GNUNET_JSON_spec_bool ("merged",
- &rh->details.merge_details.merged),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_MERGE;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- merge_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- rh->details.merge_details.flags =
- (enum TALER_WalletAccountMergeFlags) flags32;
- if (GNUNET_OK !=
- TALER_wallet_account_merge_verify (
- rh->details.merge_details.merge_timestamp,
- &rh->details.merge_details.purse_pub,
- rh->details.merge_details.purse_expiration,
- &rh->details.merge_details.h_contract_terms,
- &rh->amount,
- &rh->details.merge_details.purse_fee,
- rh->details.merge_details.min_age,
- rh->details.merge_details.flags,
- uc->reserve_pub,
- &rh->details.merge_details.reserve_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (rh->details.merge_details.merged)
- {
- if (0 >
- TALER_amount_add (uc->total_in,
- uc->total_in,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- else
- {
- if (0 >
- TALER_amount_add (uc->total_out,
- uc->total_out,
- &rh->details.merge_details.purse_fee))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Parse "history" reserve history entry.
- *
- * @param[in,out] rh entry to parse
- * @param uc our context
- * @param transaction the transaction to parse
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-parse_history (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
- struct HistoryParseContext *uc,
- const json_t *transaction)
-{
- struct GNUNET_JSON_Specification history_spec[] = {
- GNUNET_JSON_spec_fixed_auto ("reserve_sig",
- &rh->details.history_details.reserve_sig),
- GNUNET_JSON_spec_timestamp ("request_timestamp",
- &rh->details.history_details.request_timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- rh->type = TALER_EXCHANGE_RTT_HISTORY;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- history_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_reserve_history_verify (
- rh->details.history_details.request_timestamp,
- &rh->amount,
- uc->reserve_pub,
- &rh->details.history_details.reserve_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (uc->total_out,
- uc->total_out,
- &rh->amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_parse_reserve_history (
- struct TALER_EXCHANGE_Handle *exchange,
- const json_t *history,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const char *currency,
- struct TALER_Amount *total_in,
- struct TALER_Amount *total_out,
- unsigned int history_length,
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory)
-{
- const struct
- {
- const char *type;
- ParseHelper helper;
- } map[] = {
- { "CREDIT", &parse_credit },
- { "WITHDRAW", &parse_withdraw },
- { "RECOUP", &parse_recoup },
- { "MERGE", &parse_merge },
- { "CLOSING", &parse_closing },
- { "HISTORY", &parse_history },
- { NULL, NULL }
- };
- struct GNUNET_HashCode uuid[history_length];
- struct HistoryParseContext uc = {
- .exchange = exchange,
- .reserve_pub = reserve_pub,
- .uuids = uuid,
- .total_in = total_in,
- .total_out = total_out
- };
-
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (currency,
- total_in));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (currency,
- total_out));
- for (unsigned int off = 0; off<history_length; off++)
- {
- struct TALER_EXCHANGE_ReserveHistoryEntry *rh = &rhistory[off];
- json_t *transaction;
- struct TALER_Amount amount;
- const char *type;
- struct GNUNET_JSON_Specification hist_spec[] = {
- GNUNET_JSON_spec_string ("type",
- &type),
- TALER_JSON_spec_amount_any ("amount",
- &amount),
- /* 'wire' and 'signature' are optional depending on 'type'! */
- GNUNET_JSON_spec_end ()
- };
- bool found = false;
-
- transaction = json_array_get (history,
- off);
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- hist_spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- json_dumpf (transaction,
- stderr,
- JSON_INDENT (2));
- return GNUNET_SYSERR;
- }
- rh->amount = amount;
- if (GNUNET_YES !=
- TALER_amount_cmp_currency (&amount,
- total_in))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- for (unsigned int i = 0; NULL != map[i].type; i++)
- {
- if (0 == strcasecmp (map[i].type,
- type))
- {
- found = true;
- if (GNUNET_OK !=
- map[i].helper (rh,
- &uc,
- transaction))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- break;
- }
- }
- if (! found)
- {
- /* unexpected 'type', protocol incompatibility, complain! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
-}
-
-
-void
-TALER_EXCHANGE_free_reserve_history (
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory,
- unsigned int len)
-{
- for (unsigned int i = 0; i<len; i++)
- {
- switch (rhistory[i].type)
- {
- case TALER_EXCHANGE_RTT_CREDIT:
- GNUNET_free (rhistory[i].details.in_details.sender_url);
- break;
- case TALER_EXCHANGE_RTT_WITHDRAWAL:
- break;
- case TALER_EXCHANGE_RTT_RECOUP:
- break;
- case TALER_EXCHANGE_RTT_CLOSE:
- break;
- case TALER_EXCHANGE_RTT_HISTORY:
- break;
- case TALER_EXCHANGE_RTT_MERGE:
- break;
- }
- }
- GNUNET_free (rhistory);
-}
-
-
-/**
- * Context for coin helpers.
- */
-struct CoinHistoryParseContext
-{
-
- /**
- * Denomination of the coin.
- */
- const struct TALER_EXCHANGE_DenomPublicKey *dk;
-
- /**
- * Our coin public key.
- */
- const struct TALER_CoinSpendPublicKeyP *coin_pub;
-
- /**
- * Where to sum up total refunds.
- */
- struct TALER_Amount rtotal;
-
- /**
- * Total amount encountered.
- */
- struct TALER_Amount *total;
-
-};
-
-
-/**
- * Signature of functions that operate on one of
- * the coin's history entries.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-typedef enum GNUNET_GenericReturnValue
-(*CoinCheckHelper)(struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction);
-
-
-/**
- * Handle deposit entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_deposit (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- struct TALER_MerchantWireHashP h_wire;
- struct TALER_PrivateContractHashP h_contract_terms;
- // struct TALER_ExtensionContractHashP h_extensions; // FIXME!
- struct GNUNET_TIME_Timestamp wallet_timestamp;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_TIME_Timestamp refund_deadline = {0};
- struct TALER_CoinSpendSignatureP sig;
- struct TALER_AgeCommitmentHash hac;
- bool no_hac;
- struct TALER_Amount deposit_fee;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &sig),
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("h_wire",
- &h_wire),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &hac),
- &no_hac),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &wallet_timestamp),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_timestamp ("refund_deadline",
- &refund_deadline),
- NULL),
- TALER_JSON_spec_amount_any ("deposit_fee",
- &deposit_fee),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &merchant_pub),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_deposit_verify (
- amount,
- &deposit_fee,
- &h_wire,
- &h_contract_terms,
- no_hac ? NULL : &hac,
- NULL /* h_extensions! */,
- &pc->dk->h_key,
- wallet_timestamp,
- &merchant_pub,
- refund_deadline,
- pc->coin_pub,
- &sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (NULL != pc->dk)
- {
- /* check that deposit fee matches our expectations from /keys! */
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&deposit_fee,
- &pc->dk->fees.deposit)) ||
- (0 !=
- TALER_amount_cmp (&deposit_fee,
- &pc->dk->fees.deposit)) )
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_YES;
-}
-
-
-/**
- * Handle melt entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_melt (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- struct TALER_CoinSpendSignatureP sig;
- struct TALER_RefreshCommitmentP rc;
- struct TALER_AgeCommitmentHash h_age_commitment;
- bool no_hac;
- struct TALER_Amount melt_fee;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &sig),
- GNUNET_JSON_spec_fixed_auto ("rc",
- &rc),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &h_age_commitment),
- &no_hac),
- TALER_JSON_spec_amount_any ("melt_fee",
- &melt_fee),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- /* check that melt fee matches our expectations from /keys! */
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&melt_fee,
- &pc->dk->fees.refresh)) ||
- (0 !=
- TALER_amount_cmp (&melt_fee,
- &pc->dk->fees.refresh)) )
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_melt_verify (
- amount,
- &melt_fee,
- &rc,
- &pc->dk->h_key,
- no_hac
- ? NULL
- : &h_age_commitment,
- pc->coin_pub,
- &sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_YES;
-}
-
-
-/**
- * Handle refund entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_refund (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct TALER_MerchantSignatureP sig;
- struct TALER_Amount refund_fee;
- struct TALER_Amount sig_amount;
- uint64_t rtransaction_id;
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("refund_fee",
- &refund_fee),
- GNUNET_JSON_spec_fixed_auto ("merchant_sig",
- &sig),
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &merchant_pub),
- GNUNET_JSON_spec_uint64 ("rtransaction_id",
- &rtransaction_id),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (&sig_amount,
- &refund_fee,
- amount))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_merchant_refund_verify (pc->coin_pub,
- &h_contract_terms,
- rtransaction_id,
- &sig_amount,
- &merchant_pub,
- &sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- /* NOTE: theoretically, we could also check that the given
- merchant_pub and h_contract_terms appear in the
- history under deposits. However, there is really no benefit
- for the exchange to lie here, so not checking is probably OK
- (an auditor ought to check, though). Then again, we similarly
- had no reason to check the merchant's signature (other than a
- well-formendess check). */
-
- /* check that refund fee matches our expectations from /keys! */
- if ( (GNUNET_YES !=
- TALER_amount_cmp_currency (&refund_fee,
- &pc->dk->fees.refund)) ||
- (0 !=
- TALER_amount_cmp (&refund_fee,
- &pc->dk->fees.refund)) )
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_NO;
-}
-
-
-/**
- * Handle recoup entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_recoup (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- struct TALER_ReservePublicKeyP reserve_pub;
- struct GNUNET_TIME_Timestamp timestamp;
- union TALER_DenominationBlindingKeyP coin_bks;
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_ExchangeSignatureP exchange_sig;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &exchange_pub),
- GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &reserve_pub),
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &coin_sig),
- GNUNET_JSON_spec_fixed_auto ("coin_blind",
- &coin_bks),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_confirm_recoup_verify (
- timestamp,
- amount,
- pc->coin_pub,
- &reserve_pub,
- &exchange_pub,
- &exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_recoup_verify (&pc->dk->h_key,
- &coin_bks,
- pc->coin_pub,
- &coin_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_YES;
-}
-
-
-/**
- * Handle recoup-refresh entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_recoup_refresh (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- /* This is the coin that was subjected to a recoup,
- the value being credited to the old coin. */
- struct TALER_CoinSpendPublicKeyP old_coin_pub;
- union TALER_DenominationBlindingKeyP coin_bks;
- struct GNUNET_TIME_Timestamp timestamp;
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_ExchangeSignatureP exchange_sig;
- struct TALER_CoinSpendSignatureP coin_sig;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &exchange_pub),
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &coin_sig),
- GNUNET_JSON_spec_fixed_auto ("old_coin_pub",
- &old_coin_pub),
- GNUNET_JSON_spec_fixed_auto ("coin_blind",
- &coin_bks),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_confirm_recoup_refresh_verify (
- timestamp,
- amount,
- pc->coin_pub,
- &old_coin_pub,
- &exchange_pub,
- &exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_recoup_verify (&pc->dk->h_key,
- &coin_bks,
- pc->coin_pub,
- &coin_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_YES;
-}
-
-
-/**
- * Handle old coin recoup entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_old_coin_recoup (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- /* This is the coin that was credited in a recoup,
- the value being credited to the this coin. */
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_ExchangeSignatureP exchange_sig;
- struct TALER_CoinSpendPublicKeyP new_coin_pub;
- struct GNUNET_TIME_Timestamp timestamp;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &exchange_pub),
- GNUNET_JSON_spec_fixed_auto ("coin_pub",
- &new_coin_pub),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &timestamp),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_confirm_recoup_refresh_verify (
- timestamp,
- amount,
- &new_coin_pub,
- pc->coin_pub,
- &exchange_pub,
- &exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_NO;
-}
-
-
-/**
- * Handle purse deposit entry in the coin's history.
- *
- * @param[in,out] pc overall context
- * @param amount main amount of this operation
- * @param transaction JSON details for the operation
- * @return #GNUNET_SYSERR on error,
- * #GNUNET_OK to add, #GNUNET_NO to subtract
- */
-static enum GNUNET_GenericReturnValue
-help_purse_deposit (struct CoinHistoryParseContext *pc,
- const struct TALER_Amount *amount,
- json_t *transaction)
-{
- struct TALER_PurseContractPublicKeyP purse_pub;
- struct TALER_CoinSpendSignatureP coin_sig;
- const char *exchange_base_url;
- bool refunded;
- struct TALER_AgeCommitmentHash phac = { 0 };
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("purse_pub",
- &purse_pub),
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &coin_sig),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &coin_sig),
- NULL),
- GNUNET_JSON_spec_string ("exchange_base_url",
- &exchange_base_url),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &phac),
- NULL),
- GNUNET_JSON_spec_bool ("refunded",
- &refunded),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_purse_deposit_verify (
- exchange_base_url,
- &purse_pub,
- amount,
- &pc->dk->h_key,
- &phac,
- pc->coin_pub,
- &coin_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (refunded)
- {
- /* We add the amount to refunds here, the original
- deposit will be added to the balance later because
- we still return GNUNET_YES, thus effectively
- cancelling out this operation with respect to
- the final balance. */
- if (0 >
- TALER_amount_add (&pc->rtotal,
- &pc->rtotal,
- amount))
- {
- /* overflow in refund history? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_YES;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_verify_coin_history (
- const struct TALER_EXCHANGE_DenomPublicKey *dk,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- json_t *history,
- struct TALER_Amount *total)
-{
- const char *currency = dk->value.currency;
- const struct
- {
- const char *type;
- CoinCheckHelper helper;
- } map[] = {
- { "DEPOSIT", &help_deposit },
- { "MELT", &help_melt },
- { "REFUND", &help_refund },
- { "RECOUP", &help_recoup },
- { "RECOUP-REFRESH", &help_recoup_refresh },
- { "OLD-COIN-RECOUP", &help_old_coin_recoup },
- { "PURSE-DEPOSIT", &help_purse_deposit },
- { NULL, NULL }
- };
- struct CoinHistoryParseContext pc = {
- .dk = dk,
- .coin_pub = coin_pub,
- .total = total
- };
- size_t len;
-
- if (NULL == history)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- len = json_array_size (history);
- if (0 == len)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (currency,
- total));
- GNUNET_assert (GNUNET_OK ==
- TALER_amount_set_zero (currency,
- &pc.rtotal));
- for (size_t off = 0; off<len; off++)
- {
- enum GNUNET_GenericReturnValue add;
- json_t *transaction;
- struct TALER_Amount amount;
- const char *type;
- struct GNUNET_JSON_Specification spec_glob[] = {
- TALER_JSON_spec_amount_any ("amount",
- &amount),
- GNUNET_JSON_spec_string ("type",
- &type),
- GNUNET_JSON_spec_end ()
- };
-
- transaction = json_array_get (history,
- off);
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec_glob,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_YES !=
- TALER_amount_cmp_currency (&amount,
- &pc.rtotal))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Operation of type %s with amount %s\n",
- type,
- TALER_amount2s (&amount));
- add = GNUNET_SYSERR;
- for (unsigned int i = 0; NULL != map[i].type; i++)
- {
- if (0 == strcasecmp (type,
- map[i].type))
- {
- add = map[i].helper (&pc,
- &amount,
- transaction);
- break;
- }
- }
- switch (add)
- {
- case GNUNET_SYSERR:
- /* entry type not supported, new version on server? */
- GNUNET_break_op (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected type `%s' in response\n",
- type);
- return GNUNET_SYSERR;
- case GNUNET_YES:
- /* This amount should be added to the total */
- if (0 >
- TALER_amount_add (total,
- total,
- &amount))
- {
- /* overflow in history already!? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- break;
- case GNUNET_NO:
- /* This amount should be subtracted from the total.
-
- However, for the implementation, we first *add* up all of
- these negative amounts, as we might get refunds before
- deposits from a semi-evil exchange. Then, at the end, we do
- the subtraction by calculating "total = total - rtotal" */
- if (0 >
- TALER_amount_add (&pc.rtotal,
- &pc.rtotal,
- &amount))
- {
- /* overflow in refund history? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- break;
- } /* end of switch(add) */
- }
- /* Finally, subtract 'rtotal' from total to handle the subtractions */
- if (0 >
- TALER_amount_subtract (total,
- total,
- &pc.rtotal))
- {
- /* underflow in history? inconceivable! Bad exchange! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
const struct TALER_EXCHANGE_SigningPublicKey *
TALER_EXCHANGE_get_signing_key_info (
const struct TALER_EXCHANGE_Keys *keys,
@@ -1458,50 +105,6 @@ TALER_EXCHANGE_check_purse_create_conflict_ (
}
-static char *
-make_payto (const char *exchange_url,
- const struct TALER_ReservePublicKeyP *reserve_pub)
-{
- char pub_str[sizeof (*reserve_pub) * 2];
- char *end;
- bool is_http;
- char *reserve_url;
-
- end = GNUNET_STRINGS_data_to_string (
- reserve_pub,
- sizeof (*reserve_pub),
- pub_str,
- sizeof (pub_str));
- *end = '\0';
- if (0 == strncmp (exchange_url,
- "http://",
- strlen ("http://")))
- {
- is_http = true;
- exchange_url = &exchange_url[strlen ("http://")];
- }
- else if (0 == strncmp (exchange_url,
- "https://",
- strlen ("https://")))
- {
- is_http = false;
- exchange_url = &exchange_url[strlen ("https://")];
- }
- else
- {
- GNUNET_break (0);
- return NULL;
- }
- /* exchange_url includes trailing '/' */
- GNUNET_asprintf (&reserve_url,
- "payto://%s/%s%s",
- is_http ? "taler+http" : "taler",
- exchange_url,
- pub_str);
- return reserve_url;
-}
-
-
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_check_purse_merge_conflict_ (
const struct TALER_PurseMergeSignatureP *cmerge_sig,
@@ -1516,7 +119,7 @@ TALER_EXCHANGE_check_purse_merge_conflict_ (
struct TALER_ReservePublicKeyP reserve_pub;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("partner_url",
+ TALER_JSON_spec_web_url ("partner_url",
&partner_url),
NULL),
GNUNET_JSON_spec_timestamp ("merge_timestamp",
@@ -1539,8 +142,8 @@ TALER_EXCHANGE_check_purse_merge_conflict_ (
}
if (NULL == partner_url)
partner_url = exchange_url;
- payto_uri = make_payto (partner_url,
- &reserve_pub);
+ payto_uri = TALER_reserve_make_payto (partner_url,
+ &reserve_pub);
if (GNUNET_OK !=
TALER_wallet_purse_merge_verify (
payto_uri,
@@ -1588,7 +191,7 @@ TALER_EXCHANGE_check_purse_coin_conflict_ (
GNUNET_JSON_spec_fixed_auto ("coin_pub",
coin_pub),
GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("partner_url",
+ TALER_JSON_spec_web_url ("partner_url",
&partner_url),
NULL),
TALER_JSON_spec_amount_any ("amount",
@@ -1672,120 +275,7 @@ TALER_EXCHANGE_check_purse_econtract_conflict_ (
}
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_check_coin_amount_conflict_ (
- const struct TALER_EXCHANGE_Keys *keys,
- const json_t *proof,
- struct TALER_CoinSpendPublicKeyP *coin_pub,
- struct TALER_Amount *remaining)
-{
- json_t *history;
- struct TALER_Amount total;
- struct TALER_DenominationHashP h_denom_pub;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_pub",
- coin_pub),
- GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &h_denom_pub),
- GNUNET_JSON_spec_json ("history",
- &history),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (proof,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (
- keys,
- &h_denom_pub);
- if (NULL == dki)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_verify_coin_history (dki,
- coin_pub,
- history,
- &total))
- {
- GNUNET_break_op (0);
- json_decref (history);
- return GNUNET_SYSERR;
- }
- json_decref (history);
- if (0 >
- TALER_amount_subtract (remaining,
- &dki->value,
- &total))
- {
- /* Strange 'proof': coin was double-spent
- before our transaction?! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Verify that @a coin_sig does NOT appear in
- * the history of @a proof and thus whatever transaction
- * is authorized by @a coin_sig is a conflict with
- * @a proof.
- *
- * @param proof a proof to check
- * @param coin_sig signature that must not be in @a proof
- * @return #GNUNET_OK if @a coin_sig is not in @a proof
- */
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_check_coin_signature_conflict_ (
- const json_t *proof,
- const struct TALER_CoinSpendSignatureP *coin_sig)
-{
- json_t *history;
- size_t off;
- json_t *entry;
-
- history = json_object_get (proof,
- "history");
- if (NULL == history)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- json_array_foreach (history, off, entry)
- {
- struct TALER_CoinSpendSignatureP cs;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &cs),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (entry,
- spec,
- NULL, NULL))
- continue; /* entry without coin signature */
- if (0 ==
- GNUNET_memcmp (&cs,
- coin_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
-}
-
-
+// FIXME: should be used...
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_check_coin_denomination_conflict_ (
const json_t *proof,
@@ -1819,104 +309,6 @@ TALER_EXCHANGE_check_coin_denomination_conflict_ (
enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_check_coin_conflict_ (
- const struct TALER_EXCHANGE_Keys *keys,
- const json_t *proof,
- const struct TALER_EXCHANGE_DenomPublicKey *dk,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_Amount *required)
-{
- enum TALER_ErrorCode ec;
-
- ec = TALER_JSON_get_error_code (proof);
- switch (ec)
- {
- case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
- {
- struct TALER_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- proof,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 !=
- GNUNET_memcmp (&pcoin_pub,
- coin_pub))
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (-1 !=
- TALER_amount_cmp (&left,
- required))
- {
- /* Balance was sufficient after all; recoup MAY have still been possible */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_signature_conflict_ (
- proof,
- coin_sig))
- {
- /* Not a conflicting transaction: ours is included! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- break;
- }
- case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY:
- {
- struct TALER_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- proof,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (0 !=
- GNUNET_memcmp (&pcoin_pub,
- coin_pub))
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_denomination_conflict_ (
- proof,
- &dk->h_key))
- {
- /* Eh, same denomination, hence no conflict */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- break;
- }
- default:
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
TALER_EXCHANGE_get_min_denomination_ (
const struct TALER_EXCHANGE_Keys *keys,
struct TALER_Amount *min)
@@ -1949,7 +341,7 @@ TALER_EXCHANGE_get_min_denomination_ (
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_verify_deposit_signature_ (
const struct TALER_EXCHANGE_DepositContractDetail *dcd,
- const struct TALER_ExtensionContractHashP *ech,
+ const struct TALER_ExtensionPolicyHashP *ech,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_EXCHANGE_CoinDepositDetail *cdd,
const struct TALER_EXCHANGE_DenomPublicKey *dki)
@@ -1959,10 +351,11 @@ TALER_EXCHANGE_verify_deposit_signature_ (
&dki->fees.deposit,
h_wire,
&dcd->h_contract_terms,
+ &dcd->wallet_data_hash,
&cdd->h_age_commitment,
ech,
&cdd->h_denom_pub,
- dcd->timestamp,
+ dcd->wallet_timestamp,
&dcd->merchant_pub,
dcd->refund_deadline,
&cdd->coin_pub,
@@ -2008,4 +401,253 @@ TALER_EXCHANGE_verify_deposit_signature_ (
}
+/**
+ * Parse account restriction in @a jrest into @a rest.
+ *
+ * @param jresta array of account restrictions in JSON
+ * @param[out] resta_len set to length of @a resta
+ * @param[out] resta account restriction array to set
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_restrictions (const json_t *jresta,
+ unsigned int *resta_len,
+ struct TALER_EXCHANGE_AccountRestriction **resta)
+{
+ size_t alen;
+
+ if (! json_is_array (jresta))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ alen = json_array_size (jresta);
+ if (0 == alen)
+ {
+ /* no restrictions, perfectly OK */
+ *resta = NULL;
+ return GNUNET_OK;
+ }
+ *resta_len = (unsigned int) alen;
+ GNUNET_assert (alen == *resta_len);
+ *resta = GNUNET_new_array (*resta_len,
+ struct TALER_EXCHANGE_AccountRestriction);
+ for (unsigned int i = 0; i<*resta_len; i++)
+ {
+ const json_t *jr = json_array_get (jresta,
+ i);
+ struct TALER_EXCHANGE_AccountRestriction *ar = &(*resta)[i];
+ const char *type = json_string_value (json_object_get (jr,
+ "type"));
+
+ if (NULL == type)
+ {
+ GNUNET_break (0);
+ goto fail;
+ }
+ if (0 == strcmp (type,
+ "deny"))
+ {
+ ar->type = TALER_EXCHANGE_AR_DENY;
+ continue;
+ }
+ if (0 == strcmp (type,
+ "regex"))
+ {
+ const char *regex;
+ const char *hint;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string (
+ "payto_regex",
+ &regex),
+ GNUNET_JSON_spec_string (
+ "human_hint",
+ &hint),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_json (
+ "human_hint_i18n",
+ &ar->details.regex.human_hint_i18n),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (jr,
+ spec,
+ NULL, NULL))
+ {
+ /* bogus reply */
+ GNUNET_break_op (0);
+ goto fail;
+ }
+ ar->type = TALER_EXCHANGE_AR_REGEX;
+ ar->details.regex.posix_egrep = GNUNET_strdup (regex);
+ ar->details.regex.human_hint = GNUNET_strdup (hint);
+ continue;
+ }
+ /* unsupported type */
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+fail:
+ GNUNET_free (*resta);
+ *resta_len = 0;
+ return GNUNET_SYSERR;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_parse_accounts (
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const json_t *accounts,
+ unsigned int was_length,
+ struct TALER_EXCHANGE_WireAccount was[static was_length])
+{
+ memset (was,
+ 0,
+ sizeof (struct TALER_EXCHANGE_WireAccount) * was_length);
+ GNUNET_assert (was_length ==
+ json_array_size (accounts));
+ for (unsigned int i = 0;
+ i<was_length;
+ i++)
+ {
+ struct TALER_EXCHANGE_WireAccount *wa = &was[i];
+ const char *payto_uri;
+ const char *conversion_url = NULL;
+ const char *bank_label = NULL;
+ int64_t priority = 0;
+ const json_t *credit_restrictions;
+ const json_t *debit_restrictions;
+ struct GNUNET_JSON_Specification spec_account[] = {
+ TALER_JSON_spec_payto_uri ("payto_uri",
+ &payto_uri),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_web_url ("conversion_url",
+ &conversion_url),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_int64 ("priority",
+ &priority),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string ("bank_label",
+ &bank_label),
+ NULL),
+ GNUNET_JSON_spec_array_const ("credit_restrictions",
+ &credit_restrictions),
+ GNUNET_JSON_spec_array_const ("debit_restrictions",
+ &debit_restrictions),
+ GNUNET_JSON_spec_fixed_auto ("master_sig",
+ &wa->master_sig),
+ GNUNET_JSON_spec_end ()
+ };
+ json_t *account;
+
+ account = json_array_get (accounts,
+ i);
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (account,
+ spec_account,
+ NULL, NULL))
+ {
+ /* bogus reply */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ( (NULL != master_pub) &&
+ (GNUNET_OK !=
+ TALER_exchange_wire_signature_check (
+ payto_uri,
+ conversion_url,
+ debit_restrictions,
+ credit_restrictions,
+ master_pub,
+ &wa->master_sig)) )
+ {
+ /* bogus reply */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ( (GNUNET_OK !=
+ parse_restrictions (credit_restrictions,
+ &wa->credit_restrictions_length,
+ &wa->credit_restrictions)) ||
+ (GNUNET_OK !=
+ parse_restrictions (debit_restrictions,
+ &wa->debit_restrictions_length,
+ &wa->debit_restrictions)) )
+ {
+ /* bogus reply */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ wa->payto_uri = GNUNET_strdup (payto_uri);
+ wa->priority = priority;
+ if (NULL != conversion_url)
+ wa->conversion_url = GNUNET_strdup (conversion_url);
+ if (NULL != bank_label)
+ wa->bank_label = GNUNET_strdup (bank_label);
+ } /* end 'for all accounts */
+ return GNUNET_OK;
+}
+
+
+/**
+ * Free array of account restrictions.
+ *
+ * @param ar_len length of @a ar
+ * @param[in] ar array to free contents of (but not @a ar itself)
+ */
+static void
+free_restrictions (unsigned int ar_len,
+ struct TALER_EXCHANGE_AccountRestriction ar[static ar_len])
+{
+ for (unsigned int i = 0; i<ar_len; i++)
+ {
+ struct TALER_EXCHANGE_AccountRestriction *a = &ar[i];
+ switch (a->type)
+ {
+ case TALER_EXCHANGE_AR_INVALID:
+ GNUNET_break (0);
+ break;
+ case TALER_EXCHANGE_AR_DENY:
+ break;
+ case TALER_EXCHANGE_AR_REGEX:
+ GNUNET_free (ar->details.regex.posix_egrep);
+ GNUNET_free (ar->details.regex.human_hint);
+ json_decref (ar->details.regex.human_hint_i18n);
+ break;
+ }
+ }
+}
+
+
+void
+TALER_EXCHANGE_free_accounts (
+ unsigned int was_len,
+ struct TALER_EXCHANGE_WireAccount was[static was_len])
+{
+ for (unsigned int i = 0; i<was_len; i++)
+ {
+ struct TALER_EXCHANGE_WireAccount *wa = &was[i];
+
+ GNUNET_free (wa->payto_uri);
+ GNUNET_free (wa->conversion_url);
+ GNUNET_free (wa->bank_label);
+ free_restrictions (wa->credit_restrictions_length,
+ wa->credit_restrictions);
+ GNUNET_array_grow (wa->credit_restrictions,
+ wa->credit_restrictions_length,
+ 0);
+ free_restrictions (wa->debit_restrictions_length,
+ wa->debit_restrictions);
+ GNUNET_array_grow (wa->debit_restrictions,
+ wa->debit_restrictions_length,
+ 0);
+ }
+}
+
+
/* end of exchange_api_common.c */
diff --git a/src/lib/exchange_api_common.h b/src/lib/exchange_api_common.h
index a75ed3ed2..f1f0fd7fa 100644
--- a/src/lib/exchange_api_common.h
+++ b/src/lib/exchange_api_common.h
@@ -129,12 +129,10 @@ TALER_EXCHANGE_check_coin_amount_conflict_ (
/**
- * Verify that @a proof contains a coin history
- * that demonstrates that @a coin_pub was previously
- * used with a denomination key that is different
- * from @a ch_denom_pub. Note that the coin history
- * MUST have been checked before using
- * #TALER_EXCHANGE_check_coin_amount_conflict_().
+ * Verify that @a proof contains a coin history that demonstrates that @a
+ * coin_pub was previously used with a denomination key that is different from
+ * @a ch_denom_pub. Note that the coin history MUST have been checked before
+ * using #TALER_EXCHANGE_check_coin_amount_conflict_().
*
* @param proof a proof to check
* @param ch_denom_pub hash of the conflicting denomination
@@ -148,45 +146,6 @@ TALER_EXCHANGE_check_coin_denomination_conflict_ (
/**
- * Verify that @a coin_sig does NOT appear in
- * the history of @a proof and thus whatever transaction
- * is authorized by @a coin_sig is a conflict with
- * @a proof.
- *
- * @param proof a proof to check
- * @param coin_sig signature that must not be in @a proof
- * @return #GNUNET_OK if @a coin_sig is not in @a proof
- */
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_check_coin_signature_conflict_ (
- const json_t *proof,
- const struct TALER_CoinSpendSignatureP *coin_sig);
-
-
-/**
- * Check that the provided @a proof indeeds indicates
- * a conflict for @a coin_pub.
- *
- * @param keys exchange keys
- * @param proof provided conflict proof
- * @param dk denomination of @a coin_pub that the client
- * used
- * @param coin_pub public key of the coin
- * @param coin_sig signature over operation that conflicted
- * @param required balance required on the coin for the operation
- * @return #GNUNET_OK if @a proof holds
- */
-enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_check_coin_conflict_ (
- const struct TALER_EXCHANGE_Keys *keys,
- const json_t *proof,
- const struct TALER_EXCHANGE_DenomPublicKey *dk,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
- const struct TALER_CoinSpendSignatureP *coin_sig,
- const struct TALER_Amount *required);
-
-
-/**
* Find the smallest denomination amount in @e keys.
*
* @param keys keys to search
@@ -203,7 +162,7 @@ TALER_EXCHANGE_get_min_denomination_ (
* Verify signature information about the deposit.
*
* @param dcd contract details
- * @param ech hashed contract (passed to avoid recomputation)
+ * @param ech hashed policy (passed to avoid recomputation)
* @param h_wire hashed wire details (passed to avoid recomputation)
* @param cdd coin-specific details
* @param dki denomination of the coin
@@ -212,7 +171,7 @@ TALER_EXCHANGE_get_min_denomination_ (
enum GNUNET_GenericReturnValue
TALER_EXCHANGE_verify_deposit_signature_ (
const struct TALER_EXCHANGE_DepositContractDetail *dcd,
- const struct TALER_ExtensionContractHashP *ech,
+ const struct TALER_ExtensionPolicyHashP *ech,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_EXCHANGE_CoinDepositDetail *cdd,
const struct TALER_EXCHANGE_DenomPublicKey *dki);
diff --git a/src/lib/exchange_api_contracts_get.c b/src/lib/exchange_api_contracts_get.c
index 263a0cbe9..aece7733a 100644
--- a/src/lib/exchange_api_contracts_get.c
+++ b/src/lib/exchange_api_contracts_get.c
@@ -39,11 +39,6 @@ struct TALER_EXCHANGE_ContractsGetHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -109,7 +104,7 @@ handle_contract_get_finished (void *cls,
struct TALER_PurseContractSignatureP econtract_sig;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("purse_pub",
- &dr.details.success.purse_pub),
+ &dr.details.ok.purse_pub),
GNUNET_JSON_spec_fixed_auto ("econtract_sig",
&econtract_sig),
GNUNET_JSON_spec_varsize ("econtract",
@@ -133,7 +128,7 @@ handle_contract_get_finished (void *cls,
econtract,
econtract_size,
&cgh->cpub,
- &dr.details.success.purse_pub,
+ &dr.details.ok.purse_pub,
&econtract_sig))
{
GNUNET_break (0);
@@ -142,8 +137,8 @@ handle_contract_get_finished (void *cls,
GNUNET_JSON_parse_free (spec);
break;
}
- dr.details.success.econtract = econtract;
- dr.details.success.econtract_size = econtract_size;
+ dr.details.ok.econtract = econtract;
+ dr.details.ok.econtract_size = econtract_size;
cgh->cb (cgh->cb_cls,
&dr);
GNUNET_JSON_parse_free (spec);
@@ -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);
diff --git a/src/lib/exchange_api_csr_melt.c b/src/lib/exchange_api_csr_melt.c
index 9de8cd8d9..bf6f4bfe1 100644
--- a/src/lib/exchange_api_csr_melt.c
+++ b/src/lib/exchange_api_csr_melt.c
@@ -38,10 +38,6 @@
*/
struct TALER_EXCHANGE_CsRMeltHandle
{
- /**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
/**
* Function to call with the result.
@@ -90,15 +86,15 @@ csr_ok (struct TALER_EXCHANGE_CsRMeltHandle *csrh,
const json_t *arr,
struct TALER_EXCHANGE_HttpResponse *hr)
{
- unsigned int alen = json_array_size (arr);
+ size_t alen = json_array_size (arr);
struct TALER_ExchangeWithdrawValues alg_values[GNUNET_NZL (alen)];
struct TALER_EXCHANGE_CsRMeltResponse csrr = {
.hr = *hr,
- .details.success.alg_values_len = alen,
- .details.success.alg_values = alg_values
+ .details.ok.alg_values_len = alen,
+ .details.ok.alg_values = alg_values
};
- for (unsigned int i = 0; i<alen; i++)
+ for (size_t i = 0; i<alen; i++)
{
json_t *av = json_array_get (arr,
i);
@@ -120,6 +116,8 @@ csr_ok (struct TALER_EXCHANGE_CsRMeltHandle *csrh,
}
csrh->cb (csrh->cb_cls,
&csrr);
+ for (size_t i = 0; i<alen; i++)
+ TALER_denom_ewv_free (&alg_values[i]);
return GNUNET_OK;
}
@@ -220,12 +218,14 @@ handle_csr_finished (void *cls,
struct TALER_EXCHANGE_CsRMeltHandle *
-TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_RefreshMasterSecretP *rms,
- unsigned int nks_len,
- struct TALER_EXCHANGE_NonceKey *nks,
- TALER_EXCHANGE_CsRMeltCallback res_cb,
- void *res_cb_cls)
+TALER_EXCHANGE_csr_melt (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_RefreshMasterSecretP *rms,
+ unsigned int nks_len,
+ struct TALER_EXCHANGE_NonceKey nks[static nks_len],
+ TALER_EXCHANGE_CsRMeltCallback res_cb,
+ void *res_cb_cls)
{
struct TALER_EXCHANGE_CsRMeltHandle *csrh;
json_t *csr_arr;
@@ -236,13 +236,13 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
return NULL;
}
for (unsigned int i = 0; i<nks_len; i++)
- if (TALER_DENOMINATION_CS != nks[i].pk->key.cipher)
+ if (GNUNET_CRYPTO_BSA_CS !=
+ nks[i].pk->key.bsign_pub_key->cipher)
{
GNUNET_break (0);
return NULL;
}
csrh = GNUNET_new (struct TALER_EXCHANGE_CsRMeltHandle);
- csrh->exchange = exchange;
csrh->cb = res_cb;
csrh->cb_cls = res_cb_cls;
csr_arr = json_array ();
@@ -262,8 +262,9 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
json_array_append_new (csr_arr,
csr_obj));
}
- csrh->url = TEAH_path_to_url (exchange,
- "/csr-melt");
+ csrh->url = TALER_url_join (url,
+ "csr-melt",
+ NULL);
if (NULL == csrh->url)
{
json_decref (csr_arr);
@@ -272,7 +273,6 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
}
{
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
json_t *req;
req = GNUNET_JSON_PACK (
@@ -280,7 +280,6 @@ TALER_EXCHANGE_csr_melt (struct TALER_EXCHANGE_Handle *exchange,
rms),
GNUNET_JSON_pack_array_steal ("nks",
csr_arr));
- ctx = TEAH_handle_to_context (exchange);
eh = TALER_EXCHANGE_curl_easy_get_ (csrh->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
diff --git a/src/lib/exchange_api_csr_withdraw.c b/src/lib/exchange_api_csr_withdraw.c
index fa806857d..0fe731cd5 100644
--- a/src/lib/exchange_api_csr_withdraw.c
+++ b/src/lib/exchange_api_csr_withdraw.c
@@ -39,11 +39,6 @@
struct TALER_EXCHANGE_CsRWithdrawHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* Function to call with the result.
*/
TALER_EXCHANGE_CsRWithdrawCallback cb;
@@ -96,7 +91,7 @@ csr_ok (struct TALER_EXCHANGE_CsRWithdrawHandle *csrh,
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_exchange_withdraw_values (
"ewv",
- &csrr.details.success.alg_values),
+ &csrr.details.ok.alg_values),
GNUNET_JSON_spec_end ()
};
@@ -110,6 +105,7 @@ csr_ok (struct TALER_EXCHANGE_CsRWithdrawHandle *csrh,
}
csrh->cb (csrh->cb_cls,
&csrr);
+ TALER_denom_ewv_free (&csrr.details.ok.alg_values);
return GNUNET_OK;
}
@@ -204,25 +200,28 @@ handle_csr_finished (void *cls,
struct TALER_EXCHANGE_CsRWithdrawHandle *
-TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DenomPublicKey *pk,
- const struct TALER_CsNonce *nonce,
- TALER_EXCHANGE_CsRWithdrawCallback res_cb,
- void *res_cb_cls)
+TALER_EXCHANGE_csr_withdraw (
+ struct GNUNET_CURL_Context *curl_ctx,
+ const char *exchange_url,
+ const struct TALER_EXCHANGE_DenomPublicKey *pk,
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
+ TALER_EXCHANGE_CsRWithdrawCallback res_cb,
+ void *res_cb_cls)
{
struct TALER_EXCHANGE_CsRWithdrawHandle *csrh;
- if (TALER_DENOMINATION_CS != pk->key.cipher)
+ if (GNUNET_CRYPTO_BSA_CS !=
+ pk->key.bsign_pub_key->cipher)
{
GNUNET_break (0);
return NULL;
}
csrh = GNUNET_new (struct TALER_EXCHANGE_CsRWithdrawHandle);
- csrh->exchange = exchange;
csrh->cb = res_cb;
csrh->cb_cls = res_cb_cls;
- csrh->url = TEAH_path_to_url (exchange,
- "/csr-withdraw");
+ csrh->url = TALER_url_join (exchange_url,
+ "csr-withdraw",
+ NULL);
if (NULL == csrh->url)
{
GNUNET_free (csrh);
@@ -231,18 +230,16 @@ TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange,
{
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
json_t *req;
req = GNUNET_JSON_PACK (
GNUNET_JSON_pack_data_varsize ("nonce",
nonce,
- sizeof(struct TALER_CsNonce)),
+ sizeof(*nonce)),
GNUNET_JSON_pack_data_varsize ("denom_pub_hash",
&pk->h_key,
- sizeof(struct TALER_DenominationHashP)));
+ sizeof(pk->h_key)));
GNUNET_assert (NULL != req);
- ctx = TEAH_handle_to_context (exchange);
eh = TALER_EXCHANGE_curl_easy_get_ (csrh->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
@@ -259,7 +256,7 @@ TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange,
return NULL;
}
json_decref (req);
- csrh->job = GNUNET_CURL_job_add2 (ctx,
+ csrh->job = GNUNET_CURL_job_add2 (curl_ctx,
eh,
csrh->post_ctx.headers,
&handle_csr_finished,
@@ -270,8 +267,8 @@ TALER_EXCHANGE_csr_withdraw (struct TALER_EXCHANGE_Handle *exchange,
void
-TALER_EXCHANGE_csr_withdraw_cancel (struct
- TALER_EXCHANGE_CsRWithdrawHandle *csrh)
+TALER_EXCHANGE_csr_withdraw_cancel (
+ struct TALER_EXCHANGE_CsRWithdrawHandle *csrh)
{
if (NULL != csrh->job)
{
diff --git a/src/lib/exchange_api_curl_defaults.c b/src/lib/exchange_api_curl_defaults.c
index 9627db9ff..85a32189b 100644
--- a/src/lib/exchange_api_curl_defaults.c
+++ b/src/lib/exchange_api_curl_defaults.c
@@ -19,7 +19,8 @@
* @brief curl easy handle defaults
* @author Florian Dold
*/
-
+#include "platform.h"
+#include "taler_curl_lib.h"
#include "exchange_api_curl_defaults.h"
@@ -38,22 +39,14 @@ TALER_EXCHANGE_curl_easy_get_ (const char *url)
curl_easy_setopt (eh,
CURLOPT_URL,
url));
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_FOLLOWLOCATION,
- 1L));
+ TALER_curl_set_secure_redirect_policy (eh,
+ url);
/* Enable compression (using whatever curl likes), see
https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html */
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_ACCEPT_ENCODING,
""));
- /* limit MAXREDIRS to 5 as a simple security measure against
- a potential infinite loop caused by a malicious target */
- GNUNET_assert (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_MAXREDIRS,
- 5L));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_TCP_FASTOPEN,
diff --git a/src/lib/exchange_api_curl_defaults.h b/src/lib/exchange_api_curl_defaults.h
index 009d72ab8..c4ba04fc5 100644
--- a/src/lib/exchange_api_curl_defaults.h
+++ b/src/lib/exchange_api_curl_defaults.h
@@ -25,7 +25,6 @@
#define _TALER_CURL_DEFAULTS_H
-#include "platform.h"
#include <gnunet/gnunet_curl_lib.h>
diff --git a/src/lib/exchange_api_deposit.c b/src/lib/exchange_api_deposit.c
deleted file mode 100644
index 3ba986b2d..000000000
--- a/src/lib/exchange_api_deposit.c
+++ /dev/null
@@ -1,557 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
- */
-/**
- * @file lib/exchange_api_deposit.c
- * @brief Implementation of the /deposit request of the exchange's HTTP API
- * @author Sree Harsha Totakura <sreeharsha@totakura.in>
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_json_lib.h"
-#include "taler_auditor_service.h"
-#include "taler_exchange_service.h"
-#include "exchange_api_common.h"
-#include "exchange_api_handle.h"
-#include "taler_signatures.h"
-#include "exchange_api_curl_defaults.h"
-
-
-/**
- * 1:#AUDITOR_CHANCE is the probability that we report deposits
- * to the auditor.
- *
- * 20==5% of going to auditor. This is possibly still too high, but set
- * deliberately this high for testing
- */
-#define AUDITOR_CHANCE 20
-
-/**
- * @brief A Deposit Handle
- */
-struct TALER_EXCHANGE_DepositHandle
-{
-
- /**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Context for #TEH_curl_easy_post(). Keeps the data that must
- * persist for Curl to make the upload.
- */
- struct TALER_CURL_PostContext ctx;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_EXCHANGE_DepositResultCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Details about the contract.
- */
- struct TALER_EXCHANGE_DepositContractDetail dcd;
-
- /**
- * Details about the coin.
- */
- struct TALER_EXCHANGE_CoinDepositDetail cdd;
-
- /**
- * Hash of the merchant's wire details.
- */
- struct TALER_MerchantWireHashP h_wire;
-
- /**
- * Hash over the extensions, or all zero.
- */
- struct TALER_ExtensionContractHashP h_extensions;
-
- /**
- * Time when this confirmation was generated / when the exchange received
- * the deposit request.
- */
- struct GNUNET_TIME_Timestamp exchange_timestamp;
-
- /**
- * Exchange signature, set for #auditor_cb.
- */
- struct TALER_ExchangeSignatureP exchange_sig;
-
- /**
- * Exchange signing public key, set for #auditor_cb.
- */
- struct TALER_ExchangePublicKeyP exchange_pub;
-
- /**
- * Chance that we will inform the auditor about the deposit
- * is 1:n, where the value of this field is "n".
- */
- unsigned int auditor_chance;
-
-};
-
-
-/**
- * Function called for each auditor to give us a chance to possibly
- * launch a deposit confirmation interaction.
- *
- * @param cls closure
- * @param ah handle to the auditor
- * @param auditor_pub public key of the auditor
- * @return NULL if no deposit confirmation interaction was launched
- */
-static struct TEAH_AuditorInteractionEntry *
-auditor_cb (void *cls,
- struct TALER_AUDITOR_Handle *ah,
- const struct TALER_AuditorPublicKeyP *auditor_pub)
-{
- struct TALER_EXCHANGE_DepositHandle *dh = cls;
- const struct TALER_EXCHANGE_Keys *key_state;
- const struct TALER_EXCHANGE_SigningPublicKey *spk;
- struct TEAH_AuditorInteractionEntry *aie;
- struct TALER_Amount amount_without_fee;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
-
- if (0 !=
- GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- dh->auditor_chance))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Not providing deposit confirmation to auditor\n");
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Will provide deposit confirmation to auditor `%s'\n",
- TALER_B2S (auditor_pub));
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdd.h_denom_pub);
- GNUNET_assert (NULL != dki);
- spk = TALER_EXCHANGE_get_signing_key_info (key_state,
- &dh->exchange_pub);
- if (NULL == spk)
- {
- GNUNET_break_op (0);
- return NULL;
- }
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &dh->cdd.amount,
- &dki->fees.deposit));
- aie = GNUNET_new (struct TEAH_AuditorInteractionEntry);
- aie->dch = TALER_AUDITOR_deposit_confirmation (
- ah,
- &dh->h_wire,
- &dh->h_extensions,
- &dh->dcd.h_contract_terms,
- dh->exchange_timestamp,
- dh->dcd.wire_deadline,
- dh->dcd.refund_deadline,
- &amount_without_fee,
- &dh->cdd.coin_pub,
- &dh->dcd.merchant_pub,
- &dh->exchange_pub,
- &dh->exchange_sig,
- &key_state->master_pub,
- spk->valid_from,
- spk->valid_until,
- spk->valid_legal,
- &spk->master_sig,
- &TEAH_acc_confirmation_cb,
- aie);
- return aie;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP /deposit request.
- *
- * @param cls the `struct TALER_EXCHANGE_DepositHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response parsed JSON result, NULL on error
- */
-static void
-handle_deposit_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_EXCHANGE_DepositHandle *dh = cls;
- const json_t *j = response;
- struct TALER_EXCHANGE_DepositResult dr = {
- .hr.reply = j,
- .hr.http_status = (unsigned int) response_code
- };
- const struct TALER_EXCHANGE_Keys *keys;
-
- dh->job = NULL;
- keys = TALER_EXCHANGE_get_keys (dh->exchange);
- switch (response_code)
- {
- case 0:
- dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- {
- const struct TALER_EXCHANGE_Keys *key_state;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &dh->exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &dh->exchange_pub),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_string ("transaction_base_url",
- &dr.details.success.transaction_base_url),
- NULL),
- GNUNET_JSON_spec_timestamp ("exchange_timestamp",
- &dh->exchange_timestamp),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_Amount amount_without_fee;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (j,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdd.h_denom_pub);
- GNUNET_assert (NULL != dki);
- if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- &dh->exchange_pub))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
- break;
- }
- GNUNET_assert (0 <=
- TALER_amount_subtract (&amount_without_fee,
- &dh->cdd.amount,
- &dki->fees.deposit));
-
- if (GNUNET_OK !=
- TALER_exchange_online_deposit_confirmation_verify (
- &dh->dcd.h_contract_terms,
- &dh->h_wire,
- &dh->h_extensions,
- dh->exchange_timestamp,
- dh->dcd.wire_deadline,
- dh->dcd.refund_deadline,
- &amount_without_fee,
- &dh->cdd.coin_pub,
- &dh->dcd.merchant_pub,
- &dh->exchange_pub,
- &dh->exchange_sig))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_EXCHANGE_DEPOSIT_INVALID_SIGNATURE_BY_EXCHANGE;
- break;
- }
-
- TEAH_get_auditors_for_dc (dh->exchange,
- &auditor_cb,
- dh);
- }
- dr.details.success.exchange_sig = &dh->exchange_sig;
- dr.details.success.exchange_pub = &dh->exchange_pub;
- dr.details.success.deposit_timestamp = dh->exchange_timestamp;
- break;
- case MHD_HTTP_BAD_REQUEST:
- /* This should never happen, either us or the exchange is buggy
- (or API version conflict); just pass JSON reply to the application */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_FORBIDDEN:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- /* Nothing really to verify, exchange says one of the signatures is
- invalid; as we checked them, this should never happen, we
- should pass the JSON reply to the application */
- break;
- case MHD_HTTP_NOT_FOUND:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- break;
- case MHD_HTTP_CONFLICT:
- {
- const struct TALER_EXCHANGE_Keys *key_state;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
-
- key_state = TALER_EXCHANGE_get_keys (dh->exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &dh->cdd.h_denom_pub);
- GNUNET_assert (NULL != dki);
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_conflict_ (
- keys,
- j,
- dki,
- &dh->cdd.coin_pub,
- &dh->cdd.coin_sig,
- &dh->cdd.amount))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- }
- break;
- case MHD_HTTP_GONE:
- /* could happen if denomination was revoked */
- /* Note: one might want to check /keys for revocation
- signature here, alas tricky in case our /keys
- is outdated => left to clients */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- break;
- default:
- /* unexpected response code */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for exchange deposit\n",
- (unsigned int) response_code,
- dr.hr.ec);
- GNUNET_break_op (0);
- break;
- }
- dh->cb (dh->cb_cls,
- &dr);
- TALER_EXCHANGE_deposit_cancel (dh);
-}
-
-
-struct TALER_EXCHANGE_DepositHandle *
-TALER_EXCHANGE_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DepositContractDetail *dcd,
- const struct TALER_EXCHANGE_CoinDepositDetail *cdd,
- TALER_EXCHANGE_DepositResultCallback cb,
- void *cb_cls,
- enum TALER_ErrorCode *ec)
-{
- const struct TALER_EXCHANGE_Keys *key_state;
- struct TALER_EXCHANGE_DepositHandle *dh;
- struct GNUNET_CURL_Context *ctx;
- json_t *deposit_obj;
- CURL *eh;
- const struct TALER_EXCHANGE_DenomPublicKey *dki;
- struct TALER_Amount amount_without_fee;
- char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
-
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
- if (GNUNET_TIME_timestamp_cmp (dcd->refund_deadline,
- >,
- dcd->wire_deadline))
- {
- GNUNET_break_op (0);
- *ec = TALER_EC_EXCHANGE_DEPOSIT_REFUND_DEADLINE_AFTER_WIRE_DEADLINE;
- return NULL;
- }
- {
- char pub_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (
- &cdd->coin_pub,
- sizeof (struct TALER_CoinSpendPublicKeyP),
- pub_str,
- sizeof (pub_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "/coins/%s/deposit",
- pub_str);
- }
- key_state = TALER_EXCHANGE_get_keys (exchange);
- dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
- &cdd->h_denom_pub);
- if (NULL == dki)
- {
- *ec = TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
- GNUNET_break_op (0);
- return NULL;
- }
- if (0 >
- TALER_amount_subtract (&amount_without_fee,
- &cdd->amount,
- &dki->fees.deposit))
- {
- *ec = TALER_EC_EXCHANGE_DEPOSIT_FEE_ABOVE_AMOUNT;
- GNUNET_break_op (0);
- return NULL;
- }
- dh = GNUNET_new (struct TALER_EXCHANGE_DepositHandle);
- dh->auditor_chance = AUDITOR_CHANCE;
- dh->exchange = exchange;
- dh->cb = cb;
- dh->cb_cls = cb_cls;
- dh->cdd = *cdd;
- dh->dcd = *dcd;
- if (NULL != dcd->extension_details)
- TALER_deposit_extension_hash (dcd->extension_details,
- &dh->h_extensions);
- TALER_merchant_wire_signature_hash (dcd->merchant_payto_uri,
- &dcd->wire_salt,
- &dh->h_wire);
- if (GNUNET_OK !=
- TALER_EXCHANGE_verify_deposit_signature_ (dcd,
- &dh->h_extensions,
- &dh->h_wire,
- cdd,
- dki))
- {
- *ec = TALER_EC_EXCHANGE_DEPOSIT_COIN_SIGNATURE_INVALID;
- GNUNET_break_op (0);
- GNUNET_free (dh);
- return NULL;
- }
- dh->url = TEAH_path_to_url (exchange,
- arg_str);
- if (NULL == dh->url)
- {
- GNUNET_break (0);
- *ec = TALER_EC_GENERIC_ALLOCATION_FAILURE;
- GNUNET_free (dh->url);
- GNUNET_free (dh);
- return NULL;
- }
-
- deposit_obj = GNUNET_JSON_PACK (
- TALER_JSON_pack_amount ("contribution",
- &cdd->amount),
- GNUNET_JSON_pack_string ("merchant_payto_uri",
- dcd->merchant_payto_uri),
- GNUNET_JSON_pack_data_auto ("wire_salt",
- &dcd->wire_salt),
- GNUNET_JSON_pack_data_auto ("h_contract_terms",
- &dcd->h_contract_terms),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_data_auto ("h_age_commitment",
- &cdd->h_age_commitment)),
- GNUNET_JSON_pack_data_auto ("denom_pub_hash",
- &cdd->h_denom_pub),
- TALER_JSON_pack_denom_sig ("ub_sig",
- &cdd->denom_sig),
- GNUNET_JSON_pack_timestamp ("timestamp",
- dcd->timestamp),
- GNUNET_JSON_pack_data_auto ("merchant_pub",
- &dcd->merchant_pub),
- GNUNET_JSON_pack_allow_null (
- GNUNET_JSON_pack_timestamp ("refund_deadline",
- dcd->refund_deadline)),
- GNUNET_JSON_pack_timestamp ("wire_transfer_deadline",
- dcd->wire_deadline),
- GNUNET_JSON_pack_data_auto ("coin_sig",
- &cdd->coin_sig));
- GNUNET_assert (NULL != deposit_obj);
- eh = TALER_EXCHANGE_curl_easy_get_ (dh->url);
- if ( (NULL == eh) ||
- (GNUNET_OK !=
- TALER_curl_easy_post (&dh->ctx,
- eh,
- deposit_obj)) )
- {
- *ec = TALER_EC_GENERIC_CURL_ALLOCATION_FAILURE;
- GNUNET_break (0);
- if (NULL != eh)
- curl_easy_cleanup (eh);
- json_decref (deposit_obj);
- GNUNET_free (dh->url);
- GNUNET_free (dh);
- return NULL;
- }
- json_decref (deposit_obj);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "URL for deposit: `%s'\n",
- dh->url);
- ctx = TEAH_handle_to_context (exchange);
- dh->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- dh->ctx.headers,
- &handle_deposit_finished,
- dh);
- return dh;
-}
-
-
-void
-TALER_EXCHANGE_deposit_force_dc (struct TALER_EXCHANGE_DepositHandle *deposit)
-{
- deposit->auditor_chance = 1;
-}
-
-
-void
-TALER_EXCHANGE_deposit_cancel (struct TALER_EXCHANGE_DepositHandle *deposit)
-{
- if (NULL != deposit->job)
- {
- GNUNET_CURL_job_cancel (deposit->job);
- deposit->job = NULL;
- }
- GNUNET_free (deposit->url);
- TALER_curl_easy_post_finished (&deposit->ctx);
- GNUNET_free (deposit);
-}
-
-
-/* end of exchange_api_deposit.c */
diff --git a/src/lib/exchange_api_deposits_get.c b/src/lib/exchange_api_deposits_get.c
index 660323bc4..20eaea3d3 100644
--- a/src/lib/exchange_api_deposits_get.c
+++ b/src/lib/exchange_api_deposits_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -39,9 +39,9 @@ struct TALER_EXCHANGE_DepositGetHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -80,77 +80,15 @@ struct TALER_EXCHANGE_DepositGetHandle
struct TALER_PrivateContractHashP h_contract_terms;
/**
- * Raw value (binary encoding) of the wire transfer subject.
- */
- struct TALER_WireTransferIdentifierRawP wtid;
-
- /**
* The coin's public key. This is the value that must have been
* signed (blindly) by the Exchange.
*/
struct TALER_CoinSpendPublicKeyP coin_pub;
- /**
- * When did the exchange execute this transfer? Note that the
- * timestamp may not be exactly the same on the wire, i.e.
- * because the wire has a different timezone or resolution.
- */
- struct GNUNET_TIME_Timestamp execution_time;
-
- /**
- * The contribution of @e coin_pub to the total transfer volume.
- * This is the value of the deposit minus the fee.
- */
- struct TALER_Amount coin_contribution;
-
};
/**
- * Verify that the signature on the "200 OK" response
- * from the exchange is valid.
- *
- * @param dwh deposit wtid handle
- * @param exchange_pub the exchange's public key
- * @param exchange_sig the exchange's signature
- * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
- */
-// FIXME: inline...
-static enum GNUNET_GenericReturnValue
-verify_deposit_wtid_signature_ok (
- const struct TALER_EXCHANGE_DepositGetHandle *dwh,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_ExchangeSignatureP *exchange_sig)
-{
- const struct TALER_EXCHANGE_Keys *key_state;
-
- key_state = TALER_EXCHANGE_get_keys (dwh->exchange);
- if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- exchange_pub))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_exchange_online_confirm_wire_verify (
- &dwh->h_wire,
- &dwh->h_contract_terms,
- &dwh->wtid,
- &dwh->coin_pub,
- dwh->execution_time,
- &dwh->coin_contribution,
- exchange_pub,
- exchange_sig))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
* Function called when we're done processing the
* HTTP /track/transaction request.
*
@@ -180,18 +118,21 @@ handle_deposit_wtid_finished (void *cls,
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("wtid",
- &dr.details.success.wtid),
+ &dr.details.ok.wtid),
GNUNET_JSON_spec_timestamp ("execution_time",
- &dr.details.success.execution_time),
+ &dr.details.ok.execution_time),
TALER_JSON_spec_amount_any ("coin_contribution",
- &dr.details.success.coin_contribution),
+ &dr.details.ok.coin_contribution),
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &dr.details.success.exchange_sig),
+ &dr.details.ok.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &dr.details.success.exchange_pub),
+ &dr.details.ok.exchange_pub),
GNUNET_JSON_spec_end ()
};
+ const struct TALER_EXCHANGE_Keys *key_state;
+ key_state = dwh->keys;
+ GNUNET_assert (NULL != key_state);
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
spec,
@@ -202,14 +143,25 @@ handle_deposit_wtid_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- // FIXME: remove once we inline function below...
- dwh->execution_time = dr.details.success.execution_time;
- dwh->wtid = dr.details.success.wtid;
- dwh->coin_contribution = dr.details.success.coin_contribution;
if (GNUNET_OK !=
- verify_deposit_wtid_signature_ok (dwh,
- &dr.details.success.exchange_pub,
- &dr.details.success.exchange_sig))
+ TALER_EXCHANGE_test_signing_key (key_state,
+ &dr.details.ok.exchange_pub))
+ {
+ GNUNET_break_op (0);
+ dr.hr.http_status = 0;
+ dr.hr.ec = TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_SIGNATURE_BY_EXCHANGE;
+ break;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_confirm_wire_verify (
+ &dwh->h_wire,
+ &dwh->h_contract_terms,
+ &dr.details.ok.wtid,
+ &dwh->coin_pub,
+ dr.details.ok.execution_time,
+ &dr.details.ok.coin_contribution,
+ &dr.details.ok.exchange_pub,
+ &dr.details.ok.exchange_sig))
{
GNUNET_break_op (0);
dr.hr.http_status = 0;
@@ -224,11 +176,16 @@ handle_deposit_wtid_finished (void *cls,
case MHD_HTTP_ACCEPTED:
{
/* Transaction known, but not executed yet */
+ bool no_legi = false;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_timestamp ("execution_time",
&dr.details.accepted.execution_time),
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &dr.details.accepted.payment_target_uuid),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_uint64 ("requirement_row",
+ &dr.details.accepted.requirement_row),
+ &no_legi),
+ TALER_JSON_spec_aml_decision ("aml_decision",
+ &dr.details.accepted.aml_decision),
GNUNET_JSON_spec_bool ("kyc_ok",
&dr.details.accepted.kyc_ok),
GNUNET_JSON_spec_end ()
@@ -244,6 +201,8 @@ handle_deposit_wtid_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
+ if (no_legi)
+ dr.details.accepted.requirement_row = 0;
dwh->cb (dwh->cb_cls,
&dr);
TALER_EXCHANGE_deposits_get_cancel (dwh);
@@ -293,31 +252,30 @@ handle_deposit_wtid_finished (void *cls,
struct TALER_EXCHANGE_DepositGetHandle *
TALER_EXCHANGE_deposits_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_MerchantPrivateKeyP *merchant_priv,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_DepositGetCallback cb,
void *cb_cls)
{
struct TALER_MerchantPublicKeyP merchant;
struct TALER_MerchantSignatureP merchant_sig;
struct TALER_EXCHANGE_DepositGetHandle *dwh;
- struct GNUNET_CURL_Context *ctx;
CURL *eh;
char arg_str[(sizeof (struct TALER_CoinSpendPublicKeyP)
+ sizeof (struct TALER_MerchantWireHashP)
+ sizeof (struct TALER_MerchantPublicKeyP)
+ sizeof (struct TALER_PrivateContractHashP)
+ sizeof (struct TALER_MerchantSignatureP)) * 2 + 48];
+ unsigned int tms
+ = (unsigned int) timeout.rel_value_us
+ / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv,
&merchant.eddsa_pub);
TALER_merchant_deposit_sign (h_contract_terms,
@@ -331,6 +289,7 @@ TALER_EXCHANGE_deposits_get (
char msig_str[sizeof (struct TALER_MerchantSignatureP) * 2];
char chash_str[sizeof (struct TALER_PrivateContractHashP) * 2];
char whash_str[sizeof (struct TALER_MerchantWireHashP) * 2];
+ char timeout_str[24];
char *end;
end = GNUNET_STRINGS_data_to_string (h_wire,
@@ -358,23 +317,39 @@ TALER_EXCHANGE_deposits_get (
msig_str,
sizeof (msig_str));
*end = '\0';
+ if (GNUNET_TIME_relative_is_zero (timeout))
+ {
+ timeout_str[0] = '\0';
+ }
+ else
+ {
+ GNUNET_snprintf (
+ timeout_str,
+ sizeof (timeout_str),
+ "%u",
+ tms);
+ }
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/deposits/%s/%s/%s/%s?merchant_sig=%s",
+ "deposits/%s/%s/%s/%s?merchant_sig=%s%s%s",
whash_str,
mpub_str,
chash_str,
cpub_str,
- msig_str);
+ msig_str,
+ 0 == tms
+ ? ""
+ : "&timeout_ms=",
+ timeout_str);
}
dwh = GNUNET_new (struct TALER_EXCHANGE_DepositGetHandle);
- dwh->exchange = exchange;
dwh->cb = cb;
dwh->cb_cls = cb_cls;
- dwh->url = TEAH_path_to_url (exchange,
- arg_str);
+ dwh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == dwh->url)
{
GNUNET_free (dwh);
@@ -383,7 +358,6 @@ TALER_EXCHANGE_deposits_get (
dwh->h_wire = *h_wire;
dwh->h_contract_terms = *h_contract_terms;
dwh->coin_pub = *coin_pub;
-
eh = TALER_EXCHANGE_curl_easy_get_ (dwh->url);
if (NULL == eh)
{
@@ -392,11 +366,18 @@ TALER_EXCHANGE_deposits_get (
GNUNET_free (dwh);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
+ if (0 != tms)
+ {
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_TIMEOUT_MS,
+ (long) (tms + 100L)));
+ }
dwh->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_deposit_wtid_finished,
dwh);
+ dwh->keys = TALER_EXCHANGE_keys_incref (keys);
return dwh;
}
@@ -411,6 +392,7 @@ TALER_EXCHANGE_deposits_get_cancel (struct TALER_EXCHANGE_DepositGetHandle *dwh)
}
GNUNET_free (dwh->url);
TALER_curl_easy_post_finished (&dwh->ctx);
+ TALER_EXCHANGE_keys_decref (dwh->keys);
GNUNET_free (dwh);
}
diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c
index 488a419be..fdadc8d2a 100644
--- a/src/lib/exchange_api_handle.c
+++ b/src/lib/exchange_api_handle.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
@@ -40,12 +40,17 @@
* Which version of the Taler protocol is implemented
* by this library? Used to determine compatibility.
*/
-#define EXCHANGE_PROTOCOL_CURRENT 14
+#define EXCHANGE_PROTOCOL_CURRENT 19
/**
* How many versions are we backwards compatible with?
*/
-#define EXCHANGE_PROTOCOL_AGE 0
+#define EXCHANGE_PROTOCOL_AGE 2
+
+/**
+ * Set to 1 for extra debug logging.
+ */
+#define DEBUG 0
/**
* Current version for (local) JSON serialization of persisted
@@ -54,7 +59,7 @@
#define EXCHANGE_SERIALIZATION_FORMAT_VERSION 0
/**
- * How far off do we allow key liftimes to be?
+ * How far off do we allow key lifetimes to be?
*/
#define LIFETIME_TOLERANCE GNUNET_TIME_UNIT_HOURS
@@ -65,175 +70,311 @@
#define DEFAULT_EXPIRATION GNUNET_TIME_UNIT_HOURS
/**
- * Set to 1 for extra debug logging.
- */
-#define DEBUG 0
-
-/**
- * Log error related to CURL operations.
- *
- * @param type log level
- * @param function which function failed to run
- * @param code what was the curl error code
- */
-#define CURL_STRERROR(type, function, code) \
- GNUNET_log (type, "Curl function `%s' has failed at `%s:%d' with error: %s", \
- function, __FILE__, __LINE__, curl_easy_strerror (code));
-
-
-/**
- * Data for the request to get the /keys of a exchange.
+ * If the "Expire" cache control header is missing, for
+ * how long do we assume the reply to be valid at least?
*/
-struct KeysRequest;
+#define MINIMUM_EXPIRATION GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_MINUTES, 2)
/**
- * Entry in DLL of auditors used by an exchange.
+ * Handle for a GET /keys request.
*/
-struct TEAH_AuditorListEntry
+struct TALER_EXCHANGE_GetKeysHandle
{
- /**
- * Next pointer of DLL.
- */
- struct TEAH_AuditorListEntry *next;
/**
- * Prev pointer of DLL.
+ * The exchange base URL (i.e. "https://exchange.demo.taler.net/")
*/
- struct TEAH_AuditorListEntry *prev;
+ char *exchange_url;
/**
- * Base URL of the auditor.
+ * The url for the /keys request.
*/
- char *auditor_url;
+ char *url;
/**
- * Handle to the auditor.
+ * Previous /keys response, NULL for none.
*/
- struct TALER_AUDITOR_Handle *ah;
+ struct TALER_EXCHANGE_Keys *prev_keys;
/**
- * Head of DLL of interactions with this auditor.
+ * Entry for this request with the `struct GNUNET_CURL_Context`.
*/
- struct TEAH_AuditorInteractionEntry *ai_head;
+ struct GNUNET_CURL_Job *job;
/**
- * Tail of DLL of interactions with this auditor.
+ * Expiration time according to "Expire:" header.
+ * 0 if not provided by the server.
*/
- struct TEAH_AuditorInteractionEntry *ai_tail;
+ struct GNUNET_TIME_Timestamp expire;
/**
- * Public key of the auditor.
+ * Function to call with the exchange's certification data,
+ * NULL if this has already been done.
*/
- struct TALER_AuditorPublicKeyP auditor_pub;
+ TALER_EXCHANGE_GetKeysCallback cert_cb;
/**
- * Flag indicating that the auditor is available and that protocol
- * version compatibility is given.
+ * Closure to pass to @e cert_cb.
*/
- bool is_up;
+ void *cert_cb_cls;
};
-/* ***************** Internal /keys fetching ************* */
-
/**
- * Data for the request to get the /keys of a exchange.
+ * Element in the `struct SignatureContext` array.
*/
-struct KeysRequest
+struct SignatureElement
{
+
/**
- * The connection to exchange this request handle will use
+ * Offset of the denomination in the group array,
+ * for sorting (2nd rank, ascending).
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ unsigned int offset;
/**
- * The url for this handle
+ * Offset of the group in the denominations array,
+ * for sorting (2nd rank, ascending).
*/
- char *url;
+ unsigned int group_offset;
/**
- * Entry for this request with the `struct GNUNET_CURL_Context`.
+ * Pointer to actual master signature to hash over.
*/
- struct GNUNET_CURL_Job *job;
+ struct TALER_MasterSignatureP master_sig;
+};
+/**
+ * Context for collecting the array of master signatures
+ * needed to verify the exchange_sig online signature.
+ */
+struct SignatureContext
+{
/**
- * Expiration time according to "Expire:" header.
- * 0 if not provided by the server.
+ * Array of signatures to hash over.
*/
- struct GNUNET_TIME_Timestamp expire;
+ struct SignatureElement *elements;
+
+ /**
+ * Write offset in the @e elements array.
+ */
+ unsigned int elements_pos;
+ /**
+ * Allocated space for @e elements.
+ */
+ unsigned int elements_size;
};
-void
-TEAH_acc_confirmation_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr)
+/**
+ * Determine order to sort two elements by before
+ * we hash the master signatures. Used for
+ * sorting with qsort().
+ *
+ * @param a pointer to a `struct SignatureElement`
+ * @param b pointer to a `struct SignatureElement`
+ * @return 0 if equal, -1 if a < b, 1 if a > b.
+ */
+static int
+signature_context_sort_cb (const void *a,
+ const void *b)
{
- struct TEAH_AuditorInteractionEntry *aie = cls;
- struct TEAH_AuditorListEntry *ale = aie->ale;
+ const struct SignatureElement *sa = a;
+ const struct SignatureElement *sb = b;
- if (MHD_HTTP_OK != hr->http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to submit deposit confirmation to auditor `%s' with HTTP status %d (EC: %d). This is acceptable if it does not happen often.\n",
- ale->auditor_url,
- hr->http_status,
- hr->ec);
- }
- GNUNET_CONTAINER_DLL_remove (ale->ai_head,
- ale->ai_tail,
- aie);
- GNUNET_free (aie);
+ if (sa->group_offset < sb->group_offset)
+ return -1;
+ if (sa->group_offset > sb->group_offset)
+ return 1;
+ if (sa->offset < sb->offset)
+ return -1;
+ if (sa->offset > sb->offset)
+ return 1;
+ /* We should never have two disjoint elements
+ with same time and offset */
+ GNUNET_assert (sa == sb);
+ return 0;
}
-void
-TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h,
- TEAH_AuditorCallback ac,
- void *ac_cls)
+/**
+ * Append a @a master_sig to the @a sig_ctx using the
+ * given attributes for (later) sorting.
+ *
+ * @param[in,out] sig_ctx signature context to update
+ * @param group_offset offset for the group
+ * @param offset offset for the entry
+ * @param master_sig master signature for the entry
+ */
+static void
+append_signature (struct SignatureContext *sig_ctx,
+ unsigned int group_offset,
+ unsigned int offset,
+ const struct TALER_MasterSignatureP *master_sig)
{
- if (NULL == h->auditors_head)
+ struct SignatureElement *element;
+ unsigned int new_size;
+
+ if (sig_ctx->elements_pos == sig_ctx->elements_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "No auditor available for exchange `%s'. Not submitting deposit confirmations.\n",
- h->url);
- return;
+ if (0 == sig_ctx->elements_size)
+ new_size = 1024;
+ else
+ new_size = sig_ctx->elements_size * 2;
+ GNUNET_array_grow (sig_ctx->elements,
+ sig_ctx->elements_size,
+ new_size);
}
- for (struct TEAH_AuditorListEntry *ale = h->auditors_head;
- NULL != ale;
- ale = ale->next)
+ element = &sig_ctx->elements[sig_ctx->elements_pos++];
+ element->offset = offset;
+ element->group_offset = group_offset;
+ element->master_sig = *master_sig;
+}
+
+
+/**
+ * Frees @a wfm array.
+ *
+ * @param wfm fee array to release
+ * @param wfm_len length of the @a wfm array
+ */
+static void
+free_fees (struct TALER_EXCHANGE_WireFeesByMethod *wfm,
+ unsigned int wfm_len)
+{
+ for (unsigned int i = 0; i<wfm_len; i++)
{
- struct TEAH_AuditorInteractionEntry *aie;
+ struct TALER_EXCHANGE_WireFeesByMethod *wfmi = &wfm[i];
- if (! ale->is_up)
- continue;
- aie = ac (ac_cls,
- ale->ah,
- &ale->auditor_pub);
- if (NULL != aie)
+ while (NULL != wfmi->fees_head)
{
- aie->ale = ale;
- GNUNET_CONTAINER_DLL_insert (ale->ai_head,
- ale->ai_tail,
- aie);
+ struct TALER_EXCHANGE_WireAggregateFees *fe
+ = wfmi->fees_head;
+
+ wfmi->fees_head = fe->next;
+ GNUNET_free (fe);
}
+ GNUNET_free (wfmi->method);
}
+ GNUNET_free (wfm);
}
/**
- * Release memory occupied by a keys request. Note that this does not
- * cancel the request itself.
+ * Parse wire @a fees and return array.
*
- * @param kr request to free
+ * @param master_pub master public key to use to check signatures
+ * @param currency currency amounts are expected in
+ * @param fees json AggregateTransferFee to parse
+ * @param[out] fees_len set to length of returned array
+ * @return NULL on error
*/
-static void
-free_keys_request (struct KeysRequest *kr)
+static struct TALER_EXCHANGE_WireFeesByMethod *
+parse_fees (const struct TALER_MasterPublicKeyP *master_pub,
+ const char *currency,
+ const json_t *fees,
+ unsigned int *fees_len)
+{
+ struct TALER_EXCHANGE_WireFeesByMethod *fbm;
+ size_t fbml = json_object_size (fees);
+ unsigned int i = 0;
+ const char *key;
+ const json_t *fee_array;
+
+ if (UINT_MAX < fbml)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ fbm = GNUNET_new_array (fbml,
+ struct TALER_EXCHANGE_WireFeesByMethod);
+ *fees_len = (unsigned int) fbml;
+ json_object_foreach ((json_t *) fees, key, fee_array) {
+ struct TALER_EXCHANGE_WireFeesByMethod *fe = &fbm[i++];
+ size_t idx;
+ json_t *fee;
+
+ fe->method = GNUNET_strdup (key);
+ fe->fees_head = NULL;
+ json_array_foreach (fee_array, idx, fee)
+ {
+ struct TALER_EXCHANGE_WireAggregateFees *wa
+ = GNUNET_new (struct TALER_EXCHANGE_WireAggregateFees);
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("sig",
+ &wa->master_sig),
+ TALER_JSON_spec_amount ("wire_fee",
+ currency,
+ &wa->fees.wire),
+ TALER_JSON_spec_amount ("closing_fee",
+ currency,
+ &wa->fees.closing),
+ GNUNET_JSON_spec_timestamp ("start_date",
+ &wa->start_date),
+ GNUNET_JSON_spec_timestamp ("end_date",
+ &wa->end_date),
+ GNUNET_JSON_spec_end ()
+ };
+
+ wa->next = fe->fees_head;
+ fe->fees_head = wa;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (fee,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ free_fees (fbm,
+ i);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_offline_wire_fee_verify (
+ key,
+ wa->start_date,
+ wa->end_date,
+ &wa->fees,
+ master_pub,
+ &wa->master_sig))
+ {
+ GNUNET_break_op (0);
+ free_fees (fbm,
+ i);
+ return NULL;
+ }
+ } /* for all fees over time */
+ } /* for all methods */
+ GNUNET_assert (i == fbml);
+ return fbm;
+}
+
+
+void
+TEAH_get_auditors_for_dc (
+ struct TALER_EXCHANGE_Keys *keys,
+ TEAH_AuditorCallback ac,
+ void *ac_cls)
{
- GNUNET_free (kr->url);
- GNUNET_free (kr);
+ if (0 == keys->num_auditors)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "No auditor available. Not submitting deposit confirmations.\n");
+ return;
+ }
+ for (unsigned int i = 0; i<keys->num_auditors; i++)
+ {
+ const struct TALER_EXCHANGE_AuditorInformation *auditor
+ = &keys->auditors[i];
+
+ ac (ac_cls,
+ auditor->auditor_url,
+ &auditor->auditor_pub);
+ }
}
@@ -248,21 +389,20 @@ free_keys_request (struct KeysRequest *kr)
*
* @param[out] sign_key where to return the result
* @param check_sigs should we check signatures?
- * @param[in] sign_key_obj json to parse
+ * @param sign_key_obj json to parse
* @param master_key master key to use to verify signature
* @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is
- * invalid or the json malformed.
+ * invalid or the @a sign_key_obj is malformed.
*/
static enum GNUNET_GenericReturnValue
parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key,
bool check_sigs,
- json_t *sign_key_obj,
+ const json_t *sign_key_obj,
const struct TALER_MasterPublicKeyP *master_key)
{
- struct TALER_MasterSignatureP sign_key_issue_sig;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("master_sig",
- &sign_key_issue_sig),
+ &sign_key->master_sig),
GNUNET_JSON_spec_fixed_auto ("key",
&sign_key->key),
GNUNET_JSON_spec_timestamp ("stamp_start",
@@ -282,7 +422,6 @@ parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
-
if (! check_sigs)
return GNUNET_OK;
if (GNUNET_OK !=
@@ -292,12 +431,11 @@ parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key,
sign_key->valid_until,
sign_key->valid_legal,
master_key,
- &sign_key_issue_sig))
+ &sign_key->master_sig))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- sign_key->master_sig = sign_key_issue_sig;
return GNUNET_OK;
}
@@ -310,24 +448,28 @@ parse_json_signkey (struct TALER_EXCHANGE_SigningPublicKey *sign_key,
* prior to calling this function, otherwise the signature verification
* performed within this function will fail.
*
- * @param currency expected currency of all fees
* @param[out] denom_key where to return the result
* @param cipher cipher type to parse
* @param check_sigs should we check signatures?
- * @param[in] denom_key_obj json to parse
+ * @param denom_key_obj json to parse
* @param master_key master key to use to verify signature
- * @param hash_xor where to accumulate data for signature verification via XOR
+ * @param group_offset offset for the group
+ * @param index index of this denomination key in the group
+ * @param sig_ctx where to write details about encountered
+ * master signatures, NULL if not used
* @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is
* invalid or the json malformed.
*/
static enum GNUNET_GenericReturnValue
-parse_json_denomkey_partially (const char *currency,
- struct TALER_EXCHANGE_DenomPublicKey *denom_key,
- enum TALER_DenominationCipher cipher,
- bool check_sigs,
- json_t *denom_key_obj,
- struct TALER_MasterPublicKeyP *master_key,
- struct GNUNET_HashCode *hash_xor)
+parse_json_denomkey_partially (
+ struct TALER_EXCHANGE_DenomPublicKey *denom_key,
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
+ bool check_sigs,
+ const json_t *denom_key_obj,
+ struct TALER_MasterPublicKeyP *master_key,
+ unsigned int group_offset,
+ unsigned int index,
+ struct SignatureContext *sig_ctx)
{
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("master_sig",
@@ -340,6 +482,10 @@ parse_json_denomkey_partially (const char *currency,
&denom_key->valid_from),
GNUNET_JSON_spec_timestamp ("stamp_expire_legal",
&denom_key->expire_legal),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool ("lost",
+ &denom_key->lost),
+ NULL),
TALER_JSON_spec_denom_pub_cipher (NULL,
cipher,
&denom_key->key),
@@ -356,11 +502,11 @@ parse_json_denomkey_partially (const char *currency,
}
TALER_denom_pub_hash (&denom_key->key,
&denom_key->h_key);
- if (NULL != hash_xor)
- GNUNET_CRYPTO_hash_xor (&denom_key->h_key.hash,
- hash_xor,
- hash_xor);
-
+ if (NULL != sig_ctx)
+ append_signature (sig_ctx,
+ group_offset,
+ index,
+ &denom_key->master_sig);
if (! check_sigs)
return GNUNET_OK;
EXITIF (GNUNET_SYSERR ==
@@ -376,11 +522,11 @@ parse_json_denomkey_partially (const char *currency,
&denom_key->master_sig));
return GNUNET_OK;
EXITIF_exit:
+ GNUNET_JSON_parse_free (spec);
/* invalidate denom_key, just to be sure */
memset (denom_key,
0,
sizeof (*denom_key));
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -390,7 +536,7 @@ EXITIF_exit:
*
* @param[out] auditor where to return the result
* @param check_sigs should we check signatures
- * @param[in] auditor_obj json to parse
+ * @param auditor_obj json to parse
* @param key_data information about denomination keys
* @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is
* invalid or the json malformed.
@@ -398,22 +544,21 @@ EXITIF_exit:
static enum GNUNET_GenericReturnValue
parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
bool check_sigs,
- json_t *auditor_obj,
+ const json_t *auditor_obj,
const struct TALER_EXCHANGE_Keys *key_data)
{
- json_t *keys;
+ const json_t *keys;
json_t *key;
- unsigned int len;
- unsigned int off;
- unsigned int i;
+ size_t off;
+ size_t pos;
const char *auditor_url;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("auditor_pub",
&auditor->auditor_pub),
- GNUNET_JSON_spec_string ("auditor_url",
+ TALER_JSON_spec_web_url ("auditor_url",
&auditor_url),
- GNUNET_JSON_spec_json ("denomination_keys",
- &keys),
+ GNUNET_JSON_spec_array_const ("denomination_keys",
+ &keys),
GNUNET_JSON_spec_end ()
};
@@ -431,16 +576,15 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
return GNUNET_SYSERR;
}
auditor->auditor_url = GNUNET_strdup (auditor_url);
- len = json_array_size (keys);
- auditor->denom_keys = GNUNET_new_array (len,
- struct
- TALER_EXCHANGE_AuditorDenominationInfo);
- off = 0;
- json_array_foreach (keys, i, key) {
+ auditor->denom_keys
+ = GNUNET_new_array (json_array_size (keys),
+ struct TALER_EXCHANGE_AuditorDenominationInfo);
+ pos = 0;
+ json_array_foreach (keys, off, key) {
struct TALER_AuditorSignatureP auditor_sig;
struct TALER_DenominationHashP denom_h;
- const struct TALER_EXCHANGE_DenomPublicKey *dk;
- unsigned int dk_off;
+ const struct TALER_EXCHANGE_DenomPublicKey *dk = NULL;
+ unsigned int dk_off = UINT_MAX;
struct GNUNET_JSON_Specification kspec[] = {
GNUNET_JSON_spec_fixed_auto ("auditor_sig",
&auditor_sig),
@@ -457,8 +601,6 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
GNUNET_break_op (0);
continue;
}
- dk = NULL;
- dk_off = UINT_MAX;
for (unsigned int j = 0; j<key_data->num_denom_keys; j++)
{
if (0 == GNUNET_memcmp (&denom_h,
@@ -493,16 +635,19 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
&auditor_sig))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
}
- auditor->denom_keys[off].denom_key_offset = dk_off;
- auditor->denom_keys[off].auditor_sig = auditor_sig;
- off++;
+ auditor->denom_keys[pos].denom_key_offset = dk_off;
+ auditor->denom_keys[pos].auditor_sig = auditor_sig;
+ pos++;
}
- auditor->num_denom_keys = off;
- GNUNET_JSON_parse_free (spec);
+ if (pos > UINT_MAX)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ auditor->num_denom_keys = (unsigned int) pos;
return GNUNET_OK;
}
@@ -512,7 +657,7 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
*
* @param[out] gf where to return the result
* @param check_sigs should we check signatures
- * @param[in] fee_obj json to parse
+ * @param fee_obj json to parse
* @param key_data already parsed information about the exchange
* @return #GNUNET_OK if all is fine, #GNUNET_SYSERR if the signature is
* invalid or the json malformed.
@@ -520,7 +665,7 @@ parse_json_auditor (struct TALER_EXCHANGE_AuditorInformation *auditor,
static enum GNUNET_GenericReturnValue
parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf,
bool check_sigs,
- json_t *fee_obj,
+ const json_t *fee_obj,
const struct TALER_EXCHANGE_Keys *key_data)
{
struct GNUNET_JSON_Specification spec[] = {
@@ -530,8 +675,6 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf,
&gf->end_date),
GNUNET_JSON_spec_relative_time ("purse_timeout",
&gf->purse_timeout),
- GNUNET_JSON_spec_relative_time ("account_kyc_timeout",
- &gf->kyc_timeout),
GNUNET_JSON_spec_relative_time ("history_expiration",
&gf->history_expiration),
GNUNET_JSON_spec_uint32 ("purse_account_limit",
@@ -564,7 +707,6 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf,
gf->end_date,
&gf->fees,
gf->purse_timeout,
- gf->kyc_timeout,
gf->history_expiration,
gf->purse_account_limit,
&key_data->master_pub,
@@ -581,113 +723,12 @@ parse_global_fee (struct TALER_EXCHANGE_GlobalFee *gf,
/**
- * Function called with information about the auditor. Marks an
- * auditor as 'up'.
- *
- * @param cls closure, a `struct TEAH_AuditorListEntry *`
- * @param hr http response from the auditor
- * @param vi basic information about the auditor
- * @param compat protocol compatibility information
- */
-static void
-auditor_version_cb (
- void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- const struct TALER_AUDITOR_VersionInformation *vi,
- enum TALER_AUDITOR_VersionCompatibility compat)
-{
- struct TEAH_AuditorListEntry *ale = cls;
-
- (void) hr;
- if (NULL == vi)
- {
- /* In this case, we don't mark the auditor as 'up' */
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Auditor `%s' gave unexpected version response.\n",
- ale->auditor_url);
- return;
- }
-
- if (0 != (TALER_AUDITOR_VC_INCOMPATIBLE & compat))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Auditor `%s' runs incompatible protocol version!\n",
- ale->auditor_url);
- if (0 != (TALER_AUDITOR_VC_OLDER & compat))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Auditor `%s' runs outdated protocol version!\n",
- ale->auditor_url);
- }
- if (0 != (TALER_AUDITOR_VC_NEWER & compat))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Auditor `%s' runs more recent incompatible version. We should upgrade!\n",
- ale->auditor_url);
- }
- return;
- }
- ale->is_up = true;
-}
-
-
-/**
- * Recalculate our auditor list, we got /keys and it may have
- * changed.
- *
- * @param exchange exchange for which to update the list.
- */
-static void
-update_auditors (struct TALER_EXCHANGE_Handle *exchange)
-{
- struct TALER_EXCHANGE_Keys *kd = &exchange->key_data;
-
- TALER_LOG_DEBUG ("Updating auditors\n");
- for (unsigned int i = 0; i<kd->num_auditors; i++)
- {
- /* Compare auditor data from /keys with auditor data
- * from owned exchange structures. */
- struct TALER_EXCHANGE_AuditorInformation *auditor = &kd->auditors[i];
- struct TEAH_AuditorListEntry *ale = NULL;
-
- for (struct TEAH_AuditorListEntry *a = exchange->auditors_head;
- NULL != a;
- a = a->next)
- {
- if (0 == GNUNET_memcmp (&auditor->auditor_pub,
- &a->auditor_pub))
- {
- ale = a;
- break;
- }
- }
- if (NULL != ale)
- continue; /* found, no need to add */
-
- /* new auditor, add */
- TALER_LOG_DEBUG ("Found new auditor %s!\n",
- auditor->auditor_url);
- ale = GNUNET_new (struct TEAH_AuditorListEntry);
- ale->auditor_pub = auditor->auditor_pub;
- ale->auditor_url = GNUNET_strdup (auditor->auditor_url);
- GNUNET_CONTAINER_DLL_insert (exchange->auditors_head,
- exchange->auditors_tail,
- ale);
- ale->ah = TALER_AUDITOR_connect (exchange->ctx,
- ale->auditor_url,
- &auditor_version_cb,
- ale);
- }
-}
-
-
-/**
* Compare two denomination keys. Ignores revocation data.
*
* @param denom1 first denomination key
* @param denom2 second denomination key
* @return 0 if the two keys are equal (not necessarily
- * the same object), 1 otherwise.
+ * the same object), non-zero otherwise.
*/
static unsigned int
denoms_cmp (const struct TALER_EXCHANGE_DenomPublicKey *denom1,
@@ -732,29 +773,21 @@ decode_keys_json (const json_t *resp_obj,
struct TALER_EXCHANGE_Keys *key_data,
enum TALER_EXCHANGE_VersionCompatibility *vc)
{
- struct TALER_ExchangeSignatureP denominations_sig;
- struct GNUNET_HashCode hash_xor = {0};
- struct TALER_ExchangePublicKeyP pub;
- const char *currency;
- struct GNUNET_JSON_Specification mspec[] = {
- GNUNET_JSON_spec_fixed_auto ("denominations_sig",
- &denominations_sig),
- GNUNET_JSON_spec_fixed_auto ("eddsa_pub",
- &pub),
- GNUNET_JSON_spec_fixed_auto ("master_public_key",
- &key_data->master_pub),
- GNUNET_JSON_spec_timestamp ("list_issue_date",
- &key_data->list_issue_date),
- GNUNET_JSON_spec_relative_time ("reserve_closing_delay",
- &key_data->reserve_closing_delay),
- GNUNET_JSON_spec_string ("currency",
- &currency),
- GNUNET_JSON_spec_mark_optional (
- TALER_JSON_spec_amount_any ("wallet_balance_limit_without_kyc",
- &key_data->wallet_balance_limit_without_kyc),
- NULL),
- GNUNET_JSON_spec_end ()
- };
+ struct TALER_ExchangeSignatureP exchange_sig;
+ struct TALER_ExchangePublicKeyP exchange_pub;
+ const json_t *wblwk = NULL;
+ const json_t *global_fees;
+ const json_t *sign_keys_array;
+ const json_t *denominations_by_group;
+ const json_t *auditors_array;
+ const json_t *recoup_array = NULL;
+ const json_t *manifests = NULL;
+ bool no_extensions = false;
+ bool no_signature = false;
+ const json_t *accounts;
+ const json_t *fees;
+ const json_t *wads;
+ struct SignatureContext sig_ctx = { 0 };
if (JSON_OBJECT != json_typeof (resp_obj))
{
@@ -768,14 +801,10 @@ decode_keys_json (const json_t *resp_obj,
#endif
/* check the version first */
{
- const char *ver;
- unsigned int age;
- unsigned int revision;
- unsigned int current;
- char dummy;
+ struct TALER_JSON_ProtocolVersion pv;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("version",
- &ver),
+ TALER_JSON_spec_version ("version",
+ &pv),
GNUNET_JSON_spec_end ()
};
@@ -787,278 +816,378 @@ decode_keys_json (const json_t *resp_obj,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (3 != sscanf (ver,
- "%u:%u:%u%c",
- &current,
- &revision,
- &age,
- &dummy))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
*vc = TALER_EXCHANGE_VC_MATCH;
- if (EXCHANGE_PROTOCOL_CURRENT < current)
+ if (EXCHANGE_PROTOCOL_CURRENT < pv.current)
{
*vc |= TALER_EXCHANGE_VC_NEWER;
- if (EXCHANGE_PROTOCOL_CURRENT < current - age)
+ if (EXCHANGE_PROTOCOL_CURRENT < pv.current - pv.age)
*vc |= TALER_EXCHANGE_VC_INCOMPATIBLE;
}
- if (EXCHANGE_PROTOCOL_CURRENT > current)
+ if (EXCHANGE_PROTOCOL_CURRENT > pv.current)
{
*vc |= TALER_EXCHANGE_VC_OLDER;
- if (EXCHANGE_PROTOCOL_CURRENT - EXCHANGE_PROTOCOL_AGE > current)
+ if (EXCHANGE_PROTOCOL_CURRENT - EXCHANGE_PROTOCOL_AGE > pv.current)
*vc |= TALER_EXCHANGE_VC_INCOMPATIBLE;
}
- key_data->version = GNUNET_strdup (ver);
}
- EXITIF (GNUNET_OK !=
- GNUNET_JSON_parse (resp_obj,
- (check_sig) ? mspec : &mspec[2],
- NULL, NULL));
- key_data->currency = GNUNET_strdup (currency);
-
- if (GNUNET_OK ==
- TALER_amount_is_valid (&key_data->wallet_balance_limit_without_kyc))
{
- if (0 != strcasecmp (currency,
- key_data->wallet_balance_limit_without_kyc.currency))
+ const char *ver;
+ const char *currency;
+ const char *asset_type;
+ struct GNUNET_JSON_Specification mspec[] = {
+ GNUNET_JSON_spec_fixed_auto (
+ "exchange_sig",
+ &exchange_sig),
+ GNUNET_JSON_spec_fixed_auto (
+ "exchange_pub",
+ &exchange_pub),
+ GNUNET_JSON_spec_fixed_auto (
+ "master_public_key",
+ &key_data->master_pub),
+ GNUNET_JSON_spec_array_const ("accounts",
+ &accounts),
+ GNUNET_JSON_spec_object_const ("wire_fees",
+ &fees),
+ GNUNET_JSON_spec_array_const ("wads",
+ &wads),
+ GNUNET_JSON_spec_timestamp (
+ "list_issue_date",
+ &key_data->list_issue_date),
+ GNUNET_JSON_spec_relative_time (
+ "reserve_closing_delay",
+ &key_data->reserve_closing_delay),
+ GNUNET_JSON_spec_string (
+ "currency",
+ &currency),
+ GNUNET_JSON_spec_string (
+ "asset_type",
+ &asset_type),
+ GNUNET_JSON_spec_array_const (
+ "global_fees",
+ &global_fees),
+ GNUNET_JSON_spec_array_const (
+ "signkeys",
+ &sign_keys_array),
+ GNUNET_JSON_spec_array_const (
+ "denominations",
+ &denominations_by_group),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const (
+ "recoup",
+ &recoup_array),
+ NULL),
+ GNUNET_JSON_spec_array_const (
+ "auditors",
+ &auditors_array),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_bool (
+ "rewards_allowed",
+ &key_data->rewards_allowed),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_object_const ("extensions",
+ &manifests),
+ &no_extensions),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto (
+ "extensions_sig",
+ &key_data->extensions_sig),
+ &no_signature),
+ GNUNET_JSON_spec_string ("version",
+ &ver),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_array_const (
+ "wallet_balance_limit_without_kyc",
+ &wblwk),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+ const char *emsg;
+ unsigned int eline;
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (resp_obj,
+ (check_sig) ? mspec : &mspec[2],
+ &emsg,
+ &eline))
{
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Parsing /keys failed for `%s' (%u)\n",
+ emsg,
+ eline);
+ EXITIF (1);
+ }
+ {
+ struct GNUNET_JSON_Specification sspec[] = {
+ TALER_JSON_spec_currency_specification (
+ "currency_specification",
+ currency,
+ &key_data->cspec),
+ TALER_JSON_spec_amount (
+ "stefan_abs",
+ currency,
+ &key_data->stefan_abs),
+ TALER_JSON_spec_amount (
+ "stefan_log",
+ currency,
+ &key_data->stefan_log),
+ GNUNET_JSON_spec_double (
+ "stefan_lin",
+ &key_data->stefan_lin),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (resp_obj,
+ sspec,
+ &emsg,
+ &eline))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Parsing /keys failed for `%s' (%u)\n",
+ emsg,
+ eline);
+ EXITIF (1);
+ }
}
+
+ key_data->currency = GNUNET_strdup (currency);
+ key_data->version = GNUNET_strdup (ver);
+ key_data->asset_type = GNUNET_strdup (asset_type);
+ if (! no_extensions)
+ key_data->extensions = json_incref ((json_t *) manifests);
}
/* parse the global fees */
+ EXITIF (json_array_size (global_fees) > UINT_MAX);
+ key_data->num_global_fees
+ = (unsigned int) json_array_size (global_fees);
+ if (0 != key_data->num_global_fees)
{
- json_t *global_fees;
json_t *global_fee;
- unsigned int index;
+ size_t index;
- EXITIF (NULL == (global_fees =
- json_object_get (resp_obj,
- "global_fees")));
- EXITIF (! json_is_array (global_fees));
- if (0 != (key_data->num_global_fees =
- json_array_size (global_fees)))
+ key_data->global_fees
+ = GNUNET_new_array (key_data->num_global_fees,
+ struct TALER_EXCHANGE_GlobalFee);
+ json_array_foreach (global_fees, index, global_fee)
{
- key_data->global_fees
- = GNUNET_new_array (key_data->num_global_fees,
- struct TALER_EXCHANGE_GlobalFee);
- json_array_foreach (global_fees, index, global_fee) {
- EXITIF (GNUNET_SYSERR ==
- parse_global_fee (&key_data->global_fees[index],
- check_sig,
- global_fee,
- key_data));
- }
+ EXITIF (GNUNET_SYSERR ==
+ parse_global_fee (&key_data->global_fees[index],
+ check_sig,
+ global_fee,
+ key_data));
}
}
/* parse the signing keys */
+ EXITIF (json_array_size (sign_keys_array) > UINT_MAX);
+ key_data->num_sign_keys
+ = (unsigned int) json_array_size (sign_keys_array);
+ if (0 != key_data->num_sign_keys)
{
- json_t *sign_keys_array;
json_t *sign_key_obj;
- unsigned int index;
+ size_t index;
- EXITIF (NULL == (sign_keys_array =
- json_object_get (resp_obj,
- "signkeys")));
- EXITIF (! json_is_array (sign_keys_array));
- if (0 != (key_data->num_sign_keys =
- json_array_size (sign_keys_array)))
+ key_data->sign_keys
+ = GNUNET_new_array (key_data->num_sign_keys,
+ struct TALER_EXCHANGE_SigningPublicKey);
+ json_array_foreach (sign_keys_array, index, sign_key_obj) {
+ EXITIF (GNUNET_SYSERR ==
+ parse_json_signkey (&key_data->sign_keys[index],
+ check_sig,
+ sign_key_obj,
+ &key_data->master_pub));
+ }
+ }
+
+ /* Parse balance limits */
+ if (NULL != wblwk)
+ {
+ EXITIF (json_array_size (wblwk) > UINT_MAX);
+ key_data->wblwk_length
+ = (unsigned int) json_array_size (wblwk);
+ key_data->wallet_balance_limit_without_kyc
+ = GNUNET_new_array (key_data->wblwk_length,
+ struct TALER_Amount);
+ for (unsigned int i = 0; i<key_data->wblwk_length; i++)
{
- key_data->sign_keys
- = GNUNET_new_array (key_data->num_sign_keys,
- struct TALER_EXCHANGE_SigningPublicKey);
- json_array_foreach (sign_keys_array, index, sign_key_obj) {
- EXITIF (GNUNET_SYSERR ==
- parse_json_signkey (&key_data->sign_keys[index],
- check_sig,
- sign_key_obj,
- &key_data->master_pub));
- }
+ struct TALER_Amount *a = &key_data->wallet_balance_limit_without_kyc[i];
+ const json_t *aj = json_array_get (wblwk,
+ i);
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount (NULL,
+ key_data->currency,
+ a),
+ GNUNET_JSON_spec_end ()
+ };
+
+ EXITIF (GNUNET_OK !=
+ GNUNET_JSON_parse (aj,
+ spec,
+ NULL, NULL));
}
}
+ /* Parse wire accounts */
+ key_data->fees = parse_fees (&key_data->master_pub,
+ key_data->currency,
+ fees,
+ &key_data->fees_len);
+ EXITIF (NULL == key_data->fees);
+ /* parse accounts */
+ EXITIF (json_array_size (accounts) > UINT_MAX);
+ GNUNET_array_grow (key_data->accounts,
+ key_data->accounts_len,
+ json_array_size (accounts));
+ EXITIF (GNUNET_OK !=
+ TALER_EXCHANGE_parse_accounts (&key_data->master_pub,
+ accounts,
+ key_data->accounts_len,
+ key_data->accounts));
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Parsed %u wire accounts from JSON\n",
+ key_data->accounts_len);
+
+
/* Parse the supported extension(s): age-restriction. */
/* TODO: maybe lift all this into a FP in TALER_Extension ? */
+ if (! no_extensions)
{
- struct TALER_MasterSignatureP extensions_sig = {0};
- json_t *extensions = NULL;
- struct GNUNET_JSON_Specification ext_spec[] = {
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_json ("extensions",
- &extensions),
- NULL),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto (
- "extensions_sig",
- &extensions_sig),
- NULL),
- GNUNET_JSON_spec_end ()
- };
-
- /* 1. Search for extensions in the response to /keys */
- EXITIF (GNUNET_OK !=
- GNUNET_JSON_parse (resp_obj,
- ext_spec,
- NULL, NULL));
-
- if (NULL != extensions)
+ if (no_signature)
{
- /* 2. We have an extensions object. Verify its signature. */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "found extensions without signature\n");
+ }
+ else
+ {
+ /* We have an extensions object. Verify its signature. */
EXITIF (GNUNET_OK !=
- TALER_extensions_verify_json_config_signature (
- extensions,
- &extensions_sig,
+ TALER_extensions_verify_manifests_signature (
+ manifests,
+ &key_data->extensions_sig,
&key_data->master_pub));
- /* 3. Parse and set the the configuration of the extensions accordingly */
+ /* Parse and set the the configuration of the extensions accordingly */
EXITIF (GNUNET_OK !=
- TALER_extensions_load_json_config (extensions));
+ TALER_extensions_load_manifests (manifests));
}
- /* 4. assuming we might have now a new value for age_mask, set it in key_data */
- key_data->age_mask = TALER_extensions_age_restriction_ageMask ();
+ /* Assuming we might have now a new value for age_mask, set it in key_data */
+ key_data->age_mask = TALER_extensions_get_age_restriction_mask ();
}
- /**
+ /*
* Parse the denomination keys, merging with the
* possibly EXISTING array as required (/keys cherry picking).
*
* The denominations are grouped by common values of
* {cipher, value, fee, age_mask}.
- **/
+ */
{
- json_t *denominations_by_group;
json_t *group_obj;
unsigned int group_idx;
- denominations_by_group =
- json_object_get (
- resp_obj,
- "denominations");
-
- EXITIF (JSON_ARRAY !=
- json_typeof (denominations_by_group));
-
- json_array_foreach (denominations_by_group, group_idx, group_obj) {
- // Running XOR of each SHA512 hash of the denominations' public key in
- // this group. Used to compare against group.hash after all keys have
- // been parsed.
- struct GNUNET_HashCode group_hash_xor = {0};
-
- // First, parse { cipher, fees, value, age_mask, hash } of the current
- // group.
+ json_array_foreach (denominations_by_group,
+ group_idx,
+ group_obj)
+ {
+ /* First, parse { cipher, fees, value, age_mask, hash } of the current
+ group. */
struct TALER_DenominationGroup group = {0};
+ const json_t *denom_keys_array;
struct GNUNET_JSON_Specification group_spec[] = {
- TALER_JSON_spec_denomination_group (NULL, currency, &group),
+ TALER_JSON_spec_denomination_group (NULL,
+ key_data->currency,
+ &group),
+ GNUNET_JSON_spec_array_const ("denoms",
+ &denom_keys_array),
GNUNET_JSON_spec_end ()
};
+ json_t *denom_key_obj;
+ unsigned int index;
+
EXITIF (GNUNET_SYSERR ==
GNUNET_JSON_parse (group_obj,
group_spec,
NULL,
NULL));
- // Now, parse the individual denominations
+ /* Now, parse the individual denominations */
+ json_array_foreach (denom_keys_array,
+ index,
+ denom_key_obj)
{
- json_t *denom_keys_array;
- json_t *denom_key_obj;
- unsigned int index;
- denom_keys_array = json_object_get (group_obj, "denoms");
- EXITIF (JSON_ARRAY != json_typeof (denom_keys_array));
-
- json_array_foreach (denom_keys_array, index, denom_key_obj) {
- struct TALER_EXCHANGE_DenomPublicKey dk = {0};
- bool found = false;
-
- memset (&dk, 0, sizeof (dk));
-
- // Set the common fields from the group for this particular
- // denomination. Required to make the validity check inside
- // parse_json_denomkey_partially pass
- dk.key.cipher = group.cipher;
- dk.value = group.value;
- dk.fees = group.fees;
- dk.key.age_mask = group.age_mask;
-
- EXITIF (GNUNET_SYSERR ==
- parse_json_denomkey_partially (key_data->currency,
- &dk,
- group.cipher,
- check_sig,
- denom_key_obj,
- &key_data->master_pub,
- check_sig ? &hash_xor : NULL));
-
- // Build the running xor of the SHA512-hash of the public keys
- {
- struct TALER_DenominationHashP hc = {0};
- TALER_denom_pub_hash (&dk.key, &hc);
- GNUNET_CRYPTO_hash_xor (&hc.hash,
- &group_hash_xor,
- &group_hash_xor);
- }
+ /* Set the common fields from the group for this particular
+ denomination. Required to make the validity check inside
+ parse_json_denomkey_partially pass */
+ struct TALER_EXCHANGE_DenomPublicKey dk = {
+ .value = group.value,
+ .fees = group.fees,
+ .key.age_mask = group.age_mask
+ };
+ bool found = false;
- for (unsigned int j = 0;
- j<key_data->num_denom_keys;
- j++)
+ EXITIF (GNUNET_SYSERR ==
+ parse_json_denomkey_partially (&dk,
+ group.cipher,
+ check_sig,
+ denom_key_obj,
+ &key_data->master_pub,
+ group_idx,
+ index,
+ check_sig
+ ? &sig_ctx
+ : NULL));
+ for (unsigned int j = 0;
+ j<key_data->num_denom_keys;
+ j++)
+ {
+ if (0 == denoms_cmp (&dk,
+ &key_data->denom_keys[j]))
{
- if (0 == denoms_cmp (&dk,
- &key_data->denom_keys[j]))
- {
- found = true;
- break;
- }
+ found = true;
+ break;
}
+ }
- if (found)
- {
- /* 0:0:0 did not support /keys cherry picking */
- TALER_LOG_DEBUG ("Skipping denomination key: already know it\n");
- TALER_denom_pub_free (&dk.key);
- continue;
- }
+ if (found)
+ {
+ /* 0:0:0 did not support /keys cherry picking */
+ TALER_LOG_DEBUG ("Skipping denomination key: already know it\n");
+ TALER_denom_pub_free (&dk.key);
+ continue;
+ }
- if (key_data->denom_keys_size == key_data->num_denom_keys)
- GNUNET_array_grow (key_data->denom_keys,
- key_data->denom_keys_size,
- key_data->denom_keys_size * 2 + 2);
- key_data->denom_keys[key_data->num_denom_keys++] = dk;
-
- /* Update "last_denom_issue_date" */
- TALER_LOG_DEBUG ("Adding denomination key that is valid_until %s\n",
- GNUNET_TIME_timestamp2s (dk.valid_from));
- key_data->last_denom_issue_date
- = GNUNET_TIME_timestamp_max (key_data->last_denom_issue_date,
- dk.valid_from);
- }; // json_array_foreach over denominations
-
- // The calculated group_hash_xor must be the same as group.hash from
- // the json.
- EXITIF (0 !=
- GNUNET_CRYPTO_hash_cmp (&group_hash_xor, &group.hash));
-
- } // block for parsing individual denominations
- }; // json_array_foreach over groups of denominations
- }
+ if (key_data->denom_keys_size == key_data->num_denom_keys)
+ GNUNET_array_grow (key_data->denom_keys,
+ key_data->denom_keys_size,
+ key_data->denom_keys_size * 2 + 2);
+ GNUNET_assert (key_data->denom_keys_size >
+ key_data->num_denom_keys);
+ GNUNET_assert (key_data->num_denom_keys < UINT_MAX);
+ key_data->denom_keys[key_data->num_denom_keys++] = dk;
+
+ /* Update "last_denom_issue_date" */
+ TALER_LOG_DEBUG ("Adding denomination key that is valid_until %s\n",
+ GNUNET_TIME_timestamp2s (dk.valid_from));
+ key_data->last_denom_issue_date
+ = GNUNET_TIME_timestamp_max (key_data->last_denom_issue_date,
+ dk.valid_from);
+ }; /* end of json_array_foreach over denominations */
+ } /* end of json_array_foreach over groups of denominations */
+ } /* end of scope for group_ojb/group_idx */
/* parse the auditor information */
{
- json_t *auditors_array;
json_t *auditor_info;
unsigned int index;
- EXITIF (NULL == (auditors_array =
- json_object_get (resp_obj,
- "auditors")));
- EXITIF (JSON_ARRAY != json_typeof (auditors_array));
-
/* Merge with the existing auditor information we have (/keys cherry picking) */
- json_array_foreach (auditors_array, index, auditor_info) {
+ json_array_foreach (auditors_array, index, auditor_info)
+ {
struct TALER_EXCHANGE_AuditorInformation ai;
bool found = false;
@@ -1117,64 +1246,85 @@ decode_keys_json (const json_t *resp_obj,
GNUNET_array_grow (key_data->auditors,
key_data->auditors_size,
key_data->auditors_size * 2 + 2);
+ GNUNET_assert (key_data->auditors_size >
+ key_data->num_auditors);
GNUNET_assert (NULL != ai.auditor_url);
+ GNUNET_assert (key_data->num_auditors < UINT_MAX);
key_data->auditors[key_data->num_auditors++] = ai;
};
}
/* parse the revocation/recoup information */
+ if (NULL != recoup_array)
{
- json_t *recoup_array;
json_t *recoup_info;
unsigned int index;
- if (NULL != (recoup_array =
- json_object_get (resp_obj,
- "recoup")))
+ json_array_foreach (recoup_array, index, recoup_info)
{
- EXITIF (JSON_ARRAY != json_typeof (recoup_array));
-
- json_array_foreach (recoup_array, index, recoup_info) {
- struct TALER_DenominationHashP h_denom_pub;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &h_denom_pub),
- GNUNET_JSON_spec_end ()
- };
+ struct TALER_DenominationHashP h_denom_pub;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
+ &h_denom_pub),
+ GNUNET_JSON_spec_end ()
+ };
- EXITIF (GNUNET_OK !=
- GNUNET_JSON_parse (recoup_info,
- spec,
- NULL, NULL));
- for (unsigned int j = 0;
- j<key_data->num_denom_keys;
- j++)
+ EXITIF (GNUNET_OK !=
+ GNUNET_JSON_parse (recoup_info,
+ spec,
+ NULL, NULL));
+ for (unsigned int j = 0;
+ j<key_data->num_denom_keys;
+ j++)
+ {
+ if (0 == GNUNET_memcmp (&h_denom_pub,
+ &key_data->denom_keys[j].h_key))
{
- if (0 == GNUNET_memcmp (&h_denom_pub,
- &key_data->denom_keys[j].h_key))
- {
- key_data->denom_keys[j].revoked = GNUNET_YES;
- break;
- }
+ key_data->denom_keys[j].revoked = true;
+ break;
}
- };
+ }
}
}
if (check_sig)
{
+ struct GNUNET_HashContext *hash_context;
+ struct GNUNET_HashCode hc;
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+ qsort (sig_ctx.elements,
+ sig_ctx.elements_pos,
+ sizeof (struct SignatureElement),
+ &signature_context_sort_cb);
+ for (unsigned int i = 0; i<sig_ctx.elements_pos; i++)
+ {
+ struct SignatureElement *element = &sig_ctx.elements[i];
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding %u,%u,%s\n",
+ element->group_offset,
+ element->offset,
+ TALER_B2S (&element->master_sig));
+ GNUNET_CRYPTO_hash_context_read (hash_context,
+ &element->master_sig,
+ sizeof (element->master_sig));
+ }
+ GNUNET_array_grow (sig_ctx.elements,
+ sig_ctx.elements_size,
+ 0);
+ GNUNET_CRYPTO_hash_context_finish (hash_context,
+ &hc);
EXITIF (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (key_data,
- &pub));
-
+ &exchange_pub));
EXITIF (GNUNET_OK !=
TALER_exchange_online_key_set_verify (
key_data->list_issue_date,
- &hash_xor,
- &pub,
- &denominations_sig));
+ &hc,
+ &exchange_pub,
+ &exchange_sig));
}
-
return GNUNET_OK;
EXITIF_exit:
@@ -1184,87 +1334,6 @@ EXITIF_exit:
/**
- * Free key data object.
- *
- * @param key_data data to free (pointer itself excluded)
- */
-static void
-free_key_data (struct TALER_EXCHANGE_Keys *key_data)
-{
- GNUNET_array_grow (key_data->sign_keys,
- key_data->num_sign_keys,
- 0);
- for (unsigned int i = 0; i<key_data->num_denom_keys; i++)
- TALER_denom_pub_free (&key_data->denom_keys[i].key);
-
- GNUNET_array_grow (key_data->denom_keys,
- key_data->denom_keys_size,
- 0);
- for (unsigned int i = 0; i<key_data->num_auditors; i++)
- {
- GNUNET_array_grow (key_data->auditors[i].denom_keys,
- key_data->auditors[i].num_denom_keys,
- 0);
- GNUNET_free (key_data->auditors[i].auditor_url);
- }
- GNUNET_array_grow (key_data->auditors,
- key_data->auditors_size,
- 0);
- GNUNET_free (key_data->version);
- GNUNET_free (key_data->currency);
- GNUNET_free (key_data->global_fees);
-}
-
-
-/**
- * Initiate download of /keys from the exchange.
- *
- * @param cls exchange where to download /keys from
- */
-static void
-request_keys (void *cls);
-
-
-void
-TALER_EXCHANGE_set_last_denom (struct TALER_EXCHANGE_Handle *exchange,
- struct GNUNET_TIME_Timestamp last_denom_new)
-{
- TALER_LOG_DEBUG (
- "Application explicitly set last denomination validity to %s\n",
- GNUNET_TIME_timestamp2s (last_denom_new));
- exchange->key_data.last_denom_issue_date = last_denom_new;
-}
-
-
-struct GNUNET_TIME_Timestamp
-TALER_EXCHANGE_check_keys_current (struct TALER_EXCHANGE_Handle *exchange,
- enum TALER_EXCHANGE_CheckKeysFlags flags)
-{
- bool force_download = 0 != (flags & TALER_EXCHANGE_CKF_FORCE_DOWNLOAD);
- bool pull_all_keys = 0 != (flags & TALER_EXCHANGE_CKF_PULL_ALL_KEYS);
-
- if (NULL != exchange->kr)
- return GNUNET_TIME_UNIT_ZERO_TS;
-
- if (pull_all_keys)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Forcing re-download of all exchange keys\n");
- GNUNET_break (GNUNET_YES == force_download);
- exchange->state = MHS_INIT;
- }
- if ( (! force_download) &&
- (GNUNET_TIME_absolute_is_future (
- exchange->key_data_expiration.abs_time)) )
- return exchange->key_data_expiration;
- if (NULL == exchange->retry_task)
- exchange->retry_task = GNUNET_SCHEDULER_add_now (&request_keys,
- exchange);
- return GNUNET_TIME_UNIT_ZERO_TS;
-}
-
-
-/**
* Callback used when downloading the reply to a /keys request
* is complete.
*
@@ -1277,132 +1346,122 @@ keys_completed_cb (void *cls,
long response_code,
const void *resp_obj)
{
- struct KeysRequest *kr = cls;
- struct TALER_EXCHANGE_Handle *exchange = kr->exchange;
- struct TALER_EXCHANGE_Keys kd;
- struct TALER_EXCHANGE_Keys kd_old;
- enum TALER_EXCHANGE_VersionCompatibility vc;
+ struct TALER_EXCHANGE_GetKeysHandle *gkh = cls;
const json_t *j = resp_obj;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_Keys *kd = NULL;
+ struct TALER_EXCHANGE_KeysResponse kresp = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code,
+ .details.ok.compat = TALER_EXCHANGE_VC_PROTOCOL_ERROR,
};
+ gkh->job = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received keys from URL `%s' with status %ld and expiration %s.\n",
- kr->url,
+ gkh->url,
response_code,
- GNUNET_TIME_timestamp2s (kr->expire));
- if (GNUNET_TIME_absolute_is_past (kr->expire.abs_time))
+ GNUNET_TIME_timestamp2s (gkh->expire));
+ if (GNUNET_TIME_absolute_is_past (gkh->expire.abs_time))
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Exchange failed to give expiration time, assuming in %s\n",
- GNUNET_TIME_relative2s (DEFAULT_EXPIRATION,
- true));
- kr->expire
+ if (MHD_HTTP_OK == response_code)
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Exchange failed to give expiration time, assuming in %s\n",
+ GNUNET_TIME_relative2s (DEFAULT_EXPIRATION,
+ true));
+ gkh->expire
= GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_relative_to_absolute (DEFAULT_EXPIRATION));
}
- kd_old = exchange->key_data;
- memset (&kd,
- 0,
- sizeof (struct TALER_EXCHANGE_Keys));
- vc = TALER_EXCHANGE_VC_PROTOCOL_ERROR;
switch (response_code)
{
case 0:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to receive /keys response from exchange %s\n",
- exchange->url);
- free_keys_request (kr);
- exchange->keys_error_count++;
- exchange->kr = NULL;
- GNUNET_assert (NULL == exchange->retry_task);
- exchange->retry_delay = EXCHANGE_LIB_BACKOFF (exchange->retry_delay);
- exchange->retry_task = GNUNET_SCHEDULER_add_delayed (exchange->retry_delay,
- &request_keys,
- exchange);
- return;
+ gkh->exchange_url);
+ break;
case MHD_HTTP_OK:
- exchange->keys_error_count = 0;
if (NULL == j)
{
+ GNUNET_break (0);
response_code = 0;
break;
}
- /* We keep the denomination keys and auditor signatures from the
- previous iteration (/keys cherry picking) */
- kd.num_denom_keys = kd_old.num_denom_keys;
- kd.last_denom_issue_date = kd_old.last_denom_issue_date;
- GNUNET_array_grow (kd.denom_keys,
- kd.denom_keys_size,
- kd.num_denom_keys);
-
- /* First make a shallow copy, we then need another pass for the RSA key... */
- memcpy (kd.denom_keys,
- kd_old.denom_keys,
- kd_old.num_denom_keys * sizeof (struct
- TALER_EXCHANGE_DenomPublicKey));
-
- for (unsigned int i = 0; i<kd_old.num_denom_keys; i++)
- TALER_denom_pub_deep_copy (&kd.denom_keys[i].key,
- &kd_old.denom_keys[i].key);
-
- kd.num_auditors = kd_old.num_auditors;
- kd.auditors = GNUNET_new_array (kd.num_auditors,
- struct TALER_EXCHANGE_AuditorInformation);
- /* Now the necessary deep copy... */
- for (unsigned int i = 0; i<kd_old.num_auditors; i++)
+ kd = GNUNET_new (struct TALER_EXCHANGE_Keys);
+ kd->exchange_url = GNUNET_strdup (gkh->exchange_url);
+ if (NULL != gkh->prev_keys)
{
- const struct TALER_EXCHANGE_AuditorInformation *aold =
- &kd_old.auditors[i];
- struct TALER_EXCHANGE_AuditorInformation *anew = &kd.auditors[i];
-
- anew->auditor_pub = aold->auditor_pub;
- GNUNET_assert (NULL != aold->auditor_url);
- anew->auditor_url = GNUNET_strdup (aold->auditor_url);
- GNUNET_array_grow (anew->denom_keys,
- anew->num_denom_keys,
- aold->num_denom_keys);
- memcpy (anew->denom_keys,
- aold->denom_keys,
- aold->num_denom_keys
- * sizeof (struct TALER_EXCHANGE_AuditorDenominationInfo));
- }
+ const struct TALER_EXCHANGE_Keys *kd_old = gkh->prev_keys;
+
+ /* We keep the denomination keys and auditor signatures from the
+ previous iteration (/keys cherry picking) */
+ kd->num_denom_keys
+ = kd_old->num_denom_keys;
+ kd->last_denom_issue_date
+ = kd_old->last_denom_issue_date;
+ GNUNET_array_grow (kd->denom_keys,
+ kd->denom_keys_size,
+ kd->num_denom_keys);
+ /* First make a shallow copy, we then need another pass for the RSA key... */
+ GNUNET_memcpy (kd->denom_keys,
+ kd_old->denom_keys,
+ kd_old->num_denom_keys
+ * sizeof (struct TALER_EXCHANGE_DenomPublicKey));
+ for (unsigned int i = 0; i<kd_old->num_denom_keys; i++)
+ TALER_denom_pub_copy (&kd->denom_keys[i].key,
+ &kd_old->denom_keys[i].key);
+ kd->num_auditors = kd_old->num_auditors;
+ kd->auditors = GNUNET_new_array (kd->num_auditors,
+ struct TALER_EXCHANGE_AuditorInformation);
+ /* Now the necessary deep copy... */
+ for (unsigned int i = 0; i<kd_old->num_auditors; i++)
+ {
+ const struct TALER_EXCHANGE_AuditorInformation *aold =
+ &kd_old->auditors[i];
+ struct TALER_EXCHANGE_AuditorInformation *anew = &kd->auditors[i];
- /* Old auditors got just copied into new ones. */
+ anew->auditor_pub = aold->auditor_pub;
+ anew->auditor_url = GNUNET_strdup (aold->auditor_url);
+ GNUNET_array_grow (anew->denom_keys,
+ anew->num_denom_keys,
+ aold->num_denom_keys);
+ GNUNET_memcpy (
+ anew->denom_keys,
+ aold->denom_keys,
+ aold->num_denom_keys
+ * sizeof (struct TALER_EXCHANGE_AuditorDenominationInfo));
+ }
+ }
+ /* Now decode fresh /keys response */
if (GNUNET_OK !=
decode_keys_json (j,
true,
- &kd,
- &vc))
+ kd,
+ &kresp.details.ok.compat))
{
TALER_LOG_ERROR ("Could not decode /keys response\n");
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- for (unsigned int i = 0; i<kd.num_auditors; i++)
- {
- struct TALER_EXCHANGE_AuditorInformation *anew = &kd.auditors[i];
-
- GNUNET_array_grow (anew->denom_keys,
- anew->num_denom_keys,
- 0);
- GNUNET_free (anew->auditor_url);
- }
- GNUNET_free (kd.auditors);
- kd.auditors = NULL;
- kd.num_auditors = 0;
- for (unsigned int i = 0; i<kd_old.num_denom_keys; i++)
- TALER_denom_pub_free (&kd.denom_keys[i].key);
- GNUNET_array_grow (kd.denom_keys,
- kd.denom_keys_size,
- 0);
- kd.num_denom_keys = 0;
+ kd->rc = 1;
+ TALER_EXCHANGE_keys_decref (kd);
+ kd = NULL;
+ kresp.hr.http_status = 0;
+ kresp.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- json_decref (exchange->key_data_raw);
- exchange->key_data_raw = json_deep_copy (j);
- exchange->retry_delay = GNUNET_TIME_UNIT_ZERO;
+ kd->rc = 1;
+ kd->key_data_expiration = gkh->expire;
+ if (GNUNET_TIME_relative_cmp (
+ GNUNET_TIME_absolute_get_remaining (gkh->expire.abs_time),
+ <,
+ MINIMUM_EXPIRATION))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Exchange returned keys with expiration time below %s. Compensating.\n",
+ GNUNET_TIME_relative2s (MINIMUM_EXPIRATION,
+ true));
+ kd->key_data_expiration
+ = GNUNET_TIME_relative_to_timestamp (MINIMUM_EXPIRATION);
+ }
+
+ kresp.details.ok.keys = kd;
break;
case MHD_HTTP_BAD_REQUEST:
case MHD_HTTP_UNAUTHORIZED:
@@ -1410,108 +1469,36 @@ keys_completed_cb (void *cls,
case MHD_HTTP_NOT_FOUND:
if (NULL == j)
{
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = TALER_ErrorCode_get_hint (hr.ec);
+ kresp.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ kresp.hr.hint = TALER_ErrorCode_get_hint (kresp.hr.ec);
}
else
{
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ kresp.hr.ec = TALER_JSON_get_error_code (j);
+ kresp.hr.hint = TALER_JSON_get_error_hint (j);
}
break;
default:
- if (MHD_HTTP_GATEWAY_TIMEOUT == response_code)
- exchange->keys_error_count++;
if (NULL == j)
{
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = TALER_ErrorCode_get_hint (hr.ec);
+ kresp.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ kresp.hr.hint = TALER_ErrorCode_get_hint (kresp.hr.ec);
}
else
{
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ kresp.hr.ec = TALER_JSON_get_error_code (j);
+ kresp.hr.hint = TALER_JSON_get_error_hint (j);
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) kresp.hr.ec);
break;
}
- exchange->key_data = kd;
- if (GNUNET_TIME_absolute_is_past (
- exchange->key_data.last_denom_issue_date.abs_time))
- TALER_LOG_WARNING ("Last DK issue date from exchange is in the past: %s\n",
- GNUNET_TIME_timestamp2s (
- exchange->key_data.last_denom_issue_date));
- else
- TALER_LOG_DEBUG ("Last DK issue date updated to: %s\n",
- GNUNET_TIME_timestamp2s (
- exchange->key_data.last_denom_issue_date));
-
-
- if (MHD_HTTP_OK != response_code)
- {
- exchange->kr = NULL;
- free_keys_request (kr);
- exchange->state = MHS_FAILED;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Exchange keys download failed\n");
- if (NULL != exchange->key_data_raw)
- {
- json_decref (exchange->key_data_raw);
- exchange->key_data_raw = NULL;
- }
- free_key_data (&kd_old);
- /* notify application that we failed */
- exchange->cert_cb (exchange->cert_cb_cls,
- &hr,
- NULL,
- vc);
- return;
- }
-
- exchange->kr = NULL;
- exchange->key_data_expiration = kr->expire;
- free_keys_request (kr);
- exchange->state = MHS_CERT;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Successfully downloaded exchange's keys\n");
- update_auditors (exchange);
- /* notify application about the key information */
- exchange->cert_cb (exchange->cert_cb_cls,
- &hr,
- &exchange->key_data,
- vc);
- free_key_data (&kd_old);
-}
-
-
-/* ********************* library internal API ********* */
-
-
-struct GNUNET_CURL_Context *
-TEAH_handle_to_context (struct TALER_EXCHANGE_Handle *h)
-{
- return h->ctx;
-}
-
-
-enum GNUNET_GenericReturnValue
-TEAH_handle_is_ready (struct TALER_EXCHANGE_Handle *h)
-{
- return (MHS_CERT == h->state) ? GNUNET_YES : GNUNET_NO;
-}
-
-
-char *
-TEAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
- const char *path)
-{
- GNUNET_assert ('/' == path[0]);
- return TALER_url_join (h->url,
- path + 1,
- NULL);
+ gkh->cert_cb (gkh->cert_cb_cls,
+ &kresp,
+ kd);
+ TALER_EXCHANGE_get_keys_cancel (gkh);
}
@@ -1525,7 +1512,7 @@ TEAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
* Parse HTTP timestamp.
*
* @param dateline header to parse header
- * @param at where to write the result
+ * @param[out] at where to write the result
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
@@ -1625,7 +1612,7 @@ parse_date_string (const char *dateline,
* @param buffer header data received
* @param size size of an item in @a buffer
* @param nitems number of items in @a buffer
- * @param userdata the `struct KeysRequest`
+ * @param userdata the `struct TALER_EXCHANGE_GetKeysHandle`
* @return `size * nitems` on success (everything else aborts)
*/
static size_t
@@ -1634,7 +1621,7 @@ header_cb (char *buffer,
size_t nitems,
void *userdata)
{
- struct KeysRequest *kr = userdata;
+ struct TALER_EXCHANGE_GetKeysHandle *kr = userdata;
size_t total = size * nitems;
char *val;
@@ -1646,6 +1633,10 @@ header_cb (char *buffer,
return total;
val = GNUNET_strndup (&buffer[strlen (MHD_HTTP_HEADER_EXPIRES ": ")],
total - strlen (MHD_HTTP_HEADER_EXPIRES ": "));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Found %s header `%s'\n",
+ MHD_HTTP_HEADER_EXPIRES,
+ val);
if (GNUNET_OK !=
parse_date_string (val,
&kr->expire))
@@ -1661,409 +1652,66 @@ header_cb (char *buffer,
}
-/* ********************* public API ******************* */
-
-
-/**
- * Deserialize the key data and use it to bootstrap @a exchange to
- * more efficiently recover the state. Errors in @a data must be
- * tolerated (i.e. by re-downloading instead).
- *
- * @param exchange which exchange's key and wire data should be deserialized
- * @param data the data to deserialize
- */
-static void
-deserialize_data (struct TALER_EXCHANGE_Handle *exchange,
- const json_t *data)
-{
- enum TALER_EXCHANGE_VersionCompatibility vc;
- json_t *keys;
- const char *url;
- uint32_t version;
- struct GNUNET_TIME_Timestamp expire;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint32 ("version",
- &version),
- GNUNET_JSON_spec_json ("keys",
- &keys),
- GNUNET_JSON_spec_string ("exchange_url",
- &url),
- GNUNET_JSON_spec_timestamp ("expire",
- &expire),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_EXCHANGE_Keys key_data;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .ec = TALER_EC_NONE,
- .http_status = MHD_HTTP_OK,
- .reply = data
- };
-
- if (NULL == data)
- return;
- if (GNUNET_OK !=
- GNUNET_JSON_parse (data,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return;
- }
- if (0 != version)
- {
- GNUNET_JSON_parse_free (spec);
- return; /* unsupported version */
- }
- if (0 != strcmp (url,
- exchange->url))
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return;
- }
- memset (&key_data,
- 0,
- sizeof (struct TALER_EXCHANGE_Keys));
- if (GNUNET_OK !=
- decode_keys_json (keys,
- false,
- &key_data,
- &vc))
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return;
- }
- /* decode successful, initialize with the result */
- GNUNET_assert (NULL == exchange->key_data_raw);
- exchange->key_data_raw = json_deep_copy (keys);
- exchange->key_data = key_data;
- exchange->key_data_expiration = expire;
- exchange->state = MHS_CERT;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Successfully loaded exchange's keys via deserialization\n");
- update_auditors (exchange);
- /* notify application about the key information */
- exchange->cert_cb (exchange->cert_cb_cls,
- &hr,
- &exchange->key_data,
- vc);
- GNUNET_JSON_parse_free (spec);
-}
-
-
-json_t *
-TALER_EXCHANGE_serialize_data (struct TALER_EXCHANGE_Handle *exchange)
-{
- const struct TALER_EXCHANGE_Keys *kd = &exchange->key_data;
- struct GNUNET_TIME_Timestamp now;
- json_t *keys;
- json_t *signkeys;
- json_t *denoms;
- json_t *auditors;
-
- now = GNUNET_TIME_timestamp_get ();
- signkeys = json_array ();
- if (NULL == signkeys)
- {
- GNUNET_break (0);
- return NULL;
- }
- for (unsigned int i = 0; i<kd->num_sign_keys; i++)
- {
- const struct TALER_EXCHANGE_SigningPublicKey *sk = &kd->sign_keys[i];
- json_t *signkey;
-
- if (GNUNET_TIME_timestamp_cmp (now,
- >,
- sk->valid_until))
- continue; /* skip keys that have expired */
- signkey = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("key",
- &sk->key),
- GNUNET_JSON_pack_data_auto ("master_sig",
- &sk->master_sig),
- GNUNET_JSON_pack_timestamp ("stamp_start",
- sk->valid_from),
- GNUNET_JSON_pack_timestamp ("stamp_expire",
- sk->valid_until),
- GNUNET_JSON_pack_timestamp ("stamp_end",
- sk->valid_legal));
- if (NULL == signkey)
- {
- GNUNET_break (0);
- continue;
- }
- if (0 != json_array_append_new (signkeys,
- signkey))
- {
- GNUNET_break (0);
- json_decref (signkey);
- json_decref (signkeys);
- return NULL;
- }
- }
- denoms = json_array ();
- if (NULL == denoms)
- {
- GNUNET_break (0);
- json_decref (signkeys);
- return NULL;
- }
- for (unsigned int i = 0; i<kd->num_denom_keys; i++)
- {
- const struct TALER_EXCHANGE_DenomPublicKey *dk = &kd->denom_keys[i];
- json_t *denom;
-
- if (GNUNET_TIME_timestamp_cmp (now,
- >,
- dk->expire_deposit))
- continue; /* skip keys that have expired */
- denom = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_timestamp ("stamp_expire_deposit",
- dk->expire_deposit),
- GNUNET_JSON_pack_timestamp ("stamp_expire_withdraw",
- dk->withdraw_valid_until),
- GNUNET_JSON_pack_timestamp ("stamp_start",
- dk->valid_from),
- GNUNET_JSON_pack_timestamp ("stamp_expire_legal",
- dk->expire_legal),
- TALER_JSON_pack_amount ("value",
- &dk->value),
- TALER_JSON_PACK_DENOM_FEES ("fee",
- &dk->fees),
- GNUNET_JSON_pack_data_auto ("master_sig",
- &dk->master_sig),
- TALER_JSON_pack_denom_pub ("denom_pub",
- &dk->key));
- GNUNET_assert (0 ==
- json_array_append_new (denoms,
- denom));
- }
- auditors = json_array ();
- GNUNET_assert (NULL != auditors);
- for (unsigned int i = 0; i<kd->num_auditors; i++)
- {
- const struct TALER_EXCHANGE_AuditorInformation *ai = &kd->auditors[i];
- json_t *a;
- json_t *adenoms;
-
- adenoms = json_array ();
- if (NULL == adenoms)
- {
- GNUNET_break (0);
- json_decref (denoms);
- json_decref (signkeys);
- json_decref (auditors);
- return NULL;
- }
- for (unsigned int j = 0; j<ai->num_denom_keys; j++)
- {
- const struct TALER_EXCHANGE_AuditorDenominationInfo *adi =
- &ai->denom_keys[j];
- const struct TALER_EXCHANGE_DenomPublicKey *dk =
- &kd->denom_keys[adi->denom_key_offset];
- json_t *k;
-
- if (GNUNET_TIME_timestamp_cmp (now,
- >,
- dk->expire_deposit))
- continue; /* skip auditor signatures for denomination keys that have expired */
- GNUNET_assert (adi->denom_key_offset < kd->num_denom_keys);
- k = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("denom_pub_h",
- &dk->h_key),
- GNUNET_JSON_pack_data_auto ("auditor_sig",
- &adi->auditor_sig));
- GNUNET_assert (0 ==
- json_array_append_new (adenoms,
- k));
- }
-
- a = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("auditor_pub",
- &ai->auditor_pub),
- GNUNET_JSON_pack_string ("auditor_url",
- ai->auditor_url),
- GNUNET_JSON_pack_array_steal ("denomination_keys",
- adenoms));
- GNUNET_assert (0 ==
- json_array_append_new (auditors,
- a));
- }
- keys = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("version",
- kd->version),
- GNUNET_JSON_pack_string ("currency",
- kd->currency),
- GNUNET_JSON_pack_data_auto ("master_public_key",
- &kd->master_pub),
- GNUNET_JSON_pack_time_rel ("reserve_closing_delay",
- kd->reserve_closing_delay),
- GNUNET_JSON_pack_timestamp ("list_issue_date",
- kd->list_issue_date),
- GNUNET_JSON_pack_array_steal ("signkeys",
- signkeys),
- GNUNET_JSON_pack_array_steal ("denoms",
- denoms),
- GNUNET_JSON_pack_array_steal ("auditors",
- auditors));
- return GNUNET_JSON_PACK (
- GNUNET_JSON_pack_uint64 ("version",
- EXCHANGE_SERIALIZATION_FORMAT_VERSION),
- GNUNET_JSON_pack_timestamp ("expire",
- exchange->key_data_expiration),
- GNUNET_JSON_pack_string ("exchange_url",
- exchange->url),
- GNUNET_JSON_pack_object_steal ("keys",
- keys));
-}
-
-
-struct TALER_EXCHANGE_Handle *
-TALER_EXCHANGE_connect (
+struct TALER_EXCHANGE_GetKeysHandle *
+TALER_EXCHANGE_get_keys (
struct GNUNET_CURL_Context *ctx,
const char *url,
- TALER_EXCHANGE_CertificationCallback cert_cb,
- void *cert_cb_cls,
- ...)
+ struct TALER_EXCHANGE_Keys *last_keys,
+ TALER_EXCHANGE_GetKeysCallback cert_cb,
+ void *cert_cb_cls)
{
- struct TALER_EXCHANGE_Handle *exchange;
- va_list ap;
- enum TALER_EXCHANGE_Option opt;
+ struct TALER_EXCHANGE_GetKeysHandle *gkh;
+ CURL *eh;
+ char last_date[80] = { 0 };
TALER_LOG_DEBUG ("Connecting to the exchange (%s)\n",
url);
- /* Disable 100 continue processing */
- GNUNET_break (GNUNET_OK ==
- GNUNET_CURL_append_header (ctx,
- MHD_HTTP_HEADER_EXPECT ":"));
- exchange = GNUNET_new (struct TALER_EXCHANGE_Handle);
- exchange->ctx = ctx;
- exchange->url = GNUNET_strdup (url);
- exchange->cert_cb = cert_cb;
- exchange->cert_cb_cls = cert_cb_cls;
- exchange->retry_task = GNUNET_SCHEDULER_add_now (&request_keys,
- exchange);
- va_start (ap, cert_cb_cls);
- while (TALER_EXCHANGE_OPTION_END !=
- (opt = va_arg (ap, int)))
- {
- switch (opt)
- {
- case TALER_EXCHANGE_OPTION_END:
- GNUNET_assert (0);
- break;
- case TALER_EXCHANGE_OPTION_DATA:
- {
- const json_t *data = va_arg (ap, const json_t *);
-
- deserialize_data (exchange,
- data);
- break;
- }
- default:
- GNUNET_assert (0);
- break;
- }
- }
- va_end (ap);
- return exchange;
-}
-
-
-/**
- * Compute the network timeout for the next request to /keys.
- *
- * @param exchange the exchange handle
- * @returns the timeout in seconds (for use by CURL)
- */
-static long
-get_keys_timeout_seconds (struct TALER_EXCHANGE_Handle *exchange)
-{
- unsigned int kec;
-
- /* if retry counter >= 8, do not bother to go further, we
- stop the exponential back-off at 128 anyway. */
- kec = GNUNET_MIN (7,
- exchange->keys_error_count);
- return GNUNET_MIN (120,
- 5 + (1L << kec));
-}
-
-
-/**
- * Initiate download of /keys from the exchange.
- *
- * @param cls exchange where to download /keys from
- */
-static void
-request_keys (void *cls)
-{
- struct TALER_EXCHANGE_Handle *exchange = cls;
- struct KeysRequest *kr;
- CURL *eh;
- char url[200] = "/keys?";
-
- exchange->retry_task = NULL;
- GNUNET_assert (NULL == exchange->kr);
- kr = GNUNET_new (struct KeysRequest);
- kr->exchange = exchange;
-
- if (GNUNET_YES == TEAH_handle_is_ready (exchange))
+ gkh = GNUNET_new (struct TALER_EXCHANGE_GetKeysHandle);
+ gkh->exchange_url = GNUNET_strdup (url);
+ gkh->cert_cb = cert_cb;
+ gkh->cert_cb_cls = cert_cb_cls;
+ if (NULL != last_keys)
{
+ gkh->prev_keys = TALER_EXCHANGE_keys_incref (last_keys);
TALER_LOG_DEBUG ("Last DK issue date (before GETting /keys): %s\n",
GNUNET_TIME_timestamp2s (
- exchange->key_data.last_denom_issue_date));
- sprintf (&url[strlen (url)],
- "last_issue_date=%llu&",
- (unsigned long long)
- exchange->key_data.last_denom_issue_date.abs_time.abs_value_us
- / 1000000LLU);
+ last_keys->last_denom_issue_date));
+ GNUNET_snprintf (last_date,
+ sizeof (last_date),
+ "%llu",
+ (unsigned long long)
+ last_keys->last_denom_issue_date.abs_time.abs_value_us
+ / 1000000LLU);
}
-
- /* Clean the last '&'/'?' sign that we optimistically put. */
- url[strlen (url) - 1] = '\0';
- kr->url = TEAH_path_to_url (exchange,
- url);
- if (NULL == kr->url)
- {
- struct TALER_EXCHANGE_HttpResponse hr = {
- .ec = TALER_EC_GENERIC_CONFIGURATION_INVALID
- };
-
- GNUNET_free (kr);
- exchange->keys_error_count++;
- exchange->state = MHS_FAILED;
- exchange->cert_cb (exchange->cert_cb_cls,
- &hr,
- NULL,
- TALER_EXCHANGE_VC_PROTOCOL_ERROR);
- return;
- }
-
+ gkh->url = TALER_url_join (url,
+ "keys",
+ (NULL != last_keys)
+ ? "last_issue_date"
+ : NULL,
+ (NULL != last_keys)
+ ? last_date
+ : NULL,
+ NULL);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting keys with URL `%s'.\n",
- kr->url);
- eh = TALER_EXCHANGE_curl_easy_get_ (kr->url);
+ gkh->url);
+ eh = TALER_EXCHANGE_curl_easy_get_ (gkh->url);
if (NULL == eh)
{
- GNUNET_free (kr->url);
- GNUNET_free (kr);
- exchange->retry_delay = EXCHANGE_LIB_BACKOFF (exchange->retry_delay);
- exchange->retry_task = GNUNET_SCHEDULER_add_delayed (exchange->retry_delay,
- &request_keys,
- exchange);
- return;
+ GNUNET_break (0);
+ GNUNET_free (gkh->exchange_url);
+ GNUNET_free (gkh->url);
+ GNUNET_free (gkh);
+ return NULL;
}
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_VERBOSE,
- 0));
+ 1));
GNUNET_break (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_TIMEOUT,
- get_keys_timeout_seconds (exchange)));
+ 120 /* seconds */));
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_HEADERFUNCTION,
@@ -2071,70 +1719,35 @@ request_keys (void *cls)
GNUNET_assert (CURLE_OK ==
curl_easy_setopt (eh,
CURLOPT_HEADERDATA,
- kr));
- kr->job = GNUNET_CURL_job_add_with_ct_json (exchange->ctx,
- eh,
- &keys_completed_cb,
- kr);
- exchange->kr = kr;
+ gkh));
+ gkh->job = GNUNET_CURL_job_add_with_ct_json (ctx,
+ eh,
+ &keys_completed_cb,
+ gkh);
+ return gkh;
}
void
-TALER_EXCHANGE_disconnect (struct TALER_EXCHANGE_Handle *exchange)
+TALER_EXCHANGE_get_keys_cancel (
+ struct TALER_EXCHANGE_GetKeysHandle *gkh)
{
- struct TEAH_AuditorListEntry *ale;
-
- while (NULL != (ale = exchange->auditors_head))
- {
- struct TEAH_AuditorInteractionEntry *aie;
-
- while (NULL != (aie = ale->ai_head))
- {
- GNUNET_assert (aie->ale == ale);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Not sending deposit confirmation to auditor `%s' due to exchange disconnect\n",
- ale->auditor_url);
- TALER_AUDITOR_deposit_confirmation_cancel (aie->dch);
- GNUNET_CONTAINER_DLL_remove (ale->ai_head,
- ale->ai_tail,
- aie);
- GNUNET_free (aie);
- }
- GNUNET_CONTAINER_DLL_remove (exchange->auditors_head,
- exchange->auditors_tail,
- ale);
- TALER_LOG_DEBUG ("Disconnecting the auditor `%s'\n",
- ale->auditor_url);
- TALER_AUDITOR_disconnect (ale->ah);
- GNUNET_free (ale->auditor_url);
- GNUNET_free (ale);
- }
- if (NULL != exchange->kr)
+ if (NULL != gkh->job)
{
- GNUNET_CURL_job_cancel (exchange->kr->job);
- free_keys_request (exchange->kr);
- exchange->kr = NULL;
+ GNUNET_CURL_job_cancel (gkh->job);
+ gkh->job = NULL;
}
- free_key_data (&exchange->key_data);
- if (NULL != exchange->key_data_raw)
- {
- json_decref (exchange->key_data_raw);
- exchange->key_data_raw = NULL;
- }
- if (NULL != exchange->retry_task)
- {
- GNUNET_SCHEDULER_cancel (exchange->retry_task);
- exchange->retry_task = NULL;
- }
- GNUNET_free (exchange->url);
- GNUNET_free (exchange);
+ TALER_EXCHANGE_keys_decref (gkh->prev_keys);
+ GNUNET_free (gkh->exchange_url);
+ GNUNET_free (gkh->url);
+ GNUNET_free (gkh);
}
enum GNUNET_GenericReturnValue
-TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_ExchangePublicKeyP *pub)
+TALER_EXCHANGE_test_signing_key (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_ExchangePublicKeyP *pub)
{
struct GNUNET_TIME_Absolute now;
@@ -2161,13 +1774,6 @@ TALER_EXCHANGE_test_signing_key (const struct TALER_EXCHANGE_Keys *keys,
}
-const char *
-TALER_EXCHANGE_get_base_url (const struct TALER_EXCHANGE_Handle *exchange)
-{
- return exchange->url;
-}
-
-
const struct TALER_EXCHANGE_DenomPublicKey *
TALER_EXCHANGE_get_denomination_key (
const struct TALER_EXCHANGE_Keys *keys,
@@ -2211,8 +1817,8 @@ TALER_EXCHANGE_copy_denomination_key (
copy = GNUNET_new (struct TALER_EXCHANGE_DenomPublicKey);
*copy = *key;
- TALER_denom_pub_deep_copy (&copy->key,
- &key->key);
+ TALER_denom_pub_copy (&copy->key,
+ &key->key);
return copy;
}
@@ -2239,21 +1845,627 @@ TALER_EXCHANGE_get_denomination_key_by_hash (
}
-const struct TALER_EXCHANGE_Keys *
-TALER_EXCHANGE_get_keys (struct TALER_EXCHANGE_Handle *exchange)
+struct TALER_EXCHANGE_Keys *
+TALER_EXCHANGE_keys_incref (struct TALER_EXCHANGE_Keys *keys)
+{
+ GNUNET_assert (keys->rc < UINT_MAX);
+ keys->rc++;
+ return keys;
+}
+
+
+void
+TALER_EXCHANGE_keys_decref (struct TALER_EXCHANGE_Keys *keys)
+{
+ if (NULL == keys)
+ return;
+ GNUNET_assert (0 < keys->rc);
+ keys->rc--;
+ if (0 != keys->rc)
+ return;
+ GNUNET_array_grow (keys->sign_keys,
+ keys->num_sign_keys,
+ 0);
+ for (unsigned int i = 0; i<keys->num_denom_keys; i++)
+ TALER_denom_pub_free (&keys->denom_keys[i].key);
+
+ GNUNET_array_grow (keys->denom_keys,
+ keys->denom_keys_size,
+ 0);
+ for (unsigned int i = 0; i<keys->num_auditors; i++)
+ {
+ GNUNET_array_grow (keys->auditors[i].denom_keys,
+ keys->auditors[i].num_denom_keys,
+ 0);
+ GNUNET_free (keys->auditors[i].auditor_url);
+ }
+ GNUNET_array_grow (keys->auditors,
+ keys->auditors_size,
+ 0);
+ TALER_EXCHANGE_free_accounts (keys->accounts_len,
+ keys->accounts);
+ GNUNET_array_grow (keys->accounts,
+ keys->accounts_len,
+ 0);
+ free_fees (keys->fees,
+ keys->fees_len);
+ json_decref (keys->extensions);
+ GNUNET_free (keys->cspec.name);
+ json_decref (keys->cspec.map_alt_unit_names);
+ GNUNET_free (keys->wallet_balance_limit_without_kyc);
+ GNUNET_free (keys->version);
+ GNUNET_free (keys->currency);
+ GNUNET_free (keys->asset_type);
+ GNUNET_free (keys->global_fees);
+ GNUNET_free (keys->exchange_url);
+ GNUNET_free (keys);
+}
+
+
+struct TALER_EXCHANGE_Keys *
+TALER_EXCHANGE_keys_from_json (const json_t *j)
+{
+ const json_t *jkeys;
+ const char *url;
+ uint32_t version;
+ struct GNUNET_TIME_Timestamp expire
+ = GNUNET_TIME_UNIT_ZERO_TS;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint32 ("version",
+ &version),
+ GNUNET_JSON_spec_object_const ("keys",
+ &jkeys),
+ TALER_JSON_spec_web_url ("exchange_url",
+ &url),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("expire",
+ &expire),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+ struct TALER_EXCHANGE_Keys *keys;
+ enum TALER_EXCHANGE_VersionCompatibility compat;
+
+ if (NULL == j)
+ return NULL;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ if (0 != version)
+ {
+ return NULL; /* unsupported version */
+ }
+ keys = GNUNET_new (struct TALER_EXCHANGE_Keys);
+ if (GNUNET_OK !=
+ decode_keys_json (jkeys,
+ false,
+ keys,
+ &compat))
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ keys->rc = 1;
+ keys->key_data_expiration = expire;
+ keys->exchange_url = GNUNET_strdup (url);
+ return keys;
+}
+
+
+/**
+ * Data we track per denomination group.
+ */
+struct GroupData
+{
+ /**
+ * The json blob with the group meta-data and list of denominations
+ */
+ json_t *json;
+
+ /**
+ * Meta data for this group.
+ */
+ struct TALER_DenominationGroup meta;
+};
+
+
+/**
+ * Add denomination group represented by @a value
+ * to list of denominations in @a cls. Also frees
+ * the @a value.
+ *
+ * @param[in,out] cls a `json_t *` with an array to build
+ * @param key unused
+ * @param value a `struct GroupData *`
+ * @return #GNUNET_OK (continue to iterate)
+ */
+static enum GNUNET_GenericReturnValue
+add_grp (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ json_t *denominations_by_group = cls;
+ struct GroupData *gd = value;
+ const char *cipher;
+ json_t *ge;
+ bool age_restricted = gd->meta.age_mask.bits != 0;
+
+ (void) key;
+ switch (gd->meta.cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ cipher = age_restricted ? "RSA+age_restricted" : "RSA";
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ cipher = age_restricted ? "CS+age_restricted" : "CS";
+ break;
+ default:
+ GNUNET_assert (false);
+ }
+
+ ge = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("cipher",
+ cipher),
+ GNUNET_JSON_pack_array_steal ("denoms",
+ gd->json),
+ TALER_JSON_PACK_DENOM_FEES ("fee",
+ &gd->meta.fees),
+ GNUNET_JSON_pack_allow_null (
+ age_restricted
+ ? GNUNET_JSON_pack_uint64 ("age_mask",
+ gd->meta.age_mask.bits)
+ : GNUNET_JSON_pack_string ("dummy",
+ NULL)),
+ TALER_JSON_pack_amount ("value",
+ &gd->meta.value));
+ GNUNET_assert (0 ==
+ json_array_append_new (denominations_by_group,
+ ge));
+ GNUNET_free (gd);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Convert array of account restrictions @a ars to JSON.
+ *
+ * @param ar_len length of @a ars
+ * @param ars account restrictions to convert
+ * @return JSON representation
+ */
+static json_t *
+ar_to_json (unsigned int ar_len,
+ const struct TALER_EXCHANGE_AccountRestriction ars[static ar_len])
{
- (void) TALER_EXCHANGE_check_keys_current (exchange,
- TALER_EXCHANGE_CKF_NONE);
- return &exchange->key_data;
+ json_t *rval;
+
+ rval = json_array ();
+ GNUNET_assert (NULL != rval);
+ for (unsigned int i = 0; i<ar_len; i++)
+ {
+ const struct TALER_EXCHANGE_AccountRestriction *ar = &ars[i];
+
+ switch (ar->type)
+ {
+ case TALER_EXCHANGE_AR_INVALID:
+ GNUNET_break (0);
+ json_decref (rval);
+ return NULL;
+ case TALER_EXCHANGE_AR_DENY:
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ rval,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "deny"))));
+ break;
+ case TALER_EXCHANGE_AR_REGEX:
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ rval,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string (
+ "type",
+ "regex"),
+ GNUNET_JSON_pack_string (
+ "payto_regex",
+ ar->details.regex.posix_egrep),
+ GNUNET_JSON_pack_string (
+ "human_hint",
+ ar->details.regex.human_hint),
+ GNUNET_JSON_pack_object_incref (
+ "human_hint_i18n",
+ (json_t *) ar->details.regex.human_hint_i18n)
+ )));
+ break;
+ }
+ }
+ return rval;
}
json_t *
-TALER_EXCHANGE_get_keys_raw (struct TALER_EXCHANGE_Handle *exchange)
+TALER_EXCHANGE_keys_to_json (const struct TALER_EXCHANGE_Keys *kd)
{
- (void) TALER_EXCHANGE_check_keys_current (exchange,
- TALER_EXCHANGE_CKF_NONE);
- return json_deep_copy (exchange->key_data_raw);
+ struct GNUNET_TIME_Timestamp now;
+ json_t *keys;
+ json_t *signkeys;
+ json_t *denominations_by_group;
+ json_t *auditors;
+ json_t *recoup;
+ json_t *wire_fees;
+ json_t *accounts;
+ json_t *global_fees;
+ json_t *wblwk = NULL;
+
+ now = GNUNET_TIME_timestamp_get ();
+ signkeys = json_array ();
+ GNUNET_assert (NULL != signkeys);
+ for (unsigned int i = 0; i<kd->num_sign_keys; i++)
+ {
+ const struct TALER_EXCHANGE_SigningPublicKey *sk = &kd->sign_keys[i];
+ json_t *signkey;
+
+ if (GNUNET_TIME_timestamp_cmp (now,
+ >,
+ sk->valid_until))
+ continue; /* skip keys that have expired */
+ signkey = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("key",
+ &sk->key),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &sk->master_sig),
+ GNUNET_JSON_pack_timestamp ("stamp_start",
+ sk->valid_from),
+ GNUNET_JSON_pack_timestamp ("stamp_expire",
+ sk->valid_until),
+ GNUNET_JSON_pack_timestamp ("stamp_end",
+ sk->valid_legal));
+ GNUNET_assert (NULL != signkey);
+ GNUNET_assert (0 ==
+ json_array_append_new (signkeys,
+ signkey));
+ }
+
+ denominations_by_group = json_array ();
+ GNUNET_assert (NULL != denominations_by_group);
+ {
+ struct GNUNET_CONTAINER_MultiHashMap *dbg;
+
+ dbg = GNUNET_CONTAINER_multihashmap_create (128,
+ false);
+ for (unsigned int i = 0; i<kd->num_denom_keys; i++)
+ {
+ const struct TALER_EXCHANGE_DenomPublicKey *dk = &kd->denom_keys[i];
+ struct TALER_DenominationGroup meta = {
+ .cipher = dk->key.bsign_pub_key->cipher,
+ .value = dk->value,
+ .fees = dk->fees,
+ .age_mask = dk->key.age_mask
+ };
+ struct GNUNET_HashCode key;
+ struct GroupData *gd;
+ json_t *denom;
+ struct GNUNET_JSON_PackSpec key_spec;
+
+ if (GNUNET_TIME_timestamp_cmp (now,
+ >,
+ dk->expire_deposit))
+ continue; /* skip keys that have expired */
+ TALER_denomination_group_get_key (&meta,
+ &key);
+ gd = GNUNET_CONTAINER_multihashmap_get (dbg,
+ &key);
+ if (NULL == gd)
+ {
+ gd = GNUNET_new (struct GroupData);
+ gd->meta = meta;
+ gd->json = json_array ();
+ GNUNET_assert (NULL != gd->json);
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap_put (dbg,
+ &key,
+ gd,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
+ }
+ switch (meta.cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ key_spec =
+ GNUNET_JSON_pack_rsa_public_key (
+ "rsa_pub",
+ dk->key.bsign_pub_key->details.rsa_public_key);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ key_spec =
+ GNUNET_JSON_pack_data_varsize (
+ "cs_pub",
+ &dk->key.bsign_pub_key->details.cs_public_key,
+ sizeof (dk->key.bsign_pub_key->details.cs_public_key));
+ break;
+ default:
+ GNUNET_assert (false);
+ }
+ denom = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_timestamp ("stamp_expire_deposit",
+ dk->expire_deposit),
+ GNUNET_JSON_pack_timestamp ("stamp_expire_withdraw",
+ dk->withdraw_valid_until),
+ GNUNET_JSON_pack_timestamp ("stamp_start",
+ dk->valid_from),
+ GNUNET_JSON_pack_timestamp ("stamp_expire_legal",
+ dk->expire_legal),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &dk->master_sig),
+ key_spec
+ );
+ GNUNET_assert (0 ==
+ json_array_append_new (gd->json,
+ denom));
+ }
+ GNUNET_CONTAINER_multihashmap_iterate (dbg,
+ &add_grp,
+ denominations_by_group);
+ GNUNET_CONTAINER_multihashmap_destroy (dbg);
+ }
+
+ auditors = json_array ();
+ GNUNET_assert (NULL != auditors);
+ for (unsigned int i = 0; i<kd->num_auditors; i++)
+ {
+ const struct TALER_EXCHANGE_AuditorInformation *ai = &kd->auditors[i];
+ json_t *a;
+ json_t *adenoms;
+
+ adenoms = json_array ();
+ GNUNET_assert (NULL != adenoms);
+ for (unsigned int j = 0; j<ai->num_denom_keys; j++)
+ {
+ const struct TALER_EXCHANGE_AuditorDenominationInfo *adi =
+ &ai->denom_keys[j];
+ const struct TALER_EXCHANGE_DenomPublicKey *dk =
+ &kd->denom_keys[adi->denom_key_offset];
+ json_t *k;
+
+ GNUNET_assert (adi->denom_key_offset < kd->num_denom_keys);
+ if (GNUNET_TIME_timestamp_cmp (now,
+ >,
+ dk->expire_deposit))
+ continue; /* skip auditor signatures for denomination keys that have expired */
+ GNUNET_assert (adi->denom_key_offset < kd->num_denom_keys);
+ k = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("denom_pub_h",
+ &dk->h_key),
+ GNUNET_JSON_pack_data_auto ("auditor_sig",
+ &adi->auditor_sig));
+ GNUNET_assert (0 ==
+ json_array_append_new (adenoms,
+ k));
+ }
+
+ a = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("auditor_pub",
+ &ai->auditor_pub),
+ GNUNET_JSON_pack_string ("auditor_url",
+ ai->auditor_url),
+ GNUNET_JSON_pack_array_steal ("denomination_keys",
+ adenoms));
+ GNUNET_assert (0 ==
+ json_array_append_new (auditors,
+ a));
+ }
+
+ global_fees = json_array ();
+ GNUNET_assert (NULL != global_fees);
+ for (unsigned int i = 0; i<kd->num_global_fees; i++)
+ {
+ const struct TALER_EXCHANGE_GlobalFee *gf
+ = &kd->global_fees[i];
+
+ if (GNUNET_TIME_absolute_is_past (gf->end_date.abs_time))
+ continue;
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ global_fees,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_timestamp ("start_date",
+ gf->start_date),
+ GNUNET_JSON_pack_timestamp ("end_date",
+ gf->end_date),
+ TALER_JSON_PACK_GLOBAL_FEES (&gf->fees),
+ GNUNET_JSON_pack_time_rel ("history_expiration",
+ gf->history_expiration),
+ GNUNET_JSON_pack_time_rel ("purse_timeout",
+ gf->purse_timeout),
+ GNUNET_JSON_pack_uint64 ("purse_account_limit",
+ gf->purse_account_limit),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &gf->master_sig))));
+ }
+
+ accounts = json_array ();
+ GNUNET_assert (NULL != accounts);
+ for (unsigned int i = 0; i<kd->accounts_len; i++)
+ {
+ const struct TALER_EXCHANGE_WireAccount *acc
+ = &kd->accounts[i];
+ json_t *credit_restrictions;
+ json_t *debit_restrictions;
+
+ credit_restrictions
+ = ar_to_json (acc->credit_restrictions_length,
+ acc->credit_restrictions);
+ GNUNET_assert (NULL != credit_restrictions);
+ debit_restrictions
+ = ar_to_json (acc->debit_restrictions_length,
+ acc->debit_restrictions);
+ GNUNET_assert (NULL != debit_restrictions);
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ accounts,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("payto_uri",
+ acc->payto_uri),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("conversion_url",
+ acc->conversion_url)),
+ GNUNET_JSON_pack_int64 ("priority",
+ acc->priority),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("bank_label",
+ acc->bank_label)),
+ GNUNET_JSON_pack_array_steal ("debit_restrictions",
+ debit_restrictions),
+ GNUNET_JSON_pack_array_steal ("credit_restrictions",
+ credit_restrictions),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &acc->master_sig))));
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Serialized %u/%u wire accounts to JSON\n",
+ (unsigned int) json_array_size (accounts),
+ kd->accounts_len);
+
+ wire_fees = json_object ();
+ GNUNET_assert (NULL != wire_fees);
+ for (unsigned int i = 0; i<kd->fees_len; i++)
+ {
+ const struct TALER_EXCHANGE_WireFeesByMethod *fbw
+ = &kd->fees[i];
+ json_t *wf;
+
+ wf = json_array ();
+ GNUNET_assert (NULL != wf);
+ for (struct TALER_EXCHANGE_WireAggregateFees *p = fbw->fees_head;
+ NULL != p;
+ p = p->next)
+ {
+ GNUNET_assert (
+ 0 ==
+ json_array_append_new (
+ wf,
+ GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("wire_fee",
+ &p->fees.wire),
+ TALER_JSON_pack_amount ("closing_fee",
+ &p->fees.closing),
+ GNUNET_JSON_pack_timestamp ("start_date",
+ p->start_date),
+ GNUNET_JSON_pack_timestamp ("end_date",
+ p->end_date),
+ GNUNET_JSON_pack_data_auto ("sig",
+ &p->master_sig))));
+ }
+ GNUNET_assert (0 ==
+ json_object_set_new (wire_fees,
+ fbw->method,
+ wf));
+ }
+
+ recoup = json_array ();
+ GNUNET_assert (NULL != recoup);
+ for (unsigned int i = 0; i<kd->num_denom_keys; i++)
+ {
+ const struct TALER_EXCHANGE_DenomPublicKey *dk
+ = &kd->denom_keys[i];
+ if (! dk->revoked)
+ continue;
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ recoup,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("h_denom_pub",
+ &dk->h_key))));
+ }
+
+ wblwk = json_array ();
+ GNUNET_assert (NULL != wblwk);
+ for (unsigned int i = 0; i<kd->wblwk_length; i++)
+ {
+ const struct TALER_Amount *a = &kd->wallet_balance_limit_without_kyc[i];
+
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ wblwk,
+ TALER_JSON_from_amount (a)));
+ }
+
+ keys = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("version",
+ kd->version),
+ GNUNET_JSON_pack_string ("currency",
+ kd->currency),
+ GNUNET_JSON_pack_object_steal ("currency_specification",
+ TALER_CONFIG_currency_specs_to_json (
+ &kd->cspec)),
+ TALER_JSON_pack_amount ("stefan_abs",
+ &kd->stefan_abs),
+ TALER_JSON_pack_amount ("stefan_log",
+ &kd->stefan_log),
+ GNUNET_JSON_pack_double ("stefan_lin",
+ kd->stefan_lin),
+ GNUNET_JSON_pack_string ("asset_type",
+ kd->asset_type),
+ GNUNET_JSON_pack_data_auto ("master_public_key",
+ &kd->master_pub),
+ GNUNET_JSON_pack_time_rel ("reserve_closing_delay",
+ kd->reserve_closing_delay),
+ GNUNET_JSON_pack_timestamp ("list_issue_date",
+ kd->list_issue_date),
+ GNUNET_JSON_pack_array_steal ("global_fees",
+ global_fees),
+ GNUNET_JSON_pack_array_steal ("signkeys",
+ signkeys),
+ GNUNET_JSON_pack_object_steal ("wire_fees",
+ wire_fees),
+ GNUNET_JSON_pack_array_steal ("accounts",
+ accounts),
+ GNUNET_JSON_pack_array_steal ("wads",
+ json_array ()),
+ GNUNET_JSON_pack_array_steal ("denominations",
+ denominations_by_group),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_array_steal ("recoup",
+ recoup)),
+ GNUNET_JSON_pack_array_steal ("auditors",
+ auditors),
+ GNUNET_JSON_pack_bool ("rewards_allowed",
+ kd->rewards_allowed),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("extensions",
+ kd->extensions)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_is_zero (&kd->extensions_sig)
+ ? GNUNET_JSON_pack_string ("dummy",
+ NULL)
+ : GNUNET_JSON_pack_data_auto ("extensions_sig",
+ &kd->extensions_sig)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_array_steal ("wallet_balance_limit_without_kyc",
+ wblwk))
+
+ );
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("version",
+ EXCHANGE_SERIALIZATION_FORMAT_VERSION),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_timestamp ("expire",
+ kd->key_data_expiration)),
+ GNUNET_JSON_pack_string ("exchange_url",
+ kd->exchange_url),
+ GNUNET_JSON_pack_object_steal ("keys",
+ keys));
}
diff --git a/src/lib/exchange_api_handle.h b/src/lib/exchange_api_handle.h
index 7ef88489e..7c01b9a9f 100644
--- a/src/lib/exchange_api_handle.h
+++ b/src/lib/exchange_api_handle.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015 Taler Systems SA
+ Copyright (C) 2014, 2015, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -25,179 +25,23 @@
#include <gnunet/gnunet_curl_lib.h>
#include "taler_auditor_service.h"
#include "taler_exchange_service.h"
-#include "taler_crypto_lib.h"
+#include "taler_util.h"
#include "taler_curl_lib.h"
-/**
- * Entry in DLL of auditors used by an exchange.
- */
-struct TEAH_AuditorListEntry;
-
-
-/**
- * Entry in list of ongoing interactions with an auditor.
- */
-struct TEAH_AuditorInteractionEntry
-{
- /**
- * DLL entry.
- */
- struct TEAH_AuditorInteractionEntry *next;
-
- /**
- * DLL entry.
- */
- struct TEAH_AuditorInteractionEntry *prev;
-
- /**
- * Which auditor is this action associated with?
- */
- struct TEAH_AuditorListEntry *ale;
-
- /**
- * Interaction state.
- */
- struct TALER_AUDITOR_DepositConfirmationHandle *dch;
-};
-
-/**
- * Stages of initialization for the `struct TALER_EXCHANGE_Handle`
- */
-enum ExchangeHandleState
-{
- /**
- * Just allocated.
- */
- MHS_INIT = 0,
-
- /**
- * Obtained the exchange's certification data and keys.
- */
- MHS_CERT = 1,
-
- /**
- * Failed to initialize (fatal).
- */
- MHS_FAILED = 2
-};
-
-
-/**
- * Handle to the exchange
- */
-struct TALER_EXCHANGE_Handle
-{
- /**
- * The context of this handle
- */
- struct GNUNET_CURL_Context *ctx;
-
- /**
- * The URL of the exchange (i.e. "http://exchange.taler.net/")
- */
- char *url;
-
- /**
- * Function to call with the exchange's certification data,
- * NULL if this has already been done.
- */
- TALER_EXCHANGE_CertificationCallback cert_cb;
-
- /**
- * Closure to pass to @e cert_cb.
- */
- void *cert_cb_cls;
-
- /**
- * Data for the request to get the /keys of a exchange,
- * NULL once we are past stage #MHS_INIT.
- */
- struct KeysRequest *kr;
-
- /**
- * Task for retrying /keys request.
- */
- struct GNUNET_SCHEDULER_Task *retry_task;
-
- /**
- * Raw key data of the exchange, only valid if
- * @e handshake_complete is past stage #MHS_CERT.
- */
- json_t *key_data_raw;
-
- /**
- * Head of DLL of auditors of this exchange.
- */
- struct TEAH_AuditorListEntry *auditors_head;
-
- /**
- * Tail of DLL of auditors of this exchange.
- */
- struct TEAH_AuditorListEntry *auditors_tail;
-
- /**
- * Key data of the exchange, only valid if
- * @e handshake_complete is past stage #MHS_CERT.
- */
- struct TALER_EXCHANGE_Keys key_data;
-
- /**
- * Retry /keys frequency.
- */
- struct GNUNET_TIME_Relative retry_delay;
-
- /**
- * When does @e key_data expire?
- */
- struct GNUNET_TIME_Timestamp key_data_expiration;
-
- /**
- * Number of subsequent failed requests to /keys.
- *
- * Used to compute the CURL timeout for the request.
- */
- unsigned int keys_error_count;
-
- /**
- * Number of subsequent failed requests to /wire.
- *
- * Used to compute the CURL timeout for the request.
- */
- unsigned int wire_error_count;
-
- /**
- * Stage of the exchange's initialization routines.
- */
- enum ExchangeHandleState state;
-
-};
-
/**
* Function called for each auditor to give us a chance to possibly
* launch a deposit confirmation interaction.
*
* @param cls closure
- * @param ah handle to the auditor
+ * @param auditor_url base URL of the auditor
* @param auditor_pub public key of the auditor
- * @return NULL if no deposit confirmation interaction was launched
*/
-typedef struct TEAH_AuditorInteractionEntry *
-(*TEAH_AuditorCallback)(void *cls,
- struct TALER_AUDITOR_Handle *ah,
- const struct TALER_AuditorPublicKeyP *auditor_pub);
-
-
-/**
- * Signature of functions called with the result from our call to the
- * auditor's /deposit-confirmation handler.
- *
- * @param cls closure of type `struct TEAH_AuditorInteractionEntry *`
- * @param hr HTTP response
- */
-void
-TEAH_acc_confirmation_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr);
+typedef void
+(*TEAH_AuditorCallback)(
+ void *cls,
+ const char *auditor_url,
+ const struct TALER_AuditorPublicKeyP *auditor_pub);
/**
@@ -205,55 +49,16 @@ TEAH_acc_confirmation_cb (void *cls,
* @a ac and giving it a chance to start a deposit
* confirmation interaction.
*
- * @param h exchange to go over auditors for
+ * @param keys the keys to go over auditors for
* @param ac function to call per auditor
* @param ac_cls closure for @a ac
*/
void
-TEAH_get_auditors_for_dc (struct TALER_EXCHANGE_Handle *h,
- TEAH_AuditorCallback ac,
- void *ac_cls);
-
+TEAH_get_auditors_for_dc (
+ struct TALER_EXCHANGE_Keys *keys,
+ TEAH_AuditorCallback ac,
+ void *ac_cls);
-/**
- * Get the context of a exchange.
- *
- * @param h the exchange handle to query
- * @return ctx context to execute jobs in
- */
-struct GNUNET_CURL_Context *
-TEAH_handle_to_context (struct TALER_EXCHANGE_Handle *h);
-
-
-/**
- * Check if the handle is ready to process requests.
- *
- * @param h the exchange handle to query
- * @return #GNUNET_YES if we are ready, #GNUNET_NO if not
- */
-enum GNUNET_GenericReturnValue
-TEAH_handle_is_ready (struct TALER_EXCHANGE_Handle *h);
-
-/**
- * Check if the handle is ready to process requests.
- *
- * @param h the exchange handle to query
- * @return #GNUNET_YES if we are ready, #GNUNET_NO if not
- */
-enum GNUNET_GenericReturnValue
-TEAH_handle_is_ready (struct TALER_EXCHANGE_Handle *h);
-
-
-/**
- * Obtain the URL to use for an API request.
- *
- * @param h the exchange handle to query
- * @param path Taler API path (i.e. "/reserve/withdraw")
- * @return the full URL to use with cURL
- */
-char *
-TEAH_path_to_url (struct TALER_EXCHANGE_Handle *h,
- const char *path);
/* end of exchange_api_handle.h */
#endif
diff --git a/src/lib/exchange_api_kyc_check.c b/src/lib/exchange_api_kyc_check.c
index 62a1db582..5d3b3792b 100644
--- a/src/lib/exchange_api_kyc_check.c
+++ b/src/lib/exchange_api_kyc_check.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -37,14 +37,14 @@ struct TALER_EXCHANGE_KycCheckHandle
{
/**
- * The connection to exchange this request handle will use
+ * The url for this request.
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ char *url;
/**
- * The url for this request.
+ * Keys of the exchange.
*/
- char *url;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* Handle for the request.
@@ -65,6 +65,7 @@ struct TALER_EXCHANGE_KycCheckHandle
* Hash of the payto:// URL that is being KYC'ed.
*/
struct TALER_PaytoHashP h_payto;
+
};
@@ -95,16 +96,20 @@ handle_kyc_check_finished (void *cls,
break;
case MHD_HTTP_OK:
{
+ const json_t *kyc_details;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &ks.details.kyc_ok.exchange_sig),
+ &ks.details.ok.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &ks.details.kyc_ok.exchange_pub),
+ &ks.details.ok.exchange_pub),
GNUNET_JSON_spec_timestamp ("now",
- &ks.details.kyc_ok.timestamp),
+ &ks.details.ok.timestamp),
+ GNUNET_JSON_spec_object_const ("kyc_details",
+ &kyc_details),
+ TALER_JSON_spec_aml_decision ("aml_status",
+ &ks.details.ok.aml_status),
GNUNET_JSON_spec_end ()
};
- const struct TALER_EXCHANGE_Keys *key_state;
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -116,10 +121,10 @@ handle_kyc_check_finished (void *cls,
ks.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
}
- key_state = TALER_EXCHANGE_get_keys (kch->exchange);
+ ks.details.ok.kyc_details = kyc_details;
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- &ks.details.kyc_ok.exchange_pub))
+ TALER_EXCHANGE_test_signing_key (kch->keys,
+ &ks.details.ok.exchange_pub))
{
GNUNET_break_op (0);
ks.http_status = 0;
@@ -131,9 +136,10 @@ handle_kyc_check_finished (void *cls,
if (GNUNET_OK !=
TALER_exchange_online_account_setup_success_verify (
&kch->h_payto,
- ks.details.kyc_ok.timestamp,
- &ks.details.kyc_ok.exchange_pub,
- &ks.details.kyc_ok.exchange_sig))
+ ks.details.ok.kyc_details,
+ ks.details.ok.timestamp,
+ &ks.details.ok.exchange_pub,
+ &ks.details.ok.exchange_sig))
{
GNUNET_break_op (0);
ks.http_status = 0;
@@ -150,8 +156,10 @@ handle_kyc_check_finished (void *cls,
case MHD_HTTP_ACCEPTED:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_string ("kyc_url",
- &ks.details.kyc_url),
+ TALER_JSON_spec_web_url ("kyc_url",
+ &ks.details.accepted.kyc_url),
+ TALER_JSON_spec_aml_decision ("aml_status",
+ &ks.details.accepted.aml_status),
GNUNET_JSON_spec_end ()
};
@@ -184,6 +192,31 @@ handle_kyc_check_finished (void *cls,
case MHD_HTTP_NOT_FOUND:
ks.ec = TALER_JSON_get_error_code (j);
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_aml_decision (
+ "aml_status",
+ &ks.details.unavailable_for_legal_reasons.aml_status),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ ks.http_status = 0;
+ ks.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ }
+ kch->cb (kch->cb_cls,
+ &ks);
+ GNUNET_JSON_parse_free (spec);
+ TALER_EXCHANGE_kyc_check_cancel (kch);
+ return;
+ }
case MHD_HTTP_INTERNAL_SERVER_ERROR:
ks.ec = TALER_JSON_get_error_code (j);
/* Server had an internal issue; we should retry, but this API
@@ -206,24 +239,21 @@ handle_kyc_check_finished (void *cls,
struct TALER_EXCHANGE_KycCheckHandle *
-TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
- uint64_t payment_target,
- const struct TALER_PaytoHashP *h_payto,
- struct GNUNET_TIME_Relative timeout,
- TALER_EXCHANGE_KycStatusCallback cb,
- void *cb_cls)
+TALER_EXCHANGE_kyc_check (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ uint64_t requirement_row,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_KYCLOGIC_KycUserType ut,
+ struct GNUNET_TIME_Relative timeout,
+ TALER_EXCHANGE_KycStatusCallback cb,
+ void *cb_cls)
{
struct TALER_EXCHANGE_KycCheckHandle *kch;
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
char *arg_str;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
{
char payto_str[sizeof (*h_payto) * 2];
char *end;
@@ -238,18 +268,19 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
timeout_ms = timeout.rel_value_us
/ GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
GNUNET_asprintf (&arg_str,
- "/kyc-check/%llu?h_payto=%s&timeout_ms=%llu",
- (unsigned long long) payment_target,
+ "kyc-check/%llu/%s/%s?timeout_ms=%llu",
+ (unsigned long long) requirement_row,
payto_str,
+ TALER_KYCLOGIC_kyc_user_type2s (ut),
timeout_ms);
}
kch = GNUNET_new (struct TALER_EXCHANGE_KycCheckHandle);
- kch->exchange = exchange;
kch->h_payto = *h_payto;
kch->cb = cb;
kch->cb_cls = cb_cls;
- kch->url = TEAH_path_to_url (exchange,
- arg_str);
+ kch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
GNUNET_free (arg_str);
if (NULL == kch->url)
{
@@ -264,7 +295,7 @@ TALER_EXCHANGE_kyc_check (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (kch);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
+ kch->keys = TALER_EXCHANGE_keys_incref (keys);
kch->job = GNUNET_CURL_job_add_with_ct_json (ctx,
eh,
&handle_kyc_check_finished,
@@ -281,6 +312,7 @@ TALER_EXCHANGE_kyc_check_cancel (struct TALER_EXCHANGE_KycCheckHandle *kch)
GNUNET_CURL_job_cancel (kch->job);
kch->job = NULL;
}
+ TALER_EXCHANGE_keys_decref (kch->keys);
GNUNET_free (kch->url);
GNUNET_free (kch);
}
diff --git a/src/lib/exchange_api_kyc_proof.c b/src/lib/exchange_api_kyc_proof.c
index d3debbdb9..e7cc9c4cf 100644
--- a/src/lib/exchange_api_kyc_proof.c
+++ b/src/lib/exchange_api_kyc_proof.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021, 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -37,11 +37,6 @@ struct TALER_EXCHANGE_KycProofHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -140,24 +135,22 @@ handle_kyc_proof_finished (void *cls,
struct TALER_EXCHANGE_KycProofHandle *
-TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_PaytoHashP *h_payto,
- const char *code,
- const char *state,
- TALER_EXCHANGE_KycProofCallback cb,
- void *cb_cls)
+TALER_EXCHANGE_kyc_proof (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_PaytoHashP *h_payto,
+ const char *logic,
+ const char *args,
+ TALER_EXCHANGE_KycProofCallback cb,
+ void *cb_cls)
{
struct TALER_EXCHANGE_KycProofHandle *kph;
- struct GNUNET_CURL_Context *ctx;
char *arg_str;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
- /* TODO: any escaping of code/state needed??? */
+ if (NULL == args)
+ args = "";
+ else
+ GNUNET_assert (args[0] == '&');
{
char hstr[sizeof (struct TALER_PaytoHashP) * 2];
char *end;
@@ -168,17 +161,17 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,
sizeof (hstr));
*end = '\0';
GNUNET_asprintf (&arg_str,
- "/kyc-proof/%s?code=%s&state=%s",
+ "kyc-proof/%s?state=%s%s",
+ logic,
hstr,
- code,
- state);
+ args);
}
kph = GNUNET_new (struct TALER_EXCHANGE_KycProofHandle);
- kph->exchange = exchange;
kph->cb = cb;
kph->cb_cls = cb_cls;
- kph->url = TEAH_path_to_url (exchange,
- arg_str);
+ kph->url = TALER_url_join (url,
+ arg_str,
+ NULL);
GNUNET_free (arg_str);
if (NULL == kph->url)
{
@@ -199,7 +192,6 @@ TALER_EXCHANGE_kyc_proof (struct TALER_EXCHANGE_Handle *exchange,
curl_easy_setopt (kph->eh,
CURLOPT_FOLLOWLOCATION,
0L));
- ctx = TEAH_handle_to_context (exchange);
kph->job = GNUNET_CURL_job_add_raw (ctx,
kph->eh,
NULL,
diff --git a/src/lib/exchange_api_kyc_wallet.c b/src/lib/exchange_api_kyc_wallet.c
index fe5e6b702..7197694ae 100644
--- a/src/lib/exchange_api_kyc_wallet.c
+++ b/src/lib/exchange_api_kyc_wallet.c
@@ -43,11 +43,6 @@ struct TALER_EXCHANGE_KycWalletHandle
struct TALER_CURL_PostContext ctx;
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -95,11 +90,28 @@ handle_kyc_wallet_finished (void *cls,
case 0:
ks.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
- case MHD_HTTP_OK:
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ ks.ec = TALER_JSON_get_error_code (j);
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ ks.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ ks.ec = TALER_JSON_get_error_code (j);
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
{
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &ks.payment_target_uuid),
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &ks.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &ks.details.unavailable_for_legal_reasons.requirement_row),
GNUNET_JSON_spec_end ()
};
@@ -115,19 +127,6 @@ handle_kyc_wallet_finished (void *cls,
}
break;
}
- case MHD_HTTP_NO_CONTENT:
- break;
- case MHD_HTTP_BAD_REQUEST:
- ks.ec = TALER_JSON_get_error_code (j);
- /* This should never happen, either us or the exchange is buggy
- (or API version conflict); just pass JSON reply to the application */
- break;
- case MHD_HTTP_FORBIDDEN:
- ks.ec = TALER_JSON_get_error_code (j);
- break;
- case MHD_HTTP_NOT_FOUND:
- ks.ec = TALER_JSON_get_error_code (j);
- break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
ks.ec = TALER_JSON_get_error_code (j);
/* Server had an internal issue; we should retry, but this API
@@ -150,41 +149,45 @@ handle_kyc_wallet_finished (void *cls,
struct TALER_EXCHANGE_KycWalletHandle *
-TALER_EXCHANGE_kyc_wallet (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_KycWalletCallback cb,
- void *cb_cls)
+TALER_EXCHANGE_kyc_wallet (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *balance,
+ TALER_EXCHANGE_KycWalletCallback cb,
+ void *cb_cls)
{
struct TALER_EXCHANGE_KycWalletHandle *kwh;
CURL *eh;
json_t *req;
- struct GNUNET_CURL_Context *ctx;
struct TALER_ReservePublicKeyP reserve_pub;
struct TALER_ReserveSignatureP reserve_sig;
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
&reserve_pub.eddsa_pub);
TALER_wallet_account_setup_sign (reserve_priv,
+ balance,
&reserve_sig);
req = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("balance",
+ balance),
GNUNET_JSON_pack_data_auto ("reserve_pub",
&reserve_pub),
GNUNET_JSON_pack_data_auto ("reserve_sig",
&reserve_sig));
GNUNET_assert (NULL != req);
kwh = GNUNET_new (struct TALER_EXCHANGE_KycWalletHandle);
- kwh->exchange = exchange;
kwh->cb = cb;
kwh->cb_cls = cb_cls;
- kwh->url = TEAH_path_to_url (exchange,
- "/kyc-wallet");
+ kwh->url = TALER_url_join (url,
+ "kyc-wallet",
+ NULL);
if (NULL == kwh->url)
{
json_decref (req);
GNUNET_free (kwh);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
eh = TALER_EXCHANGE_curl_easy_get_ (kwh->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
diff --git a/src/lib/exchange_api_link.c b/src/lib/exchange_api_link.c
index 9e8625ed5..4b1adc723 100644
--- a/src/lib/exchange_api_link.c
+++ b/src/lib/exchange_api_link.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2021 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -37,11 +37,6 @@ struct TALER_EXCHANGE_LinkHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -94,9 +89,9 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
struct TALER_BlindedDenominationSignature bsig;
struct TALER_DenominationPublicKey rpub;
struct TALER_CoinSpendSignatureP link_sig;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_ExchangeWithdrawValues alg_values;
- struct TALER_CsNonce nonce;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
bool no_nonce;
uint32_t coin_idx;
struct GNUNET_JSON_Specification spec[] = {
@@ -119,6 +114,7 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
struct TALER_TransferSecretP secret;
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
+ struct TALER_AgeCommitmentHash *pah = NULL;
/* parse reply */
if (GNUNET_OK !=
@@ -142,49 +138,43 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
&alg_values,
&bks);
- lci->age_commitment_proof = NULL;
- lci->h_age_commitment = NULL;
+ lci->has_age_commitment = false;
/* Derive the age commitment and calculate the hash */
if (NULL != lh->age_commitment_proof)
{
- lci->age_commitment_proof = GNUNET_new (struct TALER_AgeCommitmentProof);
- lci->h_age_commitment = GNUNET_new (struct TALER_AgeCommitmentHash);
GNUNET_assert (GNUNET_OK ==
TALER_age_commitment_derive (
lh->age_commitment_proof,
&secret.key,
- lci->age_commitment_proof));
+ &lci->age_commitment_proof));
TALER_age_commitment_hash (
- &(lci->age_commitment_proof->commitment),
- lci->h_age_commitment);
+ &lci->age_commitment_proof.commitment,
+ &lci->h_age_commitment);
+
+ lci->has_age_commitment = true;
+ pah = &lci->h_age_commitment;
}
if (GNUNET_OK !=
- TALER_planchet_prepare (&rpub,
- &alg_values,
- &bks,
- &lci->coin_priv,
- lci->h_age_commitment,
- &c_hash,
- &pd))
+ TALER_planchet_prepare (
+ &rpub,
+ &alg_values,
+ &bks,
+ no_nonce
+ ? NULL
+ : &nonce,
+ &lci->coin_priv,
+ pah,
+ &c_hash,
+ &pd))
{
GNUNET_break (0);
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
- if (TALER_DENOMINATION_CS == alg_values.cipher)
- {
- if (no_nonce)
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- pd.blinded_planchet.details.cs_blinded_planchet.nonce = nonce;
- }
/* extract coin and signature */
if (GNUNET_OK !=
TALER_denom_sig_unblind (&lci->sig,
@@ -224,8 +214,8 @@ parse_link_coin (const struct TALER_EXCHANGE_LinkHandle *lh,
}
/* clean up */
- TALER_denom_pub_deep_copy (&lci->pub,
- &rpub);
+ TALER_denom_pub_copy (&lci->pub,
+ &rpub);
GNUNET_JSON_parse_free (spec);
return GNUNET_OK;
}
@@ -270,9 +260,10 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
whilst 'i' and 'session' track the 2d array. *///
for (session = 0; session<json_array_size (json); session++)
{
- json_t *jsona;
+ const json_t *jsona;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("new_coins", &jsona),
+ GNUNET_JSON_spec_array_const ("new_coins",
+ &jsona),
GNUNET_JSON_spec_end ()
};
@@ -285,16 +276,8 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (jsona))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
-
/* count all coins over all sessions */
num_coins += json_array_size (jsona);
- GNUNET_JSON_parse_free (spec);
}
/* Now that we know how big the 1d array is, allocate
and fill it. */
@@ -307,11 +290,11 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
off_coin = 0;
for (session = 0; session<json_array_size (json); session++)
{
- json_t *jsona;
+ const json_t *jsona;
struct TALER_TransferPublicKeyP trans_pub;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("new_coins",
- &jsona),
+ GNUNET_JSON_spec_array_const ("new_coins",
+ &jsona),
GNUNET_JSON_spec_fixed_auto ("transfer_pub",
&trans_pub),
GNUNET_JSON_spec_end ()
@@ -326,12 +309,6 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (jsona))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
/* decode all coins */
for (i = 0; i<json_array_size (jsona); i++)
@@ -357,16 +334,14 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
{
GNUNET_break_op (0);
ret = GNUNET_SYSERR;
- GNUNET_JSON_parse_free (spec);
break;
}
- GNUNET_JSON_parse_free (spec);
} /* end of for (session) */
if (off_coin == num_coins)
{
- lr.details.success.num_coins = num_coins;
- lr.details.success.coins = lcis;
+ lr.details.ok.num_coins = num_coins;
+ lr.details.ok.coins = lcis;
lh->link_cb (lh->link_cb_cls,
&lr);
lh->link_cb = NULL;
@@ -384,6 +359,8 @@ parse_link_ok (struct TALER_EXCHANGE_LinkHandle *lh,
{
TALER_denom_sig_free (&lcis[i].sig);
TALER_denom_pub_free (&lcis[i].pub);
+ if (lcis[i].has_age_commitment)
+ TALER_age_commitment_proof_free (&lcis[i].age_commitment_proof);
}
}
return ret;
@@ -466,26 +443,19 @@ handle_link_finished (void *cls,
struct TALER_EXCHANGE_LinkHandle *
-TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_CoinSpendPrivateKeyP *coin_priv,
- const struct
- TALER_AgeCommitmentProof *age_commitment_proof,
- TALER_EXCHANGE_LinkCallback link_cb,
- void *link_cb_cls)
+TALER_EXCHANGE_link (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ const struct TALER_AgeCommitmentProof *age_commitment_proof,
+ TALER_EXCHANGE_LinkCallback link_cb,
+ void *link_cb_cls)
{
struct TALER_EXCHANGE_LinkHandle *lh;
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
struct TALER_CoinSpendPublicKeyP coin_pub;
char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
-
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
{
@@ -500,17 +470,17 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange,
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/coins/%s/link",
+ "coins/%s/link",
pub_str);
}
lh = GNUNET_new (struct TALER_EXCHANGE_LinkHandle);
- lh->exchange = exchange;
lh->link_cb = link_cb;
lh->link_cb_cls = link_cb_cls;
lh->coin_priv = *coin_priv;
lh->age_commitment_proof = age_commitment_proof;
- lh->url = TEAH_path_to_url (exchange,
- arg_str);
+ lh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == lh->url)
{
GNUNET_free (lh);
@@ -524,7 +494,6 @@ TALER_EXCHANGE_link (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_free (lh);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
lh->job = GNUNET_CURL_job_add_with_ct_json (ctx,
eh,
&handle_link_finished,
@@ -541,6 +510,7 @@ TALER_EXCHANGE_link_cancel (struct TALER_EXCHANGE_LinkHandle *lh)
GNUNET_CURL_job_cancel (lh->job);
lh->job = NULL;
}
+
GNUNET_free (lh->url);
GNUNET_free (lh);
}
diff --git a/src/lib/exchange_api_lookup_aml_decision.c b/src/lib/exchange_api_lookup_aml_decision.c
new file mode 100644
index 000000000..501b9d185
--- /dev/null
+++ b/src/lib/exchange_api_lookup_aml_decision.c
@@ -0,0 +1,417 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_lookup_aml_decision.c
+ * @brief Implementation of the /aml/$OFFICER_PUB/decision request
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A /coins/$COIN_PUB/link Handle
+ */
+struct TALER_EXCHANGE_LookupAmlDecision
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_LookupAmlDecisionCallback decision_cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *decision_cb_cls;
+
+ /**
+ * HTTP headers for the job.
+ */
+ struct curl_slist *job_headers;
+};
+
+
+/**
+ * Parse AML decision history.
+ *
+ * @param aml_history JSON array with AML history
+ * @param[out] aml_history_ar where to write the result
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_aml_history (const json_t *aml_history,
+ struct TALER_EXCHANGE_AmlDecisionDetail *aml_history_ar)
+{
+ json_t *obj;
+ size_t idx;
+
+ json_array_foreach (aml_history, idx, obj)
+ {
+ struct TALER_EXCHANGE_AmlDecisionDetail *aml = &aml_history_ar[idx];
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_timestamp ("decision_time",
+ &aml->decision_time),
+ GNUNET_JSON_spec_string ("justification",
+ &aml->justification),
+ TALER_JSON_spec_amount_any ("new_threshold",
+ &aml->new_threshold),
+ TALER_JSON_spec_aml_decision ("new_state",
+ &aml->new_state),
+ GNUNET_JSON_spec_fixed_auto ("decider_pub",
+ &aml->decider_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (obj,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse KYC response array.
+ *
+ * @param kyc_attributes JSON array with KYC details
+ * @param[out] kyc_attributes_ar where to write the result
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_kyc_attributes (const json_t *kyc_attributes,
+ struct TALER_EXCHANGE_KycHistoryDetail *kyc_attributes_ar)
+{
+ json_t *obj;
+ size_t idx;
+
+ json_array_foreach (kyc_attributes, idx, obj)
+ {
+ struct TALER_EXCHANGE_KycHistoryDetail *kyc = &kyc_attributes_ar[idx];
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_timestamp ("collection_time",
+ &kyc->collection_time),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_object_const ("attributes",
+ &kyc->attributes),
+ NULL),
+ GNUNET_JSON_spec_string ("provider_section",
+ &kyc->provider_section),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (obj,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse the provided decision data from the "200 OK" response.
+ *
+ * @param[in,out] lh handle (callback may be zero'ed out)
+ * @param json json reply with the data for one coin
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static enum GNUNET_GenericReturnValue
+parse_decision_ok (struct TALER_EXCHANGE_LookupAmlDecision *lh,
+ const json_t *json)
+{
+ struct TALER_EXCHANGE_AmlDecisionResponse lr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
+ };
+ const json_t *aml_history;
+ const json_t *kyc_attributes;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("aml_history",
+ &aml_history),
+ GNUNET_JSON_spec_array_const ("kyc_attributes",
+ &kyc_attributes),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ lr.details.ok.aml_history_length = json_array_size (aml_history);
+ lr.details.ok.kyc_attributes_length = json_array_size (kyc_attributes);
+ {
+ struct TALER_EXCHANGE_AmlDecisionDetail aml_history_ar[
+ GNUNET_NZL (lr.details.ok.aml_history_length)];
+ struct TALER_EXCHANGE_KycHistoryDetail kyc_attributes_ar[
+ GNUNET_NZL (lr.details.ok.kyc_attributes_length)];
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
+
+ memset (aml_history_ar,
+ 0,
+ sizeof (aml_history_ar));
+ memset (kyc_attributes_ar,
+ 0,
+ sizeof (kyc_attributes_ar));
+ lr.details.ok.aml_history = aml_history_ar;
+ lr.details.ok.kyc_attributes = kyc_attributes_ar;
+ ret = parse_aml_history (aml_history,
+ aml_history_ar);
+ if (GNUNET_OK == ret)
+ ret = parse_kyc_attributes (kyc_attributes,
+ kyc_attributes_ar);
+ if (GNUNET_OK == ret)
+ {
+ lh->decision_cb (lh->decision_cb_cls,
+ &lr);
+ lh->decision_cb = NULL;
+ }
+ return ret;
+ }
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /aml/$OFFICER_PUB/decision request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_LookupAmlDecision`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_lookup_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_LookupAmlDecision *lh = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_AmlDecisionResponse lr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ lh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ lr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ parse_decision_ok (lh,
+ j))
+ {
+ GNUNET_break_op (0);
+ lr.hr.http_status = 0;
+ lr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ GNUNET_assert (NULL == lh->decision_cb);
+ TALER_EXCHANGE_lookup_aml_decision_cancel (lh);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, exchange says this coin was not melted; we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, exchange says this coin was not melted; we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange lookup AML decision\n",
+ (unsigned int) response_code,
+ (int) lr.hr.ec);
+ break;
+ }
+ if (NULL != lh->decision_cb)
+ lh->decision_cb (lh->decision_cb_cls,
+ &lr);
+ TALER_EXCHANGE_lookup_aml_decision_cancel (lh);
+}
+
+
+struct TALER_EXCHANGE_LookupAmlDecision *
+TALER_EXCHANGE_lookup_aml_decision (
+ struct GNUNET_CURL_Context *ctx,
+ const char *exchange_url,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ bool history,
+ TALER_EXCHANGE_LookupAmlDecisionCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_LookupAmlDecision *lh;
+ CURL *eh;
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ struct TALER_AmlOfficerSignatureP officer_sig;
+ char arg_str[sizeof (officer_pub) * 2
+ + sizeof (*h_payto) * 2 + 32];
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&officer_priv->eddsa_priv,
+ &officer_pub.eddsa_pub);
+ TALER_officer_aml_query_sign (officer_priv,
+ &officer_sig);
+ {
+ char pub_str[sizeof (officer_pub) * 2];
+ char pt_str[sizeof (*h_payto) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &officer_pub,
+ sizeof (officer_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ end = GNUNET_STRINGS_data_to_string (
+ h_payto,
+ sizeof (*h_payto),
+ pt_str,
+ sizeof (pt_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "aml/%s/decision/%s",
+ pub_str,
+ pt_str);
+ }
+ lh = GNUNET_new (struct TALER_EXCHANGE_LookupAmlDecision);
+ lh->decision_cb = cb;
+ lh->decision_cb_cls = cb_cls;
+ lh->url = TALER_url_join (exchange_url,
+ arg_str,
+ "history",
+ history
+ ? "true"
+ : NULL,
+ NULL);
+ if (NULL == lh->url)
+ {
+ GNUNET_free (lh);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (lh->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (lh->url);
+ GNUNET_free (lh);
+ return NULL;
+ }
+ {
+ char *hdr;
+ char sig_str[sizeof (officer_sig) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &officer_sig,
+ sizeof (officer_sig),
+ sig_str,
+ sizeof (sig_str));
+ *end = '\0';
+
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ TALER_AML_OFFICER_SIGNATURE_HEADER,
+ sig_str);
+ lh->job_headers = curl_slist_append (NULL,
+ hdr);
+ GNUNET_free (hdr);
+ lh->job_headers = curl_slist_append (lh->job_headers,
+ "Content-type: application/json");
+ lh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ lh->job_headers,
+ &handle_lookup_finished,
+ lh);
+ }
+ return lh;
+}
+
+
+void
+TALER_EXCHANGE_lookup_aml_decision_cancel (
+ struct TALER_EXCHANGE_LookupAmlDecision *lh)
+{
+ if (NULL != lh->job)
+ {
+ GNUNET_CURL_job_cancel (lh->job);
+ lh->job = NULL;
+ }
+ curl_slist_free_all (lh->job_headers);
+ GNUNET_free (lh->url);
+ GNUNET_free (lh);
+}
+
+
+/* end of exchange_api_lookup_aml_decision.c */
diff --git a/src/lib/exchange_api_lookup_aml_decisions.c b/src/lib/exchange_api_lookup_aml_decisions.c
new file mode 100644
index 000000000..bb3c18b68
--- /dev/null
+++ b/src/lib/exchange_api_lookup_aml_decisions.c
@@ -0,0 +1,376 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_lookup_aml_decisions.c
+ * @brief Implementation of the /aml/$OFFICER_PUB/decisions request
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A /coins/$COIN_PUB/link Handle
+ */
+struct TALER_EXCHANGE_LookupAmlDecisions
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_LookupAmlDecisionsCallback decisions_cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *decisions_cb_cls;
+
+ /**
+ * HTTP headers for the job.
+ */
+ struct curl_slist *job_headers;
+};
+
+
+/**
+ * Parse AML decision summary array.
+ *
+ * @param decisions JSON array with AML decision summaries
+ * @param[out] decision_ar where to write the result
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_aml_decisions (const json_t *decisions,
+ struct TALER_EXCHANGE_AmlDecisionSummary *decision_ar)
+{
+ json_t *obj;
+ size_t idx;
+
+ json_array_foreach (decisions, idx, obj)
+ {
+ struct TALER_EXCHANGE_AmlDecisionSummary *decision = &decision_ar[idx];
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("h_payto",
+ &decision->h_payto),
+ TALER_JSON_spec_aml_decision ("current_state",
+ &decision->current_state),
+ TALER_JSON_spec_amount_any ("threshold",
+ &decision->threshold),
+ GNUNET_JSON_spec_uint64 ("rowid",
+ &decision->rowid),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (obj,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse the provided decision data from the "200 OK" response.
+ *
+ * @param[in,out] lh handle (callback may be zero'ed out)
+ * @param json json reply with the data for one coin
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
+ */
+static enum GNUNET_GenericReturnValue
+parse_decisions_ok (struct TALER_EXCHANGE_LookupAmlDecisions *lh,
+ const json_t *json)
+{
+ struct TALER_EXCHANGE_AmlDecisionsResponse lr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
+ };
+ const json_t *records;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("records",
+ &records),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (json,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ lr.details.ok.decisions_length = json_array_size (records);
+ {
+ struct TALER_EXCHANGE_AmlDecisionSummary decisions[
+ GNUNET_NZL (lr.details.ok.decisions_length)];
+ enum GNUNET_GenericReturnValue ret = GNUNET_SYSERR;
+
+ lr.details.ok.decisions = decisions;
+ ret = parse_aml_decisions (records,
+ decisions);
+ if (GNUNET_OK == ret)
+ {
+ lh->decisions_cb (lh->decisions_cb_cls,
+ &lr);
+ lh->decisions_cb = NULL;
+ }
+ return ret;
+ }
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /aml/$OFFICER_PUB/decisions request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_LookupAmlDecisions`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_lookup_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_LookupAmlDecisions *lh = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_AmlDecisionsResponse lr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ lh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ lr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ parse_decisions_ok (lh,
+ j))
+ {
+ GNUNET_break_op (0);
+ lr.hr.http_status = 0;
+ lr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ GNUNET_assert (NULL == lh->decisions_cb);
+ TALER_EXCHANGE_lookup_aml_decisions_cancel (lh);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, exchange says this coin was not melted; we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, exchange says this coin was not melted; we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ lr.hr.ec = TALER_JSON_get_error_code (j);
+ lr.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for lookup AML decisions\n",
+ (unsigned int) response_code,
+ (int) lr.hr.ec);
+ break;
+ }
+ if (NULL != lh->decisions_cb)
+ lh->decisions_cb (lh->decisions_cb_cls,
+ &lr);
+ TALER_EXCHANGE_lookup_aml_decisions_cancel (lh);
+}
+
+
+struct TALER_EXCHANGE_LookupAmlDecisions *
+TALER_EXCHANGE_lookup_aml_decisions (
+ struct GNUNET_CURL_Context *ctx,
+ const char *exchange_url,
+ uint64_t start,
+ int delta,
+ enum TALER_AmlDecisionState state,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ TALER_EXCHANGE_LookupAmlDecisionsCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_LookupAmlDecisions *lh;
+ CURL *eh;
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+ struct TALER_AmlOfficerSignatureP officer_sig;
+ char arg_str[sizeof (struct TALER_AmlOfficerPublicKeyP) * 2 + 32];
+ const char *state_str = NULL;
+
+ switch (state)
+ {
+ case TALER_AML_NORMAL:
+ state_str = "normal";
+ break;
+ case TALER_AML_PENDING:
+ state_str = "pending";
+ break;
+ case TALER_AML_FROZEN:
+ state_str = "frozen";
+ break;
+ }
+ GNUNET_assert (NULL != state_str);
+ GNUNET_CRYPTO_eddsa_key_get_public (&officer_priv->eddsa_priv,
+ &officer_pub.eddsa_pub);
+ TALER_officer_aml_query_sign (officer_priv,
+ &officer_sig);
+ {
+ char pub_str[sizeof (officer_pub) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &officer_pub,
+ sizeof (officer_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "aml/%s/decisions/%s",
+ pub_str,
+ state_str);
+ }
+ lh = GNUNET_new (struct TALER_EXCHANGE_LookupAmlDecisions);
+ lh->decisions_cb = cb;
+ lh->decisions_cb_cls = cb_cls;
+ {
+ char delta_s[24];
+ char start_s[24];
+
+ GNUNET_snprintf (delta_s,
+ sizeof (delta_s),
+ "%d",
+ delta);
+ GNUNET_snprintf (start_s,
+ sizeof (start_s),
+ "%llu",
+ (unsigned long long) start);
+ lh->url = TALER_url_join (exchange_url,
+ arg_str,
+ "delta",
+ delta_s,
+ "start",
+ start_s,
+ NULL);
+ }
+ if (NULL == lh->url)
+ {
+ GNUNET_free (lh);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (lh->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (lh->url);
+ GNUNET_free (lh);
+ return NULL;
+ }
+ {
+ char *hdr;
+ char sig_str[sizeof (officer_sig) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &officer_sig,
+ sizeof (officer_sig),
+ sig_str,
+ sizeof (sig_str));
+ *end = '\0';
+
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ TALER_AML_OFFICER_SIGNATURE_HEADER,
+ sig_str);
+ lh->job_headers = curl_slist_append (NULL,
+ hdr);
+ GNUNET_free (hdr);
+ lh->job_headers = curl_slist_append (lh->job_headers,
+ "Content-type: application/json");
+ lh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ lh->job_headers,
+ &handle_lookup_finished,
+ lh);
+ }
+ return lh;
+}
+
+
+void
+TALER_EXCHANGE_lookup_aml_decisions_cancel (
+ struct TALER_EXCHANGE_LookupAmlDecisions *lh)
+{
+ if (NULL != lh->job)
+ {
+ GNUNET_CURL_job_cancel (lh->job);
+ lh->job = NULL;
+ }
+ curl_slist_free_all (lh->job_headers);
+ GNUNET_free (lh->url);
+ GNUNET_free (lh);
+}
+
+
+/* end of exchange_api_lookup_aml_decisions.c */
diff --git a/src/lib/exchange_api_management_add_partner.c b/src/lib/exchange_api_management_add_partner.c
new file mode 100644
index 000000000..fec66c567
--- /dev/null
+++ b/src/lib/exchange_api_management_add_partner.c
@@ -0,0 +1,218 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_management_add_partner.c
+ * @brief functions to add an partner by an AML officer
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "exchange_api_curl_defaults.h"
+#include "taler_signatures.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+
+
+struct TALER_EXCHANGE_ManagementAddPartner
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Minor context that holds body and headers.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ManagementAddPartnerCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Reference to the execution context.
+ */
+ struct GNUNET_CURL_Context *ctx;
+};
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP POST /management/partners request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ManagementAddPartner *`
+ * @param response_code HTTP response code, 0 on error
+ * @param response response body, NULL if not in JSON
+ */
+static void
+handle_add_partner_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ManagementAddPartner *wh = cls;
+ const json_t *json = response;
+ struct TALER_EXCHANGE_ManagementAddPartnerResponse apr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
+ };
+
+ wh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ /* no reply */
+ apr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ apr.hr.hint = "server offline?";
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ apr.hr.ec = TALER_JSON_get_error_code (json);
+ apr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_CONFLICT:
+ apr.hr.ec = TALER_JSON_get_error_code (json);
+ apr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ apr.hr.ec = TALER_JSON_get_error_code (json);
+ apr.hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for adding exchange partner\n",
+ (unsigned int) response_code,
+ (int) apr.hr.ec);
+ break;
+ }
+ if (NULL != wh->cb)
+ {
+ wh->cb (wh->cb_cls,
+ &apr);
+ wh->cb = NULL;
+ }
+ TALER_EXCHANGE_management_add_partner_cancel (wh);
+}
+
+
+struct TALER_EXCHANGE_ManagementAddPartner *
+TALER_EXCHANGE_management_add_partner (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_MasterPublicKeyP *partner_pub,
+ struct GNUNET_TIME_Timestamp start_date,
+ struct GNUNET_TIME_Timestamp end_date,
+ struct GNUNET_TIME_Relative wad_frequency,
+ const struct TALER_Amount *wad_fee,
+ const char *partner_base_url,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementAddPartnerCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_ManagementAddPartner *wh;
+ CURL *eh;
+ json_t *body;
+
+ wh = GNUNET_new (struct TALER_EXCHANGE_ManagementAddPartner);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ctx = ctx;
+ wh->url = TALER_url_join (url,
+ "management/partners",
+ NULL);
+ if (NULL == wh->url)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not construct request URL.\n");
+ GNUNET_free (wh);
+ return NULL;
+ }
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("partner_base_url",
+ partner_base_url),
+ GNUNET_JSON_pack_timestamp ("start_date",
+ start_date),
+ GNUNET_JSON_pack_timestamp ("end_date",
+ end_date),
+ GNUNET_JSON_pack_time_rel ("wad_frequency",
+ wad_frequency),
+ GNUNET_JSON_pack_data_auto ("partner_pub",
+ &partner_pub),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ &master_sig),
+ TALER_JSON_pack_amount ("wad_fee",
+ wad_fee)
+ );
+ eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&wh->post_ctx,
+ eh,
+ body)) )
+ {
+ GNUNET_break (0);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ GNUNET_free (wh->url);
+ return NULL;
+ }
+ json_decref (body);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting URL '%s'\n",
+ wh->url);
+ wh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ wh->post_ctx.headers,
+ &handle_add_partner_finished,
+ wh);
+ if (NULL == wh->job)
+ {
+ TALER_EXCHANGE_management_add_partner_cancel (wh);
+ return NULL;
+ }
+ return wh;
+}
+
+
+void
+TALER_EXCHANGE_management_add_partner_cancel (
+ struct TALER_EXCHANGE_ManagementAddPartner *wh)
+{
+ if (NULL != wh->job)
+ {
+ GNUNET_CURL_job_cancel (wh->job);
+ wh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&wh->post_ctx);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+}
diff --git a/src/lib/exchange_api_management_auditor_disable.c b/src/lib/exchange_api_management_auditor_disable.c
index b1de80f0e..8bce7f74f 100644
--- a/src/lib/exchange_api_management_auditor_disable.c
+++ b/src/lib/exchange_api_management_auditor_disable.c
@@ -81,9 +81,9 @@ handle_auditor_disable_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementAuditorDisableHandle *ah = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementAuditorDisableResponse adr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
ah->job = NULL;
@@ -92,32 +92,32 @@ handle_auditor_disable_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ adr.hr.ec = TALER_JSON_get_error_code (json);
+ adr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management auditor disable\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) adr.hr.ec);
break;
}
if (NULL != ah->cb)
{
ah->cb (ah->cb_cls,
- &hr);
+ &adr);
ah->cb = NULL;
}
TALER_EXCHANGE_management_disable_auditor_cancel (ah);
diff --git a/src/lib/exchange_api_management_auditor_enable.c b/src/lib/exchange_api_management_auditor_enable.c
index af75215ec..41c5049c2 100644
--- a/src/lib/exchange_api_management_auditor_enable.c
+++ b/src/lib/exchange_api_management_auditor_enable.c
@@ -82,9 +82,9 @@ handle_auditor_enable_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementAuditorEnableHandle *ah = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementAuditorEnableResponse aer = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
ah->job = NULL;
@@ -93,28 +93,43 @@ handle_auditor_enable_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ aer.hr.ec = TALER_JSON_get_error_code (json);
+ aer.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ ah->url);
+ if (NULL != json)
+ {
+ aer.hr.ec = TALER_JSON_get_error_code (json);
+ aer.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ aer.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ aer.hr.hint = TALER_ErrorCode_get_hint (aer.hr.ec);
+ }
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ aer.hr.ec = TALER_JSON_get_error_code (json);
+ aer.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ aer.hr.ec = TALER_JSON_get_error_code (json);
+ aer.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management auditor enable\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) aer.hr.ec);
break;
}
if (NULL != ah->cb)
{
ah->cb (ah->cb_cls,
- &hr);
+ &aer);
ah->cb = NULL;
}
TALER_EXCHANGE_management_enable_auditor_cancel (ah);
diff --git a/src/lib/exchange_api_management_drain_profits.c b/src/lib/exchange_api_management_drain_profits.c
new file mode 100644
index 000000000..bc7232b87
--- /dev/null
+++ b/src/lib/exchange_api_management_drain_profits.c
@@ -0,0 +1,213 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_management_drain_profits.c
+ * @brief functions to set wire fees at an exchange
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_curl_defaults.h"
+#include "taler_exchange_service.h"
+#include "taler_signatures.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+
+
+struct TALER_EXCHANGE_ManagementDrainProfitsHandle
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Minor context that holds body and headers.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ManagementDrainProfitsCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Reference to the execution context.
+ */
+ struct GNUNET_CURL_Context *ctx;
+};
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /management/drain request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ManagementDrainProfitsHandle *`
+ * @param response_code HTTP response code, 0 on error
+ * @param response response body, NULL if not in JSON
+ */
+static void
+handle_drain_profits_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ManagementDrainProfitsHandle *dp = cls;
+ const json_t *json = response;
+ struct TALER_EXCHANGE_ManagementDrainResponse dr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
+ };
+
+ dp->job = NULL;
+ switch (response_code)
+ {
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ dr.hr.ec = TALER_JSON_get_error_code (json);
+ dr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_CONFLICT:
+ dr.hr.ec = TALER_JSON_get_error_code (json);
+ dr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_PRECONDITION_FAILED:
+ dr.hr.ec = TALER_JSON_get_error_code (json);
+ dr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ dr.hr.ec = TALER_JSON_get_error_code (json);
+ dr.hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange management drain profits\n",
+ (unsigned int) response_code,
+ (int) dr.hr.ec);
+ break;
+ }
+ if (NULL != dp->cb)
+ {
+ dp->cb (dp->cb_cls,
+ &dr);
+ dp->cb = NULL;
+ }
+ TALER_EXCHANGE_management_drain_profits_cancel (dp);
+}
+
+
+struct TALER_EXCHANGE_ManagementDrainProfitsHandle *
+TALER_EXCHANGE_management_drain_profits (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ const struct TALER_Amount *amount,
+ struct GNUNET_TIME_Timestamp date,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementDrainProfitsCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_ManagementDrainProfitsHandle *dp;
+ CURL *eh;
+ json_t *body;
+
+ dp = GNUNET_new (struct TALER_EXCHANGE_ManagementDrainProfitsHandle);
+ dp->cb = cb;
+ dp->cb_cls = cb_cls;
+ dp->ctx = ctx;
+ dp->url = TALER_url_join (url,
+ "management/drain",
+ NULL);
+ if (NULL == dp->url)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not construct request URL.\n");
+ GNUNET_free (dp);
+ return NULL;
+ }
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("debit_account_section",
+ account_section),
+ GNUNET_JSON_pack_string ("credit_payto_uri",
+ payto_uri),
+ GNUNET_JSON_pack_data_auto ("wtid",
+ wtid),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ master_sig),
+ GNUNET_JSON_pack_timestamp ("date",
+ date),
+ TALER_JSON_pack_amount ("amount",
+ amount));
+ eh = TALER_EXCHANGE_curl_easy_get_ (dp->url);
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&dp->post_ctx,
+ eh,
+ body)) )
+ {
+ GNUNET_break (0);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ GNUNET_free (dp->url);
+ return NULL;
+ }
+ json_decref (body);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting URL '%s'\n",
+ dp->url);
+ dp->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ dp->post_ctx.headers,
+ &handle_drain_profits_finished,
+ dp);
+ if (NULL == dp->job)
+ {
+ TALER_EXCHANGE_management_drain_profits_cancel (dp);
+ return NULL;
+ }
+ return dp;
+}
+
+
+void
+TALER_EXCHANGE_management_drain_profits_cancel (
+ struct TALER_EXCHANGE_ManagementDrainProfitsHandle *dp)
+{
+ if (NULL != dp->job)
+ {
+ GNUNET_CURL_job_cancel (dp->job);
+ dp->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&dp->post_ctx);
+ GNUNET_free (dp->url);
+ GNUNET_free (dp);
+}
diff --git a/src/lib/exchange_api_management_get_keys.c b/src/lib/exchange_api_management_get_keys.c
index 8a279d1ef..b88ddc205 100644
--- a/src/lib/exchange_api_management_get_keys.c
+++ b/src/lib/exchange_api_management_get_keys.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2020 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -26,7 +26,7 @@
#include "exchange_api_curl_defaults.h"
#include "taler_signatures.h"
#include "taler_curl_lib.h"
-#include "taler_crypto_lib.h"
+#include "taler_util.h"
#include "taler_json_lib.h"
/**
@@ -75,27 +75,32 @@ struct TALER_EXCHANGE_ManagementGetKeysHandle
* @param response the response
* @return #GNUNET_OK if the response was well-formed
*/
-static int
+static enum GNUNET_GenericReturnValue
handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
const json_t *response)
{
- struct TALER_EXCHANGE_FutureKeys fk;
- json_t *sk;
- json_t *dk;
+ struct TALER_EXCHANGE_ManagementGetKeysResponse gkr = {
+ .hr.http_status = MHD_HTTP_OK,
+ .hr.reply = response,
+ };
+ struct TALER_EXCHANGE_FutureKeys *fk
+ = &gkr.details.ok.keys;
+ const json_t *sk;
+ const json_t *dk;
bool ok;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("future_denoms",
- &dk),
- GNUNET_JSON_spec_json ("future_signkeys",
- &sk),
+ GNUNET_JSON_spec_array_const ("future_denoms",
+ &dk),
+ GNUNET_JSON_spec_array_const ("future_signkeys",
+ &sk),
GNUNET_JSON_spec_fixed_auto ("master_pub",
- &fk.master_pub),
+ &fk->master_pub),
GNUNET_JSON_spec_fixed_auto ("denom_secmod_public_key",
- &fk.denom_secmod_public_key),
+ &fk->denom_secmod_public_key),
GNUNET_JSON_spec_fixed_auto ("denom_secmod_cs_public_key",
- &fk.denom_secmod_cs_public_key),
+ &fk->denom_secmod_cs_public_key),
GNUNET_JSON_spec_fixed_auto ("signkey_secmod_public_key",
- &fk.signkey_secmod_public_key),
+ &fk->signkey_secmod_public_key),
GNUNET_JSON_spec_end ()
};
@@ -107,22 +112,22 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- fk.num_sign_keys = json_array_size (sk);
- fk.num_denom_keys = json_array_size (dk);
- fk.sign_keys = GNUNET_new_array (
- fk.num_sign_keys,
+ fk->num_sign_keys = json_array_size (sk);
+ fk->num_denom_keys = json_array_size (dk);
+ fk->sign_keys = GNUNET_new_array (
+ fk->num_sign_keys,
struct TALER_EXCHANGE_FutureSigningPublicKey);
- fk.denom_keys = GNUNET_new_array (
- fk.num_denom_keys,
+ fk->denom_keys = GNUNET_new_array (
+ fk->num_denom_keys,
struct TALER_EXCHANGE_FutureDenomPublicKey);
ok = true;
- for (unsigned int i = 0; i<fk.num_sign_keys; i++)
+ for (unsigned int i = 0; i<fk->num_sign_keys; i++)
{
json_t *j = json_array_get (sk,
i);
struct TALER_EXCHANGE_FutureSigningPublicKey *sign_key
- = &fk.sign_keys[i];
- struct GNUNET_JSON_Specification spec[] = {
+ = &fk->sign_keys[i];
+ struct GNUNET_JSON_Specification ispec[] = {
GNUNET_JSON_spec_fixed_auto ("key",
&sign_key->key),
GNUNET_JSON_spec_fixed_auto ("signkey_secmod_sig",
@@ -138,7 +143,7 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
- spec,
+ ispec,
NULL, NULL))
{
GNUNET_break_op (0);
@@ -155,7 +160,7 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
&sign_key->key,
sign_key->valid_from,
duration,
- &fk.signkey_secmod_public_key,
+ &fk->signkey_secmod_public_key,
&sign_key->signkey_secmod_sig))
{
GNUNET_break_op (0);
@@ -164,12 +169,12 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
}
}
}
- for (unsigned int i = 0; i<fk.num_denom_keys; i++)
+ for (unsigned int i = 0; i<fk->num_denom_keys; i++)
{
json_t *j = json_array_get (dk,
i);
struct TALER_EXCHANGE_FutureDenomPublicKey *denom_key
- = &fk.denom_keys[i];
+ = &fk->denom_keys[i];
const char *section_name;
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("value",
@@ -223,20 +228,21 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
TALER_denom_pub_hash (&denom_key->key,
&h_denom_pub);
- switch (denom_key->key.cipher)
+ switch (denom_key->key.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
{
struct TALER_RsaPubHashP h_rsa;
- TALER_rsa_pub_hash (denom_key->key.details.rsa_public_key,
- &h_rsa);
+ TALER_rsa_pub_hash (
+ denom_key->key.bsign_pub_key->details.rsa_public_key,
+ &h_rsa);
if (GNUNET_OK !=
TALER_exchange_secmod_rsa_verify (&h_rsa,
section_name,
denom_key->valid_from,
duration,
- &fk.denom_secmod_public_key,
+ &fk->denom_secmod_public_key,
&denom_key->denom_secmod_sig))
{
GNUNET_break_op (0);
@@ -245,18 +251,19 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
}
}
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
{
struct TALER_CsPubHashP h_cs;
- TALER_cs_pub_hash (&denom_key->key.details.cs_public_key,
- &h_cs);
+ TALER_cs_pub_hash (
+ &denom_key->key.bsign_pub_key->details.cs_public_key,
+ &h_cs);
if (GNUNET_OK !=
TALER_exchange_secmod_cs_verify (&h_cs,
section_name,
denom_key->valid_from,
duration,
- &fk.denom_secmod_cs_public_key,
+ &fk->denom_secmod_cs_public_key,
&denom_key->denom_secmod_sig))
{
GNUNET_break_op (0);
@@ -271,26 +278,18 @@ handle_ok (struct TALER_EXCHANGE_ManagementGetKeysHandle *gh,
break;
}
}
- GNUNET_JSON_parse_free (spec);
if (! ok)
break;
}
if (ok)
{
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = MHD_HTTP_OK,
- .reply = response
- };
-
gh->cb (gh->cb_cls,
- &hr,
- &fk);
+ &gkr);
}
- for (unsigned int i = 0; i<fk.num_denom_keys; i++)
- TALER_denom_pub_free (&fk.denom_keys[i].key);
- GNUNET_free (fk.sign_keys);
- GNUNET_free (fk.denom_keys);
- GNUNET_JSON_parse_free (spec);
+ for (unsigned int i = 0; i<fk->num_denom_keys; i++)
+ TALER_denom_pub_free (&fk->denom_keys[i].key);
+ GNUNET_free (fk->sign_keys);
+ GNUNET_free (fk->denom_keys);
return (ok) ? GNUNET_OK : GNUNET_SYSERR;
}
@@ -310,9 +309,9 @@ handle_get_keys_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementGetKeysHandle *gh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementGetKeysResponse gkr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
gh->job = NULL;
@@ -330,29 +329,43 @@ handle_get_keys_finished (void *cls,
response_code = 0;
}
break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ gh->url);
+ if (NULL != json)
+ {
+ gkr.hr.ec = TALER_JSON_get_error_code (json);
+ gkr.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ gkr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ gkr.hr.hint = TALER_ErrorCode_get_hint (gkr.hr.ec);
+ }
+ break;
default:
/* unexpected response code */
if (NULL != json)
{
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ gkr.hr.ec = TALER_JSON_get_error_code (json);
+ gkr.hr.hint = TALER_JSON_get_error_hint (json);
}
else
{
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = TALER_ErrorCode_get_hint (hr.ec);
+ gkr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ gkr.hr.hint = TALER_ErrorCode_get_hint (gkr.hr.ec);
}
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management get keys\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) gkr.hr.ec);
break;
}
if (NULL != gh->cb)
{
gh->cb (gh->cb_cls,
- &hr,
- NULL);
+ &gkr);
gh->cb = NULL;
}
TALER_EXCHANGE_get_management_keys_cancel (gh);
diff --git a/src/lib/exchange_api_management_post_extensions.c b/src/lib/exchange_api_management_post_extensions.c
index abec4ef09..00d1c5e3f 100644
--- a/src/lib/exchange_api_management_post_extensions.c
+++ b/src/lib/exchange_api_management_post_extensions.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2021 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -83,9 +83,9 @@ handle_post_extensions_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementPostExtensionsHandle *ph = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementPostExtensionsResponse per = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
ph->job = NULL;
@@ -94,28 +94,39 @@ handle_post_extensions_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ per.hr.ec = TALER_JSON_get_error_code (json);
+ per.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ ph->url);
+ if (NULL != json)
+ {
+ per.hr.ec = TALER_JSON_get_error_code (json);
+ per.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ per.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ per.hr.hint = TALER_ErrorCode_get_hint (per.hr.ec);
+ }
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ per.hr.ec = TALER_JSON_get_error_code (json);
+ per.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management post extensions\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) per.hr.ec);
break;
}
if (NULL != ph->cb)
{
ph->cb (ph->cb_cls,
- &hr);
+ &per);
ph->cb = NULL;
}
TALER_EXCHANGE_management_post_extensions_cancel (ph);
@@ -126,7 +137,7 @@ struct TALER_EXCHANGE_ManagementPostExtensionsHandle *
TALER_EXCHANGE_management_post_extensions (
struct GNUNET_CURL_Context *ctx,
const char *url,
- struct TALER_EXCHANGE_ManagementPostExtensionsData *ped,
+ const struct TALER_EXCHANGE_ManagementPostExtensionsData *ped,
TALER_EXCHANGE_ManagementPostExtensionsCallback cb,
void *cb_cls)
{
@@ -151,7 +162,7 @@ TALER_EXCHANGE_management_post_extensions (
body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_object_steal ("extensions",
- ped->extensions),
+ (json_t *) ped->extensions),
GNUNET_JSON_pack_data_auto ("extensions_sig",
&ped->extensions_sig));
diff --git a/src/lib/exchange_api_management_post_keys.c b/src/lib/exchange_api_management_post_keys.c
index 291c0ac02..a46124d90 100644
--- a/src/lib/exchange_api_management_post_keys.c
+++ b/src/lib/exchange_api_management_post_keys.c
@@ -82,9 +82,9 @@ handle_post_keys_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementPostKeysHandle *ph = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementPostKeysResponse pkr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
ph->job = NULL;
@@ -93,32 +93,32 @@ handle_post_keys_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ pkr.hr.ec = TALER_JSON_get_error_code (json);
+ pkr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ pkr.hr.ec = TALER_JSON_get_error_code (json);
+ pkr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_REQUEST_ENTITY_TOO_LARGE:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ pkr.hr.ec = TALER_JSON_get_error_code (json);
+ pkr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ pkr.hr.ec = TALER_JSON_get_error_code (json);
+ pkr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management post keys\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) pkr.hr.ec);
break;
}
if (NULL != ph->cb)
{
ph->cb (ph->cb_cls,
- &hr);
+ &pkr);
ph->cb = NULL;
}
TALER_EXCHANGE_post_management_keys_cancel (ph);
diff --git a/src/lib/exchange_api_management_revoke_denomination_key.c b/src/lib/exchange_api_management_revoke_denomination_key.c
index 8d65b6451..a57704776 100644
--- a/src/lib/exchange_api_management_revoke_denomination_key.c
+++ b/src/lib/exchange_api_management_revoke_denomination_key.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2020 Taler Systems SA
+ Copyright (C) 2015-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -82,9 +82,9 @@ handle_revoke_denomination_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementRevokeDenominationKeyHandle *rh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementRevokeDenominationResponse rdr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
rh->job = NULL;
@@ -92,30 +92,30 @@ handle_revoke_denomination_finished (void *cls,
{
case 0:
/* no reply */
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = "server offline?";
+ rdr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ rdr.hr.hint = "server offline?";
break;
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ rdr.hr.ec = TALER_JSON_get_error_code (json);
+ rdr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ rdr.hr.ec = TALER_JSON_get_error_code (json);
+ rdr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management revoke denomination\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) rdr.hr.ec);
break;
}
if (NULL != rh->cb)
{
rh->cb (rh->cb_cls,
- &hr);
+ &rdr);
rh->cb = NULL;
}
TALER_EXCHANGE_management_revoke_denomination_key_cancel (rh);
@@ -186,6 +186,7 @@ TALER_EXCHANGE_management_revoke_denomination_key (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (rh->url);
+ GNUNET_free (rh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_management_revoke_signing_key.c b/src/lib/exchange_api_management_revoke_signing_key.c
index aac27678f..d2fa78264 100644
--- a/src/lib/exchange_api_management_revoke_signing_key.c
+++ b/src/lib/exchange_api_management_revoke_signing_key.c
@@ -79,9 +79,9 @@ handle_revoke_signing_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *rh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementRevokeSigningKeyResponse rsr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
rh->job = NULL;
@@ -89,30 +89,30 @@ handle_revoke_signing_finished (void *cls,
{
case 0:
/* no reply */
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = "server offline?";
+ rsr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ rsr.hr.hint = "server offline?";
break;
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ rsr.hr.ec = TALER_JSON_get_error_code (json);
+ rsr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ rsr.hr.ec = TALER_JSON_get_error_code (json);
+ rsr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management revoke signkey\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) rsr.hr.ec);
break;
}
if (NULL != rh->cb)
{
rh->cb (rh->cb_cls,
- &hr);
+ &rsr);
rh->cb = NULL;
}
TALER_EXCHANGE_management_revoke_signing_key_cancel (rh);
@@ -176,6 +176,7 @@ TALER_EXCHANGE_management_revoke_signing_key (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (rh->url);
+ GNUNET_free (rh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_management_set_global_fee.c b/src/lib/exchange_api_management_set_global_fee.c
index b600c8cbe..f6282a812 100644
--- a/src/lib/exchange_api_management_set_global_fee.c
+++ b/src/lib/exchange_api_management_set_global_fee.c
@@ -79,9 +79,9 @@ handle_set_global_fee_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementSetGlobalFeeHandle *sgfh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementSetGlobalFeeResponse sfr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
sgfh->job = NULL;
@@ -90,32 +90,47 @@ handle_set_global_fee_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ sfr.hr.ec = TALER_JSON_get_error_code (json);
+ sfr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ sgfh->url);
+ if (NULL != json)
+ {
+ sfr.hr.ec = TALER_JSON_get_error_code (json);
+ sfr.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ sfr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ sfr.hr.hint = TALER_ErrorCode_get_hint (sfr.hr.ec);
+ }
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ sfr.hr.ec = TALER_JSON_get_error_code (json);
+ sfr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_PRECONDITION_FAILED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ sfr.hr.ec = TALER_JSON_get_error_code (json);
+ sfr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ sfr.hr.ec = TALER_JSON_get_error_code (json);
+ sfr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management set global fee\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) sfr.hr.ec);
break;
}
if (NULL != sgfh->cb)
{
sgfh->cb (sgfh->cb_cls,
- &hr);
+ &sfr);
sgfh->cb = NULL;
}
TALER_EXCHANGE_management_set_global_fees_cancel (sgfh);
@@ -130,7 +145,6 @@ TALER_EXCHANGE_management_set_global_fees (
struct GNUNET_TIME_Timestamp validity_end,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterSignatureP *master_sig,
@@ -164,16 +178,12 @@ TALER_EXCHANGE_management_set_global_fees (
validity_end),
TALER_JSON_pack_amount ("history_fee",
&fees->history),
- TALER_JSON_pack_amount ("kyc_fee",
- &fees->kyc),
TALER_JSON_pack_amount ("account_fee",
&fees->account),
TALER_JSON_pack_amount ("purse_fee",
&fees->purse),
GNUNET_JSON_pack_time_rel ("purse_timeout",
purse_timeout),
- GNUNET_JSON_pack_time_rel ("kyc_timeout",
- kyc_timeout),
GNUNET_JSON_pack_time_rel ("history_expiration",
history_expiration),
GNUNET_JSON_pack_uint64 ("purse_account_limit",
@@ -190,6 +200,7 @@ TALER_EXCHANGE_management_set_global_fees (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (sgfh->url);
+ GNUNET_free (sgfh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_management_set_wire_fee.c b/src/lib/exchange_api_management_set_wire_fee.c
index 5951b6e20..aaeae21f4 100644
--- a/src/lib/exchange_api_management_set_wire_fee.c
+++ b/src/lib/exchange_api_management_set_wire_fee.c
@@ -79,9 +79,9 @@ handle_set_wire_fee_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementSetWireFeeHandle *swfh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementSetWireFeeResponse swr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
swfh->job = NULL;
@@ -90,32 +90,47 @@ handle_set_wire_fee_finished (void *cls,
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ swr.hr.ec = TALER_JSON_get_error_code (json);
+ swr.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ swfh->url);
+ if (NULL != json)
+ {
+ swr.hr.ec = TALER_JSON_get_error_code (json);
+ swr.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ swr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ swr.hr.hint = TALER_ErrorCode_get_hint (swr.hr.ec);
+ }
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ swr.hr.ec = TALER_JSON_get_error_code (json);
+ swr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_PRECONDITION_FAILED:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ swr.hr.ec = TALER_JSON_get_error_code (json);
+ swr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ swr.hr.ec = TALER_JSON_get_error_code (json);
+ swr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management set wire fee\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) swr.hr.ec);
break;
}
if (NULL != swfh->cb)
{
swfh->cb (swfh->cb_cls,
- &hr);
+ &swr);
swfh->cb = NULL;
}
TALER_EXCHANGE_management_set_wire_fees_cancel (swfh);
@@ -163,8 +178,6 @@ TALER_EXCHANGE_management_set_wire_fees (
validity_end),
TALER_JSON_pack_amount ("closing_fee",
&fees->closing),
- TALER_JSON_pack_amount ("wad_fee",
- &fees->wad),
TALER_JSON_pack_amount ("wire_fee",
&fees->wire));
eh = TALER_EXCHANGE_curl_easy_get_ (swfh->url);
@@ -179,6 +192,7 @@ TALER_EXCHANGE_management_set_wire_fees (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (swfh->url);
+ GNUNET_free (swfh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_management_update_aml_officer.c b/src/lib/exchange_api_management_update_aml_officer.c
new file mode 100644
index 000000000..af0169b02
--- /dev/null
+++ b/src/lib/exchange_api_management_update_aml_officer.c
@@ -0,0 +1,230 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_management_update_aml_officer.c
+ * @brief functions to update AML officer status
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "exchange_api_curl_defaults.h"
+#include "taler_signatures.h"
+#include "taler_curl_lib.h"
+#include "taler_json_lib.h"
+
+
+struct TALER_EXCHANGE_ManagementUpdateAmlOfficer
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Minor context that holds body and headers.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ManagementUpdateAmlOfficerCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Reference to the execution context.
+ */
+ struct GNUNET_CURL_Context *ctx;
+};
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /management/wire request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ManagementAuditorEnableHandle *`
+ * @param response_code HTTP response code, 0 on error
+ * @param response response body, NULL if not in JSON
+ */
+static void
+handle_update_aml_officer_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *wh = cls;
+ const json_t *json = response;
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficerResponse uar = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
+ };
+
+ wh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ /* no reply */
+ uar.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ uar.hr.hint = "server offline?";
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ uar.hr.ec = TALER_JSON_get_error_code (json);
+ uar.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ wh->url);
+ if (NULL != json)
+ {
+ uar.hr.ec = TALER_JSON_get_error_code (json);
+ uar.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ uar.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ uar.hr.hint = TALER_ErrorCode_get_hint (uar.hr.ec);
+ }
+ break;
+ case MHD_HTTP_CONFLICT:
+ uar.hr.ec = TALER_JSON_get_error_code (json);
+ uar.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ uar.hr.ec = TALER_JSON_get_error_code (json);
+ uar.hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange management update AML officer\n",
+ (unsigned int) response_code,
+ (int) uar.hr.ec);
+ break;
+ }
+ if (NULL != wh->cb)
+ {
+ wh->cb (wh->cb_cls,
+ &uar);
+ wh->cb = NULL;
+ }
+ TALER_EXCHANGE_management_update_aml_officer_cancel (wh);
+}
+
+
+struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *
+TALER_EXCHANGE_management_update_aml_officer (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterSignatureP *master_sig,
+ TALER_EXCHANGE_ManagementUpdateAmlOfficerCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *wh;
+ CURL *eh;
+ json_t *body;
+
+ wh = GNUNET_new (struct TALER_EXCHANGE_ManagementUpdateAmlOfficer);
+ wh->cb = cb;
+ wh->cb_cls = cb_cls;
+ wh->ctx = ctx;
+ wh->url = TALER_url_join (url,
+ "management/aml-officers",
+ NULL);
+ if (NULL == wh->url)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Could not construct request URL.\n");
+ GNUNET_free (wh);
+ return NULL;
+ }
+ body = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("officer_name",
+ officer_name),
+ GNUNET_JSON_pack_data_auto ("officer_pub",
+ officer_pub),
+ GNUNET_JSON_pack_data_auto ("master_sig",
+ master_sig),
+ GNUNET_JSON_pack_bool ("is_active",
+ is_active),
+ GNUNET_JSON_pack_bool ("read_only",
+ read_only),
+ GNUNET_JSON_pack_timestamp ("change_date",
+ change_date));
+ eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
+ if ( (NULL == eh) ||
+ (GNUNET_OK !=
+ TALER_curl_easy_post (&wh->post_ctx,
+ eh,
+ body)) )
+ {
+ GNUNET_break (0);
+ if (NULL != eh)
+ curl_easy_cleanup (eh);
+ json_decref (body);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+ return NULL;
+ }
+ json_decref (body);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting URL '%s'\n",
+ wh->url);
+ wh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ wh->post_ctx.headers,
+ &handle_update_aml_officer_finished,
+ wh);
+ if (NULL == wh->job)
+ {
+ TALER_EXCHANGE_management_update_aml_officer_cancel (wh);
+ return NULL;
+ }
+ return wh;
+}
+
+
+void
+TALER_EXCHANGE_management_update_aml_officer_cancel (
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *wh)
+{
+ if (NULL != wh->job)
+ {
+ GNUNET_CURL_job_cancel (wh->job);
+ wh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&wh->post_ctx);
+ GNUNET_free (wh->url);
+ GNUNET_free (wh);
+}
diff --git a/src/lib/exchange_api_management_wire_disable.c b/src/lib/exchange_api_management_wire_disable.c
index 5d97eef75..23b10c58c 100644
--- a/src/lib/exchange_api_management_wire_disable.c
+++ b/src/lib/exchange_api_management_wire_disable.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2021 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -79,9 +79,9 @@ handle_auditor_disable_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementWireDisableHandle *wh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementWireDisableResponse wdr = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
wh->job = NULL;
@@ -89,38 +89,49 @@ handle_auditor_disable_finished (void *cls,
{
case 0:
/* no reply */
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = "server offline?";
+ wdr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ wdr.hr.hint = "server offline?";
break;
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wdr.hr.ec = TALER_JSON_get_error_code (json);
+ wdr.hr.hint = TALER_JSON_get_error_hint (json);
break;
case MHD_HTTP_NOT_FOUND:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ wh->url);
+ if (NULL != json)
+ {
+ wdr.hr.ec = TALER_JSON_get_error_code (json);
+ wdr.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ wdr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ wdr.hr.hint = TALER_ErrorCode_get_hint (wdr.hr.ec);
+ }
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wdr.hr.ec = TALER_JSON_get_error_code (json);
+ wdr.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wdr.hr.ec = TALER_JSON_get_error_code (json);
+ wdr.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d exchange management disable wire\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) wdr.hr.ec);
break;
}
if (NULL != wh->cb)
{
wh->cb (wh->cb_cls,
- &hr);
+ &wdr);
wh->cb = NULL;
}
TALER_EXCHANGE_management_disable_wire_cancel (wh);
@@ -174,6 +185,7 @@ TALER_EXCHANGE_management_disable_wire (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (wh->url);
+ GNUNET_free (wh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_management_wire_enable.c b/src/lib/exchange_api_management_wire_enable.c
index 55480474e..9a163b558 100644
--- a/src/lib/exchange_api_management_wire_enable.c
+++ b/src/lib/exchange_api_management_wire_enable.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2021 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -79,9 +79,9 @@ handle_auditor_enable_finished (void *cls,
{
struct TALER_EXCHANGE_ManagementWireEnableHandle *wh = cls;
const json_t *json = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .http_status = (unsigned int) response_code,
- .reply = json
+ struct TALER_EXCHANGE_ManagementWireEnableResponse wer = {
+ .hr.http_status = (unsigned int) response_code,
+ .hr.reply = json
};
wh->job = NULL;
@@ -89,34 +89,49 @@ handle_auditor_enable_finished (void *cls,
{
case 0:
/* no reply */
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- hr.hint = "server offline?";
+ wer.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ wer.hr.hint = "server offline?";
break;
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wer.hr.ec = TALER_JSON_get_error_code (json);
+ wer.hr.hint = TALER_JSON_get_error_hint (json);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Server did not find handler at `%s'. Did you configure the correct exchange base URL?\n",
+ wh->url);
+ if (NULL != json)
+ {
+ wer.hr.ec = TALER_JSON_get_error_code (json);
+ wer.hr.hint = TALER_JSON_get_error_hint (json);
+ }
+ else
+ {
+ wer.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ wer.hr.hint = TALER_ErrorCode_get_hint (wer.hr.ec);
+ }
break;
case MHD_HTTP_CONFLICT:
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wer.hr.ec = TALER_JSON_get_error_code (json);
+ wer.hr.hint = TALER_JSON_get_error_hint (json);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (json);
- hr.hint = TALER_JSON_get_error_hint (json);
+ wer.hr.ec = TALER_JSON_get_error_code (json);
+ wer.hr.hint = TALER_JSON_get_error_hint (json);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange management enable wire\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) wer.hr.ec);
break;
}
if (NULL != wh->cb)
{
wh->cb (wh->cb_cls,
- &hr);
+ &wer);
wh->cb = NULL;
}
TALER_EXCHANGE_management_enable_wire_cancel (wh);
@@ -128,9 +143,14 @@ TALER_EXCHANGE_management_enable_wire (
struct GNUNET_CURL_Context *ctx,
const char *url,
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp validity_start,
const struct TALER_MasterSignatureP *master_sig1,
const struct TALER_MasterSignatureP *master_sig2,
+ const char *bank_label,
+ int64_t priority,
TALER_EXCHANGE_ManagementWireEnableCallback cb,
void *cb_cls)
{
@@ -167,6 +187,18 @@ TALER_EXCHANGE_management_enable_wire (
body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string ("payto_uri",
payto_uri),
+ GNUNET_JSON_pack_array_incref ("debit_restrictions",
+ (json_t *) debit_restrictions),
+ GNUNET_JSON_pack_array_incref ("credit_restrictions",
+ (json_t *) credit_restrictions),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("conversion_url",
+ conversion_url)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("bank_label",
+ bank_label)),
+ GNUNET_JSON_pack_int64 ("priority",
+ priority),
GNUNET_JSON_pack_data_auto ("master_sig_add",
master_sig1),
GNUNET_JSON_pack_data_auto ("master_sig_wire",
@@ -185,6 +217,7 @@ TALER_EXCHANGE_management_enable_wire (
curl_easy_cleanup (eh);
json_decref (body);
GNUNET_free (wh->url);
+ GNUNET_free (wh);
return NULL;
}
json_decref (body);
diff --git a/src/lib/exchange_api_melt.c b/src/lib/exchange_api_melt.c
index feeef4001..c2f8cefb7 100644
--- a/src/lib/exchange_api_melt.c
+++ b/src/lib/exchange_api_melt.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2022 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -41,9 +41,9 @@ struct TALER_EXCHANGE_MeltHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -51,6 +51,16 @@ struct TALER_EXCHANGE_MeltHandle
char *url;
/**
+ * The exchange base url.
+ */
+ char *exchange_url;
+
+ /**
+ * Curl context.
+ */
+ struct GNUNET_CURL_Context *cctx;
+
+ /**
* Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/
@@ -159,7 +169,7 @@ verify_melt_signature_ok (struct TALER_EXCHANGE_MeltHandle *mh,
return GNUNET_SYSERR;
}
/* check that exchange signing key is permitted */
- key_state = TALER_EXCHANGE_get_keys (mh->exchange);
+ key_state = mh->keys;
if (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (key_state,
exchange_pub))
@@ -208,10 +218,8 @@ handle_melt_finished (void *cls,
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
mh->job = NULL;
- keys = TALER_EXCHANGE_get_keys (mh->exchange);
switch (response_code)
{
case 0:
@@ -221,16 +229,16 @@ handle_melt_finished (void *cls,
if (GNUNET_OK !=
verify_melt_signature_ok (mh,
j,
- &mr.details.success.sign_key))
+ &mr.details.ok.sign_key))
{
GNUNET_break_op (0);
mr.hr.http_status = 0;
mr.hr.ec = TALER_EC_EXCHANGE_MELT_INVALID_SIGNATURE_BY_EXCHANGE;
break;
}
- mr.details.success.noreveal_index = mh->noreveal_index;
- mr.details.success.num_mbds = mh->rd->fresh_pks_len;
- mr.details.success.mbds = mh->mbds;
+ mr.details.ok.noreveal_index = mh->noreveal_index;
+ mr.details.ok.num_mbds = mh->rd->fresh_pks_len;
+ mr.details.ok.mbds = mh->mbds;
mh->melt_cb (mh->melt_cb_cls,
&mr);
mh->melt_cb = NULL;
@@ -244,20 +252,6 @@ handle_melt_finished (void *cls,
case MHD_HTTP_CONFLICT:
mr.hr.ec = TALER_JSON_get_error_code (j);
mr.hr.hint = TALER_JSON_get_error_hint (j);
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_conflict_ (
- keys,
- j,
- mh->dki,
- &mh->coin_pub,
- &mh->coin_sig,
- &mh->md.melted_coin.melt_amount_with_fee))
- {
- GNUNET_break_op (0);
- mr.hr.http_status = 0;
- mr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
@@ -309,13 +303,18 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
const struct TALER_EXCHANGE_Keys *key_state;
json_t *melt_obj;
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
struct TALER_DenominationHashP h_denom_pub;
struct TALER_ExchangeWithdrawValues alg_values[mh->rd->fresh_pks_len];
for (unsigned int i = 0; i<mh->rd->fresh_pks_len; i++)
- alg_values[i] = mh->mbds[i].alg_value;
+ {
+ if (GNUNET_CRYPTO_BSA_RSA ==
+ mh->rd->fresh_pks[i].key.bsign_pub_key->cipher)
+ alg_values[i] = *TALER_denom_ewv_rsa_singleton ();
+ else
+ alg_values[i] = mh->mbds[i].alg_value;
+ }
if (GNUNET_OK !=
TALER_EXCHANGE_get_melt_data_ (&mh->rms,
mh->rd,
@@ -327,13 +326,14 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
}
TALER_denom_pub_hash (&mh->md.melted_coin.pub_key,
&h_denom_pub);
- TALER_wallet_melt_sign (&mh->md.melted_coin.melt_amount_with_fee,
- &mh->md.melted_coin.fee_melt,
- &mh->md.rc,
- &h_denom_pub,
- mh->md.melted_coin.h_age_commitment,
- &mh->md.melted_coin.coin_priv,
- &mh->coin_sig);
+ TALER_wallet_melt_sign (
+ &mh->md.melted_coin.melt_amount_with_fee,
+ &mh->md.melted_coin.fee_melt,
+ &mh->md.rc,
+ &h_denom_pub,
+ mh->md.melted_coin.h_age_commitment,
+ &mh->md.melted_coin.coin_priv,
+ &mh->coin_sig);
GNUNET_CRYPTO_eddsa_key_get_public (&mh->md.melted_coin.coin_priv.eddsa_priv,
&mh->coin_pub.eddsa_pub);
melt_obj = GNUNET_JSON_PACK (
@@ -348,7 +348,7 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
GNUNET_JSON_pack_data_auto ("rc",
&mh->md.rc),
GNUNET_JSON_pack_allow_null (
- mh->md.melted_coin.h_age_commitment
+ (NULL != mh->md.melted_coin.h_age_commitment)
? GNUNET_JSON_pack_data_auto ("age_commitment_hash",
mh->md.melted_coin.h_age_commitment)
: GNUNET_JSON_pack_string ("age_commitment_hash",
@@ -371,19 +371,19 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/coins/%s/melt",
+ "coins/%s/melt",
pub_str);
}
- ctx = TEAH_handle_to_context (mh->exchange);
- key_state = TALER_EXCHANGE_get_keys (mh->exchange);
+ key_state = mh->keys;
mh->dki = TALER_EXCHANGE_get_denomination_key (key_state,
&mh->md.melted_coin.pub_key);
/* and now we can at last begin the actual request handling */
- mh->url = TEAH_path_to_url (mh->exchange,
- arg_str);
+ mh->url = TALER_url_join (mh->exchange_url,
+ arg_str,
+ NULL);
if (NULL == mh->url)
{
json_decref (melt_obj);
@@ -403,7 +403,7 @@ start_melt (struct TALER_EXCHANGE_MeltHandle *mh)
return GNUNET_SYSERR;
}
json_decref (melt_obj);
- mh->job = GNUNET_CURL_job_add2 (ctx,
+ mh->job = GNUNET_CURL_job_add2 (mh->cctx,
eh,
mh->ctx.headers,
&handle_melt_finished,
@@ -466,19 +466,18 @@ csr_cb (void *cls,
&mh->rd->fresh_pks[i];
struct TALER_ExchangeWithdrawValues *wv = &mh->mbds[i].alg_value;
- switch (fresh_pk->key.cipher)
+ switch (fresh_pk->key.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_INVALID:
+ case GNUNET_CRYPTO_BSA_INVALID:
GNUNET_break (0);
fail_mh (mh,
TALER_EC_GENERIC_CLIENT_INTERNAL_ERROR);
return;
- case TALER_DENOMINATION_RSA:
- GNUNET_assert (TALER_DENOMINATION_RSA == wv->cipher);
+ case GNUNET_CRYPTO_BSA_RSA:
break;
- case TALER_DENOMINATION_CS:
- GNUNET_assert (TALER_DENOMINATION_CS == wv->cipher);
- *wv = csrr->details.success.alg_values[nks_off];
+ case GNUNET_CRYPTO_BSA_CS:
+ TALER_denom_ewv_copy (wv,
+ &csrr->details.ok.alg_values[nks_off]);
nks_off++;
break;
}
@@ -496,11 +495,14 @@ csr_cb (void *cls,
struct TALER_EXCHANGE_MeltHandle *
-TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_RefreshMasterSecretP *rms,
- const struct TALER_EXCHANGE_RefreshData *rd,
- TALER_EXCHANGE_MeltCallback melt_cb,
- void *melt_cb_cls)
+TALER_EXCHANGE_melt (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_RefreshMasterSecretP *rms,
+ const struct TALER_EXCHANGE_RefreshData *rd,
+ TALER_EXCHANGE_MeltCallback melt_cb,
+ void *melt_cb_cls)
{
struct TALER_EXCHANGE_NonceKey nks[GNUNET_NZL (rd->fresh_pks_len)];
unsigned int nks_off = 0;
@@ -511,11 +513,10 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_break (0);
return NULL;
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
mh = GNUNET_new (struct TALER_EXCHANGE_MeltHandle);
mh->noreveal_index = TALER_CNC_KAPPA; /* invalid value */
- mh->exchange = exchange;
+ mh->cctx = ctx;
+ mh->exchange_url = GNUNET_strdup (url);
mh->rd = rd;
mh->rms = *rms;
mh->melt_cb = melt_cb;
@@ -525,29 +526,30 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
for (unsigned int i = 0; i<rd->fresh_pks_len; i++)
{
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk = &rd->fresh_pks[i];
- struct TALER_ExchangeWithdrawValues *wv = &mh->mbds[i].alg_value;
- switch (fresh_pk->key.cipher)
+ switch (fresh_pk->key.bsign_pub_key->cipher)
{
- case TALER_DENOMINATION_INVALID:
+ case GNUNET_CRYPTO_BSA_INVALID:
GNUNET_break (0);
GNUNET_free (mh->mbds);
GNUNET_free (mh);
return NULL;
- case TALER_DENOMINATION_RSA:
- wv->cipher = TALER_DENOMINATION_RSA;
+ case GNUNET_CRYPTO_BSA_RSA:
+ TALER_denom_ewv_copy (&mh->mbds[i].alg_value,
+ TALER_denom_ewv_rsa_singleton ());
break;
- case TALER_DENOMINATION_CS:
- wv->cipher = TALER_DENOMINATION_CS;
+ case GNUNET_CRYPTO_BSA_CS:
nks[nks_off].pk = fresh_pk;
nks[nks_off].cnc_num = nks_off;
nks_off++;
break;
}
}
+ mh->keys = TALER_EXCHANGE_keys_incref (keys);
if (0 != nks_off)
{
- mh->csr = TALER_EXCHANGE_csr_melt (exchange,
+ mh->csr = TALER_EXCHANGE_csr_melt (ctx,
+ url,
rms,
nks_off,
nks,
@@ -575,6 +577,8 @@ TALER_EXCHANGE_melt (struct TALER_EXCHANGE_Handle *exchange,
void
TALER_EXCHANGE_melt_cancel (struct TALER_EXCHANGE_MeltHandle *mh)
{
+ for (unsigned int i = 0; i<mh->rd->fresh_pks_len; i++)
+ TALER_denom_ewv_free (&mh->mbds[i].alg_value);
if (NULL != mh->job)
{
GNUNET_CURL_job_cancel (mh->job);
@@ -588,7 +592,9 @@ TALER_EXCHANGE_melt_cancel (struct TALER_EXCHANGE_MeltHandle *mh)
TALER_EXCHANGE_free_melt_data_ (&mh->md); /* does not free 'md' itself */
GNUNET_free (mh->mbds);
GNUNET_free (mh->url);
+ GNUNET_free (mh->exchange_url);
TALER_curl_easy_post_finished (&mh->ctx);
+ TALER_EXCHANGE_keys_decref (mh->keys);
GNUNET_free (mh);
}
diff --git a/src/lib/exchange_api_purse_create_with_deposit.c b/src/lib/exchange_api_purse_create_with_deposit.c
index ce0221aa6..fff898e57 100644
--- a/src/lib/exchange_api_purse_create_with_deposit.c
+++ b/src/lib/exchange_api_purse_create_with_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -73,9 +73,9 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -83,6 +83,11 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle
char *url;
/**
+ * The base URL of the exchange.
+ */
+ char *exchange_url;
+
+ /**
* Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/
@@ -109,7 +114,7 @@ struct TALER_EXCHANGE_PurseCreateDepositHandle
struct TALER_Amount purse_value_after_fees;
/**
- * Our encryped contract (if we had any).
+ * Our encrypted contract (if we had any).
*/
struct TALER_EncryptedContract econtract;
@@ -170,10 +175,9 @@ handle_purse_create_deposit_finished (void *cls,
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
+ const struct TALER_EXCHANGE_Keys *keys = pch->keys;
pch->job = NULL;
- keys = TALER_EXCHANGE_get_keys (pch->exchange);
switch (response_code)
{
case 0:
@@ -181,7 +185,6 @@ handle_purse_create_deposit_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_TIME_Timestamp etime;
struct TALER_Amount total_deposited;
struct TALER_ExchangeSignatureP exchange_sig;
@@ -209,9 +212,8 @@ handle_purse_create_deposit_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- key_state = TALER_EXCHANGE_get_keys (pch->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (keys,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -275,107 +277,12 @@ handle_purse_create_deposit_finished (void *cls,
}
break;
case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
- {
- struct TALER_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
- bool found = false;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- struct Deposit *deposit = &pch->deposits[i];
-
- if (0 != GNUNET_memcmp (&pcoin_pub,
- &deposit->coin_pub))
- continue;
- if (-1 !=
- TALER_amount_cmp (&left,
- &deposit->contribution))
- {
- /* Balance was sufficient after all; recoup MAY have still been possible */
- GNUNET_break_op (0);
- continue;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_signature_conflict_ (
- j,
- &deposit->coin_sig))
- {
- GNUNET_break_op (0);
- continue;
- }
- found = true;
- break;
- }
- if (! found)
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- break;
- }
+ /* Nothing to check anymore here, proof needs to be
+ checked in the GET /coins/$COIN_PUB handler */
+ break;
case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY:
- {
- struct TALER_Amount left;
- struct TALER_CoinSpendPublicKeyP pcoin_pub;
- bool found = false;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &pcoin_pub,
- &left))
- {
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- struct Deposit *deposit = &pch->deposits[i];
-
- if (0 !=
- GNUNET_memcmp (&pcoin_pub,
- &deposit->coin_pub))
- continue;
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_denomination_conflict_ (
- j,
- &deposit->h_denom_pub))
- {
- /* Eh, same denomination, hence no conflict */
- GNUNET_break_op (0);
- continue;
- }
- found = true;
- }
- if (! found)
- {
- /* conflict is for a different coin! */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* meta data conflict is real! */
- break;
- }
+ // FIXME #7267: write check (add to exchange_api_common! */
+ break;
case TALER_EC_EXCHANGE_PURSE_DEPOSIT_CONFLICTING_META_DATA:
{
struct TALER_CoinSpendPublicKeyP coin_pub;
@@ -387,7 +294,7 @@ handle_purse_create_deposit_finished (void *cls,
if (GNUNET_OK !=
TALER_EXCHANGE_check_purse_coin_conflict_ (
&pch->purse_pub,
- pch->exchange->url,
+ pch->exchange_url,
j,
&h_denom_pub,
&phac,
@@ -496,28 +403,27 @@ handle_purse_create_deposit_finished (void *cls,
struct TALER_EXCHANGE_PurseCreateDepositHandle *
TALER_EXCHANGE_purse_create_with_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
const struct TALER_ContractDiffiePrivateP *contract_priv,
const json_t *contract_terms,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
bool upload_contract,
TALER_EXCHANGE_PurseCreateDepositCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_PurseCreateDepositHandle *pch;
- struct GNUNET_CURL_Context *ctx;
json_t *create_obj;
json_t *deposit_arr;
CURL *eh;
char arg_str[sizeof (pch->purse_pub) * 2 + 32];
- char *url;
uint32_t min_age = 0;
pch = GNUNET_new (struct TALER_EXCHANGE_PurseCreateDepositHandle);
- pch->exchange = exchange;
pch->cb = cb;
pch->cb_cls = cb_cls;
{
@@ -542,8 +448,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
return NULL;
}
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
if (GNUNET_OK !=
TALER_JSON_contract_hash (contract_terms,
&pch->h_contract_terms))
@@ -565,13 +469,14 @@ TALER_EXCHANGE_purse_create_with_deposit (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/create",
+ "purses/%s/create",
pub_str);
}
GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv,
&pch->merge_pub.eddsa_pub);
- pch->url = TEAH_path_to_url (exchange,
- arg_str);
+ pch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pch->url)
{
GNUNET_break (0);
@@ -583,8 +488,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
struct Deposit);
deposit_arr = json_array ();
GNUNET_assert (NULL != deposit_arr);
- url = TEAH_path_to_url (exchange,
- "/");
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Signing with URL `%s'\n",
url);
@@ -609,8 +512,11 @@ TALER_EXCHANGE_purse_create_with_deposit (
&attest))
{
GNUNET_break (0);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
+ GNUNET_free (pch->url);
json_decref (deposit_arr);
- GNUNET_free (url);
GNUNET_free (pch);
return NULL;
}
@@ -648,7 +554,6 @@ TALER_EXCHANGE_purse_create_with_deposit (
json_array_append_new (deposit_arr,
jdeposit));
}
- GNUNET_free (url);
TALER_wallet_purse_create_sign (pch->purse_expiration,
&pch->h_contract_terms,
&pch->merge_pub,
@@ -705,7 +610,9 @@ TALER_EXCHANGE_purse_create_with_deposit (
curl_easy_cleanup (eh);
json_decref (create_obj);
GNUNET_free (pch->econtract.econtract);
- GNUNET_free (pch->deposits);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
GNUNET_free (pch->url);
GNUNET_free (pch);
return NULL;
@@ -714,7 +621,8 @@ TALER_EXCHANGE_purse_create_with_deposit (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse create with deposit: `%s'\n",
pch->url);
- ctx = TEAH_handle_to_context (exchange);
+ pch->keys = TALER_EXCHANGE_keys_incref (keys);
+ pch->exchange_url = GNUNET_strdup (url);
pch->job = GNUNET_CURL_job_add2 (ctx,
eh,
pch->ctx.headers,
@@ -734,8 +642,12 @@ TALER_EXCHANGE_purse_create_with_deposit_cancel (
pch->job = NULL;
}
GNUNET_free (pch->econtract.econtract);
+ GNUNET_free (pch->exchange_url);
GNUNET_free (pch->url);
- GNUNET_free (pch->deposits);
+ GNUNET_array_grow (pch->deposits,
+ pch->num_deposits,
+ 0);
+ TALER_EXCHANGE_keys_decref (pch->keys);
TALER_curl_easy_post_finished (&pch->ctx);
GNUNET_free (pch);
}
diff --git a/src/lib/exchange_api_purse_create_with_merge.c b/src/lib/exchange_api_purse_create_with_merge.c
index f3c72d4f7..0c8878342 100644
--- a/src/lib/exchange_api_purse_create_with_merge.c
+++ b/src/lib/exchange_api_purse_create_with_merge.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -41,9 +41,9 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -51,6 +51,11 @@ struct TALER_EXCHANGE_PurseCreateMergeHandle
char *url;
/**
+ * The exchange base URL.
+ */
+ char *exchange_url;
+
+ /**
* Context for #TEH_curl_easy_post(). Keeps the data that must
* persist for Curl to make the upload.
*/
@@ -157,7 +162,6 @@ handle_purse_create_with_merge_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_TIME_Timestamp etime;
struct TALER_Amount total_deposited;
struct TALER_ExchangeSignatureP exchange_sig;
@@ -184,9 +188,8 @@ handle_purse_create_with_merge_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- key_state = TALER_EXCHANGE_get_keys (pcm->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (pcm->keys,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -253,7 +256,7 @@ handle_purse_create_with_merge_finished (void *cls,
&pcm->merge_sig,
&pcm->merge_pub,
&pcm->purse_pub,
- pcm->exchange->url,
+ pcm->exchange_url,
j))
{
GNUNET_break_op (0);
@@ -295,9 +298,25 @@ handle_purse_create_with_merge_finished (void *cls,
dr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
- /* aka KYC required */
- dr.hr.ec = TALER_JSON_get_error_code (j);
- dr.hr.hint = TALER_JSON_get_error_hint (j);
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &dr.details.unavailable_for_legal_reasons.requirement_row),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ dr.hr.http_status = 0;
+ dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ }
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
dr.hr.ec = TALER_JSON_get_error_code (j);
@@ -324,7 +343,9 @@ handle_purse_create_with_merge_finished (void *cls,
struct TALER_EXCHANGE_PurseCreateMergeHandle *
TALER_EXCHANGE_purse_create_with_merge (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
const struct TALER_PurseContractPrivateKeyP *purse_priv,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
@@ -337,7 +358,6 @@ TALER_EXCHANGE_purse_create_with_merge (
void *cb_cls)
{
struct TALER_EXCHANGE_PurseCreateMergeHandle *pcm;
- struct GNUNET_CURL_Context *ctx;
json_t *create_with_merge_obj;
CURL *eh;
char arg_str[sizeof (pcm->reserve_pub) * 2 + 32];
@@ -346,7 +366,6 @@ TALER_EXCHANGE_purse_create_with_merge (
enum TALER_WalletAccountMergeFlags flags;
pcm = GNUNET_new (struct TALER_EXCHANGE_PurseCreateMergeHandle);
- pcm->exchange = exchange;
pcm->cb = cb;
pcm->cb_cls = cb_cls;
if (GNUNET_OK !=
@@ -393,7 +412,7 @@ TALER_EXCHANGE_purse_create_with_merge (
const struct TALER_EXCHANGE_GlobalFee *gf;
gf = TALER_EXCHANGE_get_global_fee (
- TALER_EXCHANGE_get_keys (exchange),
+ keys,
GNUNET_TIME_timestamp_get ());
purse_fee = gf->fees.purse;
flags = TALER_WAMF_MODE_CREATE_WITH_PURSE_FEE;
@@ -406,8 +425,6 @@ TALER_EXCHANGE_purse_create_with_merge (
flags = TALER_WAMF_MODE_CREATE_FROM_PURSE_QUOTA;
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
{
char pub_str[sizeof (pcm->reserve_pub) * 2];
char *end;
@@ -420,11 +437,12 @@ TALER_EXCHANGE_purse_create_with_merge (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s/purse",
+ "reserves/%s/purse",
pub_str);
}
- pcm->url = TEAH_path_to_url (exchange,
- arg_str);
+ pcm->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pcm->url)
{
GNUNET_break (0);
@@ -438,11 +456,18 @@ TALER_EXCHANGE_purse_create_with_merge (
&pcm->purse_value_after_fees,
purse_priv,
&pcm->purse_sig);
- TALER_wallet_purse_merge_sign (exchange->url,
- merge_timestamp,
- &pcm->purse_pub,
- merge_priv,
- &pcm->merge_sig);
+ {
+ char *payto_uri;
+
+ payto_uri = TALER_reserve_make_payto (url,
+ &pcm->reserve_pub);
+ TALER_wallet_purse_merge_sign (payto_uri,
+ merge_timestamp,
+ &pcm->purse_pub,
+ merge_priv,
+ &pcm->merge_sig);
+ GNUNET_free (payto_uri);
+ }
TALER_wallet_account_merge_sign (merge_timestamp,
&pcm->purse_pub,
pcm->purse_expiration,
@@ -523,7 +548,8 @@ TALER_EXCHANGE_purse_create_with_merge (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse create_with_merge: `%s'\n",
pcm->url);
- ctx = TEAH_handle_to_context (exchange);
+ pcm->keys = TALER_EXCHANGE_keys_incref (keys);
+ pcm->exchange_url = GNUNET_strdup (url);
pcm->job = GNUNET_CURL_job_add2 (ctx,
eh,
pcm->ctx.headers,
@@ -543,7 +569,9 @@ TALER_EXCHANGE_purse_create_with_merge_cancel (
pcm->job = NULL;
}
GNUNET_free (pcm->url);
+ GNUNET_free (pcm->exchange_url);
TALER_curl_easy_post_finished (&pcm->ctx);
+ TALER_EXCHANGE_keys_decref (pcm->keys);
GNUNET_free (pcm->econtract.econtract);
GNUNET_free (pcm);
}
diff --git a/src/lib/exchange_api_purse_delete.c b/src/lib/exchange_api_purse_delete.c
new file mode 100644
index 000000000..6f8ecc381
--- /dev/null
+++ b/src/lib/exchange_api_purse_delete.c
@@ -0,0 +1,243 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+ */
+/**
+ * @file lib/exchange_api_purse_delete.c
+ * @brief Implementation of the client to delete a purse
+ * into an account
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_json_lib.h"
+#include "taler_exchange_service.h"
+#include "exchange_api_handle.h"
+#include "exchange_api_common.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A purse delete with deposit handle
+ */
+struct TALER_EXCHANGE_PurseDeleteHandle
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_PurseDeleteCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Header with the purse_sig.
+ */
+ struct curl_slist *xhdr;
+};
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP DELETE /purse/$PID request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_PurseDeleteHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_purse_delete_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_PurseDeleteHandle *pdh = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_PurseDeleteResponse dr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ pdh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ dr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_NO_CONTENT:
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, exchange says one of the signatures is
+ invalid; as we checked them, this should never happen, we
+ should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ break;
+ case MHD_HTTP_CONFLICT:
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ break;
+ default:
+ /* unexpected response code */
+ dr.hr.ec = TALER_JSON_get_error_code (j);
+ dr.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for exchange deposit\n",
+ (unsigned int) response_code,
+ dr.hr.ec);
+ GNUNET_break_op (0);
+ break;
+ }
+ pdh->cb (pdh->cb_cls,
+ &dr);
+ TALER_EXCHANGE_purse_delete_cancel (pdh);
+}
+
+
+struct TALER_EXCHANGE_PurseDeleteHandle *
+TALER_EXCHANGE_purse_delete (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_PurseContractPrivateKeyP *purse_priv,
+ TALER_EXCHANGE_PurseDeleteCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_PurseDeleteHandle *pdh;
+ CURL *eh;
+ struct TALER_PurseContractPublicKeyP purse_pub;
+ struct TALER_PurseContractSignatureP purse_sig;
+ char arg_str[sizeof (purse_pub) * 2 + 32];
+
+ pdh = GNUNET_new (struct TALER_EXCHANGE_PurseDeleteHandle);
+ pdh->cb = cb;
+ pdh->cb_cls = cb_cls;
+ GNUNET_CRYPTO_eddsa_key_get_public (&purse_priv->eddsa_priv,
+ &purse_pub.eddsa_pub);
+ {
+ char pub_str[sizeof (purse_pub) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (&purse_pub,
+ sizeof (purse_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "purses/%s",
+ pub_str);
+ }
+ pdh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
+ if (NULL == pdh->url)
+ {
+ GNUNET_break (0);
+ GNUNET_free (pdh);
+ return NULL;
+ }
+ TALER_wallet_purse_delete_sign (purse_priv,
+ &purse_sig);
+ {
+ char *delete_str;
+ char *xhdr;
+
+ delete_str =
+ GNUNET_STRINGS_data_to_string_alloc (&purse_sig,
+ sizeof (purse_sig));
+ GNUNET_asprintf (&xhdr,
+ "Taler-Purse-Signature: %s",
+ delete_str);
+ GNUNET_free (delete_str);
+ pdh->xhdr = curl_slist_append (NULL,
+ xhdr);
+ GNUNET_free (xhdr);
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (pdh->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ curl_slist_free_all (pdh->xhdr);
+ GNUNET_free (pdh->url);
+ GNUNET_free (pdh);
+ return NULL;
+ }
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_CUSTOMREQUEST,
+ MHD_HTTP_METHOD_DELETE));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "URL for purse delete: `%s'\n",
+ pdh->url);
+ pdh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ pdh->xhdr,
+ &handle_purse_delete_finished,
+ pdh);
+ return pdh;
+}
+
+
+void
+TALER_EXCHANGE_purse_delete_cancel (
+ struct TALER_EXCHANGE_PurseDeleteHandle *pdh)
+{
+ if (NULL != pdh->job)
+ {
+ GNUNET_CURL_job_cancel (pdh->job);
+ pdh->job = NULL;
+ }
+ curl_slist_free_all (pdh->xhdr);
+ GNUNET_free (pdh->url);
+ GNUNET_free (pdh);
+}
+
+
+/* end of exchange_api_purse_delete.c */
diff --git a/src/lib/exchange_api_purse_deposit.c b/src/lib/exchange_api_purse_deposit.c
index 922251012..9c5fa4e78 100644
--- a/src/lib/exchange_api_purse_deposit.c
+++ b/src/lib/exchange_api_purse_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -73,9 +73,9 @@ struct TALER_EXCHANGE_PurseDepositHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -144,10 +144,9 @@ handle_purse_deposit_finished (void *cls,
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
+ const struct TALER_EXCHANGE_Keys *keys = pch->keys;
pch->job = NULL;
- keys = TALER_EXCHANGE_get_keys (pch->exchange);
switch (response_code)
{
case 0:
@@ -164,17 +163,17 @@ handle_purse_deposit_finished (void *cls,
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&exchange_pub),
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &dr.details.success.h_contract_terms),
+ &dr.details.ok.h_contract_terms),
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
&etime),
GNUNET_JSON_spec_timestamp ("purse_expiration",
- &dr.details.success.purse_expiration),
+ &dr.details.ok.purse_expiration),
TALER_JSON_spec_amount ("total_deposited",
keys->currency,
- &dr.details.success.total_deposited),
+ &dr.details.ok.total_deposited),
TALER_JSON_spec_amount ("purse_value_after_fees",
keys->currency,
- &dr.details.success.purse_value_after_fees),
+ &dr.details.ok.purse_value_after_fees),
GNUNET_JSON_spec_end ()
};
@@ -200,11 +199,11 @@ handle_purse_deposit_finished (void *cls,
if (GNUNET_OK !=
TALER_exchange_online_purse_created_verify (
etime,
- dr.details.success.purse_expiration,
- &dr.details.success.purse_value_after_fees,
- &dr.details.success.total_deposited,
+ dr.details.ok.purse_expiration,
+ &dr.details.ok.purse_value_after_fees,
+ &dr.details.ok.total_deposited,
&pch->purse_pub,
- &dr.details.success.h_contract_terms,
+ &dr.details.ok.h_contract_terms,
&exchange_pub,
&exchange_sig))
{
@@ -298,114 +297,11 @@ handle_purse_deposit_finished (void *cls,
break;
}
case TALER_EC_EXCHANGE_GENERIC_INSUFFICIENT_FUNDS:
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount remaining;
- bool found = false;
- const struct Coin *my_coin;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &coin_pub,
- &remaining))
- {
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- if (0 == GNUNET_memcmp (&coin_pub,
- &pch->coins[i].coin_pub))
- {
- found = true;
- my_coin = &pch->coins[i];
- break;
- }
- }
- if (! found)
- {
- /* proof is about a coin we did not even deposit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (1 == TALER_amount_cmp (&remaining,
- &my_coin->contribution))
- {
- /* transaction should have still fit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_signature_conflict_ (
- j,
- &my_coin->coin_sig))
- {
- /* THIS transaction must not be in the conflicting history */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* everything OK, proof of double-spending was provided */
- break;
- }
+ /* Nothing to check anymore here, proof needs to be
+ checked in the GET /coins/$COIN_PUB handler */
+ break;
case TALER_EC_EXCHANGE_GENERIC_COIN_CONFLICTING_DENOMINATION_KEY:
- {
- struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_Amount remaining;
- bool found = false;
- const struct Coin *my_coin;
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_amount_conflict_ (
- keys,
- j,
- &coin_pub,
- &remaining))
- {
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- for (unsigned int i = 0; i<pch->num_deposits; i++)
- {
- if (0 == GNUNET_memcmp (&coin_pub,
- &pch->coins[i].coin_pub))
- {
- found = true;
- my_coin = &pch->coins[i];
- break;
- }
- }
- if (! found)
- {
- /* proof is about a coin we did not even deposit */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_denomination_conflict_ (
- j,
- &my_coin->h_denom_pub))
- {
- /* no conflicting denomination detected */
- GNUNET_break_op (0);
- dr.hr.http_status = 0;
- dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- /* everything OK, proof of conflicting denomination was provided */
- break;
- }
+ break;
default:
GNUNET_break_op (0);
dr.hr.http_status = 0;
@@ -414,7 +310,7 @@ handle_purse_deposit_finished (void *cls,
} /* ec switch */
break;
case MHD_HTTP_GONE:
- /* could happen if denomination was revoked */
+ /* could happen if denomination was revoked or purse expired */
/* Note: one might want to check /keys for revocation
signature here, alas tricky in case our /keys
is outdated => left to clients */
@@ -447,32 +343,32 @@ handle_purse_deposit_finished (void *cls,
struct TALER_EXCHANGE_PurseDepositHandle *
TALER_EXCHANGE_purse_deposit (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const char *purse_exchange_url,
const struct TALER_PurseContractPublicKeyP *purse_pub,
uint8_t min_age,
unsigned int num_deposits,
- const struct TALER_EXCHANGE_PurseDeposit *deposits,
+ const struct TALER_EXCHANGE_PurseDeposit deposits[static num_deposits],
TALER_EXCHANGE_PurseDepositCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_PurseDepositHandle *pch;
- struct GNUNET_CURL_Context *ctx;
json_t *create_obj;
json_t *deposit_arr;
CURL *eh;
char arg_str[sizeof (pch->purse_pub) * 2 + 32];
+ // FIXME: use purse_exchange_url for wad transfers (#7271)
+ (void) purse_exchange_url;
if (0 == num_deposits)
{
GNUNET_break (0);
return NULL;
}
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
pch = GNUNET_new (struct TALER_EXCHANGE_PurseDepositHandle);
pch->purse_pub = *purse_pub;
- pch->exchange = exchange;
pch->cb = cb;
pch->cb_cls = cb_cls;
{
@@ -487,11 +383,12 @@ TALER_EXCHANGE_purse_deposit (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/deposit",
+ "purses/%s/deposit",
pub_str);
}
- pch->url = TEAH_path_to_url (exchange,
- arg_str);
+ pch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pch->url)
{
GNUNET_break (0);
@@ -500,8 +397,7 @@ TALER_EXCHANGE_purse_deposit (
}
deposit_arr = json_array ();
GNUNET_assert (NULL != deposit_arr);
- pch->base_url = TEAH_path_to_url (exchange,
- "/");
+ pch->base_url = GNUNET_strdup (url);
pch->num_deposits = num_deposits;
pch->coins = GNUNET_new_array (num_deposits,
struct Coin);
@@ -529,6 +425,7 @@ TALER_EXCHANGE_purse_deposit (
json_decref (deposit_arr);
GNUNET_free (pch->base_url);
GNUNET_free (pch->coins);
+ GNUNET_free (pch->url);
GNUNET_free (pch);
return NULL;
}
@@ -592,7 +489,7 @@ TALER_EXCHANGE_purse_deposit (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse deposit: `%s'\n",
pch->url);
- ctx = TEAH_handle_to_context (exchange);
+ pch->keys = TALER_EXCHANGE_keys_incref (keys);
pch->job = GNUNET_CURL_job_add2 (ctx,
eh,
pch->ctx.headers,
@@ -614,6 +511,7 @@ TALER_EXCHANGE_purse_deposit_cancel (
GNUNET_free (pch->base_url);
GNUNET_free (pch->url);
GNUNET_free (pch->coins);
+ TALER_EXCHANGE_keys_decref (pch->keys);
TALER_curl_easy_post_finished (&pch->ctx);
GNUNET_free (pch);
}
diff --git a/src/lib/exchange_api_purse_merge.c b/src/lib/exchange_api_purse_merge.c
index abe6d8cf9..c013b29d2 100644
--- a/src/lib/exchange_api_purse_merge.c
+++ b/src/lib/exchange_api_purse_merge.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -41,9 +41,9 @@ struct TALER_EXCHANGE_AccountMergeHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -148,15 +148,14 @@ handle_purse_merge_finished (void *cls,
break;
case MHD_HTTP_OK:
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct TALER_Amount total_deposited;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
- &dr.details.success.exchange_sig),
+ &dr.details.ok.exchange_sig),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
- &dr.details.success.exchange_pub),
+ &dr.details.ok.exchange_pub),
GNUNET_JSON_spec_timestamp ("exchange_timestamp",
- &dr.details.success.etime),
+ &dr.details.ok.etime),
TALER_JSON_spec_amount ("merge_amount",
pch->purse_value_after_fees.currency,
&total_deposited),
@@ -173,10 +172,9 @@ handle_purse_merge_finished (void *cls,
dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
break;
}
- key_state = TALER_EXCHANGE_get_keys (pch->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
- &dr.details.success.exchange_pub))
+ TALER_EXCHANGE_test_signing_key (pch->keys,
+ &dr.details.ok.exchange_pub))
{
GNUNET_break_op (0);
dr.hr.http_status = 0;
@@ -185,15 +183,15 @@ handle_purse_merge_finished (void *cls,
}
if (GNUNET_OK !=
TALER_exchange_online_purse_merged_verify (
- dr.details.success.etime,
+ dr.details.ok.etime,
pch->purse_expiration,
&pch->purse_value_after_fees,
&pch->purse_pub,
&pch->h_contract_terms,
&pch->reserve_pub,
pch->provider_url,
- &dr.details.success.exchange_pub,
- &dr.details.success.exchange_sig))
+ &dr.details.ok.exchange_pub,
+ &dr.details.ok.exchange_sig))
{
GNUNET_break_op (0);
dr.hr.http_status = 0;
@@ -232,7 +230,6 @@ handle_purse_merge_finished (void *cls,
GNUNET_CRYPTO_eddsa_key_get_public (&pch->merge_priv.eddsa_priv,
&merge_pub.eddsa_pub);
-
if (GNUNET_OK !=
TALER_EXCHANGE_check_purse_merge_conflict_ (
&pch->merge_sig,
@@ -257,6 +254,27 @@ handle_purse_merge_finished (void *cls,
dr.hr.ec = TALER_JSON_get_error_code (j);
dr.hr.hint = TALER_JSON_get_error_hint (j);
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ {
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &dr.details.unavailable_for_legal_reasons.requirement_row),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ dr.hr.http_status = 0;
+ dr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ }
+ break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
dr.hr.ec = TALER_JSON_get_error_code (j);
dr.hr.hint = TALER_JSON_get_error_hint (j);
@@ -282,7 +300,9 @@ handle_purse_merge_finished (void *cls,
struct TALER_EXCHANGE_AccountMergeHandle *
TALER_EXCHANGE_account_merge (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const char *reserve_exchange_url,
const struct TALER_ReservePrivateKeyP *reserve_priv,
const struct TALER_PurseContractPublicKeyP *purse_pub,
@@ -296,14 +316,12 @@ TALER_EXCHANGE_account_merge (
void *cb_cls)
{
struct TALER_EXCHANGE_AccountMergeHandle *pch;
- struct GNUNET_CURL_Context *ctx;
json_t *merge_obj;
CURL *eh;
char arg_str[sizeof (pch->purse_pub) * 2 + 32];
char *reserve_url;
pch = GNUNET_new (struct TALER_EXCHANGE_AccountMergeHandle);
- pch->exchange = exchange;
pch->merge_priv = *merge_priv;
pch->cb = cb;
pch->cb_cls = cb_cls;
@@ -312,14 +330,12 @@ TALER_EXCHANGE_account_merge (
pch->purse_expiration = purse_expiration;
pch->purse_value_after_fees = *purse_value_after_fees;
if (NULL == reserve_exchange_url)
- pch->provider_url = GNUNET_strdup (exchange->url);
+ pch->provider_url = GNUNET_strdup (url);
else
pch->provider_url = GNUNET_strdup (reserve_exchange_url);
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
&pch->reserve_pub.eddsa_pub);
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
{
char pub_str[sizeof (*purse_pub) * 2];
char *end;
@@ -332,7 +348,7 @@ TALER_EXCHANGE_account_merge (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/merge",
+ "purses/%s/merge",
pub_str);
}
reserve_url = TALER_reserve_make_payto (pch->provider_url,
@@ -344,8 +360,9 @@ TALER_EXCHANGE_account_merge (
GNUNET_free (pch);
return NULL;
}
- pch->url = TEAH_path_to_url (exchange,
- arg_str);
+ pch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pch->url)
{
GNUNET_break (0);
@@ -386,6 +403,7 @@ TALER_EXCHANGE_account_merge (
GNUNET_JSON_pack_timestamp ("merge_timestamp",
merge_timestamp));
GNUNET_assert (NULL != merge_obj);
+ GNUNET_free (reserve_url);
eh = TALER_EXCHANGE_curl_easy_get_ (pch->url);
if ( (NULL == eh) ||
(GNUNET_OK !=
@@ -406,7 +424,7 @@ TALER_EXCHANGE_account_merge (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for purse merge: `%s'\n",
pch->url);
- ctx = TEAH_handle_to_context (exchange);
+ pch->keys = TALER_EXCHANGE_keys_incref (keys);
pch->job = GNUNET_CURL_job_add2 (ctx,
eh,
pch->ctx.headers,
@@ -428,6 +446,7 @@ TALER_EXCHANGE_account_merge_cancel (
GNUNET_free (pch->url);
GNUNET_free (pch->provider_url);
TALER_curl_easy_post_finished (&pch->ctx);
+ TALER_EXCHANGE_keys_decref (pch->keys);
GNUNET_free (pch);
}
diff --git a/src/lib/exchange_api_purses_get.c b/src/lib/exchange_api_purses_get.c
index 021954c2d..dc22c75ad 100644
--- a/src/lib/exchange_api_purses_get.c
+++ b/src/lib/exchange_api_purses_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -39,9 +39,9 @@ struct TALER_EXCHANGE_PurseGetHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -94,22 +94,29 @@ handle_purse_get_finished (void *cls,
break;
case MHD_HTTP_OK:
{
+ bool no_merge = false;
+ bool no_deposit = false;
struct TALER_ExchangePublicKeyP exchange_pub;
struct TALER_ExchangeSignatureP exchange_sig;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_timestamp ("merge_timestamp",
- &dr.details.success.merge_timestamp),
- GNUNET_JSON_spec_timestamp ("deposit_timestamp",
- &dr.details.success.deposit_timestamp),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("merge_timestamp",
+ &dr.details.ok.merge_timestamp),
+ &no_merge),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_timestamp ("deposit_timestamp",
+ &dr.details.ok.deposit_timestamp),
+ &no_deposit),
TALER_JSON_spec_amount_any ("balance",
- &dr.details.success.balance),
+ &dr.details.ok.balance),
+ GNUNET_JSON_spec_timestamp ("purse_expiration",
+ &dr.details.ok.purse_expiration),
GNUNET_JSON_spec_fixed_auto ("exchange_pub",
&exchange_pub),
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
&exchange_sig),
GNUNET_JSON_spec_end ()
};
- const struct TALER_EXCHANGE_Keys *key_state;
if (GNUNET_OK !=
GNUNET_JSON_parse (j,
@@ -122,9 +129,8 @@ handle_purse_get_finished (void *cls,
break;
}
- key_state = TALER_EXCHANGE_get_keys (pgh->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (pgh->keys,
&exchange_pub))
{
GNUNET_break_op (0);
@@ -134,9 +140,9 @@ handle_purse_get_finished (void *cls,
}
if (GNUNET_OK !=
TALER_exchange_online_purse_status_verify (
- dr.details.success.merge_timestamp,
- dr.details.success.deposit_timestamp,
- &dr.details.success.balance,
+ dr.details.ok.merge_timestamp,
+ dr.details.ok.deposit_timestamp,
+ &dr.details.ok.balance,
&exchange_pub,
&exchange_sig))
{
@@ -199,7 +205,9 @@ handle_purse_get_finished (void *cls,
struct TALER_EXCHANGE_PurseGetHandle *
TALER_EXCHANGE_purse_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_PurseContractPublicKeyP *purse_pub,
struct GNUNET_TIME_Relative timeout,
bool wait_for_merge,
@@ -209,15 +217,11 @@ TALER_EXCHANGE_purse_get (
struct TALER_EXCHANGE_PurseGetHandle *pgh;
CURL *eh;
char arg_str[sizeof (*purse_pub) * 2 + 64];
+ unsigned int tms
+ = (unsigned int) timeout.rel_value_us
+ / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
pgh = GNUNET_new (struct TALER_EXCHANGE_PurseGetHandle);
- pgh->exchange = exchange;
pgh->cb = cb;
pgh->cb_cls = cb_cls;
{
@@ -232,26 +236,25 @@ TALER_EXCHANGE_purse_get (
*end = '\0';
GNUNET_snprintf (timeout_str,
sizeof (timeout_str),
- "%llu",
- (unsigned long long)
- (timeout.rel_value_us
- / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us));
- if (GNUNET_TIME_relative_is_zero (timeout))
+ "%u",
+ tms);
+ if (0 == tms)
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/%s",
+ "purses/%s/%s",
cpub_str,
wait_for_merge ? "merge" : "deposit");
else
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/purses/%s/%s?timeout_ms=%s",
+ "purses/%s/%s?timeout_ms=%s",
cpub_str,
wait_for_merge ? "merge" : "deposit",
timeout_str);
}
- pgh->url = TEAH_path_to_url (exchange,
- arg_str);
+ pgh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == pgh->url)
{
GNUNET_free (pgh);
@@ -265,10 +268,18 @@ TALER_EXCHANGE_purse_get (
GNUNET_free (pgh);
return NULL;
}
- pgh->job = GNUNET_CURL_job_add (TEAH_handle_to_context (exchange),
+ if (0 != tms)
+ {
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_TIMEOUT_MS,
+ (long) (tms + 100L)));
+ }
+ pgh->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_purse_get_finished,
pgh);
+ pgh->keys = TALER_EXCHANGE_keys_incref (keys);
return pgh;
}
@@ -283,6 +294,7 @@ TALER_EXCHANGE_purse_get_cancel (
pgh->job = NULL;
}
GNUNET_free (pgh->url);
+ TALER_EXCHANGE_keys_decref (pgh->keys);
GNUNET_free (pgh);
}
diff --git a/src/lib/exchange_api_recoup.c b/src/lib/exchange_api_recoup.c
index 49fb6fd55..56499f381 100644
--- a/src/lib/exchange_api_recoup.c
+++ b/src/lib/exchange_api_recoup.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017-2022 Taler Systems SA
+ Copyright (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -40,9 +40,9 @@ struct TALER_EXCHANGE_RecoupHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -100,16 +100,15 @@ static enum GNUNET_GenericReturnValue
process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
const json_t *json)
{
- struct TALER_ReservePublicKeyP reserve_pub;
+ struct TALER_EXCHANGE_RecoupResponse rr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
+ };
struct GNUNET_JSON_Specification spec_withdraw[] = {
GNUNET_JSON_spec_fixed_auto ("reserve_pub",
- &reserve_pub),
+ &rr.details.ok.reserve_pub),
GNUNET_JSON_spec_end ()
};
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = json,
- .http_status = MHD_HTTP_OK
- };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -120,8 +119,7 @@ process_recoup_response (const struct TALER_EXCHANGE_RecoupHandle *ph,
return GNUNET_SYSERR;
}
ph->cb (ph->cb_cls,
- &hr,
- &reserve_pub);
+ &rr);
return GNUNET_OK;
}
@@ -141,18 +139,16 @@ handle_recoup_finished (void *cls,
{
struct TALER_EXCHANGE_RecoupHandle *ph = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_RecoupResponse rr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
ph->job = NULL;
- keys = TALER_EXCHANGE_get_keys (ph->exchange);
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ rr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -160,8 +156,8 @@ handle_recoup_finished (void *cls,
j))
{
GNUNET_break_op (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
+ rr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ rr.hr.http_status = 0;
break;
}
TALER_EXCHANGE_recoup_cancel (ph);
@@ -169,36 +165,22 @@ handle_recoup_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
{
struct TALER_Amount min_key;
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
if (GNUNET_OK !=
- TALER_EXCHANGE_get_min_denomination_ (keys,
+ TALER_EXCHANGE_get_min_denomination_ (ph->keys,
&min_key))
{
GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_conflict_ (
- keys,
- j,
- &ph->pk,
- &ph->coin_pub,
- &ph->coin_sig,
- &min_key))
- {
- GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
+ rr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ rr.hr.http_status = 0;
break;
}
break;
@@ -207,65 +189,64 @@ handle_recoup_finished (void *cls,
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_GONE:
/* Kind of normal: the money was already sent to the merchant
(it was too late for the refund). */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange recoup\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) rr.hr.ec);
GNUNET_break (0);
break;
}
ph->cb (ph->cb_cls,
- &hr,
- NULL);
+ &rr);
TALER_EXCHANGE_recoup_cancel (ph);
}
struct TALER_EXCHANGE_RecoupHandle *
-TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_EXCHANGE_DenomPublicKey *pk,
- const struct TALER_DenominationSignature *denom_sig,
- const struct TALER_ExchangeWithdrawValues *exchange_vals,
- const struct TALER_PlanchetMasterSecretP *ps,
- TALER_EXCHANGE_RecoupResultCallback recoup_cb,
- void *recoup_cb_cls)
+TALER_EXCHANGE_recoup (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_EXCHANGE_DenomPublicKey *pk,
+ const struct TALER_DenominationSignature *denom_sig,
+ const struct TALER_ExchangeWithdrawValues *exchange_vals,
+ const struct TALER_PlanchetMasterSecretP *ps,
+ TALER_EXCHANGE_RecoupResultCallback recoup_cb,
+ void *recoup_cb_cls)
{
struct TALER_EXCHANGE_RecoupHandle *ph;
- struct GNUNET_CURL_Context *ctx;
struct TALER_DenominationHashP h_denom_pub;
json_t *recoup_obj;
CURL *eh;
char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
ph = GNUNET_new (struct TALER_EXCHANGE_RecoupHandle);
TALER_planchet_setup_coin_priv (ps,
exchange_vals,
@@ -292,23 +273,32 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
&ph->coin_sig),
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
&bks));
- if (TALER_DENOMINATION_CS == denom_sig->cipher)
+ switch (denom_sig->unblinded_sig->cipher)
{
- struct TALER_CsNonce nonce;
-
- // FIXME: add this to the spec!
- /* NOTE: this is not elegant, and as per the note in TALER_coin_ev_hash()
- it is not strictly clear that the nonce is needed. Best case would be
- to find a way to include it more 'naturally' somehow, for example with
- the variant union version of bks! */
- TALER_cs_withdraw_nonce_derive (ps,
- &nonce);
- GNUNET_assert (
- 0 ==
- json_object_set_new (recoup_obj,
- "cs_nonce",
- GNUNET_JSON_from_data_auto (
- &nonce)));
+ case GNUNET_CRYPTO_BSA_INVALID:
+ json_decref (recoup_obj);
+ GNUNET_break (0);
+ GNUNET_free (ph);
+ return NULL;
+ case GNUNET_CRYPTO_BSA_RSA:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ {
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+
+ /* NOTE: this is not elegant, and as per the note in TALER_coin_ev_hash()
+ it is not strictly clear that the nonce is needed. Best case would be
+ to find a way to include it more 'naturally' somehow, for example with
+ the variant union version of bks! */
+ TALER_cs_withdraw_nonce_derive (ps,
+ &nonce.cs_nonce);
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (recoup_obj,
+ "cs_nonce",
+ GNUNET_JSON_from_data_auto (
+ &nonce)));
+ }
}
{
@@ -323,19 +313,19 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/coins/%s/recoup",
+ "coins/%s/recoup",
pub_str);
}
- ph->exchange = exchange;
ph->pk = *pk;
memset (&ph->pk.key,
0,
sizeof (ph->pk.key)); /* zero out, as lifetime cannot be warranted */
ph->cb = recoup_cb;
ph->cb_cls = recoup_cb_cls;
- ph->url = TEAH_path_to_url (exchange,
- arg_str);
+ ph->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == ph->url)
{
json_decref (recoup_obj);
@@ -361,7 +351,7 @@ TALER_EXCHANGE_recoup (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for recoup: `%s'\n",
ph->url);
- ctx = TEAH_handle_to_context (exchange);
+ ph->keys = TALER_EXCHANGE_keys_incref (keys);
ph->job = GNUNET_CURL_job_add2 (ctx,
eh,
ph->ctx.headers,
@@ -381,6 +371,7 @@ TALER_EXCHANGE_recoup_cancel (struct TALER_EXCHANGE_RecoupHandle *ph)
}
GNUNET_free (ph->url);
TALER_curl_easy_post_finished (&ph->ctx);
+ TALER_EXCHANGE_keys_decref (ph->keys);
GNUNET_free (ph);
}
diff --git a/src/lib/exchange_api_recoup_refresh.c b/src/lib/exchange_api_recoup_refresh.c
index d551df743..0c2e21cbf 100644
--- a/src/lib/exchange_api_recoup_refresh.c
+++ b/src/lib/exchange_api_recoup_refresh.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2017-2022 Taler Systems SA
+ Copyright (C) 2017-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -40,9 +40,9 @@ struct TALER_EXCHANGE_RecoupRefreshHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -101,16 +101,15 @@ process_recoup_response (
const struct TALER_EXCHANGE_RecoupRefreshHandle *ph,
const json_t *json)
{
- struct TALER_CoinSpendPublicKeyP old_coin_pub;
+ struct TALER_EXCHANGE_RecoupRefreshResponse rrr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
+ };
struct GNUNET_JSON_Specification spec_refresh[] = {
GNUNET_JSON_spec_fixed_auto ("old_coin_pub",
- &old_coin_pub),
+ &rrr.details.ok.old_coin_pub),
GNUNET_JSON_spec_end ()
};
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = json,
- .http_status = MHD_HTTP_OK
- };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -121,8 +120,7 @@ process_recoup_response (
return GNUNET_SYSERR;
}
ph->cb (ph->cb_cls,
- &hr,
- &old_coin_pub);
+ &rrr);
return GNUNET_OK;
}
@@ -142,18 +140,16 @@ handle_recoup_refresh_finished (void *cls,
{
struct TALER_EXCHANGE_RecoupRefreshHandle *ph = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_RecoupRefreshResponse rrr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
};
- const struct TALER_EXCHANGE_Keys *keys;
ph->job = NULL;
- keys = TALER_EXCHANGE_get_keys (ph->exchange);
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ rrr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
@@ -161,8 +157,8 @@ handle_recoup_refresh_finished (void *cls,
j))
{
GNUNET_break_op (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
+ rrr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ rrr.hr.http_status = 0;
break;
}
TALER_EXCHANGE_recoup_refresh_cancel (ph);
@@ -170,86 +166,60 @@ handle_recoup_refresh_finished (void *cls,
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
- {
- struct TALER_Amount min_key;
-
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- if (GNUNET_OK !=
- TALER_EXCHANGE_get_min_denomination_ (keys,
- &min_key))
- {
- GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
- if (GNUNET_OK !=
- TALER_EXCHANGE_check_coin_conflict_ (
- keys,
- j,
- &ph->pk,
- &ph->coin_pub,
- &ph->coin_sig,
- &min_key))
- {
- GNUNET_break (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
- break;
- }
- break;
- }
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
case MHD_HTTP_GONE:
/* Kind of normal: the money was already sent to the merchant
(it was too late for the refund). */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rrr.hr.ec = TALER_JSON_get_error_code (j);
+ rrr.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange recoup\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) rrr.hr.ec);
GNUNET_break (0);
break;
}
ph->cb (ph->cb_cls,
- &hr,
- NULL);
+ &rrr);
TALER_EXCHANGE_recoup_refresh_cancel (ph);
}
struct TALER_EXCHANGE_RecoupRefreshHandle *
TALER_EXCHANGE_recoup_refresh (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_EXCHANGE_DenomPublicKey *pk,
const struct TALER_DenominationSignature *denom_sig,
const struct TALER_ExchangeWithdrawValues *exchange_vals,
@@ -260,19 +230,15 @@ TALER_EXCHANGE_recoup_refresh (
void *recoup_cb_cls)
{
struct TALER_EXCHANGE_RecoupRefreshHandle *ph;
- struct GNUNET_CURL_Context *ctx;
struct TALER_DenominationHashP h_denom_pub;
json_t *recoup_obj;
CURL *eh;
char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
GNUNET_assert (NULL != recoup_cb);
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
ph = GNUNET_new (struct TALER_EXCHANGE_RecoupRefreshHandle);
- ph->exchange = exchange;
ph->pk = *pk;
memset (&ph->pk.key,
0,
@@ -305,24 +271,34 @@ TALER_EXCHANGE_recoup_refresh (
GNUNET_JSON_pack_data_auto ("coin_blind_key_secret",
&bks));
- if (TALER_DENOMINATION_CS == denom_sig->cipher)
+ switch (denom_sig->unblinded_sig->cipher)
{
- struct TALER_CsNonce nonce;
-
- // FIXME: add this to the spec!
- /* NOTE: this is not elegant, and as per the note in TALER_coin_ev_hash()
- it is not strictly clear that the nonce is needed. Best case would be
- to find a way to include it more 'naturally' somehow, for example with
- the variant union version of bks! */
- TALER_cs_refresh_nonce_derive (rms,
- idx,
- &nonce);
- GNUNET_assert (
- 0 ==
- json_object_set_new (recoup_obj,
- "cs_nonce",
- GNUNET_JSON_from_data_auto (
- &nonce)));
+ case GNUNET_CRYPTO_BSA_INVALID:
+ json_decref (recoup_obj);
+ GNUNET_break (0);
+ GNUNET_free (ph);
+ return NULL;
+ case GNUNET_CRYPTO_BSA_RSA:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ {
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+
+ /* NOTE: this is not elegant, and as per the note in TALER_coin_ev_hash()
+ it is not strictly clear that the nonce is needed. Best case would be
+ to find a way to include it more 'naturally' somehow, for example with
+ the variant union version of bks! */
+ TALER_cs_refresh_nonce_derive (rms,
+ idx,
+ &nonce.cs_nonce);
+ GNUNET_assert (
+ 0 ==
+ json_object_set_new (recoup_obj,
+ "cs_nonce",
+ GNUNET_JSON_from_data_auto (
+ &nonce)));
+ }
+ break;
}
{
@@ -337,12 +313,13 @@ TALER_EXCHANGE_recoup_refresh (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/coins/%s/recoup-refresh",
+ "coins/%s/recoup-refresh",
pub_str);
}
- ph->url = TEAH_path_to_url (exchange,
- arg_str);
+ ph->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == ph->url)
{
json_decref (recoup_obj);
@@ -368,7 +345,7 @@ TALER_EXCHANGE_recoup_refresh (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for recoup-refresh: `%s'\n",
ph->url);
- ctx = TEAH_handle_to_context (exchange);
+ ph->keys = TALER_EXCHANGE_keys_incref (keys);
ph->job = GNUNET_CURL_job_add2 (ctx,
eh,
ph->ctx.headers,
@@ -389,6 +366,7 @@ TALER_EXCHANGE_recoup_refresh_cancel (
}
GNUNET_free (ph->url);
TALER_curl_easy_post_finished (&ph->ctx);
+ TALER_EXCHANGE_keys_decref (ph->keys);
GNUNET_free (ph);
}
diff --git a/src/lib/exchange_api_refresh_common.c b/src/lib/exchange_api_refresh_common.c
index 581e21152..4369367e4 100644
--- a/src/lib/exchange_api_refresh_common.c
+++ b/src/lib/exchange_api_refresh_common.c
@@ -45,6 +45,11 @@ TALER_EXCHANGE_free_melt_data_ (struct MeltData *md)
struct FreshCoinData *fcd = &md->fcds[j];
TALER_denom_pub_free (&fcd->fresh_pk);
+ for (size_t i = 0; i < TALER_CNC_KAPPA; i++)
+ {
+ TALER_age_commitment_proof_free (fcd->age_commitment_proofs[i]);
+ GNUNET_free (fcd->age_commitment_proofs[i]);
+ }
}
GNUNET_free (md->fcds);
}
@@ -63,7 +68,7 @@ TALER_EXCHANGE_get_melt_data_ (
{
struct TALER_Amount total;
struct TALER_CoinSpendPublicKeyP coin_pub;
- struct TALER_CsNonce nonces[rd->fresh_pks_len];
+ union GNUNET_CRYPTO_BlindSessionNonce nonces[rd->fresh_pks_len];
bool uses_cs = false;
GNUNET_CRYPTO_eddsa_key_get_public (&rd->melt_priv.eddsa_priv,
@@ -84,32 +89,41 @@ TALER_EXCHANGE_get_melt_data_ (
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (rd->melt_amount.currency,
&total));
- TALER_denom_pub_deep_copy (&md->melted_coin.pub_key,
- &rd->melt_pk.key);
- TALER_denom_sig_deep_copy (&md->melted_coin.sig,
- &rd->melt_sig);
+ TALER_denom_pub_copy (&md->melted_coin.pub_key,
+ &rd->melt_pk.key);
+ TALER_denom_sig_copy (&md->melted_coin.sig,
+ &rd->melt_sig);
md->fcds = GNUNET_new_array (md->num_fresh_coins,
struct FreshCoinData);
for (unsigned int j = 0; j<rd->fresh_pks_len; j++)
{
struct FreshCoinData *fcd = &md->fcds[j];
- if (alg_values[j].cipher != rd->fresh_pks[j].key.cipher)
+ TALER_denom_pub_copy (&fcd->fresh_pk,
+ &rd->fresh_pks[j].key);
+ GNUNET_assert (NULL != fcd->fresh_pk.bsign_pub_key);
+ if (alg_values[j].blinding_inputs->cipher !=
+ fcd->fresh_pk.bsign_pub_key->cipher)
{
GNUNET_break (0);
TALER_EXCHANGE_free_melt_data_ (md);
return GNUNET_SYSERR;
}
- if (TALER_DENOMINATION_CS == alg_values[j].cipher)
+ switch (fcd->fresh_pk.bsign_pub_key->cipher)
{
+ case GNUNET_CRYPTO_BSA_INVALID:
+ GNUNET_break (0);
+ TALER_EXCHANGE_free_melt_data_ (md);
+ return GNUNET_SYSERR;
+ case GNUNET_CRYPTO_BSA_RSA:
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
uses_cs = true;
- TALER_cs_refresh_nonce_derive (
- rms,
- j,
- &nonces[j]);
+ TALER_cs_refresh_nonce_derive (rms,
+ j,
+ &nonces[j].cs_nonce);
+ break;
}
- TALER_denom_pub_deep_copy (&fcd->fresh_pk,
- &rd->fresh_pks[j].key);
if ( (0 >
TALER_amount_add (&total,
&total,
@@ -165,10 +179,11 @@ TALER_EXCHANGE_get_melt_data_ (
struct TALER_CoinSpendPrivateKeyP *coin_priv = &fcd->coin_priv;
struct TALER_PlanchetMasterSecretP *ps = &fcd->ps[i];
struct TALER_RefreshCoinData *rcd = &md->rcd[i][j];
- union TALER_DenominationBlindingKeyP *bks = &fcd->bks[i];
+ union GNUNET_CRYPTO_BlindingSecretP *bks = &fcd->bks[i];
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
- struct TALER_AgeCommitmentHash *ach = NULL;
+ struct TALER_AgeCommitmentHash ach;
+ struct TALER_AgeCommitmentHash *pah = NULL;
TALER_transfer_secret_to_planchet_secret (&trans_sec,
j,
@@ -182,33 +197,30 @@ TALER_EXCHANGE_get_melt_data_ (
&alg_values[j],
bks);
- /* Handle age commitment, if present */
- if (NULL != md->melted_coin.age_commitment_proof)
+ if (NULL != rd->melt_age_commitment_proof)
{
- fcd->age_commitment_proof[i] = GNUNET_new (struct
- TALER_AgeCommitmentProof);
- ach = GNUNET_new (struct TALER_AgeCommitmentHash);
+ fcd->age_commitment_proofs[i] = GNUNET_new (struct
+ TALER_AgeCommitmentProof);
GNUNET_assert (GNUNET_OK ==
TALER_age_commitment_derive (
md->melted_coin.age_commitment_proof,
&trans_sec.key,
- fcd->age_commitment_proof[i]));
+ fcd->age_commitment_proofs[i]));
TALER_age_commitment_hash (
- &fcd->age_commitment_proof[i]->commitment,
- ach);
+ &fcd->age_commitment_proofs[i]->commitment,
+ &ach);
+ pah = &ach;
}
- if (TALER_DENOMINATION_CS == alg_values[j].cipher)
- pd.blinded_planchet.details.cs_blinded_planchet.nonce = nonces[j];
-
if (GNUNET_OK !=
TALER_planchet_prepare (&fcd->fresh_pk,
&alg_values[j],
bks,
+ &nonces[j],
coin_priv,
- ach,
+ pah,
&c_hash,
&pd))
{
diff --git a/src/lib/exchange_api_refresh_common.h b/src/lib/exchange_api_refresh_common.h
index c06824fec..f596e1e90 100644
--- a/src/lib/exchange_api_refresh_common.h
+++ b/src/lib/exchange_api_refresh_common.h
@@ -101,16 +101,15 @@ struct FreshCoinData
/**
* Arrays of age commitments and proofs to be created, one for each
- * cut-and-choose dimension. The entries in each list might be NULL and
- * indicate no age commitment/restriction on the particular coin.
+ * cut-and-choose dimension. NULL if age restriction is not applicable.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof[TALER_CNC_KAPPA];
+ struct TALER_AgeCommitmentProof *age_commitment_proofs[TALER_CNC_KAPPA];
/**
* Blinding key secrets for the coins, depending on the
* cut-and-choose.
*/
- union TALER_DenominationBlindingKeyP bks[TALER_CNC_KAPPA];
+ union GNUNET_CRYPTO_BlindingSecretP bks[TALER_CNC_KAPPA];
};
diff --git a/src/lib/exchange_api_refreshes_reveal.c b/src/lib/exchange_api_refreshes_reveal.c
index cd2a1d1f4..69c53a6c9 100644
--- a/src/lib/exchange_api_refreshes_reveal.c
+++ b/src/lib/exchange_api_refreshes_reveal.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2015-2022 Taler Systems SA
+ Copyright (C) 2015-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -40,11 +40,6 @@ struct TALER_EXCHANGE_RefreshesRevealHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -107,10 +102,10 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
const json_t *json,
struct TALER_EXCHANGE_RevealedCoinInfo *rcis)
{
- json_t *jsona;
+ const json_t *jsona;
struct GNUNET_JSON_Specification outer_spec[] = {
- GNUNET_JSON_spec_json ("ev_sigs",
- &jsona),
+ GNUNET_JSON_spec_array_const ("ev_sigs",
+ &jsona),
GNUNET_JSON_spec_end ()
};
@@ -122,24 +117,15 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if (! json_is_array (jsona))
- {
- /* We expected an array of coins */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (outer_spec);
- return GNUNET_SYSERR;
- }
if (rrh->md.num_fresh_coins != json_array_size (jsona))
{
/* Number of coins generated does not match our expectation */
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (outer_spec);
return GNUNET_SYSERR;
}
for (unsigned int i = 0; i<rrh->md.num_fresh_coins; i++)
{
- struct TALER_EXCHANGE_RevealedCoinInfo *rci =
- &rcis[i];
+ struct TALER_EXCHANGE_RevealedCoinInfo *rci = &rcis[i];
const struct FreshCoinData *fcd = &rrh->md.fcds[i];
const struct TALER_DenominationPublicKey *pk;
json_t *jsonai;
@@ -152,26 +138,22 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
GNUNET_JSON_spec_end ()
};
struct TALER_FreshCoin coin;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ const struct TALER_AgeCommitmentHash *pah = NULL;
rci->ps = fcd->ps[rrh->noreveal_index];
rci->bks = fcd->bks[rrh->noreveal_index];
- rci->age_commitment_proof = fcd->age_commitment_proof[rrh->noreveal_index];
- rci->h_age_commitment = NULL;
+ rci->age_commitment_proof = NULL;
pk = &fcd->fresh_pk;
jsonai = json_array_get (jsona, i);
-
GNUNET_assert (NULL != jsonai);
- GNUNET_assert (
- (NULL != rrh->md.melted_coin.age_commitment_proof) ==
- (NULL != rci->age_commitment_proof));
-
- if (NULL != rci->age_commitment_proof)
+ if (NULL != rrh->md.melted_coin.age_commitment_proof)
{
- rci->h_age_commitment = GNUNET_new (struct TALER_AgeCommitmentHash);
- TALER_age_commitment_hash (
- &rci->age_commitment_proof->commitment,
- rci->h_age_commitment);
+ rci->age_commitment_proof
+ = fcd->age_commitment_proofs[rrh->noreveal_index];
+ TALER_age_commitment_hash (&rci->age_commitment_proof->commitment,
+ &rci->h_age_commitment);
+ pah = &rci->h_age_commitment;
}
if (GNUNET_OK !=
@@ -180,7 +162,6 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
NULL, NULL))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (outer_spec);
return GNUNET_SYSERR;
}
@@ -194,28 +175,28 @@ refresh_reveal_ok (struct TALER_EXCHANGE_RefreshesRevealHandle *rrh,
hence recomputing it here... */
GNUNET_CRYPTO_eddsa_key_get_public (&rci->coin_priv.eddsa_priv,
&coin_pub.eddsa_pub);
- TALER_coin_pub_hash (&coin_pub,
- rci->h_age_commitment,
- &coin_hash);
+ TALER_coin_pub_hash (
+ &coin_pub,
+ pah,
+ &coin_hash);
if (GNUNET_OK !=
- TALER_planchet_to_coin (pk,
- &blind_sig,
- &bks,
- &rci->coin_priv,
- rci->h_age_commitment,
- &coin_hash,
- &rrh->alg_values[i],
- &coin))
+ TALER_planchet_to_coin (
+ pk,
+ &blind_sig,
+ &bks,
+ &rci->coin_priv,
+ pah,
+ &coin_hash,
+ &rrh->alg_values[i],
+ &coin))
{
GNUNET_break_op (0);
GNUNET_JSON_parse_free (spec);
- GNUNET_JSON_parse_free (outer_spec);
return GNUNET_SYSERR;
}
GNUNET_JSON_parse_free (spec);
rci->sig = coin.sig;
}
- GNUNET_JSON_parse_free (outer_spec);
return GNUNET_OK;
}
@@ -266,14 +247,17 @@ handle_refresh_reveal_finished (void *cls,
else
{
GNUNET_assert (rrh->noreveal_index < TALER_CNC_KAPPA);
- rr.details.success.num_coins = rrh->md.num_fresh_coins;
- rr.details.success.coins = rcis;
+ rr.details.ok.num_coins = rrh->md.num_fresh_coins;
+ rr.details.ok.coins = rcis;
rrh->reveal_cb (rrh->reveal_cb_cls,
&rr);
rrh->reveal_cb = NULL;
}
for (unsigned int i = 0; i<rrh->md.num_fresh_coins; i++)
+ {
TALER_denom_sig_free (&rcis[i].sig);
+ TALER_age_commitment_proof_free (rcis[i].age_commitment_proof);
+ }
TALER_EXCHANGE_refreshes_reveal_cancel (rrh);
return;
}
@@ -321,11 +305,12 @@ handle_refresh_reveal_finished (void *cls,
struct TALER_EXCHANGE_RefreshesRevealHandle *
TALER_EXCHANGE_refreshes_reveal (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_RefreshMasterSecretP *rms,
const struct TALER_EXCHANGE_RefreshData *rd,
unsigned int num_coins,
- const struct TALER_ExchangeWithdrawValues *alg_values,
+ const struct TALER_ExchangeWithdrawValues alg_values[static num_coins],
uint32_t noreveal_index,
TALER_EXCHANGE_RefreshesRevealCallback reveal_cb,
void *reveal_cb_cls)
@@ -338,7 +323,6 @@ TALER_EXCHANGE_refreshes_reveal (
json_t *link_sigs;
json_t *old_age_commitment = NULL;
CURL *eh;
- struct GNUNET_CURL_Context *ctx;
struct MeltData md;
char arg_str[sizeof (struct TALER_RefreshCommitmentP) * 2 + 32];
bool send_rms = false;
@@ -353,12 +337,6 @@ TALER_EXCHANGE_refreshes_reveal (
GNUNET_break (0);
return NULL;
}
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
if (GNUNET_OK !=
TALER_EXCHANGE_get_melt_data_ (rms,
rd,
@@ -378,7 +356,8 @@ TALER_EXCHANGE_refreshes_reveal (
const struct TALER_RefreshCoinData *rcd = &md.rcd[noreveal_index][i];
struct TALER_DenominationHashP denom_hash;
- if (TALER_DENOMINATION_CS == md.fcds[i].fresh_pk.cipher)
+ if (GNUNET_CRYPTO_BSA_CS ==
+ md.fcds[i].fresh_pk.bsign_pub_key->cipher)
send_rms = true;
TALER_denom_pub_hash (&md.fcds[i].fresh_pk,
&denom_hash);
@@ -429,20 +408,20 @@ TALER_EXCHANGE_refreshes_reveal (
}
/* build array of old age commitment, if applicable */
- GNUNET_assert ((NULL == rd->melt_age_commitment_proof) ==
- (NULL == rd->melt_h_age_commitment));
if (NULL != rd->melt_age_commitment_proof)
{
+ GNUNET_assert (NULL != rd->melt_h_age_commitment);
GNUNET_assert (NULL != (old_age_commitment = json_array ()));
for (size_t i = 0; i < rd->melt_age_commitment_proof->commitment.num; i++)
{
- GNUNET_assert (0 ==
- json_array_append_new (
- old_age_commitment,
- GNUNET_JSON_from_data_auto (
- &rd->melt_age_commitment_proof->
- commitment.keys[i])));
+ enum GNUNET_GenericReturnValue ret;
+
+ ret = json_array_append_new (
+ old_age_commitment,
+ GNUNET_JSON_from_data_auto (
+ &rd->melt_age_commitment_proof->commitment.keys[i]));
+ GNUNET_assert (0 == ret);
}
}
@@ -478,22 +457,24 @@ TALER_EXCHANGE_refreshes_reveal (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/refreshes/%s/reveal",
+ "refreshes/%s/reveal",
pub_str);
}
/* finally, we can actually issue the request */
rrh = GNUNET_new (struct TALER_EXCHANGE_RefreshesRevealHandle);
- rrh->exchange = exchange;
rrh->noreveal_index = noreveal_index;
rrh->reveal_cb = reveal_cb;
rrh->reveal_cb_cls = reveal_cb_cls;
rrh->md = md;
- rrh->alg_values = GNUNET_memdup (alg_values,
- md.num_fresh_coins
- * sizeof (struct
- TALER_ExchangeWithdrawValues));
- rrh->url = TEAH_path_to_url (rrh->exchange,
- arg_str);
+ rrh->alg_values
+ = GNUNET_new_array (md.num_fresh_coins,
+ struct TALER_ExchangeWithdrawValues);
+ for (unsigned int i = 0; i<md.num_fresh_coins; i++)
+ TALER_denom_ewv_copy (&rrh->alg_values[i],
+ &alg_values[i]);
+ rrh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rrh->url)
{
json_decref (reveal_obj);
@@ -521,7 +502,6 @@ TALER_EXCHANGE_refreshes_reveal (
return NULL;
}
json_decref (reveal_obj);
- ctx = TEAH_handle_to_context (rrh->exchange);
rrh->job = GNUNET_CURL_job_add2 (ctx,
eh,
rrh->ctx.headers,
@@ -540,6 +520,8 @@ TALER_EXCHANGE_refreshes_reveal_cancel (
GNUNET_CURL_job_cancel (rrh->job);
rrh->job = NULL;
}
+ for (unsigned int i = 0; i<rrh->md.num_fresh_coins; i++)
+ TALER_denom_ewv_free (&rrh->alg_values[i]);
GNUNET_free (rrh->alg_values);
GNUNET_free (rrh->url);
TALER_curl_easy_post_finished (&rrh->ctx);
diff --git a/src/lib/exchange_api_refund.c b/src/lib/exchange_api_refund.c
index 2b0f5b034..9159b55f2 100644
--- a/src/lib/exchange_api_refund.c
+++ b/src/lib/exchange_api_refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -39,9 +39,9 @@ struct TALER_EXCHANGE_RefundHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -117,7 +117,6 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh,
struct TALER_ExchangePublicKeyP *exchange_pub,
struct TALER_ExchangeSignatureP *exchange_sig)
{
- const struct TALER_EXCHANGE_Keys *key_state;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_fixed_auto ("exchange_sig",
exchange_sig),
@@ -134,9 +133,8 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- key_state = TALER_EXCHANGE_get_keys (rh->exchange);
if (GNUNET_OK !=
- TALER_EXCHANGE_test_signing_key (key_state,
+ TALER_EXCHANGE_test_signing_key (rh->keys,
exchange_pub))
{
GNUNET_break_op (0);
@@ -160,313 +158,6 @@ verify_refund_signature_ok (struct TALER_EXCHANGE_RefundHandle *rh,
/**
- * Verify that the information in the "409 Conflict" response
- * from the exchange is valid and indeed shows that the refund
- * amount requested is too high.
- *
- * @param[in,out] rh refund handle (refund fee added)
- * @param json json reply with the coin transaction history
- * @return #GNUNET_OK if the signature is valid, #GNUNET_SYSERR if not
- */
-static enum GNUNET_GenericReturnValue
-verify_conflict_history_ok (struct TALER_EXCHANGE_RefundHandle *rh,
- const json_t *json)
-{
- json_t *history;
- struct TALER_DenominationHashP h_denom_pub;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("history",
- &history),
- GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
- &h_denom_pub),
- GNUNET_JSON_spec_end ()
- };
- size_t len;
- struct TALER_Amount dtotal;
- bool have_deposit;
- struct TALER_Amount rtotal;
- bool have_refund;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- len = json_array_size (history);
- if (0 == len)
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- have_deposit = false;
- have_refund = false;
- for (size_t off = 0; off<len; off++)
- {
- json_t *transaction;
- struct TALER_Amount amount;
- const char *type;
- struct GNUNET_JSON_Specification spec_glob[] = {
- TALER_JSON_spec_amount_any ("amount",
- &amount),
- GNUNET_JSON_spec_string ("type",
- &type),
- GNUNET_JSON_spec_end ()
- };
-
- transaction = json_array_get (history,
- off);
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- spec_glob,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (0 == strcasecmp (type,
- "DEPOSIT"))
- {
- struct TALER_Amount deposit_fee;
- struct TALER_MerchantWireHashP h_wire;
- struct TALER_PrivateContractHashP h_contract_terms;
- struct TALER_AgeCommitmentHash h_age_commitment;
- bool no_hac;
- // struct TALER_ExtensionContractHashP h_extensions; // FIXME!
- struct GNUNET_TIME_Timestamp wallet_timestamp;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_TIME_Timestamp refund_deadline;
- struct TALER_CoinSpendSignatureP sig;
- struct GNUNET_JSON_Specification ispec[] = {
- GNUNET_JSON_spec_fixed_auto ("coin_sig",
- &sig),
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("h_wire",
- &h_wire),
- GNUNET_JSON_spec_mark_optional (
- GNUNET_JSON_spec_fixed_auto ("h_age_commitment",
- &h_age_commitment),
- &no_hac),
- GNUNET_JSON_spec_timestamp ("timestamp",
- &wallet_timestamp),
- GNUNET_JSON_spec_timestamp ("refund_deadline",
- &refund_deadline),
- TALER_JSON_spec_amount_any ("deposit_fee",
- &deposit_fee),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &merchant_pub),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_wallet_deposit_verify (&amount,
- &deposit_fee,
- &h_wire,
- &h_contract_terms,
- no_hac
- ? NULL
- : &h_age_commitment,
- NULL /* FIXME-OEC: h_extensions! */,
- &h_denom_pub,
- wallet_timestamp,
- &merchant_pub,
- refund_deadline,
- &rh->coin_pub,
- &sig))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if ( (0 != GNUNET_memcmp (&rh->h_contract_terms,
- &h_contract_terms)) ||
- (0 != GNUNET_memcmp (&rh->merchant,
- &merchant_pub)) )
- {
- /* deposit information is about a different merchant/contract */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (have_deposit)
- {
- /* this cannot really happen, but we conservatively support it anyway */
- if (GNUNET_YES !=
- TALER_amount_cmp_currency (&amount,
- &dtotal))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- GNUNET_break (0 <=
- TALER_amount_add (&dtotal,
- &dtotal,
- &amount));
- }
- else
- {
- dtotal = amount;
- have_deposit = true;
- }
- }
- else if (0 == strcasecmp (type,
- "REFUND"))
- {
- struct TALER_MerchantSignatureP sig;
- struct TALER_Amount refund_fee;
- struct TALER_Amount sig_amount;
- struct TALER_PrivateContractHashP h_contract_terms;
- uint64_t rtransaction_id;
- struct TALER_MerchantPublicKeyP merchant_pub;
- struct GNUNET_JSON_Specification ispec[] = {
- TALER_JSON_spec_amount_any ("refund_fee",
- &refund_fee),
- GNUNET_JSON_spec_fixed_auto ("merchant_sig",
- &sig),
- GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
- &h_contract_terms),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub",
- &merchant_pub),
- GNUNET_JSON_spec_uint64 ("rtransaction_id",
- &rtransaction_id),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (transaction,
- ispec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (0 >
- TALER_amount_add (&sig_amount,
- &refund_fee,
- &amount))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- TALER_merchant_refund_verify (&rh->coin_pub,
- &h_contract_terms,
- rtransaction_id,
- &sig_amount,
- &merchant_pub,
- &sig))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if ( (0 != GNUNET_memcmp (&rh->h_contract_terms,
- &h_contract_terms)) ||
- (0 != GNUNET_memcmp (&rh->merchant,
- &merchant_pub)) )
- {
- /* refund is about a different merchant/contract */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (rtransaction_id == rh->rtransaction_id)
- {
- /* Eh, this shows either a dependency failure or idempotency,
- but must not happen in a conflict reply. Fail! */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
-
- if (have_refund)
- {
- if (GNUNET_YES !=
- TALER_amount_cmp_currency (&amount,
- &rtotal))
- {
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- GNUNET_break (0 <=
- TALER_amount_add (&rtotal,
- &rtotal,
- &amount));
- }
- else
- {
- rtotal = amount;
- have_refund = true;
- }
- }
- else
- {
- /* unexpected type, new version on server? */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected type `%s' in response for exchange refund\n",
- type);
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- }
-
- if (have_refund)
- {
- if (0 >
- TALER_amount_add (&rtotal,
- &rtotal,
- &rh->refund_amount))
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- }
- else
- {
- rtotal = rh->refund_amount;
- have_refund = true;
- }
- if (! have_deposit)
- {
- GNUNET_break (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (-1 != TALER_amount_cmp (&dtotal,
- &rtotal))
- {
- /* rtotal <= dtotal is fine, no conflict! */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- /* dtotal < rtotal: that's a conflict! */
- GNUNET_JSON_parse_free (spec);
- return GNUNET_OK;
-}
-
-
-/**
* Verify that the information on the "412 Dependency Failed" response
* from the exchange is valid and indeed shows that there is a refund
* transaction ID reuse going on.
@@ -479,11 +170,11 @@ static enum GNUNET_GenericReturnValue
verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh,
const json_t *json)
{
- json_t *h;
+ const json_t *h;
json_t *e;
struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("history",
- &h),
+ GNUNET_JSON_spec_array_const ("history",
+ &h),
GNUNET_JSON_spec_end ()
};
@@ -495,11 +186,9 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- if ( (! json_is_array (h)) ||
- (1 != json_array_size (h) ) )
+ if (1 != json_array_size (h))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
e = json_array_get (h, 0);
@@ -535,7 +224,6 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh,
NULL, NULL))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -547,7 +235,6 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh,
&sig))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if ( (rtransaction_id != rh->rtransaction_id) ||
@@ -559,11 +246,9 @@ verify_failed_dependency_ok (struct TALER_EXCHANGE_RefundHandle *rh,
&amount)) )
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
}
- GNUNET_JSON_parse_free (spec);
return GNUNET_OK;
}
@@ -582,37 +267,28 @@ handle_refund_finished (void *cls,
const void *response)
{
struct TALER_EXCHANGE_RefundHandle *rh = cls;
- struct TALER_ExchangePublicKeyP exchange_pub;
- struct TALER_ExchangeSignatureP exchange_sig;
- struct TALER_ExchangePublicKeyP *ep = NULL;
- struct TALER_ExchangeSignatureP *es = NULL;
const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_RefundResponse rr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
};
rh->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ rr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
verify_refund_signature_ok (rh,
j,
- &exchange_pub,
- &exchange_sig))
+ &rr.details.ok.exchange_pub,
+ &rr.details.ok.exchange_sig))
{
GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_EXCHANGE_REFUND_INVALID_SIGNATURE_BY_EXCHANGE;
- }
- else
- {
- ep = &exchange_pub;
- es = &exchange_sig;
+ rr.hr.http_status = 0;
+ rr.hr.ec = TALER_EC_EXCHANGE_REFUND_INVALID_SIGNATURE_BY_EXCHANGE;
}
break;
case MHD_HTTP_BAD_REQUEST:
@@ -620,45 +296,36 @@ handle_refund_finished (void *cls,
(or API version conflict); also can happen if the currency
differs (which we should obviously never support).
Just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Nothing really to verify, this should never
happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_CONFLICT:
/* Requested total refunds exceed deposited amount */
- if (GNUNET_OK !=
- verify_conflict_history_ok (rh,
- j))
- {
- GNUNET_break (0);
- json_dumpf (j,
- stderr,
- JSON_INDENT (2));
- hr.http_status = 0;
- hr.ec = TALER_EC_EXCHANGE_REFUND_INVALID_FAILURE_PROOF_BY_EXCHANGE;
- hr.hint = "conflict information provided by exchange is invalid";
- break;
- }
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_GONE:
/* Kind of normal: the money was already sent to the merchant
(it was too late for the refund). */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_FAILED_DEPENDENCY:
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_PRECONDITION_FAILED:
if (GNUNET_OK !=
@@ -666,44 +333,44 @@ handle_refund_finished (void *cls,
j))
{
GNUNET_break (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_EXCHANGE_REFUND_INVALID_FAILURE_PROOF_BY_EXCHANGE;
- hr.hint = "failed precondition proof returned by exchange is invalid";
+ rr.hr.http_status = 0;
+ rr.hr.ec = TALER_EC_EXCHANGE_REFUND_INVALID_FAILURE_PROOF_BY_EXCHANGE;
+ rr.hr.hint = "failed precondition proof returned by exchange is invalid";
break;
}
/* Two different refund requests were made about the same deposit, but
carrying identical refund transaction ids. */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ rr.hr.ec = TALER_JSON_get_error_code (j);
+ rr.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for exchange refund\n",
(unsigned int) response_code,
- hr.ec);
+ rr.hr.ec);
break;
}
rh->cb (rh->cb_cls,
- &hr,
- ep,
- es);
+ &rr);
TALER_EXCHANGE_refund_cancel (rh);
}
struct TALER_EXCHANGE_RefundHandle *
TALER_EXCHANGE_refund (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_Amount *amount,
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
@@ -715,13 +382,10 @@ TALER_EXCHANGE_refund (
struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_MerchantSignatureP merchant_sig;
struct TALER_EXCHANGE_RefundHandle *rh;
- struct GNUNET_CURL_Context *ctx;
json_t *refund_obj;
CURL *eh;
char arg_str[sizeof (struct TALER_CoinSpendPublicKeyP) * 2 + 32];
- GNUNET_assert (GNUNET_YES ==
- TEAH_handle_is_ready (exchange));
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv->eddsa_priv,
&merchant_pub.eddsa_pub);
TALER_merchant_refund_sign (coin_pub,
@@ -742,7 +406,7 @@ TALER_EXCHANGE_refund (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/coins/%s/refund",
+ "coins/%s/refund",
pub_str);
}
refund_obj = GNUNET_JSON_PACK (
@@ -757,11 +421,11 @@ TALER_EXCHANGE_refund (
GNUNET_JSON_pack_data_auto ("merchant_sig",
&merchant_sig));
rh = GNUNET_new (struct TALER_EXCHANGE_RefundHandle);
- rh->exchange = exchange;
rh->cb = cb;
rh->cb_cls = cb_cls;
- rh->url = TEAH_path_to_url (exchange,
- arg_str);
+ rh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rh->url)
{
json_decref (refund_obj);
@@ -792,7 +456,7 @@ TALER_EXCHANGE_refund (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"URL for refund: `%s'\n",
rh->url);
- ctx = TEAH_handle_to_context (exchange);
+ rh->keys = TALER_EXCHANGE_keys_incref (keys);
rh->job = GNUNET_CURL_job_add2 (ctx,
eh,
rh->ctx.headers,
@@ -812,6 +476,7 @@ TALER_EXCHANGE_refund_cancel (struct TALER_EXCHANGE_RefundHandle *refund)
}
GNUNET_free (refund->url);
TALER_curl_easy_post_finished (&refund->ctx);
+ TALER_EXCHANGE_keys_decref (refund->keys);
GNUNET_free (refund);
}
diff --git a/src/lib/exchange_api_reserves_status.c b/src/lib/exchange_api_reserves_attest.c
index 35f5846f3..d5a867114 100644
--- a/src/lib/exchange_api_reserves_status.c
+++ b/src/lib/exchange_api_reserves_attest.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -15,13 +15,13 @@
<http://www.gnu.org/licenses/>
*/
/**
- * @file lib/exchange_api_reserves_status.c
- * @brief Implementation of the POST /reserves/$RESERVE_PUB/status requests
+ * @file lib/exchange_api_reserves_attest.c
+ * @brief Implementation of the POST /reserves-attest/$RESERVE_PUB requests
* @author Christian Grothoff
*/
#include "platform.h"
#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
+#include <microhttpd.h> /* just for HTTP attest codes */
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include <gnunet/gnunet_curl_lib.h>
@@ -33,15 +33,15 @@
/**
- * @brief A /reserves/$RID/status Handle
+ * @brief A /reserves-attest/$RID Handle
*/
-struct TALER_EXCHANGE_ReservesStatusHandle
+struct TALER_EXCHANGE_ReservesAttestHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -62,7 +62,7 @@ struct TALER_EXCHANGE_ReservesStatusHandle
/**
* Function to call with the result.
*/
- TALER_EXCHANGE_ReservesStatusCallback cb;
+ TALER_EXCHANGE_ReservesPostAttestCallback cb;
/**
* Public key of the reserve we are querying.
@@ -78,7 +78,7 @@ struct TALER_EXCHANGE_ReservesStatusHandle
/**
- * We received an #MHD_HTTP_OK status code. Handle the JSON
+ * We received an #MHD_HTTP_OK attest code. Handle the JSON
* response.
*
* @param rsh handle of the request
@@ -86,22 +86,25 @@ struct TALER_EXCHANGE_ReservesStatusHandle
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh,
+handle_reserves_attest_ok (struct TALER_EXCHANGE_ReservesAttestHandle *rsh,
const json_t *j)
{
- json_t *history;
- unsigned int len;
- struct TALER_EXCHANGE_ReserveStatus rs = {
+ struct TALER_EXCHANGE_ReservePostAttestResult rs = {
.hr.reply = j,
.hr.http_status = MHD_HTTP_OK
};
+ const json_t *attributes;
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("balance",
- &rs.details.ok.balance),
- GNUNET_JSON_spec_bool ("kyc_passed",
- &rs.details.ok.kyc_ok),
- GNUNET_JSON_spec_json ("history",
- &history),
+ GNUNET_JSON_spec_timestamp ("exchange_timestamp",
+ &rs.details.ok.exchange_time),
+ GNUNET_JSON_spec_timestamp ("expiration_time",
+ &rs.details.ok.expiration_time),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rs.details.ok.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rs.details.ok.exchange_pub),
+ GNUNET_JSON_spec_object_const ("attributes",
+ &attributes),
GNUNET_JSON_spec_end ()
};
@@ -114,39 +117,36 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- len = json_array_size (history);
+ if (GNUNET_OK !=
+ TALER_EXCHANGE_test_signing_key (rsh->keys,
+ &rs.details.ok.exchange_pub))
{
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory;
-
- rhistory = GNUNET_new_array (len,
- struct TALER_EXCHANGE_ReserveHistoryEntry);
- if (GNUNET_OK !=
- TALER_EXCHANGE_parse_reserve_history (rsh->exchange,
- history,
- &rsh->reserve_pub,
- rs.details.ok.balance.currency,
- &rs.details.ok.total_in,
- &rs.details.ok.total_out,
- len,
- rhistory))
- {
- GNUNET_break_op (0);
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
- GNUNET_JSON_parse_free (spec);
- return GNUNET_SYSERR;
- }
- if (NULL != rsh->cb)
- {
- rs.details.ok.history = rhistory;
- rs.details.ok.history_len = len;
- rsh->cb (rsh->cb_cls,
- &rs);
- rsh->cb = NULL;
- }
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_EXCHANGE_DEPOSITS_GET_INVALID_SIGNATURE_BY_EXCHANGE;
+ rsh->cb (rsh->cb_cls,
+ &rs);
+ rsh->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_SYSERR;
}
+ rs.details.ok.attributes = attributes;
+ if (GNUNET_OK !=
+ TALER_exchange_online_reserve_attest_details_verify (
+ rs.details.ok.exchange_time,
+ rs.details.ok.expiration_time,
+ &rsh->reserve_pub,
+ attributes,
+ &rs.details.ok.exchange_pub,
+ &rs.details.ok.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_SYSERR;
+ }
+ rsh->cb (rsh->cb_cls,
+ &rs);
+ rsh->cb = NULL;
GNUNET_JSON_parse_free (spec);
return GNUNET_OK;
}
@@ -154,20 +154,20 @@ handle_reserves_status_ok (struct TALER_EXCHANGE_ReservesStatusHandle *rsh,
/**
* Function called when we're done processing the
- * HTTP /reserves/$RID/status request.
+ * HTTP /reserves-attest/$RID request.
*
- * @param cls the `struct TALER_EXCHANGE_ReservesStatusHandle`
+ * @param cls the `struct TALER_EXCHANGE_ReservesAttestHandle`
* @param response_code HTTP response code, 0 on error
* @param response parsed JSON result, NULL on error
*/
static void
-handle_reserves_status_finished (void *cls,
+handle_reserves_attest_finished (void *cls,
long response_code,
const void *response)
{
- struct TALER_EXCHANGE_ReservesStatusHandle *rsh = cls;
+ struct TALER_EXCHANGE_ReservesAttestHandle *rsh = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_ReserveStatus rs = {
+ struct TALER_EXCHANGE_ReservePostAttestResult rs = {
.hr.reply = j,
.hr.http_status = (unsigned int) response_code
};
@@ -180,7 +180,7 @@ handle_reserves_status_finished (void *cls,
break;
case MHD_HTTP_OK:
if (GNUNET_OK !=
- handle_reserves_status_ok (rsh,
+ handle_reserves_attest_ok (rsh,
j))
{
rs.hr.http_status = 0;
@@ -207,6 +207,11 @@ handle_reserves_status_finished (void *cls,
rs.hr.ec = TALER_JSON_get_error_code (j);
rs.hr.hint = TALER_JSON_get_error_hint (j);
break;
+ case MHD_HTTP_CONFLICT:
+ /* Server doesn't have the requested attributes */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
@@ -219,7 +224,7 @@ handle_reserves_status_finished (void *cls,
rs.hr.ec = TALER_JSON_get_error_code (j);
rs.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for reserves status\n",
+ "Unexpected response code %u/%d for reserves attest\n",
(unsigned int) response_code,
(int) rs.hr.ec);
break;
@@ -230,33 +235,42 @@ handle_reserves_status_finished (void *cls,
&rs);
rsh->cb = NULL;
}
- TALER_EXCHANGE_reserves_status_cancel (rsh);
+ TALER_EXCHANGE_reserves_attest_cancel (rsh);
}
-struct TALER_EXCHANGE_ReservesStatusHandle *
-TALER_EXCHANGE_reserves_status (
- struct TALER_EXCHANGE_Handle *exchange,
+struct TALER_EXCHANGE_ReservesAttestHandle *
+TALER_EXCHANGE_reserves_attest (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_ReservesStatusCallback cb,
+ unsigned int attributes_length,
+ const char *attributes[const static attributes_length],
+ TALER_EXCHANGE_ReservesPostAttestCallback cb,
void *cb_cls)
{
- struct TALER_EXCHANGE_ReservesStatusHandle *rsh;
- struct GNUNET_CURL_Context *ctx;
+ struct TALER_EXCHANGE_ReservesAttestHandle *rsh;
CURL *eh;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
struct TALER_ReserveSignatureP reserve_sig;
- struct GNUNET_TIME_Timestamp ts
- = GNUNET_TIME_timestamp_get ();
+ json_t *details;
+ struct GNUNET_TIME_Timestamp ts;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
+ if (0 == attributes_length)
{
GNUNET_break (0);
return NULL;
}
- rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesStatusHandle);
- rsh->exchange = exchange;
+ details = json_array ();
+ GNUNET_assert (NULL != details);
+ for (unsigned int i = 0; i<attributes_length; i++)
+ {
+ GNUNET_assert (0 ==
+ json_array_append_new (details,
+ json_string (attributes[i])));
+ }
+ rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesAttestHandle);
rsh->cb = cb;
rsh->cb_cls = cb_cls;
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
@@ -273,13 +287,15 @@ TALER_EXCHANGE_reserves_status (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s/status",
+ "reserves-attest/%s",
pub_str);
}
- rsh->url = TEAH_path_to_url (exchange,
- arg_str);
+ rsh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rsh->url)
{
+ json_decref (details);
GNUNET_free (rsh);
return NULL;
}
@@ -287,47 +303,52 @@ TALER_EXCHANGE_reserves_status (
if (NULL == eh)
{
GNUNET_break (0);
+ json_decref (details);
GNUNET_free (rsh->url);
GNUNET_free (rsh);
return NULL;
}
- TALER_wallet_reserve_status_sign (ts,
- reserve_priv,
- &reserve_sig);
+ ts = GNUNET_TIME_timestamp_get ();
+ TALER_wallet_reserve_attest_request_sign (ts,
+ details,
+ reserve_priv,
+ &reserve_sig);
{
- json_t *status_obj = GNUNET_JSON_PACK (
+ json_t *attest_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &reserve_sig),
GNUNET_JSON_pack_timestamp ("request_timestamp",
ts),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &reserve_sig));
+ GNUNET_JSON_pack_array_steal ("details",
+ details));
if (GNUNET_OK !=
TALER_curl_easy_post (&rsh->post_ctx,
eh,
- status_obj))
+ attest_obj))
{
GNUNET_break (0);
curl_easy_cleanup (eh);
- json_decref (status_obj);
+ json_decref (attest_obj);
GNUNET_free (rsh->url);
GNUNET_free (rsh);
return NULL;
}
- json_decref (status_obj);
+ json_decref (attest_obj);
}
- ctx = TEAH_handle_to_context (exchange);
rsh->job = GNUNET_CURL_job_add2 (ctx,
eh,
rsh->post_ctx.headers,
- &handle_reserves_status_finished,
+ &handle_reserves_attest_finished,
rsh);
+ rsh->keys = TALER_EXCHANGE_keys_incref (keys);
return rsh;
}
void
-TALER_EXCHANGE_reserves_status_cancel (
- struct TALER_EXCHANGE_ReservesStatusHandle *rsh)
+TALER_EXCHANGE_reserves_attest_cancel (
+ struct TALER_EXCHANGE_ReservesAttestHandle *rsh)
{
if (NULL != rsh->job)
{
@@ -335,9 +356,10 @@ TALER_EXCHANGE_reserves_status_cancel (
rsh->job = NULL;
}
TALER_curl_easy_post_finished (&rsh->post_ctx);
+ TALER_EXCHANGE_keys_decref (rsh->keys);
GNUNET_free (rsh->url);
GNUNET_free (rsh);
}
-/* end of exchange_api_reserves_status.c */
+/* end of exchange_api_reserves_attest.c */
diff --git a/src/lib/exchange_api_reserves_close.c b/src/lib/exchange_api_reserves_close.c
new file mode 100644
index 000000000..a3769a22f
--- /dev/null
+++ b/src/lib/exchange_api_reserves_close.c
@@ -0,0 +1,373 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_reserves_close.c
+ * @brief Implementation of the POST /reserves/$RESERVE_PUB/close requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP close codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A /reserves/$RID/close Handle
+ */
+struct TALER_EXCHANGE_ReservesCloseHandle
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Context for #TEH_curl_easy_post(). Keeps the data that must
+ * persist for Curl to make the upload.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ReservesCloseCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Public key of the reserve we are querying.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Our signature.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * When did we make the request.
+ */
+ struct GNUNET_TIME_Timestamp ts;
+
+};
+
+
+/**
+ * We received an #MHD_HTTP_OK close code. Handle the JSON
+ * response.
+ *
+ * @param rch handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_close_ok (struct TALER_EXCHANGE_ReservesCloseHandle *rch,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveCloseResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_OK,
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("wire_amount",
+ &rs.details.ok.wire_amount),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ rch->cb (rch->cb_cls,
+ &rs);
+ rch->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * We received an #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS close code. Handle the JSON
+ * response.
+ *
+ * @param rch handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_close_kyc (struct TALER_EXCHANGE_ReservesCloseHandle *rch,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveCloseResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &rs.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &rs.details.unavailable_for_legal_reasons.requirement_row),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ rch->cb (rch->cb_cls,
+ &rs);
+ rch->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /reserves/$RID/close request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ReservesCloseHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_reserves_close_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ReservesCloseHandle *rch = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_ReserveCloseResult rs = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ rch->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ handle_reserves_close_ok (rch,
+ j))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* Insufficient balance to inquire for reserve close */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ if (GNUNET_OK !=
+ handle_reserves_close_kyc (rch,
+ j))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for reserves close\n",
+ (unsigned int) response_code,
+ (int) rs.hr.ec);
+ break;
+ }
+ if (NULL != rch->cb)
+ {
+ rch->cb (rch->cb_cls,
+ &rs);
+ rch->cb = NULL;
+ }
+ TALER_EXCHANGE_reserves_close_cancel (rch);
+}
+
+
+struct TALER_EXCHANGE_ReservesCloseHandle *
+TALER_EXCHANGE_reserves_close (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const char *target_payto_uri,
+ TALER_EXCHANGE_ReservesCloseCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_ReservesCloseHandle *rch;
+ CURL *eh;
+ char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
+ struct TALER_PaytoHashP h_payto;
+
+ rch = GNUNET_new (struct TALER_EXCHANGE_ReservesCloseHandle);
+ rch->cb = cb;
+ rch->cb_cls = cb_cls;
+ rch->ts = GNUNET_TIME_timestamp_get ();
+ GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
+ &rch->reserve_pub.eddsa_pub);
+ {
+ char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &rch->reserve_pub,
+ sizeof (rch->reserve_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves/%s/close",
+ pub_str);
+ }
+ rch->url = TALER_url_join (url,
+ arg_str,
+ NULL);
+ if (NULL == rch->url)
+ {
+ GNUNET_free (rch);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (rch->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (rch->url);
+ GNUNET_free (rch);
+ return NULL;
+ }
+ if (NULL != target_payto_uri)
+ TALER_payto_hash (target_payto_uri,
+ &h_payto);
+ TALER_wallet_reserve_close_sign (rch->ts,
+ (NULL != target_payto_uri)
+ ? &h_payto
+ : NULL,
+ reserve_priv,
+ &rch->reserve_sig);
+ {
+ json_t *close_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("payto_uri",
+ target_payto_uri)),
+ GNUNET_JSON_pack_timestamp ("request_timestamp",
+ rch->ts),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &rch->reserve_sig));
+
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&rch->post_ctx,
+ eh,
+ close_obj))
+ {
+ GNUNET_break (0);
+ curl_easy_cleanup (eh);
+ json_decref (close_obj);
+ GNUNET_free (rch->url);
+ GNUNET_free (rch);
+ return NULL;
+ }
+ json_decref (close_obj);
+ }
+ rch->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ rch->post_ctx.headers,
+ &handle_reserves_close_finished,
+ rch);
+ return rch;
+}
+
+
+void
+TALER_EXCHANGE_reserves_close_cancel (
+ struct TALER_EXCHANGE_ReservesCloseHandle *rch)
+{
+ if (NULL != rch->job)
+ {
+ GNUNET_CURL_job_cancel (rch->job);
+ rch->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&rch->post_ctx);
+ GNUNET_free (rch->url);
+ GNUNET_free (rch);
+}
+
+
+/* end of exchange_api_reserves_close.c */
diff --git a/src/lib/exchange_api_reserves_get.c b/src/lib/exchange_api_reserves_get.c
index d829b4593..b6980dd1d 100644
--- a/src/lib/exchange_api_reserves_get.c
+++ b/src/lib/exchange_api_reserves_get.c
@@ -39,11 +39,6 @@ struct TALER_EXCHANGE_ReservesGetHandle
{
/**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
* The url for this request.
*/
char *url;
@@ -168,9 +163,10 @@ handle_reserves_get_finished (void *cls,
rs.hr.ec = TALER_JSON_get_error_code (j);
rs.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for reserves get\n",
+ "Unexpected response code %u/%d for GET %s\n",
(unsigned int) response_code,
- (int) rs.hr.ec);
+ (int) rs.hr.ec,
+ rgh->url);
break;
}
if (NULL != rgh->cb)
@@ -185,23 +181,20 @@ handle_reserves_get_finished (void *cls,
struct TALER_EXCHANGE_ReservesGetHandle *
TALER_EXCHANGE_reserves_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
const struct TALER_ReservePublicKeyP *reserve_pub,
struct GNUNET_TIME_Relative timeout,
TALER_EXCHANGE_ReservesGetCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_ReservesGetHandle *rgh;
- struct GNUNET_CURL_Context *ctx;
CURL *eh;
char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 16 + 32];
+ unsigned int tms
+ = (unsigned int) timeout.rel_value_us
+ / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
{
char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
char *end;
@@ -215,29 +208,27 @@ TALER_EXCHANGE_reserves_get (
*end = '\0';
GNUNET_snprintf (timeout_str,
sizeof (timeout_str),
- "%llu",
- (unsigned long long)
- (timeout.rel_value_us
- / GNUNET_TIME_UNIT_MILLISECONDS.rel_value_us));
- if (GNUNET_TIME_relative_is_zero (timeout))
+ "%u",
+ tms);
+ if (0 == tms)
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s",
+ "reserves/%s",
pub_str);
else
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/reserves/%s?timeout_ms=%s",
+ "reserves/%s?timeout_ms=%s",
pub_str,
timeout_str);
}
rgh = GNUNET_new (struct TALER_EXCHANGE_ReservesGetHandle);
- rgh->exchange = exchange;
rgh->cb = cb;
rgh->cb_cls = cb_cls;
rgh->reserve_pub = *reserve_pub;
- rgh->url = TEAH_path_to_url (exchange,
- arg_str);
+ rgh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rgh->url)
{
GNUNET_free (rgh);
@@ -251,7 +242,13 @@ TALER_EXCHANGE_reserves_get (
GNUNET_free (rgh);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
+ if (0 != tms)
+ {
+ GNUNET_break (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_TIMEOUT_MS,
+ (long) (tms + 100L)));
+ }
rgh->job = GNUNET_CURL_job_add (ctx,
eh,
&handle_reserves_get_finished,
diff --git a/src/lib/exchange_api_reserves_get_attestable.c b/src/lib/exchange_api_reserves_get_attestable.c
new file mode 100644
index 000000000..f58e0592e
--- /dev/null
+++ b/src/lib/exchange_api_reserves_get_attestable.c
@@ -0,0 +1,276 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_reserves_get_attestable.c
+ * @brief Implementation of the GET_ATTESTABLE /reserves/$RESERVE_PUB requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP status codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * @brief A /reserves/ GET_ATTESTABLE Handle
+ */
+struct TALER_EXCHANGE_ReservesGetAttestHandle
+{
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ReservesGetAttestCallback cb;
+
+ /**
+ * Public key of the reserve we are querying.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+};
+
+
+/**
+ * We received an #MHD_HTTP_OK status code. Handle the JSON
+ * response.
+ *
+ * @param rgah handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_get_attestable_ok (
+ struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveGetAttestResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_OK
+ };
+ const json_t *details;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_array_const ("details",
+ &details),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ {
+ unsigned int dlen = json_array_size (details);
+ const char *attributes[GNUNET_NZL (dlen)];
+
+ for (unsigned int i = 0; i<dlen; i++)
+ {
+ json_t *detail = json_array_get (details,
+ i);
+ attributes[i] = json_string_value (detail);
+ if (NULL == attributes[i])
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ rs.details.ok.attributes_length = dlen;
+ rs.details.ok.attributes = attributes;
+ rgah->cb (rgah->cb_cls,
+ &rs);
+ rgah->cb = NULL;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP GET /reserves-attest/$RID request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ReservesGetAttestableHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_reserves_get_attestable_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_ReserveGetAttestResult rs = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ rgah->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ handle_reserves_get_attestable_ok (rgah,
+ j))
+ {
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for reserves get_attestable\n",
+ (unsigned int) response_code,
+ (int) rs.hr.ec);
+ break;
+ }
+ if (NULL != rgah->cb)
+ {
+ rgah->cb (rgah->cb_cls,
+ &rs);
+ rgah->cb = NULL;
+ }
+ TALER_EXCHANGE_reserves_get_attestable_cancel (rgah);
+}
+
+
+struct TALER_EXCHANGE_ReservesGetAttestHandle *
+TALER_EXCHANGE_reserves_get_attestable (
+ 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;
+ CURL *eh;
+ char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
+
+ {
+ char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ reserve_pub,
+ sizeof (*reserve_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves-attest/%s",
+ pub_str);
+ }
+ rgah = GNUNET_new (struct TALER_EXCHANGE_ReservesGetAttestHandle);
+ rgah->cb = cb;
+ rgah->cb_cls = cb_cls;
+ rgah->reserve_pub = *reserve_pub;
+ rgah->url = TALER_url_join (url,
+ arg_str,
+ NULL);
+ if (NULL == rgah->url)
+ {
+ GNUNET_free (rgah);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (rgah->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (rgah->url);
+ GNUNET_free (rgah);
+ return NULL;
+ }
+ rgah->job = GNUNET_CURL_job_add (ctx,
+ eh,
+ &handle_reserves_get_attestable_finished,
+ rgah);
+ return rgah;
+}
+
+
+void
+TALER_EXCHANGE_reserves_get_attestable_cancel (
+ struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah)
+{
+ if (NULL != rgah->job)
+ {
+ GNUNET_CURL_job_cancel (rgah->job);
+ rgah->job = NULL;
+ }
+ GNUNET_free (rgah->url);
+ GNUNET_free (rgah);
+}
+
+
+/* end of exchange_api_reserves_get_attestable.c */
diff --git a/src/lib/exchange_api_reserves_history.c b/src/lib/exchange_api_reserves_history.c
index 2a0dd5651..0654ad837 100644
--- a/src/lib/exchange_api_reserves_history.c
+++ b/src/lib/exchange_api_reserves_history.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -39,9 +39,9 @@ struct TALER_EXCHANGE_ReservesHistoryHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -65,29 +65,808 @@ struct TALER_EXCHANGE_ReservesHistoryHandle
TALER_EXCHANGE_ReservesHistoryCallback cb;
/**
+ * Public key of the reserve we are querying.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
* Closure for @a cb.
*/
void *cb_cls;
/**
- * Public key of the reserve we are querying.
+ * Where to store the etag (if any).
*/
- struct TALER_ReservePublicKeyP reserve_pub;
+ uint64_t etag;
+
+};
+
+
+/**
+ * Context for history entry helpers.
+ */
+struct HistoryParseContext
+{
+
+ /**
+ * Keys of the exchange we use.
+ */
+ const struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * Our reserve public key.
+ */
+ const struct TALER_ReservePublicKeyP *reserve_pub;
/**
- * Our signature.
+ * Array of UUIDs.
*/
- struct TALER_ReserveSignatureP reserve_sig;
+ struct GNUNET_HashCode *uuids;
/**
- * When did we make the request.
+ * Where to sum up total inbound amounts.
*/
- struct GNUNET_TIME_Timestamp ts;
+ struct TALER_Amount *total_in;
+ /**
+ * Where to sum up total outbound amounts.
+ */
+ struct TALER_Amount *total_out;
+
+ /**
+ * Number of entries already used in @e uuids.
+ */
+ unsigned int uuid_off;
};
/**
+ * Type of a function called to parse a reserve history
+ * entry @a rh.
+ *
+ * @param[in,out] rh where to write the result
+ * @param[in,out] uc UUID context for duplicate detection
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+typedef enum GNUNET_GenericReturnValue
+(*ParseHelper)(struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction);
+
+
+/**
+ * Parse "credit" reserve history entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_credit (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ const char *wire_uri;
+ uint64_t wire_reference;
+ struct GNUNET_TIME_Timestamp timestamp;
+ struct GNUNET_JSON_Specification withdraw_spec[] = {
+ GNUNET_JSON_spec_uint64 ("wire_reference",
+ &wire_reference),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &timestamp),
+ TALER_JSON_spec_payto_uri ("sender_account_url",
+ &wire_uri),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_CREDIT;
+ if (0 >
+ TALER_amount_add (uc->total_in,
+ uc->total_in,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ withdraw_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ rh->details.in_details.sender_url = GNUNET_strdup (wire_uri);
+ rh->details.in_details.wire_reference = wire_reference;
+ rh->details.in_details.timestamp = timestamp;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "credit" reserve history entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_withdraw (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ struct TALER_ReserveSignatureP sig;
+ struct TALER_DenominationHashP h_denom_pub;
+ struct TALER_BlindedCoinHashP bch;
+ struct TALER_Amount withdraw_fee;
+ struct GNUNET_JSON_Specification withdraw_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &sig),
+ TALER_JSON_spec_amount_any ("withdraw_fee",
+ &withdraw_fee),
+ GNUNET_JSON_spec_fixed_auto ("h_denom_pub",
+ &h_denom_pub),
+ GNUNET_JSON_spec_fixed_auto ("h_coin_envelope",
+ &bch),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_WITHDRAWAL;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ withdraw_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+
+ /* Check that the signature is a valid withdraw request */
+ if (GNUNET_OK !=
+ TALER_wallet_withdraw_verify (&h_denom_pub,
+ &rh->amount,
+ &bch,
+ uc->reserve_pub,
+ &sig))
+ {
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (withdraw_spec);
+ return GNUNET_SYSERR;
+ }
+ /* check that withdraw fee matches expectations! */
+ {
+ const struct TALER_EXCHANGE_Keys *key_state;
+ const struct TALER_EXCHANGE_DenomPublicKey *dki;
+
+ key_state = uc->keys;
+ dki = TALER_EXCHANGE_get_denomination_key_by_hash (key_state,
+ &h_denom_pub);
+ if ( (GNUNET_YES !=
+ TALER_amount_cmp_currency (&withdraw_fee,
+ &dki->fees.withdraw)) ||
+ (0 !=
+ TALER_amount_cmp (&withdraw_fee,
+ &dki->fees.withdraw)) )
+ {
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (withdraw_spec);
+ return GNUNET_SYSERR;
+ }
+ rh->details.withdraw.fee = withdraw_fee;
+ }
+ rh->details.withdraw.out_authorization_sig
+ = json_object_get (transaction,
+ "signature");
+ /* Check check that the same withdraw transaction
+ isn't listed twice by the exchange. We use the
+ "uuid" array to remember the hashes of all
+ signatures, and compare the hashes to find
+ duplicates. */
+ GNUNET_CRYPTO_hash (&sig,
+ sizeof (sig),
+ &uc->uuids[uc->uuid_off]);
+ for (unsigned int i = 0; i<uc->uuid_off; i++)
+ {
+ if (0 == GNUNET_memcmp (&uc->uuids[uc->uuid_off],
+ &uc->uuids[i]))
+ {
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (withdraw_spec);
+ return GNUNET_SYSERR;
+ }
+ }
+ uc->uuid_off++;
+
+ if (0 >
+ TALER_amount_add (uc->total_out,
+ uc->total_out,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ GNUNET_JSON_parse_free (withdraw_spec);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "recoup" reserve history entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_recoup (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ const struct TALER_EXCHANGE_Keys *key_state;
+ struct GNUNET_JSON_Specification recoup_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("coin_pub",
+ &rh->details.recoup_details.coin_pub),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.recoup_details.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.recoup_details.exchange_pub),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.recoup_details.timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_RECOUP;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ recoup_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ key_state = uc->keys;
+ if (GNUNET_OK !=
+ TALER_EXCHANGE_test_signing_key (key_state,
+ &rh->details.
+ recoup_details.exchange_pub))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_confirm_recoup_verify (
+ rh->details.recoup_details.timestamp,
+ &rh->amount,
+ &rh->details.recoup_details.coin_pub,
+ uc->reserve_pub,
+ &rh->details.recoup_details.exchange_pub,
+ &rh->details.recoup_details.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 >
+ TALER_amount_add (uc->total_in,
+ uc->total_in,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "closing" reserve history entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_closing (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ const struct TALER_EXCHANGE_Keys *key_state;
+ struct GNUNET_JSON_Specification closing_spec[] = {
+ TALER_JSON_spec_payto_uri (
+ "receiver_account_details",
+ &rh->details.close_details.receiver_account_details),
+ GNUNET_JSON_spec_fixed_auto ("wtid",
+ &rh->details.close_details.wtid),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &rh->details.close_details.exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &rh->details.close_details.exchange_pub),
+ TALER_JSON_spec_amount_any ("closing_fee",
+ &rh->details.close_details.fee),
+ GNUNET_JSON_spec_timestamp ("timestamp",
+ &rh->details.close_details.timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_CLOSING;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ closing_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ key_state = uc->keys;
+ if (GNUNET_OK !=
+ TALER_EXCHANGE_test_signing_key (
+ key_state,
+ &rh->details.close_details.exchange_pub))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_exchange_online_reserve_closed_verify (
+ rh->details.close_details.timestamp,
+ &rh->amount,
+ &rh->details.close_details.fee,
+ rh->details.close_details.receiver_account_details,
+ &rh->details.close_details.wtid,
+ uc->reserve_pub,
+ &rh->details.close_details.exchange_pub,
+ &rh->details.close_details.exchange_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 >
+ TALER_amount_add (uc->total_out,
+ uc->total_out,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "merge" reserve history entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_merge (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ uint32_t flags32;
+ struct GNUNET_JSON_Specification merge_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
+ &rh->details.merge_details.h_contract_terms),
+ GNUNET_JSON_spec_fixed_auto ("merge_pub",
+ &rh->details.merge_details.merge_pub),
+ GNUNET_JSON_spec_fixed_auto ("purse_pub",
+ &rh->details.merge_details.purse_pub),
+ GNUNET_JSON_spec_uint32 ("min_age",
+ &rh->details.merge_details.min_age),
+ GNUNET_JSON_spec_uint32 ("flags",
+ &flags32),
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rh->details.merge_details.reserve_sig),
+ TALER_JSON_spec_amount_any ("purse_fee",
+ &rh->details.merge_details.purse_fee),
+ GNUNET_JSON_spec_timestamp ("merge_timestamp",
+ &rh->details.merge_details.merge_timestamp),
+ GNUNET_JSON_spec_timestamp ("purse_expiration",
+ &rh->details.merge_details.purse_expiration),
+ GNUNET_JSON_spec_bool ("merged",
+ &rh->details.merge_details.merged),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_MERGE;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ merge_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ rh->details.merge_details.flags =
+ (enum TALER_WalletAccountMergeFlags) flags32;
+ if (GNUNET_OK !=
+ TALER_wallet_account_merge_verify (
+ rh->details.merge_details.merge_timestamp,
+ &rh->details.merge_details.purse_pub,
+ rh->details.merge_details.purse_expiration,
+ &rh->details.merge_details.h_contract_terms,
+ &rh->amount,
+ &rh->details.merge_details.purse_fee,
+ rh->details.merge_details.min_age,
+ rh->details.merge_details.flags,
+ uc->reserve_pub,
+ &rh->details.merge_details.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (rh->details.merge_details.merged)
+ {
+ if (0 >
+ TALER_amount_add (uc->total_in,
+ uc->total_in,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ else
+ {
+ if (0 >
+ TALER_amount_add (uc->total_out,
+ uc->total_out,
+ &rh->details.merge_details.purse_fee))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "open" reserve open entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_open (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ struct GNUNET_JSON_Specification open_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rh->details.open_request.reserve_sig),
+ TALER_JSON_spec_amount_any ("open_payment",
+ &rh->details.open_request.reserve_payment),
+ GNUNET_JSON_spec_uint32 ("requested_min_purses",
+ &rh->details.open_request.purse_limit),
+ GNUNET_JSON_spec_timestamp ("request_timestamp",
+ &rh->details.open_request.request_timestamp),
+ GNUNET_JSON_spec_timestamp ("requested_expiration",
+ &rh->details.open_request.reserve_expiration),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_OPEN;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ open_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_open_verify (
+ &rh->amount,
+ rh->details.open_request.request_timestamp,
+ rh->details.open_request.reserve_expiration,
+ rh->details.open_request.purse_limit,
+ uc->reserve_pub,
+ &rh->details.open_request.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (0 >
+ TALER_amount_add (uc->total_out,
+ uc->total_out,
+ &rh->amount))
+ {
+ /* overflow in history already!? inconceivable! Bad exchange! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Parse "close" reserve close entry.
+ *
+ * @param[in,out] rh entry to parse
+ * @param uc our context
+ * @param transaction the transaction to parse
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+parse_close (struct TALER_EXCHANGE_ReserveHistoryEntry *rh,
+ struct HistoryParseContext *uc,
+ const json_t *transaction)
+{
+ struct GNUNET_JSON_Specification close_spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("reserve_sig",
+ &rh->details.close_request.reserve_sig),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_fixed_auto ("h_payto",
+ &rh->details.close_request.
+ target_account_h_payto),
+ NULL),
+ GNUNET_JSON_spec_timestamp ("request_timestamp",
+ &rh->details.close_request.request_timestamp),
+ GNUNET_JSON_spec_end ()
+ };
+
+ rh->type = TALER_EXCHANGE_RTT_CLOSE;
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ close_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ /* force amount to invalid */
+ memset (&rh->amount,
+ 0,
+ sizeof (rh->amount));
+ if (GNUNET_OK !=
+ TALER_wallet_reserve_close_verify (
+ rh->details.close_request.request_timestamp,
+ &rh->details.close_request.target_account_h_payto,
+ uc->reserve_pub,
+ &rh->details.close_request.reserve_sig))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+static void
+free_reserve_history (
+ unsigned int len,
+ struct TALER_EXCHANGE_ReserveHistoryEntry rhistory[static len])
+{
+ for (unsigned int i = 0; i<len; i++)
+ {
+ switch (rhistory[i].type)
+ {
+ case TALER_EXCHANGE_RTT_CREDIT:
+ GNUNET_free (rhistory[i].details.in_details.sender_url);
+ break;
+ case TALER_EXCHANGE_RTT_WITHDRAWAL:
+ break;
+ case TALER_EXCHANGE_RTT_AGEWITHDRAWAL:
+ break;
+ case TALER_EXCHANGE_RTT_RECOUP:
+ break;
+ case TALER_EXCHANGE_RTT_CLOSING:
+ break;
+ case TALER_EXCHANGE_RTT_MERGE:
+ break;
+ case TALER_EXCHANGE_RTT_OPEN:
+ break;
+ case TALER_EXCHANGE_RTT_CLOSE:
+ break;
+ }
+ }
+ GNUNET_free (rhistory);
+}
+
+
+/**
+ * Parse history given in JSON format and return it in binary
+ * format.
+ *
+ * @param keys exchange keys
+ * @param history JSON array with the history
+ * @param reserve_pub public key of the reserve to inspect
+ * @param currency currency we expect the balance to be in
+ * @param[out] total_in set to value of credits to reserve
+ * @param[out] total_out set to value of debits from reserve
+ * @param history_length number of entries in @a history
+ * @param[out] rhistory array of length @a history_length, set to the
+ * parsed history entries
+ * @return #GNUNET_OK if history was valid and @a rhistory and @a balance
+ * were set,
+ * #GNUNET_SYSERR if there was a protocol violation in @a history
+ */
+static enum GNUNET_GenericReturnValue
+parse_reserve_history (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const json_t *history,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const char *currency,
+ struct TALER_Amount *total_in,
+ struct TALER_Amount *total_out,
+ unsigned int history_length,
+ struct TALER_EXCHANGE_ReserveHistoryEntry rhistory[static history_length])
+{
+ const struct
+ {
+ const char *type;
+ ParseHelper helper;
+ } map[] = {
+ { "CREDIT", &parse_credit },
+ { "WITHDRAW", &parse_withdraw },
+ { "RECOUP", &parse_recoup },
+ { "MERGE", &parse_merge },
+ { "CLOSING", &parse_closing },
+ { "OPEN", &parse_open },
+ { "CLOSE", &parse_close },
+ { NULL, NULL }
+ };
+ struct GNUNET_HashCode uuid[history_length];
+ struct HistoryParseContext uc = {
+ .keys = keys,
+ .reserve_pub = reserve_pub,
+ .uuids = uuid,
+ .total_in = total_in,
+ .total_out = total_out
+ };
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ total_in));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ total_out));
+ for (unsigned int off = 0; off<history_length; off++)
+ {
+ struct TALER_EXCHANGE_ReserveHistoryEntry *rh = &rhistory[off];
+ json_t *transaction;
+ struct TALER_Amount amount;
+ const char *type;
+ struct GNUNET_JSON_Specification hist_spec[] = {
+ GNUNET_JSON_spec_string ("type",
+ &type),
+ TALER_JSON_spec_amount_any ("amount",
+ &amount),
+ /* 'wire' and 'signature' are optional depending on 'type'! */
+ GNUNET_JSON_spec_end ()
+ };
+ bool found = false;
+
+ transaction = json_array_get (history,
+ off);
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (transaction,
+ hist_spec,
+ NULL, NULL))
+ {
+ GNUNET_break_op (0);
+ json_dumpf (transaction,
+ stderr,
+ JSON_INDENT (2));
+ return GNUNET_SYSERR;
+ }
+ rh->amount = amount;
+ if (GNUNET_YES !=
+ TALER_amount_cmp_currency (&amount,
+ total_in))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ for (unsigned int i = 0; NULL != map[i].type; i++)
+ {
+ if (0 == strcasecmp (map[i].type,
+ type))
+ {
+ found = true;
+ if (GNUNET_OK !=
+ map[i].helper (rh,
+ &uc,
+ transaction))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ break;
+ }
+ }
+ if (! found)
+ {
+ /* unexpected 'type', protocol incompatibility, complain! */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle HTTP header received by curl.
+ *
+ * @param buffer one line of HTTP header data
+ * @param size size of an item
+ * @param nitems number of items passed
+ * @param userdata our `struct TALER_EXCHANGE_ReservesHistoryHandle *`
+ * @return `size * nitems`
+ */
+static size_t
+handle_header (char *buffer,
+ size_t size,
+ size_t nitems,
+ void *userdata)
+{
+ struct TALER_EXCHANGE_ReservesHistoryHandle *rhh = userdata;
+ size_t total = size * nitems;
+ char *ndup;
+ const char *hdr_type;
+ char *hdr_val;
+ char *sp;
+
+ ndup = GNUNET_strndup (buffer,
+ total);
+ hdr_type = strtok_r (ndup,
+ ":",
+ &sp);
+ if (NULL == hdr_type)
+ {
+ GNUNET_free (ndup);
+ return total;
+ }
+ hdr_val = strtok_r (NULL,
+ "\n\r",
+ &sp);
+ if (NULL == hdr_val)
+ {
+ GNUNET_free (ndup);
+ return total;
+ }
+ if (' ' == *hdr_val)
+ hdr_val++;
+ if (0 == strcasecmp (hdr_type,
+ MHD_HTTP_HEADER_ETAG))
+ {
+ unsigned long long tval;
+ char dummy;
+
+ if (1 !=
+ sscanf (hdr_val,
+ "\"%llu\"%c",
+ &tval,
+ &dummy))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (ndup);
+ return 0;
+ }
+ rhh->etag = (uint64_t) tval;
+ }
+ GNUNET_free (ndup);
+ return total;
+}
+
+
+/**
* We received an #MHD_HTTP_OK history code. Handle the JSON
* response.
*
@@ -99,19 +878,18 @@ static enum GNUNET_GenericReturnValue
handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh,
const json_t *j)
{
- json_t *history;
+ const json_t *history;
unsigned int len;
struct TALER_EXCHANGE_ReserveHistory rs = {
.hr.reply = j,
.hr.http_status = MHD_HTTP_OK,
- .ts = rsh->ts,
- .reserve_sig = &rsh->reserve_sig
+ .details.ok.etag = rsh->etag
};
struct GNUNET_JSON_Specification spec[] = {
TALER_JSON_spec_amount_any ("balance",
&rs.details.ok.balance),
- GNUNET_JSON_spec_json ("history",
- &history),
+ GNUNET_JSON_spec_array_const ("history",
+ &history),
GNUNET_JSON_spec_end ()
};
@@ -131,18 +909,18 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh,
rhistory = GNUNET_new_array (len,
struct TALER_EXCHANGE_ReserveHistoryEntry);
if (GNUNET_OK !=
- TALER_EXCHANGE_parse_reserve_history (rsh->exchange,
- history,
- &rsh->reserve_pub,
- rs.details.ok.balance.currency,
- &rs.details.ok.total_in,
- &rs.details.ok.total_out,
- len,
- rhistory))
+ parse_reserve_history (rsh->keys,
+ history,
+ &rsh->reserve_pub,
+ rs.details.ok.balance.currency,
+ &rs.details.ok.total_in,
+ &rs.details.ok.total_out,
+ len,
+ rhistory))
{
GNUNET_break_op (0);
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
+ free_reserve_history (len,
+ rhistory);
GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
@@ -154,10 +932,9 @@ handle_reserves_history_ok (struct TALER_EXCHANGE_ReservesHistoryHandle *rsh,
&rs);
rsh->cb = NULL;
}
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
+ free_reserve_history (len,
+ rhistory);
}
- GNUNET_JSON_parse_free (spec);
return GNUNET_OK;
}
@@ -193,7 +970,6 @@ handle_reserves_history_finished (void *cls,
handle_reserves_history_ok (rsh,
j))
{
- GNUNET_break_op (0);
rs.hr.http_status = 0;
rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
}
@@ -218,11 +994,6 @@ handle_reserves_history_finished (void *cls,
rs.hr.ec = TALER_JSON_get_error_code (j);
rs.hr.hint = TALER_JSON_get_error_hint (j);
break;
- case MHD_HTTP_CONFLICT:
- /* Insufficient balance to inquire for reserve history */
- rs.hr.ec = TALER_JSON_get_error_code (j);
- rs.hr.hint = TALER_JSON_get_error_hint (j);
- break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
@@ -252,29 +1023,22 @@ handle_reserves_history_finished (void *cls,
struct TALER_EXCHANGE_ReservesHistoryHandle *
TALER_EXCHANGE_reserves_history (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_ReservePrivateKeyP *reserve_priv,
+ uint64_t start_off,
TALER_EXCHANGE_ReservesHistoryCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_ReservesHistoryHandle *rsh;
- struct GNUNET_CURL_Context *ctx;
CURL *eh;
- char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
- const struct TALER_EXCHANGE_Keys *keys;
- const struct TALER_EXCHANGE_GlobalFee *gf;
+ char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 64];
+ struct curl_slist *job_headers;
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
rsh = GNUNET_new (struct TALER_EXCHANGE_ReservesHistoryHandle);
- rsh->exchange = exchange;
rsh->cb = cb;
rsh->cb_cls = cb_cls;
- rsh->ts = GNUNET_TIME_timestamp_get ();
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
&rsh->reserve_pub.eddsa_pub);
{
@@ -287,13 +1051,21 @@ TALER_EXCHANGE_reserves_history (
pub_str,
sizeof (pub_str));
*end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "/reserves/%s/history",
- pub_str);
+ if (0 != start_off)
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves/%s/history?start=%llu",
+ pub_str,
+ (unsigned long long) start_off);
+ else
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves/%s/history",
+ pub_str);
}
- rsh->url = TEAH_path_to_url (exchange,
- arg_str);
+ rsh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == rsh->url)
{
GNUNET_free (rsh);
@@ -307,56 +1079,49 @@ TALER_EXCHANGE_reserves_history (
GNUNET_free (rsh);
return NULL;
}
- keys = TALER_EXCHANGE_get_keys (exchange);
- if (NULL == keys)
- {
- GNUNET_break (0);
- curl_easy_cleanup (eh);
- GNUNET_free (rsh->url);
- GNUNET_free (rsh);
- return NULL;
- }
- gf = TALER_EXCHANGE_get_global_fee (keys,
- rsh->ts);
- if (NULL == gf)
- {
- GNUNET_break_op (0);
- curl_easy_cleanup (eh);
- GNUNET_free (rsh->url);
- GNUNET_free (rsh);
- return NULL;
- }
- TALER_wallet_reserve_history_sign (rsh->ts,
- &gf->fees.history,
- reserve_priv,
- &rsh->reserve_sig);
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_HEADERFUNCTION,
+ &handle_header));
+ GNUNET_assert (CURLE_OK ==
+ curl_easy_setopt (eh,
+ CURLOPT_HEADERDATA,
+ rsh));
{
- json_t *history_obj = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_timestamp ("request_timestamp",
- rsh->ts),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &rsh->reserve_sig));
+ struct TALER_ReserveSignatureP reserve_sig;
+ char *sig_hdr;
+ char *hdr;
- if (GNUNET_OK !=
- TALER_curl_easy_post (&rsh->post_ctx,
- eh,
- history_obj))
+ TALER_wallet_reserve_history_sign (start_off,
+ reserve_priv,
+ &reserve_sig);
+
+ sig_hdr = GNUNET_STRINGS_data_to_string_alloc (
+ &reserve_sig,
+ sizeof (reserve_sig));
+ GNUNET_asprintf (&hdr,
+ "%s: %s",
+ TALER_RESERVE_HISTORY_SIGNATURE_HEADER,
+ sig_hdr);
+ GNUNET_free (sig_hdr);
+ job_headers = curl_slist_append (NULL,
+ hdr);
+ GNUNET_free (hdr);
+ if (NULL == job_headers)
{
GNUNET_break (0);
curl_easy_cleanup (eh);
- json_decref (history_obj);
- GNUNET_free (rsh->url);
- GNUNET_free (rsh);
return NULL;
}
- json_decref (history_obj);
}
- ctx = TEAH_handle_to_context (exchange);
+
+ rsh->keys = TALER_EXCHANGE_keys_incref (keys);
rsh->job = GNUNET_CURL_job_add2 (ctx,
eh,
- rsh->post_ctx.headers,
+ job_headers,
&handle_reserves_history_finished,
rsh);
+ curl_slist_free_all (job_headers);
return rsh;
}
@@ -372,6 +1137,7 @@ TALER_EXCHANGE_reserves_history_cancel (
}
TALER_curl_easy_post_finished (&rsh->post_ctx);
GNUNET_free (rsh->url);
+ TALER_EXCHANGE_keys_decref (rsh->keys);
GNUNET_free (rsh);
}
diff --git a/src/lib/exchange_api_reserves_open.c b/src/lib/exchange_api_reserves_open.c
new file mode 100644
index 000000000..36e435685
--- /dev/null
+++ b/src/lib/exchange_api_reserves_open.c
@@ -0,0 +1,567 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_reserves_open.c
+ * @brief Implementation of the POST /reserves/$RESERVE_PUB/open requests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <jansson.h>
+#include <microhttpd.h> /* just for HTTP open codes */
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include "exchange_api_common.h"
+#include "exchange_api_handle.h"
+#include "taler_signatures.h"
+#include "exchange_api_curl_defaults.h"
+
+
+/**
+ * Information we keep per coin to validate the reply.
+ */
+struct CoinData
+{
+ /**
+ * Public key of the coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
+ * Signature by the coin.
+ */
+ struct TALER_CoinSpendSignatureP coin_sig;
+
+ /**
+ * The hash of the denomination's public key
+ */
+ struct TALER_DenominationHashP h_denom_pub;
+
+ /**
+ * How much did this coin contribute.
+ */
+ struct TALER_Amount contribution;
+};
+
+
+/**
+ * @brief A /reserves/$RID/open Handle
+ */
+struct TALER_EXCHANGE_ReservesOpenHandle
+{
+
+ /**
+ * The keys of the exchange this request handle will use
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * The url for this request.
+ */
+ char *url;
+
+ /**
+ * Handle for the request.
+ */
+ struct GNUNET_CURL_Job *job;
+
+ /**
+ * Context for #TEH_curl_easy_post(). Keeps the data that must
+ * persist for Curl to make the upload.
+ */
+ struct TALER_CURL_PostContext post_ctx;
+
+ /**
+ * Function to call with the result.
+ */
+ TALER_EXCHANGE_ReservesOpenCallback cb;
+
+ /**
+ * Closure for @a cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Information we keep per coin to validate the reply.
+ */
+ struct CoinData *coins;
+
+ /**
+ * Length of the @e coins array.
+ */
+ unsigned int num_coins;
+
+ /**
+ * Public key of the reserve we are querying.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Our signature.
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * When did we make the request.
+ */
+ struct GNUNET_TIME_Timestamp ts;
+
+};
+
+
+/**
+ * We received an #MHD_HTTP_OK open code. Handle the JSON
+ * response.
+ *
+ * @param roh handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_open_ok (struct TALER_EXCHANGE_ReservesOpenHandle *roh,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveOpenResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_OK,
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("open_cost",
+ &rs.details.ok.open_cost),
+ GNUNET_JSON_spec_timestamp ("reserve_expiration",
+ &rs.details.ok.expiration_time),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ roh->cb (roh->cb_cls,
+ &rs);
+ roh->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * We received an #MHD_HTTP_PAYMENT_REQUIRED open code. Handle the JSON
+ * response.
+ *
+ * @param roh handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_open_pr (struct TALER_EXCHANGE_ReservesOpenHandle *roh,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveOpenResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_PAYMENT_REQUIRED,
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ TALER_JSON_spec_amount_any ("open_cost",
+ &rs.details.payment_required.open_cost),
+ GNUNET_JSON_spec_timestamp ("reserve_expiration",
+ &rs.details.payment_required.expiration_time),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ roh->cb (roh->cb_cls,
+ &rs);
+ roh->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * We received an #MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS open code. Handle the JSON
+ * response.
+ *
+ * @param roh handle of the request
+ * @param j JSON response
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_reserves_open_kyc (struct TALER_EXCHANGE_ReservesOpenHandle *roh,
+ const json_t *j)
+{
+ struct TALER_EXCHANGE_ReserveOpenResult rs = {
+ .hr.reply = j,
+ .hr.http_status = MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ };
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto (
+ "h_payto",
+ &rs.details.unavailable_for_legal_reasons.h_payto),
+ GNUNET_JSON_spec_uint64 (
+ "requirement_row",
+ &rs.details.unavailable_for_legal_reasons.requirement_row),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ roh->cb (roh->cb_cls,
+ &rs);
+ roh->cb = NULL;
+ GNUNET_JSON_parse_free (spec);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called when we're done processing the
+ * HTTP /reserves/$RID/open request.
+ *
+ * @param cls the `struct TALER_EXCHANGE_ReservesOpenHandle`
+ * @param response_code HTTP response code, 0 on error
+ * @param response parsed JSON result, NULL on error
+ */
+static void
+handle_reserves_open_finished (void *cls,
+ long response_code,
+ const void *response)
+{
+ struct TALER_EXCHANGE_ReservesOpenHandle *roh = cls;
+ const json_t *j = response;
+ struct TALER_EXCHANGE_ReserveOpenResult rs = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
+ };
+
+ roh->job = NULL;
+ switch (response_code)
+ {
+ case 0:
+ rs.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ break;
+ case MHD_HTTP_OK:
+ if (GNUNET_OK !=
+ handle_reserves_open_ok (roh,
+ j))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_BAD_REQUEST:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ json_dumpf (j,
+ stderr,
+ JSON_INDENT (2));
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_PAYMENT_REQUIRED:
+ if (GNUNET_OK !=
+ handle_reserves_open_pr (roh,
+ j))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ /* This should never happen, either us or the exchange is buggy
+ (or API version conflict); just pass JSON reply to the application */
+ GNUNET_break (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ /* Nothing really to verify, this should never
+ happen, we should pass the JSON reply to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ case MHD_HTTP_CONFLICT:
+ {
+ const struct CoinData *cd = NULL;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_fixed_auto ("coin_pub",
+ &rs.details.conflict.coin_pub),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (j,
+ spec,
+ NULL,
+ NULL))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ for (unsigned int i = 0; i<roh->num_coins; i++)
+ {
+ const struct CoinData *cdi = &roh->coins[i];
+
+ if (0 == GNUNET_memcmp (&rs.details.conflict.coin_pub,
+ &cdi->coin_pub))
+ {
+ cd = cdi;
+ break;
+ }
+ }
+ if (NULL == cd)
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ break;
+ }
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ }
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ if (GNUNET_OK !=
+ handle_reserves_open_kyc (roh,
+ j))
+ {
+ GNUNET_break_op (0);
+ rs.hr.http_status = 0;
+ rs.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ }
+ break;
+ case MHD_HTTP_INTERNAL_SERVER_ERROR:
+ /* Server had an internal issue; we should retry, but this API
+ leaves this to the application */
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ break;
+ default:
+ /* unexpected response code */
+ GNUNET_break_op (0);
+ rs.hr.ec = TALER_JSON_get_error_code (j);
+ rs.hr.hint = TALER_JSON_get_error_hint (j);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected response code %u/%d for reserves open\n",
+ (unsigned int) response_code,
+ (int) rs.hr.ec);
+ break;
+ }
+ if (NULL != roh->cb)
+ {
+ roh->cb (roh->cb_cls,
+ &rs);
+ roh->cb = NULL;
+ }
+ TALER_EXCHANGE_reserves_open_cancel (roh);
+}
+
+
+struct TALER_EXCHANGE_ReservesOpenHandle *
+TALER_EXCHANGE_reserves_open (
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *reserve_contribution,
+ unsigned int coin_payments_length,
+ const struct TALER_EXCHANGE_PurseDeposit coin_payments[
+ static coin_payments_length],
+ struct GNUNET_TIME_Timestamp expiration_time,
+ uint32_t min_purses,
+ TALER_EXCHANGE_ReservesOpenCallback cb,
+ void *cb_cls)
+{
+ struct TALER_EXCHANGE_ReservesOpenHandle *roh;
+ CURL *eh;
+ char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
+ json_t *cpa;
+
+ roh = GNUNET_new (struct TALER_EXCHANGE_ReservesOpenHandle);
+ roh->cb = cb;
+ roh->cb_cls = cb_cls;
+ roh->ts = GNUNET_TIME_timestamp_get ();
+ GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
+ &roh->reserve_pub.eddsa_pub);
+ {
+ char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
+ char *end;
+
+ end = GNUNET_STRINGS_data_to_string (
+ &roh->reserve_pub,
+ sizeof (roh->reserve_pub),
+ pub_str,
+ sizeof (pub_str));
+ *end = '\0';
+ GNUNET_snprintf (arg_str,
+ sizeof (arg_str),
+ "reserves/%s/open",
+ pub_str);
+ }
+ roh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
+ if (NULL == roh->url)
+ {
+ GNUNET_free (roh);
+ return NULL;
+ }
+ eh = TALER_EXCHANGE_curl_easy_get_ (roh->url);
+ if (NULL == eh)
+ {
+ GNUNET_break (0);
+ GNUNET_free (roh->url);
+ GNUNET_free (roh);
+ return NULL;
+ }
+ TALER_wallet_reserve_open_sign (reserve_contribution,
+ roh->ts,
+ expiration_time,
+ min_purses,
+ reserve_priv,
+ &roh->reserve_sig);
+ roh->coins = GNUNET_new_array (coin_payments_length,
+ struct CoinData);
+ cpa = json_array ();
+ GNUNET_assert (NULL != cpa);
+ for (unsigned int i = 0; i<coin_payments_length; i++)
+ {
+ const struct TALER_EXCHANGE_PurseDeposit *pd = &coin_payments[i];
+ const struct TALER_AgeCommitmentProof *acp = pd->age_commitment_proof;
+ struct TALER_AgeCommitmentHash ahac;
+ struct TALER_AgeCommitmentHash *achp = NULL;
+ struct CoinData *cd = &roh->coins[i];
+ json_t *cp;
+
+ cd->contribution = pd->amount;
+ cd->h_denom_pub = pd->h_denom_pub;
+ if (NULL != acp)
+ {
+ TALER_age_commitment_hash (&acp->commitment,
+ &ahac);
+ achp = &ahac;
+ }
+ TALER_wallet_reserve_open_deposit_sign (&pd->amount,
+ &roh->reserve_sig,
+ &pd->coin_priv,
+ &cd->coin_sig);
+ GNUNET_CRYPTO_eddsa_key_get_public (&pd->coin_priv.eddsa_priv,
+ &cd->coin_pub.eddsa_pub);
+
+ cp = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_auto ("h_age_commitment",
+ achp)),
+ TALER_JSON_pack_amount ("amount",
+ &pd->amount),
+ GNUNET_JSON_pack_data_auto ("denom_pub_hash",
+ &pd->h_denom_pub),
+ TALER_JSON_pack_denom_sig ("ub_sig",
+ &pd->denom_sig),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cd->coin_pub),
+ GNUNET_JSON_pack_data_auto ("coin_sig",
+ &cd->coin_sig));
+ GNUNET_assert (0 ==
+ json_array_append_new (cpa,
+ cp));
+ }
+ {
+ json_t *open_obj = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_timestamp ("request_timestamp",
+ roh->ts),
+ GNUNET_JSON_pack_timestamp ("reserve_expiration",
+ expiration_time),
+ GNUNET_JSON_pack_array_steal ("payments",
+ cpa),
+ TALER_JSON_pack_amount ("reserve_payment",
+ reserve_contribution),
+ GNUNET_JSON_pack_uint64 ("purse_limit",
+ min_purses),
+ GNUNET_JSON_pack_data_auto ("reserve_sig",
+ &roh->reserve_sig));
+
+ if (GNUNET_OK !=
+ TALER_curl_easy_post (&roh->post_ctx,
+ eh,
+ open_obj))
+ {
+ GNUNET_break (0);
+ curl_easy_cleanup (eh);
+ json_decref (open_obj);
+ GNUNET_free (roh->coins);
+ GNUNET_free (roh->url);
+ GNUNET_free (roh);
+ return NULL;
+ }
+ json_decref (open_obj);
+ }
+ roh->keys = TALER_EXCHANGE_keys_incref (keys);
+ roh->job = GNUNET_CURL_job_add2 (ctx,
+ eh,
+ roh->post_ctx.headers,
+ &handle_reserves_open_finished,
+ roh);
+ return roh;
+}
+
+
+void
+TALER_EXCHANGE_reserves_open_cancel (
+ struct TALER_EXCHANGE_ReservesOpenHandle *roh)
+{
+ if (NULL != roh->job)
+ {
+ GNUNET_CURL_job_cancel (roh->job);
+ roh->job = NULL;
+ }
+ TALER_curl_easy_post_finished (&roh->post_ctx);
+ GNUNET_free (roh->coins);
+ GNUNET_free (roh->url);
+ TALER_EXCHANGE_keys_decref (roh->keys);
+ GNUNET_free (roh);
+}
+
+
+/* end of exchange_api_reserves_open.c */
diff --git a/src/lib/exchange_api_stefan.c b/src/lib/exchange_api_stefan.c
new file mode 100644
index 000000000..226bca82f
--- /dev/null
+++ b/src/lib/exchange_api_stefan.c
@@ -0,0 +1,328 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/exchange_api_stefan.c
+ * @brief calculations on the STEFAN curve
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_handle.h"
+#include <math.h>
+
+
+/**
+ * Determine smallest denomination in @a keys.
+ *
+ * @param keys exchange response to evaluate
+ * @return NULL on error (no denominations)
+ */
+static const struct TALER_Amount *
+get_unit (const struct TALER_EXCHANGE_Keys *keys)
+{
+ const struct TALER_Amount *min = NULL;
+
+ for (unsigned int i = 0; i<keys->num_denom_keys; i++)
+ {
+ const struct TALER_EXCHANGE_DenomPublicKey *dk
+ = &keys->denom_keys[i];
+
+ if ( (NULL == min) ||
+ (1 == TALER_amount_cmp (min,
+ /* > */
+ &dk->value)) )
+ min = &dk->value;
+ }
+ GNUNET_break (NULL != min);
+ return min;
+}
+
+
+/**
+ * Convert amount to double for STEFAN curve evaluation.
+ *
+ * @param a input amount
+ * @return (rounded) amount as a double
+ */
+static double
+amount_to_double (const struct TALER_Amount *a)
+{
+ double d = (double) a->value;
+
+ d += a->fraction / ((double) TALER_AMOUNT_FRAC_BASE);
+ return d;
+}
+
+
+/**
+ * Convert double to amount for STEFAN curve evaluation.
+ *
+ * @param dv input amount
+ * @param currency deisred currency
+ * @param[out] rval (rounded) amount as a double
+ */
+static void
+double_to_amount (double dv,
+ const char *currency,
+ struct TALER_Amount *rval)
+{
+ double rem;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (currency,
+ rval));
+ rval->value = floorl (dv);
+ rem = dv - ((double) rval->value);
+ if (rem < 0.0)
+ rem = 0.0;
+ rem *= TALER_AMOUNT_FRAC_BASE;
+ rval->fraction = floorl (rem);
+ if (rval->fraction >= TALER_AMOUNT_FRAC_BASE)
+ {
+ /* Strange, multiplication overflowed our range,
+ round up value instead */
+ rval->fraction = 0;
+ rval->value += 1;
+ }
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_keys_stefan_b2n (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *brut,
+ struct TALER_Amount *net)
+{
+ const struct TALER_Amount *min;
+ double log_d = amount_to_double (&keys->stefan_log);
+ double lin_d = keys->stefan_lin;
+ double abs_d = amount_to_double (&keys->stefan_abs);
+ double bru_d = amount_to_double (brut);
+ double min_d;
+ double fee_d;
+ double net_d;
+
+ if (TALER_amount_is_zero (brut))
+ {
+ *net = *brut;
+ return GNUNET_NO;
+ }
+ min = get_unit (keys);
+ if (NULL == min)
+ return GNUNET_SYSERR;
+ if (1.0f <= keys->stefan_lin)
+ {
+ /* This cannot work, linear STEFAN fee estimate always
+ exceed any gross amount. */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ min_d = amount_to_double (min);
+ fee_d = abs_d
+ + log_d * log2 (bru_d / min_d)
+ + lin_d * bru_d;
+ if (fee_d > bru_d)
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (brut->currency,
+ net));
+ return GNUNET_NO;
+ }
+ net_d = bru_d - fee_d;
+ double_to_amount (net_d,
+ brut->currency,
+ net);
+ return GNUNET_OK;
+}
+
+
+/**
+ * Our function
+ * f(x) := ne + ab + lo * log2(x/mi) + li * x - x
+ * for #newton().
+ */
+static double
+eval_f (double mi,
+ double ab,
+ double lo,
+ double li,
+ double ne,
+ double x)
+{
+ return ne + ab + lo * log2 (x / mi) + li * x - x;
+}
+
+
+/**
+ * Our function
+ * f'(x) := lo / log(2) / x + li - 1
+ * for #newton().
+ */
+static double
+eval_fp (double mi,
+ double lo,
+ double li,
+ double ne,
+ double x)
+{
+ return lo / log (2) / x + li - 1;
+}
+
+
+/**
+ * Use Newton's method to find x where f(x)=0.
+ *
+ * @return x where "eval_f(x)==0".
+ */
+static double
+newton (double mi,
+ double ab,
+ double lo,
+ double li,
+ double ne)
+{
+ const double eps = 0.00000001; /* max error allowed */
+ double min_ab = ne + ab; /* result cannot be smaller than this! */
+ /* compute lower bounds by various heuristics */
+ double min_ab_li = min_ab + min_ab * li;
+ double min_ab_li_lo = min_ab_li + log2 (min_ab_li / mi) * lo;
+ double min_ab_lo = min_ab + log2 (min_ab / mi) * lo;
+ double min_ab_lo_li = min_ab_lo + min_ab_lo * li;
+ /* take global lower bound */
+ double x_min = GNUNET_MAX (min_ab_lo_li,
+ min_ab_li_lo);
+ double x = x_min; /* use lower bound as starting point */
+
+ /* Objective: invert
+ ne := br - ab - lo * log2 (br/mi) - li * br
+ to find 'br'.
+ Method: use Newton's method to find root of:
+ f(x) := ne + ab + lo * log2 (x/mi) + li * x - x
+ using also
+ f'(x) := lo / log(2) / x + li - 1
+ */
+ /* Loop to abort in case of divergence;
+ 100 is already very high, 2-4 is normal! */
+ for (unsigned int i = 0; i<100; i++)
+ {
+ double fx = eval_f (mi, ab, lo, li, ne, x);
+ double fxp = eval_fp (mi, lo, li, ne, x);
+ double x_new = x - fx / fxp;
+
+ if (fabs (x - x_new) <= eps)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Needed %u rounds from %f to result BRUT %f => NET: %f\n",
+ i,
+ x_min,
+ x_new,
+ x_new - ab - li * x_new - lo * log2 (x / mi));
+ return x_new;
+ }
+ if (x_new < x_min)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Divergence, obtained very bad estimate %f after %u rounds!\n",
+ x_new,
+ i);
+ return x_min;
+ }
+ x = x_new;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Slow convergence, returning bad estimate %f!\n",
+ x);
+ return x;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_EXCHANGE_keys_stefan_n2b (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *net,
+ struct TALER_Amount *brut)
+{
+ const struct TALER_Amount *min;
+ double lin_d = keys->stefan_lin;
+ double log_d = amount_to_double (&keys->stefan_log);
+ double abs_d = amount_to_double (&keys->stefan_abs);
+ double net_d = amount_to_double (net);
+ double min_d;
+ double brut_d;
+
+ if (TALER_amount_is_zero (net))
+ {
+ *brut = *net;
+ return GNUNET_NO;
+ }
+ min = get_unit (keys);
+ if (NULL == min)
+ return GNUNET_SYSERR;
+ if (1.0f <= keys->stefan_lin)
+ {
+ /* This cannot work, linear STEFAN fee estimate always
+ exceed any gross amount. */
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ min_d = amount_to_double (min);
+ brut_d = newton (min_d,
+ abs_d,
+ log_d,
+ lin_d,
+ net_d);
+ double_to_amount (brut_d,
+ net->currency,
+ brut);
+ return GNUNET_OK;
+}
+
+
+void
+TALER_EXCHANGE_keys_stefan_round (
+ const struct TALER_EXCHANGE_Keys *keys,
+ struct TALER_Amount *val)
+{
+ const struct TALER_Amount *min;
+ uint32_t mod;
+ uint32_t frac;
+ uint32_t lim;
+
+ if (0 == val->fraction)
+ {
+ /* rounding of non-fractions not supported */
+ return;
+ }
+ min = get_unit (keys);
+ if (NULL == min)
+ return;
+ if (0 == min->fraction)
+ {
+ frac = TALER_AMOUNT_FRAC_BASE;
+ }
+ else
+ {
+ frac = min->fraction;
+ }
+ lim = frac / 2;
+ mod = val->fraction % frac;
+ if (mod < lim)
+ val->fraction -= mod; /* round down */
+ else
+ val->fraction += frac - mod; /* round up */
+}
diff --git a/src/lib/exchange_api_transfers_get.c b/src/lib/exchange_api_transfers_get.c
index 06465618c..c558fb42e 100644
--- a/src/lib/exchange_api_transfers_get.c
+++ b/src/lib/exchange_api_transfers_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -38,9 +38,9 @@ struct TALER_EXCHANGE_TransfersGetHandle
{
/**
- * The connection to exchange this request handle will use
+ * The keys of the exchange this request handle will use
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_Keys *keys;
/**
* The url for this request.
@@ -84,25 +84,34 @@ check_transfers_get_response_ok (
struct TALER_EXCHANGE_TransfersGetHandle *wdh,
const json_t *json)
{
- json_t *details_j;
- struct TALER_EXCHANGE_TransferData td;
+ const json_t *details_j;
struct TALER_Amount total_expected;
struct TALER_MerchantPublicKeyP merchant_pub;
+ struct TALER_EXCHANGE_TransfersGetResponse tgr = {
+ .hr.reply = json,
+ .hr.http_status = MHD_HTTP_OK
+ };
+ struct TALER_EXCHANGE_TransferData *td
+ = &tgr.details.ok.td;
struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("total", &td.total_amount),
- TALER_JSON_spec_amount_any ("wire_fee", &td.wire_fee),
- GNUNET_JSON_spec_fixed_auto ("merchant_pub", &merchant_pub),
- GNUNET_JSON_spec_fixed_auto ("h_payto", &td.h_payto),
- GNUNET_JSON_spec_timestamp ("execution_time", &td.execution_time),
- GNUNET_JSON_spec_json ("deposits", &details_j),
- GNUNET_JSON_spec_fixed_auto ("exchange_sig", &td.exchange_sig),
- GNUNET_JSON_spec_fixed_auto ("exchange_pub", &td.exchange_pub),
+ TALER_JSON_spec_amount_any ("total",
+ &td->total_amount),
+ TALER_JSON_spec_amount_any ("wire_fee",
+ &td->wire_fee),
+ GNUNET_JSON_spec_fixed_auto ("merchant_pub",
+ &merchant_pub),
+ GNUNET_JSON_spec_fixed_auto ("h_payto",
+ &td->h_payto),
+ GNUNET_JSON_spec_timestamp ("execution_time",
+ &td->execution_time),
+ GNUNET_JSON_spec_array_const ("deposits",
+ &details_j),
+ GNUNET_JSON_spec_fixed_auto ("exchange_sig",
+ &td->exchange_sig),
+ GNUNET_JSON_spec_fixed_auto ("exchange_pub",
+ &td->exchange_pub),
GNUNET_JSON_spec_end ()
};
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = json,
- .http_status = MHD_HTTP_OK
- };
if (GNUNET_OK !=
GNUNET_JSON_parse (json,
@@ -113,32 +122,30 @@ check_transfers_get_response_ok (
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- TALER_amount_set_zero (td.total_amount.currency,
+ TALER_amount_set_zero (td->total_amount.currency,
&total_expected))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
TALER_EXCHANGE_test_signing_key (
- TALER_EXCHANGE_get_keys (wdh->exchange),
- &td.exchange_pub))
+ wdh->keys,
+ &td->exchange_pub))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
return GNUNET_SYSERR;
}
- td.details_length = json_array_size (details_j);
+ td->details_length = json_array_size (details_j);
{
struct GNUNET_HashContext *hash_context;
struct TALER_TrackTransferDetails *details;
- details = GNUNET_new_array (td.details_length,
+ details = GNUNET_new_array (td->details_length,
struct TALER_TrackTransferDetails);
- td.details = details;
+ td->details = details;
hash_context = GNUNET_CRYPTO_hash_context_start ();
- for (unsigned int i = 0; i<td.details_length; i++)
+ for (unsigned int i = 0; i<td->details_length; i++)
{
struct TALER_TrackTransferDetails *detail = &details[i];
struct json_t *detail_j = json_array_get (details_j, i);
@@ -146,21 +153,27 @@ check_transfers_get_response_ok (
GNUNET_JSON_spec_fixed_auto ("h_contract_terms",
&detail->h_contract_terms),
GNUNET_JSON_spec_fixed_auto ("coin_pub", &detail->coin_pub),
- TALER_JSON_spec_amount_any ("deposit_value", &detail->coin_value),
- TALER_JSON_spec_amount_any ("deposit_fee", &detail->coin_fee),
+ TALER_JSON_spec_amount ("deposit_value",
+ total_expected.currency,
+ &detail->coin_value),
+ TALER_JSON_spec_amount ("deposit_fee",
+ total_expected.currency,
+ &detail->coin_fee),
+ GNUNET_JSON_spec_mark_optional (
+ TALER_JSON_spec_amount ("refund_total",
+ total_expected.currency,
+ &detail->refund_total),
+ NULL),
GNUNET_JSON_spec_end ()
};
+ GNUNET_assert (GNUNET_OK ==
+ TALER_amount_set_zero (td->total_amount.currency,
+ &detail->refund_total));
if ( (GNUNET_OK !=
GNUNET_JSON_parse (detail_j,
spec_detail,
NULL, NULL)) ||
- (GNUNET_OK !=
- TALER_amount_cmp_currency (&total_expected,
- &detail->coin_value)) ||
- (GNUNET_OK !=
- TALER_amount_cmp_currency (&total_expected,
- &detail->coin_fee)) ||
(0 >
TALER_amount_add (&total_expected,
&total_expected,
@@ -172,7 +185,6 @@ check_transfers_get_response_ok (
{
GNUNET_break_op (0);
GNUNET_CRYPTO_hash_context_abort (hash_context);
- GNUNET_JSON_parse_free (spec);
GNUNET_free (details);
return GNUNET_SYSERR;
}
@@ -180,7 +192,7 @@ check_transfers_get_response_ok (
TALER_exchange_online_wire_deposit_append (
hash_context,
&detail->h_contract_terms,
- td.execution_time,
+ td->execution_time,
&detail->coin_pub,
&detail->coin_value,
&detail->coin_fee);
@@ -193,16 +205,15 @@ check_transfers_get_response_ok (
&h_details);
if (GNUNET_OK !=
TALER_exchange_online_wire_deposit_verify (
- &td.total_amount,
- &td.wire_fee,
+ &td->total_amount,
+ &td->wire_fee,
&merchant_pub,
- &td.h_payto,
+ &td->h_payto,
&h_details,
- &td.exchange_pub,
- &td.exchange_sig))
+ &td->exchange_pub,
+ &td->exchange_sig))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
GNUNET_free (details);
return GNUNET_SYSERR;
}
@@ -211,29 +222,24 @@ check_transfers_get_response_ok (
if (0 >
TALER_amount_subtract (&total_expected,
&total_expected,
- &td.wire_fee))
+ &td->wire_fee))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
GNUNET_free (details);
return GNUNET_SYSERR;
}
if (0 !=
TALER_amount_cmp (&total_expected,
- &td.total_amount))
+ &td->total_amount))
{
GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
GNUNET_free (details);
return GNUNET_SYSERR;
}
wdh->cb (wdh->cb_cls,
- &hr,
- &td);
+ &tgr);
GNUNET_free (details);
}
- GNUNET_JSON_parse_free (spec);
- TALER_EXCHANGE_transfers_get_cancel (wdh);
return GNUNET_OK;
}
@@ -253,90 +259,85 @@ handle_transfers_get_finished (void *cls,
{
struct TALER_EXCHANGE_TransfersGetHandle *wdh = cls;
const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
+ struct TALER_EXCHANGE_TransfersGetResponse tgr = {
+ .hr.reply = j,
+ .hr.http_status = (unsigned int) response_code
};
wdh->job = NULL;
switch (response_code)
{
case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+ tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
break;
case MHD_HTTP_OK:
if (GNUNET_OK ==
check_transfers_get_response_ok (wdh,
j))
+ {
+ TALER_EXCHANGE_transfers_get_cancel (wdh);
return;
+ }
GNUNET_break_op (0);
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- hr.http_status = 0;
+ tgr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
+ tgr.hr.http_status = 0;
break;
case MHD_HTTP_BAD_REQUEST:
/* This should never happen, either us or the exchange is buggy
(or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ tgr.hr.ec = TALER_JSON_get_error_code (j);
+ tgr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_FORBIDDEN:
/* Nothing really to verify, exchange says one of the signatures is
invalid; as we checked them, this should never happen, we
should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ tgr.hr.ec = TALER_JSON_get_error_code (j);
+ tgr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_NOT_FOUND:
/* Exchange does not know about transaction;
we should pass the reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ tgr.hr.ec = TALER_JSON_get_error_code (j);
+ tgr.hr.hint = TALER_JSON_get_error_hint (j);
break;
case MHD_HTTP_INTERNAL_SERVER_ERROR:
/* Server had an internal issue; we should retry, but this API
leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ tgr.hr.ec = TALER_JSON_get_error_code (j);
+ tgr.hr.hint = TALER_JSON_get_error_hint (j);
break;
default:
/* unexpected response code */
GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
+ tgr.hr.ec = TALER_JSON_get_error_code (j);
+ tgr.hr.hint = TALER_JSON_get_error_hint (j);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u/%d for transfers get\n",
(unsigned int) response_code,
- (int) hr.ec);
+ (int) tgr.hr.ec);
break;
}
wdh->cb (wdh->cb_cls,
- &hr,
- NULL);
+ &tgr);
TALER_EXCHANGE_transfers_get_cancel (wdh);
}
struct TALER_EXCHANGE_TransfersGetHandle *
TALER_EXCHANGE_transfers_get (
- struct TALER_EXCHANGE_Handle *exchange,
+ struct GNUNET_CURL_Context *ctx,
+ const char *url,
+ struct TALER_EXCHANGE_Keys *keys,
const struct TALER_WireTransferIdentifierRawP *wtid,
TALER_EXCHANGE_TransfersGetCallback cb,
void *cb_cls)
{
struct TALER_EXCHANGE_TransfersGetHandle *wdh;
- struct GNUNET_CURL_Context *ctx;
CURL *eh;
char arg_str[sizeof (struct TALER_WireTransferIdentifierRawP) * 2 + 32];
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
-
wdh = GNUNET_new (struct TALER_EXCHANGE_TransfersGetHandle);
- wdh->exchange = exchange;
wdh->cb = cb;
wdh->cb_cls = cb_cls;
@@ -352,11 +353,12 @@ TALER_EXCHANGE_transfers_get (
*end = '\0';
GNUNET_snprintf (arg_str,
sizeof (arg_str),
- "/transfers/%s",
+ "transfers/%s",
wtid_str);
}
- wdh->url = TEAH_path_to_url (wdh->exchange,
- arg_str);
+ wdh->url = TALER_url_join (url,
+ arg_str,
+ NULL);
if (NULL == wdh->url)
{
GNUNET_free (wdh);
@@ -370,7 +372,7 @@ TALER_EXCHANGE_transfers_get (
GNUNET_free (wdh);
return NULL;
}
- ctx = TEAH_handle_to_context (exchange);
+ wdh->keys = TALER_EXCHANGE_keys_incref (keys);
wdh->job = GNUNET_CURL_job_add_with_ct_json (ctx,
eh,
&handle_transfers_get_finished,
@@ -395,6 +397,7 @@ TALER_EXCHANGE_transfers_get_cancel (
wdh->job = NULL;
}
GNUNET_free (wdh->url);
+ TALER_EXCHANGE_keys_decref (wdh->keys);
GNUNET_free (wdh);
}
diff --git a/src/lib/exchange_api_wire.c b/src/lib/exchange_api_wire.c
deleted file mode 100644
index 0390623fa..000000000
--- a/src/lib/exchange_api_wire.c
+++ /dev/null
@@ -1,489 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/exchange_api_wire.c
- * @brief Implementation of the /wire request of the exchange's HTTP API
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_exchange_service.h"
-#include "taler_json_lib.h"
-#include "taler_signatures.h"
-#include "exchange_api_handle.h"
-#include "exchange_api_curl_defaults.h"
-
-
-/**
- * @brief A Wire Handle
- */
-struct TALER_EXCHANGE_WireHandle
-{
-
- /**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_EXCHANGE_WireCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
-};
-
-
-/**
- * List of wire fees by method.
- */
-struct FeeMap
-{
- /**
- * Next entry in list.
- */
- struct FeeMap *next;
-
- /**
- * Wire method this fee structure is for.
- */
- char *method;
-
- /**
- * Array of wire fees, also linked list, but allocated
- * only once.
- */
- struct TALER_EXCHANGE_WireAggregateFees *fee_list;
-};
-
-
-/**
- * Frees @a fm.
- *
- * @param fm memory to release
- */
-static void
-free_fees (struct FeeMap *fm)
-{
- while (NULL != fm)
- {
- struct FeeMap *fe = fm->next;
-
- GNUNET_free (fm->fee_list);
- GNUNET_free (fm->method);
- GNUNET_free (fm);
- fm = fe;
- }
-}
-
-
-/**
- * Parse wire @a fees and return map.
- *
- * @param fees json AggregateTransferFee to parse
- * @return NULL on error
- */
-static struct FeeMap *
-parse_fees (json_t *fees)
-{
- struct FeeMap *fm = NULL;
- const char *key;
- json_t *fee_array;
-
- json_object_foreach (fees, key, fee_array) {
- struct FeeMap *fe = GNUNET_new (struct FeeMap);
- unsigned int len;
- unsigned int idx;
- json_t *fee;
-
- if (0 == (len = json_array_size (fee_array)))
- {
- GNUNET_free (fe);
- continue; /* skip */
- }
- fe->method = GNUNET_strdup (key);
- fe->next = fm;
- fe->fee_list = GNUNET_new_array (len,
- struct TALER_EXCHANGE_WireAggregateFees);
- fm = fe;
- json_array_foreach (fee_array, idx, fee)
- {
- struct TALER_EXCHANGE_WireAggregateFees *wa = &fe->fee_list[idx];
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_fixed_auto ("sig",
- &wa->master_sig),
- TALER_JSON_spec_amount_any ("wire_fee",
- &wa->fees.wire),
- TALER_JSON_spec_amount_any ("wad_fee",
- &wa->fees.wad),
- TALER_JSON_spec_amount_any ("closing_fee",
- &wa->fees.closing),
- GNUNET_JSON_spec_timestamp ("start_date",
- &wa->start_date),
- GNUNET_JSON_spec_timestamp ("end_date",
- &wa->end_date),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (fee,
- spec,
- NULL,
- NULL))
- {
- GNUNET_break_op (0);
- free_fees (fm);
- return NULL;
- }
- if (idx + 1 < len)
- wa->next = &fe->fee_list[idx + 1];
- else
- wa->next = NULL;
- }
- }
- return fm;
-}
-
-
-/**
- * Find fee by @a method.
- *
- * @param fm map to look in
- * @param method key to look for
- * @return NULL if fee is not specified in @a fm
- */
-static const struct TALER_EXCHANGE_WireAggregateFees *
-lookup_fee (const struct FeeMap *fm,
- const char *method)
-{
- for (; NULL != fm; fm = fm->next)
- if (0 == strcasecmp (fm->method,
- method))
- return fm->fee_list;
- return NULL;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP /wire request.
- *
- * @param cls the `struct TALER_EXCHANGE_WireHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response parsed JSON result, NULL on error
- */
-static void
-handle_wire_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_EXCHANGE_WireHandle *wh = cls;
- const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
- };
-
- TALER_LOG_DEBUG ("Checking raw /wire response\n");
- wh->job = NULL;
- switch (response_code)
- {
- case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- /* FIXME: Maybe we should only increment when we know it's a timeout? */
- wh->exchange->wire_error_count++;
- break;
- case MHD_HTTP_OK:
- {
- json_t *accounts;
- json_t *fees;
- unsigned int num_accounts;
- struct FeeMap *fm;
- const struct TALER_EXCHANGE_Keys *key_state;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_json ("accounts",
- &accounts),
- GNUNET_JSON_spec_json ("fees",
- &fees),
- GNUNET_JSON_spec_end ()
- };
-
- wh->exchange->wire_error_count = 0;
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (j,
- spec,
- NULL, NULL))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (0 == (num_accounts = json_array_size (accounts)))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (NULL == (fm = parse_fees (fees)))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- GNUNET_JSON_parse_free (spec);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
-
- key_state = TALER_EXCHANGE_get_keys (wh->exchange);
- /* parse accounts */
- {
- struct TALER_EXCHANGE_WireAccount was[num_accounts];
-
- for (unsigned int i = 0; i<num_accounts; i++)
- {
- struct TALER_EXCHANGE_WireAccount *wa = &was[i];
- json_t *account;
- struct GNUNET_JSON_Specification spec_account[] = {
- GNUNET_JSON_spec_string ("payto_uri",
- &wa->payto_uri),
- GNUNET_JSON_spec_fixed_auto ("master_sig",
- &wa->master_sig),
- GNUNET_JSON_spec_end ()
- };
- char *method;
-
- account = json_array_get (accounts,
- i);
- if (GNUNET_OK !=
- TALER_JSON_exchange_wire_signature_check (account,
- &key_state->master_pub))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_EXCHANGE_WIRE_SIGNATURE_INVALID;
- break;
- }
- if (GNUNET_OK !=
- GNUNET_JSON_parse (account,
- spec_account,
- NULL, NULL))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (NULL == (method = TALER_payto_get_method (wa->payto_uri)))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- if (NULL == (wa->fees = lookup_fee (fm,
- method)))
- {
- /* bogus reply */
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- GNUNET_free (method);
- break;
- }
- GNUNET_free (method);
- } /* end 'for all accounts */
- if ( (0 != response_code) &&
- (NULL != wh->cb) )
- {
- wh->cb (wh->cb_cls,
- &hr,
- num_accounts,
- was);
- wh->cb = NULL;
- }
- } /* end of 'parse accounts */
- free_fees (fm);
- GNUNET_JSON_parse_free (spec);
- } /* end of MHD_HTTP_OK */
- break;
- case MHD_HTTP_BAD_REQUEST:
- /* This should never happen, either us or the exchange is buggy
- (or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, this should never
- happen, we should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- default:
- /* unexpected response code */
- if (MHD_HTTP_GATEWAY_TIMEOUT == response_code)
- wh->exchange->wire_error_count++;
- GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for exchange wire\n",
- (unsigned int) response_code,
- (int) hr.ec);
- break;
- }
- if (NULL != wh->cb)
- wh->cb (wh->cb_cls,
- &hr,
- 0,
- NULL);
- TALER_EXCHANGE_wire_cancel (wh);
-}
-
-
-/**
- * Compute the network timeout for the next request to /wire.
- *
- * @param exchange the exchange handle
- * @returns the timeout in seconds (for use by CURL)
- */
-static long
-get_wire_timeout_seconds (struct TALER_EXCHANGE_Handle *exchange)
-{
- return GNUNET_MIN (60,
- 5 + (1L << exchange->wire_error_count));
-}
-
-
-/**
- * Obtain information about a exchange's wire instructions.
- * A exchange may provide wire instructions for creating
- * a reserve. The wire instructions also indicate
- * which wire formats merchants may use with the exchange.
- * This API is typically used by a wallet for wiring
- * funds, and possibly by a merchant to determine
- * supported wire formats.
- *
- * Note that while we return the (main) response verbatim to the
- * caller for further processing, we do already verify that the
- * response is well-formed (i.e. that signatures included in the
- * response are all valid). If the exchange's reply is not well-formed,
- * we return an HTTP status code of zero to @a cb.
- *
- * @param exchange the exchange handle; the exchange must be ready to operate
- * @param wire_cb the callback to call when a reply for this request is available
- * @param wire_cb_cls closure for the above callback
- * @return a handle for this request
- */
-struct TALER_EXCHANGE_WireHandle *
-TALER_EXCHANGE_wire (struct TALER_EXCHANGE_Handle *exchange,
- TALER_EXCHANGE_WireCallback wire_cb,
- void *wire_cb_cls)
-{
- struct TALER_EXCHANGE_WireHandle *wh;
- struct GNUNET_CURL_Context *ctx;
- CURL *eh;
-
- if (GNUNET_YES !=
- TEAH_handle_is_ready (exchange))
- {
- GNUNET_break (0);
- return NULL;
- }
- wh = GNUNET_new (struct TALER_EXCHANGE_WireHandle);
- wh->exchange = exchange;
- wh->cb = wire_cb;
- wh->cb_cls = wire_cb_cls;
- wh->url = TEAH_path_to_url (exchange,
- "/wire");
- if (NULL == wh->url)
- {
- GNUNET_free (wh);
- return NULL;
- }
- eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
- if (NULL == eh)
- {
- GNUNET_break (0);
- GNUNET_free (wh->url);
- GNUNET_free (wh);
- return NULL;
- }
- GNUNET_break (CURLE_OK ==
- curl_easy_setopt (eh,
- CURLOPT_TIMEOUT,
- get_wire_timeout_seconds (wh->exchange)));
- ctx = TEAH_handle_to_context (exchange);
- wh->job = GNUNET_CURL_job_add_with_ct_json (ctx,
- eh,
- &handle_wire_finished,
- wh);
- return wh;
-}
-
-
-/**
- * Cancel a wire information request. This function cannot be used
- * on a request handle if a response is already served for it.
- *
- * @param wh the wire information request handle
- */
-void
-TALER_EXCHANGE_wire_cancel (struct TALER_EXCHANGE_WireHandle *wh)
-{
- if (NULL != wh->job)
- {
- GNUNET_CURL_job_cancel (wh->job);
- wh->job = NULL;
- }
- GNUNET_free (wh->url);
- GNUNET_free (wh);
-}
-
-
-/* end of exchange_api_wire.c */
diff --git a/src/lib/exchange_api_withdraw.c b/src/lib/exchange_api_withdraw.c
deleted file mode 100644
index b8ab1df44..000000000
--- a/src/lib/exchange_api_withdraw.c
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/exchange_api_withdraw.c
- * @brief Implementation of /reserves/$RESERVE_PUB/withdraw requests with blinding/unblinding
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_exchange_service.h"
-#include "taler_json_lib.h"
-#include "exchange_api_handle.h"
-#include "taler_signatures.h"
-#include "exchange_api_curl_defaults.h"
-
-
-/**
- * @brief A Withdraw Handle
- */
-struct TALER_EXCHANGE_WithdrawHandle
-{
-
- /**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * Handle for the actual (internal) withdraw operation.
- */
- struct TALER_EXCHANGE_Withdraw2Handle *wh2;
-
- /**
- * Function to call with the result.
- */
- TALER_EXCHANGE_WithdrawCallback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Reserve private key.
- */
- const struct TALER_ReservePrivateKeyP *reserve_priv;
-
- /**
- * Seed of the planchet.
- */
- struct TALER_PlanchetMasterSecretP ps;
-
- /**
- * blinding secret
- */
- union TALER_DenominationBlindingKeyP bks;
-
- /**
- * Private key of the coin we are withdrawing.
- */
- struct TALER_CoinSpendPrivateKeyP priv;
-
- /**
- * Details of the planchet.
- */
- struct TALER_PlanchetDetail pd;
-
- /**
- * Values of the @cipher selected
- */
- struct TALER_ExchangeWithdrawValues alg_values;
-
- /**
- * Hash of the age commitment for this coin, if applicable. Maybe NULL
- */
- const struct TALER_AgeCommitmentHash *ach;
-
- /**
- * Denomination key we are withdrawing.
- */
- struct TALER_EXCHANGE_DenomPublicKey pk;
-
- /**
- * Hash of the public key of the coin we are signing.
- */
- struct TALER_CoinPubHashP c_hash;
-
- /**
- * Handler for the CS R request (only used for TALER_DENOMINATION_CS denominations)
- */
- struct TALER_EXCHANGE_CsRWithdrawHandle *csrh;
-
-};
-
-
-/**
- * Function called when we're done processing the
- * HTTP /reserves/$RESERVE_PUB/withdraw request.
- *
- * @param cls the `struct TALER_EXCHANGE_WithdrawHandle`
- * @param hr HTTP response data
- * @param blind_sig blind signature over the coin, NULL on error
- */
-static void
-handle_reserve_withdraw_finished (
- void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_BlindedDenominationSignature *blind_sig)
-{
- struct TALER_EXCHANGE_WithdrawHandle *wh = cls;
- struct TALER_EXCHANGE_WithdrawResponse wr = {
- .hr = *hr
- };
-
- wh->wh2 = NULL;
- switch (hr->http_status)
- {
- case MHD_HTTP_OK:
- {
- struct TALER_FreshCoin fc;
-
- if (GNUNET_OK !=
- TALER_planchet_to_coin (&wh->pk.key,
- blind_sig,
- &wh->bks,
- &wh->priv,
- wh->ach,
- &wh->c_hash,
- &wh->alg_values,
- &fc))
- {
- wr.hr.http_status = 0;
- wr.hr.ec = TALER_EC_EXCHANGE_WITHDRAW_UNBLIND_FAILURE;
- break;
- }
- wr.details.success.coin_priv = wh->priv;
- wr.details.success.bks = wh->bks;
- wr.details.success.sig = fc.sig;
- wr.details.success.exchange_vals = wh->alg_values;
- break;
- }
- case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
- {
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &wr.details.accepted.payment_target_uuid),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (hr->reply,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- wr.hr.http_status = 0;
- wr.hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- }
- break;
- default:
- break;
- }
- wh->cb (wh->cb_cls,
- &wr);
- if (MHD_HTTP_OK == hr->http_status)
- TALER_denom_sig_free (&wr.details.success.sig);
- TALER_EXCHANGE_withdraw_cancel (wh);
-}
-
-
-/**
- * Function called when stage 1 of CS withdraw is finished (request r_pub's)
- *
- * @param cls the `struct TALER_EXCHANGE_WithdrawHandle`
- * @param csrr replies from the /csr-withdraw request
- */
-static void
-withdraw_cs_stage_two_callback (
- void *cls,
- const struct TALER_EXCHANGE_CsRWithdrawResponse *csrr)
-{
- struct TALER_EXCHANGE_WithdrawHandle *wh = cls;
- struct TALER_EXCHANGE_WithdrawResponse wr = {
- .hr = csrr->hr
- };
-
- wh->csrh = NULL;
- GNUNET_assert (TALER_DENOMINATION_CS == wh->pk.key.cipher);
- switch (csrr->hr.http_status)
- {
- case MHD_HTTP_OK:
- wh->alg_values = csrr->details.success.alg_values;
- TALER_planchet_setup_coin_priv (&wh->ps,
- &wh->alg_values,
- &wh->priv);
- TALER_planchet_blinding_secret_create (&wh->ps,
- &wh->alg_values,
- &wh->bks);
- /* This initializes the 2nd half of the
- wh->pd.blinded_planchet! */
- if (GNUNET_OK !=
- TALER_planchet_prepare (&wh->pk.key,
- &wh->alg_values,
- &wh->bks,
- &wh->priv,
- wh->ach,
- &wh->c_hash,
- &wh->pd))
- {
- GNUNET_break (0);
- GNUNET_free (wh);
- }
- wh->wh2 = TALER_EXCHANGE_withdraw2 (wh->exchange,
- &wh->pd,
- wh->reserve_priv,
- &handle_reserve_withdraw_finished,
- wh);
- return;
- default:
- break;
- }
- wh->cb (wh->cb_cls,
- &wr);
- TALER_EXCHANGE_withdraw_cancel (wh);
-}
-
-
-struct TALER_EXCHANGE_WithdrawHandle *
-TALER_EXCHANGE_withdraw (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- const struct TALER_EXCHANGE_WithdrawCoinInput *wci,
- TALER_EXCHANGE_WithdrawCallback res_cb,
- void *res_cb_cls)
-{
- struct TALER_EXCHANGE_WithdrawHandle *wh;
-
- wh = GNUNET_new (struct TALER_EXCHANGE_WithdrawHandle);
- wh->exchange = exchange;
- wh->cb = res_cb;
- wh->cb_cls = res_cb_cls;
- wh->reserve_priv = reserve_priv;
- wh->ps = *wci->ps;
- wh->ach = wci->ach;
- wh->pk = *wci->pk;
- TALER_denom_pub_deep_copy (&wh->pk.key,
- &wci->pk->key);
-
- switch (wci->pk->key.cipher)
- {
- case TALER_DENOMINATION_RSA:
- {
- wh->alg_values.cipher = TALER_DENOMINATION_RSA;
- TALER_planchet_setup_coin_priv (&wh->ps,
- &wh->alg_values,
- &wh->priv);
- TALER_planchet_blinding_secret_create (&wh->ps,
- &wh->alg_values,
- &wh->bks);
- if (GNUNET_OK !=
- TALER_planchet_prepare (&wh->pk.key,
- &wh->alg_values,
- &wh->bks,
- &wh->priv,
- wh->ach,
- &wh->c_hash,
- &wh->pd))
- {
- GNUNET_break (0);
- GNUNET_free (wh);
- return NULL;
- }
- wh->wh2 = TALER_EXCHANGE_withdraw2 (exchange,
- &wh->pd,
- wh->reserve_priv,
- &handle_reserve_withdraw_finished,
- wh);
- break;
- }
- case TALER_DENOMINATION_CS:
- {
- TALER_cs_withdraw_nonce_derive (
- &wh->ps,
- &wh->pd.blinded_planchet.details.cs_blinded_planchet.nonce);
- /* Note that we only initialize the first half
- of the blinded_planchet here; the other part
- will be done after the /csr-withdraw request! */
- wh->pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
- wh->csrh = TALER_EXCHANGE_csr_withdraw (
- exchange,
- &wh->pk,
- &wh->pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &withdraw_cs_stage_two_callback,
- wh);
- break;
- }
- default:
- GNUNET_break (0);
- GNUNET_free (wh);
- return NULL;
- }
- return wh;
-}
-
-
-void
-TALER_EXCHANGE_withdraw_cancel (struct TALER_EXCHANGE_WithdrawHandle *wh)
-{
- TALER_blinded_planchet_free (&wh->pd.blinded_planchet);
- if (NULL != wh->csrh)
- {
- TALER_EXCHANGE_csr_withdraw_cancel (wh->csrh);
- wh->csrh = NULL;
- }
- if (NULL != wh->wh2)
- {
- TALER_EXCHANGE_withdraw2_cancel (wh->wh2);
- wh->wh2 = NULL;
- }
- TALER_denom_pub_free (&wh->pk.key);
- GNUNET_free (wh);
-}
diff --git a/src/lib/exchange_api_withdraw2.c b/src/lib/exchange_api_withdraw2.c
deleted file mode 100644
index a5371442f..000000000
--- a/src/lib/exchange_api_withdraw2.c
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file lib/exchange_api_withdraw2.c
- * @brief Implementation of /reserves/$RESERVE_PUB/withdraw requests without blinding/unblinding
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <jansson.h>
-#include <microhttpd.h> /* just for HTTP status codes */
-#include <gnunet/gnunet_util_lib.h>
-#include <gnunet/gnunet_json_lib.h>
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_exchange_service.h"
-#include "taler_json_lib.h"
-#include "exchange_api_handle.h"
-#include "taler_signatures.h"
-#include "exchange_api_curl_defaults.h"
-
-
-/**
- * @brief A Withdraw Handle
- */
-struct TALER_EXCHANGE_Withdraw2Handle
-{
-
- /**
- * The connection to exchange this request handle will use
- */
- struct TALER_EXCHANGE_Handle *exchange;
-
- /**
- * The url for this request.
- */
- char *url;
-
- /**
- * Handle for the request.
- */
- struct GNUNET_CURL_Job *job;
-
- /**
- * Function to call with the result.
- */
- TALER_EXCHANGE_Withdraw2Callback cb;
-
- /**
- * Closure for @a cb.
- */
- void *cb_cls;
-
- /**
- * Context for #TEH_curl_easy_post(). Keeps the data that must
- * persist for Curl to make the upload.
- */
- struct TALER_CURL_PostContext post_ctx;
-
- /**
- * Total amount requested (value plus withdraw fee).
- */
- struct TALER_Amount requested_amount;
-
- /**
- * Public key of the reserve we are withdrawing from.
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
-};
-
-
-/**
- * We got a 200 OK response for the /reserves/$RESERVE_PUB/withdraw operation.
- * Extract the coin's signature and return it to the caller. The signature we
- * get from the exchange is for the blinded value. Thus, we first must
- * unblind it and then should verify its validity against our coin's hash.
- *
- * If everything checks out, we return the unblinded signature
- * to the application via the callback.
- *
- * @param wh operation handle
- * @param json reply from the exchange
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
- */
-static enum GNUNET_GenericReturnValue
-reserve_withdraw_ok (struct TALER_EXCHANGE_Withdraw2Handle *wh,
- const json_t *json)
-{
- struct TALER_BlindedDenominationSignature blind_sig;
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_blinded_denom_sig ("ev_sig",
- &blind_sig),
- GNUNET_JSON_spec_end ()
- };
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = json,
- .http_status = MHD_HTTP_OK
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- /* signature is valid, return it to the application */
- wh->cb (wh->cb_cls,
- &hr,
- &blind_sig);
- /* make sure callback isn't called again after return */
- wh->cb = NULL;
- GNUNET_JSON_parse_free (spec);
- return GNUNET_OK;
-}
-
-
-/**
- * We got a 409 CONFLICT response for the /reserves/$RESERVE_PUB/withdraw operation.
- * Check the signatures on the withdraw transactions in the provided
- * history and that the balances add up. We don't do anything directly
- * with the information, as the JSON will be returned to the application.
- * However, our job is ensuring that the exchange followed the protocol, and
- * this in particular means checking all of the signatures in the history.
- *
- * @param wh operation handle
- * @param json reply from the exchange
- * @return #GNUNET_OK on success, #GNUNET_SYSERR on errors
- */
-static enum GNUNET_GenericReturnValue
-reserve_withdraw_payment_required (
- struct TALER_EXCHANGE_Withdraw2Handle *wh,
- const json_t *json)
-{
- struct TALER_Amount balance;
- struct TALER_Amount total_in_from_history;
- struct TALER_Amount total_out_from_history;
- json_t *history;
- size_t len;
- struct GNUNET_JSON_Specification spec[] = {
- TALER_JSON_spec_amount_any ("balance",
- &balance),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (json,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- history = json_object_get (json,
- "history");
- if (NULL == history)
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
-
- /* go over transaction history and compute
- total incoming and outgoing amounts */
- len = json_array_size (history);
- {
- struct TALER_EXCHANGE_ReserveHistoryEntry *rhistory;
-
- /* Use heap allocation as "len" may be very big and thus this may
- not fit on the stack. Use "GNUNET_malloc_large" as a malicious
- exchange may theoretically try to crash us by giving a history
- that does not fit into our memory. */
- rhistory = GNUNET_malloc_large (
- sizeof (struct TALER_EXCHANGE_ReserveHistoryEntry)
- * len);
- if (NULL == rhistory)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- TALER_EXCHANGE_parse_reserve_history (wh->exchange,
- history,
- &wh->reserve_pub,
- balance.currency,
- &total_in_from_history,
- &total_out_from_history,
- len,
- rhistory))
- {
- GNUNET_break_op (0);
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
- return GNUNET_SYSERR;
- }
- TALER_EXCHANGE_free_reserve_history (rhistory,
- len);
- }
-
- /* Check that funds were really insufficient */
- if (0 >= TALER_amount_cmp (&wh->requested_amount,
- &balance))
- {
- /* Requested amount is smaller or equal to reported balance,
- so this should not have failed. */
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Function called when we're done processing the
- * HTTP /reserves/$RESERVE_PUB/withdraw request.
- *
- * @param cls the `struct TALER_EXCHANGE_WithdrawHandle`
- * @param response_code HTTP response code, 0 on error
- * @param response parsed JSON result, NULL on error
- */
-static void
-handle_reserve_withdraw_finished (void *cls,
- long response_code,
- const void *response)
-{
- struct TALER_EXCHANGE_Withdraw2Handle *wh = cls;
- const json_t *j = response;
- struct TALER_EXCHANGE_HttpResponse hr = {
- .reply = j,
- .http_status = (unsigned int) response_code
- };
-
- wh->job = NULL;
- switch (response_code)
- {
- case 0:
- hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
- break;
- case MHD_HTTP_OK:
- if (GNUNET_OK !=
- reserve_withdraw_ok (wh,
- j))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- GNUNET_assert (NULL == wh->cb);
- TALER_EXCHANGE_withdraw2_cancel (wh);
- return;
- case MHD_HTTP_ACCEPTED:
- /* only validate reply is well-formed */
- {
- uint64_t ptu;
- struct GNUNET_JSON_Specification spec[] = {
- GNUNET_JSON_spec_uint64 ("payment_target_uuid",
- &ptu),
- GNUNET_JSON_spec_end ()
- };
-
- if (GNUNET_OK !=
- GNUNET_JSON_parse (j,
- spec,
- NULL, NULL))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- break;
- }
- }
- break;
- case MHD_HTTP_BAD_REQUEST:
- /* This should never happen, either us or the exchange is buggy
- (or API version conflict); just pass JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_FORBIDDEN:
- GNUNET_break_op (0);
- /* Nothing really to verify, exchange says one of the signatures is
- invalid; as we checked them, this should never happen, we
- should pass the JSON reply to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_NOT_FOUND:
- /* Nothing really to verify, the exchange basically just says
- that it doesn't know this reserve. Can happen if we
- query before the wire transfer went through.
- We should simply pass the JSON reply to the application. */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_CONFLICT:
- /* The exchange says that the reserve has insufficient funds;
- check the signatures in the history... */
- if (GNUNET_OK !=
- reserve_withdraw_payment_required (wh,
- j))
- {
- GNUNET_break_op (0);
- hr.http_status = 0;
- hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED;
- }
- else
- {
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- }
- break;
- case MHD_HTTP_GONE:
- /* could happen if denomination was revoked */
- /* Note: one might want to check /keys for revocation
- signature here, alas tricky in case our /keys
- is outdated => left to clients */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- case MHD_HTTP_INTERNAL_SERVER_ERROR:
- /* Server had an internal issue; we should retry, but this API
- leaves this to the application */
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- break;
- default:
- /* unexpected response code */
- GNUNET_break_op (0);
- hr.ec = TALER_JSON_get_error_code (j);
- hr.hint = TALER_JSON_get_error_hint (j);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d for exchange withdraw\n",
- (unsigned int) response_code,
- (int) hr.ec);
- break;
- }
- if (NULL != wh->cb)
- {
- wh->cb (wh->cb_cls,
- &hr,
- NULL);
- wh->cb = NULL;
- }
- TALER_EXCHANGE_withdraw2_cancel (wh);
-}
-
-
-struct TALER_EXCHANGE_Withdraw2Handle *
-TALER_EXCHANGE_withdraw2 (
- struct TALER_EXCHANGE_Handle *exchange,
- const struct TALER_PlanchetDetail *pd,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- TALER_EXCHANGE_Withdraw2Callback res_cb,
- void *res_cb_cls)
-{
- struct TALER_EXCHANGE_Withdraw2Handle *wh;
- const struct TALER_EXCHANGE_Keys *keys;
- const struct TALER_EXCHANGE_DenomPublicKey *dk;
- struct TALER_ReserveSignatureP reserve_sig;
- char arg_str[sizeof (struct TALER_ReservePublicKeyP) * 2 + 32];
- struct TALER_BlindedCoinHashP bch;
-
- keys = TALER_EXCHANGE_get_keys (exchange);
- if (NULL == keys)
- {
- GNUNET_break (0);
- return NULL;
- }
- dk = TALER_EXCHANGE_get_denomination_key_by_hash (keys,
- &pd->denom_pub_hash);
- if (NULL == dk)
- {
- GNUNET_break (0);
- return NULL;
- }
- wh = GNUNET_new (struct TALER_EXCHANGE_Withdraw2Handle);
- wh->exchange = exchange;
- wh->cb = res_cb;
- wh->cb_cls = res_cb_cls;
- /* Compute how much we expected to charge to the reserve */
- if (0 >
- TALER_amount_add (&wh->requested_amount,
- &dk->value,
- &dk->fees.withdraw))
- {
- /* Overflow here? Very strange, our CPU must be fried... */
- GNUNET_break (0);
- GNUNET_free (wh);
- return NULL;
- }
-
- GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
- &wh->reserve_pub.eddsa_pub);
-
- {
- char pub_str[sizeof (struct TALER_ReservePublicKeyP) * 2];
- char *end;
-
- end = GNUNET_STRINGS_data_to_string (
- &wh->reserve_pub,
- sizeof (struct TALER_ReservePublicKeyP),
- pub_str,
- sizeof (pub_str));
- *end = '\0';
- GNUNET_snprintf (arg_str,
- sizeof (arg_str),
- "/reserves/%s/withdraw",
- pub_str);
- }
-
- if (GNUNET_OK !=
- TALER_coin_ev_hash (&pd->blinded_planchet,
- &pd->denom_pub_hash,
- &bch))
- {
- GNUNET_break (0);
- GNUNET_free (wh);
- return NULL;
- }
-
- TALER_wallet_withdraw_sign (&pd->denom_pub_hash,
- &wh->requested_amount,
- &bch,
- reserve_priv,
- &reserve_sig);
- {
- json_t *withdraw_obj = GNUNET_JSON_PACK (
- GNUNET_JSON_pack_data_auto ("denom_pub_hash",
- &pd->denom_pub_hash),
- TALER_JSON_pack_blinded_planchet ("coin_ev",
- &pd->blinded_planchet),
- GNUNET_JSON_pack_data_auto ("reserve_sig",
- &reserve_sig));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Attempting to withdraw from reserve %s\n",
- TALER_B2S (&wh->reserve_pub));
- wh->url = TEAH_path_to_url (exchange,
- arg_str);
- if (NULL == wh->url)
- {
- json_decref (withdraw_obj);
- GNUNET_free (wh);
- return NULL;
- }
- {
- CURL *eh;
- struct GNUNET_CURL_Context *ctx;
-
- ctx = TEAH_handle_to_context (exchange);
- eh = TALER_EXCHANGE_curl_easy_get_ (wh->url);
- if ( (NULL == eh) ||
- (GNUNET_OK !=
- TALER_curl_easy_post (&wh->post_ctx,
- eh,
- withdraw_obj)) )
- {
- GNUNET_break (0);
- if (NULL != eh)
- curl_easy_cleanup (eh);
- json_decref (withdraw_obj);
- GNUNET_free (wh->url);
- GNUNET_free (wh);
- return NULL;
- }
- json_decref (withdraw_obj);
- wh->job = GNUNET_CURL_job_add2 (ctx,
- eh,
- wh->post_ctx.headers,
- &handle_reserve_withdraw_finished,
- wh);
- }
- }
- return wh;
-}
-
-
-void
-TALER_EXCHANGE_withdraw2_cancel (struct TALER_EXCHANGE_Withdraw2Handle *wh)
-{
- if (NULL != wh->job)
- {
- GNUNET_CURL_job_cancel (wh->job);
- wh->job = NULL;
- }
- GNUNET_free (wh->url);
- TALER_curl_easy_post_finished (&wh->post_ctx);
- GNUNET_free (wh);
-}
diff --git a/src/lib/test_stefan.c b/src/lib/test_stefan.c
new file mode 100644
index 000000000..4f7add593
--- /dev/null
+++ b/src/lib/test_stefan.c
@@ -0,0 +1,206 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file lib/test_stefan.c
+ * @brief test calculations on the STEFAN curve
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_handle.h"
+
+
+/**
+ * Check if @a a and @a b are numerically close.
+ *
+ * @param a an amount
+ * @param b an amount
+ * @return true if both values are quite close
+ */
+static bool
+amount_close (const struct TALER_Amount *a,
+ const struct TALER_Amount *b)
+{
+ struct TALER_Amount delta;
+
+ switch (TALER_amount_cmp (a,
+ b))
+ {
+ case -1: /* a < b */
+ GNUNET_assert (0 <
+ TALER_amount_subtract (&delta,
+ b,
+ a));
+ break;
+ case 0:
+ /* perfect */
+ return true;
+ case 1: /* a > b */
+ GNUNET_assert (0 <
+ TALER_amount_subtract (&delta,
+ a,
+ b));
+ break;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Rounding error is %s\n",
+ TALER_amount2s (&delta));
+ if (delta.value > 0)
+ {
+ GNUNET_break (0);
+ return false;
+ }
+ if (delta.fraction > 5000)
+ {
+ GNUNET_break (0);
+ return false;
+ }
+ return true; /* let's consider this a rounding error */
+}
+
+
+int
+main (int argc,
+ char **argv)
+{
+ struct TALER_EXCHANGE_DenomPublicKey dk;
+ struct TALER_EXCHANGE_Keys keys = {
+ .denom_keys = &dk,
+ .num_denom_keys = 1
+ };
+ struct TALER_Amount brut;
+ struct TALER_Amount net;
+
+ (void) argc;
+ (void) argv;
+ GNUNET_log_setup ("test-stefan",
+ "INFO",
+ NULL);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:0.00001",
+ &dk.value));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:1",
+ &keys.stefan_abs));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:0.13",
+ &keys.stefan_log));
+ keys.stefan_lin = 1.15;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:4",
+ &brut));
+ GNUNET_log_skip (1,
+ GNUNET_NO);
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_EXCHANGE_keys_stefan_b2n (&keys,
+ &brut,
+ &net));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:4",
+ &net));
+ GNUNET_log_skip (1,
+ GNUNET_NO);
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_EXCHANGE_keys_stefan_n2b (&keys,
+ &net,
+ &brut));
+ keys.stefan_lin = 1.0;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:4",
+ &brut));
+ GNUNET_log_skip (1,
+ GNUNET_NO);
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_EXCHANGE_keys_stefan_b2n (&keys,
+ &brut,
+ &net));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("MAGIC:4",
+ &net));
+ GNUNET_log_skip (1,
+ GNUNET_NO);
+ GNUNET_assert (GNUNET_SYSERR ==
+ TALER_EXCHANGE_keys_stefan_n2b (&keys,
+ &net,
+ &brut));
+ GNUNET_assert (0 == GNUNET_get_log_skip ());
+ keys.stefan_lin = 0.1;
+
+ /* try various values for lin and log STEFAN values */
+ for (unsigned int li = 1; li < 13; li += 1)
+ {
+ keys.stefan_lin = 1.0 * li / 100.0;
+
+ for (unsigned int lx = 1; lx < 100; lx += 1)
+ {
+ keys.stefan_log.fraction = lx * TALER_AMOUNT_FRAC_BASE / 100;
+
+ /* Check brutto-to-netto is stable */
+ for (unsigned int i = 0; i<10; i++)
+ {
+ struct TALER_Amount rval;
+
+ brut.value = i;
+ brut.fraction = i * TALER_AMOUNT_FRAC_BASE / 10;
+ GNUNET_assert (GNUNET_SYSERR !=
+ TALER_EXCHANGE_keys_stefan_b2n (&keys,
+ &brut,
+ &net));
+ GNUNET_assert (GNUNET_SYSERR !=
+ TALER_EXCHANGE_keys_stefan_n2b (&keys,
+ &net,
+ &rval));
+ if (TALER_amount_is_zero (&net))
+ GNUNET_assert (TALER_amount_is_zero (&rval));
+ else
+ {
+ GNUNET_assert (amount_close (&brut,
+ &rval));
+ TALER_EXCHANGE_keys_stefan_round (&keys,
+ &rval);
+ GNUNET_assert (amount_close (&brut,
+ &rval));
+ }
+ }
+
+ /* Check netto-to-brutto is stable */
+ for (unsigned int i = 0; i<10; i++)
+ {
+ struct TALER_Amount rval;
+
+ net.value = i;
+ net.fraction = i * TALER_AMOUNT_FRAC_BASE / 10;
+ GNUNET_assert (GNUNET_SYSERR !=
+ TALER_EXCHANGE_keys_stefan_n2b (&keys,
+ &net,
+ &brut));
+ GNUNET_assert (GNUNET_SYSERR !=
+ TALER_EXCHANGE_keys_stefan_b2n (&keys,
+ &brut,
+ &rval));
+ GNUNET_assert (amount_close (&net,
+ &rval));
+ TALER_EXCHANGE_keys_stefan_round (&keys,
+ &rval);
+ GNUNET_assert (amount_close (&net,
+ &rval));
+ }
+ }
+ }
+ return 0;
+}
diff --git a/src/mhd/Makefile.am b/src/mhd/Makefile.am
index f7f052d51..cd3fe7701 100644
--- a/src/mhd/Makefile.am
+++ b/src/mhd/Makefile.am
@@ -16,12 +16,12 @@ libtalermhd_la_SOURCES = \
mhd_responses.c \
mhd_run.c
libtalermhd_la_LDFLAGS = \
- -version-info 0:0:0 \
+ -version-info 3:0:3 \
-no-undefined
libtalermhd_la_LIBADD = \
- -lgnunetjson \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
+ -lgnunetjson \
-lgnunetutil \
-lmicrohttpd \
-ljansson \
diff --git a/src/mhd/mhd_config.c b/src/mhd/mhd_config.c
index 0e9f2e088..31ec3e476 100644
--- a/src/mhd/mhd_config.c
+++ b/src/mhd/mhd_config.c
@@ -78,7 +78,7 @@ TALER_MHD_parse_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg,
section,
- "port",
+ "PORT",
&port))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
diff --git a/src/mhd/mhd_legal.c b/src/mhd/mhd_legal.c
index 5082c1811..8353a6901 100644
--- a/src/mhd/mhd_legal.c
+++ b/src/mhd/mhd_legal.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2019, 2020 Taler Systems SA
+ Copyright (C) 2019, 2020, 2022, 2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -126,10 +126,18 @@ mime_matches (const char *accept_pattern,
{
const char *da = strchr (accept_pattern, '/');
const char *dm = strchr (mime, '/');
+ const char *end;
if ( (NULL == da) ||
(NULL == dm) )
return (0 == strcmp ("*", accept_pattern));
+ // FIXME: use TALER_MHD_check_accept() here!
+ /* FIXME: eventually, we might want to parse the "q=$FLOAT"
+ part after the ';' and figure out which one is the
+ best/preferred match instead of returning a boolean... */
+ end = strchr (da, ';');
+ if (NULL == end)
+ end = &da[strlen (da)];
return
( ( (1 == da - accept_pattern) &&
('*' == *accept_pattern) ) ||
@@ -138,8 +146,9 @@ mime_matches (const char *accept_pattern,
mime,
da - accept_pattern)) ) ) &&
( (0 == strcmp (da, "/*")) ||
- (0 == strcasecmp (da,
- dm)) );
+ (0 == strncasecmp (da,
+ dm,
+ end - da)) );
}
@@ -150,9 +159,9 @@ TALER_MHD_xmime_matches (const char *accept_pattern,
char *ap = GNUNET_strdup (accept_pattern);
char *sptr;
- for (const char *tok = strtok_r (ap, ";", &sptr);
+ for (const char *tok = strtok_r (ap, ",", &sptr);
NULL != tok;
- tok = strtok_r (NULL, ";", &sptr))
+ tok = strtok_r (NULL, ",", &sptr))
{
if (mime_matches (tok,
mime))
@@ -175,13 +184,21 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
struct GNUNET_TIME_Absolute a;
struct GNUNET_TIME_Timestamp m;
char dat[128];
+ char *langs;
a = GNUNET_TIME_relative_to_absolute (MAX_TERMS_CACHING);
m = GNUNET_TIME_absolute_to_timestamp (a);
+ /* Round up to next full day to ensure the expiration
+ time does not become a fingerprint! */
+ a = GNUNET_TIME_absolute_round_down (a,
+ MAX_TERMS_CACHING);
+ a = GNUNET_TIME_absolute_add (a,
+ MAX_TERMS_CACHING);
TALER_MHD_get_date_string (m.abs_time,
dat);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Setting 'Expires' header to '%s'\n",
+ "Setting '%s' header to '%s'\n",
+ MHD_HTTP_HEADER_EXPIRES,
dat);
if (NULL != legal)
{
@@ -220,6 +237,7 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
}
t = NULL;
+ langs = NULL;
if (NULL != legal)
{
const char *mime;
@@ -229,7 +247,7 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
MHD_HEADER_KIND,
MHD_HTTP_HEADER_ACCEPT);
if (NULL == mime)
- mime = "text/html";
+ mime = "text/plain";
lang = MHD_lookup_connection_value (conn,
MHD_HEADER_KIND,
MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
@@ -245,6 +263,21 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
(TALER_MHD_xmime_matches (mime,
p->mime_type)) )
{
+ if (NULL == langs)
+ {
+ langs = GNUNET_strdup (p->language);
+ }
+ else if (NULL == strstr (langs,
+ p->language))
+ {
+ char *tmp = langs;
+
+ GNUNET_asprintf (&langs,
+ "%s,%s",
+ tmp,
+ p->language);
+ GNUNET_free (tmp);
+ }
if ( (NULL == t) ||
(! TALER_MHD_xmime_matches (mime,
t->mime_type)) ||
@@ -306,6 +339,14 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
MHD_add_response_header (resp,
MHD_HTTP_HEADER_EXPIRES,
dat));
+ if (NULL != langs)
+ {
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ "Avail-Languages",
+ langs));
+ GNUNET_free (langs);
+ }
/* Set cache control headers: our response varies depending on these headers */
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
@@ -317,7 +358,7 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
MHD_HTTP_HEADER_CACHE_CONTROL,
- "public max-age=864000"));
+ "public,max-age=864000"));
if (NULL != legal)
GNUNET_break (MHD_YES ==
MHD_add_response_header (resp,
@@ -327,6 +368,10 @@ TALER_MHD_reply_legal (struct MHD_Connection *conn,
MHD_add_response_header (resp,
MHD_HTTP_HEADER_CONTENT_TYPE,
t->mime_type));
+ GNUNET_break (MHD_YES ==
+ MHD_add_response_header (resp,
+ MHD_HTTP_HEADER_CONTENT_LANGUAGE,
+ t->language));
{
MHD_RESULT ret;
@@ -360,9 +405,10 @@ load_terms (struct TALER_MHD_Legal *legal,
const char *mime;
unsigned int priority;
} mm[] = {
+ { .ext = ".txt", .mime = "text/plain", .priority = 150 },
{ .ext = ".html", .mime = "text/html", .priority = 100 },
{ .ext = ".htm", .mime = "text/html", .priority = 99 },
- { .ext = ".txt", .mime = "text/plain", .priority = 50 },
+ { .ext = ".md", .mime = "text/markdown", .priority = 50 },
{ .ext = ".pdf", .mime = "application/pdf", .priority = 25 },
{ .ext = ".jpg", .mime = "image/jpeg" },
{ .ext = ".jpeg", .mime = "image/jpeg" },
@@ -390,7 +436,7 @@ load_terms (struct TALER_MHD_Legal *legal,
name,
ext - name - 1)) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Filename `%s' does not match Etag `%s' in directory `%s/%s'. Ignoring it.\n",
name,
legal->terms_etag,
@@ -455,6 +501,9 @@ load_terms (struct TALER_MHD_Legal *legal,
GNUNET_free (fn);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Loading legal information from file `%s'\n",
+ fn);
{
void *buf;
size_t bsize;
@@ -555,7 +604,10 @@ load_language (struct TALER_MHD_Legal *legal,
if (fn[0] == '.')
continue;
- load_terms (legal, path, lang, fn);
+ load_terms (legal,
+ path,
+ lang,
+ fn);
}
GNUNET_break (0 == closedir (d));
GNUNET_free (dname);
@@ -618,7 +670,12 @@ TALER_MHD_legal_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
if (lang[0] == '.')
continue;
- load_language (legal, path, lang);
+ if (0 == strcmp (lang,
+ "locale"))
+ continue;
+ load_language (legal,
+ path,
+ lang);
}
GNUNET_break (0 == closedir (d));
GNUNET_free (path);
diff --git a/src/mhd/mhd_parsing.c b/src/mhd/mhd_parsing.c
index bae10e724..771319bd5 100644
--- a/src/mhd/mhd_parsing.c
+++ b/src/mhd/mhd_parsing.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014--2020 Taler Systems SA
+ Copyright (C) 2014--2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -60,7 +60,7 @@ TALER_MHD_parse_post_json (struct MHD_Connection *connection,
GNUNET_break (NULL == *json);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Closing connection, upload too large\n");
- return MHD_NO;
+ return GNUNET_SYSERR;
case GNUNET_JSON_PR_JSON_INVALID:
GNUNET_break (NULL == *json);
return (MHD_YES ==
@@ -86,25 +86,40 @@ TALER_MHD_parse_post_cleanup_callback (void *con_cls)
}
-enum GNUNET_GenericReturnValue
-TALER_MHD_parse_request_arg_data (struct MHD_Connection *connection,
- const char *param_name,
- void *out_data,
- size_t out_size)
+/**
+ * Extract fixed-size base32crockford encoded data from request.
+ *
+ * Queues an error response to the connection if the parameter is missing or
+ * invalid.
+ *
+ * @param connection the MHD connection
+ * @param param_name the name of the HTTP key with the value
+ * @param kind whether to extract from header, argument or footer
+ * @param[out] out_data pointer to store the result
+ * @param out_size expected size of @a out_data
+ * @param[out] present set to true if argument was found
+ * @return
+ * #GNUNET_YES if the the argument is present
+ * #GNUNET_NO if the argument is absent or malformed
+ * #GNUNET_SYSERR on internal error (error response could not be sent)
+ */
+static enum GNUNET_GenericReturnValue
+parse_request_data (struct MHD_Connection *connection,
+ const char *param_name,
+ enum MHD_ValueKind kind,
+ void *out_data,
+ size_t out_size,
+ bool *present)
{
const char *str;
str = MHD_lookup_connection_value (connection,
- MHD_GET_ARGUMENT_KIND,
+ kind,
param_name);
if (NULL == str)
{
- return (MHD_NO ==
- TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- TALER_EC_GENERIC_PARAMETER_MISSING,
- param_name))
- ? GNUNET_SYSERR : GNUNET_NO;
+ *present = false;
+ return GNUNET_OK;
}
if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (str,
@@ -117,6 +132,182 @@ TALER_MHD_parse_request_arg_data (struct MHD_Connection *connection,
TALER_EC_GENERIC_PARAMETER_MALFORMED,
param_name))
? GNUNET_SYSERR : GNUNET_NO;
+ *present = true;
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_data (struct MHD_Connection *connection,
+ const char *param_name,
+ void *out_data,
+ size_t out_size,
+ bool *present)
+{
+ return parse_request_data (connection,
+ param_name,
+ MHD_GET_ARGUMENT_KIND,
+ out_data,
+ out_size,
+ present);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_header_data (struct MHD_Connection *connection,
+ const char *header_name,
+ void *out_data,
+ size_t out_size,
+ bool *present)
+{
+ return parse_request_data (connection,
+ header_name,
+ MHD_HEADER_KIND,
+ out_data,
+ out_size,
+ present);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_timeout (struct MHD_Connection *connection,
+ struct GNUNET_TIME_Absolute *expiration)
+{
+ const char *ts;
+ char dummy;
+ unsigned long long tms;
+
+ ts = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ "timeout_ms");
+ if (NULL == ts)
+ {
+ *expiration = GNUNET_TIME_UNIT_ZERO_ABS;
+ return GNUNET_OK;
+ }
+ if (1 !=
+ sscanf (ts,
+ "%llu%c",
+ &tms,
+ &dummy))
+ {
+ MHD_RESULT mret;
+
+ GNUNET_break_op (0);
+ mret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ "timeout_ms");
+ return (MHD_YES == mret)
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ *expiration = GNUNET_TIME_relative_to_absolute (
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
+ tms));
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_number (struct MHD_Connection *connection,
+ const char *name,
+ uint64_t *off)
+{
+ const char *ts;
+ char dummy;
+ unsigned long long num;
+
+ ts = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ name);
+ if (NULL == ts)
+ return GNUNET_OK;
+ if (1 !=
+ sscanf (ts,
+ "%llu%c",
+ &num,
+ &dummy))
+ {
+ MHD_RESULT mret;
+
+ GNUNET_break_op (0);
+ mret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ name);
+ return (MHD_YES == mret)
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ *off = (uint64_t) num;
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_snumber (struct MHD_Connection *connection,
+ const char *name,
+ int64_t *val)
+{
+ const char *ts;
+ char dummy;
+ long long num;
+
+ ts = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ name);
+ if (NULL == ts)
+ return GNUNET_OK;
+ if (1 !=
+ sscanf (ts,
+ "%lld%c",
+ &num,
+ &dummy))
+ {
+ MHD_RESULT mret;
+
+ GNUNET_break_op (0);
+ mret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ name);
+ return (MHD_YES == mret)
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ *val = (int64_t) num;
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_MHD_parse_request_arg_amount (struct MHD_Connection *connection,
+ const char *name,
+ struct TALER_Amount *val)
+{
+ const char *ts;
+
+ ts = MHD_lookup_connection_value (connection,
+ MHD_GET_ARGUMENT_KIND,
+ name);
+ if (NULL == ts)
+ return GNUNET_OK;
+ if (GNUNET_OK !=
+ TALER_string_to_amount (ts,
+ val))
+ {
+ MHD_RESULT mret;
+
+ GNUNET_break_op (0);
+ mret = TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ name);
+ return (MHD_YES == mret)
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -262,4 +453,121 @@ TALER_MHD_parse_json_array (struct MHD_Connection *connection,
}
+enum GNUNET_GenericReturnValue
+TALER_MHD_check_content_length_ (struct MHD_Connection *connection,
+ unsigned long long max_len)
+{
+ const char *cl;
+ unsigned long long cv;
+ char dummy;
+
+ /* Maybe check for maximum upload size
+ and refuse requests if they are just too big. */
+ cl = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_CONTENT_LENGTH);
+ if (NULL == cl)
+ {
+ return GNUNET_OK;
+#if 0
+ /* wallet currently doesn't always send content-length! */
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MISSING,
+ MHD_HTTP_HEADER_CONTENT_LENGTH))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+#endif
+ }
+ if (1 != sscanf (cl,
+ "%llu%c",
+ &cv,
+ &dummy))
+ {
+ /* Not valid HTTP request, just close connection. */
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_GENERIC_PARAMETER_MALFORMED,
+ MHD_HTTP_HEADER_CONTENT_LENGTH))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ if (cv > TALER_MHD_REQUEST_BUFFER_MAX)
+ {
+ GNUNET_break_op (0);
+ return (MHD_YES ==
+ TALER_MHD_reply_request_too_large (connection))
+ ? GNUNET_NO
+ : GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+int
+TALER_MHD_check_accept (struct MHD_Connection *connection,
+ const char *header,
+ ...)
+{
+ bool ret = false;
+ const char *accept;
+ char *a;
+ char *saveptr;
+
+ accept = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ header);
+ if (NULL == accept)
+ return -2; /* no Accept header set */
+
+ a = GNUNET_strdup (accept);
+ for (char *t = strtok_r (a, ",", &saveptr);
+ NULL != t;
+ t = strtok_r (NULL, ",", &saveptr))
+ {
+ char *end;
+
+ /* skip leading whitespace */
+ while (isspace ((unsigned char) t[0]))
+ t++;
+ /* trim of ';q=' parameter and everything after space */
+ /* FIXME: eventually, we might want to parse the "q=$FLOAT"
+ part after the ';' and figure out which one is the
+ best/preferred match instead of returning a boolean... */
+ end = strchr (t, ';');
+ if (NULL != end)
+ *end = '\0';
+ end = strchr (t, ' ');
+ if (NULL != end)
+ *end = '\0';
+ {
+ va_list ap;
+ int off = 0;
+ const char *val;
+
+ va_start (ap,
+ header);
+ while (NULL != (val = va_arg (ap,
+ const char *)))
+ {
+ if (0 == strcasecmp (val,
+ t))
+ {
+ ret = off;
+ break;
+ }
+ off++;
+ }
+ va_end (ap);
+ }
+ }
+ GNUNET_free (a);
+ return ret;
+}
+
+
/* end of mhd_parsing.c */
diff --git a/src/mhd/mhd_run.c b/src/mhd/mhd_run.c
index 7747358ff..8388fbff6 100644
--- a/src/mhd/mhd_run.c
+++ b/src/mhd/mhd_run.c
@@ -162,8 +162,8 @@ TALER_MHD_daemon_trigger (void)
if (NULL != mhd_task)
{
GNUNET_SCHEDULER_cancel (mhd_task);
- mhd_task = NULL;
- run_daemon (NULL);
+ mhd_task = GNUNET_SCHEDULER_add_now (&run_daemon,
+ NULL);
}
else
{
diff --git a/src/pq/Makefile.am b/src/pq/Makefile.am
index b0717dfc7..4b192d762 100644
--- a/src/pq/Makefile.am
+++ b/src/pq/Makefile.am
@@ -10,11 +10,13 @@ lib_LTLIBRARIES = \
libtalerpq.la
libtalerpq_la_SOURCES = \
+ pq_common.h pq_common.c \
pq_query_helper.c \
pq_result_helper.c
libtalerpq_la_LIBADD = \
$(top_builddir)/src/util/libtalerutil.la \
-lgnunetutil -ljansson \
+ -lgnunetpq \
-lpq \
$(XLIB)
libtalerpq_la_LDFLAGS = \
diff --git a/src/pq/pq_common.c b/src/pq/pq_common.c
new file mode 100644
index 000000000..8b6f8f22c
--- /dev/null
+++ b/src/pq/pq_common.c
@@ -0,0 +1,68 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file pq/pq_common.c
+ * @brief common defines for the pq functions
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "pq_common.h"
+
+struct TALER_PQ_AmountP
+TALER_PQ_make_taler_pq_amount_ (
+ const struct TALER_Amount *amount,
+ uint32_t oid_v,
+ uint32_t oid_f)
+{
+ struct TALER_PQ_AmountP rval = {
+ .cnt = htonl (2),
+ .oid_v = htonl (oid_v),
+ .oid_f = htonl (oid_f),
+ .sz_v = htonl (sizeof((amount)->value)),
+ .sz_f = htonl (sizeof((amount)->fraction)),
+ .v = GNUNET_htonll ((amount)->value),
+ .f = htonl ((amount)->fraction)
+ };
+
+ return rval;
+}
+
+
+size_t
+TALER_PQ_make_taler_pq_amount_currency_ (
+ const struct TALER_Amount *amount,
+ uint32_t oid_v,
+ uint32_t oid_f,
+ uint32_t oid_c,
+ struct TALER_PQ_AmountCurrencyP *rval)
+{
+ size_t clen = strlen (amount->currency);
+
+ GNUNET_assert (clen < TALER_CURRENCY_LEN);
+ rval->cnt = htonl (3);
+ rval->oid_v = htonl (oid_v);
+ rval->oid_f = htonl (oid_f);
+ rval->oid_c = htonl (oid_c);
+ rval->sz_v = htonl (sizeof(amount->value));
+ rval->sz_f = htonl (sizeof(amount->fraction));
+ rval->sz_c = htonl (clen);
+ rval->v = GNUNET_htonll (amount->value);
+ rval->f = htonl (amount->fraction);
+ memcpy (rval->c,
+ amount->currency,
+ clen);
+ return sizeof (*rval) - TALER_CURRENCY_LEN + clen;
+}
diff --git a/src/pq/pq_common.h b/src/pq/pq_common.h
new file mode 100644
index 000000000..3248778a0
--- /dev/null
+++ b/src/pq/pq_common.h
@@ -0,0 +1,148 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file pq/pq_common.h
+ * @brief common defines for the pq functions
+ * @author Özgür Kesim
+ */
+#ifndef TALER_PQ_COMMON_H_
+#define TALER_PQ_COMMON_H_
+
+#include "taler_util.h"
+
+/**
+ * Internal types that are supported as TALER-exchange-specific array types.
+ *
+ * To support a new type,
+ * 1. add a new entry into this list,
+ * 2. for query-support, implement the size calculation and memory copying in
+ * qconv_array() accordingly, in pq_query_helper.c
+ * 3. provide a query-API for arrays of the type, by calling
+ * query_param_array_generic with the appropriate parameters,
+ * in pq_query_helper.c
+ * 4. for result-support, implement memory copying by adding another case
+ * to extract_array_generic, in pq_result_helper.c
+ * 5. provide a result-spec-API for arrays of the type,
+ * in pq_result_helper.c
+ * 6. expose the API's in taler_pq_lib.h
+ */
+enum TALER_PQ_ArrayType
+{
+ TALER_PQ_array_of_blinded_denom_sig,
+ TALER_PQ_array_of_blinded_coin_hash,
+ TALER_PQ_array_of_denom_hash,
+ TALER_PQ_array_of_hash_code,
+
+ /**
+ * Amounts *without* currency.
+ */
+ TALER_PQ_array_of_amount,
+
+ /**
+ * Amounts *with* currency.
+ */
+ TALER_PQ_array_of_amount_currency,
+ TALER_PQ_array_of_MAX, /* must be last */
+};
+
+
+/**
+ * Memory representation of an taler amount record for Postgres.
+ *
+ * All values need to be in network-byte-order.
+ */
+struct TALER_PQ_AmountP
+{
+ uint32_t cnt; /* # elements in the tuple (== 2) */
+ uint32_t oid_v; /* oid of .v */
+ uint32_t sz_v; /* size of .v */
+ uint64_t v; /* value */
+ uint32_t oid_f; /* oid of .f */
+ uint32_t sz_f; /* size of .f */
+ uint32_t f; /* fraction */
+} __attribute__((packed));
+
+
+/**
+ * Memory representation of an taler amount record for Postgres.
+ *
+ * All values need to be in network-byte-order.
+ */
+struct TALER_PQ_AmountNullP
+{
+ uint32_t cnt; /* # elements in the tuple (== 2) */
+ uint32_t oid_v; /* oid of .v */
+ uint32_t sz_v; /* size of .v */
+ uint32_t oid_f; /* oid of .f */
+ uint32_t sz_f; /* size of .f */
+} __attribute__((packed));
+
+
+/**
+ * Memory representation of an taler amount record with currency for Postgres.
+ *
+ * All values need to be in network-byte-order.
+ */
+struct TALER_PQ_AmountCurrencyP
+{
+ uint32_t cnt; /* # elements in the tuple (== 3) */
+ uint32_t oid_v; /* oid of .v */
+ uint32_t sz_v; /* size of .v */
+ uint64_t v; /* value */
+ uint32_t oid_f; /* oid of .f */
+ uint32_t sz_f; /* size of .f */
+ uint32_t f; /* fraction */
+ uint32_t oid_c; /* oid of .c */
+ uint32_t sz_c; /* size of .c */
+ uint8_t c[TALER_CURRENCY_LEN]; /* currency */
+} __attribute__((packed));
+
+
+/**
+ * Create a `struct TALER_PQ_AmountP` for initialization
+ *
+ * @param amount amount of type `struct TALER_Amount *`
+ * @param oid_v OID of the INT8 type in postgres
+ * @param oid_f OID of the INT4 type in postgres
+ */
+struct TALER_PQ_AmountP
+TALER_PQ_make_taler_pq_amount_ (
+ const struct TALER_Amount *amount,
+ uint32_t oid_v,
+ uint32_t oid_f);
+
+
+/**
+ * Create a `struct TALER_PQ_AmountCurrencyP` for initialization
+ *
+ * @param amount amount of type `struct TALER_Amount *`
+ * @param oid_v OID of the INT8 type in postgres
+ * @param oid_f OID of the INT4 type in postgres
+ * @param oid_c OID of the TEXT type in postgres
+ * @param[out] rval set to encoded @a amount
+ * @return actual (useful) size of @a rval for Postgres
+ */
+size_t
+TALER_PQ_make_taler_pq_amount_currency_ (
+ const struct TALER_Amount *amount,
+ uint32_t oid_v,
+ uint32_t oid_f,
+ uint32_t oid_c,
+ struct TALER_PQ_AmountCurrencyP *rval);
+
+
+#endif /* TALER_PQ_COMMON_H_ */
+/* end of pg/pq_common.h */
diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 1db608edd..b1dfd4cf1 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014, 2015, 2016, 2021, 2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,16 +21,18 @@
* @author Christian Grothoff
*/
#include "platform.h"
+#include <gnunet/gnunet_common.h>
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_pq_lib.h>
#include "taler_pq_lib.h"
+#include "pq_common.h"
/**
- * Function called to convert input argument into SQL parameters.
+ * Function called to convert input amount into SQL parameter as tuple.
*
* @param cls closure
- * @param data pointer to input argument, here a `struct TALER_AmountNBO`
+ * @param data pointer to input argument, here a `struct TALER_Amount`
* @param data_len number of bytes in @a data (if applicable)
* @param[out] param_values SQL data to set
* @param[out] param_lengths SQL length data to set
@@ -41,43 +43,76 @@
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_amount_nbo (void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_amount_currency_tuple (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
- const struct TALER_AmountNBO *amount = data;
- unsigned int off = 0;
+ struct GNUNET_PQ_Context *db = cls;
+ const struct TALER_Amount *amount = data;
+ size_t sz;
- (void) cls;
- (void) scratch;
- (void) scratch_length;
- GNUNET_assert (sizeof (struct TALER_AmountNBO) == data_len);
- GNUNET_assert (2 == param_length);
- param_values[off] = (void *) &amount->value;
- param_lengths[off] = sizeof (amount->value);
- param_formats[off] = 1;
- off++;
- param_values[off] = (void *) &amount->fraction;
- param_lengths[off] = sizeof (amount->fraction);
- param_formats[off] = 1;
- return 0;
+ GNUNET_assert (NULL != db);
+ GNUNET_assert (NULL != amount);
+ GNUNET_assert (1 == param_length);
+ GNUNET_assert (1 <= scratch_length);
+ GNUNET_assert (sizeof (struct TALER_Amount) == data_len);
+ GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
+ {
+ char *out;
+ Oid oid_v;
+ Oid oid_f;
+ Oid oid_c;
+ struct TALER_PQ_AmountCurrencyP d;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int4",
+ &oid_f));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "varchar",
+ &oid_c));
+ sz = TALER_PQ_make_taler_pq_amount_currency_ (amount,
+ oid_v,
+ oid_f,
+ oid_c,
+ &d);
+ out = GNUNET_malloc (sz);
+ memcpy (out,
+ &d,
+ sz);
+ scratch[0] = out;
+ }
+
+ param_values[0] = scratch[0];
+ param_lengths[0] = sz;
+ param_formats[0] = 1;
+
+ return 1;
}
struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
+TALER_PQ_query_param_amount_with_currency (
+ const struct GNUNET_PQ_Context *db,
+ const struct TALER_Amount *amount)
{
struct GNUNET_PQ_QueryParam res = {
- .conv = &qconv_amount_nbo,
- .data = x,
- .size = sizeof (*x),
- .num_params = 2
+ .conv_cls = (void *) db,
+ .conv = &qconv_amount_currency_tuple,
+ .data = amount,
+ .size = sizeof (*amount),
+ .num_params = 1,
};
return res;
@@ -85,7 +120,7 @@ TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
/**
- * Function called to convert input argument into SQL parameters.
+ * Function called to convert input amount into SQL parameter as tuple.
*
* @param cls closure
* @param data pointer to input argument, here a `struct TALER_Amount`
@@ -99,49 +134,74 @@ TALER_PQ_query_param_amount_nbo (const struct TALER_AmountNBO *x)
* @return -1 on error, number of offsets used in @a scratch otherwise
*/
static int
-qconv_amount (void *cls,
- const void *data,
- size_t data_len,
- void *param_values[],
- int param_lengths[],
- int param_formats[],
- unsigned int param_length,
- void *scratch[],
- unsigned int scratch_length)
+qconv_amount_tuple (void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
{
- const struct TALER_Amount *amount_hbo = data;
- struct TALER_AmountNBO *amount;
+ struct GNUNET_PQ_Context *db = cls;
+ const struct TALER_Amount *amount = data;
+ size_t sz;
+
+ GNUNET_assert (NULL != db);
+ GNUNET_assert (NULL != amount);
+ GNUNET_assert (1 == param_length);
+ GNUNET_assert (1 <= scratch_length);
+ GNUNET_assert (sizeof (struct TALER_Amount) == data_len);
+ GNUNET_static_assert (sizeof(uint32_t) == sizeof(Oid));
+ {
+ char *out;
+ Oid oid_v;
+ Oid oid_f;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "int4",
+ &oid_f));
+
+ {
+ struct TALER_PQ_AmountP d
+ = TALER_PQ_make_taler_pq_amount_ (amount,
+ oid_v,
+ oid_f);
+
+ sz = sizeof(d);
+ out = GNUNET_malloc (sz);
+ scratch[0] = out;
+ GNUNET_memcpy (out,
+ &d,
+ sizeof(d));
+ }
+ }
+
+ param_values[0] = scratch[0];
+ param_lengths[0] = sz;
+ param_formats[0] = 1;
- (void) cls;
- (void) scratch;
- (void) scratch_length;
- GNUNET_assert (2 == param_length);
- GNUNET_assert (sizeof (struct TALER_AmountNBO) == data_len);
- amount = GNUNET_new (struct TALER_AmountNBO);
- scratch[0] = amount;
- TALER_amount_hton (amount,
- amount_hbo);
- qconv_amount_nbo (cls,
- amount,
- sizeof (struct TALER_AmountNBO),
- param_values,
- param_lengths,
- param_formats,
- param_length,
- &scratch[1],
- scratch_length - 1);
return 1;
}
struct GNUNET_PQ_QueryParam
-TALER_PQ_query_param_amount (const struct TALER_Amount *x)
+TALER_PQ_query_param_amount (
+ const struct GNUNET_PQ_Context *db,
+ const struct TALER_Amount *amount)
{
struct GNUNET_PQ_QueryParam res = {
- .conv = &qconv_amount,
- .data = x,
- .size = sizeof (*x),
- .num_params = 2
+ .conv_cls = (void *) db,
+ .conv = &qconv_amount_tuple,
+ .data = amount,
+ .size = sizeof (*amount),
+ .num_params = 1,
};
return res;
@@ -174,6 +234,7 @@ qconv_denom_pub (void *cls,
unsigned int scratch_length)
{
const struct TALER_DenominationPublicKey *denom_pub = data;
+ const struct GNUNET_CRYPTO_BlindSignPublicKey *bsp = denom_pub->bsign_pub_key;
size_t tlen;
size_t len;
uint32_t be[2];
@@ -185,38 +246,38 @@ qconv_denom_pub (void *cls,
GNUNET_assert (1 == param_length);
GNUNET_assert (scratch_length > 0);
GNUNET_break (NULL == cls);
- be[0] = htonl ((uint32_t) denom_pub->cipher);
+ be[0] = htonl ((uint32_t) bsp->cipher);
be[1] = htonl (denom_pub->age_mask.bits);
- switch (denom_pub->cipher)
+ switch (bsp->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
tlen = GNUNET_CRYPTO_rsa_public_key_encode (
- denom_pub->details.rsa_public_key,
+ bsp->details.rsa_public_key,
&tbuf);
break;
- case TALER_DENOMINATION_CS:
- tlen = sizeof (denom_pub->details.cs_public_key);
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (bsp->details.cs_public_key);
break;
default:
GNUNET_assert (0);
}
len = tlen + sizeof (be);
buf = GNUNET_malloc (len);
- memcpy (buf,
- be,
- sizeof (be));
- switch (denom_pub->cipher)
+ GNUNET_memcpy (buf,
+ be,
+ sizeof (be));
+ switch (bsp->cipher)
{
- case TALER_DENOMINATION_RSA:
- memcpy (&buf[sizeof (be)],
- tbuf,
- tlen);
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ tbuf,
+ tlen);
GNUNET_free (tbuf);
break;
- case TALER_DENOMINATION_CS:
- memcpy (&buf[sizeof (be)],
- &denom_pub->details.cs_public_key,
- tlen);
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &bsp->details.cs_public_key,
+ tlen);
break;
default:
GNUNET_assert (0);
@@ -270,6 +331,7 @@ qconv_denom_sig (void *cls,
unsigned int scratch_length)
{
const struct TALER_DenominationSignature *denom_sig = data;
+ const struct GNUNET_CRYPTO_UnblindedSignature *ubs = denom_sig->unblinded_sig;
size_t tlen;
size_t len;
uint32_t be[2];
@@ -281,38 +343,38 @@ qconv_denom_sig (void *cls,
GNUNET_assert (1 == param_length);
GNUNET_assert (scratch_length > 0);
GNUNET_break (NULL == cls);
- be[0] = htonl ((uint32_t) denom_sig->cipher);
+ be[0] = htonl ((uint32_t) ubs->cipher);
be[1] = htonl (0x00); /* magic marker: unblinded */
- switch (denom_sig->cipher)
+ switch (ubs->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
tlen = GNUNET_CRYPTO_rsa_signature_encode (
- denom_sig->details.rsa_signature,
+ ubs->details.rsa_signature,
&tbuf);
break;
- case TALER_DENOMINATION_CS:
- tlen = sizeof (denom_sig->details.cs_signature);
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (ubs->details.cs_signature);
break;
default:
GNUNET_assert (0);
}
len = tlen + sizeof (be);
buf = GNUNET_malloc (len);
- memcpy (buf,
- &be,
- sizeof (be));
- switch (denom_sig->cipher)
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (ubs->cipher)
{
- case TALER_DENOMINATION_RSA:
- memcpy (&buf[sizeof (be)],
- tbuf,
- tlen);
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ tbuf,
+ tlen);
GNUNET_free (tbuf);
break;
- case TALER_DENOMINATION_CS:
- memcpy (&buf[sizeof (be)],
- &denom_sig->details.cs_signature,
- tlen);
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &ubs->details.cs_signature,
+ tlen);
break;
default:
GNUNET_assert (0);
@@ -366,6 +428,7 @@ qconv_blinded_denom_sig (void *cls,
unsigned int scratch_length)
{
const struct TALER_BlindedDenominationSignature *denom_sig = data;
+ const struct GNUNET_CRYPTO_BlindedSignature *bs = denom_sig->blinded_sig;
size_t tlen;
size_t len;
uint32_t be[2];
@@ -377,38 +440,38 @@ qconv_blinded_denom_sig (void *cls,
GNUNET_assert (1 == param_length);
GNUNET_assert (scratch_length > 0);
GNUNET_break (NULL == cls);
- be[0] = htonl ((uint32_t) denom_sig->cipher);
+ be[0] = htonl ((uint32_t) bs->cipher);
be[1] = htonl (0x01); /* magic marker: blinded */
- switch (denom_sig->cipher)
+ switch (bs->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
tlen = GNUNET_CRYPTO_rsa_signature_encode (
- denom_sig->details.blinded_rsa_signature,
+ bs->details.blinded_rsa_signature,
&tbuf);
break;
- case TALER_DENOMINATION_CS:
- tlen = sizeof (denom_sig->details.blinded_cs_answer);
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (bs->details.blinded_cs_answer);
break;
default:
GNUNET_assert (0);
}
len = tlen + sizeof (be);
buf = GNUNET_malloc (len);
- memcpy (buf,
- &be,
- sizeof (be));
- switch (denom_sig->cipher)
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (bs->cipher)
{
- case TALER_DENOMINATION_RSA:
- memcpy (&buf[sizeof (be)],
- tbuf,
- tlen);
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ tbuf,
+ tlen);
GNUNET_free (tbuf);
break;
- case TALER_DENOMINATION_CS:
- memcpy (&buf[sizeof (be)],
- &denom_sig->details.blinded_cs_answer,
- tlen);
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &bs->details.blinded_cs_answer,
+ tlen);
break;
default:
GNUNET_assert (0);
@@ -462,6 +525,7 @@ qconv_blinded_planchet (void *cls,
unsigned int scratch_length)
{
const struct TALER_BlindedPlanchet *bp = data;
+ const struct GNUNET_CRYPTO_BlindedMessage *bm = bp->blinded_message;
size_t tlen;
size_t len;
uint32_t be[2];
@@ -472,35 +536,35 @@ qconv_blinded_planchet (void *cls,
GNUNET_assert (1 == param_length);
GNUNET_assert (scratch_length > 0);
GNUNET_break (NULL == cls);
- be[0] = htonl ((uint32_t) bp->cipher);
+ be[0] = htonl ((uint32_t) bm->cipher);
be[1] = htonl (0x0100); /* magic marker: blinded */
- switch (bp->cipher)
+ switch (bm->cipher)
{
- case TALER_DENOMINATION_RSA:
- tlen = bp->details.rsa_blinded_planchet.blinded_msg_size;
+ case GNUNET_CRYPTO_BSA_RSA:
+ tlen = bm->details.rsa_blinded_message.blinded_msg_size;
break;
- case TALER_DENOMINATION_CS:
- tlen = sizeof (bp->details.cs_blinded_planchet);
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (bm->details.cs_blinded_message);
break;
default:
GNUNET_assert (0);
}
len = tlen + sizeof (be);
buf = GNUNET_malloc (len);
- memcpy (buf,
- &be,
- sizeof (be));
- switch (bp->cipher)
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (bm->cipher)
{
- case TALER_DENOMINATION_RSA:
- memcpy (&buf[sizeof (be)],
- bp->details.rsa_blinded_planchet.blinded_msg,
- tlen);
+ case GNUNET_CRYPTO_BSA_RSA:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ bm->details.rsa_blinded_message.blinded_msg,
+ tlen);
break;
- case TALER_DENOMINATION_CS:
- memcpy (&buf[sizeof (be)],
- &bp->details.cs_blinded_planchet,
- tlen);
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &bm->details.cs_blinded_message,
+ tlen);
break;
default:
GNUNET_assert (0);
@@ -553,6 +617,8 @@ qconv_exchange_withdraw_values (void *cls,
unsigned int scratch_length)
{
const struct TALER_ExchangeWithdrawValues *alg_values = data;
+ const struct GNUNET_CRYPTO_BlindingInputValues *bi =
+ alg_values->blinding_inputs;
size_t tlen;
size_t len;
uint32_t be[2];
@@ -563,32 +629,32 @@ qconv_exchange_withdraw_values (void *cls,
GNUNET_assert (1 == param_length);
GNUNET_assert (scratch_length > 0);
GNUNET_break (NULL == cls);
- be[0] = htonl ((uint32_t) alg_values->cipher);
+ be[0] = htonl ((uint32_t) bi->cipher);
be[1] = htonl (0x010000); /* magic marker: EWV */
- switch (alg_values->cipher)
+ switch (bi->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
tlen = 0;
break;
- case TALER_DENOMINATION_CS:
- tlen = sizeof (struct TALER_DenominationCSPublicRPairP);
+ case GNUNET_CRYPTO_BSA_CS:
+ tlen = sizeof (struct GNUNET_CRYPTO_CSPublicRPairP);
break;
default:
GNUNET_assert (0);
}
len = tlen + sizeof (be);
buf = GNUNET_malloc (len);
- memcpy (buf,
- &be,
- sizeof (be));
- switch (alg_values->cipher)
+ GNUNET_memcpy (buf,
+ &be,
+ sizeof (be));
+ switch (bi->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
break;
- case TALER_DENOMINATION_CS:
- memcpy (&buf[sizeof (be)],
- &alg_values->details.cs_values,
- tlen);
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (&buf[sizeof (be)],
+ &bi->details.cs_values,
+ tlen);
break;
default:
GNUNET_assert (0);
@@ -671,4 +737,603 @@ TALER_PQ_query_param_json (const json_t *x)
}
+/** ------------------- Array support -----------------------------------**/
+
+/**
+ * Closure for the array type handlers.
+ *
+ * May contain sizes information for the data, given (and handled) by the
+ * caller.
+ */
+struct qconv_array_cls
+{
+ /**
+ * If not null, contains the array of sizes (the size of the array is the
+ * .size field in the ambient GNUNET_PQ_QueryParam struct). We do not free
+ * this memory.
+ *
+ * If not null, this value has precedence over @a sizes, which MUST be NULL */
+ const size_t *sizes;
+
+ /**
+ * If @a size and @a c_sizes are NULL, this field defines the same size
+ * for each element in the array.
+ */
+ size_t same_size;
+
+ /**
+ * If true, the array parameter to the data pointer to the qconv_array is a
+ * continuous byte array of data, either with @a same_size each or sizes
+ * provided bytes by @a sizes;
+ */
+ bool continuous;
+
+ /**
+ * Type of the array elements
+ */
+ enum TALER_PQ_ArrayType typ;
+
+ /**
+ * Oid of the array elements
+ */
+ Oid oid;
+
+ /**
+ * db context, needed for OID-lookup of basis-types
+ */
+ struct GNUNET_PQ_Context *db;
+};
+
+/**
+ * Callback to cleanup a qconv_array_cls to be used during
+ * GNUNET_PQ_cleanup_query_params_closures
+ */
+static void
+qconv_array_cls_cleanup (void *cls)
+{
+ GNUNET_free (cls);
+}
+
+
+/**
+ * Function called to convert input argument into SQL parameters for arrays
+ *
+ * Note: the format for the encoding of arrays for libpq is not very well
+ * documented. We peeked into various sources (postgresql and libpqtypes) for
+ * guidance.
+ *
+ * @param cls Closure of type struct qconv_array_cls*
+ * @param data Pointer to first element in the array
+ * @param data_len Number of _elements_ in array @a data (if applicable)
+ * @param[out] param_values SQL data to set
+ * @param[out] param_lengths SQL length data to set
+ * @param[out] param_formats SQL format data to set
+ * @param param_length number of entries available in the @a param_values, @a param_lengths and @a param_formats arrays
+ * @param[out] scratch buffer for dynamic allocations (to be done via #GNUNET_malloc()
+ * @param scratch_length number of entries left in @a scratch
+ * @return -1 on error, number of offsets used in @a scratch otherwise
+ */
+static int
+qconv_array (
+ void *cls,
+ const void *data,
+ size_t data_len,
+ void *param_values[],
+ int param_lengths[],
+ int param_formats[],
+ unsigned int param_length,
+ void *scratch[],
+ unsigned int scratch_length)
+{
+ struct qconv_array_cls *meta = cls;
+ size_t num = data_len;
+ size_t total_size;
+ const size_t *sizes;
+ bool same_sized;
+ void *elements = NULL;
+ bool noerror = true;
+ /* needed to capture the encoded rsa signatures */
+ void **buffers = NULL;
+ size_t *buffer_lengths = NULL;
+
+ (void) (param_length);
+ (void) (scratch_length);
+
+ GNUNET_assert (NULL != meta);
+ GNUNET_assert (num < INT_MAX);
+
+ sizes = meta->sizes;
+ same_sized = (0 != meta->same_size);
+
+#define RETURN_UNLESS(cond) \
+ do { \
+ if (! (cond)) \
+ { \
+ GNUNET_break ((cond)); \
+ noerror = false; \
+ goto DONE; \
+ } \
+ } while (0)
+
+ /* Calculate sizes and check bounds */
+ {
+ /* num * length-field */
+ size_t x = sizeof(uint32_t);
+ size_t y = x * num;
+ RETURN_UNLESS ((0 == num) || (y / num == x));
+
+ /* size of header */
+ total_size = x = sizeof(struct GNUNET_PQ_ArrayHeader_P);
+ total_size += y;
+ RETURN_UNLESS (total_size >= x);
+
+ /* sizes of elements */
+ if (same_sized)
+ {
+ x = num * meta->same_size;
+ RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
+
+ y = total_size;
+ total_size += x;
+ RETURN_UNLESS (total_size >= y);
+ }
+ else /* sizes are different per element */
+ {
+ switch (meta->typ)
+ {
+ case TALER_PQ_array_of_amount_currency:
+ {
+ const struct TALER_Amount *amounts = data;
+ Oid oid_v;
+ Oid oid_f;
+ Oid oid_c;
+
+ buffer_lengths = GNUNET_new_array (num, size_t);
+ /* hoist out of loop? */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int4",
+ &oid_f));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "varchar",
+ &oid_c));
+ for (size_t i = 0; i<num; i++)
+ {
+ struct TALER_PQ_AmountCurrencyP am;
+ size_t len;
+
+ len = TALER_PQ_make_taler_pq_amount_currency_ (
+ &amounts[i],
+ oid_v,
+ oid_f,
+ oid_c,
+ &am);
+ buffer_lengths[i] = len;
+ y = total_size;
+ total_size += len;
+ RETURN_UNLESS (total_size >= y);
+ }
+ sizes = buffer_lengths;
+ break;
+ }
+ case TALER_PQ_array_of_blinded_denom_sig:
+ {
+ const struct TALER_BlindedDenominationSignature *denom_sigs = data;
+ size_t len;
+
+ buffers = GNUNET_new_array (num, void *);
+ buffer_lengths = GNUNET_new_array (num, size_t);
+
+ for (size_t i = 0; i<num; i++)
+ {
+ const struct GNUNET_CRYPTO_BlindedSignature *bs =
+ denom_sigs[i].blinded_sig;
+
+ switch (bs->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ len = GNUNET_CRYPTO_rsa_signature_encode (
+ bs->details.blinded_rsa_signature,
+ &buffers[i]);
+ RETURN_UNLESS (len != 0);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ len = sizeof (bs->details.blinded_cs_answer);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+
+ /* for the cipher and marker */
+ len += 2 * sizeof(uint32_t);
+ buffer_lengths[i] = len;
+
+ y = total_size;
+ total_size += len;
+ RETURN_UNLESS (total_size >= y);
+ }
+ sizes = buffer_lengths;
+ break;
+ }
+ default:
+ GNUNET_assert (0);
+ }
+ }
+
+ RETURN_UNLESS (INT_MAX > total_size);
+ RETURN_UNLESS (0 != total_size);
+
+ elements = GNUNET_malloc (total_size);
+ }
+
+ /* Write data */
+ {
+ char *out = elements;
+ struct GNUNET_PQ_ArrayHeader_P h = {
+ .ndim = htonl (1), /* We only support one-dimensional arrays */
+ .has_null = htonl (0), /* We do not support NULL entries in arrays */
+ .lbound = htonl (1), /* Default start index value */
+ .dim = htonl (num),
+ .oid = htonl (meta->oid),
+ };
+
+ /* Write header */
+ GNUNET_memcpy (out,
+ &h,
+ sizeof(h));
+ out += sizeof(h);
+
+ /* Write elements */
+ for (size_t i = 0; i < num; i++)
+ {
+ size_t sz = same_sized ? meta->same_size : sizes[i];
+
+ *(uint32_t *) out = htonl (sz);
+ out += sizeof(uint32_t);
+ switch (meta->typ)
+ {
+ case TALER_PQ_array_of_amount:
+ {
+ const struct TALER_Amount *amounts = data;
+ Oid oid_v;
+ Oid oid_f;
+
+ /* hoist out of loop? */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int4",
+ &oid_f));
+ {
+ struct TALER_PQ_AmountP am
+ = TALER_PQ_make_taler_pq_amount_ (
+ &amounts[i],
+ oid_v,
+ oid_f);
+
+ GNUNET_memcpy (out,
+ &am,
+ sizeof(am));
+ }
+ break;
+ }
+ case TALER_PQ_array_of_amount_currency:
+ {
+ const struct TALER_Amount *amounts = data;
+ Oid oid_v;
+ Oid oid_f;
+ Oid oid_c;
+
+ /* hoist out of loop? */
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int8",
+ &oid_v));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "int4",
+ &oid_f));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (meta->db,
+ "varchar",
+ &oid_c));
+ {
+ struct TALER_PQ_AmountCurrencyP am;
+ size_t len;
+
+ len = TALER_PQ_make_taler_pq_amount_currency_ (
+ &amounts[i],
+ oid_v,
+ oid_f,
+ oid_c,
+ &am);
+ GNUNET_memcpy (out,
+ &am,
+ len);
+ }
+ break;
+ }
+ case TALER_PQ_array_of_blinded_denom_sig:
+ {
+ const struct TALER_BlindedDenominationSignature *denom_sigs = data;
+ const struct GNUNET_CRYPTO_BlindedSignature *bs =
+ denom_sigs[i].blinded_sig;
+ uint32_t be[2];
+
+ be[0] = htonl ((uint32_t) bs->cipher);
+ be[1] = htonl (0x01); /* magic margker: blinded */
+ GNUNET_memcpy (out,
+ &be,
+ sizeof(be));
+ out += sizeof(be);
+ sz -= sizeof(be);
+
+ switch (bs->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ /* For RSA, 'same_sized' must have been false */
+ GNUNET_assert (NULL != buffers);
+ GNUNET_memcpy (out,
+ buffers[i],
+ sz);
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ GNUNET_memcpy (out,
+ &bs->details.blinded_cs_answer,
+ sz);
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ break;
+ }
+ case TALER_PQ_array_of_blinded_coin_hash:
+ {
+ const struct TALER_BlindedCoinHashP *coin_hs = data;
+
+ GNUNET_memcpy (out,
+ &coin_hs[i],
+ sizeof(struct TALER_BlindedCoinHashP));
+
+ break;
+ }
+ case TALER_PQ_array_of_denom_hash:
+ {
+ const struct TALER_DenominationHashP *denom_hs = data;
+
+ GNUNET_memcpy (out,
+ &denom_hs[i],
+ sizeof(struct TALER_DenominationHashP));
+ break;
+ }
+ case TALER_PQ_array_of_hash_code:
+ {
+ const struct GNUNET_HashCode *hashes = data;
+
+ GNUNET_memcpy (out,
+ &hashes[i],
+ sizeof(struct GNUNET_HashCode));
+ break;
+ }
+ default:
+ {
+ GNUNET_assert (0);
+ break;
+ }
+ }
+ out += sz;
+ }
+ }
+ param_values[0] = elements;
+ param_lengths[0] = total_size;
+ param_formats[0] = 1;
+ scratch[0] = elements;
+
+DONE:
+ if (NULL != buffers)
+ {
+ for (size_t i = 0; i<num; i++)
+ GNUNET_free (buffers[i]);
+ GNUNET_free (buffers);
+ }
+ GNUNET_free (buffer_lengths);
+ if (noerror)
+ return 1;
+ return -1;
+}
+
+
+/**
+ * Function to generate a typ specific query parameter and corresponding closure
+ *
+ * @param num Number of elements in @a elements
+ * @param continuous If true, @a elements is an continuous array of data
+ * @param elements Array of @a num elements, either continuous or pointers
+ * @param sizes Array of @a num sizes, one per element, may be NULL
+ * @param same_size If not 0, all elements in @a elements have this size
+ * @param typ Supported internal type of each element in @a elements
+ * @param oid Oid of the type to be used in Postgres
+ * @param[in,out] db our database handle for looking up OIDs
+ * @return Query parameter
+ */
+static struct GNUNET_PQ_QueryParam
+query_param_array_generic (
+ unsigned int num,
+ bool continuous,
+ const void *elements,
+ const size_t *sizes,
+ size_t same_size,
+ enum TALER_PQ_ArrayType typ,
+ Oid oid,
+ struct GNUNET_PQ_Context *db)
+{
+ struct qconv_array_cls *meta = GNUNET_new (struct qconv_array_cls);
+
+ meta->typ = typ;
+ meta->oid = oid;
+ meta->sizes = sizes;
+ meta->same_size = same_size;
+ meta->continuous = continuous;
+ meta->db = db;
+
+ {
+ struct GNUNET_PQ_QueryParam res = {
+ .conv = qconv_array,
+ .conv_cls = meta,
+ .conv_cls_cleanup = qconv_array_cls_cleanup,
+ .data = elements,
+ .size = num,
+ .num_params = 1,
+ };
+
+ return res;
+ }
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_blinded_denom_sig (
+ size_t num,
+ const struct TALER_BlindedDenominationSignature *denom_sigs,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &oid));
+ return query_param_array_generic (num,
+ true,
+ denom_sigs,
+ NULL,
+ 0,
+ TALER_PQ_array_of_blinded_denom_sig,
+ oid,
+ NULL);
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_blinded_coin_hash (
+ size_t num,
+ const struct TALER_BlindedCoinHashP *coin_hs,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &oid));
+ return query_param_array_generic (num,
+ true,
+ coin_hs,
+ NULL,
+ sizeof(struct TALER_BlindedCoinHashP),
+ TALER_PQ_array_of_blinded_coin_hash,
+ oid,
+ NULL);
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_denom_hash (
+ size_t num,
+ const struct TALER_DenominationHashP *denom_hs,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &oid));
+ return query_param_array_generic (num,
+ true,
+ denom_hs,
+ NULL,
+ sizeof(struct TALER_DenominationHashP),
+ TALER_PQ_array_of_denom_hash,
+ oid,
+ NULL);
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_hash_code (
+ size_t num,
+ const struct GNUNET_HashCode *hashes,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db, "gnunet_hashcode", &oid));
+ return query_param_array_generic (num,
+ true,
+ hashes,
+ NULL,
+ sizeof(struct GNUNET_HashCode),
+ TALER_PQ_array_of_hash_code,
+ oid,
+ NULL);
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount (
+ size_t num,
+ const struct TALER_Amount *amounts,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "taler_amount",
+ &oid));
+ return query_param_array_generic (
+ num,
+ true,
+ amounts,
+ NULL,
+ sizeof(struct TALER_PQ_AmountP),
+ TALER_PQ_array_of_amount,
+ oid,
+ db);
+}
+
+
+struct GNUNET_PQ_QueryParam
+TALER_PQ_query_param_array_amount_with_currency (
+ size_t num,
+ const struct TALER_Amount *amounts,
+ struct GNUNET_PQ_Context *db)
+{
+ Oid oid;
+
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "taler_amount_currency",
+ &oid));
+ return query_param_array_generic (
+ num,
+ true,
+ amounts,
+ NULL,
+ 0, /* currency is technically variable length */
+ TALER_PQ_array_of_amount_currency,
+ oid,
+ db);
+}
+
+
/* end of pq/pq_query_helper.c */
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index 139cf1cbf..384200cfb 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -20,164 +20,144 @@
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
+#include "pq_common.h"
#include "taler_pq_lib.h"
/**
- * Extract a currency amount from a query result according to the
- * given specification.
+ * Extract an amount from a tuple including the currency from a Postgres
+ * database @a result at row @a row.
*
- * @param result the result to extract the amount from
- * @param row which row of the result to extract the amount from (needed as results can have multiple rows)
- * @param currency currency to use for @a r_amount_nbo
- * @param val_name name of the column with the amount's "value", must include the substring "_val".
- * @param frac_name name of the column with the amount's "fractional" value, must include the substring "_frac".
- * @param[out] r_amount_nbo where to store the amount, in network byte order
+ * @param cls closure; not used
+ * @param result where to extract data from
+ * @param row row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
* @return
* #GNUNET_YES if all results could be extracted
* #GNUNET_NO if at least one result was NULL
* #GNUNET_SYSERR if a result was invalid (non-existing field)
*/
static enum GNUNET_GenericReturnValue
-extract_amount_nbo_helper (PGresult *result,
- int row,
- const char *currency,
- const char *val_name,
- const char *frac_name,
- struct TALER_AmountNBO *r_amount_nbo)
+extract_amount_currency_tuple (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
- int val_num;
- int frac_num;
- int len;
-
- /* These checks are simply to check that clients obey by our naming
- conventions, and not for any functional reason */
- GNUNET_assert (NULL !=
- strstr (val_name,
- "_val"));
- GNUNET_assert (NULL !=
- strstr (frac_name,
- "_frac"));
- /* Set return value to invalid in case we don't finish */
- memset (r_amount_nbo,
- 0,
- sizeof (struct TALER_AmountNBO));
- val_num = PQfnumber (result,
- val_name);
- frac_num = PQfnumber (result,
- frac_name);
- if (val_num < 0)
+ struct TALER_Amount *r_amount = dst;
+ int col;
+
+ (void) cls;
+ if (sizeof (struct TALER_Amount) != *dst_size)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' does not exist in result\n",
- val_name);
+ GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (frac_num < 0)
+
+ /* Set return value to invalid in case we don't finish */
+ memset (r_amount,
+ 0,
+ sizeof (struct TALER_Amount));
+ col = PQfnumber (result,
+ fname);
+ if (col < 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Field `%s' does not exist in result\n",
- frac_name);
+ fname);
return GNUNET_SYSERR;
}
- if ( (PQgetisnull (result,
- row,
- val_num)) ||
- (PQgetisnull (result,
- row,
- frac_num)) )
+ if (PQgetisnull (result,
+ row,
+ col))
{
return GNUNET_NO;
}
- /* Note that Postgres stores value in NBO internally,
- so no conversion needed in this case */
- r_amount_nbo->value = *(uint64_t *) PQgetvalue (result,
- row,
- val_num);
- r_amount_nbo->fraction = *(uint32_t *) PQgetvalue (result,
- row,
- frac_num);
- if (GNUNET_ntohll (r_amount_nbo->value) >= TALER_AMOUNT_MAX_VALUE)
+
+ /* Parse the tuple */
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' exceeds legal range\n",
- val_name);
- return GNUNET_SYSERR;
+ struct TALER_PQ_AmountCurrencyP ap;
+ const char *in;
+ size_t size;
+
+ size = PQgetlength (result,
+ row,
+ col);
+ if ( (size >= sizeof (ap)) ||
+ (size <= sizeof (ap) - TALER_CURRENCY_LEN) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Incorrect size of binary field `%s' (got %zu, expected (%zu-%zu))\n",
+ fname,
+ size,
+ sizeof (ap) - TALER_CURRENCY_LEN,
+ sizeof (ap));
+ return GNUNET_SYSERR;
+ }
+
+ in = PQgetvalue (result,
+ row,
+ col);
+ memset (&ap.c,
+ 0,
+ TALER_CURRENCY_LEN);
+ memcpy (&ap,
+ in,
+ size);
+ if (3 != ntohl (ap.cnt))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Incorrect number of elements in tuple-field `%s'\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ /* TODO[oec]: OID-checks? */
+
+ r_amount->value = GNUNET_ntohll (ap.v);
+ r_amount->fraction = ntohl (ap.f);
+ memcpy (r_amount->currency,
+ ap.c,
+ TALER_CURRENCY_LEN);
+ if ('\0' != r_amount->currency[TALER_CURRENCY_LEN - 1])
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Invalid currency (not 0-terminated) in tuple field `%s'\n",
+ fname);
+ /* be sure nobody uses this by accident */
+ memset (r_amount,
+ 0,
+ sizeof (struct TALER_Amount));
+ return GNUNET_SYSERR;
+ }
}
- if (ntohl (r_amount_nbo->fraction) >= TALER_AMOUNT_FRAC_BASE)
+
+ if (r_amount->value >= TALER_AMOUNT_MAX_VALUE)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Field `%s' exceeds legal range\n",
- frac_name);
+ "Value in field `%s' exceeds legal range\n",
+ fname);
return GNUNET_SYSERR;
}
- len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
- strlen (currency));
- memcpy (r_amount_nbo->currency,
- currency,
- len);
- return GNUNET_OK;
-}
-
-
-/**
- * Extract data from a Postgres database @a result at row @a row.
- *
- * @param cls closure, a `const char *` giving the currency
- * @param result where to extract data from
- * @param row row to extract data from
- * @param fname name (or prefix) of the fields to extract from
- * @param[in,out] dst_size where to store size of result, may be NULL
- * @param[out] dst where to store the result
- * @return
- * #GNUNET_YES if all results could be extracted
- * #GNUNET_NO if at least one result was NULL
- * #GNUNET_SYSERR if a result was invalid (non-existing field)
- */
-static enum GNUNET_GenericReturnValue
-extract_amount_nbo (void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
-{
- const char *currency = cls;
- char *val_name;
- char *frac_name;
- enum GNUNET_GenericReturnValue ret;
-
- if (sizeof (struct TALER_AmountNBO) != *dst_size)
+ if (r_amount->fraction >= TALER_AMOUNT_FRAC_BASE)
{
- GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Fraction in field `%s' exceeds legal range\n",
+ fname);
return GNUNET_SYSERR;
}
- GNUNET_asprintf (&val_name,
- "%s_val",
- fname);
- GNUNET_asprintf (&frac_name,
- "%s_frac",
- fname);
- ret = extract_amount_nbo_helper (result,
- row,
- currency,
- val_name,
- frac_name,
- dst);
- GNUNET_free (val_name);
- GNUNET_free (frac_name);
- return ret;
+ return GNUNET_OK;
}
struct GNUNET_PQ_ResultSpec
-TALER_PQ_result_spec_amount_nbo (const char *name,
- const char *currency,
- struct TALER_AmountNBO *amount)
+TALER_PQ_result_spec_amount_with_currency (const char *name,
+ struct TALER_Amount *amount)
{
struct GNUNET_PQ_ResultSpec res = {
- .conv = &extract_amount_nbo,
- .cls = (void *) currency,
+ .conv = &extract_amount_currency_tuple,
.dst = (void *) amount,
.dst_size = sizeof (*amount),
.fname = name
@@ -188,7 +168,7 @@ TALER_PQ_result_spec_amount_nbo (const char *name,
/**
- * Extract data from a Postgres database @a result at row @a row.
+ * Extract an amount from a tuple from a Postgres database @a result at row @a row.
*
* @param cls closure, a `const char *` giving the currency
* @param result where to extract data from
@@ -202,47 +182,125 @@ TALER_PQ_result_spec_amount_nbo (const char *name,
* #GNUNET_SYSERR if a result was invalid (non-existing field)
*/
static enum GNUNET_GenericReturnValue
-extract_amount (void *cls,
- PGresult *result,
- int row,
- const char *fname,
- size_t *dst_size,
- void *dst)
+extract_amount_tuple (void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
{
- const char *currency = cls;
struct TALER_Amount *r_amount = dst;
- char *val_name;
- char *frac_name;
- struct TALER_AmountNBO amount_nbo;
- enum GNUNET_GenericReturnValue ret;
+ const char *currency = cls;
+ int col;
+ size_t len;
- if (sizeof (struct TALER_AmountNBO) != *dst_size)
+ if (sizeof (struct TALER_Amount) != *dst_size)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- GNUNET_asprintf (&val_name,
- "%s_val",
- fname);
- GNUNET_asprintf (&frac_name,
- "%s_frac",
+
+ /* Set return value to invalid in case we don't finish */
+ memset (r_amount,
+ 0,
+ sizeof (struct TALER_Amount));
+ col = PQfnumber (result,
fname);
- ret = extract_amount_nbo_helper (result,
- row,
- currency,
- val_name,
- frac_name,
- &amount_nbo);
- if (GNUNET_OK == ret)
- TALER_amount_ntoh (r_amount,
- &amount_nbo);
- else
- memset (r_amount,
- 0,
- sizeof (struct TALER_Amount));
- GNUNET_free (val_name);
- GNUNET_free (frac_name);
- return ret;
+ if (col < 0)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Field `%s' does not exist in result\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ if (PQgetisnull (result,
+ row,
+ col))
+ {
+ return GNUNET_NO;
+ }
+
+ /* Parse the tuple */
+ {
+ struct TALER_PQ_AmountP ap;
+ const char *in;
+ size_t size;
+
+ size = PQgetlength (result,
+ row,
+ col);
+ in = PQgetvalue (result,
+ row,
+ col);
+ if (sizeof(struct TALER_PQ_AmountNullP) == size)
+ {
+ struct TALER_PQ_AmountNullP apn;
+
+ memcpy (&apn,
+ in,
+ size);
+ if ( (2 == ntohl (apn.cnt)) &&
+ (-1 == (int32_t) ntohl (apn.sz_v)) &&
+ (-1 == (int32_t) ntohl (apn.sz_f)) )
+ {
+ /* is NULL! */
+ return GNUNET_NO;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Incorrect size of binary field `%s' and not NULL (got %zu, expected %zu)\n",
+ fname,
+ size,
+ sizeof(ap));
+ return GNUNET_SYSERR;
+ }
+ if (sizeof(ap) != size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Incorrect size of binary field `%s' (got %zu, expected %zu)\n",
+ fname,
+ size,
+ sizeof(ap));
+ return GNUNET_SYSERR;
+ }
+
+ memcpy (&ap,
+ in,
+ size);
+ if (2 != ntohl (ap.cnt))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Incorrect number of elements in tuple-field `%s'\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ /* TODO[oec]: OID-checks? */
+
+ r_amount->value = GNUNET_ntohll (ap.v);
+ r_amount->fraction = ntohl (ap.f);
+ }
+
+ if (r_amount->value >= TALER_AMOUNT_MAX_VALUE)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Value in field `%s' exceeds legal range\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+ if (r_amount->fraction >= TALER_AMOUNT_FRAC_BASE)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Fraction in field `%s' exceeds legal range\n",
+ fname);
+ return GNUNET_SYSERR;
+ }
+
+ len = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
+ strlen (currency));
+
+ GNUNET_memcpy (r_amount->currency,
+ currency,
+ len);
+ return GNUNET_OK;
}
@@ -252,7 +310,7 @@ TALER_PQ_result_spec_amount (const char *name,
struct TALER_Amount *amount)
{
struct GNUNET_PQ_ResultSpec res = {
- .conv = &extract_amount,
+ .conv = &extract_amount_tuple,
.cls = (void *) currency,
.dst = (void *) amount,
.dst_size = sizeof (*amount),
@@ -388,6 +446,7 @@ extract_denom_pub (void *cls,
void *dst)
{
struct TALER_DenominationPublicKey *pk = dst;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bpk;
size_t len;
const char *res;
int fnum;
@@ -420,38 +479,52 @@ extract_denom_pub (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- memcpy (be,
- res,
- sizeof (be));
+ GNUNET_memcpy (be,
+ res,
+ sizeof (be));
res += sizeof (be);
len -= sizeof (be);
- pk->cipher = ntohl (be[0]);
+ bpk = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bpk->cipher = ntohl (be[0]);
+ bpk->rc = 1;
pk->age_mask.bits = ntohl (be[1]);
- switch (pk->cipher)
+ switch (bpk->cipher)
{
- case TALER_DENOMINATION_RSA:
- pk->details.rsa_public_key
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ bpk->details.rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_decode (res,
len);
- if (NULL == pk->details.rsa_public_key)
+ if (NULL == bpk->details.rsa_public_key)
{
GNUNET_break (0);
+ GNUNET_free (bpk);
return GNUNET_SYSERR;
}
+ pk->bsign_pub_key = bpk;
+ GNUNET_CRYPTO_hash (res,
+ len,
+ &bpk->pub_key_hash);
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- if (sizeof (pk->details.cs_public_key) != len)
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bpk->details.cs_public_key) != len)
{
GNUNET_break (0);
+ GNUNET_free (bpk);
return GNUNET_SYSERR;
}
- memcpy (&pk->details.cs_public_key,
- res,
- len);
+ GNUNET_memcpy (&bpk->details.cs_public_key,
+ res,
+ len);
+ pk->bsign_pub_key = bpk;
+ GNUNET_CRYPTO_hash (res,
+ len,
+ &bpk->pub_key_hash);
return GNUNET_OK;
- default:
- GNUNET_break (0);
}
+ GNUNET_break (0);
+ GNUNET_free (bpk);
return GNUNET_SYSERR;
}
@@ -511,6 +584,7 @@ extract_denom_sig (void *cls,
void *dst)
{
struct TALER_DenominationSignature *sig = dst;
+ struct GNUNET_CRYPTO_UnblindedSignature *ubs;
size_t len;
const char *res;
int fnum;
@@ -543,9 +617,9 @@ extract_denom_sig (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- memcpy (&be,
- res,
- sizeof (be));
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
if (0x00 != ntohl (be[1]))
{
GNUNET_break (0);
@@ -553,32 +627,40 @@ extract_denom_sig (void *cls,
}
res += sizeof (be);
len -= sizeof (be);
- sig->cipher = ntohl (be[0]);
- switch (sig->cipher)
+ ubs = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
+ ubs->rc = 1;
+ ubs->cipher = ntohl (be[0]);
+ switch (ubs->cipher)
{
- case TALER_DENOMINATION_RSA:
- sig->details.rsa_signature
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ ubs->details.rsa_signature
= GNUNET_CRYPTO_rsa_signature_decode (res,
len);
- if (NULL == sig->details.rsa_signature)
+ if (NULL == ubs->details.rsa_signature)
{
GNUNET_break (0);
+ GNUNET_free (ubs);
return GNUNET_SYSERR;
}
+ sig->unblinded_sig = ubs;
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- if (sizeof (sig->details.cs_signature) != len)
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (ubs->details.cs_signature) != len)
{
GNUNET_break (0);
+ GNUNET_free (ubs);
return GNUNET_SYSERR;
}
- memcpy (&sig->details.cs_signature,
- res,
- len);
+ GNUNET_memcpy (&ubs->details.cs_signature,
+ res,
+ len);
+ sig->unblinded_sig = ubs;
return GNUNET_OK;
- default:
- GNUNET_break (0);
}
+ GNUNET_break (0);
+ GNUNET_free (ubs);
return GNUNET_SYSERR;
}
@@ -638,6 +720,7 @@ extract_blinded_denom_sig (void *cls,
void *dst)
{
struct TALER_BlindedDenominationSignature *sig = dst;
+ struct GNUNET_CRYPTO_BlindedSignature *bs;
size_t len;
const char *res;
int fnum;
@@ -670,9 +753,9 @@ extract_blinded_denom_sig (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- memcpy (&be,
- res,
- sizeof (be));
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
if (0x01 != ntohl (be[1])) /* magic marker: blinded */
{
GNUNET_break (0);
@@ -680,32 +763,40 @@ extract_blinded_denom_sig (void *cls,
}
res += sizeof (be);
len -= sizeof (be);
- sig->cipher = ntohl (be[0]);
- switch (sig->cipher)
+ bs = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ bs->rc = 1;
+ bs->cipher = ntohl (be[0]);
+ switch (bs->cipher)
{
- case TALER_DENOMINATION_RSA:
- sig->details.blinded_rsa_signature
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ bs->details.blinded_rsa_signature
= GNUNET_CRYPTO_rsa_signature_decode (res,
len);
- if (NULL == sig->details.blinded_rsa_signature)
+ if (NULL == bs->details.blinded_rsa_signature)
{
GNUNET_break (0);
+ GNUNET_free (bs);
return GNUNET_SYSERR;
}
+ sig->blinded_sig = bs;
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- if (sizeof (sig->details.blinded_cs_answer) != len)
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bs->details.blinded_cs_answer) != len)
{
GNUNET_break (0);
+ GNUNET_free (bs);
return GNUNET_SYSERR;
}
- memcpy (&sig->details.blinded_cs_answer,
- res,
- len);
+ GNUNET_memcpy (&bs->details.blinded_cs_answer,
+ res,
+ len);
+ sig->blinded_sig = bs;
return GNUNET_OK;
- default:
- GNUNET_break (0);
}
+ GNUNET_break (0);
+ GNUNET_free (bs);
return GNUNET_SYSERR;
}
@@ -766,6 +857,7 @@ extract_blinded_planchet (void *cls,
void *dst)
{
struct TALER_BlindedPlanchet *bp = dst;
+ struct GNUNET_CRYPTO_BlindedMessage *bm;
size_t len;
const char *res;
int fnum;
@@ -798,9 +890,9 @@ extract_blinded_planchet (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- memcpy (&be,
- res,
- sizeof (be));
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
if (0x0100 != ntohl (be[1])) /* magic marker: blinded */
{
GNUNET_break (0);
@@ -808,29 +900,36 @@ extract_blinded_planchet (void *cls,
}
res += sizeof (be);
len -= sizeof (be);
- bp->cipher = ntohl (be[0]);
- switch (bp->cipher)
+ bm = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
+ bm->rc = 1;
+ bm->cipher = ntohl (be[0]);
+ switch (bm->cipher)
{
- case TALER_DENOMINATION_RSA:
- bp->details.rsa_blinded_planchet.blinded_msg_size
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
+ bm->details.rsa_blinded_message.blinded_msg_size
= len;
- bp->details.rsa_blinded_planchet.blinded_msg
+ bm->details.rsa_blinded_message.blinded_msg
= GNUNET_memdup (res,
len);
+ bp->blinded_message = bm;
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- if (sizeof (bp->details.cs_blinded_planchet) != len)
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bm->details.cs_blinded_message) != len)
{
GNUNET_break (0);
+ GNUNET_free (bm);
return GNUNET_SYSERR;
}
- memcpy (&bp->details.cs_blinded_planchet,
- res,
- len);
+ GNUNET_memcpy (&bm->details.cs_blinded_message,
+ res,
+ len);
+ bp->blinded_message = bm;
return GNUNET_OK;
- default:
- GNUNET_break (0);
}
+ GNUNET_break (0);
+ GNUNET_free (bm);
return GNUNET_SYSERR;
}
@@ -891,6 +990,7 @@ extract_exchange_withdraw_values (void *cls,
void *dst)
{
struct TALER_ExchangeWithdrawValues *alg_values = dst;
+ struct GNUNET_CRYPTO_BlindingInputValues *bi;
size_t len;
const char *res;
int fnum;
@@ -923,9 +1023,9 @@ extract_exchange_withdraw_values (void *cls,
GNUNET_break (0);
return GNUNET_SYSERR;
}
- memcpy (&be,
- res,
- sizeof (be));
+ GNUNET_memcpy (&be,
+ res,
+ sizeof (be));
if (0x010000 != ntohl (be[1])) /* magic marker: EWV */
{
GNUNET_break (0);
@@ -933,29 +1033,37 @@ extract_exchange_withdraw_values (void *cls,
}
res += sizeof (be);
len -= sizeof (be);
- alg_values->cipher = ntohl (be[0]);
- switch (alg_values->cipher)
+ bi = GNUNET_new (struct GNUNET_CRYPTO_BlindingInputValues);
+ bi->rc = 1;
+ bi->cipher = ntohl (be[0]);
+ switch (bi->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ break;
+ case GNUNET_CRYPTO_BSA_RSA:
if (0 != len)
{
GNUNET_break (0);
+ GNUNET_free (bi);
return GNUNET_SYSERR;
}
+ alg_values->blinding_inputs = bi;
return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- if (sizeof (struct TALER_DenominationCSPublicRPairP) != len)
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof (bi->details.cs_values) != len)
{
GNUNET_break (0);
+ GNUNET_free (bi);
return GNUNET_SYSERR;
}
- memcpy (&alg_values->details.cs_values,
- res,
- len);
+ GNUNET_memcpy (&bi->details.cs_values,
+ res,
+ len);
+ alg_values->blinding_inputs = bi;
return GNUNET_OK;
- default:
- GNUNET_break (0);
}
+ GNUNET_break (0);
+ GNUNET_free (bi);
return GNUNET_SYSERR;
}
@@ -975,4 +1083,495 @@ TALER_PQ_result_spec_exchange_withdraw_values (
}
+/**
+ * Closure for the array result specifications. Contains type information
+ * for the generic parser extract_array_generic and out-pointers for the results.
+ */
+struct ArrayResultCls
+{
+ /**
+ * Oid of the expected type, must match the oid in the header of the PQResult struct
+ */
+ Oid oid;
+
+ /**
+ * Target type
+ */
+ enum TALER_PQ_ArrayType typ;
+
+ /**
+ * If not 0, defines the expected size of each entry
+ */
+ size_t same_size;
+
+ /**
+ * Out-pointer to write the number of elements in the array
+ */
+ size_t *num;
+
+ /**
+ * Out-pointer. If @a typ is TALER_PQ_array_of_byte and @a same_size is 0,
+ * allocate and put the array of @a num sizes here. NULL otherwise
+ */
+ size_t **sizes;
+
+ /**
+ * DB_connection, needed for OID-lookup for composite types
+ */
+ const struct GNUNET_PQ_Context *db;
+
+ /**
+ * Currency information for amount composites
+ */
+ char currency[TALER_CURRENCY_LEN];
+};
+
+
+/**
+ * Extract data from a Postgres database @a result as array of a specific type
+ * from row @a row. The type information and optionally additional
+ * out-parameters are given in @a cls which is of type array_result_cls.
+ *
+ * @param cls closure of type array_result_cls
+ * @param result where to extract data from
+ * @param row row to extract data from
+ * @param fname name (or prefix) of the fields to extract from
+ * @param[in,out] dst_size where to store size of result, may be NULL
+ * @param[out] dst where to store the result
+ * @return
+ * #GNUNET_YES if all results could be extracted
+ * #GNUNET_SYSERR if a result was invalid (non-existing field or NULL)
+ */
+static enum GNUNET_GenericReturnValue
+extract_array_generic (
+ void *cls,
+ PGresult *result,
+ int row,
+ const char *fname,
+ size_t *dst_size,
+ void *dst)
+{
+ const struct ArrayResultCls *info = cls;
+ int data_sz;
+ char *data;
+ void *out = NULL;
+ struct GNUNET_PQ_ArrayHeader_P header;
+ int col_num;
+
+ GNUNET_assert (NULL != dst);
+ *((void **) dst) = NULL;
+
+ #define FAIL_IF(cond) \
+ do { \
+ if ((cond)) \
+ { \
+ GNUNET_break (! (cond)); \
+ goto FAIL; \
+ } \
+ } while (0)
+
+ col_num = PQfnumber (result, fname);
+ FAIL_IF (0 > col_num);
+
+ data_sz = PQgetlength (result, row, col_num);
+ FAIL_IF (0 > data_sz);
+ FAIL_IF (sizeof(header) > (size_t) data_sz);
+
+ data = PQgetvalue (result, row, col_num);
+ FAIL_IF (NULL == data);
+
+ {
+ struct GNUNET_PQ_ArrayHeader_P *h =
+ (struct GNUNET_PQ_ArrayHeader_P *) data;
+
+ header.ndim = ntohl (h->ndim);
+ header.has_null = ntohl (h->has_null);
+ header.oid = ntohl (h->oid);
+ header.dim = ntohl (h->dim);
+ header.lbound = ntohl (h->lbound);
+
+ FAIL_IF (1 != header.ndim);
+ FAIL_IF (INT_MAX <= header.dim);
+ FAIL_IF (0 != header.has_null);
+ FAIL_IF (1 != header.lbound);
+ FAIL_IF (info->oid != header.oid);
+ }
+
+ if (NULL != info->num)
+ *info->num = header.dim;
+
+ {
+ char *in = data + sizeof(header);
+
+ switch (info->typ)
+ {
+ case TALER_PQ_array_of_amount:
+ {
+ struct TALER_Amount *amounts;
+ if (NULL != dst_size)
+ *dst_size = sizeof(struct TALER_Amount) * (header.dim);
+
+ amounts = GNUNET_new_array (header.dim,
+ struct TALER_Amount);
+ *((void **) dst) = amounts;
+
+ for (uint32_t i = 0; i < header.dim; i++)
+ {
+ struct TALER_PQ_AmountP ap;
+ struct TALER_Amount *amount = &amounts[i];
+ uint32_t val;
+ size_t sz;
+
+ GNUNET_memcpy (&val,
+ in,
+ sizeof(val));
+ sz = ntohl (val);
+ in += sizeof(val);
+
+ /* total size for this array-entry */
+ FAIL_IF (sizeof(ap) != sz);
+
+ GNUNET_memcpy (&ap,
+ in,
+ sz);
+ FAIL_IF (2 != ntohl (ap.cnt));
+
+ amount->value = GNUNET_ntohll (ap.v);
+ amount->fraction = ntohl (ap.f);
+ GNUNET_memcpy (amount->currency,
+ info->currency,
+ TALER_CURRENCY_LEN);
+
+ in += sizeof(struct TALER_PQ_AmountP);
+ }
+ return GNUNET_OK;
+ }
+ case TALER_PQ_array_of_denom_hash:
+ if (NULL != dst_size)
+ *dst_size = sizeof(struct TALER_DenominationHashP) * (header.dim);
+ out = GNUNET_new_array (header.dim,
+ struct TALER_DenominationHashP);
+ *((void **) dst) = out;
+ for (uint32_t i = 0; i < header.dim; i++)
+ {
+ uint32_t val;
+ size_t sz;
+
+ GNUNET_memcpy (&val,
+ in,
+ sizeof(val));
+ sz = ntohl (val);
+ FAIL_IF (sz != sizeof(struct TALER_DenominationHashP));
+ in += sizeof(uint32_t);
+ *(struct TALER_DenominationHashP *) out =
+ *(struct TALER_DenominationHashP *) in;
+ in += sz;
+ out += sz;
+ }
+ return GNUNET_OK;
+
+ case TALER_PQ_array_of_hash_code:
+ if (NULL != dst_size)
+ *dst_size = sizeof(struct GNUNET_HashCode) * (header.dim);
+ out = GNUNET_new_array (header.dim,
+ struct GNUNET_HashCode);
+ *((void **) dst) = out;
+ for (uint32_t i = 0; i < header.dim; i++)
+ {
+ uint32_t val;
+ size_t sz;
+
+ GNUNET_memcpy (&val,
+ in,
+ sizeof(val));
+ sz = ntohl (val);
+ FAIL_IF (sz != sizeof(struct GNUNET_HashCode));
+ in += sizeof(uint32_t);
+ *(struct GNUNET_HashCode *) out =
+ *(struct GNUNET_HashCode *) in;
+ in += sz;
+ out += sz;
+ }
+ return GNUNET_OK;
+
+ case TALER_PQ_array_of_blinded_coin_hash:
+ if (NULL != dst_size)
+ *dst_size = sizeof(struct TALER_BlindedCoinHashP) * (header.dim);
+ out = GNUNET_new_array (header.dim,
+ struct TALER_BlindedCoinHashP);
+ *((void **) dst) = out;
+ for (uint32_t i = 0; i < header.dim; i++)
+ {
+ uint32_t val;
+ size_t sz;
+
+ GNUNET_memcpy (&val,
+ in,
+ sizeof(val));
+ sz = ntohl (val);
+ FAIL_IF (sz != sizeof(struct TALER_BlindedCoinHashP));
+ in += sizeof(uint32_t);
+ *(struct TALER_BlindedCoinHashP *) out =
+ *(struct TALER_BlindedCoinHashP *) in;
+ in += sz;
+ out += sz;
+ }
+ return GNUNET_OK;
+
+ case TALER_PQ_array_of_blinded_denom_sig:
+ {
+ struct TALER_BlindedDenominationSignature *denom_sigs;
+ if (0 == header.dim)
+ {
+ if (NULL != dst_size)
+ *dst_size = 0;
+ break;
+ }
+
+ denom_sigs = GNUNET_new_array (header.dim,
+ struct TALER_BlindedDenominationSignature);
+ *((void **) dst) = denom_sigs;
+
+ /* copy data */
+ for (uint32_t i = 0; i < header.dim; i++)
+ {
+ struct TALER_BlindedDenominationSignature *denom_sig = &denom_sigs[i];
+ struct GNUNET_CRYPTO_BlindedSignature *bs;
+ uint32_t be[2];
+ uint32_t val;
+ size_t sz;
+
+ GNUNET_memcpy (&val,
+ in,
+ sizeof(val));
+ sz = ntohl (val);
+ FAIL_IF (sizeof(be) > sz);
+
+ in += sizeof(val);
+ GNUNET_memcpy (&be,
+ in,
+ sizeof(be));
+ FAIL_IF (0x01 != ntohl (be[1])); /* magic marker: blinded */
+
+ in += sizeof(be);
+ sz -= sizeof(be);
+ bs = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ bs->cipher = ntohl (be[0]);
+ bs->rc = 1;
+ switch (bs->cipher)
+ {
+ case GNUNET_CRYPTO_BSA_RSA:
+ bs->details.blinded_rsa_signature
+ = GNUNET_CRYPTO_rsa_signature_decode (in,
+ sz);
+ if (NULL == bs->details.blinded_rsa_signature)
+ {
+ GNUNET_free (bs);
+ FAIL_IF (true);
+ }
+ break;
+ case GNUNET_CRYPTO_BSA_CS:
+ if (sizeof(bs->details.blinded_cs_answer) != sz)
+ {
+ GNUNET_free (bs);
+ FAIL_IF (true);
+ }
+ GNUNET_memcpy (&bs->details.blinded_cs_answer,
+ in,
+ sz);
+ break;
+ default:
+ GNUNET_free (bs);
+ FAIL_IF (true);
+ }
+ denom_sig->blinded_sig = bs;
+ in += sz;
+ }
+ return GNUNET_OK;
+ }
+ default:
+ FAIL_IF (true);
+ }
+ }
+FAIL:
+ GNUNET_free (*(void **) dst);
+ return GNUNET_SYSERR;
+#undef FAIL_IF
+}
+
+
+/**
+ * Cleanup of the data and closure of an array spec.
+ */
+static void
+array_cleanup (void *cls,
+ void *rd)
+{
+ struct ArrayResultCls *info = cls;
+ void **dst = rd;
+
+ if ((0 == info->same_size) &&
+ (NULL != info->sizes))
+ GNUNET_free (*(info->sizes));
+
+ /* Clean up signatures, if applicable */
+ if (TALER_PQ_array_of_blinded_denom_sig == info->typ)
+ {
+ struct TALER_BlindedDenominationSignature *denom_sigs = *dst;
+ GNUNET_assert (NULL != info->num);
+ for (size_t i = 0; i < *info->num; i++)
+ GNUNET_free (denom_sigs[i].blinded_sig);
+ }
+
+ GNUNET_free (cls);
+ GNUNET_free (*dst);
+ *dst = NULL;
+}
+
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_blinded_denom_sig (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_BlindedDenominationSignature **denom_sigs)
+{
+ struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+ info->num = num;
+ info->typ = TALER_PQ_array_of_blinded_denom_sig;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
+
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = extract_array_generic,
+ .cleaner = array_cleanup,
+ .dst = (void *) denom_sigs,
+ .fname = name,
+ .cls = info
+ };
+ return res;
+
+};
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_blinded_coin_hash (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_BlindedCoinHashP **h_coin_evs)
+{
+ struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+ info->num = num;
+ info->typ = TALER_PQ_array_of_blinded_coin_hash;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
+
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = extract_array_generic,
+ .cleaner = array_cleanup,
+ .dst = (void *) h_coin_evs,
+ .fname = name,
+ .cls = info
+ };
+ return res;
+
+};
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_denom_hash (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct TALER_DenominationHashP **denom_hs)
+{
+ struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+ info->num = num;
+ info->typ = TALER_PQ_array_of_denom_hash;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "bytea",
+ &info->oid));
+
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = extract_array_generic,
+ .cleaner = array_cleanup,
+ .dst = (void *) denom_hs,
+ .fname = name,
+ .cls = info
+ };
+ return res;
+
+};
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_amount (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ const char *currency,
+ size_t *num,
+ struct TALER_Amount **amounts)
+{
+ struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+ info->num = num;
+ info->typ = TALER_PQ_array_of_amount;
+ info->db = db;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "taler_amount",
+ &info->oid));
+
+ {
+ size_t clen = GNUNET_MIN (TALER_CURRENCY_LEN - 1,
+ strlen (currency));
+ GNUNET_memcpy (&info->currency,
+ currency,
+ clen);
+ }
+
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = extract_array_generic,
+ .cleaner = array_cleanup,
+ .dst = (void *) amounts,
+ .fname = name,
+ .cls = info,
+ };
+ return res;
+}
+
+
+struct GNUNET_PQ_ResultSpec
+TALER_PQ_result_spec_array_hash_code (
+ struct GNUNET_PQ_Context *db,
+ const char *name,
+ size_t *num,
+ struct GNUNET_HashCode **hashes)
+{
+ struct ArrayResultCls *info = GNUNET_new (struct ArrayResultCls);
+
+ info->num = num;
+ info->typ = TALER_PQ_array_of_hash_code;
+ info->db = db;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_PQ_get_oid_by_name (db,
+ "gnunet_hashcode",
+ &info->oid));
+
+ struct GNUNET_PQ_ResultSpec res = {
+ .conv = extract_array_generic,
+ .cleaner = array_cleanup,
+ .dst = (void *) hashes,
+ .fname = name,
+ .cls = info,
+ };
+ return res;
+}
+
/* end of pq_result_helper.c */
diff --git a/src/pq/test_pq.c b/src/pq/test_pq.c
index 52e92b561..0fd2bfddf 100644
--- a/src/pq/test_pq.c
+++ b/src/pq/test_pq.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2015, 2016 Taler Systems SA
+ (C) 2015, 2016, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,6 +21,7 @@
#include "platform.h"
#include "taler_util.h"
#include "taler_pq_lib.h"
+#include <gnunet/gnunet_pq_lib.h>
/**
@@ -29,29 +30,29 @@
* @param db database handle to initialize
* @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
*/
-static int
+static enum GNUNET_GenericReturnValue
postgres_prepare (struct GNUNET_PQ_Context *db)
{
struct GNUNET_PQ_PreparedStatement ps[] = {
GNUNET_PQ_make_prepare ("test_insert",
"INSERT INTO test_pq ("
- " hamount_val"
- ",hamount_frac"
- ",namount_val"
- ",namount_frac"
+ " tamount"
",json"
+ ",aamount"
+ ",tamountc"
+ ",hash"
+ ",hashes"
") VALUES "
- "($1, $2, $3, $4, $5);",
- 5),
+ "($1, $2, $3, $4, $5, $6);"),
GNUNET_PQ_make_prepare ("test_select",
"SELECT"
- " hamount_val"
- ",hamount_frac"
- ",namount_val"
- ",namount_frac"
+ " tamount"
",json"
- " FROM test_pq;",
- 0),
+ ",aamount"
+ ",tamountc"
+ ",hash"
+ ",hashes"
+ " FROM test_pq;"),
GNUNET_PQ_PREPARED_STATEMENT_END
};
@@ -68,33 +69,64 @@ postgres_prepare (struct GNUNET_PQ_Context *db)
static int
run_queries (struct GNUNET_PQ_Context *conn)
{
- struct TALER_Amount hamount;
- struct TALER_Amount hamount2;
- struct TALER_AmountNBO namount;
- struct TALER_AmountNBO namount2;
- PGresult *result;
- int ret;
+ struct TALER_Amount tamount;
+ struct TALER_Amount aamount[3];
+ struct TALER_Amount tamountc;
+ struct GNUNET_HashCode hc =
+ {{0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+ 0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+ 0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef,
+ 0xdeadbeef,0xdeadbeef,0xdeadbeef,0xdeadbeef, }};
+ struct GNUNET_HashCode hcs[2] =
+ {{{0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+ 0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+ 0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,
+ 0xc0feec0f,0xc0feec0f,0xc0feec0f,0xc0feec0f,}},
+ {{0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+ 0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+ 0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,
+ 0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,0xdeadbeaf,}}};
json_t *json;
- json_t *json2;
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount ("EUR:5.5",
- &hamount));
- TALER_amount_hton (&namount,
- &hamount);
+ TALER_string_to_amount ("EUR:5.3",
+ &aamount[0]));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:6.4",
+ &aamount[1]));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("EUR:7.5",
+ &aamount[2]));
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount ("EUR:4.4",
- &hamount));
+ TALER_string_to_amount ("EUR:7.7",
+ &tamount));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount ("FOO:8.7",
+ &tamountc));
json = json_object ();
- json_object_set_new (json, "foo", json_integer (42));
GNUNET_assert (NULL != json);
+ GNUNET_assert (0 ==
+ json_object_set_new (json,
+ "foo",
+ json_integer (42)));
{
struct GNUNET_PQ_QueryParam params_insert[] = {
- TALER_PQ_query_param_amount (&hamount),
- TALER_PQ_query_param_amount_nbo (&namount),
+ TALER_PQ_query_param_amount (conn,
+ &tamount),
TALER_PQ_query_param_json (json),
+ TALER_PQ_query_param_array_amount (3,
+ aamount,
+ conn),
+ TALER_PQ_query_param_amount_with_currency (conn,
+ &tamountc),
+ GNUNET_PQ_query_param_fixed_size (&hc,
+ sizeof (hc)),
+ TALER_PQ_query_param_array_hash_code (2,
+ hcs,
+ conn),
GNUNET_PQ_query_param_end
};
+ PGresult *result;
result = GNUNET_PQ_exec_prepared (conn,
"test_insert",
@@ -108,55 +140,76 @@ run_queries (struct GNUNET_PQ_Context *conn)
return 1;
}
PQclear (result);
+ json_decref (json);
}
{
+ struct TALER_Amount tamount2;
+ struct TALER_Amount tamountc2;
+ struct TALER_Amount *pamount;
+ struct GNUNET_HashCode hc2;
+ struct GNUNET_HashCode *hcs2;
+ size_t npamount;
+ size_t nhcs;
+ json_t *json2;
struct GNUNET_PQ_QueryParam params_select[] = {
GNUNET_PQ_query_param_end
};
+ struct GNUNET_PQ_ResultSpec results_select[] = {
+ TALER_PQ_result_spec_amount ("tamount",
+ "EUR",
+ &tamount2),
+ TALER_PQ_result_spec_json ("json",
+ &json2),
+ TALER_PQ_result_spec_array_amount (conn,
+ "aamount",
+ "EUR",
+ &npamount,
+ &pamount),
+ TALER_PQ_result_spec_amount_with_currency ("tamountc",
+ &tamountc2),
+ GNUNET_PQ_result_spec_auto_from_type ("hash",
+ &hc2),
+ TALER_PQ_result_spec_array_hash_code (conn,
+ "hashes",
+ &nhcs,
+ &hcs2),
+ GNUNET_PQ_result_spec_end
+ };
- result = GNUNET_PQ_exec_prepared (conn,
- "test_select",
- params_select);
if (1 !=
- PQntuples (result))
+ GNUNET_PQ_eval_prepared_singleton_select (conn,
+ "test_select",
+ params_select,
+ results_select))
{
GNUNET_break (0);
- PQclear (result);
return 1;
}
- }
-
- {
- struct GNUNET_PQ_ResultSpec results_select[] = {
- TALER_PQ_result_spec_amount ("hamount", "EUR", &hamount2),
- TALER_PQ_result_spec_amount_nbo ("namount", "EUR", &namount2),
- TALER_PQ_result_spec_json ("json", &json2),
- GNUNET_PQ_result_spec_end
- };
-
- ret = GNUNET_PQ_extract_result (result,
- results_select,
- 0);
- GNUNET_break (0 ==
- TALER_amount_cmp (&hamount,
- &hamount2));
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount ("EUR:5.5",
- &hamount));
- TALER_amount_ntoh (&hamount2,
- &namount2);
GNUNET_break (0 ==
- TALER_amount_cmp (&hamount,
- &hamount2));
+ TALER_amount_cmp (&tamount,
+ &tamount2));
GNUNET_break (42 ==
- json_integer_value (json_object_get (json2, "foo")));
+ json_integer_value (json_object_get (json2,
+ "foo")));
+ GNUNET_break (3 == npamount);
+ for (size_t i = 0; i < 3; i++)
+ {
+ GNUNET_break (0 ==
+ TALER_amount_cmp (&aamount[i],
+ &pamount[i]));
+ }
+ GNUNET_break (0 ==
+ TALER_amount_cmp (&tamountc,
+ &tamountc2));
+ GNUNET_break (0 == GNUNET_memcmp (&hc,&hc2));
+ for (size_t i = 0; i < 2; i++)
+ {
+ GNUNET_break (0 ==
+ GNUNET_memcmp (&hcs[i],
+ &hcs2[i]));
+ }
GNUNET_PQ_cleanup_result (results_select);
- PQclear (result);
}
- json_decref (json);
- if (GNUNET_OK != ret)
- return 1;
-
return 0;
}
@@ -166,12 +219,37 @@ main (int argc,
const char *const argv[])
{
struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_execute ("DO $$ "
+ " BEGIN"
+ " CREATE DOMAIN gnunet_hashcode AS BYTEA"
+ " CHECK(length(VALUE)=64);"
+ " EXCEPTION"
+ " WHEN duplicate_object THEN null;"
+ " END "
+ "$$;"),
+ GNUNET_PQ_make_execute ("DO $$ "
+ " BEGIN"
+ " CREATE TYPE taler_amount AS"
+ " (val INT8, frac INT4);"
+ " EXCEPTION"
+ " WHEN duplicate_object THEN null;"
+ " END "
+ "$$;"),
+ GNUNET_PQ_make_execute ("DO $$ "
+ " BEGIN"
+ " CREATE TYPE taler_amount_currency AS"
+ " (val INT8, frac INT4, curr VARCHAR(12));"
+ " EXCEPTION"
+ " WHEN duplicate_object THEN null;"
+ " END "
+ "$$;"),
GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS test_pq ("
- " hamount_val INT8 NOT NULL"
- ",hamount_frac INT4 NOT NULL"
- ",namount_val INT8 NOT NULL"
- ",namount_frac INT4 NOT NULL"
+ " tamount taler_amount NOT NULL"
",json VARCHAR NOT NULL"
+ ",aamount taler_amount[]"
+ ",tamountc taler_amount_currency"
+ ",hash gnunet_hashcode"
+ ",hashes gnunet_hashcode[]"
")"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
@@ -196,6 +274,7 @@ main (int argc,
GNUNET_PQ_disconnect (conn);
return 1;
}
+
ret = run_queries (conn);
{
struct GNUNET_PQ_ExecuteStatement ds[] = {
diff --git a/src/sq/sq_query_helper.c b/src/sq/sq_query_helper.c
index d4b2d060d..711e63816 100644
--- a/src/sq/sq_query_helper.c
+++ b/src/sq/sq_query_helper.c
@@ -150,7 +150,7 @@ qconv_json (void *cls,
if (SQLITE_OK != sqlite3_bind_text (stmt,
(int) off,
str,
- strlen (str) + 1,
+ strlen (str),
SQLITE_TRANSIENT))
return GNUNET_SYSERR;
GNUNET_free (str);
diff --git a/src/sq/sq_result_helper.c b/src/sq/sq_result_helper.c
index bacb7743a..9d80837bd 100644
--- a/src/sq/sq_result_helper.c
+++ b/src/sq/sq_result_helper.c
@@ -23,7 +23,7 @@
#include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_sq_lib.h>
#include "taler_sq_lib.h"
-#include "taler_amount_lib.h"
+#include "taler_util.h"
/**
diff --git a/src/sq/test_sq.c b/src/sq/test_sq.c
index 5f715ad6c..8f464faf3 100644
--- a/src/sq/test_sq.c
+++ b/src/sq/test_sq.c
@@ -63,7 +63,11 @@ run_queries (sqlite3 *db)
TALER_amount_hton (&namount,
&hamount);
json = json_object ();
- json_object_set_new (json, "foo", json_integer (42));
+ GNUNET_assert (NULL != json);
+ GNUNET_assert (0 ==
+ json_object_set_new (json,
+ "foo",
+ json_integer (42)));
GNUNET_assert (NULL != json);
GNUNET_assert (GNUNET_OK ==
GNUNET_SQ_prepare (db,
@@ -152,6 +156,8 @@ main (int argc,
sqlite3 *db;
int ret;
+ (void) argc;
+ (void) argv;
GNUNET_log_setup ("test-pq",
"WARNING",
NULL);
diff --git a/src/templating/.gitignore b/src/templating/.gitignore
new file mode 100644
index 000000000..9ed2f3ff9
--- /dev/null
+++ b/src/templating/.gitignore
@@ -0,0 +1,3 @@
+test_mustach_jansson
+taler-mustach-tool
+mustach
diff --git a/src/templating/AUTHORS b/src/templating/AUTHORS
new file mode 100644
index 000000000..110b36981
--- /dev/null
+++ b/src/templating/AUTHORS
@@ -0,0 +1,38 @@
+Main author:
+ José Bollo <jobol@nonadev.net>
+
+Contributors:
+ Abhishek Mishra
+ Atlas
+ Ben Beasley
+ Christian Grothoff
+ Dominik Kummer
+ Gabriel Zachmann
+ Harold L Marzan
+ Kurt Jung
+ Lailton Fernando Mariano
+ Lucas Ramage
+ Paramtamtam
+ RekGRpth
+ Ryan Fox
+ Sami Kerola
+ Sijmen J. Mulder
+ Steve-Chavez
+ Tomasz Sieprawski
+
+Packagers:
+ pkgsrc: Sijmen J. Mulder
+ alpine linux: Lucas Ramage
+ RPM & DEB: Marcus Hardt
+
+Thanks to issue submitters:
+ Dante Torres
+ @fabbe
+ Felix von Leitner
+ Johann Oskarsson
+ Mark Bucciarelli
+ Nigel Hathaway
+ Paul Wisehart
+ Tarik @tr001
+ Thierry Fournier
+ SASU OKFT
diff --git a/src/templating/CHANGELOG.md b/src/templating/CHANGELOG.md
new file mode 100644
index 000000000..003652ebf
--- /dev/null
+++ b/src/templating/CHANGELOG.md
@@ -0,0 +1,161 @@
+1.2.7 (2024-03-21)
+------------------
+
+New:
+ - fallback to default when mustach_wrap_get_partial
+ returns MUSTACH_ERROR_PARTIAL_NOT_FOUND
+ - remove at compile time the load of files for templates
+ if MUSTACH_LOAD_TEMPLATE is defined as 0
+ - add compile time flag MUSTACH_SAFE for enforcing
+ safety behaviours
+
+Fix:
+ - selection of subitem by index (#47)
+ - get latest iterated key when getting key name (#52)
+ - allow tests without valgrind
+ - avoid recursive template expansion (#55)
+
+1.2.6 (2024-01-08)
+------------------
+
+Fix:
+ - improve naming (#42)
+ - magical spaces in recursive partials (#43)
+ - installation when tool isn't built
+ - correct detection of falsey values (#45)
+
+Minor:
+ - update to newer reference tests
+
+1.2.5 (2023-02-18)
+------------------
+
+Fix:
+ - Don't override CFLAGS in Makefile
+ - Use of $(INSTALL) in Makefile for setting options
+
+Minor:
+ - Orthograf of 'instantiate'
+
+1.2.4 (2023-01-02)
+------------------
+
+Fix:
+ - Latent SIGSEGV using cJSON
+
+1.2.3 (2022-12-21)
+------------------
+
+New:
+ - Flag Mustach_With_ErrorUndefined (and option --strict for the tool)
+ for returning a requested tag is not defined
+ - Test of specifications in separate directory
+
+Fix:
+ - Version printing is now okay
+ - Compiling libraries on Darwin (no soname but install_name)
+ - Compiling test6 with correct flags
+ - Update test from specifications
+ - Better use of valgrind reports
+
+1.2.2 (2021-10-28)
+------------------
+
+Fix:
+ - SONAME of libmustach-json-c.so
+
+1.2.1 (2021-10-19)
+------------------
+
+New:
+ - Add SONAME in libraries.
+ - Flag Mustach_With_PartialDataFirst to switch the
+ policy of resolving partials.
+
+Fix:
+ - Identification of types in cJSON
+
+1.2.0 (2021-08-24)
+------------------
+
+New:
+ - Add hook 'mustach_wrap_get_partial' for handling partials.
+ - Add test of mustache specifications https://github.com/mustache/spec.
+
+Changes:
+ - Mustach_With_SingleDot is always set.
+ - Mustach_With_IncPartial is always set.
+ - Mustach_With_AllExtensions is changed to use currently known extensions.
+ - Output of tests changed.
+ - Makefile improved.
+ - Partials are first searched as file then in current selection.
+ - Improved management of delimiters.
+
+Fixes:
+ - Improved output accordingly to https://github.com/mustache/spec:
+ - escaping of quote "
+ - interpolating null with empty string
+ - removal of empty lines with standalone tag
+ - don't enter section if null
+ - indentation of partials
+ - comment improved for get of mustach_wrap_itf.
+
+1.1.1 (2021-08-19)
+------------------
+Fixes:
+ - Avoid conflicting with getopt.
+ - Remove unexpected build artifact.
+ - Handle correctly a size of 0.
+
+1.1.0 (2021-05-01)
+------------------
+New:
+ - API refactored to take lengths to ease working with partial or
+ non-NULL-terminated strings. (ABI break)
+
+Fixes:
+ - Use correct int type for jansson (json_int_t instead of int64_t).
+ - JSON output of different backends is now the same.
+
+1.0 (2021-04-28, retracted)
+---------------------------
+Legal:
+ - License changed to ISC.
+
+Fixes:
+ - Possible data leak in memfile_open() by clearing buffers.
+ - Fix build on Solaris-likes by including alloca.h.
+ - Fix Windows build by including malloc.h, using size_t instead of
+ ssize_t, and using the standard ternary operator syntax.
+ - Fix JSON in test3 by using double quote characters.
+ - Fix installation in alternative directories such as
+ /opt/pkg/lib on macOS by setting install_name.
+ - Normalise return values in compare() implementations.
+
+New:
+ - Support for cJSON and jansson libraries.
+ - Version info now embedded at build time and shown with mustach(1)
+ usage.
+ - Versioned so-names (e.g. libxlsx.so.1.0).
+ - BINDIR, LIBDIR and INCLUDEDIR variables in Makefile.
+ - New mustach-wrap.{c,h} to ease implementation new libraries,
+ extracted and refactored from the existing implementations.
+ - Makefile now supports 3 modes: single libmustach (default), split
+ libmustache-core etc, and both.
+ - Any or all backends (json-c, jansson, etc) can be enabled at compile
+ time. By default, all available libraries are used.
+ - mustach(1) can use any JSON backend instead of only json-c.
+ - MUSTACH_COMPATIBLE_0_99 can be defined for backwards source
+ compatibility.
+ - 'No extensions' can now be set Mustach_With_NoExtensions instead of
+ passing 0.
+ - pkgconfig (.pc) file for library.
+ - Manual page for mustach(1).
+
+Changed:
+ - Many renames.
+ - Maximum tag length increased from 1024 to 4096.
+ - Other headers include json-c.h instead of using forward declarations.
+ - mustach(1) reads from /dev/stdin instead of fd 0.
+ - Several structures are now taken as const.
+ - New/changed Makefile targets.
diff --git a/src/templating/LICENSE.txt b/src/templating/LICENSE.txt
new file mode 100644
index 000000000..495aeefd5
--- /dev/null
+++ b/src/templating/LICENSE.txt
@@ -0,0 +1,14 @@
+
+Copyright (c) 2017-2020 by José Bollo
+
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
+OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
diff --git a/src/templating/Makefile.am b/src/templating/Makefile.am
new file mode 100644
index 000000000..a79b109d1
--- /dev/null
+++ b/src/templating/Makefile.am
@@ -0,0 +1,132 @@
+# This Makefile.am is in the public domain
+AM_CPPFLAGS = -I$(top_srcdir)/src/include $(LIBGCRYPT_CFLAGS)
+
+if USE_COVERAGE
+ AM_CFLAGS = --coverage -O0
+ XLIB = -lgcov
+endif
+
+noinst_PROGRAMS = \
+ taler-mustach-tool
+
+taler_mustach_tool_SOURCES = \
+ mustach-tool.c \
+ mustach-jansson.h
+taler_mustach_tool_LDADD = \
+ libmustach.la \
+ -ljansson
+taler_mustach_tool_CFLAGS = \
+ -DTOOL=MUSTACH_TOOL_JANSSON \
+ -DMUSTACH_SAFE=1 \
+ -DMUSTACH_LOAD_TEMPLATE=0
+
+lib_LTLIBRARIES = \
+ libtalertemplating.la
+
+noinst_LTLIBRARIES = \
+ libmustach.la
+
+libtalertemplating_la_SOURCES = \
+ mustach.c mustach.h \
+ mustach-wrap.c mustach-wrap.h \
+ mustach-jansson.c mustach-jansson.h \
+ templating_api.c
+libtalertemplating_la_LIBADD = \
+ $(top_builddir)/src/mhd/libtalermhd.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ -lmicrohttpd \
+ -lgnunetjson \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
+libtalertemplating_la_LDFLAGS = \
+ -version-info 0:0:0 \
+ -no-undefined
+libtalertemplating_la_CFLAGS = \
+ -DMUSTACH_SAFE=1 \
+ -DMUSTACH_LOAD_TEMPLATE=0
+
+libmustach_la_SOURCES = \
+ mustach.c mustach.h \
+ mustach-wrap.c mustach-wrap.h \
+ mustach-jansson.c mustach-jansson.h
+
+test_mustach_jansson_SOURCES = \
+ test_mustach_jansson.c
+test_mustach_jansson_LDADD = \
+ -lgnunetutil \
+ -ljansson \
+ -lmustach \
+ $(XLIB)
+
+check_PROGRAMS = \
+ test_mustach_jansson
+
+TESTS = $(check_PROGRAMS)
+
+EXTRA_DIST = \
+ $(check_SCRIPTS) \
+ mustach-original-Makefile \
+ mustach.1.gz \
+ mustach.1.scd \
+ meson.build \
+ LICENSE.txt \
+ ORIGIN \
+ pkgcfgs \
+ README.md \
+ dotest.sh \
+ AUTHORS \
+ CHANGELOG.md \
+ mustach-json-c.h \
+ mustach-json-c.c \
+ mustach-cjson.h \
+ mustach-cjson.c \
+ test1/json \
+ test1/Makefile \
+ test1/must \
+ test1/resu.ref \
+ test1/vg.ref \
+ test2/json \
+ test2/Makefile \
+ test2/must \
+ test2/resu.ref \
+ test2/vg.ref \
+ test3/json \
+ test3/Makefile \
+ test3/must \
+ test3/resu.ref \
+ test3/vg.ref \
+ test4/json \
+ test4/Makefile \
+ test4/must \
+ test4/resu.ref \
+ test4/vg.ref \
+ test5/json \
+ test5/Makefile \
+ test5/must \
+ test5/must2 \
+ test5/must2.mustache \
+ test5/must3.mustache \
+ test5/resu.ref \
+ test5/vg.ref \
+ test6/json \
+ test6/Makefile \
+ test6/must \
+ test6/resu.ref \
+ test6/test-custom-write.c \
+ test6/vg.ref \
+ test7/base.mustache \
+ test7/json \
+ test7/Makefile \
+ test7/node.mustache \
+ test7/resu.ref \
+ test7/vg.ref \
+ test8/json \
+ test8/Makefile \
+ test8/must \
+ test8/resu.ref \
+ test8/vg.ref \
+ test-specs/test-specs.c \
+ test-specs/test-specs-cjson.ref \
+ test-specs/test-specs-jansson.ref \
+ test-specs/test-specs-json-c.ref
diff --git a/src/templating/ORIGIN b/src/templating/ORIGIN
new file mode 100644
index 000000000..14902983a
--- /dev/null
+++ b/src/templating/ORIGIN
@@ -0,0 +1,11 @@
+Cloned originally from https://gitlab.com/jobol/mustach/
+
+Changes:
+========
+
+Renamed original Makefile to mustach-original-Makefile
+and wrote Makefile.am for us.
+
+Added run-original-tests.sh shell script as a wrapper around
+mustach-original-Makefile to use the original build process for the test
+suite.
diff --git a/src/templating/README.md b/src/templating/README.md
new file mode 100644
index 000000000..6e7a6c956
--- /dev/null
+++ b/src/templating/README.md
@@ -0,0 +1,320 @@
+# Introduction to Mustach 1.2
+
+`mustach` is a C implementation of the [mustache](http://mustache.github.io "main site for mustache")
+template specification.
+
+The main site for `mustach` is on [gitlab](https://gitlab.com/jobol/mustach).
+
+The simplest way to use mustach is to copy the files **mustach.h** and **mustach.c**
+directly into your project and use it.
+
+If you are using one of the JSON libraries listed below, you can get extended feature
+by also including **mustach-wrap.h**, **mustach-wrap.c**, **mustach-XXX.h** and
+**mustach-XXX.c** in your project (see below for **XXX**)
+
+- [json-c](https://github.com/json-c/json-c): use **XXX** = **json-c**
+- [jansson](http://www.digip.org/jansson/): use **XXX** = **jansson**
+- [cJSON](https://github.com/DaveGamble/cJSON): use **XXX** = **cjson**
+
+Alternatively, make and meson files are provided for building `mustach` and
+`libmustach.so` shared library.
+
+Since version 1.0, the makefile allows to compile and install different
+flavours. See below for details.
+
+## Distributions offering mustach package
+
+### Alpine Linux
+
+```sh
+apk add mustach
+apk add mustach-lib
+apk add mustach-dev
+```
+
+### NetBSD
+
+```sh
+cd devel/mustach
+make
+```
+
+See http://pkgsrc.se/devel/mustach
+
+## Known projects using Mustach
+
+This [wiki page](https://gitlab.com/jobol/mustach/-/wikis/projects-using-mustach)
+lists the known project that are using mustach and that kindly told it.
+
+Don't hesitate to tell us if you are interested to be listed there.
+
+## Using Mustach from sources
+
+The file **mustach.h** is the main documentation. Look at it.
+
+The current source files are:
+
+- **mustach.c** core implementation of mustache in C
+- **mustach.h** header file for core definitions
+- **mustach-wrap.c** generic wrapper of mustach for easier integration
+- **mustach-wrap.h** header file for using mustach-wrap
+- **mustach-json-c.c** tiny json wrapper of mustach using [json-c](https://github.com/json-c/json-c)
+- **mustach-json-c.h** header file for using the tiny json-c wrapper
+- **mustach-cjson.c** tiny json wrapper of mustach using [cJSON](https://github.com/DaveGamble/cJSON)
+- **mustach-cjson.h** header file for using the tiny cJSON wrapper
+- **mustach-jansson.c** tiny json wrapper of mustach using [jansson](https://www.digip.org/jansson/)
+- **mustach-jansson.h** header file for using the tiny jansson wrapper
+- **mustach-tool.c** simple tool for applying template files to one JSON file
+
+The file **mustach-json-c.c** is the historical example of use of **mustach** and
+**mustach-wrap** core and it is also a practical implementation that can be used.
+It uses the library json-c. (NOTE for Mac OS: available through homebrew).
+
+Since version 1.0, the project also provide integration of other JSON libraries:
+**cJSON** and **jansson**.
+
+*If you integrate a new library with* **mustach**, *your contribution will be
+welcome here*.
+
+The tool **mustach** is build using `make`, its usage is:
+
+ mustach json template [template]...
+
+It then outputs the result of applying the templates files to the JSON file.
+
+### Portability
+
+Some system does not provide *open_memstream*. In that case, tell your
+preferred compiler to declare the preprocessor symbol **NO_OPEN_MEMSTREAM**.
+Example:
+
+ CFLAGS=-DNO_OPEN_MEMSTREAM make
+
+### Integration
+
+The files **mustach.h** and **mustach-wrap.h** are the main documentation. Look at it.
+
+The file **mustach-json-c.c** provides a good example of integration.
+
+If you intend to use basic HTML/XML escaping and standard C FILE, the callbacks
+of the interface **mustach_itf** that you have to implement are:
+`enter`, `next`, `leave`, `get`.
+
+If you intend to use specific escaping and/or specific output, the callbacks
+of the interface **mustach_itf** that you have to implement are:
+`enter`, `next`, `leave`, `get` and `emit`.
+
+### Compilation Using Make
+
+Building and installing can be done using make.
+
+Example:
+
+ $ make tool=cjson libs=none PREFIX=/usr/local DESTDIR=/ install
+ $ make tool=jsonc libs=single PREFIX=/ DESTDIR=$HOME/.local install
+
+The makefile knows following switches (\*: default):
+
+ Switch name | Values | Description
+ --------------+---------+-----------------------------------------------
+ jsonc | (unset) | Auto detection of json-c
+ | no | Don't compile for json-c
+ | yes | Compile for json-c that must exist
+ --------------+---------+-----------------------------------------------
+ cjson | (unset) | Auto detection of cJSON
+ | no | Don't compile for cJSON
+ | yes | Compile for cJSON that must exist
+ --------------+---------+-----------------------------------------------
+ jansson | (unset) | Auto detection of jansson
+ | no | Don't compile for jansson
+ | yes | Compile for jansson that must exist
+ --------------+---------+-----------------------------------------------
+ tool | (unset) | Auto detection
+ | cjson | Use cjson library
+ | jsonc | Use jsonc library
+ | jansson | Use jansson library
+ | none | Don't compile the tool
+ --------------+---------+----------------------------------------------
+ libs | (unset) | Like 'all'
+ | all | Like 'single' AND 'split'
+ | single | Only libmustach.so
+ | split | All the possible libmustach-XXX.so ...
+ | none | No library is produced
+
+The libraries that can be produced are:
+
+ Library name | Content
+ --------------------+--------------------------------------------------------
+ libmustach-core | mustach.c mustach-wrap.c
+ libmustach-cjson | mustach.c mustach-wrap.c mustach-cjson.c
+ libmustach-jsonc | mustach.c mustach-wrap.c mustach-json-c.c
+ libmustach-jansson | mustach.c mustach-wrap.c mustach-jansson.c
+ libmustach | mustach.c mustach-wrap.c mustach-{cjson,json-c,jansson}.c
+
+There is no dependencies of a library to an other. This is intended and doesn't
+hurt today because the code is small.
+
+### Testing
+
+The makefile offers the way to execute basic tests. Just type `make test`.
+
+By default, if valgrind is available, tests are using it. It can be disabled
+by typing `make test valgrind=no` or `NOVALGRIND=1 make test`.
+
+## Extensions
+
+The current implementation provides extensions to specifications of **mustache**.
+This extensions can be activated or deactivated using flags.
+
+Here is the summary.
+
+ Flag name | Description
+ -------------------------------+------------------------------------------------
+ Mustach_With_Colon | Explicit tag substitution with colon
+ Mustach_With_EmptyTag | Empty Tag Allowed
+ -------------------------------+------------------------------------------------
+ Mustach_With_Equal | Value Testing Equality
+ Mustach_With_Compare | Value Comparing
+ Mustach_With_JsonPointer | Interpret JSON Pointers
+ Mustach_With_ObjectIter | Iteration On Objects
+ Mustach_With_EscFirstCmp | Escape First Compare
+ Mustach_With_ErrorUndefined | Error when a requested tag is undefined
+ -------------------------------+------------------------------------------------
+ Mustach_With_AllExtensions | Activate all known extensions
+ Mustach_With_NoExtensions | Disable any extension
+
+For the details, see below.
+
+### Explicit Tag Substitution With Colon (Mustach_With_Colon)
+
+In somecases the name of the key used for substitution begins with a
+character reserved for mustach: one of `#`, `^`, `/`, `&`, `{`, `>` and `=`.
+
+This extension introduces the special character `:` to explicitly
+tell mustach to just substitute the value. So `:` becomes a new special
+character.
+
+This is a core extension implemented in file **mustach.c**.
+
+### Empty Tag Allowed (Mustach_With_EmptyTag)
+
+When an empty tag is found, instead of automatically raising the error
+MUSTACH\_ERROR\_EMPTY\_TAG pass it.
+
+This is a core extension implemented in file **mustach.c**.
+
+### Value Testing Equality (Mustach_With_Equal)
+
+This extension allows you to test the value of the selected key.
+It allows to write `key=value` (matching test) or `key=!value`
+(not matching test) in any query.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Value Comparing (Mustach_With_Compare)
+
+These extension extends the extension for testing equality to also
+compare values if greater or lesser.
+Its allows to write `key>value` (greater), `key>=value` (greater or equal),
+`key<value` (lesser) and `key<=value` (lesser or equal).
+
+It the comparator sign appears in the first column it is ignored
+as if it was escaped.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Interpret JSON Pointers (Mustach_With_JsonPointer)
+
+This extension allows to use JSON pointers as defined in IETF RFC 6901.
+If active, any key starting with "/" is a JSON pointer.
+This implies to use the colon to introduce JSON keys.
+
+A special escaping is used for `=`, `<`, `>` signs when
+values comparisons are enabled: `~=` gives `=` in the key.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Iteration On Objects (Mustach_With_ObjectIter)
+
+With this extension, using the pattern `{{#X.*}}...{{/X.*}}`
+allows to iterate on fields of `X`.
+
+Example:
+
+- `{{s.*}} {{*}}:{{.}}{{/s.*}}` applied on `{"s":{"a":1,"b":true}}` produces ` a:1 b:true`
+
+Here the single star `{{*}}` is replaced by the iterated key
+and the single dot `{{.}}` is replaced by its value.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Error when a requested tag is undefined (Mustach_With_ErrorUndefined)
+
+Report the error MUSTACH_ERROR_UNDEFINED_TAG when a requested tag
+is not defined.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Access To Current Value
+
+*this was an extension but is now always enforced*
+
+The value of the current field can be accessed using single dot.
+
+Examples:
+
+- `{{#key}}{{.}}{{/key}}` applied to `{"key":3.14}` produces `3.14`
+- `{{#array}} {{.}}{{/array}}` applied to `{"array":[1,2]}` produces ` 1 2`.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Partial Data First
+
+*this was an extension but is now always enforced*
+
+The default resolution for partial pattern like `{{> name}}`
+is to search for `name` in the current json context and
+as a file named `name` or if not found `name.mustache`.
+
+By default, the order of the search is (1) as a file,
+and if not found, (2) in the current json context.
+
+When this option is set, the order is reverted and content
+of partial is search (1) in the current json context,
+and if not found, (2) as a file.
+
+That option is useful to keep the compatibility with
+versions of *mustach* anteriors to 1.2.0.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+### Escape First Compare
+
+This extension automatically escapes comparisons appears as
+first characters.
+
+This is a wrap extension implemented in file **mustach-wrap.c**.
+
+## Difference with version 0.99 and previous
+
+### Extensions
+
+The extensions can no more be removed at compile time, use
+flags to select your required extension on need.
+
+### Name of functions
+
+Names of functions were improved. Old names remain but are obsolete
+and legacy. Their removal in far future versions is possible.
+
+The table below summarize the changes.
+
+ legacy name | name since version 1.0.0
+ ------------------+-----------------------
+ fmustach | mustach_file
+ fdmustach | mustach_fd
+ mustach | mustach_mem
+ fmustach_json_c | mustach_json_c_file
+ fdmustach_json_c | mustach_json_c_fd
+ mustach_json_c | mustach_json_c_mem
+ mustach_json_c | mustach_json_c_write
diff --git a/src/templating/dotest.sh b/src/templating/dotest.sh
new file mode 100755
index 000000000..32f575c2e
--- /dev/null
+++ b/src/templating/dotest.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# Exit, with error message (hard failure)
+exit_fail() {
+ echo " FAIL: " "$@" >&2
+ exit 1
+}
+
+mustach="${mustach:-../mustach}"
+echo "starting test"
+if ! valgrind --version 2> /dev/null
+then
+ $mustach "$@" > resu.last || exit_fail "ERROR! mustach command failed ($?)!"
+else
+ valgrind $mustach "$@" > resu.last 2> vg.last || exit_fail "ERROR! valgrind + mustach command failed ($?)!"
+ sed -i 's:^==[0-9]*== ::' vg.last
+ awk '/^ *total heap usage: .* allocs, .* frees,.*/{if($$4-$$6)exit(1)}' vg.last || exit_fail "ERROR! Alloc/Free issue"
+fi
+if diff -w resu.ref resu.last
+then
+ echo "result ok"
+else
+ exit_fail "ERROR! Result differs"
+fi
+echo
+exit 0
diff --git a/src/templating/meson.build b/src/templating/meson.build
new file mode 100644
index 000000000..c7ecc8dfc
--- /dev/null
+++ b/src/templating/meson.build
@@ -0,0 +1,12 @@
+project('mustach', 'c',
+ version: '1.0.0'
+)
+
+mustach_inc = include_directories('.')
+mustach_lib = shared_library('mustach',
+ 'mustach.c',
+ include_directories: mustach_inc
+)
+
+mustach_dep = declare_dependency(link_with: mustach_lib,
+ include_directories: mustach_inc)
diff --git a/src/templating/mustach-cjson.c b/src/templating/mustach-cjson.c
new file mode 100644
index 000000000..ee65c8038
--- /dev/null
+++ b/src/templating/mustach-cjson.c
@@ -0,0 +1,258 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "mustach.h"
+#include "mustach-wrap.h"
+#include "mustach-cjson.h"
+
+struct expl {
+ cJSON null;
+ cJSON *root;
+ cJSON *selection;
+ int depth;
+ struct {
+ cJSON *cont;
+ cJSON *obj;
+ cJSON *next;
+ int is_objiter;
+ } stack[MUSTACH_MAX_DEPTH];
+};
+
+static int start(void *closure)
+{
+ struct expl *e = closure;
+ e->depth = 0;
+ memset(&e->null, 0, sizeof e->null);
+ e->null.type = cJSON_NULL;
+ e->selection = &e->null;
+ e->stack[0].cont = NULL;
+ e->stack[0].obj = e->root;
+ return MUSTACH_OK;
+}
+
+static int compare(void *closure, const char *value)
+{
+ struct expl *e = closure;
+ cJSON *o = e->selection;
+ double d;
+
+ if (cJSON_IsNumber(o)) {
+ d = o->valuedouble - atof(value);
+ return d < 0 ? -1 : d > 0 ? 1 : 0;
+ } else if (cJSON_IsString(o)) {
+ return strcmp(o->valuestring, value);
+ } else if (cJSON_IsTrue(o)) {
+ return strcmp("true", value);
+ } else if (cJSON_IsFalse(o)) {
+ return strcmp("false", value);
+ } else if (cJSON_IsNull(o)) {
+ return strcmp("null", value);
+ } else {
+ return 1;
+ }
+}
+
+static int sel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ cJSON *o;
+ int i, r;
+
+ if (name == NULL) {
+ o = e->stack[e->depth].obj;
+ r = 1;
+ } else {
+ i = e->depth;
+ while (i >= 0 && !(o = cJSON_GetObjectItemCaseSensitive(e->stack[i].obj, name)))
+ i--;
+ if (i >= 0)
+ r = 1;
+ else {
+ o = &e->null;
+ r = 0;
+ }
+ }
+ e->selection = o;
+ return r;
+}
+
+static int subsel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ cJSON *o = NULL;
+ int r = 0;
+
+ if (cJSON_IsObject(e->selection)) {
+ o = cJSON_GetObjectItemCaseSensitive(e->selection, name);
+ r = o != NULL;
+ }
+ else if (cJSON_IsArray(e->selection) && *name) {
+ char *end;
+ int idx = (int)strtol(name, &end, 10);
+ if (!*end && idx >= 0 && idx < cJSON_GetArraySize(e->selection)) {
+ o = cJSON_GetArrayItem(e->selection, idx);
+ r = 1;
+ }
+ }
+ if (r)
+ e->selection = o;
+ return r;
+}
+
+static int enter(void *closure, int objiter)
+{
+ struct expl *e = closure;
+ cJSON *o;
+
+ if (++e->depth >= MUSTACH_MAX_DEPTH)
+ return MUSTACH_ERROR_TOO_DEEP;
+
+ o = e->selection;
+ e->stack[e->depth].is_objiter = 0;
+ if (objiter) {
+ if (! cJSON_IsObject(o))
+ goto not_entering;
+ if (o->child == NULL)
+ goto not_entering;
+ e->stack[e->depth].obj = o->child;
+ e->stack[e->depth].next = o->child->next;
+ e->stack[e->depth].cont = o;
+ e->stack[e->depth].is_objiter = 1;
+ } else if (cJSON_IsArray(o)) {
+ if (o->child == NULL)
+ goto not_entering;
+ e->stack[e->depth].obj = o->child;
+ e->stack[e->depth].next = o->child->next;
+ e->stack[e->depth].cont = o;
+ } else if ((cJSON_IsObject(o) && o->child != NULL)
+ || cJSON_IsTrue(o)
+ || (cJSON_IsString(o) && cJSON_GetStringValue(o)[0] != '\0')
+ || (cJSON_IsNumber(o) && cJSON_GetNumberValue(o) != 0)) {
+ e->stack[e->depth].obj = o;
+ e->stack[e->depth].cont = NULL;
+ e->stack[e->depth].next = NULL;
+ } else
+ goto not_entering;
+ return 1;
+
+not_entering:
+ e->depth--;
+ return 0;
+}
+
+static int next(void *closure)
+{
+ struct expl *e = closure;
+ cJSON *o;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ o = e->stack[e->depth].next;
+ if (o == NULL)
+ return 0;
+
+ e->stack[e->depth].obj = o;
+ e->stack[e->depth].next = o->next;
+ return 1;
+}
+
+static int leave(void *closure)
+{
+ struct expl *e = closure;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ e->depth--;
+ return 0;
+}
+
+static int get(void *closure, struct mustach_sbuf *sbuf, int key)
+{
+ struct expl *e = closure;
+ const char *s;
+ int d;
+
+ if (key) {
+ s = "";
+ for (d = e->depth ; d >= 0 ; d--)
+ if (e->stack[d].is_objiter) {
+ s = e->stack[d].obj->string;
+ break;
+ }
+ }
+ else if (cJSON_IsString(e->selection))
+ s = e->selection->valuestring;
+ else if (cJSON_IsNull(e->selection))
+ s = "";
+ else {
+ s = cJSON_PrintUnformatted(e->selection);
+ if (s == NULL)
+ return MUSTACH_ERROR_SYSTEM;
+ sbuf->freecb = cJSON_free;
+ }
+ sbuf->value = s;
+ return 1;
+}
+
+const struct mustach_wrap_itf mustach_cJSON_wrap_itf = {
+ .start = start,
+ .stop = NULL,
+ .compare = compare,
+ .sel = sel,
+ .subsel = subsel,
+ .enter = enter,
+ .next = next,
+ .leave = leave,
+ .get = get
+};
+
+int mustach_cJSON_file(const char *template, size_t length, cJSON *root, int flags, FILE *file)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_file(template, length, &mustach_cJSON_wrap_itf, &e, flags, file);
+}
+
+int mustach_cJSON_fd(const char *template, size_t length, cJSON *root, int flags, int fd)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_fd(template, length, &mustach_cJSON_wrap_itf, &e, flags, fd);
+}
+
+int mustach_cJSON_mem(const char *template, size_t length, cJSON *root, int flags, char **result, size_t *size)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_mem(template, length, &mustach_cJSON_wrap_itf, &e, flags, result, size);
+}
+
+int mustach_cJSON_write(const char *template, size_t length, cJSON *root, int flags, mustach_write_cb_t *writecb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_write(template, length, &mustach_cJSON_wrap_itf, &e, flags, writecb, closure);
+}
+
+int mustach_cJSON_emit(const char *template, size_t length, cJSON *root, int flags, mustach_emit_cb_t *emitcb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_emit(template, length, &mustach_cJSON_wrap_itf, &e, flags, emitcb, closure);
+}
+
diff --git a/src/templating/mustach-cjson.h b/src/templating/mustach-cjson.h
new file mode 100644
index 000000000..e049415f8
--- /dev/null
+++ b/src/templating/mustach-cjson.h
@@ -0,0 +1,96 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _mustach_cJSON_h_included_
+#define _mustach_cJSON_h_included_
+
+/*
+ * mustach-cjson is intended to make integration of cJSON
+ * library by providing integrated functions.
+ */
+
+#include <cjson/cJSON.h>
+#include "mustach-wrap.h"
+
+/**
+ * Wrap interface used internally by mustach cJSON functions.
+ * Can be used for overriding behaviour.
+ */
+extern const struct mustach_wrap_itf mustach_cJSON_wrap_itf;
+
+/**
+ * mustach_cJSON_file - Renders the mustache 'template' in 'file' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_cJSON_file(const char *template, size_t length, cJSON *root, int flags, FILE *file);
+
+/**
+ * mustach_cJSON_fd - Renders the mustache 'template' in 'fd' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_cJSON_fd(const char *template, size_t length, cJSON *root, int flags, int fd);
+
+
+/**
+ * mustach_cJSON_mem - Renders the mustache 'template' in 'result' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_cJSON_mem(const char *template, size_t length, cJSON *root, int flags, char **result, size_t *size);
+
+/**
+ * mustach_cJSON_write - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @writecb: the function that write values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_cJSON_write(const char *template, size_t length, cJSON *root, int flags, mustach_write_cb_t *writecb, void *closure);
+
+/**
+ * mustach_cJSON_emit - Renders the mustache 'template' for 'root' to custom emiter 'emitcb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @emitcb: the function that emit values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_cJSON_emit(const char *template, size_t length, cJSON *root, int flags, mustach_emit_cb_t *emitcb, void *closure);
+
+#endif
+
diff --git a/src/templating/mustach-jansson.c b/src/templating/mustach-jansson.c
new file mode 100644
index 000000000..d9b50b57e
--- /dev/null
+++ b/src/templating/mustach-jansson.c
@@ -0,0 +1,271 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include "mustach.h"
+#include "mustach-wrap.h"
+#include "mustach-jansson.h"
+
+struct expl {
+ json_t *root;
+ json_t *selection;
+ int depth;
+ struct {
+ json_t *cont;
+ json_t *obj;
+ void *iter;
+ int is_objiter;
+ size_t index, count;
+ } stack[MUSTACH_MAX_DEPTH];
+};
+
+static int start(void *closure)
+{
+ struct expl *e = closure;
+ e->depth = 0;
+ e->selection = json_null();
+ e->stack[0].cont = NULL;
+ e->stack[0].obj = e->root;
+ e->stack[0].index = 0;
+ e->stack[0].count = 1;
+ return MUSTACH_OK;
+}
+
+static int compare(void *closure, const char *value)
+{
+ struct expl *e = closure;
+ json_t *o = e->selection;
+ double d;
+ json_int_t i;
+
+ switch (json_typeof(o)) {
+ case JSON_REAL:
+ d = json_number_value(o) - atof(value);
+ return d < 0 ? -1 : d > 0 ? 1 : 0;
+ case JSON_INTEGER:
+ i = (json_int_t)json_integer_value(o) - (json_int_t)atoll(value);
+ return i < 0 ? -1 : i > 0 ? 1 : 0;
+ case JSON_STRING:
+ return strcmp(json_string_value(o), value);
+ case JSON_TRUE:
+ return strcmp("true", value);
+ case JSON_FALSE:
+ return strcmp("false", value);
+ case JSON_NULL:
+ return strcmp("null", value);
+ default:
+ return 1;
+ }
+}
+
+static int sel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ json_t *o;
+ int i, r;
+
+ if (name == NULL) {
+ o = e->stack[e->depth].obj;
+ r = 1;
+ } else {
+ i = e->depth;
+ while (i >= 0 && !(o = json_object_get(e->stack[i].obj, name)))
+ i--;
+ if (i >= 0)
+ r = 1;
+ else {
+ o = json_null();
+ r = 0;
+ }
+ }
+ e->selection = o;
+ return r;
+}
+
+static int subsel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ json_t *o = NULL;
+ int r = 0;
+
+ if (json_is_object(e->selection)) {
+ o = json_object_get(e->selection, name);
+ r = o != NULL;
+ }
+ else if (json_is_array(e->selection)) {
+ char *end;
+ size_t idx = (size_t)strtol(name, &end, 10);
+ if (!*end && idx < json_array_size(e->selection)) {
+ o = json_array_get(e->selection, idx);
+ r = 1;
+ }
+ }
+ if (r)
+ e->selection = o;
+ return r;
+}
+
+static int enter(void *closure, int objiter)
+{
+ struct expl *e = closure;
+ json_t *o;
+
+ if (++e->depth >= MUSTACH_MAX_DEPTH)
+ return MUSTACH_ERROR_TOO_DEEP;
+
+ o = e->selection;
+ e->stack[e->depth].is_objiter = 0;
+ if (objiter) {
+ if (!json_is_object(o))
+ goto not_entering;
+ e->stack[e->depth].iter = json_object_iter(o);
+ if (e->stack[e->depth].iter == NULL)
+ goto not_entering;
+ e->stack[e->depth].obj = json_object_iter_value(e->stack[e->depth].iter);
+ e->stack[e->depth].cont = o;
+ e->stack[e->depth].is_objiter = 1;
+ } else if (json_is_array(o)) {
+ e->stack[e->depth].count = json_array_size(o);
+ if (e->stack[e->depth].count == 0)
+ goto not_entering;
+ e->stack[e->depth].cont = o;
+ e->stack[e->depth].obj = json_array_get(o, 0);
+ e->stack[e->depth].index = 0;
+ } else if ((json_is_object(o) && json_object_size(o))
+ || json_is_true(o)
+ || (json_is_string(o) && json_string_length(o) > 0)
+ || (json_is_integer(o) && json_integer_value(o) != 0)
+ || (json_is_real(o) && json_real_value(o) != 0)) {
+ e->stack[e->depth].count = 1;
+ e->stack[e->depth].cont = NULL;
+ e->stack[e->depth].obj = o;
+ e->stack[e->depth].index = 0;
+ } else
+ goto not_entering;
+ return 1;
+
+not_entering:
+ e->depth--;
+ return 0;
+}
+
+static int next(void *closure)
+{
+ struct expl *e = closure;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ if (e->stack[e->depth].is_objiter) {
+ e->stack[e->depth].iter = json_object_iter_next(e->stack[e->depth].cont, e->stack[e->depth].iter);
+ if (e->stack[e->depth].iter == NULL)
+ return 0;
+ e->stack[e->depth].obj = json_object_iter_value(e->stack[e->depth].iter);
+ return 1;
+ }
+
+ e->stack[e->depth].index++;
+ if (e->stack[e->depth].index >= e->stack[e->depth].count)
+ return 0;
+
+ e->stack[e->depth].obj = json_array_get(e->stack[e->depth].cont, e->stack[e->depth].index);
+ return 1;
+}
+
+static int leave(void *closure)
+{
+ struct expl *e = closure;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ e->depth--;
+ return 0;
+}
+
+static int get(void *closure, struct mustach_sbuf *sbuf, int key)
+{
+ struct expl *e = closure;
+ const char *s;
+ int d;
+
+ if (key) {
+ s = "";
+ for (d = e->depth ; d >= 0 ; d--)
+ if (e->stack[d].is_objiter) {
+ s = json_object_iter_key(e->stack[d].iter);
+ break;
+ }
+ }
+ else if (json_is_string(e->selection))
+ s = json_string_value(e->selection);
+ else if (json_is_null(e->selection))
+ s = "";
+ else {
+ s = json_dumps(e->selection, JSON_ENCODE_ANY | JSON_COMPACT);
+ if (s == NULL)
+ return MUSTACH_ERROR_SYSTEM;
+ sbuf->freecb = free;
+ }
+ sbuf->value = s;
+ return 1;
+}
+
+const struct mustach_wrap_itf mustach_jansson_wrap_itf = {
+ .start = start,
+ .stop = NULL,
+ .compare = compare,
+ .sel = sel,
+ .subsel = subsel,
+ .enter = enter,
+ .next = next,
+ .leave = leave,
+ .get = get
+};
+
+int mustach_jansson_file(const char *template, size_t length, json_t *root, int flags, FILE *file)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_file(template, length, &mustach_jansson_wrap_itf, &e, flags, file);
+}
+
+int mustach_jansson_fd(const char *template, size_t length, json_t *root, int flags, int fd)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_fd(template, length, &mustach_jansson_wrap_itf, &e, flags, fd);
+}
+
+int mustach_jansson_mem(const char *template, size_t length, json_t *root, int flags, char **result, size_t *size)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_mem(template, length, &mustach_jansson_wrap_itf, &e, flags, result, size);
+}
+
+int mustach_jansson_write(const char *template, size_t length, json_t *root, int flags, mustach_write_cb_t *writecb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_write(template, length, &mustach_jansson_wrap_itf, &e, flags, writecb, closure);
+}
+
+int mustach_jansson_emit(const char *template, size_t length, json_t *root, int flags, mustach_emit_cb_t *emitcb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_emit(template, length, &mustach_jansson_wrap_itf, &e, flags, emitcb, closure);
+}
+
diff --git a/src/templating/mustach-jansson.h b/src/templating/mustach-jansson.h
new file mode 100644
index 000000000..8def948e0
--- /dev/null
+++ b/src/templating/mustach-jansson.h
@@ -0,0 +1,96 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _mustach_jansson_h_included_
+#define _mustach_jansson_h_included_
+
+/*
+ * mustach-jansson is intended to make integration of jansson
+ * library by providing integrated functions.
+ */
+
+#include <jansson.h>
+#include "mustach-wrap.h"
+
+/**
+ * Wrap interface used internally by mustach jansson functions.
+ * Can be used for overriding behaviour.
+ */
+extern const struct mustach_wrap_itf mustach_jansson_wrap_itf;
+
+/**
+ * mustach_jansson_file - Renders the mustache 'template' in 'file' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_jansson_file(const char *template, size_t length, json_t *root, int flags, FILE *file);
+
+/**
+ * mustach_jansson_fd - Renders the mustache 'template' in 'fd' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_jansson_fd(const char *template, size_t length, json_t *root, int flags, int fd);
+
+
+/**
+ * mustach_jansson_mem - Renders the mustache 'template' in 'result' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_jansson_mem(const char *template, size_t length, json_t *root, int flags, char **result, size_t *size);
+
+/**
+ * mustach_jansson_write - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @writecb: the function that write values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_jansson_write(const char *template, size_t length, json_t *root, int flags, mustach_write_cb_t *writecb, void *closure);
+
+/**
+ * mustach_jansson_emit - Renders the mustache 'template' for 'root' to custom emiter 'emitcb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @emitcb: the function that emit values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_jansson_emit(const char *template, size_t length, json_t *root, int flags, mustach_emit_cb_t *emitcb, void *closure);
+
+#endif
+
diff --git a/src/templating/mustach-json-c.c b/src/templating/mustach-json-c.c
new file mode 100644
index 000000000..75251c07e
--- /dev/null
+++ b/src/templating/mustach-json-c.c
@@ -0,0 +1,284 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdio.h>
+#include <string.h>
+
+#include "mustach.h"
+#include "mustach-wrap.h"
+#include "mustach-json-c.h"
+
+struct expl {
+ struct json_object *root;
+ struct json_object *selection;
+ int depth;
+ struct {
+ struct json_object *cont;
+ struct json_object *obj;
+ struct json_object_iterator iter;
+ struct json_object_iterator enditer;
+ int is_objiter;
+ int index, count;
+ } stack[MUSTACH_MAX_DEPTH];
+};
+
+static int start(void *closure)
+{
+ struct expl *e = closure;
+ e->depth = 0;
+ e->selection = NULL;
+ e->stack[0].cont = NULL;
+ e->stack[0].obj = e->root;
+ e->stack[0].index = 0;
+ e->stack[0].count = 1;
+ return MUSTACH_OK;
+}
+
+static int compare(void *closure, const char *value)
+{
+ struct expl *e = closure;
+ struct json_object *o = e->selection;
+ double d;
+ int64_t i;
+
+ switch (json_object_get_type(o)) {
+ case json_type_double:
+ d = json_object_get_double(o) - atof(value);
+ return d < 0 ? -1 : d > 0 ? 1 : 0;
+ case json_type_int:
+ i = json_object_get_int64(o) - (int64_t)atoll(value);
+ return i < 0 ? -1 : i > 0 ? 1 : 0;
+ default:
+ return strcmp(json_object_get_string(o), value);
+ }
+}
+
+static int sel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ struct json_object *o;
+ int i, r;
+
+ if (name == NULL) {
+ o = e->stack[e->depth].obj;
+ r = 1;
+ } else {
+ i = e->depth;
+ while (i >= 0 && !json_object_object_get_ex(e->stack[i].obj, name, &o))
+ i--;
+ if (i >= 0)
+ r = 1;
+ else {
+ o = NULL;
+ r = 0;
+ }
+ }
+ e->selection = o;
+ return r;
+}
+
+static int subsel(void *closure, const char *name)
+{
+ struct expl *e = closure;
+ struct json_object *o = NULL;
+ int r = 0;
+
+ if (json_object_is_type(e->selection, json_type_object))
+ r = json_object_object_get_ex(e->selection, name, &o);
+ else if (json_object_is_type(e->selection, json_type_array)) {
+ char *end;
+ size_t idx = (size_t)strtol(name, &end, 10);
+ if (!*end && idx < json_object_array_length(e->selection)) {
+ o = json_object_array_get_idx(e->selection, idx);
+ r = 1;
+ }
+ }
+ if (r)
+ e->selection = o;
+ return r;
+}
+
+static int enter(void *closure, int objiter)
+{
+ struct expl *e = closure;
+ struct json_object *o;
+
+ if (++e->depth >= MUSTACH_MAX_DEPTH)
+ return MUSTACH_ERROR_TOO_DEEP;
+
+ o = e->selection;
+ e->stack[e->depth].is_objiter = 0;
+ if (objiter) {
+ if (!json_object_is_type(o, json_type_object))
+ goto not_entering;
+
+ e->stack[e->depth].iter = json_object_iter_begin(o);
+ e->stack[e->depth].enditer = json_object_iter_end(o);
+ if (json_object_iter_equal(&e->stack[e->depth].iter, &e->stack[e->depth].enditer))
+ goto not_entering;
+ e->stack[e->depth].obj = json_object_iter_peek_value(&e->stack[e->depth].iter);
+ e->stack[e->depth].cont = o;
+ e->stack[e->depth].is_objiter = 1;
+ } else if (json_object_is_type(o, json_type_array)) {
+ e->stack[e->depth].count = json_object_array_length(o);
+ if (e->stack[e->depth].count == 0)
+ goto not_entering;
+ e->stack[e->depth].cont = o;
+ e->stack[e->depth].obj = json_object_array_get_idx(o, 0);
+ e->stack[e->depth].index = 0;
+ } else if ((json_object_is_type(o, json_type_object) && json_object_object_length(o) > 0)
+ || json_object_get_boolean(o)) {
+ e->stack[e->depth].count = 1;
+ e->stack[e->depth].cont = NULL;
+ e->stack[e->depth].obj = o;
+ e->stack[e->depth].index = 0;
+ } else
+ goto not_entering;
+ return 1;
+
+not_entering:
+ e->depth--;
+ return 0;
+}
+
+static int next(void *closure)
+{
+ struct expl *e = closure;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ if (e->stack[e->depth].is_objiter) {
+ json_object_iter_next(&e->stack[e->depth].iter);
+ if (json_object_iter_equal(&e->stack[e->depth].iter, &e->stack[e->depth].enditer))
+ return 0;
+ e->stack[e->depth].obj = json_object_iter_peek_value(&e->stack[e->depth].iter);
+ return 1;
+ }
+
+ e->stack[e->depth].index++;
+ if (e->stack[e->depth].index >= e->stack[e->depth].count)
+ return 0;
+
+ e->stack[e->depth].obj = json_object_array_get_idx(e->stack[e->depth].cont, e->stack[e->depth].index);
+ return 1;
+}
+
+static int leave(void *closure)
+{
+ struct expl *e = closure;
+
+ if (e->depth <= 0)
+ return MUSTACH_ERROR_CLOSING;
+
+ e->depth--;
+ return 0;
+}
+
+static int get(void *closure, struct mustach_sbuf *sbuf, int key)
+{
+ struct expl *e = closure;
+ const char *s;
+ int d;
+
+ if (key) {
+ s = "";
+ for (d = e->depth ; d >= 0 ; d--)
+ if (e->stack[d].is_objiter) {
+ s = json_object_iter_peek_name(&e->stack[d].iter);
+ break;
+ }
+ }
+ else
+ switch (json_object_get_type(e->selection)) {
+ case json_type_string:
+ s = json_object_get_string(e->selection);
+ break;
+ case json_type_null:
+ s = "";
+ break;
+ default:
+ s = json_object_to_json_string_ext(e->selection, 0);
+ break;
+ }
+ sbuf->value = s;
+ return 1;
+}
+
+const struct mustach_wrap_itf mustach_json_c_wrap_itf = {
+ .start = start,
+ .stop = NULL,
+ .compare = compare,
+ .sel = sel,
+ .subsel = subsel,
+ .enter = enter,
+ .next = next,
+ .leave = leave,
+ .get = get
+};
+
+int mustach_json_c_file(const char *template, size_t length, struct json_object *root, int flags, FILE *file)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_file(template, length, &mustach_json_c_wrap_itf, &e, flags, file);
+}
+
+int mustach_json_c_fd(const char *template, size_t length, struct json_object *root, int flags, int fd)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_fd(template, length, &mustach_json_c_wrap_itf, &e, flags, fd);
+}
+
+int mustach_json_c_mem(const char *template, size_t length, struct json_object *root, int flags, char **result, size_t *size)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_mem(template, length, &mustach_json_c_wrap_itf, &e, flags, result, size);
+}
+
+int mustach_json_c_write(const char *template, size_t length, struct json_object *root, int flags, mustach_write_cb_t *writecb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_write(template, length, &mustach_json_c_wrap_itf, &e, flags, writecb, closure);
+}
+
+int mustach_json_c_emit(const char *template, size_t length, struct json_object *root, int flags, mustach_emit_cb_t *emitcb, void *closure)
+{
+ struct expl e;
+ e.root = root;
+ return mustach_wrap_emit(template, length, &mustach_json_c_wrap_itf, &e, flags, emitcb, closure);
+}
+
+int fmustach_json_c(const char *template, struct json_object *root, FILE *file)
+{
+ return mustach_json_c_file(template, 0, root, -1, file);
+}
+
+int fdmustach_json_c(const char *template, struct json_object *root, int fd)
+{
+ return mustach_json_c_fd(template, 0, root, -1, fd);
+}
+
+int mustach_json_c(const char *template, struct json_object *root, char **result, size_t *size)
+{
+ return mustach_json_c_mem(template, 0, root, -1, result, size);
+}
+
+int umustach_json_c(const char *template, struct json_object *root, mustach_write_cb_t *writecb, void *closure)
+{
+ return mustach_json_c_write(template, 0, root, -1, writecb, closure);
+}
+
+
diff --git a/src/templating/mustach-json-c.h b/src/templating/mustach-json-c.h
new file mode 100644
index 000000000..50846c6cb
--- /dev/null
+++ b/src/templating/mustach-json-c.h
@@ -0,0 +1,160 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _mustach_json_c_h_included_
+#define _mustach_json_c_h_included_
+
+/*
+ * mustach-json-c is intended to make integration of json-c
+ * library by providing integrated functions.
+ */
+
+#include <json-c/json.h>
+#include "mustach-wrap.h"
+
+/**
+ * Wrap interface used internally by mustach json-c functions.
+ * Can be used for overriding behaviour.
+ */
+extern const struct mustach_wrap_itf mustach_json_c_wrap_itf;
+
+/**
+ * mustach_json_c_file - Renders the mustache 'template' in 'file' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_json_c_file(const char *template, size_t length, struct json_object *root, int flags, FILE *file);
+
+/**
+ * mustach_json_c_fd - Renders the mustache 'template' in 'fd' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_json_c_fd(const char *template, size_t length, struct json_object *root, int flags, int fd);
+
+/**
+ * mustach_json_c_mem - Renders the mustache 'template' in 'result' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_json_c_mem(const char *template, size_t length, struct json_object *root, int flags, char **result, size_t *size);
+
+/**
+ * mustach_json_c_write - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @writecb: the function that write values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_json_c_write(const char *template, size_t length, struct json_object *root, int flags, mustach_write_cb_t *writecb, void *closure);
+
+/**
+ * mustach_json_c_emit - Renders the mustache 'template' for 'root' to custom emiter 'emitcb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @root: the root json object to render
+ * @emitcb: the function that emit values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_json_c_emit(const char *template, size_t length, struct json_object *root, int flags, mustach_emit_cb_t *emitcb, void *closure);
+
+/***************************************************************************
+* compatibility with version before 1.0
+*/
+
+/**
+ * OBSOLETE use mustach_json_c_file
+ *
+ * fmustach_json_c - Renders the mustache 'template' in 'file' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @root: the root json object to render
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+
+DEPRECATED_MUSTACH(extern int fmustach_json_c(const char *template, struct json_object *root, FILE *file));
+
+/**
+ * OBSOLETE use mustach_json_c_fd
+ *
+ * fdmustach_json_c - Renders the mustache 'template' in 'fd' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @root: the root json object to render
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+
+DEPRECATED_MUSTACH(extern int fdmustach_json_c(const char *template, struct json_object *root, int fd));
+
+/**
+ * OBSOLETE use mustach_json_c_mem
+ *
+ * mustach_json_c - Renders the mustache 'template' in 'result' for 'root'.
+ *
+ * @template: the template string to instantiate
+ * @root: the root json object to render
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+
+DEPRECATED_MUSTACH(extern int mustach_json_c(const char *template, struct json_object *root, char **result, size_t *size));
+
+/**
+ * OBSOLETE use mustach_json_c_write
+ *
+ * umustach_json_c - Renders the mustache 'template' for 'root' to custom writer 'writecb' with 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @root: the root json object to render
+ * @writecb: the function that write values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+typedef mustach_write_cb_t *mustach_json_write_cb;
+DEPRECATED_MUSTACH(extern int umustach_json_c(const char *template, struct json_object *root, mustach_write_cb_t *writecb, void *closure));
+
+#endif
diff --git a/src/templating/mustach-original-Makefile b/src/templating/mustach-original-Makefile
new file mode 100644
index 000000000..aee827583
--- /dev/null
+++ b/src/templating/mustach-original-Makefile
@@ -0,0 +1,305 @@
+# version
+MAJOR := 1
+MINOR := 2
+REVIS := 7
+
+# installation settings
+DESTDIR ?=
+PREFIX ?= /usr/local
+BINDIR ?= $(PREFIX)/bin
+LIBDIR ?= $(PREFIX)/lib
+INCLUDEDIR ?= $(PREFIX)/include
+MANDIR ?= $(PREFIX)/share/man
+PKGDIR ?= $(LIBDIR)/pkgconfig
+
+# Tools (sed must be GNU sed)
+SED ?= sed
+INSTALL ?= install
+
+# initial settings
+VERSION := $(MAJOR).$(MINOR).$(REVIS)
+SOVER := .$(MAJOR)
+SOVEREV := .$(MAJOR).$(MINOR)
+
+HEADERS := mustach.h mustach-wrap.h
+SPLITLIB := libmustach-core.so$(SOVEREV)
+SPLITPC := libmustach-core.pc
+COREOBJS := mustach.o mustach-wrap.o
+SINGLEOBJS := $(COREOBJS)
+SINGLEFLAGS :=
+SINGLELIBS :=
+TESTSPECS :=
+ALL := manuals
+
+# availability of CJSON
+ifneq ($(cjson),no)
+ cjson_cflags := $(shell pkg-config --silence-errors --cflags libcjson)
+ cjson_libs := $(shell pkg-config --silence-errors --libs libcjson)
+ ifdef cjson_libs
+ cjson := yes
+ tool ?= cjson
+ HEADERS += mustach-cjson.h
+ SPLITLIB += libmustach-cjson.so$(SOVEREV)
+ SPLITPC += libmustach-cjson.pc
+ SINGLEOBJS += mustach-cjson.o
+ SINGLEFLAGS += ${cjson_cflags}
+ SINGLELIBS += ${cjson_libs}
+ TESTSPECS += test-specs/test-specs-cjson
+ else
+ ifeq ($(cjson),yes)
+ $(error Can't find required library cjson)
+ endif
+ cjson := no
+ endif
+endif
+
+# availability of JSON-C
+ifneq ($(jsonc),no)
+ jsonc_cflags := $(shell pkg-config --silence-errors --cflags json-c)
+ jsonc_libs := $(shell pkg-config --silence-errors --libs json-c)
+ ifdef jsonc_libs
+ jsonc := yes
+ tool ?= jsonc
+ HEADERS += mustach-json-c.h
+ SPLITLIB += libmustach-json-c.so$(SOVEREV)
+ SPLITPC += libmustach-json-c.pc
+ SINGLEOBJS += mustach-json-c.o
+ SINGLEFLAGS += ${jsonc_cflags}
+ SINGLELIBS += ${jsonc_libs}
+ TESTSPECS += test-specs/test-specs-json-c
+ else
+ ifeq ($(jsonc),yes)
+ $(error Can't find required library json-c)
+ endif
+ jsonc := no
+ endif
+endif
+
+# availability of JANSSON
+ifneq ($(jansson),no)
+ jansson_cflags := $(shell pkg-config --silence-errors --cflags jansson)
+ jansson_libs := $(shell pkg-config --silence-errors --libs jansson)
+ ifdef jansson_libs
+ jansson := yes
+ tool ?= jansson
+ HEADERS += mustach-jansson.h
+ SPLITLIB += libmustach-jansson.so$(SOVEREV)
+ SPLITPC += libmustach-jansson.pc
+ SINGLEOBJS += mustach-jansson.o
+ SINGLEFLAGS += ${jansson_cflags}
+ SINGLELIBS += ${jansson_libs}
+ TESTSPECS += test-specs/test-specs-jansson
+ else
+ ifeq ($(jansson),yes)
+ $(error Can't find required library jansson)
+ endif
+ jansson := no
+ endif
+endif
+
+# tool
+TOOLOBJS = mustach-tool.o $(COREOBJS)
+tool ?= none
+ifneq ($(tool),none)
+ ifeq ($(tool),cjson)
+ TOOLOBJS += mustach-cjson.o
+ TOOLFLAGS := ${cjson_cflags} -DTOOL=MUSTACH_TOOL_CJSON
+ TOOLLIBS := ${cjson_libs}
+ TOOLDEP := mustach-cjson.h
+ else ifeq ($(tool),jsonc)
+ TOOLOBJS += mustach-json-c.o
+ TOOLFLAGS := ${jsonc_cflags} -DTOOL=MUSTACH_TOOL_JSON_C
+ TOOLLIBS := ${jsonc_libs}
+ TOOLDEP := mustach-json-c.h
+ else ifeq ($(tool),jansson)
+ TOOLOBJS += mustach-jansson.o
+ TOOLFLAGS := ${jansson_cflags} -DTOOL=MUSTACH_TOOL_JANSSON
+ TOOLLIBS := ${jansson_libs}
+ TOOLDEP := mustach-jansson.h
+ else
+ $(error Unknown library $(tool) for tool)
+ endif
+ ifneq ($($(tool)),yes)
+ $(error No library found for tool $(tool))
+ endif
+ ALL += mustach
+endif
+
+# compute targets
+libs ?= all
+ifeq (${libs},split)
+ ALL += ${SPLITLIB} ${SPLITPC}
+else ifeq (${libs},single)
+ ALL += libmustach.so$(SOVEREV) libmustach.pc
+else ifeq (${libs},all)
+ ALL += libmustach.so$(SOVEREV) libmustach.pc ${SPLITLIB} ${SPLITPC}
+else ifneq (${libs},none)
+ $(error Unknown libs $(libs))
+endif
+
+# display target
+$(info tool = ${tool})
+$(info libs = ${libs})
+$(info jsonc = ${jsonc})
+$(info jansson = ${jansson})
+$(info cjson = ${cjson})
+
+# settings
+
+EFLAGS = -fPIC -Wall -Wextra -DVERSION=${VERSION}
+
+ifeq ($(shell uname),Darwin)
+ LDFLAGS_single += -install_name $(LIBDIR)/libmustach.so$(SOVEREV)
+ LDFLAGS_core += -install_name $(LIBDIR)/libmustach-core.so$(SOVEREV)
+ LDFLAGS_cjson += -install_name $(LIBDIR)/libmustach-cjson.so$(SOVEREV)
+ LDFLAGS_jsonc += -install_name $(LIBDIR)/libmustach-json-c.so$(SOVEREV)
+ LDFLAGS_jansson += -install_name $(LIBDIR)/libmustach-jansson.so$(SOVEREV)
+else
+ LDFLAGS_single += -Wl,-soname,libmustach.so$(SOVER)
+ LDFLAGS_core += -Wl,-soname,libmustach-core.so$(SOVER)
+ LDFLAGS_cjson += -Wl,-soname,libmustach-cjson.so$(SOVER)
+ LDFLAGS_jsonc += -Wl,-soname,libmustach-json-c.so$(SOVER)
+ LDFLAGS_jansson += -Wl,-soname,libmustach-jansson.so$(SOVER)
+endif
+
+# targets
+
+.PHONY: all
+all: ${ALL}
+
+mustach: $(TOOLOBJS)
+ $(CC) $(LDFLAGS) $(TOOLFLAGS) -o mustach $(TOOLOBJS) $(TOOLLIBS)
+
+libmustach.so$(SOVEREV): $(SINGLEOBJS)
+ $(CC) -shared $(LDFLAGS) $(LDFLAGS_single) -o $@ $^ $(SINGLELIBS)
+
+libmustach-core.so$(SOVEREV): $(COREOBJS)
+ $(CC) -shared $(LDFLAGS) $(LDFLAGS_core) -o $@ $(COREOBJS) $(lib_OBJ)
+
+libmustach-cjson.so$(SOVEREV): $(COREOBJS) mustach-cjson.o
+ $(CC) -shared $(LDFLAGS) $(LDFLAGS_cjson) -o $@ $^ $(cjson_libs)
+
+libmustach-json-c.so$(SOVEREV): $(COREOBJS) mustach-json-c.o
+ $(CC) -shared $(LDFLAGS) $(LDFLAGS_jsonc) -o $@ $^ $(jsonc_libs)
+
+libmustach-jansson.so$(SOVEREV): $(COREOBJS) mustach-jansson.o
+ $(CC) -shared $(LDFLAGS) $(LDFLAGS_jansson) -o $@ $^ $(jansson_libs)
+
+# pkgconfigs
+
+%.pc: pkgcfgs
+ $(SED) -E '/^==.*==$$/{h;d};x;/==$@==/{x;s/VERSION/$(VERSION)/;p;d};x;d' $< > $@
+
+# objects
+
+mustach.o: mustach.c mustach.h
+ $(CC) -c $(EFLAGS) $(CFLAGS) -o $@ $<
+
+mustach-wrap.o: mustach-wrap.c mustach.h mustach-wrap.h
+ $(CC) -c $(EFLAGS) $(CFLAGS) -o $@ $<
+
+mustach-tool.o: mustach-tool.c mustach.h mustach-json-c.h $(TOOLDEP)
+ $(CC) -c $(EFLAGS) $(CFLAGS) $(TOOLFLAGS) -o $@ $<
+
+mustach-cjson.o: mustach-cjson.c mustach.h mustach-wrap.h mustach-cjson.h
+ $(CC) -c $(EFLAGS) $(CFLAGS) $(cjson_cflags) -o $@ $<
+
+mustach-json-c.o: mustach-json-c.c mustach.h mustach-wrap.h mustach-json-c.h
+ $(CC) -c $(EFLAGS) $(CFLAGS) $(jsonc_cflags) -o $@ $<
+
+mustach-jansson.o: mustach-jansson.c mustach.h mustach-wrap.h mustach-jansson.h
+ $(CC) -c $(EFLAGS) $(CFLAGS) $(jansson_cflags) -o $@ $<
+
+# installing
+.PHONY: install
+install: all
+ $(INSTALL) -d $(DESTDIR)$(BINDIR)
+ if test "${tool}" != "none"; then \
+ $(INSTALL) -m0755 mustach $(DESTDIR)$(BINDIR)/; \
+ fi
+ $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)/mustach
+ $(INSTALL) -m0644 $(HEADERS) $(DESTDIR)$(INCLUDEDIR)/mustach
+ $(INSTALL) -d $(DESTDIR)$(LIBDIR)
+ for x in libmustach*.so$(SOVEREV); do \
+ $(INSTALL) -m0755 $$x $(DESTDIR)$(LIBDIR)/ ;\
+ ln -sf $$x $(DESTDIR)$(LIBDIR)/$${x%.so.*}.so$(SOVER) ;\
+ ln -sf $$x $(DESTDIR)$(LIBDIR)/$${x%.so.*}.so ;\
+ done
+ $(INSTALL) -d $(DESTDIR)/$(PKGDIR)
+ $(INSTALL) -m0644 libmustach*.pc $(DESTDIR)/$(PKGDIR)
+ $(INSTALL) -d $(DESTDIR)/$(MANDIR)/man1
+ $(INSTALL) -m0644 mustach.1.gz $(DESTDIR)/$(MANDIR)/man1
+
+# deinstalling
+.PHONY: uninstall
+uninstall:
+ rm -f $(DESTDIR)$(BINDIR)/mustach
+ rm -f $(DESTDIR)$(LIBDIR)/libmustach*.so*
+ rm -rf $(DESTDIR)$(INCLUDEDIR)/mustach
+
+.PHONY: test test-basic test-specs
+test: basic-tests spec-tests
+
+basic-tests: mustach
+ @$(MAKE) -C test1 test
+ @$(MAKE) -C test2 test
+ @$(MAKE) -C test3 test
+ @$(MAKE) -C test4 test
+ @$(MAKE) -C test5 test
+ @$(MAKE) -C test6 test
+ @$(MAKE) -C test7 test
+ @$(MAKE) -C test8 test
+
+spec-tests: $(TESTSPECS)
+
+test-specs/test-specs-%: test-specs/%-test-specs test-specs/specs
+ ./$< test-specs/spec/specs/[a-z]*.json > $@.last || true
+ diff $@.ref $@.last
+
+test-specs/cjson-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-cjson.h
+ $(CC) -I. -c $(EFLAGS) $(CFLAGS) $(cjson_cflags) -DTEST=TEST_CJSON -o $@ $<
+
+test-specs/cjson-test-specs: test-specs/cjson-test-specs.o mustach-cjson.o $(COREOBJS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(cjson_libs)
+
+test-specs/json-c-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-json-c.h
+ $(CC) -I. -c $(EFLAGS) $(CFLAGS) $(jsonc_cflags) -DTEST=TEST_JSON_C -o $@ $<
+
+test-specs/json-c-test-specs: test-specs/json-c-test-specs.o mustach-json-c.o $(COREOBJS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(jsonc_libs)
+
+test-specs/jansson-test-specs.o: test-specs/test-specs.c mustach.h mustach-wrap.h mustach-jansson.h
+ $(CC) -I. -c $(EFLAGS) $(CFLAGS) $(jansson_cflags) -DTEST=TEST_JANSSON -o $@ $<
+
+test-specs/jansson-test-specs: test-specs/jansson-test-specs.o mustach-jansson.o $(COREOBJS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(jansson_libs)
+
+.PHONY: test-specs/specs
+test-specs/specs:
+ if test -d test-specs/spec; then \
+ git -C test-specs/spec pull; \
+ else \
+ git -C test-specs clone https://github.com/mustache/spec.git; \
+ fi
+
+#cleaning
+.PHONY: clean
+clean:
+ rm -f mustach libmustach*.so* *.o *.pc
+ rm -f test-specs/*-test-specs test-specs/test-specs-*.last
+ rm -rf *.gcno *.gcda coverage.info gcov-latest
+ @$(MAKE) -C test1 clean
+ @$(MAKE) -C test2 clean
+ @$(MAKE) -C test3 clean
+ @$(MAKE) -C test4 clean
+ @$(MAKE) -C test5 clean
+ @$(MAKE) -C test6 clean
+ @$(MAKE) -C test7 clean
+ @$(MAKE) -C test8 clean
+
+# manpage
+.PHONY: manuals
+manuals: mustach.1.gz
+
+mustach.1.gz: mustach.1.scd
+ if which scdoc >/dev/null 2>&1; then scdoc < mustach.1.scd | gzip > mustach.1.gz; fi
diff --git a/src/templating/mustach-tool.c b/src/templating/mustach-tool.c
new file mode 100644
index 000000000..5f28c1f58
--- /dev/null
+++ b/src/templating/mustach-tool.c
@@ -0,0 +1,258 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <libgen.h>
+
+#include "mustach-wrap.h"
+
+static const size_t BLOCKSIZE = 8192;
+
+static const char *errors[] = {
+ "??? unreferenced ???",
+ "system",
+ "unexpected end",
+ "empty tag",
+ "tag too long",
+ "bad separators",
+ "too depth",
+ "closing",
+ "bad unescape tag",
+ "invalid interface",
+ "item not found",
+ "partial not found",
+ "undefined tag",
+ "too much template nesting"
+};
+
+static const char *errmsg = 0;
+static int flags = 0;
+static FILE *output = 0;
+
+static void help(char *prog)
+{
+ char *name = basename(prog);
+#define STR_INDIR(x) #x
+#define STR(x) STR_INDIR(x)
+ printf("%s version %s\n", name, STR(VERSION));
+#undef STR
+#undef STR_INDIR
+ printf(
+ "\n"
+ "USAGE:\n"
+ " %s [FLAGS] <json-file> <mustach-templates...>\n"
+ "\n"
+ "FLAGS:\n"
+ " -h, --help Prints help information\n"
+ " -s, --strict Error when a tag is undefined\n"
+ "\n"
+ "ARGS: (if a file is -, read standard input)\n"
+ " <json-file> JSON file with input data\n"
+ " <mustach-templates...> Template files to instantiate\n",
+ name);
+ exit(0);
+}
+
+static char *readfile(const char *filename, size_t *length)
+{
+ int f;
+ struct stat s;
+ char *result;
+ size_t size, pos;
+ ssize_t rc;
+
+ result = NULL;
+ if (filename[0] == '-' && filename[1] == 0)
+ f = dup(0);
+ else
+ f = open(filename, O_RDONLY);
+ if (f < 0) {
+ fprintf(stderr, "Can't open file: %s\n", filename);
+ exit(1);
+ }
+
+ fstat(f, &s);
+ switch (s.st_mode & S_IFMT) {
+ case S_IFREG:
+ size = s.st_size;
+ break;
+ case S_IFSOCK:
+ case S_IFIFO:
+ size = BLOCKSIZE;
+ break;
+ default:
+ fprintf(stderr, "Bad file: %s\n", filename);
+ exit(1);
+ }
+
+ pos = 0;
+ result = malloc(size + 1);
+ do {
+ if (result == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
+ rc = read(f, &result[pos], (size - pos) + 1);
+ if (rc < 0) {
+ fprintf(stderr, "Error while reading %s\n", filename);
+ exit(1);
+ }
+ if (rc > 0) {
+ pos += (size_t)rc;
+ if (pos > size) {
+ size = pos + BLOCKSIZE;
+ result = realloc(result, size + 1);
+ }
+ }
+ } while(rc > 0);
+
+ close(f);
+ if (length != NULL)
+ *length = pos;
+ result[pos] = 0;
+ return result;
+}
+
+static int load_json(const char *filename);
+static int process(const char *content, size_t length);
+static void close_json();
+
+int main(int ac, char **av)
+{
+ char *t, *f;
+ char *prog = *av;
+ int s;
+ size_t length;
+
+ (void)ac; /* unused */
+ flags = Mustach_With_AllExtensions;
+ output = stdout;
+
+ for( ++av ; av[0] && av[0][0] == '-' && av[0][1] != 0 ; av++) {
+ if (!strcmp(*av, "-h") || !strcmp(*av, "--help"))
+ help(prog);
+ if (!strcmp(*av, "-s") || !strcmp(*av, "--strict"))
+ flags |= Mustach_With_ErrorUndefined;
+ }
+ if (*av) {
+ f = (av[0][0] == '-' && !av[0][1]) ? "/dev/stdin" : av[0];
+ s = load_json(f);
+ if (s < 0) {
+ fprintf(stderr, "Can't load json file %s\n", av[0]);
+ if(errmsg)
+ fprintf(stderr, " reason: %s\n", errmsg);
+ exit(1);
+ }
+ while(*++av) {
+ t = readfile(*av, &length);
+ s = process(t, length);
+ free(t);
+ if (s != MUSTACH_OK) {
+ s = -s;
+ if (s < 1 || s >= (int)(sizeof errors / sizeof * errors))
+ s = 0;
+ fprintf(stderr, "Template error %s (file %s)\n", errors[s], *av);
+ }
+ }
+ close_json();
+ }
+ return 0;
+}
+
+#define MUSTACH_TOOL_JSON_C 1
+#define MUSTACH_TOOL_JANSSON 2
+#define MUSTACH_TOOL_CJSON 3
+
+#if TOOL == MUSTACH_TOOL_JSON_C
+
+#include "mustach-json-c.h"
+
+static struct json_object *o;
+static int load_json(const char *filename)
+{
+ o = json_object_from_file(filename);
+#if JSON_C_VERSION_NUM >= 0x000D00
+ errmsg = json_util_get_last_err();
+ if (errmsg != NULL)
+ return -1;
+#endif
+ if (o == NULL) {
+ errmsg = "null json";
+ return -1;
+ }
+ return 0;
+}
+static int process(const char *content, size_t length)
+{
+ return mustach_json_c_file(content, length, o, flags, output);
+}
+static void close_json()
+{
+ json_object_put(o);
+}
+
+#elif TOOL == MUSTACH_TOOL_JANSSON
+
+#include "mustach-jansson.h"
+
+static json_t *o;
+static json_error_t e;
+static int load_json(const char *filename)
+{
+ o = json_load_file(filename, JSON_DECODE_ANY, &e);
+ if (o == NULL) {
+ errmsg = e.text;
+ return -1;
+ }
+ return 0;
+}
+static int process(const char *content, size_t length)
+{
+ return mustach_jansson_file(content, length, o, flags, output);
+}
+static void close_json()
+{
+ json_decref(o);
+}
+
+#elif TOOL == MUSTACH_TOOL_CJSON
+
+#include "mustach-cjson.h"
+
+static cJSON *o;
+static int load_json(const char *filename)
+{
+ char *t;
+ size_t length;
+
+ t = readfile(filename, &length);
+ o = t ? cJSON_ParseWithLength(t, length) : NULL;
+ free(t);
+ return -!o;
+}
+static int process(const char *content, size_t length)
+{
+ return mustach_cJSON_file(content, length, o, flags, output);
+}
+static void close_json()
+{
+ cJSON_Delete(o);
+}
+
+#else
+#error "no defined json library"
+#endif
diff --git a/src/templating/mustach-wrap.c b/src/templating/mustach-wrap.c
new file mode 100644
index 000000000..2cd00db12
--- /dev/null
+++ b/src/templating/mustach-wrap.c
@@ -0,0 +1,482 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#ifdef _WIN32
+#include <malloc.h>
+#endif
+
+#include "mustach.h"
+#include "mustach-wrap.h"
+
+/*
+* It was stated that allowing to include files
+* through template is not safe when the mustache
+* template is open to any value because it could
+* create leaks (example: {{>/etc/passwd}}).
+*/
+#if MUSTACH_SAFE
+# undef MUSTACH_LOAD_TEMPLATE
+#elif !defined(MUSTACH_LOAD_TEMPLATE)
+# define MUSTACH_LOAD_TEMPLATE 1
+#endif
+
+#if !defined(INCLUDE_PARTIAL_EXTENSION)
+# define INCLUDE_PARTIAL_EXTENSION ".mustache"
+#endif
+
+/* global hook for partials */
+int (*mustach_wrap_get_partial)(const char *name, struct mustach_sbuf *sbuf) = NULL;
+
+/* internal structure for wrapping */
+struct wrap {
+ /* original interface */
+ const struct mustach_wrap_itf *itf;
+
+ /* original closure */
+ void *closure;
+
+ /* flags */
+ int flags;
+
+ /* emiter callback */
+ mustach_emit_cb_t *emitcb;
+
+ /* write callback */
+ mustach_write_cb_t *writecb;
+};
+
+/* length given by masking with 3 */
+enum comp {
+ C_no = 0,
+ C_eq = 1,
+ C_lt = 5,
+ C_le = 6,
+ C_gt = 9,
+ C_ge = 10
+};
+
+enum sel {
+ S_none = 0,
+ S_ok = 1,
+ S_objiter = 2,
+ S_ok_or_objiter = S_ok | S_objiter
+};
+
+static enum comp getcomp(char *head, int sflags)
+{
+ return (head[0] == '=' && (sflags & Mustach_With_Equal)) ? C_eq
+ : (head[0] == '<' && (sflags & Mustach_With_Compare)) ? (head[1] == '=' ? C_le : C_lt)
+ : (head[0] == '>' && (sflags & Mustach_With_Compare)) ? (head[1] == '=' ? C_ge : C_gt)
+ : C_no;
+}
+
+static char *keyval(char *head, int sflags, enum comp *comp)
+{
+ char *w, car, escaped;
+ enum comp k;
+
+ k = C_no;
+ w = head;
+ car = *head;
+ escaped = (sflags & Mustach_With_EscFirstCmp) && (getcomp(head, sflags) != C_no);
+ while (car && (escaped || (k = getcomp(head, sflags)) == C_no)) {
+ if (escaped)
+ escaped = 0;
+ else
+ escaped = ((sflags & Mustach_With_JsonPointer) ? car == '~' : car == '\\')
+ && (getcomp(head + 1, sflags) != C_no);
+ if (!escaped)
+ *w++ = car;
+ head++;
+ car = *head;
+ }
+ *w = 0;
+ *comp = k;
+ return k == C_no ? NULL : &head[k & 3];
+}
+
+static char *getkey(char **head, int sflags)
+{
+ char *result, *iter, *write, car;
+
+ car = *(iter = *head);
+ if (!car)
+ result = NULL;
+ else {
+ result = write = iter;
+ if (sflags & Mustach_With_JsonPointer)
+ {
+ while (car && car != '/') {
+ if (car == '~')
+ switch (iter[1]) {
+ case '1': car = '/'; /*@fallthrough@*/
+ case '0': iter++;
+ }
+ *write++ = car;
+ car = *++iter;
+ }
+ *write = 0;
+ while (car == '/')
+ car = *++iter;
+ }
+ else
+ {
+ while (car && car != '.') {
+ if (car == '\\' && (iter[1] == '.' || iter[1] == '\\'))
+ car = *++iter;
+ *write++ = car;
+ car = *++iter;
+ }
+ *write = 0;
+ while (car == '.')
+ car = *++iter;
+ }
+ *head = iter;
+ }
+ return result;
+}
+
+static enum sel sel(struct wrap *w, const char *name)
+{
+ enum sel result;
+ int i, j, sflags, scmp;
+ char *key, *value;
+ enum comp k;
+
+ /* make a local writeable copy */
+ size_t lenname = 1 + strlen(name);
+ char buffer[lenname];
+ char *copy = buffer;
+ memcpy(copy, name, lenname);
+
+ /* check if matches json pointer selection */
+ sflags = w->flags;
+ if (sflags & Mustach_With_JsonPointer) {
+ if (copy[0] == '/')
+ copy++;
+ else
+ sflags ^= Mustach_With_JsonPointer;
+ }
+
+ /* extract the value, translate the key and get the comparator */
+ if (sflags & (Mustach_With_Equal | Mustach_With_Compare))
+ value = keyval(copy, sflags, &k);
+ else {
+ k = C_no;
+ value = NULL;
+ }
+
+ /* case of . alone if Mustach_With_SingleDot? */
+ if (copy[0] == '.' && copy[1] == 0 /*&& (sflags & Mustach_With_SingleDot)*/)
+ /* yes, select current */
+ result = w->itf->sel(w->closure, NULL) ? S_ok : S_none;
+ else
+ {
+ /* not the single dot, extract the first key */
+ key = getkey(&copy, sflags);
+ if (key == NULL)
+ return 0;
+
+ /* select the root item */
+ if (w->itf->sel(w->closure, key))
+ result = S_ok;
+ else if (key[0] == '*'
+ && !key[1]
+ && !value
+ && !*copy
+ && (w->flags & Mustach_With_ObjectIter)
+ && w->itf->sel(w->closure, NULL))
+ result = S_ok_or_objiter;
+ else
+ result = S_none;
+ if (result == S_ok) {
+ /* iterate the selection of sub items */
+ key = getkey(&copy, sflags);
+ while(result == S_ok && key) {
+ if (w->itf->subsel(w->closure, key))
+ /* nothing */;
+ else if (key[0] == '*'
+ && !key[1]
+ && !value
+ && !*copy
+ && (w->flags & Mustach_With_ObjectIter))
+ result = S_objiter;
+ else
+ result = S_none;
+ key = getkey(&copy, sflags);
+ }
+ }
+ }
+ /* should it be compared? */
+ if (result == S_ok && value) {
+ if (!w->itf->compare)
+ result = S_none;
+ else {
+ i = value[0] == '!';
+ scmp = w->itf->compare(w->closure, &value[i]);
+ switch (k) {
+ case C_eq: j = scmp == 0; break;
+ case C_lt: j = scmp < 0; break;
+ case C_le: j = scmp <= 0; break;
+ case C_gt: j = scmp > 0; break;
+ case C_ge: j = scmp >= 0; break;
+ default: j = i; break;
+ }
+ if (i == j)
+ result = S_none;
+ }
+ }
+ return result;
+}
+
+static int start_callback(void *closure)
+{
+ struct wrap *w = closure;
+ return w->itf->start ? w->itf->start(w->closure) : MUSTACH_OK;
+}
+
+static void stop_callback(void *closure, int status)
+{
+ struct wrap *w = closure;
+ if (w->itf->stop)
+ w->itf->stop(w->closure, status);
+}
+
+static int emit(struct wrap *w, const char *buffer, size_t size, FILE *file)
+{
+ int r;
+
+ if (w->writecb)
+ r = w->writecb(file, buffer, size);
+ else
+ r = fwrite(buffer, 1, size, file) == size ? MUSTACH_OK : MUSTACH_ERROR_SYSTEM;
+ return r;
+}
+
+static int emit_callback(void *closure, const char *buffer, size_t size, int escape, FILE *file)
+{
+ struct wrap *w = closure;
+ int r;
+ size_t s, i;
+ char car;
+
+ if (w->emitcb)
+ r = w->emitcb(file, buffer, size, escape);
+ else if (!escape)
+ r = emit(w, buffer, size, file);
+ else {
+ i = 0;
+ r = MUSTACH_OK;
+ while(i < size && r == MUSTACH_OK) {
+ s = i;
+ while (i < size && (car = buffer[i]) != '<' && car != '>' && car != '&' && car != '"')
+ i++;
+ if (i != s)
+ r = emit(w, &buffer[s], i - s, file);
+ if (i < size && r == MUSTACH_OK) {
+ switch(car) {
+ case '<': r = emit(w, "&lt;", 4, file); break;
+ case '>': r = emit(w, "&gt;", 4, file); break;
+ case '&': r = emit(w, "&amp;", 5, file); break;
+ case '"': r = emit(w, "&quot;", 6, file); break;
+ }
+ i++;
+ }
+ }
+ }
+ return r;
+}
+
+static int enter_callback(void *closure, const char *name)
+{
+ struct wrap *w = closure;
+ enum sel s = sel(w, name);
+ return s == S_none ? 0 : w->itf->enter(w->closure, s & S_objiter);
+}
+
+static int next_callback(void *closure)
+{
+ struct wrap *w = closure;
+ return w->itf->next(w->closure);
+}
+
+static int leave_callback(void *closure)
+{
+ struct wrap *w = closure;
+ return w->itf->leave(w->closure);
+}
+
+static int getoptional(struct wrap *w, const char *name, struct mustach_sbuf *sbuf)
+{
+ enum sel s = sel(w, name);
+ if (!(s & S_ok))
+ return 0;
+ return w->itf->get(w->closure, sbuf, s & S_objiter);
+}
+
+static int get_callback(void *closure, const char *name, struct mustach_sbuf *sbuf)
+{
+ struct wrap *w = closure;
+ if (getoptional(w, name, sbuf) <= 0) {
+ if (w->flags & Mustach_With_ErrorUndefined)
+ return MUSTACH_ERROR_UNDEFINED_TAG;
+ sbuf->value = "";
+ }
+ return MUSTACH_OK;
+}
+
+#if MUSTACH_LOAD_TEMPLATE
+static int get_partial_from_file(const char *name, struct mustach_sbuf *sbuf)
+{
+ static char extension[] = INCLUDE_PARTIAL_EXTENSION;
+ size_t s;
+ long pos;
+ FILE *file;
+ char *path, *buffer;
+
+ /* allocate path */
+ s = strlen(name);
+ path = malloc(s + sizeof extension);
+ if (path == NULL)
+ return MUSTACH_ERROR_SYSTEM;
+
+ /* try without extension first */
+ memcpy(path, name, s + 1);
+ file = fopen(path, "r");
+ if (file == NULL) {
+ memcpy(&path[s], extension, sizeof extension);
+ file = fopen(path, "r");
+ }
+ free(path);
+
+ /* if file opened */
+ if (file == NULL)
+ return MUSTACH_ERROR_PARTIAL_NOT_FOUND;
+
+ /* compute file size */
+ if (fseek(file, 0, SEEK_END) >= 0
+ && (pos = ftell(file)) >= 0
+ && fseek(file, 0, SEEK_SET) >= 0) {
+ /* allocate value */
+ s = (size_t)pos;
+ buffer = malloc(s + 1);
+ if (buffer != NULL) {
+ /* read value */
+ if (1 == fread(buffer, s, 1, file)) {
+ /* force zero at end */
+ sbuf->value = buffer;
+ buffer[s] = 0;
+ sbuf->freecb = free;
+ fclose(file);
+ return MUSTACH_OK;
+ }
+ free(buffer);
+ }
+ }
+ fclose(file);
+ return MUSTACH_ERROR_SYSTEM;
+}
+#endif
+
+static int partial_callback(void *closure, const char *name, struct mustach_sbuf *sbuf)
+{
+ struct wrap *w = closure;
+ int rc;
+ if (mustach_wrap_get_partial != NULL) {
+ rc = mustach_wrap_get_partial(name, sbuf);
+ if (rc != MUSTACH_ERROR_PARTIAL_NOT_FOUND) {
+ if (rc != MUSTACH_OK)
+ sbuf->value = "";
+ return rc;
+ }
+ }
+#if MUSTACH_LOAD_TEMPLATE
+ if (w->flags & Mustach_With_PartialDataFirst) {
+ if (getoptional(w, name, sbuf) > 0)
+ rc = MUSTACH_OK;
+ else
+ rc = get_partial_from_file(name, sbuf);
+ }
+ else {
+ rc = get_partial_from_file(name, sbuf);
+ if (rc != MUSTACH_OK && getoptional(w, name, sbuf) > 0)
+ rc = MUSTACH_OK;
+ }
+#else
+ rc = getoptional(w, name, sbuf) > 0 ? MUSTACH_OK : MUSTACH_ERROR_PARTIAL_NOT_FOUND;
+#endif
+ if (rc != MUSTACH_OK)
+ sbuf->value = "";
+ return MUSTACH_OK;
+}
+
+const struct mustach_itf mustach_wrap_itf = {
+ .start = start_callback,
+ .put = NULL,
+ .enter = enter_callback,
+ .next = next_callback,
+ .leave = leave_callback,
+ .partial = partial_callback,
+ .get = get_callback,
+ .emit = emit_callback,
+ .stop = stop_callback
+};
+
+static void wrap_init(struct wrap *wrap, const struct mustach_wrap_itf *itf, void *closure, int flags, mustach_emit_cb_t *emitcb, mustach_write_cb_t *writecb)
+{
+ if (flags & Mustach_With_Compare)
+ flags |= Mustach_With_Equal;
+ wrap->closure = closure;
+ wrap->itf = itf;
+ wrap->flags = flags;
+ wrap->emitcb = emitcb;
+ wrap->writecb = writecb;
+}
+
+int mustach_wrap_file(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, FILE *file)
+{
+ struct wrap w;
+ wrap_init(&w, itf, closure, flags, NULL, NULL);
+ return mustach_file(template, length, &mustach_wrap_itf, &w, flags, file);
+}
+
+int mustach_wrap_fd(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, int fd)
+{
+ struct wrap w;
+ wrap_init(&w, itf, closure, flags, NULL, NULL);
+ return mustach_fd(template, length, &mustach_wrap_itf, &w, flags, fd);
+}
+
+int mustach_wrap_mem(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, char **result, size_t *size)
+{
+ struct wrap w;
+ wrap_init(&w, itf, closure, flags, NULL, NULL);
+ return mustach_mem(template, length, &mustach_wrap_itf, &w, flags, result, size);
+}
+
+int mustach_wrap_write(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, mustach_write_cb_t *writecb, void *writeclosure)
+{
+ struct wrap w;
+ wrap_init(&w, itf, closure, flags, NULL, writecb);
+ return mustach_file(template, length, &mustach_wrap_itf, &w, flags, writeclosure);
+}
+
+int mustach_wrap_emit(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, mustach_emit_cb_t *emitcb, void *emitclosure)
+{
+ struct wrap w;
+ wrap_init(&w, itf, closure, flags, emitcb, NULL);
+ return mustach_file(template, length, &mustach_wrap_itf, &w, flags, emitclosure);
+}
+
diff --git a/src/templating/mustach-wrap.h b/src/templating/mustach-wrap.h
new file mode 100644
index 000000000..fedcb9191
--- /dev/null
+++ b/src/templating/mustach-wrap.h
@@ -0,0 +1,235 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _mustach_wrap_h_included_
+#define _mustach_wrap_h_included_
+
+/*
+ * mustach-wrap is intended to make integration of JSON
+ * libraries easier by wrapping mustach extensions in a
+ * single place.
+ *
+ * As before, using mustach and only mustach is possible
+ * (by using only mustach.h) but does not implement high
+ * level features coming with extensions implemented by
+ * this high level wrapper.
+ */
+#include "mustach.h"
+/*
+ * Definition of the writing callbacks for mustach functions
+ * producing output to callbacks.
+ *
+ * Two callback types are defined:
+ *
+ * @mustach_write_cb_t:
+ *
+ * callback receiving the escaped data to be written as 3 parameters:
+ *
+ * 1. the 'closure', the same given to the wmustach_... function
+ * 2. a pointer to a 'buffer' containing the characters to be written
+ * 3. the size in bytes of the data pointed by 'buffer'
+ *
+ * @mustach_emit_cb_t:
+ *
+ * callback receiving the data to be written and a flag indicating
+ * if escaping should be done or not as 4 parameters:
+ *
+ * 1. the 'closure', the same given to the emustach_... function
+ * 2. a pointer to a 'buffer' containing the characters to be written
+ * 3. the size in bytes of the data pointed by 'buffer'
+ * 4. a boolean indicating if 'escape' should be done
+ */
+#ifndef _mustach_output_callbacks_defined_
+#define _mustach_output_callbacks_defined_
+typedef int mustach_write_cb_t(void *closure, const char *buffer, size_t size);
+typedef int mustach_emit_cb_t(void *closure, const char *buffer, size_t size, int escape);
+#endif
+
+/**
+ * Flags specific to mustach wrap
+ */
+#define Mustach_With_SingleDot 4 /* obsolete, always set */
+#define Mustach_With_Equal 8
+#define Mustach_With_Compare 16
+#define Mustach_With_JsonPointer 32
+#define Mustach_With_ObjectIter 64
+#define Mustach_With_IncPartial 128 /* obsolete, always set */
+#define Mustach_With_EscFirstCmp 256
+#define Mustach_With_PartialDataFirst 512
+#define Mustach_With_ErrorUndefined 1024
+
+#undef Mustach_With_AllExtensions
+#define Mustach_With_AllExtensions 1023 /* don't include ErrorUndefined */
+
+/**
+ * mustach_wrap_itf - high level wrap of mustach - interface for callbacks
+ *
+ * The functions sel, subsel, enter and next should return 0 or 1.
+ *
+ * All other functions should normally return MUSTACH_OK (zero).
+ *
+ * If any function returns a negative value, it means an error that
+ * stop the processing and that is reported to the caller. Mustach
+ * also has its own error codes. Using the macros MUSTACH_ERROR_USER
+ * and MUSTACH_IS_ERROR_USER could help to avoid clashes.
+ *
+ * @start: If defined (can be NULL), starts the mustach processing
+ * of the closure, called at the very beginning before any
+ * mustach processing occurs.
+ *
+ * @stop: If defined (can be NULL), stops the mustach processing
+ * of the closure, called at the very end after all mustach
+ * processing occurered. The status returned by the processing
+ * is passed to the stop.
+ *
+ * @compare: If defined (can be NULL), compares the value of the
+ * currently selected item with the given value and returns
+ * a negative value if current value is lesser, a positive
+ * value if the current value is greater or zero when
+ * values are equals.
+ * If 'compare' is NULL, any comparison in mustach
+ * is going to fails.
+ *
+ * @sel: Selects the item of the given 'name'. If 'name' is NULL
+ * Selects the current item. Returns 1 if the selection is
+ * effective or else 0 if the selection failed.
+ *
+ * @subsel: Selects from the currently selected object the value of
+ * the field of given name. Returns 1 if the selection is
+ * effective or else 0 if the selection failed.
+ *
+ * @enter: Enters the section of 'name' if possible.
+ * Musts return 1 if entered or 0 if not entered.
+ * When 1 is returned, the function 'leave' will always be called.
+ * Conversely 'leave' is never called when enter returns 0 or
+ * a negative value.
+ * When 1 is returned, the function must activate the first
+ * item of the section.
+ *
+ * @next: Activates the next item of the section if it exists.
+ * Musts return 1 when the next item is activated.
+ * Musts return 0 when there is no item to activate.
+ *
+ * @leave: Leaves the last entered section
+ *
+ * @get: Returns in 'sbuf' the value of the current selection if 'key'
+ * is zero. Otherwise, when 'key' is not zero, return in 'sbuf'
+ * the name of key of the current selection, or if no such key
+ * exists, the empty string. Must return 1 if possible or
+ * 0 when not possible or an error code.
+ */
+struct mustach_wrap_itf {
+ int (*start)(void *closure);
+ void (*stop)(void *closure, int status);
+ int (*compare)(void *closure, const char *value);
+ int (*sel)(void *closure, const char *name);
+ int (*subsel)(void *closure, const char *name);
+ int (*enter)(void *closure, int objiter);
+ int (*next)(void *closure);
+ int (*leave)(void *closure);
+ int (*get)(void *closure, struct mustach_sbuf *sbuf, int key);
+};
+
+/**
+ * Mustach interface used internally by mustach wrapper functions.
+ * Can be used for overriding behaviour.
+ */
+extern const struct mustach_itf mustach_wrap_itf;
+
+/**
+ * Global hook for providing partials. When set to a not NULL value, the pointed
+ * function replaces the default behaviour and is called to provide the partial
+ * of the given 'name' in 'sbuf'.
+ * The function must return MUSTACH_OK when it filled 'sbuf' with value of partial
+ * or must return an error code if it failed. But if MUSTACH_ERROR_PARTIAL_NOT_FOUND
+ * is returned, the default behavior is evaluated.
+ */
+extern int (*mustach_wrap_get_partial)(const char *name, struct mustach_sbuf *sbuf);
+
+/**
+ * mustach_wrap_file - Renders the mustache 'template' in 'file' for an abstract
+ * wrapper of interface 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface of the abstract wrapper
+ * @closure: the closure of the abstract wrapper
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_wrap_file(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, FILE *file);
+
+/**
+ * mustach_wrap_fd - Renders the mustache 'template' in 'fd' for an abstract
+ * wrapper of interface 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface of the abstract wrapper
+ * @closure: the closure of the abstract wrapper
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_wrap_fd(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, int fd);
+
+/**
+ * mustach_wrap_mem - Renders the mustache 'template' in 'result' for an abstract
+ * wrapper of interface 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface of the abstract wrapper
+ * @closure: the closure of the abstract wrapper
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_wrap_mem(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, char **result, size_t *size);
+
+/**
+ * mustach_wrap_write - Renders the mustache 'template' for an abstract
+ * wrapper of interface 'itf' and 'closure' to custom writer
+ * 'writecb' with 'writeclosure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface of the abstract wrapper
+ * @closure: the closure of the abstract wrapper
+ * @writecb: the function that write values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_wrap_write(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, mustach_write_cb_t *writecb, void *writeclosure);
+
+/**
+ * mustach_wrap_emit - Renders the mustache 'template' for an abstract
+ * wrapper of interface 'itf' and 'closure' to custom emiter 'emitcb'
+ * with 'emitclosure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface of the abstract wrapper
+ * @closure: the closure of the abstract wrapper
+ * @emitcb: the function that emit values
+ * @closure: the closure for the write function
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_wrap_emit(const char *template, size_t length, const struct mustach_wrap_itf *itf, void *closure, int flags, mustach_emit_cb_t *emitcb, void *emitclosure);
+
+#endif
+
diff --git a/src/templating/mustach.1.gz b/src/templating/mustach.1.gz
new file mode 100644
index 000000000..15b8a9052
--- /dev/null
+++ b/src/templating/mustach.1.gz
Binary files differ
diff --git a/src/templating/mustach.1.scd b/src/templating/mustach.1.scd
new file mode 100644
index 000000000..af4f08ef2
--- /dev/null
+++ b/src/templating/mustach.1.scd
@@ -0,0 +1,60 @@
+mustach(1)
+
+# NAME
+
+mustach - Mustache templating command line engine
+
+# SYNOPSIS
+
+*mustach* [-s|--strict] JSON TEMPLATE...
+
+# DESCRIPTION
+
+Instanciate the TEMPLATE files accordingly to the JSON file.
+
+If one of the given files is *-*, the standard input is used.
+
+Option *--strict* make mustach fail if a tag is not found.
+
+# EXAMPLE
+
+A typical Mustache template file: *temp.must*
+
+```
+Hello {{name}}
+You have just won {{value}} dollars!
+{{#in_ca}}
+Well, {{taxed_value}} dollars, after taxes.
+{{/in_ca}}
+```
+
+Given a JSON file: *inst.json*
+
+```
+{
+ "name": "Chris",
+ "value": 10000,
+ "taxed_value": 6000,
+ "in_ca": true
+}
+```
+
+Calling the command *mustach inst.json temp.must*
+will produce the following output:
+
+```
+Hello Chris
+You have just won 10000 dollars!
+Well, 6000.0 dollars, after taxes.
+```
+
+# LINK
+
+Site of *mustach*, the *C* implementation: https://gitlab.com/jobol/mustach
+
+*Mustache format*: http://mustache.github.io/mustache.5.html
+
+Main site for *Mustache*: http://mustache.github.io/
+
+JSON: https://www.json.org/
+
diff --git a/src/templating/mustach.c b/src/templating/mustach.c
new file mode 100644
index 000000000..9f5af131c
--- /dev/null
+++ b/src/templating/mustach.c
@@ -0,0 +1,561 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#ifdef _WIN32
+#include <malloc.h>
+#endif
+
+#include "mustach.h"
+
+struct iwrap {
+ int (*emit)(void *closure, const char *buffer, size_t size, int escape, FILE *file);
+ void *closure; /* closure for: enter, next, leave, emit, get */
+ int (*put)(void *closure, const char *name, int escape, FILE *file);
+ void *closure_put; /* closure for put */
+ int (*enter)(void *closure, const char *name);
+ int (*next)(void *closure);
+ int (*leave)(void *closure);
+ int (*get)(void *closure, const char *name, struct mustach_sbuf *sbuf);
+ int (*partial)(void *closure, const char *name, struct mustach_sbuf *sbuf);
+ void *closure_partial; /* closure for partial */
+ FILE *file;
+ int flags;
+ int nesting;
+};
+
+struct prefix {
+ size_t len;
+ const char *start;
+ struct prefix *prefix;
+};
+
+#if !defined(NO_OPEN_MEMSTREAM)
+static FILE *memfile_open(char **buffer, size_t *size)
+{
+ return open_memstream(buffer, size);
+}
+static void memfile_abort(FILE *file, char **buffer, size_t *size)
+{
+ fclose(file);
+ free(*buffer);
+ *buffer = NULL;
+ *size = 0;
+}
+static int memfile_close(FILE *file, char **buffer, size_t *size)
+{
+ int rc;
+
+ /* adds terminating null */
+ rc = fputc(0, file) ? MUSTACH_ERROR_SYSTEM : 0;
+ fclose(file);
+ if (rc == 0)
+ /* removes terminating null of the length */
+ (*size)--;
+ else {
+ free(*buffer);
+ *buffer = NULL;
+ *size = 0;
+ }
+ return rc;
+}
+#else
+static FILE *memfile_open(char **buffer, size_t *size)
+{
+ /*
+ * We can't provide *buffer and *size as open_memstream does but
+ * at least clear them so the caller won't get bad data.
+ */
+ *buffer = NULL;
+ *size = 0;
+
+ return tmpfile();
+}
+static void memfile_abort(FILE *file, char **buffer, size_t *size)
+{
+ fclose(file);
+ *buffer = NULL;
+ *size = 0;
+}
+static int memfile_close(FILE *file, char **buffer, size_t *size)
+{
+ int rc;
+ size_t s;
+ char *b;
+
+ s = (size_t)ftell(file);
+ b = malloc(s + 1);
+ if (b == NULL) {
+ rc = MUSTACH_ERROR_SYSTEM;
+ errno = ENOMEM;
+ s = 0;
+ } else {
+ rewind(file);
+ if (1 == fread(b, s, 1, file)) {
+ rc = 0;
+ b[s] = 0;
+ } else {
+ rc = MUSTACH_ERROR_SYSTEM;
+ free(b);
+ b = NULL;
+ s = 0;
+ }
+ }
+ *buffer = b;
+ *size = s;
+ return rc;
+}
+#endif
+
+static inline void sbuf_reset(struct mustach_sbuf *sbuf)
+{
+ sbuf->value = NULL;
+ sbuf->freecb = NULL;
+ sbuf->closure = NULL;
+ sbuf->length = 0;
+}
+
+static inline void sbuf_release(struct mustach_sbuf *sbuf)
+{
+ if (sbuf->releasecb)
+ sbuf->releasecb(sbuf->value, sbuf->closure);
+}
+
+static inline size_t sbuf_length(struct mustach_sbuf *sbuf)
+{
+ size_t length = sbuf->length;
+ if (length == 0 && sbuf->value != NULL)
+ length = strlen(sbuf->value);
+ return length;
+}
+
+static int iwrap_emit(void *closure, const char *buffer, size_t size, int escape, FILE *file)
+{
+ size_t i, j, r;
+
+ (void)closure; /* unused */
+
+ if (!escape)
+ return fwrite(buffer, 1, size, file) != size ? MUSTACH_ERROR_SYSTEM : MUSTACH_OK;
+
+ r = i = 0;
+ while (i < size) {
+ j = i;
+ while (j < size && buffer[j] != '<' && buffer[j] != '>' && buffer[j] != '&' && buffer[j] != '"')
+ j++;
+ if (j != i && fwrite(&buffer[i], j - i, 1, file) != 1)
+ return MUSTACH_ERROR_SYSTEM;
+ if (j < size) {
+ switch(buffer[j++]) {
+ case '<':
+ r = fwrite("&lt;", 4, 1, file);
+ break;
+ case '>':
+ r = fwrite("&gt;", 4, 1, file);
+ break;
+ case '&':
+ r = fwrite("&amp;", 5, 1, file);
+ break;
+ case '"':
+ r = fwrite("&quot;", 6, 1, file);
+ break;
+ }
+ if (r != 1)
+ return MUSTACH_ERROR_SYSTEM;
+ }
+ i = j;
+ }
+ return MUSTACH_OK;
+}
+
+static int iwrap_put(void *closure, const char *name, int escape, FILE *file)
+{
+ struct iwrap *iwrap = closure;
+ int rc;
+ struct mustach_sbuf sbuf;
+ size_t length;
+
+ sbuf_reset(&sbuf);
+ rc = iwrap->get(iwrap->closure, name, &sbuf);
+ if (rc >= 0) {
+ length = sbuf_length(&sbuf);
+ if (length)
+ rc = iwrap->emit(iwrap->closure, sbuf.value, length, escape, file);
+ sbuf_release(&sbuf);
+ }
+ return rc;
+}
+
+static int iwrap_partial(void *closure, const char *name, struct mustach_sbuf *sbuf)
+{
+ struct iwrap *iwrap = closure;
+ int rc;
+ FILE *file;
+ size_t size;
+ char *result;
+
+ result = NULL;
+ file = memfile_open(&result, &size);
+ if (file == NULL)
+ rc = MUSTACH_ERROR_SYSTEM;
+ else {
+ rc = iwrap->put(iwrap->closure_put, name, 0, file);
+ if (rc < 0)
+ memfile_abort(file, &result, &size);
+ else {
+ rc = memfile_close(file, &result, &size);
+ if (rc == 0) {
+ sbuf->value = result;
+ sbuf->freecb = free;
+ sbuf->length = size;
+ }
+ }
+ }
+ return rc;
+}
+
+static int emitprefix(struct iwrap *iwrap, struct prefix *prefix)
+{
+ if (prefix->prefix) {
+ int rc = emitprefix(iwrap, prefix->prefix);
+ if (rc < 0)
+ return rc;
+ }
+ return prefix->len ? iwrap->emit(iwrap->closure, prefix->start, prefix->len, 0, iwrap->file) : 0;
+}
+
+static int process(const char *template, size_t length, struct iwrap *iwrap, struct prefix *prefix)
+{
+ struct mustach_sbuf sbuf;
+ char opstr[MUSTACH_MAX_DELIM_LENGTH], clstr[MUSTACH_MAX_DELIM_LENGTH];
+ char name[MUSTACH_MAX_LENGTH + 1], c;
+ const char *beg, *term, *end;
+ struct { const char *name, *again; size_t length; unsigned enabled: 1, entered: 1; } stack[MUSTACH_MAX_DEPTH];
+ size_t oplen, cllen, len, l;
+ int depth, rc, enabled, stdalone;
+ struct prefix pref;
+
+ pref.prefix = prefix;
+ end = template + (length ? length : strlen(template));
+ opstr[0] = opstr[1] = '{';
+ clstr[0] = clstr[1] = '}';
+ oplen = cllen = 2;
+ stdalone = enabled = 1;
+ depth = pref.len = 0;
+ for (;;) {
+ /* search next openning delimiter */
+ for (beg = template ; ; beg++) {
+ c = beg == end ? '\n' : *beg;
+ if (c == '\n') {
+ l = (beg != end) + (size_t)(beg - template);
+ if (stdalone != 2 && enabled) {
+ if (beg != template /* don't prefix empty lines */) {
+ rc = emitprefix(iwrap, &pref);
+ if (rc < 0)
+ return rc;
+ }
+ rc = iwrap->emit(iwrap->closure, template, l, 0, iwrap->file);
+ if (rc < 0)
+ return rc;
+ }
+ if (beg == end) /* no more mustach */
+ return depth ? MUSTACH_ERROR_UNEXPECTED_END : MUSTACH_OK;
+ template += l;
+ stdalone = 1;
+ pref.len = 0;
+ pref.prefix = prefix;
+ }
+ else if (!isspace(c)) {
+ if (stdalone == 2 && enabled) {
+ rc = emitprefix(iwrap, &pref);
+ if (rc < 0)
+ return rc;
+ pref.len = 0;
+ stdalone = 0;
+ pref.prefix = NULL;
+ }
+ if (c == *opstr && end - beg >= (ssize_t)oplen) {
+ for (l = 1 ; l < oplen && beg[l] == opstr[l] ; l++);
+ if (l == oplen)
+ break;
+ }
+ stdalone = 0;
+ }
+ }
+
+ pref.start = template;
+ pref.len = enabled ? (size_t)(beg - template) : 0;
+ beg += oplen;
+
+ /* search next closing delimiter */
+ for (term = beg ; ; term++) {
+ if (term == end)
+ return MUSTACH_ERROR_UNEXPECTED_END;
+ if (*term == *clstr && end - term >= (ssize_t)cllen) {
+ for (l = 1 ; l < cllen && term[l] == clstr[l] ; l++);
+ if (l == cllen)
+ break;
+ }
+ }
+ template = term + cllen;
+ len = (size_t)(term - beg);
+ c = *beg;
+ switch(c) {
+ case ':':
+ stdalone = 0;
+ if (iwrap->flags & Mustach_With_Colon)
+ goto exclude_first;
+ goto get_name;
+ case '!':
+ case '=':
+ break;
+ case '{':
+ for (l = 0 ; l < cllen && clstr[l] == '}' ; l++);
+ if (l < cllen) {
+ if (!len || beg[len-1] != '}')
+ return MUSTACH_ERROR_BAD_UNESCAPE_TAG;
+ len--;
+ } else {
+ if (term[l] != '}')
+ return MUSTACH_ERROR_BAD_UNESCAPE_TAG;
+ template++;
+ }
+ c = '&';
+ /*@fallthrough@*/
+ case '&':
+ stdalone = 0;
+ /*@fallthrough@*/
+ case '^':
+ case '#':
+ case '/':
+ case '>':
+exclude_first:
+ beg++;
+ len--;
+ goto get_name;
+ default:
+ stdalone = 0;
+get_name:
+ while (len && isspace(beg[0])) { beg++; len--; }
+ while (len && isspace(beg[len-1])) len--;
+ if (len == 0 && !(iwrap->flags & Mustach_With_EmptyTag))
+ return MUSTACH_ERROR_EMPTY_TAG;
+ if (len > MUSTACH_MAX_LENGTH)
+ return MUSTACH_ERROR_TAG_TOO_LONG;
+ memcpy(name, beg, len);
+ name[len] = 0;
+ break;
+ }
+ if (stdalone)
+ stdalone = 2;
+ else if (enabled) {
+ rc = emitprefix(iwrap, &pref);
+ if (rc < 0)
+ return rc;
+ pref.len = 0;
+ pref.prefix = NULL;
+ }
+ switch(c) {
+ case '!':
+ /* comment */
+ /* nothing to do */
+ break;
+ case '=':
+ /* defines delimiters */
+ if (len < 5 || beg[len - 1] != '=')
+ return MUSTACH_ERROR_BAD_SEPARATORS;
+ beg++;
+ len -= 2;
+ while (len && isspace(*beg))
+ beg++, len--;
+ while (len && isspace(beg[len - 1]))
+ len--;
+ for (l = 0; l < len && !isspace(beg[l]) ; l++);
+ if (l == len || l > MUSTACH_MAX_DELIM_LENGTH)
+ return MUSTACH_ERROR_BAD_SEPARATORS;
+ oplen = l;
+ memcpy(opstr, beg, l);
+ while (l < len && isspace(beg[l])) l++;
+ if (l == len || len - l > MUSTACH_MAX_DELIM_LENGTH)
+ return MUSTACH_ERROR_BAD_SEPARATORS;
+ cllen = len - l;
+ memcpy(clstr, beg + l, cllen);
+ break;
+ case '^':
+ case '#':
+ /* begin section */
+ if (depth == MUSTACH_MAX_DEPTH)
+ return MUSTACH_ERROR_TOO_DEEP;
+ rc = enabled;
+ if (rc) {
+ rc = iwrap->enter(iwrap->closure, name);
+ if (rc < 0)
+ return rc;
+ }
+ stack[depth].name = beg;
+ stack[depth].again = template;
+ stack[depth].length = len;
+ stack[depth].enabled = enabled != 0;
+ stack[depth].entered = rc != 0;
+ if ((c == '#') == (rc == 0))
+ enabled = 0;
+ depth++;
+ break;
+ case '/':
+ /* end section */
+ if (depth-- == 0 || len != stack[depth].length || memcmp(stack[depth].name, name, len))
+ return MUSTACH_ERROR_CLOSING;
+ rc = enabled && stack[depth].entered ? iwrap->next(iwrap->closure) : 0;
+ if (rc < 0)
+ return rc;
+ if (rc) {
+ template = stack[depth++].again;
+ } else {
+ enabled = stack[depth].enabled;
+ if (enabled && stack[depth].entered)
+ iwrap->leave(iwrap->closure);
+ }
+ break;
+ case '>':
+ /* partials */
+ if (enabled) {
+ if (iwrap->nesting >= MUSTACH_MAX_NESTING)
+ rc = MUSTACH_ERROR_TOO_MUCH_NESTING;
+ else {
+ sbuf_reset(&sbuf);
+ rc = iwrap->partial(iwrap->closure_partial, name, &sbuf);
+ if (rc >= 0) {
+ iwrap->nesting++;
+ rc = process(sbuf.value, sbuf_length(&sbuf), iwrap, &pref);
+ sbuf_release(&sbuf);
+ iwrap->nesting--;
+ }
+ }
+ if (rc < 0)
+ return rc;
+ }
+ break;
+ default:
+ /* replacement */
+ if (enabled) {
+ rc = iwrap->put(iwrap->closure_put, name, c != '&', iwrap->file);
+ if (rc < 0)
+ return rc;
+ }
+ break;
+ }
+ }
+}
+
+int mustach_file(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, FILE *file)
+{
+ int rc;
+ struct iwrap iwrap;
+
+ /* check validity */
+ if (!itf->enter || !itf->next || !itf->leave || (!itf->put && !itf->get))
+ return MUSTACH_ERROR_INVALID_ITF;
+
+ /* init wrap structure */
+ iwrap.closure = closure;
+ if (itf->put) {
+ iwrap.put = itf->put;
+ iwrap.closure_put = closure;
+ } else {
+ iwrap.put = iwrap_put;
+ iwrap.closure_put = &iwrap;
+ }
+ if (itf->partial) {
+ iwrap.partial = itf->partial;
+ iwrap.closure_partial = closure;
+ } else if (itf->get) {
+ iwrap.partial = itf->get;
+ iwrap.closure_partial = closure;
+ } else {
+ iwrap.partial = iwrap_partial;
+ iwrap.closure_partial = &iwrap;
+ }
+ iwrap.emit = itf->emit ? itf->emit : iwrap_emit;
+ iwrap.enter = itf->enter;
+ iwrap.next = itf->next;
+ iwrap.leave = itf->leave;
+ iwrap.get = itf->get;
+ iwrap.file = file;
+ iwrap.flags = flags;
+ iwrap.nesting = 0;
+
+ /* process */
+ rc = itf->start ? itf->start(closure) : 0;
+ if (rc == 0)
+ rc = process(template, length, &iwrap, NULL);
+ if (itf->stop)
+ itf->stop(closure, rc);
+ return rc;
+}
+
+int mustach_fd(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, int fd)
+{
+ int rc;
+ FILE *file;
+
+ file = fdopen(fd, "w");
+ if (file == NULL) {
+ rc = MUSTACH_ERROR_SYSTEM;
+ errno = ENOMEM;
+ } else {
+ rc = mustach_file(template, length, itf, closure, flags, file);
+ fclose(file);
+ }
+ return rc;
+}
+
+int mustach_mem(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, char **result, size_t *size)
+{
+ int rc;
+ FILE *file;
+ size_t s;
+
+ *result = NULL;
+ if (size == NULL)
+ size = &s;
+ file = memfile_open(result, size);
+ if (file == NULL)
+ rc = MUSTACH_ERROR_SYSTEM;
+ else {
+ rc = mustach_file(template, length, itf, closure, flags, file);
+ if (rc < 0)
+ memfile_abort(file, result, size);
+ else
+ rc = memfile_close(file, result, size);
+ }
+ return rc;
+}
+
+int fmustach(const char *template, const struct mustach_itf *itf, void *closure, FILE *file)
+{
+ return mustach_file(template, 0, itf, closure, Mustach_With_AllExtensions, file);
+}
+
+int fdmustach(const char *template, const struct mustach_itf *itf, void *closure, int fd)
+{
+ return mustach_fd(template, 0, itf, closure, Mustach_With_AllExtensions, fd);
+}
+
+int mustach(const char *template, const struct mustach_itf *itf, void *closure, char **result, size_t *size)
+{
+ return mustach_mem(template, 0, itf, closure, Mustach_With_AllExtensions, result, size);
+}
+
diff --git a/src/templating/mustach.h b/src/templating/mustach.h
new file mode 100644
index 000000000..1b44582d5
--- /dev/null
+++ b/src/templating/mustach.h
@@ -0,0 +1,319 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _mustach_h_included_
+#define _mustach_h_included_
+
+struct mustach_sbuf; /* see below */
+
+/**
+ * Current version of mustach and its derivates
+ */
+#define MUSTACH_VERSION 102
+#define MUSTACH_VERSION_MAJOR (MUSTACH_VERSION / 100)
+#define MUSTACH_VERSION_MINOR (MUSTACH_VERSION % 100)
+
+/**
+ * Maximum nested section supported
+ */
+#define MUSTACH_MAX_DEPTH 256
+
+/**
+ * Maximum nested template supported
+ */
+#define MUSTACH_MAX_NESTING 64
+
+/**
+ * Maximum length of tags in mustaches {{...}}
+ */
+#define MUSTACH_MAX_LENGTH 4096
+
+/**
+ * Maximum length of delimitors (2 normally but extended here)
+ */
+#define MUSTACH_MAX_DELIM_LENGTH 8
+
+/**
+ * Flags specific to mustach core
+ */
+#define Mustach_With_NoExtensions 0
+#define Mustach_With_Colon 1
+#define Mustach_With_EmptyTag 2
+#define Mustach_With_AllExtensions 3
+
+/*
+ * Definition of error codes returned by mustach
+ */
+#define MUSTACH_OK 0
+#define MUSTACH_ERROR_SYSTEM -1
+#define MUSTACH_ERROR_UNEXPECTED_END -2
+#define MUSTACH_ERROR_EMPTY_TAG -3
+#define MUSTACH_ERROR_TAG_TOO_LONG -4
+#define MUSTACH_ERROR_BAD_SEPARATORS -5
+#define MUSTACH_ERROR_TOO_DEEP -6
+#define MUSTACH_ERROR_CLOSING -7
+#define MUSTACH_ERROR_BAD_UNESCAPE_TAG -8
+#define MUSTACH_ERROR_INVALID_ITF -9
+#define MUSTACH_ERROR_ITEM_NOT_FOUND -10
+#define MUSTACH_ERROR_PARTIAL_NOT_FOUND -11
+#define MUSTACH_ERROR_UNDEFINED_TAG -12
+#define MUSTACH_ERROR_TOO_MUCH_NESTING -13
+
+/*
+ * You can use definition below for user specific error
+ *
+ * The macro MUSTACH_ERROR_USER is involutive so for any value
+ * value = MUSTACH_ERROR_USER(MUSTACH_ERROR_USER(value))
+ */
+#define MUSTACH_ERROR_USER_BASE -100
+#define MUSTACH_ERROR_USER(x) (MUSTACH_ERROR_USER_BASE-(x))
+#define MUSTACH_IS_ERROR_USER(x) (MUSTACH_ERROR_USER(x) >= 0)
+
+/**
+ * mustach_itf - pure abstract mustach - interface for callbacks
+ *
+ * The functions enter and next should return 0 or 1.
+ *
+ * All other functions should normally return MUSTACH_OK (zero).
+ *
+ * If any function returns a negative value, it means an error that
+ * stop the processing and that is reported to the caller. Mustach
+ * also has its own error codes. Using the macros MUSTACH_ERROR_USER
+ * and MUSTACH_IS_ERROR_USER could help to avoid clashes.
+ *
+ * @start: If defined (can be NULL), starts the mustach processing
+ * of the closure, called at the very beginning before any
+ * mustach processing occurs.
+ *
+ * @put: If defined (can be NULL), writes the value of 'name'
+ * to 'file' with 'escape' or not.
+ * As an extension (see NO_ALLOW_EMPTY_TAG), the 'name' can be
+ * the empty string. In that later case an implementation can
+ * return MUSTACH_ERROR_EMPTY_TAG to refuse empty names.
+ * If NULL and 'get' NULL the error MUSTACH_ERROR_INVALID_ITF
+ * is returned.
+ *
+ * @enter: Enters the section of 'name' if possible.
+ * Musts return 1 if entered or 0 if not entered.
+ * When 1 is returned, the function 'leave' will always be called.
+ * Conversely 'leave' is never called when enter returns 0 or
+ * a negative value.
+ * When 1 is returned, the function must activate the first
+ * item of the section.
+ *
+ * @next: Activates the next item of the section if it exists.
+ * Musts return 1 when the next item is activated.
+ * Musts return 0 when there is no item to activate.
+ *
+ * @leave: Leaves the last entered section
+ *
+ * @partial: If defined (can be NULL), returns in 'sbuf' the content of the
+ * partial of 'name'. @see mustach_sbuf
+ * If NULL but 'get' not NULL, 'get' is used instead of partial.
+ * If NULL and 'get' NULL and 'put' not NULL, 'put' is called with
+ * a true FILE.
+ *
+ * @emit: If defined (can be NULL), writes the 'buffer' of 'size' with 'escape'.
+ * If NULL the standard function 'fwrite' is used with a true FILE.
+ * If not NULL that function is called instead of 'fwrite' to output
+ * text.
+ * It implies that if you define either 'partial' or 'get' callback,
+ * the meaning of 'FILE *file' is abstract for mustach's process and
+ * then you can use 'FILE*file' pass any kind of pointer (including NULL)
+ * to the function 'fmustach'. An example of a such behaviour is given by
+ * the implementation of 'mustach_json_c_write'.
+ *
+ * @get: If defined (can be NULL), returns in 'sbuf' the value of 'name'.
+ * As an extension (see NO_ALLOW_EMPTY_TAG), the 'name' can be
+ * the empty string. In that later case an implementation can
+ * return MUSTACH_ERROR_EMPTY_TAG to refuse empty names.
+ * If 'get' is NULL and 'put' NULL the error MUSTACH_ERROR_INVALID_ITF
+ * is returned.
+ *
+ * @stop: If defined (can be NULL), stops the mustach processing
+ * of the closure, called at the very end after all mustach
+ * processing occurered. The status returned by the processing
+ * is passed to the stop.
+ *
+ * The array below summarize status of callbacks:
+ *
+ * FULLY OPTIONAL: start partial
+ * MANDATORY: enter next leave
+ * COMBINATORIAL: put emit get
+ *
+ * Not definig a MANDATORY callback returns error MUSTACH_ERROR_INVALID_ITF.
+ *
+ * For COMBINATORIAL callbacks the array below summarize possible combinations:
+ *
+ * combination : put : emit : get : abstract FILE
+ * -------------+---------+---------+---------+-----------------------
+ * HISTORIC : defined : NULL : NULL : NO: standard FILE
+ * MINIMAL : NULL : NULL : defined : NO: standard FILE
+ * CUSTOM : NULL : defined : defined : YES: abstract FILE
+ * DUCK : defined : NULL : defined : NO: standard FILE
+ * DANGEROUS : defined : defined : any : YES or NO, depends on 'partial'
+ * INVALID : NULL : any : NULL : -
+ *
+ * The DUCK case runs on one leg. 'get' is not used if 'partial' is defined
+ * but is used for 'partial' if 'partial' is NULL. Thus for clarity, do not use
+ * it that way but define 'partial' and let 'get' be NULL.
+ *
+ * The DANGEROUS case is special: it allows abstract FILE if 'partial' is defined
+ * but forbids abstract FILE when 'partial' is NULL.
+ *
+ * The INVALID case returns error MUSTACH_ERROR_INVALID_ITF.
+ */
+struct mustach_itf {
+ int (*start)(void *closure);
+ int (*put)(void *closure, const char *name, int escape, FILE *file);
+ int (*enter)(void *closure, const char *name);
+ int (*next)(void *closure);
+ int (*leave)(void *closure);
+ int (*partial)(void *closure, const char *name, struct mustach_sbuf *sbuf);
+ int (*emit)(void *closure, const char *buffer, size_t size, int escape, FILE *file);
+ int (*get)(void *closure, const char *name, struct mustach_sbuf *sbuf);
+ void (*stop)(void *closure, int status);
+};
+
+/**
+ * mustach_sbuf - Interface for handling zero terminated strings
+ *
+ * That structure is used for returning zero terminated strings -in 'value'-
+ * to mustach. The callee can provide a function for releasing the returned
+ * 'value'. Three methods for releasing the string are possible.
+ *
+ * 1. no release: set either 'freecb' or 'releasecb' with NULL (done by default)
+ * 2. release without closure: set 'freecb' to its expected value
+ * 3. release with closure: set 'releasecb' and 'closure' to their expected values
+ *
+ * @value: The value of the string. That value is not changed by mustach -const-.
+ *
+ * @freecb: The function to call for freeing the value without closure.
+ * For convenience, signature of that callback is compatible with 'free'.
+ * Can be NULL.
+ *
+ * @releasecb: The function to release with closure.
+ * Can be NULL.
+ *
+ * @closure: The closure to use for 'releasecb'.
+ *
+ * @length: Length of the value or zero if unknown and value null terminated.
+ * To return the empty string, let it to zero and let value to NULL.
+ */
+struct mustach_sbuf {
+ const char *value;
+ union {
+ void (*freecb)(void*);
+ void (*releasecb)(const char *value, void *closure);
+ };
+ void *closure;
+ size_t length;
+};
+
+/**
+ * mustach_file - Renders the mustache 'template' in 'file' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_file(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, FILE *file);
+
+/**
+ * mustach_fd - Renders the mustache 'template' in 'fd' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_fd(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, int fd);
+
+/**
+ * mustach_mem - Renders the mustache 'template' in 'result' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate
+ * @length: length of the template or zero if unknown and template null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+extern int mustach_mem(const char *template, size_t length, const struct mustach_itf *itf, void *closure, int flags, char **result, size_t *size);
+
+/***************************************************************************
+* compatibility with version before 1.0
+*/
+#ifdef __GNUC__
+#define DEPRECATED_MUSTACH(func) func __attribute__ ((deprecated))
+#elif defined(_MSC_VER)
+#define DEPRECATED_MUSTACH(func) __declspec(deprecated) func
+#elif !defined(DEPRECATED_MUSTACH)
+#pragma message("WARNING: You need to implement DEPRECATED_MUSTACH for this compiler")
+#define DEPRECATED_MUSTACH(func) func
+#endif
+/**
+ * OBSOLETE use mustach_file
+ *
+ * fmustach - Renders the mustache 'template' in 'file' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate, null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @file: the file where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+DEPRECATED_MUSTACH(extern int fmustach(const char *template, const struct mustach_itf *itf, void *closure, FILE *file));
+
+/**
+ * OBSOLETE use mustach_fd
+ *
+ * fdmustach - Renders the mustache 'template' in 'fd' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate, null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @fd: the file descriptor number where to write the result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+DEPRECATED_MUSTACH(extern int fdmustach(const char *template, const struct mustach_itf *itf, void *closure, int fd));
+
+/**
+ * OBSOLETE use mustach_mem
+ *
+ * mustach - Renders the mustache 'template' in 'result' for 'itf' and 'closure'.
+ *
+ * @template: the template string to instantiate, null terminated
+ * @itf: the interface to the functions that mustach calls
+ * @closure: the closure to pass to functions called
+ * @result: the pointer receiving the result when 0 is returned
+ * @size: the size of the returned result
+ *
+ * Returns 0 in case of success, -1 with errno set in case of system error
+ * a other negative value in case of error.
+ */
+DEPRECATED_MUSTACH(extern int mustach(const char *template, const struct mustach_itf *itf, void *closure, char **result, size_t *size));
+
+#endif
+
diff --git a/src/templating/pkgcfgs b/src/templating/pkgcfgs
new file mode 100644
index 000000000..c3e84dc0e
--- /dev/null
+++ b/src/templating/pkgcfgs
@@ -0,0 +1,35 @@
+==libmustach.pc==
+Name: libmustach
+Version: VERSION
+Description: C Mustach single library
+Cflags: -Imustach
+Libs: -lmustach
+
+==libmustach-core.pc==
+Name: libmustach-core
+Version: VERSION
+Description: C Mustach core library
+Cflags: -Imustach
+Libs: -lmustach-core
+
+==libmustach-cjson.pc==
+Name: libmustach-cjson
+Version: VERSION
+Description: C Mustach library for cJSON
+Cflags: -Imustach
+Libs: -lmustach-cjson
+
+==libmustach-json-c.pc==
+Name: libmustach-json-c
+Version: VERSION
+Description: C Mustach library for json-c
+Cflags: -Imustach
+Libs: -lmustach-json-c
+
+==libmustach-jansson.pc==
+Name: libmustach-jansson
+Version: VERSION
+Description: C Mustach library for jansson
+Cflags: -Imustach
+Libs: -lmustach-jansson
+
diff --git a/src/templating/run-original-tests.sh b/src/templating/run-original-tests.sh
new file mode 100755
index 000000000..21481a286
--- /dev/null
+++ b/src/templating/run-original-tests.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# This file is in the public domain.
+set -eux
+
+export CFLAGS="-g"
+
+echo "Ensuring clean state on entry to upstream tests ..."
+make clean
+
+# The build fails if libjson-c-dev is not installed.
+# That's OK, we don't otherwise need it and don't
+# even bother testing for it in configure.ac.
+# However, in that case, skip the test suite.
+make -f mustach-original-Makefile mustach mustach-json-c.o || exit 77
+make -f mustach-original-Makefile clean || true
+make -f mustach-original-Makefile basic-tests
+make -f mustach-original-Makefile clean || true
+
+exit 0
diff --git a/src/templating/templating_api.c b/src/templating/templating_api.c
new file mode 100644
index 000000000..88a17c682
--- /dev/null
+++ b/src/templating/templating_api.c
@@ -0,0 +1,524 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020, 2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file templating_api.c
+ * @brief logic to load and complete HTML templates
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_util.h"
+#include "taler_mhd_lib.h"
+#include "taler_templating_lib.h"
+#include "mustach.h"
+#include "mustach-jansson.h"
+#include <gnunet/gnunet_mhd_compat.h>
+
+
+/**
+ * Entry in a key-value array we use to cache templates.
+ */
+struct TVE
+{
+ /**
+ * A name, used as the key. NULL for the last entry.
+ */
+ char *name;
+
+ /**
+ * Language the template is in.
+ */
+ char *lang;
+
+ /**
+ * 0-terminated (!) file data to return for @e name and @e lang.
+ */
+ char *value;
+
+};
+
+
+/**
+ * Array of templates loaded into RAM.
+ */
+static struct TVE *loaded;
+
+/**
+ * Length of the #loaded array.
+ */
+static unsigned int loaded_length;
+
+
+/**
+ * Load Mustach template into memory. Note that we intentionally cache
+ * failures, that is if we ever failed to load a template, we will never try
+ * again.
+ *
+ * @param connection the connection we act upon
+ * @param name name of the template file to load
+ * (MUST be a 'static' string in memory!)
+ * @return NULL on error, otherwise the template
+ */
+static const char *
+lookup_template (struct MHD_Connection *connection,
+ const char *name)
+{
+ struct TVE *best = NULL;
+ const char *lang;
+
+ lang = MHD_lookup_connection_value (connection,
+ MHD_HEADER_KIND,
+ MHD_HTTP_HEADER_ACCEPT_LANGUAGE);
+ if (NULL == lang)
+ lang = "en";
+ /* find best match by language */
+ for (unsigned int i = 0; i<loaded_length; i++)
+ {
+ if (0 != strcmp (loaded[i].name,
+ name))
+ continue; /* does not match by name */
+ if ( (NULL == best) ||
+ (TALER_language_matches (lang,
+ loaded[i].lang) >
+ TALER_language_matches (lang,
+ best->lang) ) )
+ best = &loaded[i];
+ }
+ if (NULL == best)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No templates found for `%s'\n",
+ name);
+ return NULL;
+ }
+ return best->value;
+}
+
+
+/**
+ * Get the base URL for static resources.
+ *
+ * @param con the MHD connection
+ * @param instance_id the instance ID
+ * @returns the static files base URL, guaranteed
+ * to have a trailing slash.
+ */
+static char *
+make_static_url (struct MHD_Connection *con,
+ const char *instance_id)
+{
+ const char *host;
+ const char *forwarded_host;
+ const char *uri_path;
+ struct GNUNET_Buffer buf = { 0 };
+
+ host = MHD_lookup_connection_value (con,
+ MHD_HEADER_KIND,
+ "Host");
+ forwarded_host = MHD_lookup_connection_value (con,
+ MHD_HEADER_KIND,
+ "X-Forwarded-Host");
+
+ uri_path = MHD_lookup_connection_value (con,
+ MHD_HEADER_KIND,
+ "X-Forwarded-Prefix");
+ if (NULL != forwarded_host)
+ host = forwarded_host;
+
+ if (NULL == host)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+
+ GNUNET_assert (NULL != instance_id);
+
+ if (GNUNET_NO == TALER_mhd_is_https (con))
+ GNUNET_buffer_write_str (&buf,
+ "http://");
+ else
+ GNUNET_buffer_write_str (&buf,
+ "https://");
+ GNUNET_buffer_write_str (&buf,
+ host);
+ if (NULL != uri_path)
+ GNUNET_buffer_write_path (&buf,
+ uri_path);
+ if (0 != strcmp ("default",
+ instance_id))
+ {
+ GNUNET_buffer_write_path (&buf,
+ "instances");
+ GNUNET_buffer_write_path (&buf,
+ instance_id);
+ }
+ GNUNET_buffer_write_path (&buf,
+ "static/");
+ return GNUNET_buffer_reap_str (&buf);
+}
+
+
+int
+TALER_TEMPLATING_fill (const char *tmpl,
+ const json_t *root,
+ void **result,
+ size_t *result_size)
+{
+ int eno;
+
+ if (0 !=
+ (eno = mustach_jansson_mem (tmpl,
+ 0, /* length of tmpl */
+ (json_t *) root,
+ Mustach_With_AllExtensions,
+ (char **) result,
+ result_size)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "mustach failed on template with error %d\n",
+ eno);
+ *result = NULL;
+ *result_size = 0;
+ return eno;
+ }
+ return eno;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_build (struct MHD_Connection *connection,
+ unsigned int *http_status,
+ const char *template,
+ const char *instance_id,
+ const char *taler_uri,
+ const json_t *root,
+ struct MHD_Response **reply)
+{
+ char *body;
+ size_t body_size;
+
+ {
+ const char *tmpl;
+ int eno;
+
+ tmpl = lookup_template (connection,
+ template);
+ if (NULL == tmpl)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to load template `%s'\n",
+ template);
+ *http_status = MHD_HTTP_NOT_ACCEPTABLE;
+ *reply = TALER_MHD_make_error (TALER_EC_GENERIC_FAILED_TO_LOAD_TEMPLATE,
+ template);
+ return GNUNET_NO;
+ }
+ /* Add default values to the context */
+ if (NULL != instance_id)
+ {
+ char *static_url = make_static_url (connection,
+ instance_id);
+
+ GNUNET_break (0 ==
+ json_object_set_new ((json_t *) root,
+ "static_url",
+ json_string (static_url)));
+ GNUNET_free (static_url);
+ }
+ if (0 !=
+ (eno = mustach_jansson_mem (tmpl,
+ 0,
+ (json_t *) root,
+ Mustach_With_NoExtensions,
+ &body,
+ &body_size)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "mustach failed on template `%s' with error %d\n",
+ template,
+ eno);
+ *http_status = MHD_HTTP_INTERNAL_SERVER_ERROR;
+ *reply = TALER_MHD_make_error (TALER_EC_GENERIC_FAILED_TO_EXPAND_TEMPLATE,
+ template);
+ return GNUNET_NO;
+ }
+ }
+
+ /* try to compress reply if client allows it */
+ {
+ bool compressed = false;
+
+ if (MHD_YES ==
+ TALER_MHD_can_compress (connection))
+ {
+ compressed = TALER_MHD_body_compress ((void **) &body,
+ &body_size);
+ }
+ *reply = MHD_create_response_from_buffer (body_size,
+ body,
+ MHD_RESPMEM_MUST_FREE);
+ if (NULL == *reply)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (compressed)
+ {
+ if (MHD_NO ==
+ MHD_add_response_header (*reply,
+ MHD_HTTP_HEADER_CONTENT_ENCODING,
+ "deflate"))
+ {
+ GNUNET_break (0);
+ MHD_destroy_response (*reply);
+ *reply = NULL;
+ return GNUNET_SYSERR;
+ }
+ }
+ }
+
+ /* Add standard headers */
+ if (NULL != taler_uri)
+ GNUNET_break (MHD_NO !=
+ MHD_add_response_header (*reply,
+ "Taler",
+ taler_uri));
+ GNUNET_break (MHD_NO !=
+ MHD_add_response_header (*reply,
+ MHD_HTTP_HEADER_CONTENT_TYPE,
+ "text/html"));
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_reply (struct MHD_Connection *connection,
+ unsigned int http_status,
+ const char *template,
+ const char *instance_id,
+ const char *taler_uri,
+ const json_t *root)
+{
+ enum GNUNET_GenericReturnValue res;
+ struct MHD_Response *reply;
+ MHD_RESULT ret;
+
+ res = TALER_TEMPLATING_build (connection,
+ &http_status,
+ template,
+ instance_id,
+ taler_uri,
+ root,
+ &reply);
+ if (GNUNET_SYSERR == res)
+ return res;
+ ret = MHD_queue_response (connection,
+ http_status,
+ reply);
+ MHD_destroy_response (reply);
+ if (MHD_NO == ret)
+ return GNUNET_SYSERR;
+ return (res == GNUNET_OK)
+ ? GNUNET_OK
+ : GNUNET_NO;
+}
+
+
+/**
+ * Function called with a template's filename.
+ *
+ * @param cls closure, NULL
+ * @param filename complete filename (absolute path)
+ * @return #GNUNET_OK to continue to iterate,
+ * #GNUNET_NO to stop iteration with no error,
+ * #GNUNET_SYSERR to abort iteration with error!
+ */
+static enum GNUNET_GenericReturnValue
+load_template (void *cls,
+ const char *filename)
+{
+ char *lang;
+ char *end;
+ int fd;
+ struct stat sb;
+ char *map;
+ const char *name;
+
+ (void) cls;
+ if ('.' == filename[0])
+ return GNUNET_OK;
+ name = strrchr (filename,
+ '/');
+ if (NULL == name)
+ name = filename;
+ else
+ name++;
+ lang = strchr (name,
+ '.');
+ if (NULL == lang)
+ return GNUNET_OK; /* name must include .$LANG */
+ lang++;
+ end = strchr (lang,
+ '.');
+ if ( (NULL == end) ||
+ (0 != strcmp (end,
+ ".must")) )
+ return GNUNET_OK; /* name must end with '.must' */
+
+ /* finally open template */
+ fd = open (filename,
+ O_RDONLY);
+ if (-1 == fd)
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ filename);
+
+ return GNUNET_SYSERR;
+ }
+ if (0 !=
+ fstat (fd,
+ &sb))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "fstat",
+ filename);
+ GNUNET_break (0 == close (fd));
+ return GNUNET_OK;
+ }
+ map = GNUNET_malloc_large (sb.st_size + 1);
+ if (NULL == map)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "malloc");
+ GNUNET_break (0 == close (fd));
+ return GNUNET_SYSERR;
+ }
+ if (sb.st_size !=
+ read (fd,
+ map,
+ sb.st_size))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "read",
+ filename);
+ GNUNET_break (0 == close (fd));
+ return GNUNET_OK;
+ }
+ GNUNET_break (0 == close (fd));
+ GNUNET_array_grow (loaded,
+ loaded_length,
+ loaded_length + 1);
+ loaded[loaded_length - 1].name = GNUNET_strndup (name,
+ (lang - 1) - name);
+ loaded[loaded_length - 1].lang = GNUNET_strndup (lang,
+ end - lang);
+ loaded[loaded_length - 1].value = map;
+ return GNUNET_OK;
+}
+
+
+MHD_RESULT
+TALER_TEMPLATING_reply_error (
+ struct MHD_Connection *connection,
+ const char *template_basename,
+ unsigned int http_status,
+ enum TALER_ErrorCode ec,
+ const char *detail)
+{
+ json_t *data;
+ enum GNUNET_GenericReturnValue ret;
+
+ data = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("ec",
+ ec),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (ec)),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("detail",
+ detail))
+ );
+ ret = TALER_TEMPLATING_reply (connection,
+ http_status,
+ template_basename,
+ NULL,
+ NULL,
+ data);
+ json_decref (data);
+ switch (ret)
+ {
+ case GNUNET_OK:
+ return MHD_YES;
+ case GNUNET_NO:
+ return MHD_YES;
+ case GNUNET_SYSERR:
+ return MHD_NO;
+ }
+ GNUNET_assert (0);
+ return MHD_NO;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TEMPLATING_init (const char *subsystem)
+{
+ char *dn;
+ int ret;
+
+ {
+ char *path;
+
+ path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ if (NULL == path)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_asprintf (&dn,
+ "%s/%s/templates/",
+ path,
+ subsystem);
+ GNUNET_free (path);
+ }
+ ret = GNUNET_DISK_directory_scan (dn,
+ &load_template,
+ NULL);
+ GNUNET_free (dn);
+ if (-1 == ret)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+void
+TALER_TEMPLATING_done (void)
+{
+ for (unsigned int i = 0; i<loaded_length; i++)
+ {
+ GNUNET_free (loaded[i].name);
+ GNUNET_free (loaded[i].lang);
+ GNUNET_free (loaded[i].value);
+ }
+ GNUNET_array_grow (loaded,
+ loaded_length,
+ 0);
+}
+
+
+/* end of templating_api.c */
diff --git a/src/templating/test-specs/test-specs-cjson.ref b/src/templating/test-specs/test-specs-cjson.ref
new file mode 100644
index 000000000..8897c66cc
--- /dev/null
+++ b/src/templating/test-specs/test-specs-cjson.ref
@@ -0,0 +1,425 @@
+
+loading test-specs/spec/specs/comments.json
+processing file test-specs/spec/specs/comments.json
+[0] Inline
+ Comment blocks should be removed from the template.
+ => SUCCESS
+[1] Multiline
+ Multiline comments should be permitted.
+ => SUCCESS
+[2] Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[3] Indented Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[4] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[5] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[6] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[7] Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[8] Indented Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[9] Indented Inline
+ Inline comments should not strip whitespace
+ => SUCCESS
+[10] Surrounding Whitespace
+ Comment removal should preserve surrounding whitespace.
+ => SUCCESS
+[11] Variable Name Collision
+ Comments must never render, even if variable with same name exists.
+ => SUCCESS
+
+loading test-specs/spec/specs/delimiters.json
+processing file test-specs/spec/specs/delimiters.json
+[0] Pair Behavior
+ The equals sign (used on both sides) should permit delimiter changes.
+ => SUCCESS
+[1] Special Characters
+ Characters with special meaning regexen should be valid delimiters.
+ => SUCCESS
+[2] Sections
+ Delimiters set outside sections should persist.
+ => SUCCESS
+[3] Inverted Sections
+ Delimiters set outside inverted sections should persist.
+ => SUCCESS
+[4] Partial Inheritence
+ Delimiters set in a parent template should not affect a partial.
+ => SUCCESS
+[5] Post-Partial Behavior
+ Delimiters set in a partial should not affect the parent template.
+ => SUCCESS
+[6] Surrounding Whitespace
+ Surrounding whitespace should be left untouched.
+ => SUCCESS
+[7] Outlying Whitespace (Inline)
+ Whitespace should be left untouched.
+ => SUCCESS
+[8] Standalone Tag
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[9] Indented Standalone Tag
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[10] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[11] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[12] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[13] Pair with Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/interpolation.json
+processing file test-specs/spec/specs/interpolation.json
+[0] No Interpolation
+ Mustache-free templates should render as-is.
+ => SUCCESS
+[1] Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[2] HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[3] Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[4] Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[5] Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[6] Triple Mustache Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[7] Ampersand Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[8] Basic Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[9] Triple Mustache Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[10] Ampersand Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[11] Basic Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[12] Triple Mustache Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[13] Ampersand Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[14] Basic Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[15] Triple Mustache Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[16] Ampersand Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[17] Dotted Names - Basic Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[18] Dotted Names - Triple Mustache Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[19] Dotted Names - Ampersand Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[20] Dotted Names - Arbitrary Depth
+ Dotted names should be functional to any level of nesting.
+ => SUCCESS
+[21] Dotted Names - Broken Chains
+ Any falsey value prior to the last part of the name should yield ''.
+ => SUCCESS
+[22] Dotted Names - Broken Chain Resolution
+ Each part of a dotted name should resolve only against its parent.
+ => SUCCESS
+[23] Dotted Names - Initial Resolution
+ The first part of a dotted name should resolve as any other name.
+ => SUCCESS
+[24] Dotted Names - Context Precedence
+ Dotted names should be resolved against former resolutions.
+ => SUCCESS
+[25] Implicit Iterators - Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[26] Implicit Iterators - HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[27] Implicit Iterators - Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[28] Implicit Iterators - Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[29] Implicit Iterators - Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[30] Interpolation - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[31] Triple Mustache - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[32] Ampersand - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[33] Interpolation - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[34] Triple Mustache - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[35] Ampersand - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[36] Interpolation With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[37] Triple Mustache With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[38] Ampersand With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/inverted.json
+processing file test-specs/spec/specs/inverted.json
+[0] Falsey
+ Falsey sections should have their contents rendered.
+ => SUCCESS
+[1] Truthy
+ Truthy sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should behave like truthy values.
+ => SUCCESS
+[4] List
+ Lists should behave like truthy values.
+ => SUCCESS
+[5] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[6] Doubled
+ Multiple inverted sections per template should be permitted.
+ => SUCCESS
+[7] Nested (Falsey)
+ Nested falsey sections should have their contents rendered.
+ => SUCCESS
+[8] Nested (Truthy)
+ Nested truthy sections should be omitted.
+ => SUCCESS
+[9] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[10] Dotted Names - Truthy
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[11] Dotted Names - Falsey
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[12] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[13] Surrounding Whitespace
+ Inverted sections should not alter surrounding whitespace.
+ => SUCCESS
+[14] Internal Whitespace
+ Inverted should not alter internal whitespace.
+ => SUCCESS
+[15] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[16] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[17] Standalone Indented Lines
+ Standalone indented lines should be removed from the template.
+ => SUCCESS
+[18] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[19] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[20] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[21] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/partials.json
+processing file test-specs/spec/specs/partials.json
+[0] Basic Behavior
+ The greater-than operator should expand to the named partial.
+ => SUCCESS
+[1] Failed Lookup
+ The empty string should be used when the named partial is not found.
+ => SUCCESS
+[2] Context
+ The greater-than operator should operate within the current context.
+ => SUCCESS
+[3] Recursion
+ The greater-than operator should properly recurse.
+ => SUCCESS
+[4] Nested
+ The greater-than operator should work from within partials.
+ => SUCCESS
+[5] Surrounding Whitespace
+ The greater-than operator should not alter surrounding whitespace.
+ => SUCCESS
+[6] Inline Indentation
+ Whitespace should be left untouched.
+ => SUCCESS
+[7] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[8] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[9] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[10] Standalone Indentation
+ Each line of the partial should be indented before rendering.
+ => SUCCESS
+[11] Padding Whitespace
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/sections.json
+processing file test-specs/spec/specs/sections.json
+[0] Truthy
+ Truthy sections should have their contents rendered.
+ => SUCCESS
+[1] Falsey
+ Falsey sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should be pushed onto the context stack.
+ => SUCCESS
+[4] Parent contexts
+ Names missing in the current context are looked up in the stack.
+ => SUCCESS
+[5] Variable test
+ Non-false sections have their value at the top of context,
+accessible as {{.}} or through the parent context. This gives
+a simple way to display content conditionally if a variable exists.
+
+ => SUCCESS
+[6] List Contexts
+ All elements on the context stack should be accessible within lists.
+ => SUCCESS
+[7] Deeply Nested Contexts
+ All elements on the context stack should be accessible.
+ => SUCCESS
+[8] List
+ Lists should be iterated; list items should visit the context stack.
+ => SUCCESS
+[9] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[10] Doubled
+ Multiple sections per template should be permitted.
+ => SUCCESS
+[11] Nested (Truthy)
+ Nested truthy sections should have their contents rendered.
+ => SUCCESS
+[12] Nested (Falsey)
+ Nested falsey sections should be omitted.
+ => SUCCESS
+[13] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[14] Implicit Iterator - String
+ Implicit iterators should directly interpolate strings.
+ => SUCCESS
+[15] Implicit Iterator - Integer
+ Implicit iterators should cast integers to strings and interpolate.
+ => SUCCESS
+[16] Implicit Iterator - Decimal
+ Implicit iterators should cast decimals to strings and interpolate.
+ => SUCCESS
+[17] Implicit Iterator - Array
+ Implicit iterators should allow iterating over nested arrays.
+ => SUCCESS
+[18] Implicit Iterator - HTML Escaping
+ Implicit iterators with basic interpolation should be HTML escaped.
+ => SUCCESS
+[19] Implicit Iterator - Triple mustache
+ Implicit iterators in triple mustache should interpolate without HTML escaping.
+ => SUCCESS
+[20] Implicit Iterator - Ampersand
+ Implicit iterators in an Ampersand tag should interpolate without HTML escaping.
+ => SUCCESS
+[21] Implicit Iterator - Root-level
+ Implicit iterators should work on root-level lists.
+ => SUCCESS
+[22] Dotted Names - Truthy
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[23] Dotted Names - Falsey
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[24] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[25] Surrounding Whitespace
+ Sections should not alter surrounding whitespace.
+ => SUCCESS
+[26] Internal Whitespace
+ Sections should not alter internal whitespace.
+ => SUCCESS
+[27] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[28] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[29] Indented Standalone Lines
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[30] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[31] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[32] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[33] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+summary:
+ error 0
+ differ 0
+ success 133
diff --git a/src/templating/test-specs/test-specs-jansson.ref b/src/templating/test-specs/test-specs-jansson.ref
new file mode 100644
index 000000000..a1cef19c1
--- /dev/null
+++ b/src/templating/test-specs/test-specs-jansson.ref
@@ -0,0 +1,429 @@
+
+loading test-specs/spec/specs/comments.json
+processing file test-specs/spec/specs/comments.json
+[0] Inline
+ Comment blocks should be removed from the template.
+ => SUCCESS
+[1] Multiline
+ Multiline comments should be permitted.
+ => SUCCESS
+[2] Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[3] Indented Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[4] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[5] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[6] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[7] Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[8] Indented Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[9] Indented Inline
+ Inline comments should not strip whitespace
+ => SUCCESS
+[10] Surrounding Whitespace
+ Comment removal should preserve surrounding whitespace.
+ => SUCCESS
+[11] Variable Name Collision
+ Comments must never render, even if variable with same name exists.
+ => SUCCESS
+
+loading test-specs/spec/specs/delimiters.json
+processing file test-specs/spec/specs/delimiters.json
+[0] Pair Behavior
+ The equals sign (used on both sides) should permit delimiter changes.
+ => SUCCESS
+[1] Special Characters
+ Characters with special meaning regexen should be valid delimiters.
+ => SUCCESS
+[2] Sections
+ Delimiters set outside sections should persist.
+ => SUCCESS
+[3] Inverted Sections
+ Delimiters set outside inverted sections should persist.
+ => SUCCESS
+[4] Partial Inheritence
+ Delimiters set in a parent template should not affect a partial.
+ => SUCCESS
+[5] Post-Partial Behavior
+ Delimiters set in a partial should not affect the parent template.
+ => SUCCESS
+[6] Surrounding Whitespace
+ Surrounding whitespace should be left untouched.
+ => SUCCESS
+[7] Outlying Whitespace (Inline)
+ Whitespace should be left untouched.
+ => SUCCESS
+[8] Standalone Tag
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[9] Indented Standalone Tag
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[10] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[11] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[12] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[13] Pair with Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/interpolation.json
+processing file test-specs/spec/specs/interpolation.json
+[0] No Interpolation
+ Mustache-free templates should render as-is.
+ => SUCCESS
+[1] Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[2] HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[3] Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[4] Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[5] Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[6] Triple Mustache Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[7] Ampersand Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[8] Basic Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[9] Triple Mustache Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[10] Ampersand Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[11] Basic Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[12] Triple Mustache Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[13] Ampersand Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[14] Basic Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[15] Triple Mustache Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[16] Ampersand Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[17] Dotted Names - Basic Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[18] Dotted Names - Triple Mustache Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[19] Dotted Names - Ampersand Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[20] Dotted Names - Arbitrary Depth
+ Dotted names should be functional to any level of nesting.
+ => SUCCESS
+[21] Dotted Names - Broken Chains
+ Any falsey value prior to the last part of the name should yield ''.
+ => SUCCESS
+[22] Dotted Names - Broken Chain Resolution
+ Each part of a dotted name should resolve only against its parent.
+ => SUCCESS
+[23] Dotted Names - Initial Resolution
+ The first part of a dotted name should resolve as any other name.
+ => SUCCESS
+[24] Dotted Names - Context Precedence
+ Dotted names should be resolved against former resolutions.
+ => SUCCESS
+[25] Implicit Iterators - Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[26] Implicit Iterators - HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[27] Implicit Iterators - Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[28] Implicit Iterators - Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[29] Implicit Iterators - Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[30] Interpolation - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[31] Triple Mustache - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[32] Ampersand - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[33] Interpolation - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[34] Triple Mustache - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[35] Ampersand - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[36] Interpolation With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[37] Triple Mustache With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[38] Ampersand With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/inverted.json
+processing file test-specs/spec/specs/inverted.json
+[0] Falsey
+ Falsey sections should have their contents rendered.
+ => SUCCESS
+[1] Truthy
+ Truthy sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should behave like truthy values.
+ => SUCCESS
+[4] List
+ Lists should behave like truthy values.
+ => SUCCESS
+[5] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[6] Doubled
+ Multiple inverted sections per template should be permitted.
+ => SUCCESS
+[7] Nested (Falsey)
+ Nested falsey sections should have their contents rendered.
+ => SUCCESS
+[8] Nested (Truthy)
+ Nested truthy sections should be omitted.
+ => SUCCESS
+[9] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[10] Dotted Names - Truthy
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[11] Dotted Names - Falsey
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[12] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[13] Surrounding Whitespace
+ Inverted sections should not alter surrounding whitespace.
+ => SUCCESS
+[14] Internal Whitespace
+ Inverted should not alter internal whitespace.
+ => SUCCESS
+[15] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[16] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[17] Standalone Indented Lines
+ Standalone indented lines should be removed from the template.
+ => SUCCESS
+[18] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[19] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[20] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[21] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/partials.json
+processing file test-specs/spec/specs/partials.json
+[0] Basic Behavior
+ The greater-than operator should expand to the named partial.
+ => SUCCESS
+[1] Failed Lookup
+ The empty string should be used when the named partial is not found.
+ => SUCCESS
+[2] Context
+ The greater-than operator should operate within the current context.
+ => SUCCESS
+[3] Recursion
+ The greater-than operator should properly recurse.
+ => SUCCESS
+[4] Nested
+ The greater-than operator should work from within partials.
+ => SUCCESS
+[5] Surrounding Whitespace
+ The greater-than operator should not alter surrounding whitespace.
+ => SUCCESS
+[6] Inline Indentation
+ Whitespace should be left untouched.
+ => SUCCESS
+[7] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[8] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[9] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[10] Standalone Indentation
+ Each line of the partial should be indented before rendering.
+ => SUCCESS
+[11] Padding Whitespace
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/sections.json
+processing file test-specs/spec/specs/sections.json
+[0] Truthy
+ Truthy sections should have their contents rendered.
+ => SUCCESS
+[1] Falsey
+ Falsey sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should be pushed onto the context stack.
+ => SUCCESS
+[4] Parent contexts
+ Names missing in the current context are looked up in the stack.
+ => SUCCESS
+[5] Variable test
+ Non-false sections have their value at the top of context,
+accessible as {{.}} or through the parent context. This gives
+a simple way to display content conditionally if a variable exists.
+
+ => SUCCESS
+[6] List Contexts
+ All elements on the context stack should be accessible within lists.
+ => SUCCESS
+[7] Deeply Nested Contexts
+ All elements on the context stack should be accessible.
+ => SUCCESS
+[8] List
+ Lists should be iterated; list items should visit the context stack.
+ => SUCCESS
+[9] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[10] Doubled
+ Multiple sections per template should be permitted.
+ => SUCCESS
+[11] Nested (Truthy)
+ Nested truthy sections should have their contents rendered.
+ => SUCCESS
+[12] Nested (Falsey)
+ Nested falsey sections should be omitted.
+ => SUCCESS
+[13] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[14] Implicit Iterator - String
+ Implicit iterators should directly interpolate strings.
+ => SUCCESS
+[15] Implicit Iterator - Integer
+ Implicit iterators should cast integers to strings and interpolate.
+ => SUCCESS
+[16] Implicit Iterator - Decimal
+ Implicit iterators should cast decimals to strings and interpolate.
+ => DIFFERS
+ .. DATA[{"list":[1.1000000000000001,2.2000000000000002,3.2999999999999998,4.4000000000000004,5.5]}]
+ .. TEMPLATE["{{#list}}({{.}}){{/list}}"]
+ .. EXPECTED["(1.1)(2.2)(3.3)(4.4)(5.5)"]
+ .. GOT["(1.1000000000000001)(2.2000000000000002)(3.2999999999999998)(4.4000000000000004)(5.5)"]
+[17] Implicit Iterator - Array
+ Implicit iterators should allow iterating over nested arrays.
+ => SUCCESS
+[18] Implicit Iterator - HTML Escaping
+ Implicit iterators with basic interpolation should be HTML escaped.
+ => SUCCESS
+[19] Implicit Iterator - Triple mustache
+ Implicit iterators in triple mustache should interpolate without HTML escaping.
+ => SUCCESS
+[20] Implicit Iterator - Ampersand
+ Implicit iterators in an Ampersand tag should interpolate without HTML escaping.
+ => SUCCESS
+[21] Implicit Iterator - Root-level
+ Implicit iterators should work on root-level lists.
+ => SUCCESS
+[22] Dotted Names - Truthy
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[23] Dotted Names - Falsey
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[24] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[25] Surrounding Whitespace
+ Sections should not alter surrounding whitespace.
+ => SUCCESS
+[26] Internal Whitespace
+ Sections should not alter internal whitespace.
+ => SUCCESS
+[27] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[28] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[29] Indented Standalone Lines
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[30] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[31] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[32] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[33] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+summary:
+ error 0
+ differ 1
+ success 132
diff --git a/src/templating/test-specs/test-specs-json-c.ref b/src/templating/test-specs/test-specs-json-c.ref
new file mode 100644
index 000000000..8897c66cc
--- /dev/null
+++ b/src/templating/test-specs/test-specs-json-c.ref
@@ -0,0 +1,425 @@
+
+loading test-specs/spec/specs/comments.json
+processing file test-specs/spec/specs/comments.json
+[0] Inline
+ Comment blocks should be removed from the template.
+ => SUCCESS
+[1] Multiline
+ Multiline comments should be permitted.
+ => SUCCESS
+[2] Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[3] Indented Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[4] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[5] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[6] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[7] Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[8] Indented Multiline Standalone
+ All standalone comment lines should be removed.
+ => SUCCESS
+[9] Indented Inline
+ Inline comments should not strip whitespace
+ => SUCCESS
+[10] Surrounding Whitespace
+ Comment removal should preserve surrounding whitespace.
+ => SUCCESS
+[11] Variable Name Collision
+ Comments must never render, even if variable with same name exists.
+ => SUCCESS
+
+loading test-specs/spec/specs/delimiters.json
+processing file test-specs/spec/specs/delimiters.json
+[0] Pair Behavior
+ The equals sign (used on both sides) should permit delimiter changes.
+ => SUCCESS
+[1] Special Characters
+ Characters with special meaning regexen should be valid delimiters.
+ => SUCCESS
+[2] Sections
+ Delimiters set outside sections should persist.
+ => SUCCESS
+[3] Inverted Sections
+ Delimiters set outside inverted sections should persist.
+ => SUCCESS
+[4] Partial Inheritence
+ Delimiters set in a parent template should not affect a partial.
+ => SUCCESS
+[5] Post-Partial Behavior
+ Delimiters set in a partial should not affect the parent template.
+ => SUCCESS
+[6] Surrounding Whitespace
+ Surrounding whitespace should be left untouched.
+ => SUCCESS
+[7] Outlying Whitespace (Inline)
+ Whitespace should be left untouched.
+ => SUCCESS
+[8] Standalone Tag
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[9] Indented Standalone Tag
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[10] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[11] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[12] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[13] Pair with Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/interpolation.json
+processing file test-specs/spec/specs/interpolation.json
+[0] No Interpolation
+ Mustache-free templates should render as-is.
+ => SUCCESS
+[1] Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[2] HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[3] Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[4] Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[5] Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[6] Triple Mustache Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[7] Ampersand Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[8] Basic Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[9] Triple Mustache Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[10] Ampersand Decimal Interpolation
+ Decimals should interpolate seamlessly with proper significance.
+ => SUCCESS
+[11] Basic Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[12] Triple Mustache Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[13] Ampersand Null Interpolation
+ Nulls should interpolate as the empty string.
+ => SUCCESS
+[14] Basic Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[15] Triple Mustache Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[16] Ampersand Context Miss Interpolation
+ Failed context lookups should default to empty strings.
+ => SUCCESS
+[17] Dotted Names - Basic Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[18] Dotted Names - Triple Mustache Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[19] Dotted Names - Ampersand Interpolation
+ Dotted names should be considered a form of shorthand for sections.
+ => SUCCESS
+[20] Dotted Names - Arbitrary Depth
+ Dotted names should be functional to any level of nesting.
+ => SUCCESS
+[21] Dotted Names - Broken Chains
+ Any falsey value prior to the last part of the name should yield ''.
+ => SUCCESS
+[22] Dotted Names - Broken Chain Resolution
+ Each part of a dotted name should resolve only against its parent.
+ => SUCCESS
+[23] Dotted Names - Initial Resolution
+ The first part of a dotted name should resolve as any other name.
+ => SUCCESS
+[24] Dotted Names - Context Precedence
+ Dotted names should be resolved against former resolutions.
+ => SUCCESS
+[25] Implicit Iterators - Basic Interpolation
+ Unadorned tags should interpolate content into the template.
+ => SUCCESS
+[26] Implicit Iterators - HTML Escaping
+ Basic interpolation should be HTML escaped.
+ => SUCCESS
+[27] Implicit Iterators - Triple Mustache
+ Triple mustaches should interpolate without HTML escaping.
+ => SUCCESS
+[28] Implicit Iterators - Ampersand
+ Ampersand should interpolate without HTML escaping.
+ => SUCCESS
+[29] Implicit Iterators - Basic Integer Interpolation
+ Integers should interpolate seamlessly.
+ => SUCCESS
+[30] Interpolation - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[31] Triple Mustache - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[32] Ampersand - Surrounding Whitespace
+ Interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[33] Interpolation - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[34] Triple Mustache - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[35] Ampersand - Standalone
+ Standalone interpolation should not alter surrounding whitespace.
+ => SUCCESS
+[36] Interpolation With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[37] Triple Mustache With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+[38] Ampersand With Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/inverted.json
+processing file test-specs/spec/specs/inverted.json
+[0] Falsey
+ Falsey sections should have their contents rendered.
+ => SUCCESS
+[1] Truthy
+ Truthy sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should behave like truthy values.
+ => SUCCESS
+[4] List
+ Lists should behave like truthy values.
+ => SUCCESS
+[5] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[6] Doubled
+ Multiple inverted sections per template should be permitted.
+ => SUCCESS
+[7] Nested (Falsey)
+ Nested falsey sections should have their contents rendered.
+ => SUCCESS
+[8] Nested (Truthy)
+ Nested truthy sections should be omitted.
+ => SUCCESS
+[9] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[10] Dotted Names - Truthy
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[11] Dotted Names - Falsey
+ Dotted names should be valid for Inverted Section tags.
+ => SUCCESS
+[12] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[13] Surrounding Whitespace
+ Inverted sections should not alter surrounding whitespace.
+ => SUCCESS
+[14] Internal Whitespace
+ Inverted should not alter internal whitespace.
+ => SUCCESS
+[15] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[16] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[17] Standalone Indented Lines
+ Standalone indented lines should be removed from the template.
+ => SUCCESS
+[18] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[19] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[20] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[21] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/partials.json
+processing file test-specs/spec/specs/partials.json
+[0] Basic Behavior
+ The greater-than operator should expand to the named partial.
+ => SUCCESS
+[1] Failed Lookup
+ The empty string should be used when the named partial is not found.
+ => SUCCESS
+[2] Context
+ The greater-than operator should operate within the current context.
+ => SUCCESS
+[3] Recursion
+ The greater-than operator should properly recurse.
+ => SUCCESS
+[4] Nested
+ The greater-than operator should work from within partials.
+ => SUCCESS
+[5] Surrounding Whitespace
+ The greater-than operator should not alter surrounding whitespace.
+ => SUCCESS
+[6] Inline Indentation
+ Whitespace should be left untouched.
+ => SUCCESS
+[7] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[8] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[9] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[10] Standalone Indentation
+ Each line of the partial should be indented before rendering.
+ => SUCCESS
+[11] Padding Whitespace
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+loading test-specs/spec/specs/sections.json
+processing file test-specs/spec/specs/sections.json
+[0] Truthy
+ Truthy sections should have their contents rendered.
+ => SUCCESS
+[1] Falsey
+ Falsey sections should have their contents omitted.
+ => SUCCESS
+[2] Null is falsey
+ Null is falsey.
+ => SUCCESS
+[3] Context
+ Objects and hashes should be pushed onto the context stack.
+ => SUCCESS
+[4] Parent contexts
+ Names missing in the current context are looked up in the stack.
+ => SUCCESS
+[5] Variable test
+ Non-false sections have their value at the top of context,
+accessible as {{.}} or through the parent context. This gives
+a simple way to display content conditionally if a variable exists.
+
+ => SUCCESS
+[6] List Contexts
+ All elements on the context stack should be accessible within lists.
+ => SUCCESS
+[7] Deeply Nested Contexts
+ All elements on the context stack should be accessible.
+ => SUCCESS
+[8] List
+ Lists should be iterated; list items should visit the context stack.
+ => SUCCESS
+[9] Empty List
+ Empty lists should behave like falsey values.
+ => SUCCESS
+[10] Doubled
+ Multiple sections per template should be permitted.
+ => SUCCESS
+[11] Nested (Truthy)
+ Nested truthy sections should have their contents rendered.
+ => SUCCESS
+[12] Nested (Falsey)
+ Nested falsey sections should be omitted.
+ => SUCCESS
+[13] Context Misses
+ Failed context lookups should be considered falsey.
+ => SUCCESS
+[14] Implicit Iterator - String
+ Implicit iterators should directly interpolate strings.
+ => SUCCESS
+[15] Implicit Iterator - Integer
+ Implicit iterators should cast integers to strings and interpolate.
+ => SUCCESS
+[16] Implicit Iterator - Decimal
+ Implicit iterators should cast decimals to strings and interpolate.
+ => SUCCESS
+[17] Implicit Iterator - Array
+ Implicit iterators should allow iterating over nested arrays.
+ => SUCCESS
+[18] Implicit Iterator - HTML Escaping
+ Implicit iterators with basic interpolation should be HTML escaped.
+ => SUCCESS
+[19] Implicit Iterator - Triple mustache
+ Implicit iterators in triple mustache should interpolate without HTML escaping.
+ => SUCCESS
+[20] Implicit Iterator - Ampersand
+ Implicit iterators in an Ampersand tag should interpolate without HTML escaping.
+ => SUCCESS
+[21] Implicit Iterator - Root-level
+ Implicit iterators should work on root-level lists.
+ => SUCCESS
+[22] Dotted Names - Truthy
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[23] Dotted Names - Falsey
+ Dotted names should be valid for Section tags.
+ => SUCCESS
+[24] Dotted Names - Broken Chains
+ Dotted names that cannot be resolved should be considered falsey.
+ => SUCCESS
+[25] Surrounding Whitespace
+ Sections should not alter surrounding whitespace.
+ => SUCCESS
+[26] Internal Whitespace
+ Sections should not alter internal whitespace.
+ => SUCCESS
+[27] Indented Inline Sections
+ Single-line sections should not alter surrounding whitespace.
+ => SUCCESS
+[28] Standalone Lines
+ Standalone lines should be removed from the template.
+ => SUCCESS
+[29] Indented Standalone Lines
+ Indented standalone lines should be removed from the template.
+ => SUCCESS
+[30] Standalone Line Endings
+ "\r\n" should be considered a newline for standalone tags.
+ => SUCCESS
+[31] Standalone Without Previous Line
+ Standalone tags should not require a newline to precede them.
+ => SUCCESS
+[32] Standalone Without Newline
+ Standalone tags should not require a newline to follow them.
+ => SUCCESS
+[33] Padding
+ Superfluous in-tag whitespace should be ignored.
+ => SUCCESS
+
+summary:
+ error 0
+ differ 0
+ success 133
diff --git a/src/templating/test-specs/test-specs.c b/src/templating/test-specs/test-specs.c
new file mode 100644
index 000000000..15c94a80e
--- /dev/null
+++ b/src/templating/test-specs/test-specs.c
@@ -0,0 +1,520 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ SPDX-License-Identifier: ISC
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+#include "mustach-wrap.h"
+
+#define TEST_JSON_C 1
+#define TEST_JANSSON 2
+#define TEST_CJSON 3
+
+static const char *errors[] = {
+ "??? unreferenced ???",
+ "system",
+ "unexpected end",
+ "empty tag",
+ "tag too long",
+ "bad separators",
+ "too depth",
+ "closing",
+ "bad unescape tag",
+ "invalid interface",
+ "item not found",
+ "partial not found"
+};
+
+const char *mustach_error_string(int status)
+{
+ return status >= 0 ? "no error"
+ : errors[status <= -(int)(sizeof errors / sizeof * errors) ? 0 : -status];
+}
+
+static const char *errmsg = 0;
+static int flags = 0;
+static FILE *output = 0;
+
+static void help(char *prog)
+{
+ char *name = basename(prog);
+#define STR(x) #x
+ printf("%s version %s\n", name, STR(VERSION));
+#undef STR
+ printf("usage: %s test-files...\n", name);
+ exit(0);
+}
+
+#if TEST == TEST_CJSON
+
+static const size_t BLOCKSIZE = 8192;
+
+static char *readfile(const char *filename, size_t *length)
+{
+ int f;
+ struct stat s;
+ char *result;
+ size_t size, pos;
+ ssize_t rc;
+
+ result = NULL;
+ if (filename[0] == '-' && filename[1] == 0)
+ f = dup(0);
+ else
+ f = open(filename, O_RDONLY);
+ if (f < 0) {
+ fprintf(stderr, "Can't open file: %s\n", filename);
+ exit(1);
+ }
+
+ fstat(f, &s);
+ switch (s.st_mode & S_IFMT) {
+ case S_IFREG:
+ size = s.st_size;
+ break;
+ case S_IFSOCK:
+ case S_IFIFO:
+ size = BLOCKSIZE;
+ break;
+ default:
+ fprintf(stderr, "Bad file: %s\n", filename);
+ exit(1);
+ }
+
+ pos = 0;
+ result = malloc(size + 1);
+ do {
+ if (result == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
+ rc = read(f, &result[pos], (size - pos) + 1);
+ if (rc < 0) {
+ fprintf(stderr, "Error while reading %s\n", filename);
+ exit(1);
+ }
+ if (rc > 0) {
+ pos += (size_t)rc;
+ if (pos > size) {
+ size = pos + BLOCKSIZE;
+ result = realloc(result, size + 1);
+ }
+ }
+ } while(rc > 0);
+
+ close(f);
+ if (length != NULL)
+ *length = pos;
+ result[pos] = 0;
+ return result;
+}
+#endif
+
+typedef struct {
+ unsigned nerror;
+ unsigned ndiffers;
+ unsigned nsuccess;
+ unsigned ninvalid;
+} counters;
+
+static int load_json(const char *filename);
+static int process(counters *c);
+static void close_json();
+static int get_partial(const char *name, struct mustach_sbuf *sbuf);
+
+int main(int ac, char **av)
+{
+ char *f;
+ char *prog = *av;
+ int s;
+ counters c;
+
+ (void)ac; /* unused */
+ flags = Mustach_With_SingleDot | Mustach_With_IncPartial;
+ output = stdout;
+ mustach_wrap_get_partial = get_partial;
+
+ memset(&c, 0, sizeof c);
+ while (*++av) {
+ if (!strcmp(*av, "-h") || !strcmp(*av, "--help"))
+ help(prog);
+ f = (av[0][0] == '-' && !av[0][1]) ? "/dev/stdin" : av[0];
+ fprintf(output, "\nloading %s\n", f);
+ s = load_json(f);
+ if (s < 0) {
+ fprintf(stderr, "error when loading %s!\n", f);
+ if(errmsg)
+ fprintf(stderr, " reason: %s\n", errmsg);
+ exit(1);
+ }
+ fprintf(output, "processing file %s\n", f);
+ s = process(&c);
+ if (s < 0) {
+ fprintf(stderr, "error bad test file %s!\n", f);
+ exit(1);
+ }
+ close_json();
+ }
+ fprintf(output, "\nsummary:\n");
+ if (c.ninvalid)
+ fprintf(output, " invalid %u\n", c.ninvalid);
+ fprintf(output, " error %u\n", c.nerror);
+ fprintf(output, " differ %u\n", c.ndiffers);
+ fprintf(output, " success %u\n", c.nsuccess);
+ if (c.nerror)
+ return 2;
+ if (c.ndiffers)
+ return 1;
+ return 0;
+}
+
+void emit(FILE *f, const char *s)
+{
+ for(;;s++) {
+ switch(*s) {
+ case 0: return;
+ case '\\': fprintf(f, "\\\\"); break;
+ case '\t': fprintf(f, "\\t"); break;
+ case '\n': fprintf(f, "\\n"); break;
+ case '\r': fprintf(f, "\\r"); break;
+ default: fprintf(f, "%c", *s); break;
+ }
+ }
+}
+
+#if TEST == TEST_JSON_C
+
+#include "mustach-json-c.h"
+
+static struct json_object *o;
+
+static struct json_object *partials;
+static int get_partial(const char *name, struct mustach_sbuf *sbuf)
+{
+ struct json_object *x;
+ if (partials == NULL || !json_object_object_get_ex(partials, name, &x))
+ return MUSTACH_ERROR_PARTIAL_NOT_FOUND;
+ sbuf->value = json_object_get_string(x);
+ return MUSTACH_OK;
+}
+
+static int load_json(const char *filename)
+{
+ o = json_object_from_file(filename);
+#if JSON_C_VERSION_NUM >= 0x000D00
+ errmsg = json_util_get_last_err();
+ if (errmsg != NULL)
+ return -1;
+#endif
+ if (o == NULL) {
+ errmsg = "null json";
+ return -1;
+ }
+ return 0;
+}
+static int process(counters *c)
+{
+ const char *t, *e;
+ char *got;
+ unsigned i, n;
+ size_t length;
+ int s;
+ json_object *tests, *unit, *name, *desc, *data, *template, *expected;
+
+ if (!json_object_object_get_ex(o, "tests", &tests) || json_object_get_type(tests) != json_type_array)
+ return -1;
+
+ i = 0;
+ n = (unsigned)json_object_array_length(tests);
+ while (i < n) {
+ unit = json_object_array_get_idx(tests, i);
+ if (json_object_get_type(unit) != json_type_object
+ || !json_object_object_get_ex(unit, "name", &name)
+ || !json_object_object_get_ex(unit, "desc", &desc)
+ || !json_object_object_get_ex(unit, "data", &data)
+ || !json_object_object_get_ex(unit, "template", &template)
+ || !json_object_object_get_ex(unit, "expected", &expected)
+ || json_object_get_type(name) != json_type_string
+ || json_object_get_type(desc) != json_type_string
+ || json_object_get_type(template) != json_type_string
+ || json_object_get_type(expected) != json_type_string) {
+ fprintf(stderr, "invalid test %u\n", i);
+ c->ninvalid++;
+ }
+ else {
+ fprintf(output, "[%u] %s\n", i, json_object_get_string(name));
+ fprintf(output, "\t%s\n", json_object_get_string(desc));
+ if (!json_object_object_get_ex(unit, "partials", &partials))
+ partials = NULL;
+ t = json_object_get_string(template);
+ e = json_object_get_string(expected);
+ s = mustach_json_c_mem(t, 0, data, flags, &got, &length);
+ if (s == 0 && strcmp(got, e) == 0) {
+ fprintf(output, "\t=> SUCCESS\n");
+ c->nsuccess++;
+ }
+ else {
+ if (s < 0) {
+ fprintf(output, "\t=> ERROR %s\n", mustach_error_string(s));
+ c->nerror++;
+ }
+ else {
+ fprintf(output, "\t=> DIFFERS\n");
+ c->ndiffers++;
+ }
+ if (partials)
+ fprintf(output, "\t.. PARTIALS[%s]\n", json_object_to_json_string_ext(partials, 0));
+ fprintf(output, "\t.. DATA[%s]\n", json_object_to_json_string_ext(data, 0));
+ fprintf(output, "\t.. TEMPLATE[");
+ emit(output, t);
+ fprintf(output, "]\n");
+ fprintf(output, "\t.. EXPECTED[");
+ emit(output, e);
+ fprintf(output, "]\n");
+ if (s == 0) {
+ fprintf(output, "\t.. GOT[");
+ emit(output, got);
+ fprintf(output, "]\n");
+ }
+ }
+ free(got);
+ }
+ i++;
+ }
+ return 0;
+}
+static void close_json()
+{
+ json_object_put(o);
+}
+
+#elif TEST == TEST_JANSSON
+
+#include "mustach-jansson.h"
+
+static json_t *o;
+static json_error_t e;
+
+static json_t *partials;
+static int get_partial(const char *name, struct mustach_sbuf *sbuf)
+{
+ json_t *x;
+ if (partials == NULL || !(x = json_object_get(partials, name)))
+ return MUSTACH_ERROR_PARTIAL_NOT_FOUND;
+ sbuf->value = json_string_value(x);
+ return MUSTACH_OK;
+}
+
+static int load_json(const char *filename)
+{
+ o = json_load_file(filename, JSON_DECODE_ANY, &e);
+ if (o == NULL) {
+ errmsg = e.text;
+ return -1;
+ }
+ return 0;
+}
+static int process(counters *c)
+{
+ const char *t, *e;
+ char *got, *tmp;
+ int i, n;
+ size_t length;
+ int s;
+ json_t *tests, *unit, *name, *desc, *data, *template, *expected;
+
+ tests = json_object_get(o, "tests");
+ if (!tests || json_typeof(tests) != JSON_ARRAY)
+ return -1;
+
+ i = 0;
+ n = json_array_size(tests);
+ while (i < n) {
+ unit = json_array_get(tests, i);
+ if (!unit || json_typeof(unit) != JSON_OBJECT
+ || !(name = json_object_get(unit, "name"))
+ || !(desc = json_object_get(unit, "desc"))
+ || !(data = json_object_get(unit, "data"))
+ || !(template = json_object_get(unit, "template"))
+ || !(expected = json_object_get(unit, "expected"))
+ || json_typeof(name) != JSON_STRING
+ || json_typeof(desc) != JSON_STRING
+ || json_typeof(template) != JSON_STRING
+ || json_typeof(expected) != JSON_STRING) {
+ fprintf(stderr, "invalid test %u\n", i);
+ c->ninvalid++;
+ }
+ else {
+ fprintf(output, "[%u] %s\n", i, json_string_value(name));
+ fprintf(output, "\t%s\n", json_string_value(desc));
+ partials = json_object_get(unit, "partials");
+ t = json_string_value(template);
+ e = json_string_value(expected);
+ s = mustach_jansson_mem(t, 0, data, flags, &got, &length);
+ if (s == 0 && strcmp(got, e) == 0) {
+ fprintf(output, "\t=> SUCCESS\n");
+ c->nsuccess++;
+ }
+ else {
+ if (s < 0) {
+ fprintf(output, "\t=> ERROR %s\n", mustach_error_string(s));
+ c->nerror++;
+ }
+ else {
+ fprintf(output, "\t=> DIFFERS\n");
+ c->ndiffers++;
+ }
+ if (partials) {
+ tmp = json_dumps(partials, JSON_ENCODE_ANY | JSON_COMPACT);
+ fprintf(output, "\t.. PARTIALS[%s]\n", tmp);
+ free(tmp);
+ }
+ tmp = json_dumps(data, JSON_ENCODE_ANY | JSON_COMPACT);
+ fprintf(output, "\t.. DATA[%s]\n", tmp);
+ free(tmp);
+ fprintf(output, "\t.. TEMPLATE[");
+ emit(output, t);
+ fprintf(output, "]\n");
+ fprintf(output, "\t.. EXPECTED[");
+ emit(output, e);
+ fprintf(output, "]\n");
+ if (s == 0) {
+ fprintf(output, "\t.. GOT[");
+ emit(output, got);
+ fprintf(output, "]\n");
+ }
+ }
+ free(got);
+ }
+ i++;
+ }
+ return 0;
+}
+static void close_json()
+{
+ json_decref(o);
+}
+
+#elif TEST == TEST_CJSON
+
+#include "mustach-cjson.h"
+
+static cJSON *o;
+static cJSON *partials;
+static int get_partial(const char *name, struct mustach_sbuf *sbuf)
+{
+ cJSON *x;
+ if (partials == NULL || !(x = cJSON_GetObjectItemCaseSensitive(partials, name)))
+ return MUSTACH_ERROR_PARTIAL_NOT_FOUND;
+ sbuf->value = x->valuestring;
+ return MUSTACH_OK;
+}
+
+static int load_json(const char *filename)
+{
+ char *t;
+ size_t length;
+
+ t = readfile(filename, &length);
+ o = t ? cJSON_ParseWithLength(t, length) : NULL;
+ free(t);
+ return -!o;
+}
+static int process(counters *c)
+{
+ const char *t, *e;
+ char *got, *tmp;
+ int i, n;
+ size_t length;
+ int s;
+ cJSON *tests, *unit, *name, *desc, *data, *template, *expected;
+
+ tests = cJSON_GetObjectItemCaseSensitive(o, "tests");
+ if (!tests || tests->type != cJSON_Array)
+ return -1;
+
+ i = 0;
+ n = cJSON_GetArraySize(tests);
+ while (i < n) {
+ unit = cJSON_GetArrayItem(tests, i);
+ if (!unit || unit->type != cJSON_Object
+ || !(name = cJSON_GetObjectItemCaseSensitive(unit, "name"))
+ || !(desc = cJSON_GetObjectItemCaseSensitive(unit, "desc"))
+ || !(data = cJSON_GetObjectItemCaseSensitive(unit, "data"))
+ || !(template = cJSON_GetObjectItemCaseSensitive(unit, "template"))
+ || !(expected = cJSON_GetObjectItemCaseSensitive(unit, "expected"))
+ || name->type != cJSON_String
+ || desc->type != cJSON_String
+ || template->type != cJSON_String
+ || expected->type != cJSON_String) {
+ fprintf(stderr, "invalid test %u\n", i);
+ c->ninvalid++;
+ }
+ else {
+ fprintf(output, "[%u] %s\n", i, name->valuestring);
+ fprintf(output, "\t%s\n", desc->valuestring);
+ partials = cJSON_GetObjectItemCaseSensitive(unit, "partials");
+ t = template->valuestring;
+ e = expected->valuestring;
+ s = mustach_cJSON_mem(t, 0, data, flags, &got, &length);
+ if (s == 0 && strcmp(got, e) == 0) {
+ fprintf(output, "\t=> SUCCESS\n");
+ c->nsuccess++;
+ }
+ else {
+ if (s < 0) {
+ fprintf(output, "\t=> ERROR %s\n", mustach_error_string(s));
+ c->nerror++;
+ }
+ else {
+ fprintf(output, "\t=> DIFFERS\n");
+ c->ndiffers++;
+ }
+ if (partials) {
+ tmp = cJSON_PrintUnformatted(partials);
+ fprintf(output, "\t.. PARTIALS[%s]\n", tmp);
+ free(tmp);
+ }
+ tmp = cJSON_PrintUnformatted(data);
+ fprintf(output, "\t.. DATA[%s]\n", tmp);
+ free(tmp);
+ fprintf(output, "\t.. TEMPLATE[");
+ emit(output, t);
+ fprintf(output, "]\n");
+ fprintf(output, "\t.. EXPECTED[");
+ emit(output, e);
+ fprintf(output, "]\n");
+ if (s == 0) {
+ fprintf(output, "\t.. GOT[");
+ emit(output, got);
+ fprintf(output, "]\n");
+ }
+ }
+ free(got);
+ }
+ i++;
+ }
+ return 0;
+}
+static void close_json()
+{
+ cJSON_Delete(o);
+}
+
+#else
+#error "no defined json library"
+#endif
diff --git a/src/templating/test1/.gitignore b/src/templating/test1/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test1/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test1/Makefile b/src/templating/test1/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test1/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test1/json b/src/templating/test1/json
new file mode 100644
index 000000000..6562fb064
--- /dev/null
+++ b/src/templating/test1/json
@@ -0,0 +1,23 @@
+{
+ "name": "Chris",
+ "value": 10000,
+ "taxed_value": 6000,
+ "in_ca": true,
+ "person": false,
+ "repo": [
+ { "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
+ { "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
+ { "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
+ ],
+ "person?": { "name": "Jon" },
+ "special": "----{{extra}}----\n",
+ "extra": 3.14159,
+ "#sharp": "#",
+ "!bang": "!",
+ "/slash": "/",
+ "^circ": "^",
+ "=equal": "=",
+ ":colon": ":",
+ ">greater": ">",
+ "~tilde": "~"
+}
diff --git a/src/templating/test1/must b/src/templating/test1/must
new file mode 100644
index 000000000..92d30b0b2
--- /dev/null
+++ b/src/templating/test1/must
@@ -0,0 +1,49 @@
+Hello {{name}}
+You have just won {{value}} dollars!
+{{#in_ca}}
+Well, {{taxed_value}} dollars, after taxes.
+{{/in_ca}}
+Shown.
+{{#person}}
+ Never shown!
+{{/person}}
+{{^person}}
+ No person
+{{/person}}
+
+{{#repo}}
+ <b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
+{{/repo}}
+
+{{#person?}}
+ Hi {{name}}!
+{{/person?}}
+
+{{=%(% %)%=}}
+=====================================
+%(%! gros commentaire %)%
+%(%#repo%)%
+ <b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
+%(%/repo%)%
+=====================================
+%(%={{ }}=%)%
+ggggggggg
+{{> special}}
+jjjjjjjjj
+end
+
+{{:#sharp}}
+{{:!bang}}
+{{:~tilde}}
+{{:/~0tilde}}
+{{:/~1slash}} see json pointers IETF RFC 6901
+{{:^circ}}
+{{:\=equal}}
+{{::colon}}
+{{:>greater}}
+
+{{#repo}}
+who 0 {{who.0}}
+who 1 {{who.1}}
+who 2 {{who.2}}
+{{/repo}}
diff --git a/src/templating/test1/resu.ref b/src/templating/test1/resu.ref
new file mode 100644
index 000000000..6cd11bb27
--- /dev/null
+++ b/src/templating/test1/resu.ref
@@ -0,0 +1,41 @@
+Hello Chris
+You have just won 10000 dollars!
+Well, 6000 dollars, after taxes.
+Shown.
+ No person
+
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+
+ Hi Jon!
+
+=====================================
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+=====================================
+ggggggggg
+----3.14159----
+jjjjjjjjj
+end
+
+#
+!
+~
+~
+/ see json pointers IETF RFC 6901
+^
+=
+:
+&gt;
+
+who 0 {&quot;commiter&quot;:&quot;joe&quot;}
+who 1 {&quot;reviewer&quot;:&quot;avrel&quot;}
+who 2 {&quot;commiter&quot;:&quot;william&quot;}
+who 0 {&quot;commiter&quot;:&quot;jack&quot;}
+who 1 {&quot;reviewer&quot;:&quot;avrel&quot;}
+who 2 {&quot;commiter&quot;:&quot;greg&quot;}
+who 0 {&quot;reviewer&quot;:&quot;joe&quot;}
+who 1 {&quot;reviewer&quot;:&quot;jack&quot;}
+who 2 {&quot;commiter&quot;:&quot;greg&quot;}
diff --git a/src/templating/test1/vg.ref b/src/templating/test1/vg.ref
new file mode 100644
index 000000000..d086e59c5
--- /dev/null
+++ b/src/templating/test1/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 111 allocs, 111 frees, 9,702 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test2/.gitignore b/src/templating/test2/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test2/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test2/Makefile b/src/templating/test2/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test2/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test2/json b/src/templating/test2/json
new file mode 100644
index 000000000..8c668b3b1
--- /dev/null
+++ b/src/templating/test2/json
@@ -0,0 +1,9 @@
+{
+ "header": "Colors",
+ "items": [
+ {"name": "red", "first": true, "url": "#Red"},
+ {"name": "green", "link": true, "url": "#Green"},
+ {"name": "blue", "link": true, "url": "#Blue"}
+ ],
+ "empty": false
+}
diff --git a/src/templating/test2/must b/src/templating/test2/must
new file mode 100644
index 000000000..aa6da7077
--- /dev/null
+++ b/src/templating/test2/must
@@ -0,0 +1,17 @@
+<h1>{{header}}</h1>
+{{#bug}}
+{{/bug}}
+
+{{#items}}
+ {{#first}}
+ <li><strong>{{name}}</strong></li>
+ {{/first}}
+ {{#link}}
+ <li><a href="{{url}}">{{name}}</a></li>
+ {{/link}}
+{{/items}}
+
+{{#empty}}
+ <p>The list is empty.</p>
+{{/empty}}
+
diff --git a/src/templating/test2/resu.ref b/src/templating/test2/resu.ref
new file mode 100644
index 000000000..5a200a9bf
--- /dev/null
+++ b/src/templating/test2/resu.ref
@@ -0,0 +1,7 @@
+<h1>Colors</h1>
+
+ <li><strong>red</strong></li>
+ <li><a href="#Green">green</a></li>
+ <li><a href="#Blue">blue</a></li>
+
+
diff --git a/src/templating/test2/vg.ref b/src/templating/test2/vg.ref
new file mode 100644
index 000000000..e4b4f6d37
--- /dev/null
+++ b/src/templating/test2/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 38 allocs, 38 frees, 5,712 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test3/.gitignore b/src/templating/test3/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test3/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test3/Makefile b/src/templating/test3/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test3/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test3/json b/src/templating/test3/json
new file mode 100644
index 000000000..792788171
--- /dev/null
+++ b/src/templating/test3/json
@@ -0,0 +1,7 @@
+{
+ "name": "Chris",
+ "company": "<b>GitHub & Co</b>",
+ "names": ["Chris", "Kross"],
+ "skills": ["JavaScript", "PHP", "Java"],
+ "age": 18
+}
diff --git a/src/templating/test3/must b/src/templating/test3/must
new file mode 100644
index 000000000..5c490469b
--- /dev/null
+++ b/src/templating/test3/must
@@ -0,0 +1,15 @@
+* {{name}}
+* {{age}}
+* {{company}}
+* {{&company}}
+* {{{company}}}
+{{=<% %>=}}
+* <%company%>
+* <%&company%>
+* <%{company}%>
+
+<%={{ }}=%>
+* <ul>{{#names}}<li>{{.}}</li>{{/names}}</ul>
+* skills: <ul>{{#skills}}<li>{{.}}</li>{{/skills}}</ul>
+{{#age}}* age: {{.}}{{/age}}
+
diff --git a/src/templating/test3/resu.ref b/src/templating/test3/resu.ref
new file mode 100644
index 000000000..ee6dad3fb
--- /dev/null
+++ b/src/templating/test3/resu.ref
@@ -0,0 +1,13 @@
+* Chris
+* 18
+* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
+* <b>GitHub & Co</b>
+* <b>GitHub & Co</b>
+* &lt;b&gt;GitHub &amp; Co&lt;/b&gt;
+* <b>GitHub & Co</b>
+* <b>GitHub & Co</b>
+
+* <ul><li>Chris</li><li>Kross</li></ul>
+* skills: <ul><li>JavaScript</li><li>PHP</li><li>Java</li></ul>
+* age: 18
+
diff --git a/src/templating/test3/vg.ref b/src/templating/test3/vg.ref
new file mode 100644
index 000000000..21f7931eb
--- /dev/null
+++ b/src/templating/test3/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 30 allocs, 30 frees, 5,831 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test4/.gitignore b/src/templating/test4/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test4/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test4/Makefile b/src/templating/test4/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test4/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test4/json b/src/templating/test4/json
new file mode 100644
index 000000000..a10836072
--- /dev/null
+++ b/src/templating/test4/json
@@ -0,0 +1,13 @@
+{
+ "person": { "name": "Jon", "age": 25 },
+ "person.name": "Fred",
+ "person.name=Fred": "The other Fred.",
+ "persons": [
+ { "name": "Jon", "age": 25, "lang": "en" },
+ { "name": "Henry", "age": 27, "lang": "en" },
+ { "name": "Amed", "age": 24, "lang": "fr" } ],
+ "fellows": {
+ "Jon": { "age": 25, "lang": "en" },
+ "Henry": { "age": 27, "lang": "en" },
+ "Amed": { "age": 24, "lang": "fr" } }
+}
diff --git a/src/templating/test4/must b/src/templating/test4/must
new file mode 100644
index 000000000..003b93666
--- /dev/null
+++ b/src/templating/test4/must
@@ -0,0 +1,58 @@
+This are extensions!!
+
+{{person.name}}
+{{person.age}}
+
+{{person\.name}}
+{{person\.name\=Fred}}
+
+{{#person.name=Jon}}
+Hello Jon
+{{/person.name=Jon}}
+
+{{^person.name=Jon}}
+No Jon? Hey Jon...
+{{/person.name=Jon}}
+
+{{^person.name=Harry}}
+No Harry? Hey Calahan...
+{{/person.name=Harry}}
+
+{{#person\.name=Fred}}
+Hello Fred
+{{/person\.name=Fred}}
+
+{{^person\.name=Fred}}
+No Fred? Hey Fred...
+{{/person\.name=Fred}}
+
+{{#person\.name\=Fred=The other Fred.}}
+Hello Fred#2
+{{/person\.name\=Fred=The other Fred.}}
+
+{{^person\.name\=Fred=The other Fred.}}
+No Fred#2? Hey Fred#2...
+{{/person\.name\=Fred=The other Fred.}}
+
+{{#persons}}
+{{#lang=!fr}}Hello {{name}}, {{age}} years{{/lang=!fr}}
+{{#lang=fr}}Salut {{name}}, {{age}} ans{{/lang=fr}}
+{{/persons}}
+
+{{#persons}}
+{{name}}: {{age=24}}/{{age}}/{{age=!27}}
+{{/persons}}
+
+{{#fellows.*}}
+{{*}}: {{age=24}}/{{age}}/{{age=!27}}
+{{/fellows.*}}
+
+{{#*}}
+ (1) {{*}}: {{.}}
+ {{#*}}
+ (2) {{*}}: {{.}}
+ {{#*}}
+ (3) {{*}}: {{.}}
+ {{/*}}
+ {{/*}}
+{{/*}}
diff --git a/src/templating/test4/resu.ref b/src/templating/test4/resu.ref
new file mode 100644
index 000000000..8a71c4e82
--- /dev/null
+++ b/src/templating/test4/resu.ref
@@ -0,0 +1,50 @@
+This are extensions!!
+
+Jon
+25
+
+Fred
+The other Fred.
+
+Hello Jon
+
+
+No Harry? Hey Calahan...
+
+Hello Fred
+
+
+Hello Fred#2
+
+
+Hello Jon, 25 years
+
+Hello Henry, 27 years
+
+
+Salut Amed, 24 ans
+
+Jon: /25/25
+Henry: /27/
+Amed: 24/24/24
+
+Jon: /25/25
+Henry: /27/
+Amed: 24/24/24
+
+ (1) person: {&quot;name&quot;:&quot;Jon&quot;,&quot;age&quot;:25}
+ (2) name: Jon
+ (2) age: 25
+ (1) person.name: Fred
+ (1) person.name=Fred: The other Fred.
+ (1) persons: [{&quot;name&quot;:&quot;Jon&quot;,&quot;age&quot;:25,&quot;lang&quot;:&quot;en&quot;},{&quot;name&quot;:&quot;Henry&quot;,&quot;age&quot;:27,&quot;lang&quot;:&quot;en&quot;},{&quot;name&quot;:&quot;Amed&quot;,&quot;age&quot;:24,&quot;lang&quot;:&quot;fr&quot;}]
+ (1) fellows: {&quot;Jon&quot;:{&quot;age&quot;:25,&quot;lang&quot;:&quot;en&quot;},&quot;Henry&quot;:{&quot;age&quot;:27,&quot;lang&quot;:&quot;en&quot;},&quot;Amed&quot;:{&quot;age&quot;:24,&quot;lang&quot;:&quot;fr&quot;}}
+ (2) Jon: {&quot;age&quot;:25,&quot;lang&quot;:&quot;en&quot;}
+ (3) age: 25
+ (3) lang: en
+ (2) Henry: {&quot;age&quot;:27,&quot;lang&quot;:&quot;en&quot;}
+ (3) age: 27
+ (3) lang: en
+ (2) Amed: {&quot;age&quot;:24,&quot;lang&quot;:&quot;fr&quot;}
+ (3) age: 24
+ (3) lang: fr
diff --git a/src/templating/test4/vg.ref b/src/templating/test4/vg.ref
new file mode 100644
index 000000000..922b0676d
--- /dev/null
+++ b/src/templating/test4/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 121 allocs, 121 frees, 14,608 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test5/.gitignore b/src/templating/test5/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test5/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test5/Makefile b/src/templating/test5/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test5/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test5/json b/src/templating/test5/json
new file mode 100644
index 000000000..6562fb064
--- /dev/null
+++ b/src/templating/test5/json
@@ -0,0 +1,23 @@
+{
+ "name": "Chris",
+ "value": 10000,
+ "taxed_value": 6000,
+ "in_ca": true,
+ "person": false,
+ "repo": [
+ { "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
+ { "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
+ { "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
+ ],
+ "person?": { "name": "Jon" },
+ "special": "----{{extra}}----\n",
+ "extra": 3.14159,
+ "#sharp": "#",
+ "!bang": "!",
+ "/slash": "/",
+ "^circ": "^",
+ "=equal": "=",
+ ":colon": ":",
+ ">greater": ">",
+ "~tilde": "~"
+}
diff --git a/src/templating/test5/must b/src/templating/test5/must
new file mode 100644
index 000000000..44305df24
--- /dev/null
+++ b/src/templating/test5/must
@@ -0,0 +1,23 @@
+=====================================
+from json
+{{> special}}
+=====================================
+not found
+{{> notfound}}
+=====================================
+without extension first
+{{> must2 }}
+=====================================
+last with extension
+{{> must3 }}
+=====================================
+Ensure must3 didn't change specials
+
+{{#person?}}
+ Hi {{name}}!
+{{/person?}}
+
+%(%#person?%)%
+ Hi %(%name%)%!
+%(%/person?%)%
+
diff --git a/src/templating/test5/must2 b/src/templating/test5/must2
new file mode 100644
index 000000000..d4a1d3783
--- /dev/null
+++ b/src/templating/test5/must2
@@ -0,0 +1,14 @@
+must2 == BEGIN
+Hello {{name}}
+You have just won {{value}} dollars!
+{{#in_ca}}
+Well, {{taxed_value}} dollars, after taxes.
+{{/in_ca}}
+Shown.
+{{#person}}
+ Never shown!
+{{/person}}
+{{^person}}
+ No person
+{{/person}}
+must2 == END
diff --git a/src/templating/test5/must2.mustache b/src/templating/test5/must2.mustache
new file mode 100644
index 000000000..33f1ead38
--- /dev/null
+++ b/src/templating/test5/must2.mustache
@@ -0,0 +1 @@
+must2.mustache ==SHOULD NOT BE SEEN==
diff --git a/src/templating/test5/must3.mustache b/src/templating/test5/must3.mustache
new file mode 100644
index 000000000..67eddb1ef
--- /dev/null
+++ b/src/templating/test5/must3.mustache
@@ -0,0 +1,17 @@
+must3.mustache == BEGIN
+{{#repo}}
+ <b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
+{{/repo}}
+
+{{#person?}}
+ Hi {{name}}!
+{{/person?}}
+
+{{=%(% %)%=}}
+=====================================
+%(%! big comment %)%
+%(%#repo%)%
+ <b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
+%(%/repo%)%
+=====================================
+must3.mustache == END
diff --git a/src/templating/test5/resu.ref b/src/templating/test5/resu.ref
new file mode 100644
index 000000000..f2a608568
--- /dev/null
+++ b/src/templating/test5/resu.ref
@@ -0,0 +1,38 @@
+=====================================
+from json
+----3.14159----
+=====================================
+not found
+=====================================
+without extension first
+must2 == BEGIN
+Hello Chris
+You have just won 10000 dollars!
+Well, 6000 dollars, after taxes.
+Shown.
+ No person
+must2 == END
+=====================================
+last with extension
+must3.mustache == BEGIN
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+
+ Hi Jon!
+
+=====================================
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+=====================================
+must3.mustache == END
+=====================================
+Ensure must3 didn't change specials
+
+ Hi Jon!
+
+%(%#person?%)%
+ Hi %(%name%)%!
+%(%/person?%)%
+
diff --git a/src/templating/test5/vg.ref b/src/templating/test5/vg.ref
new file mode 100644
index 000000000..89dc21bcb
--- /dev/null
+++ b/src/templating/test5/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 123 allocs, 123 frees, 20,610 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test6/.gitignore b/src/templating/test6/.gitignore
new file mode 100644
index 000000000..15e6dd5a5
--- /dev/null
+++ b/src/templating/test6/.gitignore
@@ -0,0 +1,3 @@
+resu.last
+vg.last
+test-custom-write
diff --git a/src/templating/test6/Makefile b/src/templating/test6/Makefile
new file mode 100644
index 000000000..ea4f86e79
--- /dev/null
+++ b/src/templating/test6/Makefile
@@ -0,0 +1,12 @@
+.PHONY: test clean
+
+test-custom-write: test-custom-write.c ../mustach-json-c.h ../mustach-json-c.c ../mustach-wrap.c ../mustach.h ../mustach.c
+ @echo building test-custom-write
+ $(CC) $(CFLAGS) $(LDFLAGS) -g -o test-custom-write test-custom-write.c ../mustach.c ../mustach-json-c.c ../mustach-wrap.c -ljson-c
+
+test: test-custom-write
+ @mustach=./test-custom-write ../dotest.sh json -U must -l must -x must
+
+clean:
+ rm -f resu.last vg.last test-custom-write
+
diff --git a/src/templating/test6/json b/src/templating/test6/json
new file mode 100644
index 000000000..6562fb064
--- /dev/null
+++ b/src/templating/test6/json
@@ -0,0 +1,23 @@
+{
+ "name": "Chris",
+ "value": 10000,
+ "taxed_value": 6000,
+ "in_ca": true,
+ "person": false,
+ "repo": [
+ { "name": "resque", "who": [ { "commiter": "joe" }, { "reviewer": "avrel" }, { "commiter": "william" } ] },
+ { "name": "hub", "who": [ { "commiter": "jack" }, { "reviewer": "avrel" }, { "commiter": "greg" } ] },
+ { "name": "rip", "who": [ { "reviewer": "joe" }, { "reviewer": "jack" }, { "commiter": "greg" } ] }
+ ],
+ "person?": { "name": "Jon" },
+ "special": "----{{extra}}----\n",
+ "extra": 3.14159,
+ "#sharp": "#",
+ "!bang": "!",
+ "/slash": "/",
+ "^circ": "^",
+ "=equal": "=",
+ ":colon": ":",
+ ">greater": ">",
+ "~tilde": "~"
+}
diff --git a/src/templating/test6/must b/src/templating/test6/must
new file mode 100644
index 000000000..6df523669
--- /dev/null
+++ b/src/templating/test6/must
@@ -0,0 +1,43 @@
+Hello {{name}}
+You have just won {{value}} dollars!
+{{#in_ca}}
+Well, {{taxed_value}} dollars, after taxes.
+{{/in_ca}}
+Shown.
+{{#person}}
+ Never shown!
+{{/person}}
+{{^person}}
+ No person
+{{/person}}
+
+{{#repo}}
+ <b>{{name}}</b> reviewers:{{#who}} {{reviewer}}{{/who}} commiters:{{#who}} {{commiter}}{{/who}}
+{{/repo}}
+
+{{#person?}}
+ Hi {{name}}!
+{{/person?}}
+
+{{=%(% %)%=}}
+=====================================
+%(%! gros commentaire %)%
+%(%#repo%)%
+ <b>%(%name%)%</b> reviewers:%(%#who%)% %(%reviewer%)%%(%/who%)% commiters:%(%#who%)% %(%commiter%)%%(%/who%)%
+%(%/repo%)%
+=====================================
+%(%={{ }}=%)%
+ggggggggg
+{{> special}}
+jjjjjjjjj
+end
+
+{{:#sharp}}
+{{:!bang}}
+{{:~tilde}}
+{{:/~0tilde}}
+{{:/~1slash}} see json pointers IETF RFC 6901
+{{:^circ}}
+{{:\=equal}}
+{{::colon}}
+{{:>greater}}
diff --git a/src/templating/test6/resu.ref b/src/templating/test6/resu.ref
new file mode 100644
index 000000000..377eb11af
--- /dev/null
+++ b/src/templating/test6/resu.ref
@@ -0,0 +1,93 @@
+HELLO CHRIS
+YOU HAVE JUST WON 10000 DOLLARS!
+WELL, 6000 DOLLARS, AFTER TAXES.
+SHOWN.
+ NO PERSON
+
+ <B>RESQUE</B> REVIEWERS: AVREL COMMITERS: JOE WILLIAM
+ <B>HUB</B> REVIEWERS: AVREL COMMITERS: JACK GREG
+ <B>RIP</B> REVIEWERS: JOE JACK COMMITERS: GREG
+
+ HI JON!
+
+=====================================
+ <B>RESQUE</B> REVIEWERS: AVREL COMMITERS: JOE WILLIAM
+ <B>HUB</B> REVIEWERS: AVREL COMMITERS: JACK GREG
+ <B>RIP</B> REVIEWERS: JOE JACK COMMITERS: GREG
+=====================================
+GGGGGGGGG
+----3.14159----
+JJJJJJJJJ
+END
+
+#
+!
+~
+~
+/ SEE JSON POINTERS IETF RFC 6901
+^
+=
+:
+&GT;
+hello chris
+you have just won 10000 dollars!
+well, 6000 dollars, after taxes.
+shown.
+ no person
+
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+
+ hi jon!
+
+=====================================
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+=====================================
+ggggggggg
+----3.14159----
+jjjjjjjjj
+end
+
+#
+!
+~
+~
+/ see json pointers ietf rfc 6901
+^
+=
+:
+&gt;
+Hello Chris
+You have just won 10000 dollars!
+Well, 6000 dollars, after taxes.
+Shown.
+ No person
+
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+
+ Hi Jon!
+
+=====================================
+ <b>resque</b> reviewers: avrel commiters: joe william
+ <b>hub</b> reviewers: avrel commiters: jack greg
+ <b>rip</b> reviewers: joe jack commiters: greg
+=====================================
+ggggggggg
+----3.14159----
+jjjjjjjjj
+end
+
+#
+!
+~
+~
+/ see json pointers IETF RFC 6901
+^
+=
+:
+&gt;
diff --git a/src/templating/test6/test-custom-write.c b/src/templating/test6/test-custom-write.c
new file mode 100644
index 000000000..20042c1ed
--- /dev/null
+++ b/src/templating/test6/test-custom-write.c
@@ -0,0 +1,149 @@
+/*
+ Author: José Bollo <jobol@nonadev.net>
+
+ https://gitlab.com/jobol/mustach
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <libgen.h>
+
+#include "../mustach-json-c.h"
+
+static const size_t BLOCKSIZE = 8192;
+
+static char *readfile(const char *filename)
+{
+ int f;
+ struct stat s;
+ char *result, *ptr;
+ size_t size, pos;
+ ssize_t rc;
+
+ result = NULL;
+ if (filename[0] == '-' && filename[1] == 0)
+ f = dup(0);
+ else
+ f = open(filename, O_RDONLY);
+ if (f < 0) {
+ fprintf(stderr, "Can't open file: %s\n", filename);
+ exit(1);
+ }
+
+ fstat(f, &s);
+ switch (s.st_mode & S_IFMT) {
+ case S_IFREG:
+ size = s.st_size;
+ break;
+ case S_IFSOCK:
+ case S_IFIFO:
+ size = BLOCKSIZE;
+ break;
+ default:
+ fprintf(stderr, "Bad file: %s\n", filename);
+ exit(1);
+ }
+
+ pos = 0;
+ result = malloc(size + 1);
+ do {
+ if (result == NULL) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
+ rc = read(f, &result[pos], (size - pos) + 1);
+ if (rc < 0) {
+ fprintf(stderr, "Error while reading %s\n", filename);
+ exit(1);
+ }
+ if (rc > 0) {
+ pos += (size_t)rc;
+ if (pos > size) {
+ size = pos + BLOCKSIZE;
+ ptr = realloc(result, size + 1);
+ if (!ptr)
+ free(result);
+ result = ptr;
+ }
+ }
+ } while(rc > 0);
+
+ close(f);
+ result[pos] = 0;
+ return result;
+}
+
+enum { None, Upper, Lower } mode = None;
+
+int uwrite(void *closure, const char *buffer, size_t size)
+{
+ switch(mode) {
+ case None:
+ fwrite(buffer, size, 1, stdout);
+ break;
+ case Upper:
+ while(size--)
+ fputc(toupper(*buffer++), stdout);
+ break;
+ case Lower:
+ while(size--)
+ fputc(tolower(*buffer++), stdout);
+ break;
+ }
+ return 0;
+}
+
+int main(int ac, char **av)
+{
+ struct json_object *o;
+ char *t;
+ char *prog = *av;
+ int s;
+
+ if (*++av) {
+ o = json_object_from_file(av[0]);
+ if (o == NULL) {
+ fprintf(stderr, "Aborted: null json (file %s)\n", av[0]);
+ exit(1);
+ }
+ while(*++av) {
+ if (!strcmp(*av, "-U"))
+ mode = Upper;
+ else if (!strcmp(*av, "-l"))
+ mode = Lower;
+ else if (!strcmp(*av, "-x"))
+ mode = None;
+ else {
+ t = readfile(*av);
+ s = mustach_json_c_write(t, 0, o, Mustach_With_AllExtensions, uwrite, NULL);
+ if (s != 0)
+ fprintf(stderr, "Template error %d\n", s);
+ free(t);
+ }
+ }
+ json_object_put(o);
+ }
+ return 0;
+}
+
diff --git a/src/templating/test6/vg.ref b/src/templating/test6/vg.ref
new file mode 100644
index 000000000..fb0e31bd8
--- /dev/null
+++ b/src/templating/test6/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ./test-custom-write json -U must -l must -x must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 174 allocs, 174 frees, 24,250 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test7/Makefile b/src/templating/test7/Makefile
new file mode 100644
index 000000000..8e3a3b990
--- /dev/null
+++ b/src/templating/test7/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json base.mustache
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test7/base.mustache b/src/templating/test7/base.mustache
new file mode 100644
index 000000000..f701e0c65
--- /dev/null
+++ b/src/templating/test7/base.mustache
@@ -0,0 +1,2 @@
+family:
+{{> node}}
diff --git a/src/templating/test7/json b/src/templating/test7/json
new file mode 100644
index 000000000..c9ee47150
--- /dev/null
+++ b/src/templating/test7/json
@@ -0,0 +1,8 @@
+{ "data": "grandparent", "children": [
+ { "data": "parent", "children": [
+ { "data": "child", "children": [] }
+ ]},
+ { "data": "parent2", "children": [
+ { "data": "child2", "children": [ { "data": "pet", "children": false } ]}
+ ]}
+]}
diff --git a/src/templating/test7/node.mustache b/src/templating/test7/node.mustache
new file mode 100644
index 000000000..4154b12ba
--- /dev/null
+++ b/src/templating/test7/node.mustache
@@ -0,0 +1,4 @@
+<{{data}}>
+{{#children}}
+ {{> node}}
+{{/children}}
diff --git a/src/templating/test7/resu.ref b/src/templating/test7/resu.ref
new file mode 100644
index 000000000..d02b24e11
--- /dev/null
+++ b/src/templating/test7/resu.ref
@@ -0,0 +1,7 @@
+family:
+<grandparent>
+ <parent>
+ <child>
+ <parent2>
+ <child2>
+ <pet>
diff --git a/src/templating/test7/vg.ref b/src/templating/test7/vg.ref
new file mode 100644
index 000000000..032e6c447
--- /dev/null
+++ b/src/templating/test7/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json base.mustache
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 69 allocs, 69 frees, 36,313 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test8/.gitignore b/src/templating/test8/.gitignore
new file mode 100644
index 000000000..4d897daa0
--- /dev/null
+++ b/src/templating/test8/.gitignore
@@ -0,0 +1,2 @@
+resu.last
+vg.last
diff --git a/src/templating/test8/Makefile b/src/templating/test8/Makefile
new file mode 100644
index 000000000..1a3e57914
--- /dev/null
+++ b/src/templating/test8/Makefile
@@ -0,0 +1,8 @@
+.PHONY: test clean
+
+test:
+ @../dotest.sh json must
+
+clean:
+ rm -f resu.last vg.last
+
diff --git a/src/templating/test8/json b/src/templating/test8/json
new file mode 100644
index 000000000..04a1e4aaa
--- /dev/null
+++ b/src/templating/test8/json
@@ -0,0 +1,8 @@
+{
+"val1": "",
+"val2": 0,
+"val3": false,
+"val4": null,
+"val5": [],
+"val6": 0.0
+}
diff --git a/src/templating/test8/must b/src/templating/test8/must
new file mode 100644
index 000000000..a22374438
--- /dev/null
+++ b/src/templating/test8/must
@@ -0,0 +1,6 @@
+x{{#val1}} {{.}} {{/val1}}x
+x{{#val2}} {{.}} {{/val2}}x
+x{{#val3}} {{.}} {{/val3}}x
+x{{#val4}} {{.}} {{/val4}}x
+x{{#val5}} {{.}} {{/val5}}x
+x{{#val6}} {{.}} {{/val6}}x
diff --git a/src/templating/test8/resu.ref b/src/templating/test8/resu.ref
new file mode 100644
index 000000000..e0c16e49a
--- /dev/null
+++ b/src/templating/test8/resu.ref
@@ -0,0 +1,6 @@
+xx
+xx
+xx
+xx
+xx
+xx
diff --git a/src/templating/test8/vg.ref b/src/templating/test8/vg.ref
new file mode 100644
index 000000000..b5b0235f9
--- /dev/null
+++ b/src/templating/test8/vg.ref
@@ -0,0 +1,14 @@
+Memcheck, a memory error detector
+Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
+Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
+Command: ../mustach json must
+
+
+HEAP SUMMARY:
+ in use at exit: 0 bytes in 0 blocks
+ total heap usage: 17 allocs, 17 frees, 4,832 bytes allocated
+
+All heap blocks were freed -- no leaks are possible
+
+For lists of detected and suppressed errors, rerun with: -s
+ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
diff --git a/src/templating/test_mustach_jansson.c b/src/templating/test_mustach_jansson.c
new file mode 100644
index 000000000..beb155f6d
--- /dev/null
+++ b/src/templating/test_mustach_jansson.c
@@ -0,0 +1,125 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+
+/**
+ * @file test_mustach_jansson.c
+ * @brief testcase to test the mustach/jansson integration
+ * @author Florian Dold
+ */
+#include "platform.h"
+#include "mustach-jansson.h"
+#include <gnunet/gnunet_util_lib.h>
+
+static void
+assert_template (const char *template,
+ json_t *root,
+ const char *expected)
+{
+ char *r;
+ size_t sz;
+
+ GNUNET_assert (0 == mustach_jansson_mem (template,
+ 0,
+ root,
+ Mustach_With_AllExtensions,
+ &r,
+ &sz));
+ GNUNET_assert (0 == strcmp (r,
+ expected));
+ GNUNET_free (r);
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ json_t *root = json_object ();
+ json_t *arr = json_array ();
+ json_t *obj = json_object ();
+ /* test 1 */
+ const char *t1 = "hello world";
+ const char *x1 = "hello world";
+ /* test 2 */
+ const char *t2 = "hello {{ v1 }}";
+ const char *x2 = "hello world";
+ /* test 3 */
+ const char *t3 = "hello {{ v3.x }}";
+ const char *x3 = "hello baz";
+ /* test 4 */
+ const char *t4 = "hello {{# v2 }}{{ . }}{{/ v2 }}";
+ const char *x4 = "hello foobar";
+ /* test 5 */
+ const char *t5 = "hello {{# v3 }}{{ y }}/{{ x }}{{ z }}{{/ v3 }}";
+ const char *x5 = "hello quux/baz";
+ /* test 8 */
+ const char *t8 = "{{^ v4 }}fallback{{/ v4 }}";
+ const char *x8 = "fallback";
+
+ (void) argc;
+ (void) argv;
+ GNUNET_log_setup ("test-mustach-jansson",
+ "INFO",
+ NULL);
+ GNUNET_assert (NULL != root);
+ GNUNET_assert (NULL != arr);
+ GNUNET_assert (NULL != obj);
+ GNUNET_assert (0 ==
+ json_object_set_new (root,
+ "v1",
+ json_string ("world")));
+ GNUNET_assert (0 ==
+ json_object_set_new (root,
+ "v4",
+ json_array ()));
+ GNUNET_assert (0 ==
+ json_array_append_new (arr,
+ json_string ("foo")));
+ GNUNET_assert (0 ==
+ json_array_append_new (arr,
+ json_string ("bar")));
+ GNUNET_assert (0 ==
+ json_object_set_new (root,
+ "v2",
+ arr));
+ GNUNET_assert (0 ==
+ json_object_set_new (root,
+ "v3",
+ obj));
+ GNUNET_assert (0 ==
+ json_object_set_new (root,
+ "amt",
+ json_string ("EUR:123.00")));
+ GNUNET_assert (0 ==
+ json_object_set_new (obj,
+ "x",
+ json_string ("baz")));
+ GNUNET_assert (0 ==
+ json_object_set_new (obj,
+ "y",
+ json_string ("quux")));
+ assert_template (t1, root, x1);
+ assert_template (t2, root, x2);
+ assert_template (t3, root, x3);
+ assert_template (t4, root, x4);
+ assert_template (t5, root, x5);
+ assert_template (t8, root, x8);
+ json_decref (root);
+ return 0;
+}
diff --git a/src/testing/.gitignore b/src/testing/.gitignore
index 6a19ba005..e1075ab16 100644
--- a/src/testing/.gitignore
+++ b/src/testing/.gitignore
@@ -8,6 +8,10 @@ test_taler_exchange_aggregator-postgres
test_taler_exchange_wirewatch-postgres
test_exchange_api_revocation_cs
test_exchange_api_revocation_rsa
+test_exchange_api_age_restriction_cs
+test_exchange_api_age_restriction_rsa
+test_exchange_api_conflicts_cs
+test_exchange_api_conflicts_rsa
report*
test_exchange_management_api_cs
test_exchange_management_api_rsa
@@ -46,3 +50,13 @@ test_exchange_api_twisted_cs
test_exchange_api_twisted_rsa
test_exchange_p2p_cs
test_exchange_p2p_rsa
+*.edited
+tmp-last-response.*
+test_exchange_api_home/taler/auditor/
+test_exchange_api_home/taler/exchange-offline/secm_tofus.pub
+test_exchange_api_home/taler/exchange-secmod-cs/
+test_exchange_api_home/taler/exchange-secmod-eddsa/
+test_exchange_api_home/taler/exchange-secmod-rsa/
+test_exchange_api_keys_cherry_picking_home/taler/
+test_taler_exchange_httpd_home/taler/
+libeufin-bank.pid
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 74facda0a..195ab4c55 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -13,6 +13,9 @@ endif
clean-local:
rm -rf report*
+bin_SCRIPTS = \
+ taler-unified-setup.sh
+
# Libraries
lib_LTLIBRARIES = \
@@ -37,11 +40,11 @@ libtalertesting_la_LDFLAGS = \
-version-info 0:0:0 \
-no-undefined
libtalertesting_la_SOURCES = \
+ testing_api_cmd_age_withdraw.c \
testing_api_cmd_auditor_add_denom_sig.c \
testing_api_cmd_auditor_add.c \
testing_api_cmd_auditor_del.c \
testing_api_cmd_auditor_deposit_confirmation.c \
- testing_api_cmd_auditor_exchanges.c \
testing_api_cmd_auditor_exec_auditor.c \
testing_api_cmd_auditor_exec_auditor_dbinit.c \
testing_api_cmd_bank_admin_add_incoming.c \
@@ -54,8 +57,9 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_batch.c \
testing_api_cmd_batch_deposit.c \
testing_api_cmd_batch_withdraw.c \
- testing_api_cmd_change_auth.c \
- testing_api_cmd_check_keys.c \
+ testing_api_cmd_check_aml_decision.c \
+ testing_api_cmd_check_aml_decisions.c \
+ testing_api_cmd_coin_history.c \
testing_api_cmd_common.c \
testing_api_cmd_contract_get.c \
testing_api_cmd_deposit.c \
@@ -66,7 +70,10 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_exec_expire.c \
testing_api_cmd_exec_router.c \
testing_api_cmd_exec_transfer.c \
+ testing_api_cmd_exec_wget.c \
testing_api_cmd_exec_wirewatch.c \
+ testing_api_cmd_get_auditor.c \
+ testing_api_cmd_get_exchange.c \
testing_api_cmd_insert_deposit.c \
testing_api_cmd_kyc_check_get.c \
testing_api_cmd_kyc_proof.c \
@@ -77,40 +84,46 @@ libtalertesting_la_SOURCES = \
testing_api_cmd_offline_sign_keys.c \
testing_api_cmd_offline_sign_extensions.c \
testing_api_cmd_purse_create_deposit.c \
+ testing_api_cmd_purse_delete.c \
testing_api_cmd_purse_deposit.c \
testing_api_cmd_purse_get.c \
testing_api_cmd_purse_merge.c \
- testing_api_cmd_set_wire_fee.c \
testing_api_cmd_recoup.c \
testing_api_cmd_recoup_refresh.c \
testing_api_cmd_refund.c \
testing_api_cmd_refresh.c \
+ testing_api_cmd_reserve_attest.c \
+ testing_api_cmd_reserve_close.c \
testing_api_cmd_reserve_get.c \
+ testing_api_cmd_reserve_get_attestable.c \
testing_api_cmd_reserve_history.c \
+ testing_api_cmd_reserve_open.c \
testing_api_cmd_reserve_purse.c \
- testing_api_cmd_reserve_status.c \
testing_api_cmd_revoke.c \
testing_api_cmd_revoke_denom_key.c \
testing_api_cmd_revoke_sign_key.c \
- testing_api_cmd_rewind.c \
- testing_api_cmd_serialize_keys.c \
+ testing_api_cmd_run_fakebank.c \
+ testing_api_cmd_set_officer.c \
+ testing_api_cmd_set_wire_fee.c \
testing_api_cmd_signal.c \
testing_api_cmd_sleep.c \
testing_api_cmd_stat.c \
+ testing_api_cmd_system_start.c \
+ testing_api_cmd_take_aml_decision.c \
testing_api_cmd_transfer_get.c \
testing_api_cmd_wait.c \
- testing_api_cmd_wire.c \
testing_api_cmd_wire_add.c \
testing_api_cmd_wire_del.c \
testing_api_cmd_withdraw.c \
- testing_api_helpers_auditor.c \
- testing_api_helpers_bank.c \
- testing_api_helpers_exchange.c \
testing_api_loop.c \
+ testing_api_misc.c \
testing_api_traits.c
+
+
libtalertesting_la_LIBADD = \
$(top_builddir)/src/lib/libtalerauditor.la \
$(top_builddir)/src/lib/libtalerexchange.la \
+ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/mhd/libtalermhd.la \
$(top_builddir)/src/util/libtalerutil.la \
@@ -130,16 +143,16 @@ libtalertesting_la_LIBADD = \
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
-.NOTPARALLEL:
check_PROGRAMS = \
- test_auditor_api_cs \
- test_auditor_api_rsa \
- test_auditor_api_version_rsa \
- test_auditor_api_version_cs \
+ test_auditor_api_version \
test_bank_api_with_fakebank \
test_bank_api_with_nexus \
test_exchange_api_cs \
test_exchange_api_rsa \
+ test_exchange_api_age_restriction_cs \
+ test_exchange_api_age_restriction_rsa \
+ test_exchange_api_conflicts_cs \
+ test_exchange_api_conflicts_rsa \
test_exchange_api_keys_cherry_picking_cs \
test_exchange_api_keys_cherry_picking_rsa \
test_exchange_api_revocation_cs \
@@ -160,6 +173,9 @@ if HAVE_TWISTER
test_bank_api_with_fakebank_twisted
endif
+# Removed for now...
+# test_auditor_api_cs
+# test_auditor_api_rsa
TESTS = \
@@ -176,7 +192,6 @@ test_auditor_api_cs_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -193,34 +208,19 @@ test_auditor_api_rsa_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
$(XLIB)
-test_auditor_api_version_cs_SOURCES = \
- test_auditor_api_version.c
-test_auditor_api_version_cs_LDADD = \
- libtalertesting.la \
- $(top_builddir)/src/lib/libtalerauditor.la \
- $(LIBGCRYPT_LIBS) \
- $(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
- -lgnunetcurl \
- -lgnunetutil \
- -ljansson \
- $(XLIB)
-
-test_auditor_api_version_rsa_SOURCES = \
+test_auditor_api_version_SOURCES = \
test_auditor_api_version.c
-test_auditor_api_version_rsa_LDADD = \
+test_auditor_api_version_LDADD = \
libtalertesting.la \
$(top_builddir)/src/lib/libtalerauditor.la \
$(LIBGCRYPT_LIBS) \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -230,7 +230,7 @@ test_bank_api_with_nexus_SOURCES = \
test_bank_api.c
test_bank_api_with_nexus_LDADD = \
libtalertesting.la \
- -ltalerexchange \
+ $(top_builddir)/src/lib/libtalerexchange.la \
-lgnunetutil \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(XLIB)
@@ -239,7 +239,7 @@ test_bank_api_with_fakebank_SOURCES = \
test_bank_api.c
test_bank_api_with_fakebank_LDADD = \
libtalertesting.la \
- -ltalerexchange \
+ $(top_builddir)/src/lib/libtalerexchange.la \
-lgnunetutil \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(XLIB)
@@ -255,7 +255,6 @@ test_exchange_api_cs_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -272,7 +271,70 @@ test_exchange_api_rsa_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
- -lgnunettesting \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
+
+test_exchange_api_age_restriction_cs_SOURCES = \
+ test_exchange_api_age_restriction.c
+test_exchange_api_age_restriction_cs_LDADD = \
+ libtalertesting.la \
+ $(top_builddir)/src/lib/libtalerexchange.la \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/bank-lib/libtalerfakebank.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/extensions/libtalerextensions.la \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
+
+test_exchange_api_age_restriction_rsa_SOURCES = \
+ test_exchange_api_age_restriction.c
+test_exchange_api_age_restriction_rsa_LDADD = \
+ libtalertesting.la \
+ $(top_builddir)/src/lib/libtalerexchange.la \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/bank-lib/libtalerfakebank.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/extensions/libtalerextensions.la \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
+
+test_exchange_api_conflicts_cs_SOURCES = \
+ test_exchange_api_conflicts.c
+test_exchange_api_conflicts_cs_LDADD = \
+ libtalertesting.la \
+ $(top_builddir)/src/lib/libtalerexchange.la \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/bank-lib/libtalerfakebank.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/extensions/libtalerextensions.la \
+ -lgnunetcurl \
+ -lgnunetutil \
+ -ljansson \
+ $(XLIB)
+
+test_exchange_api_conflicts_rsa_SOURCES = \
+ test_exchange_api_conflicts.c
+test_exchange_api_conflicts_rsa_LDADD = \
+ libtalertesting.la \
+ $(top_builddir)/src/lib/libtalerexchange.la \
+ $(LIBGCRYPT_LIBS) \
+ $(top_builddir)/src/bank-lib/libtalerfakebank.la \
+ $(top_builddir)/src/bank-lib/libtalerbank.la \
+ $(top_builddir)/src/json/libtalerjson.la \
+ $(top_builddir)/src/util/libtalerutil.la \
+ $(top_builddir)/src/extensions/libtalerextensions.la \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -289,7 +351,6 @@ test_exchange_p2p_cs_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -306,7 +367,6 @@ test_exchange_p2p_rsa_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/extensions/libtalerextensions.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -322,7 +382,6 @@ test_exchange_api_keys_cherry_picking_cs_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -337,7 +396,6 @@ test_exchange_api_keys_cherry_picking_rsa_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -353,7 +411,6 @@ test_exchange_api_revocation_cs_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -369,7 +426,6 @@ test_exchange_api_revocation_rsa_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -385,7 +441,6 @@ test_exchange_api_overlapping_keys_bug_cs_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -400,7 +455,6 @@ test_exchange_api_overlapping_keys_bug_rsa_LDADD = \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/bank-lib/libtalerbank.la \
- -lgnunettesting \
-lgnunetcurl \
-lgnunetutil \
-ljansson \
@@ -412,7 +466,6 @@ test_exchange_management_api_cs_LDADD = \
libtalertesting.la \
$(top_builddir)/src/lib/libtalerexchange.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetutil \
$(XLIB)
@@ -422,7 +475,6 @@ test_exchange_management_api_rsa_LDADD = \
libtalertesting.la \
$(top_builddir)/src/lib/libtalerexchange.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetutil \
$(XLIB)
@@ -471,7 +523,6 @@ test_exchange_api_twisted_cs_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetjson \
-lgnunetcurl \
-lgnunetutil \
@@ -489,7 +540,6 @@ test_exchange_api_twisted_rsa_LDADD = \
$(top_builddir)/src/bank-lib/libtalerbank.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
- -lgnunettesting \
-lgnunetjson \
-lgnunetcurl \
-lgnunetutil \
@@ -505,7 +555,6 @@ test_bank_api_with_fakebank_twisted_LDADD = \
$(top_builddir)/src/lib/libtalerexchange.la \
$(top_builddir)/src/json/libtalerjson.la \
libtalertwistertesting.la \
- -lgnunettesting \
-lgnunetjson \
-lgnunetcurl \
-lgnunetutil \
@@ -531,29 +580,38 @@ test_kyc_api_LDADD = \
# Distribution
EXTRA_DIST = \
+ $(bin_SCRIPTS) \
+ valgrind.h \
+ coins-cs.conf \
+ coins-rsa.conf \
test_auditor_api-cs.conf \
test_auditor_api-rsa.conf \
test_auditor_api_expire_reserve_now-cs.conf \
test_auditor_api_expire_reserve_now-rsa.conf \
+ test_bank_api.conf \
test_bank_api_fakebank.conf \
test_bank_api_fakebank_twisted.conf \
- test_exchange_api_home/.config/taler/account-2.json \
+ test_bank_api_nexus.conf \
+ test_exchange_api_home/taler/auditor/offline-keys/auditor.priv \
test_exchange_api_home/.local/share/taler/exchange-offline/master.priv \
- test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv \
- test_exchange_api_keys_cherry_picking_home/.config/taler/x-taler-bank.json \
- test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange-offline/master.priv \
- test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange/offline-keys/master.priv \
+ test_exchange_api_home/.local/share/taler/auditor/offline-keys/auditor.priv \
+ test_exchange_api.conf \
test_exchange_api-cs.conf \
test_exchange_api-rsa.conf \
+ test_exchange_api_age_restriction.conf \
+ test_exchange_api_age_restriction-cs.conf \
+ test_exchange_api_age_restriction-rsa.conf \
+ test_exchange_api_conflicts.conf \
+ test_exchange_api_conflicts-cs.conf \
+ test_exchange_api_conflicts-rsa.conf \
+ test_exchange_api-twisted.conf \
test_exchange_api_twisted-cs.conf \
test_exchange_api_twisted-rsa.conf \
+ test_exchange_api_keys_cherry_picking.conf \
test_exchange_api_keys_cherry_picking-cs.conf \
test_exchange_api_keys_cherry_picking-rsa.conf \
test_exchange_api_expire_reserve_now-cs.conf \
test_exchange_api_expire_reserve_now-rsa.conf \
- test_taler_exchange_httpd_home/.config/taler/account-1.json \
- test_taler_exchange_httpd_home/.local/share/taler/exchange-offline/master.priv \
- test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv \
test-taler-exchange-aggregator-postgres.conf \
test-taler-exchange-wirewatch-postgres.conf \
test_kyc_api.conf
diff --git a/src/testing/coins-cs.conf b/src/testing/coins-cs.conf
new file mode 100644
index 000000000..92163baac
--- /dev/null
+++ b/src/testing/coins-cs.conf
@@ -0,0 +1,118 @@
+
+# Sections starting with "coin_" specify which denominations
+# the exchange should support (and their respective fee structure)
+[coin_eur_ct_1]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_ct_10]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_1]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_5]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+[coin_eur_10]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = CS
+
+
+[coin_eur_ct_1_age_restricted]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+age_restricted = YES
+CIPHER = CS
+
+[coin_eur_ct_10_age_restricted]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+age_restricted = YES
+CIPHER = CS
+
+[coin_eur_1_age_restricted]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+age_restricted = YES
+CIPHER = CS
+
+[coin_eur_5_age_restricted]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+age_restricted = YES
+CIPHER = CS
+
+[coin_eur_10_age_restricted]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+age_restricted = YES
+CIPHER = CS
diff --git a/src/testing/coins-rsa.conf b/src/testing/coins-rsa.conf
new file mode 100644
index 000000000..7a21a343b
--- /dev/null
+++ b/src/testing/coins-rsa.conf
@@ -0,0 +1,128 @@
+# This file is in the public domain.
+
+# Sections starting with "coin_" specify which denominations
+# the exchange should support (and their respective fee structure)
+[coin_eur_ct_1]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 1024
+
+[coin_eur_ct_10]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 1024
+
+[coin_eur_1]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 1024
+
+[coin_eur_5]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 1024
+
+[coin_eur_10]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+CIPHER = RSA
+rsa_keysize = 1024
+
+[coin_eur_ct_1_age_restricted]
+value = EUR:0.01
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.00
+fee_deposit = EUR:0.00
+fee_refresh = EUR:0.01
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+age_restricted = YES
+CIPHER = RSA
+
+[coin_eur_ct_10_age_restricted]
+value = EUR:0.10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+age_restricted = YES
+CIPHER = RSA
+
+[coin_eur_1_age_restricted]
+value = EUR:1
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+age_restricted = YES
+CIPHER = RSA
+
+[coin_eur_5_age_restricted]
+value = EUR:5
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+age_restricted = YES
+CIPHER = RSA
+
+[coin_eur_10_age_restricted]
+value = EUR:10
+duration_withdraw = 7 days
+duration_spend = 2 years
+duration_legal = 3 years
+fee_withdraw = EUR:0.01
+fee_deposit = EUR:0.01
+fee_refresh = EUR:0.03
+fee_refund = EUR:0.01
+rsa_keysize = 1024
+age_restricted = YES
+CIPHER = RSA \ No newline at end of file
diff --git a/src/testing/taler-unified-setup.sh b/src/testing/taler-unified-setup.sh
new file mode 100755
index 000000000..d933cc819
--- /dev/null
+++ b/src/testing/taler-unified-setup.sh
@@ -0,0 +1,934 @@
+#!/bin/bash
+#
+# This file is part of TALER
+# Copyright (C) 2023, 2024 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or
+# (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with TALER; see the file COPYING. If not, see
+# <http://www.gnu.org/licenses/>
+#
+# Author: Christian Grothoff
+#
+# This script configures and launches various GNU Taler services.
+# Which ones depend on command-line options. Use "-h" to find out.
+# Prints "<<READY>>" on a separate line once all requested services
+# are running. Close STDIN (or input 'NEWLINE') to stop all started
+# services again.
+#
+# shellcheck disable=SC2317
+
+set -eu
+
+# These break TALER_HOME control via TALER_TEST_HOME...
+unset XDG_DATA_HOME
+unset XDG_CONFIG_HOME
+unset XDG_CACHE_HOME
+
+EXIT_STATUS=2
+
+# Exit, with status code "skip" (no 'real' failure)
+function exit_skip() {
+ echo " SKIP: " "$@" >&2
+ EXIT_STATUS=77
+ exit "$EXIT_STATUS"
+}
+
+# Exit, with error message (hard failure)
+function exit_fail() {
+ echo " FAIL: " "$@" >&2
+ EXIT_STATUS=1
+ exit "$EXIT_STATUS"
+}
+
+# Cleanup to run whenever we exit
+function cleanup()
+{
+ echo "Taler unified setup terminating at $STAGE!" >&2
+
+ for n in $(jobs -p)
+ do
+ kill "$n" 2> /dev/null || true
+ done
+ wait
+ rm -f libeufin-nexus.pid libeufin-sandbox.pid
+ exit "$EXIT_STATUS"
+}
+
+STAGE="boot"
+
+# Install cleanup handler (except for kill -9)
+trap cleanup EXIT
+
+WAIT_FOR_SIGNAL=0
+START_AUDITOR=0
+START_BACKUP=0
+START_EXCHANGE=0
+START_FAKEBANK=0
+START_DONAU=0
+START_CHALLENGER=0
+START_AGGREGATOR=0
+START_MERCHANT=0
+START_NEXUS=0
+START_BANK=0
+START_TRANSFER=0
+START_WIREWATCH=0
+START_DEPOSITCHECK=0
+START_MERCHANT_EXCHANGE=0
+START_MERCHANT_WIREWATCH=0
+USE_ACCOUNT="exchange-account-1"
+USE_VALGRIND=""
+WIRE_DOMAIN="x-taler-bank"
+CONF_ORIG="$HOME/.config/taler.conf"
+LOGLEVEL="DEBUG"
+DEFAULT_SLEEP="0.2"
+
+# Parse command-line options
+while getopts ':abc:d:DeEfghkL:mMnr:stu:vwWz' OPTION; do
+ case "$OPTION" in
+ a)
+ START_AUDITOR="1"
+ ;;
+ b)
+ START_BANK="1"
+ ;;
+ c)
+ CONF_ORIG="$OPTARG"
+ ;;
+ d)
+ WIRE_DOMAIN="$OPTARG"
+ ;;
+ D)
+ START_DONAU="1"
+ ;;
+ e)
+ START_EXCHANGE="1"
+ ;;
+ E)
+ START_MERCHANT_EXCHANGE="1"
+ ;;
+ f)
+ START_FAKEBANK="1"
+ ;;
+ h)
+ echo 'Supported options:'
+ echo ' -a -- start auditor'
+ echo ' -b -- start bank'
+ # shellcheck disable=SC2016
+ echo ' -c $CONF -- set configuration'
+ # shellcheck disable=SC2016
+ echo ' -d $METHOD -- use wire method (default: x-taler-bank)'
+ echo ' -D -- start donau'
+ echo ' -e -- start exchange'
+ echo ' -E -- start taler-merchant-exchange'
+ echo ' -f -- start fakebank'
+ echo ' -g -- start taler-exchange-aggregator'
+ echo ' -h -- print this help'
+ echo ' -k -- start challenger (KYC service)'
+ # shellcheck disable=SC2016
+ echo ' -L $LOGLEVEL -- set log level'
+ echo ' -m -- start taler-merchant'
+ echo ' -M -- start taler-merchant-depositcheck'
+ echo ' -n -- start nexus'
+ # shellcheck disable=SC2016
+ echo ' -r $MEX -- which exchange to use at the merchant (optional)'
+ echo ' -s -- start backup/sync'
+ echo ' -t -- start taler-exchange-transfer'
+ # shellcheck disable=SC2016
+ echo ' -u $SECTION -- exchange account to use'
+ echo ' -v -- use valgrind'
+ echo ' -w -- start taler-exchange-wirewatch'
+ echo ' -W -- wait for signal'
+ echo ' -z -- start taler-merchant-wirewatch'
+ exit 0
+ ;;
+ g)
+ START_AGGREGATOR="1"
+ ;;
+ k)
+ START_CHALLENGER="1"
+ ;;
+ L)
+ LOGLEVEL="$OPTARG"
+ ;;
+ m)
+ START_MERCHANT="1"
+ ;;
+ M)
+ START_DEPOSITCHECK="1"
+ ;;
+ n)
+ START_NEXUS="1"
+ ;;
+ r)
+ USE_MERCHANT_EXCHANGE="$OPTARG"
+ ;;
+ s)
+ START_BACKUP="1"
+ ;;
+ t)
+ START_TRANSFER="1"
+ ;;
+ u)
+ USE_ACCOUNT="$OPTARG"
+ ;;
+ v)
+ USE_VALGRIND="valgrind --leak-check=yes"
+ DEFAULT_SLEEP="2"
+ ;;
+ w)
+ START_WIREWATCH="1"
+ ;;
+ W)
+ WAIT_FOR_SIGNAL="1"
+ ;;
+ z)
+ START_MERCHANT_WIREWATCH="1"
+ ;;
+ ?)
+ exit_fail "Unrecognized command line option"
+ ;;
+ esac
+done
+
+STAGE="init"
+
+echo "Starting with configuration file at: $CONF_ORIG"
+CONF="$CONF_ORIG.edited"
+cp "${CONF_ORIG}" "${CONF}"
+
+STAGE="checks"
+
+echo -n "Testing for jq"
+jq -h > /dev/null || exit_skip " jq required"
+echo " FOUND"
+
+echo -n "Testing for wget"
+wget --help > /dev/null || exit_skip " wget required"
+echo " FOUND"
+
+if [ "1" = "$START_EXCHANGE" ]
+then
+ echo -n "Testing for Taler exchange"
+ taler-exchange-httpd -h > /dev/null || exit_skip " taler-exchange-httpd required"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_DONAU" ]
+then
+ echo -n "Testing for Donau"
+ donau-httpd -h > /dev/null || exit_skip " donau-httpd required"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_MERCHANT" ]
+then
+ echo -n "Testing for Taler merchant"
+ taler-merchant-httpd -h > /dev/null || exit_skip " taler-merchant-httpd required"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_CHALLENGER" ]
+then
+ echo -n "Testing for Taler challenger"
+ challenger-httpd -h > /dev/null || exit_skip " challenger-httpd required"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_BACKUP" ]
+then
+ echo -n "Testing for sync-httpd"
+ sync-httpd -h > /dev/null || exit_skip " sync-httpd required"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_NEXUS" ]
+then
+ echo -n "Testing for libeufin-cli"
+ libeufin-cli --help >/dev/null </dev/null || exit_skip " MISSING"
+ echo " FOUND"
+fi
+
+if [ "1" = "$START_BANK" ]
+then
+ echo -n "Testing for libeufin-bank"
+ libeufin-bank --help >/dev/null </dev/null || exit_skip " MISSING"
+ echo " FOUND"
+fi
+
+STAGE="config"
+
+
+EXCHANGE_URL=$(taler-config -c "$CONF" -s "EXCHANGE" -o "BASE_URL")
+CURRENCY=$(taler-config -c "$CONF" -s "TALER" -o "CURRENCY")
+
+echo "Setting up for $CURRENCY at $EXCHANGE_URL"
+
+register_bank_account() {
+ wget \
+ --http-user="$AUSER" \
+ --http-password="$APASS" \
+ --method=DELETE \
+ -o /dev/null \
+ -O /dev/null \
+ -a wget-delete-account.log \
+ "http://localhost:${BANK_PORT}/accounts/$1" \
+ || true # deletion may fail, that's OK!
+ if [ "$1" = "exchange" ] || [ "$1" = "Exchange" ]
+ then
+ IS_EXCHANGE="true"
+ else
+ IS_EXCHANGE="false"
+ fi
+ MAYBE_IBAN="${4:-}"
+ if [ -n "$MAYBE_IBAN" ]
+ then
+ # shellcheck disable=SC2001
+ ENAME=$(echo "$3" | sed -e "s/ /+/g")
+ # Note: this assumes that $3 has no spaces. Should probably escape in the future..
+ PAYTO="payto://iban/SANDBOXX/${MAYBE_IBAN}?receiver-name=$ENAME"
+ BODY='{"username":"'"$1"'","password":"'"$2"'","is_taler_exchange":'"$IS_EXCHANGE"',"name":"'"$3"'","payto_uri":"'"$PAYTO"'"}'
+ else
+ BODY='{"username":"'"$1"'","password":"'"$2"'","is_taler_exchange":'"$IS_EXCHANGE"',"name":"'"$3"'"}'
+ fi
+ wget \
+ --http-user="$AUSER" \
+ --http-password="$APASS" \
+ --method=POST \
+ --header='Content-type: application/json' \
+ --body-data="${BODY}" \
+ -o /dev/null \
+ -O /dev/null \
+ -a wget-register-account.log \
+ "http://localhost:${BANK_PORT}/accounts"
+}
+
+register_fakebank_account() {
+ if [ "$1" = "exchange" ] || [ "$1" = "Exchange" ]
+ then
+ IS_EXCHANGE="true"
+ else
+ IS_EXCHANGE="false"
+ fi
+ BODY='{"username":"'"$1"'","password":"'"$2"'","name":"'"$1"'","is_taler_exchange":'"$IS_EXCHANGE"'}'
+ wget \
+ --post-data="$BODY" \
+ --header='Content-type: application/json' \
+ --tries=3 \
+ --waitretry=1 \
+ --timeout=30 \
+ "http://localhost:$BANK_PORT/accounts" \
+ -a wget-register-account.log \
+ -o /dev/null \
+ -O /dev/null \
+ >/dev/null
+}
+
+
+if [[ "1" = "$START_BANK" ]]
+then
+ BANK_PORT=$(taler-config -c "$CONF" -s "libeufin-bank" -o "PORT")
+ BANK_URL="http://localhost:${BANK_PORT}/"
+fi
+
+if [[ "1" = "$START_FAKEBANK" ]]
+then
+ BANK_PORT=$(taler-config -c "$CONF" -s "BANK" -o "HTTP_PORT")
+ BANK_URL="http://localhost:${BANK_PORT}/"
+fi
+
+STAGE="bank"
+
+if [ "1" = "$START_BANK" ]
+then
+ echo -n "Setting up bank database ... "
+ libeufin-bank dbinit \
+ -r \
+ -c "$CONF" \
+ &> libeufin-bank-reset.log
+ echo "DONE"
+ echo -n "Launching bank ... "
+ libeufin-bank serve \
+ -c "$CONF" \
+ > libeufin-bank-stdout.log \
+ 2> libeufin-bank-stderr.log &
+ echo $! > libeufin-bank.pid
+ echo "DONE"
+ echo -n "Waiting for Bank ..."
+ OK="0"
+ for n in $(seq 1 100); do
+ echo -n "."
+ sleep "$DEFAULT_SLEEP"
+ wget --timeout=1 \
+ --tries=3 \
+ --waitretry=0 \
+ -a wget-bank-check.log \
+ -o /dev/null \
+ -O /dev/null \
+ "${BANK_URL}config" || continue
+ OK="1"
+ break
+ done
+ if [ "1" != "$OK" ]
+ then
+ exit_skip "Failed to launch services (bank)"
+ fi
+ echo "OK"
+ echo -n "Set admin password..."
+ AUSER="admin"
+ APASS="secret"
+ libeufin-bank \
+ passwd \
+ -c "$CONF" \
+ "$AUSER" "$APASS" \
+ &> libeufin-bank-passwd.log
+ libeufin-bank \
+ edit-account \
+ -c "$CONF" \
+ --debit_threshold="$CURRENCY:1000000" \
+ "$AUSER" \
+ &> libeufin-bank-debit-threshold.log
+ echo " OK"
+fi
+
+if [ "1" = "$START_NEXUS" ]
+then
+ echo "Nexus currently not supported ..."
+fi
+
+if [ "1" = "$START_FAKEBANK" ]
+then
+ echo -n "Setting up fakebank ..."
+ $USE_VALGRIND taler-fakebank-run \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ -n 4 \
+ 2> taler-fakebank-run.log &
+ echo " OK"
+fi
+
+if [[ "1" = "$START_NEXUS" || "1" = "$START_FAKEBANK" ]]
+then
+ echo -n "Waiting for the bank"
+ # Wait for bank to be available (usually the slowest)
+ OK="0"
+ for n in $(seq 1 300)
+ do
+ echo -n "."
+ sleep "$DEFAULT_SLEEP"
+ # bank
+ wget --tries=1 \
+ --waitretry=0 \
+ --timeout=1 \
+ --user admin \
+ --password secret \
+ -a wget-bank-check.log \
+ -o /dev/null \
+ -O /dev/null \
+ "http://localhost:${BANK_PORT}/" || continue
+ OK="1"
+ break
+ done
+ if [ "1" != "$OK" ]
+ then
+ exit_skip "Failed to launch services (bank)"
+ fi
+ echo " OK"
+fi
+
+STAGE="accounts"
+
+if [ "1" = "$START_FAKEBANK" ]
+then
+ echo -n "Register Fakebank users ..."
+ register_fakebank_account fortytwo x
+ register_fakebank_account fortythree x
+ register_fakebank_account exchange x
+ register_fakebank_account tor x
+ register_fakebank_account gnunet x
+ register_fakebank_account tutorial x
+ register_fakebank_account survey x
+ echo " DONE"
+fi
+
+if [ "1" = "$START_BANK" ]
+then
+ echo -n "Register bank users ..."
+ # The specified IBAN and name must match the ones hard-coded into
+ # the C helper for the add-incoming call. Without this value,
+ # libeufin-bank won't find the target account to debit along a /add-incoming
+ # call.
+ register_bank_account fortytwo x "User42" FR7630006000011234567890189
+ register_bank_account fortythree x "Forty Three"
+ register_bank_account exchange x "Exchange Company" DE989651
+ register_bank_account tor x "Tor Project"
+ register_bank_account gnunet x "GNUnet"
+ register_bank_account tutorial x "Tutorial"
+ register_bank_account survey x "Survey"
+ echo " DONE"
+fi
+
+STAGE="exchange"
+
+if [ "1" = "$START_EXCHANGE" ]
+then
+ echo -n "Starting exchange ..."
+ EXCHANGE_PORT=$(taler-config -c "$CONF" -s EXCHANGE -o PORT)
+ SERVE=$(taler-config -c "$CONF" -s EXCHANGE -o SERVE)
+ if [ "${SERVE}" = "unix" ]
+ then
+ EXCHANGE_URL=$(taler-config -c "$CONF" -s EXCHANGE -o BASE_URL)
+ else
+ EXCHANGE_URL="http://localhost:${EXCHANGE_PORT}/"
+ fi
+ MASTER_PRIV_FILE=$(taler-config -f -c "${CONF}" -s "EXCHANGE-OFFLINE" -o "MASTER_PRIV_FILE")
+ MASTER_PRIV_DIR=$(dirname "$MASTER_PRIV_FILE")
+ mkdir -p "${MASTER_PRIV_DIR}"
+ if [ ! -e "$MASTER_PRIV_FILE" ]
+ then
+ gnunet-ecc -g1 "$MASTER_PRIV_FILE" > /dev/null 2> /dev/null
+ echo -n "."
+ fi
+ MASTER_PUB=$(gnunet-ecc -p "${MASTER_PRIV_FILE}")
+ MPUB=$(taler-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY)
+ if [ "$MPUB" != "$MASTER_PUB" ]
+ then
+ echo -n " patching master_pub ($MASTER_PUB)..."
+ taler-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY -V "$MASTER_PUB"
+ fi
+ taler-exchange-dbinit -c "$CONF" --reset
+ $USE_VALGRIND taler-exchange-secmod-eddsa \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> taler-exchange-secmod-eddsa.log &
+ $USE_VALGRIND taler-exchange-secmod-rsa \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> taler-exchange-secmod-rsa.log &
+ $USE_VALGRIND taler-exchange-secmod-cs \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> taler-exchange-secmod-cs.log &
+ $USE_VALGRIND taler-exchange-httpd \
+ -c "$CONF" \
+ -L "$LOGLEVEL" 2> taler-exchange-httpd.log &
+ echo " DONE"
+fi
+
+STAGE="donau"
+
+if [ "1" = "$START_DONAU" ]
+then
+ echo -n "Starting Donau ..."
+ DONAU_PORT=$(donau-config -c "$CONF" -s DONAU -o PORT)
+ SERVE=$(donau-config -c "$CONF" -s DONAU -o SERVE)
+ if [ "${SERVE}" = "unix" ]
+ then
+ DONAU_URL=$(donau-config -c "$CONF" -s DONAU -o BASE_URL)
+ else
+ DONAU_URL="http://localhost:${DONAU_PORT}/"
+ fi
+ donau-dbinit -c "$CONF" --reset
+ $USE_VALGRIND taler-exchange-secmod-eddsa -c "$CONF" -L "$LOGLEVEL" -s donau 2> donau-secmod-eddsa.log &
+ $USE_VALGRIND taler-exchange-secmod-rsa -c "$CONF" -L "$LOGLEVEL" -s donau 2> donau-secmod-rsa.log &
+ $USE_VALGRIND taler-exchange-secmod-cs -c "$CONF" -L "$LOGLEVEL" -s donau 2> donau-secmod-cs.log &
+ $USE_VALGRIND donau-httpd -c "$CONF" -L "$LOGLEVEL" 2> donau-httpd.log &
+ echo " DONE"
+fi
+
+STAGE="wirewatch"
+
+if [ "1" = "$START_WIREWATCH" ]
+then
+ echo -n "Starting wirewatch ..."
+ $USE_VALGRIND taler-exchange-wirewatch \
+ --account="$USE_ACCOUNT" \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ --longpoll-timeout="60 s" \
+ 2> taler-exchange-wirewatch.log &
+ echo " DONE"
+fi
+
+STAGE="aggregator"
+
+if [ "1" = "$START_AGGREGATOR" ]
+then
+ echo -n "Starting aggregator ..."
+ $USE_VALGRIND taler-exchange-aggregator \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> taler-exchange-aggregator.log &
+ echo " DONE"
+fi
+
+STAGE="transfer"
+
+if [ "1" = "$START_TRANSFER" ]
+then
+ echo -n "Starting transfer ..."
+ $USE_VALGRIND taler-exchange-transfer \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> taler-exchange-transfer.log &
+ echo " DONE"
+fi
+
+STAGE="merchant"
+
+if [ "1" = "$START_MERCHANT" ]
+then
+ echo -n "Starting merchant ..."
+ if [ -n "${USE_MERCHANT_EXCHANGE+x}" ]
+ then
+ MEPUB=$(taler-config -c "$CONF" -s "${USE_MERCHANT_EXCHANGE}" -o MASTER_KEY)
+ MXPUB=${MASTER_PUB:-$(taler-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY)}
+ if [ "$MEPUB" != "$MXPUB" ]
+ then
+ echo -n " patching master_pub ($MXPUB)..."
+ taler-config -c "$CONF" -s "${USE_MERCHANT_EXCHANGE}" -o MASTER_KEY -V "$MXPUB"
+ fi
+ fi
+ MERCHANT_TYPE=$(taler-config -c "$CONF" -s MERCHANT -o SERVE)
+ if [ "unix" = "$MERCHANT_TYPE" ]
+ then
+ MERCHANT_URL="$(taler-config -c "$CONF" -s MERCHANT -o BASE_URL)"
+ else
+ MERCHANT_PORT="$(taler-config -c "$CONF" -s MERCHANT -o PORT)"
+ MERCHANT_URL="http://localhost:${MERCHANT_PORT}/"
+ fi
+ taler-merchant-dbinit \
+ -c "$CONF" \
+ --reset &> taler-merchant-dbinit.log
+ $USE_VALGRIND taler-merchant-httpd \
+ -c "$CONF" \
+ -L "$LOGLEVEL" 2> taler-merchant-httpd.log &
+ $USE_VALGRIND taler-merchant-webhook \
+ -c "$CONF" \
+ -L "$LOGLEVEL" 2> taler-merchant-webhook.log &
+ echo " DONE"
+ if [ "1" = "$START_MERCHANT_WIREWATCH" ]
+ then
+ echo -n "Starting taler-merchant-wirewatch ..."
+ $USE_VALGRIND taler-merchant-wirewatch \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ --persist \
+ 2> taler-merchant-wirewatch.log &
+ echo " DONE"
+ fi
+ if [ "1" = "$START_MERCHANT_EXCHANGE" ]
+ then
+ echo -n "Starting taler-merchant-exchange ..."
+ $USE_VALGRIND taler-merchant-exchange \
+ -c "$CONF" \
+ -L "$LOGLEVEL" 2> taler-merchant-exchange.log &
+ echo " DONE"
+ fi
+ if [ "1" = "$START_DEPOSITCHECK" ]
+ then
+ echo -n "Starting taler-merchant-depositcheck ..."
+ $USE_VALGRIND taler-merchant-depositcheck \
+ -c "$CONF" \
+ -L "$LOGLEVEL" 2> taler-merchant-depositcheck.log &
+ echo " DONE"
+ fi
+fi
+
+STAGE="sync"
+
+if [ "1" = "$START_BACKUP" ]
+then
+ echo -n "Starting sync ..."
+ SYNC_PORT=$(taler-config -c "$CONF" -s SYNC -o PORT)
+ SERVE=$(taler-config -c "$CONF" -s SYNC -o SERVE)
+ if [ "${SERVE}" = "unix" ]
+ then
+ SYNC_URL=$(taler-config -c "$CONF" -s SYNC -o BASE_URL)
+ else
+ SYNC_URL="http://localhost:${SYNC_PORT}/"
+ fi
+ sync-dbinit -c "$CONF" --reset
+ $USE_VALGRIND sync-httpd \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> sync-httpd.log &
+ echo " DONE"
+fi
+
+STAGE="challenger"
+
+if [ "1" = "$START_CHALLENGER" ]
+then
+ echo -n "Starting challenger ..."
+ CHALLENGER_PORT=$(challenger-config -c "$CONF" -s CHALLENGER -o PORT)
+ SERVE=$(taler-config -c "$CONF" -s CHALLENGER -o SERVE)
+ if [ "${SERVE}" = "unix" ]
+ then
+ CHALLENGER_URL=$(taler-config -c "$CONF" -s CHALLENGER -o BASE_URL)
+ else
+ CHALLENGER_URL="http://localhost:${CHALLENGER_PORT}/"
+ fi
+ challenger-dbinit \
+ -c "$CONF" \
+ --reset
+ $USE_VALGRIND challenger-httpd \
+ -c "$CONF" \
+ -L "$LOGLEVEL" \
+ 2> challenger-httpd.log &
+ echo " DONE"
+ for SECTION in $(taler-config -c "$CONF" -S | grep kyc-provider)
+ do
+ LOGIC=$(taler-config -c "$CONF" -s "$SECTION" -o "LOGIC")
+ if [ "${LOGIC}" = "oauth2" ]
+ then
+ INFO=$(taler-config -c "$CONF" -s "$SECTION" -o "KYC_OAUTH2_INFO_URL")
+ if [ "${CHALLENGER_URL}info" = "$INFO" ]
+ then
+ echo -n "Enabling Challenger client for $SECTION"
+ CLIENT_SECRET=$(taler-config -c "$CONF" -s "$SECTION" -o "KYC_OAUTH2_CLIENT_SECRET")
+ RFC_8959_PREFIX="secret-token:"
+ if ! echo "${CLIENT_SECRET}" | grep ^${RFC_8959_PREFIX} > /dev/null
+ then
+ exit_fail "Client secret does not begin with '${RFC_8959_PREFIX}'"
+ fi
+ REDIRECT_URI="${EXCHANGE_URL}kyc-proof/kyc-provider-example-challeger"
+ CLIENT_ID=$(challenger-admin --add="${CLIENT_SECRET}" --quiet "${REDIRECT_URI}")
+ taler-config -c "$CONF" -s "$SECTION" -o KYC_OAUTH2_CLIENT_ID -V "$CLIENT_ID"
+ echo " DONE"
+ fi
+ fi
+ done
+fi
+
+STAGE="auditor"
+
+if [ "1" = "$START_AUDITOR" ]
+then
+ echo -n "Starting auditor ..."
+ AUDITOR_URL=$(taler-config -c "$CONF" -s AUDITOR -o BASE_URL)
+ AUDITOR_PRIV_FILE=$(taler-config -f -c "$CONF" -s AUDITOR -o AUDITOR_PRIV_FILE)
+ AUDITOR_PRIV_DIR=$(dirname "$AUDITOR_PRIV_FILE")
+ mkdir -p "$AUDITOR_PRIV_DIR"
+ if [ ! -e "$AUDITOR_PRIV_FILE" ]
+ then
+ gnunet-ecc -g1 "$AUDITOR_PRIV_FILE" > /dev/null 2> /dev/null
+ echo -n "."
+ fi
+ AUDITOR_PUB=$(gnunet-ecc -p "${AUDITOR_PRIV_FILE}")
+ MAPUB=${MASTER_PUB:-$(taler-config -c "$CONF" -s exchange -o MASTER_PUBLIC_KEY)}
+ taler-auditor-dbinit \
+ -c "$CONF" \
+ --reset
+ $USE_VALGRIND taler-auditor-httpd \
+ -L "$LOGLEVEL" \
+ -c "$CONF" 2> taler-auditor-httpd.log &
+# $USE_VALGRIND taler-helper-auditor-deposits \
+# -L "$LOGLEVEL" \
+# -c "$CONF" 2> taler-helper-auditor.log &
+ echo " DONE"
+fi
+
+STAGE="wait"
+
+echo -n "Waiting for Taler services ..."
+# Wait for all other taler services to be available
+E_DONE=0
+M_DONE=0
+S_DONE=0
+K_DONE=0
+A_DONE=0
+for n in $(seq 1 20)
+do
+ sleep "$DEFAULT_SLEEP"
+ OK="0"
+ if [ "0" = "$E_DONE" ] && [ "1" = "$START_EXCHANGE" ]
+ then
+ echo -n "E"
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ "${EXCHANGE_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null || continue
+ E_DONE=1
+ fi
+ if [ "0" = "$M_DONE" ] && [ "1" = "$START_MERCHANT" ]
+ then
+ echo -n "M"
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ "${MERCHANT_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null || continue
+ M_DONE=1
+ fi
+ if [ "0" = "$S_DONE" ] && [ "1" = "$START_BACKUP" ]
+ then
+ echo -n "S"
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ "${SYNC_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null || continue
+ S_DONE=1
+ fi
+ if [ "0" = "$K_DONE" ] && [ "1" = "$START_CHALLENGER" ]
+ then
+ echo -n "K"
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ "${CHALLENGER_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null || continue
+ K_DONE=1
+ fi
+ if [ "0" = "$A_DONE" ] && [ "1" = "$START_AUDITOR" ]
+ then
+ echo -n "A"
+ wget \
+ --tries=1 \
+ --timeout=1 \
+ "${AUDITOR_URL}config" \
+ -o /dev/null \
+ -O /dev/null >/dev/null || continue
+ A_DONE=1
+ fi
+ OK="1"
+ break
+done
+if [ 1 != "$OK" ]
+then
+ exit_skip "Failed to launch (some) Taler services"
+fi
+echo " OK"
+
+if [ "1" = "$START_EXCHANGE" ]
+then
+ echo -n "Wait for exchange /management/keys to be ready "
+ OK="0"
+ LAST_RESPONSE=$(mktemp tmp-last-response.XXXXXXXX)
+ for n in $(seq 1 10)
+ do
+ echo -n "."
+ sleep "$DEFAULT_SLEEP"
+ # exchange
+ wget \
+ --tries=3 \
+ --waitretry=0 \
+ --timeout=30 \
+ "${EXCHANGE_URL}management/keys"\
+ -o /dev/null \
+ -O "$LAST_RESPONSE" \
+ >/dev/null || continue
+ OK="1"
+ break;
+ done
+ if [ "1" != "$OK" ]
+ then
+ cat "$LAST_RESPONSE"
+ exit_fail "Failed to setup exchange keys, check secmod logs"
+ fi
+ rm "$LAST_RESPONSE"
+ echo " OK"
+
+ echo -n "Setting up exchange keys ..."
+ taler-exchange-offline -c "$CONF" \
+ download \
+ sign \
+ wire-fee now "$WIRE_DOMAIN" "$CURRENCY:0.01" "$CURRENCY:0.01" \
+ global-fee now "$CURRENCY:0.01" "$CURRENCY:0.01" "$CURRENCY:0.0" 1h 1year 5 \
+ upload &> taler-exchange-offline.log
+ echo "OK"
+ ENABLED=$(taler-config -c "$CONF" -s "$USE_ACCOUNT" -o "ENABLE_CREDIT")
+ if [ "YES" = "$ENABLED" ]
+ then
+ echo -n "Configuring bank account $USE_ACCOUNT ..."
+ EXCHANGE_PAYTO_URI=$(taler-config -c "$CONF" -s "$USE_ACCOUNT" -o "PAYTO_URI")
+ taler-exchange-offline -c "$CONF" \
+ enable-account "$EXCHANGE_PAYTO_URI" \
+ upload &> "taler-exchange-offline-account.log"
+ echo " OK"
+ else
+ echo "WARNING: Account ${USE_ACCOUNT} not enabled (set to: '$ENABLED')"
+ fi
+ if [ "1" = "$START_AUDITOR" ]
+ then
+ echo -n "Enabling auditor ..."
+ taler-exchange-offline -c "$CONF" \
+ enable-auditor "$AUDITOR_PUB" "$AUDITOR_URL" "$CURRENCY Auditor" \
+ upload &> taler-exchange-offline-auditor.log
+ echo "OK"
+ fi
+
+ echo -n "Checking /keys "
+ OK="0"
+ LAST_RESPONSE=$(mktemp tmp-last-response.XXXXXXXX)
+ for n in $(seq 1 10)
+ do
+ echo -n "."
+ sleep "$DEFAULT_SLEEP"
+ wget \
+ --tries=1 \
+ --timeout=5 \
+ "${EXCHANGE_URL}keys" \
+ -a wget-keys-check.log \
+ -o /dev/null \
+ -O "$LAST_RESPONSE" \
+ >/dev/null || continue
+ OK="1"
+ break
+ done
+ if [ "1" != "$OK" ]
+ then
+ cat "$LAST_RESPONSE"
+ exit_fail " Failed to fetch ${EXCHANGE_URL}keys"
+ fi
+ rm "$LAST_RESPONSE"
+ echo " OK"
+fi
+
+if [ "1" = "$START_AUDITOR" ]
+then
+ echo -n "Setting up auditor signatures ..."
+ timeout 15 taler-auditor-offline -c "$CONF" \
+ download \
+ sign \
+ upload &> taler-auditor-offline.log
+ echo " OK"
+fi
+
+STAGE="ready"
+
+# Signal caller that we are ready.
+echo "<<READY>>"
+
+if [ "1" = "$WAIT_FOR_SIGNAL" ]
+then
+ while true
+ do
+ sleep 0.1
+ done
+else
+ # Wait until caller stops us.
+ # shellcheck disable=SC2162
+ read
+fi
+
+STAGE="exiting"
+
+echo "Taler unified setup terminating!" >&2
+EXIT_STATUS=0
+exit "$EXIT_STATUS"
diff --git a/src/testing/test-taler-exchange-aggregator-postgres.conf b/src/testing/test-taler-exchange-aggregator-postgres.conf
index d3c6c4f2f..8c3ee4ba5 100644
--- a/src/testing/test-taler-exchange-aggregator-postgres.conf
+++ b/src/testing/test-taler-exchange-aggregator-postgres.conf
@@ -1,84 +1,59 @@
+# This file is in the public domain.
+
[PATHS]
# Persistent data storage for the testcase
TALER_TEST_HOME = test_taler_exchange_httpd_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
[taler-exchange-secmod-rsa]
# Reduce from 1 year to speed up test
LOOKAHEAD_SIGN = 24 days
[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
DURATION = 14 days
[taler]
-# Currency supported by the exchange (can only be one)
CURRENCY = EUR
CURRENCY_ROUND_UNIT = EUR:0.01
[exchange]
-# The DB plugin to use
+AML_THRESHOLD = EUR:1000000
DB = postgres
-
-# HTTP port the exchange listens to
PORT = 8081
-
-# Master public key used to sign the exchange's various keys
MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# Expected base URL of the exchange. Used in wire transfers for
-# the tracking API.
BASE_URL = "http://localhost:8081/"
[auditor]
BASE_URL = "http://auditor.example.com/"
+PORT = 8083
[auditordb-postgres]
CONFIG = "postgres:///talercheck"
[exchangedb]
-# After how long do we close idle reserves? The exchange
-# and the auditor must agree on this value. We currently
-# expect it to be globally defined for the whole system,
-# as there is no way for wallets to query this value. Thus,
-# it is only configurable for testing, and should be treated
-# as constant in production.
IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
+LEGAL_RESERVE_EXPIRATION_TIME = 7 years
[exchangedb-postgres]
-
-#The connection string the plugin has to use for connecting to the database
CONFIG = postgres:///talercheck
-[exchangedb]
-
-# After how long do we close idle reserves? The exchange
-# and the auditor must agree on this value. We currently
-# expect it to be globally defined for the whole system,
-# as there is no way for wallets to query this value. Thus,
-# it is only configurable for testing, and should be treated
-# as constant in production.
-IDLE_RESERVE_EXPIRATION_TIME = 4 weeks
-
-# After how long do we forget about reserves? Should be above
-# the legal expiration timeframe of withdrawn coins.
-LEGAL_RESERVE_EXPIRATION_TIME = 7 years
-
[exchange-account-1]
-
# What is the account URL?
PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
ENABLE_DEBIT = YES
ENABLE_CREDIT = YES
[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
WIRE_GATEWAY_AUTH_METHOD = basic
USERNAME = Exchange
PASSWORD = x
+[admin-accountcredentials-1]
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
[bank]
HTTP_PORT = 8082
diff --git a/src/testing/test-taler-exchange-wirewatch-postgres.conf b/src/testing/test-taler-exchange-wirewatch-postgres.conf
index ae8ba2329..4f13077ac 100644
--- a/src/testing/test-taler-exchange-wirewatch-postgres.conf
+++ b/src/testing/test-taler-exchange-wirewatch-postgres.conf
@@ -1,60 +1,41 @@
+# This file is in the public domain.
+
[PATHS]
# Persistent data storage for the testcase
TALER_TEST_HOME = test_taler_exchange_httpd_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
LOOKAHEAD_SIGN = 24 days
[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
DURATION = 14 days
[taler]
-# Currency supported by the exchange (can only be one)
CURRENCY = EUR
CURRENCY_ROUND_UNIT = EUR:0.01
[exchange]
-# The DB plugin to use
+AML_THRESHOLD = EUR:1000000
DB = postgres
-
-# HTTP port the exchange listens to
PORT = 8081
-
-# Master public key used to sign the exchange's various keys
MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# Expected base URL of the exchange.
BASE_URL = "http://localhost:8081/"
[exchangedb]
-# After how long do we close idle reserves? The exchange
-# and the auditor must agree on this value. We currently
-# expect it to be globally defined for the whole system,
-# as there is no way for wallets to query this value. Thus,
-# it is only configurable for testing, and should be treated
-# as constant in production.
-#
# This is THE test that requires a short reserve expiration time!
IDLE_RESERVE_EXPIRATION_TIME = 4 s
[exchangedb-postgres]
-#The connection string the plugin has to use for connecting to the database
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
CONFIG = "postgres:///talercheck"
[auditor]
BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
PORT = 8083
+[auditordb-postgres]
+CONFIG = "postgres:///talercheck"
+
[exchange-account-1]
# What is the account URL?
PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
@@ -62,7 +43,13 @@ ENABLE_DEBIT = YES
ENABLE_CREDIT = YES
[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
WIRE_GATEWAY_AUTH_METHOD = basic
USERNAME = Exchange
PASSWORD = x
@@ -70,6 +57,16 @@ PASSWORD = x
[bank]
HTTP_PORT = 8082
+[libeufin-bank]
+CURRENCY = EUR
+DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200
+DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000
+REGISTRATION_BONUS_ENABLED = yes
+REGISTRATION_BONUS = EUR:100
+SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/
+SERVE = tcp
+PORT = 8082
+
# Need at least one coin, otherwise Exchange
# refuses to start.
[coin_eur_ct_1]
diff --git a/src/testing/test_auditor_api-cs.conf b/src/testing/test_auditor_api-cs.conf
index cfd1fa6cc..b80696fb2 100644
--- a/src/testing/test_auditor_api-cs.conf
+++ b/src/testing/test_auditor_api-cs.conf
@@ -1,140 +1,4 @@
-
# This file is in the public domain.
#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-[taler-exchange-secmod-cs]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-PUBLIC_KEY = XNYZPJJ6YPSQ4C6QPW120ACG9B5E5GBTTSYWXDMDB6G4X74TDBPG
-TINY_AMOUNT = EUR:0.01
-
-[exchange]
-
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Sections starting with "exchange-account-" configure the bank accounts
-# of the exchange. The "URL" specifies the account in
-# payto://-format.
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/42/"
-
-[bank]
-HTTP_PORT = 8082
-
-# ENABLE_CREDIT = YES
-
-[exchange-account-2]
-# What is the bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-# Authentication information for basic authentication
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
-WIRE_GATEWAY_AUTH_METHOD = "basic"
-USERNAME = user
-PASSWORD = pass
-
-
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
+@INLINE@ coins-cs.conf
+@INLINE@ test_exchange_api.conf
diff --git a/src/testing/test_auditor_api-rsa.conf b/src/testing/test_auditor_api-rsa.conf
index 577d9057a..671e81108 100644
--- a/src/testing/test_auditor_api-rsa.conf
+++ b/src/testing/test_auditor_api-rsa.conf
@@ -1,146 +1,4 @@
-
# This file is in the public domain.
#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-PUBLIC_KEY = XNYZPJJ6YPSQ4C6QPW120ACG9B5E5GBTTSYWXDMDB6G4X74TDBPG
-
-TINY_AMOUNT = EUR:0.01
-
-[exchange]
-
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Sections starting with "exchange-account-" configure the bank accounts
-# of the exchange. The "URL" specifies the account in
-# payto://-format.
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/42/"
-
-[bank]
-HTTP_PORT = 8082
-
-# ENABLE_CREDIT = YES
-
-[exchange-account-2]
-# What is the bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-# Authentication information for basic authentication
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
-WIRE_GATEWAY_AUTH_METHOD = "basic"
-USERNAME = user
-PASSWORD = pass
-
-
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
+@INLINE@ coins-rsa.conf
+@INLINE@ test_exchange_api.conf
diff --git a/src/testing/test_auditor_api.c b/src/testing/test_auditor_api.c
index 305d31a09..3810c601e 100644
--- a/src/testing/test_auditor_api.c
+++ b/src/testing/test_auditor_api.c
@@ -45,14 +45,9 @@ static char *config_file;
static char *config_file_expire_reserve_now;
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
+static struct TALER_TESTING_Credentials cred;
/**
* Execute the taler-exchange-wirewatch command with
@@ -61,7 +56,7 @@ static struct TALER_TESTING_BankConfiguration bc;
* @param label label to use for the command.
*/
#define CMD_EXEC_WIREWATCH(label) \
- TALER_TESTING_cmd_exec_wirewatch (label, config_file)
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, "exchange-account-2")
/**
* Execute the taler-exchange-aggregator, closer and transfer commands with
@@ -83,8 +78,8 @@ static struct TALER_TESTING_BankConfiguration bc;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
- &bc.exchange_auth, \
- bc.user42_payto)
+ &cred.ba, \
+ cred.user42_payto)
/**
* Run the taler-auditor.
@@ -116,7 +111,7 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer
("check-create-reserve-1",
- "EUR:5.01", bc.user42_payto, bc.exchange_payto,
+ "EUR:5.01", cred.user42_payto, cred.exchange_payto,
"create-reserve-1"),
/**
* Make a reserve exist, according to the previous transfer.
@@ -140,7 +135,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-simple",
"withdraw-coin-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -157,7 +152,7 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer
("check-refresh-create-reserve-1",
- "EUR:5.01", bc.user42_payto, bc.exchange_payto,
+ "EUR:5.01", cred.user42_payto, cred.exchange_payto,
"refresh-create-reserve-1"),
/**
* Make previous command effective.
@@ -178,7 +173,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-partial",
"refresh-withdraw-coin-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice\",\"value\":\"EUR:1\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -203,7 +198,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1b",
"refresh-reveal-1",
3,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.1",
@@ -225,75 +220,75 @@ run (void *cls,
*/
TALER_TESTING_cmd_check_bank_transfer (
"check_bank_transfer-499c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer (
"check_bank_transfer-99c1",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer (
"check_bank_transfer-99c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.08",
- bc.exchange_payto,
- bc.user43_payto),
+ cred.exchange_payto,
+ cred.user43_payto),
/* The following transactions got originated within
* the "massive deposit confirms" batch. */
TALER_TESTING_cmd_check_bank_transfer (
"check-massive-transfer-1",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-2",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-3",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-4",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-5",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-6",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-7",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-8",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-9",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer
("check-massive-transfer-10",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto, bc.user43_payto),
+ cred.exchange_payto, cred.user43_payto),
TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"),
TALER_TESTING_cmd_end ()
};
@@ -311,8 +306,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"check_bank_transfer-unaggregated",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-unaggregated"),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-unaggregated",
"create-reserve-unaggregated",
@@ -322,7 +317,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-unaggregated",
"withdraw-coin-unaggregated",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_YEARS,
@@ -359,7 +354,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-1",
"withdraw-coin-r1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_MINUTES,
"EUR:5",
@@ -376,7 +371,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-2",
"withdraw-coin-r1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"more\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:4.99",
@@ -431,8 +426,9 @@ run (void *cls,
*/
CMD_TRANSFER_TO_EXCHANGE ("short-lived-reserve",
"EUR:5.01"),
- TALER_TESTING_cmd_exec_wirewatch ("short-lived-aggregation",
- config_file_expire_reserve_now),
+ TALER_TESTING_cmd_exec_wirewatch2 ("short-lived-aggregation",
+ config_file_expire_reserve_now,
+ "exchange-account-2"),
TALER_TESTING_cmd_exec_aggregator ("close-reserves",
config_file_expire_reserve_now),
/**
@@ -466,7 +462,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("recoup-deposit-partial",
"recoup-withdraw-coin-2a",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.5",
@@ -493,7 +489,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"check-massive-transfer",
"EUR:10.10",
- bc.user42_payto, bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"massive-reserve"),
CMD_EXEC_WIREWATCH ("massive-wirewatch"),
TALER_TESTING_cmd_withdraw_amount ("massive-withdraw-1",
@@ -550,7 +547,7 @@ run (void *cls,
"massive-deposit-1",
"massive-withdraw-1",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -559,7 +556,7 @@ run (void *cls,
("massive-deposit-2",
"massive-withdraw-2",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -568,7 +565,7 @@ run (void *cls,
("massive-deposit-3",
"massive-withdraw-3",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -577,7 +574,7 @@ run (void *cls,
("massive-deposit-4",
"massive-withdraw-4",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -586,7 +583,7 @@ run (void *cls,
("massive-deposit-5",
"massive-withdraw-5",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -595,7 +592,7 @@ run (void *cls,
("massive-deposit-6",
"massive-withdraw-6",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -604,7 +601,7 @@ run (void *cls,
("massive-deposit-7",
"massive-withdraw-7",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -613,7 +610,7 @@ run (void *cls,
("massive-deposit-8",
"massive-withdraw-8",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -622,7 +619,7 @@ run (void *cls,
("massive-deposit-9",
"massive-withdraw-9",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -631,15 +628,14 @@ run (void *cls,
"massive-deposit-10",
"massive-withdraw-10",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
MHD_HTTP_OK),
TALER_TESTING_cmd_deposit_confirmation ("deposit-confirmation",
- is->auditor,
"massive-deposit-10",
- 0,
+ 1,
"EUR:0.99",
MHD_HTTP_OK),
CMD_RUN_AUDITOR ("massive-auditor"),
@@ -648,28 +644,25 @@ run (void *cls,
};
struct TALER_TESTING_Command commands[] = {
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 2),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-u", "exchange-account-2",
+ "-ae",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_get_auditor ("get-auditor",
+ cred.cfg,
+ true),
TALER_TESTING_cmd_exec_auditor_offline ("auditor-offline",
config_file),
CMD_RUN_AUDITOR ("virgin-auditor"),
- TALER_TESTING_cmd_exchanges_with_url ("check-exchange",
- MHD_HTTP_OK,
- "http://localhost:8081/"),
TALER_TESTING_cmd_batch ("massive-deposit-confirms",
massive_deposit_confirms),
TALER_TESTING_cmd_batch ("withdraw",
@@ -691,9 +684,8 @@ run (void *cls,
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
@@ -701,60 +693,28 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
-
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_auditor_api-%s.conf",
- cipher);
- GNUNET_asprintf (&config_file_expire_reserve_now,
- "test_auditor_api_expire_reserve_now-%s.conf",
- cipher);
- GNUNET_free (cipher);
- /* Check fakebank port is available and get configuration data. */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 78;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_auditor_setup (&run,
- NULL,
- config_file))
- return 2;
- break;
- default:
- GNUNET_break (0);
- return 3;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_auditor_api-%s.conf",
+ cipher);
+ GNUNET_asprintf (&config_file_expire_reserve_now,
+ "test_auditor_api_expire_reserve_now-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_auditor_api_version.c b/src/testing/test_auditor_api_version.c
index 1b60b15d1..dcd542ad8 100644
--- a/src/testing/test_auditor_api_version.c
+++ b/src/testing/test_auditor_api_version.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -39,9 +39,9 @@
* Configuration file we use. One (big) configuration is used
* for the various components for this test.
*/
-#define CONFIG_FILE "test_auditor_api.conf"
+#define CONFIG_FILE "test_auditor_api-rsa.conf"
-static struct TALER_AUDITOR_Handle *ah;
+static struct TALER_AUDITOR_GetConfigHandle *ah;
static struct GNUNET_CURL_Context *ctx;
@@ -51,6 +51,7 @@ static int global_ret;
static struct GNUNET_SCHEDULER_Task *tt;
+
static void
do_shutdown (void *cls)
{
@@ -61,7 +62,11 @@ do_shutdown (void *cls)
GNUNET_SCHEDULER_cancel (tt);
tt = NULL;
}
- TALER_AUDITOR_disconnect (ah);
+ if (NULL != ah)
+ {
+ TALER_AUDITOR_get_config_cancel (ah);
+ ah = NULL;
+ }
GNUNET_CURL_fini (ctx);
GNUNET_CURL_gnunet_rc_destroy (rc);
}
@@ -81,20 +86,16 @@ do_timeout (void *cls)
* Function called with information about the auditor.
*
* @param cls closure
- * @param hr http response details
- * @param vi basic information about the auditor
- * @param compat protocol compatibility information
+ * @param vr response details
*/
static void
version_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- const struct TALER_AUDITOR_VersionInformation *vi,
- enum TALER_AUDITOR_VersionCompatibility compat)
+ const struct TALER_AUDITOR_ConfigResponse *vr)
{
(void) cls;
- (void) hr;
- if ( (NULL != vi) &&
- (TALER_AUDITOR_VC_MATCH == compat) )
+ ah = NULL;
+ if ( (MHD_HTTP_OK == vr->hr.http_status) &&
+ (TALER_AUDITOR_VC_MATCH == vr->details.ok.compat) )
global_ret = 0;
else
global_ret = 2;
@@ -117,10 +118,10 @@ run (void *cls)
ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
&rc);
rc = GNUNET_CURL_gnunet_rc_create (ctx);
- ah = TALER_AUDITOR_connect (ctx,
- auditor_url,
- &version_cb,
- NULL);
+ ah = TALER_AUDITOR_get_config (ctx,
+ auditor_url,
+ &version_cb,
+ NULL);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
@@ -148,15 +149,16 @@ main (int argc,
"taler-auditor-httpd",
"taler-auditor-httpd",
"-c", CONFIG_FILE,
+ "-L", "INFO",
NULL);
if (NULL == proc)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `taler-auditor-httpd`,"
- " is your PATH correct?\n");
+ "Failed to run `taler-auditor-httpd`, is your PATH correct?\n");
return 77;
}
- if (0 != TALER_TESTING_wait_auditor_ready ("http://localhost:8083/"))
+ global_ret = TALER_TESTING_wait_httpd_ready ("http://localhost:8083/");
+ if (0 != global_ret)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to launch `taler-auditor-httpd`\n");
@@ -166,7 +168,8 @@ main (int argc,
GNUNET_SCHEDULER_run (&run,
NULL);
}
- GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_OS_process_kill (proc,
+ SIGTERM);
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
return global_ret;
diff --git a/src/testing/test_bank_api.c b/src/testing/test_bank_api.c
index d81fbe36e..8cbc86bbd 100644
--- a/src/testing/test_bank_api.c
+++ b/src/testing/test_bank_api.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2016-2020 Taler Systems SA
+ Copyright (C) 2016-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -34,34 +34,27 @@
#include "taler_testing_lib.h"
#define CONFIG_FILE_FAKEBANK "test_bank_api_fakebank.conf"
-#define CONFIG_FILE_PYBANK "test_bank_api_pybank.conf"
+
#define CONFIG_FILE_NEXUS "test_bank_api_nexus.conf"
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
/**
- * Handle to the Py-bank daemon.
+ * Configuration file. It changes based on
+ * whether Nexus or Fakebank are used.
*/
-static struct GNUNET_OS_Process *bankd;
+static const char *cfgfile;
/**
- * Flag indicating whether the test is running against the
- * Fakebank. Set up at runtime.
+ * Our credentials.
*/
-static int with_fakebank;
+static struct TALER_TESTING_Credentials cred;
/**
- * Handles to the libeufin services.
+ * Which bank is the test running against?
+ * Set up at runtime.
*/
-static struct TALER_TESTING_LibeufinServices libeufin_services;
+static enum TALER_TESTING_BankSystem bs;
-/**
- * Needed to shutdown differently.
- */
-static int with_libeufin;
/**
* Main function that will tell the interpreter what commands to
@@ -74,52 +67,76 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_WireTransferIdentifierRawP wtid;
+ const char *ssoptions;
(void) cls;
- memset (&wtid, 42, sizeof (wtid));
+ switch (bs)
+ {
+ case TALER_TESTING_BS_FAKEBANK:
+ ssoptions = "-f";
+ break;
+ case TALER_TESTING_BS_IBAN:
+ ssoptions = "-b";
+ break;
+ default:
+ ssoptions = NULL;
+ break;
+ }
+ memset (&wtid,
+ 42,
+ sizeof (wtid));
{
struct TALER_TESTING_Command commands[] = {
+ TALER_TESTING_cmd_system_start ("start-taler",
+ cfgfile,
+ ssoptions,
+ NULL),
TALER_TESTING_cmd_bank_credits ("history-0",
- &bc.exchange_auth,
+ &cred.ba,
NULL,
1),
TALER_TESTING_cmd_admin_add_incoming ("credit-1",
- "KUDOS:5.01",
- &bc.exchange_auth,
- bc.user42_payto),
+ "EUR:5.01",
+ &cred.ba_admin,
+ cred.user42_payto),
+ /**
+ * This CMD doesn't care about the HTTP response code; that's
+ * because Fakebank and euFin behaves differently when a reserve
+ * pub is duplicate. Fakebank responds with 409, whereas euFin
+ * with 200 but it bounces the payment back to the customer.
+ */
TALER_TESTING_cmd_admin_add_incoming_with_ref ("credit-1-fail",
- "KUDOS:2.01",
- &bc.exchange_auth,
- bc.user42_payto,
+ "EUR:2.01",
+ &cred.ba_admin,
+ cred.user42_payto,
"credit-1",
- MHD_HTTP_CONFLICT),
- TALER_TESTING_cmd_sleep ("Waiting 4s for 'credit-1' to settle",
- 4),
+ -1),
+ /**
+ * Check that the incoming payment with a duplicate
+ * reserve public key didn't make it to the exchange.
+ */
TALER_TESTING_cmd_bank_credits ("history-1c",
- &bc.exchange_auth,
+ &cred.ba,
NULL,
5),
TALER_TESTING_cmd_bank_debits ("history-1d",
- &bc.exchange_auth,
+ &cred.ba,
NULL,
5),
TALER_TESTING_cmd_admin_add_incoming ("credit-2",
- "KUDOS:3.21",
- &bc.exchange_auth,
- bc.user42_payto),
+ "EUR:3.21",
+ &cred.ba_admin,
+ cred.user42_payto),
TALER_TESTING_cmd_transfer ("debit-1",
- "KUDOS:3.22",
- &bc.exchange_auth,
- bc.exchange_payto,
- bc.user42_payto,
+ "EUR:3.22",
+ &cred.ba,
+ cred.exchange_payto,
+ cred.user42_payto,
&wtid,
"http://exchange.example.com/"),
-
- TALER_TESTING_cmd_sleep ("Waiting 5s for 'debit-1' to settle",
- 5),
TALER_TESTING_cmd_bank_debits ("history-2b",
- &bc.exchange_auth,
+ &cred.ba,
NULL,
5),
TALER_TESTING_cmd_end ()
@@ -127,152 +144,53 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Bank serves at `%s'\n",
- bc.exchange_auth.wire_gateway_url);
- if (GNUNET_YES == with_fakebank)
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
- else
- TALER_TESTING_run (is,
- commands);
+ cred.ba.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
}
-/**
- * Runs #TALER_TESTING_setup() using the configuration.
- *
- * @param cls unused
- * @param cfg configuration to use
- * @return status code
- */
-static int
-setup_with_cfg (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- (void) cls;
- return TALER_TESTING_setup (&run,
- NULL,
- cfg,
- NULL,
- GNUNET_NO);
-}
-
-
int
main (int argc,
char *const *argv)
{
- int rv;
- const char *cfgfile;
-
(void) argc;
- (void) argv;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup ("test-bank-api",
- "DEBUG",
- NULL);
-
- with_fakebank = TALER_TESTING_has_in_name (argv[0],
- "_with_fakebank");
- if (GNUNET_YES == with_fakebank)
+ if (TALER_TESTING_has_in_name (argv[0],
+ "_with_fakebank"))
{
- TALER_LOG_DEBUG ("Running against the Fakebank.\n");
+ bs = TALER_TESTING_BS_FAKEBANK;
cfgfile = CONFIG_FILE_FAKEBANK;
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (CONFIG_FILE_FAKEBANK,
- "exchange-account-2",
- &bc))
- {
- GNUNET_break (0);
- return 77;
- }
}
- else if (GNUNET_YES == TALER_TESTING_has_in_name (argv[0],
- "_with_pybank"))
+ else if (TALER_TESTING_has_in_name (argv[0],
+ "_with_nexus"))
{
- TALER_LOG_DEBUG ("Running against the Pybank.\n");
- cfgfile = CONFIG_FILE_PYBANK;
- if (GNUNET_OK !=
- TALER_TESTING_prepare_bank (CONFIG_FILE_PYBANK,
- GNUNET_YES,
- "exchange-account-2",
- &bc))
- {
- GNUNET_break (0);
- return 77;
- }
-
- if (NULL == (bankd = TALER_TESTING_run_bank (
- CONFIG_FILE_PYBANK,
- bc.exchange_auth.wire_gateway_url)))
- {
- GNUNET_break (0);
- return 77;
- }
- }
- else if (GNUNET_YES == TALER_TESTING_has_in_name (argv[0],
- "_with_nexus"))
- {
- TALER_LOG_DEBUG ("Running with Nexus.\n");
- with_libeufin = GNUNET_YES;
+ bs = TALER_TESTING_BS_IBAN;
cfgfile = CONFIG_FILE_NEXUS;
- if (GNUNET_OK !=
- TALER_TESTING_prepare_nexus (CONFIG_FILE_NEXUS,
- GNUNET_YES,
- "exchange-account-2",
- &bc))
+ if (GNUNET_SYSERR ==
+ GNUNET_OS_check_helper_binary ("libeufin-bank",
+ false,
+ NULL))
{
- GNUNET_break (0);
+ fprintf (stderr,
+ "libeufin-bank not found. Skipping test.\n");
return 77;
}
- libeufin_services = TALER_TESTING_run_libeufin (&bc);
- if ( (NULL == libeufin_services.nexus) ||
- (NULL == libeufin_services.sandbox) )
- return 77;
}
else
{
- /* no bank service was ever invoked. */
+ /* no bank service was specified. */
+ GNUNET_break (0);
return 77;
}
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse_and_run (cfgfile,
- &setup_with_cfg,
- NULL))
- rv = 1;
- else
- rv = 0;
-
- if (GNUNET_NO == with_fakebank)
- {
- // -> pybank
- if (GNUNET_NO == with_libeufin)
- {
-
- GNUNET_OS_process_kill (bankd,
- SIGKILL);
- GNUNET_OS_process_wait (bankd);
- GNUNET_OS_process_destroy (bankd);
- }
- else // -> libeufin
- {
- GNUNET_OS_process_kill (libeufin_services.nexus,
- SIGKILL);
- GNUNET_OS_process_wait (libeufin_services.nexus);
- GNUNET_OS_process_destroy (libeufin_services.nexus);
-
- GNUNET_OS_process_kill (libeufin_services.sandbox,
- SIGKILL);
- GNUNET_OS_process_wait (libeufin_services.sandbox);
- GNUNET_OS_process_destroy (libeufin_services.sandbox);
- }
- }
-
- return rv;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ cfgfile,
+ "exchange-account-2",
+ bs,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_bank_api.conf b/src/testing/test_bank_api.conf
new file mode 100644
index 000000000..c262ae197
--- /dev/null
+++ b/src/testing/test_bank_api.conf
@@ -0,0 +1,23 @@
+# This file is in the public domain
+
+[PATHS]
+TALER_TEST_HOME = test_exchange_api_home/
+
+[taler]
+currency = EUR
+
+[bank]
+SERVE = http
+HTTP_PORT = 8082
+
+[libeufin-bank]
+CURRENCY = EUR
+WIRE_TYPE = iban
+IBAN_PAYTO_BIC = SANDBOXX=
+DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200
+DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000
+REGISTRATION_BONUS_ENABLED = yes
+REGISTRATION_BONUS = EUR:100
+SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/
+SERVE = tcp
+PORT = 8082
diff --git a/src/testing/test_bank_api_fakebank.conf b/src/testing/test_bank_api_fakebank.conf
index 1e5a4d18e..62fa4cd4c 100644
--- a/src/testing/test_bank_api_fakebank.conf
+++ b/src/testing/test_bank_api_fakebank.conf
@@ -1,21 +1,21 @@
# This file is in the public domain.
+@INLINE@ test_bank_api.conf
-[taler]
-currency = KUDOS
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost:8082/1?receiver-name=1"
[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+PAYTO_URI = "payto://x-taler-bank/localhost:8082/2?receiver-name=2"
[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8081/2/"
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
WIRE_GATEWAY_AUTH_METHOD = basic
USERNAME = Exchange
PASSWORD = x
-[bank]
-SERVE = http
-HTTP_PORT = 8081
-DATABASE = postgres:///talercheck
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
+[admin-accountcredentials-2]
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+WIRE_GATEWAY_AUTH_METHOD = basic
+# For now, fakebank still checks against the Exchange account...
+USERNAME = Exchange
+PASSWORD = x
diff --git a/src/testing/test_bank_api_fakebank_twisted.conf b/src/testing/test_bank_api_fakebank_twisted.conf
index 6d316c141..bc66c0d88 100644
--- a/src/testing/test_bank_api_fakebank_twisted.conf
+++ b/src/testing/test_bank_api_fakebank_twisted.conf
@@ -1,12 +1,15 @@
+# This file is in the public domain.
+
+@INLINE@ test_bank_api_fakebank.conf
[twister]
+
# HTTP listen port for twister
HTTP_PORT = 8888
SERVE = tcp
-
# HTTP Destination for twister. The test-Webserver needs
# to listen on the port used here. Note: no trailing '/'!
-DESTINATION_BASE_URL = "http://localhost:8081"
+DESTINATION_BASE_URL = "http://localhost:8082"
# Control port for TCP
# PORT = 8889
@@ -18,20 +21,3 @@ ACCEPT_FROM6 = ::1;
UNIXPATH = /tmp/taler-service-twister.sock
UNIX_MATCH_UID = NO
UNIX_MATCH_GID = YES
-
-[taler]
-currency = KUDOS
-
-[bank]
-serve = http
-http_port = 8081
-database = postgres:///talercheck
-
-[exchange-account-1]
-PAYTO_URI = "payto://x-taler-bank/localhost:8081/1?receiver-name=1"
-
-[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost:8081/2?receiver-name=2"
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
diff --git a/src/testing/test_bank_api_nexus.conf b/src/testing/test_bank_api_nexus.conf
index c514170e1..605c7b00e 100644
--- a/src/testing/test_bank_api_nexus.conf
+++ b/src/testing/test_bank_api_nexus.conf
@@ -1,23 +1,35 @@
# This file is in the public domain.
-
-[taler]
-currency = KUDOS
+@INLINE@ test_bank_api.conf
[exchange-account-2]
PAYTO_URI = payto://iban/BIC/ES9121000418450200051332?receiver-name=Exchange
[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = http://localhost:5001/facades/my-facade/taler/
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/exchange/taler-wire-gateway/
WIRE_GATEWAY_AUTH_METHOD = basic
-# the exchange authenticates as the 'admin' user,
-# since that makes the test preparation just easier.
-USERNAME = Exchange
+USERNAME = exchange
PASSWORD = x
-[bank]
-# not (!) used by the nexus, only by the helper
-# check to make sure the port is free for the nexus.
-HTTP_PORT = 5001
+[admin-accountcredentials-2]
+WIRE_GATEWAY_URL = http://localhost:8082/accounts/exchange/taler-wire-gateway/
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = admin
+# 'secret' is from taler-unified-setup.sh
+PASSWORD = secret
+
+[libeufin-bankdb-postgres]
+CONFIG="postgresql:///talercheck"
-[auditor]
-BASE_URL = "http://localhost:8083/"
+# libeufin doesn't search our config.d/currencies.conf
+# as it has a different resource path. Thus replicated
+# here.
+[currency-euro]
+ENABLED = YES
+name = "Euro"
+code = "EUR"
+decimal_separator = ","
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+is_currency_name_leading = NO
+alt_unit_names = {"0":"€"}
diff --git a/src/testing/test_bank_api_twisted.c b/src/testing/test_bank_api_twisted.c
index c550aaeb2..038ec8a1f 100644
--- a/src/testing/test_bank_api_twisted.c
+++ b/src/testing/test_bank_api_twisted.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -17,7 +17,7 @@
<http://www.gnu.org/licenses/>
*/
/**
- * @file testing/test_bank_api_with_fakebank_twisted.c
+ * @file testing/test_bank_api_twisted.c
* @author Marcello Stanisci
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Christian Grothoff
@@ -42,19 +42,20 @@
#define CONFIG_FILE_FAKEBANK "test_bank_api_fakebank_twisted.conf"
/**
- * Separate config file for running with the pybank.
+ * Configuration file we use.
*/
-#define CONFIG_FILE_PYBANK "test_bank_api_pybank_twisted.conf"
+static const char *cfgfile;
/**
- * True when the test runs against Fakebank.
+ * Our credentials.
*/
-static int with_fakebank;
+static struct TALER_TESTING_Credentials cred;
/**
- * Bank configuration data.
+ * Which bank is the test running against?
+ * Set up at runtime.
*/
-static struct TALER_TESTING_BankConfiguration bc;
+static enum TALER_TESTING_BankSystem bs;
/**
* (real) Twister URL. Used at startup time to check if it runs.
@@ -66,11 +67,6 @@ static char *twister_url;
*/
static struct GNUNET_OS_Process *twisterd;
-/**
- * Python bank process handle.
- */
-static struct GNUNET_OS_Process *bankd;
-
/**
* Main function that will tell
@@ -83,176 +79,118 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_WireTransferIdentifierRawP wtid;
- /* Route our commands through twister. */
+ /* Authentication data to route our commands through twister. */
struct TALER_BANK_AuthenticationData exchange_auth_twisted;
+ const char *systype = NULL;
(void) cls;
memset (&wtid,
0x5a,
sizeof (wtid));
- memcpy (&exchange_auth_twisted,
- &bc.exchange_auth,
- sizeof (struct TALER_BANK_AuthenticationData));
- if (with_fakebank)
- exchange_auth_twisted.wire_gateway_url =
- "http://localhost:8888/2/";
- else
- exchange_auth_twisted.wire_gateway_url =
- "http://localhost:8888/taler-wire-gateway/Exchange/";
+ GNUNET_memcpy (&exchange_auth_twisted,
+ &cred.ba,
+ sizeof (struct TALER_BANK_AuthenticationData));
+ switch (bs)
+ {
+ case TALER_TESTING_BS_FAKEBANK:
+ exchange_auth_twisted.wire_gateway_url
+ = "http://localhost:8888/accounts/2/taler-wire-gateway/";
+ systype = "-f";
+ break;
+ case TALER_TESTING_BS_IBAN:
+ exchange_auth_twisted.wire_gateway_url
+ = "http://localhost:8888/accounts/Exchange/taler-wire-gateway/";
+ systype = "-b";
+ break;
+ }
+ GNUNET_assert (NULL != systype);
- struct TALER_TESTING_Command commands[] = {
- /* Test retrying transfer after failure. */
- TALER_TESTING_cmd_malform_response ("malform-transfer",
- CONFIG_FILE_FAKEBANK),
- TALER_TESTING_cmd_transfer_retry (
- TALER_TESTING_cmd_transfer ("debit-1",
- "KUDOS:3.22",
- &exchange_auth_twisted,
- bc.exchange_payto,
- bc.user42_payto,
- &wtid,
- "http://exchange.example.com/")),
- TALER_TESTING_cmd_end ()
- };
+ {
+ struct TALER_TESTING_Command commands[] = {
+ TALER_TESTING_cmd_system_start ("start-taler",
+ cfgfile,
+ systype,
+ NULL),
+ /* Test retrying transfer after failure. */
+ TALER_TESTING_cmd_malform_response ("malform-transfer",
+ cfgfile),
+ TALER_TESTING_cmd_transfer_retry (
+ TALER_TESTING_cmd_transfer ("debit-1",
+ "EUR:3.22",
+ &exchange_auth_twisted,
+ cred.exchange_payto,
+ cred.user42_payto,
+ &wtid,
+ "http://exchange.example.com/")),
+ TALER_TESTING_cmd_end ()
+ };
- if (GNUNET_YES == with_fakebank)
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
- else
TALER_TESTING_run (is,
commands);
+ }
}
/**
* Kill, wait, and destroy convenience function.
*
- * @param process process to purge.
+ * @param[in] process process to purge.
*/
static void
purge_process (struct GNUNET_OS_Process *process)
{
- GNUNET_OS_process_kill (process, SIGINT);
+ GNUNET_OS_process_kill (process,
+ SIGINT);
GNUNET_OS_process_wait (process);
GNUNET_OS_process_destroy (process);
}
-/**
- * Runs #TALER_TESTING_setup() using the configuration.
- *
- * @param cls unused
- * @param cfg configuration to use
- * @return status code
- */
-static int
-setup_with_cfg (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- (void) cls;
- return TALER_TESTING_setup (&run,
- NULL,
- cfg,
- NULL,
- GNUNET_NO);
-}
-
-
int
main (int argc,
char *const *argv)
{
int ret;
- const char *cfgfilename;
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup ("test-bank-api-with-(fake)bank-twisted",
- "DEBUG",
- NULL);
-
- with_fakebank = TALER_TESTING_has_in_name (argv[0],
- "_with_fakebank");
-
- if (with_fakebank)
- cfgfilename = CONFIG_FILE_FAKEBANK;
- else
- cfgfilename = CONFIG_FILE_PYBANK;
-
- if (NULL == (twister_url = TALER_TWISTER_prepare_twister (
- cfgfilename)))
+ if (TALER_TESTING_has_in_name (argv[0],
+ "_with_fakebank"))
{
- GNUNET_break (0);
- return 77;
+ bs = TALER_TESTING_BS_FAKEBANK;
+ cfgfile = CONFIG_FILE_FAKEBANK;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "twister_url is %s\n",
- twister_url);
- if (NULL == (twisterd = TALER_TWISTER_run_twister (cfgfilename)))
+ else if (TALER_TESTING_has_in_name (argv[0],
+ "_with_nexus"))
{
- GNUNET_break (0);
- GNUNET_free (twister_url);
- return 77;
- }
- if (GNUNET_YES == with_fakebank)
- {
- TALER_LOG_DEBUG ("Running against the Fakebank.\n");
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (cfgfilename,
- "exchange-account-2",
- &bc))
- {
- GNUNET_break (0);
- GNUNET_free (twister_url);
- return 77;
- }
+ GNUNET_assert (0); /* FIXME: test with nexus not yet implemented */
+ bs = TALER_TESTING_BS_IBAN;
+ /* cfgfile = CONFIG_FILE_NEXUS; */
}
else
{
- TALER_LOG_DEBUG ("Running against the Pybank.\n");
- if (GNUNET_OK !=
- TALER_TESTING_prepare_bank (cfgfilename,
- GNUNET_YES,
- "exchange-account-2",
- &bc))
- {
- GNUNET_break (0);
- GNUNET_free (twister_url);
- return 77;
- }
-
- if (NULL == (bankd = TALER_TESTING_run_bank (
- cfgfilename,
- bc.exchange_auth.wire_gateway_url)))
- {
- GNUNET_break (0);
- GNUNET_free (twister_url);
- return 77;
- }
+ /* no bank service was specified. */
+ GNUNET_break (0);
+ return 77;
}
- sleep (5);
- ret = GNUNET_CONFIGURATION_parse_and_run (cfgfilename,
- &setup_with_cfg,
- NULL);
+ /* FIXME: introduce commands for twister! */
+ twister_url = TALER_TWISTER_prepare_twister (cfgfile);
+ if (NULL == twister_url)
+ return 77;
+ twisterd = TALER_TWISTER_run_twister (cfgfile);
+ if (NULL == twisterd)
+ return 77;
+ ret = TALER_TESTING_main (argv,
+ "INFO",
+ cfgfile,
+ "exchange-account-2",
+ bs,
+ &cred,
+ &run,
+ NULL);
purge_process (twisterd);
-
- if (GNUNET_NO == with_fakebank)
- {
- GNUNET_OS_process_kill (bankd,
- SIGKILL);
- GNUNET_OS_process_wait (bankd);
- GNUNET_OS_process_destroy (bankd);
- }
-
GNUNET_free (twister_url);
- if (GNUNET_OK == ret)
- return 0;
-
- return 1;
+ return ret;
}
diff --git a/src/testing/test_exchange_api-cs.conf b/src/testing/test_exchange_api-cs.conf
index 9485a724d..b80696fb2 100644
--- a/src/testing/test_exchange_api-cs.conf
+++ b/src/testing/test_exchange_api-cs.conf
@@ -1,209 +1,4 @@
# This file is in the public domain.
#
-
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-
-[exchange]
-
-TERMS_ETAG = 0
-PRIVACY_ETAG = 0
-
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-# How big is an individual shard to be processed
-# by taler-exchange-expire (in time). It may take
-# this much time for an expired purse to be really
-# cleaned up and the coins refunded.
-EXPIRE_SHARD_SIZE = 300 ms
-
-EXPIRE_IDLE_SLEEP_INTERVAL = 1 s
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Sections starting with "exchange-account-" configure the bank accounts
-# of the exchange. The "URL" specifies the account in
-# payto://-format.
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-# ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9081/42/"
-
-[exchange-account-2]
-# What is the bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_AUTH_METHOD = basic
-USERNAME = Exchange
-PASSWORD = x
-WIRE_GATEWAY_URL = "http://localhost:9081/2/"
-
-[bank]
-HTTP_PORT = 9081
-
-# Enabled extensions
-[exchange-extension-age_restriction]
-ENABLED = YES
-# default age groups:
-#AGE_GROUPS = "8:10:12:14:16:18:21"
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_1_age_restricted]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-age_restricted = YES
-CIPHER = CS
-
-[coin_eur_ct_10_age_restricted]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-age_restricted = YES
-CIPHER = CS
-
-[coin_eur_1_age_restricted]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-age_restricted = YES
-CIPHER = CS
-
-[coin_eur_5_age_restricted]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-age_restricted = YES
-CIPHER = CS
-
-[coin_eur_10_age_restricted]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-age_restricted = YES
-CIPHER = CS
+@INLINE@ coins-cs.conf
+@INLINE@ test_exchange_api.conf
diff --git a/src/testing/test_exchange_api-rsa.conf b/src/testing/test_exchange_api-rsa.conf
index bd27d560f..351c876d9 100644
--- a/src/testing/test_exchange_api-rsa.conf
+++ b/src/testing/test_exchange_api-rsa.conf
@@ -1,220 +1,4 @@
# This file is in the public domain.
#
-
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-
-[exchange]
-
-TERMS_ETAG = 0
-PRIVACY_ETAG = 0
-
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-# How big is an individual shard to be processed
-# by taler-exchange-expire (in time). It may take
-# this much time for an expired purse to be really
-# cleaned up and the coins refunded.
-EXPIRE_SHARD_SIZE = 300 ms
-
-EXPIRE_IDLE_SLEEP_INTERVAL = 1 s
-
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Sections starting with "exchange-account-" configure the bank accounts
-# of the exchange. The "URL" specifies the account in
-# payto://-format.
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-# ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9081/42/"
-
-[exchange-account-2]
-# What is the bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_AUTH_METHOD = basic
-USERNAME = Exchange
-PASSWORD = x
-WIRE_GATEWAY_URL = "http://localhost:9081/2/"
-
-[bank]
-HTTP_PORT = 9081
-
-# Enabled extensions
-[exchange-extension-age_restriction]
-ENABLED = YES
-# default age groups:
-#AGE_GROUPS = "8:10:12:14:16:18:21"
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_ct_1_age_restricted]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-age_restricted = YES
-CIPHER = RSA
-
-[coin_eur_ct_10_age_restricted]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-age_restricted = YES
-CIPHER = RSA
-
-[coin_eur_1_age_restricted]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-age_restricted = YES
-CIPHER = RSA
-
-[coin_eur_5_age_restricted]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-age_restricted = YES
-CIPHER = RSA
-
-[coin_eur_10_age_restricted]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-age_restricted = YES
-CIPHER = RSA
+@INLINE@ coins-rsa.conf
+@INLINE@ test_exchange_api.conf \ No newline at end of file
diff --git a/src/testing/test_exchange_api-twisted.conf b/src/testing/test_exchange_api-twisted.conf
new file mode 100644
index 000000000..536d36ee4
--- /dev/null
+++ b/src/testing/test_exchange_api-twisted.conf
@@ -0,0 +1,29 @@
+# This file is in the public domain.
+
+[exchange]
+# Base URL of the exchange ('S PROXY). This URL is where the
+# twister listens at, so that it will be able to get all the
+# connection addressed to the exchange. In fact, the presence
+# of the twister is 100% transparent to the test case, as it
+# only seeks the exchange/BASE_URL URL to connect to the exchange.
+BASE_URL = "http://localhost:8888/"
+
+[twister]
+# HTTP listen port for twister
+HTTP_PORT = 8888
+SERVE = tcp
+
+# HTTP Destination for twister. The test-Webserver needs
+# to listen on the port used here. Note: no trailing '/'!
+DESTINATION_BASE_URL = "http://localhost:8081"
+
+# Control port for TCP
+# PORT = 8889
+HOSTNAME = localhost
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+
+# Control port for UNIX
+UNIXPATH = /tmp/taler-service-twister.sock
+UNIX_MATCH_UID = NO
+UNIX_MATCH_GID = YES
diff --git a/src/testing/test_exchange_api.c b/src/testing/test_exchange_api.c
index f30701c34..caeec1e76 100644
--- a/src/testing/test_exchange_api.c
+++ b/src/testing/test_exchange_api.c
@@ -49,18 +49,13 @@ static char *config_file;
static char *config_file_expire_reserve_now;
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
+static struct TALER_TESTING_Credentials cred;
/**
* Some tests behave differently when using CS as we cannot
- * re-use the coin private key for different denominations
+ * reuse the coin private key for different denominations
* due to the derivation of it with the /csr values. Hence
* some tests behave differently in CS mode, hence this
* flag.
@@ -74,7 +69,7 @@ static bool uses_cs;
* @param label label to use for the command.
*/
#define CMD_EXEC_WIREWATCH(label) \
- TALER_TESTING_cmd_exec_wirewatch (label, config_file)
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, "exchange-account-2")
/**
* Execute the taler-exchange-aggregator, closer and transfer commands with
@@ -97,8 +92,8 @@ static bool uses_cs;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
- &bc.exchange_auth, \
- bc.user42_payto)
+ &cred.ba, \
+ cred.user42_payto)
/**
* Main function that will tell the interpreter what commands to
@@ -112,21 +107,6 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
/**
- * Checks made against /wire response.
- */
- struct TALER_TESTING_Command wire[] = {
- /**
- * Check if 'x-taler-bank' wire method is offered
- * by the exchange.
- */
- TALER_TESTING_cmd_wire ("wire-taler-bank-1",
- "x-taler-bank",
- NULL,
- MHD_HTTP_OK),
- TALER_TESTING_cmd_end ()
- };
-
- /**
* Test withdrawal plus spending.
*/
struct TALER_TESTING_Command withdraw[] = {
@@ -142,8 +122,8 @@ run (void *cls,
MHD_HTTP_OK),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
"EUR:6.02",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-1"),
/**
* Make a reserve exist, according to the previous
@@ -201,12 +181,17 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-simple",
"withdraw-coin-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
MHD_HTTP_OK),
- TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay",
+ TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-1",
+ "deposit-simple",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_sleep ("sleep-before-deposit-replay",
+ 1),
+ TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-2",
"deposit-simple",
MHD_HTTP_OK),
/* This creates a conflict, as we have the same coin public key (reuse!),
@@ -219,7 +204,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-reused-coin-key-failure",
"withdraw-coin-1x",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -232,7 +217,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-double-1",
"withdraw-coin-1",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -246,7 +231,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-double-1",
"withdraw-coin-1",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -257,7 +242,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-double-2",
"withdraw-coin-1",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":2}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -282,8 +267,8 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer ("ck-refresh-create-reserve-1",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"refresh-create-reserve-1"),
/**
* Make previous command effective.
@@ -304,7 +289,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-partial",
"refresh-withdraw-coin-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -341,7 +326,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1a",
"refresh-reveal-1-idempotency",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -352,7 +337,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-1b",
"refresh-reveal-1",
3,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.1",
@@ -390,8 +375,8 @@ run (void *cls,
"EUR:6.01"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-age",
"EUR:6.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-age"),
/**
* Make a reserve exist, according to the previous
@@ -417,7 +402,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-simple-age",
"withdraw-coin-age-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:4.99",
@@ -425,6 +410,14 @@ run (void *cls,
TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-age",
"deposit-simple-age",
MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-age-1",
+ "deposit-simple-age",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_sleep ("sleep-before-age-deposit-replay",
+ 1),
+ TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-age-2",
+ "deposit-simple-age",
+ MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
@@ -464,53 +457,53 @@ run (void *cls,
* Check all the transfers took place.
*/
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-499c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-499c2",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.97",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c1",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c2",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c3",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-99c4",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-08c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.08",
- bc.exchange_payto,
- bc.user43_payto),
+ cred.exchange_payto,
+ cred.user43_payto),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-08c2",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.08",
- bc.exchange_payto,
- bc.user43_payto),
+ cred.exchange_payto,
+ cred.user43_payto),
/* In case of CS, one transaction above succeeded that
failed for RSA, hence we need to check for an extra transfer here */
uses_cs
? TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-98c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.98",
- bc.exchange_payto,
- bc.user42_payto)
+ cred.exchange_payto,
+ cred.user42_payto)
: TALER_TESTING_cmd_sleep ("dummy",
0),
TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"),
@@ -544,8 +537,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"check-create-reserve-unaggregated",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-unaggregated"),
CMD_EXEC_WIREWATCH ("wirewatch-unaggregated"),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-unaggregated",
@@ -556,7 +549,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-unaggregated",
"withdraw-coin-unaggregated",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_YEARS,
@@ -578,8 +571,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"ck-refresh-create-reserve-age-1",
"EUR:6.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"refresh-create-reserve-age-1"),
/**
* Make previous command effective.
@@ -600,7 +593,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-partial-age",
"refresh-withdraw-coin-age-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -637,7 +630,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1a",
"refresh-reveal-age-1-idempotency",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -648,7 +641,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1b",
"refresh-reveal-age-1",
3,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.1",
@@ -665,7 +658,6 @@ run (void *cls,
"refresh-reveal-age-1",
MHD_HTTP_CONFLICT,
NULL),
-
TALER_TESTING_cmd_end ()
};
@@ -680,8 +672,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"check-create-reserve-aggtest",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-aggtest"),
CMD_EXEC_WIREWATCH ("wirewatch-aggtest"),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-aggtest",
@@ -692,7 +684,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-aggtest-1",
"withdraw-coin-aggtest",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:2",
@@ -700,7 +692,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit_with_ref ("deposit-aggtest-2",
"withdraw-coin-aggtest",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"foo bar\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:2",
@@ -708,10 +700,10 @@ run (void *cls,
"deposit-aggtest-1"),
CMD_EXEC_AGGREGATOR ("aggregation-aggtest"),
TALER_TESTING_cmd_check_bank_transfer ("check-bank-transfer-aggtest",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:3.97",
- bc.exchange_payto,
- bc.user43_payto),
+ cred.exchange_payto,
+ cred.user43_payto),
TALER_TESTING_cmd_check_bank_empty ("check-bank-empty-aggtest"),
TALER_TESTING_cmd_end ()
};
@@ -725,8 +717,8 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-r1",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-r1"),
/**
* Run wire-watch to trigger the reserve creation.
@@ -745,7 +737,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-1",
"withdraw-coin-r1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_MINUTES,
"EUR:5",
@@ -779,7 +771,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-insufficient-refund",
"withdraw-coin-r1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:4\"}]}",
GNUNET_TIME_UNIT_MINUTES,
"EUR:4",
@@ -796,7 +788,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-2",
"withdraw-coin-r1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"more ice cream\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:4.99",
@@ -810,10 +802,10 @@ run (void *cls,
* Check that deposit did run.
*/
TALER_TESTING_cmd_check_bank_transfer ("check_bank_transfer-pre-refund",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.97",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/**
* Run failing refund, as past deadline & aggregation.
*/
@@ -830,8 +822,8 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-rb",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-rb"),
CMD_EXEC_WIREWATCH ("wirewatch-rb"),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-rb",
@@ -842,7 +834,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-refund-1b",
"withdraw-coin-rb",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -876,8 +868,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"recoup-create-reserve-1-check",
"EUR:15.02",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"recoup-create-reserve-1"),
/**
* Run wire-watch to trigger the reserve creation.
@@ -1006,11 +998,12 @@ run (void *cls,
"EUR:5.01"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-short-lived-reserve",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"short-lived-reserve"),
- TALER_TESTING_cmd_exec_wirewatch ("short-lived-aggregation",
- config_file_expire_reserve_now),
+ TALER_TESTING_cmd_exec_wirewatch2 ("short-lived-aggregation",
+ config_file_expire_reserve_now,
+ "exchange-account-2"),
TALER_TESTING_cmd_exec_closer ("close-reserves",
config_file_expire_reserve_now,
"EUR:5",
@@ -1029,10 +1022,10 @@ run (void *cls,
0, /* age restriction off */
MHD_HTTP_CONFLICT),
TALER_TESTING_cmd_check_bank_transfer ("check_bank_short-lived_reimburse",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:5",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Fill reserve with EUR:2.02, as withdraw fee is 1 ct per
* config, then withdraw two coin, partially spend one, and
* then have the rest paid back. Check deposit of other coin
@@ -1042,8 +1035,8 @@ run (void *cls,
"EUR:2.02"),
TALER_TESTING_cmd_check_bank_admin_transfer ("ck-recoup-create-reserve-2",
"EUR:2.02",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"recoup-create-reserve-2"),
/* Make previous command effective. */
CMD_EXEC_WIREWATCH ("wirewatch-5"),
@@ -1062,7 +1055,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("recoup-deposit-partial",
"recoup-withdraw-coin-2a",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.5",
@@ -1090,7 +1083,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("recoup-deposit-revoked",
"recoup-withdraw-coin-2b",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"more ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -1102,7 +1095,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("recoup-deposit-partial-after-recoup",
"recoup-withdraw-coin-2a",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"extra ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:0.5",
@@ -1113,8 +1106,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"check-recoup-create-reserve-3",
"EUR:1.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"recoup-create-reserve-3"),
CMD_EXEC_WIREWATCH ("wirewatch-6"),
TALER_TESTING_cmd_withdraw_amount ("recoup-withdraw-coin-3-revoked",
@@ -1144,8 +1137,8 @@ run (void *cls,
MHD_HTTP_OK),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-batch-reserve-1",
"EUR:6.03",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-batch-reserve-1"),
/*
* Make a reserve exist, according to the previous
@@ -1174,17 +1167,13 @@ run (void *cls,
MHD_HTTP_OK),
TALER_TESTING_cmd_reserve_history ("history-batch-1",
"create-batch-reserve-1",
- "EUR:0",
+ "EUR:0.01",
MHD_HTTP_OK),
- TALER_TESTING_cmd_status ("status-batch-2",
- "create-batch-reserve-1",
- "EUR:0.0",
- MHD_HTTP_OK),
/**
* Spend the coins.
*/
TALER_TESTING_cmd_batch_deposit ("batch-deposit-1",
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":5}]}",
GNUNET_TIME_UNIT_ZERO,
MHD_HTTP_OK,
@@ -1193,6 +1182,10 @@ run (void *cls,
"batch-withdraw-coin-1#1",
"EUR:1",
NULL),
+ TALER_TESTING_cmd_coin_history ("coin-history-batch-1",
+ "batch-withdraw-coin-1#0",
+ "EUR:0.0",
+ MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
@@ -1213,8 +1206,9 @@ run (void *cls,
= CMD_TRANSFER_TO_EXCHANGE ("reserve-open-close-key",
"EUR:20");
reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 1]
- = TALER_TESTING_cmd_exec_wirewatch ("reserve-open-close-wirewatch",
- config_file_expire_reserve_now);
+ = TALER_TESTING_cmd_exec_wirewatch2 ("reserve-open-close-wirewatch",
+ config_file_expire_reserve_now,
+ "exchange-account-2");
reserve_open_close[(i * RESERVE_OPEN_CLOSE_CHUNK) + 2]
= TALER_TESTING_cmd_exec_closer ("reserve-open-close-aggregation",
config_file_expire_reserve_now,
@@ -1232,38 +1226,18 @@ run (void *cls,
{
struct TALER_TESTING_Command commands[] = {
- /* setup exchange */
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_extensions ("offline-sign-extensions",
- config_file),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_global_fees (
- "offline-sign-global-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_DAYS,
- 1),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
- TALER_TESTING_cmd_batch ("wire",
- wire),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_batch ("withdraw",
withdraw),
TALER_TESTING_cmd_batch ("spend",
@@ -1294,9 +1268,8 @@ run (void *cls,
TALER_TESTING_cmd_end ()
};
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
}
@@ -1305,65 +1278,30 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
-
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
-
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- uses_cs = (0 == strcmp (cipher, "cs"));
- GNUNET_asprintf (&config_file,
- "test_exchange_api-%s.conf",
- cipher);
- GNUNET_asprintf (&config_file_expire_reserve_now,
- "test_exchange_api_expire_reserve_now-%s.conf",
- cipher);
- GNUNET_free (cipher);
-
- /* Check fakebank port is available and get config */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 78;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 2;
- break;
- default:
- GNUNET_break (0);
- return 3;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ uses_cs = (0 == strcmp (cipher,
+ "cs"));
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api-%s.conf",
+ cipher);
+ GNUNET_asprintf (&config_file_expire_reserve_now,
+ "test_exchange_api_expire_reserve_now-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_exchange_api.conf b/src/testing/test_exchange_api.conf
new file mode 100644
index 000000000..c25f5091a
--- /dev/null
+++ b/src/testing/test_exchange_api.conf
@@ -0,0 +1,118 @@
+# This file is in the public domain.
+#
+
+[PATHS]
+TALER_TEST_HOME = test_exchange_api_home/
+
+[libeufin-bank]
+CURRENCY = EUR
+DEFAULT_CUSTOMER_DEBT_LIMIT = EUR:200
+DEFAULT_ADMIN_DEBT_LIMIT = EUR:2000
+REGISTRATION_BONUS_ENABLED = yes
+REGISTRATION_BONUS = EUR:100
+SUGGESTED_WITHDRAWAL_EXCHANGE = http://localhost:8081/
+WIRE_TYPE = iban
+IBAN_PAYTO_BIC = SANDBOXX
+SERVE = tcp
+PORT = 8082
+
+[libeufin-bankdb-postgres]
+CONFIG = postgresql:///talercheck
+
+
+[taler]
+CURRENCY = EUR
+CURRENCY_ROUND_UNIT = EUR:0.01
+
+[auditor]
+BASE_URL = "http://localhost:8083/"
+PORT = 8083
+PUBLIC_KEY = 9QZ7CCC5QFMWE9FVF50MGYWV7JR92SFHY5KHT8A1A2VNHM37VCRG
+TINY_AMOUNT = EUR:0.01
+
+[auditordb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[bank]
+HTTP_PORT = 8082
+
+[exchange]
+TERMS_ETAG = tos
+PRIVACY_ETAG = 0
+AML_THRESHOLD = EUR:1000000
+PORT = 8081
+MASTER_PUBLIC_KEY = QD6H521CBJBW0Z7PRN0JTAGH5JCQ97RDZRPPV5TQZSE78NQRT3KG
+DB = postgres
+BASE_URL = "http://localhost:8081/"
+EXPIRE_SHARD_SIZE ="300 ms"
+EXPIRE_IDLE_SLEEP_INTERVAL ="1 s"
+
+[exchangedb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[taler-exchange-secmod-cs]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-rsa]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-eddsa]
+LOOKAHEAD_SIGN = "24 days"
+DURATION = "14 days"
+
+
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+[exchange-account-2]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+[admin-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+# For now, fakebank still checks against the Exchange account...
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+
+[kyc-provider-test-oauth2]
+COST = 0
+LOGIC = oauth2
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = DUMMY
+KYC_OAUTH2_VALIDITY = forever
+KYC_OAUTH2_TOKEN_URL = http://localhost:6666/oauth/v2/token
+KYC_OAUTH2_AUTHORIZE_URL = http://localhost:6666/oauth/v2/login
+KYC_OAUTH2_INFO_URL = http://localhost:6666/api/user/me
+KYC_OAUTH2_CLIENT_ID = taler-exchange
+KYC_OAUTH2_CLIENT_SECRET = exchange-secret
+KYC_OAUTH2_POST_URL = http://example.com/
+KYC_OAUTH2_CONVERTER_HELPER = taler-exchange-kyc-oauth2-test-converter.sh
+
+[kyc-legitimization-close]
+OPERATION_TYPE = CLOSE
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:0
+TIMEFRAME = 1d
+
+[exchange-extension-age_restriction]
+ENABLED = YES
+#AGE_GROUPS = "8:10:12:14:16:18:21"
diff --git a/src/testing/test_exchange_api_age_restriction-cs.conf b/src/testing/test_exchange_api_age_restriction-cs.conf
new file mode 100644
index 000000000..12195f9ba
--- /dev/null
+++ b/src/testing/test_exchange_api_age_restriction-cs.conf
@@ -0,0 +1,4 @@
+# This file is in the public domain.
+#
+@INLINE@ test_exchange_api_age_restriction.conf
+@INLINE@ coins-cs.conf
diff --git a/src/testing/test_exchange_api_age_restriction-rsa.conf b/src/testing/test_exchange_api_age_restriction-rsa.conf
new file mode 100644
index 000000000..30d75090f
--- /dev/null
+++ b/src/testing/test_exchange_api_age_restriction-rsa.conf
@@ -0,0 +1,4 @@
+# This file is in the public domain.
+#
+@INLINE@ test_exchange_api_age_restriction.conf
+@INLINE@ coins-rsa.conf
diff --git a/src/testing/test_exchange_api_age_restriction.c b/src/testing/test_exchange_api_age_restriction.c
new file mode 100644
index 000000000..5ba24a00c
--- /dev/null
+++ b/src/testing/test_exchange_api_age_restriction.c
@@ -0,0 +1,370 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/test_exchange_api_age_restriction.c
+ * @brief testcase to test exchange's age-restrictrition related HTTP API interfaces
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_testing_lib.h>
+#include <microhttpd.h>
+#include "taler_bank_service.h"
+#include "taler_fakebank_lib.h"
+#include "taler_testing_lib.h"
+#include "taler_extensions.h"
+
+/**
+ * Configuration file we use. One (big) configuration is used
+ * for the various components for this test.
+ */
+static char *config_file;
+
+/**
+ * Our credentials.
+ */
+static struct TALER_TESTING_Credentials cred;
+
+/**
+ * Some tests behave differently when using CS as we cannot
+ * reuse the coin private key for different denominations
+ * due to the derivation of it with the /csr values. Hence
+ * some tests behave differently in CS mode, hence this
+ * flag.
+ */
+static bool uses_cs;
+
+/**
+ * Execute the taler-exchange-wirewatch command with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_WIREWATCH(label) \
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, "exchange-account-2")
+
+/**
+ * Execute the taler-exchange-aggregator, closer and transfer commands with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_AGGREGATOR(label) \
+ TALER_TESTING_cmd_sleep ("sleep-before-aggregator", 2), \
+ TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_file), \
+ TALER_TESTING_cmd_exec_transfer (label "-transfer", config_file)
+
+
+/**
+ * Run wire transfer of funds from some user's account to the
+ * exchange.
+ *
+ * @param label label to use for the command.
+ * @param amount amount to transfer, i.e. "EUR:1"
+ */
+#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
+ TALER_TESTING_cmd_admin_add_incoming (label, amount, \
+ &cred.ba, \
+ cred.user42_payto)
+
+/**
+ * Main function that will tell the interpreter what commands to
+ * run.
+ *
+ * @param cls closure
+ * @param is interpreter we use to run commands
+ */
+static void
+run (void *cls,
+ struct TALER_TESTING_Interpreter *is)
+{
+ (void) cls;
+ /**
+ * Test withdrawal with age restriction. Success is expected (because the
+ * amount is below the kyc threshold ), so it MUST be
+ * called _after_ TALER_TESTING_cmd_exec_offline_sign_extensions is called,
+ * i. e. age restriction is activated in the exchange!
+ *
+ * TODO: create a test that tries to withdraw coins with age restriction but
+ * (expectedly) fails because the exchange doesn't support age restriction
+ * yet.
+ */
+ struct TALER_TESTING_Command withdraw_age[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-age",
+ "EUR:6.01"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-age",
+ "EUR:6.01",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-age"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-age"),
+ /**
+ * Withdraw EUR:5.
+ */
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-age-1",
+ "create-reserve-age",
+ "EUR:5",
+ 13,
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command spend_age[] = {
+ /**
+ * Spend the coin.
+ */
+ TALER_TESTING_cmd_deposit ("deposit-simple-age",
+ "withdraw-coin-age-1",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:4.99",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit_replay ("deposit-simple-replay-age",
+ "deposit-simple-age",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end ()
+ };
+
+
+ struct TALER_TESTING_Command refresh_age[] = {
+ /* Fill reserve with EUR:5, 1ct is for fees. */
+ CMD_TRANSFER_TO_EXCHANGE ("refresh-create-reserve-age-1",
+ "EUR:6.01"),
+ TALER_TESTING_cmd_check_bank_admin_transfer (
+ "ck-refresh-create-reserve-age-1",
+ "EUR:6.01",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "refresh-create-reserve-age-1"),
+ /**
+ * Make previous command effective.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-age-2"),
+ /**
+ * Withdraw EUR:7 with age restriction for age 13.
+ */
+ TALER_TESTING_cmd_withdraw_amount ("refresh-withdraw-coin-age-1",
+ "refresh-create-reserve-age-1",
+ "EUR:5",
+ 13,
+ MHD_HTTP_OK),
+ /* Try to partially spend (deposit) 1 EUR of the 5 EUR coin
+ * (in full) (merchant would receive EUR:0.99 due to 1 ct
+ * deposit fee)
+ */
+ TALER_TESTING_cmd_deposit ("refresh-deposit-partial-age",
+ "refresh-withdraw-coin-age-1",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:1",
+ MHD_HTTP_OK),
+ /**
+ * Melt the rest of the coin's value
+ * (EUR:4.00 = 3x EUR:1.03 + 7x EUR:0.13) */
+ TALER_TESTING_cmd_melt_double ("refresh-melt-age-1",
+ "refresh-withdraw-coin-age-1",
+ MHD_HTTP_OK,
+ NULL),
+ /**
+ * Complete (successful) melt operation, and
+ * withdraw the coins
+ */
+ TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-age-1",
+ "refresh-melt-age-1",
+ MHD_HTTP_OK),
+ /**
+ * Do it again to check idempotency
+ */
+ TALER_TESTING_cmd_refresh_reveal ("refresh-reveal-age-1-idempotency",
+ "refresh-melt-age-1",
+ MHD_HTTP_OK),
+ /**
+ * Test that /refresh/link works
+ */
+ TALER_TESTING_cmd_refresh_link ("refresh-link-age-1",
+ "refresh-reveal-age-1",
+ MHD_HTTP_OK),
+ /**
+ * Try to spend a refreshed EUR:1 coin
+ */
+ TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1a",
+ "refresh-reveal-age-1-idempotency",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:1",
+ MHD_HTTP_OK),
+ /**
+ * Try to spend a refreshed EUR:0.1 coin
+ */
+ TALER_TESTING_cmd_deposit ("refresh-deposit-refreshed-age-1b",
+ "refresh-reveal-age-1",
+ 3,
+ cred.user43_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":3}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.1",
+ MHD_HTTP_OK),
+ /* Test running a failing melt operation (same operation
+ * again must fail) */
+ TALER_TESTING_cmd_melt ("refresh-melt-failing-age",
+ "refresh-withdraw-coin-age-1",
+ MHD_HTTP_CONFLICT,
+ NULL),
+ /* Test running a failing melt operation (on a coin that
+ was itself revealed and subsequently deposited) */
+ TALER_TESTING_cmd_melt ("refresh-melt-failing-age-2",
+ "refresh-reveal-age-1",
+ MHD_HTTP_CONFLICT,
+ NULL),
+ TALER_TESTING_cmd_end ()
+ };
+
+ /**
+ * Test with age-withdraw, after kyc process has set a birthdate
+ */
+ struct TALER_TESTING_Command age_withdraw[] = {
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-kyc-1",
+ "EUR:30.02"),
+ TALER_TESTING_cmd_check_bank_admin_transfer (
+ "check-create-reserve-kyc-1",
+ "EUR:30.02",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-kyc-1"),
+ CMD_EXEC_WIREWATCH ("wirewatch-age-withdraw-1"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1-lacking-kyc",
+ "create-reserve-kyc-1",
+ "EUR:10",
+ 0, /* age restriction off */
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-withdraw",
+ "withdraw-coin-1-lacking-kyc",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-kyc",
+ "withdraw-coin-1-lacking-kyc",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1-with-kyc",
+ "create-reserve-kyc-1",
+ "EUR:10",
+ 0, /* age restriction off */
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_age_withdraw ("age-withdraw-coin-1-too-low",
+ "create-reserve-kyc-1",
+ 18, /* Too high */
+ MHD_HTTP_CONFLICT,
+ "EUR:10",
+ NULL),
+ TALER_TESTING_cmd_age_withdraw ("age-withdraw-coins-1",
+ "create-reserve-kyc-1",
+ 8,
+ MHD_HTTP_OK,
+ "EUR:10",
+ "EUR:10",
+ "EUR:5",
+ NULL),
+ TALER_TESTING_cmd_age_withdraw_reveal ("age-withdraw-coins-reveal-1",
+ "age-withdraw-coins-1",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end (),
+ };
+
+ {
+ struct TALER_TESTING_Command commands[] = {
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_oauth_with_birthdate ("oauth-service-with-birthdate",
+ "2015-00-00", /* enough for a while */
+ 6666),
+ TALER_TESTING_cmd_batch ("withdraw-age",
+ withdraw_age),
+ TALER_TESTING_cmd_batch ("spend-age",
+ spend_age),
+ TALER_TESTING_cmd_batch ("refresh-age",
+ refresh_age),
+ TALER_TESTING_cmd_batch ("age-withdraw",
+ age_withdraw),
+ /* End the suite. */
+ TALER_TESTING_cmd_end ()
+ };
+
+ TALER_TESTING_run (is,
+ commands);
+ }
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ (void) argc;
+ {
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ uses_cs = (0 == strcmp (cipher,
+ "cs"));
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api_age_restriction-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
+ }
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
+}
+
+
+/* end of test_exchange_api_age_restriction.c */
diff --git a/src/testing/test_exchange_api_age_restriction.conf b/src/testing/test_exchange_api_age_restriction.conf
new file mode 100644
index 000000000..1345fcb1a
--- /dev/null
+++ b/src/testing/test_exchange_api_age_restriction.conf
@@ -0,0 +1,119 @@
+# This file is in the public domain.
+#
+
+[PATHS]
+TALER_TEST_HOME = test_exchange_api_home/
+
+[taler]
+CURRENCY = EUR
+CURRENCY_ROUND_UNIT = EUR:0.01
+
+[auditor]
+BASE_URL = "http://localhost:8083/"
+PORT = 8083
+PUBLIC_KEY = T0XJ9QZ59YDN7QG3RE40SB2HY7W0ASR1EKF4WZDGZ1G159RSQC80
+TINY_AMOUNT = EUR:0.01
+
+[auditordb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[bank]
+HTTP_PORT = 8082
+
+[exchange]
+TERMS_ETAG = tos
+PRIVACY_ETAG = 0
+AML_THRESHOLD = EUR:10
+PORT = 8081
+MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+DB = postgres
+BASE_URL = "http://localhost:8081/"
+EXPIRE_SHARD_SIZE ="300 ms"
+EXPIRE_IDLE_SLEEP_INTERVAL ="1 s"
+
+[exchangedb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[taler-exchange-secmod-cs]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-rsa]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-eddsa]
+LOOKAHEAD_SIGN = "24 days"
+DURATION = "14 days"
+
+
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/42/taler-wire-gateway/"
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/42/taler-wire-gateway/"
+
+[exchange-account-2]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+[admin-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+
+[kyc-provider-test-oauth2]
+COST = 0
+LOGIC = oauth2
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = DUMMY
+KYC_OAUTH2_VALIDITY = forever
+KYC_OAUTH2_TOKEN_URL = http://localhost:6666/oauth/v2/token
+KYC_OAUTH2_AUTHORIZE_URL = http://localhost:6666/oauth/v2/login
+KYC_OAUTH2_INFO_URL = http://localhost:6666/api/user/me
+KYC_OAUTH2_CLIENT_ID = taler-exchange
+KYC_OAUTH2_CLIENT_SECRET = exchange-secret
+KYC_OAUTH2_POST_URL = http://example.com/
+KYC_OAUTH2_CONVERTER_HELPER = taler-exchange-kyc-oauth2-test-converter.sh
+
+[kyc-legitimization-balance-high]
+OPERATION_TYPE = BALANCE
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:20
+
+[kyc-legitimization-deposit-any]
+OPERATION_TYPE = DEPOSIT
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:10
+TIMEFRAME = 1d
+
+[kyc-legitimization-withdraw]
+OPERATION_TYPE = WITHDRAW
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:15
+TIMEFRAME = 1d
+
+[kyc-legitimization-merge]
+OPERATION_TYPE = MERGE
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:15
+TIMEFRAME = 1d
+
+
+[exchange-extension-age_restriction]
+ENABLED = YES
+#AGE_GROUPS = "8:10:12:14:16:18:21"
diff --git a/src/testing/test_exchange_api_conflicts-cs.conf b/src/testing/test_exchange_api_conflicts-cs.conf
new file mode 100644
index 000000000..c15d55490
--- /dev/null
+++ b/src/testing/test_exchange_api_conflicts-cs.conf
@@ -0,0 +1,4 @@
+# This file is in the public domain.
+#
+@INLINE@ test_exchange_api_conflicts.conf
+@INLINE@ coins-cs.conf
diff --git a/src/testing/test_exchange_api_conflicts-rsa.conf b/src/testing/test_exchange_api_conflicts-rsa.conf
new file mode 100644
index 000000000..f56111eee
--- /dev/null
+++ b/src/testing/test_exchange_api_conflicts-rsa.conf
@@ -0,0 +1,4 @@
+# This file is in the public domain.
+#
+@INLINE@ test_exchange_api_conflicts.conf
+@INLINE@ coins-rsa.conf
diff --git a/src/testing/test_exchange_api_conflicts.c b/src/testing/test_exchange_api_conflicts.c
new file mode 100644
index 000000000..070809d9d
--- /dev/null
+++ b/src/testing/test_exchange_api_conflicts.c
@@ -0,0 +1,312 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/test_exchange_api_conflicts.c
+ * @brief testcase to test exchange's handling of coin conflicts: same private
+ * keys but different denominations or age restrictions
+ * @author Özgür Kesim
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_testing_lib.h>
+#include <microhttpd.h>
+#include "taler_bank_service.h"
+#include "taler_fakebank_lib.h"
+#include "taler_testing_lib.h"
+#include "taler_extensions.h"
+
+/**
+ * Configuration file we use. One (big) configuration is used
+ * for the various components for this test.
+ */
+static char *config_file;
+
+/**
+ * Our credentials.
+ */
+static struct TALER_TESTING_Credentials cred;
+
+/**
+ * Some tests behave differently when using CS as we cannot
+ * reuse the coin private key for different denominations
+ * due to the derivation of it with the /csr values. Hence
+ * some tests behave differently in CS mode, hence this
+ * flag.
+ */
+static bool uses_cs;
+
+/**
+ * Execute the taler-exchange-wirewatch command with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_WIREWATCH(label) \
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, \
+ "exchange-account-2")
+
+/**
+ * Execute the taler-exchange-aggregator, closer and transfer commands with
+ * our configuration file.
+ *
+ * @param label label to use for the command.
+ */
+#define CMD_EXEC_AGGREGATOR(label) \
+ TALER_TESTING_cmd_sleep ("sleep-before-aggregator", 2), \
+ TALER_TESTING_cmd_exec_aggregator (label "-aggregator", config_file), \
+ TALER_TESTING_cmd_exec_transfer (label "-transfer", config_file)
+
+
+/**
+ * Run wire transfer of funds from some user's account to the
+ * exchange.
+ *
+ * @param label label to use for the command.
+ * @param amount amount to transfer, i.e. "EUR:1"
+ */
+#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
+ TALER_TESTING_cmd_admin_add_incoming (label, amount, \
+ &cred.ba, \
+ cred.user42_payto)
+
+/**
+ * Main function that will tell the interpreter what commands to
+ * run.
+ *
+ * @param cls closure
+ * @param is interpreter we use to run commands
+ */
+static void
+run (void *cls,
+ struct TALER_TESTING_Interpreter *is)
+{
+ (void) cls;
+ /**
+ * Test withdrawal with conflicting coins.
+ */
+ struct TALER_TESTING_Command withdraw_conflict_denom[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-denom",
+ "EUR:21.14"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-denom",
+ "EUR:21.14",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-denom"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-conflict-denom"),
+ /**
+ * Withdraw EUR:0.10, EUR:1, EUR:5, EUR:15, but using the same private key each time.
+ */
+ TALER_TESTING_cmd_batch_withdraw_with_conflict ("withdraw-coin-denom-1",
+ "create-reserve-denom",
+ true,
+ 0, /* age */
+ MHD_HTTP_OK,
+ "EUR:1",
+ "EUR:5",
+ "EUR:10",
+ "EUR:0.10",
+ NULL),
+
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command spend_conflict_denom[] = {
+ /**
+ * Spend the coin.
+ */
+ TALER_TESTING_cmd_deposit ("deposit-denom",
+ "withdraw-coin-denom-1",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.99",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit ("deposit-denom-conflict",
+ "withdraw-coin-denom-1",
+ 1,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:4.99",
+ /* Note: For CS, even though the master secret is the
+ * same for each coin, their private keys differ due
+ * to the random choice of the nonce by the exchange. */
+ uses_cs ? MHD_HTTP_OK : MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_deposit ("deposit-denom-conflict-2",
+ "withdraw-coin-denom-1",
+ 2,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:9.99",
+ /* Note: For CS, even though the master secret is the
+ * same for each coin, their private keys differ due
+ * to the random choice of the nonce by the exchange. */
+ uses_cs ? MHD_HTTP_OK : MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_deposit ("deposit-denom-conflict-3",
+ "withdraw-coin-denom-1",
+ 3,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.09",
+ /* Note: For CS, even though the master secret is the
+ * same for each coin, their private keys differ due
+ * to the random choice of the nonce by the exchange. */
+ uses_cs ? MHD_HTTP_OK : MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command withdraw_conflict_age[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-age",
+ "EUR:3.03"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-age",
+ "EUR:3.03",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-age"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("wirewatch-conflict-age"),
+ /**
+ * Withdraw EUR:1, EUR:5, EUR:15, but using the same private key each time.
+ */
+ TALER_TESTING_cmd_batch_withdraw_with_conflict ("withdraw-coin-age-1",
+ "create-reserve-age",
+ true,
+ 10, /* age */
+ MHD_HTTP_OK,
+ "EUR:1",
+ "EUR:1",
+ "EUR:1",
+ NULL),
+
+ TALER_TESTING_cmd_end ()
+ };
+
+ struct TALER_TESTING_Command spend_conflict_age[] = {
+ /**
+ * Spend the coin.
+ */
+ TALER_TESTING_cmd_deposit ("deposit-age",
+ "withdraw-coin-age-1",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.99",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit ("deposit-age-conflict",
+ "withdraw-coin-age-1",
+ 1,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.99",
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_deposit ("deposit-age-conflict-2",
+ "withdraw-coin-age-1",
+ 2,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:0.99",
+ MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_end ()
+ };
+
+
+ {
+ struct TALER_TESTING_Command commands[] = {
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_batch ("withdraw-conflict-denom",
+ withdraw_conflict_denom),
+ TALER_TESTING_cmd_batch ("spend-conflict-denom",
+ spend_conflict_denom),
+ TALER_TESTING_cmd_batch ("withdraw-conflict-age",
+ withdraw_conflict_age),
+ TALER_TESTING_cmd_batch ("spend-conflict-age",
+ spend_conflict_age),
+ /* End the suite. */
+ TALER_TESTING_cmd_end ()
+ };
+
+ TALER_TESTING_run (is,
+ commands);
+ }
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ (void) argc;
+ {
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ uses_cs = (0 == strcmp (cipher,
+ "cs"));
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api_conflicts-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
+ }
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
+}
+
+
+/* end of test_exchange_api_conflicts.c */
diff --git a/src/testing/test_exchange_api_conflicts.conf b/src/testing/test_exchange_api_conflicts.conf
new file mode 100644
index 000000000..d04379f05
--- /dev/null
+++ b/src/testing/test_exchange_api_conflicts.conf
@@ -0,0 +1,81 @@
+# This file is in the public domain.
+#
+
+[PATHS]
+TALER_TEST_HOME = test_exchange_api_home/
+
+[taler]
+CURRENCY = EUR
+CURRENCY_ROUND_UNIT = EUR:0.01
+
+[auditor]
+BASE_URL = "http://localhost:8083/"
+PORT = 8083
+PUBLIC_KEY = T0XJ9QZ59YDN7QG3RE40SB2HY7W0ASR1EKF4WZDGZ1G159RSQC80
+TINY_AMOUNT = EUR:0.01
+
+[auditordb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[bank]
+HTTP_PORT = 8082
+
+[exchange]
+TERMS_ETAG = tos
+PRIVACY_ETAG = 0
+PORT = 8081
+AML_THRESHOLD = "EUR:99999999"
+MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+DB = postgres
+BASE_URL = "http://localhost:8081/"
+EXPIRE_SHARD_SIZE ="300 ms"
+EXPIRE_IDLE_SLEEP_INTERVAL ="1 s"
+
+[exchangedb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[taler-exchange-secmod-cs]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-rsa]
+LOOKAHEAD_SIGN = "24 days"
+
+[taler-exchange-secmod-eddsa]
+LOOKAHEAD_SIGN = "24 days"
+DURATION = "14 days"
+
+
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/42/taler-wire-gateway/"
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_AUTH_METHOD = none
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/42/taler-wire-gateway/"
+
+[exchange-account-2]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+[admin-accountcredentials-2]
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+WIRE_GATEWAY_URL = "http://localhost:8082/accounts/2/taler-wire-gateway/"
+
+
+[exchange-extension-age_restriction]
+ENABLED = YES
+#AGE_GROUPS = "8:10:12:14:16:18:21"
diff --git a/src/testing/test_exchange_api_home/.config/taler/account-2.json b/src/testing/test_exchange_api_home/.config/taler/account-2.json
deleted file mode 100644
index 21a7500b4..000000000
--- a/src/testing/test_exchange_api_home/.config/taler/account-2.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "payto_uri": "payto://x-taler-bank/localhost/2",
- "master_sig": "HEWC1XDS0QZ53YQR451VRKD4N968NXWGZXS30HJ59MJ0PESACK1ZYPYCAT15P08WD58C7D7F6EVN26D59JKA75XEBDQCM8VYFETK82R"
-} \ No newline at end of file
diff --git a/src/testing/test_exchange_api_home/.local/share/taler/auditor/offline-keys/auditor.priv b/src/testing/test_exchange_api_home/.local/share/taler/auditor/offline-keys/auditor.priv
new file mode 100644
index 000000000..5b1c8fa05
--- /dev/null
+++ b/src/testing/test_exchange_api_home/.local/share/taler/auditor/offline-keys/auditor.priv
Binary files differ
diff --git a/src/testing/test_exchange_api_home/.local/share/taler/exchange-offline/master.priv b/src/testing/test_exchange_api_home/.local/share/taler/exchange-offline/master.priv
index 394926938..391b6ea73 100644
--- a/src/testing/test_exchange_api_home/.local/share/taler/exchange-offline/master.priv
+++ b/src/testing/test_exchange_api_home/.local/share/taler/exchange-offline/master.priv
Binary files differ
diff --git a/src/testing/test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv b/src/testing/test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/testing/test_exchange_api_home/.local/share/taler/exchange/offline-keys/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv b/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv
new file mode 100644
index 000000000..7e712e483
--- /dev/null
+++ b/src/testing/test_exchange_api_home/taler/auditor/offline-keys/auditor.priv
@@ -0,0 +1 @@
+G,U{~#r-H  \ No newline at end of file
diff --git a/src/testing/test_exchange_api_keys_cherry_picking-cs.conf b/src/testing/test_exchange_api_keys_cherry_picking-cs.conf
index 751850cb2..d25ef3c00 100644
--- a/src/testing/test_exchange_api_keys_cherry_picking-cs.conf
+++ b/src/testing/test_exchange_api_keys_cherry_picking-cs.conf
@@ -1,89 +1,9 @@
# This file is in the public domain.
#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_keys_cherry_picking_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-# Persistent data storage
-TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
-
-# Configuration files
-TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
-
-# Cached data, no big deal if lost
-TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
+@INLINE@ test_exchange_api_keys_cherry_picking.conf
[taler-exchange-secmod-cs]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-
-[exchange]
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[exchange-account-1]
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9082/42/"
-
-[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:9082/2/"
-
-# Authentication information for basic authentication
-TALER_BANK_AUTH_METHOD = "basic"
-USERNAME = user
-PASSWORD = pass
-
-[bank]
-HTTP_PORT=8082
-
-[taler-exchange-secmod-cs]
-OVERLAP_DURATION = 1 s
-LOOKAHEAD_SIGN = 20 s
-
-[taler-exchange-secmod-eddsa]
OVERLAP_DURATION = 1 s
-DURATION = 30 s
LOOKAHEAD_SIGN = 20 s
[coin_eur_1]
diff --git a/src/testing/test_exchange_api_keys_cherry_picking-rsa.conf b/src/testing/test_exchange_api_keys_cherry_picking-rsa.conf
index b9ad30549..672639b3f 100644
--- a/src/testing/test_exchange_api_keys_cherry_picking-rsa.conf
+++ b/src/testing/test_exchange_api_keys_cherry_picking-rsa.conf
@@ -1,89 +1,9 @@
# This file is in the public domain.
#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_keys_cherry_picking_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-# Persistent data storage
-TALER_DATA_HOME = $TALER_HOME/.local/share/taler/
-
-# Configuration files
-TALER_CONFIG_HOME = $TALER_HOME/.config/taler/
-
-# Cached data, no big deal if lost
-TALER_CACHE_HOME = $TALER_HOME/.cache/taler/
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
+@INLINE@ test_exchange_api_keys_cherry_picking.conf
[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-
-[exchange]
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[exchange-account-1]
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9082/42/"
-
-[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:9082/2/"
-
-# Authentication information for basic authentication
-TALER_BANK_AUTH_METHOD = "basic"
-USERNAME = user
-PASSWORD = pass
-
-[bank]
-HTTP_PORT=8082
-
-[taler-exchange-secmod-rsa]
-OVERLAP_DURATION = 1 s
-LOOKAHEAD_SIGN = 20 s
-
-[taler-exchange-secmod-eddsa]
OVERLAP_DURATION = 1 s
-DURATION = 30 s
LOOKAHEAD_SIGN = 20 s
[coin_eur_1]
diff --git a/src/testing/test_exchange_api_keys_cherry_picking.c b/src/testing/test_exchange_api_keys_cherry_picking.c
index 4ad2d7207..2919ea8d5 100644
--- a/src/testing/test_exchange_api_keys_cherry_picking.c
+++ b/src/testing/test_exchange_api_keys_cherry_picking.c
@@ -43,9 +43,9 @@ lished
static char *config_file;
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
+static struct TALER_TESTING_Credentials cred;
/**
@@ -59,45 +59,27 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command commands[] = {
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("initial-/keys",
- 1),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_sleep ("sleep",
6 /* seconds */),
- TALER_TESTING_cmd_check_keys ("check-keys-1",
- 2 /* generation */),
- TALER_TESTING_cmd_check_keys_with_last_denom ("check-keys-2",
- 3 /* generation */,
- "check-keys-1"),
- TALER_TESTING_cmd_serialize_keys ("serialize-keys"),
- TALER_TESTING_cmd_connect_with_state ("reconnect-with-state",
- "serialize-keys"),
- /**
- * Make sure we have the same keys situation as
- * it was before the serialization.
- */
- TALER_TESTING_cmd_check_keys ("check-keys-after-deserialization",
- 4),
- /**
- * Use one of the deserialized keys.
- */
- TALER_TESTING_cmd_wire ("wire-with-serialized-keys",
- "x-taler-bank",
- NULL,
- MHD_HTTP_OK),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-1",
+ cred.cfg,
+ "get-exchange",
+ true,
+ true),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-2",
+ cred.cfg,
+ "get-exchange-1",
+ true,
+ true),
TALER_TESTING_cmd_end ()
};
@@ -111,50 +93,25 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "DEBUG",
- NULL);
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_exchange_api_keys_cherry_picking-%s.conf",
- cipher);
- GNUNET_free (cipher);
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api_keys_cherry_picking-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_exchange_api_keys_cherry_picking.conf b/src/testing/test_exchange_api_keys_cherry_picking.conf
new file mode 100644
index 000000000..142242424
--- /dev/null
+++ b/src/testing/test_exchange_api_keys_cherry_picking.conf
@@ -0,0 +1,58 @@
+# This file is in the public domain.
+#
+[PATHS]
+# Persistent data storage for the testcase
+TALER_TEST_HOME = test_exchange_api_keys_cherry_picking_home/
+
+[taler]
+CURRENCY = EUR
+CURRENCY_ROUND_UNIT = EUR:0.01
+
+[taler-exchange-secmod-eddsa]
+OVERLAP_DURATION = 1 s
+DURATION = 30 s
+LOOKAHEAD_SIGN = 20 s
+
+[exchange]
+AML_THRESHOLD = EUR:1000000
+PORT = 8081
+MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
+DB = postgres
+BASE_URL = "http://localhost:8081/"
+
+[exchangedb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[auditordb-postgres]
+CONFIG = "postgres:///talercheck"
+
+[exchange-account-1]
+PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-1]
+WIRE_GATEWAY_URL = "http://localhost:9082/accounts/42/taler-wire-gateway/"
+
+[admin-accountcredentials-1]
+WIRE_GATEWAY_URL = "http://localhost:9082/accounts/42/taler-wire-gateway/"
+
+[exchange-account-2]
+PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
+ENABLE_DEBIT = YES
+ENABLE_CREDIT = YES
+
+[exchange-accountcredentials-2]
+WIRE_GATEWAY_URL = "http://localhost:9082/accounts/2/taler-wire-gateway/"
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+
+[admin-accountcredentials-2]
+WIRE_GATEWAY_URL = "http://localhost:9082/accounts/2/taler-wire-gateway/"
+WIRE_GATEWAY_AUTH_METHOD = basic
+USERNAME = Exchange
+PASSWORD = x
+
+[bank]
+HTTP_PORT=8082
diff --git a/src/testing/test_exchange_api_keys_cherry_picking_home/.config/taler/x-taler-bank.json b/src/testing/test_exchange_api_keys_cherry_picking_home/.config/taler/x-taler-bank.json
deleted file mode 100644
index 21a7500b4..000000000
--- a/src/testing/test_exchange_api_keys_cherry_picking_home/.config/taler/x-taler-bank.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "payto_uri": "payto://x-taler-bank/localhost/2",
- "master_sig": "HEWC1XDS0QZ53YQR451VRKD4N968NXWGZXS30HJ59MJ0PESACK1ZYPYCAT15P08WD58C7D7F6EVN26D59JKA75XEBDQCM8VYFETK82R"
-} \ No newline at end of file
diff --git a/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange-offline/master.priv b/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange-offline/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange-offline/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange/offline-keys/master.priv b/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange/offline-keys/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/testing/test_exchange_api_keys_cherry_picking_home/.local/share/taler/exchange/offline-keys/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/testing/test_exchange_api_overlapping_keys_bug.c b/src/testing/test_exchange_api_overlapping_keys_bug.c
index 1314bdf54..33b547a37 100644
--- a/src/testing/test_exchange_api_overlapping_keys_bug.c
+++ b/src/testing/test_exchange_api_overlapping_keys_bug.c
@@ -44,9 +44,9 @@
static char *config_file;
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
+static struct TALER_TESTING_Credentials cred;
/**
@@ -60,23 +60,28 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command commands[] = {
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
- TALER_TESTING_cmd_check_keys ("first-download",
- 1),
- /* Causes GET /keys?last_denom_issue=0 */
- TALER_TESTING_cmd_check_keys_with_last_denom ("second-download",
- 1,
- "zero"),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-1",
+ cred.cfg,
+ "get-exchange",
+ true,
+ true),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-2",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_end ()
};
@@ -90,50 +95,25 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "DEBUG",
- NULL);
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_exchange_api_keys_cherry_picking-%s.conf",
- cipher);
- GNUNET_free (cipher);
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api_keys_cherry_picking-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_exchange_api_revocation.c b/src/testing/test_exchange_api_revocation.c
index 33a92551d..92e36a30a 100644
--- a/src/testing/test_exchange_api_revocation.c
+++ b/src/testing/test_exchange_api_revocation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014--2020 Taler Systems SA
+ Copyright (C) 2014--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -42,14 +42,9 @@
static char *config_file;
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
+static struct TALER_TESTING_Credentials cred;
/**
@@ -63,35 +58,37 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command revocation[] = {
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
/**
* Fill reserve with EUR:10.02, as withdraw fee is 1 ct per
* config.
*/
TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
"EUR:10.02",
- &bc.exchange_auth,
- bc.user42_payto),
+ &cred.ba,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
"EUR:10.02",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-1"),
/**
* Run wire-watch to trigger the reserve creation.
*/
- TALER_TESTING_cmd_exec_wirewatch ("wirewatch-4",
- config_file),
+ TALER_TESTING_cmd_exec_wirewatch2 ("wirewatch-4",
+ config_file,
+ "exchange-account-2"),
/* Withdraw a 5 EUR coin, at fee of 1 ct */
TALER_TESTING_cmd_withdraw_amount ("withdraw-revocation-coin-1",
"create-reserve-1",
@@ -109,7 +106,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-partial",
"withdraw-revocation-coin-1",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:1",
@@ -118,7 +115,7 @@ run (void *cls,
TALER_TESTING_cmd_deposit ("deposit-full",
"withdraw-revocation-coin-2",
0,
- bc.user42_payto,
+ cred.user42_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -241,9 +238,8 @@ run (void *cls,
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- revocation,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ revocation);
}
@@ -251,56 +247,25 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_exchange_api-%s.conf",
- cipher);
- GNUNET_free (cipher);
- /* Check fakebank port is available and get config */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_exchange_api_twisted-cs.conf b/src/testing/test_exchange_api_twisted-cs.conf
index abb88a742..ae953e732 100644
--- a/src/testing/test_exchange_api_twisted-cs.conf
+++ b/src/testing/test_exchange_api_twisted-cs.conf
@@ -1,150 +1,4 @@
# This file is in the public domain.
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
+@INLINE@ test_exchange_api-cs.conf
+@INLINE@ test_exchange_api-twisted.conf
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[exchange]
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange ('S PROXY). This URL is where the
-# twister listens at, so that it will be able to get all the
-# connection addressed to the exchange. In fact, the presence
-# of the twister is 100% transparent to the test case, as it
-# only seeks the exchange/BASE_URL URL to connect to the exchange.
-BASE_URL = "http://localhost:8888/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-PORT = 8083
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9081/42/"
-WIRE_GATEWAY_AUTH_METHOD = NONE
-
-[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
-WIRE_GATEWAY_AUTH_METHOD = BASIC
-USERNAME = user
-PASSWORD = pass
-
-[bank]
-HTTP_PORT = 8082
-
-[twister]
-# HTTP listen port for twister
-HTTP_PORT = 8888
-SERVE = tcp
-
-# HTTP Destination for twister. The test-Webserver needs
-# to listen on the port used here. Note: no trailing '/'!
-DESTINATION_BASE_URL = "http://localhost:8081"
-
-# Control port for TCP
-# PORT = 8889
-HOSTNAME = localhost
-ACCEPT_FROM = 127.0.0.1;
-ACCEPT_FROM6 = ::1;
-
-# Control port for UNIX
-UNIXPATH = /tmp/taler-service-twister.sock
-UNIX_MATCH_UID = NO
-UNIX_MATCH_GID = YES
-
-# Launching of twister by ARM
-# BINARY = taler-service-twister
-# AUTOSTART = NO
-# FORCESTART = NO
-
-
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
diff --git a/src/testing/test_exchange_api_twisted-rsa.conf b/src/testing/test_exchange_api_twisted-rsa.conf
index 847d9e1ce..3fd8f4ff1 100644
--- a/src/testing/test_exchange_api_twisted-rsa.conf
+++ b/src/testing/test_exchange_api_twisted-rsa.conf
@@ -1,156 +1,4 @@
# This file is in the public domain.
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
+@INLINE@ test_exchange_api-rsa.conf
+@INLINE@ test_exchange_api-twisted.conf
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[exchange]
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange ('S PROXY). This URL is where the
-# twister listens at, so that it will be able to get all the
-# connection addressed to the exchange. In fact, the presence
-# of the twister is 100% transparent to the test case, as it
-# only seeks the exchange/BASE_URL URL to connect to the exchange.
-BASE_URL = "http://localhost:8888/"
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-PORT = 8083
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:9081/42/"
-WIRE_GATEWAY_AUTH_METHOD = NONE
-
-[exchange-account-2]
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
-WIRE_GATEWAY_AUTH_METHOD = BASIC
-USERNAME = user
-PASSWORD = pass
-
-[bank]
-HTTP_PORT = 8082
-
-[twister]
-# HTTP listen port for twister
-HTTP_PORT = 8888
-SERVE = tcp
-
-# HTTP Destination for twister. The test-Webserver needs
-# to listen on the port used here. Note: no trailing '/'!
-DESTINATION_BASE_URL = "http://localhost:8081"
-
-# Control port for TCP
-# PORT = 8889
-HOSTNAME = localhost
-ACCEPT_FROM = 127.0.0.1;
-ACCEPT_FROM6 = ::1;
-
-# Control port for UNIX
-UNIXPATH = /tmp/taler-service-twister.sock
-UNIX_MATCH_UID = NO
-UNIX_MATCH_GID = YES
-
-# Launching of twister by ARM
-# BINARY = taler-service-twister
-# AUTOSTART = NO
-# FORCESTART = NO
-
-
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-CIPHER = RSA
-
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-CIPHER = RSA
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-CIPHER = RSA
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-CIPHER = RSA
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-rsa_keysize = 1024
-CIPHER = RSA
diff --git a/src/testing/test_exchange_api_twisted.c b/src/testing/test_exchange_api_twisted.c
index 0fb35b45d..75ffe1f15 100644
--- a/src/testing/test_exchange_api_twisted.c
+++ b/src/testing/test_exchange_api_twisted.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -44,19 +44,14 @@
static char *config_file;
/**
- * (real) Twister URL. Used at startup time to check if it runs.
+ * Our credentials.
*/
-static char *twister_url;
+static struct TALER_TESTING_Credentials cred;
/**
- * Exchange configuration data.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
+ * (real) Twister URL. Used at startup time to check if it runs.
*/
-static struct TALER_TESTING_BankConfiguration bc;
+static char *twister_url;
/**
* Twister process.
@@ -73,8 +68,9 @@ static struct GNUNET_OS_Process *twisterd;
static struct TALER_TESTING_Command
CMD_EXEC_WIREWATCH (const char *label)
{
- return TALER_TESTING_cmd_exec_wirewatch (label,
- config_file);
+ return TALER_TESTING_cmd_exec_wirewatch2 (label,
+ config_file,
+ "exchange-account-2");
}
@@ -92,8 +88,8 @@ CMD_TRANSFER_TO_EXCHANGE (const char *label,
{
return TALER_TESTING_cmd_admin_add_incoming (label,
amount,
- &bc.exchange_auth,
- bc.user42_payto);
+ &cred.ba,
+ cred.user42_payto);
}
@@ -112,8 +108,9 @@ run (void *cls,
* response from a refresh-reveal operation.
*/
struct TALER_TESTING_Command refresh_409_conflict[] = {
- CMD_TRANSFER_TO_EXCHANGE ("refresh-create-reserve",
- "EUR:5.01"),
+ CMD_TRANSFER_TO_EXCHANGE (
+ "refresh-create-reserve",
+ "EUR:5.01"),
/**
* Make previous command effective.
*/
@@ -121,34 +118,38 @@ run (void *cls,
/**
* Withdraw EUR:5.
*/
- TALER_TESTING_cmd_withdraw_amount ("refresh-withdraw-coin",
- "refresh-create-reserve",
- "EUR:5",
- 0, /* age restriction off */
- MHD_HTTP_OK),
- TALER_TESTING_cmd_deposit ("refresh-deposit-partial",
- "refresh-withdraw-coin",
- 0,
- bc.user42_payto,
- "{\"items\":[{\"name\":\"ice cream\",\
- \"value\":\"EUR:1\"}]}",
- GNUNET_TIME_UNIT_ZERO,
- "EUR:1",
- MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount (
+ "refresh-withdraw-coin",
+ "refresh-create-reserve",
+ "EUR:5",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit (
+ "refresh-deposit-partial",
+ "refresh-withdraw-coin",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
+ GNUNET_TIME_UNIT_ZERO,
+ "EUR:1",
+ MHD_HTTP_OK),
/**
* Melt the rest of the coin's value
* (EUR:4.00 = 3x EUR:1.03 + 7x EUR:0.13) */
- TALER_TESTING_cmd_melt ("refresh-melt",
- "refresh-withdraw-coin",
- MHD_HTTP_OK,
- NULL),
+ TALER_TESTING_cmd_melt (
+ "refresh-melt",
+ "refresh-withdraw-coin",
+ MHD_HTTP_OK,
+ NULL),
/* Trigger 409 Conflict. */
- TALER_TESTING_cmd_flip_upload ("flip-upload",
- config_file,
- "transfer_privs.0"),
- TALER_TESTING_cmd_refresh_reveal ("refresh-(flipped-)reveal",
- "refresh-melt",
- MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_flip_upload (
+ "flip-upload",
+ config_file,
+ "transfer_privs.0"),
+ TALER_TESTING_cmd_refresh_reveal (
+ "refresh-(flipped-)reveal",
+ "refresh-melt",
+ MHD_HTTP_CONFLICT),
TALER_TESTING_cmd_end ()
};
@@ -159,23 +160,25 @@ run (void *cls,
* lib test suite.
*/
struct TALER_TESTING_Command refund[] = {
- CMD_TRANSFER_TO_EXCHANGE ("create-reserve-r1",
- "EUR:5.01"),
+ CMD_TRANSFER_TO_EXCHANGE (
+ "create-reserve-r1",
+ "EUR:5.01"),
CMD_EXEC_WIREWATCH ("wirewatch-r1"),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-r1",
- "create-reserve-r1",
- "EUR:5",
- 0, /* age restriction off */
- MHD_HTTP_OK),
- TALER_TESTING_cmd_deposit ("deposit-refund-1",
- "withdraw-coin-r1",
- 0,
- bc.user42_payto,
- "{\"items\":[{\"name\":\"ice cream\","
- "\"value\":\"EUR:5\"}]}",
- GNUNET_TIME_UNIT_MINUTES,
- "EUR:5",
- MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount (
+ "withdraw-coin-r1",
+ "create-reserve-r1",
+ "EUR:5",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_deposit (
+ "deposit-refund-1",
+ "withdraw-coin-r1",
+ 0,
+ cred.user42_payto,
+ "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
+ GNUNET_TIME_UNIT_MINUTES,
+ "EUR:5",
+ MHD_HTTP_OK),
TALER_TESTING_cmd_refund ("refund-currency-mismatch",
MHD_HTTP_BAD_REQUEST,
"USD:5",
@@ -190,18 +193,18 @@ run (void *cls,
/* This next deposit CMD is only used to provide a
* good merchant signature to the next (failing) refund
* operations. */
- TALER_TESTING_cmd_deposit ("deposit-refund-to-fail",
- "withdraw-coin-r1",
- 0, /* coin index. */
- bc.user42_payto,
- /* This parameter will make any comparison about
- h_contract_terms fail, when /refund will be handled.
- So in other words, this is h_contract mismatch. */
- "{\"items\":[{\"name\":\"ice skate\","
- "\"value\":\"EUR:5\"}]}",
- GNUNET_TIME_UNIT_MINUTES,
- "EUR:5",
- MHD_HTTP_CONFLICT),
+ TALER_TESTING_cmd_deposit (
+ "deposit-refund-to-fail",
+ "withdraw-coin-r1",
+ 0, /* coin index. */
+ cred.user42_payto,
+ /* This parameter will make any comparison about
+ h_contract_terms fail, when /refund will be handled.
+ So in other words, this is h_contract mismatch. */
+ "{\"items\":[{\"name\":\"ice skate\",\"value\":\"EUR:5\"}]}",
+ GNUNET_TIME_UNIT_MINUTES,
+ "EUR:5",
+ MHD_HTTP_CONFLICT),
TALER_TESTING_cmd_refund ("refund-deposit-not-found",
MHD_HTTP_NOT_FOUND,
"EUR:5",
@@ -219,10 +222,11 @@ run (void *cls,
* are out of date.
*/
struct TALER_TESTING_Command expired_keys[] = {
- TALER_TESTING_cmd_modify_header_dl ("modify-expiration",
- config_file,
- MHD_HTTP_HEADER_EXPIRES,
- "Wed, 19 Jan 586524 08:01:49 GMT"),
+ TALER_TESTING_cmd_modify_header_dl (
+ "modify-expiration",
+ config_file,
+ MHD_HTTP_HEADER_EXPIRES,
+ "Wed, 19 Jan 586524 08:01:49 GMT"),
TALER_TESTING_cmd_check_keys_pull_all_keys (
"check-keys-expiration-0",
2),
@@ -232,28 +236,35 @@ run (void *cls,
CMD_TRANSFER_TO_EXCHANGE ("create-reserve-r2",
"EUR:55.01"),
CMD_EXEC_WIREWATCH ("wirewatch-r2"),
- TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-r2",
- "create-reserve-r2",
- "EUR:5",
- 0, /* age restriction off */
- MHD_HTTP_OK),
+ TALER_TESTING_cmd_withdraw_amount (
+ "withdraw-coin-r2",
+ "create-reserve-r2",
+ "EUR:5",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
#endif
struct TALER_TESTING_Command commands[] = {
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
- TALER_TESTING_cmd_batch ("refresh-reveal-409-conflict",
- refresh_409_conflict),
- TALER_TESTING_cmd_batch ("refund",
- refund),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_batch (
+ "refresh-reveal-409-conflict",
+ refresh_409_conflict),
+ TALER_TESTING_cmd_batch (
+ "refund",
+ refund),
#if 0
TALER_TESTING_cmd_batch ("expired-keys",
expired_keys),
@@ -262,16 +273,15 @@ run (void *cls,
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
/**
* Kill, wait, and destroy convenience function.
*
- * @param process process to purge.
+ * @param[in] process process to purge.
*/
static void
purge_process (struct GNUNET_OS_Process *process)
@@ -287,57 +297,37 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
int ret;
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "DEBUG",
- NULL);
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_exchange_api_twisted-%s.conf",
- cipher);
- GNUNET_free (cipher);
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- if (NULL == (twister_url = TALER_TWISTER_prepare_twister
- (config_file)))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (NULL == (twisterd = TALER_TWISTER_run_twister (config_file)))
- return 77;
- ret = TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file);
- purge_process (twisterd);
- GNUNET_free (twister_url);
+ char *cipher;
- if (GNUNET_OK != ret)
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api_twisted-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ /* FIXME: introduce commands for twister! */
+ twister_url = TALER_TWISTER_prepare_twister (config_file);
+ if (NULL == twister_url)
+ return 77;
+ twisterd = TALER_TWISTER_run_twister (config_file);
+ if (NULL == twisterd)
+ return 77;
+ ret = TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
+ purge_process (twisterd);
+ GNUNET_free (twister_url);
+ return ret;
}
diff --git a/src/testing/test_exchange_management_api.c b/src/testing/test_exchange_management_api.c
index 2bf0af3bd..7cce61b55 100644
--- a/src/testing/test_exchange_management_api.c
+++ b/src/testing/test_exchange_management_api.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020-2022 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -35,16 +35,10 @@
*/
static char *config_file;
-
-/**
- * Exchange configuration data.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
/**
- * Bank configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_BankConfiguration bc;
+static struct TALER_TESTING_Credentials cred;
/**
@@ -58,10 +52,21 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command commands[] = {
- /* this currently fails, because the
- auditor is already added by the test setup logic */
- TALER_TESTING_cmd_auditor_del ("del-auditor-NOT-FOUND",
- MHD_HTTP_NOT_FOUND,
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-u", "exchange-account-2",
+ "-ae",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
+ TALER_TESTING_cmd_get_auditor ("get-auditor",
+ cred.cfg,
+ true),
+ TALER_TESTING_cmd_auditor_del ("del-auditor-FROM-SETUP",
+ MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_auditor_add ("add-auditor-BAD-SIG",
MHD_HTTP_FORBIDDEN,
@@ -85,35 +90,30 @@ run (void *cls,
"foo-method",
"EUR:1",
"EUR:5",
- "EUR:3",
MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_set_wire_fee ("set-fee-conflicting",
"foo-method",
"EUR:1",
"EUR:1",
- "EUR:3",
MHD_HTTP_CONFLICT,
false),
TALER_TESTING_cmd_set_wire_fee ("set-fee-bad-signature",
"bar-method",
"EUR:1",
"EUR:1",
- "EUR:3",
MHD_HTTP_FORBIDDEN,
true),
TALER_TESTING_cmd_set_wire_fee ("set-fee-other-method",
"bar-method",
"EUR:1",
"EUR:1",
- "EUR:3",
MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_set_wire_fee ("set-fee-idempotent",
"bar-method",
"EUR:1",
"EUR:1",
- "EUR:3",
MHD_HTTP_NO_CONTENT,
false),
TALER_TESTING_cmd_wire_add ("add-wire-account",
@@ -146,15 +146,22 @@ run (void *cls,
false),
TALER_TESTING_cmd_exec_offline_sign_keys ("download-future-keys",
config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-1",
+ cred.cfg,
+ "get-exchange",
+ true,
+ true),
+ TALER_TESTING_cmd_get_exchange ("get-exchange-2",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_end ()
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
@@ -162,56 +169,25 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
- /* Check fakebank port is available and get config */
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- GNUNET_asprintf (&config_file,
- "test_exchange_api-%s.conf",
- cipher);
- GNUNET_free (cipher);
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES, /* reset DB? */
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_exchange_p2p.c b/src/testing/test_exchange_p2p.c
index ba6d5bbf2..093730ff2 100644
--- a/src/testing/test_exchange_p2p.c
+++ b/src/testing/test_exchange_p2p.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014--2022 Taler Systems SA
+ Copyright (C) 2014--2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -20,13 +20,9 @@
* @file testing/test_exchange_p2p.c
* @brief testcase to test exchange's P2P payments
* @author Christian Grothoff
- *
- * TODO:
- * - Test setup with KYC where purse merge is only
- * allowed for reserves with KYC completed.
- * - Test purse creation with reserve purse quota
*/
#include "platform.h"
+#include "taler_attributes.h"
#include "taler_util.h"
#include "taler_signatures.h"
#include "taler_exchange_service.h"
@@ -46,18 +42,13 @@
static char *config_file;
/**
- * Exchange configuration data.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_BankConfiguration bc;
+struct TALER_TESTING_Credentials cred;
/**
* Some tests behave differently when using CS as we cannot
- * re-use the coin private key for different denominations
+ * reuse the coin private key for different denominations
* due to the derivation of it with the /csr values. Hence
* some tests behave differently in CS mode, hence this
* flag.
@@ -71,7 +62,7 @@ static bool uses_cs;
* @param label label to use for the command.
*/
#define CMD_EXEC_WIREWATCH(label) \
- TALER_TESTING_cmd_exec_wirewatch (label, config_file)
+ TALER_TESTING_cmd_exec_wirewatch2 (label, config_file, "exchange-account-2")
/**
* Execute the taler-exchange-aggregator, closer and transfer commands with
@@ -94,8 +85,8 @@ static bool uses_cs;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
- &bc.exchange_auth, \
- bc.user42_payto)
+ &cred.ba, \
+ cred.user42_payto)
/**
* Main function that will tell the interpreter what commands to
@@ -126,13 +117,13 @@ run (void *cls,
MHD_HTTP_OK),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
"EUR:5.04",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-1"),
TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-2",
"EUR:5.01",
- bc.user42_payto,
- bc.exchange_payto,
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-2"),
/**
* Make a reserve exist, according to the previous
@@ -161,7 +152,7 @@ run (void *cls,
};
struct TALER_TESTING_Command push[] = {
TALER_TESTING_cmd_purse_create_with_deposit (
- "purse-with-deposit",
+ "purse-with-deposit-for-delete",
MHD_HTTP_OK,
"{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
true, /* upload contract */
@@ -169,11 +160,24 @@ run (void *cls,
"withdraw-coin-1",
"EUR:1.01",
NULL),
+ TALER_TESTING_cmd_purse_delete (
+ "purse-with-deposit-delete",
+ MHD_HTTP_NO_CONTENT,
+ "purse-with-deposit-for-delete"),
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-with-deposit",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:0.99\",\"summary\":\"ice cream\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "withdraw-coin-1",
+ "EUR:1.00",
+ NULL),
TALER_TESTING_cmd_purse_poll (
"push-poll-purse-before-merge",
MHD_HTTP_OK,
"purse-with-deposit",
- "EUR:1",
+ "EUR:0.99",
true,
GNUNET_TIME_UNIT_MINUTES),
TALER_TESTING_cmd_contract_get (
@@ -195,13 +199,13 @@ run (void *cls,
TALER_TESTING_cmd_status (
"push-check-post-merge-reserve-balance-get",
"create-reserve-1",
- "EUR:1.03",
+ "EUR:1.02",
MHD_HTTP_OK),
/* POST history doesn't yet support P2P transfers */
- TALER_TESTING_cmd_reserve_status (
+ TALER_TESTING_cmd_reserve_history (
"push-check-post-merge-reserve-balance-post",
"create-reserve-1",
- "EUR:1.03",
+ "EUR:1.02",
MHD_HTTP_OK),
/* Test conflicting merge */
TALER_TESTING_cmd_purse_merge (
@@ -218,6 +222,7 @@ run (void *cls,
MHD_HTTP_OK,
"{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_UNIT_MINUTES, /* expiration */
"create-reserve-1"),
TALER_TESTING_cmd_contract_get (
@@ -251,18 +256,26 @@ run (void *cls,
"create-reserve-1",
"EUR:2.02",
MHD_HTTP_OK),
- /* POST history doesn't yet support P2P transfers */
- TALER_TESTING_cmd_reserve_status (
+ TALER_TESTING_cmd_reserve_history (
"push-check-post-merge-reserve-balance-post",
"create-reserve-1",
"EUR:2.02",
MHD_HTTP_OK),
+ TALER_TESTING_cmd_purse_deposit_coins (
+ "purse-deposit-coins-idempotent",
+ MHD_HTTP_OK,
+ 0 /* min age */,
+ "purse-create-with-reserve",
+ "withdraw-coin-1",
+ "EUR:1.01",
+ NULL),
/* create 2nd purse for a deposit conflict */
TALER_TESTING_cmd_purse_create_with_reserve (
"purse-create-with-reserve-2",
MHD_HTTP_OK,
"{\"amount\":\"EUR:4\",\"summary\":\"beer\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_UNIT_MINUTES, /* expiration */
"create-reserve-1"),
TALER_TESTING_cmd_purse_deposit_coins (
@@ -282,6 +295,7 @@ run (void *cls,
MHD_HTTP_OK,
"{\"amount\":\"EUR:2\",\"summary\":\"ice cream\"}",
true /* upload contract */,
+ true /* pay purse fee */,
GNUNET_TIME_relative_multiply (
GNUNET_TIME_UNIT_SECONDS,
1), /* expiration */
@@ -356,37 +370,143 @@ run (void *cls,
NULL),
TALER_TESTING_cmd_end ()
};
+ struct TALER_TESTING_Command reserves[] = {
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-100",
+ "EUR:1.04"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-100",
+ "EUR:1.04",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-100"),
+ CMD_TRANSFER_TO_EXCHANGE ("create-reserve-101",
+ "EUR:1.04"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-101",
+ "EUR:1.04",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "create-reserve-101"),
+ CMD_EXEC_WIREWATCH ("wirewatch-100"),
+ TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-100",
+ "create-reserve-100",
+ "EUR:1",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-fail",
+ "create-reserve-101",
+ "EUR:0",
+ GNUNET_TIME_UNIT_YEARS,
+ 5, /* min purses */
+ MHD_HTTP_PAYMENT_REQUIRED,
+ NULL,
+ NULL),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-ok-a",
+ "create-reserve-101",
+ "EUR:0.01",
+ GNUNET_TIME_UNIT_MONTHS,
+ 1, /* min purses */
+ MHD_HTTP_OK,
+ NULL,
+ NULL),
+ TALER_TESTING_cmd_status ("status-101-open-paid",
+ "create-reserve-101",
+ "EUR:1.03",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_reserve_open ("reserve-open-101-ok-b",
+ "create-reserve-101",
+ "EUR:0",
+ GNUNET_TIME_UNIT_MONTHS,
+ 2, /* min purses */
+ MHD_HTTP_OK,
+ "withdraw-coin-100",
+ "EUR:0.03", /* 0.02 for the reserve open, 0.01 for deposit fee */
+ NULL,
+ NULL),
+ /* Use purse creation with purse quota here */
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-a",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-b",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve-101-fail",
+ MHD_HTTP_CONFLICT,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ false /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "create-reserve-101"),
+ TALER_TESTING_cmd_reserve_get_attestable ("reserve-101-attestable",
+ "create-reserve-101",
+ MHD_HTTP_NOT_FOUND,
+ NULL),
+ TALER_TESTING_cmd_reserve_get_attestable ("reserve-101-attest",
+ "create-reserve-101",
+ MHD_HTTP_NOT_FOUND,
+ "nx-attribute-name",
+ NULL),
+ TALER_TESTING_cmd_oauth ("start-oauth-service",
+ 6666),
+ TALER_TESTING_cmd_reserve_close ("reserve-101-close-kyc",
+ "create-reserve-101",
+ /* 42b => not to origin */
+ "payto://x-taler-bank/localhost/42?receiver-name=42b",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
+
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-close-pending",
+ "reserve-101-close-kyc",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-close-kyc",
+ "reserve-101-close-kyc",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-close-ok",
+ "reserve-101-close-kyc",
+ MHD_HTTP_NO_CONTENT),
+ /* Now it should pass */
+ TALER_TESTING_cmd_reserve_close ("reserve-101-close",
+ "create-reserve-101",
+ /* 42b => not to origin */
+ "payto://x-taler-bank/localhost/42?receiver-name=42b",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_exec_closer ("close-reserves-101",
+ config_file,
+ "EUR:1.02",
+ "EUR:0.01",
+ "create-reserve-101"),
+ TALER_TESTING_cmd_exec_transfer ("close-reserves-101-transfer",
+ config_file),
+ TALER_TESTING_cmd_status ("reserve-101-closed-status",
+ "create-reserve-101",
+ "EUR:0",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end ()
+ };
struct TALER_TESTING_Command commands[] = {
- /* setup exchange */
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_extensions ("offline-sign-extensions",
- config_file),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-wire-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_exec_offline_sign_global_fees ("offline-sign-global-fees",
- config_file,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01",
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_MINUTES,
- GNUNET_TIME_UNIT_DAYS,
- 1),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_file),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_file,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_batch ("withdraw",
withdraw),
TALER_TESTING_cmd_batch ("push",
@@ -395,14 +515,15 @@ run (void *cls,
pull),
TALER_TESTING_cmd_batch ("expire",
expire),
+ TALER_TESTING_cmd_batch ("reserves",
+ reserves),
/* End the suite. */
TALER_TESTING_cmd_end ()
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
@@ -410,62 +531,26 @@ int
main (int argc,
char *const *argv)
{
- char *cipher;
-
(void) argc;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup (argv[0],
- "INFO",
- NULL);
-
- GNUNET_assert (GNUNET_OK ==
- TALER_extension_age_restriction_register ());
-
- cipher = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
- GNUNET_assert (NULL != cipher);
- uses_cs = (0 == strcmp (cipher, "cs"));
- GNUNET_asprintf (&config_file,
- "test_exchange_api-%s.conf",
- cipher);
- GNUNET_free (cipher);
-
- /* Check fakebank port is available and get config */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_file,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (config_file);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (config_file,
- GNUNET_YES,
- &ec))
{
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 78;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_file))
- return 2;
- break;
- default:
- GNUNET_break (0);
- return 3;
+ char *cipher;
+
+ cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
+ GNUNET_assert (NULL != cipher);
+ uses_cs = (0 == strcmp (cipher, "cs"));
+ GNUNET_asprintf (&config_file,
+ "test_exchange_api-%s.conf",
+ cipher);
+ GNUNET_free (cipher);
}
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_file,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_kyc_api.c b/src/testing/test_kyc_api.c
index 303c7e11a..0844c5818 100644
--- a/src/testing/test_kyc_api.c
+++ b/src/testing/test_kyc_api.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -23,6 +23,7 @@
*/
#include "platform.h"
#include "taler_util.h"
+#include "taler_attributes.h"
#include "taler_signatures.h"
#include "taler_exchange_service.h"
#include "taler_json_lib.h"
@@ -40,14 +41,10 @@
#define CONFIG_FILE "test_kyc_api.conf"
/**
- * Exchange configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
+struct TALER_TESTING_Credentials cred;
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
/**
* Execute the taler-exchange-wirewatch command with
@@ -56,7 +53,7 @@ static struct TALER_TESTING_BankConfiguration bc;
* @param label label to use for the command.
*/
#define CMD_EXEC_WIREWATCH(label) \
- TALER_TESTING_cmd_exec_wirewatch (label, CONFIG_FILE)
+ TALER_TESTING_cmd_exec_wirewatch2 (label, CONFIG_FILE, "exchange-account-2")
/**
* Execute the taler-exchange-aggregator, closer and transfer commands with
@@ -78,8 +75,8 @@ static struct TALER_TESTING_BankConfiguration bc;
*/
#define CMD_TRANSFER_TO_EXCHANGE(label,amount) \
TALER_TESTING_cmd_admin_add_incoming (label, amount, \
- &bc.exchange_auth, \
- bc.user42_payto)
+ &cred.ba, \
+ cred.user42_payto)
/**
* Main function that will tell the interpreter what commands to
@@ -91,15 +88,14 @@ static void
run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
- /**
- * Test withdraw.
- */
struct TALER_TESTING_Command withdraw[] = {
CMD_TRANSFER_TO_EXCHANGE ("create-reserve-1",
"EUR:15.02"),
TALER_TESTING_cmd_check_bank_admin_transfer (
"check-create-reserve-1",
- "EUR:15.02", bc.user42_payto, bc.exchange_payto,
+ "EUR:15.02",
+ cred.user42_payto,
+ cred.exchange_payto,
"create-reserve-1"),
CMD_EXEC_WIREWATCH ("wirewatch-1"),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1-no-kyc",
@@ -124,16 +120,25 @@ run (void *cls,
"EUR:5",
0, /* age restriction off */
MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
- TALER_TESTING_cmd_proof_kyc ("proof-kyc",
- "create-reserve-1",
- "pass",
- "state",
- MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-withdraw",
+ "withdraw-coin-1-lacking-kyc",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-kyc",
+ "withdraw-coin-1-lacking-kyc",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-1-with-kyc",
"create-reserve-1",
"EUR:5",
0, /* age restriction off */
MHD_HTTP_OK),
+ /* Attestations above are bound to the originating *bank* account,
+ not to the reserve (!). Hence, they are NOT found here! */
+ TALER_TESTING_cmd_reserve_get_attestable ("reserve-get-attestable",
+ "create-reserve-1",
+ MHD_HTTP_NOT_FOUND,
+ NULL),
TALER_TESTING_cmd_end ()
};
struct TALER_TESTING_Command spend[] = {
@@ -141,7 +146,7 @@ run (void *cls,
"deposit-simple",
"withdraw-coin-1",
0,
- bc.user43_payto,
+ cred.user43_payto,
"{\"items\":[{\"name\":\"ice cream\",\"value\":1}]}",
GNUNET_TIME_UNIT_ZERO,
"EUR:5",
@@ -158,71 +163,378 @@ run (void *cls,
struct TALER_TESTING_Command track[] = {
CMD_EXEC_AGGREGATOR ("run-aggregator-before-kyc"),
TALER_TESTING_cmd_check_bank_empty ("check_bank_empty-no-kyc"),
+ TALER_TESTING_cmd_track_transaction (
+ "track-deposit-kyc-ready",
+ "deposit-simple",
+ 0,
+ MHD_HTTP_ACCEPTED,
+ NULL),
TALER_TESTING_cmd_check_kyc_get ("check-kyc-deposit",
- "track-deposit",
+ "track-deposit-kyc-ready",
MHD_HTTP_ACCEPTED),
- TALER_TESTING_cmd_proof_kyc ("proof-kyc-no-service",
- "track-deposit",
- "bad",
- "state",
- MHD_HTTP_BAD_GATEWAY),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-kyc-no-service",
+ "track-deposit-kyc-ready",
+ "kyc-provider-test-oauth2",
+ "bad",
+ MHD_HTTP_BAD_GATEWAY),
TALER_TESTING_cmd_oauth ("start-oauth-service",
6666),
- TALER_TESTING_cmd_proof_kyc ("proof-kyc-fail",
- "track-deposit",
- "bad",
- "state",
- MHD_HTTP_FORBIDDEN),
- TALER_TESTING_cmd_proof_kyc ("proof-kyc-fail",
- "track-deposit",
- "pass",
- "state",
- MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-kyc-fail",
+ "track-deposit-kyc-ready",
+ "kyc-provider-test-oauth2",
+ "bad",
+ MHD_HTTP_FORBIDDEN),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-deposit-again",
+ "track-deposit-kyc-ready",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-kyc-pass",
+ "track-deposit-kyc-ready",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
CMD_EXEC_AGGREGATOR ("run-aggregator-after-kyc"),
TALER_TESTING_cmd_check_bank_transfer (
"check_bank_transfer-499c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.98",
- bc.exchange_payto,
- bc.user43_payto),
+ cred.exchange_payto,
+ cred.user43_payto),
TALER_TESTING_cmd_check_bank_empty ("check_bank_empty"),
TALER_TESTING_cmd_end ()
};
struct TALER_TESTING_Command wallet_kyc[] = {
- TALER_TESTING_cmd_wallet_kyc_get (
- "wallet-kyc-fail",
- NULL,
+ TALER_TESTING_cmd_wallet_kyc_get ("wallet-kyc-fail",
+ NULL,
+ "EUR:1000000",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-wallet",
+ "wallet-kyc-fail",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("proof-wallet-kyc",
+ "wallet-kyc-fail",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_check_kyc_get ("wallet-kyc-check",
+ "wallet-kyc-fail",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_reserve_get_attestable ("wallet-get-attestable",
+ "wallet-kyc-fail",
+ MHD_HTTP_OK,
+ TALER_ATTRIBUTE_FULL_NAME,
+ NULL),
+ TALER_TESTING_cmd_reserve_attest ("wallet-get-attest",
+ "wallet-kyc-fail",
+ MHD_HTTP_OK,
+ TALER_ATTRIBUTE_FULL_NAME,
+ NULL),
+ TALER_TESTING_cmd_end ()
+ };
+
+ /**
+ * Test withdrawal for P2P
+ */
+ struct TALER_TESTING_Command p2p_withdraw[] = {
+ /**
+ * Move money to the exchange's bank account.
+ */
+ CMD_TRANSFER_TO_EXCHANGE ("p2p_create-reserve-1",
+ "EUR:5.04"),
+ CMD_TRANSFER_TO_EXCHANGE ("p2p_create-reserve-2",
+ "EUR:5.01"),
+ CMD_TRANSFER_TO_EXCHANGE ("p2p_create-reserve-3",
+ "EUR:0.03"),
+ TALER_TESTING_cmd_reserve_poll ("p2p_poll-reserve-1",
+ "p2p_create-reserve-1",
+ "EUR:5.04",
+ GNUNET_TIME_UNIT_MINUTES,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("p2p_check-create-reserve-1",
+ "EUR:5.04",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "p2p_create-reserve-1"),
+ TALER_TESTING_cmd_check_bank_admin_transfer ("p2p_check-create-reserve-2",
+ "EUR:5.01",
+ cred.user42_payto,
+ cred.exchange_payto,
+ "p2p_create-reserve-2"),
+ /**
+ * Make a reserve exist, according to the previous
+ * transfer.
+ */
+ CMD_EXEC_WIREWATCH ("p2p_wirewatch-1"),
+ TALER_TESTING_cmd_reserve_poll_finish ("p2p_finish-poll-reserve-1",
+ GNUNET_TIME_UNIT_SECONDS,
+ "p2p_poll-reserve-1"),
+ /**
+ * Withdraw EUR:5.
+ */
+ TALER_TESTING_cmd_withdraw_amount ("p2p_withdraw-coin-1",
+ "p2p_create-reserve-1",
+ "EUR:5",
+ 0, /* age restriction off */
+ MHD_HTTP_OK),
+ /**
+ * Check the reserve is depleted.
+ */
+ TALER_TESTING_cmd_status ("p2p_status-1",
+ "p2p_create-reserve-1",
+ "EUR:0.03",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_end ()
+ };
+ struct TALER_TESTING_Command push[] = {
+ TALER_TESTING_cmd_purse_create_with_deposit (
+ "purse-with-deposit",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true, /* upload contract */
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "p2p_withdraw-coin-1",
+ "EUR:1.01",
+ NULL),
+ TALER_TESTING_cmd_coin_history ("coin-history-purse-with-deposit",
+ "p2p_withdraw-coin-1#0",
+ "EUR:3.99",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_purse_poll (
+ "push-poll-purse-before-merge",
+ MHD_HTTP_OK,
+ "purse-with-deposit",
+ "EUR:1",
+ true,
+ GNUNET_TIME_UNIT_MINUTES),
+ TALER_TESTING_cmd_contract_get (
+ "push-get-contract",
+ MHD_HTTP_OK,
+ true, /* for merge */
+ "purse-with-deposit"),
+ TALER_TESTING_cmd_purse_merge (
+ "purse-merge-into-reserve",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ "push-get-contract",
+ "p2p_create-reserve-1"),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-purse-merge",
+ "purse-merge-into-reserve",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("p2p_proof-kyc",
+ "purse-merge-into-reserve",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_purse_merge (
+ "purse-merge-into-reserve",
+ MHD_HTTP_OK,
+ "push-get-contract",
+ "p2p_create-reserve-1"),
+ TALER_TESTING_cmd_purse_poll_finish (
+ "push-merge-purse-poll-finish",
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_SECONDS,
+ 5),
+ "push-poll-purse-before-merge"),
+ TALER_TESTING_cmd_status (
+ "push-check-post-merge-reserve-balance-get",
+ "p2p_create-reserve-1",
+ "EUR:1.03",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_reserve_history (
+ "push-check-post-merge-reserve-balance-post",
+ "p2p_create-reserve-1",
+ "EUR:1.03",
+ MHD_HTTP_OK),
+
+ TALER_TESTING_cmd_end ()
+ };
+ struct TALER_TESTING_Command pull[] = {
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ true /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "p2p_create-reserve-3"),
+ TALER_TESTING_cmd_check_kyc_get ("check-kyc-purse-create",
+ "purse-create-with-reserve",
+ MHD_HTTP_ACCEPTED),
+ TALER_TESTING_cmd_proof_kyc_oauth2 ("p2p_proof-kyc-pull",
+ "purse-create-with-reserve",
+ "kyc-provider-test-oauth2",
+ "pass",
+ MHD_HTTP_SEE_OTHER),
+ TALER_TESTING_cmd_purse_create_with_reserve (
+ "purse-create-with-reserve",
+ MHD_HTTP_OK,
+ "{\"amount\":\"EUR:1\",\"summary\":\"ice cream\"}",
+ true /* upload contract */,
+ true /* pay purse fee */,
+ GNUNET_TIME_UNIT_MINUTES, /* expiration */
+ "p2p_create-reserve-3"),
+ TALER_TESTING_cmd_contract_get (
+ "pull-get-contract",
+ MHD_HTTP_OK,
+ false, /* for deposit */
+ "purse-create-with-reserve"),
+ TALER_TESTING_cmd_purse_poll (
+ "pull-poll-purse-before-deposit",
+ MHD_HTTP_OK,
+ "purse-create-with-reserve",
+ "EUR:1",
+ false,
+ GNUNET_TIME_UNIT_MINUTES),
+ TALER_TESTING_cmd_purse_deposit_coins (
+ "purse-deposit-coins",
+ MHD_HTTP_OK,
+ 0 /* min age */,
+ "purse-create-with-reserve",
+ "p2p_withdraw-coin-1",
+ "EUR:1.01",
+ NULL),
+ TALER_TESTING_cmd_coin_history ("coin-history-purse-pull-deposit",
+ "p2p_withdraw-coin-1#0",
+ "EUR:2.98",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_purse_poll_finish (
+ "pull-deposit-purse-poll-finish",
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_SECONDS,
+ 5),
+ "pull-poll-purse-before-deposit"),
+ TALER_TESTING_cmd_status (
+ "pull-check-post-merge-reserve-balance-get-2",
+ "p2p_create-reserve-3",
+ "EUR:1.03",
MHD_HTTP_OK),
- TALER_TESTING_cmd_proof_kyc ("proof-wallet-kyc",
- "wallet-kyc-fail",
- "pass",
- "state",
- MHD_HTTP_SEE_OTHER),
- TALER_TESTING_cmd_check_kyc_get (
- "wallet-kyc-check",
- "wallet-kyc-fail",
+ TALER_TESTING_cmd_reserve_history (
+ "push-check-post-merge-reserve-balance-post-2",
+ "p2p_create-reserve-3",
+ "EUR:1.03",
MHD_HTTP_OK),
TALER_TESTING_cmd_end ()
};
+ struct TALER_TESTING_Command aml[] = {
+ /* Trigger something upon which an AML officer could act */
+ TALER_TESTING_cmd_wallet_kyc_get ("wallet-trigger-kyc-for-aml",
+ NULL,
+ "EUR:1000",
+ MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS),
+ TALER_TESTING_cmd_set_officer ("create-aml-officer-1",
+ NULL,
+ "Peter Falk",
+ true,
+ false),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-none-normal",
+ "create-aml-officer-1",
+ TALER_AML_NORMAL,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-none-pending",
+ "create-aml-officer-1",
+ TALER_AML_PENDING,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-none-frozen",
+ "create-aml-officer-1",
+ TALER_AML_FROZEN,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_sleep ("sleep-1a",
+ 1),
+ TALER_TESTING_cmd_set_officer ("create-aml-officer-1-disable",
+ "create-aml-officer-1",
+ "Peter Falk",
+ true,
+ true),
+ /* Test that we are not allowed to take AML decisions as our
+ AML staff account is on read-only */
+ TALER_TESTING_cmd_take_aml_decision ("aml-decide-while-disabled",
+ "create-aml-officer-1",
+ "wallet-trigger-kyc-for-aml",
+ "EUR:10000",
+ "party time",
+ TALER_AML_NORMAL,
+ NULL,
+ MHD_HTTP_FORBIDDEN),
+ /* Check that no decision was taken, but that we are allowed
+ to read this information */
+ TALER_TESTING_cmd_check_aml_decision ("check-aml-decision-empty",
+ "create-aml-officer-1",
+ "aml-decide-while-disabled",
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_sleep ("sleep-1b",
+ 1),
+ TALER_TESTING_cmd_set_officer ("create-aml-officer-1-enable",
+ "create-aml-officer-1",
+ "Peter Falk",
+ true,
+ false),
+ TALER_TESTING_cmd_take_aml_decision ("aml-decide",
+ "create-aml-officer-1",
+ "wallet-trigger-kyc-for-aml",
+ "EUR:10000",
+ "party time",
+ TALER_AML_NORMAL,
+ NULL,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-one-normal",
+ "create-aml-officer-1",
+ TALER_AML_NORMAL,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-zero-frozen",
+ "create-aml-officer-1",
+ TALER_AML_FROZEN,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_check_aml_decision ("check-aml-decision",
+ "create-aml-officer-1",
+ "aml-decide",
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_sleep ("sleep-1c",
+ 1),
+ TALER_TESTING_cmd_take_aml_decision ("aml-decide-freeze",
+ "create-aml-officer-1",
+ "wallet-trigger-kyc-for-aml",
+ "EUR:1000",
+ "party over",
+ TALER_AML_FROZEN,
+ NULL,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-one-frozen",
+ "create-aml-officer-1",
+ TALER_AML_FROZEN,
+ MHD_HTTP_OK),
+ TALER_TESTING_cmd_check_aml_decisions ("check-decisions-zero-normal",
+ "create-aml-officer-1",
+ TALER_AML_NORMAL,
+ MHD_HTTP_NO_CONTENT),
+ TALER_TESTING_cmd_sleep ("sleep-1d",
+ 1),
+ TALER_TESTING_cmd_set_officer ("create-aml-officer-1-disable",
+ "create-aml-officer-1",
+ "Peter Falk",
+ false,
+ true),
+ /* Test that we are NOT allowed to read AML decisions now that
+ our AML staff account is disabled */
+ TALER_TESTING_cmd_check_aml_decision ("check-aml-decision-disabled",
+ "create-aml-officer-1",
+ "aml-decide",
+ MHD_HTTP_FORBIDDEN),
+ TALER_TESTING_cmd_end ()
+ };
struct TALER_TESTING_Command commands[] = {
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- CONFIG_FILE,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- CONFIG_FILE),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 2),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-2"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ CONFIG_FILE,
+ "-e",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_batch ("withdraw",
withdraw),
TALER_TESTING_cmd_batch ("spend",
@@ -233,13 +545,20 @@ run (void *cls,
withdraw_kyc),
TALER_TESTING_cmd_batch ("wallet-kyc",
wallet_kyc),
+ TALER_TESTING_cmd_batch ("p2p_withdraw",
+ p2p_withdraw),
+ TALER_TESTING_cmd_batch ("push",
+ push),
+ TALER_TESTING_cmd_batch ("pull",
+ pull),
+ TALER_TESTING_cmd_batch ("aml",
+ aml),
TALER_TESTING_cmd_end ()
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- commands,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ commands);
}
@@ -248,48 +567,14 @@ main (int argc,
char *const *argv)
{
(void) argc;
- (void) argv;
- /* These environment variables get in the way... */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup ("test-kyc-api",
- "INFO",
- NULL);
- /* Check fakebank port is available and get configuration data. */
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (CONFIG_FILE,
- "exchange-account-2",
- &bc))
- return 77;
- TALER_TESTING_cleanup_files (CONFIG_FILE);
- /* @helpers. Run keyup, create tables, ... Note: it
- * fetches the port number from config in order to see
- * if it's available. */
- switch (TALER_TESTING_prepare_exchange (CONFIG_FILE,
- GNUNET_YES,
- &ec))
- {
- case GNUNET_SYSERR:
- GNUNET_break (0);
- return 1;
- case GNUNET_NO:
- return 77;
- case GNUNET_OK:
- if (GNUNET_OK !=
- /* Set up event loop and reschedule context, plus
- * start/stop the exchange. It calls TALER_TESTING_setup
- * which creates the 'is' object.
- */
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- CONFIG_FILE))
- return 1;
- break;
- default:
- GNUNET_break (0);
- return 1;
- }
- return 0;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ CONFIG_FILE,
+ "exchange-account-2",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_kyc_api.conf b/src/testing/test_kyc_api.conf
index 09e7cdc7e..b6bfdb055 100644
--- a/src/testing/test_kyc_api.conf
+++ b/src/testing/test_kyc_api.conf
@@ -1,218 +1,42 @@
-
# This file is in the public domain.
#
-[PATHS]
-# Persistent data storage for the testcase
-TALER_TEST_HOME = test_exchange_api_home/
-TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/${USER:-}/taler-system-runtime/
-
-[taler-exchange-secmod-rsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-
-[taler-exchange-secmod-eddsa]
-# Reduce from 1 year to speed up test
-LOOKAHEAD_SIGN = 24 days
-# Reduce from 12 weeks to ensure we have multiple
-DURATION = 14 days
-
-
-[taler]
-# Currency supported by the exchange (can only be one)
-CURRENCY = EUR
-CURRENCY_ROUND_UNIT = EUR:0.01
-
-[auditor]
-BASE_URL = "http://localhost:8083/"
-
-# HTTP port the auditor listens to
-PORT = 8083
-
-TINY_AMOUNT = EUR:0.01
-
-[exchange]
-
-# HTTP port the exchange listens to
-PORT = 8081
-
-# Master public key used to sign the exchange's various keys
-MASTER_PUBLIC_KEY = 98NJW3CQHZQGQXTY3K85K531XKPAPAVV4Q5V8PYYRR00NJGZWNVG
-
-# How to access our database
-DB = postgres
-
-# Base URL of the exchange. Must be set to a URL where the
-# exchange (or the twister) is actually listening.
-BASE_URL = "http://localhost:8081/"
-
-
-KYC_MODE = OAUTH2
-
-KYC_WALLET_BALANCE_LIMIT = EUR:1
-
-KYC_WITHDRAW_PERIOD = "31 days"
-
-KYC_WITHDRAW_LIMIT = EUR:8
-
-[exchange-kyc-oauth2]
-
-KYC_OAUTH2_AUTH_URL = http://localhost:6666/oauth/v2/token
-KYC_OAUTH2_LOGIN_URL = http://localhost:6666/oauth/v2/login
-KYC_INFO_URL = http://localhost:6666/api/user/me
+@INLINE@ coins-rsa.conf
+@INLINE@ test_exchange_api.conf
+
+[kyc-provider-test-oauth2]
+COST = 0
+LOGIC = oauth2
+USER_TYPE = INDIVIDUAL
+PROVIDED_CHECKS = DUMMY
+KYC_OAUTH2_VALIDITY = forever
+KYC_OAUTH2_TOKEN_URL = http://localhost:6666/oauth/v2/token
+KYC_OAUTH2_AUTHORIZE_URL = http://localhost:6666/oauth/v2/login
+KYC_OAUTH2_INFO_URL = http://localhost:6666/api/user/me
KYC_OAUTH2_CLIENT_ID = taler-exchange
KYC_OAUTH2_CLIENT_SECRET = exchange-secret
KYC_OAUTH2_POST_URL = http://example.com/
-
-[exchangedb-postgres]
-CONFIG = "postgres:///talercheck"
-
-[auditordb-postgres]
-CONFIG = "postgres:///talercheck"
-
-# Sections starting with "exchange-account-" configure the bank accounts
-# of the exchange. The "URL" specifies the account in
-# payto://-format.
-[exchange-account-1]
-# What is the URL of our account?
-PAYTO_URI = "payto://x-taler-bank/localhost/42?receiver-name=42"
-
-[exchange-accountcredentials-1]
-WIRE_GATEWAY_URL = "http://localhost:8082/42/"
-
-[bank]
-HTTP_PORT = 8082
-
-# ENABLE_CREDIT = YES
-
-[exchange-account-2]
-# What is the bank account (with the "Taler Bank" demo system)?
-PAYTO_URI = "payto://x-taler-bank/localhost/2?receiver-name=2"
-ENABLE_DEBIT = YES
-ENABLE_CREDIT = YES
-
-# Authentication information for basic authentication
-[exchange-accountcredentials-2]
-WIRE_GATEWAY_URL = "http://localhost:8082/2/"
-WIRE_GATEWAY_AUTH_METHOD = "basic"
-USERNAME = user
-PASSWORD = pass
-
-
-
-
-# Sections starting with "coin_" specify which denominations
-# the exchange should support (and their respective fee structure)
-[coin_eur_ct_1]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_ct_2]
-value = EUR:0.01
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.00
-fee_deposit = EUR:0.00
-fee_refresh = EUR:0.01
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_ct_10]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_ct_11]
-value = EUR:0.10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_1]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_2]
-value = EUR:1
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_5]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_6]
-value = EUR:5
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS
-
-[coin_eur_10]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = RSA
-rsa_keysize = 1024
-
-[coin_eur_11]
-value = EUR:10
-duration_withdraw = 7 days
-duration_spend = 2 years
-duration_legal = 3 years
-fee_withdraw = EUR:0.01
-fee_deposit = EUR:0.01
-fee_refresh = EUR:0.03
-fee_refund = EUR:0.01
-CIPHER = CS \ No newline at end of file
+KYC_OAUTH2_CONVERTER_HELPER = taler-exchange-kyc-oauth2-test-converter.sh
+# "{"full_name":"{{last_name}}, {{first_name}}"}"
+
+[kyc-legitimization-balance-high]
+OPERATION_TYPE = BALANCE
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:8
+
+[kyc-legitimization-deposit-any]
+OPERATION_TYPE = DEPOSIT
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:0
+TIMEFRAME = 1d
+
+[kyc-legitimization-withdraw]
+OPERATION_TYPE = WITHDRAW
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:10
+TIMEFRAME = 1d
+
+[kyc-legitimization-merge]
+OPERATION_TYPE = MERGE
+REQUIRED_CHECKS = DUMMY
+THRESHOLD = EUR:0
+TIMEFRAME = 1d
diff --git a/src/testing/test_taler_exchange_aggregator.c b/src/testing/test_taler_exchange_aggregator.c
index d42d59762..2d7acc6dc 100644
--- a/src/testing/test_taler_exchange_aggregator.c
+++ b/src/testing/test_taler_exchange_aggregator.c
@@ -31,24 +31,9 @@
/**
- * Helper structure to keep exchange configuration values.
+ * Our credentials.
*/
-static struct TALER_TESTING_ExchangeConfiguration ec;
-
-/**
- * Bank configuration data.
- */
-static struct TALER_TESTING_BankConfiguration bc;
-
-/**
- * Contains plugin.
- */
-static struct TALER_TESTING_DatabaseConnection dbc;
-
-/**
- * Return value from main().
- */
-static int result;
+struct TALER_TESTING_Credentials cred;
/**
* Name of the configuration file to use.
@@ -71,24 +56,6 @@ static char *config_filename;
/**
- * Function run on shutdown to unload the DB plugin.
- *
- * @param cls NULL
- */
-static void
-unload_db (void *cls)
-{
- (void) cls;
- if (NULL != dbc.plugin)
- {
- dbc.plugin->drop_tables (dbc.plugin->cls);
- TALER_EXCHANGEDB_plugin_unload (dbc.plugin);
- dbc.plugin = NULL;
- }
-}
-
-
-/**
* Collects all the tests.
*/
static void
@@ -96,12 +63,13 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command all[] = {
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- config_filename,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- // check no aggregation happens on a empty database
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-1"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_filename,
+ "-e",
+ NULL),
CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty-db",
config_filename),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
@@ -109,7 +77,7 @@ run (void *cls,
/* check aggregation happens on the simplest case:
one deposit into the database. */
TALER_TESTING_cmd_insert_deposit ("do-deposit-1",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -120,15 +88,15 @@ run (void *cls,
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.89",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-1"),
/* check aggregation accumulates well. */
TALER_TESTING_cmd_insert_deposit ("do-deposit-2a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -137,7 +105,7 @@ run (void *cls,
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-2b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -149,15 +117,15 @@ run (void *cls,
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-2",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:1.79",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-2"),
/* check that different merchants stem different aggregations. */
TALER_TESTING_cmd_insert_deposit ("do-deposit-3a",
- &dbc,
+ cred.cfg,
"bob",
"4",
GNUNET_TIME_timestamp_get (),
@@ -165,7 +133,7 @@ run (void *cls,
"EUR:1",
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-3b",
- &dbc,
+ cred.cfg,
"bob",
"5",
GNUNET_TIME_timestamp_get (),
@@ -173,7 +141,7 @@ run (void *cls,
"EUR:1",
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-3c",
- &dbc,
+ cred.cfg,
"alice",
"4",
GNUNET_TIME_timestamp_get (),
@@ -184,25 +152,25 @@ run (void *cls,
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3a",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.89",
- bc.exchange_payto,
+ cred.exchange_payto,
"payto://x-taler-bank/localhost/4?receiver-name=4"),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3b",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.89",
- bc.exchange_payto,
+ cred.exchange_payto,
"payto://x-taler-bank/localhost/4?receiver-name=4"),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-3c",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.89",
- bc.exchange_payto,
+ cred.exchange_payto,
"payto://x-taler-bank/localhost/5?receiver-name=5"),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-after-3"),
/* checking that aggregator waits for the deadline. */
TALER_TESTING_cmd_insert_deposit ("do-deposit-4a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -212,7 +180,7 @@ run (void *cls,
"EUR:0.2",
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-4b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -231,14 +199,14 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-4-delayed",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-4",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.19",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
// test picking all deposits at earliest deadline
TALER_TESTING_cmd_insert_deposit ("do-deposit-5a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -249,7 +217,7 @@ run (void *cls,
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-5b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -268,13 +236,13 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-5-delayed",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-5",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.19",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Test NEVER running 'tiny' unless they make up minimum unit */
TALER_TESTING_cmd_insert_deposit ("do-deposit-6a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -286,7 +254,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-6a-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-6b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -294,7 +262,7 @@ run (void *cls,
"EUR:0.102",
"EUR:0.1"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-6c",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -306,7 +274,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-6c-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-6d",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -318,7 +286,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-6d-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-6e",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -328,14 +296,14 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-6e",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-6",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.01",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Test profiteering if wire deadline is short */
TALER_TESTING_cmd_insert_deposit ("do-deposit-7a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -347,7 +315,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-7a-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-7b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -357,14 +325,14 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-profit",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.01",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Now check profit was actually taken */
TALER_TESTING_cmd_insert_deposit ("do-deposit-7c",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -374,14 +342,14 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-7-loss",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-7",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.01",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Test that aggregation would happen fully if wire deadline is long */
TALER_TESTING_cmd_insert_deposit ("do-deposit-8a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -395,7 +363,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-8a-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-8b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -411,7 +379,7 @@ run (void *cls,
/* now trigger aggregate with large transaction and short deadline */
TALER_TESTING_cmd_insert_deposit ("do-deposit-8c",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -421,14 +389,14 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-aggregator-deposit-8",
config_filename),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-8",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.03",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
/* Test aggregation with fees and rounding profits. */
TALER_TESTING_cmd_insert_deposit ("do-deposit-9a",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -442,7 +410,7 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_empty (
"expect-empty-transactions-after-9a-tiny"),
TALER_TESTING_cmd_insert_deposit ("do-deposit-9b",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -458,7 +426,7 @@ run (void *cls,
/* now trigger aggregate with large transaction and short deadline */
TALER_TESTING_cmd_insert_deposit ("do-deposit-9c",
- &dbc,
+ cred.cfg,
"bob",
USER42_ACCOUNT,
GNUNET_TIME_timestamp_get (),
@@ -469,49 +437,15 @@ run (void *cls,
config_filename),
/* 0.009 + 0.009 + 0.022 - 0.001 - 0.002 - 0.008 = 0.029 => 0.02 */
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-9",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:0.01",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_end ()
};
- TALER_TESTING_run_with_fakebank (is,
- all,
- bc.exchange_auth.wire_gateway_url);
-}
-
-
-/**
- * Prepare database and launch the test.
- *
- * @param cls unused
- * @param is interpreter to use
- */
-static void
-prepare_database (void *cls,
- struct TALER_TESTING_Interpreter *is)
-{
- dbc.plugin = TALER_EXCHANGEDB_plugin_load (is->cfg);
- if (NULL == dbc.plugin)
- {
- GNUNET_break (0);
- result = 77;
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (GNUNET_OK !=
- dbc.plugin->preflight (dbc.plugin->cls))
- {
- GNUNET_break (0);
- result = 77;
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- GNUNET_SCHEDULER_add_shutdown (&unload_db,
- NULL);
- run (NULL,
- is);
+ TALER_TESTING_run (is,
+ all);
}
@@ -520,7 +454,6 @@ main (int argc,
char *const argv[])
{
const char *plugin_name;
- char *testname;
if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
{
@@ -528,52 +461,17 @@ main (int argc,
return -1;
}
plugin_name++;
- (void) GNUNET_asprintf (&testname,
- "test-taler-exchange-aggregator-%s",
- plugin_name);
(void) GNUNET_asprintf (&config_filename,
- "%s.conf",
- testname);
-
- GNUNET_log_setup ("test_taler_exchange_aggregator",
- "DEBUG",
- NULL);
-
- /* these might get in the way */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
-
- TALER_TESTING_cleanup_files (config_filename);
-
- if (GNUNET_OK !=
- TALER_TESTING_prepare_exchange (config_filename,
- GNUNET_YES,
- &ec))
- {
- TALER_LOG_WARNING ("Could not prepare the exchange.\n");
- return 77;
- }
-
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_filename,
- "exchange-account-1",
- &bc))
- {
- TALER_LOG_WARNING ("Could not prepare the fakebank\n");
- return 77;
- }
- result = GNUNET_OK;
- if (GNUNET_OK !=
- TALER_TESTING_setup_with_exchange (&prepare_database,
- NULL,
- config_filename))
- {
- TALER_LOG_WARNING ("Could not prepare database for tests.\n");
- return result;
- }
- GNUNET_free (config_filename);
- GNUNET_free (testname);
- return GNUNET_OK == result ? 0 : 1;
+ "test-taler-exchange-aggregator-%s.conf",
+ plugin_name);
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_filename,
+ "exchange-account-1",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/test_taler_exchange_httpd_home/.config/taler/account-1.json b/src/testing/test_taler_exchange_httpd_home/.config/taler/account-1.json
deleted file mode 100644
index 21a7500b4..000000000
--- a/src/testing/test_taler_exchange_httpd_home/.config/taler/account-1.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
- "payto_uri": "payto://x-taler-bank/localhost/2",
- "master_sig": "HEWC1XDS0QZ53YQR451VRKD4N968NXWGZXS30HJ59MJ0PESACK1ZYPYCAT15P08WD58C7D7F6EVN26D59JKA75XEBDQCM8VYFETK82R"
-} \ No newline at end of file
diff --git a/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange-offline/master.priv b/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange-offline/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange-offline/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv b/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv
deleted file mode 100644
index 394926938..000000000
--- a/src/testing/test_taler_exchange_httpd_home/.local/share/taler/exchange/offline-keys/master.priv
+++ /dev/null
@@ -1 +0,0 @@
-p^-33XX!\0qmU_ \ No newline at end of file
diff --git a/src/testing/test_taler_exchange_wirewatch.c b/src/testing/test_taler_exchange_wirewatch.c
index d62ca55e4..86b616456 100644
--- a/src/testing/test_taler_exchange_wirewatch.c
+++ b/src/testing/test_taler_exchange_wirewatch.c
@@ -34,14 +34,9 @@
/**
- * Bank configuration data.
+ * Our credentials.
*/
-static struct TALER_TESTING_BankConfiguration bc;
-
-/**
- * Helper structure to keep exchange configuration values.
- */
-static struct TALER_TESTING_ExchangeConfiguration ec;
+static struct TALER_TESTING_Credentials cred;
/**
* Name of the configuration file to use.
@@ -66,8 +61,8 @@ transfer_to_exchange (const char *label,
{
return TALER_TESTING_cmd_admin_add_incoming (label,
amount,
- &bc.exchange_auth,
- bc.user42_payto);
+ &cred.ba,
+ cred.user42_payto);
}
@@ -82,22 +77,19 @@ run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command all[] = {
- TALER_TESTING_cmd_exec_offline_sign_fees ("offline-sign-fees",
- config_filename,
- "EUR:0.01",
- "EUR:0.01",
- "EUR:0.01"),
- TALER_TESTING_cmd_auditor_add ("add-auditor-OK",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_wire_add ("add-wire-account",
- "payto://x-taler-bank/localhost/2?receiver-name=2",
- MHD_HTTP_NO_CONTENT,
- false),
- TALER_TESTING_cmd_exec_offline_sign_keys ("offline-sign-future-keys",
- config_filename),
- TALER_TESTING_cmd_check_keys_pull_all_keys ("refetch /keys",
- 1),
+ TALER_TESTING_cmd_run_fakebank ("run-fakebank",
+ cred.cfg,
+ "exchange-account-1"),
+ TALER_TESTING_cmd_system_start ("start-taler",
+ config_filename,
+ "-e",
+ "-u", "exchange-account-1",
+ NULL),
+ TALER_TESTING_cmd_get_exchange ("get-exchange",
+ cred.cfg,
+ NULL,
+ true,
+ true),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-on-start"),
CMD_EXEC_AGGREGATOR ("run-aggregator-on-empty"),
TALER_TESTING_cmd_exec_wirewatch ("run-wirewatch-on-empty",
@@ -112,8 +104,8 @@ run (void *cls,
TALER_TESTING_cmd_check_bank_admin_transfer (
"clear-good-transfer-to-the-exchange",
"EUR:5",
- bc.user42_payto, // debit
- bc.exchange_payto, // credit
+ cred.user42_payto, // debit
+ cred.exchange_payto, // credit
"run-transfer-good-to-exchange"),
TALER_TESTING_cmd_exec_closer ("run-closer-non-expired-reserve",
@@ -136,18 +128,17 @@ run (void *cls,
CMD_EXEC_AGGREGATOR ("run-closer-on-expired-reserve"),
TALER_TESTING_cmd_check_bank_transfer ("expect-deposit-1",
- ec.exchange_url,
+ cred.exchange_url,
"EUR:4.99",
- bc.exchange_payto,
- bc.user42_payto),
+ cred.exchange_payto,
+ cred.user42_payto),
TALER_TESTING_cmd_check_bank_empty ("expect-empty-transactions-2"),
TALER_TESTING_cmd_end ()
};
(void) cls;
- TALER_TESTING_run_with_fakebank (is,
- all,
- bc.exchange_auth.wire_gateway_url);
+ TALER_TESTING_run (is,
+ all);
}
@@ -155,69 +146,29 @@ int
main (int argc,
char *const argv[])
{
- const char *plugin_name;
-
(void) argc;
- /* these might get in the way */
- unsetenv ("XDG_DATA_HOME");
- unsetenv ("XDG_CONFIG_HOME");
- GNUNET_log_setup ("test_taler_exchange_wirewatch",
- "DEBUG",
- NULL);
-
- if (NULL == (plugin_name = strrchr (argv[0], (int) '-')))
{
- GNUNET_break (0);
- return -1;
- }
- plugin_name++;
- {
- char *testname;
-
- GNUNET_asprintf (&testname,
- "test-taler-exchange-wirewatch-%s",
- plugin_name);
+ const char *plugin_name;
+
+ plugin_name = strrchr (argv[0], (int) '-');
+ if (NULL == plugin_name)
+ {
+ GNUNET_break (0);
+ return -1;
+ }
+ plugin_name++;
GNUNET_asprintf (&config_filename,
- "%s.conf",
- testname);
- GNUNET_free (testname);
- }
- /* check database is working */
- {
- struct GNUNET_PQ_Context *conn;
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-
- conn = GNUNET_PQ_connect ("postgres:///talercheck",
- NULL,
- es,
- NULL);
- if (NULL == conn)
- return 77;
- GNUNET_PQ_disconnect (conn);
- }
-
- TALER_TESTING_cleanup_files (config_filename);
- if (GNUNET_OK !=
- TALER_TESTING_prepare_exchange (config_filename,
- GNUNET_YES,
- &ec))
- {
- TALER_LOG_INFO ("Could not prepare the exchange\n");
- return 77;
+ "test-taler-exchange-wirewatch-%s.conf",
+ plugin_name);
}
-
- if (GNUNET_OK !=
- TALER_TESTING_prepare_fakebank (config_filename,
- "exchange-account-1",
- &bc))
- return 77;
-
- return (GNUNET_OK ==
- TALER_TESTING_setup_with_exchange (&run,
- NULL,
- config_filename)) ? 0 : 1;
+ return TALER_TESTING_main (argv,
+ "INFO",
+ config_filename,
+ "exchange-account-1",
+ TALER_TESTING_BS_FAKEBANK,
+ &cred,
+ &run,
+ NULL);
}
diff --git a/src/testing/testing_api_cmd_age_withdraw.c b/src/testing/testing_api_cmd_age_withdraw.c
new file mode 100644
index 000000000..6ad22809e
--- /dev/null
+++ b/src/testing/testing_api_cmd_age_withdraw.c
@@ -0,0 +1,756 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_age_withdraw.c
+ * @brief implements the age-withdraw command
+ * @author Özgür Kesim
+ */
+
+#include "platform.h"
+#include "taler_exchange_service.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_common.h>
+#include <microhttpd.h>
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_signatures.h"
+#include "taler_extensions.h"
+#include "taler_testing_lib.h"
+
+/*
+ * The output state of coin
+ */
+struct CoinOutputState
+{
+
+ /**
+ * The calculated details during "age-withdraw", for the selected coin.
+ */
+ struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails details;
+
+ /**
+ * The (wanted) value of the coin, MUST be the same as input.denom_pub.value;
+ */
+ struct TALER_Amount amount;
+
+ /**
+ * Reserve history entry that corresponds to this coin.
+ * Will be of type #TALER_EXCHANGE_RTT_AGEWITHDRAWAL.
+ */
+ struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history;
+};
+
+/**
+ * State for a "age withdraw" CMD:
+ */
+
+struct AgeWithdrawState
+{
+
+ /**
+ * Interpreter state (during command)
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * The age-withdraw handle
+ */
+ struct TALER_EXCHANGE_AgeWithdrawHandle *handle;
+
+ /**
+ * Exchange base URL. Only used as offered trait.
+ */
+ char *exchange_url;
+
+ /**
+ * URI of the reserve we are withdrawing from.
+ */
+ char *reserve_payto_uri;
+
+ /**
+ * Private key of the reserve we are withdrawing from.
+ */
+ struct TALER_ReservePrivateKeyP reserve_priv;
+
+ /**
+ * Public key of the reserve we are withdrawing from.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Which reserve should we withdraw from?
+ */
+ const char *reserve_reference;
+
+ /**
+ * Expected HTTP response code to the request.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Age mask
+ */
+ struct TALER_AgeMask mask;
+
+ /**
+ * The maximum age we commit to
+ */
+ uint8_t max_age;
+
+ /**
+ * Number of coins to withdraw
+ */
+ size_t num_coins;
+
+ /**
+ * The @e num_coins input that is provided to the
+ * `TALER_EXCHANGE_age_withdraw` API.
+ * Each contains kappa secrets, from which we will have
+ * to disclose kappa-1 in a subsequent age-withdraw-reveal operation.
+ */
+ struct TALER_EXCHANGE_AgeWithdrawCoinInput *coin_inputs;
+
+ /**
+ * The output state of @e num_coins coins, calculated during the
+ * "age-withdraw" operation.
+ */
+ struct CoinOutputState *coin_outputs;
+
+ /**
+ * The index returned by the exchange for the "age-withdraw" operation,
+ * of the kappa coin candidates that we do not disclose and keep.
+ */
+ uint8_t noreveal_index;
+
+ /**
+ * The blinded hashes of the non-revealed (to keep) @e num_coins coins.
+ */
+ const struct TALER_BlindedCoinHashP *blinded_coin_hs;
+
+ /**
+ * The hash of the commitment, needed for the reveal step.
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
+ * a request for KYC.
+ */
+ uint64_t requirement_row;
+
+};
+
+/**
+ * Callback for the "age-withdraw" ooperation; It checks that the response
+ * code is expected and store the exchange signature in the state.
+ *
+ * @param cls Closure of type `struct AgeWithdrawState *`
+ * @param response Response details
+ */
+static void
+age_withdraw_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawResponse *response)
+{
+ struct AgeWithdrawState *aws = cls;
+ struct TALER_TESTING_Interpreter *is = aws->is;
+
+ aws->handle = NULL;
+ if (aws->expected_response_code != response->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status_with_body (is,
+ response->hr.http_status,
+ aws->expected_response_code,
+ response->hr.reply);
+ return;
+ }
+
+ switch (response->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ aws->noreveal_index = response->details.ok.noreveal_index;
+ aws->h_commitment = response->details.ok.h_commitment;
+
+ GNUNET_assert (aws->num_coins == response->details.ok.num_coins);
+ for (size_t n = 0; n < aws->num_coins; n++)
+ {
+ aws->coin_outputs[n].details = response->details.ok.coin_details[n];
+ TALER_age_commitment_proof_deep_copy (
+ &response->details.ok.coin_details[n].age_commitment_proof,
+ &aws->coin_outputs[n].details.age_commitment_proof);
+ }
+ aws->blinded_coin_hs = response->details.ok.blinded_coin_hs;
+ break;
+ case MHD_HTTP_FORBIDDEN:
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_GONE:
+ /* nothing to check */
+ break;
+ case MHD_HTTP_CONFLICT:
+ /* TODO[oec]: Add this to the response-type and handle it here */
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ default:
+ /* Unsupported status code (by test harness) */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "test command for age-withdraw not support status code %u, body:\n"
+ ">>%s<<\n",
+ response->hr.http_status,
+ json_dumps (response->hr.reply, JSON_INDENT (2)));
+ GNUNET_break (0);
+ break;
+ }
+
+ /* We are done with this command, pick the next one */
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command for age-withdraw.
+ */
+static void
+age_withdraw_run (
+ void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AgeWithdrawState *aws = cls;
+ struct TALER_EXCHANGE_Keys *keys = TALER_TESTING_get_keys (is);
+ const struct TALER_ReservePrivateKeyP *rp;
+ const struct TALER_TESTING_Command *create_reserve;
+ const struct TALER_EXCHANGE_DenomPublicKey *dpk;
+
+ aws->is = is;
+
+ /* Prepare the reserve related data */
+ create_reserve
+ = TALER_TESTING_interpreter_lookup_command (
+ is,
+ aws->reserve_reference);
+
+ if (NULL == create_reserve)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_priv (create_reserve,
+ &rp))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (NULL == aws->exchange_url)
+ aws->exchange_url
+ = GNUNET_strdup (TALER_TESTING_get_exchange_url (is));
+ aws->reserve_priv = *rp;
+ GNUNET_CRYPTO_eddsa_key_get_public (&aws->reserve_priv.eddsa_priv,
+ &aws->reserve_pub.eddsa_pub);
+ aws->reserve_payto_uri
+ = TALER_reserve_make_payto (aws->exchange_url,
+ &aws->reserve_pub);
+
+ aws->coin_inputs = GNUNET_new_array (
+ aws->num_coins,
+ struct TALER_EXCHANGE_AgeWithdrawCoinInput);
+
+ for (unsigned int i = 0; i<aws->num_coins; i++)
+ {
+ struct TALER_EXCHANGE_AgeWithdrawCoinInput *input = &aws->coin_inputs[i];
+ struct CoinOutputState *cos = &aws->coin_outputs[i];
+
+ /* randomly create the secrets for the kappa coin-candidates */
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &input->secrets,
+ sizeof(input->secrets));
+ /* Find denomination */
+ dpk = TALER_TESTING_find_pk (keys,
+ &cos->amount,
+ true); /* _always_ use denominations with age-striction */
+ if (NULL == dpk)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to determine denomination key for amount at %s\n",
+ (NULL != cmd) ? cmd->label : "<retried command>");
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ /* We copy the denomination key, as re-querying /keys
+ * would free the old one. */
+ input->denom_pub = TALER_EXCHANGE_copy_denomination_key (dpk);
+ cos->reserve_history.type = TALER_EXCHANGE_RTT_AGEWITHDRAWAL;
+ GNUNET_assert (0 <=
+ TALER_amount_add (&cos->reserve_history.amount,
+ &cos->amount,
+ &input->denom_pub->fees.withdraw));
+ cos->reserve_history.details.withdraw.fee = input->denom_pub->fees.withdraw;
+ }
+
+ /* Execute the age-withdraw protocol */
+ aws->handle =
+ TALER_EXCHANGE_age_withdraw (
+ TALER_TESTING_interpreter_get_context (is),
+ keys,
+ TALER_TESTING_get_exchange_url (is),
+ rp,
+ aws->num_coins,
+ aws->coin_inputs,
+ aws->max_age,
+ &age_withdraw_cb,
+ aws);
+
+ if (NULL == aws->handle)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "age withdraw" CMD, and possibly cancel a
+ * pending operation thereof
+ *
+ * @param cls Closure of type `struct AgeWithdrawState`
+ * @param cmd The command being freed.
+ */
+static void
+age_withdraw_cleanup (
+ void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AgeWithdrawState *aws = cls;
+
+ if (NULL != aws->handle)
+ {
+ TALER_TESTING_command_incomplete (aws->is,
+ cmd->label);
+ TALER_EXCHANGE_age_withdraw_cancel (aws->handle);
+ aws->handle = NULL;
+ }
+
+ if (NULL != aws->coin_inputs)
+ {
+ for (size_t n = 0; n < aws->num_coins; n++)
+ {
+ struct TALER_EXCHANGE_AgeWithdrawCoinInput *in = &aws->coin_inputs[n];
+ struct CoinOutputState *out = &aws->coin_outputs[n];
+
+ if (NULL != in && NULL != in->denom_pub)
+ {
+ TALER_EXCHANGE_destroy_denomination_key (in->denom_pub);
+ in->denom_pub = NULL;
+ }
+ if (NULL != out)
+ TALER_age_commitment_proof_free (&out->details.age_commitment_proof);
+ }
+ GNUNET_free (aws->coin_inputs);
+ }
+ GNUNET_free (aws->coin_outputs);
+ GNUNET_free (aws->exchange_url);
+ GNUNET_free (aws->reserve_payto_uri);
+ GNUNET_free (aws);
+}
+
+
+/**
+ * Offer internal data of a "age withdraw" CMD state to other commands.
+ *
+ * @param cls Closure of type `struct AgeWithdrawState`
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param idx index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+age_withdraw_traits (
+ void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int idx)
+{
+ struct AgeWithdrawState *aws = cls;
+ uint8_t k = aws->noreveal_index;
+ struct TALER_EXCHANGE_AgeWithdrawCoinInput *in = &aws->coin_inputs[idx];
+ struct CoinOutputState *out = &aws->coin_outputs[idx];
+ struct TALER_EXCHANGE_AgeWithdrawCoinPrivateDetails *details =
+ &aws->coin_outputs[idx].details;
+ struct TALER_TESTING_Trait traits[] = {
+ /* history entry MUST be first due to response code logic below! */
+ TALER_TESTING_make_trait_reserve_history (idx,
+ &out->reserve_history),
+ TALER_TESTING_make_trait_denom_pub (idx,
+ in->denom_pub),
+ TALER_TESTING_make_trait_reserve_priv (&aws->reserve_priv),
+ TALER_TESTING_make_trait_reserve_pub (&aws->reserve_pub),
+ TALER_TESTING_make_trait_amounts (idx,
+ &out->amount),
+ /* TODO[oec]: add legal requirement to response and handle it here, as well
+ TALER_TESTING_make_trait_legi_requirement_row (&aws->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&aws->h_payto),
+ */
+ TALER_TESTING_make_trait_h_blinded_coin (idx,
+ &aws->blinded_coin_hs[idx]),
+ TALER_TESTING_make_trait_payto_uri (aws->reserve_payto_uri),
+ TALER_TESTING_make_trait_exchange_url (aws->exchange_url),
+ TALER_TESTING_make_trait_coin_priv (idx,
+ &details->coin_priv),
+ TALER_TESTING_make_trait_planchet_secrets (idx,
+ &in->secrets[k]),
+ TALER_TESTING_make_trait_blinding_key (idx,
+ &details->blinding_key),
+ TALER_TESTING_make_trait_exchange_wd_value (idx,
+ &details->alg_values),
+ TALER_TESTING_make_trait_age_commitment_proof (
+ idx,
+ &details->age_commitment_proof),
+ TALER_TESTING_make_trait_h_age_commitment (
+ idx,
+ &details->h_age_commitment),
+ };
+
+ if (idx >= aws->num_coins)
+ return GNUNET_NO;
+
+ return TALER_TESTING_get_trait ((aws->expected_response_code == MHD_HTTP_OK)
+ ? &traits[0] /* we have reserve history */
+ : &traits[1], /* skip reserve history */
+ ret,
+ trait,
+ idx);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_age_withdraw (const char *label,
+ const char *reserve_reference,
+ uint8_t max_age,
+ unsigned int expected_response_code,
+ const char *amount,
+ ...)
+{
+ struct AgeWithdrawState *aws;
+ unsigned int cnt;
+ va_list ap;
+
+ aws = GNUNET_new (struct AgeWithdrawState);
+ aws->reserve_reference = reserve_reference;
+ aws->expected_response_code = expected_response_code;
+ aws->mask = TALER_extensions_get_age_restriction_mask ();
+ aws->max_age = TALER_get_lowest_age (&aws->mask, max_age);
+
+ cnt = 1;
+ va_start (ap, amount);
+ while (NULL != (va_arg (ap, const char *)))
+ cnt++;
+ aws->num_coins = cnt;
+ aws->coin_outputs = GNUNET_new_array (cnt,
+ struct CoinOutputState);
+ va_end (ap);
+ va_start (ap, amount);
+
+ for (unsigned int i = 0; i<aws->num_coins; i++)
+ {
+ struct CoinOutputState *out = &aws->coin_outputs[i];
+ if (GNUNET_OK !=
+ TALER_string_to_amount (amount,
+ &out->amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %s\n",
+ amount,
+ label);
+ GNUNET_assert (0);
+ }
+ /* move on to next vararg! */
+ amount = va_arg (ap, const char *);
+ }
+
+ GNUNET_assert (NULL == amount);
+ va_end (ap);
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = aws,
+ .label = label,
+ .run = &age_withdraw_run,
+ .cleanup = &age_withdraw_cleanup,
+ .traits = &age_withdraw_traits,
+ };
+
+ return cmd;
+ }
+}
+
+
+/**
+ * The state for the age-withdraw-reveal operation
+ */
+struct AgeWithdrawRevealState
+{
+ /**
+ * The reference to the CMD resembling the previous call to age-withdraw
+ */
+ const char *age_withdraw_reference;
+
+ /**
+ * The state to the previous age-withdraw command
+ */
+ const struct AgeWithdrawState *aws;
+
+ /**
+ * The expected response code from the call to the
+ * age-withdraw-reveal operation
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state (during command)
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * The handle to the reveal-operation
+ */
+ struct TALER_EXCHANGE_AgeWithdrawRevealHandle *handle;
+
+
+ /**
+ * Number of coins, extracted form the age withdraw command
+ */
+ size_t num_coins;
+
+ /**
+ * The signatures of the @e num_coins coins returned
+ */
+ struct TALER_DenominationSignature *denom_sigs;
+
+};
+
+/*
+ * Callback for the reveal response
+ *
+ * @param cls Closure of type `struct AgeWithdrawRevealState`
+ * @param awr The response
+ */
+static void
+age_withdraw_reveal_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_AgeWithdrawRevealResponse *response)
+{
+ struct AgeWithdrawRevealState *awrs = cls;
+ struct TALER_TESTING_Interpreter *is = awrs->is;
+
+ awrs->handle = NULL;
+ if (awrs->expected_response_code != response->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status_with_body (is,
+ response->hr.http_status,
+ awrs->expected_response_code,
+ response->hr.reply);
+ return;
+ }
+ switch (response->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ {
+ const struct AgeWithdrawState *aws = awrs->aws;
+ GNUNET_assert (awrs->num_coins == response->details.ok.num_sigs);
+ awrs->denom_sigs = GNUNET_new_array (awrs->num_coins,
+ struct TALER_DenominationSignature);
+ for (size_t n = 0; n < awrs->num_coins; n++)
+ {
+ GNUNET_assert (GNUNET_OK ==
+ TALER_denom_sig_unblind (
+ &awrs->denom_sigs[n],
+ &response->details.ok.blinded_denom_sigs[n],
+ &aws->coin_outputs[n].details.blinding_key,
+ &aws->coin_outputs[n].details.h_coin_pub,
+ &aws->coin_outputs[n].details.alg_values,
+ &aws->coin_inputs[n].denom_pub->key));
+ TALER_denom_sig_free (&awrs->denom_sigs[n]);
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "age-withdraw reveal success!\n");
+ GNUNET_free (awrs->denom_sigs);
+ }
+ break;
+ case MHD_HTTP_NOT_FOUND:
+ case MHD_HTTP_FORBIDDEN:
+ /* nothing to check */
+ break;
+ /* TODO[oec]: handle more cases !? */
+ default:
+ /* Unsupported status code (by test harness) */
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Age withdraw reveal test command does not support status code %u\n",
+ response->hr.http_status);
+ GNUNET_break (0);
+ break;
+ }
+
+ /* We are done with this command, pick the next one */
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command for age-withdraw-reveal
+ */
+static void
+age_withdraw_reveal_run (
+ void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AgeWithdrawRevealState *awrs = cls;
+ const struct TALER_TESTING_Command *age_withdraw_cmd;
+ const struct AgeWithdrawState *aws;
+
+ (void) cmd;
+ awrs->is = is;
+
+ /*
+ * Get the command and state for the previous call to "age witdraw"
+ */
+ age_withdraw_cmd =
+ TALER_TESTING_interpreter_lookup_command (is,
+ awrs->age_withdraw_reference);
+ if (NULL == age_withdraw_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (age_withdraw_cmd->run == age_withdraw_run);
+ aws = age_withdraw_cmd->cls;
+ awrs->aws = aws;
+ awrs->num_coins = aws->num_coins;
+
+ awrs->handle =
+ TALER_EXCHANGE_age_withdraw_reveal (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ aws->num_coins,
+ aws->coin_inputs,
+ aws->noreveal_index,
+ &aws->h_commitment,
+ &aws->reserve_pub,
+ age_withdraw_reveal_cb,
+ awrs);
+}
+
+
+/**
+ * Free the state of a "age-withdraw-reveal" CMD, and possibly
+ * cancel a pending operation thereof
+ *
+ * @param cls Closure of type `struct AgeWithdrawRevealState`
+ * @param cmd The command being freed.
+ */
+static void
+age_withdraw_reveal_cleanup (
+ void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AgeWithdrawRevealState *awrs = cls;
+
+ if (NULL != awrs->handle)
+ {
+ TALER_TESTING_command_incomplete (awrs->is,
+ cmd->label);
+ TALER_EXCHANGE_age_withdraw_reveal_cancel (awrs->handle);
+ awrs->handle = NULL;
+ }
+ GNUNET_free (awrs->denom_sigs);
+ awrs->denom_sigs = NULL;
+ GNUNET_free (awrs);
+}
+
+
+/**
+ * Offer internal data of a "age withdraw reveal" CMD state to other commands.
+ *
+ * @param cls Closure of they `struct AgeWithdrawRevealState`
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param idx index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+age_withdraw_reveal_traits (
+ void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int idx)
+{
+ struct AgeWithdrawRevealState *awrs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_denom_sig (idx,
+ &awrs->denom_sigs[idx]),
+ /* FIXME: shall we provide the traits from the previous
+ * call to "age withdraw" as well? */
+ };
+
+ if (idx >= awrs->num_coins)
+ return GNUNET_NO;
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ idx);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_age_withdraw_reveal (
+ const char *label,
+ const char *age_withdraw_reference,
+ unsigned int expected_response_code)
+{
+ struct AgeWithdrawRevealState *awrs =
+ GNUNET_new (struct AgeWithdrawRevealState);
+
+ awrs->age_withdraw_reference = age_withdraw_reference;
+ awrs->expected_response_code = expected_response_code;
+
+ struct TALER_TESTING_Command cmd = {
+ .cls = awrs,
+ .label = label,
+ .run = age_withdraw_reveal_run,
+ .cleanup = age_withdraw_reveal_cleanup,
+ .traits = age_withdraw_reveal_traits,
+ };
+
+ return cmd;
+}
+
+
+/* end of testing_api_cmd_age_withdraw.c */
diff --git a/src/testing/testing_api_cmd_auditor_add.c b/src/testing/testing_api_cmd_auditor_add.c
index 8362b66c9..ac9c2c8fb 100644
--- a/src/testing/testing_api_cmd_auditor_add.c
+++ b/src/testing/testing_api_cmd_auditor_add.c
@@ -18,7 +18,7 @@
*/
/**
* @file testing/testing_api_cmd_auditor_add.c
- * @brief command for testing /auditor_add.
+ * @brief command for testing auditor_add
* @author Christian Grothoff
*/
#include "platform.h"
@@ -62,27 +62,22 @@ struct AuditorAddState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param aer response details
*/
static void
-auditor_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+auditor_add_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementAuditorEnableResponse *aer)
{
struct AuditorAddState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &aer->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -104,10 +99,43 @@ auditor_add_run (void *cls,
struct AuditorAddState *ds = cls;
struct GNUNET_TIME_Timestamp now;
struct TALER_MasterSignatureP master_sig;
+ const struct TALER_AuditorPublicKeyP *auditor_pub;
+ const struct TALER_TESTING_Command *auditor_cmd;
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const char *exchange_url;
+ const char *auditor_url;
(void) cmd;
now = GNUNET_TIME_timestamp_get ();
ds->is = is;
+
+ auditor_cmd = TALER_TESTING_interpreter_get_command (is,
+ "auditor");
+ if (NULL == auditor_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
+ &auditor_pub));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_url (auditor_cmd,
+ &auditor_url));
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+
+
if (ds->bad_sig)
{
memset (&master_sig,
@@ -116,17 +144,22 @@ auditor_add_run (void *cls,
}
else
{
- TALER_exchange_offline_auditor_add_sign (&is->auditor_pub,
- is->auditor_url,
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
+ TALER_exchange_offline_auditor_add_sign (auditor_pub,
+ auditor_url,
now,
- &is->master_priv,
+ master_priv,
&master_sig);
}
ds->dh = TALER_EXCHANGE_management_enable_auditor (
- is->ctx,
- is->exchange_url,
- &is->auditor_pub,
- is->auditor_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ auditor_pub,
+ auditor_url,
"test-case auditor", /* human-readable auditor name */
now,
&master_sig,
@@ -156,10 +189,8 @@ auditor_add_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_management_enable_auditor_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_auditor_add_denom_sig.c b/src/testing/testing_api_cmd_auditor_add_denom_sig.c
index 3d7ea82f1..6b7776896 100644
--- a/src/testing/testing_api_cmd_auditor_add_denom_sig.c
+++ b/src/testing/testing_api_cmd_auditor_add_denom_sig.c
@@ -67,27 +67,22 @@ struct AuditorAddDenomSigState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param adr response details
*/
static void
-denom_sig_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+denom_sig_add_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_AuditorAddDenominationResponse *adr)
{
struct AuditorAddDenomSigState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -110,6 +105,11 @@ auditor_add_run (void *cls,
struct TALER_AuditorSignatureP auditor_sig;
struct TALER_DenominationHashP h_denom_pub;
const struct TALER_EXCHANGE_DenomPublicKey *dk;
+ const struct TALER_AuditorPublicKeyP *auditor_pub;
+ const struct TALER_TESTING_Command *auditor_cmd;
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const char *exchange_url;
+ const char *auditor_url;
(void) cmd;
/* Get denom pub from trait */
@@ -118,7 +118,6 @@ auditor_add_run (void *cls,
denom_cmd = TALER_TESTING_interpreter_lookup_command (is,
ds->denom_ref);
-
if (NULL == denom_cmd)
{
GNUNET_break (0);
@@ -131,6 +130,31 @@ auditor_add_run (void *cls,
&dk));
}
ds->is = is;
+ auditor_cmd = TALER_TESTING_interpreter_get_command (is,
+ "auditor");
+ if (NULL == auditor_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
+ &auditor_pub));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_url (auditor_cmd,
+ &auditor_url));
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
if (ds->bad_sig)
{
memset (&auditor_sig,
@@ -139,28 +163,33 @@ auditor_add_run (void *cls,
}
else
{
- struct TALER_MasterPublicKeyP master_pub;
+ const struct TALER_MasterPublicKeyP *master_pub;
+ const struct TALER_AuditorPrivateKeyP *auditor_priv;
- GNUNET_CRYPTO_eddsa_key_get_public (&is->master_priv.eddsa_priv,
- &master_pub.eddsa_pub);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_pub (exchange_cmd,
+ &master_pub));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_priv (auditor_cmd,
+ &auditor_priv));
TALER_auditor_denom_validity_sign (
- is->auditor_url,
+ auditor_url,
&dk->h_key,
- &master_pub,
+ master_pub,
dk->valid_from,
dk->withdraw_valid_until,
dk->expire_deposit,
dk->expire_legal,
&dk->value,
&dk->fees,
- &is->auditor_priv,
+ auditor_priv,
&auditor_sig);
}
ds->dh = TALER_EXCHANGE_add_auditor_denomination (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
&h_denom_pub,
- &is->auditor_pub,
+ auditor_pub,
&auditor_sig,
&denom_sig_add_cb,
ds);
@@ -188,10 +217,8 @@ auditor_add_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_add_auditor_denomination_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_auditor_del.c b/src/testing/testing_api_cmd_auditor_del.c
index de03d1632..8256bc1c7 100644
--- a/src/testing/testing_api_cmd_auditor_del.c
+++ b/src/testing/testing_api_cmd_auditor_del.c
@@ -62,27 +62,23 @@ struct AuditorDelState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param adr response details
*/
static void
-auditor_del_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+auditor_del_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ManagementAuditorDisableResponse *adr)
+
{
struct AuditorDelState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -104,10 +100,36 @@ auditor_del_run (void *cls,
struct AuditorDelState *ds = cls;
struct TALER_MasterSignatureP master_sig;
struct GNUNET_TIME_Timestamp now;
+ const struct TALER_AuditorPublicKeyP *auditor_pub;
+ const struct TALER_TESTING_Command *auditor_cmd;
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const char *exchange_url;
(void) cmd;
now = GNUNET_TIME_timestamp_get ();
ds->is = is;
+ auditor_cmd = TALER_TESTING_interpreter_get_command (is,
+ "auditor");
+ if (NULL == auditor_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_auditor_pub (auditor_cmd,
+ &auditor_pub));
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
if (ds->bad_sig)
{
memset (&master_sig,
@@ -116,15 +138,20 @@ auditor_del_run (void *cls,
}
else
{
- TALER_exchange_offline_auditor_del_sign (&is->auditor_pub,
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
+ TALER_exchange_offline_auditor_del_sign (auditor_pub,
now,
- &is->master_priv,
+ master_priv,
&master_sig);
}
ds->dh = TALER_EXCHANGE_management_disable_auditor (
- is->ctx,
- is->exchange_url,
- &is->auditor_pub,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ auditor_pub,
now,
&master_sig,
&auditor_del_cb,
@@ -153,10 +180,8 @@ auditor_del_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_management_disable_auditor_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
index d99b12937..9477a5d7e 100644
--- a/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
+++ b/src/testing/testing_api_cmd_auditor_deposit_confirmation.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018, 2021 Taler Systems SA
+ Copyright (C) 2018-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -59,9 +59,9 @@ struct DepositConfirmationState
const char *amount_without_fee;
/**
- * Which coin of the @e deposit_reference should we confirm.
+ * How many coins were there in the @e deposit_reference?
*/
- unsigned int coin_index;
+ unsigned int num_coins;
/**
* DepositConfirmation handle while operation is running.
@@ -69,11 +69,6 @@ struct DepositConfirmationState
struct TALER_AUDITOR_DepositConfirmationHandle *dc;
/**
- * Auditor connection.
- */
- struct TALER_AUDITOR_Handle *auditor;
-
- /**
* Interpreter state.
*/
struct TALER_TESTING_Interpreter *is;
@@ -125,8 +120,7 @@ do_retry (void *cls)
struct DepositConfirmationState *dcs = cls;
dcs->retry_task = NULL;
- dcs->is->commands[dcs->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (dcs->is);
deposit_confirmation_run (dcs,
NULL,
dcs->is);
@@ -138,13 +132,15 @@ do_retry (void *cls)
* to check if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param dcr response details
*/
static void
-deposit_confirmation_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr)
+deposit_confirmation_cb (
+ void *cls,
+ const struct TALER_AUDITOR_DepositConfirmationResponse *dcr)
{
struct DepositConfirmationState *dcs = cls;
+ const struct TALER_AUDITOR_HttpResponse *hr = &dcr->hr;
dcs->dc = NULL;
if (dcs->expected_response_code != hr->http_status)
@@ -166,21 +162,16 @@ deposit_confirmation_cb (void *cls,
else
dcs->backoff = GNUNET_TIME_randomized_backoff (dcs->backoff,
MAX_BACKOFF);
- dcs->is->commands[dcs->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (dcs->is);
dcs->retry_task = GNUNET_SCHEDULER_add_delayed (dcs->backoff,
&do_retry,
dcs);
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- dcs->is->commands[dcs->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply, stderr, 0);
- TALER_TESTING_interpreter_fail (dcs->is);
+ TALER_TESTING_unexpected_status (dcs->is,
+ hr->http_status,
+ dcs->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (dcs->is);
@@ -199,7 +190,7 @@ deposit_confirmation_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
- static struct TALER_ExtensionContractHashP no_h_extensions;
+ static struct TALER_ExtensionPolicyHashP no_h_policy;
struct DepositConfirmationState *dcs = cls;
const struct TALER_TESTING_Command *deposit_cmd;
struct TALER_MerchantWireHashP h_wire;
@@ -210,20 +201,43 @@ deposit_confirmation_run (void *cls,
struct GNUNET_TIME_Timestamp refund_deadline
= GNUNET_TIME_UNIT_ZERO_TS;
struct TALER_Amount amount_without_fee;
- struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct TALER_CoinSpendPublicKeyP coin_pubs[dcs->num_coins];
+ const struct TALER_CoinSpendPublicKeyP *coin_pubps[dcs->num_coins];
+ const struct TALER_CoinSpendSignatureP *coin_sigps[dcs->num_coins];
const struct TALER_MerchantPrivateKeyP *merchant_priv;
struct TALER_MerchantPublicKeyP merchant_pub;
const struct TALER_ExchangePublicKeyP *exchange_pub;
const struct TALER_ExchangeSignatureP *exchange_sig;
const json_t *wire_details;
const json_t *contract_terms;
- const struct TALER_CoinSpendPrivateKeyP *coin_priv;
const struct TALER_EXCHANGE_Keys *keys;
const struct TALER_EXCHANGE_SigningPublicKey *spk;
+ const char *auditor_url;
(void) cmd;
dcs->is = is;
GNUNET_assert (NULL != dcs->deposit_reference);
+ {
+ const struct TALER_TESTING_Command *auditor_cmd;
+
+ auditor_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "auditor");
+ if (NULL == auditor_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_auditor_url (auditor_cmd,
+ &auditor_url))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
deposit_cmd
= TALER_TESTING_interpreter_lookup_command (is,
dcs->deposit_reference);
@@ -236,22 +250,22 @@ deposit_confirmation_run (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_exchange_pub (deposit_cmd,
- dcs->coin_index,
+ 0,
&exchange_pub));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_exchange_sig (deposit_cmd,
- dcs->coin_index,
+ 0,
&exchange_sig));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_timestamp (deposit_cmd,
- dcs->coin_index,
+ 0,
&exchange_timestamp));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_wire_deadline (deposit_cmd,
- dcs->coin_index,
+ 0,
&wire_deadline));
GNUNET_assert (NULL != exchange_timestamp);
- keys = TALER_EXCHANGE_get_keys (dcs->is->exchange);
+ keys = TALER_TESTING_get_keys (is);
GNUNET_assert (NULL != keys);
spk = TALER_EXCHANGE_get_signing_key_info (keys,
exchange_pub);
@@ -270,12 +284,23 @@ deposit_confirmation_run (void *cls,
GNUNET_assert (GNUNET_OK ==
TALER_JSON_merchant_wire_signature_hash (wire_details,
&h_wire));
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_get_trait_coin_priv (deposit_cmd,
- dcs->coin_index,
- &coin_priv));
- GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
- &coin_pub.eddsa_pub);
+
+ for (unsigned int i = 0; i<dcs->num_coins; i++)
+ {
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_coin_priv (deposit_cmd,
+ i,
+ &coin_priv));
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
+ &coin_pubs[i].eddsa_pub);
+ coin_pubps[i] = &coin_pubs[i];
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_coin_sig (deposit_cmd,
+ i,
+ &coin_sigps[i]));
+ }
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_merchant_priv (deposit_cmd,
&merchant_priv));
@@ -308,25 +333,29 @@ deposit_confirmation_run (void *cls,
if (GNUNET_TIME_absolute_is_zero (refund_deadline.abs_time))
refund_deadline = timestamp;
}
- dcs->dc = TALER_AUDITOR_deposit_confirmation (dcs->auditor,
- &h_wire,
- &no_h_extensions,
- &h_contract_terms,
- *exchange_timestamp,
- *wire_deadline,
- refund_deadline,
- &amount_without_fee,
- &coin_pub,
- &merchant_pub,
- exchange_pub,
- exchange_sig,
- &keys->master_pub,
- spk->valid_from,
- spk->valid_until,
- spk->valid_legal,
- &spk->master_sig,
- &deposit_confirmation_cb,
- dcs);
+ dcs->dc = TALER_AUDITOR_deposit_confirmation (
+ TALER_TESTING_interpreter_get_context (is),
+ auditor_url,
+ &h_wire,
+ &no_h_policy,
+ &h_contract_terms,
+ *exchange_timestamp,
+ *wire_deadline,
+ refund_deadline,
+ &amount_without_fee,
+ dcs->num_coins,
+ coin_pubps,
+ coin_sigps,
+ &merchant_pub,
+ exchange_pub,
+ exchange_sig,
+ &keys->master_pub,
+ spk->valid_from,
+ spk->valid_until,
+ spk->valid_legal,
+ &spk->master_sig,
+ &deposit_confirmation_cb,
+ dcs);
if (NULL == dcs->dc)
{
@@ -353,10 +382,8 @@ deposit_confirmation_cleanup (void *cls,
if (NULL != dcs->dc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- dcs->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (dcs->is,
+ cmd->label);
TALER_AUDITOR_deposit_confirmation_cancel (dcs->dc);
dcs->dc = NULL;
}
@@ -371,18 +398,16 @@ deposit_confirmation_cleanup (void *cls,
struct TALER_TESTING_Command
TALER_TESTING_cmd_deposit_confirmation (const char *label,
- struct TALER_AUDITOR_Handle *auditor,
const char *deposit_reference,
- unsigned int coin_index,
+ unsigned int num_coins,
const char *amount_without_fee,
unsigned int expected_response_code)
{
struct DepositConfirmationState *dcs;
dcs = GNUNET_new (struct DepositConfirmationState);
- dcs->auditor = auditor;
dcs->deposit_reference = deposit_reference;
- dcs->coin_index = coin_index;
+ dcs->num_coins = num_coins;
dcs->amount_without_fee = amount_without_fee;
dcs->expected_response_code = expected_response_code;
diff --git a/src/testing/testing_api_cmd_auditor_exchanges.c b/src/testing/testing_api_cmd_auditor_exchanges.c
deleted file mode 100644
index 1e412b2d1..000000000
--- a/src/testing/testing_api_cmd_auditor_exchanges.c
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_auditor_exchanges.c
- * @brief command for testing /exchanges of the auditor
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_auditor_service.h"
-#include "taler_testing_lib.h"
-#include "taler_signatures.h"
-#include "backoff.h"
-
-/**
- * How long do we wait AT MOST when retrying?
- */
-#define MAX_BACKOFF GNUNET_TIME_relative_multiply ( \
- GNUNET_TIME_UNIT_MILLISECONDS, 100)
-
-
-/**
- * How often do we retry before giving up?
- */
-#define NUM_RETRIES 5
-
-
-/**
- * State for a "deposit confirmation" CMD.
- */
-struct ExchangesState
-{
-
- /**
- * Exchanges handle while operation is running.
- */
- struct TALER_AUDITOR_ListExchangesHandle *leh;
-
- /**
- * Auditor connection.
- */
- struct TALER_AUDITOR_Handle *auditor;
-
- /**
- * Interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Task scheduled to try later.
- */
- struct GNUNET_SCHEDULER_Task *retry_task;
-
- /**
- * How long do we wait until we retry?
- */
- struct GNUNET_TIME_Relative backoff;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int expected_response_code;
-
- /**
- * URL of the exchange expected to be included in the response.
- */
- const char *exchange_url;
-
- /**
- * How often should we retry on (transient) failures?
- */
- unsigned int do_retry;
-
-};
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-exchanges_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is);
-
-
-/**
- * Task scheduled to re-try #exchanges_run.
- *
- * @param cls a `struct ExchangesState`
- */
-static void
-do_retry (void *cls)
-{
- struct ExchangesState *es = cls;
-
- es->retry_task = NULL;
- es->is->commands[es->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
- exchanges_run (es,
- NULL,
- es->is);
-}
-
-
-/**
- * Callback to analyze the /exchanges response.
- *
- * @param cls closure.
- * @param hr HTTP response details
- * @param num_exchanges length of the @a ei array
- * @param ei array with information about the exchanges
- */
-static void
-exchanges_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- unsigned int num_exchanges,
- const struct TALER_AUDITOR_ExchangeInfo *ei)
-{
- struct ExchangesState *es = cls;
-
- es->leh = NULL;
- if (es->expected_response_code != hr->http_status)
- {
- if (0 != es->do_retry)
- {
- es->do_retry--;
- if ( (0 == hr->http_status) ||
- (TALER_EC_GENERIC_DB_SOFT_FAILURE == hr->ec) ||
- (MHD_HTTP_INTERNAL_SERVER_ERROR == hr->http_status) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Retrying list exchanges failed with %u/%d\n",
- hr->http_status,
- (int) hr->ec);
- /* on DB conflicts, do not use backoff */
- if (TALER_EC_GENERIC_DB_SOFT_FAILURE == hr->ec)
- es->backoff = GNUNET_TIME_UNIT_ZERO;
- else
- es->backoff = GNUNET_TIME_randomized_backoff (es->backoff,
- MAX_BACKOFF);
- es->is->commands[es->is->ip].num_tries++;
- es->retry_task = GNUNET_SCHEDULER_add_delayed (es->backoff,
- &do_retry,
- es);
- return;
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- es->is->commands[es->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (es->is);
- return;
- }
- if (NULL != es->exchange_url)
- {
- unsigned int found = GNUNET_NO;
-
- for (unsigned int i = 0;
- i<num_exchanges;
- i++)
- if (0 == strcmp (es->exchange_url,
- ei[i].exchange_url))
- found = GNUNET_YES;
- if (GNUNET_NO == found)
- {
- TALER_LOG_ERROR ("Exchange '%s' doesn't exist at this auditor\n",
- es->exchange_url);
- TALER_TESTING_interpreter_fail (es->is);
- return;
- }
-
- TALER_LOG_DEBUG ("Exchange '%s' exists at this auditor!\n",
- es->exchange_url);
- }
- TALER_TESTING_interpreter_next (es->is);
-}
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-exchanges_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct ExchangesState *es = cls;
-
- (void) cmd;
- es->is = is;
- es->leh = TALER_AUDITOR_list_exchanges
- (is->auditor,
- &exchanges_cb,
- es);
-
- if (NULL == es->leh)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- return;
-}
-
-
-/**
- * Free the state of a "exchanges" CMD, and possibly cancel a
- * pending operation thereof.
- *
- * @param cls closure, a `struct ExchangesState`
- * @param cmd the command which is being cleaned up.
- */
-static void
-exchanges_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct ExchangesState *es = cls;
-
- if (NULL != es->leh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- es->is->ip,
- cmd->label);
- TALER_AUDITOR_list_exchanges_cancel (es->leh);
- es->leh = NULL;
- }
- if (NULL != es->retry_task)
- {
- GNUNET_SCHEDULER_cancel (es->retry_task);
- es->retry_task = NULL;
- }
- GNUNET_free (es);
-}
-
-
-/**
- * Offer internal data to other commands.
- *
- * @param cls closure.
- * @param[out] ret set to the wanted data.
- * @param trait name of the trait.
- * @param index index number of the traits to be returned.
- * @return #GNUNET_OK on success
- */
-static int
-exchanges_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- (void) cls;
- (void) ret;
- (void) trait;
- (void) index;
- /* Must define this function because some callbacks
- * look for certain traits on _all_ the commands. */
- return GNUNET_SYSERR;
-}
-
-
-/**
- * Create a "list exchanges" command.
- *
- * @param label command label.
- * @param auditor auditor connection.
- * @param expected_response_code expected HTTP response code.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges (const char *label,
- struct TALER_AUDITOR_Handle *auditor,
- unsigned int expected_response_code)
-{
- struct ExchangesState *es;
-
- es = GNUNET_new (struct ExchangesState);
- es->auditor = auditor;
- es->expected_response_code = expected_response_code;
-
- {
- struct TALER_TESTING_Command cmd = {
- .cls = es,
- .label = label,
- .run = &exchanges_run,
- .cleanup = &exchanges_cleanup,
- .traits = &exchanges_traits
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Create a "list exchanges" command and check whether
- * a particular exchange belongs to the returned bundle.
- *
- * @param label command label.
- * @param expected_response_code expected HTTP response code.
- * @param exchange_url URL of the exchange supposed to
- * be included in the response.
- * @return the command.
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges_with_url (const char *label,
- unsigned int expected_response_code,
- const char *exchange_url)
-{
- struct ExchangesState *es;
-
- es = GNUNET_new (struct ExchangesState);
- es->expected_response_code = expected_response_code;
- es->exchange_url = exchange_url;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = es,
- .label = label,
- .run = &exchanges_run,
- .cleanup = &exchanges_cleanup,
- .traits = &exchanges_traits
- };
-
- return cmd;
- }
-}
-
-
-/**
- * Modify an exchanges command to enable retries when we get
- * transient errors from the auditor.
- *
- * @param cmd a deposit confirmation command
- * @return the command with retries enabled
- */
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_exchanges_with_retry (struct TALER_TESTING_Command cmd)
-{
- struct ExchangesState *es;
-
- GNUNET_assert (&exchanges_run == cmd.run);
- es = cmd.cls;
- es->do_retry = NUM_RETRIES;
- return cmd;
-}
-
-
-/* end of testing_auditor_api_cmd_exchanges.c */
diff --git a/src/testing/testing_api_cmd_bank_admin_add_incoming.c b/src/testing/testing_api_cmd_bank_admin_add_incoming.c
index 28d251a4f..5c031d0b3 100644
--- a/src/testing/testing_api_cmd_bank_admin_add_incoming.c
+++ b/src/testing/testing_api_cmd_bank_admin_add_incoming.c
@@ -180,8 +180,7 @@ do_retry (void *cls)
struct AdminAddIncomingState *fts = cls;
fts->retry_task = NULL;
- fts->is->commands[fts->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (fts->is);
admin_add_incoming_run (fts,
NULL,
fts->is);
@@ -194,40 +193,54 @@ do_retry (void *cls)
* acceptable.
*
* @param cls closure with the interpreter state
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for
- * successful status request; 0 if the exchange's reply is
- * bogus (fails to follow the protocol)
- * @param ec taler-specific error code, #TALER_EC_NONE on success
- * @param serial_id unique ID of the wire transfer
- * @param timestamp time stamp of the transaction made.
- * @param json raw response
+ * @param air response details
*/
static void
confirmation_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp timestamp,
- const json_t *json)
+ const struct TALER_BANK_AdminAddIncomingResponse *air)
{
struct AdminAddIncomingState *fts = cls;
struct TALER_TESTING_Interpreter *is = fts->is;
- (void) json;
- fts->reserve_history.details.in_details.timestamp = timestamp;
- fts->reserve_history.details.in_details.wire_reference = serial_id;
fts->aih = NULL;
- if (http_status != fts->expected_http_status)
+ /**
+ * Test case not caring about the HTTP status code.
+ * That helps when Fakebank and Libeufin diverge in
+ * the response status code. An example is the
+ * /admin/add-incoming: libeufin return ALWAYS '200 OK'
+ * (see note below) whereas the Fakebank responds with
+ * '409 Conflict' upon a duplicate reserve public key.
+ *
+ * Note: this decision aims at avoiding to put Taler
+ * logic into the Sandbox; that's because banks DO allow
+ * their customers to wire the same subject multiple
+ * times. Hence, instead of triggering any error, libeufin
+ * bounces the payment back in the same way it does for
+ * malformed reserve public keys.
+ */
+ if (-1 == (int) fts->expected_http_status)
{
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ if (air->http_status != fts->expected_http_status)
+ {
+ TALER_TESTING_unexpected_status (is,
+ air->http_status,
+ fts->expected_http_status);
return;
}
- switch (http_status)
+ switch (air->http_status)
{
case MHD_HTTP_OK:
- fts->serial_id = serial_id;
- fts->timestamp = timestamp;
+ fts->reserve_history.details.in_details.timestamp
+ = air->details.ok.timestamp;
+ fts->reserve_history.details.in_details.wire_reference
+ = air->details.ok.serial_id;
+ fts->serial_id
+ = air->details.ok.serial_id;
+ fts->timestamp
+ = air->details.ok.timestamp;
TALER_TESTING_interpreter_next (is);
return;
case MHD_HTTP_UNAUTHORIZED:
@@ -251,22 +264,22 @@ confirmation_cb (void *cls,
if (0 != fts->do_retry)
{
fts->do_retry--;
- if ( (0 == http_status) ||
- (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) ||
- (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
+ if ( (0 == air->http_status) ||
+ (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec) ||
+ (MHD_HTTP_INTERNAL_SERVER_ERROR == air->http_status) )
{
GNUNET_log (
GNUNET_ERROR_TYPE_INFO,
"Retrying fakebank transfer failed with %u/%d\n",
- http_status,
- (int) ec);
+ air->http_status,
+ (int) air->ec);
/* on DB conflicts, do not use backoff */
- if (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec)
+ if (TALER_EC_GENERIC_DB_SOFT_FAILURE == air->ec)
fts->backoff = GNUNET_TIME_UNIT_ZERO;
else
fts->backoff = GNUNET_TIME_randomized_backoff (fts->backoff,
MAX_BACKOFF);
- fts->is->commands[fts->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (fts->is);
fts->retry_task = GNUNET_SCHEDULER_add_delayed (
fts->backoff,
&do_retry,
@@ -279,8 +292,8 @@ confirmation_cb (void *cls,
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Fakebank returned HTTP status %u/%d\n",
- http_status,
- (int) ec);
+ air->http_status,
+ (int) air->ec);
TALER_TESTING_interpreter_fail (is);
}
@@ -301,6 +314,7 @@ admin_add_incoming_run (void *cls,
bool have_public = false;
(void) cmd;
+ fts->is = is;
/* Use reserve public key as subject */
if (NULL != fts->reserve_reference)
{
@@ -351,7 +365,6 @@ admin_add_incoming_run (void *cls,
fts->reserve_history.amount = fts->amount;
fts->reserve_history.details.in_details.sender_url
= (char *) fts->payto_debit_account; /* remember to NOT free this one... */
- fts->is = is;
fts->aih
= TALER_BANK_admin_add_incoming (
TALER_TESTING_interpreter_get_context (is),
@@ -385,9 +398,8 @@ admin_add_incoming_cleanup (void *cls,
if (NULL != fts->aih)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %s did not complete\n",
- cmd->label);
+ TALER_TESTING_command_incomplete (fts->is,
+ cmd->label);
TALER_BANK_admin_add_incoming_cancel (fts->aih);
fts->aih = NULL;
}
@@ -426,12 +438,12 @@ admin_add_incoming_traits (void *cls,
{
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_bank_row (&fts->serial_id),
- TALER_TESTING_make_trait_debit_payto_uri (&fts->payto_debit_account),
- TALER_TESTING_make_trait_payto_uri (&fts->payto_debit_account),
+ TALER_TESTING_make_trait_debit_payto_uri (fts->payto_debit_account),
+ TALER_TESTING_make_trait_payto_uri (fts->payto_debit_account),
/* Used as a marker, content does not matter */
- TALER_TESTING_make_trait_credit_payto_uri (&void_uri),
+ TALER_TESTING_make_trait_credit_payto_uri (void_uri),
TALER_TESTING_make_trait_exchange_bank_account_url (
- &fts->exchange_credit_url),
+ fts->exchange_credit_url),
TALER_TESTING_make_trait_amount (&fts->amount),
TALER_TESTING_make_trait_timestamp (0,
&fts->timestamp),
@@ -451,13 +463,14 @@ admin_add_incoming_traits (void *cls,
{
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_bank_row (&fts->serial_id),
- TALER_TESTING_make_trait_debit_payto_uri (&fts->payto_debit_account),
+ TALER_TESTING_make_trait_debit_payto_uri (fts->payto_debit_account),
/* Used as a marker, content does not matter */
- TALER_TESTING_make_trait_credit_payto_uri (&void_uri),
+ TALER_TESTING_make_trait_credit_payto_uri (void_uri),
TALER_TESTING_make_trait_exchange_bank_account_url (
- &fts->exchange_credit_url),
+ fts->exchange_credit_url),
TALER_TESTING_make_trait_amount (&fts->amount),
- TALER_TESTING_make_trait_timestamp (0, &fts->timestamp),
+ TALER_TESTING_make_trait_timestamp (0,
+ &fts->timestamp),
TALER_TESTING_make_trait_reserve_pub (&fts->reserve_pub),
TALER_TESTING_make_trait_reserve_history (0,
&fts->reserve_history),
diff --git a/src/testing/testing_api_cmd_bank_admin_check.c b/src/testing/testing_api_cmd_bank_admin_check.c
index 21a230834..6406fe2c2 100644
--- a/src/testing/testing_api_cmd_bank_admin_check.c
+++ b/src/testing/testing_api_cmd_bank_admin_check.c
@@ -82,8 +82,30 @@ check_bank_admin_transfer_run (void *cls,
const char *credit_payto;
const struct TALER_ReservePublicKeyP *reserve_pub;
const struct TALER_TESTING_Command *cmd_ref;
+ struct TALER_FAKEBANK_Handle *fakebank;
(void) cmd;
+ {
+ const struct TALER_TESTING_Command *fakebank_cmd;
+
+ fakebank_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "fakebank");
+ if (NULL == fakebank_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_fakebank (fakebank_cmd,
+ &fakebank))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
cmd_ref
= TALER_TESTING_interpreter_lookup_command (is,
bcs->reserve_pub_ref);
@@ -102,7 +124,6 @@ check_bank_admin_transfer_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- TALER_LOG_INFO ("Deposit reference NOT given\n");
debit_payto = bcs->debit_payto;
credit_payto = bcs->credit_payto;
if (GNUNET_OK !=
@@ -110,9 +131,9 @@ check_bank_admin_transfer_run (void *cls,
&amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %u\n",
+ "Failed to parse amount `%s' at %s\n",
bcs->amount,
- is->ip);
+ TALER_TESTING_interpreter_get_current_label (is));
TALER_TESTING_interpreter_fail (is);
return;
}
@@ -123,7 +144,7 @@ check_bank_admin_transfer_run (void *cls,
debit_payto,
debit_account);
if (GNUNET_OK !=
- TALER_FAKEBANK_check_credit (is->fakebank,
+ TALER_FAKEBANK_check_credit (fakebank,
&amount,
debit_account,
credit_account,
diff --git a/src/testing/testing_api_cmd_bank_check.c b/src/testing/testing_api_cmd_bank_check.c
index be4ad3189..77d120e09 100644
--- a/src/testing/testing_api_cmd_bank_check.c
+++ b/src/testing/testing_api_cmd_bank_check.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018-2020 Taler Systems SA
+ Copyright (C) 2018-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -91,26 +91,48 @@ check_bank_transfer_run (void *cls,
struct TALER_Amount amount;
char *debit_account;
char *credit_account;
- const char **exchange_base_url;
- const char **debit_payto;
- const char **credit_payto;
+ const char *exchange_base_url;
+ const char *debit_payto;
+ const char *credit_payto;
+ struct TALER_FAKEBANK_Handle *fakebank;
(void) cmd;
+ {
+ const struct TALER_TESTING_Command *fakebank_cmd;
+
+ fakebank_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "fakebank");
+ if (NULL == fakebank_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_fakebank (fakebank_cmd,
+ &fakebank))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
if (NULL == bcs->deposit_reference)
{
TALER_LOG_INFO ("Deposit reference NOT given\n");
- debit_payto = &bcs->debit_payto;
- credit_payto = &bcs->credit_payto;
- exchange_base_url = &bcs->exchange_base_url;
+ debit_payto = bcs->debit_payto;
+ credit_payto = bcs->credit_payto;
+ exchange_base_url = bcs->exchange_base_url;
if (GNUNET_OK !=
TALER_string_to_amount (bcs->amount,
&amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %u\n",
+ "Failed to parse amount `%s' at %s\n",
bcs->amount,
- is->ip);
+ TALER_TESTING_interpreter_get_current_label (is));
TALER_TESTING_interpreter_fail (is);
return;
}
@@ -145,27 +167,22 @@ check_bank_transfer_run (void *cls,
TALER_TESTING_FAIL (is);
amount = *amount_ptr;
}
-
-
- debit_account = TALER_xtalerbank_account_from_payto (*debit_payto);
- credit_account = TALER_xtalerbank_account_from_payto (*credit_payto);
-
+ debit_account = TALER_xtalerbank_account_from_payto (debit_payto);
+ credit_account = TALER_xtalerbank_account_from_payto (credit_payto);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"converted debit_payto (%s) to debit_account (%s)\n",
- *debit_payto,
+ debit_payto,
debit_account);
-
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"converted credit_payto (%s) to credit_account (%s)\n",
- *credit_payto,
+ credit_payto,
credit_account);
-
if (GNUNET_OK !=
- TALER_FAKEBANK_check_debit (is->fakebank,
+ TALER_FAKEBANK_check_debit (fakebank,
&amount,
debit_account,
credit_account,
- *exchange_base_url,
+ exchange_base_url,
&bcs->wtid))
{
GNUNET_break (0);
@@ -217,7 +234,7 @@ check_bank_transfer_traits (void *cls,
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_wtid (wtid_ptr),
TALER_TESTING_make_trait_exchange_url (
- &bcs->exchange_base_url),
+ bcs->exchange_base_url),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_bank_check_empty.c b/src/testing/testing_api_cmd_bank_check_empty.c
index 84976b0b5..60f00fbb4 100644
--- a/src/testing/testing_api_cmd_bank_check_empty.c
+++ b/src/testing/testing_api_cmd_bank_check_empty.c
@@ -58,9 +58,33 @@ check_bank_empty_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
{
+ struct TALER_FAKEBANK_Handle *fakebank;
+
(void) cls;
(void) cmd;
- if (GNUNET_OK != TALER_FAKEBANK_check_empty (is->fakebank))
+ {
+ const struct TALER_TESTING_Command *fakebank_cmd;
+
+ fakebank_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "fakebank");
+ if (NULL == fakebank_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_fakebank (fakebank_cmd,
+ &fakebank))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ if (GNUNET_OK !=
+ TALER_FAKEBANK_check_empty (fakebank))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
diff --git a/src/testing/testing_api_cmd_bank_history_credit.c b/src/testing/testing_api_cmd_bank_history_credit.c
index 62bc47e11..956e6c857 100644
--- a/src/testing/testing_api_cmd_bank_history_credit.c
+++ b/src/testing/testing_api_cmd_bank_history_credit.c
@@ -83,6 +83,11 @@ struct HistoryState
struct TALER_BANK_CreditHistoryHandle *hh;
/**
+ * The interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
* Authentication data for the operation.
*/
struct TALER_BANK_AuthenticationData auth;
@@ -144,38 +149,161 @@ print_expected (struct History *h,
/**
+ * Closure for command_cb().
+ */
+struct IteratorContext
+{
+ /**
+ * Array of history items to return.
+ */
+ struct History *h;
+
+ /**
+ * Set to the row ID from where on we should actually process history items,
+ * or NULL if we should process all of them.
+ */
+ const uint64_t *row_id_start;
+
+ /**
+ * History state we are working on.
+ */
+ struct HistoryState *hs;
+
+ /**
+ * Current length of the @e h array.
+ */
+ unsigned int total;
+
+ /**
+ * Current write position in @e h array.
+ */
+ unsigned int pos;
+
+ /**
+ * Ok equals True whenever a starting row_id was provided AND was found
+ * among the CMDs, OR no starting row was given in the first place.
+ */
+ bool ok;
+
+};
+
+
+/**
+ * Helper function of build_history() that expands
+ * the history for each relevant command encountered.
+ *
+ * @param[in,out] cls our `struct IteratorContext`
+ * @param cmd a command to process
+ */
+static void
+command_cb (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct IteratorContext *ic = cls;
+ struct HistoryState *hs = ic->hs;
+ const uint64_t *row_id;
+ const char *credit_account;
+ const char *debit_account;
+ const struct TALER_Amount *amount;
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+ const char *exchange_credit_url;
+
+ /**
+ * The following command allows us to skip over those CMDs
+ * that do not offer a "row_id" trait. Such skipped CMDs are
+ * not interesting for building a history.
+ */
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_bank_row (cmd,
+ &row_id)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_credit_payto_uri (cmd,
+ &credit_account)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_debit_payto_uri (cmd,
+ &debit_account)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount (cmd,
+ &amount)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_pub (cmd,
+ &reserve_pub)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_exchange_bank_account_url (
+ cmd,
+ &exchange_credit_url)) )
+ return; // Not an interesting event
+
+ /**
+ * Is the interesting event a match with regard to
+ * the row_id value? If yes, store this condition
+ * to the state and analyze the next CMDs.
+ */
+ if ( (NULL != ic->row_id_start) &&
+ (*(ic->row_id_start) == *row_id) &&
+ (! ic->ok) )
+ {
+ ic->ok = true;
+ return;
+ }
+ /**
+ * The interesting event didn't match the wanted
+ * row_id value, analyze the next CMDs. Note: this
+ * branch is relevant only when row_id WAS given.
+ */
+ if (! ic->ok)
+ return;
+ if (0 != strcasecmp (hs->account_url,
+ exchange_credit_url))
+ return; // Account mismatch
+ if (ic->total >= GNUNET_MAX (hs->num_results,
+ -hs->num_results) )
+ {
+ TALER_LOG_DEBUG ("Hit history limit\n");
+ return;
+ }
+ TALER_LOG_INFO ("Found history: %s->%s for account %s\n",
+ debit_account,
+ credit_account,
+ hs->account_url);
+ /* found matching record, make sure we have room */
+ if (ic->pos == ic->total)
+ GNUNET_array_grow (ic->h,
+ ic->total,
+ ic->pos * 2);
+ ic->h[ic->pos].url = GNUNET_strdup (debit_account);
+ ic->h[ic->pos].details.debit_account_uri = ic->h[ic->pos].url;
+ ic->h[ic->pos].details.amount = *amount;
+ ic->h[ic->pos].row_id = *row_id;
+ ic->h[ic->pos].details.reserve_pub = *reserve_pub;
+ ic->pos++;
+}
+
+
+/**
* This function constructs the list of history elements that
* interest the account number of the caller. It has two main
* loops: the first to figure out how many history elements have
* to be allocated, and the second to actually populate every
* element.
*
- * @param is interpreter state (supposedly having the
- * current CMD pointing at a "history" CMD).
+ * @param hs history state
* @param[out] rh history array to initialize.
* @return number of entries in @a rh.
*/
static unsigned int
-build_history (struct TALER_TESTING_Interpreter *is,
+build_history (struct HistoryState *hs,
struct History **rh)
{
- struct HistoryState *hs = is->commands[is->ip].cls;
- unsigned int total;
- unsigned int pos;
- struct History *h;
- const struct TALER_TESTING_Command *add_incoming_cmd;
- int inc;
- unsigned int start;
- unsigned int end;
-
- /* @var turns GNUNET_YES whenever either no 'start' value was
- * given for the history query, or the given value is found
- * in the list of all the CMDs. *///
- int ok;
- const uint64_t *row_id_start = NULL;
+ struct TALER_TESTING_Interpreter *is = hs->is;
+ struct IteratorContext ic = {
+ .hs = hs
+ };
if (NULL != hs->start_row_reference)
{
+ const struct TALER_TESTING_Command *add_incoming_cmd;
+
TALER_LOG_INFO ("`%s': start row given via reference `%s'\n",
TALER_TESTING_interpreter_get_current_label (is),
hs->start_row_reference);
@@ -185,118 +313,91 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_assert (NULL != add_incoming_cmd);
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_row (add_incoming_cmd,
- &row_id_start));
+ &ic.row_id_start));
}
+ ic.ok = false;
+ if (NULL == ic.row_id_start)
+ ic.ok = true;
+ GNUNET_array_grow (ic.h,
+ ic.total,
+ 4);
GNUNET_assert (0 != hs->num_results);
- if (0 == is->ip)
- {
- TALER_LOG_DEBUG ("Checking history at FIRST transaction (EMPTY)\n");
- *rh = NULL;
- return 0;
- }
+ TALER_TESTING_iterate (is,
+ hs->num_results > 0,
+ &command_cb,
+ &ic);
+ GNUNET_assert (ic.ok);
+ GNUNET_array_grow (ic.h,
+ ic.total,
+ ic.pos);
+ if (0 == ic.pos)
+ TALER_LOG_DEBUG ("Empty credit history computed\n");
+ *rh = ic.h;
+ return ic.pos;
+}
- if (hs->num_results > 0)
+
+/**
+ * Normalize IBAN-based payto URI in @a in.
+ *
+ * @param in input payto://-URI to normalize
+ * @return normalized IBAN for the test
+ */
+static char *
+normalize (const char *in)
+{
+ char *npt;
+ const char *q = strchr (in,
+ '?');
+ const char *mptr;
+ const char *bic;
+ const char *iban;
+
+ if (NULL == q)
+ npt = GNUNET_strdup (in);
+ else
+ npt = GNUNET_strndup (in,
+ q - in);
+ if (0 != strncasecmp (npt,
+ "payto://",
+ strlen ("payto://")))
{
- inc = 1; /* _inc_rement */
- start = 0;
- end = is->ip - 1;
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Invalid payto: %s\n",
+ npt);
+ GNUNET_free (npt);
+ return NULL;
}
- else
+ mptr = npt + strlen ("payto://");
+ bic = strchr (mptr, '/');
+ if (NULL == bic)
{
- inc = -1;
- start = is->ip - 1;
- end = 0;
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Invalid payto: %s\n",
+ npt);
+ GNUNET_free (npt);
+ return NULL;
}
-
- ok = GNUNET_NO;
- if (NULL == row_id_start)
- ok = GNUNET_YES;
- h = NULL;
- total = 0;
- GNUNET_array_grow (h,
- total,
- 4);
- pos = 0;
- for (unsigned int off = start; off != end + inc; off += inc)
+ bic++;
+ iban = strchr (bic, '/');
+ if (NULL != iban)
{
- const struct TALER_TESTING_Command *cmd = &is->commands[off];
- const uint64_t *row_id;
- const char **credit_account;
- const char **debit_account;
- const struct TALER_Amount *amount;
- const struct TALER_ReservePublicKeyP *reserve_pub;
- const char **exchange_credit_url;
-
- /* The following command allows us to skip over those CMDs
- * that do not offer a "row_id" trait. Such skipped CMDs are
- * not interesting for building a history. *///
- if ( (GNUNET_OK !=
- TALER_TESTING_get_trait_bank_row (cmd,
- &row_id)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_credit_payto_uri (cmd,
- &credit_account)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_debit_payto_uri (cmd,
- &debit_account)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (cmd,
- &amount)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_pub (cmd,
- &reserve_pub)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_exchange_bank_account_url (
- cmd,
- &exchange_credit_url)) )
- continue; /* not an interesting event */
- /* Seek "/history/incoming" starting row. */
- if ( (NULL != row_id_start) &&
- (*row_id_start == *row_id) &&
- (GNUNET_NO == ok) )
- {
- /* Until here, nothing counted. */
- ok = GNUNET_YES;
- continue;
- }
- /* when 'start' was _not_ given, then ok == GNUNET_YES */
- if (GNUNET_NO == ok)
- continue; /* skip until we find the marker */
- if (0 != strcasecmp (hs->account_url,
- *exchange_credit_url))
- continue; /* account mismatch */
- if (total >= GNUNET_MAX (hs->num_results,
- -hs->num_results) )
- {
- TALER_LOG_DEBUG ("Hit history limit\n");
- break;
- }
- TALER_LOG_INFO ("Found history: %s->%s for account %s\n",
- *debit_account,
- *credit_account,
- hs->account_url);
- /* found matching record, make sure we have room */
- if (pos == total)
- GNUNET_array_grow (h,
- total,
- pos * 2);
- h[pos].url = GNUNET_strdup (*debit_account);
- h[pos].details.debit_account_uri = h[pos].url;
- h[pos].details.amount = *amount;
- h[pos].row_id = *row_id;
- h[pos].details.reserve_pub = *reserve_pub;
- h[pos].details.credit_account_uri = *exchange_credit_url;
- pos++;
+ /* need to remove bic */
+ char *n;
+
+ iban++;
+ GNUNET_asprintf (&n,
+ "payto://%.*s/%s",
+ (int) ((bic - mptr) - 1),
+ mptr,
+ iban);
+ GNUNET_free (npt);
+ npt = n;
}
- GNUNET_assert (GNUNET_YES == ok);
- GNUNET_array_grow (h,
- total,
- pos);
- if (0 == pos)
- TALER_LOG_DEBUG ("Empty credit history computed\n");
- *rh = h;
- return total;
+ return npt;
}
@@ -317,6 +418,9 @@ check_result (struct History *h,
unsigned int off,
const struct TALER_BANK_CreditDetails *details)
{
+ char *u1;
+ char *u2;
+
if (off >= total)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -329,25 +433,42 @@ check_result (struct History *h,
off);
return GNUNET_SYSERR;
}
+ u1 = normalize (h[off].details.debit_account_uri);
+ if (NULL == u1)
+ return GNUNET_SYSERR;
+ u2 = normalize (details->debit_account_uri);
+ if (NULL == u2)
+ {
+ GNUNET_free (u1);
+ return GNUNET_SYSERR;
+ }
if ( (0 != GNUNET_memcmp (&h[off].details.reserve_pub,
&details->reserve_pub)) ||
(0 != TALER_amount_cmp (&h[off].details.amount,
&details->amount)) ||
- (0 != strcasecmp (h[off].details.debit_account_uri,
- details->debit_account_uri)) )
+ (0 != strcasecmp (u1,
+ u2)) )
{
GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "expected debit_account_uri: %s\n",
- details->debit_account_uri);
+ "expected debit_account_uri: %s with %s for %s\n",
+ u1,
+ TALER_amount2s (&h[off].details.amount),
+ TALER_B2S (&h[off].details.reserve_pub));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "actual debit_account_uri: %s\n",
- h[off].details.debit_account_uri);
+ "actual debit_account_uri: %s with %s for %s\n",
+ u2,
+ TALER_amount2s (&details->amount),
+ TALER_B2S (&details->reserve_pub));
print_expected (h,
total,
off);
+ GNUNET_free (u1);
+ GNUNET_free (u2);
return GNUNET_SYSERR;
}
+ GNUNET_free (u1);
+ GNUNET_free (u2);
return GNUNET_OK;
}
@@ -360,99 +481,86 @@ check_result (struct History *h,
* finally check it against what the bank returned.
*
* @param cls closure.
- * @param http_status HTTP response code, #MHD_HTTP_OK (200)
- * for successful status request 0 if the bank's reply is
- * bogus (fails to follow the protocol),
- * #MHD_HTTP_NO_CONTENT if there are no more results; on
- * success the last callback is always of this status
- * (even if `abs(num_results)` were already returned).
- * @param ec taler status code.
- * @param row_id monotonically increasing counter corresponding to
- * the transaction.
- * @param details details about the wire transfer.
- * @param json detailed response from the HTTPD, or NULL if
- * reply was not in JSON.
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param chr http response details
*/
-static enum GNUNET_GenericReturnValue
+static void
history_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t row_id,
- const struct TALER_BANK_CreditDetails *details,
- const json_t *json)
+ const struct TALER_BANK_CreditHistoryResponse *chr)
{
- struct TALER_TESTING_Interpreter *is = cls;
- struct HistoryState *hs = is->commands[is->ip].cls;
+ struct HistoryState *hs = cls;
+ struct TALER_TESTING_Interpreter *is = hs->is;
- (void) row_id;
- if (NULL == details)
+ hs->hh = NULL;
+ switch (chr->http_status)
{
- hs->hh = NULL;
- if ( (MHD_HTTP_NOT_FOUND == http_status) &&
- (0 == hs->total) )
+ case 0:
+ GNUNET_break (0);
+ goto error;
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<chr->details.ok.details_length; i++)
+ {
+ const struct TALER_BANK_CreditDetails *cd =
+ &chr->details.ok.details[i];
+
+ /* check current element */
+ if (GNUNET_OK !=
+ check_result (hs->h,
+ hs->total,
+ hs->results_obtained,
+ cd))
+ {
+ GNUNET_break (0);
+ json_dumpf (chr->response,
+ stderr,
+ JSON_COMPACT);
+ hs->failed = true;
+ hs->hh = NULL;
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ hs->results_obtained++;
+ }
+ TALER_TESTING_interpreter_next (is);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ if (0 == hs->total)
{
/* not found is OK for empty history */
TALER_TESTING_interpreter_next (is);
- return GNUNET_OK;
+ return;
}
- if ( (hs->results_obtained != hs->total) ||
- (hs->failed) ||
- (MHD_HTTP_NO_CONTENT != http_status) )
+ GNUNET_break (0);
+ goto error;
+ case MHD_HTTP_NOT_FOUND:
+ if (0 == hs->total)
{
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected history of length %u, got %llu;"
- " HTTP status code: %u/%d, failed: %d\n",
- hs->total,
- (unsigned long long) hs->results_obtained,
- http_status,
- (int) ec,
- hs->failed ? 1 : 0);
- print_expected (hs->h,
- hs->total,
- UINT_MAX);
- TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
+ /* not found is OK for empty history */
+ TALER_TESTING_interpreter_next (is);
+ return;
}
- TALER_TESTING_interpreter_next (is);
- return GNUNET_OK;
- }
- if (MHD_HTTP_OK != http_status)
- {
+ GNUNET_break (0);
+ goto error;
+ default:
hs->hh = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unwanted response code from /history/incoming: %u\n",
- http_status);
- TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
- }
-
- /* check current element */
- if (GNUNET_OK !=
- check_result (hs->h,
- hs->total,
- hs->results_obtained,
- details))
- {
- char *acc;
-
- GNUNET_break (0);
- acc = json_dumps (json,
- JSON_COMPACT);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Result %u was `%s'\n",
- (unsigned int) hs->results_obtained++,
- acc);
- if (NULL != acc)
- free (acc);
- hs->failed = true;
- hs->hh = NULL;
+ chr->http_status);
TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
+ return;
}
- hs->results_obtained++;
- return GNUNET_OK;
+error:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected history of length %u, got %llu;"
+ " HTTP status code: %u/%d, failed: %d\n",
+ hs->total,
+ (unsigned long long) hs->results_obtained,
+ chr->http_status,
+ (int) chr->ec,
+ hs->failed ? 1 : 0);
+ print_expected (hs->h,
+ hs->total,
+ UINT_MAX);
+ TALER_TESTING_interpreter_fail (is);
}
@@ -473,6 +581,7 @@ history_run (void *cls,
const uint64_t *row_ptr;
(void) cmd;
+ hs->is = is;
/* Get row_id from trait. */
if (NULL != hs->start_row_reference)
{
@@ -493,15 +602,16 @@ history_run (void *cls,
TALER_LOG_DEBUG ("row id (from trait) is %llu\n",
(unsigned long long) row_id);
}
- hs->total = build_history (is,
+ hs->total = build_history (hs,
&hs->h);
- hs->hh = TALER_BANK_credit_history (is->ctx,
- &hs->auth,
- row_id,
- hs->num_results,
- GNUNET_TIME_UNIT_ZERO,
- &history_cb,
- is);
+ hs->hh = TALER_BANK_credit_history (
+ TALER_TESTING_interpreter_get_context (is),
+ &hs->auth,
+ row_id,
+ hs->num_results,
+ GNUNET_TIME_UNIT_ZERO,
+ &history_cb,
+ hs);
GNUNET_assert (NULL != hs->hh);
}
@@ -522,7 +632,8 @@ history_cleanup (void *cls,
(void) cmd;
if (NULL != hs->hh)
{
- TALER_LOG_WARNING ("/history/incoming did not complete\n");
+ TALER_TESTING_command_incomplete (hs->is,
+ cmd->label);
TALER_BANK_credit_history_cancel (hs->hh);
}
GNUNET_free (hs->account_url);
diff --git a/src/testing/testing_api_cmd_bank_history_debit.c b/src/testing/testing_api_cmd_bank_history_debit.c
index cb3f68097..1cb7320fa 100644
--- a/src/testing/testing_api_cmd_bank_history_debit.c
+++ b/src/testing/testing_api_cmd_bank_history_debit.c
@@ -92,6 +92,11 @@ struct HistoryState
struct TALER_BANK_DebitHistoryHandle *hh;
/**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
* Expected number of results (= rows).
*/
uint64_t results_obtained;
@@ -147,38 +152,155 @@ print_expected (struct History *h,
/**
+ * Closure for command_cb().
+ */
+struct IteratorContext
+{
+ /**
+ * Array of history items to return.
+ */
+ struct History *h;
+
+ /**
+ * Set to the row ID from where on we should actually process history items,
+ * or NULL if we should process all of them.
+ */
+ const uint64_t *row_id_start;
+
+ /**
+ * History state we are working on.
+ */
+ struct HistoryState *hs;
+
+ /**
+ * Current length of the @e h array.
+ */
+ unsigned int total;
+
+ /**
+ * Current write position in @e h array.
+ */
+ unsigned int pos;
+
+ /**
+ * Ok equals True whenever a starting row_id was provided AND was found
+ * among the CMDs, OR no starting row was given in the first place.
+ */
+ bool ok;
+
+};
+
+
+/**
+ * Helper function of build_history() that expands
+ * the history for each relevant command encountered.
+ *
+ * @param[in,out] cls our `struct IteratorContext`
+ * @param cmd a command to process
+ */
+static void
+command_cb (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct IteratorContext *ic = cls;
+ struct HistoryState *hs = ic->hs;
+
+ const uint64_t *row_id;
+ const char *debit_account;
+ const char *credit_account;
+ const struct TALER_Amount *amount;
+ const struct TALER_WireTransferIdentifierRawP *wtid;
+ const char *exchange_base_url;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Checking if command %s is relevant for debit history\n",
+ cmd->label);
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_bank_row (cmd,
+ &row_id)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_debit_payto_uri (cmd,
+ &debit_account)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_credit_payto_uri (cmd,
+ &credit_account)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount (cmd,
+ &amount)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_wtid (cmd,
+ &wtid)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_exchange_url (cmd,
+ &exchange_base_url)) )
+ return; /* not an event we care about */
+ /* Seek "/history/outgoing" starting row. */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Command %s is relevant for debit history!\n",
+ cmd->label);
+ if ( (NULL != ic->row_id_start) &&
+ (*(ic->row_id_start) == *row_id) &&
+ (! ic->ok) )
+ {
+ /* Until here, nothing counted. */
+ ic->ok = true;
+ return;
+ }
+ /* when 'start' was _not_ given, then ok == GNUNET_YES */
+ if (! ic->ok)
+ return; /* skip until we find the marker */
+ if (ic->total >= GNUNET_MAX (hs->num_results,
+ -hs->num_results) )
+ {
+ TALER_LOG_DEBUG ("Hit history limit\n");
+ return;
+ }
+ TALER_LOG_INFO ("Found history: %s->%s for account %s\n",
+ debit_account,
+ credit_account,
+ hs->account_url);
+ /* found matching record, make sure we have room */
+ if (ic->pos == ic->total)
+ GNUNET_array_grow (ic->h,
+ ic->total,
+ ic->pos * 2);
+ ic->h[ic->pos].c_url = GNUNET_strdup (credit_account);
+ ic->h[ic->pos].d_url = GNUNET_strdup (debit_account);
+ ic->h[ic->pos].details.credit_account_uri = ic->h[ic->pos].c_url;
+ ic->h[ic->pos].details.amount = *amount;
+ ic->h[ic->pos].row_id = *row_id;
+ ic->h[ic->pos].details.wtid = *wtid;
+ ic->h[ic->pos].details.exchange_base_url = exchange_base_url;
+ ic->pos++;
+}
+
+
+/**
* This function constructs the list of history elements that
* interest the account number of the caller. It has two main
* loops: the first to figure out how many history elements have
* to be allocated, and the second to actually populate every
* element.
*
- * @param is interpreter state (supposedly having the
- * current CMD pointing at a "history" CMD).
+ * @param hs history state command context
* @param[out] rh history array to initialize.
* @return number of entries in @a rh.
*/
static unsigned int
-build_history (struct TALER_TESTING_Interpreter *is,
+build_history (struct HistoryState *hs,
struct History **rh)
{
- struct HistoryState *hs = is->commands[is->ip].cls;
- unsigned int total;
- unsigned int pos;
- struct History *h;
- const struct TALER_TESTING_Command *add_incoming_cmd;
- int inc;
- int start;
- int end;
- /* #GNUNET_YES whenever either no 'start' value was given for the history
- * query, or the given value is found in the list of all the CMDs. */
- int ok;
- const uint64_t *row_id_start = NULL;
+ struct TALER_TESTING_Interpreter *is = hs->is;
+ struct IteratorContext ic = {
+ .hs = hs
+ };
if (NULL != hs->start_row_reference)
{
- TALER_LOG_INFO
- ("`%s': start row given via reference `%s'\n",
+ const struct TALER_TESTING_Command *add_incoming_cmd;
+
+ TALER_LOG_INFO (
+ "`%s': start row given via reference `%s'\n",
TALER_TESTING_interpreter_get_current_label (is),
hs->start_row_reference);
add_incoming_cmd = TALER_TESTING_interpreter_lookup_command (
@@ -187,124 +309,91 @@ build_history (struct TALER_TESTING_Interpreter *is,
GNUNET_assert (NULL != add_incoming_cmd);
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_row (add_incoming_cmd,
- &row_id_start));
+ &ic.row_id_start));
}
+ ic.ok = false;
+ if (NULL == ic.row_id_start)
+ ic.ok = true;
+ GNUNET_array_grow (ic.h,
+ ic.total,
+ 4);
GNUNET_assert (0 != hs->num_results);
- if (0 == is->ip)
- {
- TALER_LOG_DEBUG ("Checking history at first CMD..\n");
- *rh = NULL;
- return 0;
- }
+ TALER_TESTING_iterate (is,
+ hs->num_results > 0,
+ &command_cb,
+ &ic);
+ GNUNET_assert (ic.ok);
+ GNUNET_array_grow (ic.h,
+ ic.total,
+ ic.pos);
+ if (0 == ic.pos)
+ TALER_LOG_DEBUG ("Empty credit history computed\n");
+ *rh = ic.h;
+ return ic.pos;
+}
- /* AKA 'delta' */
- if (hs->num_results > 0)
- {
- inc = 1; /* _inc_rement: go forwards */
- start = 0;
- end = is->ip;
- }
+
+/**
+ * Normalize IBAN-based payto URI in @a in.
+ *
+ * @param in input payto://-URI to normalize
+ * @return normalized IBAN for the test
+ */
+static char *
+normalize (const char *in)
+{
+ char *npt;
+ const char *q = strchr (in,
+ '?');
+ const char *mptr;
+ const char *bic;
+ const char *iban;
+
+ if (NULL == q)
+ npt = GNUNET_strdup (in);
else
+ npt = GNUNET_strndup (in,
+ q - in);
+ if (0 != strncasecmp (npt,
+ "payto://",
+ strlen ("payto://")))
{
- inc = -1; /* decrement: we go backwards */
- start = is->ip - 1;
- end = -1; /* range is exclusive, do look at 0! */
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Invalid payto: %s\n",
+ npt);
+ GNUNET_free (npt);
+ return NULL;
}
-
- ok = GNUNET_NO;
- if (NULL == row_id_start)
- ok = GNUNET_YES;
- h = NULL;
- total = 0;
- GNUNET_array_grow (h,
- total,
- 4);
- pos = 0;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Checking commands %u to %u for debit history\n",
- start,
- end);
- for (int off = start; off != end; off += inc)
+ mptr = npt + strlen ("payto://");
+ bic = strchr (mptr, '/');
+ if (NULL == bic)
{
- const struct TALER_TESTING_Command *cmd = &is->commands[off];
- const uint64_t *row_id;
- const char **debit_account;
- const char **credit_account;
- const struct TALER_Amount *amount;
- const struct TALER_WireTransferIdentifierRawP *wtid;
- const char **exchange_base_url;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Checking if command %s is relevant for debit history\n",
- cmd->label);
- if ( (GNUNET_OK !=
- TALER_TESTING_get_trait_bank_row (cmd,
- &row_id)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_debit_payto_uri (cmd,
- &debit_account)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_credit_payto_uri (cmd,
- &credit_account)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (cmd,
- &amount)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_wtid (cmd,
- &wtid)) ||
- (GNUNET_OK !=
- TALER_TESTING_get_trait_exchange_url (cmd,
- &exchange_base_url)) )
- continue; /* not an event we care about */
- /* Seek "/history/outgoing" starting row. */
+ GNUNET_break (0);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Command %s is relevant for debit history!\n",
- cmd->label);
- if ( (NULL != row_id_start) &&
- (*row_id_start == *row_id) &&
- (GNUNET_NO == ok) )
- {
- /* Until here, nothing counted. */
- ok = GNUNET_YES;
- continue;
- }
- /* when 'start' was _not_ given, then ok == GNUNET_YES */
- if (GNUNET_NO == ok)
- continue; /* skip until we find the marker */
- if (total >= GNUNET_MAX (hs->num_results,
- -hs->num_results) )
- {
- TALER_LOG_DEBUG ("Hit history limit\n");
- break;
- }
- TALER_LOG_INFO ("Found history: %s->%s for account %s\n",
- *debit_account,
- *credit_account,
- hs->account_url);
- /* found matching record, make sure we have room */
- if (pos == total)
- GNUNET_array_grow (h,
- total,
- pos * 2);
- h[pos].c_url = GNUNET_strdup (*credit_account);
- h[pos].d_url = GNUNET_strdup (*debit_account);
- h[pos].details.credit_account_uri = h[pos].c_url;
- h[pos].details.debit_account_uri = h[pos].d_url;
- h[pos].details.amount = *amount;
- h[pos].row_id = *row_id;
- h[pos].details.wtid = *wtid;
- h[pos].details.exchange_base_url = *exchange_base_url;
- pos++;
+ "Invalid payto: %s\n",
+ npt);
+ GNUNET_free (npt);
+ return NULL;
}
- GNUNET_assert (GNUNET_YES == ok);
- GNUNET_array_grow (h,
- total,
- pos);
- if (0 == pos)
- TALER_LOG_DEBUG ("Empty debit history computed\n");
- *rh = h;
- return total;
+ bic++;
+ iban = strchr (bic, '/');
+ if (NULL != iban)
+ {
+ /* need to remove bic */
+ char *n;
+
+ iban++;
+ GNUNET_asprintf (&n,
+ "payto://%.*s/%s",
+ (int) ((bic - mptr) - 1),
+ mptr,
+ iban);
+ GNUNET_free (npt);
+ npt = n;
+ }
+ return npt;
}
@@ -325,6 +414,9 @@ check_result (struct History *h,
unsigned int off,
const struct TALER_BANK_DebitDetails *details)
{
+ char *u1;
+ char *u2;
+
if (off >= total)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -337,14 +429,33 @@ check_result (struct History *h,
off);
return GNUNET_SYSERR;
}
+ u1 = normalize (h[off].details.credit_account_uri);
+ if (NULL == u1)
+ return GNUNET_SYSERR;
+ u2 = normalize (details->credit_account_uri);
+ if (NULL == u2)
+ {
+ GNUNET_free (u1);
+ return GNUNET_SYSERR;
+ }
if ( (0 != GNUNET_memcmp (&h[off].details.wtid,
&details->wtid)) ||
(0 != TALER_amount_cmp (&h[off].details.amount,
&details->amount)) ||
- (0 != strcasecmp (h[off].details.credit_account_uri,
- details->credit_account_uri)) )
+ (0 != strcasecmp (u1,
+ u2)) )
{
GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "expected debit_account_uri: %s with %s for %s\n",
+ u1,
+ TALER_amount2s (&h[off].details.amount),
+ TALER_B2S (&h[off].details.wtid));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "actual debit_account_uri: %s with %s for %s\n",
+ u2,
+ TALER_amount2s (&details->amount),
+ TALER_B2S (&details->wtid));
print_expected (h,
total,
off);
@@ -362,99 +473,86 @@ check_result (struct History *h,
* finally check it against what the bank returned.
*
* @param cls closure.
- * @param http_status HTTP response code, #MHD_HTTP_OK (200)
- * for successful status request 0 if the bank's reply is
- * bogus (fails to follow the protocol),
- * #MHD_HTTP_NO_CONTENT if there are no more results; on
- * success the last callback is always of this status
- * (even if `abs(num_results)` were already returned).
- * @param ec taler status code.
- * @param row_id monotonically increasing counter corresponding to
- * the transaction.
- * @param details details about the wire transfer.
- * @param json detailed response from the HTTPD, or NULL if
- * reply was not in JSON.
- * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
+ * @param dhr http response details
*/
-static enum GNUNET_GenericReturnValue
+static void
history_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t row_id,
- const struct TALER_BANK_DebitDetails *details,
- const json_t *json)
+ const struct TALER_BANK_DebitHistoryResponse *dhr)
{
- struct TALER_TESTING_Interpreter *is = cls;
- struct HistoryState *hs = is->commands[is->ip].cls;
+ struct HistoryState *hs = cls;
+ struct TALER_TESTING_Interpreter *is = hs->is;
- (void) row_id;
- if (NULL == details)
+ hs->hh = NULL;
+ switch (dhr->http_status)
{
- hs->hh = NULL;
- if ( (MHD_HTTP_NOT_FOUND == http_status) &&
- (0 == hs->total) )
+ case 0:
+ GNUNET_break (0);
+ goto error;
+ case MHD_HTTP_OK:
+ for (unsigned int i = 0; i<dhr->details.ok.details_length; i++)
+ {
+ const struct TALER_BANK_DebitDetails *dd =
+ &dhr->details.ok.details[i];
+
+ /* check current element */
+ if (GNUNET_OK !=
+ check_result (hs->h,
+ hs->total,
+ hs->results_obtained,
+ dd))
+ {
+ GNUNET_break (0);
+ json_dumpf (dhr->response,
+ stderr,
+ JSON_COMPACT);
+ hs->failed = true;
+ hs->hh = NULL;
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ hs->results_obtained++;
+ }
+ TALER_TESTING_interpreter_next (is);
+ return;
+ case MHD_HTTP_NO_CONTENT:
+ if (0 == hs->total)
{
/* not found is OK for empty history */
TALER_TESTING_interpreter_next (is);
- return GNUNET_OK;
+ return;
}
- if ( (hs->results_obtained != hs->total) ||
- (GNUNET_YES == hs->failed) ||
- (MHD_HTTP_NO_CONTENT != http_status) )
+ GNUNET_break (0);
+ goto error;
+ case MHD_HTTP_NOT_FOUND:
+ if (0 == hs->total)
{
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected history of length %u, got %llu;"
- " HTTP status code: %u/%d, failed: %d\n",
- hs->total,
- (unsigned long long) hs->results_obtained,
- http_status,
- (int) ec,
- hs->failed);
- print_expected (hs->h,
- hs->total,
- UINT_MAX);
- TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
+ /* not found is OK for empty history */
+ TALER_TESTING_interpreter_next (is);
+ return;
}
- TALER_TESTING_interpreter_next (is);
- return GNUNET_OK;
- }
- if (MHD_HTTP_OK != http_status)
- {
- hs->hh = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unwanted response code from /history/outgoing: %u\n",
- http_status);
- TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
- }
-
- /* check current element */
- if (GNUNET_OK !=
- check_result (hs->h,
- hs->total,
- hs->results_obtained,
- details))
- {
- char *acc;
-
GNUNET_break (0);
- acc = json_dumps (json,
- JSON_COMPACT);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Result %u was `%s'\n",
- (unsigned int) hs->results_obtained++,
- acc);
- if (NULL != acc)
- free (acc);
- hs->failed = GNUNET_YES;
+ goto error;
+ default:
hs->hh = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unwanted response code from /history/incoming: %u\n",
+ dhr->http_status);
TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
+ return;
}
- hs->results_obtained++;
- return GNUNET_OK;
+error:
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected history of length %u, got %llu;"
+ " HTTP status code: %u/%d, failed: %d\n",
+ hs->total,
+ (unsigned long long) hs->results_obtained,
+ dhr->http_status,
+ (int) dhr->ec,
+ hs->failed ? 1 : 0);
+ print_expected (hs->h,
+ hs->total,
+ UINT_MAX);
+ TALER_TESTING_interpreter_fail (is);
}
@@ -475,6 +573,7 @@ history_run (void *cls,
const uint64_t *row_ptr;
(void) cmd;
+ hs->is = is;
/* Get row_id from trait. */
if (NULL != hs->start_row_reference)
{
@@ -495,14 +594,16 @@ history_run (void *cls,
TALER_LOG_DEBUG ("row id (from trait) is %llu\n",
(unsigned long long) row_id);
}
- hs->total = build_history (is, &hs->h);
- hs->hh = TALER_BANK_debit_history (is->ctx,
- &hs->auth,
- row_id,
- hs->num_results,
- GNUNET_TIME_UNIT_ZERO,
- &history_cb,
- is);
+ hs->total = build_history (hs,
+ &hs->h);
+ hs->hh = TALER_BANK_debit_history (
+ TALER_TESTING_interpreter_get_context (is),
+ &hs->auth,
+ row_id,
+ hs->num_results,
+ GNUNET_TIME_UNIT_ZERO,
+ &history_cb,
+ hs);
GNUNET_assert (NULL != hs->hh);
}
@@ -523,7 +624,8 @@ history_cleanup (void *cls,
(void) cmd;
if (NULL != hs->hh)
{
- TALER_LOG_WARNING ("/history/outgoing did not complete\n");
+ TALER_TESTING_command_incomplete (hs->is,
+ cmd->label);
TALER_BANK_debit_history_cancel (hs->hh);
}
for (unsigned int off = 0; off<hs->total; off++)
diff --git a/src/testing/testing_api_cmd_bank_transfer.c b/src/testing/testing_api_cmd_bank_transfer.c
index 8c14aac19..bfb29e120 100644
--- a/src/testing/testing_api_cmd_bank_transfer.c
+++ b/src/testing/testing_api_cmd_bank_transfer.c
@@ -149,8 +149,7 @@ do_retry (void *cls)
struct TransferState *fts = cls;
fts->retry_task = NULL;
- fts->is->commands[fts->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (fts->is);
transfer_run (fts,
NULL,
fts->is);
@@ -163,43 +162,35 @@ do_retry (void *cls)
* acceptable.
*
* @param cls closure with the interpreter state
- * @param http_status HTTP response code, #MHD_HTTP_OK (200) for
- * successful status request; 0 if the exchange's reply is
- * bogus (fails to follow the protocol)
- * @param ec taler-specific error code, #TALER_EC_NONE on success
- * @param serial_id unique ID of the wire transfer
- * @param timestamp time stamp of the transaction made.
+ * @param tr response details
*/
static void
confirmation_cb (void *cls,
- unsigned int http_status,
- enum TALER_ErrorCode ec,
- uint64_t serial_id,
- struct GNUNET_TIME_Timestamp timestamp)
+ const struct TALER_BANK_TransferResponse *tr)
{
struct TransferState *fts = cls;
struct TALER_TESTING_Interpreter *is = fts->is;
fts->weh = NULL;
- if (MHD_HTTP_OK != http_status)
+ if (MHD_HTTP_OK != tr->http_status)
{
if (0 != fts->do_retry)
{
fts->do_retry--;
- if ( (0 == http_status) ||
- (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec) ||
- (MHD_HTTP_INTERNAL_SERVER_ERROR == http_status) )
+ if ( (0 == tr->http_status) ||
+ (TALER_EC_GENERIC_DB_SOFT_FAILURE == tr->ec) ||
+ (MHD_HTTP_INTERNAL_SERVER_ERROR == tr->http_status) )
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Retrying transfer failed with %u/%d\n",
- http_status,
- (int) ec);
+ tr->http_status,
+ (int) tr->ec);
/* on DB conflicts, do not use backoff */
- if (TALER_EC_GENERIC_DB_SOFT_FAILURE == ec)
+ if (TALER_EC_GENERIC_DB_SOFT_FAILURE == tr->ec)
fts->backoff = GNUNET_TIME_UNIT_ZERO;
else
fts->backoff = EXCHANGE_LIB_BACKOFF (fts->backoff);
- fts->is->commands[fts->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (fts->is);
fts->retry_task
= GNUNET_SCHEDULER_add_delayed (fts->backoff,
&do_retry,
@@ -207,17 +198,14 @@ confirmation_cb (void *cls,
return;
}
}
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Bank returned HTTP status %u/%d\n",
- http_status,
- (int) ec);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ tr->http_status,
+ MHD_HTTP_OK);
return;
}
- fts->serial_id = serial_id;
- fts->timestamp = timestamp;
+ fts->serial_id = tr->details.ok.row_id;
+ fts->timestamp = tr->details.ok.timestamp;
TALER_TESTING_interpreter_next (is);
}
@@ -284,9 +272,8 @@ transfer_cleanup (void *cls,
if (NULL != fts->weh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %s did not complete\n",
- cmd->label);
+ TALER_TESTING_command_incomplete (fts->is,
+ cmd->label);
TALER_BANK_transfer_cancel (fts->weh);
fts->weh = NULL;
}
@@ -319,12 +306,12 @@ transfer_traits (void *cls,
struct TransferState *fts = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_exchange_url (
- (const char **) &fts->exchange_base_url),
+ fts->exchange_base_url),
TALER_TESTING_make_trait_bank_row (&fts->serial_id),
TALER_TESTING_make_trait_credit_payto_uri (
- (const char **) &fts->payto_credit_account),
+ fts->payto_credit_account),
TALER_TESTING_make_trait_debit_payto_uri (
- (const char **) &fts->payto_debit_account),
+ fts->payto_debit_account),
TALER_TESTING_make_trait_amount (&fts->amount),
TALER_TESTING_make_trait_timestamp (0, &fts->timestamp),
TALER_TESTING_make_trait_wtid (&fts->wtid),
diff --git a/src/testing/testing_api_cmd_batch.c b/src/testing/testing_api_cmd_batch.c
index e8f76ca37..5bb7b974e 100644
--- a/src/testing/testing_api_cmd_batch.c
+++ b/src/testing/testing_api_cmd_batch.c
@@ -38,6 +38,11 @@ struct BatchState
struct TALER_TESTING_Command *batch;
/**
+ * My command (the batch command).
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Internal command pointer.
*/
unsigned int batch_ip;
@@ -58,6 +63,7 @@ batch_run (void *cls,
{
struct BatchState *bs = cls;
+ bs->cmd = cmd;
if (NULL != bs->batch[bs->batch_ip].label)
TALER_LOG_INFO ("Running batched command: %s\n",
bs->batch[bs->batch_ip].label);
@@ -97,8 +103,9 @@ batch_cleanup (void *cls,
for (unsigned int i = 0;
NULL != bs->batch[i].label;
i++)
- bs->batch[i].cleanup (bs->batch[i].cls,
- &bs->batch[i]);
+ if (NULL != bs->batch[i].cleanup)
+ bs->batch[i].cleanup (bs->batch[i].cls,
+ &bs->batch[i]);
GNUNET_free (bs->batch);
GNUNET_free (bs);
}
@@ -121,7 +128,7 @@ batch_traits (void *cls,
{
struct BatchState *bs = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_batch_cmds (&bs->batch),
+ TALER_TESTING_make_trait_batch_cmds (bs->batch),
TALER_TESTING_trait_end ()
};
@@ -149,9 +156,9 @@ TALER_TESTING_cmd_batch (const char *label,
bs->batch = GNUNET_new_array (i + 1,
struct TALER_TESTING_Command);
- memcpy (bs->batch,
- batch,
- sizeof (struct TALER_TESTING_Command) * i);
+ GNUNET_memcpy (bs->batch,
+ batch,
+ sizeof (struct TALER_TESTING_Command) * i);
{
struct TALER_TESTING_Command cmd = {
.cls = bs,
@@ -166,19 +173,33 @@ TALER_TESTING_cmd_batch (const char *label,
}
-void
-TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is)
+bool
+TALER_TESTING_cmd_batch_next (struct TALER_TESTING_Interpreter *is,
+ void *cls)
{
- struct BatchState *bs = is->commands[is->ip].cls;
+ struct BatchState *bs = cls;
+ struct TALER_TESTING_Command *bcmd = &bs->batch[bs->batch_ip];
- if (NULL == bs->batch[bs->batch_ip].label)
+ if (NULL == bcmd->label)
{
- is->commands[is->ip].finish_time = GNUNET_TIME_absolute_get ();
- is->ip++;
- return;
+ /* This batch is done */
+ return true;
+ }
+ if (TALER_TESTING_cmd_is_batch (bcmd))
+ {
+ if (TALER_TESTING_cmd_batch_next (is,
+ bcmd->cls))
+ {
+ /* sub-batch is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
+ bs->batch_ip++;
+ return false;
+ }
}
- bs->batch[bs->batch_ip].finish_time = GNUNET_TIME_absolute_get ();
+ /* Simple command is done */
+ bcmd->finish_time = GNUNET_TIME_absolute_get ();
bs->batch_ip++;
+ return false;
}
diff --git a/src/testing/testing_api_cmd_batch_deposit.c b/src/testing/testing_api_cmd_batch_deposit.c
index 2ea03a51b..5139d3524 100644
--- a/src/testing/testing_api_cmd_batch_deposit.c
+++ b/src/testing/testing_api_cmd_batch_deposit.c
@@ -59,17 +59,33 @@ struct Coin
struct TALER_Amount deposit_fee;
/**
+ * Our coin signature.
+ */
+ struct TALER_CoinSpendSignatureP coin_sig;
+
+ /**
* Reference to any command that is able to provide a coin,
* possibly using $LABEL#$INDEX notation.
*/
char *coin_reference;
/**
+ * Denomination public key of the coin.
+ */
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+
+ /**
* The command being referenced.
*/
const struct TALER_TESTING_Command *coin_cmd;
/**
+ * Expected entry in the coin history created by this
+ * coin.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
* Index of the coin at @e coin_cmd.
*/
unsigned int coin_idx;
@@ -151,10 +167,9 @@ struct BatchDepositState
struct GNUNET_SCHEDULER_Task *retry_task;
/**
- * Array of @e num_coins signatures from the exchange on the
- * deposit confirmation.
+ * Deposit confirmation signature from the exchange.
*/
- struct TALER_ExchangeSignatureP *exchange_sigs;
+ struct TALER_ExchangeSignatureP exchange_sig;
/**
* Reference to previous deposit operation.
@@ -198,33 +213,17 @@ batch_deposit_cb (void *cls,
ds->dh = NULL;
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
- if (ds->num_coins != dr->details.success.num_signatures)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (ds->is);
- return;
- }
ds->deposit_succeeded = GNUNET_YES;
- ds->exchange_timestamp = dr->details.success.deposit_timestamp;
- ds->exchange_pub = *dr->details.success.exchange_pub;
- ds->exchange_sigs = GNUNET_memdup (dr->details.success.exchange_sigs,
- dr->details.success.num_signatures
- * sizeof (struct
- TALER_ExchangeSignatureP));
+ ds->exchange_timestamp = dr->details.ok.deposit_timestamp;
+ ds->exchange_pub = *dr->details.ok.exchange_pub;
+ ds->exchange_sig = *dr->details.ok.exchange_sig;
}
TALER_TESTING_interpreter_next (ds->is);
}
@@ -243,7 +242,6 @@ batch_deposit_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct BatchDepositState *ds = cls;
- const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
const struct TALER_DenominationSignature *denom_pub_sig;
struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_PrivateContractHashP h_contract_terms;
@@ -259,8 +257,15 @@ batch_deposit_run (void *cls,
&wire_salt),
GNUNET_JSON_spec_end ()
};
+ const char *exchange_url
+ = TALER_TESTING_get_exchange_url (is);
(void) cmd;
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
memset (cdds,
0,
sizeof (cdds));
@@ -340,7 +345,7 @@ batch_deposit_run (void *cls,
(GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (coin->coin_cmd,
coin->coin_idx,
- &denom_pub)) ||
+ &coin->denom_pub)) ||
(GNUNET_OK !=
TALER_TESTING_get_trait_denom_sig (coin->coin_cmd,
coin->coin_idx,
@@ -355,23 +360,38 @@ batch_deposit_run (void *cls,
TALER_age_commitment_hash (&age_commitment_proof->commitment,
&cdd->h_age_commitment);
}
- coin->deposit_fee = denom_pub->fees.deposit;
+ coin->deposit_fee = coin->denom_pub->fees.deposit;
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&cdd->coin_pub.eddsa_pub);
cdd->denom_sig = *denom_pub_sig;
- cdd->h_denom_pub = denom_pub->h_key;
+ cdd->h_denom_pub = coin->denom_pub->h_key;
TALER_wallet_deposit_sign (&coin->amount,
- &denom_pub->fees.deposit,
+ &coin->denom_pub->fees.deposit,
&h_wire,
&h_contract_terms,
+ NULL, /* wallet_data_hash */
&cdd->h_age_commitment,
- NULL, /* FIXME: add hash of extensions */
- &denom_pub->h_key,
+ NULL, /* hash of extensions */
+ &coin->denom_pub->h_key,
ds->wallet_timestamp,
&merchant_pub,
ds->refund_deadline,
coin_priv,
&cdd->coin_sig);
+ coin->coin_sig = cdd->coin_sig;
+ coin->che.type = TALER_EXCHANGE_CTT_DEPOSIT;
+ coin->che.amount = coin->amount;
+ coin->che.details.deposit.h_wire = h_wire;
+ coin->che.details.deposit.h_contract_terms = h_contract_terms;
+ coin->che.details.deposit.no_h_policy = true;
+ coin->che.details.deposit.no_wallet_data_hash = true;
+ coin->che.details.deposit.wallet_timestamp = ds->wallet_timestamp;
+ coin->che.details.deposit.merchant_pub = merchant_pub;
+ coin->che.details.deposit.refund_deadline = ds->refund_deadline;
+ coin->che.details.deposit.sig = cdd->coin_sig;
+ coin->che.details.deposit.no_hac = GNUNET_is_zero (&cdd->h_age_commitment);
+ coin->che.details.deposit.hac = cdd->h_age_commitment;
+ coin->che.details.deposit.deposit_fee = coin->denom_pub->fees.deposit;
}
GNUNET_assert (NULL == ds->dh);
@@ -381,19 +401,22 @@ batch_deposit_run (void *cls,
.merchant_payto_uri = payto_uri,
.wire_salt = wire_salt,
.h_contract_terms = h_contract_terms,
- .extension_details = NULL /* FIXME-OEC */,
- .timestamp = ds->wallet_timestamp,
+ .policy_details = NULL /* FIXME #7270-OEC */,
+ .wallet_timestamp = ds->wallet_timestamp,
.merchant_pub = merchant_pub,
.refund_deadline = ds->refund_deadline
};
- ds->dh = TALER_EXCHANGE_batch_deposit (is->exchange,
- &dcd,
- ds->num_coins,
- cdds,
- &batch_deposit_cb,
- ds,
- &ec);
+ ds->dh = TALER_EXCHANGE_batch_deposit (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ TALER_TESTING_get_keys (is),
+ &dcd,
+ ds->num_coins,
+ cdds,
+ &batch_deposit_cb,
+ ds,
+ &ec);
}
if (NULL == ds->dh)
{
@@ -422,10 +445,8 @@ batch_deposit_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_batch_deposit_cancel (ds->dh);
ds->dh = NULL;
}
@@ -437,7 +458,6 @@ batch_deposit_cleanup (void *cls,
for (unsigned int i = 0; i<ds->num_coins; i++)
GNUNET_free (ds->coins[i].coin_reference);
GNUNET_free (ds->coins);
- GNUNET_free (ds->exchange_sigs);
json_decref (ds->wire_details);
json_decref (ds->contract_terms);
GNUNET_free (ds);
@@ -460,9 +480,10 @@ batch_deposit_traits (void *cls,
unsigned int index)
{
struct BatchDepositState *ds = cls;
- struct Coin *coin = &ds->coins[index];
+ const struct Coin *coin = &ds->coins[index];
/* Will point to coin cmd internals. */
const struct TALER_CoinSpendPrivateKeyP *coin_spent_priv;
+ struct TALER_CoinSpendPublicKeyP coin_spent_pub;
const struct TALER_AgeCommitmentProof *age_commitment_proof;
if (index >= ds->num_coins)
@@ -489,27 +510,38 @@ batch_deposit_traits (void *cls,
TALER_TESTING_interpreter_fail (ds->is);
return GNUNET_NO;
}
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_spent_priv->eddsa_priv,
+ &coin_spent_pub.eddsa_pub);
+
{
struct TALER_TESTING_Trait traits[] = {
/* First two traits are only available if
ds->traits is #GNUNET_YES */
- TALER_TESTING_make_trait_exchange_pub (index,
+ TALER_TESTING_make_trait_exchange_pub (0,
&ds->exchange_pub),
- TALER_TESTING_make_trait_exchange_sig (index,
- &ds->exchange_sigs[index]),
+ TALER_TESTING_make_trait_exchange_sig (0,
+ &ds->exchange_sig),
/* These traits are always available */
TALER_TESTING_make_trait_wire_details (ds->wire_details),
TALER_TESTING_make_trait_contract_terms (ds->contract_terms),
TALER_TESTING_make_trait_merchant_priv (&ds->merchant_priv),
TALER_TESTING_make_trait_age_commitment_proof (index,
age_commitment_proof),
+ TALER_TESTING_make_trait_coin_history (index,
+ &coin->che),
+ TALER_TESTING_make_trait_coin_pub (index,
+ &coin_spent_pub),
+ TALER_TESTING_make_trait_denom_pub (index,
+ coin->denom_pub),
TALER_TESTING_make_trait_coin_priv (index,
coin_spent_priv),
+ TALER_TESTING_make_trait_coin_sig (index,
+ &coin->coin_sig),
TALER_TESTING_make_trait_deposit_amount (index,
&coin->amount),
TALER_TESTING_make_trait_deposit_fee_amount (index,
&coin->deposit_fee),
-
TALER_TESTING_make_trait_timestamp (index,
&ds->exchange_timestamp),
TALER_TESTING_make_trait_wire_deadline (index,
diff --git a/src/testing/testing_api_cmd_batch_withdraw.c b/src/testing/testing_api_cmd_batch_withdraw.c
index fb290f1e8..1b056bdbb 100644
--- a/src/testing/testing_api_cmd_batch_withdraw.c
+++ b/src/testing/testing_api_cmd_batch_withdraw.c
@@ -23,6 +23,7 @@
* @author Marcello Stanisci
*/
#include "platform.h"
+#include "taler_exchange_service.h"
#include "taler_json_lib.h"
#include <microhttpd.h>
#include <gnunet/gnunet_curl_lib.h>
@@ -56,9 +57,14 @@ struct CoinState
struct TALER_CoinSpendPrivateKeyP coin_priv;
/**
+ * Public key of the coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
* Blinding key used during the operation.
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
/**
* Values contributed from the exchange during the
@@ -79,10 +85,10 @@ struct CoinState
/**
* If age > 0, put here the corresponding age commitment with its proof and
- * its hash, respectivelly, NULL otherwise.
+ * its hash, respectively.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Reserve history entry that corresponds to this coin.
@@ -141,10 +147,16 @@ struct BatchWithdrawState
struct CoinState *coins;
/**
- * Set to the KYC UUID *if* the exchange replied with
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
* a request for KYC.
*/
- uint64_t kyc_uuid;
+ uint64_t requirement_row;
/**
* Length of the @e coins array.
@@ -161,6 +173,11 @@ struct BatchWithdrawState
* Same for all coins in the batch.
*/
uint8_t age;
+
+ /**
+ * Force a conflict:
+ */
+ bool force_conflict;
};
@@ -183,18 +200,10 @@ reserve_batch_withdraw_cb (void *cls,
ws->wsh = NULL;
if (ws->expected_response_code != wr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- wr->hr.http_status,
- (int) wr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (is),
- __FILE__,
- __LINE__);
- json_dumpf (wr->hr.reply,
- stderr,
- 0);
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status_with_body (is,
+ wr->hr.http_status,
+ ws->expected_response_code,
+ wr->hr.reply);
return;
}
switch (wr->hr.http_status)
@@ -204,19 +213,19 @@ reserve_batch_withdraw_cb (void *cls,
{
struct CoinState *cs = &ws->coins[i];
const struct TALER_EXCHANGE_PrivateCoinDetails *pcd
- = &wr->details.success.coins[i];
+ = &wr->details.ok.coins[i];
- TALER_denom_sig_deep_copy (&cs->sig,
- &pcd->sig);
+ TALER_denom_sig_copy (&cs->sig,
+ &pcd->sig);
cs->coin_priv = pcd->coin_priv;
+ GNUNET_CRYPTO_eddsa_key_get_public (&cs->coin_priv.eddsa_priv,
+ &cs->coin_pub.eddsa_pub);
+
cs->bks = pcd->bks;
- cs->exchange_vals = pcd->exchange_vals;
+ TALER_denom_ewv_copy (&cs->exchange_vals,
+ &pcd->exchange_vals);
}
break;
- case MHD_HTTP_ACCEPTED:
- /* nothing to check */
- ws->kyc_uuid = wr->details.accepted.payment_target_uuid;
- break;
case MHD_HTTP_FORBIDDEN:
/* nothing to check */
break;
@@ -224,11 +233,18 @@ reserve_batch_withdraw_cb (void *cls,
/* nothing to check */
break;
case MHD_HTTP_CONFLICT:
- /* nothing to check */
+ /* TODO[oec]: Check if age-requirement is the reason */
break;
case MHD_HTTP_GONE:
/* theoretically could check that the key was actually */
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* nothing to check */
+ ws->requirement_row
+ = wr->details.unavailable_for_legal_reasons.requirement_row;
+ ws->h_payto
+ = wr->details.unavailable_for_legal_reasons.h_payto;
+ break;
default:
/* Unsupported status code (by test harness) */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -250,10 +266,13 @@ batch_withdraw_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct BatchWithdrawState *ws = cls;
+ const struct TALER_EXCHANGE_Keys *keys = TALER_TESTING_get_keys (is);
const struct TALER_ReservePrivateKeyP *rp;
const struct TALER_TESTING_Command *create_reserve;
const struct TALER_EXCHANGE_DenomPublicKey *dpk;
struct TALER_EXCHANGE_WithdrawCoinInput wcis[ws->num_coins];
+ struct TALER_PlanchetMasterSecretP conflict_ps = {0};
+ struct TALER_AgeMask mask = {0};
(void) cmd;
ws->is = is;
@@ -278,21 +297,46 @@ batch_withdraw_run (void *cls,
}
if (NULL == ws->exchange_url)
ws->exchange_url
- = GNUNET_strdup (TALER_EXCHANGE_get_base_url (is->exchange));
+ = GNUNET_strdup (TALER_TESTING_get_exchange_url (is));
ws->reserve_priv = *rp;
GNUNET_CRYPTO_eddsa_key_get_public (&ws->reserve_priv.eddsa_priv,
&ws->reserve_pub.eddsa_pub);
ws->reserve_payto_uri
- = TALER_payto_from_reserve (ws->exchange_url,
+ = TALER_reserve_make_payto (ws->exchange_url,
&ws->reserve_pub);
+ if (0 < ws->age)
+ mask = TALER_extensions_get_age_restriction_mask ();
+
+ if (ws->force_conflict)
+ TALER_planchet_master_setup_random (&conflict_ps);
+
for (unsigned int i = 0; i<ws->num_coins; i++)
{
struct CoinState *cs = &ws->coins[i];
struct TALER_EXCHANGE_WithdrawCoinInput *wci = &wcis[i];
- TALER_planchet_master_setup_random (&cs->ps);
- dpk = TALER_TESTING_find_pk (TALER_EXCHANGE_get_keys (is->exchange),
+ if (ws->force_conflict)
+ cs->ps = conflict_ps;
+ else
+ TALER_planchet_master_setup_random (&cs->ps);
+
+ if (0 < ws->age)
+ {
+ struct GNUNET_HashCode seed = {0};
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &seed,
+ sizeof(seed));
+ TALER_age_restriction_commit (&mask,
+ ws->age,
+ &seed,
+ &cs->age_commitment_proof);
+ TALER_age_commitment_hash (&cs->age_commitment_proof.commitment,
+ &cs->h_age_commitment);
+ }
+
+
+ dpk = TALER_TESTING_find_pk (keys,
&cs->amount,
ws->age > 0);
if (NULL == dpk)
@@ -316,14 +360,17 @@ batch_withdraw_run (void *cls,
wci->pk = cs->pk;
wci->ps = &cs->ps;
- wci->ach = cs->h_age_commitment;
+ wci->ach = &cs->h_age_commitment;
}
- ws->wsh = TALER_EXCHANGE_batch_withdraw (is->exchange,
- rp,
- wcis,
- ws->num_coins,
- &reserve_batch_withdraw_cb,
- ws);
+ ws->wsh = TALER_EXCHANGE_batch_withdraw (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ keys,
+ rp,
+ ws->num_coins,
+ wcis,
+ &reserve_batch_withdraw_cb,
+ ws);
if (NULL == ws->wsh)
{
GNUNET_break (0);
@@ -348,9 +395,8 @@ batch_withdraw_cleanup (void *cls,
if (NULL != ws->wsh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %s did not complete\n",
- cmd->label);
+ TALER_TESTING_command_incomplete (ws->is,
+ cmd->label);
TALER_EXCHANGE_batch_withdraw_cancel (ws->wsh);
ws->wsh = NULL;
}
@@ -358,19 +404,15 @@ batch_withdraw_cleanup (void *cls,
{
struct CoinState *cs = &ws->coins[i];
+ TALER_denom_ewv_free (&cs->exchange_vals);
TALER_denom_sig_free (&cs->sig);
if (NULL != cs->pk)
{
TALER_EXCHANGE_destroy_denomination_key (cs->pk);
cs->pk = NULL;
}
- if (NULL != cs->age_commitment_proof)
- {
- TALER_age_commitment_proof_free (cs->age_commitment_proof);
- cs->age_commitment_proof = NULL;
- }
- if (NULL != cs->h_age_commitment)
- GNUNET_free (cs->h_age_commitment);
+ if (0 < ws->age)
+ TALER_age_commitment_proof_free (&cs->age_commitment_proof);
}
GNUNET_free (ws->coins);
GNUNET_free (ws->exchange_url);
@@ -403,6 +445,8 @@ batch_withdraw_traits (void *cls,
&cs->reserve_history),
TALER_TESTING_make_trait_coin_priv (index,
&cs->coin_priv),
+ TALER_TESTING_make_trait_coin_pub (index,
+ &cs->coin_pub),
TALER_TESTING_make_trait_planchet_secrets (index,
&cs->ps),
TALER_TESTING_make_trait_blinding_key (index,
@@ -417,15 +461,18 @@ batch_withdraw_traits (void *cls,
TALER_TESTING_make_trait_reserve_pub (&ws->reserve_pub),
TALER_TESTING_make_trait_amounts (index,
&cs->amount),
- TALER_TESTING_make_trait_payment_target_uuid (&ws->kyc_uuid),
- TALER_TESTING_make_trait_payto_uri (
- (const char **) &ws->reserve_payto_uri),
- TALER_TESTING_make_trait_exchange_url (
- (const char **) &ws->exchange_url),
+ TALER_TESTING_make_trait_legi_requirement_row (&ws->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&ws->h_payto),
+ TALER_TESTING_make_trait_payto_uri (ws->reserve_payto_uri),
+ TALER_TESTING_make_trait_exchange_url (ws->exchange_url),
TALER_TESTING_make_trait_age_commitment_proof (index,
- cs->age_commitment_proof),
+ ws->age > 0 ?
+ &cs->age_commitment_proof:
+ NULL),
TALER_TESTING_make_trait_h_age_commitment (index,
- cs->h_age_commitment),
+ ws->age > 0 ?
+ &cs->h_age_commitment :
+ NULL),
TALER_TESTING_trait_end ()
};
@@ -441,12 +488,14 @@ batch_withdraw_traits (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_batch_withdraw (const char *label,
- const char *reserve_reference,
- uint8_t age,
- unsigned int expected_response_code,
- const char *amount,
- ...)
+TALER_TESTING_cmd_batch_withdraw_with_conflict (
+ const char *label,
+ const char *reserve_reference,
+ bool conflict,
+ uint8_t age,
+ unsigned int expected_response_code,
+ const char *amount,
+ ...)
{
struct BatchWithdrawState *ws;
unsigned int cnt;
@@ -456,54 +505,24 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
ws->age = age;
ws->reserve_reference = reserve_reference;
ws->expected_response_code = expected_response_code;
+ ws->force_conflict = conflict;
cnt = 1;
- va_start (ap, amount);
- while (NULL != (va_arg (ap, const char *)))
+ va_start (ap,
+ amount);
+ while (NULL != (va_arg (ap,
+ const char *)))
cnt++;
ws->num_coins = cnt;
ws->coins = GNUNET_new_array (cnt,
struct CoinState);
va_end (ap);
- va_start (ap, amount);
+ va_start (ap,
+ amount);
for (unsigned int i = 0; i<ws->num_coins; i++)
{
struct CoinState *cs = &ws->coins[i];
- if (0 < age)
- {
- struct TALER_AgeCommitmentProof *acp;
- struct TALER_AgeCommitmentHash *hac;
- struct GNUNET_HashCode seed;
- struct TALER_AgeMask mask;
-
- acp = GNUNET_new (struct TALER_AgeCommitmentProof);
- hac = GNUNET_new (struct TALER_AgeCommitmentHash);
- mask = TALER_extensions_age_restriction_ageMask ();
- GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- &seed,
- sizeof(seed));
-
- if (GNUNET_OK !=
- TALER_age_restriction_commit (
- &mask,
- age,
- &seed,
- acp))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to generate age commitment for age %d at %s\n",
- age,
- label);
- GNUNET_assert (0);
- }
-
- TALER_age_commitment_hash (&acp->commitment,
- hac);
- cs->age_commitment_proof = acp;
- cs->h_age_commitment = hac;
- }
-
if (GNUNET_OK !=
TALER_string_to_amount (amount,
&cs->amount))
@@ -515,7 +534,8 @@ TALER_TESTING_cmd_batch_withdraw (const char *label,
GNUNET_assert (0);
}
/* move on to next vararg! */
- amount = va_arg (ap, const char *);
+ amount = va_arg (ap,
+ const char *);
}
GNUNET_assert (NULL == amount);
va_end (ap);
diff --git a/src/testing/testing_api_cmd_change_auth.c b/src/testing/testing_api_cmd_change_auth.c
deleted file mode 100644
index c3a60a1da..000000000
--- a/src/testing/testing_api_cmd_change_auth.c
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- This file is part of TALER
- (C) 2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_change_auth.c
- * @brief command(s) to change CURL context authorization header
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_testing_lib.h"
-
-
-/**
- * State for a "authchange" CMD.
- */
-struct AuthchangeState
-{
-
- /**
- * What is the new authorization token to send?
- */
- const char *auth_token;
-
- /**
- * Old context, clean up on termination.
- */
- struct GNUNET_CURL_Context *old_ctx;
-};
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-authchange_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct AuthchangeState *ss = cls;
-
- (void) cmd;
- ss->old_ctx = is->ctx;
- if (NULL != is->rc)
- {
- GNUNET_CURL_gnunet_rc_destroy (is->rc);
- is->rc = NULL;
- }
- is->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
- &is->rc);
- GNUNET_CURL_enable_async_scope_header (is->ctx,
- "Taler-Correlation-Id");
- GNUNET_assert (NULL != is->ctx);
- is->rc = GNUNET_CURL_gnunet_rc_create (is->ctx);
- if (NULL != ss->auth_token)
- {
- char *authorization;
-
- GNUNET_asprintf (&authorization,
- "%s: %s",
- MHD_HTTP_HEADER_AUTHORIZATION,
- ss->auth_token);
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CURL_append_header (is->ctx,
- authorization));
- GNUNET_free (authorization);
- }
- TALER_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Call GNUNET_CURL_fini(). Done as a separate task to
- * ensure that all of the command's cleanups have been
- * executed first. See #7151.
- *
- * @param cls a `struct GNUNET_CURL_Context *` to clean up.
- */
-static void
-deferred_cleanup_cb (void *cls)
-{
- struct GNUNET_CURL_Context *ctx = cls;
-
- GNUNET_CURL_fini (ctx);
-}
-
-
-/**
- * Cleanup the state from a "authchange" CMD.
- *
- * @param cls closure.
- * @param cmd the command which is being cleaned up.
- */
-static void
-authchange_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct AuthchangeState *ss = cls;
-
- (void) cmd;
- if (NULL != ss->old_ctx)
- {
- (void) GNUNET_SCHEDULER_add_now (&deferred_cleanup_cb,
- ss->old_ctx);
- ss->old_ctx = NULL;
- }
- GNUNET_free (ss);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_set_authorization (const char *label,
- const char *auth_token)
-{
- struct AuthchangeState *ss;
-
- ss = GNUNET_new (struct AuthchangeState);
- ss->auth_token = auth_token;
-
- {
- struct TALER_TESTING_Command cmd = {
- .cls = ss,
- .label = label,
- .run = &authchange_run,
- .cleanup = &authchange_cleanup
- };
-
- return cmd;
- }
-}
-
-
-/* end of testing_api_cmd_change_auth.c */
diff --git a/src/testing/testing_api_cmd_check_aml_decision.c b/src/testing/testing_api_cmd_check_aml_decision.c
new file mode 100644
index 000000000..fa0981e0d
--- /dev/null
+++ b/src/testing/testing_api_cmd_check_aml_decision.c
@@ -0,0 +1,270 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_check_aml_decision.c
+ * @brief command for testing /management/XXX
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "check_aml_decision" CMD.
+ */
+struct AmlCheckState
+{
+
+ /**
+ * Handle while operation is running.
+ */
+ struct TALER_EXCHANGE_LookupAmlDecision *dh;
+
+ /**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Reference to command to previous set officer.
+ */
+ const char *ref_officer;
+
+ /**
+ * Reference to command to the previous set AML status operation.
+ */
+ const char *ref_operation;
+
+ /**
+ * Expected HTTP status.
+ */
+ unsigned int expected_http_status;
+
+};
+
+
+/**
+ * Callback to analyze the /aml/$OFFICER_PUB/$decision/$H_PAYTO response, just used to check
+ * if the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param adr response details
+ */
+static void
+check_aml_decision_cb (void *cls,
+ const struct TALER_EXCHANGE_AmlDecisionResponse *adr)
+{
+ struct AmlCheckState *ds = cls;
+
+ ds->dh = NULL;
+ if (ds->expected_http_status != adr->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (ds->is,
+ adr->hr.http_status,
+ ds->expected_http_status);
+ return;
+ }
+ if (MHD_HTTP_OK == adr->hr.http_status)
+ {
+ const struct TALER_TESTING_Command *ref;
+ const char *justification;
+ enum TALER_AmlDecisionState *new_state;
+ const struct TALER_Amount *amount;
+ const struct TALER_EXCHANGE_AmlDecisionDetail *oldest = NULL;
+
+ ref = TALER_TESTING_interpreter_lookup_command (ds->is,
+ ds->ref_operation);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ds->is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_aml_justification (ref,
+ &justification));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_aml_decision (ref,
+ &new_state));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_amount (ref,
+ &amount));
+ for (unsigned int i = 0; i<adr->details.ok.aml_history_length; i++)
+ {
+ const struct TALER_EXCHANGE_AmlDecisionDetail *aml_history
+ = &adr->details.ok.aml_history[i];
+
+ if ( (NULL == oldest) ||
+ (0 !=
+ TALER_amount_cmp (amount,
+ &oldest->new_threshold)) ||
+ (GNUNET_TIME_timestamp_cmp (oldest->decision_time,
+ >,
+ aml_history->decision_time)) )
+ oldest = aml_history;
+ }
+ if (NULL == oldest)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ds->is);
+ return;
+ }
+ if ( (oldest->new_state != *new_state) ||
+ (0 != strcmp (oldest->justification,
+ justification) ) )
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ds->is);
+ return;
+ }
+ }
+ TALER_TESTING_interpreter_next (ds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+check_aml_decision_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AmlCheckState *ds = cls;
+ const struct TALER_PaytoHashP *h_payto;
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
+ const struct TALER_TESTING_Command *ref;
+ const char *exchange_url;
+
+ (void) cmd;
+ ds->is = is;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
+
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->ref_operation);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_h_payto (ref,
+ &h_payto));
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->ref_officer);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_officer_priv (ref,
+ &officer_priv));
+ ds->dh = TALER_EXCHANGE_lookup_aml_decision (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ h_payto,
+ officer_priv,
+ true, /* history */
+ &check_aml_decision_cb,
+ ds);
+ if (NULL == ds->dh)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "check_aml_decision" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct AmlCheckState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+check_aml_decision_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AmlCheckState *ds = cls;
+
+ if (NULL != ds->dh)
+ {
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
+ TALER_EXCHANGE_lookup_aml_decision_cancel (ds->dh);
+ ds->dh = NULL;
+ }
+ GNUNET_free (ds);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_check_aml_decision (
+ const char *label,
+ const char *ref_officer,
+ const char *ref_operation,
+ unsigned int expected_http_status)
+{
+ struct AmlCheckState *ds;
+
+ ds = GNUNET_new (struct AmlCheckState);
+ ds->ref_officer = ref_officer;
+ ds->ref_operation = ref_operation;
+ ds->expected_http_status = expected_http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &check_aml_decision_run,
+ .cleanup = &check_aml_decision_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_check_aml_decision.c */
diff --git a/src/testing/testing_api_cmd_check_aml_decisions.c b/src/testing/testing_api_cmd_check_aml_decisions.c
new file mode 100644
index 000000000..c8c2ec3f5
--- /dev/null
+++ b/src/testing/testing_api_cmd_check_aml_decisions.c
@@ -0,0 +1,204 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_check_aml_decisions.c
+ * @brief command for testing /aml/$OFFICER/decisions/$FILTER
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "check_aml_decision" CMD.
+ */
+struct AmlCheckState
+{
+
+ /**
+ * Handle while operation is running.
+ */
+ struct TALER_EXCHANGE_LookupAmlDecisions *dh;
+
+ /**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Reference to command to previous set officer.
+ */
+ const char *ref_officer;
+
+ /**
+ * Which states to filter by.
+ */
+ enum TALER_AmlDecisionState filter;
+
+ /**
+ * Expected HTTP status.
+ */
+ unsigned int expected_http_status;
+
+};
+
+
+/**
+ * Callback to analyze the /aml/$OFFICER_PUB/$decisions/$FILTER response, just used to check
+ * if the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param adr response details
+ */
+static void
+check_aml_decisions_cb (void *cls,
+ const struct TALER_EXCHANGE_AmlDecisionsResponse *adr)
+{
+ struct AmlCheckState *ds = cls;
+
+ ds->dh = NULL;
+ if (ds->expected_http_status != adr->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (ds->is,
+ adr->hr.http_status,
+ ds->expected_http_status);
+ return;
+ }
+ TALER_TESTING_interpreter_next (ds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+check_aml_decisions_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AmlCheckState *ds = cls;
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
+ const struct TALER_TESTING_Command *ref;
+ const char *exchange_url;
+
+ (void) cmd;
+ ds->is = is;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->ref_officer);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_officer_priv (ref,
+ &officer_priv));
+ ds->dh = TALER_EXCHANGE_lookup_aml_decisions (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ INT64_MAX,
+ -1, /* return last one for testing */
+ ds->filter,
+ officer_priv,
+ &check_aml_decisions_cb,
+ ds);
+ if (NULL == ds->dh)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "check_aml_decisions" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct AmlCheckState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+check_aml_decisions_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AmlCheckState *ds = cls;
+
+ if (NULL != ds->dh)
+ {
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
+ TALER_EXCHANGE_lookup_aml_decisions_cancel (ds->dh);
+ ds->dh = NULL;
+ }
+ GNUNET_free (ds);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_check_aml_decisions (
+ const char *label,
+ const char *ref_officer,
+ enum TALER_AmlDecisionState filter,
+ unsigned int expected_http_status)
+{
+ struct AmlCheckState *ds;
+
+ ds = GNUNET_new (struct AmlCheckState);
+ ds->ref_officer = ref_officer;
+ ds->filter = filter;
+ ds->expected_http_status = expected_http_status;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &check_aml_decisions_run,
+ .cleanup = &check_aml_decisions_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_check_aml_decisions.c */
diff --git a/src/testing/testing_api_cmd_check_keys.c b/src/testing/testing_api_cmd_check_keys.c
deleted file mode 100644
index 0dee8be3a..000000000
--- a/src/testing/testing_api_cmd_check_keys.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- This file is part of TALER
- (C) 2018, 2020, 2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_check_keys.c
- * @brief Implementation of "check keys" test command.
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_testing_lib.h"
-
-
-/**
- * State for a "check keys" CMD.
- */
-struct CheckKeysState
-{
- /**
- * This number will instruct the CMD interpreter to
- * make sure that /keys was downloaded `generation` times
- * _before_ running the very CMD logic.
- */
- unsigned int generation;
-
- /**
- * If this value is true, then the "cherry
- * picking" facility is turned off; whole /keys is
- * downloaded.
- */
- bool pull_all_keys;
-
- /**
- * Label of a command to use to derive the "last_denom_issue" date to use.
- */
- const char *last_denom_date_ref;
-
- /**
- * Last denomination date we received when doing this request.
- */
- struct GNUNET_TIME_Timestamp my_denom_date;
-};
-
-
-/**
- * Run the "check keys" command.
- *
- * @param cls closure.
- * @param cmd the command currently being executed.
- * @param is the interpreter state.
- */
-static void
-check_keys_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct CheckKeysState *cks = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "cmd `%s' (ip: %u), key generation: %d\n",
- cmd->label,
- is->ip,
- is->key_generation);
- if (is->key_generation < cks->generation)
- {
- struct GNUNET_TIME_Timestamp rdate;
-
- is->working = GNUNET_NO;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Triggering GET /keys, cmd `%s'\n",
- cmd->label);
- if (NULL != cks->last_denom_date_ref)
- {
- if (0 == strcmp ("zero",
- cks->last_denom_date_ref))
- {
- TALER_LOG_DEBUG ("Forcing last_denom_date URL argument set to zero\n");
- TALER_EXCHANGE_set_last_denom (is->exchange,
- GNUNET_TIME_UNIT_ZERO_TS);
- }
- else
- {
- const struct GNUNET_TIME_Timestamp *last_denom_date;
- const struct TALER_TESTING_Command *ref;
-
- ref = TALER_TESTING_interpreter_lookup_command (is,
- cks->last_denom_date_ref);
- if (NULL == ref)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_timestamp (ref,
- 0,
- &last_denom_date))
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- TALER_LOG_DEBUG ("Forcing last_denom_date URL argument\n");
- TALER_EXCHANGE_set_last_denom (is->exchange,
- *last_denom_date);
- }
- }
-
- rdate = TALER_EXCHANGE_check_keys_current (
- is->exchange,
- cks->pull_all_keys
- ? TALER_EXCHANGE_CKF_FORCE_ALL_NOW
- : TALER_EXCHANGE_CKF_FORCE_DOWNLOAD);
- /* Redownload /keys. */
- GNUNET_break (GNUNET_TIME_absolute_is_zero (rdate.abs_time));
- return;
- }
- {
- const struct TALER_EXCHANGE_Keys *keys;
-
- keys = TALER_EXCHANGE_get_keys (is->exchange);
- if (NULL == keys)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- cks->my_denom_date = keys->last_denom_issue_date;
- }
- TALER_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Cleanup the state.
- *
- * @param cls closure.
- * @param cmd the command which is being cleaned up.
- */
-static void
-check_keys_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct CheckKeysState *cks = cls;
-
- (void) cmd;
- GNUNET_free (cks);
-}
-
-
-/**
- * Offer internal data to a "check_keys" CMD state to other
- * commands.
- *
- * @param cls closure
- * @param[out] ret result (could be anything)
- * @param trait name of the trait
- * @param index index number of the object to offer.
- * @return #GNUNET_OK on success
- */
-static int
-check_keys_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct CheckKeysState *cks = cls;
- struct TALER_TESTING_Trait traits[] = {
- /* history entry MUST be first due to response code logic below! */
- TALER_TESTING_make_trait_timestamp (0,
- &cks->my_denom_date),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys (const char *label,
- unsigned int generation)
-{
- struct CheckKeysState *cks;
-
- cks = GNUNET_new (struct CheckKeysState);
- cks->generation = generation;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cks,
- .label = label,
- .run = &check_keys_run,
- .cleanup = &check_keys_cleanup,
- .traits = &check_keys_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys_pull_all_keys (const char *label,
- unsigned int generation)
-{
- struct TALER_TESTING_Command cmd
- = TALER_TESTING_cmd_check_keys (label,
- generation);
- struct CheckKeysState *cks = cmd.cls;
-
- cks->pull_all_keys = true;
- return cmd;
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_check_keys_with_last_denom (
- const char *label,
- unsigned int generation,
- const char *last_denom_date_ref)
-{
- struct TALER_TESTING_Command cmd
- = TALER_TESTING_cmd_check_keys (label,
- generation);
- struct CheckKeysState *cks = cmd.cls;
- cks->last_denom_date_ref = last_denom_date_ref;
- return cmd;
-}
-
-
-/* end of testing_api_cmd_check_keys.c */
diff --git a/src/testing/testing_api_cmd_coin_history.c b/src/testing/testing_api_cmd_coin_history.c
new file mode 100644
index 000000000..a1345f67f
--- /dev/null
+++ b/src/testing/testing_api_cmd_coin_history.c
@@ -0,0 +1,609 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_coin_history.c
+ * @brief Implement the /coins/$COIN_PUB/history test command.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "history" CMD.
+ */
+struct HistoryState
+{
+
+ /**
+ * Public key of the coin being analyzed.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
+ * Label to the command which created the coin to check,
+ * needed to resort the coin key.
+ */
+ const char *coin_reference;
+
+ /**
+ * Handle to the "coin history" operation.
+ */
+ struct TALER_EXCHANGE_CoinsHistoryHandle *rsh;
+
+ /**
+ * Expected coin balance.
+ */
+ const char *expected_balance;
+
+ /**
+ * Private key of the coin being analyzed.
+ */
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+};
+
+
+/**
+ * Closure for analysis_cb().
+ */
+struct AnalysisContext
+{
+ /**
+ * Coin public key we are looking at.
+ */
+ const struct TALER_CoinSpendPublicKeyP *coin_pub;
+
+ /**
+ * Length of the @e history array.
+ */
+ unsigned int history_length;
+
+ /**
+ * Array of history items to match.
+ */
+ const struct TALER_EXCHANGE_CoinHistoryEntry *history;
+
+ /**
+ * Array of @e history_length of matched entries.
+ */
+ bool *found;
+
+ /**
+ * Set to true if an entry could not be found.
+ */
+ bool failure;
+};
+
+
+/**
+ * Compare @a h1 and @a h2.
+ *
+ * @param h1 a history entry
+ * @param h2 a history entry
+ * @return 0 if @a h1 and @a h2 are equal
+ */
+static int
+history_entry_cmp (
+ const struct TALER_EXCHANGE_CoinHistoryEntry *h1,
+ const struct TALER_EXCHANGE_CoinHistoryEntry *h2)
+{
+ if (h1->type != h2->type)
+ return 1;
+ if (0 != TALER_amount_cmp (&h1->amount,
+ &h2->amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Amount mismatch (%s)\n",
+ TALER_amount2s (&h1->amount));
+ return 1;
+ }
+ switch (h1->type)
+ {
+ case TALER_EXCHANGE_CTT_NONE:
+ GNUNET_break (0);
+ break;
+ case TALER_EXCHANGE_CTT_DEPOSIT:
+ if (0 != GNUNET_memcmp (&h1->details.deposit.h_contract_terms,
+ &h2->details.deposit.h_contract_terms))
+ return 1;
+ if (0 != GNUNET_memcmp (&h1->details.deposit.merchant_pub,
+ &h2->details.deposit.merchant_pub))
+ return 1;
+ if (0 != GNUNET_memcmp (&h1->details.deposit.h_wire,
+ &h2->details.deposit.h_wire))
+ return 1;
+ if (0 != GNUNET_memcmp (&h1->details.deposit.sig,
+ &h2->details.deposit.sig))
+ return 1;
+ return 0;
+ case TALER_EXCHANGE_CTT_MELT:
+ if (0 != GNUNET_memcmp (&h1->details.melt.h_age_commitment,
+ &h2->details.melt.h_age_commitment))
+ return 1;
+ /* Note: most other fields are not initialized
+ in the trait as they are hard to extract from
+ the API */
+ return 0;
+ case TALER_EXCHANGE_CTT_REFUND:
+ if (0 != GNUNET_memcmp (&h1->details.refund.sig,
+ &h2->details.refund.sig))
+ return 1;
+ return 0;
+ case TALER_EXCHANGE_CTT_RECOUP:
+ if (0 != GNUNET_memcmp (&h1->details.recoup.coin_sig,
+ &h2->details.recoup.coin_sig))
+ return 1;
+ /* Note: exchange_sig, exchange_pub and timestamp are
+ fundamentally not available in the initiating command */
+ return 0;
+ case TALER_EXCHANGE_CTT_RECOUP_REFRESH:
+ if (0 != GNUNET_memcmp (&h1->details.recoup_refresh.coin_sig,
+ &h2->details.recoup_refresh.coin_sig))
+ return 1;
+ /* Note: exchange_sig, exchange_pub and timestamp are
+ fundamentally not available in the initiating command */
+ return 0;
+ case TALER_EXCHANGE_CTT_OLD_COIN_RECOUP:
+ if (0 != GNUNET_memcmp (&h1->details.old_coin_recoup.new_coin_pub,
+ &h2->details.old_coin_recoup.new_coin_pub))
+ return 1;
+ /* Note: exchange_sig, exchange_pub and timestamp are
+ fundamentally not available in the initiating command */
+ return 0;
+ case TALER_EXCHANGE_CTT_PURSE_DEPOSIT:
+ /* coin_sig is not initialized */
+ if (0 != GNUNET_memcmp (&h1->details.purse_deposit.purse_pub,
+ &h2->details.purse_deposit.purse_pub))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Purse public key mismatch\n");
+ return 1;
+ }
+ if (0 != strcmp (h1->details.purse_deposit.exchange_base_url,
+ h2->details.purse_deposit.exchange_base_url))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Exchange base URL mismatch (%s/%s)\n",
+ h1->details.purse_deposit.exchange_base_url,
+ h2->details.purse_deposit.exchange_base_url);
+ GNUNET_break (0);
+ return 1;
+ }
+ return 0;
+ case TALER_EXCHANGE_CTT_PURSE_REFUND:
+ /* NOTE: not supported yet (trait not returned) */
+ return 0;
+ case TALER_EXCHANGE_CTT_RESERVE_OPEN_DEPOSIT:
+ /* NOTE: not supported yet (trait not returned) */
+ if (0 != GNUNET_memcmp (&h1->details.reserve_open_deposit.coin_sig,
+ &h2->details.reserve_open_deposit.coin_sig))
+ return 1;
+ return 0;
+ }
+ GNUNET_assert (0);
+ return -1;
+}
+
+
+/**
+ * Check if @a cmd changed the coin, if so, find the
+ * entry in our history and set the respective index in found
+ * to true. If the entry is not found, set failure.
+ *
+ * @param cls our `struct AnalysisContext *`
+ * @param cmd command to analyze for impact on history
+ */
+static void
+analyze_command (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AnalysisContext *ac = cls;
+ const struct TALER_CoinSpendPublicKeyP *coin_pub = ac->coin_pub;
+ const struct TALER_EXCHANGE_CoinHistoryEntry *history = ac->history;
+ unsigned int history_length = ac->history_length;
+ bool *found = ac->found;
+
+ if (TALER_TESTING_cmd_is_batch (cmd))
+ {
+ struct TALER_TESTING_Command *cur;
+ struct TALER_TESTING_Command *bcmd;
+
+ cur = TALER_TESTING_cmd_batch_get_current (cmd);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_batch_cmds (cmd,
+ &bcmd))
+ {
+ GNUNET_break (0);
+ ac->failure = true;
+ return;
+ }
+ for (unsigned int i = 0; NULL != bcmd[i].label; i++)
+ {
+ struct TALER_TESTING_Command *step = &bcmd[i];
+
+ analyze_command (ac,
+ step);
+ if (ac->failure)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Entry for batch step `%s' missing in history\n",
+ step->label);
+ return;
+ }
+ if (step == cur)
+ break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */
+ }
+ return;
+ }
+
+ for (unsigned int j = 0; true; j++)
+ {
+ const struct TALER_CoinSpendPublicKeyP *rp;
+ const struct TALER_EXCHANGE_CoinHistoryEntry *he;
+ bool matched = false;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_pub (cmd,
+ j,
+ &rp))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Command `%s#%u' has no public key for a coin\n",
+ cmd->label,
+ j);
+ break; /* command does nothing for coins */
+ }
+ if (0 !=
+ GNUNET_memcmp (rp,
+ coin_pub))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Command `%s#%u' is about another coin\n",
+ cmd->label,
+ j);
+ continue; /* command affects some _other_ coin */
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_history (cmd,
+ j,
+ &he))
+ {
+ /* NOTE: only for debugging... */
+ if (0 == j)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Command `%s' has the coin_pub, but lacks coin history trait\n",
+ cmd->label);
+ return; /* command does nothing for coins */
+ }
+ for (unsigned int i = 0; i<history_length; i++)
+ {
+ if (found[i])
+ continue; /* already found, skip */
+ if (0 ==
+ history_entry_cmp (he,
+ &history[i]))
+ {
+ found[i] = true;
+ matched = true;
+ break;
+ }
+ }
+ if (! matched)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Command `%s' coin history entry #%u not found\n",
+ cmd->label,
+ j);
+ ac->failure = true;
+ return;
+ }
+ }
+}
+
+
+/**
+ * Check that the coin balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rs HTTP response details
+ */
+static void
+coin_history_cb (void *cls,
+ const struct TALER_EXCHANGE_CoinHistory *rs)
+{
+ struct HistoryState *ss = cls;
+ struct TALER_TESTING_Interpreter *is = ss->is;
+ struct TALER_Amount eb;
+ unsigned int hlen;
+
+ ss->rsh = NULL;
+ if (ss->expected_response_code != rs->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (ss->is,
+ rs->hr.http_status,
+ ss->expected_response_code);
+ return;
+ }
+ if (MHD_HTTP_OK != rs->hr.http_status)
+ {
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (ss->expected_balance,
+ &eb));
+
+ if (0 != TALER_amount_cmp (&eb,
+ &rs->details.ok.balance))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected balance for coin: %s\n",
+ TALER_amount_to_string (&rs->details.ok.balance));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Expected balance of: %s\n",
+ TALER_amount_to_string (&eb));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ hlen = json_array_size (rs->details.ok.history);
+ {
+ bool found[GNUNET_NZL (hlen)];
+ struct TALER_EXCHANGE_CoinHistoryEntry rhist[GNUNET_NZL (hlen)];
+ struct AnalysisContext ac = {
+ .coin_pub = &ss->coin_pub,
+ .history = rhist,
+ .history_length = hlen,
+ .found = found
+ };
+ const struct TALER_EXCHANGE_DenomPublicKey *dk;
+ struct TALER_Amount total_in;
+ struct TALER_Amount total_out;
+ struct TALER_Amount hbal;
+
+ dk = TALER_EXCHANGE_get_denomination_key_by_hash (
+ TALER_TESTING_get_keys (is),
+ &rs->details.ok.h_denom_pub);
+ memset (found,
+ 0,
+ sizeof (found));
+ memset (rhist,
+ 0,
+ sizeof (rhist));
+ if (GNUNET_OK !=
+ TALER_EXCHANGE_parse_coin_history (
+ TALER_TESTING_get_keys (is),
+ dk,
+ rs->details.ok.history,
+ &ss->coin_pub,
+ &total_in,
+ &total_out,
+ hlen,
+ rhist))
+ {
+ GNUNET_break (0);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ if (0 >
+ TALER_amount_subtract (&hbal,
+ &total_in,
+ &total_out))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Coin credits: %s\n",
+ TALER_amount2s (&total_in));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Coin debits: %s\n",
+ TALER_amount2s (&total_out));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ if (0 != TALER_amount_cmp (&hbal,
+ &rs->details.ok.balance))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ (void) ac;
+ TALER_TESTING_iterate (is,
+ true,
+ &analyze_command,
+ &ac);
+ if (ac.failure)
+ {
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+#if 1
+ for (unsigned int i = 0; i<hlen; i++)
+ {
+ if (found[i])
+ continue;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "History entry at index %u of type %d not justified by command history\n",
+ i,
+ rs->details.ok.history[i].type);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+#endif
+ }
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+history_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct HistoryState *ss = cls;
+ const struct TALER_TESTING_Command *create_coin;
+ char *cref;
+ unsigned int idx;
+
+ ss->is = is;
+ GNUNET_assert (
+ GNUNET_OK ==
+ TALER_TESTING_parse_coin_reference (
+ ss->coin_reference,
+ &cref,
+ &idx));
+ create_coin
+ = TALER_TESTING_interpreter_lookup_command (is,
+ cref);
+ if (NULL == create_coin)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (create_coin,
+ idx,
+ &ss->coin_priv))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Failed to find coin_priv for history query\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&ss->coin_priv->eddsa_priv,
+ &ss->coin_pub.eddsa_pub);
+ ss->rsh = TALER_EXCHANGE_coins_history (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ ss->coin_priv,
+ 0,
+ &coin_history_cb,
+ ss);
+}
+
+
+/**
+ * Offer internal data from a "history" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+history_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct HistoryState *hs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_coin_pub (0,
+ &hs->coin_pub),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Cleanup the state from a "coin history" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+history_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct HistoryState *ss = cls;
+
+ if (NULL != ss->rsh)
+ {
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ TALER_EXCHANGE_coins_history_cancel (ss->rsh);
+ ss->rsh = NULL;
+ }
+ GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_coin_history (const char *label,
+ const char *coin_reference,
+ const char *expected_balance,
+ unsigned int expected_response_code)
+{
+ struct HistoryState *ss;
+
+ GNUNET_assert (NULL != coin_reference);
+ ss = GNUNET_new (struct HistoryState);
+ ss->coin_reference = coin_reference;
+ ss->expected_balance = expected_balance;
+ ss->expected_response_code = expected_response_code;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &history_run,
+ .cleanup = &history_cleanup,
+ .traits = &history_traits
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_common.c b/src/testing/testing_api_cmd_common.c
index 138e5502a..2d828a2b0 100644
--- a/src/testing/testing_api_cmd_common.c
+++ b/src/testing/testing_api_cmd_common.c
@@ -25,117 +25,6 @@
#include "taler_testing_lib.h"
-int
-TALER_TESTING_history_entry_cmp (
- const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
- const struct TALER_EXCHANGE_ReserveHistoryEntry *h2)
-{
- if (h1->type != h2->type)
- return 1;
- switch (h1->type)
- {
- case TALER_EXCHANGE_RTT_CREDIT:
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (0 == strcasecmp (h1->details.in_details.sender_url,
- h2->details.in_details.sender_url)) &&
- (h1->details.in_details.wire_reference ==
- h2->details.in_details.wire_reference) &&
- (GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
- ==,
- h2->details.in_details.timestamp)) )
- return 0;
- return 1;
- case TALER_EXCHANGE_RTT_WITHDRAWAL:
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (0 ==
- TALER_amount_cmp (&h1->details.withdraw.fee,
- &h2->details.withdraw.fee)) )
- /* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
- so we cannot test for it here. but if the amount matches,
- that should be good enough. */
- return 0;
- return 1;
- case TALER_EXCHANGE_RTT_RECOUP:
- /* exchange_sig, exchange_pub and timestamp are NOT available
- from the original recoup response, hence here NOT check(able/ed) */
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (0 ==
- GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
- &h2->details.recoup_details.coin_pub)) )
- return 0;
- return 1;
- case TALER_EXCHANGE_RTT_CLOSE:
- /* testing_api_cmd_exec_closer doesn't set the
- receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
- so we cannot test for it here. but if the amount matches,
- that should be good enough. */
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (0 ==
- TALER_amount_cmp (&h1->details.close_details.fee,
- &h2->details.close_details.fee)) )
- return 0;
- return 1;
- case TALER_EXCHANGE_RTT_HISTORY:
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (GNUNET_TIME_timestamp_cmp (
- h1->details.history_details.request_timestamp,
- ==,
- h2->details.history_details.
- request_timestamp)) &&
- (0 ==
- GNUNET_memcmp (&h1->details.history_details.reserve_sig,
- &h2->details.history_details.reserve_sig)) )
- return 0;
- return 1;
- case TALER_EXCHANGE_RTT_MERGE:
- if ( (0 ==
- TALER_amount_cmp (&h1->amount,
- &h2->amount)) &&
- (0 ==
- TALER_amount_cmp (&h1->details.merge_details.purse_fee,
- &h2->details.merge_details.purse_fee)) &&
- (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.merge_timestamp,
- ==,
- h2->details.merge_details.merge_timestamp))
- &&
- (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.purse_expiration,
- ==,
- h2->details.merge_details.purse_expiration))
- &&
- (0 ==
- GNUNET_memcmp (&h1->details.merge_details.merge_pub,
- &h2->details.merge_details.merge_pub)) &&
- (0 ==
- GNUNET_memcmp (&h1->details.merge_details.h_contract_terms,
- &h2->details.merge_details.h_contract_terms)) &&
- (0 ==
- GNUNET_memcmp (&h1->details.merge_details.purse_pub,
- &h2->details.merge_details.purse_pub)) &&
- (0 ==
- GNUNET_memcmp (&h1->details.merge_details.reserve_sig,
- &h2->details.merge_details.reserve_sig)) &&
- (h1->details.merge_details.min_age ==
- h2->details.merge_details.min_age) &&
- (h1->details.merge_details.flags ==
- h2->details.merge_details.flags) )
- return 0;
- return 1;
- }
- GNUNET_assert (0);
- return 1;
-}
-
-
enum GNUNET_GenericReturnValue
TALER_TESTING_parse_coin_reference (
const char *coin_reference,
diff --git a/src/testing/testing_api_cmd_contract_get.c b/src/testing/testing_api_cmd_contract_get.c
index 10a43aa3b..fa83d83f7 100644
--- a/src/testing/testing_api_cmd_contract_get.c
+++ b/src/testing/testing_api_cmd_contract_get.c
@@ -101,26 +101,20 @@ get_cb (void *cls,
ds->dh = NULL;
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
ref = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->contract_ref);
+ GNUNET_assert (NULL != ref);
if (MHD_HTTP_OK == dr->hr.http_status)
{
const struct TALER_PurseMergePrivateKeyP *mp;
const json_t *ct;
- ds->purse_pub = dr->details.success.purse_pub;
+ ds->purse_pub = dr->details.ok.purse_pub;
if (ds->merge)
{
if (GNUNET_OK !=
@@ -135,8 +129,8 @@ get_cb (void *cls,
TALER_CRYPTO_contract_decrypt_for_merge (
&ds->contract_priv,
&ds->purse_pub,
- dr->details.success.econtract,
- dr->details.success.econtract_size,
+ dr->details.ok.econtract,
+ dr->details.ok.econtract_size,
&ds->merge_priv);
if (0 !=
GNUNET_memcmp (mp,
@@ -152,8 +146,8 @@ get_cb (void *cls,
ds->contract_terms =
TALER_CRYPTO_contract_decrypt_for_deposit (
&ds->contract_priv,
- dr->details.success.econtract,
- dr->details.success.econtract_size);
+ dr->details.ok.econtract,
+ dr->details.ok.econtract_size);
}
if (NULL == ds->contract_terms)
{
@@ -197,9 +191,16 @@ get_run (void *cls,
struct ContractGetState *ds = cls;
const struct TALER_ContractDiffiePrivateP *contract_priv;
const struct TALER_TESTING_Command *ref;
+ const char *exchange_url;
(void) cmd;
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);
@@ -213,7 +214,8 @@ get_run (void *cls,
}
ds->contract_priv = *contract_priv;
ds->dh = TALER_EXCHANGE_contract_get (
- is->exchange,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
contract_priv,
&get_cb,
ds);
@@ -243,10 +245,8 @@ get_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_contract_get_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_deposit.c b/src/testing/testing_api_cmd_deposit.c
index c54d87591..849c78c70 100644
--- a/src/testing/testing_api_cmd_deposit.c
+++ b/src/testing/testing_api_cmd_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018-2021 Taler Systems SA
+ Copyright (C) 2018-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -69,6 +69,11 @@ struct DepositState
unsigned int coin_index;
/**
+ * Our coin signature.
+ */
+ struct TALER_CoinSpendSignatureP coin_sig;
+
+ /**
* Wire details of who is depositing -- this would be merchant
* wire details in a normal scenario.
*/
@@ -98,7 +103,12 @@ struct DepositState
/**
* Deposit handle while operation is running.
*/
- struct TALER_EXCHANGE_DepositHandle *dh;
+ struct TALER_EXCHANGE_BatchDepositHandle *dh;
+
+ /**
+ * Denomination public key of the deposited coin.
+ */
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
/**
* Timestamp of the /deposit operation in the wallet (contract signing time).
@@ -131,10 +141,16 @@ struct DepositState
unsigned int do_retry;
/**
- * Set to #GNUNET_YES if the /deposit succeeded
+ * Set to true if the /deposit succeeded
* and we now can provide the resulting traits.
*/
- int deposit_succeeded;
+ bool deposit_succeeded;
+
+ /**
+ * Expected entry in the coin history created by this
+ * operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
/**
* When did the exchange receive the deposit?
@@ -165,7 +181,7 @@ struct DepositState
* When we're referencing another deposit operation,
* this will only be set after the command has been started.
*/
- int command_initialized;
+ bool command_initialized;
/**
* Reference to fetch the merchant private key from.
@@ -199,8 +215,7 @@ do_retry (void *cls)
struct DepositState *ds = cls;
ds->retry_task = NULL;
- ds->is->commands[ds->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (ds->is);
deposit_run (ds,
NULL,
ds->is);
@@ -216,7 +231,7 @@ do_retry (void *cls)
*/
static void
deposit_cb (void *cls,
- const struct TALER_EXCHANGE_DepositResult *dr)
+ const struct TALER_EXCHANGE_BatchDepositResult *dr)
{
struct DepositState *ds = cls;
@@ -240,7 +255,7 @@ deposit_cb (void *cls,
else
ds->backoff = GNUNET_TIME_randomized_backoff (ds->backoff,
MAX_BACKOFF);
- ds->is->commands[ds->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (ds->is);
GNUNET_assert (NULL == ds->retry_task);
ds->retry_task
= GNUNET_SCHEDULER_add_delayed (ds->backoff,
@@ -249,24 +264,20 @@ deposit_cb (void *cls,
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status_with_body (
+ ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code,
+ dr->hr.reply);
+
return;
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
- ds->deposit_succeeded = GNUNET_YES;
- ds->exchange_timestamp = dr->details.success.deposit_timestamp;
- ds->exchange_pub = *dr->details.success.exchange_pub;
- ds->exchange_sig = *dr->details.success.exchange_sig;
+ ds->deposit_succeeded = true;
+ ds->exchange_timestamp = dr->details.ok.deposit_timestamp;
+ ds->exchange_pub = *dr->details.ok.exchange_pub;
+ ds->exchange_sig = *dr->details.ok.exchange_sig;
}
TALER_TESTING_interpreter_next (ds->is);
}
@@ -288,11 +299,8 @@ deposit_run (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
struct TALER_CoinSpendPublicKeyP coin_pub;
- const struct TALER_AgeCommitmentProof *age_commitment_proof = NULL;
- struct TALER_AgeCommitmentHash h_age_commitment = {0};
- const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+ const struct TALER_AgeCommitmentHash *phac;
const struct TALER_DenominationSignature *denom_pub_sig;
- struct TALER_CoinSpendSignatureP coin_sig;
struct TALER_MerchantPublicKeyP merchant_pub;
struct TALER_PrivateContractHashP h_contract_terms;
enum TALER_ErrorCode ec;
@@ -305,9 +313,32 @@ deposit_run (void *cls,
&wire_salt),
GNUNET_JSON_spec_end ()
};
+ const char *exchange_url
+ = TALER_TESTING_get_exchange_url (is);
(void) cmd;
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
ds->is = is;
+ if (! GNUNET_TIME_absolute_is_zero (ds->refund_deadline.abs_time))
+ {
+ struct GNUNET_TIME_Relative refund_deadline;
+
+ refund_deadline
+ = GNUNET_TIME_absolute_get_remaining (ds->refund_deadline.abs_time);
+ ds->wire_deadline
+ = GNUNET_TIME_relative_to_timestamp (
+ GNUNET_TIME_relative_multiply (refund_deadline,
+ 2));
+ }
+ else
+ {
+ ds->refund_deadline = ds->wallet_timestamp;
+ ds->wire_deadline = GNUNET_TIME_timestamp_get ();
+ }
if (NULL != ds->deposit_reference)
{
/* We're copying another deposit operation, initialize here. */
@@ -330,9 +361,10 @@ deposit_run (void *cls,
ds->contract_terms = json_incref (ods->contract_terms);
ds->wallet_timestamp = ods->wallet_timestamp;
ds->refund_deadline = ods->refund_deadline;
+ ds->wire_deadline = ods->wire_deadline;
ds->amount = ods->amount;
ds->merchant_priv = ods->merchant_priv;
- ds->command_initialized = GNUNET_YES;
+ ds->command_initialized = true;
}
else if (NULL != ds->merchant_priv_reference)
{
@@ -386,13 +418,13 @@ deposit_run (void *cls,
ds->coin_index,
&coin_priv)) ||
(GNUNET_OK !=
- TALER_TESTING_get_trait_age_commitment_proof (coin_cmd,
- ds->coin_index,
- &age_commitment_proof)) ||
+ TALER_TESTING_get_trait_h_age_commitment (coin_cmd,
+ ds->coin_index,
+ &phac)) ||
(GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (coin_cmd,
ds->coin_index,
- &denom_pub)) ||
+ &ds->denom_pub)) ||
(GNUNET_OK !=
TALER_TESTING_get_trait_denom_sig (coin_cmd,
ds->coin_index,
@@ -406,32 +438,10 @@ deposit_run (void *cls,
return;
}
- if (NULL != age_commitment_proof)
- {
- TALER_age_commitment_hash (&age_commitment_proof->commitment,
- &h_age_commitment);
- }
- ds->deposit_fee = denom_pub->fees.deposit;
+ ds->deposit_fee = ds->denom_pub->fees.deposit;
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
- if (! GNUNET_TIME_absolute_is_zero (ds->refund_deadline.abs_time))
- {
- struct GNUNET_TIME_Relative refund_deadline;
-
- refund_deadline
- = GNUNET_TIME_absolute_get_remaining (ds->refund_deadline.abs_time);
- ds->wire_deadline
- =
- GNUNET_TIME_relative_to_timestamp (
- GNUNET_TIME_relative_multiply (refund_deadline,
- 2));
- }
- else
- {
- ds->refund_deadline = ds->wallet_timestamp;
- ds->wire_deadline = GNUNET_TIME_timestamp_get ();
- }
GNUNET_CRYPTO_eddsa_key_get_public (&ds->merchant_priv.eddsa_priv,
&merchant_pub.eddsa_pub);
{
@@ -441,45 +451,64 @@ deposit_run (void *cls,
TALER_JSON_merchant_wire_signature_hash (ds->wire_details,
&h_wire));
TALER_wallet_deposit_sign (&ds->amount,
- &denom_pub->fees.deposit,
+ &ds->denom_pub->fees.deposit,
&h_wire,
&h_contract_terms,
- &h_age_commitment,
- NULL, /* FIXME: add hash of extensions */
- &denom_pub->h_key,
+ NULL, /* wallet data hash */
+ phac,
+ NULL, /* hash of extensions */
+ &ds->denom_pub->h_key,
ds->wallet_timestamp,
&merchant_pub,
ds->refund_deadline,
coin_priv,
- &coin_sig);
+ &ds->coin_sig);
+ ds->che.type = TALER_EXCHANGE_CTT_DEPOSIT;
+ ds->che.amount = ds->amount;
+ ds->che.details.deposit.h_wire = h_wire;
+ ds->che.details.deposit.h_contract_terms = h_contract_terms;
+ ds->che.details.deposit.no_h_policy = true;
+ ds->che.details.deposit.no_wallet_data_hash = true;
+ ds->che.details.deposit.wallet_timestamp = ds->wallet_timestamp;
+ ds->che.details.deposit.merchant_pub = merchant_pub;
+ ds->che.details.deposit.refund_deadline = ds->refund_deadline;
+ ds->che.details.deposit.sig = ds->coin_sig;
+ ds->che.details.deposit.no_hac = true;
+ ds->che.details.deposit.deposit_fee = ds->denom_pub->fees.deposit;
}
GNUNET_assert (NULL == ds->dh);
{
struct TALER_EXCHANGE_CoinDepositDetail cdd = {
.amount = ds->amount,
- .h_age_commitment = h_age_commitment,
.coin_pub = coin_pub,
- .coin_sig = coin_sig,
+ .coin_sig = ds->coin_sig,
.denom_sig = *denom_pub_sig,
- .h_denom_pub = denom_pub->h_key
+ .h_denom_pub = ds->denom_pub->h_key,
+ .h_age_commitment = {{{0}}},
};
struct TALER_EXCHANGE_DepositContractDetail dcd = {
.wire_deadline = ds->wire_deadline,
.merchant_payto_uri = payto_uri,
.wire_salt = wire_salt,
.h_contract_terms = h_contract_terms,
- .extension_details = NULL /* FIXME-OEC */,
- .timestamp = ds->wallet_timestamp,
+ .wallet_timestamp = ds->wallet_timestamp,
.merchant_pub = merchant_pub,
.refund_deadline = ds->refund_deadline
};
- ds->dh = TALER_EXCHANGE_deposit (is->exchange,
- &dcd,
- &cdd,
- &deposit_cb,
- ds,
- &ec);
+ if (NULL != phac)
+ cdd.h_age_commitment = *phac;
+
+ ds->dh = TALER_EXCHANGE_batch_deposit (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ TALER_TESTING_get_keys (is),
+ &dcd,
+ 1,
+ &cdd,
+ &deposit_cb,
+ ds,
+ &ec);
}
if (NULL == ds->dh)
{
@@ -508,11 +537,9 @@ deposit_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
- TALER_EXCHANGE_deposit_cancel (ds->dh);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
+ TALER_EXCHANGE_batch_deposit_cancel (ds->dh);
ds->dh = NULL;
}
if (NULL != ds->retry_task)
@@ -545,9 +572,11 @@ deposit_traits (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
/* Will point to coin cmd internals. */
const struct TALER_CoinSpendPrivateKeyP *coin_spent_priv;
+ struct TALER_CoinSpendPublicKeyP coin_spent_pub;
const struct TALER_AgeCommitmentProof *age_commitment_proof;
+ const struct TALER_AgeCommitmentHash *h_age_commitment;
- if (GNUNET_YES != ds->command_initialized)
+ if (! ds->command_initialized)
{
/* No access to traits yet. */
GNUNET_break (0);
@@ -570,25 +599,43 @@ deposit_traits (void *cls,
(GNUNET_OK !=
TALER_TESTING_get_trait_age_commitment_proof (coin_cmd,
ds->coin_index,
- &age_commitment_proof)) )
+ &age_commitment_proof)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_h_age_commitment (coin_cmd,
+ ds->coin_index,
+ &h_age_commitment)) )
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (ds->is);
return GNUNET_NO;
}
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_spent_priv->eddsa_priv,
+ &coin_spent_pub.eddsa_pub);
+
{
struct TALER_TESTING_Trait traits[] = {
/* First two traits are only available if
- ds->traits is #GNUNET_YES */
+ ds->traits is true */
TALER_TESTING_make_trait_exchange_pub (0,
&ds->exchange_pub),
TALER_TESTING_make_trait_exchange_sig (0,
&ds->exchange_sig),
/* These traits are always available */
+ TALER_TESTING_make_trait_coin_history (0,
+ &ds->che),
TALER_TESTING_make_trait_coin_priv (0,
coin_spent_priv),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &coin_spent_pub),
+ TALER_TESTING_make_trait_denom_pub (0,
+ ds->denom_pub),
+ TALER_TESTING_make_trait_coin_sig (0,
+ &ds->coin_sig),
TALER_TESTING_make_trait_age_commitment_proof (0,
age_commitment_proof),
+ TALER_TESTING_make_trait_h_age_commitment (0,
+ h_age_commitment),
TALER_TESTING_make_trait_wire_details (ds->wire_details),
TALER_TESTING_make_trait_contract_terms (ds->contract_terms),
TALER_TESTING_make_trait_merchant_priv (&ds->merchant_priv),
@@ -616,14 +663,15 @@ deposit_traits (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_deposit (const char *label,
- const char *coin_reference,
- unsigned int coin_index,
- const char *target_account_payto,
- const char *contract_terms,
- struct GNUNET_TIME_Relative refund_deadline,
- const char *amount,
- unsigned int expected_response_code)
+TALER_TESTING_cmd_deposit (
+ const char *label,
+ const char *coin_reference,
+ unsigned int coin_index,
+ const char *target_account_payto,
+ const char *contract_terms,
+ struct GNUNET_TIME_Relative refund_deadline,
+ const char *amount,
+ unsigned int expected_response_code)
{
struct DepositState *ds;
@@ -663,7 +711,7 @@ TALER_TESTING_cmd_deposit (const char *label,
TALER_string_to_amount (amount,
&ds->amount));
ds->expected_response_code = expected_response_code;
- ds->command_initialized = GNUNET_YES;
+ ds->command_initialized = true;
{
struct TALER_TESTING_Command cmd = {
.cls = ds,
@@ -679,15 +727,16 @@ TALER_TESTING_cmd_deposit (const char *label,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_deposit_with_ref (const char *label,
- const char *coin_reference,
- unsigned int coin_index,
- const char *target_account_payto,
- const char *contract_terms,
- struct GNUNET_TIME_Relative refund_deadline,
- const char *amount,
- unsigned int expected_response_code,
- const char *merchant_priv_reference)
+TALER_TESTING_cmd_deposit_with_ref (
+ const char *label,
+ const char *coin_reference,
+ unsigned int coin_index,
+ const char *target_account_payto,
+ const char *contract_terms,
+ struct GNUNET_TIME_Relative refund_deadline,
+ const char *amount,
+ unsigned int expected_response_code,
+ const char *merchant_priv_reference)
{
struct DepositState *ds;
@@ -709,21 +758,25 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label,
GNUNET_assert (0);
}
ds->wallet_timestamp = GNUNET_TIME_timestamp_get ();
- json_object_set_new (ds->contract_terms,
- "timestamp",
- GNUNET_JSON_from_timestamp (ds->wallet_timestamp));
+ GNUNET_assert (0 ==
+ json_object_set_new (ds->contract_terms,
+ "timestamp",
+ GNUNET_JSON_from_timestamp (
+ ds->wallet_timestamp)));
if (0 != refund_deadline.rel_value_us)
{
ds->refund_deadline = GNUNET_TIME_relative_to_timestamp (refund_deadline);
- json_object_set_new (ds->contract_terms,
- "refund_deadline",
- GNUNET_JSON_from_timestamp (ds->refund_deadline));
+ GNUNET_assert (0 ==
+ json_object_set_new (ds->contract_terms,
+ "refund_deadline",
+ GNUNET_JSON_from_timestamp (
+ ds->refund_deadline)));
}
GNUNET_assert (GNUNET_OK ==
TALER_string_to_amount (amount,
&ds->amount));
ds->expected_response_code = expected_response_code;
- ds->command_initialized = GNUNET_YES;
+ ds->command_initialized = true;
{
struct TALER_TESTING_Command cmd = {
.cls = ds,
@@ -739,9 +792,10 @@ TALER_TESTING_cmd_deposit_with_ref (const char *label,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_deposit_replay (const char *label,
- const char *deposit_reference,
- unsigned int expected_response_code)
+TALER_TESTING_cmd_deposit_replay (
+ const char *label,
+ const char *deposit_reference,
+ unsigned int expected_response_code)
{
struct DepositState *ds;
diff --git a/src/testing/testing_api_cmd_deposits_get.c b/src/testing/testing_api_cmd_deposits_get.c
index 42dc1cb81..5d4436e2a 100644
--- a/src/testing/testing_api_cmd_deposits_get.c
+++ b/src/testing/testing_api_cmd_deposits_get.c
@@ -40,6 +40,11 @@ struct TrackTransactionState
const char *bank_transfer_reference;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* The WTID associated by the transaction being tracked.
*/
struct TALER_WireTransferIdentifierRawP wtid;
@@ -50,10 +55,18 @@ struct TrackTransactionState
unsigned int expected_response_code;
/**
- * Set to the KYC UUID *if* the exchange replied with
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC (#MHD_HTTP_ACCEPTED).
+ * Note: set based on our @e merchant_payto_uri, as
+ * the exchange does not respond with the payto hash.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
* a request for KYC (#MHD_HTTP_ACCEPTED).
*/
- uint64_t kyc_uuid;
+ uint64_t requirement_row;
/**
* Reference to any operation that can provide a transaction.
@@ -99,28 +112,19 @@ deposit_wtid_cb (void *cls,
{
struct TrackTransactionState *tts = cls;
struct TALER_TESTING_Interpreter *is = tts->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
tts->tth = NULL;
if (tts->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- dr->hr.http_status,
- (int) dr->hr.ec,
- cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ dr->hr.http_status,
+ tts->expected_response_code);
return;
}
switch (dr->hr.http_status)
{
case MHD_HTTP_OK:
- tts->wtid = dr->details.success.wtid;
+ tts->wtid = dr->details.ok.wtid;
if (NULL != tts->bank_transfer_reference)
{
const struct TALER_TESTING_Command *bank_transfer_cmd;
@@ -147,7 +151,7 @@ deposit_wtid_cb (void *cls,
}
/* Compare that expected and gotten subjects match. */
- if (0 != GNUNET_memcmp (&dr->details.success.wtid,
+ if (0 != GNUNET_memcmp (&dr->details.ok.wtid,
wtid_want))
{
GNUNET_break (0);
@@ -158,7 +162,10 @@ deposit_wtid_cb (void *cls,
break;
case MHD_HTTP_ACCEPTED:
/* allowed, nothing to check here */
- tts->kyc_uuid = dr->details.accepted.payment_target_uuid;
+ TALER_payto_hash (tts->merchant_payto_uri,
+ &tts->h_payto);
+ tts->requirement_row
+ = dr->details.accepted.requirement_row;
break;
case MHD_HTTP_NOT_FOUND:
/* allowed, nothing to check here */
@@ -193,7 +200,7 @@ track_transaction_run (void *cls,
struct TALER_PrivateContractHashP h_contract_terms;
const struct TALER_MerchantPrivateKeyP *merchant_priv;
- (void) cmd;
+ tts->cmd = cmd;
tts->is = is;
transaction_cmd
= TALER_TESTING_interpreter_lookup_command (tts->is,
@@ -265,13 +272,17 @@ track_transaction_run (void *cls,
return;
}
- tts->tth = TALER_EXCHANGE_deposits_get (is->exchange,
- merchant_priv,
- &h_wire_details,
- &h_contract_terms,
- &coin_pub,
- &deposit_wtid_cb,
- tts);
+ tts->tth = TALER_EXCHANGE_deposits_get (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ merchant_priv,
+ &h_wire_details,
+ &h_contract_terms,
+ &coin_pub,
+ GNUNET_TIME_UNIT_ZERO,
+ &deposit_wtid_cb,
+ tts);
GNUNET_assert (NULL != tts->tth);
}
@@ -291,10 +302,8 @@ track_transaction_cleanup (void *cls,
if (NULL != tts->tth)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- tts->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (tts->is,
+ cmd->label);
TALER_EXCHANGE_deposits_get_cancel (tts->tth);
tts->tth = NULL;
}
@@ -321,9 +330,10 @@ track_transaction_traits (void *cls,
struct TrackTransactionState *tts = cls;
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_wtid (&tts->wtid),
- TALER_TESTING_make_trait_payment_target_uuid (&tts->kyc_uuid),
- TALER_TESTING_make_trait_payto_uri (
- (const char **) &tts->merchant_payto_uri),
+ TALER_TESTING_make_trait_legi_requirement_row (
+ &tts->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&tts->h_payto),
+ TALER_TESTING_make_trait_payto_uri (tts->merchant_payto_uri),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_exec_aggregator.c b/src/testing/testing_api_cmd_exec_aggregator.c
index 0f3cc1e14..1f05576ff 100644
--- a/src/testing/testing_api_cmd_exec_aggregator.c
+++ b/src/testing/testing_api_cmd_exec_aggregator.c
@@ -72,7 +72,6 @@ aggregator_run (void *cls,
"taler-exchange-aggregator",
"taler-exchange-aggregator",
"-c", as->config_filename,
- "-L", "INFO",
"-t", /* exit when done */
(as->kyc_on)
? NULL
diff --git a/src/testing/testing_api_cmd_exec_closer.c b/src/testing/testing_api_cmd_exec_closer.c
index 75eab2d9f..2501b39a6 100644
--- a/src/testing/testing_api_cmd_exec_closer.c
+++ b/src/testing/testing_api_cmd_exec_closer.c
@@ -91,6 +91,7 @@ closer_run (void *cls,
rcmd = TALER_TESTING_interpreter_lookup_command (is,
as->reserve_ref);
+ GNUNET_assert (NULL != rcmd);
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_pub (rcmd,
&reserve_pubp))
@@ -221,11 +222,11 @@ TALER_TESTING_cmd_exec_closer (const char *label,
/* expected amount includes fee, while our argument
gives the amount _without_ the fee. So add the fee. */
GNUNET_assert (0 <=
- TALER_amount_add (&as->reserve_history.amount,
- &as->reserve_history.amount,
- &as->reserve_history.details.close_details.
- fee));
- as->reserve_history.type = TALER_EXCHANGE_RTT_CLOSE;
+ TALER_amount_add (
+ &as->reserve_history.amount,
+ &as->reserve_history.amount,
+ &as->reserve_history.details.close_details.fee));
+ as->reserve_history.type = TALER_EXCHANGE_RTT_CLOSING;
}
{
struct TALER_TESTING_Command cmd = {
diff --git a/src/testing/testing_api_cmd_exec_transfer.c b/src/testing/testing_api_cmd_exec_transfer.c
index f8af443bd..300413b4b 100644
--- a/src/testing/testing_api_cmd_exec_transfer.c
+++ b/src/testing/testing_api_cmd_exec_transfer.c
@@ -67,7 +67,6 @@ transfer_run (void *cls,
"taler-exchange-transfer",
"taler-exchange-transfer",
"-c", as->config_filename,
- "-L", "INFO",
"-S", "1",
"-w", "0",
"-t", /* exit when done */
diff --git a/src/testing/testing_api_cmd_exec_wget.c b/src/testing/testing_api_cmd_exec_wget.c
new file mode 100644
index 000000000..67aceca0a
--- /dev/null
+++ b/src/testing/testing_api_cmd_exec_wget.c
@@ -0,0 +1,158 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3,
+ or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_exec_wget.c
+ * @brief run a wget command
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_signatures.h"
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "wget" CMD.
+ */
+struct WgetState
+{
+ /**
+ * Process for the wgeter.
+ */
+ struct GNUNET_OS_Process *wget_proc;
+
+ /**
+ * URL to used by the wget.
+ */
+ const char *url;
+};
+
+
+/**
+ * Run the command; use the `wget' program.
+ *
+ * @param cls closure.
+ * @param cmd command currently being executed.
+ * @param is interpreter state.
+ */
+static void
+wget_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct WgetState *ws = cls;
+
+ (void) cmd;
+ ws->wget_proc
+ = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
+ NULL, NULL, NULL,
+ "wget",
+ "wget",
+ ws->url,
+ NULL);
+ if (NULL == ws->wget_proc)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ TALER_TESTING_wait_for_sigchld (is);
+}
+
+
+/**
+ * Free the state of a "wget" CMD, and possibly
+ * kills its process if it did not terminate regularly.
+ *
+ * @param cls closure.
+ * @param cmd the command being freed.
+ */
+static void
+wget_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct WgetState *ws = cls;
+
+ (void) cmd;
+ if (NULL != ws->wget_proc)
+ {
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (ws->wget_proc,
+ SIGKILL));
+ GNUNET_OS_process_wait (ws->wget_proc);
+ GNUNET_OS_process_destroy (ws->wget_proc);
+ ws->wget_proc = NULL;
+ }
+ GNUNET_free (ws);
+}
+
+
+/**
+ * Offer "wget" CMD internal data to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+wget_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct WgetState *ws = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_process (&ws->wget_proc),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_wget (const char *label,
+ const char *url)
+{
+ struct WgetState *ws;
+
+ ws = GNUNET_new (struct WgetState);
+ ws->url = url;
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ws,
+ .label = label,
+ .run = &wget_run,
+ .cleanup = &wget_cleanup,
+ .traits = &wget_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_exec_wget.c */
diff --git a/src/testing/testing_api_cmd_exec_wirewatch.c b/src/testing/testing_api_cmd_exec_wirewatch.c
index cd31688d5..b6ed4f0f1 100644
--- a/src/testing/testing_api_cmd_exec_wirewatch.c
+++ b/src/testing/testing_api_cmd_exec_wirewatch.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
+ Copyright (C) 2018, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -34,7 +34,6 @@
*/
struct WirewatchState
{
-
/**
* Process for the wirewatcher.
*/
@@ -44,6 +43,11 @@ struct WirewatchState
* Configuration file used by the wirewatcher.
*/
const char *config_filename;
+
+ /**
+ * Account section to be used by the wirewatcher.
+ */
+ const char *account_section;
};
@@ -71,6 +75,10 @@ wirewatch_run (void *cls,
"-S", "1",
"-w", "0",
"-t", /* exit when done */
+ (NULL == ws->account_section)
+ ? NULL
+ : "-a",
+ ws->account_section,
NULL);
if (NULL == ws->wirewatch_proc)
{
@@ -138,14 +146,15 @@ wirewatch_traits (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_exec_wirewatch (const char *label,
- const char *config_filename)
+TALER_TESTING_cmd_exec_wirewatch2 (const char *label,
+ const char *config_filename,
+ const char *account_section)
{
struct WirewatchState *ws;
ws = GNUNET_new (struct WirewatchState);
ws->config_filename = config_filename;
-
+ ws->account_section = account_section;
{
struct TALER_TESTING_Command cmd = {
.cls = ws,
@@ -160,4 +169,14 @@ TALER_TESTING_cmd_exec_wirewatch (const char *label,
}
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_exec_wirewatch (const char *label,
+ const char *config_filename)
+{
+ return TALER_TESTING_cmd_exec_wirewatch2 (label,
+ config_filename,
+ NULL);
+}
+
+
/* end of testing_api_cmd_exec_wirewatch.c */
diff --git a/src/testing/testing_api_cmd_get_auditor.c b/src/testing/testing_api_cmd_get_auditor.c
new file mode 100644
index 000000000..ab4e32665
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_auditor.c
@@ -0,0 +1,286 @@
+/*
+ This file is part of TALER
+ (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_get_auditor.c
+ * @brief Command to get an auditor handle
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "get auditor" CMD.
+ */
+struct GetAuditorState
+{
+
+ /**
+ * Private key of the auditor.
+ */
+ struct TALER_AuditorPrivateKeyP auditor_priv;
+
+ /**
+ * Public key of the auditor.
+ */
+ struct TALER_AuditorPublicKeyP auditor_pub;
+
+ /**
+ * Our interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Auditor handle used to get the configuration.
+ */
+ struct TALER_AUDITOR_GetConfigHandle *auditor;
+
+ /**
+ * URL of the auditor.
+ */
+ char *auditor_url;
+
+ /**
+ * Filename of the master private key of the auditor.
+ */
+ char *priv_file;
+
+};
+
+
+/**
+ * Function called with information about the auditor.
+ *
+ * @param cls closure
+ * @param vr response data
+ */
+static void
+version_cb (
+ void *cls,
+ const struct TALER_AUDITOR_ConfigResponse *vr)
+{
+ struct GetAuditorState *gas = cls;
+
+ gas->auditor = NULL;
+ if (MHD_HTTP_OK != vr->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (gas->is,
+ vr->hr.http_status,
+ MHD_HTTP_OK);
+ return;
+ }
+ if ( (NULL != gas->priv_file) &&
+ (0 != GNUNET_memcmp (&gas->auditor_pub,
+ &vr->details.ok.vi.auditor_pub)) )
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (gas->is);
+ return;
+ }
+ TALER_TESTING_interpreter_next (gas->is);
+}
+
+
+/**
+ * Run the "get_auditor" command.
+ *
+ * @param cls closure.
+ * @param cmd the command currently being executed.
+ * @param is the interpreter state.
+ */
+static void
+get_auditor_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetAuditorState *gas = cls;
+
+ (void) cmd;
+ if (NULL == gas->auditor_url)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (NULL != gas->priv_file)
+ {
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (gas->priv_file,
+ GNUNET_YES,
+ &gas->auditor_priv.eddsa_priv))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&gas->auditor_priv.eddsa_priv,
+ &gas->auditor_pub.eddsa_pub);
+ }
+ gas->is = is;
+ gas->auditor
+ = TALER_AUDITOR_get_config (TALER_TESTING_interpreter_get_context (is),
+ gas->auditor_url,
+ &version_cb,
+ gas);
+ if (NULL == gas->auditor)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Cleanup the state.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+get_auditor_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetAuditorState *gas = cls;
+
+ if (NULL != gas->auditor)
+ {
+ GNUNET_break (0);
+ TALER_AUDITOR_get_config_cancel (gas->auditor);
+ gas->auditor = NULL;
+ }
+ GNUNET_free (gas->priv_file);
+ GNUNET_free (gas->auditor_url);
+ GNUNET_free (gas);
+}
+
+
+/**
+ * Offer internal data to a "get_auditor" CMD state to other commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+get_auditor_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct GetAuditorState *gas = cls;
+ unsigned int off = (NULL == gas->priv_file) ? 2 : 0;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_auditor_priv (&gas->auditor_priv),
+ TALER_TESTING_make_trait_auditor_pub (&gas->auditor_pub),
+ TALER_TESTING_make_trait_auditor_url (gas->auditor_url),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (&traits[off],
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Get the base URL of the auditor from @a cfg.
+ *
+ * @param cfg configuration to evaluate
+ * @return base URL of the auditor according to @a cfg
+ */
+static char *
+get_auditor_base_url (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *auditor_url;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "auditor",
+ "BASE_URL",
+ &auditor_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "auditor",
+ "BASE_URL");
+ return NULL;
+ }
+ return auditor_url;
+}
+
+
+/**
+ * Get the file name of the master private key file of the auditor from @a
+ * cfg.
+ *
+ * @param cfg configuration to evaluate
+ * @return base URL of the auditor according to @a cfg
+ */
+static char *
+get_auditor_priv_file (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *fn;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "auditor",
+ "AUDITOR_PRIV_FILE",
+ &fn))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "auditor",
+ "AUDITOR_PRIV_FILE");
+ return NULL;
+ }
+ return fn;
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_auditor (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool load_auditor_keys)
+{
+ struct GetAuditorState *gas;
+
+ gas = GNUNET_new (struct GetAuditorState);
+ gas->auditor_url = get_auditor_base_url (cfg);
+ if (load_auditor_keys)
+ gas->priv_file = get_auditor_priv_file (cfg);
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = gas,
+ .label = label,
+ .run = &get_auditor_run,
+ .cleanup = &get_auditor_cleanup,
+ .traits = &get_auditor_traits,
+ .name = "auditor"
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_get_exchange.c b/src/testing/testing_api_cmd_get_exchange.c
new file mode 100644
index 000000000..69a6e82b0
--- /dev/null
+++ b/src/testing/testing_api_cmd_get_exchange.c
@@ -0,0 +1,411 @@
+/*
+ This file is part of TALER
+ (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_get_exchange.c
+ * @brief Command to get an exchange handle
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "get exchange" CMD.
+ */
+struct GetExchangeState
+{
+
+ /**
+ * Master private key of the exchange.
+ */
+ struct TALER_MasterPrivateKeyP master_priv;
+
+ /**
+ * Our interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Exchange handle we produced.
+ */
+ struct TALER_EXCHANGE_GetKeysHandle *exchange;
+
+ /**
+ * Keys of the exchange.
+ */
+ struct TALER_EXCHANGE_Keys *keys;
+
+ /**
+ * URL of the exchange.
+ */
+ char *exchange_url;
+
+ /**
+ * Filename of the master private key of the exchange.
+ */
+ char *master_priv_file;
+
+ /**
+ * Label of a command to use to obtain existing
+ * keys.
+ */
+ const char *last_keys_ref;
+
+ /**
+ * Last denomination date we received when doing this request.
+ */
+ struct GNUNET_TIME_Timestamp my_denom_date;
+
+ /**
+ * Are we waiting for /keys before continuing?
+ */
+ bool wait_for_keys;
+};
+
+
+/**
+ * Function called with information about who is auditing
+ * a particular exchange and what keys the exchange is using.
+ *
+ * @param cls closure
+ * @param kr response from /keys
+ * @param[in] keys the keys of the exchange
+ */
+static void
+cert_cb (void *cls,
+ const struct TALER_EXCHANGE_KeysResponse *kr,
+ struct TALER_EXCHANGE_Keys *keys)
+{
+ struct GetExchangeState *ges = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &kr->hr;
+ struct TALER_TESTING_Interpreter *is = ges->is;
+
+ ges->exchange = NULL;
+ ges->keys = keys;
+ switch (hr->http_status)
+ {
+ case MHD_HTTP_OK:
+ if (ges->wait_for_keys)
+ {
+ ges->wait_for_keys = false;
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ ges->my_denom_date = kr->details.ok.keys->last_denom_issue_date;
+ return;
+ default:
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "/keys responded with HTTP status %u\n",
+ hr->http_status);
+ if (ges->wait_for_keys)
+ {
+ ges->wait_for_keys = false;
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ return;
+ }
+}
+
+
+/**
+ * Run the "get_exchange" command.
+ *
+ * @param cls closure.
+ * @param cmd the command currently being executed.
+ * @param is the interpreter state.
+ */
+static void
+get_exchange_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetExchangeState *ges = cls;
+ struct TALER_EXCHANGE_Keys *xkeys = NULL;
+
+ (void) cmd;
+ if (NULL == ges->exchange_url)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (NULL != ges->last_keys_ref)
+ {
+ const struct TALER_TESTING_Command *state_cmd;
+ struct TALER_EXCHANGE_Keys *old_keys;
+ const char *exchange_url;
+ json_t *s_keys;
+
+ state_cmd
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ges->last_keys_ref);
+ if (NULL == state_cmd)
+ {
+ /* Command providing serialized keys not found. */
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_keys (state_cmd,
+ &old_keys))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (NULL == old_keys)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_exchange_url (state_cmd,
+ &exchange_url))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (0 != strcmp (exchange_url,
+ ges->exchange_url))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ s_keys = TALER_EXCHANGE_keys_to_json (old_keys);
+ if (NULL == s_keys)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ xkeys = TALER_EXCHANGE_keys_from_json (s_keys);
+ if (NULL == xkeys)
+ {
+ GNUNET_break (0);
+ json_dumpf (s_keys,
+ stderr,
+ JSON_INDENT (2));
+ json_decref (s_keys);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ json_decref (s_keys);
+ }
+ if (NULL != ges->master_priv_file)
+ {
+ if (GNUNET_SYSERR ==
+ GNUNET_CRYPTO_eddsa_key_from_file (ges->master_priv_file,
+ GNUNET_YES,
+ &ges->master_priv.eddsa_priv))
+ {
+ GNUNET_break (0);
+ TALER_EXCHANGE_keys_decref (xkeys);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ ges->is = is;
+ ges->exchange
+ = TALER_EXCHANGE_get_keys (TALER_TESTING_interpreter_get_context (is),
+ ges->exchange_url,
+ xkeys,
+ &cert_cb,
+ ges);
+ TALER_EXCHANGE_keys_decref (xkeys);
+ if (NULL == ges->exchange)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (! ges->wait_for_keys)
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Cleanup the state.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+get_exchange_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetExchangeState *ges = cls;
+
+ if (NULL != ges->exchange)
+ {
+ TALER_EXCHANGE_get_keys_cancel (ges->exchange);
+ ges->exchange = NULL;
+ }
+ TALER_EXCHANGE_keys_decref (ges->keys);
+ ges->keys = NULL;
+ GNUNET_free (ges->master_priv_file);
+ GNUNET_free (ges->exchange_url);
+ GNUNET_free (ges);
+}
+
+
+/**
+ * Offer internal data to a "get_exchange" CMD state to other commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+get_exchange_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct GetExchangeState *ges = cls;
+ unsigned int off = (NULL == ges->master_priv_file) ? 1 : 0;
+
+ if (NULL != ges->keys)
+ {
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_master_priv (&ges->master_priv),
+ TALER_TESTING_make_trait_master_pub (&ges->keys->master_pub),
+ TALER_TESTING_make_trait_keys (ges->keys),
+ TALER_TESTING_make_trait_exchange_url (ges->exchange_url),
+ TALER_TESTING_make_trait_timestamp (0,
+ &ges->my_denom_date),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (&traits[off],
+ ret,
+ trait,
+ index);
+ }
+ else
+ {
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_master_priv (&ges->master_priv),
+ TALER_TESTING_make_trait_exchange_url (ges->exchange_url),
+ TALER_TESTING_make_trait_timestamp (0,
+ &ges->my_denom_date),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (&traits[off],
+ ret,
+ trait,
+ index);
+ }
+}
+
+
+/**
+ * Get the base URL of the exchange from @a cfg.
+ *
+ * @param cfg configuration to evaluate
+ * @return base URL of the exchange according to @a cfg
+ */
+static char *
+get_exchange_base_url (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *exchange_url;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "exchange",
+ "BASE_URL",
+ &exchange_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return NULL;
+ }
+ return exchange_url;
+}
+
+
+/**
+ * Get the file name of the master private key file of the exchange from @a
+ * cfg.
+ *
+ * @param cfg configuration to evaluate
+ * @return base URL of the exchange according to @a cfg
+ */
+static char *
+get_exchange_master_priv_file (
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *fn;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "exchange-offline",
+ "MASTER_PRIV_FILE",
+ &fn))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange-offline",
+ "MASTER_PRIV_FILE");
+ return NULL;
+ }
+ return fn;
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_get_exchange (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *last_keys_ref,
+ bool wait_for_keys,
+ bool load_private_key)
+{
+ struct GetExchangeState *ges;
+
+ ges = GNUNET_new (struct GetExchangeState);
+ ges->exchange_url = get_exchange_base_url (cfg);
+ ges->last_keys_ref = last_keys_ref;
+ if (load_private_key)
+ ges->master_priv_file = get_exchange_master_priv_file (cfg);
+ ges->wait_for_keys = wait_for_keys;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ges,
+ .label = label,
+ .run = &get_exchange_run,
+ .cleanup = &get_exchange_cleanup,
+ .traits = &get_exchange_traits,
+ .name = "exchange"
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_insert_deposit.c b/src/testing/testing_api_cmd_insert_deposit.c
index 032ff72dc..03e704c72 100644
--- a/src/testing/testing_api_cmd_insert_deposit.c
+++ b/src/testing/testing_api_cmd_insert_deposit.c
@@ -29,6 +29,7 @@
#include "taler_signatures.h"
#include "taler_testing_lib.h"
#include "taler_exchangedb_plugin.h"
+#include "taler_exchangedb_lib.h"
/**
@@ -37,9 +38,9 @@
struct InsertDepositState
{
/**
- * Configuration file used by the command.
+ * Database connection we use.
*/
- const struct TALER_TESTING_DatabaseConnection *dbc;
+ struct TALER_EXCHANGEDB_Plugin *plugin;
/**
* Human-readable name of the shop.
@@ -71,6 +72,11 @@ struct InsertDepositState
* Deposit fee.
*/
const char *deposit_fee;
+
+ /**
+ * Do we used a cached @e plugin?
+ */
+ bool cached;
};
/**
@@ -126,32 +132,46 @@ insert_deposit_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct InsertDepositState *ids = cls;
- struct TALER_EXCHANGEDB_Deposit deposit;
+ struct TALER_EXCHANGEDB_CoinDepositInformation deposit;
+ struct TALER_EXCHANGEDB_BatchDeposit bd;
struct TALER_MerchantPrivateKeyP merchant_priv;
struct TALER_EXCHANGEDB_DenominationKeyInformation issue;
struct TALER_DenominationPublicKey dpk;
struct TALER_DenominationPrivateKey denom_priv;
+ char *receiver_wire_account;
(void) cmd;
- // prepare and store issue first.
+ if (NULL == ids->plugin)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ ids->plugin->preflight (ids->plugin->cls))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
fake_issue (&issue);
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&denom_priv,
&dpk,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
TALER_denom_pub_hash (&dpk,
&issue.denom_hash);
if ( (GNUNET_OK !=
- ids->dbc->plugin->start (ids->dbc->plugin->cls,
- "talertestinglib: denomination insertion")) ||
+ ids->plugin->start (ids->plugin->cls,
+ "talertestinglib: denomination insertion")) ||
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- ids->dbc->plugin->insert_denomination_info (ids->dbc->plugin->cls,
- &dpk,
- &issue)) ||
+ ids->plugin->insert_denomination_info (ids->plugin->cls,
+ &dpk,
+ &issue)) ||
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
- ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
+ ids->plugin->commit (ids->plugin->cls)) )
{
TALER_TESTING_interpreter_fail (is);
TALER_denom_pub_free (&dpk);
@@ -163,6 +183,11 @@ insert_deposit_run (void *cls,
memset (&deposit,
0,
sizeof (deposit));
+ memset (&bd,
+ 0,
+ sizeof (bd));
+ bd.cdis = &deposit;
+ bd.num_cdis = 1;
GNUNET_assert (
GNUNET_YES ==
@@ -175,15 +200,12 @@ insert_deposit_run (void *cls,
NULL,
0));
GNUNET_CRYPTO_eddsa_key_get_public (&merchant_priv.eddsa_priv,
- &deposit.merchant_pub.eddsa_pub);
+ &bd.merchant_pub.eddsa_pub);
GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
- &deposit.h_contract_terms.hash);
- if ( (GNUNET_OK !=
- TALER_string_to_amount (ids->amount_with_fee,
- &deposit.amount_with_fee)) ||
- (GNUNET_OK !=
- TALER_string_to_amount (ids->deposit_fee,
- &deposit.deposit_fee)) )
+ &bd.h_contract_terms.hash);
+ if (GNUNET_OK !=
+ TALER_string_to_amount (ids->amount_with_fee,
+ &deposit.amount_with_fee))
{
TALER_TESTING_interpreter_fail (is);
TALER_denom_pub_free (&dpk);
@@ -201,19 +223,20 @@ insert_deposit_run (void *cls,
struct TALER_PlanchetDetail pd;
struct TALER_BlindedDenominationSignature bds;
struct TALER_PlanchetMasterSecretP ps;
- struct TALER_ExchangeWithdrawValues alg_values;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ const struct TALER_ExchangeWithdrawValues *alg_values;
- alg_values.cipher = TALER_DENOMINATION_RSA;
+ alg_values = TALER_denom_ewv_rsa_singleton ();
TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
+ alg_values,
&bks);
GNUNET_assert (GNUNET_OK ==
TALER_denom_blind (&dpk,
&bks,
NULL, /* no age restriction active */
+ NULL, /* no nonce needed */
&deposit.coin.coin_pub,
- &alg_values,
+ alg_values,
&c_hash,
&pd.blinded_planchet));
GNUNET_assert (GNUNET_OK ==
@@ -227,45 +250,54 @@ insert_deposit_run (void *cls,
&bds,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&dpk));
TALER_blinded_denom_sig_free (&bds);
}
- GNUNET_asprintf (&deposit.receiver_wire_account,
+ GNUNET_asprintf (&receiver_wire_account,
"payto://x-taler-bank/localhost/%s?receiver-name=%s",
ids->merchant_account,
ids->merchant_account);
- memset (&deposit.wire_salt,
+ bd.receiver_wire_account = receiver_wire_account;
+ TALER_payto_hash (bd.receiver_wire_account,
+ &bd.wire_target_h_payto);
+ memset (&bd.wire_salt,
46,
- sizeof (deposit.wire_salt));
- deposit.timestamp = GNUNET_TIME_timestamp_get ();
- deposit.wire_deadline = GNUNET_TIME_relative_to_timestamp (
+ sizeof (bd.wire_salt));
+ bd.wallet_timestamp = GNUNET_TIME_timestamp_get ();
+ bd.wire_deadline = GNUNET_TIME_relative_to_timestamp (
ids->wire_deadline);
/* finally, actually perform the DB operation */
{
uint64_t known_coin_id;
struct TALER_DenominationHashP dph;
struct TALER_AgeCommitmentHash agh;
+ bool balance_ok;
+ uint32_t bad_index;
+ bool ctr_conflict;
if ( (GNUNET_OK !=
- ids->dbc->plugin->start (ids->dbc->plugin->cls,
- "libtalertesting: insert deposit")) ||
+ ids->plugin->start (ids->plugin->cls,
+ "libtalertesting: insert deposit")) ||
(0 >
- ids->dbc->plugin->ensure_coin_known (ids->dbc->plugin->cls,
- &deposit.coin,
- &known_coin_id,
- &dph,
- &agh)) ||
+ ids->plugin->ensure_coin_known (ids->plugin->cls,
+ &deposit.coin,
+ &known_coin_id,
+ &dph,
+ &agh)) ||
(GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
- ids->dbc->plugin->insert_deposit (ids->dbc->plugin->cls,
- ids->exchange_timestamp,
- &deposit)) ||
+ ids->plugin->do_deposit (ids->plugin->cls,
+ &bd,
+ &ids->exchange_timestamp,
+ &balance_ok,
+ &bad_index,
+ &ctr_conflict)) ||
(GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
- ids->dbc->plugin->commit (ids->dbc->plugin->cls)) )
+ ids->plugin->commit (ids->plugin->cls)) )
{
GNUNET_break (0);
- ids->dbc->plugin->rollback (ids->dbc->plugin->cls);
- GNUNET_free (deposit.receiver_wire_account);
+ ids->plugin->rollback (ids->plugin->cls);
+ GNUNET_free (receiver_wire_account);
TALER_denom_pub_free (&dpk);
TALER_denom_priv_free (&denom_priv);
TALER_TESTING_interpreter_fail (is);
@@ -276,7 +308,7 @@ insert_deposit_run (void *cls,
TALER_denom_sig_free (&deposit.coin.denom_sig);
TALER_denom_pub_free (&dpk);
TALER_denom_priv_free (&denom_priv);
- GNUNET_free (deposit.receiver_wire_account);
+ GNUNET_free (receiver_wire_account);
TALER_TESTING_interpreter_next (is);
}
@@ -295,6 +327,14 @@ insert_deposit_cleanup (void *cls,
struct InsertDepositState *ids = cls;
(void) cmd;
+ if ( (NULL != ids->plugin) &&
+ (! ids->cached) )
+ {
+ // FIXME: historically, we also did:
+ // ids->plugin->drop_tables (ids->plugin->cls);
+ TALER_EXCHANGEDB_plugin_unload (ids->plugin);
+ ids->plugin = NULL;
+ }
GNUNET_free (ids);
}
@@ -302,7 +342,7 @@ insert_deposit_cleanup (void *cls,
struct TALER_TESTING_Command
TALER_TESTING_cmd_insert_deposit (
const char *label,
- const struct TALER_TESTING_DatabaseConnection *dbc,
+ const struct GNUNET_CONFIGURATION_Handle *db_cfg,
const char *merchant_name,
const char *merchant_account,
struct GNUNET_TIME_Timestamp exchange_timestamp,
@@ -310,10 +350,22 @@ TALER_TESTING_cmd_insert_deposit (
const char *amount_with_fee,
const char *deposit_fee)
{
+ static struct TALER_EXCHANGEDB_Plugin *pluginc;
+ static const struct GNUNET_CONFIGURATION_Handle *db_cfgc;
struct InsertDepositState *ids;
ids = GNUNET_new (struct InsertDepositState);
- ids->dbc = dbc;
+ if (db_cfgc == db_cfg)
+ {
+ ids->plugin = pluginc;
+ ids->cached = true;
+ }
+ else
+ {
+ ids->plugin = TALER_EXCHANGEDB_plugin_load (db_cfg);
+ pluginc = ids->plugin;
+ db_cfgc = db_cfg;
+ }
ids->merchant_name = merchant_name;
ids->merchant_account = merchant_account;
ids->exchange_timestamp = exchange_timestamp;
diff --git a/src/testing/testing_api_cmd_kyc_check_get.c b/src/testing/testing_api_cmd_kyc_check_get.c
index 03b2321d1..25c7e98b8 100644
--- a/src/testing/testing_api_cmd_kyc_check_get.c
+++ b/src/testing/testing_api_cmd_kyc_check_get.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -73,19 +73,13 @@ check_kyc_cb (void *cls,
{
struct KycCheckGetState *kcg = cls;
struct TALER_TESTING_Interpreter *is = kcg->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
kcg->kwh = NULL;
if (kcg->expected_response_code != ks->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- ks->http_status,
- (int) ks->ec,
- cmd->label,
- __FILE__,
- __LINE__);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ ks->http_status,
+ kcg->expected_response_code);
return;
}
switch (ks->http_status)
@@ -93,7 +87,7 @@ check_kyc_cb (void *cls,
case MHD_HTTP_OK:
break;
case MHD_HTTP_ACCEPTED:
- kcg->kyc_url = GNUNET_strdup (ks->details.kyc_url);
+ kcg->kyc_url = GNUNET_strdup (ks->details.accepted.kyc_url);
break;
case MHD_HTTP_NO_CONTENT:
break;
@@ -119,15 +113,14 @@ check_kyc_run (void *cls,
{
struct KycCheckGetState *kcg = cls;
const struct TALER_TESTING_Command *res_cmd;
- const char **payto_uri;
- const uint64_t *payment_target;
- struct TALER_PaytoHashP h_payto;
+ const uint64_t *requirement_row;
+ const struct TALER_PaytoHashP *h_payto;
(void) cmd;
kcg->is = is;
- res_cmd = TALER_TESTING_interpreter_lookup_command (kcg->is,
- kcg->
- payment_target_reference);
+ res_cmd = TALER_TESTING_interpreter_lookup_command (
+ kcg->is,
+ kcg->payment_target_reference);
if (NULL == res_cmd)
{
GNUNET_break (0);
@@ -135,39 +128,37 @@ check_kyc_run (void *cls,
return;
}
if (GNUNET_OK !=
- TALER_TESTING_get_trait_payto_uri (res_cmd,
- &payto_uri))
+ TALER_TESTING_get_trait_legi_requirement_row (res_cmd,
+ &requirement_row))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (kcg->is);
return;
}
if (GNUNET_OK !=
- TALER_TESTING_get_trait_payment_target_uuid (res_cmd,
- &payment_target))
+ TALER_TESTING_get_trait_h_payto (res_cmd,
+ &h_payto))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (kcg->is);
return;
}
- if ( (NULL == *payto_uri) ||
- (0 == *payment_target) )
+ if (0 == *requirement_row)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (kcg->is);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Running KYC check for payto URI: %s\n",
- *payto_uri);
- TALER_payto_hash (*payto_uri,
- &h_payto);
- kcg->kwh = TALER_EXCHANGE_kyc_check (is->exchange,
- *payment_target,
- &h_payto,
- GNUNET_TIME_UNIT_SECONDS,
- &check_kyc_cb,
- kcg);
+ kcg->kwh = TALER_EXCHANGE_kyc_check (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ *requirement_row,
+ h_payto,
+ TALER_KYCLOGIC_KYC_UT_INDIVIDUAL,
+ GNUNET_TIME_UNIT_SECONDS,
+ &check_kyc_cb,
+ kcg);
GNUNET_assert (NULL != kcg->kwh);
}
@@ -187,10 +178,8 @@ check_kyc_cleanup (void *cls,
if (NULL != kcg->kwh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- kcg->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (kcg->is,
+ cmd->label);
TALER_EXCHANGE_kyc_check_cancel (kcg->kwh);
kcg->kwh = NULL;
}
@@ -216,8 +205,7 @@ check_kyc_traits (void *cls,
{
struct KycCheckGetState *kcg = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_kyc_url (
- (const char **) &kcg->kyc_url),
+ TALER_TESTING_make_trait_kyc_url (kcg->kyc_url),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_kyc_proof.c b/src/testing/testing_api_cmd_kyc_proof.c
index f9a65afb3..b079fffce 100644
--- a/src/testing/testing_api_cmd_kyc_proof.c
+++ b/src/testing/testing_api_cmd_kyc_proof.c
@@ -44,9 +44,9 @@ struct KycProofGetState
const char *code;
/**
- * State to pass.
+ * Logic section name to pass to `/kyc-proof/` handler.
*/
- const char *state;
+ const char *logic;
/**
* Expected HTTP response code.
@@ -83,18 +83,13 @@ proof_kyc_cb (void *cls,
{
struct KycProofGetState *kcg = cls;
struct TALER_TESTING_Interpreter *is = kcg->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
kcg->kph = NULL;
if (kcg->expected_response_code != kpr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- kpr->http_status,
- cmd->label,
- __FILE__,
- __LINE__);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ kpr->http_status,
+ kcg->expected_response_code);
return;
}
switch (kpr->http_status)
@@ -131,11 +126,18 @@ proof_kyc_run (void *cls,
{
struct KycProofGetState *kps = cls;
const struct TALER_TESTING_Command *res_cmd;
- const char **payto_uri;
- struct TALER_PaytoHashP h_payto;
+ const struct TALER_PaytoHashP *h_payto;
+ char *uargs;
+ const char *exchange_url;
(void) cmd;
kps->is = is;
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
res_cmd = TALER_TESTING_interpreter_lookup_command (
kps->is,
kps->payment_target_reference);
@@ -146,35 +148,28 @@ proof_kyc_run (void *cls,
return;
}
if (GNUNET_OK !=
- TALER_TESTING_get_trait_payto_uri (res_cmd,
- &payto_uri))
+ TALER_TESTING_get_trait_h_payto (res_cmd,
+ &h_payto))
{
- const struct TALER_PaytoHashP *hpt;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_h_payto (res_cmd,
- &hpt))
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (kps->is);
- return;
- }
- h_payto = *hpt;
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (kps->is);
+ return;
}
+ if (NULL == kps->code)
+ uargs = NULL;
else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Triggering KYC proof for %s\n",
- *payto_uri);
- TALER_payto_hash (*payto_uri,
- &h_payto);
- }
- kps->kph = TALER_EXCHANGE_kyc_proof (is->exchange,
- &h_payto,
- kps->code,
- kps->state,
- &proof_kyc_cb,
- kps);
+ GNUNET_asprintf (&uargs,
+ "&code=%s",
+ kps->code);
+ kps->kph = TALER_EXCHANGE_kyc_proof (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ h_payto,
+ kps->logic,
+ uargs,
+ &proof_kyc_cb,
+ kps);
+ GNUNET_free (uargs);
GNUNET_assert (NULL != kps->kph);
}
@@ -194,10 +189,8 @@ proof_kyc_cleanup (void *cls,
if (NULL != kps->kph)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- kps->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (kps->is,
+ cmd->label);
TALER_EXCHANGE_kyc_proof_cancel (kps->kph);
kps->kph = NULL;
}
@@ -223,8 +216,7 @@ proof_kyc_traits (void *cls,
{
struct KycProofGetState *kps = cls;
struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_web_url (
- (const char **) &kps->redirect_url),
+ TALER_TESTING_make_trait_web_url (kps->redirect_url),
TALER_TESTING_trait_end ()
};
@@ -236,17 +228,18 @@ proof_kyc_traits (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_proof_kyc (const char *label,
- const char *payment_target_reference,
- const char *code,
- const char *state,
- unsigned int expected_response_code)
+TALER_TESTING_cmd_proof_kyc_oauth2 (
+ const char *label,
+ const char *payment_target_reference,
+ const char *logic_section,
+ const char *code,
+ unsigned int expected_response_code)
{
struct KycProofGetState *kps;
kps = GNUNET_new (struct KycProofGetState);
kps->code = code;
- kps->state = state;
+ kps->logic = logic_section;
kps->payment_target_reference = payment_target_reference;
kps->expected_response_code = expected_response_code;
{
diff --git a/src/testing/testing_api_cmd_kyc_wallet_get.c b/src/testing/testing_api_cmd_kyc_wallet_get.c
index 91ad09ff9..ffb143ffb 100644
--- a/src/testing/testing_api_cmd_kyc_wallet_get.c
+++ b/src/testing/testing_api_cmd_kyc_wallet_get.c
@@ -49,6 +49,11 @@ struct KycWalletGetState
char *reserve_payto_uri;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Command to get a reserve private key from.
*/
const char *reserve_reference;
@@ -59,10 +64,16 @@ struct KycWalletGetState
unsigned int expected_response_code;
/**
- * Set to the KYC UUID *if* the exchange replied with
- * a request for KYC (#MHD_HTTP_ACCEPTED).
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC (#MHD_HTTP_OK).
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
+ * a request for KYC (#MHD_HTTP_OK).
*/
- uint64_t kyc_uuid;
+ uint64_t requirement_row;
/**
* Handle to the "track transaction" pending operation.
@@ -70,6 +81,11 @@ struct KycWalletGetState
struct TALER_EXCHANGE_KycWalletHandle *kwh;
/**
+ * Balance to pass to the exchange.
+ */
+ struct TALER_Amount balance;
+
+ /**
* Interpreter state.
*/
struct TALER_TESTING_Interpreter *is;
@@ -88,33 +104,29 @@ wallet_kyc_cb (void *cls,
{
struct KycWalletGetState *kwg = cls;
struct TALER_TESTING_Interpreter *is = kwg->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
kwg->kwh = NULL;
if (kwg->expected_response_code != wkr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d (wanted %u) to command %s in %s:%u\n",
- wkr->http_status,
- (int) wkr->ec,
- kwg->expected_response_code,
- cmd->label,
- __FILE__,
- __LINE__);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ wkr->http_status,
+ kwg->expected_response_code);
return;
}
switch (wkr->http_status)
{
- case MHD_HTTP_OK:
- kwg->kyc_uuid = wkr->payment_target_uuid;
- break;
case MHD_HTTP_NO_CONTENT:
break;
case MHD_HTTP_FORBIDDEN:
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ kwg->requirement_row
+ = wkr->details.unavailable_for_legal_reasons.requirement_row;
+ kwg->h_payto
+ = wkr->details.unavailable_for_legal_reasons.h_payto;
+ break;
default:
GNUNET_break (0);
break;
@@ -136,9 +148,16 @@ wallet_kyc_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct KycWalletGetState *kwg = cls;
+ const char *exchange_url;
- (void) cmd;
+ kwg->cmd = cmd;
kwg->is = is;
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
if (NULL != kwg->reserve_reference)
{
const struct TALER_TESTING_Command *res_cmd;
@@ -170,12 +189,15 @@ wallet_kyc_run (void *cls,
GNUNET_CRYPTO_eddsa_key_get_public (&kwg->reserve_priv.eddsa_priv,
&kwg->reserve_pub.eddsa_pub);
kwg->reserve_payto_uri
- = TALER_payto_from_reserve (TALER_EXCHANGE_get_base_url (is->exchange),
+ = TALER_reserve_make_payto (exchange_url,
&kwg->reserve_pub);
- kwg->kwh = TALER_EXCHANGE_kyc_wallet (is->exchange,
- &kwg->reserve_priv,
- &wallet_kyc_cb,
- kwg);
+ kwg->kwh = TALER_EXCHANGE_kyc_wallet (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ &kwg->reserve_priv,
+ &kwg->balance,
+ &wallet_kyc_cb,
+ kwg);
GNUNET_assert (NULL != kwg->kwh);
}
@@ -195,10 +217,8 @@ wallet_kyc_cleanup (void *cls,
if (NULL != kwg->kwh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- kwg->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (kwg->is,
+ cmd->label);
TALER_EXCHANGE_kyc_wallet_cancel (kwg->kwh);
kwg->kwh = NULL;
}
@@ -226,9 +246,9 @@ wallet_kyc_traits (void *cls,
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_reserve_priv (&kwg->reserve_priv),
TALER_TESTING_make_trait_reserve_pub (&kwg->reserve_pub),
- TALER_TESTING_make_trait_payment_target_uuid (&kwg->kyc_uuid),
- TALER_TESTING_make_trait_payto_uri (
- (const char **) &kwg->reserve_payto_uri),
+ TALER_TESTING_make_trait_legi_requirement_row (&kwg->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&kwg->h_payto),
+ TALER_TESTING_make_trait_payto_uri (kwg->reserve_payto_uri),
TALER_TESTING_trait_end ()
};
@@ -242,6 +262,7 @@ wallet_kyc_traits (void *cls,
struct TALER_TESTING_Command
TALER_TESTING_cmd_wallet_kyc_get (const char *label,
const char *reserve_reference,
+ const char *threshold_balance,
unsigned int expected_response_code)
{
struct KycWalletGetState *kwg;
@@ -249,6 +270,9 @@ TALER_TESTING_cmd_wallet_kyc_get (const char *label,
kwg = GNUNET_new (struct KycWalletGetState);
kwg->reserve_reference = reserve_reference;
kwg->expected_response_code = expected_response_code;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (threshold_balance,
+ &kwg->balance));
{
struct TALER_TESTING_Command cmd = {
.cls = kwg,
diff --git a/src/testing/testing_api_cmd_oauth.c b/src/testing/testing_api_cmd_oauth.c
index 045b5eefa..80d38e4c8 100644
--- a/src/testing/testing_api_cmd_oauth.c
+++ b/src/testing/testing_api_cmd_oauth.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -40,6 +40,11 @@ struct OAuthState
struct MHD_Daemon *mhd;
/**
+ * Birthdate that the oauth server should return in a response, may be NULL
+ */
+ const char *birthdate;
+
+ /**
* Port to listen on.
*/
uint16_t port;
@@ -172,23 +177,36 @@ handler_cb (void *cls,
void **con_cls)
{
struct RequestCtx *rc = *con_cls;
+ struct OAuthState *oas = cls;
unsigned int hc;
json_t *body;
- (void) cls;
(void) version;
if (0 == strcasecmp (method,
MHD_HTTP_METHOD_GET))
{
+ json_t *data =
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("id",
+ "XXXID12345678"),
+ GNUNET_JSON_pack_string ("first_name",
+ "Bob"),
+ GNUNET_JSON_pack_string ("last_name",
+ "Builder"));
+
+ if (NULL != oas->birthdate)
+ GNUNET_assert (0 ==
+ json_object_set_new (data,
+ "birthdate",
+ json_string_nocheck (
+ oas->birthdate)));
+
body = GNUNET_JSON_PACK (
GNUNET_JSON_pack_string (
"status",
"success"),
GNUNET_JSON_pack_object_steal (
- "data",
- GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("id",
- "XXXID12345678"))));
+ "data", data));
return TALER_MHD_reply_json_steal (connection,
body,
MHD_HTTP_OK);
@@ -305,6 +323,7 @@ cleanup (void *cls,
(void) toe;
if (NULL == rc)
return;
+ MHD_destroy_post_processor (rc->pp);
GNUNET_free (rc->code);
GNUNET_free (rc->client_id);
GNUNET_free (rc->redirect_uri);
@@ -328,12 +347,18 @@ oauth_run (void *cls,
struct OAuthState *oas = cls;
(void) cmd;
- oas->mhd = MHD_start_daemon (MHD_USE_AUTO_INTERNAL_THREAD,
+ oas->mhd = MHD_start_daemon (MHD_USE_AUTO_INTERNAL_THREAD | MHD_USE_DEBUG,
oas->port,
NULL, NULL,
&handler_cb, oas,
MHD_OPTION_NOTIFY_COMPLETED, &cleanup, NULL,
NULL);
+ if (NULL == oas->mhd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
TALER_TESTING_interpreter_next (is);
}
@@ -362,13 +387,15 @@ oauth_cleanup (void *cls,
struct TALER_TESTING_Command
-TALER_TESTING_cmd_oauth (const char *label,
- uint16_t port)
+TALER_TESTING_cmd_oauth_with_birthdate (const char *label,
+ const char *birthdate,
+ uint16_t port)
{
struct OAuthState *oas;
oas = GNUNET_new (struct OAuthState);
oas->port = port;
+ oas->birthdate = birthdate;
{
struct TALER_TESTING_Command cmd = {
.cls = oas,
diff --git a/src/testing/testing_api_cmd_offline_sign_global_fees.c b/src/testing/testing_api_cmd_offline_sign_global_fees.c
index 7c9032255..db3916258 100644
--- a/src/testing/testing_api_cmd_offline_sign_global_fees.c
+++ b/src/testing/testing_api_cmd_offline_sign_global_fees.c
@@ -52,11 +52,6 @@ struct OfflineSignState
const char *history_fee_s;
/**
- * The KYC fee to sign.
- */
- const char *kyc_fee_s;
-
- /**
* The account fee to sign.
*/
const char *account_fee_s;
@@ -72,11 +67,6 @@ struct OfflineSignState
struct GNUNET_TIME_Relative purse_timeout;
/**
- * How long does a user have to complete the KYC?
- */
- struct GNUNET_TIME_Relative kyc_timeout;
-
- /**
* How long do we keep the history?
*/
struct GNUNET_TIME_Relative history_expiration;
@@ -104,7 +94,6 @@ offlinesign_run (void *cls,
char num_purses[12];
char history_expiration[32];
char purse_timeout[32];
- char kyc_timeout[32];
GNUNET_snprintf (num_purses,
sizeof (num_purses),
@@ -120,11 +109,6 @@ offlinesign_run (void *cls,
"%s",
GNUNET_TIME_relative2s (ks->purse_timeout,
false));
- GNUNET_snprintf (kyc_timeout,
- sizeof (kyc_timeout),
- "%s",
- GNUNET_TIME_relative2s (ks->kyc_timeout,
- false));
ks->offlinesign_proc
= GNUNET_OS_start_process (
GNUNET_OS_INHERIT_STD_ALL,
@@ -136,11 +120,9 @@ offlinesign_run (void *cls,
"global-fee",
"now",
ks->history_fee_s,
- ks->kyc_fee_s,
ks->account_fee_s,
ks->purse_fee_s,
purse_timeout,
- kyc_timeout,
history_expiration,
num_purses,
"upload",
@@ -215,11 +197,9 @@ TALER_TESTING_cmd_exec_offline_sign_global_fees (
const char *label,
const char *config_filename,
const char *history_fee,
- const char *kyc_fee,
const char *account_fee,
const char *purse_fee,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
unsigned int num_purses)
{
@@ -228,11 +208,9 @@ TALER_TESTING_cmd_exec_offline_sign_global_fees (
ks = GNUNET_new (struct OfflineSignState);
ks->config_filename = config_filename;
ks->history_fee_s = history_fee;
- ks->kyc_fee_s = kyc_fee;
ks->account_fee_s = account_fee;
ks->purse_fee_s = purse_fee;
ks->purse_timeout = purse_timeout;
- ks->kyc_timeout = kyc_timeout;
ks->history_expiration = history_expiration;
ks->num_purses = num_purses;
{
diff --git a/src/testing/testing_api_cmd_offline_sign_wire_fees.c b/src/testing/testing_api_cmd_offline_sign_wire_fees.c
index 55746ebc5..0fccbcd0a 100644
--- a/src/testing/testing_api_cmd_offline_sign_wire_fees.c
+++ b/src/testing/testing_api_cmd_offline_sign_wire_fees.c
@@ -52,11 +52,6 @@ struct OfflineSignState
const char *wire_fee_s;
/**
- * The wad fee to sign.
- */
- const char *wad_fee_s;
-
- /**
* The closing fee to sign.
*/
const char *closing_fee_s;
@@ -91,7 +86,6 @@ offlinesign_run (void *cls,
"x-taler-bank",
ks->wire_fee_s,
ks->closing_fee_s,
- ks->wad_fee_s,
"upload",
NULL);
if (NULL == ks->offlinesign_proc)
@@ -163,15 +157,13 @@ struct TALER_TESTING_Command
TALER_TESTING_cmd_exec_offline_sign_fees (const char *label,
const char *config_filename,
const char *wire_fee,
- const char *closing_fee,
- const char *wad_fee)
+ const char *closing_fee)
{
struct OfflineSignState *ks;
ks = GNUNET_new (struct OfflineSignState);
ks->config_filename = config_filename;
ks->wire_fee_s = wire_fee;
- ks->wad_fee_s = wad_fee;
ks->closing_fee_s = closing_fee;
{
struct TALER_TESTING_Command cmd = {
diff --git a/src/testing/testing_api_cmd_purse_create_deposit.c b/src/testing/testing_api_cmd_purse_create_deposit.c
index 200127b77..4740f9801 100644
--- a/src/testing/testing_api_cmd_purse_create_deposit.c
+++ b/src/testing/testing_api_cmd_purse_create_deposit.c
@@ -44,10 +44,20 @@ struct Coin
unsigned int coin_index;
/**
+ * Public key of the deposited coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
* Amount to deposit (with fee).
*/
struct TALER_Amount deposit_with_fee;
+ /**
+ * Entry in the coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
};
@@ -162,22 +172,15 @@ deposit_cb (void *cls,
ds->dh = NULL;
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
- ds->exchange_pub = dr->details.success.exchange_pub;
- ds->exchange_sig = dr->details.success.exchange_sig;
+ ds->exchange_pub = dr->details.ok.exchange_pub;
+ ds->exchange_sig = dr->details.ok.exchange_sig;
}
TALER_TESTING_interpreter_next (ds->is);
}
@@ -200,9 +203,15 @@ deposit_run (void *cls,
(void) cmd;
ds->is = is;
+ GNUNET_CRYPTO_eddsa_key_create (&ds->purse_priv.eddsa_priv);
+ GNUNET_CRYPTO_eddsa_key_create (&ds->merge_priv.eddsa_priv);
+ GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv);
+ GNUNET_CRYPTO_eddsa_key_get_public (&ds->purse_priv.eddsa_priv,
+ &ds->purse_pub.eddsa_pub);
+
for (unsigned int i = 0; i<ds->num_coin_references; i++)
{
- const struct Coin *cr = &ds->coin_references[i];
+ struct Coin *cr = &ds->coin_references[i];
struct TALER_EXCHANGE_PurseDeposit *pd = &deposits[i];
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
@@ -246,14 +255,20 @@ deposit_run (void *cls,
pd->coin_priv = *coin_priv;
pd->amount = cr->deposit_with_fee;
pd->h_denom_pub = denom_pub->h_key;
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
+ &cr->coin_pub.eddsa_pub);
+ cr->che.type = TALER_EXCHANGE_CTT_PURSE_DEPOSIT;
+ cr->che.amount = cr->deposit_with_fee;
+ GNUNET_CRYPTO_eddsa_key_get_public (
+ &ds->purse_priv.eddsa_priv,
+ &cr->che.details.purse_deposit.purse_pub.eddsa_pub);
+ cr->che.details.purse_deposit.exchange_base_url
+ = TALER_TESTING_get_exchange_url (is);
+ TALER_age_commitment_hash (
+ &age_commitment_proof->commitment,
+ &cr->che.details.purse_deposit.phac);
}
- GNUNET_CRYPTO_eddsa_key_create (&ds->purse_priv.eddsa_priv);
- GNUNET_CRYPTO_eddsa_key_create (&ds->merge_priv.eddsa_priv);
- GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv);
- GNUNET_CRYPTO_eddsa_key_get_public (&ds->purse_priv.eddsa_priv,
- &ds->purse_pub.eddsa_pub);
-
ds->purse_expiration =
GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_relative_to_absolute (ds->rel_expiration));
@@ -263,7 +278,9 @@ deposit_run (void *cls,
"pay_deadline",
GNUNET_JSON_from_timestamp (ds->purse_expiration)));
ds->dh = TALER_EXCHANGE_purse_create_with_deposit (
- is->exchange,
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
&ds->purse_priv,
&ds->merge_priv,
&ds->contract_priv,
@@ -299,10 +316,8 @@ deposit_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_purse_create_with_deposit_cancel (ds->dh);
ds->dh = NULL;
}
@@ -330,23 +345,33 @@ deposit_traits (void *cls,
unsigned int index)
{
struct PurseCreateDepositState *ds = cls;
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_merge_priv (&ds->merge_priv),
- TALER_TESTING_make_trait_contract_priv (&ds->contract_priv),
- TALER_TESTING_make_trait_purse_priv (&ds->purse_priv),
- TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
- TALER_TESTING_make_trait_contract_terms (ds->contract_terms),
- TALER_TESTING_make_trait_deposit_amount (0,
- &ds->target_amount),
- TALER_TESTING_make_trait_timestamp (index,
- &ds->purse_expiration),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
+ if (index >= ds->num_coin_references)
+ return GNUNET_NO;
+
+ {
+ const struct Coin *co = &ds->coin_references[index];
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_merge_priv (&ds->merge_priv),
+ TALER_TESTING_make_trait_contract_priv (&ds->contract_priv),
+ TALER_TESTING_make_trait_coin_history (index,
+ &co->che),
+ TALER_TESTING_make_trait_coin_pub (index,
+ &co->coin_pub),
+ TALER_TESTING_make_trait_purse_priv (&ds->purse_priv),
+ TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
+ TALER_TESTING_make_trait_contract_terms (ds->contract_terms),
+ TALER_TESTING_make_trait_deposit_amount (0,
+ &ds->target_amount),
+ TALER_TESTING_make_trait_timestamp (index,
+ &ds->purse_expiration),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+ }
}
diff --git a/src/testing/testing_api_cmd_purse_delete.c b/src/testing/testing_api_cmd_purse_delete.c
new file mode 100644
index 000000000..26037359e
--- /dev/null
+++ b/src/testing/testing_api_cmd_purse_delete.c
@@ -0,0 +1,189 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2020 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_purse_delete.c
+ * @brief command for testing /management/purse/disable.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "purse_delete" CMD.
+ */
+struct PurseDeleteState
+{
+
+ /**
+ * Purse delete handle while operation is running.
+ */
+ struct TALER_EXCHANGE_PurseDeleteHandle *pdh;
+
+ /**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Command that created the purse we now want to
+ * delete.
+ */
+ const char *purse_cmd;
+};
+
+
+/**
+ * Callback to analyze the DELETE /purses/$PID response, just used to check if
+ * the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param pdr HTTP response details
+ */
+static void
+purse_delete_cb (void *cls,
+ const struct TALER_EXCHANGE_PurseDeleteResponse *pdr)
+{
+ struct PurseDeleteState *pds = cls;
+
+ pds->pdh = NULL;
+ if (pds->expected_response_code != pdr->hr.http_status)
+ {
+ TALER_TESTING_unexpected_status (pds->is,
+ pdr->hr.http_status,
+ pds->expected_response_code);
+ return;
+ }
+ TALER_TESTING_interpreter_next (pds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+purse_delete_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct PurseDeleteState *pds = cls;
+ const struct TALER_PurseContractPrivateKeyP *purse_priv;
+ const struct TALER_TESTING_Command *ref;
+ const char *exchange_url;
+
+ (void) cmd;
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ pds->purse_cmd);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_purse_priv (ref,
+ &purse_priv))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ pds->is = is;
+ pds->pdh = TALER_EXCHANGE_purse_delete (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ purse_priv,
+ &purse_delete_cb,
+ pds);
+ if (NULL == pds->pdh)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "purse_delete" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct PurseDeleteState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+purse_delete_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct PurseDeleteState *pds = cls;
+
+ if (NULL != pds->pdh)
+ {
+ TALER_TESTING_command_incomplete (pds->is,
+ cmd->label);
+ TALER_EXCHANGE_purse_delete_cancel (pds->pdh);
+ pds->pdh = NULL;
+ }
+ GNUNET_free (pds);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_purse_delete (const char *label,
+ unsigned int expected_http_status,
+ const char *purse_cmd)
+{
+ struct PurseDeleteState *ds;
+
+ ds = GNUNET_new (struct PurseDeleteState);
+ ds->expected_response_code = expected_http_status;
+ ds->purse_cmd = purse_cmd;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &purse_delete_run,
+ .cleanup = &purse_delete_cleanup
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_purse_delete.c */
diff --git a/src/testing/testing_api_cmd_purse_deposit.c b/src/testing/testing_api_cmd_purse_deposit.c
index b10c6d329..048c6d736 100644
--- a/src/testing/testing_api_cmd_purse_deposit.c
+++ b/src/testing/testing_api_cmd_purse_deposit.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -39,6 +39,16 @@ struct Coin
char *command_ref;
/**
+ * Entry in the coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
+ * Public key of the deposited coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
* index of the specific coin in the traits of @e command_ref.
*/
unsigned int coin_index;
@@ -137,23 +147,16 @@ deposit_cb (void *cls,
ds->dh = NULL;
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
if (MHD_HTTP_OK == dr->hr.http_status)
{
if (-1 !=
- TALER_amount_cmp (&dr->details.success.total_deposited,
- &dr->details.success.purse_value_after_fees))
+ TALER_amount_cmp (&dr->details.ok.total_deposited,
+ &dr->details.ok.purse_value_after_fees))
{
const struct TALER_TESTING_Command *purse_cmd;
const struct TALER_ReserveSignatureP *reserve_sig;
@@ -163,7 +166,7 @@ deposit_cb (void *cls,
purse_cmd = TALER_TESTING_interpreter_lookup_command (ds->is,
ds->purse_ref);
-
+ GNUNET_assert (NULL != purse_cmd);
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_sig (purse_cmd,
&reserve_sig))
@@ -202,10 +205,10 @@ deposit_cb (void *cls,
/* Deposits complete, create trait! */
ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE;
{
- const struct TALER_EXCHANGE_Keys *keys;
+ struct TALER_EXCHANGE_Keys *keys;
const struct TALER_EXCHANGE_GlobalFee *gf;
- keys = TALER_EXCHANGE_get_keys (ds->is->exchange);
+ keys = TALER_TESTING_get_keys (ds->is);
GNUNET_assert (NULL != keys);
gf = TALER_EXCHANGE_get_global_fee (keys,
*merge_timestamp);
@@ -213,7 +216,7 @@ deposit_cb (void *cls,
/* Note: change when flags below changes! */
ds->reserve_history.amount
- = dr->details.success.purse_value_after_fees;
+ = dr->details.ok.purse_value_after_fees;
if (true)
{
ds->reserve_history.details.merge_details.purse_fee = gf->fees.purse;
@@ -226,7 +229,7 @@ deposit_cb (void *cls,
}
}
ds->reserve_history.details.merge_details.h_contract_terms
- = dr->details.success.h_contract_terms;
+ = dr->details.ok.h_contract_terms;
ds->reserve_history.details.merge_details.merge_pub
= *merge_pub;
ds->reserve_history.details.merge_details.purse_pub
@@ -236,7 +239,7 @@ deposit_cb (void *cls,
ds->reserve_history.details.merge_details.merge_timestamp
= *merge_timestamp;
ds->reserve_history.details.merge_details.purse_expiration
- = dr->details.success.purse_expiration;
+ = dr->details.ok.purse_expiration;
ds->reserve_history.details.merge_details.min_age
= ds->min_age;
ds->reserve_history.details.merge_details.flags
@@ -267,9 +270,9 @@ deposit_run (void *cls,
(void) cmd;
ds->is = is;
-
purse_cmd = TALER_TESTING_interpreter_lookup_command (is,
ds->purse_ref);
+ GNUNET_assert (NULL != purse_cmd);
if (GNUNET_OK !=
TALER_TESTING_get_trait_purse_pub (purse_cmd,
&purse_pub))
@@ -281,7 +284,7 @@ deposit_run (void *cls,
ds->purse_pub = *purse_pub;
for (unsigned int i = 0; i<ds->num_coin_references; i++)
{
- const struct Coin *cr = &ds->coin_references[i];
+ struct Coin *cr = &ds->coin_references[i];
struct TALER_EXCHANGE_PurseDeposit *pd = &deposits[i];
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
@@ -291,13 +294,7 @@ deposit_run (void *cls,
coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
cr->command_ref);
- if (NULL == coin_cmd)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
+ GNUNET_assert (NULL != coin_cmd);
if ( (GNUNET_OK !=
TALER_TESTING_get_trait_coin_priv (coin_cmd,
cr->coin_index,
@@ -320,6 +317,16 @@ deposit_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
+ &cr->coin_pub.eddsa_pub);
+ cr->che.type = TALER_EXCHANGE_CTT_PURSE_DEPOSIT;
+ cr->che.amount = cr->deposit_with_fee;
+ cr->che.details.purse_deposit.purse_pub = *purse_pub;
+ cr->che.details.purse_deposit.exchange_base_url
+ = TALER_TESTING_get_exchange_url (is);
+ TALER_age_commitment_hash (
+ &age_commitment_proof->commitment,
+ &cr->che.details.purse_deposit.phac);
pd->age_commitment_proof = age_commitment_proof;
pd->denom_sig = *denom_pub_sig;
pd->coin_priv = *coin_priv;
@@ -328,8 +335,10 @@ deposit_run (void *cls,
}
ds->dh = TALER_EXCHANGE_purse_deposit (
- is->exchange,
- NULL, /* FIXME: WADs support: purse exchange URL */
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ NULL, /* FIXME #7271: WADs support: purse exchange URL */
&ds->purse_pub,
ds->min_age,
ds->num_coin_references,
@@ -362,10 +371,8 @@ deposit_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_purse_deposit_cancel (ds->dh);
ds->dh = NULL;
}
@@ -392,21 +399,31 @@ deposit_traits (void *cls,
unsigned int index)
{
struct PurseDepositState *ds = cls;
- struct TALER_TESTING_Trait traits[] = {
- /* history entry MUST be first due to response code logic below! */
- TALER_TESTING_make_trait_reserve_history (0,
- &ds->reserve_history),
- TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub),
- TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (ds->purse_complete
- ? &traits[0] /* we have reserve history */
- : &traits[1], /* skip reserve history */
- ret,
- trait,
- index);
+
+ if (index >= ds->num_coin_references)
+ return GNUNET_NO;
+ {
+ const struct Coin *co = &ds->coin_references[index];
+ struct TALER_TESTING_Trait traits[] = {
+ /* history entry MUST be first due to response code logic below! */
+ TALER_TESTING_make_trait_reserve_history (0,
+ &ds->reserve_history),
+ TALER_TESTING_make_trait_coin_history (index,
+ &co->che),
+ TALER_TESTING_make_trait_coin_pub (index,
+ &co->coin_pub),
+ TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub),
+ TALER_TESTING_make_trait_purse_pub (&ds->purse_pub),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (ds->purse_complete
+ ? &traits[0] /* we have reserve history */
+ : &traits[1], /* skip reserve history */
+ ret,
+ trait,
+ index);
+ }
}
@@ -444,7 +461,8 @@ TALER_TESTING_cmd_purse_deposit_coins (
{
struct Coin *c = &ds->coin_references[i++];
- GNUNET_assert (NULL != (val = va_arg (ap, const char *)));
+ GNUNET_assert (NULL != (val = va_arg (ap,
+ const char *)));
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_parse_coin_reference (
ref,
diff --git a/src/testing/testing_api_cmd_purse_get.c b/src/testing/testing_api_cmd_purse_get.c
index 61873721b..d5246660b 100644
--- a/src/testing/testing_api_cmd_purse_get.c
+++ b/src/testing/testing_api_cmd_purse_get.c
@@ -147,11 +147,11 @@ purse_status_cb (void *cls,
TALER_string_to_amount (ss->expected_balance,
&eb));
if (0 != TALER_amount_cmp (&eb,
- &rs->details.success.balance))
+ &rs->details.ok.balance))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected amount in purse: %s\n",
- TALER_amount_to_string (&rs->details.success.balance));
+ TALER_amount_to_string (&rs->details.ok.balance));
TALER_TESTING_interpreter_fail (ss->is);
return;
}
@@ -188,13 +188,7 @@ status_run (void *cls,
create_purse
= TALER_TESTING_interpreter_lookup_command (is,
ss->purse_reference);
-
- if (NULL == create_purse)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
+ GNUNET_assert (NULL != create_purse);
if (GNUNET_OK !=
TALER_TESTING_get_trait_purse_pub (create_purse,
&ss->purse_pub))
@@ -204,12 +198,15 @@ status_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- ss->pgh = TALER_EXCHANGE_purse_get (is->exchange,
- ss->purse_pub,
- ss->timeout,
- ss->wait_for_merge,
- &purse_status_cb,
- ss);
+ ss->pgh = TALER_EXCHANGE_purse_get (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ ss->purse_pub,
+ ss->timeout,
+ ss->wait_for_merge,
+ &purse_status_cb,
+ ss);
if (! GNUNET_TIME_relative_is_zero (ss->timeout))
{
TALER_TESTING_interpreter_next (is);
@@ -233,10 +230,8 @@ status_cleanup (void *cls,
if (NULL != ss->pgh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ss->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
TALER_EXCHANGE_purse_get_cancel (ss->pgh);
ss->pgh = NULL;
}
@@ -311,6 +306,7 @@ finish_run (void *cls,
poll_purse
= TALER_TESTING_interpreter_lookup_command (is,
ps->poll_reference);
+ GNUNET_assert (NULL != poll_purse);
GNUNET_assert (poll_purse->run == &status_run);
ss = poll_purse->cls;
if (NULL == ss->pgh)
diff --git a/src/testing/testing_api_cmd_purse_merge.c b/src/testing/testing_api_cmd_purse_merge.c
index 4d1e8bf4b..cf9d4f996 100644
--- a/src/testing/testing_api_cmd_purse_merge.c
+++ b/src/testing/testing_api_cmd_purse_merge.c
@@ -72,6 +72,18 @@ struct PurseMergeState
struct TALER_TESTING_Interpreter *is;
/**
+ * Hash of the payto://-URI for the reserve we are
+ * merging into.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
+ * a request for KYC.
+ */
+ uint64_t requirement_row;
+
+ /**
* Reserve history entry that corresponds to this operation.
* Will be of type #TALER_EXCHANGE_RTT_MERGE.
*/
@@ -129,8 +141,9 @@ merge_cb (void *cls,
struct PurseMergeState *ds = cls;
ds->dh = NULL;
- if (MHD_HTTP_OK == dr->hr.http_status)
+ switch (dr->hr.http_status)
{
+ case MHD_HTTP_OK:
ds->reserve_history.type = TALER_EXCHANGE_RTT_MERGE;
ds->reserve_history.amount = ds->value_after_fees;
GNUNET_assert (GNUNET_OK ==
@@ -153,21 +166,20 @@ merge_cb (void *cls,
= ds->min_age;
ds->reserve_history.details.merge_details.flags
= TALER_WAMF_MODE_MERGE_FULLY_PAID_PURSE;
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* KYC required */
+ ds->requirement_row =
+ dr->details.unavailable_for_legal_reasons.requirement_row;
+ break;
}
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -281,11 +293,35 @@ merge_run (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&ds->reserve_priv.eddsa_priv,
&ds->reserve_pub.eddsa_pub);
+ {
+ char *payto_uri;
+ const char *exchange_url;
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ payto_uri = TALER_reserve_make_payto (exchange_url,
+ &ds->reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &ds->h_payto);
+ GNUNET_free (payto_uri);
+ }
GNUNET_CRYPTO_eddsa_key_get_public (&merge_priv->eddsa_priv,
&ds->merge_pub.eddsa_pub);
ds->merge_timestamp = GNUNET_TIME_timestamp_get ();
ds->dh = TALER_EXCHANGE_account_merge (
- is->exchange,
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
NULL, /* no wad */
&ds->reserve_priv,
&ds->purse_pub,
@@ -323,10 +359,8 @@ merge_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_account_merge_cancel (ds->dh);
ds->dh = NULL;
}
@@ -357,6 +391,8 @@ merge_traits (void *cls,
TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub),
TALER_TESTING_make_trait_timestamp (0,
&ds->merge_timestamp),
+ TALER_TESTING_make_trait_legi_requirement_row (&ds->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&ds->h_payto),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_recoup.c b/src/testing/testing_api_cmd_recoup.c
index ed8c7eed7..cefcd96bb 100644
--- a/src/testing/testing_api_cmd_recoup.c
+++ b/src/testing/testing_api_cmd_recoup.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2018 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -59,6 +59,16 @@ struct RecoupState
struct TALER_ReservePublicKeyP reserve_pub;
/**
+ * Entry in the coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin;
+
+ /**
* Reserve history entry, set if this recoup actually filled up a reserve.
* Otherwise `reserve_history.type` will be zero.
*/
@@ -73,17 +83,15 @@ struct RecoupState
* was paid back belonged to the right reserve.
*
* @param cls closure
- * @param hr HTTP response details
- * @param reserve_pub public key of the reserve receiving the recoup
+ * @param rr response details
*/
static void
recoup_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_ReservePublicKeyP *reserve_pub)
+ const struct TALER_EXCHANGE_RecoupResponse *rr)
{
struct RecoupState *ps = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rr->hr;
struct TALER_TESTING_Interpreter *is = ps->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
const struct TALER_TESTING_Command *reserve_cmd;
char *cref;
unsigned int idx;
@@ -91,18 +99,9 @@ recoup_cb (void *cls,
ps->ph = NULL;
if (ps->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- fprintf (stderr, "\n");
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ hr->http_status,
+ ps->expected_response_code);
return;
}
@@ -135,12 +134,6 @@ recoup_cb (void *cls,
{
const struct TALER_ReservePrivateKeyP *reserve_priv;
- if (NULL == reserve_pub)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_priv (reserve_cmd,
&reserve_priv))
@@ -151,7 +144,7 @@ recoup_cb (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
&ps->reserve_pub.eddsa_pub);
- if (0 != GNUNET_memcmp (reserve_pub,
+ if (0 != GNUNET_memcmp (&rr->details.ok.reserve_pub,
&ps->reserve_pub))
{
GNUNET_break (0);
@@ -162,6 +155,7 @@ recoup_cb (void *cls,
TALER_amount_is_valid (&ps->reserve_history.amount))
ps->reserve_history.type = TALER_EXCHANGE_RTT_RECOUP;
/* ps->reserve_history.details.recoup_details.coin_pub; // initialized earlier */
+ ps->che.details.recoup.reserve_pub = ps->reserve_pub;
}
break;
case MHD_HTTP_NOT_FOUND:
@@ -200,6 +194,7 @@ recoup_run (void *cls,
char *cref;
unsigned int idx;
const struct TALER_ExchangeWithdrawValues *ewv;
+ struct TALER_DenominationHashP h_denom_pub;
ps->is = is;
if (GNUNET_OK !=
@@ -231,6 +226,8 @@ recoup_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
+ GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
+ &ps->coin.eddsa_pub);
if (GNUNET_OK !=
TALER_TESTING_get_trait_exchange_wd_value (coin_cmd,
idx,
@@ -273,13 +270,27 @@ recoup_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Trying to recoup denomination '%s'\n",
TALER_B2S (&denom_pub->h_key));
- ps->ph = TALER_EXCHANGE_recoup (is->exchange,
- denom_pub,
- coin_sig,
- ewv,
- planchet,
- &recoup_cb,
- ps);
+ ps->che.type = TALER_EXCHANGE_CTT_RECOUP;
+ ps->che.amount = ps->reserve_history.amount;
+ TALER_planchet_blinding_secret_create (planchet,
+ ewv,
+ &ps->che.details.recoup.coin_bks);
+ TALER_denom_pub_hash (&denom_pub->key,
+ &h_denom_pub);
+ TALER_wallet_recoup_sign (&h_denom_pub,
+ &ps->che.details.recoup.coin_bks,
+ coin_priv,
+ &ps->che.details.recoup.coin_sig);
+ ps->ph = TALER_EXCHANGE_recoup (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ denom_pub,
+ coin_sig,
+ ewv,
+ planchet,
+ &recoup_cb,
+ ps);
GNUNET_assert (NULL != ps->ph);
}
@@ -330,6 +341,10 @@ recoup_traits (void *cls,
TALER_TESTING_make_trait_reserve_pub (&ps->reserve_pub),
TALER_TESTING_make_trait_reserve_history (0,
&ps->reserve_history),
+ TALER_TESTING_make_trait_coin_history (0,
+ &ps->che),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &ps->coin),
TALER_TESTING_trait_end ()
};
diff --git a/src/testing/testing_api_cmd_recoup_refresh.c b/src/testing/testing_api_cmd_recoup_refresh.c
index 6081a4ba1..68d267be4 100644
--- a/src/testing/testing_api_cmd_recoup_refresh.c
+++ b/src/testing/testing_api_cmd_recoup_refresh.c
@@ -44,6 +44,26 @@ struct RecoupRefreshState
const char *coin_reference;
/**
+ * Entry in the old coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che_old;
+
+ /**
+ * Entry in the recouped coin's history generated by this operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che_new;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub_old;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub_new;
+
+ /**
* Amount to be recouped.
*/
struct TALER_Amount amount;
@@ -73,35 +93,24 @@ struct RecoupRefreshState
* was paid back belonged to the right old coin.
*
* @param cls closure
- * @param hr HTTP response details
- * @param old_coin_pub public key of the dirty coin
+ * @param rrr response details
*/
static void
recoup_refresh_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_CoinSpendPublicKeyP *old_coin_pub)
+ const struct TALER_EXCHANGE_RecoupRefreshResponse *rrr)
{
struct RecoupRefreshState *rrs = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rrr->hr;
struct TALER_TESTING_Interpreter *is = rrs->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
char *cref;
unsigned int idx;
rrs->ph = NULL;
if (rrs->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- fprintf (stderr, "\n");
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ hr->http_status,
+ rrs->expected_response_code);
return;
}
@@ -150,7 +159,7 @@ recoup_refresh_cb (void *cls,
GNUNET_CRYPTO_eddsa_key_get_public (&dirty_priv->eddsa_priv,
&oc.eddsa_pub);
if (0 != GNUNET_memcmp (&oc,
- old_coin_pub))
+ &rrr->details.ok.old_coin_pub))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
@@ -189,6 +198,7 @@ recoup_refresh_run (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_TESTING_Command *melt_cmd;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv_old;
const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
const struct TALER_DenominationSignature *coin_sig;
const struct TALER_RefreshMasterSecretP *rplanchet;
@@ -196,6 +206,7 @@ recoup_refresh_run (void *cls,
const struct TALER_ExchangeWithdrawValues *ewv;
char *cref;
unsigned int idx;
+ struct TALER_DenominationHashP h_denom_pub;
rrs->is = is;
if (GNUNET_OK !=
@@ -235,6 +246,22 @@ recoup_refresh_run (void *cls,
return;
}
if (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (melt_cmd,
+ 0,
+ &coin_priv_old))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (
+ &coin_priv->eddsa_priv,
+ &rrs->coin_pub_new.eddsa_pub);
+ GNUNET_CRYPTO_eddsa_key_get_public (
+ &coin_priv_old->eddsa_priv,
+ &rrs->coin_pub_old.eddsa_pub);
+
+ if (GNUNET_OK !=
TALER_TESTING_get_trait_exchange_wd_value (melt_cmd,
idx,
&ewv))
@@ -281,15 +308,41 @@ recoup_refresh_run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Trying to recoup_refresh denomination '%s'\n",
TALER_B2S (&denom_pub->h_key));
- rrs->ph = TALER_EXCHANGE_recoup_refresh (is->exchange,
- denom_pub,
- coin_sig,
- ewv,
- rplanchet,
- planchet,
- idx,
- &recoup_refresh_cb,
- rrs);
+ rrs->che_old.type
+ = TALER_EXCHANGE_CTT_OLD_COIN_RECOUP;
+ rrs->che_old.amount
+ = rrs->amount;
+ rrs->che_old.details.old_coin_recoup.new_coin_pub
+ = rrs->coin_pub_new;
+ rrs->che_new.type
+ = TALER_EXCHANGE_CTT_RECOUP_REFRESH;
+ rrs->che_new.amount
+ = rrs->amount;
+ rrs->che_new.details.recoup_refresh.old_coin_pub
+ = rrs->coin_pub_old;
+ TALER_planchet_blinding_secret_create (
+ planchet,
+ ewv,
+ &rrs->che_new.details.recoup_refresh.coin_bks);
+ TALER_denom_pub_hash (&denom_pub->key,
+ &h_denom_pub);
+ TALER_wallet_recoup_refresh_sign (
+ &h_denom_pub,
+ &rrs->che_new.details.recoup_refresh.coin_bks,
+ coin_priv,
+ &rrs->che_new.details.recoup_refresh.coin_sig);
+ rrs->ph = TALER_EXCHANGE_recoup_refresh (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ denom_pub,
+ coin_sig,
+ ewv,
+ rplanchet,
+ planchet,
+ idx,
+ &recoup_refresh_cb,
+ rrs);
GNUNET_assert (NULL != rrs->ph);
}
@@ -315,6 +368,42 @@ recoup_refresh_cleanup (void *cls,
}
+/**
+ * Offer internal data from a "recoup-refresh" CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+recoup_refresh_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct RecoupRefreshState *rrs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_coin_history (0,
+ &rrs->che_old),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &rrs->coin_pub_old),
+ TALER_TESTING_make_trait_coin_history (1,
+ &rrs->che_new),
+ TALER_TESTING_make_trait_coin_pub (1,
+ &rrs->coin_pub_new),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
struct TALER_TESTING_Command
TALER_TESTING_cmd_recoup_refresh (const char *label,
unsigned int expected_response_code,
@@ -343,7 +432,8 @@ TALER_TESTING_cmd_recoup_refresh (const char *label,
.cls = rrs,
.label = label,
.run = &recoup_refresh_run,
- .cleanup = &recoup_refresh_cleanup
+ .cleanup = &recoup_refresh_cleanup,
+ .traits = &recoup_refresh_traits
};
return cmd;
diff --git a/src/testing/testing_api_cmd_refresh.c b/src/testing/testing_api_cmd_refresh.c
index bc0c4e090..111e9118f 100644
--- a/src/testing/testing_api_cmd_refresh.c
+++ b/src/testing/testing_api_cmd_refresh.c
@@ -75,12 +75,12 @@ struct TALER_TESTING_FreshCoinData
* applicable.
*/
struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* The blinding key (needed for recoup operations).
*/
- union TALER_DenominationBlindingKeyP blinding_key;
+ union GNUNET_CRYPTO_BlindingSecretP blinding_key;
};
@@ -103,6 +103,11 @@ struct RefreshMeltState
struct TALER_EXCHANGE_RefreshData refresh_data;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Reference to a previous melt command.
*/
const char *melt_reference;
@@ -113,6 +118,12 @@ struct RefreshMeltState
struct TALER_EXCHANGE_MeltHandle *rmh;
/**
+ * Expected entry in the coin history created by this
+ * operation.
+ */
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
* Interpreter state.
*/
struct TALER_TESTING_Interpreter *is;
@@ -140,6 +151,11 @@ struct RefreshMeltState
const struct TALER_CoinSpendPrivateKeyP *melt_priv;
/**
+ * Public key of the dirty coin being melted.
+ */
+ struct TALER_CoinSpendPublicKeyP melt_pub;
+
+ /**
* Task scheduled to try later.
*/
struct GNUNET_SCHEDULER_Task *retry_task;
@@ -210,6 +226,11 @@ struct RefreshRevealState
struct TALER_EXCHANGE_RefreshesRevealHandle *rrh;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Convenience struct to keep in one place all the
* data related to one fresh coin, set by the reveal callback
* as it comes from the exchange.
@@ -273,6 +294,11 @@ struct RefreshLinkState
const char *reveal_reference;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Handle to the ongoing operation.
*/
struct TALER_EXCHANGE_LinkHandle *rlh;
@@ -334,8 +360,7 @@ do_reveal_retry (void *cls)
struct RefreshRevealState *rrs = cls;
rrs->retry_task = NULL;
- rrs->is->commands[rrs->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (rrs->is);
refresh_reveal_run (rrs,
NULL,
rrs->is);
@@ -380,24 +405,16 @@ reveal_cb (void *cls,
MAX_BACKOFF);
rrs->total_backoff = GNUNET_TIME_relative_add (rrs->total_backoff,
rrs->backoff);
- rrs->is->commands[rrs->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (rrs->is);
rrs->retry_task = GNUNET_SCHEDULER_add_delayed (rrs->backoff,
&do_reveal_retry,
rrs);
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- rrs->is->commands[rrs->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rrs->is);
+ TALER_TESTING_unexpected_status (rrs->is,
+ hr->http_status,
+ rrs->expected_response_code);
return;
}
melt_cmd = TALER_TESTING_interpreter_lookup_command (rrs->is,
@@ -411,7 +428,7 @@ reveal_cb (void *cls,
switch (hr->http_status)
{
case MHD_HTTP_OK:
- rrs->num_fresh_coins = rr->details.success.num_coins;
+ rrs->num_fresh_coins = rr->details.ok.num_coins;
rrs->psa = GNUNET_new_array (rrs->num_fresh_coins,
struct TALER_PlanchetMasterSecretP);
rrs->fresh_coins = GNUNET_new_array (rrs->num_fresh_coins,
@@ -419,7 +436,7 @@ reveal_cb (void *cls,
for (unsigned int i = 0; i<rrs->num_fresh_coins; i++)
{
const struct TALER_EXCHANGE_RevealedCoinInfo *coin
- = &rr->details.success.coins[i];
+ = &rr->details.ok.coins[i];
struct TALER_TESTING_FreshCoinData *fc = &rrs->fresh_coins[i];
rrs->psa[i] = coin->ps;
@@ -434,19 +451,24 @@ reveal_cb (void *cls,
return;
}
fc->coin_priv = coin->coin_priv;
- fc->age_commitment_proof = coin->age_commitment_proof;
- fc->h_age_commitment = coin->h_age_commitment;
- TALER_denom_sig_deep_copy (&fc->sig,
- &coin->sig);
+ if (NULL != coin->age_commitment_proof)
+ {
+ fc->age_commitment_proof =
+ TALER_age_commitment_proof_duplicate (coin->age_commitment_proof);
+ fc->h_age_commitment = coin->h_age_commitment;
+ }
+
+ TALER_denom_sig_copy (&fc->sig,
+ &coin->sig);
}
if (0 != rrs->total_backoff.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Total reveal backoff for %s was %s\n",
- rrs->is->commands[rrs->is->ip].label,
+ rrs->cmd->label,
GNUNET_STRINGS_relative_time_to_string (rrs->total_backoff,
- GNUNET_YES));
+ true));
}
break;
default:
@@ -467,6 +489,19 @@ reveal_cb (void *cls,
* @param is the interpreter state.
*/
static void
+melt_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is);
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
refresh_reveal_run (void *cls,
const struct TALER_TESTING_Command *cmd,
struct TALER_TESTING_Interpreter *is)
@@ -475,6 +510,7 @@ refresh_reveal_run (void *cls,
struct RefreshMeltState *rms;
const struct TALER_TESTING_Command *melt_cmd;
+ rrs->cmd = cmd;
rrs->is = is;
melt_cmd = TALER_TESTING_interpreter_lookup_command (is,
rrs->melt_reference);
@@ -484,21 +520,23 @@ refresh_reveal_run (void *cls,
TALER_TESTING_interpreter_fail (rrs->is);
return;
}
- // FIXME: use trait for 'rms'!
+ GNUNET_assert (melt_cmd->run == &melt_run);
rms = melt_cmd->cls;
{
struct TALER_ExchangeWithdrawValues alg_values[rms->num_fresh_coins];
for (unsigned int i = 0; i<rms->num_fresh_coins; i++)
alg_values[i] = rms->mbds[i].alg_value;
- rrs->rrh = TALER_EXCHANGE_refreshes_reveal (is->exchange,
- &rms->rms,
- &rms->refresh_data,
- rms->num_fresh_coins,
- alg_values,
- rms->noreveal_index,
- &reveal_cb,
- rrs);
+ rrs->rrh = TALER_EXCHANGE_refreshes_reveal (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ &rms->rms,
+ &rms->refresh_data,
+ rms->num_fresh_coins,
+ alg_values,
+ rms->noreveal_index,
+ &reveal_cb,
+ rrs);
}
if (NULL == rrs->rrh)
{
@@ -525,10 +563,8 @@ refresh_reveal_cleanup (void *cls,
(void) cmd;
if (NULL != rrs->rrh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- rrs->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (rrs->is,
+ cmd->label);
TALER_EXCHANGE_refreshes_reveal_cancel (rrs->rrh);
rrs->rrh = NULL;
}
@@ -539,7 +575,11 @@ refresh_reveal_cleanup (void *cls,
}
for (unsigned int j = 0; j < rrs->num_fresh_coins; j++)
+ {
TALER_denom_sig_free (&rrs->fresh_coins[j].sig);
+ TALER_age_commitment_proof_free (rrs->fresh_coins[j].age_commitment_proof);
+ GNUNET_free (rrs->fresh_coins[j].age_commitment_proof);
+ }
GNUNET_free (rrs->fresh_coins);
GNUNET_free (rrs->psa);
@@ -572,8 +612,7 @@ do_link_retry (void *cls)
struct RefreshLinkState *rls = cls;
rls->retry_task = NULL;
- rls->is->commands[rls->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (rls->is);
refresh_link_run (rls,
NULL,
rls->is);
@@ -595,7 +634,6 @@ link_cb (void *cls,
struct RefreshLinkState *rls = cls;
const struct TALER_EXCHANGE_HttpResponse *hr = &lr->hr;
const struct TALER_TESTING_Command *reveal_cmd;
- struct TALER_TESTING_Command *link_cmd = &rls->is->commands[rls->is->ip];
unsigned int found;
const unsigned int *num_fresh_coins;
@@ -621,24 +659,16 @@ link_cb (void *cls,
MAX_BACKOFF);
rls->total_backoff = GNUNET_TIME_relative_add (rls->total_backoff,
rls->backoff);
- rls->is->commands[rls->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (rls->is);
rls->retry_task = GNUNET_SCHEDULER_add_delayed (rls->backoff,
&do_link_retry,
rls);
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- link_cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rls->is);
+ TALER_TESTING_unexpected_status (rls->is,
+ hr->http_status,
+ rls->expected_response_code);
return;
}
reveal_cmd = TALER_TESTING_interpreter_lookup_command (rls->is,
@@ -662,11 +692,11 @@ link_cb (void *cls,
TALER_TESTING_interpreter_fail (rls->is);
return;
}
- if (lr->details.success.num_coins != *num_fresh_coins)
+ if (lr->details.ok.num_coins != *num_fresh_coins)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected number of fresh coins: %d vs %d in %s:%u\n",
- lr->details.success.num_coins,
+ lr->details.ok.num_coins,
*num_fresh_coins,
__FILE__,
__LINE__);
@@ -674,11 +704,11 @@ link_cb (void *cls,
return;
}
/* check that the coins match */
- for (unsigned int i = 0; i<lr->details.success.num_coins; i++)
- for (unsigned int j = i + 1; j<lr->details.success.num_coins; j++)
+ for (unsigned int i = 0; i<lr->details.ok.num_coins; i++)
+ for (unsigned int j = i + 1; j<lr->details.ok.num_coins; j++)
if (0 ==
- GNUNET_memcmp (&lr->details.success.coins[i].coin_priv,
- &lr->details.success.coins[j].coin_priv))
+ GNUNET_memcmp (&lr->details.ok.coins[i].coin_priv,
+ &lr->details.ok.coins[j].coin_priv))
GNUNET_break (0);
/* Note: coins might be legitimately permutated in here... */
found = 0;
@@ -696,12 +726,12 @@ link_cb (void *cls,
return;
}
- for (unsigned int i = 0; i<lr->details.success.num_coins; i++)
+ for (unsigned int i = 0; i<lr->details.ok.num_coins; i++)
{
const struct TALER_EXCHANGE_LinkedCoinInfo *lci_i
- = &lr->details.success.coins[i];
+ = &lr->details.ok.coins[i];
- for (unsigned int j = 0; j<lr->details.success.num_coins; j++)
+ for (unsigned int j = 0; j<lr->details.ok.num_coins; j++)
{
const struct TALER_TESTING_FreshCoinData *fcj
= &(*fc)[j];
@@ -722,12 +752,12 @@ link_cb (void *cls,
} /* for j*/
} /* for i */
}
- if (found != lr->details.success.num_coins)
+ if (found != lr->details.ok.num_coins)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Only %u/%u coins match expectations\n",
found,
- lr->details.success.num_coins);
+ lr->details.ok.num_coins);
GNUNET_break (0);
TALER_TESTING_interpreter_fail (rls->is);
return;
@@ -736,9 +766,9 @@ link_cb (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Total link backoff for %s was %s\n",
- rls->is->commands[rls->is->ip].label,
+ rls->cmd->label,
GNUNET_STRINGS_relative_time_to_string (rls->total_backoff,
- GNUNET_YES));
+ true));
}
break;
default:
@@ -769,9 +799,16 @@ refresh_link_run (void *cls,
const struct TALER_TESTING_Command *reveal_cmd;
const struct TALER_TESTING_Command *melt_cmd;
const struct TALER_TESTING_Command *coin_cmd;
+ const char *exchange_url;
- (void) cmd;
+ rls->cmd = cmd;
rls->is = is;
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
reveal_cmd = TALER_TESTING_interpreter_lookup_command (rls->is,
rls->reveal_reference);
if (NULL == reveal_cmd)
@@ -791,17 +828,15 @@ refresh_link_run (void *cls,
}
/* find reserve_withdraw command */
+ GNUNET_assert (melt_cmd->run == &melt_run);
+ rms = melt_cmd->cls;
+ coin_cmd = TALER_TESTING_interpreter_lookup_command (rls->is,
+ rms->coin_reference);
+ if (NULL == coin_cmd)
{
- // FIXME: use trait!
- rms = melt_cmd->cls;
- coin_cmd = TALER_TESTING_interpreter_lookup_command (rls->is,
- rms->coin_reference);
- if (NULL == coin_cmd)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (rls->is);
- return;
- }
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (rls->is);
+ return;
}
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
@@ -816,11 +851,13 @@ refresh_link_run (void *cls,
}
/* finally, use private key from withdraw sign command */
- rls->rlh = TALER_EXCHANGE_link (is->exchange,
- coin_priv,
- rms->refresh_data.melt_age_commitment_proof,
- &link_cb,
- rls);
+ rls->rlh = TALER_EXCHANGE_link (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ coin_priv,
+ rms->refresh_data.melt_age_commitment_proof,
+ &link_cb,
+ rls);
if (NULL == rls->rlh)
{
@@ -846,11 +883,8 @@ refresh_link_cleanup (void *cls,
if (NULL != rls->rlh)
{
-
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- rls->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (rls->is,
+ cmd->label);
TALER_EXCHANGE_link_cancel (rls->rlh);
rls->rlh = NULL;
}
@@ -864,19 +898,6 @@ refresh_link_cleanup (void *cls,
/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-melt_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is);
-
-
-/**
* Task scheduled to re-try #melt_run.
*
* @param cls a `struct RefreshMeltState`
@@ -887,8 +908,7 @@ do_melt_retry (void *cls)
struct RefreshMeltState *rms = cls;
rms->retry_task = NULL;
- rms->is->commands[rms->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (rms->is);
melt_run (rms,
NULL,
rms->is);
@@ -932,58 +952,56 @@ melt_cb (void *cls,
MAX_BACKOFF);
rms->total_backoff = GNUNET_TIME_relative_add (rms->total_backoff,
rms->backoff);
- rms->is->commands[rms->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (rms->is);
rms->retry_task = GNUNET_SCHEDULER_add_delayed (rms->backoff,
&do_melt_retry,
rms);
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- rms->is->commands[rms->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rms->is);
+ TALER_TESTING_unexpected_status_with_body (rms->is,
+ hr->http_status,
+ rms->expected_response_code,
+ hr->reply);
return;
}
if (MHD_HTTP_OK == hr->http_status)
{
- rms->noreveal_index = mr->details.success.noreveal_index;
- if (mr->details.success.num_mbds != rms->num_fresh_coins)
+ rms->noreveal_index = mr->details.ok.noreveal_index;
+ if (mr->details.ok.num_mbds != rms->num_fresh_coins)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (rms->is);
return;
}
GNUNET_free (rms->mbds);
- rms->mbds = GNUNET_memdup (mr->details.success.mbds,
- mr->details.success.num_mbds
- * sizeof (struct
- TALER_EXCHANGE_MeltBlindingDetail));
+ rms->mbds = GNUNET_new_array (
+ mr->details.ok.num_mbds,
+ struct TALER_EXCHANGE_MeltBlindingDetail);
+ for (unsigned int i = 0; i<mr->details.ok.num_mbds; i++)
+ TALER_denom_ewv_copy (&rms->mbds[i].alg_value,
+ &mr->details.ok.mbds[i].alg_value);
}
if (0 != rms->total_backoff.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Total melt backoff for %s was %s\n",
- rms->is->commands[rms->is->ip].label,
+ rms->cmd->label,
GNUNET_STRINGS_relative_time_to_string (rms->total_backoff,
- GNUNET_YES));
+ true));
}
if (rms->double_melt)
{
TALER_LOG_DEBUG ("Doubling the melt (%s)\n",
- rms->is->commands[rms->is->ip].label);
- rms->rmh = TALER_EXCHANGE_melt (rms->is->exchange,
- &rms->rms,
- &rms->refresh_data,
- &melt_cb,
- rms);
+ rms->cmd->label);
+ rms->rmh = TALER_EXCHANGE_melt (
+ TALER_TESTING_interpreter_get_context (rms->is),
+ TALER_TESTING_get_exchange_url (rms->is),
+ TALER_TESTING_get_keys (rms->is),
+ &rms->rms,
+ &rms->refresh_data,
+ &melt_cb,
+ rms);
rms->double_melt = false;
return;
}
@@ -1011,7 +1029,7 @@ melt_run (void *cls,
};
const char **melt_fresh_amounts;
- (void) cmd;
+ rms->cmd = cmd;
if (NULL == (melt_fresh_amounts = rms->melt_fresh_amounts))
melt_fresh_amounts = default_melt_fresh_amounts;
rms->is = is;
@@ -1028,12 +1046,12 @@ melt_run (void *cls,
{
struct TALER_Amount melt_amount;
struct TALER_Amount fresh_amount;
- const struct TALER_AgeCommitmentProof *age_commitment_proof;
- const struct TALER_AgeCommitmentHash *h_age_commitment;
+ const struct TALER_AgeCommitmentProof *age_commitment_proof = NULL;
+ const struct TALER_AgeCommitmentHash *h_age_commitment = NULL;
const struct TALER_DenominationSignature *melt_sig;
const struct TALER_EXCHANGE_DenomPublicKey *melt_denom_pub;
const struct TALER_TESTING_Command *coin_command;
- bool age_restricted;
+ bool age_restricted_denom;
if (NULL == (coin_command
= TALER_TESTING_interpreter_lookup_command (
@@ -1054,7 +1072,6 @@ melt_run (void *cls,
TALER_TESTING_interpreter_fail (rms->is);
return;
}
-
if (GNUNET_OK !=
TALER_TESTING_get_trait_age_commitment_proof (coin_command,
0,
@@ -1074,7 +1091,6 @@ melt_run (void *cls,
TALER_TESTING_interpreter_fail (rms->is);
return;
}
-
if (GNUNET_OK !=
TALER_TESTING_get_trait_denom_sig (coin_command,
0,
@@ -1084,7 +1100,6 @@ melt_run (void *cls,
TALER_TESTING_interpreter_fail (rms->is);
return;
}
-
if (GNUNET_OK !=
TALER_TESTING_get_trait_denom_pub (coin_command,
0,
@@ -1098,7 +1113,10 @@ melt_run (void *cls,
/* Melt amount starts with the melt fee of the old coin; we'll add the
values and withdraw fees of the fresh coins next */
melt_amount = melt_denom_pub->fees.refresh;
- age_restricted = melt_denom_pub->key.age_mask.bits != 0;
+ age_restricted_denom = melt_denom_pub->key.age_mask.bits != 0;
+ GNUNET_assert (age_restricted_denom == (NULL != age_commitment_proof));
+ GNUNET_assert ((NULL == age_commitment_proof) ||
+ (0 < age_commitment_proof->commitment.num));
for (unsigned int i = 0; i<num_fresh_coins; i++)
{
const struct TALER_EXCHANGE_DenomPublicKey *fresh_pk;
@@ -1115,9 +1133,9 @@ melt_run (void *cls,
TALER_TESTING_interpreter_fail (rms->is);
return;
}
- fresh_pk = TALER_TESTING_find_pk (TALER_EXCHANGE_get_keys (is->exchange),
+ fresh_pk = TALER_TESTING_find_pk (TALER_TESTING_get_keys (rms->is),
&fresh_amount,
- age_restricted);
+ age_restricted_denom);
if (NULL == fresh_pk)
{
GNUNET_break (0);
@@ -1135,27 +1153,46 @@ melt_run (void *cls,
&fresh_pk->fees.withdraw));
rms->fresh_pks[i] = *fresh_pk;
/* Make a deep copy of the RSA key */
- TALER_denom_pub_deep_copy (&rms->fresh_pks[i].key,
- &fresh_pk->key);
+ TALER_denom_pub_copy (&rms->fresh_pks[i].key,
+ &fresh_pk->key);
} /* end for */
rms->refresh_data.melt_priv = *rms->melt_priv;
+ GNUNET_CRYPTO_eddsa_key_get_public (&rms->melt_priv->eddsa_priv,
+ &rms->melt_pub.eddsa_pub);
rms->refresh_data.melt_amount = melt_amount;
rms->refresh_data.melt_sig = *melt_sig;
rms->refresh_data.melt_pk = *melt_denom_pub;
- rms->refresh_data.melt_age_commitment_proof = age_commitment_proof;
- rms->refresh_data.melt_h_age_commitment = h_age_commitment;
+
+ if (NULL != age_commitment_proof)
+ {
+ GNUNET_assert (NULL != h_age_commitment);
+ rms->refresh_data.melt_age_commitment_proof = age_commitment_proof;
+ rms->refresh_data.melt_h_age_commitment = h_age_commitment;
+ }
rms->refresh_data.fresh_pks = rms->fresh_pks;
rms->refresh_data.fresh_pks_len = num_fresh_coins;
- GNUNET_assert (age_restricted ==
+ GNUNET_assert (age_restricted_denom ==
(NULL != age_commitment_proof));
-
- rms->rmh = TALER_EXCHANGE_melt (is->exchange,
- &rms->rms,
- &rms->refresh_data,
- &melt_cb,
- rms);
+ GNUNET_assert ((NULL == age_commitment_proof) ||
+ (0 < age_commitment_proof->commitment.num));
+
+ rms->che.type = TALER_EXCHANGE_CTT_MELT;
+ rms->che.amount = melt_amount;
+ if (NULL != age_commitment_proof)
+ rms->che.details.melt.h_age_commitment = *h_age_commitment;
+ else
+ rms->che.details.melt.no_hac = true;
+
+ rms->rmh = TALER_EXCHANGE_melt (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ &rms->rms,
+ &rms->refresh_data,
+ &melt_cb,
+ rms);
if (NULL == rms->rmh)
{
@@ -1183,10 +1220,8 @@ melt_cleanup (void *cls,
(void) cmd;
if (NULL != rms->rmh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- rms->is->ip,
- rms->is->commands[rms->is->ip].label);
+ TALER_TESTING_command_incomplete (rms->is,
+ cmd->label);
TALER_EXCHANGE_melt_cancel (rms->rmh);
rms->rmh = NULL;
}
@@ -1201,7 +1236,12 @@ melt_cleanup (void *cls,
TALER_denom_pub_free (&rms->fresh_pks[i].key);
GNUNET_free (rms->fresh_pks);
}
- GNUNET_free (rms->mbds);
+ if (NULL != rms->mbds)
+ {
+ for (unsigned int i = 0; i < rms->num_fresh_coins; i++)
+ TALER_denom_ewv_free (&rms->mbds[i].alg_value);
+ GNUNET_free (rms->mbds);
+ }
GNUNET_free (rms->melt_fresh_amounts);
GNUNET_free (rms);
}
@@ -1233,17 +1273,23 @@ melt_traits (void *cls,
struct TALER_TESTING_Trait traits[] = {
TALER_TESTING_make_trait_denom_pub (index,
&rms->fresh_pks[index]),
- TALER_TESTING_make_trait_coin_priv (index,
+ TALER_TESTING_make_trait_coin_priv (0,
rms->melt_priv),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &rms->melt_pub),
+ TALER_TESTING_make_trait_coin_history (0,
+ &rms->che),
TALER_TESTING_make_trait_age_commitment_proof (
index,
rms->refresh_data.melt_age_commitment_proof),
TALER_TESTING_make_trait_h_age_commitment (
index,
rms->refresh_data.melt_h_age_commitment),
- TALER_TESTING_make_trait_exchange_wd_value (index,
- &rms->mbds[index].alg_value),
TALER_TESTING_make_trait_refresh_secret (&rms->rms),
+ (NULL != rms->mbds)
+ ? TALER_TESTING_make_trait_exchange_wd_value (index,
+ &rms->mbds[index].alg_value)
+ : TALER_TESTING_trait_end (),
TALER_TESTING_trait_end ()
};
@@ -1410,7 +1456,7 @@ refresh_reveal_traits (void *cls,
rrs->fresh_coins[index].age_commitment_proof),
TALER_TESTING_make_trait_h_age_commitment (
index,
- rrs->fresh_coins[index].h_age_commitment),
+ &rrs->fresh_coins[index].h_age_commitment),
TALER_TESTING_make_trait_denom_pub (
index,
rrs->fresh_coins[index].pk),
@@ -1428,6 +1474,7 @@ refresh_reveal_traits (void *cls,
&rrs->psa[index]),
TALER_TESTING_trait_end ()
};
+
return TALER_TESTING_get_trait (traits,
ret,
trait,
diff --git a/src/testing/testing_api_cmd_refund.c b/src/testing/testing_api_cmd_refund.c
index 4be3605a4..29b68ef08 100644
--- a/src/testing/testing_api_cmd_refund.c
+++ b/src/testing/testing_api_cmd_refund.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -54,9 +54,14 @@ struct RefundState
uint64_t refund_transaction_id;
/**
- * Connection to the exchange.
+ * Entry in the coin's history generated by this operation.
*/
- struct TALER_EXCHANGE_Handle *exchange;
+ struct TALER_EXCHANGE_CoinHistoryEntry che;
+
+ /**
+ * Public key of the refunded coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin;
/**
* Handle to the refund operation.
@@ -75,38 +80,51 @@ struct RefundState
* response code is acceptable.
*
* @param cls closure
- * @param hr HTTP response details
- * @param exchange_pub public key the exchange
- * used for signing @a obj.
- * @param exchange_sig actual signature confirming the refund
+ * @param rr response details
*/
static void
refund_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_ExchangePublicKeyP *exchange_pub,
- const struct TALER_ExchangeSignatureP *exchange_sig)
+ const struct TALER_EXCHANGE_RefundResponse *rr)
{
-
struct RefundState *rs = cls;
- struct TALER_TESTING_Command *refund_cmd;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rr->hr;
- refund_cmd = &rs->is->commands[rs->is->ip];
rs->rh = NULL;
if (rs->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- hr->ec,
- refund_cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rs->is);
+ TALER_TESTING_unexpected_status (rs->is,
+ hr->http_status,
+ rs->expected_response_code);
return;
}
+ if (MHD_HTTP_OK == hr->http_status)
+ {
+ struct TALER_Amount refund_amount;
+
+ if (GNUNET_OK !=
+ TALER_string_to_amount (rs->refund_amount,
+ &refund_amount))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s'\n",
+ rs->refund_amount);
+ TALER_TESTING_interpreter_fail (rs->is);
+ return;
+ }
+ if (0 >
+ TALER_amount_subtract (&rs->che.amount,
+ &refund_amount,
+ &rs->che.details.refund.refund_fee))
+ {
+ GNUNET_break (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to subtract %s from %s\n",
+ TALER_amount2s (&rs->che.details.refund.refund_fee),
+ rs->refund_amount);
+ TALER_TESTING_interpreter_fail (rs->is);
+ return;
+ }
+ }
TALER_TESTING_interpreter_next (rs->is);
}
@@ -125,24 +143,21 @@ refund_run (void *cls,
{
struct RefundState *rs = cls;
const struct TALER_CoinSpendPrivateKeyP *coin_priv;
- struct TALER_CoinSpendPublicKeyP coin;
const json_t *contract_terms;
struct TALER_PrivateContractHashP h_contract_terms;
struct TALER_Amount refund_amount;
const struct TALER_MerchantPrivateKeyP *merchant_priv;
const struct TALER_TESTING_Command *coin_cmd;
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
- rs->exchange = is->exchange;
rs->is = is;
-
if (GNUNET_OK !=
TALER_string_to_amount (rs->refund_amount,
&refund_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to parse amount `%s' at %u/%s\n",
+ "Failed to parse amount `%s' at %s\n",
rs->refund_amount,
- is->ip,
cmd->label);
TALER_TESTING_interpreter_fail (is);
return;
@@ -168,10 +183,15 @@ refund_run (void *cls,
&h_contract_terms));
/* Hunting for a coin .. */
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_coin_priv (coin_cmd,
- 0,
- &coin_priv))
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (coin_cmd,
+ 0,
+ &coin_priv)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_denom_pub (coin_cmd,
+ 0,
+ &denom_pub)) )
+
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
@@ -179,7 +199,7 @@ refund_run (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
- &coin.eddsa_pub);
+ &rs->coin.eddsa_pub);
if (GNUNET_OK !=
TALER_TESTING_get_trait_merchant_priv (coin_cmd,
&merchant_priv))
@@ -188,19 +208,67 @@ refund_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- rs->rh = TALER_EXCHANGE_refund (rs->exchange,
- &refund_amount,
- &h_contract_terms,
- &coin,
- rs->refund_transaction_id,
- merchant_priv,
- &refund_cb,
- rs);
+ rs->che.type = TALER_EXCHANGE_CTT_REFUND;
+ rs->che.details.refund.h_contract_terms = h_contract_terms;
+ GNUNET_CRYPTO_eddsa_key_get_public (
+ &merchant_priv->eddsa_priv,
+ &rs->che.details.refund.merchant_pub.eddsa_pub);
+ rs->che.details.refund.refund_fee = denom_pub->fees.refund;
+ rs->che.details.refund.sig_amount = refund_amount;
+ rs->che.details.refund.rtransaction_id = rs->refund_transaction_id;
+ TALER_merchant_refund_sign (&rs->coin,
+ &h_contract_terms,
+ rs->refund_transaction_id,
+ &refund_amount,
+ merchant_priv,
+ &rs->che.details.refund.sig);
+ rs->rh = TALER_EXCHANGE_refund (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ &refund_amount,
+ &h_contract_terms,
+ &rs->coin,
+ rs->refund_transaction_id,
+ merchant_priv,
+ &refund_cb,
+ rs);
GNUNET_assert (NULL != rs->rh);
}
/**
+ * Offer internal data from a "refund" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success.
+ */
+static enum GNUNET_GenericReturnValue
+refund_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct RefundState *rs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_coin_history (0,
+ &rs->che),
+ TALER_TESTING_make_trait_coin_pub (0,
+ &rs->coin),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
* Free the state from a "refund" CMD, and possibly cancel
* a pending operation thereof.
*
@@ -215,10 +283,8 @@ refund_cleanup (void *cls,
if (NULL != rs->rh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- rs->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (rs->is,
+ cmd->label);
TALER_EXCHANGE_refund_cancel (rs->rh);
rs->rh = NULL;
}
@@ -243,7 +309,8 @@ TALER_TESTING_cmd_refund (const char *label,
.cls = rs,
.label = label,
.run = &refund_run,
- .cleanup = &refund_cleanup
+ .cleanup = &refund_cleanup,
+ .traits = &refund_traits
};
return cmd;
@@ -271,7 +338,8 @@ TALER_TESTING_cmd_refund_with_id (
.cls = rs,
.label = label,
.run = &refund_run,
- .cleanup = &refund_cleanup
+ .cleanup = &refund_cleanup,
+ .traits = &refund_traits
};
return cmd;
diff --git a/src/testing/testing_api_cmd_reserve_attest.c b/src/testing/testing_api_cmd_reserve_attest.c
new file mode 100644
index 000000000..cf4b3a0c2
--- /dev/null
+++ b/src/testing/testing_api_cmd_reserve_attest.c
@@ -0,0 +1,263 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_reserve_attest.c
+ * @brief Implement the /reserve/$RID/attest test command.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+/**
+ * State for a "attest" CMD.
+ */
+struct AttestState
+{
+ /**
+ * Label to the command which created the reserve to check,
+ * needed to resort the reserve key.
+ */
+ const char *reserve_reference;
+
+ /**
+ * Handle to the "reserve attest" operation.
+ */
+ struct TALER_EXCHANGE_ReservesAttestHandle *rsh;
+
+ /**
+ * Private key of the reserve being analyzed.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
+ * Public key of the reserve being analyzed.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Array of attributes to request, of length @e attrs_len.
+ */
+ const char **attrs;
+
+ /**
+ * Length of the @e attrs array.
+ */
+ unsigned int attrs_len;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /* TODO: expose fields below as traits... */
+
+ /**
+ * Attested attributes returned by the exchange.
+ */
+ json_t *attributes;
+
+ /**
+ * Expiration time of the attested attributes.
+ */
+ struct GNUNET_TIME_Timestamp expiration_time;
+
+ /**
+ * Signature by the exchange affirming the attributes.
+ */
+ struct TALER_ExchangeSignatureP exchange_sig;
+
+ /**
+ * Online signing key used by the exchange.
+ */
+ struct TALER_ExchangePublicKeyP exchange_pub;
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rs HTTP response details
+ */
+static void
+reserve_attest_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ReservePostAttestResult *rs)
+{
+ struct AttestState *ss = cls;
+ struct TALER_TESTING_Interpreter *is = ss->is;
+
+ ss->rsh = NULL;
+ if (ss->expected_response_code != rs->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected HTTP response code: %d in %s:%u\n",
+ rs->hr.http_status,
+ __FILE__,
+ __LINE__);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ if (MHD_HTTP_OK != rs->hr.http_status)
+ {
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ ss->attributes = json_incref ((json_t*) rs->details.ok.attributes);
+ ss->expiration_time = rs->details.ok.expiration_time;
+ ss->exchange_pub = rs->details.ok.exchange_pub;
+ ss->exchange_sig = rs->details.ok.exchange_sig;
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+attest_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AttestState *ss = cls;
+ const struct TALER_TESTING_Command *create_reserve;
+ const char *exchange_url;
+
+ ss->is = is;
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ create_reserve
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ss->reserve_reference);
+
+ if (NULL == create_reserve)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_priv (create_reserve,
+ &ss->reserve_priv))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Failed to find reserve_priv for attest query\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv,
+ &ss->reserve_pub.eddsa_pub);
+ ss->rsh = TALER_EXCHANGE_reserves_attest (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ TALER_TESTING_get_keys (is),
+ ss->reserve_priv,
+ ss->attrs_len,
+ ss->attrs,
+ &reserve_attest_cb,
+ ss);
+}
+
+
+/**
+ * Cleanup the state from a "reserve attest" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+attest_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AttestState *ss = cls;
+
+ if (NULL != ss->rsh)
+ {
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ TALER_EXCHANGE_reserves_attest_cancel (ss->rsh);
+ ss->rsh = NULL;
+ }
+ json_decref (ss->attributes);
+ GNUNET_free (ss->attrs);
+ GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_attest (const char *label,
+ const char *reserve_reference,
+ unsigned int expected_response_code,
+ ...)
+{
+ struct AttestState *ss;
+ unsigned int num_args;
+ const char *ea;
+ va_list ap;
+
+ num_args = 0;
+ va_start (ap, expected_response_code);
+ while (NULL != va_arg (ap, const char *))
+ num_args++;
+ va_end (ap);
+
+ GNUNET_assert (NULL != reserve_reference);
+ ss = GNUNET_new (struct AttestState);
+ ss->reserve_reference = reserve_reference;
+ ss->expected_response_code = expected_response_code;
+ ss->attrs_len = num_args;
+ ss->attrs = GNUNET_new_array (num_args,
+ const char *);
+ num_args = 0;
+ va_start (ap, expected_response_code);
+ while (NULL != (ea = va_arg (ap, const char *)))
+ ss->attrs[num_args++] = ea;
+ va_end (ap);
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &attest_run,
+ .cleanup = &attest_cleanup
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_reserve_close.c b/src/testing/testing_api_cmd_reserve_close.c
new file mode 100644
index 000000000..8e272f547
--- /dev/null
+++ b/src/testing/testing_api_cmd_reserve_close.c
@@ -0,0 +1,260 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_reserve_close.c
+ * @brief Implement the /reserve/$RID/close test command.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "close" CMD.
+ */
+struct CloseState
+{
+ /**
+ * Label to the command which created the reserve to check,
+ * needed to resort the reserve key.
+ */
+ const char *reserve_reference;
+
+ /**
+ * Handle to the "reserve close" operation.
+ */
+ struct TALER_EXCHANGE_ReservesCloseHandle *rsh;
+
+ /**
+ * payto://-URI where to wire the funds.
+ */
+ const char *target_account;
+
+ /**
+ * Private key of the reserve being analyzed.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
+ * Public key of the reserve being analyzed.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
+ * a request for KYC.
+ */
+ uint64_t requirement_row;
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rs HTTP response details
+ */
+static void
+reserve_close_cb (void *cls,
+ const struct TALER_EXCHANGE_ReserveCloseResult *rs)
+{
+ struct CloseState *ss = cls;
+ struct TALER_TESTING_Interpreter *is = ss->is;
+
+ ss->rsh = NULL;
+ if (ss->expected_response_code != rs->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected HTTP response code: %d in %s:%u\n",
+ rs->hr.http_status,
+ __FILE__,
+ __LINE__);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ switch (rs->hr.http_status)
+ {
+ case MHD_HTTP_OK:
+ break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* nothing to check */
+ ss->requirement_row
+ = rs->details.unavailable_for_legal_reasons.requirement_row;
+ ss->h_payto
+ = rs->details.unavailable_for_legal_reasons.h_payto;
+ break;
+ default:
+ break;
+ }
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+close_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct CloseState *ss = cls;
+ const struct TALER_TESTING_Command *create_reserve;
+
+ ss->is = is;
+ create_reserve
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ss->reserve_reference);
+
+ if (NULL == create_reserve)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_priv (create_reserve,
+ &ss->reserve_priv))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Failed to find reserve_priv for close query\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv,
+ &ss->reserve_pub.eddsa_pub);
+ ss->rsh = TALER_EXCHANGE_reserves_close (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ ss->reserve_priv,
+ ss->target_account,
+ &reserve_close_cb,
+ ss);
+}
+
+
+/**
+ * Cleanup the state from a "reserve close" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+close_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct CloseState *ss = cls;
+
+ if (NULL != ss->rsh)
+ {
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ TALER_EXCHANGE_reserves_close_cancel (ss->rsh);
+ ss->rsh = NULL;
+ }
+ GNUNET_free (ss);
+}
+
+
+/**
+ * Offer internal data to a "close" CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+close_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct CloseState *cs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_legi_requirement_row (
+ &cs->requirement_row),
+ TALER_TESTING_make_trait_h_payto (
+ &cs->h_payto),
+ TALER_TESTING_trait_end ()
+ };
+
+ if (cs->expected_response_code != MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS)
+ return GNUNET_NO;
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_close (const char *label,
+ const char *reserve_reference,
+ const char *target_account,
+ unsigned int expected_response_code)
+{
+ struct CloseState *ss;
+
+ GNUNET_assert (NULL != reserve_reference);
+ ss = GNUNET_new (struct CloseState);
+ ss->reserve_reference = reserve_reference;
+ ss->target_account = target_account;
+ ss->expected_response_code = expected_response_code;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &close_run,
+ .cleanup = &close_cleanup,
+ .traits = &close_traits
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_reserve_get.c b/src/testing/testing_api_cmd_reserve_get.c
index f9b8ff6cd..9a938cf82 100644
--- a/src/testing/testing_api_cmd_reserve_get.c
+++ b/src/testing/testing_api_cmd_reserve_get.c
@@ -178,18 +178,19 @@ status_run (void *cls,
{
struct StatusState *ss = cls;
const struct TALER_TESTING_Command *create_reserve;
+ const char *exchange_url;
ss->is = is;
- create_reserve
- = TALER_TESTING_interpreter_lookup_command (is,
- ss->reserve_reference);
-
- if (NULL == create_reserve)
+ exchange_url = TALER_TESTING_get_exchange_url (is);
+ if (NULL == exchange_url)
{
GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
return;
}
+ create_reserve
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ss->reserve_reference);
+ GNUNET_assert (NULL != create_reserve);
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_pub (create_reserve,
&ss->reserve_pubp))
@@ -199,11 +200,13 @@ status_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
- ss->rsh = TALER_EXCHANGE_reserves_get (is->exchange,
- ss->reserve_pubp,
- ss->timeout,
- &reserve_status_cb,
- ss);
+ ss->rsh = TALER_EXCHANGE_reserves_get (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ ss->reserve_pubp,
+ ss->timeout,
+ &reserve_status_cb,
+ ss);
if (! GNUNET_TIME_relative_is_zero (ss->timeout))
{
TALER_TESTING_interpreter_next (is);
@@ -227,10 +230,8 @@ status_cleanup (void *cls,
if (NULL != ss->rsh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ss->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
TALER_EXCHANGE_reserves_get_cancel (ss->rsh);
ss->rsh = NULL;
}
@@ -328,6 +329,7 @@ finish_run (void *cls,
poll_reserve
= TALER_TESTING_interpreter_lookup_command (is,
ps->poll_reference);
+ GNUNET_assert (NULL != poll_reserve);
GNUNET_assert (poll_reserve->run == &status_run);
ss = poll_reserve->cls;
if (NULL == ss->rsh)
diff --git a/src/testing/testing_api_cmd_reserve_get_attestable.c b/src/testing/testing_api_cmd_reserve_get_attestable.c
new file mode 100644
index 000000000..ed1eb1355
--- /dev/null
+++ b/src/testing/testing_api_cmd_reserve_get_attestable.c
@@ -0,0 +1,242 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_reserve_get_attestable.c
+ * @brief Implement the /reserve/$RID/get_attestable test command.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "get_attestable" CMD.
+ */
+struct GetAttestableState
+{
+ /**
+ * Label to the command which created the reserve to check,
+ * needed to resort the reserve key.
+ */
+ const char *reserve_reference;
+
+ /**
+ * Handle to the "reserve get_attestable" operation.
+ */
+ struct TALER_EXCHANGE_ReservesGetAttestHandle *rgah;
+
+ /**
+ * Expected attestable attributes.
+ */
+ const char **expected_attestables;
+
+ /**
+ * Length of the @e expected_attestables array.
+ */
+ unsigned int expected_attestables_length;
+
+ /**
+ * Public key of the reserve being analyzed.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rs HTTP response details
+ */
+static void
+reserve_get_attestable_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_ReserveGetAttestResult *rs)
+{
+ struct GetAttestableState *ss = cls;
+ struct TALER_TESTING_Interpreter *is = ss->is;
+
+ ss->rgah = NULL;
+ if (ss->expected_response_code != rs->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected HTTP response code: %d in %s:%u\n",
+ rs->hr.http_status,
+ __FILE__,
+ __LINE__);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ if (MHD_HTTP_OK != rs->hr.http_status)
+ {
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ // FIXME: check returned list matches expectations!
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+get_attestable_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct GetAttestableState *ss = cls;
+ const struct TALER_TESTING_Command *ref_reserve;
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+ const char *exchange_url;
+
+ 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);
+
+ if (NULL == ref_reserve)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK ==
+ TALER_TESTING_get_trait_reserve_priv (ref_reserve,
+ &reserve_priv))
+ {
+ GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
+ &ss->reserve_pub.eddsa_pub);
+ }
+ else
+ {
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_pub (ref_reserve,
+ &reserve_pub))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR (
+ "Failed to find reserve_priv for get_attestable query\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ ss->reserve_pub = *reserve_pub;
+ }
+ ss->rgah = TALER_EXCHANGE_reserves_get_attestable (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ &ss->reserve_pub,
+ &reserve_get_attestable_cb,
+ ss);
+}
+
+
+/**
+ * Cleanup the state from a "reserve get_attestable" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+get_attestable_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct GetAttestableState *ss = cls;
+
+ if (NULL != ss->rgah)
+ {
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ TALER_EXCHANGE_reserves_get_attestable_cancel (ss->rgah);
+ ss->rgah = NULL;
+ }
+ GNUNET_free (ss->expected_attestables);
+ GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_get_attestable (const char *label,
+ const char *reserve_reference,
+ unsigned int expected_response_code,
+ ...)
+{
+ struct GetAttestableState *ss;
+ va_list ap;
+ unsigned int num_expected;
+ const char *ea;
+
+ num_expected = 0;
+ va_start (ap, expected_response_code);
+ while (NULL != va_arg (ap, const char *))
+ num_expected++;
+ va_end (ap);
+
+ GNUNET_assert (NULL != reserve_reference);
+ ss = GNUNET_new (struct GetAttestableState);
+ ss->reserve_reference = reserve_reference;
+ ss->expected_response_code = expected_response_code;
+ ss->expected_attestables_length = num_expected;
+ ss->expected_attestables = GNUNET_new_array (num_expected,
+ const char *);
+ num_expected = 0;
+ va_start (ap, expected_response_code);
+ while (NULL != (ea = va_arg (ap, const char *)))
+ ss->expected_attestables[num_expected++] = ea;
+ va_end (ap);
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &get_attestable_run,
+ .cleanup = &get_attestable_cleanup
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_reserve_history.c b/src/testing/testing_api_cmd_reserve_history.c
index beba23f11..ecb236a54 100644
--- a/src/testing/testing_api_cmd_reserve_history.c
+++ b/src/testing/testing_api_cmd_reserve_history.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2022 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -65,42 +65,223 @@ struct HistoryState
struct TALER_TESTING_Interpreter *is;
/**
- * Reserve history entry that corresponds to this operation.
- * Will be of type #TALER_EXCHANGE_RTT_HISTORY.
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+};
+
+
+/**
+ * Closure for analysis_cb().
+ */
+struct AnalysisContext
+{
+ /**
+ * Reserve public key we are looking at.
*/
- struct TALER_EXCHANGE_ReserveHistoryEntry reserve_history;
+ const struct TALER_ReservePublicKeyP *reserve_pub;
/**
- * Expected HTTP response code.
+ * Length of the @e history array.
*/
- unsigned int expected_response_code;
+ unsigned int history_length;
+ /**
+ * Array of history items to match.
+ */
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *history;
+
+ /**
+ * Array of @e history_length of matched entries.
+ */
+ bool *found;
+
+ /**
+ * Set to true if an entry could not be found.
+ */
+ bool failure;
};
/**
+ * Compare @a h1 and @a h2.
+ *
+ * @param h1 a history entry
+ * @param h2 a history entry
+ * @return 0 if @a h1 and @a h2 are equal
+ */
+static int
+history_entry_cmp (
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *h1,
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *h2)
+{
+ if (h1->type != h2->type)
+ return 1;
+ switch (h1->type)
+ {
+ case TALER_EXCHANGE_RTT_CREDIT:
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 == strcasecmp (h1->details.in_details.sender_url,
+ h2->details.in_details.sender_url)) &&
+ (h1->details.in_details.wire_reference ==
+ h2->details.in_details.wire_reference) &&
+ (GNUNET_TIME_timestamp_cmp (h1->details.in_details.timestamp,
+ ==,
+ h2->details.in_details.timestamp)) )
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_WITHDRAWAL:
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 ==
+ TALER_amount_cmp (&h1->details.withdraw.fee,
+ &h2->details.withdraw.fee)) )
+ /* testing_api_cmd_withdraw doesn't set the out_authorization_sig,
+ so we cannot test for it here. but if the amount matches,
+ that should be good enough. */
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_AGEWITHDRAWAL:
+ /* testing_api_cmd_age_withdraw doesn't set the out_authorization_sig,
+ so we cannot test for it here. but if the amount matches,
+ that should be good enough. */
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 ==
+ TALER_amount_cmp (&h1->details.age_withdraw.fee,
+ &h2->details.age_withdraw.fee)) &&
+ (h1->details.age_withdraw.max_age ==
+ h2->details.age_withdraw.max_age))
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_RECOUP:
+ /* exchange_sig, exchange_pub and timestamp are NOT available
+ from the original recoup response, hence here NOT check(able/ed) */
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.recoup_details.coin_pub,
+ &h2->details.recoup_details.coin_pub)) )
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_CLOSING:
+ /* testing_api_cmd_exec_closer doesn't set the
+ receiver_account_details, exchange_sig, exchange_pub or wtid or timestamp
+ so we cannot test for it here. but if the amount matches,
+ that should be good enough. */
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 ==
+ TALER_amount_cmp (&h1->details.close_details.fee,
+ &h2->details.close_details.fee)) )
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_MERGE:
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (0 ==
+ TALER_amount_cmp (&h1->details.merge_details.purse_fee,
+ &h2->details.merge_details.purse_fee)) &&
+ (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.merge_timestamp,
+ ==,
+ h2->details.merge_details.merge_timestamp))
+ &&
+ (GNUNET_TIME_timestamp_cmp (h1->details.merge_details.purse_expiration,
+ ==,
+ h2->details.merge_details.purse_expiration))
+ &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.merge_details.merge_pub,
+ &h2->details.merge_details.merge_pub)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.merge_details.h_contract_terms,
+ &h2->details.merge_details.h_contract_terms)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.merge_details.purse_pub,
+ &h2->details.merge_details.purse_pub)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.merge_details.reserve_sig,
+ &h2->details.merge_details.reserve_sig)) &&
+ (h1->details.merge_details.min_age ==
+ h2->details.merge_details.min_age) &&
+ (h1->details.merge_details.flags ==
+ h2->details.merge_details.flags) )
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_OPEN:
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (GNUNET_TIME_timestamp_cmp (
+ h1->details.open_request.request_timestamp,
+ ==,
+ h2->details.open_request.request_timestamp)) &&
+ (GNUNET_TIME_timestamp_cmp (
+ h1->details.open_request.reserve_expiration,
+ ==,
+ h2->details.open_request.reserve_expiration)) &&
+ (h1->details.open_request.purse_limit ==
+ h2->details.open_request.purse_limit) &&
+ (0 ==
+ TALER_amount_cmp (&h1->details.open_request.reserve_payment,
+ &h2->details.open_request.reserve_payment)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.open_request.reserve_sig,
+ &h2->details.open_request.reserve_sig)) )
+ return 0;
+ return 1;
+ case TALER_EXCHANGE_RTT_CLOSE:
+ if ( (0 ==
+ TALER_amount_cmp (&h1->amount,
+ &h2->amount)) &&
+ (GNUNET_TIME_timestamp_cmp (
+ h1->details.close_request.request_timestamp,
+ ==,
+ h2->details.close_request.request_timestamp)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.close_request.target_account_h_payto,
+ &h2->details.close_request.target_account_h_payto)) &&
+ (0 ==
+ GNUNET_memcmp (&h1->details.close_request.reserve_sig,
+ &h2->details.close_request.reserve_sig)) )
+ return 0;
+ return 1;
+ }
+ GNUNET_assert (0);
+ return 1;
+}
+
+
+/**
* Check if @a cmd changed the reserve, if so, find the
- * entry in @a history and set the respective index in @a found
- * to #GNUNET_YES. If the entry is not found, return #GNUNET_SYSERR.
+ * entry in our history and set the respective index in found
+ * to true. If the entry is not found, set failure.
*
- * @param reserve_pub public key of the reserve for which we have the @a history
+ * @param cls our `struct AnalysisContext *`
* @param cmd command to analyze for impact on history
- * @param history_length number of entries in @a history and @a found
- * @param history history to check
- * @param[in,out] found array to update
- * @return #GNUNET_OK if @a cmd action on reserve was found in @a history
*/
-static enum GNUNET_GenericReturnValue
-analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_TESTING_Command *cmd,
- unsigned int history_length,
- const struct TALER_EXCHANGE_ReserveHistoryEntry *history,
- bool *found)
+static void
+analyze_command (void *cls,
+ const struct TALER_TESTING_Command *cmd)
{
+ struct AnalysisContext *ac = cls;
+ const struct TALER_ReservePublicKeyP *reserve_pub = ac->reserve_pub;
+ const struct TALER_EXCHANGE_ReserveHistoryEntry *history = ac->history;
+ unsigned int history_length = ac->history_length;
+ bool *found = ac->found;
+
if (TALER_TESTING_cmd_is_batch (cmd))
{
struct TALER_TESTING_Command *cur;
- struct TALER_TESTING_Command **bcmd;
+ struct TALER_TESTING_Command *bcmd;
cur = TALER_TESTING_cmd_batch_get_current (cmd);
if (GNUNET_OK !=
@@ -108,28 +289,26 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
&bcmd))
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ ac->failure = true;
+ return;
}
- for (unsigned int i = 0; NULL != (*bcmd)[i].label; i++)
+ for (unsigned int i = 0; NULL != bcmd[i].label; i++)
{
- struct TALER_TESTING_Command *step = &(*bcmd)[i];
+ struct TALER_TESTING_Command *step = &bcmd[i];
- if (GNUNET_OK !=
- analyze_command (reserve_pub,
- step,
- history_length,
- history,
- found))
+ analyze_command (ac,
+ step);
+ if (ac->failure)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Entry for batch step `%s' missing in history\n",
step->label);
- return GNUNET_SYSERR;
+ return;
}
if (step == cur)
break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */
}
- return GNUNET_OK;
+ return;
}
{
@@ -138,11 +317,11 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_pub (cmd,
&rp))
- return GNUNET_OK; /* command does nothing for reserves */
+ return; /* command does nothing for reserves */
if (0 !=
GNUNET_memcmp (rp,
reserve_pub))
- return GNUNET_OK; /* command affects some _other_ reserve */
+ return; /* command affects some _other_ reserve */
for (unsigned int j = 0; true; j++)
{
const struct TALER_EXCHANGE_ReserveHistoryEntry *he;
@@ -156,17 +335,17 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
/* NOTE: only for debugging... */
if (0 == j)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Command `%s' has the reserve_pub trait, but does not reserve history trait\n",
+ "Command `%s' has the reserve_pub, but lacks reserve history trait\n",
cmd->label);
- return GNUNET_OK; /* command does nothing for reserves */
+ return; /* command does nothing for reserves */
}
for (unsigned int i = 0; i<history_length; i++)
{
if (found[i])
continue; /* already found, skip */
if (0 ==
- TALER_TESTING_history_entry_cmp (he,
- &history[i]))
+ history_entry_cmp (he,
+ &history[i]))
{
found[i] = true;
matched = true;
@@ -179,7 +358,8 @@ analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
"Command `%s' reserve history entry #%u not found\n",
cmd->label,
j);
- return GNUNET_SYSERR;
+ ac->failure = true;
+ return;
}
}
}
@@ -202,21 +382,6 @@ reserve_history_cb (void *cls,
struct TALER_Amount eb;
ss->rsh = NULL;
- if (MHD_HTTP_OK == rs->hr.http_status)
- {
- const struct TALER_EXCHANGE_Keys *keys;
- const struct TALER_EXCHANGE_GlobalFee *gf;
-
- ss->reserve_history.type = TALER_EXCHANGE_RTT_HISTORY;
- keys = TALER_EXCHANGE_get_keys (ss->is->exchange);
- GNUNET_assert (NULL != keys);
- gf = TALER_EXCHANGE_get_global_fee (keys,
- rs->ts);
- GNUNET_assert (NULL != gf);
- ss->reserve_history.amount = gf->fees.history;
- ss->reserve_history.details.history_details.request_timestamp = rs->ts;
- ss->reserve_history.details.history_details.reserve_sig = *rs->reserve_sig;
- }
if (ss->expected_response_code != rs->hr.http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -254,44 +419,42 @@ reserve_history_cb (void *cls,
}
{
bool found[rs->details.ok.history_len];
+ struct AnalysisContext ac = {
+ .reserve_pub = &ss->reserve_pub,
+ .history = rs->details.ok.history,
+ .history_length = rs->details.ok.history_len,
+ .found = found
+ };
memset (found,
0,
sizeof (found));
- for (unsigned int i = 0; i<= (unsigned int) is->ip; i++)
+ TALER_TESTING_iterate (is,
+ true,
+ &analyze_command,
+ &ac);
+ if (ac.failure)
{
- struct TALER_TESTING_Command *cmd = &is->commands[i];
-
- if (GNUNET_OK !=
- analyze_command (&ss->reserve_pub,
- cmd,
- rs->details.ok.history_len,
- rs->details.ok.history,
- found))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Entry for command `%s' missing in history\n",
- cmd->label);
- json_dumpf (rs->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
}
for (unsigned int i = 0; i<rs->details.ok.history_len; i++)
- if (! found[i])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "History entry at index %u of type %d not justified by command history\n",
- i,
- rs->details.ok.history[i].type);
- json_dumpf (rs->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
+ {
+ if (found[i])
+ continue;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "History entry at index %u of type %d not justified by command history\n",
+ i,
+ rs->details.ok.history[i].type);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
}
TALER_TESTING_interpreter_next (is);
}
@@ -333,10 +496,14 @@ history_run (void *cls,
}
GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv,
&ss->reserve_pub.eddsa_pub);
- ss->rsh = TALER_EXCHANGE_reserves_history (is->exchange,
- ss->reserve_priv,
- &reserve_history_cb,
- ss);
+ ss->rsh = TALER_EXCHANGE_reserves_history (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ ss->reserve_priv,
+ 0,
+ &reserve_history_cb,
+ ss);
}
@@ -357,16 +524,11 @@ history_traits (void *cls,
{
struct HistoryState *hs = cls;
struct TALER_TESTING_Trait traits[] = {
- /* history entry MUST be first due to response code logic below! */
- TALER_TESTING_make_trait_reserve_history (0,
- &hs->reserve_history),
TALER_TESTING_make_trait_reserve_pub (&hs->reserve_pub),
TALER_TESTING_trait_end ()
};
- return TALER_TESTING_get_trait ((hs->expected_response_code == MHD_HTTP_OK)
- ? &traits[0] /* we have reserve history */
- : &traits[1], /* skip reserve history */
+ return TALER_TESTING_get_trait (traits,
ret,
trait,
index);
@@ -388,10 +550,8 @@ history_cleanup (void *cls,
if (NULL != ss->rsh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ss->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
TALER_EXCHANGE_reserves_history_cancel (ss->rsh);
ss->rsh = NULL;
}
diff --git a/src/testing/testing_api_cmd_reserve_open.c b/src/testing/testing_api_cmd_reserve_open.c
new file mode 100644
index 000000000..189d06b26
--- /dev/null
+++ b/src/testing/testing_api_cmd_reserve_open.c
@@ -0,0 +1,349 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2014-2022 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_reserve_open.c
+ * @brief Implement the /reserve/$RID/open test command.
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+
+/**
+ * Information we track per coin used to pay for opening the
+ * reserve.
+ */
+struct CoinDetail
+{
+ /**
+ * Name of the command and index of the coin to use.
+ */
+ const char *name;
+
+ /**
+ * Amount to charge to this coin.
+ */
+ struct TALER_Amount amount;
+};
+
+
+/**
+ * State for a "open" CMD.
+ */
+struct OpenState
+{
+ /**
+ * Label to the command which created the reserve to check,
+ * needed to resort the reserve key.
+ */
+ const char *reserve_reference;
+
+ /**
+ * Requested expiration time.
+ */
+ struct GNUNET_TIME_Relative req_expiration_time;
+
+ /**
+ * Requested minimum number of purses.
+ */
+ uint32_t min_purses;
+
+ /**
+ * Amount to pay for the opening from the reserve balance.
+ */
+ struct TALER_Amount reserve_pay;
+
+ /**
+ * Handle to the "reserve open" operation.
+ */
+ struct TALER_EXCHANGE_ReservesOpenHandle *rsh;
+
+ /**
+ * Expected reserve balance.
+ */
+ const char *expected_balance;
+
+ /**
+ * Length of the @e cd array.
+ */
+ unsigned int cpl;
+
+ /**
+ * Coin details, array of length @e cpl.
+ */
+ struct CoinDetail *cd;
+
+ /**
+ * Private key of the reserve being analyzed.
+ */
+ const struct TALER_ReservePrivateKeyP *reserve_priv;
+
+ /**
+ * Public key of the reserve being analyzed.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Expected HTTP response code.
+ */
+ unsigned int expected_response_code;
+
+ /**
+ * Interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+};
+
+
+/**
+ * Check that the reserve balance and HTTP response code are
+ * both acceptable.
+ *
+ * @param cls closure.
+ * @param rs HTTP response details
+ */
+static void
+reserve_open_cb (void *cls,
+ const struct TALER_EXCHANGE_ReserveOpenResult *rs)
+{
+ struct OpenState *ss = cls;
+ struct TALER_TESTING_Interpreter *is = ss->is;
+
+ ss->rsh = NULL;
+ if (ss->expected_response_code != rs->hr.http_status)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected HTTP response code: %d in %s:%u\n",
+ rs->hr.http_status,
+ __FILE__,
+ __LINE__);
+ json_dumpf (rs->hr.reply,
+ stderr,
+ JSON_INDENT (2));
+ TALER_TESTING_interpreter_fail (ss->is);
+ return;
+ }
+ if (MHD_HTTP_OK != rs->hr.http_status)
+ {
+ TALER_TESTING_interpreter_next (is);
+ return;
+ }
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+open_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct OpenState *ss = cls;
+ const struct TALER_TESTING_Command *create_reserve;
+ struct TALER_EXCHANGE_PurseDeposit cp[GNUNET_NZL (ss->cpl)];
+
+ ss->is = is;
+ create_reserve
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ss->reserve_reference);
+
+ if (NULL == create_reserve)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_reserve_priv (create_reserve,
+ &ss->reserve_priv))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Failed to find reserve_priv for open query\n");
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv,
+ &ss->reserve_pub.eddsa_pub);
+ for (unsigned int i = 0; i<ss->cpl; i++)
+ {
+ struct TALER_EXCHANGE_PurseDeposit *cpi = &cp[i];
+ const struct TALER_TESTING_Command *cmdi;
+ const struct TALER_AgeCommitmentProof *age_commitment_proof;
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv;
+ const struct TALER_DenominationSignature *denom_sig;
+ const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
+ char *cref;
+ unsigned int cidx;
+
+ if (GNUNET_OK !=
+ TALER_TESTING_parse_coin_reference (ss->cd[i].name,
+ &cref,
+ &cidx))
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Failed to parse coin reference `%s'\n",
+ ss->cd[i].name);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ cmdi = TALER_TESTING_interpreter_lookup_command (is,
+ cref);
+ GNUNET_free (cref);
+ if (NULL == cmdi)
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Command `%s' not found\n",
+ ss->cd[i].name);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if ( (GNUNET_OK !=
+ TALER_TESTING_get_trait_age_commitment_proof (cmdi,
+ cidx,
+ &age_commitment_proof))
+ ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_coin_priv (cmdi,
+ cidx,
+ &coin_priv)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_denom_sig (cmdi,
+ cidx,
+ &denom_sig)) ||
+ (GNUNET_OK !=
+ TALER_TESTING_get_trait_denom_pub (cmdi,
+ cidx,
+ &denom_pub)) )
+ {
+ GNUNET_break (0);
+ TALER_LOG_ERROR ("Coin trait not found in `%s'\n",
+ ss->cd[i].name);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ cpi->age_commitment_proof = age_commitment_proof;
+ cpi->coin_priv = *coin_priv;
+ cpi->denom_sig = *denom_sig;
+ cpi->amount = ss->cd[i].amount;
+ cpi->h_denom_pub = denom_pub->h_key;
+ }
+ ss->rsh = TALER_EXCHANGE_reserves_open (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ ss->reserve_priv,
+ &ss->reserve_pay,
+ ss->cpl,
+ cp,
+ GNUNET_TIME_relative_to_timestamp (ss->req_expiration_time),
+ ss->min_purses,
+ &reserve_open_cb,
+ ss);
+}
+
+
+/**
+ * Cleanup the state from a "reserve open" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+open_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct OpenState *ss = cls;
+
+ if (NULL != ss->rsh)
+ {
+ TALER_TESTING_command_incomplete (ss->is,
+ cmd->label);
+ TALER_EXCHANGE_reserves_open_cancel (ss->rsh);
+ ss->rsh = NULL;
+ }
+ GNUNET_free (ss);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_reserve_open (const char *label,
+ const char *reserve_reference,
+ const char *reserve_pay,
+ struct GNUNET_TIME_Relative expiration_time,
+ uint32_t min_purses,
+ unsigned int expected_response_code,
+ ...)
+{
+ struct OpenState *ss;
+ va_list ap;
+ const char *name;
+ unsigned int i;
+
+ GNUNET_assert (NULL != reserve_reference);
+ ss = GNUNET_new (struct OpenState);
+ ss->reserve_reference = reserve_reference;
+ ss->req_expiration_time = expiration_time;
+ ss->min_purses = min_purses;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (reserve_pay,
+ &ss->reserve_pay));
+ ss->expected_response_code = expected_response_code;
+ va_start (ap,
+ expected_response_code);
+ while (NULL != (name = va_arg (ap, const char *)))
+ ss->cpl++;
+ va_end (ap);
+ GNUNET_assert (0 == (ss->cpl % 2));
+ ss->cpl /= 2; /* name and amount per coin */
+ ss->cd = GNUNET_new_array (ss->cpl,
+ struct CoinDetail);
+ i = 0;
+ va_start (ap,
+ expected_response_code);
+ while (NULL != (name = va_arg (ap, const char *)))
+ {
+ struct CoinDetail *cd = &ss->cd[i];
+ cd->name = name;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (va_arg (ap,
+ const char *),
+ &cd->amount));
+ i++;
+ }
+ va_end (ap);
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &open_run,
+ .cleanup = &open_cleanup
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_reserve_purse.c b/src/testing/testing_api_cmd_reserve_purse.c
index 488790888..ef6964f26 100644
--- a/src/testing/testing_api_cmd_reserve_purse.c
+++ b/src/testing/testing_api_cmd_reserve_purse.c
@@ -98,6 +98,18 @@ struct ReservePurseState
struct GNUNET_TIME_Timestamp purse_expiration;
/**
+ * Hash of the payto://-URI for the reserve we are
+ * merging into.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
+ * a request for KYC.
+ */
+ uint64_t requirement_row;
+
+ /**
* Contract terms for the purse.
*/
json_t *contract_terms;
@@ -117,6 +129,10 @@ struct ReservePurseState
*/
unsigned int expected_response_code;
+ /**
+ * True to pay the purse fee.
+ */
+ bool pay_purse_fee;
};
@@ -137,18 +153,19 @@ purse_cb (void *cls,
ds->reserve_sig = *dr->reserve_sig;
if (ds->expected_response_code != dr->hr.http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- dr->hr.http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (dr->hr.reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ dr->hr.http_status,
+ ds->expected_response_code);
return;
}
+ switch (dr->hr.http_status)
+ {
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* KYC required */
+ ds->requirement_row =
+ dr->details.unavailable_for_legal_reasons.requirement_row;
+ break;
+ }
TALER_TESTING_interpreter_next (ds->is);
}
@@ -194,6 +211,30 @@ purse_run (void *cls,
GNUNET_CRYPTO_ecdhe_key_create (&ds->contract_priv.ecdhe_priv);
ds->purse_expiration = GNUNET_TIME_absolute_to_timestamp (
GNUNET_TIME_relative_to_absolute (ds->expiration_rel));
+
+ {
+ char *payto_uri;
+ const char *exchange_url;
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ payto_uri = TALER_reserve_make_payto (exchange_url,
+ &ds->reserve_pub);
+ TALER_payto_hash (payto_uri,
+ &ds->h_payto);
+ GNUNET_free (payto_uri);
+ }
+
GNUNET_assert (0 ==
json_object_set_new (
ds->contract_terms,
@@ -201,14 +242,16 @@ purse_run (void *cls,
GNUNET_JSON_from_timestamp (ds->purse_expiration)));
ds->merge_timestamp = GNUNET_TIME_timestamp_get ();
ds->dh = TALER_EXCHANGE_purse_create_with_merge (
- is->exchange,
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
&ds->reserve_priv,
&ds->purse_priv,
&ds->merge_priv,
&ds->contract_priv,
ds->contract_terms,
true /* upload contract */,
- true /* do pay purse fee -- FIXME: make this a choice to test this case; then update testing_api_cmd_purse_deposit flags logic to match! */,
+ ds->pay_purse_fee,
ds->merge_timestamp,
&purse_cb,
ds);
@@ -238,10 +281,8 @@ purse_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_purse_create_with_merge_cancel (ds->dh);
ds->dh = NULL;
}
@@ -278,6 +319,8 @@ purse_traits (void *cls,
TALER_TESTING_make_trait_reserve_priv (&ds->reserve_priv),
TALER_TESTING_make_trait_reserve_pub (&ds->reserve_pub),
TALER_TESTING_make_trait_reserve_sig (&ds->reserve_sig),
+ TALER_TESTING_make_trait_legi_requirement_row (&ds->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&ds->h_payto),
TALER_TESTING_trait_end ()
};
@@ -294,6 +337,7 @@ TALER_TESTING_cmd_purse_create_with_reserve (
unsigned int expected_http_status,
const char *contract_terms,
bool upload_contract,
+ bool pay_purse_fee,
struct GNUNET_TIME_Relative expiration,
const char *reserve_ref)
{
@@ -306,6 +350,7 @@ TALER_TESTING_cmd_purse_create_with_reserve (
0 /* flags */,
&err);
GNUNET_assert (NULL != ds->contract_terms);
+ ds->pay_purse_fee = pay_purse_fee;
ds->reserve_ref = reserve_ref;
ds->expected_response_code = expected_http_status;
diff --git a/src/testing/testing_api_cmd_reserve_status.c b/src/testing/testing_api_cmd_reserve_status.c
deleted file mode 100644
index a1b7aaefd..000000000
--- a/src/testing/testing_api_cmd_reserve_status.c
+++ /dev/null
@@ -1,369 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_reserve_status.c
- * @brief Implement the /reserve/$RID/status test command.
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_testing_lib.h"
-
-
-/**
- * State for a "status" CMD.
- */
-struct StatusState
-{
- /**
- * Label to the command which created the reserve to check,
- * needed to resort the reserve key.
- */
- const char *reserve_reference;
-
- /**
- * Handle to the "reserve status" operation.
- */
- struct TALER_EXCHANGE_ReservesStatusHandle *rsh;
-
- /**
- * Expected reserve balance.
- */
- const char *expected_balance;
-
- /**
- * Private key of the reserve being analyzed.
- */
- const struct TALER_ReservePrivateKeyP *reserve_priv;
-
- /**
- * Public key of the reserve being analyzed.
- */
- struct TALER_ReservePublicKeyP reserve_pub;
-
- /**
- * Expected HTTP response code.
- */
- unsigned int expected_response_code;
-
- /**
- * Interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-};
-
-
-/**
- * Check if @a cmd changed the reserve, if so, find the
- * entry in @a history and set the respective index in @a found
- * to #GNUNET_YES. If the entry is not found, return #GNUNET_SYSERR.
- *
- * @param reserve_pub public key of the reserve for which we have the @a history
- * @param cmd command to analyze for impact on history
- * @param history_length number of entries in @a history and @a found
- * @param history history to check
- * @param[in,out] found array to update
- * @return #GNUNET_OK if @a cmd action on reserve was found in @a history
- */
-static enum GNUNET_GenericReturnValue
-analyze_command (const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_TESTING_Command *cmd,
- unsigned int history_length,
- const struct TALER_EXCHANGE_ReserveHistoryEntry *history,
- bool *found)
-{
- if (TALER_TESTING_cmd_is_batch (cmd))
- {
- struct TALER_TESTING_Command *cur;
- struct TALER_TESTING_Command **bcmd;
-
- cur = TALER_TESTING_cmd_batch_get_current (cmd);
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_batch_cmds (cmd,
- &bcmd))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- for (unsigned int i = 0; NULL != (*bcmd)[i].label; i++)
- {
- struct TALER_TESTING_Command *step = &(*bcmd)[i];
-
- if (step == cur)
- break; /* if *we* are in a batch, make sure not to analyze commands past 'now' */
- if (GNUNET_OK !=
- analyze_command (reserve_pub,
- step,
- history_length,
- history,
- found))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Entry for batch step `%s' missing in history\n",
- step->label);
- return GNUNET_SYSERR;
- }
- }
- return GNUNET_OK;
- }
- else
- {
- const struct TALER_ReservePublicKeyP *rp;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_pub (cmd,
- &rp))
- return GNUNET_OK; /* command does nothing for reserves */
- if (0 !=
- GNUNET_memcmp (rp,
- reserve_pub))
- return GNUNET_OK; /* command affects some _other_ reserve */
- for (unsigned int j = 0; true; j++)
- {
- const struct TALER_EXCHANGE_ReserveHistoryEntry *he;
- bool matched = false;
-
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_history (cmd,
- j,
- &he))
- {
- /* NOTE: only for debugging... */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Command `%s' has the reserve_pub trait, but does not reserve history trait\n",
- cmd->label);
- return GNUNET_OK; /* command does nothing for reserves */
- }
- for (unsigned int i = 0; i<history_length; i++)
- {
- if (found[i])
- continue; /* already found, skip */
- if (0 ==
- TALER_TESTING_history_entry_cmp (he,
- &history[i]))
- {
- found[i] = true;
- matched = true;
- break;
- }
- }
- if (! matched)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Command `%s' reserve history entry #%u not found\n",
- cmd->label,
- j);
- return GNUNET_SYSERR;
- }
- }
- }
-}
-
-
-/**
- * Check that the reserve balance and HTTP response code are
- * both acceptable.
- *
- * @param cls closure.
- * @param rs HTTP response details
- */
-static void
-reserve_status_cb (void *cls,
- const struct TALER_EXCHANGE_ReserveStatus *rs)
-{
- struct StatusState *ss = cls;
- struct TALER_TESTING_Interpreter *is = ss->is;
- struct TALER_Amount eb;
-
- ss->rsh = NULL;
- if (ss->expected_response_code != rs->hr.http_status)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected HTTP response code: %d in %s:%u\n",
- rs->hr.http_status,
- __FILE__,
- __LINE__);
- json_dumpf (rs->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
- if (MHD_HTTP_OK != rs->hr.http_status)
- {
- TALER_TESTING_interpreter_next (is);
- return;
- }
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (ss->expected_balance,
- &eb));
-
- if (0 != TALER_amount_cmp (&eb,
- &rs->details.ok.balance))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected amount in reserve: %s\n",
- TALER_amount_to_string (&rs->details.ok.balance));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Expected balance of: %s\n",
- TALER_amount_to_string (&eb));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
- {
- bool found[rs->details.ok.history_len];
-
- memset (found,
- 0,
- sizeof (found));
- for (unsigned int i = 0; i<= (unsigned int) is->ip; i++)
- {
- struct TALER_TESTING_Command *cmd = &is->commands[i];
-
- if (GNUNET_OK !=
- analyze_command (&ss->reserve_pub,
- cmd,
- rs->details.ok.history_len,
- rs->details.ok.history,
- found))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Entry for command `%s' missing in history\n",
- cmd->label);
- json_dumpf (rs->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
- }
- for (unsigned int i = 0; i<rs->details.ok.history_len; i++)
- if (! found[i])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "History entry at index %u of type %d not justified by command status\n",
- i,
- rs->details.ok.history[i].type);
- json_dumpf (rs->hr.reply,
- stderr,
- JSON_INDENT (2));
- TALER_TESTING_interpreter_fail (ss->is);
- return;
- }
- }
- TALER_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command being executed.
- * @param is the interpreter state.
- */
-static void
-status_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct StatusState *ss = cls;
- const struct TALER_TESTING_Command *create_reserve;
-
- ss->is = is;
- create_reserve
- = TALER_TESTING_interpreter_lookup_command (is,
- ss->reserve_reference);
-
- if (NULL == create_reserve)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (GNUNET_OK !=
- TALER_TESTING_get_trait_reserve_priv (create_reserve,
- &ss->reserve_priv))
- {
- GNUNET_break (0);
- TALER_LOG_ERROR ("Failed to find reserve_priv for status query\n");
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- GNUNET_CRYPTO_eddsa_key_get_public (&ss->reserve_priv->eddsa_priv,
- &ss->reserve_pub.eddsa_pub);
- ss->rsh = TALER_EXCHANGE_reserves_status (is->exchange,
- ss->reserve_priv,
- &reserve_status_cb,
- ss);
-}
-
-
-/**
- * Cleanup the state from a "reserve status" CMD, and possibly
- * cancel a pending operation thereof.
- *
- * @param cls closure.
- * @param cmd the command which is being cleaned up.
- */
-static void
-status_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct StatusState *ss = cls;
-
- if (NULL != ss->rsh)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ss->is->ip,
- cmd->label);
- TALER_EXCHANGE_reserves_status_cancel (ss->rsh);
- ss->rsh = NULL;
- }
- GNUNET_free (ss);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_reserve_status (const char *label,
- const char *reserve_reference,
- const char *expected_balance,
- unsigned int expected_response_code)
-{
- struct StatusState *ss;
-
- GNUNET_assert (NULL != reserve_reference);
- ss = GNUNET_new (struct StatusState);
- ss->reserve_reference = reserve_reference;
- ss->expected_balance = expected_balance;
- ss->expected_response_code = expected_response_code;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = ss,
- .label = label,
- .run = &status_run,
- .cleanup = &status_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_revoke.c b/src/testing/testing_api_cmd_revoke.c
index 4522dede1..f734be1a4 100644
--- a/src/testing/testing_api_cmd_revoke.c
+++ b/src/testing/testing_api_cmd_revoke.c
@@ -141,14 +141,12 @@ revoke_run (void *cls,
/* Get denom pub from trait */
coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
rs->coin_reference);
-
if (NULL == coin_cmd)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
-
GNUNET_assert (GNUNET_OK ==
TALER_TESTING_get_trait_denom_pub (coin_cmd,
0,
diff --git a/src/testing/testing_api_cmd_revoke_denom_key.c b/src/testing/testing_api_cmd_revoke_denom_key.c
index 7c77c3566..2663c538f 100644
--- a/src/testing/testing_api_cmd_revoke_denom_key.c
+++ b/src/testing/testing_api_cmd_revoke_denom_key.c
@@ -65,28 +65,22 @@ struct RevokeState
* Function called with information about the post revocation operation result.
*
* @param cls closure with a `struct RevokeState *`
- * @param hr HTTP response data
+ * @param rdr response data
*/
static void
success_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementRevokeDenominationResponse *rdr)
{
struct RevokeState *rs = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rdr->hr;
rs->kh = NULL;
if (rs->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- rs->is->commands[rs->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rs->is);
+ TALER_TESTING_unexpected_status (rs->is,
+ hr->http_status,
+ rs->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (rs->is);
@@ -158,7 +152,23 @@ revoke_run (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_EXCHANGE_DenomPublicKey *denom_pub;
struct TALER_MasterSignatureP master_sig;
+ const char *exchange_url;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
rs->is = is;
/* Get denom pub from trait */
coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
@@ -185,13 +195,27 @@ revoke_run (void *cls,
}
else
{
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
TALER_exchange_offline_denomination_revoke_sign (&denom_pub->h_key,
- &is->master_priv,
+ master_priv,
&master_sig);
}
rs->kh = TALER_EXCHANGE_management_revoke_denomination_key (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
&denom_pub->h_key,
&master_sig,
&success_cb,
diff --git a/src/testing/testing_api_cmd_revoke_sign_key.c b/src/testing/testing_api_cmd_revoke_sign_key.c
index 9745d728d..65b80b4c9 100644
--- a/src/testing/testing_api_cmd_revoke_sign_key.c
+++ b/src/testing/testing_api_cmd_revoke_sign_key.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as
@@ -65,28 +65,22 @@ struct RevokeState
* Function called with information about the post revocation operation result.
*
* @param cls closure with a `struct RevokeState *`
- * @param hr HTTP response data
+ * @param rsr response data
*/
static void
success_cb (
void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementRevokeSigningKeyResponse *rsr)
{
struct RevokeState *rs = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &rsr->hr;
rs->kh = NULL;
if (rs->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- rs->is->commands[rs->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (rs->is);
+ TALER_TESTING_unexpected_status (rs->is,
+ hr->http_status,
+ rs->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (rs->is);
@@ -158,7 +152,23 @@ revoke_run (void *cls,
const struct TALER_TESTING_Command *coin_cmd;
const struct TALER_ExchangePublicKeyP *exchange_pub;
struct TALER_MasterSignatureP master_sig;
+ const char *exchange_url;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
rs->is = is;
/* Get sign pub from trait */
coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
@@ -185,13 +195,27 @@ revoke_run (void *cls,
}
else
{
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
TALER_exchange_offline_signkey_revoke_sign (exchange_pub,
- &is->master_priv,
+ master_priv,
&master_sig);
}
rs->kh = TALER_EXCHANGE_management_revoke_signing_key (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
exchange_pub,
&master_sig,
&success_cb,
diff --git a/src/testing/testing_api_cmd_rewind.c b/src/testing/testing_api_cmd_rewind.c
deleted file mode 100644
index 93b38d3c3..000000000
--- a/src/testing/testing_api_cmd_rewind.c
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_rewind.c
- * @brief command to rewind the instruction pointer.
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_exchange_service.h"
-#include "taler_testing_lib.h"
-
-
-/**
- * State for a "rewind" CMD.
- */
-struct RewindIpState
-{
- /**
- * Instruction pointer to set into the interpreter.
- */
- const char *target_label;
-
- /**
- * How many times this set should take place. However, this value lives at
- * the calling process, and this CMD is only in charge of checking and
- * decremeting it.
- */
- unsigned int counter;
-};
-
-
-/**
- * Seek for the @a target command in @a batch (and rewind to it
- * if successful).
- *
- * @param is the interpreter state (for failures)
- * @param cmd batch to search for @a target
- * @param target command to search for
- * @return #GNUNET_OK on success, #GNUNET_NO if target was not found,
- * #GNUNET_SYSERR if target is in the future and we failed
- */
-static enum GNUNET_GenericReturnValue
-seek_batch (struct TALER_TESTING_Interpreter *is,
- const struct TALER_TESTING_Command *cmd,
- const struct TALER_TESTING_Command *target)
-{
- unsigned int new_ip;
- struct TALER_TESTING_Command **batch;
- struct TALER_TESTING_Command *current;
- struct TALER_TESTING_Command *icmd;
- struct TALER_TESTING_Command *match;
-
- current = TALER_TESTING_cmd_batch_get_current (cmd);
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_get_trait_batch_cmds (cmd,
- &batch));
- match = NULL;
- for (new_ip = 0;
- NULL != (icmd = &(*batch)[new_ip]);
- new_ip++)
- {
- if (current == target)
- current = NULL;
- if (icmd == target)
- {
- match = icmd;
- break;
- }
- if (TALER_TESTING_cmd_is_batch (icmd))
- {
- int ret = seek_batch (is,
- icmd,
- target);
- if (GNUNET_SYSERR == ret)
- return GNUNET_SYSERR; /* failure! */
- if (GNUNET_OK == ret)
- {
- match = icmd;
- break;
- }
- }
- }
- if (NULL == current)
- {
- /* refuse to jump forward */
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return GNUNET_SYSERR;
- }
- if (NULL == match)
- return GNUNET_NO; /* not found */
- TALER_TESTING_cmd_batch_set_current (cmd,
- new_ip);
- return GNUNET_OK;
-}
-
-
-/**
- * Run the "rewind" CMD.
- *
- * @param cls closure.
- * @param cmd command being executed now.
- * @param is the interpreter state.
- */
-static void
-rewind_ip_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct RewindIpState *ris = cls;
- const struct TALER_TESTING_Command *target;
- unsigned int new_ip;
-
- (void) cmd;
- if (0 == ris->counter)
- {
- TALER_TESTING_interpreter_next (is);
- return;
- }
- target
- = TALER_TESTING_interpreter_lookup_command (is,
- ris->target_label);
- if (NULL == target)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- ris->counter--;
- for (new_ip = 0;
- NULL != is->commands[new_ip].label;
- new_ip++)
- {
- const struct TALER_TESTING_Command *cmd = &is->commands[new_ip];
-
- if (cmd == target)
- break;
- if (TALER_TESTING_cmd_is_batch (cmd))
- {
- int ret = seek_batch (is,
- cmd,
- target);
- if (GNUNET_SYSERR == ret)
- return; /* failure! */
- if (GNUNET_OK == ret)
- break;
- }
- }
- if (new_ip > (unsigned int) is->ip)
- {
- /* refuse to jump forward */
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- is->ip = new_ip - 1; /* -1 because the next function will advance by one */
- TALER_TESTING_interpreter_next (is);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_rewind_ip (const char *label,
- const char *target_label,
- unsigned int counter)
-{
- struct RewindIpState *ris;
-
- ris = GNUNET_new (struct RewindIpState);
- ris->target_label = target_label;
- ris->counter = counter;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = ris,
- .label = label,
- .run = &rewind_ip_run
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_run_fakebank.c b/src/testing/testing_api_cmd_run_fakebank.c
new file mode 100644
index 000000000..7739d3c0c
--- /dev/null
+++ b/src/testing/testing_api_cmd_run_fakebank.c
@@ -0,0 +1,214 @@
+/*
+ This file is part of TALER
+ (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_run_fakebank.c
+ * @brief Command to run fakebank in-process
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+
+/**
+ * State for a "run fakebank" CMD.
+ */
+struct RunFakebankState
+{
+
+ /**
+ * Our interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Handle to the fakebank we are running.
+ */
+ struct TALER_FAKEBANK_Handle *fakebank;
+
+ /**
+ * URL of the bank.
+ */
+ char *bank_url;
+
+ /**
+ * Currency to use.
+ */
+ char *currency;
+
+ /**
+ * Data for access control.
+ */
+ struct TALER_BANK_AuthenticationData ba;
+
+ /**
+ * Port to use.
+ */
+ uint16_t port;
+};
+
+
+/**
+ * Run the "get_exchange" command.
+ *
+ * @param cls closure.
+ * @param cmd the command currently being executed.
+ * @param is the interpreter state.
+ */
+static void
+run_fakebank_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct RunFakebankState *rfs = cls;
+
+ (void) cmd;
+ rfs->fakebank = TALER_FAKEBANK_start (rfs->port,
+ rfs->currency);
+ if (NULL == rfs->fakebank)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ TALER_TESTING_interpreter_next (is);
+}
+
+
+/**
+ * Cleanup the state.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+run_fakebank_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct RunFakebankState *rfs = cls;
+
+ if (NULL != rfs->fakebank)
+ {
+ TALER_FAKEBANK_stop (rfs->fakebank);
+ rfs->fakebank = NULL;
+ }
+ GNUNET_free (rfs->ba.wire_gateway_url);
+ GNUNET_free (rfs->bank_url);
+ GNUNET_free (rfs->currency);
+ GNUNET_free (rfs);
+}
+
+
+/**
+ * Offer internal data to a "run_fakebank" CMD state to other commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+run_fakebank_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct RunFakebankState *rfs = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_bank_auth_data (&rfs->ba),
+ TALER_TESTING_make_trait_fakebank (rfs->fakebank),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_run_fakebank (
+ const char *label,
+ const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *exchange_account_section)
+{
+ struct RunFakebankState *rfs;
+ unsigned long long fakebank_port;
+ char *exchange_payto_uri;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ "BANK",
+ "HTTP_PORT",
+ &fakebank_port))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "BANK",
+ "HTTP_PORT");
+ GNUNET_assert (0);
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ exchange_account_section,
+ "PAYTO_URI",
+ &exchange_payto_uri))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ exchange_account_section,
+ "PAYTO_URI");
+ GNUNET_assert (0);
+ }
+ rfs = GNUNET_new (struct RunFakebankState);
+ rfs->port = (uint16_t) fakebank_port;
+ GNUNET_asprintf (&rfs->bank_url,
+ "http://localhost:%u/",
+ (unsigned int) rfs->port);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_config_get_currency (cfg,
+ &rfs->currency));
+ {
+ char *exchange_xtalerbank_account;
+
+ exchange_xtalerbank_account
+ = TALER_xtalerbank_account_from_payto (exchange_payto_uri);
+ GNUNET_assert (NULL != exchange_xtalerbank_account);
+ GNUNET_asprintf (&rfs->ba.wire_gateway_url,
+ "http://localhost:%u/%s/",
+ (unsigned int) fakebank_port,
+ exchange_xtalerbank_account);
+ GNUNET_free (exchange_xtalerbank_account);
+ GNUNET_free (exchange_payto_uri);
+ }
+ GNUNET_free (exchange_payto_uri);
+ rfs->ba.method = TALER_BANK_AUTH_NONE;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = rfs,
+ .label = label,
+ .run = &run_fakebank_run,
+ .cleanup = &run_fakebank_cleanup,
+ .traits = &run_fakebank_traits,
+ .name = "fakebank"
+ };
+
+ return cmd;
+ }
+}
diff --git a/src/testing/testing_api_cmd_serialize_keys.c b/src/testing/testing_api_cmd_serialize_keys.c
deleted file mode 100644
index ef912bf51..000000000
--- a/src/testing/testing_api_cmd_serialize_keys.c
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
- This file is part of TALER
- (C) 2018 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_cmd_serialize_keys.c
- * @brief Lets tests use the keys serialization API.
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include <jansson.h>
-#include "taler_testing_lib.h"
-
-
-/**
- * Internal state for a serialize-keys CMD.
- */
-struct SerializeKeysState
-{
- /**
- * Serialized keys.
- */
- json_t *keys;
-
- /**
- * Exchange URL. Needed because the exchange gets disconnected
- * from, after keys serialization. This value is then needed by
- * subsequent commands that have to reconnect to the exchange.
- */
- char *exchange_url;
-};
-
-
-/**
- * Internal state for a connect-with-state CMD.
- */
-struct ConnectWithStateState
-{
-
- /**
- * Reference to a CMD that offers a serialized key-state
- * that will be used in the reconnection.
- */
- const char *state_reference;
-
- /**
- * If set to GNUNET_YES, then the /keys callback has already
- * been passed the control to the next CMD. This is necessary
- * because it is not uncommon that the /keys callback gets
- * invoked multiple times, and without this flag, we would keep
- * going "next" CMD upon every invocation (causing impredictable
- * behaviour as for the instruction pointer.)
- */
- unsigned int consumed;
-
- /**
- * Interpreter state.
- */
- struct TALER_TESTING_Interpreter *is;
-};
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-serialize_keys_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct SerializeKeysState *sks = cls;
-
- sks->keys = TALER_EXCHANGE_serialize_data (is->exchange);
- if (NULL == sks->keys)
- TALER_TESTING_interpreter_fail (is);
-
- sks->exchange_url = GNUNET_strdup
- (TALER_EXCHANGE_get_base_url (is->exchange));
- TALER_EXCHANGE_disconnect (is->exchange);
- is->exchange = NULL;
- is->working = GNUNET_NO;
- TALER_TESTING_interpreter_next (is);
-}
-
-
-/**
- * Cleanup the state of a "serialize keys" CMD.
- *
- * @param cls closure.
- * @param cmd the command which is being cleaned up.
- */
-static void
-serialize_keys_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct SerializeKeysState *sks = cls;
-
- if (NULL != sks->keys)
- {
- json_decref (sks->keys);
- }
- GNUNET_free (sks->exchange_url);
- GNUNET_free (sks);
-}
-
-
-/**
- * Offer serialized keys as trait.
- *
- * @param cls closure.
- * @param[out] ret result.
- * @param trait name of the trait.
- * @param index index number of the object to offer.
- * @return #GNUNET_OK on success.
- */
-static enum GNUNET_GenericReturnValue
-serialize_keys_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct SerializeKeysState *sks = cls;
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_exchange_keys (sks->keys),
- TALER_TESTING_make_trait_exchange_url (
- (const char **) &sks->exchange_url),
- TALER_TESTING_trait_end ()
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Run the command.
- *
- * @param cls closure.
- * @param cmd the command to execute.
- * @param is the interpreter state.
- */
-static void
-connect_with_state_run (void *cls,
- const struct TALER_TESTING_Command *cmd,
- struct TALER_TESTING_Interpreter *is)
-{
- struct ConnectWithStateState *cwss = cls;
- const struct TALER_TESTING_Command *state_cmd;
- const json_t *serialized_keys;
- const char **exchange_url;
-
- /* This command usually gets rescheduled after serialized
- * reconnection. */
- if (GNUNET_YES == cwss->consumed)
- {
- TALER_TESTING_interpreter_next (is);
- return;
- }
-
- cwss->is = is;
- state_cmd = TALER_TESTING_interpreter_lookup_command (is,
- cwss->state_reference);
-
- /* Command providing serialized keys not found. */
- if (NULL == state_cmd)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_get_trait_exchange_keys (state_cmd,
- &serialized_keys));
- {
- char *dump;
-
- dump = json_dumps (serialized_keys,
- JSON_INDENT (1));
- TALER_LOG_DEBUG ("Serialized key-state: %s\n",
- dump);
- free (dump);
- }
-
- GNUNET_assert (GNUNET_OK ==
- TALER_TESTING_get_trait_exchange_url (state_cmd,
- &exchange_url));
- is->exchange = TALER_EXCHANGE_connect (is->ctx,
- *exchange_url,
- &TALER_TESTING_cert_cb,
- cwss,
- TALER_EXCHANGE_OPTION_DATA,
- serialized_keys,
- TALER_EXCHANGE_OPTION_END);
- cwss->consumed = GNUNET_YES;
-}
-
-
-/**
- * Cleanup the state of a "connect with state" CMD. Just
- * a placeholder to avoid jumping on an invalid address.
- *
- * @param cls closure.
- * @param cmd the command which is being cleaned up.
- */
-static void
-connect_with_state_cleanup (void *cls,
- const struct TALER_TESTING_Command *cmd)
-{
- struct ConnectWithStateState *cwss = cls;
-
- GNUNET_free (cwss);
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_serialize_keys (const char *label)
-{
- struct SerializeKeysState *sks;
-
- sks = GNUNET_new (struct SerializeKeysState);
- {
- struct TALER_TESTING_Command cmd = {
- .cls = sks,
- .label = label,
- .run = serialize_keys_run,
- .cleanup = serialize_keys_cleanup,
- .traits = serialize_keys_traits
- };
-
- return cmd;
- }
-}
-
-
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_connect_with_state (const char *label,
- const char *state_reference)
-{
- struct ConnectWithStateState *cwss;
-
- cwss = GNUNET_new (struct ConnectWithStateState);
- cwss->state_reference = state_reference;
- cwss->consumed = GNUNET_NO;
- {
- struct TALER_TESTING_Command cmd = {
- .cls = cwss,
- .label = label,
- .run = connect_with_state_run,
- .cleanup = connect_with_state_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_set_officer.c b/src/testing/testing_api_cmd_set_officer.c
new file mode 100644
index 000000000..4fbe5e368
--- /dev/null
+++ b/src/testing/testing_api_cmd_set_officer.c
@@ -0,0 +1,301 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_set_officer.c
+ * @brief command for testing /management/aml-officers
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "set_officer" CMD.
+ */
+struct SetOfficerState
+{
+
+ /**
+ * Update AML officer handle while operation is running.
+ */
+ struct TALER_EXCHANGE_ManagementUpdateAmlOfficer *dh;
+
+ /**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Reference to command to previous set officer
+ * to update, or NULL.
+ */
+ const char *ref_cmd;
+
+ /**
+ * Name to use for the officer.
+ */
+ const char *name;
+
+ /**
+ * Private key of the AML officer.
+ */
+ struct TALER_AmlOfficerPrivateKeyP officer_priv;
+
+ /**
+ * Public key of the AML officer.
+ */
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+
+ /**
+ * Is the officer supposed to be enabled?
+ */
+ bool is_active;
+
+ /**
+ * Is access supposed to be read-only?
+ */
+ bool read_only;
+
+};
+
+
+/**
+ * Callback to analyze the /management/XXX response, just used to check
+ * if the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param ar response details
+ */
+static void
+set_officer_cb (void *cls,
+ const struct
+ TALER_EXCHANGE_ManagementUpdateAmlOfficerResponse *ar)
+{
+ struct SetOfficerState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &ar->hr;
+
+ ds->dh = NULL;
+ if (MHD_HTTP_NO_CONTENT != hr->http_status)
+ {
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ MHD_HTTP_NO_CONTENT);
+ return;
+ }
+ TALER_TESTING_interpreter_next (ds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+set_officer_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct SetOfficerState *ds = cls;
+ struct GNUNET_TIME_Timestamp now;
+ struct TALER_MasterSignatureP master_sig;
+ const char *exchange_url;
+
+ (void) cmd;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
+ now = GNUNET_TIME_timestamp_get ();
+ ds->is = is;
+ if (NULL == ds->ref_cmd)
+ {
+ GNUNET_CRYPTO_eddsa_key_create (&ds->officer_priv.eddsa_priv);
+ GNUNET_CRYPTO_eddsa_key_get_public (&ds->officer_priv.eddsa_priv,
+ &ds->officer_pub.eddsa_pub);
+ }
+ else
+ {
+ const struct TALER_TESTING_Command *ref;
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub;
+
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->ref_cmd);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_officer_pub (ref,
+ &officer_pub));
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_officer_priv (ref,
+ &officer_priv));
+ ds->officer_pub = *officer_pub;
+ ds->officer_priv = *officer_priv;
+ }
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
+
+ TALER_exchange_offline_aml_officer_status_sign (&ds->officer_pub,
+ ds->name,
+ now,
+ ds->is_active,
+ ds->read_only,
+ master_priv,
+ &master_sig);
+ }
+ ds->dh = TALER_EXCHANGE_management_update_aml_officer (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ &ds->officer_pub,
+ ds->name,
+ now,
+ ds->is_active,
+ ds->read_only,
+ &master_sig,
+ &set_officer_cb,
+ ds);
+ if (NULL == ds->dh)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "set_officer" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct SetOfficerState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+set_officer_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct SetOfficerState *ds = cls;
+
+ if (NULL != ds->dh)
+ {
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
+ TALER_EXCHANGE_management_update_aml_officer_cancel (ds->dh);
+ ds->dh = NULL;
+ }
+ GNUNET_free (ds);
+}
+
+
+/**
+ * Offer internal data of a "set officer" CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+set_officer_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct SetOfficerState *ws = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_officer_pub (&ws->officer_pub),
+ TALER_TESTING_make_trait_officer_priv (&ws->officer_priv),
+ TALER_TESTING_make_trait_officer_name (ws->name),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_set_officer (
+ const char *label,
+ const char *ref_cmd,
+ const char *name,
+ bool is_active,
+ bool read_only)
+{
+ struct SetOfficerState *ds;
+
+ ds = GNUNET_new (struct SetOfficerState);
+ ds->ref_cmd = ref_cmd;
+ ds->name = name;
+ ds->is_active = is_active;
+ ds->read_only = read_only;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &set_officer_run,
+ .cleanup = &set_officer_cleanup,
+ .traits = &set_officer_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_set_officer.c */
diff --git a/src/testing/testing_api_cmd_set_wire_fee.c b/src/testing/testing_api_cmd_set_wire_fee.c
index 8eb993878..460a71e40 100644
--- a/src/testing/testing_api_cmd_set_wire_fee.c
+++ b/src/testing/testing_api_cmd_set_wire_fee.c
@@ -61,11 +61,6 @@ struct WireFeeState
const char *closing_fee;
/**
- * Wad fee amount to use.
- */
- const char *wad_fee;
-
- /**
* Expected HTTP response code.
*/
unsigned int expected_response_code;
@@ -82,27 +77,21 @@ struct WireFeeState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param sfr response details
*/
static void
wire_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementSetWireFeeResponse *sfr)
{
struct WireFeeState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &sfr->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -127,8 +116,24 @@ wire_add_run (void *cls,
struct GNUNET_TIME_Timestamp start_time;
struct GNUNET_TIME_Timestamp end_time;
struct TALER_WireFeeSet fees;
+ const char *exchange_url;
(void) cmd;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
ds->is = is;
now = GNUNET_TIME_absolute_get ();
start_time = GNUNET_TIME_absolute_to_timestamp (
@@ -141,9 +146,6 @@ wire_add_run (void *cls,
TALER_string_to_amount (ds->closing_fee,
&fees.closing)) ||
(GNUNET_OK !=
- TALER_string_to_amount (ds->wad_fee,
- &fees.wad)) ||
- (GNUNET_OK !=
TALER_string_to_amount (ds->wire_fee,
&fees.wire)) )
{
@@ -160,16 +162,30 @@ wire_add_run (void *cls,
}
else
{
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
TALER_exchange_offline_wire_fee_sign (ds->wire_method,
start_time,
end_time,
&fees,
- &is->master_priv,
+ master_priv,
&master_sig);
}
ds->dh = TALER_EXCHANGE_management_set_wire_fees (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
ds->wire_method,
start_time,
end_time,
@@ -201,10 +217,8 @@ wire_add_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_management_set_wire_fees_cancel (ds->dh);
ds->dh = NULL;
}
@@ -217,7 +231,6 @@ TALER_TESTING_cmd_set_wire_fee (const char *label,
const char *wire_method,
const char *wire_fee,
const char *closing_fee,
- const char *wad_fee,
unsigned int expected_http_status,
bool bad_sig)
{
@@ -229,7 +242,6 @@ TALER_TESTING_cmd_set_wire_fee (const char *label,
ds->wire_method = wire_method;
ds->wire_fee = wire_fee;
ds->closing_fee = closing_fee;
- ds->wad_fee = wad_fee;
{
struct TALER_TESTING_Command cmd = {
.cls = ds,
diff --git a/src/testing/testing_api_cmd_stat.c b/src/testing/testing_api_cmd_stat.c
index 5d41c05c9..8723aac0d 100644
--- a/src/testing/testing_api_cmd_stat.c
+++ b/src/testing/testing_api_cmd_stat.c
@@ -28,6 +28,19 @@
/**
+ * Run a "stat" CMD.
+ *
+ * @param cls closure.
+ * @param cmd the command being run.
+ * @param is the interpreter state.
+ */
+static void
+stat_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is);
+
+
+/**
* Add the time @a cmd took to the respective duration in @a timings.
*
* @param timings where to add up times
@@ -40,9 +53,20 @@ stat_cmd (struct TALER_TESTING_Timer *timings,
struct GNUNET_TIME_Relative duration;
struct GNUNET_TIME_Relative lat;
- if (cmd->start_time.abs_value_us > cmd->finish_time.abs_value_us)
+ if (GNUNET_TIME_absolute_cmp (cmd->start_time,
+ >,
+ cmd->finish_time))
{
- GNUNET_break (0);
+ /* This is a problem, except of course for
+ this command itself, as we clearly did not yet
+ finish... */
+ if (cmd->run != &stat_run)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Bad timings for `%s'\n",
+ cmd->label);
+ GNUNET_break (0);
+ }
return;
}
duration = GNUNET_TIME_absolute_get_difference (cmd->start_time,
@@ -74,16 +98,18 @@ stat_cmd (struct TALER_TESTING_Timer *timings,
/**
* Obtain statistics for @a timings of @a cmd
*
- * @param timings what timings to get
+ * @param[in,out] cls what timings to get
* @param cmd command to process
*/
static void
-do_stat (struct TALER_TESTING_Timer *timings,
+do_stat (void *cls,
const struct TALER_TESTING_Command *cmd)
{
+ struct TALER_TESTING_Timer *timings = cls;
+
if (TALER_TESTING_cmd_is_batch (cmd))
{
- struct TALER_TESTING_Command **bcmd;
+ struct TALER_TESTING_Command *bcmd;
if (GNUNET_OK !=
TALER_TESTING_get_trait_batch_cmds (cmd,
@@ -92,18 +118,15 @@ do_stat (struct TALER_TESTING_Timer *timings,
GNUNET_break (0);
return;
}
-
for (unsigned int j = 0;
- NULL != (*bcmd)[j].label;
+ NULL != bcmd[j].label;
j++)
do_stat (timings,
- &(*bcmd)[j]);
- }
- else
- {
- stat_cmd (timings,
- cmd);
+ &bcmd[j]);
+ return;
}
+ stat_cmd (timings,
+ cmd);
}
@@ -121,13 +144,10 @@ stat_run (void *cls,
{
struct TALER_TESTING_Timer *timings = cls;
- for (unsigned int i = 0; NULL != is->commands[i].label; i++)
- {
- if (cmd == &is->commands[i])
- break; /* skip at our current command */
- do_stat (timings,
- &is->commands[i]);
- }
+ TALER_TESTING_iterate (is,
+ true,
+ &do_stat,
+ timings);
TALER_TESTING_interpreter_next (is);
}
@@ -137,7 +157,7 @@ TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers)
{
struct TALER_TESTING_Command cmd = {
.label = "stat",
- .run = stat_run,
+ .run = &stat_run,
.cls = (void *) timers
};
@@ -145,4 +165,4 @@ TALER_TESTING_cmd_stat (struct TALER_TESTING_Timer *timers)
}
-/* end of testing_api_cmd_sleep.c */
+/* end of testing_api_cmd_stat.c */
diff --git a/src/testing/testing_api_cmd_system_start.c b/src/testing/testing_api_cmd_system_start.c
new file mode 100644
index 000000000..541ad75c1
--- /dev/null
+++ b/src/testing/testing_api_cmd_system_start.c
@@ -0,0 +1,395 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not,
+ see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_system_start.c
+ * @brief run taler-benchmark-setup.sh command
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_signatures.h"
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "system" CMD.
+ */
+struct SystemState
+{
+
+ /**
+ * System process.
+ */
+ struct GNUNET_OS_Process *system_proc;
+
+ /**
+ * Input pipe to @e system_proc, used to keep the
+ * process alive until we are done.
+ */
+ struct GNUNET_DISK_PipeHandle *pipe_in;
+
+ /**
+ * Output pipe to @e system_proc, used to find out
+ * when the services are ready.
+ */
+ struct GNUNET_DISK_PipeHandle *pipe_out;
+
+ /**
+ * Task reading from @e pipe_in.
+ */
+ struct GNUNET_SCHEDULER_Task *reader;
+
+ /**
+ * Waiting for child to die.
+ */
+ struct GNUNET_ChildWaitHandle *cwh;
+
+ /**
+ * Our interpreter state.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * NULL-terminated array of command-line arguments.
+ */
+ char **args;
+
+ /**
+ * Current input buffer, 0-terminated. Contains the last 15 bytes of input
+ * so we can search them again for the "<<READY>>" tag.
+ */
+ char ibuf[16];
+
+ /**
+ * Did we find the ready tag?
+ */
+ bool ready;
+
+ /**
+ * Is the child process still running?
+ */
+ bool active;
+};
+
+
+/**
+ * Defines a GNUNET_ChildCompletedCallback which is sent back
+ * upon death or completion of a child process.
+ *
+ * @param cls our `struct SystemState *`
+ * @param type type of the process
+ * @param exit_code status code of the process
+ */
+static void
+setup_terminated (void *cls,
+ enum GNUNET_OS_ProcessStatusType type,
+ long unsigned int exit_code)
+{
+ struct SystemState *as = cls;
+
+ as->cwh = NULL;
+ as->active = false;
+ if (NULL != as->reader)
+ {
+ GNUNET_SCHEDULER_cancel (as->reader);
+ as->reader = NULL;
+ }
+ if (! as->ready)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Launching Taler system failed: %d/%llu\n",
+ (int) type,
+ (unsigned long long) exit_code);
+ TALER_TESTING_interpreter_fail (as->is);
+ return;
+ }
+}
+
+
+/**
+ * Start helper to read from stdout of child.
+ *
+ * @param as our system state
+ */
+static void
+start_reader (struct SystemState *as);
+
+
+static void
+read_stdout (void *cls)
+{
+ struct SystemState *as = cls;
+ const struct GNUNET_DISK_FileHandle *fh;
+ char buf[1024 * 10];
+ ssize_t ret;
+ size_t off = 0;
+
+ as->reader = NULL;
+ strcpy (buf,
+ as->ibuf);
+ off = strlen (buf);
+ fh = GNUNET_DISK_pipe_handle (as->pipe_out,
+ GNUNET_DISK_PIPE_END_READ);
+ ret = GNUNET_DISK_file_read (fh,
+ &buf[off],
+ sizeof (buf) - off);
+ if (-1 == ret)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "read");
+ TALER_TESTING_interpreter_fail (as->is);
+ return;
+ }
+ if (0 == ret)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Child closed stdout\n");
+ return;
+ }
+ /* forward log, except single '.' outputs */
+ if ( (1 != ret) ||
+ ('.' != buf[off]) )
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "TUS: %.*s\n",
+ (int) ret,
+ &buf[off]);
+ start_reader (as);
+ off += ret;
+ if (as->ready)
+ {
+ /* already done */
+ return;
+ }
+ if (NULL !=
+ memmem (buf,
+ off,
+ "\n<<READY>>\n",
+ strlen ("\n<<READY>>\n")))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Taler system UP\n");
+ as->ready = true;
+ TALER_TESTING_interpreter_next (as->is);
+ return;
+ }
+
+ {
+ size_t mcpy;
+
+ mcpy = GNUNET_MIN (off,
+ sizeof (as->ibuf) - 1);
+ memcpy (as->ibuf,
+ &buf[off - mcpy],
+ mcpy);
+ as->ibuf[mcpy] = '\0';
+ }
+}
+
+
+static void
+start_reader (struct SystemState *as)
+{
+ const struct GNUNET_DISK_FileHandle *fh;
+
+ GNUNET_assert (NULL == as->reader);
+ fh = GNUNET_DISK_pipe_handle (as->pipe_out,
+ GNUNET_DISK_PIPE_END_READ);
+ as->reader = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ fh,
+ &read_stdout,
+ as);
+}
+
+
+/**
+ * Run the command. Use the `taler-exchange-system' program.
+ *
+ * @param cls closure.
+ * @param cmd command being run.
+ * @param is interpreter state.
+ */
+static void
+system_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct SystemState *as = cls;
+
+ (void) cmd;
+ as->is = is;
+ as->pipe_in = GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_READ);
+ GNUNET_assert (NULL != as->pipe_in);
+ as->pipe_out = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
+ GNUNET_assert (NULL != as->pipe_out);
+ as->system_proc
+ = GNUNET_OS_start_process_vap (
+ GNUNET_OS_INHERIT_STD_ERR,
+ as->pipe_in, as->pipe_out, NULL,
+ "taler-unified-setup.sh",
+ as->args);
+ if (NULL == as->system_proc)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ as->active = true;
+ start_reader (as);
+ as->cwh = GNUNET_wait_child (as->system_proc,
+ &setup_terminated,
+ as);
+}
+
+
+/**
+ * Free the state of a "system" CMD, and possibly kill its
+ * process if it did not terminate correctly.
+ *
+ * @param cls closure.
+ * @param cmd the command being freed.
+ */
+static void
+system_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct SystemState *as = cls;
+
+ (void) cmd;
+ if (NULL != as->cwh)
+ {
+ GNUNET_wait_child_cancel (as->cwh);
+ as->cwh = NULL;
+ }
+ if (NULL != as->reader)
+ {
+ GNUNET_SCHEDULER_cancel (as->reader);
+ as->reader = NULL;
+ }
+ if (NULL != as->system_proc)
+ {
+ if (as->active)
+ {
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (as->system_proc,
+ SIGTERM));
+ GNUNET_OS_process_wait (as->system_proc);
+ }
+ GNUNET_OS_process_destroy (as->system_proc);
+ as->system_proc = NULL;
+ }
+ if (NULL != as->pipe_in)
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (as->pipe_in));
+ as->pipe_in = NULL;
+ }
+ if (NULL != as->pipe_out)
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (as->pipe_out));
+ as->pipe_out = NULL;
+ }
+
+ for (unsigned int i = 0; NULL != as->args[i]; i++)
+ GNUNET_free (as->args[i]);
+ GNUNET_free (as->args);
+ GNUNET_free (as);
+}
+
+
+/**
+ * Offer "system" CMD internal data to other commands.
+ *
+ * @param cls closure.
+ * @param[out] ret result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+system_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct SystemState *as = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_process (&as->system_proc),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_system_start (
+ const char *label,
+ const char *config_file,
+ ...)
+{
+ struct SystemState *as;
+ va_list ap;
+ const char *arg;
+ unsigned int cnt;
+
+ as = GNUNET_new (struct SystemState);
+ cnt = 4; /* 0-2 reserved, +1 for NULL termination */
+ va_start (ap,
+ config_file);
+ while (NULL != (arg = va_arg (ap,
+ const char *)))
+ {
+ cnt++;
+ }
+ va_end (ap);
+ as->args = GNUNET_new_array (cnt,
+ char *);
+ as->args[0] = GNUNET_strdup ("taler-unified-setup");
+ as->args[1] = GNUNET_strdup ("-c");
+ as->args[2] = GNUNET_strdup (config_file);
+ cnt = 3;
+ va_start (ap,
+ config_file);
+ while (NULL != (arg = va_arg (ap,
+ const char *)))
+ {
+ as->args[cnt++] = GNUNET_strdup (arg);
+ }
+ va_end (ap);
+
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = as,
+ .label = label,
+ .run = &system_run,
+ .cleanup = &system_cleanup,
+ .traits = &system_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_system_start.c */
diff --git a/src/testing/testing_api_cmd_take_aml_decision.c b/src/testing/testing_api_cmd_take_aml_decision.c
new file mode 100644
index 000000000..c0e23de22
--- /dev/null
+++ b/src/testing/testing_api_cmd_take_aml_decision.c
@@ -0,0 +1,321 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your
+ option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_take_aml_decision.c
+ * @brief command for testing /aml/$OFFICER_PUB/decision
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_signatures.h"
+#include "backoff.h"
+
+
+/**
+ * State for a "take_aml_decision" CMD.
+ */
+struct AmlDecisionState
+{
+
+ /**
+ * Auditor enable handle while operation is running.
+ */
+ struct TALER_EXCHANGE_AddAmlDecision *dh;
+
+ /**
+ * Our interpreter.
+ */
+ struct TALER_TESTING_Interpreter *is;
+
+ /**
+ * Reference to command to previous set officer command that gives
+ * us an officer_priv trait.
+ */
+ const char *officer_ref_cmd;
+
+ /**
+ * Reference to command to previous AML-triggering event that gives
+ * us a payto-hash trait.
+ */
+ const char *account_ref_cmd;
+
+ /**
+ * Payto hash of the account we are manipulating the AML settings for.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * New AML state to use.
+ */
+ enum TALER_AmlDecisionState new_state;
+
+ /**
+ * Justification given.
+ */
+ const char *justification;
+
+ /**
+ * KYC requirement to add.
+ */
+ const char *kyc_requirement;
+
+ /**
+ * Threshold transaction amount.
+ */
+ struct TALER_Amount new_threshold;
+
+ /**
+ * Expected response code.
+ */
+ unsigned int expected_response;
+};
+
+
+/**
+ * Callback to analyze the /aml-decision/$OFFICER_PUB response, just used to check
+ * if the response code is acceptable.
+ *
+ * @param cls closure.
+ * @param adr response details
+ */
+static void
+take_aml_decision_cb (
+ void *cls,
+ const struct TALER_EXCHANGE_AddAmlDecisionResponse *adr)
+{
+ struct AmlDecisionState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &adr->hr;
+
+ ds->dh = NULL;
+ if (ds->expected_response != hr->http_status)
+ {
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response);
+ return;
+ }
+ TALER_TESTING_interpreter_next (ds->is);
+}
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+take_aml_decision_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct AmlDecisionState *ds = cls;
+ struct GNUNET_TIME_Timestamp now;
+ const struct TALER_PaytoHashP *h_payto;
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv;
+ const struct TALER_TESTING_Command *ref;
+ json_t *kyc_requirements = NULL;
+ const char *exchange_url;
+
+ (void) cmd;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
+ now = GNUNET_TIME_timestamp_get ();
+ ds->is = is;
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->account_ref_cmd);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_h_payto (ref,
+ &h_payto))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ ref = TALER_TESTING_interpreter_lookup_command (is,
+ ds->officer_ref_cmd);
+ if (NULL == ref)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_officer_priv (ref,
+ &officer_priv))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ ds->h_payto = *h_payto;
+ if (NULL != ds->kyc_requirement)
+ {
+ kyc_requirements = json_array ();
+ GNUNET_assert (NULL != kyc_requirements);
+ GNUNET_assert (0 ==
+ json_array_append (kyc_requirements,
+ json_string (ds->kyc_requirement)));
+ }
+
+ ds->dh = TALER_EXCHANGE_add_aml_decision (
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
+ ds->justification,
+ now,
+ &ds->new_threshold,
+ h_payto,
+ ds->new_state,
+ kyc_requirements,
+ officer_priv,
+ &take_aml_decision_cb,
+ ds);
+ json_decref (kyc_requirements);
+ if (NULL == ds->dh)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+}
+
+
+/**
+ * Free the state of a "take_aml_decision" CMD, and possibly cancel a
+ * pending operation thereof.
+ *
+ * @param cls closure, must be a `struct AmlDecisionState`.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+take_aml_decision_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AmlDecisionState *ds = cls;
+
+ if (NULL != ds->dh)
+ {
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
+ TALER_EXCHANGE_add_aml_decision_cancel (ds->dh);
+ ds->dh = NULL;
+ }
+ GNUNET_free (ds);
+}
+
+
+/**
+ * Offer internal data of a "AML decision" CMD state to other
+ * commands.
+ *
+ * @param cls closure
+ * @param[out] ret result (could be anything)
+ * @param trait name of the trait
+ * @param index index number of the object to offer.
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+take_aml_decision_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct AmlDecisionState *ws = cls;
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_h_payto (&ws->h_payto),
+ TALER_TESTING_make_trait_aml_justification (ws->justification),
+ TALER_TESTING_make_trait_aml_decision (&ws->new_state),
+ TALER_TESTING_make_trait_amount (&ws->new_threshold),
+ TALER_TESTING_trait_end ()
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_take_aml_decision (
+ const char *label,
+ const char *ref_officer,
+ const char *ref_operation,
+ const char *new_threshold,
+ const char *justification,
+ enum TALER_AmlDecisionState new_state,
+ const char *kyc_requirement,
+ unsigned int expected_response)
+{
+ struct AmlDecisionState *ds;
+
+ ds = GNUNET_new (struct AmlDecisionState);
+ ds->officer_ref_cmd = ref_officer;
+ ds->account_ref_cmd = ref_operation;
+ ds->kyc_requirement = kyc_requirement;
+ if (GNUNET_OK !=
+ TALER_string_to_amount (new_threshold,
+ &ds->new_threshold))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to parse amount `%s' at %s\n",
+ new_threshold,
+ label);
+ GNUNET_assert (0);
+ }
+ ds->new_state = new_state;
+ ds->justification = justification;
+ ds->expected_response = expected_response;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ds,
+ .label = label,
+ .run = &take_aml_decision_run,
+ .cleanup = &take_aml_decision_cleanup,
+ .traits = &take_aml_decision_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/* end of testing_api_cmd_take_aml_decision.c */
diff --git a/src/testing/testing_api_cmd_transfer_get.c b/src/testing/testing_api_cmd_transfer_get.c
index 3c467e6da..405c8b7f9 100644
--- a/src/testing/testing_api_cmd_transfer_get.c
+++ b/src/testing/testing_api_cmd_transfer_get.c
@@ -44,6 +44,11 @@ struct TrackTransferState
const char *expected_wire_fee;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Reference to any operation that can provide a WTID.
* Will be the WTID to track.
*/
@@ -98,10 +103,8 @@ track_transfer_cleanup (void *cls,
if (NULL != tts->tth)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- tts->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (tts->is,
+ cmd->label);
TALER_EXCHANGE_transfers_get_cancel (tts->tth);
tts->tth = NULL;
}
@@ -115,180 +118,178 @@ track_transfer_cleanup (void *cls,
* wire fees and hashed wire details as well.
*
* @param cls closure.
- * @param hr HTTP response details
- * @param ta transfer data returned by the exchange
+ * @param tgr response details
*/
static void
track_transfer_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_TransferData *ta)
+ const struct TALER_EXCHANGE_TransfersGetResponse *tgr)
{
struct TrackTransferState *tts = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &tgr->hr;
struct TALER_TESTING_Interpreter *is = tts->is;
- struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
struct TALER_Amount expected_amount;
tts->tth = NULL;
if (tts->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- hr->http_status,
- (int) hr->ec,
- cmd->label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status (is,
+ hr->http_status,
+ tts->expected_response_code);
return;
}
switch (hr->http_status)
{
case MHD_HTTP_OK:
- if (NULL == tts->expected_total_amount)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (NULL == tts->expected_wire_fee)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (GNUNET_OK !=
- TALER_string_to_amount (tts->expected_total_amount,
- &expected_amount))
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- if (0 != TALER_amount_cmp (&ta->total_amount,
- &expected_amount))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Total amount mismatch to command %s - "
- "%s vs %s\n",
- cmd->label,
- TALER_amount_to_string (&ta->total_amount),
- TALER_amount_to_string (&expected_amount));
- json_dumpf (hr->reply,
- stderr,
- 0);
- fprintf (stderr, "\n");
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (GNUNET_OK !=
- TALER_string_to_amount (tts->expected_wire_fee,
- &expected_amount))
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
-
- if (0 != TALER_amount_cmp (&ta->wire_fee,
- &expected_amount))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire fee mismatch to command %s\n",
- cmd->label);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
+ const struct TALER_EXCHANGE_TransferData *ta
+ = &tgr->details.ok.td;
- /**
- * Optionally checking: (1) wire-details for this transfer
- * match the ones from a referenced "deposit" operation -
- * or any operation that could provide wire-details. (2)
- * Total amount for this transfer matches the one from any
- * referenced command that could provide one.
- */
- if (NULL != tts->wire_details_reference)
- {
- const struct TALER_TESTING_Command *wire_details_cmd;
- const char **payto_uri;
- struct TALER_PaytoHashP h_payto;
-
- wire_details_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tts->wire_details_reference);
- if (NULL == wire_details_cmd)
+ if (NULL == tts->expected_total_amount)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (NULL == tts->expected_wire_fee)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
+
if (GNUNET_OK !=
- TALER_TESTING_get_trait_payto_uri (wire_details_cmd,
- &payto_uri))
+ TALER_string_to_amount (tts->expected_total_amount,
+ &expected_amount))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
- TALER_payto_hash (*payto_uri,
- &h_payto);
- if (0 != GNUNET_memcmp (&h_payto,
- &ta->h_payto))
+ if (0 != TALER_amount_cmp (&ta->total_amount,
+ &expected_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire hash missmath to command %s\n",
- cmd->label);
+ "Total amount mismatch to command %s - "
+ "%s vs %s\n",
+ tts->cmd->label,
+ TALER_amount_to_string (&ta->total_amount),
+ TALER_amount_to_string (&expected_amount));
json_dumpf (hr->reply,
stderr,
0);
+ fprintf (stderr, "\n");
TALER_TESTING_interpreter_fail (is);
return;
}
- }
- if (NULL != tts->total_amount_reference)
- {
- const struct TALER_TESTING_Command *total_amount_cmd;
- const struct TALER_Amount *total_amount_from_reference;
- total_amount_cmd
- = TALER_TESTING_interpreter_lookup_command (is,
- tts->total_amount_reference);
- if (NULL == total_amount_cmd)
- {
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
- return;
- }
if (GNUNET_OK !=
- TALER_TESTING_get_trait_amount (total_amount_cmd,
- &total_amount_from_reference))
+ TALER_string_to_amount (tts->expected_wire_fee,
+ &expected_amount))
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
- if (0 != TALER_amount_cmp (&ta->total_amount,
- total_amount_from_reference))
+
+ if (0 != TALER_amount_cmp (&ta->wire_fee,
+ &expected_amount))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Amount missmath to command %s\n",
- cmd->label);
+ "Wire fee mismatch to command %s\n",
+ tts->cmd->label);
json_dumpf (hr->reply,
stderr,
0);
TALER_TESTING_interpreter_fail (is);
return;
}
- }
- }
+
+ /**
+ * Optionally checking: (1) wire-details for this transfer
+ * match the ones from a referenced "deposit" operation -
+ * or any operation that could provide wire-details. (2)
+ * Total amount for this transfer matches the one from any
+ * referenced command that could provide one.
+ */
+ if (NULL != tts->wire_details_reference)
+ {
+ const struct TALER_TESTING_Command *wire_details_cmd;
+ const char *payto_uri;
+ struct TALER_PaytoHashP h_payto;
+
+ wire_details_cmd
+ = TALER_TESTING_interpreter_lookup_command (is,
+ tts->
+ wire_details_reference);
+ if (NULL == wire_details_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_payto_uri (wire_details_cmd,
+ &payto_uri))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ TALER_payto_hash (payto_uri,
+ &h_payto);
+ if (0 != GNUNET_memcmp (&h_payto,
+ &ta->h_payto))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Wire hash missmath to command %s\n",
+ tts->cmd->label);
+ json_dumpf (hr->reply,
+ stderr,
+ 0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ if (NULL != tts->total_amount_reference)
+ {
+ const struct TALER_TESTING_Command *total_amount_cmd;
+ const struct TALER_Amount *total_amount_from_reference;
+
+ total_amount_cmd
+ = TALER_TESTING_interpreter_lookup_command (is,
+ tts->
+ total_amount_reference);
+ if (NULL == total_amount_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_amount (total_amount_cmd,
+ &total_amount_from_reference))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ if (0 != TALER_amount_cmp (&ta->total_amount,
+ total_amount_from_reference))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Amount mismatch in command %s\n",
+ tts->cmd->label);
+ json_dumpf (hr->reply,
+ stderr,
+ 0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ }
+ break;
+ } /* case OK */
+ } /* switch on status */
TALER_TESTING_interpreter_next (is);
}
@@ -310,13 +311,13 @@ track_transfer_run (void *cls,
struct TALER_WireTransferIdentifierRawP wtid;
const struct TALER_WireTransferIdentifierRawP *wtid_ptr;
+ tts->cmd = cmd;
/* If no reference is given, we'll use a all-zeros
* WTID */
memset (&wtid,
0,
sizeof (wtid));
wtid_ptr = &wtid;
-
tts->is = is;
if (NULL != tts->wtid_reference)
{
@@ -341,10 +342,13 @@ track_transfer_run (void *cls,
}
GNUNET_assert (NULL != wtid_ptr);
}
- tts->tth = TALER_EXCHANGE_transfers_get (is->exchange,
- wtid_ptr,
- &track_transfer_cb,
- tts);
+ tts->tth = TALER_EXCHANGE_transfers_get (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ wtid_ptr,
+ &track_transfer_cb,
+ tts);
GNUNET_assert (NULL != tts->tth);
}
diff --git a/src/testing/testing_api_cmd_twister_exec_client.c b/src/testing/testing_api_cmd_twister_exec_client.c
index d1d781f5a..bf83c1f80 100644
--- a/src/testing/testing_api_cmd_twister_exec_client.c
+++ b/src/testing/testing_api_cmd_twister_exec_client.c
@@ -572,7 +572,7 @@ flip_object_cleanup
* @param index index number of the object to offer.
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
flip_object_traits (void *cls,
const void **ret,
const char *trait,
diff --git a/src/testing/testing_api_cmd_wire.c b/src/testing/testing_api_cmd_wire.c
index 4b0a177b5..41ff7a978 100644
--- a/src/testing/testing_api_cmd_wire.c
+++ b/src/testing/testing_api_cmd_wire.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
+ Copyright (C) 2018, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -39,6 +39,11 @@ struct WireState
struct TALER_EXCHANGE_WireHandle *wh;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* Which wire-method we expect is offered by the exchange.
*/
const char *expected_method;
@@ -72,19 +77,14 @@ struct WireState
* that the wire fee is acceptable too.
*
* @param cls closure.
- * @param hr HTTP response details
- * @param accounts_len length of the @a accounts array.
- * @param accounts list of wire accounts of the exchange,
- * NULL on error.
+ * @param wr response details
*/
static void
wire_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- unsigned int accounts_len,
- const struct TALER_EXCHANGE_WireAccount *accounts)
+ const struct TALER_EXCHANGE_WireResponse *wr)
{
struct WireState *ws = cls;
- struct TALER_TESTING_Command *cmd = &ws->is->commands[ws->is->ip];
+ const struct TALER_EXCHANGE_HttpResponse *hr = &wr->hr;
struct TALER_Amount expected_fee;
TALER_LOG_DEBUG ("Checking parsed /wire response\n");
@@ -100,41 +100,70 @@ wire_cb (void *cls,
if (MHD_HTTP_OK == hr->http_status)
{
+ unsigned int accounts_len
+ = wr->details.ok.accounts_len;
+ unsigned int fees_len
+ = wr->details.ok.fees_len;
+ const struct TALER_EXCHANGE_WireAccount *accounts
+ = wr->details.ok.accounts;
+ const struct TALER_EXCHANGE_WireFeesByMethod *fees
+ = wr->details.ok.fees;
+
for (unsigned int i = 0; i<accounts_len; i++)
{
char *method;
method = TALER_payto_get_method (accounts[i].payto_uri);
+ if (NULL == method)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (ws->is);
+ return;
+ }
if (0 == strcmp (ws->expected_method,
method))
{
ws->method_found = GNUNET_OK;
- if (NULL != ws->expected_fee)
+ }
+ GNUNET_free (method);
+ }
+ if (NULL != ws->expected_fee)
+ {
+ bool fee_found = false;
+
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (ws->expected_fee,
+ &expected_fee));
+ for (unsigned int i = 0; i<fees_len; i++)
+ {
+ if (0 != strcmp (fees[i].method,
+ ws->expected_method))
+ continue;
+ for (const struct TALER_EXCHANGE_WireAggregateFees *waf
+ = fees[i].fees_head;
+ NULL != waf;
+ waf = waf->next)
{
- GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (ws->expected_fee,
- &expected_fee));
- for (const struct TALER_EXCHANGE_WireAggregateFees *waf
- = accounts[i].fees;
- NULL != waf;
- waf = waf->next)
+ if (0 != TALER_amount_cmp (&waf->fees.wire,
+ &expected_fee))
{
- if (0 != TALER_amount_cmp (&waf->fees.wire,
- &expected_fee))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Wire fee mismatch to command %s\n",
- cmd->label);
- TALER_TESTING_interpreter_fail (ws->is);
- GNUNET_free (method);
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Wire fee mismatch to command %s\n",
+ ws->cmd->label);
+ TALER_TESTING_interpreter_fail (ws->is);
+ return;
}
+ fee_found = true;
}
}
- TALER_LOG_DEBUG ("Freeing method '%s'\n",
- method);
- GNUNET_free (method);
+ if (! fee_found)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "/wire does not contain expected fee '%s'\n",
+ ws->expected_fee);
+ TALER_TESTING_interpreter_fail (ws->is);
+ return;
+ }
}
if (GNUNET_OK != ws->method_found)
{
@@ -163,11 +192,14 @@ wire_run (void *cls,
{
struct WireState *ws = cls;
- (void) cmd;
+ ws->cmd = cmd;
ws->is = is;
- ws->wh = TALER_EXCHANGE_wire (is->exchange,
- &wire_cb,
- ws);
+ ws->wh = TALER_EXCHANGE_wire (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ &wire_cb,
+ ws);
}
@@ -186,10 +218,8 @@ wire_cleanup (void *cls,
if (NULL != ws->wh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ws->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ws->is,
+ cmd->label);
TALER_EXCHANGE_wire_cancel (ws->wh);
ws->wh = NULL;
}
@@ -197,17 +227,6 @@ wire_cleanup (void *cls,
}
-/**
- * Create a "wire" command.
- *
- * @param label the command label.
- * @param expected_method which wire-transfer method is expected
- * to be offered by the exchange.
- * @param expected_fee the fee the exchange should charge.
- * @param expected_response_code the HTTP response the exchange
- * should return.
- * @return the command.
- */
struct TALER_TESTING_Command
TALER_TESTING_cmd_wire (const char *label,
const char *expected_method,
diff --git a/src/testing/testing_api_cmd_wire_add.c b/src/testing/testing_api_cmd_wire_add.c
index c07e9bba6..d2a15894a 100644
--- a/src/testing/testing_api_cmd_wire_add.c
+++ b/src/testing/testing_api_cmd_wire_add.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -67,27 +67,21 @@ struct WireAddState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param wer response details
*/
static void
wire_add_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementWireEnableResponse *wer)
{
struct WireAddState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &wer->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -110,10 +104,30 @@ wire_add_run (void *cls,
struct TALER_MasterSignatureP master_sig1;
struct TALER_MasterSignatureP master_sig2;
struct GNUNET_TIME_Timestamp now;
+ json_t *credit_rest;
+ json_t *debit_rest;
+ const char *exchange_url;
(void) cmd;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
now = GNUNET_TIME_timestamp_get ();
ds->is = is;
+ debit_rest = json_array ();
+ credit_rest = json_array ();
if (ds->bad_sig)
{
memset (&master_sig1,
@@ -125,23 +139,50 @@ wire_add_run (void *cls,
}
else
{
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
TALER_exchange_offline_wire_add_sign (ds->payto_uri,
+ NULL,
+ debit_rest,
+ credit_rest,
now,
- &is->master_priv,
+ master_priv,
&master_sig1);
TALER_exchange_wire_signature_make (ds->payto_uri,
- &is->master_priv,
+ NULL,
+ debit_rest,
+ credit_rest,
+ master_priv,
&master_sig2);
}
ds->dh = TALER_EXCHANGE_management_enable_wire (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
ds->payto_uri,
+ NULL,
+ debit_rest,
+ credit_rest,
now,
&master_sig1,
&master_sig2,
+ NULL,
+ 0LL,
&wire_add_cb,
ds);
+ json_decref (debit_rest);
+ json_decref (credit_rest);
if (NULL == ds->dh)
{
GNUNET_break (0);
@@ -166,10 +207,8 @@ wire_add_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_management_enable_wire_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_wire_del.c b/src/testing/testing_api_cmd_wire_del.c
index 15d29d727..50ebfc7cb 100644
--- a/src/testing/testing_api_cmd_wire_del.c
+++ b/src/testing/testing_api_cmd_wire_del.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
@@ -67,27 +67,22 @@ struct WireDelState
* if the response code is acceptable.
*
* @param cls closure.
- * @param hr HTTP response details
+ * @param wdr response details
*/
static void
wire_del_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr)
+ const struct TALER_EXCHANGE_ManagementWireDisableResponse *wdr)
{
struct WireDelState *ds = cls;
+ const struct TALER_EXCHANGE_HttpResponse *hr = &wdr->hr;
ds->dh = NULL;
if (ds->expected_response_code != hr->http_status)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u to command %s in %s:%u\n",
- hr->http_status,
- ds->is->commands[ds->is->ip].label,
- __FILE__,
- __LINE__);
- json_dumpf (hr->reply,
- stderr,
- 0);
- TALER_TESTING_interpreter_fail (ds->is);
+ TALER_TESTING_unexpected_status (ds->is,
+ hr->http_status,
+ ds->expected_response_code);
+
return;
}
TALER_TESTING_interpreter_next (ds->is);
@@ -109,8 +104,24 @@ wire_del_run (void *cls,
struct WireDelState *ds = cls;
struct TALER_MasterSignatureP master_sig;
struct GNUNET_TIME_Timestamp now;
+ const char *exchange_url;
(void) cmd;
+ {
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url));
+ }
now = GNUNET_TIME_timestamp_get ();
ds->is = is;
if (ds->bad_sig)
@@ -121,14 +132,28 @@ wire_del_run (void *cls,
}
else
{
+ const struct TALER_TESTING_Command *exchange_cmd;
+ const struct TALER_MasterPrivateKeyP *master_priv;
+
+ exchange_cmd = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_master_priv (exchange_cmd,
+ &master_priv));
TALER_exchange_offline_wire_del_sign (ds->payto_uri,
now,
- &is->master_priv,
+ master_priv,
&master_sig);
}
ds->dh = TALER_EXCHANGE_management_disable_wire (
- is->ctx,
- is->exchange_url,
+ TALER_TESTING_interpreter_get_context (is),
+ exchange_url,
ds->payto_uri,
now,
&master_sig,
@@ -158,10 +183,8 @@ wire_del_cleanup (void *cls,
if (NULL != ds->dh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %u (%s) did not complete\n",
- ds->is->ip,
- cmd->label);
+ TALER_TESTING_command_incomplete (ds->is,
+ cmd->label);
TALER_EXCHANGE_management_disable_wire_cancel (ds->dh);
ds->dh = NULL;
}
diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c
index 44e295338..f8ff0205b 100644
--- a/src/testing/testing_api_cmd_withdraw.c
+++ b/src/testing/testing_api_cmd_withdraw.c
@@ -62,11 +62,16 @@ struct WithdrawState
/**
* Reference to a withdraw or reveal operation from which we should
- * re-use the private coin key, or NULL for regular withdrawal.
+ * reuse the private coin key, or NULL for regular withdrawal.
*/
const char *reuse_coin_key_ref;
/**
+ * Our command.
+ */
+ const struct TALER_TESTING_Command *cmd;
+
+ /**
* String describing the denomination value we should withdraw.
* A corresponding denomination key must exist in the exchange's
* offerings. Can be NULL if @e pk is set instead.
@@ -108,7 +113,7 @@ struct WithdrawState
/**
* Blinding key used during the operation.
*/
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
/**
* Values contributed from the exchange during the
@@ -139,10 +144,10 @@ struct WithdrawState
/**
* If age > 0, put here the corresponding age commitment with its proof and
- * its hash, respectivelly, NULL otherwise.
+ * its hash, respectively.
*/
- struct TALER_AgeCommitmentProof *age_commitment_proof;
- struct TALER_AgeCommitmentHash *h_age_commitment;
+ struct TALER_AgeCommitmentProof age_commitment_proof;
+ struct TALER_AgeCommitmentHash h_age_commitment;
/**
* Reserve history entry that corresponds to this operation.
@@ -153,7 +158,7 @@ struct WithdrawState
/**
* Withdraw handle (while operation is running).
*/
- struct TALER_EXCHANGE_WithdrawHandle *wsh;
+ struct TALER_EXCHANGE_BatchWithdrawHandle *wsh;
/**
* Task scheduled to try later.
@@ -171,10 +176,16 @@ struct WithdrawState
struct GNUNET_TIME_Relative total_backoff;
/**
- * Set to the KYC UUID *if* the exchange replied with
+ * Set to the KYC requirement payto hash *if* the exchange replied with a
+ * request for KYC.
+ */
+ struct TALER_PaytoHashP h_payto;
+
+ /**
+ * Set to the KYC requirement row *if* the exchange replied with
* a request for KYC.
*/
- uint64_t kyc_uuid;
+ uint64_t requirement_row;
/**
* Expected HTTP response code to the request.
@@ -214,8 +225,7 @@ do_retry (void *cls)
struct WithdrawState *ws = cls;
ws->retry_task = NULL;
- ws->is->commands[ws->is->ip].last_req_time
- = GNUNET_TIME_absolute_get ();
+ TALER_TESTING_touch_cmd (ws->is);
withdraw_run (ws,
NULL,
ws->is);
@@ -232,7 +242,7 @@ do_retry (void *cls)
*/
static void
reserve_withdraw_cb (void *cls,
- const struct TALER_EXCHANGE_WithdrawResponse *wr)
+ const struct TALER_EXCHANGE_BatchWithdrawResponse *wr)
{
struct WithdrawState *ws = cls;
struct TALER_TESTING_Interpreter *is = ws->is;
@@ -266,48 +276,38 @@ reserve_withdraw_cb (void *cls,
UNKNOWN_MAX_BACKOFF);
ws->total_backoff = GNUNET_TIME_relative_add (ws->total_backoff,
ws->backoff);
- ws->is->commands[ws->is->ip].num_tries++;
+ TALER_TESTING_inc_tries (ws->is);
ws->retry_task = GNUNET_SCHEDULER_add_delayed (ws->backoff,
&do_retry,
ws);
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected response code %u/%d to command %s in %s:%u\n",
- wr->hr.http_status,
- (int) wr->hr.ec,
- TALER_TESTING_interpreter_get_current_label (is),
- __FILE__,
- __LINE__);
- json_dumpf (wr->hr.reply,
- stderr,
- 0);
- GNUNET_break (0);
- TALER_TESTING_interpreter_fail (is);
+ TALER_TESTING_unexpected_status_with_body (is,
+ wr->hr.http_status,
+ ws->expected_response_code,
+ wr->hr.reply);
return;
}
switch (wr->hr.http_status)
{
case MHD_HTTP_OK:
- TALER_denom_sig_deep_copy (&ws->sig,
- &wr->details.success.sig);
- ws->coin_priv = wr->details.success.coin_priv;
- ws->bks = wr->details.success.bks;
- ws->exchange_vals = wr->details.success.exchange_vals;
+ GNUNET_assert (1 == wr->details.ok.num_coins);
+ TALER_denom_sig_copy (&ws->sig,
+ &wr->details.ok.coins[0].sig);
+ ws->coin_priv = wr->details.ok.coins[0].coin_priv;
+ ws->bks = wr->details.ok.coins[0].bks;
+ TALER_denom_ewv_copy (&ws->exchange_vals,
+ &wr->details.ok.coins[0].exchange_vals);
if (0 != ws->total_backoff.rel_value_us)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Total withdraw backoff for %s was %s\n",
- is->commands[is->ip].label,
+ ws->cmd->label,
GNUNET_STRINGS_relative_time_to_string (ws->total_backoff,
- GNUNET_YES));
+ true));
}
break;
- case MHD_HTTP_ACCEPTED:
- /* nothing to check */
- ws->kyc_uuid = wr->details.accepted.payment_target_uuid;
- break;
case MHD_HTTP_FORBIDDEN:
/* nothing to check */
break;
@@ -320,6 +320,13 @@ reserve_withdraw_cb (void *cls,
case MHD_HTTP_GONE:
/* theoretically could check that the key was actually */
break;
+ case MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS:
+ /* KYC required */
+ ws->requirement_row =
+ wr->details.unavailable_for_legal_reasons.requirement_row;
+ ws->h_payto
+ = wr->details.unavailable_for_legal_reasons.h_payto;
+ break;
default:
/* Unsupported status code (by test harness) */
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -345,20 +352,19 @@ withdraw_run (void *cls,
const struct TALER_TESTING_Command *create_reserve;
const struct TALER_EXCHANGE_DenomPublicKey *dpk;
- (void) cmd;
+ if (NULL != cmd)
+ ws->cmd = cmd;
ws->is = is;
create_reserve
= TALER_TESTING_interpreter_lookup_command (
is,
ws->reserve_reference);
-
if (NULL == create_reserve)
{
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
-
if (GNUNET_OK !=
TALER_TESTING_get_trait_reserve_priv (create_reserve,
&rp))
@@ -367,15 +373,14 @@ withdraw_run (void *cls,
TALER_TESTING_interpreter_fail (is);
return;
}
-
if (NULL == ws->exchange_url)
ws->exchange_url
- = GNUNET_strdup (TALER_EXCHANGE_get_base_url (is->exchange));
+ = GNUNET_strdup (TALER_TESTING_get_exchange_url (is));
ws->reserve_priv = *rp;
GNUNET_CRYPTO_eddsa_key_get_public (&ws->reserve_priv.eddsa_priv,
&ws->reserve_pub.eddsa_pub);
ws->reserve_payto_uri
- = TALER_payto_from_reserve (ws->exchange_url,
+ = TALER_reserve_make_payto (ws->exchange_url,
&ws->reserve_pub);
if (NULL == ws->reuse_coin_key_ref)
@@ -406,7 +411,7 @@ withdraw_run (void *cls,
if (NULL == ws->pk)
{
- dpk = TALER_TESTING_find_pk (TALER_EXCHANGE_get_keys (is->exchange),
+ dpk = TALER_TESTING_find_pk (TALER_TESTING_get_keys (is),
&ws->amount,
ws->age > 0);
if (NULL == dpk)
@@ -437,13 +442,18 @@ withdraw_run (void *cls,
struct TALER_EXCHANGE_WithdrawCoinInput wci = {
.pk = ws->pk,
.ps = &ws->ps,
- .ach = ws->h_age_commitment
+ .ach = 0 < ws->age ? &ws->h_age_commitment : NULL
};
- ws->wsh = TALER_EXCHANGE_withdraw (is->exchange,
- rp,
- &wci,
- &reserve_withdraw_cb,
- ws);
+
+ ws->wsh = TALER_EXCHANGE_batch_withdraw (
+ TALER_TESTING_interpreter_get_context (is),
+ TALER_TESTING_get_exchange_url (is),
+ TALER_TESTING_get_keys (is),
+ rp,
+ 1,
+ &wci,
+ &reserve_withdraw_cb,
+ ws);
}
if (NULL == ws->wsh)
{
@@ -469,10 +479,9 @@ withdraw_cleanup (void *cls,
if (NULL != ws->wsh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Command %s did not complete\n",
- cmd->label);
- TALER_EXCHANGE_withdraw_cancel (ws->wsh);
+ TALER_TESTING_command_incomplete (ws->is,
+ cmd->label);
+ TALER_EXCHANGE_batch_withdraw_cancel (ws->wsh);
ws->wsh = NULL;
}
if (NULL != ws->retry_task)
@@ -481,21 +490,14 @@ withdraw_cleanup (void *cls,
ws->retry_task = NULL;
}
TALER_denom_sig_free (&ws->sig);
+ TALER_denom_ewv_free (&ws->exchange_vals);
if (NULL != ws->pk)
{
TALER_EXCHANGE_destroy_denomination_key (ws->pk);
ws->pk = NULL;
}
- if (NULL != ws->age_commitment_proof)
- {
- TALER_age_commitment_proof_free (ws->age_commitment_proof);
- ws->age_commitment_proof = NULL;
- }
- if (NULL != ws->h_age_commitment)
- {
- GNUNET_free (ws->h_age_commitment);
- ws->h_age_commitment = NULL;
- }
+ if (ws->age > 0)
+ TALER_age_commitment_proof_free (&ws->age_commitment_proof);
GNUNET_free (ws->exchange_url);
GNUNET_free (ws->reserve_payto_uri);
GNUNET_free (ws);
@@ -537,13 +539,18 @@ withdraw_traits (void *cls,
TALER_TESTING_make_trait_reserve_priv (&ws->reserve_priv),
TALER_TESTING_make_trait_reserve_pub (&ws->reserve_pub),
TALER_TESTING_make_trait_amount (&ws->amount),
- TALER_TESTING_make_trait_payment_target_uuid (&ws->kyc_uuid),
- TALER_TESTING_make_trait_payto_uri (
- (const char **) &ws->reserve_payto_uri),
- TALER_TESTING_make_trait_exchange_url (
- (const char **) &ws->exchange_url),
- TALER_TESTING_make_trait_age_commitment_proof (0, ws->age_commitment_proof),
- TALER_TESTING_make_trait_h_age_commitment (0, ws->h_age_commitment),
+ TALER_TESTING_make_trait_legi_requirement_row (&ws->requirement_row),
+ TALER_TESTING_make_trait_h_payto (&ws->h_payto),
+ TALER_TESTING_make_trait_payto_uri (ws->reserve_payto_uri),
+ TALER_TESTING_make_trait_exchange_url (ws->exchange_url),
+ TALER_TESTING_make_trait_age_commitment_proof (0,
+ 0 < ws->age
+ ? &ws->age_commitment_proof
+ : NULL),
+ TALER_TESTING_make_trait_h_age_commitment (0,
+ 0 < ws->age
+ ? &ws->h_age_commitment
+ : NULL),
TALER_TESTING_trait_end ()
};
@@ -560,45 +567,28 @@ struct TALER_TESTING_Command
TALER_TESTING_cmd_withdraw_amount (const char *label,
const char *reserve_reference,
const char *amount,
- const uint8_t age,
+ uint8_t age,
unsigned int expected_response_code)
{
struct WithdrawState *ws;
ws = GNUNET_new (struct WithdrawState);
-
ws->age = age;
if (0 < age)
{
- struct TALER_AgeCommitmentProof *acp;
- struct TALER_AgeCommitmentHash *hac;
struct GNUNET_HashCode seed;
struct TALER_AgeMask mask;
- acp = GNUNET_new (struct TALER_AgeCommitmentProof);
- hac = GNUNET_new (struct TALER_AgeCommitmentHash);
- mask = TALER_extensions_age_restriction_ageMask ();
+ mask = TALER_extensions_get_age_restriction_mask ();
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- if (GNUNET_OK !=
- TALER_age_restriction_commit (
- &mask,
- age,
- &seed,
- acp))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to generate age commitment for age %d at %s\n",
- age,
- label);
- GNUNET_assert (0);
- }
-
- TALER_age_commitment_hash (&acp->commitment,hac);
- ws->age_commitment_proof = acp;
- ws->h_age_commitment = hac;
+ TALER_age_restriction_commit (&mask,
+ age,
+ &seed,
+ &ws->age_commitment_proof);
+ TALER_age_commitment_hash (&ws->age_commitment_proof.commitment,
+ &ws->h_age_commitment);
}
ws->reserve_reference = reserve_reference;
diff --git a/src/testing/testing_api_helpers_auditor.c b/src/testing/testing_api_helpers_auditor.c
deleted file mode 100644
index b74258004..000000000
--- a/src/testing/testing_api_helpers_auditor.c
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_helpers_auditor.c
- * @brief helper functions
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_testing_lib.h"
-#include "taler_auditor_service.h"
-
-
-/**
- * Closure for #cleanup_auditor.
- */
-struct CleanupContext
-{
- /**
- * Where we find the state to clean up.
- */
- struct TALER_TESTING_Interpreter *is;
-
- /**
- * Next cleanup routine to call, NULL for none.
- */
- GNUNET_SCHEDULER_TaskCallback fcb;
-
- /**
- * Closure for @e fcb
- */
- void *fcb_cls;
-};
-
-
-/**
- * Function to clean up the auditor connection.
- *
- * @param cls a `struct CleanupContext`
- */
-static void
-cleanup_auditor (void *cls)
-{
- struct CleanupContext *cc = cls;
- struct TALER_TESTING_Interpreter *is = cc->is;
-
- TALER_AUDITOR_disconnect (is->auditor);
- is->auditor = NULL;
- if (NULL != cc->fcb)
- cc->fcb (cc->fcb_cls);
- GNUNET_free (cc);
-}
-
-
-/**
- * Closure for #auditor_main_wrapper()
- */
-struct MainWrapperContext
-{
- /**
- * Main function to launch.
- */
- TALER_TESTING_Main main_cb;
-
- /**
- * Closure for @e main_cb.
- */
- void *main_cb_cls;
-
- /**
- * Configuration we use.
- */
- const struct GNUNET_CONFIGURATION_Handle *cfg;
-
- /**
- * Name of the configuration file.
- */
- const char *config_filename;
-
-};
-
-
-/**
- * Function called with information about the auditor.
- *
- * @param cls closure
- * @param hr http response details
- * @param vi basic information about the auditor
- * @param compat protocol compatibility information
- */
-static void
-auditor_version_cb (void *cls,
- const struct TALER_AUDITOR_HttpResponse *hr,
- const struct TALER_AUDITOR_VersionInformation *vi,
- enum TALER_AUDITOR_VersionCompatibility compat)
-{
- struct TALER_TESTING_Interpreter *is = cls;
-
- (void) hr;
- if (TALER_AUDITOR_VC_MATCH != compat)
- {
- TALER_TESTING_interpreter_fail (is);
- return;
- }
- is->auditor_working = GNUNET_YES;
-}
-
-
-/**
- * Setup the @a is 'auditor' member before running the main test loop.
- *
- * @param cls must be a `struct MainWrapperContext *`
- * @param[in,out] is interpreter state to setup
- */
-static void
-auditor_main_wrapper (void *cls,
- struct TALER_TESTING_Interpreter *is)
-{
- struct MainWrapperContext *mwc = cls;
- struct CleanupContext *cc;
- char *auditor_base_url;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (mwc->cfg,
- "auditor",
- "BASE_URL",
- &auditor_base_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "BASE_URL");
- return;
- }
-
- is->auditor = TALER_AUDITOR_connect (is->ctx,
- auditor_base_url,
- &auditor_version_cb,
- is);
- GNUNET_free (auditor_base_url);
-
- if (NULL == is->auditor)
- {
- GNUNET_break (0);
- return;
- }
-
- cc = GNUNET_new (struct CleanupContext);
- cc->is = is;
- cc->fcb = is->final_cleanup_cb;
- cc->fcb_cls = is->final_cleanup_cb_cls;
- is->final_cleanup_cb = cleanup_auditor;
- is->final_cleanup_cb_cls = cc;
- mwc->main_cb (mwc->main_cb_cls,
- is);
-}
-
-
-/**
- * Install signal handlers plus schedules the main wrapper
- * around the "run" method.
- *
- * @param cls our `struct MainWrapperContext`
- * @param cfg configuration we use
- * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
- * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
- * times.
- */
-static int
-setup_with_cfg (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct MainWrapperContext *mwc = cls;
- struct TALER_TESTING_SetupContext setup_ctx = {
- .config_filename = mwc->config_filename,
- .main_cb = &auditor_main_wrapper,
- .main_cb_cls = mwc
- };
-
- mwc->cfg = cfg;
- return TALER_TESTING_setup_with_auditor_and_exchange_cfg (&setup_ctx,
- cfg);
-}
-
-
-/**
- * Install signal handlers plus schedules the main wrapper
- * around the "run" method.
- *
- * @param main_cb the "run" method which contains all the
- * commands.
- * @param main_cb_cls a closure for "run", typically NULL.
- * @param config_filename configuration filename.
- * @return #GNUNET_OK if all is okay, != #GNUNET_OK otherwise.
- * non-GNUNET_OK codes are #GNUNET_SYSERR most of the
- * times.
- */
-int
-TALER_TESTING_auditor_setup (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_filename)
-{
- struct MainWrapperContext mwc = {
- .main_cb = main_cb,
- .main_cb_cls = main_cb_cls,
- .config_filename = config_filename
- };
-
- return GNUNET_CONFIGURATION_parse_and_run (config_filename,
- &setup_with_cfg,
- &mwc);
-}
-
-
-/* end of testing_auditor_api_helpers.c */
diff --git a/src/testing/testing_api_helpers_bank.c b/src/testing/testing_api_helpers_bank.c
deleted file mode 100644
index 1ec2050a2..000000000
--- a/src/testing/testing_api_helpers_bank.c
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2018-2021 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-/**
- * @file testing/testing_api_helpers_bank.c
- * @brief convenience functions for bank tests.
- * @author Marcello Stanisci
- * @author Christian Grothoff
- */
-#include "platform.h"
-#include <gnunet/gnunet_util_lib.h>
-#include "taler_testing_lib.h"
-#include "taler_fakebank_lib.h"
-
-#define BANK_FAIL() \
- do {GNUNET_break (0); return NULL; } while (0)
-
-
-struct TALER_FAKEBANK_Handle *
-TALER_TESTING_run_fakebank (const char *bank_url,
- const char *currency)
-{
- const char *port;
- long pnum;
- struct TALER_FAKEBANK_Handle *fakebankd;
-
- port = strrchr (bank_url,
- (unsigned char) ':');
- if (NULL == port)
- pnum = 80;
- else
- pnum = strtol (port + 1, NULL, 10);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting Fakebank on port %u (%s)\n",
- (unsigned int) pnum,
- bank_url);
- fakebankd = TALER_FAKEBANK_start ((uint16_t) pnum,
- currency);
- if (NULL == fakebankd)
- {
- GNUNET_break (0);
- return NULL;
- }
- return fakebankd;
-}
-
-
-int
-TALER_TESTING_has_in_name (const char *prog,
- const char *marker)
-{
- size_t name_pos;
- size_t pos;
-
- if (! prog || ! marker)
- return GNUNET_NO;
-
- pos = 0;
- name_pos = 0;
- while (prog[pos])
- {
- if ('/' == prog[pos])
- name_pos = pos + 1;
- pos++;
- }
- if (name_pos == pos)
- return GNUNET_YES;
- return (NULL != strstr (prog + name_pos, marker));
-}
-
-
-struct TALER_TESTING_LibeufinServices
-TALER_TESTING_run_libeufin (const struct TALER_TESTING_BankConfiguration *bc)
-{
- struct GNUNET_OS_Process *nexus_proc;
- struct GNUNET_OS_Process *sandbox_proc;
- struct TALER_TESTING_LibeufinServices ret = { 0 };
- unsigned int iter;
- char *curl_check_cmd;
-
- nexus_proc = GNUNET_OS_start_process (
- GNUNET_OS_INHERIT_STD_ERR,
- NULL, NULL, NULL,
- "libeufin-nexus",
- "libeufin-nexus",
- "serve",
- "--db-name", "/tmp/nexus-exchange-test.sqlite3",
- NULL);
- if (NULL == nexus_proc)
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "exec",
- "libeufin-nexus");
- return ret;
- }
- GNUNET_asprintf (&curl_check_cmd,
- "curl -s %s",
- bc->exchange_auth.wire_gateway_url);
- /* give child time to start and bind against the socket */
- fprintf (stderr,
- "Waiting for `nexus' to be ready (via %s)\n", curl_check_cmd);
- iter = 0;
- do
- {
- if (10 == iter)
- {
- fprintf (
- stderr,
- "Failed to launch `nexus'\n");
- GNUNET_OS_process_kill (nexus_proc,
- SIGTERM);
- GNUNET_OS_process_wait (nexus_proc);
- GNUNET_OS_process_destroy (nexus_proc);
- GNUNET_free (curl_check_cmd);
- GNUNET_break (0);
- return ret;
- }
- fprintf (stderr, ".");
- sleep (1);
- iter++;
- }
- while (0 != system (curl_check_cmd));
-
- // start sandbox.
- GNUNET_free (curl_check_cmd);
- fprintf (stderr, "\n");
-
- sandbox_proc = GNUNET_OS_start_process (
- GNUNET_OS_INHERIT_STD_ERR,
- NULL, NULL, NULL,
- "libeufin-sandbox",
- "libeufin-sandbox",
- "serve",
- "--db-name", "/tmp/sandbox-exchange-test.sqlite3",
- NULL);
- if (NULL == sandbox_proc)
- {
- GNUNET_break (0);
- return ret;
- }
-
- /* give child time to start and bind against the socket */
- fprintf (stderr,
- "Waiting for `sandbox' to be ready.\n");
- iter = 0;
- do
- {
- if (10 == iter)
- {
- fprintf (
- stderr,
- "Failed to launch `sandbox'\n");
- GNUNET_OS_process_kill (sandbox_proc,
- SIGTERM);
- GNUNET_OS_process_wait (sandbox_proc);
- GNUNET_OS_process_destroy (sandbox_proc);
- GNUNET_break (0);
- return ret;
- }
- fprintf (stderr, ".");
- sleep (1);
- iter++;
- }
- while (0 != system ("curl -s http://localhost:5000/"));
- fprintf (stderr, "\n");
-
- // Creates nexus user + bank loopback connection + Taler facade.
- if (0 != system ("taler-nexus-prepare"))
- {
- GNUNET_OS_process_kill (nexus_proc, SIGTERM);
- GNUNET_OS_process_wait (nexus_proc);
- GNUNET_OS_process_destroy (nexus_proc);
- GNUNET_OS_process_kill (sandbox_proc, SIGTERM);
- GNUNET_OS_process_wait (sandbox_proc);
- GNUNET_OS_process_destroy (sandbox_proc);
- TALER_LOG_ERROR ("Could not prepare nexus\n");
- GNUNET_break (0);
- return ret;
- }
- ret.nexus = nexus_proc;
- ret.sandbox = sandbox_proc;
- return ret;
-}
-
-
-struct GNUNET_OS_Process *
-TALER_TESTING_run_bank (const char *config_filename,
- const char *bank_url)
-{
- struct GNUNET_OS_Process *bank_proc;
- unsigned int iter;
- char *wget_cmd;
- char *database;
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- config_filename))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- exit (77);
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "bank",
- "database",
- &database))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "bank",
- "database");
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- exit (77);
- }
- GNUNET_CONFIGURATION_destroy (cfg);
- bank_proc = GNUNET_OS_start_process (
- GNUNET_OS_INHERIT_STD_ERR,
- NULL, NULL, NULL,
- "taler-bank-manage-testing",
- "taler-bank-manage-testing",
- config_filename,
- database,
- "serve", NULL);
- GNUNET_free (database);
- if (NULL == bank_proc)
- {
- BANK_FAIL ();
- }
-
- GNUNET_asprintf (&wget_cmd,
- "wget -q -t 2 -T 1 %s -o /dev/null -O /dev/null",
- bank_url);
-
- /* give child time to start and bind against the socket */
- fprintf (stderr,
- "Waiting for `taler-bank-manage' to be ready (via %s)\n", wget_cmd);
- iter = 0;
- do
- {
- if (10 == iter)
- {
- fprintf (
- stderr,
- "Failed to launch `taler-bank-manage' (or `wget')\n");
- GNUNET_OS_process_kill (bank_proc,
- SIGTERM);
- GNUNET_OS_process_wait (bank_proc);
- GNUNET_OS_process_destroy (bank_proc);
- GNUNET_free (wget_cmd);
- BANK_FAIL ();
- }
- fprintf (stderr, ".");
- sleep (1);
- iter++;
- }
- while (0 != system (wget_cmd));
- GNUNET_free (wget_cmd);
- fprintf (stderr, "\n");
-
- return bank_proc;
-
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_nexus (const char *config_filename,
- int reset_db,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc)
-{
- struct GNUNET_CONFIGURATION_Handle *cfg;
- unsigned long long port;
- char *database = NULL; // silence compiler
- char *exchange_payto_uri;
-
- GNUNET_assert (0 ==
- strncasecmp (config_section,
- "exchange-account-",
- strlen ("exchange-account-")));
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- config_filename))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- config_section,
- "PAYTO_URI",
- &exchange_payto_uri))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- config_section,
- "PAYTO_URI");
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "bank",
- "HTTP_PORT",
- &port))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "bank",
- "HTTP_PORT");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (database);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
- (uint16_t) port))
- {
- fprintf (stderr,
- "Required port %llu not available, skipping.\n",
- port);
- GNUNET_break (0);
- GNUNET_free (database);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
-
- /* DB preparation */
- if (GNUNET_YES == reset_db)
- {
- if (0 != system (
- "rm -f /tmp/nexus-exchange-test.sqlite3 && rm -f /tmp/sandbox-exchange-test.sqlite3"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to invoke db-removal command.\n");
- GNUNET_free (database);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
- }
-
- {
- char *csn;
-
- GNUNET_asprintf (&csn,
- "exchange-accountcredentials-%s",
- &config_section[strlen ("exchange-account-")]);
-
-
- if (GNUNET_OK !=
- TALER_BANK_auth_parse_cfg (cfg,
- csn,
- &bc->exchange_auth))
- {
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (csn);
- return GNUNET_SYSERR;
- }
- GNUNET_free (csn);
- }
- GNUNET_CONFIGURATION_destroy (cfg);
- bc->exchange_payto = exchange_payto_uri;
- bc->user42_payto =
- "payto://iban/BIC/FR7630006000011234567890189?receiver-name=User42";
- bc->user43_payto =
- "payto://iban/BIC/GB33BUKB20201555555555?receiver-name=User43";
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Relying on nexus %s on port %u\n",
- bc->exchange_auth.wire_gateway_url,
- (unsigned int) port);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exchange payto: %s\n",
- bc->exchange_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
- bc->user42_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
- bc->user43_payto);
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_bank (const char *config_filename,
- int reset_db,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc)
-{
- struct GNUNET_CONFIGURATION_Handle *cfg;
- unsigned long long port;
- struct GNUNET_OS_Process *dbreset_proc;
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
- char *database;
- char *exchange_payto_uri;
-
- GNUNET_assert (0 ==
- strncasecmp (config_section,
- "exchange-account-",
- strlen ("exchange-account-")));
- cfg = GNUNET_CONFIGURATION_create ();
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_load (cfg,
- config_filename))
- {
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "bank",
- "DATABASE",
- &database))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "bank",
- "DATABASE");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- config_section,
- "PAYTO_URI",
- &exchange_payto_uri))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- config_section,
- "PAYTO_URI");
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "bank",
- "HTTP_PORT",
- &port))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "bank",
- "HTTP_PORT");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (database);
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_OK !=
- GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
- (uint16_t) port))
- {
- fprintf (stderr,
- "Required port %llu not available, skipping.\n",
- port);
- GNUNET_break (0);
- GNUNET_free (database);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
-
- /* DB preparation */
- if (GNUNET_YES == reset_db)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Flushing bank database\n");
- if (NULL ==
- (dbreset_proc = GNUNET_OS_start_process (
- GNUNET_OS_INHERIT_STD_ERR,
- NULL, NULL, NULL,
- "taler-bank-manage",
- "taler-bank-manage",
- "-c", config_filename,
- "--with-db", database,
- "django",
- "flush",
- "--no-input", NULL)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to flush the bank db.\n");
- GNUNET_free (database);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
-
- if (GNUNET_SYSERR ==
- GNUNET_OS_process_wait_status (dbreset_proc,
- &type,
- &code))
- {
- GNUNET_OS_process_destroy (dbreset_proc);
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (database);
- return GNUNET_SYSERR;
- }
- if ( (type == GNUNET_OS_PROCESS_EXITED) &&
- (0 != code) )
- {
- fprintf (stderr,
- "Failed to setup database `%s'\n",
- database);
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (database);
- return GNUNET_SYSERR;
- }
- GNUNET_free (database);
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (0 != code) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected error running `taler-bank-manage django flush'!\n");
- GNUNET_break (0);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
- GNUNET_OS_process_destroy (dbreset_proc);
- }
- {
- char *csn;
-
- GNUNET_asprintf (&csn,
- "exchange-accountcredentials-%s",
- &config_section[strlen ("exchange-account-")]);
-
- if (GNUNET_OK !=
- TALER_BANK_auth_parse_cfg (cfg,
- csn,
- &bc->exchange_auth))
- {
- GNUNET_break (0);
- GNUNET_free (csn);
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
- GNUNET_free (csn);
- }
- GNUNET_CONFIGURATION_destroy (cfg);
- bc->exchange_payto = exchange_payto_uri;
- bc->user42_payto = "payto://x-taler-bank/localhost/42?receiver-name=42";
- bc->user43_payto = "payto://x-taler-bank/localhost/43?receiver-name=43";
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Using pybank %s on port %u\n",
- bc->exchange_auth.wire_gateway_url,
- (unsigned int) port);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "exchange payto: %s\n",
- bc->exchange_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "user42_payto: %s\n",
- bc->user42_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "user43_payto: %s\n",
- bc->user43_payto);
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_fakebank (const char *config_filename,
- const char *config_section,
- struct TALER_TESTING_BankConfiguration *bc)
-{
- struct GNUNET_CONFIGURATION_Handle *cfg;
- unsigned long long fakebank_port;
- char *exchange_payto_uri;
-
- cfg = GNUNET_CONFIGURATION_create ();
- if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
- config_filename))
- return GNUNET_SYSERR;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "BANK",
- "HTTP_PORT",
- &fakebank_port))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "BANK",
- "HTTP_PORT");
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- config_section,
- "PAYTO_URI",
- &exchange_payto_uri))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- config_section,
- "PAYTO_URI");
- GNUNET_CONFIGURATION_destroy (cfg);
- return GNUNET_SYSERR;
- }
- {
- char *exchange_xtalerbank_account;
-
- exchange_xtalerbank_account
- = TALER_xtalerbank_account_from_payto (exchange_payto_uri);
- if (NULL == exchange_xtalerbank_account)
- {
- GNUNET_break (0);
- GNUNET_free (exchange_payto_uri);
- return GNUNET_SYSERR;
- }
- GNUNET_asprintf (&bc->exchange_auth.wire_gateway_url,
- "http://localhost:%u/%s/",
- (unsigned int) fakebank_port,
- exchange_xtalerbank_account);
- GNUNET_free (exchange_xtalerbank_account);
- }
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Using fakebank %s on port %u\n",
- bc->exchange_auth.wire_gateway_url,
- (unsigned int) fakebank_port);
-
- GNUNET_CONFIGURATION_destroy (cfg);
- if (GNUNET_OK !=
- TALER_TESTING_url_port_free (bc->exchange_auth.wire_gateway_url))
- {
- GNUNET_free (bc->exchange_auth.wire_gateway_url);
- bc->exchange_auth.wire_gateway_url = NULL;
- GNUNET_free (exchange_payto_uri);
- return GNUNET_SYSERR;
- }
- /* Now we know it's the fake bank, for purpose of authentication, we
- * don't have any auth. */
- bc->exchange_auth.method = TALER_BANK_AUTH_NONE;
- bc->exchange_payto = exchange_payto_uri;
- bc->user42_payto = "payto://x-taler-bank/localhost/42?receiver-name=42";
- bc->user43_payto = "payto://x-taler-bank/localhost/43?receiver-name=43";
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "exchange payto: %s\n",
- bc->exchange_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user42_payto: %s\n",
- bc->user42_payto);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "user43_payto: %s\n",
- bc->user43_payto);
- return GNUNET_OK;
-}
-
-
-json_t *
-TALER_TESTING_make_wire_details (const char *payto)
-{
- struct TALER_WireSaltP salt;
-
- /* salt must be constant for aggregation tests! */
- memset (&salt,
- 47,
- sizeof (salt));
- return GNUNET_JSON_PACK (
- GNUNET_JSON_pack_string ("payto_uri",
- payto),
- GNUNET_JSON_pack_data_auto ("salt",
- &salt));
-}
-
-
-/* end of testing_api_helpers_bank.c */
diff --git a/src/testing/testing_api_helpers_exchange.c b/src/testing/testing_api_helpers_exchange.c
deleted file mode 100644
index d813021bd..000000000
--- a/src/testing/testing_api_helpers_exchange.c
+++ /dev/null
@@ -1,983 +0,0 @@
-/*
- This file is part of TALER
- Copyright (C) 2018-2020 Taler Systems SA
-
- TALER is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 3, or
- (at your option) any later version.
-
- TALER is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with TALER; see the file COPYING. If not, see
- <http://www.gnu.org/licenses/>
-*/
-
-/**
- * @file testing/testing_api_helpers_exchange.c
- * @brief helper functions
- * @author Christian Grothoff
- * @author Marcello Stanisci
- */
-#include "platform.h"
-#include "taler_json_lib.h"
-#include <gnunet/gnunet_curl_lib.h>
-#include "taler_signatures.h"
-#include "taler_extensions.h"
-#include "taler_testing_lib.h"
-
-/**
- * Run multiple taler-exchange-httpd processes in
- * parallel using GNU parallel?
- */
-#define GNU_PARALLEL 0
-
-
-void
-TALER_TESTING_cleanup_files (const char *config_name)
-{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse_and_run (config_name,
- &TALER_TESTING_cleanup_files_cfg,
- NULL))
- exit (77);
-}
-
-
-/**
- * Remove @a option directory from @a section in @a cfg.
- *
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-remove_dir (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const char *section,
- const char *option)
-{
- char *dir;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- section,
- option,
- &dir))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- section,
- option);
- return GNUNET_SYSERR;
- }
- if (GNUNET_YES ==
- GNUNET_DISK_directory_test (dir,
- GNUNET_NO))
- GNUNET_break (GNUNET_OK ==
- GNUNET_DISK_directory_remove (dir));
- GNUNET_free (dir);
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_cleanup_files_cfg (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- char *dir;
-
- (void) cls;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "exchange-offline",
- "SECM_TOFU_FILE",
- &dir))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-offline",
- "SECM_TOFU_FILE");
- return GNUNET_SYSERR;
- }
- if ( (0 != unlink (dir)) &&
- (ENOENT != errno) )
- {
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
- "unlink",
- dir);
- GNUNET_free (dir);
- return GNUNET_SYSERR;
- }
- GNUNET_free (dir);
- if (GNUNET_OK !=
- remove_dir (cfg,
- "taler-exchange-secmod-eddsa",
- "KEY_DIR"))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- remove_dir (cfg,
- "taler-exchange-secmod-rsa",
- "KEY_DIR"))
- return GNUNET_SYSERR;
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_run_auditor_exchange (const char *config_filename,
- const char *exchange_master_pub,
- const char *exchange_base_url,
- int do_remove)
-{
- struct GNUNET_OS_Process *proc;
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
-
- TALER_LOG_DEBUG ("Add exchange (%s,%s) to the auditor\n",
- exchange_base_url,
- exchange_master_pub);
-
- proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-auditor-exchange",
- "taler-auditor-exchange",
- "-c", config_filename,
- "-u", exchange_base_url,
- "-m", exchange_master_pub,
- (GNUNET_YES == do_remove)
- ? "-r"
- : NULL,
- NULL);
- if (NULL == proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `taler-auditor-exchange`, is your PATH correct?\n");
- return GNUNET_SYSERR;
- }
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait_status (proc,
- &type,
- &code));
- GNUNET_OS_process_destroy (proc);
- if ( (0 != code) ||
- (GNUNET_OS_PROCESS_EXITED != type) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "taler-auditor-exchange terminated with error (%d/%d)\n",
- (int) type,
- (int) code);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_exchange_db_reset (const char *config_filename)
-{
- struct GNUNET_OS_Process *proc;
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
-
- proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-exchange-dbinit",
- "taler-exchange-dbinit",
- "-c", config_filename,
- "-L", "WARNING",
- "-r",
- NULL);
- if (NULL == proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `taler-exchange-dbinit`, is your PATH correct?\n");
- return GNUNET_NO;
- }
- if (GNUNET_SYSERR ==
- GNUNET_OS_process_wait_status (proc,
- &type,
- &code))
- {
- GNUNET_break (0);
- GNUNET_OS_process_destroy (proc);
- return GNUNET_SYSERR;
- }
- GNUNET_OS_process_destroy (proc);
- if ( (type == GNUNET_OS_PROCESS_EXITED) &&
- (0 != code) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup (exchange) database, exit code %d\n",
- (int) code);
- return GNUNET_NO;
- }
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (0 != code) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected error (%d/%d) running `taler-exchange-dbinit'!\n",
- (int) type,
- (int) code);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_auditor_db_reset (const char *config_filename)
-{
- struct GNUNET_OS_Process *proc;
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
-
- proc = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-auditor-dbinit",
- "taler-auditor-dbinit",
- "-c", config_filename,
- "-R",
- NULL);
- if (NULL == proc)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to run `taler-auditor-dbinit`, is your PATH correct?\n");
- return GNUNET_NO;
- }
- if (GNUNET_SYSERR ==
- GNUNET_OS_process_wait_status (proc,
- &type,
- &code))
- {
- GNUNET_break (0);
- GNUNET_OS_process_destroy (proc);
- return GNUNET_SYSERR;
- }
- GNUNET_OS_process_destroy (proc);
- if ( (type == GNUNET_OS_PROCESS_EXITED) &&
- (0 != code) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup (auditor) database, exit code %d\n",
- (int) code);
- return GNUNET_NO;
- }
- if ( (type != GNUNET_OS_PROCESS_EXITED) ||
- (0 != code) )
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unexpected error (%d/%d) running `taler-auditor-dbinit'!\n",
- (int) type,
- (int) code);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/**
- * Type of closure for
- * #sign_keys_for_exchange.
- */
-struct SignInfo
-{
- /**
- * Members will be set to the exchange configuration.
- */
- struct TALER_TESTING_ExchangeConfiguration *ec;
-
- /**
- * Name of the configuration file to use.
- */
- const char *config_filename;
-
- /**
- * Did we reset the database?
- */
- int db_reset;
-};
-
-
-/**
- * Sign the keys for an exchange given configuration @a cfg.
- * The information to be signed must be in a file "auditor.in".
- *
- * @param[in,out] cls a `struct SignInfo` with further parameters
- * @param cfg configuration to use
- * @return #GNUNET_OK on success
- */
-static enum GNUNET_GenericReturnValue
-sign_keys_for_exchange (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct SignInfo *si = cls;
- char *exchange_master_pub;
- int ret;
-
- /* Load the age restriction mask from the configuration */
- TALER_extensions_load_taler_config (cfg);
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange",
- "BASE_URL",
- &si->ec->exchange_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "exchange",
- "BASE_URL");
- si->ec->exchange_url = NULL;
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "auditor",
- "BASE_URL",
- &si->ec->auditor_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
- "auditor",
- "BASE_URL");
- GNUNET_free (si->ec->exchange_url);
- si->ec->exchange_url = NULL;
- si->ec->auditor_url = NULL;
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange",
- "MASTER_PUBLIC_KEY",
- &exchange_master_pub))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "MASTER_PUBLIC_KEY");
- ret = GNUNET_SYSERR;
- goto fail;
- }
- if ( (GNUNET_OK !=
- TALER_TESTING_run_auditor_exchange (si->config_filename,
- exchange_master_pub,
- si->ec->exchange_url,
- GNUNET_NO)) &&
- (GNUNET_YES == si->db_reset) )
- {
- ret = GNUNET_NO;
- goto fail;
- }
- GNUNET_free (exchange_master_pub);
- return GNUNET_OK;
-fail:
- GNUNET_free (si->ec->exchange_url);
- GNUNET_free (si->ec->auditor_url);
- si->ec->exchange_url = NULL;
- si->ec->auditor_url = NULL;
- return ret;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_prepare_exchange (const char *config_filename,
- int reset_db,
- struct TALER_TESTING_ExchangeConfiguration *ec)
-{
- struct SignInfo si = {
- .config_filename = config_filename,
- .ec = ec,
- .db_reset = reset_db
- };
-
- if (GNUNET_YES == reset_db)
- {
- if (GNUNET_OK !=
- TALER_TESTING_exchange_db_reset (config_filename))
- return GNUNET_NO;
- if (GNUNET_OK !=
- TALER_TESTING_auditor_db_reset (config_filename))
- return GNUNET_NO;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_parse_and_run (config_filename,
- &sign_keys_for_exchange,
- &si))
- return GNUNET_NO;
- return GNUNET_OK;
-}
-
-
-const struct TALER_EXCHANGE_DenomPublicKey *
-TALER_TESTING_find_pk (const struct TALER_EXCHANGE_Keys *keys,
- const struct TALER_Amount *amount,
- bool age_restricted)
-{
- struct GNUNET_TIME_Timestamp now;
- struct TALER_EXCHANGE_DenomPublicKey *pk;
- char *str;
-
- now = GNUNET_TIME_timestamp_get ();
- for (unsigned int i = 0; i<keys->num_denom_keys; i++)
- {
- pk = &keys->denom_keys[i];
- if ( (0 == TALER_amount_cmp (amount,
- &pk->value)) &&
- (GNUNET_TIME_timestamp_cmp (now,
- >=,
- pk->valid_from)) &&
- (GNUNET_TIME_timestamp_cmp (now,
- <,
- pk->withdraw_valid_until)) &&
- (age_restricted == (0 != pk->key.age_mask.bits)) )
- return pk;
- }
- /* do 2nd pass to check if expiration times are to blame for
- * failure */
- str = TALER_amount_to_string (amount);
- for (unsigned int i = 0; i<keys->num_denom_keys; i++)
- {
- pk = &keys->denom_keys[i];
- if ( (0 == TALER_amount_cmp (amount,
- &pk->value)) &&
- (GNUNET_TIME_timestamp_cmp (now,
- <,
- pk->valid_from) ||
- GNUNET_TIME_timestamp_cmp (now,
- >,
- pk->withdraw_valid_until) ) &&
- (age_restricted == (0 != pk->key.age_mask.bits)) )
- {
- GNUNET_log
- (GNUNET_ERROR_TYPE_WARNING,
- "Have denomination key for `%s', but with wrong"
- " expiration range %llu vs [%llu,%llu)\n",
- str,
- (unsigned long long) now.abs_time.abs_value_us,
- (unsigned long long) pk->valid_from.abs_time.abs_value_us,
- (unsigned long long) pk->withdraw_valid_until.abs_time.abs_value_us);
- GNUNET_free (str);
- return NULL;
- }
- }
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "No denomination key for amount %s found\n",
- str);
- GNUNET_free (str);
- return NULL;
-}
-
-
-int
-TALER_TESTING_wait_exchange_ready (const char *base_url)
-{
- char *wget_cmd;
- unsigned int iter;
-
- GNUNET_asprintf (&wget_cmd,
- "wget -q -t 1 -T 1 %sseed -o /dev/null -O /dev/null",
- base_url); // make sure ends with '/'
- /* give child time to start and bind against the socket */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Waiting for `taler-exchange-httpd` service to be ready (check with: %s)\n",
- wget_cmd);
- iter = 0;
- do
- {
- if (10 == iter)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to launch `taler-exchange-httpd` service (or `wget')\n");
- GNUNET_free (wget_cmd);
- return 77;
- }
- sleep (1);
- iter++;
- }
- while (0 != system (wget_cmd));
- GNUNET_free (wget_cmd);
- return 0;
-}
-
-
-int
-TALER_TESTING_wait_httpd_ready (const char *base_url)
-{
- char *wget_cmd;
- unsigned int iter;
-
- GNUNET_asprintf (&wget_cmd,
- "wget -q -t 1 -T 1 %s -o /dev/null -O /dev/null",
- base_url); // make sure ends with '/'
- /* give child time to start and bind against the socket */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Waiting for HTTP service to be ready (check with: %s)\n",
- wget_cmd);
- iter = 0;
- do
- {
- if (10 == iter)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Failed to launch HTTP service (or `wget')\n");
- GNUNET_free (wget_cmd);
- return 77;
- }
- sleep (1);
- iter++;
- }
- while (0 != system (wget_cmd));
- GNUNET_free (wget_cmd);
- return 0;
-}
-
-
-/**
- * Wait for the auditor to have started. Waits for at
- * most 10s, after that returns 77 to indicate an error.
- *
- * @param base_url what URL should we expect the auditor
- * to be running at
- * @return 0 on success
- */
-int
-TALER_TESTING_wait_auditor_ready (const char *base_url)
-{
- char *wget_cmd;
- unsigned int iter;
-
- GNUNET_asprintf (&wget_cmd,
- "wget -q -t 1 -T 1 %sversion -o /dev/null -O /dev/null",
- base_url); // make sure ends with '/'
- /* give child time to start and bind against the socket */
- fprintf (stderr,
- "Waiting for `taler-auditor-httpd' to be ready at %s\n",
- base_url);
- iter = 0;
- do
- {
- if (10 == iter)
- {
- fprintf (stderr,
- "Failed to launch `taler-auditor-httpd' (or `wget')\n");
- GNUNET_free (wget_cmd);
- return 77;
- }
- fprintf (stderr, ".\n");
- sleep (1);
- iter++;
- }
- while (0 != system (wget_cmd));
- GNUNET_free (wget_cmd);
- return 0;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_exchange (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_file)
-{
- struct TALER_TESTING_SetupContext setup_ctx = {
- .config_filename = config_file,
- .main_cb = main_cb,
- .main_cb_cls = main_cb_cls
- };
- enum GNUNET_GenericReturnValue result;
-
- result =
- GNUNET_CONFIGURATION_parse_and_run (config_file,
- &TALER_TESTING_setup_with_exchange_cfg,
- &setup_ctx);
- if (GNUNET_OK != result)
- return result;
- return GNUNET_OK;
-}
-
-
-/**
- * Stop taler-exchange-crypto helpers.
- *
- * @param[in] helpers the process handles.
- */
-static void
-stop_helpers (struct GNUNET_OS_Process *helpers[3])
-{
- for (unsigned int i = 0; i<3; i++)
- {
- if (NULL == helpers[i])
- continue;
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (helpers[i],
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (helpers[i]));
- GNUNET_OS_process_destroy (helpers[i]);
- }
-}
-
-
-/**
- * Start taler-exchange-crypto helpers.
- *
- * @param config_filename configuration file to use
- * @param[out] helpers where to store the process handles.
- */
-static enum GNUNET_GenericReturnValue
-start_helpers (const char *config_filename,
- struct GNUNET_OS_Process *helpers[3])
-{
- char *dir;
- const struct GNUNET_OS_ProjectData *pd;
-
- pd = GNUNET_OS_project_data_get ();
- GNUNET_OS_init (TALER_project_data_default ());
- dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
- GNUNET_OS_init (pd);
- if (NULL == dir)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- {
- char *fn;
-
- GNUNET_asprintf (&fn,
- "%s/%s",
- dir,
- "taler-exchange-secmod-eddsa");
- helpers[0] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- fn,
- "taler-exchange-secmod-eddsa",
- "-c", config_filename,
- "-L", "INFO",
- NULL);
- GNUNET_free (fn);
- }
- {
- char *fn;
-
- GNUNET_asprintf (&fn,
- "%s/%s",
- dir,
- "taler-exchange-secmod-rsa");
- helpers[1] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- fn,
- "taler-exchange-secmod-rsa",
- "-c", config_filename,
- "-L", "INFO",
- NULL);
- GNUNET_free (fn);
- }
- {
- char *fn;
-
- GNUNET_asprintf (&fn,
- "%s/%s",
- dir,
- "taler-exchange-secmod-cs");
- helpers[2] = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- fn,
- "taler-exchange-secmod-cs",
- "-c", config_filename,
- "-L", "INFO",
- NULL);
- GNUNET_free (fn);
- }
- GNUNET_free (dir);
- if ( (NULL == helpers[0]) ||
- (NULL == helpers[1]) ||
- (NULL == helpers[2]) )
- {
- stop_helpers (helpers);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_exchange_cfg (
- void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- const struct TALER_TESTING_SetupContext *setup_ctx = cls;
- struct GNUNET_OS_Process *exchanged;
- struct GNUNET_OS_Process *helpers[3];
- unsigned long long port;
- char *serve;
- char *base_url;
- int result;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange",
- "SERVE",
- &serve))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "SERVE");
- return GNUNET_NO;
- }
-
- if (0 == strcmp ("tcp",
- serve))
- {
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "exchange",
- "PORT",
- &port))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "PORT");
- GNUNET_free (serve);
- return GNUNET_NO;
- }
-
- if (GNUNET_OK !=
- GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
- (uint16_t) port))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Required port %llu not available, skipping.\n",
- port);
- GNUNET_free (serve);
- return GNUNET_NO;
- }
- }
- GNUNET_free (serve);
- if (GNUNET_OK !=
- start_helpers (setup_ctx->config_filename,
- helpers))
- {
- GNUNET_break (0);
- return 77;
- }
- exchanged = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
-#if GNU_PARALLEL
- "parallel",
-#endif
- "taler-exchange-httpd",
- "taler-exchange-httpd",
- "-L", "INFO",
- "-a", /* some tests may need timetravel */
- "-c", setup_ctx->config_filename,
-#if GNU_PARALLEL
- "-r",
- ":::",
- "-",
- "-",
- "-",
- "-",
-#endif
- NULL);
- if (NULL == exchanged)
- {
- GNUNET_break (0);
- stop_helpers (helpers);
- return 77;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "exchange",
- "BASE_URL",
- &base_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "BASE_URL");
- stop_helpers (helpers);
- return GNUNET_NO;
- }
-
- if (0 != TALER_TESTING_wait_exchange_ready (base_url))
- {
- GNUNET_free (base_url);
- stop_helpers (helpers);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (exchanged,
- SIGTERM));
-#if GNU_PARALLEL
- /* GNU Parallel kills on 2nd SIGTERM, need to give it a
- chance to process the 1st signal first... */
- sleep (1);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (exchanged,
- SIGTERM));
-#endif
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (exchanged));
- GNUNET_OS_process_destroy (exchanged);
- return 77;
- }
- GNUNET_free (base_url);
-
- /* NOTE: this call blocks. */
- result = TALER_TESTING_setup (setup_ctx->main_cb,
- setup_ctx->main_cb_cls,
- cfg,
- exchanged,
- GNUNET_YES);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (exchanged,
- SIGTERM));
-#if GNU_PARALLEL
- /* GNU Parallel kills on 2nd SIGTERM, need to give it a
- chance to process the 1st signal first... */
- sleep (1);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (exchanged,
- SIGTERM));
-#endif
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (exchanged));
- GNUNET_OS_process_destroy (exchanged);
- stop_helpers (helpers);
- return result;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_auditor_and_exchange_cfg (
- void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- const struct TALER_TESTING_SetupContext *setup_ctx = cls;
- struct GNUNET_OS_Process *auditord;
- unsigned long long port;
- char *serve;
- char *base_url;
- int result;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "auditor",
- "SERVE",
- &serve))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "SERVE");
- return GNUNET_NO;
- }
-
- if (0 == strcmp ("tcp", serve))
- {
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "auditor",
- "PORT",
- &port))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "PORT");
- GNUNET_free (serve);
- return GNUNET_NO;
- }
-
- if (GNUNET_OK !=
- GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
- (uint16_t) port))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Required port %llu not available, skipping.\n",
- port);
- GNUNET_free (serve);
- return GNUNET_NO;
- }
- }
- GNUNET_free (serve);
- auditord = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
- NULL, NULL, NULL,
- "taler-auditor-httpd",
- "taler-auditor-httpd",
- "-c", setup_ctx->config_filename,
- NULL);
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "auditor",
- "BASE_URL",
- &base_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "BASE_URL");
- return GNUNET_NO;
- }
-
- if (0 != TALER_TESTING_wait_auditor_ready (base_url))
- {
- GNUNET_free (base_url);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (auditord,
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (auditord));
- GNUNET_OS_process_destroy (auditord);
- return 77;
- }
- GNUNET_free (base_url);
-
- /* NOTE: this call blocks. */
- result = TALER_TESTING_setup_with_exchange_cfg ((void *) setup_ctx,
- cfg);
- GNUNET_break (0 ==
- GNUNET_OS_process_kill (auditord,
- SIGTERM));
- GNUNET_break (GNUNET_OK ==
- GNUNET_OS_process_wait (auditord));
- GNUNET_OS_process_destroy (auditord);
- return result;
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup_with_auditor_and_exchange (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const char *config_file)
-{
- struct TALER_TESTING_SetupContext setup_ctx = {
- .config_filename = config_file,
- .main_cb = main_cb,
- .main_cb_cls = main_cb_cls
- };
-
- return GNUNET_CONFIGURATION_parse_and_run (
- config_file,
- &TALER_TESTING_setup_with_auditor_and_exchange_cfg,
- &setup_ctx);
-}
-
-
-enum GNUNET_GenericReturnValue
-TALER_TESTING_url_port_free (const char *url)
-{
- const char *port;
- long pnum;
-
- port = strrchr (url,
- (unsigned char) ':');
- if (NULL == port)
- pnum = 80;
- else
- pnum = strtol (port + 1, NULL, 10);
- if (GNUNET_OK !=
- GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
- pnum))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Port %u not available.\n",
- (unsigned int) pnum);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
-}
-
-
-/* end of testing_api_helpers_exchange.c */
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 190e20928..0f242f7f1 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2018 Taler Systems SA
+ Copyright (C) 2018-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
@@ -26,15 +26,65 @@
#include "platform.h"
#include "taler_json_lib.h"
#include <gnunet/gnunet_curl_lib.h>
+#include "taler_extensions.h"
#include "taler_signatures.h"
#include "taler_testing_lib.h"
-#include "taler_fakebank_lib.h"
+
/**
- * Pipe used to communicate child death via signal.
- * Must be global, as used in signal handler!
+ * The interpreter and its state
*/
-static struct GNUNET_DISK_PipeHandle *sigpipe;
+struct TALER_TESTING_Interpreter
+{
+
+ /**
+ * Commands the interpreter will run.
+ */
+ struct TALER_TESTING_Command *commands;
+
+ /**
+ * Interpreter task (if one is scheduled).
+ */
+ struct GNUNET_SCHEDULER_Task *task;
+
+ /**
+ * Handle for the child management.
+ */
+ struct GNUNET_ChildWaitHandle *cwh;
+
+ /**
+ * Main execution context for the main loop.
+ */
+ struct GNUNET_CURL_Context *ctx;
+
+ /**
+ * Context for running the CURL event loop.
+ */
+ struct GNUNET_CURL_RescheduleContext *rc;
+
+ /**
+ * Hash map mapping variable names to commands.
+ */
+ struct GNUNET_CONTAINER_MultiHashMap *vars;
+
+ /**
+ * Task run on timeout.
+ */
+ struct GNUNET_SCHEDULER_Task *timeout_task;
+
+ /**
+ * Instruction pointer. Tells #interpreter_run() which instruction to run
+ * next. Need (signed) int because it gets -1 when rewinding the
+ * interpreter to the first CMD.
+ */
+ int ip;
+
+ /**
+ * Result of the testcases, #GNUNET_OK on success
+ */
+ enum GNUNET_GenericReturnValue result;
+
+};
const struct TALER_TESTING_Command *
@@ -60,7 +110,7 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is,
if (TALER_TESTING_cmd_is_batch (cmd))
{
- struct TALER_TESTING_Command **batch;
+ struct TALER_TESTING_Command *batch;
struct TALER_TESTING_Command *current;
struct TALER_TESTING_Command *icmd;
const struct TALER_TESTING_Command *match;
@@ -72,7 +122,7 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is,
/* We must do the loop forward, but we can find the last match */
match = NULL;
for (unsigned int j = 0;
- NULL != (icmd = &(*batch)[j])->label;
+ NULL != (icmd = &batch[j])->label;
j++)
{
if (current == icmd)
@@ -90,13 +140,29 @@ TALER_TESTING_interpreter_lookup_command (struct TALER_TESTING_Interpreter *is,
"Command not found: %s\n",
label);
return NULL;
+}
+
+const struct TALER_TESTING_Command *
+TALER_TESTING_interpreter_get_command (struct TALER_TESTING_Interpreter *is,
+ const char *name)
+{
+ const struct TALER_TESTING_Command *cmd;
+ struct GNUNET_HashCode h_name;
+
+ GNUNET_CRYPTO_hash (name,
+ strlen (name),
+ &h_name);
+ cmd = GNUNET_CONTAINER_multihashmap_get (is->vars,
+ &h_name);
+ if (NULL == cmd)
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Command not found by name: %s\n",
+ name);
+ return cmd;
}
-/**
- * Obtain main execution context for the main loop.
- */
struct GNUNET_CURL_Context *
TALER_TESTING_interpreter_get_context (struct TALER_TESTING_Interpreter *is)
{
@@ -104,38 +170,18 @@ TALER_TESTING_interpreter_get_context (struct TALER_TESTING_Interpreter *is)
}
-struct TALER_FAKEBANK_Handle *
-TALER_TESTING_interpreter_get_fakebank (struct TALER_TESTING_Interpreter *is)
+void
+TALER_TESTING_touch_cmd (struct TALER_TESTING_Interpreter *is)
{
- return is->fakebank;
+ is->commands[is->ip].last_req_time
+ = GNUNET_TIME_absolute_get ();
}
void
-TALER_TESTING_run_with_fakebank (struct TALER_TESTING_Interpreter *is,
- struct TALER_TESTING_Command *commands,
- const char *bank_url)
+TALER_TESTING_inc_tries (struct TALER_TESTING_Interpreter *is)
{
- char *currency;
-
- if (GNUNET_OK !=
- TALER_config_get_currency (is->cfg,
- &currency))
- {
- is->result = GNUNET_SYSERR;
- return;
- }
- is->fakebank = TALER_TESTING_run_fakebank (bank_url,
- currency);
- GNUNET_free (currency);
- if (NULL == is->fakebank)
- {
- GNUNET_break (0);
- is->result = GNUNET_SYSERR;
- return;
- }
- TALER_TESTING_run (is,
- commands);
+ is->commands[is->ip].num_tries++;
}
@@ -159,7 +205,13 @@ TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *is)
return; /* ignore, we already failed! */
if (TALER_TESTING_cmd_is_batch (cmd))
{
- TALER_TESTING_cmd_batch_next (is);
+ if (TALER_TESTING_cmd_batch_next (is,
+ cmd->cls))
+ {
+ /* batch is done */
+ cmd->finish_time = GNUNET_TIME_absolute_get ();
+ is->ip++;
+ }
}
else
{
@@ -173,7 +225,7 @@ TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *is)
"Interpreter executed 1000 instructions in %s\n",
GNUNET_STRINGS_relative_time_to_string (
GNUNET_TIME_absolute_get_duration (last_report),
- GNUNET_YES));
+ true));
last_report = GNUNET_TIME_absolute_get ();
}
ipc++;
@@ -202,19 +254,9 @@ TALER_TESTING_interpreter_fail (struct TALER_TESTING_Interpreter *is)
}
-struct TALER_TESTING_Command
-TALER_TESTING_cmd_end (void)
-{
- static struct TALER_TESTING_Command cmd;
- cmd.label = NULL;
-
- return cmd;
-}
-
-
const char *
-TALER_TESTING_interpreter_get_current_label (struct
- TALER_TESTING_Interpreter *is)
+TALER_TESTING_interpreter_get_current_label (
+ struct TALER_TESTING_Interpreter *is)
{
struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
@@ -246,6 +288,19 @@ interpreter_run (void *cls)
= cmd->last_req_time
= GNUNET_TIME_absolute_get ();
cmd->num_tries = 1;
+ if (NULL != cmd->name)
+ {
+ struct GNUNET_HashCode h_name;
+
+ GNUNET_CRYPTO_hash (cmd->name,
+ strlen (cmd->name),
+ &h_name);
+ (void) GNUNET_CONTAINER_multihashmap_put (
+ is->vars,
+ &h_name,
+ cmd,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ }
cmd->run (cmd->cls,
cmd,
is);
@@ -277,22 +332,11 @@ do_shutdown (void *cls)
if (NULL != cmd->cleanup)
cmd->cleanup (cmd->cls,
cmd);
- if (NULL != is->exchange)
- {
- TALER_LOG_DEBUG ("Disconnecting the exchange\n");
- TALER_EXCHANGE_disconnect (is->exchange);
- is->exchange = NULL;
- }
if (NULL != is->task)
{
GNUNET_SCHEDULER_cancel (is->task);
is->task = NULL;
}
- if (NULL != is->fakebank)
- {
- TALER_FAKEBANK_stop (is->fakebank);
- is->fakebank = NULL;
- }
if (NULL != is->ctx)
{
GNUNET_CURL_fini (is->ctx);
@@ -303,15 +347,20 @@ do_shutdown (void *cls)
GNUNET_CURL_gnunet_rc_destroy (is->rc);
is->rc = NULL;
}
+ if (NULL != is->vars)
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (is->vars);
+ is->vars = NULL;
+ }
if (NULL != is->timeout_task)
{
GNUNET_SCHEDULER_cancel (is->timeout_task);
is->timeout_task = NULL;
}
- if (NULL != is->child_death_task)
+ if (NULL != is->cwh)
{
- GNUNET_SCHEDULER_cancel (is->child_death_task);
- is->child_death_task = NULL;
+ GNUNET_wait_child_cancel (is->cwh);
+ is->cwh = NULL;
}
GNUNET_free (is->commands);
}
@@ -339,30 +388,24 @@ do_timeout (void *cls)
* process died).
*
* @param cls the `struct TALER_TESTING_Interpreter *`
+ * @param type type of the process
+ * @param code status code of the process
*/
static void
-maint_child_death (void *cls)
+maint_child_death (void *cls,
+ enum GNUNET_OS_ProcessStatusType type,
+ long unsigned int code)
{
struct TALER_TESTING_Interpreter *is = cls;
struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
- const struct GNUNET_DISK_FileHandle *pr;
struct GNUNET_OS_Process **processp;
- char c[16];
- enum GNUNET_OS_ProcessStatusType type;
- unsigned long code;
+ is->cwh = NULL;
while (TALER_TESTING_cmd_is_batch (cmd))
cmd = TALER_TESTING_cmd_batch_get_current (cmd);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Got SIGCHLD for `%s'.\n",
cmd->label);
- is->child_death_task = NULL;
- pr = GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ);
- GNUNET_break (0 <
- GNUNET_DISK_file_read (pr,
- &c,
- sizeof (c)));
if (GNUNET_OK !=
TALER_TESTING_get_trait_process (cmd,
&processp))
@@ -371,13 +414,8 @@ maint_child_death (void *cls)
TALER_TESTING_interpreter_fail (is);
return;
}
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Got the dead child process handle, waiting for termination ...\n");
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait_status (*processp,
- &type,
- &code));
GNUNET_OS_process_destroy (*processp);
*processp = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -411,7 +449,6 @@ maint_child_death (void *cls)
TALER_TESTING_interpreter_fail (is);
return;
}
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Dead child, go on with next command.\n");
TALER_TESTING_interpreter_next (is);
@@ -421,16 +458,24 @@ maint_child_death (void *cls)
void
TALER_TESTING_wait_for_sigchld (struct TALER_TESTING_Interpreter *is)
{
- const struct GNUNET_DISK_FileHandle *pr;
+ struct GNUNET_OS_Process **processp;
+ struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
- GNUNET_assert (NULL == is->child_death_task);
- pr = GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ);
- is->child_death_task
- = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &maint_child_death,
- is);
+ while (TALER_TESTING_cmd_is_batch (cmd))
+ cmd = TALER_TESTING_cmd_batch_get_current (cmd);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_process (cmd,
+ &processp))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
+ }
+ GNUNET_assert (NULL == is->cwh);
+ is->cwh
+ = GNUNET_wait_child (*processp,
+ &maint_child_death,
+ is);
}
@@ -452,9 +497,9 @@ TALER_TESTING_run2 (struct TALER_TESTING_Interpreter *is,
is->commands = GNUNET_malloc_large ( (i + 1)
* sizeof (struct TALER_TESTING_Command));
GNUNET_assert (NULL != is->commands);
- memcpy (is->commands,
- commands,
- sizeof (struct TALER_TESTING_Command) * i);
+ GNUNET_memcpy (is->commands,
+ commands,
+ sizeof (struct TALER_TESTING_Command) * i);
is->timeout_task = GNUNET_SCHEDULER_add_delayed (
timeout,
&do_timeout,
@@ -466,14 +511,19 @@ TALER_TESTING_run2 (struct TALER_TESTING_Interpreter *is,
}
+#include "valgrind.h"
+
void
TALER_TESTING_run (struct TALER_TESTING_Interpreter *is,
struct TALER_TESTING_Command *commands)
{
TALER_TESTING_run2 (is,
commands,
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
- 5));
+ 0 == RUNNING_ON_VALGRIND
+ ? GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
+ 5)
+ : GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES,
+ 50));
}
@@ -507,352 +557,446 @@ struct MainContext
/**
- * Signal handler called for SIGCHLD. Triggers the
- * respective handler by writing to the trigger pipe.
+ * Initialize scheduler loop and curl context for the testcase,
+ * and responsible to run the "run" method.
+ *
+ * @param cls closure, typically the "run" method, the
+ * interpreter state and a closure for "run".
*/
static void
-sighandler_child_death (void)
+main_wrapper (void *cls)
+{
+ struct MainContext *main_ctx = cls;
+
+ main_ctx->main_cb (main_ctx->main_cb_cls,
+ main_ctx->is);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TESTING_loop (TALER_TESTING_Main main_cb,
+ void *main_cb_cls)
+{
+ struct TALER_TESTING_Interpreter is;
+ struct MainContext main_ctx = {
+ .main_cb = main_cb,
+ .main_cb_cls = main_cb_cls,
+ /* needed to init the curl ctx */
+ .is = &is,
+ };
+
+ memset (&is,
+ 0,
+ sizeof (is));
+ is.ctx = GNUNET_CURL_init (
+ &GNUNET_CURL_gnunet_scheduler_reschedule,
+ &is.rc);
+ GNUNET_CURL_enable_async_scope_header (is.ctx,
+ "Taler-Correlation-Id");
+ GNUNET_assert (NULL != is.ctx);
+ is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx);
+ is.vars = GNUNET_CONTAINER_multihashmap_create (1024,
+ false);
+ /* Blocking */
+ GNUNET_SCHEDULER_run (&main_wrapper,
+ &main_ctx);
+ return is.result;
+}
+
+
+int
+TALER_TESTING_main (char *const *argv,
+ const char *loglevel,
+ const char *cfg_file,
+ const char *exchange_account_section,
+ enum TALER_TESTING_BankSystem bs,
+ struct TALER_TESTING_Credentials *cred,
+ TALER_TESTING_Main main_cb,
+ void *main_cb_cls)
{
- static char c;
- int old_errno = errno; /* back-up errno */
+ enum GNUNET_GenericReturnValue ret;
- GNUNET_break (1 == GNUNET_DISK_file_write
- (GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c)));
- errno = old_errno; /* restore errno */
+ unsetenv ("XDG_DATA_HOME");
+ unsetenv ("XDG_CONFIG_HOME");
+ GNUNET_log_setup (argv[0],
+ loglevel,
+ NULL);
+ if (GNUNET_OK !=
+ TALER_TESTING_get_credentials (cfg_file,
+ exchange_account_section,
+ bs,
+ cred))
+ {
+ GNUNET_break (0);
+ return 77;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_cleanup_files_cfg (NULL,
+ cred->cfg))
+ {
+ GNUNET_break (0);
+ return 77;
+ }
+ if (GNUNET_OK !=
+ TALER_extensions_init (cred->cfg))
+ {
+ GNUNET_break (0);
+ return 77;
+ }
+ ret = TALER_TESTING_loop (main_cb,
+ main_cb_cls);
+ /* TODO: should we free 'cred' resources here? */
+ return (GNUNET_OK == ret) ? 0 : 1;
}
+/* ************** iterate over commands ********* */
+
+
void
-TALER_TESTING_cert_cb (void *cls,
- const struct TALER_EXCHANGE_HttpResponse *hr,
- const struct TALER_EXCHANGE_Keys *keys,
- enum TALER_EXCHANGE_VersionCompatibility compat)
+TALER_TESTING_iterate (struct TALER_TESTING_Interpreter *is,
+ bool asc,
+ TALER_TESTING_CommandIterator cb,
+ void *cb_cls)
{
- struct MainContext *main_ctx = cls;
- struct TALER_TESTING_Interpreter *is = main_ctx->is;
+ unsigned int start;
+ unsigned int end;
+ int inc;
- (void) compat;
- if (NULL == keys)
+ if (asc)
{
- if (GNUNET_NO == is->working)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Got NULL response for /keys during startup (%u/%d), retrying!\n",
- hr->http_status,
- (int) hr->ec);
- TALER_EXCHANGE_disconnect (is->exchange);
- GNUNET_assert (
- NULL != (is->exchange
- = TALER_EXCHANGE_connect (is->ctx,
- main_ctx->exchange_url,
- &TALER_TESTING_cert_cb,
- main_ctx,
- TALER_EXCHANGE_OPTION_END)));
- return;
- }
- else
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Got NULL response for /keys during execution (%u/%d)!\n",
- hr->http_status,
- (int) hr->ec);
- }
+ inc = 1;
+ start = 0;
+ end = is->ip;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got %d DK from /keys in generation %u\n",
- keys->num_denom_keys,
- is->key_generation + 1);
+ inc = -1;
+ start = is->ip;
+ end = 0;
+ }
+ for (unsigned int off = start; off != end + inc; off += inc)
+ {
+ const struct TALER_TESTING_Command *cmd = &is->commands[off];
+
+ cb (cb_cls,
+ cmd);
}
- is->key_generation++;
- is->keys = keys;
+}
- /* /keys has been called for some reason and
- * the interpreter is already running. */
- if (GNUNET_YES == is->working)
- return;
- is->working = GNUNET_YES;
- /* Trigger the next command. */
- TALER_LOG_DEBUG ("Cert_cb, scheduling CMD (ip: %d)\n",
- is->ip);
- GNUNET_SCHEDULER_add_now (&interpreter_run,
- is);
+
+/* ************** special commands ********* */
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_end (void)
+{
+ static struct TALER_TESTING_Command cmd;
+ cmd.label = NULL;
+
+ return cmd;
+}
+
+
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_set_var (const char *name,
+ struct TALER_TESTING_Command cmd)
+{
+ cmd.name = name;
+ return cmd;
}
/**
- * Initialize scheduler loop and curl context for the testcase,
- * and responsible to run the "run" method.
+ * State for a "rewind" CMD.
+ */
+struct RewindIpState
+{
+ /**
+ * Instruction pointer to set into the interpreter.
+ */
+ const char *target_label;
+
+ /**
+ * How many times this set should take place. However, this value lives at
+ * the calling process, and this CMD is only in charge of checking and
+ * decremeting it.
+ */
+ unsigned int counter;
+};
+
+
+/**
+ * Seek for the @a target command in @a batch (and rewind to it
+ * if successful).
*
- * @param cls closure, typically the "run" method, the
- * interpreter state and a closure for "run".
+ * @param is the interpreter state (for failures)
+ * @param cmd batch to search for @a target
+ * @param target command to search for
+ * @return #GNUNET_OK on success, #GNUNET_NO if target was not found,
+ * #GNUNET_SYSERR if target is in the future and we failed
*/
-static void
-main_wrapper_exchange_agnostic (void *cls)
+static enum GNUNET_GenericReturnValue
+seek_batch (struct TALER_TESTING_Interpreter *is,
+ const struct TALER_TESTING_Command *cmd,
+ const struct TALER_TESTING_Command *target)
{
- struct MainContext *main_ctx = cls;
+ unsigned int new_ip;
+ struct TALER_TESTING_Command *batch;
+ struct TALER_TESTING_Command *current;
+ struct TALER_TESTING_Command *icmd;
+ struct TALER_TESTING_Command *match;
- main_ctx->main_cb (main_ctx->main_cb_cls,
- main_ctx->is);
+ current = TALER_TESTING_cmd_batch_get_current (cmd);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_batch_cmds (cmd,
+ &batch));
+ match = NULL;
+ for (new_ip = 0;
+ NULL != (icmd = &batch[new_ip]);
+ new_ip++)
+ {
+ if (current == target)
+ current = NULL;
+ if (icmd == target)
+ {
+ match = icmd;
+ break;
+ }
+ if (TALER_TESTING_cmd_is_batch (icmd))
+ {
+ int ret = seek_batch (is,
+ icmd,
+ target);
+ if (GNUNET_SYSERR == ret)
+ return GNUNET_SYSERR; /* failure! */
+ if (GNUNET_OK == ret)
+ {
+ match = icmd;
+ break;
+ }
+ }
+ }
+ if (NULL == current)
+ {
+ /* refuse to jump forward */
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return GNUNET_SYSERR;
+ }
+ if (NULL == match)
+ return GNUNET_NO; /* not found */
+ TALER_TESTING_cmd_batch_set_current (cmd,
+ new_ip);
+ return GNUNET_OK;
}
/**
- * Function run when the test is aborted before we launch the actual
- * interpreter. Cleans up our state.
+ * Run the "rewind" CMD.
*
- * @param cls the main context
+ * @param cls closure.
+ * @param cmd command being executed now.
+ * @param is the interpreter state.
*/
static void
-do_abort (void *cls)
+rewind_ip_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
{
- struct MainContext *main_ctx = cls;
- struct TALER_TESTING_Interpreter *is = main_ctx->is;
+ struct RewindIpState *ris = cls;
+ const struct TALER_TESTING_Command *target;
+ unsigned int new_ip;
- is->timeout_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Executing abort prior to interpreter launch\n");
- if (NULL != is->exchange)
+ (void) cmd;
+ if (0 == ris->counter)
{
- TALER_EXCHANGE_disconnect (is->exchange);
- is->exchange = NULL;
+ TALER_TESTING_interpreter_next (is);
+ return;
}
- if (NULL != is->fakebank)
+ target
+ = TALER_TESTING_interpreter_lookup_command (is,
+ ris->target_label);
+ if (NULL == target)
{
- TALER_FAKEBANK_stop (is->fakebank);
- is->fakebank = NULL;
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
}
- if (NULL != is->ctx)
+ ris->counter--;
+ for (new_ip = 0;
+ NULL != is->commands[new_ip].label;
+ new_ip++)
{
- GNUNET_CURL_fini (is->ctx);
- is->ctx = NULL;
+ const struct TALER_TESTING_Command *cmd = &is->commands[new_ip];
+
+ if (cmd == target)
+ break;
+ if (TALER_TESTING_cmd_is_batch (cmd))
+ {
+ int ret = seek_batch (is,
+ cmd,
+ target);
+ if (GNUNET_SYSERR == ret)
+ return; /* failure! */
+ if (GNUNET_OK == ret)
+ break;
+ }
}
- if (NULL != is->rc)
+ if (new_ip > (unsigned int) is->ip)
{
- GNUNET_CURL_gnunet_rc_destroy (is->rc);
- is->rc = NULL;
+ /* refuse to jump forward */
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return;
}
+ is->ip = new_ip - 1; /* -1 because the next function will advance by one */
+ TALER_TESTING_interpreter_next (is);
}
-/**
- * Initialize scheduler loop and curl context for the testcase,
- * and responsible to run the "run" method.
- *
- * @param cls a `struct MainContext *`
- */
-static void
-main_wrapper_exchange_connect (void *cls)
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_rewind_ip (const char *label,
+ const char *target_label,
+ unsigned int counter)
{
- struct MainContext *main_ctx = cls;
- struct TALER_TESTING_Interpreter *is = main_ctx->is;
- char *exchange_url;
+ struct RewindIpState *ris;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (is->cfg,
- "exchange",
- "BASE_URL",
- &exchange_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "BASE_URL");
- return;
+ ris = GNUNET_new (struct RewindIpState);
+ ris->target_label = target_label;
+ ris->counter = counter;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ris,
+ .label = label,
+ .run = &rewind_ip_run
+ };
+
+ return cmd;
}
- main_ctx->exchange_url = exchange_url;
- is->timeout_task = GNUNET_SCHEDULER_add_shutdown (&do_abort,
- main_ctx);
- is->working = GNUNET_YES;
- GNUNET_assert (NULL == is->exchange);
- GNUNET_break (
- NULL != (is->exchange =
- TALER_EXCHANGE_connect (is->ctx,
- exchange_url,
- &TALER_TESTING_cert_cb,
- main_ctx,
- TALER_EXCHANGE_OPTION_END)));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Starting main test loop\n");
- main_ctx->main_cb (main_ctx->main_cb_cls,
- is);
}
/**
- * Load the exchange and auditor key material into @a is.
+ * State for a "authchange" CMD.
+ */
+struct AuthchangeState
+{
+
+ /**
+ * What is the new authorization token to send?
+ */
+ const char *auth_token;
+
+ /**
+ * Old context, clean up on termination.
+ */
+ struct GNUNET_CURL_Context *old_ctx;
+};
+
+
+/**
+ * Run the command.
*
- * @param[in,out] is state to initialize
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
*/
-static enum GNUNET_GenericReturnValue
-load_keys (struct TALER_TESTING_Interpreter *is)
+static void
+authchange_run (void *cls,
+ const struct TALER_TESTING_Command *cmd,
+ struct TALER_TESTING_Interpreter *is)
{
- char *fn;
+ struct AuthchangeState *ss = cls;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (is->cfg,
- "exchange-offline",
- "MASTER_PRIV_FILE",
- &fn))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange-offline",
- "MASTER_PRIV_FILE");
- return GNUNET_SYSERR;
- }
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create_for_file (fn))
+ (void) cmd;
+ ss->old_ctx = is->ctx;
+ if (NULL != is->rc)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not setup directory for master private key file `%s'\n",
- fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
+ GNUNET_CURL_gnunet_rc_destroy (is->rc);
+ is->rc = NULL;
}
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_eddsa_key_from_file (fn,
- GNUNET_YES,
- &is->master_priv.eddsa_priv))
+ is->ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule,
+ &is->rc);
+ GNUNET_CURL_enable_async_scope_header (is->ctx,
+ "Taler-Correlation-Id");
+ GNUNET_assert (NULL != is->ctx);
+ is->rc = GNUNET_CURL_gnunet_rc_create (is->ctx);
+ if (NULL != ss->auth_token)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not load master private key from `%s'\n",
- fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
- GNUNET_free (fn);
- GNUNET_CRYPTO_eddsa_key_get_public (&is->master_priv.eddsa_priv,
- &is->master_pub.eddsa_pub);
+ char *authorization;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (is->cfg,
- "auditor",
- "AUDITOR_PRIV_FILE",
- &fn))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "AUDITOR_PRIV_FILE");
- return GNUNET_SYSERR;
- }
- if (GNUNET_SYSERR ==
- GNUNET_DISK_directory_create_for_file (fn))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not setup directory for auditor private key file `%s'\n",
- fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
- }
- if (GNUNET_SYSERR ==
- GNUNET_CRYPTO_eddsa_key_from_file (fn,
- GNUNET_YES,
- &is->auditor_priv.eddsa_priv))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not load auditor private key from `%s'\n",
- fn);
- GNUNET_free (fn);
- return GNUNET_SYSERR;
+ GNUNET_asprintf (&authorization,
+ "%s: %s",
+ MHD_HTTP_HEADER_AUTHORIZATION,
+ ss->auth_token);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CURL_append_header (is->ctx,
+ authorization));
+ GNUNET_free (authorization);
}
- GNUNET_free (fn);
- GNUNET_CRYPTO_eddsa_key_get_public (&is->auditor_priv.eddsa_priv,
- &is->auditor_pub.eddsa_pub);
- return GNUNET_OK;
+ TALER_TESTING_interpreter_next (is);
}
/**
- * Load the exchange and auditor URLs from the configuration into @a is.
+ * Call GNUNET_CURL_fini(). Done as a separate task to
+ * ensure that all of the command's cleanups have been
+ * executed first. See #7151.
*
- * @param[in,out] is state to initialize
+ * @param cls a `struct GNUNET_CURL_Context *` to clean up.
*/
-static enum GNUNET_GenericReturnValue
-load_urls (struct TALER_TESTING_Interpreter *is)
+static void
+deferred_cleanup_cb (void *cls)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (is->cfg,
- "auditor",
- "BASE_URL",
- &is->auditor_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditor",
- "BASE_URL");
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (is->cfg,
- "exchange",
- "BASE_URL",
- &is->exchange_url))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "exchange",
- "BASE_URL");
- GNUNET_free (is->auditor_url);
- return GNUNET_SYSERR;
+ struct GNUNET_CURL_Context *ctx = cls;
+
+ GNUNET_CURL_fini (ctx);
+}
+
+
+/**
+ * Cleanup the state from a "authchange" CMD.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+authchange_cleanup (void *cls,
+ const struct TALER_TESTING_Command *cmd)
+{
+ struct AuthchangeState *ss = cls;
+
+ (void) cmd;
+ if (NULL != ss->old_ctx)
+ {
+ (void) GNUNET_SCHEDULER_add_now (&deferred_cleanup_cb,
+ ss->old_ctx);
+ ss->old_ctx = NULL;
}
- return GNUNET_OK;
+ GNUNET_free (ss);
}
-enum GNUNET_GenericReturnValue
-TALER_TESTING_setup (TALER_TESTING_Main main_cb,
- void *main_cb_cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_OS_Process *exchanged,
- int exchange_connect)
-{
- struct TALER_TESTING_Interpreter is = {
- .cfg = cfg,
- .exchanged = exchanged
- };
- struct MainContext main_ctx = {
- .main_cb = main_cb,
- .main_cb_cls = main_cb_cls,
- /* needed to init the curl ctx */
- .is = &is,
- };
- struct GNUNET_SIGNAL_Context *shc_chld;
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_set_authorization (const char *label,
+ const char *auth_token)
+{
+ struct AuthchangeState *ss;
- if (GNUNET_OK !=
- load_keys (&is))
- return GNUNET_SYSERR;
- if (GNUNET_OK !=
- load_urls (&is))
- return GNUNET_SYSERR;
- sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
- GNUNET_assert (NULL != sigpipe);
- shc_chld = GNUNET_SIGNAL_handler_install (
- GNUNET_SIGCHLD,
- &sighandler_child_death);
- is.ctx = GNUNET_CURL_init (
- &GNUNET_CURL_gnunet_scheduler_reschedule,
- &is.rc);
- GNUNET_CURL_enable_async_scope_header (is.ctx,
- "Taler-Correlation-Id");
- GNUNET_assert (NULL != is.ctx);
- is.rc = GNUNET_CURL_gnunet_rc_create (is.ctx);
+ ss = GNUNET_new (struct AuthchangeState);
+ ss->auth_token = auth_token;
- /* Blocking */
- if (GNUNET_YES == exchange_connect)
- GNUNET_SCHEDULER_run (&main_wrapper_exchange_connect,
- &main_ctx);
- else
- GNUNET_SCHEDULER_run (&main_wrapper_exchange_agnostic,
- &main_ctx);
- if (NULL != is.final_cleanup_cb)
- is.final_cleanup_cb (is.final_cleanup_cb_cls);
- GNUNET_free (main_ctx.exchange_url);
- GNUNET_SIGNAL_handler_uninstall (shc_chld);
- GNUNET_DISK_pipe_close (sigpipe);
- sigpipe = NULL;
- GNUNET_free (is.auditor_url);
- GNUNET_free (is.exchange_url);
- return is.result;
+ {
+ struct TALER_TESTING_Command cmd = {
+ .cls = ss,
+ .label = label,
+ .run = &authchange_run,
+ .cleanup = &authchange_cleanup
+ };
+
+ return cmd;
+ }
}
diff --git a/src/testing/testing_api_misc.c b/src/testing/testing_api_misc.c
new file mode 100644
index 000000000..80ff0b6c8
--- /dev/null
+++ b/src/testing/testing_api_misc.c
@@ -0,0 +1,394 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2018-2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 3, or
+ (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with TALER; see the file COPYING. If not, see
+ <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_misc.c
+ * @brief non-command functions useful for writing tests
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include <gnunet/gnunet_util_lib.h>
+#include "taler_testing_lib.h"
+#include "taler_fakebank_lib.h"
+
+
+bool
+TALER_TESTING_has_in_name (const char *prog,
+ const char *marker)
+{
+ size_t name_pos;
+ size_t pos;
+
+ if (! prog || ! marker)
+ return false;
+
+ pos = 0;
+ name_pos = 0;
+ while (prog[pos])
+ {
+ if ('/' == prog[pos])
+ name_pos = pos + 1;
+ pos++;
+ }
+ if (name_pos == pos)
+ return true;
+ return (NULL != strstr (prog + name_pos,
+ marker));
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TESTING_get_credentials (
+ const char *cfg_file,
+ const char *exchange_account_section,
+ enum TALER_TESTING_BankSystem bs,
+ struct TALER_TESTING_Credentials *ua)
+{
+ unsigned long long port;
+ char *exchange_payto_uri;
+
+ ua->cfg = GNUNET_CONFIGURATION_create ();
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_load (ua->cfg,
+ cfg_file))
+ {
+ GNUNET_break (0);
+ GNUNET_CONFIGURATION_destroy (ua->cfg);
+ return GNUNET_SYSERR;
+ }
+ if (0 !=
+ strncasecmp (exchange_account_section,
+ "exchange-account-",
+ strlen ("exchange-account-")))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ua->cfg,
+ exchange_account_section,
+ "PAYTO_URI",
+ &exchange_payto_uri))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ exchange_account_section,
+ "PAYTO_URI");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (ua->cfg,
+ "bank",
+ "HTTP_PORT",
+ &port))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "bank",
+ "HTTP_PORT");
+ return GNUNET_SYSERR;
+ }
+ {
+ char *csn;
+
+ GNUNET_asprintf (&csn,
+ "exchange-accountcredentials-%s",
+ &exchange_account_section[strlen ("exchange-account-")]);
+ if (GNUNET_OK !=
+ TALER_BANK_auth_parse_cfg (ua->cfg,
+ csn,
+ &ua->ba))
+ {
+ GNUNET_break (0);
+ GNUNET_free (csn);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (csn);
+ }
+ {
+ char *csn;
+
+ GNUNET_asprintf (&csn,
+ "admin-accountcredentials-%s",
+ &exchange_account_section[strlen ("exchange-account-")]);
+ if (GNUNET_OK !=
+ TALER_BANK_auth_parse_cfg (ua->cfg,
+ csn,
+ &ua->ba_admin))
+ {
+ GNUNET_break (0);
+ GNUNET_free (csn);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (csn);
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ua->cfg,
+ "exchange",
+ "BASE_URL",
+ &ua->exchange_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (ua->cfg,
+ "auditor",
+ "BASE_URL",
+ &ua->auditor_url))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "auditor",
+ "BASE_URL");
+ return GNUNET_SYSERR;
+ }
+
+ switch (bs)
+ {
+ case TALER_TESTING_BS_FAKEBANK:
+ ua->exchange_payto
+ = exchange_payto_uri;
+ ua->user42_payto
+ = GNUNET_strdup ("payto://x-taler-bank/localhost/42?receiver-name=42");
+ ua->user43_payto
+ = GNUNET_strdup ("payto://x-taler-bank/localhost/43?receiver-name=43");
+ break;
+ case TALER_TESTING_BS_IBAN:
+ ua->exchange_payto
+ = exchange_payto_uri;
+ ua->user42_payto
+ = GNUNET_strdup (
+ "payto://iban/SANDBOXX/FR7630006000011234567890189?receiver-name=User42");
+ ua->user43_payto
+ = GNUNET_strdup (
+ "payto://iban/SANDBOXX/GB33BUKB20201555555555?receiver-name=User43");
+ break;
+ }
+ return GNUNET_OK;
+}
+
+
+json_t *
+TALER_TESTING_make_wire_details (const char *payto)
+{
+ struct TALER_WireSaltP salt;
+
+ /* salt must be constant for aggregation tests! */
+ memset (&salt,
+ 47,
+ sizeof (salt));
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("payto_uri",
+ payto),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &salt));
+}
+
+
+/**
+ * Remove @a option directory from @a section in @a cfg.
+ *
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+remove_dir (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
+ const char *option)
+{
+ char *dir;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ section,
+ option,
+ &dir))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ option);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_YES ==
+ GNUNET_DISK_directory_test (dir,
+ GNUNET_NO))
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove (dir));
+ GNUNET_free (dir);
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TESTING_cleanup_files_cfg (
+ void *cls,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *dir;
+
+ (void) cls;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "exchange-offline",
+ "SECM_TOFU_FILE",
+ &dir))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "exchange-offline",
+ "SECM_TOFU_FILE");
+ return GNUNET_SYSERR;
+ }
+ if ( (0 != unlink (dir)) &&
+ (ENOENT != errno) )
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "unlink",
+ dir);
+ GNUNET_free (dir);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_free (dir);
+ if (GNUNET_OK !=
+ remove_dir (cfg,
+ "taler-exchange-secmod-eddsa",
+ "KEY_DIR"))
+ return GNUNET_SYSERR;
+ if (GNUNET_OK !=
+ remove_dir (cfg,
+ "taler-exchange-secmod-rsa",
+ "KEY_DIR"))
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+const struct TALER_EXCHANGE_DenomPublicKey *
+TALER_TESTING_find_pk (
+ const struct TALER_EXCHANGE_Keys *keys,
+ const struct TALER_Amount *amount,
+ bool age_restricted)
+{
+ struct GNUNET_TIME_Timestamp now;
+ struct TALER_EXCHANGE_DenomPublicKey *pk;
+ char *str;
+
+ now = GNUNET_TIME_timestamp_get ();
+ for (unsigned int i = 0; i<keys->num_denom_keys; i++)
+ {
+ pk = &keys->denom_keys[i];
+ if ( (0 == TALER_amount_cmp (amount,
+ &pk->value)) &&
+ (GNUNET_TIME_timestamp_cmp (now,
+ >=,
+ pk->valid_from)) &&
+ (GNUNET_TIME_timestamp_cmp (now,
+ <,
+ pk->withdraw_valid_until)) &&
+ (age_restricted == (0 != pk->key.age_mask.bits)) )
+ return pk;
+ }
+ /* do 2nd pass to check if expiration times are to blame for
+ * failure */
+ str = TALER_amount_to_string (amount);
+ for (unsigned int i = 0; i<keys->num_denom_keys; i++)
+ {
+ pk = &keys->denom_keys[i];
+ if ( (0 == TALER_amount_cmp (amount,
+ &pk->value)) &&
+ (GNUNET_TIME_timestamp_cmp (now,
+ <,
+ pk->valid_from) ||
+ GNUNET_TIME_timestamp_cmp (now,
+ >,
+ pk->withdraw_valid_until) ) &&
+ (age_restricted == (0 != pk->key.age_mask.bits)) )
+ {
+ GNUNET_log
+ (GNUNET_ERROR_TYPE_WARNING,
+ "Have denomination key for `%s', but with wrong"
+ " expiration range %llu vs [%llu,%llu)\n",
+ str,
+ (unsigned long long) now.abs_time.abs_value_us,
+ (unsigned long long) pk->valid_from.abs_time.abs_value_us,
+ (unsigned long long) pk->withdraw_valid_until.abs_time.abs_value_us);
+ GNUNET_free (str);
+ return NULL;
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No denomination key for amount %s found\n",
+ str);
+ GNUNET_free (str);
+ return NULL;
+}
+
+
+int
+TALER_TESTING_wait_httpd_ready (const char *base_url)
+{
+ char *wget_cmd;
+ unsigned int iter;
+
+ GNUNET_asprintf (&wget_cmd,
+ "wget -q -t 1 -T 1 %s -o /dev/null -O /dev/null",
+ base_url); // make sure ends with '/'
+ /* give child time to start and bind against the socket */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Waiting for HTTP service to be ready (check with: %s)\n",
+ wget_cmd);
+ iter = 0;
+ do
+ {
+ if (10 == iter)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to launch HTTP service (or `wget')\n");
+ GNUNET_free (wget_cmd);
+ return 77;
+ }
+ sleep (1);
+ iter++;
+ }
+ while (0 != system (wget_cmd));
+ GNUNET_free (wget_cmd);
+ return 0;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_TESTING_url_port_free (const char *url)
+{
+ const char *port;
+ long pnum;
+
+ port = strrchr (url,
+ (unsigned char) ':');
+ if (NULL == port)
+ pnum = 80;
+ else
+ pnum = strtol (port + 1, NULL, 10);
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_test_port_free (IPPROTO_TCP,
+ pnum))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Port %u not available.\n",
+ (unsigned int) pnum);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
diff --git a/src/testing/testing_api_traits.c b/src/testing/testing_api_traits.c
index db94e81a5..799ae6718 100644
--- a/src/testing/testing_api_traits.c
+++ b/src/testing/testing_api_traits.c
@@ -67,7 +67,7 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
return GNUNET_OK;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Trait %s/%u not found.\n",
trait,
index);
@@ -75,4 +75,59 @@ TALER_TESTING_get_trait (const struct TALER_TESTING_Trait *traits,
}
+const char *
+TALER_TESTING_get_exchange_url (struct TALER_TESTING_Interpreter *is)
+{
+ const char *exchange_url;
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_exchange_url (exchange_cmd,
+ &exchange_url))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return NULL;
+ }
+ return exchange_url;
+}
+
+
+struct TALER_EXCHANGE_Keys *
+TALER_TESTING_get_keys (
+ struct TALER_TESTING_Interpreter *is)
+{
+ struct TALER_EXCHANGE_Keys *keys;
+ const struct TALER_TESTING_Command *exchange_cmd;
+
+ exchange_cmd
+ = TALER_TESTING_interpreter_get_command (is,
+ "exchange");
+ if (NULL == exchange_cmd)
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ TALER_TESTING_get_trait_keys (exchange_cmd,
+ &keys))
+ {
+ GNUNET_break (0);
+ TALER_TESTING_interpreter_fail (is);
+ return NULL;
+ }
+ return keys;
+}
+
+
/* end of testing_api_traits.c */
diff --git a/src/testing/testing_api_twister_helpers.c b/src/testing/testing_api_twister_helpers.c
index 935d8bcc1..68fbf0082 100644
--- a/src/testing/testing_api_twister_helpers.c
+++ b/src/testing/testing_api_twister_helpers.c
@@ -116,7 +116,9 @@ TALER_TWISTER_run_twister (const char *config_filename)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not start the taler-twister client\n");
- GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (proc,
+ SIGTERM));
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
TWISTER_FAIL ();
@@ -129,7 +131,9 @@ TALER_TWISTER_run_twister (const char *config_filename)
&code))
{
GNUNET_OS_process_destroy (client_proc);
- GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (proc,
+ SIGTERM));
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
TWISTER_FAIL ();
@@ -140,7 +144,9 @@ TALER_TWISTER_run_twister (const char *config_filename)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to check twister works.\n");
GNUNET_OS_process_destroy (client_proc);
- GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (proc,
+ SIGTERM));
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
TWISTER_FAIL ();
@@ -151,7 +157,9 @@ TALER_TWISTER_run_twister (const char *config_filename)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected error running `taler-twister'!\n");
GNUNET_OS_process_destroy (client_proc);
- GNUNET_OS_process_kill (proc, SIGTERM);
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (proc,
+ SIGTERM));
GNUNET_OS_process_wait (proc);
GNUNET_OS_process_destroy (proc);
TWISTER_FAIL ();
diff --git a/src/testing/valgrind.h b/src/testing/valgrind.h
new file mode 100644
index 000000000..eaf1632e1
--- /dev/null
+++ b/src/testing/valgrind.h
@@ -0,0 +1,7165 @@
+/* -*- c -*-
+ ----------------------------------------------------------------
+
+ Notice that the following BSD-style license applies to this one
+ file (valgrind.h) only. The rest of Valgrind is licensed under the
+ terms of the GNU General Public License, version 2, unless
+ otherwise indicated. See the COPYING file in the source
+ distribution for details.
+
+ ----------------------------------------------------------------
+
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2017 Julian Seward. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. The origin of this software must not be misrepresented; you must
+ not claim that you wrote the original software. If you use this
+ software in a product, an acknowledgment in the product
+ documentation would be appreciated but is not required.
+
+ 3. Altered source versions must be plainly marked as such, and must
+ not be misrepresented as being the original software.
+
+ 4. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior written
+ permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+ DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+ ----------------------------------------------------------------
+
+ Notice that the above BSD-style license applies to this one file
+ (valgrind.h) only. The entire rest of Valgrind is licensed under
+ the terms of the GNU General Public License, version 2. See the
+ COPYING file in the source distribution for details.
+
+ ----------------------------------------------------------------
+*/
+
+
+/* This file is for inclusion into client (your!) code.
+
+ You can use these macros to manipulate and query Valgrind's
+ execution inside your own programs.
+
+ The resulting executables will still run without Valgrind, just a
+ little bit more slowly than they otherwise would, but otherwise
+ unchanged. When not running on valgrind, each client request
+ consumes very few (eg. 7) instructions, so the resulting performance
+ loss is negligible unless you plan to execute client requests
+ millions of times per second. Nevertheless, if that is still a
+ problem, you can compile with the NVALGRIND symbol defined (gcc
+ -DNVALGRIND) so that client requests are not even compiled in. */
+
+#ifndef __VALGRIND_H
+#define __VALGRIND_H
+
+
+/* ------------------------------------------------------------------ */
+/* VERSION NUMBER OF VALGRIND */
+/* ------------------------------------------------------------------ */
+
+/* Specify Valgrind's version number, so that user code can
+ conditionally compile based on our version number. Note that these
+ were introduced at version 3.6 and so do not exist in version 3.5
+ or earlier. The recommended way to use them to check for "version
+ X.Y or later" is (eg)
+
+#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
+ && (__VALGRIND_MAJOR__ > 3 \
+ || (__VALGRIND_MAJOR__ == 3 && __VALGRIND_MINOR__ >= 6))
+*/
+#define __VALGRIND_MAJOR__ 3
+#define __VALGRIND_MINOR__ 19
+
+
+#include <stdarg.h>
+
+/* Nb: this file might be included in a file compiled with -ansi. So
+ we can't use C++ style "//" comments nor the "asm" keyword (instead
+ use "__asm__"). */
+
+/* Derive some tags indicating what the target platform is. Note
+ that in this file we're using the compiler's CPP symbols for
+ identifying architectures, which are different to the ones we use
+ within the rest of Valgrind. Note, __powerpc__ is active for both
+ 32 and 64-bit PPC, whereas __powerpc64__ is only active for the
+ latter (on Linux, that is).
+
+ Misc note: how to find out what's predefined in gcc by default:
+ gcc -Wp,-dM somefile.c
+*/
+#undef PLAT_x86_darwin
+#undef PLAT_amd64_darwin
+#undef PLAT_x86_freebsd
+#undef PLAT_amd64_freebsd
+#undef PLAT_x86_win32
+#undef PLAT_amd64_win64
+#undef PLAT_x86_linux
+#undef PLAT_amd64_linux
+#undef PLAT_ppc32_linux
+#undef PLAT_ppc64be_linux
+#undef PLAT_ppc64le_linux
+#undef PLAT_arm_linux
+#undef PLAT_arm64_linux
+#undef PLAT_s390x_linux
+#undef PLAT_mips32_linux
+#undef PLAT_mips64_linux
+#undef PLAT_nanomips_linux
+#undef PLAT_x86_solaris
+#undef PLAT_amd64_solaris
+
+
+#if defined(__APPLE__) && defined(__i386__)
+# define PLAT_x86_darwin 1
+#elif defined(__APPLE__) && defined(__x86_64__)
+# define PLAT_amd64_darwin 1
+#elif defined(__FreeBSD__) && defined(__i386__)
+# define PLAT_x86_freebsd 1
+#elif defined(__FreeBSD__) && defined(__amd64__)
+# define PLAT_amd64_freebsd 1
+#elif (defined(__MINGW32__) && defined(__i386__)) \
+ || defined(__CYGWIN32__) \
+ || (defined(_WIN32) && defined(_M_IX86))
+# define PLAT_x86_win32 1
+#elif (defined(__MINGW32__) && defined(__x86_64__)) \
+ || (defined(_WIN32) && defined(_M_X64))
+/* __MINGW32__ and _WIN32 are defined in 64 bit mode as well. */
+# define PLAT_amd64_win64 1
+#elif defined(__linux__) && defined(__i386__)
+# define PLAT_x86_linux 1
+#elif defined(__linux__) && defined(__x86_64__) && !defined(__ILP32__)
+# define PLAT_amd64_linux 1
+#elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
+# define PLAT_ppc32_linux 1
+#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF != 2
+/* Big Endian uses ELF version 1 */
+# define PLAT_ppc64be_linux 1
+#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF == 2
+/* Little Endian uses ELF version 2 */
+# define PLAT_ppc64le_linux 1
+#elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__)
+# define PLAT_arm_linux 1
+#elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__)
+# define PLAT_arm64_linux 1
+#elif defined(__linux__) && defined(__s390__) && defined(__s390x__)
+# define PLAT_s390x_linux 1
+#elif defined(__linux__) && defined(__mips__) && (__mips==64)
+# define PLAT_mips64_linux 1
+#elif defined(__linux__) && defined(__mips__) && (__mips==32)
+# define PLAT_mips32_linux 1
+#elif defined(__linux__) && defined(__nanomips__)
+# define PLAT_nanomips_linux 1
+#elif defined(__sun) && defined(__i386__)
+# define PLAT_x86_solaris 1
+#elif defined(__sun) && defined(__x86_64__)
+# define PLAT_amd64_solaris 1
+#else
+/* If we're not compiling for our target platform, don't generate
+ any inline asms. */
+# if !defined(NVALGRIND)
+# define NVALGRIND 1
+# endif
+#endif
+
+
+/* ------------------------------------------------------------------ */
+/* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */
+/* in here of use to end-users -- skip to the next section. */
+/* ------------------------------------------------------------------ */
+
+/*
+ * VALGRIND_DO_CLIENT_REQUEST(): a statement that invokes a Valgrind client
+ * request. Accepts both pointers and integers as arguments.
+ *
+ * VALGRIND_DO_CLIENT_REQUEST_STMT(): a statement that invokes a Valgrind
+ * client request that does not return a value.
+
+ * VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind
+ * client request and whose value equals the client request result. Accepts
+ * both pointers and integers as arguments. Note that such calls are not
+ * necessarily pure functions -- they may have side effects.
+ */
+
+#define VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, \
+ _zzq_request, _zzq_arg1, _zzq_arg2, \
+ _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ do { (_zzq_rlval) = VALGRIND_DO_CLIENT_REQUEST_EXPR((_zzq_default), \
+ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \
+ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
+
+#define VALGRIND_DO_CLIENT_REQUEST_STMT(_zzq_request, _zzq_arg1, \
+ _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
+ (_zzq_request), (_zzq_arg1), (_zzq_arg2), \
+ (_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
+
+#if defined(NVALGRIND)
+
+/* Define NVALGRIND to completely remove the Valgrind magic sequence
+ from the compiled code (analogous to NDEBUG's effects on
+ assert()) */
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ (_zzq_default)
+
+#else /* ! NVALGRIND */
+
+/* The following defines the magic code sequences which the JITter
+ spots and handles magically. Don't look too closely at them as
+ they will rot your brain.
+
+ The assembly code sequences for all architectures is in this one
+ file. This is because this file must be stand-alone, and we don't
+ want to have multiple files.
+
+ For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default
+ value gets put in the return slot, so that everything works when
+ this is executed not under Valgrind. Args are passed in a memory
+ block, and so there's no intrinsic limit to the number that could
+ be passed, but it's currently five.
+
+ The macro args are:
+ _zzq_rlval result lvalue
+ _zzq_default default value (result returned when running on real CPU)
+ _zzq_request request code
+ _zzq_arg1..5 request params
+
+ The other two macros are used to support function wrapping, and are
+ a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the
+ guest's NRADDR pseudo-register and whatever other information is
+ needed to safely run the call original from the wrapper: on
+ ppc64-linux, the R2 value at the divert point is also needed. This
+ information is abstracted into a user-visible type, OrigFn.
+
+ VALGRIND_CALL_NOREDIR_* behaves the same as the following on the
+ guest, but guarantees that the branch instruction will not be
+ redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64:
+ branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a
+ complete inline asm, since it needs to be combined with more magic
+ inline asm stuff to be useful.
+*/
+
+/* ----------------- x86-{linux,darwin,solaris} ---------------- */
+
+#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
+ || (defined(PLAT_x86_win32) && defined(__GNUC__)) \
+ || defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "roll $3, %%edi ; roll $13, %%edi\n\t" \
+ "roll $29, %%edi ; roll $19, %%edi\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({volatile unsigned int _zzq_args[6]; \
+ volatile unsigned int _zzq_result; \
+ _zzq_args[0] = (unsigned int)(_zzq_request); \
+ _zzq_args[1] = (unsigned int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned int)(_zzq_arg5); \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %EDX = client_request ( %EAX ) */ \
+ "xchgl %%ebx,%%ebx" \
+ : "=d" (_zzq_result) \
+ : "a" (&_zzq_args[0]), "0" (_zzq_default) \
+ : "cc", "memory" \
+ ); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %EAX = guest_NRADDR */ \
+ "xchgl %%ecx,%%ecx" \
+ : "=a" (__addr) \
+ : \
+ : "cc", "memory" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_EAX \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* call-noredir *%EAX */ \
+ "xchgl %%edx,%%edx\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "xchgl %%edi,%%edi\n\t" \
+ : : : "cc", "memory" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_x86_linux || PLAT_x86_darwin || (PLAT_x86_win32 && __GNUC__)
+ || PLAT_x86_solaris */
+
+/* ------------------------- x86-Win32 ------------------------- */
+
+#if defined(PLAT_x86_win32) && !defined(__GNUC__)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#if defined(_MSC_VER)
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ __asm rol edi, 3 __asm rol edi, 13 \
+ __asm rol edi, 29 __asm rol edi, 19
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \
+ (uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \
+ (uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \
+ (uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5))
+
+static __inline uintptr_t
+valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request,
+ uintptr_t _zzq_arg1, uintptr_t _zzq_arg2,
+ uintptr_t _zzq_arg3, uintptr_t _zzq_arg4,
+ uintptr_t _zzq_arg5)
+{
+ volatile uintptr_t _zzq_args[6];
+ volatile unsigned int _zzq_result;
+ _zzq_args[0] = (uintptr_t)(_zzq_request);
+ _zzq_args[1] = (uintptr_t)(_zzq_arg1);
+ _zzq_args[2] = (uintptr_t)(_zzq_arg2);
+ _zzq_args[3] = (uintptr_t)(_zzq_arg3);
+ _zzq_args[4] = (uintptr_t)(_zzq_arg4);
+ _zzq_args[5] = (uintptr_t)(_zzq_arg5);
+ __asm { __asm lea eax, _zzq_args __asm mov edx, _zzq_default
+ __SPECIAL_INSTRUCTION_PREAMBLE
+ /* %EDX = client_request ( %EAX ) */
+ __asm xchg ebx,ebx
+ __asm mov _zzq_result, edx
+ }
+ return _zzq_result;
+}
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned int __addr; \
+ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %EAX = guest_NRADDR */ \
+ __asm xchg ecx,ecx \
+ __asm mov __addr, eax \
+ } \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_EAX ERROR
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm { __SPECIAL_INSTRUCTION_PREAMBLE \
+ __asm xchg edi,edi \
+ } \
+ } while (0)
+
+#else
+#error Unsupported compiler.
+#endif
+
+#endif /* PLAT_x86_win32 */
+
+/* ----------------- amd64-{linux,darwin,solaris} --------------- */
+
+#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
+ || defined(PLAT_amd64_solaris) \
+ || defined(PLAT_amd64_freebsd) \
+ || (defined(PLAT_amd64_win64) && defined(__GNUC__))
+
+typedef
+ struct {
+ unsigned long int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
+ "rolq $61, %%rdi ; rolq $51, %%rdi\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({ volatile unsigned long int _zzq_args[6]; \
+ volatile unsigned long int _zzq_result; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %RDX = client_request ( %RAX ) */ \
+ "xchgq %%rbx,%%rbx" \
+ : "=d" (_zzq_result) \
+ : "a" (&_zzq_args[0]), "0" (_zzq_default) \
+ : "cc", "memory" \
+ ); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %RAX = guest_NRADDR */ \
+ "xchgq %%rcx,%%rcx" \
+ : "=a" (__addr) \
+ : \
+ : "cc", "memory" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_RAX \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* call-noredir *%RAX */ \
+ "xchgq %%rdx,%%rdx\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "xchgq %%rdi,%%rdi\n\t" \
+ : : : "cc", "memory" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
+
+/* ------------------------- amd64-Win64 ------------------------- */
+
+#if defined(PLAT_amd64_win64) && !defined(__GNUC__)
+
+#error Unsupported compiler.
+
+#endif /* PLAT_amd64_win64 */
+
+/* ------------------------ ppc32-linux ------------------------ */
+
+#if defined(PLAT_ppc32_linux)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
+ "rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ \
+ __extension__ \
+ ({ unsigned int _zzq_args[6]; \
+ unsigned int _zzq_result; \
+ unsigned int* _zzq_ptr; \
+ _zzq_args[0] = (unsigned int)(_zzq_request); \
+ _zzq_args[1] = (unsigned int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned int)(_zzq_arg5); \
+ _zzq_ptr = _zzq_args; \
+ __asm__ volatile("mr 3,%1\n\t" /*default*/ \
+ "mr 4,%2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = client_request ( %R4 ) */ \
+ "or 1,1,1\n\t" \
+ "mr %0,3" /*result*/ \
+ : "=b" (_zzq_result) \
+ : "b" (_zzq_default), "b" (_zzq_ptr) \
+ : "cc", "memory", "r3", "r4"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ unsigned int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = guest_NRADDR */ \
+ "or 2,2,2\n\t" \
+ "mr %0,3" \
+ : "=b" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* branch-and-link-to-noredir *%R11 */ \
+ "or 3,3,3\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or 5,5,5\n\t" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_ppc32_linux */
+
+/* ------------------------ ppc64-linux ------------------------ */
+
+#if defined(PLAT_ppc64be_linux)
+
+typedef
+ struct {
+ unsigned long int nraddr; /* where's the code? */
+ unsigned long int r2; /* what tocptr do we need? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
+ "rotldi 0,0,61 ; rotldi 0,0,51\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ \
+ __extension__ \
+ ({ unsigned long int _zzq_args[6]; \
+ unsigned long int _zzq_result; \
+ unsigned long int* _zzq_ptr; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ _zzq_ptr = _zzq_args; \
+ __asm__ volatile("mr 3,%1\n\t" /*default*/ \
+ "mr 4,%2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = client_request ( %R4 ) */ \
+ "or 1,1,1\n\t" \
+ "mr %0,3" /*result*/ \
+ : "=b" (_zzq_result) \
+ : "b" (_zzq_default), "b" (_zzq_ptr) \
+ : "cc", "memory", "r3", "r4"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = guest_NRADDR */ \
+ "or 2,2,2\n\t" \
+ "mr %0,3" \
+ : "=b" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = guest_NRADDR_GPR2 */ \
+ "or 4,4,4\n\t" \
+ "mr %0,3" \
+ : "=b" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->r2 = __addr; \
+ }
+
+#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* branch-and-link-to-noredir *%R11 */ \
+ "or 3,3,3\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or 5,5,5\n\t" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_ppc64be_linux */
+
+#if defined(PLAT_ppc64le_linux)
+
+typedef
+ struct {
+ unsigned long int nraddr; /* where's the code? */
+ unsigned long int r2; /* what tocptr do we need? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
+ "rotldi 0,0,61 ; rotldi 0,0,51\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ \
+ __extension__ \
+ ({ unsigned long int _zzq_args[6]; \
+ unsigned long int _zzq_result; \
+ unsigned long int* _zzq_ptr; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ _zzq_ptr = _zzq_args; \
+ __asm__ volatile("mr 3,%1\n\t" /*default*/ \
+ "mr 4,%2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = client_request ( %R4 ) */ \
+ "or 1,1,1\n\t" \
+ "mr %0,3" /*result*/ \
+ : "=b" (_zzq_result) \
+ : "b" (_zzq_default), "b" (_zzq_ptr) \
+ : "cc", "memory", "r3", "r4"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = guest_NRADDR */ \
+ "or 2,2,2\n\t" \
+ "mr %0,3" \
+ : "=b" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %R3 = guest_NRADDR_GPR2 */ \
+ "or 4,4,4\n\t" \
+ "mr %0,3" \
+ : "=b" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->r2 = __addr; \
+ }
+
+#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* branch-and-link-to-noredir *%R12 */ \
+ "or 3,3,3\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or 5,5,5\n\t" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_ppc64le_linux */
+
+/* ------------------------- arm-linux ------------------------- */
+
+#if defined(PLAT_arm_linux)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
+ "mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ \
+ __extension__ \
+ ({volatile unsigned int _zzq_args[6]; \
+ volatile unsigned int _zzq_result; \
+ _zzq_args[0] = (unsigned int)(_zzq_request); \
+ _zzq_args[1] = (unsigned int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned int)(_zzq_arg5); \
+ __asm__ volatile("mov r3, %1\n\t" /*default*/ \
+ "mov r4, %2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* R3 = client_request ( R4 ) */ \
+ "orr r10, r10, r10\n\t" \
+ "mov %0, r3" /*result*/ \
+ : "=r" (_zzq_result) \
+ : "r" (_zzq_default), "r" (&_zzq_args[0]) \
+ : "cc","memory", "r3", "r4"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ unsigned int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* R3 = guest_NRADDR */ \
+ "orr r11, r11, r11\n\t" \
+ "mov %0, r3" \
+ : "=r" (__addr) \
+ : \
+ : "cc", "memory", "r3" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* branch-and-link-to-noredir *%R4 */ \
+ "orr r12, r12, r12\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "orr r9, r9, r9\n\t" \
+ : : : "cc", "memory" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_arm_linux */
+
+/* ------------------------ arm64-linux ------------------------- */
+
+#if defined(PLAT_arm64_linux)
+
+typedef
+ struct {
+ unsigned long int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "ror x12, x12, #3 ; ror x12, x12, #13 \n\t" \
+ "ror x12, x12, #51 ; ror x12, x12, #61 \n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ \
+ __extension__ \
+ ({volatile unsigned long int _zzq_args[6]; \
+ volatile unsigned long int _zzq_result; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ __asm__ volatile("mov x3, %1\n\t" /*default*/ \
+ "mov x4, %2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* X3 = client_request ( X4 ) */ \
+ "orr x10, x10, x10\n\t" \
+ "mov %0, x3" /*result*/ \
+ : "=r" (_zzq_result) \
+ : "r" ((unsigned long int)(_zzq_default)), \
+ "r" (&_zzq_args[0]) \
+ : "cc","memory", "x3", "x4"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* X3 = guest_NRADDR */ \
+ "orr x11, x11, x11\n\t" \
+ "mov %0, x3" \
+ : "=r" (__addr) \
+ : \
+ : "cc", "memory", "x3" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* branch-and-link-to-noredir X8 */ \
+ "orr x12, x12, x12\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "orr x9, x9, x9\n\t" \
+ : : : "cc", "memory" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_arm64_linux */
+
+/* ------------------------ s390x-linux ------------------------ */
+
+#if defined(PLAT_s390x_linux)
+
+typedef
+ struct {
+ unsigned long int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+/* __SPECIAL_INSTRUCTION_PREAMBLE will be used to identify Valgrind specific
+ * code. This detection is implemented in platform specific toIR.c
+ * (e.g. VEX/priv/guest_s390_decoder.c).
+ */
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "lr 15,15\n\t" \
+ "lr 1,1\n\t" \
+ "lr 2,2\n\t" \
+ "lr 3,3\n\t"
+
+#define __CLIENT_REQUEST_CODE "lr 2,2\n\t"
+#define __GET_NR_CONTEXT_CODE "lr 3,3\n\t"
+#define __CALL_NO_REDIR_CODE "lr 4,4\n\t"
+#define __VEX_INJECT_IR_CODE "lr 5,5\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({volatile unsigned long int _zzq_args[6]; \
+ volatile unsigned long int _zzq_result; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ __asm__ volatile(/* r2 = args */ \
+ "lgr 2,%1\n\t" \
+ /* r3 = default */ \
+ "lgr 3,%2\n\t" \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ __CLIENT_REQUEST_CODE \
+ /* results = r3 */ \
+ "lgr %0, 3\n\t" \
+ : "=d" (_zzq_result) \
+ : "a" (&_zzq_args[0]), \
+ "0" ((unsigned long int)_zzq_default) \
+ : "cc", "2", "3", "memory" \
+ ); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ __GET_NR_CONTEXT_CODE \
+ "lgr %0, 3\n\t" \
+ : "=a" (__addr) \
+ : \
+ : "cc", "3", "memory" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_R1 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ __CALL_NO_REDIR_CODE
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ __VEX_INJECT_IR_CODE); \
+ } while (0)
+
+#endif /* PLAT_s390x_linux */
+
+/* ------------------------- mips32-linux ---------------- */
+
+#if defined(PLAT_mips32_linux)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+/* .word 0x342
+ * .word 0x742
+ * .word 0xC2
+ * .word 0x4C2*/
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "srl $0, $0, 13\n\t" \
+ "srl $0, $0, 29\n\t" \
+ "srl $0, $0, 3\n\t" \
+ "srl $0, $0, 19\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({ volatile unsigned int _zzq_args[6]; \
+ volatile unsigned int _zzq_result; \
+ _zzq_args[0] = (unsigned int)(_zzq_request); \
+ _zzq_args[1] = (unsigned int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned int)(_zzq_arg5); \
+ __asm__ volatile("move $11, %1\n\t" /*default*/ \
+ "move $12, %2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* T3 = client_request ( T4 ) */ \
+ "or $13, $13, $13\n\t" \
+ "move %0, $11\n\t" /*result*/ \
+ : "=r" (_zzq_result) \
+ : "r" (_zzq_default), "r" (&_zzq_args[0]) \
+ : "$11", "$12", "memory"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* %t9 = guest_NRADDR */ \
+ "or $14, $14, $14\n\t" \
+ "move %0, $11" /*result*/ \
+ : "=r" (__addr) \
+ : \
+ : "$11" \
+ ); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_T9 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* call-noredir *%t9 */ \
+ "or $15, $15, $15\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or $11, $11, $11\n\t" \
+ ); \
+ } while (0)
+
+
+#endif /* PLAT_mips32_linux */
+
+/* ------------------------- mips64-linux ---------------- */
+
+#if defined(PLAT_mips64_linux)
+
+typedef
+ struct {
+ unsigned long nraddr; /* where's the code? */
+ }
+ OrigFn;
+
+/* dsll $0,$0, 3
+ * dsll $0,$0, 13
+ * dsll $0,$0, 29
+ * dsll $0,$0, 19*/
+#define __SPECIAL_INSTRUCTION_PREAMBLE \
+ "dsll $0,$0, 3 ; dsll $0,$0,13\n\t" \
+ "dsll $0,$0,29 ; dsll $0,$0,19\n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({ volatile unsigned long int _zzq_args[6]; \
+ volatile unsigned long int _zzq_result; \
+ _zzq_args[0] = (unsigned long int)(_zzq_request); \
+ _zzq_args[1] = (unsigned long int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned long int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned long int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned long int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned long int)(_zzq_arg5); \
+ __asm__ volatile("move $11, %1\n\t" /*default*/ \
+ "move $12, %2\n\t" /*ptr*/ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* $11 = client_request ( $12 ) */ \
+ "or $13, $13, $13\n\t" \
+ "move %0, $11\n\t" /*result*/ \
+ : "=r" (_zzq_result) \
+ : "r" (_zzq_default), "r" (&_zzq_args[0]) \
+ : "$11", "$12", "memory"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* $11 = guest_NRADDR */ \
+ "or $14, $14, $14\n\t" \
+ "move %0, $11" /*result*/ \
+ : "=r" (__addr) \
+ : \
+ : "$11"); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_T9 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* call-noredir $25 */ \
+ "or $15, $15, $15\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or $11, $11, $11\n\t" \
+ ); \
+ } while (0)
+
+#endif /* PLAT_mips64_linux */
+
+#if defined(PLAT_nanomips_linux)
+
+typedef
+ struct {
+ unsigned int nraddr; /* where's the code? */
+ }
+ OrigFn;
+/*
+ 8000 c04d srl zero, zero, 13
+ 8000 c05d srl zero, zero, 29
+ 8000 c043 srl zero, zero, 3
+ 8000 c053 srl zero, zero, 19
+*/
+
+#define __SPECIAL_INSTRUCTION_PREAMBLE "srl[32] $zero, $zero, 13 \n\t" \
+ "srl[32] $zero, $zero, 29 \n\t" \
+ "srl[32] $zero, $zero, 3 \n\t" \
+ "srl[32] $zero, $zero, 19 \n\t"
+
+#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ _zzq_default, _zzq_request, \
+ _zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
+ __extension__ \
+ ({ volatile unsigned int _zzq_args[6]; \
+ volatile unsigned int _zzq_result; \
+ _zzq_args[0] = (unsigned int)(_zzq_request); \
+ _zzq_args[1] = (unsigned int)(_zzq_arg1); \
+ _zzq_args[2] = (unsigned int)(_zzq_arg2); \
+ _zzq_args[3] = (unsigned int)(_zzq_arg3); \
+ _zzq_args[4] = (unsigned int)(_zzq_arg4); \
+ _zzq_args[5] = (unsigned int)(_zzq_arg5); \
+ __asm__ volatile("move $a7, %1\n\t" /* default */ \
+ "move $t0, %2\n\t" /* ptr */ \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* $a7 = client_request( $t0 ) */ \
+ "or[32] $t0, $t0, $t0\n\t" \
+ "move %0, $a7\n\t" /* result */ \
+ : "=r" (_zzq_result) \
+ : "r" (_zzq_default), "r" (&_zzq_args[0]) \
+ : "$a7", "$t0", "memory"); \
+ _zzq_result; \
+ })
+
+#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
+ { volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
+ volatile unsigned long int __addr; \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ /* $a7 = guest_NRADDR */ \
+ "or[32] $t1, $t1, $t1\n\t" \
+ "move %0, $a7" /*result*/ \
+ : "=r" (__addr) \
+ : \
+ : "$a7"); \
+ _zzq_orig->nraddr = __addr; \
+ }
+
+#define VALGRIND_CALL_NOREDIR_T9 \
+ __SPECIAL_INSTRUCTION_PREAMBLE \
+ /* call-noredir $25 */ \
+ "or[32] $t2, $t2, $t2\n\t"
+
+#define VALGRIND_VEX_INJECT_IR() \
+ do { \
+ __asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
+ "or[32] $t3, $t3, $t3\n\t" \
+ ); \
+ } while (0)
+
+#endif
+/* Insert assembly code for other platforms here... */
+
+#endif /* NVALGRIND */
+
+
+/* ------------------------------------------------------------------ */
+/* PLATFORM SPECIFICS for FUNCTION WRAPPING. This is all very */
+/* ugly. It's the least-worst tradeoff I can think of. */
+/* ------------------------------------------------------------------ */
+
+/* This section defines magic (a.k.a appalling-hack) macros for doing
+ guaranteed-no-redirection macros, so as to get from function
+ wrappers to the functions they are wrapping. The whole point is to
+ construct standard call sequences, but to do the call itself with a
+ special no-redirect call pseudo-instruction that the JIT
+ understands and handles specially. This section is long and
+ repetitious, and I can't see a way to make it shorter.
+
+ The naming scheme is as follows:
+
+ CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc}
+
+ 'W' stands for "word" and 'v' for "void". Hence there are
+ different macros for calling arity 0, 1, 2, 3, 4, etc, functions,
+ and for each, the possibility of returning a word-typed result, or
+ no result.
+*/
+
+/* Use these to write the name of your wrapper. NOTE: duplicates
+ VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. NOTE also: inserts
+ the default behaviour equivalance class tag "0000" into the name.
+ See pub_tool_redir.h for details -- normally you don't need to
+ think about this, though. */
+
+/* Use an extra level of macroisation so as to ensure the soname/fnname
+ args are fully macro-expanded before pasting them together. */
+#define VG_CONCAT4(_aa,_bb,_cc,_dd) _aa##_bb##_cc##_dd
+
+#define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \
+ VG_CONCAT4(_vgw00000ZU_,soname,_,fnname)
+
+#define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \
+ VG_CONCAT4(_vgw00000ZZ_,soname,_,fnname)
+
+/* Use this macro from within a wrapper function to collect the
+ context (address and possibly other info) of the original function.
+ Once you have that you can then use it in one of the CALL_FN_
+ macros. The type of the argument _lval is OrigFn. */
+#define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval)
+
+/* Also provide end-user facilities for function replacement, rather
+ than wrapping. A replacement function differs from a wrapper in
+ that it has no way to get hold of the original function being
+ called, and hence no way to call onwards to it. In a replacement
+ function, VALGRIND_GET_ORIG_FN always returns zero. */
+
+#define I_REPLACE_SONAME_FNNAME_ZU(soname,fnname) \
+ VG_CONCAT4(_vgr00000ZU_,soname,_,fnname)
+
+#define I_REPLACE_SONAME_FNNAME_ZZ(soname,fnname) \
+ VG_CONCAT4(_vgr00000ZZ_,soname,_,fnname)
+
+/* Derivatives of the main macros below, for calling functions
+ returning void. */
+
+#define CALL_FN_v_v(fnptr) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_v(_junk,fnptr); } while (0)
+
+#define CALL_FN_v_W(fnptr, arg1) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_W(_junk,fnptr,arg1); } while (0)
+
+#define CALL_FN_v_WW(fnptr, arg1,arg2) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0)
+
+#define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0)
+
+#define CALL_FN_v_WWWW(fnptr, arg1,arg2,arg3,arg4) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_WWWW(_junk,fnptr,arg1,arg2,arg3,arg4); } while (0)
+
+#define CALL_FN_v_5W(fnptr, arg1,arg2,arg3,arg4,arg5) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_5W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5); } while (0)
+
+#define CALL_FN_v_6W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_6W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6); } while (0)
+
+#define CALL_FN_v_7W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6,arg7) \
+ do { volatile unsigned long _junk; \
+ CALL_FN_W_7W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6,arg7); } while (0)
+
+/* ----------------- x86-{linux,darwin,solaris} ---------------- */
+
+#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
+ || defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd)
+
+/* These regs are trashed by the hidden call. No need to mention eax
+ as gcc can already see that, plus causes gcc to bomb. */
+#define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx"
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+#define VALGRIND_ALIGN_STACK \
+ "movl %%esp,%%edi\n\t" \
+ "andl $0xfffffff0,%%esp\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "movl %%edi,%%esp\n\t"
+
+/* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned
+ long) == 4. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $12, %%esp\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $8, %%esp\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $4, %%esp\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $12, %%esp\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $8, %%esp\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $4, %%esp\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "pushl 32(%%eax)\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $12, %%esp\n\t" \
+ "pushl 36(%%eax)\n\t" \
+ "pushl 32(%%eax)\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $8, %%esp\n\t" \
+ "pushl 40(%%eax)\n\t" \
+ "pushl 36(%%eax)\n\t" \
+ "pushl 32(%%eax)\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "subl $4, %%esp\n\t" \
+ "pushl 44(%%eax)\n\t" \
+ "pushl 40(%%eax)\n\t" \
+ "pushl 36(%%eax)\n\t" \
+ "pushl 32(%%eax)\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "pushl 48(%%eax)\n\t" \
+ "pushl 44(%%eax)\n\t" \
+ "pushl 40(%%eax)\n\t" \
+ "pushl 36(%%eax)\n\t" \
+ "pushl 32(%%eax)\n\t" \
+ "pushl 28(%%eax)\n\t" \
+ "pushl 24(%%eax)\n\t" \
+ "pushl 20(%%eax)\n\t" \
+ "pushl 16(%%eax)\n\t" \
+ "pushl 12(%%eax)\n\t" \
+ "pushl 8(%%eax)\n\t" \
+ "pushl 4(%%eax)\n\t" \
+ "movl (%%eax), %%eax\n\t" /* target->%eax */ \
+ VALGRIND_CALL_NOREDIR_EAX \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_x86_linux || PLAT_x86_darwin || PLAT_x86_solaris */
+
+/* ---------------- amd64-{linux,darwin,solaris} --------------- */
+
+#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
+ || defined(PLAT_amd64_solaris) || defined(PLAT_amd64_freebsd)
+
+/* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \
+ "rdi", "r8", "r9", "r10", "r11"
+
+/* This is all pretty complex. It's so as to make stack unwinding
+ work reliably. See bug 243270. The basic problem is the sub and
+ add of 128 of %rsp in all of the following macros. If gcc believes
+ the CFA is in %rsp, then unwinding may fail, because what's at the
+ CFA is not what gcc "expected" when it constructs the CFIs for the
+ places where the macros are instantiated.
+
+ But we can't just add a CFI annotation to increase the CFA offset
+ by 128, to match the sub of 128 from %rsp, because we don't know
+ whether gcc has chosen %rsp as the CFA at that point, or whether it
+ has chosen some other register (eg, %rbp). In the latter case,
+ adding a CFI annotation to change the CFA offset is simply wrong.
+
+ So the solution is to get hold of the CFA using
+ __builtin_dwarf_cfa(), put it in a known register, and add a
+ CFI annotation to say what the register is. We choose %rbp for
+ this (perhaps perversely), because:
+
+ (1) %rbp is already subject to unwinding. If a new register was
+ chosen then the unwinder would have to unwind it in all stack
+ traces, which is expensive, and
+
+ (2) %rbp is already subject to precise exception updates in the
+ JIT. If a new register was chosen, we'd have to have precise
+ exceptions for it too, which reduces performance of the
+ generated code.
+
+ However .. one extra complication. We can't just whack the result
+ of __builtin_dwarf_cfa() into %rbp and then add %rbp to the
+ list of trashed registers at the end of the inline assembly
+ fragments; gcc won't allow %rbp to appear in that list. Hence
+ instead we need to stash %rbp in %r15 for the duration of the asm,
+ and say that %r15 is trashed instead. gcc seems happy to go with
+ that.
+
+ Oh .. and this all needs to be conditionalised so that it is
+ unchanged from before this commit, when compiled with older gccs
+ that don't support __builtin_dwarf_cfa. Furthermore, since
+ this header file is freestanding, it has to be independent of
+ config.h, and so the following conditionalisation cannot depend on
+ configure time checks.
+
+ Although it's not clear from
+ 'defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)',
+ this expression excludes Darwin.
+ .cfi directives in Darwin assembly appear to be completely
+ different and I haven't investigated how they work.
+
+ For even more entertainment value, note we have to use the
+ completely undocumented __builtin_dwarf_cfa(), which appears to
+ really compute the CFA, whereas __builtin_frame_address(0) claims
+ to but actually doesn't. See
+ https://bugs.kde.org/show_bug.cgi?id=243270#c47
+*/
+#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
+# define __FRAME_POINTER \
+ ,"r"(__builtin_dwarf_cfa())
+# define VALGRIND_CFI_PROLOGUE \
+ "movq %%rbp, %%r15\n\t" \
+ "movq %2, %%rbp\n\t" \
+ ".cfi_remember_state\n\t" \
+ ".cfi_def_cfa rbp, 0\n\t"
+# define VALGRIND_CFI_EPILOGUE \
+ "movq %%r15, %%rbp\n\t" \
+ ".cfi_restore_state\n\t"
+#else
+# define __FRAME_POINTER
+# define VALGRIND_CFI_PROLOGUE
+# define VALGRIND_CFI_EPILOGUE
+#endif
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+#define VALGRIND_ALIGN_STACK \
+ "movq %%rsp,%%r14\n\t" \
+ "andq $0xfffffffffffffff0,%%rsp\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "movq %%r14,%%rsp\n\t"
+
+/* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned
+ long) == 8. */
+
+/* NB 9 Sept 07. There is a nasty kludge here in all these CALL_FN_
+ macros. In order not to trash the stack redzone, we need to drop
+ %rsp by 128 before the hidden call, and restore afterwards. The
+ nastyness is that it is only by luck that the stack still appears
+ to be unwindable during the hidden call - since then the behaviour
+ of any routine using this macro does not match what the CFI data
+ says. Sigh.
+
+ Why is this important? Imagine that a wrapper has a stack
+ allocated local, and passes to the hidden call, a pointer to it.
+ Because gcc does not know about the hidden call, it may allocate
+ that local in the redzone. Unfortunately the hidden call may then
+ trash it before it comes to use it. So we must step clear of the
+ redzone, for the duration of the hidden call, to make it safe.
+
+ Probably the same problem afflicts the other redzone-style ABIs too
+ (ppc64-linux); but for those, the stack is
+ self describing (none of this CFI nonsense) so at least messing
+ with the stack pointer doesn't give a danger of non-unwindable
+ stack. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $136,%%rsp\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "pushq 64(%%rax)\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $136,%%rsp\n\t" \
+ "pushq 72(%%rax)\n\t" \
+ "pushq 64(%%rax)\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "pushq 80(%%rax)\n\t" \
+ "pushq 72(%%rax)\n\t" \
+ "pushq 64(%%rax)\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $136,%%rsp\n\t" \
+ "pushq 88(%%rax)\n\t" \
+ "pushq 80(%%rax)\n\t" \
+ "pushq 72(%%rax)\n\t" \
+ "pushq 64(%%rax)\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ VALGRIND_ALIGN_STACK \
+ "subq $128,%%rsp\n\t" \
+ "pushq 96(%%rax)\n\t" \
+ "pushq 88(%%rax)\n\t" \
+ "pushq 80(%%rax)\n\t" \
+ "pushq 72(%%rax)\n\t" \
+ "pushq 64(%%rax)\n\t" \
+ "pushq 56(%%rax)\n\t" \
+ "movq 48(%%rax), %%r9\n\t" \
+ "movq 40(%%rax), %%r8\n\t" \
+ "movq 32(%%rax), %%rcx\n\t" \
+ "movq 24(%%rax), %%rdx\n\t" \
+ "movq 16(%%rax), %%rsi\n\t" \
+ "movq 8(%%rax), %%rdi\n\t" \
+ "movq (%%rax), %%rax\n\t" /* target->%rax */ \
+ VALGRIND_CALL_NOREDIR_RAX \
+ VALGRIND_RESTORE_STACK \
+ VALGRIND_CFI_EPILOGUE \
+ : /*out*/ "=a" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
+
+/* ------------------------ ppc32-linux ------------------------ */
+
+#if defined(PLAT_ppc32_linux)
+
+/* This is useful for finding out about the on-stack stuff:
+
+ extern int f9 ( int,int,int,int,int,int,int,int,int );
+ extern int f10 ( int,int,int,int,int,int,int,int,int,int );
+ extern int f11 ( int,int,int,int,int,int,int,int,int,int,int );
+ extern int f12 ( int,int,int,int,int,int,int,int,int,int,int,int );
+
+ int g9 ( void ) {
+ return f9(11,22,33,44,55,66,77,88,99);
+ }
+ int g10 ( void ) {
+ return f10(11,22,33,44,55,66,77,88,99,110);
+ }
+ int g11 ( void ) {
+ return f11(11,22,33,44,55,66,77,88,99,110,121);
+ }
+ int g12 ( void ) {
+ return f12(11,22,33,44,55,66,77,88,99,110,121,132);
+ }
+*/
+
+/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS \
+ "lr", "ctr", "xer", \
+ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
+ "r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
+ "r11", "r12", "r13"
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+#define VALGRIND_ALIGN_STACK \
+ "mr 28,1\n\t" \
+ "rlwinm 1,1,0,0,27\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "mr 1,28\n\t"
+
+/* These CALL_FN_ macros assume that on ppc32-linux,
+ sizeof(unsigned long) == 4. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 10,32(11)\n\t" /* arg8->r10 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "addi 1,1,-16\n\t" \
+ /* arg9 */ \
+ "lwz 3,36(11)\n\t" \
+ "stw 3,8(1)\n\t" \
+ /* args1-8 */ \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 10,32(11)\n\t" /* arg8->r10 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "addi 1,1,-16\n\t" \
+ /* arg10 */ \
+ "lwz 3,40(11)\n\t" \
+ "stw 3,12(1)\n\t" \
+ /* arg9 */ \
+ "lwz 3,36(11)\n\t" \
+ "stw 3,8(1)\n\t" \
+ /* args1-8 */ \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 10,32(11)\n\t" /* arg8->r10 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ _argvec[11] = (unsigned long)arg11; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "addi 1,1,-32\n\t" \
+ /* arg11 */ \
+ "lwz 3,44(11)\n\t" \
+ "stw 3,16(1)\n\t" \
+ /* arg10 */ \
+ "lwz 3,40(11)\n\t" \
+ "stw 3,12(1)\n\t" \
+ /* arg9 */ \
+ "lwz 3,36(11)\n\t" \
+ "stw 3,8(1)\n\t" \
+ /* args1-8 */ \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 10,32(11)\n\t" /* arg8->r10 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ _argvec[11] = (unsigned long)arg11; \
+ _argvec[12] = (unsigned long)arg12; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "addi 1,1,-32\n\t" \
+ /* arg12 */ \
+ "lwz 3,48(11)\n\t" \
+ "stw 3,20(1)\n\t" \
+ /* arg11 */ \
+ "lwz 3,44(11)\n\t" \
+ "stw 3,16(1)\n\t" \
+ /* arg10 */ \
+ "lwz 3,40(11)\n\t" \
+ "stw 3,12(1)\n\t" \
+ /* arg9 */ \
+ "lwz 3,36(11)\n\t" \
+ "stw 3,8(1)\n\t" \
+ /* args1-8 */ \
+ "lwz 3,4(11)\n\t" /* arg1->r3 */ \
+ "lwz 4,8(11)\n\t" \
+ "lwz 5,12(11)\n\t" \
+ "lwz 6,16(11)\n\t" /* arg4->r6 */ \
+ "lwz 7,20(11)\n\t" \
+ "lwz 8,24(11)\n\t" \
+ "lwz 9,28(11)\n\t" \
+ "lwz 10,32(11)\n\t" /* arg8->r10 */ \
+ "lwz 11,0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ VALGRIND_RESTORE_STACK \
+ "mr %0,3" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_ppc32_linux */
+
+/* ------------------------ ppc64-linux ------------------------ */
+
+#if defined(PLAT_ppc64be_linux)
+
+/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS \
+ "lr", "ctr", "xer", \
+ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
+ "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
+ "r11", "r12", "r13"
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+#define VALGRIND_ALIGN_STACK \
+ "mr 28,1\n\t" \
+ "rldicr 1,1,0,59\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "mr 1,28\n\t"
+
+/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
+ long) == 8. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+0]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+1]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+2]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+3]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+4]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+5]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+6]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+7]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+8]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(11)\n\t" /* arg8->r10 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+9]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-128\n\t" /* expand stack frame */ \
+ /* arg9 */ \
+ "ld 3,72(11)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(11)\n\t" /* arg8->r10 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+10]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-128\n\t" /* expand stack frame */ \
+ /* arg10 */ \
+ "ld 3,80(11)\n\t" \
+ "std 3,120(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(11)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(11)\n\t" /* arg8->r10 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+11]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ _argvec[2+11] = (unsigned long)arg11; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-144\n\t" /* expand stack frame */ \
+ /* arg11 */ \
+ "ld 3,88(11)\n\t" \
+ "std 3,128(1)\n\t" \
+ /* arg10 */ \
+ "ld 3,80(11)\n\t" \
+ "std 3,120(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(11)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(11)\n\t" /* arg8->r10 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+12]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ _argvec[2+11] = (unsigned long)arg11; \
+ _argvec[2+12] = (unsigned long)arg12; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 11,%1\n\t" \
+ "std 2,-16(11)\n\t" /* save tocptr */ \
+ "ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-144\n\t" /* expand stack frame */ \
+ /* arg12 */ \
+ "ld 3,96(11)\n\t" \
+ "std 3,136(1)\n\t" \
+ /* arg11 */ \
+ "ld 3,88(11)\n\t" \
+ "std 3,128(1)\n\t" \
+ /* arg10 */ \
+ "ld 3,80(11)\n\t" \
+ "std 3,120(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(11)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(11)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(11)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(11)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(11)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(11)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(11)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(11)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(11)\n\t" /* arg8->r10 */ \
+ "ld 11, 0(11)\n\t" /* target->r11 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
+ "mr 11,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(11)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_ppc64be_linux */
+
+/* ------------------------- ppc64le-linux ----------------------- */
+#if defined(PLAT_ppc64le_linux)
+
+/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS \
+ "lr", "ctr", "xer", \
+ "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
+ "r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
+ "r11", "r12", "r13"
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+#define VALGRIND_ALIGN_STACK \
+ "mr 28,1\n\t" \
+ "rldicr 1,1,0,59\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "mr 1,28\n\t"
+
+/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
+ long) == 8. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+0]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+1]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+2]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+3]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+4]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+5]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+6]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+7]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+8]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(12)\n\t" /* arg8->r10 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+9]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-128\n\t" /* expand stack frame */ \
+ /* arg9 */ \
+ "ld 3,72(12)\n\t" \
+ "std 3,96(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(12)\n\t" /* arg8->r10 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+10]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-128\n\t" /* expand stack frame */ \
+ /* arg10 */ \
+ "ld 3,80(12)\n\t" \
+ "std 3,104(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(12)\n\t" \
+ "std 3,96(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(12)\n\t" /* arg8->r10 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+11]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ _argvec[2+11] = (unsigned long)arg11; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-144\n\t" /* expand stack frame */ \
+ /* arg11 */ \
+ "ld 3,88(12)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* arg10 */ \
+ "ld 3,80(12)\n\t" \
+ "std 3,104(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(12)\n\t" \
+ "std 3,96(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(12)\n\t" /* arg8->r10 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3+12]; \
+ volatile unsigned long _res; \
+ /* _argvec[0] holds current r2 across the call */ \
+ _argvec[1] = (unsigned long)_orig.r2; \
+ _argvec[2] = (unsigned long)_orig.nraddr; \
+ _argvec[2+1] = (unsigned long)arg1; \
+ _argvec[2+2] = (unsigned long)arg2; \
+ _argvec[2+3] = (unsigned long)arg3; \
+ _argvec[2+4] = (unsigned long)arg4; \
+ _argvec[2+5] = (unsigned long)arg5; \
+ _argvec[2+6] = (unsigned long)arg6; \
+ _argvec[2+7] = (unsigned long)arg7; \
+ _argvec[2+8] = (unsigned long)arg8; \
+ _argvec[2+9] = (unsigned long)arg9; \
+ _argvec[2+10] = (unsigned long)arg10; \
+ _argvec[2+11] = (unsigned long)arg11; \
+ _argvec[2+12] = (unsigned long)arg12; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "mr 12,%1\n\t" \
+ "std 2,-16(12)\n\t" /* save tocptr */ \
+ "ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
+ "addi 1,1,-144\n\t" /* expand stack frame */ \
+ /* arg12 */ \
+ "ld 3,96(12)\n\t" \
+ "std 3,120(1)\n\t" \
+ /* arg11 */ \
+ "ld 3,88(12)\n\t" \
+ "std 3,112(1)\n\t" \
+ /* arg10 */ \
+ "ld 3,80(12)\n\t" \
+ "std 3,104(1)\n\t" \
+ /* arg9 */ \
+ "ld 3,72(12)\n\t" \
+ "std 3,96(1)\n\t" \
+ /* args1-8 */ \
+ "ld 3, 8(12)\n\t" /* arg1->r3 */ \
+ "ld 4, 16(12)\n\t" /* arg2->r4 */ \
+ "ld 5, 24(12)\n\t" /* arg3->r5 */ \
+ "ld 6, 32(12)\n\t" /* arg4->r6 */ \
+ "ld 7, 40(12)\n\t" /* arg5->r7 */ \
+ "ld 8, 48(12)\n\t" /* arg6->r8 */ \
+ "ld 9, 56(12)\n\t" /* arg7->r9 */ \
+ "ld 10, 64(12)\n\t" /* arg8->r10 */ \
+ "ld 12, 0(12)\n\t" /* target->r12 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
+ "mr 12,%1\n\t" \
+ "mr %0,3\n\t" \
+ "ld 2,-16(12)\n\t" /* restore tocptr */ \
+ VALGRIND_RESTORE_STACK \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[2]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_ppc64le_linux */
+
+/* ------------------------- arm-linux ------------------------- */
+
+#if defined(PLAT_arm_linux)
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS "r0", "r1", "r2", "r3","r4", "r12", "r14"
+
+/* Macros to save and align the stack before making a function
+ call and restore it afterwards as gcc may not keep the stack
+ pointer aligned if it doesn't realise calls are being made
+ to other functions. */
+
+/* This is a bit tricky. We store the original stack pointer in r10
+ as it is callee-saves. gcc doesn't allow the use of r11 for some
+ reason. Also, we can't directly "bic" the stack pointer in thumb
+ mode since r13 isn't an allowed register number in that context.
+ So use r4 as a temporary, since that is about to get trashed
+ anyway, just after each use of this macro. Side effect is we need
+ to be very careful about any future changes, since
+ VALGRIND_ALIGN_STACK simply assumes r4 is usable. */
+#define VALGRIND_ALIGN_STACK \
+ "mov r10, sp\n\t" \
+ "mov r4, sp\n\t" \
+ "bic r4, r4, #7\n\t" \
+ "mov sp, r4\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "mov sp, r10\n\t"
+
+/* These CALL_FN_ macros assume that on arm-linux, sizeof(unsigned
+ long) == 4. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #4 \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "push {r0} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "push {r0, r1} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #4 \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "push {r0, r1, r2} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "ldr r3, [%1, #32] \n\t" \
+ "push {r0, r1, r2, r3} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #4 \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "ldr r3, [%1, #32] \n\t" \
+ "ldr r4, [%1, #36] \n\t" \
+ "push {r0, r1, r2, r3, r4} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #40] \n\t" \
+ "push {r0} \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "ldr r3, [%1, #32] \n\t" \
+ "ldr r4, [%1, #36] \n\t" \
+ "push {r0, r1, r2, r3, r4} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #4 \n\t" \
+ "ldr r0, [%1, #40] \n\t" \
+ "ldr r1, [%1, #44] \n\t" \
+ "push {r0, r1} \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "ldr r3, [%1, #32] \n\t" \
+ "ldr r4, [%1, #36] \n\t" \
+ "push {r0, r1, r2, r3, r4} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr r0, [%1, #40] \n\t" \
+ "ldr r1, [%1, #44] \n\t" \
+ "ldr r2, [%1, #48] \n\t" \
+ "push {r0, r1, r2} \n\t" \
+ "ldr r0, [%1, #20] \n\t" \
+ "ldr r1, [%1, #24] \n\t" \
+ "ldr r2, [%1, #28] \n\t" \
+ "ldr r3, [%1, #32] \n\t" \
+ "ldr r4, [%1, #36] \n\t" \
+ "push {r0, r1, r2, r3, r4} \n\t" \
+ "ldr r0, [%1, #4] \n\t" \
+ "ldr r1, [%1, #8] \n\t" \
+ "ldr r2, [%1, #12] \n\t" \
+ "ldr r3, [%1, #16] \n\t" \
+ "ldr r4, [%1] \n\t" /* target->r4 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, r0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_arm_linux */
+
+/* ------------------------ arm64-linux ------------------------ */
+
+#if defined(PLAT_arm64_linux)
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS \
+ "x0", "x1", "x2", "x3","x4", "x5", "x6", "x7", "x8", "x9", \
+ "x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", \
+ "x18", "x19", "x20", "x30", \
+ "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \
+ "v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", \
+ "v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", \
+ "v26", "v27", "v28", "v29", "v30", "v31"
+
+/* x21 is callee-saved, so we can use it to save and restore SP around
+ the hidden call. */
+#define VALGRIND_ALIGN_STACK \
+ "mov x21, sp\n\t" \
+ "bic sp, x21, #15\n\t"
+#define VALGRIND_RESTORE_STACK \
+ "mov sp, x21\n\t"
+
+/* These CALL_FN_ macros assume that on arm64-linux,
+ sizeof(unsigned long) == 8. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x7, [%1, #64] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #0x20 \n\t" \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x7, [%1, #64] \n\t" \
+ "ldr x8, [%1, #72] \n\t" \
+ "str x8, [sp, #0] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #0x20 \n\t" \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x7, [%1, #64] \n\t" \
+ "ldr x8, [%1, #72] \n\t" \
+ "str x8, [sp, #0] \n\t" \
+ "ldr x8, [%1, #80] \n\t" \
+ "str x8, [sp, #8] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #0x30 \n\t" \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x7, [%1, #64] \n\t" \
+ "ldr x8, [%1, #72] \n\t" \
+ "str x8, [sp, #0] \n\t" \
+ "ldr x8, [%1, #80] \n\t" \
+ "str x8, [sp, #8] \n\t" \
+ "ldr x8, [%1, #88] \n\t" \
+ "str x8, [sp, #16] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10,arg11, \
+ arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ VALGRIND_ALIGN_STACK \
+ "sub sp, sp, #0x30 \n\t" \
+ "ldr x0, [%1, #8] \n\t" \
+ "ldr x1, [%1, #16] \n\t" \
+ "ldr x2, [%1, #24] \n\t" \
+ "ldr x3, [%1, #32] \n\t" \
+ "ldr x4, [%1, #40] \n\t" \
+ "ldr x5, [%1, #48] \n\t" \
+ "ldr x6, [%1, #56] \n\t" \
+ "ldr x7, [%1, #64] \n\t" \
+ "ldr x8, [%1, #72] \n\t" \
+ "str x8, [sp, #0] \n\t" \
+ "ldr x8, [%1, #80] \n\t" \
+ "str x8, [sp, #8] \n\t" \
+ "ldr x8, [%1, #88] \n\t" \
+ "str x8, [sp, #16] \n\t" \
+ "ldr x8, [%1, #96] \n\t" \
+ "str x8, [sp, #24] \n\t" \
+ "ldr x8, [%1] \n\t" /* target->x8 */ \
+ VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
+ VALGRIND_RESTORE_STACK \
+ "mov %0, x0" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_arm64_linux */
+
+/* ------------------------- s390x-linux ------------------------- */
+
+#if defined(PLAT_s390x_linux)
+
+/* Similar workaround as amd64 (see above), but we use r11 as frame
+ pointer and save the old r11 in r7. r11 might be used for
+ argvec, therefore we copy argvec in r1 since r1 is clobbered
+ after the call anyway. */
+#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
+# define __FRAME_POINTER \
+ ,"d"(__builtin_dwarf_cfa())
+# define VALGRIND_CFI_PROLOGUE \
+ ".cfi_remember_state\n\t" \
+ "lgr 1,%1\n\t" /* copy the argvec pointer in r1 */ \
+ "lgr 7,11\n\t" \
+ "lgr 11,%2\n\t" \
+ ".cfi_def_cfa r11, 0\n\t"
+# define VALGRIND_CFI_EPILOGUE \
+ "lgr 11, 7\n\t" \
+ ".cfi_restore_state\n\t"
+#else
+# define __FRAME_POINTER
+# define VALGRIND_CFI_PROLOGUE \
+ "lgr 1,%1\n\t"
+# define VALGRIND_CFI_EPILOGUE
+#endif
+
+/* Nb: On s390 the stack pointer is properly aligned *at all times*
+ according to the s390 GCC maintainer. (The ABI specification is not
+ precise in this regard.) Therefore, VALGRIND_ALIGN_STACK and
+ VALGRIND_RESTORE_STACK are not defined here. */
+
+/* These regs are trashed by the hidden call. Note that we overwrite
+ r14 in s390_irgen_noredir (VEX/priv/guest_s390_irgen.c) to give the
+ function a proper return address. All others are ABI defined call
+ clobbers. */
+#if defined(__VX__) || defined(__S390_VX__)
+#define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \
+ "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", \
+ "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", \
+ "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", \
+ "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
+#else
+#define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \
+ "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7"
+#endif
+
+/* Nb: Although r11 is modified in the asm snippets below (inside
+ VALGRIND_CFI_PROLOGUE) it is not listed in the clobber section, for
+ two reasons:
+ (1) r11 is restored in VALGRIND_CFI_EPILOGUE, so effectively it is not
+ modified
+ (2) GCC will complain that r11 cannot appear inside a clobber section,
+ when compiled with -O -fno-omit-frame-pointer
+ */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 1, 0(1)\n\t" /* target->r1 */ \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "d" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+/* The call abi has the arguments in r2-r6 and stack */
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1, arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1, arg2, arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1, arg2, arg3, arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1, arg2, arg3, arg4, arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-160\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,160\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-168\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,168\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-176\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,176\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7 ,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-184\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "mvc 176(8,15), 64(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,184\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7 ,arg8, arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-192\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "mvc 176(8,15), 64(1)\n\t" \
+ "mvc 184(8,15), 72(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,192\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7 ,arg8, arg9, arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-200\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "mvc 176(8,15), 64(1)\n\t" \
+ "mvc 184(8,15), 72(1)\n\t" \
+ "mvc 192(8,15), 80(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,200\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7 ,arg8, arg9, arg10, arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ _argvec[11] = (unsigned long)arg11; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-208\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "mvc 176(8,15), 64(1)\n\t" \
+ "mvc 184(8,15), 72(1)\n\t" \
+ "mvc 192(8,15), 80(1)\n\t" \
+ "mvc 200(8,15), 88(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,208\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
+ arg6, arg7 ,arg8, arg9, arg10, arg11, arg12)\
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)arg1; \
+ _argvec[2] = (unsigned long)arg2; \
+ _argvec[3] = (unsigned long)arg3; \
+ _argvec[4] = (unsigned long)arg4; \
+ _argvec[5] = (unsigned long)arg5; \
+ _argvec[6] = (unsigned long)arg6; \
+ _argvec[7] = (unsigned long)arg7; \
+ _argvec[8] = (unsigned long)arg8; \
+ _argvec[9] = (unsigned long)arg9; \
+ _argvec[10] = (unsigned long)arg10; \
+ _argvec[11] = (unsigned long)arg11; \
+ _argvec[12] = (unsigned long)arg12; \
+ __asm__ volatile( \
+ VALGRIND_CFI_PROLOGUE \
+ "aghi 15,-216\n\t" \
+ "lg 2, 8(1)\n\t" \
+ "lg 3,16(1)\n\t" \
+ "lg 4,24(1)\n\t" \
+ "lg 5,32(1)\n\t" \
+ "lg 6,40(1)\n\t" \
+ "mvc 160(8,15), 48(1)\n\t" \
+ "mvc 168(8,15), 56(1)\n\t" \
+ "mvc 176(8,15), 64(1)\n\t" \
+ "mvc 184(8,15), 72(1)\n\t" \
+ "mvc 192(8,15), 80(1)\n\t" \
+ "mvc 200(8,15), 88(1)\n\t" \
+ "mvc 208(8,15), 96(1)\n\t" \
+ "lg 1, 0(1)\n\t" \
+ VALGRIND_CALL_NOREDIR_R1 \
+ "aghi 15,216\n\t" \
+ VALGRIND_CFI_EPILOGUE \
+ "lgr %0, 2\n\t" \
+ : /*out*/ "=d" (_res) \
+ : /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
+ : /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+
+#endif /* PLAT_s390x_linux */
+
+/* ------------------------- mips32-linux ----------------------- */
+
+#if defined(PLAT_mips32_linux)
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
+"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
+"$25", "$31"
+
+/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned
+ long) == 4. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "subu $29, $29, 16 \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 16\n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "subu $29, $29, 16 \n\t" \
+ "lw $4, 4(%1) \n\t" /* arg1*/ \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 16 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "subu $29, $29, 16 \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 16 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "subu $29, $29, 16 \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 16 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "subu $29, $29, 16 \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 16 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 24\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 24 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 32\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "nop\n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 32 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 32\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 32 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 40\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 32(%1) \n\t" \
+ "sw $4, 28($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 40 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 40\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 32(%1) \n\t" \
+ "sw $4, 28($29) \n\t" \
+ "lw $4, 36(%1) \n\t" \
+ "sw $4, 32($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 40 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 48\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 32(%1) \n\t" \
+ "sw $4, 28($29) \n\t" \
+ "lw $4, 36(%1) \n\t" \
+ "sw $4, 32($29) \n\t" \
+ "lw $4, 40(%1) \n\t" \
+ "sw $4, 36($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 48 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 48\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 32(%1) \n\t" \
+ "sw $4, 28($29) \n\t" \
+ "lw $4, 36(%1) \n\t" \
+ "sw $4, 32($29) \n\t" \
+ "lw $4, 40(%1) \n\t" \
+ "sw $4, 36($29) \n\t" \
+ "lw $4, 44(%1) \n\t" \
+ "sw $4, 40($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 48 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ "subu $29, $29, 8 \n\t" \
+ "sw $28, 0($29) \n\t" \
+ "sw $31, 4($29) \n\t" \
+ "lw $4, 20(%1) \n\t" \
+ "subu $29, $29, 56\n\t" \
+ "sw $4, 16($29) \n\t" \
+ "lw $4, 24(%1) \n\t" \
+ "sw $4, 20($29) \n\t" \
+ "lw $4, 28(%1) \n\t" \
+ "sw $4, 24($29) \n\t" \
+ "lw $4, 32(%1) \n\t" \
+ "sw $4, 28($29) \n\t" \
+ "lw $4, 36(%1) \n\t" \
+ "sw $4, 32($29) \n\t" \
+ "lw $4, 40(%1) \n\t" \
+ "sw $4, 36($29) \n\t" \
+ "lw $4, 44(%1) \n\t" \
+ "sw $4, 40($29) \n\t" \
+ "lw $4, 48(%1) \n\t" \
+ "sw $4, 44($29) \n\t" \
+ "lw $4, 4(%1) \n\t" \
+ "lw $5, 8(%1) \n\t" \
+ "lw $6, 12(%1) \n\t" \
+ "lw $7, 16(%1) \n\t" \
+ "lw $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "addu $29, $29, 56 \n\t" \
+ "lw $28, 0($29) \n\t" \
+ "lw $31, 4($29) \n\t" \
+ "addu $29, $29, 8 \n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_mips32_linux */
+
+/* ------------------------- nanomips-linux -------------------- */
+
+#if defined(PLAT_nanomips_linux)
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS "$t4", "$t5", "$a0", "$a1", "$a2", \
+"$a3", "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", \
+"$t8","$t9", "$at"
+
+/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned
+ long) == 4. */
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[1]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[2]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[3]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[4]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[5]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ "lw $a3,16(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[6]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ "lw $a3,16(%1)\n\t" \
+ "lw $a4,20(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[7]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ "lw $a3,16(%1)\n\t" \
+ "lw $a4,20(%1)\n\t" \
+ "lw $a5,24(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[8]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ "lw $a3,16(%1)\n\t" \
+ "lw $a4,20(%1)\n\t" \
+ "lw $a5,24(%1)\n\t" \
+ "lw $a6,28(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[9]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ __asm__ volatile( \
+ "lw $t9, 0(%1)\n\t" \
+ "lw $a0, 4(%1)\n\t" \
+ "lw $a1, 8(%1)\n\t" \
+ "lw $a2,12(%1)\n\t" \
+ "lw $a3,16(%1)\n\t" \
+ "lw $a4,20(%1)\n\t" \
+ "lw $a5,24(%1)\n\t" \
+ "lw $a6,28(%1)\n\t" \
+ "lw $a7,32(%1)\n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[10]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ __asm__ volatile( \
+ "addiu $sp, $sp, -16 \n\t" \
+ "lw $t9,36(%1) \n\t" \
+ "sw $t9, 0($sp) \n\t" \
+ "lw $t9, 0(%1) \n\t" \
+ "lw $a0, 4(%1) \n\t" \
+ "lw $a1, 8(%1) \n\t" \
+ "lw $a2,12(%1) \n\t" \
+ "lw $a3,16(%1) \n\t" \
+ "lw $a4,20(%1) \n\t" \
+ "lw $a5,24(%1) \n\t" \
+ "lw $a6,28(%1) \n\t" \
+ "lw $a7,32(%1) \n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0 \n\t" \
+ "addiu $sp, $sp, 16 \n\t" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[11]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ __asm__ volatile( \
+ "addiu $sp, $sp, -16 \n\t" \
+ "lw $t9,36(%1) \n\t" \
+ "sw $t9, 0($sp) \n\t" \
+ "lw $t9,40(%1) \n\t" \
+ "sw $t9, 4($sp) \n\t" \
+ "lw $t9, 0(%1) \n\t" \
+ "lw $a0, 4(%1) \n\t" \
+ "lw $a1, 8(%1) \n\t" \
+ "lw $a2,12(%1) \n\t" \
+ "lw $a3,16(%1) \n\t" \
+ "lw $a4,20(%1) \n\t" \
+ "lw $a5,24(%1) \n\t" \
+ "lw $a6,28(%1) \n\t" \
+ "lw $a7,32(%1) \n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0 \n\t" \
+ "addiu $sp, $sp, 16 \n\t" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[12]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ __asm__ volatile( \
+ "addiu $sp, $sp, -16 \n\t" \
+ "lw $t9,36(%1) \n\t" \
+ "sw $t9, 0($sp) \n\t" \
+ "lw $t9,40(%1) \n\t" \
+ "sw $t9, 4($sp) \n\t" \
+ "lw $t9,44(%1) \n\t" \
+ "sw $t9, 8($sp) \n\t" \
+ "lw $t9, 0(%1) \n\t" \
+ "lw $a0, 4(%1) \n\t" \
+ "lw $a1, 8(%1) \n\t" \
+ "lw $a2,12(%1) \n\t" \
+ "lw $a3,16(%1) \n\t" \
+ "lw $a4,20(%1) \n\t" \
+ "lw $a5,24(%1) \n\t" \
+ "lw $a6,28(%1) \n\t" \
+ "lw $a7,32(%1) \n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0 \n\t" \
+ "addiu $sp, $sp, 16 \n\t" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long _argvec[13]; \
+ volatile unsigned long _res; \
+ _argvec[0] = (unsigned long)_orig.nraddr; \
+ _argvec[1] = (unsigned long)(arg1); \
+ _argvec[2] = (unsigned long)(arg2); \
+ _argvec[3] = (unsigned long)(arg3); \
+ _argvec[4] = (unsigned long)(arg4); \
+ _argvec[5] = (unsigned long)(arg5); \
+ _argvec[6] = (unsigned long)(arg6); \
+ _argvec[7] = (unsigned long)(arg7); \
+ _argvec[8] = (unsigned long)(arg8); \
+ _argvec[9] = (unsigned long)(arg9); \
+ _argvec[10] = (unsigned long)(arg10); \
+ _argvec[11] = (unsigned long)(arg11); \
+ _argvec[12] = (unsigned long)(arg12); \
+ __asm__ volatile( \
+ "addiu $sp, $sp, -16 \n\t" \
+ "lw $t9,36(%1) \n\t" \
+ "sw $t9, 0($sp) \n\t" \
+ "lw $t9,40(%1) \n\t" \
+ "sw $t9, 4($sp) \n\t" \
+ "lw $t9,44(%1) \n\t" \
+ "sw $t9, 8($sp) \n\t" \
+ "lw $t9,48(%1) \n\t" \
+ "sw $t9,12($sp) \n\t" \
+ "lw $t9, 0(%1) \n\t" \
+ "lw $a0, 4(%1) \n\t" \
+ "lw $a1, 8(%1) \n\t" \
+ "lw $a2,12(%1) \n\t" \
+ "lw $a3,16(%1) \n\t" \
+ "lw $a4,20(%1) \n\t" \
+ "lw $a5,24(%1) \n\t" \
+ "lw $a6,28(%1) \n\t" \
+ "lw $a7,32(%1) \n\t" \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $a0 \n\t" \
+ "addiu $sp, $sp, 16 \n\t" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) _res; \
+ } while (0)
+
+#endif /* PLAT_nanomips_linux */
+
+/* ------------------------- mips64-linux ------------------------- */
+
+#if defined(PLAT_mips64_linux)
+
+/* These regs are trashed by the hidden call. */
+#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
+"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
+"$25", "$31"
+
+/* These CALL_FN_ macros assume that on mips64-linux,
+ sizeof(long long) == 8. */
+
+#define MIPS64_LONG2REG_CAST(x) ((long long)(long)x)
+
+#define CALL_FN_W_v(lval, orig) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[1]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ __asm__ volatile( \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "0" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_W(lval, orig, arg1) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[2]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" /* arg1*/ \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[3]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = _orig.nraddr; \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+
+#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[4]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = _orig.nraddr; \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[5]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[6]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[7]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[8]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[9]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
+ __asm__ volatile( \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $11, 64(%1)\n\t" \
+ "ld $25, 0(%1) \n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[10]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
+ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
+ __asm__ volatile( \
+ "dsubu $29, $29, 8\n\t" \
+ "ld $4, 72(%1)\n\t" \
+ "sd $4, 0($29)\n\t" \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $11, 64(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "daddu $29, $29, 8\n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
+ arg7,arg8,arg9,arg10) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[11]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
+ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
+ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
+ __asm__ volatile( \
+ "dsubu $29, $29, 16\n\t" \
+ "ld $4, 72(%1)\n\t" \
+ "sd $4, 0($29)\n\t" \
+ "ld $4, 80(%1)\n\t" \
+ "sd $4, 8($29)\n\t" \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $11, 64(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "daddu $29, $29, 16\n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[12]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
+ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
+ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
+ _argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
+ __asm__ volatile( \
+ "dsubu $29, $29, 24\n\t" \
+ "ld $4, 72(%1)\n\t" \
+ "sd $4, 0($29)\n\t" \
+ "ld $4, 80(%1)\n\t" \
+ "sd $4, 8($29)\n\t" \
+ "ld $4, 88(%1)\n\t" \
+ "sd $4, 16($29)\n\t" \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $11, 64(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "daddu $29, $29, 24\n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
+ arg6,arg7,arg8,arg9,arg10, \
+ arg11,arg12) \
+ do { \
+ volatile OrigFn _orig = (orig); \
+ volatile unsigned long long _argvec[13]; \
+ volatile unsigned long long _res; \
+ _argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
+ _argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
+ _argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
+ _argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
+ _argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
+ _argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
+ _argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
+ _argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
+ _argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
+ _argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
+ _argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
+ _argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
+ _argvec[12] = MIPS64_LONG2REG_CAST(arg12); \
+ __asm__ volatile( \
+ "dsubu $29, $29, 32\n\t" \
+ "ld $4, 72(%1)\n\t" \
+ "sd $4, 0($29)\n\t" \
+ "ld $4, 80(%1)\n\t" \
+ "sd $4, 8($29)\n\t" \
+ "ld $4, 88(%1)\n\t" \
+ "sd $4, 16($29)\n\t" \
+ "ld $4, 96(%1)\n\t" \
+ "sd $4, 24($29)\n\t" \
+ "ld $4, 8(%1)\n\t" \
+ "ld $5, 16(%1)\n\t" \
+ "ld $6, 24(%1)\n\t" \
+ "ld $7, 32(%1)\n\t" \
+ "ld $8, 40(%1)\n\t" \
+ "ld $9, 48(%1)\n\t" \
+ "ld $10, 56(%1)\n\t" \
+ "ld $11, 64(%1)\n\t" \
+ "ld $25, 0(%1)\n\t" /* target->t9 */ \
+ VALGRIND_CALL_NOREDIR_T9 \
+ "daddu $29, $29, 32\n\t" \
+ "move %0, $2\n" \
+ : /*out*/ "=r" (_res) \
+ : /*in*/ "r" (&_argvec[0]) \
+ : /*trash*/ "memory", __CALLER_SAVED_REGS \
+ ); \
+ lval = (__typeof__(lval)) (long)_res; \
+ } while (0)
+
+#endif /* PLAT_mips64_linux */
+
+/* ------------------------------------------------------------------ */
+/* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */
+/* */
+/* ------------------------------------------------------------------ */
+
+/* Some request codes. There are many more of these, but most are not
+ exposed to end-user view. These are the public ones, all of the
+ form 0x1000 + small_number.
+
+ Core ones are in the range 0x00000000--0x0000ffff. The non-public
+ ones start at 0x2000.
+*/
+
+/* These macros are used by tools -- they must be public, but don't
+ embed them into other programs. */
+#define VG_USERREQ_TOOL_BASE(a,b) \
+ ((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16))
+#define VG_IS_TOOL_USERREQ(a, b, v) \
+ (VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000))
+
+/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
+ This enum comprises an ABI exported by Valgrind to programs
+ which use client requests. DO NOT CHANGE THE NUMERIC VALUES OF THESE
+ ENTRIES, NOR DELETE ANY -- add new ones at the end of the most
+ relevant group. */
+typedef
+ enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001,
+ VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
+
+ /* These allow any function to be called from the simulated
+ CPU but run on the real CPU. Nb: the first arg passed to
+ the function is always the ThreadId of the running
+ thread! So CLIENT_CALL0 actually requires a 1 arg
+ function, etc. */
+ VG_USERREQ__CLIENT_CALL0 = 0x1101,
+ VG_USERREQ__CLIENT_CALL1 = 0x1102,
+ VG_USERREQ__CLIENT_CALL2 = 0x1103,
+ VG_USERREQ__CLIENT_CALL3 = 0x1104,
+
+ /* Can be useful in regression testing suites -- eg. can
+ send Valgrind's output to /dev/null and still count
+ errors. */
+ VG_USERREQ__COUNT_ERRORS = 0x1201,
+
+ /* Allows the client program and/or gdbserver to execute a monitor
+ command. */
+ VG_USERREQ__GDB_MONITOR_COMMAND = 0x1202,
+
+ /* Allows the client program to change a dynamic command line
+ option. */
+ VG_USERREQ__CLO_CHANGE = 0x1203,
+
+ /* These are useful and can be interpreted by any tool that
+ tracks malloc() et al, by using vg_replace_malloc.c. */
+ VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
+ VG_USERREQ__RESIZEINPLACE_BLOCK = 0x130b,
+ VG_USERREQ__FREELIKE_BLOCK = 0x1302,
+ /* Memory pool support. */
+ VG_USERREQ__CREATE_MEMPOOL = 0x1303,
+ VG_USERREQ__DESTROY_MEMPOOL = 0x1304,
+ VG_USERREQ__MEMPOOL_ALLOC = 0x1305,
+ VG_USERREQ__MEMPOOL_FREE = 0x1306,
+ VG_USERREQ__MEMPOOL_TRIM = 0x1307,
+ VG_USERREQ__MOVE_MEMPOOL = 0x1308,
+ VG_USERREQ__MEMPOOL_CHANGE = 0x1309,
+ VG_USERREQ__MEMPOOL_EXISTS = 0x130a,
+
+ /* Allow printfs to valgrind log. */
+ /* The first two pass the va_list argument by value, which
+ assumes it is the same size as or smaller than a UWord,
+ which generally isn't the case. Hence are deprecated.
+ The second two pass the vargs by reference and so are
+ immune to this problem. */
+ /* both :: char* fmt, va_list vargs (DEPRECATED) */
+ VG_USERREQ__PRINTF = 0x1401,
+ VG_USERREQ__PRINTF_BACKTRACE = 0x1402,
+ /* both :: char* fmt, va_list* vargs */
+ VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403,
+ VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404,
+
+ /* Stack support. */
+ VG_USERREQ__STACK_REGISTER = 0x1501,
+ VG_USERREQ__STACK_DEREGISTER = 0x1502,
+ VG_USERREQ__STACK_CHANGE = 0x1503,
+
+ /* Wine support */
+ VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
+
+ /* Querying of debug info. */
+ VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701,
+
+ /* Disable/enable error reporting level. Takes a single
+ Word arg which is the delta to this thread's error
+ disablement indicator. Hence 1 disables or further
+ disables errors, and -1 moves back towards enablement.
+ Other values are not allowed. */
+ VG_USERREQ__CHANGE_ERR_DISABLEMENT = 0x1801,
+
+ /* Some requests used for Valgrind internal, such as
+ self-test or self-hosting. */
+ /* Initialise IR injection */
+ VG_USERREQ__VEX_INIT_FOR_IRI = 0x1901,
+ /* Used by Inner Valgrind to inform Outer Valgrind where to
+ find the list of inner guest threads */
+ VG_USERREQ__INNER_THREADS = 0x1902
+ } Vg_ClientRequest;
+
+#if !defined(__GNUC__)
+# define __extension__ /* */
+#endif
+
+
+/* Returns the number of Valgrinds this code is running under. That
+ is, 0 if running natively, 1 if running under Valgrind, 2 if
+ running under Valgrind which is running under another Valgrind,
+ etc. */
+#define RUNNING_ON_VALGRIND \
+ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */, \
+ VG_USERREQ__RUNNING_ON_VALGRIND, \
+ 0, 0, 0, 0, 0) \
+
+
+/* Discard translation of code in the range [_qzz_addr .. _qzz_addr +
+ _qzz_len - 1]. Useful if you are debugging a JITter or some such,
+ since it provides a way to make sure valgrind will retranslate the
+ invalidated area. Returns no value. */
+#define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DISCARD_TRANSLATIONS, \
+ _qzz_addr, _qzz_len, 0, 0, 0)
+
+#define VALGRIND_INNER_THREADS(_qzz_addr) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__INNER_THREADS, \
+ _qzz_addr, 0, 0, 0, 0)
+
+
+/* These requests are for getting Valgrind itself to print something.
+ Possibly with a backtrace. This is a really ugly hack. The return value
+ is the number of characters printed, excluding the "**<pid>** " part at the
+ start and the backtrace (if present). */
+
+#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
+/* Modern GCC will optimize the static routine out if unused,
+ and unused attribute will shut down warnings about it. */
+static int VALGRIND_PRINTF(const char *format, ...)
+ __attribute__((format(__printf__, 1, 2), __unused__));
+#endif
+static int
+#if defined(_MSC_VER)
+__inline
+#endif
+VALGRIND_PRINTF(const char *format, ...)
+{
+#if defined(NVALGRIND)
+ (void)format;
+ return 0;
+#else /* NVALGRIND */
+#if defined(_MSC_VER) || defined(__MINGW64__)
+ uintptr_t _qzz_res;
+#else
+ unsigned long _qzz_res;
+#endif
+ va_list vargs;
+ va_start(vargs, format);
+#if defined(_MSC_VER) || defined(__MINGW64__)
+ _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
+ VG_USERREQ__PRINTF_VALIST_BY_REF,
+ (uintptr_t)format,
+ (uintptr_t)&vargs,
+ 0, 0, 0);
+#else
+ _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
+ VG_USERREQ__PRINTF_VALIST_BY_REF,
+ (unsigned long)format,
+ (unsigned long)&vargs,
+ 0, 0, 0);
+#endif
+ va_end(vargs);
+ return (int)_qzz_res;
+#endif /* NVALGRIND */
+}
+
+#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
+static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
+ __attribute__((format(__printf__, 1, 2), __unused__));
+#endif
+static int
+#if defined(_MSC_VER)
+__inline
+#endif
+VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
+{
+#if defined(NVALGRIND)
+ (void)format;
+ return 0;
+#else /* NVALGRIND */
+#if defined(_MSC_VER) || defined(__MINGW64__)
+ uintptr_t _qzz_res;
+#else
+ unsigned long _qzz_res;
+#endif
+ va_list vargs;
+ va_start(vargs, format);
+#if defined(_MSC_VER) || defined(__MINGW64__)
+ _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
+ VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
+ (uintptr_t)format,
+ (uintptr_t)&vargs,
+ 0, 0, 0);
+#else
+ _qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
+ VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
+ (unsigned long)format,
+ (unsigned long)&vargs,
+ 0, 0, 0);
+#endif
+ va_end(vargs);
+ return (int)_qzz_res;
+#endif /* NVALGRIND */
+}
+
+
+/* These requests allow control to move from the simulated CPU to the
+ real CPU, calling an arbitrary function.
+
+ Note that the current ThreadId is inserted as the first argument.
+ So this call:
+
+ VALGRIND_NON_SIMD_CALL2(f, arg1, arg2)
+
+ requires f to have this signature:
+
+ Word f(Word tid, Word arg1, Word arg2)
+
+ where "Word" is a word-sized type.
+
+ Note that these client requests are not entirely reliable. For example,
+ if you call a function with them that subsequently calls printf(),
+ there's a high chance Valgrind will crash. Generally, your prospects of
+ these working are made higher if the called function does not refer to
+ any global variables, and does not refer to any libc or other functions
+ (printf et al). Any kind of entanglement with libc or dynamic linking is
+ likely to have a bad outcome, for tricky reasons which we've grappled
+ with a lot in the past.
+*/
+#define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \
+ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
+ VG_USERREQ__CLIENT_CALL0, \
+ _qyy_fn, \
+ 0, 0, 0, 0)
+
+#define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \
+ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
+ VG_USERREQ__CLIENT_CALL1, \
+ _qyy_fn, \
+ _qyy_arg1, 0, 0, 0)
+
+#define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \
+ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
+ VG_USERREQ__CLIENT_CALL2, \
+ _qyy_fn, \
+ _qyy_arg1, _qyy_arg2, 0, 0)
+
+#define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \
+ VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
+ VG_USERREQ__CLIENT_CALL3, \
+ _qyy_fn, \
+ _qyy_arg1, _qyy_arg2, \
+ _qyy_arg3, 0)
+
+
+/* Counts the number of errors that have been recorded by a tool. Nb:
+ the tool must record the errors with VG_(maybe_record_error)() or
+ VG_(unique_error)() for them to be counted. */
+#define VALGRIND_COUNT_ERRORS \
+ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR( \
+ 0 /* default return */, \
+ VG_USERREQ__COUNT_ERRORS, \
+ 0, 0, 0, 0, 0)
+
+/* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing
+ when heap blocks are allocated in order to give accurate results. This
+ happens automatically for the standard allocator functions such as
+ malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete,
+ delete[], etc.
+
+ But if your program uses a custom allocator, this doesn't automatically
+ happen, and Valgrind will not do as well. For example, if you allocate
+ superblocks with mmap() and then allocates chunks of the superblocks, all
+ Valgrind's observations will be at the mmap() level and it won't know that
+ the chunks should be considered separate entities. In Memcheck's case,
+ that means you probably won't get heap block overrun detection (because
+ there won't be redzones marked as unaddressable) and you definitely won't
+ get any leak detection.
+
+ The following client requests allow a custom allocator to be annotated so
+ that it can be handled accurately by Valgrind.
+
+ VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated
+ by a malloc()-like function. For Memcheck (an illustrative case), this
+ does two things:
+
+ - It records that the block has been allocated. This means any addresses
+ within the block mentioned in error messages will be
+ identified as belonging to the block. It also means that if the block
+ isn't freed it will be detected by the leak checker.
+
+ - It marks the block as being addressable and undefined (if 'is_zeroed' is
+ not set), or addressable and defined (if 'is_zeroed' is set). This
+ controls how accesses to the block by the program are handled.
+
+ 'addr' is the start of the usable block (ie. after any
+ redzone), 'sizeB' is its size. 'rzB' is the redzone size if the allocator
+ can apply redzones -- these are blocks of padding at the start and end of
+ each block. Adding redzones is recommended as it makes it much more likely
+ Valgrind will spot block overruns. `is_zeroed' indicates if the memory is
+ zeroed (or filled with another predictable value), as is the case for
+ calloc().
+
+ VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
+ heap block -- that will be used by the client program -- is allocated.
+ It's best to put it at the outermost level of the allocator if possible;
+ for example, if you have a function my_alloc() which calls
+ internal_alloc(), and the client request is put inside internal_alloc(),
+ stack traces relating to the heap block will contain entries for both
+ my_alloc() and internal_alloc(), which is probably not what you want.
+
+ For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
+ custom blocks from within a heap block, B, that has been allocated with
+ malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
+ -- the custom blocks will take precedence.
+
+ VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For
+ Memcheck, it does two things:
+
+ - It records that the block has been deallocated. This assumes that the
+ block was annotated as having been allocated via
+ VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
+
+ - It marks the block as being unaddressable.
+
+ VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
+ heap block is deallocated.
+
+ VALGRIND_RESIZEINPLACE_BLOCK informs a tool about reallocation. For
+ Memcheck, it does four things:
+
+ - It records that the size of a block has been changed. This assumes that
+ the block was annotated as having been allocated via
+ VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
+
+ - If the block shrunk, it marks the freed memory as being unaddressable.
+
+ - If the block grew, it marks the new area as undefined and defines a red
+ zone past the end of the new block.
+
+ - The V-bits of the overlap between the old and the new block are preserved.
+
+ VALGRIND_RESIZEINPLACE_BLOCK should be put after allocation of the new block
+ and before deallocation of the old block.
+
+ In many cases, these three client requests will not be enough to get your
+ allocator working well with Memcheck. More specifically, if your allocator
+ writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call
+ will be necessary to mark the memory as addressable just before the zeroing
+ occurs, otherwise you'll get a lot of invalid write errors. For example,
+ you'll need to do this if your allocator recycles freed blocks, but it
+ zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK).
+ Alternatively, if your allocator reuses freed blocks for allocator-internal
+ data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary.
+
+ Really, what's happening is a blurring of the lines between the client
+ program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the
+ memory should be considered unaddressable to the client program, but the
+ allocator knows more than the rest of the client program and so may be able
+ to safely access it. Extra client requests are necessary for Valgrind to
+ understand the distinction between the allocator and the rest of the
+ program.
+
+ Ignored if addr == 0.
+*/
+#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK, \
+ addr, sizeB, rzB, is_zeroed, 0)
+
+/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
+ Ignored if addr == 0.
+*/
+#define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__RESIZEINPLACE_BLOCK, \
+ addr, oldSizeB, newSizeB, rzB, 0)
+
+/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
+ Ignored if addr == 0.
+*/
+#define VALGRIND_FREELIKE_BLOCK(addr, rzB) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__FREELIKE_BLOCK, \
+ addr, rzB, 0, 0, 0)
+
+/* Create a memory pool. */
+#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
+ pool, rzB, is_zeroed, 0, 0)
+
+/* Create a memory pool with some flags specifying extended behaviour.
+ When flags is zero, the behaviour is identical to VALGRIND_CREATE_MEMPOOL.
+
+ The flag VALGRIND_MEMPOOL_METAPOOL specifies that the pieces of memory
+ associated with the pool using VALGRIND_MEMPOOL_ALLOC will be used
+ by the application as superblocks to dole out MALLOC_LIKE blocks using
+ VALGRIND_MALLOCLIKE_BLOCK. In other words, a meta pool is a "2 levels"
+ pool : first level is the blocks described by VALGRIND_MEMPOOL_ALLOC.
+ The second level blocks are described using VALGRIND_MALLOCLIKE_BLOCK.
+ Note that the association between the pool and the second level blocks
+ is implicit : second level blocks will be located inside first level
+ blocks. It is necessary to use the VALGRIND_MEMPOOL_METAPOOL flag
+ for such 2 levels pools, as otherwise valgrind will detect overlapping
+ memory blocks, and will abort execution (e.g. during leak search).
+
+ Such a meta pool can also be marked as an 'auto free' pool using the flag
+ VALGRIND_MEMPOOL_AUTO_FREE, which must be OR-ed together with the
+ VALGRIND_MEMPOOL_METAPOOL. For an 'auto free' pool, VALGRIND_MEMPOOL_FREE
+ will automatically free the second level blocks that are contained
+ inside the first level block freed with VALGRIND_MEMPOOL_FREE.
+ In other words, calling VALGRIND_MEMPOOL_FREE will cause implicit calls
+ to VALGRIND_FREELIKE_BLOCK for all the second level blocks included
+ in the first level block.
+ Note: it is an error to use the VALGRIND_MEMPOOL_AUTO_FREE flag
+ without the VALGRIND_MEMPOOL_METAPOOL flag.
+*/
+#define VALGRIND_MEMPOOL_AUTO_FREE 1
+#define VALGRIND_MEMPOOL_METAPOOL 2
+#define VALGRIND_CREATE_MEMPOOL_EXT(pool, rzB, is_zeroed, flags) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
+ pool, rzB, is_zeroed, flags, 0)
+
+/* Destroy a memory pool. */
+#define VALGRIND_DESTROY_MEMPOOL(pool) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \
+ pool, 0, 0, 0, 0)
+
+/* Associate a piece of memory with a memory pool. */
+#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_ALLOC, \
+ pool, addr, size, 0, 0)
+
+/* Disassociate a piece of memory from a memory pool. */
+#define VALGRIND_MEMPOOL_FREE(pool, addr) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_FREE, \
+ pool, addr, 0, 0, 0)
+
+/* Disassociate any pieces outside a particular range. */
+#define VALGRIND_MEMPOOL_TRIM(pool, addr, size) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_TRIM, \
+ pool, addr, size, 0, 0)
+
+/* Resize and/or move a piece associated with a memory pool. */
+#define VALGRIND_MOVE_MEMPOOL(poolA, poolB) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MOVE_MEMPOOL, \
+ poolA, poolB, 0, 0, 0)
+
+/* Resize and/or move a piece associated with a memory pool. */
+#define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_CHANGE, \
+ pool, addrA, addrB, size, 0)
+
+/* Return 1 if a mempool exists, else 0. */
+#define VALGRIND_MEMPOOL_EXISTS(pool) \
+ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
+ VG_USERREQ__MEMPOOL_EXISTS, \
+ pool, 0, 0, 0, 0)
+
+/* Mark a piece of memory as being a stack. Returns a stack id.
+ start is the lowest addressable stack byte, end is the highest
+ addressable stack byte. */
+#define VALGRIND_STACK_REGISTER(start, end) \
+ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
+ VG_USERREQ__STACK_REGISTER, \
+ start, end, 0, 0, 0)
+
+/* Unmark the piece of memory associated with a stack id as being a
+ stack. */
+#define VALGRIND_STACK_DEREGISTER(id) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_DEREGISTER, \
+ id, 0, 0, 0, 0)
+
+/* Change the start and end address of the stack id.
+ start is the new lowest addressable stack byte, end is the new highest
+ addressable stack byte. */
+#define VALGRIND_STACK_CHANGE(id, start, end) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_CHANGE, \
+ id, start, end, 0, 0)
+
+/* Load PDB debug info for Wine PE image_map. */
+#define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LOAD_PDB_DEBUGINFO, \
+ fd, ptr, total_size, delta, 0)
+
+/* Map a code address to a source file name and line number. buf64
+ must point to a 64-byte buffer in the caller's address space. The
+ result will be dumped in there and is guaranteed to be zero
+ terminated. If no info is found, the first byte is set to zero. */
+#define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64) \
+ (unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
+ VG_USERREQ__MAP_IP_TO_SRCLOC, \
+ addr, buf64, 0, 0, 0)
+
+/* Disable error reporting for this thread. Behaves in a stack like
+ way, so you can safely call this multiple times provided that
+ VALGRIND_ENABLE_ERROR_REPORTING is called the same number of times
+ to re-enable reporting. The first call of this macro disables
+ reporting. Subsequent calls have no effect except to increase the
+ number of VALGRIND_ENABLE_ERROR_REPORTING calls needed to re-enable
+ reporting. Child threads do not inherit this setting from their
+ parents -- they are always created with reporting enabled. */
+#define VALGRIND_DISABLE_ERROR_REPORTING \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
+ 1, 0, 0, 0, 0)
+
+/* Re-enable error reporting, as per comments on
+ VALGRIND_DISABLE_ERROR_REPORTING. */
+#define VALGRIND_ENABLE_ERROR_REPORTING \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
+ -1, 0, 0, 0, 0)
+
+/* Execute a monitor command from the client program.
+ If a connection is opened with GDB, the output will be sent
+ according to the output mode set for vgdb.
+ If no connection is opened, output will go to the log output.
+ Returns 1 if command not recognised, 0 otherwise. */
+#define VALGRIND_MONITOR_COMMAND(command) \
+ VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__GDB_MONITOR_COMMAND, \
+ command, 0, 0, 0, 0)
+
+
+/* Change the value of a dynamic command line option.
+ Note that unknown or not dynamically changeable options
+ will cause a warning message to be output. */
+#define VALGRIND_CLO_CHANGE(option) \
+ VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CLO_CHANGE, \
+ option, 0, 0, 0, 0)
+
+
+#undef PLAT_x86_darwin
+#undef PLAT_amd64_darwin
+#undef PLAT_x86_win32
+#undef PLAT_amd64_win64
+#undef PLAT_x86_linux
+#undef PLAT_amd64_linux
+#undef PLAT_ppc32_linux
+#undef PLAT_ppc64be_linux
+#undef PLAT_ppc64le_linux
+#undef PLAT_arm_linux
+#undef PLAT_s390x_linux
+#undef PLAT_mips32_linux
+#undef PLAT_mips64_linux
+#undef PLAT_nanomips_linux
+#undef PLAT_x86_solaris
+#undef PLAT_amd64_solaris
+
+#endif /* __VALGRIND_H */
diff --git a/src/util/.gitignore b/src/util/.gitignore
index c5f8c76dd..d79786ec7 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -9,3 +9,4 @@ test_helper_cs
test_helper_cs_home/
test_helper_eddsa
test_helper_eddsa_home/
+test_conversion
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 94edac021..d2504588b 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -10,6 +10,7 @@ endif
pkgcfgdir = $(prefix)/share/taler/config.d/
pkgcfg_DATA = \
+ currencies.conf \
paths.conf \
taler-exchange-secmod-eddsa.conf \
taler-exchange-secmod-rsa.conf \
@@ -20,7 +21,8 @@ EXTRA_DIST = \
taler-config.in \
test_helper_eddsa.conf \
test_helper_rsa.conf \
- test_helper_cs.conf
+ test_helper_cs.conf \
+ test_conversion.sh
bin_PROGRAMS = \
taler-exchange-secmod-eddsa \
@@ -77,9 +79,12 @@ lib_LTLIBRARIES = \
libtalerutil_la_SOURCES = \
age_restriction.c \
amount.c \
+ aml_signatures.c \
auditor_signatures.c \
config.c \
+ conversion.c \
crypto.c \
+ crypto_confirmation.c \
crypto_contract.c \
crypto_helper_common.c crypto_helper_common.h \
crypto_helper_rsa.c \
@@ -105,15 +110,17 @@ libtalerutil_la_SOURCES = \
libtalerutil_la_LIBADD = \
-lgnunetutil \
+ -lgnunetjson \
-lsodium \
-ljansson \
$(LIBGCRYPT_LIBS) \
-lmicrohttpd $(XLIB) \
+ -lunistring \
-lz \
-lm
libtalerutil_la_LDFLAGS = \
- -version-info 0:0:0 \
+ -version-info 3:3:2 \
-no-undefined
@@ -122,6 +129,7 @@ AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=
check_PROGRAMS = \
test_age_restriction \
test_amount \
+ test_conversion \
test_crypto \
test_helper_eddsa \
test_helper_rsa \
@@ -138,6 +146,14 @@ test_age_restriction_LDADD = \
-lgnunetutil \
libtalerutil.la
+test_conversion_SOURCES = \
+ test_conversion.c
+test_conversion_LDADD = \
+ -lgnunetjson \
+ -lgnunetutil \
+ -ljansson \
+ libtalerutil.la
+
test_amount_SOURCES = \
test_amount.c
test_amount_LDADD = \
diff --git a/src/util/age_restriction.c b/src/util/age_restriction.c
index 189ec4e8c..c2a7fc07c 100644
--- a/src/util/age_restriction.c
+++ b/src/util/age_restriction.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2022 Taler Systems SA
+ Copyright (C) 2022-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,7 +21,22 @@
#include "platform.h"
#include "taler_util.h"
#include "taler_signatures.h"
+#include <gnunet/gnunet_json_lib.h>
#include <gcrypt.h>
+#include <stdint.h>
+
+struct
+#ifndef AGE_RESTRICTION_WITH_ECDSA
+GNUNET_CRYPTO_Edx25519PublicKey
+#else
+GNUNET_CRYPTO_EcdsaPublicKey
+#endif
+TALER_age_commitment_base_public_key = {
+ .q_y = { 0x64, 0x41, 0xb9, 0xbd, 0xbf, 0x14, 0x39, 0x8e,
+ 0x46, 0xeb, 0x5c, 0x1d, 0x34, 0xd3, 0x9b, 0x2f,
+ 0x9b, 0x7d, 0xc8, 0x18, 0xeb, 0x9c, 0x09, 0xfb,
+ 0x43, 0xad, 0x16, 0x64, 0xbc, 0x18, 0x49, 0xb5},
+};
void
TALER_age_commitment_hash (
@@ -39,7 +54,7 @@ TALER_age_commitment_hash (
}
GNUNET_assert (__builtin_popcount (commitment->mask.bits) - 1 ==
- commitment->num);
+ (int) commitment->num);
hash_context = GNUNET_CRYPTO_hash_context_start ();
@@ -62,7 +77,7 @@ TALER_age_commitment_hash (
* defined by the given mask.
*/
uint8_t
-get_age_group (
+TALER_get_age_group (
const struct TALER_AgeMask *mask,
uint8_t age)
{
@@ -81,36 +96,97 @@ get_age_group (
}
-enum GNUNET_GenericReturnValue
+uint8_t
+TALER_get_lowest_age (
+ const struct TALER_AgeMask *mask,
+ uint8_t age)
+{
+ uint32_t m = mask->bits;
+ uint8_t group = TALER_get_age_group (mask, age);
+ uint8_t lowest = 0;
+
+ while (group > 0)
+ {
+ m = m >> 1;
+ if (m & 1)
+ group--;
+ lowest++;
+ }
+
+ return lowest;
+}
+
+
+#ifdef AGE_RESTRICTION_WITH_ECDSA
+/**
+ * @brief Helper function to generate a ECDSA private key
+ *
+ * @param seed Input seed
+ * @param size Size of the seed in bytes
+ * @param[out] pkey ECDSA private key
+ */
+static void
+ecdsa_create_from_seed (
+ const void *seed,
+ size_t seed_size,
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *key)
+{
+ enum GNUNET_GenericReturnValue ret;
+
+ GNUNET_assert (
+ GNUNET_OK ==
+ GNUNET_CRYPTO_kdf (key,
+ sizeof (*key),
+ &seed,
+ seed_size,
+ "age commitment",
+ sizeof ("age commitment") - 1,
+ NULL, 0));
+ /* See GNUNET_CRYPTO_ecdsa_key_create */
+ key->d[0] &= 248;
+ key->d[31] &= 127;
+ key->d[31] |= 64;
+}
+
+
+#endif
+
+
+void
TALER_age_restriction_commit (
const struct TALER_AgeMask *mask,
- const uint8_t age,
+ uint8_t age,
const struct GNUNET_HashCode *seed,
- struct TALER_AgeCommitmentProof *new)
+ struct TALER_AgeCommitmentProof *ncp)
{
struct GNUNET_HashCode seed_i;
- uint8_t num_pub = __builtin_popcount (mask->bits) - 1;
- uint8_t num_priv = get_age_group (mask, age);
+ uint8_t num_pub;
+ uint8_t num_priv;
size_t i;
+ GNUNET_assert (NULL != mask);
GNUNET_assert (NULL != seed);
- GNUNET_assert (NULL != new);
- GNUNET_assert (mask->bits & 1); /* fist bit must have been set */
+ GNUNET_assert (NULL != ncp);
+ GNUNET_assert (mask->bits & 1); /* first bit must have been set */
+
+ num_pub = __builtin_popcount (mask->bits) - 1;
+ num_priv = TALER_get_age_group (mask, age);
+
GNUNET_assert (31 > num_priv);
GNUNET_assert (num_priv <= num_pub);
seed_i = *seed;
- new->commitment.mask.bits = mask->bits;
- new->commitment.num = num_pub;
- new->proof.num = num_priv;
- new->proof.keys = NULL;
+ ncp->commitment.mask.bits = mask->bits;
+ ncp->commitment.num = num_pub;
+ ncp->proof.num = num_priv;
+ ncp->proof.keys = NULL;
- new->commitment.keys = GNUNET_new_array (
+ ncp->commitment.keys = GNUNET_new_array (
num_pub,
struct TALER_AgeCommitmentPublicKeyP);
if (0 < num_priv)
- new->proof.keys = GNUNET_new_array (
+ ncp->proof.keys = GNUNET_new_array (
num_priv,
struct TALER_AgeCommitmentPrivateKeyP);
@@ -125,47 +201,24 @@ TALER_age_restriction_commit (
/* Only save the private keys for age groups less than num_priv */
if (i < num_priv)
- pkey = &new->proof.keys[i];
+ pkey = &ncp->proof.keys[i];
#ifndef AGE_RESTRICTION_WITH_ECDSA
GNUNET_CRYPTO_edx25519_key_create_from_seed (&seed_i,
sizeof(seed_i),
&pkey->priv);
GNUNET_CRYPTO_edx25519_key_get_public (&pkey->priv,
- &new->commitment.keys[i].pub);
- seed_i.bits[0] += 1;
- }
-
- return GNUNET_OK;
+ &ncp->commitment.keys[i].pub);
#else
- if (GNUNET_OK !=
- GNUNET_CRYPTO_kdf (pkey,
- sizeof (*pkey),
- &salti,
- sizeof (salti),
- "age commitment",
- strlen ("age commitment"),
- NULL, 0))
- goto FAIL;
-
- /* See GNUNET_CRYPTO_ecdsa_key_create */
- pkey->priv.d[0] &= 248;
- pkey->priv.d[31] &= 127;
- pkey->priv.d[31] |= 64;
-
+ ecdsa_create_from_seed (&seed_i,
+ sizeof(seed_i),
+ &pkey->priv);
GNUNET_CRYPTO_ecdsa_key_get_public (&pkey->priv,
- &new->commitment.keys[i].pub);
+ &ncp->commitment.keys[i].pub);
+#endif
+ seed_i.bits[0] += 1;
}
-
- return GNUNET_OK;
-
-FAIL:
- GNUNET_free (new->commitment.keys);
- if (NULL != new->proof.keys)
- GNUNET_free (new->proof.keys);
- return GNUNET_SYSERR;
-#endif
}
@@ -178,7 +231,7 @@ TALER_age_commitment_derive (
GNUNET_assert (NULL != newacp);
GNUNET_assert (orig->proof.num <=
orig->commitment.num);
- GNUNET_assert (orig->commitment.num ==
+ GNUNET_assert (((int) orig->commitment.num) ==
__builtin_popcount (orig->commitment.mask.bits) - 1);
newacp->commitment.mask = orig->commitment.mask;
@@ -215,33 +268,30 @@ TALER_age_commitment_derive (
&newacp->proof.keys[i].priv);
}
#else
- char label[sizeof(uint64_t) + 1] = {0};
-
- /* Because GNUNET_CRYPTO_ecdsa_public_key_derive expects char * (and calls
- * strlen on it), we must avoid 0's in the label. */
- uint64_t nz_salt = salt | 0x8040201008040201;
- memcpy (label, &nz_salt, sizeof(nz_salt));
-
- /* 1. Derive the public keys */
- for (size_t i = 0; i < orig->commitment.num; i++)
- {
- GNUNET_CRYPTO_ecdsa_public_key_derive (
- &orig->commitment.keys[i].pub,
- label,
- "age commitment derive",
- &newacp->commitment.keys[i].pub);
- }
-
- /* 2. Derive the private keys */
- for (size_t i = 0; i < orig->proof.num; i++)
{
- struct GNUNET_CRYPTO_EcdsaPrivateKey *priv;
- priv = GNUNET_CRYPTO_ecdsa_private_key_derive (
- &orig->proof.keys[i].priv,
- label,
- "age commitment derive");
- newacp->proof.keys[i].priv = *priv;
- GNUNET_free (priv);
+ const char *label = GNUNET_h2s (salt);
+
+ /* 1. Derive the public keys */
+ for (size_t i = 0; i < orig->commitment.num; i++)
+ {
+ GNUNET_CRYPTO_ecdsa_public_key_derive (
+ &orig->commitment.keys[i].pub,
+ label,
+ "age commitment derive",
+ &newacp->commitment.keys[i].pub);
+ }
+
+ /* 2. Derive the private keys */
+ for (size_t i = 0; i < orig->proof.num; i++)
+ {
+ struct GNUNET_CRYPTO_EcdsaPrivateKey *priv;
+ priv = GNUNET_CRYPTO_ecdsa_private_key_derive (
+ &orig->proof.keys[i].priv,
+ label,
+ "age commitment derive");
+ newacp->proof.keys[i].priv = *priv;
+ GNUNET_free (priv);
+ }
}
#endif
@@ -296,8 +346,8 @@ TALER_age_commitment_attest (
GNUNET_assert (NULL != attest);
GNUNET_assert (NULL != cp);
- group = get_age_group (&cp->commitment.mask,
- age);
+ group = TALER_get_age_group (&cp->commitment.mask,
+ age);
GNUNET_assert (group < 32);
@@ -331,6 +381,7 @@ TALER_age_commitment_attest (
&at,
&attest->signature);
}
+#undef sign
return GNUNET_OK;
}
@@ -347,8 +398,8 @@ TALER_age_commitment_verify (
GNUNET_assert (NULL != attest);
GNUNET_assert (NULL != comm);
- group = get_age_group (&comm->mask,
- age);
+ group = TALER_get_age_group (&comm->mask,
+ age);
GNUNET_assert (group < 32);
@@ -380,6 +431,7 @@ TALER_age_commitment_verify (
&attest->signature,
&comm->keys[group - 1].pub);
}
+#undef verify
}
@@ -403,6 +455,9 @@ void
TALER_age_proof_free (
struct TALER_AgeProof *proof)
{
+ if (NULL == proof)
+ return;
+
if (NULL != proof->keys)
{
GNUNET_CRYPTO_zero_keys (
@@ -418,21 +473,323 @@ TALER_age_proof_free (
void
TALER_age_commitment_proof_free (
- struct TALER_AgeCommitmentProof *cp)
+ struct TALER_AgeCommitmentProof *acp)
{
- if (NULL != cp->proof.keys)
+ if (NULL == acp)
+ return;
+
+ if (NULL != acp->proof.keys)
{
GNUNET_CRYPTO_zero_keys (
- cp->proof.keys,
- sizeof(*cp->proof.keys) * cp->proof.num);
+ acp->proof.keys,
+ sizeof(*acp->proof.keys) * acp->proof.num);
- GNUNET_free (cp->proof.keys);
- cp->proof.keys = NULL;
+ GNUNET_free (acp->proof.keys);
+ acp->proof.keys = NULL;
}
- if (NULL != cp->commitment.keys)
+ if (NULL != acp->commitment.keys)
{
- GNUNET_free (cp->commitment.keys);
- cp->commitment.keys = NULL;
+ GNUNET_free (acp->commitment.keys);
+ acp->commitment.keys = NULL;
}
}
+
+
+struct TALER_AgeCommitmentProof *
+TALER_age_commitment_proof_duplicate (
+ const struct TALER_AgeCommitmentProof *acp)
+{
+ struct TALER_AgeCommitmentProof *nacp;
+
+ GNUNET_assert (NULL != acp);
+ GNUNET_assert (__builtin_popcount (acp->commitment.mask.bits) - 1 ==
+ (int) acp->commitment.num);
+
+ nacp = GNUNET_new (struct TALER_AgeCommitmentProof);
+
+ TALER_age_commitment_proof_deep_copy (acp,nacp);
+ return nacp;
+}
+
+
+void
+TALER_age_commitment_proof_deep_copy (
+ const struct TALER_AgeCommitmentProof *acp,
+ struct TALER_AgeCommitmentProof *nacp)
+{
+ GNUNET_assert (NULL != acp);
+ GNUNET_assert (__builtin_popcount (acp->commitment.mask.bits) - 1 ==
+ (int) acp->commitment.num);
+
+ *nacp = *acp;
+ nacp->commitment.keys =
+ GNUNET_new_array (acp->commitment.num,
+ struct TALER_AgeCommitmentPublicKeyP);
+ nacp->proof.keys =
+ GNUNET_new_array (acp->proof.num,
+ struct TALER_AgeCommitmentPrivateKeyP);
+
+ for (size_t i = 0; i < acp->commitment.num; i++)
+ nacp->commitment.keys[i] = acp->commitment.keys[i];
+
+ for (size_t i = 0; i < acp->proof.num; i++)
+ nacp->proof.keys[i] = acp->proof.keys[i];
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_JSON_parse_age_groups (const json_t *root,
+ struct TALER_AgeMask *mask)
+{
+ enum GNUNET_GenericReturnValue ret;
+ const char *str;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_string ("age_groups",
+ &str),
+ GNUNET_JSON_spec_end ()
+ };
+
+ ret = GNUNET_JSON_parse (root,
+ spec,
+ NULL,
+ NULL);
+ if (GNUNET_OK == ret)
+ TALER_parse_age_group_string (str, mask);
+
+ GNUNET_JSON_parse_free (spec);
+
+ return ret;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_parse_age_group_string (
+ const char *groups,
+ struct TALER_AgeMask *mask)
+{
+
+ const char *pos = groups;
+ unsigned int prev = 0;
+ unsigned int val = 0;
+ char c;
+
+ /* reset mask */
+ mask->bits = 0;
+
+ while (*pos)
+ {
+ c = *pos++;
+ if (':' == c)
+ {
+ if (prev >= val)
+ return GNUNET_SYSERR;
+
+ mask->bits |= 1 << val;
+ prev = val;
+ val = 0;
+ continue;
+ }
+
+ if ('0'>c || '9'<c)
+ return GNUNET_SYSERR;
+
+ val = 10 * val + c - '0';
+
+ if (0>=val || 32<=val)
+ return GNUNET_SYSERR;
+ }
+
+ if (32<=val || prev>=val)
+ return GNUNET_SYSERR;
+
+ mask->bits |= (1 << val);
+ mask->bits |= 1; // mark zeroth group, too
+
+ return GNUNET_OK;
+}
+
+
+const char *
+TALER_age_mask_to_string (
+ const struct TALER_AgeMask *mask)
+{
+ static char buf[256] = {0};
+ uint32_t bits = mask->bits;
+ unsigned int n = 0;
+ char *pos = buf;
+
+ memset (buf, 0, sizeof(buf));
+
+ while (bits != 0)
+ {
+ bits >>= 1;
+ n++;
+ if (0 == (bits & 1))
+ {
+ continue;
+ }
+
+ if (n > 9)
+ {
+ *(pos++) = '0' + n / 10;
+ }
+ *(pos++) = '0' + n % 10;
+
+ if (0 != (bits >> 1))
+ {
+ *(pos++) = ':';
+ }
+ }
+ return buf;
+}
+
+
+void
+TALER_age_restriction_from_secret (
+ const struct TALER_PlanchetMasterSecretP *secret,
+ const struct TALER_AgeMask *mask,
+ const uint8_t max_age,
+ struct TALER_AgeCommitmentProof *ncp)
+{
+ struct GNUNET_HashCode seed_i = {0};
+ uint8_t num_pub;
+ uint8_t num_priv;
+
+ GNUNET_assert (NULL != mask);
+ GNUNET_assert (NULL != secret);
+ GNUNET_assert (NULL != ncp);
+ GNUNET_assert (mask->bits & 1); /* fist bit must have been set */
+
+ num_pub = __builtin_popcount (mask->bits) - 1;
+ num_priv = TALER_get_age_group (mask, max_age);
+
+ GNUNET_assert (31 > num_priv);
+ GNUNET_assert (num_priv <= num_pub);
+
+ ncp->commitment.mask.bits = mask->bits;
+ ncp->commitment.num = num_pub;
+ ncp->proof.num = num_priv;
+ ncp->proof.keys = NULL;
+ ncp->commitment.keys = GNUNET_new_array (
+ num_pub,
+ struct TALER_AgeCommitmentPublicKeyP);
+ if (0 < num_priv)
+ ncp->proof.keys = GNUNET_new_array (
+ num_priv,
+ struct TALER_AgeCommitmentPrivateKeyP);
+
+ /* Create as many private keys as allow with max_age and derive the
+ * corresponding public keys. The rest of the needed public keys are created
+ * by scalar multiplication with the TALER_age_commitment_base_public_key. */
+ for (size_t i = 0; i < num_pub; i++)
+ {
+ enum GNUNET_GenericReturnValue ret;
+ const char *label = i < num_priv ? "age-commitment" : "age-factor";
+
+ ret = GNUNET_CRYPTO_kdf (&seed_i, sizeof(seed_i),
+ secret, sizeof(*secret),
+ label, strlen (label),
+ &i, sizeof(i),
+ NULL, 0);
+ GNUNET_assert (GNUNET_OK == ret);
+
+ /* Only generate and save the private keys and public keys for age groups
+ * less than num_priv */
+ if (i < num_priv)
+ {
+ struct TALER_AgeCommitmentPrivateKeyP *pkey = &ncp->proof.keys[i];
+
+#ifndef AGE_RESTRICTION_WITH_ECDSA
+ GNUNET_CRYPTO_edx25519_key_create_from_seed (&seed_i,
+ sizeof(seed_i),
+ &pkey->priv);
+ GNUNET_CRYPTO_edx25519_key_get_public (&pkey->priv,
+ &ncp->commitment.keys[i].pub);
+#else
+ ecdsa_create_from_seed (&seed_i,
+ sizeof(seed_i),
+ &pkey->priv);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&pkey->priv,
+ &ncp->commitment.keys[i].pub);
+#endif
+ }
+ else
+ {
+ /* For all indices larger than num_priv, derive a public key from
+ * TALER_age_commitment_base_public_key by scalar multiplication */
+#ifndef AGE_RESTRICTION_WITH_ECDSA
+ GNUNET_CRYPTO_edx25519_public_key_derive (
+ &TALER_age_commitment_base_public_key,
+ &seed_i,
+ sizeof(seed_i),
+ &ncp->commitment.keys[i].pub);
+#else
+
+ GNUNET_CRYPTO_ecdsa_public_key_derive (
+ &TALER_age_commitment_base_public_key,
+ GNUNET_h2s (&seed_i),
+ "age withdraw",
+ &ncp->commitment.keys[i].pub);
+#endif
+ }
+ }
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_parse_coarse_date (
+ const char *in,
+ const struct TALER_AgeMask *mask,
+ uint32_t *out)
+{
+ struct tm date = {0};
+ struct tm limit = {0};
+ time_t seconds;
+
+ if (NULL == in)
+ {
+ /* FIXME[oec]: correct behaviour? */
+ *out = 0;
+ return GNUNET_OK;
+ }
+
+ GNUNET_assert (NULL !=mask);
+ GNUNET_assert (NULL !=out);
+
+ if (NULL == strptime (in, "%Y-%m-%d", &date))
+ {
+ if (NULL == strptime (in, "%Y-%m-00", &date))
+ if (NULL == strptime (in, "%Y-00-00", &date))
+ return GNUNET_SYSERR;
+ /* turns out that the day is off by one in the last two cases */
+ date.tm_mday += 1;
+ }
+
+ seconds = timegm (&date);
+ if (-1 == seconds)
+ return GNUNET_SYSERR;
+
+ /* calculate the limit date for the largest age group */
+ {
+ time_t l = time (NULL);
+ localtime_r (&l, &limit);
+ }
+ limit.tm_year -= TALER_adult_age (mask);
+ GNUNET_assert (-1 != timegm (&limit));
+
+ if ((limit.tm_year < date.tm_year)
+ || ((limit.tm_year == date.tm_year)
+ && (limit.tm_mon < date.tm_mon))
+ || ((limit.tm_year == date.tm_year)
+ && (limit.tm_mon == date.tm_mon)
+ && (limit.tm_mday < date.tm_mday)))
+ *out = seconds / 60 / 60 / 24;
+ else
+ *out = 0;
+
+ return GNUNET_OK;
+}
+
+
+/* end util/age_restriction.c */
diff --git a/src/util/aml_signatures.c b/src/util/aml_signatures.c
new file mode 100644
index 000000000..a61646c0d
--- /dev/null
+++ b/src/util/aml_signatures.c
@@ -0,0 +1,201 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file aml_signatures.c
+ * @brief Utility functions for AML officers
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_signatures.h"
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Format used to generate the signature on an AML decision.
+ */
+struct TALER_AmlDecisionPS
+{
+ /**
+ * Purpose must be #TALER_SIGNATURE_AML_DECISION.
+ * Used for an EdDSA signature with the `struct TALER_AmlOfficerPublicKeyP`.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Hash over the justification text.
+ */
+ struct GNUNET_HashCode h_justification GNUNET_PACKED;
+
+ /**
+ * Time when this decision was made.
+ */
+ struct GNUNET_TIME_TimestampNBO decision_time;
+
+ /**
+ * New threshold for triggering possibly a new AML process.
+ */
+ struct TALER_AmountNBO new_threshold;
+
+ /**
+ * Hash of the account identifier to which the decision applies.
+ */
+ struct TALER_PaytoHashP h_payto GNUNET_PACKED;
+
+ /**
+ * Hash over JSON array with KYC requirements that were imposed. All zeros
+ * for none.
+ */
+ struct GNUNET_HashCode h_kyc_requirements;
+
+ /**
+ * What is the new AML status?
+ */
+ uint32_t new_state GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+void
+TALER_officer_aml_decision_sign (
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ struct TALER_AmlOfficerSignatureP *officer_sig)
+{
+ struct TALER_AmlDecisionPS ad = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_AML_DECISION),
+ .purpose.size = htonl (sizeof (ad)),
+ .decision_time = GNUNET_TIME_timestamp_hton (decision_time),
+ .h_payto = *h_payto,
+ .new_state = htonl ((uint32_t) new_state)
+ };
+
+ GNUNET_CRYPTO_hash (justification,
+ strlen (justification),
+ &ad.h_justification);
+ TALER_amount_hton (&ad.new_threshold,
+ new_threshold);
+ if (NULL != kyc_requirements)
+ TALER_json_hash (kyc_requirements,
+ &ad.h_kyc_requirements);
+ GNUNET_CRYPTO_eddsa_sign (&officer_priv->eddsa_priv,
+ &ad,
+ &officer_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_officer_aml_decision_verify (
+ const char *justification,
+ struct GNUNET_TIME_Timestamp decision_time,
+ const struct TALER_Amount *new_threshold,
+ const struct TALER_PaytoHashP *h_payto,
+ enum TALER_AmlDecisionState new_state,
+ const json_t *kyc_requirements,
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const struct TALER_AmlOfficerSignatureP *officer_sig)
+{
+ struct TALER_AmlDecisionPS ad = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_AML_DECISION),
+ .purpose.size = htonl (sizeof (ad)),
+ .decision_time = GNUNET_TIME_timestamp_hton (decision_time),
+ .h_payto = *h_payto,
+ .new_state = htonl ((uint32_t) new_state)
+ };
+
+ GNUNET_CRYPTO_hash (justification,
+ strlen (justification),
+ &ad.h_justification);
+ TALER_amount_hton (&ad.new_threshold,
+ new_threshold);
+ if (NULL != kyc_requirements)
+ TALER_json_hash (kyc_requirements,
+ &ad.h_kyc_requirements);
+ return GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_AML_DECISION,
+ &ad,
+ &officer_sig->eddsa_signature,
+ &officer_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Format used to generate the signature on any AML query.
+ */
+struct TALER_AmlQueryPS
+{
+ /**
+ * Purpose must be #TALER_SIGNATURE_AML_QUERY.
+ * Used for an EdDSA signature with the `struct TALER_AmlOfficerPublicKeyP`.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_officer_aml_query_sign (
+ const struct TALER_AmlOfficerPrivateKeyP *officer_priv,
+ struct TALER_AmlOfficerSignatureP *officer_sig)
+{
+ struct TALER_AmlQueryPS aq = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_AML_QUERY),
+ .purpose.size = htonl (sizeof (aq))
+ };
+
+ GNUNET_CRYPTO_eddsa_sign (&officer_priv->eddsa_priv,
+ &aq,
+ &officer_sig->eddsa_signature);
+}
+
+
+/**
+ * Verify AML query authorization.
+ *
+ * @param officer_pub public key of AML officer
+ * @param officer_sig signature to verify
+ * @return #GNUNET_OK if the signature is valid
+ */
+enum GNUNET_GenericReturnValue
+TALER_officer_aml_query_verify (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const struct TALER_AmlOfficerSignatureP *officer_sig)
+{
+ struct TALER_AmlQueryPS aq = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_AML_QUERY),
+ .purpose.size = htonl (sizeof (aq))
+ };
+
+ return GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_AML_QUERY,
+ &aq,
+ &officer_sig->eddsa_signature,
+ &officer_pub->eddsa_pub);
+}
+
+
+/* end of aml_signatures.c */
diff --git a/src/util/amount.c b/src/util/amount.c
index 43116af85..cce84d73a 100644
--- a/src/util/amount.c
+++ b/src/util/amount.c
@@ -40,6 +40,31 @@ invalidate (struct TALER_Amount *a)
enum GNUNET_GenericReturnValue
+TALER_check_currency (const char *str)
+{
+ if (strlen (str) >= TALER_CURRENCY_LEN)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Currency code name `%s' is too long\n",
+ str);
+ return GNUNET_SYSERR;
+ }
+ /* validate str has only legal characters in it! */
+ for (unsigned int i = 0; '\0' != str[i]; i++)
+ {
+ if ( ('A' > str[i]) || ('Z' < str[i]) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Currency code name `%s' contains illegal characters (only A-Z allowed)\n",
+ str);
+ return GNUNET_SYSERR;
+ }
+ }
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
TALER_string_to_amount (const char *str,
struct TALER_Amount *amount)
{
@@ -62,6 +87,7 @@ TALER_string_to_amount (const char *str,
/* parse currency */
colon = strchr (str, (int) ':');
if ( (NULL == colon) ||
+ (colon == str) ||
((colon - str) >= TALER_CURRENCY_LEN) )
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -72,14 +98,15 @@ TALER_string_to_amount (const char *str,
}
GNUNET_assert (TALER_CURRENCY_LEN > (colon - str));
- memcpy (amount->currency,
- str,
- colon - str);
+ for (unsigned int i = 0; i<colon - str; i++)
+ amount->currency[i] = str[i];
/* 0-terminate *and* normalize buffer by setting everything to '\0' */
memset (&amount->currency [colon - str],
0,
TALER_CURRENCY_LEN - (colon - str));
-
+ if (GNUNET_OK !=
+ TALER_check_currency (amount->currency))
+ return GNUNET_SYSERR;
/* skip colon */
value = colon + 1;
if ('\0' == value[0])
@@ -193,9 +220,8 @@ TALER_amount_hton (struct TALER_AmountNBO *res,
TALER_amount_is_valid (d));
res->value = GNUNET_htonll (d->value);
res->fraction = htonl (d->fraction);
- memcpy (res->currency,
- d->currency,
- TALER_CURRENCY_LEN);
+ for (unsigned int i = 0; i<TALER_CURRENCY_LEN; i++)
+ res->currency[i] = d->currency[i];
}
@@ -205,9 +231,9 @@ TALER_amount_ntoh (struct TALER_Amount *res,
{
res->value = GNUNET_ntohll (dn->value);
res->fraction = ntohl (dn->fraction);
- memcpy (res->currency,
- dn->currency,
- TALER_CURRENCY_LEN);
+ GNUNET_memcpy (res->currency,
+ dn->currency,
+ TALER_CURRENCY_LEN);
GNUNET_assert (GNUNET_YES ==
TALER_amount_is_valid (res));
}
@@ -219,15 +245,15 @@ TALER_amount_set_zero (const char *cur,
{
size_t slen;
- slen = strlen (cur);
- if (slen >= TALER_CURRENCY_LEN)
+ if (GNUNET_OK !=
+ TALER_check_currency (cur))
return GNUNET_SYSERR;
+ slen = strlen (cur);
memset (amount,
0,
sizeof (struct TALER_Amount));
- memcpy (amount->currency,
- cur,
- slen);
+ for (unsigned int i = 0; i<slen; i++)
+ amount->currency[i] = cur[i];
return GNUNET_OK;
}
@@ -236,7 +262,10 @@ enum GNUNET_GenericReturnValue
TALER_amount_is_valid (const struct TALER_Amount *amount)
{
if (amount->value > TALER_AMOUNT_MAX_VALUE)
+ {
+ GNUNET_break (0);
return GNUNET_SYSERR;
+ }
return ('\0' != amount->currency[0]) ? GNUNET_OK : GNUNET_NO;
}
@@ -553,8 +582,8 @@ const char *
TALER_amount2s (const struct TALER_Amount *amount)
{
/* 24 is sufficient for a uint64_t value in decimal; 3 is for ":.\0" */
- static GNUNET_THREAD_LOCAL char result[TALER_AMOUNT_FRAC_LEN
- + TALER_CURRENCY_LEN + 3 + 24];
+ static TALER_THREAD_LOCAL char result[TALER_AMOUNT_FRAC_LEN
+ + TALER_CURRENCY_LEN + 3 + 24];
struct TALER_Amount norm;
if (GNUNET_YES != TALER_amount_is_valid (amount))
@@ -680,9 +709,9 @@ TALER_amount_multiply (struct TALER_Amount *result,
if (GNUNET_SYSERR ==
TALER_amount_normalize (&in))
return TALER_AAR_INVALID_NORMALIZATION_FAILED;
- memcpy (result->currency,
- amount->currency,
- TALER_CURRENCY_LEN);
+ GNUNET_memcpy (result->currency,
+ amount->currency,
+ TALER_CURRENCY_LEN);
if ( (0 == factor) ||
( (0 == in.value) &&
(0 == in.fraction) ) )
diff --git a/src/util/bench_age_restriction.c b/src/util/bench_age_restriction.c
new file mode 100644
index 000000000..abda9416a
--- /dev/null
+++ b/src/util/bench_age_restriction.c
@@ -0,0 +1,208 @@
+/**
+ * @file util/bench_age_restriction.c
+ * @brief Measure Commit, Attest, Verify, Derive and Compare
+ * @author Özgür Kesim
+ *
+ * compile in exchange/src/util with
+ *
+ * gcc benc_age_restriction.c \
+ * -lgnunetutil -lgnunetjson -lsodium -ljansson \
+ * -L/usr/lib/x86_64-linux-gnu -lmicrohttpd -ltalerutil \
+ * -I../include \
+ * -o bench_age_restriction
+ *
+ */
+#include "platform.h"
+#include <math.h>
+#include <gnunet/gnunet_util_lib.h>
+#include <taler/taler_util.h>
+#include <taler/taler_crypto_lib.h>
+
+static struct TALER_AgeMask
+ age_mask = { .bits = 1
+ | 1 << 8 | 1 << 10 | 1 << 12
+ | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21 };
+
+extern uint8_t
+get_age_group (
+ const struct TALER_AgeMask *mask,
+ uint8_t age);
+
+/**
+ * Encodes the age mask into a string, like "8:10:12:14:16:18:21"
+ */
+char *
+age_mask_to_string (
+ const struct TALER_AgeMask *m)
+{
+ uint32_t bits = m->bits;
+ unsigned int n = 0;
+ char *buf = GNUNET_malloc (32 * 3); // max characters possible
+ char *pos = buf;
+
+ if (NULL == buf)
+ {
+ return buf;
+ }
+
+ while (bits != 0)
+ {
+ bits >>= 1;
+ n++;
+ if (0 == (bits & 1))
+ {
+ continue;
+ }
+
+ if (n > 9)
+ {
+ *(pos++) = '0' + n / 10;
+ }
+ *(pos++) = '0' + n % 10;
+
+ if (0 != (bits >> 1))
+ {
+ *(pos++) = ':';
+ }
+ }
+ return buf;
+}
+
+
+#define ITER 2000
+
+double
+average (long *times, size_t size)
+{
+ double mean = 0.0;
+ for (int i = 0; i < size; i++)
+ {
+ mean += times[i];
+ }
+ return mean / size;
+}
+
+
+double
+stdev (long *times, size_t size)
+{
+ double mean = average (times, size);
+ double V = 0.0;
+ for (int i = 0; i < size; i++)
+ {
+ double d = times[i] - mean;
+ d *= d;
+ V += d;
+ }
+ return sqrt (V / size);
+}
+
+
+#define pr(n,t, i) printf ("%10s (%dx):\t%.2f ± %.2fµs\n", (n), i, average ( \
+ &t[0], ITER) / 1000, stdev (&t[0], ITER) / 1000); \
+ i = 0;
+
+#define starttime clock_gettime (CLOCK_MONOTONIC, &tstart)
+#define stoptime clock_gettime (CLOCK_MONOTONIC, &tend); \
+ times[i] = ((long) tend.tv_sec * 1000 * 1000 * 1000 + tend.tv_nsec) \
+ - ((long) tstart.tv_sec * 1000 * 1000 * 1000 + tstart.tv_nsec);
+
+
+int
+main (int argc,
+ const char *const argv[])
+{
+ struct timespec tstart = {0,0}, tend = {0,0};
+ enum GNUNET_GenericReturnValue ret;
+ struct TALER_AgeCommitmentProof acp = {0};
+ uint8_t age = 21;
+ uint8_t age_group = get_age_group (&age_mask, age);
+ struct GNUNET_HashCode seed;
+ long times[ITER] = {0};
+ int i = 0;
+
+ // commit
+ for (; i < ITER; i++)
+ {
+ starttime;
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &seed,
+ sizeof(seed));
+
+ ret = TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
+ stoptime;
+
+ }
+ pr ("commit", times, i);
+
+ // attest
+ for (; i < ITER; i++)
+ {
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &seed,
+ sizeof(seed));
+
+ ret = TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
+
+ starttime;
+ uint8_t min_group = get_age_group (&age_mask, 13);
+ struct TALER_AgeAttestation at = {0};
+ ret = TALER_age_commitment_attest (&acp,
+ 13,
+ &at);
+ stoptime;
+ }
+ pr ("attest", times, i);
+
+ // verify
+ for (; i < ITER; i++)
+ {
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &seed,
+ sizeof(seed));
+
+ ret = TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
+
+ uint8_t min_group = get_age_group (&age_mask, 13);
+ struct TALER_AgeAttestation at = {0};
+
+ ret = TALER_age_commitment_attest (&acp,
+ 13,
+ &at);
+ starttime;
+ ret = TALER_age_commitment_verify (&acp.commitment,
+ 13,
+ &at);
+ stoptime;
+ }
+ pr ("verify", times, i);
+
+ // derive
+ for (; i < ITER; i++)
+ {
+ struct TALER_AgeCommitmentProof acp2 = {0};
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &seed,
+ sizeof(seed));
+ starttime;
+ TALER_age_commitment_derive (&acp,
+ &seed,
+ &acp2);
+ stoptime;
+ }
+ pr ("derive", times, i);
+
+ return 0;
+}
+
+
+/* end of tv_age_restriction.c */
diff --git a/src/util/config.c b/src/util/config.c
index c00792469..f5accaad8 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,7 +21,7 @@
*/
#include "platform.h"
#include "taler_util.h"
-
+#include <gnunet/gnunet_json_lib.h>
enum GNUNET_GenericReturnValue
TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
@@ -166,3 +166,345 @@ TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
}
return GNUNET_OK;
}
+
+
+/**
+ * Closure for #parse_currencies_cb().
+ */
+struct CurrencyParserContext
+{
+ /**
+ * Current offset in @e cspecs.
+ */
+ unsigned int num_currencies;
+
+ /**
+ * Length of the @e cspecs array.
+ */
+ unsigned int len_cspecs;
+
+ /**
+ * Array of currency specifications (see DD 51).
+ */
+ struct TALER_CurrencySpecification *cspecs;
+
+ /**
+ * Configuration we are parsing.
+ */
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
+
+ /**
+ * Set to true if the configuration was malformed.
+ */
+ bool failure;
+};
+
+
+/**
+ * Function to iterate over section.
+ *
+ * @param cls closure with a `struct CurrencyParserContext *`
+ * @param section name of the section
+ */
+static void
+parse_currencies_cb (void *cls,
+ const char *section)
+{
+ struct CurrencyParserContext *cpc = cls;
+ struct TALER_CurrencySpecification *cspec;
+ unsigned long long num;
+ char *str;
+
+ if (cpc->failure)
+ return;
+ if (0 != strncasecmp (section,
+ "currency-",
+ strlen ("currency-")))
+ return; /* not interesting */
+ if (GNUNET_YES !=
+ GNUNET_CONFIGURATION_get_value_yesno (cpc->cfg,
+ section,
+ "ENABLED"))
+ return; /* disabled */
+ if (cpc->len_cspecs == cpc->num_currencies)
+ {
+ GNUNET_array_grow (cpc->cspecs,
+ cpc->len_cspecs,
+ cpc->len_cspecs * 2 + 4);
+ }
+ cspec = &cpc->cspecs[cpc->num_currencies++];
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cpc->cfg,
+ section,
+ "CODE",
+ &str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "CODE");
+ cpc->failure = true;
+ return;
+ }
+ if (GNUNET_OK !=
+ TALER_check_currency (str))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "CODE",
+ "Currency code name given is invalid");
+ cpc->failure = true;
+ GNUNET_free (str);
+ return;
+ }
+ memset (cspec->currency,
+ 0,
+ sizeof (cspec->currency));
+ /* Already checked in TALER_check_currency(), repeated here
+ just to make static analysis happy */
+ GNUNET_assert (strlen (str) < TALER_CURRENCY_LEN);
+ strcpy (cspec->currency,
+ str);
+ GNUNET_free (str);
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cpc->cfg,
+ section,
+ "NAME",
+ &str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "NAME");
+ cpc->failure = true;
+ return;
+ }
+ cspec->name = str;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cpc->cfg,
+ section,
+ "FRACTIONAL_INPUT_DIGITS",
+ &num))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_INPUT_DIGITS");
+ cpc->failure = true;
+ return;
+ }
+ if (num > TALER_AMOUNT_FRAC_LEN)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_INPUT_DIGITS",
+ "Number given is too big");
+ cpc->failure = true;
+ return;
+ }
+ cspec->num_fractional_input_digits = num;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cpc->cfg,
+ section,
+ "FRACTIONAL_NORMAL_DIGITS",
+ &num))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_NORMAL_DIGITS");
+ cpc->failure = true;
+ return;
+ }
+ if (num > TALER_AMOUNT_FRAC_LEN)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_NORMAL_DIGITS",
+ "Number given is too big");
+ cpc->failure = true;
+ return;
+ }
+ cspec->num_fractional_normal_digits = num;
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cpc->cfg,
+ section,
+ "FRACTIONAL_TRAILING_ZERO_DIGITS",
+ &num))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_TRAILING_ZERO_DIGITS");
+ cpc->failure = true;
+ return;
+ }
+ if (num > TALER_AMOUNT_FRAC_LEN)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "FRACTIONAL_TRAILING_ZERO_DIGITS",
+ "Number given is too big");
+ cpc->failure = true;
+ return;
+ }
+ cspec->num_fractional_trailing_zero_digits = num;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cpc->cfg,
+ section,
+ "ALT_UNIT_NAMES",
+ &str))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "ALT_UNIT_NAMES");
+ cpc->failure = true;
+ return;
+ }
+ {
+ json_error_t err;
+
+ cspec->map_alt_unit_names = json_loads (str,
+ JSON_REJECT_DUPLICATES,
+ &err);
+ GNUNET_free (str);
+ if (NULL == cspec->map_alt_unit_names)
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "ALT_UNIT_NAMES",
+ err.text);
+ cpc->failure = true;
+ return;
+ }
+ }
+ if (GNUNET_OK !=
+ TALER_check_currency_scale_map (cspec->map_alt_unit_names))
+ {
+ GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
+ section,
+ "ALT_UNIT_NAMES",
+ "invalid map entry detected");
+ cpc->failure = true;
+ json_decref (cspec->map_alt_unit_names);
+ cspec->map_alt_unit_names = NULL;
+ return;
+ }
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_check_currency_scale_map (const json_t *map)
+{
+ /* validate map only maps from decimal numbers to strings! */
+ const char *str;
+ const json_t *val;
+ bool zf = false;
+
+ if (! json_is_object (map))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Object required for currency scale map\n");
+ return GNUNET_SYSERR;
+ }
+ json_object_foreach ((json_t *) map, str, val)
+ {
+ int idx;
+ char dummy;
+
+ if ( (1 != sscanf (str,
+ "%d%c",
+ &idx,
+ &dummy)) ||
+ (idx < -12) ||
+ (idx > 24) ||
+ (! json_is_string (val) ) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid entry `%s' in currency scale map\n",
+ str);
+ return GNUNET_SYSERR;
+ }
+ if (0 == idx)
+ zf = true;
+ }
+ if (! zf)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Entry for 0 missing in currency scale map\n");
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_CONFIG_parse_currencies (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ unsigned int *num_currencies,
+ struct TALER_CurrencySpecification **cspecs)
+{
+ struct CurrencyParserContext cpc = {
+ .cfg = cfg
+ };
+
+ GNUNET_CONFIGURATION_iterate_sections (cfg,
+ &parse_currencies_cb,
+ &cpc);
+ if (cpc.failure)
+ {
+ GNUNET_array_grow (cpc.cspecs,
+ cpc.len_cspecs,
+ 0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_array_grow (cpc.cspecs,
+ cpc.len_cspecs,
+ cpc.num_currencies);
+ *num_currencies = cpc.num_currencies;
+ *cspecs = cpc.cspecs;
+ if (0 == *num_currencies)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "No currency formatting specification found! Please check your installation!\n");
+ return GNUNET_NO;
+ }
+ return GNUNET_OK;
+}
+
+
+json_t *
+TALER_CONFIG_currency_specs_to_json (const struct
+ TALER_CurrencySpecification *cspec)
+{
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("name",
+ cspec->name),
+ /* 'currency' is deprecated as of exchange v18 and merchant v6;
+ remove this line once current-age > 6*/
+ GNUNET_JSON_pack_string ("currency",
+ cspec->currency),
+ GNUNET_JSON_pack_uint64 ("num_fractional_input_digits",
+ cspec->num_fractional_input_digits),
+ GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits",
+ cspec->num_fractional_normal_digits),
+ GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits",
+ cspec->num_fractional_trailing_zero_digits),
+ GNUNET_JSON_pack_object_incref ("alt_unit_names",
+ cspec->map_alt_unit_names));
+}
+
+
+void
+TALER_CONFIG_free_currencies (
+ unsigned int num_currencies,
+ struct TALER_CurrencySpecification cspecs[static num_currencies])
+{
+ for (unsigned int i = 0; i<num_currencies; i++)
+ {
+ struct TALER_CurrencySpecification *cspec = &cspecs[i];
+
+ GNUNET_free (cspec->name);
+ json_decref (cspec->map_alt_unit_names);
+ }
+ GNUNET_array_grow (cspecs,
+ num_currencies,
+ 0);
+}
diff --git a/src/util/conversion.c b/src/util/conversion.c
new file mode 100644
index 000000000..a7bc63789
--- /dev/null
+++ b/src/util/conversion.c
@@ -0,0 +1,405 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file conversion.c
+ * @brief helper routines to run some external JSON-to-JSON converter
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include <gnunet/gnunet_util_lib.h>
+
+
+struct TALER_JSON_ExternalConversion
+{
+ /**
+ * Callback to call with the result.
+ */
+ TALER_JSON_JsonCallback cb;
+
+ /**
+ * Closure for @e cb.
+ */
+ void *cb_cls;
+
+ /**
+ * Handle to the helper process.
+ */
+ struct GNUNET_OS_Process *helper;
+
+ /**
+ * Pipe for the stdin of the @e helper.
+ */
+ struct GNUNET_DISK_FileHandle *chld_stdin;
+
+ /**
+ * Pipe for the stdout of the @e helper.
+ */
+ struct GNUNET_DISK_FileHandle *chld_stdout;
+
+ /**
+ * Handle to wait on the child to terminate.
+ */
+ struct GNUNET_ChildWaitHandle *cwh;
+
+ /**
+ * Task to read JSON output from the child.
+ */
+ struct GNUNET_SCHEDULER_Task *read_task;
+
+ /**
+ * Task to send JSON input to the child.
+ */
+ struct GNUNET_SCHEDULER_Task *write_task;
+
+ /**
+ * Buffer with data we need to send to the helper.
+ */
+ void *write_buf;
+
+ /**
+ * Buffer for reading data from the helper.
+ */
+ void *read_buf;
+
+ /**
+ * Total length of @e write_buf.
+ */
+ size_t write_size;
+
+ /**
+ * Current write position in @e write_buf.
+ */
+ size_t write_pos;
+
+ /**
+ * Current size of @a read_buf.
+ */
+ size_t read_size;
+
+ /**
+ * Current offset in @a read_buf.
+ */
+ size_t read_pos;
+
+};
+
+
+/**
+ * Function called when we can read more data from
+ * the child process.
+ *
+ * @param cls our `struct TALER_JSON_ExternalConversion *`
+ */
+static void
+read_cb (void *cls)
+{
+ struct TALER_JSON_ExternalConversion *ec = cls;
+
+ ec->read_task = NULL;
+ while (1)
+ {
+ ssize_t ret;
+
+ if (ec->read_size == ec->read_pos)
+ {
+ /* Grow input buffer */
+ size_t ns;
+ void *tmp;
+
+ ns = GNUNET_MAX (2 * ec->read_size,
+ 1024);
+ if (ns > GNUNET_MAX_MALLOC_CHECKED)
+ ns = GNUNET_MAX_MALLOC_CHECKED;
+ if (ec->read_size == ns)
+ {
+ /* Helper returned more than 40 MB of data! Stop reading! */
+ GNUNET_break (0);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (ec->chld_stdin));
+ return;
+ }
+ tmp = GNUNET_malloc_large (ns);
+ if (NULL == tmp)
+ {
+ /* out of memory, also stop reading */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "malloc");
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (ec->chld_stdin));
+ return;
+ }
+ GNUNET_memcpy (tmp,
+ ec->read_buf,
+ ec->read_pos);
+ GNUNET_free (ec->read_buf);
+ ec->read_buf = tmp;
+ ec->read_size = ns;
+ }
+ ret = GNUNET_DISK_file_read (ec->chld_stdout,
+ ec->read_buf + ec->read_pos,
+ ec->read_size - ec->read_pos);
+ if (ret < 0)
+ {
+ if ( (EAGAIN != errno) &&
+ (EWOULDBLOCK != errno) &&
+ (EINTR != errno) )
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "read");
+ return;
+ }
+ break;
+ }
+ if (0 == ret)
+ {
+ /* regular end of stream, good! */
+ return;
+ }
+ GNUNET_assert (ec->read_size >= ec->read_pos + ret);
+ ec->read_pos += ret;
+ }
+ ec->read_task
+ = GNUNET_SCHEDULER_add_read_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ ec->chld_stdout,
+ &read_cb,
+ ec);
+}
+
+
+/**
+ * Function called when we can write more data to
+ * the child process.
+ *
+ * @param cls our `struct TALER_JSON_ExternalConversion *`
+ */
+static void
+write_cb (void *cls)
+{
+ struct TALER_JSON_ExternalConversion *ec = cls;
+ ssize_t ret;
+
+ ec->write_task = NULL;
+ while (ec->write_size > ec->write_pos)
+ {
+ ret = GNUNET_DISK_file_write (ec->chld_stdin,
+ ec->write_buf + ec->write_pos,
+ ec->write_size - ec->write_pos);
+ if (ret < 0)
+ {
+ if ( (EAGAIN != errno) &&
+ (EINTR != errno) )
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "write");
+ break;
+ }
+ if (0 == ret)
+ {
+ GNUNET_break (0);
+ break;
+ }
+ GNUNET_assert (ec->write_size >= ec->write_pos + ret);
+ ec->write_pos += ret;
+ }
+ if ( (ec->write_size > ec->write_pos) &&
+ ( (EAGAIN == errno) ||
+ (EWOULDBLOCK == errno) ||
+ (EINTR == errno) ) )
+ {
+ ec->write_task
+ = GNUNET_SCHEDULER_add_write_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ ec->chld_stdin,
+ &write_cb,
+ ec);
+ }
+ else
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (ec->chld_stdin));
+ ec->chld_stdin = NULL;
+ }
+}
+
+
+/**
+ * Defines a GNUNET_ChildCompletedCallback which is sent back
+ * upon death or completion of a child process.
+ *
+ * @param cls handle for the callback
+ * @param type type of the process
+ * @param exit_code status code of the process
+ *
+ */
+static void
+child_done_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType type,
+ long unsigned int exit_code)
+{
+ struct TALER_JSON_ExternalConversion *ec = cls;
+ json_t *j = NULL;
+ json_error_t err;
+
+ ec->cwh = NULL;
+ if (NULL != ec->read_task)
+ {
+ GNUNET_SCHEDULER_cancel (ec->read_task);
+ /* We could get the process termination notification before having drained
+ the read buffer. So drain it now, just in case. */
+ read_cb (ec);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Conversion helper exited with status %d and code %llu after outputting %llu bytes of data\n",
+ (int) type,
+ (unsigned long long) exit_code,
+ (unsigned long long) ec->read_pos);
+ GNUNET_OS_process_destroy (ec->helper);
+ ec->helper = NULL;
+ if (0 != ec->read_pos)
+ {
+ j = json_loadb (ec->read_buf,
+ ec->read_pos,
+ JSON_REJECT_DUPLICATES,
+ &err);
+ if (NULL == j)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to parse JSON from helper at %d: %s\n",
+ err.position,
+ err.text);
+ }
+ }
+ ec->cb (ec->cb_cls,
+ type,
+ exit_code,
+ j);
+ json_decref (j);
+ TALER_JSON_external_conversion_stop (ec);
+}
+
+
+struct TALER_JSON_ExternalConversion *
+TALER_JSON_external_conversion_start (const json_t *input,
+ TALER_JSON_JsonCallback cb,
+ void *cb_cls,
+ const char *binary,
+ ...)
+{
+ struct TALER_JSON_ExternalConversion *ec;
+ struct GNUNET_DISK_PipeHandle *pipe_stdin;
+ struct GNUNET_DISK_PipeHandle *pipe_stdout;
+ va_list ap;
+
+ ec = GNUNET_new (struct TALER_JSON_ExternalConversion);
+ ec->cb = cb;
+ ec->cb_cls = cb_cls;
+ pipe_stdin = GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_READ);
+ GNUNET_assert (NULL != pipe_stdin);
+ pipe_stdout = GNUNET_DISK_pipe (GNUNET_DISK_PF_BLOCKING_WRITE);
+ GNUNET_assert (NULL != pipe_stdout);
+ va_start (ap,
+ binary);
+ ec->helper = GNUNET_OS_start_process_va (GNUNET_OS_INHERIT_STD_ERR,
+ pipe_stdin,
+ pipe_stdout,
+ NULL,
+ binary,
+ ap);
+ va_end (ap);
+ if (NULL == ec->helper)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to run conversion helper `%s'\n",
+ binary);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (pipe_stdin));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (pipe_stdout));
+ GNUNET_free (ec);
+ return NULL;
+ }
+ ec->chld_stdin =
+ GNUNET_DISK_pipe_detach_end (pipe_stdin,
+ GNUNET_DISK_PIPE_END_WRITE);
+ ec->chld_stdout =
+ GNUNET_DISK_pipe_detach_end (pipe_stdout,
+ GNUNET_DISK_PIPE_END_READ);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (pipe_stdin));
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_pipe_close (pipe_stdout));
+ ec->write_buf = json_dumps (input, JSON_COMPACT);
+ ec->write_size = strlen (ec->write_buf);
+ ec->read_task
+ = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ ec->chld_stdout,
+ &read_cb,
+ ec);
+ ec->write_task
+ = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ ec->chld_stdin,
+ &write_cb,
+ ec);
+ ec->cwh = GNUNET_wait_child (ec->helper,
+ &child_done_cb,
+ ec);
+ return ec;
+}
+
+
+void
+TALER_JSON_external_conversion_stop (
+ struct TALER_JSON_ExternalConversion *ec)
+{
+ if (NULL != ec->cwh)
+ {
+ GNUNET_wait_child_cancel (ec->cwh);
+ ec->cwh = NULL;
+ }
+ if (NULL != ec->helper)
+ {
+ GNUNET_break (0 ==
+ GNUNET_OS_process_kill (ec->helper,
+ SIGKILL));
+ GNUNET_OS_process_destroy (ec->helper);
+ }
+ if (NULL != ec->read_task)
+ {
+ GNUNET_SCHEDULER_cancel (ec->read_task);
+ ec->read_task = NULL;
+ }
+ if (NULL != ec->write_task)
+ {
+ GNUNET_SCHEDULER_cancel (ec->write_task);
+ ec->write_task = NULL;
+ }
+ if (NULL != ec->chld_stdin)
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (ec->chld_stdin));
+ ec->chld_stdin = NULL;
+ }
+ if (NULL != ec->chld_stdout)
+ {
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_file_close (ec->chld_stdout));
+ ec->chld_stdout = NULL;
+ }
+ GNUNET_free (ec->read_buf);
+ free (ec->write_buf);
+ GNUNET_free (ec);
+}
diff --git a/src/util/crypto.c b/src/util/crypto.c
index 974566dc0..4735af3b0 100644
--- a/src/util/crypto.c
+++ b/src/util/crypto.c
@@ -27,11 +27,6 @@
#include <gcrypt.h>
/**
- * Used in TALER_AgeCommitmentHash_isNullOrZero for comparison
- */
-const struct TALER_AgeCommitmentHash TALER_ZeroAgeCommitmentHash = {0};
-
-/**
* Function called by libgcrypt on serious errors.
* Prints an error message and aborts the process.
*
@@ -90,7 +85,9 @@ TALER_test_coin_valid (const struct TALER_CoinPublicInfo *coin_public_info,
#endif
TALER_coin_pub_hash (&coin_public_info->coin_pub,
- &coin_public_info->h_age_commitment,
+ coin_public_info->no_age_commitment
+ ? NULL
+ : &coin_public_info->h_age_commitment,
&c_hash);
if (GNUNET_OK !=
@@ -217,7 +214,7 @@ TALER_planchet_secret_to_transfer_priv (
void
TALER_cs_withdraw_nonce_derive (
const struct TALER_PlanchetMasterSecretP *ps,
- struct TALER_CsNonce *nonce)
+ struct GNUNET_CRYPTO_CsSessionNonce *nonce)
{
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_kdf (nonce,
@@ -235,7 +232,7 @@ void
TALER_cs_refresh_nonce_derive (
const struct TALER_RefreshMasterSecretP *rms,
uint32_t coin_num_salt,
- struct TALER_CsNonce *nonce)
+ struct GNUNET_CRYPTO_CsSessionNonce *nonce)
{
uint32_t be_salt = htonl (coin_num_salt);
@@ -244,7 +241,7 @@ TALER_cs_refresh_nonce_derive (
sizeof (*nonce),
&be_salt,
sizeof (be_salt),
- "refresh-n", // FIXME: value used in spec?
+ "refresh-n",
strlen ("refresh-n"),
rms,
sizeof(*rms),
@@ -253,10 +250,31 @@ TALER_cs_refresh_nonce_derive (
}
+void
+TALER_rsa_pub_hash (const struct GNUNET_CRYPTO_RsaPublicKey *rsa,
+ struct TALER_RsaPubHashP *h_rsa)
+{
+ GNUNET_CRYPTO_rsa_public_key_hash (rsa,
+ &h_rsa->hash);
+
+}
+
+
+void
+TALER_cs_pub_hash (const struct GNUNET_CRYPTO_CsPublicKey *cs,
+ struct TALER_CsPubHashP *h_cs)
+{
+ GNUNET_CRYPTO_hash (cs,
+ sizeof(*cs),
+ &h_cs->hash);
+}
+
+
enum GNUNET_GenericReturnValue
TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
const struct TALER_ExchangeWithdrawValues *alg_values,
- const union TALER_DenominationBlindingKeyP *bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
const struct TALER_AgeCommitmentHash *ach,
struct TALER_CoinPubHashP *c_hash,
@@ -265,12 +283,14 @@ TALER_planchet_prepare (const struct TALER_DenominationPublicKey *dk,
{
struct TALER_CoinSpendPublicKeyP coin_pub;
- GNUNET_assert (alg_values->cipher == dk->cipher);
+ GNUNET_assert (alg_values->blinding_inputs->cipher ==
+ dk->bsign_pub_key->cipher);
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv->eddsa_priv,
&coin_pub.eddsa_pub);
if (GNUNET_OK !=
TALER_denom_blind (dk,
bks,
+ nonce,
ach,
&coin_pub,
alg_values,
@@ -297,15 +317,21 @@ enum GNUNET_GenericReturnValue
TALER_planchet_to_coin (
const struct TALER_DenominationPublicKey *dk,
const struct TALER_BlindedDenominationSignature *blind_sig,
- const union TALER_DenominationBlindingKeyP *bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
const struct TALER_AgeCommitmentHash *ach,
const struct TALER_CoinPubHashP *c_hash,
const struct TALER_ExchangeWithdrawValues *alg_values,
struct TALER_FreshCoin *coin)
{
- if ( (dk->cipher != blind_sig->cipher) ||
- (dk->cipher != alg_values->cipher) )
+ if (dk->bsign_pub_key->cipher !=
+ blind_sig->blinded_sig->cipher)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (dk->bsign_pub_key->cipher !=
+ alg_values->blinding_inputs->cipher)
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
@@ -426,24 +452,28 @@ TALER_coin_pub_hash (const struct TALER_CoinSpendPublicKeyP *coin_pub,
{
/* Coin comes with age commitment. Take the hash of the age commitment
* into account */
- const size_t key_s = sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey);
- const size_t age_s = sizeof(struct TALER_AgeCommitmentHash);
- char data[key_s + age_s];
-
- GNUNET_memcpy (&data[0],
- &coin_pub->eddsa_pub,
- key_s);
- GNUNET_memcpy (&data[key_s],
- ach,
- age_s);
- GNUNET_CRYPTO_hash (&data,
- key_s + age_s,
- &coin_h->hash);
+ struct GNUNET_HashContext *hash_context;
+
+ hash_context = GNUNET_CRYPTO_hash_context_start ();
+
+ GNUNET_CRYPTO_hash_context_read (
+ hash_context,
+ &coin_pub->eddsa_pub,
+ sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
+
+ GNUNET_CRYPTO_hash_context_read (
+ hash_context,
+ ach,
+ sizeof(struct TALER_AgeCommitmentHash));
+
+ GNUNET_CRYPTO_hash_context_finish (
+ hash_context,
+ &coin_h->hash);
}
}
-enum GNUNET_GenericReturnValue
+void
TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
const struct TALER_DenominationHashP *denom_hash,
struct TALER_BlindedCoinHashP *bch)
@@ -458,7 +488,56 @@ TALER_coin_ev_hash (const struct TALER_BlindedPlanchet *blinded_planchet,
hash_context);
GNUNET_CRYPTO_hash_context_finish (hash_context,
&bch->hash);
- return GNUNET_OK;
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+/**
+ * Structure we hash to compute the group key for
+ * a denomination group.
+ */
+struct DenominationGroupP
+{
+ /**
+ * Value of coins in this denomination group.
+ */
+ struct TALER_AmountNBO value;
+
+ /**
+ * Fee structure for all coins in the group.
+ */
+ struct TALER_DenomFeeSetNBOP fees;
+
+ /**
+ * Age mask for the denomiation, in NBO.
+ */
+ uint32_t age_mask GNUNET_PACKED;
+
+ /**
+ * Cipher used for the denomination, in NBO.
+ */
+ uint32_t cipher GNUNET_PACKED;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_denomination_group_get_key (
+ const struct TALER_DenominationGroup *dg,
+ struct GNUNET_HashCode *key)
+{
+ struct DenominationGroupP dgp = {
+ .age_mask = htonl (dg->age_mask.bits),
+ .cipher = htonl (dg->cipher)
+ };
+
+ TALER_amount_hton (&dgp.value,
+ &dg->value);
+ TALER_denom_fee_set_hton (&dgp.fees,
+ &dg->fees);
+ GNUNET_CRYPTO_hash (&dgp,
+ sizeof (dgp),
+ key);
}
diff --git a/src/util/crypto_confirmation.c b/src/util/crypto_confirmation.c
new file mode 100644
index 000000000..99552f150
--- /dev/null
+++ b/src/util/crypto_confirmation.c
@@ -0,0 +1,293 @@
+/*
+ This file is part of TALER
+ Copyright (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file util/crypto_confirmation.c
+ * @brief confirmation computation
+ * @author Christian Grothoff
+ * @author Priscilla Huang
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include "taler_mhd_lib.h"
+#include <gnunet/gnunet_db_lib.h>
+#include <gcrypt.h>
+
+/**
+ * How long is a TOTP code valid?
+ */
+#define TOTP_VALIDITY_PERIOD GNUNET_TIME_relative_multiply ( \
+ GNUNET_TIME_UNIT_SECONDS, 30)
+
+/**
+ * Range of time we allow (plus-minus).
+ */
+#define TIME_INTERVAL_RANGE 2
+
+
+/**
+ * Compute TOTP code at current time with offset
+ * @a time_off for the @a key.
+ *
+ * @param ts current time
+ * @param time_off offset to apply when computing the code
+ * @param key pos_key in binary
+ * @param key_size number of bytes in @a key
+ */
+static uint64_t
+compute_totp (struct GNUNET_TIME_Timestamp ts,
+ int time_off,
+ const void *key,
+ size_t key_size)
+{
+ struct GNUNET_TIME_Absolute now;
+ time_t t;
+ uint64_t ctr;
+ uint8_t hmac[20]; /* SHA1: 20 bytes */
+
+ now = ts.abs_time;
+ while (time_off < 0)
+ {
+ now = GNUNET_TIME_absolute_subtract (now,
+ TOTP_VALIDITY_PERIOD);
+ time_off++;
+ }
+ while (time_off > 0)
+ {
+ now = GNUNET_TIME_absolute_add (now,
+ TOTP_VALIDITY_PERIOD);
+ time_off--;
+ }
+ t = now.abs_value_us / GNUNET_TIME_UNIT_SECONDS.rel_value_us;
+ ctr = GNUNET_htonll (t / 30LLU);
+
+ {
+ gcry_md_hd_t md;
+ const unsigned char *mc;
+
+ GNUNET_assert (GPG_ERR_NO_ERROR ==
+ gcry_md_open (&md,
+ GCRY_MD_SHA1,
+ GCRY_MD_FLAG_HMAC));
+ GNUNET_assert (GPG_ERR_NO_ERROR ==
+ gcry_md_setkey (md,
+ key,
+ key_size));
+ gcry_md_write (md,
+ &ctr,
+ sizeof (ctr));
+ mc = gcry_md_read (md,
+ GCRY_MD_SHA1);
+ GNUNET_assert (NULL != mc);
+ GNUNET_memcpy (hmac,
+ mc,
+ sizeof (hmac));
+ gcry_md_close (md);
+ }
+
+ {
+ uint32_t code = 0;
+ int offset;
+
+ offset = hmac[sizeof (hmac) - 1] & 0x0f;
+ for (int count = 0; count < 4; count++)
+ code |= ((uint32_t) hmac[offset + 3 - count]) << (8 * count);
+ code &= 0x7fffffff;
+ /* always use 8 digits (maximum) */
+ code = code % 100000000;
+ return code;
+ }
+}
+
+
+int
+TALER_rfc3548_base32decode (const char *val,
+ size_t val_size,
+ void *key,
+ size_t key_len)
+{
+ /**
+ * 32 characters for decoding, using RFC 3548.
+ */
+ static const char *decTable__ = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
+ unsigned char *udata = key;
+ unsigned int wpos = 0;
+ unsigned int rpos = 0;
+ unsigned int bits = 0;
+ unsigned int vbit = 0;
+
+ while ((rpos < val_size) || (vbit >= 8))
+ {
+ if ((rpos < val_size) && (vbit < 8))
+ {
+ char c = val[rpos++];
+
+ if (c == '=')
+ {
+ /* padding character */
+ if (rpos == val_size)
+ break; /* Ok, 1x '=' padding is allowed */
+ if ( ('=' == val[rpos]) &&
+ (rpos + 1 == val_size) )
+ break; /* Ok, 2x '=' padding is allowed */
+ return -1; /* invalid padding */
+ }
+ const char *p = strchr (decTable__, toupper (c));
+ if (! p)
+ {
+ /* invalid character */
+ return -1;
+ }
+ bits = (bits << 5) | (p - decTable__);
+ vbit += 5;
+ }
+ if (vbit >= 8)
+ {
+ udata[wpos++] = (bits >> (vbit - 8)) & 0xFF;
+ vbit -= 8;
+ }
+ }
+ return wpos;
+}
+
+
+/**
+ * @brief Builds POS confirmation to verify payment.
+ *
+ * @param h_key opaque key for the totp operation
+ * @param h_key_len size of h_key in bytes
+ * @param ts current time
+ * @return Token on success, NULL of failure
+ */
+static char *
+executive_totp (void *h_key,
+ size_t h_key_len,
+ struct GNUNET_TIME_Timestamp ts)
+{
+ uint64_t code; /* totp code */
+ char *ret;
+ ret = NULL;
+
+ for (int i = -TIME_INTERVAL_RANGE; i<= TIME_INTERVAL_RANGE; i++)
+ {
+ code = compute_totp (ts,
+ i,
+ h_key,
+ h_key_len);
+ if (NULL == ret)
+ {
+ GNUNET_asprintf (&ret,
+ "%08llu",
+ (unsigned long long) code);
+ }
+ else
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp,
+ "%s\n%08llu",
+ ret,
+ (unsigned long long) code);
+ GNUNET_free (ret);
+ ret = tmp;
+ }
+ }
+ return ret;
+
+}
+
+
+char *
+TALER_build_pos_confirmation (const char *pos_key,
+ enum TALER_MerchantConfirmationAlgorithm pos_alg,
+ const struct TALER_Amount *total,
+ struct GNUNET_TIME_Timestamp ts)
+{
+ size_t pos_key_length = strlen (pos_key);
+ void *key; /* pos_key in binary */
+ size_t key_len; /* length of the key */
+ char *ret;
+ int dret;
+
+ if (TALER_MCA_NONE == pos_alg)
+ return NULL;
+ key_len = pos_key_length * 5 / 8;
+ key = GNUNET_malloc (key_len);
+ dret = TALER_rfc3548_base32decode (pos_key,
+ pos_key_length,
+ key,
+ key_len);
+ if (-1 == dret)
+ {
+ GNUNET_free (key);
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ GNUNET_assert (dret <= key_len);
+ key_len = (size_t) dret;
+ switch (pos_alg)
+ {
+ case TALER_MCA_NONE:
+ GNUNET_break (0);
+ GNUNET_free (key);
+ return NULL;
+ case TALER_MCA_WITHOUT_PRICE: /* and 30s */
+ /* Return all T-OTP codes in range separated by new lines, e.g.
+ "12345678
+ 24522552
+ 25262425
+ 42543525
+ 25253552"
+ */
+ ret = executive_totp (key,
+ key_len,
+ ts);
+ GNUNET_free (key);
+ return ret;
+ case TALER_MCA_WITH_PRICE:
+ {
+ struct GNUNET_HashCode hkey;
+ struct TALER_AmountNBO ntotal;
+
+ if ( (NULL == total) ||
+ (GNUNET_YES !=
+ TALER_amount_is_valid (total) ) )
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ TALER_amount_hton (&ntotal,
+ total);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (&hkey,
+ sizeof (hkey),
+ &ntotal,
+ sizeof (ntotal),
+ key,
+ key_len,
+ NULL,
+ 0));
+ GNUNET_free (key);
+ ret = executive_totp (&hkey,
+ sizeof(hkey),
+ ts);
+ GNUNET_free (key);
+ return ret;
+ }
+ }
+ GNUNET_free (key);
+ GNUNET_break (0);
+ return NULL;
+}
diff --git a/src/util/crypto_contract.c b/src/util/crypto_contract.c
index fe6b1e6af..bec34c983 100644
--- a/src/util/crypto_contract.c
+++ b/src/util/crypto_contract.c
@@ -109,14 +109,14 @@ derive_key (const void *key_material,
* @param[out] res_size size of the ciphertext
*/
static void
-contract_encrypt (const struct NonceP *nonce,
- const void *key,
- size_t key_len,
- const void *data,
- size_t data_size,
- const char *salt,
- void **res,
- size_t *res_size)
+blob_encrypt (const struct NonceP *nonce,
+ const void *key,
+ size_t key_len,
+ const void *data,
+ size_t data_size,
+ const char *salt,
+ void **res,
+ size_t *res_size)
{
size_t ciphertext_size;
struct SymKeyP skey;
@@ -127,10 +127,13 @@ contract_encrypt (const struct NonceP *nonce,
salt,
&skey);
ciphertext_size = crypto_secretbox_NONCEBYTES
- + crypto_secretbox_MACBYTES + data_size;
+ + crypto_secretbox_MACBYTES
+ + data_size;
*res_size = ciphertext_size;
*res = GNUNET_malloc (ciphertext_size);
- memcpy (*res, nonce, crypto_secretbox_NONCEBYTES);
+ GNUNET_memcpy (*res,
+ nonce,
+ crypto_secretbox_NONCEBYTES);
GNUNET_assert (0 ==
crypto_secretbox_easy (*res + crypto_secretbox_NONCEBYTES,
data,
@@ -153,13 +156,13 @@ contract_encrypt (const struct NonceP *nonce,
* @return #GNUNET_OK on success
*/
static enum GNUNET_GenericReturnValue
-contract_decrypt (const void *key,
- size_t key_len,
- const void *data,
- size_t data_size,
- const char *salt,
- void **res,
- size_t *res_size)
+blob_decrypt (const void *key,
+ size_t key_len,
+ const void *data,
+ size_t data_size,
+ const char *salt,
+ void **res,
+ size_t *res_size)
{
const struct NonceP *nonce;
struct SymKeyP skey;
@@ -271,21 +274,21 @@ TALER_CRYPTO_contract_encrypt_for_merge (
hdr->header.ctype = htonl (TALER_EXCHANGE_CONTRACT_PAYMENT_OFFER);
hdr->header.clen = htonl ((uint32_t) clen);
hdr->merge_priv = *merge_priv;
- memcpy (&hdr[1],
- xbuf,
- cbuf_size);
+ GNUNET_memcpy (&hdr[1],
+ xbuf,
+ cbuf_size);
GNUNET_free (xbuf);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
&nonce,
sizeof (nonce));
- contract_encrypt (&nonce,
- &key,
- sizeof (key),
- hdr,
- sizeof (*hdr) + cbuf_size,
- MERGE_SALT,
- econtract,
- econtract_size);
+ blob_encrypt (&nonce,
+ &key,
+ sizeof (key),
+ hdr,
+ sizeof (*hdr) + cbuf_size,
+ MERGE_SALT,
+ econtract,
+ econtract_size);
GNUNET_free (hdr);
}
@@ -316,13 +319,13 @@ TALER_CRYPTO_contract_decrypt_for_merge (
return NULL;
}
if (GNUNET_OK !=
- contract_decrypt (&key,
- sizeof (key),
- econtract,
- econtract_size,
- MERGE_SALT,
- &xhdr,
- &hdr_size))
+ blob_decrypt (&key,
+ sizeof (key),
+ econtract,
+ econtract_size,
+ MERGE_SALT,
+ &xhdr,
+ &hdr_size))
{
GNUNET_break_op (0);
return NULL;
@@ -407,6 +410,7 @@ TALER_CRYPTO_contract_encrypt_for_deposit (
&key));
cstr = json_dumps (contract_terms,
JSON_COMPACT | JSON_SORT_KEYS);
+ GNUNET_assert (NULL != cstr);
clen = strlen (cstr);
cbuf_size = compressBound (clen);
xbuf = GNUNET_malloc (cbuf_size);
@@ -419,30 +423,30 @@ TALER_CRYPTO_contract_encrypt_for_deposit (
hdr = GNUNET_malloc (sizeof (*hdr) + cbuf_size);
hdr->ctype = htonl (TALER_EXCHANGE_CONTRACT_PAYMENT_REQUEST);
hdr->clen = htonl ((uint32_t) clen);
- memcpy (&hdr[1],
- xbuf,
- cbuf_size);
+ GNUNET_memcpy (&hdr[1],
+ xbuf,
+ cbuf_size);
GNUNET_free (xbuf);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
&nonce,
sizeof (nonce));
- contract_encrypt (&nonce,
- &key,
- sizeof (key),
- hdr,
- sizeof (*hdr) + cbuf_size,
- DEPOSIT_SALT,
- &xecontract,
- &xecontract_size);
+ blob_encrypt (&nonce,
+ &key,
+ sizeof (key),
+ hdr,
+ sizeof (*hdr) + cbuf_size,
+ DEPOSIT_SALT,
+ &xecontract,
+ &xecontract_size);
GNUNET_free (hdr);
/* prepend purse_pub */
*econtract = GNUNET_malloc (xecontract_size + sizeof (*purse_pub));
- memcpy (*econtract,
- purse_pub,
- sizeof (*purse_pub));
- memcpy (sizeof (*purse_pub) + *econtract,
- xecontract,
- xecontract_size);
+ GNUNET_memcpy (*econtract,
+ purse_pub,
+ sizeof (*purse_pub));
+ GNUNET_memcpy (sizeof (*purse_pub) + *econtract,
+ xecontract,
+ xecontract_size);
*econtract_size = xecontract_size + sizeof (*purse_pub);
GNUNET_free (xecontract);
}
@@ -481,13 +485,13 @@ TALER_CRYPTO_contract_decrypt_for_deposit (
econtract += sizeof (*purse_pub);
econtract_size -= sizeof (*purse_pub);
if (GNUNET_OK !=
- contract_decrypt (&key,
- sizeof (key),
- econtract,
- econtract_size,
- DEPOSIT_SALT,
- &xhdr,
- &hdr_size))
+ blob_decrypt (&key,
+ sizeof (key),
+ econtract,
+ econtract_size,
+ DEPOSIT_SALT,
+ &xhdr,
+ &hdr_size))
{
GNUNET_break_op (0);
return NULL;
@@ -538,3 +542,120 @@ TALER_CRYPTO_contract_decrypt_for_deposit (
GNUNET_free (cstr);
return ret;
}
+
+
+/**
+ * Salt we use when encrypting KYC attributes.
+ */
+#define ATTRIBUTE_SALT "kyc-attributes"
+
+
+void
+TALER_CRYPTO_kyc_attributes_encrypt (
+ const struct TALER_AttributeEncryptionKeyP *key,
+ const json_t *attr,
+ void **enc_attr,
+ size_t *enc_attr_size)
+{
+ uLongf cbuf_size;
+ char *cstr;
+ uLongf clen;
+ void *xbuf;
+ int ret;
+ uint32_t belen;
+ struct NonceP nonce;
+
+ cstr = json_dumps (attr,
+ JSON_COMPACT | JSON_SORT_KEYS);
+ GNUNET_assert (NULL != cstr);
+ clen = strlen (cstr);
+ GNUNET_assert (clen <= UINT32_MAX);
+ cbuf_size = compressBound (clen);
+ xbuf = GNUNET_malloc (cbuf_size + sizeof (uint32_t));
+ belen = htonl ((uint32_t) clen);
+ GNUNET_memcpy (xbuf,
+ &belen,
+ sizeof (belen));
+ ret = compress (xbuf + 4,
+ &cbuf_size,
+ (const Bytef *) cstr,
+ clen);
+ GNUNET_assert (Z_OK == ret);
+ free (cstr);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &nonce,
+ sizeof (nonce));
+ blob_encrypt (&nonce,
+ key,
+ sizeof (*key),
+ xbuf,
+ cbuf_size + sizeof (uint32_t),
+ ATTRIBUTE_SALT,
+ enc_attr,
+ enc_attr_size);
+ GNUNET_free (xbuf);
+}
+
+
+json_t *
+TALER_CRYPTO_kyc_attributes_decrypt (
+ const struct TALER_AttributeEncryptionKeyP *key,
+ const void *enc_attr,
+ size_t enc_attr_size)
+{
+ void *xhdr;
+ size_t hdr_size;
+ char *cstr;
+ uLongf clen;
+ json_error_t json_error;
+ json_t *ret;
+ uint32_t belen;
+
+ if (GNUNET_OK !=
+ blob_decrypt (key,
+ sizeof (*key),
+ enc_attr,
+ enc_attr_size,
+ ATTRIBUTE_SALT,
+ &xhdr,
+ &hdr_size))
+ {
+ GNUNET_break_op (0);
+ return NULL;
+ }
+ GNUNET_memcpy (&belen,
+ xhdr,
+ sizeof (belen));
+ clen = ntohl (belen);
+ if (clen >= GNUNET_MAX_MALLOC_CHECKED)
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (xhdr);
+ return NULL;
+ }
+ cstr = GNUNET_malloc (clen + 1);
+ if (Z_OK !=
+ uncompress ((Bytef *) cstr,
+ &clen,
+ (const Bytef *) (xhdr + sizeof (uint32_t)),
+ hdr_size - sizeof (uint32_t)))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (cstr);
+ GNUNET_free (xhdr);
+ return NULL;
+ }
+ GNUNET_free (xhdr);
+ ret = json_loadb ((char *) cstr,
+ clen,
+ JSON_DECODE_ANY,
+ &json_error);
+ if (NULL == ret)
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (cstr);
+ return NULL;
+ }
+ GNUNET_free (cstr);
+ return ret;
+}
diff --git a/src/util/crypto_helper_cs.c b/src/util/crypto_helper_cs.c
index e12d5ad61..4c4a56feb 100644
--- a/src/util/crypto_helper_cs.c
+++ b/src/util/crypto_helper_cs.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020, 2021 Taler Systems SA
+ Copyright (C) 2020, 2021, 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -113,21 +113,27 @@ try_connect (struct TALER_CRYPTO_CsDenominationHelper *dh)
struct TALER_CRYPTO_CsDenominationHelper *
TALER_CRYPTO_helper_cs_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_CsDenominationKeyStatusCallback dkc,
void *dkc_cls)
{
struct TALER_CRYPTO_CsDenominationHelper *dh;
char *unixpath;
+ char *secname;
+ GNUNET_asprintf (&secname,
+ "%s-secmod-cs",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-cs",
+ secname,
"UNIXPATH",
&unixpath))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"UNIXPATH");
+ GNUNET_free (secname);
return NULL;
}
/* we use >= here because we want the sun_path to always
@@ -135,12 +141,14 @@ TALER_CRYPTO_helper_cs_connect (
if (strlen (unixpath) >= sizeof (dh->sa.sun_path))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"UNIXPATH",
"path too long");
GNUNET_free (unixpath);
+ GNUNET_free (secname);
return NULL;
}
+ GNUNET_free (secname);
dh = GNUNET_new (struct TALER_CRYPTO_CsDenominationHelper);
dh->dkc = dkc;
dh->dkc_cls = dkc_cls;
@@ -201,13 +209,18 @@ handle_mt_avail (struct TALER_CRYPTO_CsDenominationHelper *dh,
}
{
- struct TALER_DenominationPublicKey denom_pub;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub;
struct TALER_CsPubHashP h_cs;
- denom_pub.cipher = TALER_DENOMINATION_CS;
- denom_pub.details.cs_public_key = kan->denom_pub;
+ bsign_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bsign_pub->cipher = GNUNET_CRYPTO_BSA_CS;
+ bsign_pub->rc = 1;
+ bsign_pub->details.cs_public_key = kan->denom_pub;
- TALER_cs_pub_hash (&denom_pub.details.cs_public_key, &h_cs);
+ GNUNET_CRYPTO_hash (&bsign_pub->details.cs_public_key,
+ sizeof (bsign_pub->details.cs_public_key),
+ &bsign_pub->pub_key_hash);
+ h_cs.hash = bsign_pub->pub_key_hash;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received CS key %s (%s)\n",
GNUNET_h2s (&h_cs.hash),
@@ -222,7 +235,7 @@ handle_mt_avail (struct TALER_CRYPTO_CsDenominationHelper *dh,
&kan->secm_sig))
{
GNUNET_break_op (0);
- TALER_denom_pub_free (&denom_pub);
+ GNUNET_CRYPTO_blind_sign_pub_decref (bsign_pub);
return GNUNET_SYSERR;
}
dh->dkc (dh->dkc_cls,
@@ -230,10 +243,10 @@ handle_mt_avail (struct TALER_CRYPTO_CsDenominationHelper *dh,
GNUNET_TIME_timestamp_ntoh (kan->anchor_time),
GNUNET_TIME_relative_ntoh (kan->duration_withdraw),
&h_cs,
- &denom_pub,
+ bsign_pub,
&kan->secm_pub,
&kan->secm_sig);
- TALER_denom_pub_free (&denom_pub);
+ GNUNET_CRYPTO_blind_sign_pub_decref (bsign_pub);
}
return GNUNET_OK;
}
@@ -378,34 +391,19 @@ more:
}
-/**
- * Request helper @a dh to sign @a msg using the public key corresponding to
- * @a h_denom_pub.
- *
- * This operation will block until the signature has been obtained. Should
- * this process receive a signal (that is not ignored) while the operation is
- * pending, the operation will fail. Note that the helper may still believe
- * that it created the signature. Thus, signals may result in a small
- * differences in the signature counters. Retrying in this case may work.
- *
- * @param dh helper process connection
- * @param h_cs hash of the CS public key to use to sign
- * @param blinded_planchet blinded planchet containing c and nonce
- * @param for_melt true if the HKDF for melt should be used
- * @param[out] bs set to the blind signature
- * @return #TALER_EC_NONE on success
- */
-static enum TALER_ErrorCode
-helper_cs_sign (
+enum TALER_ErrorCode
+TALER_CRYPTO_helper_cs_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_BlindedCsPlanchet *blinded_planchet,
+ const struct TALER_CRYPTO_CsSignRequest *req,
bool for_melt,
struct TALER_BlindedDenominationSignature *bs)
{
enum TALER_ErrorCode ec = TALER_EC_INVALID;
+ const struct TALER_CsPubHashP *h_cs = req->h_cs;
- bs->cipher = TALER_DENOMINATION_INVALID;
+ memset (bs,
+ 0,
+ sizeof (*bs));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting signature process\n");
if (GNUNET_OK !=
@@ -419,15 +417,15 @@ helper_cs_sign (
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Requesting signature\n");
{
- char buf[sizeof (struct TALER_CRYPTO_CsSignRequest)];
- struct TALER_CRYPTO_CsSignRequest *sr
- = (struct TALER_CRYPTO_CsSignRequest *) buf;
+ char buf[sizeof (struct TALER_CRYPTO_CsSignRequestMessage)];
+ struct TALER_CRYPTO_CsSignRequestMessage *sr
+ = (struct TALER_CRYPTO_CsSignRequestMessage *) buf;
sr->header.size = htons (sizeof (buf));
sr->header.type = htons (TALER_HELPER_CS_MT_REQ_SIGN);
sr->for_melt = htonl (for_melt ? 1 : 0);
sr->h_cs = *h_cs;
- sr->planchet = *blinded_planchet;
+ sr->message = *req->blinded_planchet;
if (GNUNET_OK !=
TALER_crypto_helper_send_all (dh->sock,
buf,
@@ -493,7 +491,7 @@ more:
switch (ntohs (hdr->type))
{
case TALER_HELPER_CS_MT_RES_SIGNATURE:
- if (msize < sizeof (struct TALER_CRYPTO_SignResponse))
+ if (msize != sizeof (struct TALER_CRYPTO_SignResponse))
{
GNUNET_break_op (0);
do_disconnect (dh);
@@ -510,13 +508,18 @@ more:
{
const struct TALER_CRYPTO_SignResponse *sr =
(const struct TALER_CRYPTO_SignResponse *) buf;
+ struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received signature\n");
ec = TALER_EC_NONE;
finished = true;
- bs->cipher = TALER_DENOMINATION_CS;
- bs->details.blinded_cs_answer = sr->cs_answer;
+ blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ blinded_sig->cipher = GNUNET_CRYPTO_BSA_CS;
+ blinded_sig->rc = 1;
+ blinded_sig->details.blinded_cs_answer.b = ntohl (sr->b);
+ blinded_sig->details.blinded_cs_answer.s_scalar = sr->cs_answer;
+ bs->blinded_sig = blinded_sig;
break;
}
case TALER_HELPER_CS_MT_RES_SIGN_FAILURE:
@@ -533,7 +536,8 @@ more:
ec = (enum TALER_ErrorCode) ntohl (sf->ec);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Signing failed!\n");
+ "Signing failed with status %d!\n",
+ ec);
finished = true;
break;
}
@@ -591,36 +595,6 @@ end:
}
-enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_sign_melt (
- struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_BlindedCsPlanchet *blinded_planchet,
- struct TALER_BlindedDenominationSignature *bs)
-{
- return helper_cs_sign (dh,
- h_cs,
- blinded_planchet,
- true,
- bs);
-}
-
-
-enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_sign_withdraw (
- struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_BlindedCsPlanchet *blinded_planchet,
- struct TALER_BlindedDenominationSignature *bs)
-{
- return helper_cs_sign (dh,
- h_cs,
- blinded_planchet,
- false,
- bs);
-}
-
-
void
TALER_CRYPTO_helper_cs_revoke (
struct TALER_CRYPTO_CsDenominationHelper *dh,
@@ -651,31 +625,15 @@ TALER_CRYPTO_helper_cs_revoke (
}
-/**
- * Ask the helper to derive R using the @a nonce and denomination key
- * associated with @a h_cs.
- *
- * This operation will block until the R has been obtained. Should
- * this process receive a signal (that is not ignored) while the operation is
- * pending, the operation will fail. Note that the helper may still believe
- * that it created the signature. Thus, signals may result in a small
- * differences in the signature counters. Retrying in this case may work.
- *
- * @param dh helper to process connection
- * @param h_cs hash of the CS public key to revoke
- * @param nonce witdhraw nonce
- * @param for_melt true if the HKDF for melt should be used
- * @param[out] crp set to the pair of R values
- * @return set to the error code (or #TALER_EC_NONE on success)
- */
-static enum TALER_ErrorCode
-helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_CsNonce *nonce,
- bool for_melt,
- struct TALER_DenominationCSPublicRPairP *crp)
+enum TALER_ErrorCode
+TALER_CRYPTO_helper_cs_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh,
+ const struct TALER_CRYPTO_CsDeriveRequest *cdr,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP *crp)
{
enum TALER_ErrorCode ec = TALER_EC_INVALID;
+ const struct TALER_CsPubHashP *h_cs = cdr->h_cs;
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce = cdr->nonce;
memset (crp,
0,
@@ -853,32 +811,495 @@ more:
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_r_derive_withdraw (
+TALER_CRYPTO_helper_cs_batch_sign (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *crp)
+ unsigned int reqs_length,
+ const struct TALER_CRYPTO_CsSignRequest reqs[static reqs_length],
+ bool for_melt,
+ struct TALER_BlindedDenominationSignature bss[static reqs_length])
{
- return helper_cs_r_derive (dh,
- h_cs,
- nonce,
- false,
- crp);
+ enum TALER_ErrorCode ec = TALER_EC_INVALID;
+ unsigned int rpos;
+ unsigned int rend;
+ unsigned int wpos;
+
+ memset (bss,
+ 0,
+ sizeof (*bss) * reqs_length);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting signature process\n");
+ if (GNUNET_OK !=
+ try_connect (dh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to helper\n");
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting %u signatures\n",
+ reqs_length);
+ rpos = 0;
+ rend = 0;
+ wpos = 0;
+ while (rpos < reqs_length)
+ {
+ unsigned int mlen = sizeof (struct TALER_CRYPTO_BatchSignRequest);
+
+ while ( (rend < reqs_length) &&
+ (mlen + sizeof (struct TALER_CRYPTO_CsSignRequestMessage)
+ < UINT16_MAX) )
+ {
+ mlen += sizeof (struct TALER_CRYPTO_CsSignRequestMessage);
+ rend++;
+ }
+ {
+ char obuf[mlen] GNUNET_ALIGN;
+ struct TALER_CRYPTO_BatchSignRequest *bsr
+ = (struct TALER_CRYPTO_BatchSignRequest *) obuf;
+ void *wbuf;
+
+ bsr->header.type = htons (TALER_HELPER_CS_MT_REQ_BATCH_SIGN);
+ bsr->header.size = htons (mlen);
+ bsr->batch_size = htonl (rend - rpos);
+ wbuf = &bsr[1];
+ for (unsigned int i = rpos; i<rend; i++)
+ {
+ struct TALER_CRYPTO_CsSignRequestMessage *csm = wbuf;
+ const struct TALER_CRYPTO_CsSignRequest *csr = &reqs[i];
+
+ csm->header.size = htons (sizeof (*csm));
+ csm->header.type = htons (TALER_HELPER_CS_MT_REQ_SIGN);
+ csm->for_melt = htonl (for_melt ? 1 : 0);
+ csm->h_cs = *csr->h_cs;
+ csm->message = *csr->blinded_planchet;
+ wbuf += sizeof (*csm);
+ }
+ GNUNET_assert (wbuf == &obuf[mlen]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending batch request [%u-%u)\n",
+ rpos,
+ rend);
+ if (GNUNET_OK !=
+ TALER_crypto_helper_send_all (dh->sock,
+ obuf,
+ sizeof (obuf)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "send");
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ } /* end of obuf scope */
+ rpos = rend;
+ {
+ char buf[UINT16_MAX];
+ size_t off = 0;
+ const struct GNUNET_MessageHeader *hdr
+ = (const struct GNUNET_MessageHeader *) buf;
+ bool finished = false;
+
+ while (1)
+ {
+ uint16_t msize;
+ ssize_t ret;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Awaiting reply at %u (up to %u)\n",
+ wpos,
+ rend);
+ ret = recv (dh->sock,
+ &buf[off],
+ sizeof (buf) - off,
+ (finished && (0 == off))
+ ? MSG_DONTWAIT
+ : 0);
+ if (ret < 0)
+ {
+ if (EINTR == errno)
+ continue;
+ if (EAGAIN == errno)
+ {
+ GNUNET_assert (finished);
+ GNUNET_assert (0 == off);
+ break;
+ }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "recv");
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ if (0 == ret)
+ {
+ GNUNET_break (0 == off);
+ if (! finished)
+ return TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
+ if (TALER_EC_NONE == ec)
+ break;
+ return ec;
+ }
+ off += ret;
+more:
+ if (off < sizeof (struct GNUNET_MessageHeader))
+ continue;
+ msize = ntohs (hdr->size);
+ if (off < msize)
+ continue;
+ switch (ntohs (hdr->type))
+ {
+ case TALER_HELPER_CS_MT_RES_SIGNATURE:
+ if (msize != sizeof (struct TALER_CRYPTO_SignResponse))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ if (finished)
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_SignResponse *sr =
+ (const struct TALER_CRYPTO_SignResponse *) buf;
+ struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u signature\n",
+ wpos);
+ blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ blinded_sig->cipher = GNUNET_CRYPTO_BSA_CS;
+ blinded_sig->rc = 1;
+ blinded_sig->details.blinded_cs_answer.b = ntohl (sr->b);
+ blinded_sig->details.blinded_cs_answer.s_scalar = sr->cs_answer;
+
+ bss[wpos].blinded_sig = blinded_sig;
+ wpos++;
+ if (wpos == rend)
+ {
+ if (TALER_EC_INVALID == ec)
+ ec = TALER_EC_NONE;
+ finished = true;
+ }
+ break;
+ }
+
+ case TALER_HELPER_CS_MT_RES_SIGN_FAILURE:
+ if (msize != sizeof (struct TALER_CRYPTO_SignFailure))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_SignFailure *sf =
+ (const struct TALER_CRYPTO_SignFailure *) buf;
+
+ ec = (enum TALER_ErrorCode) ntohl (sf->ec);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Signing %u failed with status %d!\n",
+ wpos,
+ ec);
+ wpos++;
+ if (wpos == rend)
+ {
+ finished = true;
+ }
+ break;
+ }
+ case TALER_HELPER_CS_MT_AVAIL:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received new key!\n");
+ if (GNUNET_OK !=
+ handle_mt_avail (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_CS_MT_PURGE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received revocation!\n");
+ if (GNUNET_OK !=
+ handle_mt_purge (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_CS_SYNCED:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Synchronized add odd time with CS helper!\n");
+ dh->synced = true;
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Received unexpected message of type %u\n",
+ ntohs (hdr->type));
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ memmove (buf,
+ &buf[msize],
+ off - msize);
+ off -= msize;
+ goto more;
+ } /* while(1) */
+ } /* scope */
+ } /* while (rpos < cdrs_length) */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Existing with %u signatures and status %d\n",
+ wpos,
+ ec);
+ return ec;
}
enum TALER_ErrorCode
-TALER_CRYPTO_helper_cs_r_derive_melt (
+TALER_CRYPTO_helper_cs_r_batch_derive (
struct TALER_CRYPTO_CsDenominationHelper *dh,
- const struct TALER_CsPubHashP *h_cs,
- const struct TALER_CsNonce *nonce,
- struct TALER_DenominationCSPublicRPairP *crp)
+ unsigned int cdrs_length,
+ const struct TALER_CRYPTO_CsDeriveRequest cdrs[static cdrs_length],
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP crps[static cdrs_length])
{
- return helper_cs_r_derive (dh,
- h_cs,
- nonce,
- true,
- crp);
+ enum TALER_ErrorCode ec = TALER_EC_INVALID;
+ unsigned int rpos;
+ unsigned int rend;
+ unsigned int wpos;
+
+ memset (crps,
+ 0,
+ sizeof (*crps) * cdrs_length);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting R derivation process\n");
+ if (GNUNET_OK !=
+ try_connect (dh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to helper\n");
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting %u R pairs\n",
+ cdrs_length);
+ rpos = 0;
+ rend = 0;
+ wpos = 0;
+ while (rpos < cdrs_length)
+ {
+ unsigned int mlen = sizeof (struct TALER_CRYPTO_BatchDeriveRequest);
+
+ while ( (rend < cdrs_length) &&
+ (mlen + sizeof (struct TALER_CRYPTO_CsRDeriveRequest)
+ < UINT16_MAX) )
+ {
+ mlen += sizeof (struct TALER_CRYPTO_CsRDeriveRequest);
+ rend++;
+ }
+ {
+ char obuf[mlen] GNUNET_ALIGN;
+ struct TALER_CRYPTO_BatchDeriveRequest *bdr
+ = (struct TALER_CRYPTO_BatchDeriveRequest *) obuf;
+ void *wbuf;
+
+ bdr->header.type = htons (TALER_HELPER_CS_MT_REQ_BATCH_RDERIVE);
+ bdr->header.size = htons (mlen);
+ bdr->batch_size = htonl (rend - rpos);
+ wbuf = &bdr[1];
+ for (unsigned int i = rpos; i<rend; i++)
+ {
+ struct TALER_CRYPTO_CsRDeriveRequest *rdr = wbuf;
+ const struct TALER_CRYPTO_CsDeriveRequest *cdr = &cdrs[i];
+
+ rdr->header.size = htons (sizeof (*rdr));
+ rdr->header.type = htons (TALER_HELPER_CS_MT_REQ_RDERIVE);
+ rdr->for_melt = htonl (for_melt ? 1 : 0);
+ rdr->h_cs = *cdr->h_cs;
+ rdr->nonce = *cdr->nonce;
+ wbuf += sizeof (*rdr);
+ }
+ GNUNET_assert (wbuf == &obuf[mlen]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending batch request [%u-%u)\n",
+ rpos,
+ rend);
+ if (GNUNET_OK !=
+ TALER_crypto_helper_send_all (dh->sock,
+ obuf,
+ sizeof (obuf)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "send");
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ } /* end of obuf scope */
+ rpos = rend;
+ {
+ char buf[UINT16_MAX];
+ size_t off = 0;
+ const struct GNUNET_MessageHeader *hdr
+ = (const struct GNUNET_MessageHeader *) buf;
+ bool finished = false;
+
+ while (1)
+ {
+ uint16_t msize;
+ ssize_t ret;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Awaiting reply at %u (up to %u)\n",
+ wpos,
+ rend);
+ ret = recv (dh->sock,
+ &buf[off],
+ sizeof (buf) - off,
+ (finished && (0 == off))
+ ? MSG_DONTWAIT
+ : 0);
+ if (ret < 0)
+ {
+ if (EINTR == errno)
+ continue;
+ if (EAGAIN == errno)
+ {
+ GNUNET_assert (finished);
+ GNUNET_assert (0 == off);
+ break;
+ }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "recv");
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ if (0 == ret)
+ {
+ GNUNET_break (0 == off);
+ if (! finished)
+ return TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
+ if (TALER_EC_NONE == ec)
+ break;
+ return ec;
+ }
+ off += ret;
+more:
+ if (off < sizeof (struct GNUNET_MessageHeader))
+ continue;
+ msize = ntohs (hdr->size);
+ if (off < msize)
+ continue;
+ switch (ntohs (hdr->type))
+ {
+ case TALER_HELPER_CS_MT_RES_RDERIVE:
+ if (msize != sizeof (struct TALER_CRYPTO_RDeriveResponse))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ if (finished)
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_RDeriveResponse *rdr =
+ (const struct TALER_CRYPTO_RDeriveResponse *) buf;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u R pair\n",
+ wpos);
+ crps[wpos] = rdr->r_pub;
+ wpos++;
+ if (wpos == rend)
+ {
+ if (TALER_EC_INVALID == ec)
+ ec = TALER_EC_NONE;
+ finished = true;
+ }
+ break;
+ }
+ case TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE:
+ if (msize != sizeof (struct TALER_CRYPTO_RDeriveFailure))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_RDeriveFailure *rdf =
+ (const struct TALER_CRYPTO_RDeriveFailure *) buf;
+
+ ec = (enum TALER_ErrorCode) ntohl (rdf->ec);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "R derivation %u failed with status %d!\n",
+ wpos,
+ ec);
+ wpos++;
+ if (wpos == rend)
+ {
+ finished = true;
+ }
+ break;
+ }
+ case TALER_HELPER_CS_MT_AVAIL:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received new key!\n");
+ if (GNUNET_OK !=
+ handle_mt_avail (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_CS_MT_PURGE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received revocation!\n");
+ if (GNUNET_OK !=
+ handle_mt_purge (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_CS_SYNCED:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Synchronized add odd time with CS helper!\n");
+ dh->synced = true;
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Received unexpected message of type %u\n",
+ ntohs (hdr->type));
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ memmove (buf,
+ &buf[msize],
+ off - msize);
+ off -= msize;
+ goto more;
+ } /* while(1) */
+ } /* scope */
+ } /* while (rpos < cdrs_length) */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Existing with %u signatures and status %d\n",
+ wpos,
+ ec);
+ return ec;
}
diff --git a/src/util/crypto_helper_esign.c b/src/util/crypto_helper_esign.c
index 5a9ad74e2..e044d31d1 100644
--- a/src/util/crypto_helper_esign.c
+++ b/src/util/crypto_helper_esign.c
@@ -111,21 +111,28 @@ try_connect (struct TALER_CRYPTO_ExchangeSignHelper *esh)
struct TALER_CRYPTO_ExchangeSignHelper *
TALER_CRYPTO_helper_esign_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_ExchangeKeyStatusCallback ekc,
void *ekc_cls)
{
struct TALER_CRYPTO_ExchangeSignHelper *esh;
char *unixpath;
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-eddsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-eddsa",
+ secname,
"UNIXPATH",
&unixpath))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"UNIXPATH");
+ GNUNET_free (secname);
return NULL;
}
/* we use >= here because we want the sun_path to always
@@ -133,12 +140,14 @@ TALER_CRYPTO_helper_esign_connect (
if (strlen (unixpath) >= sizeof (esh->sa.sun_path))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"UNIXPATH",
"path too long");
GNUNET_free (unixpath);
+ GNUNET_free (secname);
return NULL;
}
+ GNUNET_free (secname);
esh = GNUNET_new (struct TALER_CRYPTO_ExchangeSignHelper);
esh->ekc = ekc;
esh->ekc_cls = ekc_cls;
@@ -357,9 +366,9 @@ TALER_CRYPTO_helper_esign_sign_ (
sr->header.size = htons (sizeof (buf));
sr->header.type = htons (TALER_HELPER_EDDSA_MT_REQ_SIGN);
sr->reserved = htonl (0);
- memcpy (&sr->purpose,
- purpose,
- purpose_size);
+ GNUNET_memcpy (&sr->purpose,
+ purpose,
+ purpose_size);
if (GNUNET_OK !=
TALER_crypto_helper_send_all (esh->sock,
buf,
diff --git a/src/util/crypto_helper_rsa.c b/src/util/crypto_helper_rsa.c
index 9491b07c9..e23e12a88 100644
--- a/src/util/crypto_helper_rsa.c
+++ b/src/util/crypto_helper_rsa.c
@@ -113,21 +113,28 @@ try_connect (struct TALER_CRYPTO_RsaDenominationHelper *dh)
struct TALER_CRYPTO_RsaDenominationHelper *
TALER_CRYPTO_helper_rsa_connect (
const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *section,
TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc,
void *dkc_cls)
{
struct TALER_CRYPTO_RsaDenominationHelper *dh;
char *unixpath;
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-rsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-rsa",
+ secname,
"UNIXPATH",
&unixpath))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ secname,
"UNIXPATH");
+ GNUNET_free (secname);
return NULL;
}
/* we use >= here because we want the sun_path to always
@@ -135,12 +142,14 @@ TALER_CRYPTO_helper_rsa_connect (
if (strlen (unixpath) >= sizeof (dh->sa.sun_path))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ secname,
"UNIXPATH",
"path too long");
GNUNET_free (unixpath);
+ GNUNET_free (secname);
return NULL;
}
+ GNUNET_free (secname);
dh = GNUNET_new (struct TALER_CRYPTO_RsaDenominationHelper);
dh->dkc = dkc;
dh->dkc_cls = dkc_cls;
@@ -203,23 +212,27 @@ handle_mt_avail (struct TALER_CRYPTO_RsaDenominationHelper *dh,
}
{
- struct TALER_DenominationPublicKey denom_pub;
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub;
struct TALER_RsaPubHashP h_rsa;
- denom_pub.cipher = TALER_DENOMINATION_RSA;
- denom_pub.details.rsa_public_key
+ bs_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
+ bs_pub->cipher = GNUNET_CRYPTO_BSA_RSA;
+ bs_pub->details.rsa_public_key
= GNUNET_CRYPTO_rsa_public_key_decode (buf,
ntohs (kan->pub_size));
- if (NULL == denom_pub.details.rsa_public_key)
+ if (NULL == bs_pub->details.rsa_public_key)
{
GNUNET_break_op (0);
+ GNUNET_free (bs_pub);
return GNUNET_SYSERR;
}
- GNUNET_CRYPTO_rsa_public_key_hash (denom_pub.details.rsa_public_key,
- &h_rsa.hash);
+ bs_pub->rc = 1;
+ GNUNET_CRYPTO_rsa_public_key_hash (bs_pub->details.rsa_public_key,
+ &bs_pub->pub_key_hash);
+ h_rsa.hash = bs_pub->pub_key_hash;
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received RSA key %s (%s)\n",
- GNUNET_h2s (&h_rsa.hash),
+ GNUNET_h2s (&bs_pub->pub_key_hash),
section_name);
if (GNUNET_OK !=
TALER_exchange_secmod_rsa_verify (
@@ -231,7 +244,7 @@ handle_mt_avail (struct TALER_CRYPTO_RsaDenominationHelper *dh,
&kan->secm_sig))
{
GNUNET_break_op (0);
- TALER_denom_pub_free (&denom_pub);
+ GNUNET_CRYPTO_blind_sign_pub_decref (bs_pub);
return GNUNET_SYSERR;
}
dh->dkc (dh->dkc_cls,
@@ -239,10 +252,10 @@ handle_mt_avail (struct TALER_CRYPTO_RsaDenominationHelper *dh,
GNUNET_TIME_timestamp_ntoh (kan->anchor_time),
GNUNET_TIME_relative_ntoh (kan->duration_withdraw),
&h_rsa,
- &denom_pub,
+ bs_pub,
&kan->secm_pub,
&kan->secm_sig);
- TALER_denom_pub_free (&denom_pub);
+ GNUNET_CRYPTO_blind_sign_pub_decref (bs_pub);
}
return GNUNET_OK;
}
@@ -395,7 +408,9 @@ TALER_CRYPTO_helper_rsa_sign (
{
enum TALER_ErrorCode ec = TALER_EC_INVALID;
- bs->cipher = TALER_DENOMINATION_INVALID;
+ memset (bs,
+ 0,
+ sizeof (*bs));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting signature process\n");
if (GNUNET_OK !=
@@ -417,9 +432,9 @@ TALER_CRYPTO_helper_rsa_sign (
sr->header.type = htons (TALER_HELPER_RSA_MT_REQ_SIGN);
sr->reserved = htonl (0);
sr->h_rsa = *rsr->h_rsa;
- memcpy (&sr[1],
- rsr->msg,
- rsr->msg_size);
+ GNUNET_memcpy (&sr[1],
+ rsr->msg,
+ rsr->msg_size);
if (GNUNET_OK !=
TALER_crypto_helper_send_all (dh->sock,
buf,
@@ -503,6 +518,7 @@ more:
const struct TALER_CRYPTO_SignResponse *sr =
(const struct TALER_CRYPTO_SignResponse *) buf;
struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
+ struct GNUNET_CRYPTO_BlindedSignature *blind_sig;
rsa_signature = GNUNET_CRYPTO_rsa_signature_decode (
&sr[1],
@@ -518,8 +534,11 @@ more:
"Received signature\n");
ec = TALER_EC_NONE;
finished = true;
- bs->cipher = TALER_DENOMINATION_RSA;
- bs->details.blinded_rsa_signature = rsa_signature;
+ blind_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ blind_sig->cipher = GNUNET_CRYPTO_BSA_RSA;
+ blind_sig->rc = 1;
+ blind_sig->details.blinded_rsa_signature = rsa_signature;
+ bs->blinded_sig = blind_sig;
break;
}
case TALER_HELPER_RSA_MT_RES_SIGN_FAILURE:
@@ -597,12 +616,260 @@ end:
enum TALER_ErrorCode
TALER_CRYPTO_helper_rsa_batch_sign (
struct TALER_CRYPTO_RsaDenominationHelper *dh,
- const struct TALER_CRYPTO_RsaSignRequest *rsrs,
unsigned int rsrs_length,
- struct TALER_BlindedDenominationSignature *bss)
+ const struct TALER_CRYPTO_RsaSignRequest rsrs[static rsrs_length],
+ struct TALER_BlindedDenominationSignature bss[static rsrs_length])
{
- GNUNET_break (0);
- return -1; /* FIXME: NOT IMPLEMENTED! */
+ enum TALER_ErrorCode ec = TALER_EC_INVALID;
+ unsigned int rpos;
+ unsigned int rend;
+ unsigned int wpos;
+
+ memset (bss,
+ 0,
+ sizeof (*bss) * rsrs_length);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting signature process\n");
+ if (GNUNET_OK !=
+ try_connect (dh))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to connect to helper\n");
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Requesting %u signatures\n",
+ rsrs_length);
+ rpos = 0;
+ rend = 0;
+ wpos = 0;
+ while (rpos < rsrs_length)
+ {
+ unsigned int mlen = sizeof (struct TALER_CRYPTO_BatchSignRequest);
+
+ while ( (rend < rsrs_length) &&
+ (mlen
+ + sizeof (struct TALER_CRYPTO_SignRequest)
+ + rsrs[rend].msg_size < UINT16_MAX) )
+ {
+ mlen += sizeof (struct TALER_CRYPTO_SignRequest) + rsrs[rend].msg_size;
+ rend++;
+ }
+ {
+ char obuf[mlen] GNUNET_ALIGN;
+ struct TALER_CRYPTO_BatchSignRequest *bsr
+ = (struct TALER_CRYPTO_BatchSignRequest *) obuf;
+ void *wbuf;
+
+ bsr->header.type = htons (TALER_HELPER_RSA_MT_REQ_BATCH_SIGN);
+ bsr->header.size = htons (mlen);
+ bsr->batch_size = htonl (rend - rpos);
+ wbuf = &bsr[1];
+ for (unsigned int i = rpos; i<rend; i++)
+ {
+ struct TALER_CRYPTO_SignRequest *sr = wbuf;
+ const struct TALER_CRYPTO_RsaSignRequest *rsr = &rsrs[i];
+
+ sr->header.type = htons (TALER_HELPER_RSA_MT_REQ_SIGN);
+ sr->header.size = htons (sizeof (*sr) + rsr->msg_size);
+ sr->reserved = htonl (0);
+ sr->h_rsa = *rsr->h_rsa;
+ GNUNET_memcpy (&sr[1],
+ rsr->msg,
+ rsr->msg_size);
+ wbuf += sizeof (*sr) + rsr->msg_size;
+ }
+ GNUNET_assert (wbuf == &obuf[mlen]);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending batch request [%u-%u)\n",
+ rpos,
+ rend);
+ if (GNUNET_OK !=
+ TALER_crypto_helper_send_all (dh->sock,
+ obuf,
+ sizeof (obuf)))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "send");
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ }
+ }
+ rpos = rend;
+ {
+ char buf[UINT16_MAX];
+ size_t off = 0;
+ const struct GNUNET_MessageHeader *hdr
+ = (const struct GNUNET_MessageHeader *) buf;
+ bool finished = false;
+
+ while (1)
+ {
+ uint16_t msize;
+ ssize_t ret;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Awaiting reply at %u (up to %u)\n",
+ wpos,
+ rend);
+ ret = recv (dh->sock,
+ &buf[off],
+ sizeof (buf) - off,
+ (finished && (0 == off))
+ ? MSG_DONTWAIT
+ : 0);
+ if (ret < 0)
+ {
+ if (EINTR == errno)
+ continue;
+ if (EAGAIN == errno)
+ {
+ GNUNET_assert (finished);
+ GNUNET_assert (0 == off);
+ break;
+ }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "recv");
+ do_disconnect (dh);
+ ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
+ break;
+ }
+ if (0 == ret)
+ {
+ GNUNET_break (0 == off);
+ if (! finished)
+ ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
+ if (TALER_EC_NONE == ec)
+ break;
+ return ec;
+ }
+ off += ret;
+more:
+ if (off < sizeof (struct GNUNET_MessageHeader))
+ continue;
+ msize = ntohs (hdr->size);
+ if (off < msize)
+ continue;
+ switch (ntohs (hdr->type))
+ {
+ case TALER_HELPER_RSA_MT_RES_SIGNATURE:
+ if (msize < sizeof (struct TALER_CRYPTO_SignResponse))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ if (finished)
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_SignResponse *sr =
+ (const struct TALER_CRYPTO_SignResponse *) buf;
+ struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
+ struct GNUNET_CRYPTO_BlindedSignature *blind_sig;
+
+ rsa_signature = GNUNET_CRYPTO_rsa_signature_decode (
+ &sr[1],
+ msize - sizeof (*sr));
+ if (NULL == rsa_signature)
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %u signature\n",
+ wpos);
+ blind_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
+ blind_sig->cipher = GNUNET_CRYPTO_BSA_RSA;
+ blind_sig->rc = 1;
+ blind_sig->details.blinded_rsa_signature = rsa_signature;
+ bss[wpos].blinded_sig = blind_sig;
+ wpos++;
+ if (wpos == rend)
+ {
+ if (TALER_EC_INVALID == ec)
+ ec = TALER_EC_NONE;
+ finished = true;
+ }
+ break;
+ }
+ case TALER_HELPER_RSA_MT_RES_SIGN_FAILURE:
+ if (msize != sizeof (struct TALER_CRYPTO_SignFailure))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ {
+ const struct TALER_CRYPTO_SignFailure *sf =
+ (const struct TALER_CRYPTO_SignFailure *) buf;
+
+ ec = (enum TALER_ErrorCode) ntohl (sf->ec);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Signing %u failed with status %d!\n",
+ wpos,
+ ec);
+ wpos++;
+ if (wpos == rend)
+ {
+ finished = true;
+ }
+ break;
+ }
+ case TALER_HELPER_RSA_MT_AVAIL:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received new key!\n");
+ if (GNUNET_OK !=
+ handle_mt_avail (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_RSA_MT_PURGE:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received revocation!\n");
+ if (GNUNET_OK !=
+ handle_mt_purge (dh,
+ hdr))
+ {
+ GNUNET_break_op (0);
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ break; /* while(1) loop ensures we recvfrom() again */
+ case TALER_HELPER_RSA_SYNCED:
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Synchronized add odd time with RSA helper!\n");
+ dh->synced = true;
+ break;
+ default:
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Received unexpected message of type %u\n",
+ ntohs (hdr->type));
+ do_disconnect (dh);
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
+ }
+ memmove (buf,
+ &buf[msize],
+ off - msize);
+ off -= msize;
+ goto more;
+ } /* while(1) */
+ } /* scope */
+ } /* while (rpos < rsrs_length) */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Existing with %u signatures and status %d\n",
+ wpos,
+ ec);
+ return ec;
}
diff --git a/src/util/currencies.conf b/src/util/currencies.conf
new file mode 100644
index 000000000..0fa831bf3
--- /dev/null
+++ b/src/util/currencies.conf
@@ -0,0 +1,89 @@
+[currency-euro]
+ENABLED = YES
+name = "Euro"
+code = "EUR"
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"€"}
+
+[currency-swiss-francs]
+ENABLED = YES
+name = "Swiss Francs"
+code = "CHF"
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"Fr.","-2":"Rp."}
+
+[currency-forint]
+ENABLED = NO
+name = "Hungarian Forint"
+code = "HUF"
+fractional_input_digits = 0
+fractional_normal_digits = 0
+fractional_trailing_zero_digits = 0
+alt_unit_names = {"0":"Ft"}
+
+[currency-us-dollar]
+ENABLED = NO
+name = "US Dollar"
+code = "USD"
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"$"}
+
+[currency-kudos]
+ENABLED = YES
+name = "Kudos (Taler Demonstrator)"
+code = "KUDOS"
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"ク"}
+
+[currency-testkudos]
+ENABLED = YES
+name = "Test-kudos (Taler Demonstrator)"
+code = "TESTKUDOS"
+fractional_input_digits = 2
+fractional_normal_digits = 2
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"テ","3":"kテ","-3":"mテ"}
+
+[currency-japanese-yen]
+ENABLED = NO
+name = "Japanese Yen"
+code = "JPY"
+fractional_input_digits = 2
+fractional_normal_digits = 0
+fractional_trailing_zero_digits = 2
+alt_unit_names = {"0":"¥"}
+
+[currency-bitcoin-mainnet]
+ENABLED = NO
+name = "Bitcoin (Mainnet)"
+code = "BITCOINBTC"
+fractional_input_digits = 8
+fractional_normal_digits = 3
+fractional_trailing_zero_digits = 0
+alt_unit_names = {"0":"BTC","-3":"mBTC"}
+
+[currency-ethereum]
+ENABLED = NO
+name = "WAI-ETHER (Ethereum)"
+code = "EthereumWAI"
+fractional_input_digits = 0
+fractional_normal_digits = 0
+fractional_trailing_zero_digits = 0
+alt_unit_names = {"0":"WAI","3":"KWAI","6":"MWAI","9":"GWAI","12":"Szabo","15":"Finney","18":"Ether","21":"KEther","24":"MEther"}
+
+[currency-netzbon]
+ENABLED=YES
+name=NetzBon
+code=NETZBON
+fractional_input_digits=2
+fractional_normal_digits=2
+fractional_trailing_zero_digits=2
+alt_unit_names = {"0":"NETZBON"}
diff --git a/src/util/denom.c b/src/util/denom.c
index c1c3cdf5a..cb232c4a3 100644
--- a/src/util/denom.c
+++ b/src/util/denom.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021, 2022 Taler Systems SA
+ Copyright (C) 2021, 2022, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -25,60 +25,27 @@
enum GNUNET_GenericReturnValue
TALER_denom_priv_create (struct TALER_DenominationPrivateKey *denom_priv,
struct TALER_DenominationPublicKey *denom_pub,
- enum TALER_DenominationCipher cipher,
+ enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
...)
{
- memset (denom_priv,
- 0,
- sizeof (*denom_priv));
+ enum GNUNET_GenericReturnValue ret;
+ va_list ap;
+
memset (denom_pub,
0,
sizeof (*denom_pub));
-
- switch (cipher)
- {
- case TALER_DENOMINATION_INVALID:
- GNUNET_break (0);
- return GNUNET_SYSERR;
- case TALER_DENOMINATION_RSA:
- {
- va_list ap;
- unsigned int bits;
-
- va_start (ap, cipher);
- bits = va_arg (ap, unsigned int);
- va_end (ap);
- if (bits < 512)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- denom_priv->details.rsa_private_key
- = GNUNET_CRYPTO_rsa_private_key_create (bits);
- }
- if (NULL == denom_priv->details.rsa_private_key)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- denom_pub->details.rsa_public_key
- = GNUNET_CRYPTO_rsa_private_key_get_public (
- denom_priv->details.rsa_private_key);
- denom_priv->cipher = TALER_DENOMINATION_RSA;
- denom_pub->cipher = TALER_DENOMINATION_RSA;
- return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- GNUNET_CRYPTO_cs_private_key_generate (&denom_priv->details.cs_private_key);
- GNUNET_CRYPTO_cs_private_key_get_public (
- &denom_priv->details.cs_private_key,
- &denom_pub->details.cs_public_key);
- denom_priv->cipher = TALER_DENOMINATION_CS;
- denom_pub->cipher = TALER_DENOMINATION_CS;
- return GNUNET_OK;
- default:
- GNUNET_break (0);
- }
- return GNUNET_SYSERR;
+ memset (denom_priv,
+ 0,
+ sizeof (*denom_priv));
+ va_start (ap,
+ cipher);
+ ret = GNUNET_CRYPTO_blind_sign_keys_create_va (
+ &denom_priv->bsign_priv_key,
+ &denom_pub->bsign_pub_key,
+ cipher,
+ ap);
+ va_end (ap);
+ return ret;
}
@@ -88,57 +55,13 @@ TALER_denom_sign_blinded (struct TALER_BlindedDenominationSignature *denom_sig,
bool for_melt,
const struct TALER_BlindedPlanchet *blinded_planchet)
{
- memset (denom_sig,
- 0,
- sizeof (*denom_sig));
- if (blinded_planchet->cipher != denom_priv->cipher)
- {
- GNUNET_break (0);
+ denom_sig->blinded_sig
+ = GNUNET_CRYPTO_blind_sign (denom_priv->bsign_priv_key,
+ for_melt ? "rm" : "rw",
+ blinded_planchet->blinded_message);
+ if (NULL == denom_sig->blinded_sig)
return GNUNET_SYSERR;
- }
- switch (denom_priv->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- GNUNET_break (0);
- return GNUNET_SYSERR;
- case TALER_DENOMINATION_RSA:
- denom_sig->details.blinded_rsa_signature
- = GNUNET_CRYPTO_rsa_sign_blinded (
- denom_priv->details.rsa_private_key,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size);
- if (NULL == denom_sig->details.blinded_rsa_signature)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- denom_sig->cipher = TALER_DENOMINATION_RSA;
- return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- {
- struct GNUNET_CRYPTO_CsRSecret r[2];
-
- GNUNET_CRYPTO_cs_r_derive (
- &blinded_planchet->details.cs_blinded_planchet.nonce.nonce,
- for_melt ? "rm" : "rw",
- &denom_priv->details.cs_private_key,
- r);
- denom_sig->details.blinded_cs_answer.b =
- GNUNET_CRYPTO_cs_sign_derive (&denom_priv->details.cs_private_key,
- r,
- blinded_planchet->details.
- cs_blinded_planchet.c,
- &blinded_planchet->details.
- cs_blinded_planchet.nonce.nonce,
- &denom_sig->details.blinded_cs_answer.
- s_scalar);
- denom_sig->cipher = TALER_DENOMINATION_CS;
- }
- return GNUNET_OK;
- default:
- GNUNET_break (0);
- }
- return GNUNET_SYSERR;
+ return GNUNET_OK;
}
@@ -146,82 +69,24 @@ enum GNUNET_GenericReturnValue
TALER_denom_sig_unblind (
struct TALER_DenominationSignature *denom_sig,
const struct TALER_BlindedDenominationSignature *bdenom_sig,
- const union TALER_DenominationBlindingKeyP *bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *bks,
const struct TALER_CoinPubHashP *c_hash,
const struct TALER_ExchangeWithdrawValues *alg_values,
const struct TALER_DenominationPublicKey *denom_pub)
{
- if (bdenom_sig->cipher != denom_pub->cipher)
+ denom_sig->unblinded_sig
+ = GNUNET_CRYPTO_blind_sig_unblind (bdenom_sig->blinded_sig,
+ bks,
+ c_hash,
+ sizeof (*c_hash),
+ alg_values->blinding_inputs,
+ denom_pub->bsign_pub_key);
+ if (NULL == denom_sig->unblinded_sig)
{
- GNUNET_break (0);
+ GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- switch (denom_pub->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- GNUNET_break (0);
- return GNUNET_SYSERR;
- case TALER_DENOMINATION_RSA:
- denom_sig->details.rsa_signature
- = GNUNET_CRYPTO_rsa_unblind (
- bdenom_sig->details.blinded_rsa_signature,
- &bks->rsa_bks,
- denom_pub->details.rsa_public_key);
- if (NULL == denom_sig->details.rsa_signature)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- denom_sig->cipher = TALER_DENOMINATION_RSA;
- return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- {
- struct GNUNET_CRYPTO_CsBlindingSecret bs[2];
- struct GNUNET_CRYPTO_CsC c[2];
- struct TALER_DenominationCSPublicRPairP r_pub_blind;
-
- GNUNET_CRYPTO_cs_blinding_secrets_derive (&bks->nonce,
- bs);
- GNUNET_CRYPTO_cs_calc_blinded_c (
- bs,
- alg_values->details.cs_values.r_pub,
- &denom_pub->details.cs_public_key,
- &c_hash->hash,
- sizeof(struct GNUNET_HashCode),
- c,
- r_pub_blind.r_pub);
- denom_sig->details.cs_signature.r_point
- = r_pub_blind.r_pub[bdenom_sig->details.blinded_cs_answer.b];
- GNUNET_CRYPTO_cs_unblind (&bdenom_sig->details.blinded_cs_answer.s_scalar,
- &bs[bdenom_sig->details.blinded_cs_answer.b],
- &denom_sig->details.cs_signature.s_scalar);
- denom_sig->cipher = TALER_DENOMINATION_CS;
- return GNUNET_OK;
- }
- default:
- GNUNET_break (0);
- }
- return GNUNET_SYSERR;
-}
-
-
-void
-TALER_rsa_pub_hash (const struct GNUNET_CRYPTO_RsaPublicKey *rsa,
- struct TALER_RsaPubHashP *h_rsa)
-{
- GNUNET_CRYPTO_rsa_public_key_hash (rsa,
- &h_rsa->hash);
-
-}
-
-
-void
-TALER_cs_pub_hash (const struct GNUNET_CRYPTO_CsPublicKey *cs,
- struct TALER_CsPubHashP *h_cs)
-{
- GNUNET_CRYPTO_hash (cs,
- sizeof(*cs),
- &h_cs->hash);
+ return GNUNET_OK;
}
@@ -229,9 +94,11 @@ void
TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub,
struct TALER_DenominationHashP *denom_hash)
{
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bsp
+ = denom_pub->bsign_pub_key;
uint32_t opt[2] = {
htonl (denom_pub->age_mask.bits),
- htonl ((uint32_t) denom_pub->cipher)
+ htonl ((uint32_t) bsp->cipher)
};
struct GNUNET_HashContext *hc;
@@ -239,15 +106,15 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub,
GNUNET_CRYPTO_hash_context_read (hc,
opt,
sizeof (opt));
- switch (denom_pub->cipher)
+ switch (bsp->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
{
void *buf;
size_t blen;
blen = GNUNET_CRYPTO_rsa_public_key_encode (
- denom_pub->details.rsa_public_key,
+ bsp->details.rsa_public_key,
&buf);
GNUNET_CRYPTO_hash_context_read (hc,
buf,
@@ -255,10 +122,10 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub,
GNUNET_free (buf);
}
break;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
GNUNET_CRYPTO_hash_context_read (hc,
- &denom_pub->details.cs_public_key,
- sizeof(denom_pub->details.cs_public_key));
+ &bsp->details.cs_public_key,
+ sizeof(bsp->details.cs_public_key));
break;
default:
GNUNET_assert (0);
@@ -268,37 +135,24 @@ TALER_denom_pub_hash (const struct TALER_DenominationPublicKey *denom_pub,
}
-void
-TALER_denom_priv_to_pub (const struct TALER_DenominationPrivateKey *denom_priv,
- const struct TALER_AgeMask age_mask,
- struct TALER_DenominationPublicKey *denom_pub)
+const struct TALER_ExchangeWithdrawValues *
+TALER_denom_ewv_rsa_singleton ()
{
- switch (denom_priv->cipher)
- {
- case TALER_DENOMINATION_RSA:
- denom_pub->cipher = TALER_DENOMINATION_RSA;
- denom_pub->age_mask = age_mask;
- denom_pub->details.rsa_public_key
- = GNUNET_CRYPTO_rsa_private_key_get_public (
- denom_priv->details.rsa_private_key);
- return;
- case TALER_DENOMINATION_CS:
- denom_pub->cipher = TALER_DENOMINATION_CS;
- denom_pub->age_mask = age_mask;
- GNUNET_CRYPTO_cs_private_key_get_public (
- &denom_priv->details.cs_private_key,
- &denom_pub->details.cs_public_key);
- return;
- default:
- GNUNET_assert (0);
- }
+ static struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA
+ };
+ static struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+ return &alg_values;
}
enum GNUNET_GenericReturnValue
TALER_denom_blind (
const struct TALER_DenominationPublicKey *dk,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
+ const union GNUNET_CRYPTO_BlindSessionNonce *nonce,
const struct TALER_AgeCommitmentHash *ach,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_ExchangeWithdrawValues *alg_values,
@@ -308,44 +162,16 @@ TALER_denom_blind (
TALER_coin_pub_hash (coin_pub,
ach,
c_hash);
- switch (dk->cipher)
- {
- case TALER_DENOMINATION_RSA:
- blinded_planchet->cipher = dk->cipher;
- if (GNUNET_YES !=
- GNUNET_CRYPTO_rsa_blind (
- &c_hash->hash,
- &coin_bks->rsa_bks,
- dk->details.rsa_public_key,
- &blinded_planchet->details.rsa_blinded_planchet.blinded_msg,
- &blinded_planchet->details.rsa_blinded_planchet.blinded_msg_size))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- return GNUNET_OK;
- case TALER_DENOMINATION_CS:
- {
- struct TALER_DenominationCSPublicRPairP blinded_r_pub;
- struct GNUNET_CRYPTO_CsBlindingSecret bs[2];
-
- blinded_planchet->cipher = TALER_DENOMINATION_CS;
- GNUNET_CRYPTO_cs_blinding_secrets_derive (&coin_bks->nonce,
- bs);
- GNUNET_CRYPTO_cs_calc_blinded_c (
- bs,
- alg_values->details.cs_values.r_pub,
- &dk->details.cs_public_key,
- c_hash,
- sizeof(*c_hash),
- blinded_planchet->details.cs_blinded_planchet.c,
- blinded_r_pub.r_pub);
- return GNUNET_OK;
- }
- default:
- GNUNET_break (0);
+ blinded_planchet->blinded_message
+ = GNUNET_CRYPTO_message_blind_to_sign (dk->bsign_pub_key,
+ coin_bks,
+ nonce,
+ c_hash,
+ sizeof (*c_hash),
+ alg_values->blinding_inputs);
+ if (NULL == blinded_planchet->blinded_message)
return GNUNET_SYSERR;
- }
+ return GNUNET_OK;
}
@@ -354,64 +180,20 @@ TALER_denom_pub_verify (const struct TALER_DenominationPublicKey *denom_pub,
const struct TALER_DenominationSignature *denom_sig,
const struct TALER_CoinPubHashP *c_hash)
{
- if (denom_pub->cipher != denom_sig->cipher)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- switch (denom_pub->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- GNUNET_break (0);
- return GNUNET_NO;
- case TALER_DENOMINATION_RSA:
- if (GNUNET_OK !=
- GNUNET_CRYPTO_rsa_verify (&c_hash->hash,
- denom_sig->details.rsa_signature,
- denom_pub->details.rsa_public_key))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Coin signature is invalid\n");
- return GNUNET_NO;
- }
- return GNUNET_YES;
- case TALER_DENOMINATION_CS:
- if (GNUNET_OK !=
- GNUNET_CRYPTO_cs_verify (&denom_sig->details.cs_signature,
- &denom_pub->details.cs_public_key,
- &c_hash->hash,
- sizeof(struct GNUNET_HashCode)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Coin signature is invalid\n");
- return GNUNET_NO;
- }
- return GNUNET_YES;
- default:
- GNUNET_assert (0);
- }
+ return GNUNET_CRYPTO_blind_sig_verify (denom_pub->bsign_pub_key,
+ denom_sig->unblinded_sig,
+ c_hash,
+ sizeof (*c_hash));
}
void
TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub)
{
- switch (denom_pub->cipher)
+ if (NULL != denom_pub->bsign_pub_key)
{
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- if (NULL != denom_pub->details.rsa_public_key)
- {
- GNUNET_CRYPTO_rsa_public_key_free (denom_pub->details.rsa_public_key);
- denom_pub->details.rsa_public_key = NULL;
- }
- denom_pub->cipher = TALER_DENOMINATION_INVALID;
- return;
- case TALER_DENOMINATION_CS:
- return;
- default:
- GNUNET_assert (0);
+ GNUNET_CRYPTO_blind_sign_pub_decref (denom_pub->bsign_pub_key);
+ denom_pub->bsign_pub_key = NULL;
}
}
@@ -419,22 +201,10 @@ TALER_denom_pub_free (struct TALER_DenominationPublicKey *denom_pub)
void
TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv)
{
- switch (denom_priv->cipher)
+ if (NULL != denom_priv->bsign_priv_key)
{
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- if (NULL != denom_priv->details.rsa_private_key)
- {
- GNUNET_CRYPTO_rsa_private_key_free (denom_priv->details.rsa_private_key);
- denom_priv->details.rsa_private_key = NULL;
- }
- denom_priv->cipher = TALER_DENOMINATION_INVALID;
- return;
- case TALER_DENOMINATION_CS:
- return;
- default:
- GNUNET_assert (0);
+ GNUNET_CRYPTO_blind_sign_priv_decref (denom_priv->bsign_priv_key);
+ denom_priv->bsign_priv_key = NULL;
}
}
@@ -442,22 +212,10 @@ TALER_denom_priv_free (struct TALER_DenominationPrivateKey *denom_priv)
void
TALER_denom_sig_free (struct TALER_DenominationSignature *denom_sig)
{
- switch (denom_sig->cipher)
+ if (NULL != denom_sig->unblinded_sig)
{
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- if (NULL != denom_sig->details.rsa_signature)
- {
- GNUNET_CRYPTO_rsa_signature_free (denom_sig->details.rsa_signature);
- denom_sig->details.rsa_signature = NULL;
- }
- denom_sig->cipher = TALER_DENOMINATION_INVALID;
- return;
- case TALER_DENOMINATION_CS:
- return;
- default:
- GNUNET_assert (0);
+ GNUNET_CRYPTO_unblinded_sig_decref (denom_sig->unblinded_sig);
+ denom_sig->unblinded_sig = NULL;
}
}
@@ -466,89 +224,73 @@ void
TALER_blinded_denom_sig_free (
struct TALER_BlindedDenominationSignature *denom_sig)
{
- switch (denom_sig->cipher)
+ if (NULL != denom_sig->blinded_sig)
{
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- if (NULL != denom_sig->details.blinded_rsa_signature)
- {
- GNUNET_CRYPTO_rsa_signature_free (
- denom_sig->details.blinded_rsa_signature);
- denom_sig->details.blinded_rsa_signature = NULL;
- }
- denom_sig->cipher = TALER_DENOMINATION_INVALID;
- return;
- case TALER_DENOMINATION_CS:
- return;
- default:
- GNUNET_assert (0);
+ GNUNET_CRYPTO_blinded_sig_decref (denom_sig->blinded_sig);
+ denom_sig->blinded_sig = NULL;
}
}
void
-TALER_denom_pub_deep_copy (struct TALER_DenominationPublicKey *denom_dst,
- const struct TALER_DenominationPublicKey *denom_src)
+TALER_denom_ewv_free (struct TALER_ExchangeWithdrawValues *ewv)
{
- *denom_dst = *denom_src; /* shallow copy */
- switch (denom_src->cipher)
- {
- case TALER_DENOMINATION_RSA:
- denom_dst->details.rsa_public_key
- = GNUNET_CRYPTO_rsa_public_key_dup (
- denom_src->details.rsa_public_key);
+ if (ewv == TALER_denom_ewv_rsa_singleton ())
return;
- case TALER_DENOMINATION_CS:
+ if (ewv->blinding_inputs ==
+ TALER_denom_ewv_rsa_singleton ()->blinding_inputs)
+ {
+ ewv->blinding_inputs = NULL;
return;
- default:
- GNUNET_assert (0);
+ }
+ if (NULL != ewv->blinding_inputs)
+ {
+ GNUNET_CRYPTO_blinding_input_values_decref (ewv->blinding_inputs);
+ ewv->blinding_inputs = NULL;
}
}
void
-TALER_denom_sig_deep_copy (struct TALER_DenominationSignature *denom_dst,
- const struct TALER_DenominationSignature *denom_src)
+TALER_denom_ewv_copy (struct TALER_ExchangeWithdrawValues *bi_dst,
+ const struct TALER_ExchangeWithdrawValues *bi_src)
{
- *denom_dst = *denom_src; /* shallow copy */
- switch (denom_src->cipher)
+ if (bi_src == TALER_denom_ewv_rsa_singleton ())
{
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- denom_dst->details.rsa_signature
- = GNUNET_CRYPTO_rsa_signature_dup (
- denom_src->details.rsa_signature);
- return;
- case TALER_DENOMINATION_CS:
+ *bi_dst = *bi_src;
return;
- default:
- GNUNET_assert (0);
}
+ bi_dst->blinding_inputs
+ = GNUNET_CRYPTO_blinding_input_values_incref (bi_src->blinding_inputs);
+}
+
+
+void
+TALER_denom_pub_copy (struct TALER_DenominationPublicKey *denom_dst,
+ const struct TALER_DenominationPublicKey *denom_src)
+{
+ denom_dst->age_mask = denom_src->age_mask;
+ denom_dst->bsign_pub_key
+ = GNUNET_CRYPTO_bsign_pub_incref (denom_src->bsign_pub_key);
}
void
-TALER_blinded_denom_sig_deep_copy (
+TALER_denom_sig_copy (struct TALER_DenominationSignature *denom_dst,
+ const struct TALER_DenominationSignature *denom_src)
+{
+ denom_dst->unblinded_sig
+ = GNUNET_CRYPTO_ub_sig_incref (denom_src->unblinded_sig);
+}
+
+
+void
+TALER_blinded_denom_sig_copy (
struct TALER_BlindedDenominationSignature *denom_dst,
const struct TALER_BlindedDenominationSignature *denom_src)
{
- *denom_dst = *denom_src; /* shallow copy */
- switch (denom_src->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- return;
- case TALER_DENOMINATION_RSA:
- denom_dst->details.blinded_rsa_signature
- = GNUNET_CRYPTO_rsa_signature_dup (
- denom_src->details.blinded_rsa_signature);
- return;
- case TALER_DENOMINATION_CS:
- return;
- default:
- GNUNET_assert (0);
- }
+ denom_dst->blinded_sig
+ = GNUNET_CRYPTO_blind_sig_incref (denom_src->blinded_sig);
}
@@ -556,24 +298,14 @@ int
TALER_denom_pub_cmp (const struct TALER_DenominationPublicKey *denom1,
const struct TALER_DenominationPublicKey *denom2)
{
- if (denom1->cipher != denom2->cipher)
- return (denom1->cipher > denom2->cipher) ? 1 : -1;
+ if (denom1->bsign_pub_key->cipher !=
+ denom2->bsign_pub_key->cipher)
+ return (denom1->bsign_pub_key->cipher >
+ denom2->bsign_pub_key->cipher) ? 1 : -1;
if (denom1->age_mask.bits != denom2->age_mask.bits)
return (denom1->age_mask.bits > denom2->age_mask.bits) ? 1 : -1;
- switch (denom1->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- return 0;
- case TALER_DENOMINATION_RSA:
- return GNUNET_CRYPTO_rsa_public_key_cmp (denom1->details.rsa_public_key,
- denom2->details.rsa_public_key);
- case TALER_DENOMINATION_CS:
- return GNUNET_memcmp (&denom1->details.cs_public_key,
- &denom2->details.cs_public_key);
- default:
- GNUNET_assert (0);
- }
- return -2;
+ return GNUNET_CRYPTO_bsign_pub_cmp (denom1->bsign_pub_key,
+ denom2->bsign_pub_key);
}
@@ -581,22 +313,8 @@ int
TALER_denom_sig_cmp (const struct TALER_DenominationSignature *sig1,
const struct TALER_DenominationSignature *sig2)
{
- if (sig1->cipher != sig2->cipher)
- return (sig1->cipher > sig2->cipher) ? 1 : -1;
- switch (sig1->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- return 0;
- case TALER_DENOMINATION_RSA:
- return GNUNET_CRYPTO_rsa_signature_cmp (sig1->details.rsa_signature,
- sig2->details.rsa_signature);
- case TALER_DENOMINATION_CS:
- return GNUNET_memcmp (&sig1->details.cs_signature,
- &sig2->details.cs_signature);
- default:
- GNUNET_assert (0);
- }
- return -2;
+ return GNUNET_CRYPTO_ub_sig_cmp (sig1->unblinded_sig,
+ sig1->unblinded_sig);
}
@@ -605,27 +323,8 @@ TALER_blinded_planchet_cmp (
const struct TALER_BlindedPlanchet *bp1,
const struct TALER_BlindedPlanchet *bp2)
{
- if (bp1->cipher != bp2->cipher)
- return (bp1->cipher > bp2->cipher) ? 1 : -1;
- switch (bp1->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- return 0;
- case TALER_DENOMINATION_RSA:
- if (bp1->details.rsa_blinded_planchet.blinded_msg_size !=
- bp2->details.rsa_blinded_planchet.blinded_msg_size)
- return (bp1->details.rsa_blinded_planchet.blinded_msg_size >
- bp2->details.rsa_blinded_planchet.blinded_msg_size) ? 1 : -1;
- return memcmp (bp1->details.rsa_blinded_planchet.blinded_msg,
- bp2->details.rsa_blinded_planchet.blinded_msg,
- bp1->details.rsa_blinded_planchet.blinded_msg_size);
- case TALER_DENOMINATION_CS:
- return GNUNET_memcmp (&bp1->details.cs_blinded_planchet,
- &bp2->details.cs_blinded_planchet);
- default:
- GNUNET_assert (0);
- }
- return -2;
+ return GNUNET_CRYPTO_blinded_message_cmp (bp1->blinded_message,
+ bp2->blinded_message);
}
@@ -634,22 +333,8 @@ TALER_blinded_denom_sig_cmp (
const struct TALER_BlindedDenominationSignature *sig1,
const struct TALER_BlindedDenominationSignature *sig2)
{
- if (sig1->cipher != sig2->cipher)
- return (sig1->cipher > sig2->cipher) ? 1 : -1;
- switch (sig1->cipher)
- {
- case TALER_DENOMINATION_INVALID:
- return 0;
- case TALER_DENOMINATION_RSA:
- return GNUNET_CRYPTO_rsa_signature_cmp (sig1->details.blinded_rsa_signature,
- sig2->details.blinded_rsa_signature);
- case TALER_DENOMINATION_CS:
- return GNUNET_memcmp (&sig1->details.blinded_cs_answer,
- &sig2->details.blinded_cs_answer);
- default:
- GNUNET_assert (0);
- }
- return -2;
+ return GNUNET_CRYPTO_blind_sig_cmp (sig1->blinded_sig,
+ sig1->blinded_sig);
}
@@ -657,31 +342,31 @@ void
TALER_blinded_planchet_hash_ (const struct TALER_BlindedPlanchet *bp,
struct GNUNET_HashContext *hash_context)
{
- uint32_t cipher = htonl (bp->cipher);
+ const struct GNUNET_CRYPTO_BlindedMessage *bm = bp->blinded_message;
+ uint32_t cipher = htonl (bm->cipher);
GNUNET_CRYPTO_hash_context_read (hash_context,
&cipher,
sizeof (cipher));
- switch (bp->cipher)
+ switch (bm->cipher)
{
- case TALER_DENOMINATION_INVALID:
- break;
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ GNUNET_break (0);
+ return;
+ case GNUNET_CRYPTO_BSA_RSA:
GNUNET_CRYPTO_hash_context_read (
hash_context,
- bp->details.rsa_blinded_planchet.blinded_msg,
- bp->details.rsa_blinded_planchet.blinded_msg_size);
- break;
- case TALER_DENOMINATION_CS:
+ bm->details.rsa_blinded_message.blinded_msg,
+ bm->details.rsa_blinded_message.blinded_msg_size);
+ return;
+ case GNUNET_CRYPTO_BSA_CS:
GNUNET_CRYPTO_hash_context_read (
hash_context,
- &bp->details.cs_blinded_planchet,
- sizeof (bp->details.cs_blinded_planchet));
- break;
- default:
- GNUNET_assert (0);
- break;
+ &bm->details.cs_blinded_message,
+ sizeof (bm->details.cs_blinded_message));
+ return;
}
+ GNUNET_assert (0);
}
@@ -689,14 +374,17 @@ void
TALER_planchet_blinding_secret_create (
const struct TALER_PlanchetMasterSecretP *ps,
const struct TALER_ExchangeWithdrawValues *alg_values,
- union TALER_DenominationBlindingKeyP *bks)
+ union GNUNET_CRYPTO_BlindingSecretP *bks)
{
- switch (alg_values->cipher)
+ const struct GNUNET_CRYPTO_BlindingInputValues *bi =
+ alg_values->blinding_inputs;
+
+ switch (bi->cipher)
{
- case TALER_DENOMINATION_INVALID:
+ case GNUNET_CRYPTO_BSA_INVALID:
GNUNET_break (0);
return;
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_RSA:
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_kdf (&bks->rsa_bks,
sizeof (bks->rsa_bks),
@@ -707,7 +395,7 @@ TALER_planchet_blinding_secret_create (
NULL,
0));
return;
- case TALER_DENOMINATION_CS:
+ case GNUNET_CRYPTO_BSA_CS:
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_kdf (&bks->nonce,
sizeof (bks->nonce),
@@ -715,14 +403,13 @@ TALER_planchet_blinding_secret_create (
strlen ("bseed"),
ps,
sizeof(*ps),
- &alg_values->details.cs_values,
- sizeof(alg_values->details.cs_values),
+ &bi->details.cs_values,
+ sizeof(bi->details.cs_values),
NULL,
0));
return;
- default:
- GNUNET_break (0);
}
+ GNUNET_assert (0);
}
@@ -732,9 +419,18 @@ TALER_planchet_setup_coin_priv (
const struct TALER_ExchangeWithdrawValues *alg_values,
struct TALER_CoinSpendPrivateKeyP *coin_priv)
{
- switch (alg_values->cipher)
+ const struct GNUNET_CRYPTO_BlindingInputValues *bi
+ = alg_values->blinding_inputs;
+
+ switch (bi->cipher)
{
- case TALER_DENOMINATION_RSA:
+ case GNUNET_CRYPTO_BSA_INVALID:
+ GNUNET_break (0);
+ memset (coin_priv,
+ 0,
+ sizeof (*coin_priv));
+ return;
+ case GNUNET_CRYPTO_BSA_RSA:
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_kdf (coin_priv,
sizeof (*coin_priv),
@@ -744,8 +440,8 @@ TALER_planchet_setup_coin_priv (
sizeof(*ps),
NULL,
0));
- break;
- case TALER_DENOMINATION_CS:
+ return;
+ case GNUNET_CRYPTO_BSA_CS:
GNUNET_assert (GNUNET_YES ==
GNUNET_CRYPTO_kdf (coin_priv,
sizeof (*coin_priv),
@@ -753,37 +449,24 @@ TALER_planchet_setup_coin_priv (
strlen ("coin"),
ps,
sizeof(*ps),
- &alg_values->details.cs_values,
- sizeof(alg_values->details.cs_values),
+ &bi->details.cs_values,
+ sizeof(bi->details.cs_values),
NULL,
0));
- break;
- default:
- GNUNET_break (0);
return;
}
+ GNUNET_assert (0);
}
void
TALER_blinded_planchet_free (struct TALER_BlindedPlanchet *blinded_planchet)
{
- switch (blinded_planchet->cipher)
+ if (NULL != blinded_planchet->blinded_message)
{
- case TALER_DENOMINATION_INVALID:
- GNUNET_break (0);
- return;
- case TALER_DENOMINATION_RSA:
- GNUNET_free (blinded_planchet->details.rsa_blinded_planchet.blinded_msg);
- return;
- case TALER_DENOMINATION_CS:
- memset (blinded_planchet,
- 0,
- sizeof (*blinded_planchet));
- /* nothing to do for CS */
- return;
+ GNUNET_CRYPTO_blinded_message_decref (blinded_planchet->blinded_message);
+ blinded_planchet->blinded_message = NULL;
}
- GNUNET_assert (0);
}
diff --git a/src/util/do_bench_age_restriction b/src/util/do_bench_age_restriction
new file mode 100755
index 000000000..a65713439
--- /dev/null
+++ b/src/util/do_bench_age_restriction
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+gcc bench_age_restriction.c \
+ -lgnunetutil -lgnunetjson -lsodium -ljansson \
+ -L/usr/lib/x86_64-linux-gnu -lmicrohttpd -ltalerutil -lm \
+ -I../include \
+ -o bench_age_restriction && ./bench_age_restriction
+
diff --git a/src/util/exchange_signatures.c b/src/util/exchange_signatures.c
index 68c0fdb0a..aaefb5cec 100644
--- a/src/util/exchange_signatures.c
+++ b/src/util/exchange_signatures.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021, 2022 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -48,10 +48,10 @@ struct TALER_DepositConfirmationPS
struct TALER_MerchantWireHashP h_wire GNUNET_PACKED;
/**
- * Hash over the extension options of the deposit, 0 if there
- * were not extension options.
+ * Hash over the optional policy extension of the deposit, 0 if there
+ * was no policy.
*/
- struct TALER_ExtensionContractHashP h_extensions GNUNET_PACKED;
+ struct TALER_ExtensionPolicyHashP h_policy GNUNET_PACKED;
/**
* Time when this confirmation was generated / when the exchange received
@@ -78,12 +78,12 @@ struct TALER_DepositConfirmationPS
* Amount to be deposited, excluding fee. Calculated from the
* amount with fee and the fee from the deposit request.
*/
- struct TALER_AmountNBO amount_without_fee;
+ struct TALER_AmountNBO total_without_fee;
/**
- * The public key of the coin that was deposited.
+ * Hash over all of the coin signatures.
*/
- struct TALER_CoinSpendPublicKeyP coin_pub;
+ struct GNUNET_HashCode h_coin_sigs;
/**
* The Merchant's public key. Allows the merchant to later refund
@@ -101,12 +101,13 @@ TALER_exchange_online_deposit_confirmation_sign (
TALER_ExchangeSignCallback scb,
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendSignatureP *coin_sigs[static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
struct TALER_ExchangePublicKeyP *pub,
struct TALER_ExchangeSignatureP *sig)
@@ -119,14 +120,22 @@ TALER_exchange_online_deposit_confirmation_sign (
.exchange_timestamp = GNUNET_TIME_timestamp_hton (exchange_timestamp),
.wire_deadline = GNUNET_TIME_timestamp_hton (wire_deadline),
.refund_deadline = GNUNET_TIME_timestamp_hton (refund_deadline),
- .coin_pub = *coin_pub,
- .merchant_pub = *merchant_pub
+ .merchant_pub = *merchant_pub,
+ .h_policy = {{{0}}}
};
-
- if (NULL != h_extensions)
- dcs.h_extensions = *h_extensions;
- TALER_amount_hton (&dcs.amount_without_fee,
- amount_without_fee);
+ struct GNUNET_HashContext *hc;
+
+ hc = GNUNET_CRYPTO_hash_context_start ();
+ for (unsigned int i = 0; i<num_coins; i++)
+ GNUNET_CRYPTO_hash_context_read (hc,
+ coin_sigs[i],
+ sizeof (*coin_sigs[i]));
+ GNUNET_CRYPTO_hash_context_finish (hc,
+ &dcs.h_coin_sigs);
+ if (NULL != h_policy)
+ dcs.h_policy = *h_policy;
+ TALER_amount_hton (&dcs.total_without_fee,
+ total_without_fee);
return scb (&dcs.purpose,
pub,
sig);
@@ -137,12 +146,13 @@ enum GNUNET_GenericReturnValue
TALER_exchange_online_deposit_confirmation_verify (
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantWireHashP *h_wire,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
struct GNUNET_TIME_Timestamp exchange_timestamp,
struct GNUNET_TIME_Timestamp wire_deadline,
struct GNUNET_TIME_Timestamp refund_deadline,
- const struct TALER_Amount *amount_without_fee,
- const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_Amount *total_without_fee,
+ unsigned int num_coins,
+ const struct TALER_CoinSpendSignatureP *coin_sigs[static num_coins],
const struct TALER_MerchantPublicKeyP *merchant_pub,
const struct TALER_ExchangePublicKeyP *exchange_pub,
const struct TALER_ExchangeSignatureP *exchange_sig)
@@ -155,14 +165,21 @@ TALER_exchange_online_deposit_confirmation_verify (
.exchange_timestamp = GNUNET_TIME_timestamp_hton (exchange_timestamp),
.wire_deadline = GNUNET_TIME_timestamp_hton (wire_deadline),
.refund_deadline = GNUNET_TIME_timestamp_hton (refund_deadline),
- .coin_pub = *coin_pub,
.merchant_pub = *merchant_pub
};
-
- if (NULL != h_extensions)
- dcs.h_extensions = *h_extensions;
- TALER_amount_hton (&dcs.amount_without_fee,
- amount_without_fee);
+ struct GNUNET_HashContext *hc;
+
+ hc = GNUNET_CRYPTO_hash_context_start ();
+ for (unsigned int i = 0; i<num_coins; i++)
+ GNUNET_CRYPTO_hash_context_read (hc,
+ coin_sigs[i],
+ sizeof (*coin_sigs[i]));
+ GNUNET_CRYPTO_hash_context_finish (hc,
+ &dcs.h_coin_sigs);
+ if (NULL != h_policy)
+ dcs.h_policy = *h_policy;
+ TALER_amount_hton (&dcs.total_without_fee,
+ total_without_fee);
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_DEPOSIT,
&dcs,
@@ -362,6 +379,91 @@ TALER_exchange_online_melt_confirmation_verify (
GNUNET_NETWORK_STRUCT_BEGIN
/**
+ * @brief Format of the block signed by the Exchange in response to a
+ * successful "/reserves/$RESERVE_PUB/age-withdraw" request. Hereby the
+ * exchange affirms that the commitment along with the maximum age group and
+ * the amount were accepted. This also commits the exchange to a particular
+ * index to not be revealed during the reveal.
+ */
+struct TALER_AgeWithdrawConfirmationPS
+{
+ /**
+ * Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_AGE_WITHDRAW. Signed by a
+ * `struct TALER_ExchangePublicKeyP` using EdDSA.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Commitment made in the /reserves/$RESERVE_PUB/age-withdraw.
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment GNUNET_PACKED;
+
+ /**
+ * Index that the client will not have to reveal, in NBO.
+ * Must be smaller than #TALER_CNC_KAPPA.
+ */
+ uint32_t noreveal_index GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+enum TALER_ErrorCode
+TALER_exchange_online_age_withdraw_confirmation_sign (
+ TALER_ExchangeSignCallback scb,
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ uint32_t noreveal_index,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig)
+{
+
+ struct TALER_AgeWithdrawConfirmationPS confirm = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_AGE_WITHDRAW),
+ .purpose.size = htonl (sizeof (confirm)),
+ .h_commitment = *h_commitment,
+ .noreveal_index = htonl (noreveal_index)
+ };
+
+ return scb (&confirm.purpose,
+ pub,
+ sig);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_age_withdraw_confirmation_verify (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ uint32_t noreveal_index,
+ const struct TALER_ExchangePublicKeyP *exchange_pub,
+ const struct TALER_ExchangeSignatureP *exchange_sig)
+{
+ struct TALER_AgeWithdrawConfirmationPS confirm = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_AGE_WITHDRAW),
+ .purpose.size = htonl (sizeof (confirm)),
+ .h_commitment = *h_commitment,
+ .noreveal_index = htonl (noreveal_index)
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_EXCHANGE_CONFIRM_AGE_WITHDRAW,
+ &confirm,
+ &exchange_sig->eddsa_signature,
+ &exchange_pub->eddsa_pub))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
+/* TODO:oec: add signature for age-withdraw, age-reveal */
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
* @brief Signature made by the exchange over the full set of keys, used
* to detect cheating exchanges that give out different sets to
* different users.
@@ -449,15 +551,20 @@ struct TALER_ExchangeAccountSetupSuccessPS
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
- * Hash over the payto for which the signature was
- * made.
+ * Hash over the payto for which the signature was made.
*/
struct TALER_PaytoHashP h_payto;
/**
+ * Hash over details on *which* KYC obligations were discharged!
+ */
+ struct GNUNET_HashCode h_kyc;
+
+ /**
* When was the signature made.
*/
struct GNUNET_TIME_TimestampNBO timestamp;
+
};
GNUNET_NETWORK_STRUCT_END
@@ -467,6 +574,7 @@ enum TALER_ErrorCode
TALER_exchange_online_account_setup_success_sign (
TALER_ExchangeSignCallback scb,
const struct TALER_PaytoHashP *h_payto,
+ const json_t *kyc,
struct GNUNET_TIME_Timestamp timestamp,
struct TALER_ExchangePublicKeyP *pub,
struct TALER_ExchangeSignatureP *sig)
@@ -476,10 +584,11 @@ TALER_exchange_online_account_setup_success_sign (
.purpose.purpose = htonl (
TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
.h_payto = *h_payto,
- .timestamp = GNUNET_TIME_timestamp_hton (
- timestamp)
+ .timestamp = GNUNET_TIME_timestamp_hton (timestamp)
};
+ TALER_json_hash (kyc,
+ &kyc_purpose.h_kyc);
return scb (&kyc_purpose.purpose,
pub,
sig);
@@ -489,6 +598,7 @@ TALER_exchange_online_account_setup_success_sign (
enum GNUNET_GenericReturnValue
TALER_exchange_online_account_setup_success_verify (
const struct TALER_PaytoHashP *h_payto,
+ const json_t *kyc,
struct GNUNET_TIME_Timestamp timestamp,
const struct TALER_ExchangePublicKeyP *pub,
const struct TALER_ExchangeSignatureP *sig)
@@ -498,10 +608,11 @@ TALER_exchange_online_account_setup_success_verify (
.purpose.purpose = htonl (
TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS),
.h_payto = *h_payto,
- .timestamp = GNUNET_TIME_timestamp_hton (
- timestamp)
+ .timestamp = GNUNET_TIME_timestamp_hton (timestamp)
};
+ TALER_json_hash (kyc,
+ &kyc_purpose.h_kyc);
return
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_ACCOUNT_SETUP_SUCCESS,
&kyc_purpose,
@@ -849,8 +960,9 @@ TALER_exchange_online_confirm_recoup_sign (
struct TALER_RecoupConfirmationPS pc = {
.purpose.size = htonl (sizeof (pc)),
.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP),
- .reserve_pub = *reserve_pub,
- .coin_pub = *coin_pub
+ .timestamp = GNUNET_TIME_timestamp_hton (timestamp),
+ .coin_pub = *coin_pub,
+ .reserve_pub = *reserve_pub
};
TALER_amount_hton (&pc.recoup_amount,
@@ -873,8 +985,9 @@ TALER_exchange_online_confirm_recoup_verify (
struct TALER_RecoupConfirmationPS pc = {
.purpose.size = htonl (sizeof (pc)),
.purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_RECOUP),
- .reserve_pub = *reserve_pub,
- .coin_pub = *coin_pub
+ .timestamp = GNUNET_TIME_timestamp_hton (timestamp),
+ .coin_pub = *coin_pub,
+ .reserve_pub = *reserve_pub
};
TALER_amount_hton (&pc.recoup_amount,
@@ -1109,10 +1222,10 @@ TALER_exchange_online_denomination_expired_sign (
};
/* strncpy would create a compiler warning */
- memcpy (dua.operation,
- op,
- GNUNET_MIN (sizeof (dua.operation),
- strlen (op)));
+ GNUNET_memcpy (dua.operation,
+ op,
+ GNUNET_MIN (sizeof (dua.operation),
+ strlen (op)));
return scb (&dua.purpose,
pub,
sig);
@@ -1136,10 +1249,10 @@ TALER_exchange_online_denomination_expired_verify (
};
/* strncpy would create a compiler warning */
- memcpy (dua.operation,
- op,
- GNUNET_MIN (sizeof (dua.operation),
- strlen (op)));
+ GNUNET_memcpy (dua.operation,
+ op,
+ GNUNET_MIN (sizeof (dua.operation),
+ strlen (op)));
return
GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_AFFIRM_DENOM_EXPIRED,
&dua,
@@ -1377,6 +1490,100 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* Response by which the exchange affirms that it has
+ * received funds deposited into a purse.
+ */
+struct TALER_CoinPurseRefundConfirmationPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Public key of the purse.
+ */
+ struct TALER_PurseContractPublicKeyP purse_pub;
+
+ /**
+ * Public key of the coin.
+ */
+ struct TALER_CoinSpendPublicKeyP coin_pub;
+
+ /**
+ * How much will be refunded to the purse.
+ */
+ struct TALER_AmountNBO refunded_amount;
+
+ /**
+ * How much was the refund fee.
+ */
+ struct TALER_AmountNBO refund_fee;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+enum TALER_ErrorCode
+TALER_exchange_online_purse_refund_sign (
+ TALER_ExchangeSignCallback scb,
+ const struct TALER_Amount *amount_without_fee,
+ const struct TALER_Amount *refund_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig)
+{
+ struct TALER_CoinPurseRefundConfirmationPS dc = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND),
+ .purpose.size = htonl (sizeof (dc)),
+ .coin_pub = *coin_pub,
+ .purse_pub = *purse_pub,
+ };
+
+ TALER_amount_hton (&dc.refunded_amount,
+ amount_without_fee);
+ TALER_amount_hton (&dc.refund_fee,
+ refund_fee);
+ return scb (&dc.purpose,
+ pub,
+ sig);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_purse_refund_verify (
+ const struct TALER_Amount *amount_without_fee,
+ const struct TALER_Amount *refund_fee,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_ExchangePublicKeyP *pub,
+ const struct TALER_ExchangeSignatureP *sig)
+{
+ struct TALER_CoinPurseRefundConfirmationPS dc = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND),
+ .purpose.size = htonl (sizeof (dc)),
+ .coin_pub = *coin_pub,
+ .purse_pub = *purse_pub,
+ };
+
+ TALER_amount_hton (&dc.refunded_amount,
+ amount_without_fee);
+ TALER_amount_hton (&dc.refund_fee,
+ refund_fee);
+ return
+ GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_EXCHANGE_CONFIRM_PURSE_REFUND,
+ &dc,
+ &sig->eddsa_signature,
+ &pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Response by which the exchange affirms that it has
* merged a purse into a reserve.
*/
struct TALER_PurseMergedConfirmationPS
@@ -1585,4 +1792,103 @@ TALER_exchange_online_purse_status_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by the exchange to affirm that the
+ * owner of a reserve has certain attributes.
+ */
+struct TALER_ExchangeAttestPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Time when the attestation was made.
+ */
+ struct GNUNET_TIME_TimestampNBO attest_timestamp;
+
+ /**
+ * Time when the attestation expires.
+ */
+ struct GNUNET_TIME_TimestampNBO expiration_time;
+
+ /**
+ * Public key of the reserve for which the attributes
+ * are attested.
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Hash over the attributes.
+ */
+ struct GNUNET_HashCode h_attributes;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+enum TALER_ErrorCode
+TALER_exchange_online_reserve_attest_details_sign (
+ TALER_ExchangeSignCallback scb,
+ struct GNUNET_TIME_Timestamp attest_timestamp,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *attributes,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig)
+{
+ struct TALER_ExchangeAttestPS rap = {
+ .purpose.size = htonl (sizeof (rap)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS),
+ .attest_timestamp = GNUNET_TIME_timestamp_hton (attest_timestamp),
+ .expiration_time = GNUNET_TIME_timestamp_hton (expiration_time),
+ .reserve_pub = *reserve_pub
+ };
+
+ TALER_json_hash (attributes,
+ &rap.h_attributes);
+ return scb (&rap.purpose,
+ pub,
+ sig);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_exchange_online_reserve_attest_details_verify (
+ struct GNUNET_TIME_Timestamp attest_timestamp,
+ struct GNUNET_TIME_Timestamp expiration_time,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const json_t *attributes,
+ struct TALER_ExchangePublicKeyP *pub,
+ struct TALER_ExchangeSignatureP *sig)
+{
+ struct TALER_ExchangeAttestPS rap = {
+ .purpose.size = htonl (sizeof (rap)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS),
+ .attest_timestamp = GNUNET_TIME_timestamp_hton (attest_timestamp),
+ .expiration_time = GNUNET_TIME_timestamp_hton (expiration_time),
+ .reserve_pub = *reserve_pub
+ };
+
+ TALER_json_hash (attributes,
+ &rap.h_attributes);
+ if (GNUNET_OK !=
+ GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_EXCHANGE_RESERVE_ATTEST_DETAILS,
+ &rap,
+ &sig->eddsa_signature,
+ &pub->eddsa_pub))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}
+
+
/* end of exchange_signatures.c */
diff --git a/src/util/iban.c b/src/util/iban.c
index efd8c4282..c2274d3cb 100644
--- a/src/util/iban.c
+++ b/src/util/iban.c
@@ -233,9 +233,9 @@ TALER_iban_validate (const char *iban)
return GNUNET_strdup ("IBAN number too short to be valid");
if (len > 34)
return GNUNET_strdup ("IBAN number too long to be valid");
- memcpy (cc, iban, 2);
- memcpy (ibancpy, iban + 4, len - 4);
- memcpy (ibancpy + len - 4, iban, 4);
+ GNUNET_memcpy (cc, iban, 2);
+ GNUNET_memcpy (ibancpy, iban + 4, len - 4);
+ GNUNET_memcpy (ibancpy + len - 4, iban, 4);
ibancpy[len] = '\0';
cc_entry.code = cc;
cc_entry.english = NULL;
diff --git a/src/util/merchant_signatures.c b/src/util/merchant_signatures.c
index 36f96499c..35e0b0e07 100644
--- a/src/util/merchant_signatures.c
+++ b/src/util/merchant_signatures.c
@@ -277,7 +277,7 @@ void
TALER_merchant_pay_sign (
const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_MerchantPrivateKeyP *merch_priv,
- struct GNUNET_CRYPTO_EddsaSignature *merch_sig)
+ struct TALER_MerchantSignatureP *merch_sig)
{
struct TALER_PaymentResponsePS mr = {
.purpose.purpose = htonl (TALER_SIGNATURE_MERCHANT_PAYMENT_OK),
@@ -287,7 +287,7 @@ TALER_merchant_pay_sign (
GNUNET_CRYPTO_eddsa_sign (&merch_priv->eddsa_priv,
&mr,
- merch_sig);
+ &merch_sig->eddsa_sig);
}
diff --git a/src/util/offline_signatures.c b/src/util/offline_signatures.c
index 54da2b114..fbff850df 100644
--- a/src/util/offline_signatures.c
+++ b/src/util/offline_signatures.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020-2022 Taler Systems SA
+ Copyright (C) 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -27,6 +27,99 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* @brief Signature made by the exchange offline key over the information of
+ * an AML officer status change.
+ */
+struct TALER_MasterAmlOfficerStatusPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_MASTER_AML_KEY. Signed
+ * by a `struct TALER_MasterPublicKeyP` using EdDSA.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Time of the change.
+ */
+ struct GNUNET_TIME_TimestampNBO change_date;
+
+ /**
+ * Public key of the AML officer.
+ */
+ struct TALER_AmlOfficerPublicKeyP officer_pub;
+
+ /**
+ * Hash over the AML officer's name.
+ */
+ struct GNUNET_HashCode h_officer_name GNUNET_PACKED;
+
+ /**
+ * Bitmask: 1 if enabled; 2 for read-only access. in NBO.
+ */
+ uint32_t is_active GNUNET_PACKED;
+};
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_exchange_offline_aml_officer_status_sign (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterPrivateKeyP *master_priv,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct TALER_MasterAmlOfficerStatusPS as = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_AML_KEY),
+ .purpose.size = htonl (sizeof (as)),
+ .change_date = GNUNET_TIME_timestamp_hton (change_date),
+ .officer_pub = *officer_pub,
+ .is_active = htonl ((is_active ? 1 : 0) + (read_only ? 2 : 0))
+ };
+
+ GNUNET_CRYPTO_hash (officer_name,
+ strlen (officer_name) + 1,
+ &as.h_officer_name);
+ GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
+ &as,
+ &master_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_exchange_offline_aml_officer_status_verify (
+ const struct TALER_AmlOfficerPublicKeyP *officer_pub,
+ const char *officer_name,
+ struct GNUNET_TIME_Timestamp change_date,
+ bool is_active,
+ bool read_only,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct TALER_MasterAmlOfficerStatusPS as = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_AML_KEY),
+ .purpose.size = htonl (sizeof (as)),
+ .change_date = GNUNET_TIME_timestamp_hton (change_date),
+ .officer_pub = *officer_pub,
+ .is_active = htonl ((is_active ? 1 : 0) + (read_only ? 2 : 0))
+ };
+
+ GNUNET_CRYPTO_hash (officer_name,
+ strlen (officer_name) + 1,
+ &as.h_officer_name);
+ return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_AML_KEY,
+ &as,
+ &master_sig->eddsa_signature,
+ &master_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Signature made by the exchange offline key over the information of
* an auditor to be added to the exchange's set of auditors.
*/
struct TALER_MasterAddAuditorPS
@@ -584,6 +677,22 @@ struct TALER_MasterAddWirePS
* Hash over the exchange's payto URI.
*/
struct TALER_PaytoHashP h_payto GNUNET_PACKED;
+
+ /**
+ * Hash over the conversion URL, all zeros if there
+ * is no conversion URL.
+ */
+ struct GNUNET_HashCode h_conversion_url;
+
+ /**
+ * Hash over the debit restrictions.
+ */
+ struct GNUNET_HashCode h_debit_restrictions;
+
+ /**
+ * Hash over the credit restrictions.
+ */
+ struct GNUNET_HashCode h_credit_restrictions;
};
GNUNET_NETWORK_STRUCT_END
@@ -592,6 +701,9 @@ GNUNET_NETWORK_STRUCT_END
void
TALER_exchange_offline_wire_add_sign (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp now,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig)
@@ -604,6 +716,14 @@ TALER_exchange_offline_wire_add_sign (
TALER_payto_hash (payto_uri,
&kv.h_payto);
+ if (NULL != conversion_url)
+ GNUNET_CRYPTO_hash (conversion_url,
+ strlen (conversion_url) + 1,
+ &kv.h_conversion_url);
+ TALER_json_hash (debit_restrictions,
+ &kv.h_debit_restrictions);
+ TALER_json_hash (credit_restrictions,
+ &kv.h_credit_restrictions);
GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
&kv,
&master_sig->eddsa_signature);
@@ -613,6 +733,9 @@ TALER_exchange_offline_wire_add_sign (
enum GNUNET_GenericReturnValue
TALER_exchange_offline_wire_add_verify (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
struct GNUNET_TIME_Timestamp sign_time,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig)
@@ -625,6 +748,14 @@ TALER_exchange_offline_wire_add_verify (
TALER_payto_hash (payto_uri,
&aw.h_payto);
+ if (NULL != conversion_url)
+ GNUNET_CRYPTO_hash (conversion_url,
+ strlen (conversion_url) + 1,
+ &aw.h_conversion_url);
+ TALER_json_hash (debit_restrictions,
+ &aw.h_debit_restrictions);
+ TALER_json_hash (credit_restrictions,
+ &aw.h_credit_restrictions);
return
GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_MASTER_ADD_WIRE,
@@ -840,15 +971,6 @@ struct TALER_MasterGlobalFeePS
struct GNUNET_TIME_RelativeNBO purse_timeout;
/**
- * How long does the exchange promise to keep funds
- * an account for which the KYC has never happened
- * after a purse was merged into an account? Basically,
- * after this time funds in an account without KYC are
- * forfeit.
- */
- struct GNUNET_TIME_RelativeNBO kyc_timeout;
-
- /**
* How long will the exchange preserve the account history? After an
* account was deleted/closed, the exchange will retain the account history
* for legal reasons until this time.
@@ -878,27 +1000,25 @@ TALER_exchange_offline_global_fee_sign (
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig)
{
- struct TALER_MasterGlobalFeePS kv = {
+ struct TALER_MasterGlobalFeePS wf = {
.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_GLOBAL_FEES),
- .purpose.size = htonl (sizeof (kv)),
+ .purpose.size = htonl (sizeof (wf)),
.start_date = GNUNET_TIME_timestamp_hton (start_time),
.end_date = GNUNET_TIME_timestamp_hton (end_time),
.purse_timeout = GNUNET_TIME_relative_hton (purse_timeout),
- .kyc_timeout = GNUNET_TIME_relative_hton (kyc_timeout),
.history_expiration = GNUNET_TIME_relative_hton (history_expiration),
.purse_account_limit = htonl (purse_account_limit)
};
- TALER_global_fee_set_hton (&kv.fees,
+ TALER_global_fee_set_hton (&wf.fees,
fees);
GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
- &kv,
+ &wf,
&master_sig->eddsa_signature);
}
@@ -909,7 +1029,6 @@ TALER_exchange_offline_global_fee_verify (
struct GNUNET_TIME_Timestamp end_time,
const struct TALER_GlobalFeeSet *fees,
struct GNUNET_TIME_Relative purse_timeout,
- struct GNUNET_TIME_Relative kyc_timeout,
struct GNUNET_TIME_Relative history_expiration,
uint32_t purse_account_limit,
const struct TALER_MasterPublicKeyP *master_pub,
@@ -921,7 +1040,6 @@ TALER_exchange_offline_global_fee_verify (
.start_date = GNUNET_TIME_timestamp_hton (start_time),
.end_date = GNUNET_TIME_timestamp_hton (end_time),
.purse_timeout = GNUNET_TIME_relative_hton (purse_timeout),
- .kyc_timeout = GNUNET_TIME_relative_hton (kyc_timeout),
.history_expiration = GNUNET_TIME_relative_hton (history_expiration),
.purse_account_limit = htonl (purse_account_limit)
};
@@ -939,10 +1057,10 @@ TALER_exchange_offline_global_fee_verify (
GNUNET_NETWORK_STRUCT_BEGIN
/**
- * @brief Signature made by the exchange offline key over the
- * configuration of an extension.
+ * @brief Signature made by the exchange offline key over the manifest of
+ * an extension.
*/
-struct TALER_MasterExtensionConfigurationPS
+struct TALER_MasterExtensionManifestPS
{
/**
* Purpose is #TALER_SIGNATURE_MASTER_EXTENSION. Signed
@@ -951,24 +1069,24 @@ struct TALER_MasterExtensionConfigurationPS
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
- * Hash of the JSON object that represents the configuration of an extension.
+ * Hash of the JSON object that represents the manifests of extensions.
*/
- struct TALER_ExtensionConfigHashP h_config GNUNET_PACKED;
+ struct TALER_ExtensionManifestsHashP h_manifest GNUNET_PACKED;
};
GNUNET_NETWORK_STRUCT_END
void
-TALER_exchange_offline_extension_config_hash_sign (
- const struct TALER_ExtensionConfigHashP *h_config,
+TALER_exchange_offline_extension_manifests_hash_sign (
+ const struct TALER_ExtensionManifestsHashP *h_manifest,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig)
{
- struct TALER_MasterExtensionConfigurationPS ec = {
+ struct TALER_MasterExtensionManifestPS ec = {
.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_EXTENSION),
.purpose.size = htonl (sizeof(ec)),
- .h_config = *h_config
+ .h_manifest = *h_manifest
};
GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
&ec,
@@ -977,16 +1095,16 @@ TALER_exchange_offline_extension_config_hash_sign (
enum GNUNET_GenericReturnValue
-TALER_exchange_offline_extension_config_hash_verify (
- const struct TALER_ExtensionConfigHashP *h_config,
+TALER_exchange_offline_extension_manifests_hash_verify (
+ const struct TALER_ExtensionManifestsHashP *h_manifest,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig
)
{
- struct TALER_MasterExtensionConfigurationPS ec = {
+ struct TALER_MasterExtensionManifestPS ec = {
.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_EXTENSION),
.purpose.size = htonl (sizeof(ec)),
- .h_config = *h_config
+ .h_manifest = *h_manifest
};
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_EXTENSION,
@@ -1015,6 +1133,22 @@ struct TALER_MasterWireDetailsPS
*/
struct TALER_PaytoHashP h_wire_details GNUNET_PACKED;
+ /**
+ * Hash over the conversion URL, all zeros if there
+ * is no conversion URL.
+ */
+ struct GNUNET_HashCode h_conversion_url;
+
+ /**
+ * Hash over the debit restrictions.
+ */
+ struct GNUNET_HashCode h_debit_restrictions;
+
+ /**
+ * Hash over the credit restrictions.
+ */
+ struct GNUNET_HashCode h_credit_restrictions;
+
};
GNUNET_NETWORK_STRUCT_END
@@ -1023,6 +1157,9 @@ GNUNET_NETWORK_STRUCT_END
enum GNUNET_GenericReturnValue
TALER_exchange_wire_signature_check (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
const struct TALER_MasterPublicKeyP *master_pub,
const struct TALER_MasterSignatureP *master_sig)
{
@@ -1033,6 +1170,14 @@ TALER_exchange_wire_signature_check (
TALER_payto_hash (payto_uri,
&wd.h_wire_details);
+ if (NULL != conversion_url)
+ GNUNET_CRYPTO_hash (conversion_url,
+ strlen (conversion_url) + 1,
+ &wd.h_conversion_url);
+ TALER_json_hash (debit_restrictions,
+ &wd.h_debit_restrictions);
+ TALER_json_hash (credit_restrictions,
+ &wd.h_credit_restrictions);
return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_WIRE_DETAILS,
&wd,
&master_sig->eddsa_signature,
@@ -1043,6 +1188,9 @@ TALER_exchange_wire_signature_check (
void
TALER_exchange_wire_signature_make (
const char *payto_uri,
+ const char *conversion_url,
+ const json_t *debit_restrictions,
+ const json_t *credit_restrictions,
const struct TALER_MasterPrivateKeyP *master_priv,
struct TALER_MasterSignatureP *master_sig)
{
@@ -1053,6 +1201,14 @@ TALER_exchange_wire_signature_make (
TALER_payto_hash (payto_uri,
&wd.h_wire_details);
+ if (NULL != conversion_url)
+ GNUNET_CRYPTO_hash (conversion_url,
+ strlen (conversion_url) + 1,
+ &wd.h_conversion_url);
+ TALER_json_hash (debit_restrictions,
+ &wd.h_debit_restrictions);
+ TALER_json_hash (credit_restrictions,
+ &wd.h_credit_restrictions);
GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
&wd,
&master_sig->eddsa_signature);
@@ -1145,4 +1301,88 @@ TALER_exchange_offline_partner_details_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by account to drain profits
+ * from the escrow account of the exchange.
+ */
+struct TALER_DrainProfitPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_MASTER_DRAIN_PROFITS
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+ struct TALER_WireTransferIdentifierRawP wtid;
+ struct GNUNET_TIME_TimestampNBO date;
+ struct TALER_AmountNBO amount;
+ struct GNUNET_HashCode h_section;
+ struct TALER_PaytoHashP h_payto;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_exchange_offline_profit_drain_sign (
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_Amount *amount,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterPrivateKeyP *master_priv,
+ struct TALER_MasterSignatureP *master_sig)
+{
+ struct TALER_DrainProfitPS wd = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_DRAIN_PROFIT),
+ .purpose.size = htonl (sizeof (wd)),
+ .wtid = *wtid,
+ .date = GNUNET_TIME_timestamp_hton (date),
+ };
+
+ GNUNET_CRYPTO_hash (account_section,
+ strlen (account_section) + 1,
+ &wd.h_section);
+ TALER_payto_hash (payto_uri,
+ &wd.h_payto);
+ TALER_amount_hton (&wd.amount,
+ amount);
+ GNUNET_CRYPTO_eddsa_sign (&master_priv->eddsa_priv,
+ &wd,
+ &master_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_exchange_offline_profit_drain_verify (
+ const struct TALER_WireTransferIdentifierRawP *wtid,
+ struct GNUNET_TIME_Timestamp date,
+ const struct TALER_Amount *amount,
+ const char *account_section,
+ const char *payto_uri,
+ const struct TALER_MasterPublicKeyP *master_pub,
+ const struct TALER_MasterSignatureP *master_sig)
+{
+ struct TALER_DrainProfitPS wd = {
+ .purpose.purpose = htonl (TALER_SIGNATURE_MASTER_DRAIN_PROFIT),
+ .purpose.size = htonl (sizeof (wd)),
+ .wtid = *wtid,
+ .date = GNUNET_TIME_timestamp_hton (date),
+ };
+
+ GNUNET_CRYPTO_hash (account_section,
+ strlen (account_section) + 1,
+ &wd.h_section);
+ TALER_payto_hash (payto_uri,
+ &wd.h_payto);
+ TALER_amount_hton (&wd.amount,
+ amount);
+ return GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_MASTER_DRAIN_PROFIT,
+ &wd,
+ &master_sig->eddsa_signature,
+ &master_pub->eddsa_pub);
+}
+
+
/* end of offline_signatures.c */
diff --git a/src/util/paths.conf b/src/util/paths.conf
index c1d2194d8..f34ccb41e 100644
--- a/src/util/paths.conf
+++ b/src/util/paths.conf
@@ -17,13 +17,13 @@ TALER_HOME = ${TALER_TEST_HOME:-${HOME:-${USERPROFILE}}}
# for how these should be used.
# Persistent data storage
-TALER_DATA_HOME = ${XDG_DATA_HOME:-$TALER_HOME/.local/share}/taler/
+TALER_DATA_HOME = ${XDG_DATA_HOME:-${TALER_HOME}/.local/share}/taler/
# Configuration files
-TALER_CONFIG_HOME = ${XDG_CONFIG_HOME:-$TALER_HOME/.config}/taler/
+TALER_CONFIG_HOME = ${XDG_CONFIG_HOME:-${TALER_HOME}/.config}/taler/
# Cached data, no big deal if lost
-TALER_CACHE_HOME = ${XDG_CACHE_HOME:-$TALER_HOME/.cache}/taler/
+TALER_CACHE_HOME = ${XDG_CACHE_HOME:-${TALER_HOME}/.cache}/taler/
# Runtime data (always lost on system boot)
TALER_RUNTIME_DIR = ${TMPDIR:-${TMP:-/tmp}}/taler-system-runtime/
diff --git a/src/util/payto.c b/src/util/payto.c
index 83a1a7e1d..6092b73fd 100644
--- a/src/util/payto.c
+++ b/src/util/payto.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2019-2022 Taler Systems SA
+ Copyright (C) 2019-2024 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -101,7 +101,9 @@ TALER_payto_get_method (const char *payto_uri)
char *
TALER_xtalerbank_account_from_payto (const char *payto)
{
+ const char *host;
const char *beg;
+ const char *nxt;
const char *end;
if (0 != strncasecmp (payto,
@@ -111,23 +113,27 @@ TALER_xtalerbank_account_from_payto (const char *payto)
GNUNET_break_op (0);
return NULL;
}
- beg = strchr (&payto[strlen (PAYTO "x-taler-bank/")],
+ host = &payto[strlen (PAYTO "x-taler-bank/")];
+ beg = strchr (host,
'/');
if (NULL == beg)
{
GNUNET_break_op (0);
return NULL;
}
- beg++; /* now points to $ACCOUNT */
+ beg++; /* now points to $ACCOUNT or $PATH */
+ nxt = strchr (beg,
+ '/');
end = strchr (beg,
'?');
if (NULL == end)
+ end = &beg[strlen (beg)];
+ while ( (NULL != nxt) &&
+ (end - nxt > 0) )
{
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid payto URI `%s'\n",
- payto);
- GNUNET_break_op (0);
- return GNUNET_strdup (beg); /* optional part is missing */
+ beg = nxt + 1;
+ nxt = strchr (beg,
+ '/');
}
return GNUNET_strndup (beg,
end - beg);
@@ -155,7 +161,6 @@ validate_payto_iban (const char *account_url)
IBAN_PREFIX,
strlen (IBAN_PREFIX)))
return NULL; /* not an IBAN */
-
iban = strrchr (account_url, '/') + 1;
#undef IBAN_PREFIX
q = strchr (iban,
@@ -189,6 +194,138 @@ validate_payto_iban (const char *account_url)
}
+/**
+ * Validate payto://x-taler-bank/ account URL (only account information,
+ * wire subject and amount are ignored).
+ *
+ * @param account_url payto URL to parse
+ * @return NULL on success, otherwise an error message
+ * to be freed by the caller
+ */
+static char *
+validate_payto_xtalerbank (const char *account_url)
+{
+ const char *user;
+ const char *nxt;
+ const char *beg;
+ const char *end;
+ const char *host;
+ bool dot_ok;
+ bool post_colon;
+ bool port_ok;
+
+#define XTALERBANK_PREFIX PAYTO "x-taler-bank/"
+ if (0 != strncasecmp (account_url,
+ XTALERBANK_PREFIX,
+ strlen (XTALERBANK_PREFIX)))
+ return NULL; /* not an IBAN */
+ host = &account_url[strlen (XTALERBANK_PREFIX)];
+#undef XTALERBANK_PREFIX
+ beg = strchr (host,
+ '/');
+ if (NULL == beg)
+ {
+ return GNUNET_strdup ("account name missing");
+ }
+ beg++; /* now points to $ACCOUNT or $PATH */
+ nxt = strchr (beg,
+ '/');
+ end = strchr (beg,
+ '?');
+ if (NULL == end)
+ {
+ return GNUNET_strdup ("'receiver-name' parameter missing");
+ }
+ while ( (NULL != nxt) &&
+ (end - nxt > 0) )
+ {
+ beg = nxt + 1;
+ nxt = strchr (beg,
+ '/');
+ }
+ user = beg;
+ if (user == host + 1)
+ {
+ return GNUNET_strdup ("domain name missing");
+ }
+ if ('-' == host[0])
+ return GNUNET_strdup ("invalid character '-' at start of domain name");
+ dot_ok = false;
+ post_colon = false;
+ port_ok = false;
+ while (host != user)
+ {
+ char c = host[0];
+
+ if ('/' == c)
+ {
+ /* path started, do not care about characters
+ in the path */
+ break;
+ }
+ if (':' == c)
+ {
+ post_colon = true;
+ host++;
+ continue;
+ }
+ if (post_colon)
+ {
+ if (! ( ('0' <= c) && ('9' >= c) ) )
+ {
+ char *err;
+
+ GNUNET_asprintf (&err,
+ "invalid character '%c' in port",
+ c);
+ return err;
+ }
+ port_ok = true;
+ }
+ else
+ {
+ if ('.' == c)
+ {
+ if (! dot_ok)
+ return GNUNET_strdup ("invalid domain name (misplaced '.')");
+ dot_ok = false;
+ }
+ else
+ {
+ if (! ( ('-' == c) ||
+ ( ('0' <= c) && ('9' >= c) ) ||
+ ( ('a' <= c) && ('z' >= c) ) ||
+ ( ('A' <= c) && ('Z' >= c) ) ) )
+ {
+ char *err;
+
+ GNUNET_asprintf (&err,
+ "invalid character '%c' in domain name",
+ c);
+ return err;
+ }
+ dot_ok = true;
+ }
+ }
+ host++;
+ }
+ if (post_colon && (! port_ok) )
+ {
+ return GNUNET_strdup ("port missing after ':'");
+ }
+ {
+ char *target;
+
+ target = payto_get_key (account_url,
+ "receiver-name=");
+ if (NULL == target)
+ return GNUNET_strdup ("'receiver-name' parameter missing");
+ GNUNET_free (target);
+ }
+ return NULL;
+}
+
+
char *
TALER_payto_validate (const char *payto_uri)
{
@@ -205,7 +342,7 @@ TALER_payto_validate (const char *payto_uri)
/* This is more strict than RFC 8905, alas we do not need to support messages/instructions/etc.,
and it is generally better to start with a narrow whitelist; we can be more permissive later ...*/
#define ALLOWED_CHARACTERS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:&?-.,=+"
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:&?-.,=+%~"
if (NULL == strchr (ALLOWED_CHARACTERS,
(int) payto_uri[i]))
{
@@ -229,6 +366,8 @@ TALER_payto_validate (const char *payto_uri)
if (NULL != (ret = validate_payto_iban (payto_uri)))
return ret; /* got a definitive answer */
+ if (NULL != (ret = validate_payto_xtalerbank (payto_uri)))
+ return ret; /* got a definitive answer */
/* Insert other bank account validation methods here later! */
@@ -256,6 +395,242 @@ TALER_payto_get_receiver_name (const char *payto)
}
+/**
+ * Normalize "payto://x-taler-bank/$HOSTNAME/[$PATH/]$USERNAME"
+ * URI in @a input.
+ *
+ * Converts to lower-case, except for [$PATH/]$USERNAME which
+ * is case-sensitive.
+ *
+ * @param len number of bytes in @a input
+ * @param input input URL
+ * @return NULL on error, otherwise 0-terminated canonicalized URI.
+ */
+static char *
+normalize_payto_x_taler_bank (size_t len,
+ const char input[static len])
+{
+ char *res = GNUNET_malloc (len + 1);
+ unsigned int sc = 0;
+
+ for (unsigned int i = 0; i<len; i++)
+ {
+ char c = input[i];
+
+ if ('/' == c)
+ sc++;
+ if (sc < 4)
+ res[i] = (char) tolower ((int) c);
+ else
+ res[i] = c;
+ }
+ return res;
+}
+
+
+/**
+ * Normalize "payto://iban[/$BIC]/$IBAN"
+ * URI in @a input.
+ *
+ * Removes $BIC (if present) and converts $IBAN to upper-case and prefix to
+ * lower-case.
+ *
+ * @param len number of bytes in @a input
+ * @param input input URL
+ * @return NULL on error, otherwise 0-terminated canonicalized URI.
+ */
+static char *
+normalize_payto_iban (size_t len,
+ const char input[static len])
+{
+ char *res;
+ size_t pos = 0;
+ unsigned int sc = 0;
+ bool have_bic;
+
+ for (unsigned int i = 0; i<len; i++)
+ if ('/' == input[i])
+ sc++;
+ if ( (sc > 4) ||
+ (sc < 3) )
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ have_bic = (4 == sc);
+ res = GNUNET_malloc (len + 1);
+ sc = 0;
+ for (unsigned int i = 0; i<len; i++)
+ {
+ char c = input[i];
+
+ if ('/' == c)
+ sc++;
+ switch (sc)
+ {
+ case 0: /* payto: */
+ case 1: /* / */
+ case 2: /* /iban */
+ res[pos++] = (char) tolower ((int) c);
+ break;
+ case 3: /* /$BIC or /$IBAN */
+ if (have_bic)
+ continue;
+ res[pos++] = (char) toupper ((int) c);
+ break;
+ case 4: /* /$IBAN */
+ res[pos++] = (char) toupper ((int) c);
+ break;
+ }
+ }
+ GNUNET_assert (pos <= len);
+ return res;
+}
+
+
+/**
+ * Normalize "payto://upi/$EMAIL"
+ * URI in @a input.
+ *
+ * Converts to lower-case.
+ *
+ * @param len number of bytes in @a input
+ * @param input input URL
+ * @return NULL on error, otherwise 0-terminated canonicalized URI.
+ */
+static char *
+normalize_payto_upi (size_t len,
+ const char input[static len])
+{
+ char *res = GNUNET_malloc (len + 1);
+
+ for (unsigned int i = 0; i<len; i++)
+ {
+ char c = input[i];
+
+ res[i] = (char) tolower ((int) c);
+ }
+ return res;
+}
+
+
+/**
+ * Normalize "payto://bitcoin/$ADDRESS"
+ * URI in @a input.
+ *
+ * Converts to lower-case, except for $ADDRESS which
+ * is case-sensitive.
+ *
+ * @param len number of bytes in @a input
+ * @param input input URL
+ * @return NULL on error, otherwise 0-terminated canonicalized URI.
+ */
+static char *
+normalize_payto_bitcoin (size_t len,
+ const char input[static len])
+{
+ char *res = GNUNET_malloc (len + 1);
+ unsigned int sc = 0;
+
+ for (unsigned int i = 0; i<len; i++)
+ {
+ char c = input[i];
+
+ if ('/' == c)
+ sc++;
+ if (sc < 3)
+ res[i] = (char) tolower ((int) c);
+ else
+ res[i] = c;
+ }
+ return res;
+}
+
+
+/**
+ * Normalize "payto://ilp/$NAME"
+ * URI in @a input.
+ *
+ * Converts to lower-case.
+ *
+ * @param len number of bytes in @a input
+ * @param input input URL
+ * @return NULL on error, otherwise 0-terminated canonicalized URI.
+ */
+static char *
+normalize_payto_ilp (size_t len,
+ const char input[static len])
+{
+ char *res = GNUNET_malloc (len + 1);
+
+ for (unsigned int i = 0; i<len; i++)
+ {
+ char c = input[i];
+
+ res[i] = (char) tolower ((int) c);
+ }
+ return res;
+}
+
+
+char *
+TALER_payto_normalize (const char *input)
+{
+ char *method;
+ const char *end;
+ char *ret;
+
+ {
+ char *err;
+
+ err = TALER_payto_validate (input);
+ if (NULL != err)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Malformed payto://-URI `%s': %s\n",
+ input,
+ err);
+ GNUNET_free (err);
+ return NULL;
+ }
+ }
+ method = TALER_payto_get_method (input);
+ if (NULL == method)
+ {
+ GNUNET_break (0);
+ return NULL;
+ }
+ end = strchr (input, '?');
+ if (NULL == end)
+ end = &input[strlen (input)];
+ if (0 == strcasecmp (method,
+ "x-taler-bank"))
+ ret = normalize_payto_x_taler_bank (end - input,
+ input);
+ else if (0 == strcasecmp (method,
+ "iban"))
+ ret = normalize_payto_iban (end - input,
+ input);
+ else if (0 == strcasecmp (method,
+ "upi"))
+ ret = normalize_payto_upi (end - input,
+ input);
+ else if (0 == strcasecmp (method,
+ "bitcoin"))
+ ret = normalize_payto_bitcoin (end - input,
+ input);
+ else if (0 == strcasecmp (method,
+ "ilp"))
+ ret = normalize_payto_ilp (end - input,
+ input);
+ else
+ ret = GNUNET_strndup (input,
+ end - input);
+ GNUNET_free (method);
+ return ret;
+}
+
+
void
TALER_payto_hash (const char *payto,
struct TALER_PaytoHashP *h_payto)
@@ -267,48 +642,9 @@ TALER_payto_hash (const char *payto,
&sha512);
GNUNET_static_assert (sizeof (sha512) > sizeof (*h_payto));
/* truncate */
- memcpy (h_payto,
- &sha512,
- sizeof (*h_payto));
-}
-
-
-char *
-TALER_payto_from_reserve (const char *exchange_base_url,
- const struct TALER_ReservePublicKeyP *reserve_pub)
-{
- char *payto_uri;
- char *rps;
- unsigned int skip;
- const char *extra = "";
- int url_len;
-
- rps = GNUNET_STRINGS_data_to_string_alloc (reserve_pub,
- sizeof (*reserve_pub));
- skip = 0;
- if (0 == strncasecmp (exchange_base_url,
- "http://",
- strlen ("http://")))
- {
- skip = strlen ("http://");
- extra = "+http";
- }
- if (0 == strncasecmp (exchange_base_url,
- "https://",
- strlen ("https://")))
- skip = strlen ("https://");
- url_len = strlen (exchange_base_url);
- if ('/' == exchange_base_url[url_len - 1])
- url_len--;
- url_len -= skip;
- GNUNET_asprintf (&payto_uri,
- "taler%s://reserve/%.*s/%s",
- extra,
- url_len,
- exchange_base_url + skip,
- rps);
- GNUNET_free (rps);
- return payto_uri;
+ GNUNET_memcpy (h_payto,
+ &sha512,
+ sizeof (*h_payto));
}
@@ -349,7 +685,7 @@ TALER_reserve_make_payto (const char *exchange_url,
/* exchange_url includes trailing '/' */
GNUNET_asprintf (&reserve_url,
"payto://%s/%s%s",
- is_http ? "taler+http" : "taler",
+ is_http ? "taler-reserve-http" : "taler-reserve",
exchange_url,
pub_str);
return reserve_url;
diff --git a/src/util/taler-config.in b/src/util/taler-config.in
index 07f6401d6..3399aec10 100644
--- a/src/util/taler-config.in
+++ b/src/util/taler-config.in
@@ -7,7 +7,7 @@ if ! type gnunet-config >/dev/null; then
exit 1
fi
-GC=`which gnunet-config`
-SO=`ls %libdir%/libtalerutil.so.* | sort -n | tail -n1`
+GC=$(which gnunet-config)
+SO=$(ls %libdir%/libtalerutil.so.* | sort -n | tail -n1)
export LD_PRELOAD=${LD_PRELOAD:-}:${SO}
exec gnunet-config "$@"
diff --git a/src/util/taler-exchange-secmod-cs.c b/src/util/taler-exchange-secmod-cs.c
index c8f0e242b..3e9ba1558 100644
--- a/src/util/taler-exchange-secmod-cs.c
+++ b/src/util/taler-exchange-secmod-cs.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2021 Taler Systems SA
+ Copyright (C) 2014-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -161,6 +161,164 @@ struct Denomination
/**
+ * A semaphore.
+ */
+struct Semaphore
+{
+ /**
+ * Mutex for the semaphore.
+ */
+ pthread_mutex_t mutex;
+
+ /**
+ * Condition variable for the semaphore.
+ */
+ pthread_cond_t cv;
+
+ /**
+ * Counter of the semaphore.
+ */
+ unsigned int ctr;
+};
+
+
+/**
+ * Job in a batch sign request.
+ */
+struct BatchJob;
+
+/**
+ * Handle for a thread that does work in batch signing.
+ */
+struct Worker
+{
+ /**
+ * Kept in a DLL.
+ */
+ struct Worker *prev;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct Worker *next;
+
+ /**
+ * Job this worker should do next.
+ */
+ struct BatchJob *job;
+
+ /**
+ * Semaphore to signal the worker that a job is available.
+ */
+ struct Semaphore sem;
+
+ /**
+ * Handle for this thread.
+ */
+ pthread_t pt;
+
+ /**
+ * Set to true if the worker should terminate.
+ */
+ bool do_shutdown;
+};
+
+
+/**
+ * Job in a batch sign request.
+ */
+struct BatchJob
+{
+
+ /**
+ * Thread doing the work.
+ */
+ struct Worker *worker;
+
+ /**
+ * Semaphore to signal that the job is finished.
+ */
+ struct Semaphore sem;
+
+ /**
+ * Computation status.
+ */
+ enum TALER_ErrorCode ec;
+
+ /**
+ * Which type of request is this?
+ */
+ enum { TYPE_SIGN, TYPE_RDERIVE } type;
+
+ /**
+ * Details depending on @e type.
+ */
+ union
+ {
+
+ /**
+ * Details if @e type is TYPE_SIGN.
+ */
+ struct
+ {
+ /**
+ * Request we are working on.
+ */
+ const struct TALER_CRYPTO_CsSignRequestMessage *sr;
+
+ /**
+ * Result with the signature.
+ */
+ struct GNUNET_CRYPTO_CsBlindSignature cs_answer;
+ } sign;
+
+ /**
+ * Details if type is TYPE_RDERIVE.
+ */
+ struct
+ {
+ /**
+ * Request we are answering.
+ */
+ const struct TALER_CRYPTO_CsRDeriveRequest *rdr;
+
+ /**
+ * Pair of points to return.
+ */
+ struct GNUNET_CRYPTO_CSPublicRPairP rpairp;
+
+ } rderive;
+
+ } details;
+
+};
+
+/**
+ * Head of DLL of workers ready for more work.
+ */
+static struct Worker *worker_head;
+
+/**
+ * Tail of DLL of workers ready for more work.
+ */
+static struct Worker *worker_tail;
+
+/**
+ * Lock for manipulating the worker DLL.
+ */
+static pthread_mutex_t worker_lock;
+
+/**
+ * Total number of workers that were started.
+ */
+static unsigned int workers;
+
+/**
+ * Semaphore used to grab a worker.
+ */
+static struct Semaphore worker_sem;
+
+/**
* Return value from main().
*/
static int global_ret;
@@ -183,6 +341,13 @@ static struct GNUNET_TIME_Timestamp now_tmp;
static char *keydir;
/**
+ * Name of the configuration section prefix to use. Usually either "taler-exchange" or
+ * "donau". The actual configuration section will then be
+ * "$SECTION-secmod-cs".
+ */
+static char *section;
+
+/**
* How much should coin creation (@e duration_withdraw) duration overlap
* with the next denomination? Basically, the starting time of two
* denominations is always @e duration_withdraw - #overlap_duration apart.
@@ -225,6 +390,12 @@ static pthread_mutex_t keys_lock;
*/
static uint64_t key_gen;
+/**
+ * Number of workers to launch. Note that connections to
+ * exchanges are NOT workers.
+ */
+static unsigned int max_workers = 16;
+
/**
* Generate the announcement message for @a dk.
@@ -259,14 +430,139 @@ generate_response (struct DenominationKey *dk)
&an->secm_sig);
an->secm_pub = TES_smpub;
p = (void *) &an[1];
- memcpy (p,
- denom->section,
- nlen);
+ GNUNET_memcpy (p,
+ denom->section,
+ nlen);
dk->an = an;
}
/**
+ * Do the actual signing work.
+ *
+ * @param h_cs hash of key to sign with
+ * @param planchet message to sign
+ * @param for_melt true if for melting
+ * @param[out] cs_sigp set to the CS signature
+ * @return #TALER_EC_NONE on success
+ */
+static enum TALER_ErrorCode
+do_sign (const struct TALER_CsPubHashP *h_cs,
+ const struct GNUNET_CRYPTO_CsBlindedMessage *planchet,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CsBlindSignature *cs_sigp)
+{
+ struct GNUNET_CRYPTO_CsRSecret r[2];
+ struct DenominationKey *dk;
+
+ GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
+ dk = GNUNET_CONTAINER_multihashmap_get (keys,
+ &h_cs->hash);
+ if (NULL == dk)
+ {
+ GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Signing request failed, denomination key %s unknown\n",
+ GNUNET_h2s (&h_cs->hash));
+ return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
+ }
+ if (GNUNET_TIME_absolute_is_future (dk->anchor.abs_time))
+ {
+ GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Signing request failed, denomination key %s is not yet valid\n",
+ GNUNET_h2s (&h_cs->hash));
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received request to sign over bytes with key %s\n",
+ GNUNET_h2s (&h_cs->hash));
+ GNUNET_assert (dk->rc < UINT_MAX);
+ dk->rc++;
+ GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
+ GNUNET_CRYPTO_cs_r_derive (&planchet->nonce,
+ for_melt ? "rm" : "rw",
+ &dk->denom_priv,
+ r);
+ GNUNET_CRYPTO_cs_sign_derive (&dk->denom_priv,
+ r,
+ planchet,
+ cs_sigp);
+ GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
+ GNUNET_assert (dk->rc > 0);
+ dk->rc--;
+ GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
+ return TALER_EC_NONE;
+}
+
+
+/**
+ * Generate error response that signing failed.
+ *
+ * @param client client to send response to
+ * @param ec error code to include
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+fail_sign (struct TES_Client *client,
+ enum TALER_ErrorCode ec)
+{
+ struct TALER_CRYPTO_SignFailure sf = {
+ .header.size = htons (sizeof (sf)),
+ .header.type = htons (TALER_HELPER_CS_MT_RES_SIGN_FAILURE),
+ .ec = htonl (ec)
+ };
+
+ return TES_transmit (client->csock,
+ &sf.header);
+}
+
+
+/**
+ * Generate error response that deriving failed.
+ *
+ * @param client client to send response to
+ * @param ec error code to include
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+fail_derive (struct TES_Client *client,
+ enum TALER_ErrorCode ec)
+{
+ struct TALER_CRYPTO_RDeriveFailure sf = {
+ .header.size = htons (sizeof (sf)),
+ .header.type = htons (TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE),
+ .ec = htonl (ec)
+ };
+
+ return TES_transmit (client->csock,
+ &sf.header);
+}
+
+
+/**
+ * Generate signature response.
+ *
+ * @param client client to send response to
+ * @param cs_answer signature to send
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+send_signature (struct TES_Client *client,
+ const struct GNUNET_CRYPTO_CsBlindSignature *cs_answer)
+{
+ struct TALER_CRYPTO_SignResponse sres;
+
+ sres.header.size = htons (sizeof (sres));
+ sres.header.type = htons (TALER_HELPER_CS_MT_RES_SIGNATURE);
+ sres.b = htonl (cs_answer->b);
+ sres.cs_answer = cs_answer->s_scalar;
+ return TES_transmit (client->csock,
+ &sres.header);
+}
+
+
+/**
* Handle @a client request @a sr to create signature. Create the
* signature using the respective key and return the result to
* the client.
@@ -277,108 +573,510 @@ generate_response (struct DenominationKey *dk)
*/
static enum GNUNET_GenericReturnValue
handle_sign_request (struct TES_Client *client,
- const struct TALER_CRYPTO_CsSignRequest *sr)
+ const struct TALER_CRYPTO_CsSignRequestMessage *sr)
{
- struct DenominationKey *dk;
- struct GNUNET_CRYPTO_CsRSecret r[2];
- struct TALER_BlindedDenominationCsSignAnswer cs_answer;
+ struct GNUNET_CRYPTO_CsBlindSignature cs_answer;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- bool for_melt;
+ enum TALER_ErrorCode ec;
+ enum GNUNET_GenericReturnValue ret;
+
+ ec = do_sign (&sr->h_cs,
+ &sr->message,
+ (0 != ntohl (sr->for_melt)),
+ &cs_answer);
+ if (TALER_EC_NONE != ec)
+ {
+ return fail_sign (client,
+ ec);
+ }
+ ret = send_signature (client,
+ &cs_answer);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Sent CS signature after %s\n",
+ GNUNET_TIME_relative2s (
+ GNUNET_TIME_absolute_get_duration (now),
+ GNUNET_YES));
+ return ret;
+}
+
+
+/**
+ * Do the actual deriving work.
+ *
+ * @param h_cs key to sign with
+ * @param nonce nonce to derive from
+ * @param for_melt true if for melting
+ * @param[out] rpairp set to the derived values
+ * @return #TALER_EC_NONE on success
+ */
+static enum TALER_ErrorCode
+do_derive (const struct TALER_CsPubHashP *h_cs,
+ const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
+ bool for_melt,
+ struct GNUNET_CRYPTO_CSPublicRPairP *rpairp)
+{
+ struct DenominationKey *dk;
+ struct GNUNET_CRYPTO_CSPrivateRPairP r_priv;
GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
dk = GNUNET_CONTAINER_multihashmap_get (keys,
- &sr->h_cs.hash);
+ &h_cs->hash);
if (NULL == dk)
{
- struct TALER_CRYPTO_SignFailure sf = {
- .header.size = htons (sizeof (sr)),
- .header.type = htons (TALER_HELPER_CS_MT_RES_SIGN_FAILURE),
- .ec = htonl (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN)
- };
-
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Signing request failed, denomination key %s unknown\n",
- GNUNET_h2s (&sr->h_cs.hash));
- return TES_transmit (client->csock,
- &sf.header);
+ "R Derive request failed, denomination key %s unknown\n",
+ GNUNET_h2s (&h_cs->hash));
+ return TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN;
}
if (GNUNET_TIME_absolute_is_future (dk->anchor.abs_time))
{
- /* it is too early */
- struct TALER_CRYPTO_SignFailure sf = {
- .header.size = htons (sizeof (sr)),
- .header.type = htons (TALER_HELPER_CS_MT_RES_SIGN_FAILURE),
- .ec = htonl (TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY)
- };
-
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Signing request failed, denomination key %s is not yet valid\n",
- GNUNET_h2s (&sr->h_cs.hash));
- return TES_transmit (client->csock,
- &sf.header);
+ "R Derive request failed, denomination key %s is not yet valid\n",
+ GNUNET_h2s (&h_cs->hash));
+ return TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY;
}
- for_melt = (0 != ntohl (sr->for_melt));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received request to sign over bytes with key %s\n",
- GNUNET_h2s (&sr->h_cs.hash));
+ "Received request to derive R with key %s\n",
+ GNUNET_h2s (&h_cs->hash));
GNUNET_assert (dk->rc < UINT_MAX);
dk->rc++;
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
- GNUNET_CRYPTO_cs_r_derive (&sr->planchet.nonce.nonce,
+ GNUNET_CRYPTO_cs_r_derive (nonce,
for_melt ? "rm" : "rw",
&dk->denom_priv,
- r);
- cs_answer.b = GNUNET_CRYPTO_cs_sign_derive (&dk->denom_priv,
- r,
- sr->planchet.c,
- &sr->planchet.nonce.nonce,
- &cs_answer.s_scalar);
-
+ r_priv.r);
GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
GNUNET_assert (dk->rc > 0);
dk->rc--;
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
- // if (NULL == cs_answer)
- // {
- // struct TALER_CRYPTO_SignFailure sf = {
- // .header.size = htons (sizeof (sf)),
- // .header.type = htons (TALER_HELPER_CS_MT_RES_SIGN_FAILURE),
- // .ec = htonl (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE)
- // };
-
- // GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- // "Signing request failed, worker failed to produce signature\n");
- // return TES_transmit (client->csock,
- // &sf.header);
- // }
-
- {
- struct TALER_CRYPTO_SignResponse *sr;
- size_t tsize;
- enum GNUNET_GenericReturnValue ret;
-
- tsize = sizeof (*sr) + sizeof(cs_answer);
- GNUNET_assert (tsize < UINT16_MAX);
- sr = GNUNET_malloc (tsize);
- sr->header.size = htons (tsize);
- sr->header.type = htons (TALER_HELPER_CS_MT_RES_SIGNATURE);
- sr->cs_answer = cs_answer;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sending CS signature after %s\n",
- GNUNET_TIME_relative2s (
- GNUNET_TIME_absolute_get_duration (now),
- GNUNET_YES));
- ret = TES_transmit (client->csock,
- &sr->header);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sent CS signature after %s\n",
- GNUNET_TIME_relative2s (
- GNUNET_TIME_absolute_get_duration (now),
- GNUNET_YES));
- GNUNET_free (sr);
- return ret;
+ GNUNET_CRYPTO_cs_r_get_public (&r_priv.r[0],
+ &rpairp->r_pub[0]);
+ GNUNET_CRYPTO_cs_r_get_public (&r_priv.r[1],
+ &rpairp->r_pub[1]);
+ return TALER_EC_NONE;
+}
+
+
+/**
+ * Generate derivation response.
+ *
+ * @param client client to send response to
+ * @param r_pub public point value pair to send
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+send_derivation (struct TES_Client *client,
+ const struct GNUNET_CRYPTO_CSPublicRPairP *r_pub)
+{
+ struct TALER_CRYPTO_RDeriveResponse rdr = {
+ .header.size = htons (sizeof (rdr)),
+ .header.type = htons (TALER_HELPER_CS_MT_RES_RDERIVE),
+ .r_pub = *r_pub
+ };
+
+ return TES_transmit (client->csock,
+ &rdr.header);
+}
+
+
+/**
+ * Initialize a semaphore @a sem with a value of @a val.
+ *
+ * @param[out] sem semaphore to initialize
+ * @param val initial value of the semaphore
+ */
+static void
+sem_init (struct Semaphore *sem,
+ unsigned int val)
+{
+ GNUNET_assert (0 ==
+ pthread_mutex_init (&sem->mutex,
+ NULL));
+ GNUNET_assert (0 ==
+ pthread_cond_init (&sem->cv,
+ NULL));
+ sem->ctr = val;
+}
+
+
+/**
+ * Decrement semaphore, blocks until this is possible.
+ *
+ * @param[in,out] sem semaphore to decrement
+ */
+static void
+sem_down (struct Semaphore *sem)
+{
+ GNUNET_assert (0 == pthread_mutex_lock (&sem->mutex));
+ while (0 == sem->ctr)
+ {
+ pthread_cond_wait (&sem->cv,
+ &sem->mutex);
+ }
+ sem->ctr--;
+ GNUNET_assert (0 == pthread_mutex_unlock (&sem->mutex));
+}
+
+
+/**
+ * Increment semaphore, blocks until this is possible.
+ *
+ * @param[in,out] sem semaphore to decrement
+ */
+static void
+sem_up (struct Semaphore *sem)
+{
+ GNUNET_assert (0 == pthread_mutex_lock (&sem->mutex));
+ sem->ctr++;
+ GNUNET_assert (0 == pthread_mutex_unlock (&sem->mutex));
+ pthread_cond_signal (&sem->cv);
+}
+
+
+/**
+ * Release resources used by @a sem.
+ *
+ * @param[in] sem semaphore to release (except the memory itself)
+ */
+static void
+sem_done (struct Semaphore *sem)
+{
+ GNUNET_break (0 == pthread_cond_destroy (&sem->cv));
+ GNUNET_break (0 == pthread_mutex_destroy (&sem->mutex));
+}
+
+
+/**
+ * Main logic of a worker thread. Grabs work, does it,
+ * grabs more work.
+ *
+ * @param cls a `struct Worker *`
+ * @returns cls
+ */
+static void *
+worker (void *cls)
+{
+ struct Worker *w = cls;
+
+ while (true)
+ {
+ GNUNET_assert (0 == pthread_mutex_lock (&worker_lock));
+ GNUNET_CONTAINER_DLL_insert (worker_head,
+ worker_tail,
+ w);
+ GNUNET_assert (0 == pthread_mutex_unlock (&worker_lock));
+ sem_up (&worker_sem);
+ sem_down (&w->sem);
+ if (w->do_shutdown)
+ break;
+ {
+ struct BatchJob *bj = w->job;
+
+ switch (bj->type)
+ {
+ case TYPE_SIGN:
+ {
+ const struct TALER_CRYPTO_CsSignRequestMessage *sr
+ = bj->details.sign.sr;
+
+ bj->ec = do_sign (&sr->h_cs,
+ &sr->message,
+ (0 != ntohl (sr->for_melt)),
+ &bj->details.sign.cs_answer);
+ break;
+ }
+ case TYPE_RDERIVE:
+ {
+ const struct TALER_CRYPTO_CsRDeriveRequest *rdr
+ = bj->details.rderive.rdr;
+ bj->ec = do_derive (&rdr->h_cs,
+ &rdr->nonce,
+ (0 != ntohl (rdr->for_melt)),
+ &bj->details.rderive.rpairp);
+ break;
+ }
+ }
+ sem_up (&bj->sem);
+ w->job = NULL;
+ }
+ }
+ return w;
+}
+
+
+/**
+ * Start batch job @a bj to sign @a sr.
+ *
+ * @param sr signature request to answer
+ * @param[out] bj job data structure
+ */
+static void
+start_sign_job (const struct TALER_CRYPTO_CsSignRequestMessage *sr,
+ struct BatchJob *bj)
+{
+ sem_init (&bj->sem,
+ 0);
+ bj->type = TYPE_SIGN;
+ bj->details.sign.sr = sr;
+ sem_down (&worker_sem);
+ GNUNET_assert (0 == pthread_mutex_lock (&worker_lock));
+ bj->worker = worker_head;
+ GNUNET_CONTAINER_DLL_remove (worker_head,
+ worker_tail,
+ bj->worker);
+ GNUNET_assert (0 == pthread_mutex_unlock (&worker_lock));
+ bj->worker->job = bj;
+ sem_up (&bj->worker->sem);
+}
+
+
+/**
+ * Start batch job @a bj to derive @a rdr.
+ *
+ * @param rdr derivation request to answer
+ * @param[out] bj job data structure
+ */
+static void
+start_derive_job (const struct TALER_CRYPTO_CsRDeriveRequest *rdr,
+ struct BatchJob *bj)
+{
+ sem_init (&bj->sem,
+ 0);
+ bj->type = TYPE_RDERIVE;
+ bj->details.rderive.rdr = rdr;
+ sem_down (&worker_sem);
+ GNUNET_assert (0 == pthread_mutex_lock (&worker_lock));
+ bj->worker = worker_head;
+ GNUNET_CONTAINER_DLL_remove (worker_head,
+ worker_tail,
+ bj->worker);
+ GNUNET_assert (0 == pthread_mutex_unlock (&worker_lock));
+ bj->worker->job = bj;
+ sem_up (&bj->worker->sem);
+}
+
+
+/**
+ * Finish a job @a bj for a @a client.
+ *
+ * @param client who made the request
+ * @param[in,out] bj job to finish
+ */
+static void
+finish_job (struct TES_Client *client,
+ struct BatchJob *bj)
+{
+ sem_down (&bj->sem);
+ sem_done (&bj->sem);
+ switch (bj->type)
+ {
+ case TYPE_SIGN:
+ if (TALER_EC_NONE != bj->ec)
+ {
+ fail_sign (client,
+ bj->ec);
+ return;
+ }
+ send_signature (client,
+ &bj->details.sign.cs_answer);
+ break;
+ case TYPE_RDERIVE:
+ if (TALER_EC_NONE != bj->ec)
+ {
+ fail_derive (client,
+ bj->ec);
+ return;
+ }
+ send_derivation (client,
+ &bj->details.rderive.rpairp);
+ break;
+ }
+}
+
+
+/**
+ * Handle @a client request @a sr to create a batch of signature. Creates the
+ * signatures using the respective key and return the results to the client.
+ *
+ * @param client the client making the request
+ * @param bsr the request details
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_batch_sign_request (struct TES_Client *client,
+ const struct TALER_CRYPTO_BatchSignRequest *bsr)
+{
+ uint32_t bs = ntohl (bsr->batch_size);
+ uint16_t size = ntohs (bsr->header.size) - sizeof (*bsr);
+ const void *off = (const void *) &bsr[1];
+ unsigned int idx = 0;
+ struct BatchJob jobs[GNUNET_NZL (bs)];
+ bool failure = false;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling batch sign request of size %u\n",
+ (unsigned int) bs);
+ if (bs > TALER_MAX_FRESH_COINS)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ while ( (bs > 0) &&
+ (size >= sizeof (struct TALER_CRYPTO_CsSignRequestMessage)) )
+ {
+ const struct TALER_CRYPTO_CsSignRequestMessage *sr = off;
+ uint16_t s = ntohs (sr->header.size);
+
+ if (s > size)
+ {
+ failure = true;
+ bs = idx;
+ break;
+ }
+ start_sign_job (sr,
+ &jobs[idx++]);
+ off += s;
+ size -= s;
+ }
+ GNUNET_break_op (0 == size);
+ bs = GNUNET_MIN (bs,
+ idx);
+ for (unsigned int i = 0; i<bs; i++)
+ finish_job (client,
+ &jobs[i]);
+ if (failure)
+ {
+ struct TALER_CRYPTO_SignFailure sf = {
+ .header.size = htons (sizeof (sf)),
+ .header.type = htons (TALER_HELPER_CS_MT_RES_BATCH_SIGN_FAILURE),
+ .ec = htonl (TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE)
+ };
+
+ GNUNET_break (0);
+ return TES_transmit (client->csock,
+ &sf.header);
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Handle @a client request @a sr to create a batch of derivations. Creates the
+ * derivations using the respective key and return the results to the client.
+ *
+ * @param client the client making the request
+ * @param bdr the request details
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+handle_batch_derive_request (struct TES_Client *client,
+ const struct TALER_CRYPTO_BatchDeriveRequest *bdr)
+{
+ uint32_t bs = ntohl (bdr->batch_size);
+ uint16_t size = ntohs (bdr->header.size) - sizeof (*bdr);
+ const void *off = (const void *) &bdr[1];
+ unsigned int idx = 0;
+ struct BatchJob jobs[bs];
+ bool failure = false;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Handling batch derivation request of size %u\n",
+ (unsigned int) bs);
+ if (bs > TALER_MAX_FRESH_COINS)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ while ( (bs > 0) &&
+ (size >= sizeof (struct TALER_CRYPTO_CsRDeriveRequest)) )
+ {
+ const struct TALER_CRYPTO_CsRDeriveRequest *rdr = off;
+ uint16_t s = ntohs (rdr->header.size);
+
+ if ( (s > size) ||
+ (s != sizeof (*rdr)) )
+ {
+ failure = true;
+ bs = idx;
+ break;
+ }
+ start_derive_job (rdr,
+ &jobs[idx++]);
+ off += s;
+ size -= s;
+ }
+ GNUNET_break_op (0 == size);
+ bs = GNUNET_MIN (bs,
+ idx);
+ for (unsigned int i = 0; i<bs; i++)
+ finish_job (client,
+ &jobs[i]);
+ if (failure)
+ {
+ GNUNET_break (0);
+ return fail_derive (client,
+ TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE);
+ }
+ return GNUNET_OK;
+}
+
+
+/**
+ * Start worker thread for batch processing.
+ *
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+start_worker (void)
+{
+ struct Worker *w;
+
+ w = GNUNET_new (struct Worker);
+ sem_init (&w->sem,
+ 0);
+ if (0 != pthread_create (&w->pt,
+ NULL,
+ &worker,
+ w))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
+ "pthread_create");
+ GNUNET_free (w);
+ return GNUNET_SYSERR;
+ }
+ workers++;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Stop all worker threads.
+ */
+static void
+stop_workers (void)
+{
+ while (workers > 0)
+ {
+ struct Worker *w;
+ void *result;
+
+ sem_down (&worker_sem);
+ GNUNET_assert (0 == pthread_mutex_lock (&worker_lock));
+ w = worker_head;
+ GNUNET_CONTAINER_DLL_remove (worker_head,
+ worker_tail,
+ w);
+ GNUNET_assert (0 == pthread_mutex_unlock (&worker_lock));
+ w->do_shutdown = true;
+ sem_up (&w->sem);
+ pthread_join (w->pt,
+ &result);
+ GNUNET_assert (result == w);
+ sem_done (&w->sem);
+ GNUNET_free (w);
+ workers--;
}
}
@@ -401,8 +1099,9 @@ setup_key (struct DenominationKey *dk,
GNUNET_CRYPTO_cs_private_key_generate (&priv);
GNUNET_CRYPTO_cs_private_key_get_public (&priv,
&pub);
- TALER_cs_pub_hash (&pub,
- &dk->h_cs);
+ GNUNET_CRYPTO_hash (&pub,
+ sizeof (pub),
+ &dk->h_cs.hash);
GNUNET_asprintf (&dk->filename,
"%s/%s/%llu",
keydir,
@@ -550,88 +1249,29 @@ static enum GNUNET_GenericReturnValue
handle_r_derive_request (struct TES_Client *client,
const struct TALER_CRYPTO_CsRDeriveRequest *rdr)
{
- struct DenominationKey *dk;
- struct TALER_DenominationCSPrivateRPairP r_priv;
- struct TALER_DenominationCSPublicRPairP r_pub;
+ struct GNUNET_CRYPTO_CSPublicRPairP r_pub;
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
- bool for_melt;
+ enum TALER_ErrorCode ec;
+ enum GNUNET_GenericReturnValue ret;
- GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
- dk = GNUNET_CONTAINER_multihashmap_get (keys,
- &rdr->h_cs.hash);
- if (NULL == dk)
+ ec = do_derive (&rdr->h_cs,
+ &rdr->nonce,
+ (0 != ntohl (rdr->for_melt)),
+ &r_pub);
+ if (TALER_EC_NONE != ec)
{
- struct TALER_CRYPTO_RDeriveFailure rdf = {
- .header.size = htons (sizeof (rdr)),
- .header.type = htons (TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE),
- .ec = htonl (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN)
- };
-
- GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "R Derive request failed, denomination key %s unknown\n",
- GNUNET_h2s (&rdr->h_cs.hash));
- return TES_transmit (client->csock,
- &rdf.header);
+ return fail_derive (client,
+ ec);
}
- if (GNUNET_TIME_absolute_is_future (dk->anchor.abs_time))
- {
- /* it is too early */
- struct TALER_CRYPTO_RDeriveFailure rdf = {
- .header.size = htons (sizeof (rdr)),
- .header.type = htons (TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE),
- .ec = htonl (TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY)
- };
- GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "R Derive request failed, denomination key %s is not yet valid\n",
- GNUNET_h2s (&rdr->h_cs.hash));
- return TES_transmit (client->csock,
- &rdf.header);
- }
- for_melt = (0 != ntohl (rdr->for_melt));
+ ret = send_derivation (client,
+ &r_pub);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Received request to derive R with key %s\n",
- GNUNET_h2s (&rdr->h_cs.hash));
- GNUNET_assert (dk->rc < UINT_MAX);
- dk->rc++;
- GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
- GNUNET_CRYPTO_cs_r_derive (&rdr->nonce.nonce,
- for_melt ? "rm" : "rw",
- &dk->denom_priv,
- r_priv.r);
- GNUNET_CRYPTO_cs_r_get_public (&r_priv.r[0],
- &r_pub.r_pub[0]);
- GNUNET_CRYPTO_cs_r_get_public (&r_priv.r[1],
- &r_pub.r_pub[1]);
- GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
- GNUNET_assert (dk->rc > 0);
- dk->rc--;
- GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
-
- {
- struct TALER_CRYPTO_RDeriveResponse rdr = {
- .header.size = htons (sizeof (struct TALER_CRYPTO_RDeriveResponse)),
- .header.type = htons (TALER_HELPER_CS_MT_RES_RDERIVE),
- .r_pub = r_pub
- };
- enum GNUNET_GenericReturnValue ret;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sending CS Derived R after %s\n",
- GNUNET_TIME_relative2s (
- GNUNET_TIME_absolute_get_duration (now),
- GNUNET_YES));
- ret = TES_transmit (client->csock,
- &rdr.header);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Sent CS Derived R after %s\n",
- GNUNET_TIME_relative2s (
- GNUNET_TIME_absolute_get_duration (now),
- GNUNET_YES));
- return ret;
- }
+ "Sent CS Derived R after %s\n",
+ GNUNET_TIME_relative2s (
+ GNUNET_TIME_absolute_get_duration (now),
+ GNUNET_YES));
+ return ret;
}
@@ -651,14 +1291,14 @@ cs_work_dispatch (struct TES_Client *client,
switch (ntohs (hdr->type))
{
case TALER_HELPER_CS_MT_REQ_SIGN:
- if (msize < sizeof (struct TALER_CRYPTO_CsSignRequest))
+ if (msize < sizeof (struct TALER_CRYPTO_CsSignRequestMessage))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
return handle_sign_request (
client,
- (const struct TALER_CRYPTO_CsSignRequest *) hdr);
+ (const struct TALER_CRYPTO_CsSignRequestMessage *) hdr);
case TALER_HELPER_CS_MT_REQ_REVOKE:
if (msize != sizeof (struct TALER_CRYPTO_CsRevokeRequest))
{
@@ -668,6 +1308,24 @@ cs_work_dispatch (struct TES_Client *client,
return handle_revoke_request (
client,
(const struct TALER_CRYPTO_CsRevokeRequest *) hdr);
+ case TALER_HELPER_CS_MT_REQ_BATCH_SIGN:
+ if (msize <= sizeof (struct TALER_CRYPTO_BatchSignRequest))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return handle_batch_sign_request (
+ client,
+ (const struct TALER_CRYPTO_BatchSignRequest *) hdr);
+ case TALER_HELPER_CS_MT_REQ_BATCH_RDERIVE:
+ if (msize <= sizeof (struct TALER_CRYPTO_BatchDeriveRequest))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return handle_batch_derive_request (
+ client,
+ (const struct TALER_CRYPTO_BatchDeriveRequest *) hdr);
case TALER_HELPER_CS_MT_REQ_RDERIVE:
if (msize != sizeof (struct TALER_CRYPTO_CsRDeriveRequest))
{
@@ -722,9 +1380,9 @@ cs_client_init (struct TES_Client *client)
NULL != dk;
dk = dk->next)
{
- memcpy (&buf[obs],
- dk->an,
- ntohs (dk->an->header.size));
+ GNUNET_memcpy (&buf[obs],
+ dk->an,
+ ntohs (dk->an->header.size));
obs += ntohs (dk->an->header.size);
}
}
@@ -821,18 +1479,18 @@ cs_update_client_keys (struct TES_Client *client)
.h_cs = key->h_cs
};
- memcpy (&buf[obs],
- &pn,
- sizeof (pn));
+ GNUNET_memcpy (&buf[obs],
+ &pn,
+ sizeof (pn));
GNUNET_assert (obs + sizeof (pn)
> obs);
obs += sizeof (pn);
}
else
{
- memcpy (&buf[obs],
- key->an,
- ntohs (key->an->header.size));
+ GNUNET_memcpy (&buf[obs],
+ key->an,
+ ntohs (key->an->header.size));
GNUNET_assert (obs + ntohs (key->an->header.size)
> obs);
obs += ntohs (key->an->header.size);
@@ -1122,20 +1780,19 @@ parse_key (struct Denomination *denom,
return;
}
{
- struct GNUNET_CRYPTO_CsPublicKey pub;
struct DenominationKey *dk;
struct DenominationKey *before;
- GNUNET_CRYPTO_cs_private_key_get_public (priv,
- &pub);
dk = GNUNET_new (struct DenominationKey);
dk->denom_priv = *priv;
dk->denom = denom;
dk->anchor = anchor;
dk->filename = GNUNET_strdup (filename);
- TALER_cs_pub_hash (&pub,
- &dk->h_cs);
- dk->denom_pub = pub;
+ GNUNET_CRYPTO_cs_private_key_get_public (priv,
+ &dk->denom_pub);
+ GNUNET_CRYPTO_hash (&dk->denom_pub,
+ sizeof (dk->denom_pub),
+ &dk->h_cs.hash);
generate_response (dk);
if (GNUNET_OK !=
GNUNET_CONTAINER_multihashmap_put (
@@ -1157,7 +1814,9 @@ parse_key (struct Denomination *denom,
NULL != pos;
pos = pos->next)
{
- if (GNUNET_TIME_timestamp_cmp (pos->anchor, >, anchor))
+ if (GNUNET_TIME_timestamp_cmp (pos->anchor,
+ >,
+ anchor))
break;
before = pos;
}
@@ -1213,7 +1872,7 @@ import_key (void *cls,
}
fd = open (filename,
- O_CLOEXEC);
+ O_RDONLY | O_CLOEXEC);
if (-1 == fd)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
@@ -1305,6 +1964,11 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *ct,
struct Denomination *denom)
{
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-cs",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
ct,
@@ -1314,6 +1978,7 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
ct,
"DURATION_WITHDRAW");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if (GNUNET_TIME_relative_cmp (overlap_duration,
@@ -1321,11 +1986,13 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
denom->duration_withdraw))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"OVERLAP_DURATION",
"Value given must be smaller than value for DURATION_WITHDRAW!");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
+ GNUNET_free (secname);
denom->section = GNUNET_strdup (ct);
return GNUNET_OK;
}
@@ -1440,28 +2107,36 @@ load_denominations (void *cls,
static enum GNUNET_GenericReturnValue
load_durations (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-cs",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-cs",
+ secname,
"OVERLAP_DURATION",
&overlap_duration))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"OVERLAP_DURATION");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-cs",
+ secname,
"LOOKAHEAD_SIGN",
&lookahead_sign))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"LOOKAHEAD_SIGN");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
+ GNUNET_free (secname);
return GNUNET_OK;
}
@@ -1481,6 +2156,8 @@ do_shutdown (void *cls)
GNUNET_SCHEDULER_cancel (keygen_task);
keygen_task = NULL;
}
+ stop_workers ();
+ sem_done (&worker_sem);
}
@@ -1503,6 +2180,7 @@ run (void *cls,
.updater = &cs_update_client_keys,
.init = &cs_client_init
};
+ char *secname;
(void) cls;
(void) args;
@@ -1517,31 +2195,62 @@ run (void *cls,
/* get current time again, we may be timetraveling! */
now = GNUNET_TIME_timestamp_get ();
}
+ GNUNET_asprintf (&secname,
+ "%s-secmod-cs",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-cs",
+ secname,
"KEY_DIR",
&keydir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-cs",
+ secname,
"KEY_DIR");
+ GNUNET_free (secname);
global_ret = EXIT_NOTCONFIGURED;
return;
}
+ GNUNET_free (secname);
if (GNUNET_OK !=
load_durations (cfg))
{
global_ret = EXIT_NOTCONFIGURED;
return;
}
- global_ret = TES_listen_start (cfg,
- "taler-exchange-secmod-cs",
- &cb);
+ {
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-cs",
+ section);
+ global_ret = TES_listen_start (cfg,
+ secname,
+ &cb);
+ GNUNET_free (secname);
+ }
if (0 != global_ret)
return;
+ sem_init (&worker_sem,
+ 0);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
+ if (0 == max_workers)
+ {
+ long lret;
+
+ lret = sysconf (_SC_NPROCESSORS_CONF);
+ if (lret <= 0)
+ lret = 1;
+ max_workers = (unsigned int) lret;
+ }
+ for (unsigned int i = 0; i<max_workers; i++)
+ if (GNUNET_OK !=
+ start_worker ())
+ {
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
/* Load denominations */
keys = GNUNET_CONTAINER_multihashmap_create (65536,
GNUNET_YES);
@@ -1592,6 +2301,11 @@ main (int argc,
char **argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('s',
+ "section",
+ "SECTION",
+ "name of the configuration section prefix to use, default is 'taler'",
+ &section),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_option_timestamp ('t',
@@ -1599,13 +2313,18 @@ main (int argc,
"TIMESTAMP",
"pretend it is a different time for the update",
&now_tmp),
+ GNUNET_GETOPT_option_uint ('w',
+ "workers",
+ "COUNT",
+ "use COUNT workers for parallel processing of batch requests",
+ &max_workers),
GNUNET_GETOPT_OPTION_END
};
enum GNUNET_GenericReturnValue ret;
/* Restrict permissions for the key files that we create. */
(void) umask (S_IWGRP | S_IROTH | S_IWOTH | S_IXOTH);
-
+ section = GNUNET_strdup ("taler-exchange");
/* force linker to link against libtalerutil; if we do
not do this, the linker may "optimize" libtalerutil
away and skip #TALER_OS_init(), which we do need */
diff --git a/src/util/taler-exchange-secmod-cs.conf b/src/util/taler-exchange-secmod-cs.conf
index 5085eab79..fa3cdba40 100644
--- a/src/util/taler-exchange-secmod-cs.conf
+++ b/src/util/taler-exchange-secmod-cs.conf
@@ -8,16 +8,16 @@
OVERLAP_DURATION = 5 m
# Where do we store the generated private keys.
-KEY_DIR = ${TALER_DATA_HOME}/exchange-secmod-cs/keys
+KEY_DIR = ${TALER_DATA_HOME}exchange-secmod-cs/keys
# Where does the helper listen for requests?
-UNIXPATH = $TALER_RUNTIME_DIR/exchange-secmod-cs/server.sock
+UNIXPATH = ${TALER_RUNTIME_DIR}exchange-secmod-cs/server.sock
# Directory for clients.
-CLIENT_DIR = $TALER_RUNTIME_DIR/exchange-secmod-cs/clients
+CLIENT_DIR = ${TALER_RUNTIME_DIR}exchange-secmod-cs/clients
# Where should the security module store its own private key?
-SM_PRIV_KEY = ${TALER_DATA_HOME}/exchange-secmod-cs/secmod-private-key
+SM_PRIV_KEY = ${TALER_DATA_HOME}exchange-secmod-cs/secmod-private-key
# For how long into the future do we pre-generate keys?
LOOKAHEAD_SIGN = 1 year
diff --git a/src/util/taler-exchange-secmod-cs.h b/src/util/taler-exchange-secmod-cs.h
index c71c3b9af..0321335da 100644
--- a/src/util/taler-exchange-secmod-cs.h
+++ b/src/util/taler-exchange-secmod-cs.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -26,17 +26,21 @@
#define TALER_HELPER_CS_MT_PURGE 1
#define TALER_HELPER_CS_MT_AVAIL 2
-#define TALER_HELPER_CS_MT_REQ_INIT 4
+#define TALER_HELPER_CS_MT_REQ_INIT 3
+#define TALER_HELPER_CS_MT_REQ_BATCH_SIGN 4
#define TALER_HELPER_CS_MT_REQ_SIGN 5
#define TALER_HELPER_CS_MT_REQ_REVOKE 6
-#define TALER_HELPER_CS_MT_REQ_RDERIVE 7
+#define TALER_HELPER_CS_MT_REQ_BATCH_RDERIVE 7
+#define TALER_HELPER_CS_MT_REQ_RDERIVE 8
-#define TALER_HELPER_CS_MT_RES_SIGNATURE 8
-#define TALER_HELPER_CS_MT_RES_SIGN_FAILURE 9
-#define TALER_HELPER_CS_MT_RES_RDERIVE 10
-#define TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE 11
+#define TALER_HELPER_CS_MT_RES_SIGNATURE 9
+#define TALER_HELPER_CS_MT_RES_SIGN_FAILURE 10
+#define TALER_HELPER_CS_MT_RES_BATCH_SIGN_FAILURE 11
+#define TALER_HELPER_CS_MT_RES_RDERIVE 12
+#define TALER_HELPER_CS_MT_RES_RDERIVE_FAILURE 13
+#define TALER_HELPER_CS_MT_RES_BATCH_RDERIVE_FAILURE 14
-#define TALER_HELPER_CS_SYNCED 12
+#define TALER_HELPER_CS_SYNCED 15
GNUNET_NETWORK_STRUCT_BEGIN
@@ -114,7 +118,7 @@ struct TALER_CRYPTO_CsKeyPurgeNotification
/**
* Message sent if a signature is requested.
*/
-struct TALER_CRYPTO_CsSignRequest
+struct TALER_CRYPTO_CsSignRequestMessage
{
/**
* Type is #TALER_HELPER_CS_MT_REQ_SIGN.
@@ -132,13 +136,35 @@ struct TALER_CRYPTO_CsSignRequest
struct TALER_CsPubHashP h_cs;
/**
- * Planchet containing message to sign
- * and nonce to derive R from
+ * Message to sign.
*/
- struct TALER_BlindedCsPlanchet planchet;
+ struct GNUNET_CRYPTO_CsBlindedMessage message;
};
+
+/**
+ * Message sent if a batch of signatures is requested.
+ */
+struct TALER_CRYPTO_BatchSignRequest
+{
+ /**
+ * Type is #TALER_HELPER_CS_MT_REQ_BATCH_SIGN.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Number of signatures to create, in NBO.
+ */
+ uint32_t batch_size;
+
+ /*
+ * Followed by @e batch_size batch sign requests.
+ */
+
+};
+
+
/**
* Message sent if a signature is requested.
*/
@@ -162,9 +188,32 @@ struct TALER_CRYPTO_CsRDeriveRequest
/**
* Withdraw nonce to derive R from
*/
- struct TALER_CsNonce nonce;
+ struct GNUNET_CRYPTO_CsSessionNonce nonce;
+};
+
+
+/**
+ * Message sent if a batch of derivations is requested.
+ */
+struct TALER_CRYPTO_BatchDeriveRequest
+{
+ /**
+ * Type is #TALER_HELPER_CS_MT_REQ_BATCH_RDERIVE.
+ */
+ struct GNUNET_MessageHeader header;
+
+ /**
+ * Number of derivations to create, in NBO.
+ */
+ uint32_t batch_size;
+
+ /*
+ * Followed by @e batch_size derive requests.
+ */
+
};
+
/**
* Message sent if a key was revoked.
*/
@@ -199,14 +248,14 @@ struct TALER_CRYPTO_SignResponse
struct GNUNET_MessageHeader header;
/**
- * For now, always zero.
+ * The chosen 'b' (0 or 1).
*/
- uint32_t reserved;
+ uint32_t b;
/**
- * Contains the blindided s and the chosen b
+ * Contains the blindided s.
*/
- struct TALER_BlindedDenominationCsSignAnswer cs_answer;
+ struct GNUNET_CRYPTO_CsBlindS cs_answer;
};
/**
@@ -225,9 +274,9 @@ struct TALER_CRYPTO_RDeriveResponse
uint32_t reserved;
/**
- * derived R
+ * Pair of derived R values
*/
- struct TALER_DenominationCSPublicRPairP r_pub;
+ struct GNUNET_CRYPTO_CSPublicRPairP r_pub;
};
diff --git a/src/util/taler-exchange-secmod-eddsa.c b/src/util/taler-exchange-secmod-eddsa.c
index 9f6f6d746..0b95447f7 100644
--- a/src/util/taler-exchange-secmod-eddsa.c
+++ b/src/util/taler-exchange-secmod-eddsa.c
@@ -137,6 +137,13 @@ static struct GNUNET_TIME_Timestamp now_tmp;
static char *keydir;
/**
+ * Name of the configuration section prefix to use. Usually either "taler-exchange" or
+ * "donau". The actual configuration section will then be
+ * "$SECTION-secmod-eddsa".
+ */
+static char *section;
+
+/**
* How much should coin creation duration overlap
* with the next key? Basically, the starting time of two
* keys is always #duration - #overlap_duration apart.
@@ -584,11 +591,11 @@ eddsa_client_init (struct TES_Client *client)
static enum GNUNET_GenericReturnValue
eddsa_update_client_keys (struct TES_Client *client)
{
+ GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Updating client %p to generation %llu\n",
client,
(unsigned long long) key_gen);
- GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
for (struct Key *key = keys_head;
NULL != key;
key = key->next)
@@ -826,9 +833,9 @@ parse_key (const char *filename,
filename);
return GNUNET_SYSERR;
}
- memcpy (&priv,
- buf,
- buf_size);
+ GNUNET_memcpy (&priv,
+ buf,
+ buf_size);
{
struct GNUNET_CRYPTO_EddsaPublicKey pub;
@@ -904,7 +911,7 @@ import_key (void *cls,
}
fd = open (filename,
- O_CLOEXEC);
+ O_RDONLY | O_CLOEXEC);
if (-1 == fd)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
@@ -991,39 +998,48 @@ import_key (void *cls,
static enum GNUNET_GenericReturnValue
load_durations (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-eddsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-eddsa",
+ secname,
"OVERLAP_DURATION",
&overlap_duration))
{
+ GNUNET_free (secname);
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"OVERLAP_DURATION");
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-eddsa",
+ secname,
"DURATION",
&duration))
{
+ GNUNET_free (secname);
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"DURATION");
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-eddsa",
+ secname,
"LOOKAHEAD_SIGN",
&lookahead_sign))
{
+ GNUNET_free (secname);
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"LOOKAHEAD_SIGN");
return GNUNET_SYSERR;
}
+ GNUNET_free (secname);
return GNUNET_OK;
}
@@ -1065,6 +1081,7 @@ run (void *cls,
.updater = eddsa_update_client_keys,
.init = eddsa_client_init
};
+ char *secname;
(void) cls;
(void) args;
@@ -1079,6 +1096,9 @@ run (void *cls,
/* get current time again, we may be timetraveling! */
now = GNUNET_TIME_timestamp_get ();
}
+ GNUNET_asprintf (&secname,
+ "%s-secmod-eddsa",
+ section);
if (GNUNET_OK !=
load_durations (cfg))
{
@@ -1087,21 +1107,31 @@ run (void *cls,
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-eddsa",
+ secname,
"KEY_DIR",
&keydir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-eddsa",
+ secname,
"KEY_DIR");
+ GNUNET_free (secname);
global_ret = EXIT_NOTCONFIGURED;
return;
}
+ GNUNET_free (secname);
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
- global_ret = TES_listen_start (cfg,
- "taler-exchange-secmod-eddsa",
- &cb);
+ {
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-eddsa",
+ section);
+ global_ret = TES_listen_start (cfg,
+ secname,
+ &cb);
+ GNUNET_free (secname);
+ }
if (0 != global_ret)
return;
/* Load keys */
@@ -1144,6 +1174,11 @@ main (int argc,
char **argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('s',
+ "section",
+ "SECTION",
+ "name of the configuration section prefix to use, default is 'taler'",
+ &section),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_option_timestamp ('t',
@@ -1157,7 +1192,7 @@ main (int argc,
/* Restrict permissions for the key files that we create. */
(void) umask (S_IWGRP | S_IROTH | S_IWOTH | S_IXOTH);
-
+ section = GNUNET_strdup ("taler-exchange");
/* force linker to link against libtalerutil; if we do
not do this, the linker may "optimize" libtalerutil
away and skip #TALER_OS_init(), which we do need */
diff --git a/src/util/taler-exchange-secmod-eddsa.conf b/src/util/taler-exchange-secmod-eddsa.conf
index ea09f0334..0cb4a4ffc 100644
--- a/src/util/taler-exchange-secmod-eddsa.conf
+++ b/src/util/taler-exchange-secmod-eddsa.conf
@@ -8,16 +8,16 @@
OVERLAP_DURATION = 5m
# Where do we store the private keys.
-KEY_DIR = ${TALER_DATA_HOME}/exchange-secmod-eddsa/keys
+KEY_DIR = ${TALER_DATA_HOME}exchange-secmod-eddsa/keys
# Where does the helper listen for requests?
-UNIXPATH = $TALER_RUNTIME_DIR/exchange-secmod-eddsa/server.sock
+UNIXPATH = ${TALER_RUNTIME_DIR}exchange-secmod-eddsa/server.sock
# Directory for clients.
-CLIENT_DIR = $TALER_RUNTIME_DIR/exchange-secmod-eddsa/clients
+CLIENT_DIR = ${TALER_RUNTIME_DIR}exchange-secmod-eddsa/clients
# Where should the security module store its own private key?
-SM_PRIV_KEY = ${TALER_DATA_HOME}/exchange-secmod-eddsa/secmod-private-key
+SM_PRIV_KEY = ${TALER_DATA_HOME}exchange-secmod-eddsa/secmod-private-key
# For how long into the future do we pre-generate keys?
LOOKAHEAD_SIGN = 1 year
diff --git a/src/util/taler-exchange-secmod-rsa.c b/src/util/taler-exchange-secmod-rsa.c
index d4b0845f6..c80e2e3c4 100644
--- a/src/util/taler-exchange-secmod-rsa.c
+++ b/src/util/taler-exchange-secmod-rsa.c
@@ -308,6 +308,13 @@ static struct GNUNET_TIME_Timestamp now_tmp;
static char *keydir;
/**
+ * Name of the configuration section prefix to use. Usually either "taler-exchange" or
+ * "donau". The actual configuration section will then be
+ * "$SECTION-secmod-rsa".
+ */
+static char *section;
+
+/**
* How much should coin creation (@e duration_withdraw) duration overlap
* with the next denomination? Basically, the starting time of two
* denominations is always @e duration_withdraw - #overlap_duration apart.
@@ -394,13 +401,13 @@ generate_response (struct DenominationKey *dk)
&an->secm_sig);
an->secm_pub = TES_smpub;
p = (void *) &an[1];
- memcpy (p,
- buf,
- buf_len);
+ GNUNET_memcpy (p,
+ buf,
+ buf_len);
GNUNET_free (buf);
- memcpy (p + buf_len,
- denom->section,
- nlen);
+ GNUNET_memcpy (p + buf_len,
+ denom->section,
+ nlen);
dk->an = an;
}
@@ -409,15 +416,13 @@ generate_response (struct DenominationKey *dk)
* Do the actual signing work.
*
* @param h_rsa key to sign with
- * @param blinded_msg message to sign
- * @param blinded_msg_size number of bytes in @a blinded_msg
+ * @param bm blinded message to sign
* @param[out] rsa_signaturep set to the RSA signature
* @return #TALER_EC_NONE on success
*/
static enum TALER_ErrorCode
do_sign (const struct TALER_RsaPubHashP *h_rsa,
- const void *blinded_msg,
- size_t blinded_msg_size,
+ const struct GNUNET_CRYPTO_RsaBlindedMessage *bm,
struct GNUNET_CRYPTO_RsaSignature **rsa_signaturep)
{
struct DenominationKey *dk;
@@ -447,15 +452,14 @@ do_sign (const struct TALER_RsaPubHashP *h_rsa,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received request to sign over %u bytes with key %s\n",
- (unsigned int) blinded_msg_size,
+ (unsigned int) bm->blinded_msg_size,
GNUNET_h2s (&h_rsa->hash));
GNUNET_assert (dk->rc < UINT_MAX);
dk->rc++;
GNUNET_assert (0 == pthread_mutex_unlock (&keys_lock));
rsa_signature
= GNUNET_CRYPTO_rsa_sign_blinded (dk->denom_priv,
- blinded_msg,
- blinded_msg_size);
+ bm);
GNUNET_assert (0 == pthread_mutex_lock (&keys_lock));
GNUNET_assert (dk->rc > 0);
dk->rc--;
@@ -524,9 +528,9 @@ send_signature (struct TES_Client *client,
sr = GNUNET_malloc (tsize);
sr->header.size = htons (tsize);
sr->header.type = htons (TALER_HELPER_RSA_MT_RES_SIGNATURE);
- memcpy (&sr[1],
- buf,
- buf_size);
+ GNUNET_memcpy (&sr[1],
+ buf,
+ buf_size);
GNUNET_free (buf);
ret = TES_transmit (client->csock,
&sr->header);
@@ -548,14 +552,15 @@ static enum GNUNET_GenericReturnValue
handle_sign_request (struct TES_Client *client,
const struct TALER_CRYPTO_SignRequest *sr)
{
- const void *blinded_msg = &sr[1];
- size_t blinded_msg_size = ntohs (sr->header.size) - sizeof (*sr);
+ struct GNUNET_CRYPTO_RsaBlindedMessage bm = {
+ .blinded_msg = (void *) &sr[1],
+ .blinded_msg_size = ntohs (sr->header.size) - sizeof (*sr)
+ };
struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
enum TALER_ErrorCode ec;
ec = do_sign (&sr->h_rsa,
- blinded_msg,
- blinded_msg_size,
+ &bm,
&rsa_signature);
if (TALER_EC_NONE != ec)
{
@@ -583,6 +588,7 @@ sem_init (struct Semaphore *sem,
GNUNET_assert (0 ==
pthread_cond_init (&sem->cv,
NULL));
+ sem->ctr = val;
}
@@ -659,12 +665,13 @@ worker (void *cls)
{
struct BatchJob *bj = w->job;
const struct TALER_CRYPTO_SignRequest *sr = bj->sr;
- const void *blinded_msg = &sr[1];
- size_t blinded_msg_size = ntohs (sr->header.size) - sizeof (*sr);
+ struct GNUNET_CRYPTO_RsaBlindedMessage bm = {
+ .blinded_msg = (void *) &sr[1],
+ .blinded_msg_size = ntohs (sr->header.size) - sizeof (*sr)
+ };
bj->ec = do_sign (&sr->h_rsa,
- blinded_msg,
- blinded_msg_size,
+ &bm,
&bj->rsa_signature);
sem_up (&bj->sem);
w->job = NULL;
@@ -765,6 +772,9 @@ handle_batch_sign_request (struct TES_Client *client,
off += s;
size -= s;
}
+ GNUNET_break_op (0 == size);
+ bs = GNUNET_MIN (bs,
+ idx);
for (unsigned int i = 0; i<bs; i++)
finish_job (client,
&jobs[i]);
@@ -876,8 +886,8 @@ setup_key (struct DenominationKey *dk,
}
buf_size = GNUNET_CRYPTO_rsa_private_key_encode (priv,
&buf);
- TALER_rsa_pub_hash (pub,
- &dk->h_rsa);
+ GNUNET_CRYPTO_rsa_public_key_hash (pub,
+ &dk->h_rsa.hash);
GNUNET_asprintf (&dk->filename,
"%s/%s/%llu",
keydir,
@@ -1107,9 +1117,9 @@ rsa_client_init (struct TES_Client *client)
NULL != dk;
dk = dk->next)
{
- memcpy (&buf[obs],
- dk->an,
- ntohs (dk->an->header.size));
+ GNUNET_memcpy (&buf[obs],
+ dk->an,
+ ntohs (dk->an->header.size));
GNUNET_assert (obs + ntohs (dk->an->header.size)
> obs);
obs += ntohs (dk->an->header.size);
@@ -1208,18 +1218,18 @@ rsa_update_client_keys (struct TES_Client *client)
.h_rsa = key->h_rsa
};
- memcpy (&buf[obs],
- &pn,
- sizeof (pn));
+ GNUNET_memcpy (&buf[obs],
+ &pn,
+ sizeof (pn));
GNUNET_assert (obs + sizeof (pn)
> obs);
obs += sizeof (pn);
}
else
{
- memcpy (&buf[obs],
- key->an,
- ntohs (key->an->header.size));
+ GNUNET_memcpy (&buf[obs],
+ key->an,
+ ntohs (key->an->header.size));
GNUNET_assert (obs + ntohs (key->an->header.size)
> obs);
obs += ntohs (key->an->header.size);
@@ -1251,6 +1261,7 @@ create_key (struct Denomination *denom,
struct GNUNET_TIME_Timestamp anchor;
anchor = now;
+ // FIXME: round down to multiple of 'anchor_round' value from configuration
if (NULL != denom->keys_tail)
{
struct GNUNET_TIME_Absolute abs;
@@ -1541,8 +1552,8 @@ parse_key (struct Denomination *denom,
dk->denom = denom;
dk->anchor = anchor;
dk->filename = GNUNET_strdup (filename);
- TALER_rsa_pub_hash (pub,
- &dk->h_rsa);
+ GNUNET_CRYPTO_rsa_public_key_hash (pub,
+ &dk->h_rsa.hash);
dk->denom_pub = pub;
generate_response (dk);
if (GNUNET_OK !=
@@ -1567,7 +1578,9 @@ parse_key (struct Denomination *denom,
NULL != pos;
pos = pos->next)
{
- if (GNUNET_TIME_timestamp_cmp (pos->anchor, >, anchor))
+ if (GNUNET_TIME_timestamp_cmp (pos->anchor,
+ >,
+ anchor))
break;
before = pos;
}
@@ -1623,13 +1636,12 @@ import_key (void *cls,
}
fd = open (filename,
- O_CLOEXEC);
+ O_RDONLY | O_CLOEXEC);
if (-1 == fd)
{
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
"open",
filename);
- GNUNET_break (0 == close (fd));
return GNUNET_OK;
}
if (0 != fstat (fd,
@@ -1718,7 +1730,11 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct Denomination *denom)
{
unsigned long long rsa_keysize;
+ char *secname;
+ GNUNET_asprintf (&secname,
+ "%s-secmod-rsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
ct,
@@ -1728,6 +1744,7 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
ct,
"DURATION_WITHDRAW");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if (GNUNET_TIME_relative_cmp (overlap_duration,
@@ -1735,9 +1752,10 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
denom->duration_withdraw))
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ section,
"OVERLAP_DURATION",
"Value given must be smaller than value for DURATION_WITHDRAW!");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
@@ -1749,6 +1767,7 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
ct,
"RSA_KEYSIZE");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if ( (rsa_keysize > 4 * 2048) ||
@@ -1758,8 +1777,10 @@ parse_denomination_cfg (const struct GNUNET_CONFIGURATION_Handle *cfg,
ct,
"RSA_KEYSIZE",
"Given RSA keysize outside of permitted range [1024,8192]\n");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
+ GNUNET_free (secname);
denom->rsa_keysize = (unsigned int) rsa_keysize;
denom->section = GNUNET_strdup (ct);
return GNUNET_OK;
@@ -1874,28 +1895,36 @@ load_denominations (void *cls,
static enum GNUNET_GenericReturnValue
load_durations (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-rsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-rsa",
+ secname,
"OVERLAP_DURATION",
&overlap_duration))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ secname,
"OVERLAP_DURATION");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_time (cfg,
- "taler-exchange-secmod-rsa",
+ secname,
"LOOKAHEAD_SIGN",
&lookahead_sign))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ secname,
"LOOKAHEAD_SIGN");
+ GNUNET_free (secname);
return GNUNET_SYSERR;
}
+ GNUNET_free (secname);
return GNUNET_OK;
}
@@ -1939,6 +1968,7 @@ run (void *cls,
.updater = rsa_update_client_keys,
.init = rsa_client_init
};
+ char *secname;
(void) cls;
(void) args;
@@ -1953,27 +1983,40 @@ run (void *cls,
/* get current time again, we may be timetraveling! */
now = GNUNET_TIME_timestamp_get ();
}
+ GNUNET_asprintf (&secname,
+ "%s-secmod-rsa",
+ section);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- "taler-exchange-secmod-rsa",
+ secname,
"KEY_DIR",
&keydir))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler-exchange-secmod-rsa",
+ secname,
"KEY_DIR");
+ GNUNET_free (secname);
global_ret = EXIT_NOTCONFIGURED;
return;
}
+ GNUNET_free (secname);
if (GNUNET_OK !=
load_durations (cfg))
{
global_ret = EXIT_NOTCONFIGURED;
return;
}
- global_ret = TES_listen_start (cfg,
- "taler-exchange-secmod-rsa",
- &cb);
+ {
+ char *secname;
+
+ GNUNET_asprintf (&secname,
+ "%s-secmod-rsa",
+ section);
+ global_ret = TES_listen_start (cfg,
+ secname,
+ &cb);
+ GNUNET_free (secname);
+ }
if (0 != global_ret)
return;
sem_init (&worker_sem,
@@ -1981,7 +2024,15 @@ run (void *cls,
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
if (0 == max_workers)
- max_workers = 1; /* FIXME: or determine from CPU? */
+ {
+ long lret;
+
+ lret = sysconf (_SC_NPROCESSORS_CONF);
+ if (lret <= 0)
+ lret = 1;
+ max_workers = (unsigned int) lret;
+ }
+
for (unsigned int i = 0; i<max_workers; i++)
if (GNUNET_OK !=
start_worker ())
@@ -2039,6 +2090,11 @@ main (int argc,
char **argv)
{
struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_option_string ('s',
+ "section",
+ "SECTION",
+ "name of the configuration section prefix to use, default is 'taler'",
+ &section),
GNUNET_GETOPT_option_timetravel ('T',
"timetravel"),
GNUNET_GETOPT_option_timestamp ('t',
@@ -2057,7 +2113,7 @@ main (int argc,
/* Restrict permissions for the key files that we create. */
(void) umask (S_IWGRP | S_IROTH | S_IWOTH | S_IXOTH);
-
+ section = GNUNET_strdup ("taler-exchange");
/* force linker to link against libtalerutil; if we do
not do this, the linker may "optimize" libtalerutil
away and skip #TALER_OS_init(), which we do need */
diff --git a/src/util/taler-exchange-secmod-rsa.conf b/src/util/taler-exchange-secmod-rsa.conf
index dfa87f050..978c40258 100644
--- a/src/util/taler-exchange-secmod-rsa.conf
+++ b/src/util/taler-exchange-secmod-rsa.conf
@@ -5,19 +5,22 @@
# wallets picking one key and then due to network latency
# another key being valid. The DURATION_WITHDRAW period
# must be longer than this value.
-OVERLAP_DURATION = 5 m
+OVERLAP_DURATION = 0 m
# Where do we store the generated private keys.
-KEY_DIR = ${TALER_DATA_HOME}/exchange-secmod-rsa/keys
+KEY_DIR = ${TALER_DATA_HOME}exchange-secmod-rsa/keys
# Where does the helper listen for requests?
-UNIXPATH = $TALER_RUNTIME_DIR/exchange-secmod-rsa/server.sock
+UNIXPATH = ${TALER_RUNTIME_DIR}exchange-secmod-rsa/server.sock
# Directory for clients.
-CLIENT_DIR = $TALER_RUNTIME_DIR/exchange-secmod-rsa/clients
+CLIENT_DIR = ${TALER_RUNTIME_DIR}exchange-secmod-rsa/clients
# Where should the security module store its own private key?
-SM_PRIV_KEY = ${TALER_DATA_HOME}/exchange-secmod-rsa/secmod-private-key
+SM_PRIV_KEY = ${TALER_DATA_HOME}exchange-secmod-rsa/secmod-private-key
# For how long into the future do we pre-generate keys?
LOOKAHEAD_SIGN = 1 year
+
+# Round down anchor key start date to multiples of this time.
+ANCHOR_ROUND = 1 ms \ No newline at end of file
diff --git a/src/util/taler-exchange-secmod-rsa.h b/src/util/taler-exchange-secmod-rsa.h
index dddaf3e1c..ffbceb48e 100644
--- a/src/util/taler-exchange-secmod-rsa.h
+++ b/src/util/taler-exchange-secmod-rsa.h
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020-2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -136,7 +136,7 @@ struct TALER_CRYPTO_SignRequest
/**
- * Message sent if a signature is requested.
+ * Message sent if a batch of signatures is requested.
*/
struct TALER_CRYPTO_BatchSignRequest
{
@@ -151,7 +151,7 @@ struct TALER_CRYPTO_BatchSignRequest
uint32_t batch_size;
/*
- * Followed by @e batch_size batch sign requests.
+ * Followed by @e batch_size sign requests.
*/
};
diff --git a/src/util/test_age_restriction.c b/src/util/test_age_restriction.c
index 3c5d52629..61499e5e0 100644
--- a/src/util/test_age_restriction.c
+++ b/src/util/test_age_restriction.c
@@ -21,12 +21,7 @@
*/
#include "platform.h"
#include "taler_util.h"
-#include "taler_crypto_lib.h"
-
-extern uint8_t
-get_age_group (
- const struct TALER_AgeMask *mask,
- uint8_t age);
+#include <gnunet/gnunet_common.h>
/**
* Encodes the age mask into a string, like "8:10:12:14:16:18:21"
@@ -85,24 +80,24 @@ test_groups (void)
.bits =
1 | 1 << 5 | 1 << 13 | 1 << 23,
- .group = { 0, 0, 0, 0, 0,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
+ .group = { 0, 0, 0, 0, 0,
+ 1, 1, 1, 1, 1, 1, 1, 1,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
},
{
.bits =
1 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21,
- .group = { 0, 0, 0, 0, 0, 0, 0, 0,
- 1, 1,
- 2, 2,
- 3, 3,
- 4, 4,
- 5, 5,
- 6, 6, 6,
- 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
+ .group = { 0, 0, 0, 0, 0, 0, 0, 0,
+ 1, 1,
+ 2, 2,
+ 3, 3,
+ 4, 4,
+ 5, 5,
+ 6, 6, 6,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7}
}
@@ -114,10 +109,10 @@ test_groups (void)
for (uint8_t i = 0; i < 32; i++)
{
- uint8_t r = get_age_group (&mask, i);
+ uint8_t r = TALER_get_age_group (&mask, i);
char *m = age_mask_to_string (&mask);
- printf ("get_age_group(%s, %2d) = %d vs %d (exp)\n",
+ printf ("TALER_get_age_group(%s, %2d) = %d vs %d (exp)\n",
m,
i,
r,
@@ -134,6 +129,177 @@ test_groups (void)
}
+enum GNUNET_GenericReturnValue
+test_dates (void)
+{
+ struct TALER_AgeMask mask = {
+ .bits = 1 | 1 << 5 | 1 << 9 | 1 << 13 | 1 << 17 | 1 << 21
+ };
+ struct
+ {
+ char *date;
+ uint32_t expected;
+ enum GNUNET_GenericReturnValue ret;
+ }
+ test [] = {
+ {.date = "abcd-00-00", .expected = 0, .ret = GNUNET_SYSERR},
+ {.date = "1900-00-01", .expected = 0, .ret = GNUNET_SYSERR},
+ {.date = "19000001", .expected = 0, .ret = GNUNET_SYSERR},
+ {.date = "2001-33-05", .expected = 0, .ret = GNUNET_SYSERR},
+ {.date = "2001-33-35", .expected = 0, .ret = GNUNET_SYSERR},
+
+ {.date = "1900-00-00", .expected = 0, .ret = GNUNET_OK},
+ {.date = "2001-00-00", .expected = 0, .ret = GNUNET_OK},
+ {.date = "2001-03-00", .expected = 0, .ret = GNUNET_OK},
+ {.date = "2001-03-05", .expected = 0, .ret = GNUNET_OK},
+
+ /* These dates should be far enough for the near future so that
+ * the expected values are correct. Will need adjustment in 2044 :) */
+ {.date = "2022-11-26", .expected = 19322, .ret = GNUNET_OK },
+ {.date = "2022-11-27", .expected = 19323, .ret = GNUNET_OK },
+ {.date = "2023-06-26", .expected = 19534, .ret = GNUNET_OK },
+ {.date = "2023-06-01", .expected = 19509, .ret = GNUNET_OK },
+ {.date = "2023-06-00", .expected = 19509, .ret = GNUNET_OK },
+ {.date = "2023-01-01", .expected = 19358, .ret = GNUNET_OK },
+ {.date = "2023-00-00", .expected = 19358, .ret = GNUNET_OK },
+
+ /* Special case: .date == NULL meands birthday == current date, which
+ * should be 21 years in the future. We will set these values below in the
+ * loop */
+ {.date = NULL, .expected = 0, .ret = GNUNET_OK },
+ };
+ char buf[256] = {0};
+
+ for (uint8_t t = 0; t < sizeof(test) / sizeof(test[0]); t++)
+ {
+ uint32_t d;
+ enum GNUNET_GenericReturnValue ret;
+ char *date = test[t].date;
+
+ if (NULL == test[t].date)
+ {
+ /* Special case: We set .date to the current date. */
+ time_t tn;
+ struct tm now;
+
+ time (&tn);
+ localtime_r (&tn, &now);
+ strftime (buf, sizeof(buf), "%Y-%m-%d", &now);
+ date = &buf[0];
+
+ /* The expected value is the number of days since 1970-01-01,
+ * counted simplistically */
+ test[t].expected = timegm (&now) / 60 / 60 / 24;
+ }
+
+ ret = TALER_parse_coarse_date (date,
+ &mask,
+ &d);
+ if (ret != test[t].ret)
+ {
+ printf (
+ "dates[%d] for date `%s` expected parser to return: %d, got: %d\n",
+ t, date, test[t].ret, ret);
+ return GNUNET_SYSERR;
+ }
+
+ if (ret == GNUNET_SYSERR)
+ continue;
+
+ if (d != test[t].expected)
+ {
+ printf (
+ "dates[%d] for date `%s` expected value %d, but got %d\n",
+ t, date, test[t].expected, d);
+ return GNUNET_SYSERR;
+ }
+
+ printf ("dates[%d] for date `%s` got expected value %d\n",
+ t, date, d);
+ }
+
+ printf ("done with dates\n");
+
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+test_lowest (void)
+{
+ struct TALER_AgeMask mask = {
+ .bits = 1 | 1 << 5 | 1 << 9 | 1 << 13 | 1 << 17 | 1 << 21
+ };
+
+ struct { uint8_t age; uint8_t expected; }
+ test [] = {
+ {.age = 1, .expected = 0 },
+ {.age = 2, .expected = 0 },
+ {.age = 3, .expected = 0 },
+ {.age = 4, .expected = 0 },
+ {.age = 5, .expected = 5 },
+ {.age = 6, .expected = 5 },
+ {.age = 7, .expected = 5 },
+ {.age = 8, .expected = 5 },
+ {.age = 9, .expected = 9 },
+ {.age = 10, .expected = 9 },
+ {.age = 11, .expected = 9 },
+ {.age = 12, .expected = 9 },
+ {.age = 13, .expected = 13 },
+ {.age = 14, .expected = 13 },
+ {.age = 15, .expected = 13 },
+ {.age = 16, .expected = 13 },
+ {.age = 17, .expected = 17 },
+ {.age = 18, .expected = 17 },
+ {.age = 19, .expected = 17 },
+ {.age = 20, .expected = 17 },
+ {.age = 21, .expected = 21 },
+ {.age = 22, .expected = 21 },
+ };
+
+ for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++)
+ {
+ uint8_t l = TALER_get_lowest_age (&mask, test[n].age);
+ printf ("lowest[%d] for age %d, expected lowest: %d, got: %d\n",
+ n, test[n].age, test[n].expected, l);
+ if (test[n].expected != l)
+ return GNUNET_SYSERR;
+ }
+
+ return GNUNET_OK;
+}
+
+
+enum GNUNET_GenericReturnValue
+test_adult (void)
+{
+ struct { struct TALER_AgeMask mask; uint8_t expected; }
+ test[] = {
+ { .mask = {.bits = 1 | 1 << 2},
+ .expected = 2 },
+ { .mask = {.bits = 1 | 1 << 2 | 1 << 3},
+ .expected = 3 },
+ { .mask = {.bits = 1 | 1 << 3},
+ .expected = 3 },
+ { .mask = {.bits = 1 | 1 << 22},
+ .expected = 22 },
+ { .mask = {.bits = 1 | 1 << 10 | 1 << 16 | 1 << 22},
+ .expected = 22 },
+ };
+ for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++)
+ {
+ uint8_t l = TALER_adult_age (&test[n].mask);
+ printf ("adult[%d] for mask %s, expected: %d, got: %d\n",
+ n, TALER_age_mask_to_string (&test[n].mask), test[n].expected, l);
+ if (test[n].expected != l)
+ return GNUNET_SYSERR;
+ }
+ printf ("done with adult\n");
+
+ return GNUNET_OK;
+}
+
+
static struct TALER_AgeMask age_mask = {
.bits = 1 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21
};
@@ -147,7 +313,7 @@ test_attestation (void)
enum GNUNET_GenericReturnValue ret;
struct TALER_AgeCommitmentProof acp[3] = {0};
struct TALER_AgeAttestation at = {0};
- uint8_t age_group = get_age_group (&age_mask, age);
+ uint8_t age_group = TALER_get_age_group (&age_mask, age);
struct GNUNET_HashCode seed;
@@ -155,15 +321,13 @@ test_attestation (void)
&seed,
sizeof(seed));
- ret = TALER_age_restriction_commit (&age_mask,
- age,
- &seed,
- &acp[0]);
-
+ TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp[0]);
printf (
- "commit(age:%d) == %d; proof.num: %ld; age_group: %d\n",
+ "commit(age:%d); proof.num: %ld; age_group: %d\n",
age,
- ret,
acp[0].proof.num,
age_group);
@@ -184,7 +348,7 @@ test_attestation (void)
{
for (uint8_t min = 0; min < 22; min++)
{
- uint8_t min_group = get_age_group (&age_mask, min);
+ uint8_t min_group = TALER_get_age_group (&age_mask, min);
ret = TALER_age_commitment_attest (&acp[i],
min,
@@ -260,11 +424,17 @@ main (int argc,
NULL);
if (GNUNET_OK != test_groups ())
return 1;
+ if (GNUNET_OK != test_lowest ())
+ return 2;
if (GNUNET_OK != test_attestation ())
{
GNUNET_break (0);
- return 2;
+ return 3;
}
+ if (GNUNET_OK != test_dates ())
+ return 4;
+ if (GNUNET_OK != test_adult ())
+ return 5;
return 0;
}
diff --git a/src/util/test_amount.c b/src/util/test_amount.c
index 1af383dcc..57d73b14f 100644
--- a/src/util/test_amount.c
+++ b/src/util/test_amount.c
@@ -21,7 +21,6 @@
*/
#include "platform.h"
#include "taler_util.h"
-#include "taler_amount_lib.h"
int
@@ -79,31 +78,31 @@ main (int argc,
/* test conversion with leading zero in fraction */
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount ("eur:0.02",
+ TALER_string_to_amount ("EUR:0.02",
&a2));
- GNUNET_assert (0 == strcasecmp ("eur",
+ GNUNET_assert (0 == strcasecmp ("EUR",
a2.currency));
GNUNET_assert (0 == a2.value);
GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 100 * 2 == a2.fraction);
c = TALER_amount_to_string (&a2);
- GNUNET_assert (0 == strcmp ("eur:0.02",
- c));
+ GNUNET_assert (0 == strcasecmp ("EUR:0.02",
+ c));
GNUNET_free (c);
/* test conversion with leading space and with fraction */
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (" eur:4.12",
+ TALER_string_to_amount (" EUR:4.12",
&a2));
- GNUNET_assert (0 == strcasecmp ("eur",
+ GNUNET_assert (0 == strcasecmp ("EUR",
a2.currency));
GNUNET_assert (4 == a2.value);
GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 100 * 12 == a2.fraction);
/* test use of local currency */
GNUNET_assert (GNUNET_OK ==
- TALER_string_to_amount (" *LOCAL:4444.1000",
+ TALER_string_to_amount (" LOCAL:4444.1000",
&a3));
- GNUNET_assert (0 == strcasecmp ("*LOCAL",
+ GNUNET_assert (0 == strcasecmp ("LOCAL",
a3.currency));
GNUNET_assert (4444 == a3.value);
GNUNET_assert (TALER_AMOUNT_FRAC_BASE / 10 == a3.fraction);
diff --git a/src/util/test_conversion.c b/src/util/test_conversion.c
new file mode 100644
index 000000000..00cb35e72
--- /dev/null
+++ b/src/util/test_conversion.c
@@ -0,0 +1,149 @@
+/*
+ This file is part of TALER
+ (C) 2023 Taler Systems SA
+
+ TALER is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file util/test_conversion.c
+ * @brief Tests for conversion logic
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "taler_util.h"
+#include <gnunet/gnunet_json_lib.h>
+
+/**
+ * Return value from main().
+ */
+static int global_ret;
+
+/**
+ * Handle to our helper.
+ */
+static struct TALER_JSON_ExternalConversion *ec;
+
+
+/**
+ * Type of a callback that receives a JSON @a result.
+ *
+ * @param cls closure
+ * @param status_type how did the process die
+ * @apram code termination status code from the process
+ * @param result some JSON result, NULL if we failed to get an JSON output
+ */
+static void
+conv_cb (void *cls,
+ enum GNUNET_OS_ProcessStatusType status_type,
+ unsigned long code,
+ const json_t *result)
+{
+ json_t *expect;
+
+ (void) cls;
+ (void) status_type;
+ ec = NULL;
+ global_ret = 3;
+ if (42 != code)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected return value from helper: %u\n",
+ (unsigned int) code);
+ return;
+ }
+ expect = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("foo",
+ "arg")
+ );
+ if (1 == json_equal (expect,
+ result))
+ {
+ global_ret = 0;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected JSON result\n");
+ json_dumpf (result,
+ stderr,
+ JSON_INDENT (2));
+ global_ret = 4;
+ }
+ json_decref (expect);
+}
+
+
+/**
+ * Function called on shutdown/CTRL-C.
+ *
+ * @param cls NULL
+ */
+static void
+do_shutdown (void *cls)
+{
+ (void) cls;
+ if (NULL != ec)
+ {
+ GNUNET_break (0);
+ global_ret = 2;
+ TALER_JSON_external_conversion_stop (ec);
+ ec = NULL;
+ }
+}
+
+
+/**
+ * Main test function.
+ *
+ * @param cls NULL
+ */
+static void
+run (void *cls)
+{
+ json_t *input;
+
+ (void) cls;
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
+ NULL);
+ input = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("key",
+ "foo")
+ );
+ ec = TALER_JSON_external_conversion_start (input,
+ &conv_cb,
+ NULL,
+ "./test_conversion.sh",
+ "test_conversion.sh",
+ "arg",
+ NULL);
+ json_decref (input);
+ GNUNET_assert (NULL != ec);
+}
+
+
+int
+main (int argc,
+ const char *const argv[])
+{
+ (void) argc;
+ (void) argv;
+ unsetenv ("XDG_DATA_HOME");
+ unsetenv ("XDG_CONFIG_HOME");
+ GNUNET_log_setup ("test-conversion",
+ "WARNING",
+ NULL);
+ GNUNET_OS_init (TALER_project_data_default ());
+ global_ret = 1;
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+ return global_ret;
+}
diff --git a/src/util/test_conversion.sh b/src/util/test_conversion.sh
new file mode 100755
index 000000000..26e1a36d8
--- /dev/null
+++ b/src/util/test_conversion.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+KEY=$(jq -r .key)
+echo -n "{\"$KEY\":\"$1\"}"
+exit 42
diff --git a/src/util/test_crypto.c b/src/util/test_crypto.c
index 186874e3c..2a2090952 100644
--- a/src/util/test_crypto.c
+++ b/src/util/test_crypto.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2015, 2020-2022 Taler Systems SA
+ (C) 2015, 2020-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -21,7 +21,6 @@
*/
#include "platform.h"
#include "taler_util.h"
-#include "taler_crypto_lib.h"
/**
@@ -38,14 +37,21 @@ test_high_level (void)
struct TALER_TransferPublicKeyP trans_pub;
struct TALER_TransferSecretP secret;
struct TALER_TransferSecretP secret2;
- union TALER_DenominationBlindingKeyP bks1;
- union TALER_DenominationBlindingKeyP bks2;
+ union GNUNET_CRYPTO_BlindingSecretP bks1;
+ union GNUNET_CRYPTO_BlindingSecretP bks2;
struct TALER_CoinSpendPrivateKeyP coin_priv1;
struct TALER_CoinSpendPrivateKeyP coin_priv2;
struct TALER_PlanchetMasterSecretP ps1;
struct TALER_PlanchetMasterSecretP ps2;
- struct TALER_ExchangeWithdrawValues alg1;
- struct TALER_ExchangeWithdrawValues alg2;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_RSA
+ };
+ struct TALER_ExchangeWithdrawValues alg1 = {
+ .blinding_inputs = &bi
+ };
+ struct TALER_ExchangeWithdrawValues alg2 = {
+ .blinding_inputs = &bi
+ };
GNUNET_CRYPTO_eddsa_key_create (&coin_priv.eddsa_priv);
GNUNET_CRYPTO_eddsa_key_get_public (&coin_priv.eddsa_priv,
@@ -71,14 +77,12 @@ test_high_level (void)
TALER_transfer_secret_to_planchet_secret (&secret,
0,
&ps1);
- alg1.cipher = TALER_DENOMINATION_RSA;
TALER_planchet_setup_coin_priv (&ps1,
&alg1,
&coin_priv1);
TALER_planchet_blinding_secret_create (&ps1,
&alg1,
&bks1);
- alg2.cipher = TALER_DENOMINATION_RSA;
TALER_transfer_secret_to_planchet_secret (&secret,
1,
&ps2);
@@ -117,31 +121,30 @@ test_planchets_rsa (uint8_t age)
{
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_DenominationPrivateKey dk_priv;
struct TALER_DenominationPublicKey dk_pub;
- struct TALER_ExchangeWithdrawValues alg_values;
+ const struct TALER_ExchangeWithdrawValues *alg_values;
struct TALER_PlanchetDetail pd;
struct TALER_BlindedDenominationSignature blind_sig;
struct TALER_FreshCoin coin;
struct TALER_CoinPubHashP c_hash;
struct TALER_AgeCommitmentHash *ach = NULL;
+ struct TALER_AgeCommitmentHash ah = {0};
+ alg_values = TALER_denom_ewv_rsa_singleton ();
if (0 < age)
{
struct TALER_AgeCommitmentProof acp;
- struct TALER_AgeCommitmentHash ah = {0};
struct GNUNET_HashCode seed;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- GNUNET_assert (GNUNET_OK ==
- TALER_age_restriction_commit (&age_mask,
- age,
- &seed,
- &acp));
+ TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
TALER_age_commitment_hash (&acp.commitment,
&ah);
ach = &ah;
@@ -151,12 +154,12 @@ test_planchets_rsa (uint8_t age)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
&ps,
sizeof (ps));
-
+ GNUNET_log_skip (1, GNUNET_YES);
GNUNET_assert (GNUNET_SYSERR ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_INVALID));
-
+ GNUNET_CRYPTO_BSA_INVALID));
+ GNUNET_log_skip (1, GNUNET_YES);
GNUNET_assert (GNUNET_SYSERR ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
@@ -165,19 +168,19 @@ test_planchets_rsa (uint8_t age)
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_RSA,
+ GNUNET_CRYPTO_BSA_RSA,
1024));
- alg_values.cipher = TALER_DENOMINATION_RSA;
TALER_planchet_setup_coin_priv (&ps,
- &alg_values,
+ alg_values,
&coin_priv);
TALER_planchet_blinding_secret_create (&ps,
- &alg_values,
+ alg_values,
&bks);
GNUNET_assert (GNUNET_OK ==
TALER_planchet_prepare (&dk_pub,
- &alg_values,
+ alg_values,
&bks,
+ NULL,
&coin_priv,
ach,
&c_hash,
@@ -195,7 +198,7 @@ test_planchets_rsa (uint8_t age)
&coin_priv,
ach,
&c_hash,
- &alg_values,
+ alg_values,
&coin));
TALER_blinded_denom_sig_free (&blind_sig);
TALER_denom_sig_free (&coin.sig);
@@ -206,39 +209,6 @@ test_planchets_rsa (uint8_t age)
/**
- * @brief Function for CS signatures to derive public R_0 and R_1
- *
- * @param nonce withdraw nonce from a client
- * @param denom_priv denomination privkey as long-term secret
- * @param r_pub the resulting R_0 and R_1
- * @return enum GNUNET_GenericReturnValue
- */
-static enum GNUNET_GenericReturnValue
-derive_r_public (
- const struct TALER_CsNonce *nonce,
- const struct TALER_DenominationPrivateKey *denom_priv,
- struct TALER_DenominationCSPublicRPairP *r_pub)
-{
- struct GNUNET_CRYPTO_CsRSecret r[2];
-
- if (denom_priv->cipher != TALER_DENOMINATION_CS)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- GNUNET_CRYPTO_cs_r_derive (&nonce->nonce,
- "rw",
- &denom_priv->details.cs_private_key,
- r);
- GNUNET_CRYPTO_cs_r_get_public (&r[0],
- &r_pub->r_pub[0]);
- GNUNET_CRYPTO_cs_r_get_public (&r[1],
- &r_pub->r_pub[1]);
- return GNUNET_OK;
-}
-
-
-/**
* Test the basic planchet functionality of creating a fresh planchet with CS denomination
* and extracting the respective signature.
*
@@ -249,11 +219,12 @@ test_planchets_cs (uint8_t age)
{
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_DenominationPrivateKey dk_priv;
struct TALER_DenominationPublicKey dk_pub;
struct TALER_PlanchetDetail pd;
struct TALER_CoinPubHashP c_hash;
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
struct TALER_BlindedDenominationSignature blind_sig;
struct TALER_FreshCoin coin;
struct TALER_ExchangeWithdrawValues alg_values;
@@ -268,12 +239,10 @@ test_planchets_cs (uint8_t age)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&seed,
sizeof(seed));
-
- GNUNET_assert (GNUNET_OK ==
- TALER_age_restriction_commit (&age_mask,
- age,
- &seed,
- &acp));
+ TALER_age_restriction_commit (&age_mask,
+ age,
+ &seed,
+ &acp);
TALER_age_commitment_hash (&acp.commitment,
&ah);
ach = &ah;
@@ -286,16 +255,17 @@ test_planchets_cs (uint8_t age)
GNUNET_assert (GNUNET_OK ==
TALER_denom_priv_create (&dk_priv,
&dk_pub,
- TALER_DENOMINATION_CS));
- alg_values.cipher = TALER_DENOMINATION_CS;
+ GNUNET_CRYPTO_BSA_CS));
TALER_cs_withdraw_nonce_derive (
&ps,
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce);
- GNUNET_assert (GNUNET_OK ==
- derive_r_public (
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &dk_priv,
- &alg_values.details.cs_values));
+ &nonce.cs_nonce);
+ // FIXME: define Taler abstraction for this:
+ alg_values.blinding_inputs
+ = GNUNET_CRYPTO_get_blinding_input_values (dk_priv.bsign_priv_key,
+ &nonce,
+ "rw");
+ TALER_denom_pub_hash (&dk_pub,
+ &pd.denom_pub_hash);
TALER_planchet_setup_coin_priv (&ps,
&alg_values,
&coin_priv);
@@ -306,6 +276,7 @@ test_planchets_cs (uint8_t age)
TALER_planchet_prepare (&dk_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
ach,
&c_hash,
@@ -315,7 +286,6 @@ test_planchets_cs (uint8_t age)
&dk_priv,
false,
&pd.blinded_planchet));
- TALER_planchet_detail_free (&pd);
GNUNET_assert (GNUNET_OK ==
TALER_planchet_to_coin (&dk_pub,
&blind_sig,
@@ -356,15 +326,24 @@ test_exchange_sigs (void)
struct TALER_MasterPrivateKeyP priv;
struct TALER_MasterPublicKeyP pub;
struct TALER_MasterSignatureP sig;
+ json_t *rest;
GNUNET_CRYPTO_eddsa_key_create (&priv.eddsa_priv);
+ rest = json_array ();
+ GNUNET_assert (NULL != rest);
TALER_exchange_wire_signature_make (pt,
+ NULL,
+ rest,
+ rest,
&priv,
&sig);
GNUNET_CRYPTO_eddsa_key_get_public (&priv.eddsa_priv,
&pub.eddsa_pub);
if (GNUNET_OK !=
TALER_exchange_wire_signature_check (pt,
+ NULL,
+ rest,
+ rest,
&pub,
&sig))
{
@@ -374,12 +353,28 @@ test_exchange_sigs (void)
if (GNUNET_OK ==
TALER_exchange_wire_signature_check (
"payto://x-taler-bank/localhost/Other",
+ NULL,
+ rest,
+ rest,
&pub,
&sig))
{
GNUNET_break (0);
return 1;
}
+ if (GNUNET_OK ==
+ TALER_exchange_wire_signature_check (
+ pt,
+ "http://example.com/",
+ rest,
+ rest,
+ &pub,
+ &sig))
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ json_decref (rest);
return 0;
}
@@ -482,12 +477,51 @@ test_contracts (void)
}
+static int
+test_attributes (void)
+{
+ struct TALER_AttributeEncryptionKeyP key;
+ void *eattr;
+ size_t eattr_size;
+ json_t *c;
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &key,
+ sizeof (key));
+ c = json_pack ("{s:s}", "test", "value");
+ GNUNET_assert (NULL != c);
+ TALER_CRYPTO_kyc_attributes_encrypt (&key,
+ c,
+ &eattr,
+ &eattr_size);
+ json_decref (c);
+ c = TALER_CRYPTO_kyc_attributes_decrypt (&key,
+ eattr,
+ eattr_size);
+ GNUNET_free (eattr);
+ if (NULL == c)
+ {
+ GNUNET_break (0);
+ return 1;
+ }
+ GNUNET_assert (0 ==
+ strcmp ("value",
+ json_string_value (json_object_get (c,
+ "test"))));
+ json_decref (c);
+ return 0;
+}
+
+
int
main (int argc,
const char *const argv[])
{
(void) argc;
(void) argv;
+ GNUNET_log_setup ("test-crypto",
+ "WARNING",
+ NULL);
if (0 != test_high_level ())
return 1;
if (0 != test_planchets (0))
@@ -500,6 +534,8 @@ main (int argc,
return 5;
if (0 != test_contracts ())
return 6;
+ if (0 != test_attributes ())
+ return 7;
return 0;
}
diff --git a/src/util/test_helper_cs.c b/src/util/test_helper_cs.c
index 566f1d611..93562e459 100644
--- a/src/util/test_helper_cs.c
+++ b/src/util/test_helper_cs.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2020, 2021 Taler Systems SA
+ (C) 2020, 2021, 2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -129,7 +129,7 @@ free_keys (void)
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_cs hash of the @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bs_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -140,7 +140,7 @@ key_cb (void *cls,
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_CsPubHashP *h_cs,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig)
{
@@ -155,7 +155,7 @@ key_cb (void *cls,
{
bool found = false;
- GNUNET_break (NULL == denom_pub);
+ GNUNET_break (NULL == bs_pub);
GNUNET_break (NULL == section_name);
for (unsigned int i = 0; i<MAX_KEYS; i++)
if (0 == GNUNET_memcmp (h_cs,
@@ -176,7 +176,7 @@ key_cb (void *cls,
return;
}
- GNUNET_break (NULL != denom_pub);
+ GNUNET_break (NULL != bs_pub);
for (unsigned int i = 0; i<MAX_KEYS; i++)
if (! keys[i].valid)
{
@@ -184,8 +184,8 @@ key_cb (void *cls,
keys[i].h_cs = *h_cs;
keys[i].start_time = start_time;
keys[i].validity_duration = validity_duration;
- TALER_denom_pub_deep_copy (&keys[i].denom_pub,
- denom_pub);
+ keys[i].denom_pub.bsign_pub_key
+ = GNUNET_CRYPTO_bsign_pub_incref (bs_pub);
num_keys++;
return;
}
@@ -268,9 +268,15 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
bool success = false;
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_CoinPubHashP c_hash;
- struct TALER_ExchangeWithdrawValues alg_values;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_CS
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
TALER_planchet_master_setup_random (&ps);
for (unsigned int i = 0; i<MAX_KEYS; i++)
@@ -279,21 +285,26 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
if (! keys[i].valid)
continue;
- GNUNET_assert (TALER_DENOMINATION_CS ==
- keys[i].denom_pub.cipher);
- pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
+ GNUNET_assert (GNUNET_CRYPTO_BSA_CS ==
+ keys[i].denom_pub.bsign_pub_key->cipher);
TALER_cs_withdraw_nonce_derive (
&ps,
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce);
+ &nonce.cs_nonce);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting R derivation with key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
- alg_values.cipher = TALER_DENOMINATION_CS;
- ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (
- dh,
- &keys[i].h_cs,
- &pd.blinded_planchet.details.cs_blinded_planchet.nonce,
- &alg_values.details.cs_values);
+ {
+ struct TALER_CRYPTO_CsDeriveRequest cdr = {
+ .h_cs = &keys[i].h_cs,
+ .nonce = &nonce.cs_nonce
+ };
+
+ ec = TALER_CRYPTO_helper_cs_r_derive (
+ dh,
+ &cdr,
+ false,
+ &bi.details.cs_values);
+ }
switch (ec)
{
case TALER_EC_NONE:
@@ -329,10 +340,12 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
TALER_planchet_prepare (&keys[i].denom_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
NULL, /* no age commitment */
&c_hash,
&pd));
+ TALER_blinded_planchet_free (&pd.blinded_planchet);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Successfully prepared planchet");
success = true;
@@ -372,8 +385,11 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
/* check R derivation does not work if the key is unknown */
{
struct TALER_CsPubHashP rnd;
- struct TALER_CsNonce nonce;
- struct TALER_DenominationCSPublicRPairP crp;
+ struct GNUNET_CRYPTO_CSPublicRPairP crp;
+ struct TALER_CRYPTO_CsDeriveRequest cdr = {
+ .h_cs = &rnd,
+ .nonce = &nonce.cs_nonce,
+ };
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd,
@@ -381,10 +397,10 @@ test_r_derive (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&nonce,
sizeof (nonce));
- ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (dh,
- &rnd,
- &nonce,
- &crp);
+ ec = TALER_CRYPTO_helper_cs_r_derive (dh,
+ &cdr,
+ false,
+ &crp);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{
GNUNET_break (0);
@@ -412,9 +428,15 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
bool success = false;
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
struct TALER_CoinPubHashP c_hash;
- struct TALER_ExchangeWithdrawValues alg_values;
+ struct GNUNET_CRYPTO_BlindingInputValues bi = {
+ .cipher = GNUNET_CRYPTO_BSA_CS
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bi
+ };
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
TALER_planchet_master_setup_random (&ps);
for (unsigned int i = 0; i<MAX_KEYS; i++)
@@ -423,21 +445,19 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
continue;
{
struct TALER_PlanchetDetail pd;
-
- pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
- // keys[i].denom_pub.cipher = TALER_DENOMINATION_CS;
+ struct TALER_CRYPTO_CsSignRequest csr;
+ struct TALER_CRYPTO_CsDeriveRequest cdr = {
+ .h_cs = &keys[i].h_cs,
+ .nonce = &nonce.cs_nonce
+ };
TALER_cs_withdraw_nonce_derive (&ps,
- &pd.blinded_planchet.details.
- cs_blinded_planchet.nonce);
- alg_values.cipher = TALER_DENOMINATION_CS;
- ec = TALER_CRYPTO_helper_cs_r_derive_withdraw (
+ &nonce.cs_nonce);
+ ec = TALER_CRYPTO_helper_cs_r_derive (
dh,
- &keys[i].h_cs,
- &pd.blinded_planchet.
- details.
- cs_blinded_planchet.nonce,
- &alg_values.details.cs_values);
+ &cdr,
+ false,
+ &bi.details.cs_values);
if (TALER_EC_NONE != ec)
continue;
TALER_planchet_setup_coin_priv (&ps,
@@ -446,11 +466,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
TALER_planchet_blinding_secret_create (&ps,
&alg_values,
&bks);
-
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
NULL, /* no age commitment */
&c_hash,
@@ -458,12 +478,15 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Requesting signature with key %s\n",
GNUNET_h2s (&keys[i].h_cs.hash));
- ec = TALER_CRYPTO_helper_cs_sign_withdraw (
+ csr.h_cs = &keys[i].h_cs;
+ csr.blinded_planchet
+ = &pd.blinded_planchet.blinded_message->details.cs_blinded_message;
+ ec = TALER_CRYPTO_helper_cs_sign (
dh,
- &keys[i].h_cs,
- &pd.blinded_planchet.details.
- cs_blinded_planchet,
+ &csr,
+ false,
&ds);
+ TALER_blinded_planchet_free (&pd.blinded_planchet);
}
switch (ec)
{
@@ -475,6 +498,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
{
/* key worked too early */
GNUNET_break (0);
+ TALER_blinded_denom_sig_free (&ds);
return 4;
}
if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_duration (
@@ -484,6 +508,7 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
{
/* key worked too later */
GNUNET_break (0);
+ TALER_blinded_denom_sig_free (&ds);
return 5;
}
{
@@ -500,8 +525,11 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
&coin))
{
GNUNET_break (0);
+ TALER_blinded_denom_sig_free (&ds);
return 6;
}
+ TALER_blinded_denom_sig_free (&ds);
+ TALER_denom_sig_free (&coin.sig);
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received valid signature for key %s\n",
@@ -544,25 +572,29 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
{
struct TALER_PlanchetDetail pd;
struct TALER_CsPubHashP rnd;
+ struct TALER_CRYPTO_CsSignRequest csr;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&rnd,
sizeof (rnd));
- pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[0].denom_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
NULL, /* no age commitment */
&c_hash,
&pd));
-
- ec = TALER_CRYPTO_helper_cs_sign_withdraw (
+ csr.h_cs = &rnd;
+ csr.blinded_planchet
+ = &pd.blinded_planchet.blinded_message->details.cs_blinded_message;
+ ec = TALER_CRYPTO_helper_cs_sign (
dh,
- &rnd,
- &pd.blinded_planchet.details.cs_blinded_planchet,
+ &csr,
+ false,
&ds);
+ TALER_blinded_planchet_free (&pd.blinded_planchet);
if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
{
if (TALER_EC_NONE == ec)
@@ -579,6 +611,226 @@ test_signing (struct TALER_CRYPTO_CsDenominationHelper *dh)
/**
+ * Test batch signing logic.
+ *
+ * @param dh handle to the helper
+ * @param batch_size how large should the batch be
+ * @param check_sigs also check unknown key and signatures
+ * @return 0 on success
+ */
+static int
+test_batch_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
+ unsigned int batch_size,
+ bool check_sigs)
+{
+ struct TALER_BlindedDenominationSignature ds[batch_size];
+ enum TALER_ErrorCode ec;
+ bool success = false;
+ struct TALER_PlanchetMasterSecretP ps[batch_size];
+ struct TALER_CoinSpendPrivateKeyP coin_priv[batch_size];
+ union GNUNET_CRYPTO_BlindingSecretP bks[batch_size];
+ struct TALER_CoinPubHashP c_hash[batch_size];
+ struct GNUNET_CRYPTO_BlindingInputValues bi[batch_size];
+ struct TALER_ExchangeWithdrawValues alg_values[batch_size];
+ union GNUNET_CRYPTO_BlindSessionNonce nonces[batch_size];
+
+ for (unsigned int i = 0; i<batch_size; i++)
+ TALER_planchet_master_setup_random (&ps[i]);
+ for (unsigned int k = 0; k<MAX_KEYS; k++)
+ {
+ if (! keys[k].valid)
+ continue;
+ {
+ struct TALER_PlanchetDetail pd[batch_size];
+ struct TALER_CRYPTO_CsSignRequest csr[batch_size];
+ struct TALER_CRYPTO_CsDeriveRequest cdr[batch_size];
+ struct GNUNET_CRYPTO_CSPublicRPairP crps[batch_size];
+
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ cdr[i].h_cs = &keys[k].h_cs;
+ cdr[i].nonce = &nonces[i].cs_nonce;
+ TALER_cs_withdraw_nonce_derive (
+ &ps[i],
+ &nonces[i].cs_nonce);
+ bi[i].cipher = GNUNET_CRYPTO_BSA_CS;
+ alg_values[i].blinding_inputs = &bi[i];
+ }
+ ec = TALER_CRYPTO_helper_cs_r_batch_derive (
+ dh,
+ batch_size,
+ cdr,
+ false,
+ crps);
+ if (TALER_EC_NONE != ec)
+ continue;
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ bi[i].details.cs_values = crps[i];
+ TALER_planchet_setup_coin_priv (&ps[i],
+ &alg_values[i],
+ &coin_priv[i]);
+ TALER_planchet_blinding_secret_create (&ps[i],
+ &alg_values[i],
+ &bks[i]);
+ GNUNET_assert (GNUNET_YES ==
+ TALER_planchet_prepare (&keys[k].denom_pub,
+ &alg_values[i],
+ &bks[i],
+ &nonces[i],
+ &coin_priv[i],
+ NULL, /* no age commitment */
+ &c_hash[i],
+ &pd[i]));
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Requesting signature with key %s\n",
+ GNUNET_h2s (&keys[k].h_cs.hash));
+ csr[i].h_cs = &keys[k].h_cs;
+ csr[i].blinded_planchet
+ = &pd[i].blinded_planchet.blinded_message->details.cs_blinded_message;
+ }
+ ec = TALER_CRYPTO_helper_cs_batch_sign (
+ dh,
+ batch_size,
+ csr,
+ false,
+ ds);
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ TALER_blinded_planchet_free (&pd[i].blinded_planchet);
+ }
+ }
+ switch (ec)
+ {
+ case TALER_EC_NONE:
+ if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_remaining (
+ keys[k].start_time.abs_time),
+ >,
+ GNUNET_TIME_UNIT_SECONDS))
+ {
+ /* key worked too early */
+ GNUNET_break (0);
+ return 4;
+ }
+ if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_duration (
+ keys[k].start_time.abs_time),
+ >,
+ keys[k].validity_duration))
+ {
+ /* key worked too later */
+ GNUNET_break (0);
+ return 5;
+ }
+ if (check_sigs)
+ {
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ struct TALER_FreshCoin coin;
+
+ if (GNUNET_OK !=
+ TALER_planchet_to_coin (&keys[k].denom_pub,
+ &ds[i],
+ &bks[i],
+ &coin_priv[i],
+ NULL, /* no age commitment */
+ &c_hash[i],
+ &alg_values[i],
+ &coin))
+ {
+ GNUNET_break (0);
+ return 6;
+ }
+ TALER_blinded_denom_sig_free (&ds[i]);
+ TALER_denom_sig_free (&coin.sig);
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received valid signature for key %s\n",
+ GNUNET_h2s (&keys[k].h_cs.hash));
+ }
+ else
+ {
+ for (unsigned int i = 0; i<batch_size; i++)
+ TALER_blinded_denom_sig_free (&ds[i]);
+ }
+ success = true;
+ break;
+ case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY:
+ /* This 'failure' is expected, we're testing also for the
+ error handling! */
+ if ( (GNUNET_TIME_relative_is_zero (
+ GNUNET_TIME_absolute_get_remaining (
+ keys[k].start_time.abs_time))) &&
+ (GNUNET_TIME_relative_cmp (
+ GNUNET_TIME_absolute_get_duration (
+ keys[k].start_time.abs_time),
+ <,
+ keys[k].validity_duration)) )
+ {
+ /* key should have worked! */
+ GNUNET_break (0);
+ return 6;
+ }
+ break;
+ default:
+ /* unexpected error */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected error %d\n",
+ ec);
+ return 7;
+ }
+ }
+ if (! success)
+ {
+ /* no valid key for signing found, also bad */
+ GNUNET_break (0);
+ return 16;
+ }
+
+ /* check signing does not work if the key is unknown */
+ if (check_sigs)
+ {
+ struct TALER_PlanchetDetail pd;
+ struct TALER_CsPubHashP rnd;
+ struct TALER_CRYPTO_CsSignRequest csr;
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &rnd,
+ sizeof (rnd));
+ GNUNET_assert (GNUNET_YES ==
+ TALER_planchet_prepare (&keys[0].denom_pub,
+ &alg_values[0],
+ &bks[0],
+ &nonces[0],
+ &coin_priv[0],
+ NULL, /* no age commitment */
+ &c_hash[0],
+ &pd));
+ csr.h_cs = &rnd;
+ csr.blinded_planchet
+ = &pd.blinded_planchet.blinded_message->details.cs_blinded_message;
+ ec = TALER_CRYPTO_helper_cs_batch_sign (
+ dh,
+ 1,
+ &csr,
+ false,
+ &ds[0]);
+ TALER_blinded_planchet_free (&pd.blinded_planchet);
+ if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
+ {
+ if (TALER_EC_NONE == ec)
+ TALER_blinded_denom_sig_free (&ds[0]);
+ GNUNET_break (0);
+ return 17;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Signing with invalid key %s failed as desired\n",
+ GNUNET_h2s (&rnd.hash));
+ }
+ return 0;
+}
+
+
+/**
* Benchmark signing logic.
*
* @param dh handle to the helper
@@ -593,8 +845,13 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
struct GNUNET_TIME_Relative duration;
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
- struct TALER_ExchangeWithdrawValues alg_values;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ struct GNUNET_CRYPTO_BlindingInputValues bv = {
+ .cipher = GNUNET_CRYPTO_BSA_CS
+ };
+ struct TALER_ExchangeWithdrawValues alg_values = {
+ .blinding_inputs = &bv
+ };
TALER_planchet_master_setup_random (&ps);
duration = GNUNET_TIME_UNIT_ZERO;
@@ -618,19 +875,20 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
{
struct TALER_CoinPubHashP c_hash;
struct TALER_PlanchetDetail pd;
-
- pd.blinded_planchet.cipher = TALER_DENOMINATION_CS;
- TALER_cs_withdraw_nonce_derive (&ps,
- &pd.blinded_planchet.details.
- cs_blinded_planchet.nonce);
- alg_values.cipher = TALER_DENOMINATION_CS;
- ec = TALER_CRYPTO_helper_cs_r_derive_melt (
+ union GNUNET_CRYPTO_BlindSessionNonce nonce;
+ struct TALER_CRYPTO_CsDeriveRequest cdr = {
+ .h_cs = &keys[i].h_cs,
+ .nonce = &nonce.cs_nonce
+ };
+
+ TALER_cs_withdraw_nonce_derive (
+ &ps,
+ &nonce.cs_nonce);
+ ec = TALER_CRYPTO_helper_cs_r_derive (
dh,
- &keys[i].h_cs,
- &pd.blinded_planchet.
- details.
- cs_blinded_planchet.nonce,
- &alg_values.details.cs_values);
+ &cdr,
+ true,
+ &bv.details.cs_values);
if (TALER_EC_NONE != ec)
continue;
TALER_planchet_setup_coin_priv (&ps,
@@ -643,6 +901,7 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
TALER_planchet_prepare (&keys[i].denom_pub,
&alg_values,
&bks,
+ &nonce,
&coin_priv,
NULL, /* no age commitment */
&c_hash,
@@ -652,12 +911,15 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
{
struct GNUNET_TIME_Absolute start = GNUNET_TIME_absolute_get ();
struct GNUNET_TIME_Relative delay;
+ struct TALER_CRYPTO_CsSignRequest csr;
- ec = TALER_CRYPTO_helper_cs_sign_melt (
+ csr.h_cs = &keys[i].h_cs;
+ csr.blinded_planchet
+ = &pd.blinded_planchet.blinded_message->details.cs_blinded_message;
+ ec = TALER_CRYPTO_helper_cs_sign (
dh,
- &keys[i].h_cs,
- &pd.blinded_planchet.details.
- cs_blinded_planchet,
+ &csr,
+ true,
&ds);
if (TALER_EC_NONE != ec)
break;
@@ -669,9 +931,10 @@ perf_signing (struct TALER_CRYPTO_CsDenominationHelper *dh,
if (NUM_SIGN_PERFS <= j)
break;
}
+ TALER_blinded_planchet_free (&pd.blinded_planchet);
}
- } /* for i */
- } /* for j */
+ } /* for i */
+ } /* for j */
fprintf (stderr,
"%u (%s) signature operations took %s\n",
(unsigned int) NUM_SIGN_PERFS,
@@ -707,6 +970,7 @@ par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
int ret;
dh = TALER_CRYPTO_helper_cs_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
GNUNET_assert (NULL != dh);
@@ -764,6 +1028,7 @@ run_test (void)
nanosleep (&req,
NULL);
dh = TALER_CRYPTO_helper_cs_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
if (NULL != dh)
@@ -796,6 +1061,34 @@ run_test (void)
if (0 == ret)
ret = test_signing (dh);
if (0 == ret)
+ ret = test_batch_signing (dh,
+ 2,
+ true);
+ if (0 == ret)
+ ret = test_batch_signing (dh,
+ 256,
+ true);
+ for (unsigned int i = 0; i<5; i++)
+ {
+ static unsigned int batches[] = { 1, 4, 16, 64, 256 };
+ unsigned int batch_size = batches[i];
+ struct GNUNET_TIME_Absolute start;
+ struct GNUNET_TIME_Relative duration;
+
+ start = GNUNET_TIME_absolute_get ();
+ if (0 != ret)
+ break;
+ ret = test_batch_signing (dh,
+ batch_size,
+ false);
+ duration = GNUNET_TIME_absolute_get_duration (start);
+ fprintf (stderr,
+ "%4u (batch) signature operations took %s (total real time)\n",
+ (unsigned int) batch_size,
+ GNUNET_STRINGS_relative_time_to_string (duration,
+ GNUNET_YES));
+ }
+ if (0 == ret)
ret = perf_signing (dh,
"sequential");
TALER_CRYPTO_helper_cs_disconnect (dh);
@@ -818,13 +1111,14 @@ main (int argc,
int ret;
enum GNUNET_OS_ProcessStatusType type;
unsigned long code;
+ const char *loglev = "WARNING";
(void) argc;
(void) argv;
unsetenv ("XDG_DATA_HOME");
unsetenv ("XDG_CONFIG_HOME");
GNUNET_log_setup ("test-helper-cs",
- "WARNING",
+ loglev,
NULL);
GNUNET_OS_init (TALER_project_data_default ());
libexec_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
@@ -840,7 +1134,7 @@ main (int argc,
"-c",
"test_helper_cs.conf",
"-L",
- "WARNING",
+ loglev,
NULL);
if (NULL == helper)
{
diff --git a/src/util/test_helper_eddsa.c b/src/util/test_helper_eddsa.c
index da1c51b46..0119e4278 100644
--- a/src/util/test_helper_eddsa.c
+++ b/src/util/test_helper_eddsa.c
@@ -365,6 +365,7 @@ par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
int ret;
esh = TALER_CRYPTO_helper_esign_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
if (NULL == esh)
@@ -427,6 +428,7 @@ run_test (void)
nanosleep (&req,
NULL);
esh = TALER_CRYPTO_helper_esign_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
if (NULL != esh)
diff --git a/src/util/test_helper_rsa.c b/src/util/test_helper_rsa.c
index 3f3eafddb..2bc15879f 100644
--- a/src/util/test_helper_rsa.c
+++ b/src/util/test_helper_rsa.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- (C) 2020, 2021 Taler Systems SA
+ (C) 2020, 2021, 2022 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -129,7 +129,7 @@ free_keys (void)
* @param validity_duration how long does the key remain available for signing;
* zero if the key has been revoked or purged
* @param h_rsa hash of the @a denom_pub that is available (or was purged)
- * @param denom_pub the public key itself, NULL if the key was revoked or purged
+ * @param bs_pub the public key itself, NULL if the key was revoked or purged
* @param sm_pub public key of the security module, NULL if the key was revoked or purged
* @param sm_sig signature from the security module, NULL if the key was revoked or purged
* The signature was already verified against @a sm_pub.
@@ -140,7 +140,7 @@ key_cb (void *cls,
struct GNUNET_TIME_Timestamp start_time,
struct GNUNET_TIME_Relative validity_duration,
const struct TALER_RsaPubHashP *h_rsa,
- const struct TALER_DenominationPublicKey *denom_pub,
+ struct GNUNET_CRYPTO_BlindSignPublicKey *bs_pub,
const struct TALER_SecurityModulePublicKeyP *sm_pub,
const struct TALER_SecurityModuleSignatureP *sm_sig)
{
@@ -155,7 +155,7 @@ key_cb (void *cls,
{
bool found = false;
- GNUNET_break (NULL == denom_pub);
+ GNUNET_break (NULL == bs_pub);
GNUNET_break (NULL == section_name);
for (unsigned int i = 0; i<MAX_KEYS; i++)
if (0 == GNUNET_memcmp (h_rsa,
@@ -176,7 +176,7 @@ key_cb (void *cls,
return;
}
- GNUNET_break (NULL != denom_pub);
+ GNUNET_break (NULL != bs_pub);
for (unsigned int i = 0; i<MAX_KEYS; i++)
if (! keys[i].valid)
{
@@ -184,8 +184,8 @@ key_cb (void *cls,
keys[i].h_rsa = *h_rsa;
keys[i].start_time = start_time;
keys[i].validity_duration = validity_duration;
- TALER_denom_pub_deep_copy (&keys[i].denom_pub,
- denom_pub);
+ keys[i].denom_pub.bsign_pub_key
+ = GNUNET_CRYPTO_bsign_pub_incref (bs_pub);
num_keys++;
return;
}
@@ -268,19 +268,22 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
enum TALER_ErrorCode ec;
bool success = false;
struct TALER_PlanchetMasterSecretP ps;
- struct TALER_ExchangeWithdrawValues alg_values;
+ const struct TALER_ExchangeWithdrawValues *alg_values
+ = TALER_denom_ewv_rsa_singleton ();
struct TALER_AgeCommitmentHash ach;
struct TALER_CoinPubHashP c_hash;
struct TALER_CoinSpendPrivateKeyP coin_priv;
- union TALER_DenominationBlindingKeyP bks;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
&ps,
sizeof (ps));
-
- alg_values.cipher = TALER_DENOMINATION_RSA;
- TALER_planchet_setup_coin_priv (&ps, &alg_values, &coin_priv);
- TALER_planchet_blinding_secret_create (&ps, &alg_values, &bks);
+ TALER_planchet_setup_coin_priv (&ps,
+ alg_values,
+ &coin_priv);
+ TALER_planchet_blinding_secret_create (&ps,
+ alg_values,
+ &bks);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&ach,
sizeof(ach));
@@ -289,17 +292,17 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
{
if (! keys[i].valid)
continue;
- if (TALER_DENOMINATION_RSA != keys[i].denom_pub.cipher)
+ if (GNUNET_CRYPTO_BSA_RSA !=
+ keys[i].denom_pub.bsign_pub_key->cipher)
continue;
{
- struct TALER_PlanchetDetail pd = {
- .blinded_planchet.cipher = TALER_DENOMINATION_RSA
- };
+ struct TALER_PlanchetDetail pd;
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub,
- &alg_values,
+ alg_values,
&bks,
+ NULL,
&coin_priv,
&ach,
&c_hash,
@@ -308,9 +311,11 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
struct TALER_CRYPTO_RsaSignRequest rsr = {
.h_rsa = &keys[i].h_rsa,
.msg =
- pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg,
+ pd.blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg,
.msg_size =
- pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg_size
+ pd.blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg_size
};
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -352,7 +357,7 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
&ds,
&bks,
&c_hash,
- &alg_values,
+ alg_values,
&keys[i].denom_pub))
{
GNUNET_break (0);
@@ -441,6 +446,227 @@ test_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh)
/**
+ * Test batch signing logic.
+ *
+ * @param dh handle to the helper
+ * @param batch_size how large should the batch be
+ * @param check_sigs also check unknown key and signatures
+ * @return 0 on success
+ */
+static int
+test_batch_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
+ unsigned int batch_size,
+ bool check_sigs)
+{
+ struct TALER_BlindedDenominationSignature ds[batch_size];
+ enum TALER_ErrorCode ec;
+ bool success = false;
+ struct TALER_PlanchetMasterSecretP ps[batch_size];
+ const struct TALER_ExchangeWithdrawValues *alg_values;
+ struct TALER_AgeCommitmentHash ach[batch_size];
+ struct TALER_CoinPubHashP c_hash[batch_size];
+ struct TALER_CoinSpendPrivateKeyP coin_priv[batch_size];
+ union GNUNET_CRYPTO_BlindingSecretP bks[batch_size];
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
+ &ps,
+ sizeof (ps));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &ach,
+ sizeof(ach));
+ alg_values = TALER_denom_ewv_rsa_singleton ();
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ TALER_planchet_setup_coin_priv (&ps[i],
+ alg_values,
+ &coin_priv[i]);
+ TALER_planchet_blinding_secret_create (&ps[i],
+ alg_values,
+ &bks[i]);
+ }
+ for (unsigned int k = 0; k<MAX_KEYS; k++)
+ {
+ if (success && ! check_sigs)
+ break; /* only do one round */
+ if (! keys[k].valid)
+ continue;
+ if (GNUNET_CRYPTO_BSA_RSA !=
+ keys[k].denom_pub.bsign_pub_key->cipher)
+ continue;
+ {
+ struct TALER_PlanchetDetail pd[batch_size];
+ struct TALER_CRYPTO_RsaSignRequest rsr[batch_size];
+
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ GNUNET_assert (GNUNET_YES ==
+ TALER_planchet_prepare (&keys[k].denom_pub,
+ alg_values,
+ &bks[i],
+ NULL,
+ &coin_priv[i],
+ &ach[i],
+ &c_hash[i],
+ &pd[i]));
+ rsr[i].h_rsa
+ = &keys[k].h_rsa;
+ rsr[i].msg
+ = pd[i].blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg;
+ rsr[i].msg_size
+ = pd[i].blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg_size;
+ }
+ ec = TALER_CRYPTO_helper_rsa_batch_sign (dh,
+ batch_size,
+ rsr,
+ ds);
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ if (TALER_EC_NONE == ec)
+ GNUNET_break (GNUNET_CRYPTO_BSA_RSA ==
+ ds[i].blinded_sig->cipher);
+ TALER_blinded_planchet_free (&pd[i].blinded_planchet);
+ }
+ }
+ switch (ec)
+ {
+ case TALER_EC_NONE:
+ if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_remaining (
+ keys[k].start_time.abs_time),
+ >,
+ GNUNET_TIME_UNIT_SECONDS))
+ {
+ /* key worked too early */
+ GNUNET_break (0);
+ return 4;
+ }
+ if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_duration (
+ keys[k].start_time.abs_time),
+ >,
+ keys[k].validity_duration))
+ {
+ /* key worked too later */
+ GNUNET_break (0);
+ return 5;
+ }
+ for (unsigned int i = 0; i<batch_size; i++)
+ {
+ struct TALER_DenominationSignature rs;
+
+ if (check_sigs)
+ {
+ if (GNUNET_OK !=
+ TALER_denom_sig_unblind (&rs,
+ &ds[i],
+ &bks[i],
+ &c_hash[i],
+ alg_values,
+ &keys[k].denom_pub))
+ {
+ GNUNET_break (0);
+ return 6;
+ }
+ }
+ TALER_blinded_denom_sig_free (&ds[i]);
+ if (check_sigs)
+ {
+ if (GNUNET_OK !=
+ TALER_denom_pub_verify (&keys[k].denom_pub,
+ &rs,
+ &c_hash[i]))
+ {
+ /* signature invalid */
+ GNUNET_break (0);
+ TALER_denom_sig_free (&rs);
+ return 7;
+ }
+ TALER_denom_sig_free (&rs);
+ }
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received valid signature for key %s\n",
+ GNUNET_h2s (&keys[k].h_rsa.hash));
+ success = true;
+ break;
+ case TALER_EC_EXCHANGE_DENOMINATION_HELPER_TOO_EARLY:
+ /* This 'failure' is expected, we're testing also for the
+ error handling! */
+ for (unsigned int i = 0; i<batch_size; i++)
+ TALER_blinded_denom_sig_free (&ds[i]);
+ if ( (GNUNET_TIME_relative_is_zero (
+ GNUNET_TIME_absolute_get_remaining (
+ keys[k].start_time.abs_time))) &&
+ (GNUNET_TIME_relative_cmp (
+ GNUNET_TIME_absolute_get_duration (
+ keys[k].start_time.abs_time),
+ <,
+ keys[k].validity_duration)) )
+ {
+ /* key should have worked! */
+ GNUNET_break (0);
+ return 6;
+ }
+ break;
+ case TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN:
+ for (unsigned int i = 0; i<batch_size; i++)
+ TALER_blinded_denom_sig_free (&ds[i]);
+ break;
+ default:
+ /* unexpected error */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Unexpected error %d at %s:%u\n",
+ ec,
+ __FILE__,
+ __LINE__);
+ for (unsigned int i = 0; i<batch_size; i++)
+ TALER_blinded_denom_sig_free (&ds[i]);
+ return 7;
+ }
+ }
+ if (! success)
+ {
+ /* no valid key for signing found, also bad */
+ GNUNET_break (0);
+ return 16;
+ }
+
+ /* check signing does not work if the key is unknown */
+ if (check_sigs)
+ {
+ struct TALER_RsaPubHashP rnd;
+ struct TALER_CRYPTO_RsaSignRequest rsr = {
+ .h_rsa = &rnd,
+ .msg = "Hello",
+ .msg_size = strlen ("Hello")
+ };
+
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
+ &rnd,
+ sizeof (rnd));
+ ec = TALER_CRYPTO_helper_rsa_batch_sign (dh,
+ 1,
+ &rsr,
+ ds);
+ if (TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN != ec)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Signing with invalid key returned unexpected status %d\n",
+ ec);
+ if (TALER_EC_NONE == ec)
+ TALER_blinded_denom_sig_free (ds);
+ GNUNET_break (0);
+ return 17;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Signing with invalid key %s failed as desired\n",
+ GNUNET_h2s (&rnd.hash));
+ }
+ return 0;
+}
+
+
+/**
* Benchmark signing logic.
*
* @param dh handle to the helper
@@ -456,13 +682,17 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
struct TALER_PlanchetMasterSecretP ps;
struct TALER_CoinSpendPrivateKeyP coin_priv;
struct TALER_AgeCommitmentHash ach;
- union TALER_DenominationBlindingKeyP bks;
- struct TALER_ExchangeWithdrawValues alg_values;
+ union GNUNET_CRYPTO_BlindingSecretP bks;
+ const struct TALER_ExchangeWithdrawValues *alg_values
+ = TALER_denom_ewv_rsa_singleton ();
TALER_planchet_master_setup_random (&ps);
- alg_values.cipher = TALER_DENOMINATION_RSA;
- TALER_planchet_setup_coin_priv (&ps, &alg_values, &coin_priv);
- TALER_planchet_blinding_secret_create (&ps, &alg_values, &bks);
+ TALER_planchet_setup_coin_priv (&ps,
+ alg_values,
+ &coin_priv);
+ TALER_planchet_blinding_secret_create (&ps,
+ alg_values,
+ &bks);
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
&ach,
sizeof(ach));
@@ -474,7 +704,8 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
{
if (! keys[i].valid)
continue;
- if (TALER_DENOMINATION_RSA != keys[i].denom_pub.cipher)
+ if (GNUNET_CRYPTO_BSA_RSA !=
+ keys[i].denom_pub.bsign_pub_key->cipher)
continue;
if (GNUNET_TIME_relative_cmp (GNUNET_TIME_absolute_get_remaining (
keys[i].start_time.abs_time),
@@ -492,8 +723,9 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
GNUNET_assert (GNUNET_YES ==
TALER_planchet_prepare (&keys[i].denom_pub,
- &alg_values,
+ alg_values,
&bks,
+ NULL,
&coin_priv,
&ach,
&c_hash,
@@ -506,9 +738,11 @@ perf_signing (struct TALER_CRYPTO_RsaDenominationHelper *dh,
struct TALER_CRYPTO_RsaSignRequest rsr = {
.h_rsa = &keys[i].h_rsa,
.msg =
- pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg,
+ pd.blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg,
.msg_size =
- pd.blinded_planchet.details.rsa_blinded_planchet.blinded_msg_size
+ pd.blinded_planchet.blinded_message->details.rsa_blinded_message.
+ blinded_msg_size
};
ec = TALER_CRYPTO_helper_rsa_sign (dh,
@@ -563,6 +797,7 @@ par_signing (struct GNUNET_CONFIGURATION_Handle *cfg)
int ret;
dh = TALER_CRYPTO_helper_rsa_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
GNUNET_assert (NULL != dh);
@@ -614,12 +849,14 @@ run_test (void)
return 77;
}
- fprintf (stderr, "Waiting for helper to start ... ");
+ fprintf (stderr,
+ "Waiting for helper to start ... ");
for (unsigned int i = 0; i<100; i++)
{
nanosleep (&req,
NULL);
dh = TALER_CRYPTO_helper_rsa_connect (cfg,
+ "taler-exchange",
&key_cb,
NULL);
if (NULL != dh)
@@ -650,6 +887,34 @@ run_test (void)
if (0 == ret)
ret = test_signing (dh);
if (0 == ret)
+ ret = test_batch_signing (dh,
+ 2,
+ true);
+ if (0 == ret)
+ ret = test_batch_signing (dh,
+ 256,
+ true);
+ for (unsigned int i = 0; i<5; i++)
+ {
+ static unsigned int batches[] = { 1, 4, 16, 64, 256 };
+ unsigned int batch_size = batches[i];
+ struct GNUNET_TIME_Absolute start;
+ struct GNUNET_TIME_Relative duration;
+
+ start = GNUNET_TIME_absolute_get ();
+ if (0 != ret)
+ break;
+ ret = test_batch_signing (dh,
+ batch_size,
+ false);
+ duration = GNUNET_TIME_absolute_get_duration (start);
+ fprintf (stderr,
+ "%4u (batch) signature operations took %s (total real time)\n",
+ (unsigned int) batch_size,
+ GNUNET_STRINGS_relative_time_to_string (duration,
+ GNUNET_YES));
+ }
+ if (0 == ret)
ret = perf_signing (dh,
"sequential");
TALER_CRYPTO_helper_rsa_disconnect (dh);
diff --git a/src/util/test_payto.c b/src/util/test_payto.c
index 4dc73a964..62ba7d28e 100644
--- a/src/util/test_payto.c
+++ b/src/util/test_payto.c
@@ -22,16 +22,16 @@
#include "taler_util.h"
#define CHECK(a,b) do { \
- GNUNET_assert (a != NULL); \
- GNUNET_assert (b != NULL); \
- if (0 != strcmp (a,b)) { \
- GNUNET_break (0); \
- fprintf (stderr, "Got %s, wanted %s\n", b, a); \
- GNUNET_free (b); \
- return 1; \
- } else { \
- GNUNET_free (b); \
- } \
+ GNUNET_assert (a != NULL); \
+ GNUNET_assert (b != NULL); \
+ if (0 != strcmp (a,b)) { \
+ GNUNET_break (0); \
+ fprintf (stderr, "Got %s, wanted %s\n", b, a); \
+ GNUNET_free (b); \
+ return 1; \
+ } else { \
+ GNUNET_free (b); \
+ } \
} while (0)
@@ -50,11 +50,55 @@ main (int argc,
TALER_iban_validate ("FR1420041010050500013M02606"));
GNUNET_assert (NULL ==
TALER_iban_validate ("DE89370400440532013000"));
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/hostname/username?receiver-name=foo");
+ GNUNET_assert (NULL == r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/hostname/~path/username?receiver-name=foo");
+ GNUNET_assert (NULL == r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/hostname/~path/username?receiver-name=fo/o");
+ GNUNET_assert (NULL == r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/hostname/path/username?receiver-name=foo");
+ GNUNET_assert (NULL == r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/https://hostname/username?receiver-name=foo");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/hostname:4a2/path/username?receiver-name=foo");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/-hostname/username?receiver-name=foo");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/domain..name/username?receiver-name=foo");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/domain..name/?receiver-name=foo");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
+ r = TALER_payto_validate (
+ "payto://x-taler-bank/domain.name/username");
+ GNUNET_assert (NULL != r);
+ GNUNET_free (r);
r = TALER_xtalerbank_account_from_payto (
"payto://x-taler-bank/localhost:1080/alice");
CHECK ("alice",
r);
r = TALER_xtalerbank_account_from_payto (
+ "payto://x-taler-bank/localhost:1080/path/alice");
+ CHECK ("alice",
+ r);
+ r = TALER_xtalerbank_account_from_payto (
+ "payto://x-taler-bank/localhost:1080/path/alice?receiver-name=ali/cia");
+ CHECK ("alice",
+ r);
+ r = TALER_xtalerbank_account_from_payto (
"payto://x-taler-bank/localhost:1080/alice?subject=hello&amount=EUR:1");
CHECK ("alice",
r);
diff --git a/src/util/tv_age_restriction.c b/src/util/tv_age_restriction.c
index a2b0a7451..9fc2b4823 100644
--- a/src/util/tv_age_restriction.c
+++ b/src/util/tv_age_restriction.c
@@ -34,16 +34,12 @@ get_age_group (
/**
* Encodes the age mask into a string, like "8:10:12:14:16:18:21"
- *
- * @param mask Age mask
- * @return String representation of the age mask, allocated by GNUNET_malloc.
- * Can be used as value in the TALER config.
*/
char *
age_mask_to_string (
- const struct TALER_AgeMask *m)
+ const struct TALER_AgeMask *mask)
{
- uint32_t bits = m->bits;
+ uint32_t bits = mask->bits;
unsigned int n = 0;
char *buf = GNUNET_malloc (32 * 3); // max characters possible
char *pos = buf;
diff --git a/src/util/url.c b/src/util/url.c
index a140a3a2e..bf59ba6ec 100644
--- a/src/util/url.c
+++ b/src/util/url.c
@@ -212,8 +212,6 @@ TALER_url_join (const char *base_url,
...)
{
struct GNUNET_Buffer buf = { 0 };
- va_list args;
- size_t len;
GNUNET_assert (NULL != base_url);
GNUNET_assert (NULL != path);
@@ -224,40 +222,45 @@ TALER_url_join (const char *base_url,
"Empty base URL specified\n");
return NULL;
}
- if ('/' != base_url[strlen (base_url) - 1])
+ if ('\0' != path[0])
{
- /* Must be an actual base URL! */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Base URL `%s' does not end with '/', cannot join with `%s'\n",
- base_url,
- path);
- return NULL;
+ if ('/' != base_url[strlen (base_url) - 1])
+ {
+ /* Must be an actual base URL! */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Base URL `%s' does not end with '/', cannot join with `%s'\n",
+ base_url,
+ path);
+ return NULL;
+ }
+ if ('/' == path[0])
+ {
+ /* The path must be relative. */
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Path `%s' is not relative\n",
+ path);
+ return NULL;
+ }
}
- if ('/' == path[0])
+
{
- /* The path must be relative. */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Path `%s' is not relative\n",
- path);
- return NULL;
+ va_list args;
+ size_t len;
+
+ va_start (args,
+ path);
+ len = strlen (base_url) + strlen (path) + 1;
+ len += calculate_argument_length (args);
+ GNUNET_buffer_prealloc (&buf,
+ len);
+ GNUNET_buffer_write_str (&buf,
+ base_url);
+ GNUNET_buffer_write_str (&buf,
+ path);
+ serialize_arguments (&buf,
+ args);
+ va_end (args);
}
-
- va_start (args,
- path);
-
- len = strlen (base_url) + strlen (path) + 1;
- len += calculate_argument_length (args);
-
- GNUNET_buffer_prealloc (&buf,
- len);
- GNUNET_buffer_write_str (&buf,
- base_url);
- GNUNET_buffer_write_str (&buf,
- path);
- serialize_arguments (&buf,
- args);
- va_end (args);
-
return GNUNET_buffer_reap_str (&buf);
}
@@ -322,7 +325,7 @@ TALER_url_valid_charset (const char *url)
for (unsigned int i = 0; '\0' != url[i]; i++)
{
#define ALLOWED_CHARACTERS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:;&?-.,=_~%+"
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/:;&?-.,=_~%+#"
if (NULL == strchr (ALLOWED_CHARACTERS,
(int) url[i]))
return false;
@@ -332,4 +335,20 @@ TALER_url_valid_charset (const char *url)
}
+bool
+TALER_is_web_url (const char *url)
+{
+ if ( (0 != strncasecmp (url,
+ "https://",
+ strlen ("https://"))) &&
+ (0 != strncasecmp (url,
+ "http://",
+ strlen ("http://"))) )
+ return false;
+ if (! TALER_url_valid_charset (url) )
+ return false;
+ return true;
+}
+
+
/* end of url.c */
diff --git a/src/util/util.c b/src/util/util.c
index 2d10fd69d..da5727487 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2014-2020 Taler Systems SA
+ Copyright (C) 2014-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -19,16 +19,20 @@
* @author Sree Harsha Totakura <sreeharsha@totakura.in>
* @author Florian Dold
* @author Benedikt Mueller
+ * @author Christian Grothoff
*/
#include "platform.h"
#include "taler_util.h"
+#include "taler_attributes.h"
+#include <gnunet/gnunet_json_lib.h>
+#include <unistr.h>
const char *
TALER_b2s (const void *buf,
size_t buf_size)
{
- static GNUNET_THREAD_LOCAL char ret[9];
+ static TALER_THREAD_LOCAL char ret[9];
struct GNUNET_HashCode hc;
char *tmp;
@@ -37,9 +41,9 @@ TALER_b2s (const void *buf,
&hc);
tmp = GNUNET_STRINGS_data_to_string_alloc (&hc,
sizeof (hc));
- memcpy (ret,
- tmp,
- 8);
+ GNUNET_memcpy (ret,
+ tmp,
+ 8);
GNUNET_free (tmp);
ret[8] = '\0';
return ret;
@@ -82,8 +86,6 @@ TALER_global_fee_set_hton (struct TALER_GlobalFeeSetNBOP *nbo,
{
TALER_amount_hton (&nbo->history,
&fees->history);
- TALER_amount_hton (&nbo->kyc,
- &fees->kyc);
TALER_amount_hton (&nbo->account,
&fees->account);
TALER_amount_hton (&nbo->purse,
@@ -97,8 +99,6 @@ TALER_global_fee_set_ntoh (struct TALER_GlobalFeeSet *fees,
{
TALER_amount_ntoh (&fees->history,
&nbo->history);
- TALER_amount_ntoh (&fees->kyc,
- &nbo->kyc);
TALER_amount_ntoh (&fees->account,
&nbo->account);
TALER_amount_ntoh (&fees->purse,
@@ -114,8 +114,6 @@ TALER_wire_fee_set_hton (struct TALER_WireFeeSetNBOP *nbo,
&fees->wire);
TALER_amount_hton (&nbo->closing,
&fees->closing);
- TALER_amount_hton (&nbo->wad,
- &fees->wad);
}
@@ -127,8 +125,6 @@ TALER_wire_fee_set_ntoh (struct TALER_WireFeeSet *fees,
&nbo->wire);
TALER_amount_ntoh (&fees->closing,
&nbo->closing);
- TALER_amount_ntoh (&fees->wad,
- &nbo->wad);
}
@@ -142,10 +138,6 @@ TALER_global_fee_set_cmp (const struct TALER_GlobalFeeSet *f1,
&f2->history);
if (0 != ret)
return ret;
- ret = TALER_amount_cmp (&f1->kyc,
- &f2->kyc);
- if (0 != ret)
- return ret;
ret = TALER_amount_cmp (&f1->account,
&f2->account);
if (0 != ret)
@@ -172,10 +164,6 @@ TALER_wire_fee_set_cmp (const struct TALER_WireFeeSet *f1,
&f2->closing);
if (0 != ret)
return ret;
- ret = TALER_amount_cmp (&f1->wad,
- &f2->wad);
- if (0 != ret)
- return ret;
return 0;
}
@@ -217,6 +205,189 @@ TALER_denom_fee_check_currency (
}
+/**
+ * Dump character in the low range into @a buf
+ * following RFC 8785.
+ *
+ * @param[in,out] buf buffer to modify
+ * @param val value to dump
+ */
+static void
+lowdump (struct GNUNET_Buffer *buf,
+ unsigned char val)
+{
+ char scratch[7];
+
+ switch (val)
+ {
+ case 0x8:
+ GNUNET_buffer_write (buf,
+ "\\b",
+ 2);
+ break;
+ case 0x9:
+ GNUNET_buffer_write (buf,
+ "\\t",
+ 2);
+ break;
+ case 0xA:
+ GNUNET_buffer_write (buf,
+ "\\n",
+ 2);
+ break;
+ case 0xC:
+ GNUNET_buffer_write (buf,
+ "\\f",
+ 2);
+ break;
+ case 0xD:
+ GNUNET_buffer_write (buf,
+ "\\r",
+ 2);
+ break;
+ default:
+ GNUNET_snprintf (scratch,
+ sizeof (scratch),
+ "\\u%04x",
+ (unsigned int) val);
+ GNUNET_buffer_write (buf,
+ scratch,
+ 6);
+ break;
+ }
+}
+
+
+size_t
+TALER_rfc8785encode (char **inp)
+{
+ struct GNUNET_Buffer buf = { 0 };
+ size_t left = strlen (*inp) + 1;
+ size_t olen;
+ char *in = *inp;
+ const char *pos = in;
+
+ GNUNET_buffer_prealloc (&buf,
+ left + 40);
+ buf.warn_grow = 0; /* disable, + 40 is just a wild guess */
+ while (1)
+ {
+ int mbl = u8_mblen ((unsigned char *) pos,
+ left);
+ unsigned char val;
+
+ if (0 == mbl)
+ break;
+ val = (unsigned char) *pos;
+ if ( (1 == mbl) &&
+ (val <= 0x1F) )
+ {
+ /* Should not happen, as input is produced by
+ * JSON stringification */
+ GNUNET_break (0);
+ lowdump (&buf,
+ val);
+ }
+ else if ( (1 == mbl) && ('\\' == *pos) )
+ {
+ switch (*(pos + 1))
+ {
+ case '\\':
+ mbl = 2;
+ GNUNET_buffer_write (&buf,
+ pos,
+ mbl);
+ break;
+ case 'u':
+ {
+ unsigned int num;
+ uint32_t n32;
+ unsigned char res[8];
+ size_t rlen;
+
+ GNUNET_assert ( (1 ==
+ sscanf (pos + 2,
+ "%4x",
+ &num)) ||
+ (1 ==
+ sscanf (pos + 2,
+ "%4X",
+ &num)) );
+ mbl = 6;
+ n32 = (uint32_t) num;
+ rlen = sizeof (res);
+ u32_to_u8 (&n32,
+ 1,
+ res,
+ &rlen);
+ if ( (1 == rlen) &&
+ (res[0] <= 0x1F) )
+ {
+ lowdump (&buf,
+ res[0]);
+ }
+ else
+ {
+ GNUNET_buffer_write (&buf,
+ (const char *) res,
+ rlen);
+ }
+ }
+ break;
+ default:
+ mbl = 2;
+ GNUNET_buffer_write (&buf,
+ pos,
+ mbl);
+ break;
+ }
+ }
+ else
+ {
+ GNUNET_buffer_write (&buf,
+ pos,
+ mbl);
+ }
+ left -= mbl;
+ pos += mbl;
+ }
+
+ /* 0-terminate buffer */
+ GNUNET_buffer_write (&buf,
+ "",
+ 1);
+ GNUNET_free (in);
+ *inp = GNUNET_buffer_reap (&buf,
+ &olen);
+ return olen;
+}
+
+
+/**
+ * Hash normalized @a j JSON object or array and
+ * store the result in @a hc.
+ *
+ * @param j JSON to hash
+ * @param[out] hc where to write the hash
+ */
+void
+TALER_json_hash (const json_t *j,
+ struct GNUNET_HashCode *hc)
+{
+ char *cstr;
+ size_t clen;
+
+ cstr = json_dumps (j,
+ JSON_COMPACT | JSON_SORT_KEYS);
+ GNUNET_assert (NULL != cstr);
+ clen = TALER_rfc8785encode (&cstr);
+ GNUNET_CRYPTO_hash (cstr,
+ clen,
+ hc);
+ GNUNET_free (cstr);
+}
+
+
#ifdef __APPLE__
char *
strchrnul (const char *s,
@@ -234,4 +405,51 @@ strchrnul (const char *s,
#endif
+void
+TALER_CRYPTO_attributes_to_kyc_prox (
+ const json_t *attr,
+ struct GNUNET_ShortHashCode *kyc_prox)
+{
+ const char *name = NULL;
+ const char *birthdate = NULL;
+ struct GNUNET_JSON_Specification spec[] = {
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string (TALER_ATTRIBUTE_FULL_NAME,
+ &name),
+ NULL),
+ GNUNET_JSON_spec_mark_optional (
+ GNUNET_JSON_spec_string (TALER_ATTRIBUTE_BIRTHDATE,
+ &birthdate),
+ NULL),
+ GNUNET_JSON_spec_end ()
+ };
+
+ if (GNUNET_OK !=
+ GNUNET_JSON_parse (attr,
+ spec,
+ NULL, NULL))
+ {
+ GNUNET_break (0);
+ memset (kyc_prox,
+ 0,
+ sizeof (*kyc_prox));
+ return;
+ }
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (
+ kyc_prox,
+ sizeof (*kyc_prox),
+ name,
+ (NULL == name)
+ ? 0
+ : strlen (name),
+ birthdate,
+ (NULL == birthdate)
+ ? 0
+ : strlen (birthdate),
+ NULL,
+ 0));
+}
+
+
/* end of util.c */
diff --git a/src/util/wallet_signatures.c b/src/util/wallet_signatures.c
index 4761ab6e7..0b6ab5432 100644
--- a/src/util/wallet_signatures.c
+++ b/src/util/wallet_signatures.c
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2021, 2022 Taler Systems SA
+ Copyright (C) 2021-2023 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
@@ -17,12 +17,16 @@
* @file wallet_signatures.c
* @brief Utility functions for Taler wallet signatures
* @author Christian Grothoff
+ * @author Özgür Kesim
*/
#include "platform.h"
#include "taler_util.h"
#include "taler_signatures.h"
+#include <gnunet/gnunet_common.h>
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* @brief Format used to generate the signature on a request to deposit
* a coin into the account of a merchant.
@@ -47,9 +51,9 @@ struct TALER_DepositRequestPS
struct TALER_AgeCommitmentHash h_age_commitment GNUNET_PACKED;
/**
- * Hash over extension attributes shared with the exchange.
+ * Hash over optional policy extension attributes shared with the exchange.
*/
- struct TALER_ExtensionContractHashP h_extensions GNUNET_PACKED;
+ struct TALER_ExtensionPolicyHashP h_policy GNUNET_PACKED;
/**
* Hash over the wiring information of the merchant.
@@ -107,8 +111,15 @@ struct TALER_DepositRequestPS
*/
struct TALER_MerchantPublicKeyP merchant;
+ /**
+ * Hash over a JSON containing data provided by the
+ * wallet to complete the contract upon payment.
+ */
+ struct GNUNET_HashCode wallet_data_hash;
+
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_deposit_sign (
@@ -116,8 +127,9 @@ TALER_wallet_deposit_sign (
const struct TALER_Amount *deposit_fee,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct GNUNET_HashCode *wallet_data_hash,
const struct TALER_AgeCommitmentHash *h_age_commitment,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_DenominationHashP *h_denom_pub,
const struct GNUNET_TIME_Timestamp wallet_timestamp,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -136,10 +148,12 @@ TALER_wallet_deposit_sign (
.merchant = *merchant_pub
};
+ if (NULL != wallet_data_hash)
+ dr.wallet_data_hash = *wallet_data_hash;
if (NULL != h_age_commitment)
dr.h_age_commitment = *h_age_commitment;
- if (NULL != h_extensions)
- dr.h_extensions = *h_extensions;
+ if (NULL != h_policy)
+ dr.h_policy = *h_policy;
TALER_amount_hton (&dr.amount_with_fee,
amount);
TALER_amount_hton (&dr.deposit_fee,
@@ -156,8 +170,9 @@ TALER_wallet_deposit_verify (
const struct TALER_Amount *deposit_fee,
const struct TALER_MerchantWireHashP *h_wire,
const struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct GNUNET_HashCode *wallet_data_hash,
const struct TALER_AgeCommitmentHash *h_age_commitment,
- const struct TALER_ExtensionContractHashP *h_extensions,
+ const struct TALER_ExtensionPolicyHashP *h_policy,
const struct TALER_DenominationHashP *h_denom_pub,
struct GNUNET_TIME_Timestamp wallet_timestamp,
const struct TALER_MerchantPublicKeyP *merchant_pub,
@@ -174,14 +189,14 @@ TALER_wallet_deposit_verify (
.wallet_timestamp = GNUNET_TIME_timestamp_hton (wallet_timestamp),
.refund_deadline = GNUNET_TIME_timestamp_hton (refund_deadline),
.merchant = *merchant_pub,
- .h_age_commitment = {{{0}}},
- .h_extensions = {{{0}}}
};
+ if (NULL != wallet_data_hash)
+ dr.wallet_data_hash = *wallet_data_hash;
if (NULL != h_age_commitment)
dr.h_age_commitment = *h_age_commitment;
- if (NULL != h_extensions)
- dr.h_extensions = *h_extensions;
+ if (NULL != h_policy)
+ dr.h_policy = *h_policy;
TALER_amount_hton (&dr.amount_with_fee,
amount);
TALER_amount_hton (&dr.deposit_fee,
@@ -199,6 +214,8 @@ TALER_wallet_deposit_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* @brief Format used for to allow the wallet to authenticate
* link data provided by the exchange.
@@ -233,6 +250,7 @@ struct TALER_LinkDataPS
struct TALER_BlindedCoinHashP coin_envelope_hash;
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_link_sign (const struct TALER_DenominationHashP *h_denom_pub,
@@ -279,6 +297,8 @@ TALER_wallet_link_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Signed data to request that a coin should be refunded as part of
* the "emergency" /recoup protocol. The refund will go back to the bank
@@ -300,15 +320,17 @@ struct TALER_RecoupRequestPS
/**
* Blinding factor that was used to withdraw the coin.
*/
- union TALER_DenominationBlindingKeyP coin_blind;
+ union GNUNET_CRYPTO_BlindingSecretP coin_blind;
};
+GNUNET_NETWORK_STRUCT_END
+
enum GNUNET_GenericReturnValue
TALER_wallet_recoup_verify (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig)
{
@@ -329,7 +351,7 @@ TALER_wallet_recoup_verify (
void
TALER_wallet_recoup_sign (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_CoinSpendSignatureP *coin_sig)
{
@@ -349,7 +371,7 @@ TALER_wallet_recoup_sign (
enum GNUNET_GenericReturnValue
TALER_wallet_recoup_refresh_verify (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
const struct TALER_CoinSpendSignatureP *coin_sig)
{
@@ -370,7 +392,7 @@ TALER_wallet_recoup_refresh_verify (
void
TALER_wallet_recoup_refresh_sign (
const struct TALER_DenominationHashP *h_denom_pub,
- const union TALER_DenominationBlindingKeyP *coin_bks,
+ const union GNUNET_CRYPTO_BlindingSecretP *coin_bks,
const struct TALER_CoinSpendPrivateKeyP *coin_priv,
struct TALER_CoinSpendSignatureP *coin_sig)
{
@@ -387,6 +409,8 @@ TALER_wallet_recoup_refresh_sign (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* @brief Message signed by a coin to indicate that the coin should be
* melted.
@@ -438,6 +462,7 @@ struct TALER_RefreshMeltCoinAffirmationPS
struct TALER_AmountNBO melt_fee;
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_melt_sign (
@@ -504,6 +529,9 @@ TALER_wallet_melt_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+
/**
* @brief Format used for to generate the signature on a request to withdraw
* coins from a reserve.
@@ -538,6 +566,8 @@ struct TALER_WithdrawRequestPS
};
+GNUNET_NETWORK_STRUCT_END
+
void
TALER_wallet_withdraw_sign (
const struct TALER_DenominationHashP *h_denom_pub,
@@ -586,45 +616,181 @@ TALER_wallet_withdraw_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * @brief Format used for to generate the signature on a request to
+ * age-withdraw from a reserve.
+ */
+struct TALER_AgeWithdrawRequestPS
+{
+
+ /**
+ * Purpose must be #TALER_SIGNATURE_WALLET_RESERVE_WITHDRAW.
+ * Used with an EdDSA signature of a `struct TALER_ReservePublicKeyP`.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * The reserve's public key
+ */
+ struct TALER_ReservePublicKeyP reserve_pub;
+
+ /**
+ * Value of the coin being exchanged (matching the denomination key)
+ * plus the transaction fee. We include this in what is being
+ * signed so that we can verify a reserve's remaining total balance
+ * without needing to access the respective denomination key
+ * information each time.
+ */
+ struct TALER_AmountNBO amount_with_fee;
+
+ /**
+ * Running SHA512 hash of the commitment of n*kappa coins
+ */
+ struct TALER_AgeWithdrawCommitmentHashP h_commitment;
+
+ /**
+ * The mask that defines the age groups. MUST be the same for all denominations.
+ */
+ struct TALER_AgeMask mask;
+
+ /**
+ * Maximum age group that the coins are going to be restricted to.
+ */
+ uint8_t max_age_group;
+};
+
+
+GNUNET_NETWORK_STRUCT_END
+
+void
+TALER_wallet_age_withdraw_sign (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_AgeMask *mask,
+ uint8_t max_age,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_AgeWithdrawRequestPS req = {
+ .purpose.size = htonl (sizeof (req)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_AGE_WITHDRAW),
+ .h_commitment = *h_commitment,
+ .mask = *mask,
+ .max_age_group = TALER_get_age_group (mask, max_age)
+ };
+
+ GNUNET_CRYPTO_eddsa_key_get_public (&reserve_priv->eddsa_priv,
+ &req.reserve_pub.eddsa_pub);
+ TALER_amount_hton (&req.amount_with_fee,
+ amount_with_fee);
+ GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
+ &req,
+ &reserve_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_age_withdraw_verify (
+ const struct TALER_AgeWithdrawCommitmentHashP *h_commitment,
+ const struct TALER_Amount *amount_with_fee,
+ const struct TALER_AgeMask *mask,
+ uint8_t max_age,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_AgeWithdrawRequestPS awsrd = {
+ .purpose.size = htonl (sizeof (awsrd)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_AGE_WITHDRAW),
+ .reserve_pub = *reserve_pub,
+ .h_commitment = *h_commitment,
+ .mask = *mask,
+ .max_age_group = TALER_get_age_group (mask, max_age)
+ };
+
+ TALER_amount_hton (&awsrd.amount_with_fee,
+ amount_with_fee);
+ return GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_WALLET_RESERVE_AGE_WITHDRAW,
+ &awsrd,
+ &reserve_sig->eddsa_signature,
+ &reserve_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+
+/**
+ * @brief Format used for to generate the signature on a request to withdraw
+ * coins from a reserve.
+ */
+struct TALER_AccountSetupRequestSignaturePS
+{
+
+ /**
+ * Purpose must be #TALER_SIGNATURE_WALLET_ACCOUNT_SETUP.
+ * Used with an EdDSA signature of a `struct TALER_ReservePublicKeyP`.
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Balance threshold the wallet is about to cross.
+ */
+ struct TALER_AmountNBO threshold;
+
+};
+
+
+GNUNET_NETWORK_STRUCT_END
+
+
void
TALER_wallet_account_setup_sign (
const struct TALER_ReservePrivateKeyP *reserve_priv,
+ const struct TALER_Amount *balance_threshold,
struct TALER_ReserveSignatureP *reserve_sig)
{
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose = {
- .size = htonl (sizeof (purpose)),
- .purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
+ struct TALER_AccountSetupRequestSignaturePS asap = {
+ .purpose.size = htonl (sizeof (asap)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
};
- GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign_ (&reserve_priv->eddsa_priv,
- &purpose,
- &reserve_sig->eddsa_signature));
+ TALER_amount_hton (&asap.threshold,
+ balance_threshold);
+ GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
+ &asap,
+ &reserve_sig->eddsa_signature);
}
enum GNUNET_GenericReturnValue
TALER_wallet_account_setup_verify (
const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_Amount *balance_threshold,
const struct TALER_ReserveSignatureP *reserve_sig)
{
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose = {
- .size = htonl (sizeof (purpose)),
- .purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
+ struct TALER_AccountSetupRequestSignaturePS asap = {
+ .purpose.size = htonl (sizeof (asap)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_ACCOUNT_SETUP)
};
- return GNUNET_CRYPTO_eddsa_verify_ (
+ TALER_amount_hton (&asap.threshold,
+ balance_threshold);
+ return GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_WALLET_ACCOUNT_SETUP,
- &purpose,
+ &asap,
&reserve_sig->eddsa_signature,
&reserve_pub->eddsa_pub);
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+
/**
- * Response by which a wallet requests a full
- * reserve history and indicates it is willing
- * to pay for it.
+ * Response by which a wallet requests a reserve history.
*/
struct TALER_ReserveHistoryRequestPS
{
@@ -635,33 +801,27 @@ struct TALER_ReserveHistoryRequestPS
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
- * When did the wallet make the request.
+ * Which entries to exclude. Only return above this offset.
*/
- struct GNUNET_TIME_TimestampNBO request_timestamp;
-
- /**
- * How much does the exchange charge for the history?
- */
- struct TALER_AmountNBO history_fee;
+ uint64_t start_off;
};
+GNUNET_NETWORK_STRUCT_END
+
enum GNUNET_GenericReturnValue
TALER_wallet_reserve_history_verify (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_Amount *history_fee,
+ uint64_t start_off,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_ReserveSignatureP *reserve_sig)
{
struct TALER_ReserveHistoryRequestPS rhr = {
.purpose.size = htonl (sizeof (rhr)),
.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_HISTORY),
- .request_timestamp = GNUNET_TIME_timestamp_hton (ts)
+ .start_off = GNUNET_htonll (start_off)
};
- TALER_amount_hton (&rhr.history_fee,
- history_fee);
return GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_WALLET_RESERVE_HISTORY,
&rhr,
@@ -672,82 +832,84 @@ TALER_wallet_reserve_history_verify (
void
TALER_wallet_reserve_history_sign (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_Amount *history_fee,
+ uint64_t start_off,
const struct TALER_ReservePrivateKeyP *reserve_priv,
struct TALER_ReserveSignatureP *reserve_sig)
{
struct TALER_ReserveHistoryRequestPS rhr = {
.purpose.size = htonl (sizeof (rhr)),
.purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_HISTORY),
- .request_timestamp = GNUNET_TIME_timestamp_hton (ts)
+ .start_off = GNUNET_htonll (start_off)
};
- TALER_amount_hton (&rhr.history_fee,
- history_fee);
GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
&rhr,
&reserve_sig->eddsa_signature);
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
- * Response by which a wallet requests an account status.
+ * Response by which a wallet requests a coin history.
*/
-struct TALER_ReserveStatusRequestPS
+struct TALER_CoinHistoryRequestPS
{
/**
- * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_STATUS
+ * Purpose is #TALER_SIGNATURE_WALLET_COIN_HISTORY
*/
struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
/**
- * When did the wallet make the request.
+ * Which entries to exclude. Only return above this offset.
*/
- struct GNUNET_TIME_TimestampNBO request_timestamp;
+ uint64_t start_off;
};
+GNUNET_NETWORK_STRUCT_END
enum GNUNET_GenericReturnValue
-TALER_wallet_reserve_status_verify (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePublicKeyP *reserve_pub,
- const struct TALER_ReserveSignatureP *reserve_sig)
+TALER_wallet_coin_history_verify (
+ uint64_t start_off,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig)
{
- struct TALER_ReserveStatusRequestPS rsr = {
+ struct TALER_CoinHistoryRequestPS rsr = {
.purpose.size = htonl (sizeof (rsr)),
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_STATUS),
- .request_timestamp = GNUNET_TIME_timestamp_hton (ts)
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_HISTORY),
+ .start_off = GNUNET_htonll (start_off)
};
return GNUNET_CRYPTO_eddsa_verify (
- TALER_SIGNATURE_WALLET_RESERVE_STATUS,
+ TALER_SIGNATURE_WALLET_COIN_HISTORY,
&rsr,
- &reserve_sig->eddsa_signature,
- &reserve_pub->eddsa_pub);
+ &coin_sig->eddsa_signature,
+ &coin_pub->eddsa_pub);
}
void
-TALER_wallet_reserve_status_sign (
- const struct GNUNET_TIME_Timestamp ts,
- const struct TALER_ReservePrivateKeyP *reserve_priv,
- struct TALER_ReserveSignatureP *reserve_sig)
+TALER_wallet_coin_history_sign (
+ uint64_t start_off,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ struct TALER_CoinSpendSignatureP *coin_sig)
{
- struct TALER_ReserveStatusRequestPS rsr = {
+ struct TALER_CoinHistoryRequestPS rsr = {
.purpose.size = htonl (sizeof (rsr)),
- .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_STATUS),
- .request_timestamp = GNUNET_TIME_timestamp_hton (ts)
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_COIN_HISTORY),
+ .start_off = GNUNET_htonll (start_off)
};
- GNUNET_CRYPTO_eddsa_sign (&reserve_priv->eddsa_priv,
+ GNUNET_CRYPTO_eddsa_sign (&coin_priv->eddsa_priv,
&rsr,
- &reserve_sig->eddsa_signature);
+ &coin_sig->eddsa_signature);
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message signed to create a purse (without reserve).
*/
@@ -787,10 +949,13 @@ struct TALER_PurseCreatePS
};
+GNUNET_NETWORK_STRUCT_END
+
+
void
TALER_wallet_purse_create_sign (
struct GNUNET_TIME_Timestamp purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_PurseMergePublicKeyP *merge_pub,
uint32_t min_age,
const struct TALER_Amount *amount,
@@ -817,7 +982,7 @@ TALER_wallet_purse_create_sign (
enum GNUNET_GenericReturnValue
TALER_wallet_purse_create_verify (
struct GNUNET_TIME_Timestamp purse_expiration,
- struct TALER_PrivateContractHashP *h_contract_terms,
+ const struct TALER_PrivateContractHashP *h_contract_terms,
const struct TALER_PurseMergePublicKeyP *merge_pub,
uint32_t min_age,
const struct TALER_Amount *amount,
@@ -843,6 +1008,59 @@ TALER_wallet_purse_create_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed to delete a purse.
+ */
+struct TALER_PurseDeletePS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_WALLET_PURSE_DELETE
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+};
+
+
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_wallet_purse_delete_sign (
+ const struct TALER_PurseContractPrivateKeyP *purse_priv,
+ struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct TALER_PurseDeletePS pm = {
+ .purpose.size = htonl (sizeof (pm)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_PURSE_DELETE)
+ };
+
+ GNUNET_CRYPTO_eddsa_sign (&purse_priv->eddsa_priv,
+ &pm,
+ &purse_sig->eddsa_signature);
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_purse_delete_verify (
+ const struct TALER_PurseContractPublicKeyP *purse_pub,
+ const struct TALER_PurseContractSignatureP *purse_sig)
+{
+ struct TALER_PurseDeletePS pm = {
+ .purpose.size = htonl (sizeof (pm)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_PURSE_DELETE)
+ };
+
+ return GNUNET_CRYPTO_eddsa_verify (
+ TALER_SIGNATURE_WALLET_PURSE_DELETE,
+ &pm,
+ &purse_sig->eddsa_signature,
+ &purse_pub->eddsa_pub);
+}
+
+
void
TALER_wallet_purse_status_sign (
const struct TALER_PurseContractPrivateKeyP *purse_priv,
@@ -877,6 +1095,8 @@ TALER_wallet_purse_status_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message signed to deposit a coin into a purse.
*/
@@ -916,6 +1136,7 @@ struct TALER_PurseDepositPS
struct GNUNET_HashCode h_exchange_base_url GNUNET_PACKED;
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_purse_deposit_sign (
@@ -977,6 +1198,8 @@ TALER_wallet_purse_deposit_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message signed to merge a purse into a reserve.
*/
@@ -1006,10 +1229,11 @@ struct TALER_PurseMergePS
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_purse_merge_sign (
- const char *reserve_url,
+ const char *reserve_uri,
struct GNUNET_TIME_Timestamp merge_timestamp,
const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_PurseMergePrivateKeyP *merge_priv,
@@ -1022,7 +1246,11 @@ TALER_wallet_purse_merge_sign (
.purse_pub = *purse_pub
};
- TALER_payto_hash (reserve_url,
+ GNUNET_assert (0 ==
+ strncasecmp (reserve_uri,
+ "payto://taler-reserve",
+ strlen ("payto://taler-reserve")));
+ TALER_payto_hash (reserve_uri,
&pm.h_payto);
GNUNET_CRYPTO_eddsa_sign (&merge_priv->eddsa_priv,
&pm,
@@ -1032,7 +1260,7 @@ TALER_wallet_purse_merge_sign (
enum GNUNET_GenericReturnValue
TALER_wallet_purse_merge_verify (
- const char *reserve_url,
+ const char *reserve_uri,
struct GNUNET_TIME_Timestamp merge_timestamp,
const struct TALER_PurseContractPublicKeyP *purse_pub,
const struct TALER_PurseMergePublicKeyP *merge_pub,
@@ -1045,7 +1273,15 @@ TALER_wallet_purse_merge_verify (
.purse_pub = *purse_pub
};
- TALER_payto_hash (reserve_url,
+ if (0 !=
+ strncasecmp (reserve_uri,
+ "payto://taler-reserve",
+ strlen ("payto://taler-reserve")))
+ {
+ GNUNET_break (0);
+ return GNUNET_NO;
+ }
+ TALER_payto_hash (reserve_uri,
&pm.h_payto);
return GNUNET_CRYPTO_eddsa_verify (
TALER_SIGNATURE_WALLET_PURSE_MERGE,
@@ -1055,6 +1291,8 @@ TALER_wallet_purse_merge_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message signed by account to merge a purse into a reserve.
*/
@@ -1110,6 +1348,8 @@ struct TALER_AccountMergePS
uint32_t flags GNUNET_PACKED;
};
+GNUNET_NETWORK_STRUCT_END
+
void
TALER_wallet_account_merge_sign (
@@ -1181,40 +1421,323 @@ TALER_wallet_account_merge_verify (
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by reserve key.
+ */
+struct TALER_ReserveOpenPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_OPEN
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Amount to be paid from the reserve balance to open
+ * the reserve.
+ */
+ struct TALER_AmountNBO reserve_payment;
+
+ /**
+ * When was the request created.
+ */
+ struct GNUNET_TIME_TimestampNBO request_timestamp;
+
+ /**
+ * For how long should the reserve be kept open.
+ * (Determines amount to be paid.)
+ */
+ struct GNUNET_TIME_TimestampNBO reserve_expiration;
+
+ /**
+ * How many open purses should be included with the
+ * open reserve?
+ * (Determines amount to be paid.)
+ */
+ uint32_t purse_limit GNUNET_PACKED;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
void
-TALER_wallet_account_close_sign (
+TALER_wallet_reserve_open_sign (
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
const struct TALER_ReservePrivateKeyP *reserve_priv,
struct TALER_ReserveSignatureP *reserve_sig)
{
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose = {
- .size = htonl (sizeof (purpose)),
- .purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_CLOSE)
+ struct TALER_ReserveOpenPS rop = {
+ .purpose.size = htonl (sizeof (rop)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_OPEN),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp),
+ .reserve_expiration = GNUNET_TIME_timestamp_hton (reserve_expiration),
+ .purse_limit = htonl (purse_limit)
};
+ TALER_amount_hton (&rop.reserve_payment,
+ reserve_payment);
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_sign_ (&reserve_priv->eddsa_priv,
- &purpose,
+ &rop.purpose,
&reserve_sig->eddsa_signature));
}
enum GNUNET_GenericReturnValue
-TALER_wallet_account_close_verify (
+TALER_wallet_reserve_open_verify (
+ const struct TALER_Amount *reserve_payment,
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ struct GNUNET_TIME_Timestamp reserve_expiration,
+ uint32_t purse_limit,
const struct TALER_ReservePublicKeyP *reserve_pub,
const struct TALER_ReserveSignatureP *reserve_sig)
{
- struct GNUNET_CRYPTO_EccSignaturePurpose purpose = {
- .size = htonl (sizeof (purpose)),
- .purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_CLOSE)
+ struct TALER_ReserveOpenPS rop = {
+ .purpose.size = htonl (sizeof (rop)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_OPEN),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp),
+ .reserve_expiration = GNUNET_TIME_timestamp_hton (reserve_expiration),
+ .purse_limit = htonl (purse_limit)
};
+ TALER_amount_hton (&rop.reserve_payment,
+ reserve_payment);
+ return GNUNET_CRYPTO_eddsa_verify_ (TALER_SIGNATURE_WALLET_RESERVE_OPEN,
+ &rop.purpose,
+ &reserve_sig->eddsa_signature,
+ &reserve_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by
+ */
+struct TALER_ReserveOpenDepositPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * Which reserve's opening signature should be paid for?
+ */
+ struct TALER_ReserveSignatureP reserve_sig;
+
+ /**
+ * Specifies how much of the coin's value should be spent on opening this
+ * reserve.
+ */
+ struct TALER_AmountNBO coin_contribution;
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+// FIXME-#7267: add h_age_commitment, h_denom_pub to have proof!
+void
+TALER_wallet_reserve_open_deposit_sign (
+ const struct TALER_Amount *coin_contribution,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_CoinSpendPrivateKeyP *coin_priv,
+ struct TALER_CoinSpendSignatureP *coin_sig)
+{
+ struct TALER_ReserveOpenDepositPS rod = {
+ .purpose.size = htonl (sizeof (rod)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT),
+ .reserve_sig = *reserve_sig
+ };
+
+ TALER_amount_hton (&rod.coin_contribution,
+ coin_contribution);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_sign_ (&coin_priv->eddsa_priv,
+ &rod.purpose,
+ &coin_sig->eddsa_signature));
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_open_deposit_verify (
+ const struct TALER_Amount *coin_contribution,
+ const struct TALER_ReserveSignatureP *reserve_sig,
+ const struct TALER_CoinSpendPublicKeyP *coin_pub,
+ const struct TALER_CoinSpendSignatureP *coin_sig)
+{
+ struct TALER_ReserveOpenDepositPS rod = {
+ .purpose.size = htonl (sizeof (rod)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT),
+ .reserve_sig = *reserve_sig
+ };
+
+ TALER_amount_hton (&rod.coin_contribution,
+ coin_contribution);
+ return GNUNET_CRYPTO_eddsa_verify_ (
+ TALER_SIGNATURE_WALLET_RESERVE_OPEN_DEPOSIT,
+ &rod.purpose,
+ &coin_sig->eddsa_signature,
+ &coin_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by reserve key.
+ */
+struct TALER_ReserveClosePS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_WALLET_RESERVE_CLOSE
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * When was the request created.
+ */
+ struct GNUNET_TIME_TimestampNBO request_timestamp;
+
+ /**
+ * Hash of the payto://-URI of the target account
+ * for the closure, or all zeros for the reserve
+ * origin account.
+ */
+ struct TALER_PaytoHashP target_account_h_payto;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_wallet_reserve_close_sign (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_ReserveClosePS rcp = {
+ .purpose.size = htonl (sizeof (rcp)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_CLOSE),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp)
+ };
+
+ if (NULL != h_payto)
+ rcp.target_account_h_payto = *h_payto;
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_sign_ (&reserve_priv->eddsa_priv,
+ &rcp.purpose,
+ &reserve_sig->eddsa_signature));
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_close_verify (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const struct TALER_PaytoHashP *h_payto,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_ReserveClosePS rcp = {
+ .purpose.size = htonl (sizeof (rcp)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_CLOSE),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp)
+ };
+
+ if (NULL != h_payto)
+ rcp.target_account_h_payto = *h_payto;
return GNUNET_CRYPTO_eddsa_verify_ (TALER_SIGNATURE_WALLET_RESERVE_CLOSE,
- &purpose,
+ &rcp.purpose,
&reserve_sig->eddsa_signature,
&reserve_pub->eddsa_pub);
}
+GNUNET_NETWORK_STRUCT_BEGIN
+
+/**
+ * Message signed by reserve private key.
+ */
+struct TALER_ReserveAttestRequestPS
+{
+
+ /**
+ * Purpose is #TALER_SIGNATURE_WALLET_ATTEST_REQUEST
+ */
+ struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
+
+ /**
+ * When was the request created.
+ */
+ struct GNUNET_TIME_TimestampNBO request_timestamp;
+
+ /**
+ * Hash over the JSON array of requested attributes.
+ */
+ struct GNUNET_HashCode h_details;
+
+};
+
+GNUNET_NETWORK_STRUCT_END
+
+
+void
+TALER_wallet_reserve_attest_request_sign (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const json_t *details,
+ const struct TALER_ReservePrivateKeyP *reserve_priv,
+ struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_ReserveAttestRequestPS rcp = {
+ .purpose.size = htonl (sizeof (rcp)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_ATTEST_DETAILS),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp)
+ };
+
+ TALER_json_hash (details,
+ &rcp.h_details);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_sign_ (&reserve_priv->eddsa_priv,
+ &rcp.purpose,
+ &reserve_sig->eddsa_signature));
+}
+
+
+enum GNUNET_GenericReturnValue
+TALER_wallet_reserve_attest_request_verify (
+ struct GNUNET_TIME_Timestamp request_timestamp,
+ const json_t *details,
+ const struct TALER_ReservePublicKeyP *reserve_pub,
+ const struct TALER_ReserveSignatureP *reserve_sig)
+{
+ struct TALER_ReserveAttestRequestPS rcp = {
+ .purpose.size = htonl (sizeof (rcp)),
+ .purpose.purpose = htonl (TALER_SIGNATURE_WALLET_RESERVE_ATTEST_DETAILS),
+ .request_timestamp = GNUNET_TIME_timestamp_hton (request_timestamp)
+ };
+
+ TALER_json_hash (details,
+ &rcp.h_details);
+ return GNUNET_CRYPTO_eddsa_verify_ (
+ TALER_SIGNATURE_WALLET_RESERVE_ATTEST_DETAILS,
+ &rcp.purpose,
+ &reserve_sig->eddsa_signature,
+ &reserve_pub->eddsa_pub);
+}
+
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Message signed by purse to associate an encrypted contract.
*/
@@ -1237,6 +1760,7 @@ struct TALER_PurseContractPS
struct TALER_ContractDiffiePublicP contract_pub;
};
+GNUNET_NETWORK_STRUCT_END
void
TALER_wallet_econtract_upload_sign (